diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000000..3f96d694ee --- /dev/null +++ b/.clang-format @@ -0,0 +1,141 @@ +# +# Copyright (c) .NET Foundation and Contributors +# See LICENSE file in the project root for full license information. +# + +--- +Language: Cpp +# BasedOnStyle: Microsoft +AccessModifierOffset: -2 +AlignAfterOpenBracket: AlwaysBreak +AlignConsecutiveMacros: true +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlines: Right +AlignOperands: true +AlignTrailingComments: true +AllowAllArgumentsOnNextLine: false +AllowAllConstructorInitializersOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: None +AllowShortLambdasOnASingleLine: All +AllowShortIfStatementsOnASingleLine: Never +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: MultiLine +BinPackArguments: false +BinPackParameters: false +BraceWrapping: + AfterCaseLabel: true + AfterClass: true + AfterControlStatement: true + AfterEnum: true + AfterFunction: true + AfterNamespace: true + AfterObjCDeclaration: true + AfterStruct: true + AfterUnion: false + AfterExternBlock: true + BeforeCatch: true + BeforeElse: true + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Custom +BreakBeforeInheritanceComma: false +BreakInheritanceList: BeforeColon +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeColon +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: true +ColumnLimit: 120 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DeriveLineEnding: true +DerivePointerAlignment: false +DisableFormat: false +ExperimentalAutoDetectBinPacking: true +FixNamespaceComments: true +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + SortPriority: 0 + - Regex: '^(<|"(gtest|gmock|isl|json)/)' + Priority: 3 + SortPriority: 0 + - Regex: '.*' + Priority: 1 + SortPriority: 0 +IncludeIsMainRegex: '(Test)?$' +IncludeIsMainSourceRegex: '' +IndentCaseLabels: true +IndentGotoLabels: true +IndentPPDirectives: None +IndentWidth: 4 +IndentWrappedFunctionNames: true +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: true +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBinPackProtocolList: Auto +ObjCBlockIndentWidth: 2 +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 1000 +PointerAlignment: Right +ReflowComments: true +SortIncludes: false +SortUsingDeclarations: true +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyBlock: false +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInConditionalStatement: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +SpaceBeforeSquareBrackets: false +Standard: Latest +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TabWidth: 4 +UseCRLF: false +UseTab: Never +... diff --git a/.gitignore b/.gitignore index f279299b65..54bea977f8 100644 --- a/.gitignore +++ b/.gitignore @@ -6,8 +6,9 @@ /build/ /build/.gitkeep -# ignore cmake-variants file (will change frequently per user/board setup, use should derive content from cmake-variants.TEMPLATE.json) -cmake-variants.json +# ignore cmake-variants file (will change per user/board setup, developers should derive content from cmake-variants.TEMPLATE.json) +/cmake-variants.json +.vscode/cmake-variants.json # ignore any content inside the Interop assemblies folder InteropAssemblies/* @@ -15,7 +16,7 @@ InteropAssemblies/* !InteropAssemblies/README.md # Visual Studio Code -# ignore C/C++ launch file (will change frequently per user/board setup, use should derive content from launch.TEMPLATE.json) +# ignore C/C++ launch file (will change frequently per user/board setup, developers should derive content from launch.TEMPLATE.json) .vscode/launch.json .vscode/.cmaketools.json .vscode/settings.json diff --git a/.typo-ci.yml b/.typo-ci.yml new file mode 100644 index 0000000000..a124602167 --- /dev/null +++ b/.typo-ci.yml @@ -0,0 +1,25 @@ +dictionaries: + - en + - en_GB + +# Any files/folders we should ignore? +excluded_files: + - ".typo-ci.yml" + - ".gitignore" + +# Any typos we should ignore? +excluded_words: + - nanoFramework + - llvm + - vso + - autocrlf + - uart + - gpio + - csharp + - dotnet + - spi + - i2c + - pwm + +# Would you like filenames to also be spellchecked? +spellcheck_filenames: true diff --git a/.vscode/cmake-variants.TEMPLATE.json b/.vscode/cmake-variants.TEMPLATE.json new file mode 100644 index 0000000000..1adf55e95f --- /dev/null +++ b/.vscode/cmake-variants.TEMPLATE.json @@ -0,0 +1,107 @@ +{ + "buildType": { + "default": "debug", + "choices": { + "debug": { + "short": "Debug", + "long": "Emit debug information without performing optimizations", + "buildType": "Debug" + }, + "minsize": { + "short": "MinSizeRel", + "long": "Optimize for smallest binary size", + "buildType": "MinSizeRel" + }, + "reldeb": { + "short": "RelWithDebInfo", + "long": "Perform optimizations AND include debugging information", + "buildType": "RelWithDebInfo" + } + } + }, + "linkage": { + "default": "", + "choices": { + "OPTION_NAME_HERE": { + "short": "", + "settings": { + "BUILD_VERSION": "0.9.99.999", + "CMAKE_TOOLCHAIN_FILE": "CMake/toolchain..cmake", + "TOOLCHAIN_PREFIX": "", + "TOOL_HEX2DFU_PREFIX": "", + "ESP32_IDF_PATH": "/esp-idf", + "ESP32_LIBS_PATH": "/libs", + "ESP32_BOARD": "ESP32_WROOM_32", + "EXECUTABLE_OUTPUT_PATH": "${workspaceRoot}/build", + "TARGET_SERIES": "", + "USE_RNG": "", + "DP_FLOATINGPOINT": "", + "SUPPORT_ANY_BASE_CONVERSION": "", + "RTOS": "", + "RTOS_SOURCE_FOLDER": "", + "CHIBIOS_CONTRIB_REQUIRED": "OFF-default-ON-to-include_ChibiOS-Contrib-repository-in-the-build", + "CHIBIOS_CONTRIB_SOURCE": "", + "FREERTOS_BOARD": "", + "RTOS_VERSION": "", + "RTOS_SOURCE": "", + "CMSIS_SOURCE": "", + "CMSIS_VERSION": "", + "CHIBIOS_BOARD": "", + "STM32_CUBE_PACKAGE_REQUIRED": "", + "STM32_CUBE_PACKAGE_SOURCE": "", + "TI_BOARD": "", + "TI_SL_CC32xx_SDK_SOURCE": "", + "TI_SL_CC13x2_26x2_SDK_SOURCE": "", + "TI_XDCTOOLS_SOURCE": "", + "TI_SYSCONFIG_SOURCE": "", + "SPIFFS_SOURCE": "", + "SWO_OUTPUT": "OFF-default-ON-to-enable-ARM-CortexM-Single-Wire-Output", + "FATFS_VERSION": "", + "FATFS_SOURCE": "", + "LWIP_VERSION": "", + "NF_BUILD_RTM": "OFF-default-ON-to-enable-RTM-build", + "NF_WP_TRACE_ERRORS": "OFF-default-ON-to-enable-trace-error-messages-wire-protocol", + "NF_WP_TRACE_HEADERS": "OFF-default-ON-to-enable-trace-header-messages-wire-protocol", + "NF_WP_TRACE_STATE": "OFF-default-ON-to-enable-trace-state-messages-wire-protocol", + "NF_WP_TRACE_NODATA": "OFF-default-ON-to-enable-trace-no-data-messages-wire-protocol", + "NF_WP_TRACE_ALL": "OFF-default-ON-to-enable-trace-all-messages-wire-protocol", + "NF_WP_IMPLEMENTS_CRC32": "ON-default-OFF-to-disable-CRC32-wire-protocol", + "NF_FEATURE_DEBUGGER": "OFF-default-ON-to-include-managed-app-debugging-capability", + "NF_FEATURE_RTC": "OFF-default-ON-to-enable-hardware-RTC", + "NF_FEATURE_USE_APPDOMAINS": "OFF-default-ON-to-enable-support-for-Application-Domains", + "NF_FEATURE_SUPPORT_REFLECTION": "ON-default-OFF-to-disable-support-for-System.Reflection-API", + "NF_FEATURE_WATCHDOG": "ON-to-enable-hardware-watchdog-ON-is-default", + "NF_FEATURE_HAS_CONFIG_BLOCK": "OFF-default-ON-to-enable-configuration-block-storage", + "NF_FEATURE_HAS_SDCARD": "OFF-default-ON-to-enable-support-for-SDCard-storage-device", + "NF_FEATURE_HAS_USB_MSD": "OFF-default-ON-to-enable-support-for-USB-Mass-storage-device", + "NF_FEATURE_USE_SPIFFS": "OFF-default-ON-to-enable-support-for-SPI-flash-file-system", + "NF_PLATFORM_NO_CLR_TRACE": "OFF-default-ON-to-disable-all-trace-on-CLR", + "NF_CLR_NO_IL_INLINE": "OFF-default-ON-to-disable-CLR-IL-inlining", + "NF_INTEROP_ASSEMBLIES": "assembly-namespaces-separated-by-whitespace-leave-empty-to-NOT-include-any-interop-assemblies", + "NF_NETWORKING_SNTP": "ON-default-to-add-SNTP-client-requires-networking", + "NF_SECURITY_MBEDTLS": "OFF-default-ON-to-add-network-security-from-mbedTLS", + "MBEDTLS_SOURCE": "", + "API_nanoFramework.Devices.Can": "OFF-default-ON-to-add-this-API", + "API_nanoFramework.Devices.OneWire": "OFF-default-ON-to-add-this-API", + "API_nanoFramework.ResourceManager": "OFF-default-ON-to-add-this-API", + "API_nanoFramework.System.Collections": "OFF-default-ON-to-add-this-API", + "API_nanoFramework.System.Text": "OFF-default-ON-to-add-this-API", + "API_System.Math": "OFF-default-ON-to-add-this-API", + "API_System.Net": "OFF-default-ON-to-add-this-API", + "API_Windows.Devices.Adc": "OFF-default-ON-to-add-this-API", + "API_System.Device.Dac": "OFF-default-ON-to-add-this-API", + "API_Windows.Devices.Gpio": "OFF-default-ON-to-add-this-API", + "API_Windows.Devices.I2c": "OFF-default-ON-to-add-this-API", + "API_Windows.Devices.Pwm": "OFF-default-ON-to-add-this-API", + "API_Windows.Devices.SerialCommunication": "OFF-default-ON-to-add-this-API", + "API_Windows.Devices.Spi": "OFF-default-ON-to-add-this-API", + "API_Windows.Networking.Sockets": "OFF-default-ON-to-add-this-API", + "API_Hardware.Esp32": "OFF-default-ON-to-add-this-API", + "API_Hardware.Stm32": "OFF-default-ON-to-add-this-API", + "API_nanoFramework.TI.EasyLink": "OFF-default-ON-to-add-this-API", + "API_nanoFramework.Hardware.Esp32.Rmt": "OFF-default-ON-to-add-this-API" + } + } + } + } +} diff --git a/.vscode/launch.TEMPLATE-ESP32.json b/.vscode/launch.TEMPLATE-ESP32.json deleted file mode 100644 index c5a8ed25c4..0000000000 --- a/.vscode/launch.TEMPLATE-ESP32.json +++ /dev/null @@ -1,76 +0,0 @@ -{ - "version": "0.2.0", - "configurations": [ - { - "name": "ESP32 nanoCLR - OLimex OCD-H", - "type": "cppdbg", - "request": "launch", - "MIMode": "gdb", - "miDebuggerPath": "/xtensa-esp32-elf/bin/xtensa-esp32-elf-gdb.exe", - "stopAtEntry":true, - "program": "/nanoCLR.elf", - - "setupCommands": [ - {"description":"" , "text" : "set logging on"}, - {"description":"" , "text" : "target extended-remote localhost:3333"}, - {"description":"" , "text" : "file /nanoCLR.elf"}, - {"description":"" , "text" : "monitor reset halt"}, - {"description":"" , "text" : "thb app_main"}, - {"description":"" , "text" : "x $a1=0"} - ], - - "launchCompleteCommand": "exec-run", - "debugServerPath": "/bin/openocd.exe", - "debugServerArgs": "-s \"/share/openocd/scripts/\" -f interface/ftdi/olimex-arm-usb-ocd-h.cfg -f target/esp32.cfg -c \"adapter_khz 3000\" " , - "serverStarted": "Info : .*Tensilica.*0x1.", - "filterStderr": true, - "externalConsole": true, - "cwd": "${cwd}", - - "logging": { - "trace": true, - "traceResponse": true, - "engineLogging": true, - "programOutput": true, - "exceptions": true, - "moduleLoad": true - } - }, - { - "name": "ESP32 nanoCLR - Wrover", - "type": "cppdbg", - "request": "launch", - "MIMode": "gdb", - "miDebuggerPath": "/xtensa-esp32-elf/bin/xtensa-esp32-elf-gdb.exe", - "stopAtEntry":true, - "program": "/nanoCLR.elf", - - "setupCommands": [ - {"description":"" , "text" : "set logging on"}, - {"description":"" , "text" : "target extended-remote localhost:3333"}, - {"description":"" , "text" : "file /nanoCLR.elf"}, - {"description":"" , "text" : "monitor reset halt"}, - {"description":"" , "text" : "thb app_main"}, - {"description":"" , "text" : "x $a1=0"} - ], - - "launchCompleteCommand": "exec-run", - "debugServerPath": "/bin/openocd.exe", - "debugServerArgs": "-s \"/share/openocd/scripts/\" -f interface/ftdi/esp32_devkitj_v1.cfg -f target/esp32.cfg -c \"adapter_khz 2000\" " , - "serverStarted": "Info : .*Tensilica.*0x1.", - "filterStderr": true, - "externalConsole": true, - "cwd": "${cwd}", - - "logging": { - "trace": true, - "traceResponse": true, - "engineLogging": true, - "programOutput": true, - "exceptions": true, - "moduleLoad": true - } - } - - ] -} diff --git a/.vscode/launch.TEMPLATE-MIMXRT1060.json b/.vscode/launch.TEMPLATE-MIMXRT1060.json deleted file mode 100644 index 00af7985b2..0000000000 --- a/.vscode/launch.TEMPLATE-MIMXRT1060.json +++ /dev/null @@ -1,49 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": "MIMXRT1060 Launch", - "type": "cppdbg", - "request": "launch", - "program": "${workspaceFolder}/Build/nanoCLR.elf", - "stopAtEntry": false, - "cwd": "${workspaceFolder}", - "environment": [], - "externalConsole": true, - "MIMode": "gdb", - "miDebuggerPath": "C:/nanoFramework_Tools/GNU_ARM_Toolchain/7 2018-q2-update/bin/arm-none-eabi-gdb.exe", - "setupCommands": [ - {"text": "set breakpoint pending on"}, - {"text": "-enable-pretty-printing"}, - {"text": "set python print-stack none"}, - {"text": "set print object on"}, - {"text": "set print sevenbit-strings on"}, - {"text": "set charset ISO-8859-1"}, - {"text": "set auto-solib-add on"}, - {"text": "file C:/nanoFramework/nf-interpreter/Build/nanoCLR.elf"}, - {"text": "set non-stop on"}, - {"text": "set pagination off"}, - {"text": "set mi-async"}, - {"text": "set remotetimeout 60"}, - {"text": "target extended-remote | C:/nxp/MCUXpressoIDE_10.2.1_795/ide/bin/crt_emu_cm_redlink.exe -g -mi -2 -pMIMXRT1062xxxxA -vendor=NXP --reset= -cache=disable --flash-dir=C:/nxp/MCUXpressoIDE_10.2.1_795/ide/bin/Flash --flash-driver=MIMXRT1060_SFDP_QSPI.cfx --no-packed"}, - {"text": "set mem inaccessible-by-default off"}, - {"text": "mon ondisconnect cont"}, - {"text": "set arm force-mode thumb"}, - {"text": "set remote hardware-breakpoint-limit 6"}, - {"text": "mon semihost enable"}, - {"text": "load"}, - {"text": "thbreak main"}, -// {"text": "continue"}, - - // {"text": "monitor run"} - ], - "launchCompleteCommand" : "None", - "logging": { - "engineLogging": false - } - }, - ] -} \ No newline at end of file diff --git a/.vscode/launch.TEMPLATE.json b/.vscode/launch.TEMPLATE.json index 12bd0344bb..71b4c5cdb3 100644 --- a/.vscode/launch.TEMPLATE.json +++ b/.vscode/launch.TEMPLATE.json @@ -5,7 +5,7 @@ "name": "name the launch configuration 1 (booter) here", "type": "cppdbg", "request": "launch", - "miDebuggerPath": "", + "miDebuggerPath": "", "targetArchitecture": "ARM", "program": "/nanoBooter.elf", @@ -24,8 +24,8 @@ ], "launchCompleteCommand": "exec-continue", - "debugServerPath": "/bin/openocd.exe", - "debugServerArgs": "-s \"/share/openocd/scripts/\" -f interface/.cfg -f board/.cfg", + "debugServerPath": "/bin/openocd.exe", + "debugServerArgs": "-s \"/share/openocd/scripts/\" -f interface/.cfg -f board/.cfg", "serverStarted": "Info\\ :\\ [\\w\\d\\.]*:\\ hardware", "filterStderr": true, "externalConsole": true, @@ -41,7 +41,7 @@ "name": "name the launch configuration 2 (CLR) here", "type": "cppdbg", "request": "launch", - "miDebuggerPath": "", + "miDebuggerPath": "", "targetArchitecture": "ARM", "program": "/nanoCLR.elf", @@ -60,8 +60,8 @@ ], "launchCompleteCommand": "exec-continue", - "debugServerPath": "/bin/openocd.exe", - "debugServerArgs": "-s \"/share/openocd/scripts/\" -f interface/.cfg -f board/.cfg", + "debugServerPath": "/bin/openocd.exe", + "debugServerArgs": "-s \"/share/openocd/scripts/\" -f interface/.cfg -f board/.cfg", "serverStarted": "Info\\ :\\ [\\w\\d\\.]*:\\ hardware", "filterStderr": true, "externalConsole": true, @@ -89,7 +89,7 @@ {"description":"" , "text" : "continue", "ignoreFailures": true } ], - "miDebuggerPath": "", + "miDebuggerPath": "", "targetArchitecture": "ARM", "program": "${workspaceRoot}/build/nanoCLR.elf", diff --git a/.vscode/tasks.TEMPLATE-ESP32.json b/.vscode/tasks.TEMPLATE-ESP32.json deleted file mode 100644 index 58d722806e..0000000000 --- a/.vscode/tasks.TEMPLATE-ESP32.json +++ /dev/null @@ -1,47 +0,0 @@ -{ - // See https://go.microsoft.com/fwlink/?LinkId=733558 - // for the documentation about the tasks.json format - "version": "2.0.0", - "tasks": [ - { - "taskName": "Flash nanoCLR ", - "type": "shell", - "command": "python /components/esptool_py/esptool/esptool.py --chip esp32 --port \"\" --baud 921600 --before \"default_reset\" --after \"hard_reset\" write_flash -z --flash_mode \"dio\" --flash_freq \"40m\" --flash_size detect 0x1000 /bootloader.bin 0x10000 /nanoCLR.bin 0x8000 /partitions_4mb.bin", - "presentation": { - "reveal": "always", - "panel": "shared" - }, - "problemMatcher": [] - }, - { - "taskName": "Erase flash ", - "type": "shell", - "command": "python /components/esptool_py/esptool/esptool.py --chip esp32 --port \"\" --baud 115200 --before \"default_reset\" --after \"hard_reset\" erase_flash", - "presentation": { - "reveal": "always", - "panel": "shared" - }, - "problemMatcher": [] - }, - { - "taskName": "Flash nanoCLR Wrover ", - "type": "shell", - "command": "python /components/esptool_py/esptool/esptool.py --chip esp32 --port \"\" --baud 921600 --before \"default_reset\" --after \"hard_reset\" write_flash -z --flash_mode \"dio\" --flash_freq \"40m\" --flash_size detect 0x1000 /bootloader.bin 0x10000 /nanoCLR.bin 0x8000 /partitions_4mb.bin", - "presentation": { - "reveal": "always", - "panel": "shared" - }, - "problemMatcher": [] - }, - { - "taskName": "Flash nanoCLR ESP32-EVB ", - "type": "shell", - "command": "python /components/esptool_py/esptool/esptool.py --chip esp32 --port \"\" --baud 921600 --before \"default_reset\" --after \"hard_reset\" write_flash -z --flash_mode \"dio\" --flash_freq \"40m\" --flash_size detect 0x1000 /bootloader.bin 0x10000 /nanoCLR.bin 0x8000 /partitions_4mb.bin", - "presentation": { - "reveal": "always", - "panel": "shared" - }, - "problemMatcher": [] - } - ] -} \ No newline at end of file diff --git a/.vscode/tasks.TEMPLATE-MIMXRT1060.json b/.vscode/tasks.TEMPLATE-MIMXRT1060.json deleted file mode 100644 index 2da995919d..0000000000 --- a/.vscode/tasks.TEMPLATE-MIMXRT1060.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - // See https://go.microsoft.com/fwlink/?LinkId=733558 - // for the documentation about the tasks.json format - "version": "2.0.0", - "tasks": [ - { - "label": "Flash MIMXRT1060", - "type": "shell", - "command": "C:/nxp/MCUXpressoIDE_10.2.1_795/ide/bin/crt_emu_cm_redlink.exe", - "options": { - "cwd": "${workspaceFolder}/Build" - }, - "args": [ - "-pMIMXRT1062xxxxA", - "--vendor=NXP", - "--flash-dir=C:/nxp/MCUXpressoIDE_10.2.1_795/ide/bin/Flash", - "--flash-driver=MIMXRT1060_SFDP_QSPI.cfx", - "--flash-load=nanoBooter.elf", - "--rst" - ], - "presentation": { - "reveal": "always", - "panel": "dedicated" - }, - "problemMatcher": [] - } - ] -} \ No newline at end of file diff --git a/.vscode/tasks.TEMPLATE.json b/.vscode/tasks.TEMPLATE.json new file mode 100644 index 0000000000..5a7bf08942 --- /dev/null +++ b/.vscode/tasks.TEMPLATE.json @@ -0,0 +1,85 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "Install nanoFramework tools", + "type": "shell", + "group": "none", + "presentation": { + "echo": true, + "reveal": "always", + "focus": false, + "panel": "shared", + "showReuseMessage": true, + "clear": false + }, + "command": "install-scripts\\install-nf-tools.ps1 -TargetSeries ${input:targetSeries} -Path '${input:toolsPath}' " + }, + { + "label": "Flash nanoCLR to ESP32", + "type": "shell", + "command": "python /components/esptool_py/esptool/esptool.py --chip esp32 --port \"${input:comPort}\" --baud 921600 --before \"default_reset\" --after \"hard_reset\" write_flash -z --flash_mode \"dio\" --flash_freq \"40m\" --flash_size detect 0x1000 /bootloader.bin 0x10000 /nanoCLR.bin 0x8000 /partitions_4mb.bin", + "presentation": { + "reveal": "always", + "panel": "shared" + }, + "problemMatcher": [] + }, + { + "label": "Erase ESP32 flash", + "type": "shell", + "command": "python /components/esptool_py/esptool/esptool.py --chip esp32 --port \"${input:comPort}\" --baud 921600 --before \"default_reset\" --after \"hard_reset\" erase_flash", + "presentation": { + "reveal": "always", + "panel": "shared" + }, + "problemMatcher": [] + }, + { + "label": "Flash MIMXRT1060", + "type": "shell", + "command": "C:/nxp/MCUXpressoIDE_10.2.1_795/ide/bin/crt_emu_cm_redlink.exe", + "options": { + "cwd": "${workspaceFolder}/Build" + }, + "args": [ + "-pMIMXRT1062xxxxA", + "--vendor=NXP", + "--flash-dir=C:/nxp/MCUXpressoIDE_10.2.1_795/ide/bin/Flash", + "--flash-driver=MIMXRT1060_SFDP_QSPI.cfx", + "--flash-load=nanoBooter.elf", + "--rst" + ], + "presentation": { + "reveal": "always", + "panel": "dedicated" + }, + "problemMatcher": [] + } + ], + "inputs": [ + { + "id": "toolsPath", + "type": "promptString", + "default": "C:\nftools", + "description": "Path where to install the tools." + }, + { + "id": "targetSeries", + "type": "pickString", + "description": "Series of the target to install the tools for.", + "options": [ + "ESP32", + "STM32", + "NXP", + "TI" + ] + }, + { + "id": "comPort", + "type": "promptString", + "default": "COM1", + "description": "COM port of the ESP32 device." + } + ] +} \ No newline at end of file diff --git a/CMake/CMSIS.CMakeLists.cmake.in b/CMake/CMSIS.CMakeLists.cmake.in index 03ce0efa94..443b446e9b 100644 --- a/CMake/CMSIS.CMakeLists.cmake.in +++ b/CMake/CMSIS.CMakeLists.cmake.in @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/ChibiOS-Contrib.CMakeLists.cmake.in b/CMake/ChibiOS-Contrib.CMakeLists.cmake.in index 0b14e4e0bb..1c44fb9aa7 100644 --- a/CMake/ChibiOS-Contrib.CMakeLists.cmake.in +++ b/CMake/ChibiOS-Contrib.CMakeLists.cmake.in @@ -1,8 +1,10 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # +cmake_minimum_required(VERSION 3.15) + project(ChibiOS-Contrib-download NONE) include(ExternalProject) diff --git a/CMake/ChibiOS.CMakeLists.cmake.in b/CMake/ChibiOS.CMakeLists.cmake.in index e6bf3b424b..222ec4f735 100644 --- a/CMake/ChibiOS.CMakeLists.cmake.in +++ b/CMake/ChibiOS.CMakeLists.cmake.in @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # @@ -15,7 +15,7 @@ ExternalProject_Add( PREFIX ChibiOS SOURCE_DIR ${CMAKE_BINARY_DIR}/ChibiOS_Source GIT_REPOSITORY https://github.com/nanoframework/chibios - GIT_TAG ${CHIBIOS_GIT_TAG} # target specified branch + GIT_TAG ${RTOS_VERSION} # target specified branch GIT_SHALLOW 1 # download only the tip of the branch, not the complete history TIMEOUT 10 LOG_DOWNLOAD 1 diff --git a/CMake/ChibiOS_target_os.h.in b/CMake/ChibiOS_target_os.h.in index 5e4e5f3774..246dd4f792 100644 --- a/CMake/ChibiOS_target_os.h.in +++ b/CMake/ChibiOS_target_os.h.in @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/CMake/ESP32_target_os.h.in b/CMake/ESP32_target_os.h.in index 61e628f769..07826c9c4b 100644 --- a/CMake/ESP32_target_os.h.in +++ b/CMake/ESP32_target_os.h.in @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/CMake/FatFS.CMakeLists.cmake.in b/CMake/FatFS.CMakeLists.cmake.in index e23ce137bd..719a521f07 100644 --- a/CMake/FatFS.CMakeLists.cmake.in +++ b/CMake/FatFS.CMakeLists.cmake.in @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/FreeRTOS.CMakeLists.cmake.in b/CMake/FreeRTOS.CMakeLists.cmake.in index a1d43fda5a..c54edf708c 100644 --- a/CMake/FreeRTOS.CMakeLists.cmake.in +++ b/CMake/FreeRTOS.CMakeLists.cmake.in @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # @@ -15,7 +15,7 @@ ExternalProject_Add( PREFIX FreeRTOS SOURCE_DIR ${CMAKE_BINARY_DIR}/FreeRTOS_Source GIT_REPOSITORY https://github.com/FreeRTOS/FreeRTOS-Kernel.git - GIT_TAG ${FREERTOS_VERSION_TAG} # target specified branch + GIT_TAG ${RTOS_VERSION} # target specified branch GIT_SHALLOW 1 # download only the tip of the branch, not the complete history TIMEOUT 10 LOG_DOWNLOAD 1 diff --git a/CMake/FreeRTOS_target_os.h.in b/CMake/FreeRTOS_target_os.h.in index 800c17416a..69e1dda997 100644 --- a/CMake/FreeRTOS_target_os.h.in +++ b/CMake/FreeRTOS_target_os.h.in @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/CMake/LWIP.CMakeLists.cmake.in b/CMake/LWIP.CMakeLists.cmake.in index 323b262f91..e94b755c27 100644 --- a/CMake/LWIP.CMakeLists.cmake.in +++ b/CMake/LWIP.CMakeLists.cmake.in @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/Modules/CHIBIOS_STM32F0xx_GCC_options.cmake b/CMake/Modules/CHIBIOS_STM32F0xx_GCC_options.cmake index 0ebf94976d..b2331e37d1 100644 --- a/CMake/Modules/CHIBIOS_STM32F0xx_GCC_options.cmake +++ b/CMake/Modules/CHIBIOS_STM32F0xx_GCC_options.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/Modules/CHIBIOS_STM32F0xx_sources.cmake b/CMake/Modules/CHIBIOS_STM32F0xx_sources.cmake index 86a435fca9..1401b6ae21 100644 --- a/CMake/Modules/CHIBIOS_STM32F0xx_sources.cmake +++ b/CMake/Modules/CHIBIOS_STM32F0xx_sources.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # @@ -77,7 +77,9 @@ foreach(SRC_FILE ${CHIBIOS_PORT_SRCS}) CMAKE_FIND_ROOT_PATH_BOTH ) - # message("${SRC_FILE} >> ${CHIBIOS_F0_SRC_FILE}") # debug helper + if (BUILD_VERBOSE) + message("${SRC_FILE} >> ${CHIBIOS_F0_SRC_FILE}") # debug helper + endif() list(APPEND CHIBIOS_SOURCES ${CHIBIOS_F0_SRC_FILE}) endforeach() diff --git a/CMake/Modules/CHIBIOS_STM32F4xx_GCC_options.cmake b/CMake/Modules/CHIBIOS_STM32F4xx_GCC_options.cmake index 7ff1c3f310..b0c4ad6f69 100644 --- a/CMake/Modules/CHIBIOS_STM32F4xx_GCC_options.cmake +++ b/CMake/Modules/CHIBIOS_STM32F4xx_GCC_options.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/Modules/CHIBIOS_STM32F4xx_sources.cmake b/CMake/Modules/CHIBIOS_STM32F4xx_sources.cmake index 8a25d5ea18..a13983b0db 100644 --- a/CMake/Modules/CHIBIOS_STM32F4xx_sources.cmake +++ b/CMake/Modules/CHIBIOS_STM32F4xx_sources.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # @@ -86,7 +86,9 @@ foreach(SRC_FILE ${CHIBIOS_PORT_SRCS}) CMAKE_FIND_ROOT_PATH_BOTH ) - # message("${SRC_FILE} >> ${CHIBIOS_F4_SRC_FILE}") # debug helper + if (BUILD_VERBOSE) + message("${SRC_FILE} >> ${CHIBIOS_F4_SRC_FILE}") # debug helper + endif() list(APPEND CHIBIOS_SOURCES ${CHIBIOS_F4_SRC_FILE}) endforeach() diff --git a/CMake/Modules/CHIBIOS_STM32F7xx_GCC_options.cmake b/CMake/Modules/CHIBIOS_STM32F7xx_GCC_options.cmake index 8bf0f38e8f..06f69103fc 100644 --- a/CMake/Modules/CHIBIOS_STM32F7xx_GCC_options.cmake +++ b/CMake/Modules/CHIBIOS_STM32F7xx_GCC_options.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/Modules/CHIBIOS_STM32F7xx_sources.cmake b/CMake/Modules/CHIBIOS_STM32F7xx_sources.cmake index f3b2ff2c3a..15b299fd1b 100644 --- a/CMake/Modules/CHIBIOS_STM32F7xx_sources.cmake +++ b/CMake/Modules/CHIBIOS_STM32F7xx_sources.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # @@ -87,7 +87,9 @@ foreach(SRC_FILE ${CHIBIOS_PORT_SRCS}) CMAKE_FIND_ROOT_PATH_BOTH ) - # message("${SRC_FILE} >> ${CHIBIOS_F7_SRC_FILE}") # debug helper + if (BUILD_VERBOSE) + message("${SRC_FILE} >> ${CHIBIOS_F7_SRC_FILE}") # debug helper + endif() list(APPEND CHIBIOS_SOURCES ${CHIBIOS_F7_SRC_FILE}) endforeach() diff --git a/CMake/Modules/CHIBIOS_STM32H7xx_GCC_options.cmake b/CMake/Modules/CHIBIOS_STM32H7xx_GCC_options.cmake index 8bf0f38e8f..06f69103fc 100644 --- a/CMake/Modules/CHIBIOS_STM32H7xx_GCC_options.cmake +++ b/CMake/Modules/CHIBIOS_STM32H7xx_GCC_options.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/Modules/CHIBIOS_STM32H7xx_sources.cmake b/CMake/Modules/CHIBIOS_STM32H7xx_sources.cmake index d31fd89ebf..92c5572a3f 100644 --- a/CMake/Modules/CHIBIOS_STM32H7xx_sources.cmake +++ b/CMake/Modules/CHIBIOS_STM32H7xx_sources.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # @@ -88,7 +88,9 @@ foreach(SRC_FILE ${CHIBIOS_PORT_SRCS}) CMAKE_FIND_ROOT_PATH_BOTH ) - # message("${SRC_FILE} >> ${CHIBIOS_H7_SRC_FILE}") # debug helper + if (BUILD_VERBOSE) + message("${SRC_FILE} >> ${CHIBIOS_H7_SRC_FILE}") # debug helper + endif() list(APPEND CHIBIOS_SOURCES ${CHIBIOS_H7_SRC_FILE}) endforeach() diff --git a/CMake/Modules/CHIBIOS_STM32L0xx_GCC_options.cmake b/CMake/Modules/CHIBIOS_STM32L0xx_GCC_options.cmake index 322aa15103..385dc884f1 100644 --- a/CMake/Modules/CHIBIOS_STM32L0xx_GCC_options.cmake +++ b/CMake/Modules/CHIBIOS_STM32L0xx_GCC_options.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2018 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/Modules/CHIBIOS_STM32L0xx_sources.cmake b/CMake/Modules/CHIBIOS_STM32L0xx_sources.cmake index fe07cfc4b6..6a3242f66f 100644 --- a/CMake/Modules/CHIBIOS_STM32L0xx_sources.cmake +++ b/CMake/Modules/CHIBIOS_STM32L0xx_sources.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2018 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # @@ -77,7 +77,9 @@ foreach(SRC_FILE ${CHIBIOS_PORT_SRCS}) CMAKE_FIND_ROOT_PATH_BOTH ) - # message("${SRC_FILE} >> ${CHIBIOS_L0_SRC_FILE}") # debug helper + if (BUILD_VERBOSE) + message("${SRC_FILE} >> ${CHIBIOS_L0_SRC_FILE}") # debug helper + endif() list(APPEND CHIBIOS_SOURCES ${CHIBIOS_L0_SRC_FILE}) endforeach() diff --git a/CMake/Modules/CHIBIOS_STM32L4xx_GCC_options.cmake b/CMake/Modules/CHIBIOS_STM32L4xx_GCC_options.cmake new file mode 100644 index 0000000000..8062907d88 --- /dev/null +++ b/CMake/Modules/CHIBIOS_STM32L4xx_GCC_options.cmake @@ -0,0 +1,47 @@ +# +# Copyright (c) .NET Foundation and Contributors +# See LICENSE file in the project root for full license information. +# + +################################################################# +# WHEN ADDING A NEW SERIES add the appropriate GCC options below +################################################################# + +# need to specify this for assembler +set(CMAKE_ASM_FLAGS " -mthumb -mcpu=cortex-m4 -x assembler-with-cpp" CACHE INTERNAL "asm compiler flags") + +# need to specify linker flags here +set(CMAKE_EXE_LINKER_FLAGS " -Wl,--gc-sections -Wl,--no-wchar-size-warning -Wl,--print-memory-usage -mthumb -mcpu=cortex-m4 -mfpu=fpv5-sp-d16 -mfloat-abi=hard -mabi=aapcs -nostartfiles " CACHE INTERNAL "executable linker flags") + + +function(NF_SET_COMPILER_OPTIONS TARGET) + + # include any extra options coming from any extra args? + target_compile_options(${TARGET} PUBLIC ${ARGN} -mthumb -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mabi=aapcs -nostdlib -Wall -Wextra -Werror -ffunction-sections -fshort-wchar -falign-functions=16 -fdata-sections -fno-builtin -fno-common -fomit-frame-pointer -mlong-calls -fdollars-in-identifiers -fno-exceptions -fno-unroll-loops -frounding-math -fsignaling-nans -ffloat-store -fno-math-errno -ftree-vectorize -fcheck-new ) + + # this series has FPU + target_compile_definitions(${TARGET} PUBLIC -DCORTEX_USE_FPU=TRUE) + +endfunction() + + +function(NF_SET_LINKER_OPTIONS TARGET) + + # request specs from newlib nano + set_property(TARGET ${TARGET} APPEND_STRING PROPERTY LINK_FLAGS " --specs=nano.specs ") + + # set extra linker flags + set_property(TARGET ${TARGET} APPEND_STRING PROPERTY LINK_FLAGS " ${ARGN}") + + # set optimization linker flags for RELEASE and MinSizeRel + if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "MinSizeRel") + set_property(TARGET ${TARGET} APPEND_STRING PROPERTY LINK_FLAGS " -flto -fuse-linker-plugin -Os") + endif() + + # set optimization flags + nf_set_optimization_options(${TARGET}) + + # set link map + nf_set_link_map(${TARGET}) + +endfunction() diff --git a/CMake/Modules/CHIBIOS_STM32L4xx_sources.cmake b/CMake/Modules/CHIBIOS_STM32L4xx_sources.cmake new file mode 100644 index 0000000000..3216b207cf --- /dev/null +++ b/CMake/Modules/CHIBIOS_STM32L4xx_sources.cmake @@ -0,0 +1,168 @@ +# +# Copyright (c) .NET Foundation and Contributors +# See LICENSE file in the project root for full license information. +# + +# from startup_stm32L4xx.mk +# List of the ChibiOS generic STM32L4xx startup and CMSIS files. + +################################################################################################ +# WHEN ADDING A NEW BOARD add the source code file for the hal/ports/STM32/STM32L4xx/platform.mk +################################################################################################ + +set(CHIBIOS_PORT_SRCS + # startup code + crt1.c + vectors.S + crt0_v7m.S + + nvic.c + stm32_isr.c + hal_lld.c + + hal_adc_lld.c + hal_can_lld.c + hal_crypto_lld.c + hal_dac_lld.c + stm32_dma.c + stm32_exti.c + hal_pal_lld.c + hal_i2c_lld.c + #hal_mac_lld.c + hal_usb_lld.c + hal_wspi_lld.c + hal_trng_lld.c + hal_rtc_lld.c + hal_sdc_lld.c + + hal_i2s_lld.c + hal_spi_lld.c + + hal_st_lld.c + hal_gpt_lld.c + hal_icu_lld.c + hal_pwm_lld.c + + hal_serial_lld.c + hal_uart_lld.c + + hal_wdg_lld.c + + # RT + chcore.c + chcore_v7m.c + chcoreasm_v7m.S +) + +foreach(SRC_FILE ${CHIBIOS_PORT_SRCS}) + set(CHIBIOS_L4_SRC_FILE SRC_FILE-NOTFOUND) + find_file(CHIBIOS_L4_SRC_FILE ${SRC_FILE} + PATHS + + ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/common/ports/ARMCMx/compilers/GCC + ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/common/startup/ARMCMx/compilers/GCC + ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/common/ports/ARMCMx + ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/common/ARMCMx + + ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/STM32F4xx + ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/ADCv3 + ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/CANv1 + ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/CRYPv1 + ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/DACv1 + ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/DMAv1 + ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/EXTIv1 + ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/GPIOv3 + ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/I2Cv2 + #${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/MACv1 + ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/OTGv1 + ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/QUADSPIv1 + ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/RNGv1 + ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/RTCv2 + ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/SDMMCv1 + ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/SPIv2 + ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/TIMv1 + ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/USARTv2 + ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/xWDGv1 + + CMAKE_FIND_ROOT_PATH_BOTH + ) + if (BUILD_VERBOSE) + message("${SRC_FILE} >> ${CHIBIOS_L4_SRC_FILE}") # debug helper + endif() + list(APPEND CHIBIOS_SOURCES ${CHIBIOS_L4_SRC_FILE}) +endforeach() + +list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/common/portability/GCC) +list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/common/startup/ARMCMx/compilers/GCC) +list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/common/startup/ARMCMx/devices/STM32L4xx) +list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/common/ext/ARM/CMSIS/Core/Include) +list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/common/ext/ST/STM32L4xx) + +list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/ADCv3) +list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/CANv1) +list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/CRYPv1) +list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/DACv1) +list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/DMAv1) +list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/EXTIv1) +list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/GPIOv3) +list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/I2Cv2) +#list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/MACv1) +list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/OTGv1) +list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/QUADSPIv1) +list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/RNGv1) +list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/RTCv2) +list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/SDMMCv1) +list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/SPIv2) +list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/TIMv1) +list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/USARTv2) +list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/xWDGv1) + + +#################################################################################### +# WHEN ADDING A NEW CHIBIOS OVERLAY component add the include directory(ies) below +#################################################################################### +# component STM32_FLASH +list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FLASHv2) +# component STM32_CRC +list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/CRCv1) +# component STM32_RNG +list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/RNGv1) +# component STM32_FSMC (Flexible Memory Controller) +list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FSMCv1) +# component STM32_ONEWIRE (One Wire driver) +list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/ONEWIREv1) +# component STM32_QSPI (Quad-SPI) +list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/QSPIv1) + +############################################################################################################################### +# Add above the required include directory(ies) for a new nanoFramework overlay component that you are adding +# following the template below. +# +# list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/) +############################################################################################################################### + + +#################################################################################################### +# WHEN ADDING A NEW CHIBIOS OVERLAY component add the source file(s) specific to this series below +#################################################################################################### +# component STM32_FLASH +list(APPEND ChibiOSnfOverlay_SOURCES ${PROJECT_SOURCE_DIR}/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FLASHv2/flash_lld.c) +# component STM32_CRC +list(APPEND ChibiOSnfOverlay_SOURCES ${PROJECT_SOURCE_DIR}/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/CRCv1/crc_lld.c) +# component STM32_RNG +list(APPEND ChibiOSnfOverlay_SOURCES ${PROJECT_SOURCE_DIR}/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/RNGv1/rng_lld.c) +# component STM32_FSMC (Flexible Memory Controller) +list(APPEND ChibiOSnfOverlay_SOURCES ${PROJECT_SOURCE_DIR}/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FSMCv1/fsmc_nand_lld.c) +list(APPEND ChibiOSnfOverlay_SOURCES ${PROJECT_SOURCE_DIR}/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FSMCv1/fsmc_sdram_lld.c) +list(APPEND ChibiOSnfOverlay_SOURCES ${PROJECT_SOURCE_DIR}/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FSMCv1/fsmc_sram_lld.c) +# component STM32_ONEWIRE +list(APPEND ChibiOSnfOverlay_SOURCES ${PROJECT_SOURCE_DIR}/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/ONEWIREv1/onewire_lld.c) +# component STM32_QSPI (Quad-SPI) +list(APPEND ChibiOSnfOverlay_SOURCES ${PROJECT_SOURCE_DIR}/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/QSPIv1/qspi_lld.c) + +########################################################################################################################## +# Add above ALL the source code file(s) low level driver specif for a series required for a new nanoFramework +# overlay component that you are adding following the template below. +# +# list(APPEND CHIBIOS_SOURCES ${PROJECT_SOURCE_DIR}/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/src/) +########################################################################################################################## diff --git a/CMake/Modules/FindBuildUtils.cmake b/CMake/Modules/FindBuildUtils.cmake index eeb1b4394d..247ffc3f8d 100644 --- a/CMake/Modules/FindBuildUtils.cmake +++ b/CMake/Modules/FindBuildUtils.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/Modules/FindCHIBIOS.cmake b/CMake/Modules/FindCHIBIOS.cmake index 41fca7dec4..26445d6644 100644 --- a/CMake/Modules/FindCHIBIOS.cmake +++ b/CMake/Modules/FindCHIBIOS.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # @@ -9,7 +9,7 @@ # check if the series name is supported -set(CHIBIOS_STM_SUPPORTED_SERIES "STM32F0xx" "STM32F4xx" "STM32F7xx" "STM32H7xx" "TICC3200" CACHE INTERNAL "supported STM series names for ChibiOS") +set(CHIBIOS_STM_SUPPORTED_SERIES "STM32F0xx" "STM32F4xx" "STM32F7xx" "STM32H7xx" "TICC3200" "STM32L4xx" CACHE INTERNAL "supported STM series names for ChibiOS") set(CHIBIOS_TI_SUPPORTED_SERIES "TICC3200" CACHE INTERNAL "supported TI series names for ChibiOS") list(FIND CHIBIOS_STM_SUPPORTED_SERIES ${TARGET_SERIES} TARGET_SERIES_NAME_INDEX) @@ -171,11 +171,13 @@ foreach(SRC_FILE ${CHIBIOS_SRCS}) CMAKE_FIND_ROOT_PATH_BOTH ) - #message("${SRC_FILE} >> ${CHIBIOS_SRC_FILE}") # debug helper + if (BUILD_VERBOSE) + message("${SRC_FILE} >> ${CHIBIOS_SRC_FILE}") # debug helper + endif() list(APPEND CHIBIOS_SOURCES ${CHIBIOS_SRC_FILE}) endforeach() include(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(CHIBIOS DEFAULT_MSG CHIBIOS_INCLUDE_DIRS CHIBIOS_SOURCES) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(ChibiOS DEFAULT_MSG CHIBIOS_INCLUDE_DIRS CHIBIOS_SOURCES) diff --git a/CMake/Modules/FindCHIBIOS_FATFS.cmake b/CMake/Modules/FindCHIBIOS_FATFS.cmake index 27d3808afd..4e99d406e2 100644 --- a/CMake/Modules/FindCHIBIOS_FATFS.cmake +++ b/CMake/Modules/FindCHIBIOS_FATFS.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/Modules/FindCHIBIOS_LWIP.cmake b/CMake/Modules/FindCHIBIOS_LWIP.cmake index 8ad123f178..f24cbf8454 100644 --- a/CMake/Modules/FindCHIBIOS_LWIP.cmake +++ b/CMake/Modules/FindCHIBIOS_LWIP.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/Modules/FindCMSIS.cmake b/CMake/Modules/FindCMSIS.cmake index 443f84a432..07dad6a5fa 100644 --- a/CMake/Modules/FindCMSIS.cmake +++ b/CMake/Modules/FindCMSIS.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/Modules/FindChibiOS-Contrib.cmake b/CMake/Modules/FindChibiOS-Contrib.cmake index 69c5d9ac01..88c3a205f2 100644 --- a/CMake/Modules/FindChibiOS-Contrib.cmake +++ b/CMake/Modules/FindChibiOS-Contrib.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # @@ -43,4 +43,4 @@ list(APPEND CHIBIOS_CONTRIB_SOURCES ${PROJECT_BINARY_DIR}/ChibiOS-Contrib_Source list(APPEND CHIBIOS_CONTRIB_SOURCES ${PROJECT_BINARY_DIR}/ChibiOS-Contrib_Source/os/hal/ports/STM32/LLD/USBHv1/hal_usbh_lld.c) include(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(CHIBIOS_CONTRIB DEFAULT_MSG CHIBIOS_CONTRIB_INCLUDE_DIRS CHIBIOS_CONTRIB_SOURCES) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(ChibiOS-Contrib DEFAULT_MSG CHIBIOS_CONTRIB_INCLUDE_DIRS CHIBIOS_CONTRIB_SOURCES) diff --git a/CMake/Modules/FindChibiOSnfOverlay.cmake b/CMake/Modules/FindChibiOSnfOverlay.cmake index 82aabec235..90be70d880 100644 --- a/CMake/Modules/FindChibiOSnfOverlay.cmake +++ b/CMake/Modules/FindChibiOSnfOverlay.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/Modules/FindFATFS.cmake b/CMake/Modules/FindFATFS.cmake index 085210e5ac..7facd2397e 100644 --- a/CMake/Modules/FindFATFS.cmake +++ b/CMake/Modules/FindFATFS.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/Modules/FindFreeRTOS.cmake b/CMake/Modules/FindFreeRTOS.cmake index 51cc2ea4b9..177f1b5a28 100644 --- a/CMake/Modules/FindFreeRTOS.cmake +++ b/CMake/Modules/FindFreeRTOS.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/Modules/FindLWIP.cmake b/CMake/Modules/FindLWIP.cmake index 521c57d0d4..ff82543287 100644 --- a/CMake/Modules/FindLWIP.cmake +++ b/CMake/Modules/FindLWIP.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/Modules/FindMBEDOS.cmake b/CMake/Modules/FindMBEDOS.cmake deleted file mode 100644 index 65518a6b91..0000000000 --- a/CMake/Modules/FindMBEDOS.cmake +++ /dev/null @@ -1,389 +0,0 @@ -# -# Copyright (c) 2017 The nanoFramework project contributors -# See LICENSE file in the project root for full license information. -# - -include(JSONParser) - -# read mBed targets file -file(READ "${PROJECT_BINARY_DIR}/mBedOS_Source/targets/targets.json" TARGETS_JSON) - -# try to find target -string(FIND ${TARGETS_JSON} ${MBED_TARGET} FOUND_TARGET) - -# message(STATUS "${MBED_TARGET} @ ${FOUND_TARGET}") - -if(${FOUND_TARGET} GREATER -1) - # target found - - message(STATUS "mBed target '${MBED_TARGET}' found") - # get substring with data - math(EXPR FOUND_TARGET "${FOUND_TARGET} - 1") - - # because there is not an elegant way of finding the end of the json section of this target we are setting this to 1000 chars - # the downside is that for most target this overuns to the next target - string(SUBSTRING "${TARGETS_JSON}" ${FOUND_TARGET} 2000 TARGET_TENTATIVE_JSON) -else() - message(FATAL_ERROR "\n\nSorry but ${MBED_TARGET} seems to be missing in the list of the mBed supported targets...\n\n") -endif() - -# parse target data -sbeParseJson(MBED_TARGET_DATA TARGET_TENTATIVE_JSON) - -# try to extract relevant data -foreach(var ${MBED_TARGET_DATA}) - - # sanity check when json parse has overun to the next target - string(FIND ${var} "MBED_TARGET_DATA.${MBED_TARGET}" MBED_TARGET_NAME_FOUND) - if(MBED_TARGET_NAME_FOUND GREATER -1) - - # seems to belong to target, extract data - #message("${var} : ${${var}}") # debug helper - - # core - string(FIND ${var} "core" MBED_TARGET_CORE_INDEX) - if(${MBED_TARGET_CORE_INDEX} GREATER -1) - set(MBED_TARGET_CORE ${${var}}) - endif() - - # extra labels 0 is: target vendor - string(FIND ${var} "MBED_TARGET_DATA.${MBED_TARGET}.extra_labels_0" MBED_TARGET_VENDOR_INDEX) - if(${MBED_TARGET_VENDOR_INDEX} GREATER -1) - set(MBED_TARGET_VENDOR ${${var}}) - endif() - - # extra labels 1 is: target series/variant - string(FIND ${var} "MBED_TARGET_DATA.${MBED_TARGET}.extra_labels_1" MBED_TARGET_SERIES_INDEX) - if(${MBED_TARGET_SERIES_INDEX} GREATER -1) - set(MBED_TARGET_SERIES ${${var}}) - endif() - - # extra labels 2 is used for compiler defs - string(FIND ${var} "MBED_TARGET_DATA.${MBED_TARGET}.extra_labels_2" MBED_TARGET_EXTRA_LABEL2_INDEX) - if(${MBED_TARGET_EXTRA_LABEL2_INDEX} GREATER -1) - set(MBED_TARGET_EXTRA_LABEL2 ${${var}}) - endif() - - # 'macros' lists target aditional macros - string(FIND ${var} "MBED_TARGET_DATA.${MBED_TARGET}.macros_" MBED_TARGET_MACROS_INDEX) - if(${MBED_TARGET_MACROS_INDEX} GREATER -1) - list(APPEND MBED_TARGET_MACROS ${${var}}) - endif() - - # 'device has' lists target features - string(FIND ${var} "MBED_TARGET_DATA.${MBED_TARGET}.device_has_" MBED_TARGET_DEVICE_HAS_INDEX) - if(${MBED_TARGET_DEVICE_HAS_INDEX} GREATER -1) - list(APPEND MBED_TARGET_FEATURES ${${var}}) - endif() - - # 'supported form factors' lists supported form factors for board - string(FIND ${var} "MBED_TARGET_DATA.${MBED_TARGET}.supported_form_factors_" MBED_TARGET_DEVICE_FORM_FACTORS_INDEX) - if(${MBED_TARGET_DEVICE_FORM_FACTORS_INDEX} GREATER -1) - list(APPEND MBED_TARGET_DEVICE_FORM_FACTORS ${${var}}) - endif() - - endif() - -endforeach() - -message("mBed target has ${MBED_TARGET_CORE}") -message("mBed target vendor is ${MBED_TARGET_VENDOR}") -message("mBed target series is ${MBED_TARGET_SERIES}") -#message("mBed target features: ${MBED_TARGET_FEATURES}") - -# get target core short name -string(REPLACE "Cortex-" "" MBED_TARGET_CORE_SHORT ${MBED_TARGET_CORE} ) - -# set compiler options (general) -string(APPEND MBEDOS_COMPILE_OPTIONS "-D__CORTEX_${MBED_TARGET_CORE_SHORT} -D__MBED__=1 -DTARGET_LIKE_MBED -D__MBED_CMSIS_RTOS_CM -DTOOLCHAIN_object -D__CMSIS_RTOS -DTOOLCHAIN_GCC -DTARGET_CORTEX_M -DARM_MATH_C${MBED_TARGET_CORE_SHORT} -DTARGET_${MBED_TARGET_CORE_SHORT} -DTOOLCHAIN_GCC_ARM -DTARGET_RELEASE -DTARGET_LIKE_CORTEX_${MBED_TARGET_CORE_SHORT} -D__CORTEX_${MBED_TARGET_CORE_SHORT} -DTARGET_${MBED_TARGET_VENDOR} -DTARGET_${MBED_TARGET_SERIES} -DTARGET_UVISOR_UNSUPPORTED -DTARGET_${MBED_TARGET}") - -# extra compiler def from extra label 2 -if(MBED_TARGET_EXTRA_LABEL2) - string(APPEND MBEDOS_COMPILE_OPTIONS " -DTARGET_${MBED_TARGET_EXTRA_LABEL2}") -endif() - -# set compiler options (target specific features) -foreach(feature ${MBED_TARGET_FEATURES}) - string(APPEND MBEDOS_COMPILE_OPTIONS " -DDEVICE_${feature}=1") -endforeach() - -# set compiler options (form factors) -foreach(ff ${MBED_TARGET_DEVICE_FORM_FACTORS}) - string(APPEND MBEDOS_COMPILE_OPTIONS " -DTARGET_FF_${ff}") -endforeach() - -# set compiler options (macros) -foreach(macro ${MBED_TARGET_MACROS}) - string(APPEND MBEDOS_COMPILE_OPTIONS " -D${macro}") -endforeach() - -#message(">>MBEDOS_COMPILE_OPTIONS: ${MBEDOS_COMPILE_OPTIONS}<<") # debug helper - -# set include directories for mBed RTOS -list(APPEND MBEDOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/mBedOS_Source) -list(APPEND MBEDOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/mBedOS_Source/cmsis) -list(APPEND MBEDOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/mBedOS_Source/cmsis/TOOLCHAIN_GCC) -list(APPEND MBEDOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/mBedOS_Source/docs) -list(APPEND MBEDOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/mBedOS_Source/drivers) -list(APPEND MBEDOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/mBedOS_Source/events) -list(APPEND MBEDOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/mBedOS_Source/events/equeue) -list(APPEND MBEDOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/mBedOS_Source/features) -list(APPEND MBEDOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/mBedOS_Source/features/frameworks) -list(APPEND MBEDOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/mBedOS_Source/features/frameworks/greentea-client) -list(APPEND MBEDOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/mBedOS_Source/features/frameworks/greentea-client/greentea-client) -list(APPEND MBEDOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/mBedOS_Source/features/frameworks/greentea-client/source) -list(APPEND MBEDOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/mBedOS_Source/features/frameworks/unity) -list(APPEND MBEDOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/mBedOS_Source/features/frameworks/unity/source) -list(APPEND MBEDOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/mBedOS_Source/features/frameworks/unity/unity) -list(APPEND MBEDOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/mBedOS_Source/features/frameworks/utest) -list(APPEND MBEDOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/mBedOS_Source/features/frameworks/utest/source) -list(APPEND MBEDOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/mBedOS_Source/features/frameworks/utest/utest) -list(APPEND MBEDOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/mBedOS_Source/features/mbedtls) -list(APPEND MBEDOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/mBedOS_Source/features/mbedtls/importer) -list(APPEND MBEDOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/mBedOS_Source/features/mbedtls/inc) -list(APPEND MBEDOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/mBedOS_Source/features/mbedtls/inc/mbedtls) -list(APPEND MBEDOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/mBedOS_Source/features/mbedtls/platform) -list(APPEND MBEDOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/mBedOS_Source/features/mbedtls/platform/inc) -list(APPEND MBEDOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/mBedOS_Source/features/mbedtls/platform/src) -list(APPEND MBEDOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/mBedOS_Source/features/mbedtls/src) -list(APPEND MBEDOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/mBedOS_Source/features/nanostack) -list(APPEND MBEDOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/mBedOS_Source/features/netsocket) -list(APPEND MBEDOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/mBedOS_Source/features/storage) -list(APPEND MBEDOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/mBedOS_Source/hal) -list(APPEND MBEDOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/mBedOS_Source/hal/storage_abstraction) -list(APPEND MBEDOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/mBedOS_Source/platform) -list(APPEND MBEDOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/mBedOS_Source/rtos) -list(APPEND MBEDOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/mBedOS_Source/rtos/rtx) -list(APPEND MBEDOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/mBedOS_Source/rtos/rtx/TARGET_CORTEX_M) -list(APPEND MBEDOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/mBedOS_Source/rtos/rtx/TARGET_CORTEX_M/TARGET_${MBED_TARGET_CORE_SHORT}) -list(APPEND MBEDOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/mBedOS_Source/rtos/rtx/TARGET_CORTEX_M/TARGET_${MBED_TARGET_CORE_SHORT}/TOOLCHAIN_GCC) -list(APPEND MBEDOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/mBedOS_Source/targets) -list(APPEND MBEDOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/mBedOS_Source/targets/TARGET_${MBED_TARGET_VENDOR}) -list(APPEND MBEDOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/mBedOS_Source/targets/TARGET_${MBED_TARGET_VENDOR}/TARGET_${MBED_TARGET_SERIES}) -list(APPEND MBEDOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/mBedOS_Source/targets/TARGET_${MBED_TARGET_VENDOR}/TARGET_${MBED_TARGET_SERIES}/device) -list(APPEND MBEDOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/mBedOS_Source/targets/TARGET_${MBED_TARGET_VENDOR}/TARGET_${MBED_TARGET_SERIES}/TARGET_${MBED_TARGET}) -list(APPEND MBEDOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/mBedOS_Source/targets/TARGET_${MBED_TARGET_VENDOR}/TARGET_${MBED_TARGET_SERIES}/TARGET_${MBED_TARGET}/device) -list(APPEND MBEDOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/mBedOS_Source/targets/TARGET_${MBED_TARGET_VENDOR}/TARGET_${MBED_TARGET_SERIES}/TARGET_${MBED_TARGET}/device/TOOLCHAIN_GCC_ARM) - -# source files and GCC options according to target vendor and series -if("${MBED_TARGET_VENDOR}" STREQUAL "STM") - include(MBED_${MBED_TARGET_SERIES}_sources) - include(MBED_${MBED_TARGET_SERIES}_GCC_options) -endif() - -# source files for RTOS -set(MBEDRTOS_SRCS - # drivers - AnalogIn.cpp - BusIn.cpp - BusInOut.cpp - BusOut.cpp - CAN.cpp - Ethernet.cpp - FileBase.cpp - FileLike.cpp - FilePath.cpp - FileSystemLike.cpp - I2C.cpp - I2CSlave.cpp - InterruptIn.cpp - InterruptManager.cpp - LocalFileSystem.cpp - RawSerial.cpp - SPI.cpp - SPISlave.cpp - Serial.cpp - SerialBase.cpp - Stream.cpp - Ticker.cpp - Timeout.cpp - Timer.cpp - TimerEvent.cpp - - # events - EventQueue.cpp - equeue.c - equeue_mbed.cpp - equeue_posix.c - - # features - greentea_metrics.cpp - greentea_serial.cpp - test_env.cpp - unity.c - mbed-utest-shim.cpp - unity_handler.cpp - utest_case.cpp - utest_default_handlers.cpp - utest_greentea_handlers.cpp - utest_harness.cpp - utest_shim.cpp - utest_stack_trace.cpp - utest_types.cpp - - # mbed tls - mbed_trng.c - aes.c - aesni.c - arc4.c - asn1parse.c - asn1write.c - base64.c - bignum.c - blowfish.c - camellia.c - ccm.c - certs.c - cipher.c - cipher_wrap.c - cmac.c - ctr_drbg.c - debug.c - des.c - dhm.c - ecdh.c - ecdsa.c - ecjpake.c - ecp.c - ecp_curves.c - entropy.c - entropy_poll.c - error.c - gcm.c - havege.c - hmac_drbg.c - md.c - md2.c - md4.c - md5.c - md_wrap.c - memory_buffer_alloc.c - net_sockets.c - oid.c - padlock.c - pem.c - pk.c - pk_wrap.c - pkcs11.c - pkcs12.c - pkcs5.c - pkparse.c - pkwrite.c - platform.c - ripemd160.c - rsa.c - sha1.c - sha256.c - sha512.c - ssl_cache.c - ssl_ciphersuites.c - ssl_cli.c - ssl_cookie.c - ssl_srv.c - ssl_ticket.c - ssl_tls.c - threading.c - timing.c - version.c - version_features.c - x509.c - x509_create.c - x509_crl.c - x509_crt.c - x509_csr.c - x509write_crt.c - x509write_csr.c - xtea.c - - # net socket - NetworkInterface.cpp - NetworkStack.cpp - Socket.cpp - SocketAddress.cpp - TCPServer.cpp - TCPSocket.cpp - UDPSocket.cpp - WiFiAccessPoint.cpp - nsapi_dns.cpp - - # mBed HAL - mbed_gpio.c - mbed_lp_ticker_api.c - mbed_pinmap_common.c - mbed_ticker_api.c - mbed_us_ticker_api.c - - # mBed platfom - CallChain.cpp - mbed_alloc_wrappers.cpp - mbed_assert.c - mbed_board.c - mbed_critical.c - mbed_error.c - mbed_interface.c - mbed_mem_trace.c - mbed_rtc_time.cpp - mbed_semihost_api.c - mbed_stats.c - mbed_wait_api_no_rtos.c - mbed_wait_api_rtos.cpp - retarget.cpp - - # RTOS - Mutex.cpp - RtosTimer.cpp - Semaphore.cpp - Thread.cpp - rtos_idle.c - HAL_CM.c - RTX_Conf_CM.c - rt_CMSIS.c - rt_Event.c - rt_List.c - rt_Mailbox.c - rt_MemBox.c - rt_Memory.c - rt_Mutex.c - rt_OsEventObserver.c - rt_Robin.c - rt_Semaphore.c - rt_System.c - rt_Task.c - rt_Time.c - rt_Timer.c -) - -foreach(SRC_FILE ${MBEDRTOS_SRCS}) - set(MBEDOS_SRC_FILE SRC_FILE-NOTFOUND) - find_file(MBEDOS_SRC_FILE ${SRC_FILE} - PATHS - ${PROJECT_BINARY_DIR}/mBedOS_Source/drivers - ${PROJECT_BINARY_DIR}/mBedOS_Source/events - ${PROJECT_BINARY_DIR}/mBedOS_Source/events/equeue - ${PROJECT_BINARY_DIR}/mBedOS_Source/features/frameworks/greentea-client/source - ${PROJECT_BINARY_DIR}/mBedOS_Source/features/frameworks/unity/source - ${PROJECT_BINARY_DIR}/mBedOS_Source/features/frameworks/utest - ${PROJECT_BINARY_DIR}/mBedOS_Source/features/frameworks/utest/source - - ${PROJECT_BINARY_DIR}/mBedOS_Source/features/mbedtls/platform/src - ${PROJECT_BINARY_DIR}/mBedOS_Source/features/mbedtls/src - ${PROJECT_BINARY_DIR}/mBedOS_Source/features/netsocket - - ${PROJECT_BINARY_DIR}/mBedOS_Source/hal - - ${PROJECT_BINARY_DIR}/mBedOS_Source/platform - - ${PROJECT_BINARY_DIR}/mBedOS_Source/rtos - ${PROJECT_BINARY_DIR}/mBedOS_Source/rtos/rtx - ${PROJECT_BINARY_DIR}/mBedOS_Source/rtos/rtx/TARGET_CORTEX_M - - CMAKE_FIND_ROOT_PATH_BOTH - ) - # message("${SRC_FILE} >> ${MBEDOS_SRC_FILE}") # debug helper - list(APPEND MBEDOS_SOURCES ${MBEDOS_SRC_FILE}) -endforeach() - - -include(FindPackageHandleStandardArgs) - -FIND_PACKAGE_HANDLE_STANDARD_ARGS(MBEDOS DEFAULT_MSG MBEDOS_INCLUDE_DIRS MBEDOS_SOURCES) diff --git a/CMake/Modules/FindNF_CoreCLR.cmake b/CMake/Modules/FindNF_CoreCLR.cmake index 8a9fd4d949..d155fc85bc 100644 --- a/CMake/Modules/FindNF_CoreCLR.cmake +++ b/CMake/Modules/FindNF_CoreCLR.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # @@ -145,9 +145,11 @@ set(NF_CoreCLR_SRCS # HAL nanoHAL_Time.cpp nanoHAL_Watchdog.c + nanoHAL_SystemEvents.c # PAL nanoPAL_BlockStorage.c + nanoPAL_Events.cpp nanoPAL_NativeDouble.cpp nanoPAL_Network_stubs.cpp nanoPAL_PerformanceCounters_stubs.cpp @@ -234,6 +236,7 @@ foreach(SRC_FILE ${NF_CoreCLR_SRCS}) ${PROJECT_SOURCE_DIR}/src/PAL ${PROJECT_SOURCE_DIR}/src/PAL/BlockStorage ${PROJECT_SOURCE_DIR}/src/PAL/Double + ${PROJECT_SOURCE_DIR}/src/PAL/Events # PAL stubs ${PROJECT_SOURCE_DIR}/src/PAL/AsyncProcCall diff --git a/CMake/Modules/FindNF_Debugger.cmake b/CMake/Modules/FindNF_Debugger.cmake index 84655de414..6cecff9af1 100644 --- a/CMake/Modules/FindNF_Debugger.cmake +++ b/CMake/Modules/FindNF_Debugger.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/Modules/FindNF_Diagnostics.cmake b/CMake/Modules/FindNF_Diagnostics.cmake index a5b68c76c6..d6dfd72bee 100644 --- a/CMake/Modules/FindNF_Diagnostics.cmake +++ b/CMake/Modules/FindNF_Diagnostics.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/Modules/FindNF_Networking.cmake b/CMake/Modules/FindNF_Networking.cmake index 281b6aa87f..a72918cb78 100644 --- a/CMake/Modules/FindNF_Networking.cmake +++ b/CMake/Modules/FindNF_Networking.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/Modules/FindRTXRTOS.cmake b/CMake/Modules/FindRTXRTOS.cmake index c36076bb72..fa88ba66d5 100644 --- a/CMake/Modules/FindRTXRTOS.cmake +++ b/CMake/Modules/FindRTXRTOS.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/Modules/FindRTXRTOS2.cmake b/CMake/Modules/FindRTXRTOS2.cmake index cc3342ae49..2724540653 100644 --- a/CMake/Modules/FindRTXRTOS2.cmake +++ b/CMake/Modules/FindRTXRTOS2.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/Modules/FindSPIFFS.cmake b/CMake/Modules/FindSPIFFS.cmake index d3a13b9ebb..23ea2761dd 100644 --- a/CMake/Modules/FindSPIFFS.cmake +++ b/CMake/Modules/FindSPIFFS.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/Modules/FindSTM32F0_CubePackage.cmake b/CMake/Modules/FindSTM32F0_CubePackage.cmake index 75939aa2fe..7c55d8b6e0 100644 --- a/CMake/Modules/FindSTM32F0_CubePackage.cmake +++ b/CMake/Modules/FindSTM32F0_CubePackage.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/Modules/FindSTM32F4_CubePackage.cmake b/CMake/Modules/FindSTM32F4_CubePackage.cmake index 557c94f49b..565a1f2872 100644 --- a/CMake/Modules/FindSTM32F4_CubePackage.cmake +++ b/CMake/Modules/FindSTM32F4_CubePackage.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/Modules/FindSTM32F7_CubePackage.cmake b/CMake/Modules/FindSTM32F7_CubePackage.cmake index c5fb281c7b..9b761fd097 100644 --- a/CMake/Modules/FindSTM32F7_CubePackage.cmake +++ b/CMake/Modules/FindSTM32F7_CubePackage.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/Modules/FindSTM32FREERTOS.cmake b/CMake/Modules/FindSTM32FREERTOS.cmake index 8b557481f3..b15d6e8168 100644 --- a/CMake/Modules/FindSTM32FREERTOS.cmake +++ b/CMake/Modules/FindSTM32FREERTOS.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/Modules/FindSTM32H7_CubePackage.cmake b/CMake/Modules/FindSTM32H7_CubePackage.cmake index 1f0cb07d05..ab952a1064 100644 --- a/CMake/Modules/FindSTM32H7_CubePackage.cmake +++ b/CMake/Modules/FindSTM32H7_CubePackage.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/Modules/FindSTM32L0_CubePackage.cmake b/CMake/Modules/FindSTM32L0_CubePackage.cmake index e126f65f59..c488d4e73f 100644 --- a/CMake/Modules/FindSTM32L0_CubePackage.cmake +++ b/CMake/Modules/FindSTM32L0_CubePackage.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/Modules/FindSTM32L4_CubePackage.cmake b/CMake/Modules/FindSTM32L4_CubePackage.cmake new file mode 100644 index 0000000000..a8770a5af6 --- /dev/null +++ b/CMake/Modules/FindSTM32L4_CubePackage.cmake @@ -0,0 +1,31 @@ +# +# Copyright (c) 2019 The nanoFramework project contributors +# See LICENSE file in the project root for full license information. +# + +# set include directories +list(APPEND STM32L4_CubePackage_INCLUDE_DIRS "${PROJECT_BINARY_DIR}/STM32L4_CubePackage_Source/Drivers/STM32L4xx_HAL_Driver/Inc") + +# source files +set(STM32_CubePackage_SRCS + + # add HAL files here as required +) + +foreach(SRC_FILE ${STM32L4_CubePackage_SRCS}) + set(STM32L4_CubePackage_SRC_FILE SRC_FILE-NOTFOUND) + find_file(STM32L4_CubePackage_SRC_FILE ${SRC_FILE} + PATHS + + "${PROJECT_BINARY_DIR}/STM32L4_CubePackage_Source/Drivers/STM32L4xx_HAL_Driver/Src" + + CMAKE_FIND_ROOT_PATH_BOTH + ) + # message("${SRC_FILE} >> ${STM32L4_CubePackage_SRC_FILE}") # debug helper + list(APPEND STM32L4_CubePackage_SOURCES ${STM32L4_CubePackage_SRC_FILE}) +endforeach() + + +include(FindPackageHandleStandardArgs) + +FIND_PACKAGE_HANDLE_STANDARD_ARGS(STM32L4_CubePackage DEFAULT_MSG STM32L4_CubePackage_INCLUDE_DIRS STM32L4_CubePackage_SOURCES) diff --git a/CMake/Modules/FindSystem.Device.Dac.cmake b/CMake/Modules/FindSystem.Device.Dac.cmake new file mode 100644 index 0000000000..0f0da6fea1 --- /dev/null +++ b/CMake/Modules/FindSystem.Device.Dac.cmake @@ -0,0 +1,46 @@ +# +# Copyright (c) .NET Foundation and Contributors +# See LICENSE file in the project root for full license information. +# + +# native code directory +set(BASE_PATH_FOR_THIS_MODULE "${BASE_PATH_FOR_CLASS_LIBRARIES_MODULES}/System.Device.Dac") + + +# set include directories +list(APPEND System.Device.Dac_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/src/CLR/Core) +list(APPEND System.Device.Dac_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/src/CLR/Include) +list(APPEND System.Device.Dac_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/src/HAL/Include) +list(APPEND System.Device.Dac_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/src/PAL/Include) +list(APPEND System.Device.Dac_INCLUDE_DIRS ${BASE_PATH_FOR_THIS_MODULE}) +list(APPEND System.Device.Dac_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/src/System.Device.Dac) + + +# source files +set(System.Device.Dac_SRCS + + sys_dev_dac_native.cpp + sys_dev_dac_native_System_Device_Dac_DacController.cpp + sys_dev_dac_native_System_Device_Dac_DacChannel.cpp + + target_system_device_dac_config.cpp +) + +foreach(SRC_FILE ${System.Device.Dac_SRCS}) + set(System.Device.Dac_SRC_FILE SRC_FILE-NOTFOUND) + find_file(System.Device.Dac_SRC_FILE ${SRC_FILE} + PATHS + ${BASE_PATH_FOR_THIS_MODULE} + ${TARGET_BASE_LOCATION} + ${PROJECT_SOURCE_DIR}/src/System.Device.Dac + + CMAKE_FIND_ROOT_PATH_BOTH + ) + # message("${SRC_FILE} >> ${System.Device.Dac_SRC_FILE}") # debug helper + list(APPEND System.Device.Dac_SOURCES ${System.Device.Dac_SRC_FILE}) +endforeach() + + +include(FindPackageHandleStandardArgs) + +FIND_PACKAGE_HANDLE_STANDARD_ARGS(System.Device.Dac DEFAULT_MSG System.Device.Dac_INCLUDE_DIRS System.Device.Dac_SOURCES) diff --git a/CMake/Modules/FindSystem.Devices.Dac.cmake b/CMake/Modules/FindSystem.Devices.Dac.cmake deleted file mode 100644 index 94b36889a9..0000000000 --- a/CMake/Modules/FindSystem.Devices.Dac.cmake +++ /dev/null @@ -1,46 +0,0 @@ -# -# Copyright (c) 2019 The nanoFramework project contributors -# See LICENSE file in the project root for full license information. -# - -# native code directory -set(BASE_PATH_FOR_THIS_MODULE "${BASE_PATH_FOR_CLASS_LIBRARIES_MODULES}/System.Devices.Dac") - - -# set include directories -list(APPEND System.Devices.Dac_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/src/CLR/Core) -list(APPEND System.Devices.Dac_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/src/CLR/Include) -list(APPEND System.Devices.Dac_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/src/HAL/Include) -list(APPEND System.Devices.Dac_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/src/PAL/Include) -list(APPEND System.Devices.Dac_INCLUDE_DIRS ${BASE_PATH_FOR_THIS_MODULE}) -list(APPEND System.Devices.Dac_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/src/System.Devices.Dac) - - -# source files -set(System.Devices.Dac_SRCS - - sys_dev_dac_native.cpp - sys_dev_dac_native_System_Devices_Dac_DacController.cpp - sys_dev_dac_native_System_Devices_Dac_DacChannel.cpp - - target_system_devices_dac_config.cpp -) - -foreach(SRC_FILE ${System.Devices.Dac_SRCS}) - set(System.Devices.Dac_SRC_FILE SRC_FILE-NOTFOUND) - find_file(System.Devices.Dac_SRC_FILE ${SRC_FILE} - PATHS - ${BASE_PATH_FOR_THIS_MODULE} - ${TARGET_BASE_LOCATION} - ${PROJECT_SOURCE_DIR}/src/System.Devices.Dac - - CMAKE_FIND_ROOT_PATH_BOTH - ) - # message("${SRC_FILE} >> ${System.Devices.Dac_SRC_FILE}") # debug helper - list(APPEND System.Devices.Dac_SOURCES ${System.Devices.Dac_SRC_FILE}) -endforeach() - - -include(FindPackageHandleStandardArgs) - -FIND_PACKAGE_HANDLE_STANDARD_ARGS(System.Devices.Dac DEFAULT_MSG System.Devices.Dac_INCLUDE_DIRS System.Devices.Dac_SOURCES) diff --git a/CMake/Modules/FindSystem.Math.cmake b/CMake/Modules/FindSystem.Math.cmake index e211bf2bc6..76b870f1d5 100644 --- a/CMake/Modules/FindSystem.Math.cmake +++ b/CMake/Modules/FindSystem.Math.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2018 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/Modules/FindSystem.Net.cmake b/CMake/Modules/FindSystem.Net.cmake index 3f8f444fff..547af5d8f5 100644 --- a/CMake/Modules/FindSystem.Net.cmake +++ b/CMake/Modules/FindSystem.Net.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/Modules/FindTI_SimpleLink.cmake b/CMake/Modules/FindTI_SimpleLink.cmake index 45f0a6ad25..856419f4d1 100644 --- a/CMake/Modules/FindTI_SimpleLink.cmake +++ b/CMake/Modules/FindTI_SimpleLink.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/Modules/FindWindows.Devices.Adc.cmake b/CMake/Modules/FindWindows.Devices.Adc.cmake index 70d6479a2e..6b00ae41da 100644 --- a/CMake/Modules/FindWindows.Devices.Adc.cmake +++ b/CMake/Modules/FindWindows.Devices.Adc.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/Modules/FindWindows.Devices.Gpio.cmake b/CMake/Modules/FindWindows.Devices.Gpio.cmake index b9a9c52f07..c63b474b20 100644 --- a/CMake/Modules/FindWindows.Devices.Gpio.cmake +++ b/CMake/Modules/FindWindows.Devices.Gpio.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/Modules/FindWindows.Devices.I2c.cmake b/CMake/Modules/FindWindows.Devices.I2c.cmake index ea9f242cf2..e1028bfe8a 100644 --- a/CMake/Modules/FindWindows.Devices.I2c.cmake +++ b/CMake/Modules/FindWindows.Devices.I2c.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/Modules/FindWindows.Devices.Pwm.cmake b/CMake/Modules/FindWindows.Devices.Pwm.cmake index 3dbc63510b..58555fe0ad 100644 --- a/CMake/Modules/FindWindows.Devices.Pwm.cmake +++ b/CMake/Modules/FindWindows.Devices.Pwm.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/Modules/FindWindows.Devices.SerialCommunication.cmake b/CMake/Modules/FindWindows.Devices.SerialCommunication.cmake index 5c3baf413f..aec7f90d96 100644 --- a/CMake/Modules/FindWindows.Devices.SerialCommunication.cmake +++ b/CMake/Modules/FindWindows.Devices.SerialCommunication.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/Modules/FindWindows.Devices.Spi.cmake b/CMake/Modules/FindWindows.Devices.Spi.cmake index ec3f708f17..24fcb33be3 100644 --- a/CMake/Modules/FindWindows.Devices.Spi.cmake +++ b/CMake/Modules/FindWindows.Devices.Spi.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # @@ -18,7 +18,8 @@ list(APPEND Windows.Devices.Spi_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/src/Windows.D # source files set(Windows.Devices.Spi_SRCS - + cpu_spi.cpp + nanoHAL_spi.cpp win_dev_spi_native_Windows_Devices_Spi_SpiBusInfo.cpp win_dev_spi_native_Windows_Devices_Spi_SpiController.cpp win_dev_spi_native_Windows_Devices_Spi_SpiDevice.cpp diff --git a/CMake/Modules/FindWindows.Devices.WiFi.cmake b/CMake/Modules/FindWindows.Devices.WiFi.cmake index e1221581a3..23b898f639 100644 --- a/CMake/Modules/FindWindows.Devices.WiFi.cmake +++ b/CMake/Modules/FindWindows.Devices.WiFi.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/Modules/FindWindows.Networking.Sockets.cmake b/CMake/Modules/FindWindows.Networking.Sockets.cmake index a54b830f8b..9fc78b9d3b 100644 --- a/CMake/Modules/FindWindows.Networking.Sockets.cmake +++ b/CMake/Modules/FindWindows.Networking.Sockets.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/Modules/FindWindows.Storage.cmake b/CMake/Modules/FindWindows.Storage.cmake index cf97c3eaf0..f48e32f12d 100644 --- a/CMake/Modules/FindWindows.Storage.cmake +++ b/CMake/Modules/FindWindows.Storage.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/Modules/FindWireProtocol.cmake b/CMake/Modules/FindWireProtocol.cmake index 4ab68c8cf7..e138c07ec8 100644 --- a/CMake/Modules/FindWireProtocol.cmake +++ b/CMake/Modules/FindWireProtocol.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/Modules/FindmbedTLS.cmake b/CMake/Modules/FindmbedTLS.cmake index 52149f831c..16f277e0eb 100644 --- a/CMake/Modules/FindmbedTLS.cmake +++ b/CMake/Modules/FindmbedTLS.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2018 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # @@ -7,7 +7,19 @@ # we are replicating their CMakeList here. Actually this is more a simplified version... # List of the required include paths -list(APPEND mbedTLS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/mbedTLS_Source/include/) +# the list of the required include paths needs to be platform specific because of ESP32 port +if(RTOS_FREERTOS_ESP32_CHECK) + + # List of the required include paths + list(APPEND mbedTLS_INCLUDE_DIRS ${ESP32_IDF_PATH}/components/mbedtls/port/include) + list(APPEND mbedTLS_INCLUDE_DIRS ${ESP32_IDF_PATH}/components/mbedtls/port/include/mbedtls) + list(APPEND mbedTLS_INCLUDE_DIRS ${ESP32_IDF_PATH}/components/mbedtls/mbedtls/include) + +else() + + list(APPEND mbedTLS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/mbedTLS_Source/include) + +endif() option(USE_PKCS11_HELPER_LIBRARY "Build mbed TLS with the pkcs11-helper library." OFF) option(ENABLE_ZLIB_SUPPORT "Build mbed TLS with zlib library." OFF) @@ -20,8 +32,13 @@ if(ENABLE_ZLIB_SUPPORT) endif(ZLIB_FOUND) endif(ENABLE_ZLIB_SUPPORT) -# add_subdirectory(library) -# add_subdirectory(include) +# sources need to be added from mbedTLS repo or ESP32 depending on build +# adjust search path here +if(RTOS_FREERTOS_ESP32_CHECK) + set(MBEDTLS_PATH ${ESP32_IDF_PATH}/components/mbedtls/mbedtls/library) +else() + set(MBEDTLS_PATH ${PROJECT_BINARY_DIR}/mbedTLS_Source/library) +endif() set(src_crypto aes.c @@ -57,7 +74,6 @@ set(src_crypto md2.c md4.c md5.c - md_wrap.c memory_buffer_alloc.c oid.c padlock.c @@ -86,6 +102,24 @@ set(src_crypto mbedtls_entropy_hardware_pool.c ) +foreach(SRC_FILE ${src_crypto}) + set(MBEDTLS_SRC_FILE SRC_FILE -NOTFOUND) + find_file(MBEDTLS_SRC_FILE ${SRC_FILE} + PATHS + ${MBEDTLS_PATH} + + ${BASE_PATH_FOR_CLASS_LIBRARIES_MODULES}/ + + CMAKE_FIND_ROOT_PATH_BOTH + ) + # message("${SRC_FILE} >> ${MBEDTLS_SRC_FILE}") # debug helper + list(APPEND mbedTLS_SOURCES ${MBEDTLS_SRC_FILE}) +endforeach() + +# unset this warning as error required for this source file +SET_SOURCE_FILES_PROPERTIES( ${PROJECT_BINARY_DIR}/mbedTLS_Source/library/hmac_drbg.c PROPERTIES COMPILE_FLAGS -Wno-maybe-uninitialized) +SET_SOURCE_FILES_PROPERTIES( ${PROJECT_BINARY_DIR}/mbedTLS_Source/library/x509_crt.c PROPERTIES COMPILE_FLAGS -Wno-maybe-uninitialized) + set(src_x509 certs.c pkcs11.c @@ -98,9 +132,20 @@ set(src_x509 x509write_csr.c ) +foreach(SRC_FILE ${src_x509}) + set(MBEDTLS_SRC_FILE SRC_FILE -NOTFOUND) + find_file(MBEDTLS_SRC_FILE ${SRC_FILE} + PATHS + ${MBEDTLS_PATH} + + CMAKE_FIND_ROOT_PATH_BOTH + ) + # message("${SRC_FILE} >> ${MBEDTLS_SRC_FILE}") # debug helper + list(APPEND mbedTLS_SOURCES ${MBEDTLS_SRC_FILE}) +endforeach() + set(src_tls debug.c - net_sockets.c ssl_cache.c ssl_ciphersuites.c ssl_cli.c @@ -110,13 +155,11 @@ set(src_tls ssl_tls.c ) -foreach(SRC_FILE ${src_crypto}) +foreach(SRC_FILE ${src_tls}) set(MBEDTLS_SRC_FILE SRC_FILE -NOTFOUND) find_file(MBEDTLS_SRC_FILE ${SRC_FILE} PATHS - ${PROJECT_BINARY_DIR}/mbedTLS_Source/library - - ${BASE_PATH_FOR_CLASS_LIBRARIES_MODULES}/ + ${MBEDTLS_PATH} CMAKE_FIND_ROOT_PATH_BOTH ) @@ -124,27 +167,46 @@ foreach(SRC_FILE ${src_crypto}) list(APPEND mbedTLS_SOURCES ${MBEDTLS_SRC_FILE}) endforeach() -# unset this warning as error required for this source file -SET_SOURCE_FILES_PROPERTIES( ${PROJECT_BINARY_DIR}/mbedTLS_Source/library/hmac_drbg.c PROPERTIES COMPILE_FLAGS -Wno-maybe-uninitialized) -SET_SOURCE_FILES_PROPERTIES( ${PROJECT_BINARY_DIR}/mbedTLS_Source/library/x509_crt.c PROPERTIES COMPILE_FLAGS -Wno-maybe-uninitialized) +# some sources need to be added from mbedTLS repo or ESP32 depending on build +# check port files specific to ESP32 IDF here 'components/mbedtls/CMakeLists.txt' +if(RTOS_FREERTOS_ESP32_CHECK) -foreach(SRC_FILE ${src_x509}) - set(MBEDTLS_SRC_FILE SRC_FILE -NOTFOUND) - find_file(MBEDTLS_SRC_FILE ${SRC_FILE} - PATHS - ${PROJECT_BINARY_DIR}/mbedTLS_Source/library + set(src_platform_specific + + md_wrap.c + + esp_bignum.c + esp_hardware.c + esp_mem.c + esp_sha1.c + esp_sha256.c + esp_sha512.c + mbedtls_debug.c + + net_sockets.c - CMAKE_FIND_ROOT_PATH_BOTH ) - # message("${SRC_FILE} >> ${MBEDTLS_SRC_FILE}") # debug helper - list(APPEND mbedTLS_SOURCES ${MBEDTLS_SRC_FILE}) -endforeach() + +else() -foreach(SRC_FILE ${src_tls}) + # other platforms use the official sources + + set(src_platform_specific + + ssl_msg.c + net_sockets.c + + ) + +endif() + +foreach(SRC_FILE ${src_platform_specific}) set(MBEDTLS_SRC_FILE SRC_FILE -NOTFOUND) find_file(MBEDTLS_SRC_FILE ${SRC_FILE} - PATHS - ${PROJECT_BINARY_DIR}/mbedTLS_Source/library + PATHS + + ${ESP32_IDF_PATH}/components/mbedtls/port + ${MBEDTLS_PATH} CMAKE_FIND_ROOT_PATH_BOTH ) diff --git a/CMake/Modules/FindnanoFramework.Devices.Can.cmake b/CMake/Modules/FindnanoFramework.Devices.Can.cmake index 384152a838..1ce9155ac7 100644 --- a/CMake/Modules/FindnanoFramework.Devices.Can.cmake +++ b/CMake/Modules/FindnanoFramework.Devices.Can.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2018 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/Modules/FindnanoFramework.Devices.OneWire.cmake b/CMake/Modules/FindnanoFramework.Devices.OneWire.cmake index c3d9e3a4aa..39298a48fa 100644 --- a/CMake/Modules/FindnanoFramework.Devices.OneWire.cmake +++ b/CMake/Modules/FindnanoFramework.Devices.OneWire.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2018 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/Modules/FindnanoFramework.Hardware.Esp32.Rmt.cmake b/CMake/Modules/FindnanoFramework.Hardware.Esp32.Rmt.cmake new file mode 100644 index 0000000000..f9ae2ab92a --- /dev/null +++ b/CMake/Modules/FindnanoFramework.Hardware.Esp32.Rmt.cmake @@ -0,0 +1,42 @@ +# +# Copyright (c) .NET Foundation and Contributors +# See LICENSE file in the project root for full license information. +# + +# native code directory +set(BASE_PATH_FOR_THIS_MODULE ${BASE_PATH_FOR_CLASS_LIBRARIES_MODULES}/nanoFramework.Hardware.Esp32.Rmt) + + +# set include directories +list(APPEND nanoFramework.Hardware.Esp32.Rmt_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/src/CLR/Core) +list(APPEND nanoFramework.Hardware.Esp32.Rmt_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/src/CLR/Include) +list(APPEND nanoFramework.Hardware.Esp32.Rmt_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/src/HAL/Include) +list(APPEND nanoFramework.Hardware.Esp32.Rmt_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/src/PAL/Include) +list(APPEND nanoFramework.Hardware.Esp32.Rmt_INCLUDE_DIRS ${BASE_PATH_FOR_THIS_MODULE}) +list(APPEND nanoFramework.Hardware.Esp32.Rmt_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/src/nanoFramework.Hardware.Esp32.Rmt) + +# source files +set(nanoFramework.Hardware.Esp32.Rmt_SRCS + + nanoFramework_hardware_esp32_rmt_native.cpp + nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_RmtChannel.cpp + nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_TransmitterChannel.cpp + nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_ReceiverChannel.cpp +) + +foreach(SRC_FILE ${nanoFramework.Hardware.Esp32.Rmt_SRCS}) + set(nanoFramework.Hardware.Esp32.Rmt_SRC_FILE SRC_FILE-NOTFOUND) + find_file(nanoFramework.Hardware.Esp32.Rmt_SRC_FILE ${SRC_FILE} + PATHS + "${BASE_PATH_FOR_THIS_MODULE}" + "${TARGET_BASE_LOCATION}" + + CMAKE_FIND_ROOT_PATH_BOTH + ) + # message("${SRC_FILE} >> ${nanoFramework.Hardware.Esp32.Rmt_SRC_FILE}") # debug helper + list(APPEND nanoFramework.Hardware.Esp32.Rmt_SOURCES ${nanoFramework.Hardware.Esp32.Rmt_SRC_FILE}) +endforeach() + +include(FindPackageHandleStandardArgs) + +FIND_PACKAGE_HANDLE_STANDARD_ARGS(nanoFramework.Hardware.Esp32.Rmt DEFAULT_MSG nanoFramework.Hardware.Esp32.Rmt_INCLUDE_DIRS nanoFramework.Hardware.Esp32.Rmt_SOURCES) diff --git a/CMake/Modules/FindnanoFramework.Hardware.Esp32.cmake b/CMake/Modules/FindnanoFramework.Hardware.Esp32.cmake index 9255d68c51..62f4234af3 100644 --- a/CMake/Modules/FindnanoFramework.Hardware.Esp32.cmake +++ b/CMake/Modules/FindnanoFramework.Hardware.Esp32.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/Modules/FindnanoFramework.Hardware.Stm32.cmake b/CMake/Modules/FindnanoFramework.Hardware.Stm32.cmake index 87dfaeb591..48fdf98a71 100644 --- a/CMake/Modules/FindnanoFramework.Hardware.Stm32.cmake +++ b/CMake/Modules/FindnanoFramework.Hardware.Stm32.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/Modules/FindnanoFramework.Hardware.TI.cmake b/CMake/Modules/FindnanoFramework.Hardware.TI.cmake new file mode 100644 index 0000000000..9aa27366a0 --- /dev/null +++ b/CMake/Modules/FindnanoFramework.Hardware.TI.cmake @@ -0,0 +1,44 @@ +# +# Copyright (c) .NET Foundation and Contributors +# See LICENSE file in the project root for full license information. +# + +# native code directory +set(BASE_PATH_FOR_THIS_MODULE ${BASE_PATH_FOR_CLASS_LIBRARIES_MODULES}/nanoFramework.Hardware.TI) + + +# set include directories +list(APPEND nanoFramework.Hardware.TI_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/src/CLR/Core) +list(APPEND nanoFramework.Hardware.TI_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/src/CLR/Include) +list(APPEND nanoFramework.Hardware.TI_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/src/HAL/Include) +list(APPEND nanoFramework.Hardware.TI_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/src/PAL/Include) +list(APPEND nanoFramework.Hardware.TI_INCLUDE_DIRS ${BASE_PATH_FOR_THIS_MODULE}) +list(APPEND nanoFramework.Hardware.TI_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/src/nanoFramework.Hardware.TI) + +# source files +set(nanoFramework.Hardware.TI_SRCS + + nf_hardware_ti_native.cpp + + + nf_hardware_ti_native_nanoFramework_Hardware_TI_Power.cpp + nf_hardware_ti_native_nanoFramework_Hardware_TI_Utilities.cpp + +) + +foreach(SRC_FILE ${nanoFramework.Hardware.TI_SRCS}) + set(nanoFramework.Hardware.TI_SRC_FILE SRC_FILE-NOTFOUND) + find_file(nanoFramework.Hardware.TI_SRC_FILE ${SRC_FILE} + PATHS + "${BASE_PATH_FOR_THIS_MODULE}" + "${TARGET_BASE_LOCATION}" + + CMAKE_FIND_ROOT_PATH_BOTH + ) + # message("${SRC_FILE} >> ${nanoFramework.Hardware.TI_SRC_FILE}") # debug helper + list(APPEND nanoFramework.Hardware.TI_SOURCES ${nanoFramework.Hardware.TI_SRC_FILE}) +endforeach() + +include(FindPackageHandleStandardArgs) + +FIND_PACKAGE_HANDLE_STANDARD_ARGS(nanoFramework.Hardware.TI DEFAULT_MSG nanoFramework.Hardware.TI_INCLUDE_DIRS nanoFramework.Hardware.TI_SOURCES) diff --git a/CMake/Modules/FindnanoFramework.Networking.Sntp.cmake b/CMake/Modules/FindnanoFramework.Networking.Sntp.cmake index 75604406c7..828a16d636 100644 --- a/CMake/Modules/FindnanoFramework.Networking.Sntp.cmake +++ b/CMake/Modules/FindnanoFramework.Networking.Sntp.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/Modules/FindnanoFramework.ResourceManager.cmake b/CMake/Modules/FindnanoFramework.ResourceManager.cmake index bb2dbb0065..99af521dba 100644 --- a/CMake/Modules/FindnanoFramework.ResourceManager.cmake +++ b/CMake/Modules/FindnanoFramework.ResourceManager.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/Modules/FindnanoFramework.Runtime.Events.cmake b/CMake/Modules/FindnanoFramework.Runtime.Events.cmake index d7e9be4f4e..39ec2d0842 100644 --- a/CMake/Modules/FindnanoFramework.Runtime.Events.cmake +++ b/CMake/Modules/FindnanoFramework.Runtime.Events.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/Modules/FindnanoFramework.System.Collections.cmake b/CMake/Modules/FindnanoFramework.System.Collections.cmake index afa84191f2..0cbcb34e72 100644 --- a/CMake/Modules/FindnanoFramework.System.Collections.cmake +++ b/CMake/Modules/FindnanoFramework.System.Collections.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/Modules/FindnanoFramework.System.Text.cmake b/CMake/Modules/FindnanoFramework.System.Text.cmake index 818a798093..400df335cc 100644 --- a/CMake/Modules/FindnanoFramework.System.Text.cmake +++ b/CMake/Modules/FindnanoFramework.System.Text.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/Modules/FindnanoFramework.TI.EasyLink.cmake b/CMake/Modules/FindnanoFramework.TI.EasyLink.cmake index 0830237fc5..42db1f751d 100644 --- a/CMake/Modules/FindnanoFramework.TI.EasyLink.cmake +++ b/CMake/Modules/FindnanoFramework.TI.EasyLink.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # @@ -17,10 +17,6 @@ set(nanoFramework.TI.EasyLink_SRCS # source files for EasyLink EasyLink.c - easylink_config.c - - smartrf_settings.c - smartrf_settings_predefined.c # targetEasyLinkCC13xx_CC26xx_RadioTask.c @@ -36,8 +32,6 @@ foreach(SRC_FILE ${nanoFramework.TI.EasyLink_SRCS}) ${BASE_PATH_FOR_THIS_MODULE} ${TARGET_BASE_LOCATION} - ${TARGET_BASE_LOCATION}/smartrf_settings - ${TARGET_BASE_LOCATION}/easylink ${PROJECT_SOURCE_DIR}/src/nanoFramework.TI.EasyLink ${PROJECT_SOURCE_DIR}/targets/TI-SimpleLink/common/easylink ${PROJECT_SOURCE_DIR}/targets/TI-SimpleLink/nanoCLR diff --git a/CMake/Modules/FreeRTOS_iMXRT10xx_GCC_options.cmake b/CMake/Modules/FreeRTOS_iMXRT10xx_GCC_options.cmake index ee19192c27..d6140daea9 100644 --- a/CMake/Modules/FreeRTOS_iMXRT10xx_GCC_options.cmake +++ b/CMake/Modules/FreeRTOS_iMXRT10xx_GCC_options.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/Modules/FreeRTOS_iMXRT10xx_sources.cmake b/CMake/Modules/FreeRTOS_iMXRT10xx_sources.cmake index 24d265d284..a3484e51d3 100644 --- a/CMake/Modules/FreeRTOS_iMXRT10xx_sources.cmake +++ b/CMake/Modules/FreeRTOS_iMXRT10xx_sources.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/Modules/JSONParser.cmake b/CMake/Modules/JSONParser.cmake deleted file mode 100644 index b9230e4e46..0000000000 --- a/CMake/Modules/JSONParser.cmake +++ /dev/null @@ -1,289 +0,0 @@ -# source from https://github.com/sbellus/json-cmake - -cmake_minimum_required(VERSION 3.1) - -if (DEFINED JSonParserGuard) - return() -endif() - -set(JSonParserGuard yes) - -macro(sbeParseJson prefix jsonString) - cmake_policy(PUSH) - - set(json_string "${${jsonString}}") - string(LENGTH "${json_string}" json_jsonLen) - set(json_index 0) - set(json_AllVariables ${prefix}) - set(json_ArrayNestingLevel 0) - set(json_MaxArrayNestingLevel 0) - - _sbeParse(${prefix}) - - unset(json_index) - unset(json_AllVariables) - unset(json_jsonLen) - unset(json_string) - unset(json_value) - unset(json_inValue) - unset(json_name) - unset(json_inName) - unset(json_newPrefix) - unset(json_reservedWord) - unset(json_arrayIndex) - unset(json_char) - unset(json_end) - unset(json_ArrayNestingLevel) - foreach(json_nestingLevel RANGE ${json_MaxArrayNestingLevel}) - unset(json_${json_nestingLevel}_arrayIndex) - endforeach() - unset(json_nestingLevel) - unset(json_MaxArrayNestingLevel) - - cmake_policy(POP) -endmacro() - -macro(sbeClearJson prefix) - foreach(json_var ${${prefix}}) - unset(${json_var}) - endforeach() - - unset(${prefix}) - unset(json_var) -endmacro() - -macro(sbePrintJson prefix) - foreach(json_var ${${prefix}}) - message("${json_var} = ${${json_var}}") - endforeach() -endmacro() - -macro(_sbeParse prefix) - - while(${json_index} LESS ${json_jsonLen}) - string(SUBSTRING "${json_string}" ${json_index} 1 json_char) - - if("\"" STREQUAL "${json_char}") - _sbeParseNameValue(${prefix}) - elseif("{" STREQUAL "${json_char}") - _sbeMoveToNextNonEmptyCharacter() - _sbeParseObject(${prefix}) - elseif("[" STREQUAL "${json_char}") - _sbeMoveToNextNonEmptyCharacter() - _sbeParseArray(${prefix}) - endif() - - if(${json_index} LESS ${json_jsonLen}) - string(SUBSTRING "${json_string}" ${json_index} 1 json_char) - else() - break() - endif() - - if ("}" STREQUAL "${json_char}" OR "]" STREQUAL "${json_char}") - break() - endif() - - _sbeMoveToNextNonEmptyCharacter() - endwhile() -endmacro() - -macro(_sbeParseNameValue prefix) - set(json_name "") - set(json_inName no) - - while(${json_index} LESS ${json_jsonLen}) - string(SUBSTRING "${json_string}" ${json_index} 1 json_char) - - # check if name ends - if("\"" STREQUAL "${json_char}" AND json_inName) - set(json_inName no) - _sbeMoveToNextNonEmptyCharacter() - if(NOT ${json_index} LESS ${json_jsonLen}) - break() - endif() - string(SUBSTRING "${json_string}" ${json_index} 1 json_char) - set(json_newPrefix ${prefix}.${json_name}) - set(json_name "") - - if(":" STREQUAL "${json_char}") - _sbeMoveToNextNonEmptyCharacter() - if(NOT ${json_index} LESS ${json_jsonLen}) - break() - endif() - string(SUBSTRING "${json_string}" ${json_index} 1 json_char) - - if("\"" STREQUAL "${json_char}") - _sbeParseValue(${json_newPrefix}) - break() - elseif("{" STREQUAL "${json_char}") - _sbeMoveToNextNonEmptyCharacter() - _sbeParseObject(${json_newPrefix}) - break() - elseif("[" STREQUAL "${json_char}") - _sbeMoveToNextNonEmptyCharacter() - _sbeParseArray(${json_newPrefix}) - break() - else() - # reserved word starts - _sbeParseReservedWord(${json_newPrefix}) - break() - endif() - else() - # name without value - list(APPEND ${json_AllVariables} ${json_newPrefix}) - set(${json_newPrefix} "") - break() - endif() - endif() - - if(json_inName) - # remove escapes - if("\\" STREQUAL "${json_char}") - math(EXPR json_index "${json_index} + 1") - if(NOT ${json_index} LESS ${json_jsonLen}) - break() - endif() - string(SUBSTRING "${json_string}" ${json_index} 1 json_char) - endif() - - set(json_name "${json_name}${json_char}") - endif() - - # check if name starts - if("\"" STREQUAL "${json_char}" AND NOT json_inName) - set(json_inName yes) - endif() - - _sbeMoveToNextNonEmptyCharacter() - endwhile() -endmacro() - -macro(_sbeParseReservedWord prefix) - set(json_reservedWord "") - set(json_end no) - while(${json_index} LESS ${json_jsonLen} AND NOT json_end) - string(SUBSTRING "${json_string}" ${json_index} 1 json_char) - - if("," STREQUAL "${json_char}" OR "}" STREQUAL "${json_char}" OR "]" STREQUAL "${json_char}") - set(json_end yes) - else() - set(json_reservedWord "${json_reservedWord}${json_char}") - math(EXPR json_index "${json_index} + 1") - endif() - endwhile() - - list(APPEND ${json_AllVariables} ${prefix}) - string(STRIP "${json_reservedWord}" json_reservedWord) - set(${prefix} ${json_reservedWord}) -endmacro() - -macro(_sbeParseValue prefix) - cmake_policy(SET CMP0054 NEW) # turn off implicit expansions in if statement - - set(json_value "") - set(json_inValue no) - - while(${json_index} LESS ${json_jsonLen}) - string(SUBSTRING "${json_string}" ${json_index} 1 json_char) - - # check if json_value ends, it is ended by " - if("\"" STREQUAL "${json_char}" AND json_inValue) - set(json_inValue no) - - set(${prefix} ${json_value}) - list(APPEND ${json_AllVariables} ${prefix}) - _sbeMoveToNextNonEmptyCharacter() - break() - endif() - - if(json_inValue) - # if " is escaped consume - if("\\" STREQUAL "${json_char}") - math(EXPR json_index "${json_index} + 1") - if(NOT ${json_index} LESS ${json_jsonLen}) - break() - endif() - string(SUBSTRING "${json_string}" ${json_index} 1 json_char) - if(NOT "\"" STREQUAL "${json_char}") - # if it is not " then copy also escape character - set(json_char "\\${json_char}") - endif() - endif() - - _sbeAddEscapedCharacter("${json_char}") - endif() - - # check if value starts - if("\"" STREQUAL "${json_char}" AND NOT json_inValue) - set(json_inValue yes) - endif() - - math(EXPR json_index "${json_index} + 1") - endwhile() -endmacro() - -macro(_sbeAddEscapedCharacter char) - string(CONCAT json_value "${json_value}" "${char}") -endmacro() - -macro(_sbeParseObject prefix) - _sbeParse(${prefix}) - _sbeMoveToNextNonEmptyCharacter() -endmacro() - -macro(_sbeParseArray prefix) - math(EXPR json_ArrayNestingLevel "${json_ArrayNestingLevel} + 1") - set(json_${json_ArrayNestingLevel}_arrayIndex 0) - - set(${prefix} "") - list(APPEND ${json_AllVariables} ${prefix}) - - while(${json_index} LESS ${json_jsonLen}) - string(SUBSTRING "${json_string}" ${json_index} 1 json_char) - - if("\"" STREQUAL "${json_char}") - # simple value - list(APPEND ${prefix} ${json_${json_ArrayNestingLevel}_arrayIndex}) - _sbeParseValue(${prefix}_${json_${json_ArrayNestingLevel}_arrayIndex}) - elseif("{" STREQUAL "${json_char}") - # object - _sbeMoveToNextNonEmptyCharacter() - list(APPEND ${prefix} ${json_${json_ArrayNestingLevel}_arrayIndex}) - _sbeParseObject(${prefix}_${json_${json_ArrayNestingLevel}_arrayIndex}) - else() - list(APPEND ${prefix} ${json_${json_ArrayNestingLevel}_arrayIndex}) - _sbeParseReservedWord(${prefix}_${json_${json_ArrayNestingLevel}_arrayIndex}) - endif() - - if(NOT ${json_index} LESS ${json_jsonLen}) - break() - endif() - - string(SUBSTRING "${json_string}" ${json_index} 1 json_char) - - if("]" STREQUAL "${json_char}") - _sbeMoveToNextNonEmptyCharacter() - break() - elseif("," STREQUAL "${json_char}") - math(EXPR json_${json_ArrayNestingLevel}_arrayIndex "${json_${json_ArrayNestingLevel}_arrayIndex} + 1") - endif() - - _sbeMoveToNextNonEmptyCharacter() - endwhile() - - if(${json_MaxArrayNestingLevel} LESS ${json_ArrayNestingLevel}) - set(json_MaxArrayNestingLevel ${json_ArrayNestingLevel}) - endif() - math(EXPR json_ArrayNestingLevel "${json_ArrayNestingLevel} - 1") -endmacro() - -macro(_sbeMoveToNextNonEmptyCharacter) - math(EXPR json_index "${json_index} + 1") - if(${json_index} LESS ${json_jsonLen}) - string(SUBSTRING "${json_string}" ${json_index} 1 json_char) - while(${json_char} MATCHES "[ \t\n\r]" AND ${json_index} LESS ${json_jsonLen}) - math(EXPR json_index "${json_index} + 1") - string(SUBSTRING "${json_string}" ${json_index} 1 json_char) - endwhile() - endif() -endmacro() diff --git a/CMake/Modules/MBED_STM32F0_GCC_options.cmake b/CMake/Modules/MBED_STM32F0_GCC_options.cmake deleted file mode 100644 index b7c46de5c8..0000000000 --- a/CMake/Modules/MBED_STM32F0_GCC_options.cmake +++ /dev/null @@ -1,16 +0,0 @@ -# -# Copyright (c) 2017 The nanoFramework project contributors -# See LICENSE file in the project root for full license information. -# - -################################################################# -# WHEN ADDING A NEW TARGET add the appropriate GCC options below -################################################################# - -set(CMAKE_C_FLAGS "-mthumb -mcpu=cortex-m0 -fno-builtin -std=c11 -g -Wall -ffunction-sections -fdata-sections -fomit-frame-pointer -mlong-calls -mabi=aapcs -fno-exceptions -fno-unroll-loops -ftree-vectorize -specs=nano.specs" CACHE INTERNAL "c compiler flags") -set(CMAKE_CXX_FLAGS "-mthumb -mcpu=cortex-m0 -std=c++11 -ffunction-sections -fdata-sections -fomit-frame-pointer -mlong-calls -mabi=aapcs -fno-exceptions -fno-unroll-loops -ftree-vectorize -specs=nano.specs" CACHE INTERNAL "cxx compiler flags") -set(CMAKE_ASM_FLAGS "-c -mthumb -mcpu=cortex-m0 -g -Wa,--no-warn -x assembler-with-cpp " CACHE INTERNAL "asm compiler flags") - -set(CMAKE_EXE_LINKER_FLAGS "-mthumb -mcpu=cortex-m0 -static -mabi=aapcs -Wl,-gc-sections" CACHE INTERNAL "executable linker flags") -set(CMAKE_MODULE_LINKER_FLAGS "-mthumb -mcpu=cortex-m0 -specs=nano.specs " CACHE INTERNAL "module linker flags") -set(CMAKE_SHARED_LINKER_FLAGS "-mthumb -mcpu=cortex-m0 -specs=nano.specs " CACHE INTERNAL "shared linker flags") diff --git a/CMake/Modules/MBED_STM32F0_sources.cmake b/CMake/Modules/MBED_STM32F0_sources.cmake deleted file mode 100644 index 4eb322d818..0000000000 --- a/CMake/Modules/MBED_STM32F0_sources.cmake +++ /dev/null @@ -1,134 +0,0 @@ -# -# Copyright (c) 2017 The nanoFramework project contributors -# See LICENSE file in the project root for full license information. -# - -########################################################################### -# WHEN ADDING A NEW SERIES add the include to the vendor source code below -########################################################################### -include(MBED_STM_sources) - -####################################################################################### -# WHEN ADDING A NEW TARGET add the source code file for the series\device folder below -####################################################################################### - -# sources in series\device folder -set(MBED_VENDOR_SERIES_DEVICE_SRCS - stm32f0xx_hal.c - stm32f0xx_hal_adc.c - stm32f0xx_hal_adc_ex.c - stm32f0xx_hal_can.c - stm32f0xx_hal_cec.c - stm32f0xx_hal_comp.c - stm32f0xx_hal_cortex.c - stm32f0xx_hal_crc.c - stm32f0xx_hal_crc_ex.c - stm32f0xx_hal_dac.c - stm32f0xx_hal_dac_ex.c - stm32f0xx_hal_dma.c - stm32f0xx_hal_flash.c - stm32f0xx_hal_flash_ex.c - stm32f0xx_hal_gpio.c - stm32f0xx_hal_i2c.c - stm32f0xx_hal_i2c_ex.c - stm32f0xx_hal_i2s.c - stm32f0xx_hal_irda.c - stm32f0xx_hal_iwdg.c - stm32f0xx_hal_pcd.c - stm32f0xx_hal_pcd_ex.c - stm32f0xx_hal_pwr.c - stm32f0xx_hal_pwr_ex.c - stm32f0xx_hal_rcc.c - stm32f0xx_hal_rcc_ex.c - stm32f0xx_hal_rtc.c - stm32f0xx_hal_rtc_ex.c - stm32f0xx_hal_smartcard.c - stm32f0xx_hal_smartcard_ex.c - stm32f0xx_hal_smbus.c - stm32f0xx_hal_spi.c - stm32f0xx_hal_spi_ex.c - stm32f0xx_hal_tim.c - stm32f0xx_hal_tim_ex.c - stm32f0xx_hal_tsc.c - stm32f0xx_hal_uart.c - stm32f0xx_hal_uart_ex.c - stm32f0xx_hal_usart.c - stm32f0xx_hal_wwdg.c -) -foreach(SRC_FILE ${MBED_VENDOR_SERIES_DEVICE_SRCS}) - set(MBEDOS_SRC_FILE SRC_FILE-NOTFOUND) - find_file(MBEDOS_SRC_FILE ${SRC_FILE} - PATHS - ${PROJECT_BINARY_DIR}/mBedOS_Source/targets/TARGET_${MBED_TARGET_VENDOR}/TARGET_${MBED_TARGET_SERIES}/device - CMAKE_FIND_ROOT_PATH_BOTH - ) - # message("${SRC_FILE} >> ${MBEDOS_SRC_FILE}") # debug helper - list(APPEND MBEDOS_SOURCES ${MBEDOS_SRC_FILE}) -endforeach() - -########################################################################## -# WHEN ADDING A NEW TARGET add the source code file for the series below -########################################################################## - -set(MBED_VENDOR_SERIES_AND_TARGET_SRCS - analogin_api.c - analogout_api.c - can_api.c - gpio_api.c - gpio_irq_api.c - lp_ticker.c - mbed_overrides.c - pinmap.c - port_api.c - pwmout_api.c - rtc_api.c - serial_api.c - sleep.c - spi_api.c - - PeripheralPins.c - cmsis_nvic.c - system_stm32f0xx.c -) -foreach(SRC_FILE ${MBED_VENDOR_SERIES_AND_TARGET_SRCS}) - set(MBEDOS_SRC_FILE SRC_FILE-NOTFOUND) - find_file(MBEDOS_SRC_FILE ${SRC_FILE} - PATHS - ${PROJECT_BINARY_DIR}/mBedOS_Source/targets/TARGET_${MBED_TARGET_VENDOR}/TARGET_${MBED_TARGET_SERIES} - ${PROJECT_BINARY_DIR}/mBedOS_Source/targets/TARGET_${MBED_TARGET_VENDOR}/TARGET_${MBED_TARGET_SERIES}/TARGET_${MBED_TARGET} - ${PROJECT_BINARY_DIR}/mBedOS_Source/targets/TARGET_${MBED_TARGET_VENDOR}/TARGET_${MBED_TARGET_SERIES}/TARGET_${MBED_TARGET}/device - ${PROJECT_BINARY_DIR}/mBedOS_Source/targets/TARGET_${MBED_TARGET_VENDOR}/TARGET_${MBED_TARGET_SERIES}/TARGET_${MBED_TARGET}/device/TOOLCHAIN_GCC_ARM - CMAKE_FIND_ROOT_PATH_BOTH - ) - # message("${SRC_FILE} >> ${MBEDOS_SRC_FILE}") # debug helper - list(APPEND MBEDOS_SOURCES ${MBEDOS_SRC_FILE}) -endforeach() - -####################################################################################################################################### -# WHEN ADDING A NEW TARGET add the respective if clause below along with the startup file and the linker file name (without extension) -####################################################################################################################################### - -# startup file -if(${MBED_TARGET} STREQUAL "NUCLEO_F091RC") - list(APPEND MBEDOS_SOURCES ${PROJECT_BINARY_DIR}/mBedOS_Source/targets/TARGET_${MBED_TARGET_VENDOR}/TARGET_${MBED_TARGET_SERIES}/TARGET_NUCLEO_F091RC/device/TOOLCHAIN_GCC_ARM/startup_stm32f091xc.S) - set(LINKER_FILE "STM32F091XC") -endif() - -####################################################################################################################################### - - -################################################################ -# WHEN ADDING A NEW TARGET check if the linker file below works -################################################################ - -function(MBED_SET_LINKER_OPTIONS TARGET) - - get_target_property(TARGET_LD_FLAGS ${TARGET} LINK_FLAGS) - if(TARGET_LD_FLAGS) - set(TARGET_LD_FLAGS "-T${PROJECT_BINARY_DIR}/mBedOS_Source/targets/TARGET_${MBED_TARGET_VENDOR}/TARGET_${MBED_TARGET_SERIES}/TARGET_${MBED_TARGET}/device/TOOLCHAIN_GCC_ARM/${LINKER_FILE}.LD ${TARGET_LD_FLAGS}") - else() - set(TARGET_LD_FLAGS "-T${PROJECT_BINARY_DIR}/mBedOS_Source/targets/TARGET_${MBED_TARGET_VENDOR}/TARGET_${MBED_TARGET_SERIES}/TARGET_${MBED_TARGET}/device/TOOLCHAIN_GCC_ARM/${LINKER_FILE}.LD") - endif() - set_target_properties(${TARGET} PROPERTIES LINK_FLAGS ${TARGET_LD_FLAGS}) - -endfunction() diff --git a/CMake/Modules/MBED_STM_sources.cmake b/CMake/Modules/MBED_STM_sources.cmake deleted file mode 100644 index 5116e03709..0000000000 --- a/CMake/Modules/MBED_STM_sources.cmake +++ /dev/null @@ -1,35 +0,0 @@ -# -# Copyright (c) 2017 The nanoFramework project contributors -# See LICENSE file in the project root for full license information. -# - -############################################################################ -# WHEN ADDING A NEW VENDOR add the source code from the vendor folder below -############################################################################ - -# source files common for all STM targets -set(MBED_VENDOR_SRCS - hal_tick_16b.c - hal_tick_32b.c - i2c_api.c - stm_spi_api.c - trng_api.c - us_ticker_16b.c - us_ticker_32b.c -) -foreach(SRC_FILE ${MBED_VENDOR_SRCS}) - set(MBEDOS_SRC_FILE SRC_FILE-NOTFOUND) - find_file(MBEDOS_SRC_FILE ${SRC_FILE} - PATHS - ${PROJECT_BINARY_DIR}/mBedOS_Source/targets/TARGET_${MBED_TARGET_VENDOR} - CMAKE_FIND_ROOT_PATH_BOTH - ) - # message("${SRC_FILE} >> ${MBEDOS_SRC_FILE}") # debug helper - list(APPEND MBEDOS_SOURCES ${MBEDOS_SRC_FILE}) -endforeach() - -# HAL_CMx file -list(APPEND MBEDOS_SOURCES ${PROJECT_BINARY_DIR}/mBedOS_Source/rtos/rtx/TARGET_CORTEX_M/TARGET_${MBED_TARGET_CORE_SHORT}/TOOLCHAIN_GCC/HAL_C${MBED_TARGET_CORE_SHORT}.S) - -# SVC_Table file -list(APPEND MBEDOS_SOURCES ${PROJECT_BINARY_DIR}/mBedOS_Source/rtos/rtx/TARGET_CORTEX_M/TARGET_${MBED_TARGET_CORE_SHORT}/TOOLCHAIN_GCC/SVC_Table.S) diff --git a/CMake/Modules/NF_NativeAssemblies.cmake b/CMake/Modules/NF_NativeAssemblies.cmake index 3b407747c9..2ed9ebc98b 100644 --- a/CMake/Modules/NF_NativeAssemblies.cmake +++ b/CMake/Modules/NF_NativeAssemblies.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # @@ -19,7 +19,7 @@ option(API_nanoFramework.System.Text "option for nanoFramework.System option(API_System.Math "option for System.Math") option(API_System.Net "option for System.Net") option(API_Windows.Devices.Adc "option for Windows.Devices.Adc API") -option(API_System.Devices.Dac "option for System.Devices.Dac API") +option(API_System.Device.Dac "option for System.Device.Dac API") option(API_Windows.Devices.Gpio "option for Windows.Devices.Gpio API") option(API_Windows.Devices.I2c "option for Windows.Devices.I2c API") option(API_Windows.Devices.Pwm "option for Windows.Devices.Pwm API") @@ -31,6 +31,7 @@ option(API_Windows.Storage "option for Windows.Storage") # Esp32 only option(API_Hardware.Esp32 "option for Hardware.Esp32") +option(API_nanoFramework.Hardware.Esp32.Rmt "option for nanoFramework.Hardware.Esp32.Rmt") # Stm32 only @@ -38,6 +39,7 @@ option(API_Hardware.Stm32 "option for Hardware.Stm32") # TI CC13xxCC26xx option(API_nanoFramework.TI.EasyLink "option for nanoFramework.TI.EasyLink API") +option(API_nanoFramework.Hardware.TI "option for nanoFramework.Hardware.TI API") ################################################################# @@ -86,6 +88,12 @@ macro(ParseNativeAssemblies) PerformSettingsForApiEntry("nanoFramework.Hardware.Esp32") endif() + # nanoFramework.Hardware.Esp32.Rmt + if(API_nanoFramework.Hardware.Esp32.Rmt) + ##### API name here (doted name) + PerformSettingsForApiEntry("nanoFramework.Hardware.Esp32.Rmt") + endif() + # Hardware.Stm32 if(API_Hardware.Stm32) ##### API name here (doted name) @@ -134,6 +142,12 @@ macro(ParseNativeAssemblies) PerformSettingsForApiEntry("nanoFramework.TI.EasyLink") endif() + # nanoFramework.Hardware.TI + if(API_nanoFramework.Hardware.TI) + ##### API name here (doted name) + PerformSettingsForApiEntry("nanoFramework.Hardware.TI") + endif() + # nanoFramework.Runtime.Events if(API_nanoFramework.Runtime.Events) ##### API name here (doted name) @@ -166,10 +180,10 @@ macro(ParseNativeAssemblies) PerformSettingsForApiEntry("Windows.Devices.Adc") endif() - # System.Devices.Dac - if(API_System.Devices.Dac) + # System.Device.Dac + if(API_System.Device.Dac) ##### API name here (doted name) - PerformSettingsForApiEntry("System.Devices.Dac") + PerformSettingsForApiEntry("System.Device.Dac") endif() # Windows.Devices.Gpio @@ -313,8 +327,13 @@ macro(ParseInteropAssemblies) # check if there are any Interop assemblies to be added if(NF_INTEROP_ASSEMBLIES) + # need to split define containing assembly namespaces + # for Windows buids this is a string with the namespaces separated by an whitespace + # e.g.: "NF_INTEROP_ASSEMBLIES": "Assembly1_Namespace Assembly2_Namespace" + separate_arguments(INTEROP_ASSEMBLIES_LIST NATIVE_COMMAND ${NF_INTEROP_ASSEMBLIES}) + # loop through each Interop assembly and add it to the build - foreach(assembly ${NF_INTEROP_ASSEMBLIES}) + foreach(assembly ${INTEROP_ASSEMBLIES_LIST}) PerformSettingsForInteropEntry(${assembly}) endforeach() diff --git a/CMake/Modules/NF_Utils.cmake b/CMake/Modules/NF_Utils.cmake index b66b81cbe0..40a51d4afb 100644 --- a/CMake/Modules/NF_Utils.cmake +++ b/CMake/Modules/NF_Utils.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/Modules/STM32_CubePackage.cmake b/CMake/Modules/STM32_CubePackage.cmake index 8285b9e773..0a7443055e 100644 --- a/CMake/Modules/STM32_CubePackage.cmake +++ b/CMake/Modules/STM32_CubePackage.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/Modules/TI_SimpleLink_CC13x2_26x2_GCC_options.cmake b/CMake/Modules/TI_SimpleLink_CC13x2_26x2_GCC_options.cmake index bab3a149e5..059c4a5dc3 100644 --- a/CMake/Modules/TI_SimpleLink_CC13x2_26x2_GCC_options.cmake +++ b/CMake/Modules/TI_SimpleLink_CC13x2_26x2_GCC_options.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # @@ -11,7 +11,7 @@ set(CMAKE_ASM_FLAGS " -mthumb -mcpu=cortex-m4 -x assembler-with-cpp" CACHE INTERNAL "asm compiler flags") # need to specify linker flags here -set(CMAKE_EXE_LINKER_FLAGS " -L${PROJECT_BINARY_DIR}/SimpleLinkCC13x2_26x2SDK_Source/kernel/tirtos/packages/gnu/targets/arm/libs/install-native/arm-none-eabi/lib/thumb/v7e-m/fpv4-sp/hard -L${TOOLCHAIN_PREFIX}/arm-none-eabi/lib -Wl,--gc-sections -Wl,--no-wchar-size-warning -Wl,--print-memory-usage -mcpu=cortex-m4 -march=armv7e-m -mthumb -nostartfiles -std=c99 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -ffunction-sections -fdata-sections -g -gstrict-dwarf -Wall " CACHE INTERNAL "executable linker flags") +set(CMAKE_EXE_LINKER_FLAGS " -mfpu=fpv4-sp-d16 -ffunction-sections -fdata-sections -g -gdwarf-3 -gstrict-dwarf -Wall -mcpu=cortex-m4 -nostartfiles -static -Wl,--gc-sections -L${PROJECT_BINARY_DIR}/SimpleLinkCC13x2_26x2SDK_Source/source -L${PROJECT_BINARY_DIR}/SimpleLinkCC13x2_26x2SDK_Source/kernel/tirtos/packages -L${PROJECT_BINARY_DIR}/SimpleLinkCC13x2_26x2SDK_Source/kernel/tirtos/packages/gnu/targets/arm/libs/install-native/arm-none-eabi/lib/thumb/v7e-m/hard -Wl,--gc-sections -Wl,--no-wchar-size-warning -Wl,--print-memory-usage -march=armv7e-m -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Wall " CACHE INTERNAL "executable linker flags") function(NF_SET_COMPILER_OPTIONS TARGET) diff --git a/CMake/Modules/TI_SimpleLink_CC13x2_26x2_sources.cmake b/CMake/Modules/TI_SimpleLink_CC13x2_26x2_sources.cmake index 12c5c2321a..66964778b1 100644 --- a/CMake/Modules/TI_SimpleLink_CC13x2_26x2_sources.cmake +++ b/CMake/Modules/TI_SimpleLink_CC13x2_26x2_sources.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # @@ -9,13 +9,15 @@ string(REPLACE "TI_" "" TARGET_NAME_SHORT "${TARGET_NAME}") # includes for SimpleLink CC13x2_26x2 SDK -list(APPEND TI_SimpleLink_INCLUDE_DIRS "${PROJECT_BINARY_DIR}/SimpleLinkCC13x2_26x2SDK_Source") -list(APPEND TI_SimpleLink_INCLUDE_DIRS "${PROJECT_BINARY_DIR}/SimpleLinkCC13x2_26x2SDK_Source/ti/drivers") -list(APPEND TI_SimpleLink_INCLUDE_DIRS "${PROJECT_BINARY_DIR}/SimpleLinkCC13x2_26x2SDK_Source/ti/boards/${TARGET_NAME_SHORT}") -list(APPEND TI_SimpleLink_INCLUDE_DIRS "${PROJECT_BINARY_DIR}/SimpleLinkCC13x2_26x2SDK_Source/ti/devices/cc13x2_cc26x2") -list(APPEND TI_SimpleLink_INCLUDE_DIRS "${PROJECT_BINARY_DIR}/SimpleLinkCC13x2_26x2SDK_Source/ti/devices/cc13x2_cc26x2/driverlib") -list(APPEND TI_SimpleLink_INCLUDE_DIRS "${PROJECT_BINARY_DIR}/SimpleLinkCC13x2_26x2SDK_Source/ti/net") -list(APPEND TI_SimpleLink_INCLUDE_DIRS "${PROJECT_BINARY_DIR}/SimpleLinkCC13x2_26x2SDK_Source/ti/bsd") -list(APPEND TI_SimpleLink_INCLUDE_DIRS "${PROJECT_BINARY_DIR}/SimpleLinkCC13x2_26x2SDK_Source/kernel/tirtos/packages") +list(APPEND TI_SimpleLink_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/SimpleLinkCC13x2_26x2SDK_Source) +list(APPEND TI_SimpleLink_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/SimpleLinkCC13x2_26x2SDK_Source/source) +list(APPEND TI_SimpleLink_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/SimpleLinkCC13x2_26x2SDK_Source/source/ti/devices) +list(APPEND TI_SimpleLink_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/SimpleLinkCC13x2_26x2SDK_Source/source/ti/drivers) +list(APPEND TI_SimpleLink_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/SimpleLinkCC13x2_26x2SDK_Source/source/ti/boards/${TARGET_NAME_SHORT}) +list(APPEND TI_SimpleLink_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/SimpleLinkCC13x2_26x2SDK_Source/source/ti/devices/cc13x2_cc26x2) +list(APPEND TI_SimpleLink_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/SimpleLinkCC13x2_26x2SDK_Source/source/ti/devices/cc13x2_cc26x2/driverlib) +list(APPEND TI_SimpleLink_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/SimpleLinkCC13x2_26x2SDK_Source/source/ti/net) +list(APPEND TI_SimpleLink_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/SimpleLinkCC13x2_26x2SDK_Source/source/ti/bsd) +list(APPEND TI_SimpleLink_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/SimpleLinkCC13x2_26x2SDK_Source/kernel/tirtos/packages) # the sources files are pulled into the build in the target CMakelists through the XDS tools command line diff --git a/CMake/Modules/TI_SimpleLink_CC32xx_GCC_options.cmake b/CMake/Modules/TI_SimpleLink_CC32xx_GCC_options.cmake index 53102c6aec..1017ab3789 100644 --- a/CMake/Modules/TI_SimpleLink_CC32xx_GCC_options.cmake +++ b/CMake/Modules/TI_SimpleLink_CC32xx_GCC_options.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/Modules/TI_SimpleLink_CC32xx_sources.cmake b/CMake/Modules/TI_SimpleLink_CC32xx_sources.cmake index 5a814fc525..96c2f7b1c7 100644 --- a/CMake/Modules/TI_SimpleLink_CC32xx_sources.cmake +++ b/CMake/Modules/TI_SimpleLink_CC32xx_sources.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/RTXRTOS.CMakeLists.cmake.in b/CMake/RTXRTOS.CMakeLists.cmake.in index 38c5495553..e0578412c1 100644 --- a/CMake/RTXRTOS.CMakeLists.cmake.in +++ b/CMake/RTXRTOS.CMakeLists.cmake.in @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # @@ -15,7 +15,7 @@ include(ExternalProject) PREFIX RTXRTOS SOURCE_DIR ${CMAKE_BINARY_DIR}/RTXRTOS_Source GIT_REPOSITORY https://github.com/ARM-software/CMSIS_5 - GIT_TAG master # target master branch + GIT_TAG ${RTOS_VERSION} # target master branch GIT_SHALLOW 1 # download only the tip of the branch, not the complete history TIMEOUT 10 LOG_DOWNLOAD 1 diff --git a/CMake/SPIFFS.CMakeLists.cmake.in b/CMake/SPIFFS.CMakeLists.cmake.in index 2cabb9e635..6cf344c3e1 100644 --- a/CMake/SPIFFS.CMakeLists.cmake.in +++ b/CMake/SPIFFS.CMakeLists.cmake.in @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/STM32.CubePackage.CMakeLists.cmake.in b/CMake/STM32.CubePackage.CMakeLists.cmake.in index 189a329b7a..7e20cde4db 100644 --- a/CMake/STM32.CubePackage.CMakeLists.cmake.in +++ b/CMake/STM32.CubePackage.CMakeLists.cmake.in @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/SimpleLinkCC13x2_26x2Sdk.CMakeLists.cmake.in b/CMake/SimpleLinkCC13x2_26x2Sdk.CMakeLists.cmake.in index f99ec93cce..db549a8061 100644 --- a/CMake/SimpleLinkCC13x2_26x2Sdk.CMakeLists.cmake.in +++ b/CMake/SimpleLinkCC13x2_26x2Sdk.CMakeLists.cmake.in @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/SimpleLinkCC32xxSdk.CMakeLists.cmake.in b/CMake/SimpleLinkCC32xxSdk.CMakeLists.cmake.in index c021ca72e9..8445dcec4b 100644 --- a/CMake/SimpleLinkCC32xxSdk.CMakeLists.cmake.in +++ b/CMake/SimpleLinkCC32xxSdk.CMakeLists.cmake.in @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/TI_SimpleLink_target_os.h.in b/CMake/TI_SimpleLink_target_os.h.in index 450b595152..b6f1191b51 100644 --- a/CMake/TI_SimpleLink_target_os.h.in +++ b/CMake/TI_SimpleLink_target_os.h.in @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // @@ -16,8 +16,6 @@ #define VERSION_BUILD @nanoFramework_VERSION_PATCH@U #define VERSION_REVISION @nanoFramework_VERSION_TWEAK@U -#define TARGETINFOSTRING "@CMAKE_BUILD_TYPE@ build with TI SL CC32xx SDK v3.10.00.04" - #define NANOCLR_LIGHT_MATH @TARGET_LIGHT_MATH@ #define DP_FLOATINGPOINT @TARGET_DP_FLOATINGPOINT@ diff --git a/CMake/TI_SysConfig.CMakeLists.cmake.in b/CMake/TI_SysConfig.CMakeLists.cmake.in new file mode 100644 index 0000000000..1d94c9e7d0 --- /dev/null +++ b/CMake/TI_SysConfig.CMakeLists.cmake.in @@ -0,0 +1,27 @@ +# +# Copyright (c) .NET Foundation and Contributors +# See LICENSE file in the project root for full license information. +# + +cmake_minimum_required(VERSION 3.15) + +project(TI_SysConfig-download NONE) + +include(ExternalProject) + +# download TI XDCTools from nanoFramework repo +ExternalProject_Add( + TI_SysConfig + PREFIX TI_SysConfig + SOURCE_DIR ${CMAKE_BINARY_DIR}/TI_SysConfig + GIT_REPOSITORY https://github.com/nanoframework/TI_SysConfig + GIT_TAG ${TI_SYSCONFIG_VERSION_TAG} # target specified branch + GIT_SHALLOW 1 # download only the tip of the branch, not the complete history + TIMEOUT 10 + LOG_DOWNLOAD 1 + + # Disable all other steps + INSTALL_COMMAND "" + CONFIGURE_COMMAND "" + BUILD_COMMAND "" +) diff --git a/CMake/TI_XDCTools.CMakeLists.cmake.in b/CMake/TI_XDCTools.CMakeLists.cmake.in index c3fe8d14ba..8e10e2eafd 100644 --- a/CMake/TI_XDCTools.CMakeLists.cmake.in +++ b/CMake/TI_XDCTools.CMakeLists.cmake.in @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/binutils.ChibiOS.cmake b/CMake/binutils.ChibiOS.cmake index d8c2ed75f1..050680a5f3 100644 --- a/CMake/binutils.ChibiOS.cmake +++ b/CMake/binutils.ChibiOS.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/binutils.FreeRTOS.cmake b/CMake/binutils.FreeRTOS.cmake index d454b09ffa..bd96de388f 100644 --- a/CMake/binutils.FreeRTOS.cmake +++ b/CMake/binutils.FreeRTOS.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # @@ -7,8 +7,8 @@ function(NF_SET_OPTIMIZATION_OPTIONS TARGET) target_compile_options(${TARGET} PRIVATE $<$:-Og -femit-class-debug-always -g3 -ggdb> - $<$:-O3> - $<$:-Os> + $<$:-O3 -flto -fuse-linker-plugin -fno-fat-lto-objects> + $<$:-Os -flto -fuse-linker-plugin -fno-fat-lto-objects> $<$:-Os -femit-class-debug-always -g3 -ggdb> ) diff --git a/CMake/binutils.TI_SimpleLink.cmake b/CMake/binutils.TI_SimpleLink.cmake index b7548bd13d..3a94f93412 100644 --- a/CMake/binutils.TI_SimpleLink.cmake +++ b/CMake/binutils.TI_SimpleLink.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/binutils.arm-none-eabi.cmake b/CMake/binutils.arm-none-eabi.cmake index e5dcfa9462..57908370d8 100644 --- a/CMake/binutils.arm-none-eabi.cmake +++ b/CMake/binutils.arm-none-eabi.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/mBedOS.CMakeLists.cmake.in b/CMake/mBedOS.CMakeLists.cmake.in deleted file mode 100644 index 2e5904596d..0000000000 --- a/CMake/mBedOS.CMakeLists.cmake.in +++ /dev/null @@ -1,27 +0,0 @@ -# -# Copyright (c) 2019 The nanoFramework project contributors -# See LICENSE file in the project root for full license information. -# - -cmake_minimum_required(VERSION 3.15) - -project(mBedOS-download NONE) - -include(ExternalProject) - -# download mBed RTOS source from official mBed GitHub repo - ExternalProject_Add( - mBedOS - PREFIX mBedOS - SOURCE_DIR ${CMAKE_BINARY_DIR}/mBedOS_Source - GIT_REPOSITORY https://github.com/ARMmbed/mbed-os/ - GIT_TAG master # target master branch - GIT_SHALLOW 1 # download only the tip of the branch, not the complete history - TIMEOUT 10 - LOG_DOWNLOAD 1 - - # Disable all other steps - CONFIGURE_COMMAND "" - BUILD_COMMAND "" - INSTALL_COMMAND "" - ) diff --git a/CMake/mbedTLS.CMakeLists.cmake.in b/CMake/mbedTLS.CMakeLists.cmake.in index 492a5c678f..cbe310688a 100644 --- a/CMake/mbedTLS.CMakeLists.cmake.in +++ b/CMake/mbedTLS.CMakeLists.cmake.in @@ -1,5 +1,5 @@ # -# Copyright (c) 2018 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/toolchain.arm-none-eabi.cmake b/CMake/toolchain.arm-none-eabi.cmake index 035033a3af..3fb1a2cf98 100644 --- a/CMake/toolchain.arm-none-eabi.cmake +++ b/CMake/toolchain.arm-none-eabi.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/CMake/toolchain.xtensa-esp32-elf.cmake b/CMake/toolchain.xtensa-esp32-elf.cmake index 7c4a940f36..ee2e5cf32c 100644 --- a/CMake/toolchain.xtensa-esp32-elf.cmake +++ b/CMake/toolchain.xtensa-esp32-elf.cmake @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # @@ -9,9 +9,9 @@ include(CMakeForceCompiler) set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY ) # set toolchain directories -set(TOOLCHAIN_BIN_DIR ${TOOLCHAIN_PREFIX}/xtensa-esp32-elf/bin) +set(TOOLCHAIN_BIN_DIR ${TOOLCHAIN_PREFIX}/bin) set(TOOLCHAIN_INC_DIR ${ESP32_IDF_PATH}/components/newlib/include) -set(TOOLCHAIN_LIB_DIR ${TOOLCHAIN_PREFIX}/xtensa-esp32-elf/xtensa-esp32-elf/lib) +set(TOOLCHAIN_LIB_DIR ${TOOLCHAIN_PREFIX}/xtensa-esp32-elf/lib) # the name of the operating system for which CMake is to build set(CMAKE_SYSTEM_NAME Generic) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1eaf139d02..83ddaa42c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # @@ -8,7 +8,9 @@ cmake_minimum_required(VERSION 3.15) include(CMakeToolsHelpers OPTIONAL) include(ExternalProject) -set(CMAKE_VERBOSE_MAKEFILE 1) # debug helper +if (BUILD_VERBOSE) + set(CMAKE_VERBOSE_MAKEFILE ON CACHE BOOL "ON" FORCE) # debug helper +endif() # the following prevents launchin a build in the source tree set(CMAKE_DISABLE_SOURCE_CHANGES ON) @@ -499,10 +501,10 @@ else() endif() -if(API_System.Devices.Dac) - set(HAL_USE_DAC_OPTION TRUE CACHE INTERNAL "HAL DAC for System.Devices.Dac") +if(API_System.Device.Dac) + set(HAL_USE_DAC_OPTION TRUE CACHE INTERNAL "HAL DAC for System.Device.Dac") else() - set(HAL_USE_DAC_OPTION FALSE CACHE INTERNAL "HAL DAC for System.Devices.Dac") + set(HAL_USE_DAC_OPTION FALSE CACHE INTERNAL "HAL DAC for System.Device.Dac") endif() @@ -693,44 +695,13 @@ if(RTOS_CHIBIOS_CHECK) endif() endif() -####################### -# FreeRTOS -elseif(RTOS_FREERTOS_CHECK) - - add_subdirectory(targets/FreeRTOS) ####################### # FreeRTOS elseif(RTOS_FREERTOS_CHECK) add_subdirectory(targets/FreeRTOS) - - # now add the subdirectory for the board - # try to find board in the targets folder - if(EXISTS ${PROJECT_SOURCE_DIR}/targets/FreeRTOS/NXP/${FREERTOS_BOARD}) - # board found - message(STATUS "Support for target board '${FREERTOS_BOARD}' found") - - # add TARGET board directory - add_subdirectory("targets/FreeRTOS/NXP/${FREERTOS_BOARD}") - else() - - # try to find board in the Community targets folder - if(EXISTS ${PROJECT_SOURCE_DIR}/targets-community/FreeRTOS/NXP/${FREERTOS_BOARD}) - # board found - message(STATUS "Support for target board '${FREERTOS_BOARD}' found in Community targets") - - # add TARGET board directory from Community - add_subdirectory("targets-community/FreeRTOS/NXP/${FREERTOS_BOARD}") - - else() - # board NOT found in targets folder - # board NOT found in targets folder - message(FATAL_ERROR "\n\nSorry but support for ${FREERTOS_BOARD} target is not available...\n\You can wait for that to be added or you might want to contribute and start working on a PR for that.\n\n") - endif() - - endif() ####################### # FreeRTOS ESP32 elseif(RTOS_FREERTOS_ESP32_CHECK) @@ -738,8 +709,14 @@ elseif(RTOS_FREERTOS_ESP32_CHECK) if("${TARGET_SERIES}" STREQUAL "ESP32") message(STATUS "Platform ESP32 target board: ${ESP32_BOARD}") + if(API_nanoFramework.Hardware.Esp32.Rmt) + set(HAL_USE_ESP32_RMT_OPTION TRUE CACHE INTERNAL "HAL RMT for nanoFramework.Hardware.Esp32.Rmt") + else() + set(HAL_USE_ESP32_RMT_OPTION FALSE CACHE INTERNAL "HAL RMT for nanoFramework.Hardware.Esp32.Rmt") + endif() + # check watchdog feature - # EPS32 build has watchdog enabled by default, so setting it to OFF doens't make sense + # EPS32 build has watchdog enabled by default, so setting it to OFF doesn't make sense # becuase the build system can't honour that preference if(NOT NF_FEATURE_WATCHDOG) message(FATAL_ERROR "\n\nESP32 watchdog is enabled by default in so you can't have the NF_FEATURE_WATCHDOG option set to OFF.\n\n") diff --git a/CMakeSettings.SAMPLE.json b/CMakeSettings.SAMPLE.json index f2e528edb9..9f3209f169 100644 --- a/CMakeSettings.SAMPLE.json +++ b/CMakeSettings.SAMPLE.json @@ -20,12 +20,12 @@ }, { "name": "ESP32_TOOLCHAIN_PATH", - "value": "C:/ESP32_TOOLS", + "value": "C:/ESP32_TOOLS/xtensa-esp32-elf", "type": "PATH" }, { "name": "TOOLCHAIN_PREFIX", - "value": "C:/ESP32_TOOLS", + "value": "C:/ESP32_TOOLS/xtensa-esp32-elf", "type": "PATH" }, { @@ -160,8 +160,8 @@ }, { "name": "NF_INTEROP_ASSEMBLIES", - "value": "False", - "type": "BOOL" + "value": "Assembly1_Namespace Assembly2_Namespace", + "type": "STRING" }, { "name": "NF_NETWORKING_SNTP", @@ -199,7 +199,7 @@ "type": "BOOL" }, { - "name": "API_System.Devices.Dac", + "name": "API_System.Device.Dac", "value": "False", "type": "BOOL" }, @@ -299,7 +299,7 @@ "type": "STRING" }, { - "name": "CHIBIOS_SOURCE", + "name": "RTOS_SOURCE_FOLDER", "value": "C:/usr/src/NanoFramework/ChibiOS", "type": "PATH" }, @@ -420,8 +420,8 @@ }, { "name": "NF_INTEROP_ASSEMBLIES", - "value": "OFF", - "type": "BOOL" + "value": "Assembly1_Namespace Assembly2_Namespace", + "type": "STRING" }, { "name": "NF_NETWORKING_SNTP", @@ -459,7 +459,7 @@ "type": "BOOL" }, { - "name": "API_System.Devices.Dac", + "name": "API_System.Device.Dac", "value": "False", "type": "BOOL" }, diff --git a/CMakeSettings.json b/CMakeSettings.json index d74fb3620b..de047c9034 100644 --- a/CMakeSettings.json +++ b/CMakeSettings.json @@ -48,7 +48,7 @@ "value": "ST_STM32F769I_DISCOVERY" }, { - "name": "CHIBIOS_SOURCE", + "name": "RTOS_SOURCE_FOLDER", "value": "E:/GitHub/ChibiOS" }, { @@ -141,7 +141,7 @@ }, { "name": "NF_INTEROP_ASSEMBLIES", - "value": "OFF" + "value": "" }, { "name": "NF_NETWORKING_SNTP", @@ -172,7 +172,7 @@ "value": "ON" }, { - "name": "API_System.Devices.Dac", + "name": "API_System.Device.Dac", "value": "ON" }, { @@ -367,8 +367,8 @@ "value": "OFF" }, { - "name": "NF_INTEROP_ASSEMBLIES:BOOL", //OFF-default-ON-to-disable-CLR-IL-inlining - "value": "OFF" + "name": "NF_INTEROP_ASSEMBLIES:STRING", //empty-to-NOT-include-any-interop-assemblies + "value": "" }, { "name": "NF_NETWORKING_SNTP:BOOL", //ON-default-to-add-SNTP-client-requires-networking @@ -412,7 +412,7 @@ "value": "ON" }, { - "name": "API_System.Devices.Dac:BOOL", //OFF-default-ON-to-add-this-API + "name": "API_System.Device.Dac:BOOL", //OFF-default-ON-to-add-this-API "value": "ON" }, { diff --git a/InteropAssemblies/CLR_RT_InteropAssembliesTable.cpp.in b/InteropAssemblies/CLR_RT_InteropAssembliesTable.cpp.in index a8649fb7cd..e21be78352 100644 --- a/InteropAssemblies/CLR_RT_InteropAssembliesTable.cpp.in +++ b/InteropAssemblies/CLR_RT_InteropAssembliesTable.cpp.in @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000..94286c941a --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) .NET Foundation and Contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/LICENSE.md b/LICENSE.md deleted file mode 100644 index 44a0d2d8f3..0000000000 --- a/LICENSE.md +++ /dev/null @@ -1,192 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - - Copyright 2017 The nanoFramework project contributors - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. \ No newline at end of file diff --git a/README.md b/README.md index 3dc6e0c2e0..0c92c80662 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![#yourfirstpr](https://img.shields.io/badge/first--timers--only-friendly-blue.svg)](https://github.com/nanoframework/Home/blob/master/CONTRIBUTING.md) +[![License](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE) [![#yourfirstpr](https://img.shields.io/badge/first--timers--only-friendly-blue.svg)](https://github.com/nanoframework/Home/blob/master/CONTRIBUTING.md) [![Discord](https://img.shields.io/discord/478725473862549535.svg)](https://discord.gg/gCyBu8T) @@ -101,9 +101,13 @@ The list of contributors to this project can be found at [CONTRIBUTORS](https:// ## License -The nanoFramework Interpreter is licensed under the [Apache 2.0 license](http://www.apache.org/licenses/LICENSE-2.0). +The nanoFramework Interpreter is licensed under the [MIT license](LICENSE.md). ## Code of Conduct -This project has adopted the code of conduct defined by the [Contributor Covenant](CODE_OF_CONDUCT.md) -to clarify expected behavior in our community. +This project has adopted the code of conduct defined by the Contributor Covenant to clarify expected behavior in our community. +For more information see the [.NET Foundation Code of Conduct](https://dotnetfoundation.org/code-of-conduct). + +### .NET Foundation + +This project is supported by the [.NET Foundation](https://dotnetfoundation.org). diff --git a/README.zh-cn.md b/README.zh-cn.md index aee098c610..0b8084a8c4 100644 --- a/README.zh-cn.md +++ b/README.zh-cn.md @@ -1,4 +1,4 @@ -[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![#yourfirstpr](https://img.shields.io/badge/first--timers--only-friendly-blue.svg)](https://github.com/nanoframework/Home/blob/master/CONTRIBUTING.md) +[![License](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE) [![#yourfirstpr](https://img.shields.io/badge/first--timers--only-friendly-blue.svg)](https://github.com/nanoframework/Home/blob/master/CONTRIBUTING.md) [![Discord](https://img.shields.io/discord/478725473862549535.svg)](https://discord.gg/gCyBu8T) @@ -100,7 +100,7 @@ ## 授权 -nanoFramework 解析器基于 [Apache 2.0 license](http://www.apache.org/licenses/LICENSE-2.0) 授权。 +**nanoFramework** 解析器基于 [MIT license](LICENSE.md) 授权。 ## 行为准则 diff --git a/azure-pipelines-templates/build-chibios-stm32.yml b/azure-pipelines-templates/build-chibios-stm32.yml index bb81e734b7..6cad48d497 100644 --- a/azure-pipelines-templates/build-chibios-stm32.yml +++ b/azure-pipelines-templates/build-chibios-stm32.yml @@ -1,4 +1,4 @@ -# Copyright (c) 2018 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. parameters: diff --git a/azure-pipelines-templates/build-esp32.yml b/azure-pipelines-templates/build-esp32.yml index af9ca47cc2..dc88017ab6 100644 --- a/azure-pipelines-templates/build-esp32.yml +++ b/azure-pipelines-templates/build-esp32.yml @@ -1,4 +1,4 @@ -# Copyright (c) 2018 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. parameters: @@ -17,16 +17,16 @@ steps: workingDirectory: ${{ parameters.buildDirectory }} displayName: Build with CMake + # because of permission issues (the python script isn't allowed to write on the output folder) + # we need to perform these steps by calling directly the python scripts - task: PythonScript@0 inputs: scriptSource: 'filePath' scriptPath: '$(Agent.TempDirectory)\ESP32_Tools\esp-idf-v3.3.1\components\esptool_py\esptool\esptool.py' - arguments: '--chip esp32 elf2image --flash_mode dio --flash_freq 40m --flash_size 4MB -o ${{ parameters.buildDirectory }}\nanoCLR.bin ${{ parameters.buildDirectory }}\targets\FreeRTOS_ESP32\$(BoardName)\nanoCLR.elf' + arguments: '--chip esp32 elf2image --flash_mode dio --flash_freq 40m --flash_size 4MB -o ${{ parameters.buildDirectory }}\nanoCLR.bin ${{ parameters.buildDirectory }}\nanoCLR.elf' condition: succeeded() displayName: Generate nanoCLR bin file for deployment - # because of permission issues (the python script isn't allowed to write on the output folder) - # we need to perform these steps by calling directly the python scripts - task: PythonScript@0 inputs: scriptSource: 'filePath' diff --git a/azure-pipelines-templates/build-freertos-nxp.yml b/azure-pipelines-templates/build-freertos-nxp.yml index efe84d19c6..8c58576dc9 100644 --- a/azure-pipelines-templates/build-freertos-nxp.yml +++ b/azure-pipelines-templates/build-freertos-nxp.yml @@ -1,4 +1,4 @@ -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. parameters: diff --git a/azure-pipelines-templates/build-ti-simplelink.yml b/azure-pipelines-templates/build-ti-simplelink.yml index 1caf3d3b6b..558b59bfd3 100644 --- a/azure-pipelines-templates/build-ti-simplelink.yml +++ b/azure-pipelines-templates/build-ti-simplelink.yml @@ -1,4 +1,4 @@ -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. parameters: diff --git a/azure-pipelines-templates/check-code-style.yml b/azure-pipelines-templates/check-code-style.yml new file mode 100644 index 0000000000..49f60f37ca --- /dev/null +++ b/azure-pipelines-templates/check-code-style.yml @@ -0,0 +1,169 @@ +# Copyright (c) .NET Foundation and Contributors +# See LICENSE file in the project root for full license information. + +steps: + + - task: PowerShell@2 + name: Check_Code_Style + displayName: Check code style + condition: eq(variables['Build.Reason'], 'PullRequest') + inputs: + failOnStderr: false + targetType: 'inline' + script: | + # need this to remove definition of redirect stdErr (only on Azure Pipelines image fo VS2019) + $env:GIT_REDIRECT_STDERR = '2>&1' + + # compute authorization header in format "AUTHORIZATION: basic 'encoded token'" + # 'encoded token' is the Base64 of the string "nfbot:personal-token" + $auth = "basic $([System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("nfbot:$(GitHubToken)"))))" + + git config --global gc.auto 0 + git config --global user.name nfbot + git config --global user.email nanoframework@outlook.com + git config --global core.autocrlf true + + # find PR + "Getting PR#$env:System_PullRequest_PullRequestNumber details..." | Write-Host -ForegroundColor White -NoNewline + $pr = Invoke-WebRequest "https://api.github.com/repos/nanoFramework/nf-interpreter/pulls/$env:System_PullRequest_PullRequestNumber" | ConvertFrom-Json + + if($($pr.number) -eq "$env:System_PullRequest_PullRequestNumber") + { + 'OK' | Write-Host -ForegroundColor Green + } + + # fetch GitHub repo & branches + Write-Debug "Fetch GitHub repo & branches" + + # add remote for PR head + "Adding remote: $($pr.head.repo.html_url)..." | Write-Host -ForegroundColor White + + git remote add pr-branch "$($pr.head.repo.html_url)" > $null + git fetch --quiet --all > $null + + # checkout from PR repo/branch + "Checkout remote branch: $($pr.head.ref)..." | Write-Host -ForegroundColor White + + git checkout --quiet --no-progress "refs/remotes/pr-branch/$($pr.head.ref)" > $null + + # switch to working branch + $branchName = "nfbot/clang-format-fix/$([guid]::NewGuid().ToString())" + git switch --quiet --no-progress -c $branchName > $null + + "Working branch is $branchName" | Write-Host -ForegroundColor White + + # list PR files + $prFiles = Invoke-WebRequest "https://api.github.com/repos/nanoFramework/nf-interpreter/pulls/$env:System_PullRequest_PullRequestNumber/files" | ConvertFrom-Json + + "Starting file check..." | Write-Host -ForegroundColor White + + # find clang-format + $clangFormat = "clang-format.exe" + if(!(Get-Command $clangFormat -ErrorAction SilentlyContinue)) + { + Write-Information "Can't find clang-format.exe in %PATH%, trying to use %VCINSTALLDIR%..." + + $clangFormat="$(Agent.TempDirectory)\llvm\bin\clang-format.exe" + + if(!(Test-Path -Path $clangFormat -PathType leaf)) + { + "Can't find clang-format.exe executable!" | Write-Host -ForegroundColor Red + } + } + + # have clang-format parse each file source file + foreach($file in $prFiles) + { + Write-Debug "checking: $($file.filename)" + + # don't process deleted files + if( $($file.status) -eq "modified" -or + $($file.status) -eq "added" -or + $($file.status) -eq "renamed") + { + # we only care about C/C++ source files and headers + if( $($file.filename).endswith(".c") -or + $($file.filename).endswith(".cpp") -or + $($file.filename).endswith(".h")) + { + "Parsing '$($file.filename)'..." | Write-Host -ForegroundColor White -NoNewline + + # parse file + & $clangFormat -style=file -i "$($file.filename)" + + "OK" | Write-Host -ForegroundColor Green + } + } + } + + # check if anything was changed + $repoStatus = "$(git status --short --porcelain)" + + if ($repoStatus -ne "") + { + "Commit changes..." | Write-Host -ForegroundColor White + + # commit changed files + git add -A 2>&1 + git commit -m "Code style fixes" -m "Automated fixes for code style." > $null + + "Pushing changes..." | Write-Host -ForegroundColor White + + # push to nf-interpreter repo + git -c http.extraheader="AUTHORIZATION: $auth" push --porcelain --set-upstream origin "$branchName" + + # submit PR with code style fixes + $prRequestBody = @{title="Code style fixes for $env:Build_Repository_Name PR#$env:System_PullRequest_PullRequestNumber";body="Automated fix of code style using project clang-format rules.`nYou can review and make changes or simply merge this PR to apply the fixes.";head="nanoFramework:$branchName";base="$($pr.head.ref)"} | ConvertTo-Json + + # start PR + Write-Debug "Starting PR with fixes." + "Creating PR..." | Write-Host -ForegroundColor White + + $githubApiEndpoint = "https://api.github.com/repos/$($pr.head.repo.full_name)/pulls" + [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 + + try + { + $result = Invoke-RestMethod -Method Post -UserAgent [Microsoft.PowerShell.Commands.PSUserAgent]::InternetExplorer -Uri $githubApiEndpoint -Header @{"Authorization"="$auth"} -ContentType "application/json" -Body $prRequestBody + 'Submitting PR with code style fixes...' | Write-Host -ForegroundColor White -NoNewline + + 'OK' | Write-Host -ForegroundColor Green + + # PR submitted, add a comment + $codeStyleFixesComment = @{body="@$($pr.user.login) there are issues with the code style on the source files.`nA PR was submitted with the code style fixes. Please review and merge the changes. See $($result.html_url).`n`nMake sure you are using the project code style. Check the details [here](https://docs.nanoframework.net/content/contributing/cxx-coding-style.html)."} | ConvertTo-Json + Invoke-RestMethod -Method Post -UserAgent [Microsoft.PowerShell.Commands.PSUserAgent]::InternetExplorer -Uri $($pr.comments_url) -Header @{"Authorization"="$auth"} -ContentType "application/json" -Body $codeStyleFixesComment + } + catch + { + "Failed" | Write-Host -ForegroundColor Red + + $result = $_.Exception.Response.GetResponseStream() + $reader = New-Object System.IO.StreamReader($result) + $reader.BaseStream.Position = 0 + $reader.DiscardBufferedData() + $responseBody = $reader.ReadToEnd() + + "Error submitting PR: $responseBody" | Write-Host -ForegroundColor Red + + # most likely this is a permissions issue because the base repo is read only or protected + # report to user + $codeStyleFixesComment = @{body="@$($pr.user.login) there are issues with the code style on the source files.`n`n:warning:Couldn't submit a PR with the fixes against your repo.:warning:`n`nPlease merge the changes from https://github.com/nanoframework/nf-interpreter/tree/$branchName."} | ConvertTo-Json + $result = Invoke-RestMethod -Method Post -UserAgent [Microsoft.PowerShell.Commands.PSUserAgent]::InternetExplorer -Uri $($pr.comments_url) -Header @{"Authorization"="$auth"} -ContentType "application/json" -Body $codeStyleFixesComment + + throw "Error starting PR: $responseBody" + } + + # set variable to skip build failure report on Discord + echo "##vso[task.setvariable variable=CODE_STYLE_CHECK_FAILED;isOutput=true]true" + + # force the check to fail + throw "Code style check failed" + } + + - task: PowerShell@2 + name: Check_Code_Style_SKIP + displayName: Check code style (SKIP) + condition: ne(variables['Build.Reason'], 'PullRequest') + inputs: + targetType: 'inline' + script: exit 0 diff --git a/azure-pipelines-templates/download-hexdfu.yml b/azure-pipelines-templates/download-hexdfu.yml index 94f4be0f81..cff0ebb052 100644 --- a/azure-pipelines-templates/download-hexdfu.yml +++ b/azure-pipelines-templates/download-hexdfu.yml @@ -1,10 +1,10 @@ -# Copyright (c) 2018 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. steps: - task: Cache@2 inputs: - key: hex2dfuKey + key: '1-0 | hex2dfuKey' restoreKeys: hex2dfuKey path: $(Agent.TempDirectory)/hex2dfu cacheHitVar: HEX2DFU_CACHE_RESTORED @@ -12,18 +12,12 @@ steps: displayName: Cache HEX2DFU - task: PowerShell@2 - inputs: - targetType: 'inline' - script: | - md -Force "$env:Agent_TempDirectory\hex2dfu" | Out-Null - Write-Host "Downloading hex2dfu..." - $url = "https://github.com/nanoframework/hex2dfu/releases/latest/download/hex2dfu.exe" - $output = "$env:Agent_TempDirectory\hex2dfu\hex2dfu.exe" - (New-Object Net.WebClient).DownloadFile($url, $output) - errorActionPreference: 'stop' - failOnStderr: 'true' condition: and( eq(variables['NeedsDFU'], true), ne(variables.HEX2DFU_CACHE_RESTORED, 'true')) displayName: Install HEX2DFU + inputs: + targetType: 'filePath' + filePath: 'install-scripts\install-nf-hex2dfu.ps1' + failOnStderr: 'true' - task: PowerShell@2 inputs: diff --git a/azure-pipelines-templates/download-install-arm-gcc-toolchain.yml b/azure-pipelines-templates/download-install-arm-gcc-toolchain.yml index 28298243e4..c7ea547e2c 100644 --- a/azure-pipelines-templates/download-install-arm-gcc-toolchain.yml +++ b/azure-pipelines-templates/download-install-arm-gcc-toolchain.yml @@ -1,47 +1,31 @@ -# Copyright (c) 2018 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. steps: - task: Cache@2 + condition: eq(variables.GccArm_Version, '') + displayName: Cache ARM GCC toolchain inputs: - key: gccUpdateKey + key: '9-2020-q2-update | gccUpdateKey' restoreKeys: gccUpdateKey path: $(Agent.TempDirectory)\GNU_Tools_ARM_Embedded cacheHitVar: GCC_CACHE_RESTORED - condition: eq(variables.GccArm_Version, '') - displayName: Cache ARM GCC toolchain - task: PowerShell@2 - inputs: - targetType: 'inline' - script: | - - # this is the default GNU GCC ARM version - $gccVersion = "8-2019-q3-update" - - if("$(GccArm_Version)" -ne "") - { - # specific version requested, replace default one - $gccVersion = "$(GccArm_Version)" - } - - $url = "https://bintray.com/nfbot/internal-build-tools/download_file?file_path=gcc-arm-none-eabi-$gccVersion-win32.7z" - - Write-Host "Downloading ARM GNU GCC toolchain $(GccArm_Version)..." - - $output = "$PSScriptRoot\gcc-arm.7z" - (New-Object Net.WebClient).DownloadFile($url, $output) - errorActionPreference: 'stop' - failOnStderr: 'true' condition: ne(variables.GCC_CACHE_RESTORED, 'true') displayName: Downloading ARM GCC toolchain + inputs: + targetType: 'filePath' + filePath: 'install-scripts\install-arm-gcc-toolchain.ps1' + arguments: '-Version "$(GccArm_Version)"' + failOnStderr: true - task: ExtractFiles@1 + displayName: Extracting ARM GCC toolchain + condition: ne(variables.GCC_CACHE_RESTORED, 'true') inputs: archiveFilePatterns: '$(Agent.TempDirectory)\gcc-arm.7z' destinationFolder: '$(Agent.TempDirectory)\GNU_Tools_ARM_Embedded' - condition: ne(variables.GCC_CACHE_RESTORED, 'true') - displayName: Extracting ARM GCC toolchain - script: echo "##vso[task.prependpath]C:\Windows\System32" displayName: Tweak PATH to reach cmd diff --git a/azure-pipelines-templates/download-install-esp32-build-components.yml b/azure-pipelines-templates/download-install-esp32-build-components.yml index 67cca0e7be..1adda34c78 100644 --- a/azure-pipelines-templates/download-install-esp32-build-components.yml +++ b/azure-pipelines-templates/download-install-esp32-build-components.yml @@ -1,87 +1,70 @@ -# Copyright (c) 2018 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. steps: - task: Cache@2 inputs: - key: esp331ToolsKey + key: '3-3-1 | esp331ToolsKey' restoreKeys: esp331ToolchainKey path: $(Agent.TempDirectory)\ESP32_Tools cacheHitVar: ESP_TOOLS_CACHE_RESTORED displayName: Cache ESP32 tools - task: PowerShell@2 + displayName: Download & install xtensa ESP32 toolchain inputs: - targetType: 'inline' - script: | - Write-Host "Downloading Xtensa ESP32 toolchain..." - $url = "https://dl.espressif.com/dl/xtensa-esp32-elf-win32-1.22.0-80-g6c4433a-5.2.0.zip" - $output = "$PSScriptRoot\xtensa-esp32-elf-win32.zip" - (New-Object Net.WebClient).DownloadFile($url, $output) - errorActionPreference: 'stop' - failOnStderr: 'true' - condition: ne(variables.ESP_TOOLS_CACHE_RESTORED, 'true') - displayName: Download xtensa ESP32 toolchain + targetType: 'filePath' + filePath: 'install-scripts\install-esp32-toolchain.ps1' + failOnStderr: true - task: ExtractFiles@1 + condition: ne(variables.ESP_TOOLS_CACHE_RESTORED, 'true') + displayName: Extracting xtensa ESP32 toolchain inputs: archiveFilePatterns: '$(Agent.TempDirectory)\xtensa-esp32-elf-win32.zip' destinationFolder: '$(Agent.TempDirectory)\ESP32_Tools' cleanDestinationFolder: false - condition: ne(variables.ESP_TOOLS_CACHE_RESTORED, 'true') - displayName: Extracting xtensa ESP32 toolchain - task: PowerShell@2 + displayName: Downloading & install ESP32 pre-compiled libs inputs: - targetType: 'inline' - script: | - Write-Host "Downloading ESP32 pre-compiled libs..." - $url = "https://bintray.com/nfbot/internal-build-tools/download_file?file_path=IDF_libs-v3.3.1.zip" - $output = "$PSScriptRoot\IDF_libs-v3.3.1.zip" - (New-Object Net.WebClient).DownloadFile($url, $output) - errorActionPreference: 'stop' - failOnStderr: 'true' - condition: ne(variables.ESP_TOOLS_CACHE_RESTORED, 'true') - displayName: Downloading ESP32 pre-compiled libs + targetType: 'filePath' + filePath: 'install-scripts\install-esp32-libs.ps1' + failOnStderr: true - task: ExtractFiles@1 - inputs: - archiveFilePatterns: '$(Agent.TempDirectory)\IDF_libs-v3.3.1.zip' - destinationFolder: '$(Agent.TempDirectory)\ESP32_Tools\libs-v3.3.1' - cleanDestinationFolder: false condition: ne(variables.ESP_TOOLS_CACHE_RESTORED, 'true') displayName: Installing ESP32 pre-compiled libs - + inputs: + archiveFilePatterns: '$(Agent.TempDirectory)\esp-idf-libs.zip' + destinationFolder: '$(Agent.TempDirectory)\ESP32_Tools\libs' + cleanDestinationFolder: false + - task: PowerShell@2 + displayName: Downloading & install ESP32 IDF inputs: - targetType: 'inline' - script: | - Write-Host "Downloading ESP32 IDF..." - $url = "https://dl.espressif.com/dl/esp-idf/releases/esp-idf-v3.3.1.zip" - $output = "$PSScriptRoot\esp-idf-v3.3.1.zip" - (New-Object Net.WebClient).DownloadFile($url, $output) - errorActionPreference: 'stop' - failOnStderr: 'true' - condition: ne(variables.ESP_TOOLS_CACHE_RESTORED, 'true') - displayName: Downloading ESP32 IDF + targetType: 'filePath' + filePath: 'install-scripts\install-esp32-idf.ps1' + failOnStderr: true - task: ExtractFiles@1 + condition: ne(variables.ESP_TOOLS_CACHE_RESTORED, 'true') + displayName: Installing Espressif IDF inputs: - archiveFilePatterns: '$(Agent.TempDirectory)\esp-idf-v3.3.1.zip' + archiveFilePatterns: '$(Agent.TempDirectory)\esp-idf.zip' destinationFolder: '$(Agent.TempDirectory)\ESP32_Tools' cleanDestinationFolder: false - condition: ne(variables.ESP_TOOLS_CACHE_RESTORED, 'true') - displayName: Installing Espressif IDF # Use Python Version 3.7 and add it to path - task: UsePythonVersion@0 + displayName: Set Python to v3.7 inputs: versionSpec: '3.7' addToPath: true - displayName: Set Python to v3.7 # in this one have to call Python with full path otherwise it can fail - task: PowerShell@2 + displayName: Installing python pyserial inputs: targetType: 'inline' script: python -m pip install pyserial @@ -89,19 +72,6 @@ steps: errorActionPreference: 'silentlyContinue' failOnStderr: false ignoreLASTEXITCODE: false - displayName: Installing python pyserial - - - task: PowerShell@2 - inputs: - targetType: 'inline' - script: | - # need to replace forward slash for paths to work with GCC and CMake - $tempDirPath = "$env:Agent_TempDirectory".Replace('\','/') - Write-Host "$("##vso[task.setvariable variable=ESP32_LIBS_PATH]")$tempDirPath/ESP32_Tools/libs-v3.3.1" - Write-Host "$("##vso[task.setvariable variable=ESP32_IDF_PATH]")$tempDirPath/ESP32_Tools/esp-idf-v3.3.1" - errorActionPreference: 'stop' - failOnStderr: 'true' - displayName: Adjust paths - script: echo "##vso[task.prependpath]C:\Windows\System32" displayName: Tweak PATH to reach cmd diff --git a/azure-pipelines-templates/download-install-llvm.yml b/azure-pipelines-templates/download-install-llvm.yml new file mode 100644 index 0000000000..74bf78a870 --- /dev/null +++ b/azure-pipelines-templates/download-install-llvm.yml @@ -0,0 +1,26 @@ +# Copyright (c) .NET Foundation and Contributors +# See LICENSE file in the project root for full license information. + +steps: + - task: PowerShell@2 + displayName: Downloading LLVM 10.0 + condition: eq(variables['Build.Reason'], 'PullRequest') + inputs: + targetType: 'inline' + script: | + $url = "https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.0/LLVM-10.0.0-win64.exe" + $output = "$(Agent.TempDirectory)\LLVM-10.0.0-win64.exe" + (New-Object Net.WebClient).DownloadFile($url, $output) + errorActionPreference: 'stop' + failOnStderr: 'true' + + - task: ExtractFiles@1 + displayName: Install LLVM 10 + condition: eq(variables['Build.Reason'], 'PullRequest') + inputs: + archiveFilePatterns: '$(Agent.TempDirectory)\LLVM-10.0.0-win64.exe' + destinationFolder: '$(Agent.TempDirectory)\llvm' + + - script: echo "##vso[task.prependpath]$(Agent.TempDirectory)\llvm\bin" + displayName: Add LLVM to PATH + condition: eq(variables['Build.Reason'], 'PullRequest') diff --git a/azure-pipelines-templates/download-install-ninja.yml b/azure-pipelines-templates/download-install-ninja.yml index 29f7e9cfa7..3c5314cee4 100644 --- a/azure-pipelines-templates/download-install-ninja.yml +++ b/azure-pipelines-templates/download-install-ninja.yml @@ -1,27 +1,22 @@ -# Copyright (c) 2018 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. steps: - task: Cache@2 inputs: - key: ninjaKey + key: '1-10-0 | ninjaKey' restoreKeys: ninjaKey path: $(Agent.TempDirectory)/ninja cacheHitVar: NINJA_CACHE_RESTORED displayName: Cache Ninja - task: PowerShell@2 - inputs: - targetType: 'inline' - script: | - Write-Host "Downloading Ninja..." - $url = "https://github.com/ninja-build/ninja/releases/download/v1.8.2/ninja-win.zip" - $output = "$PSScriptRoot\ninja.zip" - (New-Object Net.WebClient).DownloadFile($url, $output) - errorActionPreference: 'stop' - failOnStderr: 'true' condition: ne(variables.NINJA_CACHE_RESTORED, 'true') displayName: Download Ninja + inputs: + targetType: 'filePath' + filePath: 'install-scripts\install-ninja.ps1' + failOnStderr: 'true' - task: ExtractFiles@1 inputs: diff --git a/azure-pipelines-templates/download-srecord.yml b/azure-pipelines-templates/download-srecord.yml index 2eb4b06817..7dc45815f0 100644 --- a/azure-pipelines-templates/download-srecord.yml +++ b/azure-pipelines-templates/download-srecord.yml @@ -1,42 +1,27 @@ -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. steps: - task: Cache@2 + condition: eq(variables['NeedsSRECORD'], true) + displayName: Cache SRECORD inputs: - key: srecordKey + key: '1-0 | srecordKey' restoreKeys: srecordKey path: $(Agent.TempDirectory)/srecord cacheHitVar: SRECORD_CACHE_RESTORED - displayName: Cache SRECORD - task: PowerShell@2 - inputs: - targetType: 'inline' - script: | - Write-Host "Downloading SRecord..." - $url = "https://bintray.com/nfbot/internal-build-tools/download_file?file_path=srecord-1.64-win32.zip" - $output = "$env:Agent_TempDirectory\srecord.zip" - (New-Object Net.WebClient).DownloadFile($url, $output) - errorActionPreference: 'stop' - failOnStderr: 'true' - condition: and( eq(variables['NeedsSRECORD'], true), ne(variables.SRECORD_CACHE_RESTORED, 'true')) + condition: eq(variables['NeedsSRECORD'], true) displayName: Install SRECORD + inputs: + targetType: 'filePath' + filePath: 'install-scripts\install-srecord.ps1' + failOnStderr: true - task: ExtractFiles@1 + condition: and( eq(variables['NeedsSRECORD'], true), ne(variables.SRECORD_CACHE_RESTORED, 'true')) + displayName: Extract SRECORD inputs: archiveFilePatterns: '$(Agent.TempDirectory)\srecord.zip' destinationFolder: '$(Agent.TempDirectory)\srecord' - condition: ne(variables.SRECORD_CACHE_RESTORED, 'true') - displayName: Extract SRECORD - - - task: PowerShell@2 - inputs: - targetType: 'inline' - script: | - $newPath = "$env:Agent_TempDirectory".Replace('\','/') - Write-Host "$("##vso[task.setvariable variable=SRECORD_PATH]")$newPath" - errorActionPreference: 'stop' - failOnStderr: 'true' - condition: eq(variables['NeedsSRECORD'], true) - displayName: Adjust SRECORD path \ No newline at end of file diff --git a/azure-pipelines-templates/nb-gitversioning.yml b/azure-pipelines-templates/nb-gitversioning.yml index 11160b811f..d94c5833b2 100644 --- a/azure-pipelines-templates/nb-gitversioning.yml +++ b/azure-pipelines-templates/nb-gitversioning.yml @@ -1,4 +1,4 @@ -# Copyright (c) 2018 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. steps: @@ -20,7 +20,6 @@ steps: inputs: targetType: 'inline' script: | - Write-Host "$("##vso[task.setvariable variable=NBGV_Version]")0.0.0" - Write-Host "$("##vso[task.setvariable variable=NBGV_VersionHeight]")$env:System_PullRequest_PullRequestNumber" + Write-Host "$("##vso[task.setvariable variable=NBGV_Version]")0.0.0.$env:System_PullRequest_PullRequestNumber" condition: eq(variables['system.pullrequest.isfork'], true) displayName: Set temporary build number diff --git a/azure-pipelines-templates/pack-publish-artifacts.yml b/azure-pipelines-templates/pack-publish-artifacts.yml index 4f251b8552..9c4aae91d0 100644 --- a/azure-pipelines-templates/pack-publish-artifacts.yml +++ b/azure-pipelines-templates/pack-publish-artifacts.yml @@ -1,4 +1,4 @@ -# Copyright (c) 2018 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. parameters: diff --git a/azure-pipelines-templates/pack-publish-managed-helpers.yml b/azure-pipelines-templates/pack-publish-managed-helpers.yml index 77cbe9e7ba..cf2a210265 100644 --- a/azure-pipelines-templates/pack-publish-managed-helpers.yml +++ b/azure-pipelines-templates/pack-publish-managed-helpers.yml @@ -1,4 +1,4 @@ -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. steps: @@ -58,5 +58,5 @@ steps: nuGetFeedType: external packagesToPush: '$(Build.ArtifactStagingDirectory)/*.nupkg' publishFeedCredentials: 'NuGet' - condition: and( succeeded(), eq(variables['BUILD_NUGET_PACKAGE'], true), not( startsWith(variables['Build.SourceBranch'], 'refs/pull') ) ) + condition: and( succeeded(), eq(variables['BUILD_NUGET_PACKAGE'], true), ne(variables['Build.Reason'], 'PullRequest') ) displayName: Push managed helpers NuGet packages to NuGet diff --git a/azure-pipelines-templates/pack-publish-ti-sl-managed-helpers.yml b/azure-pipelines-templates/pack-publish-ti-sl-managed-helpers.yml index acbf53a4a5..5bc602d2fa 100644 --- a/azure-pipelines-templates/pack-publish-ti-sl-managed-helpers.yml +++ b/azure-pipelines-templates/pack-publish-ti-sl-managed-helpers.yml @@ -1,4 +1,4 @@ -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. steps: @@ -58,5 +58,5 @@ steps: nuGetFeedType: external packagesToPush: '$(Build.ArtifactStagingDirectory)/*.nupkg' publishFeedCredentials: 'NuGet' - condition: and( succeeded(), eq(variables['BUILD_NUGET_PACKAGE'], true), not( startsWith(variables['Build.SourceBranch'], 'refs/pull') ) ) + condition: and( succeeded(), eq(variables['BUILD_NUGET_PACKAGE'], true), ne(variables['Build.Reason'], 'PullRequest') ) displayName: Push managed helpers NuGet packages to NuGet diff --git a/azure-pipelines-templates/publish-bintray.yml b/azure-pipelines-templates/publish-bintray.yml index 62e6f86a94..7826587c66 100644 --- a/azure-pipelines-templates/publish-bintray.yml +++ b/azure-pipelines-templates/publish-bintray.yml @@ -1,4 +1,4 @@ -# Copyright (c) 2018 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # To publish builds of targets in branches other than develop @@ -14,17 +14,17 @@ steps: replaceExistingArchive: true # skip task on PR build and when on branch other than master or nf community targets # execute on 'ForceUpload' parameter - condition: or( eq(variables['ForceUpload'], true), and( succeeded(), ne(variables['Build.Reason'], 'PullRequest'), or( eq(variables['Build.SourceBranchName'], 'master'), eq(variables['Build.Repository_Name'], 'nf-Community-Targets')) ) ) + condition: or( eq(variables['ForceUpload'], true), and( succeeded(), ne(variables['Build.Reason'], 'PullRequest'), or( eq(variables['Build.SourceBranchName'], 'master'), eq(variables['Build.Repository.Name'], 'nanoframework/nf-Community-Targets')) ) ) displayName: Zip binary files (release) - task: CopyFiles@1 inputs: sourceFolder: $(Agent.TempDirectory) Contents: | - '$(BoardName)-$(NBGV_AssemblyVersion).zip' + *.zip TargetFolder: '$(Build.ArtifactStagingDirectory)\$(BoardName)' flattenFolders: true - condition: or( eq(variables['ForceUpload'], true), and( succeeded(), ne(variables['Build.Reason'], 'PullRequest'), or( eq(variables['Build.SourceBranchName'], 'master'), eq(variables['Build.Repository_Name'], 'nf-Community-Targets')) ) ) + condition: or( eq(variables['ForceUpload'], true), and( succeeded(), ne(variables['Build.Reason'], 'PullRequest'), or( eq(variables['Build.SourceBranchName'], 'master'), eq(variables['Build.Repository.Name'], 'nanoframework/nf-Community-Targets')) ) ) displayName: Collecting deployable artifacts (release) - task: ArchiveFiles@2 @@ -32,7 +32,7 @@ steps: rootFolderOrFile: '$(Build.ArtifactStagingDirectory)\$(BoardName)' includeRootFolder: false archiveType: 'zip' - archiveFile: '$(Agent.TempDirectory)\$(BoardName)-$(NBGV_AssemblyVersion)-preview.zip' + archiveFile: '$(Agent.TempDirectory)\$(BoardName)-$(NBGV_SimpleVersion)-preview.$(NBGV_VersionHeight).zip' replaceExistingArchive: true # skip task on PR build and when on branch other than develop, master or release # execute on 'ForceUpload' parameter @@ -43,6 +43,7 @@ steps: inputs: sourceFolder: $(Agent.TempDirectory) Contents: | + *.zip '$(BoardName)-$(NBGV_AssemblyVersion)-preview.zip' TargetFolder: '$(Build.ArtifactStagingDirectory)\$(BoardName)' flattenFolders: true @@ -74,6 +75,8 @@ steps: Write-Host "$("##vso[task.setvariable variable=BINTRAY_REPO]")nanoframework-images-community-targets" # set package name Write-Host "$("##vso[task.setvariable variable=PACKAGE_NAME]")$(BoardName)-$(NBGV_AssemblyVersion)" + # set version + Write-Host "$("##vso[task.setvariable variable=PACKAGE_VERSION]")$(NBGV_AssemblyVersion)" } else { @@ -83,7 +86,9 @@ steps: # this a dev or release branch, publish to Bintray dev repo Write-Host "$("##vso[task.setvariable variable=BINTRAY_REPO]")nanoframework-images-dev" # set package name - Write-Host "$("##vso[task.setvariable variable=PACKAGE_NAME]")$(BoardName)-$(NBGV_AssemblyVersion)-preview" + Write-Host "$("##vso[task.setvariable variable=PACKAGE_NAME]")$(BoardName)-$(NBGV_SimpleVersion)-preview.$(NBGV_VersionHeight)" + # set version + Write-Host "$("##vso[task.setvariable variable=PACKAGE_VERSION]")$(NBGV_SimpleVersion)-preview.$(NBGV_VersionHeight)" } else { @@ -91,6 +96,8 @@ steps: Write-Host "$("##vso[task.setvariable variable=BINTRAY_REPO]")nanoframework-images" # set package name Write-Host "$("##vso[task.setvariable variable=PACKAGE_NAME]")$(BoardName)-$(NBGV_AssemblyVersion)" + # set version + Write-Host "$("##vso[task.setvariable variable=PACKAGE_VERSION]")$(NBGV_AssemblyVersion)" } } errorActionPreference: 'stop' @@ -106,7 +113,7 @@ steps: username: 'nfbot' password: '$(BinTrayKey)' url: 'https://api.bintray.com/' - remotePath: 'content/nfbot/$(BINTRAY_REPO)/$(BoardName)/$(NBGV_AssemblyVersion)/$(PACKAGE_NAME).zip;publish=1' + remotePath: 'content/nfbot/$(BINTRAY_REPO)/$(BoardName)/$(PACKAGE_VERSION)/$(PACKAGE_NAME).zip;publish=1' # execute on 'ForceUpload' parameter condition: or( eq(variables['ForceUpload'], true), and( succeeded(), ne(variables['Build.Reason'], 'PullRequest'), or( eq(variables['Build.SourceBranchName'], 'develop'), eq(variables['Build.SourceBranchName'], 'master'), contains(variables['Build.SourceBranchName'], 'release') ) ) ) displayName: Upload artifact to Bintray diff --git a/azure-pipelines.yml b/azure-pipelines.yml index d0a5369a1d..70ab7eaaa7 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -4,8 +4,9 @@ trigger: paths: exclude: [ "doc", "*.md", ".gitignore", "README.md" ] -# no pr config, we want to trigger builds for all PRs on all branches - +pr: + autoCancel: true + # add nf-tools repo to resources (for Azure Pipelines templates) resources: repositories: @@ -38,11 +39,11 @@ jobs: else { # get commit details, if this is a PR - if($env:Build_SourceBranch -like "refs/pull*") + if($env:Build_Reason -eq 'PullRequest') { $commit = Invoke-RestMethod -Uri "https://api.github.com/repos/nanoframework/nf-interpreter/commits/$(Build.SourceVersion)" -ContentType "application/json" -Method GET - if( ($commit.commit.author.name -eq "nfbot") -and (($commit.commit.message -like "*[version update]*") -or ($commit.commit.message -like "***NO_CI***")) ) + if( ($commit.commit.author.name -eq "nfbot") -and ($commit.commit.message -like "*[version update]*") ) { echo "##vso[task.setvariable variable=SKIP_BUILD;isOutput=true]true" } @@ -53,14 +54,7 @@ jobs: } else { - if($commit.commit.message -like "***NO_CI***") - { - echo "##vso[task.setvariable variable=SKIP_BUILD;isOutput=true]true" - } - else - { - echo "##vso[task.setvariable variable=SKIP_BUILD;isOutput=true]false" - } + echo "##vso[task.setvariable variable=SKIP_BUILD;isOutput=true]false" } } @@ -132,13 +126,31 @@ jobs: condition: eq( variables['StartReleaseCandidate'], true ) displayName: NBGV prepare release +############################## +- job: Check_Code_Style + condition: ne( dependencies.Check_Build_Options.outputs['BuildOptions.SKIP_BUILD'], true ) + + dependsOn: + - Check_Build_Options + + pool: + vmImage: 'windows-latest' + + steps: + - checkout: self + fetchDepth: 1 + + - template: azure-pipelines-templates/download-install-llvm.yml + - template: azure-pipelines-templates/check-code-style.yml + ################# # STM32 - job: Build_STM32_targets - condition: not( eq( dependencies.Check_Build_Options.outputs['BuildOptions.SKIP_BUILD'], true ) ) + condition: and( succeeded('Check_Code_Style'), ne( dependencies.Check_Build_Options.outputs['BuildOptions.SKIP_BUILD'], true ) ) dependsOn: - Check_Build_Options + - Check_Code_Style pool: vmImage: 'VS2017-Win2016' @@ -152,12 +164,12 @@ jobs: NeedsDFU: true NETDUINO3_WIFI: BoardName: NETDUINO3_WIFI - BuildOptions: -DTARGET_SERIES=STM32F4xx -DRTOS=CHIBIOS -DSUPPORT_ANY_BASE_CONVERSION=ON -DNF_FEATURE_DEBUGGER=ON -DNF_FEATURE_RTC=ON -DNF_FEATURE_HAS_SDCARD=ON -DAPI_System.Math=ON -DAPI_Hardware.Stm32=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_Windows.Devices.Spi=ON -DAPI_Windows.Devices.I2c=ON -DAPI_Windows.Devices.Pwm=ON -DAPI_Windows.Devices.SerialCommunication=ON -DAPI_Windows.Devices.Adc=ON -DAPI_System.Devices.Dac=OFF -DAPI_nanoFramework.Devices.OneWire=ON -DAPI_Windows.Storage=ON -DAPI_nanoFramework.ResourceManager=ON -DAPI_nanoFramework.System.Collections=ON -DAPI_nanoFramework.System.Text=ON + BuildOptions: -DTARGET_SERIES=STM32F4xx -DRTOS=CHIBIOS -DSUPPORT_ANY_BASE_CONVERSION=ON -DNF_FEATURE_DEBUGGER=ON -DNF_FEATURE_RTC=ON -DNF_FEATURE_HAS_SDCARD=ON -DAPI_System.Math=ON -DAPI_Hardware.Stm32=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_Windows.Devices.Spi=ON -DAPI_Windows.Devices.I2c=ON -DAPI_Windows.Devices.Pwm=ON -DAPI_Windows.Devices.SerialCommunication=ON -DAPI_Windows.Devices.Adc=ON -DAPI_System.Device.Dac=OFF -DAPI_nanoFramework.Devices.OneWire=ON -DAPI_Windows.Storage=ON -DAPI_nanoFramework.ResourceManager=ON -DAPI_nanoFramework.System.Collections=ON -DAPI_nanoFramework.System.Text=ON GccArm_Version: NeedsDFU: true ORGPAL_PALTHREE: BoardName: ORGPAL_PALTHREE - BuildOptions: -DTARGET_SERIES=STM32F7xx -DRTOS=CHIBIOS -DCHIBIOS_CONTRIB_REQUIRED=ON -DSTM32_CUBE_PACKAGE_REQUIRED=ON -DSUPPORT_ANY_BASE_CONVERSION=ON -DNF_FEATURE_DEBUGGER=ON -DSWO_OUTPUT=ON -DNF_FEATURE_RTC=ON -DNF_FEATURE_HAS_USB_MSD=ON -DNF_FEATURE_HAS_SDCARD=ON -DNF_FEATURE_USE_SPIFFS=ON -DAPI_System.Math=ON -DAPI_Hardware.Stm32=ON -DNF_FEATURE_HAS_CONFIG_BLOCK=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_Windows.Devices.Spi=ON -DAPI_Windows.Devices.I2c=ON -DAPI_Windows.Devices.Pwm=ON -DAPI_Windows.Devices.SerialCommunication=ON -DAPI_Windows.Devices.Adc=ON -DAPI_System.Devices.Dac=ON -DAPI_System.Net=ON -DNF_SECURITY_MBEDTLS=ON -DAPI_Windows.Storage=ON -DAPI_nanoFramework.ResourceManager=ON -DAPI_nanoFramework.System.Collections=ON -DAPI_nanoFramework.System.Text=ON + BuildOptions: -DTARGET_SERIES=STM32F7xx -DRTOS=CHIBIOS -DCHIBIOS_CONTRIB_REQUIRED=ON -DSTM32_CUBE_PACKAGE_REQUIRED=ON -DSUPPORT_ANY_BASE_CONVERSION=ON -DNF_FEATURE_DEBUGGER=ON -DNF_FEATURE_RTC=ON -DNF_FEATURE_HAS_USB_MSD=ON -DNF_FEATURE_HAS_SDCARD=ON -DNF_FEATURE_USE_SPIFFS=ON -DAPI_System.Math=ON -DAPI_Hardware.Stm32=ON -DNF_FEATURE_HAS_CONFIG_BLOCK=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_Windows.Devices.Spi=ON -DAPI_Windows.Devices.I2c=ON -DAPI_Windows.Devices.Pwm=ON -DAPI_Windows.Devices.SerialCommunication=ON -DAPI_Windows.Devices.Adc=ON -DAPI_System.Device.Dac=ON -DAPI_System.Net=ON -DNF_SECURITY_MBEDTLS=ON -DAPI_Windows.Storage=ON -DAPI_nanoFramework.ResourceManager=ON -DAPI_nanoFramework.System.Collections=ON -DAPI_nanoFramework.System.Text=ON GccArm_Version: NeedsDFU: true ST_STM32F429I_DISCOVERY: @@ -167,12 +179,12 @@ jobs: NeedsDFU: false ST_NUCLEO64_F091RC: BoardName: ST_NUCLEO64_F091RC - BuildOptions: -DTARGET_SERIES=STM32F0xx -DRTOS=CHIBIOS -DNF_FEATURE_DEBUGGER=ON -DNF_FEATURE_RTC=ON -DUSE_RNG=OFF -DNF_PLATFORM_NO_CLR_TRACE=ON -DNF_CLR_NO_IL_INLINE=ON -DAPI_Hardware.Stm32=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_Windows.Devices.Spi=ON -DAPI_Windows.Devices.I2c=ON -DAPI_Windows.Devices.Pwm=ON -DAPI_Windows.Devices.SerialCommunication=ON - GccArm_Version: 5-2016-q3-update + BuildOptions: -DTARGET_SERIES=STM32F0xx -DRTOS=CHIBIOS -DNF_FEATURE_DEBUGGER=ON -DNF_FEATURE_RTC=ON -DUSE_RNG=OFF -DNF_PLATFORM_NO_CLR_TRACE=ON -DNF_CLR_NO_IL_INLINE=ON -DAPI_Hardware.Stm32=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_Windows.Devices.Spi=ON -DAPI_Windows.Devices.I2c=ON -DAPI_Windows.Devices.Pwm=ON -DAPI_Windows.Devices.SerialCommunication=ON -DAPI_nanoFramework.System.Text=ON + GccArm_Version: NeedsDFU: false ST_STM32F769I_DISCOVERY: BoardName: ST_STM32F769I_DISCOVERY - BuildOptions: -DTARGET_SERIES=STM32F7xx -DRTOS=CHIBIOS -DSUPPORT_ANY_BASE_CONVERSION=ON -DNF_FEATURE_DEBUGGER=ON -DNF_FEATURE_RTC=ON -DNF_FEATURE_HAS_SDCARD=ON -DAPI_System.Math=ON -DAPI_Hardware.Stm32=ON -DNF_FEATURE_HAS_CONFIG_BLOCK=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_Windows.Devices.Spi=ON -DAPI_Windows.Devices.I2c=ON -DAPI_Windows.Devices.Pwm=ON -DAPI_Windows.Devices.SerialCommunication=ON -DAPI_Windows.Devices.Adc=ON -DAPI_System.Devices.Dac=ON -DAPI_System.Net=ON -DNF_SECURITY_MBEDTLS=ON -DAPI_nanoFramework.Devices.OneWire=ON -DAPI_nanoFramework.Devices.Can=ON -DAPI_Windows.Storage=ON -DAPI_nanoFramework.ResourceManager=ON -DAPI_nanoFramework.System.Collections=ON -DAPI_nanoFramework.System.Text=ON + BuildOptions: -DTARGET_SERIES=STM32F7xx -DRTOS=CHIBIOS -DSUPPORT_ANY_BASE_CONVERSION=ON -DNF_FEATURE_DEBUGGER=ON -DNF_FEATURE_RTC=ON -DNF_FEATURE_HAS_SDCARD=ON -DAPI_System.Math=ON -DAPI_Hardware.Stm32=ON -DNF_FEATURE_HAS_CONFIG_BLOCK=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_Windows.Devices.Spi=ON -DAPI_Windows.Devices.I2c=ON -DAPI_Windows.Devices.Pwm=ON -DAPI_Windows.Devices.SerialCommunication=ON -DAPI_Windows.Devices.Adc=ON -DAPI_System.Device.Dac=ON -DAPI_System.Net=ON -DNF_SECURITY_MBEDTLS=ON -DAPI_nanoFramework.Devices.OneWire=ON -DAPI_nanoFramework.Devices.Can=ON -DAPI_Windows.Storage=ON -DAPI_nanoFramework.ResourceManager=ON -DAPI_nanoFramework.System.Collections=ON -DAPI_nanoFramework.System.Text=ON GccArm_Version: NeedsDFU: false @@ -200,10 +212,11 @@ jobs: ################# # ESP32 targets - job: Build_ESP32_targets - condition: not( eq( dependencies.Check_Build_Options.outputs['BuildOptions.SKIP_BUILD'], true ) ) + condition: and( succeeded('Check_Code_Style'), ne( dependencies.Check_Build_Options.outputs['BuildOptions.SKIP_BUILD'], true ) ) dependsOn: - Check_Build_Options + - Check_Code_Style pool: vmImage: 'VS2017-Win2016' @@ -213,10 +226,10 @@ jobs: matrix: ESP32_WROOM_32: BoardName: ESP32_WROOM_32 - BuildOptions: -DTARGET_SERIES=ESP32 -DRTOS=FREERTOS_ESP32 -DNF_FEATURE_DEBUGGER=ON -DNF_FEATURE_RTC=ON -DNF_FEATURE_HAS_CONFIG_BLOCK=ON -DNF_FEATURE_HAS_SDCARD=ON -DAPI_System.Math=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_Windows.Devices.Spi=ON -DAPI_Windows.Devices.I2c=ON -DAPI_Windows.Devices.Pwm=ON -DAPI_Windows.Devices.SerialCommunication=ON -DAPI_Windows.Devices.Adc=ON -DAPI_System.Net=ON -DAPI_Windows.Devices.Wifi=ON -DAPI_Windows.Storage=ON -DNF_SECURITY_MBEDTLS=ON -DAPI_Hardware.Esp32=ON -DSUPPORT_ANY_BASE_CONVERSION=ON -DAPI_nanoFramework.Devices.OneWire=ON -DAPI_nanoFramework.ResourceManager=ON -DAPI_nanoFramework.System.Collections=ON -DAPI_nanoFramework.System.Text=ON + BuildOptions: -DTARGET_SERIES=ESP32 -DRTOS=FREERTOS_ESP32 -DNF_FEATURE_DEBUGGER=ON -DNF_FEATURE_RTC=ON -DNF_FEATURE_HAS_CONFIG_BLOCK=ON -DNF_FEATURE_HAS_SDCARD=ON -DAPI_System.Math=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_Windows.Devices.Spi=ON -DAPI_Windows.Devices.I2c=ON -DAPI_Windows.Devices.Pwm=ON -DAPI_Windows.Devices.SerialCommunication=ON -DAPI_Windows.Devices.Adc=ON -DAPI_System.Net=ON -DAPI_Windows.Devices.Wifi=ON -DAPI_Windows.Storage=ON -DNF_SECURITY_MBEDTLS=ON -DAPI_Hardware.Esp32=ON -DSUPPORT_ANY_BASE_CONVERSION=ON -DAPI_nanoFramework.Devices.OneWire=ON -DAPI_nanoFramework.ResourceManager=ON -DAPI_nanoFramework.System.Collections=ON -DAPI_nanoFramework.System.Text=ON -DAPI_nanoFramework.Hardware.Esp32.Rmt=ON variables: - ESP32_TOOLCHAIN_PATH: $(Agent.TempDirectory)\ESP32_Tools + ESP32_TOOLCHAIN_PATH: $(Agent.TempDirectory)\ESP32_Tools\xtensa-esp32-elf steps: - template: azure-pipelines-templates/nb-gitversioning.yml @@ -244,10 +257,11 @@ jobs: ################# # NXP - job: Build_NXP_targets - condition: not( eq( dependencies.Check_Build_Options.outputs['BuildOptions.SKIP_BUILD'], true ) ) + condition: and( succeeded('Check_Code_Style'), ne( dependencies.Check_Build_Options.outputs['BuildOptions.SKIP_BUILD'], true ) ) dependsOn: - Check_Build_Options + - Check_Code_Style pool: vmImage: 'VS2017-Win2016' @@ -284,23 +298,25 @@ jobs: ################# # TI SimpleLink - job: Build_TI_SimpleLink_targets - condition: not( eq( dependencies.Check_Build_Options.outputs['BuildOptions.SKIP_BUILD'], true ) ) + condition: and( succeeded('Check_Code_Style'), ne( dependencies.Check_Build_Options.outputs['BuildOptions.SKIP_BUILD'], true ) ) dependsOn: - Check_Build_Options + - Check_Code_Style pool: vmImage: 'VS2017-Win2016' strategy: matrix: - TI_CC3220SF_LAUNCHXL: - BoardName: TI_CC3220SF_LAUNCHXL - BuildOptions: -DTARGET_SERIES=CC32xx -DRTOS=TI_SIMPLELINK -DSUPPORT_ANY_BASE_CONVERSION=OFF -DNF_FEATURE_DEBUGGER=ON -DNF_FEATURE_RTC=ON -DNF_FEATURE_WATCHDOG=OFF -DNF_FEATURE_HAS_CONFIG_BLOCK=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_Windows.Devices.Spi=ON -DAPI_Windows.Devices.I2c=ON -DAPI_Windows.Devices.Pwm=ON -DAPI_Windows.Devices.SerialCommunication=OFF -DAPI_Windows.Devices.Adc=ON -DAPI_System.Net=ON -DAPI_nanoFramework.System.Collections=ON -DAPI_nanoFramework.System.Text=ON - GccArm_Version: + # disabled: waiting to update SDK to latest version with Sys Config + # TI_CC3220SF_LAUNCHXL: + # BoardName: TI_CC3220SF_LAUNCHXL + # BuildOptions: -DTARGET_SERIES=CC32xx -DRTOS=TI_SIMPLELINK -DSUPPORT_ANY_BASE_CONVERSION=OFF -DNF_FEATURE_DEBUGGER=ON -DNF_FEATURE_RTC=ON -DNF_FEATURE_WATCHDOG=OFF -DNF_FEATURE_HAS_CONFIG_BLOCK=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_Windows.Devices.Spi=ON -DAPI_Windows.Devices.I2c=ON -DAPI_Windows.Devices.Pwm=ON -DAPI_Windows.Devices.SerialCommunication=OFF -DAPI_Windows.Devices.Adc=ON -DAPI_System.Net=ON -DAPI_nanoFramework.System.Collections=ON -DAPI_nanoFramework.System.Text=ON + # GccArm_Version: TI_CC1352R1_LAUNCHXL: BoardName: TI_CC1352R1_LAUNCHXL - BuildOptions: -DTARGET_SERIES=CC13x2_26x2 -DRTOS=TI_SIMPLELINK -DSUPPORT_ANY_BASE_CONVERSION=OFF -DNF_FEATURE_DEBUGGER=ON -DNF_FEATURE_RTC=ON -DNF_FEATURE_WATCHDOG=OFF -DAPI_Windows.Devices.Gpio=ON -DAPI_Windows.Devices.Spi=OFF -DAPI_Windows.Devices.I2c=OFF -DAPI_Windows.Devices.Pwm=OFF -DAPI_Windows.Devices.SerialCommunication=OFF -DAPI_Windows.Devices.Adc=OFF -DAPI_nanoFramework.TI.EasyLink=ON + BuildOptions: -DTARGET_SERIES=CC13x2_26x2 -DRTOS=TI_SIMPLELINK -DSUPPORT_ANY_BASE_CONVERSION=OFF -DNF_FEATURE_DEBUGGER=ON -DNF_FEATURE_RTC=ON -DNF_FEATURE_WATCHDOG=OFF -DAPI_Windows.Devices.Gpio=ON -DAPI_Windows.Devices.Spi=OFF -DAPI_Windows.Devices.I2c=OFF -DAPI_Windows.Devices.Pwm=OFF -DAPI_Windows.Devices.SerialCommunication=OFF -DAPI_Windows.Devices.Adc=ON -DAPI_nanoFramework.TI.EasyLink=ON -DAPI_nanoFramework.Hardware.TI=ON GccArm_Version: variables: @@ -325,10 +341,11 @@ jobs: ################# # WIN32 - job: Build_WIN32_nanoCLR - condition: not( eq( dependencies.Check_Build_Options.outputs['BuildOptions.SKIP_BUILD'], true ) ) + condition: and( succeeded('Check_Code_Style'), ne( dependencies.Check_Build_Options.outputs['BuildOptions.SKIP_BUILD'], true ) ) dependsOn: - Check_Build_Options + - Check_Code_Style pool: vmImage: 'VS2017-Win2016' @@ -380,7 +397,7 @@ jobs: gem install github_changelog_generator --quiet --no-document # need to call it passing both cache options with full path otherwise it won't work github_changelog_generator --token $(GitHubToken) --cache-log $env:AGENT_TEMPDIRECTORY\github-changelog-logger.log --cache-file $env:AGENT_TEMPDIRECTORY\github-changelog-http-cache --pr-wo-labels --future-release "v$env:NBGV_AssemblyVersion" - condition: and( succeeded(), not( startsWith(variables['Build.SourceBranch'], 'refs/pull') ), or( eq(variables['Build.SourceBranchName'], 'master'), startsWith(variables['Build.SourceBranch'], 'refs/tags/v') ) ) + condition: and( succeeded(), ne(variables['Build.Reason'], 'PullRequest'), or( eq(variables['Build.SourceBranchName'], 'master'), startsWith(variables['Build.SourceBranch'], 'refs/tags/v') ) ) displayName: Generate change log # generate change log without future version @@ -388,7 +405,7 @@ jobs: gem install github_changelog_generator --quiet --no-document # need to call it passing both cache options with full path otherwise it won't work github_changelog_generator --token $(GitHubToken) --cache-log $env:AGENT_TEMPDIRECTORY\github-changelog-logger.log --cache-file $env:AGENT_TEMPDIRECTORY\github-changelog-http-cache --pr-wo-labels - condition: and( succeeded(), not( startsWith(variables['Build.SourceBranch'], 'refs/pull') ), not( or( eq(variables['Build.SourceBranchName'], 'master'), startsWith(variables['Build.SourceBranch'], 'refs/tags/v') ) ) ) + condition: and( succeeded(), ne(variables['Build.Reason'], 'PullRequest'), not( or( eq(variables['Build.SourceBranchName'], 'master'), startsWith(variables['Build.SourceBranch'], 'refs/tags/v') ) ) ) displayName: Generate change log # push new changelog to GitHub repo @@ -406,7 +423,7 @@ jobs: $auth = "basic $([System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("nfbot:$(GitHubToken)"))))" git -c http.extraheader="AUTHORIZATION: $auth" push origin "HEAD:$(Build.SourceBranchName)" - condition: and( succeeded(), not( startsWith(variables['Build.SourceBranch'], 'refs/pull') ) ) + condition: and( succeeded(), ne(variables['Build.Reason'], 'PullRequest') ) displayName: Push changelog to GitHub ####################### @@ -465,7 +482,8 @@ jobs: - Build_TI_SimpleLink_targets - Build_WIN32_nanoCLR - Generate_change_log - condition: or( failed('Build_STM32_targets'), failed('Build_ESP32_targets'), failed('Build_NXP_targets'), failed('Build_TI_SimpleLink_targets'), failed('Build_WIN32_nanoCLR'), failed('Generate_change_log')) + - Check_Code_Style + condition: and(ne( dependencies.Check_Code_Style.outputs['Check_Code_Style.CODE_STYLE_CHECK_FAILED'], true), or( failed('Build_STM32_targets'), failed('Build_ESP32_targets'), failed('Build_NXP_targets'), failed('Build_TI_SimpleLink_targets'), failed('Build_WIN32_nanoCLR'), failed('Generate_change_log'))) pool: vmImage: 'VS2017-Win2016' diff --git a/build.ps1 b/build.ps1 new file mode 100644 index 0000000000..cd9d7e8783 --- /dev/null +++ b/build.ps1 @@ -0,0 +1,199 @@ +# Copyright (c) .NET Foundation and Contributors +# See LICENSE file in the project root for full license information. + +[CmdletBinding(SupportsShouldProcess = $true)] +param ( + [Parameter(HelpMessage = "Please enter the target name [e.g. ESP32_WROOM_32 or ST_STM32F429I_DISCOVERY or NETDUINO3_WIFI].")][string]$Target, + [Parameter(HelpMessage = "Enter the path to the folder where the tools should be installed.")][string]$Path = "C:\nftools" +) + +# create build folder +mkdir -Force "$PSScriptRoot\build" | Out-Null + +# move to build folder +Set-Location "build" | Out-Null + +"Running CMake build preparation..." | Write-Host -ForegroundColor White + +If ($Target -eq "MBN_QUAIL" -or + $Target -eq "NETDUINO3_WIFI" -or + $Target -eq "ORGPAL_PALTHREE" -or + $Target -eq "ST_NUCLEO64_F091RC" -or + $Target -eq "ST_STM32F429I_DISCOVERY" -or + $Target -eq "ST_STM32F769I_DISCOVERY") { + + # run the install tools to have the build vars filled + Invoke-Expression "$PSScriptRoot\install-scripts\install-stm32-tools.ps1 -Path $Path" + + If ( $Target -eq "MBN_QUAIL" ) { + + $cmakeOptions = " -DTOOL_HEX2DFU_PREFIX=$:env:HEX2DFU_PATH -DTARGET_SERIES=STM32F4xx -DRTOS=CHIBIOS -DSUPPORT_ANY_BASE_CONVERSION=ON -DNF_FEATURE_DEBUGGER=ON -DNF_FEATURE_RTC=ON -DAPI_System.Math=ON -DAPI_Hardware.Stm32=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_Windows.Devices.Spi=ON -DAPI_Windows.Devices.I2c=ON -DAPI_Windows.Devices.Pwm=ON -DAPI_Windows.Devices.SerialCommunication=ON -DAPI_nanoFramework.Devices.OneWire=ON -DAPI_nanoFramework.ResourceManager=ON -DAPI_nanoFramework.System.Collections=ON -DAPI_nanoFramework.System.Text=ON" + } + elseif ($Target -eq "NETDUINO3_WIFI") { + + $cmakeOptions = " -DTOOL_HEX2DFU_PREFIX=$:env:HEX2DFU_PATH -DTARGET_SERIES=STM32F4xx -DRTOS=CHIBIOS -DSUPPORT_ANY_BASE_CONVERSION=ON -DNF_FEATURE_DEBUGGER=ON -DNF_FEATURE_RTC=ON -DNF_FEATURE_HAS_SDCARD=ON -DAPI_System.Math=ON -DAPI_Hardware.Stm32=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_Windows.Devices.Spi=ON -DAPI_Windows.Devices.I2c=ON -DAPI_Windows.Devices.Pwm=ON -DAPI_Windows.Devices.SerialCommunication=ON -DAPI_Windows.Devices.Adc=ON -DAPI_System.Device.Dac=OFF -DAPI_nanoFramework.Devices.OneWire=ON -DAPI_Windows.Storage=ON -DAPI_nanoFramework.ResourceManager=ON -DAPI_nanoFramework.System.Collections=ON -DAPI_nanoFramework.System.Text=ON" + } + elseif ($Target -eq "ORGPAL_PALTHREE") { + + $cmakeOptions = " -DTOOL_HEX2DFU_PREFIX=$:env:HEX2DFU_PATH -DTARGET_SERIES=STM32F7xx -DRTOS=CHIBIOS -DCHIBIOS_CONTRIB_REQUIRED=ON -DSTM32_CUBE_PACKAGE_REQUIRED=ON -DSUPPORT_ANY_BASE_CONVERSION=ON -DNF_FEATURE_DEBUGGER=ON -DSWO_OUTPUT=ON -DNF_FEATURE_RTC=ON -DNF_FEATURE_HAS_USB_MSD=ON -DNF_FEATURE_HAS_SDCARD=ON -DNF_FEATURE_USE_SPIFFS=ON -DAPI_System.Math=ON -DAPI_Hardware.Stm32=ON -DNF_FEATURE_HAS_CONFIG_BLOCK=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_Windows.Devices.Spi=ON -DAPI_Windows.Devices.I2c=ON -DAPI_Windows.Devices.Pwm=ON -DAPI_Windows.Devices.SerialCommunication=ON -DAPI_Windows.Devices.Adc=ON -DAPI_System.Device.Dac=ON -DAPI_System.Net=ON -DNF_SECURITY_MBEDTLS=ON -DAPI_Windows.Storage=ON -DAPI_nanoFramework.ResourceManager=ON -DAPI_nanoFramework.System.Collections=ON -DAPI_nanoFramework.System.Text=ON" + } + elseif ($Target -eq "ST_NUCLEO64_F091RC") { + Write-Error "Build not supported because this target requires a different GCC toolchain version" + + Exit 1 + } + elseif ($Target -eq "ST_STM32F429I_DISCOVERY") { + + $cmakeOptions = "-DTARGET_SERIES=STM32F4xx -DRTOS=CHIBIOS -DSUPPORT_ANY_BASE_CONVERSION=ON -DNF_FEATURE_DEBUGGER=ON -DSWO_OUTPUT=ON -DNF_FEATURE_RTC=ON -DAPI_System.Math=ON -DAPI_Hardware.Stm32=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_Windows.Devices.Spi=ON -DAPI_Windows.Devices.I2c=ON -DAPI_Windows.Devices.Pwm=ON -DAPI_Windows.Devices.SerialCommunication=ON -DAPI_Windows.Devices.Adc=ON -DAPI_nanoFramework.Devices.OneWire=ON -DAPI_nanoFramework.Devices.Can=ON -DAPI_nanoFramework.ResourceManager=ON -DAPI_nanoFramework.System.Collections=ON -DAPI_nanoFramework.System.Text=ON" + } + elseif ($Target -eq "ST_STM32F769I_DISCOVERY") { + + $cmakeOptions = " -DTARGET_SERIES=STM32F7xx -DRTOS=CHIBIOS -DSUPPORT_ANY_BASE_CONVERSION=ON -DNF_FEATURE_DEBUGGER=ON -DSWO_OUTPUT=ON -DNF_FEATURE_RTC=ON -DNF_FEATURE_HAS_SDCARD=ON -DAPI_System.Math=ON -DAPI_Hardware.Stm32=ON -DNF_FEATURE_HAS_CONFIG_BLOCK=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_Windows.Devices.Spi=ON -DAPI_Windows.Devices.I2c=ON -DAPI_Windows.Devices.Pwm=ON -DAPI_Windows.Devices.SerialCommunication=ON -DAPI_Windows.Devices.Adc=ON -DAPI_System.Device.Dac=ON -DAPI_System.Net=ON -DNF_SECURITY_MBEDTLS=ON -DAPI_nanoFramework.Devices.OneWire=ON -DAPI_nanoFramework.Devices.Can=ON -DAPI_Windows.Storage=ON -DAPI_nanoFramework.ResourceManager=ON -DAPI_nanoFramework.System.Collections=ON -DAPI_nanoFramework.System.Text=ON" + } + + # CMake prep + $cmakePrep = " -G Ninja -DCMAKE_TOOLCHAIN_FILE=""CMake/toolchain.arm-none-eabi.cmake"" -DTOOLCHAIN_PREFIX=""$env:GNU_GCC_TOOLCHAIN_PATH"" -DCMAKE_BUILD_TYPE=Debug -DBUILD_VERSION=9.9.99.99 -DCHIBIOS_BOARD=$Target $cmakeOptions .." +} +elseif ($Target -eq "ESP32_WROOM_32") { + + # run the install tools + Invoke-Expression "$PSScriptRoot\install-scripts\install-esp32-tools.ps1 -Path $Path" + + $cmakeOptions = " -DTARGET_SERIES=ESP32 -DRTOS=FREERTOS_ESP32 -DNF_FEATURE_DEBUGGER=ON -DNF_FEATURE_RTC=ON -DNF_FEATURE_HAS_CONFIG_BLOCK=ON -DNF_FEATURE_HAS_SDCARD=ON -DAPI_System.Math=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_Windows.Devices.Spi=ON -DAPI_Windows.Devices.I2c=ON -DAPI_Windows.Devices.Pwm=ON -DAPI_Windows.Devices.SerialCommunication=ON -DAPI_Windows.Devices.Adc=ON -DAPI_System.Net=ON -DAPI_Windows.Devices.Wifi=ON -DAPI_Windows.Storage=ON -DNF_SECURITY_MBEDTLS=ON -DAPI_Hardware.Esp32=ON -DSUPPORT_ANY_BASE_CONVERSION=ON -DAPI_nanoFramework.Devices.OneWire=ON -DAPI_nanoFramework.ResourceManager=ON -DAPI_nanoFramework.System.Collections=ON -DAPI_nanoFramework.System.Text=ON" + + # CMake prep + $cmakePrep = " -G Ninja -DCMAKE_TOOLCHAIN_FILE=""CMake/toolchain.xtensa-esp32-elf.cmake"" -DTOOLCHAIN_PREFIX=""$env:ESP32_TOOLCHAIN_PATH"" -DESP32_IDF_PATH=""$env:ESP32_IDF_PATH"" -DESP32_LIBS_PATH=""$env:ESP32_LIBS_PATH"" -DCMAKE_BUILD_TYPE=Debug -DBUILD_VERSION=9.99.999 -DESP32_BOARD=$Target $cmakeOptions .." +} +elseif ($Target -eq "TI_CC3220SF_LAUNCHXL") { + # TODO + Write-Error "Build not supported becuase the build system for this target is being reworked" + + Exit 1 +} +elseif ($Target -eq "TI_CC1352R1_LAUNCHXL") { + + # run the install tools, OK to reuse the STM32 + Invoke-Expression "$PSScriptRoot\install-scripts\install-stm32-tools.ps1 -Path $Path" + + If ( $Target -eq "TI_CC1352R1_LAUNCHXL" ) { + $cmakeOptions = " -DTARGET_SERIES=CC13x2_26x2 -DRTOS=TI_SIMPLELINK -DSUPPORT_ANY_BASE_CONVERSION=OFF -DNF_FEATURE_DEBUGGER=ON -DNF_FEATURE_RTC=ON -DNF_FEATURE_WATCHDOG=OFF -DAPI_Windows.Devices.Gpio=ON -DAPI_Windows.Devices.Spi=OFF -DAPI_Windows.Devices.I2c=OFF -DAPI_Windows.Devices.Pwm=OFF -DAPI_Windows.Devices.SerialCommunication=OFF -DAPI_Windows.Devices.Adc=OFF -DAPI_nanoFramework.TI.EasyLink=ON" + } + + # CMake prep + $cmakePrep = " -G Ninja -DCMAKE_TOOLCHAIN_FILE=""CMake/toolchain.arm-none-eabi.cmake"" -DTOOLCHAIN_PREFIX=""$env:GNU_GCC_TOOLCHAIN_PATH"" -DCMAKE_BUILD_TYPE=Debug -DBUILD_VERSION=9.99.999 -DTI_BOARD=$Target $cmakeOptions .." +} +elseif ($Target -eq "NXP_MIMXRT1060_EVK") { + # TODO + Write-Error "Build not supported becuase the build system for this target is being reworked" + + Exit 1 +} +elseif ($Target -eq "GHI_FEZ_CERB40_NF" -or + $Target -eq "I2M_ELECTRON_NF" -or + $Target -eq "I2M_OXYGEN_NF" -or + $Target -eq "ST_NUCLEO64_F401RE_NF" -or + $Target -eq "ST_NUCLEO64_F411RE_NF" -or + $Target -eq "ST_STM32F411_DISCOVERY" -or + $Target -eq "ST_NUCLEO144_F412ZG_NF" -or + $Target -eq "ST_NUCLEO144_F746ZG" -or + $Target -eq "ST_STM32F4_DISCOVERY" -or + $Target -eq "ST_NUCLEO144_F439ZI") { + + # run the install tools, OK to reuse the STM32 + Invoke-Expression "$PSScriptRoot\install-scripts\install-stm32-tools.ps1 -Path $Path" + + # community targets with STM32 + If ($Target -eq "GHI_FEZ_CERB40_NF") { + $cmakeOptions = " -DTARGET_SERIES=STM32F4xx -DNF_FEATURE_DEBUGGER=ON -DNF_FEATURE_RTC=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_Windows.Devices.Spi=ON -DAPI_Windows.Devices.I2c=ON -DAPI_Windows.Devices.Pwm=ON -DAPI_Windows.Devices.SerialCommunication=ON -DAPI_Windows.Devices.Adc=ON" + } + elseif ($Target -eq "I2M_ELECTRON_NF") { + $cmakeOptions = " -DTARGET_SERIES=STM32F4xx -DNF_FEATURE_DEBUGGER=ON -DUSE_RNG=OFF -DNF_FEATURE_RTC=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_Windows.Devices.Spi=ON -DAPI_Windows.Devices.I2c=ON -DAPI_Windows.Devices.Pwm=ON -DAPI_Windows.Devices.SerialCommunication=ON -DAPI_Windows.Devices.Adc=ON" + } + elseif ($Target -eq "I2M_OXYGEN_NF") { + $cmakeOptions = " -DTARGET_SERIES=STM32F4xx -DNF_FEATURE_DEBUGGER=ON -DUSE_RNG=OFF -DNF_FEATURE_RTC=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_Windows.Devices.Spi=ON -DAPI_Windows.Devices.I2c=ON -DAPI_Windows.Devices.Pwm=ON -DAPI_Windows.Devices.SerialCommunication=ON -DAPI_Windows.Devices.Adc=ON" + } + elseif ($Target -eq "ST_NUCLEO64_F401RE_NF") { + $cmakeOptions = " -DTARGET_SERIES=STM32F4xx -DNF_FEATURE_DEBUGGER=ON -DUSE_RNG=OFF -DSWO_OUTPUT=ON -DNF_FEATURE_RTC=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_Windows.Devices.Spi=ON -DAPI_Windows.Devices.I2c=ON -DAPI_Windows.Devices.Pwm=ON -DAPI_Windows.Devices.SerialCommunication=ON -DAPI_Windows.Devices.Adc=ON -DAPI_nanoFramework.Devices.OneWire=ON" + } + elseif ($Target -eq "ST_NUCLEO64_F411RE_NF") { + $cmakeOptions = " -DTARGET_SERIES=STM32F4xx -DNF_FEATURE_DEBUGGER=ON -DUSE_RNG=OFF -DSWO_OUTPUT=ON -DNF_FEATURE_RTC=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_Windows.Devices.Spi=ON -DAPI_Windows.Devices.I2c=ON -DAPI_Windows.Devices.Pwm=ON -DAPI_Windows.Devices.SerialCommunication=ON -DAPI_Windows.Devices.Adc=ON -DAPI_nanoFramework.System.Collections=ON -DAPI_nanoFramework.ResourceManager=ON -DAPI_nanoFramework.System.Text=ON" + } + elseif ($Target -eq "ST_STM32F411_DISCOVERY") { + $cmakeOptions = " -DTARGET_SERIES=STM32F4xx -DNF_FEATURE_DEBUGGER=ON -DUSE_RNG=OFF -DSWO_OUTPUT=ON -DNF_FEATURE_RTC=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_Windows.Devices.Spi=ON -DAPI_Windows.Devices.I2c=ON -DAPI_Windows.Devices.Pwm=ON -DAPI_Windows.Devices.SerialCommunication=ON -DAPI_Windows.Devices.Adc=ON -DAPI_nanoFramework.System.Collections=ON -DAPI_nanoFramework.ResourceManager=ON -DAPI_nanoFramework.System.Text=ON" + } + elseif ($Target -eq "ST_NUCLEO144_F412ZG_NF") { + $cmakeOptions = " -DTARGET_SERIES=STM32F4xx -DNF_FEATURE_DEBUGGER=ON -DSWO_OUTPUT=ON -DNF_FEATURE_RTC=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_Windows.Devices.Spi=ON -DAPI_Windows.Devices.I2c=ON -DAPI_Windows.Devices.Pwm=ON -DAPI_Windows.Devices.SerialCommunication=OFF -DAPI_Windows.Devices.Adc=ON" + } + elseif ($Target -eq "ST_NUCLEO144_F746ZG") { + $cmakeOptions = " -DTARGET_SERIES=STM32F7xx -DRTOS=CHIBIOS -DNF_FEATURE_DEBUGGER=ON -DSWO_OUTPUT=ON -DNF_FEATURE_RTC=ON -DNF_FEATURE_HAS_CONFIG_BLOCK=ON -DAPI_System.Math=ON -DAPI_Hardware.Stm32=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_Windows.Devices.Spi=ON -DAPI_Windows.Devices.I2c=ON -DAPI_Windows.Devices.Pwm=ON -DAPI_Windows.Devices.SerialCommunication=ON -DAPI_Windows.Devices.Adc=ON -DAPI_System.Net=ON -DNF_SECURITY_MBEDTLS=ON -DAPI_nanoFramework.Devices.OneWire=ON" + } + elseif ($Target -eq "ST_STM32F4_DISCOVERY") { + $cmakeOptions = " -DTARGET_SERIES=STM32F4xx -DRTOS=CHIBIOS -DSUPPORT_ANY_BASE_CONVERSION=ON -DNF_FEATURE_DEBUGGER=ON -DSWO_OUTPUT=ON -DNF_FEATURE_RTC=ON -DAPI_System.Math=ON -DAPI_Hardware.Stm32=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_Windows.Devices.Spi=ON -DAPI_Windows.Devices.I2c=ON -DAPI_Windows.Devices.Pwm=ON -DAPI_Windows.Devices.SerialCommunication=ON -DAPI_Windows.Devices.Adc=ON -DAPI_nanoFramework.Devices.OneWire=ON -DAPI_nanoFramework.Devices.Can=ON" + } + elseif ($Target -eq "ST_NUCLEO144_F439ZI") { + $cmakeOptions = " -DTARGET_SERIES=STM32F4xx -DRTOS=CHIBIOS -DNF_FEATURE_DEBUGGER=ON -DSWO_OUTPUT=ON -DNF_FEATURE_RTC=ON -DNF_FEATURE_HAS_CONFIG_BLOCK=ON -DAPI_System.Math=ON -DAPI_Hardware.Stm32=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_Windows.Devices.Spi=ON -DAPI_Windows.Devices.I2c=ON -DAPI_Windows.Devices.Pwm=ON -DAPI_Windows.Devices.SerialCommunication=ON -DAPI_Windows.Devices.Adc=ON -DAPI_System.Net=ON -DNF_SECURITY_MBEDTLS=ON" + } + + # CMake prep + $cmakePrep = " -G Ninja -DCMAKE_TOOLCHAIN_FILE=""CMake/toolchain.arm-none-eabi.cmake"" -DTOOLCHAIN_PREFIX=""$env:GNU_GCC_TOOLCHAIN_PATH"" -DCMAKE_BUILD_TYPE=Debug -DBUILD_VERSION=9.9.99.99 -DCHIBIOS_BOARD=$Target $cmakeOptions .." +} +elseif ($Target -eq "TI_CC1352P1_LAUNCHXL") { + # community targets with TI CC13xx + $cmakeOptions = " -DTARGET_SERIES=CC13x2_26x2 -DRTOS=TI_SIMPLELINK -DSUPPORT_ANY_BASE_CONVERSION=OFF -DNF_FEATURE_DEBUGGER=ON -DNF_FEATURE_RTC=ON -DNF_FEATURE_WATCHDOG=OFF -DAPI_Windows.Devices.Gpio=ON -DAPI_Windows.Devices.Spi=OFF -DAPI_Windows.Devices.I2c=OFF -DAPI_Windows.Devices.Pwm=OFF -DAPI_Windows.Devices.SerialCommunication=OFF -DAPI_Windows.Devices.Adc=OFF -DAPI_nanoFramework.TI.EasyLink=ON" + + # CMake prep + $cmakePrep = " -G Ninja -DCMAKE_TOOLCHAIN_FILE=""CMake/toolchain.arm-none-eabi.cmake"" -DTOOLCHAIN_PREFIX=""$env:GNU_GCC_TOOLCHAIN_PATH"" -DCMAKE_BUILD_TYPE=Debug -DBUILD_VERSION=9.9.99.99 -DCHIBIOS_BOARD=$Target $cmakeOptions .." +} +else { + Write-Error "Unknown target name." +} + +# get path to the cmake executable +$cmake = (Get-Command "cmake.exe" -ErrorAction SilentlyContinue) + +# output CMake command +"Just in case you're curious on what the call to CMake is, here's the command line for preparation:" | Write-Host -ForegroundColor White +Write-Host "'cmake $cmakePrep'" | Write-Host -ForegroundColor White + +# start a process with the call to CMake +# dev note: this seems to be the best approach to calling CMake from Powershell because of the complications with properly passing the arguments +# also CMake may write to stdErr and PSCore treats that as an error +$buildProcess = Start-Process -ErrorAction Continue -NoNewWindow -Wait -PassThru -FilePath $cmake.Path -ArgumentList $cmakePrep +$buildProcess.WaitForExit(); +if ($buildProcess.ExitCode -ne 0) { + "CMake preparation failed. Check the error message above." | Write-Host -ForegroundColor Red + exit 1 +} + +# need to move up from the build directory +Set-Location ".." | Out-Null + +# CMake build +$cmakeBuild = " --build build --target all --config Debug" + +# output CMake command +"Just in case you're curious on what the call to CMake is, here's the command line for the build:" | Write-Host -ForegroundColor White +Write-Host "'cmake $cmakeBuild'" | Write-Host -ForegroundColor White + +$buildProcess = Start-Process -ErrorAction Continue -NoNewWindow -Wait -PassThru -FilePath $cmake.Path -ArgumentList $cmakeBuild +$buildProcess.WaitForExit(); +if ($buildProcess.ExitCode -ne 0) { + "CMake build failed. Check the error message above." | Write-Host -ForegroundColor Red + exit 1 +} + +"Build completed." | Write-Host -ForegroundColor Green +"Firmware images (nanoBooter or/and nanoCLR) available in 'build' folder." | Write-Host -ForegroundColor White + +<# +.SYNOPSIS + Performs the build of a nanoFramework target, installing all the required tools and libraries. +.DESCRIPTION + Power Shell Script to build of a nanoFramework target, installing all the required tools and libraries. +.PARAMETER Target + The name of teh target to build [e.g. ESP32_WROOM_32 or ST_STM32F429I_DISCOVERY or NETDUINO3_WIFI]. +.EXAMPLE + .\build.ps1 -Target ST_STM32F429I_DISCOVERY +.NOTES + The script installs all the required tools and libraries on default locations. +#> diff --git a/cmake-variants.TEMPLATE-ESP32.json b/cmake-variants.TEMPLATE-ESP32.json deleted file mode 100644 index 429e17f526..0000000000 --- a/cmake-variants.TEMPLATE-ESP32.json +++ /dev/null @@ -1,79 +0,0 @@ -{ - "buildType": { - "default": "debug", - "choices": { - "debug": { - "short": "Debug", - "long": "Emit debug information without performing optimizations", - "buildType": "Debug" - }, - "release": { - "short": "Release", - "long": "Enable optimizations, omit debug info", - "buildType": "Release" - }, - "minsize": { - "short": "MinSizeRel", - "long": "Optimize for smallest binary size", - "buildType": "MinSizeRel" - }, - "reldeb": { - "short": "RelWithDebInfo", - "long": "Perform optimizations AND include debugging information", - "buildType": "RelWithDebInfo" - } - } - }, - - "linkage": { - "default": "", - "choices": { - - "Esp32_nanoCLR": { - "short": "NanoCLR", - "settings": { - "BUILD_VERSION": "0.9.99.999", - "CMAKE_TOOLCHAIN_FILE" : "CMake/toolchain.xtensa-esp32-elf.cmake", - "TOOLCHAIN_PREFIX": "", - "ESP32_IDF_PATH": "", - "ESP32_LIBS_PATH": "", - "EXECUTABLE_OUTPUT_PATH": "${workspaceRoot}/build", - "TARGET_SERIES": "ESP32", - "ESP32_BOARD": "ESP32_WROOM_32", - "USE_FPU": "TRUE", - "RTOS": "FREERTOS_ESP32", - "SWO_OUTPUT": "OFF", - "NF_BUILD_RTM": "OFF", - "NF_WP_TRACE_ERRORS": "OFF", - "NF_WP_TRACE_HEADERS": "OFF", - "NF_WP_TRACE_STATE": "OFF", - "NF_WP_TRACE_NODATA": "OFF", - "NF_WP_TRACE_ALL": "OFF", - "NF_WP_IMPLEMENTS_CRC32": "ON", - "NF_FEATURE_DEBUGGER": "ON", - "NF_FEATURE_RTC": "ON", - "NF_FEATURE_USE_APPDOMAINS": "OFF", - "NF_FEATURE_SUPPORT_REFLECTION" : "ON", - "NF_FEATURE_HAS_CONFIG_BLOCK": "ON", - "NF_FEATURE_HAS_SDCARD": "ON", - "API_System.Net": "ON", - "NF_SECURITY_MBEDTLS": "ON", - "API_nanoFramework.ResourceManager" : "ON", - "API_nanoFramework.System.Collections" : "ON", - "API_nanoFramework.System.Text" : "ON", - "API_Windows.Devices.Wifi": "ON", - "API_Windows.Devices.Adc": "ON", - "API_System.Devices.Dac" : "OFF", - "API_Windows.Devices.Gpio": "ON", - "API_Windows.Devices.I2c": "ON", - "API_Windows.Devices.Pwm": "ON", - "API_Windows.Devices.SerialCommunication": "ON", - "API_Windows.Devices.Spi": "ON", - "API_Windows.Networking.Sockets": "OFF", - "API_Windows.Storage": "ON", - "API_Hardware.Esp32": "ON" - } - } - } - } -} diff --git a/cmake-variants.TEMPLATE.json b/cmake-variants.TEMPLATE.json deleted file mode 100644 index e0d7238e30..0000000000 --- a/cmake-variants.TEMPLATE.json +++ /dev/null @@ -1,100 +0,0 @@ -{ - "buildType": { - "default": "debug", - "choices": { - "debug": { - "short": "Debug", - "long": "Emit debug information without performing optimizations", - "buildType": "Debug" - }, - "minsize": { - "short": "MinSizeRel", - "long": "Optimize for smallest binary size", - "buildType": "MinSizeRel" - }, - "reldeb": { - "short": "RelWithDebInfo", - "long": "Perform optimizations AND include debugging information", - "buildType": "RelWithDebInfo" - } - } - }, - - "linkage": { - "default": "", - "choices": { - "OPTION_NAME_HERE": { - "short": "", - "settings": { - "BUILD_VERSION" : "0.9.99.999", - "CMAKE_TOOLCHAIN_FILE" : "CMake/toolchain..cmake", - "TOOLCHAIN_PREFIX" : "", - "TOOL_HEX2DFU_PREFIX" : "", - "ESP32_IDF_PATH" : "/esp-idf", - "ESP32_LIBS_PATH" : "/libs", - "TARGET_SERIES" : "", - "USE_RNG" : "", - "DP_FLOATINGPOINT" : "", - "SUPPORT_ANY_BASE_CONVERSION" : "", - "RTOS" : "", - "CHIBIOS_SOURCE" : "", - "CHIBIOS_CONTRIB_REQUIRED" : "OFF-default-ON-to-include_ChibiOS-Contrib-repository-in-the-build", - "CHIBIOS_CONTRIB_SOURCE" : "", - "FREERTOS_BOARD" : "", - "FREERTOS_VERSION" : "", - "FREERTOS_SOURCE" : "", - "CMSIS_SOURCE" : "", - "CMSIS_VERSION" : "", - "CHIBIOS_BOARD" : "", - "STM32_CUBE_PACKAGE_REQUIRED" : "", - "STM32_CUBE_PACKAGE_SOURCE" : "", - "TI_BOARD" : "", - "TI_SL_CC32xx_SDK_SOURCE" : "", - "SPIFFS_SOURCE" : "", - "SWO_OUTPUT" : "OFF-default-ON-to-enable-ARM-CortexM-Single-Wire-Output", - "FATFS_VERSION": "", - "NF_BUILD_RTM" : "OFF-default-ON-to-enable-RTM-build", - "NF_WP_TRACE_ERRORS" : "OFF-default-ON-to-enable-trace-error-messages-wire-protocol", - "NF_WP_TRACE_HEADERS" : "OFF-default-ON-to-enable-trace-header-messages-wire-protocol", - "NF_WP_TRACE_STATE" : "OFF-default-ON-to-enable-trace-state-messages-wire-protocol", - "NF_WP_TRACE_NODATA" : "OFF-default-ON-to-enable-trace-no-data-messages-wire-protocol", - "NF_WP_TRACE_ALL" : "OFF-default-ON-to-enable-trace-all-messages-wire-protocol", - "NF_WP_IMPLEMENTS_CRC32" : "ON-default-OFF-to-disable-CRC32-wire-protocol", - "NF_FEATURE_DEBUGGER" : "OFF-default-ON-to-include-managed-app-debugging-capability", - "NF_FEATURE_RTC" : "OFF-default-ON-to-enable-hardware-RTC", - "NF_FEATURE_USE_APPDOMAINS" : "OFF-default-ON-to-enable-support-for-Application-Domains", - "NF_FEATURE_SUPPORT_REFLECTION" : "ON-default-OFF-to-disable-support-for-System.Reflection-API", - "NF_FEATURE_WATCHDOG" : "ON-to-enable-hardware-watchdog-ON-is-default", - "NF_FEATURE_HAS_CONFIG_BLOCK" : "OFF-default-ON-to-enable-configuration-block-storage", - "NF_FEATURE_HAS_SDCARD" : "OFF-default-ON-to-enable-support-for-SDCard-storage-device", - "NF_FEATURE_HAS_USB_MSD" : "OFF-default-ON-to-enable-support-for-USB-Mass-storage-device", - "NF_FEATURE_USE_SPIFFS" : "OFF-default-ON-to-enable-support-for-SPI-flash-file-system", - "NF_PLATFORM_NO_CLR_TRACE" : "OFF-default-ON-to-disable-all-trace-on-CLR", - "NF_CLR_NO_IL_INLINE" : "OFF-default-ON-to-disable-CLR-IL-inlining", - "NF_INTEROP_ASSEMBLIES" : [ "Assembly1-Namespace", "Assembly2-Namespace" ], - "NF_NETWORKING_SNTP" : "ON-default-to-add-SNTP-client-requires-networking", - "NF_SECURITY_MBEDTLS" : "OFF-default-ON-to-add-network-security-from-mbedTLS", - "MBEDTLS_SOURCE" : "", - "API_nanoFramework.Devices.Can" : "OFF-default-ON-to-add-this-API", - "API_nanoFramework.Devices.OneWire" : "OFF-default-ON-to-add-this-API", - "API_nanoFramework.ResourceManager" : "OFF-default-ON-to-add-this-API", - "API_nanoFramework.System.Collections" : "OFF-default-ON-to-add-this-API", - "API_nanoFramework.System.Text" : "OFF-default-ON-to-add-this-API", - "API_System.Math" : "OFF-default-ON-to-add-this-API", - "API_System.Net" : "OFF-default-ON-to-add-this-API", - "API_Windows.Devices.Adc" : "OFF-default-ON-to-add-this-API", - "API_System.Devices.Dac" : "OFF-default-ON-to-add-this-API", - "API_Windows.Devices.Gpio" : "OFF-default-ON-to-add-this-API", - "API_Windows.Devices.I2c" : "OFF-default-ON-to-add-this-API", - "API_Windows.Devices.Pwm" : "OFF-default-ON-to-add-this-API", - "API_Windows.Devices.SerialCommunication" : "OFF-default-ON-to-add-this-API", - "API_Windows.Devices.Spi" : "OFF-default-ON-to-add-this-API", - "API_Windows.Networking.Sockets" : "OFF-default-ON-to-add-this-API", - "API_Hardware.Esp32" : "OFF-default-ON-to-add-this-API", - "API_Hardware.Stm32" : "OFF-default-ON-to-add-this-API", - "API_nanoFramework.TI.EasyLink" : "OFF-default-ON-to-add-this-API" - } - } - } - } -} diff --git a/install-scripts/Initialize-VSCode.ps1 b/install-scripts/Initialize-VSCode.ps1 new file mode 100644 index 0000000000..a8bcacc40b --- /dev/null +++ b/install-scripts/Initialize-VSCode.ps1 @@ -0,0 +1,94 @@ +# Copyright (c) .NET Foundation and Contributors +# See LICENSE file in the project root for full license information. + +# This PS configures Visual Studio Code to use with nanoFramework: +# sets/updates the required settings in settings.json +# sets/updates the launch.json from the targets +# sets/updates the cmake-variants.json from the targets + +function Main { + param ( + [Parameter(HelpMessage = "Updates the settings.json file from the template.")] + [switch]$UpdateSettings = $false, + [Parameter(HelpMessage = "Updates the launch.json configuration for the various targets from the templates on the targets directory.")] + [switch]$UpdateLaunch = $false, + [Parameter(HelpMessage = "Force setting/updating the values even if they already exist.")] + [switch]$force = $false + ) + + Import-Module -Name "$PSScriptRoot\configure-vscode-common.psm1" + + ############################ + # settings.json + + # path to settings.json file + $filePath = Join-Path -Path $(Get-VSCodeFolderPath) -ChildPath "settings.json" + + # flag for file changes + $fileChanges = $false + + # file exists + $fileExists = Test-Path $filePath -ErrorAction SilentlyContinue + + if ($fileExists -ne $true) { + # create file + Set-Content -Path "$filePath" -Value '{ }' -Encoding UTF8 + } + + # read settings file as json + $settings = Get-Content -Raw -Encoding UTF8 $filePath | ConvertFrom-Json + + if ($null -ne $settings) { + + # check 'cmake.configureSettings' + if ($null -eq $settings."cmake.configureSettings") { + # create 'cmake.configureSettings' + $settings | Add-Member -MemberType NoteProperty -Name 'cmake.configureSettings' -Value $(New-Object PSObject) + + # flag changes + $fileChanges = $true + } + + # set CMAKE_MAKE_PROGRAM with Ninja in case it's not available on the PATH inside "cmake.configureSettings" + if ($null -eq $settings."cmake.configureSettings".CMAKE_MAKE_PROGRAM -or $force) { + # need to replace forward slash for paths to work with GCC and CMake + $ninjaPath = Join-Path -Path $env:NINJA_PATH -ChildPath 'ninja.exe' + $ninjaPath = $ninjaPath.Replace('\', '/') + + + $settings."cmake.configureSettings" | Add-Member -MemberType NoteProperty -Name 'CMAKE_MAKE_PROGRAM' -Value "$ninjaPath" + + # flag changes + $fileChanges = $true + } + + # setting Ninja as the preferred generator + if ($null -eq $settings."cmake.generator" -or $force) { + $settings | Add-Member -MemberType NoteProperty -Name 'cmake.generator' -Value 'Ninja' + + # flag changes + $fileChanges = $true + } + + # save changes, if needed + if ($fileChanges) { + + $settings | ConvertTo-Json -depth 32 | Out-File $filePath -Encoding UTF8 -Force + + Repair-Patterns($filePath) + } + } + + # set/update launch.json + . .\Set-VSCode-Launch.ps1 + Set-VSCode-Launch $force + + # set/update tasks.json + . .\Set-VSCode-Tasks.ps1 + Set-VSCode-Tasks $force + + # set/update cmake-variants.json + . .\Set-VSCode-CMakes.ps1 + Set-VSCode-CMakes $force +} + +Main diff --git a/install-scripts/Set-PathVariable.ps1 b/install-scripts/Set-PathVariable.ps1 index cc7b65056f..db5005358e 100644 --- a/install-scripts/Set-PathVariable.ps1 +++ b/install-scripts/Set-PathVariable.ps1 @@ -1,28 +1,26 @@ - ## Based on Hahndorf's awesome collection of PowerShell scripts. - ## https://github.com/hahndorf/hacops - [CmdletBinding(SupportsShouldProcess = $true)] +## Based on Hahndorf's awesome collection of PowerShell scripts. +## https://github.com/hahndorf/hacops + +[CmdletBinding(SupportsShouldProcess = $true)] Param( - [parameter(Mandatory=$true)] + [parameter(Mandatory = $true)] [string]$NewLocation) -Begin -{ +Begin { -# requires –runasadministrator + # requires –runasadministrator $regPath = "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" $hklm = [Microsoft.Win32.Registry]::LocalMachine - Function GetOldPath() - { + Function GetOldPath() { $regKey = $hklm.OpenSubKey($regPath, $FALSE) $envpath = $regKey.GetValue("Path", "", [Microsoft.Win32.RegistryValueOptions]::DoNotExpandEnvironmentNames) return $envPath } } -Process -{ +Process { # Win32API error codes $ERROR_SUCCESS = 0 $ERROR_DUP_NAME = 34 @@ -30,8 +28,7 @@ Process $NewLocation = $NewLocation.Trim(); - If ($NewLocation -eq "" -or $NewLocation -eq $null) - { + If ($NewLocation -eq "" -or $NewLocation -eq $null) { Exit $ERROR_INVALID_DATA } @@ -40,17 +37,16 @@ Process # check whether the new location is already in the path $parts = $oldPath.split(";") - If ($parts -contains $NewLocation) - { - Write-Warning ("The new location is already in the path ('"+$NewLocation+"')") + If ($parts -contains $NewLocation) { + Write-Warning ("The new location is already in the path ('" + $NewLocation + "')") Exit $ERROR_DUP_NAME } # build the new path, make sure we don't have double semicolons $newPath = $oldPath + ";" + $NewLocation - $newPath = $newPath -replace ";;",";" + $newPath = $newPath -replace ";;", ";" - if ($pscmdlet.ShouldProcess("%Path%", "Set $newPath")){ + if ($pscmdlet.ShouldProcess("%Path%", "Set $newPath")) { # add to the current session $env:path += ";$NewLocation" # save into registry diff --git a/install-scripts/Set-VSCode-CMakes.ps1 b/install-scripts/Set-VSCode-CMakes.ps1 new file mode 100644 index 0000000000..738e051520 --- /dev/null +++ b/install-scripts/Set-VSCode-CMakes.ps1 @@ -0,0 +1,110 @@ +# Copyright (c) .NET Foundation and Contributors +# See LICENSE file in the project root for full license information. + +# This PS sets/updates Visual Studio Code cmake-variants.json from the targets + +function Set-VSCode-CMakes { + param ( + [switch]$force = $false + ) + + # flag for file changes + $fileChanges = $false + + $choicesToUpdate = @() + + # path to cmake-variants.json file + $filePath = Join-Path -Path $(Get-VSCodeFolderPath) -ChildPath "cmake-variants.json" + + # file exists + $fileExists = Test-Path $filePath -ErrorAction SilentlyContinue + + if ($fileExists -ne $true) { + # create file by copying from the template + Copy-Item "$(Get-VSCodeFolderPath)\cmake-variants.TEMPLATE.json" -Destination "$(Get-VSCodeFolderPath)\cmake-variants.json" -Force + + # read cmake-variants file as json + $cmakeVariants = Get-Content -Raw -Encoding UTF8 $filePath | ConvertFrom-Json + + # replace choices with empty value + $cmakeVariants.linkage | Add-Member -MemberType NoteProperty -Name "choices" -Value $(New-Object PSObject) -Force + + # save back + $cmakeVariants | ConvertTo-Json -depth 32 -Compress | Out-File $filePath -Encoding UTF8 -Force + } + else { + try { + # read cmake-variants file as json + $cmakeVariants = Get-Content -Raw -Encoding UTF8 $filePath | ConvertFrom-Json + } + catch { + "There seems to be a formatting error on the '$filePath' file. Can't update..." | Write-Error + Exit 1 + } + } + + if ($null -ne $cmakeVariants) { + + # get all cmake-variants.json file from the targets and targets community + Get-ChildItem -Path "$(Get-RepoPath)\targets*" -Include "cmake-variants.json" -Recurse | + Foreach-object { + + $cmakeTemplate = Get-Content -Raw -Encoding UTF8 $_.FullName | ConvertFrom-Json + + foreach ($newChoice in $cmakeTemplate.linkage.choices) { + + $addChoice = $true + + # loop through each existing linkage choice + foreach ($existingChoice in $cmakeVariants.linkage.choices) { + + if(($existingChoice | Get-Member -MemberType NoteProperty).Name -eq ($newChoice | Get-Member -MemberType NoteProperty).Name) + { + # choice already exists + if($force) + { + $addChoice = $true + } + else { + $addChoice = $false + } + + Continue + } + } + + if($addChoice) { + # copy config + $choicesToUpdate += $newChoice + + # flag changes + $fileChanges = $true + } + } + } + + # add any choices that are to be added + foreach($choice in $choicesToUpdate) + { + # need to access PS object + $object = ($choice | Get-Member -MemberType NoteProperty) + + # need to grab the name to be used as key + $key = $object.Name + + # now add it, use with force, in case this to update the value + $cmakeVariants.linkage.choices | Add-Member -MemberType NoteProperty -Name $key -Value $choice."$key" -Force + } + + # save changes, if needed + if ($fileChanges) { + + # save file with updated contents + $cmakeVariants | ConvertTo-Json -depth 32 -Compress | Out-File $filePath -Encoding UTF8 -Force + + Repair-Patterns $filePath + + Update-Paths $filePath + } + } +} diff --git a/install-scripts/Set-VSCode-Launch.ps1 b/install-scripts/Set-VSCode-Launch.ps1 new file mode 100644 index 0000000000..0b11d43bc1 --- /dev/null +++ b/install-scripts/Set-VSCode-Launch.ps1 @@ -0,0 +1,107 @@ +# Copyright (c) .NET Foundation and Contributors +# See LICENSE file in the project root for full license information. + +# This PS sets/updates Visual Studio Code launch.json from the targets + +function Set-VSCode-Launch { + param ( + [switch]$force = $false + ) + + # flag for file changes + $fileChanges = $false + + # path to launch.json file + $filePath = Join-Path -Path $(Get-VSCodeFolderPath) -ChildPath "launch.json" + + # file exists + $fileExists = Test-Path $filePath -ErrorAction SilentlyContinue + + if ($fileExists -ne $true) { + # create file + Set-Content -Path "$filePath" -Value '{ "version": "0.2.0", "configurations": [ ] }' -Encoding UTF8 + } + + $configsToAdd = @() + $configsToRemove = @() + + try { + # read launch file as json + $launch = Get-Content -Raw -Encoding UTF8 $filePath | ConvertFrom-Json + } + catch { + "There seems to be a formatting error on the '$filePath' file. Can't update..." | Write-Error + Exit 1 + } + + if ($null -ne $launch) { + + # get all launch.json file from the targets and targets community + Get-ChildItem -Path "$(Get-RepoPath)\targets*" -Include "launch.json" -Recurse | + Foreach-object { + + $launchTemplate = Get-Content -Raw -Encoding UTF8 $_.FullName | ConvertFrom-Json + + foreach ($newConfig in $launchTemplate.configurations) { + + $addConfig = $true + + # loop through each existing configuration + foreach ($existingConfig in $launch.configurations) { + + if($($existingConfig.name) -eq $($newConfig.name)) + { + # config already exists + if($force) + { + $configsToRemove += $existingConfig + $addConfig = $true + } + else { + $addConfig = $false + } + + Continue + } + } + + if($addConfig) { + # copy config + $configsToAdd += $newConfig + + # flag changes + $fileChanges = $true + } + } + } + + # remove any configs that are to be removed + [System.Collections.ArrayList]$bkpConfigs= $launch.configurations + foreach($config in $configsToRemove) + { + $bkpConfigs.Remove($config) + } + + if($configsToRemove.Count -gt 0) + { + $launch.configurations = $bkpConfigs + } + + # add any configs that are to be added + foreach($config in $configsToAdd) + { + $launch.configurations += $config + } + + # save changes, if needed + if ($fileChanges) { + + # save file with updated contents + $launch | ConvertTo-Json -depth 32 | Out-File $filePath -Encoding UTF8 -Force + + Repair-Patterns $filePath + + Update-Paths $filePath + } + } +} diff --git a/install-scripts/Set-VSCode-Tasks.ps1 b/install-scripts/Set-VSCode-Tasks.ps1 new file mode 100644 index 0000000000..a4b7690a9a --- /dev/null +++ b/install-scripts/Set-VSCode-Tasks.ps1 @@ -0,0 +1,152 @@ +# Copyright (c) .NET Foundation and Contributors +# See LICENSE file in the project root for full license information. + +# This PS sets/updates Visual Studio Code tasks.json + +function Set-VSCode-Tasks { + param ( + [switch]$force = $false + ) + + # flag for file changes + $fileChanges = $false + + # path to tasks.json file + $filePath = Join-Path -Path $(Get-VSCodeFolderPath) -ChildPath "tasks.json" + + # file exists + $fileExists = Test-Path $filePath -ErrorAction SilentlyContinue + + if ($fileExists -ne $true) { + # create file + Set-Content -Path $filePath -Value '{ "version": "2.0.0", "tasks": [ ], "inputs": [] }' -Encoding UTF8 + } + + # read task file as json + $tasks = Get-Content -Raw -Encoding UTF8 $filePath | ConvertFrom-Json + + if ($null -ne $tasks) { + + # read tasks template file as json + $tasksTemplate = Get-Content -Raw -Encoding UTF8 "$(Get-VSCodeFolderPath)\tasks.TEMPLATE.json" | ConvertFrom-Json + + # placeholder for the tasks to add + $tasksToAdd = @() + $tasksToRemove = @() + + # placeholder for the inputs to add + $inputsToAdd = @() + $inputsToRemove = @() + + foreach ($templateEntry in $tasksTemplate.tasks) { + + $addTask = $true + + # loop through each existing task + foreach ($existingTask in $tasks.tasks) { + + if($($existingTask.label) -eq $($templateEntry.label)) + { + # task already exists + if($force) + { + $tasksToRemove += $existingTask + $addTask = $true + } + else { + $addTask = $false + } + + Continue + } + } + + if($addTask) { + # copy task + $tasksToAdd += $templateEntry + + # flag changes + $fileChanges = $true + } + } + + foreach ($templateEntry in $tasksTemplate.inputs) { + + $addInput = $true + + # loop through each existing input + foreach ($existingInput in $tasks.inputs) { + + if($($existingInput.label) -eq $($templateEntry.id)) + { + # input already exists + if($force) + { + $inputsToRemove += $existingInput + $addInput = $true + } + else { + $addInput = $false + } + + Continue + } + } + + if($addInput) { + # copy input + $inputsToAdd += $templateEntry + + # flag changes + $fileChanges = $true + } + } + + # remove any tasks that are to be removed + if($tasksToRemove.Count -gt 0) + { + [System.Collections.ArrayList]$bkpTasks = $tasks.tasks + foreach($task in $tasksToRemove) + { + $bkpTasks.Remove($task) + } + + $tasks.tasks = $bkpTasks + } + + # add any inputs that are to be added + foreach($task in $tasksToAdd) + { + $tasks.tasks += $task + } + + # remove any inputs that are to be removed + if($inputsToRemove.Count -gt 0) + { + [System.Collections.ArrayList]$bkpInputs = $tasks.inputs + foreach($input in $inputsToRemove) + { + $bkpInputs.Remove($input) + } + + $tasks.inputs = $bkpInputs + } + + # add any inputs that are to be added + foreach($input in $inputsToAdd) + { + $tasks.inputs += $input + } + + # save changes, if needed + if ($fileChanges) { + + # save file with updated contents + $tasks | ConvertTo-Json -depth 32 | Out-File $filePath -Encoding UTF8 -Force + + Repair-Patterns $filePath + + Update-Paths $filePath + } + } +} diff --git a/install-scripts/configure-vscode-common.psm1 b/install-scripts/configure-vscode-common.psm1 new file mode 100644 index 0000000000..69cb1275c4 --- /dev/null +++ b/install-scripts/configure-vscode-common.psm1 @@ -0,0 +1,112 @@ +# Copyright (c) .NET Foundation and Contributors +# See LICENSE file in the project root for full license information. + +# patterns to be replaced in the templates +$toolchainPattern = "" +$esp32ToolchainPattern = "" +$repoRootPattern = "" +$openOcdPattern = "" +$esp32OpenOcdPattern = "" +$buildFolderPattern = "" +$esp32BootloaderFolderPattern = "" +$esp32IdfFolderPattern = "" +$esp32LibsFolderPattern = "" +$hex2dfuPattern = "" +$srecordPattern = "" + +function Get-RepoPath { + return Join-Path -Path $PSScriptRoot -ChildPath "\.." -Resolve +} + +function Get-VSCodeFolderPath { + return Join-Path -Path $(Get-RepoPath) -ChildPath ".vscode" +} + +<# +.SYNOPSIS +Replaces various patterns present in the templates to with the correct paths for the current setup. +#> +function Update-Paths { + param ( + $filePath + ) + + # load content as string to allow replacing content + $content = Get-Content -Path $filePath | Out-String + + # replace patterns in the file content + # to be safe, make sure to replace the paths with the forward slashes + + if($env:GNU_GCC_TOOLCHAIN_PATH) + { + $content = $content -replace $toolchainPattern, $env:GNU_GCC_TOOLCHAIN_PATH.Replace('\', '/') + } + + if($env:OPENOCD_PATH) + { + $content = $content -replace $openOcdPattern, $env:OPENOCD_PATH.Replace('\', '/') + } + + if($env:HEX2DFU_PATH) + { + $content = $content -replace $hex2dfuPattern, $env:HEX2DFU_PATH.Replace('\', '/') + } + + if($env:ESP32_TOOLCHAIN_PATH) + { + $content = $content -replace $esp32ToolchainPattern, $env:ESP32_TOOLCHAIN_PATH.Replace('\', '/') + } + + if($env:ESP32_OPENOCD_PATH) + { + $content = $content -replace $esp32OpenOcdPattern, $env:ESP32_OPENOCD_PATH.Replace('\', '/') + } + + if($env:ESP32_LIBS_PATH) + { + $content = $content -replace $esp32LibsFolderPattern, $env:ESP32_LIBS_PATH.Replace('\', '/') + $content = $content -replace $esp32BootloaderFolderPattern, $env:ESP32_LIBS_PATH.Replace('\', '/') + } + + if($env:ESP32_IDF_PATH) + { + $content = $content -replace $esp32IdfFolderPattern, $env:ESP32_IDF_PATH.Replace('\', '/') + } + + if($env:SRECORD_PATH) + { + $content = $content -replace $srecordPattern, $env:SRECORD_PATH.Replace('\', '/') + } + + $content = $content -replace $repoRootPattern, $(Get-RepoPath).Replace('\', '/') + $content = $content -replace $buildFolderPattern, "$(Get-RepoPath)\build".Replace('\', '/') + + # save back to the file + $content | Out-File -FilePath $filePath -Encoding utf8 -Force +} + +<# +.SYNOPSIS +Repair unwanted patterns in json content result of a bad encoding. +#> +function Repair-Patterns { + param ( + $filePath + ) + + # replace unwanted patterns + $replacePatterns = @{ + "\\u003c" = "<" + "\\u003e" = ">" + "\\u0027" = "'" + } + + $inputJson = Get-Content -Path $filePath | Out-String + + foreach ($pattern in $replacePatterns.GetEnumerator()) + { + $inputJson = $inputJson -replace $pattern.Key, $pattern.Value + } + + $inputJson | Out-File -FilePath $filePath -Encoding utf8 -Force +} diff --git a/install-scripts/install-arm-gcc-toolchain.ps1 b/install-scripts/install-arm-gcc-toolchain.ps1 index 46e04d631a..0b6a8801c9 100644 --- a/install-scripts/install-arm-gcc-toolchain.ps1 +++ b/install-scripts/install-arm-gcc-toolchain.ps1 @@ -1,35 +1,99 @@ +# Copyright (c) .NET Foundation and Contributors +# See LICENSE file in the project root for full license information. + # This PS installs the ARM GNU GCC toolchain from our Bintray repository if it's not already available -if($psISE) { $PSScriptRoot = Split-Path -Path $psISE.CurrentFile.FullPath} #In case running in psISE -if(!$PSScriptRoot){ $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent } # or older PS -#Set location of nf-interpreter top-level -$nfRoot = "$PSScriptRoot\.." -$zipRoot = "$nfRoot\zips\" +[CmdletBinding(SupportsShouldProcess = $true)] +param ( + [Parameter(HelpMessage = "Path to the folder where the tool is to be installed.")][string]$Path, + [Parameter(HelpMessage = "GNU GCC version requested.")][string]$Version, + [switch]$force = $false +) + +# set default GNU GCC version +if ([string]::IsNullOrEmpty($Version)) { + $Version = "9-2020-q2-update" +} + + +# check if running on Azure Pipelines by looking at this two environment variables +$IsAzurePipelines = $env:Agent_HomeDirectory -and $env:Build_BuildNumber + +if ($IsAzurePipelines) { + $zipRoot = "$env:Agent_TempDirectory" +} +else { + #Set location of nf-interpreter top-level + $nfRoot = "$PSScriptRoot\.." + $zipRoot = "$nfRoot\zips" + + # Create directory for zip files if necessary + mkdir -Force $zipRoot | Out-Null +} + +if ([string]::IsNullOrEmpty($Path) -or $force) { + # no path requested + # check for NF_TOOLS_PATH + if ($env:NF_TOOLS_PATH) { + $Path = $env:NF_TOOLS_PATH + } + else { + # use default + $Path = 'C:\nftools' + } + + # append the tool path + $Path = $Path + "\GNU_Tools_ARM_Embedded\$Version" +} # check if path already exists -$GnuGccPathExists = Test-Path $env:GNU_GCC_TOOLCHAIN_PATH -ErrorAction SilentlyContinue +$gnuGccPathExists = Test-Path $Path -ErrorAction SilentlyContinue -If($GnuGccPathExists -eq $False) -{ - Write-Host "Downloading ARM GNU GCC toolchain..." - - $url = "https://bintray.com/nfbot/internal-build-tools/download_file?file_path=gcc-arm-none-eabi-9-2019-q4-update-win32.7z" +# download, if needed +If ($gnuGccPathExists -eq $False -or $force) { + $url = "https://bintray.com/nfbot/internal-build-tools/download_file?file_path=gcc-arm-none-eabi-$Version-win32.7z" $output = "$zipRoot\gcc-arm.7z" - - # Stop security tripping us up - [Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls" - # Create directory for zip files if necessary - md -Force $zipRoot | Out-Null - - # download 7zip with toolchain - (New-Object Net.WebClient).DownloadFile($url, $output) - - # Install 7Zip4PowerShell module from PSGallery if not already installed - Install-Module -Name 7Zip4Powershell -RequiredVersion 1.8.0 -Scope CurrentUser - - Write-Host "Installing ARM GNU GCC toolchain..." - - # unzip toolchain - Expand-7Zip -ArchiveFileName $output -TargetPath $env:GNU_GCC_TOOLCHAIN_PATH + # Don't download again if already exists + if (![System.IO.File]::Exists($output) -or $force) { + "Download URL is: '$url'" | Write-Host -ForegroundColor White + + "Downloading ARM GNU GCC toolchain..." | Write-Host -ForegroundColor White -NoNewline + + # Stop security tripping us up + [Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls" + + # download 7zip with toolchain + (New-Object Net.WebClient).DownloadFile($url, $output) + + "OK" | Write-Host -ForegroundColor Green + } + + # unzip to install path, if not on Azure + if ($IsAzurePipelines -eq $False) { + # Install 7Zip4PowerShell module from PSGallery if not already installed + Install-Module -Name 7Zip4Powershell -RequiredVersion 1.10.0 -Scope CurrentUser + + "Installing ARM GNU GCC toolchain..." | Write-Host -ForegroundColor White -NoNewline + + # unzip toolchain + Expand-7Zip -ArchiveFileName $output -TargetPath $Path > $null + + "OK" | Write-Host -ForegroundColor Green + } +} +else { + "Skipping install of ARM GNU GCC toolchain" | Write-Host -ForegroundColor Yellow +} + +# set env variable, if not on Azure +if ($IsAzurePipelines -eq $False) { + # need to replace forward slash for paths to work with GCC and CMake + $Path = "$Path".Replace('\', '/') + + $env:GNU_GCC_TOOLCHAIN_PATH = $Path + # this call can fail if the script is not run with appropriate permissions + [System.Environment]::SetEnvironmentVariable("GNU_GCC_TOOLCHAIN_PATH", $env:GNU_GCC_TOOLCHAIN_PATH, "User") + + "Set User Environment GNU_GCC_TOOLCHAIN_PATH='" + $env:GNU_GCC_TOOLCHAIN_PATH + "'" | Write-Host -ForegroundColor Yellow } diff --git a/install-scripts/install-cmake.ps1 b/install-scripts/install-cmake.ps1 new file mode 100644 index 0000000000..744c670244 --- /dev/null +++ b/install-scripts/install-cmake.ps1 @@ -0,0 +1,32 @@ +# Copyright (c) .NET Foundation and Contributors +# See LICENSE file in the project root for full license information. + +# This PS installs CMake + +# requires this module +Install-Module -Name WebKitDev -Scope CurrentUser + +# default version is: +[version]$version="3.15.7" + +# check if CMake is installed +$cmake = (Get-Command "cmake.exe" -ErrorAction SilentlyContinue) +if($cmake) +{ + if($cmake.Version -ge $version) + { + "Skipping instal of CMake. Found v$version" | Write-Host -ForegroundColor Yellow + + exit 0 + } +} + +"Installing CMake v$version..." | Write-Host -ForegroundColor White + +$url = ('https://cmake.org/files/v{0}.{1}/cmake-{0}.{1}.{2}-win64-x64.msi' -f $version.Major, $version.Minor, $version.Build); + +$options = @( + 'ADD_CMAKE_TO_PATH="System"' +); + +Install-FromMsi -Name 'cmake' -Url $url -Options $options diff --git a/install-scripts/install-esp32-idf.ps1 b/install-scripts/install-esp32-idf.ps1 index 7bfd95a108..b04648eeff 100644 --- a/install-scripts/install-esp32-idf.ps1 +++ b/install-scripts/install-esp32-idf.ps1 @@ -1,45 +1,119 @@ +# Copyright (c) .NET Foundation and Contributors +# See LICENSE file in the project root for full license information. + # This PS installs IDF esp32 sdk -if($psISE) { $PSScriptRoot = Split-Path -Path $psISE.CurrentFile.FullPath} #In case running in psISE -if(!$PSScriptRoot){ $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent } # or older PS -#Set location of nf-interpreter top-level -$nfRoot = "$PSScriptRoot\.." -$zipRoot = "$nfRoot\zips\" +[CmdletBinding(SupportsShouldProcess = $true)] +param ( + [Parameter(HelpMessage = "Path to the folder where the tool is to be installed.")][string]$Path, + [switch]$force = $false +) -# check if path already exists -$Esp32IdfPathExists = Test-Path $env:ESP32_IDF_PATH -ErrorAction SilentlyContinue +$idfVersion = "esp-idf-v3.3.1" -If($Esp32IdfPathExists -eq $False) -{ - $url = "https://dl.espressif.com/dl/esp-idf/releases/esp-idf-v3.3.1.zip" - $output = "$zipRoot\esp-idf-v3.3.1.zip" +# check if running on Azure Pipelines by looking at this two environment variables +$IsAzurePipelines = $env:Agent_HomeDirectory -and $env:Build_BuildNumber - # Don't download again if already exists. User can remove from zips to force... - if(![System.IO.File]::Exists($output)){ - - Write-Host "Downloading ESP32 IDF..." +if ($IsAzurePipelines) { + $zipRoot = "$env:Agent_TempDirectory" - # Stop security tripping us up - [Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls" + $Path = "$env:Agent_TempDirectory\ESP32_Tools\$idfVersion" +} +else { + #Set location of nf-interpreter top-level + $nfRoot = "$PSScriptRoot\.." + $zipRoot = "$nfRoot\zips" + + # Create directory for zip files if necessary + mkdir -Force $zipRoot | Out-Null +} + +if ([string]::IsNullOrEmpty($Path) -or $force) { + # no path requested + # check for NF_TOOLS_PATH + if ($env:NF_TOOLS_PATH) { + $Path = $env:NF_TOOLS_PATH + } + else { + # use default + $Path = 'C:\nftools' + } + + $finalPath = $Path + "\$idfVersion" + + # check if path already exists + $esp32IdfPathExists = Test-Path $finalPath -ErrorAction SilentlyContinue +} +else { + # check if path already exists + $esp32IdfPathExists = Test-Path $Path -ErrorAction SilentlyContinue + + # need this here for the replacements ahead + $finalPath = $Path +} + +If ($esp32IdfPathExists -eq $False -or $force) { + $url = "https://dl.espressif.com/dl/esp-idf/releases/$idfVersion.zip" + $output = "$zipRoot\esp-idf.zip" - # Create directory for zip files if necessary - md -Force $zipRoot | Out-Null + # Don't download again if already exists + if (![System.IO.File]::Exists($output) -or $force) { + "Downloading ESP32 IDF..." | Write-Host -ForegroundColor White -NoNewline + # Stop security tripping us up + [Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls" + # download zip with Espressif IDF (New-Object Net.WebClient).DownloadFile($url, $output) + + "OK" | Write-Host -ForegroundColor Green } - Write-Host "Installing Espressif IDF @ '$env:ESP32_TOOLS_PATH'..." + # unzip to install path, if not on Azure + if ($IsAzurePipelines -eq $False) { + "Installing Espressif IDF @ '$Path'..." | Write-Host -ForegroundColor White -NoNewline + + # unzip + Expand-Archive -Path $output -DestinationPath $Path - # unzip - Expand-Archive $output -DestinationPath $env:ESP32_TOOLS_PATH + "OK" | Write-Host -ForegroundColor Green + } + + # set path destination after expand operation + $Path = $finalPath } -else -{ - Write-Warning ("Skiping instal of Espressif IDF") +else { + "Skipping install of Espressif IDF" | Write-Host -ForegroundColor Yellow + + # set path destination after expand operation + $Path = $finalPath } -Write-Host "Installing python pyserial..." -# Make sure serial package is installed in python otherwise -# the esptool.py tool won't run -python -m pip install pyserial --upgrade pip +# set env variable, if not on Azure +if ($IsAzurePipelines -eq $False) { + # need to replace forward slash for paths to work with GCC and CMake + $Path = "$Path".Replace('\', '/') + + $env:ESP32_IDF_PATH = $Path + # this call can fail if the script is not run with appropriate permissions + [System.Environment]::SetEnvironmentVariable("ESP32_IDF_PATH", $env:ESP32_IDF_PATH, "User") + + "Set User Environment ESP32_IDF_PATH='" + $env:ESP32_IDF_PATH + "'" | Write-Host -ForegroundColor Yellow +} + +# install python pyserial, if not on Azure +if ($IsAzurePipelines -eq $False) { + "Installing python pyserial..." | Write-Host -ForegroundColor White + + # Make sure serial package is installed in python otherwise + # the esptool.py tool won't run + python -m pip install pyserial --upgrade pip +} + +# on Azure, adjust IDF path +if ($IsAzurePipelines -eq $True) { + # need to replace forward slash for paths to work with GCC and CMake + $tempDirPath = "$Path".Replace('\', '/') + + Write-Host "$("##vso[task.setvariable variable=ESP32_IDF_PATH]")$tempDirPath" +} diff --git a/install-scripts/install-esp32-libs.ps1 b/install-scripts/install-esp32-libs.ps1 index 8108ad6346..093e5d0ee7 100644 --- a/install-scripts/install-esp32-libs.ps1 +++ b/install-scripts/install-esp32-libs.ps1 @@ -1,42 +1,95 @@ +# Copyright (c) .NET Foundation and Contributors +# See LICENSE file in the project root for full license information. + # This PS installs the pre-compiled EPS32 libraries from our Bintray repository -if($psISE) { $PSScriptRoot = Split-Path -Path $psISE.CurrentFile.FullPath} #In case running in psISE -if(!$PSScriptRoot){ $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent } # or older PS -#Set location of nf-interpreter top-level -$nfRoot = "$PSScriptRoot\.." -$zipRoot = "$nfRoot\zips\" +[CmdletBinding(SupportsShouldProcess = $true)] +param ( + [Parameter(HelpMessage = "Path to the folder where the tool is to be installed.")][string]$Path, + [switch]$force = $false +) + +$libsVersion = "libs-v3.3.1" + +# check if running on Azure Pipelines by looking at this two environment variables +$IsAzurePipelines = $env:Agent_HomeDirectory -and $env:Build_BuildNumber + +if ($IsAzurePipelines) { + $zipRoot = "$env:Agent_TempDirectory" + + $Path = "$env:Agent_TempDirectory\ESP32_Tools\libs" +} +else { + #Set location of nf-interpreter top-level + $nfRoot = "$PSScriptRoot\.." + $zipRoot = "$nfRoot\zips" + + # Create directory for zip files if necessary + mkdir -Force $zipRoot | Out-Null +} + +if ([string]::IsNullOrEmpty($Path) -or $force) { + # no path requested + # check for NF_TOOLS_PATH + if ($env:NF_TOOLS_PATH) { + $Path = $env:NF_TOOLS_PATH + } + else { + # use default + $Path = 'C:\nftools' + } + + $Path = $Path + "\$libsVersion" +} # check if path already exists -$ESP32LibPathExists = Test-Path $env:ESP32_LIBS_PATH -ErrorAction SilentlyContinue +$esp32LibPathExists = Test-Path $Path -ErrorAction SilentlyContinue -If($ESP32LibPathExists -eq $False) -{ - $url = "https://bintray.com/nfbot/internal-build-tools/download_file?file_path=IDF_libs-v3.3.1.zip" - $output = "$zipRoot\IDF_libs-v3.3.1.zip" +If ($esp32LibPathExists -eq $False -or $force) { + $url = "https://bintray.com/nfbot/internal-build-tools/download_file?file_path=IDF_$libsVersion.zip" + $output = "$zipRoot\esp-idf-libs.zip" # Don't download again if already exists. User can remove from zips to force... - if(![System.IO.File]::Exists($output)){ - - Write-Host "Downloading ESP32 pre-compiled libs..." + if (![System.IO.File]::Exists($output) -or $force) { + "Downloading ESP32 pre-compiled libs..." | Write-Host -ForegroundColor White -NoNewline # Stop security tripping us up [Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls" - # Create directory for zip files if necessary - md -Force $zipRoot | Out-Null - # download zip IDF (New-Object Net.WebClient).DownloadFile($url, $output) } - Write-Host "Installing ESP32 pre-compiled libs @ '$env:ESP32_LIBS_PATH'..." - - # unzip libs - #Expand-7Zip -ArchiveFileName $output -TargetPath $env:ESP32_LIBS_PATH - #unzip using PowerShell 5+ inbuilt command - Expand-Archive -Path $output -DestinationPath $env:ESP32_LIBS_PATH + # unzip to install path, if not on Azure + if ($IsAzurePipelines -eq $False) { + "Installing ESP32 pre-compiled libs @ '$Path'..." | Write-Host -ForegroundColor White -NoNewline + + # unzip + Expand-Archive -Path $output -DestinationPath $Path + + "OK" | Write-Host -ForegroundColor Green + } +} +else { + "Skipping install of ESP32 pre-compiled libs" | Write-Host -ForegroundColor Yellow +} + +# set env variable, if not on Azure +if ($IsAzurePipelines -eq $False) { + # need to replace forward slash for paths to work with GCC and CMake + $Path = "$Path".Replace('\', '/') + + $env:ESP32_LIBS_PATH = $Path + # this call can fail if the script is not run with appropriate permissions + [System.Environment]::SetEnvironmentVariable("ESP32_LIBS_PATH", $env:ESP32_LIBS_PATH, "User") + + "Set User Environment ESP32_LIBS_PATH='" + $env:ESP32_LIBS_PATH + "'" | Write-Host -ForegroundColor Yellow } -else -{ - Write-Warning ("Skiping instal of ESP32 pre-compiled libs") + +# on Azure, adjust libs path +if ($IsAzurePipelines -eq $True) { + # need to replace forward slash for paths to work with GCC and CMake + $tempDirPath = "$Path".Replace('\', '/') + + Write-Host "$("##vso[task.setvariable variable=ESP32_LIBS_PATH]")$tempDirPath" } diff --git a/install-scripts/install-esp32-openocd.ps1 b/install-scripts/install-esp32-openocd.ps1 index a3fabf0149..5995af3f86 100644 --- a/install-scripts/install-esp32-openocd.ps1 +++ b/install-scripts/install-esp32-openocd.ps1 @@ -1,42 +1,73 @@ +# Copyright (c) .NET Foundation and Contributors +# See LICENSE file in the project root for full license information. + # This PS installs the OpenOCD ESP32 toolchain from Espressif downloads repository -# if it's not already available at ESP32_TOOLS_PATH\openocd-esp32 -if($psISE) { $PSScriptRoot = Split-Path -Path $psISE.CurrentFile.FullPath} #In case running in psISE -if(!$PSScriptRoot){ $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent } # or older PS +[CmdletBinding(SupportsShouldProcess = $true)] +param ( + [Parameter(HelpMessage = "Path to the folder where the tool is to be installed.")][string]$Path, + [switch]$force = $false +) + #Set location of nf-interpreter top-level $nfRoot = "$PSScriptRoot\.." -$zipRoot = "$nfRoot\zips\" +$zipRoot = "$nfRoot\zips" -$env:ESP32_OPENOCD_PATH=($env:ESP32_TOOLS_PATH+'\openocd-esp32') -# check if path already exists -$OpenOCDPathExists = Test-Path $env:ESP32_OPENOCD_PATH -ErrorAction SilentlyContinue +# Create directory for zip files if necessary +mkdir -Force $zipRoot | Out-Null + +if ([string]::IsNullOrEmpty($Path) -or $force) { + # no path requested + # check for NF_TOOLS_PATH + if ($env:NF_TOOLS_PATH) { + $Path = $env:NF_TOOLS_PATH + } + else { + # use default + $Path = "C:\nftools" + } -If($OpenOCDPathExists -eq $False) -{ - Write-Host "Downloading OpenOCD for ESP32 ..." + # append the tool path + $Path = $Path + "\openocd-esp32" +} + +# check if path already exists +$openOCDPathExists = Test-Path $Path -ErrorAction SilentlyContinue +If ($openOCDPathExists -eq $False -or $force) { $url = "https://github.com/espressif/openocd-esp32/releases/download/v0.10.0-esp32-20190212/openocd-esp32-win32-0.10.0-esp32-20190212.zip" $output = "$zipRoot\openocd-esp32.zip" + + # Don't download again if already exists + if (![System.IO.File]::Exists($output) -or $force) { + "Downloading OpenOCD for ESP32 ..." | Write-Host -ForegroundColor White -NoNewline - # Stop security tripping us up - [Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls" + # Stop security tripping us up + [Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls" - # Create directory for zip files if necessary - md -Force $zipRoot | Out-Null - - # download zip with OpenOcd tool - (New-Object Net.WebClient).DownloadFile($url, $output) + # Create directory for zip files if necessary + mkdir -Force $zipRoot | Out-Null + + # download zip with OpenOcd tool + (New-Object Net.WebClient).DownloadFile($url, $output) + + "OK" | Write-Host -ForegroundColor Green + } - Write-Host "Installing OpenOCD @ '$env:ESP32_OPENOCD_PATH'..." + "Installing OpenOCD for ESP32 @ '$Path'..." | Write-Host -ForegroundColor White -NoNewline # unzip - #Expand-Archive $output -DestinationPath $env:ESP32_OPENOCD_PATH - - Expand-Archive $output -DestinationPath "$PSScriptRoot\openocd-esp32" - Move-Item -Path ("$PSScriptRoot\openocd-esp32\openocd-esp32\") -Destination $env:ESP32_OPENOCD_PATH - Remove-Item "$PSScriptRoot\openocd-esp32" -Force + # set the destination path one level up to place it at the intended directory + Expand-Archive -Path $output -DestinationPath "$Path\.." + + "OK" | Write-Host -ForegroundColor Green } -else -{ - Write-Warning ("Skiping instal of OpenOCD") +else { + "Skipping instal of OpenOCD for ESP32" | Write-Host -ForegroundColor Yellow } + +$env:ESP32_OPENOCD_PATH = $Path +# this call can fail if the script is not run with appropriate permissions +[System.Environment]::SetEnvironmentVariable("ESP32_OPENOCD_PATH", $env:ESP32_OPENOCD_PATH, "User") + +"Set User Environment ESP32_OPENOCD_PATH='" + $env:ESP32_OPENOCD_PATH + "'" | Write-Host -ForegroundColor Yellow diff --git a/install-scripts/install-esp32-toolchain.ps1 b/install-scripts/install-esp32-toolchain.ps1 index 351a95b9a8..427890fb7e 100644 --- a/install-scripts/install-esp32-toolchain.ps1 +++ b/install-scripts/install-esp32-toolchain.ps1 @@ -1,45 +1,102 @@ +# Copyright (c) .NET Foundation and Contributors +# See LICENSE file in the project root for full license information. + # This PS installs the xtensa ESP32 toolchain from Espressif downloads repository -# if it's not already available at ESP32_TOOLCHAIN_PATH -if($psISE) { $PSScriptRoot = Split-Path -Path $psISE.CurrentFile.FullPath} #In case running in psISE -if(!$PSScriptRoot){ $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent } # or older PS -#Set location of nf-interpreter top-level -$nfRoot = "$PSScriptRoot\.." -$zipRoot = "$nfRoot\zips\" +[CmdletBinding(SupportsShouldProcess = $true)] +param ( + [Parameter(HelpMessage = "Path to the folder where the tool is to be installed.")][string]$Path, + [switch]$force = $false +) + +# check if running on Azure Pipelines by looking at this two environment variables +$IsAzurePipelines = $env:Agent_HomeDirectory -and $env:Build_BuildNumber -# check if path already exists -$XtensaPathExists = Test-Path $env:ESP32_TOOLCHAIN_PATH -ErrorAction SilentlyContinue +if ($IsAzurePipelines) { + $zipRoot = "$env:Agent_TempDirectory" + + $Path = "$env:Agent_TempDirectory\ESP32_Tools" +} +else { + #Set location of nf-interpreter top-level + $nfRoot = "$PSScriptRoot\.." + $zipRoot = "$nfRoot\zips" -If($XtensaPathExists -eq $False) -{ + # Create directory for zip files if necessary + mkdir -Force $zipRoot | Out-Null +} + +if ([string]::IsNullOrEmpty($Path) -or $force) { + # no path requested + # check for NF_TOOLS_PATH + if ($env:NF_TOOLS_PATH) { + $Path = $env:NF_TOOLS_PATH + } + else { + # use default + $Path = 'C:\nftools' + } + + $finalPath = $Path + "\xtensa-esp32-elf" + + # check if path already exists + $xtensaPathExists = Test-Path $finalPath -ErrorAction SilentlyContinue +} +else { + # check if path already exists + $xtensaPathExists = Test-Path $Path -ErrorAction SilentlyContinue + + # need this here for the replacements ahead + $finalPath = $Path +} + +If ($xtensaPathExists -eq $False -or $force) { # Download xtensa ESP32 toolchain and install $url = "https://dl.espressif.com/dl/xtensa-esp32-elf-win32-1.22.0-80-g6c4433a-5.2.0.zip" $output = "$zipRoot\xtensa-esp32-elf-win32.zip" - # Don't download again if already exists. User can remove from zips to force... - if(![System.IO.File]::Exists($output)){ - Write-Host "Downloading Xtensa ESP32 toolchain..." - - # Stop security tripping us up - [Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls" + # Don't download again if already exists + if (![System.IO.File]::Exists($output) -or $force) { + "Downloading Xtensa ESP32 toolchain..." | Write-Host -ForegroundColor White -NoNewline - # Create directory for zip files if necessary - md -Force $zipRoot | Out-Null + # Stop security tripping us up + [Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls" # download zip with toolchain (New-Object Net.WebClient).DownloadFile($url, $output) + + "OK" | Write-Host -ForegroundColor Green } - Write-Host "Installing Xtensa ESP32 toolchain @ '$env:ESP32_TOOLCHAIN_PATH'..." - - # unzip toolchain (This used the older of the two Expand-7Zip addons) - #Expand-7Zip -ArchiveFileName $output -TargetPath $env:ESP32_TOOLCHAIN_PATH + # unzip to install path, if not on Azure + if ($IsAzurePipelines -eq $False) { + "Installing Xtensa ESP32 toolchain @ '$Path'..." | Write-Host -ForegroundColor White -NoNewline + + #unzip using PowerShell 5+ inbuilt command + Expand-Archive -Path $output -DestinationPath $Path + + "OK" | Write-Host -ForegroundColor Green - #unzip using PowerShell 5+ inbuilt command - Expand-Archive -Path $output -DestinationPath $env:ESP32_TOOLCHAIN_PATH + # set path destination after expand operation + $Path = $finalPath + } +} +else { + "Skipping instal of Xtensa ESP32 toolchain" | Write-Host -ForegroundColor Yellow + + # set path destination after expand operation + $Path = $finalPath } -else -{ - Write-Warning ("Skiping instal of Xtensa ESP32 toolchain") + +# set env variable, if not on Azure +if ($IsAzurePipelines -eq $False) { + # need to replace forward slash for paths to work with GCC and CMake + $Path = "$Path".Replace('\', '/') + + $env:ESP32_TOOLCHAIN_PATH = $Path + # this call can fail if the script is not run with appropriate permissions + [System.Environment]::SetEnvironmentVariable("ESP32_TOOLCHAIN_PATH", $env:ESP32_TOOLCHAIN_PATH, "User") + + "Set User Environment ESP32_TOOLCHAIN_PATH='" + $env:ESP32_TOOLCHAIN_PATH + "'" | Write-Host -ForegroundColor Yellow } diff --git a/install-scripts/install-esp32-tools.ps1 b/install-scripts/install-esp32-tools.ps1 index 6a60def974..5f81bf3d17 100644 --- a/install-scripts/install-esp32-tools.ps1 +++ b/install-scripts/install-esp32-tools.ps1 @@ -1,170 +1,67 @@ +# Copyright (c) .NET Foundation and Contributors +# See LICENSE file in the project root for full license information. + [CmdletBinding(SupportsShouldProcess = $true)] param ( -[Parameter(HelpMessage="Please enter the COM port for ESP32 flash utility [e.g. COM1 or /dev/ttyUSB0].",Position=2)][string]$COMPORT, -[Parameter(HelpMessage="Enter the path to the folder where the tools should be installed.",Position=3)][string]$Path, -[switch]$force = $false + [Parameter(HelpMessage = "Enter the path to the folder where the tools should be installed.")][string]$Path, + [Parameter(HelpMessage = "Please enter the COM port for ESP32 flash utility [e.g. COM1].")][string]$COMPort, + [switch]$force = $false ) - -[Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls" -Write-Host "Install Tools to build nanoCLR into default folders and configure json files ..." -$env:BOARD_NAME = "ESP32_WROOM_32" - -If([string]::IsNullOrEmpty($COMPORT)) -{ - Write-Warning ("Please use parameter -C to set COM port for ESP32 flash utility [e.g. -C COM1], or edit tasks.json") -} - -$env:NANOCLR_COMPORT = $COMPORT - -if($psISE) { $PSScriptRoot = Split-Path -Path $psISE.CurrentFile.FullPath} #In case running in psISE -if(!$PSScriptRoot){ $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent } # or older PS - -#Set location of nf-interpreter top-level -$nfRoot = "$PSScriptRoot\.." - -# create build folder if necessary -md -Force "$nfRoot\build" | Out-Null - -#Write-Host $PSScriptRoot -#Write-Host $nfRoot -Write-Host "BOARD_NAME=" $env:BOARD_NAME - -If(-Not [string]::IsNullOrEmpty($Path)) -{ - # user has requested install on a specific path - - # force update of base path for tools - $env:ESP32_TOOLS_PATH = $Path - Write-Host ("Set User Environment ESP32_TOOLS_PATH='"+$env:ESP32_TOOLS_PATH+"'") - [System.Environment]::SetEnvironmentVariable("ESP32_TOOLS_PATH", $env:ESP32_TOOLS_PATH, "User") - - # set flag to force updating all tool paths - $PathSet = $true -} -else -{ - # no path requested, set to default location - $env:ESP32_TOOLS_PATH= 'C:\ESP32_TOOLS' - Write-Host ("Set User Environment ESP32_TOOLS_PATH='"+$env:ESP32_TOOLS_PATH+"'") - [System.Environment]::SetEnvironmentVariable("ESP32_TOOLS_PATH", $env:ESP32_TOOLS_PATH, "User") - - # clear flag to force updating all tool paths - $PathSet = $false +If ([string]::IsNullOrEmpty($COMPort)) { + "Please use parameter -COMPort to set COM port for ESP32 flash utility [e.g. -COMPort COM1], or edit tasks.json" | Write-Host -ForegroundColor Yellow } -# set env var for all tools paths -Write-Host "Set User Environment Variables (can be slow if many Applications running)..." +$env:NANOCLR_COMPORT = $COMPort -If([string]::IsNullOrEmpty($env:ESP32_TOOLCHAIN_PREFIX) -or $PathSet -or $force) -{ - $env:ESP32_TOOLCHAIN_PREFIX= ($env:ESP32_TOOLS_PATH) - Write-Host ("Set User Environment ESP32_TOOLCHAIN_PREFIX='"+$env:ESP32_TOOLCHAIN_PREFIX+"'") - [System.Environment]::SetEnvironmentVariable("ESP32_TOOLCHAIN_PREFIX", $env:ESP32_TOOLCHAIN_PREFIX, "User") -} +# need this check here as the path can be passed with an empty string +if ([string]::IsNullOrEmpty($Path) -or $force) { -If([string]::IsNullOrEmpty($env:ESP32_TOOLCHAIN_PATH) -or $PathSet -or $force) -{ - $env:ESP32_TOOLCHAIN_PATH= ($env:ESP32_TOOLS_PATH) - Write-Host ("Set User Environment ESP32_TOOLCHAIN_PATH='"+$env:ESP32_TOOLCHAIN_PATH+"'") - [System.Environment]::SetEnvironmentVariable("ESP32_TOOLCHAIN_PATH", $env:ESP32_TOOLCHAIN_PATH, "User") + # check if there is already a path set + if($env:NF_TOOLS_PATH) + { + $Path = $env:NF_TOOLS_PATH + } + else { + $Path = "C:\nftools" + } } -If([string]::IsNullOrEmpty($env:ESP32_LIBS_PATH) -or $PathSet -or $force) -{ - $env:ESP32_LIBS_PATH=($env:ESP32_TOOLS_PATH+'\libs-v3.3.1') - Write-Host ("Set User Environment ESP32_LIBS_PATH='"+$env:ESP32_LIBS_PATH+"'") - [System.Environment]::SetEnvironmentVariable("ESP32_LIBS_PATH", $env:ESP32_LIBS_PATH, "User") -} +"Set User Environment NF_TOOLS_PATH='" + $Path + "'" | Write-Host -ForegroundColor White -If([string]::IsNullOrEmpty($env:ESP32_IDF_PATH) -or [string]::IsNullOrEmpty($env:IDF_PATH) -or $PathSet -or $force) -{ - $env:IDF_PATH=$env:ESP32_IDF_PATH=($env:ESP32_TOOLS_PATH+'\esp-idf-v3.3.1') - Write-Host ("Set User Environment ESP32_IDF_PATH='"+$env:ESP32_IDF_PATH+"'") - Write-Host ("Set User Environment IDF_PATH='"+$env:IDF_PATH+"'") - [System.Environment]::SetEnvironmentVariable("ESP32_IDF_PATH", $env:ESP32_IDF_PATH, "User") - [System.Environment]::SetEnvironmentVariable("IDF_PATH", $env:IDF_PATH, "User") -} +# set environment variable +$env:NF_TOOLS_PATH = $Path +[System.Environment]::SetEnvironmentVariable("NF_TOOLS_PATH", $Path, "User") -If([string]::IsNullOrEmpty($env:NINJA_PATH) -or $PathSet -or $force) -{ - $env:NINJA_PATH= ($env:ESP32_TOOLS_PATH+'\ninja') - Write-Host ("Set User Environment NINJA_PATH='"+$env:NINJA_PATH+"'") - [System.Environment]::SetEnvironmentVariable("NINJA_PATH", $env:NINJA_PATH, "User") -} - -# call the script for each of the tools -Invoke-Expression -Command $PSScriptRoot\install-esp32-toolchain.ps1 -Invoke-Expression -Command $PSScriptRoot\install-esp32-libs.ps1 -Invoke-Expression -Command $PSScriptRoot\install-esp32-idf.ps1 -Invoke-Expression -Command $PSScriptRoot\install-ninja.ps1 -Invoke-Expression -Command $PSScriptRoot\install-esp32-openocd.ps1 - -# add Ninja to the path # this call can fail if the script is not run with appropriate permissions -Write-Host ("Trying to add Ninja to the path "+$env:NINJA_PATH) -Invoke-Expression -Command "$PSScriptRoot\Set-PathVariable.ps1 -NewLocation $env:NINJA_PATH" - -$filePathExists = Test-Path "$nfRoot\cmake-variants.json" -ErrorAction SilentlyContinue -If($filePathExists -eq $False -or $force) -{ - Write-Host ("Create .\cmake-variants.json with install paths from .\cmake-variants.TEMPLATE-ESP32.json") - Copy-Item "$nfRoot\cmake-variants.TEMPLATE-ESP32.json" -Destination "$nfRoot\cmake-variants.json" -Force - $variants = (Get-Content "$nfRoot\cmake-variants.json") - $variants = $variants.Replace('', $env:ESP32_IDF_PATH.ToString().Replace("\", "/")) - $variants = $variants.Replace('', $env:ESP32_LIBS_PATH.ToString().Replace("\", "/")) - $variants = $variants.Replace('', $env:ESP32_TOOLCHAIN_PREFIX.ToString().Replace("\", "/")) - Set-Content -Path "$nfRoot\cmake-variants.json" -Value $variants -} +[System.Environment]::SetEnvironmentVariable("NF_TOOLS_PATH", $Path, "Machine") -$buildFolderPath = Resolve-Path $nfRoot\build - -$filePathExists = Test-Path "$nfRoot\.vscode\tasks.json" -ErrorAction SilentlyContinue -#$filePathExists=$False -If($filePathExists -eq $False -or $force) -{ - Write-Host ("Create .\.vscode\tasks.json with install paths from .\vscode\tasks.TEMPLATE-ESP32.json") - Copy-Item "$nfRoot\.vscode\tasks.TEMPLATE-ESP32.json" -Destination "$nfRoot\.vscode\tasks.json" -Force - $tasks = (Get-Content "$nfRoot\.vscode\tasks.json") - $tasks = $tasks.Replace('', $env:ESP32_IDF_PATH.ToString().Replace("\", "/")) - $tasks = $tasks.Replace('', $env:ESP32_LIBS_PATH.ToString().Replace("\", "/")) - $tasks = $tasks.Replace('', $buildFolderPath.ToString().Replace("\", "/")) - $tasks = $tasks.Replace('', $env:ESP32_TOOLCHAIN_PREFIX.ToString().Replace("\", "/")) - - # Update the COMPORT placeholder if the paramter is supplied. - If(![string]::IsNullOrEmpty($COMPORT)) - { - $tasks = $tasks.Replace('', $env:NANOCLR_COMPORT.ToString()) - } - Set-Content -Path "$nfRoot\.vscode\tasks.json" -Value $tasks +# need to pass the 'force' switch? +if ($force) { + $commandArgs = " -force" } -$filePathExists = Test-Path "$nfRoot\.vscode\launch.json" -ErrorAction SilentlyContinue -#$filePathExists=$False -If($filePathExists -eq $False -or $force) -{ - Write-Host "Create .\.vscode\launch.json with install paths from .\vscode\launch.TEMPLATE-ESP32.json" - Copy-Item "$nfRoot\.vscode\launch.TEMPLATE-ESP32.json" -Destination "$nfRoot\.vscode\launch.json" -Force - - $launch = (Get-Content "$nfRoot\.vscode\launch.json") - $launch = $launch.Replace('', $buildFolderPath.ToString().Replace("\", "/")) - $launch = $launch.Replace('', $env:ESP32_OPENOCD_PATH.Replace("\", "/")) - $launch = $launch.Replace('', $env:ESP32_TOOLCHAIN_PATH.Replace("\", "/")) - Set-Content -Path "$nfRoot\.vscode\launch.json" -Value $launch -} +# call the script for each of the tools +Invoke-Expression $PSScriptRoot\install-cmake.ps1 +Invoke-Expression "$PSScriptRoot\install-esp32-toolchain.ps1 $commandArgs" +Invoke-Expression "$PSScriptRoot\install-esp32-libs.ps1 $commandArgs" +Invoke-Expression "$PSScriptRoot\install-esp32-idf.ps1 $commandArgs" +Invoke-Expression "$PSScriptRoot\install-ninja.ps1 $commandArgs" +Invoke-Expression "$PSScriptRoot\install-esp32-openocd.ps1 $commandArgs" <# .SYNOPSIS - Install the default ESP32 tools and libraries neede to build nanoFramework, and setup the build environemnt. + Install the default ESP32 tools and libraries needed to build nanoFramework, and setup the build environment. .DESCRIPTION - Power Shell Script to install the default tools to build nanoFramework, including setting the machine path and other environment variables needed for ESP32 DevKitC. Use the -Force paramter to over-write existing Environment variables. -.PARAMETER COMPORT + Power Shell Script to install the default tools to build nanoFramework, including setting the machine path and other environment variables needed for ESP32 WROOM 32. + Use the -Force parameter to overwrite existing Environment variables. +.PARAMETER COMPort The COM port for NANOCLR [e.g. COM1]. .PARAMETER Path The path to the folder where the tools should be installed. .EXAMPLE .\install-esp32-tools.ps1 -COMPORT COM19 - Installs the tools for Espressive ESP32 to default path, define required envisonment variables and update VSCode files with paths and set COM19 in tasks.json + Installs the tools for Espressif ESP32 to default path, define required environment variables and update VSCode files with paths and set COM19 in tasks.json .NOTES Tested on Windows 10 Author: nanoFramework Contributors diff --git a/install-scripts/install-nf-hex2dfu.ps1 b/install-scripts/install-nf-hex2dfu.ps1 index 72cfdf8f00..c0d8b2d52f 100644 --- a/install-scripts/install-nf-hex2dfu.ps1 +++ b/install-scripts/install-nf-hex2dfu.ps1 @@ -1,21 +1,84 @@ +# Copyright (c) .NET Foundation and Contributors +# See LICENSE file in the project root for full license information. + # This PS installs nanoFramework hex2dfu command line utility +[CmdletBinding(SupportsShouldProcess = $true)] +param ( + [Parameter(HelpMessage = "Path to the folder where the tool is to be installed.", Position = 0)][string]$Path, + [switch]$force = $false +) + +# check if running on Azure Pipelines by looking at this two environment variables +$IsAzurePipelines = $env:Agent_HomeDirectory -and $env:Build_BuildNumber + +if ($IsAzurePipelines) { + $zipRoot = "$env:Agent_TempDirectory" +} +else { + #Set location of nf-interpreter top-level + $nfRoot = "$PSScriptRoot\.." + $zipRoot = "$nfRoot\zips" + + # Create directory for zip files if necessary + mkdir -Force $zipRoot | Out-Null +} + +if ([string]::IsNullOrEmpty($Path) -or $force) { + # no path requested + # check for NF_TOOLS_PATH + if ($env:NF_TOOLS_PATH) { + $Path = $env:NF_TOOLS_PATH + } + else { + # use default + $Path = 'C:\nftools' + } + + # append the tool path + $Path = $Path + "\hex2dfu" +} + # check if path already exists -$hex2dfuPathExists = Test-Path $env:HEX2DFU_PATH -ErrorAction SilentlyContinue +$hex2dfuPathExists = Test-Path $Path -ErrorAction SilentlyContinue -If($hex2dfuPathExists -eq $False) -{ - & md $($env:HEX2DFU_PATH) > $null +If ($hex2dfuPathExists -eq $False -or $force) { + # need to have the destination directory to download into + if ($IsAzurePipelines -eq $False) { + & mkdir $($Path) | Out-Null + $downloadPath = $($Path) + } + else { + $downloadPath = "$env:Agent_TempDirectory\hex2dfu" + mkdir -Force $downloadPath | Out-Null + } - Write-Host "Downloading hex2dfu..." + "Downloading hex2dfu..." | Write-Host -ForegroundColor White -NoNewline $url = "https://github.com/nanoframework/hex2dfu/releases/latest/download/hex2dfu.exe" - - $output = "$env:HEX2DFU_PATH\hex2dfu.exe" + $output = "$downloadPath\hex2dfu.exe" + # Stop security tripping us up [Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls" - # download executable with utility + # download zip with Ninja tool (New-Object Net.WebClient).DownloadFile($url, $output) + + "OK" | Write-Host -ForegroundColor Green +} +else { + "Skipping install of hex2dfu" | Write-Host -ForegroundColor Yellow +} + +# set env variable, if not on Azure +if ($IsAzurePipelines -eq $False) { + # need to replace forward slash for paths to work with GCC and CMake + $Path = "$Path".Replace('\', '/') + + $env:HEX2DFU_PATH = $Path + # this call can fail if the script is not run with appropriate permissions + [System.Environment]::SetEnvironmentVariable("HEX2DFU_PATH", $env:HEX2DFU_PATH, "User") + + "Set User Environment HEX2DFU_PATH='" + $env:HEX2DFU_PATH + "'" | Write-Host -ForegroundColor Yellow } diff --git a/install-scripts/install-nf-tools.ps1 b/install-scripts/install-nf-tools.ps1 new file mode 100644 index 0000000000..53ccb86ed4 --- /dev/null +++ b/install-scripts/install-nf-tools.ps1 @@ -0,0 +1,41 @@ +# Copyright (c) .NET Foundation and Contributors +# See LICENSE file in the project root for full license information. + +[CmdletBinding(SupportsShouldProcess = $true)] +param ( + [Parameter(Mandatory=$true)] + [ValidateSet("ESP32", "STM32", "NXP", "TI")] + [string]$TargetSeries, + [Parameter(HelpMessage = "Enter the path to the folder where the tools should be installed.")][string]$Path, + [switch]$force = $false +) + +$commandArgs = "" + +# any path set? +if (-not [string]::IsNullOrEmpty($Path)) { + $commandArgs = " -Path '$Path'" +} + +# need to pass the 'force' switch? +if ($force) { + $commandArgs += " -force" +} + +if($TargetSeries -eq "ESP32") +{ + Invoke-Expression "$PSScriptRoot\install-esp32-tools.ps1 $commandArgs" +} +elseif ($TargetSeries -eq "STM32") { + Invoke-Expression "$PSScriptRoot\install-stm32-tools.ps1 $commandArgs" +} +elseif ($TargetSeries -eq "NXP") { + Invoke-Expression "$PSScriptRoot\install-stm32-tools.ps1 $commandArgs" + Invoke-Expression "$PSScriptRoot\install-srecord.ps1 $commandArgs" +} +elseif ($TargetSeries -eq "TI") { + Invoke-Expression "$PSScriptRoot\install-stm32-tools.ps1 $commandArgs" +} +else { + # shouldn't reach here +} diff --git a/install-scripts/install-ninja.ps1 b/install-scripts/install-ninja.ps1 index 5542868ab2..75fe7ea273 100644 --- a/install-scripts/install-ninja.ps1 +++ b/install-scripts/install-ninja.ps1 @@ -1,35 +1,113 @@ +# Copyright (c) .NET Foundation and Contributors +# See LICENSE file in the project root for full license information. + # This PS installs Ninja build tool -if($psISE) { $PSScriptRoot = Split-Path -Path $psISE.CurrentFile.FullPath} #In case running in psISE -if(!$PSScriptRoot){ $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent } # or older PS -#Set location of nf-interpreter top-level -$nfRoot = "$PSScriptRoot\.." -$zipRoot = "$nfRoot\zips\" +[CmdletBinding(SupportsShouldProcess = $true)] +param ( + [Parameter(HelpMessage = "Path to the folder where the tool is to be installed.")][string]$Path, + [switch]$force = $false +) -# check if path already exists -$NinjaPathExists = Test-Path $env:NINJA_PATH -ErrorAction SilentlyContinue +# check if running on Azure Pipelines by looking at this two environment variables +$IsAzurePipelines = $env:Agent_HomeDirectory -and $env:Build_BuildNumber + +if ($IsAzurePipelines) { + $zipRoot = "$env:Agent_TempDirectory" +} +else { + #Set location of nf-interpreter top-level + $nfRoot = "$PSScriptRoot\.." + $zipRoot = "$nfRoot\zips" + + # Create directory for zip files if necessary + mkdir -Force $zipRoot | Out-Null +} + +if ([string]::IsNullOrEmpty($Path) -or $force) { + # no path requested + # check for NF_TOOLS_PATH + if ($env:NF_TOOLS_PATH) { + $Path = $env:NF_TOOLS_PATH + } + else { + # use default + $Path = 'C:\nftools' + } + + # append the tool path + $Path = $Path + "\Ninja" +} -If($NinjaPathExists -eq $False) -{ - Write-Host "Downloading Ninja..." +# check if path already exists +$ninjaPathExists = Test-Path $Path -ErrorAction SilentlyContinue - $url = "https://github.com/ninja-build/ninja/releases/download/v1.8.2/ninja-win.zip" +If ($ninjaPathExists -eq $False -or $force) { + $url = "https://github.com/ninja-build/ninja/releases/download/v1.10.0/ninja-win.zip" $output = "$zipRoot\ninja.zip" - # Stop security tripping us up - [Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls" + + # Don't download again if already exists + if (![System.IO.File]::Exists($output) -or $force) { + "Downloading Ninja..." | Write-Host -ForegroundColor White -NoNewline - # Create directory for zip files if necessary - md -Force $zipRoot | Out-Null + # Stop security tripping us up + [Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls" + + # download zip with Ninja tool + (New-Object Net.WebClient).DownloadFile($url, $output) + + "OK" | Write-Host -ForegroundColor Green + } + + # unzip to install path, if not on Azure + if ($IsAzurePipelines -eq $False) { + "Installing Ninja..." | Write-Host -ForegroundColor White -NoNewline + + # unzip tool + Expand-Archive $output -DestinationPath $Path > $null + + "OK" | Write-Host -ForegroundColor Green + } +} +else { + "Skipping install of Ninja" | Write-Host -ForegroundColor Yellow +} + +# set env variable, if not on Azure +if ($IsAzurePipelines -eq $False) { + $env:NINJA_PATH = $Path + # this call can fail if the script is not run with appropriate permissions + [System.Environment]::SetEnvironmentVariable("NINJA_PATH", $env:NINJA_PATH, "User") + + "Set User Environment NINJA_PATH='" + $env:NINJA_PATH + "'" | Write-Host -ForegroundColor Yellow +} + +# if not on Azure, add ninja to the PATH +if ($IsAzurePipelines -eq $False) { + + # check if it's already there + $ninja = (Get-Command "ninja.exe" -ErrorAction SilentlyContinue) + if ($ninja) { + # reachable, we're good + exit 0 + } - # download zip with Ninja tool - (New-Object Net.WebClient).DownloadFile($url, $output) + # add to path + try { + [Environment]::SetEnvironmentVariable( + "Path", + [Environment]::GetEnvironmentVariable("Path", "User") + ";$Path", + "User") - Write-Host "Installing Ninja..." + # this call can fail if the script is not run with appropriate permissions + [Environment]::SetEnvironmentVariable( + "Path", + [Environment]::GetEnvironmentVariable("Path", [EnvironmentVariableTarget]::Machine) + ";$Path", + "Machine") - # unzip - Expand-Archive $output -DestinationPath $env:NINJA_PATH + "Add ninja to PATH" | Write-Host -ForegroundColor White + } + catch { + "Fail to update PATH environment variable. Make sure to manually add '$Path' to the PATH." | Write-Host -ForegroundColor Red + } } -else -{ - Write-Warning ("Skiping instal of Ninja") -} \ No newline at end of file diff --git a/install-scripts/install-openocd.ps1 b/install-scripts/install-openocd.ps1 new file mode 100644 index 0000000000..8e2641f91a --- /dev/null +++ b/install-scripts/install-openocd.ps1 @@ -0,0 +1,78 @@ +# Copyright (c) .NET Foundation and Contributors +# See LICENSE file in the project root for full license information. + +# This PS installs the OpenOCD + +[CmdletBinding(SupportsShouldProcess = $true)] +param ( + [Parameter(HelpMessage = "Path to the folder where the tool is to be installed.")][string]$Path, + [switch]$force = $false +) + +#Set location of nf-interpreter top-level +$nfRoot = "$PSScriptRoot\.." +$zipRoot = "$nfRoot\zips" + +# Create directory for zip files if necessary +mkdir -Force $zipRoot | Out-Null + +if ([string]::IsNullOrEmpty($Path) -or $force) { + # no path requested + # check for NF_TOOLS_PATH + if ($env:NF_TOOLS_PATH) { + $Path = $env:NF_TOOLS_PATH + } + else { + # use default + $Path = E:\stm32_tools#"C:\nftools" + } + + # append the tool path + $Path = $Path + "\openocd" +} + +# check if path already exists +$openOCDPathExists = Test-Path $Path -ErrorAction SilentlyContinue + +If ($openOCDPathExists -eq $False -or $force) { + $url = "https://github.com/xpack-dev-tools/openocd-xpack/releases/download/v0.10.0-13/xpack-openocd-0.10.0-13-win32-x64.zip" + $output = "$zipRoot\openocd.zip" + + # Don't download again if already exists + if (![System.IO.File]::Exists($output) -or $force) { + "Downloading OpenOCD..." | Write-Host -ForegroundColor White -NoNewline + + # Stop security tripping us up + [Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls" + + # Create directory for zip files if necessary + mkdir -Force $zipRoot | Out-Null + + # download zip with OpenOcd tool + (New-Object Net.WebClient).DownloadFile($url, $output) + + "OK" | Write-Host -ForegroundColor Green + } + + "Installing OpenOCD @ '$Path'..." | Write-Host -ForegroundColor White -NoNewline + + # unzip to temp directory + Expand-Archive -Path $output -DestinationPath "$Path\temp" + + # move to final location + Get-ChildItem -Path "$Path\temp\xPack\OpenOCD\0.10.0-13" -Recurse | Move-Item -Destination "$Path" + + # remove temp directory + Remove-Item $Path\temp -Recurse -Force + + "OK" | Write-Host -ForegroundColor Green +} +else { + "Skipping instal of OpenOCD" | Write-Host -ForegroundColor Yellow +} + +$env:OPENOCD_PATH = $Path +# this call can fail if the script is not run with appropriate permissions +[System.Environment]::SetEnvironmentVariable("OPENOCD_PATH", $env:OPENOCD_PATH, "User") + +"Set User Environment OPENOCD_PATH='" + $env:OPENOCD_PATH + "'" | Write-Host -ForegroundColor Yellow diff --git a/install-scripts/install-srecord.ps1 b/install-scripts/install-srecord.ps1 new file mode 100644 index 0000000000..5cb9e9ef79 --- /dev/null +++ b/install-scripts/install-srecord.ps1 @@ -0,0 +1,93 @@ +# Copyright (c) .NET Foundation and Contributors +# See LICENSE file in the project root for full license information. + +# This PS installs srecord tool + +[CmdletBinding(SupportsShouldProcess = $true)] +param ( + [Parameter(HelpMessage = "Path to the folder where the tool is to be installed.")][string]$Path, + [switch]$force = $false +) + +# check if running on Azure Pipelines by looking at this two environment variables +$IsAzurePipelines = $env:Agent_HomeDirectory -and $env:Build_BuildNumber + +if ($IsAzurePipelines) { + $zipRoot = "$env:Agent_TempDirectory" +} +else { + #Set location of nf-interpreter top-level + $nfRoot = "$PSScriptRoot\.." + $zipRoot = "$nfRoot\zips" + + # Create directory for zip files if necessary + mkdir -Force $zipRoot | Out-Null +} + +if ([string]::IsNullOrEmpty($Path) -or $force) { + # no path requested + # check for NF_TOOLS_PATH + if ($env:NF_TOOLS_PATH) { + $Path = $env:NF_TOOLS_PATH + } + else { + # use default + $Path = 'C:\nftools' + } + + # append the tool path + $Path = $Path + "\srecord" +} + +# check if path already exists +$ninjaPathExists = Test-Path $Path -ErrorAction SilentlyContinue + +If ($ninjaPathExists -eq $False -or $force) { + $url = "https://bintray.com/nfbot/internal-build-tools/download_file?file_path=srecord-1.64-win32.zip" + $output = "$zipRoot\srecord.zip" + + # Don't download again if already exists + if (![System.IO.File]::Exists($output) -or $force) { + "Downloading SRecord..." | Write-Host -ForegroundColor White -NoNewline + + # Stop security tripping us up + [Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls" + + # download zip with Ninja tool + (New-Object Net.WebClient).DownloadFile($url, $output) + + "OK" | Write-Host -ForegroundColor Green + } + + # unzip to install path, if not on Azure + if ($IsAzurePipelines -eq $False) { + "Installing SRecord..." | Write-Host -ForegroundColor White -NoNewline + + # unzip tool + Expand-Archive $output -DestinationPath $Path > $null + + "OK" | Write-Host -ForegroundColor Green + } +} +else { + "Skipping install of SRecord" | Write-Host -ForegroundColor Yellow +} + +# set env variable, if not on Azure +if ($IsAzurePipelines -eq $False) { + # need to replace forward slash for paths to work with GCC and CMake + $Path = "$Path".Replace('\', '/') + + $env:SRECORD_PATH = $Path + # this call can fail if the script is not run with appropriate permissions + [System.Environment]::SetEnvironmentVariable("SRECORD_PATH", $env:SRECORD_PATH, "User") + + "Set User Environment SRECORD_PATH='" + $env:SRECORD_PATH + "'" | Write-Host -ForegroundColor Yellow +} + +# on Azure, adjust SRecord path +if ($IsAzurePipelines -eq $True) { + # need to replace forward slash for paths to work with GCC and CMake + $newPath = "$env:Agent_TempDirectory".Replace('\', '/') + Write-Host "$("##vso[task.setvariable variable=SRECORD_PATH]")$newPath" +} diff --git a/install-scripts/install-stm32-tools.ps1 b/install-scripts/install-stm32-tools.ps1 index 3f571202bd..26926d14e9 100644 --- a/install-scripts/install-stm32-tools.ps1 +++ b/install-scripts/install-stm32-tools.ps1 @@ -1,96 +1,55 @@ +# Copyright (c) .NET Foundation and Contributors +# See LICENSE file in the project root for full license information. + [CmdletBinding(SupportsShouldProcess = $true)] param ( -[Parameter(HelpMessage="Enter the path to the folder where the tools should be installed.",Position=2)][string]$Path, -[switch]$force = $false + [Parameter(HelpMessage = "Enter the path to the folder where the tools should be installed.")][string]$Path, + [switch]$force = $false ) -# set board name -$BOARD_NAME = "STM32" - -[Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls" - -Write-Host "Install Tools to build nanoCLR into default folders and configure json files ..." -$env:BOARD_NAME = $BOARD_NAME -$env:NANOCLR_COMPORT = $COMPORT - -if($psISE) { $PSScriptRoot = Split-Path -Path $psISE.CurrentFile.FullPath} #In case running in psISE -if(!$PSScriptRoot){ $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent } # or older PS - -#Set location of nf-interpreter -$nfRoot = "$PSScriptRoot\.." - -# create build folder if necessary -md -Force "$nfRoot\build" | Out-Null - -Write-Host "BOARD_NAME=" $env:BOARD_NAME - -If(-Not [string]::IsNullOrEmpty($Path)) -{ - # user has requested install on a specific path - - # force update of base path for tools - $env:STM32_TOOLS_PATH = $Path - Write-Host ("Set User Environment STM32_TOOLS_PATH='"+$env:STM32_TOOLS_PATH+"'") - [System.Environment]::SetEnvironmentVariable("STM32_TOOLS_PATH", $env:STM32_TOOLS_PATH, "User") - - $env:GNU_GCC_TOOLCHAIN_PATH=($env:STM32_TOOLS_PATH+'\9-2019-q4-update') - Write-Host ("Set User Environment GNU_GCC_TOOLCHAIN_PATH='"+$env:GNU_GCC_TOOLCHAIN_PATH+"'") - [System.Environment]::SetEnvironmentVariable("GNU_GCC_TOOLCHAIN_PATH", $env:GNU_GCC_TOOLCHAIN_PATH, "User") - - # set flag to force updating all tool paths - $PathSet = $true +# need this check here as the path can be passed with an empty string +if ([string]::IsNullOrEmpty($Path) -or $force) { + + # check if there is already a path set + if($env:NF_TOOLS_PATH) + { + $Path = $env:NF_TOOLS_PATH + } + else { + $Path = "C:\nftools" + } } -else -{ - # no path requested, set to default location - - # force update of base path for path - $env:STM32_TOOLS_PATH = 'C:\mytools' - Write-Host ("Set User Environment STM32_TOOLS_PATH='"+$env:STM32_TOOLS_PATH+"'") - [System.Environment]::SetEnvironmentVariable("STM32_TOOLS_PATH", $env:STM32_TOOLS_PATH, "User") - $env:GNU_GCC_TOOLCHAIN_PATH='C:\GNU_Tools_ARM_Embedded\9-2019-q4-update' - Write-Host ("Set User Environment GNU_GCC_TOOLCHAIN_PATH='"+$env:GNU_GCC_TOOLCHAIN_PATH+"'") - [System.Environment]::SetEnvironmentVariable("GNU_GCC_TOOLCHAIN_PATH", $env:GNU_GCC_TOOLCHAIN_PATH, "User") +# set environment variable +$env:NF_TOOLS_PATH = $Path - # clear flag to force updating all tool paths - $PathSet = $false -} +"Set User Environment NF_TOOLS_PATH='" + $Path + "'" | Write-Host -ForegroundColor White +[System.Environment]::SetEnvironmentVariable("NF_TOOLS_PATH", $Path, "User") -If([string]::IsNullOrEmpty($env:HEX2DFU_PATH) -or $PathSet -or $force) -{ - $env:HEX2DFU_PATH= ($env:STM32_TOOLS_PATH+'\hex2dfu') - Write-Host ("Set User Environment HEX2DFU_PATH='"+$env:HEX2DFU_PATH+"'") - [System.Environment]::SetEnvironmentVariable("HEX2DFU_PATH", $env:HEX2DFU_PATH, "User") -} +# this call can fail if the script is not run with appropriate permissions +[System.Environment]::SetEnvironmentVariable("NF_TOOLS_PATH", $Path, "Machine") -If([string]::IsNullOrEmpty($env:NINJA_PATH) -or $PathSet -or $force) -{ - $env:NINJA_PATH= ($env:STM32_TOOLS_PATH+'\ninja') - Write-Host ("Set User Environment NINJA_PATH='"+$env:NINJA_PATH+"'") - [System.Environment]::SetEnvironmentVariable("NINJA_PATH", $env:NINJA_PATH, "User") +# need to pass the 'force' switch? +if ($force) { + $commandArgs = " -force" } -# get build matrix (Not used anymore) -#Invoke-Expression -Command $PSScriptRoot\get-stm32-targets-to-build.ps1 - # install tools and utilities -Invoke-Expression -Command $PSScriptRoot\install-arm-gcc-toolchain.ps1 -Invoke-Expression -Command $PSScriptRoot\install-ninja.ps1 -Invoke-Expression -Command $PSScriptRoot\install-nf-hex2dfu.ps1 - -# add Ninja to the path -# this call can fail if the script is not run with appropriate permissions -[System.Environment]::SetEnvironmentVariable("NINJA_PATH", $env:NINJA_PATH, "User") +Invoke-Expression $PSScriptRoot\install-cmake.ps1 +Invoke-Expression "$PSScriptRoot\install-arm-gcc-toolchain.ps1 $commandArgs" +Invoke-Expression "$PSScriptRoot\install-ninja.ps1 $commandArgs" +Invoke-Expression "$PSScriptRoot\install-nf-hex2dfu.ps1 $commandArgs" +Invoke-Expression "$PSScriptRoot\install-openocd.ps1 $commandArgs" <# .SYNOPSIS - Install the default tools to build nanoFramework for STM32 and setup build environemnt. + Install the default tools to build nanoFramework for STM32 and setup build environment. .DESCRIPTION - Power Shell Script to install the default tools to build nano Framework, including setting the machine path and other environment variables needed for STM32 + Power Shell Script to install the default tools to build nanoFramework, including setting the machine path and other environment variables needed for STM32 + Use the -Force parameter to overwrite existing Environment variables. .EXAMPLE .\install-stm32-tools.ps1 - Install the tools for STM32 to default path, define required environment variables and update VSCode files with paths and set COM19 in tasks.json + Install the tools for STM32 to default path, define required environment variables .NOTES Tested on Windows 10 Author: nanoFramework Contributors diff --git a/src/CLR/CorLib/CorLib.h b/src/CLR/CorLib/CorLib.h index 10739403f4..c2f37338b3 100644 --- a/src/CLR/CorLib/CorLib.h +++ b/src/CLR/CorLib/CorLib.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/CorLib/corlib_native.cpp b/src/CLR/CorLib/corlib_native.cpp index e4c4a9ee17..7053e4a9de 100644 --- a/src/CLR/CorLib/corlib_native.cpp +++ b/src/CLR/CorLib/corlib_native.cpp @@ -1,9 +1,11 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // #include "CorLib.h" +// clang-format off + #if (NANOCLR_REFLECTION == TRUE) static const CLR_RT_MethodHandler method_lookup[] = @@ -18,6 +20,7 @@ static const CLR_RT_MethodHandler method_lookup[] = NULL, NULL, NULL, + NULL, Library_corlib_native_System_Globalization_CultureInfo::get_CurrentUICultureInternal___STATIC__SystemGlobalizationCultureInfo, Library_corlib_native_System_Globalization_CultureInfo::set_CurrentUICultureInternal___STATIC__VOID__SystemGlobalizationCultureInfo, NULL, @@ -640,6 +643,8 @@ static const CLR_RT_MethodHandler method_lookup[] = NULL, NULL, NULL, + NULL, + NULL, Library_corlib_native_System_Runtime_CompilerServices_RuntimeHelpers::InitializeArray___STATIC__VOID__SystemArray__SystemRuntimeFieldHandle, Library_corlib_native_System_Runtime_CompilerServices_RuntimeHelpers::GetObjectValue___STATIC__OBJECT__OBJECT, Library_corlib_native_System_Runtime_CompilerServices_RuntimeHelpers::RunClassConstructor___STATIC__VOID__SystemRuntimeTypeHandle, @@ -678,6 +683,18 @@ static const CLR_RT_MethodHandler method_lookup[] = NULL, NULL, NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, Library_corlib_native_System_Threading_AutoResetEvent::_ctor___VOID__BOOLEAN, Library_corlib_native_System_Threading_AutoResetEvent::Reset___BOOLEAN, Library_corlib_native_System_Threading_AutoResetEvent::Set___BOOLEAN, @@ -763,6 +780,7 @@ static const CLR_RT_MethodHandler method_lookup[] = NULL, NULL, NULL, + NULL, Library_corlib_native_System_Globalization_CultureInfo::get_CurrentUICultureInternal___STATIC__SystemGlobalizationCultureInfo, Library_corlib_native_System_Globalization_CultureInfo::set_CurrentUICultureInternal___STATIC__VOID__SystemGlobalizationCultureInfo, NULL, @@ -1269,6 +1287,8 @@ static const CLR_RT_MethodHandler method_lookup[] = NULL, NULL, NULL, + NULL, + NULL, Library_corlib_native_System_Runtime_CompilerServices_RuntimeHelpers::InitializeArray___STATIC__VOID__SystemArray__SystemRuntimeFieldHandle, Library_corlib_native_System_Runtime_CompilerServices_RuntimeHelpers::GetObjectValue___STATIC__OBJECT__OBJECT, Library_corlib_native_System_Runtime_CompilerServices_RuntimeHelpers::RunClassConstructor___STATIC__VOID__SystemRuntimeTypeHandle, @@ -1293,6 +1313,18 @@ static const CLR_RT_MethodHandler method_lookup[] = NULL, NULL, NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, Library_corlib_native_System_Threading_AutoResetEvent::_ctor___VOID__BOOLEAN, Library_corlib_native_System_Threading_AutoResetEvent::Reset___BOOLEAN, Library_corlib_native_System_Threading_AutoResetEvent::Set___BOOLEAN, @@ -1377,16 +1409,18 @@ const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_mscorlib = #if (NANOCLR_REFLECTION == TRUE) - 0x9D93AC29, + 0x14A112A6, #elif (NANOCLR_REFLECTION == FALSE) - 0x1F09272F, + 0x09DDE96D, #else #error "NANOCLR_REFLECTION has to be define either TRUE or FALSE. Check the build options." #endif method_lookup, - { 100, 4, 10, 0 } + { 100, 5, 0, 0 } }; + +// clang-format on diff --git a/src/CLR/CorLib/corlib_native.h b/src/CLR/CorLib/corlib_native.h index 49cfa88840..a8eb92dd41 100644 --- a/src/CLR/CorLib/corlib_native.h +++ b/src/CLR/CorLib/corlib_native.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/CorLib/corlib_native_System_AppDomain.cpp b/src/CLR/CorLib/corlib_native_System_AppDomain.cpp index 8134950b63..5510462787 100644 --- a/src/CLR/CorLib/corlib_native_System_AppDomain.cpp +++ b/src/CLR/CorLib/corlib_native_System_AppDomain.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // @@ -7,276 +7,299 @@ #if defined(NANOCLR_APPDOMAINS) - - -HRESULT Library_corlib_native_System_AppDomain::GetAssemblies___SZARRAY_SystemReflectionAssembly( CLR_RT_StackFrame& stack ) -{ +HRESULT Library_corlib_native_System_AppDomain::GetAssemblies___SZARRAY_SystemReflectionAssembly( + CLR_RT_StackFrame &stack) +{ NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - - CLR_RT_AppDomain* appDomainSav = NULL; - CLR_RT_AppDomain* appDomain; - NANOCLR_CHECK_HRESULT(GetAppDomain( stack.ThisRef(), appDomain, appDomainSav, true )); + CLR_RT_AppDomain *appDomainSav = NULL; + CLR_RT_AppDomain *appDomain; + + NANOCLR_CHECK_HRESULT(GetAppDomain(stack.ThisRef(), appDomain, appDomainSav, true)); - NANOCLR_CHECK_HRESULT(appDomain->GetAssemblies( stack.PushValueAndClear() )); + NANOCLR_CHECK_HRESULT(appDomain->GetAssemblies(stack.PushValueAndClear())); NANOCLR_CLEANUP(); - g_CLR_RT_ExecutionEngine.SetCurrentAppDomain( appDomainSav ); + g_CLR_RT_ExecutionEngine.SetCurrentAppDomain(appDomainSav); NANOCLR_CLEANUP_END(); } -HRESULT Library_corlib_native_System_AppDomain::LoadInternal___SystemReflectionAssembly__STRING__BOOLEAN__I4__I4__I4__I4( CLR_RT_StackFrame& stack ) +HRESULT Library_corlib_native_System_AppDomain:: + LoadInternal___SystemReflectionAssembly__STRING__BOOLEAN__I4__I4__I4__I4(CLR_RT_StackFrame &stack) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - CLR_RT_HeapBlock* pArgs = &(stack.Arg1()); - CLR_RT_AppDomain* appDomainSav; - CLR_RT_AppDomain* appDomain; - CLR_RT_Assembly* assembly; - CLR_RT_Assembly_Index idx; - bool fVersion; - CLR_INT16 maj, min, build, rev; - const char* szAssembly; - - NANOCLR_CHECK_HRESULT(GetAppDomain( stack.ThisRef(), appDomain, appDomainSav, true )); - - szAssembly = pArgs[ 0 ].RecoverString(); FAULT_ON_NULL(szAssembly); - fVersion = pArgs[ 1 ].NumericByRef().u8 != 0; - maj = pArgs[ 2 ].NumericByRef().s4; - min = pArgs[ 3 ].NumericByRef().s4; - build = pArgs[ 4 ].NumericByRef().s4; - rev = pArgs[ 5 ].NumericByRef().s4; - - if(fVersion && (maj == -1 || min == -1 || build == -1 || rev == -1)) + CLR_RT_HeapBlock *pArgs = &(stack.Arg1()); + CLR_RT_AppDomain *appDomainSav; + CLR_RT_AppDomain *appDomain; + CLR_RT_Assembly *assembly; + CLR_RT_Assembly_Index idx; + bool fVersion; + CLR_INT16 maj, min, build, rev; + const char *szAssembly; + + NANOCLR_CHECK_HRESULT(GetAppDomain(stack.ThisRef(), appDomain, appDomainSav, true)); + + szAssembly = pArgs[0].RecoverString(); + FAULT_ON_NULL(szAssembly); + fVersion = pArgs[1].NumericByRef().u8 != 0; + maj = pArgs[2].NumericByRef().s4; + min = pArgs[3].NumericByRef().s4; + build = pArgs[4].NumericByRef().s4; + rev = pArgs[5].NumericByRef().s4; + + if (fVersion && (maj == -1 || min == -1 || build == -1 || rev == -1)) { NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); } - if(fVersion) + if (fVersion) { CLR_RECORD_VERSION ver; - ver.iMajorVersion = (CLR_UINT16) maj; - ver.iMinorVersion = (CLR_UINT16) min; - ver.iBuildNumber = (CLR_UINT16) build; - ver.iRevisionNumber = (CLR_UINT16) rev; - - assembly = g_CLR_RT_TypeSystem.FindAssembly( szAssembly, &ver, true ); FAULT_ON_NULL_HR(assembly, CLR_E_INVALID_PARAMETER); + ver.iMajorVersion = (CLR_UINT16)maj; + ver.iMinorVersion = (CLR_UINT16)min; + ver.iBuildNumber = (CLR_UINT16)build; + ver.iRevisionNumber = (CLR_UINT16)rev; + + assembly = g_CLR_RT_TypeSystem.FindAssembly(szAssembly, &ver, true); + FAULT_ON_NULL_HR(assembly, CLR_E_INVALID_PARAMETER); } else - { - assembly = g_CLR_RT_TypeSystem.FindAssembly( szAssembly, NULL, false ); FAULT_ON_NULL_HR(assembly, CLR_E_INVALID_PARAMETER); + { + assembly = g_CLR_RT_TypeSystem.FindAssembly(szAssembly, NULL, false); + FAULT_ON_NULL_HR(assembly, CLR_E_INVALID_PARAMETER); } - - NANOCLR_CHECK_HRESULT(appDomain->LoadAssembly( assembly )); + + NANOCLR_CHECK_HRESULT(appDomain->LoadAssembly(assembly)); { - CLR_RT_HeapBlock& top = stack.PushValue(); - CLR_RT_HeapBlock* hbObj; + CLR_RT_HeapBlock &top = stack.PushValue(); + CLR_RT_HeapBlock *hbObj; - idx.Set( assembly->m_idx ); + idx.Set(assembly->m_idx); NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.NewObjectFromIndex(top, g_CLR_RT_WellKnownTypes.m_Assembly)); hbObj = top.Dereference(); - hbObj->SetReflection( idx ); + hbObj->SetReflection(idx); } NANOCLR_CLEANUP(); - g_CLR_RT_ExecutionEngine.SetCurrentAppDomain( appDomainSav ); + g_CLR_RT_ExecutionEngine.SetCurrentAppDomain(appDomainSav); NANOCLR_CLEANUP_END(); } -HRESULT Library_corlib_native_System_AppDomain::CreateDomain___STATIC__SystemAppDomain__STRING( CLR_RT_StackFrame& stack ) +HRESULT Library_corlib_native_System_AppDomain::CreateDomain___STATIC__SystemAppDomain__STRING(CLR_RT_StackFrame &stack) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - - CLR_RT_AppDomain* appDomain = NULL; - CLR_RT_HeapBlock& pArgs = stack.Arg0(); - CLR_RT_HeapBlock res; res.SetObjectReference( NULL ); - CLR_RT_ProtectFromGC gc( res ); - const char* szName; - - szName = pArgs.RecoverString(); FAULT_ON_NULL(szName); - - NANOCLR_CHECK_HRESULT(CLR_RT_AppDomain::CreateInstance( szName, appDomain )); - - //load mscorlib - NANOCLR_CHECK_HRESULT(appDomain->LoadAssembly( g_CLR_RT_TypeSystem.m_assemblyMscorlib )); - - //load Runtime.Native - if(g_CLR_RT_TypeSystem.m_assemblyNative != NULL) + + CLR_RT_AppDomain *appDomain = NULL; + CLR_RT_HeapBlock &pArgs = stack.Arg0(); + CLR_RT_HeapBlock res; + res.SetObjectReference(NULL); + CLR_RT_ProtectFromGC gc(res); + const char *szName; + + szName = pArgs.RecoverString(); + FAULT_ON_NULL(szName); + + NANOCLR_CHECK_HRESULT(CLR_RT_AppDomain::CreateInstance(szName, appDomain)); + + // load mscorlib + NANOCLR_CHECK_HRESULT(appDomain->LoadAssembly(g_CLR_RT_TypeSystem.m_assemblyMscorlib)); + + // load Runtime.Native + if (g_CLR_RT_TypeSystem.m_assemblyNative != NULL) { - NANOCLR_CHECK_HRESULT(appDomain->LoadAssembly( g_CLR_RT_TypeSystem.m_assemblyNative )); + NANOCLR_CHECK_HRESULT(appDomain->LoadAssembly(g_CLR_RT_TypeSystem.m_assemblyNative)); } - NANOCLR_CHECK_HRESULT(appDomain->GetManagedObject( res )); + NANOCLR_CHECK_HRESULT(appDomain->GetManagedObject(res)); - //Marshal the new AD to the calling AD. - NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.GetCurrentAppDomain()->MarshalObject( res, res, appDomain )); + // Marshal the new AD to the calling AD. + NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.GetCurrentAppDomain()->MarshalObject(res, res, appDomain)); - stack.PushValueAndAssign( res ); + stack.PushValueAndAssign(res); NANOCLR_CLEANUP(); - if(FAILED(hr)) + if (FAILED(hr)) { - if(appDomain) + if (appDomain) { appDomain->DestroyInstance(); - } + } } NANOCLR_CLEANUP_END(); } -HRESULT Library_corlib_native_System_AppDomain::Unload___STATIC__VOID__SystemAppDomain( CLR_RT_StackFrame& stack ) +HRESULT Library_corlib_native_System_AppDomain::Unload___STATIC__VOID__SystemAppDomain(CLR_RT_StackFrame &stack) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - CLR_RT_AppDomain* appDomainSav; - CLR_RT_AppDomain* appDomain; - CLR_RT_HeapBlock hbTimeout; - CLR_INT64* timeout; - bool fRes; - - NANOCLR_CHECK_HRESULT(GetAppDomain( stack.ThisRef(), appDomain, appDomainSav, false )); - - hbTimeout.SetInteger( 5 * 1000 * TIME_CONVERSION__TO_MILLISECONDS); - - if(stack.m_customState == 0) - { - //Attempt to unload the AppDomain only once - NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.UnloadAppDomain( appDomain, stack.m_owningThread )); + CLR_RT_AppDomain *appDomainSav; + CLR_RT_AppDomain *appDomain; + CLR_RT_HeapBlock hbTimeout; + CLR_INT64 *timeout; + bool fRes; + + NANOCLR_CHECK_HRESULT(GetAppDomain(stack.ThisRef(), appDomain, appDomainSav, false)); + + hbTimeout.SetInteger(5 * 1000 * TIME_CONVERSION__TO_MILLISECONDS); + + if (stack.m_customState == 0) + { + // Attempt to unload the AppDomain only once + NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.UnloadAppDomain(appDomain, stack.m_owningThread)); } - NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks( hbTimeout, timeout )); + NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks(hbTimeout, timeout)); fRes = true; - while(fRes) + while (fRes) { - //Check to make sure this AppDomain is the one that caused the event to fire - if(appDomain->m_state == CLR_RT_AppDomain::AppDomainState_Unloaded) break; + // Check to make sure this AppDomain is the one that caused the event to fire + if (appDomain->m_state == CLR_RT_AppDomain::AppDomainState_Unloaded) + break; _ASSERTE(CLR_EE_IS(UnloadingAppDomain)); - NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.WaitEvents( stack.m_owningThread, *timeout, CLR_RT_ExecutionEngine::c_Event_AppDomain, fRes )); + NANOCLR_CHECK_HRESULT( + g_CLR_RT_ExecutionEngine.WaitEvents(stack.m_owningThread, *timeout, Event_AppDomain, fRes)); } - if(!fRes) NANOCLR_SET_AND_LEAVE(CLR_E_TIMEOUT); + if (!fRes) + NANOCLR_SET_AND_LEAVE(CLR_E_TIMEOUT); appDomain->DestroyInstance(); stack.PopValue(); - + NANOCLR_CLEANUP(); - g_CLR_RT_ExecutionEngine.SetCurrentAppDomain( appDomainSav ); + g_CLR_RT_ExecutionEngine.SetCurrentAppDomain(appDomainSav); NANOCLR_CLEANUP_END(); } //--// -HRESULT Library_corlib_native_System_AppDomain::GetAppDomain( CLR_RT_HeapBlock& ref, CLR_RT_AppDomain*& appDomain, CLR_RT_AppDomain*& appDomainSav, bool fCheckForUnloadingAppDomain ) +HRESULT Library_corlib_native_System_AppDomain::GetAppDomain( + CLR_RT_HeapBlock &ref, + CLR_RT_AppDomain *&appDomain, + CLR_RT_AppDomain *&appDomainSav, + bool fCheckForUnloadingAppDomain) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - CLR_RT_HeapBlock* obj; - CLR_RT_ObjectToEvent_Source* src; + CLR_RT_HeapBlock *obj; + CLR_RT_ObjectToEvent_Source *src; - //Setting up appDomainSav is guaranteed to be initialized correctly by this function + // Setting up appDomainSav is guaranteed to be initialized correctly by this function appDomainSav = g_CLR_RT_ExecutionEngine.GetCurrentAppDomain(); - + _ASSERTE(ref.DataType() == DATATYPE_OBJECT); - - obj = ref.Dereference(); FAULT_ON_NULL(obj); - - if(obj->DataType() == DATATYPE_TRANSPARENT_PROXY) + + obj = ref.Dereference(); + FAULT_ON_NULL(obj); + + if (obj->DataType() == DATATYPE_TRANSPARENT_PROXY) { appDomain = obj->TransparentProxyAppDomain(); - if(!appDomain) NANOCLR_SET_AND_LEAVE(CLR_E_APPDOMAIN_EXITED); + if (!appDomain) + NANOCLR_SET_AND_LEAVE(CLR_E_APPDOMAIN_EXITED); - obj = obj->TransparentProxyDereference(); FAULT_ON_NULL(obj); + obj = obj->TransparentProxyDereference(); + FAULT_ON_NULL(obj); } - _ASSERTE(obj->DataType() == DATATYPE_CLASS ); + _ASSERTE(obj->DataType() == DATATYPE_CLASS); _ASSERTE(obj->ObjectCls().m_data == g_CLR_RT_WellKnownTypes.m_AppDomain.m_data); - - src = CLR_RT_ObjectToEvent_Source::ExtractInstance( obj[ FIELD___appDomain ] ); FAULT_ON_NULL(src); - appDomain = (CLR_RT_AppDomain*)src->m_eventPtr ; FAULT_ON_NULL(appDomain); - + + src = CLR_RT_ObjectToEvent_Source::ExtractInstance(obj[FIELD___appDomain]); + FAULT_ON_NULL(src); + appDomain = (CLR_RT_AppDomain *)src->m_eventPtr; + FAULT_ON_NULL(appDomain); + _ASSERTE(appDomain->DataType() == DATATYPE_APPDOMAIN_HEAD); - if(fCheckForUnloadingAppDomain) + if (fCheckForUnloadingAppDomain) { - if(!appDomain->IsLoaded()) NANOCLR_SET_AND_LEAVE(CLR_E_APPDOMAIN_EXITED); + if (!appDomain->IsLoaded()) + NANOCLR_SET_AND_LEAVE(CLR_E_APPDOMAIN_EXITED); } - (void)g_CLR_RT_ExecutionEngine.SetCurrentAppDomain( appDomain ); + (void)g_CLR_RT_ExecutionEngine.SetCurrentAppDomain(appDomain); NANOCLR_NOCLEANUP(); } -#else //#if defined(NANOCLR_APPDOMAINS) +#else //#if defined(NANOCLR_APPDOMAINS) #if (NANOCLR_REFLECTION == TRUE) -HRESULT Library_corlib_native_System_AppDomain::GetAssemblies___SZARRAY_SystemReflectionAssembly( CLR_RT_StackFrame& stack ) +HRESULT Library_corlib_native_System_AppDomain::GetAssemblies___SZARRAY_SystemReflectionAssembly( + CLR_RT_StackFrame &stack) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - - CLR_RT_HeapBlock& top = stack.PushValueAndClear(); - int count = 0; - CLR_RT_HeapBlock* pArray = NULL; + CLR_RT_HeapBlock &top = stack.PushValueAndClear(); + + int count = 0; + CLR_RT_HeapBlock *pArray = NULL; - for(int pass=0; pass<2; pass++) + for (int pass = 0; pass < 2; pass++) { NANOCLR_FOREACH_ASSEMBLY(g_CLR_RT_TypeSystem) { - if(pass == 0) + if (pass == 0) { count++; } else { - CLR_RT_HeapBlock* hbObj; - CLR_RT_Assembly_Index idx; idx.Set( pASSM->m_idx ); + CLR_RT_HeapBlock *hbObj; + CLR_RT_Assembly_Index idx; + idx.Set(pASSM->m_idx); - NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.NewObjectFromIndex(*pArray, g_CLR_RT_WellKnownTypes.m_Assembly)); + NANOCLR_CHECK_HRESULT( + g_CLR_RT_ExecutionEngine.NewObjectFromIndex(*pArray, g_CLR_RT_WellKnownTypes.m_Assembly)); hbObj = pArray->Dereference(); - - hbObj->SetReflection( idx ); + + hbObj->SetReflection(idx); pArray++; } } NANOCLR_FOREACH_ASSEMBLY_END(); - if(pass == 0) + if (pass == 0) { - NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_Array::CreateInstance( top, count, g_CLR_RT_WellKnownTypes.m_Assembly )); + NANOCLR_CHECK_HRESULT( + CLR_RT_HeapBlock_Array::CreateInstance(top, count, g_CLR_RT_WellKnownTypes.m_Assembly)); - pArray = (CLR_RT_HeapBlock*)top.DereferenceArray()->GetFirstElement(); + pArray = (CLR_RT_HeapBlock *)top.DereferenceArray()->GetFirstElement(); } } NANOCLR_NOCLEANUP(); } -HRESULT Library_corlib_native_System_AppDomain::LoadInternal___SystemReflectionAssembly__STRING__BOOLEAN__I4__I4__I4__I4( CLR_RT_StackFrame& stack ) +HRESULT Library_corlib_native_System_AppDomain:: + LoadInternal___SystemReflectionAssembly__STRING__BOOLEAN__I4__I4__I4__I4(CLR_RT_StackFrame &stack) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); @@ -286,7 +309,7 @@ HRESULT Library_corlib_native_System_AppDomain::LoadInternal___SystemReflectionA NANOCLR_NOCLEANUP(); } -HRESULT Library_corlib_native_System_AppDomain::CreateDomain___STATIC__SystemAppDomain__STRING( CLR_RT_StackFrame& stack ) +HRESULT Library_corlib_native_System_AppDomain::CreateDomain___STATIC__SystemAppDomain__STRING(CLR_RT_StackFrame &stack) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); @@ -296,7 +319,7 @@ HRESULT Library_corlib_native_System_AppDomain::CreateDomain___STATIC__SystemApp NANOCLR_NOCLEANUP(); } -HRESULT Library_corlib_native_System_AppDomain::Unload___STATIC__VOID__SystemAppDomain( CLR_RT_StackFrame& stack ) +HRESULT Library_corlib_native_System_AppDomain::Unload___STATIC__VOID__SystemAppDomain(CLR_RT_StackFrame &stack) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); diff --git a/src/CLR/CorLib/corlib_native_System_Array.cpp b/src/CLR/CorLib/corlib_native_System_Array.cpp index 03eb5be5bd..a42fff593b 100644 --- a/src/CLR/CorLib/corlib_native_System_Array.cpp +++ b/src/CLR/CorLib/corlib_native_System_Array.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/CorLib/corlib_native_System_Attribute.cpp b/src/CLR/CorLib/corlib_native_System_Attribute.cpp index 488a22e748..46f163e0c0 100644 --- a/src/CLR/CorLib/corlib_native_System_Attribute.cpp +++ b/src/CLR/CorLib/corlib_native_System_Attribute.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/CorLib/corlib_native_System_BitConverter.cpp b/src/CLR/CorLib/corlib_native_System_BitConverter.cpp index d257eed2af..3b6e1e7e2e 100644 --- a/src/CLR/CorLib/corlib_native_System_BitConverter.cpp +++ b/src/CLR/CorLib/corlib_native_System_BitConverter.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/CorLib/corlib_native_System_Collections_ArrayList.cpp b/src/CLR/CorLib/corlib_native_System_Collections_ArrayList.cpp index 440a584e02..3bf0b42516 100644 --- a/src/CLR/CorLib/corlib_native_System_Collections_ArrayList.cpp +++ b/src/CLR/CorLib/corlib_native_System_Collections_ArrayList.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/CorLib/corlib_native_System_Console.cpp b/src/CLR/CorLib/corlib_native_System_Console.cpp index 93ac4028d9..ce29613f40 100644 --- a/src/CLR/CorLib/corlib_native_System_Console.cpp +++ b/src/CLR/CorLib/corlib_native_System_Console.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/CorLib/corlib_native_System_Convert.cpp b/src/CLR/CorLib/corlib_native_System_Convert.cpp index ae34fa14d0..50090e6c7d 100644 --- a/src/CLR/CorLib/corlib_native_System_Convert.cpp +++ b/src/CLR/CorLib/corlib_native_System_Convert.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/CorLib/corlib_native_System_DateTime.cpp b/src/CLR/CorLib/corlib_native_System_DateTime.cpp index 1797869751..2399e39773 100644 --- a/src/CLR/CorLib/corlib_native_System_DateTime.cpp +++ b/src/CLR/CorLib/corlib_native_System_DateTime.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/CorLib/corlib_native_System_Delegate.cpp b/src/CLR/CorLib/corlib_native_System_Delegate.cpp index fc08e48e89..d27dc4e3b6 100644 --- a/src/CLR/CorLib/corlib_native_System_Delegate.cpp +++ b/src/CLR/CorLib/corlib_native_System_Delegate.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/CorLib/corlib_native_System_Diagnostics_Debug.cpp b/src/CLR/CorLib/corlib_native_System_Diagnostics_Debug.cpp index 5662c7faec..52f47a2a1f 100644 --- a/src/CLR/CorLib/corlib_native_System_Diagnostics_Debug.cpp +++ b/src/CLR/CorLib/corlib_native_System_Diagnostics_Debug.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2020 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/CorLib/corlib_native_System_Diagnostics_Debugger.cpp b/src/CLR/CorLib/corlib_native_System_Diagnostics_Debugger.cpp index 3a2e394f20..dcc19dd8a4 100644 --- a/src/CLR/CorLib/corlib_native_System_Diagnostics_Debugger.cpp +++ b/src/CLR/CorLib/corlib_native_System_Diagnostics_Debugger.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/CorLib/corlib_native_System_Double.cpp b/src/CLR/CorLib/corlib_native_System_Double.cpp index 2c3ddcd307..4f1b847ebf 100644 --- a/src/CLR/CorLib/corlib_native_System_Double.cpp +++ b/src/CLR/CorLib/corlib_native_System_Double.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/CorLib/corlib_native_System_Enum.cpp b/src/CLR/CorLib/corlib_native_System_Enum.cpp index 488a22e748..46f163e0c0 100644 --- a/src/CLR/CorLib/corlib_native_System_Enum.cpp +++ b/src/CLR/CorLib/corlib_native_System_Enum.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/CorLib/corlib_native_System_Exception.cpp b/src/CLR/CorLib/corlib_native_System_Exception.cpp index 0205f404c5..860ba8a970 100644 --- a/src/CLR/CorLib/corlib_native_System_Exception.cpp +++ b/src/CLR/CorLib/corlib_native_System_Exception.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/CorLib/corlib_native_System_GC.cpp b/src/CLR/CorLib/corlib_native_System_GC.cpp index 2f94e266b3..ce2af4ccf9 100644 --- a/src/CLR/CorLib/corlib_native_System_GC.cpp +++ b/src/CLR/CorLib/corlib_native_System_GC.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/CorLib/corlib_native_System_Globalization_CultureInfo.cpp b/src/CLR/CorLib/corlib_native_System_Globalization_CultureInfo.cpp index 274c3db7b5..5be4b34317 100644 --- a/src/CLR/CorLib/corlib_native_System_Globalization_CultureInfo.cpp +++ b/src/CLR/CorLib/corlib_native_System_Globalization_CultureInfo.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/CorLib/corlib_native_System_Globalization_DateTimeFormat.cpp b/src/CLR/CorLib/corlib_native_System_Globalization_DateTimeFormat.cpp index a667560a07..bfd87f8268 100644 --- a/src/CLR/CorLib/corlib_native_System_Globalization_DateTimeFormat.cpp +++ b/src/CLR/CorLib/corlib_native_System_Globalization_DateTimeFormat.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/CorLib/corlib_native_System_Guid.cpp b/src/CLR/CorLib/corlib_native_System_Guid.cpp index ccadaf36b6..cac42f7c49 100644 --- a/src/CLR/CorLib/corlib_native_System_Guid.cpp +++ b/src/CLR/CorLib/corlib_native_System_Guid.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/CorLib/corlib_native_System_MarshalByRefObject.cpp b/src/CLR/CorLib/corlib_native_System_MarshalByRefObject.cpp index 488a22e748..46f163e0c0 100644 --- a/src/CLR/CorLib/corlib_native_System_MarshalByRefObject.cpp +++ b/src/CLR/CorLib/corlib_native_System_MarshalByRefObject.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/CorLib/corlib_native_System_MathInternal.cpp b/src/CLR/CorLib/corlib_native_System_MathInternal.cpp index 335f396cd7..4c2eedd850 100644 --- a/src/CLR/CorLib/corlib_native_System_MathInternal.cpp +++ b/src/CLR/CorLib/corlib_native_System_MathInternal.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/CorLib/corlib_native_System_MulticastDelegate.cpp b/src/CLR/CorLib/corlib_native_System_MulticastDelegate.cpp index 7ee1daf5de..ba5576a3fe 100644 --- a/src/CLR/CorLib/corlib_native_System_MulticastDelegate.cpp +++ b/src/CLR/CorLib/corlib_native_System_MulticastDelegate.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/CorLib/corlib_native_System_Number.cpp b/src/CLR/CorLib/corlib_native_System_Number.cpp index e67e17936d..ee09083262 100644 --- a/src/CLR/CorLib/corlib_native_System_Number.cpp +++ b/src/CLR/CorLib/corlib_native_System_Number.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/CorLib/corlib_native_System_Object.cpp b/src/CLR/CorLib/corlib_native_System_Object.cpp index 25c113fbd6..b20abd98e9 100644 --- a/src/CLR/CorLib/corlib_native_System_Object.cpp +++ b/src/CLR/CorLib/corlib_native_System_Object.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/CorLib/corlib_native_System_Random.cpp b/src/CLR/CorLib/corlib_native_System_Random.cpp index 233dd56959..506cfb6486 100644 --- a/src/CLR/CorLib/corlib_native_System_Random.cpp +++ b/src/CLR/CorLib/corlib_native_System_Random.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/CorLib/corlib_native_System_Reflection_Assembly.cpp b/src/CLR/CorLib/corlib_native_System_Reflection_Assembly.cpp index d116594736..32f0048b07 100644 --- a/src/CLR/CorLib/corlib_native_System_Reflection_Assembly.cpp +++ b/src/CLR/CorLib/corlib_native_System_Reflection_Assembly.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/CorLib/corlib_native_System_Reflection_Binder.cpp b/src/CLR/CorLib/corlib_native_System_Reflection_Binder.cpp index 488a22e748..46f163e0c0 100644 --- a/src/CLR/CorLib/corlib_native_System_Reflection_Binder.cpp +++ b/src/CLR/CorLib/corlib_native_System_Reflection_Binder.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/CorLib/corlib_native_System_Reflection_ConstructorInfo.cpp b/src/CLR/CorLib/corlib_native_System_Reflection_ConstructorInfo.cpp index 3c05abc985..3e38c856e9 100644 --- a/src/CLR/CorLib/corlib_native_System_Reflection_ConstructorInfo.cpp +++ b/src/CLR/CorLib/corlib_native_System_Reflection_ConstructorInfo.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/CorLib/corlib_native_System_Reflection_FieldInfo.cpp b/src/CLR/CorLib/corlib_native_System_Reflection_FieldInfo.cpp index a96d653e08..e63233358c 100644 --- a/src/CLR/CorLib/corlib_native_System_Reflection_FieldInfo.cpp +++ b/src/CLR/CorLib/corlib_native_System_Reflection_FieldInfo.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/CorLib/corlib_native_System_Reflection_MemberInfo.cpp b/src/CLR/CorLib/corlib_native_System_Reflection_MemberInfo.cpp index 488a22e748..46f163e0c0 100644 --- a/src/CLR/CorLib/corlib_native_System_Reflection_MemberInfo.cpp +++ b/src/CLR/CorLib/corlib_native_System_Reflection_MemberInfo.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/CorLib/corlib_native_System_Reflection_MethodBase.cpp b/src/CLR/CorLib/corlib_native_System_Reflection_MethodBase.cpp index a77af2340c..4418a30cd0 100644 --- a/src/CLR/CorLib/corlib_native_System_Reflection_MethodBase.cpp +++ b/src/CLR/CorLib/corlib_native_System_Reflection_MethodBase.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/CorLib/corlib_native_System_Reflection_PropertyInfo.cpp b/src/CLR/CorLib/corlib_native_System_Reflection_PropertyInfo.cpp index 8c58f62a01..73c180dbac 100644 --- a/src/CLR/CorLib/corlib_native_System_Reflection_PropertyInfo.cpp +++ b/src/CLR/CorLib/corlib_native_System_Reflection_PropertyInfo.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/CorLib/corlib_native_System_Reflection_RuntimeFieldInfo.cpp b/src/CLR/CorLib/corlib_native_System_Reflection_RuntimeFieldInfo.cpp index a47a8cf179..afc06eb12f 100644 --- a/src/CLR/CorLib/corlib_native_System_Reflection_RuntimeFieldInfo.cpp +++ b/src/CLR/CorLib/corlib_native_System_Reflection_RuntimeFieldInfo.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/CorLib/corlib_native_System_Reflection_RuntimeMethodInfo.cpp b/src/CLR/CorLib/corlib_native_System_Reflection_RuntimeMethodInfo.cpp index 2129e343a4..80b4de18ac 100644 --- a/src/CLR/CorLib/corlib_native_System_Reflection_RuntimeMethodInfo.cpp +++ b/src/CLR/CorLib/corlib_native_System_Reflection_RuntimeMethodInfo.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/CorLib/corlib_native_System_RuntimeType.cpp b/src/CLR/CorLib/corlib_native_System_RuntimeType.cpp index 7ab8821308..8262087117 100644 --- a/src/CLR/CorLib/corlib_native_System_RuntimeType.cpp +++ b/src/CLR/CorLib/corlib_native_System_RuntimeType.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/CorLib/corlib_native_System_Runtime_CompilerServices_RuntimeHelpers.cpp b/src/CLR/CorLib/corlib_native_System_Runtime_CompilerServices_RuntimeHelpers.cpp index 69f9ac196b..4bb211e949 100644 --- a/src/CLR/CorLib/corlib_native_System_Runtime_CompilerServices_RuntimeHelpers.cpp +++ b/src/CLR/CorLib/corlib_native_System_Runtime_CompilerServices_RuntimeHelpers.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/CorLib/corlib_native_System_Runtime_Remoting_RemotingServices.cpp b/src/CLR/CorLib/corlib_native_System_Runtime_Remoting_RemotingServices.cpp index be4d82a692..13dfbadbd7 100644 --- a/src/CLR/CorLib/corlib_native_System_Runtime_Remoting_RemotingServices.cpp +++ b/src/CLR/CorLib/corlib_native_System_Runtime_Remoting_RemotingServices.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/CorLib/corlib_native_System_String.cpp b/src/CLR/CorLib/corlib_native_System_String.cpp index 2a9d4e2716..8d30079738 100644 --- a/src/CLR/CorLib/corlib_native_System_String.cpp +++ b/src/CLR/CorLib/corlib_native_System_String.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/CorLib/corlib_native_System_Threading_AutoResetEvent.cpp b/src/CLR/CorLib/corlib_native_System_Threading_AutoResetEvent.cpp index 1037e1d36e..1242bba352 100644 --- a/src/CLR/CorLib/corlib_native_System_Threading_AutoResetEvent.cpp +++ b/src/CLR/CorLib/corlib_native_System_Threading_AutoResetEvent.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/CorLib/corlib_native_System_Threading_Interlocked.cpp b/src/CLR/CorLib/corlib_native_System_Threading_Interlocked.cpp index 54bb93220e..87a11fae4f 100644 --- a/src/CLR/CorLib/corlib_native_System_Threading_Interlocked.cpp +++ b/src/CLR/CorLib/corlib_native_System_Threading_Interlocked.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/CorLib/corlib_native_System_Threading_ManualResetEvent.cpp b/src/CLR/CorLib/corlib_native_System_Threading_ManualResetEvent.cpp index 8482a43d89..c2c257f506 100644 --- a/src/CLR/CorLib/corlib_native_System_Threading_ManualResetEvent.cpp +++ b/src/CLR/CorLib/corlib_native_System_Threading_ManualResetEvent.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/CorLib/corlib_native_System_Threading_Monitor.cpp b/src/CLR/CorLib/corlib_native_System_Threading_Monitor.cpp index 0a1c43fb64..ecfdb4959c 100644 --- a/src/CLR/CorLib/corlib_native_System_Threading_Monitor.cpp +++ b/src/CLR/CorLib/corlib_native_System_Threading_Monitor.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/CorLib/corlib_native_System_Threading_Thread.cpp b/src/CLR/CorLib/corlib_native_System_Threading_Thread.cpp index add106ca15..879cc49287 100644 --- a/src/CLR/CorLib/corlib_native_System_Threading_Thread.cpp +++ b/src/CLR/CorLib/corlib_native_System_Threading_Thread.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/CorLib/corlib_native_System_Threading_Timer.cpp b/src/CLR/CorLib/corlib_native_System_Threading_Timer.cpp index 6f5aa716dc..03688d6c2c 100644 --- a/src/CLR/CorLib/corlib_native_System_Threading_Timer.cpp +++ b/src/CLR/CorLib/corlib_native_System_Threading_Timer.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/CorLib/corlib_native_System_Threading_WaitHandle.cpp b/src/CLR/CorLib/corlib_native_System_Threading_WaitHandle.cpp index abf735d6c5..770f04e154 100644 --- a/src/CLR/CorLib/corlib_native_System_Threading_WaitHandle.cpp +++ b/src/CLR/CorLib/corlib_native_System_Threading_WaitHandle.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/CorLib/corlib_native_System_TimeSpan.cpp b/src/CLR/CorLib/corlib_native_System_TimeSpan.cpp index 71c1a07679..4f058944bb 100644 --- a/src/CLR/CorLib/corlib_native_System_TimeSpan.cpp +++ b/src/CLR/CorLib/corlib_native_System_TimeSpan.cpp @@ -1,140 +1,173 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // #include "CorLib.h" - -HRESULT Library_corlib_native_System_TimeSpan::Equals___BOOLEAN__OBJECT( CLR_RT_StackFrame& stack ) +HRESULT Library_corlib_native_System_TimeSpan::Equals___BOOLEAN__OBJECT(CLR_RT_StackFrame &stack) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - NANOCLR_CHECK_HRESULT(CompareTo___I4__OBJECT( stack )); + NANOCLR_CHECK_HRESULT(CompareTo___I4__OBJECT(stack)); { - CLR_RT_HeapBlock& res = stack.TopValue(); + CLR_RT_HeapBlock &res = stack.TopValue(); - res.SetBoolean( res.NumericByRef().s4 == 0 ); + res.SetBoolean(res.NumericByRef().s4 == 0); } NANOCLR_NOCLEANUP(); } -HRESULT Library_corlib_native_System_TimeSpan::ToString___STRING( CLR_RT_StackFrame& stack ) +HRESULT Library_corlib_native_System_TimeSpan::ToString___STRING(CLR_RT_StackFrame &stack) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - char rgBuffer[ 128 ]; - char* szBuffer = rgBuffer; - size_t iBuffer = ARRAYSIZE(rgBuffer); - CLR_INT64* val = GetValuePtr( stack ); FAULT_ON_NULL(val); + char rgBuffer[128]; + char *szBuffer = rgBuffer; + size_t iBuffer = ARRAYSIZE(rgBuffer); + CLR_INT64 *val = GetValuePtr(stack); + FAULT_ON_NULL(val); - HAL_Time_TimeSpanToStringEx( *val, szBuffer, iBuffer ); + HAL_Time_TimeSpanToStringEx(*val, szBuffer, iBuffer); - NANOCLR_SET_AND_LEAVE(stack.SetResult_String( rgBuffer )); + NANOCLR_SET_AND_LEAVE(stack.SetResult_String(rgBuffer)); NANOCLR_NOCLEANUP(); } -HRESULT Library_corlib_native_System_TimeSpan::_ctor___VOID__I4__I4__I4( CLR_RT_StackFrame& stack ) +HRESULT Library_corlib_native_System_TimeSpan::_ctor___VOID__I4__I4__I4(CLR_RT_StackFrame &stack) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - CLR_RT_HeapBlock* pArgs = &(stack.Arg1()); - CLR_INT64* val = GetValuePtr( stack ); FAULT_ON_NULL(val); + CLR_RT_HeapBlock *pArgs = &(stack.Arg1()); + CLR_INT64 *val = GetValuePtr(stack); + FAULT_ON_NULL(val); - ConstructTimeSpan( val, 0, pArgs[ 0 ].NumericByRef().s4, pArgs[ 1 ].NumericByRef().s4, pArgs[ 2 ].NumericByRef().s4, 0 ); + ConstructTimeSpan(val, 0, pArgs[0].NumericByRef().s4, pArgs[1].NumericByRef().s4, pArgs[2].NumericByRef().s4, 0); NANOCLR_NOCLEANUP(); } -HRESULT Library_corlib_native_System_TimeSpan::_ctor___VOID__I4__I4__I4__I4( CLR_RT_StackFrame& stack ) +HRESULT Library_corlib_native_System_TimeSpan::_ctor___VOID__I4__I4__I4__I4(CLR_RT_StackFrame &stack) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - CLR_RT_HeapBlock* pArgs = &(stack.Arg1()); - CLR_INT64* val = GetValuePtr( stack ); FAULT_ON_NULL(val); + CLR_RT_HeapBlock *pArgs = &(stack.Arg1()); + CLR_INT64 *val = GetValuePtr(stack); + FAULT_ON_NULL(val); - ConstructTimeSpan( val, pArgs[ 0 ].NumericByRef().s4, pArgs[ 1 ].NumericByRef().s4, pArgs[ 2 ].NumericByRef().s4, pArgs[ 3 ].NumericByRef().s4, 0 ); + ConstructTimeSpan( + val, + pArgs[0].NumericByRef().s4, + pArgs[1].NumericByRef().s4, + pArgs[2].NumericByRef().s4, + pArgs[3].NumericByRef().s4, + 0); NANOCLR_NOCLEANUP(); } -HRESULT Library_corlib_native_System_TimeSpan::_ctor___VOID__I4__I4__I4__I4__I4( CLR_RT_StackFrame& stack ) +HRESULT Library_corlib_native_System_TimeSpan::_ctor___VOID__I4__I4__I4__I4__I4(CLR_RT_StackFrame &stack) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - CLR_RT_HeapBlock* pArgs = &(stack.Arg1()); - CLR_INT64* val = GetValuePtr( stack ); FAULT_ON_NULL(val); + CLR_RT_HeapBlock *pArgs = &(stack.Arg1()); + CLR_INT64 *val = GetValuePtr(stack); + FAULT_ON_NULL(val); - ConstructTimeSpan( val, pArgs[ 0 ].NumericByRef().s4, pArgs[ 1 ].NumericByRef().s4, pArgs[ 2 ].NumericByRef().s4, pArgs[ 3 ].NumericByRef().s4, pArgs[ 4 ].NumericByRef().s4 ); + ConstructTimeSpan( + val, + pArgs[0].NumericByRef().s4, + pArgs[1].NumericByRef().s4, + pArgs[2].NumericByRef().s4, + pArgs[3].NumericByRef().s4, + pArgs[4].NumericByRef().s4); NANOCLR_NOCLEANUP(); } -void Library_corlib_native_System_TimeSpan::ConstructTimeSpan( CLR_INT64* val, CLR_INT32 days, CLR_INT32 hours, CLR_INT32 minutes, CLR_INT32 seconds, CLR_INT32 msec ) +void Library_corlib_native_System_TimeSpan::ConstructTimeSpan( + CLR_INT64 *val, + CLR_INT32 days, + CLR_INT32 hours, + CLR_INT32 minutes, + CLR_INT32 seconds, + CLR_INT32 msec) { - *val = ((CLR_INT64)days) * TIME_CONVERSION__ONEDAY + - hours * TIME_CONVERSION__ONEHOUR + - minutes * TIME_CONVERSION__ONEMINUTE + - seconds * TIME_CONVERSION__ONESECOND; + *val = ((CLR_INT64)days) * TIME_CONVERSION__ONEDAY + hours * TIME_CONVERSION__ONEHOUR + + minutes * TIME_CONVERSION__ONEMINUTE + seconds * TIME_CONVERSION__ONESECOND; *val *= 1000; - *val += msec; - *val *= TIME_CONVERSION__TICKUNITS; + + if ((*val == 0) && (msec == -1)) + { + // this is the edge case for creating a System.Threading.Timeout.InfiniteTimeSpan + *val = -1; + } + else + { + // remaining situation, just take the milliseconds value as it is and convert to ticks + *val += msec; + *val *= TIME_CONVERSION__TICKUNITS; + } } -HRESULT Library_corlib_native_System_TimeSpan::CompareTo___I4__OBJECT( CLR_RT_StackFrame& stack ) +HRESULT Library_corlib_native_System_TimeSpan::CompareTo___I4__OBJECT(CLR_RT_StackFrame &stack) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - CLR_RT_HeapBlock* pRight = stack.Arg1().Dereference(); + CLR_RT_HeapBlock *pRight = stack.Arg1().Dereference(); - if(pRight) + if (pRight) { - NANOCLR_SET_AND_LEAVE(Compare___STATIC__I4__SystemTimeSpan__SystemTimeSpan( stack )); + NANOCLR_SET_AND_LEAVE(Compare___STATIC__I4__SystemTimeSpan__SystemTimeSpan(stack)); } - stack.SetResult_I4( 1 ); + stack.SetResult_I4(1); NANOCLR_NOCLEANUP(); } -HRESULT Library_corlib_native_System_TimeSpan::Compare___STATIC__I4__SystemTimeSpan__SystemTimeSpan( CLR_RT_StackFrame& stack ) +HRESULT Library_corlib_native_System_TimeSpan::Compare___STATIC__I4__SystemTimeSpan__SystemTimeSpan( + CLR_RT_StackFrame &stack) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - CLR_INT64* pLeft; - CLR_INT64* pRight; + CLR_INT64 *pLeft; + CLR_INT64 *pRight; CLR_RT_HeapBlock resLeft; CLR_RT_HeapBlock resRight; - pLeft = Library_corlib_native_System_TimeSpan::GetValuePtr( stack ); FAULT_ON_NULL(pLeft); - pRight = Library_corlib_native_System_TimeSpan::GetValuePtr( stack.Arg1() ); FAULT_ON_NULL(pRight); + pLeft = Library_corlib_native_System_TimeSpan::GetValuePtr(stack); + FAULT_ON_NULL(pLeft); + pRight = Library_corlib_native_System_TimeSpan::GetValuePtr(stack.Arg1()); + FAULT_ON_NULL(pRight); - resLeft .SetInteger( *pLeft ); - resRight.SetInteger( *pRight ); + resLeft.SetInteger(*pLeft); + resRight.SetInteger(*pRight); - stack.SetResult_I4( CLR_RT_HeapBlock::Compare_Signed_Values( resLeft, resRight ) ); + stack.SetResult_I4(CLR_RT_HeapBlock::Compare_Signed_Values(resLeft, resRight)); NANOCLR_NOCLEANUP(); } -HRESULT Library_corlib_native_System_TimeSpan::Equals___STATIC__BOOLEAN__SystemTimeSpan__SystemTimeSpan( CLR_RT_StackFrame& stack ) +HRESULT Library_corlib_native_System_TimeSpan::Equals___STATIC__BOOLEAN__SystemTimeSpan__SystemTimeSpan( + CLR_RT_StackFrame &stack) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - NANOCLR_CHECK_HRESULT(Compare___STATIC__I4__SystemTimeSpan__SystemTimeSpan( stack )); + NANOCLR_CHECK_HRESULT(Compare___STATIC__I4__SystemTimeSpan__SystemTimeSpan(stack)); stack.ConvertResultToBoolean(); @@ -143,51 +176,52 @@ HRESULT Library_corlib_native_System_TimeSpan::Equals___STATIC__BOOLEAN__SystemT //--// -CLR_INT64* Library_corlib_native_System_TimeSpan::NewObject( CLR_RT_StackFrame& stack ) +CLR_INT64 *Library_corlib_native_System_TimeSpan::NewObject(CLR_RT_StackFrame &stack) { NATIVE_PROFILE_CLR_CORE(); - CLR_RT_HeapBlock& ref = stack.PushValue(); + CLR_RT_HeapBlock &ref = stack.PushValue(); - ref.SetDataId( CLR_RT_HEAPBLOCK_RAW_ID( DATATYPE_TIMESPAN, 0, 1 ) ); - ref.ClearData( ); + ref.SetDataId(CLR_RT_HEAPBLOCK_RAW_ID(DATATYPE_TIMESPAN, 0, 1)); + ref.ClearData(); - return (CLR_INT64*)&ref.NumericByRef().s8; + return (CLR_INT64 *)&ref.NumericByRef().s8; } -CLR_INT64* Library_corlib_native_System_TimeSpan::GetValuePtr( CLR_RT_StackFrame& stack ) +CLR_INT64 *Library_corlib_native_System_TimeSpan::GetValuePtr(CLR_RT_StackFrame &stack) { NATIVE_PROFILE_CLR_CORE(); - return GetValuePtr( stack.Arg0() ); + return GetValuePtr(stack.Arg0()); } -CLR_INT64* Library_corlib_native_System_TimeSpan::GetValuePtr( CLR_RT_HeapBlock& ref ) +CLR_INT64 *Library_corlib_native_System_TimeSpan::GetValuePtr(CLR_RT_HeapBlock &ref) { NATIVE_PROFILE_CLR_CORE(); - CLR_RT_HeapBlock* obj = &ref; - CLR_DataType dt = obj->DataType(); + CLR_RT_HeapBlock *obj = &ref; + CLR_DataType dt = obj->DataType(); - if(dt == DATATYPE_OBJECT || dt == DATATYPE_BYREF) + if (dt == DATATYPE_OBJECT || dt == DATATYPE_BYREF) { - obj = obj->Dereference(); if(!obj) return NULL; + obj = obj->Dereference(); + if (!obj) + return NULL; dt = obj->DataType(); } - if(dt == DATATYPE_TIMESPAN) + if (dt == DATATYPE_TIMESPAN) { - return (CLR_INT64*)&obj->NumericByRef().s8; + return (CLR_INT64 *)&obj->NumericByRef().s8; } - if(dt == DATATYPE_I8) + if (dt == DATATYPE_I8) { - return (CLR_INT64*)&obj->NumericByRef().s8; + return (CLR_INT64 *)&obj->NumericByRef().s8; } - if(dt == DATATYPE_VALUETYPE && obj->ObjectCls().m_data == g_CLR_RT_WellKnownTypes.m_TimeSpan.m_data) + if (dt == DATATYPE_VALUETYPE && obj->ObjectCls().m_data == g_CLR_RT_WellKnownTypes.m_TimeSpan.m_data) { - return (CLR_INT64*)&obj[ FIELD___ticks ].NumericByRef().s8; + return (CLR_INT64 *)&obj[FIELD___ticks].NumericByRef().s8; } return NULL; } - diff --git a/src/CLR/CorLib/corlib_native_System_Type.cpp b/src/CLR/CorLib/corlib_native_System_Type.cpp index 71702da9f5..87f2f0abd0 100644 --- a/src/CLR/CorLib/corlib_native_System_Type.cpp +++ b/src/CLR/CorLib/corlib_native_System_Type.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/CorLib/corlib_native_System_ValueType.cpp b/src/CLR/CorLib/corlib_native_System_ValueType.cpp index fe06deafe8..21ba850324 100644 --- a/src/CLR/CorLib/corlib_native_System_ValueType.cpp +++ b/src/CLR/CorLib/corlib_native_System_ValueType.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/CorLib/corlib_native_System_WeakReference.cpp b/src/CLR/CorLib/corlib_native_System_WeakReference.cpp index edc390bbbf..feb334c164 100644 --- a/src/CLR/CorLib/corlib_native_System_WeakReference.cpp +++ b/src/CLR/CorLib/corlib_native_System_WeakReference.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Core/CLR_RT_DblLinkedList.cpp b/src/CLR/Core/CLR_RT_DblLinkedList.cpp index c5ab184ce2..a438c27683 100644 --- a/src/CLR/Core/CLR_RT_DblLinkedList.cpp +++ b/src/CLR/Core/CLR_RT_DblLinkedList.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Core/CLR_RT_HeapBlock.cpp b/src/CLR/Core/CLR_RT_HeapBlock.cpp index 47dbf15439..83a6be905b 100644 --- a/src/CLR/Core/CLR_RT_HeapBlock.cpp +++ b/src/CLR/Core/CLR_RT_HeapBlock.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Core/CLR_RT_HeapBlock_Array.cpp b/src/CLR/Core/CLR_RT_HeapBlock_Array.cpp index 23da842629..49d41fc704 100644 --- a/src/CLR/Core/CLR_RT_HeapBlock_Array.cpp +++ b/src/CLR/Core/CLR_RT_HeapBlock_Array.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Core/CLR_RT_HeapBlock_ArrayList.cpp b/src/CLR/Core/CLR_RT_HeapBlock_ArrayList.cpp index 80e26d1a3c..f59b1393da 100644 --- a/src/CLR/Core/CLR_RT_HeapBlock_ArrayList.cpp +++ b/src/CLR/Core/CLR_RT_HeapBlock_ArrayList.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Core/CLR_RT_HeapBlock_BinaryBlob.cpp b/src/CLR/Core/CLR_RT_HeapBlock_BinaryBlob.cpp index e871bc8641..7a224eba5b 100644 --- a/src/CLR/Core/CLR_RT_HeapBlock_BinaryBlob.cpp +++ b/src/CLR/Core/CLR_RT_HeapBlock_BinaryBlob.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Core/CLR_RT_HeapBlock_Delegate.cpp b/src/CLR/Core/CLR_RT_HeapBlock_Delegate.cpp index 5af4e0b55b..4d817403e3 100644 --- a/src/CLR/Core/CLR_RT_HeapBlock_Delegate.cpp +++ b/src/CLR/Core/CLR_RT_HeapBlock_Delegate.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Core/CLR_RT_HeapBlock_Delegate_List.cpp b/src/CLR/Core/CLR_RT_HeapBlock_Delegate_List.cpp index e9a199b5a8..aad6c405b8 100644 --- a/src/CLR/Core/CLR_RT_HeapBlock_Delegate_List.cpp +++ b/src/CLR/Core/CLR_RT_HeapBlock_Delegate_List.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Core/CLR_RT_HeapBlock_Finalizer.cpp b/src/CLR/Core/CLR_RT_HeapBlock_Finalizer.cpp index c06cee13cb..3ce13a981a 100644 --- a/src/CLR/Core/CLR_RT_HeapBlock_Finalizer.cpp +++ b/src/CLR/Core/CLR_RT_HeapBlock_Finalizer.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Core/CLR_RT_HeapBlock_Lock.cpp b/src/CLR/Core/CLR_RT_HeapBlock_Lock.cpp index 99a040c7da..bf127f1077 100644 --- a/src/CLR/Core/CLR_RT_HeapBlock_Lock.cpp +++ b/src/CLR/Core/CLR_RT_HeapBlock_Lock.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Core/CLR_RT_HeapBlock_LockRequest.cpp b/src/CLR/Core/CLR_RT_HeapBlock_LockRequest.cpp index 807f4fcb11..4013e89e75 100644 --- a/src/CLR/Core/CLR_RT_HeapBlock_LockRequest.cpp +++ b/src/CLR/Core/CLR_RT_HeapBlock_LockRequest.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Core/CLR_RT_HeapBlock_Node.cpp b/src/CLR/Core/CLR_RT_HeapBlock_Node.cpp index 1ece561122..0d69072e85 100644 --- a/src/CLR/Core/CLR_RT_HeapBlock_Node.cpp +++ b/src/CLR/Core/CLR_RT_HeapBlock_Node.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Core/CLR_RT_HeapBlock_Queue.cpp b/src/CLR/Core/CLR_RT_HeapBlock_Queue.cpp index 85b6c1764e..116d4e00bb 100644 --- a/src/CLR/Core/CLR_RT_HeapBlock_Queue.cpp +++ b/src/CLR/Core/CLR_RT_HeapBlock_Queue.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Core/CLR_RT_HeapBlock_Stack.cpp b/src/CLR/Core/CLR_RT_HeapBlock_Stack.cpp index 0b64745a24..6069f7235d 100644 --- a/src/CLR/Core/CLR_RT_HeapBlock_Stack.cpp +++ b/src/CLR/Core/CLR_RT_HeapBlock_Stack.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Core/CLR_RT_HeapBlock_String.cpp b/src/CLR/Core/CLR_RT_HeapBlock_String.cpp index 69b849df3e..e0638e84ed 100644 --- a/src/CLR/Core/CLR_RT_HeapBlock_String.cpp +++ b/src/CLR/Core/CLR_RT_HeapBlock_String.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Core/CLR_RT_HeapBlock_Timer.cpp b/src/CLR/Core/CLR_RT_HeapBlock_Timer.cpp index f04bccb05f..d88f7e7f58 100644 --- a/src/CLR/Core/CLR_RT_HeapBlock_Timer.cpp +++ b/src/CLR/Core/CLR_RT_HeapBlock_Timer.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Core/CLR_RT_HeapBlock_WaitForObject.cpp b/src/CLR/Core/CLR_RT_HeapBlock_WaitForObject.cpp index aa42285ffb..5fc15290af 100644 --- a/src/CLR/Core/CLR_RT_HeapBlock_WaitForObject.cpp +++ b/src/CLR/Core/CLR_RT_HeapBlock_WaitForObject.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Core/CLR_RT_HeapCluster.cpp b/src/CLR/Core/CLR_RT_HeapCluster.cpp index bacf114fa3..8b87ad95f0 100644 --- a/src/CLR/Core/CLR_RT_HeapCluster.cpp +++ b/src/CLR/Core/CLR_RT_HeapCluster.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Core/CLR_RT_Interop.cpp b/src/CLR/Core/CLR_RT_Interop.cpp index 7613871cf3..1764eaa2ef 100644 --- a/src/CLR/Core/CLR_RT_Interop.cpp +++ b/src/CLR/Core/CLR_RT_Interop.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Core/CLR_RT_Memory.cpp b/src/CLR/Core/CLR_RT_Memory.cpp index 493bf048d1..7377603b7d 100644 --- a/src/CLR/Core/CLR_RT_Memory.cpp +++ b/src/CLR/Core/CLR_RT_Memory.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Core/CLR_RT_ObjectToEvent_Destination.cpp b/src/CLR/Core/CLR_RT_ObjectToEvent_Destination.cpp index 6f11dad9ca..316c4cdd21 100644 --- a/src/CLR/Core/CLR_RT_ObjectToEvent_Destination.cpp +++ b/src/CLR/Core/CLR_RT_ObjectToEvent_Destination.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Core/CLR_RT_ObjectToEvent_Source.cpp b/src/CLR/Core/CLR_RT_ObjectToEvent_Source.cpp index 57dbe957b3..18a0d3426b 100644 --- a/src/CLR/Core/CLR_RT_ObjectToEvent_Source.cpp +++ b/src/CLR/Core/CLR_RT_ObjectToEvent_Source.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Core/CLR_RT_RuntimeMemory.cpp b/src/CLR/Core/CLR_RT_RuntimeMemory.cpp index 0a5902e299..73f34f35be 100644 --- a/src/CLR/Core/CLR_RT_RuntimeMemory.cpp +++ b/src/CLR/Core/CLR_RT_RuntimeMemory.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Core/CLR_RT_StackFrame.cpp b/src/CLR/Core/CLR_RT_StackFrame.cpp index f2a869c542..af597131b4 100644 --- a/src/CLR/Core/CLR_RT_StackFrame.cpp +++ b/src/CLR/Core/CLR_RT_StackFrame.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Core/CLR_RT_SystemAssembliesTable.cpp b/src/CLR/Core/CLR_RT_SystemAssembliesTable.cpp index e078c67ee4..9ea9d85d30 100644 --- a/src/CLR/Core/CLR_RT_SystemAssembliesTable.cpp +++ b/src/CLR/Core/CLR_RT_SystemAssembliesTable.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Core/CLR_RT_UnicodeHelper.cpp b/src/CLR/Core/CLR_RT_UnicodeHelper.cpp index 86ca3a81db..0b90975a34 100644 --- a/src/CLR/Core/CLR_RT_UnicodeHelper.cpp +++ b/src/CLR/Core/CLR_RT_UnicodeHelper.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Core/Cache.cpp b/src/CLR/Core/Cache.cpp index 0552404435..f67fe5f2e0 100644 --- a/src/CLR/Core/Cache.cpp +++ b/src/CLR/Core/Cache.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Core/Checks.cpp b/src/CLR/Core/Checks.cpp index cc4984b631..367e9dd86a 100644 --- a/src/CLR/Core/Checks.cpp +++ b/src/CLR/Core/Checks.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Core/Core.cpp b/src/CLR/Core/Core.cpp index d190286933..fbe6e6888d 100644 --- a/src/CLR/Core/Core.cpp +++ b/src/CLR/Core/Core.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Core/Core.h b/src/CLR/Core/Core.h index 1a5f4e57e2..43e321532f 100644 --- a/src/CLR/Core/Core.h +++ b/src/CLR/Core/Core.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Core/Execution.cpp b/src/CLR/Core/Execution.cpp index 7f0f6736a1..0d5dcff50d 100644 --- a/src/CLR/Core/Execution.cpp +++ b/src/CLR/Core/Execution.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // @@ -11,10 +11,9 @@ static const CLR_INT64 c_MaximumTimeToActive = (TIME_CONVERSION__ONEMINUTE * TIME_CONVERSION__TO_SECONDS); - //--// -CLR_RT_ExecutionEngine::ExecutionConstraintCompensation CLR_RT_ExecutionEngine::s_compensation = { 0, 0, 0 }; +CLR_RT_ExecutionEngine::ExecutionConstraintCompensation CLR_RT_ExecutionEngine::s_compensation = {0, 0, 0}; //--// @@ -37,63 +36,62 @@ HRESULT CLR_RT_ExecutionEngine::ExecutionEngine_Initialize() NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - m_maximumTimeToActive = c_MaximumTimeToActive; // CLR_INT64 m_maximumTimeToActive - // int m_iDebugger_Conditions; - // + m_maximumTimeToActive = c_MaximumTimeToActive; // CLR_INT64 m_maximumTimeToActive + // int m_iDebugger_Conditions; + // - // CLR_INT64 m_currentNextActivityTime; - m_timerCache = false; // bool m_timerCache; + // CLR_INT64 m_currentNextActivityTime; + m_timerCache = false; // bool m_timerCache; // CLR_INT64 m_timerCacheNextTimeout; // - m_heap .DblLinkedList_Initialize(); // CLR_RT_DblLinkedList m_heap; + m_heap.DblLinkedList_Initialize(); // CLR_RT_DblLinkedList m_heap; // CLR_RT_HeapCluster* m_lastHcUsed; - m_heapState = c_HeapState_Normal; // int m_heapState; + m_heapState = c_HeapState_Normal; // int m_heapState; // m_weakReferences.DblLinkedList_Initialize(); // CLR_RT_DblLinkedList m_weakReferences; // - m_timers .DblLinkedList_Initialize(); // CLR_RT_DblLinkedList m_timers; - m_raisedEvents = 0; // CLR_UINT32 m_raisedEvents; + m_timers.DblLinkedList_Initialize(); // CLR_RT_DblLinkedList m_timers; + m_raisedEvents = 0; // CLR_UINT32 m_raisedEvents; // - m_threadsReady .DblLinkedList_Initialize(); // CLR_RT_DblLinkedList m_threadsReady; + m_threadsReady.DblLinkedList_Initialize(); // CLR_RT_DblLinkedList m_threadsReady; m_threadsWaiting.DblLinkedList_Initialize(); // CLR_RT_DblLinkedList m_threadsWaiting; - m_threadsZombie .DblLinkedList_Initialize(); // CLR_RT_DblLinkedList m_threadsZombie; + m_threadsZombie.DblLinkedList_Initialize(); // CLR_RT_DblLinkedList m_threadsZombie; // int m_lastPid; // - m_finalizersAlive .DblLinkedList_Initialize(); // CLR_RT_DblLinkedList m_finalizersAlive; + m_finalizersAlive.DblLinkedList_Initialize(); // CLR_RT_DblLinkedList m_finalizersAlive; m_finalizersPending.DblLinkedList_Initialize(); // CLR_RT_DblLinkedList m_finalizersPending; // CLR_RT_Thread* m_finalizerThread; // CLR_RT_Thread* m_cctorThread; // #if !defined(NANOCLR_APPDOMAINS) - m_globalLock = NULL; // CLR_RT_HeapBlock* m_globalLock; - m_outOfMemoryException = NULL; // CLR_RT_HeapBlock* m_outOfMemoryException; -#endif // + m_globalLock = NULL; // CLR_RT_HeapBlock* m_globalLock; + m_outOfMemoryException = NULL; // CLR_RT_HeapBlock* m_outOfMemoryException; +#endif // - m_currentUICulture = NULL; // CLR_RT_HeapBlock* m_currentUICulture; + m_currentUICulture = NULL; // CLR_RT_HeapBlock* m_currentUICulture; - CLR_RT_HeapBlock_EndPoint::HandlerMethod_Initialize(); + CLR_RT_HeapBlock_EndPoint::HandlerMethod_Initialize(); CLR_RT_HeapBlock_NativeEventDispatcher::HandlerMethod_Initialize(); - m_interruptThread = NULL; // CLR_RT_Thread m_interruptThread; + m_interruptThread = NULL; // CLR_RT_Thread m_interruptThread; #if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) - m_scratchPadArray = NULL; // CLR_RT_HeapBlock_Array* m_scratchPadArray; -#endif //#if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) - + m_scratchPadArray = NULL; // CLR_RT_HeapBlock_Array* m_scratchPadArray; +#endif //#if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) #if defined(NANOCLR_APPDOMAINS) - m_appDomains.DblLinkedList_Initialize(); // CLR_RT_DblLinkedList m_appDomains; - - m_appDomainCurrent = NULL; // CLR_AppDomainCurrent* m_appDomainCurrent; - m_appDomainIdNext = c_AppDomainId_Invalid + 1; // int m_appDomainIdNext; + m_appDomains.DblLinkedList_Initialize(); // CLR_RT_DblLinkedList m_appDomains; + + m_appDomainCurrent = NULL; // CLR_AppDomainCurrent* m_appDomainCurrent; + m_appDomainIdNext = c_AppDomainId_Invalid + 1; // int m_appDomainIdNext; #endif - m_currentThread = NULL; + m_currentThread = NULL; m_GlobalExecutionCounter = 0; #if !defined(BUILD_RTM) - m_fShuttingDown = false; //bool m_fShuttingDown; + m_fShuttingDown = false; // bool m_fShuttingDown; #endif //--// @@ -110,7 +108,7 @@ HRESULT CLR_RT_ExecutionEngine::ExecutionEngine_Initialize() //--// NANOCLR_CHECK_HRESULT(CLR_Messaging::CreateInstance()); - + NANOCLR_CHECK_HRESULT(CLR_DBG_Debugger::CreateInstance()); #if defined(NANOCLR_PROFILE_NEW) @@ -118,12 +116,12 @@ HRESULT CLR_RT_ExecutionEngine::ExecutionEngine_Initialize() #endif #if defined(NANOCLR_APPDOMAINS) - NANOCLR_CHECK_HRESULT(CLR_RT_AppDomain::CreateInstance( "default", m_appDomainCurrent )); + NANOCLR_CHECK_HRESULT(CLR_RT_AppDomain::CreateInstance("default", m_appDomainCurrent)); #endif m_startTime = HAL_Time_CurrentTime(); - CLR_RT_HeapBlock_WeakReference::RecoverObjects( m_heap ); + CLR_RT_HeapBlock_WeakReference::RecoverObjects(m_heap); //--// @@ -137,53 +135,53 @@ HRESULT CLR_RT_ExecutionEngine::AllocateHeaps() const CLR_UINT32 c_HeapClusterSize = sizeof(CLR_RT_HeapBlock) * CLR_RT_HeapBlock::HB_MaxSize; - CLR_UINT8* heapFirstFree = s_CLR_RT_Heap.m_location; - CLR_UINT32 heapFree = s_CLR_RT_Heap.m_size; - CLR_INT32 i = 0; - CLR_UINT32 blockSize = 1; + CLR_UINT8 *heapFirstFree = s_CLR_RT_Heap.m_location; + CLR_UINT32 heapFree = s_CLR_RT_Heap.m_size; + CLR_INT32 i = 0; + CLR_UINT32 blockSize = 1; - if(heapFree <= sizeof(CLR_RT_HeapCluster)) + if (heapFree <= sizeof(CLR_RT_HeapCluster)) { NANOCLR_SET_AND_LEAVE(CLR_E_OUT_OF_MEMORY); } - while(heapFree > sizeof(CLR_RT_HeapCluster)) + while (heapFree > sizeof(CLR_RT_HeapCluster)) { - CLR_RT_HeapCluster* hc = (CLR_RT_HeapCluster*) heapFirstFree; - CLR_UINT32 size = (heapFree < c_HeapClusterSize) ? heapFree : c_HeapClusterSize; + CLR_RT_HeapCluster *hc = (CLR_RT_HeapCluster *)heapFirstFree; + CLR_UINT32 size = (heapFree < c_HeapClusterSize) ? heapFree : c_HeapClusterSize; #if NANOCLR_VALIDATE_HEAP >= NANOCLR_VALIDATE_HEAP_1_HeapBlocksAndUnlink - CLR_Debug::Printf( "Heap Cluster information\r\n"); - CLR_Debug::Printf( "Start: %08x\r\n", (size_t)heapFirstFree); - CLR_Debug::Printf( "Free: %08x\r\n", (size_t)heapFree); - CLR_Debug::Printf( "Block size: %d\r\n", sizeof(CLR_RT_HeapBlock)); + CLR_Debug::Printf("Heap Cluster information\r\n"); + CLR_Debug::Printf("Start: %08x\r\n", (size_t)heapFirstFree); + CLR_Debug::Printf("Free: %08x\r\n", (size_t)heapFree); + CLR_Debug::Printf("Block size: %d\r\n", sizeof(CLR_RT_HeapBlock)); #endif /// /// Speed up heap initialization for devices with very large heaps > 1MB /// Exponentially increase the size of a default heap block /// - if(i > 100*1024*1024) + if (i > 100 * 1024 * 1024) { blockSize = CLR_RT_HeapBlock::HB_MaxSize; } - else if( i > 10*1024*1024) + else if (i > 10 * 1024 * 1024) { - blockSize = 10*1024; + blockSize = 10 * 1024; } - else if(i > 1024*1024) + else if (i > 1024 * 1024) { - blockSize = 1*1024; + blockSize = 1 * 1024; } - hc->HeapCluster_Initialize( size, blockSize ); + hc->HeapCluster_Initialize(size, blockSize); - m_heap.LinkAtBack( hc ); + m_heap.LinkAtBack(hc); heapFirstFree += size; - heapFree -= size; - i += size; + heapFree -= size; + i += size; } NANOCLR_NOCLEANUP(); @@ -195,7 +193,7 @@ HRESULT CLR_RT_ExecutionEngine::DeleteInstance() { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - + g_CLR_RT_ExecutionEngine.ExecutionEngine_Cleanup(); NANOCLR_NOCLEANUP_NOLABEL(); @@ -207,8 +205,8 @@ void CLR_RT_ExecutionEngine::ExecutionEngine_Cleanup() // developer notes: // Most of the following calls are just for pure ceremony and gracefully terminating stuff, // cleaning collections and such. - // In particular the previous existing calls to Abort threads and ReleaseAllThreads is completely irrelevant - // because the execution engine wasn't running anymore. Whatever code that is on those threads + // In particular the previous existing calls to Abort threads and ReleaseAllThreads is completely irrelevant + // because the execution engine wasn't running anymore. Whatever code that is on those threads // there to be executed wouldn't never be executed anyways. ///////////////////////////////////////////////////////////////////////////////////////////////// @@ -230,7 +228,7 @@ void CLR_RT_ExecutionEngine::ExecutionEngine_Cleanup() CLR_HW_Hardware::DeleteInstance(); - m_finalizersAlive .DblLinkedList_PushToCache(); + m_finalizersAlive.DblLinkedList_PushToCache(); m_finalizersPending.DblLinkedList_PushToCache(); m_finalizerThread = NULL; m_cctorThread = NULL; @@ -243,10 +241,10 @@ void CLR_RT_ExecutionEngine::ExecutionEngine_Cleanup() m_globalLock = NULL; #endif - CLR_RT_HeapBlock_EndPoint::HandlerMethod_CleanUp(); + CLR_RT_HeapBlock_EndPoint::HandlerMethod_CleanUp(); CLR_RT_HeapBlock_NativeEventDispatcher::HandlerMethod_CleanUp(); - m_interruptThread = NULL; + m_interruptThread = NULL; m_heap.DblLinkedList_Initialize(); } @@ -263,11 +261,11 @@ HRESULT CLR_RT_ExecutionEngine::StartHardware() NANOCLR_NOCLEANUP(); } -void CLR_RT_ExecutionEngine::Reboot( bool fHard ) +void CLR_RT_ExecutionEngine::Reboot(bool fHard) { NATIVE_PROFILE_CLR_CORE(); - if(fHard) + if (fHard) { ::CPU_Reset(); } @@ -289,30 +287,31 @@ void CLR_RT_ExecutionEngine::JoinAllThreadsAndExecuteFinalizer() void CLR_RT_ExecutionEngine::LoadDownloadedAssemblies() { - NATIVE_PROFILE_CLR_CORE (); + NATIVE_PROFILE_CLR_CORE(); PerformGarbageCollection(); - PerformHeapCompaction (); + PerformHeapCompaction(); // // Load any patch or similar! // - NANOCLR_FOREACH_NODE(CLR_RT_HeapBlock_WeakReference,weak,m_weakReferences) + NANOCLR_FOREACH_NODE(CLR_RT_HeapBlock_WeakReference, weak, m_weakReferences) { - if((weak->m_identity.m_flags & CLR_RT_HeapBlock_WeakReference::WR_ArrayOfBytes) != 0 && weak->m_targetSerialized) + if ((weak->m_identity.m_flags & CLR_RT_HeapBlock_WeakReference::WR_ArrayOfBytes) != 0 && + weak->m_targetSerialized) { - CLR_RECORD_ASSEMBLY* header; + CLR_RECORD_ASSEMBLY *header; - header = (CLR_RECORD_ASSEMBLY*)weak->m_targetSerialized->GetFirstElement(); + header = (CLR_RECORD_ASSEMBLY *)weak->m_targetSerialized->GetFirstElement(); - if(header->GoodAssembly()) + if (header->GoodAssembly()) { - CLR_RT_Assembly* assm = NULL; + CLR_RT_Assembly *assm = NULL; - if(SUCCEEDED(CLR_RT_Assembly::CreateInstance( header, assm ))) + if (SUCCEEDED(CLR_RT_Assembly::CreateInstance(header, assm))) { assm->m_pFile = weak->m_targetSerialized; - g_CLR_RT_TypeSystem.Link( assm ); + g_CLR_RT_TypeSystem.Link(assm); } } } @@ -323,12 +322,12 @@ void CLR_RT_ExecutionEngine::LoadDownloadedAssemblies() NANOCLR_FOREACH_ASSEMBLY(g_CLR_RT_TypeSystem) { - if(pASSM->m_pFile) + if (pASSM->m_pFile) { // // For those assemblies that failed to load (missing dependency?), clean up. // - if((pASSM->m_flags & CLR_RT_Assembly::ResolutionCompleted) == 0) + if ((pASSM->m_flags & CLR_RT_Assembly::ResolutionCompleted) == 0) { pASSM->m_pFile = NULL; @@ -369,7 +368,8 @@ CLR_UINT32 CLR_RT_ExecutionEngine::PerformGarbageCollection() m_lastHcUsed = NULL; #if !defined(BUILD_RTM) || defined(_WIN32) - if(m_fPerformHeapCompaction) CLR_EE_SET( Compaction_Pending ); + if (m_fPerformHeapCompaction) + CLR_EE_SET(Compaction_Pending); #endif g_CLR_RT_ExecutionEngine.SpawnFinalizer(); @@ -380,11 +380,12 @@ CLR_UINT32 CLR_RT_ExecutionEngine::PerformGarbageCollection() void CLR_RT_ExecutionEngine::PerformHeapCompaction() { NATIVE_PROFILE_CLR_CORE(); - if(CLR_EE_DBG_IS( NoCompaction )) return; + if (CLR_EE_DBG_IS(NoCompaction)) + return; g_CLR_RT_GarbageCollector.ExecuteCompaction(); - CLR_EE_CLR( Compaction_Pending ); + CLR_EE_CLR(Compaction_Pending); m_lastHcUsed = NULL; } @@ -393,15 +394,15 @@ void CLR_RT_ExecutionEngine::Relocate() { NATIVE_PROFILE_CLR_CORE(); #if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) - CLR_RT_GarbageCollector::Heap_Relocate( (void**)&m_scratchPadArray ); + CLR_RT_GarbageCollector::Heap_Relocate((void **)&m_scratchPadArray); #endif //#if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) #if !defined(NANOCLR_APPDOMAINS) - CLR_RT_GarbageCollector::Heap_Relocate( (void**)&m_globalLock ); - //CLR_RT_GarbageCollector::Heap_Relocate( (void**)&m_outOfMemoryException ); + CLR_RT_GarbageCollector::Heap_Relocate((void **)&m_globalLock); + // CLR_RT_GarbageCollector::Heap_Relocate( (void**)&m_outOfMemoryException ); #endif - CLR_RT_GarbageCollector::Heap_Relocate( (void**)&m_currentUICulture ); + CLR_RT_GarbageCollector::Heap_Relocate((void **)&m_currentUICulture); m_weakReferences.Relocate(); } @@ -410,16 +411,16 @@ void CLR_RT_ExecutionEngine::Relocate() #if defined(NANOCLR_APPDOMAINS) -void CLR_RT_ExecutionEngine::TryToUnloadAppDomains_Helper_Threads( CLR_RT_DblLinkedList& threads ) -{ +void CLR_RT_ExecutionEngine::TryToUnloadAppDomains_Helper_Threads(CLR_RT_DblLinkedList &threads) +{ NATIVE_PROFILE_CLR_CORE(); - NANOCLR_FOREACH_NODE(CLR_RT_Thread,th,threads) + NANOCLR_FOREACH_NODE(CLR_RT_Thread, th, threads) { - if(th->m_flags & CLR_RT_Thread::TH_F_ContainsDoomedAppDomain) + if (th->m_flags & CLR_RT_Thread::TH_F_ContainsDoomedAppDomain) { NANOCLR_FOREACH_NODE(CLR_RT_StackFrame, stack, th->m_stackFrames) { - stack->m_appDomain->m_fCanBeUnloaded = false; + stack->m_appDomain->m_fCanBeUnloaded = false; } NANOCLR_FOREACH_NODE_END(); } @@ -427,18 +428,18 @@ void CLR_RT_ExecutionEngine::TryToUnloadAppDomains_Helper_Threads( CLR_RT_DblLin NANOCLR_FOREACH_NODE_END(); } -void CLR_RT_ExecutionEngine::TryToUnloadAppDomains_Helper_Finalizers( CLR_RT_DblLinkedList& finalizers, bool fAlive ) +void CLR_RT_ExecutionEngine::TryToUnloadAppDomains_Helper_Finalizers(CLR_RT_DblLinkedList &finalizers, bool fAlive) { NATIVE_PROFILE_CLR_CORE(); - NANOCLR_FOREACH_NODE(CLR_RT_HeapBlock_Finalizer,fin,finalizers) + NANOCLR_FOREACH_NODE(CLR_RT_HeapBlock_Finalizer, fin, finalizers) { - if(!fin->m_appDomain->IsLoaded()) + if (!fin->m_appDomain->IsLoaded()) { - if(fAlive) + if (fAlive) { - //When an AppDomain is being unloaded, all live finalizers are run, regardless - //of whether or not they are still reachable. - m_finalizersPending.LinkAtBack( fin ); + // When an AppDomain is being unloaded, all live finalizers are run, regardless + // of whether or not they are still reachable. + m_finalizersPending.LinkAtBack(fin); } fin->m_appDomain->m_fCanBeUnloaded = false; @@ -452,26 +453,26 @@ bool CLR_RT_ExecutionEngine::TryToUnloadAppDomains() NATIVE_PROFILE_CLR_CORE(); bool fAnyAppDomainsUnloaded = false; - NANOCLR_FOREACH_NODE(CLR_RT_AppDomain,appDomain,m_appDomains) + NANOCLR_FOREACH_NODE(CLR_RT_AppDomain, appDomain, m_appDomains) { appDomain->m_fCanBeUnloaded = true; } NANOCLR_FOREACH_NODE_END(); - TryToUnloadAppDomains_Helper_Finalizers( m_finalizersAlive , true ); - TryToUnloadAppDomains_Helper_Finalizers( m_finalizersPending, false ); - - TryToUnloadAppDomains_Helper_Threads( m_threadsReady ); - TryToUnloadAppDomains_Helper_Threads( m_threadsWaiting ); + TryToUnloadAppDomains_Helper_Finalizers(m_finalizersAlive, true); + TryToUnloadAppDomains_Helper_Finalizers(m_finalizersPending, false); + + TryToUnloadAppDomains_Helper_Threads(m_threadsReady); + TryToUnloadAppDomains_Helper_Threads(m_threadsWaiting); + + CLR_EE_CLR(UnloadingAppDomain); - CLR_EE_CLR( UnloadingAppDomain ); - - NANOCLR_FOREACH_NODE(CLR_RT_AppDomain,appDomain,m_appDomains) + NANOCLR_FOREACH_NODE(CLR_RT_AppDomain, appDomain, m_appDomains) { - if(appDomain->m_state == CLR_RT_AppDomain::AppDomainState_Unloading) + if (appDomain->m_state == CLR_RT_AppDomain::AppDomainState_Unloading) { - if(appDomain->m_fCanBeUnloaded) - { + if (appDomain->m_fCanBeUnloaded) + { appDomain->m_state = CLR_RT_AppDomain::AppDomainState_Unloaded; appDomain->AppDomain_Uninitialize(); fAnyAppDomainsUnloaded = true; @@ -484,9 +485,9 @@ bool CLR_RT_ExecutionEngine::TryToUnloadAppDomains() } NANOCLR_FOREACH_NODE_END(); - if(fAnyAppDomainsUnloaded) - { - SignalEvents( CLR_RT_ExecutionEngine::c_Event_AppDomain ); + if (fAnyAppDomainsUnloaded) + { + SignalEvents(Event_AppDomain); #if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) Breakpoint_Assemblies_Loaded(); #endif //#if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) @@ -502,11 +503,11 @@ HRESULT CLR_RT_ExecutionEngine::WaitForDebugger() NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - while(CLR_EE_DBG_IS(Stopped) && !CLR_EE_DBG_IS(RebootPending) && !CLR_EE_DBG_IS(ExitPending)) + while (CLR_EE_DBG_IS(Stopped) && !CLR_EE_DBG_IS(RebootPending) && !CLR_EE_DBG_IS(ExitPending)) { // TODO: Generalize this as a standard HAL API #if defined(WIN32) - if(HAL_Windows_IsShutdownPending()) + if (HAL_Windows_IsShutdownPending()) { NANOCLR_SET_AND_LEAVE(CLR_E_SHUTTING_DOWN); } @@ -519,65 +520,65 @@ HRESULT CLR_RT_ExecutionEngine::WaitForDebugger() NANOCLR_NOCLEANUP(); #else NANOCLR_NOCLEANUP_NOLABEL(); -#endif +#endif } #if defined(WIN32) -HRESULT CLR_RT_ExecutionEngine::CreateEntryPointArgs( CLR_RT_HeapBlock& argsBlk, wchar_t* szCommandLineArgs ) +HRESULT CLR_RT_ExecutionEngine::CreateEntryPointArgs(CLR_RT_HeapBlock &argsBlk, wchar_t *szCommandLineArgs) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - + std::list args; - wchar_t* szArgNext = NULL; - wchar_t* szArg = szCommandLineArgs; - wchar_t* sep = L" "; - wchar_t* context = NULL; - - szArg = wcstok_s( szArg, sep, &context ); - - while(szArg != NULL) + wchar_t *szArgNext = NULL; + wchar_t *szArg = szCommandLineArgs; + wchar_t *sep = L" "; + wchar_t *context = NULL; + + szArg = wcstok_s(szArg, sep, &context); + + while (szArg != NULL) { - std::wstring arg = szArg; - args.insert( args.end(), arg ); - - szArg = wcstok_s( NULL, sep, &context ); + std::wstring arg = szArg; + args.insert(args.end(), arg); + + szArg = wcstok_s(NULL, sep, &context); } - NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_Array::CreateInstance( argsBlk, (CLR_UINT32)args.size(), g_CLR_RT_WellKnownTypes.m_String )); - - CLR_RT_HeapBlock_Array* array = argsBlk.Array(); + NANOCLR_CHECK_HRESULT( + CLR_RT_HeapBlock_Array::CreateInstance(argsBlk, (CLR_UINT32)args.size(), g_CLR_RT_WellKnownTypes.m_String)); + + CLR_RT_HeapBlock_Array *array = argsBlk.Array(); CLR_UINT32 iArg = 0; - for(std::list::iterator it = args.begin(); it != args.end(); it++, iArg++) + for (std::list::iterator it = args.begin(); it != args.end(); it++, iArg++) { std::string arg; - CLR_RT_HeapBlock* blk = (CLR_RT_HeapBlock*)array->GetElement( iArg ); - CLR_RT_UnicodeHelper::ConvertToUTF8( (*it).c_str(), arg ); + CLR_RT_HeapBlock *blk = (CLR_RT_HeapBlock *)array->GetElement(iArg); + CLR_RT_UnicodeHelper::ConvertToUTF8((*it).c_str(), arg); + + NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_String::CreateInstance(*blk, arg.c_str())); + } - NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_String::CreateInstance( *blk, arg.c_str() )); - } - NANOCLR_NOCLEANUP(); } #endif -HRESULT CLR_RT_ExecutionEngine::Execute( wchar_t* entryPointArgs, int maxContextSwitch ) -{ +HRESULT CLR_RT_ExecutionEngine::Execute(wchar_t *entryPointArgs, int maxContextSwitch) +{ NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); CLR_RT_HeapBlock ref; - CLR_RT_Thread* thMain = NULL; + CLR_RT_Thread *thMain = NULL; - - if(NANOCLR_INDEX_IS_INVALID(g_CLR_RT_TypeSystem.m_entryPoint)) + if (NANOCLR_INDEX_IS_INVALID(g_CLR_RT_TypeSystem.m_entryPoint)) { #if !defined(BUILD_RTM) || defined(_WIN32) - CLR_Debug::Printf( "Cannot find any entrypoint!\r\n" ); + CLR_Debug::Printf("Cannot find any entrypoint!\r\n"); #endif NANOCLR_SET_AND_LEAVE(CLR_E_ENTRYPOINT_NOT_FOUND); } @@ -585,58 +586,59 @@ HRESULT CLR_RT_ExecutionEngine::Execute( wchar_t* entryPointArgs, int maxContext NANOCLR_CHECK_HRESULT(WaitForDebugger()); #if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) - CLR_EE_DBG_SET_MASK(StateProgramRunning,StateMask); + CLR_EE_DBG_SET_MASK(StateProgramRunning, StateMask); #endif //#if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) - - NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_Delegate::CreateInstance( ref, g_CLR_RT_TypeSystem.m_entryPoint, NULL )); + + NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_Delegate::CreateInstance(ref, g_CLR_RT_TypeSystem.m_entryPoint, NULL)); { - CLR_RT_ProtectFromGC gc( ref ); + CLR_RT_ProtectFromGC gc(ref); - NANOCLR_CHECK_HRESULT(NewThread( thMain, ref.DereferenceDelegate(), ThreadPriority::Normal, -1 )); + NANOCLR_CHECK_HRESULT(NewThread(thMain, ref.DereferenceDelegate(), ThreadPriority::Normal, -1)); } - { - CLR_RT_StackFrame* stack = thMain->CurrentFrame(); - - if(stack->m_call.m_target->numArgs > 0) - { - //Main entrypoint takes an optional String[] parameter. - //Set the arg to NULL, if that's the case. + { + CLR_RT_StackFrame *stack = thMain->CurrentFrame(); - #if defined(WIN32) - if(entryPointArgs != NULL) + if (stack->m_call.m_target->numArgs > 0) + { + // Main entrypoint takes an optional String[] parameter. + // Set the arg to NULL, if that's the case. + +#if defined(WIN32) + if (entryPointArgs != NULL) { - NANOCLR_CHECK_HRESULT(CreateEntryPointArgs( stack->m_arguments[ 0 ], entryPointArgs )); + NANOCLR_CHECK_HRESULT(CreateEntryPointArgs(stack->m_arguments[0], entryPointArgs)); } else - #else +#else (void)entryPointArgs; - #endif +#endif { - NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_Array::CreateInstance( stack->m_arguments[ 0 ], 0, g_CLR_RT_WellKnownTypes.m_String )); + NANOCLR_CHECK_HRESULT( + CLR_RT_HeapBlock_Array::CreateInstance(stack->m_arguments[0], 0, g_CLR_RT_WellKnownTypes.m_String)); } } } - //To debug static constructors, the thread should be created after the entrypoint thread. + // To debug static constructors, the thread should be created after the entrypoint thread. NANOCLR_CHECK_HRESULT(WaitForDebugger()); - - // m_cctorThread is NULL before call and inialized by the SpawnStaticConstructor - SpawnStaticConstructor( m_cctorThread ); + // m_cctorThread is NULL before call and inialized by the SpawnStaticConstructor + SpawnStaticConstructor(m_cctorThread); - while(true) + while (true) { - HRESULT hr2 = ScheduleThreads( maxContextSwitch ); NANOCLR_CHECK_HRESULT(hr2); - - if(CLR_EE_DBG_IS( RebootPending ) || CLR_EE_DBG_IS( ExitPending ) || CLR_EE_REBOOT_IS(ClrOnly)) + HRESULT hr2 = ScheduleThreads(maxContextSwitch); + NANOCLR_CHECK_HRESULT(hr2); + + if (CLR_EE_DBG_IS(RebootPending) || CLR_EE_DBG_IS(ExitPending) || CLR_EE_REBOOT_IS(ClrOnly)) { NANOCLR_SET_AND_LEAVE(S_FALSE); } #if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) - if(CLR_EE_DBG_IS( Stopped )) + if (CLR_EE_DBG_IS(Stopped)) { CLR_RT_ExecutionEngine::ExecutionConstraint_Suspend(); @@ -646,35 +648,35 @@ HRESULT CLR_RT_ExecutionEngine::Execute( wchar_t* entryPointArgs, int maxContext } #endif //#if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) - if(CLR_EE_IS(Compaction_Pending)) - { + if (CLR_EE_IS(Compaction_Pending)) + { PerformHeapCompaction(); _ASSERTE(FIMPLIES(CLR_EE_DBG_IS_NOT(NoCompaction), CLR_EE_IS_NOT(Compaction_Pending))); } - - if(hr2 == CLR_S_NO_READY_THREADS) + + if (hr2 == CLR_S_NO_READY_THREADS) { WaitForActivity(); } - else if(hr2 == CLR_S_QUANTUM_EXPIRED) + else if (hr2 == CLR_S_QUANTUM_EXPIRED) { #if !defined(BUILD_RTM) || defined(_WIN32) - if(m_fPerformGarbageCollection) + if (m_fPerformGarbageCollection) { #if defined(NANOCLR_GC_VERBOSE) - if(s_CLR_RT_fTrace_GC >= c_CLR_RT_Trace_Info) + if (s_CLR_RT_fTrace_GC >= c_CLR_RT_Trace_Info) { - CLR_Debug::Printf( " Memory: Forcing GC.\r\n" ); + CLR_Debug::Printf(" Memory: Forcing GC.\r\n"); } #endif PerformGarbageCollection(); #if defined(NANOCLR_GC_VERBOSE) - if(s_CLR_RT_fTrace_Memory > c_CLR_RT_Trace_Info) + if (s_CLR_RT_fTrace_Memory > c_CLR_RT_Trace_Info) { CLR_UINT32 inUse = g_CLR_RT_GarbageCollector.m_totalBytes - g_CLR_RT_GarbageCollector.m_freeBytes; - CLR_Debug::Printf( " Memory: INUSE: %d\r\n", (int)inUse ); + CLR_Debug::Printf(" Memory: INUSE: %d\r\n", (int)inUse); } #endif } @@ -682,7 +684,7 @@ HRESULT CLR_RT_ExecutionEngine::Execute( wchar_t* entryPointArgs, int maxContext } else { - break; + break; } } @@ -697,29 +699,29 @@ HRESULT CLR_RT_ExecutionEngine::Execute( wchar_t* entryPointArgs, int maxContext #if defined(WIN32) #if defined(NANOCLR_PROFILE_NEW) - if(CLR_EE_PRF_IS( Enabled )) + if (CLR_EE_PRF_IS(Enabled)) { - //Clients do not get all the messages they want if a program happens to end and the emulator terminates before - //the pipe can be read; furthermore the emulator must be able to persist until all required data is requested. + // Clients do not get all the messages they want if a program happens to end and the emulator terminates before + // the pipe can be read; furthermore the emulator must be able to persist until all required data is requested. CLR_EE_DBG_SET(Stopped); } #endif - //By skipping the whole CLRStartup routine, the Monitor_Program_Exit message never gets sent to clients. - CLR_EE_DBG_EVENT_BROADCAST(CLR_DBG_Commands::c_Monitor_ProgramExit,0,NULL,WP_Flags_c_NonCritical); + // By skipping the whole CLRStartup routine, the Monitor_Program_Exit message never gets sent to clients. + CLR_EE_DBG_EVENT_BROADCAST(CLR_DBG_Commands::c_Monitor_ProgramExit, 0, NULL, WP_Flags_c_NonCritical); WaitForDebugger(); #endif NANOCLR_CLEANUP_END(); } -bool CLR_RT_ExecutionEngine::EnsureSystemThread( CLR_RT_Thread*& thread, int priority ) +bool CLR_RT_ExecutionEngine::EnsureSystemThread(CLR_RT_Thread *&thread, int priority) { NATIVE_PROFILE_CLR_CORE(); - if(thread == NULL) + if (thread == NULL) { - return SUCCEEDED(NewThread( thread, NULL, priority, -1, CLR_RT_Thread::TH_F_System )); + return SUCCEEDED(NewThread(thread, NULL, priority, -1, CLR_RT_Thread::TH_F_System)); } else { @@ -730,18 +732,18 @@ bool CLR_RT_ExecutionEngine::EnsureSystemThread( CLR_RT_Thread*& thread, int pri void CLR_RT_ExecutionEngine::SpawnTimer() { NATIVE_PROFILE_CLR_CORE(); - NANOCLR_FOREACH_NODE(CLR_RT_HeapBlock_Timer,timer,m_timers) + NANOCLR_FOREACH_NODE(CLR_RT_HeapBlock_Timer, timer, m_timers) { - if(timer->m_flags & CLR_RT_HeapBlock_Timer::c_Triggered) - { - if(EnsureSystemThread( m_timerThread, ThreadPriority::Normal )) + if (timer->m_flags & CLR_RT_HeapBlock_Timer::c_Triggered) + { + if (EnsureSystemThread(m_timerThread, ThreadPriority::Normal)) { - //only fire one timer at a time + // only fire one timer at a time - timer->SpawnTimer( m_timerThread ); + timer->SpawnTimer(m_timerThread); - //put at the back of the queue to allow for fairness of the timers. - m_timers.LinkAtBack( timer ); + // put at the back of the queue to allow for fairness of the timers. + m_timers.LinkAtBack(timer); } break; } @@ -749,41 +751,45 @@ void CLR_RT_ExecutionEngine::SpawnTimer() NANOCLR_FOREACH_NODE_END(); } -void CLR_RT_ExecutionEngine::StaticConstructorTerminationCallback( void* arg ) +void CLR_RT_ExecutionEngine::StaticConstructorTerminationCallback(void *arg) { (void)arg; NATIVE_PROFILE_CLR_CORE(); - g_CLR_RT_ExecutionEngine.SpawnStaticConstructor( g_CLR_RT_ExecutionEngine.m_cctorThread ); + g_CLR_RT_ExecutionEngine.SpawnStaticConstructor(g_CLR_RT_ExecutionEngine.m_cctorThread); } #if defined(NANOCLR_APPDOMAINS) -bool CLR_RT_ExecutionEngine::SpawnStaticConstructorHelper( CLR_RT_AppDomain* appDomain, CLR_RT_AppDomainAssembly* appDomainAssembly, const CLR_RT_MethodDef_Index& idx ) +bool CLR_RT_ExecutionEngine::SpawnStaticConstructorHelper( + CLR_RT_AppDomain *appDomain, + CLR_RT_AppDomainAssembly *appDomainAssembly, + const CLR_RT_MethodDef_Index &idx) { NATIVE_PROFILE_CLR_CORE(); CLR_RT_MethodDef_Index idxNext; _ASSERTE(m_cctorThread != NULL); - //_ASSERTE(m_cctorThread->CanThreadBeReused()); + //_ASSERTE(m_cctorThread->CanThreadBeReused()); idxNext.m_data = idx.m_data; _ASSERTE(appDomainAssembly != NULL); - //find next method with static constructor - if(appDomainAssembly->m_assembly->FindNextStaticConstructor( idxNext )) - { - CLR_RT_HeapBlock_Delegate* dlg; - CLR_RT_HeapBlock refDlg; refDlg.SetObjectReference( NULL ); - CLR_RT_ProtectFromGC gc( refDlg ); - - if(SUCCEEDED(CLR_RT_HeapBlock_Delegate::CreateInstance( refDlg, idxNext, NULL ))) + // find next method with static constructor + if (appDomainAssembly->m_assembly->FindNextStaticConstructor(idxNext)) + { + CLR_RT_HeapBlock_Delegate *dlg; + CLR_RT_HeapBlock refDlg; + refDlg.SetObjectReference(NULL); + CLR_RT_ProtectFromGC gc(refDlg); + + if (SUCCEEDED(CLR_RT_HeapBlock_Delegate::CreateInstance(refDlg, idxNext, NULL))) { dlg = refDlg.DereferenceDelegate(); dlg->m_appDomain = appDomain; - if(SUCCEEDED(m_cctorThread->PushThreadProcDelegate( dlg ))) - { + if (SUCCEEDED(m_cctorThread->PushThreadProcDelegate(dlg))) + { m_cctorThread->m_terminationCallback = CLR_RT_ExecutionEngine::StaticConstructorTerminationCallback; return true; @@ -795,67 +801,67 @@ bool CLR_RT_ExecutionEngine::SpawnStaticConstructorHelper( CLR_RT_AppDomain* app return false; } -void CLR_RT_ExecutionEngine::SpawnStaticConstructor( CLR_RT_Thread *&pCctorThread ) +void CLR_RT_ExecutionEngine::SpawnStaticConstructor(CLR_RT_Thread *&pCctorThread) { NATIVE_PROFILE_CLR_CORE(); - CLR_RT_HeapBlock_Delegate* dlg = NULL; + CLR_RT_HeapBlock_Delegate *dlg = NULL; - if(!EnsureSystemThread(pCctorThread, ThreadPriority::System_Highest )) + if (!EnsureSystemThread(pCctorThread, ThreadPriority::System_Highest)) return; dlg = pCctorThread->m_dlg; - if(dlg != NULL) + if (dlg != NULL) { - CLR_RT_AppDomainAssembly* appDomainAssembly; + CLR_RT_AppDomainAssembly *appDomainAssembly; CLR_RT_MethodDef_Index idx = dlg->DelegateFtn(); CLR_RT_MethodDef_Instance inst; - //Find next static constructor for given idx + // Find next static constructor for given idx _ASSERTE(NANOCLR_INDEX_IS_VALID(idx)); - _SIDE_ASSERTE(inst.InitializeFromIndex( idx )); + _SIDE_ASSERTE(inst.InitializeFromIndex(idx)); + + appDomainAssembly = dlg->m_appDomain->FindAppDomainAssembly(inst.m_assm); - appDomainAssembly = dlg->m_appDomain->FindAppDomainAssembly( inst.m_assm ); - _ASSERTE(appDomainAssembly != NULL); - _ASSERTE(appDomainAssembly->m_assembly == inst.m_assm ); - - //This is ok if idx is no longer valid. SpawnStaticConstructorHelper will call FindNextStaticConstructor - //which will fail + _ASSERTE(appDomainAssembly->m_assembly == inst.m_assm); + + // This is ok if idx is no longer valid. SpawnStaticConstructorHelper will call FindNextStaticConstructor + // which will fail idx.m_data++; - //This is not the first static constructor run in this appDomain - if(SpawnStaticConstructorHelper( dlg->m_appDomain, appDomainAssembly, idx )) + // This is not the first static constructor run in this appDomain + if (SpawnStaticConstructorHelper(dlg->m_appDomain, appDomainAssembly, idx)) return; } - //first, find the AppDomainAssembly to run. (what about appdomains!!!) - NANOCLR_FOREACH_NODE(CLR_RT_AppDomain,appDomain,g_CLR_RT_ExecutionEngine.m_appDomains) + // first, find the AppDomainAssembly to run. (what about appdomains!!!) + NANOCLR_FOREACH_NODE(CLR_RT_AppDomain, appDomain, g_CLR_RT_ExecutionEngine.m_appDomains) { - NANOCLR_FOREACH_NODE(CLR_RT_AppDomainAssembly,appDomainAssembly,appDomain->m_appDomainAssemblies) + NANOCLR_FOREACH_NODE(CLR_RT_AppDomainAssembly, appDomainAssembly, appDomain->m_appDomainAssemblies) { - CLR_RT_Assembly* assembly = appDomainAssembly->m_assembly; + CLR_RT_Assembly *assembly = appDomainAssembly->m_assembly; - //Find an AppDomainAssembly that does not have it's static constructor bit set... - if((appDomainAssembly->m_flags & CLR_RT_AppDomainAssembly::StaticConstructorsExecuted) == 0) - { - CLR_RT_MethodDef_Index idx; idx.Set( assembly->m_idx, 0 ); + // Find an AppDomainAssembly that does not have it's static constructor bit set... + if ((appDomainAssembly->m_flags & CLR_RT_AppDomainAssembly::StaticConstructorsExecuted) == 0) + { + CLR_RT_MethodDef_Index idx; + idx.Set(assembly->m_idx, 0); #ifdef DEBUG - - //Check that all dependent assemblies have had static constructors run. - CLR_RT_AssemblyRef_CrossReference* ar = assembly->m_pCrossReference_AssemblyRef; - for(int i=0; im_pTablesSize[ TBL_AssemblyRef ]; i++, ar++) + + // Check that all dependent assemblies have had static constructors run. + CLR_RT_AssemblyRef_CrossReference *ar = assembly->m_pCrossReference_AssemblyRef; + for (int i = 0; i < assembly->m_pTablesSize[TBL_AssemblyRef]; i++, ar++) { - CLR_RT_AppDomainAssembly* appDomainAssemblyRef = appDomain->FindAppDomainAssembly(ar->m_target); - + CLR_RT_AppDomainAssembly *appDomainAssemblyRef = appDomain->FindAppDomainAssembly(ar->m_target); + _ASSERTE(appDomainAssemblyRef != NULL); _ASSERTE(appDomainAssemblyRef->m_flags & CLR_RT_AppDomainAssembly::StaticConstructorsExecuted); } #endif - - if(SpawnStaticConstructorHelper( appDomain, appDomainAssembly, idx )) + if (SpawnStaticConstructorHelper(appDomain, appDomainAssembly, idx)) return; } } @@ -863,39 +869,39 @@ void CLR_RT_ExecutionEngine::SpawnStaticConstructor( CLR_RT_Thread *&pCctorThrea } NANOCLR_FOREACH_NODE_END(); - // No more static constructors needed... // Perform 1 action: // 1. Destroy constructor thread. pCctorThread->DestroyInstance(); } -#else //NANOCLR_APPDOMAINS +#else // NANOCLR_APPDOMAINS -bool CLR_RT_ExecutionEngine::SpawnStaticConstructorHelper( CLR_RT_Assembly* assembly, const CLR_RT_MethodDef_Index& idx ) +bool CLR_RT_ExecutionEngine::SpawnStaticConstructorHelper(CLR_RT_Assembly *assembly, const CLR_RT_MethodDef_Index &idx) { NATIVE_PROFILE_CLR_CORE(); CLR_RT_MethodDef_Index idxNext; _ASSERTE(m_cctorThread != NULL); - _ASSERTE(m_cctorThread->CanThreadBeReused()); + _ASSERTE(m_cctorThread->CanThreadBeReused()); idxNext.m_data = idx.m_data; _ASSERTE(assembly != NULL); - //find next method with static constructor - if(assembly->FindNextStaticConstructor( idxNext )) - { - CLR_RT_HeapBlock_Delegate* dlg; - CLR_RT_HeapBlock refDlg; refDlg.SetObjectReference( NULL ); - CLR_RT_ProtectFromGC gc( refDlg ); - - if(SUCCEEDED(CLR_RT_HeapBlock_Delegate::CreateInstance( refDlg, idxNext, NULL ))) + // find next method with static constructor + if (assembly->FindNextStaticConstructor(idxNext)) + { + CLR_RT_HeapBlock_Delegate *dlg; + CLR_RT_HeapBlock refDlg; + refDlg.SetObjectReference(NULL); + CLR_RT_ProtectFromGC gc(refDlg); + + if (SUCCEEDED(CLR_RT_HeapBlock_Delegate::CreateInstance(refDlg, idxNext, NULL))) { dlg = refDlg.DereferenceDelegate(); - if(SUCCEEDED(m_cctorThread->PushThreadProcDelegate( dlg ))) - { + if (SUCCEEDED(m_cctorThread->PushThreadProcDelegate(dlg))) + { m_cctorThread->m_terminationCallback = CLR_RT_ExecutionEngine::StaticConstructorTerminationCallback; return true; @@ -907,65 +913,66 @@ bool CLR_RT_ExecutionEngine::SpawnStaticConstructorHelper( CLR_RT_Assembly* asse return false; } -void CLR_RT_ExecutionEngine::SpawnStaticConstructor( CLR_RT_Thread *&pCctorThread ) +void CLR_RT_ExecutionEngine::SpawnStaticConstructor(CLR_RT_Thread *&pCctorThread) { NATIVE_PROFILE_CLR_CORE(); - CLR_RT_HeapBlock_Delegate* dlg = NULL; + CLR_RT_HeapBlock_Delegate *dlg = NULL; - if(!EnsureSystemThread(pCctorThread, ThreadPriority::System_Highest)) + if (!EnsureSystemThread(pCctorThread, ThreadPriority::System_Highest)) return; dlg = pCctorThread->m_dlg; - if(dlg != NULL) - { + if (dlg != NULL) + { CLR_RT_MethodDef_Index idx = dlg->DelegateFtn(); CLR_RT_MethodDef_Instance inst; - //Find next static constructor for given idx + // Find next static constructor for given idx _ASSERTE(NANOCLR_INDEX_IS_VALID(idx)); - _SIDE_ASSERTE(inst.InitializeFromIndex( idx )); - - //This is ok if idx is no longer valid. SpawnStaticConstructorHelper will call FindNextStaticConstructor - //which will fail + _SIDE_ASSERTE(inst.InitializeFromIndex(idx)); + + // This is ok if idx is no longer valid. SpawnStaticConstructorHelper will call FindNextStaticConstructor + // which will fail idx.m_data++; - if(SpawnStaticConstructorHelper( inst.m_assm, idx )) + if (SpawnStaticConstructorHelper(inst.m_assm, idx)) return; } - //first, find the AppDomainAssembly to run. (what about appdomains!!!) - NANOCLR_FOREACH_ASSEMBLY(g_CLR_RT_TypeSystem) + // first, find the AppDomainAssembly to run. (what about appdomains!!!) + NANOCLR_FOREACH_ASSEMBLY(g_CLR_RT_TypeSystem) { - //Find an AppDomainAssembly that does not have it's static constructor bit set... - if((pASSM->m_flags & CLR_RT_Assembly::StaticConstructorsExecuted) == 0) - { - CLR_RT_MethodDef_Index idx; idx.Set( pASSM->m_idx, 0 ); + // Find an AppDomainAssembly that does not have it's static constructor bit set... + if ((pASSM->m_flags & CLR_RT_Assembly::StaticConstructorsExecuted) == 0) + { + CLR_RT_MethodDef_Index idx; + idx.Set(pASSM->m_idx, 0); bool fDepedenciesRun = true; - //Check that all dependent assemblies have had static constructors run. - CLR_RT_AssemblyRef_CrossReference* ar = pASSM->m_pCrossReference_AssemblyRef; - for(int i=0; im_pTablesSize[ TBL_AssemblyRef ]; i++, ar++) + // Check that all dependent assemblies have had static constructors run. + CLR_RT_AssemblyRef_CrossReference *ar = pASSM->m_pCrossReference_AssemblyRef; + for (int i = 0; i < pASSM->m_pTablesSize[TBL_AssemblyRef]; i++, ar++) { - if((ar->m_target->m_flags & CLR_RT_Assembly::StaticConstructorsExecuted) == 0) + if ((ar->m_target->m_flags & CLR_RT_Assembly::StaticConstructorsExecuted) == 0) { fDepedenciesRun = true; break; } } - - if(fDepedenciesRun && SpawnStaticConstructorHelper( pASSM, idx )) + + if (fDepedenciesRun && SpawnStaticConstructorHelper(pASSM, idx)) return; } } NANOCLR_FOREACH_ASSEMBLY_END(); - //no more static constructors needed... + // no more static constructors needed... pCctorThread->DestroyInstance(); } -#endif //NANOCLR_APPDOMAINS +#endif // NANOCLR_APPDOMAINS -void CLR_RT_ExecutionEngine::FinalizerTerminationCallback(void* arg) +void CLR_RT_ExecutionEngine::FinalizerTerminationCallback(void *arg) { (void)arg; @@ -974,157 +981,164 @@ void CLR_RT_ExecutionEngine::FinalizerTerminationCallback(void* arg) } void CLR_RT_ExecutionEngine::SpawnFinalizer() -{ +{ NATIVE_PROFILE_CLR_CORE(); - - CLR_RT_HeapBlock_Finalizer* fin = (CLR_RT_HeapBlock_Finalizer*)m_finalizersPending.FirstNode(); - if(fin->Next() != NULL) + + CLR_RT_HeapBlock_Finalizer *fin = (CLR_RT_HeapBlock_Finalizer *)m_finalizersPending.FirstNode(); + if (fin->Next() != NULL) { - CLR_RT_HeapBlock delegate; delegate.SetObjectReference( NULL ); - CLR_RT_ProtectFromGC gc( delegate ); + CLR_RT_HeapBlock delegate; + delegate.SetObjectReference(NULL); + CLR_RT_ProtectFromGC gc(delegate); #if defined(NANOCLR_APPDOMAINS) - (void)SetCurrentAppDomain( fin->m_appDomain ); + (void)SetCurrentAppDomain(fin->m_appDomain); #endif - if(EnsureSystemThread(m_finalizerThread, ThreadPriority::BelowNormal)) + if (EnsureSystemThread(m_finalizerThread, ThreadPriority::BelowNormal)) { - if(SUCCEEDED(CLR_RT_HeapBlock_Delegate::CreateInstance( delegate, fin->m_md, NULL ))) + if (SUCCEEDED(CLR_RT_HeapBlock_Delegate::CreateInstance(delegate, fin->m_md, NULL))) { - CLR_RT_HeapBlock_Delegate* dlg = delegate.DereferenceDelegate(); + CLR_RT_HeapBlock_Delegate *dlg = delegate.DereferenceDelegate(); - dlg->m_object.SetObjectReference( fin->m_object ); + dlg->m_object.SetObjectReference(fin->m_object); - if(SUCCEEDED(m_finalizerThread->PushThreadProcDelegate( dlg ))) + if (SUCCEEDED(m_finalizerThread->PushThreadProcDelegate(dlg))) { - g_CLR_RT_EventCache.Append_Node( fin ); + g_CLR_RT_EventCache.Append_Node(fin); m_finalizerThread->m_terminationCallback = CLR_RT_ExecutionEngine::FinalizerTerminationCallback; - } + } } } } } -void CLR_RT_ExecutionEngine::AdjustExecutionCounter( CLR_RT_DblLinkedList &threadList, int iUpdateValue ) +void CLR_RT_ExecutionEngine::AdjustExecutionCounter(CLR_RT_DblLinkedList &threadList, int iUpdateValue) -{ // Iterate over threads in increase executioin counter by iUpdateValue - NANOCLR_FOREACH_NODE(CLR_RT_Thread,pThread,threadList) +{ // Iterate over threads in increase executioin counter by iUpdateValue + NANOCLR_FOREACH_NODE(CLR_RT_Thread, pThread, threadList) { pThread->m_executionCounter += iUpdateValue; // Update m_executionCounter if thread is too behind of m_GlobalExecutionCounter - pThread->BringExecCounterToDate( m_GlobalExecutionCounter ); + pThread->BringExecCounterToDate(m_GlobalExecutionCounter); } NANOCLR_FOREACH_NODE_END() } -void CLR_RT_ExecutionEngine::UpdateToLowestExecutionCounter( CLR_RT_Thread *pThread ) const +void CLR_RT_ExecutionEngine::UpdateToLowestExecutionCounter(CLR_RT_Thread *pThread) const { // Set the m_executionCounter in thread to lowest value among ready threads. // Thus it will be executed last. - pThread->m_executionCounter = m_GlobalExecutionCounter - 1; + pThread->m_executionCounter = m_GlobalExecutionCounter - 1; } -void CLR_RT_ExecutionEngine::RetrieveCurrentMethod( CLR_UINT32& assmIdx, CLR_UINT32& methodIdx ) +void CLR_RT_ExecutionEngine::RetrieveCurrentMethod(CLR_UINT32 &assmIdx, CLR_UINT32 &methodIdx) { - assmIdx = 0; + assmIdx = 0; methodIdx = 0; - if(m_currentThread != NULL) + if (m_currentThread != NULL) { - CLR_RT_StackFrame* stack = m_currentThread->CurrentFrame(); + CLR_RT_StackFrame *stack = m_currentThread->CurrentFrame(); - if(stack) + if (stack) { - assmIdx = stack->m_call.Assembly(); - methodIdx = stack->m_call.Method (); + assmIdx = stack->m_call.Assembly(); + methodIdx = stack->m_call.Method(); } } } -void CLR_RetrieveCurrentMethod( CLR_UINT32 & assmIdx, CLR_UINT32 & methodIdx ) +void CLR_RetrieveCurrentMethod(CLR_UINT32 &assmIdx, CLR_UINT32 &methodIdx) { - g_CLR_RT_ExecutionEngine.RetrieveCurrentMethod( assmIdx, methodIdx ); + g_CLR_RT_ExecutionEngine.RetrieveCurrentMethod(assmIdx, methodIdx); } void CLR_SoftReboot() { - CLR_EE_DBG_SET( RebootPending ); + CLR_EE_DBG_SET(RebootPending); } void CLR_DebuggerBreak() { - if(g_CLR_RT_ExecutionEngine.m_currentThread != NULL) + if (g_CLR_RT_ExecutionEngine.m_currentThread != NULL) { CLR_RT_HeapBlock *obj = g_CLR_RT_ExecutionEngine.m_currentThread->m_currentException.Dereference(); /// - /// Only inject the exception once -- if the dereference is not null then the exception is already set on the current thread + /// Only inject the exception once -- if the dereference is not null then the exception is already set on the + /// current thread /// - if(obj == NULL) - { - Library_corlib_native_System_Exception::CreateInstance( g_CLR_RT_ExecutionEngine.m_currentThread->m_currentException, g_CLR_RT_WellKnownTypes.m_WatchdogException, CLR_E_WATCHDOG_TIMEOUT, g_CLR_RT_ExecutionEngine.m_currentThread->CurrentFrame() ); + if (obj == NULL) + { + Library_corlib_native_System_Exception::CreateInstance( + g_CLR_RT_ExecutionEngine.m_currentThread->m_currentException, + g_CLR_RT_WellKnownTypes.m_WatchdogException, + CLR_E_WATCHDOG_TIMEOUT, + g_CLR_RT_ExecutionEngine.m_currentThread->CurrentFrame()); } } } - -HRESULT CLR_RT_ExecutionEngine::ScheduleThreads( int maxContextSwitch ) + +HRESULT CLR_RT_ExecutionEngine::ScheduleThreads(int maxContextSwitch) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); -#if defined(NANOCLR_APPDOMAINS) - CLR_RT_AppDomain* appDomainSav = g_CLR_RT_ExecutionEngine.GetCurrentAppDomain(); +#if defined(NANOCLR_APPDOMAINS) + CLR_RT_AppDomain *appDomainSav = g_CLR_RT_ExecutionEngine.GetCurrentAppDomain(); #endif - // We run threads based on the m_executionCounter. + // We run threads based on the m_executionCounter. // The thread with highest m_executionCounter is chosen for execution. // The highest value of m_executionCounter of any thread is stored in m_GlobalExecutionCounter - // We need to check that m_GlobalExecutionCounter does not underflow ( runs below - -2147483647 ) This would be very rare condition, but it may happen. - // We put threshold at - 0x40000000 - if ( m_GlobalExecutionCounter < -EXECUTION_COUNTER_MAXIMUM ) - { // Iterate over threads in all queues and bump the execution counter by MAX_EXECUTION_COUNTER_ADJUSTMENT + // We need to check that m_GlobalExecutionCounter does not underflow ( runs below - -2147483647 ) This would be very + // rare condition, but it may happen. We put threshold at - 0x40000000 + if (m_GlobalExecutionCounter < -EXECUTION_COUNTER_MAXIMUM) + { // Iterate over threads in all queues and bump the execution counter by MAX_EXECUTION_COUNTER_ADJUSTMENT m_GlobalExecutionCounter += EXECUTION_COUNTER_ADJUSTMENT; - // For each list of threads runs over it and updates execution counter. - // AdjustExecutionCounter gets const & to list of threads. + // For each list of threads runs over it and updates execution counter. + // AdjustExecutionCounter gets const & to list of threads. // List of threads is not modified, but m_executionCounter is bumped up in each thread. - AdjustExecutionCounter( m_threadsReady, EXECUTION_COUNTER_ADJUSTMENT ); - AdjustExecutionCounter( m_threadsWaiting, EXECUTION_COUNTER_ADJUSTMENT ); - AdjustExecutionCounter( m_threadsZombie, EXECUTION_COUNTER_ADJUSTMENT ); + AdjustExecutionCounter(m_threadsReady, EXECUTION_COUNTER_ADJUSTMENT); + AdjustExecutionCounter(m_threadsWaiting, EXECUTION_COUNTER_ADJUSTMENT); + AdjustExecutionCounter(m_threadsZombie, EXECUTION_COUNTER_ADJUSTMENT); } - - while(maxContextSwitch-- > 0) + + while (maxContextSwitch-- > 0) { - + #if defined(WIN32) - if(HAL_Windows_IsShutdownPending()) + if (HAL_Windows_IsShutdownPending()) { NANOCLR_SET_AND_LEAVE(CLR_S_NO_THREADS); } #endif #if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) - if(CLR_EE_DBG_IS( Stopped )) + if (CLR_EE_DBG_IS(Stopped)) { NANOCLR_SET_AND_LEAVE(CLR_S_NO_READY_THREADS); } -#endif //#if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) +#endif //#if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) - CLR_RT_Thread* th = NULL; + CLR_RT_Thread *th = NULL; // If a static constructor thread exists, we should be running it. // What about func-eval? - if (m_cctorThread == NULL) + if (m_cctorThread == NULL) { - // This is normal case execution. Looks for first ready thread. - th = (CLR_RT_Thread*)m_threadsReady.FirstNode(); + // This is normal case execution. Looks for first ready thread. + th = (CLR_RT_Thread *)m_threadsReady.FirstNode(); } - else //If a static constructor thread exists, we should be running it. + else // If a static constructor thread exists, we should be running it. { // This is special case executed during initialization of static constructors. - if (m_cctorThread->m_status == CLR_RT_Thread::TH_S_Ready && !(m_cctorThread->m_flags & CLR_RT_Thread::TH_F_Suspended)) + if (m_cctorThread->m_status == CLR_RT_Thread::TH_S_Ready && + !(m_cctorThread->m_flags & CLR_RT_Thread::TH_F_Suspended)) { th = m_cctorThread; } @@ -1132,54 +1146,51 @@ HRESULT CLR_RT_ExecutionEngine::ScheduleThreads( int maxContextSwitch ) { // The m_cctorThread is exists, but not ready - means entered blocking call. // We do not want to preempt constructor thread, so stay idle. - NANOCLR_SET_AND_LEAVE(CLR_S_NO_READY_THREADS); + NANOCLR_SET_AND_LEAVE(CLR_S_NO_READY_THREADS); } } - - - // If th->Next() is NULL, then there are no Ready to run threads in the system. // In this case we spawn finalizer and make finalizer thread as ready one. - if(th->Next() == NULL) + if (th->Next() == NULL) { g_CLR_RT_ExecutionEngine.SpawnFinalizer(); - + // Now finalizer thread might be in ready state if there are object that need call to finalizer. // th might point to finilizer thread. - th = (CLR_RT_Thread*)m_threadsReady.FirstNode(); + th = (CLR_RT_Thread *)m_threadsReady.FirstNode(); - //Thread create can cause stopping debugging event + // Thread create can cause stopping debugging event #if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) - if(CLR_EE_DBG_IS(Stopped)) + if (CLR_EE_DBG_IS(Stopped)) { NANOCLR_SET_AND_LEAVE(CLR_S_NO_READY_THREADS); } #endif //#if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) } - // If there is ready thread - decrease m_executionCounter for this (th) thread. - if( th->Next() != NULL ) + // If there is ready thread - decrease m_executionCounter for this (th) thread. + if (th->Next() != NULL) { // The value to update m_executionCounter for each run. See comment for GetQuantumDebit for possible values int debitForEachRun = th->GetQuantumDebit(); // If thread is way too much behind on its execution, we cut off extra credit. // We guarantee the thread will not be scheduled more than 4 consecutive times. - th->BringExecCounterToDate( m_GlobalExecutionCounter ); - + th->BringExecCounterToDate(m_GlobalExecutionCounter); + // Subtract the execution counter by debit value ( for executing thread ) th->m_executionCounter -= debitForEachRun; - // Keep the track of lowest execution counter. - if ( th->m_executionCounter < m_GlobalExecutionCounter ) + // Keep the track of lowest execution counter. + if (th->m_executionCounter < m_GlobalExecutionCounter) { m_GlobalExecutionCounter = th->m_executionCounter; } } else { - if(m_threadsWaiting.IsEmpty()) + if (m_threadsWaiting.IsEmpty()) { NANOCLR_SET_AND_LEAVE(CLR_S_NO_THREADS); } @@ -1194,26 +1205,26 @@ HRESULT CLR_RT_ExecutionEngine::ScheduleThreads( int maxContextSwitch ) hr = th->Execute(); } - if(FAILED(hr)) + if (FAILED(hr)) { - switch(hr) + switch (hr) { - case CLR_E_RESCHEDULE: - break; + case CLR_E_RESCHEDULE: + break; - case CLR_E_THREAD_WAITING: - th->m_status = CLR_RT_Thread::TH_S_Waiting; - break; + case CLR_E_THREAD_WAITING: + th->m_status = CLR_RT_Thread::TH_S_Waiting; + break; - default: - th->m_status = CLR_RT_Thread::TH_S_Terminated; - break; + default: + th->m_status = CLR_RT_Thread::TH_S_Terminated; + break; } } Watchdog_Reset(); - PutInProperList( th ); + PutInProperList(th); (void)ProcessTimer(); } @@ -1222,21 +1233,21 @@ HRESULT CLR_RT_ExecutionEngine::ScheduleThreads( int maxContextSwitch ) NANOCLR_CLEANUP(); -#if defined(NANOCLR_APPDOMAINS) - - if(CLR_EE_IS( UnloadingAppDomain )) +#if defined(NANOCLR_APPDOMAINS) + + if (CLR_EE_IS(UnloadingAppDomain)) { - if(TryToUnloadAppDomains()) + if (TryToUnloadAppDomains()) { - //If we are successful in unloading an AppDomain, return CLR_S_QUANTUM_EXPIRED - //to cause ScheduleThreads to be called again. This allows the somewhat expensive operation - //of trying to unload an AppDomain once every ScheduleThread call, rather than once every context switch + // If we are successful in unloading an AppDomain, return CLR_S_QUANTUM_EXPIRED + // to cause ScheduleThreads to be called again. This allows the somewhat expensive operation + // of trying to unload an AppDomain once every ScheduleThread call, rather than once every context switch hr = CLR_S_QUANTUM_EXPIRED; } } - g_CLR_RT_ExecutionEngine.SetCurrentAppDomain( appDomainSav ); + g_CLR_RT_ExecutionEngine.SetCurrentAppDomain(appDomainSav); #endif NANOCLR_CLEANUP_END(); @@ -1248,148 +1259,158 @@ CLR_UINT32 CLR_RT_ExecutionEngine::WaitForActivity() CLR_INT64 timeoutMin = ProcessTimer(); - if(m_threadsReady.IsEmpty() == false) return 0; // Someone woke up... + if (m_threadsReady.IsEmpty() == false) + return 0; // Someone woke up... - if(timeoutMin > 0LL) + if (timeoutMin > 0LL) { - NANOCLR_FOREACH_NODE(CLR_RT_Thread,th,m_threadsWaiting) + NANOCLR_FOREACH_NODE(CLR_RT_Thread, th, m_threadsWaiting) { - if((th->m_waitForEvents & c_Event_IdleCPU) != 0 && th->m_waitForEvents_IdleTimeWorkItem < timeoutMin) + if ((th->m_waitForEvents & Event_IdleCPU) != 0 && th->m_waitForEvents_IdleTimeWorkItem < timeoutMin) { th->m_waitForEvents_IdleTimeWorkItem = TIMEOUT_ZERO; - th->Restart( true ); + th->Restart(true); return SYSTEM_EVENT_FLAG_ALL; // Someone woke up... } } NANOCLR_FOREACH_NODE_END(); - return WaitForActivity( SLEEP_LEVEL__SLEEP, g_CLR_HW_Hardware.m_wakeupEvents, timeoutMin ); + return WaitForActivity(SLEEP_LEVEL__SLEEP, g_CLR_HW_Hardware.m_wakeupEvents, timeoutMin); } return 0; } -CLR_UINT32 CLR_RT_ExecutionEngine::WaitForActivity( CLR_UINT32 powerLevel, CLR_UINT32 events, CLR_INT64 timeout_ms ) +CLR_UINT32 CLR_RT_ExecutionEngine::WaitForActivity(CLR_UINT32 powerLevel, CLR_UINT32 events, CLR_INT64 timeout_ms) { NATIVE_PROFILE_CLR_CORE(); - - if(powerLevel != PowerLevel__Active) + + if (powerLevel != PowerLevel__Active) { - return WaitSystemEvents( powerLevel, events, timeout_ms ); + return WaitSystemEvents(powerLevel, events, timeout_ms); } - + return 0; } //--// -void CLR_RT_ExecutionEngine::PutInProperList( CLR_RT_Thread* th ) +void CLR_RT_ExecutionEngine::PutInProperList(CLR_RT_Thread *th) { NATIVE_PROFILE_CLR_CORE(); - switch(th->m_status) + switch (th->m_status) { - case CLR_RT_Thread::TH_S_Ready: - if((th->m_flags & CLR_RT_Thread::TH_F_Suspended) == 0) - { - InsertThreadRoundRobin( m_threadsReady, th ); + case CLR_RT_Thread::TH_S_Ready: + if ((th->m_flags & CLR_RT_Thread::TH_F_Suspended) == 0) + { + InsertThreadRoundRobin(m_threadsReady, th); + break; + } + // + // Fall-through... + // + case CLR_RT_Thread::TH_S_Waiting: + m_threadsWaiting.LinkAtBack(th); break; - } - // - // Fall-through... - // - case CLR_RT_Thread::TH_S_Waiting: - m_threadsWaiting.LinkAtBack( th ); - break; - case CLR_RT_Thread::TH_S_Terminated: - th->Passivate(); - break; + case CLR_RT_Thread::TH_S_Terminated: + th->Passivate(); + break; - case CLR_RT_Thread::TH_S_Unstarted: - m_threadsZombie.LinkAtFront( th ); - break; + case CLR_RT_Thread::TH_S_Unstarted: + m_threadsZombie.LinkAtFront(th); + break; } } -void CLR_RT_ExecutionEngine::AbortAllThreads( CLR_RT_DblLinkedList& threads ) +void CLR_RT_ExecutionEngine::AbortAllThreads(CLR_RT_DblLinkedList &threads) { NATIVE_PROFILE_CLR_CORE(); - NANOCLR_FOREACH_NODE(CLR_RT_Thread,th,threads) + NANOCLR_FOREACH_NODE(CLR_RT_Thread, th, threads) { - if((th->m_flags & CLR_RT_Thread::TH_F_Aborted) == 0) + if ((th->m_flags & CLR_RT_Thread::TH_F_Aborted) == 0) { th->Abort(); - NANOCLR_FOREACH_NODE_RESTART(CLR_RT_Thread,th,threads); + NANOCLR_FOREACH_NODE_RESTART(CLR_RT_Thread, th, threads); } } NANOCLR_FOREACH_NODE_END(); } -void CLR_RT_ExecutionEngine::ReleaseAllThreads( CLR_RT_DblLinkedList& threads ) +void CLR_RT_ExecutionEngine::ReleaseAllThreads(CLR_RT_DblLinkedList &threads) { NATIVE_PROFILE_CLR_CORE(); - while(true) + while (true) { - CLR_RT_Thread* th = (CLR_RT_Thread*)threads.ExtractFirstNode(); if(!th) break; + CLR_RT_Thread *th = (CLR_RT_Thread *)threads.ExtractFirstNode(); + if (!th) + break; th->DestroyInstance(); } } -void CLR_RT_ExecutionEngine::InsertThreadRoundRobin( CLR_RT_DblLinkedList& threads, CLR_RT_Thread* thTarget ) +void CLR_RT_ExecutionEngine::InsertThreadRoundRobin(CLR_RT_DblLinkedList &threads, CLR_RT_Thread *thTarget) { NATIVE_PROFILE_CLR_CORE(); - CLR_RT_Thread* th; + CLR_RT_Thread *th; thTarget->Unlink(); - if(threads.IsEmpty()) + if (threads.IsEmpty()) { - th = (CLR_RT_Thread*)threads.Tail(); + th = (CLR_RT_Thread *)threads.Tail(); } else { int priTarget = thTarget->GetExecutionCounter(); - NANOCLR_FOREACH_NODE__NODECL(CLR_RT_Thread,th,threads) + NANOCLR_FOREACH_NODE__NODECL(CLR_RT_Thread, th, threads) { - if(th->GetExecutionCounter() < priTarget) break; + if (th->GetExecutionCounter() < priTarget) + break; } NANOCLR_FOREACH_NODE_END(); } - thTarget->m_waitForEvents = 0; + thTarget->m_waitForEvents = 0; thTarget->m_waitForEvents_Timeout = TIMEOUT_INFINITE; - if(thTarget->m_waitForObject != NULL) + if (thTarget->m_waitForObject != NULL) { - g_CLR_RT_EventCache.Append_Node( thTarget->m_waitForObject ); - + g_CLR_RT_EventCache.Append_Node(thTarget->m_waitForObject); + thTarget->m_waitForObject = NULL; } - threads.InsertBeforeNode( th, thTarget ); + threads.InsertBeforeNode(th, thTarget); } //--// -HRESULT CLR_RT_ExecutionEngine::NewThread( CLR_RT_Thread*& thRes, CLR_RT_HeapBlock_Delegate* pDelegate, int priority, CLR_INT32 id, CLR_UINT32 flags ) +HRESULT CLR_RT_ExecutionEngine::NewThread( + CLR_RT_Thread *&thRes, + CLR_RT_HeapBlock_Delegate *pDelegate, + int priority, + CLR_INT32 id, + CLR_UINT32 flags) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - NANOCLR_CHECK_HRESULT(CLR_RT_Thread::CreateInstance( id != -1 ? id : ++m_lastPid, pDelegate, priority, thRes, flags )); + NANOCLR_CHECK_HRESULT( + CLR_RT_Thread::CreateInstance(id != -1 ? id : ++m_lastPid, pDelegate, priority, thRes, flags)); - PutInProperList( thRes ); + PutInProperList(thRes); NANOCLR_CLEANUP(); - if(FAILED(hr)) + if (FAILED(hr)) { - if(thRes) + if (thRes) { thRes->DestroyInstance(); @@ -1399,87 +1420,103 @@ HRESULT CLR_RT_ExecutionEngine::NewThread( CLR_RT_Thread*& thRes, CLR_RT_HeapBlo NANOCLR_CLEANUP_END(); } - -CLR_INT32 CLR_RT_ExecutionEngine::GetNextThreadId() + +CLR_INT32 CLR_RT_ExecutionEngine::GetNextThreadId() { - return ++m_lastPid; -} + return ++m_lastPid; +} //--// -CLR_RT_HeapBlock* CLR_RT_ExecutionEngine::ExtractHeapBlocksForArray( CLR_RT_TypeDef_Instance& inst, CLR_UINT32 length, const CLR_RT_ReflectionDef_Index& reflex ) +CLR_RT_HeapBlock *CLR_RT_ExecutionEngine::ExtractHeapBlocksForArray( + CLR_RT_TypeDef_Instance &inst, + CLR_UINT32 length, + const CLR_RT_ReflectionDef_Index &reflex) { NATIVE_PROFILE_CLR_CORE(); - CLR_DataType dt = (CLR_DataType)inst.m_target->dataType; - const CLR_RT_DataTypeLookup& dtl = c_CLR_RT_DataTypeLookup[ dt ]; + CLR_DataType dt = (CLR_DataType)inst.m_target->dataType; + const CLR_RT_DataTypeLookup &dtl = c_CLR_RT_DataTypeLookup[dt]; CLR_UINT32 totLength = (CLR_UINT32)(sizeof(CLR_RT_HeapBlock_Array) + length * dtl.m_sizeInBytes); CLR_UINT32 lengthHB = CONVERTFROMSIZETOHEAPBLOCKS(totLength); - if(lengthHB > CLR_RT_HeapBlock::HB_MaxSize) return NULL; + if (lengthHB > CLR_RT_HeapBlock::HB_MaxSize) + return NULL; - CLR_RT_HeapBlock_Array* pArray = (CLR_RT_HeapBlock_Array*)ExtractHeapBlocks( m_heap, DATATYPE_SZARRAY, 0, lengthHB ); + CLR_RT_HeapBlock_Array *pArray = (CLR_RT_HeapBlock_Array *)ExtractHeapBlocks(m_heap, DATATYPE_SZARRAY, 0, lengthHB); - if(pArray) + if (pArray) { - pArray->ReflectionData() = reflex; - pArray->m_numOfElements = length; + pArray->ReflectionData() = reflex; + pArray->m_numOfElements = length; - pArray->m_typeOfElement = dt; - pArray->m_sizeOfElement = dtl.m_sizeInBytes; - pArray->m_fReference = (dtl.m_flags & CLR_RT_DataTypeLookup::c_Numeric) == 0; + pArray->m_typeOfElement = dt; + pArray->m_sizeOfElement = dtl.m_sizeInBytes; + pArray->m_fReference = (dtl.m_flags & CLR_RT_DataTypeLookup::c_Numeric) == 0; #if defined(NANOCLR_PROFILE_NEW_ALLOCATIONS) - g_CLR_PRF_Profiler.TrackObjectCreation( pArray ); + g_CLR_PRF_Profiler.TrackObjectCreation(pArray); #endif } return pArray; } -CLR_RT_HeapBlock* CLR_RT_ExecutionEngine::ExtractHeapBlocksForClassOrValueTypes( CLR_UINT32 dataType, CLR_UINT32 flags, const CLR_RT_TypeDef_Index& cls, CLR_UINT32 length ) +CLR_RT_HeapBlock *CLR_RT_ExecutionEngine::ExtractHeapBlocksForClassOrValueTypes( + CLR_UINT32 dataType, + CLR_UINT32 flags, + const CLR_RT_TypeDef_Index &cls, + CLR_UINT32 length) { NATIVE_PROFILE_CLR_CORE(); - if(length > CLR_RT_HeapBlock::HB_MaxSize) return NULL; + if (length > CLR_RT_HeapBlock::HB_MaxSize) + return NULL; _ASSERTE(dataType == DATATYPE_CLASS || dataType == DATATYPE_VALUETYPE); flags = flags | CLR_RT_HeapBlock::HB_InitializeToZero; - CLR_RT_HeapBlock* hb = ExtractHeapBlocks( m_heap, dataType, flags, length ); + CLR_RT_HeapBlock *hb = ExtractHeapBlocks(m_heap, dataType, flags, length); - if(hb) + if (hb) { hb->SetObjectCls(cls); #if defined(NANOCLR_PROFILE_NEW_ALLOCATIONS) - g_CLR_PRF_Profiler.TrackObjectCreation( hb ); + g_CLR_PRF_Profiler.TrackObjectCreation(hb); #endif } return hb; } -CLR_RT_HeapBlock* CLR_RT_ExecutionEngine::ExtractHeapBytesForObjects( CLR_UINT32 dataType, CLR_UINT32 flags, CLR_UINT32 length ) +CLR_RT_HeapBlock *CLR_RT_ExecutionEngine::ExtractHeapBytesForObjects( + CLR_UINT32 dataType, + CLR_UINT32 flags, + CLR_UINT32 length) { NATIVE_PROFILE_CLR_CORE(); - return ExtractHeapBlocksForObjects( dataType, flags, CONVERTFROMSIZETOHEAPBLOCKS(length) ); + return ExtractHeapBlocksForObjects(dataType, flags, CONVERTFROMSIZETOHEAPBLOCKS(length)); } -CLR_RT_HeapBlock* CLR_RT_ExecutionEngine::ExtractHeapBlocksForObjects( CLR_UINT32 dataType, CLR_UINT32 flags, CLR_UINT32 length ) +CLR_RT_HeapBlock *CLR_RT_ExecutionEngine::ExtractHeapBlocksForObjects( + CLR_UINT32 dataType, + CLR_UINT32 flags, + CLR_UINT32 length) { NATIVE_PROFILE_CLR_CORE(); - if(length > CLR_RT_HeapBlock::HB_MaxSize) return NULL; + if (length > CLR_RT_HeapBlock::HB_MaxSize) + return NULL; _ASSERTE(dataType != DATATYPE_CLASS && dataType != DATATYPE_VALUETYPE && dataType != DATATYPE_SZARRAY); flags &= ~CLR_RT_HeapBlock::HB_Alive; - CLR_RT_HeapBlock* hb = ExtractHeapBlocks( m_heap, dataType, flags, length ); + CLR_RT_HeapBlock *hb = ExtractHeapBlocks(m_heap, dataType, flags, length); #if defined(NANOCLR_PROFILE_NEW_ALLOCATIONS) - if(hb) + if (hb) { - g_CLR_PRF_Profiler.TrackObjectCreation( hb ); + g_CLR_PRF_Profiler.TrackObjectCreation(hb); } #endif @@ -1488,61 +1525,69 @@ CLR_RT_HeapBlock* CLR_RT_ExecutionEngine::ExtractHeapBlocksForObjects( CLR_UINT3 //--// -CLR_RT_HeapBlock_Node* CLR_RT_ExecutionEngine::ExtractHeapBlocksForEvents( CLR_UINT32 dataType, CLR_UINT32 flags, CLR_UINT32 length ) +CLR_RT_HeapBlock_Node *CLR_RT_ExecutionEngine::ExtractHeapBlocksForEvents( + CLR_UINT32 dataType, + CLR_UINT32 flags, + CLR_UINT32 length) { NATIVE_PROFILE_CLR_CORE(); - if(length > CLR_RT_HeapBlock::HB_MaxSize) return NULL; + if (length > CLR_RT_HeapBlock::HB_MaxSize) + return NULL; flags |= CLR_RT_HeapBlock::HB_Alive | CLR_RT_HeapBlock::HB_Event; - CLR_RT_HeapBlock_Node* hb = (CLR_RT_HeapBlock_Node*)ExtractHeapBlocks( m_heap, dataType, flags, length ); + CLR_RT_HeapBlock_Node *hb = (CLR_RT_HeapBlock_Node *)ExtractHeapBlocks(m_heap, dataType, flags, length); - if(hb) + if (hb) { hb->GenericNode_Initialize(); #if defined(NANOCLR_PROFILE_NEW_ALLOCATIONS) - g_CLR_PRF_Profiler.TrackObjectCreation( hb ); + g_CLR_PRF_Profiler.TrackObjectCreation(hb); #endif } return hb; } -CLR_RT_HeapBlock* CLR_RT_ExecutionEngine::ExtractHeapBlocks( CLR_RT_DblLinkedList& heap, CLR_UINT32 dataType, CLR_UINT32 flags, CLR_UINT32 length ) +CLR_RT_HeapBlock *CLR_RT_ExecutionEngine::ExtractHeapBlocks( + CLR_RT_DblLinkedList &heap, + CLR_UINT32 dataType, + CLR_UINT32 flags, + CLR_UINT32 length) { NATIVE_PROFILE_CLR_CORE(); #if !defined(BUILD_RTM) - if(m_heapState == c_HeapState_UnderGC && ((flags & CLR_RT_HeapBlock::HB_SpecialGCAllocation) == 0)) + if (m_heapState == c_HeapState_UnderGC && ((flags & CLR_RT_HeapBlock::HB_SpecialGCAllocation) == 0)) { - CLR_Debug::Printf( "Internal error: call to memory allocation during garbage collection!!!\r\n" ); + CLR_Debug::Printf("Internal error: call to memory allocation during garbage collection!!!\r\n"); // Getting here during a GC is possible, since the watchdog ISR may now require - // dynamic memory allocation for logging. Returning NULL means the watchdog log will + // dynamic memory allocation for logging. Returning NULL means the watchdog log will // be lost, but without major restructuring there is not much we can do. return NULL; } #endif #if defined(NANOCLR_FORCE_GC_BEFORE_EVERY_ALLOCATION) - if(m_heapState != c_HeapState_UnderGC) + if (m_heapState != c_HeapState_UnderGC) { g_CLR_RT_EventCache.EventCache_Cleanup(); PerformGarbageCollection(); } #endif - for(int phase=0; ; phase++) + for (int phase = 0;; phase++) { { - CLR_RT_HeapBlock* hb; + CLR_RT_HeapBlock *hb; - if(flags & CLR_RT_HeapBlock::HB_Event) + if (flags & CLR_RT_HeapBlock::HB_Event) { - NANOCLR_FOREACH_NODE_BACKWARD(CLR_RT_HeapCluster,hc,heap) + NANOCLR_FOREACH_NODE_BACKWARD(CLR_RT_HeapCluster, hc, heap) { - hb = hc->ExtractBlocks( dataType, flags, length ); - if(hb) + hb = hc->ExtractBlocks(dataType, flags, length); + if (hb) { return hb; } @@ -1551,26 +1596,26 @@ CLR_RT_HeapBlock* CLR_RT_ExecutionEngine::ExtractHeapBlocks( CLR_RT_DblLinkedLis } else { - if(m_lastHcUsed != NULL) + if (m_lastHcUsed != NULL) { - hb = m_lastHcUsed->ExtractBlocks( dataType, flags, length ); - if(hb) + hb = m_lastHcUsed->ExtractBlocks(dataType, flags, length); + if (hb) { return hb; } } - NANOCLR_FOREACH_NODE(CLR_RT_HeapCluster,hc,heap) + NANOCLR_FOREACH_NODE(CLR_RT_HeapCluster, hc, heap) { - hb = hc->ExtractBlocks( dataType, flags, length ); - if(hb) + hb = hc->ExtractBlocks(dataType, flags, length); + if (hb) { #if defined(NANOCLR_GC_VERBOSE) - if(s_CLR_RT_fTrace_Memory >= c_CLR_RT_Trace_Info) + if (s_CLR_RT_fTrace_Memory >= c_CLR_RT_Trace_Info) { - if(phase != 0) + if (phase != 0) { - CLR_Debug::Printf( "ExtractHeapBlocks succeeded at phase %d\r\n", phase ); + CLR_Debug::Printf("ExtractHeapBlocks succeeded at phase %d\r\n", phase); } } #endif @@ -1584,71 +1629,76 @@ CLR_RT_HeapBlock* CLR_RT_ExecutionEngine::ExtractHeapBlocks( CLR_RT_DblLinkedLis m_lastHcUsed = NULL; } - if(flags & CLR_RT_HeapBlock::HB_NoGcOnFailedAllocation) + if (flags & CLR_RT_HeapBlock::HB_NoGcOnFailedAllocation) { return NULL; } - switch(phase) + switch (phase) { - case 0: + case 0: #if defined(NANOCLR_GC_VERBOSE) - if(s_CLR_RT_fTrace_Memory >= c_CLR_RT_Trace_Info) - { - CLR_Debug::Printf( " Memory: ExtractHeapBlocks: %d bytes needed.\r\n", length * sizeof(CLR_RT_HeapBlock) ); - } + if (s_CLR_RT_fTrace_Memory >= c_CLR_RT_Trace_Info) + { + CLR_Debug::Printf( + " Memory: ExtractHeapBlocks: %d bytes needed.\r\n", + length * sizeof(CLR_RT_HeapBlock)); + } #endif - PerformGarbageCollection(); + PerformGarbageCollection(); - break; + break; - default: // Total failure... + default: // Total failure... #if !defined(BUILD_RTM) - CLR_Debug::Printf( "Failed allocation for %d blocks, %d bytes\r\n\r\n", length, length * sizeof(CLR_RT_HeapBlock) ); + CLR_Debug::Printf( + "Failed allocation for %d blocks, %d bytes\r\n\r\n", + length, + length * sizeof(CLR_RT_HeapBlock)); #endif - if(g_CLR_RT_GarbageCollector.m_freeBytes >= (length * sizeof(CLR_RT_HeapBlock))) - { - - //A compaction probably would have saved this OOM - //Compaction will occur for Bitmaps, Arrays, etc. if this function returns NULL, so lets not - //through an assert here + if (g_CLR_RT_GarbageCollector.m_freeBytes >= (length * sizeof(CLR_RT_HeapBlock))) + { - //Throw the OOM, and schedule a compaction at a safe point - CLR_EE_SET( Compaction_Pending ); - } + // A compaction probably would have saved this OOM + // Compaction will occur for Bitmaps, Arrays, etc. if this function returns NULL, so lets not + // through an assert here - return NULL; + // Throw the OOM, and schedule a compaction at a safe point + CLR_EE_SET(Compaction_Pending); + } + + return NULL; } } } - -CLR_RT_HeapBlock* CLR_RT_ExecutionEngine::AccessStaticField( const CLR_RT_FieldDef_Index& fd ) +CLR_RT_HeapBlock *CLR_RT_ExecutionEngine::AccessStaticField(const CLR_RT_FieldDef_Index &fd) { NATIVE_PROFILE_CLR_CORE(); CLR_RT_FieldDef_Instance inst; - if(inst.InitializeFromIndex( fd ) && inst.m_target->flags & CLR_RECORD_FIELDDEF::FD_Static) + if (inst.InitializeFromIndex(fd) && inst.m_target->flags & CLR_RECORD_FIELDDEF::FD_Static) { -#if defined(NANOCLR_APPDOMAINS) +#if defined(NANOCLR_APPDOMAINS) { - CLR_RT_AppDomainAssembly* appDomainAssembly = g_CLR_RT_ExecutionEngine.GetCurrentAppDomain()->FindAppDomainAssembly( inst.m_assm ); + CLR_RT_AppDomainAssembly *appDomainAssembly = + g_CLR_RT_ExecutionEngine.GetCurrentAppDomain()->FindAppDomainAssembly(inst.m_assm); - if(appDomainAssembly) + if (appDomainAssembly) { - return &appDomainAssembly->m_pStaticFields[ inst.CrossReference().m_offset ]; + return &appDomainAssembly->m_pStaticFields[inst.CrossReference().m_offset]; } } #else - return &inst.m_assm->m_pStaticFields[ inst.CrossReference().m_offset ]; + return &inst.m_assm->m_pStaticFields[inst.CrossReference().m_offset]; #endif } return NULL; } -HRESULT CLR_RT_ExecutionEngine::InitializeReference( CLR_RT_HeapBlock& ref, CLR_RT_SignatureParser& parser ) +HRESULT CLR_RT_ExecutionEngine::InitializeReference(CLR_RT_HeapBlock &ref, CLR_RT_SignatureParser &parser) { NATIVE_PROFILE_CLR_CORE(); // @@ -1660,61 +1710,69 @@ HRESULT CLR_RT_ExecutionEngine::InitializeReference( CLR_RT_HeapBlock& ref, CLR_ NANOCLR_HEADER(); CLR_RT_SignatureParser::Element res; - CLR_DataType dt; + CLR_DataType dt; - NANOCLR_CHECK_HRESULT(parser.Advance( res )); + NANOCLR_CHECK_HRESULT(parser.Advance(res)); dt = res.m_dt; - if(res.m_levels > 0) // Array + if (res.m_levels > 0) // Array { dt = DATATYPE_OBJECT; } else { - if(dt == DATATYPE_VALUETYPE) + if (dt == DATATYPE_VALUETYPE) { - CLR_RT_TypeDef_Instance inst; inst.InitializeFromIndex( res.m_cls ); + CLR_RT_TypeDef_Instance inst; + inst.InitializeFromIndex(res.m_cls); - if((inst.m_target->flags & CLR_RECORD_TYPEDEF::TD_Semantics_Mask) == CLR_RECORD_TYPEDEF::TD_Semantics_Enum) + if ((inst.m_target->flags & CLR_RECORD_TYPEDEF::TD_Semantics_Mask) == CLR_RECORD_TYPEDEF::TD_Semantics_Enum) { dt = (CLR_DataType)inst.m_target->dataType; } else { - NANOCLR_SET_AND_LEAVE(NewObject( ref, inst )); + NANOCLR_SET_AND_LEAVE(NewObject(ref, inst)); } } else { - if(c_CLR_RT_DataTypeLookup[ dt ].m_flags & CLR_RT_DataTypeLookup::c_Reference) + if (c_CLR_RT_DataTypeLookup[dt].m_flags & CLR_RT_DataTypeLookup::c_Reference) { dt = DATATYPE_OBJECT; } } } - ref.SetDataId( CLR_RT_HEAPBLOCK_RAW_ID( dt, CLR_RT_HeapBlock::HB_Alive, 1 ) ); + ref.SetDataId(CLR_RT_HEAPBLOCK_RAW_ID(dt, CLR_RT_HeapBlock::HB_Alive, 1)); ref.ClearData(); NANOCLR_NOCLEANUP(); } -HRESULT CLR_RT_ExecutionEngine::InitializeReference( CLR_RT_HeapBlock& ref, const CLR_RECORD_FIELDDEF* target, CLR_RT_Assembly* assm ) +HRESULT CLR_RT_ExecutionEngine::InitializeReference( + CLR_RT_HeapBlock &ref, + const CLR_RECORD_FIELDDEF *target, + CLR_RT_Assembly *assm) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - CLR_RT_SignatureParser parser; parser.Initialize_FieldDef( assm, target ); + CLR_RT_SignatureParser parser; + parser.Initialize_FieldDef(assm, target); - NANOCLR_SET_AND_LEAVE(InitializeReference( ref, parser )); + NANOCLR_SET_AND_LEAVE(InitializeReference(ref, parser)); NANOCLR_NOCLEANUP(); } //--// -HRESULT CLR_RT_ExecutionEngine::InitializeLocals( CLR_RT_HeapBlock* locals, CLR_RT_Assembly* assm, const CLR_RECORD_METHODDEF* md ) +HRESULT CLR_RT_ExecutionEngine::InitializeLocals( + CLR_RT_HeapBlock *locals, + CLR_RT_Assembly *assm, + const CLR_RECORD_METHODDEF *md) { NATIVE_PROFILE_CLR_CORE(); // @@ -1722,139 +1780,141 @@ HRESULT CLR_RT_ExecutionEngine::InitializeLocals( CLR_RT_HeapBlock* locals, CLR_ // // This method is a shortcut for the following code: // - + NANOCLR_HEADER(); - CLR_PMETADATA sig = assm->GetSignature( md->locals ); - CLR_UINT32 count = md->numLocals; - bool fZeroed = false; + CLR_PMETADATA sig = assm->GetSignature(md->locals); + CLR_UINT32 count = md->numLocals; + bool fZeroed = false; - while(count) + while (count) { - CLR_DataType dt = DATATYPE_VOID; + CLR_DataType dt = DATATYPE_VOID; CLR_RT_TypeDef_Index cls; - CLR_UINT32 levels = 0; - CLR_DataType dtModifier = DATATYPE_VOID; + CLR_UINT32 levels = 0; + CLR_DataType dtModifier = DATATYPE_VOID; - while(true) + while (true) { - dt = CLR_UncompressElementType( sig ); + dt = CLR_UncompressElementType(sig); - switch(dt) + switch (dt) { - case DATATYPE_TYPE_PINNED : - dtModifier = DATATYPE_TYPE_PINNED; - break; - - // Array declared on stack .locals init [0] int16[] foo, - case DATATYPE_SZARRAY: - // Reference declared on stack - .locals init [1] int16& pinned pShort, - case DATATYPE_BYREF: - levels++; - break; + case DATATYPE_TYPE_PINNED: + dtModifier = DATATYPE_TYPE_PINNED; + break; - case DATATYPE_CLASS: - case DATATYPE_VALUETYPE: + // Array declared on stack .locals init [0] int16[] foo, + case DATATYPE_SZARRAY: + // Reference declared on stack - .locals init [1] int16& pinned pShort, + case DATATYPE_BYREF: + levels++; + break; + + case DATATYPE_CLASS: + case DATATYPE_VALUETYPE: { - CLR_UINT32 tk = CLR_TkFromStream( sig ); - CLR_UINT32 idx = CLR_DataFromTk( tk ); + CLR_UINT32 tk = CLR_TkFromStream(sig); + CLR_UINT32 idx = CLR_DataFromTk(tk); - switch(CLR_TypeFromTk( tk )) + switch (CLR_TypeFromTk(tk)) { - case TBL_TypeSpec: + case TBL_TypeSpec: { - CLR_RT_SignatureParser sub; sub.Initialize_TypeSpec( assm, assm->GetTypeSpec( idx ) ); + CLR_RT_SignatureParser sub; + sub.Initialize_TypeSpec(assm, assm->GetTypeSpec(idx)); CLR_RT_SignatureParser::Element res; - NANOCLR_CHECK_HRESULT(sub.Advance( res )); + NANOCLR_CHECK_HRESULT(sub.Advance(res)); - cls = res.m_cls; + cls = res.m_cls; levels += res.m_levels; } break; - case TBL_TypeRef: - cls = assm->m_pCrossReference_TypeRef[ idx ].m_target; - break; + case TBL_TypeRef: + cls = assm->m_pCrossReference_TypeRef[idx].m_target; + break; - case TBL_TypeDef: - cls.Set( assm->m_idx, idx ); - break; + case TBL_TypeDef: + cls.Set(assm->m_idx, idx); + break; - default: - NANOCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE); + default: + NANOCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE); } - } - goto done; + goto done; - default: + default: { - const CLR_RT_TypeDef_Index* cls2 = c_CLR_RT_DataTypeLookup[ dt ].m_cls; + const CLR_RT_TypeDef_Index *cls2 = c_CLR_RT_DataTypeLookup[dt].m_cls; - if(cls2 == NULL) + if (cls2 == NULL) { NANOCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE); } cls = *cls2; } - goto done; + goto done; } } -done: - if(levels > 0) // Array or reference + done: + if (levels > 0) // Array or reference { - locals->SetObjectReference( NULL ); - - // If local varialb has DATATYPE_TYPE_PINNED, we mark heap block as - if ( dtModifier == DATATYPE_TYPE_PINNED ) + locals->SetObjectReference(NULL); + + // If local varialb has DATATYPE_TYPE_PINNED, we mark heap block as + if (dtModifier == DATATYPE_TYPE_PINNED) { locals->Pin(); } } else { - if(dt == DATATYPE_VALUETYPE) + if (dt == DATATYPE_VALUETYPE) { - CLR_RT_TypeDef_Instance inst; inst.InitializeFromIndex( cls ); + CLR_RT_TypeDef_Instance inst; + inst.InitializeFromIndex(cls); - if(inst.m_target->dataType != DATATYPE_VALUETYPE) + if (inst.m_target->dataType != DATATYPE_VALUETYPE) { - locals->SetDataId( CLR_RT_HEAPBLOCK_RAW_ID( inst.m_target->dataType, CLR_RT_HeapBlock::HB_Alive, 1 ) ); + locals->SetDataId(CLR_RT_HEAPBLOCK_RAW_ID(inst.m_target->dataType, CLR_RT_HeapBlock::HB_Alive, 1)); locals->ClearData(); } else { // - // Before we allocate anything, we need to make sure the rest of the local variables are in a consistent state. + // Before we allocate anything, we need to make sure the rest of the local variables are in a + // consistent state. // - if(fZeroed == false) + if (fZeroed == false) { fZeroed = true; - CLR_RT_HeapBlock* ptr = locals; - CLR_RT_HeapBlock* ptrEnd = &locals[ count ]; + CLR_RT_HeapBlock *ptr = locals; + CLR_RT_HeapBlock *ptrEnd = &locals[count]; do { - ptr->SetDataId( CLR_RT_HEAPBLOCK_RAW_ID(DATATYPE_I4,0,1) ); + ptr->SetDataId(CLR_RT_HEAPBLOCK_RAW_ID(DATATYPE_I4, 0, 1)); - } while(++ptr < ptrEnd); + } while (++ptr < ptrEnd); } - NANOCLR_CHECK_HRESULT(NewObject( *locals, inst )); + NANOCLR_CHECK_HRESULT(NewObject(*locals, inst)); } } else { - if(c_CLR_RT_DataTypeLookup[ dt ].m_flags & CLR_RT_DataTypeLookup::c_Reference) + if (c_CLR_RT_DataTypeLookup[dt].m_flags & CLR_RT_DataTypeLookup::c_Reference) { dt = DATATYPE_OBJECT; } - locals->SetDataId( CLR_RT_HEAPBLOCK_RAW_ID(dt,CLR_RT_HeapBlock::HB_Alive,1) ); + locals->SetDataId(CLR_RT_HEAPBLOCK_RAW_ID(dt, CLR_RT_HeapBlock::HB_Alive, 1)); locals->ClearData(); } } @@ -1868,155 +1928,164 @@ HRESULT CLR_RT_ExecutionEngine::InitializeLocals( CLR_RT_HeapBlock* locals, CLR_ //--// -HRESULT CLR_RT_ExecutionEngine::NewObjectFromIndex( CLR_RT_HeapBlock& reference, const CLR_RT_TypeDef_Index& cls ) +HRESULT CLR_RT_ExecutionEngine::NewObjectFromIndex(CLR_RT_HeapBlock &reference, const CLR_RT_TypeDef_Index &cls) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); CLR_RT_TypeDef_Instance inst; - if(inst.InitializeFromIndex( cls ) == false) NANOCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE); + if (inst.InitializeFromIndex(cls) == false) + NANOCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE); - NANOCLR_SET_AND_LEAVE(NewObject( reference, inst )); + NANOCLR_SET_AND_LEAVE(NewObject(reference, inst)); NANOCLR_NOCLEANUP(); } -HRESULT CLR_RT_ExecutionEngine::NewObject( CLR_RT_HeapBlock& reference, const CLR_RT_TypeDef_Instance& inst ) +HRESULT CLR_RT_ExecutionEngine::NewObject(CLR_RT_HeapBlock &reference, const CLR_RT_TypeDef_Instance &inst) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - reference.SetObjectReference( NULL ); + reference.SetObjectReference(NULL); CLR_DataType dt = (CLR_DataType)inst.m_target->dataType; // // You cannot create an array this way. // - if(inst.m_data == g_CLR_RT_WellKnownTypes.m_Array.m_data) + if (inst.m_data == g_CLR_RT_WellKnownTypes.m_Array.m_data) { NANOCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE); } - if((c_CLR_RT_DataTypeLookup[ dt ].m_flags & CLR_RT_DataTypeLookup::c_Reference) == 0) + if ((c_CLR_RT_DataTypeLookup[dt].m_flags & CLR_RT_DataTypeLookup::c_Reference) == 0) { - reference.SetDataId( CLR_RT_HEAPBLOCK_RAW_ID(dt,0,1) ); + reference.SetDataId(CLR_RT_HEAPBLOCK_RAW_ID(dt, 0, 1)); } else { - switch(dt) + switch (dt) { - case DATATYPE_STRING: - // - // Special case for strings. - // - break; + case DATATYPE_STRING: + // + // Special case for strings. + // + break; - case DATATYPE_WEAKCLASS: + case DATATYPE_WEAKCLASS: { - CLR_RT_HeapBlock_WeakReference* weakref; + CLR_RT_HeapBlock_WeakReference *weakref; - // this used to be a call to CLR_RT_HeapBlock_WeakReference::CreateInstance - weakref = (CLR_RT_HeapBlock_WeakReference*)g_CLR_RT_ExecutionEngine.ExtractHeapBytesForObjects( DATATYPE_WEAKCLASS, CLR_RT_HeapBlock::HB_InitializeToZero, sizeof(*weakref) ); + // this used to be a call to CLR_RT_HeapBlock_WeakReference::CreateInstance + weakref = (CLR_RT_HeapBlock_WeakReference *)g_CLR_RT_ExecutionEngine.ExtractHeapBytesForObjects( + DATATYPE_WEAKCLASS, + CLR_RT_HeapBlock::HB_InitializeToZero, + sizeof(*weakref)); CHECK_ALLOCATION(weakref); - reference.SetObjectReference( weakref ); + reference.SetObjectReference(weakref); } break; - case DATATYPE_CLASS: - case DATATYPE_VALUETYPE: + case DATATYPE_CLASS: + case DATATYPE_VALUETYPE: { - int clsFields = inst.m_target->iFields_Num; - int totFields = inst.CrossReference().m_totalFields + CLR_RT_HeapBlock::HB_Object_Fields_Offset; - CLR_RT_HeapBlock* obj = ExtractHeapBlocksForClassOrValueTypes( dt, 0, inst, totFields ); CHECK_ALLOCATION(obj); + int clsFields = inst.m_target->iFields_Num; + int totFields = inst.CrossReference().m_totalFields + CLR_RT_HeapBlock::HB_Object_Fields_Offset; + CLR_RT_HeapBlock *obj = ExtractHeapBlocksForClassOrValueTypes(dt, 0, inst, totFields); + CHECK_ALLOCATION(obj); - reference.SetObjectReference( obj ); + reference.SetObjectReference(obj); { - const CLR_RECORD_FIELDDEF* target = NULL; - CLR_RT_Assembly* assm = NULL; - CLR_RT_TypeDef_Instance instSub = inst; - + const CLR_RECORD_FIELDDEF *target = NULL; + CLR_RT_Assembly *assm = NULL; + CLR_RT_TypeDef_Instance instSub = inst; - NANOCLR_CHECK_HRESULT(obj->SetObjectCls( inst )); + NANOCLR_CHECK_HRESULT(obj->SetObjectCls(inst)); // // Initialize field types, from last to first. // - // We do the decrement BEFORE the comparison because we want to stop short of the first field, the object descriptor (already initialized). + // We do the decrement BEFORE the comparison because we want to stop short of the first field, the + // object descriptor (already initialized). // obj += totFields; - while(--totFields > 0) + while (--totFields > 0) { - while(clsFields == 0) + while (clsFields == 0) { - if(instSub.SwitchToParent() == false) NANOCLR_SET_AND_LEAVE(CLR_E_FAIL); + if (instSub.SwitchToParent() == false) + NANOCLR_SET_AND_LEAVE(CLR_E_FAIL); clsFields = instSub.m_target->iFields_Num; - target = NULL; + target = NULL; } - if(target == NULL) + if (target == NULL) { - assm = instSub.m_assm; - target = assm->GetFieldDef( instSub.m_target->iFields_First + clsFields ); + assm = instSub.m_assm; + target = assm->GetFieldDef(instSub.m_target->iFields_First + clsFields); } - obj--; target--; clsFields--; + obj--; + target--; + clsFields--; - NANOCLR_CHECK_HRESULT(InitializeReference( *obj, target, assm )); + NANOCLR_CHECK_HRESULT(InitializeReference(*obj, target, assm)); } } - if(inst.HasFinalizer()) + if (inst.HasFinalizer()) { - NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_Finalizer::CreateInstance( reference.Dereference(), inst )); + NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_Finalizer::CreateInstance(reference.Dereference(), inst)); } } break; - default: - NANOCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE); + default: + NANOCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE); } } NANOCLR_NOCLEANUP(); } -HRESULT CLR_RT_ExecutionEngine::NewObject( CLR_RT_HeapBlock& reference, CLR_UINT32 tk, CLR_RT_Assembly* assm ) +HRESULT CLR_RT_ExecutionEngine::NewObject(CLR_RT_HeapBlock &reference, CLR_UINT32 tk, CLR_RT_Assembly *assm) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); CLR_RT_TypeDef_Instance res; - if(res.ResolveToken( tk, assm ) == false) NANOCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE); + if (res.ResolveToken(tk, assm) == false) + NANOCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE); - NANOCLR_CHECK_HRESULT(NewObjectFromIndex( reference, res )); + NANOCLR_CHECK_HRESULT(NewObjectFromIndex(reference, res)); NANOCLR_NOCLEANUP(); } //--// -HRESULT CLR_RT_ExecutionEngine::CloneObject( CLR_RT_HeapBlock& reference, const CLR_RT_HeapBlock& source ) +HRESULT CLR_RT_ExecutionEngine::CloneObject(CLR_RT_HeapBlock &reference, const CLR_RT_HeapBlock &source) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - const CLR_RT_HeapBlock* obj = &source; - CLR_DataType dt; + const CLR_RT_HeapBlock *obj = &source; + CLR_DataType dt; - while(true) + while (true) { dt = (CLR_DataType)obj->DataType(); - if(dt == DATATYPE_BYREF || - dt == DATATYPE_OBJECT ) + if (dt == DATATYPE_BYREF || dt == DATATYPE_OBJECT) { - obj = obj->Dereference(); FAULT_ON_NULL(obj); + obj = obj->Dereference(); + FAULT_ON_NULL(obj); } else { @@ -2024,65 +2093,69 @@ HRESULT CLR_RT_ExecutionEngine::CloneObject( CLR_RT_HeapBlock& reference, const } } - switch(dt) + switch (dt) { - case DATATYPE_VALUETYPE: - case DATATYPE_CLASS: + case DATATYPE_VALUETYPE: + case DATATYPE_CLASS: { // // Save the pointer to the object to clone, in case 'reference' and 'source' point to the same block. // - CLR_RT_HeapBlock safeSource; safeSource.SetObjectReference( obj ); - CLR_RT_ProtectFromGC gc( safeSource ); + CLR_RT_HeapBlock safeSource; + safeSource.SetObjectReference(obj); + CLR_RT_ProtectFromGC gc(safeSource); - NANOCLR_CHECK_HRESULT(NewObjectFromIndex( reference , obj->ObjectCls() )); - NANOCLR_CHECK_HRESULT(CopyValueType ( reference.Dereference(), obj )); + NANOCLR_CHECK_HRESULT(NewObjectFromIndex(reference, obj->ObjectCls())); + NANOCLR_CHECK_HRESULT(CopyValueType(reference.Dereference(), obj)); } break; - default: - if((c_CLR_RT_DataTypeLookup[ dt ].m_flags & CLR_RT_DataTypeLookup::c_OptimizedValueType) == 0) - { - NANOCLR_SET_AND_LEAVE(CLR_E_NOT_SUPPORTED); - } + default: + if ((c_CLR_RT_DataTypeLookup[dt].m_flags & CLR_RT_DataTypeLookup::c_OptimizedValueType) == 0) + { + NANOCLR_SET_AND_LEAVE(CLR_E_NOT_SUPPORTED); + } - // - // Non-reference type, straight copy. - // - reference.Assign( source ); - break; + // + // Non-reference type, straight copy. + // + reference.Assign(source); + break; } NANOCLR_NOCLEANUP(); } -HRESULT CLR_RT_ExecutionEngine::CopyValueType( CLR_RT_HeapBlock* destination, const CLR_RT_HeapBlock* source ) +HRESULT CLR_RT_ExecutionEngine::CopyValueType(CLR_RT_HeapBlock *destination, const CLR_RT_HeapBlock *source) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - if(destination != source) + if (destination != source) { - const CLR_RT_TypeDef_Index& cls = source->ObjectCls(); - if(cls.m_data == destination->ObjectCls().m_data) + const CLR_RT_TypeDef_Index &cls = source->ObjectCls(); + if (cls.m_data == destination->ObjectCls().m_data) { - CLR_RT_TypeDef_Instance inst; inst.InitializeFromIndex( cls ); - CLR_UINT32 totFields = inst.CrossReference().m_totalFields; + CLR_RT_TypeDef_Instance inst; + inst.InitializeFromIndex(cls); + CLR_UINT32 totFields = inst.CrossReference().m_totalFields; - if(source->IsBoxed()) destination->Box(); + if (source->IsBoxed()) + destination->Box(); - while(true) + while (true) { - if(totFields-- == 0) break; + if (totFields-- == 0) + break; // // We increment the two pointers to skip the header of the objects. // - source ++; + source++; destination++; - NANOCLR_CHECK_HRESULT(destination->Reassign( *source )); + NANOCLR_CHECK_HRESULT(destination->Reassign(*source)); } NANOCLR_SET_AND_LEAVE(S_OK); @@ -2096,26 +2169,29 @@ HRESULT CLR_RT_ExecutionEngine::CopyValueType( CLR_RT_HeapBlock* destination, co //--// -HRESULT CLR_RT_ExecutionEngine::NewArrayList( CLR_RT_HeapBlock& ref, int size, CLR_RT_HeapBlock_Array*& array ) +HRESULT CLR_RT_ExecutionEngine::NewArrayList(CLR_RT_HeapBlock &ref, int size, CLR_RT_HeapBlock_Array *&array) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); const int minCapacity = CLR_RT_ArrayListHelper::c_defaultCapacity; - int count = size; - int capacity = size < minCapacity ? minCapacity : size; + int count = size; + int capacity = size < minCapacity ? minCapacity : size; - NANOCLR_CHECK_HRESULT(NewObjectFromIndex( ref, g_CLR_RT_WellKnownTypes.m_ArrayList )); + NANOCLR_CHECK_HRESULT(NewObjectFromIndex(ref, g_CLR_RT_WellKnownTypes.m_ArrayList)); - NANOCLR_CHECK_HRESULT(CLR_RT_ArrayListHelper::PrepareArrayList ( ref, count, capacity )); - NANOCLR_CHECK_HRESULT(CLR_RT_ArrayListHelper::ExtractArrayFromArrayList( ref, array, count, capacity )); + NANOCLR_CHECK_HRESULT(CLR_RT_ArrayListHelper::PrepareArrayList(ref, count, capacity)); + NANOCLR_CHECK_HRESULT(CLR_RT_ArrayListHelper::ExtractArrayFromArrayList(ref, array, count, capacity)); NANOCLR_NOCLEANUP(); } //--// -HRESULT CLR_RT_ExecutionEngine::FindFieldDef( CLR_RT_TypeDef_Instance& inst, const char* szText, CLR_RT_FieldDef_Index& res ) +HRESULT CLR_RT_ExecutionEngine::FindFieldDef( + CLR_RT_TypeDef_Instance &inst, + const char *szText, + CLR_RT_FieldDef_Index &res) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); @@ -2124,59 +2200,67 @@ HRESULT CLR_RT_ExecutionEngine::FindFieldDef( CLR_RT_TypeDef_Instance& inst, con do { - if(local.m_assm->FindFieldDef( local.m_target, szText, NULL, 0, res )) NANOCLR_SET_AND_LEAVE(S_OK); - } - while(local.SwitchToParent()); + if (local.m_assm->FindFieldDef(local.m_target, szText, NULL, 0, res)) + NANOCLR_SET_AND_LEAVE(S_OK); + } while (local.SwitchToParent()); NANOCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE); NANOCLR_NOCLEANUP(); } -HRESULT CLR_RT_ExecutionEngine::FindFieldDef( CLR_RT_HeapBlock& reference, const char* szText, CLR_RT_FieldDef_Index& res ) +HRESULT CLR_RT_ExecutionEngine::FindFieldDef( + CLR_RT_HeapBlock &reference, + const char *szText, + CLR_RT_FieldDef_Index &res) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - CLR_RT_HeapBlock* obj; + CLR_RT_HeapBlock *obj; CLR_RT_TypeDef_Instance inst; - if(reference.DataType() != DATATYPE_OBJECT) NANOCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE); + if (reference.DataType() != DATATYPE_OBJECT) + NANOCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE); - obj = reference.Dereference(); FAULT_ON_NULL(obj); + obj = reference.Dereference(); + FAULT_ON_NULL(obj); - if(inst.InitializeFromIndex( obj->ObjectCls() ) == false) + if (inst.InitializeFromIndex(obj->ObjectCls()) == false) { NANOCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE); } - NANOCLR_SET_AND_LEAVE(FindFieldDef( inst, szText, res )); + NANOCLR_SET_AND_LEAVE(FindFieldDef(inst, szText, res)); NANOCLR_NOCLEANUP(); } -HRESULT CLR_RT_ExecutionEngine::FindField( CLR_RT_HeapBlock& reference, const char* szText, CLR_RT_HeapBlock*& field ) +HRESULT CLR_RT_ExecutionEngine::FindField(CLR_RT_HeapBlock &reference, const char *szText, CLR_RT_HeapBlock *&field) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - CLR_RT_FieldDef_Instance inst; - CLR_RT_FieldDef_Index idx; - CLR_RT_HeapBlock* res; + CLR_RT_FieldDef_Instance inst; + CLR_RT_FieldDef_Index idx; + CLR_RT_HeapBlock *res; field = NULL; - NANOCLR_CHECK_HRESULT(FindFieldDef( reference, szText, idx )); + NANOCLR_CHECK_HRESULT(FindFieldDef(reference, szText, idx)); - inst.InitializeFromIndex( idx ); + inst.InitializeFromIndex(idx); - if(inst.m_target->flags & CLR_RECORD_FIELDDEF::FD_Static) + if (inst.m_target->flags & CLR_RECORD_FIELDDEF::FD_Static) { - res = CLR_RT_ExecutionEngine::AccessStaticField( idx ); if(res == NULL) NANOCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE); + res = CLR_RT_ExecutionEngine::AccessStaticField(idx); + if (res == NULL) + NANOCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE); } else { - res = reference.Dereference(); FAULT_ON_NULL(res); + res = reference.Dereference(); + FAULT_ON_NULL(res); res += inst.CrossReference().m_offset; } @@ -2186,50 +2270,51 @@ HRESULT CLR_RT_ExecutionEngine::FindField( CLR_RT_HeapBlock& reference, const ch NANOCLR_NOCLEANUP(); } -HRESULT CLR_RT_ExecutionEngine::SetField( CLR_RT_HeapBlock& reference, const char* szText, CLR_RT_HeapBlock& value ) +HRESULT CLR_RT_ExecutionEngine::SetField(CLR_RT_HeapBlock &reference, const char *szText, CLR_RT_HeapBlock &value) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - CLR_RT_HeapBlock* field; + CLR_RT_HeapBlock *field; - NANOCLR_CHECK_HRESULT(FindField( reference, szText, field )); + NANOCLR_CHECK_HRESULT(FindField(reference, szText, field)); - field->Assign( value ); + field->Assign(value); NANOCLR_NOCLEANUP(); } -HRESULT CLR_RT_ExecutionEngine::GetField( CLR_RT_HeapBlock& reference, const char* szText, CLR_RT_HeapBlock& value ) +HRESULT CLR_RT_ExecutionEngine::GetField(CLR_RT_HeapBlock &reference, const char *szText, CLR_RT_HeapBlock &value) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - CLR_RT_HeapBlock* field; + CLR_RT_HeapBlock *field; - NANOCLR_CHECK_HRESULT(FindField( reference, szText, field )); + NANOCLR_CHECK_HRESULT(FindField(reference, szText, field)); - value.Assign( *field ); + value.Assign(*field); NANOCLR_NOCLEANUP(); } //--// -CLR_RT_HeapBlock_Lock* CLR_RT_ExecutionEngine::FindLockObject( CLR_RT_DblLinkedList& threads, CLR_RT_HeapBlock& object ) +CLR_RT_HeapBlock_Lock *CLR_RT_ExecutionEngine::FindLockObject(CLR_RT_DblLinkedList &threads, CLR_RT_HeapBlock &object) { NATIVE_PROFILE_CLR_CORE(); - NANOCLR_FOREACH_NODE(CLR_RT_Thread,th,threads) + NANOCLR_FOREACH_NODE(CLR_RT_Thread, th, threads) { - NANOCLR_FOREACH_NODE(CLR_RT_HeapBlock_Lock,lock,th->m_locks) - { - CLR_RT_HeapBlock& res = lock->m_resource; + NANOCLR_FOREACH_NODE(CLR_RT_HeapBlock_Lock, lock, th->m_locks) + { + CLR_RT_HeapBlock &res = lock->m_resource; #if defined(NANOCLR_APPDOMAINS) - if(lock->m_appDomain != GetCurrentAppDomain()) continue; + if (lock->m_appDomain != GetCurrentAppDomain()) + continue; #endif - if(CLR_RT_HeapBlock::ObjectsEqual(res, object, true)) + if (CLR_RT_HeapBlock::ObjectsEqual(res, object, true)) { return lock; } @@ -2241,63 +2326,69 @@ CLR_RT_HeapBlock_Lock* CLR_RT_ExecutionEngine::FindLockObject( CLR_RT_DblLinkedL return NULL; } -CLR_RT_HeapBlock_Lock* CLR_RT_ExecutionEngine::FindLockObject( CLR_RT_HeapBlock& object ) +CLR_RT_HeapBlock_Lock *CLR_RT_ExecutionEngine::FindLockObject(CLR_RT_HeapBlock &object) { NATIVE_PROFILE_CLR_CORE(); - CLR_RT_HeapBlock_Lock* lock; + CLR_RT_HeapBlock_Lock *lock; - if(object.DataType() == DATATYPE_OBJECT) + if (object.DataType() == DATATYPE_OBJECT) { - CLR_RT_HeapBlock* ptr = object.Dereference(); + CLR_RT_HeapBlock *ptr = object.Dereference(); - if(ptr) + if (ptr) { - switch(ptr->DataType()) + switch (ptr->DataType()) { case DATATYPE_VALUETYPE: - case DATATYPE_CLASS : + case DATATYPE_CLASS: return ptr->ObjectLock(); default: // the remaining data types aren't to be handled - break; + break; } } } - lock = FindLockObject( m_threadsReady , object ); if(lock) return lock; - lock = FindLockObject( m_threadsWaiting, object ); return lock; + lock = FindLockObject(m_threadsReady, object); + if (lock) + return lock; + lock = FindLockObject(m_threadsWaiting, object); + return lock; } //--// -void CLR_RT_ExecutionEngine::DeleteLockRequests( CLR_RT_Thread* thTarget, CLR_RT_SubThread* sthTarget ) +void CLR_RT_ExecutionEngine::DeleteLockRequests(CLR_RT_Thread *thTarget, CLR_RT_SubThread *sthTarget) { NATIVE_PROFILE_CLR_CORE(); - if(( thTarget && thTarget->m_lockRequestsCount) || - (sthTarget && sthTarget->m_lockRequestsCount) ) + if ((thTarget && thTarget->m_lockRequestsCount) || (sthTarget && sthTarget->m_lockRequestsCount)) { - DeleteLockRequests( thTarget, sthTarget, m_threadsReady ); - DeleteLockRequests( thTarget, sthTarget, m_threadsWaiting ); + DeleteLockRequests(thTarget, sthTarget, m_threadsReady); + DeleteLockRequests(thTarget, sthTarget, m_threadsWaiting); } } -void CLR_RT_ExecutionEngine::DeleteLockRequests( CLR_RT_Thread* thTarget, CLR_RT_SubThread* sthTarget, CLR_RT_DblLinkedList& threads ) +void CLR_RT_ExecutionEngine::DeleteLockRequests( + CLR_RT_Thread *thTarget, + CLR_RT_SubThread *sthTarget, + CLR_RT_DblLinkedList &threads) { NATIVE_PROFILE_CLR_CORE(); - NANOCLR_FOREACH_NODE(CLR_RT_Thread,th,threads) + NANOCLR_FOREACH_NODE(CLR_RT_Thread, th, threads) { - NANOCLR_FOREACH_NODE(CLR_RT_HeapBlock_Lock,lock,th->m_locks) + NANOCLR_FOREACH_NODE(CLR_RT_HeapBlock_Lock, lock, th->m_locks) { - NANOCLR_FOREACH_NODE(CLR_RT_HeapBlock_LockRequest,req,lock->m_requests) + NANOCLR_FOREACH_NODE(CLR_RT_HeapBlock_LockRequest, req, lock->m_requests) { - CLR_RT_SubThread* sth = req->m_subthreadWaiting; + CLR_RT_SubThread *sth = req->m_subthreadWaiting; - if(sth == sthTarget || sth->m_owningThread == thTarget) + if (sth == sthTarget || sth->m_owningThread == thTarget) { - g_CLR_RT_EventCache.Append_Node( req ); + g_CLR_RT_EventCache.Append_Node(req); - if(sth->ChangeLockRequestCount( -1 )) return; + if (sth->ChangeLockRequestCount(-1)) + return; } } NANOCLR_FOREACH_NODE_END(); @@ -2329,67 +2420,66 @@ CLR_INT64 CLR_RT_ExecutionEngine::ProcessTimer() //////////////////////////////////////////////// // WARNING - // - // The check on the 'Stopped' condition, and the 'else' - // condition below cause a race condition when the application is running under debugger + // + // The check on the 'Stopped' condition, and the 'else' + // condition below cause a race condition when the application is running under debugger // and there are no ready threads in the app. teh desktop side debugger in facts is prodigal - // of Stopped commands and so is the runtime itself. Since the commands come asynchronously - // though and there is no co-ordination it is possible that + // of Stopped commands and so is the runtime itself. Since the commands come asynchronously + // though and there is no co-ordination it is possible that // a) a 'Stopped' condition reset get lost or // b) waiting threads whose timers are expired are never moved to the ready queue - // - - if(CLR_EE_DBG_IS( Stopped ) && m_threadsWaiting.IsEmpty()) + // + + if (CLR_EE_DBG_IS(Stopped) && m_threadsWaiting.IsEmpty()) { // Don't process events while the debugger is stopped and no thread was waiting. // if some thread was waiting we might need to transfer it to the ready queue } else { - if(m_timerCache && m_timerCacheNextTimeout > HAL_Time_CurrentTime()) + if (m_timerCache && m_timerCacheNextTimeout > HAL_Time_CurrentTime()) { timeoutMin = m_timerCacheNextTimeout - HAL_Time_CurrentTime(); } - //else + // else { - CheckTimers( timeoutMin ); - - CheckThreads( timeoutMin, m_threadsReady ); - CheckThreads( timeoutMin, m_threadsWaiting ); + CheckTimers(timeoutMin); + + CheckThreads(timeoutMin, m_threadsReady); + CheckThreads(timeoutMin, m_threadsWaiting); m_timerCacheNextTimeout = timeoutMin + HAL_Time_CurrentTime(); - m_timerCache = (m_timerCacheNextTimeout > HAL_Time_CurrentTime()); - + m_timerCache = (m_timerCacheNextTimeout > HAL_Time_CurrentTime()); } } // if the system timer is not set as one of the wakeup events then just return the max time to active - if(0 == (g_CLR_HW_Hardware.m_wakeupEvents & SYSTEM_EVENT_FLAG_SYSTEM_TIMER)) + if (0 == (g_CLR_HW_Hardware.m_wakeupEvents & SYSTEM_EVENT_FLAG_SYSTEM_TIMER)) { timeoutMin = m_maximumTimeToActive; - } + } return timeoutMin; } -void CLR_RT_ExecutionEngine::ProcessTimeEvent( CLR_UINT32 event ) +void CLR_RT_ExecutionEngine::ProcessTimeEvent(CLR_UINT32 event) { NATIVE_PROFILE_CLR_CORE(); SYSTEMTIME systemTime; - HAL_Time_ToSystemTime( HAL_Time_CurrentTime(), &systemTime ); + HAL_Time_ToSystemTime(HAL_Time_CurrentTime(), &systemTime); - NANOCLR_FOREACH_NODE(CLR_RT_HeapBlock_Timer,timer,m_timers) + NANOCLR_FOREACH_NODE(CLR_RT_HeapBlock_Timer, timer, m_timers) { - if(timer->m_flags & CLR_RT_HeapBlock_Timer::c_EnabledTimer) + if (timer->m_flags & CLR_RT_HeapBlock_Timer::c_EnabledTimer) { CLR_UINT32 val = timer->m_flags & CLR_RT_HeapBlock_Timer::c_AnyChange; - if(val) + if (val) { - timer->AdjustNextFixedExpire( systemTime, true ); + timer->AdjustNextFixedExpire(systemTime, true); - if(val == event && (timer->m_flags & CLR_RT_HeapBlock_Timer::c_Recurring) == 0) + if (val == event && (timer->m_flags & CLR_RT_HeapBlock_Timer::c_Recurring) == 0) { timer->Trigger(); } @@ -2409,15 +2499,16 @@ void CLR_RT_ExecutionEngine::InvalidateTimerCache() //--//--// -bool CLR_RT_ExecutionEngine::IsTimeExpired( const CLR_INT64& timeExpire, CLR_INT64& timeoutMin ) +bool CLR_RT_ExecutionEngine::IsTimeExpired(const CLR_INT64 &timeExpire, CLR_INT64 &timeoutMin) { NATIVE_PROFILE_CLR_CORE(); - if(timeExpire <= (CLR_INT64)HAL_Time_CurrentTime()) return true; + if (timeExpire <= (CLR_INT64)HAL_Time_CurrentTime()) + return true; CLR_INT64 diff = timeExpire - HAL_Time_CurrentTime(); - if(diff < timeoutMin) + if (diff < timeoutMin) { timeoutMin = diff; } @@ -2425,36 +2516,38 @@ bool CLR_RT_ExecutionEngine::IsTimeExpired( const CLR_INT64& timeExpire, CLR_INT return false; } -bool CLR_RT_ExecutionEngine::IsThereEnoughIdleTime( CLR_UINT32 expectedMsec ) +bool CLR_RT_ExecutionEngine::IsThereEnoughIdleTime(CLR_UINT32 expectedMsec) { NATIVE_PROFILE_CLR_CORE(); - if(::Events_MaskedRead( g_CLR_HW_Hardware.m_wakeupEvents )) return false; + if (::Events_MaskedRead(g_CLR_HW_Hardware.m_wakeupEvents)) + return false; CLR_INT64 now = HAL_Time_CurrentTime(); - if(now + expectedMsec * TIME_CONVERSION__TO_MILLISECONDS >= m_currentNextActivityTime) return false; + if (now + expectedMsec * TIME_CONVERSION__TO_MILLISECONDS >= m_currentNextActivityTime) + return false; return true; } //--// -void CLR_RT_ExecutionEngine::CheckTimers( CLR_INT64& timeoutMin ) +void CLR_RT_ExecutionEngine::CheckTimers(CLR_INT64 &timeoutMin) { NATIVE_PROFILE_CLR_CORE(); bool fAnyTimersExpired = false; - NANOCLR_FOREACH_NODE(CLR_RT_HeapBlock_Timer,timer,m_timers) + NANOCLR_FOREACH_NODE(CLR_RT_HeapBlock_Timer, timer, m_timers) { - if(timer->m_flags & CLR_RT_HeapBlock_Timer::c_EnabledTimer) + if (timer->m_flags & CLR_RT_HeapBlock_Timer::c_EnabledTimer) { CLR_INT64 expire = timer->m_timeExpire; - if(IsTimeExpired( expire, timeoutMin )) + if (IsTimeExpired(expire, timeoutMin)) { - - #if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) - if(CLR_EE_DBG_IS_NOT( PauseTimers )) - #endif + +#if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) + if (CLR_EE_DBG_IS_NOT(PauseTimers)) +#endif { timer->Trigger(); fAnyTimersExpired = true; @@ -2464,23 +2557,22 @@ void CLR_RT_ExecutionEngine::CheckTimers( CLR_INT64& timeoutMin ) } NANOCLR_FOREACH_NODE_END(); - if(fAnyTimersExpired) + if (fAnyTimersExpired) { SpawnTimer(); } - } -void CLR_RT_ExecutionEngine::CheckThreads( CLR_INT64& timeoutMin, CLR_RT_DblLinkedList& threads ) +void CLR_RT_ExecutionEngine::CheckThreads(CLR_INT64 &timeoutMin, CLR_RT_DblLinkedList &threads) { NATIVE_PROFILE_CLR_CORE(); - NANOCLR_FOREACH_NODE(CLR_RT_Thread,th,threads) + NANOCLR_FOREACH_NODE(CLR_RT_Thread, th, threads) { CLR_INT64 expire; #if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) - if(th->m_flags & CLR_RT_Thread::TH_F_Suspended) + if (th->m_flags & CLR_RT_Thread::TH_F_Suspended) { continue; } @@ -2490,11 +2582,11 @@ void CLR_RT_ExecutionEngine::CheckThreads( CLR_INT64& timeoutMin, CLR_RT_DblLink // Check events. // expire = th->m_waitForEvents_Timeout; - if(IsTimeExpired( expire, timeoutMin )) + if (IsTimeExpired(expire, timeoutMin)) { th->m_waitForEvents_Timeout = TIMEOUT_INFINITE; - th->Restart( false ); + th->Restart(false); } // @@ -2502,15 +2594,15 @@ void CLR_RT_ExecutionEngine::CheckThreads( CLR_INT64& timeoutMin, CLR_RT_DblLink // { - CLR_RT_HeapBlock_WaitForObject* wait = th->m_waitForObject; + CLR_RT_HeapBlock_WaitForObject *wait = th->m_waitForObject; - if(wait) + if (wait) { - if(IsTimeExpired( wait->m_timeExpire, timeoutMin )) + if (IsTimeExpired(wait->m_timeExpire, timeoutMin)) { th->m_waitForObject_Result = CLR_RT_Thread::TH_WAIT_RESULT_TIMEOUT; - - th->Restart( true ); + + th->Restart(true); } } } @@ -2518,17 +2610,17 @@ void CLR_RT_ExecutionEngine::CheckThreads( CLR_INT64& timeoutMin, CLR_RT_DblLink // // Check lock requests. // - NANOCLR_FOREACH_NODE(CLR_RT_HeapBlock_Lock,lock,th->m_locks) + NANOCLR_FOREACH_NODE(CLR_RT_HeapBlock_Lock, lock, th->m_locks) { - NANOCLR_FOREACH_NODE(CLR_RT_HeapBlock_LockRequest,req,lock->m_requests) + NANOCLR_FOREACH_NODE(CLR_RT_HeapBlock_LockRequest, req, lock->m_requests) { - if(IsTimeExpired( req->m_timeExpire, timeoutMin )) + if (IsTimeExpired(req->m_timeExpire, timeoutMin)) { - CLR_RT_SubThread* sth = req->m_subthreadWaiting; + CLR_RT_SubThread *sth = req->m_subthreadWaiting; - sth->ChangeLockRequestCount( -1 ); + sth->ChangeLockRequestCount(-1); - g_CLR_RT_EventCache.Append_Node( req ); + g_CLR_RT_EventCache.Append_Node(req); } } NANOCLR_FOREACH_NODE_END(); @@ -2538,26 +2630,31 @@ void CLR_RT_ExecutionEngine::CheckThreads( CLR_INT64& timeoutMin, CLR_RT_DblLink // // Check constraints. // - NANOCLR_FOREACH_NODE_BACKWARD(CLR_RT_SubThread,sth,th->m_subThreads) + NANOCLR_FOREACH_NODE_BACKWARD(CLR_RT_SubThread, sth, th->m_subThreads) { - if(sth->m_timeConstraint != TIMEOUT_INFINITE) + if (sth->m_timeConstraint != TIMEOUT_INFINITE) { - if(IsTimeExpired( s_compensation.Adjust( sth->m_timeConstraint ), timeoutMin )) + if (IsTimeExpired(s_compensation.Adjust(sth->m_timeConstraint), timeoutMin)) { - (void)Library_corlib_native_System_Exception::CreateInstance( th->m_currentException, g_CLR_RT_WellKnownTypes.m_ConstraintException, S_OK, th->CurrentFrame() ); + (void)Library_corlib_native_System_Exception::CreateInstance( + th->m_currentException, + g_CLR_RT_WellKnownTypes.m_ConstraintException, + S_OK, + th->CurrentFrame()); - if((sth->m_status & CLR_RT_SubThread::STATUS_Triggered) == 0) + if ((sth->m_status & CLR_RT_SubThread::STATUS_Triggered) == 0) { sth->m_status |= CLR_RT_SubThread::STATUS_Triggered; // // This is the first time, give it 500msec to clean before killing it. // - sth->m_timeConstraint += TIME_CONVERSION__TO_MILLISECONDS * 500; CLR_RT_ExecutionEngine::InvalidateTimerCache(); + sth->m_timeConstraint += TIME_CONVERSION__TO_MILLISECONDS * 500; + CLR_RT_ExecutionEngine::InvalidateTimerCache(); } else { - CLR_RT_SubThread::DestroyInstance( th, sth, CLR_RT_SubThread::MODE_CheckLocks ); + CLR_RT_SubThread::DestroyInstance(th, sth, CLR_RT_SubThread::MODE_CheckLocks); // // So it doesn't fire again... @@ -2565,7 +2662,7 @@ void CLR_RT_ExecutionEngine::CheckThreads( CLR_INT64& timeoutMin, CLR_RT_DblLink sth->m_timeConstraint = TIMEOUT_INFINITE; } - th->Restart( true ); + th->Restart(true); } } } @@ -2576,48 +2673,53 @@ void CLR_RT_ExecutionEngine::CheckThreads( CLR_INT64& timeoutMin, CLR_RT_DblLink //--// -HRESULT CLR_RT_ExecutionEngine::LockObject( CLR_RT_HeapBlock& reference, CLR_RT_SubThread* sth, const CLR_INT64& timeExpire, bool fForce ) +HRESULT CLR_RT_ExecutionEngine::LockObject( + CLR_RT_HeapBlock &reference, + CLR_RT_SubThread *sth, + const CLR_INT64 &timeExpire, + bool fForce) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - CLR_RT_HeapBlock_Lock* lock; + CLR_RT_HeapBlock_Lock *lock; + + lock = FindLockObject(reference); - lock = FindLockObject( reference ); - - if(lock == NULL) + if (lock == NULL) { - NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_Lock::CreateInstance( lock, sth->m_owningThread, reference )); + NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_Lock::CreateInstance(lock, sth->m_owningThread, reference)); } - NANOCLR_SET_AND_LEAVE(CLR_RT_HeapBlock_Lock::IncrementOwnership( lock, sth, timeExpire, fForce )); + NANOCLR_SET_AND_LEAVE(CLR_RT_HeapBlock_Lock::IncrementOwnership(lock, sth, timeExpire, fForce)); NANOCLR_NOCLEANUP(); } -HRESULT CLR_RT_ExecutionEngine::UnlockObject( CLR_RT_HeapBlock& reference, CLR_RT_SubThread* sth ) +HRESULT CLR_RT_ExecutionEngine::UnlockObject(CLR_RT_HeapBlock &reference, CLR_RT_SubThread *sth) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - CLR_RT_HeapBlock_Lock* lock; + CLR_RT_HeapBlock_Lock *lock; - lock = FindLockObject( reference ); + lock = FindLockObject(reference); - NANOCLR_SET_AND_LEAVE(CLR_RT_HeapBlock_Lock::DecrementOwnership( lock, sth )); + NANOCLR_SET_AND_LEAVE(CLR_RT_HeapBlock_Lock::DecrementOwnership(lock, sth)); NANOCLR_NOCLEANUP(); } //--// -HRESULT CLR_RT_ExecutionEngine::Sleep( CLR_RT_Thread* caller, const CLR_INT64& timeExpire ) +HRESULT CLR_RT_ExecutionEngine::Sleep(CLR_RT_Thread *caller, const CLR_INT64 &timeExpire) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - - caller->m_waitForEvents_Timeout = timeExpire; CLR_RT_ExecutionEngine::InvalidateTimerCache(); - caller->m_status = CLR_RT_Thread::TH_S_Waiting; + + caller->m_waitForEvents_Timeout = timeExpire; + CLR_RT_ExecutionEngine::InvalidateTimerCache(); + caller->m_status = CLR_RT_Thread::TH_S_Waiting; NANOCLR_SET_AND_LEAVE(CLR_E_THREAD_WAITING); @@ -2626,12 +2728,16 @@ HRESULT CLR_RT_ExecutionEngine::Sleep( CLR_RT_Thread* caller, const CLR_INT64& t //--// -HRESULT CLR_RT_ExecutionEngine::WaitEvents( CLR_RT_Thread* caller, const CLR_INT64& timeExpire, CLR_UINT32 events, bool& fSuccess ) +HRESULT CLR_RT_ExecutionEngine::WaitEvents( + CLR_RT_Thread *caller, + const CLR_INT64 &timeExpire, + CLR_UINT32 events, + bool &fSuccess) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - if(m_raisedEvents & events) + if (m_raisedEvents & events) { m_raisedEvents &= ~events; @@ -2641,11 +2747,12 @@ HRESULT CLR_RT_ExecutionEngine::WaitEvents( CLR_RT_Thread* caller, const CLR_INT { fSuccess = false; - if((CLR_INT64)HAL_Time_CurrentTime() < timeExpire) + if ((CLR_INT64)HAL_Time_CurrentTime() < timeExpire) { - caller->m_waitForEvents = events; - caller->m_waitForEvents_Timeout = timeExpire; CLR_RT_ExecutionEngine::InvalidateTimerCache(); - caller->m_status = CLR_RT_Thread::TH_S_Waiting; + caller->m_waitForEvents = events; + caller->m_waitForEvents_Timeout = timeExpire; + CLR_RT_ExecutionEngine::InvalidateTimerCache(); + caller->m_status = CLR_RT_Thread::TH_S_Waiting; NANOCLR_SET_AND_LEAVE(CLR_E_THREAD_WAITING); } @@ -2654,82 +2761,83 @@ HRESULT CLR_RT_ExecutionEngine::WaitEvents( CLR_RT_Thread* caller, const CLR_INT NANOCLR_NOCLEANUP(); } -void CLR_RT_ExecutionEngine::SignalEvents( CLR_RT_DblLinkedList& threads, CLR_UINT32 events ) +void CLR_RT_ExecutionEngine::SignalEvents(CLR_RT_DblLinkedList &threads, CLR_UINT32 events) { NATIVE_PROFILE_CLR_CORE(); m_raisedEvents |= events; - NANOCLR_FOREACH_NODE(CLR_RT_Thread,th,threads) + NANOCLR_FOREACH_NODE(CLR_RT_Thread, th, threads) { - if((th->m_waitForEvents & events) != 0) + if ((th->m_waitForEvents & events) != 0) { _ASSERTE(&threads == &m_threadsWaiting); _ASSERTE(th->m_status == CLR_RT_Thread::TH_S_Waiting); - th->Restart( true ); + th->Restart(true); } } NANOCLR_FOREACH_NODE_END(); } -void CLR_RT_ExecutionEngine::SignalEvents( CLR_UINT32 events ) +void CLR_RT_ExecutionEngine::SignalEvents(CLR_UINT32 events) { NATIVE_PROFILE_CLR_CORE(); - //Why does the ready queue need to be checked. - SignalEvents( m_threadsReady , events ); - SignalEvents( m_threadsWaiting, events ); + // Why does the ready queue need to be checked. + SignalEvents(m_threadsReady, events); + SignalEvents(m_threadsWaiting, events); } //--// -bool CLR_RT_ExecutionEngine::IsInstanceOf( CLR_RT_TypeDescriptor& desc, CLR_RT_TypeDescriptor& descTarget, bool isInstInstruction ) +bool CLR_RT_ExecutionEngine::IsInstanceOf( + CLR_RT_TypeDescriptor &desc, + CLR_RT_TypeDescriptor &descTarget, + bool isInstInstruction) { NATIVE_PROFILE_CLR_CORE(); - CLR_RT_TypeDef_Instance& inst = desc .m_handlerCls; - CLR_RT_TypeDef_Instance& instTarget = descTarget.m_handlerCls; - bool fArray = false; + CLR_RT_TypeDef_Instance &inst = desc.m_handlerCls; + CLR_RT_TypeDef_Instance &instTarget = descTarget.m_handlerCls; + bool fArray = false; - while(desc .m_reflex.m_levels > 0 && - descTarget.m_reflex.m_levels > 0 ) + while (desc.m_reflex.m_levels > 0 && descTarget.m_reflex.m_levels > 0) { - desc .GetElementType( desc ); - descTarget.GetElementType( descTarget ); + desc.GetElementType(desc); + descTarget.GetElementType(descTarget); fArray = true; } - if(desc.m_reflex.m_levels < descTarget.m_reflex.m_levels) return false; + if (desc.m_reflex.m_levels < descTarget.m_reflex.m_levels) + return false; - if(desc.m_reflex.m_levels > descTarget.m_reflex.m_levels) + if (desc.m_reflex.m_levels > descTarget.m_reflex.m_levels) { - if( - descTarget.m_reflex.m_levels == 0 && - !isInstInstruction) + if (descTarget.m_reflex.m_levels == 0 && !isInstInstruction) { // // Casting from [] to System.Array or System.Object is always allowed. // - if(inst.m_data == g_CLR_RT_WellKnownTypes.m_Array .m_data || - inst.m_data == g_CLR_RT_WellKnownTypes.m_Object .m_data || - inst.m_data == g_CLR_RT_WellKnownTypes.m_IList .m_data || - inst.m_data == g_CLR_RT_WellKnownTypes.m_ICloneable.m_data ) + if (inst.m_data == g_CLR_RT_WellKnownTypes.m_Array.m_data || + inst.m_data == g_CLR_RT_WellKnownTypes.m_Object.m_data || + inst.m_data == g_CLR_RT_WellKnownTypes.m_IList.m_data || + inst.m_data == g_CLR_RT_WellKnownTypes.m_ICloneable.m_data) { return true; } } - if(inst.m_target->dataType != instTarget.m_target->dataType) + if (inst.m_target->dataType != instTarget.m_target->dataType) { return false; } } - CLR_UINT32 semantic = (inst .m_target->flags & CLR_RECORD_TYPEDEF::TD_Semantics_Mask); + CLR_UINT32 semantic = (inst.m_target->flags & CLR_RECORD_TYPEDEF::TD_Semantics_Mask); CLR_UINT32 semanticTarget = (instTarget.m_target->flags & CLR_RECORD_TYPEDEF::TD_Semantics_Mask); - if(fArray) + if (fArray) { - if(semantic != semanticTarget) + if (semantic != semanticTarget) { return false; } @@ -2737,7 +2845,7 @@ bool CLR_RT_ExecutionEngine::IsInstanceOf( CLR_RT_TypeDescriptor& desc, CLR_RT_T do { - if(inst.m_data == instTarget.m_data) + if (inst.m_data == instTarget.m_data) { return true; } @@ -2745,103 +2853,120 @@ bool CLR_RT_ExecutionEngine::IsInstanceOf( CLR_RT_TypeDescriptor& desc, CLR_RT_T // // Scan the list of interfaces. // - if(semanticTarget == CLR_RECORD_TYPEDEF::TD_Semantics_Interface && inst.m_target->interfaces != CLR_EmptyIndex) + if (semanticTarget == CLR_RECORD_TYPEDEF::TD_Semantics_Interface && inst.m_target->interfaces != CLR_EmptyIndex) { - CLR_RT_SignatureParser parser; parser.Initialize_Interfaces( inst.m_assm, inst.m_target ); + CLR_RT_SignatureParser parser; + parser.Initialize_Interfaces(inst.m_assm, inst.m_target); CLR_RT_SignatureParser::Element res; - while(parser.Available() > 0) + while (parser.Available() > 0) { - if(FAILED(parser.Advance( res ))) break; + if (FAILED(parser.Advance(res))) + break; - if(res.m_cls.m_data == instTarget.m_data) + if (res.m_cls.m_data == instTarget.m_data) { return true; } } } - } - while(inst.SwitchToParent()); + } while (inst.SwitchToParent()); return false; } -bool CLR_RT_ExecutionEngine::IsInstanceOf( const CLR_RT_TypeDef_Index& cls, const CLR_RT_TypeDef_Index& clsTarget ) +bool CLR_RT_ExecutionEngine::IsInstanceOf(const CLR_RT_TypeDef_Index &cls, const CLR_RT_TypeDef_Index &clsTarget) { NATIVE_PROFILE_CLR_CORE(); CLR_RT_TypeDescriptor desc; CLR_RT_TypeDescriptor descTarget; - if(FAILED(desc .InitializeFromType( cls ))) return false; - if(FAILED(descTarget.InitializeFromType( clsTarget ))) return false; + if (FAILED(desc.InitializeFromType(cls))) + return false; + if (FAILED(descTarget.InitializeFromType(clsTarget))) + return false; - return IsInstanceOf( desc, descTarget, false ); + return IsInstanceOf(desc, descTarget, false); } -bool CLR_RT_ExecutionEngine::IsInstanceOf( CLR_RT_HeapBlock& ref, const CLR_RT_TypeDef_Index& clsTarget ) +bool CLR_RT_ExecutionEngine::IsInstanceOf(CLR_RT_HeapBlock &ref, const CLR_RT_TypeDef_Index &clsTarget) { NATIVE_PROFILE_CLR_CORE(); CLR_RT_TypeDescriptor desc; CLR_RT_TypeDescriptor descTarget; - if(FAILED(desc .InitializeFromObject( ref ))) return false; - if(FAILED(descTarget.InitializeFromType ( clsTarget ))) return false; + if (FAILED(desc.InitializeFromObject(ref))) + return false; + if (FAILED(descTarget.InitializeFromType(clsTarget))) + return false; - return IsInstanceOf( desc, descTarget, false ); + return IsInstanceOf(desc, descTarget, false); } -bool CLR_RT_ExecutionEngine::IsInstanceOf( CLR_RT_HeapBlock& obj, CLR_RT_Assembly* assm, CLR_UINT32 token, bool isInstInstruction ) +bool CLR_RT_ExecutionEngine::IsInstanceOf( + CLR_RT_HeapBlock &obj, + CLR_RT_Assembly *assm, + CLR_UINT32 token, + bool isInstInstruction) { NATIVE_PROFILE_CLR_CORE(); - CLR_RT_TypeDescriptor desc; - CLR_RT_TypeDescriptor descTarget; - CLR_RT_TypeDef_Instance clsTarget; + CLR_RT_TypeDescriptor desc; + CLR_RT_TypeDescriptor descTarget; + CLR_RT_TypeDef_Instance clsTarget; CLR_RT_TypeSpec_Instance defTarget; - if(FAILED(desc.InitializeFromObject( obj ))) return false; + if (FAILED(desc.InitializeFromObject(obj))) + return false; - if(clsTarget.ResolveToken( token, assm )) + if (clsTarget.ResolveToken(token, assm)) { // // Shortcut for identity. // - if(desc.m_handlerCls.m_data == clsTarget.m_data) return true; + if (desc.m_handlerCls.m_data == clsTarget.m_data) + return true; - if(FAILED(descTarget.InitializeFromType( clsTarget ))) return false; + if (FAILED(descTarget.InitializeFromType(clsTarget))) + return false; } - else if(defTarget.ResolveToken( token, assm )) + else if (defTarget.ResolveToken(token, assm)) { - if(FAILED(descTarget.InitializeFromTypeSpec( defTarget ))) return false; + if (FAILED(descTarget.InitializeFromTypeSpec(defTarget))) + return false; } else { return false; } - return IsInstanceOf( desc, descTarget, isInstInstruction ); + return IsInstanceOf(desc, descTarget, isInstInstruction); } -HRESULT CLR_RT_ExecutionEngine::CastToType( CLR_RT_HeapBlock& ref, CLR_UINT32 tk, CLR_RT_Assembly* assm, bool isInstInstruction ) +HRESULT CLR_RT_ExecutionEngine::CastToType( + CLR_RT_HeapBlock &ref, + CLR_UINT32 tk, + CLR_RT_Assembly *assm, + bool isInstInstruction) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - if(ref.DataType() == DATATYPE_OBJECT && ref.Dereference() == NULL) + if (ref.DataType() == DATATYPE_OBJECT && ref.Dereference() == NULL) { ; } - else if(g_CLR_RT_ExecutionEngine.IsInstanceOf( ref, assm, tk, isInstInstruction ) == true) + else if (g_CLR_RT_ExecutionEngine.IsInstanceOf(ref, assm, tk, isInstInstruction) == true) { ; } else { - if(isInstInstruction == false) + if (isInstInstruction == false) { NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_CAST); } - ref.SetObjectReference( NULL ); + ref.SetObjectReference(NULL); } NANOCLR_NOCLEANUP(); @@ -2849,20 +2974,19 @@ HRESULT CLR_RT_ExecutionEngine::CastToType( CLR_RT_HeapBlock& ref, CLR_UINT32 tk //////////////////////////////////////////////////////////////////////////////////////////////////// - -HRESULT CLR_RT_ExecutionEngine::InitTimeout( CLR_INT64& timeExpire, const CLR_INT64& timeout ) +HRESULT CLR_RT_ExecutionEngine::InitTimeout(CLR_INT64 &timeExpire, const CLR_INT64 &timeout) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - if(timeout < 0) + if (timeout < 0) { // because we are expecting the timeout value to be in ticks // need to check for two possible infinite timeouts: // 1. when coding in native it's supposed to use -1L as a timeout infinite - // 2. in managed code the constant System.Threading.Timeout.Infinite is -1 milliseconds, therefore needs to be converted to ticks - if( (timeout != -1L) && - (timeout != -1L * TIME_CONVERSION__TO_MILLISECONDS)) + // 2. in managed code the constant System.Threading.Timeout.Infinite is -1 milliseconds, therefore needs to be + // converted to ticks + if ((timeout != -1L) && (timeout != -1L * TIME_CONVERSION__TO_MILLISECONDS)) { NANOCLR_SET_AND_LEAVE(CLR_E_OUT_OF_RANGE); } @@ -2877,14 +3001,14 @@ HRESULT CLR_RT_ExecutionEngine::InitTimeout( CLR_INT64& timeExpire, const CLR_IN NANOCLR_NOCLEANUP(); } -HRESULT CLR_RT_ExecutionEngine::InitTimeout( CLR_INT64& timeExpire, CLR_INT32 timeout ) +HRESULT CLR_RT_ExecutionEngine::InitTimeout(CLR_INT64 &timeExpire, CLR_INT32 timeout) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - if(timeout < 0) + if (timeout < 0) { - if(timeout != -1) + if (timeout != -1) { NANOCLR_SET_AND_LEAVE(CLR_E_OUT_OF_RANGE); } @@ -2893,7 +3017,7 @@ HRESULT CLR_RT_ExecutionEngine::InitTimeout( CLR_INT64& timeExpire, CLR_INT32 ti } else { - timeExpire = timeout; + timeExpire = timeout; timeExpire *= TIME_CONVERSION__TO_MILLISECONDS; timeExpire += HAL_Time_CurrentTime(); } @@ -2908,90 +3032,96 @@ void CLR_RT_ExecutionEngine::DebuggerLoop() NATIVE_PROFILE_CLR_CORE(); ProcessHardware(); - WaitSystemEvents(SLEEP_LEVEL__SLEEP, g_CLR_HW_Hardware.m_wakeupEvents, TIME_CONVERSION__TO_MILLISECONDS * 100 ); + WaitSystemEvents(SLEEP_LEVEL__SLEEP, g_CLR_HW_Hardware.m_wakeupEvents, TIME_CONVERSION__TO_MILLISECONDS * 100); } - //--// - //////////////////////////////////////////////////////////////////////////////////////////////////// #if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) -void CLR_RT_ExecutionEngine::SetDebuggingInfoBreakpoints( bool fSet ) +void CLR_RT_ExecutionEngine::SetDebuggingInfoBreakpoints(bool fSet) { NATIVE_PROFILE_CLR_CORE(); - for(size_t pos=0; posm_pid; + bp.m_pid = th->m_pid; th->m_timeQuantumExpired = true; } - if(m_breakpointsActiveNum == 1) + if (m_breakpointsActiveNum == 1) { - CLR_EE_DBG_EVENT_SEND(CLR_DBG_Commands::c_Debugging_Execution_BreakpointHit, sizeof(CLR_DBG_Commands::Debugging_Execution_BreakpointDef), &m_breakpointsActive[0],WP_Flags_c_NonCritical); + CLR_EE_DBG_EVENT_SEND( + CLR_DBG_Commands::c_Debugging_Execution_BreakpointHit, + sizeof(CLR_DBG_Commands::Debugging_Execution_BreakpointDef), + &m_breakpointsActive[0], + WP_Flags_c_NonCritical); } } else @@ -3001,35 +3131,42 @@ void CLR_RT_ExecutionEngine::StopOnBreakpoint( CLR_DBG_Commands::Debugging_Execu } } -void CLR_RT_ExecutionEngine::StopOnBreakpoint( CLR_DBG_Commands::Debugging_Execution_BreakpointDef& def, CLR_RT_StackFrame* stack, CLR_PMETADATA ip ) -{ +void CLR_RT_ExecutionEngine::StopOnBreakpoint( + CLR_DBG_Commands::Debugging_Execution_BreakpointDef &def, + CLR_RT_StackFrame *stack, + CLR_PMETADATA ip) +{ NATIVE_PROFILE_CLR_CORE(); - if(ip == NULL) ip = stack->m_IP; - + if (ip == NULL) + ip = stack->m_IP; + def.m_depth = stack->m_depth; - def.m_md = stack->m_call; - def.m_IP = (CLR_UINT32)(ip - stack->m_IPstart); + def.m_md = stack->m_call; + def.m_IP = (CLR_UINT32)(ip - stack->m_IPstart); - //Don't fail for special cases regarding messages dealing with exception handling. + // Don't fail for special cases regarding messages dealing with exception handling. _ASSERTE(def.m_IP == 0xffffffff || ip >= stack->m_IPstart); - //we don't actually know the end of the method. + // we don't actually know the end of the method. - StopOnBreakpoint( def, stack->m_owningThread ); + StopOnBreakpoint(def, stack->m_owningThread); } -bool CLR_RT_ExecutionEngine::DequeueActiveBreakpoint( CLR_DBG_Commands::Debugging_Execution_BreakpointDef& def ) +bool CLR_RT_ExecutionEngine::DequeueActiveBreakpoint(CLR_DBG_Commands::Debugging_Execution_BreakpointDef &def) { NATIVE_PROFILE_CLR_CORE(); - if(m_breakpointsActiveNum) + if (m_breakpointsActiveNum) { - def = m_breakpointsActive[ 0 ]; + def = m_breakpointsActive[0]; - if(--m_breakpointsActiveNum == 0) + if (--m_breakpointsActiveNum == 0) { def.m_flags |= CLR_DBG_Commands::Debugging_Execution_BreakpointDef::c_LAST_BREAKPOINT; } - memmove( &m_breakpointsActive[ 0 ], &m_breakpointsActive[ 1 ], sizeof(m_breakpointsActive[ 0 ]) * m_breakpointsActiveNum ); + memmove( + &m_breakpointsActive[0], + &m_breakpointsActive[1], + sizeof(m_breakpointsActive[0]) * m_breakpointsActiveNum); return true; } @@ -3039,34 +3176,40 @@ bool CLR_RT_ExecutionEngine::DequeueActiveBreakpoint( CLR_DBG_Commands::Debuggin //--// -void CLR_RT_ExecutionEngine::Breakpoint_System_Event( CLR_DBG_Commands::Debugging_Execution_BreakpointDef& hit, CLR_UINT16 event, CLR_RT_Thread* th, CLR_RT_StackFrame* stack, CLR_PMETADATA ip ) -{ +void CLR_RT_ExecutionEngine::Breakpoint_System_Event( + CLR_DBG_Commands::Debugging_Execution_BreakpointDef &hit, + CLR_UINT16 event, + CLR_RT_Thread *th, + CLR_RT_StackFrame *stack, + CLR_PMETADATA ip) +{ NATIVE_PROFILE_CLR_CORE(); - for(size_t pos=0; posm_owningThread)); th = stack->m_owningThread; } - if(th == NULL || (def.m_pid == th->m_pid) || def.m_pid == CLR_DBG_Commands::Debugging_Execution_BreakpointDef::c_PID_ANY) + if (th == NULL || (def.m_pid == th->m_pid) || + def.m_pid == CLR_DBG_Commands::Debugging_Execution_BreakpointDef::c_PID_ANY) { - if(def.m_flags & event) + if (def.m_flags & event) { - hit.m_id = def.m_id; - hit.m_flags = event; - - if(stack != NULL) + hit.m_id = def.m_id; + hit.m_flags = event; + + if (stack != NULL) { - StopOnBreakpoint( hit, stack, ip ); + StopOnBreakpoint(hit, stack, ip); } else { - StopOnBreakpoint( hit, th ); + StopOnBreakpoint(hit, th); } } } @@ -3076,36 +3219,42 @@ void CLR_RT_ExecutionEngine::Breakpoint_System_Event( CLR_DBG_Commands::Debuggin void CLR_RT_ExecutionEngine::Breakpoint_Assemblies_Loaded() { NATIVE_PROFILE_CLR_CORE(); - CLR_DBG_Commands::Debugging_Execution_BreakpointDef hit; NANOCLR_CLEAR(hit); + CLR_DBG_Commands::Debugging_Execution_BreakpointDef hit; + NANOCLR_CLEAR(hit); - for(size_t i = 0; i < this->m_breakpointsActiveNum; i++) + for (size_t i = 0; i < this->m_breakpointsActiveNum; i++) { - CLR_DBG_Commands::Debugging_Execution_BreakpointDef& def = this->m_breakpointsActive[ i ]; + CLR_DBG_Commands::Debugging_Execution_BreakpointDef &def = this->m_breakpointsActive[i]; - if(def.m_flags & CLR_DBG_Commands::Debugging_Execution_BreakpointDef::c_ASSEMBLIES_LOADED) + if (def.m_flags & CLR_DBG_Commands::Debugging_Execution_BreakpointDef::c_ASSEMBLIES_LOADED) { - //There is already one queued AssembliesLoaded breakpoint. No need to send another one. + // There is already one queued AssembliesLoaded breakpoint. No need to send another one. return; } } - Breakpoint_System_Event( hit, CLR_DBG_Commands::Debugging_Execution_BreakpointDef::c_ASSEMBLIES_LOADED, m_currentThread, NULL, NULL ); + Breakpoint_System_Event( + hit, + CLR_DBG_Commands::Debugging_Execution_BreakpointDef::c_ASSEMBLIES_LOADED, + m_currentThread, + NULL, + NULL); } -void CLR_RT_ExecutionEngine::Breakpoint_Threads_Prepare( CLR_RT_DblLinkedList& threads ) +void CLR_RT_ExecutionEngine::Breakpoint_Threads_Prepare(CLR_RT_DblLinkedList &threads) { NATIVE_PROFILE_CLR_CORE(); - NANOCLR_FOREACH_NODE(CLR_RT_Thread,th,threads) + NANOCLR_FOREACH_NODE(CLR_RT_Thread, th, threads) { th->m_fHasJMCStepper = false; - for(size_t pos=0; posm_pid) + if (def.m_pid == th->m_pid) { th->m_fHasJMCStepper = true; break; @@ -3113,23 +3262,23 @@ void CLR_RT_ExecutionEngine::Breakpoint_Threads_Prepare( CLR_RT_DblLinkedList& t } } - NANOCLR_FOREACH_NODE(CLR_RT_StackFrame,call,th->m_stackFrames) + NANOCLR_FOREACH_NODE(CLR_RT_StackFrame, call, th->m_stackFrames) { call->m_flags &= ~CLR_RT_StackFrame::c_HasBreakpoint; - if(call->m_call.DebuggingInfo().HasBreakpoint()) + if (call->m_call.DebuggingInfo().HasBreakpoint()) { call->m_flags |= CLR_RT_StackFrame::c_HasBreakpoint; } else { - for(size_t pos=0; posm_pid && def.m_depth == call->m_depth) + if (def.m_pid == th->m_pid && def.m_depth == call->m_depth) { call->m_flags |= CLR_RT_StackFrame::c_HasBreakpoint; break; @@ -3138,21 +3287,21 @@ void CLR_RT_ExecutionEngine::Breakpoint_Threads_Prepare( CLR_RT_DblLinkedList& t } } #ifndef CLR_NO_IL_INLINE - if(call->m_inlineFrame) + if (call->m_inlineFrame) { - if(call->m_inlineFrame->m_frame.m_call.DebuggingInfo().HasBreakpoint()) + if (call->m_inlineFrame->m_frame.m_call.DebuggingInfo().HasBreakpoint()) { call->m_flags |= CLR_RT_StackFrame::c_HasBreakpoint; } else { - for(size_t pos=0; posm_pid && def.m_depth == (call->m_depth-1)) + if (def.m_pid == th->m_pid && def.m_depth == (call->m_depth - 1)) { call->m_flags |= CLR_RT_StackFrame::c_HasBreakpoint; break; @@ -3168,65 +3317,68 @@ void CLR_RT_ExecutionEngine::Breakpoint_Threads_Prepare( CLR_RT_DblLinkedList& t NANOCLR_FOREACH_NODE_END(); } -void CLR_RT_ExecutionEngine::Breakpoint_Thread_Terminated( CLR_RT_Thread* th ) +void CLR_RT_ExecutionEngine::Breakpoint_Thread_Terminated(CLR_RT_Thread *th) { NATIVE_PROFILE_CLR_CORE(); - CLR_DBG_Commands::Debugging_Execution_BreakpointDef hit; NANOCLR_CLEAR(hit); + CLR_DBG_Commands::Debugging_Execution_BreakpointDef hit; + NANOCLR_CLEAR(hit); CLR_UINT16 evt = CLR_DBG_Commands::Debugging_Execution_BreakpointDef::c_THREAD_TERMINATED; hit.m_depth = 0xFFFFFFFF; - - if(th->m_scratchPad >= 0) + + if (th->m_scratchPad >= 0) { - evt |= CLR_DBG_Commands::Debugging_Execution_BreakpointDef::c_EVAL_COMPLETE; + evt |= CLR_DBG_Commands::Debugging_Execution_BreakpointDef::c_EVAL_COMPLETE; } - Breakpoint_System_Event( hit, evt, th, NULL, NULL ); + Breakpoint_System_Event(hit, evt, th, NULL, NULL); } -void CLR_RT_ExecutionEngine::Breakpoint_Thread_Created( CLR_RT_Thread* th ) +void CLR_RT_ExecutionEngine::Breakpoint_Thread_Created(CLR_RT_Thread *th) { NATIVE_PROFILE_CLR_CORE(); - CLR_DBG_Commands::Debugging_Execution_BreakpointDef hit; NANOCLR_CLEAR(hit); + CLR_DBG_Commands::Debugging_Execution_BreakpointDef hit; + NANOCLR_CLEAR(hit); - Breakpoint_System_Event( hit, CLR_DBG_Commands::Debugging_Execution_BreakpointDef::c_THREAD_CREATED, th, NULL, NULL ); + Breakpoint_System_Event(hit, CLR_DBG_Commands::Debugging_Execution_BreakpointDef::c_THREAD_CREATED, th, NULL, NULL); } //--// -void CLR_RT_ExecutionEngine::Breakpoint_StackFrame_Push( CLR_RT_StackFrame* stack, CLR_UINT32 reason ) +void CLR_RT_ExecutionEngine::Breakpoint_StackFrame_Push(CLR_RT_StackFrame *stack, CLR_UINT32 reason) { NATIVE_PROFILE_CLR_CORE(); - CLR_RT_Thread* th = stack->m_owningThread; - int pid = th->m_pid; - CLR_UINT32 depthMax = stack->m_depth - 1; - CLR_UINT16 flags = CLR_DBG_Commands::Debugging_Execution_BreakpointDef::c_STEP_IN; - CLR_UINT32 depthMin = depthMax; + CLR_RT_Thread *th = stack->m_owningThread; + int pid = th->m_pid; + CLR_UINT32 depthMax = stack->m_depth - 1; + CLR_UINT16 flags = CLR_DBG_Commands::Debugging_Execution_BreakpointDef::c_STEP_IN; + CLR_UINT32 depthMin = depthMax; - if(stack->m_flags & CLR_RT_StackFrame::c_PseudoStackFrameForFilter) + if (stack->m_flags & CLR_RT_StackFrame::c_PseudoStackFrameForFilter) { - //If a filter frame is being pushed on (assuming the InterceptMask for filters is set), we want to intercept the frame - //in certain special cases. + // If a filter frame is being pushed on (assuming the InterceptMask for filters is set), we want to intercept + // the frame in certain special cases. _ASSERTE(th->m_nestedExceptionsPos); - CLR_RT_Thread::UnwindStack& us = th->m_nestedExceptions[ th->m_nestedExceptionsPos-1 ]; + CLR_RT_Thread::UnwindStack &us = th->m_nestedExceptions[th->m_nestedExceptionsPos - 1]; _ASSERTE(us.m_stack == stack); depthMin = us.m_handlerStack->m_depth; - //If we popped off frames from AppDomain transitions that had steppers, we want to break there as well. + // If we popped off frames from AppDomain transitions that had steppers, we want to break there as well. depthMax = 0xffffffff; - flags |= CLR_DBG_Commands::Debugging_Execution_BreakpointDef::c_STEP_OVER | CLR_DBG_Commands::Debugging_Execution_BreakpointDef::c_STEP_OUT; + flags |= CLR_DBG_Commands::Debugging_Execution_BreakpointDef::c_STEP_OVER | + CLR_DBG_Commands::Debugging_Execution_BreakpointDef::c_STEP_OUT; } - for(size_t pos=0; posm_call.DebuggingInfo().IsJMC(); } @@ -3235,49 +3387,51 @@ void CLR_RT_ExecutionEngine::Breakpoint_StackFrame_Push( CLR_RT_StackFrame* stac fStop = (def.m_depth >= depthMin && def.m_depth <= depthMax); } - if(def.m_depth == depthMin && (def.m_flags & CLR_DBG_Commands::Debugging_Execution_BreakpointDef::c_STEP) == CLR_DBG_Commands::Debugging_Execution_BreakpointDef::c_STEP_OUT) + if (def.m_depth == depthMin && + (def.m_flags & CLR_DBG_Commands::Debugging_Execution_BreakpointDef::c_STEP) == + CLR_DBG_Commands::Debugging_Execution_BreakpointDef::c_STEP_OUT) { - //In the case a user did a step out in a frame, we don't want to break if a filter gets pushed from that frame. However, if there is a step in or over on that frame, - //we should break. + // In the case a user did a step out in a frame, we don't want to break if a filter gets pushed from + // that frame. However, if there is a step in or over on that frame, we should break. fStop = false; } - if(fStop) + if (fStop) { CLR_DBG_Commands::Debugging_Execution_BreakpointDef hit = def; hit.m_flags = CLR_DBG_Commands::Debugging_Execution_BreakpointDef::c_STEP_IN; hit.m_depthExceptionHandler = reason; - StopOnBreakpoint( hit, stack, NULL ); + StopOnBreakpoint(hit, stack, NULL); } } } } - Breakpoint_StackFrame_Hard( stack, stack->m_IP ); + Breakpoint_StackFrame_Hard(stack, stack->m_IP); } -void CLR_RT_ExecutionEngine::Breakpoint_StackFrame_Pop( CLR_RT_StackFrame* stack, bool stepEH ) +void CLR_RT_ExecutionEngine::Breakpoint_StackFrame_Pop(CLR_RT_StackFrame *stack, bool stepEH) { NATIVE_PROFILE_CLR_CORE(); - int pid = stack->m_owningThread->m_pid; - CLR_UINT32 depth = stack->m_depth; - CLR_RT_StackFrame* caller = stack->Caller(); + int pid = stack->m_owningThread->m_pid; + CLR_UINT32 depth = stack->m_depth; + CLR_RT_StackFrame *caller = stack->Caller(); - if(caller->Prev() || stepEH) + if (caller->Prev() || stepEH) { - for(size_t pos=0; posm_call.DebuggingInfo().IsJMC(); } @@ -3286,22 +3440,24 @@ void CLR_RT_ExecutionEngine::Breakpoint_StackFrame_Pop( CLR_RT_StackFrame* stack fStop = (depth <= def.m_depth); } - if(fStop) + if (fStop) { CLR_DBG_Commands::Debugging_Execution_BreakpointDef hit = def; hit.m_flags = CLR_DBG_Commands::Debugging_Execution_BreakpointDef::c_STEP_OUT; - - if(stepEH) + + if (stepEH) { - hit.m_depthExceptionHandler = CLR_DBG_Commands::Debugging_Execution_BreakpointDef::c_DEPTH_STEP_EXCEPTION_HANDLER; + hit.m_depthExceptionHandler = + CLR_DBG_Commands::Debugging_Execution_BreakpointDef::c_DEPTH_STEP_EXCEPTION_HANDLER; } else { - hit.m_depthExceptionHandler = CLR_DBG_Commands::Debugging_Execution_BreakpointDef::c_DEPTH_STEP_RETURN; + hit.m_depthExceptionHandler = + CLR_DBG_Commands::Debugging_Execution_BreakpointDef::c_DEPTH_STEP_RETURN; } - StopOnBreakpoint( hit, (stepEH)? stack : caller, NULL ); + StopOnBreakpoint(hit, (stepEH) ? stack : caller, NULL); } } } @@ -3309,24 +3465,24 @@ void CLR_RT_ExecutionEngine::Breakpoint_StackFrame_Pop( CLR_RT_StackFrame* stack } } -void CLR_RT_ExecutionEngine::Breakpoint_StackFrame_Step( CLR_RT_StackFrame* stack, CLR_PMETADATA ip ) +void CLR_RT_ExecutionEngine::Breakpoint_StackFrame_Step(CLR_RT_StackFrame *stack, CLR_PMETADATA ip) { NATIVE_PROFILE_CLR_CORE(); - int pid = stack->m_owningThread->m_pid; - CLR_UINT32 depth = stack->m_depth; + int pid = stack->m_owningThread->m_pid; + CLR_UINT32 depth = stack->m_depth; CLR_UINT32 IPoffset = (CLR_UINT32)(ip - stack->m_IPstart); - for(size_t pos=0; pos= def.m_IPEnd)) + if (def.m_pid == pid && def.m_depth == depth && (IPoffset < def.m_IPStart || IPoffset >= def.m_IPEnd)) { - if(def.m_flags & CLR_DBG_Commands::Debugging_Execution_BreakpointDef::c_STEP_JMC) + if (def.m_flags & CLR_DBG_Commands::Debugging_Execution_BreakpointDef::c_STEP_JMC) { - if(!stack->m_call.DebuggingInfo().IsJMC()) + if (!stack->m_call.DebuggingInfo().IsJMC()) { continue; } @@ -3336,36 +3492,37 @@ void CLR_RT_ExecutionEngine::Breakpoint_StackFrame_Step( CLR_RT_StackFrame* stac hit.m_flags = CLR_DBG_Commands::Debugging_Execution_BreakpointDef::c_STEP_OVER; - StopOnBreakpoint( hit, stack, ip ); + StopOnBreakpoint(hit, stack, ip); } } } - Breakpoint_StackFrame_Hard( stack, ip ); + Breakpoint_StackFrame_Hard(stack, ip); } -void CLR_RT_ExecutionEngine::Breakpoint_StackFrame_Hard( CLR_RT_StackFrame* stack, CLR_PMETADATA ip ) +void CLR_RT_ExecutionEngine::Breakpoint_StackFrame_Hard(CLR_RT_StackFrame *stack, CLR_PMETADATA ip) { NATIVE_PROFILE_CLR_CORE(); - if(stack->Prev() != NULL && ip != NULL) + if (stack->Prev() != NULL && ip != NULL) { CLR_UINT32 IPoffset = (CLR_UINT32)(ip - stack->m_IPstart); - for(size_t pos=0; posm_owningThread->m_pid || def.m_pid == CLR_DBG_Commands::Debugging_Execution_BreakpointDef::c_PID_ANY) + if (def.m_pid == stack->m_owningThread->m_pid || + def.m_pid == CLR_DBG_Commands::Debugging_Execution_BreakpointDef::c_PID_ANY) { - if(def.m_md.m_data == stack->m_call.m_data && def.m_IP == IPoffset) + if (def.m_md.m_data == stack->m_call.m_data && def.m_IP == IPoffset) { CLR_DBG_Commands::Debugging_Execution_BreakpointDef hit = def; hit.m_flags = CLR_DBG_Commands::Debugging_Execution_BreakpointDef::c_HARD; - StopOnBreakpoint( hit, stack, ip ); + StopOnBreakpoint(hit, stack, ip); } } } @@ -3373,46 +3530,60 @@ void CLR_RT_ExecutionEngine::Breakpoint_StackFrame_Hard( CLR_RT_StackFrame* stac } } -void CLR_RT_ExecutionEngine::Breakpoint_StackFrame_Break( CLR_RT_StackFrame* stack ) +void CLR_RT_ExecutionEngine::Breakpoint_StackFrame_Break(CLR_RT_StackFrame *stack) { NATIVE_PROFILE_CLR_CORE(); - CLR_DBG_Commands::Debugging_Execution_BreakpointDef hit; NANOCLR_CLEAR(hit); - - Breakpoint_System_Event( hit, CLR_DBG_Commands::Debugging_Execution_BreakpointDef::c_BREAK, NULL, stack, NULL ); + CLR_DBG_Commands::Debugging_Execution_BreakpointDef hit; + NANOCLR_CLEAR(hit); + + Breakpoint_System_Event(hit, CLR_DBG_Commands::Debugging_Execution_BreakpointDef::c_BREAK, NULL, stack, NULL); } //--// -void CLR_RT_ExecutionEngine::Breakpoint_Exception( CLR_RT_StackFrame* stack, CLR_UINT32 reason, CLR_PMETADATA ip ) +void CLR_RT_ExecutionEngine::Breakpoint_Exception(CLR_RT_StackFrame *stack, CLR_UINT32 reason, CLR_PMETADATA ip) { NATIVE_PROFILE_CLR_CORE(); - CLR_DBG_Commands::Debugging_Execution_BreakpointDef hit; NANOCLR_CLEAR(hit); + CLR_DBG_Commands::Debugging_Execution_BreakpointDef hit; + NANOCLR_CLEAR(hit); hit.m_depthExceptionHandler = reason; - Breakpoint_System_Event( hit, CLR_DBG_Commands::Debugging_Execution_BreakpointDef::c_EXCEPTION_THROWN, NULL, stack, ip ); + Breakpoint_System_Event( + hit, + CLR_DBG_Commands::Debugging_Execution_BreakpointDef::c_EXCEPTION_THROWN, + NULL, + stack, + ip); } -void CLR_RT_ExecutionEngine::Breakpoint_Exception_Uncaught( CLR_RT_Thread* th ) +void CLR_RT_ExecutionEngine::Breakpoint_Exception_Uncaught(CLR_RT_Thread *th) { NATIVE_PROFILE_CLR_CORE(); - CLR_DBG_Commands::Debugging_Execution_BreakpointDef hit; NANOCLR_CLEAR(hit); + CLR_DBG_Commands::Debugging_Execution_BreakpointDef hit; + NANOCLR_CLEAR(hit); - hit.m_depth = CLR_DBG_Commands::Debugging_Execution_BreakpointDef::c_DEPTH_UNCAUGHT; + hit.m_depth = CLR_DBG_Commands::Debugging_Execution_BreakpointDef::c_DEPTH_UNCAUGHT; hit.m_depthExceptionHandler = CLR_DBG_Commands::Debugging_Execution_BreakpointDef::c_DEPTH_UNCAUGHT; - Breakpoint_System_Event( hit, CLR_DBG_Commands::Debugging_Execution_BreakpointDef::c_EXCEPTION_THROWN, th, NULL, NULL ); + Breakpoint_System_Event( + hit, + CLR_DBG_Commands::Debugging_Execution_BreakpointDef::c_EXCEPTION_THROWN, + th, + NULL, + NULL); } -void CLR_RT_ExecutionEngine::Breakpoint_Exception_Intercepted( CLR_RT_StackFrame* stack ) +void CLR_RT_ExecutionEngine::Breakpoint_Exception_Intercepted(CLR_RT_StackFrame *stack) { NATIVE_PROFILE_CLR_CORE(); - CLR_DBG_Commands::Debugging_Execution_BreakpointDef hit; NANOCLR_CLEAR(hit); - CLR_UINT16 event = CLR_DBG_Commands::Debugging_Execution_BreakpointDef::c_EXCEPTION_CAUGHT - | CLR_DBG_Commands::Debugging_Execution_BreakpointDef::c_EXCEPTION_UNWIND; - + CLR_DBG_Commands::Debugging_Execution_BreakpointDef hit; + NANOCLR_CLEAR(hit); + CLR_UINT16 event = CLR_DBG_Commands::Debugging_Execution_BreakpointDef::c_EXCEPTION_CAUGHT | + CLR_DBG_Commands::Debugging_Execution_BreakpointDef::c_EXCEPTION_UNWIND; + hit.m_depthExceptionHandler = stack->m_depth; - - Breakpoint_System_Event( hit, event, NULL, stack, NULL ); + + Breakpoint_System_Event(hit, event, NULL, stack, NULL); } #endif //#if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) @@ -3421,48 +3592,50 @@ void CLR_RT_ExecutionEngine::Breakpoint_Exception_Intercepted( CLR_RT_StackFrame #if defined(NANOCLR_APPDOMAINS) -CLR_RT_AppDomain* CLR_RT_ExecutionEngine::SetCurrentAppDomain( CLR_RT_AppDomain* appDomain ) -{ +CLR_RT_AppDomain *CLR_RT_ExecutionEngine::SetCurrentAppDomain(CLR_RT_AppDomain *appDomain) +{ NATIVE_PROFILE_CLR_CORE(); - CLR_RT_AppDomain* ad = m_appDomainCurrent; + CLR_RT_AppDomain *ad = m_appDomainCurrent; m_appDomainCurrent = appDomain; return ad; } -CLR_RT_AppDomain* CLR_RT_ExecutionEngine::GetCurrentAppDomain() +CLR_RT_AppDomain *CLR_RT_ExecutionEngine::GetCurrentAppDomain() { NATIVE_PROFILE_CLR_CORE(); return m_appDomainCurrent; } -void CLR_RT_ExecutionEngine::PrepareThreadsForAppDomainUnload( CLR_RT_AppDomain* appDomain, CLR_RT_DblLinkedList& threads) +void CLR_RT_ExecutionEngine::PrepareThreadsForAppDomainUnload( + CLR_RT_AppDomain *appDomain, + CLR_RT_DblLinkedList &threads) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_FOREACH_NODE(CLR_RT_Thread, th, threads) { bool fFoundDoomedAppDomain = false; - bool fInjectThreadAbort = false; + bool fInjectThreadAbort = false; NANOCLR_FOREACH_NODE(CLR_RT_StackFrame, stack, th->m_stackFrames) { - if(!fFoundDoomedAppDomain) + if (!fFoundDoomedAppDomain) { - if(stack->m_appDomain == appDomain) - { - //The first stack frame found in a doomed AppDomain + if (stack->m_appDomain == appDomain) + { + // The first stack frame found in a doomed AppDomain fFoundDoomedAppDomain = true; - fInjectThreadAbort = true; - stack->m_flags |= CLR_RT_StackFrame::c_AppDomainInjectException; - th ->m_flags |= CLR_RT_Thread::TH_F_ContainsDoomedAppDomain; + fInjectThreadAbort = true; + stack->m_flags |= CLR_RT_StackFrame::c_AppDomainInjectException; + th->m_flags |= CLR_RT_Thread::TH_F_ContainsDoomedAppDomain; } } - else //fFoundDoomedAppDomain + else // fFoundDoomedAppDomain { - if(stack->m_flags & CLR_RT_StackFrame::c_AppDomainInjectException) + if (stack->m_flags & CLR_RT_StackFrame::c_AppDomainInjectException) { - //This thread is already being unwound due to an unloading AppDomain + // This thread is already being unwound due to an unloading AppDomain stack->m_flags &= ~CLR_RT_StackFrame::c_AppDomainInjectException; fInjectThreadAbort = false; } @@ -3470,28 +3643,29 @@ void CLR_RT_ExecutionEngine::PrepareThreadsForAppDomainUnload( CLR_RT_AppDomain* } NANOCLR_FOREACH_NODE_END(); - if(fInjectThreadAbort) - { + if (fInjectThreadAbort) + { (void)th->Abort(); } } NANOCLR_FOREACH_NODE_END(); } -HRESULT CLR_RT_ExecutionEngine::UnloadAppDomain( CLR_RT_AppDomain* appDomain, CLR_RT_Thread* th ) +HRESULT CLR_RT_ExecutionEngine::UnloadAppDomain(CLR_RT_AppDomain *appDomain, CLR_RT_Thread *th) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - //Check to make sure the current thread does not contain any doomed AppDomains + // Check to make sure the current thread does not contain any doomed AppDomains NANOCLR_FOREACH_NODE(CLR_RT_StackFrame, stack, th->m_stackFrames) { - if(!stack->m_appDomain->IsLoaded() || stack->m_appDomain == appDomain) NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); + if (!stack->m_appDomain->IsLoaded() || stack->m_appDomain == appDomain) + NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); } NANOCLR_FOREACH_NODE_END(); - PrepareThreadsForAppDomainUnload( appDomain, m_threadsReady ); - PrepareThreadsForAppDomainUnload( appDomain, m_threadsWaiting ); + PrepareThreadsForAppDomainUnload(appDomain, m_threadsReady); + PrepareThreadsForAppDomainUnload(appDomain, m_threadsWaiting); appDomain->m_state = CLR_RT_AppDomain::AppDomainState_Unloading; CLR_EE_SET(UnloadingAppDomain); @@ -3503,30 +3677,30 @@ HRESULT CLR_RT_ExecutionEngine::UnloadAppDomain( CLR_RT_AppDomain* appDomain, CL //////////////////////////////////////////////////////////////////////////////////////////////////// -CLR_UINT32 CLR_RT_ExecutionEngine::WaitSystemEvents( CLR_UINT32 powerLevel, CLR_UINT32 events, CLR_INT64 timeExpire ) +CLR_UINT32 CLR_RT_ExecutionEngine::WaitSystemEvents(CLR_UINT32 powerLevel, CLR_UINT32 events, CLR_INT64 timeExpire) { NATIVE_PROFILE_CLR_CORE(); CLR_INT32 timeout; - + CLR_UINT32 res = 0; m_currentNextActivityTime = timeExpire + HAL_Time_CurrentTime(); timeout = (CLR_INT32)timeExpire / TIME_CONVERSION__TO_MILLISECONDS; - if(timeout == 0) timeout = 1; + if (timeout == 0) + timeout = 1; #if defined(NANOCLR_TRACE_SYSTEMEVENTWAIT) CLR_INT64 start = HAL_Time_CurrentTime(); #endif #if defined(NANOCLR_STRESS_GC) - if(timeout > 100) + if (timeout > 100) { CLR_INT64 startGC = HAL_Time_CurrentTime(); - - g_CLR_RT_ExecutionEngine.PerformHeapCompaction (); + g_CLR_RT_ExecutionEngine.PerformHeapCompaction(); CLR_INT64 endGC = HAL_Time_CurrentTime(); @@ -3539,32 +3713,31 @@ CLR_UINT32 CLR_RT_ExecutionEngine::WaitSystemEvents( CLR_UINT32 powerLevel, CLR_ // TODO check if the watchdog needs to be feed here... don't think so Watchdog_Reset(); - res = ::Events_WaitForEvents( powerLevel, events, timeout ); + res = ::Events_WaitForEvents(powerLevel, events, timeout); // UNDONE: FIXME // ::Watchdog_GetSetEnabled( bool, bool ); // TODO check if the watchdog needs to be feed here... don't think so Watchdog_Reset(); - #if defined(NANOCLR_TRACE_SYSTEMEVENTWAIT) - CLR_INT64 stop = HAL_Time_CurrentTime(); + CLR_INT64 stop = HAL_Time_CurrentTime(); CLR_INT64 stop2 = HAL_Time_CurrentTime(); static CLR_INT64 totalRequested = 0; - static CLR_INT64 totalActual = 0; - static CLR_INT64 samples = 0; + static CLR_INT64 totalActual = 0; + static CLR_INT64 samples = 0; totalRequested += timeout; - totalActual += (stop - start) - (stop2 - stop); - samples += 1; + totalActual += (stop - start) - (stop2 - stop); + samples += 1; - if(samples == 10000) + if (samples == 10000) { - CLR_Debug::Printf( "Wait %lld %lld\r\n", totalRequested / samples, totalActual / samples ); + CLR_Debug::Printf("Wait %lld %lld\r\n", totalRequested / samples, totalActual / samples); totalRequested = 0; - totalActual = 0; - samples = 0; + totalActual = 0; + samples = 0; } #endif @@ -3572,4 +3745,3 @@ CLR_UINT32 CLR_RT_ExecutionEngine::WaitSystemEvents( CLR_UINT32 powerLevel, CLR_ return res; } - diff --git a/src/CLR/Core/GarbageCollector.cpp b/src/CLR/Core/GarbageCollector.cpp index a79979da97..45c25724bd 100644 --- a/src/CLR/Core/GarbageCollector.cpp +++ b/src/CLR/Core/GarbageCollector.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Core/GarbageCollector_Compaction.cpp b/src/CLR/Core/GarbageCollector_Compaction.cpp index 82596063d2..7ecd94549c 100644 --- a/src/CLR/Core/GarbageCollector_Compaction.cpp +++ b/src/CLR/Core/GarbageCollector_Compaction.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Core/GarbageCollector_ComputeReachabilityGraph.cpp b/src/CLR/Core/GarbageCollector_ComputeReachabilityGraph.cpp index 5e8ac82baf..ad76c24d69 100644 --- a/src/CLR/Core/GarbageCollector_ComputeReachabilityGraph.cpp +++ b/src/CLR/Core/GarbageCollector_ComputeReachabilityGraph.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Core/GarbageCollector_Info.cpp b/src/CLR/Core/GarbageCollector_Info.cpp index 741567c757..ad88bb41bd 100644 --- a/src/CLR/Core/GarbageCollector_Info.cpp +++ b/src/CLR/Core/GarbageCollector_Info.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Core/Hardware/Hardware.cpp b/src/CLR/Core/Hardware/Hardware.cpp index 75f670fdf7..efb28a1c4a 100644 --- a/src/CLR/Core/Hardware/Hardware.cpp +++ b/src/CLR/Core/Hardware/Hardware.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // @@ -26,25 +26,27 @@ HRESULT CLR_HW_Hardware::Hardware_Initialize() NANOCLR_HEADER(); - if(m_fInitialized == false) + if (m_fInitialized == false) { Time_Initialize(); - m_interruptData.m_HalQueue.Initialize( (CLR_HW_Hardware::HalInterruptRecord*)&g_scratchInterruptDispatchingStorage, InterruptRecords() ); + m_interruptData.m_HalQueue.Initialize( + (CLR_HW_Hardware::HalInterruptRecord *)&g_scratchInterruptDispatchingStorage, + InterruptRecords()); - m_interruptData.m_applicationQueue.DblLinkedList_Initialize (); + m_interruptData.m_applicationQueue.DblLinkedList_Initialize(); m_interruptData.m_queuedInterrupts = 0; - m_DebuggerEventsMask = 0; + m_DebuggerEventsMask = 0; #if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) - m_DebuggerEventsMask |= ExtractEventFromTransport( HalSystemConfig.DebuggerPort ); + m_DebuggerEventsMask |= ExtractEventFromTransport(HalSystemConfig.DebuggerPort); #endif m_wakeupEvents = c_Default_WakeupEvents | m_DebuggerEventsMask; - m_powerLevel = PowerLevel__Active; - + m_powerLevel = PowerLevel__Active; + m_fInitialized = true; } @@ -68,7 +70,7 @@ void CLR_HW_Hardware::Hardware_Cleanup() { NATIVE_PROFILE_CLR_HARDWARE(); - if(m_fInitialized == true) + if (m_fInitialized == true) { m_fInitialized = false; } @@ -85,96 +87,96 @@ void CLR_HW_Hardware::ProcessActivity() { NATIVE_PROFILE_CLR_HARDWARE(); - for(int i=0; i<10; i++) + for (int i = 0; i < 10; i++) { - if(!HAL_CONTINUATION::Dequeue_And_Execute()) break; + if (!HAL_CONTINUATION::Dequeue_And_Execute()) + break; } - // UNDONE: FIXME: - //if(!msg.IsDebuggerInitialized()) + // UNDONE: FIXME: + // if(!msg.IsDebuggerInitialized()) //{ // msg.InitializeDebugger(); //} - // UNDONE: FIXME:msg.PurgeCache(); - - // UNDONE: FIXME:dbg.PurgeCache(); + // UNDONE: FIXME:msg.PurgeCache(); + + // UNDONE: FIXME:dbg.PurgeCache(); - uint32_t events = ::Events_Get( m_wakeupEvents ); + uint32_t events = ::Events_Get(m_wakeupEvents); uint32_t eventsCLR = 0; - if(events & m_DebuggerEventsMask) + if (events & m_DebuggerEventsMask) { - //dbg.ProcessCommands(); + // dbg.ProcessCommands(); #if defined(PLATFORM_ARM) || defined(PLATFORM_ESP32) - if(CLR_EE_DBG_IS(RebootPending)) + if (CLR_EE_DBG_IS(RebootPending)) { #if !defined(BUILD_RTM) - CLR_Debug::Printf( "Rebooting...\r\n" ); + CLR_Debug::Printf("Rebooting...\r\n"); #endif - if(!CLR_EE_REBOOT_IS(ClrOnly)) + if (!CLR_EE_REBOOT_IS(ClrOnly)) { - CLR_RT_ExecutionEngine::Reboot( false ); + CLR_RT_ExecutionEngine::Reboot(false); } } #endif } - if(events & SYSTEM_EVENT_FLAG_COM_IN) + if (events & SYSTEM_EVENT_FLAG_COM_IN) { - eventsCLR |= CLR_RT_ExecutionEngine::c_Event_SerialPortIn; + eventsCLR |= Event_SerialPortIn; } - if(events & SYSTEM_EVENT_FLAG_COM_OUT) + if (events & SYSTEM_EVENT_FLAG_COM_OUT) { - eventsCLR |= CLR_RT_ExecutionEngine::c_Event_SerialPortOut; + eventsCLR |= Event_SerialPortOut; } - if((events & SYSTEM_EVENT_HW_INTERRUPT) + if ((events & SYSTEM_EVENT_HW_INTERRUPT) #if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) || (!CLR_EE_DBG_IS(Stopped) && !g_CLR_HW_Hardware.m_interruptData.m_applicationQueue.IsEmpty()) #endif //#if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) - ) + ) { ProcessInterrupts(); } - if(events & SYSTEM_EVENT_FLAG_SOCKET) + if (events & SYSTEM_EVENT_FLAG_SOCKET) { - eventsCLR |= CLR_RT_ExecutionEngine::c_Event_Socket; + eventsCLR |= Event_Socket; } - if(events & SYSTEM_EVENT_FLAG_SPI_MASTER) + if (events & SYSTEM_EVENT_FLAG_SPI_MASTER) { - eventsCLR |= CLR_RT_ExecutionEngine::c_Event_SpiMaster; + eventsCLR |= Event_SpiMaster; } - if(events & SYSTEM_EVENT_FLAG_I2C_MASTER) + if (events & SYSTEM_EVENT_FLAG_I2C_MASTER) { - eventsCLR |= CLR_RT_ExecutionEngine::c_Event_I2cMaster; + eventsCLR |= Event_I2cMaster; } - if(events & SYSTEM_EVENT_FLAG_ONEWIRE_MASTER) + if (events & SYSTEM_EVENT_FLAG_ONEWIRE_MASTER) { - eventsCLR |= CLR_RT_ExecutionEngine::c_Event_OneWireMaster; + eventsCLR |= Event_OneWireMaster; } - if(events & SYSTEM_EVENT_FLAG_STORAGE_IO) + if (events & SYSTEM_EVENT_FLAG_STORAGE_IO) { - eventsCLR |= CLR_RT_ExecutionEngine::c_Event_StorageIo; + eventsCLR |= Event_StorageIo; } - if(events & SYSTEM_EVENT_FLAG_RADIO) + if (events & SYSTEM_EVENT_FLAG_RADIO) { - eventsCLR |= CLR_RT_ExecutionEngine::c_Event_Radio; + eventsCLR |= Event_Radio; } - if(eventsCLR) + if (eventsCLR) { - g_CLR_RT_ExecutionEngine.SignalEvents( eventsCLR ); + g_CLR_RT_ExecutionEngine.SignalEvents(eventsCLR); } } //--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--// - diff --git a/src/CLR/Core/Hardware/Hardware_stub.cpp b/src/CLR/Core/Hardware/Hardware_stub.cpp index 3fef9f2967..e4875c17b0 100644 --- a/src/CLR/Core/Hardware/Hardware_stub.cpp +++ b/src/CLR/Core/Hardware/Hardware_stub.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Core/Interpreter.cpp b/src/CLR/Core/Interpreter.cpp index dd7b41d126..f0ee6a9978 100644 --- a/src/CLR/Core/Interpreter.cpp +++ b/src/CLR/Core/Interpreter.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Core/InterruptHandler/InterruptHandler.cpp b/src/CLR/Core/InterruptHandler/InterruptHandler.cpp index feec3befd9..51a58d1b71 100644 --- a/src/CLR/Core/InterruptHandler/InterruptHandler.cpp +++ b/src/CLR/Core/InterruptHandler/InterruptHandler.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Core/InterruptHandler/InterruptHandler_stub.cpp b/src/CLR/Core/InterruptHandler/InterruptHandler_stub.cpp index 83e44e2eef..6576837b52 100644 --- a/src/CLR/Core/InterruptHandler/InterruptHandler_stub.cpp +++ b/src/CLR/Core/InterruptHandler/InterruptHandler_stub.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Core/NativeEventDispatcher/NativeEventDispatcher.cpp b/src/CLR/Core/NativeEventDispatcher/NativeEventDispatcher.cpp index f793fddc0d..bb3dca4e8d 100644 --- a/src/CLR/Core/NativeEventDispatcher/NativeEventDispatcher.cpp +++ b/src/CLR/Core/NativeEventDispatcher/NativeEventDispatcher.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Core/NativeEventDispatcher/NativeEventDispatcher_stub.cpp b/src/CLR/Core/NativeEventDispatcher/NativeEventDispatcher_stub.cpp index 1f73901093..e97b4fe62c 100644 --- a/src/CLR/Core/NativeEventDispatcher/NativeEventDispatcher_stub.cpp +++ b/src/CLR/Core/NativeEventDispatcher/NativeEventDispatcher_stub.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Core/RPC/CLR_RT_HeapBlock_EndPoint.cpp b/src/CLR/Core/RPC/CLR_RT_HeapBlock_EndPoint.cpp index a529b6f86e..caf1abb299 100644 --- a/src/CLR/Core/RPC/CLR_RT_HeapBlock_EndPoint.cpp +++ b/src/CLR/Core/RPC/CLR_RT_HeapBlock_EndPoint.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Core/RPC/RPC_stub.cpp b/src/CLR/Core/RPC/RPC_stub.cpp index e0632f9b6a..dfb95c9e25 100644 --- a/src/CLR/Core/RPC/RPC_stub.cpp +++ b/src/CLR/Core/RPC/RPC_stub.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Core/Random.cpp b/src/CLR/Core/Random.cpp index bb1dd1ec2a..01cf0d20b0 100644 --- a/src/CLR/Core/Random.cpp +++ b/src/CLR/Core/Random.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Core/Serialization/BinaryFormatter.cpp b/src/CLR/Core/Serialization/BinaryFormatter.cpp index 4e52dbed23..e6739610e9 100644 --- a/src/CLR/Core/Serialization/BinaryFormatter.cpp +++ b/src/CLR/Core/Serialization/BinaryFormatter.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Core/Serialization/BinaryFormatter_stub.cpp b/src/CLR/Core/Serialization/BinaryFormatter_stub.cpp index ead85bd48e..50be39ea8a 100644 --- a/src/CLR/Core/Serialization/BinaryFormatter_stub.cpp +++ b/src/CLR/Core/Serialization/BinaryFormatter_stub.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Core/Streams.cpp b/src/CLR/Core/Streams.cpp index 3b38e3b065..8e7533d1c3 100644 --- a/src/CLR/Core/Streams.cpp +++ b/src/CLR/Core/Streams.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Core/StringTable.cpp b/src/CLR/Core/StringTable.cpp index dddd76a4a7..77303e2ed3 100644 --- a/src/CLR/Core/StringTable.cpp +++ b/src/CLR/Core/StringTable.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Core/Thread.cpp b/src/CLR/Core/Thread.cpp index 229ae61814..15cb99c567 100644 --- a/src/CLR/Core/Thread.cpp +++ b/src/CLR/Core/Thread.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Core/TypeSystem.cpp b/src/CLR/Core/TypeSystem.cpp index b1e9ee24fb..41dae842ff 100644 --- a/src/CLR/Core/TypeSystem.cpp +++ b/src/CLR/Core/TypeSystem.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // @@ -10,66 +10,66 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// -#define ITERATE_THROUGH_RECORDS(assm,i,tblName,tblNameUC) \ - const CLR_RECORD_##tblNameUC* src = (const CLR_RECORD_##tblNameUC*)assm->GetTable( TBL_##tblName );\ - CLR_RT_##tblName##_CrossReference* dst = assm->m_pCrossReference_##tblName;\ - for(i=0; im_pTablesSize[TBL_##tblName]; i++, src++, dst++) +#define ITERATE_THROUGH_RECORDS(assm, i, tblName, tblNameUC) \ + const CLR_RECORD_##tblNameUC *src = (const CLR_RECORD_##tblNameUC *)assm->GetTable(TBL_##tblName); \ + CLR_RT_##tblName##_CrossReference *dst = assm->m_pCrossReference_##tblName; \ + for (i = 0; i < assm->m_pTablesSize[TBL_##tblName]; i++, src++, dst++) //////////////////////////////////////////////////////////////////////////////////////////////////// #if defined(_WIN32) -#define NANOCLR_TRACE_DEFAULT(win,arm) (win) +#define NANOCLR_TRACE_DEFAULT(win, arm) (win) #else -#define NANOCLR_TRACE_DEFAULT(win,arm) (arm) +#define NANOCLR_TRACE_DEFAULT(win, arm) (arm) #endif #if defined(NANOCLR_TRACE_ERRORS) -int s_CLR_RT_fTrace_Errors = NANOCLR_TRACE_DEFAULT(c_CLR_RT_Trace_Info,c_CLR_RT_Trace_Info); +int s_CLR_RT_fTrace_Errors = NANOCLR_TRACE_DEFAULT(c_CLR_RT_Trace_Info, c_CLR_RT_Trace_Info); #endif #if defined(NANOCLR_TRACE_EXCEPTIONS) -int s_CLR_RT_fTrace_Exceptions = NANOCLR_TRACE_DEFAULT(c_CLR_RT_Trace_Info,c_CLR_RT_Trace_Info); +int s_CLR_RT_fTrace_Exceptions = NANOCLR_TRACE_DEFAULT(c_CLR_RT_Trace_Info, c_CLR_RT_Trace_Info); #endif #if defined(NANOCLR_TRACE_INSTRUCTIONS) -int s_CLR_RT_fTrace_Instructions = NANOCLR_TRACE_DEFAULT(c_CLR_RT_Trace_None,c_CLR_RT_Trace_None); +int s_CLR_RT_fTrace_Instructions = NANOCLR_TRACE_DEFAULT(c_CLR_RT_Trace_None, c_CLR_RT_Trace_None); #endif #if defined(NANOCLR_GC_VERBOSE) -int s_CLR_RT_fTrace_Memory = NANOCLR_TRACE_DEFAULT(c_CLR_RT_Trace_None,c_CLR_RT_Trace_None); +int s_CLR_RT_fTrace_Memory = NANOCLR_TRACE_DEFAULT(c_CLR_RT_Trace_None, c_CLR_RT_Trace_None); #endif #if defined(NANOCLR_TRACE_MEMORY_STATS) -int s_CLR_RT_fTrace_MemoryStats = NANOCLR_TRACE_DEFAULT(c_CLR_RT_Trace_Info,c_CLR_RT_Trace_Info); +int s_CLR_RT_fTrace_MemoryStats = NANOCLR_TRACE_DEFAULT(c_CLR_RT_Trace_Info, c_CLR_RT_Trace_Info); #endif #if defined(NANOCLR_GC_VERBOSE) -int s_CLR_RT_fTrace_GC = NANOCLR_TRACE_DEFAULT(c_CLR_RT_Trace_None,c_CLR_RT_Trace_None); +int s_CLR_RT_fTrace_GC = NANOCLR_TRACE_DEFAULT(c_CLR_RT_Trace_None, c_CLR_RT_Trace_None); #endif #if defined(WIN32) -int s_CLR_RT_fTrace_SimulateSpeed = NANOCLR_TRACE_DEFAULT(c_CLR_RT_Trace_Info,c_CLR_RT_Trace_None); +int s_CLR_RT_fTrace_SimulateSpeed = NANOCLR_TRACE_DEFAULT(c_CLR_RT_Trace_Info, c_CLR_RT_Trace_None); #endif #if !defined(BUILD_RTM) -int s_CLR_RT_fTrace_AssemblyOverhead = NANOCLR_TRACE_DEFAULT(c_CLR_RT_Trace_Info,c_CLR_RT_Trace_Info); +int s_CLR_RT_fTrace_AssemblyOverhead = NANOCLR_TRACE_DEFAULT(c_CLR_RT_Trace_Info, c_CLR_RT_Trace_Info); #endif #if defined(WIN32) -int s_CLR_RT_fTrace_StopOnFAILED = NANOCLR_TRACE_DEFAULT(c_CLR_RT_Trace_None,c_CLR_RT_Trace_None); +int s_CLR_RT_fTrace_StopOnFAILED = NANOCLR_TRACE_DEFAULT(c_CLR_RT_Trace_None, c_CLR_RT_Trace_None); #endif #if defined(WIN32) -int s_CLR_RT_fTrace_ARM_Execution = 0; +int s_CLR_RT_fTrace_ARM_Execution = 0; -int s_CLR_RT_fTrace_RedirectLinesPerFile; +int s_CLR_RT_fTrace_RedirectLinesPerFile; std::wstring s_CLR_RT_fTrace_RedirectOutput; std::wstring s_CLR_RT_fTrace_RedirectCallChain; std::wstring s_CLR_RT_fTrace_HeapDump_FilePrefix; -bool s_CLR_RT_fTrace_HeapDump_IncludeCreators = false; +bool s_CLR_RT_fTrace_HeapDump_IncludeCreators = false; -bool s_CLR_RT_fTimeWarp = false; +bool s_CLR_RT_fTimeWarp = false; #endif //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -77,39 +77,41 @@ bool s_CLR_RT_fTimeWarp = false; void CLR_RT_ReflectionDef_Index::Clear() { NATIVE_PROFILE_CLR_CORE(); - m_kind = REFLECTION_INVALID; - m_levels = 0; + m_kind = REFLECTION_INVALID; + m_levels = 0; m_data.m_raw = 0; } CLR_UINT32 CLR_RT_ReflectionDef_Index::GetTypeHash() const { NATIVE_PROFILE_CLR_CORE(); - switch(m_kind) + switch (m_kind) { - case REFLECTION_TYPE: + case REFLECTION_TYPE: { CLR_RT_TypeDef_Instance inst; - if(m_levels != 0) return 0; + if (m_levels != 0) + return 0; - if(!inst.InitializeFromIndex( m_data.m_type )) return 0; + if (!inst.InitializeFromIndex(m_data.m_type)) + return 0; return inst.CrossReference().m_hash; } - case REFLECTION_TYPE_DELAYED: - return m_data.m_raw; + case REFLECTION_TYPE_DELAYED: + return m_data.m_raw; } return 0; } -void CLR_RT_ReflectionDef_Index::InitializeFromHash( CLR_UINT32 hash ) +void CLR_RT_ReflectionDef_Index::InitializeFromHash(CLR_UINT32 hash) { NATIVE_PROFILE_CLR_CORE(); - m_kind = REFLECTION_TYPE_DELAYED; - m_levels = 0; + m_kind = REFLECTION_TYPE_DELAYED; + m_levels = 0; m_data.m_raw = hash; } @@ -119,72 +121,73 @@ CLR_UINT64 CLR_RT_ReflectionDef_Index::GetRawData() const CLR_UINT64 data; _ASSERTE(sizeof(data) == sizeof(*this)); - memcpy( &data, this, sizeof(data) ); + memcpy(&data, this, sizeof(data)); return data; } -void CLR_RT_ReflectionDef_Index::SetRawData( CLR_UINT64 data ) +void CLR_RT_ReflectionDef_Index::SetRawData(CLR_UINT64 data) { NATIVE_PROFILE_CLR_CORE(); _ASSERTE(sizeof(data) == sizeof(*this)); - memcpy( this, &data, sizeof(data) ); + memcpy(this, &data, sizeof(data)); } -bool CLR_RT_ReflectionDef_Index::Convert( CLR_RT_HeapBlock& ref, CLR_RT_Assembly_Instance& inst ) +bool CLR_RT_ReflectionDef_Index::Convert(CLR_RT_HeapBlock &ref, CLR_RT_Assembly_Instance &inst) { NATIVE_PROFILE_CLR_CORE(); - if(ref.DataType() == DATATYPE_REFLECTION) + if (ref.DataType() == DATATYPE_REFLECTION) { - return inst.InitializeFromIndex( ref.ReflectionDataConst().m_data.m_assm ); + return inst.InitializeFromIndex(ref.ReflectionDataConst().m_data.m_assm); } return false; } -bool CLR_RT_ReflectionDef_Index::Convert( CLR_RT_HeapBlock& ref, CLR_RT_TypeDef_Instance& inst, CLR_UINT32* levels ) +bool CLR_RT_ReflectionDef_Index::Convert(CLR_RT_HeapBlock &ref, CLR_RT_TypeDef_Instance &inst, CLR_UINT32 *levels) { NATIVE_PROFILE_CLR_CORE(); - if(ref.DataType() == DATATYPE_REFLECTION) + if (ref.DataType() == DATATYPE_REFLECTION) { - return inst.InitializeFromReflection( ref.ReflectionDataConst(), levels ); + return inst.InitializeFromReflection(ref.ReflectionDataConst(), levels); } return false; } -bool CLR_RT_ReflectionDef_Index::Convert( CLR_RT_HeapBlock& ref, CLR_RT_MethodDef_Instance& inst ) +bool CLR_RT_ReflectionDef_Index::Convert(CLR_RT_HeapBlock &ref, CLR_RT_MethodDef_Instance &inst) { NATIVE_PROFILE_CLR_CORE(); - if(ref.DataType() == DATATYPE_REFLECTION) + if (ref.DataType() == DATATYPE_REFLECTION) { - switch(ref.ReflectionData().m_kind) + switch (ref.ReflectionData().m_kind) { - case REFLECTION_CONSTRUCTOR: - case REFLECTION_METHOD: - return inst.InitializeFromIndex( ref.ReflectionDataConst().m_data.m_method ); + case REFLECTION_CONSTRUCTOR: + case REFLECTION_METHOD: + return inst.InitializeFromIndex(ref.ReflectionDataConst().m_data.m_method); } } return false; } -bool CLR_RT_ReflectionDef_Index::Convert( CLR_RT_HeapBlock& ref, CLR_RT_FieldDef_Instance& inst ) +bool CLR_RT_ReflectionDef_Index::Convert(CLR_RT_HeapBlock &ref, CLR_RT_FieldDef_Instance &inst) { NATIVE_PROFILE_CLR_CORE(); - if(ref.DataType() == DATATYPE_REFLECTION && ref.ReflectionData().m_kind == REFLECTION_FIELD) + if (ref.DataType() == DATATYPE_REFLECTION && ref.ReflectionData().m_kind == REFLECTION_FIELD) { - return inst.InitializeFromIndex( ref.ReflectionDataConst().m_data.m_field ); + return inst.InitializeFromIndex(ref.ReflectionDataConst().m_data.m_field); } return false; } -bool CLR_RT_ReflectionDef_Index::Convert( CLR_RT_HeapBlock& ref, CLR_UINT32& hash ) +bool CLR_RT_ReflectionDef_Index::Convert(CLR_RT_HeapBlock &ref, CLR_UINT32 &hash) { NATIVE_PROFILE_CLR_CORE(); - if(ref.DataType() != DATATYPE_REFLECTION) return false; + if (ref.DataType() != DATATYPE_REFLECTION) + return false; hash = ref.ReflectionData().GetTypeHash(); @@ -193,88 +196,88 @@ bool CLR_RT_ReflectionDef_Index::Convert( CLR_RT_HeapBlock& ref, CLR_UINT32& has //////////////////////////////////////////////////////////////////////////////////////////////////// -void CLR_RT_SignatureParser::Initialize_TypeSpec( CLR_RT_Assembly* assm, const CLR_RECORD_TYPESPEC* ts ) +void CLR_RT_SignatureParser::Initialize_TypeSpec(CLR_RT_Assembly *assm, const CLR_RECORD_TYPESPEC *ts) { NATIVE_PROFILE_CLR_CORE(); - Initialize_TypeSpec( assm, assm->GetSignature( ts->sig ) ); + Initialize_TypeSpec(assm, assm->GetSignature(ts->sig)); } -void CLR_RT_SignatureParser::Initialize_TypeSpec( CLR_RT_Assembly* assm, CLR_PMETADATA ts ) +void CLR_RT_SignatureParser::Initialize_TypeSpec(CLR_RT_Assembly *assm, CLR_PMETADATA ts) { NATIVE_PROFILE_CLR_CORE(); - m_assm = assm; - m_sig = ts; + m_assm = assm; + m_sig = ts; - m_type = CLR_RT_SignatureParser::c_TypeSpec; + m_type = CLR_RT_SignatureParser::c_TypeSpec; m_flags = 0; m_count = 1; } //--// -void CLR_RT_SignatureParser::Initialize_Interfaces( CLR_RT_Assembly* assm, const CLR_RECORD_TYPEDEF* td ) +void CLR_RT_SignatureParser::Initialize_Interfaces(CLR_RT_Assembly *assm, const CLR_RECORD_TYPEDEF *td) { NATIVE_PROFILE_CLR_CORE(); - if(td->interfaces != CLR_EmptyIndex) + if (td->interfaces != CLR_EmptyIndex) { - CLR_PMETADATA sig = assm->GetSignature( td->interfaces ); + CLR_PMETADATA sig = assm->GetSignature(td->interfaces); m_count = (*sig++); - m_sig = sig; + m_sig = sig; } else { m_count = 0; - m_sig = NULL; + m_sig = NULL; } - m_type = CLR_RT_SignatureParser::c_Interfaces; + m_type = CLR_RT_SignatureParser::c_Interfaces; m_flags = 0; - m_assm = assm; + m_assm = assm; } //--// -void CLR_RT_SignatureParser::Initialize_FieldDef( CLR_RT_Assembly* assm, const CLR_RECORD_FIELDDEF* fd ) +void CLR_RT_SignatureParser::Initialize_FieldDef(CLR_RT_Assembly *assm, const CLR_RECORD_FIELDDEF *fd) { NATIVE_PROFILE_CLR_CORE(); - Initialize_FieldDef( assm, assm->GetSignature( fd->sig ) ); + Initialize_FieldDef(assm, assm->GetSignature(fd->sig)); } -void CLR_RT_SignatureParser::Initialize_FieldDef( CLR_RT_Assembly* assm, CLR_PMETADATA fd ) +void CLR_RT_SignatureParser::Initialize_FieldDef(CLR_RT_Assembly *assm, CLR_PMETADATA fd) { NATIVE_PROFILE_CLR_CORE(); - m_type = CLR_RT_SignatureParser::c_Field; + m_type = CLR_RT_SignatureParser::c_Field; m_flags = (*fd++); m_count = 1; - m_assm = assm; - m_sig = fd; + m_assm = assm; + m_sig = fd; } //--// -void CLR_RT_SignatureParser::Initialize_MethodSignature( CLR_RT_Assembly* assm, const CLR_RECORD_METHODDEF* md ) +void CLR_RT_SignatureParser::Initialize_MethodSignature(CLR_RT_Assembly *assm, const CLR_RECORD_METHODDEF *md) { NATIVE_PROFILE_CLR_CORE(); - Initialize_MethodSignature( assm, assm->GetSignature( md->sig ) ); + Initialize_MethodSignature(assm, assm->GetSignature(md->sig)); } -void CLR_RT_SignatureParser::Initialize_MethodSignature( CLR_RT_Assembly* assm, CLR_PMETADATA md ) +void CLR_RT_SignatureParser::Initialize_MethodSignature(CLR_RT_Assembly *assm, CLR_PMETADATA md) { NATIVE_PROFILE_CLR_CORE(); - m_type = CLR_RT_SignatureParser::c_Method; + m_type = CLR_RT_SignatureParser::c_Method; m_flags = (*md++); m_count = (*md++) + 1; - m_assm = assm; - m_sig = md; + m_assm = assm; + m_sig = md; } //--// -void CLR_RT_SignatureParser::Initialize_MethodLocals( CLR_RT_Assembly* assm, const CLR_RECORD_METHODDEF* md ) +void CLR_RT_SignatureParser::Initialize_MethodLocals(CLR_RT_Assembly *assm, const CLR_RECORD_METHODDEF *md) { NATIVE_PROFILE_CLR_CORE(); // @@ -283,29 +286,29 @@ void CLR_RT_SignatureParser::Initialize_MethodLocals( CLR_RT_Assembly* assm, con // If you change this method, change "CLR_RT_ExecutionEngine::InitializeLocals" too. // - m_assm = assm; - m_sig = assm->GetSignature( md->locals ); + m_assm = assm; + m_sig = assm->GetSignature(md->locals); - m_type = CLR_RT_SignatureParser::c_Locals; + m_type = CLR_RT_SignatureParser::c_Locals; m_flags = 0; m_count = md->numLocals; } //--// -void CLR_RT_SignatureParser::Initialize_Objects( CLR_RT_HeapBlock* lst, int count, bool fTypes ) +void CLR_RT_SignatureParser::Initialize_Objects(CLR_RT_HeapBlock *lst, int count, bool fTypes) { NATIVE_PROFILE_CLR_CORE(); m_lst = lst; - m_type = CLR_RT_SignatureParser::c_Object; + m_type = CLR_RT_SignatureParser::c_Object; m_flags = fTypes ? 1 : 0; m_count = count; } //--// -HRESULT CLR_RT_SignatureParser::Advance( Element& res ) +HRESULT CLR_RT_SignatureParser::Advance(Element &res) { NATIVE_PROFILE_CLR_CORE(); // @@ -323,15 +326,15 @@ HRESULT CLR_RT_SignatureParser::Advance( Element& res ) res.m_fByRef = false; res.m_levels = 0; - switch(m_type) + switch (m_type) { - case c_Interfaces: + case c_Interfaces: { CLR_RT_TypeDef_Instance cls; res.m_dt = DATATYPE_CLASS; - if(cls.ResolveToken( CLR_TkFromStream( m_sig ), m_assm ) == false) + if (cls.ResolveToken(CLR_TkFromStream(m_sig), m_assm) == false) { NANOCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE); } @@ -340,28 +343,28 @@ HRESULT CLR_RT_SignatureParser::Advance( Element& res ) } break; - case c_Object: + case c_Object: { CLR_RT_TypeDescriptor desc; - CLR_RT_HeapBlock* ptr = m_lst++; + CLR_RT_HeapBlock *ptr = m_lst++; - if(m_flags) + if (m_flags) { // Reflection types are now boxed, so unbox first - if(ptr->DataType() == DATATYPE_OBJECT) + if (ptr->DataType() == DATATYPE_OBJECT) { ptr = ptr->Dereference(); } - if(ptr->DataType() != DATATYPE_REFLECTION) + if (ptr->DataType() != DATATYPE_REFLECTION) { NANOCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE); } - NANOCLR_CHECK_HRESULT(desc.InitializeFromReflection( ptr->ReflectionDataConst() )); + NANOCLR_CHECK_HRESULT(desc.InitializeFromReflection(ptr->ReflectionDataConst())); } else { - switch(ptr->DataType()) + switch (ptr->DataType()) { case DATATYPE_BYREF: case DATATYPE_ARRAY_BYREF: @@ -373,101 +376,102 @@ HRESULT CLR_RT_SignatureParser::Advance( Element& res ) break; } - NANOCLR_CHECK_HRESULT(desc.InitializeFromObject( *ptr )); + NANOCLR_CHECK_HRESULT(desc.InitializeFromObject(*ptr)); } - desc.m_handlerCls.InitializeFromIndex( desc.m_reflex.m_data.m_type ); + desc.m_handlerCls.InitializeFromIndex(desc.m_reflex.m_data.m_type); - res.m_levels = desc.m_reflex.m_levels; - res.m_dt = (CLR_DataType)desc.m_handlerCls.m_target->dataType; - res.m_cls = desc.m_reflex.m_data.m_type; + res.m_levels = desc.m_reflex.m_levels; + res.m_dt = (CLR_DataType)desc.m_handlerCls.m_target->dataType; + res.m_cls = desc.m_reflex.m_data.m_type; // // Special case for Object types. // - if(res.m_cls.m_data == g_CLR_RT_WellKnownTypes.m_Object.m_data) + if (res.m_cls.m_data == g_CLR_RT_WellKnownTypes.m_Object.m_data) { res.m_dt = DATATYPE_OBJECT; } } break; - default: - while(true) - { - res.m_dt = CLR_UncompressElementType( m_sig ); - - switch(res.m_dt) + default: + while (true) { - case DATATYPE_BYREF: - if(res.m_fByRef) - { - NANOCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE); - } + res.m_dt = CLR_UncompressElementType(m_sig); - res.m_fByRef = true; - break; - - case DATATYPE_SZARRAY: - res.m_levels++; - break; - - case DATATYPE_CLASS : - case DATATYPE_VALUETYPE: + switch (res.m_dt) { - CLR_UINT32 tk = CLR_TkFromStream( m_sig ); + case DATATYPE_BYREF: + if (res.m_fByRef) + { + NANOCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE); + } - if(CLR_TypeFromTk( tk ) == TBL_TypeSpec) - { - CLR_RT_SignatureParser sub; sub.Initialize_TypeSpec( m_assm, m_assm->GetTypeSpec( CLR_DataFromTk( tk ) ) ); - int extraLevels = res.m_levels; + res.m_fByRef = true; + break; - NANOCLR_CHECK_HRESULT(sub.Advance( res )); + case DATATYPE_SZARRAY: + res.m_levels++; + break; - res.m_levels += extraLevels; - } - else + case DATATYPE_CLASS: + case DATATYPE_VALUETYPE: { - CLR_RT_TypeDef_Instance cls; + CLR_UINT32 tk = CLR_TkFromStream(m_sig); - if(cls.ResolveToken( tk, m_assm ) == false) + if (CLR_TypeFromTk(tk) == TBL_TypeSpec) { - NANOCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE); - } + CLR_RT_SignatureParser sub; + sub.Initialize_TypeSpec(m_assm, m_assm->GetTypeSpec(CLR_DataFromTk(tk))); + int extraLevels = res.m_levels; - res.m_cls = cls; - } + NANOCLR_CHECK_HRESULT(sub.Advance(res)); - NANOCLR_SET_AND_LEAVE(S_OK); - } + res.m_levels += extraLevels; + } + else + { + CLR_RT_TypeDef_Instance cls; - case DATATYPE_OBJECT: - res.m_cls = g_CLR_RT_WellKnownTypes.m_Object; + if (cls.ResolveToken(tk, m_assm) == false) + { + NANOCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE); + } - NANOCLR_SET_AND_LEAVE(S_OK); + res.m_cls = cls; + } - case DATATYPE_VOID: - res.m_cls = g_CLR_RT_WellKnownTypes.m_Void; + NANOCLR_SET_AND_LEAVE(S_OK); + } - NANOCLR_SET_AND_LEAVE(S_OK); + case DATATYPE_OBJECT: + res.m_cls = g_CLR_RT_WellKnownTypes.m_Object; - default: - { - const CLR_RT_TypeDef_Index* cls = c_CLR_RT_DataTypeLookup[ res.m_dt ].m_cls; + NANOCLR_SET_AND_LEAVE(S_OK); + + case DATATYPE_VOID: + res.m_cls = g_CLR_RT_WellKnownTypes.m_Void; - if(cls) - { - res.m_cls = *cls; NANOCLR_SET_AND_LEAVE(S_OK); - } - else + + default: { - NANOCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE); + const CLR_RT_TypeDef_Index *cls = c_CLR_RT_DataTypeLookup[res.m_dt].m_cls; + + if (cls) + { + res.m_cls = *cls; + NANOCLR_SET_AND_LEAVE(S_OK); + } + else + { + NANOCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE); + } } } } - } - break; + break; } NANOCLR_NOCLEANUP(); @@ -475,13 +479,13 @@ HRESULT CLR_RT_SignatureParser::Advance( Element& res ) //////////////////////////////////////////////////////////////////////////////////////////////////// -bool CLR_RT_Assembly_Instance::InitializeFromIndex( const CLR_RT_Assembly_Index& idx ) +bool CLR_RT_Assembly_Instance::InitializeFromIndex(const CLR_RT_Assembly_Index &idx) { NATIVE_PROFILE_CLR_CORE(); - if(NANOCLR_INDEX_IS_VALID(idx)) + if (NANOCLR_INDEX_IS_VALID(idx)) { m_data = idx.m_data; - m_assm = g_CLR_RT_TypeSystem.m_assemblies[ Assembly()-1 ]; + m_assm = g_CLR_RT_TypeSystem.m_assemblies[Assembly() - 1]; return true; } @@ -502,20 +506,20 @@ void CLR_RT_Assembly_Instance::Clear() ////////////////////////////// -bool CLR_RT_TypeSpec_Instance::InitializeFromIndex( const CLR_RT_TypeSpec_Index& idx ) +bool CLR_RT_TypeSpec_Instance::InitializeFromIndex(const CLR_RT_TypeSpec_Index &idx) { NATIVE_PROFILE_CLR_CORE(); - if(NANOCLR_INDEX_IS_VALID(idx)) + if (NANOCLR_INDEX_IS_VALID(idx)) { - m_data = idx.m_data; - m_assm = g_CLR_RT_TypeSystem.m_assemblies[ Assembly()-1 ] ; - m_target = m_assm->GetSignature( m_assm->GetTypeSpec ( TypeSpec() )->sig ); + m_data = idx.m_data; + m_assm = g_CLR_RT_TypeSystem.m_assemblies[Assembly() - 1]; + m_target = m_assm->GetSignature(m_assm->GetTypeSpec(TypeSpec())->sig); return true; } - m_data = 0; - m_assm = NULL; + m_data = 0; + m_assm = NULL; m_target = NULL; return false; @@ -526,21 +530,21 @@ void CLR_RT_TypeSpec_Instance::Clear() NATIVE_PROFILE_CLR_CORE(); CLR_RT_TypeSpec_Index::Clear(); - m_assm = NULL; + m_assm = NULL; m_target = NULL; } -bool CLR_RT_TypeSpec_Instance::ResolveToken( CLR_UINT32 tk, CLR_RT_Assembly* assm ) +bool CLR_RT_TypeSpec_Instance::ResolveToken(CLR_UINT32 tk, CLR_RT_Assembly *assm) { NATIVE_PROFILE_CLR_CORE(); - if(assm && CLR_TypeFromTk( tk ) == TBL_TypeSpec) + if (assm && CLR_TypeFromTk(tk) == TBL_TypeSpec) { - CLR_UINT32 idx = CLR_DataFromTk( tk ); + CLR_UINT32 idx = CLR_DataFromTk(tk); - Set( assm->m_idx, idx ); + Set(assm->m_idx, idx); - m_assm = assm; - m_target = assm->GetSignature( assm->GetTypeSpec( idx )->sig ); + m_assm = assm; + m_target = assm->GetSignature(assm->GetTypeSpec(idx)->sig); return true; } @@ -552,69 +556,70 @@ bool CLR_RT_TypeSpec_Instance::ResolveToken( CLR_UINT32 tk, CLR_RT_Assembly* ass ////////////////////////////// -bool CLR_RT_TypeDef_Instance::InitializeFromReflection( const CLR_RT_ReflectionDef_Index& reflex, CLR_UINT32* levels ) +bool CLR_RT_TypeDef_Instance::InitializeFromReflection(const CLR_RT_ReflectionDef_Index &reflex, CLR_UINT32 *levels) { NATIVE_PROFILE_CLR_CORE(); - CLR_RT_TypeDef_Index cls; - const CLR_RT_TypeDef_Index* ptr = NULL; + CLR_RT_TypeDef_Index cls; + const CLR_RT_TypeDef_Index *ptr = NULL; - if(levels) *levels = reflex.m_levels; + if (levels) + *levels = reflex.m_levels; - switch(reflex.m_kind) + switch (reflex.m_kind) { - case REFLECTION_TYPE: - if(reflex.m_levels > 0 && levels == NULL) - { - ptr = &g_CLR_RT_WellKnownTypes.m_Array; - } - else - { - ptr = &reflex.m_data.m_type; - } - break; + case REFLECTION_TYPE: + if (reflex.m_levels > 0 && levels == NULL) + { + ptr = &g_CLR_RT_WellKnownTypes.m_Array; + } + else + { + ptr = &reflex.m_data.m_type; + } + break; - case REFLECTION_TYPE_DELAYED: - if(g_CLR_RT_TypeSystem.FindTypeDef( reflex.m_data.m_raw, cls )) - { - ptr = &cls; - } - break; + case REFLECTION_TYPE_DELAYED: + if (g_CLR_RT_TypeSystem.FindTypeDef(reflex.m_data.m_raw, cls)) + { + ptr = &cls; + } + break; } - return ptr ? InitializeFromIndex( *ptr ) : false; + return ptr ? InitializeFromIndex(*ptr) : false; } -bool CLR_RT_TypeDef_Instance::InitializeFromIndex( const CLR_RT_TypeDef_Index& idx ) +bool CLR_RT_TypeDef_Instance::InitializeFromIndex(const CLR_RT_TypeDef_Index &idx) { NATIVE_PROFILE_CLR_CORE(); - if(NANOCLR_INDEX_IS_VALID(idx)) + if (NANOCLR_INDEX_IS_VALID(idx)) { - m_data = idx.m_data; - m_assm = g_CLR_RT_TypeSystem.m_assemblies[ Assembly()-1 ]; - m_target = m_assm->GetTypeDef ( Type () ); + m_data = idx.m_data; + m_assm = g_CLR_RT_TypeSystem.m_assemblies[Assembly() - 1]; + m_target = m_assm->GetTypeDef(Type()); return true; } - m_data = 0; - m_assm = NULL; + m_data = 0; + m_assm = NULL; m_target = NULL; return false; } -bool CLR_RT_TypeDef_Instance::InitializeFromMethod( const CLR_RT_MethodDef_Instance& md ) +bool CLR_RT_TypeDef_Instance::InitializeFromMethod(const CLR_RT_MethodDef_Instance &md) { NATIVE_PROFILE_CLR_CORE(); - if(NANOCLR_INDEX_IS_VALID(md)) + if (NANOCLR_INDEX_IS_VALID(md)) { CLR_IDX idxAssm = md.Assembly(); CLR_IDX idxType = md.CrossReference().GetOwner(); - Set( idxAssm, idxType ); + Set(idxAssm, idxType); - m_assm = g_CLR_RT_TypeSystem.m_assemblies[ idxAssm-1 ]; - m_target = m_assm->GetTypeDef ( idxType ); + m_assm = g_CLR_RT_TypeSystem.m_assemblies[idxAssm - 1]; + m_target = m_assm->GetTypeDef(idxType); return true; } @@ -624,21 +629,21 @@ bool CLR_RT_TypeDef_Instance::InitializeFromMethod( const CLR_RT_MethodDef_Insta return false; } -bool CLR_RT_TypeDef_Instance::InitializeFromField( const CLR_RT_FieldDef_Instance& fd ) +bool CLR_RT_TypeDef_Instance::InitializeFromField(const CLR_RT_FieldDef_Instance &fd) { NATIVE_PROFILE_CLR_CORE(); - if(NANOCLR_INDEX_IS_VALID(fd)) + if (NANOCLR_INDEX_IS_VALID(fd)) { - CLR_RT_Assembly* assm = fd.m_assm; - const CLR_RECORD_TYPEDEF* td = (const CLR_RECORD_TYPEDEF*)assm->GetTable( TBL_TypeDef ); - CLR_IDX idxField = fd.Field(); - int i = assm->m_pTablesSize[ TBL_TypeDef ]; + CLR_RT_Assembly *assm = fd.m_assm; + const CLR_RECORD_TYPEDEF *td = (const CLR_RECORD_TYPEDEF *)assm->GetTable(TBL_TypeDef); + CLR_IDX idxField = fd.Field(); + int i = assm->m_pTablesSize[TBL_TypeDef]; - if(fd.m_target->flags & CLR_RECORD_FIELDDEF::FD_Static) + if (fd.m_target->flags & CLR_RECORD_FIELDDEF::FD_Static) { - for(;i; i--, td++) + for (; i; i--, td++) { - if(td->sFields_First <= idxField && idxField < td->sFields_First + td->sFields_Num) + if (td->sFields_First <= idxField && idxField < td->sFields_First + td->sFields_Num) { break; } @@ -646,24 +651,24 @@ bool CLR_RT_TypeDef_Instance::InitializeFromField( const CLR_RT_FieldDef_Instanc } else { - for(;i; i--, td++) + for (; i; i--, td++) { - if(td->iFields_First <= idxField && idxField < td->iFields_First + td->iFields_Num) + if (td->iFields_First <= idxField && idxField < td->iFields_First + td->iFields_Num) { break; } } } - if(i) + if (i) { CLR_IDX idxAssm = fd.Assembly(); - CLR_IDX idxType = assm->m_pTablesSize[ TBL_TypeDef ] - i; + CLR_IDX idxType = assm->m_pTablesSize[TBL_TypeDef] - i; - Set( idxAssm, idxType ); + Set(idxAssm, idxType); - m_assm = g_CLR_RT_TypeSystem.m_assemblies[ idxAssm-1 ]; - m_target = m_assm->GetTypeDef ( idxType ); + m_assm = g_CLR_RT_TypeSystem.m_assemblies[idxAssm - 1]; + m_target = m_assm->GetTypeDef(idxType); return true; } @@ -685,30 +690,30 @@ void CLR_RT_TypeDef_Instance::Clear() NATIVE_PROFILE_CLR_CORE(); CLR_RT_TypeDef_Index::Clear(); - m_assm = NULL; + m_assm = NULL; m_target = NULL; } -bool CLR_RT_TypeDef_Instance::ResolveToken( CLR_UINT32 tk, CLR_RT_Assembly* assm ) +bool CLR_RT_TypeDef_Instance::ResolveToken(CLR_UINT32 tk, CLR_RT_Assembly *assm) { NATIVE_PROFILE_CLR_CORE(); - if(assm) + if (assm) { - CLR_UINT32 idx = CLR_DataFromTk( tk ); + CLR_UINT32 idx = CLR_DataFromTk(tk); - switch( CLR_TypeFromTk( tk ) ) + switch (CLR_TypeFromTk(tk)) { case TBL_TypeRef: - m_data = assm->m_pCrossReference_TypeRef[ idx ].m_target.m_data; - m_assm = g_CLR_RT_TypeSystem.m_assemblies[ Assembly()-1 ]; - m_target = m_assm->GetTypeDef ( Type () ); + m_data = assm->m_pCrossReference_TypeRef[idx].m_target.m_data; + m_assm = g_CLR_RT_TypeSystem.m_assemblies[Assembly() - 1]; + m_target = m_assm->GetTypeDef(Type()); return true; case TBL_TypeDef: - Set( assm->m_idx, idx ); + Set(assm->m_idx, idx); - m_assm = assm; - m_target = assm->GetTypeDef( idx ); + m_assm = assm; + m_target = assm->GetTypeDef(idx); return true; default: @@ -727,27 +732,27 @@ bool CLR_RT_TypeDef_Instance::ResolveToken( CLR_UINT32 tk, CLR_RT_Assembly* assm bool CLR_RT_TypeDef_Instance::SwitchToParent() { NATIVE_PROFILE_CLR_CORE(); - if(NANOCLR_INDEX_IS_VALID(*this)) + if (NANOCLR_INDEX_IS_VALID(*this)) { CLR_IDX extends = m_target->extends; - if(extends != CLR_EmptyIndex) + if (extends != CLR_EmptyIndex) { - CLR_RT_TypeDef_Index tmp; - const CLR_RT_TypeDef_Index* cls; + CLR_RT_TypeDef_Index tmp; + const CLR_RT_TypeDef_Index *cls; - if(extends & 0x8000) // TypeRef + if (extends & 0x8000) // TypeRef { - cls = &m_assm->m_pCrossReference_TypeRef[ extends & 0x7FFF ].m_target; + cls = &m_assm->m_pCrossReference_TypeRef[extends & 0x7FFF].m_target; } else { - tmp.Set( Assembly(), extends ); + tmp.Set(Assembly(), extends); cls = &tmp; } - return InitializeFromIndex( *cls ); + return InitializeFromIndex(*cls); } } @@ -759,25 +764,26 @@ bool CLR_RT_TypeDef_Instance::SwitchToParent() bool CLR_RT_TypeDef_Instance::HasFinalizer() const { NATIVE_PROFILE_CLR_CORE(); - return NANOCLR_INDEX_IS_VALID(*this) && (CrossReference().m_flags & CLR_RT_TypeDef_CrossReference::TD_CR_HasFinalizer); + return NANOCLR_INDEX_IS_VALID(*this) && + (CrossReference().m_flags & CLR_RT_TypeDef_CrossReference::TD_CR_HasFinalizer); } ////////////////////////////// -bool CLR_RT_FieldDef_Instance::InitializeFromIndex( const CLR_RT_FieldDef_Index& idx ) +bool CLR_RT_FieldDef_Instance::InitializeFromIndex(const CLR_RT_FieldDef_Index &idx) { NATIVE_PROFILE_CLR_CORE(); - if(NANOCLR_INDEX_IS_VALID(idx)) + if (NANOCLR_INDEX_IS_VALID(idx)) { - m_data = idx.m_data; - m_assm = g_CLR_RT_TypeSystem.m_assemblies[ Assembly()-1 ]; - m_target = m_assm->GetFieldDef ( Field () ); + m_data = idx.m_data; + m_assm = g_CLR_RT_TypeSystem.m_assemblies[Assembly() - 1]; + m_target = m_assm->GetFieldDef(Field()); return true; } - m_data = 0; - m_assm = NULL; + m_data = 0; + m_assm = NULL; m_target = NULL; return false; @@ -788,30 +794,30 @@ void CLR_RT_FieldDef_Instance::Clear() NATIVE_PROFILE_CLR_CORE(); CLR_RT_FieldDef_Index::Clear(); - m_assm = NULL; + m_assm = NULL; m_target = NULL; } -bool CLR_RT_FieldDef_Instance::ResolveToken( CLR_UINT32 tk, CLR_RT_Assembly* assm ) +bool CLR_RT_FieldDef_Instance::ResolveToken(CLR_UINT32 tk, CLR_RT_Assembly *assm) { NATIVE_PROFILE_CLR_CORE(); - if(assm) + if (assm) { - CLR_UINT32 idx = CLR_DataFromTk( tk ); + CLR_UINT32 idx = CLR_DataFromTk(tk); - switch(CLR_TypeFromTk( tk )) + switch (CLR_TypeFromTk(tk)) { case TBL_FieldRef: - m_data = assm->m_pCrossReference_FieldRef[ idx ].m_target.m_data; - m_assm = g_CLR_RT_TypeSystem.m_assemblies[ Assembly()-1 ]; - m_target = m_assm->GetFieldDef ( Field () ); + m_data = assm->m_pCrossReference_FieldRef[idx].m_target.m_data; + m_assm = g_CLR_RT_TypeSystem.m_assemblies[Assembly() - 1]; + m_target = m_assm->GetFieldDef(Field()); return true; case TBL_FieldDef: - Set( assm->m_idx, idx ); + Set(assm->m_idx, idx); - m_assm = assm; - m_target = m_assm->GetFieldDef( idx ); + m_assm = assm; + m_target = m_assm->GetFieldDef(idx); return true; default: @@ -827,20 +833,20 @@ bool CLR_RT_FieldDef_Instance::ResolveToken( CLR_UINT32 tk, CLR_RT_Assembly* ass ////////////////////////////// -bool CLR_RT_MethodDef_Instance::InitializeFromIndex( const CLR_RT_MethodDef_Index& idx ) +bool CLR_RT_MethodDef_Instance::InitializeFromIndex(const CLR_RT_MethodDef_Index &idx) { NATIVE_PROFILE_CLR_CORE(); - if(NANOCLR_INDEX_IS_VALID(idx)) + if (NANOCLR_INDEX_IS_VALID(idx)) { - m_data = idx.m_data; - m_assm = g_CLR_RT_TypeSystem.m_assemblies[ Assembly()-1 ]; - m_target = m_assm->GetMethodDef ( Method () ); + m_data = idx.m_data; + m_assm = g_CLR_RT_TypeSystem.m_assemblies[Assembly() - 1]; + m_target = m_assm->GetMethodDef(Method()); return true; } - m_data = 0; - m_assm = NULL; + m_data = 0; + m_assm = NULL; m_target = NULL; return false; @@ -851,30 +857,30 @@ void CLR_RT_MethodDef_Instance::Clear() NATIVE_PROFILE_CLR_CORE(); CLR_RT_MethodDef_Index::Clear(); - m_assm = NULL; + m_assm = NULL; m_target = NULL; } -bool CLR_RT_MethodDef_Instance::ResolveToken( CLR_UINT32 tk, CLR_RT_Assembly* assm ) +bool CLR_RT_MethodDef_Instance::ResolveToken(CLR_UINT32 tk, CLR_RT_Assembly *assm) { NATIVE_PROFILE_CLR_CORE(); - if(assm) + if (assm) { - CLR_UINT32 idx = CLR_DataFromTk( tk ); + CLR_UINT32 idx = CLR_DataFromTk(tk); - switch(CLR_TypeFromTk( tk )) + switch (CLR_TypeFromTk(tk)) { case TBL_MethodRef: - m_data = assm->m_pCrossReference_MethodRef[ idx ].m_target.m_data; - m_assm = g_CLR_RT_TypeSystem.m_assemblies[ Assembly()-1 ]; - m_target = m_assm->GetMethodDef ( Method () ); + m_data = assm->m_pCrossReference_MethodRef[idx].m_target.m_data; + m_assm = g_CLR_RT_TypeSystem.m_assemblies[Assembly() - 1]; + m_target = m_assm->GetMethodDef(Method()); return true; case TBL_MethodDef: - Set( assm->m_idx, idx ); + Set(assm->m_idx, idx); - m_assm = assm; - m_target = m_assm->GetMethodDef( idx ); + m_assm = assm; + m_target = m_assm->GetMethodDef(idx); return true; default: @@ -896,33 +902,33 @@ void CLR_RT_TypeDescriptor::TypeDescriptor_Initialize() m_flags = 0; // CLR_UINT32 m_flags; m_handlerCls.Clear(); // CLR_RT_TypeDef_Instance m_handlerCls; // - m_reflex .Clear(); // CLR_RT_ReflectionDef_Index m_reflex; + m_reflex.Clear(); // CLR_RT_ReflectionDef_Index m_reflex; } -HRESULT CLR_RT_TypeDescriptor::InitializeFromDataType( CLR_DataType dt ) +HRESULT CLR_RT_TypeDescriptor::InitializeFromDataType(CLR_DataType dt) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - if(dt >= DATATYPE_FIRST_INVALID) + if (dt >= DATATYPE_FIRST_INVALID) { NANOCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE); } else { - const CLR_RT_DataTypeLookup& dtl = c_CLR_RT_DataTypeLookup[ dt ]; + const CLR_RT_DataTypeLookup &dtl = c_CLR_RT_DataTypeLookup[dt]; m_flags = dtl.m_flags & CLR_RT_DataTypeLookup::c_SemanticMask2; - if(dtl.m_cls) + if (dtl.m_cls) { - if(m_handlerCls.InitializeFromIndex( *dtl.m_cls ) == false) + if (m_handlerCls.InitializeFromIndex(*dtl.m_cls) == false) { NANOCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE); } - m_reflex.m_kind = REFLECTION_TYPE; - m_reflex.m_levels = 0; + m_reflex.m_kind = REFLECTION_TYPE; + m_reflex.m_levels = 0; m_reflex.m_data.m_type = *dtl.m_cls; } else @@ -934,22 +940,22 @@ HRESULT CLR_RT_TypeDescriptor::InitializeFromDataType( CLR_DataType dt ) NANOCLR_NOCLEANUP(); } -HRESULT CLR_RT_TypeDescriptor::InitializeFromReflection( const CLR_RT_ReflectionDef_Index& reflex ) +HRESULT CLR_RT_TypeDescriptor::InitializeFromReflection(const CLR_RT_ReflectionDef_Index &reflex) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); CLR_RT_TypeDef_Instance inst; - CLR_UINT32 levels; + CLR_UINT32 levels; - if(inst.InitializeFromReflection( reflex, &levels ) == false) + if (inst.InitializeFromReflection(reflex, &levels) == false) { NANOCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE); } - NANOCLR_CHECK_HRESULT(InitializeFromType( inst )); + NANOCLR_CHECK_HRESULT(InitializeFromType(inst)); - if(levels) + if (levels) { m_reflex.m_levels = levels; @@ -959,69 +965,78 @@ HRESULT CLR_RT_TypeDescriptor::InitializeFromReflection( const CLR_RT_Reflection NANOCLR_NOCLEANUP(); } -HRESULT CLR_RT_TypeDescriptor::InitializeFromTypeSpec( const CLR_RT_TypeSpec_Index& sig ) +HRESULT CLR_RT_TypeDescriptor::InitializeFromTypeSpec(const CLR_RT_TypeSpec_Index &sig) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); CLR_RT_TypeSpec_Instance inst; - CLR_RT_SignatureParser parser; + CLR_RT_SignatureParser parser; - if(inst.InitializeFromIndex( sig ) == false) + if (inst.InitializeFromIndex(sig) == false) { NANOCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE); } - parser.Initialize_TypeSpec( inst.m_assm, inst.m_target ); + parser.Initialize_TypeSpec(inst.m_assm, inst.m_target); - NANOCLR_SET_AND_LEAVE(InitializeFromSignatureParser( parser )); + NANOCLR_SET_AND_LEAVE(InitializeFromSignatureParser(parser)); NANOCLR_NOCLEANUP(); } -HRESULT CLR_RT_TypeDescriptor::InitializeFromType( const CLR_RT_TypeDef_Index& cls ) +HRESULT CLR_RT_TypeDescriptor::InitializeFromType(const CLR_RT_TypeDef_Index &cls) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - if(m_handlerCls.InitializeFromIndex( cls ) == false) + if (m_handlerCls.InitializeFromIndex(cls) == false) { NANOCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE); } else { - const CLR_RT_DataTypeLookup& dtl = c_CLR_RT_DataTypeLookup[ m_handlerCls.m_target->dataType ]; + const CLR_RT_DataTypeLookup &dtl = c_CLR_RT_DataTypeLookup[m_handlerCls.m_target->dataType]; - m_flags = dtl.m_flags & CLR_RT_DataTypeLookup::c_SemanticMask; + m_flags = dtl.m_flags & CLR_RT_DataTypeLookup::c_SemanticMask; - m_reflex.m_kind = REFLECTION_TYPE; - m_reflex.m_levels = 0; + m_reflex.m_kind = REFLECTION_TYPE; + m_reflex.m_levels = 0; m_reflex.m_data.m_type = m_handlerCls; - if(m_flags == CLR_RT_DataTypeLookup::c_Primitive) + if (m_flags == CLR_RT_DataTypeLookup::c_Primitive) { - if((m_handlerCls.m_target->flags & CLR_RECORD_TYPEDEF::TD_Semantics_Mask) == CLR_RECORD_TYPEDEF::TD_Semantics_Enum) + if ((m_handlerCls.m_target->flags & CLR_RECORD_TYPEDEF::TD_Semantics_Mask) == + CLR_RECORD_TYPEDEF::TD_Semantics_Enum) { m_flags = CLR_RT_DataTypeLookup::c_Enum; } } else { - switch(m_handlerCls.m_target->flags & CLR_RECORD_TYPEDEF::TD_Semantics_Mask) + switch (m_handlerCls.m_target->flags & CLR_RECORD_TYPEDEF::TD_Semantics_Mask) { - case CLR_RECORD_TYPEDEF::TD_Semantics_ValueType: m_flags = CLR_RT_DataTypeLookup::c_ValueType; break; - case CLR_RECORD_TYPEDEF::TD_Semantics_Class : m_flags = CLR_RT_DataTypeLookup::c_Class ; break; - case CLR_RECORD_TYPEDEF::TD_Semantics_Interface: m_flags = CLR_RT_DataTypeLookup::c_Interface; break; - case CLR_RECORD_TYPEDEF::TD_Semantics_Enum : m_flags = CLR_RT_DataTypeLookup::c_Enum ; break; + case CLR_RECORD_TYPEDEF::TD_Semantics_ValueType: + m_flags = CLR_RT_DataTypeLookup::c_ValueType; + break; + case CLR_RECORD_TYPEDEF::TD_Semantics_Class: + m_flags = CLR_RT_DataTypeLookup::c_Class; + break; + case CLR_RECORD_TYPEDEF::TD_Semantics_Interface: + m_flags = CLR_RT_DataTypeLookup::c_Interface; + break; + case CLR_RECORD_TYPEDEF::TD_Semantics_Enum: + m_flags = CLR_RT_DataTypeLookup::c_Enum; + break; } } - if(m_handlerCls.m_data == g_CLR_RT_WellKnownTypes.m_Array.m_data) + if (m_handlerCls.m_data == g_CLR_RT_WellKnownTypes.m_Array.m_data) { m_flags |= CLR_RT_DataTypeLookup::c_Array; } - if(m_handlerCls.m_data == g_CLR_RT_WellKnownTypes.m_ArrayList.m_data) + if (m_handlerCls.m_data == g_CLR_RT_WellKnownTypes.m_ArrayList.m_data) { m_flags |= CLR_RT_DataTypeLookup::c_ArrayList; } @@ -1030,35 +1045,36 @@ HRESULT CLR_RT_TypeDescriptor::InitializeFromType( const CLR_RT_TypeDef_Index& c NANOCLR_NOCLEANUP(); } -HRESULT CLR_RT_TypeDescriptor::InitializeFromFieldDefinition( const CLR_RT_FieldDef_Instance& fd ) +HRESULT CLR_RT_TypeDescriptor::InitializeFromFieldDefinition(const CLR_RT_FieldDef_Instance &fd) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - CLR_RT_SignatureParser parser; parser.Initialize_FieldDef( fd.m_assm, fd.m_target ); + CLR_RT_SignatureParser parser; + parser.Initialize_FieldDef(fd.m_assm, fd.m_target); - NANOCLR_SET_AND_LEAVE(InitializeFromSignatureParser( parser )); + NANOCLR_SET_AND_LEAVE(InitializeFromSignatureParser(parser)); NANOCLR_NOCLEANUP(); } -HRESULT CLR_RT_TypeDescriptor::InitializeFromSignatureParser( CLR_RT_SignatureParser& parser ) +HRESULT CLR_RT_TypeDescriptor::InitializeFromSignatureParser(CLR_RT_SignatureParser &parser) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); CLR_RT_SignatureParser::Element res; - if(parser.Available() <= 0) + if (parser.Available() <= 0) { NANOCLR_SET_AND_LEAVE(CLR_E_OUT_OF_RANGE); } - NANOCLR_CHECK_HRESULT(parser.Advance( res )); + NANOCLR_CHECK_HRESULT(parser.Advance(res)); - NANOCLR_CHECK_HRESULT(InitializeFromType( res.m_cls )); + NANOCLR_CHECK_HRESULT(InitializeFromType(res.m_cls)); - if(res.m_levels) + if (res.m_levels) { m_reflex.m_levels = res.m_levels; @@ -1068,26 +1084,25 @@ HRESULT CLR_RT_TypeDescriptor::InitializeFromSignatureParser( CLR_RT_SignaturePa NANOCLR_NOCLEANUP(); } -HRESULT CLR_RT_TypeDescriptor::InitializeFromObject( const CLR_RT_HeapBlock& ref ) +HRESULT CLR_RT_TypeDescriptor::InitializeFromObject(const CLR_RT_HeapBlock &ref) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - const CLR_RT_HeapBlock* obj = &ref; - CLR_DataType dt; + const CLR_RT_HeapBlock *obj = &ref; + CLR_DataType dt; - - while(true) + while (true) { dt = (CLR_DataType)obj->DataType(); - if(dt == DATATYPE_BYREF || - dt == DATATYPE_OBJECT ) + if (dt == DATATYPE_BYREF || dt == DATATYPE_OBJECT) { - obj = obj->Dereference(); FAULT_ON_NULL(obj); + obj = obj->Dereference(); + FAULT_ON_NULL(obj); } #if defined(NANOCLR_APPDOMAINS) - else if(dt == DATATYPE_TRANSPARENT_PROXY) + else if (dt == DATATYPE_TRANSPARENT_PROXY) { NANOCLR_CHECK_HRESULT(obj->TransparentProxyValidate()); obj = obj->TransparentProxyDereference(); @@ -1100,97 +1115,111 @@ HRESULT CLR_RT_TypeDescriptor::InitializeFromObject( const CLR_RT_HeapBlock& ref } { - const CLR_RT_TypeDef_Index* cls = NULL; - const CLR_RT_ReflectionDef_Index* reflex = NULL; + const CLR_RT_TypeDef_Index *cls = NULL; + const CLR_RT_ReflectionDef_Index *reflex = NULL; - switch(dt) + switch (dt) { - case DATATYPE_SZARRAY: - reflex = &obj->ReflectionDataConst(); - cls = &reflex->m_data.m_type; - break; + case DATATYPE_SZARRAY: + reflex = &obj->ReflectionDataConst(); + cls = &reflex->m_data.m_type; + break; - case DATATYPE_VALUETYPE: - case DATATYPE_CLASS: - cls = &obj->ObjectCls(); - break; + case DATATYPE_VALUETYPE: + case DATATYPE_CLASS: + cls = &obj->ObjectCls(); + break; - case DATATYPE_DELEGATE_HEAD: + case DATATYPE_DELEGATE_HEAD: { - CLR_RT_HeapBlock_Delegate* dlg = (CLR_RT_HeapBlock_Delegate*)obj; + CLR_RT_HeapBlock_Delegate *dlg = (CLR_RT_HeapBlock_Delegate *)obj; cls = NANOCLR_INDEX_IS_VALID(dlg->m_cls) ? &dlg->m_cls : &g_CLR_RT_WellKnownTypes.m_Delegate; } break; - case DATATYPE_DELEGATELIST_HEAD: + case DATATYPE_DELEGATELIST_HEAD: { - CLR_RT_HeapBlock_Delegate_List* dlgLst = (CLR_RT_HeapBlock_Delegate_List*)obj; + CLR_RT_HeapBlock_Delegate_List *dlgLst = (CLR_RT_HeapBlock_Delegate_List *)obj; - cls = NANOCLR_INDEX_IS_VALID(dlgLst->m_cls) ? &dlgLst->m_cls : &g_CLR_RT_WellKnownTypes.m_MulticastDelegate; + cls = NANOCLR_INDEX_IS_VALID(dlgLst->m_cls) ? &dlgLst->m_cls + : &g_CLR_RT_WellKnownTypes.m_MulticastDelegate; } break; - //--// + //--// - case DATATYPE_WEAKCLASS: + case DATATYPE_WEAKCLASS: { cls = &g_CLR_RT_WellKnownTypes.m_WeakReference; } break; - //--// + //--// - case DATATYPE_REFLECTION: - reflex = &(obj->ReflectionDataConst()); + case DATATYPE_REFLECTION: + reflex = &(obj->ReflectionDataConst()); - switch(reflex->m_kind) - { - case REFLECTION_ASSEMBLY : cls = &g_CLR_RT_WellKnownTypes.m_Assembly ; break; - case REFLECTION_TYPE : cls = &g_CLR_RT_WellKnownTypes.m_Type ; break; - case REFLECTION_TYPE_DELAYED: cls = &g_CLR_RT_WellKnownTypes.m_Type ; break; - case REFLECTION_CONSTRUCTOR : cls = &g_CLR_RT_WellKnownTypes.m_ConstructorInfo; break; - case REFLECTION_METHOD : cls = &g_CLR_RT_WellKnownTypes.m_MethodInfo ; break; - case REFLECTION_FIELD : cls = &g_CLR_RT_WellKnownTypes.m_FieldInfo ; break; - } + switch (reflex->m_kind) + { + case REFLECTION_ASSEMBLY: + cls = &g_CLR_RT_WellKnownTypes.m_Assembly; + break; + case REFLECTION_TYPE: + cls = &g_CLR_RT_WellKnownTypes.m_Type; + break; + case REFLECTION_TYPE_DELAYED: + cls = &g_CLR_RT_WellKnownTypes.m_Type; + break; + case REFLECTION_CONSTRUCTOR: + cls = &g_CLR_RT_WellKnownTypes.m_ConstructorInfo; + break; + case REFLECTION_METHOD: + cls = &g_CLR_RT_WellKnownTypes.m_MethodInfo; + break; + case REFLECTION_FIELD: + cls = &g_CLR_RT_WellKnownTypes.m_FieldInfo; + break; + } - break; + break; - //--// + //--// - case DATATYPE_ARRAY_BYREF: + case DATATYPE_ARRAY_BYREF: { - CLR_RT_HeapBlock_Array* array = obj->Array(); FAULT_ON_NULL(array); + CLR_RT_HeapBlock_Array *array = obj->Array(); + FAULT_ON_NULL(array); - if(array->m_fReference) + if (array->m_fReference) { - obj = (CLR_RT_HeapBlock*)array->GetElement( obj->ArrayIndex() ); + obj = (CLR_RT_HeapBlock *)array->GetElement(obj->ArrayIndex()); - NANOCLR_SET_AND_LEAVE(InitializeFromObject( *obj )); + NANOCLR_SET_AND_LEAVE(InitializeFromObject(*obj)); } reflex = &array->ReflectionDataConst(); - cls = &reflex->m_data.m_type; + cls = &reflex->m_data.m_type; } break; - //--// + //--// - default: - NANOCLR_SET_AND_LEAVE(InitializeFromDataType( dt )); + default: + NANOCLR_SET_AND_LEAVE(InitializeFromDataType(dt)); } - if(cls) + if (cls) { - NANOCLR_CHECK_HRESULT(InitializeFromType( *cls )); + NANOCLR_CHECK_HRESULT(InitializeFromType(*cls)); } - if(reflex) + if (reflex) { m_reflex = *reflex; } - if(dt == DATATYPE_SZARRAY) + if (dt == DATATYPE_SZARRAY) { ConvertToArray(); } @@ -1207,23 +1236,24 @@ void CLR_RT_TypeDescriptor::ConvertToArray() m_flags &= CLR_RT_DataTypeLookup::c_SemanticMask; m_flags |= CLR_RT_DataTypeLookup::c_Array; - m_handlerCls.InitializeFromIndex( g_CLR_RT_WellKnownTypes.m_Array ); + m_handlerCls.InitializeFromIndex(g_CLR_RT_WellKnownTypes.m_Array); } bool CLR_RT_TypeDescriptor::ShouldEmitHash() { NATIVE_PROFILE_CLR_CORE(); - if(m_flags & (CLR_RT_DataTypeLookup::c_Array | CLR_RT_DataTypeLookup::c_ArrayList)) + if (m_flags & (CLR_RT_DataTypeLookup::c_Array | CLR_RT_DataTypeLookup::c_ArrayList)) { return true; } - if(m_flags & (CLR_RT_DataTypeLookup::c_Primitive | CLR_RT_DataTypeLookup::c_ValueType | CLR_RT_DataTypeLookup::c_Enum)) + if (m_flags & + (CLR_RT_DataTypeLookup::c_Primitive | CLR_RT_DataTypeLookup::c_ValueType | CLR_RT_DataTypeLookup::c_Enum)) { return false; } - if(m_handlerCls.CrossReference().m_hash != 0) + if (m_handlerCls.CrossReference().m_hash != 0) { return true; } @@ -1231,22 +1261,22 @@ bool CLR_RT_TypeDescriptor::ShouldEmitHash() return false; } -bool CLR_RT_TypeDescriptor::GetElementType( CLR_RT_TypeDescriptor& sub ) +bool CLR_RT_TypeDescriptor::GetElementType(CLR_RT_TypeDescriptor &sub) { NATIVE_PROFILE_CLR_CORE(); - switch(m_reflex.m_levels) + switch (m_reflex.m_levels) { - case 0: - return false; + case 0: + return false; - case 1: - sub.InitializeFromType( m_reflex.m_data.m_type ); - break; + case 1: + sub.InitializeFromType(m_reflex.m_data.m_type); + break; - default: - sub = *this; - sub.m_reflex.m_levels--; - break; + default: + sub = *this; + sub.m_reflex.m_levels--; + break; } return true; @@ -1254,20 +1284,20 @@ bool CLR_RT_TypeDescriptor::GetElementType( CLR_RT_TypeDescriptor& sub ) //////////////////////////////////////// -HRESULT CLR_RT_TypeDescriptor::ExtractObjectAndDataType( CLR_RT_HeapBlock*& ref, CLR_DataType& dt ) +HRESULT CLR_RT_TypeDescriptor::ExtractObjectAndDataType(CLR_RT_HeapBlock *&ref, CLR_DataType &dt) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - while(true) + while (true) { dt = (CLR_DataType)ref->DataType(); - if(dt == DATATYPE_BYREF || - dt == DATATYPE_OBJECT ) + if (dt == DATATYPE_BYREF || dt == DATATYPE_OBJECT) { - ref = ref->Dereference(); FAULT_ON_NULL(ref); + ref = ref->Dereference(); + FAULT_ON_NULL(ref); } else { @@ -1278,27 +1308,26 @@ HRESULT CLR_RT_TypeDescriptor::ExtractObjectAndDataType( CLR_RT_HeapBlock*& ref, NANOCLR_NOCLEANUP(); } - -HRESULT CLR_RT_TypeDescriptor::ExtractTypeIndexFromObject( const CLR_RT_HeapBlock& ref, CLR_RT_TypeDef_Index& res ) +HRESULT CLR_RT_TypeDescriptor::ExtractTypeIndexFromObject(const CLR_RT_HeapBlock &ref, CLR_RT_TypeDef_Index &res) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - CLR_RT_HeapBlock* obj = (CLR_RT_HeapBlock*)&ref; - CLR_DataType dt; + CLR_RT_HeapBlock *obj = (CLR_RT_HeapBlock *)&ref; + CLR_DataType dt; NANOCLR_CHECK_HRESULT(CLR_RT_TypeDescriptor::ExtractObjectAndDataType(obj, dt)); - if(dt == DATATYPE_VALUETYPE || dt == DATATYPE_CLASS) + if (dt == DATATYPE_VALUETYPE || dt == DATATYPE_CLASS) { res = obj->ObjectCls(); } else { - const CLR_RT_DataTypeLookup& dtl = c_CLR_RT_DataTypeLookup[ dt ]; + const CLR_RT_DataTypeLookup &dtl = c_CLR_RT_DataTypeLookup[dt]; - if(dtl.m_cls) + if (dtl.m_cls) { res = *dtl.m_cls; } @@ -1308,16 +1337,16 @@ HRESULT CLR_RT_TypeDescriptor::ExtractTypeIndexFromObject( const CLR_RT_HeapBloc } } - if(NANOCLR_INDEX_IS_INVALID(res)) + if (NANOCLR_INDEX_IS_INVALID(res)) { CLR_RT_TypeDescriptor desc; - NANOCLR_CHECK_HRESULT(desc.InitializeFromObject( ref )) - + NANOCLR_CHECK_HRESULT(desc.InitializeFromObject(ref)) + // If desc.InitializeFromObject( ref ) call succeded, then we use m_handlerCls for res res = desc.m_handlerCls; - if(NANOCLR_INDEX_IS_INVALID(res)) + if (NANOCLR_INDEX_IS_INVALID(res)) { NANOCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE); } @@ -1338,20 +1367,24 @@ static const char c_MARKER_ASSEMBLY_V1[] = "NFMRK1"; bool CLR_RECORD_ASSEMBLY::GoodHeader() const { NATIVE_PROFILE_CLR_CORE(); - CLR_RECORD_ASSEMBLY header = *this; header.headerCRC = 0; + CLR_RECORD_ASSEMBLY header = *this; + header.headerCRC = 0; - if(SUPPORT_ComputeCRC( &header, sizeof(header), 0 ) != this->headerCRC) return false; + if (SUPPORT_ComputeCRC(&header, sizeof(header), 0) != this->headerCRC) + return false; - if(this->stringTableVersion != c_CLR_StringTable_Version) return false; + if (this->stringTableVersion != c_CLR_StringTable_Version) + return false; - return memcmp( marker, c_MARKER_ASSEMBLY_V1, sizeof(c_MARKER_ASSEMBLY_V1) ) == 0; + return memcmp(marker, c_MARKER_ASSEMBLY_V1, sizeof(c_MARKER_ASSEMBLY_V1)) == 0; } bool CLR_RECORD_ASSEMBLY::GoodAssembly() const { NATIVE_PROFILE_CLR_CORE(); - if(!GoodHeader()) return false; - return SUPPORT_ComputeCRC( &this[ 1 ], this->TotalSize() - sizeof(*this), 0 ) == this->assemblyCRC; + if (!GoodHeader()) + return false; + return SUPPORT_ComputeCRC(&this[1], this->TotalSize() - sizeof(*this), 0) == this->assemblyCRC; } #if defined(WIN32) @@ -1359,35 +1392,36 @@ bool CLR_RECORD_ASSEMBLY::GoodAssembly() const void CLR_RECORD_ASSEMBLY::ComputeCRC() { NATIVE_PROFILE_CLR_CORE(); - memcpy( marker, c_MARKER_ASSEMBLY_V1, sizeof(marker) ); + memcpy(marker, c_MARKER_ASSEMBLY_V1, sizeof(marker)); - headerCRC = 0; - assemblyCRC = SUPPORT_ComputeCRC( &this[ 1 ], this->TotalSize() - sizeof(*this), 0 ); - headerCRC = SUPPORT_ComputeCRC( this , sizeof(*this), 0 ); + headerCRC = 0; + assemblyCRC = SUPPORT_ComputeCRC(&this[1], this->TotalSize() - sizeof(*this), 0); + headerCRC = SUPPORT_ComputeCRC(this, sizeof(*this), 0); } #endif -CLR_UINT32 CLR_RECORD_ASSEMBLY::ComputeAssemblyHash( const char* name, const CLR_RECORD_VERSION& ver ) +CLR_UINT32 CLR_RECORD_ASSEMBLY::ComputeAssemblyHash(const char *name, const CLR_RECORD_VERSION &ver) { NATIVE_PROFILE_CLR_CORE(); CLR_UINT32 assemblyHASH; - assemblyHASH = SUPPORT_ComputeCRC( name, (int)hal_strlen_s( name ), 0 ); - assemblyHASH = SUPPORT_ComputeCRC( &ver, sizeof( ver ), assemblyHASH ); + assemblyHASH = SUPPORT_ComputeCRC(name, (int)hal_strlen_s(name), 0); + assemblyHASH = SUPPORT_ComputeCRC(&ver, sizeof(ver), assemblyHASH); return assemblyHASH; } //--// -CLR_PMETADATA CLR_RECORD_EH::ExtractEhFromByteCode( CLR_PMETADATA ipEnd, const CLR_RECORD_EH*& ptrEh, CLR_UINT32& numEh ) +CLR_PMETADATA CLR_RECORD_EH::ExtractEhFromByteCode(CLR_PMETADATA ipEnd, const CLR_RECORD_EH *&ptrEh, CLR_UINT32 &numEh) { NATIVE_PROFILE_CLR_CORE(); - CLR_UINT32 num = *(--ipEnd); ipEnd -= sizeof(CLR_RECORD_EH) * num; + CLR_UINT32 num = *(--ipEnd); + ipEnd -= sizeof(CLR_RECORD_EH) * num; numEh = num; - ptrEh = (const CLR_RECORD_EH*)ipEnd; + ptrEh = (const CLR_RECORD_EH *)ipEnd; return ipEnd; } @@ -1395,69 +1429,71 @@ CLR_PMETADATA CLR_RECORD_EH::ExtractEhFromByteCode( CLR_PMETADATA ipEnd, const C CLR_UINT32 CLR_RECORD_EH::GetToken() const { NATIVE_PROFILE_CLR_CORE(); - if(classToken & 0x8000) + if (classToken & 0x8000) { - return CLR_TkFromType( TBL_TypeRef, classToken & 0x7FFF ); + return CLR_TkFromType(TBL_TypeRef, classToken & 0x7FFF); } else { - return CLR_TkFromType( TBL_TypeDef, classToken ); + return CLR_TkFromType(TBL_TypeDef, classToken); } } //////////////////////////////////////////////////////////////////////////////////////////////////// -bool CLR_RT_ExceptionHandler::ConvertFromEH( const CLR_RT_MethodDef_Instance& owner, CLR_PMETADATA ipStart, const CLR_RECORD_EH* ehPtr ) +bool CLR_RT_ExceptionHandler::ConvertFromEH( + const CLR_RT_MethodDef_Instance &owner, + CLR_PMETADATA ipStart, + const CLR_RECORD_EH *ehPtr) { NATIVE_PROFILE_CLR_CORE(); - CLR_RECORD_EH eh; memcpy( &eh, ehPtr, sizeof(eh) ); + CLR_RECORD_EH eh; + memcpy(&eh, ehPtr, sizeof(eh)); - switch(eh.mode) + switch (eh.mode) { - case CLR_RECORD_EH::EH_Finally: - m_typeFilter.Clear(); - break; + case CLR_RECORD_EH::EH_Finally: + m_typeFilter.Clear(); + break; - case CLR_RECORD_EH::EH_Filter: - m_userFilterStart = ipStart + eh.filterStart; - break; + case CLR_RECORD_EH::EH_Filter: + m_userFilterStart = ipStart + eh.filterStart; + break; - case CLR_RECORD_EH::EH_CatchAll: - m_typeFilter = g_CLR_RT_WellKnownTypes.m_Object; - break; + case CLR_RECORD_EH::EH_CatchAll: + m_typeFilter = g_CLR_RT_WellKnownTypes.m_Object; + break; - case CLR_RECORD_EH::EH_Catch: + case CLR_RECORD_EH::EH_Catch: { CLR_RT_TypeDef_Instance cls; - if(cls.ResolveToken( eh.GetToken(), owner.m_assm ) == false) return false; + if (cls.ResolveToken(eh.GetToken(), owner.m_assm) == false) + return false; m_typeFilter = cls; } break; - default: - return false; + default: + return false; } - if(owner.m_target->RVA == CLR_EmptyIndex) return false; + if (owner.m_target->RVA == CLR_EmptyIndex) + return false; - m_ehType = eh.mode; - m_tryStart = ipStart + eh.tryStart; - m_tryEnd = ipStart + eh.tryEnd; + m_ehType = eh.mode; + m_tryStart = ipStart + eh.tryStart; + m_tryEnd = ipStart + eh.tryEnd; m_handlerStart = ipStart + eh.handlerStart; - m_handlerEnd = ipStart + eh.handlerEnd; + m_handlerEnd = ipStart + eh.handlerEnd; return true; } //////////////////////////////////////////////////////////////////////////////////////////////////// - -bool CLR_RT_Assembly::IsSameAssembly( const CLR_RT_Assembly& assm ) const +bool CLR_RT_Assembly::IsSameAssembly(const CLR_RT_Assembly &assm) const { - if( - m_header->headerCRC == assm.m_header->headerCRC && - m_header->assemblyCRC == assm.m_header->assemblyCRC - ) + if (m_header->headerCRC == assm.m_header->headerCRC && m_header->assemblyCRC == assm.m_header->assemblyCRC) { return true; } @@ -1465,65 +1501,68 @@ bool CLR_RT_Assembly::IsSameAssembly( const CLR_RT_Assembly& assm ) const return false; } -void CLR_RT_Assembly::Assembly_Initialize( CLR_RT_Assembly::Offsets& offsets ) +void CLR_RT_Assembly::Assembly_Initialize(CLR_RT_Assembly::Offsets &offsets) { NATIVE_PROFILE_CLR_CORE(); - CLR_UINT8* buffer = (CLR_UINT8*)this; - int i; + CLR_UINT8 *buffer = (CLR_UINT8 *)this; + int i; - m_szName = GetString( m_header->assemblyName ); + m_szName = GetString(m_header->assemblyName); //--// - buffer += offsets.iBase ; - m_pCrossReference_AssemblyRef = (CLR_RT_AssemblyRef_CrossReference*)buffer; buffer += offsets.iAssemblyRef ; - m_pCrossReference_TypeRef = (CLR_RT_TypeRef_CrossReference *)buffer; buffer += offsets.iTypeRef ; - m_pCrossReference_FieldRef = (CLR_RT_FieldRef_CrossReference *)buffer; buffer += offsets.iFieldRef ; - m_pCrossReference_MethodRef = (CLR_RT_MethodRef_CrossReference *)buffer; buffer += offsets.iMethodRef ; - m_pCrossReference_TypeDef = (CLR_RT_TypeDef_CrossReference *)buffer; buffer += offsets.iTypeDef ; - m_pCrossReference_FieldDef = (CLR_RT_FieldDef_CrossReference *)buffer; buffer += offsets.iFieldDef ; - m_pCrossReference_MethodDef = (CLR_RT_MethodDef_CrossReference *)buffer; buffer += offsets.iMethodDef ; + buffer += offsets.iBase; + m_pCrossReference_AssemblyRef = (CLR_RT_AssemblyRef_CrossReference *)buffer; + buffer += offsets.iAssemblyRef; + m_pCrossReference_TypeRef = (CLR_RT_TypeRef_CrossReference *)buffer; + buffer += offsets.iTypeRef; + m_pCrossReference_FieldRef = (CLR_RT_FieldRef_CrossReference *)buffer; + buffer += offsets.iFieldRef; + m_pCrossReference_MethodRef = (CLR_RT_MethodRef_CrossReference *)buffer; + buffer += offsets.iMethodRef; + m_pCrossReference_TypeDef = (CLR_RT_TypeDef_CrossReference *)buffer; + buffer += offsets.iTypeDef; + m_pCrossReference_FieldDef = (CLR_RT_FieldDef_CrossReference *)buffer; + buffer += offsets.iFieldDef; + m_pCrossReference_MethodDef = (CLR_RT_MethodDef_CrossReference *)buffer; + buffer += offsets.iMethodDef; #if !defined(NANOCLR_APPDOMAINS) - m_pStaticFields = (CLR_RT_HeapBlock *)buffer; buffer += offsets.iStaticFields ; + m_pStaticFields = (CLR_RT_HeapBlock *)buffer; + buffer += offsets.iStaticFields; - memset( m_pStaticFields, 0, offsets.iStaticFields ); + memset(m_pStaticFields, 0, offsets.iStaticFields); #endif //--// - { - ITERATE_THROUGH_RECORDS(this,i,TypeDef,TYPEDEF) - { - dst->m_flags = 0; - dst->m_totalFields = 0; - dst->m_hash = 0; - } - } + {ITERATE_THROUGH_RECORDS(this, i, TypeDef, TYPEDEF){dst->m_flags = 0; + dst->m_totalFields = 0; + dst->m_hash = 0; +} +} - { - ITERATE_THROUGH_RECORDS(this,i,FieldDef,FIELDDEF) - { - dst->m_offset = CLR_EmptyIndex; - } - } +{ITERATE_THROUGH_RECORDS(this, i, FieldDef, FIELDDEF){dst->m_offset = CLR_EmptyIndex; +} +} +{ + ITERATE_THROUGH_RECORDS(this, i, MethodDef, METHODDEF) { - ITERATE_THROUGH_RECORDS(this,i,MethodDef,METHODDEF) - { - dst->m_data = CLR_EmptyIndex; - } + dst->m_data = CLR_EmptyIndex; } +} #if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) - { - m_pDebuggingInfo_MethodDef = (CLR_RT_MethodDef_DebuggingInfo*)buffer; buffer += offsets.iDebuggingInfoMethods; +{ + m_pDebuggingInfo_MethodDef = (CLR_RT_MethodDef_DebuggingInfo *)buffer; + buffer += offsets.iDebuggingInfoMethods; - memset( m_pDebuggingInfo_MethodDef, 0, offsets.iDebuggingInfoMethods ); - } + memset(m_pDebuggingInfo_MethodDef, 0, offsets.iDebuggingInfoMethods); +} #endif //#if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) } -HRESULT CLR_RT_Assembly::CreateInstance( const CLR_RECORD_ASSEMBLY* header, CLR_RT_Assembly*& assm ) +HRESULT CLR_RT_Assembly::CreateInstance(const CLR_RECORD_ASSEMBLY *header, CLR_RT_Assembly *&assm) { NATIVE_PROFILE_CLR_CORE(); // @@ -1531,36 +1570,36 @@ HRESULT CLR_RT_Assembly::CreateInstance( const CLR_RECORD_ASSEMBLY* header, CLR_ // NANOCLR_HEADER(); - CLR_UINT8 buf[ sizeof(CLR_RT_Assembly) ]; - CLR_RT_Assembly* skeleton = (CLR_RT_Assembly*)buf; + CLR_UINT8 buf[sizeof(CLR_RT_Assembly)]; + CLR_RT_Assembly *skeleton = (CLR_RT_Assembly *)buf; NANOCLR_CLEAR(*skeleton); - if(header->GoodAssembly() == false) NANOCLR_MSG_SET_AND_LEAVE(CLR_E_FAIL, L"Failed in type system: assembly is not good.\n"); + if (header->GoodAssembly() == false) + NANOCLR_MSG_SET_AND_LEAVE(CLR_E_FAIL, L"Failed in type system: assembly is not good.\n"); skeleton->m_header = header; - // // Compute overall size for assembly data structure. // { - for(uint32_t i = 0; im_pTablesSize)-1; i++) + for (uint32_t i = 0; i < ARRAYSIZE(skeleton->m_pTablesSize) - 1; i++) { - skeleton->m_pTablesSize[ i ] = header->SizeOfTable ( (CLR_TABLESENUM)i ); + skeleton->m_pTablesSize[i] = header->SizeOfTable((CLR_TABLESENUM)i); } - skeleton->m_pTablesSize[ TBL_AssemblyRef ] /= sizeof(CLR_RECORD_ASSEMBLYREF ); - skeleton->m_pTablesSize[ TBL_TypeRef ] /= sizeof(CLR_RECORD_TYPEREF ); - skeleton->m_pTablesSize[ TBL_FieldRef ] /= sizeof(CLR_RECORD_FIELDREF ); - skeleton->m_pTablesSize[ TBL_MethodRef ] /= sizeof(CLR_RECORD_METHODREF ); - skeleton->m_pTablesSize[ TBL_TypeDef ] /= sizeof(CLR_RECORD_TYPEDEF ); - skeleton->m_pTablesSize[ TBL_FieldDef ] /= sizeof(CLR_RECORD_FIELDDEF ); - skeleton->m_pTablesSize[ TBL_MethodDef ] /= sizeof(CLR_RECORD_METHODDEF ); - skeleton->m_pTablesSize[ TBL_Attributes ] /= sizeof(CLR_RECORD_ATTRIBUTE ); - skeleton->m_pTablesSize[ TBL_TypeSpec ] /= sizeof(CLR_RECORD_TYPESPEC ); - skeleton->m_pTablesSize[ TBL_Resources ] /= sizeof(CLR_RECORD_RESOURCE ); - skeleton->m_pTablesSize[ TBL_ResourcesFiles ] /= sizeof(CLR_RECORD_RESOURCE_FILE); + skeleton->m_pTablesSize[TBL_AssemblyRef] /= sizeof(CLR_RECORD_ASSEMBLYREF); + skeleton->m_pTablesSize[TBL_TypeRef] /= sizeof(CLR_RECORD_TYPEREF); + skeleton->m_pTablesSize[TBL_FieldRef] /= sizeof(CLR_RECORD_FIELDREF); + skeleton->m_pTablesSize[TBL_MethodRef] /= sizeof(CLR_RECORD_METHODREF); + skeleton->m_pTablesSize[TBL_TypeDef] /= sizeof(CLR_RECORD_TYPEDEF); + skeleton->m_pTablesSize[TBL_FieldDef] /= sizeof(CLR_RECORD_FIELDDEF); + skeleton->m_pTablesSize[TBL_MethodDef] /= sizeof(CLR_RECORD_METHODDEF); + skeleton->m_pTablesSize[TBL_Attributes] /= sizeof(CLR_RECORD_ATTRIBUTE); + skeleton->m_pTablesSize[TBL_TypeSpec] /= sizeof(CLR_RECORD_TYPESPEC); + skeleton->m_pTablesSize[TBL_Resources] /= sizeof(CLR_RECORD_RESOURCE); + skeleton->m_pTablesSize[TBL_ResourcesFiles] /= sizeof(CLR_RECORD_RESOURCE_FILE); } //--// @@ -1569,9 +1608,9 @@ HRESULT CLR_RT_Assembly::CreateInstance( const CLR_RECORD_ASSEMBLY* header, CLR_ // Count static fields. // { - const CLR_RECORD_TYPEDEF* src = (const CLR_RECORD_TYPEDEF*)skeleton->GetTable( TBL_TypeDef ); + const CLR_RECORD_TYPEDEF *src = (const CLR_RECORD_TYPEDEF *)skeleton->GetTable(TBL_TypeDef); - for(int i=0; im_pTablesSize[ TBL_TypeDef ]; i++, src++) + for (int i = 0; i < skeleton->m_pTablesSize[TBL_TypeDef]; i++, src++) { skeleton->m_iStaticFields += src->sFields_Num; } @@ -1582,36 +1621,42 @@ HRESULT CLR_RT_Assembly::CreateInstance( const CLR_RECORD_ASSEMBLY* header, CLR_ { CLR_RT_Assembly::Offsets offsets; - offsets.iBase = ROUNDTOMULTIPLE(sizeof(CLR_RT_Assembly) , CLR_UINT32); - offsets.iAssemblyRef = ROUNDTOMULTIPLE(skeleton->m_pTablesSize[ TBL_AssemblyRef ] * sizeof(CLR_RT_AssemblyRef_CrossReference), CLR_UINT32); - offsets.iTypeRef = ROUNDTOMULTIPLE(skeleton->m_pTablesSize[ TBL_TypeRef ] * sizeof(CLR_RT_TypeRef_CrossReference ), CLR_UINT32); - offsets.iFieldRef = ROUNDTOMULTIPLE(skeleton->m_pTablesSize[ TBL_FieldRef ] * sizeof(CLR_RT_FieldRef_CrossReference ), CLR_UINT32); - offsets.iMethodRef = ROUNDTOMULTIPLE(skeleton->m_pTablesSize[ TBL_MethodRef ] * sizeof(CLR_RT_MethodRef_CrossReference ), CLR_UINT32); - offsets.iTypeDef = ROUNDTOMULTIPLE(skeleton->m_pTablesSize[ TBL_TypeDef ] * sizeof(CLR_RT_TypeDef_CrossReference ), CLR_UINT32); - offsets.iFieldDef = ROUNDTOMULTIPLE(skeleton->m_pTablesSize[ TBL_FieldDef ] * sizeof(CLR_RT_FieldDef_CrossReference ), CLR_UINT32); - offsets.iMethodDef = ROUNDTOMULTIPLE(skeleton->m_pTablesSize[ TBL_MethodDef ] * sizeof(CLR_RT_MethodDef_CrossReference ), CLR_UINT32); - - if(skeleton->m_header->numOfPatchedMethods > 0) + offsets.iBase = ROUNDTOMULTIPLE(sizeof(CLR_RT_Assembly), CLR_UINT32); + offsets.iAssemblyRef = ROUNDTOMULTIPLE( + skeleton->m_pTablesSize[TBL_AssemblyRef] * sizeof(CLR_RT_AssemblyRef_CrossReference), + CLR_UINT32); + offsets.iTypeRef = + ROUNDTOMULTIPLE(skeleton->m_pTablesSize[TBL_TypeRef] * sizeof(CLR_RT_TypeRef_CrossReference), CLR_UINT32); + offsets.iFieldRef = + ROUNDTOMULTIPLE(skeleton->m_pTablesSize[TBL_FieldRef] * sizeof(CLR_RT_FieldRef_CrossReference), CLR_UINT32); + offsets.iMethodRef = ROUNDTOMULTIPLE( + skeleton->m_pTablesSize[TBL_MethodRef] * sizeof(CLR_RT_MethodRef_CrossReference), + CLR_UINT32); + offsets.iTypeDef = + ROUNDTOMULTIPLE(skeleton->m_pTablesSize[TBL_TypeDef] * sizeof(CLR_RT_TypeDef_CrossReference), CLR_UINT32); + offsets.iFieldDef = + ROUNDTOMULTIPLE(skeleton->m_pTablesSize[TBL_FieldDef] * sizeof(CLR_RT_FieldDef_CrossReference), CLR_UINT32); + offsets.iMethodDef = ROUNDTOMULTIPLE( + skeleton->m_pTablesSize[TBL_MethodDef] * sizeof(CLR_RT_MethodDef_CrossReference), + CLR_UINT32); + + if (skeleton->m_header->numOfPatchedMethods > 0) { NANOCLR_SET_AND_LEAVE(CLR_E_ASSM_PATCHING_NOT_SUPPORTED); } #if !defined(NANOCLR_APPDOMAINS) - offsets.iStaticFields = ROUNDTOMULTIPLE(skeleton->m_iStaticFields * sizeof(CLR_RT_HeapBlock ), CLR_UINT32); + offsets.iStaticFields = ROUNDTOMULTIPLE(skeleton->m_iStaticFields * sizeof(CLR_RT_HeapBlock), CLR_UINT32); #endif #if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) - offsets.iDebuggingInfoMethods = ROUNDTOMULTIPLE(skeleton->m_pTablesSize[ TBL_MethodDef ] * sizeof(CLR_RT_MethodDef_DebuggingInfo ), CLR_UINT32); + offsets.iDebuggingInfoMethods = ROUNDTOMULTIPLE( + skeleton->m_pTablesSize[TBL_MethodDef] * sizeof(CLR_RT_MethodDef_DebuggingInfo), + CLR_UINT32); #endif //#if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) - size_t iTotalRamSize = offsets.iBase + - offsets.iAssemblyRef + - offsets.iTypeRef + - offsets.iFieldRef + - offsets.iMethodRef + - offsets.iTypeDef + - offsets.iFieldDef + - offsets.iMethodDef; + size_t iTotalRamSize = offsets.iBase + offsets.iAssemblyRef + offsets.iTypeRef + offsets.iFieldRef + + offsets.iMethodRef + offsets.iTypeDef + offsets.iFieldDef + offsets.iMethodDef; #if !defined(NANOCLR_APPDOMAINS) iTotalRamSize += offsets.iStaticFields; @@ -1623,60 +1668,107 @@ HRESULT CLR_RT_Assembly::CreateInstance( const CLR_RECORD_ASSEMBLY* header, CLR_ //--// - assm = EVENTCACHE_EXTRACT_NODE_AS_BYTES(g_CLR_RT_EventCache,CLR_RT_Assembly,DATATYPE_ASSEMBLY,0,(CLR_UINT32)iTotalRamSize); CHECK_ALLOCATION(assm); + assm = EVENTCACHE_EXTRACT_NODE_AS_BYTES( + g_CLR_RT_EventCache, + CLR_RT_Assembly, + DATATYPE_ASSEMBLY, + 0, + (CLR_UINT32)iTotalRamSize); + CHECK_ALLOCATION(assm); { // // We don't want to blow away the block header... // - CLR_RT_HeapBlock* src = skeleton; - CLR_RT_HeapBlock* dst = assm; + CLR_RT_HeapBlock *src = skeleton; + CLR_RT_HeapBlock *dst = assm; - memset( &dst[ 1 ], 0, iTotalRamSize-sizeof(CLR_RT_HeapBlock) ); - memcpy( &dst[ 1 ], &src[ 1 ], sizeof(*assm)-sizeof(CLR_RT_HeapBlock) ); + memset(&dst[1], 0, iTotalRamSize - sizeof(CLR_RT_HeapBlock)); + memcpy(&dst[1], &src[1], sizeof(*assm) - sizeof(CLR_RT_HeapBlock)); } - assm->Assembly_Initialize( offsets ); - -#if !defined(BUILD_RTM) - CLR_Debug::Printf( " Assembly: %s (%d.%d.%d.%d) ", assm->m_szName, header->version.iMajorVersion, header->version.iMinorVersion, header->version.iBuildNumber, header->version.iRevisionNumber ); + assm->Assembly_Initialize(offsets); - if(s_CLR_RT_fTrace_AssemblyOverhead >= c_CLR_RT_Trace_Info) +#if !defined(BUILD_RTM) + CLR_Debug::Printf( + " Assembly: %s (%d.%d.%d.%d) ", + assm->m_szName, + header->version.iMajorVersion, + header->version.iMinorVersion, + header->version.iBuildNumber, + header->version.iRevisionNumber); + + if (s_CLR_RT_fTrace_AssemblyOverhead >= c_CLR_RT_Trace_Info) { - size_t iMetaData = header->SizeOfTable( TBL_AssemblyRef ) + - header->SizeOfTable( TBL_TypeRef ) + - header->SizeOfTable( TBL_FieldRef ) + - header->SizeOfTable( TBL_MethodRef ) + - header->SizeOfTable( TBL_TypeDef ) + - header->SizeOfTable( TBL_FieldDef ) + - header->SizeOfTable( TBL_MethodDef ) + - header->SizeOfTable( TBL_Attributes ) + - header->SizeOfTable( TBL_TypeSpec ) + - header->SizeOfTable( TBL_Signatures ); - - CLR_Debug::Printf( " (%d RAM - %d ROM - %d METADATA)\r\n\r\n", iTotalRamSize, header->TotalSize(), iMetaData ); - - CLR_Debug::Printf( " AssemblyRef = %8d bytes (%8d elements)\r\n", offsets.iAssemblyRef , skeleton->m_pTablesSize[ TBL_AssemblyRef ] ); - CLR_Debug::Printf( " TypeRef = %8d bytes (%8d elements)\r\n", offsets.iTypeRef , skeleton->m_pTablesSize[ TBL_TypeRef ] ); - CLR_Debug::Printf( " FieldRef = %8d bytes (%8d elements)\r\n", offsets.iFieldRef , skeleton->m_pTablesSize[ TBL_FieldRef ] ); - CLR_Debug::Printf( " MethodRef = %8d bytes (%8d elements)\r\n", offsets.iMethodRef , skeleton->m_pTablesSize[ TBL_MethodRef ] ); - CLR_Debug::Printf( " TypeDef = %8d bytes (%8d elements)\r\n", offsets.iTypeDef , skeleton->m_pTablesSize[ TBL_TypeDef ] ); - CLR_Debug::Printf( " FieldDef = %8d bytes (%8d elements)\r\n", offsets.iFieldDef , skeleton->m_pTablesSize[ TBL_FieldDef ] ); - CLR_Debug::Printf( " MethodDef = %8d bytes (%8d elements)\r\n", offsets.iMethodDef , skeleton->m_pTablesSize[ TBL_MethodDef ] ); -#if !defined(NANOCLR_APPDOMAINS) - CLR_Debug::Printf( " StaticFields = %8d bytes (%8d elements)\r\n", offsets.iStaticFields , skeleton->m_iStaticFields ); + size_t iMetaData = header->SizeOfTable(TBL_AssemblyRef) + header->SizeOfTable(TBL_TypeRef) + + header->SizeOfTable(TBL_FieldRef) + header->SizeOfTable(TBL_MethodRef) + + header->SizeOfTable(TBL_TypeDef) + header->SizeOfTable(TBL_FieldDef) + + header->SizeOfTable(TBL_MethodDef) + header->SizeOfTable(TBL_Attributes) + + header->SizeOfTable(TBL_TypeSpec) + header->SizeOfTable(TBL_Signatures); + + CLR_Debug::Printf( + " (%d RAM - %d ROM - %d METADATA)\r\n\r\n", + iTotalRamSize, + header->TotalSize(), + iMetaData); + + CLR_Debug::Printf( + " AssemblyRef = %8d bytes (%8d elements)\r\n", + offsets.iAssemblyRef, + skeleton->m_pTablesSize[TBL_AssemblyRef]); + CLR_Debug::Printf( + " TypeRef = %8d bytes (%8d elements)\r\n", + offsets.iTypeRef, + skeleton->m_pTablesSize[TBL_TypeRef]); + CLR_Debug::Printf( + " FieldRef = %8d bytes (%8d elements)\r\n", + offsets.iFieldRef, + skeleton->m_pTablesSize[TBL_FieldRef]); + CLR_Debug::Printf( + " MethodRef = %8d bytes (%8d elements)\r\n", + offsets.iMethodRef, + skeleton->m_pTablesSize[TBL_MethodRef]); + CLR_Debug::Printf( + " TypeDef = %8d bytes (%8d elements)\r\n", + offsets.iTypeDef, + skeleton->m_pTablesSize[TBL_TypeDef]); + CLR_Debug::Printf( + " FieldDef = %8d bytes (%8d elements)\r\n", + offsets.iFieldDef, + skeleton->m_pTablesSize[TBL_FieldDef]); + CLR_Debug::Printf( + " MethodDef = %8d bytes (%8d elements)\r\n", + offsets.iMethodDef, + skeleton->m_pTablesSize[TBL_MethodDef]); +#if !defined(NANOCLR_APPDOMAINS) + CLR_Debug::Printf( + " StaticFields = %8d bytes (%8d elements)\r\n", + offsets.iStaticFields, + skeleton->m_iStaticFields); #endif - CLR_Debug::Printf( "\r\n" ); - - CLR_Debug::Printf( " Attributes = %8d bytes (%8d elements)\r\n", skeleton->m_pTablesSize[ TBL_Attributes ] * sizeof(CLR_RECORD_ATTRIBUTE), skeleton->m_pTablesSize[ TBL_Attributes ] ); - CLR_Debug::Printf( " TypeSpec = %8d bytes (%8d elements)\r\n", skeleton->m_pTablesSize[ TBL_TypeSpec ] * sizeof(CLR_RECORD_TYPESPEC ), skeleton->m_pTablesSize[ TBL_TypeSpec ] ); - CLR_Debug::Printf( " Resources = %8d bytes (%8d elements)\r\n", skeleton->m_pTablesSize[ TBL_Resources ] * sizeof(CLR_RECORD_RESOURCE ), skeleton->m_pTablesSize[ TBL_Resources ] ); - CLR_Debug::Printf( " Resources Files = %8d bytes (%8d elements)\r\n", skeleton->m_pTablesSize[ TBL_ResourcesFiles ] * sizeof(CLR_RECORD_RESOURCE ), skeleton->m_pTablesSize[ TBL_ResourcesFiles ] ); - CLR_Debug::Printf( " Resources Data = %8d bytes\r\n" , skeleton->m_pTablesSize[ TBL_ResourcesData ] ); - CLR_Debug::Printf( " Strings = %8d bytes\r\n" , skeleton->m_pTablesSize[ TBL_Strings ] ); - CLR_Debug::Printf( " Signatures = %8d bytes\r\n" , skeleton->m_pTablesSize[ TBL_Signatures ] ); - CLR_Debug::Printf( " ByteCode = %8d bytes\r\n" , skeleton->m_pTablesSize[ TBL_ByteCode ] ); - CLR_Debug::Printf( "\r\n\r\n" ); + CLR_Debug::Printf("\r\n"); + + CLR_Debug::Printf( + " Attributes = %8d bytes (%8d elements)\r\n", + skeleton->m_pTablesSize[TBL_Attributes] * sizeof(CLR_RECORD_ATTRIBUTE), + skeleton->m_pTablesSize[TBL_Attributes]); + CLR_Debug::Printf( + " TypeSpec = %8d bytes (%8d elements)\r\n", + skeleton->m_pTablesSize[TBL_TypeSpec] * sizeof(CLR_RECORD_TYPESPEC), + skeleton->m_pTablesSize[TBL_TypeSpec]); + CLR_Debug::Printf( + " Resources = %8d bytes (%8d elements)\r\n", + skeleton->m_pTablesSize[TBL_Resources] * sizeof(CLR_RECORD_RESOURCE), + skeleton->m_pTablesSize[TBL_Resources]); + CLR_Debug::Printf( + " Resources Files = %8d bytes (%8d elements)\r\n", + skeleton->m_pTablesSize[TBL_ResourcesFiles] * sizeof(CLR_RECORD_RESOURCE), + skeleton->m_pTablesSize[TBL_ResourcesFiles]); + CLR_Debug::Printf(" Resources Data = %8d bytes\r\n", skeleton->m_pTablesSize[TBL_ResourcesData]); + CLR_Debug::Printf(" Strings = %8d bytes\r\n", skeleton->m_pTablesSize[TBL_Strings]); + CLR_Debug::Printf(" Signatures = %8d bytes\r\n", skeleton->m_pTablesSize[TBL_Signatures]); + CLR_Debug::Printf(" ByteCode = %8d bytes\r\n", skeleton->m_pTablesSize[TBL_ByteCode]); + CLR_Debug::Printf("\r\n\r\n"); } #endif } @@ -1684,50 +1776,64 @@ HRESULT CLR_RT_Assembly::CreateInstance( const CLR_RECORD_ASSEMBLY* header, CLR_ NANOCLR_NOCLEANUP(); } - #if defined(WIN32) -HRESULT CLR_RT_Assembly::CreateInstance( const CLR_RECORD_ASSEMBLY* header, CLR_RT_Assembly*& assm, const wchar_t* szName ) +HRESULT CLR_RT_Assembly::CreateInstance( + const CLR_RECORD_ASSEMBLY *header, + CLR_RT_Assembly *&assm, + const wchar_t *szName) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); std::string strPath; - NANOCLR_CHECK_HRESULT(CLR_RT_Assembly::CreateInstance( header, assm )); + NANOCLR_CHECK_HRESULT(CLR_RT_Assembly::CreateInstance(header, assm)); - if(szName != NULL) + if (szName != NULL) { - CLR_RT_UnicodeHelper::ConvertToUTF8( szName, strPath ); + CLR_RT_UnicodeHelper::ConvertToUTF8(szName, strPath); - assm->m_strPath = new std::string( strPath ); + assm->m_strPath = new std::string(strPath); } NANOCLR_NOCLEANUP(); } #endif -bool CLR_RT_Assembly::Resolve_AssemblyRef( bool fOutput ) +bool CLR_RT_Assembly::Resolve_AssemblyRef(bool fOutput) { NATIVE_PROFILE_CLR_CORE(); bool fGot = true; - int i; + int i; - ITERATE_THROUGH_RECORDS(this,i,AssemblyRef,ASSEMBLYREF) + ITERATE_THROUGH_RECORDS(this, i, AssemblyRef, ASSEMBLYREF) { - const char* szName = GetString( src->name ); + const char *szName = GetString(src->name); - if(dst->m_target == NULL) + if (dst->m_target == NULL) { - CLR_RT_Assembly* target = g_CLR_RT_TypeSystem.FindAssembly( szName, &src->version, false ); + CLR_RT_Assembly *target = g_CLR_RT_TypeSystem.FindAssembly(szName, &src->version, false); - if(target == NULL || (target->m_flags & CLR_RT_Assembly::Resolved) == 0) + if (target == NULL || (target->m_flags & CLR_RT_Assembly::Resolved) == 0) { #if !defined(BUILD_RTM) - if(fOutput) + if (fOutput) { - CLR_Debug::Printf( "Assembly: %s (%d.%d.%d.%d)", m_szName, m_header->version.iMajorVersion, m_header->version.iMinorVersion, m_header->version.iBuildNumber, m_header->version.iRevisionNumber ); - - CLR_Debug::Printf( " needs assembly '%s' (%d.%d.%d.%d)\r\n", szName, src->version.iMajorVersion, src->version.iMinorVersion, src->version.iBuildNumber, src->version.iRevisionNumber ); + CLR_Debug::Printf( + "Assembly: %s (%d.%d.%d.%d)", + m_szName, + m_header->version.iMajorVersion, + m_header->version.iMinorVersion, + m_header->version.iBuildNumber, + m_header->version.iRevisionNumber); + + CLR_Debug::Printf( + " needs assembly '%s' (%d.%d.%d.%d)\r\n", + szName, + src->version.iMajorVersion, + src->version.iMinorVersion, + src->version.iBuildNumber, + src->version.iRevisionNumber); } #endif @@ -1746,13 +1852,13 @@ bool CLR_RT_Assembly::Resolve_AssemblyRef( bool fOutput ) void CLR_RT_Assembly::DestroyInstance() { NATIVE_PROFILE_CLR_CORE(); - if(m_idx) + if (m_idx) { - g_CLR_RT_TypeSystem.m_assemblies[ m_idx-1 ] = NULL; + g_CLR_RT_TypeSystem.m_assemblies[m_idx - 1] = NULL; } #if defined(WIN32) - if(this->m_strPath != NULL) + if (this->m_strPath != NULL) { delete this->m_strPath; this->m_strPath = NULL; @@ -1761,7 +1867,7 @@ void CLR_RT_Assembly::DestroyInstance() //--// - g_CLR_RT_EventCache.Append_Node( this ); + g_CLR_RT_EventCache.Append_Node(this); } //--// @@ -1772,59 +1878,59 @@ HRESULT CLR_RT_Assembly::Resolve_TypeRef() int i; - ITERATE_THROUGH_RECORDS(this,i,TypeRef,TYPEREF) + ITERATE_THROUGH_RECORDS(this, i, TypeRef, TYPEREF) { - if(src->scope & 0x8000) // Flag for TypeRef + if (src->scope & 0x8000) // Flag for TypeRef { CLR_RT_TypeDef_Instance inst; - if(inst.InitializeFromIndex( m_pCrossReference_TypeRef[ src->scope & 0x7FFF ].m_target ) == false) + if (inst.InitializeFromIndex(m_pCrossReference_TypeRef[src->scope & 0x7FFF].m_target) == false) { #if !defined(BUILD_RTM) - CLR_Debug::Printf( "Resolve: unknown scope: %08x\r\n", src->scope ); + CLR_Debug::Printf("Resolve: unknown scope: %08x\r\n", src->scope); #endif #if defined(_WIN32) - NANOCLR_CHARMSG_SET_AND_LEAVE(CLR_E_FAIL, "Resolve: unknown scope: %08x\r\n", src->scope); + NANOCLR_CHARMSG_SET_AND_LEAVE(CLR_E_FAIL, "Resolve: unknown scope: %08x\r\n", src->scope); #else - NANOCLR_MSG1_SET_AND_LEAVE(CLR_E_FAIL, L"Resolve: unknown scope: %08x\r\n", src->scope); + NANOCLR_MSG1_SET_AND_LEAVE(CLR_E_FAIL, L"Resolve: unknown scope: %08x\r\n", src->scope); #endif } - const char* szName = GetString( src->name ); - if(inst.m_assm->FindTypeDef( szName, inst.Type(), dst->m_target ) == false) + const char *szName = GetString(src->name); + if (inst.m_assm->FindTypeDef(szName, inst.Type(), dst->m_target) == false) { #if !defined(BUILD_RTM) - CLR_Debug::Printf( "Resolve: unknown type: %s\r\n", szName ); + CLR_Debug::Printf("Resolve: unknown type: %s\r\n", szName); #endif #if defined(_WIN32) - NANOCLR_CHARMSG_SET_AND_LEAVE(CLR_E_FAIL, "Resolve: unknown type: %s\r\n", szName); + NANOCLR_CHARMSG_SET_AND_LEAVE(CLR_E_FAIL, "Resolve: unknown type: %s\r\n", szName); #else - NANOCLR_MSG1_SET_AND_LEAVE(CLR_E_FAIL, L"Resolve: unknown type: %s\r\n", szName); + NANOCLR_MSG1_SET_AND_LEAVE(CLR_E_FAIL, L"Resolve: unknown type: %s\r\n", szName); #endif } } else { - CLR_RT_Assembly* assm = m_pCrossReference_AssemblyRef[ src->scope ].m_target; - if(assm == NULL) + CLR_RT_Assembly *assm = m_pCrossReference_AssemblyRef[src->scope].m_target; + if (assm == NULL) { - NANOCLR_MSG_SET_AND_LEAVE(CLR_E_FAIL, L"Resolve: assm is null\n"); + NANOCLR_MSG_SET_AND_LEAVE(CLR_E_FAIL, L"Resolve: assm is null\n"); } - const char* szNameSpace = GetString( src->nameSpace ); - const char* szName = GetString( src->name ); - if(assm->FindTypeDef( szName, szNameSpace, dst->m_target ) == false) + const char *szNameSpace = GetString(src->nameSpace); + const char *szName = GetString(src->name); + if (assm->FindTypeDef(szName, szNameSpace, dst->m_target) == false) { #if !defined(BUILD_RTM) - CLR_Debug::Printf( "Resolve: unknown type: %s.%s\r\n", szNameSpace, szName ); + CLR_Debug::Printf("Resolve: unknown type: %s.%s\r\n", szNameSpace, szName); #endif #if defined(_WIN32) - NANOCLR_CHARMSG_SET_AND_LEAVE(CLR_E_FAIL, "Resolve: unknown type: %s.%s\r\n", szNameSpace, szName); + NANOCLR_CHARMSG_SET_AND_LEAVE(CLR_E_FAIL, "Resolve: unknown type: %s.%s\r\n", szNameSpace, szName); #else - NANOCLR_MSG1_SET_AND_LEAVE(CLR_E_FAIL, L"Resolve: unknown type: %s\r\n", szName); + NANOCLR_MSG1_SET_AND_LEAVE(CLR_E_FAIL, L"Resolve: unknown type: %s\r\n", szName); #endif } } @@ -1840,35 +1946,35 @@ HRESULT CLR_RT_Assembly::Resolve_FieldRef() int i; - ITERATE_THROUGH_RECORDS(this,i,FieldRef,FIELDREF) + ITERATE_THROUGH_RECORDS(this, i, FieldRef, FIELDREF) { CLR_RT_TypeDef_Instance inst; - if(inst.InitializeFromIndex( m_pCrossReference_TypeRef[ src->container ].m_target ) == false) + if (inst.InitializeFromIndex(m_pCrossReference_TypeRef[src->container].m_target) == false) { #if !defined(BUILD_RTM) - CLR_Debug::Printf( "Resolve Field: unknown scope: %08x\r\n", src->container ); + CLR_Debug::Printf("Resolve Field: unknown scope: %08x\r\n", src->container); #endif #if defined(_WIN32) - NANOCLR_CHARMSG_SET_AND_LEAVE(CLR_E_FAIL, "Resolve Field: unknown scope: %08x\r\n", src->container); + NANOCLR_CHARMSG_SET_AND_LEAVE(CLR_E_FAIL, "Resolve Field: unknown scope: %08x\r\n", src->container); #else - NANOCLR_MSG1_SET_AND_LEAVE(CLR_E_FAIL, L"Resolve Field: unknown scope: %08x\r\n", src->container); + NANOCLR_MSG1_SET_AND_LEAVE(CLR_E_FAIL, L"Resolve Field: unknown scope: %08x\r\n", src->container); #endif } - const char* szName = GetString( src->name ); + const char *szName = GetString(src->name); - if(inst.m_assm->FindFieldDef( inst.m_target, szName, this, src->sig, dst->m_target ) == false) + if (inst.m_assm->FindFieldDef(inst.m_target, szName, this, src->sig, dst->m_target) == false) { #if !defined(BUILD_RTM) - CLR_Debug::Printf( "Resolve: unknown field: %s\r\n", szName ); + CLR_Debug::Printf("Resolve: unknown field: %s\r\n", szName); #endif #if defined(_WIN32) - NANOCLR_CHARMSG_SET_AND_LEAVE(CLR_E_FAIL, "Resolve: unknown field: %s\r\n", szName); + NANOCLR_CHARMSG_SET_AND_LEAVE(CLR_E_FAIL, "Resolve: unknown field: %s\r\n", szName); #else - NANOCLR_MSG1_SET_AND_LEAVE(CLR_E_FAIL, L"Resolve: unknown field: %s\r\n", szName); + NANOCLR_MSG1_SET_AND_LEAVE(CLR_E_FAIL, L"Resolve: unknown field: %s\r\n", szName); #endif } } @@ -1883,29 +1989,29 @@ HRESULT CLR_RT_Assembly::Resolve_MethodRef() int i; - ITERATE_THROUGH_RECORDS(this,i,MethodRef,METHODREF) + ITERATE_THROUGH_RECORDS(this, i, MethodRef, METHODREF) { CLR_RT_TypeDef_Instance inst; - if(inst.InitializeFromIndex( m_pCrossReference_TypeRef[ src->container ].m_target ) == false) + if (inst.InitializeFromIndex(m_pCrossReference_TypeRef[src->container].m_target) == false) { #if !defined(BUILD_RTM) - CLR_Debug::Printf( "Resolve Field: unknown scope: %08x\r\n", src->container ); + CLR_Debug::Printf("Resolve Field: unknown scope: %08x\r\n", src->container); #endif #if defined(_WIN32) - NANOCLR_CHARMSG_SET_AND_LEAVE(CLR_E_FAIL, "Resolve Field: unknown scope: %08x\r\n", src->container); + NANOCLR_CHARMSG_SET_AND_LEAVE(CLR_E_FAIL, "Resolve Field: unknown scope: %08x\r\n", src->container); #else - NANOCLR_MSG1_SET_AND_LEAVE(CLR_E_FAIL, L"Resolve Field: unknown scope: %08x\r\n", src->container); + NANOCLR_MSG1_SET_AND_LEAVE(CLR_E_FAIL, L"Resolve Field: unknown scope: %08x\r\n", src->container); #endif } - const char* name = GetString( src->name ); - bool fGot = false; + const char *name = GetString(src->name); + bool fGot = false; - while(NANOCLR_INDEX_IS_VALID(inst)) + while (NANOCLR_INDEX_IS_VALID(inst)) { - if(inst.m_assm->FindMethodDef( inst.m_target, name, this, src->sig, dst->m_target )) + if (inst.m_assm->FindMethodDef(inst.m_target, name, this, src->sig, dst->m_target)) { fGot = true; break; @@ -1914,21 +2020,25 @@ HRESULT CLR_RT_Assembly::Resolve_MethodRef() inst.SwitchToParent(); } - if(fGot == false) + if (fGot == false) { - inst.InitializeFromIndex( m_pCrossReference_TypeRef[ src->container ].m_target ); + inst.InitializeFromIndex(m_pCrossReference_TypeRef[src->container].m_target); - const CLR_RECORD_TYPEDEF* qTD = inst.m_target; - CLR_RT_Assembly* qASSM = inst.m_assm; + const CLR_RECORD_TYPEDEF *qTD = inst.m_target; + CLR_RT_Assembly *qASSM = inst.m_assm; #if !defined(BUILD_RTM) - CLR_Debug::Printf( "Resolve: unknown method: %s.%s.%s\r\n", qASSM->GetString( qTD->nameSpace ), qASSM->GetString( qTD->name ), name ); + CLR_Debug::Printf( + "Resolve: unknown method: %s.%s.%s\r\n", + qASSM->GetString(qTD->nameSpace), + qASSM->GetString(qTD->name), + name); #endif #if defined(_WIN32) - NANOCLR_CHARMSG_SET_AND_LEAVE(CLR_E_FAIL, "Resolve: unknown method: %s\r\n", name); + NANOCLR_CHARMSG_SET_AND_LEAVE(CLR_E_FAIL, "Resolve: unknown method: %s\r\n", name); #else - NANOCLR_MSG1_SET_AND_LEAVE(CLR_E_FAIL, L"Resolve: unknown method: %s\r\n", name); + NANOCLR_MSG1_SET_AND_LEAVE(CLR_E_FAIL, L"Resolve: unknown method: %s\r\n", name); #endif } } @@ -1942,7 +2052,7 @@ void CLR_RT_Assembly::Resolve_Link() int iStaticFields = 0; int idxType; - ITERATE_THROUGH_RECORDS(this,idxType,TypeDef,TYPEDEF) + ITERATE_THROUGH_RECORDS(this, idxType, TypeDef, TYPEDEF) { int num; int i; @@ -1951,11 +2061,11 @@ void CLR_RT_Assembly::Resolve_Link() // Link static fields. // { - CLR_RT_FieldDef_CrossReference* fd = &m_pCrossReference_FieldDef[ src->sFields_First ]; + CLR_RT_FieldDef_CrossReference *fd = &m_pCrossReference_FieldDef[src->sFields_First]; num = src->sFields_Num; - for(; num; num--, fd++) + for (; num; num--, fd++) { fd->m_offset = iStaticFields++; } @@ -1965,38 +2075,40 @@ void CLR_RT_Assembly::Resolve_Link() // Link instance fields. // { - CLR_RT_TypeDef_Index idx ; idx.Set( m_idx, idxType ); - CLR_RT_TypeDef_Instance inst; inst.InitializeFromIndex( idx ); - CLR_IDX tot = 0; + CLR_RT_TypeDef_Index idx; + idx.Set(m_idx, idxType); + CLR_RT_TypeDef_Instance inst; + inst.InitializeFromIndex(idx); + CLR_IDX tot = 0; do { - if(inst.m_target->flags & CLR_RECORD_TYPEDEF::TD_HasFinalizer) + if (inst.m_target->flags & CLR_RECORD_TYPEDEF::TD_HasFinalizer) { dst->m_flags |= CLR_RT_TypeDef_CrossReference::TD_CR_HasFinalizer; } #if defined(NANOCLR_APPDOMAINS) - if(inst.m_data == g_CLR_RT_WellKnownTypes.m_MarshalByRefObject.m_data) + if (inst.m_data == g_CLR_RT_WellKnownTypes.m_MarshalByRefObject.m_data) { dst->m_flags |= CLR_RT_TypeDef_CrossReference::TD_CR_IsMarshalByRefObject; } #endif tot += inst.m_target->iFields_Num; - } - while(inst.SwitchToParent()); + } while (inst.SwitchToParent()); dst->m_totalFields = tot; //--// - CLR_RT_FieldDef_CrossReference* fd = &m_pCrossReference_FieldDef[ src->iFields_First ]; + CLR_RT_FieldDef_CrossReference *fd = &m_pCrossReference_FieldDef[src->iFields_First]; num = src->iFields_Num; - i = tot - num + CLR_RT_HeapBlock::HB_Object_Fields_Offset; // Take into account the offset from the beginning of the object. + i = tot - num + CLR_RT_HeapBlock::HB_Object_Fields_Offset; // Take into account the offset from the + // beginning of the object. - for(; num; num--, i++, fd++) + for (; num; num--, i++, fd++) { fd->m_offset = i; } @@ -2006,11 +2118,11 @@ void CLR_RT_Assembly::Resolve_Link() // Link methods. // { - CLR_RT_MethodDef_CrossReference* md = &m_pCrossReference_MethodDef[ src->methods_First ]; + CLR_RT_MethodDef_CrossReference *md = &m_pCrossReference_MethodDef[src->methods_First]; int num = src->vMethods_Num + src->iMethods_Num + src->sMethods_Num; - for(; num; num--, md++) + for (; num; num--, md++) { md->m_data = idxType; } @@ -2022,31 +2134,35 @@ void CLR_RT_Assembly::Resolve_Link() #if defined(NANOCLR_APPDOMAINS) -HRESULT CLR_RT_AppDomain::CreateInstance( const char* szName, CLR_RT_AppDomain*& appDomain ) +HRESULT CLR_RT_AppDomain::CreateInstance(const char *szName, CLR_RT_AppDomain *&appDomain) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - CLR_RT_HeapBlock name; name.SetObjectReference( NULL ); - CLR_RT_ProtectFromGC gc( name ); + CLR_RT_HeapBlock name; + name.SetObjectReference(NULL); + CLR_RT_ProtectFromGC gc(name); - if(!szName || szName[ 0 ] == '\0') NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); + if (!szName || szName[0] == '\0') + NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); - //Check to see that the name does not already exist. - NANOCLR_FOREACH_NODE(CLR_RT_AppDomain,appDomain,g_CLR_RT_ExecutionEngine.m_appDomains) + // Check to see that the name does not already exist. + NANOCLR_FOREACH_NODE(CLR_RT_AppDomain, appDomain, g_CLR_RT_ExecutionEngine.m_appDomains) { - if(!strcmp( appDomain->m_strName->StringText(), szName )) NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); + if (!strcmp(appDomain->m_strName->StringText(), szName)) + NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); } NANOCLR_FOREACH_NODE_END(); - NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_String::CreateInstance( name, szName )); + NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_String::CreateInstance(name, szName)); - appDomain = EVENTCACHE_EXTRACT_NODE(g_CLR_RT_EventCache,CLR_RT_AppDomain,DATATYPE_APPDOMAIN_HEAD); CHECK_ALLOCATION(appDomain); + appDomain = EVENTCACHE_EXTRACT_NODE(g_CLR_RT_EventCache, CLR_RT_AppDomain, DATATYPE_APPDOMAIN_HEAD); + CHECK_ALLOCATION(appDomain); appDomain->AppDomain_Initialize(); appDomain->m_strName = name.DereferenceString(); - g_CLR_RT_ExecutionEngine.m_appDomains.LinkAtBack( appDomain ); + g_CLR_RT_ExecutionEngine.m_appDomains.LinkAtBack(appDomain); NANOCLR_NOCLEANUP(); } @@ -2057,22 +2173,23 @@ void CLR_RT_AppDomain::RecoverFromGC() CheckAll(); /* - AppDomains can be zombied and stay around forever. It is worth looking into cleaning up dead AppDomains, but this - needs to be done with great care. First, enumerations of AppDomains must not be allowed. Second, the AppDomain must really be dead. - This is much harder to ensure. Everything that is needed to be checked for explicit AD unloading (stack frames, finalizable objects) - must be checked, but also other things that can cause the AppDomain to be alive, like timers, manaaged drivers, transparent proxies, etc.. + AppDomains can be zombied and stay around forever. It is worth looking into cleaning up dead AppDomains, but + this needs to be done with great care. First, enumerations of AppDomains must not be allowed. Second, the + AppDomain must really be dead. This is much harder to ensure. Everything that is needed to be checked for + explicit AD unloading (stack frames, finalizable objects) must be checked, but also other things that can cause + the AppDomain to be alive, like timers, manaaged drivers, transparent proxies, etc.. */ - if(m_state == CLR_RT_AppDomain::AppDomainState_Unloaded) + if (m_state == CLR_RT_AppDomain::AppDomainState_Unloaded) { - //We could actually clean up here. Since the AppDomain is now officially loaded, - //we can remove all object_to_event_dst references, and null out the - //pointers in the managed AppDomain class, provided that calling any method on the - //AppDomain will result in a AppDomainDisposed exception. However, it's probably - //not worth the effort, the majority of the resources have been already cleaned - //up, from AppDomain_Uninitialize + // We could actually clean up here. Since the AppDomain is now officially loaded, + // we can remove all object_to_event_dst references, and null out the + // pointers in the managed AppDomain class, provided that calling any method on the + // AppDomain will result in a AppDomainDisposed exception. However, it's probably + // not worth the effort, the majority of the resources have been already cleaned + // up, from AppDomain_Uninitialize - if(IsReadyForRelease()) + if (IsReadyForRelease()) { DestroyInstance(); } @@ -2086,18 +2203,18 @@ void CLR_RT_AppDomain::AppDomain_Initialize() m_appDomainAssemblies.DblLinkedList_Initialize(); - m_state = CLR_RT_AppDomain::AppDomainState_Loaded; - m_id = g_CLR_RT_ExecutionEngine.m_appDomainIdNext++; - m_globalLock = NULL; - m_strName = NULL; - m_outOfMemoryException = NULL; + m_state = CLR_RT_AppDomain::AppDomainState_Loaded; + m_id = g_CLR_RT_ExecutionEngine.m_appDomainIdNext++; + m_globalLock = NULL; + m_strName = NULL; + m_outOfMemoryException = NULL; m_appDomainAssemblyLastAccess = NULL; } void CLR_RT_AppDomain::AppDomain_Uninitialize() { NATIVE_PROFILE_CLR_CORE(); - NANOCLR_FOREACH_NODE(CLR_RT_AppDomainAssembly,appDomainAssembly,m_appDomainAssemblies) + NANOCLR_FOREACH_NODE(CLR_RT_AppDomainAssembly, appDomainAssembly, m_appDomainAssemblies) { appDomainAssembly->DestroyInstance(); } @@ -2111,86 +2228,87 @@ void CLR_RT_AppDomain::DestroyInstance() Unlink(); - g_CLR_RT_EventCache.Append_Node( this ); + g_CLR_RT_EventCache.Append_Node(this); } -HRESULT CLR_RT_AppDomain::LoadAssembly( CLR_RT_Assembly* assm ) +HRESULT CLR_RT_AppDomain::LoadAssembly(CLR_RT_Assembly *assm) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - CLR_RT_AppDomain* appDomainSav = g_CLR_RT_ExecutionEngine.SetCurrentAppDomain( this ); - CLR_RT_AppDomainAssembly* appDomainAssembly = NULL; + CLR_RT_AppDomain *appDomainSav = g_CLR_RT_ExecutionEngine.SetCurrentAppDomain(this); + CLR_RT_AppDomainAssembly *appDomainAssembly = NULL; int i; - FAULT_ON_NULL( assm ); + FAULT_ON_NULL(assm); - //check to make sure the assembly is not already loaded - if(FindAppDomainAssembly( assm ) != NULL) NANOCLR_SET_AND_LEAVE(S_OK); + // check to make sure the assembly is not already loaded + if (FindAppDomainAssembly(assm) != NULL) + NANOCLR_SET_AND_LEAVE(S_OK); #if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) g_CLR_RT_ExecutionEngine.Breakpoint_Assemblies_Loaded(); #endif - //Next, make sure that all dependent assemblies are loaded. + // Next, make sure that all dependent assemblies are loaded. { - ITERATE_THROUGH_RECORDS(assm,i,AssemblyRef,ASSEMBLYREF) + ITERATE_THROUGH_RECORDS(assm, i, AssemblyRef, ASSEMBLYREF) { - NANOCLR_CHECK_HRESULT(LoadAssembly( dst->m_target )); + NANOCLR_CHECK_HRESULT(LoadAssembly(dst->m_target)); } } - NANOCLR_CHECK_HRESULT(CLR_RT_AppDomainAssembly::CreateInstance( this, assm, appDomainAssembly )); + NANOCLR_CHECK_HRESULT(CLR_RT_AppDomainAssembly::CreateInstance(this, assm, appDomainAssembly)); - if(m_outOfMemoryException == NULL) + if (m_outOfMemoryException == NULL) { - //Allocate an out of memory exception. We should never get into a case where an out of memory exception - //cannot be thrown. + // Allocate an out of memory exception. We should never get into a case where an out of memory exception + // cannot be thrown. CLR_RT_HeapBlock exception; - _ASSERTE(!strcmp( assm->m_szName, "mscorlib" )); //always the first assembly to be loaded + _ASSERTE(!strcmp(assm->m_szName, "mscorlib")); // always the first assembly to be loaded - NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.NewObjectFromIndex( exception, g_CLR_RT_WellKnownTypes.m_OutOfMemoryException )); + NANOCLR_CHECK_HRESULT( + g_CLR_RT_ExecutionEngine.NewObjectFromIndex(exception, g_CLR_RT_WellKnownTypes.m_OutOfMemoryException)); m_outOfMemoryException = exception.Dereference(); } NANOCLR_CLEANUP(); - if(FAILED(hr)) + if (FAILED(hr)) { - if(appDomainAssembly) + if (appDomainAssembly) { appDomainAssembly->DestroyInstance(); } } - (void)g_CLR_RT_ExecutionEngine.SetCurrentAppDomain( appDomainSav ); + (void)g_CLR_RT_ExecutionEngine.SetCurrentAppDomain(appDomainSav); NANOCLR_CLEANUP_END(); } - -HRESULT CLR_RT_AppDomain::GetManagedObject( CLR_RT_HeapBlock& res ) +HRESULT CLR_RT_AppDomain::GetManagedObject(CLR_RT_HeapBlock &res) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - CLR_RT_AppDomain* appDomainSav = g_CLR_RT_ExecutionEngine.SetCurrentAppDomain( this ); + CLR_RT_AppDomain *appDomainSav = g_CLR_RT_ExecutionEngine.SetCurrentAppDomain(this); - res.SetObjectReference( NULL ); + res.SetObjectReference(NULL); - //Check if a managed object is already present, and use it - NANOCLR_FOREACH_NODE(CLR_RT_ObjectToEvent_Source,ref,m_references) + // Check if a managed object is already present, and use it + NANOCLR_FOREACH_NODE(CLR_RT_ObjectToEvent_Source, ref, m_references) { - CLR_RT_HeapBlock* obj = ref->m_objectPtr; + CLR_RT_HeapBlock *obj = ref->m_objectPtr; _ASSERTE(FIMPLIES(obj, obj->DataType() == DATATYPE_CLASS || obj->DataType() == DATATYPE_VALUETYPE)); - if(obj && obj->ObjectCls().m_data == g_CLR_RT_WellKnownTypes.m_AppDomain.m_data) + if (obj && obj->ObjectCls().m_data == g_CLR_RT_WellKnownTypes.m_AppDomain.m_data) { - //managed appDomain is found. Use it. - res.SetObjectReference( ref->m_objectPtr ); + // managed appDomain is found. Use it. + res.SetObjectReference(ref->m_objectPtr); NANOCLR_SET_AND_LEAVE(S_OK); } @@ -2198,37 +2316,40 @@ HRESULT CLR_RT_AppDomain::GetManagedObject( CLR_RT_HeapBlock& res ) NANOCLR_FOREACH_NODE_END(); { - //Create the managed AppDomain in the destination AppDomain - CLR_RT_HeapBlock* pRes; - CLR_RT_ProtectFromGC gc( res ); + // Create the managed AppDomain in the destination AppDomain + CLR_RT_HeapBlock *pRes; + CLR_RT_ProtectFromGC gc(res); - NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.NewObjectFromIndex( res, g_CLR_RT_WellKnownTypes.m_AppDomain )); + NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.NewObjectFromIndex(res, g_CLR_RT_WellKnownTypes.m_AppDomain)); pRes = res.Dereference(); - NANOCLR_CHECK_HRESULT(CLR_RT_ObjectToEvent_Source::CreateInstance( this, *pRes, pRes[ Library_corlib_native_System_AppDomain::FIELD___appDomain ] )); + NANOCLR_CHECK_HRESULT(CLR_RT_ObjectToEvent_Source::CreateInstance( + this, + *pRes, + pRes[Library_corlib_native_System_AppDomain::FIELD___appDomain])); - pRes[ Library_corlib_native_System_AppDomain::FIELD___friendlyName ].SetObjectReference( m_strName ); + pRes[Library_corlib_native_System_AppDomain::FIELD___friendlyName].SetObjectReference(m_strName); } NANOCLR_CLEANUP(); - g_CLR_RT_ExecutionEngine.SetCurrentAppDomain( appDomainSav ); + g_CLR_RT_ExecutionEngine.SetCurrentAppDomain(appDomainSav); NANOCLR_CLEANUP_END(); } -CLR_RT_AppDomainAssembly* CLR_RT_AppDomain::FindAppDomainAssembly( CLR_RT_Assembly* assm ) +CLR_RT_AppDomainAssembly *CLR_RT_AppDomain::FindAppDomainAssembly(CLR_RT_Assembly *assm) { NATIVE_PROFILE_CLR_CORE(); - if(m_appDomainAssemblyLastAccess != NULL && m_appDomainAssemblyLastAccess->m_assembly == assm) + if (m_appDomainAssemblyLastAccess != NULL && m_appDomainAssemblyLastAccess->m_assembly == assm) { return m_appDomainAssemblyLastAccess; } - NANOCLR_FOREACH_NODE(CLR_RT_AppDomainAssembly,appDomainAssembly,m_appDomainAssemblies) + NANOCLR_FOREACH_NODE(CLR_RT_AppDomainAssembly, appDomainAssembly, m_appDomainAssemblies) { - if(appDomainAssembly->m_assembly == assm) + if (appDomainAssembly->m_assembly == assm) { m_appDomainAssemblyLastAccess = appDomainAssembly; @@ -2243,54 +2364,56 @@ CLR_RT_AppDomainAssembly* CLR_RT_AppDomain::FindAppDomainAssembly( CLR_RT_Assemb void CLR_RT_AppDomain::Relocate() { NATIVE_PROFILE_CLR_CORE(); - CLR_RT_GarbageCollector::Heap_Relocate( (void**)&m_globalLock ); - CLR_RT_GarbageCollector::Heap_Relocate( (void**)&m_strName ); - CLR_RT_GarbageCollector::Heap_Relocate( (void**)&m_outOfMemoryException ); + CLR_RT_GarbageCollector::Heap_Relocate((void **)&m_globalLock); + CLR_RT_GarbageCollector::Heap_Relocate((void **)&m_strName); + CLR_RT_GarbageCollector::Heap_Relocate((void **)&m_outOfMemoryException); } -HRESULT CLR_RT_AppDomain::VerifyTypeIsLoaded( const CLR_RT_TypeDef_Index& idx ) +HRESULT CLR_RT_AppDomain::VerifyTypeIsLoaded(const CLR_RT_TypeDef_Index &idx) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); CLR_RT_TypeDef_Instance inst; - if(!inst.InitializeFromIndex( idx )) NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER ); - if(!FindAppDomainAssembly ( inst.m_assm )) NANOCLR_SET_AND_LEAVE(CLR_E_APPDOMAIN_MARSHAL_EXCEPTION); + if (!inst.InitializeFromIndex(idx)) + NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); + if (!FindAppDomainAssembly(inst.m_assm)) + NANOCLR_SET_AND_LEAVE(CLR_E_APPDOMAIN_MARSHAL_EXCEPTION); NANOCLR_NOCLEANUP(); } -HRESULT CLR_RT_AppDomain::MarshalObject( CLR_RT_HeapBlock& src, CLR_RT_HeapBlock& dst, CLR_RT_AppDomain* appDomainSrc ) +HRESULT CLR_RT_AppDomain::MarshalObject(CLR_RT_HeapBlock &src, CLR_RT_HeapBlock &dst, CLR_RT_AppDomain *appDomainSrc) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - //This function marshals an object from appDomainSrc to 'this' AppDomain - //If appDomainSrc == NULL, this uses the current AppDomain + // This function marshals an object from appDomainSrc to 'this' AppDomain + // If appDomainSrc == NULL, this uses the current AppDomain - CLR_RT_AppDomain* appDomainDst = this; - CLR_RT_HeapBlock* proxySrc = NULL; - CLR_RT_HeapBlock* mbroSrc = NULL; - bool fSimpleAssign = false; + CLR_RT_AppDomain *appDomainDst = this; + CLR_RT_HeapBlock *proxySrc = NULL; + CLR_RT_HeapBlock *mbroSrc = NULL; + bool fSimpleAssign = false; CLR_RT_TypeDef_Index idxVerify = g_CLR_RT_WellKnownTypes.m_Object; - CLR_DataType dtSrc = src.DataType(); - CLR_RT_AppDomain* appDomainSav = g_CLR_RT_ExecutionEngine.GetCurrentAppDomain(); + CLR_DataType dtSrc = src.DataType(); + CLR_RT_AppDomain *appDomainSav = g_CLR_RT_ExecutionEngine.GetCurrentAppDomain(); - if(!appDomainSrc) + if (!appDomainSrc) { appDomainSrc = appDomainSav; } // - //DATATYPE_LAST_PRIMITIVE_TO_MARSHAL note - //We should think about allowing STRINGS to be shared across AD boundaries - //Strings are read-only and it is safe to do this with some small restrictions - //First, as with the Assembly unloading, some strings can actually point within an - //assembly. If we allow assemblies to be unloaded (and why shouldn't we, if they are - //not in any AppDomain, than we need to deal with this case). If we just - //get copy the string on constructor, then we do not need to marshal strings - //across AD boundaries. + // DATATYPE_LAST_PRIMITIVE_TO_MARSHAL note + // We should think about allowing STRINGS to be shared across AD boundaries + // Strings are read-only and it is safe to do this with some small restrictions + // First, as with the Assembly unloading, some strings can actually point within an + // assembly. If we allow assemblies to be unloaded (and why shouldn't we, if they are + // not in any AppDomain, than we need to deal with this case). If we just + // get copy the string on constructor, then we do not need to marshal strings + // across AD boundaries. // fSimpleAssign = (appDomainSrc == appDomainDst); fSimpleAssign = fSimpleAssign || (dtSrc <= DATATYPE_LAST_PRIMITIVE_TO_MARSHAL); @@ -2300,166 +2423,177 @@ HRESULT CLR_RT_AppDomain::MarshalObject( CLR_RT_HeapBlock& src, CLR_RT_HeapBlock fSimpleAssign = fSimpleAssign || (dtSrc == DATATYPE_STRING && !src.StringAssembly()); #endif - if(!fSimpleAssign) + if (!fSimpleAssign) { - if(dtSrc == DATATYPE_OBJECT) + if (dtSrc == DATATYPE_OBJECT) { - CLR_RT_HeapBlock* ptr = src.Dereference(); + CLR_RT_HeapBlock *ptr = src.Dereference(); - switch(ptr->DataType()) + switch (ptr->DataType()) { case DATATYPE_TRANSPARENT_PROXY: - { - proxySrc = ptr; + { + proxySrc = ptr; - NANOCLR_CHECK_HRESULT(proxySrc->TransparentProxyValidate()); + NANOCLR_CHECK_HRESULT(proxySrc->TransparentProxyValidate()); - idxVerify = proxySrc->TransparentProxyDereference()->ObjectCls(); + idxVerify = proxySrc->TransparentProxyDereference()->ObjectCls(); - if(proxySrc->TransparentProxyAppDomain() != appDomainDst) - { - //marshalling a transparent proxy object to a third AppDomain - //This makes the marshaling a simple assign of the DATATYPE_TRANSPARENT_PROXY heapblock - fSimpleAssign = true; - } + if (proxySrc->TransparentProxyAppDomain() != appDomainDst) + { + // marshalling a transparent proxy object to a third AppDomain + // This makes the marshaling a simple assign of the DATATYPE_TRANSPARENT_PROXY heapblock + fSimpleAssign = true; } - break; + } + break; case DATATYPE_CLASS: - { - CLR_RT_TypeDef_Instance inst; + { + CLR_RT_TypeDef_Instance inst; - if(inst.InitializeFromIndex( ptr->ObjectCls() )) + if (inst.InitializeFromIndex(ptr->ObjectCls())) + { + if ((inst.CrossReference().m_flags & + CLR_RT_TypeDef_CrossReference::TD_CR_IsMarshalByRefObject) != 0) { - if((inst.CrossReference().m_flags & CLR_RT_TypeDef_CrossReference::TD_CR_IsMarshalByRefObject) != 0) - { - idxVerify = inst; + idxVerify = inst; - mbroSrc = ptr; - } + mbroSrc = ptr; } } - break; + } + break; } } } - NANOCLR_CHECK_HRESULT(appDomainDst->VerifyTypeIsLoaded( idxVerify )); + NANOCLR_CHECK_HRESULT(appDomainDst->VerifyTypeIsLoaded(idxVerify)); - if(fSimpleAssign) + if (fSimpleAssign) { - dst.Assign( src ); + dst.Assign(src); } - else if(proxySrc != NULL) + else if (proxySrc != NULL) { - //src is OBJECT->TRANSPARENT_PROXY->CLASS, and we are marshalling into 'this' appDomain - //dst is OBJECT->CLASS + // src is OBJECT->TRANSPARENT_PROXY->CLASS, and we are marshalling into 'this' appDomain + // dst is OBJECT->CLASS _ASSERTE(proxySrc->TransparentProxyAppDomain() == appDomainDst); - dst.SetObjectReference( proxySrc->TransparentProxyDereference() ); + dst.SetObjectReference(proxySrc->TransparentProxyDereference()); } - else if(mbroSrc != NULL) + else if (mbroSrc != NULL) { - //src is a MarshalByRefObject that we are marshalling outside of its AppDomain - //src is OBJECT->CLASS - //dst is OBJECT->TRANSPARENT_PROXY->CLASS + // src is a MarshalByRefObject that we are marshalling outside of its AppDomain + // src is OBJECT->CLASS + // dst is OBJECT->TRANSPARENT_PROXY->CLASS - (void)g_CLR_RT_ExecutionEngine.SetCurrentAppDomain( appDomainDst ); - CLR_RT_HeapBlock* proxyDst = g_CLR_RT_ExecutionEngine.ExtractHeapBlocksForObjects( DATATYPE_TRANSPARENT_PROXY, 0, 1 ); CHECK_ALLOCATION(proxyDst); + (void)g_CLR_RT_ExecutionEngine.SetCurrentAppDomain(appDomainDst); + CLR_RT_HeapBlock *proxyDst = + g_CLR_RT_ExecutionEngine.ExtractHeapBlocksForObjects(DATATYPE_TRANSPARENT_PROXY, 0, 1); + CHECK_ALLOCATION(proxyDst); - proxyDst->SetTransparentProxyReference( appDomainSrc, mbroSrc ); - dst.SetObjectReference( proxyDst ); + proxyDst->SetTransparentProxyReference(appDomainSrc, mbroSrc); + dst.SetObjectReference(proxyDst); } else { - CLR_RT_HeapBlock blk; blk.SetObjectReference( NULL ); - CLR_RT_ProtectFromGC gc( blk ); + CLR_RT_HeapBlock blk; + blk.SetObjectReference(NULL); + CLR_RT_ProtectFromGC gc(blk); bool fNoCompaction = CLR_EE_DBG_IS(NoCompaction); - //Need to prevent compaction between serialization/deserialization. - //Doesn't seem that currently compaction can actually occur during this time, - //but just to be safe, we should prevent it. + // Need to prevent compaction between serialization/deserialization. + // Doesn't seem that currently compaction can actually occur during this time, + // but just to be safe, we should prevent it. CLR_EE_DBG_SET(NoCompaction); - NANOCLR_CHECK_HRESULT(CLR_RT_BinaryFormatter::Serialize( blk, src, NULL, CLR_RT_BinaryFormatter::c_Flags_Marshal )); + NANOCLR_CHECK_HRESULT( + CLR_RT_BinaryFormatter::Serialize(blk, src, NULL, CLR_RT_BinaryFormatter::c_Flags_Marshal)); - (void)g_CLR_RT_ExecutionEngine.SetCurrentAppDomain( appDomainDst ); - hr = CLR_RT_BinaryFormatter::Deserialize( dst, blk, NULL, NULL, CLR_RT_BinaryFormatter::c_Flags_Marshal ); + (void)g_CLR_RT_ExecutionEngine.SetCurrentAppDomain(appDomainDst); + hr = CLR_RT_BinaryFormatter::Deserialize(dst, blk, NULL, NULL, CLR_RT_BinaryFormatter::c_Flags_Marshal); - CLR_EE_DBG_RESTORE(NoCompaction,fNoCompaction); + CLR_EE_DBG_RESTORE(NoCompaction, fNoCompaction); } NANOCLR_CLEANUP(); - (void)g_CLR_RT_ExecutionEngine.SetCurrentAppDomain( appDomainSav ); + (void)g_CLR_RT_ExecutionEngine.SetCurrentAppDomain(appDomainSav); NANOCLR_CLEANUP_END(); } -HRESULT CLR_RT_AppDomain::MarshalParameters( CLR_RT_HeapBlock* callerArgs, CLR_RT_HeapBlock* calleeArgs, int count, bool fOnReturn, CLR_RT_AppDomain* appDomainSrc ) +HRESULT CLR_RT_AppDomain::MarshalParameters( + CLR_RT_HeapBlock *callerArgs, + CLR_RT_HeapBlock *calleeArgs, + int count, + bool fOnReturn, + CLR_RT_AppDomain *appDomainSrc) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - CLR_RT_HeapBlock* src = fOnReturn ? calleeArgs : callerArgs; - CLR_RT_HeapBlock* dst = fOnReturn ? callerArgs : calleeArgs; + CLR_RT_HeapBlock *src = fOnReturn ? calleeArgs : callerArgs; + CLR_RT_HeapBlock *dst = fOnReturn ? callerArgs : calleeArgs; - while(count-- > 0) + while (count-- > 0) { CLR_DataType dtSrc = src->DataType(); CLR_DataType dtDst = dst->DataType(); - if(dtSrc == DATATYPE_BYREF || dtSrc == DATATYPE_ARRAY_BYREF) + if (dtSrc == DATATYPE_BYREF || dtSrc == DATATYPE_ARRAY_BYREF) { - CLR_RT_HeapBlock srcObj; - CLR_RT_HeapBlock dstObj; + CLR_RT_HeapBlock srcObj; + CLR_RT_HeapBlock dstObj; - if(fOnReturn) + if (fOnReturn) { - srcObj.Assign( *src->Dereference() ); + srcObj.Assign(*src->Dereference()); - NANOCLR_CHECK_HRESULT(MarshalObject( srcObj, dstObj, appDomainSrc )); + NANOCLR_CHECK_HRESULT(MarshalObject(srcObj, dstObj, appDomainSrc)); - //Move the marshaled object back into dst heapblock - if(dtDst == DATATYPE_BYREF) + // Move the marshaled object back into dst heapblock + if (dtDst == DATATYPE_BYREF) { - dst->Dereference()->Assign( dstObj ); + dst->Dereference()->Assign(dstObj); } else { - dstObj.StoreToReference( *dst, 0 ); + dstObj.StoreToReference(*dst, 0); } } - else //!fOnReturn + else //! fOnReturn { - CLR_RT_HeapBlock* dstPtr = NULL; + CLR_RT_HeapBlock *dstPtr = NULL; - if(dtSrc == DATATYPE_BYREF) + if (dtSrc == DATATYPE_BYREF) { - srcObj.Assign( *src->Dereference() ); + srcObj.Assign(*src->Dereference()); } else { - srcObj.LoadFromReference( *src ); + srcObj.LoadFromReference(*src); } - NANOCLR_CHECK_HRESULT(MarshalObject( srcObj, dstObj, appDomainSrc )); + NANOCLR_CHECK_HRESULT(MarshalObject(srcObj, dstObj, appDomainSrc)); - //Need to copy DstObj onto the heap. - dstPtr = g_CLR_RT_ExecutionEngine.ExtractHeapBlocksForObjects( DATATYPE_OBJECT, 0, 1 ); FAULT_ON_NULL(dstPtr); + // Need to copy DstObj onto the heap. + dstPtr = g_CLR_RT_ExecutionEngine.ExtractHeapBlocksForObjects(DATATYPE_OBJECT, 0, 1); + FAULT_ON_NULL(dstPtr); - _ASSERTE(c_CLR_RT_DataTypeLookup[ dstObj.DataType() ].m_sizeInBytes != CLR_RT_DataTypeLookup::c_NA); + _ASSERTE(c_CLR_RT_DataTypeLookup[dstObj.DataType()].m_sizeInBytes != CLR_RT_DataTypeLookup::c_NA); - dstPtr->Assign( dstObj ); + dstPtr->Assign(dstObj); - //Turn the OBJECT back into a BYREF - dst->SetReference( *dstPtr ); + // Turn the OBJECT back into a BYREF + dst->SetReference(*dstPtr); } } - else //Not BYREF + else // Not BYREF { - if(!fOnReturn) + if (!fOnReturn) { - NANOCLR_CHECK_HRESULT(MarshalObject( *src, *dst, appDomainSrc )); + NANOCLR_CHECK_HRESULT(MarshalObject(*src, *dst, appDomainSrc)); } } @@ -2470,43 +2604,45 @@ HRESULT CLR_RT_AppDomain::MarshalParameters( CLR_RT_HeapBlock* callerArgs, CLR_R NANOCLR_NOCLEANUP(); } - -HRESULT CLR_RT_AppDomain::GetAssemblies( CLR_RT_HeapBlock& ref ) +HRESULT CLR_RT_AppDomain::GetAssemblies(CLR_RT_HeapBlock &ref) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - int count = 0; - CLR_RT_HeapBlock* pArray = NULL; - - for(int pass=0; pass<2; pass++) + int count = 0; + CLR_RT_HeapBlock *pArray = NULL; + + for (int pass = 0; pass < 2; pass++) { - NANOCLR_FOREACH_ASSEMBLY_IN_APPDOMAIN( this ) + NANOCLR_FOREACH_ASSEMBLY_IN_APPDOMAIN(this) { - if(pass == 0) + if (pass == 0) { count++; } else { - CLR_RT_HeapBlock* hbObj; - CLR_RT_Assembly_Index idx; idx.Set( pASSM->m_idx ); + CLR_RT_HeapBlock *hbObj; + CLR_RT_Assembly_Index idx; + idx.Set(pASSM->m_idx); - NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.NewObjectFromIndex(*pArray, g_CLR_RT_WellKnownTypes.m_Assembly)); + NANOCLR_CHECK_HRESULT( + g_CLR_RT_ExecutionEngine.NewObjectFromIndex(*pArray, g_CLR_RT_WellKnownTypes.m_Assembly)); hbObj = pArray->Dereference(); - - hbObj->SetReflection( idx ); + + hbObj->SetReflection(idx); pArray++; } } NANOCLR_FOREACH_ASSEMBLY_IN_APPDOMAIN_END(); - if(pass == 0) + if (pass == 0) { - NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_Array::CreateInstance( ref, count, g_CLR_RT_WellKnownTypes.m_Assembly )); + NANOCLR_CHECK_HRESULT( + CLR_RT_HeapBlock_Array::CreateInstance(ref, count, g_CLR_RT_WellKnownTypes.m_Assembly)); - pArray = (CLR_RT_HeapBlock*)ref.DereferenceArray()->GetFirstElement(); + pArray = (CLR_RT_HeapBlock *)ref.DereferenceArray()->GetFirstElement(); } } @@ -2521,22 +2657,31 @@ bool CLR_RT_AppDomain::IsLoaded() //--// -HRESULT CLR_RT_AppDomainAssembly::CreateInstance( CLR_RT_AppDomain* appDomain, CLR_RT_Assembly* assm, CLR_RT_AppDomainAssembly*& appDomainAssembly ) +HRESULT CLR_RT_AppDomainAssembly::CreateInstance( + CLR_RT_AppDomain *appDomain, + CLR_RT_Assembly *assm, + CLR_RT_AppDomainAssembly *&appDomainAssembly) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); int size = CONVERTFROMSIZETOHEAPBLOCKS(sizeof(CLR_RT_AppDomainAssembly)) + assm->m_iStaticFields; - appDomainAssembly = EVENTCACHE_EXTRACT_NODE_AS_BLOCKS(g_CLR_RT_EventCache,CLR_RT_AppDomainAssembly,DATATYPE_APPDOMAIN_ASSEMBLY,CLR_RT_HeapBlock::HB_InitializeToZero,size); CHECK_ALLOCATION(appDomainAssembly); + appDomainAssembly = EVENTCACHE_EXTRACT_NODE_AS_BLOCKS( + g_CLR_RT_EventCache, + CLR_RT_AppDomainAssembly, + DATATYPE_APPDOMAIN_ASSEMBLY, + CLR_RT_HeapBlock::HB_InitializeToZero, + size); + CHECK_ALLOCATION(appDomainAssembly); - NANOCLR_CHECK_HRESULT(appDomainAssembly->AppDomainAssembly_Initialize( appDomain, assm )); + NANOCLR_CHECK_HRESULT(appDomainAssembly->AppDomainAssembly_Initialize(appDomain, assm)); NANOCLR_CLEANUP(); - if(FAILED(hr)) + if (FAILED(hr)) { - if(appDomainAssembly) + if (appDomainAssembly) { appDomainAssembly->DestroyInstance(); } @@ -2545,17 +2690,17 @@ HRESULT CLR_RT_AppDomainAssembly::CreateInstance( CLR_RT_AppDomain* appDomain, C NANOCLR_CLEANUP_END(); } -HRESULT CLR_RT_AppDomainAssembly::AppDomainAssembly_Initialize( CLR_RT_AppDomain* appDomain, CLR_RT_Assembly* assm ) +HRESULT CLR_RT_AppDomainAssembly::AppDomainAssembly_Initialize(CLR_RT_AppDomain *appDomain, CLR_RT_Assembly *assm) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - CLR_RT_AppDomain* appDomainSav = g_CLR_RT_ExecutionEngine.SetCurrentAppDomain( appDomain ); + CLR_RT_AppDomain *appDomainSav = g_CLR_RT_ExecutionEngine.SetCurrentAppDomain(appDomain); - m_appDomain = appDomain; - m_assembly = assm; - m_flags = 0; - m_pStaticFields = (CLR_RT_HeapBlock*)&this[ 1 ]; + m_appDomain = appDomain; + m_assembly = assm; + m_flags = 0; + m_pStaticFields = (CLR_RT_HeapBlock *)&this[1]; /* The AppDomainAssembly gets linked before it is actually initialized, for two reasons. First, it needs to be @@ -2563,25 +2708,25 @@ HRESULT CLR_RT_AppDomainAssembly::AppDomainAssembly_Initialize( CLR_RT_AppDomain loaded in the AppDomain when the static constructors are run. */ - appDomain->m_appDomainAssemblies.LinkAtBack( this ); + appDomain->m_appDomainAssemblies.LinkAtBack(this); - NANOCLR_CHECK_HRESULT(assm->Resolve_AllocateStaticFields( m_pStaticFields )); + NANOCLR_CHECK_HRESULT(assm->Resolve_AllocateStaticFields(m_pStaticFields)); - if(!CLR_EE_DBG_IS_MASK(StateInitialize,StateMask)) + if (!CLR_EE_DBG_IS_MASK(StateInitialize, StateMask)) { - //Only in the non-boot case should we do this. Otherwise, debug events can occur out of order (thread creation of the - //static constructor before thread creation of the main thread. - g_CLR_RT_ExecutionEngine.SpawnStaticConstructor( g_CLR_RT_ExecutionEngine.m_cctorThread ); + // Only in the non-boot case should we do this. Otherwise, debug events can occur out of order (thread creation + // of the static constructor before thread creation of the main thread. + g_CLR_RT_ExecutionEngine.SpawnStaticConstructor(g_CLR_RT_ExecutionEngine.m_cctorThread); } NANOCLR_CLEANUP(); - if(FAILED(hr)) + if (FAILED(hr)) { Unlink(); } - g_CLR_RT_ExecutionEngine.SetCurrentAppDomain( appDomainSav ); + g_CLR_RT_ExecutionEngine.SetCurrentAppDomain(appDomainSav); NANOCLR_CLEANUP_END(); } @@ -2591,155 +2736,160 @@ void CLR_RT_AppDomainAssembly::DestroyInstance() NATIVE_PROFILE_CLR_CORE(); Unlink(); - g_CLR_RT_EventCache.Append_Node( this ); + g_CLR_RT_EventCache.Append_Node(this); } void CLR_RT_AppDomainAssembly::Relocate() { NATIVE_PROFILE_CLR_CORE(); - CLR_RT_GarbageCollector::Heap_Relocate( m_pStaticFields, m_assembly->m_iStaticFields ); + CLR_RT_GarbageCollector::Heap_Relocate(m_pStaticFields, m_assembly->m_iStaticFields); } -#endif //NANOCLR_APPDOMAINS +#endif // NANOCLR_APPDOMAINS //--// - struct TypeIndexLookup { - const char* nameSpace; - const char* name; - CLR_RT_TypeDef_Index* ptr; + const char *nameSpace; + const char *name; + CLR_RT_TypeDef_Index *ptr; }; -static const TypeIndexLookup c_TypeIndexLookup[] = -{ -#define TIL(ns,nm,fld) { ns, nm, &g_CLR_RT_WellKnownTypes.fld } - TIL( "System" , "Boolean" , m_Boolean ), - TIL( "System" , "Char" , m_Char ), - TIL( "System" , "SByte" , m_Int8 ), - TIL( "System" , "Byte" , m_UInt8 ), - TIL( "System" , "Int16" , m_Int16 ), - TIL( "System" , "UInt16" , m_UInt16 ), - TIL( "System" , "Int32" , m_Int32 ), - TIL( "System" , "UInt32" , m_UInt32 ), - TIL( "System" , "Int64" , m_Int64 ), - TIL( "System" , "UInt64" , m_UInt64 ), - TIL( "System" , "Single" , m_Single ), - TIL( "System" , "Double" , m_Double ), - TIL( "System" , "DateTime" , m_DateTime ), - TIL( "System" , "TimeSpan" , m_TimeSpan ), - TIL( "System" , "String" , m_String ), - - TIL( "System" , "Void" , m_Void ), - TIL( "System" , "Object" , m_Object ), - TIL( "System" , "ValueType" , m_ValueType ), - TIL( "System" , "Enum" , m_Enum ), - - TIL( "System" , "AppDomainUnloadedException" , m_AppDomainUnloadedException ), - TIL( "System" , "ArgumentNullException" , m_ArgumentNullException ), - TIL( "System" , "ArgumentException" , m_ArgumentException ), - TIL( "System" , "ArgumentOutOfRangeException" , m_ArgumentOutOfRangeException ), - TIL( "System" , "Exception" , m_Exception ), - TIL( "System" , "IndexOutOfRangeException" , m_IndexOutOfRangeException ), - TIL( "System" , "InvalidCastException" , m_InvalidCastException ), - TIL( "System" , "InvalidOperationException" , m_InvalidOperationException ), - TIL( "System" , "NotSupportedException" , m_NotSupportedException ), - TIL( "System" , "NotImplementedException" , m_NotImplementedException ), - TIL( "System" , "NullReferenceException" , m_NullReferenceException ), - TIL( "System" , "OutOfMemoryException" , m_OutOfMemoryException ), - TIL( "System" , "ObjectDisposedException" , m_ObjectDisposedException ), - TIL( "System.Threading" , "ThreadAbortException" , m_ThreadAbortException ), - TIL( "nanoFramework.Runtime.Native" , "ConstraintException" , m_ConstraintException ), - - TIL( "System" , "Delegate" , m_Delegate ), - TIL( "System" , "MulticastDelegate" , m_MulticastDelegate ), - - TIL( "System" , "Array" , m_Array ), - TIL( "System.Collections" , "ArrayList" , m_ArrayList ), - TIL( "System" , "ICloneable" , m_ICloneable ), - TIL( "System.Collections" , "IList" , m_IList ), - - TIL( "System.Reflection" , "Assembly" , m_Assembly ), - TIL( "System" , "Type" , m_TypeStatic ), - TIL( "System" , "RuntimeType" , m_Type ), - TIL( "System.Reflection" , "RuntimeConstructorInfo" , m_ConstructorInfo ), - TIL( "System.Reflection" , "RuntimeMethodInfo" , m_MethodInfo ), - TIL( "System.Reflection" , "RuntimeFieldInfo" , m_FieldInfo ), - - TIL( "System" , "WeakReference" , m_WeakReference ), - - TIL( "Microsoft.SPOT" , "SerializationHintsAttribute" , m_SerializationHintsAttribute ), - - TIL( "Microsoft.SPOT.Hardware" , "WatchdogException" , m_WatchdogException ), - - TIL( "System.Net.NetworkInformation" , "NetworkInterface" , m_NetworkInterface ), - TIL( "System.Net.NetworkInformation" , "Wireless80211Configuration" , m_Wireless80211Configuration ), - TIL( "System.Net.NetworkInformation" , "WirelessAPConfiguration" , m_WirelessAPConfiguration ), - TIL( "System.Net.NetworkInformation" , "WirelessAPStation" , m_WirelessAPStation ), +static const TypeIndexLookup c_TypeIndexLookup[] = { +#define TIL(ns, nm, fld) \ + { \ + ns, nm, &g_CLR_RT_WellKnownTypes.fld \ + } + TIL("System", "Boolean", m_Boolean), + TIL("System", "Char", m_Char), + TIL("System", "SByte", m_Int8), + TIL("System", "Byte", m_UInt8), + TIL("System", "Int16", m_Int16), + TIL("System", "UInt16", m_UInt16), + TIL("System", "Int32", m_Int32), + TIL("System", "UInt32", m_UInt32), + TIL("System", "Int64", m_Int64), + TIL("System", "UInt64", m_UInt64), + TIL("System", "Single", m_Single), + TIL("System", "Double", m_Double), + TIL("System", "DateTime", m_DateTime), + TIL("System", "TimeSpan", m_TimeSpan), + TIL("System", "String", m_String), + + TIL("System", "Void", m_Void), + TIL("System", "Object", m_Object), + TIL("System", "ValueType", m_ValueType), + TIL("System", "Enum", m_Enum), + + TIL("System", "AppDomainUnloadedException", m_AppDomainUnloadedException), + TIL("System", "ArgumentNullException", m_ArgumentNullException), + TIL("System", "ArgumentException", m_ArgumentException), + TIL("System", "ArgumentOutOfRangeException", m_ArgumentOutOfRangeException), + TIL("System", "Exception", m_Exception), + TIL("System", "IndexOutOfRangeException", m_IndexOutOfRangeException), + TIL("System", "InvalidCastException", m_InvalidCastException), + TIL("System", "InvalidOperationException", m_InvalidOperationException), + TIL("System", "NotSupportedException", m_NotSupportedException), + TIL("System", "NotImplementedException", m_NotImplementedException), + TIL("System", "NullReferenceException", m_NullReferenceException), + TIL("System", "OutOfMemoryException", m_OutOfMemoryException), + TIL("System", "ObjectDisposedException", m_ObjectDisposedException), + TIL("System.Threading", "ThreadAbortException", m_ThreadAbortException), + TIL("nanoFramework.Runtime.Native", "ConstraintException", m_ConstraintException), + + TIL("System", "Delegate", m_Delegate), + TIL("System", "MulticastDelegate", m_MulticastDelegate), + + TIL("System", "Array", m_Array), + TIL("System.Collections", "ArrayList", m_ArrayList), + TIL("System", "ICloneable", m_ICloneable), + TIL("System.Collections", "IList", m_IList), + + TIL("System.Reflection", "Assembly", m_Assembly), + TIL("System", "Type", m_TypeStatic), + TIL("System", "RuntimeType", m_Type), + TIL("System.Reflection", "RuntimeConstructorInfo", m_ConstructorInfo), + TIL("System.Reflection", "RuntimeMethodInfo", m_MethodInfo), + TIL("System.Reflection", "RuntimeFieldInfo", m_FieldInfo), + + TIL("System", "WeakReference", m_WeakReference), + + TIL("Microsoft.SPOT", "SerializationHintsAttribute", m_SerializationHintsAttribute), + + TIL("Microsoft.SPOT.Hardware", "WatchdogException", m_WatchdogException), + + TIL("System.Net.NetworkInformation", "NetworkInterface", m_NetworkInterface), + TIL("System.Net.NetworkInformation", "Wireless80211Configuration", m_Wireless80211Configuration), + TIL("System.Net.NetworkInformation", "WirelessAPConfiguration", m_WirelessAPConfiguration), + TIL("System.Net.NetworkInformation", "WirelessAPStation", m_WirelessAPStation), #if defined(NANOCLR_APPDOMAINS) - TIL( "System" , "AppDomain" , m_AppDomain ), - TIL( "System" , "MarshalByRefObject" , m_MarshalByRefObject ), + TIL("System", "AppDomain", m_AppDomain), + TIL("System", "MarshalByRefObject", m_MarshalByRefObject), #endif - TIL( "System.Threading" , "Thread" , m_Thread ), - TIL( "System.Resources" , "ResourceManager" , m_ResourceManager ), + TIL("System.Threading", "Thread", m_Thread), + TIL("System.Resources", "ResourceManager", m_ResourceManager), - TIL( "System.Net.Sockets" , "SocketException" , m_SocketException ), + TIL("System.Net.Sockets", "SocketException", m_SocketException), - TIL( "Windows.Devices.I2c" , "I2cTransferResult" , m_I2cTransferResult ), + TIL("Windows.Devices.I2c", "I2cTransferResult", m_I2cTransferResult), + +#if (HAL_USE_ESP32_RMT_OPTION == TRUE) + TIL("nanoFramework.Hardware.Esp32.Rmt", "RmtCommand", m_RmtCommand), +#endif #undef TIL }; - //--// - struct MethodIndexLookup { - const char* name; - CLR_RT_TypeDef_Index* type; - CLR_RT_MethodDef_Index* method; + const char *name; + CLR_RT_TypeDef_Index *type; + CLR_RT_MethodDef_Index *method; }; -static const MethodIndexLookup c_MethodIndexLookup[] = -{ - #define MIL(nm,type,method) { nm, &g_CLR_RT_WellKnownTypes.type, &g_CLR_RT_WellKnownMethods.method } +static const MethodIndexLookup c_MethodIndexLookup[] = { +#define MIL(nm, type, method) \ + { \ + nm, &g_CLR_RT_WellKnownTypes.type, &g_CLR_RT_WellKnownMethods.method \ + } - MIL( "GetObjectFromId" , m_ResourceManager, m_ResourceManager_GetObjectFromId ), - MIL( "GetObjectChunkFromId", m_ResourceManager, m_ResourceManager_GetObjectChunkFromId ), + MIL("GetObjectFromId", m_ResourceManager, m_ResourceManager_GetObjectFromId), + MIL("GetObjectChunkFromId", m_ResourceManager, m_ResourceManager_GetObjectChunkFromId), - #undef MIL +#undef MIL }; void CLR_RT_Assembly::Resolve_TypeDef() { NATIVE_PROFILE_CLR_CORE(); - const TypeIndexLookup* tilOuterClass = NULL; - const TypeIndexLookup* til = c_TypeIndexLookup; + const TypeIndexLookup *tilOuterClass = NULL; + const TypeIndexLookup *til = c_TypeIndexLookup; - for(size_t i=0; iptr; + CLR_RT_TypeDef_Index &dst = *til->ptr; - if(NANOCLR_INDEX_IS_INVALID(dst)) + if (NANOCLR_INDEX_IS_INVALID(dst)) { - if(til->nameSpace == NULL) + if (til->nameSpace == NULL) { - if(tilOuterClass) + if (tilOuterClass) { - FindTypeDef( til->name, tilOuterClass->ptr->Type(), dst ); + FindTypeDef(til->name, tilOuterClass->ptr->Type(), dst); } } else { - FindTypeDef( til->name, til->nameSpace, dst ); + FindTypeDef(til->name, til->nameSpace, dst); } } - if(til->nameSpace != NULL) + if (til->nameSpace != NULL) { tilOuterClass = til; } @@ -2749,29 +2899,30 @@ void CLR_RT_Assembly::Resolve_TypeDef() void CLR_RT_Assembly::Resolve_MethodDef() { NATIVE_PROFILE_CLR_CORE(); - const CLR_RECORD_METHODDEF* md = GetMethodDef( 0 ); + const CLR_RECORD_METHODDEF *md = GetMethodDef(0); - for(int i=0; itype; - CLR_RT_MethodDef_Index& idxMethod = *mil->method; + CLR_RT_TypeDef_Index &idxType = *mil->type; + CLR_RT_MethodDef_Index &idxMethod = *mil->method; - if(NANOCLR_INDEX_IS_VALID(idxType) && NANOCLR_INDEX_IS_INVALID(idxMethod)) + if (NANOCLR_INDEX_IS_VALID(idxType) && NANOCLR_INDEX_IS_INVALID(idxMethod)) { CLR_RT_TypeDef_Instance instType; - _SIDE_ASSERTE(instType.InitializeFromIndex( idxType )); + _SIDE_ASSERTE(instType.InitializeFromIndex(idxType)); - if(instType.m_assm == this) + if (instType.m_assm == this) { - if(!strcmp( GetString(md->name), mil->name )) + if (!strcmp(GetString(md->name), mil->name)) { idxMethod.m_data = idx.m_data; } @@ -2779,27 +2930,27 @@ void CLR_RT_Assembly::Resolve_MethodDef() } } - if(md->flags & CLR_RECORD_METHODDEF::MD_EntryPoint) + if (md->flags & CLR_RECORD_METHODDEF::MD_EntryPoint) { g_CLR_RT_TypeSystem.m_entryPoint = idx; } } } -HRESULT CLR_RT_Assembly::Resolve_AllocateStaticFields( CLR_RT_HeapBlock* pStaticFields ) +HRESULT CLR_RT_Assembly::Resolve_AllocateStaticFields(CLR_RT_HeapBlock *pStaticFields) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - const CLR_RECORD_FIELDDEF* fd = GetFieldDef( 0 ); + const CLR_RECORD_FIELDDEF *fd = GetFieldDef(0); - for(int i=0; iflags & CLR_RECORD_FIELDDEF::FD_Static) + if (fd->flags & CLR_RECORD_FIELDDEF::FD_Static) { - CLR_RT_FieldDef_CrossReference& res = m_pCrossReference_FieldDef[ i ]; + CLR_RT_FieldDef_CrossReference &res = m_pCrossReference_FieldDef[i]; - NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.InitializeReference( pStaticFields[ res.m_offset ], fd, this )); + NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.InitializeReference(pStaticFields[res.m_offset], fd, this)); } } @@ -2811,54 +2962,54 @@ HRESULT CLR_RT_Assembly::PrepareForExecution() NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - if((m_flags & CLR_RT_Assembly::PreparingForExecution) != 0) + if ((m_flags & CLR_RT_Assembly::PreparingForExecution) != 0) { - //Circular dependency + // Circular dependency _ASSERTE(false); NANOCLR_MSG_SET_AND_LEAVE(CLR_E_FAIL, L"Failed to prepare type system for execution\n"); } - if((m_flags & CLR_RT_Assembly::PreparedForExecution) == 0) + if ((m_flags & CLR_RT_Assembly::PreparedForExecution) == 0) { int i; m_flags |= CLR_RT_Assembly::PreparingForExecution; - ITERATE_THROUGH_RECORDS(this,i,AssemblyRef,ASSEMBLYREF) + ITERATE_THROUGH_RECORDS(this, i, AssemblyRef, ASSEMBLYREF) { _ASSERTE(dst->m_target != NULL); - if(dst->m_target != NULL) + if (dst->m_target != NULL) { NANOCLR_CHECK_HRESULT(dst->m_target->PrepareForExecution()); } } - if(m_header->patchEntryOffset != 0xFFFFFFFF) + if (m_header->patchEntryOffset != 0xFFFFFFFF) { - CLR_PMETADATA ptr = GetResourceData( m_header->patchEntryOffset ); + CLR_PMETADATA ptr = GetResourceData(m_header->patchEntryOffset); #if defined(WIN32) - CLR_Debug::Printf( "Simulating jump into patch code...\r\n" ); + CLR_Debug::Printf("Simulating jump into patch code...\r\n"); #else ((void (*)())ptr)(); #endif } #if defined(NANOCLR_APPDOMAINS) - //Temporary solution. All Assemblies get added to the current AppDomain - //Which assemblies get loaded at boot, and when assemblies get added to AppDomain at runtime is - //not yet determined/implemented + // Temporary solution. All Assemblies get added to the current AppDomain + // Which assemblies get loaded at boot, and when assemblies get added to AppDomain at runtime is + // not yet determined/implemented - NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.GetCurrentAppDomain()->LoadAssembly( this )); + NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.GetCurrentAppDomain()->LoadAssembly(this)); #endif } NANOCLR_CLEANUP(); - //Only try once. If this fails, then what? - m_flags |= CLR_RT_Assembly::PreparedForExecution; + // Only try once. If this fails, then what? + m_flags |= CLR_RT_Assembly::PreparedForExecution; m_flags &= ~CLR_RT_Assembly::PreparingForExecution; NANOCLR_CLEANUP_END(); @@ -2869,33 +3020,33 @@ HRESULT CLR_RT_Assembly::PrepareForExecution() CLR_UINT32 CLR_RT_Assembly::ComputeAssemblyHash() { NATIVE_PROFILE_CLR_CORE(); - return m_header->ComputeAssemblyHash( m_szName, m_header->version ); + return m_header->ComputeAssemblyHash(m_szName, m_header->version); } -CLR_UINT32 CLR_RT_Assembly::ComputeAssemblyHash( const CLR_RECORD_ASSEMBLYREF* ar ) +CLR_UINT32 CLR_RT_Assembly::ComputeAssemblyHash(const CLR_RECORD_ASSEMBLYREF *ar) { NATIVE_PROFILE_CLR_CORE(); - return m_header->ComputeAssemblyHash( GetString( ar->name ), ar->version ); + return m_header->ComputeAssemblyHash(GetString(ar->name), ar->version); } //--// -bool CLR_RT_Assembly::FindTypeDef( const char* name, const char* nameSpace, CLR_RT_TypeDef_Index& idx ) +bool CLR_RT_Assembly::FindTypeDef(const char *name, const char *nameSpace, CLR_RT_TypeDef_Index &idx) { NATIVE_PROFILE_CLR_CORE(); - const CLR_RECORD_TYPEDEF* target = GetTypeDef( 0 ); - int tblSize = m_pTablesSize[ TBL_TypeDef ]; + const CLR_RECORD_TYPEDEF *target = GetTypeDef(0); + int tblSize = m_pTablesSize[TBL_TypeDef]; - for(int i=0; ienclosingType == CLR_EmptyIndex) + if (target->enclosingType == CLR_EmptyIndex) { - const char* szNameSpace = GetString( target->nameSpace ); - const char* szName = GetString( target->name ); + const char *szNameSpace = GetString(target->nameSpace); + const char *szName = GetString(target->name); - if(!strcmp( szName, name ) && !strcmp( szNameSpace, nameSpace )) + if (!strcmp(szName, name) && !strcmp(szNameSpace, nameSpace)) { - idx.Set( m_idx, i ); + idx.Set(m_idx, i); return true; } @@ -2907,21 +3058,21 @@ bool CLR_RT_Assembly::FindTypeDef( const char* name, const char* nameSpace, CLR_ return false; } -bool CLR_RT_Assembly::FindTypeDef( const char* name, CLR_IDX scope, CLR_RT_TypeDef_Index& idx ) +bool CLR_RT_Assembly::FindTypeDef(const char *name, CLR_IDX scope, CLR_RT_TypeDef_Index &idx) { NATIVE_PROFILE_CLR_CORE(); - const CLR_RECORD_TYPEDEF* target = GetTypeDef( 0 ); - int tblSize = m_pTablesSize[ TBL_TypeDef ]; + const CLR_RECORD_TYPEDEF *target = GetTypeDef(0); + int tblSize = m_pTablesSize[TBL_TypeDef]; - for(int i=0; ienclosingType == scope) + if (target->enclosingType == scope) { - const char* szName = GetString( target->name ); + const char *szName = GetString(target->name); - if(!strcmp( szName, name )) + if (!strcmp(szName, name)) { - idx.Set( m_idx, i ); + idx.Set(m_idx, i); return true; } @@ -2933,21 +3084,22 @@ bool CLR_RT_Assembly::FindTypeDef( const char* name, CLR_IDX scope, CLR_RT_TypeD return false; } -bool CLR_RT_Assembly::FindTypeDef( CLR_UINT32 hash, CLR_RT_TypeDef_Index& idx ) +bool CLR_RT_Assembly::FindTypeDef(CLR_UINT32 hash, CLR_RT_TypeDef_Index &idx) { NATIVE_PROFILE_CLR_CORE(); - CLR_RT_TypeDef_CrossReference* p = m_pCrossReference_TypeDef; - CLR_UINT32 tblSize = m_pTablesSize[ TBL_TypeDef ]; - CLR_UINT32 i; + CLR_RT_TypeDef_CrossReference *p = m_pCrossReference_TypeDef; + CLR_UINT32 tblSize = m_pTablesSize[TBL_TypeDef]; + CLR_UINT32 i; - for(i=0; im_hash == hash) break; + if (p->m_hash == hash) + break; } - if(i != tblSize) + if (i != tblSize) { - idx.Set( m_idx, i ); + idx.Set(m_idx, i); return true; } @@ -2961,26 +3113,36 @@ bool CLR_RT_Assembly::FindTypeDef( CLR_UINT32 hash, CLR_RT_TypeDef_Index& idx ) //--// -static bool local_FindFieldDef( CLR_RT_Assembly* assm, CLR_UINT32 first, CLR_UINT32 num, const char* szText, CLR_RT_Assembly* base, CLR_IDX sig, CLR_RT_FieldDef_Index& res ) +static bool local_FindFieldDef( + CLR_RT_Assembly *assm, + CLR_UINT32 first, + CLR_UINT32 num, + const char *szText, + CLR_RT_Assembly *base, + CLR_IDX sig, + CLR_RT_FieldDef_Index &res) { NATIVE_PROFILE_CLR_CORE(); - const CLR_RECORD_FIELDDEF* fd = assm->GetFieldDef( first ); + const CLR_RECORD_FIELDDEF *fd = assm->GetFieldDef(first); - for(CLR_UINT32 i=0; iGetString( fd->name ); + const char *fieldName = assm->GetString(fd->name); - if(!strcmp( fieldName, szText )) + if (!strcmp(fieldName, szText)) { - if(base) + if (base) { - CLR_RT_SignatureParser parserLeft ; parserLeft .Initialize_FieldDef( assm, fd ); - CLR_RT_SignatureParser parserRight; parserRight.Initialize_FieldDef( base, base->GetSignature( sig ) ); + CLR_RT_SignatureParser parserLeft; + parserLeft.Initialize_FieldDef(assm, fd); + CLR_RT_SignatureParser parserRight; + parserRight.Initialize_FieldDef(base, base->GetSignature(sig)); - if(CLR_RT_TypeSystem::MatchSignature( parserLeft, parserRight ) == false) continue; + if (CLR_RT_TypeSystem::MatchSignature(parserLeft, parserRight) == false) + continue; } - res.Set( assm->m_idx, first + i ); + res.Set(assm->m_idx, first + i); return true; } @@ -2991,43 +3153,57 @@ static bool local_FindFieldDef( CLR_RT_Assembly* assm, CLR_UINT32 first, CLR_UIN return false; } -bool CLR_RT_Assembly::FindFieldDef( const CLR_RECORD_TYPEDEF* td, const char* name, CLR_RT_Assembly* base, CLR_IDX sig, CLR_RT_FieldDef_Index& idx ) +bool CLR_RT_Assembly::FindFieldDef( + const CLR_RECORD_TYPEDEF *td, + const char *name, + CLR_RT_Assembly *base, + CLR_IDX sig, + CLR_RT_FieldDef_Index &idx) { NATIVE_PROFILE_CLR_CORE(); - if(local_FindFieldDef( this, td->iFields_First, td->iFields_Num, name, base, sig, idx )) return true; - if(local_FindFieldDef( this, td->sFields_First, td->sFields_Num, name, base, sig, idx )) return true; + if (local_FindFieldDef(this, td->iFields_First, td->iFields_Num, name, base, sig, idx)) + return true; + if (local_FindFieldDef(this, td->sFields_First, td->sFields_Num, name, base, sig, idx)) + return true; idx.Clear(); return false; } -bool CLR_RT_Assembly::FindMethodDef( const CLR_RECORD_TYPEDEF* td, const char* name, CLR_RT_Assembly* base, CLR_SIG sig, CLR_RT_MethodDef_Index& idx ) +bool CLR_RT_Assembly::FindMethodDef( + const CLR_RECORD_TYPEDEF *td, + const char *name, + CLR_RT_Assembly *base, + CLR_SIG sig, + CLR_RT_MethodDef_Index &idx) { NATIVE_PROFILE_CLR_CORE(); - int i; - int num = td->vMethods_Num + td->iMethods_Num + td->sMethods_Num; - const CLR_RECORD_METHODDEF* md = GetMethodDef( td->methods_First ); + int i; + int num = td->vMethods_Num + td->iMethods_Num + td->sMethods_Num; + const CLR_RECORD_METHODDEF *md = GetMethodDef(td->methods_First); - for(i=0; iname ); + const char *methodName = GetString(md->name); - if(!strcmp( methodName, name )) + if (!strcmp(methodName, name)) { bool fMatch = true; - if(CLR_SIG_INVALID != sig) + if (CLR_SIG_INVALID != sig) { - CLR_RT_SignatureParser parserLeft ; parserLeft .Initialize_MethodSignature( this, md ); - CLR_RT_SignatureParser parserRight; parserRight.Initialize_MethodSignature( base, base->GetSignature( sig ) ); + CLR_RT_SignatureParser parserLeft; + parserLeft.Initialize_MethodSignature(this, md); + CLR_RT_SignatureParser parserRight; + parserRight.Initialize_MethodSignature(base, base->GetSignature(sig)); - fMatch = CLR_RT_TypeSystem::MatchSignature( parserLeft, parserRight ); + fMatch = CLR_RT_TypeSystem::MatchSignature(parserLeft, parserRight); } - if(fMatch) + if (fMatch) { - idx.Set( m_idx, i + td->methods_First ); + idx.Set(m_idx, i + td->methods_First); return true; } @@ -3041,27 +3217,28 @@ bool CLR_RT_Assembly::FindMethodDef( const CLR_RECORD_TYPEDEF* td, const char* n //////////////////////////////////////////////////////////////////////////////////////////////////// -bool CLR_RT_Assembly::FindMethodBoundaries( CLR_IDX i, CLR_OFFSET& start, CLR_OFFSET& end ) +bool CLR_RT_Assembly::FindMethodBoundaries(CLR_IDX i, CLR_OFFSET &start, CLR_OFFSET &end) { NATIVE_PROFILE_CLR_CORE(); - const CLR_RECORD_METHODDEF* p = GetMethodDef( i ); + const CLR_RECORD_METHODDEF *p = GetMethodDef(i); - if(p->RVA == CLR_EmptyIndex) return false; + if (p->RVA == CLR_EmptyIndex) + return false; start = p->RVA; - while(true) + while (true) { p++; i++; - if(i == m_pTablesSize[ TBL_MethodDef ]) + if (i == m_pTablesSize[TBL_MethodDef]) { - end = m_pTablesSize[ TBL_ByteCode ]; + end = m_pTablesSize[TBL_ByteCode]; break; } - if(p->RVA != CLR_EmptyIndex) + if (p->RVA != CLR_EmptyIndex) { end = p->RVA; break; @@ -3071,18 +3248,18 @@ bool CLR_RT_Assembly::FindMethodBoundaries( CLR_IDX i, CLR_OFFSET& start, CLR_OF return true; } -bool CLR_RT_Assembly::FindNextStaticConstructor( CLR_RT_MethodDef_Index& idx ) +bool CLR_RT_Assembly::FindNextStaticConstructor(CLR_RT_MethodDef_Index &idx) { NATIVE_PROFILE_CLR_CORE(); _ASSERTE(m_idx == idx.Assembly()); - for(int i=idx.Method(); iflags & CLR_RECORD_METHODDEF::MD_StaticConstructor) + if (md->flags & CLR_RECORD_METHODDEF::MD_StaticConstructor) { return true; } @@ -3099,46 +3276,47 @@ HRESULT CLR_RT_Assembly::Resolve_ComputeHashes() NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - const CLR_RECORD_TYPEDEF* src = GetTypeDef( 0 ); - CLR_RT_TypeDef_CrossReference* dst = m_pCrossReference_TypeDef; + const CLR_RECORD_TYPEDEF *src = GetTypeDef(0); + CLR_RT_TypeDef_CrossReference *dst = m_pCrossReference_TypeDef; - for(int i=0; iGetFieldDef( target->iFields_First ); + const CLR_RECORD_TYPEDEF *target = inst.m_target; + const CLR_RECORD_FIELDDEF *fd = inst.m_assm->GetFieldDef(target->iFields_First); - for(int j=0; jiFields_Num; j++, fd++) + for (int j = 0; j < target->iFields_Num; j++, fd++) { - if((fd->flags & CLR_RECORD_FIELDDEF::FD_NotSerialized) == 0) + if ((fd->flags & CLR_RECORD_FIELDDEF::FD_NotSerialized) == 0) { - CLR_RT_SignatureParser parser; parser.Initialize_FieldDef( inst.m_assm, fd ); + CLR_RT_SignatureParser parser; + parser.Initialize_FieldDef(inst.m_assm, fd); CLR_RT_SignatureParser::Element res; - NANOCLR_CHECK_HRESULT(parser.Advance( res )); + NANOCLR_CHECK_HRESULT(parser.Advance(res)); - while(res.m_levels-- > 0) + while (res.m_levels-- > 0) { - hash = ComputeHashForType( DATATYPE_SZARRAY, hash ); + hash = ComputeHashForType(DATATYPE_SZARRAY, hash); } - hash = ComputeHashForType( res.m_dt, hash ); + hash = ComputeHashForType(res.m_dt, hash); - if( (res.m_dt == DATATYPE_VALUETYPE) || - (res.m_dt == DATATYPE_CLASS)) + if ((res.m_dt == DATATYPE_VALUETYPE) || (res.m_dt == DATATYPE_CLASS)) { - hash = ComputeHashForName( res.m_cls, hash ); + hash = ComputeHashForName(res.m_cls, hash); } - const char* fieldName = inst.m_assm->GetString( fd->name ); + const char *fieldName = inst.m_assm->GetString(fd->name); - hash = SUPPORT_ComputeCRC( fieldName, (CLR_UINT32)hal_strlen_s(fieldName), hash ); + hash = SUPPORT_ComputeCRC(fieldName, (CLR_UINT32)hal_strlen_s(fieldName), hash); } } @@ -3151,47 +3329,47 @@ HRESULT CLR_RT_Assembly::Resolve_ComputeHashes() NANOCLR_NOCLEANUP(); } -CLR_UINT32 CLR_RT_Assembly::ComputeHashForName( const CLR_RT_TypeDef_Index& td, CLR_UINT32 hash ) +CLR_UINT32 CLR_RT_Assembly::ComputeHashForName(const CLR_RT_TypeDef_Index &td, CLR_UINT32 hash) { NATIVE_PROFILE_CLR_CORE(); - char rgBuffer[ 512 ]; - char* szBuffer = rgBuffer; - size_t iBuffer = MAXSTRLEN(rgBuffer); + char rgBuffer[512]; + char *szBuffer = rgBuffer; + size_t iBuffer = MAXSTRLEN(rgBuffer); - g_CLR_RT_TypeSystem.BuildTypeName( td, szBuffer, iBuffer ); + g_CLR_RT_TypeSystem.BuildTypeName(td, szBuffer, iBuffer); - CLR_UINT32 hashPost = SUPPORT_ComputeCRC( rgBuffer, (int)(MAXSTRLEN(rgBuffer) - iBuffer), hash ); + CLR_UINT32 hashPost = SUPPORT_ComputeCRC(rgBuffer, (int)(MAXSTRLEN(rgBuffer) - iBuffer), hash); return hashPost; } -CLR_UINT32 CLR_RT_Assembly::ComputeHashForType( CLR_DataType et, CLR_UINT32 hash ) +CLR_UINT32 CLR_RT_Assembly::ComputeHashForType(CLR_DataType et, CLR_UINT32 hash) { NATIVE_PROFILE_CLR_CORE(); - CLR_UINT8 val = (CLR_UINT8)CLR_RT_TypeSystem::MapDataTypeToElementType( et ); + CLR_UINT8 val = (CLR_UINT8)CLR_RT_TypeSystem::MapDataTypeToElementType(et); - CLR_UINT32 hashPost = SUPPORT_ComputeCRC( &val, sizeof(val), hash ); + CLR_UINT32 hashPost = SUPPORT_ComputeCRC(&val, sizeof(val), hash); return hashPost; } //--// -CLR_RT_HeapBlock* CLR_RT_Assembly::GetStaticField( const int index ) +CLR_RT_HeapBlock *CLR_RT_Assembly::GetStaticField(const int index) { NATIVE_PROFILE_CLR_CORE(); #if defined(NANOCLR_APPDOMAINS) - CLR_RT_AppDomainAssembly* adAssm = g_CLR_RT_ExecutionEngine.GetCurrentAppDomain()->FindAppDomainAssembly( this ); + CLR_RT_AppDomainAssembly *adAssm = g_CLR_RT_ExecutionEngine.GetCurrentAppDomain()->FindAppDomainAssembly(this); _ASSERTE(adAssm); - return &adAssm->m_pStaticFields[ index ]; - + return &adAssm->m_pStaticFields[index]; + #else - return &m_pStaticFields[ index ]; + return &m_pStaticFields[index]; #endif } @@ -3203,13 +3381,13 @@ void CLR_RT_Assembly::Relocate() NATIVE_PROFILE_CLR_CORE(); #if !defined(NANOCLR_APPDOMAINS) - CLR_RT_GarbageCollector::Heap_Relocate( m_pStaticFields, m_iStaticFields ); + CLR_RT_GarbageCollector::Heap_Relocate(m_pStaticFields, m_iStaticFields); #endif - CLR_RT_GarbageCollector::Heap_Relocate( (void**)&m_header ); - CLR_RT_GarbageCollector::Heap_Relocate( (void**)&m_szName ); - CLR_RT_GarbageCollector::Heap_Relocate( (void**)&m_pFile ); - CLR_RT_GarbageCollector::Heap_Relocate( (void**)&m_nativeCode ); + CLR_RT_GarbageCollector::Heap_Relocate((void **)&m_header); + CLR_RT_GarbageCollector::Heap_Relocate((void **)&m_szName); + CLR_RT_GarbageCollector::Heap_Relocate((void **)&m_pFile); + CLR_RT_GarbageCollector::Heap_Relocate((void **)&m_nativeCode); } //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -3237,7 +3415,7 @@ void CLR_RT_TypeSystem::TypeSystem_Cleanup() //--// -void CLR_RT_TypeSystem::Link( CLR_RT_Assembly* assm ) +void CLR_RT_TypeSystem::Link(CLR_RT_Assembly *assm) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_FOREACH_ASSEMBLY_NULL(*this) @@ -3246,56 +3424,56 @@ void CLR_RT_TypeSystem::Link( CLR_RT_Assembly* assm ) assm->m_idx = idx; - PostLinkageProcessing( assm ); + PostLinkageProcessing(assm); - if(m_assembliesMax < idx) m_assembliesMax = idx; + if (m_assembliesMax < idx) + m_assembliesMax = idx; return; } NANOCLR_FOREACH_ASSEMBLY_NULL_END(); } -void CLR_RT_TypeSystem::PostLinkageProcessing( CLR_RT_Assembly* assm ) +void CLR_RT_TypeSystem::PostLinkageProcessing(CLR_RT_Assembly *assm) { NATIVE_PROFILE_CLR_CORE(); - if(!strcmp( assm->m_szName, "mscorlib" )) + if (!strcmp(assm->m_szName, "mscorlib")) { m_assemblyMscorlib = assm; } - if(!strcmp( assm->m_szName, "nanoFramework.Runtime.Native" )) + if (!strcmp(assm->m_szName, "nanoFramework.Runtime.Native")) { m_assemblyNative = assm; } } -CLR_RT_Assembly* CLR_RT_TypeSystem::FindAssembly( const char* szName, const CLR_RECORD_VERSION* ver, bool fExact ) +CLR_RT_Assembly *CLR_RT_TypeSystem::FindAssembly(const char *szName, const CLR_RECORD_VERSION *ver, bool fExact) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_FOREACH_ASSEMBLY(*this) { - if(!strcmp(pASSM->m_szName, szName)) + if (!strcmp(pASSM->m_szName, szName)) { // if there is no version information, anything goes - if(NULL == ver) + if (NULL == ver) { return pASSM; } // exact match requested: must take into accoutn all numbers in the version - else if(fExact) + else if (fExact) { - if(0 == memcmp( &pASSM->m_header->version, ver, sizeof(*ver) )) + if (0 == memcmp(&pASSM->m_header->version, ver, sizeof(*ver))) { return pASSM; } } - // exact match was NOT required but still there version information, - // we will enforce only the first two number because (by convention) + // exact match was NOT required but still there version information, + // we will enforce only the first two number because (by convention) // only the minor field is required to be bumped when native assemblies change CRC - else if( - ver->iMajorVersion == pASSM->m_header->version.iMajorVersion && - ver->iMinorVersion == pASSM->m_header->version.iMinorVersion - ) + else if ( + ver->iMajorVersion == pASSM->m_header->version.iMajorVersion && + ver->iMinorVersion == pASSM->m_header->version.iMinorVersion) { return pASSM; } @@ -3306,32 +3484,38 @@ CLR_RT_Assembly* CLR_RT_TypeSystem::FindAssembly( const char* szName, const CLR_ return NULL; } -bool CLR_RT_TypeSystem::FindTypeDef( const char* name, const char* nameSpace, CLR_RT_Assembly* assm, CLR_RT_TypeDef_Index& res ) +bool CLR_RT_TypeSystem::FindTypeDef( + const char *name, + const char *nameSpace, + CLR_RT_Assembly *assm, + CLR_RT_TypeDef_Index &res) { NATIVE_PROFILE_CLR_CORE(); - if(assm) + if (assm) { NANOCLR_FOREACH_ASSEMBLY_IN_CURRENT_APPDOMAIN(*this) { - if(pASSM->IsSameAssembly( *assm ) && pASSM->FindTypeDef( name, nameSpace, res )) return true; + if (pASSM->IsSameAssembly(*assm) && pASSM->FindTypeDef(name, nameSpace, res)) + return true; } NANOCLR_FOREACH_ASSEMBLY_IN_CURRENT_APPDOMAIN_END(); res.Clear(); - + return false; } - return FindTypeDef( name, nameSpace, res); + return FindTypeDef(name, nameSpace, res); } -bool CLR_RT_TypeSystem::FindTypeDef( const char* name, const char* nameSpace, CLR_RT_TypeDef_Index& res ) +bool CLR_RT_TypeSystem::FindTypeDef(const char *name, const char *nameSpace, CLR_RT_TypeDef_Index &res) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_FOREACH_ASSEMBLY_IN_CURRENT_APPDOMAIN(*this) { - if(pASSM->FindTypeDef( name, nameSpace, res )) return true; + if (pASSM->FindTypeDef(name, nameSpace, res)) + return true; } NANOCLR_FOREACH_ASSEMBLY_IN_CURRENT_APPDOMAIN_END(); @@ -3339,12 +3523,13 @@ bool CLR_RT_TypeSystem::FindTypeDef( const char* name, const char* nameSpace, CL return false; } -bool CLR_RT_TypeSystem::FindTypeDef( CLR_UINT32 hash, CLR_RT_TypeDef_Index& res ) +bool CLR_RT_TypeSystem::FindTypeDef(CLR_UINT32 hash, CLR_RT_TypeDef_Index &res) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_FOREACH_ASSEMBLY_IN_CURRENT_APPDOMAIN(*this) { - if(pASSM->FindTypeDef( hash, res )) return true; + if (pASSM->FindTypeDef(hash, res)) + return true; } NANOCLR_FOREACH_ASSEMBLY_IN_CURRENT_APPDOMAIN_END(); @@ -3352,34 +3537,36 @@ bool CLR_RT_TypeSystem::FindTypeDef( CLR_UINT32 hash, CLR_RT_TypeDef_Index& res return false; } -bool CLR_RT_TypeSystem::FindTypeDef( const char* szClass, CLR_RT_Assembly* assm, CLR_RT_TypeDef_Index& res ) +bool CLR_RT_TypeSystem::FindTypeDef(const char *szClass, CLR_RT_Assembly *assm, CLR_RT_TypeDef_Index &res) { (void)szClass; (void)assm; (void)res; NATIVE_PROFILE_CLR_CORE(); - - char rgName [ MAXTYPENAMELEN ]; - char rgNamespace[ MAXTYPENAMELEN ]; - if(hal_strlen_s(szClass) < ARRAYSIZE(rgNamespace)) + char rgName[MAXTYPENAMELEN]; + char rgNamespace[MAXTYPENAMELEN]; + + if (hal_strlen_s(szClass) < ARRAYSIZE(rgNamespace)) { - const char* szPtr = szClass; - const char* szPtr_LastDot = NULL; - const char* szPtr_FirstSubType = NULL; - char c; + const char *szPtr = szClass; + const char *szPtr_LastDot = NULL; + const char *szPtr_FirstSubType = NULL; + char c; size_t len; - while(true) + while (true) { - c = szPtr[ 0 ]; if(!c) break; + c = szPtr[0]; + if (!c) + break; - if(c == '.') + if (c == '.') { szPtr_LastDot = szPtr; } - else if(c == '+') + else if (c == '+') { szPtr_FirstSubType = szPtr; break; @@ -3388,24 +3575,25 @@ bool CLR_RT_TypeSystem::FindTypeDef( const char* szClass, CLR_RT_Assembly* assm, szPtr++; } - if(szPtr_LastDot) + if (szPtr_LastDot) { - len = szPtr_LastDot++ - szClass ; hal_strncpy_s( rgNamespace, ARRAYSIZE(rgNamespace), szClass , len ); - len = szPtr - szPtr_LastDot; hal_strncpy_s( rgName , ARRAYSIZE(rgName ), szPtr_LastDot, len ); + len = szPtr_LastDot++ - szClass; + hal_strncpy_s(rgNamespace, ARRAYSIZE(rgNamespace), szClass, len); + len = szPtr - szPtr_LastDot; + hal_strncpy_s(rgName, ARRAYSIZE(rgName), szPtr_LastDot, len); } else { - rgNamespace[ 0 ] = 0; - hal_strcpy_s( rgName, ARRAYSIZE(rgName), szClass ); + rgNamespace[0] = 0; + hal_strcpy_s(rgName, ARRAYSIZE(rgName), szClass); } - - if(FindTypeDef( rgName, rgNamespace, assm, res )) + if (FindTypeDef(rgName, rgNamespace, assm, res)) { // // Found the containing type, let's look for the nested type. // - if(szPtr_FirstSubType) + if (szPtr_FirstSubType) { CLR_RT_TypeDef_Instance inst; @@ -3413,25 +3601,29 @@ bool CLR_RT_TypeSystem::FindTypeDef( const char* szClass, CLR_RT_Assembly* assm, { szPtr = ++szPtr_FirstSubType; - while(true) + while (true) { - c = szPtr_FirstSubType[ 0 ]; if(!c) break; + c = szPtr_FirstSubType[0]; + if (!c) + break; - if(c == '+') break; + if (c == '+') + break; szPtr_FirstSubType++; } - len = szPtr_FirstSubType - szPtr; hal_strncpy_s( rgName, ARRAYSIZE(rgName), szPtr, len ); + len = szPtr_FirstSubType - szPtr; + hal_strncpy_s(rgName, ARRAYSIZE(rgName), szPtr, len); - inst.InitializeFromIndex( res ); + inst.InitializeFromIndex(res); - if(inst.m_assm->FindTypeDef( rgName, res.Type(), res ) == false) + if (inst.m_assm->FindTypeDef(rgName, res.Type(), res) == false) { return false; } - } while(c == '+'); + } while (c == '+'); } return true; @@ -3443,7 +3635,7 @@ bool CLR_RT_TypeSystem::FindTypeDef( const char* szClass, CLR_RT_Assembly* assm, return false; } -bool CLR_RT_TypeSystem::FindTypeDef( const char* szClass, CLR_RT_Assembly* assm, CLR_RT_ReflectionDef_Index& reflex ) +bool CLR_RT_TypeSystem::FindTypeDef(const char *szClass, CLR_RT_Assembly *assm, CLR_RT_ReflectionDef_Index &reflex) { (void)szClass; (void)assm; @@ -3493,8 +3685,9 @@ bool CLR_RT_TypeSystem::FindTypeDef( const char* szClass, CLR_RT_Assembly* assm, // if(szPtr_LastDot) // { - // len = szPtr_LastDot++ - szClass ; hal_strncpy_s( rgNamespace, ARRAYSIZE(rgNamespace), szClass , len ); - // len = szPtr - szPtr_LastDot; hal_strncpy_s( rgName , ARRAYSIZE(rgName ), szPtr_LastDot, len ); + // len = szPtr_LastDot++ - szClass ; hal_strncpy_s( rgNamespace, ARRAYSIZE(rgNamespace), szClass , + // len ); len = szPtr - szPtr_LastDot; hal_strncpy_s( rgName , ARRAYSIZE(rgName ), + // szPtr_LastDot, len ); // } // else // { @@ -3544,7 +3737,7 @@ bool CLR_RT_TypeSystem::FindTypeDef( const char* szClass, CLR_RT_Assembly* assm, // } // } // - //res.Clear(); + // res.Clear(); return false; } @@ -3553,29 +3746,32 @@ bool CLR_RT_TypeSystem::FindTypeDef( const char* szClass, CLR_RT_Assembly* assm, int #if defined(_MSC_VER) -__cdecl + __cdecl #endif -CompareResource( const void* p1, const void* p2 ) + CompareResource(const void *p1, const void *p2) { NATIVE_PROFILE_CLR_CORE(); - const CLR_RECORD_RESOURCE* resource1 = (const CLR_RECORD_RESOURCE*)p1; - const CLR_RECORD_RESOURCE* resource2 = (const CLR_RECORD_RESOURCE*)p2; + const CLR_RECORD_RESOURCE *resource1 = (const CLR_RECORD_RESOURCE *)p1; + const CLR_RECORD_RESOURCE *resource2 = (const CLR_RECORD_RESOURCE *)p2; return (int)resource1->id - (int)resource2->id; } -HRESULT CLR_RT_TypeSystem::LocateResourceFile( CLR_RT_Assembly_Instance assm, const char* name, CLR_INT32& idxResourceFile ) +HRESULT CLR_RT_TypeSystem::LocateResourceFile( + CLR_RT_Assembly_Instance assm, + const char *name, + CLR_INT32 &idxResourceFile) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - CLR_RT_Assembly* pAssm = assm.m_assm; + CLR_RT_Assembly *pAssm = assm.m_assm; - for(idxResourceFile = 0; idxResourceFile < pAssm->m_pTablesSize[ TBL_ResourcesFiles ]; idxResourceFile++) + for (idxResourceFile = 0; idxResourceFile < pAssm->m_pTablesSize[TBL_ResourcesFiles]; idxResourceFile++) { - const CLR_RECORD_RESOURCE_FILE* resourceFile = pAssm->GetResourceFile( idxResourceFile ); + const CLR_RECORD_RESOURCE_FILE *resourceFile = pAssm->GetResourceFile(idxResourceFile); - if(!strcmp( pAssm->GetString( resourceFile->name ), name )) + if (!strcmp(pAssm->GetString(resourceFile->name), name)) { NANOCLR_SET_AND_LEAVE(S_OK); } @@ -3586,42 +3782,49 @@ HRESULT CLR_RT_TypeSystem::LocateResourceFile( CLR_RT_Assembly_Instance assm, co NANOCLR_NOCLEANUP(); } -HRESULT CLR_RT_TypeSystem::LocateResource( CLR_RT_Assembly_Instance assm, CLR_INT32 idxResourceFile, CLR_INT16 id, const CLR_RECORD_RESOURCE*& res, CLR_UINT32& size ) +HRESULT CLR_RT_TypeSystem::LocateResource( + CLR_RT_Assembly_Instance assm, + CLR_INT32 idxResourceFile, + CLR_INT16 id, + const CLR_RECORD_RESOURCE *&res, + CLR_UINT32 &size) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - CLR_RT_Assembly* pAssm = assm.m_assm; - const CLR_RECORD_RESOURCE_FILE* resourceFile; + CLR_RT_Assembly *pAssm = assm.m_assm; + const CLR_RECORD_RESOURCE_FILE *resourceFile; CLR_RECORD_RESOURCE resourceT; - const CLR_RECORD_RESOURCE* resNext; - const CLR_RECORD_RESOURCE* resZero; + const CLR_RECORD_RESOURCE *resNext; + const CLR_RECORD_RESOURCE *resZero; - res = NULL; + res = NULL; size = 0; - if(idxResourceFile < 0 || idxResourceFile >= pAssm->m_pTablesSize[ TBL_ResourcesFiles ]) NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); + if (idxResourceFile < 0 || idxResourceFile >= pAssm->m_pTablesSize[TBL_ResourcesFiles]) + NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); - resourceFile = pAssm->GetResourceFile( idxResourceFile ); + resourceFile = pAssm->GetResourceFile(idxResourceFile); _ASSERTE(resourceFile->numberOfResources > 0); - resZero = pAssm->GetResource( resourceFile->offset ); + resZero = pAssm->GetResource(resourceFile->offset); resourceT.id = id; - res = (const CLR_RECORD_RESOURCE*)bsearch( &resourceT, resZero, resourceFile->numberOfResources, sizeof(CLR_RECORD_RESOURCE), CompareResource ); + res = (const CLR_RECORD_RESOURCE *) + bsearch(&resourceT, resZero, resourceFile->numberOfResources, sizeof(CLR_RECORD_RESOURCE), CompareResource); - if(res != NULL) + if (res != NULL) { - //compute size here... - //assert not the last resource - _ASSERTE(res + 1 <= pAssm->GetResource( pAssm->m_pTablesSize[ TBL_Resources ] - 1)); - resNext = res+1; + // compute size here... + // assert not the last resource + _ASSERTE(res + 1 <= pAssm->GetResource(pAssm->m_pTablesSize[TBL_Resources] - 1)); + resNext = res + 1; size = resNext->offset - res->offset; - //deal with alignment. + // deal with alignment. size -= (resNext->flags & CLR_RECORD_RESOURCE::FLAGS_PaddingMask); } @@ -3635,33 +3838,33 @@ HRESULT CLR_RT_TypeSystem::ResolveAll() bool fOutput = false; - while(true) + while (true) { - bool fGot = false; + bool fGot = false; bool fNeedResolution = false; NANOCLR_FOREACH_ASSEMBLY(*this) { - if((pASSM->m_flags & CLR_RT_Assembly::Resolved) == 0) + if ((pASSM->m_flags & CLR_RT_Assembly::Resolved) == 0) { fNeedResolution = true; - if(pASSM->Resolve_AssemblyRef( fOutput )) + if (pASSM->Resolve_AssemblyRef(fOutput)) { fGot = true; pASSM->m_flags |= CLR_RT_Assembly::Resolved; - NANOCLR_CHECK_HRESULT(pASSM->Resolve_TypeRef ()); - NANOCLR_CHECK_HRESULT(pASSM->Resolve_FieldRef ()); - NANOCLR_CHECK_HRESULT(pASSM->Resolve_MethodRef ()); - /********************/pASSM->Resolve_TypeDef () ; - /********************/pASSM->Resolve_MethodDef () ; - /********************/pASSM->Resolve_Link () ; - NANOCLR_CHECK_HRESULT(pASSM->Resolve_ComputeHashes ()); + NANOCLR_CHECK_HRESULT(pASSM->Resolve_TypeRef()); + NANOCLR_CHECK_HRESULT(pASSM->Resolve_FieldRef()); + NANOCLR_CHECK_HRESULT(pASSM->Resolve_MethodRef()); + /********************/ pASSM->Resolve_TypeDef(); + /********************/ pASSM->Resolve_MethodDef(); + /********************/ pASSM->Resolve_Link(); + NANOCLR_CHECK_HRESULT(pASSM->Resolve_ComputeHashes()); #if !defined(NANOCLR_APPDOMAINS) - NANOCLR_CHECK_HRESULT(pASSM->Resolve_AllocateStaticFields( pASSM->m_pStaticFields )); + NANOCLR_CHECK_HRESULT(pASSM->Resolve_AllocateStaticFields(pASSM->m_pStaticFields)); #endif pASSM->m_flags |= CLR_RT_Assembly::ResolutionCompleted; @@ -3670,17 +3873,17 @@ HRESULT CLR_RT_TypeSystem::ResolveAll() } NANOCLR_FOREACH_ASSEMBLY_END(); - if(fOutput == true) + if (fOutput == true) { NANOCLR_SET_AND_LEAVE(CLR_E_TYPE_UNAVAILABLE); } - if(fGot == false) + if (fGot == false) { - if(fNeedResolution) + if (fNeedResolution) { #if !defined(BUILD_RTM) - CLR_Debug::Printf( "Link failure: some assembly references cannot be resolved!!\r\n\r\n" ); + CLR_Debug::Printf("Link failure: some assembly references cannot be resolved!!\r\n\r\n"); #endif fOutput = true; @@ -3694,50 +3897,64 @@ HRESULT CLR_RT_TypeSystem::ResolveAll() #if !defined(BUILD_RTM) - if(s_CLR_RT_fTrace_AssemblyOverhead >= c_CLR_RT_Trace_Info) + if (s_CLR_RT_fTrace_AssemblyOverhead >= c_CLR_RT_Trace_Info) { { - int pTablesSize[ TBL_Max ]; memset( pTablesSize, 0, sizeof(pTablesSize) ); - CLR_RT_Assembly::Offsets offsets ; memset( &offsets , 0, sizeof(offsets ) ); + int pTablesSize[TBL_Max]; + memset(pTablesSize, 0, sizeof(pTablesSize)); + CLR_RT_Assembly::Offsets offsets; + memset(&offsets, 0, sizeof(offsets)); - size_t iStaticFields = 0 ; - size_t iTotalRamSize = 0 ; - size_t iTotalRomSize = 0 ; - size_t iMetaData = 0 ; + size_t iStaticFields = 0; + size_t iTotalRamSize = 0; + size_t iTotalRomSize = 0; + size_t iMetaData = 0; NANOCLR_FOREACH_ASSEMBLY(*this) { - offsets.iBase += ROUNDTOMULTIPLE(sizeof(CLR_RT_Assembly) , CLR_UINT32); - offsets.iAssemblyRef += ROUNDTOMULTIPLE(pASSM->m_pTablesSize[ TBL_AssemblyRef ] * sizeof(CLR_RT_AssemblyRef_CrossReference), CLR_UINT32); - offsets.iTypeRef += ROUNDTOMULTIPLE(pASSM->m_pTablesSize[ TBL_TypeRef ] * sizeof(CLR_RT_TypeRef_CrossReference ), CLR_UINT32); - offsets.iFieldRef += ROUNDTOMULTIPLE(pASSM->m_pTablesSize[ TBL_FieldRef ] * sizeof(CLR_RT_FieldRef_CrossReference ), CLR_UINT32); - offsets.iMethodRef += ROUNDTOMULTIPLE(pASSM->m_pTablesSize[ TBL_MethodRef ] * sizeof(CLR_RT_MethodRef_CrossReference ), CLR_UINT32); - offsets.iTypeDef += ROUNDTOMULTIPLE(pASSM->m_pTablesSize[ TBL_TypeDef ] * sizeof(CLR_RT_TypeDef_CrossReference ), CLR_UINT32); - offsets.iFieldDef += ROUNDTOMULTIPLE(pASSM->m_pTablesSize[ TBL_FieldDef ] * sizeof(CLR_RT_FieldDef_CrossReference ), CLR_UINT32); - offsets.iMethodDef += ROUNDTOMULTIPLE(pASSM->m_pTablesSize[ TBL_MethodDef ] * sizeof(CLR_RT_MethodDef_CrossReference ), CLR_UINT32); + offsets.iBase += ROUNDTOMULTIPLE(sizeof(CLR_RT_Assembly), CLR_UINT32); + offsets.iAssemblyRef += ROUNDTOMULTIPLE( + pASSM->m_pTablesSize[TBL_AssemblyRef] * sizeof(CLR_RT_AssemblyRef_CrossReference), + CLR_UINT32); + offsets.iTypeRef += ROUNDTOMULTIPLE( + pASSM->m_pTablesSize[TBL_TypeRef] * sizeof(CLR_RT_TypeRef_CrossReference), + CLR_UINT32); + offsets.iFieldRef += ROUNDTOMULTIPLE( + pASSM->m_pTablesSize[TBL_FieldRef] * sizeof(CLR_RT_FieldRef_CrossReference), + CLR_UINT32); + offsets.iMethodRef += ROUNDTOMULTIPLE( + pASSM->m_pTablesSize[TBL_MethodRef] * sizeof(CLR_RT_MethodRef_CrossReference), + CLR_UINT32); + offsets.iTypeDef += ROUNDTOMULTIPLE( + pASSM->m_pTablesSize[TBL_TypeDef] * sizeof(CLR_RT_TypeDef_CrossReference), + CLR_UINT32); + offsets.iFieldDef += ROUNDTOMULTIPLE( + pASSM->m_pTablesSize[TBL_FieldDef] * sizeof(CLR_RT_FieldDef_CrossReference), + CLR_UINT32); + offsets.iMethodDef += ROUNDTOMULTIPLE( + pASSM->m_pTablesSize[TBL_MethodDef] * sizeof(CLR_RT_MethodDef_CrossReference), + CLR_UINT32); #if !defined(NANOCLR_APPDOMAINS) - offsets.iStaticFields += ROUNDTOMULTIPLE(pASSM->m_iStaticFields * sizeof(CLR_RT_HeapBlock ), CLR_UINT32); + offsets.iStaticFields += ROUNDTOMULTIPLE(pASSM->m_iStaticFields * sizeof(CLR_RT_HeapBlock), CLR_UINT32); #endif #if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) - offsets.iDebuggingInfoMethods += ROUNDTOMULTIPLE(pASSM->m_pTablesSize[ TBL_MethodDef ] * sizeof(CLR_RT_MethodDef_DebuggingInfo ), CLR_UINT32); + offsets.iDebuggingInfoMethods += ROUNDTOMULTIPLE( + pASSM->m_pTablesSize[TBL_MethodDef] * sizeof(CLR_RT_MethodDef_DebuggingInfo), + CLR_UINT32); #endif //#if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) - iMetaData += pASSM->m_header->SizeOfTable( TBL_AssemblyRef ) + - pASSM->m_header->SizeOfTable( TBL_TypeRef ) + - pASSM->m_header->SizeOfTable( TBL_FieldRef ) + - pASSM->m_header->SizeOfTable( TBL_MethodRef ) + - pASSM->m_header->SizeOfTable( TBL_TypeDef ) + - pASSM->m_header->SizeOfTable( TBL_FieldDef ) + - pASSM->m_header->SizeOfTable( TBL_MethodDef ) + - pASSM->m_header->SizeOfTable( TBL_Attributes ) + - pASSM->m_header->SizeOfTable( TBL_TypeSpec ) + - pASSM->m_header->SizeOfTable( TBL_Signatures ); - - for(int tbl=0; tblm_header->SizeOfTable(TBL_AssemblyRef) + pASSM->m_header->SizeOfTable(TBL_TypeRef) + + pASSM->m_header->SizeOfTable(TBL_FieldRef) + pASSM->m_header->SizeOfTable(TBL_MethodRef) + + pASSM->m_header->SizeOfTable(TBL_TypeDef) + pASSM->m_header->SizeOfTable(TBL_FieldDef) + + pASSM->m_header->SizeOfTable(TBL_MethodDef) + + pASSM->m_header->SizeOfTable(TBL_Attributes) + pASSM->m_header->SizeOfTable(TBL_TypeSpec) + + pASSM->m_header->SizeOfTable(TBL_Signatures); + + for (int tbl = 0; tbl < TBL_Max; tbl++) { - pTablesSize[ tbl ] += pASSM->m_pTablesSize[ tbl ]; + pTablesSize[tbl] += pASSM->m_pTablesSize[tbl]; } iTotalRomSize += pASSM->m_header->TotalSize(); @@ -3746,49 +3963,80 @@ HRESULT CLR_RT_TypeSystem::ResolveAll() } NANOCLR_FOREACH_ASSEMBLY_END(); - iTotalRamSize = offsets.iBase + - offsets.iAssemblyRef + - offsets.iTypeRef + - offsets.iFieldRef + - offsets.iMethodRef + - offsets.iTypeDef + - offsets.iFieldDef + - offsets.iMethodDef; + iTotalRamSize = offsets.iBase + offsets.iAssemblyRef + offsets.iTypeRef + offsets.iFieldRef + + offsets.iMethodRef + offsets.iTypeDef + offsets.iFieldDef + offsets.iMethodDef; #if !defined(NANOCLR_APPDOMAINS) iTotalRamSize += offsets.iStaticFields; #endif - CLR_Debug::Printf( "\r\nTotal: (%d RAM - %d ROM - %d METADATA)\r\n\r\n", iTotalRamSize, iTotalRomSize, iMetaData ); - - CLR_Debug::Printf( " AssemblyRef = %8d bytes (%8d elements)\r\n", offsets.iAssemblyRef , pTablesSize[TBL_AssemblyRef] ); - CLR_Debug::Printf( " TypeRef = %8d bytes (%8d elements)\r\n", offsets.iTypeRef , pTablesSize[TBL_TypeRef ] ); - CLR_Debug::Printf( " FieldRef = %8d bytes (%8d elements)\r\n", offsets.iFieldRef , pTablesSize[TBL_FieldRef ] ); - CLR_Debug::Printf( " MethodRef = %8d bytes (%8d elements)\r\n", offsets.iMethodRef , pTablesSize[TBL_MethodRef ] ); - CLR_Debug::Printf( " TypeDef = %8d bytes (%8d elements)\r\n", offsets.iTypeDef , pTablesSize[TBL_TypeDef ] ); - CLR_Debug::Printf( " FieldDef = %8d bytes (%8d elements)\r\n", offsets.iFieldDef , pTablesSize[TBL_FieldDef ] ); - CLR_Debug::Printf( " MethodDef = %8d bytes (%8d elements)\r\n", offsets.iMethodDef , pTablesSize[TBL_MethodDef ] ); + CLR_Debug::Printf( + "\r\nTotal: (%d RAM - %d ROM - %d METADATA)\r\n\r\n", + iTotalRamSize, + iTotalRomSize, + iMetaData); + + CLR_Debug::Printf( + " AssemblyRef = %8d bytes (%8d elements)\r\n", + offsets.iAssemblyRef, + pTablesSize[TBL_AssemblyRef]); + CLR_Debug::Printf( + " TypeRef = %8d bytes (%8d elements)\r\n", + offsets.iTypeRef, + pTablesSize[TBL_TypeRef]); + CLR_Debug::Printf( + " FieldRef = %8d bytes (%8d elements)\r\n", + offsets.iFieldRef, + pTablesSize[TBL_FieldRef]); + CLR_Debug::Printf( + " MethodRef = %8d bytes (%8d elements)\r\n", + offsets.iMethodRef, + pTablesSize[TBL_MethodRef]); + CLR_Debug::Printf( + " TypeDef = %8d bytes (%8d elements)\r\n", + offsets.iTypeDef, + pTablesSize[TBL_TypeDef]); + CLR_Debug::Printf( + " FieldDef = %8d bytes (%8d elements)\r\n", + offsets.iFieldDef, + pTablesSize[TBL_FieldDef]); + CLR_Debug::Printf( + " MethodDef = %8d bytes (%8d elements)\r\n", + offsets.iMethodDef, + pTablesSize[TBL_MethodDef]); #if !defined(NANOCLR_APPDOMAINS) - CLR_Debug::Printf( " StaticFields = %8d bytes (%8d elements)\r\n", offsets.iStaticFields , iStaticFields ); + CLR_Debug::Printf(" StaticFields = %8d bytes (%8d elements)\r\n", offsets.iStaticFields, iStaticFields); #endif - CLR_Debug::Printf( "\r\n" ); + CLR_Debug::Printf("\r\n"); #if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) - CLR_Debug::Printf( " DebuggingInfo = %8d bytes\r\n", offsets.iDebuggingInfoMethods ); - CLR_Debug::Printf( "\r\n" ); + CLR_Debug::Printf(" DebuggingInfo = %8d bytes\r\n", offsets.iDebuggingInfoMethods); + CLR_Debug::Printf("\r\n"); #endif //#if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) - CLR_Debug::Printf( " Attributes = %8d bytes (%8d elements)\r\n", pTablesSize[ TBL_Attributes ] * sizeof(CLR_RECORD_ATTRIBUTE ), pTablesSize[ TBL_Attributes ] ); - CLR_Debug::Printf( " TypeSpec = %8d bytes (%8d elements)\r\n", pTablesSize[ TBL_TypeSpec ] * sizeof(CLR_RECORD_TYPESPEC ), pTablesSize[ TBL_TypeSpec ] ); - CLR_Debug::Printf( " Resources Files = %8d bytes (%8d elements)\r\n", pTablesSize[ TBL_ResourcesFiles ] * sizeof(CLR_RECORD_RESOURCE_FILE ), pTablesSize[ TBL_ResourcesFiles ] ); - CLR_Debug::Printf( " Resources = %8d bytes (%8d elements)\r\n", pTablesSize[ TBL_Resources ] * sizeof(CLR_RECORD_RESOURCE ), pTablesSize[ TBL_Resources ] ); - CLR_Debug::Printf( " Resources Data = %8d bytes\r\n" , pTablesSize[ TBL_ResourcesData ] ); - CLR_Debug::Printf( " Strings = %8d bytes\r\n" , pTablesSize[ TBL_Strings ] ); - CLR_Debug::Printf( " Signatures = %8d bytes\r\n" , pTablesSize[ TBL_Signatures ] ); - CLR_Debug::Printf( " ByteCode = %8d bytes\r\n" , pTablesSize[ TBL_ByteCode ] ); - CLR_Debug::Printf( "\r\n\r\n" ); + CLR_Debug::Printf( + " Attributes = %8d bytes (%8d elements)\r\n", + pTablesSize[TBL_Attributes] * sizeof(CLR_RECORD_ATTRIBUTE), + pTablesSize[TBL_Attributes]); + CLR_Debug::Printf( + " TypeSpec = %8d bytes (%8d elements)\r\n", + pTablesSize[TBL_TypeSpec] * sizeof(CLR_RECORD_TYPESPEC), + pTablesSize[TBL_TypeSpec]); + CLR_Debug::Printf( + " Resources Files = %8d bytes (%8d elements)\r\n", + pTablesSize[TBL_ResourcesFiles] * sizeof(CLR_RECORD_RESOURCE_FILE), + pTablesSize[TBL_ResourcesFiles]); + CLR_Debug::Printf( + " Resources = %8d bytes (%8d elements)\r\n", + pTablesSize[TBL_Resources] * sizeof(CLR_RECORD_RESOURCE), + pTablesSize[TBL_Resources]); + CLR_Debug::Printf(" Resources Data = %8d bytes\r\n", pTablesSize[TBL_ResourcesData]); + CLR_Debug::Printf(" Strings = %8d bytes\r\n", pTablesSize[TBL_Strings]); + CLR_Debug::Printf(" Signatures = %8d bytes\r\n", pTablesSize[TBL_Signatures]); + CLR_Debug::Printf(" ByteCode = %8d bytes\r\n", pTablesSize[TBL_ByteCode]); + CLR_Debug::Printf("\r\n\r\n"); } } @@ -3797,14 +4045,14 @@ HRESULT CLR_RT_TypeSystem::ResolveAll() NANOCLR_NOCLEANUP(); } -HRESULT CLR_RT_TypeSystem::PrepareForExecutionHelper( const char* szAssembly ) +HRESULT CLR_RT_TypeSystem::PrepareForExecutionHelper(const char *szAssembly) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); NANOCLR_FOREACH_ASSEMBLY(*this) { - if(!strcmp( szAssembly, pASSM->m_szName )) + if (!strcmp(szAssembly, pASSM->m_szName)) { NANOCLR_CHECK_HRESULT(pASSM->PrepareForExecution()); } @@ -3825,22 +4073,23 @@ HRESULT CLR_RT_TypeSystem::PrepareForExecution() #endif //#if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) #if !defined(NANOCLR_APPDOMAINS) - if(g_CLR_RT_ExecutionEngine.m_outOfMemoryException == NULL) + if (g_CLR_RT_ExecutionEngine.m_outOfMemoryException == NULL) { CLR_RT_HeapBlock exception; - NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.NewObjectFromIndex( exception, g_CLR_RT_WellKnownTypes.m_OutOfMemoryException )); + NANOCLR_CHECK_HRESULT( + g_CLR_RT_ExecutionEngine.NewObjectFromIndex(exception, g_CLR_RT_WellKnownTypes.m_OutOfMemoryException)); g_CLR_RT_ExecutionEngine.m_outOfMemoryException = exception.Dereference(); } #endif // Load Runtime.Events to setup EventSink for other assemblies using it - NANOCLR_CHECK_HRESULT(PrepareForExecutionHelper( "nanoFramework.Runtime.Events" )); - + NANOCLR_CHECK_HRESULT(PrepareForExecutionHelper("nanoFramework.Runtime.Events")); + // Load Runtime.Native for other assemblies using it - NANOCLR_CHECK_HRESULT(PrepareForExecutionHelper( "nanoFramework.Runtime.Native" )); - + NANOCLR_CHECK_HRESULT(PrepareForExecutionHelper("nanoFramework.Runtime.Native")); + NANOCLR_FOREACH_ASSEMBLY(*this) { NANOCLR_CHECK_HRESULT(pASSM->PrepareForExecution()); @@ -3860,63 +4109,87 @@ HRESULT CLR_RT_TypeSystem::PrepareForExecution() //--// -bool CLR_RT_TypeSystem::MatchSignature( CLR_RT_SignatureParser& parserLeft, CLR_RT_SignatureParser& parserRight ) +bool CLR_RT_TypeSystem::MatchSignature(CLR_RT_SignatureParser &parserLeft, CLR_RT_SignatureParser &parserRight) { NATIVE_PROFILE_CLR_CORE(); - if(parserLeft.m_type != parserRight.m_type ) return false; - if(parserLeft.m_flags != parserRight.m_flags) return false; + if (parserLeft.m_type != parserRight.m_type) + return false; + if (parserLeft.m_flags != parserRight.m_flags) + return false; - return MatchSignatureDirect( parserLeft, parserRight, false ); + return MatchSignatureDirect(parserLeft, parserRight, false); } -bool CLR_RT_TypeSystem::MatchSignatureDirect( CLR_RT_SignatureParser& parserLeft, CLR_RT_SignatureParser& parserRight, bool fIsInstanceOfOK ) +bool CLR_RT_TypeSystem::MatchSignatureDirect( + CLR_RT_SignatureParser &parserLeft, + CLR_RT_SignatureParser &parserRight, + bool fIsInstanceOfOK) { NATIVE_PROFILE_CLR_CORE(); - while(true) + while (true) { - int iAvailLeft = parserLeft .Available(); + int iAvailLeft = parserLeft.Available(); int iAvailRight = parserRight.Available(); - if(iAvailLeft != iAvailRight) return false; + if (iAvailLeft != iAvailRight) + return false; - if(!iAvailLeft) return true; + if (!iAvailLeft) + return true; - CLR_RT_SignatureParser::Element resLeft; if(FAILED(parserLeft .Advance( resLeft ))) return false; - CLR_RT_SignatureParser::Element resRight; if(FAILED(parserRight.Advance( resRight ))) return false; + CLR_RT_SignatureParser::Element resLeft; + if (FAILED(parserLeft.Advance(resLeft))) + return false; + CLR_RT_SignatureParser::Element resRight; + if (FAILED(parserRight.Advance(resRight))) + return false; - if(!MatchSignatureElement( resLeft, resRight, fIsInstanceOfOK )) return false; + if (!MatchSignatureElement(resLeft, resRight, fIsInstanceOfOK)) + return false; } return true; } -bool CLR_RT_TypeSystem::MatchSignatureElement( CLR_RT_SignatureParser::Element& resLeft, CLR_RT_SignatureParser::Element& resRight, bool fIsInstanceOfOK ) +bool CLR_RT_TypeSystem::MatchSignatureElement( + CLR_RT_SignatureParser::Element &resLeft, + CLR_RT_SignatureParser::Element &resRight, + bool fIsInstanceOfOK) { NATIVE_PROFILE_CLR_CORE(); - if(fIsInstanceOfOK) + if (fIsInstanceOfOK) { - CLR_RT_ReflectionDef_Index idxLeft ; CLR_RT_TypeDescriptor descLeft; - CLR_RT_ReflectionDef_Index idxRight; CLR_RT_TypeDescriptor descRight; + CLR_RT_ReflectionDef_Index idxLeft; + CLR_RT_TypeDescriptor descLeft; + CLR_RT_ReflectionDef_Index idxRight; + CLR_RT_TypeDescriptor descRight; - idxLeft.m_kind = REFLECTION_TYPE; - idxLeft.m_levels = resLeft.m_levels; - idxLeft.m_data.m_type = resLeft.m_cls; + idxLeft.m_kind = REFLECTION_TYPE; + idxLeft.m_levels = resLeft.m_levels; + idxLeft.m_data.m_type = resLeft.m_cls; - idxRight.m_kind = REFLECTION_TYPE; - idxRight.m_levels = resRight.m_levels; - idxRight.m_data.m_type = resRight.m_cls; + idxRight.m_kind = REFLECTION_TYPE; + idxRight.m_levels = resRight.m_levels; + idxRight.m_data.m_type = resRight.m_cls; - if(FAILED(descLeft .InitializeFromReflection( idxLeft ))) return false; - if(FAILED(descRight.InitializeFromReflection( idxRight ))) return false; + if (FAILED(descLeft.InitializeFromReflection(idxLeft))) + return false; + if (FAILED(descRight.InitializeFromReflection(idxRight))) + return false; - if(!CLR_RT_ExecutionEngine::IsInstanceOf( descRight, descLeft, false )) return false; + if (!CLR_RT_ExecutionEngine::IsInstanceOf(descRight, descLeft, false)) + return false; } else { - if(resLeft.m_fByRef != resRight.m_fByRef ) return false; - if(resLeft.m_levels != resRight.m_levels ) return false; - if(resLeft.m_dt != resRight.m_dt ) return false; - if(resLeft.m_cls.m_data != resRight.m_cls.m_data) return false; + if (resLeft.m_fByRef != resRight.m_fByRef) + return false; + if (resLeft.m_levels != resRight.m_levels) + return false; + if (resLeft.m_dt != resRight.m_dt) + return false; + if (resLeft.m_cls.m_data != resRight.m_cls.m_data) + return false; } return true; @@ -3924,145 +4197,171 @@ bool CLR_RT_TypeSystem::MatchSignatureElement( CLR_RT_SignatureParser::Element& //--// -HRESULT CLR_RT_TypeSystem::QueueStringToBuffer( char*& szBuffer, size_t& iBuffer, const char* szText ) +HRESULT CLR_RT_TypeSystem::QueueStringToBuffer(char *&szBuffer, size_t &iBuffer, const char *szText) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - if(szText) + if (szText) { - if(CLR_SafeSprintf( szBuffer, iBuffer, "%s", szText ) == false) + if (CLR_SafeSprintf(szBuffer, iBuffer, "%s", szText) == false) { NANOCLR_SET_AND_LEAVE(CLR_E_OUT_OF_MEMORY); } } else { - szBuffer[ 0 ] = 0; + szBuffer[0] = 0; } NANOCLR_NOCLEANUP(); } -HRESULT CLR_RT_TypeSystem::BuildTypeName( const CLR_RT_TypeDef_Index& cls, char*& szBuffer, size_t& iBuffer ) +HRESULT CLR_RT_TypeSystem::BuildTypeName(const CLR_RT_TypeDef_Index &cls, char *&szBuffer, size_t &iBuffer) { NATIVE_PROFILE_CLR_CORE(); - return BuildTypeName( cls, szBuffer, iBuffer, CLR_RT_TypeSystem::TYPENAME_FLAGS_FULL, 0 ); + return BuildTypeName(cls, szBuffer, iBuffer, CLR_RT_TypeSystem::TYPENAME_FLAGS_FULL, 0); } -HRESULT CLR_RT_TypeSystem::BuildTypeName ( const CLR_RT_TypeDef_Index& cls, char*& szBuffer, size_t& iBuffer, CLR_UINT32 flags, CLR_UINT32 levels ) +HRESULT CLR_RT_TypeSystem::BuildTypeName( + const CLR_RT_TypeDef_Index &cls, + char *&szBuffer, + size_t &iBuffer, + CLR_UINT32 flags, + CLR_UINT32 levels) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - CLR_RT_TypeDef_Instance inst; - CLR_RT_Assembly* assm; - const CLR_RECORD_TYPEDEF* td; + CLR_RT_TypeDef_Instance inst; + CLR_RT_Assembly *assm; + const CLR_RECORD_TYPEDEF *td; bool fFullName; - if(inst.InitializeFromIndex( cls ) == false) NANOCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE); + if (inst.InitializeFromIndex(cls) == false) + NANOCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE); - assm = inst.m_assm; - td = inst.m_target; + assm = inst.m_assm; + td = inst.m_target; fFullName = flags & CLR_RT_TypeSystem::TYPENAME_FLAGS_FULL; - if(fFullName && td->enclosingType != CLR_EmptyIndex) + if (fFullName && td->enclosingType != CLR_EmptyIndex) { - CLR_RT_TypeDef_Index clsSub; clsSub.Set( inst.Assembly(), td->enclosingType ); + CLR_RT_TypeDef_Index clsSub; + clsSub.Set(inst.Assembly(), td->enclosingType); - NANOCLR_CHECK_HRESULT(BuildTypeName( clsSub, szBuffer, iBuffer, flags, 0 )); + NANOCLR_CHECK_HRESULT(BuildTypeName(clsSub, szBuffer, iBuffer, flags, 0)); - NANOCLR_CHECK_HRESULT(QueueStringToBuffer( szBuffer, iBuffer, (flags & CLR_RT_TypeSystem::TYPENAME_NESTED_SEPARATOR_DOT) ? "." : "+" )); + NANOCLR_CHECK_HRESULT(QueueStringToBuffer( + szBuffer, + iBuffer, + (flags & CLR_RT_TypeSystem::TYPENAME_NESTED_SEPARATOR_DOT) ? "." : "+")); } - if(fFullName && td->nameSpace != CLR_EmptyIndex) + if (fFullName && td->nameSpace != CLR_EmptyIndex) { - const char* szNameSpace = assm->GetString( td->nameSpace ); + const char *szNameSpace = assm->GetString(td->nameSpace); - if(szNameSpace[ 0 ]) + if (szNameSpace[0]) { - NANOCLR_CHECK_HRESULT(QueueStringToBuffer( szBuffer, iBuffer, szNameSpace )); - NANOCLR_CHECK_HRESULT(QueueStringToBuffer( szBuffer, iBuffer, "." )); + NANOCLR_CHECK_HRESULT(QueueStringToBuffer(szBuffer, iBuffer, szNameSpace)); + NANOCLR_CHECK_HRESULT(QueueStringToBuffer(szBuffer, iBuffer, ".")); } } - NANOCLR_CHECK_HRESULT(QueueStringToBuffer( szBuffer, iBuffer, assm->GetString( td->name ) )); + NANOCLR_CHECK_HRESULT(QueueStringToBuffer(szBuffer, iBuffer, assm->GetString(td->name))); - while(levels-- > 0) + while (levels-- > 0) { - NANOCLR_CHECK_HRESULT(QueueStringToBuffer( szBuffer, iBuffer, "[]" )); + NANOCLR_CHECK_HRESULT(QueueStringToBuffer(szBuffer, iBuffer, "[]")); } NANOCLR_NOCLEANUP(); } -HRESULT CLR_RT_TypeSystem::BuildMethodName( const CLR_RT_MethodDef_Index& md, char*& szBuffer, size_t& iBuffer ) +HRESULT CLR_RT_TypeSystem::BuildMethodName(const CLR_RT_MethodDef_Index &md, char *&szBuffer, size_t &iBuffer) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); CLR_RT_MethodDef_Instance inst; - CLR_RT_TypeDef_Instance instOwner; + CLR_RT_TypeDef_Instance instOwner; - if(inst .InitializeFromIndex ( md ) == false) NANOCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE); - if(instOwner.InitializeFromMethod( inst ) == false) NANOCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE); + if (inst.InitializeFromIndex(md) == false) + NANOCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE); + if (instOwner.InitializeFromMethod(inst) == false) + NANOCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE); - NANOCLR_CHECK_HRESULT(BuildTypeName( instOwner, szBuffer, iBuffer )); + NANOCLR_CHECK_HRESULT(BuildTypeName(instOwner, szBuffer, iBuffer)); - CLR_SafeSprintf( szBuffer, iBuffer, "::%s", inst.m_assm->GetString( inst.m_target->name ) ); + CLR_SafeSprintf(szBuffer, iBuffer, "::%s", inst.m_assm->GetString(inst.m_target->name)); NANOCLR_NOCLEANUP(); } -HRESULT CLR_RT_TypeSystem::BuildFieldName( const CLR_RT_FieldDef_Index& fd, char*& szBuffer, size_t& iBuffer ) +HRESULT CLR_RT_TypeSystem::BuildFieldName(const CLR_RT_FieldDef_Index &fd, char *&szBuffer, size_t &iBuffer) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - CLR_RT_FieldDef_Instance inst; - CLR_RT_TypeDef_Instance instOwner; + CLR_RT_FieldDef_Instance inst; + CLR_RT_TypeDef_Instance instOwner; - if(inst .InitializeFromIndex( fd ) == false) NANOCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE); - if(instOwner.InitializeFromField( inst ) == false) NANOCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE); + if (inst.InitializeFromIndex(fd) == false) + NANOCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE); + if (instOwner.InitializeFromField(inst) == false) + NANOCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE); - NANOCLR_CHECK_HRESULT(BuildTypeName( instOwner, szBuffer, iBuffer )); + NANOCLR_CHECK_HRESULT(BuildTypeName(instOwner, szBuffer, iBuffer)); - CLR_SafeSprintf( szBuffer, iBuffer, "::%s", inst.m_assm->GetString( inst.m_target->name ) ); + CLR_SafeSprintf(szBuffer, iBuffer, "::%s", inst.m_assm->GetString(inst.m_target->name)); NANOCLR_NOCLEANUP(); } //--// -bool CLR_RT_TypeSystem::FindVirtualMethodDef( const CLR_RT_TypeDef_Index& cls, const CLR_RT_MethodDef_Index& calleeMD, CLR_RT_MethodDef_Index& idx ) +bool CLR_RT_TypeSystem::FindVirtualMethodDef( + const CLR_RT_TypeDef_Index &cls, + const CLR_RT_MethodDef_Index &calleeMD, + CLR_RT_MethodDef_Index &idx) { NATIVE_PROFILE_CLR_CORE(); CLR_RT_MethodDef_Instance calleeInst; - if(calleeInst.InitializeFromIndex( calleeMD )) + if (calleeInst.InitializeFromIndex(calleeMD)) { - const char* calleeName = calleeInst.m_assm->GetString( calleeInst.m_target->name ); + const char *calleeName = calleeInst.m_assm->GetString(calleeInst.m_target->name); - CLR_RT_TypeDef_Instance inst; inst.InitializeFromMethod( calleeInst ); + CLR_RT_TypeDef_Instance inst; + inst.InitializeFromMethod(calleeInst); - if((inst.m_target->flags & CLR_RECORD_TYPEDEF::TD_Semantics_Mask) == CLR_RECORD_TYPEDEF::TD_Semantics_Interface) + if ((inst.m_target->flags & CLR_RECORD_TYPEDEF::TD_Semantics_Mask) == + CLR_RECORD_TYPEDEF::TD_Semantics_Interface) { // // It's an interface method, it could be that the class is implementing explicitly the method. // Prepend the Interface name to the method name and try again. // - char rgBuffer[ 512 ]; - char* szBuffer = rgBuffer; - size_t iBuffer = MAXSTRLEN(rgBuffer); - - BuildTypeName ( inst, szBuffer, iBuffer, CLR_RT_TypeSystem::TYPENAME_FLAGS_FULL | CLR_RT_TypeSystem::TYPENAME_NESTED_SEPARATOR_DOT, 0 ); - QueueStringToBuffer( szBuffer, iBuffer, "." ); - QueueStringToBuffer( szBuffer, iBuffer, calleeName ); - - if(FindVirtualMethodDef( cls, calleeMD, rgBuffer, idx )) return true; + char rgBuffer[512]; + char *szBuffer = rgBuffer; + size_t iBuffer = MAXSTRLEN(rgBuffer); + + BuildTypeName( + inst, + szBuffer, + iBuffer, + CLR_RT_TypeSystem::TYPENAME_FLAGS_FULL | CLR_RT_TypeSystem::TYPENAME_NESTED_SEPARATOR_DOT, + 0); + QueueStringToBuffer(szBuffer, iBuffer, "."); + QueueStringToBuffer(szBuffer, iBuffer, calleeName); + + if (FindVirtualMethodDef(cls, calleeMD, rgBuffer, idx)) + return true; } - if(FindVirtualMethodDef( cls, calleeMD, calleeName, idx )) return true; + if (FindVirtualMethodDef(cls, calleeMD, calleeName, idx)) + return true; } idx.Clear(); @@ -4070,44 +4369,52 @@ bool CLR_RT_TypeSystem::FindVirtualMethodDef( const CLR_RT_TypeDef_Index& cls, c return false; } -bool CLR_RT_TypeSystem::FindVirtualMethodDef( const CLR_RT_TypeDef_Index& cls, const CLR_RT_MethodDef_Index& calleeMD, const char* calleeName, CLR_RT_MethodDef_Index& idx ) +bool CLR_RT_TypeSystem::FindVirtualMethodDef( + const CLR_RT_TypeDef_Index &cls, + const CLR_RT_MethodDef_Index &calleeMD, + const char *calleeName, + CLR_RT_MethodDef_Index &idx) { NATIVE_PROFILE_CLR_CORE(); - CLR_RT_TypeDef_Instance clsInst ; clsInst .InitializeFromIndex( cls ); - CLR_RT_MethodDef_Instance calleeInst; calleeInst.InitializeFromIndex( calleeMD ); + CLR_RT_TypeDef_Instance clsInst; + clsInst.InitializeFromIndex(cls); + CLR_RT_MethodDef_Instance calleeInst; + calleeInst.InitializeFromIndex(calleeMD); - CLR_RT_Assembly* calleeAssm = calleeInst.m_assm; - const CLR_RECORD_METHODDEF* calleeMDR = calleeInst.m_target; - CLR_UINT8 calleeNumArgs = calleeMDR->numArgs; + CLR_RT_Assembly *calleeAssm = calleeInst.m_assm; + const CLR_RECORD_METHODDEF *calleeMDR = calleeInst.m_target; + CLR_UINT8 calleeNumArgs = calleeMDR->numArgs; - while(NANOCLR_INDEX_IS_VALID(clsInst)) + while (NANOCLR_INDEX_IS_VALID(clsInst)) { - CLR_RT_Assembly* targetAssm = clsInst.m_assm; - const CLR_RECORD_TYPEDEF* targetTDR = clsInst.m_target; - const CLR_RECORD_METHODDEF* targetMDR = targetAssm->GetMethodDef( targetTDR->methods_First ); - int num = targetTDR->vMethods_Num + targetTDR->iMethods_Num; + CLR_RT_Assembly *targetAssm = clsInst.m_assm; + const CLR_RECORD_TYPEDEF *targetTDR = clsInst.m_target; + const CLR_RECORD_METHODDEF *targetMDR = targetAssm->GetMethodDef(targetTDR->methods_First); + int num = targetTDR->vMethods_Num + targetTDR->iMethods_Num; - for(int i=0; inumArgs == calleeNumArgs && (targetMDR->flags & CLR_RECORD_METHODDEF::MD_Abstract) == 0) + if (targetMDR->numArgs == calleeNumArgs && (targetMDR->flags & CLR_RECORD_METHODDEF::MD_Abstract) == 0) { - const char* targetName = targetAssm->GetString( targetMDR->name ); + const char *targetName = targetAssm->GetString(targetMDR->name); - if(!strcmp( targetName, calleeName )) + if (!strcmp(targetName, calleeName)) { - CLR_RT_SignatureParser parserLeft ; parserLeft .Initialize_MethodSignature( calleeAssm, calleeMDR ); - CLR_RT_SignatureParser parserRight; parserRight.Initialize_MethodSignature( targetAssm, targetMDR ); + CLR_RT_SignatureParser parserLeft; + parserLeft.Initialize_MethodSignature(calleeAssm, calleeMDR); + CLR_RT_SignatureParser parserRight; + parserRight.Initialize_MethodSignature(targetAssm, targetMDR); - if(CLR_RT_TypeSystem::MatchSignature( parserLeft, parserRight )) + if (CLR_RT_TypeSystem::MatchSignature(parserLeft, parserRight)) { - idx.Set( targetAssm->m_idx, i + targetTDR->methods_First ); + idx.Set(targetAssm->m_idx, i + targetTDR->methods_First); return true; } @@ -4123,99 +4430,102 @@ bool CLR_RT_TypeSystem::FindVirtualMethodDef( const CLR_RT_TypeDef_Index& cls, c return false; } -CLR_DataType CLR_RT_TypeSystem::MapElementTypeToDataType( CLR_UINT32 et ) +CLR_DataType CLR_RT_TypeSystem::MapElementTypeToDataType(CLR_UINT32 et) { NATIVE_PROFILE_CLR_CORE(); - const CLR_RT_DataTypeLookup* ptr = c_CLR_RT_DataTypeLookup; + const CLR_RT_DataTypeLookup *ptr = c_CLR_RT_DataTypeLookup; - for(CLR_UINT32 num = 0; numm_convertToElementType == et) return (CLR_DataType)num; + if (ptr->m_convertToElementType == et) + return (CLR_DataType)num; } - if(et == ELEMENT_TYPE_I) return DATATYPE_I4; - if(et == ELEMENT_TYPE_U) return DATATYPE_U4; + if (et == ELEMENT_TYPE_I) + return DATATYPE_I4; + if (et == ELEMENT_TYPE_U) + return DATATYPE_U4; return DATATYPE_FIRST_INVALID; } -CLR_UINT32 CLR_RT_TypeSystem::MapDataTypeToElementType( CLR_DataType dt ) +CLR_UINT32 CLR_RT_TypeSystem::MapDataTypeToElementType(CLR_DataType dt) { NATIVE_PROFILE_CLR_CORE(); - return c_CLR_RT_DataTypeLookup[ dt ].m_convertToElementType; + return c_CLR_RT_DataTypeLookup[dt].m_convertToElementType; } //--// -void CLR_RT_AttributeEnumerator::Initialize( CLR_RT_Assembly* assm ) +void CLR_RT_AttributeEnumerator::Initialize(CLR_RT_Assembly *assm) { NATIVE_PROFILE_CLR_CORE(); m_assm = assm; // CLR_RT_Assembly* m_assm; - m_ptr = NULL; // const CLR_RECORD_ATTRIBUTE* m_ptr; - m_num = 0; // int m_num; + m_ptr = NULL; // const CLR_RECORD_ATTRIBUTE* m_ptr; + m_num = 0; // int m_num; // CLR_RECORD_ATTRIBUTE m_data; m_match.Clear(); // CLR_RT_MethodDef_Index m_match; } -void CLR_RT_AttributeEnumerator::Initialize( const CLR_RT_TypeDef_Instance& inst ) +void CLR_RT_AttributeEnumerator::Initialize(const CLR_RT_TypeDef_Instance &inst) { NATIVE_PROFILE_CLR_CORE(); m_data.ownerType = TBL_TypeDef; - m_data.ownerIdx = inst.Type(); + m_data.ownerIdx = inst.Type(); - Initialize( inst.m_assm ); + Initialize(inst.m_assm); } -void CLR_RT_AttributeEnumerator::Initialize( const CLR_RT_FieldDef_Instance& inst ) +void CLR_RT_AttributeEnumerator::Initialize(const CLR_RT_FieldDef_Instance &inst) { NATIVE_PROFILE_CLR_CORE(); m_data.ownerType = TBL_FieldDef; - m_data.ownerIdx = inst.Field(); + m_data.ownerIdx = inst.Field(); - Initialize( inst.m_assm ); + Initialize(inst.m_assm); } -void CLR_RT_AttributeEnumerator::Initialize( const CLR_RT_MethodDef_Instance& inst ) +void CLR_RT_AttributeEnumerator::Initialize(const CLR_RT_MethodDef_Instance &inst) { NATIVE_PROFILE_CLR_CORE(); m_data.ownerType = TBL_MethodDef; - m_data.ownerIdx = inst.Method(); + m_data.ownerIdx = inst.Method(); - Initialize( inst.m_assm ); + Initialize(inst.m_assm); } bool CLR_RT_AttributeEnumerator::Advance() { NATIVE_PROFILE_CLR_CORE(); - const CLR_RECORD_ATTRIBUTE* ptr = m_ptr; - int num = m_num; - CLR_UINT32 key = m_data.Key(); - bool fRes = false; + const CLR_RECORD_ATTRIBUTE *ptr = m_ptr; + int num = m_num; + CLR_UINT32 key = m_data.Key(); + bool fRes = false; - if(ptr == NULL) + if (ptr == NULL) { - ptr = m_assm->GetAttribute( 0 ) - 1; - num = m_assm->m_pTablesSize[ TBL_Attributes ]; + ptr = m_assm->GetAttribute(0) - 1; + num = m_assm->m_pTablesSize[TBL_Attributes]; } - while(num) + while (num) { ptr++; num--; - if(ptr->Key() == key) + if (ptr->Key() == key) { CLR_IDX tk = ptr->constructor; - if(tk & 0x8000) + if (tk & 0x8000) { - m_match = m_assm->m_pCrossReference_MethodRef[ tk & 0x7FFF ].m_target; + m_match = m_assm->m_pCrossReference_MethodRef[tk & 0x7FFF].m_target; } else { - m_match.Set( m_assm->m_idx, tk ); + m_match.Set(m_assm->m_idx, tk); } - m_blob = m_assm->GetSignature( ptr->data ); + m_blob = m_assm->GetSignature(ptr->data); fRes = true; break; @@ -4228,33 +4538,37 @@ bool CLR_RT_AttributeEnumerator::Advance() return fRes; } -void CLR_RT_AttributeEnumerator::GetCurrent( CLR_RT_TypeDef_Instance* instTD ) +void CLR_RT_AttributeEnumerator::GetCurrent(CLR_RT_TypeDef_Instance *instTD) { CLR_RT_MethodDef_Instance md; - md.InitializeFromIndex ( m_match ); - instTD->InitializeFromMethod( md ); + md.InitializeFromIndex(m_match); + instTD->InitializeFromMethod(md); } -bool CLR_RT_AttributeEnumerator::MatchNext( const CLR_RT_TypeDef_Instance* instTD, const CLR_RT_MethodDef_Instance* instMD ) +bool CLR_RT_AttributeEnumerator::MatchNext( + const CLR_RT_TypeDef_Instance *instTD, + const CLR_RT_MethodDef_Instance *instMD) { NATIVE_PROFILE_CLR_CORE(); - while(Advance()) + while (Advance()) { - if(instMD) + if (instMD) { - if(m_match.m_data != instMD->m_data) continue; + if (m_match.m_data != instMD->m_data) + continue; } - if(instTD) + if (instTD) { CLR_RT_MethodDef_Instance md; - CLR_RT_TypeDef_Instance td; + CLR_RT_TypeDef_Instance td; - md.InitializeFromIndex ( m_match ); - td.InitializeFromMethod( md ); + md.InitializeFromIndex(m_match); + td.InitializeFromMethod(md); - if(td.m_data != instTD->m_data) continue; + if (td.m_data != instTD->m_data) + continue; } return true; @@ -4265,24 +4579,23 @@ bool CLR_RT_AttributeEnumerator::MatchNext( const CLR_RT_TypeDef_Instance* instT //--// -HRESULT CLR_RT_AttributeParser::Initialize( const CLR_RT_AttributeEnumerator& en ) +HRESULT CLR_RT_AttributeParser::Initialize(const CLR_RT_AttributeEnumerator &en) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - if(m_md.InitializeFromIndex ( en.m_match ) == false || - m_td.InitializeFromMethod( m_md ) == false ) + if (m_md.InitializeFromIndex(en.m_match) == false || m_td.InitializeFromMethod(m_md) == false) { NANOCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE); } - m_parser.Initialize_MethodSignature( m_md.m_assm, m_md.m_target ); - m_parser.Advance( m_res ); // Skip return value. + m_parser.Initialize_MethodSignature(m_md.m_assm, m_md.m_target); + m_parser.Advance(m_res); // Skip return value. m_assm = en.m_assm; m_blob = en.m_blob; - m_currentPos = 0; + m_currentPos = 0; m_fixed_Count = m_md.m_target->numArgs - 1; m_named_Count = -1; m_constructorParsed = false; @@ -4291,36 +4604,32 @@ HRESULT CLR_RT_AttributeParser::Initialize( const CLR_RT_AttributeEnumerator& en NANOCLR_NOCLEANUP(); } -HRESULT CLR_RT_AttributeParser::Next( Value*& res ) +HRESULT CLR_RT_AttributeParser::Next(Value *&res) { NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - if(m_currentPos == m_fixed_Count) + if (m_currentPos == m_fixed_Count) { - NANOCLR_READ_UNALIGNED_UINT16(m_named_Count,m_blob); + NANOCLR_READ_UNALIGNED_UINT16(m_named_Count, m_blob); } - if( m_fixed_Count == 0 && - m_named_Count == 0 && - !m_constructorParsed ) + if (m_fixed_Count == 0 && m_named_Count == 0 && !m_constructorParsed) { // Attribute class has no fields, no properties and only default constructor m_lastValue.m_mode = Value::c_DefaultConstructor; m_lastValue.m_name = NULL; - NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.NewObject( m_lastValue.m_value, m_td )); + NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.NewObject(m_lastValue.m_value, m_td)); res = &m_lastValue; m_constructorParsed = true; NANOCLR_SET_AND_LEAVE(S_OK); - } - else if((m_currentPos < m_fixed_Count) && - !m_constructorParsed ) + else if ((m_currentPos < m_fixed_Count) && !m_constructorParsed) { // Attribute class has a constructor @@ -4330,34 +4639,38 @@ HRESULT CLR_RT_AttributeParser::Next( Value*& res ) //////////////////////////////////////////////// // need to read the arguments from the blob - NANOCLR_CHECK_HRESULT(m_parser.Advance( m_res )); + NANOCLR_CHECK_HRESULT(m_parser.Advance(m_res)); // // Skip value info. // m_blob += sizeof(CLR_UINT8); - const CLR_RT_DataTypeLookup& dtl = c_CLR_RT_DataTypeLookup[ m_res.m_dt ]; + const CLR_RT_DataTypeLookup &dtl = c_CLR_RT_DataTypeLookup[m_res.m_dt]; - if(dtl.m_flags & CLR_RT_DataTypeLookup::c_Numeric) + if (dtl.m_flags & CLR_RT_DataTypeLookup::c_Numeric) { // size of value CLR_UINT32 size = dtl.m_sizeInBytes; - NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.NewObjectFromIndex(m_lastValue.m_value, g_CLR_RT_WellKnownTypes.m_TypeStatic)); + NANOCLR_CHECK_HRESULT( + g_CLR_RT_ExecutionEngine.NewObjectFromIndex(m_lastValue.m_value, g_CLR_RT_WellKnownTypes.m_TypeStatic)); // need to setup reflection and data type Id to properly setup the object m_lastValue.m_value.SetReflection(*dtl.m_cls); - m_lastValue.m_value.SetDataId( CLR_RT_HEAPBLOCK_RAW_ID(m_res.m_dt, 0, 1) ); + m_lastValue.m_value.SetDataId(CLR_RT_HEAPBLOCK_RAW_ID(m_res.m_dt, 0, 1)); - // because this is a numeric object, performa a raw copy of the numeric value data from the blob to the return value - memcpy( (CLR_UINT8*)&m_lastValue.m_value.NumericByRef(), m_blob, size ); m_blob += size; + // because this is a numeric object, performa a raw copy of the numeric value data from the blob to the + // return value + memcpy((CLR_UINT8 *)&m_lastValue.m_value.NumericByRef(), m_blob, size); + m_blob += size; } - else if(m_res.m_dt == DATATYPE_STRING) + else if (m_res.m_dt == DATATYPE_STRING) { - CLR_UINT32 tk; NANOCLR_READ_UNALIGNED_UINT16(tk,m_blob); + CLR_UINT32 tk; + NANOCLR_READ_UNALIGNED_UINT16(tk, m_blob); - CLR_RT_HeapBlock_String::CreateInstance( m_lastValue.m_value, CLR_TkFromType( TBL_Strings, tk ), m_assm ); + CLR_RT_HeapBlock_String::CreateInstance(m_lastValue.m_value, CLR_TkFromType(TBL_Strings, tk), m_assm); } else { @@ -4370,27 +4683,27 @@ HRESULT CLR_RT_AttributeParser::Next( Value*& res ) NANOCLR_SET_AND_LEAVE(S_OK); } - else if(m_currentPos < m_fixed_Count + m_named_Count && - !m_constructorParsed ) + else if (m_currentPos < m_fixed_Count + m_named_Count && !m_constructorParsed) { // Attribute class has named fields - CLR_UINT32 kind; NANOCLR_READ_UNALIGNED_UINT8(kind,m_blob); + CLR_UINT32 kind; + NANOCLR_READ_UNALIGNED_UINT8(kind, m_blob); m_lastValue.m_name = GetString(); - if(kind == SERIALIZATION_TYPE_FIELD) + if (kind == SERIALIZATION_TYPE_FIELD) { - CLR_RT_FieldDef_Index fd; + CLR_RT_FieldDef_Index fd; CLR_RT_FieldDef_Instance inst; m_lastValue.m_mode = Value::c_NamedField; - NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.FindFieldDef( m_td, m_lastValue.m_name, fd )); + NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.FindFieldDef(m_td, m_lastValue.m_name, fd)); - inst.InitializeFromIndex( fd ); + inst.InitializeFromIndex(fd); - m_parser.Initialize_FieldDef( inst.m_assm, inst.m_target ); + m_parser.Initialize_FieldDef(inst.m_assm, inst.m_target); } else { @@ -4410,18 +4723,19 @@ HRESULT CLR_RT_AttributeParser::Next( Value*& res ) NANOCLR_SET_AND_LEAVE(S_OK); } - NANOCLR_CHECK_HRESULT(m_parser.Advance( m_res )); + NANOCLR_CHECK_HRESULT(m_parser.Advance(m_res)); res = &m_lastValue; // // Check for Enums. // - if(m_res.m_dt == DATATYPE_VALUETYPE) + if (m_res.m_dt == DATATYPE_VALUETYPE) { - CLR_RT_TypeDef_Instance td; td.InitializeFromIndex( m_res.m_cls ); + CLR_RT_TypeDef_Instance td; + td.InitializeFromIndex(m_res.m_cls); - if((td.m_target->flags & CLR_RECORD_TYPEDEF::TD_Semantics_Mask) == CLR_RECORD_TYPEDEF::TD_Semantics_Enum) + if ((td.m_target->flags & CLR_RECORD_TYPEDEF::TD_Semantics_Mask) == CLR_RECORD_TYPEDEF::TD_Semantics_Enum) { m_res.m_dt = (CLR_DataType)td.m_target->dataType; } @@ -4433,24 +4747,26 @@ HRESULT CLR_RT_AttributeParser::Next( Value*& res ) m_blob += sizeof(CLR_UINT8); { - const CLR_RT_DataTypeLookup& dtl = c_CLR_RT_DataTypeLookup[ m_res.m_dt ]; + const CLR_RT_DataTypeLookup &dtl = c_CLR_RT_DataTypeLookup[m_res.m_dt]; - if(dtl.m_flags & CLR_RT_DataTypeLookup::c_Numeric) + if (dtl.m_flags & CLR_RT_DataTypeLookup::c_Numeric) { // need to setup reflection and data type Id to properly setup the object m_lastValue.m_value.SetReflection(m_res.m_cls); - m_lastValue.m_value.SetDataId( CLR_RT_HEAPBLOCK_RAW_ID(m_res.m_dt, 0, 1) ); + m_lastValue.m_value.SetDataId(CLR_RT_HEAPBLOCK_RAW_ID(m_res.m_dt, 0, 1)); CLR_UINT32 size = dtl.m_sizeInBytes; - memcpy( &m_lastValue.m_value.NumericByRef(), m_blob, size ); m_blob += size; + memcpy(&m_lastValue.m_value.NumericByRef(), m_blob, size); + m_blob += size; } - else if(m_res.m_dt == DATATYPE_STRING) + else if (m_res.m_dt == DATATYPE_STRING) { - CLR_UINT32 tk; NANOCLR_READ_UNALIGNED_UINT16(tk,m_blob); + CLR_UINT32 tk; + NANOCLR_READ_UNALIGNED_UINT16(tk, m_blob); - CLR_RT_HeapBlock_String::CreateInstance( m_lastValue.m_value, CLR_TkFromType( TBL_Strings, tk ), m_assm ); + CLR_RT_HeapBlock_String::CreateInstance(m_lastValue.m_value, CLR_TkFromType(TBL_Strings, tk), m_assm); } else { @@ -4463,10 +4779,11 @@ HRESULT CLR_RT_AttributeParser::Next( Value*& res ) NANOCLR_NOCLEANUP(); } -const char* CLR_RT_AttributeParser::GetString() +const char *CLR_RT_AttributeParser::GetString() { NATIVE_PROFILE_CLR_CORE(); - CLR_UINT32 tk; NANOCLR_READ_UNALIGNED_UINT16(tk,m_blob); + CLR_UINT32 tk; + NANOCLR_READ_UNALIGNED_UINT16(tk, m_blob); - return m_assm->GetString( tk ); + return m_assm->GetString(tk); } diff --git a/src/CLR/Core/TypeSystemLookup.cpp b/src/CLR/Core/TypeSystemLookup.cpp index 7be8e05411..bac70fd8d7 100644 --- a/src/CLR/Core/TypeSystemLookup.cpp +++ b/src/CLR/Core/TypeSystemLookup.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Core/Various.cpp b/src/CLR/Core/Various.cpp index b810979a74..433d30c299 100644 --- a/src/CLR/Core/Various.cpp +++ b/src/CLR/Core/Various.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Core/corhdr_private.h b/src/CLR/Core/corhdr_private.h index b9e98a54ed..081f531209 100644 --- a/src/CLR/Core/corhdr_private.h +++ b/src/CLR/Core/corhdr_private.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Core/nanoSupport_CRC32.c b/src/CLR/Core/nanoSupport_CRC32.c index 85ef81de81..d37621e65a 100644 --- a/src/CLR/Core/nanoSupport_CRC32.c +++ b/src/CLR/Core/nanoSupport_CRC32.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Debugger/CMakeLists.txt b/src/CLR/Debugger/CMakeLists.txt index ab90ee1a21..e112f3b5bc 100644 --- a/src/CLR/Debugger/CMakeLists.txt +++ b/src/CLR/Debugger/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/src/CLR/Debugger/Debugger.cpp b/src/CLR/Debugger/Debugger.cpp index 7c0a9003ed..75f07fa443 100644 --- a/src/CLR/Debugger/Debugger.cpp +++ b/src/CLR/Debugger/Debugger.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // @@ -12,11 +12,11 @@ #include "Debugger.h" #include -#define __min(a,b) (((a) < (b)) ? (a) : (b)) +#define __min(a, b) (((a) < (b)) ? (a) : (b)) #if 0 -#define TRACE0( msg, ...) debug_printf( msg ) -#define TRACE( msg, ...) debug_printf( msg, __VA_ARGS__ ) +#define TRACE0(msg, ...) debug_printf(msg) +#define TRACE(msg, ...) debug_printf(msg, __VA_ARGS__) char const* const AccessMemoryModeNames[] = { "AccessMemory_Check", "AccessMemory_Read", @@ -24,8 +24,8 @@ char const* const AccessMemoryModeNames[] = { "AccessMemory_Erase" }; #else -#define TRACE0(msg,...) -#define TRACE(msg,...) +#define TRACE0(msg, ...) +#define TRACE(msg, ...) #endif //--// @@ -33,9 +33,9 @@ char const* const AccessMemoryModeNames[] = { extern const CLR_RT_NativeAssemblyData *g_CLR_InteropAssembliesNativeData[]; extern uint16_t g_CLR_InteropAssembliesCount; -CLR_DBG_Debugger* g_CLR_DBG_Debugger; +CLR_DBG_Debugger *g_CLR_DBG_Debugger; -BlockStorageDevice* CLR_DBG_Debugger::m_deploymentStorageDevice = NULL; +BlockStorageDevice *CLR_DBG_Debugger::m_deploymentStorageDevice = NULL; //--// @@ -44,10 +44,10 @@ void CLR_DBG_Debugger::Debugger_WaitForCommands() NATIVE_PROFILE_CLR_DEBUGGER(); #if !defined(BUILD_RTM) - CLR_Debug::Printf( "Waiting for debug commands...\r\n" ); + CLR_Debug::Printf("Waiting for debug commands...\r\n"); #endif - while( !CLR_EE_DBG_IS(RebootPending) && !CLR_EE_DBG_IS(ExitPending) ) + while (!CLR_EE_DBG_IS(RebootPending) && !CLR_EE_DBG_IS(ExitPending)) { g_CLR_RT_ExecutionEngine.DebuggerLoop(); } @@ -65,31 +65,35 @@ void CLR_DBG_Debugger::Debugger_Discovery() Monitor_Ping_Command cmd; cmd.m_source = Monitor_Ping_c_Ping_Source_NanoCLR; - while(true) + while (true) { - CLR_EE_DBG_EVENT_BROADCAST(CLR_DBG_Commands::c_Monitor_Ping, sizeof(cmd), &cmd, WP_Flags_c_NoCaching | WP_Flags_c_NonCritical); + CLR_EE_DBG_EVENT_BROADCAST( + CLR_DBG_Commands::c_Monitor_Ping, + sizeof(cmd), + &cmd, + WP_Flags_c_NoCaching | WP_Flags_c_NonCritical); // if we support soft reboot and the debugger is not stopped then we don't need to connect the debugger - if(!CLR_EE_DBG_IS(Stopped) && ::CPU_IsSoftRebootSupported()) + if (!CLR_EE_DBG_IS(Stopped) && ::CPU_IsSoftRebootSupported()) { break; } g_CLR_RT_ExecutionEngine.DebuggerLoop(); - if(CLR_EE_DBG_IS(Enabled)) + if (CLR_EE_DBG_IS(Enabled)) { // Debugger on the other side, let's exit the discovery loop. - CLR_Debug::Printf( "Debugger found. Resuming boot sequence.\r\n" ); + CLR_Debug::Printf("Debugger found. Resuming boot sequence.\r\n"); break; } CLR_INT64 now = HAL_Time_CurrentTime(); - if(expire < now) + if (expire < now) { // no response after timeout... - CLR_Debug::Printf( "No debugger found...\r\n" ); + CLR_Debug::Printf("No debugger found...\r\n"); break; } } @@ -105,18 +109,18 @@ HRESULT CLR_DBG_Debugger::CreateInstance() NANOCLR_HEADER(); // alloc memory for debugger - g_CLR_DBG_Debugger = (CLR_DBG_Debugger*)platform_malloc(sizeof(CLR_DBG_Debugger)); + g_CLR_DBG_Debugger = (CLR_DBG_Debugger *)platform_malloc(sizeof(CLR_DBG_Debugger)); - // sanity check... + // sanity check... FAULT_ON_NULL(g_CLR_DBG_Debugger); //... and clear memory memset(g_CLR_DBG_Debugger, 0, sizeof(CLR_DBG_Debugger)); // alloc memory for debugger messaging - g_CLR_DBG_Debugger->m_messaging = (CLR_Messaging*)platform_malloc(sizeof(CLR_Messaging)); - - // sanity check... + g_CLR_DBG_Debugger->m_messaging = (CLR_Messaging *)platform_malloc(sizeof(CLR_Messaging)); + + // sanity check... FAULT_ON_NULL(g_CLR_DBG_Debugger->m_messaging); //... and clear memory @@ -127,7 +131,7 @@ HRESULT CLR_DBG_Debugger::CreateInstance() BlockStorageStream stream; memset(&stream, 0, sizeof(BlockStorageStream)); - if (BlockStorageStream_Initialize(&stream, BlockUsage_DEPLOYMENT )) + if (BlockStorageStream_Initialize(&stream, BlockUsage_DEPLOYMENT)) { m_deploymentStorageDevice = stream.Device; } @@ -141,14 +145,18 @@ HRESULT CLR_DBG_Debugger::CreateInstance() NANOCLR_NOCLEANUP(); } -HRESULT CLR_DBG_Debugger::Debugger_Initialize( COM_HANDLE port ) +HRESULT CLR_DBG_Debugger::Debugger_Initialize(COM_HANDLE port) { (void)port; NATIVE_PROFILE_CLR_DEBUGGER(); NANOCLR_HEADER(); - m_messaging->Initialize( c_Debugger_Lookup_Request, c_Debugger_Lookup_Request_count, c_Debugger_Lookup_Reply, c_Debugger_Lookup_Reply_count ); + m_messaging->Initialize( + c_Debugger_Lookup_Request, + c_Debugger_Lookup_Request_count, + c_Debugger_Lookup_Reply, + c_Debugger_Lookup_Reply_count); NANOCLR_NOCLEANUP_NOLABEL(); } @@ -187,10 +195,14 @@ void CLR_DBG_Debugger::Debugger_Cleanup() // m_messaging->m_controller.AdvanceState(); // } -void CLR_DBG_Debugger::BroadcastEvent( unsigned int cmd, unsigned int payloadSize, unsigned char* payload, unsigned int flags ) +void CLR_DBG_Debugger::BroadcastEvent( + unsigned int cmd, + unsigned int payloadSize, + unsigned char *payload, + unsigned int flags) { NATIVE_PROFILE_CLR_DEBUGGER(); - WP_PrepareAndSendProtocolMessage( cmd, payloadSize, payload, flags ); + WP_PrepareAndSendProtocolMessage(cmd, payloadSize, payload, flags); } //--// @@ -199,63 +211,66 @@ void CLR_DBG_Debugger::BroadcastEvent( unsigned int cmd, unsigned int payloadSiz #if defined(NANOCLR_APPDOMAINS) -CLR_RT_AppDomain* CLR_DBG_Debugger::GetAppDomainFromID( CLR_UINT32 id ) +CLR_RT_AppDomain *CLR_DBG_Debugger::GetAppDomainFromID(CLR_UINT32 id) { NATIVE_PROFILE_CLR_DEBUGGER(); NANOCLR_FOREACH_NODE(CLR_RT_AppDomain, appDomain, g_CLR_RT_ExecutionEngine.m_appDomains) { - if(appDomain->m_id == id) return appDomain; + if (appDomain->m_id == id) + return appDomain; } NANOCLR_FOREACH_NODE_END(); return NULL; } -#endif //NANOCLR_APPDOMAINS +#endif // NANOCLR_APPDOMAINS -CLR_RT_Thread* CLR_DBG_Debugger::GetThreadFromPid( CLR_INT32 pid ) +CLR_RT_Thread *CLR_DBG_Debugger::GetThreadFromPid(CLR_INT32 pid) { NATIVE_PROFILE_CLR_DEBUGGER(); - NANOCLR_FOREACH_NODE(CLR_RT_Thread,th,g_CLR_RT_ExecutionEngine.m_threadsReady) + NANOCLR_FOREACH_NODE(CLR_RT_Thread, th, g_CLR_RT_ExecutionEngine.m_threadsReady) { - if(th->m_pid == pid) return th; + if (th->m_pid == pid) + return th; } NANOCLR_FOREACH_NODE_END(); - NANOCLR_FOREACH_NODE(CLR_RT_Thread,th,g_CLR_RT_ExecutionEngine.m_threadsWaiting) + NANOCLR_FOREACH_NODE(CLR_RT_Thread, th, g_CLR_RT_ExecutionEngine.m_threadsWaiting) { - if(th->m_pid == pid) return th; + if (th->m_pid == pid) + return th; } NANOCLR_FOREACH_NODE_END(); return NULL; } -HRESULT CLR_DBG_Debugger::CreateListOfThreads( CLR_DBG_Commands::Debugging_Thread_List::Reply*& cmdReply, int& totLen ) +HRESULT CLR_DBG_Debugger::CreateListOfThreads(CLR_DBG_Commands::Debugging_Thread_List::Reply *&cmdReply, int &totLen) { NATIVE_PROFILE_CLR_DEBUGGER(); NANOCLR_HEADER(); - CLR_UINT32* pidDst; - int num; + CLR_UINT32 *pidDst; + int num; - num = g_CLR_RT_ExecutionEngine.m_threadsReady .NumOfNodes() + - g_CLR_RT_ExecutionEngine.m_threadsWaiting.NumOfNodes(); + num = g_CLR_RT_ExecutionEngine.m_threadsReady.NumOfNodes() + g_CLR_RT_ExecutionEngine.m_threadsWaiting.NumOfNodes(); - totLen = sizeof(*cmdReply) + (num-1) * sizeof(CLR_UINT32); + totLen = sizeof(*cmdReply) + (num - 1) * sizeof(CLR_UINT32); - cmdReply = (CLR_DBG_Commands::Debugging_Thread_List::Reply*)CLR_RT_Memory::Allocate_And_Erase( totLen, true ); CHECK_ALLOCATION(cmdReply); + cmdReply = (CLR_DBG_Commands::Debugging_Thread_List::Reply *)CLR_RT_Memory::Allocate_And_Erase(totLen, true); + CHECK_ALLOCATION(cmdReply); cmdReply->m_num = num; pidDst = cmdReply->m_pids; - NANOCLR_FOREACH_NODE(CLR_RT_Thread,thSrc,g_CLR_RT_ExecutionEngine.m_threadsReady) + NANOCLR_FOREACH_NODE(CLR_RT_Thread, thSrc, g_CLR_RT_ExecutionEngine.m_threadsReady) { *pidDst++ = thSrc->m_pid; } NANOCLR_FOREACH_NODE_END(); - NANOCLR_FOREACH_NODE(CLR_RT_Thread,thSrc,g_CLR_RT_ExecutionEngine.m_threadsWaiting) + NANOCLR_FOREACH_NODE(CLR_RT_Thread, thSrc, g_CLR_RT_ExecutionEngine.m_threadsWaiting) { *pidDst++ = thSrc->m_pid; } @@ -264,57 +279,61 @@ HRESULT CLR_DBG_Debugger::CreateListOfThreads( CLR_DBG_Commands::Debugging_Threa NANOCLR_NOCLEANUP(); } -HRESULT CLR_DBG_Debugger::CreateListOfCalls( CLR_INT32 pid, CLR_DBG_Commands::Debugging_Thread_Stack::Reply*& cmdReply, int& totLen ) +HRESULT CLR_DBG_Debugger::CreateListOfCalls( + CLR_INT32 pid, + CLR_DBG_Commands::Debugging_Thread_Stack::Reply *&cmdReply, + int &totLen) { NATIVE_PROFILE_CLR_DEBUGGER(); NANOCLR_HEADER(); - CLR_RT_Thread* th = GetThreadFromPid( pid ); FAULT_ON_NULL(th); + CLR_RT_Thread *th = GetThreadFromPid(pid); + FAULT_ON_NULL(th); - for(int pass=0; pass<2; pass++) + for (int pass = 0; pass < 2; pass++) { int num = 0; - NANOCLR_FOREACH_NODE(CLR_RT_StackFrame,call,th->m_stackFrames) + NANOCLR_FOREACH_NODE(CLR_RT_StackFrame, call, th->m_stackFrames) { - if(pass == 1) + if (pass == 1) { int tmp = num; - + #ifndef CLR_NO_IL_INLINE - if(call->m_inlineFrame) + if (call->m_inlineFrame) { - CLR_DBG_Commands::Debugging_Thread_Stack::Reply::Call& dst = cmdReply->m_data[ tmp++ ]; - - dst.m_md = call->m_inlineFrame->m_frame.m_call; + CLR_DBG_Commands::Debugging_Thread_Stack::Reply::Call &dst = cmdReply->m_data[tmp++]; + + dst.m_md = call->m_inlineFrame->m_frame.m_call; dst.m_IP = (CLR_UINT32)(call->m_inlineFrame->m_frame.m_IP - call->m_inlineFrame->m_frame.m_IPStart); #if defined(NANOCLR_APPDOMAINS) dst.m_appDomainID = call->m_appDomain->m_id; - dst.m_flags = call->m_flags; + dst.m_flags = call->m_flags; #endif } #endif - CLR_DBG_Commands::Debugging_Thread_Stack::Reply::Call& dst = cmdReply->m_data[ tmp ]; + CLR_DBG_Commands::Debugging_Thread_Stack::Reply::Call &dst = cmdReply->m_data[tmp]; - dst.m_md = call->m_call; + dst.m_md = call->m_call; dst.m_IP = (CLR_UINT32)(call->m_IP - call->m_IPstart); - if(dst.m_IP && call != th->CurrentFrame()) + if (dst.m_IP && call != th->CurrentFrame()) { - //With the exception of when the IP is 0, for a breakpoint on Push, - //The call->m_IP is the next instruction to execute, not the currently executing one. - //For non-leaf frames, this will return the IP within the call. + // With the exception of when the IP is 0, for a breakpoint on Push, + // The call->m_IP is the next instruction to execute, not the currently executing one. + // For non-leaf frames, this will return the IP within the call. dst.m_IP--; } #if defined(NANOCLR_APPDOMAINS) dst.m_appDomainID = call->m_appDomain->m_id; - dst.m_flags = call->m_flags; + dst.m_flags = call->m_flags; #endif } #ifndef CLR_NO_IL_INLINE - if(call->m_inlineFrame) + if (call->m_inlineFrame) { num++; } @@ -324,15 +343,18 @@ HRESULT CLR_DBG_Debugger::CreateListOfCalls( CLR_INT32 pid, CLR_DBG_Commands::De } NANOCLR_FOREACH_NODE_END(); - if(pass == 0) + if (pass == 0) { - totLen = sizeof(*cmdReply) + (num-1) * sizeof(CLR_DBG_Commands::Debugging_Thread_Stack::Reply::Call); + totLen = sizeof(*cmdReply) + (num - 1) * sizeof(CLR_DBG_Commands::Debugging_Thread_Stack::Reply::Call); - cmdReply = (CLR_DBG_Commands::Debugging_Thread_Stack::Reply*)CLR_RT_Memory::Allocate_And_Erase( totLen, CLR_RT_HeapBlock::HB_CompactOnFailure ); CHECK_ALLOCATION(cmdReply); + cmdReply = (CLR_DBG_Commands::Debugging_Thread_Stack::Reply *)CLR_RT_Memory::Allocate_And_Erase( + totLen, + CLR_RT_HeapBlock::HB_CompactOnFailure); + CHECK_ALLOCATION(cmdReply); - cmdReply->m_num = num; + cmdReply->m_num = num; cmdReply->m_status = th->m_status; - cmdReply->m_flags = th->m_flags; + cmdReply->m_flags = th->m_flags; } } @@ -343,7 +365,7 @@ HRESULT CLR_DBG_Debugger::CreateListOfCalls( CLR_INT32 pid, CLR_DBG_Commands::De //////////////////////////////////////////////////////////////////////////////////////////////////// -bool CLR_DBG_Debugger::Monitor_Ping( WP_Message* msg) +bool CLR_DBG_Debugger::Monitor_Ping(WP_Message *msg) { NATIVE_PROFILE_CLR_DEBUGGER(); bool fStopOnBoot = true; @@ -351,59 +373,61 @@ bool CLR_DBG_Debugger::Monitor_Ping( WP_Message* msg) // // There's someone on the other side!! // - CLR_EE_DBG_SET( Enabled ); + CLR_EE_DBG_SET(Enabled); - if((msg->m_header.m_flags & WP_Flags_c_Reply ) == 0) + if ((msg->m_header.m_flags & WP_Flags_c_Reply) == 0) { Monitor_Ping_Reply cmdReply; - Monitor_Ping_Command *cmd = (Monitor_Ping_Command*)msg->m_payload; + Monitor_Ping_Command *cmd = (Monitor_Ping_Command *)msg->m_payload; // default is to stop the debugger (backwards compatibility) fStopOnBoot = (cmd != NULL) && (cmd->m_dbg_flags & Monitor_Ping_c_Ping_DbgFlag_Stop); - cmdReply.m_source = Monitor_Ping_c_Ping_Source_NanoCLR; + cmdReply.m_source = Monitor_Ping_c_Ping_Source_NanoCLR; cmdReply.m_dbg_flags = CLR_EE_DBG_IS(StateProgramExited) != 0 ? Monitor_Ping_c_Ping_DbgFlag_AppExit : 0; - #if defined(WP_IMPLEMENTS_CRC32) +#if defined(WP_IMPLEMENTS_CRC32) cmdReply.m_dbg_flags |= Monitor_Ping_c_Ping_WPFlag_SupportsCRC32; - #endif - - // Wire Protocol packet size - #if (WP_PACKET_SIZE == 512) +#endif + + // Wire Protocol packet size +#if (WP_PACKET_SIZE == 512) cmdReply.m_dbg_flags |= Monitor_Ping_c_PacketSize_0512; - #elif (WP_PACKET_SIZE == 256) +#elif (WP_PACKET_SIZE == 256) cmdReply.m_dbg_flags |= Monitor_Ping_c_PacketSize_0256; - #elif (WP_PACKET_SIZE == 128) +#elif (WP_PACKET_SIZE == 128) cmdReply.m_dbg_flags |= Monitor_Ping_c_PacketSize_0128; - #elif (WP_PACKET_SIZE == 1024) +#elif (WP_PACKET_SIZE == 1024) cmdReply.m_dbg_flags |= Monitor_Ping_c_PacketSize_1024; - #endif +#endif - WP_ReplyToCommand( msg, true, false, &cmdReply, sizeof(cmdReply) ); + WP_ReplyToCommand(msg, true, false, &cmdReply, sizeof(cmdReply)); } else { - Monitor_Ping_Reply *cmdReply = (Monitor_Ping_Reply*)msg->m_payload; + Monitor_Ping_Reply *cmdReply = (Monitor_Ping_Reply *)msg->m_payload; // default is to stop the debugger (backwards compatibility) fStopOnBoot = (cmdReply != NULL) && (cmdReply->m_dbg_flags & Monitor_Ping_c_Ping_DbgFlag_Stop); } - if(CLR_EE_DBG_IS_MASK(StateInitialize, StateMask)) + if (CLR_EE_DBG_IS_MASK(StateInitialize, StateMask)) { - if(fStopOnBoot) CLR_EE_DBG_SET(Stopped); - else CLR_EE_DBG_CLR(Stopped); + if (fStopOnBoot) + CLR_EE_DBG_SET(Stopped); + else + CLR_EE_DBG_CLR(Stopped); } return true; } -bool CLR_DBG_Debugger::Monitor_FlashSectorMap( WP_Message* msg) +bool CLR_DBG_Debugger::Monitor_FlashSectorMap(WP_Message *msg) { - NATIVE_PROFILE_CLR_DEBUGGER(); + NATIVE_PROFILE_CLR_DEBUGGER(); - if((msg->m_header.m_flags & WP_Flags_c_Reply) == 0) + if ((msg->m_header.m_flags & WP_Flags_c_Reply) == 0) { struct Flash_BlockRegionInfo { @@ -421,59 +445,62 @@ bool CLR_DBG_Debugger::Monitor_FlashSectorMap( WP_Message* msg) unsigned int numDevices = BlockStorageList_GetNumDevices(); // get an array of pointer to all the storage devices in the list and then request the device info - BlockStorageDevice** devices = (BlockStorageDevice**) platform_malloc(numDevices * sizeof(BlockStorageDevice*)); - DeviceBlockInfo** deviceInfos = (DeviceBlockInfo**) platform_malloc(numDevices * sizeof(DeviceBlockInfo*)); + BlockStorageDevice **devices = + (BlockStorageDevice **)platform_malloc(numDevices * sizeof(BlockStorageDevice *)); + DeviceBlockInfo **deviceInfos = (DeviceBlockInfo **)platform_malloc(numDevices * sizeof(DeviceBlockInfo *)); - for(unsigned int i = 0; i < numDevices; i++) + for (unsigned int i = 0; i < numDevices; i++) { - if(i == 0) + if (i == 0) { devices[i] = BlockStorageList_GetFirstDevice(); - } + } else { - devices[i] = BlockStorageList_GetNextDevice(devices[i-1]); + devices[i] = BlockStorageList_GetNextDevice(devices[i - 1]); } // sanity check - if(devices[i] == NULL) + if (devices[i] == NULL) { - WP_ReplyToCommand( msg, true, false, NULL, 0 ); + WP_ReplyToCommand(msg, true, false, NULL, 0); return false; } deviceInfos[i] = BlockStorageDevice_GetDeviceInfo(devices[i]); } - - for(int cnt = 0; cnt < 2; cnt++) + + for (int cnt = 0; cnt < 2; cnt++) { - if(cnt == 1) + if (cnt == 1) { - pData = (struct Flash_BlockRegionInfo*)platform_malloc(rangeCount * sizeof(struct Flash_BlockRegionInfo)); + pData = + (struct Flash_BlockRegionInfo *)platform_malloc(rangeCount * sizeof(struct Flash_BlockRegionInfo)); - if(pData == NULL) + if (pData == NULL) { - WP_ReplyToCommand( msg, true, false, NULL, 0 ); + WP_ReplyToCommand(msg, true, false, NULL, 0); return false; } } - for(unsigned int i = 0; i < numDevices; i++) + for (unsigned int i = 0; i < numDevices; i++) { - for(unsigned int j = 0; j < deviceInfos[i]->NumRegions; j++) + for (unsigned int j = 0; j < deviceInfos[i]->NumRegions; j++) { - const BlockRegionInfo* pRegion = &deviceInfos[i]->Regions[ j ]; + const BlockRegionInfo *pRegion = &deviceInfos[i]->Regions[j]; - for(unsigned int k = 0; k < pRegion->NumBlockRanges; k++) + for (unsigned int k = 0; k < pRegion->NumBlockRanges; k++) { - if(cnt == 0) + if (cnt == 0) { rangeCount++; } else { - pData[ rangeIndex ].StartAddress = BlockRegionInfo_BlockAddress(pRegion, pRegion->BlockRanges[ k ].StartBlock); - pData[ rangeIndex ].NumBlocks = BlockRange_GetBlockCount(pRegion->BlockRanges[k]); - pData[ rangeIndex ].BytesPerBlock = pRegion->BytesPerBlock; - pData[ rangeIndex ].Usage = pRegion->BlockRanges[ k ].RangeType & BlockRange_USAGE_MASK; + pData[rangeIndex].StartAddress = + BlockRegionInfo_BlockAddress(pRegion, pRegion->BlockRanges[k].StartBlock); + pData[rangeIndex].NumBlocks = BlockRange_GetBlockCount(pRegion->BlockRanges[k]); + pData[rangeIndex].BytesPerBlock = pRegion->BytesPerBlock; + pData[rangeIndex].Usage = pRegion->BlockRanges[k].RangeType & BlockRange_USAGE_MASK; rangeIndex++; } } @@ -481,8 +508,7 @@ bool CLR_DBG_Debugger::Monitor_FlashSectorMap( WP_Message* msg) } } - - WP_ReplyToCommand( msg, true, false, (void*)pData, rangeCount * sizeof (struct Flash_BlockRegionInfo) ); + WP_ReplyToCommand(msg, true, false, (void *)pData, rangeCount * sizeof(struct Flash_BlockRegionInfo)); platform_free(pData); platform_free(devices); @@ -490,46 +516,39 @@ bool CLR_DBG_Debugger::Monitor_FlashSectorMap( WP_Message* msg) } return true; - } //--// - - - - - - -bool CLR_DBG_Debugger::CheckPermission( ByteAddress address, int mode ) +bool CLR_DBG_Debugger::CheckPermission(ByteAddress address, int mode) { NATIVE_PROFILE_CLR_DEBUGGER(); - bool hasPermission = false; + bool hasPermission = false; unsigned int regionIndex, rangeIndex; - BlockStorageDevice_FindRegionFromAddress(m_deploymentStorageDevice, address, ®ionIndex, &rangeIndex); - const BlockRange& range = BlockStorageDevice_GetDeviceInfo(m_deploymentStorageDevice)->Regions[ regionIndex ].BlockRanges[ rangeIndex ]; - + BlockStorageDevice_FindRegionFromAddress(m_deploymentStorageDevice, address, ®ionIndex, &rangeIndex); + const BlockRange &range = + BlockStorageDevice_GetDeviceInfo(m_deploymentStorageDevice)->Regions[regionIndex].BlockRanges[rangeIndex]; - switch(mode) + switch (mode) { case AccessMemory_Check: hasPermission = true; break; case AccessMemory_Read: #if defined(BUILD_RTM) - if(!DebuggerPort_IsUsingSsl(HalSystemConfig.DebuggerPort)) + if (!DebuggerPort_IsUsingSsl(HalSystemConfig.DebuggerPort)) break; #endif - switch(range.RangeType) + switch (range.RangeType) { - case BlockRange_BLOCKTYPE_CONFIG: // fall through - case BlockRange_BLOCKTYPE_BOOTSTRAP: // fall through - case BlockRange_BLOCKTYPE_CODE: // fall through - case BlockRange_BLOCKTYPE_DIRTYBIT: // fall through - case BlockRange_BLOCKTYPE_DEPLOYMENT: // fall through - case BlockRange_BLOCKTYPE_FILESYSTEM: // fall through - case BlockRange_BLOCKTYPE_STORAGE_A: // fall through + case BlockRange_BLOCKTYPE_CONFIG: // fall through + case BlockRange_BLOCKTYPE_BOOTSTRAP: // fall through + case BlockRange_BLOCKTYPE_CODE: // fall through + case BlockRange_BLOCKTYPE_DIRTYBIT: // fall through + case BlockRange_BLOCKTYPE_DEPLOYMENT: // fall through + case BlockRange_BLOCKTYPE_FILESYSTEM: // fall through + case BlockRange_BLOCKTYPE_STORAGE_A: // fall through case BlockRange_BLOCKTYPE_STORAGE_B: case BlockRange_BLOCKTYPE_SIMPLE_A: case BlockRange_BLOCKTYPE_SIMPLE_B: @@ -541,10 +560,10 @@ bool CLR_DBG_Debugger::CheckPermission( ByteAddress address, int mode ) break; case AccessMemory_Write: #if defined(BUILD_RTM) - if(!DebuggerPort_IsUsingSsl(HalSystemConfig.DebuggerPort)) + if (!DebuggerPort_IsUsingSsl(HalSystemConfig.DebuggerPort)) break; #endif - if(BlockRange_IsDeployment(range) || BlockRange_IsConfig(range)) + if (BlockRange_IsDeployment(range) || BlockRange_IsConfig(range)) { hasPermission = true; } @@ -555,10 +574,10 @@ bool CLR_DBG_Debugger::CheckPermission( ByteAddress address, int mode ) break; case AccessMemory_Erase: #if defined(BUILD_RTM) - if(!DebuggerPort_IsUsingSsl(HalSystemConfig.DebuggerPort)) + if (!DebuggerPort_IsUsingSsl(HalSystemConfig.DebuggerPort)) break; #endif - switch(range.RangeType) + switch (range.RangeType) { case BlockRange_BLOCKTYPE_DEPLOYMENT: case BlockRange_BLOCKTYPE_FILESYSTEM: @@ -580,109 +599,126 @@ bool CLR_DBG_Debugger::CheckPermission( ByteAddress address, int mode ) return hasPermission; } -bool CLR_DBG_Debugger::AccessMemory( uint32_t location, uint32_t lengthInBytes, uint8_t* buf, uint32_t mode, uint32_t& errorCode ) +void CLR_DBG_Debugger::AccessMemory( + uint32_t location, + uint32_t lengthInBytes, + uint8_t *buf, + uint32_t mode, + uint32_t *errorCode) { NATIVE_PROFILE_CLR_DEBUGGER(); - TRACE("AccessMemory( 0x%08X, 0x%08x, 0x%08X, %s)\n", location, lengthInBytes, buf, AccessMemoryModeNames[mode] ); + TRACE("AccessMemory( 0x%08X, 0x%08x, 0x%08X, %s)\n", location, lengthInBytes, buf, AccessMemoryModeNames[mode]); bool proceed = false; // reset error code - errorCode = AccessMemoryErrorCode_RequestedOperationFailed; + *errorCode = AccessMemoryErrorCode_RequestedOperationFailed; //--// unsigned int iRegion, iRange; if (BlockStorageDevice_FindRegionFromAddress(m_deploymentStorageDevice, location, &iRegion, &iRange)) { - const DeviceBlockInfo* deviceInfo = BlockStorageDevice_GetDeviceInfo(m_deploymentStorageDevice); + const DeviceBlockInfo *deviceInfo = BlockStorageDevice_GetDeviceInfo(m_deploymentStorageDevice); // start from the block where the sector sits. - ByteAddress accessAddress = location; + ByteAddress accessAddress = location; - uint8_t* bufPtr = buf; - signed int accessLenInBytes = lengthInBytes; - signed int blockOffset = BlockRegionInfo_OffsetFromBlock(((BlockRegionInfo*)(&deviceInfo->Regions[iRegion])), accessAddress); + uint8_t *bufPtr = buf; + signed int accessLenInBytes = lengthInBytes; + signed int blockOffset = + BlockRegionInfo_OffsetFromBlock(((BlockRegionInfo *)(&deviceInfo->Regions[iRegion])), accessAddress); - for(;iRegion < deviceInfo->NumRegions; iRegion++) + for (; iRegion < deviceInfo->NumRegions; iRegion++) { - const BlockRegionInfo *pRegion = &deviceInfo->Regions[ iRegion ]; + const BlockRegionInfo *pRegion = &deviceInfo->Regions[iRegion]; - unsigned int blockIndex = BlockRegionInfo_BlockIndexFromAddress(pRegion, accessAddress); - unsigned int accessMaxLength = pRegion->BytesPerBlock - blockOffset; + unsigned int blockIndex = BlockRegionInfo_BlockIndexFromAddress(pRegion, accessAddress); + unsigned int accessMaxLength = pRegion->BytesPerBlock - blockOffset; blockOffset = 0; - for(;blockIndex < pRegion->NumBlocks; blockIndex++) + for (; blockIndex < pRegion->NumBlocks; blockIndex++) { - //accessMaxLength =the current largest number of bytes can be read from the block from the address to its block boundary. + // accessMaxLength =the current largest number of bytes can be read from the block from the address to + // its block boundary. unsigned int NumOfBytes = __min(accessMaxLength, (unsigned int)accessLenInBytes); accessMaxLength = pRegion->BytesPerBlock; - if(blockIndex > pRegion->BlockRanges[ iRange ].EndBlock) + if (blockIndex > pRegion->BlockRanges[iRange].EndBlock) { iRange++; - if(iRange >= pRegion->NumBlockRanges) + if (iRange >= pRegion->NumBlockRanges) { ASSERT(false); break; } } - // since AccessMemory_Check is always true and will not break from here, no need to check AccessMemory_Check to free memory. - if(!CheckPermission( accessAddress, mode )) + // since AccessMemory_Check is always true and will not break from here, no need to check + // AccessMemory_Check to free memory. + if (!CheckPermission(accessAddress, mode)) { TRACE0("=> Permission check failed!\n"); - + // set error code - errorCode = AccessMemoryErrorCode_PermissionDenied; + *errorCode = AccessMemoryErrorCode_PermissionDenied; // done here - return false; + return; } - switch(mode) + switch (mode) { case AccessMemory_Check: case AccessMemory_Read: - if(deviceInfo->Attribute & MediaAttribute_SupportsXIP) + if (deviceInfo->Attribute & MediaAttribute_SupportsXIP) { - memcpy( (unsigned char*)bufPtr, (const void*)accessAddress, NumOfBytes ); + memcpy((unsigned char *)bufPtr, (const void *)accessAddress, NumOfBytes); proceed = true; } else { if (mode == AccessMemory_Check) { - bufPtr = (unsigned char*) CLR_RT_Memory::Allocate( lengthInBytes, true ); + bufPtr = (unsigned char *)CLR_RT_Memory::Allocate(lengthInBytes, true); - if(!bufPtr) + if (!bufPtr) { - TRACE0( "=> Failed to allocate data buffer\n"); - + TRACE0("=> Failed to allocate data buffer\n"); + // set error code - errorCode = AccessMemoryErrorCode_PermissionDenied; + *errorCode = AccessMemoryErrorCode_PermissionDenied; // done here - return false; + return; } } - proceed = BlockStorageDevice_Read(m_deploymentStorageDevice, accessAddress , NumOfBytes, (unsigned char *)bufPtr); + proceed = BlockStorageDevice_Read( + m_deploymentStorageDevice, + accessAddress, + NumOfBytes, + (unsigned char *)bufPtr); if (mode == AccessMemory_Check) { - *(unsigned int*)buf = SUPPORT_ComputeCRC( bufPtr, NumOfBytes, *(unsigned int*)buf ); + *(unsigned int *)buf = SUPPORT_ComputeCRC(bufPtr, NumOfBytes, *(unsigned int *)buf); - CLR_RT_Memory::Release( bufPtr ); + CLR_RT_Memory::Release(bufPtr); } } break; case AccessMemory_Write: - proceed = BlockStorageDevice_Write(m_deploymentStorageDevice, accessAddress , NumOfBytes, (unsigned char *)bufPtr, false); + proceed = BlockStorageDevice_Write( + m_deploymentStorageDevice, + accessAddress, + NumOfBytes, + (unsigned char *)bufPtr, + false); break; case AccessMemory_Erase: @@ -698,13 +734,13 @@ bool CLR_DBG_Debugger::AccessMemory( uint32_t location, uint32_t lengthInBytes, } break; - default: + default: break; } - if(!proceed) + if (!proceed) { - return false; + return; } accessLenInBytes -= NumOfBytes; @@ -714,17 +750,17 @@ bool CLR_DBG_Debugger::AccessMemory( uint32_t location, uint32_t lengthInBytes, break; } - bufPtr += NumOfBytes; + bufPtr += NumOfBytes; accessAddress += NumOfBytes; } blockIndex = 0; - iRange = 0; + iRange = 0; - if ((accessLenInBytes <= 0) || (!proceed)) - { - break; - } + if ((accessLenInBytes <= 0) || (!proceed)) + { + break; + } } } else @@ -732,60 +768,65 @@ bool CLR_DBG_Debugger::AccessMemory( uint32_t location, uint32_t lengthInBytes, //--// RAM write ByteAddress sectAddr = location; - #if defined(_WIN32) +#if defined(_WIN32) bool proceed = false; - void * temp; - temp = (void *) sectAddr; + void *temp; + temp = (void *)sectAddr; - switch(mode) + switch (mode) { - case AccessMemory_Check: - break; + case AccessMemory_Check: + break; - case AccessMemory_Read: - proceed = IsBadReadPtr( temp, lengthInBytes ) == false; - break; + case AccessMemory_Read: + proceed = IsBadReadPtr(temp, lengthInBytes) == false; + break; - case AccessMemory_Write: - proceed = IsBadWritePtr( temp, lengthInBytes ) == false; - break; + case AccessMemory_Write: + proceed = IsBadWritePtr(temp, lengthInBytes) == false; + break; } - if(proceed) - #else + if (proceed) +#else - unsigned int sectAddrEnd = sectAddr + lengthInBytes; + unsigned int sectAddrEnd = sectAddr + lengthInBytes; unsigned int ramStartAddress = HalSystemConfig.RAM1.Base; - unsigned int ramEndAddress = ramStartAddress + HalSystemConfig.RAM1.Size ; + unsigned int ramEndAddress = ramStartAddress + HalSystemConfig.RAM1.Size; - if((sectAddr =ramEndAddress) || (sectAddrEnd >ramEndAddress) ) + if ((sectAddr < ramStartAddress) || (sectAddr >= ramEndAddress) || (sectAddrEnd > ramEndAddress)) { - TRACE(" Invalid address %x and range %x Ram Start %x, Ram end %x\r\n", sectAddr, lengthInBytes, ramStartAddress, ramEndAddress); - return false; + TRACE( + " Invalid address %x and range %x Ram Start %x, Ram end %x\r\n", + sectAddr, + lengthInBytes, + ramStartAddress, + ramEndAddress); + return; } else - #endif +#endif { - switch(mode) + switch (mode) { case AccessMemory_Check: break; case AccessMemory_Read: - memcpy( buf, (const void*)sectAddr, lengthInBytes ); + memcpy(buf, (const void *)sectAddr, lengthInBytes); break; case AccessMemory_Write: - unsigned char * memPtr; - memPtr = (unsigned char*)sectAddr; - memcpy( memPtr, buf, lengthInBytes ); + unsigned char *memPtr; + memPtr = (unsigned char *)sectAddr; + memcpy(memPtr, buf, lengthInBytes); break; case AccessMemory_Erase: - memPtr = (unsigned char*)sectAddr; - if (lengthInBytes !=0) - memset( memPtr, 0xFF, lengthInBytes ); + memPtr = (unsigned char *)sectAddr; + if (lengthInBytes != 0) + memset(memPtr, 0xFF, lengthInBytes); break; default: @@ -794,24 +835,22 @@ bool CLR_DBG_Debugger::AccessMemory( uint32_t location, uint32_t lengthInBytes, } } - TRACE0( "=> SUCCESS\n"); + TRACE0("=> SUCCESS\n"); - errorCode = AccessMemoryErrorCode_NoError; - - return true; + *errorCode = AccessMemoryErrorCode_NoError; } -bool CLR_DBG_Debugger::Monitor_ReadMemory( WP_Message* msg) +bool CLR_DBG_Debugger::Monitor_ReadMemory(WP_Message *msg) { NATIVE_PROFILE_CLR_DEBUGGER(); - CLR_DBG_Commands_Monitor_ReadMemory* cmd = (CLR_DBG_Commands_Monitor_ReadMemory*)msg->m_payload; - uint8_t* buffer; + CLR_DBG_Commands_Monitor_ReadMemory *cmd = (CLR_DBG_Commands_Monitor_ReadMemory *)msg->m_payload; + uint8_t *buffer; uint32_t errorCode; uint32_t allocationSize = 0; - uint32_t len = cmd->length; - + uint32_t len = cmd->length; + // adjust length, if bigger than the WP packet size if (len > WP_PACKET_SIZE) { @@ -824,17 +863,17 @@ bool CLR_DBG_Debugger::Monitor_ReadMemory( WP_Message* msg) allocationSize += len; // allocate memory - buffer = (uint8_t*)platform_malloc(allocationSize); + buffer = (uint8_t *)platform_malloc(allocationSize); // sanity check - if(buffer != NULL) + if (buffer != NULL) { // clear allocated memory memset(buffer, 0, allocationSize); - g_CLR_DBG_Debugger->AccessMemory( cmd->address, len, (buffer + sizeof(uint32_t)), AccessMemory_Read, errorCode ); + g_CLR_DBG_Debugger->AccessMemory(cmd->address, len, (buffer + sizeof(uint32_t)), AccessMemory_Read, &errorCode); - WP_ReplyToCommand( msg, true, false, buffer, allocationSize ); + WP_ReplyToCommand(msg, true, false, buffer, allocationSize); // free allocated memory platform_free(buffer); @@ -846,58 +885,58 @@ bool CLR_DBG_Debugger::Monitor_ReadMemory( WP_Message* msg) return false; } -bool CLR_DBG_Debugger::Monitor_WriteMemory( WP_Message* msg) +bool CLR_DBG_Debugger::Monitor_WriteMemory(WP_Message *msg) { NATIVE_PROFILE_CLR_DEBUGGER(); - CLR_DBG_Commands_Monitor_WriteMemory* cmd = (CLR_DBG_Commands_Monitor_WriteMemory*)msg->m_payload; + CLR_DBG_Commands_Monitor_WriteMemory *cmd = (CLR_DBG_Commands_Monitor_WriteMemory *)msg->m_payload; CLR_DBG_Commands_Monitor_WriteMemory_Reply cmdReply; - g_CLR_DBG_Debugger->AccessMemory( cmd->address, cmd->length, cmd->data, AccessMemory_Write, cmdReply.ErrorCode ); + g_CLR_DBG_Debugger->AccessMemory(cmd->address, cmd->length, cmd->data, AccessMemory_Write, &cmdReply); WP_ReplyToCommand(msg, true, false, &cmdReply, sizeof(cmdReply)); return true; } -bool CLR_DBG_Debugger::Monitor_CheckMemory( WP_Message* msg) +bool CLR_DBG_Debugger::Monitor_CheckMemory(WP_Message *msg) { NATIVE_PROFILE_CLR_DEBUGGER(); - CLR_DBG_Commands_Monitor_CheckMemory* cmd = (CLR_DBG_Commands_Monitor_CheckMemory*)msg->m_payload; - CLR_DBG_Commands_Monitor_CheckMemory_Reply cmdReply; + CLR_DBG_Commands_Monitor_CheckMemory *cmd = (CLR_DBG_Commands_Monitor_CheckMemory *)msg->m_payload; + CLR_DBG_Commands_Monitor_CheckMemory_Reply cmdReply; uint32_t errorCode; - g_CLR_DBG_Debugger->AccessMemory( cmd->address, cmd->length, (unsigned char*)&cmdReply.crc, AccessMemory_Check, errorCode ); + g_CLR_DBG_Debugger + ->AccessMemory(cmd->address, cmd->length, (unsigned char *)&cmdReply, AccessMemory_Check, &errorCode); - WP_ReplyToCommand( msg, true, false, &cmdReply, sizeof(cmdReply) ); + WP_ReplyToCommand(msg, true, false, &cmdReply, sizeof(cmdReply)); return true; } -bool CLR_DBG_Debugger::Monitor_EraseMemory( WP_Message* msg) +bool CLR_DBG_Debugger::Monitor_EraseMemory(WP_Message *msg) { NATIVE_PROFILE_CLR_DEBUGGER(); - CLR_DBG_Commands_Monitor_EraseMemory* cmd = (CLR_DBG_Commands_Monitor_EraseMemory*)msg->m_payload; + CLR_DBG_Commands_Monitor_EraseMemory *cmd = (CLR_DBG_Commands_Monitor_EraseMemory *)msg->m_payload; CLR_DBG_Commands_Monitor_EraseMemory_Reply cmdReply; - g_CLR_DBG_Debugger->AccessMemory( cmd->address, cmd->length, NULL, AccessMemory_Erase, cmdReply.ErrorCode ); + g_CLR_DBG_Debugger->AccessMemory(cmd->address, cmd->length, NULL, AccessMemory_Erase, &cmdReply); WP_ReplyToCommand(msg, true, false, &cmdReply, sizeof(cmdReply)); return true; } -bool CLR_DBG_Debugger::Monitor_Execute( WP_Message* msg) +bool CLR_DBG_Debugger::Monitor_Execute(WP_Message *msg) { NATIVE_PROFILE_CLR_DEBUGGER(); - - CLR_DBG_Commands::Monitor_Execute* cmd = (CLR_DBG_Commands::Monitor_Execute*)msg->m_payload; + CLR_DBG_Commands::Monitor_Execute *cmd = (CLR_DBG_Commands::Monitor_Execute *)msg->m_payload; #if defined(BUILD_RTM) - if(!DebuggerPort_IsUsingSsl(HalSystemConfig.DebuggerPort)) + if (!DebuggerPort_IsUsingSsl(HalSystemConfig.DebuggerPort)) return false; #endif @@ -908,19 +947,20 @@ bool CLR_DBG_Debugger::Monitor_Execute( WP_Message* msg) return true; } -bool CLR_DBG_Debugger::Monitor_Reboot( WP_Message* msg) +bool CLR_DBG_Debugger::Monitor_Reboot(WP_Message *msg) { NATIVE_PROFILE_CLR_DEBUGGER(); - - CLR_DBG_Commands::Monitor_Reboot* cmd = (CLR_DBG_Commands::Monitor_Reboot*)msg->m_payload; - if(NULL != cmd) + CLR_DBG_Commands::Monitor_Reboot *cmd = (CLR_DBG_Commands::Monitor_Reboot *)msg->m_payload; + + if (NULL != cmd) { - if(CLR_DBG_Commands::Monitor_Reboot::c_EnterBootloader == (cmd->m_flags & CLR_DBG_Commands::Monitor_Reboot::c_EnterBootloader)) + if (CLR_DBG_Commands::Monitor_Reboot::c_EnterBootloader == + (cmd->m_flags & CLR_DBG_Commands::Monitor_Reboot::c_EnterBootloader)) { WP_ReplyToCommand(msg, true, false, NULL, 0); - Events_WaitForEvents( 0, 100 ); // give message a little time to be flushed + Events_WaitForEvents(0, 100); // give message a little time to be flushed HAL_EnterBooterMode(); } @@ -930,110 +970,121 @@ bool CLR_DBG_Debugger::Monitor_Reboot( WP_Message* msg) WP_ReplyToCommand(msg, true, false, NULL, 0); - Events_WaitForEvents( 0, 100 ); // give message a little time to be flushed + Events_WaitForEvents(0, 100); // give message a little time to be flushed - CLR_EE_DBG_SET( RebootPending ); + CLR_EE_DBG_SET(RebootPending); return true; } -bool CLR_DBG_Debugger::Monitor_MemoryMap( WP_Message* msg) +bool CLR_DBG_Debugger::Monitor_MemoryMap(WP_Message *msg) { NATIVE_PROFILE_CLR_DEBUGGER(); - + MemoryMap_Range map[2]; map[0].m_address = HalSystemConfig.RAM1.Base; - map[0].m_length = HalSystemConfig.RAM1.Size; - map[0].m_flags = Monitor_MemoryMap_c_RAM; + map[0].m_length = HalSystemConfig.RAM1.Size; + map[0].m_flags = Monitor_MemoryMap_c_RAM; map[1].m_address = HalSystemConfig.FLASH1.Base; - map[1].m_length = HalSystemConfig.FLASH1.Size; - map[1].m_flags = Monitor_MemoryMap_c_FLASH; + map[1].m_length = HalSystemConfig.FLASH1.Size; + map[1].m_flags = Monitor_MemoryMap_c_FLASH; WP_ReplyToCommand(msg, true, false, map, sizeof(map)); return true; } -bool CLR_DBG_Debugger::Monitor_DeploymentMap( WP_Message* msg) +bool CLR_DBG_Debugger::Monitor_DeploymentMap(WP_Message *msg) { (void)msg; return true; } -bool CLR_DBG_Debugger::Monitor_QueryConfiguration( WP_Message* message) +bool CLR_DBG_Debugger::Monitor_QueryConfiguration(WP_Message *message) { NATIVE_PROFILE_CLR_DEBUGGER(); - bool success = false; + bool success = false; // include handling of configuration block only if feature is available - #if (HAS_CONFIG_BLOCK == TRUE) +#if (HAS_CONFIG_BLOCK == TRUE) - Monitor_QueryConfiguration_Command *cmd = (Monitor_QueryConfiguration_Command*)message->m_payload; - int size = 0; + Monitor_QueryConfiguration_Command *cmd = (Monitor_QueryConfiguration_Command *)message->m_payload; + int size = 0; int sizeOfBlock = 0; - HAL_Configuration_NetworkInterface* configNetworkInterface; - HAL_Configuration_Wireless80211* configWireless80211NetworkInterface; - HAL_Configuration_X509CaRootBundle* x509Certificate; + HAL_Configuration_NetworkInterface *configNetworkInterface; + HAL_Configuration_Wireless80211 *configWireless80211NetworkInterface; + HAL_Configuration_X509CaRootBundle *x509Certificate; - switch((DeviceConfigurationOption)cmd->Configuration) + switch ((DeviceConfigurationOption)cmd->Configuration) { case DeviceConfigurationOption_Network: - configNetworkInterface = (HAL_Configuration_NetworkInterface*)platform_malloc(sizeof(HAL_Configuration_NetworkInterface)); + configNetworkInterface = + (HAL_Configuration_NetworkInterface *)platform_malloc(sizeof(HAL_Configuration_NetworkInterface)); memset(configNetworkInterface, 0, sizeof(HAL_Configuration_NetworkInterface)); - if(ConfigurationManager_GetConfigurationBlock(configNetworkInterface, (DeviceConfigurationOption)cmd->Configuration, cmd->BlockIndex) == true) + if (ConfigurationManager_GetConfigurationBlock( + configNetworkInterface, + (DeviceConfigurationOption)cmd->Configuration, + cmd->BlockIndex) == true) { size = sizeof(HAL_Configuration_NetworkInterface); success = true; - WP_ReplyToCommand( message, success, false, (uint8_t*)configNetworkInterface, size ); - } + WP_ReplyToCommand(message, success, false, (uint8_t *)configNetworkInterface, size); + } platform_free(configNetworkInterface); break; case DeviceConfigurationOption_Wireless80211Network: - configWireless80211NetworkInterface = (HAL_Configuration_Wireless80211*)platform_malloc(sizeof(HAL_Configuration_Wireless80211)); + configWireless80211NetworkInterface = + (HAL_Configuration_Wireless80211 *)platform_malloc(sizeof(HAL_Configuration_Wireless80211)); memset(configWireless80211NetworkInterface, 0, sizeof(HAL_Configuration_Wireless80211)); - if(ConfigurationManager_GetConfigurationBlock(configWireless80211NetworkInterface, (DeviceConfigurationOption)cmd->Configuration, cmd->BlockIndex) == true) + if (ConfigurationManager_GetConfigurationBlock( + configWireless80211NetworkInterface, + (DeviceConfigurationOption)cmd->Configuration, + cmd->BlockIndex) == true) { size = sizeof(HAL_Configuration_Wireless80211); success = true; - WP_ReplyToCommand( message, success, false, (uint8_t*)configWireless80211NetworkInterface, size ); + WP_ReplyToCommand(message, success, false, (uint8_t *)configWireless80211NetworkInterface, size); } platform_free(configWireless80211NetworkInterface); break; - + case DeviceConfigurationOption_X509CaRootBundle: - if(g_TargetConfiguration.CertificateStore->Count > cmd->BlockIndex ) + if (g_TargetConfiguration.CertificateStore->Count > cmd->BlockIndex) { // because X509 certificate has a variable length need to compute the block size in two steps sizeOfBlock = offsetof(HAL_Configuration_X509CaRootBundle, Certificate); sizeOfBlock += g_TargetConfiguration.CertificateStore->Certificates[cmd->BlockIndex]->CertificateSize; } - x509Certificate = (HAL_Configuration_X509CaRootBundle*)platform_malloc(sizeOfBlock); + x509Certificate = (HAL_Configuration_X509CaRootBundle *)platform_malloc(sizeOfBlock); memset(x509Certificate, 0, sizeof(sizeOfBlock)); - if(ConfigurationManager_GetConfigurationBlock(x509Certificate, (DeviceConfigurationOption)cmd->Configuration, cmd->BlockIndex) == true) + if (ConfigurationManager_GetConfigurationBlock( + x509Certificate, + (DeviceConfigurationOption)cmd->Configuration, + cmd->BlockIndex) == true) { size = sizeOfBlock; success = true; - WP_ReplyToCommand( message, success, false, (uint8_t*)x509Certificate, size ); + WP_ReplyToCommand(message, success, false, (uint8_t *)x509Certificate, size); } platform_free(x509Certificate); break; - + case DeviceConfigurationOption_WirelessNetworkAP: // TODO missing implementation for now break; @@ -1042,44 +1093,50 @@ bool CLR_DBG_Debugger::Monitor_QueryConfiguration( WP_Message* message) break; } - if(!success) + if (!success) { - WP_ReplyToCommand( message, success, false, NULL, size ); + WP_ReplyToCommand(message, success, false, NULL, size); } - #else +#else (void)message; - #endif // (HAS_CONFIG_BLOCK == TRUE) +#endif // (HAS_CONFIG_BLOCK == TRUE) return success; } -bool CLR_DBG_Debugger::Monitor_UpdateConfiguration(WP_Message* message) +bool CLR_DBG_Debugger::Monitor_UpdateConfiguration(WP_Message *message) { NATIVE_PROFILE_CLR_DEBUGGER(); bool success = false; // include handling of configuration block only if feature is available - #if (HAS_CONFIG_BLOCK == TRUE) +#if (HAS_CONFIG_BLOCK == TRUE) - Monitor_UpdateConfiguration_Command* cmd = (Monitor_UpdateConfiguration_Command*)message->m_payload; + Monitor_UpdateConfiguration_Command *cmd = (Monitor_UpdateConfiguration_Command *)message->m_payload; Monitor_UpdateConfiguration_Reply cmdReply; - switch((DeviceConfigurationOption)cmd->Configuration) + switch ((DeviceConfigurationOption)cmd->Configuration) { case DeviceConfigurationOption_Network: case DeviceConfigurationOption_Wireless80211Network: case DeviceConfigurationOption_X509CaRootBundle: case DeviceConfigurationOption_All: - if(ConfigurationManager_StoreConfigurationBlock(cmd->Data, (DeviceConfigurationOption)cmd->Configuration, cmd->BlockIndex, cmd->Length, cmd->Offset, cmd->Done) == true) + if (ConfigurationManager_StoreConfigurationBlock( + cmd->Data, + (DeviceConfigurationOption)cmd->Configuration, + cmd->BlockIndex, + cmd->Length, + cmd->Offset, + cmd->Done) == true) { cmdReply.ErrorCode = 0; success = true; } - else + else { cmdReply.ErrorCode = 100; } @@ -1091,50 +1148,51 @@ bool CLR_DBG_Debugger::Monitor_UpdateConfiguration(WP_Message* message) WP_ReplyToCommand(message, success, false, &cmdReply, sizeof(cmdReply)); - #else +#else (void)message; - #endif // (HAS_CONFIG_BLOCK == TRUE) +#endif // (HAS_CONFIG_BLOCK == TRUE) return success; } //--// -bool CLR_DBG_Debugger::Debugging_Execution_BasePtr( WP_Message* msg) +bool CLR_DBG_Debugger::Debugging_Execution_BasePtr(WP_Message *msg) { NATIVE_PROFILE_CLR_DEBUGGER(); - + CLR_DBG_Commands::Debugging_Execution_BasePtr::Reply cmdReply; cmdReply.m_EE = (CLR_UINT32)(size_t)&g_CLR_RT_ExecutionEngine; - WP_ReplyToCommand( msg, true, false, &cmdReply, sizeof(cmdReply) ); + WP_ReplyToCommand(msg, true, false, &cmdReply, sizeof(cmdReply)); return true; } -bool CLR_DBG_Debugger::Debugging_Execution_ChangeConditions( WP_Message* msg) +bool CLR_DBG_Debugger::Debugging_Execution_ChangeConditions(WP_Message *msg) { NATIVE_PROFILE_CLR_DEBUGGER(); - - CLR_DBG_Commands::Debugging_Execution_ChangeConditions* cmd = (CLR_DBG_Commands::Debugging_Execution_ChangeConditions*)msg->m_payload; - g_CLR_RT_ExecutionEngine.m_iDebugger_Conditions |= cmd->FlagsToSet; + CLR_DBG_Commands::Debugging_Execution_ChangeConditions *cmd = + (CLR_DBG_Commands::Debugging_Execution_ChangeConditions *)msg->m_payload; + + g_CLR_RT_ExecutionEngine.m_iDebugger_Conditions |= cmd->FlagsToSet; g_CLR_RT_ExecutionEngine.m_iDebugger_Conditions &= ~cmd->FlagsToReset; // updating the debugging execution conditions requires sometime to propagate // make sure we allow enough time for that to happen OS_DELAY(100); - if((msg->m_header.m_flags & WP_Flags_c_NonCritical) == 0) + if ((msg->m_header.m_flags & WP_Flags_c_NonCritical) == 0) { CLR_DBG_Commands::Debugging_Execution_ChangeConditions::Reply cmdReply; cmdReply.CurrentState = g_CLR_RT_ExecutionEngine.m_iDebugger_Conditions; - WP_ReplyToCommand( msg, true, false, &cmdReply, sizeof(cmdReply) ); + WP_ReplyToCommand(msg, true, false, &cmdReply, sizeof(cmdReply)); } return true; @@ -1142,95 +1200,100 @@ bool CLR_DBG_Debugger::Debugging_Execution_ChangeConditions( WP_Message* msg) //--// -static void GetClrReleaseInfo(CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::ClrInfo& clrInfo) +static void GetClrReleaseInfo(CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::ClrInfo &clrInfo) { - NFReleaseInfo::Init( - clrInfo.m_clrReleaseInfo, - VERSION_MAJOR, - VERSION_MINOR, - VERSION_BUILD, - VERSION_REVISION, - OEMSYSTEMINFOSTRING, + NFReleaseInfo::Init( + clrInfo.m_clrReleaseInfo, + VERSION_MAJOR, + VERSION_MINOR, + VERSION_BUILD, + VERSION_REVISION, + OEMSYSTEMINFOSTRING, ARRAYSIZE(OEMSYSTEMINFOSTRING), TARGETNAMESTRING, ARRAYSIZE(TARGETNAMESTRING), PLATFORMNAMESTRING, - ARRAYSIZE(PLATFORMNAMESTRING) - ); + ARRAYSIZE(PLATFORMNAMESTRING)); - if ( g_CLR_RT_TypeSystem.m_assemblyMscorlib && - g_CLR_RT_TypeSystem.m_assemblyMscorlib->m_header) + if (g_CLR_RT_TypeSystem.m_assemblyMscorlib && g_CLR_RT_TypeSystem.m_assemblyMscorlib->m_header) { - const CLR_RECORD_VERSION* mscorlibVer = & (g_CLR_RT_TypeSystem.m_assemblyMscorlib->m_header->version); - NFVersion::Init( clrInfo.m_TargetFrameworkVersion, - mscorlibVer->iMajorVersion, mscorlibVer->iMinorVersion, - mscorlibVer->iBuildNumber, mscorlibVer->iRevisionNumber - ); + const CLR_RECORD_VERSION *mscorlibVer = &(g_CLR_RT_TypeSystem.m_assemblyMscorlib->m_header->version); + NFVersion::Init( + clrInfo.m_TargetFrameworkVersion, + mscorlibVer->iMajorVersion, + mscorlibVer->iMinorVersion, + mscorlibVer->iBuildNumber, + mscorlibVer->iRevisionNumber); } else { - NFVersion::Init( clrInfo.m_TargetFrameworkVersion, 0, 0, 0, 0 ); + NFVersion::Init(clrInfo.m_TargetFrameworkVersion, 0, 0, 0, 0); } } -static bool GetInteropNativeAssemblies( uint8_t* &data, int* size, uint32_t startIndex, uint32_t count ) +static bool GetInteropNativeAssemblies(uint8_t *&data, int *size, uint32_t startIndex, uint32_t count) { uint32_t index = 0; - - CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::NativeAssemblyDetails* interopNativeAssemblies = NULL; + + CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::NativeAssemblyDetails *interopNativeAssemblies = NULL; // sanity checks on the requested size - // - if 0, adjust to the assemblies count to make the execution backwards compatible + // - if 0, adjust to the assemblies count to make the execution backwards compatible // - trim if over the available assembly count // (max possible page size is 255) - if(startIndex == 0 && count == 0) + if (startIndex == 0 && count == 0) { - // adjust to the assemblies count to make the execution backwards compatible + // adjust to the assemblies count to make the execution backwards compatible count = g_CLR_InteropAssembliesCount; } - else if(count > 255 || - count + startIndex > g_CLR_InteropAssembliesCount) + else if (count > 255 || count + startIndex > g_CLR_InteropAssembliesCount) { - // adjust to the assemblies count so it doesn't overflow + // adjust to the assemblies count so it doesn't overflow count = g_CLR_InteropAssembliesCount - startIndex; } // alloc buffer to hold the requested number of assemblies - interopNativeAssemblies = (CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::NativeAssemblyDetails*)platform_malloc(sizeof(CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::NativeAssemblyDetails) * count); + interopNativeAssemblies = + (CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::NativeAssemblyDetails *)platform_malloc( + sizeof(CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::NativeAssemblyDetails) * count); // check for malloc failure - if(interopNativeAssemblies == NULL) + if (interopNativeAssemblies == NULL) { return false; } // clear buffer memory memset( - interopNativeAssemblies, - 0, + interopNativeAssemblies, + 0, sizeof(CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::NativeAssemblyDetails) * count); // fill the array - for ( uint32_t i = 0; i < g_CLR_InteropAssembliesCount; i++ ) + for (uint32_t i = 0; i < g_CLR_InteropAssembliesCount; i++) { // check if the assembly at this position it's on the requested range - if( i >= startIndex && - i < (startIndex + count)) + if (i >= startIndex && i < (startIndex + count)) { interopNativeAssemblies[index].CheckSum = g_CLR_InteropAssembliesNativeData[i]->m_checkSum; - hal_strcpy_s((char*)interopNativeAssemblies[index].AssemblyName, ARRAYSIZE(interopNativeAssemblies[index].AssemblyName), g_CLR_InteropAssembliesNativeData[i]->m_szAssemblyName); - - NFVersion::Init(interopNativeAssemblies[index].Version, - g_CLR_InteropAssembliesNativeData[i]->m_Version.iMajorVersion, g_CLR_InteropAssembliesNativeData[i]->m_Version.iMinorVersion, - g_CLR_InteropAssembliesNativeData[i]->m_Version.iBuildNumber, g_CLR_InteropAssembliesNativeData[i]->m_Version.iRevisionNumber - ); + hal_strcpy_s( + (char *)interopNativeAssemblies[index].AssemblyName, + ARRAYSIZE(interopNativeAssemblies[index].AssemblyName), + g_CLR_InteropAssembliesNativeData[i]->m_szAssemblyName); + + NFVersion::Init( + interopNativeAssemblies[index].Version, + g_CLR_InteropAssembliesNativeData[i]->m_Version.iMajorVersion, + g_CLR_InteropAssembliesNativeData[i]->m_Version.iMinorVersion, + g_CLR_InteropAssembliesNativeData[i]->m_Version.iBuildNumber, + g_CLR_InteropAssembliesNativeData[i]->m_Version.iRevisionNumber); index++; } } - // copy back the buffer - data = (uint8_t*)interopNativeAssemblies; + // copy back the buffer + data = (uint8_t *)interopNativeAssemblies; // set buffer size *size = (sizeof(CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::NativeAssemblyDetails) * count); @@ -1240,18 +1303,19 @@ static bool GetInteropNativeAssemblies( uint8_t* &data, int* size, uint32_t star //--// -bool CLR_DBG_Debugger::Debugging_Execution_QueryCLRCapabilities( WP_Message* msg) +bool CLR_DBG_Debugger::Debugging_Execution_QueryCLRCapabilities(WP_Message *msg) { NATIVE_PROFILE_CLR_DEBUGGER(); - - CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities* cmd = (CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities*)msg->m_payload; + + CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities *cmd = + (CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities *)msg->m_payload; CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::ReplyUnion reply; reply.u_capsFlags = 0; - CLR_UINT8* data = NULL; - int size = 0; - bool fSuccess = true; + CLR_UINT8 *data = NULL; + int size = 0; + bool fSuccess = true; bool freeAllocFlag = false; uint32_t startIndex = 0; uint32_t count = 0xFF; @@ -1259,7 +1323,7 @@ bool CLR_DBG_Debugger::Debugging_Execution_QueryCLRCapabilities( WP_Message* msg // set the compiler info string here #if defined(__GNUC__) #define COMPILER_INFO "GNU ARM GCC" - const size_t len = MIN(sizeof(COMPILER_INFO), sizeof(reply.u_SoftwareVersion.CompilerInfo)-1); + const size_t len = MIN(sizeof(COMPILER_INFO), sizeof(reply.u_SoftwareVersion.CompilerInfo) - 1); #else #define COMPILER_INFO "UNKNOWN" const size_t len = 0; @@ -1270,91 +1334,113 @@ bool CLR_DBG_Debugger::Debugging_Execution_QueryCLRCapabilities( WP_Message* msg // need to mask the command to get only the lower byte with the command code uint32_t cmdCode = 0x000000FF & cmd->m_cmd; - switch(cmdCode) + switch (cmdCode) { case CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::c_CapabilityFlags: #if !defined(NANOCLR_EMULATED_FLOATINGPOINT) - reply.u_capsFlags |= CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::c_CapabilityFlags_FloatingPoint; + reply.u_capsFlags |= + CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::c_CapabilityFlags_FloatingPoint; #endif - reply.u_capsFlags |= CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::c_CapabilityFlags_ExceptionFilters; + reply.u_capsFlags |= + CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::c_CapabilityFlags_ExceptionFilters; // the current version ONLY suports incremental deployment - reply.u_capsFlags |= CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::c_CapabilityFlags_IncrementalDeployment; + reply.u_capsFlags |= + CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::c_CapabilityFlags_IncrementalDeployment; #if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) - reply.u_capsFlags |= CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::c_CapabilityFlags_SourceLevelDebugging; + reply.u_capsFlags |= + CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::c_CapabilityFlags_SourceLevelDebugging; - reply.u_capsFlags |= CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::c_CapabilityFlags_ThreadCreateEx; + reply.u_capsFlags |= + CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::c_CapabilityFlags_ThreadCreateEx; #endif #if defined(NANOCLR_PROFILE_NEW) - reply.u_capsFlags |= CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::c_CapabilityFlags_Profiling; + reply.u_capsFlags |= + CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::c_CapabilityFlags_Profiling; #if defined(NANOCLR_PROFILE_NEW_CALLS) - reply.u_capsFlags |= CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::c_CapabilityFlags_Profiling_Calls; + reply.u_capsFlags |= + CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::c_CapabilityFlags_Profiling_Calls; #endif #if defined(NANOCLR_PROFILE_NEW_ALLOCATIONS) - reply.u_capsFlags |= CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::c_CapabilityFlags_Profiling_Allocations; + reply.u_capsFlags |= + CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::c_CapabilityFlags_Profiling_Allocations; #endif #endif #if defined(NANOCLR_APPDOMAINS) - reply.u_capsFlags |= CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::c_CapabilityFlags_AppDomains; + reply.u_capsFlags |= + CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::c_CapabilityFlags_AppDomains; #endif if (CPU_IsSoftRebootSupported()) { - reply.u_capsFlags |= CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::c_CapabilityFlags_SoftReboot; + reply.u_capsFlags |= + CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::c_CapabilityFlags_SoftReboot; } if (::Target_ConfigUpdateRequiresErase()) { - reply.u_capsFlags |= CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::c_CapabilityFlags_ConfigBlockRequiresErase; + reply.u_capsFlags |= CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities:: + c_CapabilityFlags_ConfigBlockRequiresErase; } if (::Target_HasNanoBooter()) { - reply.u_capsFlags |= CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::c_CapabilityFlags_HasNanoBooter; + reply.u_capsFlags |= + CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::c_CapabilityFlags_HasNanoBooter; } - reply.u_capsFlags |= (::GetPlatformCapabilities() & - ( CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::c_CapabilityFlags_PlatformCapabiliy_0 | - CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::c_CapabilityFlags_PlatformCapabiliy_1)); + reply.u_capsFlags |= + (::GetPlatformCapabilities() & + (CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::c_CapabilityFlags_PlatformCapabiliy_0 | + CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::c_CapabilityFlags_PlatformCapabiliy_1)); - reply.u_capsFlags |= (::GetTargetCapabilities() & - ( CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::c_CapabilityFlags_TargetCapabiliy_0 | - CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::c_CapabilityFlags_TargetCapabiliy_1)); + reply.u_capsFlags |= + (::GetTargetCapabilities() & + (CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::c_CapabilityFlags_TargetCapabiliy_0 | + CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::c_CapabilityFlags_TargetCapabiliy_1)); - data = (CLR_UINT8*)&reply.u_capsFlags; + data = (CLR_UINT8 *)&reply.u_capsFlags; size = sizeof(reply.u_capsFlags); break; case CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::c_CapabilityVersion: #if defined(__GNUC__) - // this is returning the GNU GCC compiler version in coded format: MAJOR x 10000 + MINOR x 100 + PATCH + // this is returning the GNU GCC compiler version in coded format: MAJOR x 10000 + MINOR x 100 + PATCH // example: v6.3.1 shows as 6 x 10000 + 3 x 100 + 1 = 60301 reply.u_SoftwareVersion.CompilerVersion = (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__); #else - reply.u_SoftwareVersion.CompilerVersion = -1; + reply.u_SoftwareVersion.CompilerVersion = -1; #endif #if defined(__DATE__) - hal_strncpy_s( reply.u_SoftwareVersion.BuildDate, sizeof(reply.u_SoftwareVersion.BuildDate), __DATE__, hal_strlen_s(__DATE__) ); + hal_strncpy_s( + reply.u_SoftwareVersion.BuildDate, + sizeof(reply.u_SoftwareVersion.BuildDate), + __DATE__, + hal_strlen_s(__DATE__)); #else #error "__DATE__ with build timestamp needs to be defined" #endif - hal_strncpy_s( (char*)&reply.u_SoftwareVersion.CompilerInfo[ 0 ], sizeof(reply.u_SoftwareVersion.CompilerInfo), COMPILER_INFO, len ); + hal_strncpy_s( + (char *)&reply.u_SoftwareVersion.CompilerInfo[0], + sizeof(reply.u_SoftwareVersion.CompilerInfo), + COMPILER_INFO, + len); - data = (CLR_UINT8*)&reply.u_SoftwareVersion; + data = (CLR_UINT8 *)&reply.u_SoftwareVersion; size = sizeof(reply.u_SoftwareVersion); break; case CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::c_HalSystemInfo: - if(GetHalSystemInfo( reply.u_HalSystemInfo ) == true) + if (GetHalSystemInfo(reply.u_HalSystemInfo) == true) { - data = (CLR_UINT8*)&reply.u_HalSystemInfo; + data = (CLR_UINT8 *)&reply.u_HalSystemInfo; size = sizeof(reply.u_HalSystemInfo); } else @@ -1365,14 +1451,14 @@ bool CLR_DBG_Debugger::Debugging_Execution_QueryCLRCapabilities( WP_Message* msg case CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::c_ClrInfo: GetClrReleaseInfo(reply.u_ClrInfo); - data = (CLR_UINT8*)&reply.u_ClrInfo; + data = (CLR_UINT8 *)&reply.u_ClrInfo; size = sizeof(reply.u_ClrInfo); break; case CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::c_TargetReleaseInfo: - if(Target_GetReleaseInfo(reply.u_TargetReleaseInfo) == true) + if (Target_GetReleaseInfo(reply.u_TargetReleaseInfo) == true) { - data = (CLR_UINT8*)&reply.u_TargetReleaseInfo; + data = (CLR_UINT8 *)&reply.u_TargetReleaseInfo; size = sizeof(reply.u_TargetReleaseInfo); } else @@ -1382,7 +1468,7 @@ bool CLR_DBG_Debugger::Debugging_Execution_QueryCLRCapabilities( WP_Message* msg break; case CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::c_InteropNativeAssemblies: - + // the start index and count are encoded on the MSBytes of the command, like this: 0xCCSSxxxx // SS: index of the 1st assembly to list // CC: how many assemblies to add to the list @@ -1394,7 +1480,7 @@ bool CLR_DBG_Debugger::Debugging_Execution_QueryCLRCapabilities( WP_Message* msg // now fix the start index by masking the count byte startIndex &= 0x000000FF; - if(GetInteropNativeAssemblies(data, &size, startIndex, count) == true) + if (GetInteropNativeAssemblies(data, &size, startIndex, count) == true) { // signal need to free memory freeAllocFlag = true; @@ -1406,10 +1492,10 @@ bool CLR_DBG_Debugger::Debugging_Execution_QueryCLRCapabilities( WP_Message* msg break; case CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::c_InteropNativeAssembliesCount: - // reusing the struct field to return the assemblies count + // reusing the struct field to return the assemblies count // because GCC optimizations prevent using the variable directly reply.u_capsFlags = g_CLR_InteropAssembliesCount; - data = (CLR_UINT8*)&reply.u_capsFlags; + data = (CLR_UINT8 *)&reply.u_capsFlags; size = sizeof(reply.u_capsFlags); break; @@ -1418,10 +1504,10 @@ bool CLR_DBG_Debugger::Debugging_Execution_QueryCLRCapabilities( WP_Message* msg break; } - WP_ReplyToCommand( msg, fSuccess, false, data, size ); + WP_ReplyToCommand(msg, fSuccess, false, data, size); // check if we need to free data pointer - if(freeAllocFlag) + if (freeAllocFlag) { platform_free(data); } @@ -1429,326 +1515,120 @@ bool CLR_DBG_Debugger::Debugging_Execution_QueryCLRCapabilities( WP_Message* msg return true; } -bool CLR_DBG_Debugger::Debugging_Execution_Allocate( WP_Message* msg) +bool CLR_DBG_Debugger::Debugging_Execution_Allocate(WP_Message *msg) { NATIVE_PROFILE_CLR_DEBUGGER(); - - CLR_DBG_Commands::Debugging_Execution_Allocate* cmd = (CLR_DBG_Commands::Debugging_Execution_Allocate*)msg->m_payload; + + CLR_DBG_Commands::Debugging_Execution_Allocate *cmd = + (CLR_DBG_Commands::Debugging_Execution_Allocate *)msg->m_payload; CLR_DBG_Commands::Debugging_Execution_Allocate::Reply reply; - reply.m_address = (CLR_UINT32)(size_t)CLR_RT_Memory::Allocate( cmd->m_size, CLR_RT_HeapBlock::HB_CompactOnFailure ); + reply.m_address = (CLR_UINT32)(size_t)CLR_RT_Memory::Allocate(cmd->m_size, CLR_RT_HeapBlock::HB_CompactOnFailure); - if(!reply.m_address) return false; + if (!reply.m_address) + return false; - WP_ReplyToCommand( msg, true, false, &reply, sizeof(reply) ); + WP_ReplyToCommand(msg, true, false, &reply, sizeof(reply)); return true; } -bool CLR_DBG_Debugger::Debugging_UpgradeToSsl(WP_Message* msg) +bool CLR_DBG_Debugger::Debugging_UpgradeToSsl(WP_Message *msg) { - - CLR_DBG_Commands::Debugging_UpgradeToSsl* cmd = (CLR_DBG_Commands::Debugging_UpgradeToSsl*)msg->m_payload; + + CLR_DBG_Commands::Debugging_UpgradeToSsl *cmd = (CLR_DBG_Commands::Debugging_UpgradeToSsl *)msg->m_payload; CLR_DBG_Commands::Debugging_UpgradeToSsl::Reply reply; - if(!DebuggerPort_IsSslSupported(HalSystemConfig.DebuggerPort)) + if (!DebuggerPort_IsSslSupported(HalSystemConfig.DebuggerPort)) { return false; } reply.m_success = 1; - WP_ReplyToCommand( msg, true, true, &reply, sizeof(reply) ); + WP_ReplyToCommand(msg, true, true, &reply, sizeof(reply)); Events_WaitForEvents(0, 300); return true == DebuggerPort_UpgradeToSsl(HalSystemConfig.DebuggerPort, cmd->m_flags); } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) -static bool FillValues( CLR_RT_HeapBlock* ptr, CLR_DBG_Commands::Debugging_Value*& array, size_t num, CLR_RT_HeapBlock* reference, CLR_RT_TypeDef_Instance* pTD ) +static bool FillValues( + CLR_RT_HeapBlock *ptr, + CLR_DBG_Commands::Debugging_Value *&array, + size_t num, + CLR_RT_HeapBlock *reference, + CLR_RT_TypeDef_Instance *pTD) { NATIVE_PROFILE_CLR_DEBUGGER(); - if(!ptr) return true; + if (!ptr) + return true; - if(!array || num == 0) return false; + if (!array || num == 0) + return false; - CLR_DBG_Commands::Debugging_Value* dst = array++; num--; - CLR_RT_TypeDescriptor desc; + CLR_DBG_Commands::Debugging_Value *dst = array++; + num--; + CLR_RT_TypeDescriptor desc; - memset( dst, 0, sizeof(*dst) ); + memset(dst, 0, sizeof(*dst)); dst->m_referenceID = (reference != NULL) ? reference : ptr; - dst->m_dt = ptr->DataType (); - dst->m_flags = ptr->DataFlags(); - dst->m_size = ptr->DataSize (); + dst->m_dt = ptr->DataType(); + dst->m_flags = ptr->DataFlags(); + dst->m_size = ptr->DataSize(); - if(pTD != NULL) + if (pTD != NULL) { dst->m_td = *pTD; } - else if(SUCCEEDED(desc.InitializeFromObject( *ptr ))) + else if (SUCCEEDED(desc.InitializeFromObject(*ptr))) { dst->m_td = desc.m_handlerCls; } - switch(dst->m_dt) + switch (dst->m_dt) { - case DATATYPE_BOOLEAN : - case DATATYPE_I1 : - case DATATYPE_U1 : + case DATATYPE_BOOLEAN: + case DATATYPE_I1: + case DATATYPE_U1: - case DATATYPE_CHAR : - case DATATYPE_I2 : - case DATATYPE_U2 : + case DATATYPE_CHAR: + case DATATYPE_I2: + case DATATYPE_U2: - case DATATYPE_I4 : - case DATATYPE_U4 : - case DATATYPE_R4 : + case DATATYPE_I4: + case DATATYPE_U4: + case DATATYPE_R4: - case DATATYPE_I8 : - case DATATYPE_U8 : - case DATATYPE_R8 : - case DATATYPE_DATETIME : - case DATATYPE_TIMESPAN : - case DATATYPE_REFLECTION: - // - // Primitives or optimized value types. - // - memcpy( dst->m_builtinValue, (void*)&ptr->NumericByRefConst().u1, 8 ); - break; + case DATATYPE_I8: + case DATATYPE_U8: + case DATATYPE_R8: + case DATATYPE_DATETIME: + case DATATYPE_TIMESPAN: + case DATATYPE_REFLECTION: + // + // Primitives or optimized value types. + // + memcpy(dst->m_builtinValue, (void *)&ptr->NumericByRefConst().u1, 8); + break; - case DATATYPE_STRING: + case DATATYPE_STRING: { - const char* text = ptr->StringText(); + const char *text = ptr->StringText(); - if(text != NULL) + if (text != NULL) { - dst->m_charsInString = text; - dst->m_bytesInString = (CLR_UINT32)hal_strlen_s( text ); - - hal_strncpy_s( (char*)dst->m_builtinValue, ARRAYSIZE(dst->m_builtinValue), text, __min(dst->m_bytesInString, MAXSTRLEN(dst->m_builtinValue)) ); + dst->m_charsInString = text; + dst->m_bytesInString = (CLR_UINT32)hal_strlen_s(text); + + hal_strncpy_s( + (char *)dst->m_builtinValue, + ARRAYSIZE(dst->m_builtinValue), + text, + __min(dst->m_bytesInString, MAXSTRLEN(dst->m_builtinValue))); } else { @@ -1759,111 +1639,114 @@ static bool FillValues( CLR_RT_HeapBlock* ptr, CLR_DBG_Commands::Debugging_Value } break; + case DATATYPE_OBJECT: + case DATATYPE_BYREF: + return FillValues(ptr->Dereference(), array, num, NULL, pTD); - case DATATYPE_OBJECT: - case DATATYPE_BYREF : - return FillValues( ptr->Dereference(), array, num, NULL, pTD ); - - - case DATATYPE_CLASS : - case DATATYPE_VALUETYPE: - dst->m_td = ptr->ObjectCls(); - break; + case DATATYPE_CLASS: + case DATATYPE_VALUETYPE: + dst->m_td = ptr->ObjectCls(); + break; - case DATATYPE_SZARRAY: + case DATATYPE_SZARRAY: { - CLR_RT_HeapBlock_Array* ptr2 = (CLR_RT_HeapBlock_Array*)ptr; + CLR_RT_HeapBlock_Array *ptr2 = (CLR_RT_HeapBlock_Array *)ptr; dst->m_array_numOfElements = ptr2->m_numOfElements; - dst->m_array_depth = ptr2->ReflectionDataConst().m_levels; - dst->m_array_typeIndex = ptr2->ReflectionDataConst().m_data.m_type; + dst->m_array_depth = ptr2->ReflectionDataConst().m_levels; + dst->m_array_typeIndex = ptr2->ReflectionDataConst().m_data.m_type; } break; - //////////////////////////////////////// + //////////////////////////////////////// - case DATATYPE_WEAKCLASS : - break; + case DATATYPE_WEAKCLASS: + break; - case DATATYPE_ARRAY_BYREF : - dst->m_arrayref_referenceID = ptr->Array (); - dst->m_arrayref_index = ptr->ArrayIndex(); + case DATATYPE_ARRAY_BYREF: + dst->m_arrayref_referenceID = ptr->Array(); + dst->m_arrayref_index = ptr->ArrayIndex(); - break; + break; - case DATATYPE_DELEGATE_HEAD : - break; + case DATATYPE_DELEGATE_HEAD: + break; - case DATATYPE_DELEGATELIST_HEAD : - break; + case DATATYPE_DELEGATELIST_HEAD: + break; - case DATATYPE_FREEBLOCK : - case DATATYPE_CACHEDBLOCK : - case DATATYPE_ASSEMBLY : - case DATATYPE_OBJECT_TO_EVENT : - case DATATYPE_BINARY_BLOB_HEAD : - - case DATATYPE_THREAD : - case DATATYPE_SUBTHREAD : - case DATATYPE_STACK_FRAME : - case DATATYPE_TIMER_HEAD : - case DATATYPE_LOCK_HEAD : - case DATATYPE_LOCK_OWNER_HEAD : - case DATATYPE_LOCK_REQUEST_HEAD : - case DATATYPE_WAIT_FOR_OBJECT_HEAD : - case DATATYPE_FINALIZER_HEAD : - case DATATYPE_MEMORY_STREAM_HEAD : - case DATATYPE_MEMORY_STREAM_DATA : - - case DATATYPE_SERIALIZER_HEAD : - case DATATYPE_SERIALIZER_DUPLICATE : - case DATATYPE_SERIALIZER_STATE : - - case DATATYPE_ENDPOINT_HEAD : + case DATATYPE_FREEBLOCK: + case DATATYPE_CACHEDBLOCK: + case DATATYPE_ASSEMBLY: + case DATATYPE_OBJECT_TO_EVENT: + case DATATYPE_BINARY_BLOB_HEAD: + + case DATATYPE_THREAD: + case DATATYPE_SUBTHREAD: + case DATATYPE_STACK_FRAME: + case DATATYPE_TIMER_HEAD: + case DATATYPE_LOCK_HEAD: + case DATATYPE_LOCK_OWNER_HEAD: + case DATATYPE_LOCK_REQUEST_HEAD: + case DATATYPE_WAIT_FOR_OBJECT_HEAD: + case DATATYPE_FINALIZER_HEAD: + case DATATYPE_MEMORY_STREAM_HEAD: + case DATATYPE_MEMORY_STREAM_DATA: + + case DATATYPE_SERIALIZER_HEAD: + case DATATYPE_SERIALIZER_DUPLICATE: + case DATATYPE_SERIALIZER_STATE: + + case DATATYPE_ENDPOINT_HEAD: #if defined(NANOCLR_APPDOMAINS) - case DATATYPE_APPDOMAIN_HEAD : - case DATATYPE_TRANSPARENT_PROXY : - case DATATYPE_APPDOMAIN_ASSEMBLY : + case DATATYPE_APPDOMAIN_HEAD: + case DATATYPE_TRANSPARENT_PROXY: + case DATATYPE_APPDOMAIN_ASSEMBLY: #endif - break; + break; } return true; } -bool CLR_DBG_Debugger::GetValue( WP_Message* msg, CLR_RT_HeapBlock* ptr, CLR_RT_HeapBlock* reference, CLR_RT_TypeDef_Instance *pTD ) +bool CLR_DBG_Debugger::GetValue( + WP_Message *msg, + CLR_RT_HeapBlock *ptr, + CLR_RT_HeapBlock *reference, + CLR_RT_TypeDef_Instance *pTD) { NATIVE_PROFILE_CLR_DEBUGGER(); - CLR_DBG_Commands::Debugging_Value reply[ 4 ]; - CLR_DBG_Commands::Debugging_Value* array = reply; + CLR_DBG_Commands::Debugging_Value reply[4]; + CLR_DBG_Commands::Debugging_Value *array = reply; - if(FillValues( ptr, array, ARRAYSIZE(reply), reference, pTD )) + if (FillValues(ptr, array, ARRAYSIZE(reply), reference, pTD)) { - WP_ReplyToCommand( msg, true, false, reply, (int)((size_t)array - (size_t)reply) ); + WP_ReplyToCommand(msg, true, false, reply, (int)((size_t)array - (size_t)reply)); return true; } - WP_ReplyToCommand(msg, false, false, NULL, 0); + WP_ReplyToCommand(msg, false, false, NULL, 0); return false; } //--// -bool CLR_DBG_Debugger::Debugging_Execution_SetCurrentAppDomain( WP_Message* msg) +bool CLR_DBG_Debugger::Debugging_Execution_SetCurrentAppDomain(WP_Message *msg) { NATIVE_PROFILE_CLR_DEBUGGER(); #if defined(NANOCLR_APPDOMAINS) - - CLR_DBG_Commands::Debugging_Execution_SetCurrentAppDomain* cmd = (CLR_DBG_Commands::Debugging_Execution_SetCurrentAppDomain*)msg->m_payload; - CLR_RT_AppDomain* appDomain = g_CLR_DBG_Debugger->GetAppDomainFromID( cmd->m_id ); - if(appDomain) + CLR_DBG_Commands::Debugging_Execution_SetCurrentAppDomain *cmd = + (CLR_DBG_Commands::Debugging_Execution_SetCurrentAppDomain *)msg->m_payload; + CLR_RT_AppDomain *appDomain = g_CLR_DBG_Debugger->GetAppDomainFromID(cmd->m_id); + + if (appDomain) { - g_CLR_RT_ExecutionEngine.SetCurrentAppDomain( appDomain ); + g_CLR_RT_ExecutionEngine.SetCurrentAppDomain(appDomain); } WP_ReplyToCommand(msg, appDomain != NULL, false, NULL, 0); @@ -1875,103 +1758,107 @@ bool CLR_DBG_Debugger::Debugging_Execution_SetCurrentAppDomain( WP_Message* msg) #endif } -bool CLR_DBG_Debugger::Debugging_Execution_Breakpoints( WP_Message* msg) +bool CLR_DBG_Debugger::Debugging_Execution_Breakpoints(WP_Message *msg) { NATIVE_PROFILE_CLR_DEBUGGER(); - - CLR_DBG_Commands::Debugging_Execution_Breakpoints* cmd = (CLR_DBG_Commands::Debugging_Execution_Breakpoints*)msg->m_payload; - g_CLR_RT_ExecutionEngine.InstallBreakpoints( cmd->m_data, (msg->m_header.m_size - sizeof(cmd->m_flags)) / sizeof(CLR_DBG_Commands::Debugging_Execution_BreakpointDef) ); + CLR_DBG_Commands::Debugging_Execution_Breakpoints *cmd = + (CLR_DBG_Commands::Debugging_Execution_Breakpoints *)msg->m_payload; + + g_CLR_RT_ExecutionEngine.InstallBreakpoints( + cmd->m_data, + (msg->m_header.m_size - sizeof(cmd->m_flags)) / sizeof(CLR_DBG_Commands::Debugging_Execution_BreakpointDef)); WP_ReplyToCommand(msg, true, false, NULL, 0); return true; } -bool CLR_DBG_Debugger::Debugging_Execution_BreakpointStatus( WP_Message* msg) +bool CLR_DBG_Debugger::Debugging_Execution_BreakpointStatus(WP_Message *msg) { NATIVE_PROFILE_CLR_DEBUGGER(); - + CLR_DBG_Commands::Debugging_Execution_BreakpointStatus::Reply reply; - if(g_CLR_RT_ExecutionEngine.DequeueActiveBreakpoint( reply.m_lastHit ) == false) + if (g_CLR_RT_ExecutionEngine.DequeueActiveBreakpoint(reply.m_lastHit) == false) { - memset( &reply.m_lastHit, 0, sizeof(reply.m_lastHit) ); + memset(&reply.m_lastHit, 0, sizeof(reply.m_lastHit)); } - WP_ReplyToCommand( msg, true, false, &reply, sizeof(reply) ); + WP_ReplyToCommand(msg, true, false, &reply, sizeof(reply)); return true; } //--// -CLR_RT_Assembly* CLR_DBG_Debugger::IsGoodAssembly( CLR_IDX idxAssm ) +CLR_RT_Assembly *CLR_DBG_Debugger::IsGoodAssembly(CLR_IDX idxAssm) { NATIVE_PROFILE_CLR_DEBUGGER(); NANOCLR_FOREACH_ASSEMBLY(g_CLR_RT_TypeSystem) { - if(pASSM->m_idx == idxAssm) return pASSM; + if (pASSM->m_idx == idxAssm) + return pASSM; } NANOCLR_FOREACH_ASSEMBLY_END(); return NULL; } -bool CLR_DBG_Debugger::CheckTypeDef( const CLR_RT_TypeDef_Index& td, CLR_RT_TypeDef_Instance& inst ) +bool CLR_DBG_Debugger::CheckTypeDef(const CLR_RT_TypeDef_Index &td, CLR_RT_TypeDef_Instance &inst) { NATIVE_PROFILE_CLR_DEBUGGER(); - CLR_RT_Assembly* assm = IsGoodAssembly( td.Assembly() ); + CLR_RT_Assembly *assm = IsGoodAssembly(td.Assembly()); - if(assm && td.Type() < assm->m_pTablesSize[ TBL_TypeDef ]) + if (assm && td.Type() < assm->m_pTablesSize[TBL_TypeDef]) { - return inst.InitializeFromIndex( td ); + return inst.InitializeFromIndex(td); } return false; } -bool CLR_DBG_Debugger::CheckFieldDef( const CLR_RT_FieldDef_Index& fd, CLR_RT_FieldDef_Instance& inst ) +bool CLR_DBG_Debugger::CheckFieldDef(const CLR_RT_FieldDef_Index &fd, CLR_RT_FieldDef_Instance &inst) { NATIVE_PROFILE_CLR_DEBUGGER(); - CLR_RT_Assembly* assm = IsGoodAssembly( fd.Assembly() ); + CLR_RT_Assembly *assm = IsGoodAssembly(fd.Assembly()); - if(assm && fd.Field() < assm->m_pTablesSize[ TBL_FieldDef ]) + if (assm && fd.Field() < assm->m_pTablesSize[TBL_FieldDef]) { - return inst.InitializeFromIndex( fd ); + return inst.InitializeFromIndex(fd); } return false; } -bool CLR_DBG_Debugger::CheckMethodDef( const CLR_RT_MethodDef_Index& md, CLR_RT_MethodDef_Instance& inst ) +bool CLR_DBG_Debugger::CheckMethodDef(const CLR_RT_MethodDef_Index &md, CLR_RT_MethodDef_Instance &inst) { NATIVE_PROFILE_CLR_DEBUGGER(); - CLR_RT_Assembly* assm = IsGoodAssembly( md.Assembly() ); + CLR_RT_Assembly *assm = IsGoodAssembly(md.Assembly()); - if(assm && md.Method() < assm->m_pTablesSize[ TBL_MethodDef ]) + if (assm && md.Method() < assm->m_pTablesSize[TBL_MethodDef]) { - return inst.InitializeFromIndex( md ); + return inst.InitializeFromIndex(md); } return false; } -CLR_RT_StackFrame* CLR_DBG_Debugger::CheckStackFrame( CLR_INT32 pid, CLR_UINT32 depth, bool& isInline ) +CLR_RT_StackFrame *CLR_DBG_Debugger::CheckStackFrame(CLR_INT32 pid, CLR_UINT32 depth, bool &isInline) { NATIVE_PROFILE_CLR_DEBUGGER(); - CLR_RT_Thread* th = GetThreadFromPid( pid ); + CLR_RT_Thread *th = GetThreadFromPid(pid); isInline = false; - if(th) + if (th) { - NANOCLR_FOREACH_NODE(CLR_RT_StackFrame,call,th->m_stackFrames) + NANOCLR_FOREACH_NODE(CLR_RT_StackFrame, call, th->m_stackFrames) { #ifndef CLR_NO_IL_INLINE - if(call->m_inlineFrame) + if (call->m_inlineFrame) { - if(depth-- == 0) + if (depth-- == 0) { isInline = true; return call; @@ -1979,7 +1866,8 @@ CLR_RT_StackFrame* CLR_DBG_Debugger::CheckStackFrame( CLR_INT32 pid, CLR_UINT32 } #endif - if(depth-- == 0) return call; + if (depth-- == 0) + return call; } NANOCLR_FOREACH_NODE_END(); } @@ -1989,21 +1877,22 @@ CLR_RT_StackFrame* CLR_DBG_Debugger::CheckStackFrame( CLR_INT32 pid, CLR_UINT32 //--// -static HRESULT Debugging_Thread_Create_Helper( CLR_RT_MethodDef_Index& md, CLR_RT_Thread*& th, CLR_INT32 pid ) +static HRESULT Debugging_Thread_Create_Helper(CLR_RT_MethodDef_Index &md, CLR_RT_Thread *&th, CLR_INT32 pid) { NATIVE_PROFILE_CLR_DEBUGGER(); NANOCLR_HEADER(); - CLR_RT_HeapBlock ref; ref.SetObjectReference( NULL ); - CLR_RT_ProtectFromGC gc( ref ); - CLR_RT_Thread* realThread = (pid != 0) ? CLR_DBG_Debugger::GetThreadFromPid( pid ) : NULL; + CLR_RT_HeapBlock ref; + ref.SetObjectReference(NULL); + CLR_RT_ProtectFromGC gc(ref); + CLR_RT_Thread *realThread = (pid != 0) ? CLR_DBG_Debugger::GetThreadFromPid(pid) : NULL; th = NULL; - NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_Delegate::CreateInstance( ref, md, NULL )); + NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_Delegate::CreateInstance(ref, md, NULL)); - NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.NewThread( th, ref.DereferenceDelegate(), ThreadPriority::Highest, -1 )); - + NANOCLR_CHECK_HRESULT( + g_CLR_RT_ExecutionEngine.NewThread(th, ref.DereferenceDelegate(), ThreadPriority::Highest, -1)); if (realThread) { @@ -2011,19 +1900,20 @@ static HRESULT Debugging_Thread_Create_Helper( CLR_RT_MethodDef_Index& md, CLR_R } { - CLR_RT_StackFrame* stack = th->CurrentFrame(); - const CLR_RECORD_METHODDEF* target = stack->m_call.m_target; - CLR_UINT8 numArgs = target->numArgs; + CLR_RT_StackFrame *stack = th->CurrentFrame(); + const CLR_RECORD_METHODDEF *target = stack->m_call.m_target; + CLR_UINT8 numArgs = target->numArgs; - if(numArgs) + if (numArgs) { - CLR_RT_SignatureParser parser; parser.Initialize_MethodSignature( stack->m_call.m_assm, target ); + CLR_RT_SignatureParser parser; + parser.Initialize_MethodSignature(stack->m_call.m_assm, target); CLR_RT_SignatureParser::Element res; - CLR_RT_HeapBlock* args = stack->m_arguments; + CLR_RT_HeapBlock *args = stack->m_arguments; - if(parser.m_flags & PIMAGE_CEE_CS_CALLCONV_HASTHIS) + if (parser.m_flags & PIMAGE_CEE_CS_CALLCONV_HASTHIS) { - args->SetObjectReference( NULL ); + args->SetObjectReference(NULL); numArgs--; args++; @@ -2032,7 +1922,7 @@ static HRESULT Debugging_Thread_Create_Helper( CLR_RT_MethodDef_Index& md, CLR_R // // Skip return value. // - NANOCLR_CHECK_HRESULT(parser.Advance( res )); + NANOCLR_CHECK_HRESULT(parser.Advance(res)); // // None of the arguments can be ByRef. @@ -2040,29 +1930,29 @@ static HRESULT Debugging_Thread_Create_Helper( CLR_RT_MethodDef_Index& md, CLR_R { CLR_RT_SignatureParser parser2 = parser; - for(;parser2.Available() > 0;) + for (; parser2.Available() > 0;) { - NANOCLR_CHECK_HRESULT(parser2.Advance( res )); + NANOCLR_CHECK_HRESULT(parser2.Advance(res)); - if(res.m_fByRef) + if (res.m_fByRef) { NANOCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE); } } } - for(CLR_UINT8 i=0; iTerminate(); th = NULL; @@ -2072,15 +1962,15 @@ static HRESULT Debugging_Thread_Create_Helper( CLR_RT_MethodDef_Index& md, CLR_R NANOCLR_CLEANUP_END(); } -bool CLR_DBG_Debugger::Debugging_Thread_CreateEx( WP_Message* msg) +bool CLR_DBG_Debugger::Debugging_Thread_CreateEx(WP_Message *msg) { NATIVE_PROFILE_CLR_DEBUGGER(); - - CLR_DBG_Commands::Debugging_Thread_CreateEx* cmd = (CLR_DBG_Commands::Debugging_Thread_CreateEx*)msg->m_payload; + + CLR_DBG_Commands::Debugging_Thread_CreateEx *cmd = (CLR_DBG_Commands::Debugging_Thread_CreateEx *)msg->m_payload; CLR_DBG_Commands::Debugging_Thread_CreateEx::Reply cmdReply; - CLR_RT_Thread* th; + CLR_RT_Thread *th; - if(SUCCEEDED(Debugging_Thread_Create_Helper( cmd->m_md, th, cmd->m_pid ))) + if (SUCCEEDED(Debugging_Thread_Create_Helper(cmd->m_md, th, cmd->m_pid))) { th->m_scratchPad = cmd->m_scratchPad; @@ -2091,63 +1981,63 @@ bool CLR_DBG_Debugger::Debugging_Thread_CreateEx( WP_Message* msg) cmdReply.m_pid = -1; } - WP_ReplyToCommand( msg, true, false, &cmdReply, sizeof(cmdReply) ); + WP_ReplyToCommand(msg, true, false, &cmdReply, sizeof(cmdReply)); return true; } -bool CLR_DBG_Debugger::Debugging_Thread_List( WP_Message* msg) +bool CLR_DBG_Debugger::Debugging_Thread_List(WP_Message *msg) { NATIVE_PROFILE_CLR_DEBUGGER(); - - CLR_DBG_Commands::Debugging_Thread_List::Reply* cmdReply = NULL; - int len = 0; - if(FAILED(g_CLR_DBG_Debugger->CreateListOfThreads( cmdReply, len ))) + CLR_DBG_Commands::Debugging_Thread_List::Reply *cmdReply = NULL; + int len = 0; + + if (FAILED(g_CLR_DBG_Debugger->CreateListOfThreads(cmdReply, len))) { - WP_ReplyToCommand( msg, false, false, NULL, 0); + WP_ReplyToCommand(msg, false, false, NULL, 0); } else { - WP_ReplyToCommand( msg, true, false, cmdReply, len ); + WP_ReplyToCommand(msg, true, false, cmdReply, len); } - CLR_RT_Memory::Release( cmdReply ); + CLR_RT_Memory::Release(cmdReply); return true; } -bool CLR_DBG_Debugger::Debugging_Thread_Stack( WP_Message* msg) +bool CLR_DBG_Debugger::Debugging_Thread_Stack(WP_Message *msg) { NATIVE_PROFILE_CLR_DEBUGGER(); - - CLR_DBG_Commands::Debugging_Thread_Stack* cmd = (CLR_DBG_Commands::Debugging_Thread_Stack*)msg->m_payload; - CLR_DBG_Commands::Debugging_Thread_Stack::Reply* cmdReply = NULL; - int len = 0; - if(FAILED(g_CLR_DBG_Debugger->CreateListOfCalls( cmd->m_pid, cmdReply, len ))) + CLR_DBG_Commands::Debugging_Thread_Stack *cmd = (CLR_DBG_Commands::Debugging_Thread_Stack *)msg->m_payload; + CLR_DBG_Commands::Debugging_Thread_Stack::Reply *cmdReply = NULL; + int len = 0; + + if (FAILED(g_CLR_DBG_Debugger->CreateListOfCalls(cmd->m_pid, cmdReply, len))) { WP_ReplyToCommand(msg, false, false, NULL, 0); } else { - WP_ReplyToCommand( msg, true, false, cmdReply, len ); + WP_ReplyToCommand(msg, true, false, cmdReply, len); } - CLR_RT_Memory::Release( cmdReply ); + CLR_RT_Memory::Release(cmdReply); return true; } -bool CLR_DBG_Debugger::Debugging_Thread_Kill( WP_Message* msg) +bool CLR_DBG_Debugger::Debugging_Thread_Kill(WP_Message *msg) { NATIVE_PROFILE_CLR_DEBUGGER(); - - CLR_DBG_Commands::Debugging_Thread_Kill* cmd = (CLR_DBG_Commands::Debugging_Thread_Kill*)msg->m_payload; + + CLR_DBG_Commands::Debugging_Thread_Kill *cmd = (CLR_DBG_Commands::Debugging_Thread_Kill *)msg->m_payload; CLR_DBG_Commands::Debugging_Thread_Kill::Reply cmdReply; - CLR_RT_Thread* th = g_CLR_DBG_Debugger->GetThreadFromPid( cmd->m_pid ); + CLR_RT_Thread *th = g_CLR_DBG_Debugger->GetThreadFromPid(cmd->m_pid); - if(th) + if (th) { th->Terminate(); @@ -2158,19 +2048,19 @@ bool CLR_DBG_Debugger::Debugging_Thread_Kill( WP_Message* msg) cmdReply.m_result = 0; } - WP_ReplyToCommand( msg, true, false, &cmdReply, sizeof(cmdReply) ); + WP_ReplyToCommand(msg, true, false, &cmdReply, sizeof(cmdReply)); return true; } -bool CLR_DBG_Debugger::Debugging_Thread_Suspend( WP_Message* msg) +bool CLR_DBG_Debugger::Debugging_Thread_Suspend(WP_Message *msg) { NATIVE_PROFILE_CLR_DEBUGGER(); - - CLR_DBG_Commands::Debugging_Thread_Suspend* cmd = (CLR_DBG_Commands::Debugging_Thread_Suspend*)msg->m_payload; - CLR_RT_Thread* th = g_CLR_DBG_Debugger->GetThreadFromPid( cmd->m_pid ); - if(th) + CLR_DBG_Commands::Debugging_Thread_Suspend *cmd = (CLR_DBG_Commands::Debugging_Thread_Suspend *)msg->m_payload; + CLR_RT_Thread *th = g_CLR_DBG_Debugger->GetThreadFromPid(cmd->m_pid); + + if (th) { th->Suspend(); } @@ -2180,14 +2070,14 @@ bool CLR_DBG_Debugger::Debugging_Thread_Suspend( WP_Message* msg) return true; } -bool CLR_DBG_Debugger::Debugging_Thread_Resume( WP_Message* msg) +bool CLR_DBG_Debugger::Debugging_Thread_Resume(WP_Message *msg) { NATIVE_PROFILE_CLR_DEBUGGER(); - - CLR_DBG_Commands::Debugging_Thread_Resume* cmd = (CLR_DBG_Commands::Debugging_Thread_Resume*)msg->m_payload; - CLR_RT_Thread* th = g_CLR_DBG_Debugger->GetThreadFromPid( cmd->m_pid ); - if(th) + CLR_DBG_Commands::Debugging_Thread_Resume *cmd = (CLR_DBG_Commands::Debugging_Thread_Resume *)msg->m_payload; + CLR_RT_Thread *th = g_CLR_DBG_Debugger->GetThreadFromPid(cmd->m_pid); + + if (th) { th->Resume(); } @@ -2197,125 +2087,135 @@ bool CLR_DBG_Debugger::Debugging_Thread_Resume( WP_Message* msg) return true; } -bool CLR_DBG_Debugger::Debugging_Thread_Get( WP_Message* msg) +bool CLR_DBG_Debugger::Debugging_Thread_Get(WP_Message *msg) { NATIVE_PROFILE_CLR_DEBUGGER(); - CLR_DBG_Debugger* dbg = g_CLR_DBG_Debugger; - CLR_DBG_Commands::Debugging_Thread_Get* cmd = (CLR_DBG_Commands::Debugging_Thread_Get*)msg->m_payload; - CLR_RT_Thread* th = dbg->GetThreadFromPid( cmd->m_pid ); - CLR_RT_HeapBlock* pThread; + CLR_DBG_Debugger *dbg = g_CLR_DBG_Debugger; + CLR_DBG_Commands::Debugging_Thread_Get *cmd = (CLR_DBG_Commands::Debugging_Thread_Get *)msg->m_payload; + CLR_RT_Thread *th = dbg->GetThreadFromPid(cmd->m_pid); + CLR_RT_HeapBlock *pThread; bool fFound = false; - if(th == NULL) return false; + if (th == NULL) + return false; #if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) - //If we are a thread spawned by the debugger to perform evaluations, - //return the thread object that correspond to thread that has focus in debugger. + // If we are a thread spawned by the debugger to perform evaluations, + // return the thread object that correspond to thread that has focus in debugger. th = th->m_realThread; #endif //#if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) - //Find an existing managed thread, if it exists - //making sure to only return the managed object association with the current appdomain - //to prevent leaking of managed Thread objects across AD boundaries. + // Find an existing managed thread, if it exists + // making sure to only return the managed object association with the current appdomain + // to prevent leaking of managed Thread objects across AD boundaries. - NANOCLR_FOREACH_NODE(CLR_RT_ObjectToEvent_Source,src,th->m_references) + NANOCLR_FOREACH_NODE(CLR_RT_ObjectToEvent_Source, src, th->m_references) { - CLR_RT_HeapBlock* pManagedThread = src->m_objectPtr; + CLR_RT_HeapBlock *pManagedThread = src->m_objectPtr; _ASSERTE(pManagedThread != NULL); - + #if defined(NANOCLR_APPDOMAINS) { - CLR_RT_ObjectToEvent_Source* appDomainSrc = CLR_RT_ObjectToEvent_Source::ExtractInstance( pManagedThread[ Library_corlib_native_System_Threading_Thread::FIELD___appDomain ] ); + CLR_RT_ObjectToEvent_Source *appDomainSrc = CLR_RT_ObjectToEvent_Source::ExtractInstance( + pManagedThread[Library_corlib_native_System_Threading_Thread::FIELD___appDomain]); + + if (appDomainSrc == NULL) + break; - if(appDomainSrc == NULL) break; - fFound = (appDomainSrc->m_eventPtr == g_CLR_RT_ExecutionEngine.GetCurrentAppDomain()); } #else fFound = true; #endif - if(fFound) + if (fFound) { pThread = pManagedThread; - + break; } } - NANOCLR_FOREACH_NODE_END(); + NANOCLR_FOREACH_NODE_END(); - if(!fFound) + if (!fFound) { - pThread = (CLR_RT_HeapBlock*)platform_malloc(sizeof(CLR_RT_HeapBlock)); - - //Create the managed thread. - //This implies that there is no state in the managed object. This is not exactly true, as the managed thread - //contains the priority as well as the delegate to start. However, that state is really just used as a placeholder for - //the data before the thread is started. Once the thread is started, they are copied over to the unmanaged thread object - //and no longer used. The managed object is then used simply as a wrapper for the unmanaged thread. Therefore, it is safe - //to simply make another managed thread here. - if(SUCCEEDED(g_CLR_RT_ExecutionEngine.NewObjectFromIndex( *pThread, g_CLR_RT_WellKnownTypes.m_Thread ))) + pThread = (CLR_RT_HeapBlock *)platform_malloc(sizeof(CLR_RT_HeapBlock)); + + // Create the managed thread. + // This implies that there is no state in the managed object. This is not exactly true, as the managed thread + // contains the priority as well as the delegate to start. However, that state is really just used as a + // placeholder for the data before the thread is started. Once the thread is started, they are copied over to + // the unmanaged thread object and no longer used. The managed object is then used simply as a wrapper for the + // unmanaged thread. Therefore, it is safe to simply make another managed thread here. + if (SUCCEEDED(g_CLR_RT_ExecutionEngine.NewObjectFromIndex(*pThread, g_CLR_RT_WellKnownTypes.m_Thread))) { - CLR_RT_HeapBlock* pRes = pThread->Dereference(); + CLR_RT_HeapBlock *pRes = pThread->Dereference(); int pri = th->GetThreadPriority(); - + pRes[Library_corlib_native_System_Threading_Thread::FIELD___priority].NumericByRef().s4 = pri; - if(SUCCEEDED(CLR_RT_ObjectToEvent_Source::CreateInstance( th, *pRes, pRes[ Library_corlib_native_System_Threading_Thread::FIELD___thread ] ))) + if (SUCCEEDED(CLR_RT_ObjectToEvent_Source::CreateInstance( + th, + *pRes, + pRes[Library_corlib_native_System_Threading_Thread::FIELD___thread]))) { #if defined(NANOCLR_APPDOMAINS) - CLR_RT_ObjectToEvent_Source::CreateInstance( g_CLR_RT_ExecutionEngine.GetCurrentAppDomain(), *pRes, pRes[ Library_corlib_native_System_Threading_Thread::FIELD___appDomain ] ); + CLR_RT_ObjectToEvent_Source::CreateInstance( + g_CLR_RT_ExecutionEngine.GetCurrentAppDomain(), + *pRes, + pRes[Library_corlib_native_System_Threading_Thread::FIELD___appDomain]); #endif fFound = true; } - } } - if(!fFound) return false; - - return g_CLR_DBG_Debugger->GetValue( msg, pThread, NULL, NULL ); + if (!fFound) + return false; + + return g_CLR_DBG_Debugger->GetValue(msg, pThread, NULL, NULL); } -bool CLR_DBG_Debugger::Debugging_Thread_GetException( WP_Message* msg) +bool CLR_DBG_Debugger::Debugging_Thread_GetException(WP_Message *msg) { NATIVE_PROFILE_CLR_DEBUGGER(); - - CLR_DBG_Commands::Debugging_Thread_GetException* cmd = (CLR_DBG_Commands::Debugging_Thread_GetException*)msg->m_payload; - CLR_RT_Thread* th = g_CLR_DBG_Debugger->GetThreadFromPid( cmd->m_pid ); - CLR_RT_HeapBlock* blk = NULL; - if(th) + CLR_DBG_Commands::Debugging_Thread_GetException *cmd = + (CLR_DBG_Commands::Debugging_Thread_GetException *)msg->m_payload; + CLR_RT_Thread *th = g_CLR_DBG_Debugger->GetThreadFromPid(cmd->m_pid); + CLR_RT_HeapBlock *blk = NULL; + + if (th) { blk = &th->m_currentException; } - return g_CLR_DBG_Debugger->GetValue( msg, blk, NULL, NULL ); + return g_CLR_DBG_Debugger->GetValue(msg, blk, NULL, NULL); } -bool CLR_DBG_Debugger::Debugging_Thread_Unwind( WP_Message* msg) +bool CLR_DBG_Debugger::Debugging_Thread_Unwind(WP_Message *msg) { NATIVE_PROFILE_CLR_DEBUGGER(); - - CLR_DBG_Commands::Debugging_Thread_Unwind* cmd = (CLR_DBG_Commands::Debugging_Thread_Unwind*)msg->m_payload; - CLR_RT_StackFrame* call; - CLR_RT_Thread* th; - bool isInline = false; - if((call = g_CLR_DBG_Debugger->CheckStackFrame( cmd->m_pid, cmd->m_depth, isInline )) != NULL) + CLR_DBG_Commands::Debugging_Thread_Unwind *cmd = (CLR_DBG_Commands::Debugging_Thread_Unwind *)msg->m_payload; + CLR_RT_StackFrame *call; + CLR_RT_Thread *th; + bool isInline = false; + + if ((call = g_CLR_DBG_Debugger->CheckStackFrame(cmd->m_pid, cmd->m_depth, isInline)) != NULL) { _ASSERTE((call->m_flags & CLR_RT_StackFrame::c_MethodKind_Native) == 0); th = call->m_owningThread; _ASSERTE(th->m_nestedExceptionsPos); - CLR_RT_Thread::UnwindStack& us = th->m_nestedExceptions[ th->m_nestedExceptionsPos - 1 ]; + CLR_RT_Thread::UnwindStack &us = th->m_nestedExceptions[th->m_nestedExceptionsPos - 1]; _ASSERTE(th->m_currentException.Dereference() == us.m_exception); _ASSERTE(us.m_flags & CLR_RT_Thread::UnwindStack::c_ContinueExceptionHandler); - us.m_handlerStack = call; - us.m_flags |= CLR_RT_Thread::UnwindStack::c_MagicCatchForInteceptedException; + us.m_handlerStack = call; + us.m_flags |= CLR_RT_Thread::UnwindStack::c_MagicCatchForInteceptedException; us.SetPhase(CLR_RT_Thread::UnwindStack::p_2_RunningFinallys_0); } @@ -2325,70 +2225,70 @@ bool CLR_DBG_Debugger::Debugging_Thread_Unwind( WP_Message* msg) //--// -bool CLR_DBG_Debugger::Debugging_Stack_Info( WP_Message* msg) +bool CLR_DBG_Debugger::Debugging_Stack_Info(WP_Message *msg) { NATIVE_PROFILE_CLR_DEBUGGER(); - - CLR_DBG_Commands::Debugging_Stack_Info* cmd = (CLR_DBG_Commands::Debugging_Stack_Info*)msg->m_payload; + + CLR_DBG_Commands::Debugging_Stack_Info *cmd = (CLR_DBG_Commands::Debugging_Stack_Info *)msg->m_payload; CLR_DBG_Commands::Debugging_Stack_Info::Reply cmdReply; - CLR_RT_StackFrame* call; - bool isInline = false; + CLR_RT_StackFrame *call; + bool isInline = false; - if((call = g_CLR_DBG_Debugger->CheckStackFrame( cmd->m_pid, cmd->m_depth, isInline )) != NULL) + if ((call = g_CLR_DBG_Debugger->CheckStackFrame(cmd->m_pid, cmd->m_depth, isInline)) != NULL) { #ifndef CLR_NO_IL_INLINE - if(isInline) + if (isInline) { - cmdReply.m_md = call->m_inlineFrame->m_frame.m_call; - cmdReply.m_IP = (CLR_UINT32)(call->m_inlineFrame->m_frame.m_IP - call->m_inlineFrame->m_frame.m_IPStart); - cmdReply.m_numOfArguments = call->m_inlineFrame->m_frame.m_call.m_target->numArgs; - cmdReply.m_numOfLocals = call->m_inlineFrame->m_frame.m_call.m_target->numLocals; + cmdReply.m_md = call->m_inlineFrame->m_frame.m_call; + cmdReply.m_IP = (CLR_UINT32)(call->m_inlineFrame->m_frame.m_IP - call->m_inlineFrame->m_frame.m_IPStart); + cmdReply.m_numOfArguments = call->m_inlineFrame->m_frame.m_call.m_target->numArgs; + cmdReply.m_numOfLocals = call->m_inlineFrame->m_frame.m_call.m_target->numLocals; cmdReply.m_depthOfEvalStack = (CLR_UINT32)(call->m_evalStack - call->m_inlineFrame->m_frame.m_evalStack); } else #endif { - cmdReply.m_md = call->m_call; - cmdReply.m_IP = (CLR_UINT32)(call->m_IP - call->m_IPstart); - cmdReply.m_numOfArguments = call->m_call.m_target->numArgs; - cmdReply.m_numOfLocals = call->m_call.m_target->numLocals; - cmdReply.m_depthOfEvalStack = (CLR_UINT32) call->TopValuePosition(); + cmdReply.m_md = call->m_call; + cmdReply.m_IP = (CLR_UINT32)(call->m_IP - call->m_IPstart); + cmdReply.m_numOfArguments = call->m_call.m_target->numArgs; + cmdReply.m_numOfLocals = call->m_call.m_target->numLocals; + cmdReply.m_depthOfEvalStack = (CLR_UINT32)call->TopValuePosition(); } - WP_ReplyToCommand( msg, true, false, &cmdReply, sizeof(cmdReply) ); + WP_ReplyToCommand(msg, true, false, &cmdReply, sizeof(cmdReply)); return true; } - WP_ReplyToCommand(msg, false, false, NULL, 0); + WP_ReplyToCommand(msg, false, false, NULL, 0); return true; } -bool CLR_DBG_Debugger::Debugging_Stack_SetIP( WP_Message* msg) +bool CLR_DBG_Debugger::Debugging_Stack_SetIP(WP_Message *msg) { NATIVE_PROFILE_CLR_DEBUGGER(); - - CLR_DBG_Commands::Debugging_Stack_SetIP* cmd = (CLR_DBG_Commands::Debugging_Stack_SetIP*)msg->m_payload; - CLR_RT_StackFrame* call; - bool isInline = false; - if((call = g_CLR_DBG_Debugger->CheckStackFrame( cmd->m_pid, cmd->m_depth, isInline )) != NULL) + CLR_DBG_Commands::Debugging_Stack_SetIP *cmd = (CLR_DBG_Commands::Debugging_Stack_SetIP *)msg->m_payload; + CLR_RT_StackFrame *call; + bool isInline = false; + + if ((call = g_CLR_DBG_Debugger->CheckStackFrame(cmd->m_pid, cmd->m_depth, isInline)) != NULL) { #ifndef CLR_NO_IL_INLINE - if(isInline) + if (isInline) { WP_ReplyToCommand(msg, false, false, NULL, 0); return true; } else -#endif +#endif { - call->m_IP = call->m_IPstart + cmd->m_IP; - call->m_evalStackPos = call->m_evalStack + cmd->m_depthOfEvalStack; + call->m_IP = call->m_IPstart + cmd->m_IP; + call->m_evalStackPos = call->m_evalStack + cmd->m_depthOfEvalStack; } - + call->m_flags &= ~CLR_RT_StackFrame::c_InvalidIP; WP_ReplyToCommand(msg, true, false, NULL, 0); @@ -2403,55 +2303,56 @@ bool CLR_DBG_Debugger::Debugging_Stack_SetIP( WP_Message* msg) //--// -static bool IsBlockEnumMaybe( CLR_RT_HeapBlock* blk ) +static bool IsBlockEnumMaybe(CLR_RT_HeapBlock *blk) { NATIVE_PROFILE_CLR_DEBUGGER(); const CLR_UINT32 c_MaskForPrimitive = CLR_RT_DataTypeLookup::c_Integer | CLR_RT_DataTypeLookup::c_Numeric; CLR_RT_TypeDescriptor desc; - if(FAILED(desc.InitializeFromObject( *blk ))) return false; + if (FAILED(desc.InitializeFromObject(*blk))) + return false; - const CLR_RT_DataTypeLookup& dtl = c_CLR_RT_DataTypeLookup[ desc.m_handlerCls.m_target->dataType ]; + const CLR_RT_DataTypeLookup &dtl = c_CLR_RT_DataTypeLookup[desc.m_handlerCls.m_target->dataType]; return (dtl.m_flags & c_MaskForPrimitive) == c_MaskForPrimitive; } -static bool SetBlockHelper( CLR_RT_HeapBlock* blk, CLR_DataType dt, CLR_UINT8* builtinValue ) +static bool SetBlockHelper(CLR_RT_HeapBlock *blk, CLR_DataType dt, CLR_UINT8 *builtinValue) { NATIVE_PROFILE_CLR_DEBUGGER(); bool fCanAssign = false; - if(blk) + if (blk) { - CLR_DataType dtDst; - CLR_RT_HeapBlock src; + CLR_DataType dtDst; + CLR_RT_HeapBlock src; dtDst = blk->DataType(); - src.SetDataId( CLR_RT_HEAPBLOCK_RAW_ID(dt, 0, 1) ); - memcpy( (void*)&src.NumericByRef().u1, builtinValue, sizeof(CLR_UINT64) ); + src.SetDataId(CLR_RT_HEAPBLOCK_RAW_ID(dt, 0, 1)); + memcpy((void *)&src.NumericByRef().u1, builtinValue, sizeof(CLR_UINT64)); - if(dtDst == dt) + if (dtDst == dt) { fCanAssign = true; } else { - if(dt == DATATYPE_REFLECTION) + if (dt == DATATYPE_REFLECTION) { fCanAssign = (dtDst == DATATYPE_OBJECT && blk->Dereference() == NULL); } - else if(dt == DATATYPE_OBJECT) + else if (dt == DATATYPE_OBJECT) { - fCanAssign = (src .Dereference() == NULL && dtDst == DATATYPE_REFLECTION); + fCanAssign = (src.Dereference() == NULL && dtDst == DATATYPE_REFLECTION); } else { - _ASSERTE(c_CLR_RT_DataTypeLookup[ dtDst ].m_flags & CLR_RT_DataTypeLookup::c_Numeric); + _ASSERTE(c_CLR_RT_DataTypeLookup[dtDst].m_flags & CLR_RT_DataTypeLookup::c_Numeric); - if(c_CLR_RT_DataTypeLookup[ dtDst ].m_sizeInBytes == sizeof(CLR_INT32) && - c_CLR_RT_DataTypeLookup[ dt ].m_sizeInBytes < sizeof(CLR_INT32)) + if (c_CLR_RT_DataTypeLookup[dtDst].m_sizeInBytes == sizeof(CLR_INT32) && + c_CLR_RT_DataTypeLookup[dt].m_sizeInBytes < sizeof(CLR_INT32)) { dt = dtDst; fCanAssign = true; @@ -2459,28 +2360,28 @@ static bool SetBlockHelper( CLR_RT_HeapBlock* blk, CLR_DataType dt, CLR_UINT8* b } } - if(fCanAssign) + if (fCanAssign) { - blk->ChangeDataType( dt ); - memcpy( (void*)&blk->NumericByRef().u1, builtinValue, sizeof(CLR_UINT64) ); + blk->ChangeDataType(dt); + memcpy((void *)&blk->NumericByRef().u1, builtinValue, sizeof(CLR_UINT64)); } } return fCanAssign; } -static CLR_RT_HeapBlock* GetScratchPad_Helper( int idx ) +static CLR_RT_HeapBlock *GetScratchPad_Helper(int idx) { NATIVE_PROFILE_CLR_DEBUGGER(); - CLR_RT_HeapBlock_Array* array = g_CLR_RT_ExecutionEngine.m_scratchPadArray; - CLR_RT_HeapBlock tmp; - CLR_RT_HeapBlock ref; + CLR_RT_HeapBlock_Array *array = g_CLR_RT_ExecutionEngine.m_scratchPadArray; + CLR_RT_HeapBlock tmp; + CLR_RT_HeapBlock ref; - tmp.SetObjectReference( array ); + tmp.SetObjectReference(array); - if(SUCCEEDED(ref.InitializeArrayReference( tmp, idx ))) + if (SUCCEEDED(ref.InitializeArrayReference(tmp, idx))) { - return (CLR_RT_HeapBlock*)array->GetElement( idx ); + return (CLR_RT_HeapBlock *)array->GetElement(idx); } return NULL; @@ -2488,28 +2389,32 @@ static CLR_RT_HeapBlock* GetScratchPad_Helper( int idx ) //--// -bool CLR_DBG_Debugger::Debugging_Value_ResizeScratchPad( WP_Message* msg) +bool CLR_DBG_Debugger::Debugging_Value_ResizeScratchPad(WP_Message *msg) { NATIVE_PROFILE_CLR_DEBUGGER(); - - CLR_DBG_Commands::Debugging_Value_ResizeScratchPad* cmd = (CLR_DBG_Commands::Debugging_Value_ResizeScratchPad*)msg->m_payload; - CLR_RT_HeapBlock ref; - bool fRes = true; - if(cmd->m_size == 0) + CLR_DBG_Commands::Debugging_Value_ResizeScratchPad *cmd = + (CLR_DBG_Commands::Debugging_Value_ResizeScratchPad *)msg->m_payload; + CLR_RT_HeapBlock ref; + bool fRes = true; + + if (cmd->m_size == 0) { g_CLR_RT_ExecutionEngine.m_scratchPadArray = NULL; } else { - if(SUCCEEDED(CLR_RT_HeapBlock_Array::CreateInstance( ref, cmd->m_size, g_CLR_RT_WellKnownTypes.m_Object ))) + if (SUCCEEDED(CLR_RT_HeapBlock_Array::CreateInstance(ref, cmd->m_size, g_CLR_RT_WellKnownTypes.m_Object))) { - CLR_RT_HeapBlock_Array* pOld = g_CLR_RT_ExecutionEngine.m_scratchPadArray; - CLR_RT_HeapBlock_Array* pNew = ref.DereferenceArray(); + CLR_RT_HeapBlock_Array *pOld = g_CLR_RT_ExecutionEngine.m_scratchPadArray; + CLR_RT_HeapBlock_Array *pNew = ref.DereferenceArray(); - if(pOld) + if (pOld) { - memcpy( pNew->GetFirstElement(), pOld->GetFirstElement(), sizeof(CLR_RT_HeapBlock) * __min( pNew->m_numOfElements, pOld->m_numOfElements ) ); + memcpy( + pNew->GetFirstElement(), + pOld->GetFirstElement(), + sizeof(CLR_RT_HeapBlock) * __min(pNew->m_numOfElements, pOld->m_numOfElements)); } g_CLR_RT_ExecutionEngine.m_scratchPadArray = pNew; @@ -2525,256 +2430,268 @@ bool CLR_DBG_Debugger::Debugging_Value_ResizeScratchPad( WP_Message* msg) return false; } -bool CLR_DBG_Debugger::Debugging_Value_GetStack( WP_Message* msg) +bool CLR_DBG_Debugger::Debugging_Value_GetStack(WP_Message *msg) { NATIVE_PROFILE_CLR_DEBUGGER(); - - CLR_DBG_Commands::Debugging_Value_GetStack* cmd = (CLR_DBG_Commands::Debugging_Value_GetStack*)msg->m_payload; - CLR_RT_StackFrame* call; - bool isInline = false; - if((call = g_CLR_DBG_Debugger->CheckStackFrame( cmd->m_pid, cmd->m_depth, isInline )) != NULL) + CLR_DBG_Commands::Debugging_Value_GetStack *cmd = (CLR_DBG_Commands::Debugging_Value_GetStack *)msg->m_payload; + CLR_RT_StackFrame *call; + bool isInline = false; + + if ((call = g_CLR_DBG_Debugger->CheckStackFrame(cmd->m_pid, cmd->m_depth, isInline)) != NULL) { - CLR_RT_HeapBlock* array; - CLR_UINT32 num; + CLR_RT_HeapBlock *array; + CLR_UINT32 num; #ifndef CLR_NO_IL_INLINE - CLR_RT_MethodDef_Instance& md = isInline ? call->m_inlineFrame->m_frame.m_call : call->m_call; + CLR_RT_MethodDef_Instance &md = isInline ? call->m_inlineFrame->m_frame.m_call : call->m_call; #else - CLR_RT_MethodDef_Instance& md = call->m_call; + CLR_RT_MethodDef_Instance &md = call->m_call; #endif - switch(cmd->m_kind) + switch (cmd->m_kind) { - case CLR_DBG_Commands::Debugging_Value_GetStack::c_Argument: + case CLR_DBG_Commands::Debugging_Value_GetStack::c_Argument: #ifndef CLR_NO_IL_INLINE - array = isInline ? call->m_inlineFrame->m_frame.m_args : call->m_arguments; - num = isInline ? md.m_target->numArgs : md.m_target->numArgs; + array = isInline ? call->m_inlineFrame->m_frame.m_args : call->m_arguments; + num = isInline ? md.m_target->numArgs : md.m_target->numArgs; #else - array = call->m_arguments; - num = call->m_call.m_target->numArgs; + array = call->m_arguments; + num = call->m_call.m_target->numArgs; #endif - break; + break; - case CLR_DBG_Commands::Debugging_Value_GetStack::c_Local: + case CLR_DBG_Commands::Debugging_Value_GetStack::c_Local: #ifndef CLR_NO_IL_INLINE - array = isInline ? call->m_inlineFrame->m_frame.m_locals : call->m_locals; - num = isInline ? md.m_target->numLocals : md.m_target->numLocals; + array = isInline ? call->m_inlineFrame->m_frame.m_locals : call->m_locals; + num = isInline ? md.m_target->numLocals : md.m_target->numLocals; #else - array = call->m_locals; - num = call->m_call.m_target->numLocals; + array = call->m_locals; + num = call->m_call.m_target->numLocals; #endif - break; + break; - case CLR_DBG_Commands::Debugging_Value_GetStack::c_EvalStack: + case CLR_DBG_Commands::Debugging_Value_GetStack::c_EvalStack: #ifndef CLR_NO_IL_INLINE - array = isInline ? call->m_inlineFrame->m_frame.m_evalStack : call->m_evalStack; - num = isInline ? (CLR_UINT32)(call->m_evalStack - call->m_inlineFrame->m_frame.m_evalStack) : (CLR_UINT32)call->TopValuePosition(); + array = isInline ? call->m_inlineFrame->m_frame.m_evalStack : call->m_evalStack; + num = isInline ? (CLR_UINT32)(call->m_evalStack - call->m_inlineFrame->m_frame.m_evalStack) + : (CLR_UINT32)call->TopValuePosition(); #else - array = call->m_evalStack; - num = (CLR_UINT32)call->TopValuePosition(); + array = call->m_evalStack; + num = (CLR_UINT32)call->TopValuePosition(); #endif - break; + break; - default: - return false; + default: + return false; } - if(cmd->m_index >= num) return false; + if (cmd->m_index >= num) + return false; - CLR_RT_HeapBlock* blk = &array[ cmd->m_index ]; - CLR_RT_HeapBlock* reference = NULL; - CLR_RT_HeapBlock tmp; - CLR_RT_TypeDef_Instance* pTD = NULL; - CLR_RT_TypeDef_Instance td; + CLR_RT_HeapBlock *blk = &array[cmd->m_index]; + CLR_RT_HeapBlock *reference = NULL; + CLR_RT_HeapBlock tmp; + CLR_RT_TypeDef_Instance *pTD = NULL; + CLR_RT_TypeDef_Instance td; - if(cmd->m_kind != CLR_DBG_Commands::Debugging_Value_GetStack::c_EvalStack && IsBlockEnumMaybe( blk )) + if (cmd->m_kind != CLR_DBG_Commands::Debugging_Value_GetStack::c_EvalStack && IsBlockEnumMaybe(blk)) { - CLR_UINT32 iElement = cmd->m_index; - CLR_RT_SignatureParser parser; + CLR_UINT32 iElement = cmd->m_index; + CLR_RT_SignatureParser parser; CLR_RT_SignatureParser::Element res; - CLR_RT_TypeDescriptor desc; + CLR_RT_TypeDescriptor desc; - if(cmd->m_kind == CLR_DBG_Commands::Debugging_Value_GetStack::c_Argument) + if (cmd->m_kind == CLR_DBG_Commands::Debugging_Value_GetStack::c_Argument) { - parser.Initialize_MethodSignature( md.m_assm, md.m_target ); + parser.Initialize_MethodSignature(md.m_assm, md.m_target); iElement++; // Skip the return value, always at the head of the signature. - if(parser.m_flags & PIMAGE_CEE_CS_CALLCONV_HASTHIS) + if (parser.m_flags & PIMAGE_CEE_CS_CALLCONV_HASTHIS) { - if(iElement == 0) return false; // The requested argument is the "this" argument, it can never be a primitive. + if (iElement == 0) + return false; // The requested argument is the "this" argument, it can never be a primitive. iElement--; } } else { - parser.Initialize_MethodLocals( md.m_assm, md.m_target ); + parser.Initialize_MethodLocals(md.m_assm, md.m_target); } do { - parser.Advance( res ); - } - while(iElement--); + parser.Advance(res); + } while (iElement--); // // Arguments to a methods come from the eval stack and we don't fix up the eval stack for each call. // So some arguments have the wrong datatype, since an eval stack push always promotes to 32 bits. // - if(c_CLR_RT_DataTypeLookup[ blk->DataType() ].m_sizeInBytes == sizeof(CLR_INT32) && - c_CLR_RT_DataTypeLookup[ res.m_dt ].m_sizeInBytes < sizeof(CLR_INT32) ) + if (c_CLR_RT_DataTypeLookup[blk->DataType()].m_sizeInBytes == sizeof(CLR_INT32) && + c_CLR_RT_DataTypeLookup[res.m_dt].m_sizeInBytes < sizeof(CLR_INT32)) { - tmp.Assign ( *blk ); - tmp.ChangeDataType( res.m_dt ); + tmp.Assign(*blk); + tmp.ChangeDataType(res.m_dt); - reference = blk; blk = &tmp; + reference = blk; + blk = &tmp; } // // Check for enum. // - desc.InitializeFromType( res.m_cls ); + desc.InitializeFromType(res.m_cls); - if(desc.m_handlerCls.m_target->IsEnum()) + if (desc.m_handlerCls.m_target->IsEnum()) { - td = desc.m_handlerCls; pTD = &td; + td = desc.m_handlerCls; + pTD = &td; } } - return g_CLR_DBG_Debugger->GetValue( msg, blk, reference, pTD ); + return g_CLR_DBG_Debugger->GetValue(msg, blk, reference, pTD); } return false; } -bool CLR_DBG_Debugger::Debugging_Value_GetField( WP_Message* msg) +bool CLR_DBG_Debugger::Debugging_Value_GetField(WP_Message *msg) { NATIVE_PROFILE_CLR_DEBUGGER(); - - CLR_DBG_Commands::Debugging_Value_GetField* cmd = (CLR_DBG_Commands::Debugging_Value_GetField*)msg->m_payload; - CLR_RT_HeapBlock* blk = cmd->m_heapblock; - CLR_RT_HeapBlock* reference = NULL; - CLR_RT_HeapBlock tmp; - CLR_RT_TypeDescriptor desc; - CLR_RT_TypeDef_Instance td; - CLR_RT_TypeDef_Instance* pTD = NULL; - CLR_RT_FieldDef_Instance inst; - CLR_UINT32 offset; - if(blk != NULL && cmd->m_offset > 0) + CLR_DBG_Commands::Debugging_Value_GetField *cmd = (CLR_DBG_Commands::Debugging_Value_GetField *)msg->m_payload; + CLR_RT_HeapBlock *blk = cmd->m_heapblock; + CLR_RT_HeapBlock *reference = NULL; + CLR_RT_HeapBlock tmp; + CLR_RT_TypeDescriptor desc; + CLR_RT_TypeDef_Instance td; + CLR_RT_TypeDef_Instance *pTD = NULL; + CLR_RT_FieldDef_Instance inst; + CLR_UINT32 offset; + + if (blk != NULL && cmd->m_offset > 0) { - if(FAILED(desc.InitializeFromObject( *blk ))) return false; + if (FAILED(desc.InitializeFromObject(*blk))) + return false; - td = desc.m_handlerCls; + td = desc.m_handlerCls; offset = cmd->m_offset - 1; - while(true) + while (true) { - CLR_UINT32 iFields = td.m_target->iFields_Num; + CLR_UINT32 iFields = td.m_target->iFields_Num; CLR_UINT32 totalFields = td.CrossReference().m_totalFields; - CLR_UINT32 dFields = totalFields - iFields; + CLR_UINT32 dFields = totalFields - iFields; - if(offset >= dFields) + if (offset >= dFields) { offset -= dFields; break; } - if(!td.SwitchToParent()) return false; + if (!td.SwitchToParent()) + return false; } - cmd->m_fd.Set( td.Assembly(), td.m_target->iFields_First + offset ); + cmd->m_fd.Set(td.Assembly(), td.m_target->iFields_First + offset); } - if(!g_CLR_DBG_Debugger->CheckFieldDef( cmd->m_fd, inst )) return false; + if (!g_CLR_DBG_Debugger->CheckFieldDef(cmd->m_fd, inst)) + return false; - if(blk == NULL) + if (blk == NULL) { - blk = CLR_RT_ExecutionEngine::AccessStaticField( cmd->m_fd ); + blk = CLR_RT_ExecutionEngine::AccessStaticField(cmd->m_fd); } else { - if(cmd->m_offset == 0) + if (cmd->m_offset == 0) { cmd->m_offset = inst.CrossReference().m_offset; } - if(cmd->m_offset == 0) return false; + if (cmd->m_offset == 0) + return false; - switch(blk->DataType()) + switch (blk->DataType()) { - case DATATYPE_CLASS : + case DATATYPE_CLASS: case DATATYPE_VALUETYPE: break; default: - if(FAILED(blk->EnsureObjectReference( blk ))) return false; + if (FAILED(blk->EnsureObjectReference(blk))) + return false; break; } - switch(blk->DataType()) + switch (blk->DataType()) { case DATATYPE_DATETIME: // Special case. case DATATYPE_TIMESPAN: // Special case. - tmp.SetInteger( (CLR_INT64)blk->NumericByRefConst().s8 ); - reference = blk; blk = &tmp; + tmp.SetInteger((CLR_INT64)blk->NumericByRefConst().s8); + reference = blk; + blk = &tmp; break; default: - blk = &blk[ cmd->m_offset ]; + blk = &blk[cmd->m_offset]; break; } } - if(IsBlockEnumMaybe( blk )) + if (IsBlockEnumMaybe(blk)) { - if(SUCCEEDED(desc.InitializeFromFieldDefinition( inst ))) + if (SUCCEEDED(desc.InitializeFromFieldDefinition(inst))) { - if(desc.m_handlerCls.m_target->IsEnum()) + if (desc.m_handlerCls.m_target->IsEnum()) { pTD = &desc.m_handlerCls; } } } - return g_CLR_DBG_Debugger->GetValue( msg, blk, reference, pTD ); + return g_CLR_DBG_Debugger->GetValue(msg, blk, reference, pTD); } -bool CLR_DBG_Debugger::Debugging_Value_GetArray( WP_Message* msg) +bool CLR_DBG_Debugger::Debugging_Value_GetArray(WP_Message *msg) { NATIVE_PROFILE_CLR_DEBUGGER(); - - CLR_DBG_Commands::Debugging_Value_GetArray* cmd = (CLR_DBG_Commands::Debugging_Value_GetArray*)msg->m_payload; - CLR_RT_HeapBlock* blk = NULL; - CLR_RT_HeapBlock* reference = NULL; - CLR_RT_HeapBlock tmp; - CLR_RT_HeapBlock ref; - CLR_RT_TypeDef_Instance* pTD = NULL; - CLR_RT_TypeDef_Instance td; - tmp.SetObjectReference( cmd->m_heapblock ); + CLR_DBG_Commands::Debugging_Value_GetArray *cmd = (CLR_DBG_Commands::Debugging_Value_GetArray *)msg->m_payload; + CLR_RT_HeapBlock *blk = NULL; + CLR_RT_HeapBlock *reference = NULL; + CLR_RT_HeapBlock tmp; + CLR_RT_HeapBlock ref; + CLR_RT_TypeDef_Instance *pTD = NULL; + CLR_RT_TypeDef_Instance td; - if(SUCCEEDED(ref.InitializeArrayReference( tmp, cmd->m_index ))) + tmp.SetObjectReference(cmd->m_heapblock); + + if (SUCCEEDED(ref.InitializeArrayReference(tmp, cmd->m_index))) { - CLR_RT_HeapBlock_Array* array = ref.Array(); + CLR_RT_HeapBlock_Array *array = ref.Array(); - if(array->m_fReference) + if (array->m_fReference) { - blk = (CLR_RT_HeapBlock*)array->GetElement( cmd->m_index ); + blk = (CLR_RT_HeapBlock *)array->GetElement(cmd->m_index); } else { - if(FAILED(tmp.LoadFromReference( ref ))) return false; + if (FAILED(tmp.LoadFromReference(ref))) + return false; - blk = &tmp; reference = (CLR_RT_HeapBlock*)-1; + blk = &tmp; + reference = (CLR_RT_HeapBlock *)-1; } - if(IsBlockEnumMaybe( blk )) + if (IsBlockEnumMaybe(blk)) { - if(td.InitializeFromIndex( array->ReflectionDataConst().m_data.m_type )) + if (td.InitializeFromIndex(array->ReflectionDataConst().m_data.m_type)) { - if(td.m_target->IsEnum()) + if (td.m_target->IsEnum()) { pTD = &td; } @@ -2782,66 +2699,67 @@ bool CLR_DBG_Debugger::Debugging_Value_GetArray( WP_Message* msg) } } - return g_CLR_DBG_Debugger->GetValue( msg, blk, reference, pTD ); + return g_CLR_DBG_Debugger->GetValue(msg, blk, reference, pTD); } -bool CLR_DBG_Debugger::Debugging_Value_GetBlock( WP_Message* msg) +bool CLR_DBG_Debugger::Debugging_Value_GetBlock(WP_Message *msg) { NATIVE_PROFILE_CLR_DEBUGGER(); - - CLR_DBG_Commands::Debugging_Value_GetBlock* cmd = (CLR_DBG_Commands::Debugging_Value_GetBlock*)msg->m_payload; - CLR_RT_HeapBlock* blk = cmd->m_heapblock; - return g_CLR_DBG_Debugger->GetValue( msg, blk, NULL, NULL ); + CLR_DBG_Commands::Debugging_Value_GetBlock *cmd = (CLR_DBG_Commands::Debugging_Value_GetBlock *)msg->m_payload; + CLR_RT_HeapBlock *blk = cmd->m_heapblock; + + return g_CLR_DBG_Debugger->GetValue(msg, blk, NULL, NULL); } -bool CLR_DBG_Debugger::Debugging_Value_GetScratchPad( WP_Message* msg) +bool CLR_DBG_Debugger::Debugging_Value_GetScratchPad(WP_Message *msg) { NATIVE_PROFILE_CLR_DEBUGGER(); - - CLR_DBG_Commands::Debugging_Value_GetScratchPad* cmd = (CLR_DBG_Commands::Debugging_Value_GetScratchPad*)msg->m_payload; - CLR_RT_HeapBlock* blk = GetScratchPad_Helper( cmd->m_idx ); - return g_CLR_DBG_Debugger->GetValue( msg, blk, NULL, NULL ); + CLR_DBG_Commands::Debugging_Value_GetScratchPad *cmd = + (CLR_DBG_Commands::Debugging_Value_GetScratchPad *)msg->m_payload; + CLR_RT_HeapBlock *blk = GetScratchPad_Helper(cmd->m_idx); + + return g_CLR_DBG_Debugger->GetValue(msg, blk, NULL, NULL); } -bool CLR_DBG_Debugger::Debugging_Value_SetBlock( WP_Message* msg) +bool CLR_DBG_Debugger::Debugging_Value_SetBlock(WP_Message *msg) { NATIVE_PROFILE_CLR_DEBUGGER(); - - CLR_DBG_Commands::Debugging_Value_SetBlock* cmd = (CLR_DBG_Commands::Debugging_Value_SetBlock*)msg->m_payload; - CLR_RT_HeapBlock* blk = cmd->m_heapblock; - WP_ReplyToCommand(msg, SetBlockHelper( blk, (CLR_DataType)cmd->m_dt, cmd->m_builtinValue ), false, NULL, 0); + CLR_DBG_Commands::Debugging_Value_SetBlock *cmd = (CLR_DBG_Commands::Debugging_Value_SetBlock *)msg->m_payload; + CLR_RT_HeapBlock *blk = cmd->m_heapblock; + + WP_ReplyToCommand(msg, SetBlockHelper(blk, (CLR_DataType)cmd->m_dt, cmd->m_builtinValue), false, NULL, 0); return true; } -bool CLR_DBG_Debugger::Debugging_Value_SetArray( WP_Message* msg) +bool CLR_DBG_Debugger::Debugging_Value_SetArray(WP_Message *msg) { NATIVE_PROFILE_CLR_DEBUGGER(); - - CLR_DBG_Commands::Debugging_Value_SetArray* cmd = (CLR_DBG_Commands::Debugging_Value_SetArray*)msg->m_payload; - CLR_RT_HeapBlock_Array* array = cmd->m_heapblock; - CLR_RT_HeapBlock tmp; - bool fSuccess = false; - tmp.SetObjectReference( cmd->m_heapblock ); + CLR_DBG_Commands::Debugging_Value_SetArray *cmd = (CLR_DBG_Commands::Debugging_Value_SetArray *)msg->m_payload; + CLR_RT_HeapBlock_Array *array = cmd->m_heapblock; + CLR_RT_HeapBlock tmp; + bool fSuccess = false; + + tmp.SetObjectReference(cmd->m_heapblock); // // We can only set values in arrays of primitive types. // - if(array != NULL && !array->m_fReference) + if (array != NULL && !array->m_fReference) { CLR_RT_HeapBlock ref; - if(SUCCEEDED(ref.InitializeArrayReference( tmp, cmd->m_index ))) + if (SUCCEEDED(ref.InitializeArrayReference(tmp, cmd->m_index))) { - if(SUCCEEDED(tmp.LoadFromReference( ref ))) + if (SUCCEEDED(tmp.LoadFromReference(ref))) { - if(SetBlockHelper( &tmp, tmp.DataType(), cmd->m_builtinValue )) + if (SetBlockHelper(&tmp, tmp.DataType(), cmd->m_builtinValue)) { - if(SUCCEEDED(tmp.StoreToReference( ref, 0 ))) + if (SUCCEEDED(tmp.StoreToReference(ref, 0))) { fSuccess = true; } @@ -2857,120 +2775,124 @@ bool CLR_DBG_Debugger::Debugging_Value_SetArray( WP_Message* msg) //--// -bool CLR_DBG_Debugger::Debugging_Value_AllocateObject( WP_Message* msg) +bool CLR_DBG_Debugger::Debugging_Value_AllocateObject(WP_Message *msg) { NATIVE_PROFILE_CLR_DEBUGGER(); - - CLR_DBG_Commands::Debugging_Value_AllocateObject* cmd = (CLR_DBG_Commands::Debugging_Value_AllocateObject*)msg->m_payload; - CLR_RT_HeapBlock* blk = NULL; - CLR_RT_HeapBlock* ptr = GetScratchPad_Helper( cmd->m_index ); - if(ptr) + CLR_DBG_Commands::Debugging_Value_AllocateObject *cmd = + (CLR_DBG_Commands::Debugging_Value_AllocateObject *)msg->m_payload; + CLR_RT_HeapBlock *blk = NULL; + CLR_RT_HeapBlock *ptr = GetScratchPad_Helper(cmd->m_index); + + if (ptr) { - if(SUCCEEDED(g_CLR_RT_ExecutionEngine.NewObjectFromIndex( *ptr, cmd->m_td ))) + if (SUCCEEDED(g_CLR_RT_ExecutionEngine.NewObjectFromIndex(*ptr, cmd->m_td))) { blk = ptr; } } - return g_CLR_DBG_Debugger->GetValue( msg, blk, NULL, NULL ); + return g_CLR_DBG_Debugger->GetValue(msg, blk, NULL, NULL); } -bool CLR_DBG_Debugger::Debugging_Value_AllocateString( WP_Message* msg) +bool CLR_DBG_Debugger::Debugging_Value_AllocateString(WP_Message *msg) { NATIVE_PROFILE_CLR_DEBUGGER(); - - CLR_DBG_Commands::Debugging_Value_AllocateString* cmd = (CLR_DBG_Commands::Debugging_Value_AllocateString*)msg->m_payload; - CLR_RT_HeapBlock* blk = NULL; - CLR_RT_HeapBlock* ptr = GetScratchPad_Helper( cmd->m_index ); - if(ptr) + CLR_DBG_Commands::Debugging_Value_AllocateString *cmd = + (CLR_DBG_Commands::Debugging_Value_AllocateString *)msg->m_payload; + CLR_RT_HeapBlock *blk = NULL; + CLR_RT_HeapBlock *ptr = GetScratchPad_Helper(cmd->m_index); + + if (ptr) { - CLR_RT_HeapBlock_String* str = CLR_RT_HeapBlock_String::CreateInstance( *ptr, cmd->m_size ); + CLR_RT_HeapBlock_String *str = CLR_RT_HeapBlock_String::CreateInstance(*ptr, cmd->m_size); - if(str) + if (str) { - char* dst = (char*)str->StringText(); + char *dst = (char *)str->StringText(); // // Fill the string with spaces, it will be set at a later stage. // - memset( dst, ' ', cmd->m_size ); dst[ cmd->m_size ] = 0; + memset(dst, ' ', cmd->m_size); + dst[cmd->m_size] = 0; blk = ptr; } } - return g_CLR_DBG_Debugger->GetValue( msg, blk, NULL, NULL ); + return g_CLR_DBG_Debugger->GetValue(msg, blk, NULL, NULL); } -bool CLR_DBG_Debugger::Debugging_Value_AllocateArray( WP_Message* msg) +bool CLR_DBG_Debugger::Debugging_Value_AllocateArray(WP_Message *msg) { NATIVE_PROFILE_CLR_DEBUGGER(); - - CLR_DBG_Commands::Debugging_Value_AllocateArray* cmd = (CLR_DBG_Commands::Debugging_Value_AllocateArray*)msg->m_payload; - CLR_RT_HeapBlock* blk = NULL; - CLR_RT_HeapBlock* ptr = GetScratchPad_Helper( cmd->m_index ); - if(ptr) + CLR_DBG_Commands::Debugging_Value_AllocateArray *cmd = + (CLR_DBG_Commands::Debugging_Value_AllocateArray *)msg->m_payload; + CLR_RT_HeapBlock *blk = NULL; + CLR_RT_HeapBlock *ptr = GetScratchPad_Helper(cmd->m_index); + + if (ptr) { CLR_RT_ReflectionDef_Index reflex; - reflex.m_kind = REFLECTION_TYPE; - reflex.m_levels = cmd->m_depth; + reflex.m_kind = REFLECTION_TYPE; + reflex.m_levels = cmd->m_depth; reflex.m_data.m_type = cmd->m_td; - if(SUCCEEDED(CLR_RT_HeapBlock_Array::CreateInstance( *ptr, cmd->m_numOfElements, reflex ))) + if (SUCCEEDED(CLR_RT_HeapBlock_Array::CreateInstance(*ptr, cmd->m_numOfElements, reflex))) { blk = ptr; } } - return g_CLR_DBG_Debugger->GetValue( msg, blk, NULL, NULL ); + return g_CLR_DBG_Debugger->GetValue(msg, blk, NULL, NULL); } #endif //#if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) #if defined(NANOCLR_PROFILE_NEW) -bool CLR_DBG_Debugger::Profiling_Command( WP_Message* msg) +bool CLR_DBG_Debugger::Profiling_Command(WP_Message *msg) { NATIVE_PROFILE_CLR_DEBUGGER(); - CLR_DBG_Debugger* dbg = g_CLR_DBG_Debugger; - CLR_DBG_Commands::Profiling_Command* cmd = (CLR_DBG_Commands::Profiling_Command*)msg->m_payload; - CLR_UINT8 command = cmd->m_command; + CLR_DBG_Debugger *dbg = g_CLR_DBG_Debugger; + CLR_DBG_Commands::Profiling_Command *cmd = (CLR_DBG_Commands::Profiling_Command *)msg->m_payload; + CLR_UINT8 command = cmd->m_command; - switch(command) + switch (command) { case CLR_DBG_Commands::Profiling_Command::c_Command_ChangeConditions: - return dbg->Profiling_ChangeConditions( msg ); + return dbg->Profiling_ChangeConditions(msg); case CLR_DBG_Commands::Profiling_Command::c_Command_FlushStream: - return dbg->Profiling_FlushStream( msg ); + return dbg->Profiling_FlushStream(msg); default: return false; } } -bool CLR_DBG_Debugger::Profiling_ChangeConditions( WP_Message* msg ) +bool CLR_DBG_Debugger::Profiling_ChangeConditions(WP_Message *msg) { NATIVE_PROFILE_CLR_DEBUGGER(); - CLR_DBG_Commands::Profiling_Command* parent_cmd = (CLR_DBG_Commands::Profiling_Command*)msg->m_payload; - CLR_DBG_Commands::Profiling_ChangeConditions* cmd = (CLR_DBG_Commands::Profiling_ChangeConditions*)&parent_cmd[1]; + CLR_DBG_Commands::Profiling_Command *parent_cmd = (CLR_DBG_Commands::Profiling_Command *)msg->m_payload; + CLR_DBG_Commands::Profiling_ChangeConditions *cmd = (CLR_DBG_Commands::Profiling_ChangeConditions *)&parent_cmd[1]; - g_CLR_RT_ExecutionEngine.m_iProfiling_Conditions |= cmd->m_set; + g_CLR_RT_ExecutionEngine.m_iProfiling_Conditions |= cmd->m_set; g_CLR_RT_ExecutionEngine.m_iProfiling_Conditions &= ~cmd->m_reset; CLR_DBG_Commands::Profiling_Command::Reply cmdReply; cmdReply.m_raw = g_CLR_RT_ExecutionEngine.m_iProfiling_Conditions; - WP_ReplyToCommand( msg, true, false, &cmdReply, sizeof(cmdReply) ); + WP_ReplyToCommand(msg, true, false, &cmdReply, sizeof(cmdReply)); - _ASSERTE(FIMPLIES(CLR_EE_PRF_IS(Allocations), CLR_EE_PRF_IS(Enabled))); - _ASSERTE(FIMPLIES(CLR_EE_PRF_IS(Calls) , CLR_EE_PRF_IS(Enabled))); + _ASSERTE(FIMPLIES(CLR_EE_PRF_IS(Allocations), CLR_EE_PRF_IS(Enabled))); + _ASSERTE(FIMPLIES(CLR_EE_PRF_IS(Calls), CLR_EE_PRF_IS(Enabled))); - if((cmd->m_set & CLR_RT_ExecutionEngine::c_fProfiling_Enabled) != 0) + if ((cmd->m_set & CLR_RT_ExecutionEngine::c_fProfiling_Enabled) != 0) { g_CLR_PRF_Profiler.SendMemoryLayout(); } @@ -2978,7 +2900,7 @@ bool CLR_DBG_Debugger::Profiling_ChangeConditions( WP_Message* msg ) return true; } -bool CLR_DBG_Debugger::Profiling_FlushStream( WP_Message* msg ) +bool CLR_DBG_Debugger::Profiling_FlushStream(WP_Message *msg) { NATIVE_PROFILE_CLR_DEBUGGER(); CLR_DBG_Commands::Profiling_Command::Reply cmdReply; @@ -2987,7 +2909,7 @@ bool CLR_DBG_Debugger::Profiling_FlushStream( WP_Message* msg ) cmdReply.m_raw = 0; - WP_ReplyToCommand( msg, true, false, &cmdReply, sizeof(cmdReply) ); + WP_ReplyToCommand(msg, true, false, &cmdReply, sizeof(cmdReply)); return true; } @@ -3000,58 +2922,60 @@ bool CLR_DBG_Debugger::Profiling_FlushStream( WP_Message* msg ) struct AnalyzeObject { - CLR_RT_HeapBlock* m_ptr; - bool m_fNull; - bool m_fBoxed; - bool m_fCanBeNull; + CLR_RT_HeapBlock *m_ptr; + bool m_fNull; + bool m_fBoxed; + bool m_fCanBeNull; CLR_RT_TypeDescriptor m_desc; - CLR_RT_HeapBlock m_value; + CLR_RT_HeapBlock m_value; }; -static HRESULT AnalyzeObject_Helper( CLR_RT_HeapBlock* ptr, AnalyzeObject& ao ) +static HRESULT AnalyzeObject_Helper(CLR_RT_HeapBlock *ptr, AnalyzeObject &ao) { NATIVE_PROFILE_CLR_DEBUGGER(); NANOCLR_HEADER(); - if(ptr && ptr->DataType() == DATATYPE_BYREF) ptr = ptr->Dereference(); + if (ptr && ptr->DataType() == DATATYPE_BYREF) + ptr = ptr->Dereference(); ao.m_ptr = ptr; - if(ptr == NULL || (ptr->DataType() == DATATYPE_OBJECT && ptr->Dereference() == NULL)) + if (ptr == NULL || (ptr->DataType() == DATATYPE_OBJECT && ptr->Dereference() == NULL)) { - ao.m_fNull = true; - ao.m_fBoxed = false; + ao.m_fNull = true; + ao.m_fBoxed = false; ao.m_fCanBeNull = true; } else { - NANOCLR_CHECK_HRESULT(ao.m_desc.InitializeFromObject( *ptr )); + NANOCLR_CHECK_HRESULT(ao.m_desc.InitializeFromObject(*ptr)); - ao.m_fNull = false; + ao.m_fNull = false; ao.m_fBoxed = (ptr->DataType() == DATATYPE_OBJECT && ptr->Dereference()->IsBoxed()); - switch(ao.m_desc.m_flags & CLR_RT_DataTypeLookup::c_SemanticMask2 & ~CLR_RT_DataTypeLookup::c_SemanticMask) + switch (ao.m_desc.m_flags & CLR_RT_DataTypeLookup::c_SemanticMask2 & ~CLR_RT_DataTypeLookup::c_SemanticMask) { - case CLR_RT_DataTypeLookup::c_Array: - case CLR_RT_DataTypeLookup::c_ArrayList: - ao.m_fCanBeNull = true; - break; - default: + case CLR_RT_DataTypeLookup::c_Array: + case CLR_RT_DataTypeLookup::c_ArrayList: + ao.m_fCanBeNull = true; + break; + default: { - switch(ao.m_desc.m_flags & CLR_RT_DataTypeLookup::c_SemanticMask) + switch (ao.m_desc.m_flags & CLR_RT_DataTypeLookup::c_SemanticMask) { - case CLR_RT_DataTypeLookup::c_Primitive: - case CLR_RT_DataTypeLookup::c_ValueType: - case CLR_RT_DataTypeLookup::c_Enum: - ao.m_fCanBeNull = ao.m_fBoxed || (ao.m_desc.m_handlerCls.m_data == g_CLR_RT_WellKnownTypes.m_String.m_data); - break; + case CLR_RT_DataTypeLookup::c_Primitive: + case CLR_RT_DataTypeLookup::c_ValueType: + case CLR_RT_DataTypeLookup::c_Enum: + ao.m_fCanBeNull = + ao.m_fBoxed || (ao.m_desc.m_handlerCls.m_data == g_CLR_RT_WellKnownTypes.m_String.m_data); + break; - default: - ao.m_fCanBeNull = true; - break; + default: + ao.m_fCanBeNull = true; + break; } - break; + break; } } } @@ -3059,119 +2983,120 @@ static HRESULT AnalyzeObject_Helper( CLR_RT_HeapBlock* ptr, AnalyzeObject& ao ) NANOCLR_NOCLEANUP(); } -static HRESULT Assign_Helper( CLR_RT_HeapBlock* blkDst, CLR_RT_HeapBlock* blkSrc ) +static HRESULT Assign_Helper(CLR_RT_HeapBlock *blkDst, CLR_RT_HeapBlock *blkSrc) { NATIVE_PROFILE_CLR_DEBUGGER(); NANOCLR_HEADER(); - AnalyzeObject aoDst; - AnalyzeObject aoSrc; - CLR_RT_HeapBlock srcVal; srcVal.SetObjectReference( NULL ); - CLR_RT_ProtectFromGC gc( srcVal ); + AnalyzeObject aoDst; + AnalyzeObject aoSrc; + CLR_RT_HeapBlock srcVal; + srcVal.SetObjectReference(NULL); + CLR_RT_ProtectFromGC gc(srcVal); - NANOCLR_CHECK_HRESULT(AnalyzeObject_Helper( blkDst, aoDst )); - NANOCLR_CHECK_HRESULT(AnalyzeObject_Helper( blkSrc, aoSrc )); + NANOCLR_CHECK_HRESULT(AnalyzeObject_Helper(blkDst, aoDst)); + NANOCLR_CHECK_HRESULT(AnalyzeObject_Helper(blkSrc, aoSrc)); - if(aoSrc.m_fNull) + if (aoSrc.m_fNull) { - if(aoDst.m_fCanBeNull == false) + if (aoDst.m_fCanBeNull == false) { NANOCLR_SET_AND_LEAVE(CLR_E_WRONG_TYPE); } - NANOCLR_CHECK_HRESULT(srcVal.StoreToReference( *blkDst, 0 )); + NANOCLR_CHECK_HRESULT(srcVal.StoreToReference(*blkDst, 0)); } else { - NANOCLR_CHECK_HRESULT(srcVal.LoadFromReference( *blkSrc )); + NANOCLR_CHECK_HRESULT(srcVal.LoadFromReference(*blkSrc)); - if(aoDst.m_fNull) + if (aoDst.m_fNull) { - if(aoSrc.m_fCanBeNull == false) + if (aoSrc.m_fCanBeNull == false) { - NANOCLR_CHECK_HRESULT(srcVal.PerformBoxing( aoSrc.m_desc.m_handlerCls )); + NANOCLR_CHECK_HRESULT(srcVal.PerformBoxing(aoSrc.m_desc.m_handlerCls)); } - blkDst->Assign( srcVal ); + blkDst->Assign(srcVal); } else { - if(srcVal.IsAValueType()) + if (srcVal.IsAValueType()) { - if(blkDst->IsAValueType() == false) + if (blkDst->IsAValueType() == false) { - NANOCLR_CHECK_HRESULT(srcVal.PerformBoxing( aoSrc.m_desc.m_handlerCls )); + NANOCLR_CHECK_HRESULT(srcVal.PerformBoxing(aoSrc.m_desc.m_handlerCls)); } } else { - if(blkDst->IsAValueType() == true) + if (blkDst->IsAValueType() == true) { - NANOCLR_CHECK_HRESULT(srcVal.PerformUnboxing( aoSrc.m_desc.m_handlerCls )); + NANOCLR_CHECK_HRESULT(srcVal.PerformUnboxing(aoSrc.m_desc.m_handlerCls)); } } - NANOCLR_CHECK_HRESULT(blkDst->Reassign( srcVal )); + NANOCLR_CHECK_HRESULT(blkDst->Reassign(srcVal)); } } NANOCLR_NOCLEANUP(); } - -bool CLR_DBG_Debugger::Debugging_Value_Assign( WP_Message* msg) +bool CLR_DBG_Debugger::Debugging_Value_Assign(WP_Message *msg) { NATIVE_PROFILE_CLR_DEBUGGER(); - - CLR_DBG_Commands::Debugging_Value_Assign* cmd = (CLR_DBG_Commands::Debugging_Value_Assign*)msg->m_payload; - CLR_RT_HeapBlock* blkDst = cmd->m_heapblockDst; - CLR_RT_HeapBlock* blkSrc = cmd->m_heapblockSrc; - if(blkDst && FAILED(Assign_Helper( blkDst, blkSrc ))) + CLR_DBG_Commands::Debugging_Value_Assign *cmd = (CLR_DBG_Commands::Debugging_Value_Assign *)msg->m_payload; + CLR_RT_HeapBlock *blkDst = cmd->m_heapblockDst; + CLR_RT_HeapBlock *blkSrc = cmd->m_heapblockSrc; + + if (blkDst && FAILED(Assign_Helper(blkDst, blkSrc))) { blkDst = NULL; } - return g_CLR_DBG_Debugger->GetValue( msg, blkDst, NULL, NULL ); + return g_CLR_DBG_Debugger->GetValue(msg, blkDst, NULL, NULL); } //--// -bool CLR_DBG_Debugger::Debugging_TypeSys_Assemblies( WP_Message* msg) +bool CLR_DBG_Debugger::Debugging_TypeSys_Assemblies(WP_Message *msg) { NATIVE_PROFILE_CLR_DEBUGGER(); - - CLR_RT_Assembly_Index assemblies[ CLR_RT_TypeSystem::c_MaxAssemblies ]; - int num = 0; + + CLR_RT_Assembly_Index assemblies[CLR_RT_TypeSystem::c_MaxAssemblies]; + int num = 0; NANOCLR_FOREACH_ASSEMBLY(g_CLR_RT_TypeSystem) { - assemblies[ num++ ].Set( pASSM->m_idx ); + assemblies[num++].Set(pASSM->m_idx); } NANOCLR_FOREACH_ASSEMBLY_END(); - WP_ReplyToCommand( msg, true, false, assemblies, sizeof(CLR_RT_Assembly_Index) * num ); + WP_ReplyToCommand(msg, true, false, assemblies, sizeof(CLR_RT_Assembly_Index) * num); return true; } -bool CLR_DBG_Debugger::Debugging_TypeSys_AppDomains( WP_Message* msg) +bool CLR_DBG_Debugger::Debugging_TypeSys_AppDomains(WP_Message *msg) { NATIVE_PROFILE_CLR_DEBUGGER(); #if defined(NANOCLR_APPDOMAINS) - - int num = 0; - CLR_UINT32 appDomainIDs[ 256 ]; + + int num = 0; + CLR_UINT32 appDomainIDs[256]; NANOCLR_FOREACH_NODE(CLR_RT_AppDomain, appDomain, g_CLR_RT_ExecutionEngine.m_appDomains) { - appDomainIDs[ num++ ] = appDomain->m_id; + appDomainIDs[num++] = appDomain->m_id; - if(num >= ARRAYSIZE(appDomainIDs)) break; + if (num >= ARRAYSIZE(appDomainIDs)) + break; } NANOCLR_FOREACH_NODE_END(); - WP_ReplyToCommand( msg, true, false, appDomainIDs, sizeof(CLR_UINT32) * num ); + WP_ReplyToCommand(msg, true, false, appDomainIDs, sizeof(CLR_UINT32) * num); return true; #else @@ -3182,42 +3107,50 @@ bool CLR_DBG_Debugger::Debugging_TypeSys_AppDomains( WP_Message* msg) //--// -bool CLR_DBG_Debugger::Debugging_Resolve_AppDomain( WP_Message* msg) +bool CLR_DBG_Debugger::Debugging_Resolve_AppDomain(WP_Message *msg) { NATIVE_PROFILE_CLR_DEBUGGER(); #if defined(NANOCLR_APPDOMAINS) - - CLR_DBG_Commands::Debugging_Resolve_AppDomain* cmd = (CLR_DBG_Commands::Debugging_Resolve_AppDomain*)msg->m_payload; - CLR_RT_AppDomain* appDomain = g_CLR_DBG_Debugger->GetAppDomainFromID( cmd->m_id ); - CLR_UINT32 numAssemblies = 0; - CLR_DBG_Commands::Debugging_Resolve_AppDomain::Reply* cmdReply; - CLR_UINT8 buf[ sizeof(CLR_DBG_Commands::Debugging_Resolve_AppDomain::Reply) + sizeof(CLR_RT_Assembly_Index)*CLR_RT_TypeSystem::c_MaxAssemblies ]; - size_t count; - const char* name; - CLR_RT_Assembly_Index* pAssemblyIndex; - if(appDomain) + CLR_DBG_Commands::Debugging_Resolve_AppDomain *cmd = + (CLR_DBG_Commands::Debugging_Resolve_AppDomain *)msg->m_payload; + CLR_RT_AppDomain *appDomain = g_CLR_DBG_Debugger->GetAppDomainFromID(cmd->m_id); + CLR_UINT32 numAssemblies = 0; + CLR_DBG_Commands::Debugging_Resolve_AppDomain::Reply *cmdReply; + CLR_UINT8 + buf[sizeof(CLR_DBG_Commands::Debugging_Resolve_AppDomain::Reply) + + sizeof(CLR_RT_Assembly_Index) * CLR_RT_TypeSystem::c_MaxAssemblies]; + size_t count; + const char *name; + CLR_RT_Assembly_Index *pAssemblyIndex; + + if (appDomain) { - cmdReply = (CLR_DBG_Commands::Debugging_Resolve_AppDomain::Reply*)&buf; + cmdReply = (CLR_DBG_Commands::Debugging_Resolve_AppDomain::Reply *)&buf; cmdReply->m_state = appDomain->m_state; - name = appDomain->m_strName->StringText(); - count = __min( hal_strlen_s( name ) + 1, sizeof(cmdReply->m_szName) - 1 ); + name = appDomain->m_strName->StringText(); + count = __min(hal_strlen_s(name) + 1, sizeof(cmdReply->m_szName) - 1); - hal_strncpy_s( cmdReply->m_szName, ARRAYSIZE(cmdReply->m_szName), name, count ); + hal_strncpy_s(cmdReply->m_szName, ARRAYSIZE(cmdReply->m_szName), name, count); - pAssemblyIndex = (CLR_RT_Assembly_Index*)(&cmdReply->m_assemblies); + pAssemblyIndex = (CLR_RT_Assembly_Index *)(&cmdReply->m_assemblies); NANOCLR_FOREACH_ASSEMBLY_IN_APPDOMAIN(appDomain) { - pAssemblyIndex->Set( pASSM->m_idx ); + pAssemblyIndex->Set(pASSM->m_idx); pAssemblyIndex++; numAssemblies++; } NANOCLR_FOREACH_ASSEMBLY_IN_APPDOMAIN_END(); - WP_ReplyToCommand( msg, true, false, cmdReply, sizeof(*cmdReply) + sizeof(CLR_RT_Assembly_Index) * (numAssemblies - 1) ); + WP_ReplyToCommand( + msg, + true, + false, + cmdReply, + sizeof(*cmdReply) + sizeof(CLR_RT_Assembly_Index) * (numAssemblies - 1)); } else { @@ -3231,32 +3164,41 @@ bool CLR_DBG_Debugger::Debugging_Resolve_AppDomain( WP_Message* msg) #endif } -bool CLR_DBG_Debugger::Debugging_Resolve_Assembly( WP_Message* msg) +bool CLR_DBG_Debugger::Debugging_Resolve_Assembly(WP_Message *msg) { NATIVE_PROFILE_CLR_DEBUGGER(); - - CLR_DBG_Commands::Debugging_Resolve_Assembly* cmd = (CLR_DBG_Commands::Debugging_Resolve_Assembly*)msg->m_payload; + + CLR_DBG_Commands::Debugging_Resolve_Assembly *cmd = (CLR_DBG_Commands::Debugging_Resolve_Assembly *)msg->m_payload; CLR_DBG_Commands::Debugging_Resolve_Assembly::Reply cmdReply; - CLR_RT_Assembly* assm = g_CLR_DBG_Debugger->IsGoodAssembly( cmd->m_idx.Assembly() ); + CLR_RT_Assembly *assm = g_CLR_DBG_Debugger->IsGoodAssembly(cmd->m_idx.Assembly()); - if(assm) + if (assm) { #if defined(_WIN32) - //append path - if(assm->m_strPath != NULL) + // append path + if (assm->m_strPath != NULL) { - sprintf_s( cmdReply.m_szName, ARRAYSIZE(cmdReply.m_szName), "%s,%s", assm->m_szName, assm->m_strPath->c_str() ); + sprintf_s( + cmdReply.m_szName, + ARRAYSIZE(cmdReply.m_szName), + "%s,%s", + assm->m_szName, + assm->m_strPath->c_str()); } else #endif { - hal_strncpy_s( cmdReply.m_szName, ARRAYSIZE(cmdReply.m_szName), assm->m_szName, MAXSTRLEN(cmdReply.m_szName) ); + hal_strncpy_s( + cmdReply.m_szName, + ARRAYSIZE(cmdReply.m_szName), + assm->m_szName, + MAXSTRLEN(cmdReply.m_szName)); } - cmdReply.m_flags = assm->m_flags; + cmdReply.m_flags = assm->m_flags; cmdReply.m_version = assm->m_header->version; - WP_ReplyToCommand( msg, true, false, &cmdReply, sizeof(cmdReply) ); + WP_ReplyToCommand(msg, true, false, &cmdReply, sizeof(cmdReply)); return true; } @@ -3266,22 +3208,22 @@ bool CLR_DBG_Debugger::Debugging_Resolve_Assembly( WP_Message* msg) return true; } -bool CLR_DBG_Debugger::Debugging_Resolve_Type( WP_Message* msg) +bool CLR_DBG_Debugger::Debugging_Resolve_Type(WP_Message *msg) { NATIVE_PROFILE_CLR_DEBUGGER(); - - CLR_DBG_Commands::Debugging_Resolve_Type* cmd = (CLR_DBG_Commands::Debugging_Resolve_Type*)msg->m_payload; + + CLR_DBG_Commands::Debugging_Resolve_Type *cmd = (CLR_DBG_Commands::Debugging_Resolve_Type *)msg->m_payload; CLR_DBG_Commands::Debugging_Resolve_Type::Reply cmdReply; - CLR_RT_TypeDef_Instance inst; + CLR_RT_TypeDef_Instance inst; - if(g_CLR_DBG_Debugger->CheckTypeDef( cmd->m_td, inst )) + if (g_CLR_DBG_Debugger->CheckTypeDef(cmd->m_td, inst)) { - char* szBuffer = cmdReply.m_type; - size_t iBuffer = MAXSTRLEN(cmdReply.m_type); + char *szBuffer = cmdReply.m_type; + size_t iBuffer = MAXSTRLEN(cmdReply.m_type); - if(SUCCEEDED(g_CLR_RT_TypeSystem.BuildTypeName( inst, szBuffer, iBuffer ))) + if (SUCCEEDED(g_CLR_RT_TypeSystem.BuildTypeName(inst, szBuffer, iBuffer))) { - WP_ReplyToCommand( msg, true, false, &cmdReply, sizeof(cmdReply) ); + WP_ReplyToCommand(msg, true, false, &cmdReply, sizeof(cmdReply)); return true; } @@ -3292,27 +3234,28 @@ bool CLR_DBG_Debugger::Debugging_Resolve_Type( WP_Message* msg) return true; } -bool CLR_DBG_Debugger::Debugging_Resolve_Field( WP_Message* msg) +bool CLR_DBG_Debugger::Debugging_Resolve_Field(WP_Message *msg) { NATIVE_PROFILE_CLR_DEBUGGER(); - - CLR_DBG_Commands::Debugging_Resolve_Field* cmd = (CLR_DBG_Commands::Debugging_Resolve_Field*)msg->m_payload; + + CLR_DBG_Commands::Debugging_Resolve_Field *cmd = (CLR_DBG_Commands::Debugging_Resolve_Field *)msg->m_payload; CLR_DBG_Commands::Debugging_Resolve_Field::Reply cmdReply; - CLR_RT_FieldDef_Instance inst; + CLR_RT_FieldDef_Instance inst; - if(g_CLR_DBG_Debugger->CheckFieldDef( cmd->m_fd, inst )) + if (g_CLR_DBG_Debugger->CheckFieldDef(cmd->m_fd, inst)) { - char* szBuffer = cmdReply.m_name; - size_t iBuffer = MAXSTRLEN(cmdReply.m_name); + char *szBuffer = cmdReply.m_name; + size_t iBuffer = MAXSTRLEN(cmdReply.m_name); - if(SUCCEEDED(g_CLR_RT_TypeSystem.BuildFieldName( inst, szBuffer, iBuffer ))) + if (SUCCEEDED(g_CLR_RT_TypeSystem.BuildFieldName(inst, szBuffer, iBuffer))) { - CLR_RT_TypeDef_Instance instClass; instClass.InitializeFromField( inst ); + CLR_RT_TypeDef_Instance instClass; + instClass.InitializeFromField(inst); - cmdReply.m_td = instClass; + cmdReply.m_td = instClass; cmdReply.m_index = inst.CrossReference().m_offset; - WP_ReplyToCommand( msg, true, false, &cmdReply, sizeof(cmdReply) ); + WP_ReplyToCommand(msg, true, false, &cmdReply, sizeof(cmdReply)); return true; } @@ -3323,25 +3266,25 @@ bool CLR_DBG_Debugger::Debugging_Resolve_Field( WP_Message* msg) return true; } -bool CLR_DBG_Debugger::Debugging_Resolve_Method( WP_Message* msg) +bool CLR_DBG_Debugger::Debugging_Resolve_Method(WP_Message *msg) { NATIVE_PROFILE_CLR_DEBUGGER(); - - CLR_DBG_Commands::Debugging_Resolve_Method* cmd = (CLR_DBG_Commands::Debugging_Resolve_Method*)msg->m_payload; + + CLR_DBG_Commands::Debugging_Resolve_Method *cmd = (CLR_DBG_Commands::Debugging_Resolve_Method *)msg->m_payload; CLR_DBG_Commands::Debugging_Resolve_Method::Reply cmdReply; - CLR_RT_MethodDef_Instance inst; - CLR_RT_TypeDef_Instance instOwner; + CLR_RT_MethodDef_Instance inst; + CLR_RT_TypeDef_Instance instOwner; - if(g_CLR_DBG_Debugger->CheckMethodDef( cmd->m_md, inst ) && instOwner.InitializeFromMethod( inst )) + if (g_CLR_DBG_Debugger->CheckMethodDef(cmd->m_md, inst) && instOwner.InitializeFromMethod(inst)) { - char* szBuffer = cmdReply.m_method; - size_t iBuffer = MAXSTRLEN(cmdReply.m_method); + char *szBuffer = cmdReply.m_method; + size_t iBuffer = MAXSTRLEN(cmdReply.m_method); cmdReply.m_td = instOwner; - CLR_SafeSprintf( szBuffer, iBuffer, "%s", inst.m_assm->GetString( inst.m_target->name ) ); + CLR_SafeSprintf(szBuffer, iBuffer, "%s", inst.m_assm->GetString(inst.m_target->name)); - WP_ReplyToCommand( msg, true, false, &cmdReply, sizeof(cmdReply) ); + WP_ReplyToCommand(msg, true, false, &cmdReply, sizeof(cmdReply)); return true; } @@ -3351,163 +3294,170 @@ bool CLR_DBG_Debugger::Debugging_Resolve_Method( WP_Message* msg) return true; } -bool CLR_DBG_Debugger::Debugging_Resolve_VirtualMethod( WP_Message* msg) +bool CLR_DBG_Debugger::Debugging_Resolve_VirtualMethod(WP_Message *msg) { NATIVE_PROFILE_CLR_DEBUGGER(); - - CLR_DBG_Commands::Debugging_Resolve_VirtualMethod* cmd = (CLR_DBG_Commands::Debugging_Resolve_VirtualMethod*)msg->m_payload; + + CLR_DBG_Commands::Debugging_Resolve_VirtualMethod *cmd = + (CLR_DBG_Commands::Debugging_Resolve_VirtualMethod *)msg->m_payload; CLR_DBG_Commands::Debugging_Resolve_VirtualMethod::Reply cmdReply; - CLR_RT_TypeDef_Index cls; - CLR_RT_MethodDef_Index md; + CLR_RT_TypeDef_Index cls; + CLR_RT_MethodDef_Index md; cmdReply.m_md.Clear(); - if(SUCCEEDED(CLR_RT_TypeDescriptor::ExtractTypeIndexFromObject( *cmd->m_obj, cls ))) + if (SUCCEEDED(CLR_RT_TypeDescriptor::ExtractTypeIndexFromObject(*cmd->m_obj, cls))) { - if(g_CLR_RT_EventCache.FindVirtualMethod( cls, cmd->m_md, md )) + if (g_CLR_RT_EventCache.FindVirtualMethod(cls, cmd->m_md, md)) { cmdReply.m_md = md; } } - WP_ReplyToCommand( msg, true, false, &cmdReply, sizeof(cmdReply) ); + WP_ReplyToCommand(msg, true, false, &cmdReply, sizeof(cmdReply)); return true; } - #endif //#if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) //--// - -bool CLR_DBG_Debugger::Debugging_Deployment_Status( WP_Message* msg) +bool CLR_DBG_Debugger::Debugging_Deployment_Status(WP_Message *msg) { NATIVE_PROFILE_CLR_DEBUGGER(); - CLR_DBG_Commands::Debugging_Deployment_Status::Reply* cmdReply; - CLR_UINT32 totLength; - CLR_UINT32 deploySectorsNum = 0; - CLR_UINT32 deploySectorStart = 0; - CLR_UINT32 deployLength = 0; + CLR_DBG_Commands::Debugging_Deployment_Status::Reply *cmdReply; + CLR_UINT32 totLength; + CLR_UINT32 deploySectorsNum = 0; + CLR_UINT32 deploySectorStart = 0; + CLR_UINT32 deployLength = 0; // find the first device in list with DEPLOYMENT blocks if (m_deploymentStorageDevice != NULL) { BlockStorageStream stream; - if(BlockStorageStream_InitializeWithBlockStorageDevice(&stream, BlockUsage_DEPLOYMENT, m_deploymentStorageDevice )) + if (BlockStorageStream_InitializeWithBlockStorageDevice( + &stream, + BlockUsage_DEPLOYMENT, + m_deploymentStorageDevice)) { do { - if(deploySectorsNum == 0) + if (deploySectorsNum == 0) { deploySectorStart = BlockStorageStream_CurrentAddress(&stream); } - deployLength += stream.Length; - deploySectorsNum ++; - } - while(BlockStorageStream_NextStream(&stream) && stream.BaseAddress == (deploySectorStart + deployLength)); + deployLength += stream.Length; + deploySectorsNum++; + } while (BlockStorageStream_NextStream(&stream) && + stream.BaseAddress == (deploySectorStart + deployLength)); } totLength = sizeof(CLR_DBG_Commands::Debugging_Deployment_Status::Reply); - cmdReply = (CLR_DBG_Commands::Debugging_Deployment_Status::Reply*)CLR_RT_Memory::Allocate( totLength, true ); + cmdReply = (CLR_DBG_Commands::Debugging_Deployment_Status::Reply *)CLR_RT_Memory::Allocate(totLength, true); - if(!cmdReply) return false; + if (!cmdReply) + return false; - CLR_RT_Memory::ZeroFill( cmdReply, totLength ); + CLR_RT_Memory::ZeroFill(cmdReply, totLength); - cmdReply->EntryPoint = g_CLR_RT_TypeSystem.m_entryPoint.m_data; - cmdReply->StorageStart = deploySectorStart; - cmdReply->StorageLength = deployLength; + cmdReply->EntryPoint = g_CLR_RT_TypeSystem.m_entryPoint.m_data; + cmdReply->StorageStart = deploySectorStart; + cmdReply->StorageLength = deployLength; - WP_ReplyToCommand( msg, true, false, cmdReply, totLength ); + WP_ReplyToCommand(msg, true, false, cmdReply, totLength); - CLR_RT_Memory::Release( cmdReply ); + CLR_RT_Memory::Release(cmdReply); return true; } else { - WP_ReplyToCommand( msg, false, false, NULL, 0 ); + WP_ReplyToCommand(msg, false, false, NULL, 0); return false; } } #if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) -bool CLR_DBG_Debugger::Debugging_Info_SetJMC_Method( const CLR_RT_MethodDef_Index& idx, bool fJMC ) +bool CLR_DBG_Debugger::Debugging_Info_SetJMC_Method(const CLR_RT_MethodDef_Index &idx, bool fJMC) { NATIVE_PROFILE_CLR_DEBUGGER(); CLR_RT_MethodDef_Instance inst; - if(!CheckMethodDef( idx, inst ) ) return false; - if(inst.m_target->RVA == CLR_EmptyIndex) return false; + if (!CheckMethodDef(idx, inst)) + return false; + if (inst.m_target->RVA == CLR_EmptyIndex) + return false; - inst.DebuggingInfo().SetJMC( fJMC ); + inst.DebuggingInfo().SetJMC(fJMC); return true; } -bool CLR_DBG_Debugger::Debugging_Info_SetJMC_Type( const CLR_RT_TypeDef_Index& idx, bool fJMC ) +bool CLR_DBG_Debugger::Debugging_Info_SetJMC_Type(const CLR_RT_TypeDef_Index &idx, bool fJMC) { NATIVE_PROFILE_CLR_DEBUGGER(); - const CLR_RECORD_TYPEDEF* td; - CLR_RT_TypeDef_Instance inst; - int totMethods; - CLR_RT_MethodDef_Index md; + const CLR_RECORD_TYPEDEF *td; + CLR_RT_TypeDef_Instance inst; + int totMethods; + CLR_RT_MethodDef_Index md; - if(!CheckTypeDef( idx, inst )) return false; + if (!CheckTypeDef(idx, inst)) + return false; - td = inst.m_target; + td = inst.m_target; totMethods = td->vMethods_Num + td->iMethods_Num + td->sMethods_Num; - for(int i=0; imethods_First + i ); + md.Set(idx.Assembly(), td->methods_First + i); - Debugging_Info_SetJMC_Method( md, fJMC ); + Debugging_Info_SetJMC_Method(md, fJMC); } return true; } -bool CLR_DBG_Debugger::Debugging_Info_SetJMC( WP_Message* msg) +bool CLR_DBG_Debugger::Debugging_Info_SetJMC(WP_Message *msg) { NATIVE_PROFILE_CLR_DEBUGGER(); - - CLR_DBG_Commands::Debugging_Info_SetJMC* cmd = (CLR_DBG_Commands::Debugging_Info_SetJMC*)msg->m_payload; - bool fJMC = (cmd->m_fIsJMC != 0); - switch(cmd->m_kind) + CLR_DBG_Commands::Debugging_Info_SetJMC *cmd = (CLR_DBG_Commands::Debugging_Info_SetJMC *)msg->m_payload; + bool fJMC = (cmd->m_fIsJMC != 0); + + switch (cmd->m_kind) { - case REFLECTION_ASSEMBLY: + case REFLECTION_ASSEMBLY: { - CLR_RT_Assembly* assm = g_CLR_DBG_Debugger->IsGoodAssembly( cmd->m_data.m_assm.Assembly() ); + CLR_RT_Assembly *assm = g_CLR_DBG_Debugger->IsGoodAssembly(cmd->m_data.m_assm.Assembly()); - if(!assm) return false; + if (!assm) + return false; - for(int i=0; im_pTablesSize[ TBL_TypeDef ]; i++) + for (int i = 0; i < assm->m_pTablesSize[TBL_TypeDef]; i++) { CLR_RT_TypeDef_Index idx; - idx.Set( cmd->m_data.m_assm.Assembly(), i ); + idx.Set(cmd->m_data.m_assm.Assembly(), i); - g_CLR_DBG_Debugger->Debugging_Info_SetJMC_Type( idx, fJMC ); + g_CLR_DBG_Debugger->Debugging_Info_SetJMC_Type(idx, fJMC); } return true; } - case REFLECTION_TYPE: - return g_CLR_DBG_Debugger->Debugging_Info_SetJMC_Type( cmd->m_data.m_type, fJMC ); + case REFLECTION_TYPE: + return g_CLR_DBG_Debugger->Debugging_Info_SetJMC_Type(cmd->m_data.m_type, fJMC); - case REFLECTION_METHOD: - return g_CLR_DBG_Debugger->Debugging_Info_SetJMC_Method( cmd->m_data.m_method, fJMC ); + case REFLECTION_METHOD: + return g_CLR_DBG_Debugger->Debugging_Info_SetJMC_Method(cmd->m_data.m_method, fJMC); - default: - return false; + default: + return false; } } diff --git a/src/CLR/Debugger/Debugger.h b/src/CLR/Debugger/Debugger.h index 2460a7456b..ddb57bac01 100644 --- a/src/CLR/Debugger/Debugger.h +++ b/src/CLR/Debugger/Debugger.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Debugger/Debugger_full.cpp b/src/CLR/Debugger/Debugger_full.cpp index 77775f0330..42e3a3b2a1 100644 --- a/src/CLR/Debugger/Debugger_full.cpp +++ b/src/CLR/Debugger/Debugger_full.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Debugger/Debugger_minimal.cpp b/src/CLR/Debugger/Debugger_minimal.cpp index c63267cc57..bf8e95d6a5 100644 --- a/src/CLR/Debugger/Debugger_minimal.cpp +++ b/src/CLR/Debugger/Debugger_minimal.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Debugger/Debugger_stub.cpp b/src/CLR/Debugger/Debugger_stub.cpp index a292ec81d6..79b765d7f5 100644 --- a/src/CLR/Debugger/Debugger_stub.cpp +++ b/src/CLR/Debugger/Debugger_stub.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Diagnostics/Diagnostics.h b/src/CLR/Diagnostics/Diagnostics.h index aabf7238d7..01b5147d5c 100644 --- a/src/CLR/Diagnostics/Diagnostics.h +++ b/src/CLR/Diagnostics/Diagnostics.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Diagnostics/Diagnostics_stub.cpp b/src/CLR/Diagnostics/Diagnostics_stub.cpp index cfb883d5fb..fc57db7773 100644 --- a/src/CLR/Diagnostics/Diagnostics_stub.cpp +++ b/src/CLR/Diagnostics/Diagnostics_stub.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Diagnostics/Info.cpp b/src/CLR/Diagnostics/Info.cpp index ff8cbdf276..29b1fb3dba 100644 --- a/src/CLR/Diagnostics/Info.cpp +++ b/src/CLR/Diagnostics/Info.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Diagnostics/Profile.cpp b/src/CLR/Diagnostics/Profile.cpp index 0d63a9de64..3d2f0c4636 100644 --- a/src/CLR/Diagnostics/Profile.cpp +++ b/src/CLR/Diagnostics/Profile.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Diagnostics/Profiler.cpp b/src/CLR/Diagnostics/Profiler.cpp index d29473c1bb..fbaaec1e1d 100644 --- a/src/CLR/Diagnostics/Profiler.cpp +++ b/src/CLR/Diagnostics/Profiler.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Helpers/Base64/base64.c b/src/CLR/Helpers/Base64/base64.c index 7c07298a4f..95421900e6 100644 --- a/src/CLR/Helpers/Base64/base64.c +++ b/src/CLR/Helpers/Base64/base64.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) https://www.mycplus.com. All Rights Reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Helpers/Base64/base64.h b/src/CLR/Helpers/Base64/base64.h index 03ab6e61b2..09cf8f3ecf 100644 --- a/src/CLR/Helpers/Base64/base64.h +++ b/src/CLR/Helpers/Base64/base64.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) ARM Limited. All Rights Reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Helpers/TinyPrintf/printf.c b/src/CLR/Helpers/TinyPrintf/printf.c index ab902bfc34..c4baf8aeb1 100644 --- a/src/CLR/Helpers/TinyPrintf/printf.c +++ b/src/CLR/Helpers/TinyPrintf/printf.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2001, 2002 Georges Menie. All rights reserved. // Portions Copyright (c) 2009-2013 Daniel D Miller. All rights reserved. // See LICENSE file in the project root for full license information. diff --git a/src/CLR/Helpers/TinyPrintf/printf.h b/src/CLR/Helpers/TinyPrintf/printf.h index 4ff4c07697..5098024e9d 100644 --- a/src/CLR/Helpers/TinyPrintf/printf.h +++ b/src/CLR/Helpers/TinyPrintf/printf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2001, 2002 Georges Menie. All rights reserved. // Portions Copyright (c) 2009-2013 Daniel D Miller. All rights reserved. // See LICENSE file in the project root for full license information. diff --git a/src/CLR/Include/WireProtocol.h b/src/CLR/Include/WireProtocol.h index 2ccc63fe8d..ad475588dc 100644 --- a/src/CLR/Include/WireProtocol.h +++ b/src/CLR/Include/WireProtocol.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Include/WireProtocol_App_Interface.h b/src/CLR/Include/WireProtocol_App_Interface.h index fa3c133526..f413d93bb7 100644 --- a/src/CLR/Include/WireProtocol_App_Interface.h +++ b/src/CLR/Include/WireProtocol_App_Interface.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Include/WireProtocol_HAL_Interface.h b/src/CLR/Include/WireProtocol_HAL_Interface.h index 9bcbb463a5..3ac204f4cc 100644 --- a/src/CLR/Include/WireProtocol_HAL_Interface.h +++ b/src/CLR/Include/WireProtocol_HAL_Interface.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Include/WireProtocol_Message.h b/src/CLR/Include/WireProtocol_Message.h index 703058b356..a45824416c 100644 --- a/src/CLR/Include/WireProtocol_Message.h +++ b/src/CLR/Include/WireProtocol_Message.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Include/WireProtocol_MonitorCommands.h b/src/CLR/Include/WireProtocol_MonitorCommands.h index b593cbf636..fced503ad5 100644 --- a/src/CLR/Include/WireProtocol_MonitorCommands.h +++ b/src/CLR/Include/WireProtocol_MonitorCommands.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // @@ -18,39 +18,37 @@ // backwards compatible with .NETMF typedef enum Monitor_Reboot_Options { - Monitor_Reboot_c_NormalReboot = 0, + Monitor_Reboot_c_NormalReboot = 0, Monitor_Reboot_c_EnterBootloader = 1, - Monitor_Reboot_c_ClrRebootOnly = 2, + Monitor_Reboot_c_ClrRebootOnly = 2, Monitor_Reboot_c_ClrStopDebugger = 4 -}Monitor_Reboot_Options; +} Monitor_Reboot_Options; // structure for Access Memory operations typedef enum AccessMemory_Operations { // check if memory space is erased - AccessMemory_Check = 0x00, + AccessMemory_Check = 0x00, // read block of data starting at a given address - AccessMemory_Read = 0x01, - - // write block of data starting at a given address - AccessMemory_Write = 0x02, + AccessMemory_Read = 0x01, - // erase sector/block/page at a given address - AccessMemory_Erase = 0x03, + // write block of data starting at a given address + AccessMemory_Write = 0x02, + // erase sector/block/page at a given address + AccessMemory_Erase = 0x03, - AccessMemory_Mask = 0x0F + AccessMemory_Mask = 0x0F -}AccessMemory_Operations; +} AccessMemory_Operations; typedef enum MemoryMap_Options { - Monitor_MemoryMap_c_RAM = 0x00000001, - Monitor_MemoryMap_c_FLASH = 0x00000002, - -}MemoryMap_Options; + Monitor_MemoryMap_c_RAM = 0x00000001, + Monitor_MemoryMap_c_FLASH = 0x00000002, +} MemoryMap_Options; ////////////////////////////////////////// // typedefs @@ -62,7 +60,7 @@ typedef struct Monitor_Ping_Reply uint32_t m_source; uint32_t m_dbg_flags; -}Monitor_Ping_Reply; +} Monitor_Ping_Reply; // structure for command Monitor Ping // backwards compatible with .NETMF @@ -71,69 +69,56 @@ typedef struct Monitor_Ping_Command uint32_t m_source; uint32_t m_dbg_flags; -}Monitor_Ping_Command; - +} Monitor_Ping_Command; // structure with reply for OEM information command typedef struct Monitor_OemInfo_Reply { - ReleaseInfo m_releaseInfo; + ReleaseInfo m_releaseInfo; -}Monitor_OemInfo_Reply; +} Monitor_OemInfo_Reply; typedef struct CLR_DBG_Commands_Monitor_ReadMemory { - uint32_t address; - uint32_t length; - unsigned char data[1]; + uint32_t address; + uint32_t length; + unsigned char data[1]; -}CLR_DBG_Commands_Monitor_ReadMemory; +} CLR_DBG_Commands_Monitor_ReadMemory; typedef struct CLR_DBG_Commands_Monitor_WriteMemory { - uint32_t address; - uint32_t length; - unsigned char data[1]; + uint32_t address; + uint32_t length; + unsigned char data[1]; -}CLR_DBG_Commands_Monitor_WriteMemory; +} CLR_DBG_Commands_Monitor_WriteMemory; typedef struct Monitor_Reboot_Command { uint32_t m_flags; -}Monitor_Reboot_Command; +} Monitor_Reboot_Command; typedef struct CLR_DBG_Commands_Monitor_EraseMemory { uint32_t address; uint32_t length; -}CLR_DBG_Commands_Monitor_EraseMemory; +} CLR_DBG_Commands_Monitor_EraseMemory; typedef struct CLR_DBG_Commands_Monitor_CheckMemory { uint32_t address; uint32_t length; -}CLR_DBG_Commands_Monitor_CheckMemory; +} CLR_DBG_Commands_Monitor_CheckMemory; -typedef struct CLR_DBG_Commands_Monitor_CheckMemory_Reply -{ - uint32_t crc; - -}CLR_DBG_Commands_Monitor_CheckMemory_Reply; +typedef uint32_t CLR_DBG_Commands_Monitor_CheckMemory_Reply; -typedef struct CLR_DBG_Commands_Monitor_EraseMemory_Reply -{ - uint32_t ErrorCode; - -}CLR_DBG_Commands_Monitor_EraseMemory_Reply; - -typedef struct CLR_DBG_Commands_Monitor_WriteMemory_Reply -{ - uint32_t ErrorCode; +typedef uint32_t CLR_DBG_Commands_Monitor_EraseMemory_Reply; -}CLR_DBG_Commands_Monitor_WriteMemory_Reply; +typedef uint32_t CLR_DBG_Commands_Monitor_WriteMemory_Reply; typedef struct MemoryMap_Range { @@ -141,21 +126,20 @@ typedef struct MemoryMap_Range uint32_t m_length; uint32_t m_flags; -}MemoryMap_Range; - +} MemoryMap_Range; typedef struct CLR_DBG_Commands_Monitor_MemoryMap { MemoryMap_Range m_map[1]; -}CLR_DBG_Commands_Monitor_MemoryMap; +} CLR_DBG_Commands_Monitor_MemoryMap; typedef struct Monitor_QueryConfiguration_Command { uint32_t Configuration; uint32_t BlockIndex; -}Monitor_QueryConfiguration_Command; +} Monitor_QueryConfiguration_Command; typedef struct __nfpack Monitor_UpdateConfiguration_Command { @@ -166,32 +150,33 @@ typedef struct __nfpack Monitor_UpdateConfiguration_Command uint32_t Done; uint8_t Data[1]; -}Monitor_UpdateConfiguration_Command; +} Monitor_UpdateConfiguration_Command; typedef struct Monitor_UpdateConfiguration_Reply { uint32_t ErrorCode; -}Monitor_UpdateConfiguration_Reply; +} Monitor_UpdateConfiguration_Reply; ////////////////////////////////////////// // function declarations (commands) #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif -int Monitor_Ping(WP_Message* message); -int Monitor_OemInfo(WP_Message* message); -int Monitor_WriteMemory(WP_Message* message); -int Monitor_ReadMemory(WP_Message* message); -int Monitor_Reboot(WP_Message* message); -int Monitor_EraseMemory(WP_Message* message); -int Monitor_QueryConfiguration(WP_Message* message); -int Monitor_UpdateConfiguration(WP_Message* message); -int Monitor_CheckMemory(WP_Message* message); -int Monitor_MemoryMap(WP_Message* message); -int Monitor_FlashSectorMap(WP_Message* message); + int Monitor_Ping(WP_Message *message); + int Monitor_OemInfo(WP_Message *message); + int Monitor_WriteMemory(WP_Message *message); + int Monitor_ReadMemory(WP_Message *message); + int Monitor_Reboot(WP_Message *message); + int Monitor_EraseMemory(WP_Message *message); + int Monitor_QueryConfiguration(WP_Message *message); + int Monitor_UpdateConfiguration(WP_Message *message); + int Monitor_CheckMemory(WP_Message *message); + int Monitor_MemoryMap(WP_Message *message); + int Monitor_FlashSectorMap(WP_Message *message); #ifdef __cplusplus } diff --git a/src/CLR/Include/nanoCLR_Application.h b/src/CLR/Include/nanoCLR_Application.h index 6cba90ebc9..3ad39b64d8 100644 --- a/src/CLR/Include/nanoCLR_Application.h +++ b/src/CLR/Include/nanoCLR_Application.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Include/nanoCLR_Checks.h b/src/CLR/Include/nanoCLR_Checks.h index a2398d8d2c..59d0f2e41a 100644 --- a/src/CLR/Include/nanoCLR_Checks.h +++ b/src/CLR/Include/nanoCLR_Checks.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Include/nanoCLR_Debugging.h b/src/CLR/Include/nanoCLR_Debugging.h index d6c4115ad5..1f5c40cc71 100644 --- a/src/CLR/Include/nanoCLR_Debugging.h +++ b/src/CLR/Include/nanoCLR_Debugging.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // @@ -18,50 +18,33 @@ //#if defined(_MSC_VER) struct CLR_DBG_Commands { - static const unsigned int c_Monitor_Ping = 0x00000000; // The payload is empty, this command is used to let the other side know we are here... - static const unsigned int c_Monitor_Message = 0x00000001; // The payload is composed of the string characters, no zero at the end. - static const unsigned int c_Monitor_ReadMemory = 0x00000002; - static const unsigned int c_Monitor_WriteMemory = 0x00000003; - static const unsigned int c_Monitor_CheckMemory = 0x00000004; - static const unsigned int c_Monitor_EraseMemory = 0x00000005; - static const unsigned int c_Monitor_Execute = 0x00000006; - static const unsigned int c_Monitor_Reboot = 0x00000007; - static const unsigned int c_Monitor_MemoryMap = 0x00000008; - static const unsigned int c_Monitor_ProgramExit = 0x00000009; // The payload is empty, this command is used to tell the PC of a program termination - static const unsigned int c_Monitor_CheckSignature = 0x0000000A; - static const unsigned int c_Monitor_DeploymentMap = 0x0000000B; - static const unsigned int c_Monitor_FlashSectorMap = 0x0000000C; - static const unsigned int c_Monitor_OemInfo = 0x0000000E; + static const unsigned int c_Monitor_Ping = + 0x00000000; // The payload is empty, this command is used to let the other side know we are here... + static const unsigned int c_Monitor_Message = + 0x00000001; // The payload is composed of the string characters, no zero at the end. + static const unsigned int c_Monitor_ReadMemory = 0x00000002; + static const unsigned int c_Monitor_WriteMemory = 0x00000003; + static const unsigned int c_Monitor_CheckMemory = 0x00000004; + static const unsigned int c_Monitor_EraseMemory = 0x00000005; + static const unsigned int c_Monitor_Execute = 0x00000006; + static const unsigned int c_Monitor_Reboot = 0x00000007; + static const unsigned int c_Monitor_MemoryMap = 0x00000008; + static const unsigned int c_Monitor_ProgramExit = + 0x00000009; // The payload is empty, this command is used to tell the PC of a program termination + static const unsigned int c_Monitor_CheckSignature = 0x0000000A; + static const unsigned int c_Monitor_DeploymentMap = 0x0000000B; + static const unsigned int c_Monitor_FlashSectorMap = 0x0000000C; + static const unsigned int c_Monitor_OemInfo = 0x0000000E; static const unsigned int c_Monitor_QueryConfiguration = 0x0000000F; - static const unsigned int c_Monitor_UpdateConfiguration= 0x00000010; + static const unsigned int c_Monitor_UpdateConfiguration = 0x00000010; //--// - - - - - - - - - - - - - - - - - - - - struct Monitor_OemInfo { struct Reply { - NFReleaseInfo m_releaseInfo; + NFReleaseInfo m_releaseInfo; }; }; @@ -70,235 +53,175 @@ struct CLR_DBG_Commands ///////////////////////////////////////////////////////////////////////////////////////////////////////// struct Monitor_Reboot { - static const unsigned int c_NormalReboot = 0; + static const unsigned int c_NormalReboot = 0; static const unsigned int c_EnterBootloader = 1; - static const unsigned int c_ClrOnly = 2; - static const unsigned int c_WaitForDebugger = 4; + static const unsigned int c_ClrOnly = 2; + static const unsigned int c_WaitForDebugger = 4; unsigned int m_flags; }; - - - - - - - - - - - - - - - - - - - - - - - struct Monitor_Signature - { + { unsigned int m_keyIndex; - unsigned int m_length; - unsigned char m_signature[ 1 ]; + unsigned int m_length; + unsigned char m_signature[1]; }; - - - - - - - - - - - - - - - - - - - - - - struct Monitor_Execute { unsigned int m_address; }; - - - - - - - - - - - - - - - - struct Monitor_DeploymentMap - { + { static const CLR_UINT32 c_CRC_Erased_Sentinel = 0x0; struct FlashSector { CLR_UINT32 m_start; CLR_UINT32 m_length; - + CLR_UINT32 m_crc; }; struct Reply { - FlashSector m_data[ 1 ]; + FlashSector m_data[1]; }; }; - - - struct Monitor_SignatureKeyUpdate { unsigned int m_keyIndex; - unsigned char m_newKeySignature[ 128 ]; - unsigned char m_newKey[ 260 ]; + unsigned char m_newKeySignature[128]; + unsigned char m_newKey[260]; unsigned int m_reserveLength; - unsigned char m_reserveData[ 1 ]; + unsigned char m_reserveData[1]; }; //--------------------------------------------------------------// - static const unsigned int c_Debugging_Execution_BasePtr = 0x00020000; // Returns the pointer for the ExecutionEngine object. - static const unsigned int c_Debugging_Execution_ChangeConditions = 0x00020001; // Sets/resets the state of the debugger. - static const unsigned int c_Debugging_Execution_SecurityKey = 0x00020002; // Sets security key. - static const unsigned int c_Debugging_Execution_Unlock = 0x00020003; // Unlock the low-level command, for mfg. test programs. - static const unsigned int c_Debugging_Execution_Allocate = 0x00020004; // Permanently allocate some memory. - static const unsigned int c_Debugging_Execution_Breakpoints = 0x00020005; // Sets breakpoints. - static const unsigned int c_Debugging_Execution_BreakpointHit = 0x00020006; // Notification that a breakpoint was hit. - static const unsigned int c_Debugging_Execution_BreakpointStatus = 0x00020007; // Queries last breakpoint hit. - static const unsigned int c_Debugging_Execution_QueryCLRCapabilities = 0x00020008; // Queries capabilities of the CLR. - static const unsigned int c_Debugging_Execution_SetCurrentAppDomain = 0x00020009; // Sets the current AppDomain. This is required before - // performing certain debugging operations, such as - // accessing a static field, or doing function evaluation, - - static const unsigned int c_Debugging_Thread_Create = 0x00020010; // OBSOLETE - Use c_Debugging_Thread_CreateEx instead. - static const unsigned int c_Debugging_Thread_List = 0x00020011; // Lists the active/waiting threads. - static const unsigned int c_Debugging_Thread_Stack = 0x00020012; // Lists the call stack for a thread. - static const unsigned int c_Debugging_Thread_Kill = 0x00020013; // Kills a thread. - static const unsigned int c_Debugging_Thread_Suspend = 0x00020014; // Suspends the execution of a thread. - static const unsigned int c_Debugging_Thread_Resume = 0x00020015; // Resumes the execution of a thread. - static const unsigned int c_Debugging_Thread_GetException = 0x00020016; // Gets the current exception. - static const unsigned int c_Debugging_Thread_Unwind = 0x00020017; // Unwinds to given stack frame. - static const unsigned int c_Debugging_Thread_CreateEx = 0x00020018; // Creates a new thread but Thread.CurrentThread will return the identity of the passed thread. - static const unsigned int c_Debugging_Thread_Get = 0x00021000; // Gets the current thread. - - static const unsigned int c_Debugging_Stack_Info = 0x00020020; // Gets more info on a stack frame. - static const unsigned int c_Debugging_Stack_SetIP = 0x00020021; // Sets the IP on a given thread. - - static const unsigned int c_Debugging_Value_ResizeScratchPad = 0x00020030; // Resizes the scratchpad area. - static const unsigned int c_Debugging_Value_GetStack = 0x00020031; // Reads a value from the stack frame. - static const unsigned int c_Debugging_Value_GetField = 0x00020032; // Reads a value from an object's field. - static const unsigned int c_Debugging_Value_GetArray = 0x00020033; // Reads a value from an array's element. - static const unsigned int c_Debugging_Value_GetBlock = 0x00020034; // Reads a value from a heap block. - static const unsigned int c_Debugging_Value_GetScratchPad = 0x00020035; // Reads a value from the scratchpad area. - static const unsigned int c_Debugging_Value_SetBlock = 0x00020036; // Writes a value to a heap block. - static const unsigned int c_Debugging_Value_SetArray = 0x00020037; // Writes a value to an array's element. - static const unsigned int c_Debugging_Value_AllocateObject = 0x00020038; // Creates a new instance of an object. - static const unsigned int c_Debugging_Value_AllocateString = 0x00020039; // Creates a new instance of a string. - static const unsigned int c_Debugging_Value_AllocateArray = 0x0002003A; // Creates a new instance of an array. - static const unsigned int c_Debugging_Value_Assign = 0x0002003B; // Assigns a value to another value. - - static const unsigned int c_Debugging_TypeSys_Assemblies = 0x00020040; // Lists all the assemblies in the system. - static const unsigned int c_Debugging_TypeSys_AppDomains = 0x00020044; // Lists all the AppDomans loaded. - - static const unsigned int c_Debugging_Resolve_Assembly = 0x00020050; // Resolves an assembly. - static const unsigned int c_Debugging_Resolve_Type = 0x00020051; // Resolves a type to a string. - static const unsigned int c_Debugging_Resolve_Field = 0x00020052; // Resolves a field to a string. - static const unsigned int c_Debugging_Resolve_Method = 0x00020053; // Resolves a method to a string. - static const unsigned int c_Debugging_Resolve_VirtualMethod = 0x00020054; // Resolves a virtual method to the actual implementation. - static const unsigned int c_Debugging_Resolve_AppDomain = 0x00020055; // Resolves an AppDomain to it's name, and list its loaded assemblies. - - - - - - - - - - static const unsigned int c_Debugging_UpgradeToSsl = 0x00020069; // - - //--// - - static const unsigned int c_Debugging_Button_Report = 0x00020080; // Reports a button press/release. - static const unsigned int c_Debugging_Button_Inject = 0x00020081; // Injects a button press/release. - - static const unsigned int c_Debugging_Deployment_Status = 0x000200B0; // Returns entryPoint and boundary of deployment area. - - static const unsigned int c_Debugging_Info_SetJMC = 0x000200C0; // Sets code to be flagged as JMC (Just my code). - - static const unsigned int c_Profiling_Command = 0x00030000; // Various incoming commands regarding profiling - static const unsigned int c_Profiling_Stream = 0x00030001; // Stream for MFProfiler information. + static const unsigned int c_Debugging_Execution_BasePtr = + 0x00020000; // Returns the pointer for the ExecutionEngine object. + static const unsigned int c_Debugging_Execution_ChangeConditions = + 0x00020001; // Sets/resets the state of the debugger. + static const unsigned int c_Debugging_Execution_SecurityKey = 0x00020002; // Sets security key. + static const unsigned int c_Debugging_Execution_Unlock = + 0x00020003; // Unlock the low-level command, for mfg. test programs. + static const unsigned int c_Debugging_Execution_Allocate = 0x00020004; // Permanently allocate some memory. + static const unsigned int c_Debugging_Execution_Breakpoints = 0x00020005; // Sets breakpoints. + static const unsigned int c_Debugging_Execution_BreakpointHit = + 0x00020006; // Notification that a breakpoint was hit. + static const unsigned int c_Debugging_Execution_BreakpointStatus = 0x00020007; // Queries last breakpoint hit. + static const unsigned int c_Debugging_Execution_QueryCLRCapabilities = + 0x00020008; // Queries capabilities of the CLR. + static const unsigned int c_Debugging_Execution_SetCurrentAppDomain = + 0x00020009; // Sets the current AppDomain. This is required before + // performing certain debugging operations, such as + // accessing a static field, or doing function evaluation, + + static const unsigned int c_Debugging_Thread_Create = + 0x00020010; // OBSOLETE - Use c_Debugging_Thread_CreateEx instead. + static const unsigned int c_Debugging_Thread_List = 0x00020011; // Lists the active/waiting threads. + static const unsigned int c_Debugging_Thread_Stack = 0x00020012; // Lists the call stack for a thread. + static const unsigned int c_Debugging_Thread_Kill = 0x00020013; // Kills a thread. + static const unsigned int c_Debugging_Thread_Suspend = 0x00020014; // Suspends the execution of a thread. + static const unsigned int c_Debugging_Thread_Resume = 0x00020015; // Resumes the execution of a thread. + static const unsigned int c_Debugging_Thread_GetException = 0x00020016; // Gets the current exception. + static const unsigned int c_Debugging_Thread_Unwind = 0x00020017; // Unwinds to given stack frame. + static const unsigned int c_Debugging_Thread_CreateEx = + 0x00020018; // Creates a new thread but Thread.CurrentThread will return the identity of the passed thread. + static const unsigned int c_Debugging_Thread_Get = 0x00021000; // Gets the current thread. + + static const unsigned int c_Debugging_Stack_Info = 0x00020020; // Gets more info on a stack frame. + static const unsigned int c_Debugging_Stack_SetIP = 0x00020021; // Sets the IP on a given thread. + + static const unsigned int c_Debugging_Value_ResizeScratchPad = 0x00020030; // Resizes the scratchpad area. + static const unsigned int c_Debugging_Value_GetStack = 0x00020031; // Reads a value from the stack frame. + static const unsigned int c_Debugging_Value_GetField = 0x00020032; // Reads a value from an object's field. + static const unsigned int c_Debugging_Value_GetArray = 0x00020033; // Reads a value from an array's element. + static const unsigned int c_Debugging_Value_GetBlock = 0x00020034; // Reads a value from a heap block. + static const unsigned int c_Debugging_Value_GetScratchPad = 0x00020035; // Reads a value from the scratchpad area. + static const unsigned int c_Debugging_Value_SetBlock = 0x00020036; // Writes a value to a heap block. + static const unsigned int c_Debugging_Value_SetArray = 0x00020037; // Writes a value to an array's element. + static const unsigned int c_Debugging_Value_AllocateObject = 0x00020038; // Creates a new instance of an object. + static const unsigned int c_Debugging_Value_AllocateString = 0x00020039; // Creates a new instance of a string. + static const unsigned int c_Debugging_Value_AllocateArray = 0x0002003A; // Creates a new instance of an array. + static const unsigned int c_Debugging_Value_Assign = 0x0002003B; // Assigns a value to another value. + + static const unsigned int c_Debugging_TypeSys_Assemblies = 0x00020040; // Lists all the assemblies in the system. + static const unsigned int c_Debugging_TypeSys_AppDomains = 0x00020044; // Lists all the AppDomans loaded. + + static const unsigned int c_Debugging_Resolve_Assembly = 0x00020050; // Resolves an assembly. + static const unsigned int c_Debugging_Resolve_Type = 0x00020051; // Resolves a type to a string. + static const unsigned int c_Debugging_Resolve_Field = 0x00020052; // Resolves a field to a string. + static const unsigned int c_Debugging_Resolve_Method = 0x00020053; // Resolves a method to a string. + static const unsigned int c_Debugging_Resolve_VirtualMethod = + 0x00020054; // Resolves a virtual method to the actual implementation. + static const unsigned int c_Debugging_Resolve_AppDomain = + 0x00020055; // Resolves an AppDomain to it's name, and list its loaded assemblies. + + static const unsigned int c_Debugging_UpgradeToSsl = 0x00020069; // + + //--// + + static const unsigned int c_Debugging_Button_Report = 0x00020080; // Reports a button press/release. + static const unsigned int c_Debugging_Button_Inject = 0x00020081; // Injects a button press/release. + + static const unsigned int c_Debugging_Deployment_Status = + 0x000200B0; // Returns entryPoint and boundary of deployment area. + + static const unsigned int c_Debugging_Info_SetJMC = 0x000200C0; // Sets code to be flagged as JMC (Just my code). + + static const unsigned int c_Profiling_Command = 0x00030000; // Various incoming commands regarding profiling + static const unsigned int c_Profiling_Stream = 0x00030001; // Stream for MFProfiler information. //--// struct Debugging_Execution_Unlock { - unsigned char m_command[ 128 ]; - unsigned char m_hash [ 128 ]; + unsigned char m_command[128]; + unsigned char m_hash[128]; }; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // !!! KEEP IN SYNC WITH nanoFramework.Tools.Debugger.WireProtocol.Commands.Debugging_Execution_QueryCLRCapabilities (in managed code) !!! // + // !!! KEEP IN SYNC WITH nanoFramework.Tools.Debugger.WireProtocol.Commands.Debugging_Execution_QueryCLRCapabilities + // (in managed code) !!! // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// struct Debugging_Execution_QueryCLRCapabilities { - static const CLR_UINT32 c_CapabilityFlags = 1; - static const CLR_UINT32 c_CapabilityVersion = 3; - static const CLR_UINT32 c_HalSystemInfo = 5; - static const CLR_UINT32 c_ClrInfo = 6; - static const CLR_UINT32 c_TargetReleaseInfo = 7; - static const CLR_UINT32 c_InteropNativeAssemblies = 8; - static const CLR_UINT32 c_InteropNativeAssembliesCount = 9; - - static const CLR_UINT32 c_CapabilityFlags_FloatingPoint = 0x00000001; - static const CLR_UINT32 c_CapabilityFlags_SourceLevelDebugging = 0x00000002; - static const CLR_UINT32 c_CapabilityFlags_AppDomains = 0x00000004; - static const CLR_UINT32 c_CapabilityFlags_ExceptionFilters = 0x00000008; - static const CLR_UINT32 c_CapabilityFlags_IncrementalDeployment = 0x00000010; - static const CLR_UINT32 c_CapabilityFlags_SoftReboot = 0x00000020; - static const CLR_UINT32 c_CapabilityFlags_Profiling = 0x00000040; - static const CLR_UINT32 c_CapabilityFlags_Profiling_Allocations = 0x00000080; - static const CLR_UINT32 c_CapabilityFlags_Profiling_Calls = 0x00000100; - static const CLR_UINT32 c_CapabilityFlags_ThreadCreateEx = 0x00000400; - static const CLR_UINT32 c_CapabilityFlags_ConfigBlockRequiresErase = 0x00000800; - static const CLR_UINT32 c_CapabilityFlags_HasNanoBooter = 0x00001000; - static const CLR_UINT32 c_CapabilityFlags_PlatformCapabiliy_0 = 0x00010000; - static const CLR_UINT32 c_CapabilityFlags_PlatformCapabiliy_1 = 0x00020000; - static const CLR_UINT32 c_CapabilityFlags_TargetCapabiliy_0 = 0x00040000; - static const CLR_UINT32 c_CapabilityFlags_TargetCapabiliy_1 = 0x00080000; + static const CLR_UINT32 c_CapabilityFlags = 1; + static const CLR_UINT32 c_CapabilityVersion = 3; + static const CLR_UINT32 c_HalSystemInfo = 5; + static const CLR_UINT32 c_ClrInfo = 6; + static const CLR_UINT32 c_TargetReleaseInfo = 7; + static const CLR_UINT32 c_InteropNativeAssemblies = 8; + static const CLR_UINT32 c_InteropNativeAssembliesCount = 9; + + static const CLR_UINT32 c_CapabilityFlags_FloatingPoint = 0x00000001; + static const CLR_UINT32 c_CapabilityFlags_SourceLevelDebugging = 0x00000002; + static const CLR_UINT32 c_CapabilityFlags_AppDomains = 0x00000004; + static const CLR_UINT32 c_CapabilityFlags_ExceptionFilters = 0x00000008; + static const CLR_UINT32 c_CapabilityFlags_IncrementalDeployment = 0x00000010; + static const CLR_UINT32 c_CapabilityFlags_SoftReboot = 0x00000020; + static const CLR_UINT32 c_CapabilityFlags_Profiling = 0x00000040; + static const CLR_UINT32 c_CapabilityFlags_Profiling_Allocations = 0x00000080; + static const CLR_UINT32 c_CapabilityFlags_Profiling_Calls = 0x00000100; + static const CLR_UINT32 c_CapabilityFlags_ThreadCreateEx = 0x00000400; + static const CLR_UINT32 c_CapabilityFlags_ConfigBlockRequiresErase = 0x00000800; + static const CLR_UINT32 c_CapabilityFlags_HasNanoBooter = 0x00001000; + static const CLR_UINT32 c_CapabilityFlags_PlatformCapabiliy_0 = 0x00010000; + static const CLR_UINT32 c_CapabilityFlags_PlatformCapabiliy_1 = 0x00020000; + static const CLR_UINT32 c_CapabilityFlags_TargetCapabiliy_0 = 0x00040000; + static const CLR_UINT32 c_CapabilityFlags_TargetCapabiliy_1 = 0x00080000; CLR_UINT32 m_cmd; struct __nfpack SoftwareVersion { - char BuildDate[ 22 ]; + char BuildDate[22]; char CompilerInfo[16]; unsigned int CompilerVersion; }; @@ -306,26 +229,24 @@ struct CLR_DBG_Commands struct __nfpack ClrInfo { NFReleaseInfo m_clrReleaseInfo; - NFVersion m_TargetFrameworkVersion; + NFVersion m_TargetFrameworkVersion; }; - + struct __nfpack NativeAssemblyDetails { uint32_t CheckSum; NFVersion Version; uint8_t AssemblyName[128]; - }; - union ReplyUnion - { - CLR_UINT32 u_capsFlags; - SoftwareVersion u_SoftwareVersion; - HalSystemInfo u_HalSystemInfo; - ClrInfo u_ClrInfo; - NFReleaseInfo u_TargetReleaseInfo; - }; - }; + union ReplyUnion { + CLR_UINT32 u_capsFlags; + SoftwareVersion u_SoftwareVersion; + HalSystemInfo u_HalSystemInfo; + ClrInfo u_ClrInfo; + NFReleaseInfo u_TargetReleaseInfo; + }; + }; //--// @@ -335,7 +256,7 @@ struct CLR_DBG_Commands struct Reply { - CLR_UINT32 m_found; + CLR_UINT32 m_found; CLR_RT_HeapBlock_EndPoint::Address m_addr; }; }; @@ -343,11 +264,11 @@ struct CLR_DBG_Commands struct Debugging_Messaging_Send { CLR_RT_HeapBlock_EndPoint::Address m_addr; - unsigned char m_data[ 1 ]; + unsigned char m_data[1]; struct Reply { - CLR_UINT32 m_found; + CLR_UINT32 m_found; CLR_RT_HeapBlock_EndPoint::Address m_addr; }; }; @@ -355,17 +276,16 @@ struct CLR_DBG_Commands struct Debugging_Messaging_Reply { CLR_RT_HeapBlock_EndPoint::Address m_addr; - unsigned char m_data[ 1 ]; + unsigned char m_data[1]; struct Reply { - CLR_UINT32 m_found; + CLR_UINT32 m_found; CLR_RT_HeapBlock_EndPoint::Address m_addr; }; }; //--// - struct Debugging_Execution_BasePtr { @@ -388,7 +308,7 @@ struct CLR_DBG_Commands struct Debugging_Execution_SecurityKey { - CLR_UINT8 m_key[ 32 ]; + CLR_UINT8 m_key[32]; }; struct Debugging_Execution_Allocate @@ -411,8 +331,7 @@ struct CLR_DBG_Commands }; }; - - //struct Debugging_MFUpdate_Start + // struct Debugging_MFUpdate_Start //{ // char m_provider[64]; // CLR_UINT32 m_updateId; @@ -429,7 +348,7 @@ struct CLR_DBG_Commands // }; //}; - //struct Debugging_MFUpdate_AuthCommand + // struct Debugging_MFUpdate_AuthCommand //{ // CLR_UINT32 m_updateHandle; // CLR_UINT32 m_authCommand; @@ -444,7 +363,7 @@ struct CLR_DBG_Commands // }; //}; - //struct Debugging_MFUpdate_Authenticate + // struct Debugging_MFUpdate_Authenticate //{ // CLR_UINT32 m_updateHandle; // CLR_UINT32 m_authenticationLen; @@ -456,10 +375,10 @@ struct CLR_DBG_Commands // }; //}; - //struct Debugging_MFUpdate_GetMissingPkts + // struct Debugging_MFUpdate_GetMissingPkts //{ // CLR_UINT32 m_updateHandle; - // + // // struct Reply // { // CLR_INT32 m_success; @@ -468,7 +387,7 @@ struct CLR_DBG_Commands // }; //}; - //struct Debugging_MFUpdate_AddPacket + // struct Debugging_MFUpdate_AddPacket //{ // CLR_INT32 m_updateHandle; // CLR_UINT32 m_packetIndex; @@ -482,7 +401,7 @@ struct CLR_DBG_Commands // }; //}; - //struct Debugging_MFUpdate_Install + // struct Debugging_MFUpdate_Install //{ // CLR_INT32 m_updateHandle; // CLR_UINT32 m_updateValidationSize; @@ -493,73 +412,71 @@ struct CLR_DBG_Commands // CLR_UINT32 m_success; // }; //}; - struct Debugging_Execution_BreakpointDef { - static const CLR_UINT16 c_STEP_IN = 0x0001; - static const CLR_UINT16 c_STEP_OVER = 0x0002; - static const CLR_UINT16 c_STEP_OUT = 0x0004; - static const CLR_UINT16 c_HARD = 0x0008; - static const CLR_UINT16 c_EXCEPTION_THROWN = 0x0010; - static const CLR_UINT16 c_EXCEPTION_CAUGHT = 0x0020; + static const CLR_UINT16 c_STEP_IN = 0x0001; + static const CLR_UINT16 c_STEP_OVER = 0x0002; + static const CLR_UINT16 c_STEP_OUT = 0x0004; + static const CLR_UINT16 c_HARD = 0x0008; + static const CLR_UINT16 c_EXCEPTION_THROWN = 0x0010; + static const CLR_UINT16 c_EXCEPTION_CAUGHT = 0x0020; static const CLR_UINT16 c_EXCEPTION_UNCAUGHT = 0x0040; - static const CLR_UINT16 c_THREAD_TERMINATED = 0x0080; - static const CLR_UINT16 c_THREAD_CREATED = 0x0100; - static const CLR_UINT16 c_ASSEMBLIES_LOADED = 0x0200; - static const CLR_UINT16 c_LAST_BREAKPOINT = 0x0400; - static const CLR_UINT16 c_STEP_JMC = 0x0800; - static const CLR_UINT16 c_BREAK = 0x1000; - static const CLR_UINT16 c_EVAL_COMPLETE = 0x2000; - static const CLR_UINT16 c_EXCEPTION_UNWIND = 0x4000; - static const CLR_UINT16 c_EXCEPTION_FINALLY = 0x8000; - - static const CLR_UINT16 c_STEP = c_STEP_IN | c_STEP_OVER | c_STEP_OUT; - - static const CLR_INT32 c_PID_ANY = 0x7FFFFFFF; - - static const CLR_UINT32 c_DEPTH_EXCEPTION_FIRST_CHANCE = 0x00000000; - static const CLR_UINT32 c_DEPTH_EXCEPTION_USERS_CHANCE = 0x00000001; - static const CLR_UINT32 c_DEPTH_EXCEPTION_HANDLER_FOUND = 0x00000002; - - static const CLR_UINT32 c_DEPTH_STEP_NORMAL = 0x00000010; - static const CLR_UINT32 c_DEPTH_STEP_RETURN = 0x00000020; - static const CLR_UINT32 c_DEPTH_STEP_CALL = 0x00000030; - static const CLR_UINT32 c_DEPTH_STEP_EXCEPTION_FILTER = 0x00000040; - static const CLR_UINT32 c_DEPTH_STEP_EXCEPTION_HANDLER = 0x00000050; - static const CLR_UINT32 c_DEPTH_STEP_INTERCEPT = 0x00000060; - static const CLR_UINT32 c_DEPTH_STEP_EXIT = 0x00000070; - - static const CLR_UINT32 c_DEPTH_UNCAUGHT = 0xFFFFFFFF; - - - CLR_UINT16 m_id; - CLR_UINT16 m_flags; - - CLR_INT32 m_pid; - CLR_UINT32 m_depth; + static const CLR_UINT16 c_THREAD_TERMINATED = 0x0080; + static const CLR_UINT16 c_THREAD_CREATED = 0x0100; + static const CLR_UINT16 c_ASSEMBLIES_LOADED = 0x0200; + static const CLR_UINT16 c_LAST_BREAKPOINT = 0x0400; + static const CLR_UINT16 c_STEP_JMC = 0x0800; + static const CLR_UINT16 c_BREAK = 0x1000; + static const CLR_UINT16 c_EVAL_COMPLETE = 0x2000; + static const CLR_UINT16 c_EXCEPTION_UNWIND = 0x4000; + static const CLR_UINT16 c_EXCEPTION_FINALLY = 0x8000; + + static const CLR_UINT16 c_STEP = c_STEP_IN | c_STEP_OVER | c_STEP_OUT; + + static const CLR_INT32 c_PID_ANY = 0x7FFFFFFF; + + static const CLR_UINT32 c_DEPTH_EXCEPTION_FIRST_CHANCE = 0x00000000; + static const CLR_UINT32 c_DEPTH_EXCEPTION_USERS_CHANCE = 0x00000001; + static const CLR_UINT32 c_DEPTH_EXCEPTION_HANDLER_FOUND = 0x00000002; + + static const CLR_UINT32 c_DEPTH_STEP_NORMAL = 0x00000010; + static const CLR_UINT32 c_DEPTH_STEP_RETURN = 0x00000020; + static const CLR_UINT32 c_DEPTH_STEP_CALL = 0x00000030; + static const CLR_UINT32 c_DEPTH_STEP_EXCEPTION_FILTER = 0x00000040; + static const CLR_UINT32 c_DEPTH_STEP_EXCEPTION_HANDLER = 0x00000050; + static const CLR_UINT32 c_DEPTH_STEP_INTERCEPT = 0x00000060; + static const CLR_UINT32 c_DEPTH_STEP_EXIT = 0x00000070; + + static const CLR_UINT32 c_DEPTH_UNCAUGHT = 0xFFFFFFFF; + + CLR_UINT16 m_id; + CLR_UINT16 m_flags; + + CLR_INT32 m_pid; + CLR_UINT32 m_depth; // // m_IPStart, m_IPEnd are used for optimizing stepping operations. // A STEP_IN | STEP_OVER breakpoint will be hit in the given stack frame // only if the IP is outside of the given range [m_IPStart m_IPEnd). // - CLR_UINT32 m_IPStart; - CLR_UINT32 m_IPEnd; + CLR_UINT32 m_IPStart; + CLR_UINT32 m_IPEnd; CLR_RT_MethodDef_Index m_md; - CLR_UINT32 m_IP; + CLR_UINT32 m_IP; - CLR_RT_TypeDef_Index m_td; + CLR_RT_TypeDef_Index m_td; - CLR_UINT32 m_depthExceptionHandler; + CLR_UINT32 m_depthExceptionHandler; }; struct Debugging_Execution_Breakpoints { - CLR_UINT32 m_flags; + CLR_UINT32 m_flags; - Debugging_Execution_BreakpointDef m_data[ 1 ]; + Debugging_Execution_BreakpointDef m_data[1]; }; struct Debugging_Execution_BreakpointHit @@ -585,8 +502,8 @@ struct CLR_DBG_Commands struct Debugging_Thread_CreateEx { CLR_RT_MethodDef_Index m_md; - int m_scratchPad; - CLR_UINT32 m_pid; + int m_scratchPad; + CLR_UINT32 m_pid; struct Reply { @@ -601,7 +518,7 @@ struct CLR_DBG_Commands struct Reply { CLR_UINT32 m_num; - CLR_UINT32 m_pids[ 1 ]; + CLR_UINT32 m_pids[1]; }; }; @@ -616,18 +533,17 @@ struct CLR_DBG_Commands struct Call { CLR_RT_MethodDef_Index m_md; - CLR_UINT32 m_IP; + CLR_UINT32 m_IP; #if defined(NANOCLR_APPDOMAINS) - CLR_UINT32 m_appDomainID; - CLR_UINT32 m_flags; + CLR_UINT32 m_appDomainID; + CLR_UINT32 m_flags; #endif - }; CLR_UINT32 m_num; CLR_UINT32 m_status; CLR_UINT32 m_flags; - Call m_data[ 1 ]; + Call m_data[1]; }; }; @@ -685,10 +601,10 @@ struct CLR_DBG_Commands struct Reply { CLR_RT_MethodDef_Index m_md; - CLR_UINT32 m_IP; - CLR_UINT32 m_numOfArguments; - CLR_UINT32 m_numOfLocals; - CLR_UINT32 m_depthOfEvalStack; + CLR_UINT32 m_IP; + CLR_UINT32 m_numOfArguments; + CLR_UINT32 m_numOfLocals; + CLR_UINT32 m_depthOfEvalStack; }; }; @@ -705,39 +621,39 @@ struct CLR_DBG_Commands struct Debugging_Value { - CLR_RT_HeapBlock* m_referenceID; - CLR_UINT32 m_dt; // CLR_RT_HeapBlock::DataType () - CLR_UINT32 m_flags; // CLR_RT_HeapBlock::DataFlags() - CLR_UINT32 m_size; // CLR_RT_HeapBlock::DataSize () + CLR_RT_HeapBlock *m_referenceID; + CLR_UINT32 m_dt; // CLR_RT_HeapBlock::DataType () + CLR_UINT32 m_flags; // CLR_RT_HeapBlock::DataFlags() + CLR_UINT32 m_size; // CLR_RT_HeapBlock::DataSize () // // For primitive types // - CLR_UINT8 m_builtinValue[ 128 ]; // Space for string preview... + CLR_UINT8 m_builtinValue[128]; // Space for string preview... // // For DATATYPE_STRING // - CLR_UINT32 m_bytesInString; - const char* m_charsInString; + CLR_UINT32 m_bytesInString; + const char *m_charsInString; // // For DATATYPE_VALUETYPE or DATATYPE_CLASSTYPE // - CLR_RT_TypeDef_Index m_td; + CLR_RT_TypeDef_Index m_td; // // For DATATYPE_SZARRAY // - CLR_UINT32 m_array_numOfElements; - CLR_UINT32 m_array_depth; - CLR_RT_TypeDef_Index m_array_typeIndex; + CLR_UINT32 m_array_numOfElements; + CLR_UINT32 m_array_depth; + CLR_RT_TypeDef_Index m_array_typeIndex; // // For values from an array. // - CLR_RT_HeapBlock_Array* m_arrayref_referenceID; - CLR_UINT32 m_arrayref_index; + CLR_RT_HeapBlock_Array *m_arrayref_referenceID; + CLR_UINT32 m_arrayref_index; }; struct Debugging_Value_ResizeScratchPad @@ -747,8 +663,8 @@ struct CLR_DBG_Commands struct Debugging_Value_GetStack { - static const CLR_UINT32 c_Local = 0; - static const CLR_UINT32 c_Argument = 1; + static const CLR_UINT32 c_Local = 0; + static const CLR_UINT32 c_Argument = 1; static const CLR_UINT32 c_EvalStack = 2; CLR_UINT32 m_pid; @@ -756,7 +672,6 @@ struct CLR_DBG_Commands CLR_UINT32 m_kind; CLR_UINT32 m_index; - // // The reply is an array of Debugging_Value // @@ -764,11 +679,10 @@ struct CLR_DBG_Commands struct Debugging_Value_GetField { - CLR_RT_HeapBlock* m_heapblock; - CLR_UINT32 m_offset; + CLR_RT_HeapBlock *m_heapblock; + CLR_UINT32 m_offset; CLR_RT_FieldDef_Index m_fd; - // // The reply is an array of Debugging_Value // @@ -776,9 +690,8 @@ struct CLR_DBG_Commands struct Debugging_Value_GetArray { - CLR_RT_HeapBlock* m_heapblock; - CLR_UINT32 m_index; - + CLR_RT_HeapBlock *m_heapblock; + CLR_UINT32 m_index; // // The reply is an array of Debugging_Value @@ -787,8 +700,7 @@ struct CLR_DBG_Commands struct Debugging_Value_GetBlock { - CLR_RT_HeapBlock* m_heapblock; - + CLR_RT_HeapBlock *m_heapblock; // // The reply is an array of Debugging_Value @@ -799,7 +711,6 @@ struct CLR_DBG_Commands { CLR_UINT32 m_idx; - // // The reply is an array of Debugging_Value // @@ -807,23 +718,23 @@ struct CLR_DBG_Commands struct Debugging_Value_SetBlock { - CLR_RT_HeapBlock* m_heapblock; - CLR_UINT32 m_dt; // CLR_RT_HeapBlock::DataType () - CLR_UINT8 m_builtinValue[ 8 ]; + CLR_RT_HeapBlock *m_heapblock; + CLR_UINT32 m_dt; // CLR_RT_HeapBlock::DataType () + CLR_UINT8 m_builtinValue[8]; }; struct Debugging_Value_SetArray { - CLR_RT_HeapBlock_Array* m_heapblock; - CLR_UINT32 m_index; - CLR_UINT8 m_builtinValue[ 8 ]; + CLR_RT_HeapBlock_Array *m_heapblock; + CLR_UINT32 m_index; + CLR_UINT8 m_builtinValue[8]; }; //--// struct Debugging_Value_AllocateObject { - int m_index; + int m_index; CLR_RT_TypeDef_Index m_td; // @@ -833,7 +744,7 @@ struct CLR_DBG_Commands struct Debugging_Value_AllocateString { - int m_index; + int m_index; CLR_UINT32 m_size; // @@ -843,10 +754,10 @@ struct CLR_DBG_Commands struct Debugging_Value_AllocateArray { - int m_index; + int m_index; CLR_RT_TypeDef_Index m_td; - CLR_UINT32 m_depth; - CLR_UINT32 m_numOfElements; + CLR_UINT32 m_depth; + CLR_UINT32 m_numOfElements; // // The reply is an array of Debugging_Value @@ -855,8 +766,8 @@ struct CLR_DBG_Commands struct Debugging_Value_Assign { - CLR_RT_HeapBlock* m_heapblockSrc; - CLR_RT_HeapBlock* m_heapblockDst; + CLR_RT_HeapBlock *m_heapblockSrc; + CLR_RT_HeapBlock *m_heapblockDst; // // The reply is an array of Debugging_Value @@ -866,7 +777,7 @@ struct CLR_DBG_Commands //--// struct Debugging_TypeSys_Assemblies - { + { // // The reply is just an array of CLR_RT_Assembly_Index. // @@ -877,32 +788,32 @@ struct CLR_DBG_Commands // // The reply is just an array of AppDomainIDs // - }; + }; //--// struct Debugging_Resolve_AppDomain - { - CLR_UINT32 m_id; + { + CLR_UINT32 m_id; struct Reply { CLR_UINT32 m_state; - char m_szName[ 512 ]; - CLR_UINT32 m_assemblies[ 1 ]; //Array of CLR_RT_Assembly_Index + char m_szName[512]; + CLR_UINT32 m_assemblies[1]; // Array of CLR_RT_Assembly_Index }; }; struct Debugging_Resolve_Assembly { - CLR_RT_Assembly_Index m_idx; - - struct Reply - { - CLR_UINT32 m_flags; - CLR_RECORD_VERSION m_version; - char m_szName[ 512 ]; - }; + CLR_RT_Assembly_Index m_idx; + + struct Reply + { + CLR_UINT32 m_flags; + CLR_RECORD_VERSION m_version; + char m_szName[512]; + }; }; struct Debugging_Resolve_Type @@ -911,7 +822,7 @@ struct CLR_DBG_Commands struct Reply { - char m_type[ 512 ]; + char m_type[512]; }; }; @@ -922,8 +833,8 @@ struct CLR_DBG_Commands struct Reply { CLR_RT_TypeDef_Index m_td; - CLR_UINT32 m_index; - char m_name[ 512 ]; + CLR_UINT32 m_index; + char m_name[512]; }; }; @@ -934,14 +845,14 @@ struct CLR_DBG_Commands struct Reply { CLR_RT_TypeDef_Index m_td; - char m_method[ 512 ]; + char m_method[512]; }; }; struct Debugging_Resolve_VirtualMethod { CLR_RT_MethodDef_Index m_md; - CLR_RT_HeapBlock* m_obj; + CLR_RT_HeapBlock *m_obj; struct Reply { @@ -952,7 +863,7 @@ struct CLR_DBG_Commands //--// struct Debugging_Deployment_Status - { + { struct FlashSector { CLR_UINT32 Start; @@ -964,7 +875,7 @@ struct CLR_DBG_Commands CLR_UINT32 EntryPoint; CLR_UINT32 StorageStart; CLR_UINT32 StorageLength; - + // FlashSector SectorData[ 1 ]; }; }; @@ -974,21 +885,20 @@ struct CLR_DBG_Commands struct Debugging_Info_SetJMC { CLR_UINT32 m_fIsJMC; - CLR_UINT32 m_kind; // CLR_ReflectionType + CLR_UINT32 m_kind; // CLR_ReflectionType - union - { - CLR_RT_Assembly_Index m_assm; - CLR_RT_TypeDef_Index m_type; + union { + CLR_RT_Assembly_Index m_assm; + CLR_RT_TypeDef_Index m_type; CLR_RT_MethodDef_Index m_method; - CLR_UINT32 m_raw; + CLR_UINT32 m_raw; } m_data; }; struct Profiling_Command { static const CLR_UINT8 c_Command_ChangeConditions = 0x01; - static const CLR_UINT8 c_Command_FlushStream = 0x02; + static const CLR_UINT8 c_Command_FlushStream = 0x02; CLR_UINT8 m_command; @@ -1009,15 +919,13 @@ struct CLR_DBG_Commands CLR_UINT16 m_seqId; CLR_UINT16 m_bitLen; }; - }; //#endif struct CLR_DBG_Debugger { - CLR_Messaging* m_messaging; - static BlockStorageDevice* m_deploymentStorageDevice; - + CLR_Messaging *m_messaging; + static BlockStorageDevice *m_deploymentStorageDevice; //--// @@ -1026,135 +934,131 @@ struct CLR_DBG_Debugger static HRESULT CreateInstance(); - HRESULT Debugger_Initialize( COM_HANDLE port ); + HRESULT Debugger_Initialize(COM_HANDLE port); static HRESULT DeleteInstance(); void Debugger_Cleanup(); - static void BroadcastEvent( unsigned int cmd, unsigned int payloadSize, unsigned char* payload, unsigned int flags ); - - void PurgeCache (); + static void BroadcastEvent(unsigned int cmd, unsigned int payloadSize, unsigned char *payload, unsigned int flags); -private: + void PurgeCache(); - bool CheckPermission( ByteAddress address, int mode ); + private: + bool CheckPermission(ByteAddress address, int mode); - bool AccessMemory( uint32_t location, uint32_t lengthInBytes, uint8_t* buf, uint32_t mode, uint32_t& errorCode ); + void AccessMemory(uint32_t location, uint32_t lengthInBytes, uint8_t *buf, uint32_t mode, uint32_t *errorCode); #if defined(NANOCLR_APPDOMAINS) - CLR_RT_AppDomain* GetAppDomainFromID ( CLR_UINT32 id ); + CLR_RT_AppDomain *GetAppDomainFromID(CLR_UINT32 id); #endif - CLR_RT_StackFrame* CheckStackFrame ( CLR_INT32 pid, CLR_UINT32 depth, bool& isInline ); - HRESULT CreateListOfThreads( CLR_DBG_Commands::Debugging_Thread_List ::Reply*& cmdReply, int& totLen ); - HRESULT CreateListOfCalls ( CLR_INT32 pid, CLR_DBG_Commands::Debugging_Thread_Stack::Reply*& cmdReply, int& totLen ); - - CLR_RT_Assembly* IsGoodAssembly( CLR_IDX idxAssm ); - bool CheckTypeDef ( const CLR_RT_TypeDef_Index& td , CLR_RT_TypeDef_Instance& inst ); - bool CheckFieldDef ( const CLR_RT_FieldDef_Index& fd , CLR_RT_FieldDef_Instance& inst ); - bool CheckMethodDef( const CLR_RT_MethodDef_Index& md , CLR_RT_MethodDef_Instance& inst ); - - bool GetValue( WP_Message* msg, CLR_RT_HeapBlock* ptr, CLR_RT_HeapBlock* reference, CLR_RT_TypeDef_Instance* pTD ); + CLR_RT_StackFrame *CheckStackFrame(CLR_INT32 pid, CLR_UINT32 depth, bool &isInline); + HRESULT CreateListOfThreads(CLR_DBG_Commands::Debugging_Thread_List ::Reply *&cmdReply, int &totLen); + HRESULT CreateListOfCalls(CLR_INT32 pid, CLR_DBG_Commands::Debugging_Thread_Stack::Reply *&cmdReply, int &totLen); - bool AllocateAndQueueMessage( CLR_UINT32 cmd, unsigned int length, unsigned char* data, CLR_RT_HeapBlock_EndPoint::Port port, CLR_RT_HeapBlock_EndPoint::Address addr, CLR_UINT32 found ); + CLR_RT_Assembly *IsGoodAssembly(CLR_IDX idxAssm); + bool CheckTypeDef(const CLR_RT_TypeDef_Index &td, CLR_RT_TypeDef_Instance &inst); + bool CheckFieldDef(const CLR_RT_FieldDef_Index &fd, CLR_RT_FieldDef_Instance &inst); + bool CheckMethodDef(const CLR_RT_MethodDef_Index &md, CLR_RT_MethodDef_Instance &inst); - bool ProcessHeader ( WP_Message* msg ); - bool ProcessPayload ( WP_Message* msg ); + bool GetValue(WP_Message *msg, CLR_RT_HeapBlock *ptr, CLR_RT_HeapBlock *reference, CLR_RT_TypeDef_Instance *pTD); - -public: - static CLR_RT_Thread* GetThreadFromPid ( CLR_INT32 pid ); - - static bool Monitor_Ping ( WP_Message* msg ); - static bool Monitor_Reboot ( WP_Message* msg ); - static bool Debugging_Execution_QueryCLRCapabilities( WP_Message* msg ); - - static bool Monitor_ReadMemory ( WP_Message* msg ); - static bool Monitor_WriteMemory ( WP_Message* msg ); - static bool Monitor_CheckMemory ( WP_Message* msg ); - static bool Monitor_EraseMemory ( WP_Message* msg ); - static bool Monitor_Execute ( WP_Message* msg ); - static bool Monitor_MemoryMap ( WP_Message* msg ); - static bool Monitor_FlashSectorMap ( WP_Message* msg ); - static bool Monitor_DeploymentMap ( WP_Message* msg ); - static bool Monitor_QueryConfiguration ( WP_Message* msg ); - static bool Monitor_UpdateConfiguration ( WP_Message* msg ); - - - static bool Debugging_Execution_BasePtr ( WP_Message* msg ); - static bool Debugging_Execution_ChangeConditions ( WP_Message* msg ); - - static bool Debugging_Execution_Allocate ( WP_Message* msg ); - - static bool Debugging_UpgradeToSsl ( WP_Message* msg ); + bool AllocateAndQueueMessage( + CLR_UINT32 cmd, + unsigned int length, + unsigned char *data, + CLR_RT_HeapBlock_EndPoint::Port port, + CLR_RT_HeapBlock_EndPoint::Address addr, + CLR_UINT32 found); + bool ProcessHeader(WP_Message *msg); + bool ProcessPayload(WP_Message *msg); + public: + static CLR_RT_Thread *GetThreadFromPid(CLR_INT32 pid); + static bool Monitor_Ping(WP_Message *msg); + static bool Monitor_Reboot(WP_Message *msg); + static bool Debugging_Execution_QueryCLRCapabilities(WP_Message *msg); + static bool Monitor_ReadMemory(WP_Message *msg); + static bool Monitor_WriteMemory(WP_Message *msg); + static bool Monitor_CheckMemory(WP_Message *msg); + static bool Monitor_EraseMemory(WP_Message *msg); + static bool Monitor_Execute(WP_Message *msg); + static bool Monitor_MemoryMap(WP_Message *msg); + static bool Monitor_FlashSectorMap(WP_Message *msg); + static bool Monitor_DeploymentMap(WP_Message *msg); + static bool Monitor_QueryConfiguration(WP_Message *msg); + static bool Monitor_UpdateConfiguration(WP_Message *msg); + static bool Debugging_Execution_BasePtr(WP_Message *msg); + static bool Debugging_Execution_ChangeConditions(WP_Message *msg); + static bool Debugging_Execution_Allocate(WP_Message *msg); + static bool Debugging_UpgradeToSsl(WP_Message *msg); #if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) - static bool Debugging_Execution_Breakpoints ( WP_Message* msg ); - static bool Debugging_Execution_BreakpointStatus ( WP_Message* msg ); - static bool Debugging_Execution_SetCurrentAppDomain ( WP_Message* msg ); - - static bool Debugging_Thread_CreateEx ( WP_Message* msg ); - static bool Debugging_Thread_List ( WP_Message* msg ); - static bool Debugging_Thread_Stack ( WP_Message* msg ); - static bool Debugging_Thread_Kill ( WP_Message* msg ); - static bool Debugging_Thread_Suspend ( WP_Message* msg ); - static bool Debugging_Thread_Resume ( WP_Message* msg ); - static bool Debugging_Thread_GetException ( WP_Message* msg ); - static bool Debugging_Thread_Unwind ( WP_Message* msg ); - static bool Debugging_Thread_Get ( WP_Message* msg ); - - static bool Debugging_Stack_Info ( WP_Message* msg ); - static bool Debugging_Stack_SetIP ( WP_Message* msg ); - - static bool Debugging_Value_ResizeScratchPad ( WP_Message* msg ); - static bool Debugging_Value_GetStack ( WP_Message* msg ); - static bool Debugging_Value_GetField ( WP_Message* msg ); - static bool Debugging_Value_GetArray ( WP_Message* msg ); - static bool Debugging_Value_GetBlock ( WP_Message* msg ); - static bool Debugging_Value_GetScratchPad ( WP_Message* msg ); - static bool Debugging_Value_SetBlock ( WP_Message* msg ); - static bool Debugging_Value_SetArray ( WP_Message* msg ); - static bool Debugging_Value_AllocateObject ( WP_Message* msg ); - static bool Debugging_Value_AllocateString ( WP_Message* msg ); - static bool Debugging_Value_AllocateArray ( WP_Message* msg ); - static bool Debugging_Value_Assign ( WP_Message* msg ); - - static bool Debugging_TypeSys_Assemblies ( WP_Message* msg ); - static bool Debugging_TypeSys_AppDomains ( WP_Message* msg ); - - static bool Debugging_Resolve_AppDomain ( WP_Message* msg ); - static bool Debugging_Resolve_Assembly ( WP_Message* msg ); - static bool Debugging_Resolve_Type ( WP_Message* msg ); - static bool Debugging_Resolve_Field ( WP_Message* msg ); - static bool Debugging_Resolve_Method ( WP_Message* msg ); - static bool Debugging_Resolve_VirtualMethod ( WP_Message* msg ); + static bool Debugging_Execution_Breakpoints(WP_Message *msg); + static bool Debugging_Execution_BreakpointStatus(WP_Message *msg); + static bool Debugging_Execution_SetCurrentAppDomain(WP_Message *msg); + + static bool Debugging_Thread_CreateEx(WP_Message *msg); + static bool Debugging_Thread_List(WP_Message *msg); + static bool Debugging_Thread_Stack(WP_Message *msg); + static bool Debugging_Thread_Kill(WP_Message *msg); + static bool Debugging_Thread_Suspend(WP_Message *msg); + static bool Debugging_Thread_Resume(WP_Message *msg); + static bool Debugging_Thread_GetException(WP_Message *msg); + static bool Debugging_Thread_Unwind(WP_Message *msg); + static bool Debugging_Thread_Get(WP_Message *msg); + + static bool Debugging_Stack_Info(WP_Message *msg); + static bool Debugging_Stack_SetIP(WP_Message *msg); + + static bool Debugging_Value_ResizeScratchPad(WP_Message *msg); + static bool Debugging_Value_GetStack(WP_Message *msg); + static bool Debugging_Value_GetField(WP_Message *msg); + static bool Debugging_Value_GetArray(WP_Message *msg); + static bool Debugging_Value_GetBlock(WP_Message *msg); + static bool Debugging_Value_GetScratchPad(WP_Message *msg); + static bool Debugging_Value_SetBlock(WP_Message *msg); + static bool Debugging_Value_SetArray(WP_Message *msg); + static bool Debugging_Value_AllocateObject(WP_Message *msg); + static bool Debugging_Value_AllocateString(WP_Message *msg); + static bool Debugging_Value_AllocateArray(WP_Message *msg); + static bool Debugging_Value_Assign(WP_Message *msg); + + static bool Debugging_TypeSys_Assemblies(WP_Message *msg); + static bool Debugging_TypeSys_AppDomains(WP_Message *msg); + + static bool Debugging_Resolve_AppDomain(WP_Message *msg); + static bool Debugging_Resolve_Assembly(WP_Message *msg); + static bool Debugging_Resolve_Type(WP_Message *msg); + static bool Debugging_Resolve_Field(WP_Message *msg); + static bool Debugging_Resolve_Method(WP_Message *msg); + static bool Debugging_Resolve_VirtualMethod(WP_Message *msg); #endif //#if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) - static bool Debugging_Deployment_Status ( WP_Message* msg ); + static bool Debugging_Deployment_Status(WP_Message *msg); #if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) - static bool Debugging_Info_SetJMC ( WP_Message* msg ); - - bool Debugging_Info_SetJMC_Type ( const CLR_RT_TypeDef_Index& idx, bool fJMC ); - bool Debugging_Info_SetJMC_Method ( const CLR_RT_MethodDef_Index& idx, bool fJMC ); + static bool Debugging_Info_SetJMC(WP_Message *msg); + + bool Debugging_Info_SetJMC_Type(const CLR_RT_TypeDef_Index &idx, bool fJMC); + bool Debugging_Info_SetJMC_Method(const CLR_RT_MethodDef_Index &idx, bool fJMC); #endif //#if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) - static bool Profiling_Command ( WP_Message* msg ); - bool Profiling_ChangeConditions ( WP_Message* msg ); - bool Profiling_FlushStream ( WP_Message* msg ); + static bool Profiling_Command(WP_Message *msg); + bool Profiling_ChangeConditions(WP_Message *msg); + bool Profiling_FlushStream(WP_Message *msg); }; //--// -extern CLR_DBG_Debugger* g_CLR_DBG_Debugger; +extern CLR_DBG_Debugger *g_CLR_DBG_Debugger; //--// @@ -1166,4 +1070,3 @@ extern const CLR_UINT32 c_Debugger_Lookup_Reply_count; //--// #endif // _NANOCLR_DEBUGGING_H_ - diff --git a/src/CLR/Include/nanoCLR_ErrorCodes.h b/src/CLR/Include/nanoCLR_ErrorCodes.h index e757a622d0..0574e64a7d 100644 --- a/src/CLR/Include/nanoCLR_ErrorCodes.h +++ b/src/CLR/Include/nanoCLR_ErrorCodes.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Include/nanoCLR_Hardware.h b/src/CLR/Include/nanoCLR_Hardware.h index e902f233c6..43abf320fe 100644 --- a/src/CLR/Include/nanoCLR_Hardware.h +++ b/src/CLR/Include/nanoCLR_Hardware.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Include/nanoCLR_Interop.h b/src/CLR/Include/nanoCLR_Interop.h index ae4b5029cf..0bd6056be0 100644 --- a/src/CLR/Include/nanoCLR_Interop.h +++ b/src/CLR/Include/nanoCLR_Interop.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Include/nanoCLR_Messaging.h b/src/CLR/Include/nanoCLR_Messaging.h index 854e056ed5..8a5325a48a 100644 --- a/src/CLR/Include/nanoCLR_Messaging.h +++ b/src/CLR/Include/nanoCLR_Messaging.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Include/nanoCLR_ParseOptions.h b/src/CLR/Include/nanoCLR_ParseOptions.h index 497e0a1c0d..1cc195a945 100644 --- a/src/CLR/Include/nanoCLR_ParseOptions.h +++ b/src/CLR/Include/nanoCLR_ParseOptions.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Include/nanoCLR_PlatformDef.h b/src/CLR/Include/nanoCLR_PlatformDef.h index e3059cf15b..400783bcc6 100644 --- a/src/CLR/Include/nanoCLR_PlatformDef.h +++ b/src/CLR/Include/nanoCLR_PlatformDef.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Include/nanoCLR_Profiling.h b/src/CLR/Include/nanoCLR_Profiling.h index 4bcc9f0cec..26dea9cb63 100644 --- a/src/CLR/Include/nanoCLR_Profiling.h +++ b/src/CLR/Include/nanoCLR_Profiling.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Include/nanoCLR_Runtime.h b/src/CLR/Include/nanoCLR_Runtime.h index b935a5691f..5b04b538c4 100644 --- a/src/CLR/Include/nanoCLR_Runtime.h +++ b/src/CLR/Include/nanoCLR_Runtime.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // @@ -34,20 +34,20 @@ extern const CLR_RADIAN c_CLR_radians[]; #include #include -typedef std::set< std::wstring > CLR_RT_StringSet; -typedef CLR_RT_StringSet::iterator CLR_RT_StringSetIter; +typedef std::set CLR_RT_StringSet; +typedef CLR_RT_StringSet::iterator CLR_RT_StringSetIter; -typedef std::map< std::string,int > CLR_RT_StringMap; -typedef CLR_RT_StringMap::iterator CLR_RT_StringMapIter; +typedef std::map CLR_RT_StringMap; +typedef CLR_RT_StringMap::iterator CLR_RT_StringMapIter; -typedef std::vector< std::wstring > CLR_RT_StringVector; -typedef CLR_RT_StringVector::iterator CLR_RT_StringVectorIter; +typedef std::vector CLR_RT_StringVector; +typedef CLR_RT_StringVector::iterator CLR_RT_StringVectorIter; -typedef std::map< std::wstring, CLR_UINT32 > CLR_RT_SymbolToAddressMap; -typedef CLR_RT_SymbolToAddressMap::iterator CLR_RT_SymbolToAddressMapIter; +typedef std::map CLR_RT_SymbolToAddressMap; +typedef CLR_RT_SymbolToAddressMap::iterator CLR_RT_SymbolToAddressMapIter; -typedef std::map< CLR_UINT32, std::wstring > CLR_RT_AddressToSymbolMap; -typedef CLR_RT_AddressToSymbolMap::iterator CLR_RT_AddressToSymbolMapIter; +typedef std::map CLR_RT_AddressToSymbolMap; +typedef CLR_RT_AddressToSymbolMap::iterator CLR_RT_AddressToSymbolMapIter; #else @@ -65,9 +65,8 @@ typedef CLR_RT_AddressToSymbolMap::iterator CLR_RT_AddressToSymbolMapIter; #if defined(_WIN32) //--// -#define _COM_SMRT_PTR(i) typedef _com_ptr_t<_com_IIID> i ## Ptr -#define _COM_SMRT_PTR_2(i,u) typedef _com_ptr_t<_com_IIID> i ## Ptr - +#define _COM_SMRT_PTR(i) typedef _com_ptr_t<_com_IIID> i##Ptr +#define _COM_SMRT_PTR_2(i, u) typedef _com_ptr_t<_com_IIID> i##Ptr _COM_SMRT_PTR(IXMLDOMDocument); _COM_SMRT_PTR(IXMLDOMNode); @@ -76,117 +75,252 @@ class CLR_XmlUtil { IXMLDOMDocumentPtr m_xddDoc; IXMLDOMNodePtr m_xdnRoot; - HANDLE m_hEvent; // Used to abort a download. - unsigned long m_dwTimeout; // Used to limit a download. + HANDLE m_hEvent; // Used to abort a download. + unsigned long m_dwTimeout; // Used to limit a download. - void Init (); + void Init(); void Clean(); - HRESULT LoadPost( /*[in] */ const wchar_t* szRootTag , - /*[out]*/ bool& fLoaded , - /*[out]*/ bool* fFound ); + HRESULT LoadPost( + /*[in] */ const wchar_t *szRootTag, + /*[out]*/ bool &fLoaded, + /*[out]*/ bool *fFound); HRESULT CreateParser(); -public: - CLR_XmlUtil( /*[in]*/ const CLR_XmlUtil& xml ); - CLR_XmlUtil( /*[in]*/ IXMLDOMDocument* xddDoc , /*[in]*/ const wchar_t* szRootTag = NULL ); - CLR_XmlUtil( /*[in]*/ IXMLDOMNode* xdnRoot = NULL, /*[in]*/ const wchar_t* szRootTag = NULL ); + public: + CLR_XmlUtil(/*[in]*/ const CLR_XmlUtil &xml); + CLR_XmlUtil(/*[in]*/ IXMLDOMDocument *xddDoc, /*[in]*/ const wchar_t *szRootTag = NULL); + CLR_XmlUtil(/*[in]*/ IXMLDOMNode *xdnRoot = NULL, /*[in]*/ const wchar_t *szRootTag = NULL); ~CLR_XmlUtil(); - - CLR_XmlUtil& operator=( /*[in]*/ const CLR_XmlUtil& xml ); - CLR_XmlUtil& operator=( /*[in]*/ IXMLDOMNode* xdnRoot ); + CLR_XmlUtil &operator=(/*[in]*/ const CLR_XmlUtil &xml); + CLR_XmlUtil &operator=(/*[in]*/ IXMLDOMNode *xdnRoot); HRESULT DumpError(); - HRESULT New ( /*[in]*/ IXMLDOMNode* xdnRoot , /*[in] */ bool fDeep = false ); - HRESULT New ( /*[in]*/ const wchar_t* szRootTag, /*[in] */ const wchar_t* szEncoding = L"utf-8" /*L"unicode"*/ ); - HRESULT Load ( /*[in ]*/ const wchar_t* szFile , /*[in]*/ const wchar_t* szRootTag, /*[out]*/ bool& fLoaded, /*[out]*/ bool* fFound = NULL ); - HRESULT LoadAsStream( /*[in ]*/ IUnknown* pStream , /*[in]*/ const wchar_t* szRootTag, /*[out]*/ bool& fLoaded, /*[out]*/ bool* fFound = NULL ); - HRESULT LoadAsString( /*[in ]*/ BSTR bstrData, /*[in]*/ const wchar_t* szRootTag, /*[out]*/ bool& fLoaded, /*[out]*/ bool* fFound = NULL ); - HRESULT Save ( /*[in ]*/ const wchar_t* szFile ); - HRESULT SaveAsStream( /*[out]*/ IUnknown* *ppStream ); - HRESULT SaveAsString( /*[out]*/ BSTR *pbstrData ); - - HRESULT SetTimeout( /*[in]*/ unsigned long dwTimeout ); - HRESULT Abort ( ); - - HRESULT SetVersionAndEncoding( /*[in]*/ const wchar_t* szVersion, /*[in]*/ const wchar_t* szEncoding ); - - HRESULT GetDocument ( /*[out]*/ IXMLDOMDocument* * pVal ) const; - HRESULT GetRoot ( /*[out]*/ IXMLDOMNode* * pVal ) const; - HRESULT GetNodes ( /*[in]*/ const wchar_t* szTag, /*[out]*/ IXMLDOMNodeList* * pVal ) const; - HRESULT GetNode ( /*[in]*/ const wchar_t* szTag, /*[out]*/ IXMLDOMNode* * pVal ) const; - HRESULT CreateNode ( /*[in]*/ const wchar_t* szTag, /*[out]*/ IXMLDOMNode* * pVal, /*[in]*/ IXMLDOMNode* pxdnNode = NULL ); - - HRESULT GetAttribute ( /*[in]*/ const wchar_t* szTag, /*[in]*/ const wchar_t* szAttr, /*[out]*/ IXMLDOMAttribute* * pValue, /*[out]*/ bool& fFound, /*[in]*/ IXMLDOMNode* pxdnNode = NULL ); - HRESULT GetAttribute ( /*[in]*/ const wchar_t* szTag, /*[in]*/ const wchar_t* szAttr, /*[out]*/ _bstr_t& bstrValue, /*[out]*/ bool& fFound, /*[in]*/ IXMLDOMNode* pxdnNode = NULL ); - HRESULT GetAttribute ( /*[in]*/ const wchar_t* szTag, /*[in]*/ const wchar_t* szAttr, /*[out]*/ std::wstring& szValue, /*[out]*/ bool& fFound, /*[in]*/ IXMLDOMNode* pxdnNode = NULL ); - HRESULT GetAttribute ( /*[in]*/ const wchar_t* szTag, /*[in]*/ const wchar_t* szAttr, /*[out]*/ signed int& lValue, /*[out]*/ bool& fFound, /*[in]*/ IXMLDOMNode* pxdnNode = NULL ); - HRESULT GetValue ( /*[in]*/ const wchar_t* szTag, /*[out]*/ _variant_t& vValue, /*[out]*/ bool& fFound, /*[in]*/ IXMLDOMNode* pxdnNode = NULL ); - HRESULT GetValue ( /*[in]*/ const wchar_t* szTag, /*[out]*/ _bstr_t& bstrValue, /*[out]*/ bool& fFound, /*[in]*/ IXMLDOMNode* pxdnNode = NULL ); - HRESULT GetValue ( /*[in]*/ const wchar_t* szTag, /*[out]*/ std::wstring& szValue, /*[out]*/ bool& fFound, /*[in]*/ IXMLDOMNode* pxdnNode = NULL ); - - HRESULT ModifyAttribute( /*[in]*/ const wchar_t* szTag, /*[in]*/ const wchar_t* szAttr, /*[in] */ const _bstr_t& bstrValue, /*[out]*/ bool& fFound, /*[in]*/ IXMLDOMNode* pxdnNode = NULL ); - HRESULT ModifyAttribute( /*[in]*/ const wchar_t* szTag, /*[in]*/ const wchar_t* szAttr, /*[in] */ const std::wstring& szValue, /*[out]*/ bool& fFound, /*[in]*/ IXMLDOMNode* pxdnNode = NULL ); - HRESULT ModifyAttribute( /*[in]*/ const wchar_t* szTag, /*[in]*/ const wchar_t* szAttr, /*[in] */ const wchar_t* szValue, /*[out]*/ bool& fFound, /*[in]*/ IXMLDOMNode* pxdnNode = NULL ); - HRESULT ModifyAttribute( /*[in]*/ const wchar_t* szTag, /*[in]*/ const wchar_t* szAttr, /*[in] */ signed int lValue, /*[out]*/ bool& fFound, /*[in]*/ IXMLDOMNode* pxdnNode = NULL ); - HRESULT ModifyValue ( /*[in]*/ const wchar_t* szTag, /*[in] */ const _variant_t& vValue, /*[out]*/ bool& fFound, /*[in]*/ IXMLDOMNode* pxdnNode = NULL ); - HRESULT ModifyValue ( /*[in]*/ const wchar_t* szTag, /*[in] */ const _bstr_t& bstrValue, /*[out]*/ bool& fFound, /*[in]*/ IXMLDOMNode* pxdnNode = NULL ); - HRESULT ModifyValue ( /*[in]*/ const wchar_t* szTag, /*[in] */ const std::wstring& szValue, /*[out]*/ bool& fFound, /*[in]*/ IXMLDOMNode* pxdnNode = NULL ); - - HRESULT PutAttribute ( /*[in]*/ const wchar_t* szTag, /*[in]*/ const wchar_t* szAttr, /*[in] */ IXMLDOMAttribute* * pValue, /*[out]*/ bool& fFound, /*[in]*/ IXMLDOMNode* pxdnNode = NULL ); - HRESULT PutAttribute ( /*[in]*/ const wchar_t* szTag, /*[in]*/ const wchar_t* szAttr, /*[in] */ const _bstr_t& bstrValue, /*[out]*/ bool& fFound, /*[in]*/ IXMLDOMNode* pxdnNode = NULL ); - HRESULT PutAttribute ( /*[in]*/ const wchar_t* szTag, /*[in]*/ const wchar_t* szAttr, /*[in] */ const std::wstring& szValue, /*[out]*/ bool& fFound, /*[in]*/ IXMLDOMNode* pxdnNode = NULL ); - HRESULT PutAttribute ( /*[in]*/ const wchar_t* szTag, /*[in]*/ const wchar_t* szAttr, /*[in] */ const wchar_t* szValue, /*[out]*/ bool& fFound, /*[in]*/ IXMLDOMNode* pxdnNode = NULL ); - HRESULT PutAttribute ( /*[in]*/ const wchar_t* szTag, /*[in]*/ const wchar_t* szAttr, /*[in] */ signed int lValue, /*[out]*/ bool& fFound, /*[in]*/ IXMLDOMNode* pxdnNode = NULL ); - HRESULT PutValue ( /*[in]*/ const wchar_t* szTag, /*[in] */ const _variant_t& vValue, /*[out]*/ bool& fFound, /*[in]*/ IXMLDOMNode* pxdnNode = NULL ); - HRESULT PutValue ( /*[in]*/ const wchar_t* szTag, /*[in] */ const _bstr_t& bstrValue, /*[out]*/ bool& fFound, /*[in]*/ IXMLDOMNode* pxdnNode = NULL ); - HRESULT PutValue ( /*[in]*/ const wchar_t* szTag, /*[in] */ const std::wstring& szValue, /*[out]*/ bool& fFound, /*[in]*/ IXMLDOMNode* pxdnNode = NULL ); - HRESULT PutValue ( /*[in]*/ const wchar_t* szTag, /*[in] */ const wchar_t* szValue, /*[out]*/ bool& fFound, /*[in]*/ IXMLDOMNode* pxdnNode = NULL ); - - HRESULT RemoveAttribute( /*[in]*/ const wchar_t* szTag, /*[in]*/ const wchar_t* szAttr, /*[in]*/ IXMLDOMNode* pxdnNode = NULL ); - HRESULT RemoveValue ( /*[in]*/ const wchar_t* szTag, /*[in]*/ IXMLDOMNode* pxdnNode = NULL ); - HRESULT RemoveNode ( /*[in]*/ const wchar_t* szTag, /*[in]*/ IXMLDOMNode* pxdnNode = NULL ); + HRESULT New(/*[in]*/ IXMLDOMNode *xdnRoot, /*[in] */ bool fDeep = false); + HRESULT New(/*[in]*/ const wchar_t *szRootTag, /*[in] */ const wchar_t *szEncoding = L"utf-8" /*L"unicode"*/); + HRESULT Load( + /*[in ]*/ const wchar_t *szFile, + /*[in]*/ const wchar_t *szRootTag, + /*[out]*/ bool &fLoaded, + /*[out]*/ bool *fFound = NULL); + HRESULT LoadAsStream( + /*[in ]*/ IUnknown *pStream, + /*[in]*/ const wchar_t *szRootTag, + /*[out]*/ bool &fLoaded, + /*[out]*/ bool *fFound = NULL); + HRESULT LoadAsString( + /*[in ]*/ BSTR bstrData, + /*[in]*/ const wchar_t *szRootTag, + /*[out]*/ bool &fLoaded, + /*[out]*/ bool *fFound = NULL); + HRESULT Save(/*[in ]*/ const wchar_t *szFile); + HRESULT SaveAsStream(/*[out]*/ IUnknown **ppStream); + HRESULT SaveAsString(/*[out]*/ BSTR *pbstrData); + + HRESULT SetTimeout(/*[in]*/ unsigned long dwTimeout); + HRESULT Abort(); + + HRESULT SetVersionAndEncoding(/*[in]*/ const wchar_t *szVersion, /*[in]*/ const wchar_t *szEncoding); + + HRESULT GetDocument(/*[out]*/ IXMLDOMDocument **pVal) const; + HRESULT GetRoot(/*[out]*/ IXMLDOMNode **pVal) const; + HRESULT GetNodes(/*[in]*/ const wchar_t *szTag, /*[out]*/ IXMLDOMNodeList **pVal) const; + HRESULT GetNode(/*[in]*/ const wchar_t *szTag, /*[out]*/ IXMLDOMNode **pVal) const; + HRESULT CreateNode( + /*[in]*/ const wchar_t *szTag, + /*[out]*/ IXMLDOMNode **pVal, + /*[in]*/ IXMLDOMNode *pxdnNode = NULL); + + HRESULT GetAttribute( + /*[in]*/ const wchar_t *szTag, + /*[in]*/ const wchar_t *szAttr, + /*[out]*/ IXMLDOMAttribute **pValue, + /*[out]*/ bool &fFound, + /*[in]*/ IXMLDOMNode *pxdnNode = NULL); + HRESULT GetAttribute( + /*[in]*/ const wchar_t *szTag, + /*[in]*/ const wchar_t *szAttr, + /*[out]*/ _bstr_t &bstrValue, + /*[out]*/ bool &fFound, + /*[in]*/ IXMLDOMNode *pxdnNode = NULL); + HRESULT GetAttribute( + /*[in]*/ const wchar_t *szTag, + /*[in]*/ const wchar_t *szAttr, + /*[out]*/ std::wstring &szValue, + /*[out]*/ bool &fFound, + /*[in]*/ IXMLDOMNode *pxdnNode = NULL); + HRESULT GetAttribute( + /*[in]*/ const wchar_t *szTag, + /*[in]*/ const wchar_t *szAttr, + /*[out]*/ signed int &lValue, + /*[out]*/ bool &fFound, + /*[in]*/ IXMLDOMNode *pxdnNode = NULL); + HRESULT GetValue( + /*[in]*/ const wchar_t *szTag, + /*[out]*/ _variant_t &vValue, + /*[out]*/ bool &fFound, + /*[in]*/ IXMLDOMNode *pxdnNode = NULL); + HRESULT GetValue( + /*[in]*/ const wchar_t *szTag, + /*[out]*/ _bstr_t &bstrValue, + /*[out]*/ bool &fFound, + /*[in]*/ IXMLDOMNode *pxdnNode = NULL); + HRESULT GetValue( + /*[in]*/ const wchar_t *szTag, + /*[out]*/ std::wstring &szValue, + /*[out]*/ bool &fFound, + /*[in]*/ IXMLDOMNode *pxdnNode = NULL); + + HRESULT ModifyAttribute( + /*[in]*/ const wchar_t *szTag, + /*[in]*/ const wchar_t *szAttr, + /*[in] */ const _bstr_t &bstrValue, + /*[out]*/ bool &fFound, + /*[in]*/ IXMLDOMNode *pxdnNode = NULL); + HRESULT ModifyAttribute( + /*[in]*/ const wchar_t *szTag, + /*[in]*/ const wchar_t *szAttr, + /*[in] */ const std::wstring &szValue, + /*[out]*/ bool &fFound, + /*[in]*/ IXMLDOMNode *pxdnNode = NULL); + HRESULT ModifyAttribute( + /*[in]*/ const wchar_t *szTag, + /*[in]*/ const wchar_t *szAttr, + /*[in] */ const wchar_t *szValue, + /*[out]*/ bool &fFound, + /*[in]*/ IXMLDOMNode *pxdnNode = NULL); + HRESULT ModifyAttribute( + /*[in]*/ const wchar_t *szTag, + /*[in]*/ const wchar_t *szAttr, + /*[in] */ signed int lValue, + /*[out]*/ bool &fFound, + /*[in]*/ IXMLDOMNode *pxdnNode = NULL); + HRESULT ModifyValue( + /*[in]*/ const wchar_t *szTag, + /*[in] */ const _variant_t &vValue, + /*[out]*/ bool &fFound, + /*[in]*/ IXMLDOMNode *pxdnNode = NULL); + HRESULT ModifyValue( + /*[in]*/ const wchar_t *szTag, + /*[in] */ const _bstr_t &bstrValue, + /*[out]*/ bool &fFound, + /*[in]*/ IXMLDOMNode *pxdnNode = NULL); + HRESULT ModifyValue( + /*[in]*/ const wchar_t *szTag, + /*[in] */ const std::wstring &szValue, + /*[out]*/ bool &fFound, + /*[in]*/ IXMLDOMNode *pxdnNode = NULL); + + HRESULT PutAttribute( + /*[in]*/ const wchar_t *szTag, + /*[in]*/ const wchar_t *szAttr, + /*[in] */ IXMLDOMAttribute **pValue, + /*[out]*/ bool &fFound, + /*[in]*/ IXMLDOMNode *pxdnNode = NULL); + HRESULT PutAttribute( + /*[in]*/ const wchar_t *szTag, + /*[in]*/ const wchar_t *szAttr, + /*[in] */ const _bstr_t &bstrValue, + /*[out]*/ bool &fFound, + /*[in]*/ IXMLDOMNode *pxdnNode = NULL); + HRESULT PutAttribute( + /*[in]*/ const wchar_t *szTag, + /*[in]*/ const wchar_t *szAttr, + /*[in] */ const std::wstring &szValue, + /*[out]*/ bool &fFound, + /*[in]*/ IXMLDOMNode *pxdnNode = NULL); + HRESULT PutAttribute( + /*[in]*/ const wchar_t *szTag, + /*[in]*/ const wchar_t *szAttr, + /*[in] */ const wchar_t *szValue, + /*[out]*/ bool &fFound, + /*[in]*/ IXMLDOMNode *pxdnNode = NULL); + HRESULT PutAttribute( + /*[in]*/ const wchar_t *szTag, + /*[in]*/ const wchar_t *szAttr, + /*[in] */ signed int lValue, + /*[out]*/ bool &fFound, + /*[in]*/ IXMLDOMNode *pxdnNode = NULL); + HRESULT PutValue( + /*[in]*/ const wchar_t *szTag, + /*[in] */ const _variant_t &vValue, + /*[out]*/ bool &fFound, + /*[in]*/ IXMLDOMNode *pxdnNode = NULL); + HRESULT PutValue( + /*[in]*/ const wchar_t *szTag, + /*[in] */ const _bstr_t &bstrValue, + /*[out]*/ bool &fFound, + /*[in]*/ IXMLDOMNode *pxdnNode = NULL); + HRESULT PutValue( + /*[in]*/ const wchar_t *szTag, + /*[in] */ const std::wstring &szValue, + /*[out]*/ bool &fFound, + /*[in]*/ IXMLDOMNode *pxdnNode = NULL); + HRESULT PutValue( + /*[in]*/ const wchar_t *szTag, + /*[in] */ const wchar_t *szValue, + /*[out]*/ bool &fFound, + /*[in]*/ IXMLDOMNode *pxdnNode = NULL); + + HRESULT RemoveAttribute( + /*[in]*/ const wchar_t *szTag, + /*[in]*/ const wchar_t *szAttr, + /*[in]*/ IXMLDOMNode *pxdnNode = NULL); + HRESULT RemoveValue(/*[in]*/ const wchar_t *szTag, /*[in]*/ IXMLDOMNode *pxdnNode = NULL); + HRESULT RemoveNode(/*[in]*/ const wchar_t *szTag, /*[in]*/ IXMLDOMNode *pxdnNode = NULL); }; //--// - -typedef std::vector< CLR_UINT8 > CLR_RT_Buffer; +typedef std::vector CLR_RT_Buffer; struct CLR_RT_FileStore { - static HRESULT LoadFile( const wchar_t* szFile, CLR_RT_Buffer& vec ); - static HRESULT SaveFile( const wchar_t* szFile, const CLR_RT_Buffer& vec ); - static HRESULT SaveFile( const wchar_t* szFile, const CLR_UINT8* buf, size_t size ); - - static HRESULT ExtractTokensFromFile( const wchar_t* szFileName, CLR_RT_StringVector& vec, const wchar_t* separators = L" \t", bool fNoComments = true ); - - static void ExtractTokens ( const CLR_RT_Buffer& buf , CLR_RT_StringVector& vec, const wchar_t* separators = L" \t", bool fNoComments = true ); - static void ExtractTokensFromBuffer( wchar_t* szLine, CLR_RT_StringVector& vec, const wchar_t* separators = L" \t", bool fNoComments = true ); - static void ExtractTokensFromString( const wchar_t* szLine, CLR_RT_StringVector& vec, const wchar_t* separators = L" \t" ); + static HRESULT LoadFile(const wchar_t *szFile, CLR_RT_Buffer &vec); + static HRESULT SaveFile(const wchar_t *szFile, const CLR_RT_Buffer &vec); + static HRESULT SaveFile(const wchar_t *szFile, const CLR_UINT8 *buf, size_t size); + + static HRESULT ExtractTokensFromFile( + const wchar_t *szFileName, + CLR_RT_StringVector &vec, + const wchar_t *separators = L" \t", + bool fNoComments = true); + + static void ExtractTokens( + const CLR_RT_Buffer &buf, + CLR_RT_StringVector &vec, + const wchar_t *separators = L" \t", + bool fNoComments = true); + static void ExtractTokensFromBuffer( + wchar_t *szLine, + CLR_RT_StringVector &vec, + const wchar_t *separators = L" \t", + bool fNoComments = true); + static void ExtractTokensFromString( + const wchar_t *szLine, + CLR_RT_StringVector &vec, + const wchar_t *separators = L" \t"); }; #endif - //////////////////////////////////////////////////////////////////////////////////////////////////// #if !defined(MAX) -#define MAX(a,b) (a > b ? a : b) +#define MAX(a, b) (a > b ? a : b) #endif #if !defined(MIN) -#define MIN(a,b) (a < b ? a : b) +#define MIN(a, b) (a < b ? a : b) #endif -#define ABS(x) (x > 0 ? x : (-x)) +#define ABS(x) (x > 0 ? x : (-x)) #define FLOOR32(x) ((CLR_INT32)x) #define FRAC(x) (x - FLOOR32(x)) //////////////////////////////////////////////////////////////////////////////////////////////////// - struct CLR_RT_HeapBlock; struct CLR_RT_HeapBlock_Node; @@ -213,7 +347,7 @@ struct CLR_RT_DblLinkedList; #if defined(NANOCLR_APPDOMAINS) struct CLR_RT_AppDomain; struct CLR_RT_AppDomainAssembly; -#endif //NANOCLR_APPDOMAINS +#endif // NANOCLR_APPDOMAINS struct CLR_RT_Assembly; struct CLR_RT_TypeSystem; @@ -234,10 +368,9 @@ struct CLR_RT_ExecutionEngine_PerfCounters; struct CLR_HW_Hardware; -typedef void (*CLR_RT_MarkingHandler )( CLR_RT_HeapBlock_BinaryBlob* ptr ); -typedef void (*CLR_RT_RelocationHandler)( CLR_RT_HeapBlock_BinaryBlob* ptr ); -typedef void (*CLR_RT_HardwareHandler )(); - +typedef void (*CLR_RT_MarkingHandler)(CLR_RT_HeapBlock_BinaryBlob *ptr); +typedef void (*CLR_RT_RelocationHandler)(CLR_RT_HeapBlock_BinaryBlob *ptr); +typedef void (*CLR_RT_HardwareHandler)(); //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -253,18 +386,17 @@ struct CLR_PROF_Handler; struct CLR_PROF_CounterCallChain { - CLR_UINT64 m_time_exclusive; - CLR_RT_StackFrame* m_owningStackFrame; - CLR_PROF_Handler* m_owningHandler; - + CLR_UINT64 m_time_exclusive; + CLR_RT_StackFrame *m_owningStackFrame; + CLR_PROF_Handler *m_owningHandler; //--// - void* Prepare ( CLR_PROF_Handler* handler ); - void Complete( CLR_UINT64& t, CLR_PROF_Handler* handler ); + void *Prepare(CLR_PROF_Handler *handler); + void Complete(CLR_UINT64 &t, CLR_PROF_Handler *handler); - void Enter( CLR_RT_StackFrame* stack ); - void Leave( ); + void Enter(CLR_RT_StackFrame *stack); + void Leave(); //--// @@ -276,55 +408,64 @@ struct CLR_PROF_CounterCallChain struct CLR_PROF_Handler { - static const int c_Mode_Ignore = 0; - static const int c_Mode_Plain = 1; - static const int c_Mode_Simple = 2; + static const int c_Mode_Ignore = 0; + static const int c_Mode_Plain = 1; + static const int c_Mode_Simple = 2; #if defined(NANOCLR_PROFILE_NEW_CALLS) static const int c_Mode_CallChain = 3; #endif - static bool s_initialized; - static CLR_PROF_Handler* s_current; - static volatile CLR_UINT64 s_time_overhead; - static volatile CLR_UINT64 s_time_freeze; - static volatile CLR_UINT64 s_time_adjusted; + static bool s_initialized; + static CLR_PROF_Handler *s_current; + static volatile CLR_UINT64 s_time_overhead; + static volatile CLR_UINT64 s_time_freeze; + static volatile CLR_UINT64 s_time_adjusted; - int m_target_Mode; - void* m_target; + int m_target_Mode; + void *m_target; - CLR_PROF_Handler* m_containing; - CLR_UINT64 m_time_correction; - CLR_UINT64 m_time_start; + CLR_PROF_Handler *m_containing; + CLR_UINT64 m_time_correction; + CLR_UINT64 m_time_start; //--// - CLR_PROF_Handler( ) { Constructor( ); } + CLR_PROF_Handler() + { + Constructor(); + } #if defined(NANOCLR_PROFILE_NEW_CALLS) - CLR_PROF_Handler( CLR_PROF_CounterCallChain& target ) { Constructor( target ); } + CLR_PROF_Handler(CLR_PROF_CounterCallChain &target) + { + Constructor(target); + } #endif - ~CLR_PROF_Handler() { Destructor(); } + ~CLR_PROF_Handler() + { + Destructor(); + } //--// - static void Calibrate ( ); - static void SuspendTime ( ); - static CLR_UINT64 GetFrozenTime( ); - static CLR_UINT64 ResumeTime ( ); - static CLR_UINT64 ResumeTime ( CLR_INT64 t ); + static void Calibrate(); + static void SuspendTime(); + static CLR_UINT64 GetFrozenTime(); + static CLR_UINT64 ResumeTime(); + static CLR_UINT64 ResumeTime(CLR_INT64 t); //--// -private: - void Constructor( ); + private: + void Constructor(); #if defined(NANOCLR_PROFILE_NEW_CALLS) - void Constructor( CLR_PROF_CounterCallChain& target ); + void Constructor(CLR_PROF_CounterCallChain &target); #endif - void Destructor(); + void Destructor(); - void Init( void* target ); + void Init(void *target); PROHIBIT_COPY_CONSTRUCTORS2(CLR_PROF_Handler); }; @@ -344,12 +485,12 @@ struct CLR_PROF_Handler #if defined(NANOCLR_PROFILE_NEW_CALLS) #define CLR_PROF_HANDLER_CALLCHAIN_VOID(v) CLR_PROF_Handler v -#define CLR_PROF_HANDLER_CALLCHAIN(v,t) CLR_PROF_Handler v( t ) +#define CLR_PROF_HANDLER_CALLCHAIN(v, t) CLR_PROF_Handler v(t) #else #define CLR_PROF_HANDLER_CALLCHAIN_VOID(v) -#define CLR_PROF_HANDLER_CALLCHAIN(v,t) +#define CLR_PROF_HANDLER_CALLCHAIN(v, t) #endif @@ -357,10 +498,10 @@ struct CLR_PROF_Handler struct CLR_RT_MemoryRange { - unsigned char* m_location; + unsigned char *m_location; unsigned int m_size; - bool LimitToRange( CLR_RT_MemoryRange& filtered, unsigned char* address, unsigned int length ) const; + bool LimitToRange(CLR_RT_MemoryRange &filtered, unsigned char *address, unsigned int length) const; }; extern CLR_RT_MemoryRange s_CLR_RT_Heap; @@ -369,77 +510,85 @@ extern CLR_RT_MemoryRange s_CLR_RT_Heap; struct CLR_RT_Memory { - static void ZeroFill( void* buf, size_t len ) { memset( buf, 0, len ); } + static void ZeroFill(void *buf, size_t len) + { + memset(buf, 0, len); + } //--// - static void Reset ( ); - static void* SubtractFromSystem( size_t len ); - static void Release ( void* ptr ); - static void* Allocate ( size_t len, CLR_UINT32 flags = 0 ); - static void* ReAllocate ( void* ptr, size_t len ); - static void* Allocate_And_Erase( size_t len, CLR_UINT32 flags = 0 ); + static void Reset(); + static void *SubtractFromSystem(size_t len); + static void Release(void *ptr); + static void *Allocate(size_t len, CLR_UINT32 flags = 0); + static void *ReAllocate(void *ptr, size_t len); + static void *Allocate_And_Erase(size_t len, CLR_UINT32 flags = 0); }; //--// struct CLR_RT_Random { -public: - void Initialize(); - void Initialize( int seed ); + public: + void Initialize(); + void Initialize(int seed); - uint32_t Next(); + uint32_t Next(); #if !defined(NANOCLR_EMULATED_FLOATINGPOINT) - double NextDouble(); + double NextDouble(); #else - CLR_INT64 NextDouble(); + CLR_INT64 NextDouble(); #endif - void NextBytes( unsigned char* buffer, unsigned int count ); + void NextBytes(unsigned char *buffer, unsigned int count); }; //--// -extern void CLR_RT_GetVersion( unsigned short int* pMajor, unsigned short int* pMinor, unsigned short int* pBuild, unsigned short int* pRevision ); +extern void CLR_RT_GetVersion( + unsigned short int *pMajor, + unsigned short int *pMinor, + unsigned short int *pBuild, + unsigned short int *pRevision); -#define NANOCLR_CLEAR(ref) CLR_RT_Memory::ZeroFill( &ref, sizeof(ref) ) +#define NANOCLR_CLEAR(ref) CLR_RT_Memory::ZeroFill(&ref, sizeof(ref)) //--// -static const int c_CLR_RT_Trace_None = 0; -static const int c_CLR_RT_Trace_Info = 1; -static const int c_CLR_RT_Trace_Verbose = 2; -static const int c_CLR_RT_Trace_Annoying = 3; +static const int c_CLR_RT_Trace_None = 0; +static const int c_CLR_RT_Trace_Info = 1; +static const int c_CLR_RT_Trace_Verbose = 2; +static const int c_CLR_RT_Trace_Annoying = 3; static const int c_CLR_RT_Trace_Obnoxious = 4; -extern int s_CLR_RT_fTrace_Errors; -extern int s_CLR_RT_fTrace_Exceptions; -extern int s_CLR_RT_fTrace_Instructions; -extern int s_CLR_RT_fTrace_Memory; -extern int s_CLR_RT_fTrace_MemoryStats; -extern int s_CLR_RT_fTrace_StopOnFAILED; -extern int s_CLR_RT_fTrace_GC; -extern int s_CLR_RT_fTrace_GC_Depth; -extern int s_CLR_RT_fTrace_SimulateSpeed; -extern int s_CLR_RT_fTrace_AssemblyOverhead; +extern int s_CLR_RT_fTrace_Errors; +extern int s_CLR_RT_fTrace_Exceptions; +extern int s_CLR_RT_fTrace_Instructions; +extern int s_CLR_RT_fTrace_Memory; +extern int s_CLR_RT_fTrace_MemoryStats; +extern int s_CLR_RT_fTrace_StopOnFAILED; +extern int s_CLR_RT_fTrace_GC; +extern int s_CLR_RT_fTrace_GC_Depth; +extern int s_CLR_RT_fTrace_SimulateSpeed; +extern int s_CLR_RT_fTrace_AssemblyOverhead; #if defined(_WIN32) -extern int s_CLR_RT_fTrace_ARM_Execution; +extern int s_CLR_RT_fTrace_ARM_Execution; -extern int s_CLR_RT_fTrace_RedirectLinesPerFile; +extern int s_CLR_RT_fTrace_RedirectLinesPerFile; extern std::wstring s_CLR_RT_fTrace_RedirectOutput; extern std::wstring s_CLR_RT_fTrace_RedirectCallChain; extern std::wstring s_CLR_RT_fTrace_HeapDump_FilePrefix; -extern bool s_CLR_RT_fTrace_HeapDump_IncludeCreators; +extern bool s_CLR_RT_fTrace_HeapDump_IncludeCreators; -extern bool s_CLR_RT_fTimeWarp; +extern bool s_CLR_RT_fTimeWarp; #endif -static const int MAXHOSTNAMELEN = 256; // Typical of many sockets implementations, incl. Windows -static const int MAXTYPENAMELEN = 256; // Including terminating null byte. Enforced in MetadataProcessor. The standard imposes no limit, but we necessarily do. +static const int MAXHOSTNAMELEN = 256; // Typical of many sockets implementations, incl. Windows +static const int MAXTYPENAMELEN = 256; // Including terminating null byte. Enforced in MetadataProcessor. The standard + // imposes no limit, but we necessarily do. //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -449,7 +598,8 @@ static const int MAXTYPENAMELEN = 256; // Including terminating null byte. Enfo // // IMPORTANT: THE ASSEMBLY IDX IN ALL THE CLR_RT_*_Index STRUCTURES SHOULD ALWAYS BE ENCODED THE SAME WAY!!! // -// For details, go to "bool CLR_RT_GarbageCollector::ComputeReachabilityGraphForMultipleBlocks( CLR_RT_HeapBlock* lstExt, CLR_UINT32 numExt )" +// For details, go to "bool CLR_RT_GarbageCollector::ComputeReachabilityGraphForMultipleBlocks( CLR_RT_HeapBlock* +// lstExt, CLR_UINT32 numExt )" // struct CLR_RT_Assembly_Index @@ -463,14 +613,17 @@ struct CLR_RT_Assembly_Index m_data = 0; } - void Set( CLR_UINT32 idxAssm ) + void Set(CLR_UINT32 idxAssm) { m_data = idxAssm << 16; } //--// - CLR_IDX Assembly() const { return (CLR_IDX)(m_data >> 16); } + CLR_IDX Assembly() const + { + return (CLR_IDX)(m_data >> 16); + } }; struct CLR_RT_TypeSpec_Index @@ -484,15 +637,21 @@ struct CLR_RT_TypeSpec_Index m_data = 0; } - void Set( CLR_UINT32 idxAssm, CLR_UINT32 idxType ) + void Set(CLR_UINT32 idxAssm, CLR_UINT32 idxType) { m_data = idxAssm << 16 | idxType; } //--// - CLR_IDX Assembly() const { return (CLR_IDX)(m_data >> 16); } - CLR_IDX TypeSpec() const { return (CLR_IDX)(m_data ); } + CLR_IDX Assembly() const + { + return (CLR_IDX)(m_data >> 16); + } + CLR_IDX TypeSpec() const + { + return (CLR_IDX)(m_data); + } }; struct CLR_RT_TypeDef_Index @@ -506,15 +665,21 @@ struct CLR_RT_TypeDef_Index m_data = 0; } - void Set( CLR_UINT32 idxAssm, CLR_UINT32 idxType ) + void Set(CLR_UINT32 idxAssm, CLR_UINT32 idxType) { m_data = idxAssm << 16 | idxType; } //--// - CLR_IDX Assembly() const { return (CLR_IDX)(m_data >> 16); } - CLR_IDX Type () const { return (CLR_IDX)(m_data ); } + CLR_IDX Assembly() const + { + return (CLR_IDX)(m_data >> 16); + } + CLR_IDX Type() const + { + return (CLR_IDX)(m_data); + } }; struct CLR_RT_FieldDef_Index @@ -528,15 +693,21 @@ struct CLR_RT_FieldDef_Index m_data = 0; } - void Set( CLR_UINT32 idxAssm, CLR_UINT32 idxField ) + void Set(CLR_UINT32 idxAssm, CLR_UINT32 idxField) { m_data = idxAssm << 16 | idxField; } //--// - CLR_IDX Assembly() const { return (CLR_IDX)(m_data >> 16); } - CLR_IDX Field () const { return (CLR_IDX)(m_data ); } + CLR_IDX Assembly() const + { + return (CLR_IDX)(m_data >> 16); + } + CLR_IDX Field() const + { + return (CLR_IDX)(m_data); + } }; struct CLR_RT_MethodDef_Index @@ -550,29 +721,34 @@ struct CLR_RT_MethodDef_Index m_data = 0; } - void Set( CLR_UINT32 idxAssm, CLR_UINT32 idxMethod ) + void Set(CLR_UINT32 idxAssm, CLR_UINT32 idxMethod) { m_data = idxAssm << 16 | idxMethod; } //--// - CLR_IDX Assembly() const { return (CLR_IDX)(m_data >> 16); } - CLR_IDX Method () const { return (CLR_IDX)(m_data ); } + CLR_IDX Assembly() const + { + return (CLR_IDX)(m_data >> 16); + } + CLR_IDX Method() const + { + return (CLR_IDX)(m_data); + } }; struct CLR_RT_ReflectionDef_Index { - CLR_UINT16 m_kind; // CLR_ReflectionType + CLR_UINT16 m_kind; // CLR_ReflectionType CLR_UINT16 m_levels; - union - { - CLR_RT_Assembly_Index m_assm; - CLR_RT_TypeDef_Index m_type; + union { + CLR_RT_Assembly_Index m_assm; + CLR_RT_TypeDef_Index m_type; CLR_RT_MethodDef_Index m_method; - CLR_RT_FieldDef_Index m_field; - CLR_UINT32 m_raw; + CLR_RT_FieldDef_Index m_field; + CLR_UINT32 m_raw; } m_data; //--// @@ -581,26 +757,25 @@ struct CLR_RT_ReflectionDef_Index CLR_UINT32 GetTypeHash() const; - void InitializeFromHash( CLR_UINT32 hash ); + void InitializeFromHash(CLR_UINT32 hash); - CLR_UINT64 GetRawData( ) const; - void SetRawData( CLR_UINT64 data ); + CLR_UINT64 GetRawData() const; + void SetRawData(CLR_UINT64 data); //--// - static bool Convert( CLR_RT_HeapBlock& ref, CLR_RT_Assembly_Instance& inst ); - static bool Convert( CLR_RT_HeapBlock& ref, CLR_RT_TypeDef_Instance& inst, CLR_UINT32* levels ); - static bool Convert( CLR_RT_HeapBlock& ref, CLR_RT_MethodDef_Instance& inst ); - static bool Convert( CLR_RT_HeapBlock& ref, CLR_RT_FieldDef_Instance& inst ); - static bool Convert( CLR_RT_HeapBlock& ref, CLR_UINT32& hash ); + static bool Convert(CLR_RT_HeapBlock &ref, CLR_RT_Assembly_Instance &inst); + static bool Convert(CLR_RT_HeapBlock &ref, CLR_RT_TypeDef_Instance &inst, CLR_UINT32 *levels); + static bool Convert(CLR_RT_HeapBlock &ref, CLR_RT_MethodDef_Instance &inst); + static bool Convert(CLR_RT_HeapBlock &ref, CLR_RT_FieldDef_Instance &inst); + static bool Convert(CLR_RT_HeapBlock &ref, CLR_UINT32 &hash); }; - //--// struct CLR_RT_AssemblyRef_CrossReference { - CLR_RT_Assembly* m_target; // EVENT HEAP - NO RELOCATION - + CLR_RT_Assembly *m_target; // EVENT HEAP - NO RELOCATION - }; struct CLR_RT_TypeRef_CrossReference @@ -626,22 +801,25 @@ struct CLR_RT_FieldDef_CrossReference struct CLR_RT_TypeDef_CrossReference { static const CLR_UINT32 TD_CR_StaticConstructorCalled = 0x0001; - static const CLR_UINT32 TD_CR_HasFinalizer = 0x0002; - static const CLR_UINT32 TD_CR_IsMarshalByRefObject = 0x0004; + static const CLR_UINT32 TD_CR_HasFinalizer = 0x0002; + static const CLR_UINT32 TD_CR_IsMarshalByRefObject = 0x0004; CLR_UINT16 m_flags; - CLR_IDX m_totalFields; + CLR_IDX m_totalFields; CLR_UINT32 m_hash; }; struct CLR_RT_MethodDef_CrossReference { - static const CLR_UINT16 MD_CR_Patched = 0x8000; + static const CLR_UINT16 MD_CR_Patched = 0x8000; static const CLR_UINT16 MD_CR_OwnerMask = 0x7FFF; CLR_UINT16 m_data; - CLR_IDX GetOwner () const { return (CLR_IDX)(m_data); } + CLR_IDX GetOwner() const + { + return (CLR_IDX)(m_data); + } }; struct CLR_RT_MethodDef_Patch @@ -654,35 +832,61 @@ struct CLR_RT_MethodDef_Patch struct CLR_RT_MethodDef_DebuggingInfo { - static const CLR_UINT8 MD_DI_JustMyCode = 0x01; - static const CLR_UINT8 MD_DI_HasBreakpoint = 0x02; + static const CLR_UINT8 MD_DI_JustMyCode = 0x01; + static const CLR_UINT8 MD_DI_HasBreakpoint = 0x02; CLR_UINT8 m_flags; - bool IsJMC () const { return IsFlagSet( MD_DI_JustMyCode ) ; } - bool HasBreakpoint() const { return IsFlagSet( MD_DI_HasBreakpoint ); } + bool IsJMC() const + { + return IsFlagSet(MD_DI_JustMyCode); + } + bool HasBreakpoint() const + { + return IsFlagSet(MD_DI_HasBreakpoint); + } - void SetJMC ( bool b ) { SetResetFlags( b, MD_DI_JustMyCode ); } - void SetBreakpoint( bool b ) { SetResetFlags( b, MD_DI_HasBreakpoint ); } + void SetJMC(bool b) + { + SetResetFlags(b, MD_DI_JustMyCode); + } + void SetBreakpoint(bool b) + { + SetResetFlags(b, MD_DI_HasBreakpoint); + } -private: - void SetFlags ( CLR_UINT8 flags ) { m_flags |= flags ; } - void ResetFlags ( CLR_UINT8 flags ) { m_flags &= ~flags ; } - bool IsFlagSet ( CLR_UINT8 flags ) const { return (m_flags & flags) != 0 ; } - void SetResetFlags( bool b, CLR_UINT8 flags ) { if(b) SetFlags( flags ); else ResetFlags( flags ); } + private: + void SetFlags(CLR_UINT8 flags) + { + m_flags |= flags; + } + void ResetFlags(CLR_UINT8 flags) + { + m_flags &= ~flags; + } + bool IsFlagSet(CLR_UINT8 flags) const + { + return (m_flags & flags) != 0; + } + void SetResetFlags(bool b, CLR_UINT8 flags) + { + if (b) + SetFlags(flags); + else + ResetFlags(flags); + } }; #endif //#if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) - //////////////////////////////////////////////////////////////////////////////////////////////////// #include -//TODO: Change this to an extern method that is defined in the HAL +// TODO: Change this to an extern method that is defined in the HAL #if defined(PLATFORM_WINDOWS_EMULATOR) - #define SYSTEM_CLOCK_HZ g_HAL_Configuration_Windows.SystemClock - #define SLOW_CLOCKS_PER_SECOND g_HAL_Configuration_Windows.SlowClockPerSecond +#define SYSTEM_CLOCK_HZ g_HAL_Configuration_Windows.SystemClock +#define SLOW_CLOCKS_PER_SECOND g_HAL_Configuration_Windows.SlowClockPerSecond #endif //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -690,9 +894,9 @@ struct CLR_RT_MethodDef_DebuggingInfo struct CLR_RT_UnicodeHelper { - static const CLR_UINT32 SURROGATE_HALFSHIFT = 10; - static const CLR_UINT32 SURROGATE_HALFBASE = 0x00010000; - static const CLR_UINT32 SURROGATE_HALFMASK = 0x000003FF; + static const CLR_UINT32 SURROGATE_HALFSHIFT = 10; + static const CLR_UINT32 SURROGATE_HALFBASE = 0x00010000; + static const CLR_UINT32 SURROGATE_HALFMASK = 0x000003FF; #ifdef HIGH_SURROGATE_START #undef HIGH_SURROGATE_START @@ -700,58 +904,70 @@ struct CLR_RT_UnicodeHelper #undef LOW_SURROGATE_START #undef LOW_SURROGATE_END #endif - static const CLR_UINT16 HIGH_SURROGATE_START = 0xD800; - static const CLR_UINT16 HIGH_SURROGATE_END = 0xDBFF; - static const CLR_UINT16 LOW_SURROGATE_START = 0xDC00; - static const CLR_UINT16 LOW_SURROGATE_END = 0xDFFF; + static const CLR_UINT16 HIGH_SURROGATE_START = 0xD800; + static const CLR_UINT16 HIGH_SURROGATE_END = 0xDBFF; + static const CLR_UINT16 LOW_SURROGATE_START = 0xDC00; + static const CLR_UINT16 LOW_SURROGATE_END = 0xDFFF; - const CLR_UINT8* m_inputUTF8; - const CLR_UINT16* m_inputUTF16; + const CLR_UINT8 *m_inputUTF8; + const CLR_UINT16 *m_inputUTF16; - CLR_UINT8* m_outputUTF8; - int m_outputUTF8_size; + CLR_UINT8 *m_outputUTF8; + int m_outputUTF8_size; - CLR_UINT16* m_outputUTF16; - int m_outputUTF16_size; + CLR_UINT16 *m_outputUTF16; + int m_outputUTF16_size; //--// - void SetInputUTF8 ( const char* src ) { m_inputUTF8 = (const CLR_UINT8*)src; } - void SetInputUTF16( const CLR_UINT16* src ) { m_inputUTF16 = src; } + void SetInputUTF8(const char *src) + { + m_inputUTF8 = (const CLR_UINT8 *)src; + } + void SetInputUTF16(const CLR_UINT16 *src) + { + m_inputUTF16 = src; + } - int CountNumberOfCharacters( int max = -1 ); - int CountNumberOfBytes ( int max = -1 ); + int CountNumberOfCharacters(int max = -1); + int CountNumberOfBytes(int max = -1); //--// - bool ConvertFromUTF8( int iMaxChars, bool fJustMove, int iMaxBytes = -1 ); - bool ConvertToUTF8 ( int iMaxChars, bool fJustMove ); + bool ConvertFromUTF8(int iMaxChars, bool fJustMove, int iMaxBytes = -1); + bool ConvertToUTF8(int iMaxChars, bool fJustMove); + + bool MoveBackwardInUTF8(const char *utf8StringStart, int iMaxChars); - bool MoveBackwardInUTF8( const char* utf8StringStart, int iMaxChars ); - #if defined(_WIN32) - static void ConvertToUTF8 ( const std::wstring& src, std:: string& dst ); - static void ConvertFromUTF8( const std:: string& src, std::wstring& dst ); + static void ConvertToUTF8(const std::wstring &src, std::string &dst); + static void ConvertFromUTF8(const std::string &src, std::wstring &dst); #endif }; class UnicodeString { -private: - CLR_RT_UnicodeHelper m_unicodeHelper; - CLR_RT_HeapBlock m_uHeapBlock; - CLR_UINT16* m_wCharArray; - int m_length; /// Length in wide characters (not bytes). + private: + CLR_RT_UnicodeHelper m_unicodeHelper; + CLR_RT_HeapBlock m_uHeapBlock; + CLR_UINT16 *m_wCharArray; + int m_length; /// Length in wide characters (not bytes). -public: + public: UnicodeString(); ~UnicodeString(); - HRESULT Assign( const char* string ); - operator const wchar_t*() { return (const wchar_t*)m_wCharArray; } - unsigned int Length(){ return m_length; } + HRESULT Assign(const char *string); + operator const wchar_t *() + { + return (const wchar_t *)m_wCharArray; + } + unsigned int Length() + { + return m_length; + } -private: + private: void Release(); }; @@ -761,123 +977,134 @@ struct CLR_RT_ArrayListHelper { static const int c_defaultCapacity = 2; - static const int FIELD___items = 1; - static const int FIELD___size = 2; + static const int FIELD___items = 1; + static const int FIELD___size = 2; //--// - static HRESULT PrepareArrayList ( CLR_RT_HeapBlock& pThisRef, int count, int capacity ); - static HRESULT ExtractArrayFromArrayList( CLR_RT_HeapBlock& pThisRef, CLR_RT_HeapBlock_Array* & array, int& count, int& capacity ); + static HRESULT PrepareArrayList(CLR_RT_HeapBlock &pThisRef, int count, int capacity); + static HRESULT ExtractArrayFromArrayList( + CLR_RT_HeapBlock &pThisRef, + CLR_RT_HeapBlock_Array *&array, + int &count, + int &capacity); }; //--// struct CLR_RT_ByteArrayReader { - HRESULT Init( const unsigned char* src, unsigned int srcSize ); + HRESULT Init(const unsigned char *src, unsigned int srcSize); - HRESULT Read( void* dst, unsigned int size ); - HRESULT Read1Byte( void* dst ); + HRESULT Read(void *dst, unsigned int size); + HRESULT Read1Byte(void *dst); - HRESULT Skip( unsigned int size ); + HRESULT Skip(unsigned int size); - bool IsValid() { return (source && sourceSize > 0); } + bool IsValid() + { + return (source && sourceSize > 0); + } - const unsigned char* source; - unsigned int sourceSize; + const unsigned char *source; + unsigned int sourceSize; }; //////////////////////////////////////////////////////////////////////////////////////////////////// struct CLR_RT_SignatureParser { - static const int c_TypeSpec = 0; + static const int c_TypeSpec = 0; static const int c_Interfaces = 1; - static const int c_Field = 2; - static const int c_Method = 3; - static const int c_Locals = 4; - static const int c_Object = 5; + static const int c_Field = 2; + static const int c_Method = 3; + static const int c_Locals = 4; + static const int c_Object = 5; struct Element { - bool m_fByRef; - int m_levels; - CLR_DataType m_dt; + bool m_fByRef; + int m_levels; + CLR_DataType m_dt; CLR_RT_TypeDef_Index m_cls; }; - CLR_RT_HeapBlock* m_lst; - CLR_RT_Assembly* m_assm; - CLR_PMETADATA m_sig; + CLR_RT_HeapBlock *m_lst; + CLR_RT_Assembly *m_assm; + CLR_PMETADATA m_sig; - int m_type; - CLR_UINT32 m_flags; - int m_count; + int m_type; + CLR_UINT32 m_flags; + int m_count; //--// - void Initialize_TypeSpec ( CLR_RT_Assembly* assm, const CLR_RECORD_TYPESPEC* ts ); - void Initialize_Interfaces ( CLR_RT_Assembly* assm, const CLR_RECORD_TYPEDEF* td ); - void Initialize_FieldDef ( CLR_RT_Assembly* assm, const CLR_RECORD_FIELDDEF* fd ); - void Initialize_MethodSignature( CLR_RT_Assembly* assm, const CLR_RECORD_METHODDEF* md ); - void Initialize_MethodLocals ( CLR_RT_Assembly* assm, const CLR_RECORD_METHODDEF* md ); + void Initialize_TypeSpec(CLR_RT_Assembly *assm, const CLR_RECORD_TYPESPEC *ts); + void Initialize_Interfaces(CLR_RT_Assembly *assm, const CLR_RECORD_TYPEDEF *td); + void Initialize_FieldDef(CLR_RT_Assembly *assm, const CLR_RECORD_FIELDDEF *fd); + void Initialize_MethodSignature(CLR_RT_Assembly *assm, const CLR_RECORD_METHODDEF *md); + void Initialize_MethodLocals(CLR_RT_Assembly *assm, const CLR_RECORD_METHODDEF *md); - void Initialize_TypeSpec ( CLR_RT_Assembly* assm, CLR_PMETADATA ts ); - void Initialize_FieldDef ( CLR_RT_Assembly* assm, CLR_PMETADATA fd ); - void Initialize_MethodSignature( CLR_RT_Assembly* assm, CLR_PMETADATA md ); + void Initialize_TypeSpec(CLR_RT_Assembly *assm, CLR_PMETADATA ts); + void Initialize_FieldDef(CLR_RT_Assembly *assm, CLR_PMETADATA fd); + void Initialize_MethodSignature(CLR_RT_Assembly *assm, CLR_PMETADATA md); - void Initialize_Objects ( CLR_RT_HeapBlock* lst, int count, bool fTypes ); + void Initialize_Objects(CLR_RT_HeapBlock *lst, int count, bool fTypes); - int Available() const { return m_count; } + int Available() const + { + return m_count; + } - HRESULT Advance( Element& res ); + HRESULT Advance(Element &res); }; //////////////////////////////////////////////////////////////////////////////////////////////////// -#define NANOCLR_FOREACH_ASSEMBLY(ts) \ - { \ - CLR_RT_Assembly** ppASSM = (ts).m_assemblies; \ - size_t iASSM = (ts).m_assembliesMax; \ - for( ;iASSM--; ppASSM++) \ - { \ - CLR_RT_Assembly* pASSM = *ppASSM; \ - if(pASSM) - -#define NANOCLR_FOREACH_ASSEMBLY_END() \ - } \ +#define NANOCLR_FOREACH_ASSEMBLY(ts) \ + { \ + CLR_RT_Assembly **ppASSM = (ts).m_assemblies; \ + size_t iASSM = (ts).m_assembliesMax; \ + for (; iASSM--; ppASSM++) \ + { \ + CLR_RT_Assembly *pASSM = *ppASSM; \ + if (pASSM) + +#define NANOCLR_FOREACH_ASSEMBLY_END() \ + } \ } -#define NANOCLR_FOREACH_ASSEMBLY_NULL(ts) \ - { \ - CLR_RT_Assembly** ppASSM = (ts).m_assemblies; \ - size_t iASSM = ARRAYSIZE((ts).m_assemblies); \ - CLR_IDX idx = 1; \ - for( ;iASSM--; ppASSM++,idx++) \ - { \ - if(*ppASSM == NULL) - -#define NANOCLR_FOREACH_ASSEMBLY_NULL_END() \ - } \ +#define NANOCLR_FOREACH_ASSEMBLY_NULL(ts) \ + { \ + CLR_RT_Assembly **ppASSM = (ts).m_assemblies; \ + size_t iASSM = ARRAYSIZE((ts).m_assemblies); \ + CLR_IDX idx = 1; \ + for (; iASSM--; ppASSM++, idx++) \ + { \ + if (*ppASSM == NULL) + +#define NANOCLR_FOREACH_ASSEMBLY_NULL_END() \ + } \ } #if defined(NANOCLR_APPDOMAINS) - #define NANOCLR_FOREACH_ASSEMBLY_IN_APPDOMAIN(ad) \ - NANOCLR_FOREACH_NODE(CLR_RT_AppDomainAssembly, appDomainAssembly, (ad)->m_appDomainAssemblies) \ - { \ - CLR_RT_Assembly* pASSM = appDomainAssembly->m_assembly; - - #define NANOCLR_FOREACH_ASSEMBLY_IN_APPDOMAIN_END() \ - } \ - NANOCLR_FOREACH_NODE_END() - - #define NANOCLR_FOREACH_ASSEMBLY_IN_CURRENT_APPDOMAIN(ts) NANOCLR_FOREACH_ASSEMBLY_IN_APPDOMAIN(g_CLR_RT_ExecutionEngine.GetCurrentAppDomain()) - #define NANOCLR_FOREACH_ASSEMBLY_IN_CURRENT_APPDOMAIN_END() NANOCLR_FOREACH_ASSEMBLY_IN_APPDOMAIN_END() +#define NANOCLR_FOREACH_ASSEMBLY_IN_APPDOMAIN(ad) \ + NANOCLR_FOREACH_NODE(CLR_RT_AppDomainAssembly, appDomainAssembly, (ad)->m_appDomainAssemblies) \ + { \ + CLR_RT_Assembly *pASSM = appDomainAssembly->m_assembly; + +#define NANOCLR_FOREACH_ASSEMBLY_IN_APPDOMAIN_END() \ + } \ + NANOCLR_FOREACH_NODE_END() + +#define NANOCLR_FOREACH_ASSEMBLY_IN_CURRENT_APPDOMAIN(ts) \ + NANOCLR_FOREACH_ASSEMBLY_IN_APPDOMAIN(g_CLR_RT_ExecutionEngine.GetCurrentAppDomain()) +#define NANOCLR_FOREACH_ASSEMBLY_IN_CURRENT_APPDOMAIN_END() NANOCLR_FOREACH_ASSEMBLY_IN_APPDOMAIN_END() #else - #define NANOCLR_FOREACH_ASSEMBLY_IN_APPDOMAIN(ts, ad) NANOCLR_FOREACH_ASSEMBLY(ts) - #define NANOCLR_FOREACH_ASSEMBLY_IN_APPDOMAIN_END() NANOCLR_FOREACH_ASSEMBLY_END() - #define NANOCLR_FOREACH_ASSEMBLY_IN_CURRENT_APPDOMAIN(ts) NANOCLR_FOREACH_ASSEMBLY(ts) - #define NANOCLR_FOREACH_ASSEMBLY_IN_CURRENT_APPDOMAIN_END() NANOCLR_FOREACH_ASSEMBLY_END() +#define NANOCLR_FOREACH_ASSEMBLY_IN_APPDOMAIN(ts, ad) NANOCLR_FOREACH_ASSEMBLY(ts) +#define NANOCLR_FOREACH_ASSEMBLY_IN_APPDOMAIN_END() NANOCLR_FOREACH_ASSEMBLY_END() +#define NANOCLR_FOREACH_ASSEMBLY_IN_CURRENT_APPDOMAIN(ts) NANOCLR_FOREACH_ASSEMBLY(ts) +#define NANOCLR_FOREACH_ASSEMBLY_IN_CURRENT_APPDOMAIN_END() NANOCLR_FOREACH_ASSEMBLY_END() #endif // This type is needed on PC only for Interop code generation. For device code forward declaration only class CLR_RT_VectorOfManagedElements; @@ -900,223 +1127,291 @@ struct CLR_RT_Assembly : public CLR_RT_HeapBlock_Node // EVENT HEAP - NO RELOCAT size_t iFieldDef; size_t iMethodDef; - #if !defined(NANOCLR_APPDOMAINS) +#if !defined(NANOCLR_APPDOMAINS) size_t iStaticFields; - #endif +#endif - #if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) +#if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) size_t iDebuggingInfoMethods; - #endif //#if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) +#endif //#if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) }; //--// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // NEED TO KEEP THESE IN SYNC WITH Enum 'Commands.DebuggingResolveAssembly.ResolvedStatus' on debugger library code // + // NEED TO KEEP THESE IN SYNC WITH Enum 'Commands.DebuggingResolveAssembly.ResolvedStatus' on debugger library code + // // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - static const CLR_UINT32 Resolved = 0x00000001; - static const CLR_UINT32 ResolutionCompleted = 0x00000002; - static const CLR_UINT32 PreparedForExecution = 0x00000004; - static const CLR_UINT32 Deployed = 0x00000008; - static const CLR_UINT32 PreparingForExecution = 0x00000010; + static const CLR_UINT32 Resolved = 0x00000001; + static const CLR_UINT32 ResolutionCompleted = 0x00000002; + static const CLR_UINT32 PreparedForExecution = 0x00000004; + static const CLR_UINT32 Deployed = 0x00000008; + static const CLR_UINT32 PreparingForExecution = 0x00000010; static const CLR_UINT32 StaticConstructorsExecuted = 0x00000020; - CLR_UINT32 m_idx; // Relative to the type system (for static fields access). - CLR_UINT32 m_flags; - - const CLR_RECORD_ASSEMBLY* m_header; // ANY HEAP - DO RELOCATION - - const char* m_szName; // ANY HEAP - DO RELOCATION - - - const CLR_RT_MethodHandler* m_nativeCode; - - int m_pTablesSize[ TBL_Max ]; + CLR_UINT32 m_idx; // Relative to the type system (for static fields access). + CLR_UINT32 m_flags; - #if !defined(NANOCLR_APPDOMAINS) - CLR_RT_HeapBlock* m_pStaticFields; // EVENT HEAP - NO RELOCATION - (but the data they point to has to be relocated) - #endif + const CLR_RECORD_ASSEMBLY *m_header; // ANY HEAP - DO RELOCATION - + const char *m_szName; // ANY HEAP - DO RELOCATION - - int m_iStaticFields; + const CLR_RT_MethodHandler *m_nativeCode; - CLR_RT_HeapBlock_Array* m_pFile; // ANY HEAP - DO RELOCATION - + int m_pTablesSize[TBL_Max]; - CLR_RT_AssemblyRef_CrossReference* m_pCrossReference_AssemblyRef; // EVENT HEAP - NO RELOCATION - (but the data they point to has to be relocated) - CLR_RT_TypeRef_CrossReference * m_pCrossReference_TypeRef ; // EVENT HEAP - NO RELOCATION - (but the data they point to has to be relocated) - CLR_RT_FieldRef_CrossReference * m_pCrossReference_FieldRef ; // EVENT HEAP - NO RELOCATION - (but the data they point to has to be relocated) - CLR_RT_MethodRef_CrossReference * m_pCrossReference_MethodRef ; // EVENT HEAP - NO RELOCATION - (but the data they point to has to be relocated) - CLR_RT_TypeDef_CrossReference * m_pCrossReference_TypeDef ; // EVENT HEAP - NO RELOCATION - (but the data they point to has to be relocated) - CLR_RT_FieldDef_CrossReference * m_pCrossReference_FieldDef ; // EVENT HEAP - NO RELOCATION - (but the data they point to has to be relocated) - CLR_RT_MethodDef_CrossReference * m_pCrossReference_MethodDef ; // EVENT HEAP - NO RELOCATION - (but the data they point to has to be relocated) +#if !defined(NANOCLR_APPDOMAINS) + CLR_RT_HeapBlock *m_pStaticFields; // EVENT HEAP - NO RELOCATION - (but the data they point to has to be relocated) +#endif - #if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) - CLR_RT_MethodDef_DebuggingInfo * m_pDebuggingInfo_MethodDef ; //EVENT HEAP - NO RELOCATION - (but the data they point to has to be relocated) - #endif //#if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) + int m_iStaticFields; + + CLR_RT_HeapBlock_Array *m_pFile; // ANY HEAP - DO RELOCATION - + + CLR_RT_AssemblyRef_CrossReference + *m_pCrossReference_AssemblyRef; // EVENT HEAP - NO RELOCATION - (but the data they point to has to be relocated) + CLR_RT_TypeRef_CrossReference + *m_pCrossReference_TypeRef; // EVENT HEAP - NO RELOCATION - (but the data they point to has to be relocated) + CLR_RT_FieldRef_CrossReference + *m_pCrossReference_FieldRef; // EVENT HEAP - NO RELOCATION - (but the data they point to has to be relocated) + CLR_RT_MethodRef_CrossReference + *m_pCrossReference_MethodRef; // EVENT HEAP - NO RELOCATION - (but the data they point to has to be relocated) + CLR_RT_TypeDef_CrossReference + *m_pCrossReference_TypeDef; // EVENT HEAP - NO RELOCATION - (but the data they point to has to be relocated) + CLR_RT_FieldDef_CrossReference + *m_pCrossReference_FieldDef; // EVENT HEAP - NO RELOCATION - (but the data they point to has to be relocated) + CLR_RT_MethodDef_CrossReference + *m_pCrossReference_MethodDef; // EVENT HEAP - NO RELOCATION - (but the data they point to has to be relocated) - #if defined(NANOCLR_TRACE_STACK_HEAVY) && defined(_WIN32) - int m_maxOpcodes; - int* m_stackDepth; - #endif +#if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) + CLR_RT_MethodDef_DebuggingInfo + *m_pDebuggingInfo_MethodDef; // EVENT HEAP - NO RELOCATION - (but the data they point to has to be relocated) +#endif //#if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) +#if defined(NANOCLR_TRACE_STACK_HEAVY) && defined(_WIN32) + int m_maxOpcodes; + int *m_stackDepth; +#endif - #if defined(_WIN32) - std::string* m_strPath; - #endif +#if defined(_WIN32) + std::string *m_strPath; +#endif //--// static void InitString(); - bool IsSameAssembly( const CLR_RT_Assembly& assm ) const; - - #if defined(_WIN32) + bool IsSameAssembly(const CLR_RT_Assembly &assm) const; - static void InitString( std::map& map ); - static HRESULT CreateInstance ( const CLR_RECORD_ASSEMBLY* data, CLR_RT_Assembly*& assm, const wchar_t* szName ); +#if defined(_WIN32) + + static void InitString(std::map &map); + static HRESULT CreateInstance(const CLR_RECORD_ASSEMBLY *data, CLR_RT_Assembly *&assm, const wchar_t *szName); - #endif +#endif //--// - static HRESULT CreateInstance ( const CLR_RECORD_ASSEMBLY* data, CLR_RT_Assembly*& assm ); - void DestroyInstance( ); + static HRESULT CreateInstance(const CLR_RECORD_ASSEMBLY *data, CLR_RT_Assembly *&assm); + void DestroyInstance(); - void Assembly_Initialize( CLR_RT_Assembly::Offsets& offsets ); - - bool Resolve_AssemblyRef ( bool fOutput ); - HRESULT Resolve_TypeRef ( ); - HRESULT Resolve_FieldRef ( ); - HRESULT Resolve_MethodRef ( ); - void Resolve_TypeDef ( ); - void Resolve_MethodDef ( ); - void Resolve_Link ( ); - HRESULT Resolve_ComputeHashes ( ); - HRESULT Resolve_AllocateStaticFields ( CLR_RT_HeapBlock* pStaticFields ); + void Assembly_Initialize(CLR_RT_Assembly::Offsets &offsets); - HRESULT PrepareForExecution(); + bool Resolve_AssemblyRef(bool fOutput); + HRESULT Resolve_TypeRef(); + HRESULT Resolve_FieldRef(); + HRESULT Resolve_MethodRef(); + void Resolve_TypeDef(); + void Resolve_MethodDef(); + void Resolve_Link(); + HRESULT Resolve_ComputeHashes(); + HRESULT Resolve_AllocateStaticFields(CLR_RT_HeapBlock *pStaticFields); - CLR_UINT32 ComputeAssemblyHash( ); - CLR_UINT32 ComputeAssemblyHash( const CLR_RECORD_ASSEMBLYREF* ar ); + HRESULT PrepareForExecution(); + CLR_UINT32 ComputeAssemblyHash(); + CLR_UINT32 ComputeAssemblyHash(const CLR_RECORD_ASSEMBLYREF *ar); - bool FindTypeDef ( const char* name, const char* nameSpace , CLR_RT_TypeDef_Index& idx ); - bool FindTypeDef ( const char* name, CLR_IDX scope , CLR_RT_TypeDef_Index& idx ); - bool FindTypeDef ( CLR_UINT32 hash , CLR_RT_TypeDef_Index& idx ); + bool FindTypeDef(const char *name, const char *nameSpace, CLR_RT_TypeDef_Index &idx); + bool FindTypeDef(const char *name, CLR_IDX scope, CLR_RT_TypeDef_Index &idx); + bool FindTypeDef(CLR_UINT32 hash, CLR_RT_TypeDef_Index &idx); - bool FindFieldDef ( const CLR_RECORD_TYPEDEF* src, const char* name, CLR_RT_Assembly* base, CLR_SIG sig, CLR_RT_FieldDef_Index& idx ); - bool FindMethodDef( const CLR_RECORD_TYPEDEF* src, const char* name, CLR_RT_Assembly* base, CLR_SIG sig, CLR_RT_MethodDef_Index& idx ); + bool FindFieldDef( + const CLR_RECORD_TYPEDEF *src, + const char *name, + CLR_RT_Assembly *base, + CLR_SIG sig, + CLR_RT_FieldDef_Index &idx); + bool FindMethodDef( + const CLR_RECORD_TYPEDEF *src, + const char *name, + CLR_RT_Assembly *base, + CLR_SIG sig, + CLR_RT_MethodDef_Index &idx); - bool FindNextStaticConstructor( CLR_RT_MethodDef_Index& idx ); + bool FindNextStaticConstructor(CLR_RT_MethodDef_Index &idx); - bool FindMethodBoundaries( CLR_IDX i, CLR_OFFSET& start, CLR_OFFSET& end ); + bool FindMethodBoundaries(CLR_IDX i, CLR_OFFSET &start, CLR_OFFSET &end); - void Relocate(); + void Relocate(); //--// - CLR_RT_HeapBlock* GetStaticField( const int index ); + CLR_RT_HeapBlock *GetStaticField(const int index); //--// - CLR_PMETADATA GetTable( CLR_TABLESENUM tbl ) { return (CLR_PMETADATA)m_header + m_header->startOfTables[ tbl ]; } + CLR_PMETADATA GetTable(CLR_TABLESENUM tbl) + { + return (CLR_PMETADATA)m_header + m_header->startOfTables[tbl]; + } - #define NANOCLR_ASSEMBLY_RESOLVE(cls,tbl,idx) (const cls *)((CLR_UINT8*)m_header + m_header->startOfTables[ tbl ] + (sizeof(cls) * idx)) - const CLR_RECORD_ASSEMBLYREF * GetAssemblyRef ( CLR_IDX i ) { return NANOCLR_ASSEMBLY_RESOLVE(CLR_RECORD_ASSEMBLYREF , TBL_AssemblyRef , i); } - const CLR_RECORD_TYPEREF * GetTypeRef ( CLR_IDX i ) { return NANOCLR_ASSEMBLY_RESOLVE(CLR_RECORD_TYPEREF , TBL_TypeRef , i); } - const CLR_RECORD_FIELDREF * GetFieldRef ( CLR_IDX i ) { return NANOCLR_ASSEMBLY_RESOLVE(CLR_RECORD_FIELDREF , TBL_FieldRef , i); } - const CLR_RECORD_METHODREF * GetMethodRef ( CLR_IDX i ) { return NANOCLR_ASSEMBLY_RESOLVE(CLR_RECORD_METHODREF , TBL_MethodRef , i); } - const CLR_RECORD_TYPEDEF * GetTypeDef ( CLR_IDX i ) { return NANOCLR_ASSEMBLY_RESOLVE(CLR_RECORD_TYPEDEF , TBL_TypeDef , i); } - const CLR_RECORD_FIELDDEF * GetFieldDef ( CLR_IDX i ) { return NANOCLR_ASSEMBLY_RESOLVE(CLR_RECORD_FIELDDEF , TBL_FieldDef , i); } - const CLR_RECORD_METHODDEF * GetMethodDef ( CLR_IDX i ) { return NANOCLR_ASSEMBLY_RESOLVE(CLR_RECORD_METHODDEF , TBL_MethodDef , i); } - const CLR_RECORD_ATTRIBUTE * GetAttribute ( CLR_IDX i ) { return NANOCLR_ASSEMBLY_RESOLVE(CLR_RECORD_ATTRIBUTE , TBL_Attributes , i); } - const CLR_RECORD_TYPESPEC * GetTypeSpec ( CLR_IDX i ) { return NANOCLR_ASSEMBLY_RESOLVE(CLR_RECORD_TYPESPEC , TBL_TypeSpec , i); } - const CLR_RECORD_RESOURCE_FILE* GetResourceFile( CLR_IDX i ) { return NANOCLR_ASSEMBLY_RESOLVE(CLR_RECORD_RESOURCE_FILE, TBL_ResourcesFiles, i); } - const CLR_RECORD_RESOURCE * GetResource ( CLR_IDX i ) { return NANOCLR_ASSEMBLY_RESOLVE(CLR_RECORD_RESOURCE , TBL_Resources , i); } - CLR_PMETADATA GetResourceData( CLR_UINT32 i ) { return NANOCLR_ASSEMBLY_RESOLVE(CLR_UINT8 , TBL_ResourcesData , i); } - const char* GetString ( CLR_STRING i ); - CLR_PMETADATA GetSignature ( CLR_SIG i ) { return NANOCLR_ASSEMBLY_RESOLVE(CLR_UINT8 , TBL_Signatures , i); } - CLR_PMETADATA GetByteCode ( CLR_OFFSET i ) { return NANOCLR_ASSEMBLY_RESOLVE(CLR_UINT8 , TBL_ByteCode , i); } - #undef NANOCLR_ASSEMBLY_RESOLVE +#define NANOCLR_ASSEMBLY_RESOLVE(cls, tbl, idx) \ + (const cls *)((CLR_UINT8 *)m_header + m_header->startOfTables[tbl] + (sizeof(cls) * idx)) + const CLR_RECORD_ASSEMBLYREF *GetAssemblyRef(CLR_IDX i) + { + return NANOCLR_ASSEMBLY_RESOLVE(CLR_RECORD_ASSEMBLYREF, TBL_AssemblyRef, i); + } + const CLR_RECORD_TYPEREF *GetTypeRef(CLR_IDX i) + { + return NANOCLR_ASSEMBLY_RESOLVE(CLR_RECORD_TYPEREF, TBL_TypeRef, i); + } + const CLR_RECORD_FIELDREF *GetFieldRef(CLR_IDX i) + { + return NANOCLR_ASSEMBLY_RESOLVE(CLR_RECORD_FIELDREF, TBL_FieldRef, i); + } + const CLR_RECORD_METHODREF *GetMethodRef(CLR_IDX i) + { + return NANOCLR_ASSEMBLY_RESOLVE(CLR_RECORD_METHODREF, TBL_MethodRef, i); + } + const CLR_RECORD_TYPEDEF *GetTypeDef(CLR_IDX i) + { + return NANOCLR_ASSEMBLY_RESOLVE(CLR_RECORD_TYPEDEF, TBL_TypeDef, i); + } + const CLR_RECORD_FIELDDEF *GetFieldDef(CLR_IDX i) + { + return NANOCLR_ASSEMBLY_RESOLVE(CLR_RECORD_FIELDDEF, TBL_FieldDef, i); + } + const CLR_RECORD_METHODDEF *GetMethodDef(CLR_IDX i) + { + return NANOCLR_ASSEMBLY_RESOLVE(CLR_RECORD_METHODDEF, TBL_MethodDef, i); + } + const CLR_RECORD_ATTRIBUTE *GetAttribute(CLR_IDX i) + { + return NANOCLR_ASSEMBLY_RESOLVE(CLR_RECORD_ATTRIBUTE, TBL_Attributes, i); + } + const CLR_RECORD_TYPESPEC *GetTypeSpec(CLR_IDX i) + { + return NANOCLR_ASSEMBLY_RESOLVE(CLR_RECORD_TYPESPEC, TBL_TypeSpec, i); + } + const CLR_RECORD_RESOURCE_FILE *GetResourceFile(CLR_IDX i) + { + return NANOCLR_ASSEMBLY_RESOLVE(CLR_RECORD_RESOURCE_FILE, TBL_ResourcesFiles, i); + } + const CLR_RECORD_RESOURCE *GetResource(CLR_IDX i) + { + return NANOCLR_ASSEMBLY_RESOLVE(CLR_RECORD_RESOURCE, TBL_Resources, i); + } + CLR_PMETADATA GetResourceData(CLR_UINT32 i) + { + return NANOCLR_ASSEMBLY_RESOLVE(CLR_UINT8, TBL_ResourcesData, i); + } + const char *GetString(CLR_STRING i); + CLR_PMETADATA GetSignature(CLR_SIG i) + { + return NANOCLR_ASSEMBLY_RESOLVE(CLR_UINT8, TBL_Signatures, i); + } + CLR_PMETADATA GetByteCode(CLR_OFFSET i) + { + return NANOCLR_ASSEMBLY_RESOLVE(CLR_UINT8, TBL_ByteCode, i); + } +#undef NANOCLR_ASSEMBLY_RESOLVE //--// - #undef DECL_POSTFIX - #if defined(NANOCLR_TRACE_INSTRUCTIONS) - #define DECL_POSTFIX - #else - #define DECL_POSTFIX {} - #endif +#undef DECL_POSTFIX +#if defined(NANOCLR_TRACE_INSTRUCTIONS) +#define DECL_POSTFIX +#else +#define DECL_POSTFIX \ + { \ + } +#endif - public: - void DumpOpcode ( CLR_RT_StackFrame* stack, CLR_PMETADATA ip ) DECL_POSTFIX; - void DumpOpcodeDirect( CLR_RT_MethodDef_Instance& call , CLR_PMETADATA ip, CLR_PMETADATA ipStart, int pid ) DECL_POSTFIX; + public: + void DumpOpcode(CLR_RT_StackFrame *stack, CLR_PMETADATA ip) DECL_POSTFIX; + void DumpOpcodeDirect(CLR_RT_MethodDef_Instance &call, CLR_PMETADATA ip, CLR_PMETADATA ipStart, int pid) + DECL_POSTFIX; - private: - void DumpToken ( CLR_UINT32 tk ) DECL_POSTFIX; - void DumpSignature ( CLR_SIG sig ) DECL_POSTFIX; - void DumpSignature ( CLR_PMETADATA& p ) DECL_POSTFIX; - void DumpSignatureToken( CLR_PMETADATA& p ) DECL_POSTFIX; + private: + void DumpToken(CLR_UINT32 tk) DECL_POSTFIX; + void DumpSignature(CLR_SIG sig) DECL_POSTFIX; + void DumpSignature(CLR_PMETADATA &p) DECL_POSTFIX; + void DumpSignatureToken(CLR_PMETADATA &p) DECL_POSTFIX; //--// - #if defined(_WIN32) - static FILE* s_output; - static FILE* s_toclose; +#if defined(_WIN32) + static FILE *s_output; + static FILE *s_toclose; - public: - static void Dump_SetDevice ( FILE *&outputDeviceFile, const wchar_t* szFileName ); - static void Dump_SetDevice ( const wchar_t* szFileName ); + public: + static void Dump_SetDevice(FILE *&outputDeviceFile, const wchar_t *szFileName); + static void Dump_SetDevice(const wchar_t *szFileName); - static void Dump_CloseDevice( FILE *&outputDeviceFile); - static void Dump_CloseDevice( ); + static void Dump_CloseDevice(FILE *&outputDeviceFile); + static void Dump_CloseDevice(); - static void Dump_Printf ( FILE *outputDeviceFile, const char *format, ... ); - static void Dump_Printf ( const char *format, ... ); + static void Dump_Printf(FILE *outputDeviceFile, const char *format, ...); + static void Dump_Printf(const char *format, ...); - static void Dump_Indent( const CLR_RECORD_METHODDEF* md, size_t offset, size_t level ); + static void Dump_Indent(const CLR_RECORD_METHODDEF *md, size_t offset, size_t level); - void Dump( bool fNoByteCode ); + void Dump(bool fNoByteCode); - unsigned int GenerateSignatureForNativeMethods(); + unsigned int GenerateSignatureForNativeMethods(); - bool AreInternalMethodsPresent( const CLR_RECORD_TYPEDEF* td ); - void GenerateSkeleton( const wchar_t* szFileName, const wchar_t* szProjectName ); - void GenerateSkeletonFromComplientNames( const wchar_t* szFileName, const wchar_t* szProjectName ); - - void BuildParametersList( CLR_PMETADATA pMetaData, CLR_RT_VectorOfManagedElements &elemPtrArray ); - void GenerateSkeletonStubFieldsDef( const CLR_RECORD_TYPEDEF *pClsType, FILE *pFileStubHead, std::string strIndent, std::string strMngClassName ); - void GenerateSkeletonStubCode( const wchar_t* szFilePath, FILE *pFileDotNetProj ); + bool AreInternalMethodsPresent(const CLR_RECORD_TYPEDEF *td); + void GenerateSkeleton(const wchar_t *szFileName, const wchar_t *szProjectName); + void GenerateSkeletonFromComplientNames(const wchar_t *szFileName, const wchar_t *szProjectName); - void BuildMethodName_NoInterop(const CLR_RECORD_METHODDEF* md, std::string& name, CLR_RT_StringMap& mapMethods); - void GenerateSkeleton_NoInterop(LPCWSTR szFileName, LPCWSTR szProjectName); + void BuildParametersList(CLR_PMETADATA pMetaData, CLR_RT_VectorOfManagedElements &elemPtrArray); + void GenerateSkeletonStubFieldsDef( + const CLR_RECORD_TYPEDEF *pClsType, + FILE *pFileStubHead, + std::string strIndent, + std::string strMngClassName); + void GenerateSkeletonStubCode(const wchar_t *szFilePath, FILE *pFileDotNetProj); - void BuildMethodName( const CLR_RECORD_METHODDEF* md, std::string& name , CLR_RT_StringMap& mapMethods ); - void BuildClassName ( const CLR_RECORD_TYPEREF* tr, std::string& cls_name, bool fEscape ); - void BuildClassName ( const CLR_RECORD_TYPEDEF* td, std::string& cls_name, bool fEscape ); - void BuildTypeName ( const CLR_RECORD_TYPEDEF* td, std::string& type_name ); + void BuildMethodName_NoInterop(const CLR_RECORD_METHODDEF *md, std::string &name, CLR_RT_StringMap &mapMethods); + void GenerateSkeleton_NoInterop(LPCWSTR szFileName, LPCWSTR szProjectName); - #endif - private: + void BuildMethodName(const CLR_RECORD_METHODDEF *md, std::string &name, CLR_RT_StringMap &mapMethods); + void BuildClassName(const CLR_RECORD_TYPEREF *tr, std::string &cls_name, bool fEscape); + void BuildClassName(const CLR_RECORD_TYPEDEF *td, std::string &cls_name, bool fEscape); + void BuildTypeName(const CLR_RECORD_TYPEDEF *td, std::string &type_name); - #if defined(_WIN32) - void Dump_Token ( CLR_UINT32 tk ); - void Dump_FieldOwner ( CLR_UINT32 idx ); - void Dump_MethodOwner ( CLR_UINT32 idx ); - void Dump_Signature ( CLR_SIG sig ); - void Dump_Signature ( CLR_PMETADATA& p ); - void Dump_SignatureToken( CLR_PMETADATA& p ); - #endif +#endif + private: +#if defined(_WIN32) + void Dump_Token(CLR_UINT32 tk); + void Dump_FieldOwner(CLR_UINT32 idx); + void Dump_MethodOwner(CLR_UINT32 idx); + void Dump_Signature(CLR_SIG sig); + void Dump_Signature(CLR_PMETADATA &p); + void Dump_SignatureToken(CLR_PMETADATA &p); +#endif - //--// + //--// PROHIBIT_ALL_CONSTRUCTORS(CLR_RT_Assembly); //--// - private: + private: + CLR_UINT32 ComputeHashForName(const CLR_RT_TypeDef_Index &td, CLR_UINT32 hash); - CLR_UINT32 ComputeHashForName( const CLR_RT_TypeDef_Index& td, CLR_UINT32 hash ); - - static CLR_UINT32 ComputeHashForType( CLR_DataType dt, CLR_UINT32 hash ); + static CLR_UINT32 ComputeHashForType(CLR_DataType dt, CLR_UINT32 hash); }; #ifdef __GNUC__ @@ -1136,55 +1431,62 @@ struct CLR_RT_AppDomain : public CLR_RT_ObjectToEvent_Destination // EVENT HEAP AppDomainState_Unloaded }; - AppDomainState m_state; - int m_id; - CLR_RT_DblLinkedList m_appDomainAssemblies; - CLR_RT_HeapBlock* m_globalLock; // OBJECT HEAP - DO RELOCATION - - CLR_RT_HeapBlock_String* m_strName; // OBJECT HEAP - DO RELOCATION - - CLR_RT_HeapBlock* m_outOfMemoryException; // OBJECT HEAP - DO RELOCATION - - CLR_RT_AppDomainAssembly* m_appDomainAssemblyLastAccess; // EVENT HEAP - NO RELOCATION - - bool m_fCanBeUnloaded; + AppDomainState m_state; + int m_id; + CLR_RT_DblLinkedList m_appDomainAssemblies; + CLR_RT_HeapBlock *m_globalLock; // OBJECT HEAP - DO RELOCATION - + CLR_RT_HeapBlock_String *m_strName; // OBJECT HEAP - DO RELOCATION - + CLR_RT_HeapBlock *m_outOfMemoryException; // OBJECT HEAP - DO RELOCATION - + CLR_RT_AppDomainAssembly *m_appDomainAssemblyLastAccess; // EVENT HEAP - NO RELOCATION - + bool m_fCanBeUnloaded; - static HRESULT CreateInstance ( const char* szName, CLR_RT_AppDomain*& appDomain); + static HRESULT CreateInstance(const char *szName, CLR_RT_AppDomain *&appDomain); - void DestroyInstance (); - void AppDomain_Initialize (); + void DestroyInstance(); + void AppDomain_Initialize(); void AppDomain_Uninitialize(); - bool IsLoaded (); + bool IsLoaded(); - void Relocate (); + void Relocate(); void RecoverFromGC(); - CLR_RT_AppDomainAssembly* FindAppDomainAssembly( CLR_RT_Assembly* assm ); + CLR_RT_AppDomainAssembly *FindAppDomainAssembly(CLR_RT_Assembly *assm); - HRESULT MarshalObject ( CLR_RT_HeapBlock& src , CLR_RT_HeapBlock& dst, CLR_RT_AppDomain* appDomainSrc = NULL ); - HRESULT MarshalParameters( CLR_RT_HeapBlock* callerArgs, CLR_RT_HeapBlock* calleeArgs, int count, bool fOnReturn, CLR_RT_AppDomain* appDomainSrc = NULL ); + HRESULT MarshalObject(CLR_RT_HeapBlock &src, CLR_RT_HeapBlock &dst, CLR_RT_AppDomain *appDomainSrc = NULL); + HRESULT MarshalParameters( + CLR_RT_HeapBlock *callerArgs, + CLR_RT_HeapBlock *calleeArgs, + int count, + bool fOnReturn, + CLR_RT_AppDomain *appDomainSrc = NULL); - HRESULT VerifyTypeIsLoaded( const CLR_RT_TypeDef_Index& idx ); - HRESULT GetAssemblies ( CLR_RT_HeapBlock& ref ); - HRESULT LoadAssembly ( CLR_RT_Assembly* assm ); - HRESULT GetManagedObject ( CLR_RT_HeapBlock& obj ); + HRESULT VerifyTypeIsLoaded(const CLR_RT_TypeDef_Index &idx); + HRESULT GetAssemblies(CLR_RT_HeapBlock &ref); + HRESULT LoadAssembly(CLR_RT_Assembly *assm); + HRESULT GetManagedObject(CLR_RT_HeapBlock &obj); }; -struct CLR_RT_AppDomainAssembly : public CLR_RT_HeapBlock_Node //EVENT HEAP - NO RELOCATION - +struct CLR_RT_AppDomainAssembly : public CLR_RT_HeapBlock_Node // EVENT HEAP - NO RELOCATION - { static const CLR_UINT32 StaticConstructorsExecuted = 0x00000001; - CLR_UINT32 m_flags; - CLR_RT_AppDomain* m_appDomain; // EVENT HEAP - NO RELOCATION - - CLR_RT_Assembly* m_assembly; // EVENT HEAP - NO RELOCATION - - CLR_RT_HeapBlock* m_pStaticFields; // EVENT HEAP - NO RELOCATION - (but the data they point to has to be relocated) - + CLR_UINT32 m_flags; + CLR_RT_AppDomain *m_appDomain; // EVENT HEAP - NO RELOCATION - + CLR_RT_Assembly *m_assembly; // EVENT HEAP - NO RELOCATION - + CLR_RT_HeapBlock *m_pStaticFields; // EVENT HEAP - NO RELOCATION - (but the data they point to has to be relocated) - static HRESULT CreateInstance( CLR_RT_AppDomain* appDomain, CLR_RT_Assembly* assm, CLR_RT_AppDomainAssembly*& appDomainAssembly ); + static HRESULT CreateInstance( + CLR_RT_AppDomain *appDomain, + CLR_RT_Assembly *assm, + CLR_RT_AppDomainAssembly *&appDomainAssembly); - void DestroyInstance(); - HRESULT AppDomainAssembly_Initialize( CLR_RT_AppDomain* appDomain, CLR_RT_Assembly* assm ); + void DestroyInstance(); + HRESULT AppDomainAssembly_Initialize(CLR_RT_AppDomain *appDomain, CLR_RT_Assembly *assm); - void Relocate(); + void Relocate(); }; -#endif //NANOCLR_APPDOMAINS +#endif // NANOCLR_APPDOMAINS //--// @@ -1267,6 +1569,10 @@ struct CLR_RT_WellKnownTypes CLR_RT_TypeDef_Index m_I2cTransferResult; +#if (HAL_USE_ESP32_RMT_OPTION == TRUE) + CLR_RT_TypeDef_Index m_RmtCommand; +#endif + PROHIBIT_COPY_CONSTRUCTORS(CLR_RT_WellKnownTypes); }; @@ -1288,42 +1594,42 @@ typedef void (CLR_RT_HeapBlock::*CLR_RT_HeapBlockRelocate)(); struct CLR_RT_DataTypeLookup { - static const CLR_UINT8 c_NA = 0x00; - static const CLR_UINT8 c_VariableSize = 0xFF; - - static const CLR_UINT32 c_Primitive = 0x00000001; - static const CLR_UINT32 c_Interface = 0x00000002; - static const CLR_UINT32 c_Class = 0x00000004; - static const CLR_UINT32 c_ValueType = 0x00000008; - static const CLR_UINT32 c_Enum = 0x00000010; - static const CLR_UINT32 c_SemanticMask = 0x0000001F; - - static const CLR_UINT32 c_Array = 0x00000020; - static const CLR_UINT32 c_ArrayList = 0x00000040; - static const CLR_UINT32 c_SemanticMask2 = 0x0000007F; - - static const CLR_UINT32 c_Reference = 0x00010000; - static const CLR_UINT32 c_Numeric = 0x00020000; - static const CLR_UINT32 c_Integer = 0x00040000; - static const CLR_UINT32 c_Signed = 0x00080000; - static const CLR_UINT32 c_Direct = 0x00100000; // This isn't an indirect reference. + static const CLR_UINT8 c_NA = 0x00; + static const CLR_UINT8 c_VariableSize = 0xFF; + + static const CLR_UINT32 c_Primitive = 0x00000001; + static const CLR_UINT32 c_Interface = 0x00000002; + static const CLR_UINT32 c_Class = 0x00000004; + static const CLR_UINT32 c_ValueType = 0x00000008; + static const CLR_UINT32 c_Enum = 0x00000010; + static const CLR_UINT32 c_SemanticMask = 0x0000001F; + + static const CLR_UINT32 c_Array = 0x00000020; + static const CLR_UINT32 c_ArrayList = 0x00000040; + static const CLR_UINT32 c_SemanticMask2 = 0x0000007F; + + static const CLR_UINT32 c_Reference = 0x00010000; + static const CLR_UINT32 c_Numeric = 0x00020000; + static const CLR_UINT32 c_Integer = 0x00040000; + static const CLR_UINT32 c_Signed = 0x00080000; + static const CLR_UINT32 c_Direct = 0x00100000; // This isn't an indirect reference. static const CLR_UINT32 c_OptimizedValueType = 0x00200000; // A value type that is kept in a single HeapBlock. - static const CLR_UINT32 c_ManagedType = 0x00400000; // this dt represents a managed type, or a pointer to a managed type - // More specificly, TypeDescriptor::InitializeFromObject will succeed - // when starting from an object of with this dt + static const CLR_UINT32 c_ManagedType = 0x00400000; // this dt represents a managed type, or a pointer to a managed + // type More specificly, TypeDescriptor::InitializeFromObject + // will succeed when starting from an object of with this dt - CLR_UINT32 m_flags; - CLR_UINT8 m_sizeInBits; - CLR_UINT8 m_sizeInBytes; - CLR_UINT8 m_promoteTo; - CLR_UINT8 m_convertToElementType; + CLR_UINT32 m_flags; + CLR_UINT8 m_sizeInBits; + CLR_UINT8 m_sizeInBytes; + CLR_UINT8 m_promoteTo; + CLR_UINT8 m_convertToElementType; - CLR_RT_TypeDef_Index* m_cls; + CLR_RT_TypeDef_Index *m_cls; CLR_RT_HeapBlockRelocate m_relocate; #if defined(_WIN32) || defined(NANOCLR_TRACE_MEMORY_STATS) - const char* m_name; -#endif + const char *m_name; +#endif }; extern const CLR_RT_DataTypeLookup c_CLR_RT_DataTypeLookup[]; @@ -1332,62 +1638,77 @@ extern const CLR_RT_DataTypeLookup c_CLR_RT_DataTypeLookup[]; struct CLR_RT_OpcodeLookup { - static const CLR_UINT16 COND_BRANCH_NEVER = 0x0000; - static const CLR_UINT16 COND_BRANCH_ALWAYS = 0x0001; - static const CLR_UINT16 COND_BRANCH_IFTRUE = 0x0002; - static const CLR_UINT16 COND_BRANCH_IFFALSE = 0x0003; - static const CLR_UINT16 COND_BRANCH_IFEQUAL = 0x0004; - static const CLR_UINT16 COND_BRANCH_IFNOTEQUAL = 0x0005; - static const CLR_UINT16 COND_BRANCH_IFGREATER = 0x0006; + static const CLR_UINT16 COND_BRANCH_NEVER = 0x0000; + static const CLR_UINT16 COND_BRANCH_ALWAYS = 0x0001; + static const CLR_UINT16 COND_BRANCH_IFTRUE = 0x0002; + static const CLR_UINT16 COND_BRANCH_IFFALSE = 0x0003; + static const CLR_UINT16 COND_BRANCH_IFEQUAL = 0x0004; + static const CLR_UINT16 COND_BRANCH_IFNOTEQUAL = 0x0005; + static const CLR_UINT16 COND_BRANCH_IFGREATER = 0x0006; static const CLR_UINT16 COND_BRANCH_IFGREATEROREQUAL = 0x0007; - static const CLR_UINT16 COND_BRANCH_IFLESS = 0x0008; - static const CLR_UINT16 COND_BRANCH_IFLESSOREQUAL = 0x0009; - static const CLR_UINT16 COND_BRANCH_IFMATCH = 0x000A; - static const CLR_UINT16 COND_BRANCH_THROW = 0x000B; - static const CLR_UINT16 COND_BRANCH_MASK = 0x000F; - - static const CLR_UINT16 COND_OVERFLOW = 0x0010; - static const CLR_UINT16 COND_UNSIGNED = 0x0020; - - static const CLR_UINT16 STACK_RESET = 0x0080; - - static const CLR_UINT16 ATTRIB_HAS_TARGET = 0x0100; - static const CLR_UINT16 ATTRIB_HAS_DT = 0x0200; - static const CLR_UINT16 ATTRIB_HAS_INDEX = 0x0400; - static const CLR_UINT16 ATTRIB_HAS_TOKEN = 0x0800; - static const CLR_UINT16 ATTRIB_HAS_I4 = 0x1000; - static const CLR_UINT16 ATTRIB_HAS_R4 = 0x2000; - static const CLR_UINT16 ATTRIB_HAS_I8 = 0x4000; - static const CLR_UINT16 ATTRIB_HAS_R8 = 0x8000; + static const CLR_UINT16 COND_BRANCH_IFLESS = 0x0008; + static const CLR_UINT16 COND_BRANCH_IFLESSOREQUAL = 0x0009; + static const CLR_UINT16 COND_BRANCH_IFMATCH = 0x000A; + static const CLR_UINT16 COND_BRANCH_THROW = 0x000B; + static const CLR_UINT16 COND_BRANCH_MASK = 0x000F; + + static const CLR_UINT16 COND_OVERFLOW = 0x0010; + static const CLR_UINT16 COND_UNSIGNED = 0x0020; + + static const CLR_UINT16 STACK_RESET = 0x0080; + + static const CLR_UINT16 ATTRIB_HAS_TARGET = 0x0100; + static const CLR_UINT16 ATTRIB_HAS_DT = 0x0200; + static const CLR_UINT16 ATTRIB_HAS_INDEX = 0x0400; + static const CLR_UINT16 ATTRIB_HAS_TOKEN = 0x0800; + static const CLR_UINT16 ATTRIB_HAS_I4 = 0x1000; + static const CLR_UINT16 ATTRIB_HAS_R4 = 0x2000; + static const CLR_UINT16 ATTRIB_HAS_I8 = 0x4000; + static const CLR_UINT16 ATTRIB_HAS_R8 = 0x8000; #if defined(NANOCLR_OPCODE_NAMES) - const char* m_name; -#endif + const char *m_name; +#endif #if defined(NANOCLR_OPCODE_STACKCHANGES) - CLR_UINT8 m_stackChanges; + CLR_UINT8 m_stackChanges; #endif - CLR_OpcodeParam m_opParam; + CLR_OpcodeParam m_opParam; //--// #if defined(NANOCLR_OPCODE_PARSER) CLR_LOGICAL_OPCODE m_logicalOpcode; - CLR_DataType m_dt; - CLR_INT8 m_index; - CLR_UINT16 m_flags; + CLR_DataType m_dt; + CLR_INT8 m_index; + CLR_UINT16 m_flags; #endif #if defined(NANOCLR_OPCODE_STACKCHANGES) - CLR_UINT32 StackPop () const { return m_stackChanges >> 4; } - CLR_UINT32 StackPush () const { return m_stackChanges & 0xF; } - CLR_INT32 StackChanges() const { return StackPush() - StackPop(); } + CLR_UINT32 StackPop() const + { + return m_stackChanges >> 4; + } + CLR_UINT32 StackPush() const + { + return m_stackChanges & 0xF; + } + CLR_INT32 StackChanges() const + { + return StackPush() - StackPop(); + } #endif #if defined(NANOCLR_OPCODE_NAMES) - const char* Name() const { return m_name; } + const char *Name() const + { + return m_name; + } #else - const char* Name() const { return ""; } + const char *Name() const + { + return ""; + } #endif }; @@ -1397,23 +1718,28 @@ extern const CLR_RT_OpcodeLookup c_CLR_RT_OpcodeLookup[]; struct CLR_RT_LogicalOpcodeLookup { - static const CLR_UINT32 RESTARTPOINT_NEXT = 0x00000001; - static const CLR_UINT32 EXCEPTION = 0x00000002; - static const CLR_UINT32 EXCEPTION_IF_OVERFLOW = 0x00000010; - static const CLR_UINT32 EXCEPTION_IF_ZERO = 0x00000020; - static const CLR_UINT32 EXCEPTION_ON_CAST = 0x00000040; + static const CLR_UINT32 RESTARTPOINT_NEXT = 0x00000001; + static const CLR_UINT32 EXCEPTION = 0x00000002; + static const CLR_UINT32 EXCEPTION_IF_OVERFLOW = 0x00000010; + static const CLR_UINT32 EXCEPTION_IF_ZERO = 0x00000020; + static const CLR_UINT32 EXCEPTION_ON_CAST = 0x00000040; #if defined(NANOCLR_OPCODE_NAMES) - const char* m_name; + const char *m_name; #endif CLR_UINT32 m_flags; - #if defined(NANOCLR_OPCODE_NAMES) - const char* Name() const { return m_name; } + const char *Name() const + { + return m_name; + } #else - const char* Name() const { return ""; } + const char *Name() const + { + return ""; + } #endif }; @@ -1421,12 +1747,11 @@ extern const CLR_RT_LogicalOpcodeLookup c_CLR_RT_LogicalOpcodeLookup[]; //--// - struct CLR_RT_TypeSystem // EVENT HEAP - NO RELOCATION - { struct CompatibilityLookup { - const char* name; + const char *name; CLR_RECORD_VERSION version; }; @@ -1436,15 +1761,15 @@ struct CLR_RT_TypeSystem // EVENT HEAP - NO RELOCATION - //--// - static const CLR_UINT32 TYPENAME_FLAGS_FULL = 0x1; + static const CLR_UINT32 TYPENAME_FLAGS_FULL = 0x1; static const CLR_UINT32 TYPENAME_NESTED_SEPARATOR_DOT = 0x2; //--// - CLR_RT_Assembly* m_assemblies[ c_MaxAssemblies ]; // EVENT HEAP - NO RELOCATION - array of CLR_RT_Assembly - size_t m_assembliesMax; - CLR_RT_Assembly* m_assemblyMscorlib; - CLR_RT_Assembly* m_assemblyNative; + CLR_RT_Assembly *m_assemblies[c_MaxAssemblies]; // EVENT HEAP - NO RELOCATION - array of CLR_RT_Assembly + size_t m_assembliesMax; + CLR_RT_Assembly *m_assemblyMscorlib; + CLR_RT_Assembly *m_assemblyNative; CLR_RT_MethodDef_Index m_entryPoint; @@ -1453,43 +1778,66 @@ struct CLR_RT_TypeSystem // EVENT HEAP - NO RELOCATION - void TypeSystem_Initialize(); void TypeSystem_Cleanup(); - void Link ( CLR_RT_Assembly* assm ); - void PostLinkageProcessing( CLR_RT_Assembly* assm ); - - HRESULT ResolveAll ( ); - HRESULT PrepareForExecution ( ); - HRESULT PrepareForExecutionHelper( const char* szAssembly ); + void Link(CLR_RT_Assembly *assm); + void PostLinkageProcessing(CLR_RT_Assembly *assm); - CLR_RT_Assembly* FindAssembly( const char* name, const CLR_RECORD_VERSION* ver, bool fExact ); - - bool FindTypeDef ( const char* name, const char* nameSpace, CLR_RT_Assembly* assm, CLR_RT_TypeDef_Index& res ); - bool FindTypeDef ( const char* name, CLR_RT_Assembly* assm, CLR_RT_TypeDef_Index& res ); - bool FindTypeDef ( const char* name, const char* nameSpace, CLR_RT_TypeDef_Index& res ); - bool FindTypeDef ( CLR_UINT32 hash , CLR_RT_TypeDef_Index& res ); - bool FindTypeDef ( const char* name , CLR_RT_TypeDef_Index& res ); - bool FindTypeDef ( const char* name , CLR_RT_Assembly* assm, CLR_RT_ReflectionDef_Index& reflex ); - - HRESULT LocateResourceFile( CLR_RT_Assembly_Instance assm, const char* name, CLR_INT32& idxResourceFile ); - HRESULT LocateResource ( CLR_RT_Assembly_Instance assm, CLR_INT32 idxResourceFile, CLR_INT16 id, const CLR_RECORD_RESOURCE*& res, CLR_UINT32& size ); - - HRESULT BuildTypeName ( const CLR_RT_TypeDef_Index& cls, char*& szBuffer, size_t& size, CLR_UINT32 flags, CLR_UINT32 levels ); - HRESULT BuildTypeName ( const CLR_RT_TypeDef_Index& cls, char*& szBuffer, size_t& size ); - HRESULT BuildMethodName ( const CLR_RT_MethodDef_Index& md , char*& szBuffer, size_t& size ); - HRESULT BuildFieldName ( const CLR_RT_FieldDef_Index& fd , char*& szBuffer, size_t& size ); - HRESULT QueueStringToBuffer( char*& szBuffer, size_t& size, const char* szText ); - - bool FindVirtualMethodDef( const CLR_RT_TypeDef_Index& cls, const CLR_RT_MethodDef_Index& calleeMD , CLR_RT_MethodDef_Index& idx ); - bool FindVirtualMethodDef( const CLR_RT_TypeDef_Index& cls, const CLR_RT_MethodDef_Index& calleeMD, const char* calleeName, CLR_RT_MethodDef_Index& idx ); - - static bool MatchSignature ( CLR_RT_SignatureParser& parserLeft , CLR_RT_SignatureParser& parserRight ); - static bool MatchSignatureDirect ( CLR_RT_SignatureParser& parserLeft , CLR_RT_SignatureParser& parserRight , bool fIsInstanceOfOK ); - static bool MatchSignatureElement( CLR_RT_SignatureParser::Element& resLeft, CLR_RT_SignatureParser::Element& resRight, bool fIsInstanceOfOK ); - - static CLR_DataType MapElementTypeToDataType( CLR_UINT32 et ); - static CLR_UINT32 MapDataTypeToElementType( CLR_DataType dt ); + HRESULT ResolveAll(); + HRESULT PrepareForExecution(); + HRESULT PrepareForExecutionHelper(const char *szAssembly); + + CLR_RT_Assembly *FindAssembly(const char *name, const CLR_RECORD_VERSION *ver, bool fExact); + + bool FindTypeDef(const char *name, const char *nameSpace, CLR_RT_Assembly *assm, CLR_RT_TypeDef_Index &res); + bool FindTypeDef(const char *name, CLR_RT_Assembly *assm, CLR_RT_TypeDef_Index &res); + bool FindTypeDef(const char *name, const char *nameSpace, CLR_RT_TypeDef_Index &res); + bool FindTypeDef(CLR_UINT32 hash, CLR_RT_TypeDef_Index &res); + bool FindTypeDef(const char *name, CLR_RT_TypeDef_Index &res); + bool FindTypeDef(const char *name, CLR_RT_Assembly *assm, CLR_RT_ReflectionDef_Index &reflex); + + HRESULT LocateResourceFile(CLR_RT_Assembly_Instance assm, const char *name, CLR_INT32 &idxResourceFile); + HRESULT LocateResource( + CLR_RT_Assembly_Instance assm, + CLR_INT32 idxResourceFile, + CLR_INT16 id, + const CLR_RECORD_RESOURCE *&res, + CLR_UINT32 &size); + + HRESULT BuildTypeName( + const CLR_RT_TypeDef_Index &cls, + char *&szBuffer, + size_t &size, + CLR_UINT32 flags, + CLR_UINT32 levels); + HRESULT BuildTypeName(const CLR_RT_TypeDef_Index &cls, char *&szBuffer, size_t &size); + HRESULT BuildMethodName(const CLR_RT_MethodDef_Index &md, char *&szBuffer, size_t &size); + HRESULT BuildFieldName(const CLR_RT_FieldDef_Index &fd, char *&szBuffer, size_t &size); + HRESULT QueueStringToBuffer(char *&szBuffer, size_t &size, const char *szText); + + bool FindVirtualMethodDef( + const CLR_RT_TypeDef_Index &cls, + const CLR_RT_MethodDef_Index &calleeMD, + CLR_RT_MethodDef_Index &idx); + bool FindVirtualMethodDef( + const CLR_RT_TypeDef_Index &cls, + const CLR_RT_MethodDef_Index &calleeMD, + const char *calleeName, + CLR_RT_MethodDef_Index &idx); + + static bool MatchSignature(CLR_RT_SignatureParser &parserLeft, CLR_RT_SignatureParser &parserRight); + static bool MatchSignatureDirect( + CLR_RT_SignatureParser &parserLeft, + CLR_RT_SignatureParser &parserRight, + bool fIsInstanceOfOK); + static bool MatchSignatureElement( + CLR_RT_SignatureParser::Element &resLeft, + CLR_RT_SignatureParser::Element &resRight, + bool fIsInstanceOfOK); + + static CLR_DataType MapElementTypeToDataType(CLR_UINT32 et); + static CLR_UINT32 MapDataTypeToElementType(CLR_DataType dt); #if defined(_WIN32) - void Dump( const wchar_t* szFileName, bool fNoByteCode ); + void Dump(const wchar_t *szFileName, bool fNoByteCode); #endif //--// @@ -1503,51 +1851,54 @@ extern CLR_RT_TypeSystem g_CLR_RT_TypeSystem; struct CLR_RT_Assembly_Instance : public CLR_RT_Assembly_Index { - CLR_RT_Assembly* m_assm; + CLR_RT_Assembly *m_assm; //--// - bool InitializeFromIndex( const CLR_RT_Assembly_Index& idx ); - void Clear ( ); + bool InitializeFromIndex(const CLR_RT_Assembly_Index &idx); + void Clear(); }; struct CLR_RT_TypeSpec_Instance : public CLR_RT_TypeSpec_Index { - CLR_RT_Assembly* m_assm; - CLR_PMETADATA m_target; + CLR_RT_Assembly *m_assm; + CLR_PMETADATA m_target; //--// - bool InitializeFromIndex( const CLR_RT_TypeSpec_Index& idx ); - void Clear ( ); + bool InitializeFromIndex(const CLR_RT_TypeSpec_Index &idx); + void Clear(); - bool ResolveToken( CLR_UINT32 tk, CLR_RT_Assembly* assm ); + bool ResolveToken(CLR_UINT32 tk, CLR_RT_Assembly *assm); }; //--// struct CLR_RT_TypeDef_Instance : public CLR_RT_TypeDef_Index { - CLR_RT_Assembly* m_assm; - const CLR_RECORD_TYPEDEF* m_target; + CLR_RT_Assembly *m_assm; + const CLR_RECORD_TYPEDEF *m_target; //--// - bool InitializeFromReflection ( const CLR_RT_ReflectionDef_Index& reflex, CLR_UINT32* levels ); - bool InitializeFromIndex ( const CLR_RT_TypeDef_Index& idx ); - bool InitializeFromMethod ( const CLR_RT_MethodDef_Instance& md ); - bool InitializeFromField ( const CLR_RT_FieldDef_Instance& fd ); + bool InitializeFromReflection(const CLR_RT_ReflectionDef_Index &reflex, CLR_UINT32 *levels); + bool InitializeFromIndex(const CLR_RT_TypeDef_Index &idx); + bool InitializeFromMethod(const CLR_RT_MethodDef_Instance &md); + bool InitializeFromField(const CLR_RT_FieldDef_Instance &fd); - void Clear ( ); + void Clear(); - bool ResolveToken( CLR_UINT32 tk, CLR_RT_Assembly* assm ); + bool ResolveToken(CLR_UINT32 tk, CLR_RT_Assembly *assm); //--// - CLR_RT_TypeDef_CrossReference& CrossReference() const { return m_assm->m_pCrossReference_TypeDef[ Type() ]; } + CLR_RT_TypeDef_CrossReference &CrossReference() const + { + return m_assm->m_pCrossReference_TypeDef[Type()]; + } bool SwitchToParent(); - bool HasFinalizer () const; + bool HasFinalizer() const; bool IsATypeHandler(); }; @@ -1556,70 +1907,81 @@ struct CLR_RT_TypeDef_Instance : public CLR_RT_TypeDef_Index struct CLR_RT_FieldDef_Instance : public CLR_RT_FieldDef_Index { - CLR_RT_Assembly* m_assm; - const CLR_RECORD_FIELDDEF* m_target; + CLR_RT_Assembly *m_assm; + const CLR_RECORD_FIELDDEF *m_target; //--// - bool InitializeFromIndex( const CLR_RT_FieldDef_Index& idx ); - void Clear ( ); + bool InitializeFromIndex(const CLR_RT_FieldDef_Index &idx); + void Clear(); - bool ResolveToken( CLR_UINT32 tk, CLR_RT_Assembly* assm ); + bool ResolveToken(CLR_UINT32 tk, CLR_RT_Assembly *assm); //--// - CLR_RT_FieldDef_CrossReference& CrossReference() const { return m_assm->m_pCrossReference_FieldDef[ Field() ]; } + CLR_RT_FieldDef_CrossReference &CrossReference() const + { + return m_assm->m_pCrossReference_FieldDef[Field()]; + } }; //--// struct CLR_RT_MethodDef_Instance : public CLR_RT_MethodDef_Index { - CLR_RT_Assembly* m_assm; - const CLR_RECORD_METHODDEF* m_target; + CLR_RT_Assembly *m_assm; + const CLR_RECORD_METHODDEF *m_target; //--// - bool InitializeFromIndex( const CLR_RT_MethodDef_Index& idx ); - void Clear ( ); + bool InitializeFromIndex(const CLR_RT_MethodDef_Index &idx); + void Clear(); - bool ResolveToken( CLR_UINT32 tk, CLR_RT_Assembly* assm ); + bool ResolveToken(CLR_UINT32 tk, CLR_RT_Assembly *assm); //--// - CLR_RT_MethodDef_CrossReference& CrossReference() const { return m_assm->m_pCrossReference_MethodDef[ Method() ]; } - CLR_UINT32 Hits() const { return 0; } + CLR_RT_MethodDef_CrossReference &CrossReference() const + { + return m_assm->m_pCrossReference_MethodDef[Method()]; + } + CLR_UINT32 Hits() const + { + return 0; + } #if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) - CLR_RT_MethodDef_DebuggingInfo& DebuggingInfo() const { return m_assm->m_pDebuggingInfo_MethodDef[ Method() ]; } + CLR_RT_MethodDef_DebuggingInfo &DebuggingInfo() const + { + return m_assm->m_pDebuggingInfo_MethodDef[Method()]; + } #endif //#if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) }; - //////////////////////////////////////////////////////////////////////////////////////////////////// struct CLR_RT_AttributeEnumerator { - CLR_RT_Assembly* m_assm; - const CLR_RECORD_ATTRIBUTE* m_ptr; - int m_num; - CLR_RECORD_ATTRIBUTE m_data; + CLR_RT_Assembly *m_assm; + const CLR_RECORD_ATTRIBUTE *m_ptr; + int m_num; + CLR_RECORD_ATTRIBUTE m_data; - CLR_RT_MethodDef_Index m_match; - CLR_PMETADATA m_blob; + CLR_RT_MethodDef_Index m_match; + CLR_PMETADATA m_blob; - void Initialize( const CLR_RT_TypeDef_Instance & inst ); - void Initialize( const CLR_RT_FieldDef_Instance & inst ); - void Initialize( const CLR_RT_MethodDef_Instance& inst ); + void Initialize(const CLR_RT_TypeDef_Instance &inst); + void Initialize(const CLR_RT_FieldDef_Instance &inst); + void Initialize(const CLR_RT_MethodDef_Instance &inst); bool Advance(); - bool MatchNext( const CLR_RT_TypeDef_Instance* instTD, const CLR_RT_MethodDef_Instance* instMD ); + bool MatchNext(const CLR_RT_TypeDef_Instance *instTD, const CLR_RT_MethodDef_Instance *instMD); + + void GetCurrent(CLR_RT_TypeDef_Instance *instTD); - void GetCurrent(CLR_RT_TypeDef_Instance* instTD); - -private: - void Initialize( CLR_RT_Assembly* assm ); + private: + void Initialize(CLR_RT_Assembly *assm); }; struct CLR_RT_AttributeParser @@ -1627,74 +1989,77 @@ struct CLR_RT_AttributeParser struct Value { static const int c_ConstructorArgument = 1; - static const int c_NamedField = 2; - static const int c_NamedProperty = 3; - static const int c_DefaultConstructor = 4; + static const int c_NamedField = 2; + static const int c_NamedProperty = 3; + static const int c_DefaultConstructor = 4; - int m_mode; + int m_mode; CLR_RT_HeapBlock m_value; - int m_pos; - const char* m_name; + int m_pos; + const char *m_name; }; //--// - CLR_RT_Assembly* m_assm; - CLR_PMETADATA m_blob; + CLR_RT_Assembly *m_assm; + CLR_PMETADATA m_blob; - CLR_RT_MethodDef_Instance m_md; - CLR_RT_MethodDef_Index m_mdIdx; - CLR_RT_TypeDef_Instance m_td; - CLR_RT_SignatureParser m_parser; + CLR_RT_MethodDef_Instance m_md; + CLR_RT_MethodDef_Index m_mdIdx; + CLR_RT_TypeDef_Instance m_td; + CLR_RT_SignatureParser m_parser; CLR_RT_SignatureParser::Element m_res; - int m_currentPos; - int m_fixed_Count; - int m_named_Count; - Value m_lastValue; - bool m_constructorParsed; + int m_currentPos; + int m_fixed_Count; + int m_named_Count; + Value m_lastValue; + bool m_constructorParsed; //--// - HRESULT Initialize( const CLR_RT_AttributeEnumerator& en ); + HRESULT Initialize(const CLR_RT_AttributeEnumerator &en); - HRESULT Next( Value*& res ); + HRESULT Next(Value *&res); -private: - const char* GetString(); + private: + const char *GetString(); }; //////////////////////////////////////////////////////////////////////////////// struct CLR_RT_TypeDescriptor { - CLR_UINT32 m_flags; - CLR_RT_TypeDef_Instance m_handlerCls; + CLR_UINT32 m_flags; + CLR_RT_TypeDef_Instance m_handlerCls; CLR_RT_ReflectionDef_Index m_reflex; - CLR_DataType GetDataType() const { return (CLR_DataType)m_handlerCls.m_target->dataType; } + CLR_DataType GetDataType() const + { + return (CLR_DataType)m_handlerCls.m_target->dataType; + } //--// void TypeDescriptor_Initialize(); - HRESULT InitializeFromDataType ( CLR_DataType dt ); - HRESULT InitializeFromReflection ( const CLR_RT_ReflectionDef_Index& reflex ); - HRESULT InitializeFromTypeSpec ( const CLR_RT_TypeSpec_Index& sig ); - HRESULT InitializeFromType ( const CLR_RT_TypeDef_Index& cls ); - HRESULT InitializeFromFieldDefinition( const CLR_RT_FieldDef_Instance& fd ); - HRESULT InitializeFromSignatureParser( CLR_RT_SignatureParser& parser ); - HRESULT InitializeFromObject ( const CLR_RT_HeapBlock& ref ); + HRESULT InitializeFromDataType(CLR_DataType dt); + HRESULT InitializeFromReflection(const CLR_RT_ReflectionDef_Index &reflex); + HRESULT InitializeFromTypeSpec(const CLR_RT_TypeSpec_Index &sig); + HRESULT InitializeFromType(const CLR_RT_TypeDef_Index &cls); + HRESULT InitializeFromFieldDefinition(const CLR_RT_FieldDef_Instance &fd); + HRESULT InitializeFromSignatureParser(CLR_RT_SignatureParser &parser); + HRESULT InitializeFromObject(const CLR_RT_HeapBlock &ref); void ConvertToArray(); bool ShouldEmitHash(); - bool GetElementType( CLR_RT_TypeDescriptor& sub ); + bool GetElementType(CLR_RT_TypeDescriptor &sub); - static HRESULT ExtractTypeIndexFromObject( const CLR_RT_HeapBlock& ref, CLR_RT_TypeDef_Index& res ); - static HRESULT ExtractObjectAndDataType( CLR_RT_HeapBlock*& ref, CLR_DataType& dt ); + static HRESULT ExtractTypeIndexFromObject(const CLR_RT_HeapBlock &ref, CLR_RT_TypeDef_Index &res); + static HRESULT ExtractObjectAndDataType(CLR_RT_HeapBlock *&ref, CLR_DataType &dt); }; #include @@ -1708,29 +2073,31 @@ struct CLR_RT_TypeDescriptor struct CLR_RT_HeapCluster : public CLR_RT_HeapBlock_Node // EVENT HEAP - NO RELOCATION - { - CLR_RT_DblLinkedList m_freeList; // list of CLR_RT_HeapBlock_Node - CLR_RT_HeapBlock_Node* m_payloadStart; - CLR_RT_HeapBlock_Node* m_payloadEnd; + CLR_RT_DblLinkedList m_freeList; // list of CLR_RT_HeapBlock_Node + CLR_RT_HeapBlock_Node *m_payloadStart; + CLR_RT_HeapBlock_Node *m_payloadEnd; //--// - void HeapCluster_Initialize( CLR_UINT32 size, CLR_UINT32 blockSize ); // Memory is not erased by the caller. + void HeapCluster_Initialize(CLR_UINT32 size, CLR_UINT32 blockSize); // Memory is not erased by the caller. - CLR_RT_HeapBlock* ExtractBlocks( CLR_UINT32 dataType, CLR_UINT32 flags, CLR_UINT32 length ); + CLR_RT_HeapBlock *ExtractBlocks(CLR_UINT32 dataType, CLR_UINT32 flags, CLR_UINT32 length); void RecoverFromGC(); - CLR_RT_HeapBlock_Node* InsertInOrder( CLR_RT_HeapBlock_Node* node, CLR_UINT32 size ); + CLR_RT_HeapBlock_Node *InsertInOrder(CLR_RT_HeapBlock_Node *node, CLR_UINT32 size); //--// - #undef DECL_POSTFIX - #if NANOCLR_VALIDATE_HEAP >= NANOCLR_VALIDATE_HEAP_1_HeapBlocksAndUnlink - #define DECL_POSTFIX - #else - #define DECL_POSTFIX {} - #endif - void ValidateBlock( CLR_RT_HeapBlock* ptr ) DECL_POSTFIX; +#undef DECL_POSTFIX +#if NANOCLR_VALIDATE_HEAP >= NANOCLR_VALIDATE_HEAP_1_HeapBlocksAndUnlink +#define DECL_POSTFIX +#else +#define DECL_POSTFIX \ + { \ + } +#endif + void ValidateBlock(CLR_RT_HeapBlock *ptr) DECL_POSTFIX; //--// @@ -1746,22 +2113,21 @@ struct CLR_RT_HeapCluster : public CLR_RT_HeapBlock_Node // EVENT HEAP - NO RELO #ifndef CLR_NO_IL_INLINE struct CLR_RT_InlineFrame { - CLR_RT_HeapBlock* m_locals; - CLR_RT_HeapBlock* m_args; - CLR_RT_HeapBlock* m_evalStack; - CLR_RT_HeapBlock* m_evalPos; + CLR_RT_HeapBlock *m_locals; + CLR_RT_HeapBlock *m_args; + CLR_RT_HeapBlock *m_evalStack; + CLR_RT_HeapBlock *m_evalPos; CLR_RT_MethodDef_Instance m_call; - CLR_PMETADATA m_IP; - CLR_PMETADATA m_IPStart; + CLR_PMETADATA m_IP; + CLR_PMETADATA m_IPStart; }; struct CLR_RT_InlineBuffer { - union - { - CLR_RT_InlineBuffer* m_pNext; + union { + CLR_RT_InlineBuffer *m_pNext; - CLR_RT_InlineFrame m_frame; + CLR_RT_InlineFrame m_frame; }; }; #endif @@ -1773,55 +2139,55 @@ struct CLR_RT_InlineBuffer struct CLR_RT_StackFrame : public CLR_RT_HeapBlock_Node // EVENT HEAP - NO RELOCATION - { - static const int c_OverheadForNewObjOrInteropMethod = 2; // We need to have more slots in the stack to process a 'newobj' opcode. - static const int c_MinimumStack = 10; - + static const int c_OverheadForNewObjOrInteropMethod = + 2; // We need to have more slots in the stack to process a 'newobj' opcode. + static const int c_MinimumStack = 10; - static const CLR_UINT32 c_MethodKind_Native = 0x00000000; - static const CLR_UINT32 c_MethodKind_Interpreted = 0x00000001; - static const CLR_UINT32 c_UNUSED_00000002 = 0x00000002; // c_MethodKind_Jitted - static const CLR_UINT32 c_MethodKind_Mask = 0x00000003; + static const CLR_UINT32 c_MethodKind_Native = 0x00000000; + static const CLR_UINT32 c_MethodKind_Interpreted = 0x00000001; + static const CLR_UINT32 c_UNUSED_00000002 = 0x00000002; // c_MethodKind_Jitted + static const CLR_UINT32 c_MethodKind_Mask = 0x00000003; - static const CLR_UINT32 c_NativeProfiled = 0x00000004; - static const CLR_UINT32 c_MethodKind_Inlined = 0x00000008; + static const CLR_UINT32 c_NativeProfiled = 0x00000004; + static const CLR_UINT32 c_MethodKind_Inlined = 0x00000008; - static const CLR_UINT32 c_ExecutingConstructor = 0x00000010; + static const CLR_UINT32 c_ExecutingConstructor = 0x00000010; static const CLR_UINT32 c_CompactAndRestartOnOutOfMemory = 0x00000020; - static const CLR_UINT32 c_CallOnPop = 0x00000040; - static const CLR_UINT32 c_CalledOnPop = 0x00000080; + static const CLR_UINT32 c_CallOnPop = 0x00000040; + static const CLR_UINT32 c_CalledOnPop = 0x00000080; - static const CLR_UINT32 c_NeedToSynchronize = 0x00000100; - static const CLR_UINT32 c_PendingSynchronize = 0x00000200; - static const CLR_UINT32 c_Synchronized = 0x00000400; - static const CLR_UINT32 c_UNUSED_00000800 = 0x00000800; + static const CLR_UINT32 c_NeedToSynchronize = 0x00000100; + static const CLR_UINT32 c_PendingSynchronize = 0x00000200; + static const CLR_UINT32 c_Synchronized = 0x00000400; + static const CLR_UINT32 c_UNUSED_00000800 = 0x00000800; - static const CLR_UINT32 c_NeedToSynchronizeGlobally = 0x00001000; - static const CLR_UINT32 c_PendingSynchronizeGlobally = 0x00002000; - static const CLR_UINT32 c_SynchronizedGlobally = 0x00004000; - static const CLR_UINT32 c_UNUSED_00008000 = 0x00008000; + static const CLR_UINT32 c_NeedToSynchronizeGlobally = 0x00001000; + static const CLR_UINT32 c_PendingSynchronizeGlobally = 0x00002000; + static const CLR_UINT32 c_SynchronizedGlobally = 0x00004000; + static const CLR_UINT32 c_UNUSED_00008000 = 0x00008000; - static const CLR_UINT32 c_ExecutingIL = 0x00010000; - static const CLR_UINT32 c_CallerIsCompatibleForCall = 0x00020000; - static const CLR_UINT32 c_CallerIsCompatibleForRet = 0x00040000; - static const CLR_UINT32 c_PseudoStackFrameForFilter = 0x00080000; + static const CLR_UINT32 c_ExecutingIL = 0x00010000; + static const CLR_UINT32 c_CallerIsCompatibleForCall = 0x00020000; + static const CLR_UINT32 c_CallerIsCompatibleForRet = 0x00040000; + static const CLR_UINT32 c_PseudoStackFrameForFilter = 0x00080000; - static const CLR_UINT32 c_InlineMethodHasReturnValue = 0x00100000; - static const CLR_UINT32 c_UNUSED_00200000 = 0x00200000; - static const CLR_UINT32 c_UNUSED_00400000 = 0x00400000; - static const CLR_UINT32 c_UNUSED_00800000 = 0x00800000; + static const CLR_UINT32 c_InlineMethodHasReturnValue = 0x00100000; + static const CLR_UINT32 c_UNUSED_00200000 = 0x00200000; + static const CLR_UINT32 c_UNUSED_00400000 = 0x00400000; + static const CLR_UINT32 c_UNUSED_00800000 = 0x00800000; - static const CLR_UINT32 c_UNUSED_01000000 = 0x01000000; - static const CLR_UINT32 c_UNUSED_02000000 = 0x02000000; + static const CLR_UINT32 c_UNUSED_01000000 = 0x01000000; + static const CLR_UINT32 c_UNUSED_02000000 = 0x02000000; - static const CLR_UINT32 c_AppDomainMethodInvoke = 0x04000000; - static const CLR_UINT32 c_AppDomainInjectException = 0x08000000; - static const CLR_UINT32 c_AppDomainTransition = 0x10000000; - static const CLR_UINT32 c_InvalidIP = 0x20000000; - static const CLR_UINT32 c_UNUSED_40000000 = 0x40000000; - static const CLR_UINT32 c_HasBreakpoint = 0x80000000; + static const CLR_UINT32 c_AppDomainMethodInvoke = 0x04000000; + static const CLR_UINT32 c_AppDomainInjectException = 0x08000000; + static const CLR_UINT32 c_AppDomainTransition = 0x10000000; + static const CLR_UINT32 c_InvalidIP = 0x20000000; + static const CLR_UINT32 c_UNUSED_40000000 = 0x40000000; + static const CLR_UINT32 c_HasBreakpoint = 0x80000000; - static const CLR_UINT32 c_ProcessSynchronize = c_NeedToSynchronize | c_PendingSynchronize | - c_NeedToSynchronizeGlobally | c_PendingSynchronizeGlobally ; + static const CLR_UINT32 c_ProcessSynchronize = + c_NeedToSynchronize | c_PendingSynchronize | c_NeedToSynchronizeGlobally | c_PendingSynchronizeGlobally; //--// @@ -1829,107 +2195,113 @@ struct CLR_RT_StackFrame : public CLR_RT_HeapBlock_Node // EVENT HEAP - NO RELOC // // These fields have to be aligned // - CLR_RT_Thread* m_owningThread; // EVENT HEAP - NO RELOCATION - - CLR_RT_HeapBlock* m_evalStack; // EVENT HEAP - NO RELOCATION - - CLR_RT_HeapBlock* m_arguments; // EVENT HEAP - NO RELOCATION - - CLR_RT_HeapBlock* m_locals; // EVENT HEAP - NO RELOCATION - - CLR_PMETADATA m_IP; // ANY HEAP - DO RELOCATION - + CLR_RT_Thread *m_owningThread; // EVENT HEAP - NO RELOCATION - + CLR_RT_HeapBlock *m_evalStack; // EVENT HEAP - NO RELOCATION - + CLR_RT_HeapBlock *m_arguments; // EVENT HEAP - NO RELOCATION - + CLR_RT_HeapBlock *m_locals; // EVENT HEAP - NO RELOCATION - + CLR_PMETADATA m_IP; // ANY HEAP - DO RELOCATION - // /////////////////////////////////////////////////////////////////////////////////////////// - CLR_RT_SubThread* m_owningSubThread; // EVENT HEAP - NO RELOCATION - - CLR_UINT32 m_flags; + CLR_RT_SubThread *m_owningSubThread; // EVENT HEAP - NO RELOCATION - + CLR_UINT32 m_flags; CLR_RT_MethodDef_Instance m_call; - CLR_RT_MethodHandler m_nativeMethod; - CLR_PMETADATA m_IPstart; // ANY HEAP - DO RELOCATION - + CLR_RT_MethodHandler m_nativeMethod; + CLR_PMETADATA m_IPstart; // ANY HEAP - DO RELOCATION - - CLR_RT_HeapBlock* m_evalStackPos; // EVENT HEAP - NO RELOCATION - - CLR_RT_HeapBlock* m_evalStackEnd; // EVENT HEAP - NO RELOCATION - + CLR_RT_HeapBlock *m_evalStackPos; // EVENT HEAP - NO RELOCATION - + CLR_RT_HeapBlock *m_evalStackEnd; // EVENT HEAP - NO RELOCATION - - union - { - CLR_UINT32 m_customState; - void* m_customPointer; + union { + CLR_UINT32 m_customState; + void *m_customPointer; }; +#ifndef CLR_NO_IL_INLINE + CLR_RT_InlineBuffer *m_inlineFrame; +#endif - #ifndef CLR_NO_IL_INLINE - CLR_RT_InlineBuffer* m_inlineFrame; - #endif - - #if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) - CLR_UINT32 m_depth; - #endif //#if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) +#if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) + CLR_UINT32 m_depth; +#endif //#if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) - #if defined(NANOCLR_PROFILE_NEW_CALLS) +#if defined(NANOCLR_PROFILE_NEW_CALLS) CLR_PROF_CounterCallChain m_callchain; - #endif +#endif - #if defined(NANOCLR_APPDOMAINS) - CLR_RT_AppDomain* m_appDomain; - #endif +#if defined(NANOCLR_APPDOMAINS) + CLR_RT_AppDomain *m_appDomain; +#endif - #if defined(ENABLE_NATIVE_PROFILER) - bool m_fNativeProfiled; - #endif +#if defined(ENABLE_NATIVE_PROFILER) + bool m_fNativeProfiled; +#endif - CLR_RT_HeapBlock m_extension[ 1 ]; + CLR_RT_HeapBlock m_extension[1]; //////////////////////////////////////// - static HRESULT Push( CLR_RT_Thread* th, const CLR_RT_MethodDef_Instance& callInst, CLR_INT32 extraBlocks ); + static HRESULT Push(CLR_RT_Thread *th, const CLR_RT_MethodDef_Instance &callInst, CLR_INT32 extraBlocks); void Pop(); - #ifndef CLR_NO_IL_INLINE - bool PushInline( CLR_PMETADATA& ip, CLR_RT_Assembly*& assm, CLR_RT_HeapBlock*& evalPos, CLR_RT_MethodDef_Instance& calleeInst, CLR_RT_HeapBlock* pThis); - void PopInline ( ); +#ifndef CLR_NO_IL_INLINE + bool PushInline( + CLR_PMETADATA &ip, + CLR_RT_Assembly *&assm, + CLR_RT_HeapBlock *&evalPos, + CLR_RT_MethodDef_Instance &calleeInst, + CLR_RT_HeapBlock *pThis); + void PopInline(); void RestoreFromInlineStack(); - void RestoreStack(CLR_RT_InlineFrame& frame); - void SaveStack(CLR_RT_InlineFrame& frame); - #endif - + void RestoreStack(CLR_RT_InlineFrame &frame); + void SaveStack(CLR_RT_InlineFrame &frame); +#endif - #if defined(NANOCLR_APPDOMAINS) - static HRESULT PushAppDomainTransition( CLR_RT_Thread* th, const CLR_RT_MethodDef_Instance& callInst, CLR_RT_HeapBlock* pThis, CLR_RT_HeapBlock* pArgs ); - HRESULT PopAppDomainTransition( ); - #endif +#if defined(NANOCLR_APPDOMAINS) + static HRESULT PushAppDomainTransition( + CLR_RT_Thread *th, + const CLR_RT_MethodDef_Instance &callInst, + CLR_RT_HeapBlock *pThis, + CLR_RT_HeapBlock *pArgs); + HRESULT PopAppDomainTransition(); +#endif HRESULT FixCall(); - HRESULT MakeCall ( CLR_RT_MethodDef_Instance md, CLR_RT_HeapBlock* blkThis, CLR_RT_HeapBlock* blkArgs, int nArgs ); - - HRESULT HandleSynchronized( bool fAcquire, bool fGlobal ); - - void SetResult ( CLR_INT32 val, CLR_DataType dataType ); - void SetResult_I1 ( CLR_UINT8 val ); - void SetResult_I2 ( CLR_INT16 val ); - void SetResult_I4 ( CLR_INT32 val ); - void SetResult_I8 ( CLR_INT64& val ); - void SetResult_U1 ( CLR_INT8 val ); - void SetResult_U2 ( CLR_UINT16 val ); - void SetResult_U4 ( CLR_UINT32 val ); - void SetResult_U8 ( CLR_UINT64& val ); - - #if !defined(NANOCLR_EMULATED_FLOATINGPOINT) - void SetResult_R4 ( float val ); - void SetResult_R8 ( double val ); - #else - void SetResult_R4 ( CLR_INT32 val ); - void SetResult_R8 ( CLR_INT64 val ); - #endif - - void SetResult_Boolean( bool val ); - void SetResult_Object ( CLR_RT_HeapBlock* val ); - HRESULT SetResult_String ( const char* val ); - - HRESULT SetupTimeoutFromTicks( CLR_RT_HeapBlock& input, CLR_INT64*& output ); - HRESULT SetupTimeoutFromTimeSpan( CLR_RT_HeapBlock& inputTimeSpan, CLR_INT64*& output ); + HRESULT MakeCall(CLR_RT_MethodDef_Instance md, CLR_RT_HeapBlock *blkThis, CLR_RT_HeapBlock *blkArgs, int nArgs); + + HRESULT HandleSynchronized(bool fAcquire, bool fGlobal); + + void SetResult(CLR_INT32 val, CLR_DataType dataType); + void SetResult_I1(CLR_UINT8 val); + void SetResult_I2(CLR_INT16 val); + void SetResult_I4(CLR_INT32 val); + void SetResult_I8(CLR_INT64 &val); + void SetResult_U1(CLR_INT8 val); + void SetResult_U2(CLR_UINT16 val); + void SetResult_U4(CLR_UINT32 val); + void SetResult_U8(CLR_UINT64 &val); + +#if !defined(NANOCLR_EMULATED_FLOATINGPOINT) + void SetResult_R4(float val); + void SetResult_R8(double val); +#else + void SetResult_R4(CLR_INT32 val); + void SetResult_R8(CLR_INT64 val); +#endif + + void SetResult_Boolean(bool val); + void SetResult_Object(CLR_RT_HeapBlock *val); + HRESULT SetResult_String(const char *val); + + HRESULT SetupTimeoutFromTicks(CLR_RT_HeapBlock &input, CLR_INT64 *&output); + HRESULT SetupTimeoutFromTimeSpan(CLR_RT_HeapBlock &inputTimeSpan, CLR_INT64 *&output); void ConvertResultToBoolean(); - void NegateResult (); + void NegateResult(); HRESULT NotImplementedStub(); @@ -1937,53 +2309,114 @@ struct CLR_RT_StackFrame : public CLR_RT_HeapBlock_Node // EVENT HEAP - NO RELOC //////////////////////////////////////// - CLR_RT_HeapBlock& ThisRef() const { return m_arguments[ 0 ]; } - CLR_RT_HeapBlock* This() const { return ThisRef().Dereference(); } + CLR_RT_HeapBlock &ThisRef() const + { + return m_arguments[0]; + } + CLR_RT_HeapBlock *This() const + { + return ThisRef().Dereference(); + } + + CLR_RT_HeapBlock &Arg0() const + { + return m_arguments[0]; + } + CLR_RT_HeapBlock &Arg1() const + { + return m_arguments[1]; + } + CLR_RT_HeapBlock &Arg2() const + { + return m_arguments[2]; + } + CLR_RT_HeapBlock &Arg3() const + { + return m_arguments[3]; + } + CLR_RT_HeapBlock &Arg4() const + { + return m_arguments[4]; + } + CLR_RT_HeapBlock &Arg5() const + { + return m_arguments[5]; + } + CLR_RT_HeapBlock &Arg6() const + { + return m_arguments[6]; + } + CLR_RT_HeapBlock &Arg7() const + { + return m_arguments[7]; + } - CLR_RT_HeapBlock& Arg0() const { return m_arguments[ 0 ]; } - CLR_RT_HeapBlock& Arg1() const { return m_arguments[ 1 ]; } - CLR_RT_HeapBlock& Arg2() const { return m_arguments[ 2 ]; } - CLR_RT_HeapBlock& Arg3() const { return m_arguments[ 3 ]; } - CLR_RT_HeapBlock& Arg4() const { return m_arguments[ 4 ]; } - CLR_RT_HeapBlock& Arg5() const { return m_arguments[ 5 ]; } - CLR_RT_HeapBlock& Arg6() const { return m_arguments[ 6 ]; } - CLR_RT_HeapBlock& Arg7() const { return m_arguments[ 7 ]; } + CLR_RT_HeapBlock &ArgN(CLR_INT32 n) const + { + return m_arguments[n]; + } - CLR_RT_HeapBlock& ArgN( CLR_INT32 n ) const { return m_arguments[ n ]; } + CLR_RT_HeapBlock &TopValue() + { + return m_evalStackPos[-1]; + } + CLR_RT_HeapBlock &PushValue() + { + _ASSERTE(m_evalStackPos < m_evalStackEnd); + return *m_evalStackPos++; + } + CLR_RT_HeapBlock &PopValue() + { + _ASSERTE(m_evalStackPos > m_evalStack); + return *--m_evalStackPos; + } + void ResetStack() + { + m_evalStackPos = m_evalStack; + } + int TopValuePosition() + { + return (int)(m_evalStackPos - m_evalStack); + } - CLR_RT_HeapBlock& TopValue () { return m_evalStackPos[ -1 ]; } - CLR_RT_HeapBlock& PushValue () { _ASSERTE(m_evalStackPos < m_evalStackEnd); return * m_evalStackPos++; } - CLR_RT_HeapBlock& PopValue () { _ASSERTE(m_evalStackPos > m_evalStack ); return *--m_evalStackPos; } - void ResetStack () { m_evalStackPos = m_evalStack ; } - int TopValuePosition () { return (int)(m_evalStackPos - m_evalStack); } + CLR_RT_MethodDef_Instance &MethodCall() + { + return m_call; + } - CLR_RT_MethodDef_Instance& MethodCall() { return m_call; } - - CLR_RT_HeapBlock& PushValueAndClear() + CLR_RT_HeapBlock &PushValueAndClear() { - CLR_RT_HeapBlock& val = PushValue(); + CLR_RT_HeapBlock &val = PushValue(); - val.SetObjectReference( NULL ); + val.SetObjectReference(NULL); return val; } - CLR_RT_HeapBlock& PushValueAndAssign( const CLR_RT_HeapBlock& value ) + CLR_RT_HeapBlock &PushValueAndAssign(const CLR_RT_HeapBlock &value) { - CLR_RT_HeapBlock& top = PushValue(); + CLR_RT_HeapBlock &top = PushValue(); - top.Assign( value ); + top.Assign(value); return top; } - - inline void PushValueI4( CLR_INT32 val ) { SetResult_I4( val ); } + inline void PushValueI4(CLR_INT32 val) + { + SetResult_I4(val); + } //--// - CLR_RT_StackFrame* Caller() { return (CLR_RT_StackFrame*)Prev(); } - CLR_RT_StackFrame* Callee() { return (CLR_RT_StackFrame*)Next(); } + CLR_RT_StackFrame *Caller() + { + return (CLR_RT_StackFrame *)Prev(); + } + CLR_RT_StackFrame *Callee() + { + return (CLR_RT_StackFrame *)Next(); + } PROHIBIT_ALL_CONSTRUCTORS(CLR_RT_StackFrame); }; @@ -1995,18 +2428,18 @@ struct CLR_RT_StackFrame : public CLR_RT_HeapBlock_Node // EVENT HEAP - NO RELOC // // This CT_ASSERT macro generates a compiler error in case these fields get out of alignment. // -// The use of offsetof below throwns an "invalid offset warning" because CLR_RT_StackFrame is not POD type -// C+17 is the first standard that allow this, so until we are using it we have to disable it to keep GCC happy +// The use of offsetof below throwns an "invalid offset warning" because CLR_RT_StackFrame is not POD type +// C+17 is the first standard that allow this, so until we are using it we have to disable it to keep GCC happy #ifdef __GNUC__ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Winvalid-offsetof" #endif -CT_ASSERT( offsetof(CLR_RT_StackFrame,m_owningThread) + sizeof(CLR_UINT32) == offsetof(CLR_RT_StackFrame,m_evalStack ) ) -CT_ASSERT( offsetof(CLR_RT_StackFrame,m_evalStack ) + sizeof(CLR_UINT32) == offsetof(CLR_RT_StackFrame,m_arguments ) ) -CT_ASSERT( offsetof(CLR_RT_StackFrame,m_arguments ) + sizeof(CLR_UINT32) == offsetof(CLR_RT_StackFrame,m_locals ) ) -CT_ASSERT( offsetof(CLR_RT_StackFrame,m_locals ) + sizeof(CLR_UINT32) == offsetof(CLR_RT_StackFrame,m_IP ) ) +CT_ASSERT(offsetof(CLR_RT_StackFrame, m_owningThread) + sizeof(CLR_UINT32) == offsetof(CLR_RT_StackFrame, m_evalStack)) +CT_ASSERT(offsetof(CLR_RT_StackFrame, m_evalStack) + sizeof(CLR_UINT32) == offsetof(CLR_RT_StackFrame, m_arguments)) +CT_ASSERT(offsetof(CLR_RT_StackFrame, m_arguments) + sizeof(CLR_UINT32) == offsetof(CLR_RT_StackFrame, m_locals)) +CT_ASSERT(offsetof(CLR_RT_StackFrame, m_locals) + sizeof(CLR_UINT32) == offsetof(CLR_RT_StackFrame, m_IP)) #ifdef __GNUC__ #pragma GCC diagnostic pop @@ -2016,29 +2449,38 @@ CT_ASSERT( offsetof(CLR_RT_StackFrame,m_locals ) + sizeof(CLR_UINT32) == of struct CLR_RT_ProtectFromGC { - static const CLR_UINT32 c_Generic = 0x00000001; - static const CLR_UINT32 c_HeapBlock = 0x00000002; + static const CLR_UINT32 c_Generic = 0x00000001; + static const CLR_UINT32 c_HeapBlock = 0x00000002; static const CLR_UINT32 c_ResetKeepAlive = 0x00000004; - typedef void (*Callback)( void* state ); + typedef void (*Callback)(void *state); - static CLR_RT_ProtectFromGC* s_first; + static CLR_RT_ProtectFromGC *s_first; - CLR_RT_ProtectFromGC* m_next; - void** m_data; - Callback m_fpn; - CLR_UINT32 m_flags; + CLR_RT_ProtectFromGC *m_next; + void **m_data; + Callback m_fpn; + CLR_UINT32 m_flags; - CLR_RT_ProtectFromGC ( CLR_RT_HeapBlock& ref ) { Initialize( ref ); } - CLR_RT_ProtectFromGC ( void** data, Callback fpn ) { Initialize( data, fpn ); } - ~CLR_RT_ProtectFromGC( ) { Cleanup ( ); } + CLR_RT_ProtectFromGC(CLR_RT_HeapBlock &ref) + { + Initialize(ref); + } + CLR_RT_ProtectFromGC(void **data, Callback fpn) + { + Initialize(data, fpn); + } + ~CLR_RT_ProtectFromGC() + { + Cleanup(); + } static void InvokeAll(); -private: - void Initialize( CLR_RT_HeapBlock& ref ); - void Initialize( void** data, Callback fpn ); - void Cleanup ( ); + private: + void Initialize(CLR_RT_HeapBlock &ref); + void Initialize(void **data, Callback fpn); + void Cleanup(); void Invoke(); }; @@ -2049,22 +2491,22 @@ struct CLR_RT_ProtectFromGC struct CLR_RT_AssertEarlyCollection { - static CLR_RT_AssertEarlyCollection* s_first; + static CLR_RT_AssertEarlyCollection *s_first; - CLR_RT_AssertEarlyCollection* m_next; - CLR_RT_HeapBlock* m_ptr; + CLR_RT_AssertEarlyCollection *m_next; + CLR_RT_HeapBlock *m_ptr; - CLR_RT_AssertEarlyCollection( CLR_RT_HeapBlock* ptr ); + CLR_RT_AssertEarlyCollection(CLR_RT_HeapBlock *ptr); ~CLR_RT_AssertEarlyCollection(); void Cancel(); - static void CheckAll( CLR_RT_HeapBlock* ptr ); + static void CheckAll(CLR_RT_HeapBlock *ptr); }; -#define NANOCLR_FAULT_ON_EARLY_COLLECTION(ptr) CLR_RT_AssertEarlyCollection aec##ptr( ptr ) +#define NANOCLR_FAULT_ON_EARLY_COLLECTION(ptr) CLR_RT_AssertEarlyCollection aec##ptr(ptr) #define NANOCLR_CANCEL_EARLY_COLLECTION(ptr) aec##ptr.Cancel() -#define NANOCLR_CHECK_EARLY_COLLECTION(ptr) CLR_RT_AssertEarlyCollection::CheckAll( ptr ) +#define NANOCLR_CHECK_EARLY_COLLECTION(ptr) CLR_RT_AssertEarlyCollection::CheckAll(ptr) #else @@ -2083,211 +2525,244 @@ struct CLR_RT_AssertEarlyCollection struct CLR_RT_GarbageCollector { - typedef bool (*MarkSingleFtn )( CLR_RT_HeapBlock** ptr ); - typedef bool (*MarkMultipleFtn)( CLR_RT_HeapBlock* lstExt, CLR_UINT32 numExt ); - typedef bool (*RelocateFtn )( void** ref ); + typedef bool (*MarkSingleFtn)(CLR_RT_HeapBlock **ptr); + typedef bool (*MarkMultipleFtn)(CLR_RT_HeapBlock *lstExt, CLR_UINT32 numExt); + typedef bool (*RelocateFtn)(void **ref); struct MarkStackElement { - CLR_RT_HeapBlock* ptr; - CLR_UINT32 num; - #if defined(NANOCLR_VALIDATE_APPDOMAIN_ISOLATION) - CLR_RT_AppDomain* appDomain; - #endif + CLR_RT_HeapBlock *ptr; + CLR_UINT32 num; +#if defined(NANOCLR_VALIDATE_APPDOMAIN_ISOLATION) + CLR_RT_AppDomain *appDomain; +#endif }; struct MarkStack : CLR_RT_HeapBlock_Node { - MarkStackElement* m_last; - MarkStackElement* m_top; + MarkStackElement *m_last; + MarkStackElement *m_top; - void Initialize( MarkStackElement* ptr, size_t num ); + void Initialize(MarkStackElement *ptr, size_t num); }; struct RelocationRegion { - CLR_UINT8* m_start; - CLR_UINT8* m_end; - CLR_UINT8* m_destination; + CLR_UINT8 *m_start; + CLR_UINT8 *m_end; + CLR_UINT8 *m_destination; CLR_UINT32 m_offset; }; //--// - static const int c_minimumSpaceForGC = 128; - static const int c_minimumSpaceForCompact = 128; - static const CLR_UINT32 c_pressureThreshold = 10; - static const CLR_UINT32 c_memoryThreshold = HEAP_SIZE_THRESHOLD; - static const CLR_UINT32 c_memoryThreshold2 = HEAP_SIZE_THRESHOLD_UPPER; + static const int c_minimumSpaceForGC = 128; + static const int c_minimumSpaceForCompact = 128; + static const CLR_UINT32 c_pressureThreshold = 10; + static const CLR_UINT32 c_memoryThreshold = HEAP_SIZE_THRESHOLD; + static const CLR_UINT32 c_memoryThreshold2 = HEAP_SIZE_THRESHOLD_UPPER; - static const CLR_UINT32 c_StartGraphEvent = 0x00000001; - static const CLR_UINT32 c_StopGraphEvent = 0x00000002; - static const CLR_UINT32 c_DumpGraphHeapEvent = 0x00000004; + static const CLR_UINT32 c_StartGraphEvent = 0x00000001; + static const CLR_UINT32 c_StopGraphEvent = 0x00000002; + static const CLR_UINT32 c_DumpGraphHeapEvent = 0x00000004; static const CLR_UINT32 c_DumpPerfCountersEvent = 0x00000008; - CLR_UINT32 m_numberOfGarbageCollections; - CLR_UINT32 m_numberOfCompactions; - - CLR_RT_DblLinkedList m_weakDelegates_Reachable; // list of CLR_RT_HeapBlock_Delegate_List + CLR_UINT32 m_numberOfGarbageCollections; + CLR_UINT32 m_numberOfCompactions; + CLR_RT_DblLinkedList m_weakDelegates_Reachable; // list of CLR_RT_HeapBlock_Delegate_List - CLR_UINT32 m_totalBytes; - CLR_UINT32 m_freeBytes; - CLR_UINT32 m_pressureCounter; + CLR_UINT32 m_totalBytes; + CLR_UINT32 m_freeBytes; + CLR_UINT32 m_pressureCounter; - CLR_RT_DblLinkedList* m_markStackList; - MarkStack* m_markStack; + CLR_RT_DblLinkedList *m_markStackList; + MarkStack *m_markStack; - RelocationRegion* m_relocBlocks; - size_t m_relocTotal; - size_t m_relocCount; - CLR_UINT8* m_relocMinimum; - CLR_UINT8* m_relocMaximum; - #if NANOCLR_VALIDATE_HEAP > NANOCLR_VALIDATE_HEAP_0_None - RelocateFtn m_relocWorker; - #endif + RelocationRegion *m_relocBlocks; + size_t m_relocTotal; + size_t m_relocCount; + CLR_UINT8 *m_relocMinimum; + CLR_UINT8 *m_relocMaximum; +#if NANOCLR_VALIDATE_HEAP > NANOCLR_VALIDATE_HEAP_0_None + RelocateFtn m_relocWorker; +#endif - MarkSingleFtn m_funcSingleBlock; - MarkMultipleFtn m_funcMultipleBlocks; + MarkSingleFtn m_funcSingleBlock; + MarkMultipleFtn m_funcMultipleBlocks; - bool m_fOutOfStackSpaceForGC; + bool m_fOutOfStackSpaceForGC; - #if defined(_WIN32) - CLR_UINT32 m_events; - #endif +#if defined(_WIN32) + CLR_UINT32 m_events; +#endif //--// CLR_UINT32 ExecuteGarbageCollection(); - CLR_UINT32 ExecuteCompaction (); + CLR_UINT32 ExecuteCompaction(); - void Mark (); - void MarkWeak (); - void Sweep (); + void Mark(); + void MarkWeak(); + void Sweep(); void CheckMemoryPressure(); - #if defined(NANOCLR_APPDOMAINS) +#if defined(NANOCLR_APPDOMAINS) void AppDomain_Mark(); - #endif +#endif void Assembly_Mark(); - void Thread_Mark( CLR_RT_DblLinkedList& threads ); - void Thread_Mark( CLR_RT_Thread* thread ); + void Thread_Mark(CLR_RT_DblLinkedList &threads); + void Thread_Mark(CLR_RT_Thread *thread); - void Heap_Compact (); + void Heap_Compact(); CLR_UINT32 Heap_ComputeAliveVsDeadRatio(); void RecoverEventsFromGC(); - void Heap_Relocate_Prepare ( RelocationRegion* blocks, size_t total ); - void Heap_Relocate_AddBlock( CLR_UINT8* dst, CLR_UINT8* src, CLR_UINT32 length ); - void Heap_Relocate ( ); + void Heap_Relocate_Prepare(RelocationRegion *blocks, size_t total); + void Heap_Relocate_AddBlock(CLR_UINT8 *dst, CLR_UINT8 *src, CLR_UINT32 length); + void Heap_Relocate(); //--// - static void Heap_Relocate( CLR_RT_HeapBlock* lst, CLR_UINT32 len ); - static void Heap_Relocate( void** ref ); + static void Heap_Relocate(CLR_RT_HeapBlock *lst, CLR_UINT32 len); + static void Heap_Relocate(void **ref); //--// - #if NANOCLR_VALIDATE_HEAP >= NANOCLR_VALIDATE_HEAP_3_Compaction +#if NANOCLR_VALIDATE_HEAP >= NANOCLR_VALIDATE_HEAP_3_Compaction - static bool Relocation_JustCheck( void** ref ); + static bool Relocation_JustCheck(void **ref); - void ValidatePointers() { Heap_Relocate_Pass( Relocation_JustCheck ); } + void ValidatePointers() + { + Heap_Relocate_Pass(Relocation_JustCheck); + } - static void ValidateCluster ( CLR_RT_HeapCluster* hc ); - static void ValidateHeap ( CLR_RT_DblLinkedList& lst ); - static void ValidateBlockNotInFreeList( CLR_RT_DblLinkedList& lst, CLR_RT_HeapBlock_Node* dst ); - static bool IsBlockInFreeList ( CLR_RT_DblLinkedList& lst, CLR_RT_HeapBlock_Node* dst, bool fExact ); - static bool IsBlockInHeap ( CLR_RT_DblLinkedList& lst, CLR_RT_HeapBlock_Node* dst ); + static void ValidateCluster(CLR_RT_HeapCluster *hc); + static void ValidateHeap(CLR_RT_DblLinkedList &lst); + static void ValidateBlockNotInFreeList(CLR_RT_DblLinkedList &lst, CLR_RT_HeapBlock_Node *dst); + static bool IsBlockInFreeList(CLR_RT_DblLinkedList &lst, CLR_RT_HeapBlock_Node *dst, bool fExact); + static bool IsBlockInHeap(CLR_RT_DblLinkedList &lst, CLR_RT_HeapBlock_Node *dst); - #else +#else - void ValidatePointers() {} + void ValidatePointers() + { + } - static void ValidateCluster ( CLR_RT_HeapCluster* hc ) {} - static void ValidateHeap ( CLR_RT_DblLinkedList& lst ) {} - static void ValidateBlockNotInFreeList( CLR_RT_DblLinkedList& lst, CLR_RT_HeapBlock_Node* dst ) {} + static void ValidateCluster(CLR_RT_HeapCluster *hc) + { + } + static void ValidateHeap(CLR_RT_DblLinkedList &lst) + { + } + static void ValidateBlockNotInFreeList(CLR_RT_DblLinkedList &lst, CLR_RT_HeapBlock_Node *dst) + { + } - #endif +#endif - #if NANOCLR_VALIDATE_HEAP >= NANOCLR_VALIDATE_HEAP_4_CompactionPlus +#if NANOCLR_VALIDATE_HEAP >= NANOCLR_VALIDATE_HEAP_4_CompactionPlus struct RelocationRecord { - void** oldRef; - CLR_UINT32* oldPtr; + void **oldRef; + CLR_UINT32 *oldPtr; - void** newRef; - CLR_UINT32* newPtr; + void **newRef; + CLR_UINT32 *newPtr; - CLR_UINT32 data; + CLR_UINT32 data; }; - typedef std::list Rel_List; - typedef Rel_List::iterator Rel_List_Iter; + typedef std::list Rel_List; + typedef Rel_List::iterator Rel_List_Iter; - typedef std::map< void**, RelocationRecord* > Rel_Map; - typedef Rel_Map::iterator Rel_Map_Iter; + typedef std::map Rel_Map; + typedef Rel_Map::iterator Rel_Map_Iter; static Rel_List s_lstRecords; - static Rel_Map s_mapOldToRecord; - static Rel_Map s_mapNewToRecord; + static Rel_Map s_mapOldToRecord; + static Rel_Map s_mapNewToRecord; - void Relocation_UpdatePointer(void** ref); + void Relocation_UpdatePointer(void **ref); - static bool TestPointers_PopulateOld_Worker( void** ref ); - static bool TestPointers_PopulateNew_Worker( void** ref ); + static bool TestPointers_PopulateOld_Worker(void **ref); + static bool TestPointers_PopulateNew_Worker(void **ref); void TestPointers_PopulateOld(); - void TestPointers_Remap (); + void TestPointers_Remap(); void TestPointers_PopulateNew(); - #else +#else - void TestPointers_PopulateOld() {} - void TestPointers_Remap () {} - void TestPointers_PopulateNew() {} + void TestPointers_PopulateOld() + { + } + void TestPointers_Remap() + { + } + void TestPointers_PopulateNew() + { + } - #endif +#endif //--// - #if defined(NANOCLR_GC_VERBOSE) +#if defined(NANOCLR_GC_VERBOSE) - void GC_Stats( int& resNumberObjects, int& resSizeObjects, int& resNumberEvents, int& resSizeEvents ); + void GC_Stats(int &resNumberObjects, int &resSizeObjects, int &resNumberEvents, int &resSizeEvents); - void DumpThreads ( ); + void DumpThreads(); - #else +#else - void GC_Stats( int& resNumberObjects, int& resSizeObjects, int& resNumberEvents, int& resSizeEvents ) + void GC_Stats(int &resNumberObjects, int &resSizeObjects, int &resNumberEvents, int &resSizeEvents) { resNumberObjects = 0; - resSizeObjects = 0; - resNumberEvents = 0; - resSizeEvents = 0; + resSizeObjects = 0; + resNumberEvents = 0; + resSizeEvents = 0; } - void DumpThreads ( ) {} + void DumpThreads() + { + } - #endif +#endif //--// - bool CheckSingleBlock( CLR_RT_HeapBlock** ptr ) { return m_funcSingleBlock( ( CLR_RT_HeapBlock* *)ptr ); } - bool CheckSingleBlock( CLR_RT_HeapBlock_Array** ptr ) { return m_funcSingleBlock( (CLR_RT_HeapBlock* *)ptr ); } - bool CheckSingleBlock( CLR_RT_HeapBlock_Delegate** ptr ) { return m_funcSingleBlock( (CLR_RT_HeapBlock* *)ptr ); } + bool CheckSingleBlock(CLR_RT_HeapBlock **ptr) + { + return m_funcSingleBlock((CLR_RT_HeapBlock **)ptr); + } + bool CheckSingleBlock(CLR_RT_HeapBlock_Array **ptr) + { + return m_funcSingleBlock((CLR_RT_HeapBlock **)ptr); + } + bool CheckSingleBlock(CLR_RT_HeapBlock_Delegate **ptr) + { + return m_funcSingleBlock((CLR_RT_HeapBlock **)ptr); + } - bool CheckSingleBlock_Force( CLR_RT_HeapBlock* ptr ) { return ptr ? m_funcMultipleBlocks( ptr, 1 ) : true; } - bool CheckMultipleBlocks ( CLR_RT_HeapBlock* lst, CLR_UINT32 num ) { return lst ? m_funcMultipleBlocks( lst, num ) : true; } + bool CheckSingleBlock_Force(CLR_RT_HeapBlock *ptr) + { + return ptr ? m_funcMultipleBlocks(ptr, 1) : true; + } + bool CheckMultipleBlocks(CLR_RT_HeapBlock *lst, CLR_UINT32 num) + { + return lst ? m_funcMultipleBlocks(lst, num) : true; + } //--// - static bool ComputeReachabilityGraphForSingleBlock ( CLR_RT_HeapBlock** ptr ); - static bool ComputeReachabilityGraphForMultipleBlocks( CLR_RT_HeapBlock* lst, CLR_UINT32 num ); + static bool ComputeReachabilityGraphForSingleBlock(CLR_RT_HeapBlock **ptr); + static bool ComputeReachabilityGraphForMultipleBlocks(CLR_RT_HeapBlock *lst, CLR_UINT32 num); //--// @@ -2295,11 +2770,10 @@ struct CLR_RT_GarbageCollector //--// - private: - - void Heap_Relocate_Pass( RelocateFtn ftn ); + private: + void Heap_Relocate_Pass(RelocateFtn ftn); - void MarkSlow(); + void MarkSlow(); }; #ifdef __GNUC__ @@ -2313,24 +2787,24 @@ extern CLR_RT_GarbageCollector g_CLR_RT_GarbageCollector; struct CLR_RT_SubThread : public CLR_RT_HeapBlock_Node // EVENT HEAP - NO RELOCATION - { static const int MODE_IncludeSelf = 0x00000001; - static const int MODE_CheckLocks = 0x00000002; + static const int MODE_CheckLocks = 0x00000002; static const int STATUS_Triggered = 0x00000001; - CLR_RT_Thread* m_owningThread; // EVENT HEAP - NO RELOCATION - - CLR_RT_StackFrame* m_owningStackFrame; - CLR_UINT32 m_lockRequestsCount; + CLR_RT_Thread *m_owningThread; // EVENT HEAP - NO RELOCATION - + CLR_RT_StackFrame *m_owningStackFrame; + CLR_UINT32 m_lockRequestsCount; - int m_priority; - CLR_INT64 m_timeConstraint; - CLR_UINT32 m_status; + int m_priority; + CLR_INT64 m_timeConstraint; + CLR_UINT32 m_status; //--// - static HRESULT CreateInstance ( CLR_RT_Thread* th, CLR_RT_StackFrame* stack , int priority, CLR_RT_SubThread*& sth ); - static void DestroyInstance( CLR_RT_Thread* th, CLR_RT_SubThread* sthBase, int flags ); + static HRESULT CreateInstance(CLR_RT_Thread *th, CLR_RT_StackFrame *stack, int priority, CLR_RT_SubThread *&sth); + static void DestroyInstance(CLR_RT_Thread *th, CLR_RT_SubThread *sthBase, int flags); - bool ChangeLockRequestCount( int diff ); + bool ChangeLockRequestCount(int diff); //--// @@ -2342,27 +2816,37 @@ struct CLR_RT_SubThread : public CLR_RT_HeapBlock_Node // EVENT HEAP - NO RELOCA struct CLR_RT_ExceptionHandler { union { - CLR_RT_TypeDef_Index m_typeFilter; - CLR_PMETADATA m_userFilterStart; + CLR_RT_TypeDef_Index m_typeFilter; + CLR_PMETADATA m_userFilterStart; }; - CLR_PMETADATA m_tryStart; - CLR_PMETADATA m_tryEnd; - CLR_PMETADATA m_handlerStart; - CLR_PMETADATA m_handlerEnd; + CLR_PMETADATA m_tryStart; + CLR_PMETADATA m_tryEnd; + CLR_PMETADATA m_handlerStart; + CLR_PMETADATA m_handlerEnd; - CLR_UINT16 m_ehType; + CLR_UINT16 m_ehType; //--// - bool ConvertFromEH( const CLR_RT_MethodDef_Instance& owner, CLR_PMETADATA ipStart, const CLR_RECORD_EH* ehPtr ); - - bool IsCatch() const { return m_ehType == CLR_RECORD_EH::EH_Catch ; } - bool IsCatchAll() const { return m_ehType == CLR_RECORD_EH::EH_CatchAll ; } - bool IsFilter() const { return m_ehType == CLR_RECORD_EH::EH_Filter ; } - bool IsFinally() const { return m_ehType == CLR_RECORD_EH::EH_Finally ; } + bool ConvertFromEH(const CLR_RT_MethodDef_Instance &owner, CLR_PMETADATA ipStart, const CLR_RECORD_EH *ehPtr); + bool IsCatch() const + { + return m_ehType == CLR_RECORD_EH::EH_Catch; + } + bool IsCatchAll() const + { + return m_ehType == CLR_RECORD_EH::EH_CatchAll; + } + bool IsFilter() const + { + return m_ehType == CLR_RECORD_EH::EH_Filter; + } + bool IsFinally() const + { + return m_ehType == CLR_RECORD_EH::EH_Finally; + } }; - // // Directly from the .NET enumerator. // @@ -2371,137 +2855,144 @@ struct ThreadPriority /*========================================================================= ** Constants for thread priorities. =========================================================================*/ - static const int Lowest = 0; + static const int Lowest = 0; static const int BelowNormal = 1; - static const int Normal = 2; + static const int Normal = 2; static const int AboveNormal = 3; - static const int Highest = 4; + static const int Highest = 4; // One more priority for internal creation of managed code threads. // We do not expose this priority to C# applications. - static const int System_Highest = 5; + static const int System_Highest = 5; }; struct CLR_RT_Thread : public CLR_RT_ObjectToEvent_Destination // EVENT HEAP - NO RELOCATION - { - typedef void (*ThreadTerminationCallback)( void* arg ); + typedef void (*ThreadTerminationCallback)(void *arg); struct UnwindStack { - CLR_RT_StackFrame* m_stack; - CLR_RT_HeapBlock* m_exception; - CLR_PMETADATA m_ip; - - CLR_PMETADATA m_currentBlockStart; - CLR_PMETADATA m_currentBlockEnd; - CLR_PMETADATA m_handlerBlockStart; - CLR_PMETADATA m_handlerBlockEnd; - - CLR_RT_StackFrame* m_handlerStack; - CLR_UINT8 m_flags; - - static const CLR_UINT8 p_Phase_Mask = 0x07; - static const CLR_UINT8 p_1_SearchingForHandler_0 = 0x01; - static const CLR_UINT8 p_1_SearchingForHandler_1_SentFirstChance = 0x02; - static const CLR_UINT8 p_1_SearchingForHandler_2_SentUsersChance = 0x03; - static const CLR_UINT8 p_2_RunningFinallys_0 = 0x04; - static const CLR_UINT8 p_2_RunningFinallys_1_SentUnwindBegin = 0x05; - static const CLR_UINT8 p_3_RunningHandler = 0x06; - static const CLR_UINT8 p_4_NormalCleanup = 0x07; - - static const CLR_UINT8 c_MagicCatchForInline = 0x20; - static const CLR_UINT8 c_MagicCatchForInteceptedException = 0x40; - static const CLR_UINT8 c_ContinueExceptionHandler = 0x80; - - CLR_UINT8 inline GetPhase() { return m_flags & p_Phase_Mask; } - void inline SetPhase(CLR_UINT8 phase) + CLR_RT_StackFrame *m_stack; + CLR_RT_HeapBlock *m_exception; + CLR_PMETADATA m_ip; + + CLR_PMETADATA m_currentBlockStart; + CLR_PMETADATA m_currentBlockEnd; + CLR_PMETADATA m_handlerBlockStart; + CLR_PMETADATA m_handlerBlockEnd; + + CLR_RT_StackFrame *m_handlerStack; + CLR_UINT8 m_flags; + + static const CLR_UINT8 p_Phase_Mask = 0x07; + static const CLR_UINT8 p_1_SearchingForHandler_0 = 0x01; + static const CLR_UINT8 p_1_SearchingForHandler_1_SentFirstChance = 0x02; + static const CLR_UINT8 p_1_SearchingForHandler_2_SentUsersChance = 0x03; + static const CLR_UINT8 p_2_RunningFinallys_0 = 0x04; + static const CLR_UINT8 p_2_RunningFinallys_1_SentUnwindBegin = 0x05; + static const CLR_UINT8 p_3_RunningHandler = 0x06; + static const CLR_UINT8 p_4_NormalCleanup = 0x07; + + static const CLR_UINT8 c_MagicCatchForInline = 0x20; + static const CLR_UINT8 c_MagicCatchForInteceptedException = 0x40; + static const CLR_UINT8 c_ContinueExceptionHandler = 0x80; + + CLR_UINT8 inline GetPhase() + { + return m_flags & p_Phase_Mask; + } + void inline SetPhase(CLR_UINT8 phase) { _ASSERTE((phase & ~p_Phase_Mask) == 0); m_flags = (m_flags & ~p_Phase_Mask) | phase; } - }; - static const CLR_UINT32 TH_S_Ready = 0x00000000; - static const CLR_UINT32 TH_S_Waiting = 0x00000001; + static const CLR_UINT32 TH_S_Ready = 0x00000000; + static const CLR_UINT32 TH_S_Waiting = 0x00000001; static const CLR_UINT32 TH_S_Terminated = 0x00000002; - static const CLR_UINT32 TH_S_Unstarted = 0x00000003; + static const CLR_UINT32 TH_S_Unstarted = 0x00000003; - static const CLR_UINT32 TH_F_Suspended = 0x00000001; - static const CLR_UINT32 TH_F_Aborted = 0x00000002; - static const CLR_UINT32 TH_F_System = 0x00000004; + static const CLR_UINT32 TH_F_Suspended = 0x00000001; + static const CLR_UINT32 TH_F_Aborted = 0x00000002; + static const CLR_UINT32 TH_F_System = 0x00000004; static const CLR_UINT32 TH_F_ContainsDoomedAppDomain = 0x00000008; - static const CLR_INT32 TH_WAIT_RESULT_INIT = -1; - static const CLR_INT32 TH_WAIT_RESULT_HANDLE_0 = 0; - static const CLR_INT32 TH_WAIT_RESULT_TIMEOUT = 0x102; //WaitHandle.WaitTimeout - static const CLR_INT32 TH_WAIT_RESULT_HANDLE_ALL = 0x103; + static const CLR_INT32 TH_WAIT_RESULT_INIT = -1; + static const CLR_INT32 TH_WAIT_RESULT_HANDLE_0 = 0; + static const CLR_INT32 TH_WAIT_RESULT_TIMEOUT = 0x102; // WaitHandle.WaitTimeout + static const CLR_INT32 TH_WAIT_RESULT_HANDLE_ALL = 0x103; static const CLR_UINT32 c_TimeQuantum_Milliseconds = 20; - static const int c_MaxStackUnwindDepth = 6; + static const int c_MaxStackUnwindDepth = 6; - int m_pid; - CLR_UINT32 m_status; - CLR_UINT32 m_flags; - int m_executionCounter; - volatile bool m_timeQuantumExpired; + int m_pid; + CLR_UINT32 m_status; + CLR_UINT32 m_flags; + int m_executionCounter; + volatile bool m_timeQuantumExpired; - CLR_RT_HeapBlock_Delegate* m_dlg; // OBJECT HEAP - DO RELOCATION - - CLR_RT_HeapBlock m_currentException; // OBJECT HEAP - DO RELOCATION - - UnwindStack m_nestedExceptions[ c_MaxStackUnwindDepth ]; - int m_nestedExceptionsPos; + CLR_RT_HeapBlock_Delegate *m_dlg; // OBJECT HEAP - DO RELOCATION - + CLR_RT_HeapBlock m_currentException; // OBJECT HEAP - DO RELOCATION - + UnwindStack m_nestedExceptions[c_MaxStackUnwindDepth]; + int m_nestedExceptionsPos; //--// // // For example, timers are implemented in terms of Threads. If not NULL, this is a worker thread for a timer. // - ThreadTerminationCallback m_terminationCallback; - void* m_terminationParameter; // EVENT HEAP - NO RELOCATION - + ThreadTerminationCallback m_terminationCallback; + void *m_terminationParameter; // EVENT HEAP - NO RELOCATION - - CLR_UINT32 m_waitForEvents; - CLR_INT64 m_waitForEvents_Timeout; - CLR_INT64 m_waitForEvents_IdleTimeWorkItem; + CLR_UINT32 m_waitForEvents; + CLR_INT64 m_waitForEvents_Timeout; + CLR_INT64 m_waitForEvents_IdleTimeWorkItem; - CLR_RT_DblLinkedList m_locks; // EVENT HEAP - NO RELOCATION - list of CLR_RT_HeapBlock_Lock - CLR_UINT32 m_lockRequestsCount; + CLR_RT_DblLinkedList m_locks; // EVENT HEAP - NO RELOCATION - list of CLR_RT_HeapBlock_Lock + CLR_UINT32 m_lockRequestsCount; - CLR_RT_HeapBlock_WaitForObject* m_waitForObject; // EVENT HEAP - NO RELOCATION, but the objects they point to do - CLR_INT32 m_waitForObject_Result; + CLR_RT_HeapBlock_WaitForObject *m_waitForObject; // EVENT HEAP - NO RELOCATION, but the objects they point to do + CLR_INT32 m_waitForObject_Result; - CLR_RT_DblLinkedList m_stackFrames; // EVENT HEAP - NO RELOCATION - list of CLR_RT_StackFrame + CLR_RT_DblLinkedList m_stackFrames; // EVENT HEAP - NO RELOCATION - list of CLR_RT_StackFrame - CLR_RT_DblLinkedList m_subThreads; // EVENT HEAP - NO RELOCATION - list of CLR_RT_SubThread + CLR_RT_DblLinkedList m_subThreads; // EVENT HEAP - NO RELOCATION - list of CLR_RT_SubThread #if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) - int m_scratchPad; - bool m_fHasJMCStepper; + int m_scratchPad; + bool m_fHasJMCStepper; - CLR_RT_Thread* m_realThread; // Normally, this points to the CLR_RT_Thread object that contains it. - // However, if this thread was spawned on behalf of the debugger to evaluate - // a property or function call, it points to the object coresponding to the - // thread that is currently selected in the debugger. -#endif //#if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) + CLR_RT_Thread *m_realThread; // Normally, this points to the CLR_RT_Thread object that contains it. + // However, if this thread was spawned on behalf of the debugger to evaluate + // a property or function call, it points to the object coresponding to the + // thread that is currently selected in the debugger. +#endif //#if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) #if defined(ENABLE_NATIVE_PROFILER) - bool m_fNativeProfiled; + bool m_fNativeProfiled; #endif //--// - static HRESULT CreateInstance( int pid, CLR_RT_HeapBlock_Delegate* pDelegate, int priority, CLR_RT_Thread*& th, CLR_UINT32 flags ); - static HRESULT CreateInstance( int pid, int priority, CLR_RT_Thread*& th, CLR_UINT32 flags ); - HRESULT PushThreadProcDelegate( CLR_RT_HeapBlock_Delegate* pDelegate ); + static HRESULT CreateInstance( + int pid, + CLR_RT_HeapBlock_Delegate *pDelegate, + int priority, + CLR_RT_Thread *&th, + CLR_UINT32 flags); + static HRESULT CreateInstance(int pid, int priority, CLR_RT_Thread *&th, CLR_UINT32 flags); + HRESULT PushThreadProcDelegate(CLR_RT_HeapBlock_Delegate *pDelegate); void DestroyInstance(); - HRESULT Execute (); + HRESULT Execute(); - HRESULT Suspend (); - HRESULT Resume (); + HRESULT Suspend(); + HRESULT Resume(); HRESULT Terminate(); - HRESULT Abort (); + HRESULT Abort(); - void Restart( bool fDeleteEvent ); + void Restart(bool fDeleteEvent); void Passivate(); @@ -2509,42 +3000,68 @@ struct CLR_RT_Thread : public CLR_RT_ObjectToEvent_Destination // EVENT HEAP - N void RecoverFromGC(); - void Relocate(); - - UnwindStack* PushEH ( ); - void PopEH_Inner( CLR_RT_StackFrame* stack, CLR_PMETADATA ip ); - bool FindEhBlock( CLR_RT_StackFrame* stack, CLR_PMETADATA from, CLR_PMETADATA to, CLR_RT_ExceptionHandler& eh, bool onlyFinallys ); + void Relocate(); + UnwindStack *PushEH(); + void PopEH_Inner(CLR_RT_StackFrame *stack, CLR_PMETADATA ip); + bool FindEhBlock( + CLR_RT_StackFrame *stack, + CLR_PMETADATA from, + CLR_PMETADATA to, + CLR_RT_ExceptionHandler &eh, + bool onlyFinallys); - HRESULT ProcessException ( ); - HRESULT ProcessException_EndFilter ( ); - HRESULT ProcessException_EndFinally ( ); - HRESULT ProcessException_Phase1 ( ); - HRESULT ProcessException_Phase2 ( ); - void ProcessException_FilterPseudoFrameCopyVars(CLR_RT_StackFrame* to, CLR_RT_StackFrame* from); + HRESULT ProcessException(); + HRESULT ProcessException_EndFilter(); + HRESULT ProcessException_EndFinally(); + HRESULT ProcessException_Phase1(); + HRESULT ProcessException_Phase2(); + void ProcessException_FilterPseudoFrameCopyVars(CLR_RT_StackFrame *to, CLR_RT_StackFrame *from); - static void ProtectFromGCCallback( void* state ); + static void ProtectFromGCCallback(void *state); - static HRESULT Execute_DelegateInvoke( CLR_RT_StackFrame& stack ); - static HRESULT Execute_IL ( CLR_RT_StackFrame& stack ); + static HRESULT Execute_DelegateInvoke(CLR_RT_StackFrame &stack); + static HRESULT Execute_IL(CLR_RT_StackFrame &stack); //--// - CLR_RT_StackFrame* FirstFrame () const { return (CLR_RT_StackFrame*)m_stackFrames.FirstNode(); } - CLR_RT_StackFrame* CurrentFrame() const { return (CLR_RT_StackFrame*)m_stackFrames.LastNode (); } + CLR_RT_StackFrame *FirstFrame() const + { + return (CLR_RT_StackFrame *)m_stackFrames.FirstNode(); + } + CLR_RT_StackFrame *CurrentFrame() const + { + return (CLR_RT_StackFrame *)m_stackFrames.LastNode(); + } - CLR_RT_SubThread* CurrentSubThread() const { return (CLR_RT_SubThread*)m_subThreads.LastNode(); } + CLR_RT_SubThread *CurrentSubThread() const + { + return (CLR_RT_SubThread *)m_subThreads.LastNode(); + } #if defined(NANOCLR_APPDOMAINS) - CLR_RT_AppDomain* CurrentAppDomain() const { CLR_RT_StackFrame* stack = CurrentFrame(); return stack->Prev() ? stack->m_appDomain : NULL; } + CLR_RT_AppDomain *CurrentAppDomain() const + { + CLR_RT_StackFrame *stack = CurrentFrame(); + return stack->Prev() ? stack->m_appDomain : NULL; + } #endif // Just return priority, no way to set it through this function. - int GetThreadPriority() const { return CurrentSubThread()->m_priority; } + int GetThreadPriority() const + { + return CurrentSubThread()->m_priority; + } // Here we set it. This function is called if managed code changes thread priority. - void SetThreadPriority( int threadPri ) { CurrentSubThread()->m_priority = threadPri; } + void SetThreadPriority(int threadPri) + { + CurrentSubThread()->m_priority = threadPri; + } - int GetExecutionCounter() const { return CurrentSubThread()->m_priority + m_executionCounter; } + int GetExecutionCounter() const + { + return CurrentSubThread()->m_priority + m_executionCounter; + } // QuantumDebit is update for execution counter for each quantum: // System_Highest - 1 @@ -2553,18 +3070,27 @@ struct CLR_RT_Thread : public CLR_RT_ObjectToEvent_Destination // EVENT HEAP - N // Normal - 8 // Below Normal - 16 // Lowest - 32 - int GetQuantumDebit() const { return 1 << ( ThreadPriority::System_Highest - GetThreadPriority() ); } + int GetQuantumDebit() const + { + return 1 << (ThreadPriority::System_Highest - GetThreadPriority()); + } // If thread was sleeping and get too far behind on updating of m_executionCounter // Then we make m_executionCounter 4 quantums above m_GlobalExecutionCounter; - void BringExecCounterToDate( int iGlobalExecutionCounter ); + void BringExecCounterToDate(int iGlobalExecutionCounter); - void PopEH( CLR_RT_StackFrame* stack, CLR_PMETADATA ip ) { if(m_nestedExceptionsPos) PopEH_Inner( stack, ip ); } + void PopEH(CLR_RT_StackFrame *stack, CLR_PMETADATA ip) + { + if (m_nestedExceptionsPos) + PopEH_Inner(stack, ip); + } #if defined(NANOCLR_TRACE_CALLS) void DumpStack(); #else - void DumpStack() {} + void DumpStack() + { + } #endif bool IsFinalizerThread(); @@ -2578,14 +3104,13 @@ struct CLR_RT_Thread : public CLR_RT_ObjectToEvent_Destination // EVENT HEAP - N //--// -private: - + private: HRESULT Execute_Inner(); }; //////////////////////////////////////////////////////////////////////////////// -extern size_t LinkArraySize (); +extern size_t LinkArraySize(); extern size_t LinkMRUArraySize(); extern size_t PayloadArraySize(); extern size_t InterruptRecords(); @@ -2593,13 +3118,12 @@ extern size_t InterruptRecords(); extern size_t InlineBufferCount(); #endif - -extern CLR_UINT32 g_scratchVirtualMethodTableLink []; -extern CLR_UINT32 g_scratchVirtualMethodTableLinkMRU []; -extern CLR_UINT32 g_scratchVirtualMethodPayload []; +extern CLR_UINT32 g_scratchVirtualMethodTableLink[]; +extern CLR_UINT32 g_scratchVirtualMethodTableLinkMRU[]; +extern CLR_UINT32 g_scratchVirtualMethodPayload[]; extern CLR_UINT32 g_scratchInterruptDispatchingStorage[]; #ifndef CLR_NO_IL_INLINE -extern CLR_UINT32 g_scratchInlineBuffer []; +extern CLR_UINT32 g_scratchInlineBuffer[]; #endif //////////////////////////////////////////////////////////////////////////////// @@ -2619,16 +3143,17 @@ struct CLR_RT_EventCache // The first two fields compose the key, the last field is the value. // CLR_RT_MethodDef_Index m_mdVirtual; // The definition of the virtual method. - CLR_RT_TypeDef_Index m_cls; // The class of the instance we need to resolve. + CLR_RT_TypeDef_Index m_cls; // The class of the instance we need to resolve. CLR_RT_MethodDef_Index m_md; // The actual implementation of the virtual method. //--// - int Compare( Payload& right ) + int Compare(Payload &right) { - if(m_mdVirtual.m_data == right.m_mdVirtual.m_data) + if (m_mdVirtual.m_data == right.m_mdVirtual.m_data) { - if(m_cls.m_data == right.m_cls.m_data) return 0; + if (m_cls.m_data == right.m_cls.m_data) + return 0; return m_cls.m_data < right.m_cls.m_data ? -1 : 1; } @@ -2643,38 +3168,46 @@ struct CLR_RT_EventCache //--// - static int Callback_Compare( void* state, CLR_RT_AVLTree::Entry* left, CLR_RT_AVLTree::Entry* right ); + static int Callback_Compare(void *state, CLR_RT_AVLTree::Entry *left, CLR_RT_AVLTree::Entry *right); }; struct VirtualMethodTable { - CLR_RT_AVLTree m_tree; - LookupEntry* m_entries; + CLR_RT_AVLTree m_tree; + LookupEntry *m_entries; - CLR_RT_DblLinkedList m_list_freeItems; // list of CLR_RT_EventCache::LookupEntry - CLR_RT_DblLinkedList m_list_inUse; // list of CLR_RT_EventCache::LookupEntry + CLR_RT_DblLinkedList m_list_freeItems; // list of CLR_RT_EventCache::LookupEntry + CLR_RT_DblLinkedList m_list_inUse; // list of CLR_RT_EventCache::LookupEntry //--// void Initialize(); - bool FindVirtualMethod( const CLR_RT_TypeDef_Index& cls, const CLR_RT_MethodDef_Index& mdVirtual, CLR_RT_MethodDef_Index& md ); + bool FindVirtualMethod( + const CLR_RT_TypeDef_Index &cls, + const CLR_RT_MethodDef_Index &mdVirtual, + CLR_RT_MethodDef_Index &md); //--// - static CLR_RT_AVLTree::Entry* Callback_NewNode ( void* state, CLR_RT_AVLTree::Entry* payload ); - static void Callback_FreeNode( void* state, CLR_RT_AVLTree::Entry* node ); - static void Callback_Reassign( void* state, CLR_RT_AVLTree::Entry* from, CLR_RT_AVLTree::Entry* to ); + static CLR_RT_AVLTree::Entry *Callback_NewNode(void *state, CLR_RT_AVLTree::Entry *payload); + static void Callback_FreeNode(void *state, CLR_RT_AVLTree::Entry *node); + static void Callback_Reassign(void *state, CLR_RT_AVLTree::Entry *from, CLR_RT_AVLTree::Entry *to); //--// #if defined(_WIN32) - void DumpTree ( ); - bool ConsistencyCheck( ); - bool ConsistencyCheck( LookupEntry* node, int& depth ); + void DumpTree(); + bool ConsistencyCheck(); + bool ConsistencyCheck(LookupEntry *node, int &depth); #else - void DumpTree () { } - bool ConsistencyCheck() { return true; } + void DumpTree() + { + } + bool ConsistencyCheck() + { + return true; + } #endif }; @@ -2691,30 +3224,35 @@ struct CLR_RT_EventCache struct Key { CLR_RT_MethodDef_Index m_mdVirtual; // The definition of the virtual method. - CLR_RT_TypeDef_Index m_cls; // The class of the instance we need to resolve. + CLR_RT_TypeDef_Index m_cls; // The class of the instance we need to resolve. }; - Key m_key; - CLR_RT_MethodDef_Index m_md; // The actual implementation of the virtual method. + Key m_key; + CLR_RT_MethodDef_Index m_md; // The actual implementation of the virtual method. }; struct VirtualMethodTable { - Link* m_entries; - Link* m_entriesMRU; - Payload* m_payloads; + Link *m_entries; + Link *m_entriesMRU; + Payload *m_payloads; //--// void Initialize(); - bool FindVirtualMethod( const CLR_RT_TypeDef_Index& cls, const CLR_RT_MethodDef_Index& mdVirtual, CLR_RT_MethodDef_Index& md ); - - private: + bool FindVirtualMethod( + const CLR_RT_TypeDef_Index &cls, + const CLR_RT_MethodDef_Index &mdVirtual, + CLR_RT_MethodDef_Index &md); - CLR_UINT32 GetNewEntry() { return m_entriesMRU[ LinkMRUArraySize() - 1 ].m_prev; } + private: + CLR_UINT32 GetNewEntry() + { + return m_entriesMRU[LinkMRUArraySize() - 1].m_prev; + } - static void MoveEntryToTop( Link* entries, CLR_UINT32 slot, CLR_UINT32 idx ); + static void MoveEntryToTop(Link *entries, CLR_UINT32 slot, CLR_UINT32 idx); }; #endif @@ -2725,39 +3263,55 @@ struct CLR_RT_EventCache // the scratch array is used to avoid bringing in arm ABI methods (for semihosting) // struct arrays require initialization with the v3.0 compiler and this is done with ABI methods, // unless of course you provide a work around lik this ;-) - unsigned int m_scratch[ (sizeof(BoundedList) * c_maxFastLists + 3) / sizeof(unsigned int) ]; - BoundedList* m_events; + unsigned int m_scratch[(sizeof(BoundedList) * c_maxFastLists + 3) / sizeof(unsigned int)]; + BoundedList *m_events; - VirtualMethodTable m_lookup_VirtualMethod; + VirtualMethodTable m_lookup_VirtualMethod; #ifndef CLR_NO_IL_INLINE - CLR_RT_InlineBuffer* m_inlineBufferStart; + CLR_RT_InlineBuffer *m_inlineBufferStart; #endif //--// - void EventCache_Initialize(); - CLR_UINT32 EventCache_Cleanup (); + void EventCache_Initialize(); + CLR_UINT32 EventCache_Cleanup(); - void Append_Node ( CLR_RT_HeapBlock* node ); - CLR_RT_HeapBlock* Extract_Node_Slow ( CLR_UINT32 dataType, CLR_UINT32 flags, CLR_UINT32 blocks ); - CLR_RT_HeapBlock* Extract_Node_Fast ( CLR_UINT32 dataType, CLR_UINT32 flags, CLR_UINT32 blocks ); - CLR_RT_HeapBlock* Extract_Node_Bytes( CLR_UINT32 dataType, CLR_UINT32 flags, CLR_UINT32 bytes ); - CLR_RT_HeapBlock* Extract_Node ( CLR_UINT32 dataType, CLR_UINT32 flags, CLR_UINT32 blocks ); + void Append_Node(CLR_RT_HeapBlock *node); + CLR_RT_HeapBlock *Extract_Node_Slow(CLR_UINT32 dataType, CLR_UINT32 flags, CLR_UINT32 blocks); + CLR_RT_HeapBlock *Extract_Node_Fast(CLR_UINT32 dataType, CLR_UINT32 flags, CLR_UINT32 blocks); + CLR_RT_HeapBlock *Extract_Node_Bytes(CLR_UINT32 dataType, CLR_UINT32 flags, CLR_UINT32 bytes); + CLR_RT_HeapBlock *Extract_Node(CLR_UINT32 dataType, CLR_UINT32 flags, CLR_UINT32 blocks); - bool FindVirtualMethod( const CLR_RT_TypeDef_Index& cls, const CLR_RT_MethodDef_Index& mdVirtual, CLR_RT_MethodDef_Index& md ); + bool FindVirtualMethod( + const CLR_RT_TypeDef_Index &cls, + const CLR_RT_MethodDef_Index &mdVirtual, + CLR_RT_MethodDef_Index &md); #ifndef CLR_NO_IL_INLINE - bool GetInlineFrameBuffer(CLR_RT_InlineBuffer** ppBuffer); - bool FreeInlineBuffer(CLR_RT_InlineBuffer* pBuffer); + bool GetInlineFrameBuffer(CLR_RT_InlineBuffer **ppBuffer); + bool FreeInlineBuffer(CLR_RT_InlineBuffer *pBuffer); #endif //--// -#define EVENTCACHE_EXTRACT_NODE_AS_BYTES(ev,cls,type,flags,size) (cls*)((ev).Extract_Node_Bytes( type, flags, size )) -#define EVENTCACHE_EXTRACT_NODE_AS_BLOCKS(ev,cls,type,flags,size) (cls*)((ev).Extract_Node( type, flags, size )) -#define EVENTCACHE_EXTRACT_NODE(ev,cls,type) EVENTCACHE_EXTRACT_NODE_AS_BLOCKS(ev,cls,type, 0,CONVERTFROMSIZETOHEAPBLOCKS(sizeof(cls))) -#define EVENTCACHE_EXTRACT_NODE_NOALLOC(ev,cls,type) EVENTCACHE_EXTRACT_NODE_AS_BLOCKS(ev,cls,type,CLR_RT_HeapBlock::HB_NoGcOnFailure ,CONVERTFROMSIZETOHEAPBLOCKS(sizeof(cls))) -#define EVENTCACHE_EXTRACT_NODE_INITTOZERO(ev,cls,type) EVENTCACHE_EXTRACT_NODE_AS_BLOCKS(ev,cls,type,CLR_RT_HeapBlock::HB_InitializeToZero,CONVERTFROMSIZETOHEAPBLOCKS(sizeof(cls))) +#define EVENTCACHE_EXTRACT_NODE_AS_BYTES(ev, cls, type, flags, size) (cls *)((ev).Extract_Node_Bytes(type, flags, size)) +#define EVENTCACHE_EXTRACT_NODE_AS_BLOCKS(ev, cls, type, flags, size) (cls *)((ev).Extract_Node(type, flags, size)) +#define EVENTCACHE_EXTRACT_NODE(ev, cls, type) \ + EVENTCACHE_EXTRACT_NODE_AS_BLOCKS(ev, cls, type, 0, CONVERTFROMSIZETOHEAPBLOCKS(sizeof(cls))) +#define EVENTCACHE_EXTRACT_NODE_NOALLOC(ev, cls, type) \ + EVENTCACHE_EXTRACT_NODE_AS_BLOCKS( \ + ev, \ + cls, \ + type, \ + CLR_RT_HeapBlock::HB_NoGcOnFailure, \ + CONVERTFROMSIZETOHEAPBLOCKS(sizeof(cls))) +#define EVENTCACHE_EXTRACT_NODE_INITTOZERO(ev, cls, type) \ + EVENTCACHE_EXTRACT_NODE_AS_BLOCKS( \ + ev, \ + cls, \ + type, \ + CLR_RT_HeapBlock::HB_InitializeToZero, \ + CONVERTFROMSIZETOHEAPBLOCKS(sizeof(cls))) //--// @@ -2771,10 +3325,10 @@ extern CLR_RT_EventCache g_CLR_RT_EventCache; // defined arrays to handle those data structures in the Virtual Method cache #if defined(NANOCLR_USE_AVLTREE_FOR_METHODLOOKUP) -CT_ASSERT( sizeof(CLR_RT_EventCache::LookupEntry) == 12 ) +CT_ASSERT(sizeof(CLR_RT_EventCache::LookupEntry) == 12) #else -CT_ASSERT( sizeof(CLR_RT_EventCache::Link) == 4 ) -CT_ASSERT( sizeof(CLR_RT_EventCache::Payload) == 12 ) +CT_ASSERT(sizeof(CLR_RT_EventCache::Link) == 4) +CT_ASSERT(sizeof(CLR_RT_EventCache::Payload) == 12) #endif ////////////////////////////////////////////////////////////////////////////////////// @@ -2797,137 +3351,163 @@ extern bool g_CLR_RT_fBadStack; #endif //--// +typedef enum Events +{ + Event_SerialPortIn = 0x00000002, + Event_SerialPortOut = 0x00000004, + Event_EndPoint = 0x00000008, + Event_StorageIo = 0x00000020, + Event_I2cMaster = 0x00000080, + Event_SpiMaster = 0x00000100, + Event_OneWireMaster = 0x00000200, + Event_Radio = 0x00000400, + Event_AppDomain = 0x02000000, + Event_Socket = 0x20000000, + Event_IdleCPU = 0x40000000, + Event_LowMemory = 0x80000000, +} Events; struct CLR_RT_ExecutionEngine { - static const CLR_UINT32 c_Event_SerialPortIn = 0x00000002; - static const CLR_UINT32 c_Event_SerialPortOut = 0x00000004; - static const CLR_UINT32 c_Event_EndPoint = 0x00000008; - static const CLR_UINT32 c_Event_StorageIo = 0x00000020; - static const CLR_UINT32 c_Event_I2cMaster = 0x00000080; - static const CLR_UINT32 c_Event_SpiMaster = 0x00000100; - static const CLR_UINT32 c_Event_OneWireMaster = 0x00000200; - static const CLR_UINT32 c_Event_Radio = 0x00000400; - static const CLR_UINT32 c_Event_AppDomain = 0x02000000; - static const CLR_UINT32 c_Event_Socket = 0x20000000; - static const CLR_UINT32 c_Event_IdleCPU = 0x40000000; - static const CLR_UINT32 c_Event_LowMemory = 0x80000000; // Wait for a low-memory condition. - //////////////////////////////////////////////////////////////////////////////////////////////// - static const CLR_UINT32 c_Compile_CPP = 0x00000001; - static const CLR_UINT32 c_Compile_ARM = 0x00000002; + static const CLR_UINT32 c_Compile_CPP = 0x00000001; + static const CLR_UINT32 c_Compile_ARM = 0x00000002; //////////////////////////////////////////////////////////////////////////////////////////////// - static const int c_HeapState_Normal = 0x00000000; - static const int c_HeapState_UnderGC = 0x00000001; + static const int c_HeapState_Normal = 0x00000000; + static const int c_HeapState_UnderGC = 0x00000001; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // NEED TO KEEP THESE IN SYNC WITH Enum 'Commands.Debugging_Execution_ChangeConditions...' on debugger library code // + // NEED TO KEEP THESE IN SYNC WITH Enum 'Commands.Debugging_Execution_ChangeConditions...' on debugger library code + // // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - static const int c_fDebugger_StateInitialize = 0x00000000; - static const int c_fDebugger_StateResolutionFailed = 0x00000001; - static const int c_fDebugger_StateProgramRunning = 0x00000400; - static const int c_fDebugger_StateProgramExited = 0x00000800; - static const int c_fDebugger_StateMask = c_fDebugger_StateProgramRunning + c_fDebugger_StateProgramExited; + static const int c_fDebugger_StateInitialize = 0x00000000; + static const int c_fDebugger_StateResolutionFailed = 0x00000001; + static const int c_fDebugger_StateProgramRunning = 0x00000400; + static const int c_fDebugger_StateProgramExited = 0x00000800; + static const int c_fDebugger_StateMask = c_fDebugger_StateProgramRunning + c_fDebugger_StateProgramExited; // - static const int c_fDebugger_BreakpointsDisabled = 0x00001000; + static const int c_fDebugger_BreakpointsDisabled = 0x00001000; // - static const int c_fDebugger_Quiet = 0x00010000; // Do not spew debug text to the debugger - static const int c_fDebugger_ExitPending = 0x00020000; + static const int c_fDebugger_Quiet = 0x00010000; // Do not spew debug text to the debugger + static const int c_fDebugger_ExitPending = 0x00020000; // - static const int c_fDebugger_PauseTimers = 0x04000000; // Threads associated with timers are created in "suspended" mode. - static const int c_fDebugger_NoCompaction = 0x08000000; // Don't perform compaction during execution. + static const int c_fDebugger_PauseTimers = + 0x04000000; // Threads associated with timers are created in "suspended" mode. + static const int c_fDebugger_NoCompaction = 0x08000000; // Don't perform compaction during execution. // - static const int c_fDebugger_SourceLevelDebugging = 0x10000000; - static const int c_fDebugger_RebootPending = 0x20000000; - static const int c_fDebugger_Enabled = 0x40000000; - static const int c_fDebugger_Stopped = 0x80000000; + static const int c_fDebugger_SourceLevelDebugging = 0x10000000; + static const int c_fDebugger_RebootPending = 0x20000000; + static const int c_fDebugger_Enabled = 0x40000000; + static const int c_fDebugger_Stopped = 0x80000000; - volatile int m_iDebugger_Conditions; + volatile int m_iDebugger_Conditions; //////////////////////////////////////////////////////////////////////////////////////////////// - static const int c_fExecution_GC_Pending = 0x00000001; //Not currently used - static const int c_fExecution_Compaction_Pending = 0x00000002; + static const int c_fExecution_GC_Pending = 0x00000001; // Not currently used + static const int c_fExecution_Compaction_Pending = 0x00000002; #if defined(NANOCLR_APPDOMAINS) - static const int c_fExecution_UnloadingAppDomain = 0x00000004; + static const int c_fExecution_UnloadingAppDomain = 0x00000004; #endif - int m_iExecution_Conditions; + int m_iExecution_Conditions; - int m_iReboot_Options; + int m_iReboot_Options; //////////////////////////////////////////////////////////////////////////////////////////////// - static const int c_fProfiling_Enabled = 0x00000001; - static const int c_fProfiling_Allocations = 0x00000002; - static const int c_fProfiling_Calls = 0x00000004; - static const int c_fProfiling_CLRTypes = 0x00000008; //Don't dump out certain types, like ASSEMBLY, or THREAD, or BINARY_BLOB, etc. - int m_iProfiling_Conditions; + static const int c_fProfiling_Enabled = 0x00000001; + static const int c_fProfiling_Allocations = 0x00000002; + static const int c_fProfiling_Calls = 0x00000004; + static const int c_fProfiling_CLRTypes = + 0x00000008; // Don't dump out certain types, like ASSEMBLY, or THREAD, or BINARY_BLOB, etc. + int m_iProfiling_Conditions; enum - { EXECUTION_COUNTER_MAXIMUM = 0x70000000, // Threshold value when we increase all execution counters to avoid overflow - EXECUTION_COUNTER_ADJUSTMENT = 0x60000000 // The update ( increase ) value for all executioin counters after threshold is reached. + { + EXECUTION_COUNTER_MAXIMUM = + 0x70000000, // Threshold value when we increase all execution counters to avoid overflow + EXECUTION_COUNTER_ADJUSTMENT = + 0x60000000 // The update ( increase ) value for all executioin counters after threshold is reached. }; //////////////////////////////////////////////////////////////////////////////////////////////// #if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) - static const int c_MaxBreakpointsActive = 5; + static const int c_MaxBreakpointsActive = 5; - size_t m_breakpointsNum; - CLR_DBG_Commands::Debugging_Execution_BreakpointDef* m_breakpoints; - CLR_DBG_Commands::Debugging_Execution_BreakpointDef m_breakpointsActive[ c_MaxBreakpointsActive ]; - size_t m_breakpointsActiveNum; + size_t m_breakpointsNum; + CLR_DBG_Commands::Debugging_Execution_BreakpointDef *m_breakpoints; + CLR_DBG_Commands::Debugging_Execution_BreakpointDef m_breakpointsActive[c_MaxBreakpointsActive]; + size_t m_breakpointsActiveNum; #endif //#if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) #if !defined(BUILD_RTM) || defined(_WIN32) - bool m_fPerformGarbageCollection; //Should the EE do a GC every context switch - bool m_fPerformHeapCompaction; //Should the EE do a Compaction following every GC + bool m_fPerformGarbageCollection; // Should the EE do a GC every context switch + bool m_fPerformHeapCompaction; // Should the EE do a Compaction following every GC #endif #if defined(NANOCLR_APPDOMAINS) - static const int c_AppDomainId_Invalid = 0; - - CLR_RT_DblLinkedList m_appDomains; - CLR_RT_AppDomain* m_appDomainCurrent; - int m_appDomainIdNext; - - CLR_RT_AppDomain* SetCurrentAppDomain( CLR_RT_AppDomain* appDomain ); - CLR_RT_AppDomain* GetCurrentAppDomain( ); - - HRESULT UnloadAppDomain ( CLR_RT_AppDomain* appDomain, CLR_RT_Thread* th ); - void PrepareThreadsForAppDomainUnload( CLR_RT_AppDomain* appDomain, CLR_RT_DblLinkedList& threads ); - - void TryToUnloadAppDomains_Helper_Threads ( CLR_RT_DblLinkedList& threads ); - void TryToUnloadAppDomains_Helper_Finalizers( CLR_RT_DblLinkedList& finalizers, bool fAlive ); - bool TryToUnloadAppDomains ( ); -#endif //NANOCLR_APPDOMAINS - -#define CLR_EE_DBG_IS( Cond ) ((g_CLR_RT_ExecutionEngine.m_iDebugger_Conditions & CLR_RT_ExecutionEngine::c_fDebugger_##Cond) != 0) -#define CLR_EE_DBG_IS_NOT( Cond ) ((g_CLR_RT_ExecutionEngine.m_iDebugger_Conditions & CLR_RT_ExecutionEngine::c_fDebugger_##Cond) == 0) -#define CLR_EE_DBG_SET( Cond ) g_CLR_RT_ExecutionEngine.m_iDebugger_Conditions |= CLR_RT_ExecutionEngine::c_fDebugger_##Cond -#define CLR_EE_DBG_CLR( Cond ) g_CLR_RT_ExecutionEngine.m_iDebugger_Conditions &= ~CLR_RT_ExecutionEngine::c_fDebugger_##Cond -#define CLR_EE_DBG_SET_MASK( Cond, Mask ) CLR_EE_DBG_CLR( Mask ); CLR_EE_DBG_SET( Cond ); -#define CLR_EE_DBG_RESTORE( Cond, f ) ((f) ? CLR_EE_DBG_SET( Cond ) : CLR_EE_DBG_CLR( Cond ) ) -#define CLR_EE_DBG_IS_MASK( Cond, Mask ) ((g_CLR_RT_ExecutionEngine.m_iDebugger_Conditions & CLR_RT_ExecutionEngine::c_fDebugger_##Mask) == CLR_RT_ExecutionEngine::c_fDebugger_##Cond) - -#define CLR_EE_PRF_IS( Cond ) ((g_CLR_RT_ExecutionEngine.m_iProfiling_Conditions & CLR_RT_ExecutionEngine::c_fProfiling_##Cond) != 0) -#define CLR_EE_PRF_IS_NOT( Cond ) ((g_CLR_RT_ExecutionEngine.m_iProfiling_Conditions & CLR_RT_ExecutionEngine::c_fProfiling_##Cond) == 0) - -#define CLR_EE_IS( Cond ) ((g_CLR_RT_ExecutionEngine.m_iExecution_Conditions & CLR_RT_ExecutionEngine::c_fExecution_##Cond) != 0) -#define CLR_EE_IS_NOT( Cond ) ((g_CLR_RT_ExecutionEngine.m_iExecution_Conditions & CLR_RT_ExecutionEngine::c_fExecution_##Cond) == 0) -#define CLR_EE_SET( Cond ) g_CLR_RT_ExecutionEngine.m_iExecution_Conditions |= CLR_RT_ExecutionEngine::c_fExecution_##Cond -#define CLR_EE_CLR( Cond ) g_CLR_RT_ExecutionEngine.m_iExecution_Conditions &= ~CLR_RT_ExecutionEngine::c_fExecution_##Cond - -#define CLR_EE_REBOOT_IS( Cond ) ((g_CLR_RT_ExecutionEngine.m_iReboot_Options & CLR_DBG_Commands::Monitor_Reboot::c_##Cond) == CLR_DBG_Commands::Monitor_Reboot::c_##Cond) -#define CLR_EE_REBOOT_CLR g_CLR_RT_ExecutionEngine.m_iReboot_Options = CLR_DBG_Commands::Monitor_Reboot::c_ClrOnly - -#define CLR_EE_DBG_EVENT_SEND( cmd, size, payload, flags ) ((g_CLR_DBG_Debugger->m_messaging != NULL) ? g_CLR_DBG_Debugger->m_messaging->SendEvent( cmd, size, (unsigned char*)payload, flags ) : false) - -#define CLR_EE_DBG_EVENT_BROADCAST( cmd, size, payload, flags ) CLR_EE_DBG_EVENT_SEND( cmd, size, payload, flags ) + static const int c_AppDomainId_Invalid = 0; + + CLR_RT_DblLinkedList m_appDomains; + CLR_RT_AppDomain *m_appDomainCurrent; + int m_appDomainIdNext; + + CLR_RT_AppDomain *SetCurrentAppDomain(CLR_RT_AppDomain *appDomain); + CLR_RT_AppDomain *GetCurrentAppDomain(); + + HRESULT UnloadAppDomain(CLR_RT_AppDomain *appDomain, CLR_RT_Thread *th); + void PrepareThreadsForAppDomainUnload(CLR_RT_AppDomain *appDomain, CLR_RT_DblLinkedList &threads); + + void TryToUnloadAppDomains_Helper_Threads(CLR_RT_DblLinkedList &threads); + void TryToUnloadAppDomains_Helper_Finalizers(CLR_RT_DblLinkedList &finalizers, bool fAlive); + bool TryToUnloadAppDomains(); +#endif // NANOCLR_APPDOMAINS + +#define CLR_EE_DBG_IS(Cond) \ + ((g_CLR_RT_ExecutionEngine.m_iDebugger_Conditions & CLR_RT_ExecutionEngine::c_fDebugger_##Cond) != 0) +#define CLR_EE_DBG_IS_NOT(Cond) \ + ((g_CLR_RT_ExecutionEngine.m_iDebugger_Conditions & CLR_RT_ExecutionEngine::c_fDebugger_##Cond) == 0) +#define CLR_EE_DBG_SET(Cond) \ + g_CLR_RT_ExecutionEngine.m_iDebugger_Conditions |= CLR_RT_ExecutionEngine::c_fDebugger_##Cond +#define CLR_EE_DBG_CLR(Cond) \ + g_CLR_RT_ExecutionEngine.m_iDebugger_Conditions &= ~CLR_RT_ExecutionEngine::c_fDebugger_##Cond +#define CLR_EE_DBG_SET_MASK(Cond, Mask) \ + CLR_EE_DBG_CLR(Mask); \ + CLR_EE_DBG_SET(Cond); +#define CLR_EE_DBG_RESTORE(Cond, f) ((f) ? CLR_EE_DBG_SET(Cond) : CLR_EE_DBG_CLR(Cond)) +#define CLR_EE_DBG_IS_MASK(Cond, Mask) \ + ((g_CLR_RT_ExecutionEngine.m_iDebugger_Conditions & CLR_RT_ExecutionEngine::c_fDebugger_##Mask) == \ + CLR_RT_ExecutionEngine::c_fDebugger_##Cond) + +#define CLR_EE_PRF_IS(Cond) \ + ((g_CLR_RT_ExecutionEngine.m_iProfiling_Conditions & CLR_RT_ExecutionEngine::c_fProfiling_##Cond) != 0) +#define CLR_EE_PRF_IS_NOT(Cond) \ + ((g_CLR_RT_ExecutionEngine.m_iProfiling_Conditions & CLR_RT_ExecutionEngine::c_fProfiling_##Cond) == 0) + +#define CLR_EE_IS(Cond) \ + ((g_CLR_RT_ExecutionEngine.m_iExecution_Conditions & CLR_RT_ExecutionEngine::c_fExecution_##Cond) != 0) +#define CLR_EE_IS_NOT(Cond) \ + ((g_CLR_RT_ExecutionEngine.m_iExecution_Conditions & CLR_RT_ExecutionEngine::c_fExecution_##Cond) == 0) +#define CLR_EE_SET(Cond) g_CLR_RT_ExecutionEngine.m_iExecution_Conditions |= CLR_RT_ExecutionEngine::c_fExecution_##Cond +#define CLR_EE_CLR(Cond) \ + g_CLR_RT_ExecutionEngine.m_iExecution_Conditions &= ~CLR_RT_ExecutionEngine::c_fExecution_##Cond + +#define CLR_EE_REBOOT_IS(Cond) \ + ((g_CLR_RT_ExecutionEngine.m_iReboot_Options & CLR_DBG_Commands::Monitor_Reboot::c_##Cond) == \ + CLR_DBG_Commands::Monitor_Reboot::c_##Cond) +#define CLR_EE_REBOOT_CLR g_CLR_RT_ExecutionEngine.m_iReboot_Options = CLR_DBG_Commands::Monitor_Reboot::c_ClrOnly + +#define CLR_EE_DBG_EVENT_SEND(cmd, size, payload, flags) \ + ((g_CLR_DBG_Debugger->m_messaging != NULL) \ + ? g_CLR_DBG_Debugger->m_messaging->SendEvent(cmd, size, (unsigned char *)payload, flags) \ + : false) + +#define CLR_EE_DBG_EVENT_BROADCAST(cmd, size, payload, flags) CLR_EE_DBG_EVENT_SEND(cmd, size, payload, flags) //////////////////////////////////////////////////////////////////////////////////////////////// @@ -2936,13 +3516,13 @@ struct CLR_RT_ExecutionEngine // struct ExecutionConstraintCompensation { - CLR_INT32 m_recursion; - CLR_INT32 m_start; - CLR_INT32 m_cumulative; + CLR_INT32 m_recursion; + CLR_INT32 m_start; + CLR_INT32 m_cumulative; void Suspend() { - if(m_recursion++ == 0) + if (m_recursion++ == 0) { m_start = HAL_Time_CurrentSysTicks(); } @@ -2950,74 +3530,74 @@ struct CLR_RT_ExecutionEngine void Resume() { - if(m_recursion) + if (m_recursion) { - if(--m_recursion == 0) + if (--m_recursion == 0) { m_cumulative += (HAL_Time_CurrentSysTicks() - m_start); } } } - CLR_INT64 Adjust( CLR_INT64 time ) const + CLR_INT64 Adjust(CLR_INT64 time) const { // FIXME: evaluate if the caller code can be adjusted to use SysTicks instead of 100ns ticks - return time + ::HAL_Time_SysTicksToTime( m_cumulative ); + return time + ::HAL_Time_SysTicksToTime(m_cumulative); } }; static ExecutionConstraintCompensation s_compensation; //--// - - CLR_INT64 m_maximumTimeToActive; - + + CLR_INT64 m_maximumTimeToActive; + //--// - - CLR_INT64 m_startTime; - CLR_INT64 m_currentNextActivityTime; - bool m_timerCache; - CLR_UINT64 m_timerCacheNextTimeout; - CLR_RT_DblLinkedList m_heap; // list of CLR_RT_HeapCluster - CLR_RT_HeapCluster* m_lastHcUsed; - int m_heapState; + CLR_INT64 m_startTime; + CLR_INT64 m_currentNextActivityTime; + bool m_timerCache; + CLR_UINT64 m_timerCacheNextTimeout; + + CLR_RT_DblLinkedList m_heap; // list of CLR_RT_HeapCluster + CLR_RT_HeapCluster *m_lastHcUsed; + int m_heapState; - CLR_RT_DblLinkedList m_weakReferences; // OBJECT HEAP - DO RELOCATION - list of CLR_RT_HeapBlock_WeakReference + CLR_RT_DblLinkedList m_weakReferences; // OBJECT HEAP - DO RELOCATION - list of CLR_RT_HeapBlock_WeakReference - CLR_RT_DblLinkedList m_timers; // EVENT HEAP - NO RELOCATION - list of CLR_RT_HeapBlock_Timer - CLR_UINT32 m_raisedEvents; + CLR_RT_DblLinkedList m_timers; // EVENT HEAP - NO RELOCATION - list of CLR_RT_HeapBlock_Timer + CLR_UINT32 m_raisedEvents; - CLR_RT_DblLinkedList m_threadsReady; // EVENT HEAP - NO RELOCATION - list of CLR_RT_Thread - CLR_RT_DblLinkedList m_threadsWaiting; // EVENT HEAP - NO RELOCATION - list of CLR_RT_Thread - CLR_RT_DblLinkedList m_threadsZombie; // EVENT HEAP - NO RELOCATION - list of CLR_RT_Thread - int m_lastPid; - CLR_RT_Thread* m_currentThread; + CLR_RT_DblLinkedList m_threadsReady; // EVENT HEAP - NO RELOCATION - list of CLR_RT_Thread + CLR_RT_DblLinkedList m_threadsWaiting; // EVENT HEAP - NO RELOCATION - list of CLR_RT_Thread + CLR_RT_DblLinkedList m_threadsZombie; // EVENT HEAP - NO RELOCATION - list of CLR_RT_Thread + int m_lastPid; + CLR_RT_Thread *m_currentThread; - CLR_RT_DblLinkedList m_finalizersAlive; // EVENT HEAP - NO RELOCATION - list of CLR_RT_HeapBlock_Finalizer - CLR_RT_DblLinkedList m_finalizersPending; // EVENT HEAP - NO RELOCATION - list of CLR_RT_HeapBlock_Finalizer - CLR_RT_Thread* m_finalizerThread; // EVENT HEAP - NO RELOCATION - - CLR_RT_Thread* m_cctorThread; // EVENT HEAP - NO RELOCATION - + CLR_RT_DblLinkedList m_finalizersAlive; // EVENT HEAP - NO RELOCATION - list of CLR_RT_HeapBlock_Finalizer + CLR_RT_DblLinkedList m_finalizersPending; // EVENT HEAP - NO RELOCATION - list of CLR_RT_HeapBlock_Finalizer + CLR_RT_Thread *m_finalizerThread; // EVENT HEAP - NO RELOCATION - + CLR_RT_Thread *m_cctorThread; // EVENT HEAP - NO RELOCATION - #if !defined(NANOCLR_APPDOMAINS) - CLR_RT_HeapBlock* m_globalLock; // OBJECT HEAP - DO RELOCATION - - CLR_RT_HeapBlock* m_outOfMemoryException; // OBJECT HEAP - DO RELOCATION - + CLR_RT_HeapBlock *m_globalLock; // OBJECT HEAP - DO RELOCATION - + CLR_RT_HeapBlock *m_outOfMemoryException; // OBJECT HEAP - DO RELOCATION - #endif - CLR_RT_HeapBlock* m_currentUICulture; // OBJECT HEAP - DO RELOCATION - + CLR_RT_HeapBlock *m_currentUICulture; // OBJECT HEAP - DO RELOCATION - //--// - CLR_RT_Thread* m_interruptThread; // EVENT HEAP - NO RELOCATION - CLR_RT_Thread* m_timerThread; // EVENT HEAP - NO RELOCATION + CLR_RT_Thread *m_interruptThread; // EVENT HEAP - NO RELOCATION + CLR_RT_Thread *m_timerThread; // EVENT HEAP - NO RELOCATION //--// #if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) - CLR_RT_HeapBlock_Array* m_scratchPadArray; // OBJECT HEAP - DO RELOCATION - + CLR_RT_HeapBlock_Array *m_scratchPadArray; // OBJECT HEAP - DO RELOCATION - #endif - bool m_fShuttingDown; + bool m_fShuttingDown; //--// @@ -3031,212 +3611,234 @@ struct CLR_RT_ExecutionEngine HRESULT StartHardware(); - static void Reboot( bool fHard ); + static void Reboot(bool fHard); void JoinAllThreadsAndExecuteFinalizer(); - + void LoadDownloadedAssemblies(); static void ExecutionConstraint_Suspend(); - static void ExecutionConstraint_Resume (); + static void ExecutionConstraint_Resume(); CLR_UINT32 PerformGarbageCollection(); - void PerformHeapCompaction (); + void PerformHeapCompaction(); - void Relocate(); + void Relocate(); - HRESULT ScheduleThreads( int maxContextSwitch ); + HRESULT ScheduleThreads(int maxContextSwitch); - CLR_UINT32 WaitForActivity( CLR_UINT32 powerLevel, CLR_UINT32 events, CLR_INT64 timeout_ms ); - CLR_UINT32 WaitForActivity( ); + CLR_UINT32 WaitForActivity(CLR_UINT32 powerLevel, CLR_UINT32 events, CLR_INT64 timeout_ms); + CLR_UINT32 WaitForActivity(); - HRESULT Execute ( wchar_t* entryPointArgs, int maxContextSwitch ); + HRESULT Execute(wchar_t *entryPointArgs, int maxContextSwitch); HRESULT WaitForDebugger(); - static CLR_RT_HeapBlock* AccessStaticField( const CLR_RT_FieldDef_Index& fd ); + static CLR_RT_HeapBlock *AccessStaticField(const CLR_RT_FieldDef_Index &fd); - void ProcessTimeEvent( CLR_UINT32 event ); + void ProcessTimeEvent(CLR_UINT32 event); static void InvalidateTimerCache(); static CLR_INT64 GetUptime(); - CLR_RT_HeapBlock* ExtractHeapBlocksForArray( CLR_RT_TypeDef_Instance& inst, CLR_UINT32 length, const CLR_RT_ReflectionDef_Index& reflex ); - CLR_RT_HeapBlock* ExtractHeapBlocksForClassOrValueTypes( CLR_UINT32 dataType, CLR_UINT32 flags, const CLR_RT_TypeDef_Index& cls, CLR_UINT32 length ); - CLR_RT_HeapBlock* ExtractHeapBytesForObjects ( CLR_UINT32 dataType, CLR_UINT32 flags, CLR_UINT32 length ); - CLR_RT_HeapBlock* ExtractHeapBlocksForObjects ( CLR_UINT32 dataType, CLR_UINT32 flags, CLR_UINT32 length ); - CLR_RT_HeapBlock_Node* ExtractHeapBlocksForEvents ( CLR_UINT32 dataType, CLR_UINT32 flags, CLR_UINT32 length ); - - HRESULT NewThread ( CLR_RT_Thread*& th, CLR_RT_HeapBlock_Delegate* pDelegate, int priority, CLR_INT32 id, CLR_UINT32 flags = 0 ); - void PutInProperList( CLR_RT_Thread* th ); - CLR_INT32 GetNextThreadId( ); + CLR_RT_HeapBlock *ExtractHeapBlocksForArray( + CLR_RT_TypeDef_Instance &inst, + CLR_UINT32 length, + const CLR_RT_ReflectionDef_Index &reflex); + CLR_RT_HeapBlock *ExtractHeapBlocksForClassOrValueTypes( + CLR_UINT32 dataType, + CLR_UINT32 flags, + const CLR_RT_TypeDef_Index &cls, + CLR_UINT32 length); + CLR_RT_HeapBlock *ExtractHeapBytesForObjects(CLR_UINT32 dataType, CLR_UINT32 flags, CLR_UINT32 length); + CLR_RT_HeapBlock *ExtractHeapBlocksForObjects(CLR_UINT32 dataType, CLR_UINT32 flags, CLR_UINT32 length); + CLR_RT_HeapBlock_Node *ExtractHeapBlocksForEvents(CLR_UINT32 dataType, CLR_UINT32 flags, CLR_UINT32 length); - HRESULT InitializeReference( CLR_RT_HeapBlock& ref, CLR_RT_SignatureParser& parser ); - HRESULT InitializeReference( CLR_RT_HeapBlock& ref, const CLR_RECORD_FIELDDEF* target, CLR_RT_Assembly* assm ); + HRESULT NewThread( + CLR_RT_Thread *&th, + CLR_RT_HeapBlock_Delegate *pDelegate, + int priority, + CLR_INT32 id, + CLR_UINT32 flags = 0); + void PutInProperList(CLR_RT_Thread *th); + CLR_INT32 GetNextThreadId(); - HRESULT InitializeLocals( CLR_RT_HeapBlock* locals, CLR_RT_Assembly* assm, const CLR_RECORD_METHODDEF* md ); + HRESULT InitializeReference(CLR_RT_HeapBlock &ref, CLR_RT_SignatureParser &parser); + HRESULT InitializeReference(CLR_RT_HeapBlock &ref, const CLR_RECORD_FIELDDEF *target, CLR_RT_Assembly *assm); - HRESULT NewObjectFromIndex( CLR_RT_HeapBlock& reference, const CLR_RT_TypeDef_Index& cls ); - HRESULT NewObject ( CLR_RT_HeapBlock& reference, const CLR_RT_TypeDef_Instance& inst ); - HRESULT NewObject ( CLR_RT_HeapBlock& reference, CLR_UINT32 token, CLR_RT_Assembly* assm ); + HRESULT InitializeLocals(CLR_RT_HeapBlock *locals, CLR_RT_Assembly *assm, const CLR_RECORD_METHODDEF *md); - HRESULT CloneObject ( CLR_RT_HeapBlock& reference , const CLR_RT_HeapBlock& source ); - HRESULT CopyValueType( CLR_RT_HeapBlock* destination, const CLR_RT_HeapBlock* source ); + HRESULT NewObjectFromIndex(CLR_RT_HeapBlock &reference, const CLR_RT_TypeDef_Index &cls); + HRESULT NewObject(CLR_RT_HeapBlock &reference, const CLR_RT_TypeDef_Instance &inst); + HRESULT NewObject(CLR_RT_HeapBlock &reference, CLR_UINT32 token, CLR_RT_Assembly *assm); - HRESULT NewArrayList ( CLR_RT_HeapBlock& ref, int size, CLR_RT_HeapBlock_Array*& array ); + HRESULT CloneObject(CLR_RT_HeapBlock &reference, const CLR_RT_HeapBlock &source); + HRESULT CopyValueType(CLR_RT_HeapBlock *destination, const CLR_RT_HeapBlock *source); + HRESULT NewArrayList(CLR_RT_HeapBlock &ref, int size, CLR_RT_HeapBlock_Array *&array); - HRESULT FindFieldDef( CLR_RT_TypeDef_Instance& inst , const char* szText , CLR_RT_FieldDef_Index& res ); - HRESULT FindFieldDef( CLR_RT_HeapBlock& reference, const char* szText , CLR_RT_FieldDef_Index& res ); - HRESULT FindField ( CLR_RT_HeapBlock& reference, const char* szText, CLR_RT_HeapBlock*& field ); - HRESULT SetField ( CLR_RT_HeapBlock& reference, const char* szText, CLR_RT_HeapBlock& value ); - HRESULT GetField ( CLR_RT_HeapBlock& reference, const char* szText, CLR_RT_HeapBlock& value ); + HRESULT FindFieldDef(CLR_RT_TypeDef_Instance &inst, const char *szText, CLR_RT_FieldDef_Index &res); + HRESULT FindFieldDef(CLR_RT_HeapBlock &reference, const char *szText, CLR_RT_FieldDef_Index &res); + HRESULT FindField(CLR_RT_HeapBlock &reference, const char *szText, CLR_RT_HeapBlock *&field); + HRESULT SetField(CLR_RT_HeapBlock &reference, const char *szText, CLR_RT_HeapBlock &value); + HRESULT GetField(CLR_RT_HeapBlock &reference, const char *szText, CLR_RT_HeapBlock &value); + HRESULT LockObject(CLR_RT_HeapBlock &reference, CLR_RT_SubThread *sth, const CLR_INT64 &timeExpire, bool fForce); + HRESULT UnlockObject(CLR_RT_HeapBlock &reference, CLR_RT_SubThread *sth); + void DeleteLockRequests(CLR_RT_Thread *thTarget, CLR_RT_SubThread *sthTarget); - HRESULT LockObject ( CLR_RT_HeapBlock& reference, CLR_RT_SubThread* sth, const CLR_INT64& timeExpire, bool fForce ); - HRESULT UnlockObject ( CLR_RT_HeapBlock& reference, CLR_RT_SubThread* sth ); - void DeleteLockRequests( CLR_RT_Thread* thTarget , CLR_RT_SubThread* sthTarget ); + HRESULT Sleep(CLR_RT_Thread *caller, const CLR_INT64 &timeExpire); - HRESULT Sleep( CLR_RT_Thread* caller, const CLR_INT64& timeExpire ); + HRESULT WaitEvents(CLR_RT_Thread *caller, const CLR_INT64 &timeExpire, CLR_UINT32 events, bool &fSuccess); + void SignalEvents(CLR_RT_DblLinkedList &threads, CLR_UINT32 events); + void SignalEvents(CLR_UINT32 events); - HRESULT WaitEvents ( CLR_RT_Thread* caller, const CLR_INT64& timeExpire, CLR_UINT32 events, bool& fSuccess ); - void SignalEvents( CLR_RT_DblLinkedList& threads, CLR_UINT32 events ); - void SignalEvents( CLR_UINT32 events ); + HRESULT InitTimeout(CLR_INT64 &timeExpire, const CLR_INT64 &timeout); + HRESULT InitTimeout(CLR_INT64 &timeExpire, CLR_INT32 timeout); + static bool IsInstanceOf(CLR_RT_TypeDescriptor &desc, CLR_RT_TypeDescriptor &descTarget, bool isInstInstruction); + static bool IsInstanceOf(const CLR_RT_TypeDef_Index &cls, const CLR_RT_TypeDef_Index &clsTarget); + static bool IsInstanceOf(CLR_RT_HeapBlock &obj, const CLR_RT_TypeDef_Index &clsTarget); + static bool IsInstanceOf(CLR_RT_HeapBlock &obj, CLR_RT_Assembly *assm, CLR_UINT32 token, bool isInstInstruction); - HRESULT InitTimeout( CLR_INT64& timeExpire, const CLR_INT64& timeout ); - HRESULT InitTimeout( CLR_INT64& timeExpire, CLR_INT32 timeout ); - - static bool IsInstanceOf( CLR_RT_TypeDescriptor& desc, CLR_RT_TypeDescriptor& descTarget , bool isInstInstruction); - static bool IsInstanceOf( const CLR_RT_TypeDef_Index& cls , const CLR_RT_TypeDef_Index& clsTarget ); - static bool IsInstanceOf( CLR_RT_HeapBlock& obj , const CLR_RT_TypeDef_Index& clsTarget ); - static bool IsInstanceOf( CLR_RT_HeapBlock& obj , CLR_RT_Assembly* assm, CLR_UINT32 token , bool isInstInstruction); - - static HRESULT CastToType( CLR_RT_HeapBlock& ref, CLR_UINT32 tk, CLR_RT_Assembly* assm, bool isInstInstruction ); + static HRESULT CastToType(CLR_RT_HeapBlock &ref, CLR_UINT32 tk, CLR_RT_Assembly *assm, bool isInstInstruction); void DebuggerLoop(); #if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) - void SetDebuggingInfoBreakpoints( bool fSet ); - void InstallBreakpoints ( CLR_DBG_Commands::Debugging_Execution_BreakpointDef* data, size_t num ); - void StopOnBreakpoint ( CLR_DBG_Commands::Debugging_Execution_BreakpointDef& def , CLR_RT_Thread* th ); - void StopOnBreakpoint ( CLR_DBG_Commands::Debugging_Execution_BreakpointDef& def , CLR_RT_StackFrame* stack, CLR_PMETADATA ip ); - void Breakpoint_System_Event ( CLR_DBG_Commands::Debugging_Execution_BreakpointDef& def , CLR_UINT16 event, CLR_RT_Thread* th, CLR_RT_StackFrame* stack, CLR_PMETADATA ip ); - bool DequeueActiveBreakpoint ( CLR_DBG_Commands::Debugging_Execution_BreakpointDef& def ); + void SetDebuggingInfoBreakpoints(bool fSet); + void InstallBreakpoints(CLR_DBG_Commands::Debugging_Execution_BreakpointDef *data, size_t num); + void StopOnBreakpoint(CLR_DBG_Commands::Debugging_Execution_BreakpointDef &def, CLR_RT_Thread *th); + void StopOnBreakpoint( + CLR_DBG_Commands::Debugging_Execution_BreakpointDef &def, + CLR_RT_StackFrame *stack, + CLR_PMETADATA ip); + void Breakpoint_System_Event( + CLR_DBG_Commands::Debugging_Execution_BreakpointDef &def, + CLR_UINT16 event, + CLR_RT_Thread *th, + CLR_RT_StackFrame *stack, + CLR_PMETADATA ip); + bool DequeueActiveBreakpoint(CLR_DBG_Commands::Debugging_Execution_BreakpointDef &def); void Breakpoint_Assemblies_Loaded(); - void Breakpoint_Threads_Prepare ( CLR_RT_DblLinkedList& threads ); - void Breakpoint_Thread_Terminated( CLR_RT_Thread* th ); - void Breakpoint_Thread_Created ( CLR_RT_Thread* th ); + void Breakpoint_Threads_Prepare(CLR_RT_DblLinkedList &threads); + void Breakpoint_Thread_Terminated(CLR_RT_Thread *th); + void Breakpoint_Thread_Created(CLR_RT_Thread *th); - void Breakpoint_StackFrame_Break ( CLR_RT_StackFrame* stack ); - void Breakpoint_StackFrame_Push ( CLR_RT_StackFrame* stack, CLR_UINT32 reason ); - void Breakpoint_StackFrame_Pop ( CLR_RT_StackFrame* stack, bool stepEH ); - void Breakpoint_StackFrame_Step ( CLR_RT_StackFrame* stack, CLR_PMETADATA ip ); - void Breakpoint_StackFrame_Hard ( CLR_RT_StackFrame* stack, CLR_PMETADATA ip ); + void Breakpoint_StackFrame_Break(CLR_RT_StackFrame *stack); + void Breakpoint_StackFrame_Push(CLR_RT_StackFrame *stack, CLR_UINT32 reason); + void Breakpoint_StackFrame_Pop(CLR_RT_StackFrame *stack, bool stepEH); + void Breakpoint_StackFrame_Step(CLR_RT_StackFrame *stack, CLR_PMETADATA ip); + void Breakpoint_StackFrame_Hard(CLR_RT_StackFrame *stack, CLR_PMETADATA ip); - void Breakpoint_Exception ( CLR_RT_StackFrame* stack, CLR_UINT32 reason, CLR_PMETADATA ip ); - void Breakpoint_Exception_Intercepted( CLR_RT_StackFrame* stack ); - void Breakpoint_Exception_Uncaught ( CLR_RT_Thread* th ); + void Breakpoint_Exception(CLR_RT_StackFrame *stack, CLR_UINT32 reason, CLR_PMETADATA ip); + void Breakpoint_Exception_Intercepted(CLR_RT_StackFrame *stack); + void Breakpoint_Exception_Uncaught(CLR_RT_Thread *th); #endif //#if defined(NANOCLR_ENABLE_SOURCELEVELDEBUGGING) //--// - bool IsTimeExpired( const CLR_INT64& timeExpire, CLR_INT64& timeoutMin ); + bool IsTimeExpired(const CLR_INT64 &timeExpire, CLR_INT64 &timeoutMin); - bool IsThereEnoughIdleTime( CLR_UINT32 expectedMsec ); + bool IsThereEnoughIdleTime(CLR_UINT32 expectedMsec); void SpawnTimer(); void SpawnFinalizer(); - void SpawnStaticConstructor( CLR_RT_Thread *&pCctorThread ); + void SpawnStaticConstructor(CLR_RT_Thread *&pCctorThread); #if defined(NANOCLR_APPDOMAINS) - bool SpawnStaticConstructorHelper( CLR_RT_AppDomain* appDomain, CLR_RT_AppDomainAssembly* appDomainAssembly, const CLR_RT_MethodDef_Index& idx ); + bool SpawnStaticConstructorHelper( + CLR_RT_AppDomain *appDomain, + CLR_RT_AppDomainAssembly *appDomainAssembly, + const CLR_RT_MethodDef_Index &idx); #else - bool SpawnStaticConstructorHelper( CLR_RT_Assembly* assembly, const CLR_RT_MethodDef_Index& idx ); + bool SpawnStaticConstructorHelper(CLR_RT_Assembly *assembly, const CLR_RT_MethodDef_Index &idx); #endif - static void FinalizerTerminationCallback( void* arg ); - static void StaticConstructorTerminationCallback( void* arg ); - bool EnsureSystemThread( CLR_RT_Thread*& thread, int priority ); - + static void FinalizerTerminationCallback(void *arg); + static void StaticConstructorTerminationCallback(void *arg); + bool EnsureSystemThread(CLR_RT_Thread *&thread, int priority); + CLR_INT64 ProcessTimer(); - + //--// PROHIBIT_COPY_CONSTRUCTORS(CLR_RT_ExecutionEngine); //--// -private: - + private: HRESULT AllocateHeaps(); - void DeleteLockRequests( CLR_RT_Thread* thTarget, CLR_RT_SubThread* sthTarget, CLR_RT_DblLinkedList& threads ); - - CLR_RT_HeapBlock* ExtractHeapBlocks ( CLR_RT_DblLinkedList& heap, CLR_UINT32 dataType, CLR_UINT32 flags, CLR_UINT32 length ); + void DeleteLockRequests(CLR_RT_Thread *thTarget, CLR_RT_SubThread *sthTarget, CLR_RT_DblLinkedList &threads); - CLR_RT_HeapBlock_Lock* FindLockObject( CLR_RT_DblLinkedList& threads, CLR_RT_HeapBlock& object ); - CLR_RT_HeapBlock_Lock* FindLockObject( CLR_RT_HeapBlock& object ); + CLR_RT_HeapBlock *ExtractHeapBlocks( + CLR_RT_DblLinkedList &heap, + CLR_UINT32 dataType, + CLR_UINT32 flags, + CLR_UINT32 length); - void CheckTimers ( CLR_INT64& timeoutMin ); - void CheckThreads ( CLR_INT64& timeoutMin, CLR_RT_DblLinkedList& threads ); + CLR_RT_HeapBlock_Lock *FindLockObject(CLR_RT_DblLinkedList &threads, CLR_RT_HeapBlock &object); + CLR_RT_HeapBlock_Lock *FindLockObject(CLR_RT_HeapBlock &object); - void ProcessHardware(); + void CheckTimers(CLR_INT64 &timeoutMin); + void CheckThreads(CLR_INT64 &timeoutMin, CLR_RT_DblLinkedList &threads); + void ProcessHardware(); - void ReleaseAllThreads( CLR_RT_DblLinkedList& threads ); - void AbortAllThreads ( CLR_RT_DblLinkedList& threads ); + void ReleaseAllThreads(CLR_RT_DblLinkedList &threads); + void AbortAllThreads(CLR_RT_DblLinkedList &threads); - void InsertThreadRoundRobin( CLR_RT_DblLinkedList& threads, CLR_RT_Thread* th ); + void InsertThreadRoundRobin(CLR_RT_DblLinkedList &threads, CLR_RT_Thread *th); - CLR_UINT32 WaitSystemEvents( CLR_UINT32 powerLevel, CLR_UINT32 events, CLR_INT64 timeExpire ); + CLR_UINT32 WaitSystemEvents(CLR_UINT32 powerLevel, CLR_UINT32 events, CLR_INT64 timeExpire); #if defined(_WIN32) - HRESULT CreateEntryPointArgs( CLR_RT_HeapBlock& args, wchar_t* szCommandLineArgs ); + HRESULT CreateEntryPointArgs(CLR_RT_HeapBlock &args, wchar_t *szCommandLineArgs); #endif // The lowest value for execution counter in threads. - int m_GlobalExecutionCounter; + int m_GlobalExecutionCounter; // Increase the value of m_executionCounter for all threads by iUpdateValue. // This ensures that counter does not underflow. - void AdjustExecutionCounter( CLR_RT_DblLinkedList &threadList, int iUpdateValue ); -public : - + void AdjustExecutionCounter(CLR_RT_DblLinkedList &threadList, int iUpdateValue); + + public: // This function updates execution counter in pThread and makes it last to execute. // It is used to Thread.Sleep(0) imlementation. The thread is still ready, but is last to execute. - void UpdateToLowestExecutionCounter( CLR_RT_Thread *pThread ) const; - - void RetrieveCurrentMethod( CLR_UINT32& assmIdx, CLR_UINT32& methodIdx ); + void UpdateToLowestExecutionCounter(CLR_RT_Thread *pThread) const; + + void RetrieveCurrentMethod(CLR_UINT32 &assmIdx, CLR_UINT32 &methodIdx); }; extern CLR_RT_ExecutionEngine g_CLR_RT_ExecutionEngine; -extern CLR_UINT32 g_buildCRC; +extern CLR_UINT32 g_buildCRC; //--// // // CT_ASSERT macro generates a compiler error in case the size of any structure changes. // -CT_ASSERT( sizeof(CLR_RT_HeapBlock) == 12 ) -CT_ASSERT( sizeof(CLR_RT_HeapBlock_Raw) == sizeof(CLR_RT_HeapBlock) ) +CT_ASSERT(sizeof(CLR_RT_HeapBlock) == 12) +CT_ASSERT(sizeof(CLR_RT_HeapBlock_Raw) == sizeof(CLR_RT_HeapBlock)) #if defined(NANOCLR_TRACE_MEMORY_STATS) -#define NANOCLR_TRACE_MEMORY_STATS_EXTRA_SIZE 4 +#define NANOCLR_TRACE_MEMORY_STATS_EXTRA_SIZE 4 #else -#define NANOCLR_TRACE_MEMORY_STATS_EXTRA_SIZE 0 +#define NANOCLR_TRACE_MEMORY_STATS_EXTRA_SIZE 0 #endif -#if defined(__GNUC__) // Gcc compiler uses 8 bytes for a function pointer - CT_ASSERT( sizeof(CLR_RT_DataTypeLookup) == 20 + NANOCLR_TRACE_MEMORY_STATS_EXTRA_SIZE ) +#if defined(__GNUC__) // Gcc compiler uses 8 bytes for a function pointer +CT_ASSERT(sizeof(CLR_RT_DataTypeLookup) == 20 + NANOCLR_TRACE_MEMORY_STATS_EXTRA_SIZE) #elif defined(PLATFORM_WINDOWS_EMULATOR) || defined(NANOCLR_TRACE_MEMORY_STATS) - CT_ASSERT( sizeof(CLR_RT_DataTypeLookup) == 16 + 4 ) +CT_ASSERT(sizeof(CLR_RT_DataTypeLookup) == 16 + 4) #else -! ERROR +!ERROR #endif @@ -3247,4 +3849,3 @@ CT_ASSERT( sizeof(CLR_RT_HeapBlock_Raw) == sizeof(CLR_RT_HeapBlock) ) #endif #endif // _NANOCLR_RUNTIME_H_ - diff --git a/src/CLR/Include/nanoCLR_Runtime__HeapBlock.h b/src/CLR/Include/nanoCLR_Runtime__HeapBlock.h index 374c811eb2..49fd0843de 100644 --- a/src/CLR/Include/nanoCLR_Runtime__HeapBlock.h +++ b/src/CLR/Include/nanoCLR_Runtime__HeapBlock.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Include/nanoCLR_Runtime__Serialization.h b/src/CLR/Include/nanoCLR_Runtime__Serialization.h index 32fd47d5b6..2049c8296b 100644 --- a/src/CLR/Include/nanoCLR_Runtime__Serialization.h +++ b/src/CLR/Include/nanoCLR_Runtime__Serialization.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Include/nanoCLR_Types.h b/src/CLR/Include/nanoCLR_Types.h index d2e6dd4721..c0bae25508 100644 --- a/src/CLR/Include/nanoCLR_Types.h +++ b/src/CLR/Include/nanoCLR_Types.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Include/nanoCLR_Win32.h b/src/CLR/Include/nanoCLR_Win32.h index b4fae5be06..be0ea0f067 100644 --- a/src/CLR/Include/nanoCLR_Win32.h +++ b/src/CLR/Include/nanoCLR_Win32.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Include/nanoPackStruct.h b/src/CLR/Include/nanoPackStruct.h index c275b40782..848644c91c 100644 --- a/src/CLR/Include/nanoPackStruct.h +++ b/src/CLR/Include/nanoPackStruct.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // #ifndef _NANO_PACKSTRUCT_H_ diff --git a/src/CLR/Include/nanoSupport.h b/src/CLR/Include/nanoSupport.h index 68c50068d8..e3f7142c03 100644 --- a/src/CLR/Include/nanoSupport.h +++ b/src/CLR/Include/nanoSupport.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Include/nanoWeak.h b/src/CLR/Include/nanoWeak.h index 13290dff71..f13bcc6f14 100644 --- a/src/CLR/Include/nanoWeak.h +++ b/src/CLR/Include/nanoWeak.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Include/nf_errors_exceptions.h b/src/CLR/Include/nf_errors_exceptions.h index 5d7bd40cd1..479b6b0095 100644 --- a/src/CLR/Include/nf_errors_exceptions.h +++ b/src/CLR/Include/nf_errors_exceptions.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Include/opcode.def b/src/CLR/Include/opcode.def index 9f909fc380..57f1e75ba0 100644 --- a/src/CLR/Include/opcode.def +++ b/src/CLR/Include/opcode.def @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Include/stdafx.h b/src/CLR/Include/stdafx.h index d680969bb4..a43c28c002 100644 --- a/src/CLR/Include/stdafx.h +++ b/src/CLR/Include/stdafx.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Messaging/Messaging.cpp b/src/CLR/Messaging/Messaging.cpp index 71f07b1ccd..14bfb6b7fc 100644 --- a/src/CLR/Messaging/Messaging.cpp +++ b/src/CLR/Messaging/Messaging.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // @@ -10,110 +10,130 @@ #include // the Arm 3.0 compiler drags in a bunch of ABI methods (for initialization) if struct arrays are not initialized -CLR_UINT32 g_scratchMessaging[ sizeof(CLR_Messaging) ]; +CLR_UINT32 g_scratchMessaging[sizeof(CLR_Messaging)]; CLR_Messaging *g_CLR_Messaging; //////////////////////////////////////////////////////////////////////////////////////////////////// //--// -static const CLR_Messaging_CommandHandlerLookup c_Messaging_Lookup_Request[] = -{ - { CLR_Messaging::Messaging_Query, CLR_Messaging_Commands::c_Messaging_Query }, - { CLR_Messaging::Messaging_Send, CLR_Messaging_Commands::c_Messaging_Send }, - { CLR_Messaging::Messaging_Reply, CLR_Messaging_Commands::c_Messaging_Reply }, +static const CLR_Messaging_CommandHandlerLookup c_Messaging_Lookup_Request[] = { + {CLR_Messaging::Messaging_Query, CLR_Messaging_Commands::c_Messaging_Query}, + {CLR_Messaging::Messaging_Send, CLR_Messaging_Commands::c_Messaging_Send}, + {CLR_Messaging::Messaging_Reply, CLR_Messaging_Commands::c_Messaging_Reply}, }; -static const CLR_Messaging_CommandHandlerLookup c_Messaging_Lookup_Reply[] = -{ - { CLR_Messaging::Messaging_Query, CLR_Messaging_Commands::c_Messaging_Query }, - { CLR_Messaging::Messaging_Send, CLR_Messaging_Commands::c_Messaging_Send }, - { CLR_Messaging::Messaging_Reply, CLR_Messaging_Commands::c_Messaging_Reply }, +static const CLR_Messaging_CommandHandlerLookup c_Messaging_Lookup_Reply[] = { + {CLR_Messaging::Messaging_Query, CLR_Messaging_Commands::c_Messaging_Query}, + {CLR_Messaging::Messaging_Send, CLR_Messaging_Commands::c_Messaging_Send}, + {CLR_Messaging::Messaging_Reply, CLR_Messaging_Commands::c_Messaging_Reply}, }; - //--// -bool CLR_Messaging::AllocateAndQueueMessage( CLR_UINT32 cmd, unsigned int length, unsigned char* data, CLR_RT_HeapBlock_EndPoint::Port port, CLR_RT_HeapBlock_EndPoint::Address addr, CLR_UINT32 found ) +bool CLR_Messaging::AllocateAndQueueMessage( + CLR_UINT32 cmd, + unsigned int length, + unsigned char *data, + CLR_RT_HeapBlock_EndPoint::Port port, + CLR_RT_HeapBlock_EndPoint::Address addr, + CLR_UINT32 found) { NATIVE_PROFILE_CLR_MESSAGING(); - CLR_RT_HeapBlock_EndPoint::Message* rpc; - CLR_RT_HeapBlock_EndPoint* ep; - - if((ep = CLR_RT_HeapBlock_EndPoint::FindEndPoint( port )) == NULL) return false; + CLR_RT_HeapBlock_EndPoint::Message *rpc; + CLR_RT_HeapBlock_EndPoint *ep; + + if ((ep = CLR_RT_HeapBlock_EndPoint::FindEndPoint(port)) == NULL) + return false; { - CLR_RT_ProtectFromGC gc( *ep ); + CLR_RT_ProtectFromGC gc(*ep); + + if ((rpc = (CLR_RT_HeapBlock_EndPoint::Message *) + CLR_RT_Memory::Allocate(sizeof(*rpc) + length, CLR_RT_HeapBlock::HB_CompactOnFailure)) == NULL) + return false; - if((rpc = (CLR_RT_HeapBlock_EndPoint::Message*)CLR_RT_Memory::Allocate( sizeof(*rpc) + length, CLR_RT_HeapBlock::HB_CompactOnFailure )) == NULL) return false; - rpc->ClearData(); - - rpc->m_cmd = cmd;; - rpc->m_addr = addr; - rpc->m_length = length; - rpc->m_found = found; - - if(data) memcpy( rpc->m_data, data, length ); - ep->m_messages.LinkAtBack( rpc ); + rpc->m_cmd = cmd; + ; + rpc->m_addr = addr; + rpc->m_length = length; + rpc->m_found = found; + + if (data) + memcpy(rpc->m_data, data, length); + + ep->m_messages.LinkAtBack(rpc); - g_CLR_RT_ExecutionEngine.SignalEvents( CLR_RT_ExecutionEngine::c_Event_EndPoint ); + g_CLR_RT_ExecutionEngine.SignalEvents(Event_EndPoint); } return true; } - -bool CLR_Messaging::Messaging_Query( WP_Message* msg ) +bool CLR_Messaging::Messaging_Query(WP_Message *msg) { NATIVE_PROFILE_CLR_MESSAGING(); - CLR_Messaging_Commands::Messaging_Query* cmd = (CLR_Messaging_Commands::Messaging_Query*)msg->m_payload; + CLR_Messaging_Commands::Messaging_Query *cmd = (CLR_Messaging_Commands::Messaging_Query *)msg->m_payload; CLR_Messaging_Commands::Messaging_Query::Reply res; - CLR_RT_HeapBlock_EndPoint* ep = CLR_RT_HeapBlock_EndPoint::FindEndPoint( cmd->m_addr.m_to ); + CLR_RT_HeapBlock_EndPoint *ep = CLR_RT_HeapBlock_EndPoint::FindEndPoint(cmd->m_addr.m_to); res.m_found = (ep != NULL); - res.m_addr = cmd->m_addr; + res.m_addr = cmd->m_addr; WP_ReplyToCommand(msg, true, false, &res, sizeof(res)); return true; } -bool CLR_Messaging::Messaging_Query__Reply( WP_Message* msg ) +bool CLR_Messaging::Messaging_Query__Reply(WP_Message *msg) { NATIVE_PROFILE_CLR_MESSAGING(); - - CLR_Messaging_Commands::Messaging_Query::Reply* cmd = (CLR_Messaging_Commands::Messaging_Query::Reply*)msg->m_payload; - - g_CLR_Messaging->AllocateAndQueueMessage( CLR_Messaging_Commands::c_Messaging_Query, 0, NULL, cmd->m_addr.m_from, cmd->m_addr, cmd->m_found ); - + + CLR_Messaging_Commands::Messaging_Query::Reply *cmd = + (CLR_Messaging_Commands::Messaging_Query::Reply *)msg->m_payload; + + g_CLR_Messaging->AllocateAndQueueMessage( + CLR_Messaging_Commands::c_Messaging_Query, + 0, + NULL, + cmd->m_addr.m_from, + cmd->m_addr, + cmd->m_found); + return true; } //--// -bool CLR_Messaging::Messaging_Send( WP_Message* msg ) +bool CLR_Messaging::Messaging_Send(WP_Message *msg) { NATIVE_PROFILE_CLR_MESSAGING(); - CLR_Messaging_Commands::Messaging_Send* cmd = (CLR_Messaging_Commands::Messaging_Send*)msg->m_payload; + CLR_Messaging_Commands::Messaging_Send *cmd = (CLR_Messaging_Commands::Messaging_Send *)msg->m_payload; CLR_Messaging_Commands::Messaging_Send::Reply res; - CLR_UINT32 len; - bool fRes; + CLR_UINT32 len; + bool fRes; len = msg->m_header.m_size - sizeof(cmd->m_addr); - - fRes = g_CLR_Messaging->AllocateAndQueueMessage( CLR_Messaging_Commands::c_Messaging_Send, len, cmd->m_data, cmd->m_addr.m_to, cmd->m_addr, false ); + + fRes = g_CLR_Messaging->AllocateAndQueueMessage( + CLR_Messaging_Commands::c_Messaging_Send, + len, + cmd->m_data, + cmd->m_addr.m_to, + cmd->m_addr, + false); res.m_found = true; - res.m_addr = cmd->m_addr; + res.m_addr = cmd->m_addr; - WP_ReplyToCommand( msg, fRes, false, &res, sizeof(res) ); + WP_ReplyToCommand(msg, fRes, false, &res, sizeof(res)); return true; } -bool CLR_Messaging::Messaging_Send__Reply( WP_Message* msg ) +bool CLR_Messaging::Messaging_Send__Reply(WP_Message *msg) { (void)msg; @@ -127,26 +147,32 @@ bool CLR_Messaging::Messaging_Send__Reply( WP_Message* msg ) //--// -bool CLR_Messaging::Messaging_Reply( WP_Message* msg ) +bool CLR_Messaging::Messaging_Reply(WP_Message *msg) { NATIVE_PROFILE_CLR_MESSAGING(); - CLR_Messaging_Commands::Messaging_Reply* cmd = (CLR_Messaging_Commands::Messaging_Reply*)msg->m_payload; + CLR_Messaging_Commands::Messaging_Reply *cmd = (CLR_Messaging_Commands::Messaging_Reply *)msg->m_payload; CLR_Messaging_Commands::Messaging_Reply::Reply res; - bool fRes; - CLR_UINT32 len; + bool fRes; + CLR_UINT32 len; len = msg->m_header.m_size - sizeof(cmd->m_addr); - fRes = g_CLR_Messaging->AllocateAndQueueMessage( CLR_Messaging_Commands::c_Messaging_Reply, len, cmd->m_data, cmd->m_addr.m_from, cmd->m_addr, false ); + fRes = g_CLR_Messaging->AllocateAndQueueMessage( + CLR_Messaging_Commands::c_Messaging_Reply, + len, + cmd->m_data, + cmd->m_addr.m_from, + cmd->m_addr, + false); res.m_found = true; - res.m_addr = cmd->m_addr; + res.m_addr = cmd->m_addr; - WP_ReplyToCommand( msg, fRes, false, &res, sizeof(res) ); + WP_ReplyToCommand(msg, fRes, false, &res, sizeof(res)); return true; } -bool CLR_Messaging::Messaging_Reply__Reply( WP_Message* msg ) +bool CLR_Messaging::Messaging_Reply__Reply(WP_Message *msg) { (void)msg; @@ -158,49 +184,47 @@ bool CLR_Messaging::Messaging_Reply__Reply( WP_Message* msg ) return true; } - //////////////////////////////////////////////////////////////////////////////////////////////////// - //--// -bool CLR_Messaging::App_ProcessHeader( void* state, WP_Message* msg ) +bool CLR_Messaging::App_ProcessHeader(void *state, WP_Message *msg) { NATIVE_PROFILE_CLR_MESSAGING(); - CLR_Messaging* pThis = (CLR_Messaging*)state; + CLR_Messaging *pThis = (CLR_Messaging *)state; Watchdog_Reset(); - if( !pThis->ProcessHeader( msg ) ) + if (!pThis->ProcessHeader(msg)) { TRACE0("ProcessHeader() indicated invalid header!\n"); return false; } - if(msg->m_header.m_size) + if (msg->m_header.m_size) { - void* ptr = CLR_RT_Memory::Allocate( msg->m_header.m_size, CLR_RT_HeapBlock::HB_CompactOnFailure ); + void *ptr = CLR_RT_Memory::Allocate(msg->m_header.m_size, CLR_RT_HeapBlock::HB_CompactOnFailure); - if(ptr == NULL) + if (ptr == NULL) { TRACE0("Failed to allocate 0x%08X bytes for message payload!\n"); return false; } - msg->m_payload = (unsigned char*)ptr; + msg->m_payload = (unsigned char *)ptr; } return true; } -bool CLR_Messaging::App_ProcessPayload( void* state, WP_Message* msg ) +bool CLR_Messaging::App_ProcessPayload(void *state, WP_Message *msg) { NATIVE_PROFILE_CLR_MESSAGING(); - CLR_Messaging* pThis = (CLR_Messaging*)state; + CLR_Messaging *pThis = (CLR_Messaging *)state; Watchdog_Reset(); - if(pThis->ProcessPayload( msg ) == false) + if (pThis->ProcessPayload(msg) == false) { return false; } @@ -208,14 +232,14 @@ bool CLR_Messaging::App_ProcessPayload( void* state, WP_Message* msg ) return true; } -bool CLR_Messaging::App_Release( void* state, WP_Message* msg ) +bool CLR_Messaging::App_Release(void *state, WP_Message *msg) { (void)state; NATIVE_PROFILE_CLR_MESSAGING(); - if(msg->m_payload != NULL) + if (msg->m_payload != NULL) { - CLR_RT_Memory::Release( msg->m_payload ); + CLR_RT_Memory::Release(msg->m_payload); msg->m_payload = NULL; } @@ -225,19 +249,6 @@ bool CLR_Messaging::App_Release( void* state, WP_Message* msg ) //--// - - - - - - - - - - - - - //////////////////////////////////////////////////////////////////////////////////////////////////// HRESULT CLR_Messaging::CreateInstance() @@ -245,16 +256,11 @@ HRESULT CLR_Messaging::CreateInstance() NATIVE_PROFILE_CLR_MESSAGING(); NANOCLR_HEADER(); - g_CLR_Messaging = (CLR_Messaging*)&g_scratchMessaging[ 0 ]; + g_CLR_Messaging = (CLR_Messaging *)&g_scratchMessaging[0]; + + CLR_RT_Memory::ZeroFill(g_CLR_Messaging, sizeof(CLR_Messaging)); - CLR_RT_Memory::ZeroFill( g_CLR_Messaging, sizeof(CLR_Messaging) ); - - g_CLR_Messaging->Initialize( - NULL, - 0, - NULL, - 0 - ); + g_CLR_Messaging->Initialize(NULL, 0, NULL, 0); NANOCLR_NOCLEANUP_NOLABEL(); } @@ -262,32 +268,31 @@ HRESULT CLR_Messaging::CreateInstance() //--// void CLR_Messaging::Initialize( - const CLR_Messaging_CommandHandlerLookup* requestLookup, - const CLR_UINT32 requestLookupCount, - const CLR_Messaging_CommandHandlerLookup* replyLookup, - const CLR_UINT32 replyLookupCount - ) + const CLR_Messaging_CommandHandlerLookup *requestLookup, + const CLR_UINT32 requestLookupCount, + const CLR_Messaging_CommandHandlerLookup *replyLookup, + const CLR_UINT32 replyLookupCount) { - if(m_fInitialized) return; + if (m_fInitialized) + return; - m_Lookup_Requests[ 0 ].table = c_Messaging_Lookup_Request; - m_Lookup_Requests[ 0 ].size = ARRAYSIZE(c_Messaging_Lookup_Request); + m_Lookup_Requests[0].table = c_Messaging_Lookup_Request; + m_Lookup_Requests[0].size = ARRAYSIZE(c_Messaging_Lookup_Request); - m_Lookup_Replies[ 0 ].table = c_Messaging_Lookup_Reply; - m_Lookup_Replies[ 0 ].size = ARRAYSIZE(c_Messaging_Lookup_Reply); + m_Lookup_Replies[0].table = c_Messaging_Lookup_Reply; + m_Lookup_Replies[0].size = ARRAYSIZE(c_Messaging_Lookup_Reply); - m_port = HalSystemConfig.DebuggerPort; + m_port = HalSystemConfig.DebuggerPort; - m_Lookup_Requests[ 1 ].table = requestLookup; - m_Lookup_Requests[ 1 ].size = requestLookupCount; + m_Lookup_Requests[1].table = requestLookup; + m_Lookup_Requests[1].size = requestLookupCount; - m_Lookup_Replies[ 1 ].table = replyLookup; - m_Lookup_Replies[ 1 ].size = replyLookupCount; + m_Lookup_Replies[1].table = replyLookup; + m_Lookup_Replies[1].size = replyLookupCount; - m_fDebuggerInitialized = (DebuggerPort_Initialize( HalSystemConfig.DebuggerPort ) != false); + m_fDebuggerInitialized = (DebuggerPort_Initialize(HalSystemConfig.DebuggerPort) != false); m_fInitialized = true; - } HRESULT CLR_Messaging::DeleteInstance() @@ -304,15 +309,16 @@ void CLR_Messaging::Cleanup() { NATIVE_PROFILE_CLR_MESSAGING(); - if(!m_fInitialized) return; + if (!m_fInitialized) + return; // Some devices cannot reset the USB controller so we need to allow them to skip uninitialization // of the debug transport - if(!g_fDoNotUninitializeDebuggerPort) + if (!g_fDoNotUninitializeDebuggerPort) { - DebuggerPort_Uninitialize( m_port ); + DebuggerPort_Uninitialize(m_port); } - + m_fDebuggerInitialized = false; m_fInitialized = false; @@ -320,28 +326,19 @@ void CLR_Messaging::Cleanup() //--// - - - - - - - - - -bool CLR_Messaging::ProcessHeader( WP_Message* msg ) +bool CLR_Messaging::ProcessHeader(WP_Message *msg) { (void)msg; NATIVE_PROFILE_CLR_MESSAGING(); - TRACE("MSG: 0x%08X\n", msg->m_header.m_cmd ); + TRACE("MSG: 0x%08X\n", msg->m_header.m_cmd); return true; } -bool CLR_Messaging::ProcessPayload( WP_Message* msg ) +bool CLR_Messaging::ProcessPayload(WP_Message *msg) { NATIVE_PROFILE_CLR_MESSAGING(); - if(msg->m_header.m_flags & WP_Flags_c_NACK) + if (msg->m_header.m_flags & WP_Flags_c_NACK) { // // Bad packet... @@ -351,30 +348,30 @@ bool CLR_Messaging::ProcessPayload( WP_Message* msg ) //--// - const CLR_Messaging_CommandHandlerLookups* tables; + const CLR_Messaging_CommandHandlerLookups *tables; int tableCount = 0; - if(msg->m_header.m_flags & WP_Flags_c_Reply) + if (msg->m_header.m_flags & WP_Flags_c_Reply) { - tables = m_Lookup_Replies; + tables = m_Lookup_Replies; tableCount = ARRAYSIZE(m_Lookup_Replies); } else { - tables = m_Lookup_Requests; + tables = m_Lookup_Requests; tableCount = ARRAYSIZE(m_Lookup_Requests); } - while(tableCount-- > 0) + while (tableCount-- > 0) { - size_t num = tables->size; - const CLR_Messaging_CommandHandlerLookup* cmd = tables->table; + size_t num = tables->size; + const CLR_Messaging_CommandHandlerLookup *cmd = tables->table; - while(num-- > 0 && cmd != NULL) + while (num-- > 0 && cmd != NULL) { - if(cmd->cmd == msg->m_header.m_cmd) + if (cmd->cmd == msg->m_header.m_cmd) { - WP_ReplyToCommand(msg, (*(cmd->hnd))( msg ), false, NULL, 0); + WP_ReplyToCommand(msg, (*(cmd->hnd))(msg), false, NULL, 0); return true; } @@ -384,25 +381,25 @@ bool CLR_Messaging::ProcessPayload( WP_Message* msg ) } WP_ReplyToCommand(msg, false, false, NULL, 0); - + return true; } // wrapper function for CLR_Messaging::ProcessPayload( -extern "C" int CLR_Messaging_ProcessPayload(WP_Message* msg) +extern "C" int CLR_Messaging_ProcessPayload(WP_Message *msg) { if (g_CLR_DBG_Debugger == NULL) { return false; } - + bool retValue = g_CLR_DBG_Debugger->m_messaging->ProcessPayload(msg); return retValue; } //--// -bool CLR_Messaging::SendEvent( unsigned int cmd, unsigned int payloadSize, unsigned char* payload, unsigned int flags ) +bool CLR_Messaging::SendEvent(unsigned int cmd, unsigned int payloadSize, unsigned char *payload, unsigned int flags) { NATIVE_PROFILE_CLR_MESSAGING(); WP_PrepareAndSendProtocolMessage(cmd, payloadSize, payload, flags); @@ -412,7 +409,11 @@ bool CLR_Messaging::SendEvent( unsigned int cmd, unsigned int payloadSize, unsig return true; } -void CLR_Messaging::BroadcastEvent( unsigned int cmd, unsigned int payloadSize, unsigned char* payload, unsigned int flags ) +void CLR_Messaging::BroadcastEvent( + unsigned int cmd, + unsigned int payloadSize, + unsigned char *payload, + unsigned int flags) { NATIVE_PROFILE_CLR_MESSAGING(); WP_PrepareAndSendProtocolMessage(cmd, payloadSize, payload, flags); diff --git a/src/CLR/Messaging/Messaging_stub.cpp b/src/CLR/Messaging/Messaging_stub.cpp index 3d93cbfecc..cd50d16daa 100644 --- a/src/CLR/Messaging/Messaging_stub.cpp +++ b/src/CLR/Messaging/Messaging_stub.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Startup/CLRStartup.cpp b/src/CLR/Startup/CLRStartup.cpp index 797cc7c055..25059510ee 100644 --- a/src/CLR/Startup/CLRStartup.cpp +++ b/src/CLR/Startup/CLRStartup.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/Startup/CLRStartup.h b/src/CLR/Startup/CLRStartup.h index 68b0212c0c..b1234aa0d8 100644 --- a/src/CLR/Startup/CLRStartup.h +++ b/src/CLR/Startup/CLRStartup.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/System.Math/nf_native_system_math.cpp b/src/CLR/System.Math/nf_native_system_math.cpp index 41e89df4b9..65fdaefda6 100644 --- a/src/CLR/System.Math/nf_native_system_math.cpp +++ b/src/CLR/System.Math/nf_native_system_math.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/System.Math/nf_native_system_math.h b/src/CLR/System.Math/nf_native_system_math.h index 9d91affad7..62e2bde80e 100644 --- a/src/CLR/System.Math/nf_native_system_math.h +++ b/src/CLR/System.Math/nf_native_system_math.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/System.Math/nf_native_system_math_System_Math.cpp b/src/CLR/System.Math/nf_native_system_math_System_Math.cpp index 7b42b1138e..477466124f 100644 --- a/src/CLR/System.Math/nf_native_system_math_System_Math.cpp +++ b/src/CLR/System.Math/nf_native_system_math_System_Math.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/WireProtocol/WireProtocol_App_Interface.c b/src/CLR/WireProtocol/WireProtocol_App_Interface.c index 00f04a07fa..5aa234bef8 100644 --- a/src/CLR/WireProtocol/WireProtocol_App_Interface.c +++ b/src/CLR/WireProtocol/WireProtocol_App_Interface.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/WireProtocol/WireProtocol_HAL_Interface.c b/src/CLR/WireProtocol/WireProtocol_HAL_Interface.c index f27f003511..d9f38b4230 100644 --- a/src/CLR/WireProtocol/WireProtocol_HAL_Interface.c +++ b/src/CLR/WireProtocol/WireProtocol_HAL_Interface.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/WireProtocol/WireProtocol_Message.c b/src/CLR/WireProtocol/WireProtocol_Message.c index c874d0a085..ae9771e5f4 100644 --- a/src/CLR/WireProtocol/WireProtocol_Message.c +++ b/src/CLR/WireProtocol/WireProtocol_Message.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/WireProtocol/WireProtocol_MonitorCommands.c b/src/CLR/WireProtocol/WireProtocol_MonitorCommands.c index 040c554aa9..2516f76666 100644 --- a/src/CLR/WireProtocol/WireProtocol_MonitorCommands.c +++ b/src/CLR/WireProtocol/WireProtocol_MonitorCommands.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/src/CLR/WireProtocol/targetHAL_time.cpp b/src/CLR/WireProtocol/targetHAL_time.cpp index d3c5a5ac5e..6b9dbbc51e 100644 --- a/src/CLR/WireProtocol/targetHAL_time.cpp +++ b/src/CLR/WireProtocol/targetHAL_time.cpp @@ -1,6 +1,6 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/DeviceInterfaces/Networking.Sntp/nf_lwipopts_sntp.h b/src/DeviceInterfaces/Networking.Sntp/nf_lwipopts_sntp.h index 55d0603c54..3a5bcdca8c 100644 --- a/src/DeviceInterfaces/Networking.Sntp/nf_lwipopts_sntp.h +++ b/src/DeviceInterfaces/Networking.Sntp/nf_lwipopts_sntp.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/src/DeviceInterfaces/Networking.Sntp/nf_networking_sntp.cpp b/src/DeviceInterfaces/Networking.Sntp/nf_networking_sntp.cpp index 04f8d3906a..8708c3b09c 100644 --- a/src/DeviceInterfaces/Networking.Sntp/nf_networking_sntp.cpp +++ b/src/DeviceInterfaces/Networking.Sntp/nf_networking_sntp.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/src/DeviceInterfaces/Networking.Sntp/nf_networking_sntp.h b/src/DeviceInterfaces/Networking.Sntp/nf_networking_sntp.h index 833eaabbb2..aace88632e 100644 --- a/src/DeviceInterfaces/Networking.Sntp/nf_networking_sntp.h +++ b/src/DeviceInterfaces/Networking.Sntp/nf_networking_sntp.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/DeviceInterfaces/Networking.Sntp/nf_networking_sntp_nanoFramework_Networking_Sntp.cpp b/src/DeviceInterfaces/Networking.Sntp/nf_networking_sntp_nanoFramework_Networking_Sntp.cpp index 4064338f56..47f6018968 100644 --- a/src/DeviceInterfaces/Networking.Sntp/nf_networking_sntp_nanoFramework_Networking_Sntp.cpp +++ b/src/DeviceInterfaces/Networking.Sntp/nf_networking_sntp_nanoFramework_Networking_Sntp.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/src/DeviceInterfaces/System.Net/sys_net_native.cpp b/src/DeviceInterfaces/System.Net/sys_net_native.cpp index ef30d9355d..46f1c2af8f 100644 --- a/src/DeviceInterfaces/System.Net/sys_net_native.cpp +++ b/src/DeviceInterfaces/System.Net/sys_net_native.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/DeviceInterfaces/System.Net/sys_net_native.h b/src/DeviceInterfaces/System.Net/sys_net_native.h index 573a49065e..7b412d0bda 100644 --- a/src/DeviceInterfaces/System.Net/sys_net_native.h +++ b/src/DeviceInterfaces/System.Net/sys_net_native.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/DeviceInterfaces/System.Net/sys_net_native_System_Net_NetworkInformation_NetworkInterface.cpp b/src/DeviceInterfaces/System.Net/sys_net_native_System_Net_NetworkInformation_NetworkInterface.cpp index f77c568927..e8f84328dc 100644 --- a/src/DeviceInterfaces/System.Net/sys_net_native_System_Net_NetworkInformation_NetworkInterface.cpp +++ b/src/DeviceInterfaces/System.Net/sys_net_native_System_Net_NetworkInformation_NetworkInterface.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/DeviceInterfaces/System.Net/sys_net_native_System_Net_NetworkInformation_Wireless80211Configuration.cpp b/src/DeviceInterfaces/System.Net/sys_net_native_System_Net_NetworkInformation_Wireless80211Configuration.cpp index a7690b2863..4f0367d8fe 100644 --- a/src/DeviceInterfaces/System.Net/sys_net_native_System_Net_NetworkInformation_Wireless80211Configuration.cpp +++ b/src/DeviceInterfaces/System.Net/sys_net_native_System_Net_NetworkInformation_Wireless80211Configuration.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/DeviceInterfaces/System.Net/sys_net_native_System_Net_NetworkInformation_WirelessAPConfiguration.cpp b/src/DeviceInterfaces/System.Net/sys_net_native_System_Net_NetworkInformation_WirelessAPConfiguration.cpp index 4f2ea18828..972c2c9cdf 100644 --- a/src/DeviceInterfaces/System.Net/sys_net_native_System_Net_NetworkInformation_WirelessAPConfiguration.cpp +++ b/src/DeviceInterfaces/System.Net/sys_net_native_System_Net_NetworkInformation_WirelessAPConfiguration.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/DeviceInterfaces/System.Net/sys_net_native_System_Net_Security_CertificateManager.cpp b/src/DeviceInterfaces/System.Net/sys_net_native_System_Net_Security_CertificateManager.cpp index a8c6b9b244..7838ca6dc8 100644 --- a/src/DeviceInterfaces/System.Net/sys_net_native_System_Net_Security_CertificateManager.cpp +++ b/src/DeviceInterfaces/System.Net/sys_net_native_System_Net_Security_CertificateManager.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/DeviceInterfaces/System.Net/sys_net_native_System_Net_Security_SslNative.cpp b/src/DeviceInterfaces/System.Net/sys_net_native_System_Net_Security_SslNative.cpp index d6ce05bc08..7d3caf87f3 100644 --- a/src/DeviceInterfaces/System.Net/sys_net_native_System_Net_Security_SslNative.cpp +++ b/src/DeviceInterfaces/System.Net/sys_net_native_System_Net_Security_SslNative.cpp @@ -1,13 +1,11 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // - #include "sys_net_native.h" - struct SSL_SeedConfig { HAL_DRIVER_CONFIG_HEADER Header; @@ -15,28 +13,32 @@ struct SSL_SeedConfig //--// uint64_t SeedCounter; - uint8_t SslSeedKey[ 260 ]; + uint8_t SslSeedKey[260]; //--// - static const char * GetDriverName() { return "SSL_SEED_KEY"; } + static const char *GetDriverName() + { + return "SSL_SEED_KEY"; + } }; struct SSL_SeedDriver { - SSL_SeedConfig Config; - - bool Initialized; - HAL_COMPLETION m_completion; + SSL_SeedConfig Config; + + bool Initialized; + HAL_COMPLETION m_completion; }; static SSL_SeedDriver g_SSL_SeedData; // TODO - save seed value -static void UpdateSslSeedValue(void* arg) +static void UpdateSslSeedValue(void *arg) { (void)arg; - // if(!HAL_CONFIG_BLOCK::UpdateBlockWithName( g_SSL_SeedData.Config.GetDriverName(), &g_SSL_SeedData.Config, sizeof(g_SSL_SeedData.Config), TRUE )) + // if(!HAL_CONFIG_BLOCK::UpdateBlockWithName( g_SSL_SeedData.Config.GetDriverName(), &g_SSL_SeedData.Config, + // sizeof(g_SSL_SeedData.Config), TRUE )) // { // ASSERT(FALSE); // CPU_Reset(); @@ -44,91 +46,98 @@ static void UpdateSslSeedValue(void* arg) } // TODO generate ramdom seed for encryption -// Maybe move this to specicfic provider files +// Maybe move this to specicfic provider files static void GenerateNewSslSeed() { -// uint8_t signature[ 128 ]; -// uint8_t IVPtr[ BLOCK_SIZE ]; -// bool success; + // uint8_t signature[ 128 ]; + // uint8_t IVPtr[ BLOCK_SIZE ]; + // bool success; -// uint64_t data[ 2 ] = { ++g_SSL_SeedData.Config.SeedCounter, HAL_Time_CurrentTicks() }; + // uint64_t data[ 2 ] = { ++g_SSL_SeedData.Config.SeedCounter, HAL_Time_CurrentTicks() }; -// memset( &IVPtr[ 0 ], 0, sizeof(IVPtr) ); + // memset( &IVPtr[ 0 ], 0, sizeof(IVPtr) ); -// // Encrypts a buffer using a symmetric algorithm. -// // BOOL Crypto_Encrypt(BYTE *Key, BYTE *IV, DWORD cbIVSize, BYTE* pPlainText, DWORD cbPlainText, BYTE *pCypherText, DWORD cbCypherText); -// //success = Crypto_Encrypt( (BYTE*)&g_SSL_SeedData.Config.SslSeedKey[ 0 ], (uint8_t*)IVPtr, sizeof(IVPtr), (uint8_t*)&data, sizeof(data), signature, sizeof(signature) ) == CRYPTO_SUCCESS ? S_OK : CLR_E_FAIL; + // // Encrypts a buffer using a symmetric algorithm. + // // BOOL Crypto_Encrypt(BYTE *Key, BYTE *IV, DWORD cbIVSize, BYTE* pPlainText, DWORD cbPlainText, BYTE + // *pCypherText, DWORD cbCypherText); + // //success = Crypto_Encrypt( (BYTE*)&g_SSL_SeedData.Config.SslSeedKey[ 0 ], (uint8_t*)IVPtr, sizeof(IVPtr), + // (uint8_t*)&data, sizeof(data), signature, sizeof(signature) ) == CRYPTO_SUCCESS ? S_OK : CLR_E_FAIL; -// // ASSERT(success); + // // ASSERT(success); -// ssl_rand_seed(signature, sizeof(signature)); + // ssl_rand_seed(signature, sizeof(signature)); -// if(!g_SSL_SeedData.m_completion.IsLinked()) -// { -// g_SSL_SeedData.m_completion.EnqueueDelta( 5 * 1000000ul ); // 5 seconds -// } + // if(!g_SSL_SeedData.m_completion.IsLinked()) + // { + // g_SSL_SeedData.m_completion.EnqueueDelta( 5 * 1000000ul ); // 5 seconds + // } } //--// -void Time_GetDateTime(DATE_TIME_INFO* dt) +void Time_GetDateTime(DATE_TIME_INFO *dt) { NATIVE_PROFILE_CLR_NETWORK(); SYSTEMTIME st; - HAL_Time_ToSystemTime( HAL_Time_CurrentTime(), &st ); - -// TODO check if offset needed for security date time, maybe needed to certificate validation -// dt->tzOffset = Time_GetTimeZoneOffset() * 60; + HAL_Time_ToSystemTime(HAL_Time_CurrentTime(), &st); + + // TODO check if offset needed for security date time, maybe needed to certificate validation + // dt->tzOffset = Time_GetTimeZoneOffset() * 60; dt->tzOffset = 0; - - dt->year = st.wYear; - dt->month = st.wMonth; - dt->day = st.wDay; - dt->hour = st.wHour; + + dt->year = st.wYear; + dt->month = st.wMonth; + dt->day = st.wDay; + dt->hour = st.wHour; dt->minute = st.wMinute; dt->second = st.wSecond; - dt->msec = st.wMilliseconds; + dt->msec = st.wMilliseconds; - dt->dlsTime = 0; - } + dt->dlsTime = 0; +} // Initalise SSL as a server -HRESULT Library_sys_net_native_System_Net_Security_SslNative::SecureServerInit___STATIC__I4__I4__I4__SystemSecurityCryptographyX509CertificatesX509Certificate__SystemSecurityCryptographyX509CertificatesX509Certificate( CLR_RT_StackFrame& stack ) +HRESULT Library_sys_net_native_System_Net_Security_SslNative:: + SecureServerInit___STATIC__I4__I4__I4__SystemSecurityCryptographyX509CertificatesX509Certificate__SystemSecurityCryptographyX509CertificatesX509Certificate( + CLR_RT_StackFrame &stack) { NATIVE_PROFILE_CLR_NETWORK(); - return InitHelper( stack, true ); + return InitHelper(stack, true); } // Initalise SSL as a client -HRESULT Library_sys_net_native_System_Net_Security_SslNative::SecureClientInit___STATIC__I4__I4__I4__SystemSecurityCryptographyX509CertificatesX509Certificate__SystemSecurityCryptographyX509CertificatesX509Certificate( CLR_RT_StackFrame& stack ) +HRESULT Library_sys_net_native_System_Net_Security_SslNative:: + SecureClientInit___STATIC__I4__I4__I4__SystemSecurityCryptographyX509CertificatesX509Certificate__SystemSecurityCryptographyX509CertificatesX509Certificate( + CLR_RT_StackFrame &stack) { NATIVE_PROFILE_CLR_NETWORK(); - return InitHelper( stack, false ); + return InitHelper(stack, false); } // -// Server - socket connected now accept connection by doing the server SSL handshake +// Server - socket connected now accept connection by doing the server SSL handshake // -HRESULT Library_sys_net_native_System_Net_Security_SslNative::SecureAccept___STATIC__VOID__I4__OBJECT( CLR_RT_StackFrame& stack ) +HRESULT Library_sys_net_native_System_Net_Security_SslNative::SecureAccept___STATIC__VOID__I4__OBJECT( + CLR_RT_StackFrame &stack) { NATIVE_PROFILE_CLR_NETWORK(); NANOCLR_HEADER(); - CLR_INT32 sslContext = stack.Arg0().NumericByRef().s4; - CLR_RT_HeapBlock* socket = stack.Arg1().Dereference(); - CLR_INT32 timeout_ms = -1; // wait forever - CLR_RT_HeapBlock hbTimeout; + CLR_INT32 sslContext = stack.Arg0().NumericByRef().s4; + CLR_RT_HeapBlock *socket = stack.Arg1().Dereference(); + CLR_INT32 timeout_ms = -1; // wait forever + CLR_RT_HeapBlock hbTimeout; - int result = 0; - CLR_INT32 handle; - bool fRes = true; + int result = 0; + CLR_INT32 handle; + bool fRes = true; CLR_INT64 *timeout; FAULT_ON_NULL(socket); - handle = socket[ Library_sys_net_native_System_Net_Sockets_NativeSocket::FIELD__m_Handle ].NumericByRef().s4; + handle = socket[Library_sys_net_native_System_Net_Sockets_NativeSocket::FIELD__m_Handle].NumericByRef().s4; /* Because we could have been a rescheduled call due to a prior call that would have blocked, we need to see * if our handle has been shutdown before continuing. */ @@ -139,20 +148,20 @@ HRESULT Library_sys_net_native_System_Net_Security_SslNative::SecureAccept___STA } // !! need to cast to CLR_INT64 otherwise it wont setup a proper timeout infinite - hbTimeout.SetInteger( (CLR_INT64)timeout_ms * TIME_CONVERSION__TO_MILLISECONDS ); - - NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks( hbTimeout, timeout )); + hbTimeout.SetInteger((CLR_INT64)timeout_ms * TIME_CONVERSION__TO_MILLISECONDS); + NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks(hbTimeout, timeout)); // first make sure we have data to read or ability to write - while(true) + while (true) { - result = SSL_Accept( handle, sslContext ); + result = SSL_Accept(handle, sslContext); - if(result == SOCK_EWOULDBLOCK || result == SOCK_TRY_AGAIN) + if (result == SOCK_EWOULDBLOCK || result == SOCK_TRY_AGAIN) { // non-blocking - allow other threads to run while we wait for socket activity - NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.WaitEvents( stack.m_owningThread, *timeout, CLR_RT_ExecutionEngine::c_Event_Socket, fRes )); + NANOCLR_CHECK_HRESULT( + g_CLR_RT_ExecutionEngine.WaitEvents(stack.m_owningThread, *timeout, Event_Socket, fRes)); } else { @@ -160,9 +169,9 @@ HRESULT Library_sys_net_native_System_Net_Security_SslNative::SecureAccept___STA } } - stack.PopValue(); // Timeout + stack.PopValue(); // Timeout - NANOCLR_CHECK_HRESULT(ThrowOnError( stack, result )); + NANOCLR_CHECK_HRESULT(ThrowOnError(stack, result)); NANOCLR_NOCLEANUP(); } @@ -170,31 +179,32 @@ HRESULT Library_sys_net_native_System_Net_Security_SslNative::SecureAccept___STA // // Client - Natve socket connected, now do client side SSL handshake // -HRESULT Library_sys_net_native_System_Net_Security_SslNative::SecureConnect___STATIC__VOID__I4__STRING__OBJECT( CLR_RT_StackFrame& stack ) +HRESULT Library_sys_net_native_System_Net_Security_SslNative::SecureConnect___STATIC__VOID__I4__STRING__OBJECT( + CLR_RT_StackFrame &stack) { NATIVE_PROFILE_CLR_NETWORK(); NANOCLR_HEADER(); - CLR_INT32 sslContext = stack.Arg0().NumericByRef().s4; - CLR_RT_HeapBlock* hb = stack.Arg1().DereferenceString(); - CLR_RT_HeapBlock* socket = stack.Arg2().Dereference(); - CLR_RT_HeapBlock hbTimeout; - - int result; - const char * szName; - CLR_INT32 handle; - bool fRes = true; - CLR_INT64 * timeout; + CLR_INT32 sslContext = stack.Arg0().NumericByRef().s4; + CLR_RT_HeapBlock *hb = stack.Arg1().DereferenceString(); + CLR_RT_HeapBlock *socket = stack.Arg2().Dereference(); + CLR_RT_HeapBlock hbTimeout; + + int result; + const char *szName; + CLR_INT32 handle; + bool fRes = true; + CLR_INT64 *timeout; FAULT_ON_NULL(socket); - handle = socket[ Library_sys_net_native_System_Net_Sockets_NativeSocket::FIELD__m_Handle ].NumericByRef().s4; + handle = socket[Library_sys_net_native_System_Net_Sockets_NativeSocket::FIELD__m_Handle].NumericByRef().s4; /* Because we could have been a rescheduled call due to a prior call that would have blocked, we need to see * if our handle has been shutdown before continuing. */ if (handle == Library_sys_net_native_System_Net_Sockets_NativeSocket::DISPOSED_HANDLE) { - ThrowError( stack, CLR_E_OBJECT_DISPOSED ); + ThrowError(stack, CLR_E_OBJECT_DISPOSED); NANOCLR_SET_AND_LEAVE(CLR_E_PROCESS_EXCEPTION); } @@ -204,20 +214,22 @@ HRESULT Library_sys_net_native_System_Net_Security_SslNative::SecureConnect___ST // Infinite Timeout // !! need to cast to CLR_INT64 otherwise it wont setup a proper timeout infinite - hbTimeout.SetInteger( (CLR_INT64)-1 ); - - NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks( hbTimeout, timeout )); + hbTimeout.SetInteger((CLR_INT64)-1); - while(true) + NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks(hbTimeout, timeout)); + + while (true) { - result = SSL_Connect( handle, szName, sslContext ); + result = SSL_Connect(handle, szName, sslContext); - if(result == SOCK_EWOULDBLOCK || result == SOCK_TRY_AGAIN) + if (result == SOCK_EWOULDBLOCK || result == SOCK_TRY_AGAIN) { // non-blocking - allow other threads to run while we wait for socket activity - NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.WaitEvents( stack.m_owningThread, *timeout, CLR_RT_ExecutionEngine::c_Event_Socket, fRes )); + NANOCLR_CHECK_HRESULT( + g_CLR_RT_ExecutionEngine.WaitEvents(stack.m_owningThread, *timeout, Event_Socket, fRes)); - if(result < 0) break; + if (result < 0) + break; } else { @@ -225,26 +237,29 @@ HRESULT Library_sys_net_native_System_Net_Security_SslNative::SecureConnect___ST } } - stack.PopValue(); // Timeout + stack.PopValue(); // Timeout - NANOCLR_CHECK_HRESULT(ThrowOnError( stack, result )); + NANOCLR_CHECK_HRESULT(ThrowOnError(stack, result)); NANOCLR_NOCLEANUP(); } -HRESULT Library_sys_net_native_System_Net_Security_SslNative::SecureRead___STATIC__I4__OBJECT__SZARRAY_U1__I4__I4__I4( CLR_RT_StackFrame& stack ) +HRESULT Library_sys_net_native_System_Net_Security_SslNative::SecureRead___STATIC__I4__OBJECT__SZARRAY_U1__I4__I4__I4( + CLR_RT_StackFrame &stack) { NATIVE_PROFILE_CLR_NETWORK(); - return ReadWriteHelper( stack, false ); + return ReadWriteHelper(stack, false); } -HRESULT Library_sys_net_native_System_Net_Security_SslNative::SecureWrite___STATIC__I4__OBJECT__SZARRAY_U1__I4__I4__I4( CLR_RT_StackFrame& stack ) +HRESULT Library_sys_net_native_System_Net_Security_SslNative::SecureWrite___STATIC__I4__OBJECT__SZARRAY_U1__I4__I4__I4( + CLR_RT_StackFrame &stack) { NATIVE_PROFILE_CLR_NETWORK(); - return ReadWriteHelper( stack, true ); + return ReadWriteHelper(stack, true); } -HRESULT Library_sys_net_native_System_Net_Security_SslNative::SecureCloseSocket___STATIC__I4__OBJECT( CLR_RT_StackFrame& stack ) +HRESULT Library_sys_net_native_System_Net_Security_SslNative::SecureCloseSocket___STATIC__I4__OBJECT( + CLR_RT_StackFrame &stack) { NATIVE_PROFILE_CLR_NETWORK(); NANOCLR_HEADER(); @@ -252,327 +267,379 @@ HRESULT Library_sys_net_native_System_Net_Security_SslNative::SecureCloseSocket_ int result; CLR_INT32 handle; - CLR_RT_HeapBlock* socket = stack.Arg0().Dereference(); FAULT_ON_NULL(socket); + CLR_RT_HeapBlock *socket = stack.Arg0().Dereference(); + FAULT_ON_NULL(socket); - handle = socket[ Library_sys_net_native_System_Net_Sockets_NativeSocket::FIELD__m_Handle ].NumericByRef().s4; + handle = socket[Library_sys_net_native_System_Net_Sockets_NativeSocket::FIELD__m_Handle].NumericByRef().s4; - result = SSL_CloseSocket( handle ); + result = SSL_CloseSocket(handle); - stack.SetResult_I4( result ); + stack.SetResult_I4(result); NANOCLR_NOCLEANUP(); } -HRESULT Library_sys_net_native_System_Net_Security_SslNative::ExitSecureContext___STATIC__I4__I4( CLR_RT_StackFrame& stack ) +HRESULT Library_sys_net_native_System_Net_Security_SslNative::ExitSecureContext___STATIC__I4__I4( + CLR_RT_StackFrame &stack) { NATIVE_PROFILE_CLR_NETWORK(); NANOCLR_HEADER(); CLR_INT32 sslContext = stack.Arg0().NumericByRef().s4; - int result = SSL_ExitContext( sslContext ) == TRUE ? 0 : -1; + int result = SSL_ExitContext(sslContext) == TRUE ? 0 : -1; - stack.SetResult_I4( result ); + stack.SetResult_I4(result); NANOCLR_NOCLEANUP_NOLABEL(); } -HRESULT Library_sys_net_native_System_Net_Security_SslNative::DataAvailable___STATIC__I4__OBJECT( CLR_RT_StackFrame& stack ) +HRESULT Library_sys_net_native_System_Net_Security_SslNative::DataAvailable___STATIC__I4__OBJECT( + CLR_RT_StackFrame &stack) { NATIVE_PROFILE_CLR_NETWORK(); NANOCLR_HEADER(); - CLR_RT_HeapBlock* socket = stack.Arg0().Dereference(); - int result; + CLR_RT_HeapBlock *socket = stack.Arg0().Dereference(); + int result; CLR_INT32 handle; FAULT_ON_NULL(socket); - handle = socket[ Library_sys_net_native_System_Net_Sockets_NativeSocket::FIELD__m_Handle ].NumericByRef().s4; + handle = socket[Library_sys_net_native_System_Net_Sockets_NativeSocket::FIELD__m_Handle].NumericByRef().s4; - result = SSL_DataAvailable( handle ); + result = SSL_DataAvailable(handle); // ThrowOnError expects anything other than 0 to be a failure - so return 0 if we don't have an error - NANOCLR_CHECK_HRESULT(ThrowOnError( stack, result >= 0 ? 0 : result )); + NANOCLR_CHECK_HRESULT(ThrowOnError(stack, result >= 0 ? 0 : result)); - stack.SetResult_I4( result ); + stack.SetResult_I4(result); NANOCLR_NOCLEANUP(); } -HRESULT Library_sys_net_native_System_Net_Security_SslNative::ReadWriteHelper( CLR_RT_StackFrame& stack, bool isWrite ) +HRESULT Library_sys_net_native_System_Net_Security_SslNative::ReadWriteHelper(CLR_RT_StackFrame &stack, bool isWrite) { NATIVE_PROFILE_CLR_NETWORK(); NANOCLR_HEADER(); - CLR_RT_HeapBlock* socket = stack.Arg0().Dereference(); - CLR_RT_HeapBlock_Array* arrData = stack.Arg1().DereferenceArray(); - CLR_INT32 offset = stack.Arg2().NumericByRef().s4; - CLR_INT32 count = stack.Arg3().NumericByRef().s4; - CLR_INT32 timeout_ms = stack.Arg4().NumericByRef().s4; - CLR_UINT8* buffer; - CLR_RT_HeapBlock hbTimeout; + CLR_RT_HeapBlock *socket = stack.Arg0().Dereference(); + CLR_RT_HeapBlock_Array *arrData = stack.Arg1().DereferenceArray(); + CLR_INT32 offset = stack.Arg2().NumericByRef().s4; + CLR_INT32 count = stack.Arg3().NumericByRef().s4; + CLR_INT32 timeout_ms = stack.Arg4().NumericByRef().s4; + CLR_UINT8 *buffer; + CLR_RT_HeapBlock hbTimeout; - CLR_INT32 totReadWrite; - bool fRes = true; + CLR_INT32 totReadWrite; + bool fRes = true; CLR_INT64 *timeout; - int result = 0; + int result = 0; CLR_INT32 handle; - if(count == 0) + if (count == 0) { - stack.SetResult_I4( 0 ); + stack.SetResult_I4(0); NANOCLR_SET_AND_LEAVE(S_OK); } FAULT_ON_NULL(socket); - handle = socket[ Library_sys_net_native_System_Net_Sockets_NativeSocket::FIELD__m_Handle ].NumericByRef().s4; + handle = socket[Library_sys_net_native_System_Net_Sockets_NativeSocket::FIELD__m_Handle].NumericByRef().s4; // Check not Disposed if (handle == Library_sys_net_native_System_Net_Sockets_NativeSocket::DISPOSED_HANDLE) { - ThrowError( stack, CLR_E_OBJECT_DISPOSED ); + ThrowError(stack, CLR_E_OBJECT_DISPOSED); NANOCLR_SET_AND_LEAVE(CLR_E_PROCESS_EXCEPTION); } FAULT_ON_NULL(arrData); // !! need to cast to CLR_INT64 otherwise it wont setup a proper timeout infinite - hbTimeout.SetInteger( (CLR_INT64)timeout_ms * TIME_CONVERSION__TO_MILLISECONDS ); - - NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks( hbTimeout, timeout )); + hbTimeout.SetInteger((CLR_INT64)timeout_ms * TIME_CONVERSION__TO_MILLISECONDS); + + NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks(hbTimeout, timeout)); // // Push "totReadWrite" onto the eval stack. // - if(stack.m_customState == 1) + if (stack.m_customState == 1) { - stack.PushValueI4( 0 ); + stack.PushValueI4(0); stack.m_customState = 2; } - totReadWrite = stack.m_evalStack[ 1 ].NumericByRef().s4; + totReadWrite = stack.m_evalStack[1].NumericByRef().s4; - buffer = arrData->GetElement( offset + totReadWrite ); + buffer = arrData->GetElement(offset + totReadWrite); count -= totReadWrite; - if((offset + count + totReadWrite) > (int)arrData->m_numOfElements) NANOCLR_SET_AND_LEAVE(CLR_E_INDEX_OUT_OF_RANGE); + if ((offset + count + totReadWrite) > (int)arrData->m_numOfElements) + NANOCLR_SET_AND_LEAVE(CLR_E_INDEX_OUT_OF_RANGE); - while(count > 0) + while (count > 0) { // first make sure we have data to read or ability to write - while(fRes) + while (fRes) { - if(!isWrite) + if (!isWrite) { // check SSL_DataAvailable() in case SSL has already read and buffered socket data result = SSL_DataAvailable(handle); - if((result > 0) || ((result < 0) && (SOCK_getlasterror() != SOCK_EWOULDBLOCK))) + if ((result > 0) || ((result < 0) && (SOCK_getlasterror() != SOCK_EWOULDBLOCK))) { break; } } - result = Library_sys_net_native_System_Net_Sockets_NativeSocket::Helper__SelectSocket( handle, isWrite ? 1 : 0 ); + result = + Library_sys_net_native_System_Net_Sockets_NativeSocket::Helper__SelectSocket(handle, isWrite ? 1 : 0); - if((result > 0) || ((result < 0) && (SOCK_getlasterror() != SOCK_EWOULDBLOCK))) + if ((result > 0) || ((result < 0) && (SOCK_getlasterror() != SOCK_EWOULDBLOCK))) { break; } // non-blocking - allow other threads to run while we wait for socket activity - NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.WaitEvents( stack.m_owningThread, *timeout, CLR_RT_ExecutionEngine::c_Event_Socket, fRes )); + NANOCLR_CHECK_HRESULT( + g_CLR_RT_ExecutionEngine.WaitEvents(stack.m_owningThread, *timeout, Event_Socket, fRes)); - // timeout expired - if(!fRes) + // timeout expired + if (!fRes) { result = SOCK_SOCKET_ERROR; - + ThrowError(stack, SOCK_ETIMEDOUT); - - NANOCLR_SET_AND_LEAVE( CLR_E_PROCESS_EXCEPTION ); + + NANOCLR_SET_AND_LEAVE(CLR_E_PROCESS_EXCEPTION); } } // socket is in the excepted state, so let's bail out - if(SOCK_SOCKET_ERROR == result) + if (SOCK_SOCKET_ERROR == result) { break; } - if(isWrite) + if (isWrite) { - result = SSL_Write( handle, (const char*)buffer, count ); + result = SSL_Write(handle, (const char *)buffer, count); } else { - result = SSL_Read( handle, (char*)buffer, count ); + result = SSL_Read(handle, (char *)buffer, count); - if(result == SSL_RESULT__WOULD_BLOCK) + if (result == SSL_RESULT__WOULD_BLOCK) { continue; } } // ThrowOnError expects anything other than 0 to be a failure - so return 0 if we don't have an error - if(result <= 0) + if (result <= 0) { break; } - buffer += result; + buffer += result; totReadWrite += result; - count -= result; - + count -= result; // read is non-blocking if we have any data - if(!isWrite && (totReadWrite > 0)) + if (!isWrite && (totReadWrite > 0)) { break; } - stack.m_evalStack[ 1 ].NumericByRef().s4 = totReadWrite; + stack.m_evalStack[1].NumericByRef().s4 = totReadWrite; } - stack.PopValue(); // totReadWrite - stack.PopValue(); // Timeout + stack.PopValue(); // totReadWrite + stack.PopValue(); // Timeout - if(result < 0) + if (result < 0) { - NANOCLR_CHECK_HRESULT(ThrowOnError( stack, result )); + NANOCLR_CHECK_HRESULT(ThrowOnError(stack, result)); } - stack.SetResult_I4( totReadWrite ); - + stack.SetResult_I4(totReadWrite); + NANOCLR_NOCLEANUP(); - } - -HRESULT Library_sys_net_native_System_Net_Security_SslNative::InitHelper( CLR_RT_StackFrame& stack, bool isServer ) +HRESULT Library_sys_net_native_System_Net_Security_SslNative::InitHelper(CLR_RT_StackFrame &stack, bool isServer) { NATIVE_PROFILE_CLR_NETWORK(); NANOCLR_HEADER(); - CLR_RT_TypeDef_Index x509Certificate2TypeDef; - - CLR_INT32 sslContext = -1; - CLR_INT32 sslMode = stack.Arg0().NumericByRef().s4; - CLR_INT32 sslVerify = stack.Arg1().NumericByRef().s4; - CLR_RT_HeapBlock *hbCert = stack.Arg2().Dereference(); - CLR_RT_HeapBlock* caCert = stack.Arg3().Dereference(); - CLR_RT_HeapBlock_Array* arrCert = NULL; - CLR_RT_HeapBlock_Array* privateKey = NULL; - CLR_UINT8* sslCert = NULL; - int result; - bool isFirstCall = false; - const char * password = ""; - uint8_t* pk = NULL; - - if(!g_SSL_SeedData.Initialized) + CLR_RT_TypeDef_Index x509Certificate2TypeDef; + + CLR_INT32 sslContext = -1; + CLR_INT32 sslMode = stack.Arg0().NumericByRef().s4; + CLR_INT32 sslVerify = stack.Arg1().NumericByRef().s4; + CLR_RT_HeapBlock *hbCert = stack.Arg2().Dereference(); + CLR_RT_HeapBlock *caCert = stack.Arg3().Dereference(); + CLR_RT_HeapBlock_Array *arrCert = NULL; + CLR_RT_HeapBlock_Array *privateKey = NULL; + CLR_UINT8 *sslCert = NULL; + int result; + bool isFirstCall = false; + const char *password = ""; + uint8_t *pk = NULL; + + if (!g_SSL_SeedData.Initialized) { -// bool fOK = FALSE; + // bool fOK = FALSE; isFirstCall = true; -// FIXME -// #if !defined(_WIN32) && !defined(WIN32) && !defined(_WIN32_WCE) -// int i; - -// // TODO save seed data -// // if(!HAL_CONFIG_BLOCK::ApplyConfig( g_SSL_SeedData.Config.GetDriverName(), &g_SSL_SeedData.Config, sizeof(g_SSL_SeedData.Config) )) -// // { -// // return CLR_E_NOT_SUPPORTED; -// // } - -// // validate the security key (make sure it isn't all 0x00 or all 0xFF -// for(i=1; iPin(); // there is a client certificate, find if it's a X509Certificate2 - if(hbCert->ObjectCls().Type() == x509Certificate2TypeDef.Type()) + if (hbCert->ObjectCls().Type() == x509Certificate2TypeDef.Type()) { - // get private key - privateKey = hbCert[ Library_sys_net_native_System_Security_Cryptography_X509Certificates_X509Certificate2::FIELD___privateKey ].DereferenceArray(); + // get private key + privateKey = hbCert[Library_sys_net_native_System_Security_Cryptography_X509Certificates_X509Certificate2:: + FIELD___privateKey] + .DereferenceArray(); pk = privateKey->GetFirstElement(); } - // get certificate + // get certificate sslCert = arrCert->GetFirstElement(); // get password - CLR_RT_HeapBlock *hbPwd = hbCert[ Library_sys_net_native_System_Security_Cryptography_X509Certificates_X509Certificate::FIELD___password ].Dereference();// FAULT_ON_NULL(hbPwd); + CLR_RT_HeapBlock *hbPwd = + hbCert + [Library_sys_net_native_System_Security_Cryptography_X509Certificates_X509Certificate::FIELD___password] + .Dereference(); // FAULT_ON_NULL(hbPwd); password = hbPwd->StringText(); } - if(isServer) + if (isServer) { - result = (SSL_ServerInit( sslMode, sslVerify, (const char*)sslCert, sslCert == NULL ? 0 : arrCert->m_numOfElements, pk, pk == NULL ? 0 : privateKey->m_numOfElements, password, hal_strlen_s(password), sslContext ) ? 0 : -1); + result = + (SSL_ServerInit( + sslMode, + sslVerify, + (const char *)sslCert, + sslCert == NULL ? 0 : arrCert->m_numOfElements, + pk, + pk == NULL ? 0 : privateKey->m_numOfElements, + password, + hal_strlen_s(password), + sslContext) + ? 0 + : -1); } else { - result = (SSL_ClientInit( sslMode, sslVerify, (const char*)sslCert, sslCert == NULL ? 0 : arrCert->m_numOfElements, pk, pk == NULL ? 0 : privateKey->m_numOfElements, password, hal_strlen_s(password), sslContext ) ? 0 : -1); + result = + (SSL_ClientInit( + sslMode, + sslVerify, + (const char *)sslCert, + sslCert == NULL ? 0 : arrCert->m_numOfElements, + pk, + pk == NULL ? 0 : privateKey->m_numOfElements, + password, + hal_strlen_s(password), + sslContext) + ? 0 + : -1); } - NANOCLR_CHECK_HRESULT(ThrowOnError( stack, result )); + NANOCLR_CHECK_HRESULT(ThrowOnError(stack, result)); - if(isFirstCall) + if (isFirstCall) { GenerateNewSslSeed(); } - if(caCert != NULL) + if (caCert != NULL) { - arrCert = caCert[ Library_sys_net_native_System_Security_Cryptography_X509Certificates_X509Certificate::FIELD___certificate ].DereferenceArray(); //FAULT_ON_NULL(arrCert); + arrCert = caCert[Library_sys_net_native_System_Security_Cryptography_X509Certificates_X509Certificate:: + FIELD___certificate] + .DereferenceArray(); // FAULT_ON_NULL(arrCert); // If arrCert == NULL then the certificate is an X509Certificate2 which uses a certificate handle - if(arrCert == NULL) + if (arrCert == NULL) { CLR_INT32 sessionCtx = 0; - arrCert = caCert[ Library_sys_net_native_System_Security_Cryptography_X509Certificates_X509Certificate::FIELD___handle ].DereferenceArray(); FAULT_ON_NULL(arrCert); + arrCert = caCert[Library_sys_net_native_System_Security_Cryptography_X509Certificates_X509Certificate:: + FIELD___handle] + .DereferenceArray(); + FAULT_ON_NULL(arrCert); sslCert = arrCert->GetFirstElement(); - arrCert = caCert[ Library_sys_net_native_System_Security_Cryptography_X509Certificates_X509Certificate::FIELD___sessionHandle ].DereferenceArray(); FAULT_ON_NULL(arrCert); + arrCert = caCert[Library_sys_net_native_System_Security_Cryptography_X509Certificates_X509Certificate:: + FIELD___sessionHandle] + .DereferenceArray(); + FAULT_ON_NULL(arrCert); - sessionCtx = *(int32_t*)arrCert->GetFirstElement(); + sessionCtx = *(int32_t *)arrCert->GetFirstElement(); // pass the session handle down as the password paramter and the certificate handle as the data parameter - result = (SSL_AddCertificateAuthority( sslContext, (const char*)sslCert, arrCert->m_numOfElements, (LPCSTR)&sessionCtx ) ? 0 : -1); - - NANOCLR_CHECK_HRESULT(ThrowOnError( stack, result )); + result = + (SSL_AddCertificateAuthority( + sslContext, + (const char *)sslCert, + arrCert->m_numOfElements, + (LPCSTR)&sessionCtx) + ? 0 + : -1); + + NANOCLR_CHECK_HRESULT(ThrowOnError(stack, result)); } else { @@ -581,51 +648,62 @@ HRESULT Library_sys_net_native_System_Net_Security_SslNative::InitHelper( CLR_RT sslCert = arrCert->GetFirstElement(); - CLR_RT_HeapBlock *hbPwd = caCert[ Library_sys_net_native_System_Security_Cryptography_X509Certificates_X509Certificate::FIELD___password ].Dereference(); FAULT_ON_NULL(hbPwd); + CLR_RT_HeapBlock *hbPwd = + caCert[Library_sys_net_native_System_Security_Cryptography_X509Certificates_X509Certificate:: + FIELD___password] + .Dereference(); + FAULT_ON_NULL(hbPwd); LPCSTR szCAPwd = hbPwd->StringText(); - - result = (SSL_AddCertificateAuthority( sslContext, (const char*)sslCert, arrCert->m_numOfElements, szCAPwd ) ? 0 : -1); - - NANOCLR_CHECK_HRESULT(ThrowOnError( stack, result )); + + result = + (SSL_AddCertificateAuthority(sslContext, (const char *)sslCert, arrCert->m_numOfElements, szCAPwd) + ? 0 + : -1); + + NANOCLR_CHECK_HRESULT(ThrowOnError(stack, result)); } } - stack.SetResult_I4( sslContext ); + stack.SetResult_I4(sslContext); NANOCLR_CLEANUP(); - if(FAILED(hr) && (sslContext != -1)) + if (FAILED(hr) && (sslContext != -1)) { - SSL_ExitContext( sslContext ); + SSL_ExitContext(sslContext); } NANOCLR_CLEANUP_END(); } -void Library_sys_net_native_System_Net_Security_SslNative::ThrowError( CLR_RT_StackFrame& stack, int errorCode ) -{ +void Library_sys_net_native_System_Net_Security_SslNative::ThrowError(CLR_RT_StackFrame &stack, int errorCode) +{ NATIVE_PROFILE_CLR_NETWORK(); - CLR_RT_HeapBlock& res = stack.m_owningThread->m_currentException; - - if((Library_corlib_native_System_Exception::CreateInstance( res, g_CLR_RT_WellKnownTypes.m_SocketException, CLR_E_FAIL, &stack )) == S_OK) + CLR_RT_HeapBlock &res = stack.m_owningThread->m_currentException; + + if ((Library_corlib_native_System_Exception::CreateInstance( + res, + g_CLR_RT_WellKnownTypes.m_SocketException, + CLR_E_FAIL, + &stack)) == S_OK) { - res.Dereference()[ Library_sys_net_native_System_Net_Sockets_SocketException::FIELD___errorCode ].SetInteger( errorCode ); + res.Dereference()[Library_sys_net_native_System_Net_Sockets_SocketException::FIELD___errorCode].SetInteger( + errorCode); } } -HRESULT Library_sys_net_native_System_Net_Security_SslNative::ThrowOnError( CLR_RT_StackFrame& stack, int res ) -{ +HRESULT Library_sys_net_native_System_Net_Security_SslNative::ThrowOnError(CLR_RT_StackFrame &stack, int res) +{ NATIVE_PROFILE_CLR_NETWORK(); NANOCLR_HEADER(); - if(res != 0) - { - ThrowError( stack, res ); + if (res != 0) + { + ThrowError(stack, res); - NANOCLR_SET_AND_LEAVE( CLR_E_PROCESS_EXCEPTION ); + NANOCLR_SET_AND_LEAVE(CLR_E_PROCESS_EXCEPTION); } NANOCLR_NOCLEANUP(); } - diff --git a/src/DeviceInterfaces/System.Net/sys_net_native_System_Net_Sockets_NativeSocket.cpp b/src/DeviceInterfaces/System.Net/sys_net_native_System_Net_Sockets_NativeSocket.cpp index c800eb919c..077dbf7d73 100644 --- a/src/DeviceInterfaces/System.Net/sys_net_native_System_Net_Sockets_NativeSocket.cpp +++ b/src/DeviceInterfaces/System.Net/sys_net_native_System_Net_Sockets_NativeSocket.cpp @@ -1,172 +1,179 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // - #include "sys_net_native.h" -HRESULT Library_sys_net_native_System_Net_Sockets_NativeSocket::socket___STATIC__I4__I4__I4__I4( CLR_RT_StackFrame& stack ) +HRESULT Library_sys_net_native_System_Net_Sockets_NativeSocket::socket___STATIC__I4__I4__I4__I4( + CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); - CLR_INT32 family = stack.Arg0().NumericByRef().s4; - CLR_INT32 type = stack.Arg1().NumericByRef().s4; + CLR_INT32 family = stack.Arg0().NumericByRef().s4; + CLR_INT32 type = stack.Arg1().NumericByRef().s4; CLR_INT32 protocol = stack.Arg2().NumericByRef().s4; - + CLR_INT32 nonBlocking = 1; - CLR_INT32 sock = SOCK_socket( family, type, protocol ); - - NANOCLR_CHECK_HRESULT(ThrowOnError( stack, sock )); - - NANOCLR_CHECK_HRESULT(ThrowOnError( stack, SOCK_ioctl( sock, SOCK_FIONBIO, &nonBlocking ) )); + CLR_INT32 sock = SOCK_socket(family, type, protocol); + + NANOCLR_CHECK_HRESULT(ThrowOnError(stack, sock)); + + NANOCLR_CHECK_HRESULT(ThrowOnError(stack, SOCK_ioctl(sock, SOCK_FIONBIO, &nonBlocking))); - stack.SetResult_I4( sock ); + stack.SetResult_I4(sock); NANOCLR_NOCLEANUP(); } -HRESULT Library_sys_net_native_System_Net_Sockets_NativeSocket::bind___STATIC__VOID__OBJECT__SystemNetEndPoint( CLR_RT_StackFrame& stack ) +HRESULT Library_sys_net_native_System_Net_Sockets_NativeSocket::bind___STATIC__VOID__OBJECT__SystemNetEndPoint( + CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); - return BindConnectHelper( stack, true ); + return BindConnectHelper(stack, true); NANOCLR_NOCLEANUP_NOLABEL(); } -HRESULT Library_sys_net_native_System_Net_Sockets_NativeSocket::connect___STATIC__VOID__OBJECT__SystemNetEndPoint__BOOLEAN( CLR_RT_StackFrame& stack ) +HRESULT Library_sys_net_native_System_Net_Sockets_NativeSocket:: + connect___STATIC__VOID__OBJECT__SystemNetEndPoint__BOOLEAN(CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); - return BindConnectHelper( stack, false ); + return BindConnectHelper(stack, false); NANOCLR_NOCLEANUP_NOLABEL(); } -HRESULT Library_sys_net_native_System_Net_Sockets_NativeSocket::send___STATIC__I4__OBJECT__SZARRAY_U1__I4__I4__I4__I4( CLR_RT_StackFrame& stack ) +HRESULT Library_sys_net_native_System_Net_Sockets_NativeSocket::send___STATIC__I4__OBJECT__SZARRAY_U1__I4__I4__I4__I4( + CLR_RT_StackFrame &stack) { NATIVE_PROFILE_CLR_NETWORK(); - return SendRecvHelper( stack, true, false ); + return SendRecvHelper(stack, true, false); } -HRESULT Library_sys_net_native_System_Net_Sockets_NativeSocket::recv___STATIC__I4__OBJECT__SZARRAY_U1__I4__I4__I4__I4( CLR_RT_StackFrame& stack ) +HRESULT Library_sys_net_native_System_Net_Sockets_NativeSocket::recv___STATIC__I4__OBJECT__SZARRAY_U1__I4__I4__I4__I4( + CLR_RT_StackFrame &stack) { NATIVE_PROFILE_CLR_NETWORK(); - return SendRecvHelper( stack, false, false ); + return SendRecvHelper(stack, false, false); } -HRESULT Library_sys_net_native_System_Net_Sockets_NativeSocket::close___STATIC__I4__OBJECT( CLR_RT_StackFrame& stack ) +HRESULT Library_sys_net_native_System_Net_Sockets_NativeSocket::close___STATIC__I4__OBJECT(CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); CLR_INT32 handle, ret; - CLR_RT_HeapBlock* socket = stack.Arg0().Dereference(); FAULT_ON_NULL(socket); - - handle = socket[ FIELD__m_Handle ].NumericByRef().s4; + CLR_RT_HeapBlock *socket = stack.Arg0().Dereference(); + FAULT_ON_NULL(socket); + + handle = socket[FIELD__m_Handle].NumericByRef().s4; + + ret = SOCK_close(handle); + + // If a socket gets closed, we need to make sure to wake up any threads that are waiting on it. + Events_Set(SYSTEM_EVENT_FLAG_SOCKET); - ret = SOCK_close( handle ); - - //If a socket gets closed, we need to make sure to wake up any threads that are waiting on it. - Events_Set( SYSTEM_EVENT_FLAG_SOCKET ); + stack.SetResult_I4(ret); - stack.SetResult_I4( ret ); - NANOCLR_NOCLEANUP(); } -HRESULT Library_sys_net_native_System_Net_Sockets_NativeSocket::listen___STATIC__VOID__OBJECT__I4( CLR_RT_StackFrame& stack ) +HRESULT Library_sys_net_native_System_Net_Sockets_NativeSocket::listen___STATIC__VOID__OBJECT__I4( + CLR_RT_StackFrame &stack) { NATIVE_PROFILE_CLR_NETWORK(); NANOCLR_HEADER(); - CLR_RT_HeapBlock* socket = stack.Arg0().Dereference(); + CLR_RT_HeapBlock *socket = stack.Arg0().Dereference(); CLR_INT32 handle; CLR_INT32 backlog = stack.Arg1().NumericByRef().s4; CLR_INT32 ret; FAULT_ON_NULL(socket); - handle = socket[ FIELD__m_Handle ].NumericByRef().s4; + handle = socket[FIELD__m_Handle].NumericByRef().s4; - ret = SOCK_listen( handle, backlog ); + ret = SOCK_listen(handle, backlog); - NANOCLR_CHECK_HRESULT(ThrowOnError( stack, ret )); + NANOCLR_CHECK_HRESULT(ThrowOnError(stack, ret)); NANOCLR_NOCLEANUP(); } -HRESULT Library_sys_net_native_System_Net_Sockets_NativeSocket::accept___STATIC__I4__OBJECT( CLR_RT_StackFrame& stack ) +HRESULT Library_sys_net_native_System_Net_Sockets_NativeSocket::accept___STATIC__I4__OBJECT(CLR_RT_StackFrame &stack) { NATIVE_PROFILE_CLR_NETWORK(); NANOCLR_HEADER(); - CLR_RT_HeapBlock* socket = stack.Arg0().Dereference(); + CLR_RT_HeapBlock *socket = stack.Arg0().Dereference(); CLR_INT32 handle; CLR_INT32 ret; CLR_INT32 nonBlocking = 1; FAULT_ON_NULL(socket); - handle = socket[ FIELD__m_Handle ].NumericByRef().s4; - + handle = socket[FIELD__m_Handle].NumericByRef().s4; /* Because we could have been a rescheduled call due to a prior call that would have blocked, we need to see - * if our handle has been shutdown before continuing. */ + * if our handle has been shutdown before continuing. */ if (handle == DISPOSED_HANDLE) { ThrowError(stack, CLR_E_OBJECT_DISPOSED); - NANOCLR_SET_AND_LEAVE (CLR_E_PROCESS_EXCEPTION); + NANOCLR_SET_AND_LEAVE(CLR_E_PROCESS_EXCEPTION); } - ret = SOCK_accept( handle, NULL, NULL ); + ret = SOCK_accept(handle, NULL, NULL); - if(ret != SOCK_SOCKET_ERROR) + if (ret != SOCK_SOCKET_ERROR) { - NANOCLR_CHECK_HRESULT(ThrowOnError( stack, SOCK_ioctl( ret, SOCK_FIONBIO, &nonBlocking ) )); + NANOCLR_CHECK_HRESULT(ThrowOnError(stack, SOCK_ioctl(ret, SOCK_FIONBIO, &nonBlocking))); } - NANOCLR_CHECK_HRESULT(ThrowOnError( stack, ret )); + NANOCLR_CHECK_HRESULT(ThrowOnError(stack, ret)); - stack.SetResult_I4( ret ); + stack.SetResult_I4(ret); NANOCLR_NOCLEANUP(); } -HRESULT Library_sys_net_native_System_Net_Sockets_NativeSocket::getaddrinfo___STATIC__VOID__STRING__BYREF_STRING__BYREF_SZARRAY_SZARRAY_U1( CLR_RT_StackFrame& stack ) +HRESULT Library_sys_net_native_System_Net_Sockets_NativeSocket:: + getaddrinfo___STATIC__VOID__STRING__BYREF_STRING__BYREF_SZARRAY_SZARRAY_U1(CLR_RT_StackFrame &stack) { NATIVE_PROFILE_CLR_NETWORK(); NANOCLR_HEADER(); LPCSTR szName = stack.Arg0().RecoverString(); struct SOCK_addrinfo hints; - struct SOCK_addrinfo* addr = NULL; - struct SOCK_addrinfo* addrT; - CLR_UINT32 cAddresses = 0; - CLR_RT_HeapBlock* pAddress; - CLR_INT32 timeout_ms = 30000; - CLR_RT_HeapBlock hbTimeout; - CLR_INT32 ret; - bool fRes = true; - CLR_INT64* timeout; - uint32_t socketError = SOCK_SOCKET_ERROR; + struct SOCK_addrinfo *addr = NULL; + struct SOCK_addrinfo *addrT; + CLR_UINT32 cAddresses = 0; + CLR_RT_HeapBlock *pAddress; + CLR_INT32 timeout_ms = 30000; + CLR_RT_HeapBlock hbTimeout; + CLR_INT32 ret; + bool fRes = true; + CLR_INT64 *timeout; + uint32_t socketError = SOCK_SOCKET_ERROR; // !! need to cast to CLR_INT64 otherwise it wont setup a proper timeout infinite - hbTimeout.SetInteger( (CLR_INT64)timeout_ms * TIME_CONVERSION__TO_MILLISECONDS ); + hbTimeout.SetInteger((CLR_INT64)timeout_ms * TIME_CONVERSION__TO_MILLISECONDS); - NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks( hbTimeout, timeout )); + NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks(hbTimeout, timeout)); do { - memset( &hints, 0, sizeof(hints) ); + memset(&hints, 0, sizeof(hints)); - ret = SOCK_getaddrinfo( szName, NULL, &hints, &addr ); + ret = SOCK_getaddrinfo(szName, NULL, &hints, &addr); - if(ret == SOCK_SOCKET_ERROR) + if (ret == SOCK_SOCKET_ERROR) { // get last error from socket socketError = SOCK_getlasterror(); - if(socketError == SOCK_EWOULDBLOCK) + if (socketError == SOCK_EWOULDBLOCK) { // non-blocking - allow other threads to run while we wait for handle activity - NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.WaitEvents( stack.m_owningThread, *timeout, CLR_RT_ExecutionEngine::c_Event_Socket, fRes )); + NANOCLR_CHECK_HRESULT( + g_CLR_RT_ExecutionEngine.WaitEvents(stack.m_owningThread, *timeout, Event_Socket, fRes)); } else { @@ -181,17 +188,16 @@ HRESULT Library_sys_net_native_System_Net_Sockets_NativeSocket::getaddrinfo___ST // done here break; } - } - while(fRes); - + } while (fRes); + // timeout expired - if(!fRes) + if (!fRes) { ret = SOCK_SOCKET_ERROR; - - ThrowError( stack, SOCK_ETIMEDOUT ); - - NANOCLR_SET_AND_LEAVE( CLR_E_PROCESS_EXCEPTION ); + + ThrowError(stack, SOCK_ETIMEDOUT); + + NANOCLR_SET_AND_LEAVE(CLR_E_PROCESS_EXCEPTION); } else { @@ -200,223 +206,237 @@ HRESULT Library_sys_net_native_System_Net_Sockets_NativeSocket::getaddrinfo___ST } // getaddrinfo returns a winsock error code rather than SOCK_SOCKET_ERROR, so pass this on to the exception handling - if(ret != 0) + if (ret != 0) { - ThrowError( stack, ret ); + ThrowError(stack, ret); NANOCLR_SET_AND_LEAVE(CLR_E_PROCESS_EXCEPTION); } { - CLR_RT_HeapBlock hbCanonicalName; - CLR_RT_HeapBlock hbAddresses; - - hbCanonicalName.SetObjectReference( NULL ); - CLR_RT_ProtectFromGC gc( hbCanonicalName ); + CLR_RT_HeapBlock hbCanonicalName; + CLR_RT_HeapBlock hbAddresses; + + hbCanonicalName.SetObjectReference(NULL); + CLR_RT_ProtectFromGC gc(hbCanonicalName); - hbAddresses.SetObjectReference( NULL ); - CLR_RT_ProtectFromGC gc2( hbAddresses ); + hbAddresses.SetObjectReference(NULL); + CLR_RT_ProtectFromGC gc2(hbAddresses); - for(int pass = 0; pass < 2; pass++) - { + for (int pass = 0; pass < 2; pass++) + { cAddresses = 0; - for(addrT = addr; addrT != NULL; addrT = addrT->ai_next) + for (addrT = addr; addrT != NULL; addrT = addrT->ai_next) { - if(pass == 1) + if (pass == 1) { - if(addrT->ai_canonname && addrT->ai_canonname[ 0 ]) + if (addrT->ai_canonname && addrT->ai_canonname[0]) { - //allocate return string - NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_String::CreateInstance( hbCanonicalName, addrT->ai_canonname )); - NANOCLR_CHECK_HRESULT(hbCanonicalName.StoreToReference( stack.Arg1(), 0 )); + // allocate return string + NANOCLR_CHECK_HRESULT( + CLR_RT_HeapBlock_String::CreateInstance(hbCanonicalName, addrT->ai_canonname)); + NANOCLR_CHECK_HRESULT(hbCanonicalName.StoreToReference(stack.Arg1(), 0)); } - //allocate address and store into array - pAddress = (CLR_RT_HeapBlock*)hbAddresses.DereferenceArray()->GetElement( cAddresses ); + // allocate address and store into array + pAddress = (CLR_RT_HeapBlock *)hbAddresses.DereferenceArray()->GetElement(cAddresses); - NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_Array::CreateInstance( *pAddress, (CLR_UINT32)addrT->ai_addrlen, g_CLR_RT_WellKnownTypes.m_UInt8 )); + NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_Array::CreateInstance( + *pAddress, + (CLR_UINT32)addrT->ai_addrlen, + g_CLR_RT_WellKnownTypes.m_UInt8)); - //copy address. - memcpy( pAddress->DereferenceArray()->GetFirstElement(), addrT->ai_addr, addrT->ai_addrlen ); + // copy address. + memcpy(pAddress->DereferenceArray()->GetFirstElement(), addrT->ai_addr, addrT->ai_addrlen); } - + cAddresses++; } - - if(pass == 0) + + if (pass == 0) { - //allocate array of byte arrays + // allocate array of byte arrays CLR_RT_ReflectionDef_Index idx; - idx.m_kind = REFLECTION_TYPE; - idx.m_levels = 2; + idx.m_kind = REFLECTION_TYPE; + idx.m_levels = 2; idx.m_data.m_type.m_data = g_CLR_RT_WellKnownTypes.m_UInt8.m_data; - NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_Array::CreateInstance( hbAddresses, cAddresses, idx )); + NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_Array::CreateInstance(hbAddresses, cAddresses, idx)); - NANOCLR_CHECK_HRESULT(hbAddresses.StoreToReference( stack.Arg2(), 0 )); + NANOCLR_CHECK_HRESULT(hbAddresses.StoreToReference(stack.Arg2(), 0)); } - } + } } - stack.PopValue(); // Timeout - + stack.PopValue(); // Timeout + NANOCLR_CLEANUP(); - if( addr ) SOCK_freeaddrinfo( addr ); + if (addr) + SOCK_freeaddrinfo(addr); NANOCLR_CLEANUP_END(); } -HRESULT Library_sys_net_native_System_Net_Sockets_NativeSocket::shutdown___STATIC__VOID__OBJECT__I4__BYREF_I4( CLR_RT_StackFrame& stack ) +HRESULT Library_sys_net_native_System_Net_Sockets_NativeSocket::shutdown___STATIC__VOID__OBJECT__I4__BYREF_I4( + CLR_RT_StackFrame &stack) { NATIVE_PROFILE_CLR_NETWORK(); NANOCLR_HEADER(); - CLR_RT_HeapBlock* socket = stack.Arg0().Dereference(); + CLR_RT_HeapBlock *socket = stack.Arg0().Dereference(); CLR_INT32 handle; CLR_INT32 how = stack.Arg1().NumericByRef().s4; CLR_INT32 ret; - + FAULT_ON_NULL(socket); - handle = socket[ FIELD__m_Handle ].NumericByRef().s4; + handle = socket[FIELD__m_Handle].NumericByRef().s4; - ret = SOCK_shutdown( handle, how ); + ret = SOCK_shutdown(handle, how); - NANOCLR_CHECK_HRESULT(ThrowOnError( stack, ret )); + NANOCLR_CHECK_HRESULT(ThrowOnError(stack, ret)); NANOCLR_NOCLEANUP(); } -HRESULT Library_sys_net_native_System_Net_Sockets_NativeSocket::sendto___STATIC__I4__OBJECT__SZARRAY_U1__I4__I4__I4__I4__SystemNetEndPoint( CLR_RT_StackFrame& stack ) +HRESULT Library_sys_net_native_System_Net_Sockets_NativeSocket:: + sendto___STATIC__I4__OBJECT__SZARRAY_U1__I4__I4__I4__I4__SystemNetEndPoint(CLR_RT_StackFrame &stack) { NATIVE_PROFILE_CLR_NETWORK(); - return SendRecvHelper( stack, true, true ); + return SendRecvHelper(stack, true, true); } -HRESULT Library_sys_net_native_System_Net_Sockets_NativeSocket::recvfrom___STATIC__I4__OBJECT__SZARRAY_U1__I4__I4__I4__I4__BYREF_SystemNetEndPoint( CLR_RT_StackFrame& stack ) +HRESULT Library_sys_net_native_System_Net_Sockets_NativeSocket:: + recvfrom___STATIC__I4__OBJECT__SZARRAY_U1__I4__I4__I4__I4__BYREF_SystemNetEndPoint(CLR_RT_StackFrame &stack) { NATIVE_PROFILE_CLR_NETWORK(); - return SendRecvHelper( stack, false, true ); + return SendRecvHelper(stack, false, true); } -HRESULT Library_sys_net_native_System_Net_Sockets_NativeSocket::getpeername___STATIC__VOID__OBJECT__BYREF_SystemNetEndPoint( CLR_RT_StackFrame& stack ) +HRESULT Library_sys_net_native_System_Net_Sockets_NativeSocket:: + getpeername___STATIC__VOID__OBJECT__BYREF_SystemNetEndPoint(CLR_RT_StackFrame &stack) { - NATIVE_PROFILE_CLR_NETWORK(); - return SockNameHelper( stack, true ); + NATIVE_PROFILE_CLR_NETWORK(); + return SockNameHelper(stack, true); } -HRESULT Library_sys_net_native_System_Net_Sockets_NativeSocket::getsockname___STATIC__VOID__OBJECT__BYREF_SystemNetEndPoint( CLR_RT_StackFrame& stack ) +HRESULT Library_sys_net_native_System_Net_Sockets_NativeSocket:: + getsockname___STATIC__VOID__OBJECT__BYREF_SystemNetEndPoint(CLR_RT_StackFrame &stack) { NATIVE_PROFILE_CLR_NETWORK(); - return SockNameHelper( stack, false ); + return SockNameHelper(stack, false); } -HRESULT Library_sys_net_native_System_Net_Sockets_NativeSocket::getsockopt___STATIC__VOID__OBJECT__I4__I4__SZARRAY_U1( CLR_RT_StackFrame& stack ) +HRESULT Library_sys_net_native_System_Net_Sockets_NativeSocket::getsockopt___STATIC__VOID__OBJECT__I4__I4__SZARRAY_U1( + CLR_RT_StackFrame &stack) { NATIVE_PROFILE_CLR_NETWORK(); - return SockOptHelper( stack, true ); + return SockOptHelper(stack, true); } -HRESULT Library_sys_net_native_System_Net_Sockets_NativeSocket::setsockopt___STATIC__VOID__OBJECT__I4__I4__SZARRAY_U1( CLR_RT_StackFrame& stack ) +HRESULT Library_sys_net_native_System_Net_Sockets_NativeSocket::setsockopt___STATIC__VOID__OBJECT__I4__I4__SZARRAY_U1( + CLR_RT_StackFrame &stack) { NATIVE_PROFILE_CLR_NETWORK(); - return SockOptHelper( stack, false ); + return SockOptHelper(stack, false); } -HRESULT Library_sys_net_native_System_Net_Sockets_NativeSocket::poll___STATIC__BOOLEAN__OBJECT__I4__I4( CLR_RT_StackFrame& stack ) +HRESULT Library_sys_net_native_System_Net_Sockets_NativeSocket::poll___STATIC__BOOLEAN__OBJECT__I4__I4( + CLR_RT_StackFrame &stack) { NATIVE_PROFILE_CLR_NETWORK(); NANOCLR_HEADER(); - CLR_RT_HeapBlock* socket = stack.Arg0().Dereference(); + CLR_RT_HeapBlock *socket = stack.Arg0().Dereference(); CLR_INT32 handle; - CLR_INT32 mode = stack.Arg1().NumericByRef().s4; + CLR_INT32 mode = stack.Arg1().NumericByRef().s4; CLR_INT32 timeout_us = stack.Arg2().NumericByRef().s4; CLR_RT_HeapBlock hbTimeout; CLR_INT32 res = 0; - bool fRes = true; + bool fRes = true; - CLR_INT64* timeout; + CLR_INT64 *timeout; FAULT_ON_NULL(socket); - handle = socket[ FIELD__m_Handle ].NumericByRef().s4; + handle = socket[FIELD__m_Handle].NumericByRef().s4; /* Because we could have been a rescheduled call due to a prior call that would have blocked, we need to see * if our handle has been shutdown before continuing. */ if (handle == DISPOSED_HANDLE) { - ThrowError( stack, CLR_E_OBJECT_DISPOSED ); - NANOCLR_SET_AND_LEAVE (CLR_E_PROCESS_EXCEPTION); + ThrowError(stack, CLR_E_OBJECT_DISPOSED); + NANOCLR_SET_AND_LEAVE(CLR_E_PROCESS_EXCEPTION); } - if(timeout_us < 0) + if (timeout_us < 0) { // Infinite Timeout // !! need to cast to CLR_INT64 otherwise it wont setup a proper timeout infinite - hbTimeout.SetInteger( (CLR_INT64)-1 ); + hbTimeout.SetInteger((CLR_INT64)-1); } else { // !! need to cast to CLR_INT64 otherwise it wont setup a proper timeout infinite - hbTimeout.SetInteger( (CLR_INT64)timeout_us * TIME_CONVERSION__TO_MILLISECONDS / 1000 ); + hbTimeout.SetInteger((CLR_INT64)timeout_us * TIME_CONVERSION__TO_MILLISECONDS / 1000); } - - NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks( hbTimeout, timeout )); + NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks(hbTimeout, timeout)); - while(fRes) + while (fRes) { - res = Helper__SelectSocket( handle, mode ); + res = Helper__SelectSocket(handle, mode); - if(res != 0) break; + if (res != 0) + break; - NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.WaitEvents( stack.m_owningThread, *timeout, CLR_RT_ExecutionEngine::c_Event_Socket, fRes )); + NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.WaitEvents(stack.m_owningThread, *timeout, Event_Socket, fRes)); } - stack.PopValue(); //timer + stack.PopValue(); // timer - NANOCLR_CHECK_HRESULT(ThrowOnError( stack, res )); + NANOCLR_CHECK_HRESULT(ThrowOnError(stack, res)); - stack.SetResult_Boolean( res != 0 ); + stack.SetResult_Boolean(res != 0); NANOCLR_NOCLEANUP(); } -HRESULT Library_sys_net_native_System_Net_Sockets_NativeSocket::ioctl___STATIC__VOID__OBJECT__U4__BYREF_U4( CLR_RT_StackFrame& stack ) +HRESULT Library_sys_net_native_System_Net_Sockets_NativeSocket::ioctl___STATIC__VOID__OBJECT__U4__BYREF_U4( + CLR_RT_StackFrame &stack) { NATIVE_PROFILE_CLR_NETWORK(); NANOCLR_HEADER(); - CLR_RT_HeapBlock* socket = stack.Arg0().Dereference(); + CLR_RT_HeapBlock *socket = stack.Arg0().Dereference(); CLR_INT32 handle; - CLR_INT32 cmd = stack.Arg1().NumericByRef().s4; + CLR_INT32 cmd = stack.Arg1().NumericByRef().s4; CLR_RT_HeapBlock blkArg; CLR_INT32 ret; FAULT_ON_NULL(socket); - handle = socket[ FIELD__m_Handle ].NumericByRef().s4; + handle = socket[FIELD__m_Handle].NumericByRef().s4; + + _SIDE_ASSERTE(SUCCEEDED(blkArg.LoadFromReference(stack.Arg2()))); - _SIDE_ASSERTE(SUCCEEDED(blkArg.LoadFromReference( stack.Arg2() ))); + ret = SOCK_ioctl(handle, cmd, (CLR_INT32 *)&blkArg.NumericByRef().s4); - ret = SOCK_ioctl( handle, cmd, (CLR_INT32*)&blkArg.NumericByRef().s4 ); - - NANOCLR_CHECK_HRESULT(ThrowOnError( stack, ret )); + NANOCLR_CHECK_HRESULT(ThrowOnError(stack, ret)); - _SIDE_ASSERTE(SUCCEEDED(blkArg.StoreToReference( stack.Arg2(), 0 ))); + _SIDE_ASSERTE(SUCCEEDED(blkArg.StoreToReference(stack.Arg2(), 0))); NANOCLR_NOCLEANUP(); } //--// -HRESULT Library_sys_net_native_System_Net_Sockets_NativeSocket::BindConnectHelper( CLR_RT_StackFrame& stack, bool fBind ) +HRESULT Library_sys_net_native_System_Net_Sockets_NativeSocket::BindConnectHelper(CLR_RT_StackFrame &stack, bool fBind) { NATIVE_PROFILE_CLR_NETWORK(); NANOCLR_HEADER(); - CLR_RT_HeapBlock* socket = stack.Arg0().Dereference(); + CLR_RT_HeapBlock *socket = stack.Arg0().Dereference(); CLR_INT32 handle; SOCK_sockaddr addr; @@ -425,42 +445,42 @@ HRESULT Library_sys_net_native_System_Net_Sockets_NativeSocket::BindConnectHelpe bool fThrowOnWouldBlock = false; FAULT_ON_NULL(socket); - handle = socket[ FIELD__m_Handle ].NumericByRef().s4; + handle = socket[FIELD__m_Handle].NumericByRef().s4; - NANOCLR_CHECK_HRESULT(MarshalSockAddress( &addr, addrLen, stack.Arg1() )); + NANOCLR_CHECK_HRESULT(MarshalSockAddress(&addr, addrLen, stack.Arg1())); - if(fBind) + if (fBind) { - ret = SOCK_bind( handle, &addr, addrLen ); + ret = SOCK_bind(handle, &addr, addrLen); } else { - ret = SOCK_connect( handle, &addr, addrLen ); - + ret = SOCK_connect(handle, &addr, addrLen); + fThrowOnWouldBlock = (stack.Arg2().NumericByRefConst().s4 != 0); - - if(!fThrowOnWouldBlock && SOCK_getsocklasterror( handle ) == SOCK_EWOULDBLOCK) + + if (!fThrowOnWouldBlock && SOCK_getsocklasterror(handle) == SOCK_EWOULDBLOCK) { - NANOCLR_SET_AND_LEAVE(S_OK); + NANOCLR_SET_AND_LEAVE(S_OK); } } - NANOCLR_CHECK_HRESULT(ThrowOnError( stack, ret )); + NANOCLR_CHECK_HRESULT(ThrowOnError(stack, ret)); NANOCLR_NOCLEANUP(); } -CLR_INT32 Library_sys_net_native_System_Net_Sockets_NativeSocket::Helper__SelectSocket(CLR_INT32 handle, CLR_INT32 mode ) +CLR_INT32 Library_sys_net_native_System_Net_Sockets_NativeSocket::Helper__SelectSocket(CLR_INT32 handle, CLR_INT32 mode) { struct SOCK_timeval timeval; - SOCK_fd_set* readfds = NULL; - SOCK_fd_set* writefds = NULL; - SOCK_fd_set* exceptfds = NULL; + SOCK_fd_set *readfds = NULL; + SOCK_fd_set *writefds = NULL; + SOCK_fd_set *exceptfds = NULL; SOCK_fd_set fds; SOCK_fd_set fdsExcept; - CLR_INT32 res = 0; + CLR_INT32 res = 0; - switch(mode) + switch (mode) { case 0: readfds = &fds; @@ -475,31 +495,31 @@ CLR_INT32 Library_sys_net_native_System_Net_Sockets_NativeSocket::Helper__Select exceptfds = &fds; break; } - - fds.fd_count = 1; - fds.fd_array[ 0 ] = handle; + + fds.fd_count = 1; + fds.fd_array[0] = handle; // This Poll method is a little handicapped in the sense that it only allows the caller to wait // for a read, a write or an except. This causes a problem when there is a socket exception. The // poll will continue to block forever because the select statement wasn't looking for exceptions // Therefore, we will force the select call to look for the except case if it is not already doing it. - if(exceptfds == NULL) + if (exceptfds == NULL) { - fdsExcept.fd_count = 1; - fdsExcept.fd_array[ 0 ] = handle; - exceptfds = &fdsExcept; + fdsExcept.fd_count = 1; + fdsExcept.fd_array[0] = handle; + exceptfds = &fdsExcept; } - timeval.tv_sec = 0; + timeval.tv_sec = 0; timeval.tv_usec = 0; - res = SOCK_select( 1, readfds, writefds, exceptfds, &timeval ); + res = SOCK_select(1, readfds, writefds, exceptfds, &timeval); // socket is in the exception state (only return error if caller was NOT looking for the excepted state) - if((mode != 2) && (fdsExcept.fd_count != 0)) + if ((mode != 2) && (fdsExcept.fd_count != 0)) { // For read mode ignore exception if we have data to read - if(!(mode == 0 && fds.fd_count != 0)) + if (!(mode == 0 && fds.fd_count != 0)) { return SOCK_SOCKET_ERROR; } @@ -508,7 +528,10 @@ CLR_INT32 Library_sys_net_native_System_Net_Sockets_NativeSocket::Helper__Select return res; } -HRESULT Library_sys_net_native_System_Net_Sockets_NativeSocket::MarshalSockAddress( CLR_RT_HeapBlock& blkDst, const struct SOCK_sockaddr* addrSrc, CLR_UINT32 addrLenSrc ) +HRESULT Library_sys_net_native_System_Net_Sockets_NativeSocket::MarshalSockAddress( + CLR_RT_HeapBlock &blkDst, + const struct SOCK_sockaddr *addrSrc, + CLR_UINT32 addrLenSrc) { NATIVE_PROFILE_CLR_NETWORK(); @@ -516,27 +539,29 @@ HRESULT Library_sys_net_native_System_Net_Sockets_NativeSocket::MarshalSockAddre (void)addrLenSrc; - SOCK_sockaddr_in* src = (SOCK_sockaddr_in*)addrSrc; + SOCK_sockaddr_in *src = (SOCK_sockaddr_in *)addrSrc; CLR_RT_TypeDef_Index ipAddressTypeDef; CLR_RT_TypeDef_Index ipEndPointTypeDef; - CLR_RT_HeapBlock* ipAddressHbObj; - CLR_RT_HeapBlock* ipEndPointHbObj; + CLR_RT_HeapBlock *ipAddressHbObj; + CLR_RT_HeapBlock *ipEndPointHbObj; - CLR_RT_HeapBlock ipAddress; ipAddress.SetObjectReference( NULL ); - CLR_RT_ProtectFromGC gc1( ipAddress ); + CLR_RT_HeapBlock ipAddress; + ipAddress.SetObjectReference(NULL); + CLR_RT_ProtectFromGC gc1(ipAddress); - CLR_RT_HeapBlock ipEndPoint; ipEndPoint.SetObjectReference( NULL ); - CLR_RT_ProtectFromGC gc2( ipEndPoint ); + CLR_RT_HeapBlock ipEndPoint; + ipEndPoint.SetObjectReference(NULL); + CLR_RT_ProtectFromGC gc2(ipEndPoint); // find type definition, don't bother checking the result as it exists for sure - g_CLR_RT_TypeSystem.FindTypeDef( "IPAddress", "System.Net", ipAddressTypeDef ); + g_CLR_RT_TypeSystem.FindTypeDef("IPAddress", "System.Net", ipAddressTypeDef); // create an instance of NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.NewObjectFromIndex(ipAddress, ipAddressTypeDef)); // find type definition, don't bother checking the result as it exists for sure - g_CLR_RT_TypeSystem.FindTypeDef( "IPEndPoint", "System.Net", ipEndPointTypeDef ); + g_CLR_RT_TypeSystem.FindTypeDef("IPEndPoint", "System.Net", ipEndPointTypeDef); // create an instance of NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.NewObjectFromIndex(ipEndPoint, ipEndPointTypeDef)); @@ -550,326 +575,345 @@ HRESULT Library_sys_net_native_System_Net_Sockets_NativeSocket::MarshalSockAddre // IPAddress _address field // CLR_INT64 fields need to be accessed by pointer - CLR_RT_HeapBlock& addressFieldRef = ipAddressHbObj[ Library_sys_net_native_System_Net_IPAddress::FIELD___address ]; - CLR_INT64* pRes = (CLR_INT64*)&addressFieldRef.NumericByRef().s8; + CLR_RT_HeapBlock &addressFieldRef = + ipAddressHbObj[Library_sys_net_native_System_Net_IPAddress::FIELD___address]; + CLR_INT64 *pRes = (CLR_INT64 *)&addressFieldRef.NumericByRef().s8; *pRes = src->sin_addr.S_un.S_addr; - + // IPAddress _family field - ipAddressHbObj[ Library_sys_net_native_System_Net_IPAddress::FIELD___family ].NumericByRef().s4 = src->sin_family; - + ipAddressHbObj[Library_sys_net_native_System_Net_IPAddress::FIELD___family].NumericByRef().s4 = src->sin_family; + // IPEndPoint _port field // take care of endianess swapping - ipEndPointHbObj[ Library_sys_net_native_System_Net_IPEndPoint::FIELD___port ].NumericByRef().s4 = SOCK_ntohs(src->sin_port); + ipEndPointHbObj[Library_sys_net_native_System_Net_IPEndPoint::FIELD___port].NumericByRef().s4 = + SOCK_ntohs(src->sin_port); // set IPEndPoint address with IPAddress heap block object - ipEndPointHbObj[ Library_sys_net_native_System_Net_IPEndPoint::FIELD___address ].SetObjectReference( ipAddressHbObj ); + ipEndPointHbObj[Library_sys_net_native_System_Net_IPEndPoint::FIELD___address].SetObjectReference( + ipAddressHbObj); } _ASSERTE(blkDst.DataType() == DATATYPE_BYREF); // store the new IPEndPoint object to reference - NANOCLR_CHECK_HRESULT(ipEndPoint.StoreToReference( blkDst, 0 )); + NANOCLR_CHECK_HRESULT(ipEndPoint.StoreToReference(blkDst, 0)); NANOCLR_NOCLEANUP(); } -HRESULT Library_sys_net_native_System_Net_Sockets_NativeSocket::MarshalSockAddress( struct SOCK_sockaddr* addrDst, CLR_UINT32& addrLenDst, const CLR_RT_HeapBlock& blkEndPointAddress ) -{ +HRESULT Library_sys_net_native_System_Net_Sockets_NativeSocket::MarshalSockAddress( + struct SOCK_sockaddr *addrDst, + CLR_UINT32 &addrLenDst, + const CLR_RT_HeapBlock &blkEndPointAddress) +{ NATIVE_PROFILE_CLR_NETWORK(); NANOCLR_HEADER(); - SOCK_sockaddr_in* dst = (SOCK_sockaddr_in*)addrDst; + SOCK_sockaddr_in *dst = (SOCK_sockaddr_in *)addrDst; - CLR_RT_HeapBlock* endPointAddress; - CLR_RT_HeapBlock* remoteEndPointAddress; + CLR_RT_HeapBlock *endPointAddress; + CLR_RT_HeapBlock *remoteEndPointAddress; int64_t address; int32_t port; - endPointAddress = blkEndPointAddress.Dereference(); + endPointAddress = blkEndPointAddress.Dereference(); FAULT_ON_NULL(endPointAddress); // get a pointer to the managed field object instance for m_Address - remoteEndPointAddress = endPointAddress[ Library_sys_net_native_System_Net_IPEndPoint::FIELD___address ].Dereference(); + remoteEndPointAddress = + endPointAddress[Library_sys_net_native_System_Net_IPEndPoint::FIELD___address].Dereference(); FAULT_ON_NULL(remoteEndPointAddress); // get value of m_Address field (type long) - address = (CLR_INT64)remoteEndPointAddress[ Library_sys_net_native_System_Net_IPAddress::FIELD___address ].NumericByRef().s8; + address = (CLR_INT64)remoteEndPointAddress[Library_sys_net_native_System_Net_IPAddress::FIELD___address] + .NumericByRef() + .s8; // get value of m_Port field (type int) - port = endPointAddress[ Library_sys_net_native_System_Net_IPEndPoint::FIELD___port ].NumericByRef().s4; + port = endPointAddress[Library_sys_net_native_System_Net_IPEndPoint::FIELD___port].NumericByRef().s4; // clear struct memset(dst, 0, sizeof(SOCK_sockaddr)); - dst->sin_family = SOCK_AF_INET; + dst->sin_family = SOCK_AF_INET; // need to convert port number to network order - dst->sin_port = SOCK_htons(port); + dst->sin_port = SOCK_htons(port); - //address already in network byte order - memcpy((int8_t*)&dst->sin_addr.S_un.S_addr, (int8_t*)&address, sizeof(address)); + // address already in network byte order + memcpy((int8_t *)&dst->sin_addr.S_un.S_addr, (int8_t *)&address, sizeof(address)); addrLenDst = sizeof(address); NANOCLR_NOCLEANUP(); } -HRESULT Library_sys_net_native_System_Net_Sockets_NativeSocket::SendRecvHelper( CLR_RT_StackFrame& stack, bool fSend, bool fAddress ) +HRESULT Library_sys_net_native_System_Net_Sockets_NativeSocket::SendRecvHelper( + CLR_RT_StackFrame &stack, + bool fSend, + bool fAddress) { NATIVE_PROFILE_CLR_NETWORK(); NANOCLR_HEADER(); - CLR_RT_HeapBlock* socket = stack.Arg0().Dereference(); - CLR_INT32 handle; - CLR_RT_HeapBlock_Array* arrData = stack.Arg1().DereferenceArray(); - CLR_UINT32 offset = stack.Arg2().NumericByRef().u4; - CLR_UINT32 count = stack.Arg3().NumericByRef().u4; - CLR_INT32 flags = stack.Arg4().NumericByRef().s4; - CLR_RT_HeapBlock hbTimeout; + CLR_RT_HeapBlock *socket = stack.Arg0().Dereference(); + CLR_INT32 handle; + CLR_RT_HeapBlock_Array *arrData = stack.Arg1().DereferenceArray(); + CLR_UINT32 offset = stack.Arg2().NumericByRef().u4; + CLR_UINT32 count = stack.Arg3().NumericByRef().u4; + CLR_INT32 flags = stack.Arg4().NumericByRef().s4; + CLR_RT_HeapBlock hbTimeout; - CLR_INT64* timeout; - CLR_UINT8* buf; - bool fRes = true; - CLR_INT32 totReadWrite; - CLR_INT32 ret = 0; + CLR_INT64 *timeout; + CLR_UINT8 *buf; + bool fRes = true; + CLR_INT32 totReadWrite; + CLR_INT32 ret = 0; FAULT_ON_NULL(socket); FAULT_ON_NULL(arrData); - - handle = socket[ FIELD__m_Handle ].NumericByRef().s4; + + handle = socket[FIELD__m_Handle].NumericByRef().s4; /* Because we could have been a rescheduled call due to a prior call that would have blocked, we need to see * if our handle has been shutdown before continuing. */ if (handle == DISPOSED_HANDLE) { - ThrowError( stack, CLR_E_OBJECT_DISPOSED ); - NANOCLR_SET_AND_LEAVE (CLR_E_PROCESS_EXCEPTION); + ThrowError(stack, CLR_E_OBJECT_DISPOSED); + NANOCLR_SET_AND_LEAVE(CLR_E_PROCESS_EXCEPTION); } - if(offset + count > arrData->m_numOfElements) NANOCLR_SET_AND_LEAVE(CLR_E_INDEX_OUT_OF_RANGE); + if (offset + count > arrData->m_numOfElements) + NANOCLR_SET_AND_LEAVE(CLR_E_INDEX_OUT_OF_RANGE); // Infinite Timeout // !! need to cast to CLR_INT64 otherwise it wont setup a proper timeout infinite - hbTimeout.SetInteger( (CLR_INT64)-1 ); - NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks( hbTimeout, timeout )); + hbTimeout.SetInteger((CLR_INT64)-1); + NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks(hbTimeout, timeout)); // // Push "totReadWrite" onto the eval stack. // - if(stack.m_customState == 1) + if (stack.m_customState == 1) { - stack.PushValueI4( 0 ); - + stack.PushValueI4(0); + stack.m_customState = 2; } - totReadWrite = stack.m_evalStack[ 1 ].NumericByRef().s4; + totReadWrite = stack.m_evalStack[1].NumericByRef().s4; - buf = arrData->GetElement( offset + totReadWrite ); + buf = arrData->GetElement(offset + totReadWrite); count -= totReadWrite; - while(count > 0) + while (count > 0) { CLR_INT32 bytes = 0; // first make sure we have data to read or ability to write - while(fRes) + while (fRes) { - ret = Helper__SelectSocket( handle, fSend ? 1 : 0 ); + ret = Helper__SelectSocket(handle, fSend ? 1 : 0); - if(ret != 0) break; + if (ret != 0) + break; // non-blocking - allow other threads to run while we wait for handle activity - NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.WaitEvents( stack.m_owningThread, *timeout, CLR_RT_ExecutionEngine::c_Event_Socket, fRes )); + NANOCLR_CHECK_HRESULT( + g_CLR_RT_ExecutionEngine.WaitEvents(stack.m_owningThread, *timeout, Event_Socket, fRes)); } // timeout expired - if(!fRes) + if (!fRes) { ret = SOCK_SOCKET_ERROR; - - ThrowError( stack, SOCK_ETIMEDOUT ); - NANOCLR_SET_AND_LEAVE( CLR_E_PROCESS_EXCEPTION ); + ThrowError(stack, SOCK_ETIMEDOUT); + + NANOCLR_SET_AND_LEAVE(CLR_E_PROCESS_EXCEPTION); } // socket is in the excepted state, so let's bail out - if(SOCK_SOCKET_ERROR == ret) + if (SOCK_SOCKET_ERROR == ret) { break; } - if(fAddress) + if (fAddress) { struct SOCK_sockaddr addr; CLR_UINT32 addrLen = sizeof(addr); - CLR_RT_HeapBlock& blkAddr = stack.Arg6(); + CLR_RT_HeapBlock &blkAddr = stack.Arg6(); - if(fSend) + if (fSend) { - NANOCLR_CHECK_HRESULT(MarshalSockAddress( &addr, addrLen, blkAddr )); + NANOCLR_CHECK_HRESULT(MarshalSockAddress(&addr, addrLen, blkAddr)); - bytes = SOCK_sendto( handle, (const char*)buf, count, flags, &addr, addrLen ); + bytes = SOCK_sendto(handle, (const char *)buf, count, flags, &addr, addrLen); } else { - CLR_RT_HeapBlock* pBlkAddr = blkAddr.Dereference(); - - NANOCLR_CHECK_HRESULT(MarshalSockAddress( &addr, addrLen, *pBlkAddr )); + CLR_RT_HeapBlock *pBlkAddr = blkAddr.Dereference(); - bytes = SOCK_recvfrom( handle, (char*)buf, count, flags, &addr, (int*)&addrLen ); + NANOCLR_CHECK_HRESULT(MarshalSockAddress(&addr, addrLen, *pBlkAddr)); - if(bytes != SOCK_SOCKET_ERROR) + bytes = SOCK_recvfrom(handle, (char *)buf, count, flags, &addr, (int *)&addrLen); + + if (bytes != SOCK_SOCKET_ERROR) { - NANOCLR_CHECK_HRESULT(MarshalSockAddress( blkAddr, &addr, addrLen )); + NANOCLR_CHECK_HRESULT(MarshalSockAddress(blkAddr, &addr, addrLen)); } } } else { - if(fSend) + if (fSend) { - bytes = SOCK_send( handle, (const char*)buf, count, flags ); + bytes = SOCK_send(handle, (const char *)buf, count, flags); } else { - bytes = SOCK_recv( handle, (char*)buf, count, flags ); + bytes = SOCK_recv(handle, (char *)buf, count, flags); } } // send/recv/sendto/recvfrom failed - if(bytes == SOCK_SOCKET_ERROR) + if (bytes == SOCK_SOCKET_ERROR) { CLR_INT32 err = SOCK_getsocklasterror(handle); - - if(err != SOCK_EWOULDBLOCK) + + if (err != SOCK_EWOULDBLOCK) { ret = SOCK_SOCKET_ERROR; break; } - + continue; } - // zero recv bytes indicates the handle has been closed. - else if(!fSend && (bytes == 0)) + // zero recv bytes indicates the handle has been closed. + else if (!fSend && (bytes == 0)) { break; } - - buf += bytes; + + buf += bytes; totReadWrite += bytes; - count -= bytes; + count -= bytes; - stack.m_evalStack[ 1 ].NumericByRef().s4 = totReadWrite; + stack.m_evalStack[1].NumericByRef().s4 = totReadWrite; // receive returns immediately after receiving bytes. - if(!fSend && (totReadWrite > 0)) + if (!fSend && (totReadWrite > 0)) { break; } - } - stack.PopValue(); // totReadWrite - stack.PopValue(); // Timeout - - NANOCLR_CHECK_HRESULT(ThrowOnError( stack, ret )); + stack.PopValue(); // totReadWrite + stack.PopValue(); // Timeout + + NANOCLR_CHECK_HRESULT(ThrowOnError(stack, ret)); - stack.SetResult_I4( totReadWrite ); + stack.SetResult_I4(totReadWrite); NANOCLR_NOCLEANUP(); } -HRESULT Library_sys_net_native_System_Net_Sockets_NativeSocket::SockOptHelper( CLR_RT_StackFrame& stack, bool fGet ) +HRESULT Library_sys_net_native_System_Net_Sockets_NativeSocket::SockOptHelper(CLR_RT_StackFrame &stack, bool fGet) { NATIVE_PROFILE_CLR_NETWORK(); NANOCLR_HEADER(); - CLR_RT_HeapBlock* socket = stack.Arg0().Dereference(); + CLR_RT_HeapBlock *socket = stack.Arg0().Dereference(); CLR_INT32 handle; - CLR_INT32 level = stack.Arg1().NumericByRef().s4; + CLR_INT32 level = stack.Arg1().NumericByRef().s4; CLR_INT32 optname = stack.Arg2().NumericByRef().s4; - CLR_RT_HeapBlock_Array* arrOpt = stack.Arg3().DereferenceArray(); - char* optval; + CLR_RT_HeapBlock_Array *arrOpt = stack.Arg3().DereferenceArray(); + char *optval; CLR_INT32 optlen; CLR_INT32 ret; FAULT_ON_NULL(socket); - handle = socket[ FIELD__m_Handle ].NumericByRef().s4; + handle = socket[FIELD__m_Handle].NumericByRef().s4; FAULT_ON_NULL(arrOpt); - - optval = (char*)arrOpt->GetFirstElement(); + + optval = (char *)arrOpt->GetFirstElement(); optlen = arrOpt->m_numOfElements; - if(fGet) + if (fGet) { - ret = SOCK_getsockopt( handle, level, optname, optval, &optlen ); - _ASSERTE( optlen <= (CLR_INT32)arrOpt->m_numOfElements ); + ret = SOCK_getsockopt(handle, level, optname, optval, &optlen); + _ASSERTE(optlen <= (CLR_INT32)arrOpt->m_numOfElements); } else { - ret = SOCK_setsockopt( handle, level, optname, optval, optlen ); + ret = SOCK_setsockopt(handle, level, optname, optval, optlen); } - NANOCLR_CHECK_HRESULT(ThrowOnError( stack, ret )); + NANOCLR_CHECK_HRESULT(ThrowOnError(stack, ret)); NANOCLR_NOCLEANUP(); } -HRESULT Library_sys_net_native_System_Net_Sockets_NativeSocket::SockNameHelper( CLR_RT_StackFrame& stack, bool fPeer ) +HRESULT Library_sys_net_native_System_Net_Sockets_NativeSocket::SockNameHelper(CLR_RT_StackFrame &stack, bool fPeer) { NATIVE_PROFILE_CLR_NETWORK(); NANOCLR_HEADER(); - CLR_RT_HeapBlock* socket = stack.Arg0().Dereference(); + CLR_RT_HeapBlock *socket = stack.Arg0().Dereference(); CLR_INT32 handle; CLR_INT32 ret; - + struct SOCK_sockaddr addr; CLR_INT32 addrLen = sizeof(addr); FAULT_ON_NULL(socket); - handle = socket[ FIELD__m_Handle ].NumericByRef().s4; + handle = socket[FIELD__m_Handle].NumericByRef().s4; - if(fPeer) + if (fPeer) { - ret = SOCK_getpeername( handle, &addr, &addrLen ); + ret = SOCK_getpeername(handle, &addr, &addrLen); } else { - ret = SOCK_getsockname( handle, &addr, &addrLen ); + ret = SOCK_getsockname(handle, &addr, &addrLen); } - - NANOCLR_CHECK_HRESULT(ThrowOnError( stack, ret )); - NANOCLR_CHECK_HRESULT(MarshalSockAddress( stack.Arg1(), &addr, addrLen )); - + NANOCLR_CHECK_HRESULT(ThrowOnError(stack, ret)); + + NANOCLR_CHECK_HRESULT(MarshalSockAddress(stack.Arg1(), &addr, addrLen)); + NANOCLR_NOCLEANUP(); } -void Library_sys_net_native_System_Net_Sockets_NativeSocket::ThrowError( CLR_RT_StackFrame& stack, CLR_INT32 errorCode ) -{ +void Library_sys_net_native_System_Net_Sockets_NativeSocket::ThrowError(CLR_RT_StackFrame &stack, CLR_INT32 errorCode) +{ NATIVE_PROFILE_CLR_NETWORK(); - CLR_RT_HeapBlock& res = stack.m_owningThread->m_currentException; - - if((Library_corlib_native_System_Exception::CreateInstance( res, g_CLR_RT_WellKnownTypes.m_SocketException, CLR_E_FAIL, &stack )) == S_OK) + CLR_RT_HeapBlock &res = stack.m_owningThread->m_currentException; + + if ((Library_corlib_native_System_Exception::CreateInstance( + res, + g_CLR_RT_WellKnownTypes.m_SocketException, + CLR_E_FAIL, + &stack)) == S_OK) { - res.Dereference()[ Library_sys_net_native_System_Net_Sockets_SocketException::FIELD___errorCode ].SetInteger( errorCode ); + res.Dereference()[Library_sys_net_native_System_Net_Sockets_SocketException::FIELD___errorCode].SetInteger( + errorCode); } } -HRESULT Library_sys_net_native_System_Net_Sockets_NativeSocket::ThrowOnError( CLR_RT_StackFrame& stack, CLR_INT32 res ) -{ +HRESULT Library_sys_net_native_System_Net_Sockets_NativeSocket::ThrowOnError(CLR_RT_StackFrame &stack, CLR_INT32 res) +{ NATIVE_PROFILE_CLR_NETWORK(); NANOCLR_HEADER(); - if(res == SOCK_SOCKET_ERROR) - { + if (res == SOCK_SOCKET_ERROR) + { CLR_INT32 err = SOCK_getlasterror(); - ThrowError( stack, err ); + ThrowError(stack, err); - NANOCLR_SET_AND_LEAVE( CLR_E_PROCESS_EXCEPTION ); + NANOCLR_SET_AND_LEAVE(CLR_E_PROCESS_EXCEPTION); } NANOCLR_NOCLEANUP(); diff --git a/src/DeviceInterfaces/System.Net/sys_net_native_System_Security_Cryptography_X509Certificates_X509Certificate.cpp b/src/DeviceInterfaces/System.Net/sys_net_native_System_Security_Cryptography_X509Certificates_X509Certificate.cpp index 224e1a825d..d6b0caa862 100644 --- a/src/DeviceInterfaces/System.Net/sys_net_native_System_Security_Cryptography_X509Certificates_X509Certificate.cpp +++ b/src/DeviceInterfaces/System.Net/sys_net_native_System_Security_Cryptography_X509Certificates_X509Certificate.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/DeviceInterfaces/System.Net/sys_net_native_System_Security_Cryptography_X509Certificates_X509Certificate2.cpp b/src/DeviceInterfaces/System.Net/sys_net_native_System_Security_Cryptography_X509Certificates_X509Certificate2.cpp index 0ed9c8e4a4..3a139e6e7f 100644 --- a/src/DeviceInterfaces/System.Net/sys_net_native_System_Security_Cryptography_X509Certificates_X509Certificate2.cpp +++ b/src/DeviceInterfaces/System.Net/sys_net_native_System_Security_Cryptography_X509Certificates_X509Certificate2.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/HAL/Include/nanoHAL.h b/src/HAL/Include/nanoHAL.h index 00bfdc3cee..e2a6615f2e 100644 --- a/src/HAL/Include/nanoHAL.h +++ b/src/HAL/Include/nanoHAL.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // @@ -18,19 +18,17 @@ /***************************************************/ // Keep in sync with the nanoCLR_Runtime__HeapBlock.h -#define HAL_FLOAT_SHIFT 10 -#define HAL_FLOAT_PRECISION 1000 +#define HAL_FLOAT_SHIFT 10 +#define HAL_FLOAT_PRECISION 1000 -#define HAL_DOUBLE_SHIFT 16 -#define HAL_DOUBLE_PRECISION 10000 +#define HAL_DOUBLE_SHIFT 16 +#define HAL_DOUBLE_PRECISION 10000 /************************************************/ #else #include #endif - - #include #include #include @@ -58,74 +56,13 @@ #define NATIVE_PROFILE_CLR_IOPORT() #define NATIVE_PROFILE_CLR_IO() - #if defined(_MSC_VER) #define GNU_PACKED - - - - #elif defined(__GNUC__) - -#define GNU_PACKED __attribute__((packed)) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +#define GNU_PACKED __attribute__((packed)) #else !ERROR @@ -133,1572 +70,746 @@ //--// - - - - - - - - - - - - - //--// - - //--// - - - - - - //--// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#define TRANSPORT_SHIFT 8 -#define TRANSPORT_MASK (0xFF << TRANSPORT_SHIFT) -#define PORT_NUMBER_MASK 0x00FF +#define TRANSPORT_SHIFT 8 +#define TRANSPORT_MASK (0xFF << TRANSPORT_SHIFT) +#define PORT_NUMBER_MASK 0x00FF // Macro to extract the transport type from a COM_HANDLE -#define ExtractTransport(x) ((unsigned int)(x) & TRANSPORT_MASK) +#define ExtractTransport(x) ((unsigned int)(x)&TRANSPORT_MASK) // Macro to extract well-known system event flag ids from a COM_HANDLE -#define ExtractEventFromTransport(x) (ExtractTransport(x) == USART_TRANSPORT ? SYSTEM_EVENT_FLAG_COM_IN: \ - ExtractTransport(x) == SOCKET_TRANSPORT ? SYSTEM_EVENT_FLAG_SOCKET: \ - ExtractTransport(x) == GENERIC_TRANSPORT ? SYSTEM_EVENT_FLAG_GENERIC_PORT: \ - ExtractTransport(x) == DEBUG_TRANSPORT ? SYSTEM_EVENT_FLAG_DEBUGGER_ACTIVITY: \ - ExtractTransport(x) == MESSAGING_TRANSPORT ? SYSTEM_EVENT_FLAG_MESSAGING_ACTIVITY: \ - 0) \ - -#define USART_TRANSPORT (1 << TRANSPORT_SHIFT) +#define ExtractEventFromTransport(x) \ + (ExtractTransport(x) == USART_TRANSPORT \ + ? SYSTEM_EVENT_FLAG_COM_IN \ + : ExtractTransport(x) == SOCKET_TRANSPORT \ + ? SYSTEM_EVENT_FLAG_SOCKET \ + : ExtractTransport(x) == GENERIC_TRANSPORT \ + ? SYSTEM_EVENT_FLAG_GENERIC_PORT \ + : ExtractTransport(x) == DEBUG_TRANSPORT \ + ? SYSTEM_EVENT_FLAG_DEBUGGER_ACTIVITY \ + : ExtractTransport(x) == MESSAGING_TRANSPORT ? SYSTEM_EVENT_FLAG_MESSAGING_ACTIVITY : 0) + +#define USART_TRANSPORT (1 << TRANSPORT_SHIFT) //#define COM_NULL ((COM_HANDLE)(USART_TRANSPORT)) -#define USB_TRANSPORT (2 << TRANSPORT_SHIFT) +#define USB_TRANSPORT (2 << TRANSPORT_SHIFT) //#define USB_CONTROLLER_SHIFT 5 //#define USB_CONTROLLER_MASK 0xE0 //#define USB_STREAM_MASK 0x00FF //#define USB_STREAM_INDEX_MASK 0x001F -#define SOCKET_TRANSPORT (3 << TRANSPORT_SHIFT) -#define COM_SOCKET_DBG ((COM_HANDLE)(SOCKET_TRANSPORT + 1)) - -#define DEBUG_TRANSPORT (4 << TRANSPORT_SHIFT) - - - - - - - -#define MESSAGING_TRANSPORT (7 << TRANSPORT_SHIFT) - -#define GENERIC_TRANSPORT (8 << TRANSPORT_SHIFT) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// Creates a COM_HANDLE value for a platform specific port number -#define ConvertCOM_DebugHandle(x) ((COM_HANDLE)((x) + DEBUG_TRANSPORT + 1)) - -// Extracts a Socket transport port id from a SOCKET_TRASNPORT COM_HANDLE -#define ConvertCOM_SockPort(x) (((x) & PORT_NUMBER_MASK) - 1) - -typedef unsigned int FLASH_WORD; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -typedef void (*LOGGING_CALLBACK)(const char* text); - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// //--// - -// //--// - - - - -//--// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -//--// - - - - - - - - - - - - - - -//--// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -template class HAL_DblLinkedList; - -template class HAL_DblLinkedNode -{ - T* m_nextNode; - T* m_prevNode; - - friend class HAL_DblLinkedList; - -public: - void Initialize() - { - m_nextNode = NULL; - m_prevNode = NULL; - } - - T* Next() const { return m_nextNode; } - T* Prev() const { return m_prevNode; } - - void SetNext( T* next ) { m_nextNode = next; } - void SetPrev( T* prev ) { m_prevNode = prev; } - - bool IsLinked() const { return m_nextNode != NULL; } - - //--// - - void RemoveFromList() - { - T* next = m_nextNode; - T* prev = m_prevNode; - - if(prev) prev->m_nextNode = next; - if(next) next->m_prevNode = prev; - } - - void Unlink() - { - T* next = m_nextNode; - T* prev = m_prevNode; - - if(prev) prev->m_nextNode = next; - if(next) next->m_prevNode = prev; - - m_nextNode = NULL; - m_prevNode = NULL; - } -}; - -//--// - -// The use of offsetof below throwns an "invalid offset warning" because CLR_RT_StackFrame is not POD type -// C+17 is the first standard that allow this, so until we are using it we have to disable it to keep GCC happy - -#ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Winvalid-offsetof" -#endif - -template class HAL_DblLinkedList -{ - // - // Logically, a list starts with a HAL_DblLinkedNode with only the Next() set and ends with a node with only Prev() set. - // This can be collapsed to have the two nodes overlap. - // - T* m_first; - T* m_null; - T* m_last; - - //--// - -public: - void Initialize() - { - m_first = Tail(); - m_null = NULL; - m_last = Head(); - } - - int NumOfNodes() - { - T* ptr; - T* ptrNext; - int num = 0; - - for(ptr = FirstNode(); (ptrNext = ptr->Next()) != NULL; ptr = ptrNext) - { - num++; - } - - return num; - } - - //--// - - T* FirstNode() const { return m_first ; } - T* LastNode () const { return m_last ; } - bool IsEmpty () const { return m_first == Tail(); } - - T* FirstValidNode() const { T* res = m_first; return res->Next() ? res : NULL; } - T* LastValidNode () const { T* res = m_last ; return res->Prev() ? res : NULL; } - - T* Head() const { return (T*)((size_t)&m_first - offsetof(T, m_nextNode)); } - T* Tail() const { return (T*)((size_t)&m_last - offsetof(T, m_prevNode)); } - - //--// - -private: - - void Insert( T* prev, T* next, T* node ) - { - node->m_nextNode = next; - node->m_prevNode = prev; - - next->m_prevNode = node; - prev->m_nextNode = node; - } - -public: -#if defined(_DEBUG) - bool Exists( T* searchNode ) - { - T* node = FirstValidNode(); - while( node != NULL && node != searchNode ) - { - if (node == node->Next()) - { - ASSERT(false); - } - node = node->Next(); - } - return (node == NULL? false: true); - } -#endif - - void InsertBeforeNode( T* node, T* nodeNew ) - { - if(node && nodeNew && node != nodeNew) - { - nodeNew->RemoveFromList(); - - Insert( node->Prev(), node, nodeNew ); - } - } - - void InsertAfterNode( T* node, T* nodeNew ) - { - if(node && nodeNew && node != nodeNew) - { - nodeNew->RemoveFromList(); - - Insert( node, node->Next(), nodeNew ); - } - } - - void LinkAtFront( T* node ) - { - InsertAfterNode( Head(), node ); - } - - void LinkAtBack( T* node ) - { - InsertBeforeNode( Tail(), node ); - } - - T* ExtractFirstNode() - { - T* node = FirstValidNode(); - - if(node) node->Unlink(); - - return node; - } - - T* ExtractLastNode() - { - T* node = LastValidNode(); - - if(node) node->Unlink(); - - return node; - } -}; - -#ifdef __GNUC__ -#pragma GCC diagnostic pop -#endif - -//--// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -template class Hal_Queue_UnknownSize -{ - size_t m_writer; - size_t m_reader; - size_t m_size; - bool m_full; - T* m_data; - -public: - void Initialize( T* data, size_t size ) - { - m_writer = 0; - m_reader = 0; - m_size = size; - m_data = data; - m_full = false; - } - - size_t NumberOfElements() - { - if(m_writer < m_reader) return m_size + m_writer - m_reader; - else if(m_full) return m_size; - else return m_writer - m_reader; - } - - bool IsEmpty() - { - return (m_writer == m_reader && !m_full); - } - - bool IsFull() - { - return m_full; - } - - T* operator[](int index) - { - if(index < 0 || index >= NumberOfElements()) return NULL; - - return &m_data[(m_reader + index) % m_size]; - } - - T* Push() - { - size_t oldWriter = m_writer; - - if(m_full) return NULL; - - m_writer++; if(m_writer == m_size) m_writer = 0; - - if(m_writer == m_reader) m_full = true; - - return &m_data[oldWriter]; - } - - T* Peek() - { - if(m_writer == m_reader && !m_full) return NULL; - - return &m_data[m_reader]; - } - - T* Pop() - { - size_t oldReader = m_reader; - - if(m_reader == m_writer && !m_full) return (T*)NULL; - - m_reader++; if(m_reader == m_size) m_reader = 0; - - m_full = false; - - return &m_data[oldReader]; - } - - T* Push( size_t &nElements ) - { - size_t oldWriter = m_writer; - size_t max = 0; - - if(m_full || (nElements == 0)) - { - nElements = 0; - return NULL; - } - - if(m_writer < m_reader) max = m_reader - m_writer; - else max = m_size - m_writer; - - nElements = (max < nElements? max: nElements); - - m_writer += nElements; if(m_writer == m_size) m_writer = 0; - - if(m_writer == m_reader) m_full = true; - - return &m_data[oldWriter]; - } - - T* Pop( size_t &nElements ) - { - size_t oldReader = m_reader; - size_t max = 0; - - if(nElements == 0) return NULL; - - if((m_reader == m_writer) && !m_full) - { - nElements = 0; - // reset the reader/writer to maximize push potential - m_reader = 0; - m_writer = 0; - return NULL; - } - - if(m_writer <= m_reader) max = m_size - m_reader; - else max = m_writer - m_reader; - - nElements = (max < nElements? max: nElements); - - m_reader += nElements; if(m_reader == m_size) m_reader = 0; - - m_full = false; - - return &m_data[oldReader]; - } - - T* Storage() { return m_data; } -}; - -template class HAL_RingBuffer -{ - size_t _dataSize; - size_t _size; - size_t _capacity; - size_t _write_index; - size_t _read_index; - T * _buffer; - -public: - - void Initialize(T* data, size_t size) - { - _dataSize = sizeof(T); - - _capacity = (size * _dataSize); - _write_index = 0; - _read_index = 0; - _size = 0; - - _buffer = data; - } - - size_t Capacity() { return (_capacity / _dataSize); } - - size_t Length() { return (_size / _dataSize); } - - // Push a single element to the buffer. - size_t Push(const T data) - { - // check for buffer full - if(_size == _capacity) - { - // buffer full - return 0; - } - - T* destination = _buffer; - destination += _write_index; - - *destination = data; - _write_index += _dataSize; - - // check if we are the end of the capacity - if (_write_index == _capacity) _write_index = 0; - - // update ring buffer size - _size += _dataSize; - - return 1; - } - - // Push N elements to the buffer. - size_t Push(const T* data, size_t length) - { - size_t lengthToWrite = 0; - - // sanity check for 0 length - if (length == 0) return 0; - - // check for buffer full - if(_size == _capacity) - { - // buffer full - return 0; - } - - if( (length * _dataSize) < (_capacity - _size)) - { - lengthToWrite = (length * _dataSize); - } - else - { - lengthToWrite = (_capacity - _size); - } - - // single memcpy - if (lengthToWrite <= _capacity - _write_index) - { - memcpy(_buffer + _write_index, data, lengthToWrite); - _write_index += lengthToWrite; - - // check if we are the end of the capacity - if (_write_index == _capacity) _write_index = 0; - } - // need to memcpy in two chunks - else - { - size_t chunk1Size = _capacity - _write_index; - memcpy(_buffer + _write_index, data, chunk1Size); - - size_t chunk2Size = lengthToWrite - chunk1Size; - memcpy(_buffer, data + chunk1Size, chunk2Size); - - _write_index = chunk2Size; - } - - // update ring buffer size - _size += lengthToWrite; - - return (lengthToWrite / _dataSize); - } - - // Pop N elements from ring buffer returning them in the data argument. - size_t Pop(T* data, size_t length) - { - size_t lengthToRead = 0; - - // sanity check for 0 length - if (length == 0) return 0; - - // check for buffer empty - if(_size == 0) - { - return 0; - } - - lengthToRead = (length * _dataSize); - - // can read in a single memcpy - if (lengthToRead <= _capacity - _read_index) - { - memcpy(data, _buffer + _read_index, lengthToRead); - _read_index += lengthToRead; - - // check if we are at end of capacity - if (_read_index == _capacity) _read_index = 0; - } - // need to memcpy in two steps - else - { - size_t chunk1Size = _capacity - _read_index; - memcpy(data, _buffer + _read_index, chunk1Size); - - size_t chunk2Size = lengthToRead - chunk1Size; - memcpy(data + chunk1Size, _buffer, chunk2Size); - - _read_index = chunk2Size; - } - - // update ring buffer size - _size -= lengthToRead; - - // check for optimization to improve sequential push - // buffer has to be empty and read and write indexes coincide - if(_size == 0 && (_write_index == _read_index)) - { - // reset the read/write index - _write_index = 0; - _read_index = 0; - } - - return (lengthToRead / _dataSize); - } - - // Pop N elements from ring buffer. The elements are not actually returned, just popped from the buffer. - size_t Pop(size_t length) - { - size_t lengthToRead = 0; - - // sanity check for 0 length - if (length == 0) return 0; - - // check for buffer empty - if(_size == 0) - { - return 0; - } - - lengthToRead = (length * _dataSize); - - // can read in a single memcpy - if (lengthToRead <= _capacity - _read_index) - { - _read_index += lengthToRead; - - // check if we are at end of capacity - if (_read_index == _capacity) _read_index = 0; - } - // need to memcpy in two steps - else - { - size_t chunk1Size = _capacity - _read_index; - size_t chunk2Size = lengthToRead - chunk1Size; - _read_index = chunk2Size; - } - - // update ring buffer size - _size -= lengthToRead; - - // check for optimization to improve sequential push - // buffer has to be empty and read and write indexes coincide - if(_size == 0 && (_write_index == _read_index)) - { - // reset the read/write index - _write_index = 0; - _read_index = 0; - } - - return (lengthToRead / _dataSize); - } - - void OptimizeSequence() - { - // no elements, so there is nothing to optimize - if(_size == 0) return; - - // read index is already at index 0, so there is nothing to optimize - if(_read_index == 0) return; - - // can move data in a single memcpy - if (_read_index < _write_index) - { - // buffer looks like this - // |...xxxxx.....| - memcpy(_buffer, _buffer + _read_index, _size); - } - // need to move data in two steps - else - { - // buffer looks like this - // |xxxx......xxxxxx| - - // store size of tail - size_t tailSize = _write_index - (1 * _dataSize); - - // 1st move tail to temp buffer (need to malloc first) - T* tempBuffer = (T*)platform_malloc(tailSize); - - memcpy(tempBuffer, _buffer, tailSize); - - // store size of remaining buffer - size_t headSize = _capacity - _read_index; - - // 2nd move head to start of buffer - memcpy(_buffer, _buffer + _read_index, headSize); - - // 3rd move temp buffer after head - memcpy(_buffer + headSize, tempBuffer, tailSize); - - // free memory - platform_free(tempBuffer); - } - - // adjust indexes - _read_index = 0; - _write_index = _size; - } - - T* Reader() { return _buffer + _read_index; } -}; - -//--// - -//#include <..\Initialization\MasterConfig.h> - - - - - - -//--// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// hal cleanup for CLR reboot - -void nanoHAL_Initialize(); -void nanoHAL_Uninitialize(); - -void HAL_EnterBooterMode(); - -typedef void (*ON_SOFT_REBOOT_HANDLER)(void); - -void HAL_AddSoftRebootHandler(ON_SOFT_REBOOT_HANDLER handler); - -//--// - - - - - - - - - - - - - - - - - -//--// - - - -//--// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +#define SOCKET_TRANSPORT (3 << TRANSPORT_SHIFT) +#define COM_SOCKET_DBG ((COM_HANDLE)(SOCKET_TRANSPORT + 1)) +#define DEBUG_TRANSPORT (4 << TRANSPORT_SHIFT) +#define MESSAGING_TRANSPORT (7 << TRANSPORT_SHIFT) +#define GENERIC_TRANSPORT (8 << TRANSPORT_SHIFT) +// Creates a COM_HANDLE value for a platform specific port number +#define ConvertCOM_DebugHandle(x) ((COM_HANDLE)((x) + DEBUG_TRANSPORT + 1)) +// Extracts a Socket transport port id from a SOCKET_TRASNPORT COM_HANDLE +#define ConvertCOM_SockPort(x) (((x)&PORT_NUMBER_MASK) - 1) +typedef unsigned int FLASH_WORD; +typedef void (*LOGGING_CALLBACK)(const char *text); +// //--// +// //--// +//--// +//--// +//--// +template class HAL_DblLinkedList; +template class HAL_DblLinkedNode +{ + T *m_nextNode; + T *m_prevNode; + friend class HAL_DblLinkedList; + public: + void Initialize() + { + m_nextNode = NULL; + m_prevNode = NULL; + } + T *Next() const + { + return m_nextNode; + } + T *Prev() const + { + return m_prevNode; + } + void SetNext(T *next) + { + m_nextNode = next; + } + void SetPrev(T *prev) + { + m_prevNode = prev; + } + bool IsLinked() const + { + return m_nextNode != NULL; + } + //--// + void RemoveFromList() + { + T *next = m_nextNode; + T *prev = m_prevNode; + if (prev) + prev->m_nextNode = next; + if (next) + next->m_prevNode = prev; + } + void Unlink() + { + T *next = m_nextNode; + T *prev = m_prevNode; + if (prev) + prev->m_nextNode = next; + if (next) + next->m_prevNode = prev; + m_nextNode = NULL; + m_prevNode = NULL; + } +}; +//--// +// The use of offsetof below throwns an "invalid offset warning" because CLR_RT_StackFrame is not POD type +// C+17 is the first standard that allow this, so until we are using it we have to disable it to keep GCC happy +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Winvalid-offsetof" +#endif +template class HAL_DblLinkedList +{ + // + // Logically, a list starts with a HAL_DblLinkedNode with only the Next() set and ends with a node with only Prev() + // set. This can be collapsed to have the two nodes overlap. + // + T *m_first; + T *m_null; + T *m_last; + //--// + public: + void Initialize() + { + m_first = Tail(); + m_null = NULL; + m_last = Head(); + } + int NumOfNodes() + { + T *ptr; + T *ptrNext; + int num = 0; + for (ptr = FirstNode(); (ptrNext = ptr->Next()) != NULL; ptr = ptrNext) + { + num++; + } + return num; + } + //--// + T *FirstNode() const + { + return m_first; + } + T *LastNode() const + { + return m_last; + } + bool IsEmpty() const + { + return m_first == Tail(); + } + T *FirstValidNode() const + { + T *res = m_first; + return res->Next() ? res : NULL; + } + T *LastValidNode() const + { + T *res = m_last; + return res->Prev() ? res : NULL; + } + T *Head() const + { + return (T *)((size_t)&m_first - offsetof(T, m_nextNode)); + } + T *Tail() const + { + return (T *)((size_t)&m_last - offsetof(T, m_prevNode)); + } + //--// + private: + void Insert(T *prev, T *next, T *node) + { + node->m_nextNode = next; + node->m_prevNode = prev; + next->m_prevNode = node; + prev->m_nextNode = node; + } + public: +#if defined(_DEBUG) + bool Exists(T *searchNode) + { + T *node = FirstValidNode(); + while (node != NULL && node != searchNode) + { + if (node == node->Next()) + { + ASSERT(false); + } + node = node->Next(); + } + return (node == NULL ? false : true); + } +#endif + void InsertBeforeNode(T *node, T *nodeNew) + { + if (node && nodeNew && node != nodeNew) + { + nodeNew->RemoveFromList(); + Insert(node->Prev(), node, nodeNew); + } + } + void InsertAfterNode(T *node, T *nodeNew) + { + if (node && nodeNew && node != nodeNew) + { + nodeNew->RemoveFromList(); + Insert(node, node->Next(), nodeNew); + } + } + void LinkAtFront(T *node) + { + InsertAfterNode(Head(), node); + } + void LinkAtBack(T *node) + { + InsertBeforeNode(Tail(), node); + } + T *ExtractFirstNode() + { + T *node = FirstValidNode(); + if (node) + node->Unlink(); + return node; + } + T *ExtractLastNode() + { + T *node = LastValidNode(); + if (node) + node->Unlink(); + return node; + } +}; +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif +//--// +template class Hal_Queue_UnknownSize +{ + size_t m_writer; + size_t m_reader; + size_t m_size; + bool m_full; + T *m_data; + public: + void Initialize(T *data, size_t size) + { + m_writer = 0; + m_reader = 0; + m_size = size; + m_data = data; + m_full = false; + } + size_t NumberOfElements() + { + if (m_writer < m_reader) + return m_size + m_writer - m_reader; + else if (m_full) + return m_size; + else + return m_writer - m_reader; + } + bool IsEmpty() + { + return (m_writer == m_reader && !m_full); + } + bool IsFull() + { + return m_full; + } + T *operator[](int index) + { + if (index < 0 || index >= NumberOfElements()) + return NULL; + return &m_data[(m_reader + index) % m_size]; + } + T *Push() + { + size_t oldWriter = m_writer; + if (m_full) + return NULL; + m_writer++; + if (m_writer == m_size) + m_writer = 0; + if (m_writer == m_reader) + m_full = true; + return &m_data[oldWriter]; + } + T *Peek() + { + if (m_writer == m_reader && !m_full) + return NULL; + return &m_data[m_reader]; + } + T *Pop() + { + size_t oldReader = m_reader; + if (m_reader == m_writer && !m_full) + return (T *)NULL; + m_reader++; + if (m_reader == m_size) + m_reader = 0; + m_full = false; + return &m_data[oldReader]; + } + T *Push(size_t &nElements) + { + size_t oldWriter = m_writer; + size_t max = 0; + if (m_full || (nElements == 0)) + { + nElements = 0; + return NULL; + } + if (m_writer < m_reader) + max = m_reader - m_writer; + else + max = m_size - m_writer; + nElements = (max < nElements ? max : nElements); + m_writer += nElements; + if (m_writer == m_size) + m_writer = 0; + if (m_writer == m_reader) + m_full = true; + return &m_data[oldWriter]; + } + T *Pop(size_t &nElements) + { + size_t oldReader = m_reader; + size_t max = 0; + if (nElements == 0) + return NULL; + if ((m_reader == m_writer) && !m_full) + { + nElements = 0; + // reset the reader/writer to maximize push potential + m_reader = 0; + m_writer = 0; + return NULL; + } + if (m_writer <= m_reader) + max = m_size - m_reader; + else + max = m_writer - m_reader; + nElements = (max < nElements ? max : nElements); + m_reader += nElements; + if (m_reader == m_size) + m_reader = 0; + m_full = false; + return &m_data[oldReader]; + } + T *Storage() + { + return m_data; + } +}; +template class HAL_RingBuffer +{ + size_t _dataSize; + size_t _size; + size_t _capacity; + size_t _write_index; + size_t _read_index; + T *_buffer; + public: + void Initialize(T *data, size_t size) + { + _dataSize = sizeof(T); + _capacity = (size * _dataSize); + _write_index = 0; + _read_index = 0; + _size = 0; + _buffer = data; + } + size_t Capacity() + { + return (_capacity / _dataSize); + } + size_t Length() + { + return (_size / _dataSize); + } + // Push a single element to the buffer. + size_t Push(const T data) + { + // check for buffer full + if (_size == _capacity) + { + // buffer full + return 0; + } + T *destination = _buffer; + destination += _write_index; + *destination = data; + _write_index += _dataSize; + // check if we are the end of the capacity + if (_write_index == _capacity) + _write_index = 0; + // update ring buffer size + _size += _dataSize; + return 1; + } + // Push N elements to the buffer. + size_t Push(const T *data, size_t length) + { + size_t lengthToWrite = 0; + // sanity check for 0 length + if (length == 0) + return 0; + // check for buffer full + if (_size == _capacity) + { + // buffer full + return 0; + } + if ((length * _dataSize) < (_capacity - _size)) + { + lengthToWrite = (length * _dataSize); + } + else + { + lengthToWrite = (_capacity - _size); + } + // single memcpy + if (lengthToWrite <= _capacity - _write_index) + { + memcpy(_buffer + _write_index, data, lengthToWrite); + _write_index += lengthToWrite; + // check if we are the end of the capacity + if (_write_index == _capacity) + _write_index = 0; + } + // need to memcpy in two chunks + else + { + size_t chunk1Size = _capacity - _write_index; + memcpy(_buffer + _write_index, data, chunk1Size); + size_t chunk2Size = lengthToWrite - chunk1Size; + memcpy(_buffer, data + chunk1Size, chunk2Size); + _write_index = chunk2Size; + } + // update ring buffer size + _size += lengthToWrite; + return (lengthToWrite / _dataSize); + } + // Pop N elements from ring buffer returning them in the data argument. + size_t Pop(T *data, size_t length) + { + size_t lengthToRead = 0; + // sanity check for 0 length + if (length == 0) + return 0; + // check for buffer empty + if (_size == 0) + { + return 0; + } + lengthToRead = (length * _dataSize); + // can read in a single memcpy + if (lengthToRead <= _capacity - _read_index) + { + memcpy(data, _buffer + _read_index, lengthToRead); + _read_index += lengthToRead; + // check if we are at end of capacity + if (_read_index == _capacity) + _read_index = 0; + } + // need to memcpy in two steps + else + { + size_t chunk1Size = _capacity - _read_index; + memcpy(data, _buffer + _read_index, chunk1Size); + size_t chunk2Size = lengthToRead - chunk1Size; + memcpy(data + chunk1Size, _buffer, chunk2Size); + _read_index = chunk2Size; + } + // update ring buffer size + _size -= lengthToRead; + // check for optimization to improve sequential push + // buffer has to be empty and read and write indexes coincide + if (_size == 0 && (_write_index == _read_index)) + { + // reset the read/write index + _write_index = 0; + _read_index = 0; + } + return (lengthToRead / _dataSize); + } + // Pop N elements from ring buffer. The elements are not actually returned, just popped from the buffer. + size_t Pop(size_t length) + { + size_t lengthToRead = 0; + // sanity check for 0 length + if (length == 0) + return 0; + // check for buffer empty + if (_size == 0) + { + return 0; + } + lengthToRead = (length * _dataSize); + // can read in a single memcpy + if (lengthToRead <= _capacity - _read_index) + { + _read_index += lengthToRead; + // check if we are at end of capacity + if (_read_index == _capacity) + _read_index = 0; + } + // need to memcpy in two steps + else + { + size_t chunk1Size = _capacity - _read_index; + size_t chunk2Size = lengthToRead - chunk1Size; + _read_index = chunk2Size; + } + // update ring buffer size + _size -= lengthToRead; + // check for optimization to improve sequential push + // buffer has to be empty and read and write indexes coincide + if (_size == 0 && (_write_index == _read_index)) + { + // reset the read/write index + _write_index = 0; + _read_index = 0; + } + return (lengthToRead / _dataSize); + } + void OptimizeSequence() + { + // no elements, so there is nothing to optimize + if (_size == 0) + return; + // read index is already at index 0, so there is nothing to optimize + if (_read_index == 0) + return; + // can move data in a single memcpy + if (_read_index < _write_index) + { + // buffer looks like this + // |...xxxxx.....| + memcpy(_buffer, _buffer + _read_index, _size); + } + // need to move data in two steps + else + { + // buffer looks like this + // |xxxx......xxxxxx| + // store size of tail + size_t tailSize = _write_index - (1 * _dataSize); + // 1st move tail to temp buffer (need to malloc first) + T *tempBuffer = (T *)platform_malloc(tailSize); + memcpy(tempBuffer, _buffer, tailSize); + // store size of remaining buffer + size_t headSize = _capacity - _read_index; + // 2nd move head to start of buffer + memcpy(_buffer, _buffer + _read_index, headSize); + // 3rd move temp buffer after head + memcpy(_buffer + headSize, tempBuffer, tailSize); + // free memory + platform_free(tempBuffer); + } + // adjust indexes + _read_index = 0; + _write_index = _size; + } + T *Reader() + { + return _buffer + _read_index; + } +}; +//--// +//#include <..\Initialization\MasterConfig.h> +//--// +// hal cleanup for CLR reboot +void nanoHAL_Initialize(); +void nanoHAL_Uninitialize(); +void HAL_EnterBooterMode(); +typedef void (*ON_SOFT_REBOOT_HANDLER)(void); +void HAL_AddSoftRebootHandler(ON_SOFT_REBOOT_HANDLER handler); +//--// +//--// +//--// //--// @@ -1727,30 +838,13 @@ extern bool g_fDoNotUninitializeDebuggerPort; //// Gp I/O driver //#include // -//// Gp I/O driver +// Gp I/O driver #include -// - - - - - - - - - - - - - - - - - // -//// SPI driver -//#include +// SPI driver +#include + // //// External bus interface driver //#include @@ -1773,8 +867,6 @@ extern bool g_fDoNotUninitializeDebuggerPort; //// Power API //#include - - // // Chipset // @@ -1782,7 +874,6 @@ extern bool g_fDoNotUninitializeDebuggerPort; //#include - // platform_selector.h (from MasterConfig.h) #if defined(_WIN32) @@ -1791,15 +882,15 @@ extern bool g_fDoNotUninitializeDebuggerPort; #define GLOBAL_UNLOCK() #if defined(_DEBUG) -#define ASSERT_IRQ_MUST_BE_ON() ASSERT(!HAL_Windows_HasGlobalLock()) +#define ASSERT_IRQ_MUST_BE_ON() ASSERT(!HAL_Windows_HasGlobalLock()) #else #define ASSERT_IRQ_MUST_BE_ON() #endif -#elif defined(__arm__) | defined(PLATFORM_ESP32) +#elif defined(__arm__) | defined(PLATFORM_ESP32) // nothing to define here just to help the nanoCLR VS project to build hapilly #else #error Unsupported platform #endif -#endif // _NANOHAL_H_ +#endif // _NANOHAL_H_ diff --git a/src/HAL/Include/nanoHAL_ConfigurationManager.h b/src/HAL/Include/nanoHAL_ConfigurationManager.h index 1ee4f8d399..a6b483c155 100644 --- a/src/HAL/Include/nanoHAL_ConfigurationManager.h +++ b/src/HAL/Include/nanoHAL_ConfigurationManager.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/src/HAL/Include/nanoHAL_Network.h b/src/HAL/Include/nanoHAL_Network.h index b1697639f7..26c888eff8 100644 --- a/src/HAL/Include/nanoHAL_Network.h +++ b/src/HAL/Include/nanoHAL_Network.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/src/HAL/Include/nanoHAL_Power.h b/src/HAL/Include/nanoHAL_Power.h index e8e6a2bc8b..77306c96b1 100644 --- a/src/HAL/Include/nanoHAL_Power.h +++ b/src/HAL/Include/nanoHAL_Power.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/src/HAL/Include/nanoHAL_ReleaseInfo.h b/src/HAL/Include/nanoHAL_ReleaseInfo.h index 248b5c3e17..2e0ce7c46e 100644 --- a/src/HAL/Include/nanoHAL_ReleaseInfo.h +++ b/src/HAL/Include/nanoHAL_ReleaseInfo.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/HAL/Include/nanoHAL_Spi.h b/src/HAL/Include/nanoHAL_Spi.h new file mode 100644 index 0000000000..e2b4f8e69f --- /dev/null +++ b/src/HAL/Include/nanoHAL_Spi.h @@ -0,0 +1,86 @@ +// +// Copyright (c) .NET Foundation and Contributors +// Portions Copyright (c) Microsoft Corporation. All rights reserved. +// See LICENSE file in the project root for full license information. +// + +#ifndef _NANOHAL_SPI_H_ +#define _NANOHAL_SPI_H_ 1 + +#include "TargetHAL_Spi.h" + +#include "CPU_SPI_decl.h" + +// Global SPI handle type +#define CPU_DEVICE_TYPE_SPI 1 + +struct nanoSPI_BusConfig +{ + bool spiBusInited; + int8_t devicesInUse; + SPI_DEVICE_CONFIGURATION deviceCongfig[MAX_SPI_DEVICES]; + uint32_t deviceHandles[MAX_SPI_DEVICES]; + float byteTime[MAX_SPI_DEVICES]; + SPI_OP_STATUS spiStatus; +}; + +// Called on CLR startup +bool nanoSPI_Initialize(); + +// Called on CLR closedown +void nanoSPI_Uninitialize(); + +// HAL Access layer + +// Open SPI bus / device using device configuration +// Register GPIO pins as in use +// Return result, if S_OK then handle returned in handle +HRESULT nanoSPI_OpenDevice(SPI_DEVICE_CONFIGURATION &Configuration, uint32_t &handle); + +// Specify alternate pins or -1 for default, Needed ? +// only possible of first device open +HRESULT nanoSPI_OpenDeviceEx( + SPI_DEVICE_CONFIGURATION &Configuration, + uint32_t &handle, + GPIO_PIN altMsk, + GPIO_PIN altMiso, + GPIO_PIN altMosi); + +// Close SPI device +// When last device closed bus is closed +HRESULT nanoSPI_CloseDevice(uint32_t handle); + +// Return the time in ms for a byte transfer +float nanoSPI_GetByteTime(uint32_t handle); + +// Execute a SPI write/read operation +// if callback is null the operation will completed as part of the call +// if callback is not null then the job will be queued and the callback called when completed +// return status of operation +// >0 = operation Id +// 0=ok completed (null callback) +// -1 = SPI error (null callback) +// -2 = Unable to queue operation( queue full ) +HRESULT nanoSPI_Write_Read( + uint32_t handle, + SPI_WRITE_READ_SETTINGS &settings, + uint8_t *writeData, + int32_t writeSize, + uint8_t *readData, + int32_t readSize); + +// Return status of last async operation +SPI_OP_STATUS nanoSPI_Op_Status(uint32_t handle); + +// Start a read / write spi job +// result = -1 Busy ( wait for bus to be released ) +// callback called on job completion +HRESULT nanoSPI_start_nWrite_nRead( + uint32_t handle, + SPI_WRITE_READ_SETTINGS &settings, + uint8_t *writeData, + int32_t writeSize, + uint8_t *readData, + int32_t readSize); + +#endif // _NANOHAL_SPI_H_ diff --git a/src/HAL/Include/nanoHAL_Time.h b/src/HAL/Include/nanoHAL_Time.h index bb6b67ab49..70ef264092 100644 --- a/src/HAL/Include/nanoHAL_Time.h +++ b/src/HAL/Include/nanoHAL_Time.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/HAL/Include/nanoHAL_Types.h b/src/HAL/Include/nanoHAL_Types.h index 6b181898b8..607a49cb23 100644 --- a/src/HAL/Include/nanoHAL_Types.h +++ b/src/HAL/Include/nanoHAL_Types.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/HAL/Include/nanoHAL_Watchdog.h b/src/HAL/Include/nanoHAL_Watchdog.h index 895564bc51..814f8f5ad6 100644 --- a/src/HAL/Include/nanoHAL_Watchdog.h +++ b/src/HAL/Include/nanoHAL_Watchdog.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/HAL/Include/nanoHAL_Windows_Storage.h b/src/HAL/Include/nanoHAL_Windows_Storage.h index d5cd01e6ff..43a5a20b62 100644 --- a/src/HAL/Include/nanoHAL_Windows_Storage.h +++ b/src/HAL/Include/nanoHAL_Windows_Storage.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // #ifndef _NANOHAL_WINDOWS_STORAGE_H_ diff --git a/src/HAL/Include/nanoHAL_v2.h b/src/HAL/Include/nanoHAL_v2.h index ac08c90b04..0e8a6942c9 100644 --- a/src/HAL/Include/nanoHAL_v2.h +++ b/src/HAL/Include/nanoHAL_v2.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // @@ -30,31 +30,31 @@ typedef enum SYSTEM_STATE ////////////////////////////////////////////////////////////////// typedef enum SLEEP_LEVEL { - SLEEP_LEVEL__AWAKE = 0x00, + SLEEP_LEVEL__AWAKE = 0x00, SLEEP_LEVEL__SELECTIVE_OFF = 0x10, - SLEEP_LEVEL__SLEEP = 0x20, - SLEEP_LEVEL__DEEP_SLEEP = 0x30, - SLEEP_LEVEL__OFF = 0x40, + SLEEP_LEVEL__SLEEP = 0x20, + SLEEP_LEVEL__DEEP_SLEEP = 0x30, + SLEEP_LEVEL__OFF = 0x40, } SLEEP_LEVEL_type; -//These events match emulator events in Framework\Tools\Emulator\Events.cs +// These events match emulator events in Framework\Tools\Emulator\Events.cs -#define SYSTEM_EVENT_FLAG_COM_IN 0x00000001 -#define SYSTEM_EVENT_FLAG_COM_OUT 0x00000002 -#define SYSTEM_EVENT_FLAG_STORAGE_IO 0x00000004 -#define SYSTEM_EVENT_FLAG_SYSTEM_TIMER 0x00000010 +#define SYSTEM_EVENT_FLAG_COM_IN 0x00000001 +#define SYSTEM_EVENT_FLAG_COM_OUT 0x00000002 +#define SYSTEM_EVENT_FLAG_STORAGE_IO 0x00000004 +#define SYSTEM_EVENT_FLAG_SYSTEM_TIMER 0x00000010 //#define SYSTEM_EVENT_FLAG_TIMER1 0x00000020 //#define SYSTEM_EVENT_FLAG_TIMER2 0x00000040 //#define SYSTEM_EVENT_FLAG_BUTTON 0x00000080 -#define SYSTEM_EVENT_FLAG_GENERIC_PORT 0x00000100 +#define SYSTEM_EVENT_FLAG_GENERIC_PORT 0x00000100 //#define SYSTEM_EVENT_FLAG_UNUSED_0x00000200 0x00000200 //#define SYSTEM_EVENT_FLAG_UNUSED_0x00000400 0x00000400 -#define SYSTEM_EVENT_FLAG_NETWORK 0x00000800 +#define SYSTEM_EVENT_FLAG_NETWORK 0x00000800 //#define SYSTEM_EVENT_FLAG_TONE_COMPLETE 0x00001000 //#define SYSTEM_EVENT_FLAG_TONE_BUFFER_EMPTY 0x00002000 -#define SYSTEM_EVENT_FLAG_SOCKET 0x00004000 -#define SYSTEM_EVENT_FLAG_ONEWIRE_MASTER 0x00008000 -#define SYSTEM_EVENT_FLAG_RADIO 0x00010000 +#define SYSTEM_EVENT_FLAG_SOCKET 0x00004000 +#define SYSTEM_EVENT_FLAG_ONEWIRE_MASTER 0x00008000 +#define SYSTEM_EVENT_FLAG_RADIO 0x00010000 //#define SYSTEM_EVENT_FLAG_SPI 0x00008000 //#define SYSTEM_EVENT_FLAG_OEM_RESERVED_1 0x00020000 @@ -62,38 +62,35 @@ typedef enum SLEEP_LEVEL //#define SYSTEM_EVENT_FLAG_UNUSED_0x00080000 0x00080000 //#define SYSTEM_EVENT_FLAG_UNUSED_0x00100000 0x00100000 - //#define SYSTEM_EVENT_FLAG_UNUSED_0x00200000 0x00200000 //#define SYSTEM_EVENT_FLAG_UNUSED_0x00400000 0x00400000 //#define SYSTEM_EVENT_FLAG_UNUSED_0x00800000 0x00800000 //#define SYSTEM_EVENT_FLAG_UNUSED_0x01000000 0x01000000 -#define SYSTEM_EVENT_FLAG_SPI_MASTER 0x02000000 -#define SYSTEM_EVENT_FLAG_I2C_MASTER 0x04000000 -#define SYSTEM_EVENT_HW_INTERRUPT 0x08000000 -#define SYSTEM_EVENT_FLAG_DEBUGGER_ACTIVITY 0x20000000 -#define SYSTEM_EVENT_FLAG_MESSAGING_ACTIVITY 0x40000000 +#define SYSTEM_EVENT_FLAG_SPI_MASTER 0x02000000 +#define SYSTEM_EVENT_FLAG_I2C_MASTER 0x04000000 +#define SYSTEM_EVENT_HW_INTERRUPT 0x08000000 +#define SYSTEM_EVENT_FLAG_DEBUGGER_ACTIVITY 0x20000000 +#define SYSTEM_EVENT_FLAG_MESSAGING_ACTIVITY 0x40000000 //#define SYSTEM_EVENT_FLAG_UNUSED_0x80000000 0x80000000 -#define SYSTEM_EVENT_FLAG_ALL 0xFFFFFFFF - +#define SYSTEM_EVENT_FLAG_ALL 0xFFFFFFFF //////////////////////////////////////////////////////////////////////////////////////////// // !!! KEEP IN SYNC WITH nanoFramework.Runtime.Events.EventCategory (in managed code) !!! // //////////////////////////////////////////////////////////////////////////////////////////// -#define EVENT_UNKNOWN 0 -#define EVENT_CUSTOM 10 -#define EVENT_GPIO 20 -#define EVENT_SERIAL 30 -#define EVENT_NETWORK 40 -#define EVENT_WIFI 50 -#define EVENT_CAN 60 -#define EVENT_STORAGE 70 -#define EVENT_RADIO 80 +#define EVENT_UNKNOWN 0 +#define EVENT_CUSTOM 10 +#define EVENT_GPIO 20 +#define EVENT_SERIAL 30 +#define EVENT_NETWORK 40 +#define EVENT_WIFI 50 +#define EVENT_CAN 60 +#define EVENT_STORAGE 70 +#define EVENT_RADIO 80 //////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////// - // COM_HANDLE Defines a type representing both a port type or "transport" and a port number // The COM_HANDLE is a multi bit field value with the following bit fields usage // |--------+--------+--------+--------| @@ -104,7 +101,7 @@ typedef enum SLEEP_LEVEL // |--------+--------+--------+--------| // |00000000|00000000|TTTTTTTT|cccppppp| ( transport == USB_TRANSPORT ) // |--------+--------+--------+--------| -// +// // where: // T => Transport type // USART_TRANSPORT => 1 @@ -115,14 +112,14 @@ typedef enum SLEEP_LEVEL // FLASH_WRITE_TRANSPORT => 6 // MESSAGING_TRANSPORT => 7 // GENERIC_TRANSPORT => 8 -// p => port instance number +// p => port instance number // Port instances in the handle are 1 based. (e.g. p == 0 is invalid except when T == 0 ) // c -> Controller instance number ( USB_TRANSPORT only ) // // NULL_PORT => T==0 && p == 0 // -// GENERIC_TRANSPORT is any custom port that isn't one of the above, they -// are implemented for the DebugPort_xxxx APIs and the port number is +// GENERIC_TRANSPORT is any custom port that isn't one of the above, they +// are implemented for the DebugPort_xxxx APIs and the port number is // an index into a const global table of port interfaces (structure of // function pointers) These allow custom extensions to the normal transports // without needing to continue defining additional transport types and modifying @@ -133,13 +130,13 @@ typedef int COM_HANDLE; typedef struct HAL_DRIVER_CONFIG_HEADER { unsigned int Enable; -}HAL_DRIVER_CONFIG_HEADER; +} HAL_DRIVER_CONFIG_HEADER; typedef struct HAL_SYSTEM_MEMORY_CONFIG { unsigned int Base; unsigned int Size; -}HAL_SYSTEM_MEMORY_CONFIG; +} HAL_SYSTEM_MEMORY_CONFIG; typedef struct HAL_SYSTEM_CONFIG { @@ -147,50 +144,52 @@ typedef struct HAL_SYSTEM_CONFIG //--// - COM_HANDLE DebuggerPort; + COM_HANDLE DebuggerPort; // communication channel for debug messages in the debugger // which may be VS, MFDEPLOY, etc... Accessed via debug_printf // in the HAL/PAL and System.Diagnostics.Debug.Print() in managed // applications - COM_HANDLE DebugTextPort; + COM_HANDLE DebugTextPort; - unsigned int USART_DefaultBaudRate; + unsigned int USART_DefaultBaudRate; // internal HAL/PAL debug/tracing channel, this is separate // to allow tracing messages in the driver that implements // the transport for the Debugger and DebugTextPort. This // channel is accessed via hal_printf() in the HAL/PAL - COM_HANDLE stdio; + COM_HANDLE stdio; HAL_SYSTEM_MEMORY_CONFIG RAM1; HAL_SYSTEM_MEMORY_CONFIG FLASH1; -}HAL_SYSTEM_CONFIG; +} HAL_SYSTEM_CONFIG; -extern HAL_SYSTEM_CONFIG HalSystemConfig; +extern HAL_SYSTEM_CONFIG HalSystemConfig; #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif -void nanoHAL_Initialize_C(); -void nanoHAL_Uninitialize_C(); -void HeapLocation_C(unsigned char** baseAddress, unsigned int* sizeInBytes); + void nanoHAL_Initialize_C(); + void nanoHAL_Uninitialize_C(); + void HeapLocation_C(unsigned char **baseAddress, unsigned int *sizeInBytes); -// Call to the external memory configuration and initialization function -// If a target has external memory it has to provide the implementation for it. -void Target_ExternalMemoryInit(); + // Call to the external memory configuration and initialization function + // If a target has external memory it has to provide the implementation for it. + void Target_ExternalMemoryInit(); #ifdef __cplusplus } #endif #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif -void CPU_Reset(); -void CPU_Sleep(SLEEP_LEVEL_type level, uint64_t wakeEvents); -void CPU_SetPowerMode(PowerLevel_type powerLevel); + void CPU_Reset(); + void CPU_Sleep(SLEEP_LEVEL_type level, uint64_t wakeEvents); + void CPU_SetPowerMode(PowerLevel_type powerLevel); #ifdef __cplusplus } @@ -199,78 +198,96 @@ void CPU_SetPowerMode(PowerLevel_type powerLevel); //--// // -// This has to be extern "C" because we want to use platform implemented malloc +// This has to be extern "C" because we want to use platform implemented malloc // #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif -void* platform_malloc ( size_t size ); -void platform_free ( void* ptr ); -void* platform_realloc( void* ptr, size_t size ); + void *platform_malloc(size_t size); + void platform_free(void *ptr); + void *platform_realloc(void *ptr, size_t size); #ifdef __cplusplus } #endif -void SystemState_Set ( SYSTEM_STATE_type newState ); -void SystemState_Clear( SYSTEM_STATE_type state ); -bool SystemState_Query( SYSTEM_STATE_type state ); +void SystemState_Set(SYSTEM_STATE_type newState); +void SystemState_Clear(SYSTEM_STATE_type state); +bool SystemState_Query(SYSTEM_STATE_type state); //--// - #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif -void SystemState_SetNoLock ( SYSTEM_STATE_type state ); -void SystemState_ClearNoLock( SYSTEM_STATE_type state ); -bool SystemState_QueryNoLock( SYSTEM_STATE_type state ); + void SystemState_SetNoLock(SYSTEM_STATE_type state); + void SystemState_ClearNoLock(SYSTEM_STATE_type state); + bool SystemState_QueryNoLock(SYSTEM_STATE_type state); #ifdef __cplusplus } #endif +// these macros are to be used at entry/exit of native interrupt handlers +#define NATIVE_INTERRUPT_START \ + SystemState_SetNoLock(SYSTEM_STATE_ISR); \ + SystemState_SetNoLock(SYSTEM_STATE_NO_CONTINUATIONS); +#define NATIVE_INTERRUPT_END \ + SystemState_ClearNoLock(SYSTEM_STATE_NO_CONTINUATIONS); \ + SystemState_ClearNoLock(SYSTEM_STATE_ISR); + //--// -#define HAL_COMPLETION_IDLE_VALUE 0x0000FFFFFFFFFFFFull +#define HAL_COMPLETION_IDLE_VALUE 0x0000FFFFFFFFFFFFull // provide platform dependent delay to CLR code #if defined(_WIN32) -#define OS_DELAY(milliSecs); +#define OS_DELAY(milliSecs) ; #else -#define OS_DELAY(milliSecs) PLATFORM_DELAY(milliSecs) +#define OS_DELAY(milliSecs) PLATFORM_DELAY(milliSecs) #endif //--// // Function macros #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif -void HAL_Assert ( const char* Func, int Line, const char* File ); -// HAL_AssertEx is to be defined at platform layer -void HAL_AssertEx(); + void HAL_Assert(const char *Func, int Line, const char *File); + // HAL_AssertEx is to be defined at platform layer + void HAL_AssertEx(); #ifdef __cplusplus } #endif #if defined(PLATFORM_ARM) || defined(PLATFORM_ESP32) - #if !defined(BUILD_RTM) - #define ASSERT(i) { if(!(i)) HAL_AssertEx(); } - #define _SIDE_ASSERTE(i) { if(!(i)) HAL_AssertEx(); } - #endif +#if !defined(BUILD_RTM) +#define ASSERT(i) \ + { \ + if (!(i)) \ + HAL_AssertEx(); \ + } +#define _SIDE_ASSERTE(i) \ + { \ + if (!(i)) \ + HAL_AssertEx(); \ + } +#endif #else - #if defined(_DEBUG) +#if defined(_DEBUG) #if !defined _ASSERTE #error #endif - #define ASSERT(i) _ASSERTE(i) - #define _SIDE_ASSERTE(i) _ASSERTE(i) - #endif +#define ASSERT(i) _ASSERTE(i) +#define _SIDE_ASSERTE(i) _ASSERTE(i) +#endif #endif #ifndef ASSERT @@ -286,9 +303,10 @@ void HAL_AssertEx(); #endif #if STATIC_ASSERT_SUPPORTED -#define CT_ASSERT_STRING( x ) #x -#define CT_ASSERT_UNIQUE_NAME(e,name)static_assert( (e), CT_ASSERT_STRING( name ) "@" __FILE__ CT_ASSERT_STRING(__LINE__) ); -#define CT_ASSERT(e) static_assert( (e), __FILE__ CT_ASSERT_STRING(__LINE__) ); +#define CT_ASSERT_STRING(x) #x +#define CT_ASSERT_UNIQUE_NAME(e, name) \ + static_assert((e), CT_ASSERT_STRING(name) "@" __FILE__ CT_ASSERT_STRING(__LINE__)); +#define CT_ASSERT(e) static_assert((e), __FILE__ CT_ASSERT_STRING(__LINE__)); #else // CT_ASSERT (compile-time assert) macro is used to test condition at compiler time and generate // compiler error if condition is bool. @@ -300,44 +318,53 @@ void HAL_AssertEx(); // The possible problem with the macro - it creates multiple identical typedefs. // It is not a problem in global scope, but if macro is used inside of struct - it generates warnings. // CT_ASSERT_UNIQUE_NAME is the same in essence, but it provides a way to customize the name of the type. -#define CT_ASSERT_UNIQUE_NAME(e,name) typedef char __CT_ASSERT__##name[(e)?1:-1]; -#define CT_ASSERT(e) CT_ASSERT_UNIQUE_NAME(e,nanoclr) +#define CT_ASSERT_UNIQUE_NAME(e, name) typedef char __CT_ASSERT__##name[(e) ? 1 : -1]; +#define CT_ASSERT(e) CT_ASSERT_UNIQUE_NAME(e, nanoclr) #endif #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif #if !defined(BUILD_RTM) -void debug_printf( const char *format, ... ); + void debug_printf(const char *format, ...); #else -__inline void debug_printf( const char *format, ... ) {} +__inline void debug_printf(const char *format, ...) +{ +} -#endif // !defined(BUILD_RTM) +#endif // !defined(BUILD_RTM) #ifdef __cplusplus } #endif //--// -#define NANOCLR_LOCKED_ACCESS_DECLARATION(type, name) type copy##name -#define NANOCLR_LOCKED_ACCESS_EXECUTE(name, expr) { GLOBAL_LOCK(); copy##name = expr; GLOBAL_UNLOCK(); } -#define NANOCLR_LOCKED_ACCESS_GET(name) copy##name +#define NANOCLR_LOCKED_ACCESS_DECLARATION(type, name) type copy##name +#define NANOCLR_LOCKED_ACCESS_EXECUTE(name, expr) \ + { \ + GLOBAL_LOCK(); \ + copy##name = expr; \ + GLOBAL_UNLOCK(); \ + } +#define NANOCLR_LOCKED_ACCESS_GET(name) copy##name //--// #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif -bool Target_HasNanoBooter(); -void HARD_Breakpoint(); -bool Target_ConfigUpdateRequiresErase(); -uint32_t GetPlatformCapabilities(); -uint32_t GetTargetCapabilities(); + bool Target_HasNanoBooter(); + void HARD_Breakpoint(); + bool Target_ConfigUpdateRequiresErase(); + uint32_t GetPlatformCapabilities(); + uint32_t GetTargetCapabilities(); #ifdef __cplusplus } diff --git a/src/HAL/nanoHAL_ConfigurationManager.c b/src/HAL/nanoHAL_ConfigurationManager.c index 31250f31cd..e47c6dece9 100644 --- a/src/HAL/nanoHAL_ConfigurationManager.c +++ b/src/HAL/nanoHAL_ConfigurationManager.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/src/HAL/nanoHAL_ConfigurationManager_stubs.c b/src/HAL/nanoHAL_ConfigurationManager_stubs.c index 95ee4c42be..a9cf80f807 100644 --- a/src/HAL/nanoHAL_ConfigurationManager_stubs.c +++ b/src/HAL/nanoHAL_ConfigurationManager_stubs.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/src/HAL/nanoHAL_SystemEvents.c b/src/HAL/nanoHAL_SystemEvents.c new file mode 100644 index 0000000000..c8146cde62 --- /dev/null +++ b/src/HAL/nanoHAL_SystemEvents.c @@ -0,0 +1,54 @@ +// +// Copyright (c) .NET Foundation and Contributors +// See LICENSE file in the project root for full license information. +// + +#include +#include +#include + +volatile int32_t SystemStates[SYSTEM_STATE_TOTAL_STATES]; + +// the functions below are declared as weak so they can be replaced at target/platform level if needed + +__nfweak void SystemState_SetNoLock(SYSTEM_STATE_type state) +{ + SystemStates[state]++; +} + +__nfweak void SystemState_ClearNoLock(SYSTEM_STATE_type state) +{ + SystemStates[state]--; +} + +__nfweak bool SystemState_QueryNoLock(SYSTEM_STATE_type state) +{ + return (SystemStates[state] > 0) ? true : false; +} + +__nfweak void SystemState_Set(SYSTEM_STATE_type state) +{ +#ifdef __CM0_CMSIS_VERSION + GLOBAL_LOCK(); + SystemState_SetNoLock(state); + GLOBAL_UNLOCK(); +#else + __atomic_fetch_add(&SystemStates[state], 1, __ATOMIC_RELAXED); +#endif +} + +__nfweak void SystemState_Clear(SYSTEM_STATE_type state) +{ +#ifdef __CM0_CMSIS_VERSION + GLOBAL_LOCK(); + SystemState_ClearNoLock(state); + GLOBAL_UNLOCK(); +#else + __atomic_fetch_sub(&SystemStates[state], 1, __ATOMIC_RELAXED); +#endif +} + +__nfweak bool SystemState_Query(SYSTEM_STATE_type state) +{ + return __atomic_load_n(&state, __ATOMIC_RELAXED) ? true : false; +} diff --git a/src/HAL/nanoHAL_SystemInformation.cpp b/src/HAL/nanoHAL_SystemInformation.cpp index 2632a0c578..4f887c0e65 100644 --- a/src/HAL/nanoHAL_SystemInformation.cpp +++ b/src/HAL/nanoHAL_SystemInformation.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/HAL/nanoHAL_Time.cpp b/src/HAL/nanoHAL_Time.cpp index 459b289348..8603b8465c 100644 --- a/src/HAL/nanoHAL_Time.cpp +++ b/src/HAL/nanoHAL_Time.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/HAL/nanoHAL_Watchdog.c b/src/HAL/nanoHAL_Watchdog.c index c0e013317b..49700ed5c0 100644 --- a/src/HAL/nanoHAL_Watchdog.c +++ b/src/HAL/nanoHAL_Watchdog.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/PAL/AsyncProcCall/AsyncCompletions.cpp b/src/PAL/AsyncProcCall/AsyncCompletions.cpp index 29543a297d..2bbd434590 100644 --- a/src/PAL/AsyncProcCall/AsyncCompletions.cpp +++ b/src/PAL/AsyncProcCall/AsyncCompletions.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/PAL/AsyncProcCall/AsyncContinuations.cpp b/src/PAL/AsyncProcCall/AsyncContinuations.cpp index 87543d2b94..e81e8a0838 100644 --- a/src/PAL/AsyncProcCall/AsyncContinuations.cpp +++ b/src/PAL/AsyncProcCall/AsyncContinuations.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/PAL/AsyncProcCall/Async_stubs.cpp b/src/PAL/AsyncProcCall/Async_stubs.cpp index a620e97cd1..dc60423d3d 100644 --- a/src/PAL/AsyncProcCall/Async_stubs.cpp +++ b/src/PAL/AsyncProcCall/Async_stubs.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/PAL/BlockStorage/nanoPAL_BlockStorage.c b/src/PAL/BlockStorage/nanoPAL_BlockStorage.c index be3122c87a..9dae892f0d 100644 --- a/src/PAL/BlockStorage/nanoPAL_BlockStorage.c +++ b/src/PAL/BlockStorage/nanoPAL_BlockStorage.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/PAL/COM/COM_stubs.c b/src/PAL/COM/COM_stubs.c index f1892cabdb..2caa88cc95 100644 --- a/src/PAL/COM/COM_stubs.c +++ b/src/PAL/COM/COM_stubs.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/PAL/COM/ComDirector.cpp b/src/PAL/COM/ComDirector.cpp index 040b405003..52022a5638 100644 --- a/src/PAL/COM/ComDirector.cpp +++ b/src/PAL/COM/ComDirector.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/PAL/COM/GenericPort_stubs.c b/src/PAL/COM/GenericPort_stubs.c index 8de1d3bd69..cabcc7e655 100644 --- a/src/PAL/COM/GenericPort_stubs.c +++ b/src/PAL/COM/GenericPort_stubs.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/PAL/COM/sockets/Sockets_debugger.cpp b/src/PAL/COM/sockets/Sockets_debugger.cpp index 17ef409e74..f34532819c 100644 --- a/src/PAL/COM/sockets/Sockets_debugger.cpp +++ b/src/PAL/COM/sockets/Sockets_debugger.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/PAL/COM/sockets/sockets_lwip.cpp b/src/PAL/COM/sockets/sockets_lwip.cpp index 9f8c5a8872..4450a8880d 100644 --- a/src/PAL/COM/sockets/sockets_lwip.cpp +++ b/src/PAL/COM/sockets/sockets_lwip.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/PAL/COM/sockets/sockets_lwip.h b/src/PAL/COM/sockets/sockets_lwip.h index bb7b972c12..5e8cfefe84 100644 --- a/src/PAL/COM/sockets/sockets_lwip.h +++ b/src/PAL/COM/sockets/sockets_lwip.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/PAL/COM/sockets/ssl/mbedTLS/mbedtls.h b/src/PAL/COM/sockets/ssl/mbedTLS/mbedtls.h index 75f164ce90..97d3337c53 100644 --- a/src/PAL/COM/sockets/ssl/mbedTLS/mbedtls.h +++ b/src/PAL/COM/sockets/ssl/mbedTLS/mbedtls.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/PAL/COM/sockets/ssl/mbedTLS/nf_mbedtls_config.h b/src/PAL/COM/sockets/ssl/mbedTLS/nf_mbedtls_config.h index 0b33bb1a7d..bc78eab9a6 100644 --- a/src/PAL/COM/sockets/ssl/mbedTLS/nf_mbedtls_config.h +++ b/src/PAL/COM/sockets/ssl/mbedTLS/nf_mbedtls_config.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006-2015, ARM Limited, All Rights Reserved // See LICENSE file in the project root for full license information. // @@ -13,10 +13,11 @@ // need to declare this as external to be picked up by mbed TLS platform_time #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif -time_t nf_get_unix_epoch(); + time_t nf_get_unix_epoch(); #ifdef __cplusplus } @@ -29,6 +30,8 @@ time_t nf_get_unix_epoch(); #define MBEDTLS_HAVE_TIME_DATE +#define MBEDTLS_DEPRECATED_REMOVED + // need to define this as the alternative to standard time function #define MBEDTLS_PLATFORM_TIME_MACRO nf_get_unix_epoch @@ -103,8 +106,6 @@ time_t nf_get_unix_epoch(); #define MBEDTLS_ARC4_C #define MBEDTLS_ASN1_PARSE_C -//#define MBEDTLS_ASN1_WRITE_C - #define MBEDTLS_BASE64_C #define MBEDTLS_BIGNUM_C @@ -122,8 +123,6 @@ time_t nf_get_unix_epoch(); #define MBEDTLS_DHM_C #define MBEDTLS_ECDH_C -//#define MBEDTLS_ECDSA_C - #define MBEDTLS_ECP_C #define MBEDTLS_ENTROPY_C @@ -176,7 +175,7 @@ time_t nf_get_unix_epoch(); #define MBEDTLS_XTEA_C -#define MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_KEY_EXCHANGE +#define MBEDTLS_AES_ROM_TABLES //////////////////////////////////////////////////////////////////////////// // This define depends on the platform having a hardware random generator. diff --git a/src/PAL/COM/sockets/ssl/mbedTLS/ssl_accept_internal.cpp b/src/PAL/COM/sockets/ssl/mbedTLS/ssl_accept_internal.cpp index 346e72153d..946db5a6b2 100644 --- a/src/PAL/COM/sockets/ssl/mbedTLS/ssl_accept_internal.cpp +++ b/src/PAL/COM/sockets/ssl/mbedTLS/ssl_accept_internal.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/src/PAL/COM/sockets/ssl/mbedTLS/ssl_add_cert_auth_internal.cpp b/src/PAL/COM/sockets/ssl/mbedTLS/ssl_add_cert_auth_internal.cpp index 24afcc7168..d73cc65cb3 100644 --- a/src/PAL/COM/sockets/ssl/mbedTLS/ssl_add_cert_auth_internal.cpp +++ b/src/PAL/COM/sockets/ssl/mbedTLS/ssl_add_cert_auth_internal.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/src/PAL/COM/sockets/ssl/mbedTLS/ssl_close_socket_internal.cpp b/src/PAL/COM/sockets/ssl/mbedTLS/ssl_close_socket_internal.cpp index 053492e178..b7dd71aa3e 100644 --- a/src/PAL/COM/sockets/ssl/mbedTLS/ssl_close_socket_internal.cpp +++ b/src/PAL/COM/sockets/ssl/mbedTLS/ssl_close_socket_internal.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/src/PAL/COM/sockets/ssl/mbedTLS/ssl_connect_internal.cpp b/src/PAL/COM/sockets/ssl/mbedTLS/ssl_connect_internal.cpp index 56112f25c9..90914acf3e 100644 --- a/src/PAL/COM/sockets/ssl/mbedTLS/ssl_connect_internal.cpp +++ b/src/PAL/COM/sockets/ssl/mbedTLS/ssl_connect_internal.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006-2015, ARM Limited, All Rights Reserved // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. diff --git a/src/PAL/COM/sockets/ssl/mbedTLS/ssl_decode_private_key_internal.cpp b/src/PAL/COM/sockets/ssl/mbedTLS/ssl_decode_private_key_internal.cpp index 255aee3b13..c6402456bc 100644 --- a/src/PAL/COM/sockets/ssl/mbedTLS/ssl_decode_private_key_internal.cpp +++ b/src/PAL/COM/sockets/ssl/mbedTLS/ssl_decode_private_key_internal.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/PAL/COM/sockets/ssl/mbedTLS/ssl_exit_context_internal.cpp b/src/PAL/COM/sockets/ssl/mbedTLS/ssl_exit_context_internal.cpp index d6c45e2a50..b16a801571 100644 --- a/src/PAL/COM/sockets/ssl/mbedTLS/ssl_exit_context_internal.cpp +++ b/src/PAL/COM/sockets/ssl/mbedTLS/ssl_exit_context_internal.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006-2015, ARM Limited, All Rights Reserved // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. diff --git a/src/PAL/COM/sockets/ssl/mbedTLS/ssl_generic.cpp b/src/PAL/COM/sockets/ssl/mbedTLS/ssl_generic.cpp index a272ebb891..c4b9c01cc2 100644 --- a/src/PAL/COM/sockets/ssl/mbedTLS/ssl_generic.cpp +++ b/src/PAL/COM/sockets/ssl/mbedTLS/ssl_generic.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/PAL/COM/sockets/ssl/mbedTLS/ssl_generic_init_internal.cpp b/src/PAL/COM/sockets/ssl/mbedTLS/ssl_generic_init_internal.cpp index 47c4bdee1b..5b3a041122 100644 --- a/src/PAL/COM/sockets/ssl/mbedTLS/ssl_generic_init_internal.cpp +++ b/src/PAL/COM/sockets/ssl/mbedTLS/ssl_generic_init_internal.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006-2015, ARM Limited, All Rights Reserved // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. diff --git a/src/PAL/COM/sockets/ssl/mbedTLS/ssl_initialize_internal.cpp b/src/PAL/COM/sockets/ssl/mbedTLS/ssl_initialize_internal.cpp index 7450d355bb..72cdb7070b 100644 --- a/src/PAL/COM/sockets/ssl/mbedTLS/ssl_initialize_internal.cpp +++ b/src/PAL/COM/sockets/ssl/mbedTLS/ssl_initialize_internal.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006-2015, ARM Limited, All Rights Reserved // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. diff --git a/src/PAL/COM/sockets/ssl/mbedTLS/ssl_parse_certificate_internal.cpp b/src/PAL/COM/sockets/ssl/mbedTLS/ssl_parse_certificate_internal.cpp index 8169de41da..55023aacbf 100644 --- a/src/PAL/COM/sockets/ssl/mbedTLS/ssl_parse_certificate_internal.cpp +++ b/src/PAL/COM/sockets/ssl/mbedTLS/ssl_parse_certificate_internal.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/PAL/COM/sockets/ssl/mbedTLS/ssl_pending_internal.cpp b/src/PAL/COM/sockets/ssl/mbedTLS/ssl_pending_internal.cpp index 2fafa75dcd..5abdb0ecdd 100644 --- a/src/PAL/COM/sockets/ssl/mbedTLS/ssl_pending_internal.cpp +++ b/src/PAL/COM/sockets/ssl/mbedTLS/ssl_pending_internal.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/src/PAL/COM/sockets/ssl/mbedTLS/ssl_read_internal.cpp b/src/PAL/COM/sockets/ssl/mbedTLS/ssl_read_internal.cpp index 1d8254b10b..bc6ccca87b 100644 --- a/src/PAL/COM/sockets/ssl/mbedTLS/ssl_read_internal.cpp +++ b/src/PAL/COM/sockets/ssl/mbedTLS/ssl_read_internal.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/src/PAL/COM/sockets/ssl/mbedTLS/ssl_uninitialize_internal.cpp b/src/PAL/COM/sockets/ssl/mbedTLS/ssl_uninitialize_internal.cpp index fe044c2e6d..36657f5ae2 100644 --- a/src/PAL/COM/sockets/ssl/mbedTLS/ssl_uninitialize_internal.cpp +++ b/src/PAL/COM/sockets/ssl/mbedTLS/ssl_uninitialize_internal.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/PAL/COM/sockets/ssl/mbedTLS/ssl_write_internal.cpp b/src/PAL/COM/sockets/ssl/mbedTLS/ssl_write_internal.cpp index 472c656080..584741cfa4 100644 --- a/src/PAL/COM/sockets/ssl/mbedTLS/ssl_write_internal.cpp +++ b/src/PAL/COM/sockets/ssl/mbedTLS/ssl_write_internal.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/PAL/COM/sockets/ssl/ssl.cpp b/src/PAL/COM/sockets/ssl/ssl.cpp index 84bfa0bd29..9e9f12114b 100644 --- a/src/PAL/COM/sockets/ssl/ssl.cpp +++ b/src/PAL/COM/sockets/ssl/ssl.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/PAL/COM/sockets/ssl/ssl.h b/src/PAL/COM/sockets/ssl/ssl.h index 7582f22180..e8df54c4ef 100644 --- a/src/PAL/COM/sockets/ssl/ssl.h +++ b/src/PAL/COM/sockets/ssl/ssl.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/PAL/COM/sockets/ssl/ssl_functions.h b/src/PAL/COM/sockets/ssl/ssl_functions.h index 7bf171a89e..4080c40830 100644 --- a/src/PAL/COM/sockets/ssl/ssl_functions.h +++ b/src/PAL/COM/sockets/ssl/ssl_functions.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/PAL/COM/sockets/ssl/ssl_stubs.cpp b/src/PAL/COM/sockets/ssl/ssl_stubs.cpp index 1025cc34db..0f4b71e06d 100644 --- a/src/PAL/COM/sockets/ssl/ssl_stubs.cpp +++ b/src/PAL/COM/sockets/ssl/ssl_stubs.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/PAL/COM/sockets/ssl/ssl_types.h b/src/PAL/COM/sockets/ssl/ssl_types.h index 53960da5cf..de9934279c 100644 --- a/src/PAL/COM/sockets/ssl/ssl_types.h +++ b/src/PAL/COM/sockets/ssl/ssl_types.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/PAL/Double/nanoPAL_NativeDouble.cpp b/src/PAL/Double/nanoPAL_NativeDouble.cpp index d40b26dac6..c6ee0e176f 100644 --- a/src/PAL/Double/nanoPAL_NativeDouble.cpp +++ b/src/PAL/Double/nanoPAL_NativeDouble.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/PAL/Events/nanoPAL_Events.cpp b/src/PAL/Events/nanoPAL_Events.cpp new file mode 100644 index 0000000000..6fe92cd495 --- /dev/null +++ b/src/PAL/Events/nanoPAL_Events.cpp @@ -0,0 +1,95 @@ +// +// Copyright (c) .NET Foundation and Contributors +// Portions Copyright (c) Microsoft Corporation. All rights reserved. +// See LICENSE file in the project root for full license information. +// + +#include +// #include + +static uint32_t systemEvents; + +set_Event_Callback g_Event_Callback = NULL; +void *g_Event_Callback_Arg = NULL; + +// functions below declared as weak can be replaced at target/platform level if needed + +__nfweak bool Events_Initialize_Platform() +{ + return true; +} + +__nfweak bool Events_Uninitialize_Platform() +{ + return true; +} + +__nfweak void Events_Set(uint32_t events) +{ + NATIVE_PROFILE_PAL_EVENTS(); + + // set events atomically +#ifdef __CM0_CMSIS_VERSION + GLOBAL_LOCK(); + systemEvents |= events; + GLOBAL_UNLOCK(); +#else + __atomic_fetch_or(&systemEvents, events, __ATOMIC_RELAXED); +#endif + + if (g_Event_Callback != NULL) + { + g_Event_Callback(g_Event_Callback_Arg); + } +} + +__nfweak uint32_t Events_Get(uint32_t eventsOfInterest) +{ + NATIVE_PROFILE_PAL_EVENTS(); + + // ... clear the requested flags atomically + // give the caller notice of just the events they asked for ( and were cleared already ) +#ifdef __CM0_CMSIS_VERSION + // get the requested flags from system events state and... + uint32_t returnEvents = (systemEvents & eventsOfInterest); + + GLOBAL_LOCK(); + systemEvents &= ~eventsOfInterest; + GLOBAL_UNLOCK(); + + return returnEvents; +#else + return __atomic_fetch_and(&systemEvents, ~eventsOfInterest, __ATOMIC_RELAXED) & eventsOfInterest; +#endif +} + +__nfweak uint32_t Events_MaskedRead(uint32_t eventsOfInterest) +{ + NATIVE_PROFILE_PAL_EVENTS(); + return (systemEvents & eventsOfInterest); +} + +__nfweak void Events_SetCallback(set_Event_Callback pfn, void *arg) +{ + NATIVE_PROFILE_PAL_EVENTS(); + + g_Event_Callback = pfn; + g_Event_Callback_Arg = arg; +} + +bool Events_Initialize() +{ + NATIVE_PROFILE_PAL_EVENTS(); + + // init events atomically + __atomic_clear(&systemEvents, __ATOMIC_RELAXED); + + return Events_Initialize_Platform(); +} + +bool Events_Uninitialize() +{ + NATIVE_PROFILE_PAL_EVENTS(); + + return Events_Uninitialize_Platform(); +} diff --git a/src/PAL/Events/nanoPAL_Events_driver.cpp b/src/PAL/Events/nanoPAL_Events_driver.cpp index 655bebdd0f..993c7ef3ab 100644 --- a/src/PAL/Events/nanoPAL_Events_driver.cpp +++ b/src/PAL/Events/nanoPAL_Events_driver.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/PAL/Events/nanoPAL_Events_functions.cpp b/src/PAL/Events/nanoPAL_Events_functions.cpp index 7e0c3628f0..8b229f296e 100644 --- a/src/PAL/Events/nanoPAL_Events_functions.cpp +++ b/src/PAL/Events/nanoPAL_Events_functions.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/PAL/Include/CPU_GPIO_decl.h b/src/PAL/Include/CPU_GPIO_decl.h index 8d485ce2b6..90928a7c7a 100644 --- a/src/PAL/Include/CPU_GPIO_decl.h +++ b/src/PAL/Include/CPU_GPIO_decl.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // @@ -7,19 +7,18 @@ #ifndef _DRIVERS_GPIO_DECL_H_ #define _DRIVERS_GPIO_DECL_H_ 1 -#if defined (__GNUC__) +#if defined(__GNUC__) #define __int64 long long #endif typedef unsigned __int64 CLR_UINT64; -#define GPIO_PIN_NONE 0xFFFFFFFF - -#define GPIO_ATTRIBUTE_NONE 0x00 -#define GPIO_ATTRIBUTE_INPUT 0x01 -#define GPIO_ATTRIBUTE_OUTPUT 0x02 -#define GPIO_ATTRIBUTE_ALTERNATE_A 0x04 -#define GPIO_ATTRIBUTE_ALTERNATE_B 0x08 +#define GPIO_PIN_NONE 0xFFFFFFFF +#define GPIO_ATTRIBUTE_NONE 0x00 +#define GPIO_ATTRIBUTE_INPUT 0x01 +#define GPIO_ATTRIBUTE_OUTPUT 0x02 +#define GPIO_ATTRIBUTE_ALTERNATE_A 0x04 +#define GPIO_ATTRIBUTE_ALTERNATE_B 0x08 // from declaration at src\Windows.Devices.Gpio\win_dev_gpio_native.h typedef enum __nfpack GpioPinDriveMode @@ -43,12 +42,12 @@ typedef enum __nfpack GpioPinValue enum GPIO_INT_EDGE { - GPIO_INT_NONE = 0, - GPIO_INT_EDGE_LOW = 1, - GPIO_INT_EDGE_HIGH = 2, - GPIO_INT_EDGE_BOTH = 3, + GPIO_INT_NONE = 0, + GPIO_INT_EDGE_LOW = 1, + GPIO_INT_EDGE_HIGH = 2, + GPIO_INT_EDGE_BOTH = 3, GPIO_INT_LEVEL_HIGH = 4, - GPIO_INT_LEVEL_LOW = 5 + GPIO_INT_LEVEL_LOW = 5 }; // struct GPIO_FLAG_RESISTOR @@ -58,21 +57,19 @@ enum GPIO_INT_EDGE // GPIO_RESISTOR Resistor; // }; +typedef void (*GPIO_INTERRUPT_SERVICE_ROUTINE)(GPIO_PIN pin, bool pinState); -typedef void (*GPIO_INTERRUPT_SERVICE_ROUTINE)( GPIO_PIN Pin, bool PinState, void* Param ); - -bool CPU_GPIO_Initialize (); -bool CPU_GPIO_Uninitialize (); - +bool CPU_GPIO_Initialize(); +bool CPU_GPIO_Uninitialize(); -void CPU_GPIO_DisablePin ( GPIO_PIN Pin, GpioPinDriveMode driveMode, uint32_t alternateFunction); +void CPU_GPIO_DisablePin(GPIO_PIN Pin, GpioPinDriveMode driveMode, uint32_t alternateFunction); // // CPU_GPIO_EnableOutputPin // // Parameters :- // -// Pin +// Pin // The number of the input pin to be enabled. // InitialState // Inial value of pin @@ -82,14 +79,14 @@ void CPU_GPIO_DisablePin ( GPIO_PIN Pin, GpioPinDriveMode driveMode, uint3 // Return Value // true if the specified pin was successfully enabled as output; otherwise, false. // -bool CPU_GPIO_EnableOutputPin( GPIO_PIN Pin, GpioPinValue InitialState, GpioPinDriveMode driveMode ); +bool CPU_GPIO_EnableOutputPin(GPIO_PIN Pin, GpioPinValue InitialState, GpioPinDriveMode driveMode); // // CPU_GPIO_EnableInputPin // // Parameters :- // -// pinNumber +// pinNumber // The number of the input pin to be enabled. // Debounce milisecs // A value you can set to greater than 0 to enable glitch filtering (debouncing) for the number of millissecs @@ -104,32 +101,35 @@ bool CPU_GPIO_EnableOutputPin( GPIO_PIN Pin, GpioPinValue InitialState, GpioPi // Return Value // true if the specified pin was successfully enabled; otherwise, false. // -bool CPU_GPIO_EnableInputPin( GPIO_PIN pinNumber, CLR_UINT64 debounceTimeMilliseconds, GPIO_INTERRUPT_SERVICE_ROUTINE pin_ISR, void* isr_Param, GPIO_INT_EDGE intEdge, GpioPinDriveMode driveMode ); +bool CPU_GPIO_EnableInputPin( + GPIO_PIN pinNumber, + CLR_UINT64 debounceTimeMilliseconds, + GPIO_INTERRUPT_SERVICE_ROUTINE pin_ISR, + void *isr_Param, + GPIO_INT_EDGE intEdge, + GpioPinDriveMode driveMode); // Return current gpio pin state -GpioPinValue CPU_GPIO_GetPinState ( GPIO_PIN Pin ); +GpioPinValue CPU_GPIO_GetPinState(GPIO_PIN Pin); // Set state of output gpio pin -void CPU_GPIO_SetPinState ( GPIO_PIN Pin, GpioPinValue PinState ); +void CPU_GPIO_SetPinState(GPIO_PIN Pin, GpioPinValue PinState); // Check if pin is already reserved // Returns true if pin is already reserved -bool CPU_GPIO_PinIsBusy ( GPIO_PIN Pin ); +bool CPU_GPIO_PinIsBusy(GPIO_PIN Pin); // Reserved or Unreserve gpio pin // if clearing reserve always return true -// If reserving pin then return false if already reserved -bool CPU_GPIO_ReservePin ( GPIO_PIN Pin, bool fReserve ); - +// If reserving pin then return false if already reserved +bool CPU_GPIO_ReservePin(GPIO_PIN Pin, bool fReserve); // Return count of gpio pins avaiable -int32_t CPU_GPIO_GetPinCount (); - +int32_t CPU_GPIO_GetPinCount(); // Get / Set the pin debounce time in millisecs uint32_t CPU_GPIO_GetPinDebounce(GPIO_PIN Pin); -bool CPU_GPIO_SetPinDebounce(GPIO_PIN pinNumber, CLR_UINT64 debounceTimeMilliseconds); - +bool CPU_GPIO_SetPinDebounce(GPIO_PIN pinNumber, CLR_UINT64 debounceTimeMilliseconds); // Validate pin and set drive mode // return true if pin ok @@ -139,20 +139,17 @@ bool CPU_GPIO_SetDriveMode(GPIO_PIN pinNumber, GpioPinDriveMode driveMode); // return true if drive mode supported bool CPU_GPIO_DriveModeSupported(GPIO_PIN pinNumber, GpioPinDriveMode driveMode); - // ==== Not implemented/used ==== -// Retrieves an array containing the attributes of all the GPIO pins. +// Retrieves an array containing the attributes of all the GPIO pins. // void CPU_GPIO_GetPinsMap(uint8_t* pins, size_t size); -// Retrieves the resistor modes supported by a designated GPIO pin. -//uint8_t CPU_GPIO_GetSupportedResistorModes(GPIO_PIN pin); +// Retrieves the resistor modes supported by a designated GPIO pin. +// uint8_t CPU_GPIO_GetSupportedResistorModes(GPIO_PIN pin); -// Retrieves the interrupt edge modes supported by a designated GPIO pin. -//uint8_t CPU_GPIO_GetSupportedInterruptModes(GPIO_PIN pin); - -//Retrieves the GPIO attributes of a specified pin. ( none=0, input=1, output=2, altA=4, altB=8 etc ) -//uint32_t CPU_GPIO_Attributes(GPIO_PIN Pin); +// Retrieves the interrupt edge modes supported by a designated GPIO pin. +// uint8_t CPU_GPIO_GetSupportedInterruptModes(GPIO_PIN pin); +// Retrieves the GPIO attributes of a specified pin. ( none=0, input=1, output=2, altA=4, altB=8 etc ) +// uint32_t CPU_GPIO_Attributes(GPIO_PIN Pin); #endif // _DRIVERS_GPIO_DECL_H_ - diff --git a/src/PAL/Include/CPU_SPI_decl.h b/src/PAL/Include/CPU_SPI_decl.h new file mode 100644 index 0000000000..31d196bd5d --- /dev/null +++ b/src/PAL/Include/CPU_SPI_decl.h @@ -0,0 +1,145 @@ +// +// Copyright (c) .NET Foundation and Contributors +// Portions Copyright (c) Microsoft Corporation. All rights reserved. +// See LICENSE file in the project root for full license information. +// + +#ifndef _DRIVERS_SPI_DECL_H_ +#define _DRIVERS_SPI_DECL_H_ 1 + +#define SPI_CTRL_DEFAULT 0 + +// Callback when operation complete on bus in async operation +typedef void (*SPI_Callback)(int busIndex); + +/////////////////////////////////////////////////////////////////////////////////////// +// !!! KEEP IN SYNC WITH Windows.Devices.Spi.SpiMode (in managed code) !!! // +/////////////////////////////////////////////////////////////////////////////////////// +typedef enum __nfpack DataBitOrder +{ + DataBitOrder_MSB = 0, + DataBitOrder_LSB = 1 +} DataBitOrder; + +/////////////////////////////////////////////////////////////////////////////////////// +// !!! KEEP IN SYNC WITH Windows.Devices.Spi.SpiMode (in managed code) !!! // +/////////////////////////////////////////////////////////////////////////////////////// + +// SPI mode +typedef enum __nfpack SpiMode +{ + SpiMode_Mode0 = 0, + SpiMode_Mode1 = 1, + SpiMode_Mode2 = 2, + SpiMode_Mode3 = 3 +} SpiMode; + +typedef enum __nfpack SpiBusMode +{ + SpiBusMode_slave = 0, + SpiBusMode_master = 1 +} SpiBusMode; + +// Async operation status +typedef enum __nfpack SPI_OP_STATUS +{ + SPI_OP_READY, // Bus ready for new operation + SPI_OP_RUNNING, // operation still running + SPI_OP_COMPLETE // Last operation complete +} SPI_OP_STATUS; + +struct SPI_DEVICE_CONFIGURATION +{ + uint32_t Spi_Bus; // SPi bus thats connected to device + SpiBusMode BusMode; // Slave or master(default) + GPIO_PIN DeviceChipSelect; // GPIO pin used for device Chip select + bool ChipSelectActive; // False = LOW active, True = HIGH active + SpiMode Spi_Mode; // SPI mode 0 -> 3 + bool MD16bits; // True = SPI data takes the form of 16-bit words otherwise 8-bit words. + DataBitOrder DataOrder16; // Data order for 16 bit operation + + // Master Only + uint32_t Clock_RateHz; // Master - SPI bus clock frequency, in hertz (Hz). + uint32_t CS_Setup_uSecs; // Master - Not sure if we need these !! + uint32_t CS_Hold_uSecs; // Master - +}; + +struct SPI_WRITE_READ_SETTINGS +{ + bool fullDuplex; // Full duplex opertaion + int readOffset; // Read offset on half duplex read ( from end of write ) + bool Bits16ReadWrite; // True if a 16bit operation + SPI_Callback callback; // NUll is operation is Synchronous +}; + +#define CPU_SPI_ERROR_PARAM -1 +#define CPU_SPI_ERROR_NOMEM -2 +#define CPU_SPI_ERROR_FAIL -3 +#define CPU_SPI_ERROR_TIMEOUT -4 + +// HAL SPi functions (porting layer) + +// Initialise an SPI bus, called before any devices opened (optional) +bool CPU_SPI_Initialize(uint8_t bus); + +// Unintialise spi bus, called after last device removed (optional) +bool CPU_SPI_Uninitialize(uint8_t bus); + +// Return status of current SPI operation +// Used to find status of an Async SPI call +SPI_OP_STATUS CPU_SPI_OP_Status(uint8_t spi_bus, uint32_t deviceHandle); + +// Add a device to SPi Bus (Optional) +// Returns a device handle. Returns 0 if error +// deviceHandle is a reference to underlying OS handle/address of device. If not required then return +// value not equal 0 +uint32_t CPU_SPI_Add_Device(const SPI_DEVICE_CONFIGURATION &spiDeviceConfig); + +// Remove device from bus (Optional) +// return true is successful +bool CPU_SPI_Remove_Device(uint32_t deviceHandle); + +// Write / read 8 bit data to device specified by handle +// return result 0=S_OK, CLR_E_BUSY async operation and operation still running or another error code +HRESULT CPU_SPI_nWrite_nRead( + uint32_t deviceHandle, + SPI_DEVICE_CONFIGURATION &sdev, + SPI_WRITE_READ_SETTINGS &swrs, + uint8_t *writePtr, + int32_t writeSize, + uint8_t *readPtr, + int32_t readSize); + +// Write / read 16 bit data to device specified by handle +// return result 0=S_OK, CLR_E_BUSY async operation and operation still running or another error code +HRESULT CPU_SPI_nWrite16_nRead16( + uint32_t deviceHandle, + SPI_DEVICE_CONFIGURATION &sdev, + SPI_WRITE_READ_SETTINGS &swrs, + uint16_t *writePtr, + int32_t writeSize, + uint16_t *readPtr, + int32_t readSize); + +// Return bit map of available SPI buses +// bit 0 - SPI1 +// bit 1 - SPI2 +// bit 2 - SPI3 +// etc +uint32_t CPU_SPI_PortsMap(); + +// Total number of SPI buses available +uint32_t CPU_SPI_PortsCount(); + +// Return pins used for SPI bus +// return -1 if not known +void CPU_SPI_GetPins(uint32_t spi_bus, GPIO_PIN &clk, GPIO_PIN &miso, GPIO_PIN &mosi); + +// Minimum and Maximum clock frequency available based on bus and configured pins +uint32_t CPU_SPI_MinClockFrequency(uint32_t spi_bus); +uint32_t CPU_SPI_MaxClockFrequency(uint32_t spi_bus); + +// Number of SPI devices that can simultaneously be opened on a bus ( hardware restrictions) +uint32_t CPU_SPI_ChipSelectLineCount(uint32_t spi_bus); + +#endif // _DRIVERS_SPI_DECL_H_ diff --git a/src/PAL/Include/nanoCRT.h b/src/PAL/Include/nanoCRT.h index 145cf42bf7..9f0f02d116 100644 --- a/src/PAL/Include/nanoCRT.h +++ b/src/PAL/Include/nanoCRT.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/PAL/Include/nanoPAL.h b/src/PAL/Include/nanoPAL.h index 0fe17e3569..05813161ba 100644 --- a/src/PAL/Include/nanoPAL.h +++ b/src/PAL/Include/nanoPAL.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/PAL/Include/nanoPAL_AsyncProcCalls_decl.h b/src/PAL/Include/nanoPAL_AsyncProcCalls_decl.h index 811d4f3888..3aa2333ca9 100644 --- a/src/PAL/Include/nanoPAL_AsyncProcCalls_decl.h +++ b/src/PAL/Include/nanoPAL_AsyncProcCalls_decl.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/PAL/Include/nanoPAL_BlockStorage.h b/src/PAL/Include/nanoPAL_BlockStorage.h index 1131628027..2356126c3b 100644 --- a/src/PAL/Include/nanoPAL_BlockStorage.h +++ b/src/PAL/Include/nanoPAL_BlockStorage.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/PAL/Include/nanoPAL_COM.h b/src/PAL/Include/nanoPAL_COM.h index 10defc06b7..77d157c0e0 100644 --- a/src/PAL/Include/nanoPAL_COM.h +++ b/src/PAL/Include/nanoPAL_COM.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/PAL/Include/nanoPAL_Events.h b/src/PAL/Include/nanoPAL_Events.h index 6454775c5b..118999dd41 100644 --- a/src/PAL/Include/nanoPAL_Events.h +++ b/src/PAL/Include/nanoPAL_Events.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // @@ -9,53 +9,47 @@ #include #include -typedef void (*set_Event_Callback)( void* ); +typedef void (*set_Event_Callback)(void *); #define EVENTS_TIMEOUT_INFINITE 0xFFFFFFFF #if NATIVE_PROFILE_PAL & NATIVE_PROFILE_PAL_EVENTS__flag - #define NATIVE_PROFILE_PAL_EVENTS() Native_Profiler profiler_obj +#define NATIVE_PROFILE_PAL_EVENTS() Native_Profiler profiler_obj #else - #define NATIVE_PROFILE_PAL_EVENTS() +#define NATIVE_PROFILE_PAL_EVENTS() #endif +#ifdef __cplusplus +extern "C" +{ +#endif - bool Events_Initialize(); - bool Events_Uninitialize(); - void Events_Set( uint32_t events ); - -// destructive read system event flags - uint32_t Events_Get( uint32_t eventsOfInterest ); - -// non-destructive read system event flags - uint32_t Events_MaskedRead( uint32_t eventsOfInterest ); + bool Events_Initialize(); + bool Events_Uninitialize(); + void Events_Set(uint32_t events); -// returns 0 for timeout, non-zero are events that have happened and were asked to be waiting on (non-destructive read) -// timeout limit is about 3034 milliseconds currently -// values greater than this are capped to this + // destructive read system event flags + uint32_t Events_Get(uint32_t eventsOfInterest); -// sleep relative time into the future, or until a SystemEvent occurs, which occurs first -// timeout is a non-negative number of 1mSec ticks, or -1 (any negative value) to sleep forever until a SystemEvent occurs + // non-destructive read system event flags + uint32_t Events_MaskedRead(uint32_t eventsOfInterest); -// Events_WaitForEvents(0, n), sleeps for n milliseconds independent of events -// Events_WaitForEvents(0, EVENTS_TIMEOUT_INFINITE) sleeps forever. Don't do that. -// Events_WaitForEvents(flags, EVENTS_TIMEOUT_INFINITE) waits forever for that event. + // returns 0 for timeout, non-zero are events that have happened and were asked to be waiting on (non-destructive + // read) timeout limit is about 3034 milliseconds currently values greater than this are capped to this -uint32_t Events_WaitForEvents( uint32_t powerLevel, uint32_t wakeupSystemEvents, uint32_t timeoutMilliseconds ); + // sleep relative time into the future, or until a SystemEvent occurs, which occurs first + // timeout is a non-negative number of 1mSec ticks, or -1 (any negative value) to sleep forever until a SystemEvent + // occurs -__inline uint32_t Events_WaitForEvents( uint32_t wakeupSystemEvents, uint32_t timeoutMilliseconds ) -{ - return Events_WaitForEvents( SLEEP_LEVEL__SLEEP, wakeupSystemEvents, timeoutMilliseconds ); -} + // Events_WaitForEvents(0, n), sleeps for n milliseconds independent of events + // Events_WaitForEvents(0, EVENTS_TIMEOUT_INFINITE) sleeps forever. Don't do that. + // Events_WaitForEvents(flags, EVENTS_TIMEOUT_INFINITE) waits forever for that event. - void Events_SetBoolTimer( bool* timerCompleteFlag, uint32_t millisecondsFromNow ); - void Events_SetCallback( set_Event_Callback pfn, void* arg ); - void FreeManagedEvent(uint8_t category, uint8_t subCategory, uint16_t data1, uint32_t data2); + uint32_t Events_WaitForEvents(uint32_t powerLevel, uint32_t wakeupSystemEvents, uint32_t timeoutMilliseconds); - -#ifdef __cplusplus -extern "C" { -#endif + void Events_SetBoolTimer(bool *timerCompleteFlag, uint32_t millisecondsFromNow); + void Events_SetCallback(set_Event_Callback pfn, void *arg); + void FreeManagedEvent(uint8_t category, uint8_t subCategory, uint16_t data1, uint32_t data2); void PostManagedEvent(uint8_t category, uint8_t subCategory, uint16_t data1, uint32_t data2); @@ -63,36 +57,39 @@ extern "C" { } #endif +__inline uint32_t Events_WaitForEvents(uint32_t wakeupSystemEvents, uint32_t timeoutMilliseconds) +{ + return Events_WaitForEvents(SLEEP_LEVEL__SLEEP, wakeupSystemEvents, timeoutMilliseconds); +} + //--// -typedef void (*PALEVENTLISTENER) (uint32_t e, uint32_t param); +typedef void (*PALEVENTLISTENER)(uint32_t e, uint32_t param); struct PalEventListener : public HAL_DblLinkedNode { PALEVENTLISTENER m_palEventListener; - uint32_t m_eventMask; + uint32_t m_eventMask; }; - HRESULT PalEvent_Initialize(); HRESULT PalEvent_Uninitialize(); HRESULT PalEvent_Post(uint32_t e, uint32_t param); -HRESULT PalEvent_Enlist(PalEventListener* listener); +HRESULT PalEvent_Enlist(PalEventListener *listener); //--// struct PalEventDriver { -public: - + public: HAL_DblLinkedList listenerList; static HRESULT Initialize(); static HRESULT Uninitialize(); static HRESULT PostEvent(uint32_t e, uint32_t param); - static HRESULT EnlistListener(PalEventListener* listener); + static HRESULT EnlistListener(PalEventListener *listener); -private: + private: static bool s_initialized; }; diff --git a/src/PAL/Include/nanoPAL_GPIO.h b/src/PAL/Include/nanoPAL_GPIO.h index c7ebbc1647..0aa8a2cd9f 100644 --- a/src/PAL/Include/nanoPAL_GPIO.h +++ b/src/PAL/Include/nanoPAL_GPIO.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/src/PAL/Include/nanoPAL_NativeDouble.h b/src/PAL/Include/nanoPAL_NativeDouble.h index 2f0657f8f2..b945019b04 100644 --- a/src/PAL/Include/nanoPAL_NativeDouble.h +++ b/src/PAL/Include/nanoPAL_NativeDouble.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/PAL/Include/nanoPAL_Network.h b/src/PAL/Include/nanoPAL_Network.h index a2d79034db..0b0ad505c5 100644 --- a/src/PAL/Include/nanoPAL_Network.h +++ b/src/PAL/Include/nanoPAL_Network.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // @@ -7,19 +7,22 @@ #ifndef _NETWORK_DECL_H_ #define _NETWORK_DECL_H_ 1 - #ifdef PLATFORM_DEPENDENT__SOCKETS_MAX_COUNT -#define SOCKETS_MAX_COUNT PLATFORM_DEPENDENT__SOCKETS_MAX_COUNT +#define SOCKETS_MAX_COUNT PLATFORM_DEPENDENT__SOCKETS_MAX_COUNT #else -#define SOCKETS_MAX_COUNT 1 // required to have at least one for array init +// required to have at least one for array init +//////////////////////////////////////////////////////////////////////////////////////////////////////// +// PLATFORM_DEPENDENT__SOCKETS_MAX_COUNT not defined at target or platform level, using default value // +//////////////////////////////////////////////////////////////////////////////////////////////////////// +#define SOCKETS_MAX_COUNT 1 #endif #ifdef PLATFORM_DEPENDENT__SOCKETS_MAX_SEND_LENGTH -#define SOCKETS_MAX_SEND_LENGTH PLATFORM_DEPENDENT__SOCKETS_MAX_SEND_LENGTH +#define SOCKETS_MAX_SEND_LENGTH PLATFORM_DEPENDENT__SOCKETS_MAX_SEND_LENGTH #endif #if !defined(DEBGGER_NETWORK_INTERFACE_INDEX) -#define DEBGGER_NETWORK_INTERFACE_INDEX 0 +#define DEBGGER_NETWORK_INTERFACE_INDEX 0 #endif #endif //_NETWORK_DECL_H_ diff --git a/src/PAL/Include/nanoPAL_PerformanceCounters.h b/src/PAL/Include/nanoPAL_PerformanceCounters.h index a068d5a85d..ed09043e73 100644 --- a/src/PAL/Include/nanoPAL_PerformanceCounters.h +++ b/src/PAL/Include/nanoPAL_PerformanceCounters.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/src/PAL/Include/nanoPAL_Sockets.h b/src/PAL/Include/nanoPAL_Sockets.h index 12c1cd3c34..bb59c468c5 100644 --- a/src/PAL/Include/nanoPAL_Sockets.h +++ b/src/PAL/Include/nanoPAL_Sockets.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/PAL/Include/nanoPAL_Time.h b/src/PAL/Include/nanoPAL_Time.h index 597427e365..0f29276815 100644 --- a/src/PAL/Include/nanoPAL_Time.h +++ b/src/PAL/Include/nanoPAL_Time.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/src/PAL/Lwip/lwIP_Sockets.cpp b/src/PAL/Lwip/lwIP_Sockets.cpp index 640b1ad76e..c463fc370a 100644 --- a/src/PAL/Lwip/lwIP_Sockets.cpp +++ b/src/PAL/Lwip/lwIP_Sockets.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/PAL/Lwip/lwIP_Sockets.h b/src/PAL/Lwip/lwIP_Sockets.h index 18bc841cc4..1b980d6778 100644 --- a/src/PAL/Lwip/lwIP_Sockets.h +++ b/src/PAL/Lwip/lwIP_Sockets.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/PAL/Lwip/lwIP_Sockets_functions.cpp b/src/PAL/Lwip/lwIP_Sockets_functions.cpp index e1e7317888..652e362281 100644 --- a/src/PAL/Lwip/lwIP_Sockets_functions.cpp +++ b/src/PAL/Lwip/lwIP_Sockets_functions.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/PAL/Profiler/nanoPAL_PerformanceCounters_stubs.cpp b/src/PAL/Profiler/nanoPAL_PerformanceCounters_stubs.cpp index ca72a4bbc3..93fee865d1 100644 --- a/src/PAL/Profiler/nanoPAL_PerformanceCounters_stubs.cpp +++ b/src/PAL/Profiler/nanoPAL_PerformanceCounters_stubs.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/PAL/nanoPAL_Network_stubs.cpp b/src/PAL/nanoPAL_Network_stubs.cpp index a079c544be..6ace25d5f6 100644 --- a/src/PAL/nanoPAL_Network_stubs.cpp +++ b/src/PAL/nanoPAL_Network_stubs.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/src/System.Device.Dac/sys_dev_dac_native.cpp b/src/System.Device.Dac/sys_dev_dac_native.cpp new file mode 100644 index 0000000000..5a99d45013 --- /dev/null +++ b/src/System.Device.Dac/sys_dev_dac_native.cpp @@ -0,0 +1,45 @@ +// +// Copyright (c) .NET Foundation and Contributors +// See LICENSE file in the project root for full license information. +// + +#include "sys_dev_dac_native.h" + +static const CLR_RT_MethodHandler method_lookup[] = { + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + Library_sys_dev_dac_native_System_Device_Dac_DacController::NativeOpenChannel___VOID__I4, + Library_sys_dev_dac_native_System_Device_Dac_DacController::NativeGetChannelCount___I4, + Library_sys_dev_dac_native_System_Device_Dac_DacController::NativeGetResolutionInBits___I4, + Library_sys_dev_dac_native_System_Device_Dac_DacController::NativeInit___VOID, + NULL, + NULL, + Library_sys_dev_dac_native_System_Device_Dac_DacController::GetDeviceSelector___STATIC__STRING, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + Library_sys_dev_dac_native_System_Device_Dac_DacChannel::NativeWriteValue___VOID__U2, + Library_sys_dev_dac_native_System_Device_Dac_DacChannel::NativeDispose___VOID__BOOLEAN, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, +}; + +const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_System_Device_Dac = + {"System.Device.Dac", 0x5ED97E79, method_lookup, {100, 0, 0, 6}}; diff --git a/src/System.Devices.Dac/sys_dev_dac_native.h b/src/System.Device.Dac/sys_dev_dac_native.h similarity index 78% rename from src/System.Devices.Dac/sys_dev_dac_native.h rename to src/System.Device.Dac/sys_dev_dac_native.h index 87aff514a4..bd23a9640b 100644 --- a/src/System.Devices.Dac/sys_dev_dac_native.h +++ b/src/System.Device.Dac/sys_dev_dac_native.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // @@ -10,7 +10,7 @@ #include #include -struct Library_sys_dev_dac_native_System_Devices_Dac_DacController +struct Library_sys_dev_dac_native_System_Device_Dac_DacController { static const int FIELD___syncLock = 1; static const int FIELD___controllerId = 2; @@ -23,10 +23,9 @@ struct Library_sys_dev_dac_native_System_Devices_Dac_DacController NANOCLR_NATIVE_DECLARE(GetDeviceSelector___STATIC__STRING); //--// - }; -struct Library_sys_dev_dac_native_System_Devices_Dac_DacChannel +struct Library_sys_dev_dac_native_System_Device_Dac_DacChannel { static const int FIELD___syncLock = 1; static const int FIELD___channelNumber = 2; @@ -37,18 +36,16 @@ struct Library_sys_dev_dac_native_System_Devices_Dac_DacChannel NANOCLR_NATIVE_DECLARE(NativeDispose___VOID__BOOLEAN); //--// - }; -struct Library_sys_dev_dac_native_System_Devices_Dac_DacControllerManager +struct Library_sys_dev_dac_native_System_Device_Dac_DacControllerManager { static const int FIELD_STATIC___syncLock = 0; static const int FIELD_STATIC__s_controllersCollection = 1; //--// - }; -extern const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_System_Devices_Dac; +extern const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_System_Device_Dac; -#endif //_SYS_DEV_DAC_NATIVE_H_ +#endif //_SYS_DEV_DAC_NATIVE_H_ diff --git a/src/System.Devices.Dac/sys_dev_dac_native.cpp b/src/System.Devices.Dac/sys_dev_dac_native.cpp deleted file mode 100644 index 69343dd323..0000000000 --- a/src/System.Devices.Dac/sys_dev_dac_native.cpp +++ /dev/null @@ -1,53 +0,0 @@ -// -// Copyright (c) 2019 The nanoFramework project contributors -// See LICENSE file in the project root for full license information. -// - - -#include "sys_dev_dac_native.h" - - -static const CLR_RT_MethodHandler method_lookup[] = -{ - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - Library_sys_dev_dac_native_System_Devices_Dac_DacController::NativeOpenChannel___VOID__I4, - Library_sys_dev_dac_native_System_Devices_Dac_DacController::NativeGetChannelCount___I4, - Library_sys_dev_dac_native_System_Devices_Dac_DacController::NativeGetResolutionInBits___I4, - Library_sys_dev_dac_native_System_Devices_Dac_DacController::NativeInit___VOID, - NULL, - NULL, - Library_sys_dev_dac_native_System_Devices_Dac_DacController::GetDeviceSelector___STATIC__STRING, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - Library_sys_dev_dac_native_System_Devices_Dac_DacChannel::NativeWriteValue___VOID__U2, - Library_sys_dev_dac_native_System_Devices_Dac_DacChannel::NativeDispose___VOID__BOOLEAN, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, -}; - -const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_System_Devices_Dac = -{ - "System.Devices.Dac", - 0x5ED97E79, - method_lookup, - { 100, 0, 0, 6 } -}; diff --git a/src/Windows.Devices.Adc/win_dev_adc_native.cpp b/src/Windows.Devices.Adc/win_dev_adc_native.cpp index ac08fe18fd..a63939461e 100644 --- a/src/Windows.Devices.Adc/win_dev_adc_native.cpp +++ b/src/Windows.Devices.Adc/win_dev_adc_native.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/src/Windows.Devices.Adc/win_dev_adc_native.h b/src/Windows.Devices.Adc/win_dev_adc_native.h index 42d84425c4..e76ea7e719 100644 --- a/src/Windows.Devices.Adc/win_dev_adc_native.h +++ b/src/Windows.Devices.Adc/win_dev_adc_native.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/src/Windows.Devices.Gpio/win_dev_gpio_native.cpp b/src/Windows.Devices.Gpio/win_dev_gpio_native.cpp index 7e6c8e75a4..ceb1d1f8c5 100644 --- a/src/Windows.Devices.Gpio/win_dev_gpio_native.cpp +++ b/src/Windows.Devices.Gpio/win_dev_gpio_native.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/Windows.Devices.Gpio/win_dev_gpio_native.h b/src/Windows.Devices.Gpio/win_dev_gpio_native.h index c184cefc01..6ec487cc1b 100644 --- a/src/Windows.Devices.Gpio/win_dev_gpio_native.h +++ b/src/Windows.Devices.Gpio/win_dev_gpio_native.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/Windows.Devices.Gpio/win_dev_gpio_native_Windows_Devices_Gpio_GpioController.cpp b/src/Windows.Devices.Gpio/win_dev_gpio_native_Windows_Devices_Gpio_GpioController.cpp index c8d1340ec8..0337d176cc 100644 --- a/src/Windows.Devices.Gpio/win_dev_gpio_native_Windows_Devices_Gpio_GpioController.cpp +++ b/src/Windows.Devices.Gpio/win_dev_gpio_native_Windows_Devices_Gpio_GpioController.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/Windows.Devices.Gpio/win_dev_gpio_native_Windows_Devices_Gpio_GpioPin.cpp b/src/Windows.Devices.Gpio/win_dev_gpio_native_Windows_Devices_Gpio_GpioPin.cpp index b2e5c8e167..d9483167e2 100644 --- a/src/Windows.Devices.Gpio/win_dev_gpio_native_Windows_Devices_Gpio_GpioPin.cpp +++ b/src/Windows.Devices.Gpio/win_dev_gpio_native_Windows_Devices_Gpio_GpioPin.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // @@ -12,247 +12,266 @@ /////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////// -void Gpio_Interupt_ISR(GPIO_PIN pinNumber, bool pinState, void* param ) +void Gpio_Interupt_ISR(GPIO_PIN pinNumber, bool pinState) { - NATIVE_INTERRUPT_START - - CLR_RT_HeapBlock *pThis = (CLR_RT_HeapBlock *)param; - if (pThis != NULL) - { - // check if object has been disposed - if (pThis[Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::FIELD___disposedValue].NumericByRef().u1 == 0) - { - // flag to determine if there are any callbacks registered in managed code - bool callbacksRegistered = (pThis[Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::FIELD___callbacks].Dereference() != NULL); - if (callbacksRegistered) - { - // if handle registered then post a managed event with the current pin reading - PostManagedEvent(EVENT_GPIO, 0, (uint16_t)pinNumber, (uint32_t)pinState); - } - } - } - - NATIVE_INTERRUPT_END + // if handle registered then post a managed event with the current pin reading + PostManagedEvent(EVENT_GPIO, 0, (uint16_t)pinNumber, (uint32_t)pinState); } -HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::Read___WindowsDevicesGpioGpioPinValue( CLR_RT_StackFrame& stack ) +HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::Read___WindowsDevicesGpioGpioPinValue( + CLR_RT_StackFrame &stack) { - NANOCLR_HEADER(); - { - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + NANOCLR_HEADER(); + { + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); - if(pThis[ Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::FIELD___disposedValue ].NumericByRef().u1 != 0) - { - NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); - } + if (pThis[Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::FIELD___disposedValue].NumericByRef().u1 != + 0) + { + NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); + } - GPIO_PIN pinNumber = (GPIO_PIN)pThis[ FIELD___pinNumber ].NumericByRefConst().s4; + GPIO_PIN pinNumber = (GPIO_PIN)pThis[FIELD___pinNumber].NumericByRefConst().s4; - stack.SetResult_I4( CPU_GPIO_GetPinState(pinNumber) ); - } - NANOCLR_NOCLEANUP(); + stack.SetResult_I4(CPU_GPIO_GetPinState(pinNumber)); + } + NANOCLR_NOCLEANUP(); } -HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::Toggle___VOID( CLR_RT_StackFrame& stack ) +HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::Toggle___VOID(CLR_RT_StackFrame &stack) { - NANOCLR_HEADER(); - { - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); - - // check if object has been disposed - if(pThis[ Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::FIELD___disposedValue ].NumericByRef().u1 != 0) - { - NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); - } - - GPIO_PIN pinNumber = (GPIO_PIN)pThis[ FIELD___pinNumber ].NumericByRefConst().s4; - GpioPinDriveMode driveMode = (GpioPinDriveMode)pThis[ FIELD___driveMode ].NumericByRefConst().s4; - - // sanity check for drive mode set to output so we don't mess up writing to an input pin - if (driveMode >= GpioPinDriveMode_Output) - { - // Not all lower level API offer a 'toggle', so need to rely on the last output value field and toggle that one - GpioPinValue newState = (GpioPinValue)(GpioPinValue_High ^ (GpioPinValue)pThis[ FIELD___lastOutputValue ].NumericByRef().s4); - - // ...write back to the GPIO... - CPU_GPIO_SetPinState(pinNumber, newState ); - - // ... and finally store it - pThis[ FIELD___lastOutputValue ].NumericByRef().s4 = newState; - } - } - NANOCLR_NOCLEANUP(); + NANOCLR_HEADER(); + { + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + + // check if object has been disposed + if (pThis[Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::FIELD___disposedValue].NumericByRef().u1 != + 0) + { + NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); + } + + GPIO_PIN pinNumber = (GPIO_PIN)pThis[FIELD___pinNumber].NumericByRefConst().s4; + GpioPinDriveMode driveMode = (GpioPinDriveMode)pThis[FIELD___driveMode].NumericByRefConst().s4; + + // sanity check for drive mode set to output so we don't mess up writing to an input pin + if (driveMode >= GpioPinDriveMode_Output) + { + // Not all lower level API offer a 'toggle', so need to rely on the last output value field and toggle that + // one + GpioPinValue newState = + (GpioPinValue)(GpioPinValue_High ^ (GpioPinValue)pThis[FIELD___lastOutputValue].NumericByRef().s4); + + // ...write back to the GPIO... + CPU_GPIO_SetPinState(pinNumber, newState); + + // ... and finally store it + pThis[FIELD___lastOutputValue].NumericByRef().s4 = newState; + } + } + NANOCLR_NOCLEANUP(); } -HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::DisposeNative___VOID( CLR_RT_StackFrame& stack ) +HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::DisposeNative___VOID(CLR_RT_StackFrame &stack) { - NANOCLR_HEADER(); - { - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); - - // set pin to input to save power - // clear interrupts - // releases the pin - GPIO_PIN pinNumber = (GPIO_PIN)pThis[ FIELD___pinNumber ].NumericByRefConst().s4; - - CPU_GPIO_DisablePin(pinNumber, GpioPinDriveMode_Input, 0) ; - } - NANOCLR_NOCLEANUP(); + NANOCLR_HEADER(); + { + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + + // set pin to input to save power + // clear interrupts + // releases the pin + GPIO_PIN pinNumber = (GPIO_PIN)pThis[FIELD___pinNumber].NumericByRefConst().s4; + + CPU_GPIO_DisablePin(pinNumber, GpioPinDriveMode_Input, 0); + } + NANOCLR_NOCLEANUP(); } -HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::NativeIsDriveModeSupported___BOOLEAN__WindowsDevicesGpioGpioPinDriveMode( CLR_RT_StackFrame& stack ) +HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin:: + NativeIsDriveModeSupported___BOOLEAN__WindowsDevicesGpioGpioPinDriveMode(CLR_RT_StackFrame &stack) { - NANOCLR_HEADER(); - { - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + NANOCLR_HEADER(); + { + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); - GPIO_PIN pinNumber = (GPIO_PIN)pThis[ FIELD___pinNumber ].NumericByRefConst().s4; + GPIO_PIN pinNumber = (GPIO_PIN)pThis[FIELD___pinNumber].NumericByRefConst().s4; - GpioPinDriveMode driveMode = (GpioPinDriveMode)stack.Arg1().NumericByRef().s4; + GpioPinDriveMode driveMode = (GpioPinDriveMode)stack.Arg1().NumericByRef().s4; - // Return value to the managed application - stack.SetResult_Boolean(CPU_GPIO_DriveModeSupported(pinNumber, driveMode)) ; - } - NANOCLR_NOCLEANUP(); + // Return value to the managed application + stack.SetResult_Boolean(CPU_GPIO_DriveModeSupported(pinNumber, driveMode)); + } + NANOCLR_NOCLEANUP(); } -HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::NativeSetDriveMode___VOID__WindowsDevicesGpioGpioPinDriveMode( CLR_RT_StackFrame& stack ) +HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin:: + NativeSetDriveMode___VOID__WindowsDevicesGpioGpioPinDriveMode(CLR_RT_StackFrame &stack) { - NANOCLR_HEADER(); - { - bool validPin; - CLR_UINT64 debounceTimeoutMilsec; - - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); - - if(pThis[ Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::FIELD___disposedValue ].NumericByRef().u1 != 0) - { - NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); - } - - GPIO_PIN pinNumber = (GPIO_PIN)pThis[ FIELD___pinNumber ].NumericByRefConst().s4; - GpioPinDriveMode driveMode = (GpioPinDriveMode)stack.Arg1().NumericByRef().s4; - - if (driveMode >= (int)GpioPinDriveMode_Output) - { - validPin = CPU_GPIO_EnableOutputPin(pinNumber, GpioPinValue_Low, driveMode); - } - else - { - NANOCLR_CHECK_HRESULT( ExtractDebounceTimeSpanValue(pThis[ FIELD___debounceTimeout ], debounceTimeoutMilsec ) ); - - validPin = CPU_GPIO_EnableInputPin(pinNumber, debounceTimeoutMilsec, Gpio_Interupt_ISR, (void*)pThis, GPIO_INT_EDGE_BOTH, driveMode); - } - - if (!validPin) - { - NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); - } - - // protect this from GC so that the callback is where it's supposed to - CLR_RT_ProtectFromGC gc( *pThis ); - - - } - NANOCLR_NOCLEANUP(); + NANOCLR_HEADER(); + { + bool validPin; + CLR_UINT64 debounceTimeoutMilsec; + bool callbacksRegistered = false; + + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + + if (pThis[Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::FIELD___disposedValue].NumericByRef().u1 != + 0) + { + NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); + } + + GPIO_PIN pinNumber = (GPIO_PIN)pThis[FIELD___pinNumber].NumericByRefConst().s4; + GpioPinDriveMode driveMode = (GpioPinDriveMode)stack.Arg1().NumericByRef().s4; + + if (driveMode >= (int)GpioPinDriveMode_Output) + { + validPin = CPU_GPIO_EnableOutputPin(pinNumber, GpioPinValue_Low, driveMode); + } + else + { + NANOCLR_CHECK_HRESULT(ExtractDebounceTimeSpanValue(pThis[FIELD___debounceTimeout], debounceTimeoutMilsec)); + + // flag to determine if there are any callbacks registered in managed code + // this is use to determine if there is any need to setup and process INT handler + callbacksRegistered = + (pThis[Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::FIELD___callbacks].Dereference() != + NULL); + + validPin = CPU_GPIO_EnableInputPin( + pinNumber, + debounceTimeoutMilsec, + callbacksRegistered ? Gpio_Interupt_ISR : NULL, + NULL, + GPIO_INT_EDGE_BOTH, + driveMode); + } + + if (!validPin) + { + NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); + } + + // protect this from GC so that the callback is where it's supposed to + CLR_RT_ProtectFromGC gc(*pThis); + } + NANOCLR_NOCLEANUP(); } -HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::NativeInit___BOOLEAN__I4( CLR_RT_StackFrame& stack ) +HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::NativeInit___BOOLEAN__I4(CLR_RT_StackFrame &stack) { - NANOCLR_HEADER(); - { - GPIO_PIN pinNumber = (GPIO_PIN)stack.Arg1().NumericByRef().s4; - - // Return value to the managed application - stack.SetResult_Boolean(CPU_GPIO_ReservePin(pinNumber, true)); - } - NANOCLR_NOCLEANUP_NOLABEL(); + NANOCLR_HEADER(); + { + GPIO_PIN pinNumber = (GPIO_PIN)stack.Arg1().NumericByRef().s4; + + // Return value to the managed application + stack.SetResult_Boolean(CPU_GPIO_ReservePin(pinNumber, true)); + } + NANOCLR_NOCLEANUP_NOLABEL(); } -HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::NativeSetDebounceTimeout___VOID( CLR_RT_StackFrame& stack ) +HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::NativeSetDebounceTimeout___VOID( + CLR_RT_StackFrame &stack) { - NANOCLR_HEADER(); - { - CLR_UINT64 debounceTimeoutMilsec; + NANOCLR_HEADER(); + { + CLR_UINT64 debounceTimeoutMilsec; - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); - GPIO_PIN pinNumber = (GPIO_PIN)pThis[ FIELD___pinNumber ].NumericByRefConst().s4; + GPIO_PIN pinNumber = (GPIO_PIN)pThis[FIELD___pinNumber].NumericByRefConst().s4; - NANOCLR_CHECK_HRESULT( ExtractDebounceTimeSpanValue(pThis[ FIELD___debounceTimeout ], debounceTimeoutMilsec ) ); + NANOCLR_CHECK_HRESULT(ExtractDebounceTimeSpanValue(pThis[FIELD___debounceTimeout], debounceTimeoutMilsec)); - // developer note: - // the following call will FAIL if the pin hasn't been previously setup as input - // that's OK because the debounce timeout will be eventually set when the pin is configured - CPU_GPIO_SetPinDebounce( pinNumber, debounceTimeoutMilsec ); - } - NANOCLR_NOCLEANUP(); + // developer note: + // the following call will FAIL if the pin hasn't been previously setup as input + // that's OK because the debounce timeout will be eventually set when the pin is configured + CPU_GPIO_SetPinDebounce(pinNumber, debounceTimeoutMilsec); + } + NANOCLR_NOCLEANUP(); } -HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::WriteNative___VOID__WindowsDevicesGpioGpioPinValue( CLR_RT_StackFrame& stack ) +HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::WriteNative___VOID__WindowsDevicesGpioGpioPinValue( + CLR_RT_StackFrame &stack) { - NANOCLR_HEADER(); - { - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); - - // check if object has been disposed - if(pThis[ Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::FIELD___disposedValue ].NumericByRef().u1 != 0) - { - NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); - } - - GPIO_PIN pinNumber = (GPIO_PIN)pThis[ FIELD___pinNumber ].NumericByRefConst().s4; - GpioPinDriveMode driveMode = (GpioPinDriveMode)pThis[ FIELD___driveMode ].NumericByRefConst().s4; - - GpioPinValue state = (GpioPinValue)stack.Arg1().NumericByRef().s4; - - // sanity check for drive mode set to output so we don't mess up writing to an input pin - if ((driveMode >= GpioPinDriveMode_Output) ) - { - CPU_GPIO_SetPinState(pinNumber, state ); - - // store the output value in the field - pThis[ FIELD___lastOutputValue ].NumericByRef().s4 = state; - } - else - { - NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); - } - } - NANOCLR_NOCLEANUP(); + NANOCLR_HEADER(); + { + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + + // check if object has been disposed + if (pThis[Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::FIELD___disposedValue].NumericByRef().u1 != + 0) + { + NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); + } + + GPIO_PIN pinNumber = (GPIO_PIN)pThis[FIELD___pinNumber].NumericByRefConst().s4; + GpioPinDriveMode driveMode = (GpioPinDriveMode)pThis[FIELD___driveMode].NumericByRefConst().s4; + + GpioPinValue state = (GpioPinValue)stack.Arg1().NumericByRef().s4; + + // sanity check for drive mode set to output so we don't mess up writing to an input pin + if ((driveMode >= GpioPinDriveMode_Output)) + { + CPU_GPIO_SetPinState(pinNumber, state); + + // store the output value in the field + pThis[FIELD___lastOutputValue].NumericByRef().s4 = state; + } + else + { + NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); + } + } + NANOCLR_NOCLEANUP(); } -HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::NativeSetAlternateFunction___VOID__I4( CLR_RT_StackFrame& stack ) +HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::NativeSetAlternateFunction___VOID__I4( + CLR_RT_StackFrame &stack) { - NANOCLR_HEADER(); - { - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); - - // check if object has been disposed - if(pThis[ Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::FIELD___disposedValue ].NumericByRef().u1 != 0) - { - NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); - } - - // get pin number and take the port and pad references from that one - int16_t pinNumber = pThis[ FIELD___pinNumber ].NumericByRefConst().s4; - - // get alternate function argument - int32_t alternateFunction = stack.Arg1().NumericByRef().s4; - - CPU_GPIO_DisablePin( pinNumber, GpioPinDriveMode_Input, alternateFunction); - } - NANOCLR_NOCLEANUP(); + NANOCLR_HEADER(); + { + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + + // check if object has been disposed + if (pThis[Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::FIELD___disposedValue].NumericByRef().u1 != + 0) + { + NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); + } + + // get pin number and take the port and pad references from that one + int16_t pinNumber = pThis[FIELD___pinNumber].NumericByRefConst().s4; + + // get alternate function argument + int32_t alternateFunction = stack.Arg1().NumericByRef().s4; + + CPU_GPIO_DisablePin(pinNumber, GpioPinDriveMode_Input, alternateFunction); + } + NANOCLR_NOCLEANUP(); } -HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::ExtractDebounceTimeSpanValue( CLR_RT_HeapBlock& timeSpanValue, CLR_UINT64& value ) +HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::ExtractDebounceTimeSpanValue( + CLR_RT_HeapBlock &timeSpanValue, + CLR_UINT64 &value) { NANOCLR_HEADER(); - { - // debounceTimeout field its a TimeSpan, which is a primitive type stored as an heap block, therefore needs to be accessed indirectly - CLR_INT64* debounceValue = Library_corlib_native_System_TimeSpan::GetValuePtr( timeSpanValue ); FAULT_ON_NULL(debounceValue); - - value = *(CLR_UINT64*)debounceValue / TIME_CONVERSION__TO_MILLISECONDS; - } - NANOCLR_NOCLEANUP(); + { + // debounceTimeout field its a TimeSpan, which is a primitive type stored as an heap block, therefore needs to + // be accessed indirectly + CLR_INT64 *debounceValue = Library_corlib_native_System_TimeSpan::GetValuePtr(timeSpanValue); + FAULT_ON_NULL(debounceValue); + + value = *(CLR_UINT64 *)debounceValue / TIME_CONVERSION__TO_MILLISECONDS; + } + NANOCLR_NOCLEANUP(); } diff --git a/src/Windows.Devices.I2c/win_dev_i2c_native.cpp b/src/Windows.Devices.I2c/win_dev_i2c_native.cpp index dd76489d99..b444050ff3 100644 --- a/src/Windows.Devices.I2c/win_dev_i2c_native.cpp +++ b/src/Windows.Devices.I2c/win_dev_i2c_native.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/src/Windows.Devices.I2c/win_dev_i2c_native.h b/src/Windows.Devices.I2c/win_dev_i2c_native.h index d288d65207..e4e04e2953 100644 --- a/src/Windows.Devices.I2c/win_dev_i2c_native.h +++ b/src/Windows.Devices.I2c/win_dev_i2c_native.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/src/Windows.Devices.Pwm/win_dev_pwm_native.cpp b/src/Windows.Devices.Pwm/win_dev_pwm_native.cpp index 3c1c27a1c5..2026b25386 100644 --- a/src/Windows.Devices.Pwm/win_dev_pwm_native.cpp +++ b/src/Windows.Devices.Pwm/win_dev_pwm_native.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/src/Windows.Devices.Pwm/win_dev_pwm_native.h b/src/Windows.Devices.Pwm/win_dev_pwm_native.h index 81c8bd748d..4f23069b23 100644 --- a/src/Windows.Devices.Pwm/win_dev_pwm_native.h +++ b/src/Windows.Devices.Pwm/win_dev_pwm_native.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/src/Windows.Devices.SerialCommunication/win_dev_serial_native.cpp b/src/Windows.Devices.SerialCommunication/win_dev_serial_native.cpp index 6bf829d48d..67f13842cb 100644 --- a/src/Windows.Devices.SerialCommunication/win_dev_serial_native.cpp +++ b/src/Windows.Devices.SerialCommunication/win_dev_serial_native.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/src/Windows.Devices.SerialCommunication/win_dev_serial_native.h b/src/Windows.Devices.SerialCommunication/win_dev_serial_native.h index 789d78edab..4c7e5ef8f6 100644 --- a/src/Windows.Devices.SerialCommunication/win_dev_serial_native.h +++ b/src/Windows.Devices.SerialCommunication/win_dev_serial_native.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/src/Windows.Devices.Spi/nanoHAL_Spi.cpp b/src/Windows.Devices.Spi/nanoHAL_Spi.cpp new file mode 100644 index 0000000000..6af4ce35b7 --- /dev/null +++ b/src/Windows.Devices.Spi/nanoHAL_Spi.cpp @@ -0,0 +1,365 @@ +// +// Copyright (c) .NET Foundation and Contributors +// Portions Copyright (c) Microsoft Corporation. All rights reserved. +// See LICENSE file in the project root for full license information. +// +// +// nano_SPI_xxxx +// +// Logical SPI device access +// +#include +#include + +#include +#include +#include + +// Create a handle built from device type, SPI bus number and device index +#define CreateSpiHandle(spiBusIndex, deviceIndex) ((CPU_DEVICE_TYPE_SPI << 16) + (spiBusIndex << 8) + deviceIndex) + +#define GetBusFromHandle(handle) ((handle >> 8) & 0x00ff); + +// Saved config for each available SPI bus +nanoSPI_BusConfig spiconfig[NUM_SPI_BUSES]; + +// Define weak functions for some optional PAL functions +// so low level implementations don't require them. +__nfweak bool CPU_SPI_Initialize(uint8_t bus) +{ + (void)bus; + return true; +} +__nfweak bool CPU_SPI_Uninitialize(uint8_t bus) +{ + (void)bus; + return true; +} +__nfweak SPI_OP_STATUS CPU_SPI_OP_Status(uint8_t spi_bus, uint32_t deviceHandle) +{ + (void)spi_bus; + (void)deviceHandle; + + return SPI_OP_STATUS::SPI_OP_COMPLETE; +} + +__nfweak uint32_t CPU_SPI_Add_Device(const SPI_DEVICE_CONFIGURATION &spiDeviceConfig) +{ + (void)spiDeviceConfig; + return 1; +} + +__nfweak bool CPU_SPI_Remove_Device(uint32_t deviceHandle) +{ + (void)deviceHandle; + return true; +}; + +// +// Number of SPI buses available +__nfweak uint32_t CPU_SPI_PortsCount() +{ + uint32_t count = 0; + uint32_t map = CPU_SPI_PortsMap(); + + while (map > 0) + { + if (map & 0x01) + count++; + map >>= 1; + } + return count; +} + +// Pins not know +__nfweak void CPU_SPI_GetPins(uint32_t spi_bus, GPIO_PIN &clockPin, GPIO_PIN &misoPin, GPIO_PIN &mosiPin) +{ + (void)spi_bus; + + clockPin = GPIO_PIN_NONE; + misoPin = GPIO_PIN_NONE; + mosiPin = GPIO_PIN_NONE; +} + +// +// Find the Bus / Device ptr from the handle +// +// return true = handle valid +static bool getDevice(uint32_t handle, uint8_t &spiBus, int &deviceIndex) +{ + int type = handle >> 16 & 0x00ff; + deviceIndex = handle & 0x00ff; + + spiBus = GetBusFromHandle(handle); + + // Validate type, bus, deviceIndex + if (type != CPU_DEVICE_TYPE_SPI || spiBus >= NUM_SPI_BUSES || deviceIndex >= NUM_SPI_BUSES) + return false; + + return true; +} + +// Find a free slot in the device table +// Return index or -1 if no free slots +static int FindFreeDeviceSlotSpi(int spiBus, GPIO_PIN cs) +{ + for (int deviceIndex = 0; deviceIndex < MAX_SPI_DEVICES; deviceIndex++) + { + if (spiconfig[spiBus].deviceHandles[deviceIndex] == 0) + return deviceIndex; + // Check device chip select not already in use + if (spiconfig[spiBus].deviceCongfig[deviceIndex].DeviceChipSelect == cs) + return -2; + } + return -1; +} + +// Initialise the spiconfig structure +// Called on CLR startup +bool nanoSPI_Initialize() +{ + for (int spiBus = 0; spiBus < NUM_SPI_BUSES; spiBus++) + { + spiconfig[spiBus].spiBusInited = false; + spiconfig[spiBus].devicesInUse = 0; + memset(&spiconfig[spiBus].deviceHandles, 0, sizeof(spiconfig[spiBus].deviceHandles)); + } + return true; +} + +// Uninitializes (resets) all SPI devices. +// Called on CLR closedown +void nanoSPI_Uninitialize() +{ + for (int spiBusIndex = 0; spiBusIndex < NUM_SPI_BUSES; spiBusIndex++) + { + if (spiconfig[spiBusIndex].spiBusInited) + { + // Remove any devices + // Bus will be closed when last device closed in SPI_CloseDevice + for (int deviceIndex = 0; deviceIndex < MAX_SPI_DEVICES; deviceIndex++) + { + uint32_t deviceHandle = spiconfig[spiBusIndex].deviceHandles[deviceIndex]; + if (deviceHandle != 0) + nanoSPI_CloseDevice(CreateSpiHandle(spiBusIndex, deviceIndex)); + } + } + } +} + +SPI_OP_STATUS nanoSPI_Op_Status(uint32_t handle) +{ + uint8_t spiBus; + int deviceIndex; + + getDevice(handle, spiBus, deviceIndex); + + SPI_OP_STATUS status = CPU_SPI_OP_Status(spiBus, spiconfig[spiBus].deviceHandles[deviceIndex]); + + return status; +} + +// Open SPI bus / device using device configuration +// Register GPIO pins as in use +// Return handle ( index to device on bus), negative = error +HRESULT nanoSPI_OpenDevice(SPI_DEVICE_CONFIGURATION &Configuration, uint32_t &handle) +{ + return nanoSPI_OpenDeviceEx(Configuration, handle, GPIO_PIN_NONE, GPIO_PIN_NONE, GPIO_PIN_NONE); +} + +// Reserve SPI bus pins +HRESULT nanoSPI_ReserveBusPins(int spiBus, bool reserve) +{ + GPIO_PIN pins[3]; + + CPU_SPI_GetPins(spiBus, pins[0], pins[1], pins[2]); + + if (reserve) + { + // if reserve , Check can reserve + for (int i = 0; i < 3; i++) + { + if (pins[0] != GPIO_PIN_NONE) + { + if (CPU_GPIO_PinIsBusy(pins[i])) + return CLR_E_INVALID_PARAMETER; + } + } + } + + // Reserve / UnReserve pins + for (int i = 0; i < 3; i++) + { + if (pins[i] != GPIO_PIN_NONE) + { + if (CPU_GPIO_ReservePin(pins[i], reserve) == false) + return CLR_E_INVALID_PARAMETER; + } + } + + return S_OK; +} + +// Specify alternate pins for SPI or -1 for use default for bus +HRESULT nanoSPI_OpenDeviceEx( + SPI_DEVICE_CONFIGURATION &spiDeviceConfig, + uint32_t &handle, + GPIO_PIN altMsk, + GPIO_PIN altMiso, + GPIO_PIN altMosi) +{ + // Use alternate pins if defined + // TODO params + (void)altMsk; + (void)altMiso; + (void)altMosi; + + int deviceIndex; + int32_t deviceHandle; + + // spiBus 0 to (number of buses - 1) + uint8_t spiBusIndex = (uint8_t)spiDeviceConfig.Spi_Bus - 1; + if (spiBusIndex >= NUM_SPI_BUSES) + return CLR_E_INVALID_PARAMETER; + + // Validate Bus available + if (!(CPU_SPI_PortsMap() & (1 << spiBusIndex))) + return CLR_E_INVALID_PARAMETER; + + // Check not maximum devices per SPI bus reached + if (spiconfig[spiBusIndex].devicesInUse >= MAX_SPI_DEVICES) + return CLR_E_INDEX_OUT_OF_RANGE; + + // Initialise Bus if not already initialised + if (!spiconfig[spiBusIndex].spiBusInited) + { + if (!CPU_SPI_Initialize(spiBusIndex)) + return CLR_E_INVALID_PARAMETER; + + // Reserve pins used by SPI bus + HRESULT hr = nanoSPI_ReserveBusPins(spiBusIndex, true); + if (hr != S_OK) + return hr; + + spiconfig[spiBusIndex].spiBusInited = true; + } + + // Find if device slot is available and check + deviceIndex = FindFreeDeviceSlotSpi(spiBusIndex, spiDeviceConfig.DeviceChipSelect); + if (deviceIndex < 0) + { + if (deviceIndex == -1) + // No device slots left + return CLR_E_INDEX_OUT_OF_RANGE; + else + // Return NOT_SUPPORTED when Device already in use. Not really any other relevant exception that's + // currently raised in managed code + return CLR_E_NOT_SUPPORTED; + } + + // Add device and get handle + deviceHandle = CPU_SPI_Add_Device(spiDeviceConfig); + if (deviceHandle != 0) + { + // Reserve chip select pin + if (CPU_GPIO_ReservePin((GPIO_PIN)spiDeviceConfig.DeviceChipSelect, true) == false) + { + // Failed to reserve CS pin + CPU_SPI_Remove_Device(deviceHandle); + return CLR_E_FAIL; + } + } + + // Add next Device - Copy device config, save handle, increment number devices on bus + nanoSPI_BusConfig *pBusConfig = &spiconfig[spiBusIndex]; + pBusConfig->deviceCongfig[deviceIndex] = spiDeviceConfig; + pBusConfig->deviceHandles[deviceIndex] = deviceHandle; + + // Compute rough estimate on the time to tx/rx a byte (in milliseconds) + // Used to compute length of time for each IO to see if this is a long running operation + // Store for each device as each device could use a different bit rate + pBusConfig->byteTime[deviceIndex] = (1.0 / spiDeviceConfig.Clock_RateHz) * 1000 * 8; + + pBusConfig->devicesInUse++; + + // Return unique generated device handle + handle = CreateSpiHandle(spiBusIndex, deviceIndex); + + return S_OK; +} + +// SPI_CloseDevice +// SPI_CloseDevice +// +// Close device on SPI bus +// +HRESULT nanoSPI_CloseDevice(uint32_t handle) +{ + uint8_t spiBus; + int deviceIndex; + + if (!getDevice(handle, spiBus, deviceIndex)) + return CLR_E_INVALID_PARAMETER; + + // Remove device from bus (ignore any error ) + CPU_SPI_Remove_Device(spiconfig[spiBus].deviceHandles[deviceIndex]); + + spiconfig[spiBus].deviceHandles[deviceIndex] = 0; + spiconfig[spiBus].devicesInUse--; + + // Unreserve CS pin + CPU_GPIO_ReservePin(spiconfig[spiBus].deviceCongfig->DeviceChipSelect, false); + + // Last device on bus then close bus and also remove bus pin reserves + if (spiconfig[spiBus].devicesInUse <= 0) + { + // Uninitialise bus and reset init flag + CPU_SPI_Uninitialize(spiBus); + spiconfig[spiBus].spiBusInited = false; + + // Unreserve bus pins + nanoSPI_ReserveBusPins(spiBus, false); + } + + return S_OK; +} + +// +// Get time to send 1 byte on bus using current config +// +float nanoSPI_GetByteTime(uint32_t handle) +{ + uint8_t spiBus; + int deviceIndex; + + getDevice(handle, spiBus, deviceIndex); + + return spiconfig[spiBus].byteTime[deviceIndex]; +} + +// +// Write and/or read data to device on SPi bus +// +HRESULT nanoSPI_Write_Read( + uint32_t handle, + SPI_WRITE_READ_SETTINGS &swrs, + uint8_t *writePtr, + int32_t wsize, + uint8_t *readPtr, + int32_t readSize) +{ + uint8_t spiBus; + int deviceIndex; + + if (!getDevice(handle, spiBus, deviceIndex)) + return CLR_E_INVALID_PARAMETER; + + return CPU_SPI_nWrite_nRead( + spiconfig[spiBus].deviceHandles[deviceIndex], + spiconfig[spiBus].deviceCongfig[deviceIndex], + swrs, + writePtr, + wsize, + readPtr, + readSize); +} diff --git a/src/Windows.Devices.Spi/win_dev_spi_native.cpp b/src/Windows.Devices.Spi/win_dev_spi_native.cpp index 7a5735358f..9b25588e8d 100644 --- a/src/Windows.Devices.Spi/win_dev_spi_native.cpp +++ b/src/Windows.Devices.Spi/win_dev_spi_native.cpp @@ -1,26 +1,23 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // - #include "win_dev_spi_native.h" - -static const CLR_RT_MethodHandler method_lookup[] = -{ - NULL, +static const CLR_RT_MethodHandler method_lookup[] = { NULL, NULL, NULL, NULL, NULL, NULL, - Library_win_dev_spi_native_Windows_Devices_Spi_SpiBusInfo::get_MaxClockFrequency___I4, - Library_win_dev_spi_native_Windows_Devices_Spi_SpiBusInfo::get_MinClockFrequency___I4, NULL, NULL, NULL, + Library_win_dev_spi_native_Windows_Devices_Spi_SpiBusInfo::NativeChipSelectLineCount___I4, + Library_win_dev_spi_native_Windows_Devices_Spi_SpiBusInfo::NativeMaxClockFrequency___I4, + Library_win_dev_spi_native_Windows_Devices_Spi_SpiBusInfo::NativeMinClockFrequency___I4, NULL, NULL, NULL, @@ -61,7 +58,7 @@ static const CLR_RT_MethodHandler method_lookup[] = Library_win_dev_spi_native_Windows_Devices_Spi_SpiDevice::NativeTransfer___VOID__SZARRAY_U1__SZARRAY_U1__BOOLEAN, Library_win_dev_spi_native_Windows_Devices_Spi_SpiDevice::NativeTransfer___VOID__SZARRAY_U2__SZARRAY_U2__BOOLEAN, Library_win_dev_spi_native_Windows_Devices_Spi_SpiDevice::NativeInit___VOID, - NULL, + Library_win_dev_spi_native_Windows_Devices_Spi_SpiDevice::NativeOpenDevice___I4, NULL, NULL, NULL, @@ -71,9 +68,4 @@ static const CLR_RT_MethodHandler method_lookup[] = }; const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_Windows_Devices_Spi = -{ - "Windows.Devices.Spi", - 0x59B5BFC3, - method_lookup, - { 100, 1, 4, 1 } -}; + {"Windows.Devices.Spi", 0x9C215530, method_lookup, {100, 1, 4, 2}}; diff --git a/src/Windows.Devices.Spi/win_dev_spi_native.h b/src/Windows.Devices.Spi/win_dev_spi_native.h index 7db0a8b294..bf22c4a11b 100644 --- a/src/Windows.Devices.Spi/win_dev_spi_native.h +++ b/src/Windows.Devices.Spi/win_dev_spi_native.h @@ -1,41 +1,27 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // - #ifndef _WIN_DEV_SPI_NATIVE_H_ #define _WIN_DEV_SPI_NATIVE_H_ - #include #include #include -#include -typedef enum __nfpack DataBitOrder -{ - DataBitOrder_MSB = 0, - DataBitOrder_LSB = 1, -} DataBitOrder; - -typedef enum __nfpack SpiMode -{ - SpiMode_Mode0 = 0, - SpiMode_Mode1 = 1, - SpiMode_Mode2 = 2, - SpiMode_Mode3 = 3, -} SpiMode; +/////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////// struct Library_win_dev_spi_native_Windows_Devices_Spi_SpiBusInfo { - static const int FIELD___chipSelectLineCount = 1; + static const int FIELD___controllerId = 1; - NANOCLR_NATIVE_DECLARE(get_MaxClockFrequency___I4); - NANOCLR_NATIVE_DECLARE(get_MinClockFrequency___I4); + NANOCLR_NATIVE_DECLARE(NativeChipSelectLineCount___I4); + NANOCLR_NATIVE_DECLARE(NativeMaxClockFrequency___I4); + NANOCLR_NATIVE_DECLARE(NativeMinClockFrequency___I4); //--// - }; struct Library_win_dev_spi_native_Windows_Devices_Spi_SpiConnectionSettings @@ -48,19 +34,16 @@ struct Library_win_dev_spi_native_Windows_Devices_Spi_SpiConnectionSettings static const int FIELD___bitOrder = 6; //--// - }; struct Library_win_dev_spi_native_Windows_Devices_Spi_SpiController { static const int FIELD___syncLock = 1; static const int FIELD___controllerId = 2; - static const int FIELD__s_deviceCollection = 3; NANOCLR_NATIVE_DECLARE(GetDeviceSelector___STATIC__STRING); //--// - }; struct Library_win_dev_spi_native_Windows_Devices_Spi_SpiControllerManager @@ -69,27 +52,27 @@ struct Library_win_dev_spi_native_Windows_Devices_Spi_SpiControllerManager static const int FIELD_STATIC__s_controllersCollection = 1; //--// - }; struct Library_win_dev_spi_native_Windows_Devices_Spi_SpiDevice { - static const int FIELD___syncLock = 1; - static const int FIELD___spiBus = 2; - static const int FIELD___deviceId = 3; - static const int FIELD___connectionSettings = 4; + static const int FIELD___deviceId = 1; + static const int FIELD___connectionSettings = 2; + static const int FIELD___spiController = 3; + static const int FIELD___syncLock = 4; static const int FIELD___disposedValue = 5; NANOCLR_NATIVE_DECLARE(DisposeNative___VOID); NANOCLR_NATIVE_DECLARE(NativeTransfer___VOID__SZARRAY_U1__SZARRAY_U1__BOOLEAN); NANOCLR_NATIVE_DECLARE(NativeTransfer___VOID__SZARRAY_U2__SZARRAY_U2__BOOLEAN); NANOCLR_NATIVE_DECLARE(NativeInit___VOID); + NANOCLR_NATIVE_DECLARE(NativeOpenDevice___I4); //--// - static HRESULT NativeTransfer(CLR_RT_StackFrame& stack, bool bufferIs16bits); + static HRESULT NativeTransfer(CLR_RT_StackFrame &stack, bool bufferIs16bits); }; extern const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_Windows_Devices_Spi; -#endif //_WIN_DEV_SPI_NATIVE_H_ +#endif //_WIN_DEV_SPI_NATIVE_H_ diff --git a/src/Windows.Devices.Spi/win_dev_spi_native_Windows_Devices_Spi_SpiBusInfo.cpp b/src/Windows.Devices.Spi/win_dev_spi_native_Windows_Devices_Spi_SpiBusInfo.cpp new file mode 100644 index 0000000000..bcffd3671c --- /dev/null +++ b/src/Windows.Devices.Spi/win_dev_spi_native_Windows_Devices_Spi_SpiBusInfo.cpp @@ -0,0 +1,54 @@ +// +// Copyright (c) .NET Foundation and Contributors +// See LICENSE file in the project root for full license information. +// + +#include "win_dev_spi_native_target.h" + +HRESULT Library_win_dev_spi_native_Windows_Devices_Spi_SpiBusInfo::NativeChipSelectLineCount___I4( + CLR_RT_StackFrame &stack) +{ + NANOCLR_HEADER(); + { + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + + int32_t controllerID = + pThis[Library_win_dev_spi_native_Windows_Devices_Spi_SpiBusInfo::FIELD___controllerId].NumericByRef().s4; + + stack.SetResult_I4(CPU_SPI_ChipSelectLineCount(controllerID)); + } + NANOCLR_NOCLEANUP(); +} + +HRESULT Library_win_dev_spi_native_Windows_Devices_Spi_SpiBusInfo::NativeMaxClockFrequency___I4( + CLR_RT_StackFrame &stack) +{ + NANOCLR_HEADER(); + { + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + + int32_t controllerID = + pThis[Library_win_dev_spi_native_Windows_Devices_Spi_SpiBusInfo::FIELD___controllerId].NumericByRef().s4; + + stack.SetResult_I4(CPU_SPI_MaxClockFrequency(controllerID)); + } + NANOCLR_NOCLEANUP(); +} + +HRESULT Library_win_dev_spi_native_Windows_Devices_Spi_SpiBusInfo::NativeMinClockFrequency___I4( + CLR_RT_StackFrame &stack) +{ + NANOCLR_HEADER(); + { + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + + int32_t controllerID = + pThis[Library_win_dev_spi_native_Windows_Devices_Spi_SpiBusInfo::FIELD___controllerId].NumericByRef().s4; + + stack.SetResult_I4(CPU_SPI_MinClockFrequency(controllerID)); + } + NANOCLR_NOCLEANUP(); +} diff --git a/src/Windows.Devices.Spi/win_dev_spi_native_Windows_Devices_Spi_SpiController.cpp b/src/Windows.Devices.Spi/win_dev_spi_native_Windows_Devices_Spi_SpiController.cpp new file mode 100644 index 0000000000..ae5e1ead15 --- /dev/null +++ b/src/Windows.Devices.Spi/win_dev_spi_native_Windows_Devices_Spi_SpiController.cpp @@ -0,0 +1,46 @@ +// +// Copyright (c) .NET Foundation and Contributors +// See LICENSE file in the project root for full license information. +// + +#include "win_dev_spi_native_target.h" + +HRESULT Library_win_dev_spi_native_Windows_Devices_Spi_SpiController::GetDeviceSelector___STATIC__STRING( + CLR_RT_StackFrame &stack) +{ + NANOCLR_HEADER(); + { + uint32_t spiCount = CPU_SPI_PortsCount(); + + // Length of string requird to return availble names + uint32_t spiMaxStringLength = spiCount * 5; + char *deviceSelectorString = (char *)platform_malloc(spiMaxStringLength + 1); + deviceSelectorString[0] = 0; // terminate in case no buses + + char busNum[2] = "1"; + + uint32_t spiMap = CPU_SPI_PortsMap(); + while (spiMap > 0) + { + if (spiMap & 0x01) + { + strcat(deviceSelectorString, "SPI"); + strcat(deviceSelectorString, busNum); + if (spiMap > 1) + { + strcat(deviceSelectorString, ","); + } + } + spiMap >>= 1; + busNum[0] += 1; + } + + // because the caller is expecting a result to be returned + // we need set a return result in the stack argument using the appropriate SetResult according to the variable + // type (a string here) + NANOCLR_CHECK_HRESULT(stack.SetResult_String(deviceSelectorString)); + + platform_free(deviceSelectorString); + } + NANOCLR_NOCLEANUP(); +} diff --git a/src/Windows.Devices.Spi/win_dev_spi_native_Windows_Devices_Spi_SpiDevice.cpp b/src/Windows.Devices.Spi/win_dev_spi_native_Windows_Devices_Spi_SpiDevice.cpp new file mode 100644 index 0000000000..7a6aa208f4 --- /dev/null +++ b/src/Windows.Devices.Spi/win_dev_spi_native_Windows_Devices_Spi_SpiDevice.cpp @@ -0,0 +1,303 @@ +// +// Copyright (c) .NET Foundation and Contributors +// See LICENSE file in the project root for full license information. +// + +#include +#include +#include "win_dev_spi_native_target.h" + +// define this type here to make it shorter and improve code readability +typedef Library_win_dev_spi_native_Windows_Devices_Spi_SpiConnectionSettings SpiConnectionSettings; + +void nano_spi_callback(int busIndex) +{ + (void)busIndex; + + // fire event for SPI transaction complete + Events_Set(SYSTEM_EVENT_FLAG_SPI_MASTER); +} + +// estimate the time required to perform the SPI transaction +// TODO doesn't take into account of full duplex or sequential ( assumes sequential at the moment ) +bool IsLongRunningOperation( + uint32_t writeSize, + uint32_t readSize, + bool fullDuplex, + bool bufferIs16bits, + float byteTime, + uint32_t &estimatedDurationMiliseconds) +{ + if (bufferIs16bits) + { + // double the buffers size + writeSize = 2 * writeSize; + readSize = 2 * readSize; + } + + if (fullDuplex) + { + estimatedDurationMiliseconds = byteTime * MAX(writeSize, readSize); + } + else + { + estimatedDurationMiliseconds = byteTime * (writeSize + readSize); + } + + if (estimatedDurationMiliseconds > CLR_RT_Thread::c_TimeQuantum_Milliseconds) + { + // total operation time will exceed thread quantum, so this is a long running operation + return true; + } + else + { + return false; + } +} + +HRESULT Library_win_dev_spi_native_Windows_Devices_Spi_SpiDevice:: + NativeTransfer___VOID__SZARRAY_U1__SZARRAY_U1__BOOLEAN(CLR_RT_StackFrame &stack) +{ + return NativeTransfer(stack, false); +} + +HRESULT Library_win_dev_spi_native_Windows_Devices_Spi_SpiDevice:: + NativeTransfer___VOID__SZARRAY_U2__SZARRAY_U2__BOOLEAN(CLR_RT_StackFrame &stack) +{ + return NativeTransfer(stack, true); +} + +HRESULT Library_win_dev_spi_native_Windows_Devices_Spi_SpiDevice::NativeTransfer( + CLR_RT_StackFrame &stack, + bool data16Bits) +{ + NANOCLR_HEADER(); + { + unsigned char *writeData = NULL; + unsigned char *readData = NULL; + int writeSize = 0; + int readSize = 0; + SPI_WRITE_READ_SETTINGS rws; + + bool isLongRunningOperation; + uint32_t estimatedDurationMiliseconds; + CLR_RT_HeapBlock hbTimeout; + CLR_INT64 *timeout; + bool eventResult = true; + + // get a pointer to the managed object instance and check that it's not NULL + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + + // get device handle saved on open + uint32_t deviceId = + pThis[Library_win_dev_spi_native_Windows_Devices_Spi_SpiDevice::FIELD___deviceId].NumericByRef().u4; + + if (stack.m_customState == 0) + { + // get a pointer to the managed spi connectionSettings object instance + CLR_RT_HeapBlock *pConfig = pThis[FIELD___connectionSettings].Dereference(); + + // get data bit length + int databitLength = pConfig[SpiConnectionSettings::FIELD___databitLength].NumericByRef().s4; + if (databitLength <= 0) + databitLength = 8; + if (data16Bits) + databitLength = 16; + + // dereference the write and read buffers from the arguments + CLR_RT_HeapBlock_Array *writeBuffer = stack.Arg1().DereferenceArray(); + if (writeBuffer != NULL) + { + // grab the pointer to the array by getting the first element of the array + if (data16Bits) + writeData = (unsigned char *)writeBuffer->GetFirstElementUInt16(); + else + writeData = writeBuffer->GetFirstElement(); + + // get the size of the buffer by reading the number of elements in the HeapBlock array + writeSize = writeBuffer->m_numOfElements; + } + + CLR_RT_HeapBlock_Array *readBuffer = stack.Arg2().DereferenceArray(); + if (readBuffer != NULL) + { + // grab the pointer to the array by getting the first element of the array + if (data16Bits) + readData = (unsigned char *)readBuffer->GetFirstElementUInt16(); + else + readData = readBuffer->GetFirstElement(); + + // get the size of the buffer by reading the number of elements in the HeapBlock array + readSize = readBuffer->m_numOfElements; + } + + // Are we using SPI full-duplex for transfer ? + bool fullDuplex = (bool)stack.Arg3().NumericByRef().u1; + + // Only tranfer in 16 bit if Buffer and request are for 16 bit + bool dataTransfer16 = + (pConfig[SpiConnectionSettings::FIELD___databitLength].NumericByRef().s4 == 16) && data16Bits; + + // Set up read/write settings for SPI_Write_Read call + rws = {fullDuplex, 0, dataTransfer16, 0}; + + // Check to see if we should run async so as not to hold up other tasks + isLongRunningOperation = IsLongRunningOperation( + writeSize, + readSize, + fullDuplex, + data16Bits, + nanoSPI_GetByteTime(deviceId), + (uint32_t &)estimatedDurationMiliseconds); + + if (isLongRunningOperation) + { + // if this is a long running operation, set a timeout equal to the estimated transaction duration in + // milliseconds this value has to be in ticks to be properly loaded by SetupTimeoutFromTicks() below + + // Use twice the estimated Duration as timeout + estimatedDurationMiliseconds *= 2; + + hbTimeout.SetInteger((CLR_INT64)estimatedDurationMiliseconds * TIME_CONVERSION__TO_MILLISECONDS); + + // if m_customState == 0 then push timeout on to eval stack[0] then move to m_customState = 1 + // Return current timeout value + NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks(hbTimeout, timeout)); + + // protect the buffers from GC so DMA can find them where they are supposed to be + if (writeBuffer != NULL) + CLR_RT_ProtectFromGC gcWriteBuffer(*writeBuffer); + if (readBuffer != NULL) + CLR_RT_ProtectFromGC gcReadBuffer(*readBuffer); + + // Set callback for async calls to nano spi + rws.callback = nano_spi_callback; + } + + // Start SPI transfer + // We can ask for async transfer by setting callback but it depends if underlying supports it + // return of CLR_E_BUSY means async started + hr = nanoSPI_Write_Read( + deviceId, + rws, + (uint8_t *)writeData, + (int32_t)writeSize, + (uint8_t *)readData, + (int32_t)readSize); + + // Async transfer started, go to custom 2 state ( wait completion ) + if (hr == CLR_E_BUSY) + { + stack.m_customState = 2; + } + } + + // Waiting for Async operation to complete + if (stack.m_customState == 2) + { + // Get timeout from eval stack we set up + stack.SetupTimeoutFromTicks(hbTimeout, timeout); + + while (eventResult) + { + // Has it completed ? + if (nanoSPI_Op_Status(deviceId) == SPI_OP_COMPLETE) + { + // SPI driver is ready meaning that the SPI transaction(s) is(are) completed + break; + } + + // non-blocking wait allowing other threads to run while we wait for the Spi transaction to complete + NANOCLR_CHECK_HRESULT( + g_CLR_RT_ExecutionEngine.WaitEvents(stack.m_owningThread, *timeout, Event_SpiMaster, eventResult)); + + if (!eventResult) + { + // Timeout + NANOCLR_SET_AND_LEAVE(CLR_E_TIMEOUT); + } + } + + // pop timeout heap block from stack + stack.PopValue(); + + // null pointers and vars + pThis = NULL; + } + } + + NANOCLR_NOCLEANUP(); +} + +HRESULT Library_win_dev_spi_native_Windows_Devices_Spi_SpiDevice::NativeOpenDevice___I4(CLR_RT_StackFrame &stack) +{ + { + NANOCLR_HEADER(); + { + int32_t controllerID; + SPI_DEVICE_CONFIGURATION spiConfig; + + // get a pointer to the managed object instance and check that it's not NULL + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + + // Get reference to manage code SPI controller + CLR_RT_HeapBlock *controller = + pThis[Library_win_dev_spi_native_Windows_Devices_Spi_SpiDevice::FIELD___spiController].Dereference(); + + controllerID = + controller[Library_win_dev_spi_native_Windows_Devices_Spi_SpiController::FIELD___controllerId] + .NumericByRef() + .s4; + // Get reference to manage code SPI settings + CLR_RT_HeapBlock *config = + pThis[Library_win_dev_spi_native_Windows_Devices_Spi_SpiDevice::FIELD___connectionSettings] + .Dereference(); + + // bus zero based + spiConfig.BusMode = SpiBusMode_master; + spiConfig.Spi_Bus = controllerID; + spiConfig.DeviceChipSelect = config[SpiConnectionSettings::FIELD___csLine].NumericByRef().s4; + spiConfig.ChipSelectActive = false; // TODO - is this something we would like to expose to managed code + spiConfig.Spi_Mode = (SpiMode)config[SpiConnectionSettings::FIELD___spiMode].NumericByRef().s4; + spiConfig.DataOrder16 = (DataBitOrder)config[SpiConnectionSettings::FIELD___bitOrder].NumericByRef().s4; + spiConfig.Clock_RateHz = config[SpiConnectionSettings::FIELD___clockFrequency].NumericByRef().s4; + + // Returns handle to device + uint32_t handle; + + hr = nanoSPI_OpenDevice(spiConfig, handle); + NANOCLR_CHECK_HRESULT(hr); + + // Return device handle + stack.SetResult_I4(handle); + } + NANOCLR_NOCLEANUP(); + } +} + +HRESULT Library_win_dev_spi_native_Windows_Devices_Spi_SpiDevice::NativeInit___VOID(CLR_RT_StackFrame &stack) +{ + NANOCLR_HEADER(); + { + (void)stack; + } + NANOCLR_NOCLEANUP_NOLABEL(); +} + +HRESULT Library_win_dev_spi_native_Windows_Devices_Spi_SpiDevice::DisposeNative___VOID(CLR_RT_StackFrame &stack) +{ + NANOCLR_HEADER(); + { + // get a pointer to the managed object instance and check that it's not NULL + CLR_RT_HeapBlock *pThis = stack.This(); + + // get device handle + int32_t deviceId = + pThis[Library_win_dev_spi_native_Windows_Devices_Spi_SpiDevice::FIELD___deviceId].NumericByRef().s4; + + nanoSPI_CloseDevice(deviceId); + } + NANOCLR_NOCLEANUP_NOLABEL(); +} diff --git a/src/Windows.Devices.Wifi/win_dev_wifi_native.cpp b/src/Windows.Devices.Wifi/win_dev_wifi_native.cpp index 1cdf0f4395..5a64df5ef9 100644 --- a/src/Windows.Devices.Wifi/win_dev_wifi_native.cpp +++ b/src/Windows.Devices.Wifi/win_dev_wifi_native.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/src/Windows.Devices.Wifi/win_dev_wifi_native.h b/src/Windows.Devices.Wifi/win_dev_wifi_native.h index 5db41185e3..ba60b5fdd2 100644 --- a/src/Windows.Devices.Wifi/win_dev_wifi_native.h +++ b/src/Windows.Devices.Wifi/win_dev_wifi_native.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/src/Windows.Networking.Sockets/win_net_sockets_native.cpp b/src/Windows.Networking.Sockets/win_net_sockets_native.cpp index cc85cebb7f..eda26e044e 100644 --- a/src/Windows.Networking.Sockets/win_net_sockets_native.cpp +++ b/src/Windows.Networking.Sockets/win_net_sockets_native.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/Windows.Networking.Sockets/win_net_sockets_native.h b/src/Windows.Networking.Sockets/win_net_sockets_native.h index 9b2d9775de..ec02e53527 100644 --- a/src/Windows.Networking.Sockets/win_net_sockets_native.h +++ b/src/Windows.Networking.Sockets/win_net_sockets_native.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. //--------------------------------------------------------------------------- diff --git a/src/Windows.Storage/win_storage_native.cpp b/src/Windows.Storage/win_storage_native.cpp index 9c3500caf3..5423754b14 100644 --- a/src/Windows.Storage/win_storage_native.cpp +++ b/src/Windows.Storage/win_storage_native.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/src/Windows.Storage/win_storage_native.h b/src/Windows.Storage/win_storage_native.h index f158bb7b9e..b5653eb65a 100644 --- a/src/Windows.Storage/win_storage_native.h +++ b/src/Windows.Storage/win_storage_native.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/src/nanoFramework.Devices.Can/nf_devices_can_native.cpp b/src/nanoFramework.Devices.Can/nf_devices_can_native.cpp index 89a57b490e..12ee83bd80 100644 --- a/src/nanoFramework.Devices.Can/nf_devices_can_native.cpp +++ b/src/nanoFramework.Devices.Can/nf_devices_can_native.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/src/nanoFramework.Devices.Can/nf_devices_can_native.h b/src/nanoFramework.Devices.Can/nf_devices_can_native.h index d83bdf5f87..d3c34f2386 100644 --- a/src/nanoFramework.Devices.Can/nf_devices_can_native.h +++ b/src/nanoFramework.Devices.Can/nf_devices_can_native.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/src/nanoFramework.Devices.OneWire/nf_devices_onewire_native.cpp b/src/nanoFramework.Devices.OneWire/nf_devices_onewire_native.cpp index daa5ac1c1b..acb5993ef2 100644 --- a/src/nanoFramework.Devices.OneWire/nf_devices_onewire_native.cpp +++ b/src/nanoFramework.Devices.OneWire/nf_devices_onewire_native.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/src/nanoFramework.Devices.OneWire/nf_devices_onewire_native.h b/src/nanoFramework.Devices.OneWire/nf_devices_onewire_native.h index 176f4681a8..31a7561e67 100644 --- a/src/nanoFramework.Devices.OneWire/nf_devices_onewire_native.h +++ b/src/nanoFramework.Devices.OneWire/nf_devices_onewire_native.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/src/nanoFramework.ResourceManager/nf_system_resourcemanager.cpp b/src/nanoFramework.ResourceManager/nf_system_resourcemanager.cpp index fe3ee0161f..da132248d3 100644 --- a/src/nanoFramework.ResourceManager/nf_system_resourcemanager.cpp +++ b/src/nanoFramework.ResourceManager/nf_system_resourcemanager.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/nanoFramework.ResourceManager/nf_system_resourcemanager.h b/src/nanoFramework.ResourceManager/nf_system_resourcemanager.h index ceb8878278..787d6a51d8 100644 --- a/src/nanoFramework.ResourceManager/nf_system_resourcemanager.h +++ b/src/nanoFramework.ResourceManager/nf_system_resourcemanager.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/nanoFramework.ResourceManager/nf_system_resourcemanager_System_Resources_ResourceManager.cpp b/src/nanoFramework.ResourceManager/nf_system_resourcemanager_System_Resources_ResourceManager.cpp index 7bc08ed8a8..fe0d6ee06a 100644 --- a/src/nanoFramework.ResourceManager/nf_system_resourcemanager_System_Resources_ResourceManager.cpp +++ b/src/nanoFramework.ResourceManager/nf_system_resourcemanager_System_Resources_ResourceManager.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/nanoFramework.ResourceManager/nf_system_resourcemanager_nanoFramework_Runtime_Native_ResourceUtility.cpp b/src/nanoFramework.ResourceManager/nf_system_resourcemanager_nanoFramework_Runtime_Native_ResourceUtility.cpp index dadd9e0be3..c8df4e9c14 100644 --- a/src/nanoFramework.ResourceManager/nf_system_resourcemanager_nanoFramework_Runtime_Native_ResourceUtility.cpp +++ b/src/nanoFramework.ResourceManager/nf_system_resourcemanager_nanoFramework_Runtime_Native_ResourceUtility.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/nanoFramework.Runtime.Events/nf_rt_events_native.cpp b/src/nanoFramework.Runtime.Events/nf_rt_events_native.cpp index aea3384006..964411bff5 100644 --- a/src/nanoFramework.Runtime.Events/nf_rt_events_native.cpp +++ b/src/nanoFramework.Runtime.Events/nf_rt_events_native.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/nanoFramework.Runtime.Events/nf_rt_events_native.h b/src/nanoFramework.Runtime.Events/nf_rt_events_native.h index edf2c48b92..eafbd2c773 100644 --- a/src/nanoFramework.Runtime.Events/nf_rt_events_native.h +++ b/src/nanoFramework.Runtime.Events/nf_rt_events_native.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/nanoFramework.Runtime.Events/nf_rt_events_native_nanoFramework_Runtime_Events_EventSink.cpp b/src/nanoFramework.Runtime.Events/nf_rt_events_native_nanoFramework_Runtime_Events_EventSink.cpp index 05593f92d4..22aabf500c 100644 --- a/src/nanoFramework.Runtime.Events/nf_rt_events_native_nanoFramework_Runtime_Events_EventSink.cpp +++ b/src/nanoFramework.Runtime.Events/nf_rt_events_native_nanoFramework_Runtime_Events_EventSink.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/nanoFramework.Runtime.Events/nf_rt_events_native_nanoFramework_Runtime_Events_NativeEventDispatcher.cpp b/src/nanoFramework.Runtime.Events/nf_rt_events_native_nanoFramework_Runtime_Events_NativeEventDispatcher.cpp index 9dd7d31578..988e9a28be 100644 --- a/src/nanoFramework.Runtime.Events/nf_rt_events_native_nanoFramework_Runtime_Events_NativeEventDispatcher.cpp +++ b/src/nanoFramework.Runtime.Events/nf_rt_events_native_nanoFramework_Runtime_Events_NativeEventDispatcher.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/nanoFramework.Runtime.Events/nf_rt_events_native_nanoFramework_Runtime_Events_WeakDelegate.cpp b/src/nanoFramework.Runtime.Events/nf_rt_events_native_nanoFramework_Runtime_Events_WeakDelegate.cpp index b8b6f4bb9e..80ba5aca13 100644 --- a/src/nanoFramework.Runtime.Events/nf_rt_events_native_nanoFramework_Runtime_Events_WeakDelegate.cpp +++ b/src/nanoFramework.Runtime.Events/nf_rt_events_native_nanoFramework_Runtime_Events_WeakDelegate.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/nanoFramework.Runtime.Native/nf_rt_native.cpp b/src/nanoFramework.Runtime.Native/nf_rt_native.cpp index f7f662b2e1..e435383708 100644 --- a/src/nanoFramework.Runtime.Native/nf_rt_native.cpp +++ b/src/nanoFramework.Runtime.Native/nf_rt_native.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/nanoFramework.Runtime.Native/nf_rt_native.h b/src/nanoFramework.Runtime.Native/nf_rt_native.h index 855b7765c6..49a4f479e1 100644 --- a/src/nanoFramework.Runtime.Native/nf_rt_native.h +++ b/src/nanoFramework.Runtime.Native/nf_rt_native.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/nanoFramework.Runtime.Native/nf_rt_native_nanoFramework_Runtime_Hardware_SystemInfo.cpp b/src/nanoFramework.Runtime.Native/nf_rt_native_nanoFramework_Runtime_Hardware_SystemInfo.cpp index 520332336f..071b9c8ebe 100644 --- a/src/nanoFramework.Runtime.Native/nf_rt_native_nanoFramework_Runtime_Hardware_SystemInfo.cpp +++ b/src/nanoFramework.Runtime.Native/nf_rt_native_nanoFramework_Runtime_Hardware_SystemInfo.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/nanoFramework.Runtime.Native/nf_rt_native_nanoFramework_Runtime_Native_ExecutionConstraint.cpp b/src/nanoFramework.Runtime.Native/nf_rt_native_nanoFramework_Runtime_Native_ExecutionConstraint.cpp index 326b32bb85..be119ef474 100644 --- a/src/nanoFramework.Runtime.Native/nf_rt_native_nanoFramework_Runtime_Native_ExecutionConstraint.cpp +++ b/src/nanoFramework.Runtime.Native/nf_rt_native_nanoFramework_Runtime_Native_ExecutionConstraint.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/nanoFramework.Runtime.Native/nf_rt_native_nanoFramework_Runtime_Native_GC.cpp b/src/nanoFramework.Runtime.Native/nf_rt_native_nanoFramework_Runtime_Native_GC.cpp index 92528d1248..ece7219695 100644 --- a/src/nanoFramework.Runtime.Native/nf_rt_native_nanoFramework_Runtime_Native_GC.cpp +++ b/src/nanoFramework.Runtime.Native/nf_rt_native_nanoFramework_Runtime_Native_GC.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/nanoFramework.Runtime.Native/nf_rt_native_nanoFramework_Runtime_Native_Power.cpp b/src/nanoFramework.Runtime.Native/nf_rt_native_nanoFramework_Runtime_Native_Power.cpp index 2d49398caf..07d3576a4d 100644 --- a/src/nanoFramework.Runtime.Native/nf_rt_native_nanoFramework_Runtime_Native_Power.cpp +++ b/src/nanoFramework.Runtime.Native/nf_rt_native_nanoFramework_Runtime_Native_Power.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/src/nanoFramework.Runtime.Native/nf_rt_native_nanoFramework_Runtime_Native_Rtc_stubs.cpp b/src/nanoFramework.Runtime.Native/nf_rt_native_nanoFramework_Runtime_Native_Rtc_stubs.cpp index ec344dcd4c..91e63416a6 100644 --- a/src/nanoFramework.Runtime.Native/nf_rt_native_nanoFramework_Runtime_Native_Rtc_stubs.cpp +++ b/src/nanoFramework.Runtime.Native/nf_rt_native_nanoFramework_Runtime_Native_Rtc_stubs.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/src/nanoFramework.System.Collections/nf_system_collections.h b/src/nanoFramework.System.Collections/nf_system_collections.h index 7d1916f0da..73dca7e534 100644 --- a/src/nanoFramework.System.Collections/nf_system_collections.h +++ b/src/nanoFramework.System.Collections/nf_system_collections.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/nanoFramework.System.Collections/nf_system_collections_System_Collections_Queue.cpp b/src/nanoFramework.System.Collections/nf_system_collections_System_Collections_Queue.cpp index 0363fd274a..e35c3c47cf 100644 --- a/src/nanoFramework.System.Collections/nf_system_collections_System_Collections_Queue.cpp +++ b/src/nanoFramework.System.Collections/nf_system_collections_System_Collections_Queue.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/nanoFramework.System.Collections/nf_system_collections_System_Collections_Stack.cpp b/src/nanoFramework.System.Collections/nf_system_collections_System_Collections_Stack.cpp index d5449c2463..48de996c1a 100644 --- a/src/nanoFramework.System.Collections/nf_system_collections_System_Collections_Stack.cpp +++ b/src/nanoFramework.System.Collections/nf_system_collections_System_Collections_Stack.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/nanoFramework.System.Text/nf_system_text.cpp b/src/nanoFramework.System.Text/nf_system_text.cpp index 6ed024c92f..c490786f3f 100644 --- a/src/nanoFramework.System.Text/nf_system_text.cpp +++ b/src/nanoFramework.System.Text/nf_system_text.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/src/nanoFramework.System.Text/nf_system_text.h b/src/nanoFramework.System.Text/nf_system_text.h index b51f5823e8..64d6cd4146 100644 --- a/src/nanoFramework.System.Text/nf_system_text.h +++ b/src/nanoFramework.System.Text/nf_system_text.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/src/nanoFramework.System.Text/nf_system_text_System_Text_UTF8Decoder.cpp b/src/nanoFramework.System.Text/nf_system_text_System_Text_UTF8Decoder.cpp index 7ec1235f85..2c6242dc0e 100644 --- a/src/nanoFramework.System.Text/nf_system_text_System_Text_UTF8Decoder.cpp +++ b/src/nanoFramework.System.Text/nf_system_text_System_Text_UTF8Decoder.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/src/nanoFramework.System.Text/nf_system_text_System_Text_UTF8Encoding.cpp b/src/nanoFramework.System.Text/nf_system_text_System_Text_UTF8Encoding.cpp index 68e9f78df7..29a9636aac 100644 --- a/src/nanoFramework.System.Text/nf_system_text_System_Text_UTF8Encoding.cpp +++ b/src/nanoFramework.System.Text/nf_system_text_System_Text_UTF8Encoding.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets-community b/targets-community index 4fc299d152..5bea59807c 160000 --- a/targets-community +++ b/targets-community @@ -1 +1 @@ -Subproject commit 4fc299d152b2507f5ea8984abe584aab38cd5a2d +Subproject commit 5bea59807c04d7edd415239cece52e3ff9a6bd99 diff --git a/targets/CMSIS-OS/ChibiOS/CMakeLists.txt b/targets/CMSIS-OS/ChibiOS/CMakeLists.txt index 93e38c6f32..320ae043dd 100644 --- a/targets/CMSIS-OS/ChibiOS/CMakeLists.txt +++ b/targets/CMSIS-OS/ChibiOS/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # @@ -23,11 +23,11 @@ if(DEFINED TOOL_HEX2DFU_PREFIX) endif() endif() -# check if CHIBIOS_SOURCE was specified or if it's empty (default is empty) -set(NO_CHIBIOS_SOURCE TRUE) -if(CHIBIOS_SOURCE) - if(NOT "${CHIBIOS_SOURCE}" STREQUAL "") - set(NO_CHIBIOS_SOURCE FALSE) +# check if RTOS_SOURCE_FOLDER was specified or if it's empty (default is empty) +set(NO_RTOS_SOURCE_FOLDER TRUE) +if(RTOS_SOURCE_FOLDER) + if(NOT "${RTOS_SOURCE_FOLDER}" STREQUAL "") + set(NO_RTOS_SOURCE_FOLDER FALSE) endif() endif() @@ -39,7 +39,7 @@ if(CHIBIOS_CONTRIB_SOURCE) endif() endif() -if(NO_CHIBIOS_SOURCE) +if(NO_RTOS_SOURCE_FOLDER) # no CHIBIOS source specified, download it from it's repo # check for Git (needed here for advanced warning to user if it's not installed) @@ -51,7 +51,7 @@ if(NO_CHIBIOS_SOURCE) endif() # ChibiOS version - set(CHIBIOS_GIT_TAG "stable_19.1.x") + set(RTOS_VERSION "stable_19.1.x") message(STATUS "RTOS is: CHIBIOS (latest available code from ${CHIBIOS_GIT_TAG})") # need to setup a separate CMake project to download the code from the GitHub repository @@ -75,7 +75,7 @@ if(NO_CHIBIOS_SOURCE) PREFIX ChibiOS SOURCE_DIR ${CMAKE_BINARY_DIR}/ChibiOS_Source GIT_REPOSITORY https://github.com/nanoframework/chibios - GIT_TAG ${CHIBIOS_GIT_TAG} # target specified branch + GIT_TAG ${RTOS_VERSION} # target specified branch GIT_SHALLOW 1 # download only the tip of the branch, not the complete history TIMEOUT 10 LOG_DOWNLOAD 1 @@ -93,21 +93,21 @@ else() # ChibiOS source was specified # sanity check is source path exists - if(EXISTS "${CHIBIOS_SOURCE}/") - message(STATUS "RTOS is: ChibiOS (source from: ${CHIBIOS_SOURCE})") + if(EXISTS "${RTOS_SOURCE_FOLDER}/") + message(STATUS "RTOS is: ChibiOS (source from: ${RTOS_SOURCE_FOLDER})") # check if we already have the sources, no need to copy again NF_DIRECTORY_EXISTS_NOT_EMPTY(${CMAKE_BINARY_DIR}/ChibiOS_Source/ SOURCE_EXISTS) if(NOT ${SOURCE_EXISTS}) - file(COPY "${CHIBIOS_SOURCE}/" DESTINATION "${CMAKE_BINARY_DIR}/ChibiOS_Source") + file(COPY "${RTOS_SOURCE_FOLDER}/" DESTINATION "${CMAKE_BINARY_DIR}/ChibiOS_Source") else() - message(STATUS "Using local cache of ChibiOS source from ${CHIBIOS_SOURCE}") + message(STATUS "Using local cache of ChibiOS source from ${RTOS_SOURCE_FOLDER}") endif() set(CHIBIOS_INCLUDE_DIR ${CMAKE_BINARY_DIR}/ChibiOS_Source/include) else() - message(FATAL_ERROR "Couldn't find ChibiOS source at ${CHIBIOS_SOURCE}/") + message(FATAL_ERROR "Couldn't find ChibiOS source at ${RTOS_SOURCE_FOLDER}/") endif() # add ChibiOS as external project @@ -343,7 +343,7 @@ if(NF_SECURITY_MBEDTLS) endif() # set tag for currently supported version - set(MBEDTLS_GIT_TAG "mbedtls-2.16.3") + set(MBEDTLS_GIT_TAG "mbedtls-2.23.0") # need to setup a separate CMake project to download the code from the GitHub repository # otherwise it won't be available before the actual build step diff --git a/targets/CMSIS-OS/ChibiOS/Include/CLR_Startup_Thread.h b/targets/CMSIS-OS/ChibiOS/Include/CLR_Startup_Thread.h index 3c394ef4be..7c3f0f07d7 100644 --- a/targets/CMSIS-OS/ChibiOS/Include/CLR_Startup_Thread.h +++ b/targets/CMSIS-OS/ChibiOS/Include/CLR_Startup_Thread.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/Include/CMakeLists.txt b/targets/CMSIS-OS/ChibiOS/Include/CMakeLists.txt index 011c8fada4..c136111b0b 100644 --- a/targets/CMSIS-OS/ChibiOS/Include/CMakeLists.txt +++ b/targets/CMSIS-OS/ChibiOS/Include/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/targets/CMSIS-OS/ChibiOS/Include/LaunchCLR.h b/targets/CMSIS-OS/ChibiOS/Include/LaunchCLR.h index 15e319ef7e..08ccbb0451 100644 --- a/targets/CMSIS-OS/ChibiOS/Include/LaunchCLR.h +++ b/targets/CMSIS-OS/ChibiOS/Include/LaunchCLR.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/Include/TargetHAL_Spi.h b/targets/CMSIS-OS/ChibiOS/Include/TargetHAL_Spi.h new file mode 100644 index 0000000000..d693620000 --- /dev/null +++ b/targets/CMSIS-OS/ChibiOS/Include/TargetHAL_Spi.h @@ -0,0 +1,15 @@ +// +// Copyright (c) .NET Foundation and Contributors +// See LICENSE file in the project root for full license information. +// + +#ifndef _TARGET_HAL_SPI_H_ +#define _TARGET_HAL_SPI_H_ 1 + +// # of buses +#define NUM_SPI_BUSES 5 + +// Maximum number of devices per SPI bus +#define MAX_SPI_DEVICES 5 + +#endif //_TARGET_HAL_SPI_H_ diff --git a/targets/CMSIS-OS/ChibiOS/Include/TargetPAL_BlockStorage.h b/targets/CMSIS-OS/ChibiOS/Include/TargetPAL_BlockStorage.h index 805c2e320d..de9364c773 100644 --- a/targets/CMSIS-OS/ChibiOS/Include/TargetPAL_BlockStorage.h +++ b/targets/CMSIS-OS/ChibiOS/Include/TargetPAL_BlockStorage.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/Include/Target_BlockStorage_STM32FlashDriver.h b/targets/CMSIS-OS/ChibiOS/Include/Target_BlockStorage_STM32FlashDriver.h index 421ebc4dfc..e252087fad 100644 --- a/targets/CMSIS-OS/ChibiOS/Include/Target_BlockStorage_STM32FlashDriver.h +++ b/targets/CMSIS-OS/ChibiOS/Include/Target_BlockStorage_STM32FlashDriver.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/Include/Target_Windows_Storage.h b/targets/CMSIS-OS/ChibiOS/Include/Target_Windows_Storage.h index ad2adadded..93c2fa118a 100644 --- a/targets/CMSIS-OS/ChibiOS/Include/Target_Windows_Storage.h +++ b/targets/CMSIS-OS/ChibiOS/Include/Target_Windows_Storage.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/Include/WireProtocol_ReceiverThread.h b/targets/CMSIS-OS/ChibiOS/Include/WireProtocol_ReceiverThread.h index c6b75c3e8d..404e9eeae6 100644 --- a/targets/CMSIS-OS/ChibiOS/Include/WireProtocol_ReceiverThread.h +++ b/targets/CMSIS-OS/ChibiOS/Include/WireProtocol_ReceiverThread.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/lwipopts.h b/targets/CMSIS-OS/ChibiOS/Include/lwipopts.h similarity index 77% rename from targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/lwipopts.h rename to targets/CMSIS-OS/ChibiOS/Include/lwipopts.h index e3e393c349..1a370120ac 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/lwipopts.h +++ b/targets/CMSIS-OS/ChibiOS/Include/lwipopts.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2001-2004 Swedish Institute of Computer Science, All Rights Reserved // See LICENSE file in the project root for full license information. // @@ -11,9 +11,9 @@ /* * Copyright (c) 2001-2004 Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, @@ -22,33 +22,32 @@ * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. + * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT - * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * OF SUCH DAMAGE. * * This file is part of the lwIP TCP/IP stack. - * + * * Author: Adam Dunkels * */ #ifndef __LWIPOPT_H__ #define __LWIPOPT_H__ - #define _REENT_ONLY #define set_errno(err) #include +#include #include -#include /* ----------------------------------------------- @@ -62,15 +61,15 @@ * allocation and deallocation. */ #ifndef SYS_LIGHTWEIGHT_PROT -#define SYS_LIGHTWEIGHT_PROT 1 +#define SYS_LIGHTWEIGHT_PROT 1 #endif -/** +/** * NO_SYS==1: Provides VERY minimal functionality. Otherwise, * use lwIP facilities. */ #ifndef NO_SYS -#define NO_SYS 0 +#define NO_SYS 0 #endif /** @@ -78,7 +77,7 @@ * Mainly for compatibility to old versions. */ #ifndef NO_SYS_NO_TIMERS -#define NO_SYS_NO_TIMERS 0 +#define NO_SYS_NO_TIMERS 0 #endif // empty on purpose @@ -89,7 +88,7 @@ * one included in your C library */ #ifndef MEMCPY -#define MEMCPY(dst,src,len) memcpy(dst,src,len) +#define MEMCPY(dst, src, len) memcpy(dst, src, len) #endif /** @@ -97,7 +96,7 @@ * call to memcpy() if the length is known at compile time and is small. */ #ifndef SMEMCPY -#define SMEMCPY(dst,src,len) memcpy(dst,src,len) +#define SMEMCPY(dst, src, len) memcpy(dst, src, len) #endif /* @@ -111,16 +110,16 @@ * already use it. */ #ifndef MEM_LIBC_MALLOC -#define MEM_LIBC_MALLOC 1 +#define MEM_LIBC_MALLOC 1 #endif /** -* MEMP_MEM_MALLOC==1: Use mem_malloc/mem_free instead of the lwip pool allocator. -* Especially useful with MEM_LIBC_MALLOC but handle with care regarding execution -* speed and usage from interrupts! -*/ + * MEMP_MEM_MALLOC==1: Use mem_malloc/mem_free instead of the lwip pool allocator. + * Especially useful with MEM_LIBC_MALLOC but handle with care regarding execution + * speed and usage from interrupts! + */ #ifndef MEMP_MEM_MALLOC -#define MEMP_MEM_MALLOC 1 +#define MEMP_MEM_MALLOC 1 #endif /** @@ -129,7 +128,7 @@ * 2 byte alignment -> #define MEM_ALIGNMENT 2 */ #ifndef MEM_ALIGNMENT -#define MEM_ALIGNMENT 4 +#define MEM_ALIGNMENT 4 #endif /** @@ -137,7 +136,7 @@ * a lot of data that needs to be copied, this should be set high. */ #ifndef MEM_SIZE -#define MEM_SIZE (16 * 1024) +#define MEM_SIZE (16 * 1024) #endif /** @@ -146,7 +145,7 @@ * Default is one big array for all pools */ #ifndef MEMP_SEPARATE_POOLS -#define MEMP_SEPARATE_POOLS 0 +#define MEMP_SEPARATE_POOLS 0 #endif /** @@ -159,7 +158,7 @@ * memp_malloc() or memp_free() is called (useful but slow!) */ #ifndef MEMP_OVERFLOW_CHECK -#define MEMP_OVERFLOW_CHECK 0 +#define MEMP_OVERFLOW_CHECK 0 #endif /** @@ -167,7 +166,7 @@ * sure that there are no cycles in the linked lists. */ #ifndef MEMP_SANITY_CHECK -#define MEMP_SANITY_CHECK 0 +#define MEMP_SANITY_CHECK 0 #endif /** @@ -177,7 +176,7 @@ * To use this, MEMP_USE_CUSTOM_POOLS also has to be enabled. */ #ifndef MEM_USE_POOLS -#define MEM_USE_POOLS 0 +#define MEM_USE_POOLS 0 #endif /** @@ -185,17 +184,17 @@ * bigger pool - WARNING: THIS MIGHT WASTE MEMORY but it can make a system more * reliable. */ #ifndef MEM_USE_POOLS_TRY_BIGGER_POOL -#define MEM_USE_POOLS_TRY_BIGGER_POOL 0 +#define MEM_USE_POOLS_TRY_BIGGER_POOL 0 #endif /** * MEMP_USE_CUSTOM_POOLS==1: whether to include a user file lwippools.h * that defines additional pools beyond the "standard" ones required - * by lwIP. If you set this to 1, you must have lwippools.h in your - * inlude path somewhere. + * by lwIP. If you set this to 1, you must have lwippools.h in your + * inlude path somewhere. */ #ifndef MEMP_USE_CUSTOM_POOLS -#define MEMP_USE_CUSTOM_POOLS 0 +#define MEMP_USE_CUSTOM_POOLS 0 #endif /** @@ -228,7 +227,7 @@ /** * LWIP_IPV6==1: Enable IPv6 */ -#define LWIP_IPV6 0 +#define LWIP_IPV6 0 /* ------------------------------------------------ @@ -241,7 +240,7 @@ * this should be set high. */ #ifndef MEMP_NUM_PBUF -#define MEMP_NUM_PBUF 16 +#define MEMP_NUM_PBUF 16 #endif /** @@ -249,7 +248,7 @@ * (requires the LWIP_RAW option) */ #ifndef MEMP_NUM_RAW_PCB -#define MEMP_NUM_RAW_PCB 4 +#define MEMP_NUM_RAW_PCB 4 #endif /** @@ -258,7 +257,7 @@ * (requires the LWIP_UDP option) */ #ifndef MEMP_NUM_UDP_PCB -#define MEMP_NUM_UDP_PCB 4 +#define MEMP_NUM_UDP_PCB 4 #endif /** @@ -266,7 +265,7 @@ * (requires the LWIP_TCP option) */ #ifndef MEMP_NUM_TCP_PCB -#define MEMP_NUM_TCP_PCB 5 +#define MEMP_NUM_TCP_PCB 5 #endif /** @@ -274,7 +273,7 @@ * (requires the LWIP_TCP option) */ #ifndef MEMP_NUM_TCP_PCB_LISTEN -#define MEMP_NUM_TCP_PCB_LISTEN 8 +#define MEMP_NUM_TCP_PCB_LISTEN 8 #endif /** @@ -282,7 +281,7 @@ * (requires the LWIP_TCP option) */ #ifndef MEMP_NUM_TCP_SEG -#define MEMP_NUM_TCP_SEG 16 +#define MEMP_NUM_TCP_SEG 16 #endif /** @@ -290,7 +289,7 @@ * reassembly (whole packets, not fragments!) */ #ifndef MEMP_NUM_REASSDATA -#define MEMP_NUM_REASSDATA 5 +#define MEMP_NUM_REASSDATA 5 #endif /** @@ -301,7 +300,7 @@ * where the packet is not yet sent when netif->output returns. */ #ifndef MEMP_NUM_FRAG_PBUF -#define MEMP_NUM_FRAG_PBUF 15 +#define MEMP_NUM_FRAG_PBUF 15 #endif /** @@ -311,7 +310,7 @@ * (requires the ARP_QUEUEING option) */ #ifndef MEMP_NUM_ARP_QUEUE -#define MEMP_NUM_ARP_QUEUE 30 +#define MEMP_NUM_ARP_QUEUE 30 #endif /** @@ -321,7 +320,7 @@ * (requires the LWIP_IGMP option) */ #ifndef MEMP_NUM_IGMP_GROUP -#define MEMP_NUM_IGMP_GROUP 8 +#define MEMP_NUM_IGMP_GROUP 8 #endif /** @@ -331,7 +330,9 @@ * The formula expects settings to be either '0' or '1'. */ #ifndef MEMP_NUM_SYS_TIMEOUT -#define MEMP_NUM_SYS_TIMEOUT (LWIP_TCP + IP_REASSEMBLY + LWIP_ARP + (2*LWIP_DHCP) + LWIP_AUTOIP + LWIP_IGMP + LWIP_DNS + PPP_SUPPORT + (LWIP_IPV6 ? (1 + LWIP_IPV6_REASS + LWIP_IPV6_MLD) : 0)) +#define MEMP_NUM_SYS_TIMEOUT \ + (LWIP_TCP + IP_REASSEMBLY + LWIP_ARP + (2 * LWIP_DHCP) + LWIP_AUTOIP + LWIP_IGMP + LWIP_DNS + PPP_SUPPORT + \ + (LWIP_IPV6 ? (1 + LWIP_IPV6_REASS + LWIP_IPV6_MLD) : 0)) #endif /** @@ -339,7 +340,7 @@ * (only needed if you use the sequential API, like api_lib.c) */ #ifndef MEMP_NUM_NETBUF -#define MEMP_NUM_NETBUF 2 +#define MEMP_NUM_NETBUF 2 #endif /** @@ -347,32 +348,32 @@ * (only needed if you use the sequential API, like api_lib.c) */ #ifndef MEMP_NUM_NETCONN -#define MEMP_NUM_NETCONN 4 +#define MEMP_NUM_NETCONN 4 #endif /** * MEMP_NUM_TCPIP_MSG_API: the number of struct tcpip_msg, which are used - * for callback/timeout API communication. + * for callback/timeout API communication. * (only needed if you use tcpip.c) */ #ifndef MEMP_NUM_TCPIP_MSG_API -#define MEMP_NUM_TCPIP_MSG_API 8 +#define MEMP_NUM_TCPIP_MSG_API 8 #endif /** * MEMP_NUM_TCPIP_MSG_INPKT: the number of struct tcpip_msg, which are used - * for incoming packets. + * for incoming packets. * (only needed if you use tcpip.c) */ #ifndef MEMP_NUM_TCPIP_MSG_INPKT -#define MEMP_NUM_TCPIP_MSG_INPKT 8 +#define MEMP_NUM_TCPIP_MSG_INPKT 8 #endif /** * MEMP_NUM_SNMP_NODE: the number of leafs in the SNMP tree. */ #ifndef MEMP_NUM_SNMP_NODE -#define MEMP_NUM_SNMP_NODE 50 +#define MEMP_NUM_SNMP_NODE 50 #endif /** @@ -380,7 +381,7 @@ * Every branch has one leaf (MEMP_NUM_SNMP_NODE) at least! */ #ifndef MEMP_NUM_SNMP_ROOTNODE -#define MEMP_NUM_SNMP_ROOTNODE 30 +#define MEMP_NUM_SNMP_ROOTNODE 30 #endif /** @@ -389,7 +390,7 @@ * 1 for output) */ #ifndef MEMP_NUM_SNMP_VARBIND -#define MEMP_NUM_SNMP_VARBIND 2 +#define MEMP_NUM_SNMP_VARBIND 2 #endif /** @@ -398,7 +399,7 @@ * (1 for the value read and 2 for OIDs - input and output) */ #ifndef MEMP_NUM_SNMP_VALUE -#define MEMP_NUM_SNMP_VALUE 3 +#define MEMP_NUM_SNMP_VALUE 3 #endif /** @@ -406,7 +407,7 @@ * (before freeing the corresponding memory using lwip_freeaddrinfo()). */ #ifndef MEMP_NUM_NETDB -#define MEMP_NUM_NETDB 1 +#define MEMP_NUM_NETDB 1 #endif /** @@ -414,7 +415,7 @@ * if DNS_LOCAL_HOSTLIST_IS_DYNAMIC==1. */ #ifndef MEMP_NUM_LOCALHOSTLIST -#define MEMP_NUM_LOCALHOSTLIST 1 +#define MEMP_NUM_LOCALHOSTLIST 1 #endif /** @@ -422,14 +423,14 @@ * interfaces (only used with PPPOE_SUPPORT==1) */ #ifndef MEMP_NUM_PPPOE_INTERFACES -#define MEMP_NUM_PPPOE_INTERFACES 1 +#define MEMP_NUM_PPPOE_INTERFACES 1 #endif /** - * PBUF_POOL_SIZE: the number of buffers in the pbuf pool. + * PBUF_POOL_SIZE: the number of buffers in the pbuf pool. */ #ifndef PBUF_POOL_SIZE -#define PBUF_POOL_SIZE 16 +#define PBUF_POOL_SIZE 16 #endif /* @@ -441,14 +442,14 @@ * LWIP_ARP==1: Enable ARP functionality. */ #ifndef LWIP_ARP -#define LWIP_ARP 1 +#define LWIP_ARP 1 #endif /** * ARP_TABLE_SIZE: Number of active MAC-IP address pairs cached. */ #ifndef ARP_TABLE_SIZE -#define ARP_TABLE_SIZE 10 +#define ARP_TABLE_SIZE 10 #endif /** @@ -459,7 +460,7 @@ * packet in a row to an IP address that is not in the ARP cache. */ #ifndef ARP_QUEUEING -#define ARP_QUEUEING 0 +#define ARP_QUEUEING 0 #endif /** @@ -473,7 +474,7 @@ * Also notice that this slows down input processing of every IP packet! */ #ifndef ETHARP_TRUST_IP_MAC -#define ETHARP_TRUST_IP_MAC 0 +#define ETHARP_TRUST_IP_MAC 0 #endif /** @@ -485,14 +486,14 @@ * that returns 1 to accept a packet or 0 to drop a packet. */ #ifndef ETHARP_SUPPORT_VLAN -#define ETHARP_SUPPORT_VLAN 0 +#define ETHARP_SUPPORT_VLAN 0 #endif /** LWIP_ETHERNET==1: enable ethernet support for PPPoE even though ARP * might be disabled */ #ifndef LWIP_ETHERNET -#define LWIP_ETHERNET (LWIP_ARP || PPPOE_SUPPORT) +#define LWIP_ETHERNET (LWIP_ARP || PPPOE_SUPPORT) #endif /** ETH_PAD_SIZE: number of bytes added before the ethernet header to ensure @@ -501,14 +502,14 @@ * on a 32-bit boundary, so setting this to 2 can speed up 32-bit-platforms. */ #ifndef ETH_PAD_SIZE -#define ETH_PAD_SIZE 0 +#define ETH_PAD_SIZE 0 #endif /** ETHARP_SUPPORT_STATIC_ENTRIES==1: enable code to support static ARP table * entries (using etharp_add_static_entry/etharp_remove_static_entry). */ #ifndef ETHARP_SUPPORT_STATIC_ENTRIES -#define ETHARP_SUPPORT_STATIC_ENTRIES 0 +#define ETHARP_SUPPORT_STATIC_ENTRIES 0 #endif /* @@ -522,7 +523,7 @@ * interface, define this to 0. */ #ifndef IP_FORWARD -#define IP_FORWARD 0 +#define IP_FORWARD 0 #endif /** @@ -531,7 +532,7 @@ * IP_OPTIONS_ALLOWED==1: IP options are allowed (but not parsed). */ #ifndef IP_OPTIONS_ALLOWED -#define IP_OPTIONS_ALLOWED 1 +#define IP_OPTIONS_ALLOWED 1 #endif /** @@ -540,7 +541,7 @@ * via IP_FRAG. */ #ifndef IP_REASSEMBLY -#define IP_REASSEMBLY 1 +#define IP_REASSEMBLY 1 #endif /** @@ -549,7 +550,7 @@ * controlled via IP_REASSEMBLY. */ #ifndef IP_FRAG -#define IP_FRAG 1 +#define IP_FRAG 1 #endif /** @@ -558,7 +559,7 @@ * in this time, the whole packet is discarded. */ #ifndef IP_REASS_MAXAGE -#define IP_REASS_MAXAGE 3 +#define IP_REASS_MAXAGE 3 #endif /** @@ -568,7 +569,7 @@ * packets even if the maximum amount of fragments is enqueued for reassembly! */ #ifndef IP_REASS_MAX_PBUFS -#define IP_REASS_MAX_PBUFS 10 +#define IP_REASS_MAX_PBUFS 10 #endif /** @@ -579,7 +580,7 @@ * ATTENTION: IP_FRAG_USES_STATIC_BUF==1 may not be used for DMA-enabled MACs! */ #ifndef IP_FRAG_USES_STATIC_BUF -#define IP_FRAG_USES_STATIC_BUF 0 +#define IP_FRAG_USES_STATIC_BUF 0 #endif /** @@ -587,14 +588,14 @@ * (requires IP_FRAG_USES_STATIC_BUF==1) */ #if IP_FRAG_USES_STATIC_BUF && !defined(IP_FRAG_MAX_MTU) -#define IP_FRAG_MAX_MTU 1500 +#define IP_FRAG_MAX_MTU 1500 #endif /** * IP_DEFAULT_TTL: Default value for Time-To-Live used by transport layers. */ #ifndef IP_DEFAULT_TTL -#define IP_DEFAULT_TTL 255 +#define IP_DEFAULT_TTL 255 #endif /** @@ -603,7 +604,7 @@ * on recv operations, you also have to set IP_SOF_BROADCAST_RECV=1. */ #ifndef IP_SOF_BROADCAST -#define IP_SOF_BROADCAST 0 +#define IP_SOF_BROADCAST 0 #endif /** @@ -611,7 +612,7 @@ * filter on recv operations. */ #ifndef IP_SOF_BROADCAST_RECV -#define IP_SOF_BROADCAST_RECV 0 +#define IP_SOF_BROADCAST_RECV 0 #endif /** @@ -646,28 +647,28 @@ * Be careful, disable that make your product non-compliant to RFC1122 */ #ifndef LWIP_ICMP -#define LWIP_ICMP 1 +#define LWIP_ICMP 1 #endif /** * ICMP_TTL: Default value for Time-To-Live used by ICMP packets. */ #ifndef ICMP_TTL -#define ICMP_TTL (IP_DEFAULT_TTL) +#define ICMP_TTL (IP_DEFAULT_TTL) #endif /** * LWIP_BROADCAST_PING==1: respond to broadcast pings (default is unicast only) */ #ifndef LWIP_BROADCAST_PING -#define LWIP_BROADCAST_PING 0 +#define LWIP_BROADCAST_PING 0 #endif /** * LWIP_MULTICAST_PING==1: respond to multicast pings (default is unicast only) */ #ifndef LWIP_MULTICAST_PING -#define LWIP_MULTICAST_PING 0 +#define LWIP_MULTICAST_PING 0 #endif /* @@ -679,14 +680,14 @@ * LWIP_RAW==1: Enable application layer to hook into the IP layer itself. */ #ifndef LWIP_RAW -#define LWIP_RAW 1 +#define LWIP_RAW 1 #endif /** * LWIP_RAW==1: Enable application layer to hook into the IP layer itself. */ #ifndef RAW_TTL -#define RAW_TTL (IP_DEFAULT_TTL) +#define RAW_TTL (IP_DEFAULT_TTL) #endif /* @@ -698,17 +699,17 @@ * LWIP_DHCP==1: Enable DHCP module. */ #ifndef LWIP_DHCP -#define LWIP_DHCP 1 +#define LWIP_DHCP 1 #endif /** * DHCP_DOES_ARP_CHECK==1: Do an ARP check on the offered address. */ #ifndef DHCP_DOES_ARP_CHECK -#define DHCP_DOES_ARP_CHECK ((LWIP_DHCP) && (LWIP_ARP)) +#define DHCP_DOES_ARP_CHECK ((LWIP_DHCP) && (LWIP_ARP)) #endif -#define LWIP_DHCP_CHECK_LINK_UP 1 +#define LWIP_DHCP_CHECK_LINK_UP 1 /* ------------------------------------ @@ -719,7 +720,7 @@ * LWIP_AUTOIP==1: Enable AUTOIP module. */ #ifndef LWIP_AUTOIP -#define LWIP_AUTOIP 0 +#define LWIP_AUTOIP 0 #endif /** @@ -727,7 +728,7 @@ * the same interface at the same time. */ #ifndef LWIP_DHCP_AUTOIP_COOP -#define LWIP_DHCP_AUTOIP_COOP 0 +#define LWIP_DHCP_AUTOIP_COOP 0 #endif /** @@ -738,7 +739,7 @@ * AutoIP. */ #ifndef LWIP_DHCP_AUTOIP_COOP_TRIES -#define LWIP_DHCP_AUTOIP_COOP_TRIES 9 +#define LWIP_DHCP_AUTOIP_COOP_TRIES 9 #endif /* @@ -751,7 +752,7 @@ * transport. */ #ifndef LWIP_SNMP -#define LWIP_SNMP 0 +#define LWIP_SNMP 0 #endif /** @@ -760,7 +761,7 @@ * Does not have to be changed unless external MIBs answer request asynchronously */ #ifndef SNMP_CONCURRENT_REQUESTS -#define SNMP_CONCURRENT_REQUESTS 1 +#define SNMP_CONCURRENT_REQUESTS 1 #endif /** @@ -768,16 +769,16 @@ * destination is required */ #ifndef SNMP_TRAP_DESTINATIONS -#define SNMP_TRAP_DESTINATIONS 1 +#define SNMP_TRAP_DESTINATIONS 1 #endif /** - * SNMP_PRIVATE_MIB: + * SNMP_PRIVATE_MIB: * When using a private MIB, you have to create a file 'private_mib.h' that contains * a 'struct mib_array_node mib_private' which contains your MIB. */ #ifndef SNMP_PRIVATE_MIB -#define SNMP_PRIVATE_MIB 0 +#define SNMP_PRIVATE_MIB 0 #endif /** @@ -786,7 +787,7 @@ * Unsafe requests are disabled by default! */ #ifndef SNMP_SAFE_REQUESTS -#define SNMP_SAFE_REQUESTS 1 +#define SNMP_SAFE_REQUESTS 1 #endif /** @@ -794,7 +795,7 @@ * MEMP_SNMP_VALUE elements. */ #ifndef SNMP_MAX_OCTET_STRING_LEN -#define SNMP_MAX_OCTET_STRING_LEN 127 +#define SNMP_MAX_OCTET_STRING_LEN 127 #endif /** @@ -803,7 +804,7 @@ * This affects the size of MEMP_SNMP_VALUE elements. */ #ifndef SNMP_MAX_TREE_DEPTH -#define SNMP_MAX_TREE_DEPTH 15 +#define SNMP_MAX_TREE_DEPTH 15 #endif /** @@ -811,7 +812,7 @@ * SNMP_MAX_OCTET_STRING_LEN and SNMP_MAX_TREE_DEPTH. */ #ifndef SNMP_MAX_VALUE_SIZE -#define SNMP_MAX_VALUE_SIZE LWIP_MAX((SNMP_MAX_OCTET_STRING_LEN)+1, sizeof(s32_t)*(SNMP_MAX_TREE_DEPTH)) +#define SNMP_MAX_VALUE_SIZE LWIP_MAX((SNMP_MAX_OCTET_STRING_LEN) + 1, sizeof(s32_t) * (SNMP_MAX_TREE_DEPTH)) #endif /* @@ -820,10 +821,10 @@ ---------------------------------- */ /** - * LWIP_IGMP==1: Turn on IGMP module. + * LWIP_IGMP==1: Turn on IGMP module. */ #ifndef LWIP_IGMP -#define LWIP_IGMP 0 +#define LWIP_IGMP 0 #endif /* @@ -836,32 +837,32 @@ * transport. */ #ifndef LWIP_DNS -#define LWIP_DNS 1 +#define LWIP_DNS 1 #endif /** DNS maximum number of entries to maintain locally. */ #ifndef DNS_TABLE_SIZE -#define DNS_TABLE_SIZE 4 +#define DNS_TABLE_SIZE 4 #endif /** DNS maximum host name length supported in the name table. */ #ifndef DNS_MAX_NAME_LENGTH -#define DNS_MAX_NAME_LENGTH 256 +#define DNS_MAX_NAME_LENGTH 256 #endif /** The maximum of DNS servers */ #ifndef DNS_MAX_SERVERS -#define DNS_MAX_SERVERS 2 +#define DNS_MAX_SERVERS 2 #endif /** DNS do a name checking between the query and the response. */ #ifndef DNS_DOES_NAME_CHECK -#define DNS_DOES_NAME_CHECK 1 +#define DNS_DOES_NAME_CHECK 1 #endif /** DNS message max. size. Default value is RFC compliant. */ #ifndef DNS_MSG_SIZE -#define DNS_MSG_SIZE 512 +#define DNS_MSG_SIZE 512 #endif /** DNS_LOCAL_HOSTLIST: Implements a local host-to-address list. If enabled, @@ -875,13 +876,13 @@ * that returns the IP address or INADDR_NONE if not found. */ #ifndef DNS_LOCAL_HOSTLIST -#define DNS_LOCAL_HOSTLIST 0 +#define DNS_LOCAL_HOSTLIST 0 #endif /* DNS_LOCAL_HOSTLIST */ /** If this is turned on, the local host-list can be dynamically changed * at runtime. */ #ifndef DNS_LOCAL_HOSTLIST_IS_DYNAMIC -#define DNS_LOCAL_HOSTLIST_IS_DYNAMIC 0 +#define DNS_LOCAL_HOSTLIST_IS_DYNAMIC 0 #endif /* DNS_LOCAL_HOSTLIST_IS_DYNAMIC */ /* @@ -893,28 +894,28 @@ * LWIP_UDP==1: Turn on UDP. */ #ifndef LWIP_UDP -#define LWIP_UDP 1 +#define LWIP_UDP 1 #endif /** * LWIP_UDPLITE==1: Turn on UDP-Lite. (Requires LWIP_UDP) */ #ifndef LWIP_UDPLITE -#define LWIP_UDPLITE 0 +#define LWIP_UDPLITE 0 #endif /** * UDP_TTL: Default Time-To-Live value. */ #ifndef UDP_TTL -#define UDP_TTL (IP_DEFAULT_TTL) +#define UDP_TTL (IP_DEFAULT_TTL) #endif /** * LWIP_NETBUF_RECVINFO==1: append destination addr and port to every netbuf. */ #ifndef LWIP_NETBUF_RECVINFO -#define LWIP_NETBUF_RECVINFO 0 +#define LWIP_NETBUF_RECVINFO 0 #endif /* @@ -926,36 +927,36 @@ * LWIP_TCP==1: Turn on TCP. */ #ifndef LWIP_TCP -#define LWIP_TCP 1 +#define LWIP_TCP 1 #endif /** * TCP_TTL: Default Time-To-Live value. */ #ifndef TCP_TTL -#define TCP_TTL (IP_DEFAULT_TTL) +#define TCP_TTL (IP_DEFAULT_TTL) #endif /** - * TCP_WND: The size of a TCP window. This must be at least + * TCP_WND: The size of a TCP window. This must be at least * (2 * TCP_MSS) for things to work well */ #ifndef TCP_WND -#define TCP_WND (4 * TCP_MSS) -#endif +#define TCP_WND (4 * TCP_MSS) +#endif /** * TCP_MAXRTX: Maximum number of retransmissions of data segments. */ #ifndef TCP_MAXRTX -#define TCP_MAXRTX 12 +#define TCP_MAXRTX 12 #endif /** * TCP_SYNMAXRTX: Maximum number of retransmissions of SYN segments. */ #ifndef TCP_SYNMAXRTX -#define TCP_SYNMAXRTX 6 +#define TCP_SYNMAXRTX 6 #endif /** @@ -963,7 +964,7 @@ * Define to 0 if your device is low on memory. */ #ifndef TCP_QUEUE_OOSEQ -#define TCP_QUEUE_OOSEQ (LWIP_TCP) +#define TCP_QUEUE_OOSEQ (LWIP_TCP) #endif /** @@ -974,7 +975,7 @@ * an upper limit on the MSS advertised by the remote host. */ #ifndef TCP_MSS -#define TCP_MSS 1480 +#define TCP_MSS 1480 #endif /** @@ -986,16 +987,15 @@ * netif used for a connection and limits the MSS if it would be too big otherwise. */ #ifndef TCP_CALCULATE_EFF_SEND_MSS -#define TCP_CALCULATE_EFF_SEND_MSS 1 +#define TCP_CALCULATE_EFF_SEND_MSS 1 #endif - /** * TCP_SND_BUF: TCP sender buffer space (bytes). * To achieve good performance, this should be at least 2 * TCP_MSS. */ #ifndef TCP_SND_BUF -#define TCP_SND_BUF (2 * TCP_MSS) +#define TCP_SND_BUF (2 * TCP_MSS) #endif /** @@ -1003,7 +1003,7 @@ * as much as (2 * TCP_SND_BUF/TCP_MSS) for things to work. */ #ifndef TCP_SND_QUEUELEN -#define TCP_SND_QUEUELEN ((4 * (TCP_SND_BUF) + (TCP_MSS - 1))/(TCP_MSS)) +#define TCP_SND_QUEUELEN ((4 * (TCP_SND_BUF) + (TCP_MSS - 1)) / (TCP_MSS)) #endif /** @@ -1012,7 +1012,7 @@ * TCP snd_buf for select to return writable (combined with TCP_SNDQUEUELOWAT). */ #ifndef TCP_SNDLOWAT -#define TCP_SNDLOWAT LWIP_MIN(LWIP_MAX(((TCP_SND_BUF)/2), (2 * TCP_MSS) + 1), (TCP_SND_BUF) - 1) +#define TCP_SNDLOWAT LWIP_MIN(LWIP_MAX(((TCP_SND_BUF) / 2), (2 * TCP_MSS) + 1), (TCP_SND_BUF)-1) #endif /** @@ -1021,7 +1021,7 @@ * this number, select returns writable (combined with TCP_SNDLOWAT). */ #ifndef TCP_SNDQUEUELOWAT -#define TCP_SNDQUEUELOWAT LWIP_MAX(((TCP_SND_QUEUELEN)/2), 5) +#define TCP_SNDQUEUELOWAT LWIP_MAX(((TCP_SND_QUEUELEN) / 2), 5) #endif /** @@ -1029,7 +1029,7 @@ * Default is 0 (no limit). Only valid for TCP_QUEUE_OOSEQ==0. */ #ifndef TCP_OOSEQ_MAX_BYTES -#define TCP_OOSEQ_MAX_BYTES 0 +#define TCP_OOSEQ_MAX_BYTES 0 #endif /** @@ -1037,14 +1037,14 @@ * Default is 0 (no limit). Only valid for TCP_QUEUE_OOSEQ==0. */ #ifndef TCP_OOSEQ_MAX_PBUFS -#define TCP_OOSEQ_MAX_PBUFS 0 +#define TCP_OOSEQ_MAX_PBUFS 0 #endif /** * TCP_LISTEN_BACKLOG: Enable the backlog option for tcp listen pcb. */ #ifndef TCP_LISTEN_BACKLOG -#define TCP_LISTEN_BACKLOG 1 +#define TCP_LISTEN_BACKLOG 1 #endif /** @@ -1053,7 +1053,7 @@ * 0xff is the maximum (u8_t). */ #ifndef TCP_DEFAULT_LISTEN_BACKLOG -#define TCP_DEFAULT_LISTEN_BACKLOG 0xff +#define TCP_DEFAULT_LISTEN_BACKLOG 0xff #endif /** @@ -1071,14 +1071,14 @@ * TCP_MSS/4: Try to create 4 fragments or less per TCP packet. */ #ifndef TCP_OVERSIZE -#define TCP_OVERSIZE TCP_MSS +#define TCP_OVERSIZE TCP_MSS #endif /** * LWIP_TCP_TIMESTAMPS==1: support the TCP timestamp option. */ #ifndef LWIP_TCP_TIMESTAMPS -#define LWIP_TCP_TIMESTAMPS 0 +#define LWIP_TCP_TIMESTAMPS 0 #endif /** @@ -1086,7 +1086,7 @@ * explicit window update */ #ifndef TCP_WND_UPDATE_THRESHOLD -#define TCP_WND_UPDATE_THRESHOLD (TCP_WND / 4) +#define TCP_WND_UPDATE_THRESHOLD (TCP_WND / 4) #endif /** @@ -1097,11 +1097,10 @@ * for the event. This is the default. */ #if !defined(LWIP_EVENT_API) && !defined(LWIP_CALLBACK_API) -#define LWIP_EVENT_API 0 -#define LWIP_CALLBACK_API 1 +#define LWIP_EVENT_API 0 +#define LWIP_CALLBACK_API 1 #endif - /* ---------------------------------- ---------- Pbuf options ---------- @@ -1113,7 +1112,7 @@ * Ethernet. */ #ifndef PBUF_LINK_HLEN -#define PBUF_LINK_HLEN (14 + ETH_PAD_SIZE) +#define PBUF_LINK_HLEN (14 + ETH_PAD_SIZE) #endif /** @@ -1122,7 +1121,7 @@ * TCP_MSS, IP header, and link header. */ #ifndef PBUF_POOL_BUFSIZE -#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(TCP_MSS+40+PBUF_LINK_HLEN) +#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(TCP_MSS + 40 + PBUF_LINK_HLEN) #endif /* @@ -1135,14 +1134,14 @@ * field. */ #ifndef LWIP_NETIF_HOSTNAME -#define LWIP_NETIF_HOSTNAME 1 +#define LWIP_NETIF_HOSTNAME 1 #endif /** * LWIP_NETIF_API==1: Support netif api (in netifapi.c) */ #ifndef LWIP_NETIF_API -#define LWIP_NETIF_API 0 +#define LWIP_NETIF_API 0 #endif /** @@ -1150,7 +1149,7 @@ * changes its up/down status (i.e., due to DHCP IP acquistion) */ #ifndef LWIP_NETIF_STATUS_CALLBACK -#define LWIP_NETIF_STATUS_CALLBACK 1 +#define LWIP_NETIF_STATUS_CALLBACK 1 #endif /** @@ -1158,7 +1157,7 @@ * whenever the link changes (i.e., link down) */ #ifndef LWIP_NETIF_LINK_CALLBACK -#define LWIP_NETIF_LINK_CALLBACK 1 +#define LWIP_NETIF_LINK_CALLBACK 1 #endif /** @@ -1166,7 +1165,7 @@ * when a netif has been removed */ #ifndef LWIP_NETIF_REMOVE_CALLBACK -#define LWIP_NETIF_REMOVE_CALLBACK 0 +#define LWIP_NETIF_REMOVE_CALLBACK 0 #endif /** @@ -1177,7 +1176,7 @@ * if you have a tiny ARP table or if there never are concurrent connections. */ #ifndef LWIP_NETIF_HWADDRHINT -#define LWIP_NETIF_HWADDRHINT 0 +#define LWIP_NETIF_HWADDRHINT 0 #endif /** @@ -1185,7 +1184,7 @@ * address equal to the netif IP address, looping them back up the stack. */ #ifndef LWIP_NETIF_LOOPBACK -#define LWIP_NETIF_LOOPBACK 0 +#define LWIP_NETIF_LOOPBACK 0 #endif /** @@ -1193,7 +1192,7 @@ * sending for each netif (0 = disabled) */ #ifndef LWIP_LOOPBACK_MAX_PBUFS -#define LWIP_LOOPBACK_MAX_PBUFS 0 +#define LWIP_LOOPBACK_MAX_PBUFS 0 #endif /** @@ -1210,7 +1209,7 @@ * the main application loop. */ #ifndef LWIP_NETIF_LOOPBACK_MULTITHREADING -#define LWIP_NETIF_LOOPBACK_MULTITHREADING (!NO_SYS) +#define LWIP_NETIF_LOOPBACK_MULTITHREADING (!NO_SYS) #endif /** @@ -1223,7 +1222,7 @@ * @todo: TCP and IP-frag do not work with this, yet: */ #ifndef LWIP_NETIF_TX_SINGLE_PBUF -#define LWIP_NETIF_TX_SINGLE_PBUF 0 +#define LWIP_NETIF_TX_SINGLE_PBUF 0 #endif /* LWIP_NETIF_TX_SINGLE_PBUF */ /* @@ -1235,7 +1234,7 @@ * LWIP_HAVE_LOOPIF==1: Support loop interface (127.0.0.1) and loopif.c */ #ifndef LWIP_HAVE_LOOPIF -#define LWIP_HAVE_LOOPIF 0 +#define LWIP_HAVE_LOOPIF 0 #endif /* @@ -1247,7 +1246,7 @@ * LWIP_HAVE_SLIPIF==1: Support slip interface and slipif.c */ #ifndef LWIP_HAVE_SLIPIF -#define LWIP_HAVE_SLIPIF 0 +#define LWIP_HAVE_SLIPIF 0 #endif /* @@ -1259,7 +1258,7 @@ * TCPIP_THREAD_NAME: The name assigned to the main tcpip thread. */ #ifndef TCPIP_THREAD_NAME -#define TCPIP_THREAD_NAME "tcpip_thread" +#define TCPIP_THREAD_NAME "tcpip_thread" #endif /** @@ -1268,7 +1267,7 @@ * sys_thread_new() when the thread is created. */ #ifndef TCPIP_THREAD_STACKSIZE -#define TCPIP_THREAD_STACKSIZE 1024 +#define TCPIP_THREAD_STACKSIZE 1024 #endif /** @@ -1277,7 +1276,7 @@ * sys_thread_new() when the thread is created. */ #ifndef TCPIP_THREAD_PRIO -#define TCPIP_THREAD_PRIO (NORMALPRIO) +#define TCPIP_THREAD_PRIO (NORMALPRIO) #endif /** @@ -1286,14 +1285,14 @@ * sys_mbox_new() when tcpip_init is called. */ #ifndef TCPIP_MBOX_SIZE -#define TCPIP_MBOX_SIZE MEMP_NUM_PBUF +#define TCPIP_MBOX_SIZE MEMP_NUM_PBUF #endif /** * SLIPIF_THREAD_NAME: The name assigned to the slipif_loop thread. */ #ifndef SLIPIF_THREAD_NAME -#define SLIPIF_THREAD_NAME "slipif_loop" +#define SLIPIF_THREAD_NAME "slipif_loop" #endif /** @@ -1302,7 +1301,7 @@ * sys_thread_new() when the thread is created. */ #ifndef SLIPIF_THREAD_STACKSIZE -#define SLIPIF_THREAD_STACKSIZE 1024 +#define SLIPIF_THREAD_STACKSIZE 1024 #endif /** @@ -1311,14 +1310,14 @@ * sys_thread_new() when the thread is created. */ #ifndef SLIPIF_THREAD_PRIO -#define SLIPIF_THREAD_PRIO (NORMALPRIO) +#define SLIPIF_THREAD_PRIO (NORMALPRIO) #endif /** * PPP_THREAD_NAME: The name assigned to the pppInputThread. */ #ifndef PPP_THREAD_NAME -#define PPP_THREAD_NAME "pppInputThread" +#define PPP_THREAD_NAME "pppInputThread" #endif /** @@ -1327,7 +1326,7 @@ * sys_thread_new() when the thread is created. */ #ifndef PPP_THREAD_STACKSIZE -#define PPP_THREAD_STACKSIZE 1024 +#define PPP_THREAD_STACKSIZE 1024 #endif /** @@ -1336,14 +1335,14 @@ * sys_thread_new() when the thread is created. */ #ifndef PPP_THREAD_PRIO -#define PPP_THREAD_PRIO (NORMALPRIO) +#define PPP_THREAD_PRIO (NORMALPRIO) #endif /** * DEFAULT_THREAD_NAME: The name assigned to any other lwIP thread. */ #ifndef DEFAULT_THREAD_NAME -#define DEFAULT_THREAD_NAME "lwIP" +#define DEFAULT_THREAD_NAME "lwIP" #endif /** @@ -1352,7 +1351,7 @@ * sys_thread_new() when the thread is created. */ #ifndef DEFAULT_THREAD_STACKSIZE -#define DEFAULT_THREAD_STACKSIZE 1024 +#define DEFAULT_THREAD_STACKSIZE 1024 #endif /** @@ -1361,7 +1360,7 @@ * sys_thread_new() when the thread is created. */ #ifndef DEFAULT_THREAD_PRIO -#define DEFAULT_THREAD_PRIO (NORMALPRIO) +#define DEFAULT_THREAD_PRIO (NORMALPRIO) #endif /** @@ -1370,7 +1369,7 @@ * to sys_mbox_new() when the recvmbox is created. */ #ifndef DEFAULT_RAW_RECVMBOX_SIZE -#define DEFAULT_RAW_RECVMBOX_SIZE 4 +#define DEFAULT_RAW_RECVMBOX_SIZE 4 #endif /** @@ -1379,7 +1378,7 @@ * to sys_mbox_new() when the recvmbox is created. */ #ifndef DEFAULT_UDP_RECVMBOX_SIZE -#define DEFAULT_UDP_RECVMBOX_SIZE 4 +#define DEFAULT_UDP_RECVMBOX_SIZE 4 #endif /** @@ -1388,7 +1387,7 @@ * to sys_mbox_new() when the recvmbox is created. */ #ifndef DEFAULT_TCP_RECVMBOX_SIZE -#define DEFAULT_TCP_RECVMBOX_SIZE 40 +#define DEFAULT_TCP_RECVMBOX_SIZE 40 #endif /** @@ -1397,7 +1396,7 @@ * sys_mbox_new() when the acceptmbox is created. */ #ifndef DEFAULT_ACCEPTMBOX_SIZE -#define DEFAULT_ACCEPTMBOX_SIZE 4 +#define DEFAULT_ACCEPTMBOX_SIZE 4 #endif /* @@ -1410,7 +1409,7 @@ * Don't use it if you're not an active lwIP project member */ #ifndef LWIP_TCPIP_CORE_LOCKING -#define LWIP_TCPIP_CORE_LOCKING 0 +#define LWIP_TCPIP_CORE_LOCKING 0 #endif /** @@ -1418,21 +1417,21 @@ * Don't use it if you're not an active lwIP project member */ #ifndef LWIP_TCPIP_CORE_LOCKING_INPUT -#define LWIP_TCPIP_CORE_LOCKING_INPUT 0 +#define LWIP_TCPIP_CORE_LOCKING_INPUT 0 #endif /** * LWIP_NETCONN==1: Enable Netconn API (require to use api_lib.c) */ #ifndef LWIP_NETCONN -#define LWIP_NETCONN 1 +#define LWIP_NETCONN 1 #endif /** LWIP_TCPIP_TIMEOUT==1: Enable tcpip_timeout/tcpip_untimeout tod create * timers running in tcpip_thread from another thread. */ #ifndef LWIP_TCPIP_TIMEOUT -#define LWIP_TCPIP_TIMEOUT 1 +#define LWIP_TCPIP_TIMEOUT 1 #endif /* @@ -1444,7 +1443,7 @@ * LWIP_SOCKET==1: Enable Socket API (require to use sockets.c) */ #ifndef LWIP_SOCKET -#define LWIP_SOCKET 1 +#define LWIP_SOCKET 1 #endif /** @@ -1452,7 +1451,7 @@ * (only used if you use sockets.c) */ #ifndef LWIP_COMPAT_SOCKETS -#define LWIP_COMPAT_SOCKETS 1 +#define LWIP_COMPAT_SOCKETS 1 #endif /** @@ -1461,7 +1460,7 @@ * names (read, write & close). (only used if you use sockets.c) */ #ifndef LWIP_POSIX_SOCKETS_IO_NAMES -#define LWIP_POSIX_SOCKETS_IO_NAMES 1 +#define LWIP_POSIX_SOCKETS_IO_NAMES 1 #endif /** @@ -1470,7 +1469,7 @@ * in seconds. (does not require sockets.c, and will affect tcp.c) */ #ifndef LWIP_TCP_KEEPALIVE -#define LWIP_TCP_KEEPALIVE 0 +#define LWIP_TCP_KEEPALIVE 0 #endif /** @@ -1478,7 +1477,7 @@ * SO_SNDTIMEO processing. */ #ifndef LWIP_SO_SNDTIMEO -#define LWIP_SO_SNDTIMEO 1 +#define LWIP_SO_SNDTIMEO 1 #endif /** @@ -1486,33 +1485,33 @@ * SO_RCVTIMEO processing. */ #ifndef LWIP_SO_RCVTIMEO -#define LWIP_SO_RCVTIMEO 1 +#define LWIP_SO_RCVTIMEO 1 #endif /** - * LWIP_SO_LINGER==1: Enable linger option for sockets/netconns + * LWIP_SO_LINGER==1: Enable linger option for sockets/netconns */ -#define LWIP_SO_LINGER 1 +#define LWIP_SO_LINGER 1 /** * LWIP_SO_RCVBUF==1: Enable SO_RCVBUF processing. */ #ifndef LWIP_SO_RCVBUF -#define LWIP_SO_RCVBUF 1 +#define LWIP_SO_RCVBUF 1 #endif /** * If LWIP_SO_RCVBUF is used, this is the default value for recv_bufsize. */ #ifndef RECV_BUFSIZE_DEFAULT -#define RECV_BUFSIZE_DEFAULT INT_MAX +#define RECV_BUFSIZE_DEFAULT INT_MAX #endif /** * SO_REUSE==1: Enable SO_REUSEADDR option. */ #ifndef SO_REUSE -#define SO_REUSE 1 +#define SO_REUSE 1 #endif /** @@ -1521,7 +1520,7 @@ * WARNING: Adds a memcpy for every packet if passing to more than one pcb! */ #ifndef SO_REUSE_RXTOALL -#define SO_REUSE_RXTOALL 1 +#define SO_REUSE_RXTOALL 1 #endif /* @@ -1533,7 +1532,7 @@ * LWIP_STATS==1: Enable statistics collection in lwip_stats. */ #ifndef LWIP_STATS -#define LWIP_STATS 0 +#define LWIP_STATS 0 #endif #if LWIP_STATS @@ -1542,28 +1541,28 @@ * LWIP_STATS_DISPLAY==1: Compile in the statistics output functions. */ #ifndef LWIP_STATS_DISPLAY -#define LWIP_STATS_DISPLAY 0 +#define LWIP_STATS_DISPLAY 0 #endif /** * LINK_STATS==1: Enable link stats. */ #ifndef LINK_STATS -#define LINK_STATS 1 +#define LINK_STATS 1 #endif /** * ETHARP_STATS==1: Enable etharp stats. */ #ifndef ETHARP_STATS -#define ETHARP_STATS (LWIP_ARP) +#define ETHARP_STATS (LWIP_ARP) #endif /** * IP_STATS==1: Enable IP stats. */ #ifndef IP_STATS -#define IP_STATS 1 +#define IP_STATS 1 #endif /** @@ -1571,21 +1570,21 @@ * on if using either frag or reass. */ #ifndef IPFRAG_STATS -#define IPFRAG_STATS (IP_REASSEMBLY || IP_FRAG) +#define IPFRAG_STATS (IP_REASSEMBLY || IP_FRAG) #endif /** * ICMP_STATS==1: Enable ICMP stats. */ #ifndef ICMP_STATS -#define ICMP_STATS 1 +#define ICMP_STATS 1 #endif /** * IGMP_STATS==1: Enable IGMP stats. */ #ifndef IGMP_STATS -#define IGMP_STATS (LWIP_IGMP) +#define IGMP_STATS (LWIP_IGMP) #endif /** @@ -1593,7 +1592,7 @@ * UDP enabled, otherwise off. */ #ifndef UDP_STATS -#define UDP_STATS (LWIP_UDP) +#define UDP_STATS (LWIP_UDP) #endif /** @@ -1601,43 +1600,43 @@ * enabled, otherwise off. */ #ifndef TCP_STATS -#define TCP_STATS (LWIP_TCP) +#define TCP_STATS (LWIP_TCP) #endif /** * MEM_STATS==1: Enable mem.c stats. */ #ifndef MEM_STATS -#define MEM_STATS ((MEM_LIBC_MALLOC == 0) && (MEM_USE_POOLS == 0)) +#define MEM_STATS ((MEM_LIBC_MALLOC == 0) && (MEM_USE_POOLS == 0)) #endif /** * MEMP_STATS==1: Enable memp.c pool stats. */ #ifndef MEMP_STATS -#define MEMP_STATS (MEMP_MEM_MALLOC == 0) +#define MEMP_STATS (MEMP_MEM_MALLOC == 0) #endif /** * SYS_STATS==1: Enable system stats (sem and mbox counts, etc). */ #ifndef SYS_STATS -#define SYS_STATS (NO_SYS == 0) +#define SYS_STATS (NO_SYS == 0) #endif #else -#define LINK_STATS 0 -#define IP_STATS 0 -#define IPFRAG_STATS 0 -#define ICMP_STATS 0 -#define IGMP_STATS 0 -#define UDP_STATS 0 -#define TCP_STATS 0 -#define MEM_STATS 0 -#define MEMP_STATS 0 -#define SYS_STATS 0 -#define LWIP_STATS_DISPLAY 0 +#define LINK_STATS 0 +#define IP_STATS 0 +#define IPFRAG_STATS 0 +#define ICMP_STATS 0 +#define IGMP_STATS 0 +#define UDP_STATS 0 +#define TCP_STATS 0 +#define MEM_STATS 0 +#define MEMP_STATS 0 +#define SYS_STATS 0 +#define LWIP_STATS_DISPLAY 0 #endif /* LWIP_STATS */ @@ -1650,21 +1649,21 @@ * PPP_SUPPORT==1: Enable PPP. */ #ifndef PPP_SUPPORT -#define PPP_SUPPORT 0 +#define PPP_SUPPORT 0 #endif /** * PPPOE_SUPPORT==1: Enable PPP Over Ethernet */ #ifndef PPPOE_SUPPORT -#define PPPOE_SUPPORT 0 +#define PPPOE_SUPPORT 0 #endif /** * PPPOS_SUPPORT==1: Enable PPP Over Serial */ #ifndef PPPOS_SUPPORT -#define PPPOS_SUPPORT PPP_SUPPORT +#define PPPOS_SUPPORT PPP_SUPPORT #endif #if PPP_SUPPORT @@ -1673,106 +1672,106 @@ * NUM_PPP: Max PPP sessions. */ #ifndef NUM_PPP -#define NUM_PPP 1 +#define NUM_PPP 1 #endif /** * PAP_SUPPORT==1: Support PAP. */ #ifndef PAP_SUPPORT -#define PAP_SUPPORT 0 +#define PAP_SUPPORT 0 #endif /** * CHAP_SUPPORT==1: Support CHAP. */ #ifndef CHAP_SUPPORT -#define CHAP_SUPPORT 0 +#define CHAP_SUPPORT 0 #endif /** * MSCHAP_SUPPORT==1: Support MSCHAP. CURRENTLY NOT SUPPORTED! DO NOT SET! */ #ifndef MSCHAP_SUPPORT -#define MSCHAP_SUPPORT 0 +#define MSCHAP_SUPPORT 0 #endif /** * CBCP_SUPPORT==1: Support CBCP. CURRENTLY NOT SUPPORTED! DO NOT SET! */ #ifndef CBCP_SUPPORT -#define CBCP_SUPPORT 0 +#define CBCP_SUPPORT 0 #endif /** * CCP_SUPPORT==1: Support CCP. CURRENTLY NOT SUPPORTED! DO NOT SET! */ #ifndef CCP_SUPPORT -#define CCP_SUPPORT 0 +#define CCP_SUPPORT 0 #endif /** * VJ_SUPPORT==1: Support VJ header compression. */ #ifndef VJ_SUPPORT -#define VJ_SUPPORT 0 +#define VJ_SUPPORT 0 #endif /** * MD5_SUPPORT==1: Support MD5 (see also CHAP). */ #ifndef MD5_SUPPORT -#define MD5_SUPPORT 0 +#define MD5_SUPPORT 0 #endif /* * Timeouts */ #ifndef FSM_DEFTIMEOUT -#define FSM_DEFTIMEOUT 6 /* Timeout time in seconds */ +#define FSM_DEFTIMEOUT 6 /* Timeout time in seconds */ #endif #ifndef FSM_DEFMAXTERMREQS -#define FSM_DEFMAXTERMREQS 2 /* Maximum Terminate-Request transmissions */ +#define FSM_DEFMAXTERMREQS 2 /* Maximum Terminate-Request transmissions */ #endif #ifndef FSM_DEFMAXCONFREQS -#define FSM_DEFMAXCONFREQS 10 /* Maximum Configure-Request transmissions */ +#define FSM_DEFMAXCONFREQS 10 /* Maximum Configure-Request transmissions */ #endif #ifndef FSM_DEFMAXNAKLOOPS -#define FSM_DEFMAXNAKLOOPS 5 /* Maximum number of nak loops */ +#define FSM_DEFMAXNAKLOOPS 5 /* Maximum number of nak loops */ #endif #ifndef UPAP_DEFTIMEOUT -#define UPAP_DEFTIMEOUT 6 /* Timeout (seconds) for retransmitting req */ +#define UPAP_DEFTIMEOUT 6 /* Timeout (seconds) for retransmitting req */ #endif #ifndef UPAP_DEFREQTIME -#define UPAP_DEFREQTIME 30 /* Time to wait for auth-req from peer */ +#define UPAP_DEFREQTIME 30 /* Time to wait for auth-req from peer */ #endif #ifndef CHAP_DEFTIMEOUT -#define CHAP_DEFTIMEOUT 6 /* Timeout time in seconds */ +#define CHAP_DEFTIMEOUT 6 /* Timeout time in seconds */ #endif #ifndef CHAP_DEFTRANSMITS -#define CHAP_DEFTRANSMITS 10 /* max # times to send challenge */ +#define CHAP_DEFTRANSMITS 10 /* max # times to send challenge */ #endif /* Interval in seconds between keepalive echo requests, 0 to disable. */ #ifndef LCP_ECHOINTERVAL -#define LCP_ECHOINTERVAL 0 +#define LCP_ECHOINTERVAL 0 #endif /* Number of unanswered echo requests before failure. */ #ifndef LCP_MAXECHOFAILS -#define LCP_MAXECHOFAILS 3 +#define LCP_MAXECHOFAILS 3 #endif /* Max Xmit idle time (in jiffies) before resend flag char. */ #ifndef PPP_MAXIDLEFLAG -#define PPP_MAXIDLEFLAG 100 +#define PPP_MAXIDLEFLAG 100 #endif /* @@ -1783,24 +1782,24 @@ * (XXX - these constants should simply be shared by lcp.c instead * of living in lcp.h) */ -#define PPP_MTU 1500 /* Default MTU (size of Info field) */ +#define PPP_MTU 1500 /* Default MTU (size of Info field) */ #ifndef PPP_MAXMTU /* #define PPP_MAXMTU 65535 - (PPP_HDRLEN + PPP_FCSLEN) */ -#define PPP_MAXMTU 1500 /* Largest MTU we allow */ +#define PPP_MAXMTU 1500 /* Largest MTU we allow */ #endif -#define PPP_MINMTU 64 -#define PPP_MRU 1500 /* default MRU = max length of info field */ -#define PPP_MAXMRU 1500 /* Largest MRU we allow */ +#define PPP_MINMTU 64 +#define PPP_MRU 1500 /* default MRU = max length of info field */ +#define PPP_MAXMRU 1500 /* Largest MRU we allow */ #ifndef PPP_DEFMRU -#define PPP_DEFMRU 296 /* Try for this */ +#define PPP_DEFMRU 296 /* Try for this */ #endif -#define PPP_MINMRU 128 /* No MRUs below this */ +#define PPP_MINMRU 128 /* No MRUs below this */ #ifndef MAXNAMELEN -#define MAXNAMELEN 256 /* max length of hostname or name for auth */ +#define MAXNAMELEN 256 /* max length of hostname or name for auth */ #endif #ifndef MAXSECRETLEN -#define MAXSECRETLEN 256 /* max length of password or secret */ +#define MAXSECRETLEN 256 /* max length of password or secret */ #endif #endif /* PPP_SUPPORT */ @@ -1814,49 +1813,49 @@ * CHECKSUM_GEN_IP==1: Generate checksums in software for outgoing IP packets. */ #ifndef CHECKSUM_GEN_IP -#define CHECKSUM_GEN_IP 1 +#define CHECKSUM_GEN_IP 1 #endif - + /** * CHECKSUM_GEN_UDP==1: Generate checksums in software for outgoing UDP packets. */ #ifndef CHECKSUM_GEN_UDP -#define CHECKSUM_GEN_UDP 1 +#define CHECKSUM_GEN_UDP 1 #endif - + /** * CHECKSUM_GEN_TCP==1: Generate checksums in software for outgoing TCP packets. */ #ifndef CHECKSUM_GEN_TCP -#define CHECKSUM_GEN_TCP 1 +#define CHECKSUM_GEN_TCP 1 #endif /** * CHECKSUM_GEN_ICMP==1: Generate checksums in software for outgoing ICMP packets. */ #ifndef CHECKSUM_GEN_ICMP -#define CHECKSUM_GEN_ICMP 1 +#define CHECKSUM_GEN_ICMP 1 #endif - + /** * CHECKSUM_CHECK_IP==1: Check checksums in software for incoming IP packets. */ #ifndef CHECKSUM_CHECK_IP -#define CHECKSUM_CHECK_IP 1 +#define CHECKSUM_CHECK_IP 1 #endif - + /** * CHECKSUM_CHECK_UDP==1: Check checksums in software for incoming UDP packets. */ #ifndef CHECKSUM_CHECK_UDP -#define CHECKSUM_CHECK_UDP 1 +#define CHECKSUM_CHECK_UDP 1 #endif /** * CHECKSUM_CHECK_TCP==1: Check checksums in software for incoming TCP packets. */ #ifndef CHECKSUM_CHECK_TCP -#define CHECKSUM_CHECK_TCP 1 +#define CHECKSUM_CHECK_TCP 1 #endif /** @@ -1864,7 +1863,7 @@ * application buffers to pbufs. */ #ifndef LWIP_CHECKSUM_ON_COPY -#define LWIP_CHECKSUM_ON_COPY 0 +#define LWIP_CHECKSUM_ON_COPY 0 #endif /* @@ -1906,7 +1905,7 @@ * messages are written. */ #ifndef LWIP_DBG_MIN_LEVEL -#define LWIP_DBG_MIN_LEVEL LWIP_DBG_LEVEL_ALL +#define LWIP_DBG_MIN_LEVEL LWIP_DBG_LEVEL_ALL #endif /** @@ -1914,140 +1913,140 @@ * debug messages of certain types. */ #ifndef LWIP_DBG_TYPES_ON -#define LWIP_DBG_TYPES_ON LWIP_DBG_OFF +#define LWIP_DBG_TYPES_ON LWIP_DBG_OFF #endif /** * ETHARP_DEBUG: Enable debugging in etharp.c. */ #ifndef ETHARP_DEBUG -#define ETHARP_DEBUG LWIP_DBG_OFF +#define ETHARP_DEBUG LWIP_DBG_OFF #endif /** * NETIF_DEBUG: Enable debugging in netif.c. */ #ifndef NETIF_DEBUG -#define NETIF_DEBUG LWIP_DBG_OFF +#define NETIF_DEBUG LWIP_DBG_OFF #endif /** * PBUF_DEBUG: Enable debugging in pbuf.c. */ #ifndef PBUF_DEBUG -#define PBUF_DEBUG LWIP_DBG_OFF +#define PBUF_DEBUG LWIP_DBG_OFF #endif /** * API_LIB_DEBUG: Enable debugging in api_lib.c. */ #ifndef API_LIB_DEBUG -#define API_LIB_DEBUG LWIP_DBG_OFF +#define API_LIB_DEBUG LWIP_DBG_OFF #endif /** * API_MSG_DEBUG: Enable debugging in api_msg.c. */ #ifndef API_MSG_DEBUG -#define API_MSG_DEBUG LWIP_DBG_OFF +#define API_MSG_DEBUG LWIP_DBG_OFF #endif /** * SOCKETS_DEBUG: Enable debugging in sockets.c. */ #ifndef SOCKETS_DEBUG -#define SOCKETS_DEBUG LWIP_DBG_OFF +#define SOCKETS_DEBUG LWIP_DBG_OFF #endif /** * ICMP_DEBUG: Enable debugging in icmp.c. */ #ifndef ICMP_DEBUG -#define ICMP_DEBUG LWIP_DBG_OFF +#define ICMP_DEBUG LWIP_DBG_OFF #endif /** * IGMP_DEBUG: Enable debugging in igmp.c. */ #ifndef IGMP_DEBUG -#define IGMP_DEBUG LWIP_DBG_OFF +#define IGMP_DEBUG LWIP_DBG_OFF #endif /** * INET_DEBUG: Enable debugging in inet.c. */ #ifndef INET_DEBUG -#define INET_DEBUG LWIP_DBG_OFF +#define INET_DEBUG LWIP_DBG_OFF #endif /** * IP_DEBUG: Enable debugging for IP. */ #ifndef IP_DEBUG -#define IP_DEBUG LWIP_DBG_OFF +#define IP_DEBUG LWIP_DBG_OFF #endif /** * IP_REASS_DEBUG: Enable debugging in ip_frag.c for both frag & reass. */ #ifndef IP_REASS_DEBUG -#define IP_REASS_DEBUG LWIP_DBG_OFF +#define IP_REASS_DEBUG LWIP_DBG_OFF #endif /** * RAW_DEBUG: Enable debugging in raw.c. */ #ifndef RAW_DEBUG -#define RAW_DEBUG LWIP_DBG_OFF +#define RAW_DEBUG LWIP_DBG_OFF #endif /** * MEM_DEBUG: Enable debugging in mem.c. */ #ifndef MEM_DEBUG -#define MEM_DEBUG LWIP_DBG_OFF +#define MEM_DEBUG LWIP_DBG_OFF #endif /** * MEMP_DEBUG: Enable debugging in memp.c. */ #ifndef MEMP_DEBUG -#define MEMP_DEBUG LWIP_DBG_OFF +#define MEMP_DEBUG LWIP_DBG_OFF #endif /** * SYS_DEBUG: Enable debugging in sys.c. */ #ifndef SYS_DEBUG -#define SYS_DEBUG LWIP_DBG_OFF +#define SYS_DEBUG LWIP_DBG_OFF #endif /** * TIMERS_DEBUG: Enable debugging in timers.c. */ #ifndef TIMERS_DEBUG -#define TIMERS_DEBUG LWIP_DBG_OFF +#define TIMERS_DEBUG LWIP_DBG_OFF #endif /** * TCP_DEBUG: Enable debugging for TCP. */ #ifndef TCP_DEBUG -#define TCP_DEBUG LWIP_DBG_OFF +#define TCP_DEBUG LWIP_DBG_OFF #endif /** * TCP_INPUT_DEBUG: Enable debugging in tcp_in.c for incoming debug. */ #ifndef TCP_INPUT_DEBUG -#define TCP_INPUT_DEBUG LWIP_DBG_OFF +#define TCP_INPUT_DEBUG LWIP_DBG_OFF #endif /** * TCP_FR_DEBUG: Enable debugging in tcp_in.c for fast retransmit. */ #ifndef TCP_FR_DEBUG -#define TCP_FR_DEBUG LWIP_DBG_OFF +#define TCP_FR_DEBUG LWIP_DBG_OFF #endif /** @@ -2055,105 +2054,105 @@ * timeout. */ #ifndef TCP_RTO_DEBUG -#define TCP_RTO_DEBUG LWIP_DBG_OFF +#define TCP_RTO_DEBUG LWIP_DBG_OFF #endif /** * TCP_CWND_DEBUG: Enable debugging for TCP congestion window. */ #ifndef TCP_CWND_DEBUG -#define TCP_CWND_DEBUG LWIP_DBG_OFF +#define TCP_CWND_DEBUG LWIP_DBG_OFF #endif /** * TCP_WND_DEBUG: Enable debugging in tcp_in.c for window updating. */ #ifndef TCP_WND_DEBUG -#define TCP_WND_DEBUG LWIP_DBG_OFF +#define TCP_WND_DEBUG LWIP_DBG_OFF #endif /** * TCP_OUTPUT_DEBUG: Enable debugging in tcp_out.c output functions. */ #ifndef TCP_OUTPUT_DEBUG -#define TCP_OUTPUT_DEBUG LWIP_DBG_OFF +#define TCP_OUTPUT_DEBUG LWIP_DBG_OFF #endif /** * TCP_RST_DEBUG: Enable debugging for TCP with the RST message. */ #ifndef TCP_RST_DEBUG -#define TCP_RST_DEBUG LWIP_DBG_OFF +#define TCP_RST_DEBUG LWIP_DBG_OFF #endif /** * TCP_QLEN_DEBUG: Enable debugging for TCP queue lengths. */ #ifndef TCP_QLEN_DEBUG -#define TCP_QLEN_DEBUG LWIP_DBG_OFF +#define TCP_QLEN_DEBUG LWIP_DBG_OFF #endif /** * UDP_DEBUG: Enable debugging in UDP. */ #ifndef UDP_DEBUG -#define UDP_DEBUG LWIP_DBG_OFF +#define UDP_DEBUG LWIP_DBG_OFF #endif /** * TCPIP_DEBUG: Enable debugging in tcpip.c. */ #ifndef TCPIP_DEBUG -#define TCPIP_DEBUG LWIP_DBG_OFF +#define TCPIP_DEBUG LWIP_DBG_OFF #endif /** * PPP_DEBUG: Enable debugging for PPP. */ #ifndef PPP_DEBUG -#define PPP_DEBUG LWIP_DBG_OFF +#define PPP_DEBUG LWIP_DBG_OFF #endif /** * SLIP_DEBUG: Enable debugging in slipif.c. */ #ifndef SLIP_DEBUG -#define SLIP_DEBUG LWIP_DBG_OFF +#define SLIP_DEBUG LWIP_DBG_OFF #endif /** * DHCP_DEBUG: Enable debugging in dhcp.c. */ #ifndef DHCP_DEBUG -#define DHCP_DEBUG LWIP_DBG_OFF +#define DHCP_DEBUG LWIP_DBG_OFF #endif /** * AUTOIP_DEBUG: Enable debugging in autoip.c. */ #ifndef AUTOIP_DEBUG -#define AUTOIP_DEBUG LWIP_DBG_OFF +#define AUTOIP_DEBUG LWIP_DBG_OFF #endif /** * SNMP_MSG_DEBUG: Enable debugging for SNMP messages. */ #ifndef SNMP_MSG_DEBUG -#define SNMP_MSG_DEBUG LWIP_DBG_OFF +#define SNMP_MSG_DEBUG LWIP_DBG_OFF #endif /** * SNMP_MIB_DEBUG: Enable debugging for SNMP MIBs. */ #ifndef SNMP_MIB_DEBUG -#define SNMP_MIB_DEBUG LWIP_DBG_OFF +#define SNMP_MIB_DEBUG LWIP_DBG_OFF #endif /** * DNS_DEBUG: Enable debugging for DNS. */ #ifndef DNS_DEBUG -#define DNS_DEBUG LWIP_DBG_OFF +#define DNS_DEBUG LWIP_DBG_OFF #endif // in order to enable the lwIP debug output the below has to be uncomment and diff --git a/targets/CMSIS-OS/ChibiOS/Include/platform_target_capabilities.h b/targets/CMSIS-OS/ChibiOS/Include/platform_target_capabilities.h index eb7f38d850..d716779d98 100644 --- a/targets/CMSIS-OS/ChibiOS/Include/platform_target_capabilities.h +++ b/targets/CMSIS-OS/ChibiOS/Include/platform_target_capabilities.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/Include/targetHAL.h b/targets/CMSIS-OS/ChibiOS/Include/targetHAL.h index 0080329a2c..ac94d6eca8 100644 --- a/targets/CMSIS-OS/ChibiOS/Include/targetHAL.h +++ b/targets/CMSIS-OS/ChibiOS/Include/targetHAL.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // @@ -7,29 +7,25 @@ #define _TARGET_HAL_H_ #include +#include #include #include #include // platform dependent delay -#define PLATFORM_DELAY(milliSecs) osDelay(milliSecs); +#define PLATFORM_DELAY(milliSecs) osDelay(milliSecs); // Definitions for Sockets/Network -#define GLOBAL_LOCK_SOCKETS(x) +#define GLOBAL_LOCK_SOCKETS(x) -#define PLATFORM_DEPENDENT__SOCKETS_MAX_COUNT 16 +// get number of sockets from lwIP options +#define PLATFORM_DEPENDENT__SOCKETS_MAX_COUNT MEMP_NUM_NETCONN -#define LPCSTR const char* - -// these macros are to be used at entry/exit of native interrupt handlers -#define NATIVE_INTERRUPT_START SystemState_SetNoLock( SYSTEM_STATE_ISR ); \ - SystemState_SetNoLock( SYSTEM_STATE_NO_CONTINUATIONS ); -#define NATIVE_INTERRUPT_END SystemState_ClearNoLock( SYSTEM_STATE_NO_CONTINUATIONS ); \ - SystemState_ClearNoLock( SYSTEM_STATE_ISR ); +#define LPCSTR const char * #if !defined(BUILD_RTM) -#define HARD_BREAKPOINT() HARD_Breakpoint() +#define HARD_BREAKPOINT() HARD_Breakpoint() // #if defined(_DEBUG) // #define DEBUG_HARD_BREAKPOINT() HARD_Breakpoint() @@ -42,8 +38,7 @@ // #define HARD_BREAKPOINT() // #define DEBUG_HARD_BREAKPOINT() -#endif // !defined(BUILD_RTM) - +#endif // !defined(BUILD_RTM) ///////////////////////////////////////////////////////////////////////////////////////////////////// // DEBUGGER HELPER // @@ -52,11 +47,11 @@ // The implementation should is to be provided by each target at target_common.h.in // //////////////////////////////////////////////////////////////////////////////////////////////////// #if defined(BUILD_RTM) - #define EVENTS_HEART_BEAT +#define EVENTS_HEART_BEAT #else - #ifndef EVENTS_HEART_BEAT - #define EVENTS_HEART_BEAT __NOP() - #endif // EVENTS_HEART_BEAT +#ifndef EVENTS_HEART_BEAT +#define EVENTS_HEART_BEAT __NOP() +#endif // EVENTS_HEART_BEAT #endif #define NANOCLR_STOP() CPU_Reset(); @@ -71,23 +66,23 @@ extern uint32_t __nanoConfig_end__; extern uint32_t __deployment_start__; extern uint32_t __deployment_end__; +extern int my_lock_counter; + +#define GLOBAL_LOCK() \ + { \ + if (port_is_isr_context()) \ + chSysLockFromISR(); \ + else \ + chSysLock(); + +#define GLOBAL_UNLOCK() \ + if (port_is_isr_context()) \ + chSysUnlockFromISR(); \ + else \ + chSysUnlock(); \ + } + #endif //_TARGET_HAL_H_ -extern int my_lock_counter; - -#define GLOBAL_LOCK() \ - { \ - if (port_is_isr_context()) \ - chSysLockFromISR(); \ - else \ - chSysLock(); - - -#define GLOBAL_UNLOCK() \ - if (port_is_isr_context()) \ - chSysUnlockFromISR(); \ - else \ - chSysUnlock(); \ - } - -//#define GLOBAL_LOCK() chSysLock(); -//#define GLOBAL_UNLOCK(); chSysUnlock(); + +//#define GLOBAL_LOCK() chSysLock(); +//#define GLOBAL_UNLOCK(); chSysUnlock(); diff --git a/targets/CMSIS-OS/ChibiOS/Include/targetHAL_Power.h b/targets/CMSIS-OS/ChibiOS/Include/targetHAL_Power.h index 96d00feec0..778225b63f 100644 --- a/targets/CMSIS-OS/ChibiOS/Include/targetHAL_Power.h +++ b/targets/CMSIS-OS/ChibiOS/Include/targetHAL_Power.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/Include/targetHAL_Time.h b/targets/CMSIS-OS/ChibiOS/Include/targetHAL_Time.h index 8808317877..3a60dde1d4 100644 --- a/targets/CMSIS-OS/ChibiOS/Include/targetHAL_Time.h +++ b/targets/CMSIS-OS/ChibiOS/Include/targetHAL_Time.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/Include/targetHAL_Watchdog.h b/targets/CMSIS-OS/ChibiOS/Include/targetHAL_Watchdog.h index e1ac49b008..6c8292c9ac 100644 --- a/targets/CMSIS-OS/ChibiOS/Include/targetHAL_Watchdog.h +++ b/targets/CMSIS-OS/ChibiOS/Include/targetHAL_Watchdog.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // #include diff --git a/targets/CMSIS-OS/ChibiOS/Include/targetPAL.h b/targets/CMSIS-OS/ChibiOS/Include/targetPAL.h index b8edb90136..23df3e04b4 100644 --- a/targets/CMSIS-OS/ChibiOS/Include/targetPAL.h +++ b/targets/CMSIS-OS/ChibiOS/Include/targetPAL.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/Include/targetPAL_Time.h b/targets/CMSIS-OS/ChibiOS/Include/targetPAL_Time.h index 3d857fd3c4..640e0c28be 100644 --- a/targets/CMSIS-OS/ChibiOS/Include/targetPAL_Time.h +++ b/targets/CMSIS-OS/ChibiOS/Include/targetPAL_Time.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/Lwip/platform_sys_arch.c b/targets/CMSIS-OS/ChibiOS/Lwip/platform_sys_arch.c index 5f030756fa..d0e9aff9dc 100644 --- a/targets/CMSIS-OS/ChibiOS/Lwip/platform_sys_arch.c +++ b/targets/CMSIS-OS/ChibiOS/Lwip/platform_sys_arch.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2001-2004 Swedish Institute of Computer Science. All rights reserved. // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. diff --git a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/CMakeLists.txt b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/CMakeLists.txt index 9b420b646e..ab77a4089a 100644 --- a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/CMakeLists.txt +++ b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # @@ -17,7 +17,7 @@ set(NANOBOOTER_PROJECT_NAME "nanoBooter") set(NANOCLR_PROJECT_NAME "nanoCLR") find_package(BuildUtils REQUIRED) -find_package(CHIBIOS REQUIRED) +find_package(ChibiOS REQUIRED) find_package(ChibiOSnfOverlay REQUIRED) find_package(WireProtocol REQUIRED) diff --git a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/board.h b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/board.h index fa8d113f1e..c6c8108149 100644 --- a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/board.h +++ b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/board.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/cmake-variants.json b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/cmake-variants.json new file mode 100644 index 0000000000..ce11100a08 --- /dev/null +++ b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/cmake-variants.json @@ -0,0 +1,59 @@ +{ + "buildType": { + "default": "debug", + "choices": { + "debug": { + "short": "Debug", + "long": "Emit debug information without performing optimizations", + "buildType": "Debug" + }, + "minsize": { + "short": "MinSizeRel", + "long": "Optimize for smallest binary size", + "buildType": "MinSizeRel" + }, + "reldeb": { + "short": "RelWithDebInfo", + "long": "Perform optimizations AND include debugging information", + "buildType": "RelWithDebInfo" + } + } + }, + "linkage": { + "default": "", + "choices": { + "MBN_QUAIL": { + "short": "MBN_QUAIL", + "settings": { + "BUILD_VERSION": "0.9.99.999", + "CMAKE_TOOLCHAIN_FILE" : "CMake/toolchain.arm-none-eabi.cmake", + "TOOLCHAIN_PREFIX": "", + "TOOL_HEX2DFU_PREFIX": "", + "RTOS": "CHIBIOS", + "TARGET_SERIES": "STM32F4xx", + "RTOS_SOURCE_FOLDER": "", + "RTOS_BOARD": "MBN_QUAIL", + "CHIBIOS_CONTRIB_REQUIRED": "OFF", + "CHIBIOS_CONTRIB_SOURCE": "", + "STM32_CUBE_PACKAGE_REQUIRED": "OFF", + "STM32_CUBE_PACKAGE_SOURCE": "", + "SUPPORT_ANY_BASE_CONVERSION": "ON", + "NF_FEATURE_DEBUGGER": "ON", + "NF_FEATURE_RTC": "ON", + "NF_BUILD_RTM": "OFF", + "API_System.Math": "ON", + "API_Hardware.Stm32": "ON", + "API_Windows.Devices.Gpio": "ON", + "API_Windows.Devices.Spi": "ON", + "API_Windows.Devices.I2c": "ON", + "API_Windows.Devices.Pwm": "ON", + "API_Windows.Devices.SerialCommunication": "ON", + "API_nanoFramework.Devices.OneWire": "ON", + "API_nanoFramework.ResourceManager": "ON", + "API_nanoFramework.System.Collections": "ON", + "API_nanoFramework.System.Text": "ON" + } + } + } + } +} \ No newline at end of file diff --git a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/common/CMakeLists.txt b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/common/CMakeLists.txt index 6c1542ca48..fd2dba947c 100644 --- a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/common/CMakeLists.txt +++ b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/common/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/common/Device_BlockStorage-DEBUG.c b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/common/Device_BlockStorage-DEBUG.c index a970be7725..25d78df213 100644 --- a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/common/Device_BlockStorage-DEBUG.c +++ b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/common/Device_BlockStorage-DEBUG.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/common/Device_BlockStorage.c b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/common/Device_BlockStorage.c index 2342826374..5598400676 100644 --- a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/common/Device_BlockStorage.c +++ b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/common/Device_BlockStorage.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/common/usbcfg.c b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/common/usbcfg.c index a75da7cee7..c1652b62b1 100644 --- a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/common/usbcfg.c +++ b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/common/usbcfg.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/common/usbcfg.h b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/common/usbcfg.h index 354fb4287a..65bf4c35a6 100644 --- a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/common/usbcfg.h +++ b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/common/usbcfg.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/launch.json b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/launch.json new file mode 100644 index 0000000000..fd74aba28f --- /dev/null +++ b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/launch.json @@ -0,0 +1,115 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "NETDUINO3_WIFI nanoBooter", + "type": "cppdbg", + "request": "launch", + "miDebuggerPath": "/bin/arm-none-eabi-gdb.exe", + "targetArchitecture": "ARM", + "program": "${workspaceRoot}/build/nanoBooter.elf", + "setupCommands": [ + { + "text": "target extended-remote localhost:3333" + }, + { + "text": "monitor reset_config none separate" + }, + { + "text": "monitor reset halt" + }, + { + "text": "monitor flash write_image erase \"/build/nanoBooter.hex\" " + }, + { + "text": "file /build/nanoBooter.elf" + }, + { + "text": "monitor reset halt" + }, + { + "text": "set output-radix 16", + "description": "set the default numeric base to 16", + "ignoreFailures": false + } + ], + "customLaunchSetupCommands": [ + { + "text": "monitor reset_config none separate" + }, + { + "text": "monitor reset halt" + } + ], + "logging": { + "moduleLoad": false, + "trace": false, + "engineLogging": false, + "programOutput": true, + "exceptions": true + }, + "launchCompleteCommand": "exec-continue", + "debugServerPath": "/bin/openocd.exe", + "debugServerArgs": "-s \"/scripts/\" -f board/stm32f4discovery.cfg", + "serverStarted": "Info\\ :\\ [\\w\\d\\.]*:\\ hardware", + "filterStderr": true, + "externalConsole": true, + "cwd": "${cwd}" + }, + { + "name": "NETDUINO3_WIFI nanoCLR", + "type": "cppdbg", + "request": "launch", + "miDebuggerPath": "/bin/arm-none-eabi-gdb.exe", + "targetArchitecture": "ARM", + "program": "${workspaceRoot}/build/nanoCLR.elf", + "setupCommands": [ + { + "text": "target extended-remote localhost:3333" + }, + { + "text": "monitor reset_config none separate" + }, + { + "text": "monitor reset halt" + }, + { + "text": "monitor flash write_image erase \"/build/nanoCLR.hex\" " + }, + { + "text": "file /build/nanoCLR.elf" + }, + { + "text": "monitor reset halt" + }, + { + "text": "set output-radix 16", + "description": "set the default numeric base to 16", + "ignoreFailures": false + } + ], + "customLaunchSetupCommands": [ + { + "text": "monitor reset_config none separate" + }, + { + "text": "monitor reset halt" + } + ], + "logging": { + "moduleLoad": false, + "trace": false, + "engineLogging": false, + "programOutput": true, + "exceptions": true + }, + "launchCompleteCommand": "exec-continue", + "debugServerPath": "/bin/openocd.exe", + "debugServerArgs": "-s \"/scripts/\" -f board/stm32429i_eval_stlink.cfg", + "serverStarted": "Info\\ :\\ [\\w\\d\\.]*:\\ hardware", + "filterStderr": true, + "externalConsole": true, + "cwd": "${cwd}" + } + ] +} \ No newline at end of file diff --git a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoBooter/CMakeLists.txt b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoBooter/CMakeLists.txt index fca210179c..8b73c031cd 100644 --- a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoBooter/CMakeLists.txt +++ b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoBooter/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoBooter/chconf.h b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoBooter/chconf.h index 9b971fb64e..ced99e403d 100644 --- a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoBooter/chconf.h +++ b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoBooter/chconf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoBooter/halconf.h b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoBooter/halconf.h index 35930c9932..603ef67803 100644 --- a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoBooter/halconf.h +++ b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoBooter/halconf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoBooter/halconf_nf.h b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoBooter/halconf_nf.h index 725fa09fb7..d8e6723765 100644 --- a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoBooter/halconf_nf.h +++ b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoBooter/halconf_nf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoBooter/main.c b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoBooter/main.c index 6511087078..1ad254bab0 100644 --- a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoBooter/main.c +++ b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoBooter/main.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoBooter/mbn_quail_booter-DEBUG.ld b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoBooter/mbn_quail_booter-DEBUG.ld index 505f0a7af7..8c87275568 100644 --- a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoBooter/mbn_quail_booter-DEBUG.ld +++ b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoBooter/mbn_quail_booter-DEBUG.ld @@ -1,6 +1,6 @@ /* // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoBooter/mbn_quail_booter.ld b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoBooter/mbn_quail_booter.ld index 315881629a..1df12a065d 100644 --- a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoBooter/mbn_quail_booter.ld +++ b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoBooter/mbn_quail_booter.ld @@ -1,6 +1,6 @@ /* // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoBooter/mcuconf.h b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoBooter/mcuconf.h index 7afe4083f6..df28db4e4e 100644 --- a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoBooter/mcuconf.h +++ b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoBooter/mcuconf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoBooter/mcuconf_nf.h b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoBooter/mcuconf_nf.h index a69773a129..d15f9ce64b 100644 --- a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoBooter/mcuconf_nf.h +++ b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoBooter/mcuconf_nf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoBooter/target_board.h.in b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoBooter/target_board.h.in index 880aebeaca..25310190f0 100644 --- a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoBooter/target_board.h.in +++ b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoBooter/target_board.h.in @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoCLR/CMakeLists.txt b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoCLR/CMakeLists.txt index 43cba58931..751bfa9537 100644 --- a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoCLR/CMakeLists.txt +++ b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoCLR/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoCLR/chconf.h b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoCLR/chconf.h index f3f2f640d9..26c2c4b846 100644 --- a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoCLR/chconf.h +++ b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoCLR/chconf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoCLR/halconf.h b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoCLR/halconf.h index a1cf08e623..7659439e2e 100644 --- a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoCLR/halconf.h +++ b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoCLR/halconf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoCLR/halconf_nf.h b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoCLR/halconf_nf.h index 1710cb9cda..0f3b4b74c7 100644 --- a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoCLR/halconf_nf.h +++ b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoCLR/halconf_nf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoCLR/main.c b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoCLR/main.c index 05a84b2686..2a080c391f 100644 --- a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoCLR/main.c +++ b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoCLR/main.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoCLR/mbn_quail_CLR-DEBUG.ld b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoCLR/mbn_quail_CLR-DEBUG.ld index d2ef582b9e..987cb621ed 100644 --- a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoCLR/mbn_quail_CLR-DEBUG.ld +++ b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoCLR/mbn_quail_CLR-DEBUG.ld @@ -1,6 +1,6 @@ /* // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoCLR/mbn_quail_CLR.ld b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoCLR/mbn_quail_CLR.ld index 5a59730ec1..b0c4cb9381 100644 --- a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoCLR/mbn_quail_CLR.ld +++ b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoCLR/mbn_quail_CLR.ld @@ -1,6 +1,6 @@ /* // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoCLR/mcuconf.h b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoCLR/mcuconf.h index 60a895dd4d..b061336571 100644 --- a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoCLR/mcuconf.h +++ b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoCLR/mcuconf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoCLR/mcuconf_nf.h b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoCLR/mcuconf_nf.h index a69773a129..d15f9ce64b 100644 --- a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoCLR/mcuconf_nf.h +++ b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoCLR/mcuconf_nf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoCLR/nanoHAL.cpp b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoCLR/nanoHAL.cpp index 4c278755f9..9b3dd7451e 100644 --- a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoCLR/nanoHAL.cpp +++ b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoCLR/nanoHAL.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoCLR/target_board.h.in b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoCLR/target_board.h.in index 8bb3b241d0..706f53d55e 100644 --- a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoCLR/target_board.h.in +++ b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoCLR/target_board.h.in @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/target_BlockStorage.c b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/target_BlockStorage.c index 9e7c7f5546..db45d1a411 100644 --- a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/target_BlockStorage.c +++ b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/target_BlockStorage.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/target_BlockStorage.h b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/target_BlockStorage.h index aa50b1b7f2..8a56d0eee0 100644 --- a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/target_BlockStorage.h +++ b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/target_BlockStorage.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/target_common.c b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/target_common.c index ccee7c5e03..9fc1974764 100644 --- a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/target_common.c +++ b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/target_common.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/target_common.h.in b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/target_common.h.in index bf75e0d120..1693348fd1 100644 --- a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/target_common.h.in +++ b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/target_common.h.in @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/target_nf_devices_onewire_config.cpp b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/target_nf_devices_onewire_config.cpp index 5df22a7d2a..e8d1ba126d 100644 --- a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/target_nf_devices_onewire_config.cpp +++ b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/target_nf_devices_onewire_config.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/target_nf_devices_onewire_config.h b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/target_nf_devices_onewire_config.h index d0fb1c8775..e54cfb0f9b 100644 --- a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/target_nf_devices_onewire_config.h +++ b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/target_nf_devices_onewire_config.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/target_system_devices_dac_config.cpp b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/target_system_devices_dac_config.cpp index 97181d6fec..35a61746cb 100644 --- a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/target_system_devices_dac_config.cpp +++ b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/target_system_devices_dac_config.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/target_windows_devices_i2c_config.cpp b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/target_windows_devices_i2c_config.cpp index 18b1cd191d..45bb32f24e 100644 --- a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/target_windows_devices_i2c_config.cpp +++ b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/target_windows_devices_i2c_config.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/target_windows_devices_serialcommunication_config.cpp b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/target_windows_devices_serialcommunication_config.cpp index d4957c6d83..93f5dac659 100644 --- a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/target_windows_devices_serialcommunication_config.cpp +++ b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/target_windows_devices_serialcommunication_config.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/target_windows_devices_serialcommunication_config.h b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/target_windows_devices_serialcommunication_config.h index 9f7ead7292..21999c6f04 100644 --- a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/target_windows_devices_serialcommunication_config.h +++ b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/target_windows_devices_serialcommunication_config.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/target_windows_devices_spi_config.cpp b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/target_windows_devices_spi_config.cpp index 57e5a72eda..896a04c243 100644 --- a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/target_windows_devices_spi_config.cpp +++ b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/target_windows_devices_spi_config.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/target_windows_storage_config.h b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/target_windows_storage_config.h index 8601cffd16..a9a27a7454 100644 --- a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/target_windows_storage_config.h +++ b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/target_windows_storage_config.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/CMakeLists.txt b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/CMakeLists.txt index d65f39be6f..d580bcefae 100644 --- a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/CMakeLists.txt +++ b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # @@ -17,7 +17,7 @@ set(NANOBOOTER_PROJECT_NAME "nanoBooter") set(NANOCLR_PROJECT_NAME "nanoCLR") find_package(BuildUtils REQUIRED) -find_package(CHIBIOS REQUIRED) +find_package(ChibiOS REQUIRED) find_package(ChibiOSnfOverlay REQUIRED) find_package(WireProtocol REQUIRED) diff --git a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/board.h b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/board.h index b72dcb4e99..e2fe9b672e 100644 --- a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/board.h +++ b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/board.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/cmake-variants.json b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/cmake-variants.json new file mode 100644 index 0000000000..7716d7cbe9 --- /dev/null +++ b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/cmake-variants.json @@ -0,0 +1,63 @@ +{ + "buildType": { + "default": "debug", + "choices": { + "debug": { + "short": "Debug", + "long": "Emit debug information without performing optimizations", + "buildType": "Debug" + }, + "minsize": { + "short": "MinSizeRel", + "long": "Optimize for smallest binary size", + "buildType": "MinSizeRel" + }, + "reldeb": { + "short": "RelWithDebInfo", + "long": "Perform optimizations AND include debugging information", + "buildType": "RelWithDebInfo" + } + } + }, + "linkage": { + "default": "", + "choices": { + "NETDUINO3_WIFI": { + "short": "NETDUINO3_WIFI", + "settings": { + "BUILD_VERSION": "0.9.99.999", + "CMAKE_TOOLCHAIN_FILE" : "CMake/toolchain.arm-none-eabi.cmake", + "TOOLCHAIN_PREFIX": "", + "TOOL_HEX2DFU_PREFIX": "", + "RTOS": "CHIBIOS", + "TARGET_SERIES": "STM32F4xx", + "RTOS_SOURCE_FOLDER": "", + "CHIBIOS_BOARD": "NETDUINO3_WIFI", + "CHIBIOS_CONTRIB_REQUIRED": "OFF", + "CHIBIOS_CONTRIB_SOURCE": "", + "STM32_CUBE_PACKAGE_REQUIRED": "OFF", + "STM32_CUBE_PACKAGE_SOURCE": "", + "MBEDTLS_SOURCE": "", + "SUPPORT_ANY_BASE_CONVERSION": "ON", + "NF_FEATURE_DEBUGGER": "ON", + "NF_FEATURE_RTC": "ON", + "NF_FEATURE_HAS_SDCARD": "ON", + "SWO_OUTPUT": "OFF", + "NF_BUILD_RTM": "OFF", + "API_System.Math": "ON", + "API_Hardware.Stm32": "ON", + "API_Windows.Devices.Gpio": "ON", + "API_Windows.Devices.Spi": "ON", + "API_Windows.Devices.I2c": "ON", + "API_Windows.Devices.Pwm": "ON", + "API_Windows.Devices.SerialCommunication": "ON", + "API_Windows.Devices.Adc": "ON", + "API_nanoFramework.Devices.OneWire": "ON", + "API_nanoFramework.ResourceManager": "ON", + "API_nanoFramework.System.Collections": "ON", + "API_nanoFramework.System.Text": "ON" + } + } + } + } +} \ No newline at end of file diff --git a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/common/CMakeLists.txt b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/common/CMakeLists.txt index aa7f1d543b..e363bd4e5f 100644 --- a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/common/CMakeLists.txt +++ b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/common/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/common/Device_BlockStorage-DEBUG.c b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/common/Device_BlockStorage-DEBUG.c index a970be7725..25d78df213 100644 --- a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/common/Device_BlockStorage-DEBUG.c +++ b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/common/Device_BlockStorage-DEBUG.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/common/Device_BlockStorage.c b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/common/Device_BlockStorage.c index 2342826374..5598400676 100644 --- a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/common/Device_BlockStorage.c +++ b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/common/Device_BlockStorage.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/common/usbcfg.c b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/common/usbcfg.c index 9fd0a5adfe..b976bbf343 100644 --- a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/common/usbcfg.c +++ b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/common/usbcfg.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/common/usbcfg.h b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/common/usbcfg.h index 167e1df889..47d4546acb 100644 --- a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/common/usbcfg.h +++ b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/common/usbcfg.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/launch.json b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/launch.json new file mode 100644 index 0000000000..3b08d9ea59 --- /dev/null +++ b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/launch.json @@ -0,0 +1,115 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "NETDUINO3_WIFI nanoBooter", + "type": "cppdbg", + "request": "launch", + "miDebuggerPath": "/bin/arm-none-eabi-gdb.exe", + "targetArchitecture": "ARM", + "program": "${workspaceRoot}/build/nanoBooter.elf", + "setupCommands": [ + { + "text": "target extended-remote localhost:3333" + }, + { + "text": "monitor reset_config none separate" + }, + { + "text": "monitor reset halt" + }, + { + "text": "monitor flash write_image erase \"/build/nanoBooter.hex\" " + }, + { + "text": "file /build/nanoBooter.elf" + }, + { + "text": "monitor reset halt" + }, + { + "text": "set output-radix 16", + "description": "set the default numeric base to 16", + "ignoreFailures": false + } + ], + "customLaunchSetupCommands": [ + { + "text": "monitor reset_config none separate" + }, + { + "text": "monitor reset halt" + } + ], + "logging": { + "moduleLoad": false, + "trace": false, + "engineLogging": false, + "programOutput": true, + "exceptions": true + }, + "launchCompleteCommand": "exec-continue", + "debugServerPath": "/bin/openocd.exe", + "debugServerArgs": "-s \"/scripts/\" -f board/stm32f4discovery.cfg", + "serverStarted": "Info\\ :\\ [\\w\\d\\.]*:\\ hardware", + "filterStderr": true, + "externalConsole": true, + "cwd": "${cwd}" + }, + { + "name": "NETDUINO3_WIFI nanoCLR", + "type": "cppdbg", + "request": "launch", + "miDebuggerPath": "/bin/arm-none-eabi-gdb.exe", + "targetArchitecture": "ARM", + "program": "${workspaceRoot}/build/nanoCLR.elf", + "setupCommands": [ + { + "text": "target extended-remote localhost:3333" + }, + { + "text": "monitor reset_config none separate" + }, + { + "text": "monitor reset halt" + }, + { + "text": "monitor flash write_image erase \"/build/nanoCLR.hex\" " + }, + { + "text": "file /build/nanoCLR.elf" + }, + { + "text": "monitor reset halt" + }, + { + "text": "set output-radix 16", + "description": "set the default numeric base to 16", + "ignoreFailures": false + } + ], + "customLaunchSetupCommands": [ + { + "text": "monitor reset_config none separate" + }, + { + "text": "monitor reset halt" + } + ], + "logging": { + "moduleLoad": false, + "trace": false, + "engineLogging": false, + "programOutput": true, + "exceptions": true + }, + "launchCompleteCommand": "exec-continue", + "debugServerPath": "/bin/openocd.exe", + "debugServerArgs": "-s \"/scripts/\" -f board/stm32429i_eval_stlink.cfg", + "serverStarted": "Info\\ :\\ [\\w\\d\\.]*:\\ hardware", + "filterStderr": true, + "externalConsole": true, + "cwd": "${cwd}" + } + ] +} diff --git a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/managed_helpers/NETDUINO3_WIFI.Adc.cs b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/managed_helpers/NETDUINO3_WIFI.Adc.cs index 825543d565..4bdb79d61f 100644 --- a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/managed_helpers/NETDUINO3_WIFI.Adc.cs +++ b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/managed_helpers/NETDUINO3_WIFI.Adc.cs @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/managed_helpers/package.nuspec b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/managed_helpers/package.nuspec index 4a89a9c1c0..860a61a44c 100644 --- a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/managed_helpers/package.nuspec +++ b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/managed_helpers/package.nuspec @@ -18,7 +18,7 @@ https://github.com/nanoframework https://secure.gravatar.com/avatar/97d0e092247f0716db6d4b47b7d1d1ad https://github.com/nanoframework/nf-interpreter/blob/develop/LICENSE.md - Copyright (c) 2019 The nanoFramework project contributors + Copyright (c) .NET Foundation and Contributors nanoFramework, nano Framework, NETNF, NETMF, Micro Framework, STM32, .net, NETDUINO3_WIFI diff --git a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoBooter/CMakeLists.txt b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoBooter/CMakeLists.txt index 291f47e121..09b9337e00 100644 --- a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoBooter/CMakeLists.txt +++ b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoBooter/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoBooter/chconf.h b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoBooter/chconf.h index 13cec57854..de070861bd 100644 --- a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoBooter/chconf.h +++ b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoBooter/chconf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoBooter/halconf.h b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoBooter/halconf.h index b970c22f6f..23e61d878f 100644 --- a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoBooter/halconf.h +++ b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoBooter/halconf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoBooter/halconf_nf.h b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoBooter/halconf_nf.h index ac3bc93126..83ae9e61dc 100644 --- a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoBooter/halconf_nf.h +++ b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoBooter/halconf_nf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoBooter/main.c b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoBooter/main.c index f578ad36a9..9d3a6f2c99 100644 --- a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoBooter/main.c +++ b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoBooter/main.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoBooter/mcuconf.h b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoBooter/mcuconf.h index 0ac31e2c1c..c5548028dc 100644 --- a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoBooter/mcuconf.h +++ b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoBooter/mcuconf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoBooter/mcuconf_nf.h b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoBooter/mcuconf_nf.h index 574b9636f7..f05caa0b4d 100644 --- a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoBooter/mcuconf_nf.h +++ b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoBooter/mcuconf_nf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoBooter/netduino3wifi_booter-DEBUG.ld b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoBooter/netduino3wifi_booter-DEBUG.ld index 505f0a7af7..8c87275568 100644 --- a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoBooter/netduino3wifi_booter-DEBUG.ld +++ b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoBooter/netduino3wifi_booter-DEBUG.ld @@ -1,6 +1,6 @@ /* // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoBooter/netduino3wifi_booter.ld b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoBooter/netduino3wifi_booter.ld index 315881629a..1df12a065d 100644 --- a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoBooter/netduino3wifi_booter.ld +++ b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoBooter/netduino3wifi_booter.ld @@ -1,6 +1,6 @@ /* // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoBooter/target_board.h.in b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoBooter/target_board.h.in index 750beb565c..ad151ebd73 100644 --- a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoBooter/target_board.h.in +++ b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoBooter/target_board.h.in @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoCLR/CMakeLists.txt b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoCLR/CMakeLists.txt index e5496b7ea0..f5fab75926 100644 --- a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoCLR/CMakeLists.txt +++ b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoCLR/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoCLR/chconf.h b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoCLR/chconf.h index 390ce3a688..628a650c57 100644 --- a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoCLR/chconf.h +++ b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoCLR/chconf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoCLR/halconf.h b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoCLR/halconf.h index 264cfad61a..fef6a39531 100644 --- a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoCLR/halconf.h +++ b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoCLR/halconf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoCLR/halconf_nf.h b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoCLR/halconf_nf.h index d6ba3607dd..e97ceee212 100644 --- a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoCLR/halconf_nf.h +++ b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoCLR/halconf_nf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoCLR/main.c b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoCLR/main.c index d2f74c399a..42fa6ef0b0 100644 --- a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoCLR/main.c +++ b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoCLR/main.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoCLR/mcuconf.h b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoCLR/mcuconf.h index 01dd9af272..ac9994388a 100644 --- a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoCLR/mcuconf.h +++ b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoCLR/mcuconf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoCLR/mcuconf_nf.h b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoCLR/mcuconf_nf.h index 5ff03534b6..7c689dd279 100644 --- a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoCLR/mcuconf_nf.h +++ b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoCLR/mcuconf_nf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoCLR/nanoHAL.cpp b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoCLR/nanoHAL.cpp index 076a50fc68..a971e00292 100644 --- a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoCLR/nanoHAL.cpp +++ b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoCLR/nanoHAL.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoCLR/netduino3wifi_CLR-DEBUG.ld b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoCLR/netduino3wifi_CLR-DEBUG.ld index d2ef582b9e..987cb621ed 100644 --- a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoCLR/netduino3wifi_CLR-DEBUG.ld +++ b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoCLR/netduino3wifi_CLR-DEBUG.ld @@ -1,6 +1,6 @@ /* // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoCLR/netduino3wifi_CLR.ld b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoCLR/netduino3wifi_CLR.ld index 5a59730ec1..b0c4cb9381 100644 --- a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoCLR/netduino3wifi_CLR.ld +++ b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoCLR/netduino3wifi_CLR.ld @@ -1,6 +1,6 @@ /* // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoCLR/target_board.h.in b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoCLR/target_board.h.in index 6fb5861584..f5476e640a 100644 --- a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoCLR/target_board.h.in +++ b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoCLR/target_board.h.in @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_BlockStorage.c b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_BlockStorage.c index 9e7c7f5546..db45d1a411 100644 --- a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_BlockStorage.c +++ b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_BlockStorage.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_BlockStorage.h b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_BlockStorage.h index aa50b1b7f2..8a56d0eee0 100644 --- a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_BlockStorage.h +++ b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_BlockStorage.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_common.c b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_common.c index ccee7c5e03..9fc1974764 100644 --- a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_common.c +++ b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_common.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_common.h.in b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_common.h.in index 563fe883bf..b30be5c75c 100644 --- a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_common.h.in +++ b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_common.h.in @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_nf_devices_can_config.cpp b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_nf_devices_can_config.cpp index 7dbe7ff19a..c7d263b871 100644 --- a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_nf_devices_can_config.cpp +++ b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_nf_devices_can_config.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_nf_devices_can_config.h b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_nf_devices_can_config.h index adc8ace3b2..db3e146a08 100644 --- a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_nf_devices_can_config.h +++ b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_nf_devices_can_config.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_nf_devices_onewire_config.cpp b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_nf_devices_onewire_config.cpp index 89ad1d8352..774baf30e5 100644 --- a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_nf_devices_onewire_config.cpp +++ b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_nf_devices_onewire_config.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_nf_devices_onewire_config.h b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_nf_devices_onewire_config.h index d0fb1c8775..e54cfb0f9b 100644 --- a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_nf_devices_onewire_config.h +++ b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_nf_devices_onewire_config.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_system_devices_dac_config.cpp b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_system_devices_dac_config.cpp index 97181d6fec..35a61746cb 100644 --- a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_system_devices_dac_config.cpp +++ b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_system_devices_dac_config.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_windows_devices_adc_config.cpp b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_windows_devices_adc_config.cpp index 362011df7e..dfec1ae5c8 100644 --- a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_windows_devices_adc_config.cpp +++ b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_windows_devices_adc_config.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_windows_devices_i2c_config.cpp b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_windows_devices_i2c_config.cpp index 18b1cd191d..45bb32f24e 100644 --- a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_windows_devices_i2c_config.cpp +++ b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_windows_devices_i2c_config.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_windows_devices_serialcommunication_config.cpp b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_windows_devices_serialcommunication_config.cpp index 6f13e26cfb..615d655a68 100644 --- a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_windows_devices_serialcommunication_config.cpp +++ b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_windows_devices_serialcommunication_config.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_windows_devices_serialcommunication_config.h b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_windows_devices_serialcommunication_config.h index 07dc7c6f67..09515990b5 100644 --- a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_windows_devices_serialcommunication_config.h +++ b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_windows_devices_serialcommunication_config.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_windows_devices_spi_config.cpp b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_windows_devices_spi_config.cpp index 551c590139..4fff795dfa 100644 --- a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_windows_devices_spi_config.cpp +++ b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_windows_devices_spi_config.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_windows_storage_config.h b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_windows_storage_config.h index 8601cffd16..a9a27a7454 100644 --- a/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_windows_storage_config.h +++ b/targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_windows_storage_config.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/CMakeLists.txt b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/CMakeLists.txt index 94c75c5aa7..e8bbdc52e5 100644 --- a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/CMakeLists.txt +++ b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # @@ -18,7 +18,7 @@ set(NANOBOOTER_PROJECT_NAME "nanoBooter") set(NANOCLR_PROJECT_NAME "nanoCLR") find_package(BuildUtils REQUIRED) -find_package(CHIBIOS REQUIRED) +find_package(ChibiOS REQUIRED) find_package(ChibiOSnfOverlay REQUIRED) find_package(WireProtocol REQUIRED) @@ -44,7 +44,7 @@ endif() # nF feature: networking if(USE_NETWORKING_OPTION) find_package(CHIBIOS_LWIP REQUIRED) - find_package(NF_NETWORKING REQUIRED) + find_package(NF_Networking REQUIRED) endif() # nF feature: filesystem diff --git a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/cmake-variants.json b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/cmake-variants.json new file mode 100644 index 0000000000..8850243b86 --- /dev/null +++ b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/cmake-variants.json @@ -0,0 +1,72 @@ +{ + "buildType": { + "default": "debug", + "choices": { + "debug": { + "short": "Debug", + "long": "Emit debug information without performing optimizations", + "buildType": "Debug" + }, + "minsize": { + "short": "MinSizeRel", + "long": "Optimize for smallest binary size", + "buildType": "MinSizeRel" + }, + "reldeb": { + "short": "RelWithDebInfo", + "long": "Perform optimizations AND include debugging information", + "buildType": "RelWithDebInfo" + } + } + }, + "linkage": { + "default": "", + "choices": { + "ORGPAL_PALTHREE": { + "short": "ORGPAL_PALTHREE", + "settings": { + "BUILD_VERSION": "0.9.99.999", + "CMAKE_TOOLCHAIN_FILE": "CMake/toolchain.arm-none-eabi.cmake", + "TOOLCHAIN_PREFIX": "", + "TOOL_HEX2DFU_PREFIX": "", + "RTOS": "CHIBIOS", + "TARGET_SERIES": "STM32F7xx", + "RTOS_SOURCE_FOLDER": "", + "CHIBIOS_BOARD": "ORGPAL_PALTHREE", + "CHIBIOS_CONTRIB_REQUIRED": "OFF", + "CHIBIOS_CONTRIB_SOURCE": "", + "STM32_CUBE_PACKAGE_REQUIRED": "ON", + "STM32_CUBE_PACKAGE_SOURCE": "", + "MBEDTLS_SOURCE": "", + "FATFS_SOURCE": "", + "SUPPORT_ANY_BASE_CONVERSION": "ON", + "NF_FEATURE_DEBUGGER": "ON", + "NF_FEATURE_RTC": "ON", + "NF_FEATURE_HAS_SDCARD": "ON", + "NF_FEATURE_HAS_CONFIG_BLOCK": "ON", + "NF_FEATURE_HAS_USB_MSD": "ON", + "NF_FEATURE_USE_SPIFFS": "ON", + "NF_SECURITY_MBEDTLS": "ON", + "SWO_OUTPUT": "OFF", + "NF_BUILD_RTM": "OFF", + "API_System.Math": "ON", + "API_Hardware.Stm32": "ON", + "API_Windows.Devices.Gpio": "ON", + "API_Windows.Devices.Spi": "ON", + "API_Windows.Devices.I2c": "ON", + "API_Windows.Devices.Pwm": "ON", + "API_Windows.Devices.SerialCommunication": "ON", + "API_Windows.Devices.Adc": "ON", + "API_Windows.Device.Dac": "ON", + "API_System.Net": "ON", + "API_nanoFramework.Devices.OneWire": "ON", + "API_nanoFramework.Devices.Can": "ON", + "API_Windows.Storage": "ON", + "API_nanoFramework.ResourceManager": "ON", + "API_nanoFramework.System.Collections": "ON", + "API_nanoFramework.System.Text": "ON" + } + } + } + } +} diff --git a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/common/CMakeLists.txt b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/common/CMakeLists.txt index c4291c25da..d04aefc632 100644 --- a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/common/CMakeLists.txt +++ b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/common/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/common/Device_BlockStorage-DEBUG.c b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/common/Device_BlockStorage-DEBUG.c index 3695ffd06f..0ff4f316ec 100644 --- a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/common/Device_BlockStorage-DEBUG.c +++ b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/common/Device_BlockStorage-DEBUG.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/common/Device_BlockStorage.c b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/common/Device_BlockStorage.c index f44b3c293e..1cd903ee4e 100644 --- a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/common/Device_BlockStorage.c +++ b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/common/Device_BlockStorage.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/common/targetHAL_ConfigurationManager.cpp b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/common/targetHAL_ConfigurationManager.cpp index 178f6aa783..0bdb275fd8 100644 --- a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/common/targetHAL_ConfigurationManager.cpp +++ b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/common/targetHAL_ConfigurationManager.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/common/usbcfg.c b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/common/usbcfg.c index 4d384f05bc..66f7eedfa8 100644 --- a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/common/usbcfg.c +++ b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/common/usbcfg.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/common/usbcfg.h b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/common/usbcfg.h index 72960028c4..a41d20143e 100644 --- a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/common/usbcfg.h +++ b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/common/usbcfg.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/launch.json b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/launch.json new file mode 100644 index 0000000000..880532cf4a --- /dev/null +++ b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/launch.json @@ -0,0 +1,109 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "ORGPAL_PALTHREE nanoBooter", + "type": "cppdbg", + "request": "launch", + "miDebuggerPath": "/bin/arm-none-eabi-gdb.exe", + "targetArchitecture": "ARM", + "program": "${workspaceRoot}/build/nanoBooter.elf", + "setupCommands": [ + { + "text": "target extended-remote localhost:3333" + }, + { + "text": "monitor reset_config none separate" + }, + { + "text": "monitor reset halt" + }, + { + "text": "monitor flash write_image erase \"/build/nanoBooter.hex\" " + }, + { + "text": "file /build/nanoBooter.elf" + }, + { + "text": "set output-radix 16", + "description": "set the default numeric base to 16", + "ignoreFailures": false + } + ], + "customLaunchSetupCommands": [ + { + "text": "monitor reset_config none separate" + }, + { + "text": "monitor reset halt" + } + ], + "logging": { + "moduleLoad": false, + "trace": false, + "engineLogging": false, + "programOutput": true, + "exceptions": true + }, + "launchCompleteCommand": "exec-continue", + "debugServerPath": "/bin/openocd.exe", + "debugServerArgs": "-s \"/scripts/\" -f board/stm32f7discovery.cfg", + "serverStarted": "Info\\ :\\ [\\w\\d\\.]*:\\ hardware", + "filterStderr": true, + "externalConsole": true, + "cwd": "${cwd}" + }, + { + "name": "ORGPAL_PALTHREE nanoCLR", + "type": "cppdbg", + "request": "launch", + "miDebuggerPath": "/bin/arm-none-eabi-gdb.exe", + "targetArchitecture": "ARM", + "program": "${workspaceRoot}/build/nanoCLR.elf", + "setupCommands": [ + { + "text": "target extended-remote localhost:3333" + }, + { + "text": "monitor reset_config none separate" + }, + { + "text": "monitor reset halt" + }, + { + "text": "monitor flash write_image erase \"/build/nanoCLR.hex\" " + }, + { + "text": "file /build/nanoCLR.elf" + }, + { + "text": "set output-radix 16", + "description": "set the default numeric base to 16", + "ignoreFailures": false + } + ], + "customLaunchSetupCommands": [ + { + "text": "monitor reset_config none separate" + }, + { + "text": "monitor reset halt" + } + ], + "logging": { + "moduleLoad": false, + "trace": false, + "engineLogging": false, + "programOutput": true, + "exceptions": true + }, + "launchCompleteCommand": "exec-continue", + "debugServerPath": "/bin/openocd.exe", + "debugServerArgs": "-s \"/scripts/\" -f board/stm32f7discovery.cfg", + "serverStarted": "Info\\ :\\ [\\w\\d\\.]*:\\ hardware", + "filterStderr": true, + "externalConsole": true, + "cwd": "${cwd}" + } + ] +} \ No newline at end of file diff --git a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/managed_helpers/ORGPAL_PALTHREE.Adc.cs b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/managed_helpers/ORGPAL_PALTHREE.Adc.cs index d48848f9ce..2e194763aa 100644 --- a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/managed_helpers/ORGPAL_PALTHREE.Adc.cs +++ b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/managed_helpers/ORGPAL_PALTHREE.Adc.cs @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/managed_helpers/package.nuspec b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/managed_helpers/package.nuspec index 9e0fba70da..a0ce92d235 100644 --- a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/managed_helpers/package.nuspec +++ b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/managed_helpers/package.nuspec @@ -18,7 +18,7 @@ https://github.com/nanoframework https://secure.gravatar.com/avatar/97d0e092247f0716db6d4b47b7d1d1ad https://github.com/nanoframework/nf-interpreter/blob/develop/LICENSE.md - Copyright (c) 2019 The nanoFramework project contributors + Copyright (c) .NET Foundation and Contributors nanoFramework, nano Framework, NETNF, NETMF, Micro Framework, STM32, .net, STM32F769I diff --git a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/mbedtls_config.h b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/mbedtls_config.h index 9877ca778c..8e6da134b1 100644 --- a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/mbedtls_config.h +++ b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/mbedtls_config.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006-2015, ARM Limited, All Rights Reserved // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoBooter/CMakeLists.txt b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoBooter/CMakeLists.txt index f0e921f750..73b5927c6b 100644 --- a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoBooter/CMakeLists.txt +++ b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoBooter/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoBooter/STM32F76xx_booter-DEBUG.ld b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoBooter/STM32F76xx_booter-DEBUG.ld index 0637fbd71e..ed45588cf4 100644 --- a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoBooter/STM32F76xx_booter-DEBUG.ld +++ b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoBooter/STM32F76xx_booter-DEBUG.ld @@ -1,6 +1,6 @@ /* // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoBooter/STM32F76xx_booter.ld b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoBooter/STM32F76xx_booter.ld index 0637fbd71e..ed45588cf4 100644 --- a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoBooter/STM32F76xx_booter.ld +++ b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoBooter/STM32F76xx_booter.ld @@ -1,6 +1,6 @@ /* // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoBooter/chconf.h b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoBooter/chconf.h index 63ff829392..c84a62641b 100644 --- a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoBooter/chconf.h +++ b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoBooter/chconf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoBooter/halconf.h b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoBooter/halconf.h index 211bf5d100..a323b29f0c 100644 --- a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoBooter/halconf.h +++ b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoBooter/halconf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoBooter/halconf_nf.h b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoBooter/halconf_nf.h index b7b11c4ba1..b4df1a7406 100644 --- a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoBooter/halconf_nf.h +++ b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoBooter/halconf_nf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoBooter/main.c b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoBooter/main.c index 1a9a4d8ecc..207485c544 100644 --- a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoBooter/main.c +++ b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoBooter/main.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoBooter/mcuconf.h b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoBooter/mcuconf.h index 9b43c5001d..1a3986e948 100644 --- a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoBooter/mcuconf.h +++ b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoBooter/mcuconf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoBooter/mcuconf_nf.h b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoBooter/mcuconf_nf.h index 5ff03534b6..7c689dd279 100644 --- a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoBooter/mcuconf_nf.h +++ b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoBooter/mcuconf_nf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoBooter/target_board.h.in b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoBooter/target_board.h.in index 19531d9c5d..425437e722 100644 --- a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoBooter/target_board.h.in +++ b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoBooter/target_board.h.in @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoCLR/CMakeLists.txt b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoCLR/CMakeLists.txt index e5496b7ea0..f5fab75926 100644 --- a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoCLR/CMakeLists.txt +++ b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoCLR/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoCLR/STM32F76xx_CLR-DEBUG.ld b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoCLR/STM32F76xx_CLR-DEBUG.ld index f99d66e720..d937cb201f 100644 --- a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoCLR/STM32F76xx_CLR-DEBUG.ld +++ b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoCLR/STM32F76xx_CLR-DEBUG.ld @@ -1,6 +1,6 @@ /* // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoCLR/STM32F76xx_CLR.ld b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoCLR/STM32F76xx_CLR.ld index f99d66e720..d937cb201f 100644 --- a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoCLR/STM32F76xx_CLR.ld +++ b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoCLR/STM32F76xx_CLR.ld @@ -1,6 +1,6 @@ /* // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoCLR/chconf.h b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoCLR/chconf.h index 390ce3a688..628a650c57 100644 --- a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoCLR/chconf.h +++ b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoCLR/chconf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoCLR/halconf.h b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoCLR/halconf.h index 7933aa7d2b..ea6e72bfdb 100644 --- a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoCLR/halconf.h +++ b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoCLR/halconf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoCLR/halconf_community.h b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoCLR/halconf_community.h index de0e1ecd5e..c2df6cd3b6 100644 --- a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoCLR/halconf_community.h +++ b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoCLR/halconf_community.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Uladzimir Pylinsky aka barthess. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoCLR/halconf_nf.h b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoCLR/halconf_nf.h index 303c76b14d..53e1e18771 100644 --- a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoCLR/halconf_nf.h +++ b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoCLR/halconf_nf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoCLR/main.c b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoCLR/main.c index f22131fde2..074c05dc26 100644 --- a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoCLR/main.c +++ b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoCLR/main.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoCLR/mcuconf.h b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoCLR/mcuconf.h index 5ea56b7555..f98c395f46 100644 --- a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoCLR/mcuconf.h +++ b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoCLR/mcuconf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoCLR/mcuconf_community.h b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoCLR/mcuconf_community.h index a12c6b4487..9907be4cc6 100644 --- a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoCLR/mcuconf_community.h +++ b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoCLR/mcuconf_community.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Uladzimir Pylinsky aka barthess. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoCLR/mcuconf_nf.h b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoCLR/mcuconf_nf.h index 780a16cd4f..b66994331d 100644 --- a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoCLR/mcuconf_nf.h +++ b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoCLR/mcuconf_nf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoCLR/nanoHAL.cpp b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoCLR/nanoHAL.cpp index 076a50fc68..a971e00292 100644 --- a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoCLR/nanoHAL.cpp +++ b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoCLR/nanoHAL.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoCLR/target_board.h.in b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoCLR/target_board.h.in index b980bc05d7..d0b1050e8c 100644 --- a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoCLR/target_board.h.in +++ b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/nanoCLR/target_board.h.in @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/spiffs_config.h b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/spiffs_config.h index 628962532b..57e94e62b7 100644 --- a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/spiffs_config.h +++ b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/spiffs_config.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2013, petera, All Rights Reserved // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/stm32f7xx_hal_conf.h b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/stm32f7xx_hal_conf.h index 39efb87f4e..e8191e8d3f 100644 --- a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/stm32f7xx_hal_conf.h +++ b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/stm32f7xx_hal_conf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2016 STMicroelectronics. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_BlockStorage.c b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_BlockStorage.c index 9e7c7f5546..db45d1a411 100644 --- a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_BlockStorage.c +++ b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_BlockStorage.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_BlockStorage.h b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_BlockStorage.h index aa50b1b7f2..8a56d0eee0 100644 --- a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_BlockStorage.h +++ b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_BlockStorage.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_common.c b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_common.c index 7c293b8641..d9a7475233 100644 --- a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_common.c +++ b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_common.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_common.h.in b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_common.h.in index 3d71f89076..f0365eae96 100644 --- a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_common.h.in +++ b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_common.h.in @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // @@ -12,6 +12,8 @@ #define _TARGET_COMMON_H_ #include +#include +#include ///////////////////////////////////////////////////////////////////////////////////////// // The following addresses and sizes should be filled in according to the SoC data-sheet diff --git a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_external_memory.c b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_external_memory.c index 61e2bfae73..2b59a581c9 100644 --- a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_external_memory.c +++ b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_external_memory.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_lwip_sntp_opts.h b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_lwip_sntp_opts.h index f286fde99c..99c463e11b 100644 --- a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_lwip_sntp_opts.h +++ b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_lwip_sntp_opts.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_lwipopts.h b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_lwipopts.h new file mode 100644 index 0000000000..ca1a0b4465 --- /dev/null +++ b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_lwipopts.h @@ -0,0 +1,8 @@ +// +// Copyright (c) .NET Foundation and Contributors +// See LICENSE file in the project root for full license information. +// + +///////////////////////////////////////////////////////////////////////////////////////// +// THIS FILE IS BLANK ON PURPOSE BECAUSE THIS TARGET DOESN'T OVERRIDE ANY lwIP OPTIONS // +///////////////////////////////////////////////////////////////////////////////////////// diff --git a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_nf_devices_onewire_config.c b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_nf_devices_onewire_config.c index deae010fb4..df20bf5f78 100644 --- a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_nf_devices_onewire_config.c +++ b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_nf_devices_onewire_config.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_nf_devices_onewire_config.h b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_nf_devices_onewire_config.h index 41c091f8d8..17986f1e5b 100644 --- a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_nf_devices_onewire_config.h +++ b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_nf_devices_onewire_config.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_spiffs.c b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_spiffs.c index 8357ee2b03..1cf7ddfa19 100644 --- a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_spiffs.c +++ b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_spiffs.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2016 STMicroelectronics. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_spiffs.h b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_spiffs.h index 8e67862260..c1ebb7f04e 100644 --- a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_spiffs.h +++ b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_spiffs.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_system_devices_dac_config.cpp b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_system_device_dac_config.cpp similarity index 71% rename from targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_system_devices_dac_config.cpp rename to targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_system_device_dac_config.cpp index 049422f78a..948967e054 100644 --- a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_system_devices_dac_config.cpp +++ b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_system_device_dac_config.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // @@ -7,7 +7,7 @@ const NF_PAL_DAC_PORT_PIN_CHANNEL DacPortPinConfig[] = { - // DAC1, channel 1, GPIO port A, pin 4 + // DAC1, channel 1, GPIO port A, pin 4 {1, 1, GPIOA, 4}, }; diff --git a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_windows_devices_adc_config.cpp b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_windows_devices_adc_config.cpp index 12159ff0b9..938b99029d 100644 --- a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_windows_devices_adc_config.cpp +++ b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_windows_devices_adc_config.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_windows_devices_i2c_config.cpp b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_windows_devices_i2c_config.cpp index b6d034a3be..befabebcf0 100644 --- a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_windows_devices_i2c_config.cpp +++ b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_windows_devices_i2c_config.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_windows_devices_serialcommunication_config.cpp b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_windows_devices_serialcommunication_config.cpp index ff0a4cd3bc..d80feab71d 100644 --- a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_windows_devices_serialcommunication_config.cpp +++ b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_windows_devices_serialcommunication_config.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_windows_devices_serialcommunication_config.h b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_windows_devices_serialcommunication_config.h index 3f63a06288..94a56a7ccc 100644 --- a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_windows_devices_serialcommunication_config.h +++ b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_windows_devices_serialcommunication_config.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_windows_devices_spi_config.cpp b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_windows_devices_spi_config.cpp index 8d30336b78..0e94cfaacc 100644 --- a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_windows_devices_spi_config.cpp +++ b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_windows_devices_spi_config.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_windows_storage_config.h b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_windows_storage_config.h index ac414807ef..1b3a66e5a3 100644 --- a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_windows_storage_config.h +++ b/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/target_windows_storage_config.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/CMakeLists.txt b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/CMakeLists.txt index 7d9ca8c1fc..c5d5f77936 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/CMakeLists.txt +++ b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # @@ -17,7 +17,7 @@ set(NANOBOOTER_PROJECT_NAME "nanoBooter") set(NANOCLR_PROJECT_NAME "nanoCLR") find_package(BuildUtils REQUIRED) -find_package(CHIBIOS REQUIRED) +find_package(ChibiOS REQUIRED) find_package(ChibiOSnfOverlay REQUIRED) find_package(WireProtocol REQUIRED) diff --git a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/cmake-variants.json b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/cmake-variants.json new file mode 100644 index 0000000000..6b887e165d --- /dev/null +++ b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/cmake-variants.json @@ -0,0 +1,56 @@ +{ + "buildType": { + "default": "debug", + "choices": { + "debug": { + "short": "Debug", + "long": "Emit debug information without performing optimizations", + "buildType": "Debug" + }, + "minsize": { + "short": "MinSizeRel", + "long": "Optimize for smallest binary size", + "buildType": "MinSizeRel" + }, + "reldeb": { + "short": "RelWithDebInfo", + "long": "Perform optimizations AND include debugging information", + "buildType": "RelWithDebInfo" + } + } + }, + "linkage": { + "default": "", + "choices": { + "ST_NUCLEO64_F091RC": { + "short": "ST_NUCLEO64_F091RC", + "settings": { + "BUILD_VERSION": "0.9.99.999", + "CMAKE_TOOLCHAIN_FILE": "CMake/toolchain.arm-none-eabi.cmake", + "TOOLCHAIN_PREFIX": "", + "TOOL_HEX2DFU_PREFIX": "", + "TARGET_SERIES": "STM32F0xx", + "RTOS": "CHIBIOS", + "RTOS_SOURCE_FOLDER": "", + "CHIBIOS_BOARD": "ST_NUCLEO64_F091RC", + "CHIBIOS_CONTRIB_REQUIRED": "OFF", + "CHIBIOS_CONTRIB_SOURCE": "", + "STM32_CUBE_PACKAGE_REQUIRED": "OFF", + "STM32_CUBE_PACKAGE_SOURCE": "", + "NF_FEATURE_DEBUGGER": "ON", + "NF_FEATURE_RTC": "ON", + "NF_PLATFORM_NO_CLR_TRACE": "ON", + "NF_CLR_NO_IL_INLINE": "ON", + "USE_RNG": "OFF", + "NF_BUILD_RTM": "OFF", + "API_Hardware.Stm32": "ON", + "API_Windows.Devices.Gpio": "ON", + "API_Windows.Devices.Spi": "ON", + "API_Windows.Devices.I2c": "ON", + "API_Windows.Devices.Pwm": "ON", + "API_Windows.Devices.SerialCommunication": "ON" + } + } + } + } +} \ No newline at end of file diff --git a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/common/CMakeLists.txt b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/common/CMakeLists.txt index 777d4ec387..5c3313ad49 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/common/CMakeLists.txt +++ b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/common/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/common/Device_BlockStorage-DEBUG.c b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/common/Device_BlockStorage-DEBUG.c index cbeb7bf039..8eef51f687 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/common/Device_BlockStorage-DEBUG.c +++ b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/common/Device_BlockStorage-DEBUG.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/common/Device_BlockStorage.c b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/common/Device_BlockStorage.c index ecd9b529cb..addba4ab97 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/common/Device_BlockStorage.c +++ b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/common/Device_BlockStorage.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/common/serialcfg.h b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/common/serialcfg.h index a9e1b9b5ad..879537da84 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/common/serialcfg.h +++ b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/common/serialcfg.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/launch.json b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/launch.json new file mode 100644 index 0000000000..2dea792394 --- /dev/null +++ b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/launch.json @@ -0,0 +1,115 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "ST_NUCLEO64_F091RC nanoBooter", + "type": "cppdbg", + "request": "launch", + "miDebuggerPath": "/bin/arm-none-eabi-gdb.exe", + "targetArchitecture": "ARM", + "program": "${workspaceRoot}/build/nanoBooter.elf", + "setupCommands": [ + { + "text": "target extended-remote localhost:3333" + }, + { + "text": "monitor reset_config none separate" + }, + { + "text": "monitor reset halt" + }, + { + "text": "monitor flash write_image erase \"/build/nanoBooter.hex\" " + }, + { + "text": "file /build/nanoBooter.elf" + }, + { + "text": "monitor reset halt" + }, + { + "text": "set output-radix 16", + "description": "set the default numeric base to 16", + "ignoreFailures": false + } + ], + "customLaunchSetupCommands": [ + { + "text": "monitor reset_config none separate" + }, + { + "text": "monitor reset halt" + } + ], + "logging": { + "moduleLoad": false, + "trace": false, + "engineLogging": false, + "programOutput": true, + "exceptions": true + }, + "launchCompleteCommand": "exec-continue", + "debugServerPath": "/bin/openocd.exe", + "debugServerArgs": "-s \"/scripts/\" -f board/st_nucleo_f0.cfg", + "serverStarted": "Info\\ :\\ [\\w\\d\\.]*:\\ hardware", + "filterStderr": true, + "externalConsole": true, + "cwd": "${cwd}" + }, + { + "name": "ST_NUCLEO64_F091RC nanoCLR", + "type": "cppdbg", + "request": "launch", + "miDebuggerPath": "/bin/arm-none-eabi-gdb.exe", + "targetArchitecture": "ARM", + "program": "${workspaceRoot}/build/nanoCLR.elf", + "setupCommands": [ + { + "text": "target extended-remote localhost:3333" + }, + { + "text": "monitor reset_config none separate" + }, + { + "text": "monitor reset halt" + }, + { + "text": "monitor flash write_image erase \"/build/nanoCLR.hex\" " + }, + { + "text": "file /build/nanoCLR.elf" + }, + { + "text": "monitor reset halt" + }, + { + "text": "set output-radix 16", + "description": "set the default numeric base to 16", + "ignoreFailures": false + } + ], + "customLaunchSetupCommands": [ + { + "text": "monitor reset_config none separate" + }, + { + "text": "monitor reset halt" + } + ], + "logging": { + "moduleLoad": false, + "trace": false, + "engineLogging": false, + "programOutput": true, + "exceptions": true + }, + "launchCompleteCommand": "exec-continue", + "debugServerPath": "/bin/openocd.exe", + "debugServerArgs": "-s \"/scripts/\" -f board/st_nucleo_f0.cfg", + "serverStarted": "Info\\ :\\ [\\w\\d\\.]*:\\ hardware", + "filterStderr": true, + "externalConsole": true, + "cwd": "${cwd}" + } + ] +} diff --git a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoBooter/CMakeLists.txt b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoBooter/CMakeLists.txt index 291f47e121..09b9337e00 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoBooter/CMakeLists.txt +++ b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoBooter/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoBooter/STM32F091xC_booter-DEBUG.ld b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoBooter/STM32F091xC_booter-DEBUG.ld index 527cb2463b..9ad027bd71 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoBooter/STM32F091xC_booter-DEBUG.ld +++ b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoBooter/STM32F091xC_booter-DEBUG.ld @@ -1,6 +1,6 @@ /* // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoBooter/STM32F091xC_booter.ld b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoBooter/STM32F091xC_booter.ld index 94753e9d1d..fb4d33e1d6 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoBooter/STM32F091xC_booter.ld +++ b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoBooter/STM32F091xC_booter.ld @@ -1,6 +1,6 @@ /* // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoBooter/chconf.h b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoBooter/chconf.h index e6e3fc7134..a19792bfb3 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoBooter/chconf.h +++ b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoBooter/chconf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoBooter/halconf.h b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoBooter/halconf.h index f0824d670b..c9efc039e9 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoBooter/halconf.h +++ b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoBooter/halconf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoBooter/halconf_nf.h b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoBooter/halconf_nf.h index 81cfcee6fc..4ddadac787 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoBooter/halconf_nf.h +++ b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoBooter/halconf_nf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoBooter/main.c b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoBooter/main.c index 3c37cb0fd9..3189da448d 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoBooter/main.c +++ b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoBooter/main.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoBooter/mcuconf.h b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoBooter/mcuconf.h index 08bc4e0213..eabd133b26 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoBooter/mcuconf.h +++ b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoBooter/mcuconf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoBooter/mcuconf_nf.h b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoBooter/mcuconf_nf.h index 574b9636f7..f05caa0b4d 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoBooter/mcuconf_nf.h +++ b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoBooter/mcuconf_nf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoBooter/target_board.h.in b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoBooter/target_board.h.in index 750beb565c..ad151ebd73 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoBooter/target_board.h.in +++ b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoBooter/target_board.h.in @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoCLR/CMakeLists.txt b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoCLR/CMakeLists.txt index e5496b7ea0..f5fab75926 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoCLR/CMakeLists.txt +++ b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoCLR/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoCLR/STM32F091xC_CLR-DEBUG.ld b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoCLR/STM32F091xC_CLR-DEBUG.ld index 4bc731d495..fab32971ab 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoCLR/STM32F091xC_CLR-DEBUG.ld +++ b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoCLR/STM32F091xC_CLR-DEBUG.ld @@ -1,6 +1,6 @@ /* // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoCLR/STM32F091xC_CLR.ld b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoCLR/STM32F091xC_CLR.ld index d622e1555a..80bceb3ac2 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoCLR/STM32F091xC_CLR.ld +++ b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoCLR/STM32F091xC_CLR.ld @@ -1,6 +1,6 @@ /* // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoCLR/chconf.h b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoCLR/chconf.h index 83434f3694..47c37b4583 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoCLR/chconf.h +++ b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoCLR/chconf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoCLR/halconf.h b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoCLR/halconf.h index a99b33ac22..655c20380b 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoCLR/halconf.h +++ b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoCLR/halconf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoCLR/halconf_nf.h b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoCLR/halconf_nf.h index 81cfcee6fc..4ddadac787 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoCLR/halconf_nf.h +++ b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoCLR/halconf_nf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoCLR/main.c b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoCLR/main.c index 6d2d06b024..9e3d5f0e78 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoCLR/main.c +++ b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoCLR/main.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoCLR/mcuconf.h b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoCLR/mcuconf.h index d023f997c0..75f393dda2 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoCLR/mcuconf.h +++ b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoCLR/mcuconf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoCLR/mcuconf_nf.h b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoCLR/mcuconf_nf.h index 574b9636f7..f05caa0b4d 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoCLR/mcuconf_nf.h +++ b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoCLR/mcuconf_nf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoCLR/nanoHAL.cpp b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoCLR/nanoHAL.cpp index 076a50fc68..a971e00292 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoCLR/nanoHAL.cpp +++ b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoCLR/nanoHAL.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoCLR/target_board.h.in b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoCLR/target_board.h.in index 6fb5861584..f5476e640a 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoCLR/target_board.h.in +++ b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoCLR/target_board.h.in @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/target_BlockStorage.c b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/target_BlockStorage.c index 9e7c7f5546..db45d1a411 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/target_BlockStorage.c +++ b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/target_BlockStorage.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/target_BlockStorage.h b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/target_BlockStorage.h index aa50b1b7f2..8a56d0eee0 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/target_BlockStorage.h +++ b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/target_BlockStorage.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/target_common.c b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/target_common.c index c633da5b38..ed6a5179e9 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/target_common.c +++ b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/target_common.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/target_common.h.in b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/target_common.h.in index e629d90b8e..ea5dd511e9 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/target_common.h.in +++ b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/target_common.h.in @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/target_system_devices_dac_config.cpp b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/target_system_devices_dac_config.cpp index 049422f78a..eee3e0fa6e 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/target_system_devices_dac_config.cpp +++ b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/target_system_devices_dac_config.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/target_windows_devices_i2c_config.cpp b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/target_windows_devices_i2c_config.cpp index 2618ec3e97..8cfcf1edd6 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/target_windows_devices_i2c_config.cpp +++ b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/target_windows_devices_i2c_config.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/target_windows_devices_serialcommunication_config.cpp b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/target_windows_devices_serialcommunication_config.cpp index 673d3b7e0d..5614860d48 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/target_windows_devices_serialcommunication_config.cpp +++ b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/target_windows_devices_serialcommunication_config.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/target_windows_devices_serialcommunication_config.h b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/target_windows_devices_serialcommunication_config.h index 6def329eca..5f55ef6d8a 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/target_windows_devices_serialcommunication_config.h +++ b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/target_windows_devices_serialcommunication_config.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/target_windows_devices_spi_config.cpp b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/target_windows_devices_spi_config.cpp index e53e80ac83..8215e98b46 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/target_windows_devices_spi_config.cpp +++ b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/target_windows_devices_spi_config.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/CMakeLists.txt b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/CMakeLists.txt index 8117063c51..b9e614972b 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/CMakeLists.txt +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # @@ -17,7 +17,7 @@ set(NANOBOOTER_PROJECT_NAME "nanoBooter") set(NANOCLR_PROJECT_NAME "nanoCLR") find_package(BuildUtils REQUIRED) -find_package(CHIBIOS REQUIRED) +find_package(ChibiOS REQUIRED) find_package(ChibiOSnfOverlay REQUIRED) find_package(WireProtocol REQUIRED) diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/cmake-variants.json b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/cmake-variants.json new file mode 100644 index 0000000000..a164d85406 --- /dev/null +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/cmake-variants.json @@ -0,0 +1,62 @@ +{ + "buildType": { + "default": "debug", + "choices": { + "debug": { + "short": "Debug", + "long": "Emit debug information without performing optimizations", + "buildType": "Debug" + }, + "minsize": { + "short": "MinSizeRel", + "long": "Optimize for smallest binary size", + "buildType": "MinSizeRel" + }, + "reldeb": { + "short": "RelWithDebInfo", + "long": "Perform optimizations AND include debugging information", + "buildType": "RelWithDebInfo" + } + } + }, + "linkage": { + "default": "", + "choices": { + "ST_STM32F429I_DISCOVERY": { + "short": "ST_STM32F429I_DISCOVERY", + "settings": { + "BUILD_VERSION": "0.9.99.999", + "CMAKE_TOOLCHAIN_FILE" : "CMake/toolchain.arm-none-eabi.cmake", + "TOOLCHAIN_PREFIX": "", + "TOOL_HEX2DFU_PREFIX": "", + "RTOS": "CHIBIOS", + "TARGET_SERIES": "STM32F4xx", + "RTOS_SOURCE_FOLDER": "", + "CHIBIOS_BOARD": "ST_STM32F429I_DISCOVERY", + "CHIBIOS_CONTRIB_REQUIRED": "OFF", + "CHIBIOS_CONTRIB_SOURCE": "", + "STM32_CUBE_PACKAGE_REQUIRED": "OFF", + "STM32_CUBE_PACKAGE_SOURCE": "", + "SUPPORT_ANY_BASE_CONVERSION": "ON", + "NF_FEATURE_DEBUGGER": "ON", + "NF_FEATURE_RTC": "ON", + "SWO_OUTPUT": "OFF", + "NF_BUILD_RTM": "OFF", + "API_System.Math": "ON", + "API_Hardware.Stm32": "ON", + "API_Windows.Devices.Gpio": "ON", + "API_Windows.Devices.Spi": "ON", + "API_Windows.Devices.I2c": "ON", + "API_Windows.Devices.Pwm": "ON", + "API_Windows.Devices.SerialCommunication": "ON", + "API_Windows.Devices.Adc": "ON", + "API_nanoFramework.Devices.OneWire": "ON", + "API_nanoFramework.Devices.Can": "ON", + "API_nanoFramework.ResourceManager": "ON", + "API_nanoFramework.System.Collections": "ON", + "API_nanoFramework.System.Text": "ON" + } + } + } + } +} \ No newline at end of file diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/common/CMakeLists.txt b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/common/CMakeLists.txt index aa7f1d543b..e363bd4e5f 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/common/CMakeLists.txt +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/common/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/common/Device_BlockStorage-DEBUG.c b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/common/Device_BlockStorage-DEBUG.c index 66a8d940f0..10d2cbb634 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/common/Device_BlockStorage-DEBUG.c +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/common/Device_BlockStorage-DEBUG.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/common/Device_BlockStorage.c b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/common/Device_BlockStorage.c index 7e34313ebb..ed8b0fc034 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/common/Device_BlockStorage.c +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/common/Device_BlockStorage.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/common/usbcfg.c b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/common/usbcfg.c index 217a411e7f..d1391fe967 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/common/usbcfg.c +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/common/usbcfg.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/common/usbcfg.h b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/common/usbcfg.h index 167e1df889..47d4546acb 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/common/usbcfg.h +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/common/usbcfg.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/launch.json b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/launch.json new file mode 100644 index 0000000000..7e88f202b6 --- /dev/null +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/launch.json @@ -0,0 +1,115 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "ST_STM32F429I_DISCOVERY nanoBooter", + "type": "cppdbg", + "request": "launch", + "miDebuggerPath": "/bin/arm-none-eabi-gdb.exe", + "targetArchitecture": "ARM", + "program": "${workspaceRoot}/build/nanoBooter.elf", + "setupCommands": [ + { + "text": "target extended-remote localhost:3333" + }, + { + "text": "monitor reset_config none separate" + }, + { + "text": "monitor reset halt" + }, + { + "text": "monitor flash write_image erase \"/build/nanoBooter.hex\" " + }, + { + "text": "file /build/nanoBooter.elf" + }, + { + "text": "monitor reset halt" + }, + { + "text": "set output-radix 16", + "description": "set the default numeric base to 16", + "ignoreFailures": false + } + ], + "customLaunchSetupCommands": [ + { + "text": "monitor reset_config none separate" + }, + { + "text": "monitor reset halt" + } + ], + "logging": { + "moduleLoad": false, + "trace": false, + "engineLogging": false, + "programOutput": true, + "exceptions": true + }, + "launchCompleteCommand": "exec-continue", + "debugServerPath": "/bin/openocd.exe", + "debugServerArgs": "-s \"/scripts/\" -f board/stm32429i_eval_stlink.cfg", + "serverStarted": "Info\\ :\\ [\\w\\d\\.]*:\\ hardware", + "filterStderr": true, + "externalConsole": true, + "cwd": "${cwd}" + }, + { + "name": "ST_STM32F429I_DISCOVERY nanoCLR", + "type": "cppdbg", + "request": "launch", + "miDebuggerPath": "/bin/arm-none-eabi-gdb.exe", + "targetArchitecture": "ARM", + "program": "${workspaceRoot}/build/nanoCLR.elf", + "setupCommands": [ + { + "text": "target extended-remote localhost:3333" + }, + { + "text": "monitor reset_config none separate" + }, + { + "text": "monitor reset halt" + }, + { + "text": "monitor flash write_image erase \"/build/nanoCLR.hex\" " + }, + { + "text": "file /build/nanoCLR.elf" + }, + { + "text": "monitor reset halt" + }, + { + "text": "set output-radix 16", + "description": "set the default numeric base to 16", + "ignoreFailures": false + } + ], + "customLaunchSetupCommands": [ + { + "text": "monitor reset_config none separate" + }, + { + "text": "monitor reset halt" + } + ], + "logging": { + "moduleLoad": false, + "trace": false, + "engineLogging": false, + "programOutput": true, + "exceptions": true + }, + "launchCompleteCommand": "exec-continue", + "debugServerPath": "/bin/openocd.exe", + "debugServerArgs": "-s \"/scripts/\" -f board/stm32429i_eval_stlink.cfg", + "serverStarted": "Info\\ :\\ [\\w\\d\\.]*:\\ hardware", + "filterStderr": true, + "externalConsole": true, + "cwd": "${cwd}" + } + ] +} diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/managed_helpers/STM32F429I_DISCOVERY.Adc.cs b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/managed_helpers/STM32F429I_DISCOVERY.Adc.cs index 78d7cb980c..2d250f09e6 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/managed_helpers/STM32F429I_DISCOVERY.Adc.cs +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/managed_helpers/STM32F429I_DISCOVERY.Adc.cs @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/managed_helpers/package.nuspec b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/managed_helpers/package.nuspec index 2bec83244c..2885111407 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/managed_helpers/package.nuspec +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/managed_helpers/package.nuspec @@ -18,7 +18,7 @@ https://github.com/nanoframework https://secure.gravatar.com/avatar/97d0e092247f0716db6d4b47b7d1d1ad https://github.com/nanoframework/nf-interpreter/blob/develop/LICENSE.md - Copyright (c) 2019 The nanoFramework project contributors + Copyright (c) .NET Foundation and Contributors nanoFramework, nano Framework, NETNF, NETMF, Micro Framework, STM32, .net, STM32F429I diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoBooter/CMakeLists.txt b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoBooter/CMakeLists.txt index 291f47e121..09b9337e00 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoBooter/CMakeLists.txt +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoBooter/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoBooter/STM32F429xI_booter-DEBUG.ld b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoBooter/STM32F429xI_booter-DEBUG.ld index c0e7244504..f4ef29c58a 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoBooter/STM32F429xI_booter-DEBUG.ld +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoBooter/STM32F429xI_booter-DEBUG.ld @@ -1,6 +1,6 @@ /* // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoBooter/STM32F429xI_booter.ld b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoBooter/STM32F429xI_booter.ld index 306edee749..33ae9b1343 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoBooter/STM32F429xI_booter.ld +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoBooter/STM32F429xI_booter.ld @@ -1,6 +1,6 @@ /* // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoBooter/chconf.h b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoBooter/chconf.h index ef98a91450..53aac2c4bd 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoBooter/chconf.h +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoBooter/chconf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoBooter/halconf.h b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoBooter/halconf.h index 13104b34d5..b3e588f33d 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoBooter/halconf.h +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoBooter/halconf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoBooter/halconf_nf.h b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoBooter/halconf_nf.h index ac3bc93126..83ae9e61dc 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoBooter/halconf_nf.h +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoBooter/halconf_nf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoBooter/main.c b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoBooter/main.c index 98d2885981..57f1a161ee 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoBooter/main.c +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoBooter/main.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoBooter/mcuconf.h b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoBooter/mcuconf.h index 10f82577a7..bf956ff24d 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoBooter/mcuconf.h +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoBooter/mcuconf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoBooter/mcuconf_nf.h b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoBooter/mcuconf_nf.h index 5ff03534b6..7c689dd279 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoBooter/mcuconf_nf.h +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoBooter/mcuconf_nf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoBooter/target_board.h.in b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoBooter/target_board.h.in index 750beb565c..ad151ebd73 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoBooter/target_board.h.in +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoBooter/target_board.h.in @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoCLR/CMakeLists.txt b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoCLR/CMakeLists.txt index e5496b7ea0..f5fab75926 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoCLR/CMakeLists.txt +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoCLR/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoCLR/STM32F429xI_CLR-DEBUG.ld b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoCLR/STM32F429xI_CLR-DEBUG.ld index bd27c82947..5546e6f323 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoCLR/STM32F429xI_CLR-DEBUG.ld +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoCLR/STM32F429xI_CLR-DEBUG.ld @@ -1,6 +1,6 @@ /* // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoCLR/STM32F429xI_CLR.ld b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoCLR/STM32F429xI_CLR.ld index 1c731acf15..6d25e969be 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoCLR/STM32F429xI_CLR.ld +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoCLR/STM32F429xI_CLR.ld @@ -1,6 +1,6 @@ /* // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoCLR/chconf.h b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoCLR/chconf.h index ef39575e47..a3c5d78718 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoCLR/chconf.h +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoCLR/chconf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoCLR/halconf.h b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoCLR/halconf.h index 554a9b96ed..9294082ca3 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoCLR/halconf.h +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoCLR/halconf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoCLR/halconf_nf.h b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoCLR/halconf_nf.h index ec812f88fe..647cdb8099 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoCLR/halconf_nf.h +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoCLR/halconf_nf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoCLR/main.c b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoCLR/main.c index cc5a2446b9..c81f961e1f 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoCLR/main.c +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoCLR/main.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoCLR/mcuconf.h b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoCLR/mcuconf.h index f8e9944e0e..b0c9454d75 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoCLR/mcuconf.h +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoCLR/mcuconf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoCLR/mcuconf_nf.h b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoCLR/mcuconf_nf.h index b34976b479..c7537d70f4 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoCLR/mcuconf_nf.h +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoCLR/mcuconf_nf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoCLR/nanoHAL.cpp b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoCLR/nanoHAL.cpp index 076a50fc68..a971e00292 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoCLR/nanoHAL.cpp +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoCLR/nanoHAL.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoCLR/target_board.h.in b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoCLR/target_board.h.in index 6fb5861584..f5476e640a 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoCLR/target_board.h.in +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoCLR/target_board.h.in @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_BlockStorage.c b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_BlockStorage.c index 9e7c7f5546..db45d1a411 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_BlockStorage.c +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_BlockStorage.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_BlockStorage.h b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_BlockStorage.h index aa50b1b7f2..8a56d0eee0 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_BlockStorage.h +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_BlockStorage.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_common.c b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_common.c index c633da5b38..ed6a5179e9 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_common.c +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_common.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_common.h.in b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_common.h.in index 8ca77162ea..c66222d90c 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_common.h.in +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_common.h.in @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_external_memory.c b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_external_memory.c index 61e2bfae73..2b59a581c9 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_external_memory.c +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_external_memory.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_nf_devices_can_config.cpp b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_nf_devices_can_config.cpp index 7dbe7ff19a..c7d263b871 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_nf_devices_can_config.cpp +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_nf_devices_can_config.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_nf_devices_can_config.h b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_nf_devices_can_config.h index adc8ace3b2..db3e146a08 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_nf_devices_can_config.h +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_nf_devices_can_config.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_nf_devices_onewire_config.cpp b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_nf_devices_onewire_config.cpp index 22cb4e030a..611dd64597 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_nf_devices_onewire_config.cpp +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_nf_devices_onewire_config.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_nf_devices_onewire_config.h b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_nf_devices_onewire_config.h index 56079a6582..9523fbed23 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_nf_devices_onewire_config.h +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_nf_devices_onewire_config.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_system_devices_dac_config.cpp b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_system_devices_dac_config.cpp index e3a0eee975..80a2765bec 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_system_devices_dac_config.cpp +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_system_devices_dac_config.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_windows_devices_adc_config.cpp b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_windows_devices_adc_config.cpp index 88d00fa8f8..7b371fd489 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_windows_devices_adc_config.cpp +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_windows_devices_adc_config.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_windows_devices_i2c_config.cpp b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_windows_devices_i2c_config.cpp index 2563aa28d8..c9a61dba9e 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_windows_devices_i2c_config.cpp +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_windows_devices_i2c_config.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_windows_devices_serialcommunication_config.cpp b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_windows_devices_serialcommunication_config.cpp index 6a9ad77f4c..6b5e0ae1f5 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_windows_devices_serialcommunication_config.cpp +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_windows_devices_serialcommunication_config.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_windows_devices_serialcommunication_config.h b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_windows_devices_serialcommunication_config.h index 66229d1279..a8db9ee41c 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_windows_devices_serialcommunication_config.h +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_windows_devices_serialcommunication_config.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_windows_devices_spi_config.cpp b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_windows_devices_spi_config.cpp index 67d4b401a0..ca5c6c1637 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_windows_devices_spi_config.cpp +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/target_windows_devices_spi_config.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/CMakeLists.txt b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/CMakeLists.txt index 6716508f50..9dad3846ca 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/CMakeLists.txt +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # @@ -17,7 +17,7 @@ set(NANOBOOTER_PROJECT_NAME "nanoBooter") set(NANOCLR_PROJECT_NAME "nanoCLR") find_package(BuildUtils REQUIRED) -find_package(CHIBIOS REQUIRED) +find_package(ChibiOS REQUIRED) find_package(ChibiOSnfOverlay REQUIRED) find_package(WireProtocol REQUIRED) diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/cmake-variants.json b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/cmake-variants.json new file mode 100644 index 0000000000..8df41513fb --- /dev/null +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/cmake-variants.json @@ -0,0 +1,70 @@ +{ + "buildType": { + "default": "debug", + "choices": { + "debug": { + "short": "Debug", + "long": "Emit debug information without performing optimizations", + "buildType": "Debug" + }, + "minsize": { + "short": "MinSizeRel", + "long": "Optimize for smallest binary size", + "buildType": "MinSizeRel" + }, + "reldeb": { + "short": "RelWithDebInfo", + "long": "Perform optimizations AND include debugging information", + "buildType": "RelWithDebInfo" + } + } + }, + "linkage": { + "default": "", + "choices": { + "ST_STM32F769I_DISCOVERY": { + "short": "ST_STM32F769I_DISCOVERY", + "settings": { + "BUILD_VERSION": "0.9.99.999", + "CMAKE_TOOLCHAIN_FILE": "CMake/toolchain.arm-none-eabi.cmake", + "TOOLCHAIN_PREFIX": "", + "TOOL_HEX2DFU_PREFIX": "", + "RTOS": "CHIBIOS", + "TARGET_SERIES": "STM32F7xx", + "RTOS_SOURCE_FOLDER": "", + "CHIBIOS_BOARD": "ST_STM32F769I_DISCOVERY", + "CHIBIOS_CONTRIB_REQUIRED": "OFF", + "CHIBIOS_CONTRIB_SOURCE": "", + "STM32_CUBE_PACKAGE_REQUIRED": "OFF", + "STM32_CUBE_PACKAGE_SOURCE": "", + "MBEDTLS_SOURCE": "", + "FATFS_SOURCE": "", + "SUPPORT_ANY_BASE_CONVERSION": "ON", + "NF_FEATURE_DEBUGGER": "ON", + "NF_FEATURE_RTC": "ON", + "NF_FEATURE_HAS_SDCARD": "ON", + "NF_FEATURE_HAS_CONFIG_BLOCK": "ON", + "NF_SECURITY_MBEDTLS": "ON", + "SWO_OUTPUT": "OFF", + "NF_BUILD_RTM": "OFF", + "API_System.Math": "ON", + "API_Hardware.Stm32": "ON", + "API_Windows.Devices.Gpio": "ON", + "API_Windows.Devices.Spi": "ON", + "API_Windows.Devices.I2c": "ON", + "API_Windows.Devices.Pwm": "ON", + "API_Windows.Devices.SerialCommunication": "ON", + "API_Windows.Devices.Adc": "ON", + "API_Windows.Device.Dac": "ON", + "API_System.Net": "ON", + "API_nanoFramework.Devices.OneWire": "ON", + "API_nanoFramework.Devices.Can": "ON", + "API_Windows.Storage": "ON", + "API_nanoFramework.ResourceManager": "ON", + "API_nanoFramework.System.Collections": "ON", + "API_nanoFramework.System.Text": "ON" + } + } + } + } +} diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/common/CMakeLists.txt b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/common/CMakeLists.txt index 7c21ff9b57..190dc7f5fd 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/common/CMakeLists.txt +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/common/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/common/Device_BlockStorage-DEBUG.c b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/common/Device_BlockStorage-DEBUG.c index 3695ffd06f..0ff4f316ec 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/common/Device_BlockStorage-DEBUG.c +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/common/Device_BlockStorage-DEBUG.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/common/Device_BlockStorage.c b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/common/Device_BlockStorage.c index d5aa46574f..006329f023 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/common/Device_BlockStorage.c +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/common/Device_BlockStorage.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/common/serialcfg.h b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/common/serialcfg.h index cbe6b254a6..b356b1736a 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/common/serialcfg.h +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/common/serialcfg.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/common/targetHAL_ConfigurationManager.cpp b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/common/targetHAL_ConfigurationManager.cpp index 178f6aa783..0bdb275fd8 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/common/targetHAL_ConfigurationManager.cpp +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/common/targetHAL_ConfigurationManager.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/launch.json b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/launch.json new file mode 100644 index 0000000000..13ca18f992 --- /dev/null +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/launch.json @@ -0,0 +1,109 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "ST_STM32F769I_DISCOVERY nanoBooter", + "type": "cppdbg", + "request": "launch", + "miDebuggerPath": "/bin/arm-none-eabi-gdb.exe", + "targetArchitecture": "ARM", + "program": "${workspaceRoot}/build/nanoBooter.elf", + "setupCommands": [ + { + "text": "target extended-remote localhost:3333" + }, + { + "text": "monitor reset_config none separate" + }, + { + "text": "monitor reset halt" + }, + { + "text": "monitor flash write_image erase \"/build/nanoBooter.hex\" " + }, + { + "text": "file /build/nanoBooter.elf" + }, + { + "text": "set output-radix 16", + "description": "set the default numeric base to 16", + "ignoreFailures": false + } + ], + "customLaunchSetupCommands": [ + { + "text": "monitor reset_config none separate" + }, + { + "text": "monitor reset halt" + } + ], + "logging": { + "moduleLoad": false, + "trace": false, + "engineLogging": false, + "programOutput": true, + "exceptions": true + }, + "launchCompleteCommand": "exec-continue", + "debugServerPath": "/bin/openocd.exe", + "debugServerArgs": "-s \"/scripts/\" -f board/stm32f7discovery.cfg", + "serverStarted": "Info\\ :\\ [\\w\\d\\.]*:\\ hardware", + "filterStderr": true, + "externalConsole": true, + "cwd": "${cwd}" + }, + { + "name": "ST_STM32F769I_DISCOVERY nanoCLR", + "type": "cppdbg", + "request": "launch", + "miDebuggerPath": "/bin/arm-none-eabi-gdb.exe", + "targetArchitecture": "ARM", + "program": "${workspaceRoot}/build/nanoCLR.elf", + "setupCommands": [ + { + "text": "target extended-remote localhost:3333" + }, + { + "text": "monitor reset_config none separate" + }, + { + "text": "monitor reset halt" + }, + { + "text": "monitor flash write_image erase \"/build/nanoCLR.hex\" " + }, + { + "text": "file /build/nanoCLR.elf" + }, + { + "text": "set output-radix 16", + "description": "set the default numeric base to 16", + "ignoreFailures": false + } + ], + "customLaunchSetupCommands": [ + { + "text": "monitor reset_config none separate" + }, + { + "text": "monitor reset halt" + } + ], + "logging": { + "moduleLoad": false, + "trace": false, + "engineLogging": false, + "programOutput": true, + "exceptions": true + }, + "launchCompleteCommand": "exec-continue", + "debugServerPath": "/bin/openocd.exe", + "debugServerArgs": "-s \"/scripts/\" -f board/stm32f7discovery.cfg", + "serverStarted": "Info\\ :\\ [\\w\\d\\.]*:\\ hardware", + "filterStderr": true, + "externalConsole": true, + "cwd": "${cwd}" + } + ] +} diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/managed_helpers/STM32F769I_DISCOVERY.Adc.cs b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/managed_helpers/STM32F769I_DISCOVERY.Adc.cs index b78ba6eb52..86cb27da99 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/managed_helpers/STM32F769I_DISCOVERY.Adc.cs +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/managed_helpers/STM32F769I_DISCOVERY.Adc.cs @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/managed_helpers/package.nuspec b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/managed_helpers/package.nuspec index 58e7f992d9..749089f934 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/managed_helpers/package.nuspec +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/managed_helpers/package.nuspec @@ -18,7 +18,7 @@ https://github.com/nanoframework https://secure.gravatar.com/avatar/97d0e092247f0716db6d4b47b7d1d1ad https://github.com/nanoframework/nf-interpreter/blob/develop/LICENSE.md - Copyright (c) 2019 The nanoFramework project contributors + Copyright (c) .NET Foundation and Contributors nanoFramework, nano Framework, NETNF, NETMF, Micro Framework, STM32, .net, STM32F769I diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/mbedtls_config.h b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/mbedtls_config.h index 344adf5be4..6cf360ae36 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/mbedtls_config.h +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/mbedtls_config.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006-2015, ARM Limited, All Rights Reserved // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoBooter/CMakeLists.txt b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoBooter/CMakeLists.txt index f0e921f750..73b5927c6b 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoBooter/CMakeLists.txt +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoBooter/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoBooter/STM32F76xx_booter-DEBUG.ld b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoBooter/STM32F76xx_booter-DEBUG.ld index 0637fbd71e..ed45588cf4 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoBooter/STM32F76xx_booter-DEBUG.ld +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoBooter/STM32F76xx_booter-DEBUG.ld @@ -1,6 +1,6 @@ /* // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoBooter/STM32F76xx_booter.ld b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoBooter/STM32F76xx_booter.ld index 0637fbd71e..ed45588cf4 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoBooter/STM32F76xx_booter.ld +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoBooter/STM32F76xx_booter.ld @@ -1,6 +1,6 @@ /* // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoBooter/chconf.h b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoBooter/chconf.h index 0bd93fbe49..8c2fe05561 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoBooter/chconf.h +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoBooter/chconf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoBooter/halconf.h b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoBooter/halconf.h index fb74d8edc3..7276e0ea6d 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoBooter/halconf.h +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoBooter/halconf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoBooter/halconf_nf.h b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoBooter/halconf_nf.h index ac3bc93126..83ae9e61dc 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoBooter/halconf_nf.h +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoBooter/halconf_nf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoBooter/main.c b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoBooter/main.c index d7840f0005..55de002589 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoBooter/main.c +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoBooter/main.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoBooter/mcuconf.h b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoBooter/mcuconf.h index be56ce4438..6e358b0b6a 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoBooter/mcuconf.h +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoBooter/mcuconf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoBooter/mcuconf_nf.h b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoBooter/mcuconf_nf.h index 5ff03534b6..7c689dd279 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoBooter/mcuconf_nf.h +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoBooter/mcuconf_nf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoBooter/target_board.h.in b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoBooter/target_board.h.in index 750beb565c..ad151ebd73 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoBooter/target_board.h.in +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoBooter/target_board.h.in @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/CMakeLists.txt b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/CMakeLists.txt index e5496b7ea0..f5fab75926 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/CMakeLists.txt +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/STM32F76xx_CLR-DEBUG.ld b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/STM32F76xx_CLR-DEBUG.ld index 63725eeb02..2c64a39bad 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/STM32F76xx_CLR-DEBUG.ld +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/STM32F76xx_CLR-DEBUG.ld @@ -1,6 +1,6 @@ /* // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/STM32F76xx_CLR.ld b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/STM32F76xx_CLR.ld index 3bc7ae3762..55e1aad074 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/STM32F76xx_CLR.ld +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/STM32F76xx_CLR.ld @@ -1,6 +1,6 @@ /* // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/chconf.h b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/chconf.h index 214cbcd6e2..925fb80c5d 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/chconf.h +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/chconf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/halconf.h b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/halconf.h index 32abfdc568..3b486a9618 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/halconf.h +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/halconf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/halconf_nf.h b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/halconf_nf.h index 4d615a0b14..9f134acec8 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/halconf_nf.h +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/halconf_nf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/main.c b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/main.c index e63db4fa56..184456e3a1 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/main.c +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/main.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/mcuconf.h b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/mcuconf.h index a7b6c6af48..3f7b418066 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/mcuconf.h +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/mcuconf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/mcuconf_nf.h b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/mcuconf_nf.h index bf6b31e3c8..125aa7171d 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/mcuconf_nf.h +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/mcuconf_nf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/nanoHAL.cpp b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/nanoHAL.cpp index 076a50fc68..a971e00292 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/nanoHAL.cpp +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/nanoHAL.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/target_board.h.in b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/target_board.h.in index 6fb5861584..f5476e640a 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/target_board.h.in +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/target_board.h.in @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/spiffs_config.h b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/spiffs_config.h index f0fba80b36..6699d4456d 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/spiffs_config.h +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/spiffs_config.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2013, petera, All Rights Reserved // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/stm32f7xx_hal_conf.h b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/stm32f7xx_hal_conf.h index a6c88c0581..c01df7b0aa 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/stm32f7xx_hal_conf.h +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/stm32f7xx_hal_conf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2016 STMicroelectronics. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_BlockStorage.c b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_BlockStorage.c index 9e7c7f5546..db45d1a411 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_BlockStorage.c +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_BlockStorage.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_BlockStorage.h b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_BlockStorage.h index aa50b1b7f2..8a56d0eee0 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_BlockStorage.h +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_BlockStorage.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_common.c b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_common.c index ee602ba034..c266d62c2b 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_common.c +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_common.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_common.h.in b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_common.h.in index ec25526b74..0c4bbd91e8 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_common.h.in +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_common.h.in @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // @@ -12,6 +12,8 @@ #define _TARGET_COMMON_H_ #include +#include +#include ///////////////////////////////////////////////////////////////////////////////////////// // The following addresses and sizes should be filled in according to the SoC data-sheet diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_external_memory.c b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_external_memory.c index 299fe1efaf..ac5a917b4c 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_external_memory.c +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_external_memory.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_lwip_sntp_opts.h b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_lwip_sntp_opts.h index c115cd67bd..a0f52fe8e3 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_lwip_sntp_opts.h +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_lwip_sntp_opts.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_lwipopts.h b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_lwipopts.h new file mode 100644 index 0000000000..ca1a0b4465 --- /dev/null +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_lwipopts.h @@ -0,0 +1,8 @@ +// +// Copyright (c) .NET Foundation and Contributors +// See LICENSE file in the project root for full license information. +// + +///////////////////////////////////////////////////////////////////////////////////////// +// THIS FILE IS BLANK ON PURPOSE BECAUSE THIS TARGET DOESN'T OVERRIDE ANY lwIP OPTIONS // +///////////////////////////////////////////////////////////////////////////////////////// diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_nf_devices_can_config.cpp b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_nf_devices_can_config.cpp index 7dbe7ff19a..c7d263b871 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_nf_devices_can_config.cpp +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_nf_devices_can_config.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_nf_devices_can_config.h b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_nf_devices_can_config.h index adc8ace3b2..db3e146a08 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_nf_devices_can_config.h +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_nf_devices_can_config.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_nf_devices_onewire_config.cpp b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_nf_devices_onewire_config.cpp index 09f1420ecf..61ac65de1a 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_nf_devices_onewire_config.cpp +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_nf_devices_onewire_config.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_nf_devices_onewire_config.h b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_nf_devices_onewire_config.h index 76f90a1079..53130a03ed 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_nf_devices_onewire_config.h +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_nf_devices_onewire_config.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_spiffs.c b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_spiffs.c index 103930bb51..128fdb708e 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_spiffs.c +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_spiffs.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2016 STMicroelectronics. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_spiffs.h b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_spiffs.h index c6d1b86aaa..325d1233b8 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_spiffs.h +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_spiffs.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_system_devices_dac_config.cpp b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_system_device_dac_config.cpp similarity index 71% rename from targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_system_devices_dac_config.cpp rename to targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_system_device_dac_config.cpp index 049422f78a..948967e054 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_system_devices_dac_config.cpp +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_system_device_dac_config.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // @@ -7,7 +7,7 @@ const NF_PAL_DAC_PORT_PIN_CHANNEL DacPortPinConfig[] = { - // DAC1, channel 1, GPIO port A, pin 4 + // DAC1, channel 1, GPIO port A, pin 4 {1, 1, GPIOA, 4}, }; diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_windows_devices_adc_config.cpp b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_windows_devices_adc_config.cpp index 3a886009b7..f1f43c11ce 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_windows_devices_adc_config.cpp +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_windows_devices_adc_config.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_windows_devices_i2c_config.cpp b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_windows_devices_i2c_config.cpp index 2a60a22f67..d25693720c 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_windows_devices_i2c_config.cpp +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_windows_devices_i2c_config.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_windows_devices_serialcommunication_config.cpp b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_windows_devices_serialcommunication_config.cpp index 2f2f4148de..894146c3d4 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_windows_devices_serialcommunication_config.cpp +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_windows_devices_serialcommunication_config.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_windows_devices_serialcommunication_config.h b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_windows_devices_serialcommunication_config.h index 346f56740d..3e5733f82f 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_windows_devices_serialcommunication_config.h +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_windows_devices_serialcommunication_config.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_windows_devices_spi_config.cpp b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_windows_devices_spi_config.cpp index 4f3bb3fcd7..dc14a8245d 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_windows_devices_spi_config.cpp +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_windows_devices_spi_config.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_windows_storage_config.h b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_windows_storage_config.h index 5dc140d813..a7bf747bf3 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_windows_storage_config.h +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/target_windows_storage_config.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/common/CMakeLists.txt b/targets/CMSIS-OS/ChibiOS/common/CMakeLists.txt index ba2bf0f7cc..1d53bc3e61 100644 --- a/targets/CMSIS-OS/ChibiOS/common/CMakeLists.txt +++ b/targets/CMSIS-OS/ChibiOS/common/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/targets/CMSIS-OS/ChibiOS/common/LaunchCLR.c b/targets/CMSIS-OS/ChibiOS/common/LaunchCLR.c index 19f441a3ee..bb941b47a7 100644 --- a/targets/CMSIS-OS/ChibiOS/common/LaunchCLR.c +++ b/targets/CMSIS-OS/ChibiOS/common/LaunchCLR.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/common/Target_BlockStorage_STM32FlashDriver.c b/targets/CMSIS-OS/ChibiOS/common/Target_BlockStorage_STM32FlashDriver.c index deb991a43b..e8381da8b2 100644 --- a/targets/CMSIS-OS/ChibiOS/common/Target_BlockStorage_STM32FlashDriver.c +++ b/targets/CMSIS-OS/ChibiOS/common/Target_BlockStorage_STM32FlashDriver.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/common/Target_Network.cpp b/targets/CMSIS-OS/ChibiOS/common/Target_Network.cpp index e69baef2f5..62985cc0f1 100644 --- a/targets/CMSIS-OS/ChibiOS/common/Target_Network.cpp +++ b/targets/CMSIS-OS/ChibiOS/common/Target_Network.cpp @@ -1,17 +1,16 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // #include #include -extern "C" struct netif * nf_getNetif(); +extern "C" struct netif *nf_getNetif(); // // Works with the Target_NetworkConfig to map the Network_Interface_XXXXX calls to the correct driver - bool Network_Interface_Bind(int index) { (void)index; @@ -19,12 +18,15 @@ bool Network_Interface_Bind(int index) return true; } -int Network_Interface_Open(int index) +int Network_Interface_Open(int index) { HAL_Configuration_NetworkInterface networkConfiguration; // load network interface configuration from storage - if(!ConfigurationManager_GetConfigurationBlock((void*)&networkConfiguration, DeviceConfigurationOption_Network, index)) + if (!ConfigurationManager_GetConfigurationBlock( + (void *)&networkConfiguration, + DeviceConfigurationOption_Network, + index)) { // failed to load configuration // FIXME output error? @@ -32,7 +34,7 @@ int Network_Interface_Open(int index) } _ASSERTE(networkConfiguration.StartupAddressMode > 0); - switch(index) + switch (index) { case 0: { @@ -43,20 +45,20 @@ int Network_Interface_Open(int index) // This used by Network stack to hook in to status/address changes for events to users // For now get the Netif number form original Chibios binding code - struct netif * nptr = nf_getNetif(); - return nptr->num; + struct netif *nptr = nf_getNetif(); + return nptr->num; } break; } - return SOCK_SOCKET_ERROR; + return SOCK_SOCKET_ERROR; } bool Network_Interface_Close(int index) { - switch(index) + switch (index) { case 0: return true; } - return false; -} \ No newline at end of file + return false; +} diff --git a/targets/CMSIS-OS/ChibiOS/common/Target_Windows_Storage.c b/targets/CMSIS-OS/ChibiOS/common/Target_Windows_Storage.c index 5f2ec2d81d..aebc02d365 100644 --- a/targets/CMSIS-OS/ChibiOS/common/Target_Windows_Storage.c +++ b/targets/CMSIS-OS/ChibiOS/common/Target_Windows_Storage.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/common/WireProtocol_HAL_Interface.c b/targets/CMSIS-OS/ChibiOS/common/WireProtocol_HAL_Interface.c index c337c28c31..c3bd8b662a 100644 --- a/targets/CMSIS-OS/ChibiOS/common/WireProtocol_HAL_Interface.c +++ b/targets/CMSIS-OS/ChibiOS/common/WireProtocol_HAL_Interface.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/common/WireProtocol_ReceiverThread.c b/targets/CMSIS-OS/ChibiOS/common/WireProtocol_ReceiverThread.c index 6ff6df4daf..d0b70808a0 100644 --- a/targets/CMSIS-OS/ChibiOS/common/WireProtocol_ReceiverThread.c +++ b/targets/CMSIS-OS/ChibiOS/common/WireProtocol_ReceiverThread.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/common/hard_fault_handler.c b/targets/CMSIS-OS/ChibiOS/common/hard_fault_handler.c index e9b1664942..cc9bb65685 100644 --- a/targets/CMSIS-OS/ChibiOS/common/hard_fault_handler.c +++ b/targets/CMSIS-OS/ChibiOS/common/hard_fault_handler.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/common/nanoSupport_CRC32.c b/targets/CMSIS-OS/ChibiOS/common/nanoSupport_CRC32.c index cab0f94c94..924f87af71 100644 --- a/targets/CMSIS-OS/ChibiOS/common/nanoSupport_CRC32.c +++ b/targets/CMSIS-OS/ChibiOS/common/nanoSupport_CRC32.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/common/platform_BlockStorage.c b/targets/CMSIS-OS/ChibiOS/common/platform_BlockStorage.c index 868a587877..3e797bddc4 100644 --- a/targets/CMSIS-OS/ChibiOS/common/platform_BlockStorage.c +++ b/targets/CMSIS-OS/ChibiOS/common/platform_BlockStorage.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/common/platform_heap.c b/targets/CMSIS-OS/ChibiOS/common/platform_heap.c index 87c648d33e..37e559f312 100644 --- a/targets/CMSIS-OS/ChibiOS/common/platform_heap.c +++ b/targets/CMSIS-OS/ChibiOS/common/platform_heap.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/common/rules.ld b/targets/CMSIS-OS/ChibiOS/common/rules.ld index 4e323fa89c..5776727ce5 100644 --- a/targets/CMSIS-OS/ChibiOS/common/rules.ld +++ b/targets/CMSIS-OS/ChibiOS/common/rules.ld @@ -1,6 +1,6 @@ /* // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/common/rules_code.ld b/targets/CMSIS-OS/ChibiOS/common/rules_code.ld index 80a49318bd..1cde0c8cb5 100644 --- a/targets/CMSIS-OS/ChibiOS/common/rules_code.ld +++ b/targets/CMSIS-OS/ChibiOS/common/rules_code.ld @@ -1,6 +1,6 @@ /* // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // @@ -20,7 +20,7 @@ ENTRY(Reset_Handler) SECTIONS { - .vectors : ALIGN(16) + .vectors : ALIGN(1024) { KEEP(*(.vectors)) } > VECTORS_FLASH AT > VECTORS_FLASH_LMA diff --git a/targets/CMSIS-OS/ChibiOS/common/rules_data.ld b/targets/CMSIS-OS/ChibiOS/common/rules_data.ld index 18da278483..2975fcf875 100644 --- a/targets/CMSIS-OS/ChibiOS/common/rules_data.ld +++ b/targets/CMSIS-OS/ChibiOS/common/rules_data.ld @@ -1,6 +1,6 @@ /* // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/common/rules_stacks.ld b/targets/CMSIS-OS/ChibiOS/common/rules_stacks.ld index 227a90c6d2..ab5f6fc70f 100644 --- a/targets/CMSIS-OS/ChibiOS/common/rules_stacks.ld +++ b/targets/CMSIS-OS/ChibiOS/common/rules_stacks.ld @@ -1,6 +1,6 @@ /* // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/common/targetHAL.c b/targets/CMSIS-OS/ChibiOS/common/targetHAL.c index 0088b871f1..d9d00a5da1 100644 --- a/targets/CMSIS-OS/ChibiOS/common/targetHAL.c +++ b/targets/CMSIS-OS/ChibiOS/common/targetHAL.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/common/targetHAL_ConfigurationManager.cpp b/targets/CMSIS-OS/ChibiOS/common/targetHAL_ConfigurationManager.cpp index c525094d5e..7bed439c53 100644 --- a/targets/CMSIS-OS/ChibiOS/common/targetHAL_ConfigurationManager.cpp +++ b/targets/CMSIS-OS/ChibiOS/common/targetHAL_ConfigurationManager.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/common/targetHAL_Network.cpp b/targets/CMSIS-OS/ChibiOS/common/targetHAL_Network.cpp index e7b265cae2..29add06308 100644 --- a/targets/CMSIS-OS/ChibiOS/common/targetHAL_Network.cpp +++ b/targets/CMSIS-OS/ChibiOS/common/targetHAL_Network.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/common/targetHAL_Time.cpp b/targets/CMSIS-OS/ChibiOS/common/targetHAL_Time.cpp index 4b11d4f003..7ffd0596f7 100644 --- a/targets/CMSIS-OS/ChibiOS/common/targetHAL_Time.cpp +++ b/targets/CMSIS-OS/ChibiOS/common/targetHAL_Time.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nanoBooter/CMakeLists.txt b/targets/CMSIS-OS/ChibiOS/nanoBooter/CMakeLists.txt index d88eae237e..47694af1ab 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoBooter/CMakeLists.txt +++ b/targets/CMSIS-OS/ChibiOS/nanoBooter/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/targets/CMSIS-OS/ChibiOS/nanoBooter/WireProtocol_App_Interface.c b/targets/CMSIS-OS/ChibiOS/nanoBooter/WireProtocol_App_Interface.c index d2be2eebe5..055e05b48f 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoBooter/WireProtocol_App_Interface.c +++ b/targets/CMSIS-OS/ChibiOS/nanoBooter/WireProtocol_App_Interface.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nanoBooter/WireProtocol_MonitorCommands.c b/targets/CMSIS-OS/ChibiOS/nanoBooter/WireProtocol_MonitorCommands.c index 0c67fb515a..378060316d 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoBooter/WireProtocol_MonitorCommands.c +++ b/targets/CMSIS-OS/ChibiOS/nanoBooter/WireProtocol_MonitorCommands.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // @@ -17,7 +17,7 @@ ////////////////////////////////////////////////////////////////////// // helper functions -int NanoBooter_GetReleaseInfo(ReleaseInfo* releaseInfo) +int NanoBooter_GetReleaseInfo(ReleaseInfo *releaseInfo) { releaseInfo->version.usMajor = VERSION_MAJOR; releaseInfo->version.usMinor = VERSION_MINOR; @@ -32,12 +32,12 @@ int NanoBooter_GetReleaseInfo(ReleaseInfo* releaseInfo) return true; } -static int AccessMemory(uint32_t location, uint32_t lengthInBytes, uint8_t* buffer, int32_t mode, uint32_t* errorCode) +static int AccessMemory(uint32_t location, uint32_t lengthInBytes, uint8_t *buffer, int32_t mode, uint32_t *errorCode) { // reset error code *errorCode = AccessMemoryErrorCode_NoError; - - switch(mode) + + switch (mode) { case AccessMemory_Write: // use FLASH driver to perform write operation @@ -68,29 +68,28 @@ static int AccessMemory(uint32_t location, uint32_t lengthInBytes, uint8_t* buff //////////////////////////////////////////////////// -int Monitor_Ping(WP_Message* message) +int Monitor_Ping(WP_Message *message) { - if((message->m_header.m_flags & WP_Flags_c_Reply) == 0) + if ((message->m_header.m_flags & WP_Flags_c_Reply) == 0) { Monitor_Ping_Reply cmdReply; cmdReply.m_source = Monitor_Ping_c_Ping_Source_NanoBooter; cmdReply.m_dbg_flags = 0; - #if defined(WP_IMPLEMENTS_CRC32) - cmdReply.m_dbg_flags |= Monitor_Ping_c_Ping_WPFlag_SupportsCRC32; - #endif +#if defined(WP_IMPLEMENTS_CRC32) + cmdReply.m_dbg_flags |= Monitor_Ping_c_Ping_WPFlag_SupportsCRC32; +#endif - // Wire Protocol packet size - #if (WP_PACKET_SIZE == 512) +// Wire Protocol packet size +#if (WP_PACKET_SIZE == 512) cmdReply.m_dbg_flags |= Monitor_Ping_c_PacketSize_0512; - #elif (WP_PACKET_SIZE == 256) +#elif (WP_PACKET_SIZE == 256) cmdReply.m_dbg_flags |= Monitor_Ping_c_PacketSize_0256; - #elif (WP_PACKET_SIZE == 128) +#elif (WP_PACKET_SIZE == 128) cmdReply.m_dbg_flags |= Monitor_Ping_c_PacketSize_0128; - #elif (WP_PACKET_SIZE == 1024) +#elif (WP_PACKET_SIZE == 1024) cmdReply.m_dbg_flags |= Monitor_Ping_c_PacketSize_1024; - #endif - +#endif WP_ReplyToCommand(message, true, false, &cmdReply, sizeof(cmdReply)); } @@ -98,70 +97,71 @@ int Monitor_Ping(WP_Message* message) return true; } -int Monitor_OemInfo(WP_Message* message) +int Monitor_OemInfo(WP_Message *message) { - if((message->m_header.m_flags & WP_Flags_c_Reply) == 0) + if ((message->m_header.m_flags & WP_Flags_c_Reply) == 0) { - Monitor_OemInfo_Reply cmdReply; - + Monitor_OemInfo_Reply cmdReply; + bool fOK = NanoBooter_GetReleaseInfo(&cmdReply.m_releaseInfo) == true; - + WP_ReplyToCommand(message, fOK, false, &cmdReply, sizeof(cmdReply)); } return true; } -int Monitor_ReadMemory(WP_Message* message) +int Monitor_ReadMemory(WP_Message *message) { - CLR_DBG_Commands_Monitor_ReadMemory* cmd = (CLR_DBG_Commands_Monitor_ReadMemory*)message->m_payload; + CLR_DBG_Commands_Monitor_ReadMemory *cmd = (CLR_DBG_Commands_Monitor_ReadMemory *)message->m_payload; - unsigned char buf[ 1024 ]; - unsigned int len = cmd->length; if(len > sizeof(buf)) len = sizeof(buf); + unsigned char buf[1024]; + unsigned int len = cmd->length; + if (len > sizeof(buf)) + len = sizeof(buf); uint32_t errorCode; - AccessMemory(cmd->address, len, buf, AccessMemory_Read, &errorCode ); + AccessMemory(cmd->address, len, buf, AccessMemory_Read, &errorCode); WP_ReplyToCommand(message, true, false, buf, len); return true; } -int Monitor_WriteMemory(WP_Message* message) +int Monitor_WriteMemory(WP_Message *message) { - CLR_DBG_Commands_Monitor_WriteMemory* cmd = (CLR_DBG_Commands_Monitor_WriteMemory*)message->m_payload; + CLR_DBG_Commands_Monitor_WriteMemory *cmd = (CLR_DBG_Commands_Monitor_WriteMemory *)message->m_payload; CLR_DBG_Commands_Monitor_WriteMemory_Reply cmdReply; - // TODO: not sure if we really need this // if(!m_signedDataState.VerifyContiguousData(cmd->m_address, cmd->m_length)) // { // m_signedDataState.EraseMemoryAndReset(); - + // return false; // } // TODO: not sure if we really need this // nanoBooter_OnStateChange(State_MemoryWrite, (void*)cmd->m_address); - // assume at RAM, directly use the original address - AccessMemory(cmd->address, cmd->length, cmd->data, AccessMemory_Write, &cmdReply.ErrorCode); - + // assume at RAM, directly use the original address + AccessMemory(cmd->address, cmd->length, cmd->data, AccessMemory_Write, &cmdReply); + WP_ReplyToCommand(message, true, false, &cmdReply, sizeof(cmdReply)); return true; } -int Monitor_Reboot(WP_Message* message) +int Monitor_Reboot(WP_Message *message) { - Monitor_Reboot_Command* cmd = (Monitor_Reboot_Command*)message->m_payload; + Monitor_Reboot_Command *cmd = (Monitor_Reboot_Command *)message->m_payload; WP_ReplyToCommand(message, true, false, NULL, 0); - if(cmd != NULL) + if (cmd != NULL) { // only reset if we are not trying to get into the bootloader - if((cmd->m_flags & Monitor_Reboot_c_EnterBootloader) != Monitor_Reboot_c_EnterBootloader) + if ((cmd->m_flags & Monitor_Reboot_c_EnterBootloader) != Monitor_Reboot_c_EnterBootloader) { // RESET CPU // because ChibiOS relies on CMSIS it's recommended to make use of the CMSIS API @@ -172,55 +172,61 @@ int Monitor_Reboot(WP_Message* message) return true; } -int Monitor_EraseMemory(WP_Message* message) +int Monitor_EraseMemory(WP_Message *message) { - CLR_DBG_Commands_Monitor_EraseMemory* cmd = (CLR_DBG_Commands_Monitor_EraseMemory*)message->m_payload; + CLR_DBG_Commands_Monitor_EraseMemory *cmd = (CLR_DBG_Commands_Monitor_EraseMemory *)message->m_payload; CLR_DBG_Commands_Monitor_EraseMemory_Reply cmdReply; // TODO: not sure if we really need this // nanoBooter_OnStateChange( State_MemoryErase, (void*)cmd->m_address ); - - AccessMemory(cmd->address, cmd->length, NULL, AccessMemory_Erase, &cmdReply.ErrorCode); + + AccessMemory(cmd->address, cmd->length, NULL, AccessMemory_Erase, &cmdReply); WP_ReplyToCommand(message, true, false, &cmdReply, sizeof(cmdReply)); - + return true; } -int Monitor_QueryConfiguration(WP_Message* message) +int Monitor_QueryConfiguration(WP_Message *message) { - bool success = false; + bool success = false; // include handling of configuration block only if feature is available - #if (HAS_CONFIG_BLOCK == TRUE) +#if (HAS_CONFIG_BLOCK == TRUE) - Monitor_QueryConfiguration_Command *cmd = (Monitor_QueryConfiguration_Command*)message->m_payload; - int size = 0; + Monitor_QueryConfiguration_Command *cmd = (Monitor_QueryConfiguration_Command *)message->m_payload; + int size = 0; HAL_Configuration_NetworkInterface configNetworkInterface; HAL_Configuration_Wireless80211 configWireless80211NetworkInterface; - switch((DeviceConfigurationOption)cmd->Configuration) + switch ((DeviceConfigurationOption)cmd->Configuration) { case DeviceConfigurationOption_Network: - if(ConfigurationManager_GetConfigurationBlock((void *)&configNetworkInterface, (DeviceConfigurationOption)cmd->Configuration, cmd->BlockIndex) == true) + if (ConfigurationManager_GetConfigurationBlock( + (void *)&configNetworkInterface, + (DeviceConfigurationOption)cmd->Configuration, + cmd->BlockIndex) == true) { size = sizeof(HAL_Configuration_NetworkInterface); success = true; - WP_ReplyToCommand( message, success, false, (uint8_t*)&configNetworkInterface, size ); - } + WP_ReplyToCommand(message, success, false, (uint8_t *)&configNetworkInterface, size); + } break; case DeviceConfigurationOption_Wireless80211Network: - if(ConfigurationManager_GetConfigurationBlock((void *)&configWireless80211NetworkInterface, (DeviceConfigurationOption)cmd->Configuration, cmd->BlockIndex) == true) + if (ConfigurationManager_GetConfigurationBlock( + (void *)&configWireless80211NetworkInterface, + (DeviceConfigurationOption)cmd->Configuration, + cmd->BlockIndex) == true) { size = sizeof(HAL_Configuration_Wireless80211); success = true; - WP_ReplyToCommand( message, success, false, (uint8_t*)&configWireless80211NetworkInterface, size ); + WP_ReplyToCommand(message, success, false, (uint8_t *)&configWireless80211NetworkInterface, size); } break; @@ -229,45 +235,51 @@ int Monitor_QueryConfiguration(WP_Message* message) break; default: - break; + break; } - if(!success) + if (!success) { - WP_ReplyToCommand( message, success, false, NULL, size ); + WP_ReplyToCommand(message, success, false, NULL, size); } - #else +#else (void)message; - #endif // (HAS_CONFIG_BLOCK == TRUE) +#endif // (HAS_CONFIG_BLOCK == TRUE) return success; } -int Monitor_UpdateConfiguration(WP_Message* message) +int Monitor_UpdateConfiguration(WP_Message *message) { bool success = false; // include handling of configuration block only if feature is available - #if (HAS_CONFIG_BLOCK == TRUE) - - Monitor_UpdateConfiguration_Command* cmd = (Monitor_UpdateConfiguration_Command*)message->m_payload; +#if (HAS_CONFIG_BLOCK == TRUE) + + Monitor_UpdateConfiguration_Command *cmd = (Monitor_UpdateConfiguration_Command *)message->m_payload; Monitor_UpdateConfiguration_Reply cmdReply; - switch((DeviceConfigurationOption)cmd->Configuration) + switch ((DeviceConfigurationOption)cmd->Configuration) { case DeviceConfigurationOption_Network: case DeviceConfigurationOption_Wireless80211Network: case DeviceConfigurationOption_X509CaRootBundle: case DeviceConfigurationOption_All: - if(ConfigurationManager_StoreConfigurationBlock(cmd->Data, (DeviceConfigurationOption)cmd->Configuration, cmd->BlockIndex, cmd->Length, cmd->Offset, cmd->Done) == true) + if (ConfigurationManager_StoreConfigurationBlock( + cmd->Data, + (DeviceConfigurationOption)cmd->Configuration, + cmd->BlockIndex, + cmd->Length, + cmd->Offset, + cmd->Done) == true) { cmdReply.ErrorCode = 0; success = true; } - else + else { cmdReply.ErrorCode = 100; } @@ -279,58 +291,58 @@ int Monitor_UpdateConfiguration(WP_Message* message) WP_ReplyToCommand(message, success, false, &cmdReply, sizeof(cmdReply)); - #else +#else (void)message; - #endif // (HAS_CONFIG_BLOCK == TRUE) +#endif // (HAS_CONFIG_BLOCK == TRUE) return success; } -int Monitor_CheckMemory(WP_Message* message) +int Monitor_CheckMemory(WP_Message *message) { bool ret = false; - CLR_DBG_Commands_Monitor_CheckMemory* cmd = (CLR_DBG_Commands_Monitor_CheckMemory*)message->m_payload; + CLR_DBG_Commands_Monitor_CheckMemory *cmd = (CLR_DBG_Commands_Monitor_CheckMemory *)message->m_payload; CLR_DBG_Commands_Monitor_CheckMemory_Reply cmdReply; uint32_t errorCode; - ret = AccessMemory(cmd->address, cmd->length, (uint8_t*)&cmdReply.crc, AccessMemory_Check, &errorCode); + ret = AccessMemory(cmd->address, cmd->length, (uint8_t *)&cmdReply, AccessMemory_Check, &errorCode); WP_ReplyToCommand(message, ret, false, &cmdReply, sizeof(cmdReply)); return ret; } -int Monitor_MemoryMap(WP_Message* message) +int Monitor_MemoryMap(WP_Message *message) { MemoryMap_Range map[2]; // if(m_signedDataState.CheckDirty()) // { // m_signedDataState.EraseMemoryAndReset(); - + // return false; // } map[0].m_address = HalSystemConfig.RAM1.Base; - map[0].m_length = HalSystemConfig.RAM1.Size; - map[0].m_flags = Monitor_MemoryMap_c_RAM; + map[0].m_length = HalSystemConfig.RAM1.Size; + map[0].m_flags = Monitor_MemoryMap_c_RAM; map[1].m_address = HalSystemConfig.FLASH1.Base; - map[1].m_length = HalSystemConfig.FLASH1.Size; - map[1].m_flags = Monitor_MemoryMap_c_FLASH; + map[1].m_length = HalSystemConfig.FLASH1.Size; + map[1].m_flags = Monitor_MemoryMap_c_FLASH; WP_ReplyToCommand(message, true, false, map, sizeof(map)); return true; } -int Monitor_FlashSectorMap(WP_Message* message) +int Monitor_FlashSectorMap(WP_Message *message) { - if((message->m_header.m_flags & WP_Flags_c_Reply) == 0) + if ((message->m_header.m_flags & WP_Flags_c_Reply) == 0) { struct Flash_BlockRegionInfo { @@ -344,54 +356,55 @@ int Monitor_FlashSectorMap(WP_Message* message) unsigned int rangeCount = 0; unsigned int rangeIndex = 0; - for(int cnt = 0; cnt < 2; cnt++) + for (int cnt = 0; cnt < 2; cnt++) { - BlockStorageDevice* device = BlockStorageList_GetFirstDevice(); + BlockStorageDevice *device = BlockStorageList_GetFirstDevice(); - if(device == NULL) + if (device == NULL) { WP_ReplyToCommand(message, true, false, NULL, 0); return false; } - if(cnt == 1) + if (cnt == 1) { - pData = (struct Flash_BlockRegionInfo*)platform_malloc(rangeCount * sizeof(struct Flash_BlockRegionInfo)); + pData = + (struct Flash_BlockRegionInfo *)platform_malloc(rangeCount * sizeof(struct Flash_BlockRegionInfo)); - if(pData == NULL) + if (pData == NULL) { WP_ReplyToCommand(message, true, false, NULL, 0); return false; } } - DeviceBlockInfo* deviceInfo = BlockStorageDevice_GetDeviceInfo(device); + DeviceBlockInfo *deviceInfo = BlockStorageDevice_GetDeviceInfo(device); - for(unsigned int i = 0; i < deviceInfo->NumRegions; i++) + for (unsigned int i = 0; i < deviceInfo->NumRegions; i++) { - const BlockRegionInfo* pRegion = &deviceInfo->Regions[ i ]; + const BlockRegionInfo *pRegion = &deviceInfo->Regions[i]; - for(unsigned int j = 0; j < pRegion->NumBlockRanges; j++) + for (unsigned int j = 0; j < pRegion->NumBlockRanges; j++) { - if(cnt == 0) + if (cnt == 0) { rangeCount++; } else { - pData[ rangeIndex ].StartAddress = BlockRegionInfo_BlockAddress(pRegion, pRegion->BlockRanges[ j ].StartBlock); - pData[ rangeIndex ].NumBlocks = BlockRange_GetBlockCount(pRegion->BlockRanges[j]); - pData[ rangeIndex ].BytesPerBlock = pRegion->BytesPerBlock; - pData[ rangeIndex ].Usage = pRegion->BlockRanges[ j ].RangeType & BlockRange_USAGE_MASK; + pData[rangeIndex].StartAddress = + BlockRegionInfo_BlockAddress(pRegion, pRegion->BlockRanges[j].StartBlock); + pData[rangeIndex].NumBlocks = BlockRange_GetBlockCount(pRegion->BlockRanges[j]); + pData[rangeIndex].BytesPerBlock = pRegion->BytesPerBlock; + pData[rangeIndex].Usage = pRegion->BlockRanges[j].RangeType & BlockRange_USAGE_MASK; rangeIndex++; } } } } - - WP_ReplyToCommand(message, true, false, (void*)pData, rangeCount * sizeof(struct Flash_BlockRegionInfo)); + WP_ReplyToCommand(message, true, false, (void *)pData, rangeCount * sizeof(struct Flash_BlockRegionInfo)); platform_free(pData); } diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/CLR_Startup_Thread.c b/targets/CMSIS-OS/ChibiOS/nanoCLR/CLR_Startup_Thread.c index dd6e6c97f5..d23b151ff2 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/CLR_Startup_Thread.c +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/CLR_Startup_Thread.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/CMakeLists.txt b/targets/CMSIS-OS/ChibiOS/nanoCLR/CMakeLists.txt index 824c46e23a..d090742869 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/CMakeLists.txt +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/Memory.cpp b/targets/CMSIS-OS/ChibiOS/nanoCLR/Memory.cpp index 312e8ce413..18cb76f929 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/Memory.cpp +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/Memory.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/System.Devices.Dac/sys_dev_dac_native_System_Devices_Dac_DacChannel.cpp b/targets/CMSIS-OS/ChibiOS/nanoCLR/System.Device.Dac/sys_dev_dac_native_System_Device_Dac_DacChannel.cpp similarity index 67% rename from targets/CMSIS-OS/ChibiOS/nanoCLR/System.Devices.Dac/sys_dev_dac_native_System_Devices_Dac_DacChannel.cpp rename to targets/CMSIS-OS/ChibiOS/nanoCLR/System.Device.Dac/sys_dev_dac_native_System_Device_Dac_DacChannel.cpp index ccbe64cbbc..566b75b5fb 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/System.Devices.Dac/sys_dev_dac_native_System_Devices_Dac_DacChannel.cpp +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/System.Device.Dac/sys_dev_dac_native_System_Device_Dac_DacChannel.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // @@ -14,25 +14,24 @@ // not used, just left here if needed for debugging purposes static void dacerrorcallback(DACDriver *dacp, dacerror_t err) { - (void)dacp; - (void)err; + (void)dacp; + (void)err; } #ifdef __GNUC__ #pragma GCC diagnostic pop #endif - -HRESULT Library_sys_dev_dac_native_System_Devices_Dac_DacChannel::NativeWriteValue___VOID__U2( CLR_RT_StackFrame& stack ) +HRESULT Library_sys_dev_dac_native_System_Device_Dac_DacChannel::NativeWriteValue___VOID__U2(CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); - CLR_RT_HeapBlock* dacController = NULL; + CLR_RT_HeapBlock *dacController = NULL; // we are filling this below with the appropriate DAC port pin config and DAC driver NF_PAL_DAC_PORT_PIN_CHANNEL dacDefinition; - NF_PAL_DAC* palDac; - + NF_PAL_DAC *palDac; + dacsample_t sample; int channelNumber; int controllerId; @@ -41,7 +40,8 @@ HRESULT Library_sys_dev_dac_native_System_Devices_Dac_DacChannel::NativeWriteVal sample = (dacsample_t)stack.Arg1().NumericByRef().u2; // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); // Get channel from _channelNumber field channelNumber = pThis[FIELD___channelNumber].NumericByRef().s4; @@ -51,43 +51,45 @@ HRESULT Library_sys_dev_dac_native_System_Devices_Dac_DacChannel::NativeWriteVal dacController = pThis[FIELD___dacController].Dereference(); // get pointer to _controllerId field in DacController - controllerId = dacController[Library_sys_dev_dac_native_System_Devices_Dac_DacController::FIELD___controllerId].NumericByRef().s4; + controllerId = dacController[Library_sys_dev_dac_native_System_Device_Dac_DacController::FIELD___controllerId] + .NumericByRef() + .s4; // only one DAC controller for now, but check it anyways - if(controllerId == 1) + if (controllerId == 1) { dacDefinition = DacPortPinConfig[channelNumber]; // we should remove form the build the DAC controller & channel combinations that aren't implemented // plus we have to use the default to catch invalid DAC Ids - switch(ENCODED_DAC_REF(dacDefinition.dacIndex, dacDefinition.dacChannel)) + switch (ENCODED_DAC_REF(dacDefinition.dacIndex, dacDefinition.dacChannel)) { - #if STM32_DAC_USE_DAC1_CH1 +#if STM32_DAC_USE_DAC1_CH1 case 11: palDac = &Dac1_1_PAL; break; - #endif +#endif - #if STM32_DAC_USE_DAC1_CH2 +#if STM32_DAC_USE_DAC1_CH2 case 12: palDac = &Dac1_2_PAL; break; - #endif +#endif - #if STM32_DAC_USE_DAC2_CH1 +#if STM32_DAC_USE_DAC2_CH1 case 21: palDac = &Dac2_1_PAL; break; - #endif +#endif - #if STM32_DAC_USE_DAC2_CH2 +#if STM32_DAC_USE_DAC2_CH2 case 22: palDac = &Dac2_2_PAL; break; - #endif +#endif - default: - NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); + default: + NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); } } else @@ -101,7 +103,7 @@ HRESULT Library_sys_dev_dac_native_System_Devices_Dac_DacChannel::NativeWriteVal NANOCLR_NOCLEANUP(); } -HRESULT Library_sys_dev_dac_native_System_Devices_Dac_DacChannel::NativeDispose___VOID__BOOLEAN( CLR_RT_StackFrame& stack ) +HRESULT Library_sys_dev_dac_native_System_Device_Dac_DacChannel::NativeDispose___VOID__BOOLEAN(CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); @@ -110,7 +112,8 @@ HRESULT Library_sys_dev_dac_native_System_Devices_Dac_DacChannel::NativeDispose_ bool disposeController = false; // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); // get disposeController disposeController = (bool)stack.Arg0().NumericByRef().u1; @@ -118,39 +121,39 @@ HRESULT Library_sys_dev_dac_native_System_Devices_Dac_DacChannel::NativeDispose_ // Get channel from _channelNumber field channelNumber = pThis[FIELD___channelNumber].NumericByRef().s4; - if(disposeController) + if (disposeController) { dacDefinition = DacPortPinConfig[channelNumber]; - switch(ENCODED_DAC_REF(dacDefinition.dacIndex, dacDefinition.dacChannel)) + switch (ENCODED_DAC_REF(dacDefinition.dacIndex, dacDefinition.dacChannel)) { - #if STM32_DAC_USE_DAC1_CH1 +#if STM32_DAC_USE_DAC1_CH1 case 11: dacStop(&DACD1); break; - #endif +#endif - #if STM32_DAC_USE_DAC1_CH2 +#if STM32_DAC_USE_DAC1_CH2 case 12: dacStop(&DACD2); break; - #endif +#endif - #if STM32_DAC_USE_DAC2_CH1 +#if STM32_DAC_USE_DAC2_CH1 case 21: dacStop(&DACD3); break; - #endif +#endif - #if STM32_DAC_USE_DAC2_CH2 +#if STM32_DAC_USE_DAC2_CH2 case 22: dacStop(&DACD4); break; - #endif +#endif - default: - NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); - } + default: + NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); + } } NANOCLR_NOCLEANUP(); diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/System.Devices.Dac/sys_dev_dac_native_System_Devices_Dac_DacController.cpp b/targets/CMSIS-OS/ChibiOS/nanoCLR/System.Device.Dac/sys_dev_dac_native_System_Device_Dac_DacController.cpp similarity index 64% rename from targets/CMSIS-OS/ChibiOS/nanoCLR/System.Devices.Dac/sys_dev_dac_native_System_Devices_Dac_DacController.cpp rename to targets/CMSIS-OS/ChibiOS/nanoCLR/System.Device.Dac/sys_dev_dac_native_System_Device_Dac_DacController.cpp index 6206f38631..cfdeb6b9c8 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/System.Devices.Dac/sys_dev_dac_native_System_Devices_Dac_DacController.cpp +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/System.Device.Dac/sys_dev_dac_native_System_Device_Dac_DacController.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // @@ -22,69 +22,71 @@ NF_PAL_DAC Dac2_1_PAL; NF_PAL_DAC Dac2_2_PAL; #endif -HRESULT Library_sys_dev_dac_native_System_Devices_Dac_DacController::NativeOpenChannel___VOID__I4( CLR_RT_StackFrame& stack ) +HRESULT Library_sys_dev_dac_native_System_Device_Dac_DacController::NativeOpenChannel___VOID__I4( + CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); - + // we are filling this below with the appropriate ADC port pin config and ADC driver NF_PAL_DAC_PORT_PIN_CHANNEL dacDefinition; - NF_PAL_DAC* palDac; + NF_PAL_DAC *palDac; int controllerId; // Get channel from argument int channel = stack.Arg1().NumericByRef().s4; // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); // get controller ID controllerId = pThis[FIELD___controllerId].NumericByRef().s4; // only one DAC controller for now, but check it anyways - if(controllerId == 1) + if (controllerId == 1) { dacDefinition = DacPortPinConfig[channel]; - switch(ENCODED_DAC_REF(dacDefinition.dacIndex, dacDefinition.dacChannel)) + switch (ENCODED_DAC_REF(dacDefinition.dacIndex, dacDefinition.dacChannel)) { - #if STM32_DAC_USE_DAC1_CH1 +#if STM32_DAC_USE_DAC1_CH1 case 11: Dac1_1_PAL.Driver = &DACD1; palDac = &Dac1_1_PAL; // unlike STM documentation, ChibiOS uses a 0 index for DAC channels palDac->Channel = 1 - 1; break; - #endif +#endif - #if STM32_DAC_USE_DAC1_CH2 +#if STM32_DAC_USE_DAC1_CH2 case 12: Dac1_2_PAL.Driver = &DACD2; palDac = &Dac1_2_PAL; // unlike STM documentation, ChibiOS uses a 0 index for DAC channels palDac->Channel = 2 - 1; break; - #endif +#endif - #if STM32_DAC_USE_DAC2_CH1 +#if STM32_DAC_USE_DAC2_CH1 case 21: Dac2_1_PAL.Driver = &DACD3; palDac = &Dac2_1_PAL; // unlike STM documentation, ChibiOS uses a 0 index for DAC channels palDac->Channel = 1 - 1; break; - #endif +#endif - #if STM32_DAC_USE_DAC2_CH2 +#if STM32_DAC_USE_DAC2_CH2 case 22: Dac2_2_PAL.Driver = &DACD4; palDac = &Dac2_2_PAL; // unlike STM documentation, ChibiOS uses a 0 index for DAC channels palDac->Channel = 2 - 1; break; - #endif +#endif - default: - NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); + default: + NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); } } else @@ -93,9 +95,9 @@ HRESULT Library_sys_dev_dac_native_System_Devices_Dac_DacController::NativeOpenC } // start DAC driver if it's not already started - if(palDac->Driver->state < DAC_READY) + if (palDac->Driver->state < DAC_READY) { - if(dacDefinition.portId != NULL) + if (dacDefinition.portId != NULL) { palSetPadMode(dacDefinition.portId, dacDefinition.pin, PAL_MODE_INPUT_ANALOG); } @@ -103,9 +105,9 @@ HRESULT Library_sys_dev_dac_native_System_Devices_Dac_DacController::NativeOpenC // set DAC config: 12 bits data mode, others registers to defaults memset(&palDac->Config, 0, sizeof(DACConfig)); - palDac->Config.init = 0; - palDac->Config.datamode = DAC_DHRM_12BIT_RIGHT; - palDac->Config.cr = 0; + palDac->Config.init = 0; + palDac->Config.datamode = DAC_DHRM_12BIT_RIGHT; + palDac->Config.cr = 0; // start DAC dacStart(palDac->Driver, &palDac->Config); @@ -114,33 +116,35 @@ HRESULT Library_sys_dev_dac_native_System_Devices_Dac_DacController::NativeOpenC NANOCLR_NOCLEANUP(); } -HRESULT Library_sys_dev_dac_native_System_Devices_Dac_DacController::NativeGetChannelCount___I4( CLR_RT_StackFrame& stack ) +HRESULT Library_sys_dev_dac_native_System_Device_Dac_DacController::NativeGetChannelCount___I4(CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); int channelCount; int controllerId; - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); - controllerId = pThis[ FIELD___controllerId ].NumericByRefConst().s4; + controllerId = pThis[FIELD___controllerId].NumericByRefConst().s4; - switch(controllerId) + switch (controllerId) { - case 1: + case 1: channelCount = DacChannelCount; break; - default: + default: NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); } - + // Return value to the managed application stack.SetResult_I4(channelCount); NANOCLR_NOCLEANUP(); } -HRESULT Library_sys_dev_dac_native_System_Devices_Dac_DacController::NativeGetResolutionInBits___I4( CLR_RT_StackFrame& stack ) +HRESULT Library_sys_dev_dac_native_System_Device_Dac_DacController::NativeGetResolutionInBits___I4( + CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); { @@ -150,39 +154,42 @@ HRESULT Library_sys_dev_dac_native_System_Devices_Dac_DacController::NativeGetRe NANOCLR_NOCLEANUP_NOLABEL(); } -HRESULT Library_sys_dev_dac_native_System_Devices_Dac_DacController::NativeInit___VOID( CLR_RT_StackFrame& stack ) +HRESULT Library_sys_dev_dac_native_System_Device_Dac_DacController::NativeInit___VOID(CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); int controllerId; // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); // get pointer to _controllerId field in DacController controllerId = pThis[FIELD___controllerId].NumericByRef().s4; // all required initialization for DAC is already handled in ChibiOS driver - switch(controllerId) + switch (controllerId) { - case 1: + case 1: break; - default: + default: NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); } NANOCLR_NOCLEANUP(); } -HRESULT Library_sys_dev_dac_native_System_Devices_Dac_DacController::GetDeviceSelector___STATIC__STRING( CLR_RT_StackFrame& stack ) +HRESULT Library_sys_dev_dac_native_System_Device_Dac_DacController::GetDeviceSelector___STATIC__STRING( + CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); { - // because the caller is expecting a result to be returned - // we need set a return result in the stack argument using the appropriate SetResult according to the variable type (a string here) - stack.SetResult_String("DAC1"); + // because the caller is expecting a result to be returned + // we need set a return result in the stack argument using the appropriate SetResult according to the variable + // type (a string here) + stack.SetResult_String("DAC1"); } NANOCLR_NOCLEANUP_NOLABEL(); } diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/System.Devices.Dac/sys_dev_dac_native_target.h b/targets/CMSIS-OS/ChibiOS/nanoCLR/System.Device.Dac/sys_dev_dac_native_target.h similarity index 74% rename from targets/CMSIS-OS/ChibiOS/nanoCLR/System.Devices.Dac/sys_dev_dac_native_target.h rename to targets/CMSIS-OS/ChibiOS/nanoCLR/System.Device.Dac/sys_dev_dac_native_target.h index a237eadb52..7145bd89f4 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/System.Devices.Dac/sys_dev_dac_native_target.h +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/System.Device.Dac/sys_dev_dac_native_target.h @@ -1,9 +1,8 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // - #ifndef _SYS_DEV_DAC_NATIVE_TARGET_H_ #define _SYS_DEV_DAC_NATIVE_TARGET_H_ @@ -14,25 +13,25 @@ struct NF_PAL_DAC_PORT_PIN_CHANNEL { // Index of DAC converter // on most STM32 devices can be converter 1 or 2 - uint8_t dacIndex; + uint8_t dacIndex; // DAC channel // on most STM32 devices can be channel 1 or 2 - uint8_t dacChannel; + uint8_t dacChannel; // GPIO port ID - stm32_gpio_t* portId; + stm32_gpio_t *portId; // GPIO pin of the DAC channel - uint8_t pin; + uint8_t pin; }; -// struct representing the DAC controller +// struct representing the DAC controller struct NF_PAL_DAC { - DACDriver* Driver; - DACConfig Config; - uint8_t Channel; + DACDriver *Driver; + DACConfig Config; + uint8_t Channel; }; //////////////////////////////////////////// @@ -51,14 +50,12 @@ extern NF_PAL_DAC Dac2_1_PAL; extern NF_PAL_DAC Dac2_2_PAL; #endif - // there is a driver for each pair DAC converter + channel // let's code the options with DAC controller on the tens place and the channel on the ones place // like this: channel 2 of DAC controller 1 being => (1 * 10) + 12 = 12 -#define ENCODED_DAC_REF( dac, channel) (dac * 10 + channel) - +#define ENCODED_DAC_REF(dac, channel) (dac * 10 + channel) extern const NF_PAL_DAC_PORT_PIN_CHANNEL DacPortPinConfig[]; extern const int DacChannelCount; -#endif //_SYS_DEV_DAC_NATIVE_TARGET_H_ +#endif //_SYS_DEV_DAC_NATIVE_TARGET_H_ diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.Adc/win_dev_adc_native_Windows_Devices_Adc_AdcChannel.cpp b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.Adc/win_dev_adc_native_Windows_Devices_Adc_AdcChannel.cpp index 9d7d04faf6..9b47dd6a3d 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.Adc/win_dev_adc_native_Windows_Devices_Adc_AdcChannel.cpp +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.Adc/win_dev_adc_native_Windows_Devices_Adc_AdcChannel.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.Adc/win_dev_adc_native_Windows_Devices_Adc_AdcController.cpp b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.Adc/win_dev_adc_native_Windows_Devices_Adc_AdcController.cpp index 7b9671cc68..44224f10fa 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.Adc/win_dev_adc_native_Windows_Devices_Adc_AdcController.cpp +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.Adc/win_dev_adc_native_Windows_Devices_Adc_AdcController.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.Adc/win_dev_adc_native_target.h b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.Adc/win_dev_adc_native_target.h index e2cdb6667b..e9591aff2b 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.Adc/win_dev_adc_native_target.h +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.Adc/win_dev_adc_native_target.h @@ -1,24 +1,23 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // - #ifndef _WIN_DEV_ADC_NATIVE_TARGET_H_ #define _WIN_DEV_ADC_NATIVE_TARGET_H_ #include #include -struct NF_PAL_ADC_PORT_PIN_CHANNEL +typedef struct { - uint8_t adcIndex; - stm32_gpio_t* portId; - uint8_t pin; - uint32_t adcChannel; -}; + uint8_t adcIndex; + stm32_gpio_t *portId; + uint8_t pin; + uint32_t adcChannel; +} NF_PAL_ADC_PORT_PIN_CHANNEL; extern const NF_PAL_ADC_PORT_PIN_CHANNEL AdcPortPinConfig[]; extern const int AdcChannelCount; -#endif //_WIN_DEV_ADC_NATIVE_TARGET_H_ +#endif //_WIN_DEV_ADC_NATIVE_TARGET_H_ diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.Gpio/cpu_gpio.cpp b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.Gpio/cpu_gpio.cpp index 1236fcfa6e..a28655cce3 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.Gpio/cpu_gpio.cpp +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.Gpio/cpu_gpio.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // @@ -10,305 +10,319 @@ #include #include "win_dev_gpio_native_target.h" - -//volatile uint16_t lastPadValue; - - -#define GPIO_MAX_PIN 256 -#define TOTAL_GPIO_PORTS ((GPIO_MAX_PIN + 15) / 16) +#define GPIO_MAX_PIN 256 +#define TOTAL_GPIO_PORTS ((GPIO_MAX_PIN + 15) / 16) // Double linkedlist to hold the state of each Input pin struct gpio_input_state : public HAL_DblLinkedNode { - GPIO_PIN pinNumber; // Pin number - virtual_timer_t debounceTimer; // debounce timer for this Pin - GPIO_INTERRUPT_SERVICE_ROUTINE isrPtr; // Ptr to user ISR or null - uint32_t debounceMs; // debounce Millsecs, no debonce=0 - uint8_t mode; // Interrupt mode - void * param; // Param to user isr call - bool expected; // Expected state for debounce handler - bool waitingDebounce; // True if waiting for debounce timer to complete + GPIO_PIN pinNumber; // Pin number + virtual_timer_t debounceTimer; // debounce timer for this Pin + GPIO_INTERRUPT_SERVICE_ROUTINE isrPtr; // Ptr to user ISR or null + uint32_t debounceMs; // debounce Millsecs, no debonce=0 + uint8_t mode; // Interrupt mode + void *param; // Param to user isr call + bool expected; // Expected state for debounce handler + bool waitingDebounce; // True if waiting for debounce timer to complete }; -static HAL_DblLinkedList gpioInputList; // Double Linked list for GPIO input status -static uint16_t pinReserved[TOTAL_GPIO_PORTS]; // reserved - 1 bit per pin - +static HAL_DblLinkedList gpioInputList; // Double Linked list for GPIO input status +static uint16_t pinReserved[TOTAL_GPIO_PORTS]; // reserved - 1 bit per pin // this is an utility function to get a ChibiOS PAL IoLine from our "encoded" pin number static ioline_t GetIoLine(int16_t pinNumber) { - stm32_gpio_t* port = GPIO_PORT(pinNumber); - int16_t pad = pinNumber % 16; - - return PAL_LINE(port, pad); + stm32_gpio_t *port = GPIO_PORT(pinNumber); + int16_t pad = pinNumber % 16; + return PAL_LINE(port, pad); } -bool IsValidGpioPin(GPIO_PIN pinNumber) +bool IsValidGpioPin(GPIO_PIN pinNumber) { - return (pinNumber <= GPIO_MAX_PIN); + return (pinNumber <= GPIO_MAX_PIN); } -static void debounceTimer_Callback(void* arg) +static void DebounceTimerCallback(void *arg) { - gpio_input_state* pState = (gpio_input_state*)arg; - if (pState->isrPtr) - { - // get current pin state - bool actual = palReadLine(GetIoLine(pState->pinNumber)); - if (actual == pState->expected) - { - pState->isrPtr(pState->pinNumber, actual, pState->param); - if (pState->mode == GPIO_INT_EDGE_BOTH) - { - // both edges - pState->expected ^= 1; // update expected state - } - } - } - - pState->waitingDebounce = false; + gpio_input_state *pState = (gpio_input_state *)arg; + + // get current pin state + bool actual = palReadLine(GetIoLine(pState->pinNumber)); + if (actual == pState->expected) + { + pState->isrPtr(pState->pinNumber, actual); + if (pState->mode == GPIO_INT_EDGE_BOTH) + { + // both edges + pState->expected ^= 1; // update expected state + } + } + + pState->waitingDebounce = false; } - static void GpioEventCallback(void *arg) { - NATIVE_INTERRUPT_START + NATIVE_INTERRUPT_START - chSysLockFromISR(); + chSysLockFromISR(); - gpio_input_state * pGpio = (gpio_input_state *)arg; + gpio_input_state *pGpio = (gpio_input_state *)arg; - // Ignore any pin changes during debounce - if (pGpio->waitingDebounce) - { - chSysUnlockFromISR(); - return; - } + // Ignore any pin changes during debounce + if (pGpio->waitingDebounce) + { + chSysUnlockFromISR(); + return; + } - // check if there is a debounce time set - if (pGpio->debounceMs > 0) - { - // Set flag we are waiting for debounce on this pin - pGpio->waitingDebounce = true; + // check if there is a debounce time set + if (pGpio->debounceMs > 0) + { + // Set flag we are waiting for debounce on this pin + pGpio->waitingDebounce = true; - // setup timer - chVTSetI(&pGpio->debounceTimer, TIME_MS2I(pGpio->debounceMs), debounceTimer_Callback, pGpio); - } - else - { - // get IoLine from pin number - ioline_t ioLine = GetIoLine(pGpio->pinNumber); + // setup timer + chVTSetI(&pGpio->debounceTimer, TIME_MS2I(pGpio->debounceMs), DebounceTimerCallback, pGpio); + } + else + { + // get IoLine from pin number + ioline_t ioLine = GetIoLine(pGpio->pinNumber); - chSysUnlockFromISR(); - pGpio->isrPtr(pGpio->pinNumber, palReadLine(ioLine), pGpio->param); - chSysLockFromISR(); - } + chSysUnlockFromISR(); + pGpio->isrPtr(pGpio->pinNumber, palReadLine(ioLine)); + chSysLockFromISR(); + } - chSysUnlockFromISR(); + chSysUnlockFromISR(); - NATIVE_INTERRUPT_END + NATIVE_INTERRUPT_END } - - // Get pointer to gpio_input_state for Gpio pin // return NULL if not found -gpio_input_state * GetInputState(GPIO_PIN pinNumber) +gpio_input_state *GetInputState(GPIO_PIN pinNumber) { - gpio_input_state * ptr = gpioInputList.FirstNode(); - while (ptr->Next() != NULL) - { - if (ptr->pinNumber == pinNumber) return ptr; - ptr = ptr->Next(); - } - return NULL; + gpio_input_state *ptr = gpioInputList.FirstNode(); + while (ptr->Next() != NULL) + { + if (ptr->pinNumber == pinNumber) + return ptr; + ptr = ptr->Next(); + } + return NULL; } // Allocate a new gpio_input_state and add to end of list // if already exist then just return current ptr -gpio_input_state * AllocateGpioInputState(GPIO_PIN pinNumber) +gpio_input_state *AllocateGpioInputState(GPIO_PIN pinNumber) { - gpio_input_state * ptr = GetInputState(pinNumber); - - if (ptr == NULL) - { - ptr = (gpio_input_state *)platform_malloc(sizeof(gpio_input_state)); + gpio_input_state *ptr = GetInputState(pinNumber); - // sanity check - if(ptr != NULL) - { - memset(ptr, 0, sizeof(gpio_input_state)); - ptr->pinNumber = pinNumber; + if (ptr == NULL) + { + ptr = (gpio_input_state *)platform_malloc(sizeof(gpio_input_state)); - chVTObjectInit(&ptr->debounceTimer); + // sanity check + if (ptr != NULL) + { + memset(ptr, 0, sizeof(gpio_input_state)); + ptr->pinNumber = pinNumber; - gpioInputList.LinkAtBack(ptr); - } - } + chVTObjectInit(&ptr->debounceTimer); - return ptr; + gpioInputList.LinkAtBack(ptr); + } + } + + return ptr; } -void UnlinkInputState(gpio_input_state * pState) +void UnlinkInputState(gpio_input_state *pState) { - chVTReset(&pState->debounceTimer); + chVTReset(&pState->debounceTimer); - // disable the EXT interrupt channel - // it's OK to do always this, no matter if it's enabled or not - palDisableLineEvent(GetIoLine(pState->pinNumber)); + // disable the EXT interrupt channel + // it's OK to do always this, no matter if it's enabled or not + palDisableLineEvent(GetIoLine(pState->pinNumber)); - pState->Unlink(); - platform_free(pState); + pState->Unlink(); + platform_free(pState); } // Delete gpio_input_state from List and tidy up ( Timer & ISR handler ) void DeleteInputState(GPIO_PIN pinNumber) { - gpio_input_state * pState = GetInputState(pinNumber); - if (pState) - { - UnlinkInputState(pState); - } + gpio_input_state *pState = GetInputState(pinNumber); + if (pState) + { + UnlinkInputState(pState); + } } -bool CPU_GPIO_Initialize() +bool CPU_GPIO_Initialize() { - // Initialise Double linked list for input pin states - gpioInputList.Initialize(); + // Initialise Double linked list for input pin states + gpioInputList.Initialize(); - // Make sure all pins are not reserved - memset(pinReserved, 0, sizeof(pinReserved)); + // Make sure all pins are not reserved + memset(pinReserved, 0, sizeof(pinReserved)); - return true; + return true; } -bool CPU_GPIO_Uninitialize() +bool CPU_GPIO_Uninitialize() { - NANOCLR_FOREACH_NODE(gpio_input_state, pGpio, gpioInputList) - { - UnlinkInputState(pGpio); - } - NANOCLR_FOREACH_NODE_END(); + NANOCLR_FOREACH_NODE(gpio_input_state, pGpio, gpioInputList) + { + UnlinkInputState(pGpio); + } + NANOCLR_FOREACH_NODE_END(); - return true; + return true; } // Set/reset reserved state of pin -bool CPU_GPIO_ReservePin(GPIO_PIN pinNumber, bool fReserve) +bool CPU_GPIO_ReservePin(GPIO_PIN pinNumber, bool fReserve) { - // Check if valid pin number - if (!IsValidGpioPin(pinNumber)) return false; - - int port = pinNumber >> 4, bit = 1 << (pinNumber & 0x0F); - bool ret = true; - GLOBAL_LOCK(); - - if (fReserve) - { - if (pinReserved[port] & bit) - { - ret = false; // already reserved - } - else - { - pinReserved[port] |= bit; - } - } - else - { - pinReserved[port] &= ~bit; - } - - GLOBAL_UNLOCK(); - return ret; + // Check if valid pin number + if (!IsValidGpioPin(pinNumber)) + return false; + + int port = pinNumber >> 4, bit = 1 << (pinNumber & 0x0F); + bool ret = true; + GLOBAL_LOCK(); + + if (fReserve) + { + if (pinReserved[port] & bit) + { + ret = false; // already reserved + } + else + { + pinReserved[port] |= bit; + } + } + else + { + pinReserved[port] &= ~bit; + } + + GLOBAL_UNLOCK(); + return ret; } // Return if Pin is reserved bool CPU_GPIO_PinIsBusy(GPIO_PIN pinNumber) { - // Check if valid pin number - if (!IsValidGpioPin(pinNumber)) return false; + // Check if valid pin number + if (!IsValidGpioPin(pinNumber)) + return false; - int port = pinNumber >> 4, sh = pinNumber & 0x0F; - return (pinReserved[port] >> sh) & 1; + int port = pinNumber >> 4, sh = pinNumber & 0x0F; + return (pinReserved[port] >> sh) & 1; } // Return maximum number of pins int32_t CPU_GPIO_GetPinCount() { - return GPIO_MAX_PIN; + return GPIO_MAX_PIN; } // Get current state of pin GpioPinValue CPU_GPIO_GetPinState(GPIO_PIN pin) { - return (GpioPinValue)palReadLine(GetIoLine(pin)); + return (GpioPinValue)palReadLine(GetIoLine(pin)); } // Set Pin state void CPU_GPIO_SetPinState(GPIO_PIN pin, GpioPinValue PinState) { - palWriteLine(GetIoLine(pin), (int)PinState); + palWriteLine(GetIoLine(pin), (int)PinState); } -bool CPU_GPIO_EnableInputPin(GPIO_PIN pinNumber, CLR_UINT64 debounceTimeMilliseconds, GPIO_INTERRUPT_SERVICE_ROUTINE pin_ISR, void* isr_Param, GPIO_INT_EDGE intEdge, GpioPinDriveMode driveMode) +bool CPU_GPIO_EnableInputPin( + GPIO_PIN pinNumber, + CLR_UINT64 debounceTimeMilliseconds, + GPIO_INTERRUPT_SERVICE_ROUTINE pinISR, + void *isrParam, + GPIO_INT_EDGE intEdge, + GpioPinDriveMode driveMode) { - gpio_input_state * pState; - - // Check Input drive mode - if (driveMode >= (int)GpioPinDriveMode_Output) - { - return false; - } - - // Set as Input GPIO_INT_EDGE intEdge, GPIO_RESISTOR ResistorState - if (!CPU_GPIO_SetDriveMode(pinNumber, driveMode)) - { - return false; - } - pState = AllocateGpioInputState(pinNumber); - - // Link ISR ptr supplied and not already set up - // CPU_GPIO_EnableInputPin could be called a 2nd time with changed parameters - if ((pin_ISR != NULL) && (pState->isrPtr == NULL)) - { - // there are callbacks registered and... - // the drive mode is input so need to setup the interrupt - - // get IoLine from pin number - ioline_t ioLine = GetIoLine(pinNumber); - - palEnableLineEvent(ioLine, PAL_EVENT_MODE_BOTH_EDGES); - palSetLineCallback(ioLine, GpioEventCallback, pState); - } - - pState->isrPtr = pin_ISR; - pState->mode = intEdge; - pState->param = (void *)isr_Param; - pState->debounceMs = (uint32_t)(debounceTimeMilliseconds); - - switch (intEdge) - { - case GPIO_INT_EDGE_LOW: - case GPIO_INT_LEVEL_LOW: - pState->expected = PAL_LOW; - break; - - case GPIO_INT_EDGE_HIGH: - case GPIO_INT_LEVEL_HIGH: - pState->expected = PAL_HIGH; - break; - - case GPIO_INT_EDGE_BOTH: - pState->expected = !CPU_GPIO_GetPinState(pinNumber); // expected NOT current state - break; - - default: - break; - } - - return true; + gpio_input_state *pState; + + // Check Input drive mode + if (driveMode >= (int)GpioPinDriveMode_Output) + { + return false; + } + + // Set as Input GPIO_INT_EDGE intEdge, GPIO_RESISTOR ResistorState + if (!CPU_GPIO_SetDriveMode(pinNumber, driveMode)) + { + return false; + } + + pState = AllocateGpioInputState(pinNumber); + + // Link ISR ptr supplied and not already set up + // CPU_GPIO_EnableInputPin could be called a 2nd time with changed parameters + if (pinISR != NULL && (pState->isrPtr == NULL)) + { + // there are callbacks registered and... + // the drive mode is input so need to setup the interrupt + + // get IoLine from pin number + ioline_t ioLine = GetIoLine(pinNumber); + + palEnableLineEvent(ioLine, PAL_EVENT_MODE_BOTH_EDGES); + palSetLineCallback(ioLine, GpioEventCallback, pState); + + // store parameters & configs + pState->isrPtr = pinISR; + pState->mode = intEdge; + pState->param = (void *)isrParam; + pState->debounceMs = (uint32_t)(debounceTimeMilliseconds); + + switch (intEdge) + { + case GPIO_INT_EDGE_LOW: + case GPIO_INT_LEVEL_LOW: + pState->expected = PAL_LOW; + break; + + case GPIO_INT_EDGE_HIGH: + case GPIO_INT_LEVEL_HIGH: + pState->expected = PAL_HIGH; + break; + + case GPIO_INT_EDGE_BOTH: + pState->expected = !CPU_GPIO_GetPinState(pinNumber); // expected NOT current state + break; + + default: + break; + } + } + else if (pinISR == NULL && (pState->isrPtr != NULL)) + { + // there is no managed handler setup anymore + + // disable the EXT interrupt channel + // it's OK to do always this, no matter if it's enabled or not + palDisableLineEvent(GetIoLine(pState->pinNumber)); + + // clear parameters & configs + pState->isrPtr = NULL; + pState->mode = GPIO_INT_NONE; + pState->param = NULL; + pState->debounceMs = 0; + } + + return true; } // Enable an output pin @@ -318,113 +332,112 @@ bool CPU_GPIO_EnableInputPin(GPIO_PIN pinNumber, CLR_UINT64 debounceTimeMillisec // driveMode - Drive mode and resistors // return - True if succesful, false invalid pin, pin not putput, invalid drive mode for ouptput // -bool CPU_GPIO_EnableOutputPin(GPIO_PIN pinNumber, GpioPinValue InitialState, GpioPinDriveMode driveMode) +bool CPU_GPIO_EnableOutputPin(GPIO_PIN pinNumber, GpioPinValue InitialState, GpioPinDriveMode driveMode) { - // check not an output drive mode - if (driveMode < (int)GpioPinDriveMode_Output) return false; + // check not an output drive mode + if (driveMode < (int)GpioPinDriveMode_Output) + return false; - // If this is currently an input pin then clean up - DeleteInputState(pinNumber); + // If this is currently an input pin then clean up + DeleteInputState(pinNumber); - if (CPU_GPIO_SetDriveMode(pinNumber, driveMode) == false) return false; + if (CPU_GPIO_SetDriveMode(pinNumber, driveMode) == false) + return false; - CPU_GPIO_SetPinState(pinNumber, InitialState); + CPU_GPIO_SetPinState(pinNumber, InitialState); - return true; + return true; } - void CPU_GPIO_DisablePin(GPIO_PIN pinNumber, GpioPinDriveMode driveMode, uint32_t alternateFunction) { - DeleteInputState(pinNumber); + DeleteInputState(pinNumber); - GLOBAL_LOCK(); + GLOBAL_LOCK(); - CPU_GPIO_SetDriveMode(pinNumber, driveMode); + CPU_GPIO_SetDriveMode(pinNumber, driveMode); - // get IoLine from pin number - ioline_t ioLine = GetIoLine(pinNumber); - palSetLineMode(ioLine, PAL_MODE_ALTERNATE(alternateFunction)); + // get IoLine from pin number + ioline_t ioLine = GetIoLine(pinNumber); + palSetLineMode(ioLine, PAL_MODE_ALTERNATE(alternateFunction)); - GLOBAL_UNLOCK(); + GLOBAL_UNLOCK(); - CPU_GPIO_ReservePin(pinNumber, false); + CPU_GPIO_ReservePin(pinNumber, false); } // Validate pin and set drive mode // return true if ok bool CPU_GPIO_SetDriveMode(GPIO_PIN pinNumber, GpioPinDriveMode driveMode) { - // get IoLine from pin number - ioline_t ioLine = GetIoLine(pinNumber); + // get IoLine from pin number + ioline_t ioLine = GetIoLine(pinNumber); - switch (driveMode) - { - case GpioPinDriveMode_Input: - palSetLineMode(ioLine, PAL_MODE_INPUT); - break; + switch (driveMode) + { + case GpioPinDriveMode_Input: + palSetLineMode(ioLine, PAL_MODE_INPUT); + break; - case GpioPinDriveMode_InputPullDown: - palSetLineMode(ioLine, PAL_MODE_INPUT_PULLDOWN); - break; + case GpioPinDriveMode_InputPullDown: + palSetLineMode(ioLine, PAL_MODE_INPUT_PULLDOWN); + break; - case GpioPinDriveMode_InputPullUp: - palSetLineMode(ioLine, PAL_MODE_INPUT_PULLUP); - break; + case GpioPinDriveMode_InputPullUp: + palSetLineMode(ioLine, PAL_MODE_INPUT_PULLUP); + break; - case GpioPinDriveMode_Output: - palSetLineMode(ioLine, PAL_MODE_OUTPUT_PUSHPULL); - break; + case GpioPinDriveMode_Output: + palSetLineMode(ioLine, PAL_MODE_OUTPUT_PUSHPULL); + break; - case GpioPinDriveMode_OutputOpenDrain: - palSetLineMode(ioLine, PAL_MODE_OUTPUT_OPENDRAIN); - break; + case GpioPinDriveMode_OutputOpenDrain: + palSetLineMode(ioLine, PAL_MODE_OUTPUT_OPENDRAIN); + break; - default: - // all other modes are NOT supported - return false; - } + default: + // all other modes are NOT supported + return false; + } - return true; + return true; } bool CPU_GPIO_DriveModeSupported(GPIO_PIN pinNumber, GpioPinDriveMode driveMode) { - (void)pinNumber; + (void)pinNumber; - bool driveModeSupported = false; + bool driveModeSupported = false; - // check if the requested drive mode is support by ChibiOS config - if ((driveMode == GpioPinDriveMode_Input) || - (driveMode == GpioPinDriveMode_InputPullDown) || - (driveMode == GpioPinDriveMode_InputPullUp) || - (driveMode == GpioPinDriveMode_Output) || - (driveMode == GpioPinDriveMode_OutputOpenDrain)) - { - driveModeSupported = true; - } + // check if the requested drive mode is support by ChibiOS config + if ((driveMode == GpioPinDriveMode_Input) || (driveMode == GpioPinDriveMode_InputPullDown) || + (driveMode == GpioPinDriveMode_InputPullUp) || (driveMode == GpioPinDriveMode_Output) || + (driveMode == GpioPinDriveMode_OutputOpenDrain)) + { + driveModeSupported = true; + } - return driveModeSupported; + return driveModeSupported; } uint32_t CPU_GPIO_GetPinDebounce(GPIO_PIN pinNumber) { - gpio_input_state * ptr = GetInputState(pinNumber); - if (ptr) - { - return ptr->debounceMs; - } + gpio_input_state *ptr = GetInputState(pinNumber); + if (ptr) + { + return ptr->debounceMs; + } - return 0; + return 0; } bool CPU_GPIO_SetPinDebounce(GPIO_PIN pinNumber, CLR_UINT64 debounceTimeMilliseconds) { - gpio_input_state * ptr = GetInputState(pinNumber); - if (ptr) - { - ptr->debounceMs = (uint32_t)(debounceTimeMilliseconds); - return true; - } - return false; + gpio_input_state *ptr = GetInputState(pinNumber); + if (ptr) + { + ptr->debounceMs = (uint32_t)(debounceTimeMilliseconds); + return true; + } + return false; } diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.Gpio/win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter.cpp b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.Gpio/win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter.cpp index 9fc3521839..46d9716912 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.Gpio/win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter.cpp +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.Gpio/win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.Gpio/win_dev_gpio_native_target.h b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.Gpio/win_dev_gpio_native_target.h index 991e00d6ac..93dcc20789 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.Gpio/win_dev_gpio_native_target.h +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.Gpio/win_dev_gpio_native_target.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.I2c/win_dev_i2c_native_Windows_Devices_I2C_I2cDevice.cpp b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.I2c/win_dev_i2c_native_Windows_Devices_I2C_I2cDevice.cpp index 913b541370..882031a997 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.I2c/win_dev_i2c_native_Windows_Devices_I2C_I2cDevice.cpp +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.I2c/win_dev_i2c_native_Windows_Devices_I2C_I2cDevice.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // @@ -16,30 +16,36 @@ typedef Library_win_dev_i2c_native_Windows_Devices_I2c_I2cConnectionSettings I2c // I2C PAL strucs declared in win_dev_i2c_native.h // ///////////////////////////////////////////////////// #if STM32_I2C_USE_I2C1 - NF_PAL_I2C I2C1_PAL; +NF_PAL_I2C I2C1_PAL; #endif #if STM32_I2C_USE_I2C2 - NF_PAL_I2C I2C2_PAL; +NF_PAL_I2C I2C2_PAL; #endif #if STM32_I2C_USE_I2C3 - NF_PAL_I2C I2C3_PAL; +NF_PAL_I2C I2C3_PAL; #endif #if STM32_I2C_USE_I2C4 - NF_PAL_I2C I2C4_PAL; +NF_PAL_I2C I2C4_PAL; #endif - // ChibiOS I2C working thread static THD_FUNCTION(I2CWorkingThread, arg) { - NF_PAL_I2C* palI2c = (NF_PAL_I2C*)arg; + NF_PAL_I2C *palI2c = (NF_PAL_I2C *)arg; msg_t result; int estimatedDurationMiliseconds = palI2c->ByteTime * (palI2c->WriteSize + palI2c->ReadSize + 1); if (palI2c->ReadSize != 0 && palI2c->WriteSize != 0) { // this is a Write/Read transaction - result = i2cMasterTransmitTimeout(palI2c->Driver, palI2c->Address, palI2c->WriteBuffer, palI2c->WriteSize, palI2c->ReadBuffer, palI2c->ReadSize, TIME_MS2I(estimatedDurationMiliseconds)); + result = i2cMasterTransmitTimeout( + palI2c->Driver, + palI2c->Address, + palI2c->WriteBuffer, + palI2c->WriteSize, + palI2c->ReadBuffer, + palI2c->ReadSize, + TIME_MS2I(estimatedDurationMiliseconds)); } else { @@ -49,7 +55,14 @@ static THD_FUNCTION(I2CWorkingThread, arg) estimatedDurationMiliseconds = palI2c->ByteTime * (palI2c->WriteSize + 1); - result = i2cMasterTransmitTimeout(palI2c->Driver, palI2c->Address, palI2c->WriteBuffer, palI2c->WriteSize, NULL, 0, TIME_MS2I(estimatedDurationMiliseconds)); + result = i2cMasterTransmitTimeout( + palI2c->Driver, + palI2c->Address, + palI2c->WriteBuffer, + palI2c->WriteSize, + NULL, + 0, + TIME_MS2I(estimatedDurationMiliseconds)); } else { @@ -57,7 +70,12 @@ static THD_FUNCTION(I2CWorkingThread, arg) estimatedDurationMiliseconds = palI2c->ByteTime * (palI2c->ReadSize + 1); - result = i2cMasterReceiveTimeout (palI2c->Driver, palI2c->Address, palI2c->ReadBuffer, palI2c->ReadSize, TIME_MS2I(estimatedDurationMiliseconds)); + result = i2cMasterReceiveTimeout( + palI2c->Driver, + palI2c->Address, + palI2c->ReadBuffer, + palI2c->ReadSize, + TIME_MS2I(estimatedDurationMiliseconds)); } } @@ -67,20 +85,19 @@ static THD_FUNCTION(I2CWorkingThread, arg) chThdExit(result); } -void GetI2cConfig(CLR_RT_HeapBlock* managedConfig, I2CConfig* llConfig) +void GetI2cConfig(CLR_RT_HeapBlock *managedConfig, I2CConfig *llConfig) { - I2cBusSpeed busSpeed = (I2cBusSpeed)managedConfig[ I2cConnectionSettings::FIELD___busSpeed ].NumericByRef().s4; + I2cBusSpeed busSpeed = (I2cBusSpeed)managedConfig[I2cConnectionSettings::FIELD___busSpeed].NumericByRef().s4; - // set the LL I2C configuration (according to I2C driver version) - #if defined(STM32F1XX) || defined(STM32F4XX) || defined(STM32L1XX) +// set the LL I2C configuration (according to I2C driver version) +#if defined(STM32F1XX) || defined(STM32F4XX) || defined(STM32L1XX) llConfig->op_mode = OPMODE_I2C; llConfig->clock_speed = busSpeed == I2cBusSpeed_StandardMode ? 100000U : 400000U; llConfig->duty_cycle = busSpeed == I2cBusSpeed_StandardMode ? STD_DUTY_CYCLE : FAST_DUTY_CYCLE_2; - #elif defined(STM32F7XX) || defined(STM32F3XX) || defined(STM32F0XX) || \ - defined(STM32L0XX) || defined(STM32L4XX) || \ - defined(STM32H7XX) +#elif defined(STM32F7XX) || defined(STM32F3XX) || defined(STM32F0XX) || defined(STM32L0XX) || defined(STM32L4XX) || \ + defined(STM32H7XX) // Standard mode : 100 KHz, Rise time 120 ns, Fall time 25 ns, 54MHz clock source // Fast mode : 400 KHz, Rise time 120 ns, Fall time 25 ns, 54MHz clock source @@ -89,123 +106,130 @@ void GetI2cConfig(CLR_RT_HeapBlock* managedConfig, I2CConfig* llConfig) llConfig->cr1 = 0; llConfig->cr2 = 0; - #else - #error Your board is unimplemented. Please provide the needed information for the realtime OS as done above! - #endif - +#else +#error Your board is unimplemented. Please provide the needed information for the realtime OS as done above! +#endif } // estimate the time required to perform the I2C transaction -bool IsLongRunningOperation(uint16_t writeSize, uint16_t readSize, float byteTime, uint32_t& estimatedDurationMiliseconds) +bool IsLongRunningOperation( + uint16_t writeSize, + uint16_t readSize, + float byteTime, + uint32_t &estimatedDurationMiliseconds) { // add an extra byte to account for the address estimatedDurationMiliseconds = byteTime * (writeSize + readSize + 1); - if(estimatedDurationMiliseconds > CLR_RT_Thread::c_TimeQuantum_Milliseconds) + if (estimatedDurationMiliseconds > CLR_RT_Thread::c_TimeQuantum_Milliseconds) { // total operation time will exceed thread quantum, so this is a long running operation return true; } else { - return false; + return false; } } -HRESULT Library_win_dev_i2c_native_Windows_Devices_I2c_I2cDevice::NativeInit___VOID( CLR_RT_StackFrame& stack ) +HRESULT Library_win_dev_i2c_native_Windows_Devices_I2c_I2cDevice::NativeInit___VOID(CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); - { - NF_PAL_I2C* palI2c = NULL; - // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); - - // get a pointer to the managed I2C connectionSettings object instance - CLR_RT_HeapBlock* pConfig = pThis[ FIELD___connectionSettings ].Dereference(); - - // get bus index - // this is coded with a multiplication, need to perform and int division to get the number - // see the comments in the I2cDevice() constructor in managed code for details - uint8_t busIndex = (uint8_t)(pThis[ FIELD___deviceId ].NumericByRef().s4 / 1000); - - // config GPIO pins used by the I2C peripheral - // init the PAL struct for this I2C bus and assign the respective driver - // all this occurs if not already done - // why do we need to check if this is already done? because several I2cDevice objects can be created associated to the same bus just using different addresses - switch (busIndex) - { - #if STM32_I2C_USE_I2C1 - case 1: - if(I2C1_PAL.Driver == NULL) - { - ConfigPins_I2C1(); + NF_PAL_I2C *palI2c = NULL; + CLR_RT_HeapBlock *pConfig; + uint8_t busIndex; - I2C1_PAL.Driver = &I2CD1; - palI2c = &I2C1_PAL; - } - break; - #endif - #if STM32_I2C_USE_I2C2 - case 2: - if(I2C2_PAL.Driver == NULL) - { - ConfigPins_I2C2(); + // get a pointer to the managed object instance and check that it's not NULL + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + + // get a pointer to the managed I2C connectionSettings object instance + pConfig = pThis[FIELD___connectionSettings].Dereference(); + + // get bus index + // this is coded with a multiplication, need to perform and int division to get the number + // see the comments in the I2cDevice() constructor in managed code for details + busIndex = (uint8_t)(pThis[FIELD___deviceId].NumericByRef().s4 / 1000); + + // config GPIO pins used by the I2C peripheral + // init the PAL struct for this I2C bus and assign the respective driver + // all this occurs if not already done + // why do we need to check if this is already done? because several I2cDevice objects can be created associated to + // the same bus just using different addresses + switch (busIndex) + { +#if STM32_I2C_USE_I2C1 + case 1: + if (I2C1_PAL.Driver == NULL) + { + ConfigPins_I2C1(); - I2C2_PAL.Driver = &I2CD2; - palI2c = &I2C2_PAL; - } - break; - #endif - #if STM32_I2C_USE_I2C3 - case 3: - if(I2C3_PAL.Driver == NULL) - { - ConfigPins_I2C3(); + I2C1_PAL.Driver = &I2CD1; + palI2c = &I2C1_PAL; + } + break; +#endif +#if STM32_I2C_USE_I2C2 + case 2: + if (I2C2_PAL.Driver == NULL) + { + ConfigPins_I2C2(); - I2C3_PAL.Driver = &I2CD3; - palI2c = &I2C3_PAL; - } - break; - #endif - #if STM32_I2C_USE_I2C4 - case 4: - if(I2C4_PAL.Driver == NULL) - { - ConfigPins_I2C4(); + I2C2_PAL.Driver = &I2CD2; + palI2c = &I2C2_PAL; + } + break; +#endif +#if STM32_I2C_USE_I2C3 + case 3: + if (I2C3_PAL.Driver == NULL) + { + ConfigPins_I2C3(); - I2C4_PAL.Driver = &I2CD4; - palI2c = &I2C4_PAL; - } - break; - #endif + I2C3_PAL.Driver = &I2CD3; + palI2c = &I2C3_PAL; + } + break; +#endif +#if STM32_I2C_USE_I2C4 + case 4: + if (I2C4_PAL.Driver == NULL) + { + ConfigPins_I2C4(); - default: - // this I2C bus is not valid - NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); - break; - } + I2C4_PAL.Driver = &I2CD4; + palI2c = &I2C4_PAL; + } + break; +#endif - // Get a general low-level I2C configuration, depending on user's managed parameters - GetI2cConfig(pConfig, &palI2c->Configuration); + default: + // this I2C bus is not valid + NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); + break; + } - // compute rough estimate on the time to tx/rx a byte (in milliseconds) - if((I2cBusSpeed)pConfig[ I2cConnectionSettings::FIELD___busSpeed ].NumericByRef().s4 == I2cBusSpeed_StandardMode) - { - // 100kbit/s: this is roughly 0.10ms per byte, give or take - palI2c->ByteTime = 0.1; - } - else - { - // 400kbit/s: this is roughly 0.02ms per byte, give or take - palI2c->ByteTime = 0.02; - } + // Get a general low-level I2C configuration, depending on user's managed parameters + GetI2cConfig(pConfig, &palI2c->Configuration); + // compute rough estimate on the time to tx/rx a byte (in milliseconds) + if ((I2cBusSpeed)pConfig[I2cConnectionSettings::FIELD___busSpeed].NumericByRef().s4 == I2cBusSpeed_StandardMode) + { + // 100kbit/s: this is roughly 0.10ms per byte, give or take + palI2c->ByteTime = 0.1; } + else + { + // 400kbit/s: this is roughly 0.02ms per byte, give or take + palI2c->ByteTime = 0.02; + } + NANOCLR_NOCLEANUP(); } -HRESULT Library_win_dev_i2c_native_Windows_Devices_I2c_I2cDevice::NativeDispose___VOID__BOOLEAN( CLR_RT_StackFrame& stack ) +HRESULT Library_win_dev_i2c_native_Windows_Devices_I2c_I2cDevice::NativeDispose___VOID__BOOLEAN( + CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); @@ -213,56 +237,57 @@ HRESULT Library_win_dev_i2c_native_Windows_Devices_I2c_I2cDevice::NativeDispose_ bool disposeController = false; // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); // get disposeController disposeController = (bool)stack.Arg0().NumericByRef().u1; - if(disposeController) + if (disposeController) { // get bus index // this is coded with a multiplication, need to perform and int division to get the number // see the comments in the I2cDevice() constructor in managed code for details - busIndex = (uint8_t)(pThis[ FIELD___deviceId ].NumericByRef().s4 / 1000); + busIndex = (uint8_t)(pThis[FIELD___deviceId].NumericByRef().s4 / 1000); // get the driver for the I2C bus switch (busIndex) { - #if STM32_I2C_USE_I2C1 - case 1 : +#if STM32_I2C_USE_I2C1 + case 1: // deactivates the I2C peripheral i2cStop(&I2CD1); // nulls driver I2C1_PAL.Driver = NULL; break; - #endif +#endif - #if STM32_I2C_USE_I2C2 - case 2 : +#if STM32_I2C_USE_I2C2 + case 2: // deactivates the I2C peripheral i2cStop(&I2CD2); // nulls driver I2C2_PAL.Driver = NULL; break; - #endif +#endif - #if STM32_I2C_USE_I2C3 - case 3 : +#if STM32_I2C_USE_I2C3 + case 3: // deactivates the I2C peripheral i2cStop(&I2CD3); // nulls driver I2C3_PAL.Driver = NULL; break; - #endif +#endif - #if STM32_I2C_USE_I2C4 - case 4 : +#if STM32_I2C_USE_I2C4 + case 4: // deactivates the I2C peripheral i2cStop(&I2CD4); // nulls driver I2C4_PAL.Driver = NULL; break; - #endif +#endif default: // the requested I2C bus is not valid @@ -274,58 +299,60 @@ HRESULT Library_win_dev_i2c_native_Windows_Devices_I2c_I2cDevice::NativeDispose_ NANOCLR_NOCLEANUP(); } -HRESULT Library_win_dev_i2c_native_Windows_Devices_I2c_I2cDevice::NativeTransmit___WindowsDevicesI2cI2cTransferResult__SZARRAY_U1__SZARRAY_U1( CLR_RT_StackFrame& stack ) +HRESULT Library_win_dev_i2c_native_Windows_Devices_I2c_I2cDevice:: + NativeTransmit___WindowsDevicesI2cI2cTransferResult__SZARRAY_U1__SZARRAY_U1(CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); { uint8_t busIndex; - NF_PAL_I2C* palI2c = NULL; + NF_PAL_I2C *palI2c = NULL; bool isLongRunningOperation = false; msg_t transactionResult = MSG_OK; - CLR_RT_HeapBlock hbTimeout; - CLR_INT64* timeout; - bool eventResult = true; - uint32_t estimatedDurationMiliseconds; + CLR_RT_HeapBlock hbTimeout; + CLR_INT64 *timeout; + bool eventResult = true; + uint32_t estimatedDurationMiliseconds; - CLR_RT_HeapBlock_Array* writeBuffer; - CLR_RT_HeapBlock_Array* readBuffer; - CLR_RT_HeapBlock* result; + CLR_RT_HeapBlock_Array *writeBuffer; + CLR_RT_HeapBlock_Array *readBuffer; + CLR_RT_HeapBlock *result; // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); // get pointer to connection settings field - CLR_RT_HeapBlock* connectionSettings = pThis[ FIELD___connectionSettings ].Dereference(); + CLR_RT_HeapBlock *connectionSettings = pThis[FIELD___connectionSettings].Dereference(); // get bus index // this is coded with a multiplication, need to perform and int division to get the number // see the comments in the I2cDevice() constructor in managed code for details - busIndex = (uint8_t)(pThis[ FIELD___deviceId ].NumericByRef().s4 / 1000); + busIndex = (uint8_t)(pThis[FIELD___deviceId].NumericByRef().s4 / 1000); // get the driver for the I2C bus switch (busIndex) { - #if STM32_I2C_USE_I2C1 - case 1 : +#if STM32_I2C_USE_I2C1 + case 1: palI2c = &I2C1_PAL; break; - #endif - #if STM32_I2C_USE_I2C2 - case 2 : +#endif +#if STM32_I2C_USE_I2C2 + case 2: palI2c = &I2C2_PAL; break; - #endif - #if STM32_I2C_USE_I2C3 - case 3 : +#endif +#if STM32_I2C_USE_I2C3 + case 3: palI2c = &I2C3_PAL; break; - #endif - #if STM32_I2C_USE_I2C4 - case 4 : +#endif +#if STM32_I2C_USE_I2C4 + case 4: palI2c = &I2C4_PAL; break; - #endif +#endif default: // the requested I2C bus is not valid NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); @@ -358,35 +385,43 @@ HRESULT Library_win_dev_i2c_native_Windows_Devices_I2c_I2cDevice::NativeTransmit } // check if this is a long running operation - isLongRunningOperation = IsLongRunningOperation(palI2c->WriteSize, palI2c->ReadSize, palI2c->ByteTime, (uint32_t&)estimatedDurationMiliseconds); + isLongRunningOperation = IsLongRunningOperation( + palI2c->WriteSize, + palI2c->ReadSize, + palI2c->ByteTime, + (uint32_t &)estimatedDurationMiliseconds); - if(isLongRunningOperation) + if (isLongRunningOperation) { - // if this is a long running operation, set a timeout equal to the estimated transaction duration in milliseconds - // this value has to be in ticks to be properly loaded by SetupTimeoutFromTicks() below + // if this is a long running operation, set a timeout equal to the estimated transaction duration in + // milliseconds this value has to be in ticks to be properly loaded by SetupTimeoutFromTicks() below hbTimeout.SetInteger((CLR_INT64)estimatedDurationMiliseconds * TIME_CONVERSION__TO_MILLISECONDS); - NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks( hbTimeout, timeout )); - + NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks(hbTimeout, timeout)); + // protect the buffers from GC so DMA can find them where they are supposed to be - CLR_RT_ProtectFromGC gcWriteBuffer( *writeBuffer ); - CLR_RT_ProtectFromGC gcReadBuffer( *readBuffer ); + CLR_RT_ProtectFromGC gcWriteBuffer(*writeBuffer); + CLR_RT_ProtectFromGC gcReadBuffer(*readBuffer); } // this is going to be used to check for the right event in case of simultaneous I2C transaction - if(!isLongRunningOperation || stack.m_customState == 1) + if (!isLongRunningOperation || stack.m_customState == 1) { // get slave address from connection settings field - palI2c->Address = (i2caddr_t)connectionSettings[Library_win_dev_i2c_native_Windows_Devices_I2c_I2cConnectionSettings::FIELD___slaveAddress].NumericByRef().s4; + palI2c->Address = + (i2caddr_t)connectionSettings + [Library_win_dev_i2c_native_Windows_Devices_I2c_I2cConnectionSettings::FIELD___slaveAddress] + .NumericByRef() + .s4; // when using I2Cv1 driver the address needs to be loaded in the I2C driver struct - #if defined(STM32F1XX) || defined(STM32F4XX) || defined(STM32L1XX) +#if defined(STM32F1XX) || defined(STM32F4XX) || defined(STM32L1XX) palI2c->Driver->addr = palI2c->Address; - #endif +#endif if (writeBuffer != NULL) { - palI2c->WriteBuffer = (uint8_t*)writeBuffer->GetFirstElement(); + palI2c->WriteBuffer = (uint8_t *)writeBuffer->GetFirstElement(); // flush DMA buffer to ensure cache coherency // (only required for Cortex-M7) @@ -395,29 +430,34 @@ HRESULT Library_win_dev_i2c_native_Windows_Devices_I2c_I2cDevice::NativeTransmit if (readBuffer != NULL) { - palI2c->ReadBuffer = (uint8_t*)readBuffer->GetFirstElement(); + palI2c->ReadBuffer = (uint8_t *)readBuffer->GetFirstElement(); } - + // because the bus access is shared, acquire the appropriate bus i2cAcquireBus(palI2c->Driver); i2cStart(palI2c->Driver, &palI2c->Configuration); } - if(isLongRunningOperation) + if (isLongRunningOperation) { // this is a long running operation and hasn't started yet // perform I2C transaction using driver's ASYNC API which is launching a thread to perform it - if(stack.m_customState == 1) + if (stack.m_customState == 1) { // spawn working thread to perform the I2C transaction - palI2c->WorkingThread = chThdCreateFromHeap(NULL, THD_WORKING_AREA_SIZE(256), - "I2CWT", NORMALPRIO, I2CWorkingThread, palI2c); - - if(palI2c->WorkingThread == NULL) + palI2c->WorkingThread = chThdCreateFromHeap( + NULL, + THD_WORKING_AREA_SIZE(256), + "I2CWT", + NORMALPRIO, + I2CWorkingThread, + palI2c); + + if (palI2c->WorkingThread == NULL) { NANOCLR_SET_AND_LEAVE(CLR_E_PROCESS_EXCEPTION); } - + // bump custom state stack.m_customState = 2; } @@ -430,48 +470,68 @@ HRESULT Library_win_dev_i2c_native_Windows_Devices_I2c_I2cDevice::NativeTransmit if (palI2c->ReadSize != 0 && palI2c->WriteSize != 0) { // this is a Write/Read transaction - transactionResult = i2cMasterTransmitTimeout(palI2c->Driver, palI2c->Address, palI2c->WriteBuffer, palI2c->WriteSize, palI2c->ReadBuffer, palI2c->ReadSize, TIME_MS2I(20)); + transactionResult = i2cMasterTransmitTimeout( + palI2c->Driver, + palI2c->Address, + palI2c->WriteBuffer, + palI2c->WriteSize, + palI2c->ReadBuffer, + palI2c->ReadSize, + TIME_MS2I(20)); } else { if (palI2c->ReadSize == 0) { // this is Write only transaction - transactionResult = i2cMasterTransmitTimeout(palI2c->Driver, palI2c->Address, palI2c->WriteBuffer, palI2c->WriteSize, NULL, 0, TIME_MS2I(20)); + transactionResult = i2cMasterTransmitTimeout( + palI2c->Driver, + palI2c->Address, + palI2c->WriteBuffer, + palI2c->WriteSize, + NULL, + 0, + TIME_MS2I(20)); } else { // this is a Read only transaction - transactionResult = i2cMasterReceiveTimeout (palI2c->Driver, palI2c->Address, palI2c->ReadBuffer, palI2c->ReadSize, TIME_MS2I(20)); + transactionResult = i2cMasterReceiveTimeout( + palI2c->Driver, + palI2c->Address, + palI2c->ReadBuffer, + palI2c->ReadSize, + TIME_MS2I(20)); } } - } + } - while(eventResult) + while (eventResult) { - if(!isLongRunningOperation) + if (!isLongRunningOperation) { // this is not a long running operation so nothing to do here break; } - if(palI2c->WorkingThread->state == CH_STATE_FINAL) + if (palI2c->WorkingThread->state == CH_STATE_FINAL) { // I2C working thread is now complete break; } // non-blocking wait allowing other threads to run while we wait for the I2C transaction to complete - NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.WaitEvents( stack.m_owningThread, *timeout, CLR_RT_ExecutionEngine::c_Event_I2cMaster, eventResult )); + NANOCLR_CHECK_HRESULT( + g_CLR_RT_ExecutionEngine.WaitEvents(stack.m_owningThread, *timeout, Event_I2cMaster, eventResult)); } - if(isLongRunningOperation) + if (isLongRunningOperation) { // pop timeout heap block from stack stack.PopValue(); } - if(eventResult || !isLongRunningOperation) + if (eventResult || !isLongRunningOperation) { // event occurred // OR this is NOT a long running operation @@ -479,14 +539,18 @@ HRESULT Library_win_dev_i2c_native_Windows_Devices_I2c_I2cDevice::NativeTransmit i2cReleaseBus(palI2c->Driver); // create the return object (I2cTransferResult) - // only at this point we are sure that there will be a return from this thread so it's OK to use the managed stack - CLR_RT_HeapBlock& top = stack.PushValueAndClear(); - NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.NewObjectFromIndex(top, g_CLR_RT_WellKnownTypes.m_I2cTransferResult)); - result = top.Dereference(); FAULT_ON_NULL(result); - - if(isLongRunningOperation) + // only at this point we are sure that there will be a return from this thread so it's OK to use the managed + // stack + CLR_RT_HeapBlock &top = stack.PushValueAndClear(); + NANOCLR_CHECK_HRESULT( + g_CLR_RT_ExecutionEngine.NewObjectFromIndex(top, g_CLR_RT_WellKnownTypes.m_I2cTransferResult)); + result = top.Dereference(); + FAULT_ON_NULL(result); + + if (isLongRunningOperation) { - // ChibiOS requirement: need to call chThdWait for I2C working thread in order to have it's memory released to the heap, otherwise it won't be returned + // ChibiOS requirement: need to call chThdWait for I2C working thread in order to have it's memory + // released to the heap, otherwise it won't be returned transactionResult = chThdWait(palI2c->WorkingThread); } @@ -495,43 +559,49 @@ HRESULT Library_win_dev_i2c_native_Windows_Devices_I2c_I2cDevice::NativeTransmit { // error in transaction int errors = i2cGetErrors(palI2c->Driver); - + // figure out what was the error and set the status field - switch(errors) + switch (errors) { case I2C_ACK_FAILURE: - result[ Library_win_dev_i2c_native_Windows_Devices_I2c_I2cTransferResult::FIELD___status ].SetInteger((CLR_UINT32)I2cTransferStatus_SlaveAddressNotAcknowledged); + result[Library_win_dev_i2c_native_Windows_Devices_I2c_I2cTransferResult::FIELD___status] + .SetInteger((CLR_UINT32)I2cTransferStatus_SlaveAddressNotAcknowledged); break; case I2C_TIMEOUT: - result[ Library_win_dev_i2c_native_Windows_Devices_I2c_I2cTransferResult::FIELD___status ].SetInteger((CLR_UINT32)I2cTransferStatus_ClockStretchTimeout); + result[Library_win_dev_i2c_native_Windows_Devices_I2c_I2cTransferResult::FIELD___status] + .SetInteger((CLR_UINT32)I2cTransferStatus_ClockStretchTimeout); break; default: - result[ Library_win_dev_i2c_native_Windows_Devices_I2c_I2cTransferResult::FIELD___status ].SetInteger((CLR_UINT32)I2cTransferStatus_UnknownError); + result[Library_win_dev_i2c_native_Windows_Devices_I2c_I2cTransferResult::FIELD___status] + .SetInteger((CLR_UINT32)I2cTransferStatus_UnknownError); } - // set the bytes transferred count to 0 because we don't have a way to know how many bytes were actually sent/received - result[ Library_win_dev_i2c_native_Windows_Devices_I2c_I2cTransferResult::FIELD___bytesTransferred ].SetInteger(0); + // set the bytes transferred count to 0 because we don't have a way to know how many bytes were actually + // sent/received + result[Library_win_dev_i2c_native_Windows_Devices_I2c_I2cTransferResult::FIELD___bytesTransferred] + .SetInteger(0); } else { // successfull transaction // set the result field - result[ Library_win_dev_i2c_native_Windows_Devices_I2c_I2cTransferResult::FIELD___status ].SetInteger((CLR_UINT32)I2cTransferStatus_FullTransfer); + result[Library_win_dev_i2c_native_Windows_Devices_I2c_I2cTransferResult::FIELD___status].SetInteger( + (CLR_UINT32)I2cTransferStatus_FullTransfer); // set the bytes transferred field - result[ Library_win_dev_i2c_native_Windows_Devices_I2c_I2cTransferResult::FIELD___bytesTransferred ].SetInteger((CLR_UINT32)(palI2c->WriteSize + palI2c->ReadSize)); + result[Library_win_dev_i2c_native_Windows_Devices_I2c_I2cTransferResult::FIELD___bytesTransferred] + .SetInteger((CLR_UINT32)(palI2c->WriteSize + palI2c->ReadSize)); } - - if(palI2c->ReadSize > 0) + + if (palI2c->ReadSize > 0) { // invalidate cache over read buffer to ensure that content from DMA is read // (only required for Cortex-M7) cacheBufferInvalidate(palI2c->ReadBuffer, palI2c->ReadSize); } } - } NANOCLR_NOCLEANUP(); } diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.I2c/win_dev_i2c_native_Windows_Devices_I2c_I2cController.cpp b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.I2c/win_dev_i2c_native_Windows_Devices_I2c_I2cController.cpp index d718a27e2b..ef6346c25a 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.I2c/win_dev_i2c_native_Windows_Devices_I2c_I2cController.cpp +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.I2c/win_dev_i2c_native_Windows_Devices_I2c_I2cController.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.I2c/win_dev_i2c_native_target.h b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.I2c/win_dev_i2c_native_target.h index 734e1ca21e..673a477fe9 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.I2c/win_dev_i2c_native_target.h +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.I2c/win_dev_i2c_native_target.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // @@ -9,47 +9,53 @@ #include #include -// struct representing the I2C -struct NF_PAL_I2C +// struct representing the I2C +typedef struct NF_PAL_I2C_ { - I2CDriver* Driver; - I2CConfig Configuration; - thread_t* WorkingThread; - i2caddr_t Address; + I2CDriver *Driver; + I2CConfig Configuration; + thread_t *WorkingThread; + i2caddr_t Address; float ByteTime; - uint8_t* WriteBuffer; - uint8_t WriteSize; + uint8_t *WriteBuffer; + uint8_t WriteSize; - uint8_t* ReadBuffer; - uint8_t ReadSize; -}; + uint8_t *ReadBuffer; + uint8_t ReadSize; +} NF_PAL_I2C; /////////////////////////////////////////// // declaration of the the I2C PAL strucs // /////////////////////////////////////////// #if STM32_I2C_USE_I2C1 - extern NF_PAL_I2C I2C1_PAL; +extern NF_PAL_I2C I2C1_PAL; #endif #if STM32_I2C_USE_I2C2 - extern NF_PAL_I2C I2C2_PAL; +extern NF_PAL_I2C I2C2_PAL; #endif #if STM32_I2C_USE_I2C3 - extern NF_PAL_I2C I2C3_PAL; +extern NF_PAL_I2C I2C3_PAL; #endif #if STM32_I2C_USE_I2C4 - extern NF_PAL_I2C I2C4_PAL; +extern NF_PAL_I2C I2C4_PAL; #endif - // the following macro defines a function that configures the GPIO pins for a STM32 I2C peripheral // it gets called in the Windows_Devices_I2c_I2cDevice::NativeInit function // this is required because the I2C peripherals can use multiple GPIO configuration combinations -#define I2C_CONFIG_PINS(num, gpio_port_scl, gpio_port_sda, scl_pin, sda_pin, alternate_function) void ConfigPins_I2C##num() \ -{ \ - palSetPadMode(gpio_port_scl, scl_pin, (PAL_MODE_ALTERNATE(alternate_function) | PAL_STM32_OSPEED_HIGHEST | PAL_STM32_OTYPE_OPENDRAIN) ); \ - palSetPadMode(gpio_port_sda, sda_pin, (PAL_MODE_ALTERNATE(alternate_function) | PAL_STM32_OSPEED_HIGHEST | PAL_STM32_OTYPE_OPENDRAIN)); \ -} +#define I2C_CONFIG_PINS(num, gpio_port_scl, gpio_port_sda, scl_pin, sda_pin, alternate_function) \ + void ConfigPins_I2C##num() \ + { \ + palSetPadMode( \ + gpio_port_scl, \ + scl_pin, \ + (PAL_MODE_ALTERNATE(alternate_function) | PAL_STM32_OSPEED_HIGHEST | PAL_STM32_OTYPE_OPENDRAIN)); \ + palSetPadMode( \ + gpio_port_sda, \ + sda_pin, \ + (PAL_MODE_ALTERNATE(alternate_function) | PAL_STM32_OSPEED_HIGHEST | PAL_STM32_OTYPE_OPENDRAIN)); \ + } ////////////////////////////////////////////////////////////////////////////////////////////// // when an I2C is defined the declarations below will have the real function/configuration // @@ -60,4 +66,4 @@ void ConfigPins_I2C2(); void ConfigPins_I2C3(); void ConfigPins_I2C4(); -#endif //_WIN_DEV_I2C_NATIVE_TARGET_H_ +#endif //_WIN_DEV_I2C_NATIVE_TARGET_H_ diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.Pwm/win_dev_pwm_native_Windows_Devices_Pwm_PwmController.cpp b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.Pwm/win_dev_pwm_native_Windows_Devices_Pwm_PwmController.cpp index 70678628f4..508df2a6bf 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.Pwm/win_dev_pwm_native_Windows_Devices_Pwm_PwmController.cpp +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.Pwm/win_dev_pwm_native_Windows_Devices_Pwm_PwmController.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.Pwm/win_dev_pwm_native_Windows_Devices_Pwm_PwmPin.cpp b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.Pwm/win_dev_pwm_native_Windows_Devices_Pwm_PwmPin.cpp index fb91b7061b..5acab1e8d6 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.Pwm/win_dev_pwm_native_Windows_Devices_Pwm_PwmPin.cpp +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.Pwm/win_dev_pwm_native_Windows_Devices_Pwm_PwmPin.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.Pwm/win_dev_pwm_native_target.h b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.Pwm/win_dev_pwm_native_target.h index 802c8c78a3..e5bf18c38f 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.Pwm/win_dev_pwm_native_target.h +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.Pwm/win_dev_pwm_native_target.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.SerialCommunication/win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice.cpp b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.SerialCommunication/win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice.cpp index 6843dd543c..b70799e300 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.SerialCommunication/win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice.cpp +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.SerialCommunication/win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // @@ -11,87 +11,87 @@ // UART PAL strucs delcared in win_dev_serial_native.h // ///////////////////////////////////////////////////////// #if NF_SERIAL_COMM_STM32_UART_USE_USART1 - NF_PAL_UART Uart1_PAL; +NF_PAL_UART Uart1_PAL; #endif #if NF_SERIAL_COMM_STM32_UART_USE_USART2 - NF_PAL_UART Uart2_PAL; +NF_PAL_UART Uart2_PAL; #endif #if NF_SERIAL_COMM_STM32_UART_USE_USART3 - NF_PAL_UART Uart3_PAL; +NF_PAL_UART Uart3_PAL; #endif #if NF_SERIAL_COMM_STM32_UART_USE_UART4 - NF_PAL_UART Uart4_PAL; +NF_PAL_UART Uart4_PAL; #endif #if NF_SERIAL_COMM_STM32_UART_USE_UART5 - NF_PAL_UART Uart5_PAL; +NF_PAL_UART Uart5_PAL; #endif #if NF_SERIAL_COMM_STM32_UART_USE_USART6 - NF_PAL_UART Uart6_PAL; +NF_PAL_UART Uart6_PAL; #endif #if NF_SERIAL_COMM_STM32_UART_USE_UART7 - NF_PAL_UART Uart7_PAL; +NF_PAL_UART Uart7_PAL; #endif #if NF_SERIAL_COMM_STM32_UART_USE_UART8 - NF_PAL_UART Uart8_PAL; +NF_PAL_UART Uart8_PAL; #endif // This callback is invoked when a transmission buffer has been completely read by the driver. -static void TxEnd1(UARTDriver *uartp) +static void TxEnd1(UARTDriver *uartp) { (void)uartp; NATIVE_INTERRUPT_START - NF_PAL_UART* palUart; + NF_PAL_UART *palUart; - #if NF_SERIAL_COMM_STM32_UART_USE_USART1 +#if NF_SERIAL_COMM_STM32_UART_USE_USART1 if (uartp == &UARTD1) { palUart = &Uart1_PAL; } - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_USART2 +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_USART2 if (uartp == &UARTD2) { palUart = &Uart2_PAL; } - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_USART3 +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_USART3 if (uartp == &UARTD3) { palUart = &Uart3_PAL; } - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_UART4 +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_UART4 if (uartp == &UARTD4) { palUart = &Uart4_PAL; } - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_UART5 +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_UART5 if (uartp == &UARTD5) { palUart = &Uart5_PAL; } - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_USART6 +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_USART6 if (uartp == &UARTD6) { palUart = &Uart6_PAL; } - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_UART7 +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_UART7 if (uartp == &UARTD7) { palUart = &Uart7_PAL; } - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_UART8 +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_UART8 if (uartp == &UARTD8) { palUart = &Uart8_PAL; } - #endif +#endif // pop elements from ring buffer, just pop palUart->TxRingBuffer.Pop(palUart->TxOngoingCount); @@ -99,76 +99,77 @@ static void TxEnd1(UARTDriver *uartp) // reset Tx ongoing count palUart->TxOngoingCount = 0; - Events_Set( SYSTEM_EVENT_FLAG_COM_OUT ); + Events_Set(SYSTEM_EVENT_FLAG_COM_OUT); NATIVE_INTERRUPT_END } -// This callback is invoked when a character is received but the application was not ready to receive it, the character is passed as parameter. -static void RxChar(UARTDriver *uartp, uint16_t c) +// This callback is invoked when a character is received but the application was not ready to receive it, the character +// is passed as parameter. +static void RxChar(UARTDriver *uartp, uint16_t c) { NATIVE_INTERRUPT_START - NF_PAL_UART* palUart; + NF_PAL_UART *palUart; uint8_t portIndex = 0; - #if NF_SERIAL_COMM_STM32_UART_USE_USART1 +#if NF_SERIAL_COMM_STM32_UART_USE_USART1 if (uartp == &UARTD1) { palUart = &Uart1_PAL; portIndex = 1; } - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_USART2 +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_USART2 if (uartp == &UARTD2) { palUart = &Uart2_PAL; portIndex = 2; } - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_USART3 +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_USART3 if (uartp == &UARTD3) { palUart = &Uart3_PAL; portIndex = 3; } - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_UART4 +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_UART4 if (uartp == &UARTD4) { palUart = &Uart4_PAL; portIndex = 4; } - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_UART5 +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_UART5 if (uartp == &UARTD5) { palUart = &Uart5_PAL; portIndex = 5; } - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_USART6 +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_USART6 if (uartp == &UARTD6) { palUart = &Uart6_PAL; portIndex = 6; } - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_UART7 +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_UART7 if (uartp == &UARTD7) { palUart = &Uart7_PAL; portIndex = 7; } - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_UART8 +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_UART8 if (uartp == &UARTD8) { palUart = &Uart8_PAL; portIndex = 8; } - #endif - +#endif + // store this into the UART Rx buffer // push char to ring buffer @@ -176,13 +177,12 @@ static void RxChar(UARTDriver *uartp, uint16_t c) palUart->RxRingBuffer.Push((uint8_t)c); // is there a read operation going on? - if(palUart->RxBytesToRead > 0) + if (palUart->RxBytesToRead > 0) { // yes // check if the requested bytes are available in the buffer... //... or if the watch char was received - if((palUart->RxRingBuffer.Length() >= palUart->RxBytesToRead) || - (c == palUart->WatchChar)) + if ((palUart->RxRingBuffer.Length() >= palUart->RxBytesToRead) || (c == palUart->WatchChar)) { // reset Rx bytes to read count palUart->RxBytesToRead = 0; @@ -194,100 +194,106 @@ static void RxChar(UARTDriver *uartp, uint16_t c) else { // no read operation ongoing, so fire an event - - // post a managed event with the port index and event code (check if this is the watch char or just another another) - // TODO: check if callbacks are registered so this is called only if there is anyone listening otherwise don't bother - // for that to happen ChibiOS callback has to accept arg which we would passing the GpioPin CLR_RT_HeapBlock (see Gpio handler) - // check http://www.chibios.com/forum/viewtopic.php?f=36&t=4798 - PostManagedEvent( EVENT_SERIAL, 0, portIndex, (c == palUart->WatchChar) ? SerialData_WatchChar : SerialData_Chars ); + + // post a managed event with the port index and event code (check if this is the watch char or just another + // another) + // TODO: check if callbacks are registered so this is called only if there is anyone listening otherwise don't + // bother for that to happen ChibiOS callback has to accept arg which we would passing the GpioPin + // CLR_RT_HeapBlock (see Gpio handler) check http://www.chibios.com/forum/viewtopic.php?f=36&t=4798 + PostManagedEvent( + EVENT_SERIAL, + 0, + portIndex, + (c == palUart->WatchChar) ? SerialData_WatchChar : SerialData_Chars); } NATIVE_INTERRUPT_END } -HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::NativeDispose___VOID( CLR_RT_StackFrame& stack ) +HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::NativeDispose___VOID( + CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); - // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); // Choose the driver for this SerialDevice - switch ((int)pThis[ FIELD___portIndex ].NumericByRef().s4) + switch ((int)pThis[FIELD___portIndex].NumericByRef().s4) { - #if NF_SERIAL_COMM_STM32_UART_USE_USART1 - case 1 : +#if NF_SERIAL_COMM_STM32_UART_USE_USART1 + case 1: UnInit_UART1(); // stop UART uartStop(&UARTD1); Uart1_PAL.UartDriver = NULL; break; - #endif +#endif - #if NF_SERIAL_COMM_STM32_UART_USE_USART2 - case 2 : +#if NF_SERIAL_COMM_STM32_UART_USE_USART2 + case 2: UnInit_UART2(); // stop UART uartStop(&UARTD2); Uart2_PAL.UartDriver = NULL; break; - #endif +#endif - #if NF_SERIAL_COMM_STM32_UART_USE_USART3 - case 3 : +#if NF_SERIAL_COMM_STM32_UART_USE_USART3 + case 3: UnInit_UART3(); // stop UART uartStop(&UARTD3); Uart3_PAL.UartDriver = NULL; break; - #endif +#endif - #if NF_SERIAL_COMM_STM32_UART_USE_UART4 - case 4 : +#if NF_SERIAL_COMM_STM32_UART_USE_UART4 + case 4: UnInit_UART4(); // stop UART uartStop(&UARTD4); Uart4_PAL.UartDriver = NULL; break; - #endif +#endif - #if NF_SERIAL_COMM_STM32_UART_USE_UART5 - case 5 : +#if NF_SERIAL_COMM_STM32_UART_USE_UART5 + case 5: UnInit_UART5(); // stop UART uartStop(&UARTD5); Uart5_PAL.UartDriver = NULL; - break; - #endif + break; +#endif - #if NF_SERIAL_COMM_STM32_UART_USE_USART6 - case 6 : +#if NF_SERIAL_COMM_STM32_UART_USE_USART6 + case 6: UnInit_UART6(); // stop UART uartStop(&UARTD6); Uart6_PAL.UartDriver = NULL; - break; - #endif + break; +#endif - #if NF_SERIAL_COMM_STM32_UART_USE_UART7 - case 7 : +#if NF_SERIAL_COMM_STM32_UART_USE_UART7 + case 7: UnInit_UART7(); // stop UART uartStop(&UARTD7); Uart7_PAL.UartDriver = NULL; break; - #endif +#endif - #if NF_SERIAL_COMM_STM32_UART_USE_UART8 - case 8 : +#if NF_SERIAL_COMM_STM32_UART_USE_UART8 + case 8: UnInit_UART8(); // stop UART uartStop(&UARTD8); Uart8_PAL.UartDriver = NULL; break; - #endif +#endif default: // this COM port is not valid @@ -298,74 +304,76 @@ HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_Serial NANOCLR_NOCLEANUP(); } -HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::NativeInit___VOID( CLR_RT_StackFrame& stack ) +HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::NativeInit___VOID( + CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); { - NF_PAL_UART* palUart; + NF_PAL_UART *palUart; // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); // Choose the driver for this SerialDevice - switch ((int)pThis[ FIELD___portIndex ].NumericByRef().s4) + switch ((int)pThis[FIELD___portIndex].NumericByRef().s4) { - #if NF_SERIAL_COMM_STM32_UART_USE_USART1 - case 1 : +#if NF_SERIAL_COMM_STM32_UART_USE_USART1 + case 1: Init_UART1(); Uart1_PAL.UartDriver = &UARTD1; palUart = &Uart1_PAL; break; - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_USART2 - case 2 : +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_USART2 + case 2: Init_UART2(); Uart2_PAL.UartDriver = &UARTD2; palUart = &Uart2_PAL; break; - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_USART3 - case 3 : +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_USART3 + case 3: Init_UART3(); Uart3_PAL.UartDriver = &UARTD3; palUart = &Uart3_PAL; break; - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_UART4 - case 4 : +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_UART4 + case 4: Init_UART4(); Uart4_PAL.UartDriver = &UARTD4; palUart = &Uart4_PAL; break; - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_UART5 - case 5 : +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_UART5 + case 5: Init_UART5(); Uart5_PAL.UartDriver = &UARTD5; palUart = &Uart5_PAL; - break; - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_USART6 - case 6 : + break; +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_USART6 + case 6: Init_UART6(); Uart6_PAL.UartDriver = &UARTD6; palUart = &Uart6_PAL; - break; - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_UART7 - case 7 : + break; +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_UART7 + case 7: Init_UART7(); Uart7_PAL.UartDriver = &UARTD7; palUart = &Uart7_PAL; break; - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_UART8 - case 8 : +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_UART8 + case 8: Init_UART8(); Uart8_PAL.UartDriver = &UARTD8; palUart = &Uart8_PAL; break; - #endif +#endif default: // this COM port is not valid NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); @@ -375,66 +383,68 @@ HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_Serial // configure UART handlers palUart->Uart_cfg.txend1_cb = TxEnd1; palUart->Uart_cfg.rxchar_cb = RxChar; - //palUart->Uart_cfg.rxend_cb = RxEnd; + // palUart->Uart_cfg.rxend_cb = RxEnd; // call the configure return NativeConfig___VOID(stack); } - NANOCLR_NOCLEANUP(); + NANOCLR_NOCLEANUP(); } -HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::NativeConfig___VOID( CLR_RT_StackFrame& stack ) +HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::NativeConfig___VOID( + CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); { - NF_PAL_UART* palUart = NULL; + NF_PAL_UART *palUart = NULL; // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); // Choose the driver for this SerialDevice - switch ((int)pThis[ FIELD___portIndex ].NumericByRef().s4) + switch ((int)pThis[FIELD___portIndex].NumericByRef().s4) { - #if NF_SERIAL_COMM_STM32_UART_USE_USART1 - case 1 : +#if NF_SERIAL_COMM_STM32_UART_USE_USART1 + case 1: palUart = &Uart1_PAL; break; - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_USART2 - case 2 : +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_USART2 + case 2: palUart = &Uart2_PAL; break; - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_USART3 - case 3 : +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_USART3 + case 3: palUart = &Uart3_PAL; break; - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_UART4 - case 4 : +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_UART4 + case 4: palUart = &Uart4_PAL; break; - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_UART5 - case 5 : +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_UART5 + case 5: palUart = &Uart5_PAL; - break; - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_USART6 - case 6 : + break; +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_USART6 + case 6: palUart = &Uart6_PAL; - break; - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_UART7 - case 7 : + break; +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_UART7 + case 7: palUart = &Uart7_PAL; break; - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_UART8 - case 8 : +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_UART8 + case 8: palUart = &Uart8_PAL; break; - #endif +#endif } // setup configuration @@ -449,68 +459,68 @@ HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_Serial // clear bits for stop bits setting palUart->Uart_cfg.cr2 &= ~USART_CR2_STOP; - switch ((SerialStopBitCount)pThis[ FIELD___stopBits ].NumericByRef().s4) + switch ((SerialStopBitCount)pThis[FIELD___stopBits].NumericByRef().s4) { - case SerialStopBitCount_One : + case SerialStopBitCount_One: // already set with the above break; - case SerialStopBitCount_OnePointFive : + case SerialStopBitCount_OnePointFive: palUart->Uart_cfg.cr2 |= USART_CR2_STOP_1 + USART_CR2_STOP_0; break; - case SerialStopBitCount_Two : + case SerialStopBitCount_Two: palUart->Uart_cfg.cr2 |= USART_CR2_STOP_1; break; } // baud rate - palUart->Uart_cfg.speed = (int)pThis[ FIELD___baudRate ].NumericByRef().s4; - + palUart->Uart_cfg.speed = (int)pThis[FIELD___baudRate].NumericByRef().s4; + // stop UART, better do this before changing configuration uartStop(palUart->UartDriver); - // get pointer to PAL UART - switch ((int)pThis[ FIELD___portIndex ].NumericByRef().s4) + // get pointer to PAL UART + switch ((int)pThis[FIELD___portIndex].NumericByRef().s4) { - #if NF_SERIAL_COMM_STM32_UART_USE_USART1 - case 1 : +#if NF_SERIAL_COMM_STM32_UART_USE_USART1 + case 1: ConfigPins_UART1(); break; - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_USART2 - case 2 : +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_USART2 + case 2: ConfigPins_UART2(); break; - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_USART3 - case 3 : +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_USART3 + case 3: ConfigPins_UART3(); break; - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_UART4 - case 4 : +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_UART4 + case 4: ConfigPins_UART4(); break; - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_UART5 - case 5 : +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_UART5 + case 5: ConfigPins_UART5(); - break; - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_USART6 - case 6 : + break; +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_USART6 + case 6: ConfigPins_UART6(); - break; - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_UART7 - case 7 : + break; +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_UART7 + case 7: ConfigPins_UART7(); break; - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_UART8 - case 8 : +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_UART8 + case 8: ConfigPins_UART8(); break; - #endif +#endif } uartStart(palUart->UartDriver, &palUart->Uart_cfg); @@ -523,25 +533,27 @@ HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_Serial NANOCLR_NOCLEANUP(); } -HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::NativeWrite___VOID__SZARRAY_U1( CLR_RT_StackFrame& stack ) +HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::NativeWrite___VOID__SZARRAY_U1( + CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); { - NF_PAL_UART* palUart = NULL; + NF_PAL_UART *palUart = NULL; - uint8_t* data; + uint8_t *data; unsigned int length = 0; // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); - if(pThis[ FIELD___disposed ].NumericByRef().u1 != 0) + if (pThis[FIELD___disposed].NumericByRef().u1 != 0) { NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); } // dereference the data buffer from the argument - CLR_RT_HeapBlock_Array* dataBuffer = stack.Arg1().DereferenceArray(); + CLR_RT_HeapBlock_Array *dataBuffer = stack.Arg1().DereferenceArray(); // get a the pointer to the array by using the first element of the array data = dataBuffer->GetFirstElement(); @@ -549,73 +561,78 @@ HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_Serial // get the size of the buffer length = dataBuffer->m_numOfElements; - // get pointer to PAL UART - switch ((int)pThis[ FIELD___portIndex ].NumericByRef().s4) + // get pointer to PAL UART + switch ((int)pThis[FIELD___portIndex].NumericByRef().s4) { - #if NF_SERIAL_COMM_STM32_UART_USE_USART1 - case 1 : +#if NF_SERIAL_COMM_STM32_UART_USE_USART1 + case 1: palUart = &Uart1_PAL; break; - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_USART2 - case 2 : +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_USART2 + case 2: palUart = &Uart2_PAL; break; - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_USART3 - case 3 : +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_USART3 + case 3: palUart = &Uart3_PAL; break; - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_UART4 - case 4 : +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_UART4 + case 4: palUart = &Uart4_PAL; break; - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_UART5 - case 5 : +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_UART5 + case 5: palUart = &Uart5_PAL; - break; - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_USART6 - case 6 : + break; +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_USART6 + case 6: palUart = &Uart6_PAL; - break; - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_UART7 - case 7 : + break; +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_UART7 + case 7: palUart = &Uart7_PAL; break; - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_UART8 - case 8 : +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_UART8 + case 8: palUart = &Uart8_PAL; break; - #endif +#endif } // check if there is enough room in the buffer - if(palUart->TxRingBuffer.Capacity() - palUart->TxRingBuffer.Length() < length) + if (palUart->TxRingBuffer.Capacity() - palUart->TxRingBuffer.Length() < length) { // not enough room in the buffer - NANOCLR_SET_AND_LEAVE(CLR_E_BUFFER_TOO_SMALL); + NANOCLR_SET_AND_LEAVE(CLR_E_BUFFER_TOO_SMALL); } // push data to buffer size_t bytesWritten = palUart->TxRingBuffer.Push(data, length); // check if all requested bytes were written - if(bytesWritten != length) + if (bytesWritten != length) { // not sure if this is the best exception to throw here... NANOCLR_SET_AND_LEAVE(CLR_E_FAIL); } - + // need to update the _unstoredBufferLength field in the SerialDeviceOutputStream // get pointer to outputStream field - CLR_RT_HeapBlock* outputStream = pThis[Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::FIELD___outputStream].Dereference(); + CLR_RT_HeapBlock *outputStream = + pThis[Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::FIELD___outputStream] + .Dereference(); // get pointer to _unstoredBufferLength field and udpate field value - outputStream[Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDeviceOutputStream::FIELD___unstoredBufferLength].NumericByRef().s4 = palUart->TxRingBuffer.Length(); + outputStream[Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDeviceOutputStream:: + FIELD___unstoredBufferLength] + .NumericByRef() + .s4 = palUart->TxRingBuffer.Length(); // null pointers and vars pThis = NULL; @@ -623,89 +640,91 @@ HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_Serial NANOCLR_NOCLEANUP(); } -HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::NativeStore___U4( CLR_RT_StackFrame& stack ) +HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::NativeStore___U4( + CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); - NF_PAL_UART* palUart = NULL; + NF_PAL_UART *palUart = NULL; size_t length = 0; - int64_t* timeoutTicks; + int64_t *timeoutTicks; bool eventResult = true; bool txOk = false; - + // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); - if(pThis[ FIELD___disposed ].NumericByRef().u1 != 0) + if (pThis[FIELD___disposed].NumericByRef().u1 != 0) { NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); } // Choose the driver for this SerialDevice - switch ((int)pThis[ FIELD___portIndex ].NumericByRef().s4) + switch ((int)pThis[FIELD___portIndex].NumericByRef().s4) { #if NF_SERIAL_COMM_STM32_UART_USE_USART1 - case 1 : + case 1: palUart = &Uart1_PAL; break; #endif #if NF_SERIAL_COMM_STM32_UART_USE_USART2 - case 2 : + case 2: palUart = &Uart2_PAL; break; #endif #if NF_SERIAL_COMM_STM32_UART_USE_USART3 - case 3 : + case 3: palUart = &Uart3_PAL; break; #endif #if NF_SERIAL_COMM_STM32_UART_USE_UART4 - case 4 : + case 4: palUart = &Uart4_PAL; break; #endif #if NF_SERIAL_COMM_STM32_UART_USE_UART5 - case 5 : + case 5: palUart = &Uart5_PAL; break; #endif #if NF_SERIAL_COMM_STM32_UART_USE_USART6 - case 6 : + case 6: palUart = &Uart6_PAL; break; #endif #if NF_SERIAL_COMM_STM32_UART_USE_UART7 - case 7 : + case 7: palUart = &Uart7_PAL; break; #endif #if NF_SERIAL_COMM_STM32_UART_USE_UART8 - case 8 : + case 8: palUart = &Uart8_PAL; break; #endif } // setup timeout from _writetTimeout field - NANOCLR_CHECK_HRESULT( stack.SetupTimeoutFromTimeSpan(pThis[ FIELD___writeTimeout ], timeoutTicks) ); + NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTimeSpan(pThis[FIELD___writeTimeout], timeoutTicks)); // push dummy length value onto the eval stack // this is going to be used to store how many bytes where buffered to Tx - if(stack.m_customState == 1) + if (stack.m_customState == 1) { stack.PushValueI4(0); - + // bump custom state so the read value above is pushed only once stack.m_customState = 2; } // check if there is anything the buffer - if(palUart->TxRingBuffer.Length() > 0) + if (palUart->TxRingBuffer.Length() > 0) { // check if there is a TX operation ongoing - if(palUart->TxOngoingCount == 0) + if (palUart->TxOngoingCount == 0) { // OK to Tx txOk = true; @@ -716,7 +735,7 @@ HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_Serial } } - if(txOk) + if (txOk) { // optimize buffer for sequential reading palUart->TxRingBuffer.OptimizeSequence(); @@ -726,7 +745,7 @@ HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_Serial // push to the stack how many bytes bytes where buffered for Tx stack.m_evalStack[1].NumericByRef().s4 = length; - + // flush DMA buffer to ensure cache coherency // (only required for Cortex-M7) cacheBufferFlush(palUart->TxRingBuffer.Reader(), length); @@ -738,18 +757,19 @@ HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_Serial uartAcquireBus(palUart->UartDriver); // start sending data (DMA will read from the ring buffer) - uartStartSend(palUart->UartDriver, length, (uint8_t*)palUart->TxRingBuffer.Reader()); + uartStartSend(palUart->UartDriver, length, (uint8_t *)palUart->TxRingBuffer.Reader()); } - while(eventResult) + while (eventResult) { // non-blocking wait allowing other threads to run while we wait for the Tx operation to complete - NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.WaitEvents( stack.m_owningThread, *timeoutTicks, CLR_RT_ExecutionEngine::c_Event_SerialPortOut, eventResult )); - + NANOCLR_CHECK_HRESULT( + g_CLR_RT_ExecutionEngine.WaitEvents(stack.m_owningThread, *timeoutTicks, Event_SerialPortOut, eventResult)); + // done here, release the UART uartReleaseBus(palUart->UartDriver); - if(eventResult) + if (eventResult) { // event occurred // get from the eval stack how many bytes were buffered to Tx @@ -760,7 +780,7 @@ HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_Serial } else { - NANOCLR_SET_AND_LEAVE( CLR_E_TIMEOUT ); + NANOCLR_SET_AND_LEAVE(CLR_E_TIMEOUT); } } @@ -775,14 +795,15 @@ HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_Serial NANOCLR_NOCLEANUP(); } -HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::NativeRead___U4__SZARRAY_U1__I4__I4( CLR_RT_StackFrame& stack ) +HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice:: + NativeRead___U4__SZARRAY_U1__I4__I4(CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); - CLR_RT_HeapBlock_Array* dataBuffer; - NF_PAL_UART* palUart = NULL; + CLR_RT_HeapBlock_Array *dataBuffer; + NF_PAL_UART *palUart = NULL; - uint8_t* data; + uint8_t *data; size_t dataLength = 0; size_t count = 0; @@ -791,13 +812,15 @@ HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_Serial InputStreamOptions options = InputStreamOptions_None; - int64_t* timeoutTicks; + int64_t *timeoutTicks; bool eventResult = true; // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); if(!(pThis)) FAULT_ON_NULL(pThis); + CLR_RT_HeapBlock *pThis = stack.This(); + if (!(pThis)) + FAULT_ON_NULL(pThis); - if(pThis[ FIELD___disposed ].NumericByRef().u1 != 0) + if (pThis[FIELD___disposed].NumericByRef().u1 != 0) { NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); } @@ -809,7 +832,7 @@ HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_Serial data = dataBuffer->GetFirstElement(); // get the length of the data buffer - dataLength = dataBuffer->m_numOfElements; + dataLength = dataBuffer->m_numOfElements; // get how many bytes are requested to read count = stack.Arg2().NumericByRef().s4; @@ -818,65 +841,65 @@ HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_Serial options = (InputStreamOptions)stack.Arg3().NumericByRef().s4; // Choose the driver for this SerialDevice - switch ((int)pThis[ FIELD___portIndex ].NumericByRef().s4) + switch ((int)pThis[FIELD___portIndex].NumericByRef().s4) { #if NF_SERIAL_COMM_STM32_UART_USE_USART1 - case 1 : + case 1: palUart = &Uart1_PAL; break; #endif #if NF_SERIAL_COMM_STM32_UART_USE_USART2 - case 2 : + case 2: palUart = &Uart2_PAL; break; #endif #if NF_SERIAL_COMM_STM32_UART_USE_USART3 - case 3 : + case 3: palUart = &Uart3_PAL; break; #endif #if NF_SERIAL_COMM_STM32_UART_USE_UART4 - case 4 : + case 4: palUart = &Uart4_PAL; break; #endif #if NF_SERIAL_COMM_STM32_UART_USE_UART5 - case 5 : + case 5: palUart = &Uart5_PAL; break; #endif #if NF_SERIAL_COMM_STM32_UART_USE_USART6 - case 6 : + case 6: palUart = &Uart6_PAL; break; #endif #if NF_SERIAL_COMM_STM32_UART_USE_UART7 - case 7 : + case 7: palUart = &Uart7_PAL; break; #endif #if NF_SERIAL_COMM_STM32_UART_USE_UART8 - case 8 : + case 8: palUart = &Uart8_PAL; break; #endif } // setup timeout from the _readtimeout heap block - NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTimeSpan( pThis[ FIELD___readTimeout ], timeoutTicks )); + NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTimeSpan(pThis[FIELD___readTimeout], timeoutTicks)); // figure out what's available in the Rx ring buffer - if(palUart->RxRingBuffer.Length() >= count) + if (palUart->RxRingBuffer.Length() >= count) { // read from Rx ring buffer bytesToRead = count; // is the read ahead option enabled? - if(options == InputStreamOptions_ReadAhead) + if (options == InputStreamOptions_ReadAhead) { // yes // check how many bytes we can store in the buffer argument - if(dataLength < palUart->RxRingBuffer.Length()) + if (dataLength < palUart->RxRingBuffer.Length()) { // read as many bytes has the buffer can hold bytesToRead = dataLength; @@ -890,30 +913,30 @@ HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_Serial // we have enough bytes, skip wait for event eventResult = false; - + // clear event by getting it Events_Get(SYSTEM_EVENT_FLAG_COM_IN); } else { - if(stack.m_customState == 1) + if (stack.m_customState == 1) { // not enough bytes available, have to read from UART palUart->RxBytesToRead = count; - + // clear event by getting it Events_Get(SYSTEM_EVENT_FLAG_COM_IN); // don't read anything from the buffer yet bytesToRead = 0; - } + } } - while(eventResult) + while (eventResult) { - if(stack.m_customState == 1) + if (stack.m_customState == 1) { - if(bytesToRead > 0) + if (bytesToRead > 0) { // enough bytes available eventResult = false; @@ -928,19 +951,21 @@ HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_Serial else { // wait for event - NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.WaitEvents(stack.m_owningThread, *timeoutTicks, CLR_RT_ExecutionEngine::c_Event_SerialPortIn, eventResult)); + NANOCLR_CHECK_HRESULT( + g_CLR_RT_ExecutionEngine + .WaitEvents(stack.m_owningThread, *timeoutTicks, Event_SerialPortIn, eventResult)); - if(!eventResult) + if (!eventResult) { // event timeout - // compute how many bytes to read + // compute how many bytes to read // considering the InputStreamOptions read ahead option - if(options == InputStreamOptions_ReadAhead) + if (options == InputStreamOptions_ReadAhead) { // yes // check how many bytes we can store in the buffer argument - if(dataLength < palUart->RxRingBuffer.Length()) + if (dataLength < palUart->RxRingBuffer.Length()) { // read as many bytes has the buffer can hold bytesToRead = dataLength; @@ -956,7 +981,7 @@ HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_Serial // take InputStreamOptions_Partial as default and read requested quantity or what's available bytesToRead = count; - if(count > palUart->RxRingBuffer.Length()) + if (count > palUart->RxRingBuffer.Length()) { // need to adjust because there aren't enough bytes available bytesToRead = palUart->RxRingBuffer.Length(); @@ -966,7 +991,7 @@ HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_Serial } } - if(bytesToRead > 0) + if (bytesToRead > 0) { // pop the requested bytes from the ring buffer bytesRead = palUart->RxRingBuffer.Pop(data, bytesToRead); @@ -981,58 +1006,60 @@ HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_Serial NANOCLR_NOCLEANUP(); } -HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::NativeSetWatchChar___VOID( CLR_RT_StackFrame& stack ) +HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::NativeSetWatchChar___VOID( + CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); { - NF_PAL_UART* palUart; + NF_PAL_UART *palUart; // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); // Choose the driver for this SerialDevice - switch ((int)pThis[ FIELD___portIndex ].NumericByRef().s4) + switch ((int)pThis[FIELD___portIndex].NumericByRef().s4) { - #if NF_SERIAL_COMM_STM32_UART_USE_USART1 - case 1 : +#if NF_SERIAL_COMM_STM32_UART_USE_USART1 + case 1: palUart = &Uart1_PAL; break; - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_USART2 - case 2 : +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_USART2 + case 2: palUart = &Uart2_PAL; break; - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_USART3 - case 3 : +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_USART3 + case 3: palUart = &Uart3_PAL; break; - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_UART4 - case 4 : +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_UART4 + case 4: palUart = &Uart4_PAL; break; - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_UART5 - case 5 : +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_UART5 + case 5: palUart = &Uart5_PAL; - break; - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_USART6 - case 6 : + break; +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_USART6 + case 6: palUart = &Uart6_PAL; - break; - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_UART7 - case 7 : + break; +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_UART7 + case 7: palUart = &Uart7_PAL; break; - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_UART8 - case 8 : +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_UART8 + case 8: palUart = &Uart8_PAL; break; - #endif +#endif default: // this COM port is not valid NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); @@ -1040,64 +1067,65 @@ HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_Serial } // set watch char - palUart->WatchChar = (uint8_t)pThis[ FIELD___watchChar ].NumericByRef().u1; - + palUart->WatchChar = (uint8_t)pThis[FIELD___watchChar].NumericByRef().u1; } - NANOCLR_NOCLEANUP(); + NANOCLR_NOCLEANUP(); } -HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::get_BytesToRead___U4( CLR_RT_StackFrame& stack ) +HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::get_BytesToRead___U4( + CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); { - NF_PAL_UART* palUart; + NF_PAL_UART *palUart; // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); // Choose the driver for this SerialDevice - switch ((int)pThis[ FIELD___portIndex ].NumericByRef().s4) + switch ((int)pThis[FIELD___portIndex].NumericByRef().s4) { - #if NF_SERIAL_COMM_STM32_UART_USE_USART1 - case 1 : +#if NF_SERIAL_COMM_STM32_UART_USE_USART1 + case 1: palUart = &Uart1_PAL; break; - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_USART2 - case 2 : +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_USART2 + case 2: palUart = &Uart2_PAL; break; - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_USART3 - case 3 : +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_USART3 + case 3: palUart = &Uart3_PAL; break; - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_UART4 - case 4 : +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_UART4 + case 4: palUart = &Uart4_PAL; break; - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_UART5 - case 5 : +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_UART5 + case 5: palUart = &Uart5_PAL; - break; - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_USART6 - case 6 : + break; +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_USART6 + case 6: palUart = &Uart6_PAL; - break; - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_UART7 - case 7 : + break; +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_UART7 + case 7: palUart = &Uart7_PAL; break; - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_UART8 - case 8 : +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_UART8 + case 8: palUart = &Uart8_PAL; break; - #endif +#endif default: // this COM port is not valid NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); @@ -1106,49 +1134,51 @@ HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_Serial // get length of Rx ring buffer stack.SetResult_U4(palUart->RxRingBuffer.Length()); - } - NANOCLR_NOCLEANUP(); + NANOCLR_NOCLEANUP(); } -HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::GetDeviceSelector___STATIC__STRING( CLR_RT_StackFrame& stack ) +HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice:: + GetDeviceSelector___STATIC__STRING(CLR_RT_StackFrame &stack) { - NANOCLR_HEADER(); - { - // declare the device selector string whose max size is "COM1,COM2,COM3,COM4,COM5,COM6,COM7,COM8," + terminator and init with the terminator - char deviceSelectorString[ 40 + 1] = { 0 }; - - #if NF_SERIAL_COMM_STM32_UART_USE_USART1 - strcat(deviceSelectorString, "COM1,"); - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_USART2 - strcat(deviceSelectorString, "COM2,"); - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_USART3 - strcat(deviceSelectorString, "COM3,"); - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_UART4 - strcat(deviceSelectorString, "COM4,"); - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_UART5 - strcat(deviceSelectorString, "COM5,"); - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_USART6 - strcat(deviceSelectorString, "COM6,"); - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_UART7 - strcat(deviceSelectorString, "COM7,"); - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_UART8 - strcat(deviceSelectorString, "COM8,"); - #endif - - // replace the last comma with a terminator - deviceSelectorString[hal_strlen_s(deviceSelectorString) - 1] = '\0'; - - // because the caller is expecting a result to be returned - // we need set a return result in the stack argument using the appropriate SetResult according to the variable type (a string here) - stack.SetResult_String(deviceSelectorString); - } - NANOCLR_NOCLEANUP_NOLABEL(); + NANOCLR_HEADER(); + { + // declare the device selector string whose max size is "COM1,COM2,COM3,COM4,COM5,COM6,COM7,COM8," + terminator + // and init with the terminator + char deviceSelectorString[40 + 1] = {0}; + +#if NF_SERIAL_COMM_STM32_UART_USE_USART1 + strcat(deviceSelectorString, "COM1,"); +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_USART2 + strcat(deviceSelectorString, "COM2,"); +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_USART3 + strcat(deviceSelectorString, "COM3,"); +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_UART4 + strcat(deviceSelectorString, "COM4,"); +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_UART5 + strcat(deviceSelectorString, "COM5,"); +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_USART6 + strcat(deviceSelectorString, "COM6,"); +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_UART7 + strcat(deviceSelectorString, "COM7,"); +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_UART8 + strcat(deviceSelectorString, "COM8,"); +#endif + + // replace the last comma with a terminator + deviceSelectorString[hal_strlen_s(deviceSelectorString) - 1] = '\0'; + + // because the caller is expecting a result to be returned + // we need set a return result in the stack argument using the appropriate SetResult according to the variable + // type (a string here) + stack.SetResult_String(deviceSelectorString); + } + NANOCLR_NOCLEANUP_NOLABEL(); } diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.SerialCommunication/win_dev_serial_native_target.h b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.SerialCommunication/win_dev_serial_native_target.h index 57f70acc66..fd3bd05133 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.SerialCommunication/win_dev_serial_native_target.h +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.SerialCommunication/win_dev_serial_native_target.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // @@ -10,62 +10,63 @@ #include #include -// struct representing the UART -struct NF_PAL_UART +// struct representing the UART +typedef struct { - UARTDriver* UartDriver; + UARTDriver *UartDriver; UARTConfig Uart_cfg; HAL_RingBuffer TxRingBuffer; - uint8_t* TxBuffer; + uint8_t *TxBuffer; uint16_t TxOngoingCount; HAL_RingBuffer RxRingBuffer; - uint8_t* RxBuffer; + uint8_t *RxBuffer; uint16_t RxBytesToRead; uint8_t WatchChar; -}; - +} NF_PAL_UART; //////////////////////////////////////////// // declaration of the the UART PAL strucs // //////////////////////////////////////////// #if NF_SERIAL_COMM_STM32_UART_USE_USART1 - extern NF_PAL_UART Uart1_PAL; +extern NF_PAL_UART Uart1_PAL; #endif #if NF_SERIAL_COMM_STM32_UART_USE_USART2 - extern NF_PAL_UART Uart2_PAL; +extern NF_PAL_UART Uart2_PAL; #endif #if NF_SERIAL_COMM_STM32_UART_USE_USART3 - extern NF_PAL_UART Uart3_PAL; +extern NF_PAL_UART Uart3_PAL; #endif #if NF_SERIAL_COMM_STM32_UART_USE_UART4 - extern NF_PAL_UART Uart4_PAL; +extern NF_PAL_UART Uart4_PAL; #endif #if NF_SERIAL_COMM_STM32_UART_USE_UART5 - extern NF_PAL_UART Uart5_PAL; +extern NF_PAL_UART Uart5_PAL; #endif #if NF_SERIAL_COMM_STM32_UART_USE_USART6 - extern NF_PAL_UART Uart6_PAL; +extern NF_PAL_UART Uart6_PAL; #endif #if NF_SERIAL_COMM_STM32_UART_USE_UART7 - extern NF_PAL_UART Uart7_PAL; +extern NF_PAL_UART Uart7_PAL; #endif #if NF_SERIAL_COMM_STM32_UART_USE_UART8 - extern NF_PAL_UART Uart8_PAL; +extern NF_PAL_UART Uart8_PAL; #endif // the following macro defines a function that configures the GPIO pins for a STM32 UART/USART // it gets called in the Windows_Devices_SerialCommunication_SerialDevice::NativeConfig function // this is required because the UART/USART peripherals can use multiple GPIO configuration combinations -#define UART_CONFIG_PINS(num, gpio_port_tx, gpio_port_rx, tx_pin, rx_pin, alternate_function) void ConfigPins_UART##num() { \ - palSetPadMode(gpio_port_tx, tx_pin, PAL_MODE_ALTERNATE(alternate_function)); \ - palSetPadMode(gpio_port_rx, rx_pin, PAL_MODE_ALTERNATE(alternate_function)); \ +#define UART_CONFIG_PINS(num, gpio_port_tx, gpio_port_rx, tx_pin, rx_pin, alternate_function) \ + void ConfigPins_UART##num() \ + { \ + palSetPadMode(gpio_port_tx, tx_pin, PAL_MODE_ALTERNATE(alternate_function)); \ + palSetPadMode(gpio_port_rx, rx_pin, PAL_MODE_ALTERNATE(alternate_function)); \ } /////////////////////////////////////////////////////////////////////////////////////////////////// -// when a UART/USART is defined the declarations below will have the real function/configuration +// when a UART/USART is defined the declarations below will have the real function/configuration // in the target folder @ target_windows_devices_serialcommunication_config.cpp /////////////////////////////////////////////////////////////////////////////////////////////////// void ConfigPins_UART1(); @@ -77,7 +78,6 @@ void ConfigPins_UART6(); void ConfigPins_UART7(); void ConfigPins_UART8(); - ///////////////////////////////////// // UART Tx buffers // // these live in the target folder // @@ -91,7 +91,6 @@ extern uint8_t Uart6_TxBuffer[]; extern uint8_t Uart7_TxBuffer[]; extern uint8_t Uart8_TxBuffer[]; - ///////////////////////////////////// // UART Rx buffers // // these live in the target folder // @@ -105,54 +104,56 @@ extern uint8_t Uart6_RxBuffer[]; extern uint8_t Uart7_RxBuffer[]; extern uint8_t Uart8_RxBuffer[]; - // the following macro defines a function that initializes an UART struct // it gets called in the Windows_Devices_SerialCommunication_SerialDevice::NativeInit function #if defined(STM32F7XX) || defined(STM32F0XX) // STM32F7 and STM32F0 use UART driver v2 -#define UART_INIT(num, tx_buffer_size, rx_buffer_size) void Init_UART##num() { \ - Uart##num##_PAL.Uart_cfg.txend2_cb = NULL; \ - Uart##num##_PAL.Uart_cfg.rxend_cb = NULL; \ - Uart##num##_PAL.Uart_cfg.rxerr_cb = NULL; \ - Uart##num##_PAL.Uart_cfg.timeout_cb = NULL; \ - Uart##num##_PAL.Uart_cfg.timeout = 0; \ - Uart##num##_PAL.Uart_cfg.speed = 9600; \ - Uart##num##_PAL.Uart_cfg.cr1 = 0; \ - Uart##num##_PAL.Uart_cfg.cr2 = 0; \ - Uart##num##_PAL.Uart_cfg.cr3 = 0; \ - Uart##num##_PAL.TxBuffer = Uart##num##_TxBuffer; \ - Uart##num##_PAL.TxRingBuffer.Initialize( Uart##num##_PAL.TxBuffer, tx_buffer_size); \ - Uart##num##_PAL.TxOngoingCount = 0; \ - Uart##num##_PAL.RxBuffer = Uart##num##_RxBuffer; \ - Uart##num##_PAL.RxRingBuffer.Initialize( Uart##num##_PAL.RxBuffer, rx_buffer_size); \ - Uart##num##_PAL.WatchChar = 0; \ -} +#define UART_INIT(num, tx_buffer_size, rx_buffer_size) \ + void Init_UART##num() \ + { \ + Uart##num##_PAL.Uart_cfg.txend2_cb = NULL; \ + Uart##num##_PAL.Uart_cfg.rxend_cb = NULL; \ + Uart##num##_PAL.Uart_cfg.rxerr_cb = NULL; \ + Uart##num##_PAL.Uart_cfg.timeout_cb = NULL; \ + Uart##num##_PAL.Uart_cfg.timeout = 0; \ + Uart##num##_PAL.Uart_cfg.speed = 9600; \ + Uart##num##_PAL.Uart_cfg.cr1 = 0; \ + Uart##num##_PAL.Uart_cfg.cr2 = 0; \ + Uart##num##_PAL.Uart_cfg.cr3 = 0; \ + Uart##num##_PAL.TxBuffer = Uart##num##_TxBuffer; \ + Uart##num##_PAL.TxRingBuffer.Initialize(Uart##num##_PAL.TxBuffer, tx_buffer_size); \ + Uart##num##_PAL.TxOngoingCount = 0; \ + Uart##num##_PAL.RxBuffer = Uart##num##_RxBuffer; \ + Uart##num##_PAL.RxRingBuffer.Initialize(Uart##num##_PAL.RxBuffer, rx_buffer_size); \ + Uart##num##_PAL.WatchChar = 0; \ + } #else // all other STM32F use UART driver v1 which has a different UARTConfig struct -#define UART_INIT(num, tx_buffer_size, rx_buffer_size) void Init_UART##num() { \ - Uart##num##_PAL.Uart_cfg.txend2_cb = NULL; \ - Uart##num##_PAL.Uart_cfg.rxend_cb = NULL; \ - Uart##num##_PAL.Uart_cfg.rxerr_cb = NULL; \ - Uart##num##_PAL.Uart_cfg.speed = 9600; \ - Uart##num##_PAL.Uart_cfg.cr1 = 0; \ - Uart##num##_PAL.Uart_cfg.cr2 = 0; \ - Uart##num##_PAL.Uart_cfg.cr3 = 0; \ - Uart##num##_PAL.TxBuffer = Uart##num##_TxBuffer; \ - Uart##num##_PAL.TxRingBuffer.Initialize( Uart##num##_PAL.TxBuffer, tx_buffer_size); \ - Uart##num##_PAL.TxOngoingCount = 0; \ - Uart##num##_PAL.RxBuffer = Uart##num##_RxBuffer; \ - Uart##num##_PAL.RxRingBuffer.Initialize( Uart##num##_PAL.RxBuffer, rx_buffer_size); \ - Uart##num##_PAL.WatchChar = 0; \ -} +#define UART_INIT(num, tx_buffer_size, rx_buffer_size) \ + void Init_UART##num() \ + { \ + Uart##num##_PAL.Uart_cfg.txend2_cb = NULL; \ + Uart##num##_PAL.Uart_cfg.rxend_cb = NULL; \ + Uart##num##_PAL.Uart_cfg.rxerr_cb = NULL; \ + Uart##num##_PAL.Uart_cfg.speed = 9600; \ + Uart##num##_PAL.Uart_cfg.cr1 = 0; \ + Uart##num##_PAL.Uart_cfg.cr2 = 0; \ + Uart##num##_PAL.Uart_cfg.cr3 = 0; \ + Uart##num##_PAL.TxBuffer = Uart##num##_TxBuffer; \ + Uart##num##_PAL.TxRingBuffer.Initialize(Uart##num##_PAL.TxBuffer, tx_buffer_size); \ + Uart##num##_PAL.TxOngoingCount = 0; \ + Uart##num##_PAL.RxBuffer = Uart##num##_RxBuffer; \ + Uart##num##_PAL.RxRingBuffer.Initialize(Uart##num##_PAL.RxBuffer, rx_buffer_size); \ + Uart##num##_PAL.WatchChar = 0; \ + } #endif - -// when a UART/USART is defined the declarations below will have the real function/configuration +// when a UART/USART is defined the declarations below will have the real function/configuration // in the target folder @ target_windows_devices_serialcommunication_config.cpp void Init_UART1(); void Init_UART2(); @@ -163,12 +164,15 @@ void Init_UART6(); void Init_UART7(); void Init_UART8(); - // the following macro defines a function that un initializes an UART struct // it gets called in the Windows_Devices_SerialCommunication_SerialDevice::NativeDispose function -#define UART_UNINIT(num) void UnInit_UART##num() { return; } +#define UART_UNINIT(num) \ + void UnInit_UART##num() \ + { \ + return; \ + } -// when a UART/USART is defined the declarations below will have the real function/configuration +// when a UART/USART is defined the declarations below will have the real function/configuration // in the target folder @ target_windows_devices_serialcommunication_config.cpp void UnInit_UART1(); void UnInit_UART2(); @@ -179,4 +183,4 @@ void UnInit_UART6(); void UnInit_UART7(); void UnInit_UART8(); -#endif //_WIN_DEV_SERIAL_NATIVE_TARGET_H_ +#endif //_WIN_DEV_SERIAL_NATIVE_TARGET_H_ diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.Spi/CPU_SPI.cpp b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.Spi/CPU_SPI.cpp new file mode 100644 index 0000000000..75f4835878 --- /dev/null +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.Spi/CPU_SPI.cpp @@ -0,0 +1,778 @@ +// +// Copyright (c) .NET Foundation and Contributors +// See LICENSE file in the project root for full license information. +// + +#include +#include +#include +#include +#include +#include + +#include +#include + +///////////////////////////////////////////////////// +// SPI PAL strucs declared in win_dev_spi_native.h // +///////////////////////////////////////////////////// +#if STM32_SPI_USE_SPI1 +NF_PAL_SPI SPI1_PAL; +#endif +#if STM32_SPI_USE_SPI2 +NF_PAL_SPI SPI2_PAL; +#endif +#if STM32_SPI_USE_SPI3 +NF_PAL_SPI SPI3_PAL; +#endif +#if STM32_SPI_USE_SPI4 +NF_PAL_SPI SPI4_PAL; +#endif +#if STM32_SPI_USE_SPI5 +NF_PAL_SPI SPI5_PAL; +#endif +#if STM32_SPI_USE_SPI6 +NF_PAL_SPI SPI6_PAL; +#endif + +// Tidy up after completing tranfer +static void CompleteTranfer(NF_PAL_SPI *palSpi) +{ + // just to satisfy the driver ceremony, no actual implementation for STM32 + spiUnselect(palSpi->Driver); + + // Release the bus + spiReleaseBus(palSpi->Driver); + + // event occurred + if (palSpi->ReadSize > 0) + { + // because this was a Read transaction, need to copy from DMA buffer to managed buffer + int ReadSize = palSpi->ReadSize; + + // Adjust read size for data width of 16bits + if (palSpi->BufferIs16bits) + ReadSize *= 2; + + // invalidate cache over read buffer to ensure that content from DMA is read + // (only required for Cortex-M7) + // get the pointer to the read buffer as UINT16 because it's really an UINT16 (2 bytes) + cacheBufferInvalidate(palSpi->ReadBuffer, (palSpi->ReadSize * 2)); + } +} + +// Callback used when a async opertion completes +static void SpiCallback(SPIDriver *spip) +{ + (void)spip; + + NATIVE_INTERRUPT_START + + NF_PAL_SPI *palSpi = NULL; + + // Find the NF_PAL_SPI * for driver +#if STM32_SPI_USE_SPI1 + if (spip == &SPID1) + { + palSpi = &SPI1_PAL; + } +#endif +#if STM32_SPI_USE_SPI2 + if (spip == &SPID2) + { + palSpi = &SPI2_PAL; + } +#endif +#if STM32_SPI_USE_SPI3 + if (spip == &SPID3) + { + palSpi = &SPI3_PAL; + } +#endif +#if STM32_SPI_USE_SPI4 + if (spip == &SPID4) + { + palSpi = &SPI4_PAL; + } +#endif +#if STM32_SPI_USE_SPI5 + if (spip == &SPID5) + { + palSpi = &SPI5_PAL; + } +#endif +#if STM32_SPI_USE_SPI6 + if (spip == &SPID6) + { + palSpi = &SPI6_PAL; + } +#endif + + // check if there is any Rx operation due + if (palSpi->SequentialTxRx) + { + // yes there is! + // clear flag and... + palSpi->SequentialTxRx = false; + + // ... start it + spiStartReceive(palSpi->Driver, palSpi->ReadSize, palSpi->ReadBuffer); + } + else + { + // all done here! + + // Tidy up, release etc + CompleteTranfer(palSpi); + + // fire callback for SPI transaction complete + // only if callback set + if (palSpi->Callback) + palSpi->Callback(palSpi->BusIndex); + } + + NATIVE_INTERRUPT_END +}; + +// Computes the SPI peripheral baud rate according to the requested frequency +uint16_t ComputeBaudRate(SPI_DEVICE_CONFIGURATION &config, int32_t &actualFrequency) +{ + uint16_t divider = 0; + int32_t maxSpiFrequency; + int32_t requestedFrequency = config.Clock_RateHz; + int busIndex = config.Spi_Bus; + +#if defined(STM32L0XX) + + // SP1 is feed by APB2 (STM32_PCLK2) + actualFrequency = STM32_PCLK2; + + // SPI2 is feed by APB1 (STM32_PCLK1) + if (busIndex == 1) + { + actualFrequency = STM32_PCLK1; + } + + // from datasheet + maxSpiFrequency = 12000000; + +#elif defined(STM32F0XX) + + (void)busIndex; + + // STM32F0 SPI is always feed by APB1 + actualFrequency = STM32_PCLK1; + + // from datasheet + maxSpiFrequency = 18000000; + +#elif defined(STM32F4XX) || defined(STM32F7XX) + + // SP1, SPI4, SPI5 and SPI6 are feed by APB2 (STM32_PCLK2) + actualFrequency = STM32_PCLK2; + + // SPI2 and SPI3 are feed by APB1 (STM32_PCLK1) + if (busIndex == 2 || busIndex == 3) + { + actualFrequency = STM32_PCLK1; + } + + // this is not really accurate because there are different max SPI clocks depending on which APB clock source if + // feeding the SPI because ChibiOS doesn't offer that we have to go with minimum common denominator + maxSpiFrequency = STM32_SPII2S_MAX; + +#elif defined(STM32H7XX) + + // SP1, SPI4, SPI5 and SPI6 are feed by APB2 (STM32_PCLK2) + actualFrequency = STM32_PCLK2; + maxSpiFrequency = STM32_SPI456_MAX; + + // SPI1, SPI2 and SPI3 are feed by APB1 (STM32_PCLK1) + if (busIndex == 2 || busIndex == 3) + { + actualFrequency = STM32_PCLK1; + maxSpiFrequency = STM32_SPI123_MAX; + } + +#else + +#error "Error setting max SPI frequency. Check if the target series is defined." + +#endif + + // when requested frequency is 0, means that the developer hasn't set ClockFrequency in SpiConnectionSettings + // default to the max possible SPI frequency + if (requestedFrequency == 0) + { + requestedFrequency = maxSpiFrequency; + } + + for (; divider < 8; divider++) + { + actualFrequency = actualFrequency / 2; + + if (actualFrequency <= requestedFrequency) + { + // best match for the requested frequency + // just check if it's below the max SPI frequency + if (actualFrequency <= maxSpiFrequency) + { + // we are good with this value + break; + } + } + } + + // the baud rate bits are in the position B5:3 so need to left shit the divider value + return divider << 3; +} + +// Return the NF_PAL structure for busIndex +// Return NULL is invalid bus +NF_PAL_SPI *GetNfPalfromBusIndex(uint8_t busIndex) +{ + NF_PAL_SPI *palSpi = NULL; + + // get the PAL struct for the SPI bus + switch (busIndex) + { +#if STM32_SPI_USE_SPI1 + case 1: + palSpi = &SPI1_PAL; + break; +#endif +#if STM32_SPI_USE_SPI2 + case 2: + palSpi = &SPI2_PAL; + break; +#endif +#if STM32_SPI_USE_SPI3 + case 3: + palSpi = &SPI3_PAL; + break; +#endif +#if STM32_SPI_USE_SPI4 + case 4: + palSpi = &SPI4_PAL; + break; +#endif +#if STM32_SPI_USE_SPI5 + case 5: + palSpi = &SPI5_PAL; + break; +#endif +#if STM32_SPI_USE_SPI6 + case 6: + palSpi = &SPI6_PAL; + break; +#endif + default: + // the requested SPI bus is not valid + break; + } + + return palSpi; +} + +// Give a complete low-level SPI configuration from passed SPI_DEVICE_CONFIGURATION +void GetSPIConfig(SPI_DEVICE_CONFIGURATION &config, SPI_WRITE_READ_SETTINGS &wrc, SPIConfig *llConfig) +{ + int32_t actualFrequency; + + // clear values + llConfig->cr1 = 0; + llConfig->cr2 = 0; + + // get chip select pin + int csPin = config.DeviceChipSelect; + + // SPI mode + switch (config.Spi_Mode) + { + case SpiMode_Mode1: + llConfig->cr1 |= SPI_CR1_CPHA; + break; + + case SpiMode_Mode2: + llConfig->cr1 |= SPI_CR1_CPOL; + break; + + case SpiMode_Mode3: + llConfig->cr1 |= SPI_CR1_CPHA | SPI_CR1_CPOL; + break; + + default: // Default to Mode0 if invalid mode specified + break; + } + + // compute baud rate of SPI peripheral according to the requested frequency + llConfig->cr1 |= ComputeBaudRate(config, actualFrequency); + + // set data transfer length according passed setting + if (wrc.Bits16ReadWrite) + { + // Set data transfer length to 16 bits +#ifdef STM32F4XX + llConfig->cr1 |= SPI_CR1_DFF; +#endif +#ifdef STM32F7XX + llConfig->cr2 = SPI_CR2_DS_3 | SPI_CR2_DS_2 | SPI_CR2_DS_1 | SPI_CR2_DS_0; +#endif + // Sets the order of bytes transmission : MSB first or LSB first + int bitOrder = config.DataOrder16; + if (bitOrder == DataBitOrder_LSB) + { + llConfig->cr1 |= SPI_CR1_LSBFIRST; + } + } + else + { + // set transfer length to 8bits +#ifdef STM32F4XX + llConfig->cr1 &= ~SPI_CR1_DFF; +#endif +#ifdef STM32F7XX + llConfig->cr2 |= SPI_CR2_DS_2 | SPI_CR2_DS_1 | SPI_CR2_DS_0; +#endif + } + + // Create the low level configuration +#if (SPI_SUPPORTS_CIRCULAR == TRUE) + llConfig->circular = SPI_USE_CIRCULAR; +#endif + llConfig->end_cb = SpiCallback; + + // make sure the CS pin is properly configured as GPIO, output & pushpull + palSetPadMode(GPIO_PORT(csPin), csPin % 16, (PAL_STM32_OSPEED_HIGHEST | PAL_MODE_OUTPUT_PUSHPULL)); + + // being SPI CS active low, default it to high + palSetPad(GPIO_PORT(csPin), csPin % 16); + + // set port&pad for CS pin + llConfig->ssport = GPIO_PORT(csPin); + llConfig->sspad = csPin % 16; +} + +// Performs a read/write operation on 8-bit word data. +// +// Parameters +// deviceHandle +// Device handle from add_device +// sdev +// reference to SPI_DEVICE_CONFIGURATION +// wrc +// reference to SPI_WRITE_READ_SETTINGS +// writeData +// A pointer to the buffer from which the data is to be written to the device. +// writeSize +// The number of elements(8 or 16) to be written. +// readData +// A pointer to the buffer into which the data is to be read from the device. +// readSize +// The number of elements(8 or 16) to be read. +// +// return S_OK=Successful, Async started=CLR_BUSY, Error=CLR_E_OUT_OF_MEMORY, CLR_E_INVALID_PARAMETER, CLR_E_FAIL +// +HRESULT CPU_SPI_nWrite_nRead( + uint32_t deviceHandle, + SPI_DEVICE_CONFIGURATION &sdev, + SPI_WRITE_READ_SETTINGS &wrc, + uint8_t *writeBuffer, + int32_t writeSize, + uint8_t *readBuffer, + int32_t readSize) +{ + NANOCLR_HEADER(); + { + NF_PAL_SPI *palSpi = (NF_PAL_SPI *)deviceHandle; + bool sync = (wrc.callback == 0); // If callback then use aync operation + + // Save width of transfer + palSpi->BufferIs16bits = wrc.Bits16ReadWrite; + + // Callback sync / async + palSpi->Callback = wrc.callback; + + if (writeBuffer != NULL) + { + palSpi->WriteSize = writeSize; + } + + if (readBuffer != NULL) + { + palSpi->ReadSize = readSize; + } + + // === Setup the operation and init buffers === + palSpi->BusIndex = sdev.Spi_Bus; + + // get the LL SPI configuration, depending on passed parameters and buffer element size + GetSPIConfig(sdev, wrc, &palSpi->Configuration); + + // Clear callback if sync + if (sync) + palSpi->Configuration.end_cb = NULL; + + if (writeBuffer != NULL) + { + // set the pointer to the write buffer as BYTE + palSpi->WriteBuffer = (uint8_t *)writeBuffer; + + // set DMA write buffer + if (palSpi->BufferIs16bits) + { + // flush DMA buffer to ensure cache coherency + // (only required for Cortex-M7) + cacheBufferFlush(palSpi->WriteBuffer, (palSpi->WriteSize * 2)); + } + else + { + // flush DMA buffer to ensure cache coherency + // (only required for Cortex-M7) + cacheBufferFlush(palSpi->WriteBuffer, palSpi->WriteSize); + } + } + + if (readBuffer != NULL) + { + // set DMA read buffer + if (palSpi->ReadSize > 0) + { + palSpi->ReadBuffer = (uint8_t *)readBuffer; + } + } + + // because the bus access is shared, acquire and select the appropriate bus + spiAcquireBus(palSpi->Driver); + spiStart(palSpi->Driver, &palSpi->Configuration); + + // just to satisfy the driver ceremony, no actual implementation for STM32 + spiSelect(palSpi->Driver); + + if (sync) + { + // Sync operation + // perform SPI operation using driver's SYNC API + if (palSpi->WriteSize != 0 && palSpi->ReadSize != 0) + { + // Transmit+Receive + if (wrc.fullDuplex) + { + // Full duplex + // Uses the largest buffer size as transfer size + spiExchange( + palSpi->Driver, + palSpi->WriteSize > palSpi->ReadSize ? palSpi->WriteSize : palSpi->ReadSize, + palSpi->WriteBuffer, + palSpi->ReadBuffer); + } + else + { + // send operation + spiSend(palSpi->Driver, palSpi->WriteSize, palSpi->WriteBuffer); + // receive operation + spiReceive(palSpi->Driver, palSpi->ReadSize, palSpi->ReadBuffer); + } + } + else + { + // Transmit only or Receive only + if (palSpi->ReadSize != 0) + { + // receive + spiReceive(palSpi->Driver, palSpi->ReadSize, palSpi->ReadBuffer); + } + else + { + // send + spiSend(palSpi->Driver, palSpi->WriteSize, palSpi->WriteBuffer); + } + } + + // Release bus & cacheBufferInvalidate etc + CompleteTranfer(palSpi); + } + else + // Start an Asyncronous SPI transfer + // perform SPI operation using driver's ASYNC API + // Completed on calling Spi Callback + { + // this is a Async operation + // perform SPI operation using driver's ASYNC API + if (palSpi->WriteSize != 0 && palSpi->ReadSize != 0) + { + // Transmit+Receive + if (wrc.fullDuplex) + { + // Full duplex + // single operation, clear flag + palSpi->SequentialTxRx = false; + + // Uses the largest buffer size as transfer size + spiStartExchange( + palSpi->Driver, + palSpi->WriteSize > palSpi->ReadSize ? palSpi->WriteSize : palSpi->ReadSize, + palSpi->WriteBuffer, + palSpi->ReadBuffer); + } + else + { + // flag that an Rx is required after the Tx operation completes + palSpi->SequentialTxRx = true; + + // start send operation + spiStartSend(palSpi->Driver, palSpi->WriteSize, palSpi->WriteBuffer); + // receive operation will be started in the callback after the above completes + } + } + else + { + // Transmit only or Receive only + if (palSpi->ReadSize != 0) + { + // single operation, clear flag + palSpi->SequentialTxRx = false; + + // start receive + spiStartReceive(palSpi->Driver, palSpi->ReadSize, palSpi->ReadBuffer); + } + else + { + // single operation, clear flag + palSpi->SequentialTxRx = false; + + // start send + spiStartSend(palSpi->Driver, palSpi->WriteSize, palSpi->WriteBuffer); + } + } + + // Inform caller async operation started + NANOCLR_SET_AND_LEAVE(CLR_E_BUSY); + } + } + + NANOCLR_NOCLEANUP(); +} + +SPI_OP_STATUS CPU_SPI_OP_Status(uint8_t spi_bus, uint32_t deviceHandle) +{ + (void)spi_bus; + + NF_PAL_SPI *palSpi = (NF_PAL_SPI *)deviceHandle; + SPI_OP_STATUS os; + + switch (palSpi->Driver->state) + { + default: + case SPI_UNINIT: + case SPI_STOP: + case SPI_READY: + os = SPI_OP_READY; + break; + + case SPI_ACTIVE: + os = SPI_OP_RUNNING; + break; + + case SPI_COMPLETE: + os = SPI_OP_COMPLETE; + break; + } + return os; +} + +bool CPU_SPI_Initialize(uint8_t busIndex) +{ + // init the PAL struct for this SPI bus and assign the respective driver + // all this occurs if not already done + // why do we need this? because several SPIDevice objects can be created associated to the same bus + switch (busIndex + 1) + { +#if STM32_SPI_USE_SPI1 + case 1: + if (SPI1_PAL.Driver == NULL) + { + ConfigPins_SPI1(); + SPI1_PAL.Driver = &SPID1; + } + break; +#endif +#if STM32_SPI_USE_SPI2 + case 2: + if (SPI2_PAL.Driver == NULL) + { + ConfigPins_SPI2(); + SPI2_PAL.Driver = &SPID2; + } + break; +#endif +#if STM32_SPI_USE_SPI3 + case 3: + if (SPI3_PAL.Driver == NULL) + { + ConfigPins_SPI3(); + SPI3_PAL.Driver = &SPID3; + } + break; +#endif +#if STM32_SPI_USE_SPI4 + case 4: + if (SPI4_PAL.Driver == NULL) + { + ConfigPins_SPI4(); + SPI4_PAL.Driver = &SPID4; + } + break; +#endif +#if STM32_SPI_USE_SPI5 + case 5: + if (SPI5_PAL.Driver == NULL) + { + ConfigPins_SPI5(); + SPI5_PAL.Driver = &SPID5; + } + break; +#endif +#if STM32_SPI_USE_SPI6 + case 6: + if (SPI6_PAL.Driver == NULL) + { + ConfigPins_SPI6(); + SPI6_PAL.Driver = &SPID6; + } + break; +#endif + default: + // this SPI bus is not valid + return false; + } + + return true; +} + +bool CPU_SPI_Uninitialize(uint8_t busIndex) +{ + // get the PAL struct for the SPI bus + switch (busIndex + 1) + { +#if STM32_SPI_USE_SPI1 + case 1: + spiStop(&SPID1); + SPI1_PAL.Driver = NULL; + spiReleaseBus(&SPID1); + break; +#endif + +#if STM32_SPI_USE_SPI2 + case 2: + spiStop(&SPID2); + SPI2_PAL.Driver = NULL; + spiReleaseBus(&SPID2); + break; +#endif + +#if STM32_SPI_USE_SPI3 + case 3: + spiStop(&SPID3); + SPI3_PAL.Driver = NULL; + spiReleaseBus(&SPID3); + break; +#endif + +#if STM32_SPI_USE_SPI4 + case 4: + spiStop(&SPID4); + SPI4_PAL.Driver = NULL; + spiReleaseBus(&SPID4); + break; +#endif + +#if STM32_SPI_USE_SPI5 + case 5: + spiStop(&SPID5); + SPI5_PAL.Driver = NULL; + spiReleaseBus(&SPID5); + break; +#endif + +#if STM32_SPI_USE_SPI6 + case 6: + spiStop(&SPID6); + SPI6_PAL.Driver = NULL; + spiReleaseBus(&SPID6); + break; +#endif + + default: + // the requested SPI bus is not valid + return false; + } + + return true; +} + +// return Map of available SPI ports +uint32_t CPU_SPI_PortsMap() +{ + uint32_t map = 0; + +#if STM32_SPI_USE_SPI1 + map |= 0x01; +#endif +#if STM32_SPI_USE_SPI2 + map |= 0x02; +#endif +#if STM32_SPI_USE_SPI3 + map |= 0x04; +#endif +#if STM32_SPI_USE_SPI4 + map |= 0x08; +#endif +#if STM32_SPI_USE_SPI5 + map |= 0x10; +#endif +#if STM32_SPI_USE_SPI6 + map |= 0x20; +#endif + return map; +} + +// Add a device to SPi Bus (Optional) +// Returns a device handle. Returns 0 if error +uint32_t CPU_SPI_Add_Device(const SPI_DEVICE_CONFIGURATION &spiDeviceConfig) +{ + return (uint32_t)GetNfPalfromBusIndex(spiDeviceConfig.Spi_Bus); +} + +// Return pins used for SPI bus +void CPU_SPI_GetPins(uint32_t spi_bus, GPIO_PIN &clk, GPIO_PIN &miso, GPIO_PIN &mosi) +{ + (void)spi_bus; + + clk = (GPIO_PIN)-1; + miso = (GPIO_PIN)-1; + mosi = (GPIO_PIN)-1; +} + +// Minimum and Maximum clock frequency available based on bus and configured pins +uint32_t CPU_SPI_MinClockFrequency(uint32_t spi_bus) +{ + // Max prescaler value = 256 + // SPI2 or SPI3 are on APB1, so divide max frequency by four. + return (spi_bus == 2 or spi_bus == 3) ? SystemCoreClock >>= 9 : SystemCoreClock >> 8; +} + +uint32_t CPU_SPI_MaxClockFrequency(uint32_t spi_bus) +{ + // According to STM : "At a minimum, the clock frequency should be twice the required communication frequency." + // So maximum useable frequency is CoreClock / 2. + // SPI2 or SPI3 are on APB1, so divide max frequency by four. + return (spi_bus == 2 or spi_bus == 3) ? SystemCoreClock >>= 2 : SystemCoreClock >> 1; +} + +// Maximum number of SPI devices that can be opened on a bus +uint32_t CPU_SPI_ChipSelectLineCount(uint32_t spi_bus) +{ + (void)spi_bus; + return 10; +} diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.Spi/win_dev_spi_native_Windows_Devices_Spi_SpiBusInfo.cpp b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.Spi/win_dev_spi_native_Windows_Devices_Spi_SpiBusInfo.cpp deleted file mode 100644 index 3f777bf727..0000000000 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.Spi/win_dev_spi_native_Windows_Devices_Spi_SpiBusInfo.cpp +++ /dev/null @@ -1,43 +0,0 @@ -// -// Copyright (c) 2017 The nanoFramework project contributors -// See LICENSE file in the project root for full license information. -// - - -#include "win_dev_spi_native_target.h" - - -HRESULT Library_win_dev_spi_native_Windows_Devices_Spi_SpiBusInfo::get_MaxClockFrequency___I4( CLR_RT_StackFrame& stack ) -{ - NANOCLR_HEADER(); - { - CLR_RT_HeapBlock* pArg = &(stack.Arg1()); - - // spiBus is an ASCII string with the bus name in format 'SPIn' - // need to grab 'n' from the string and convert to the integer value from the ASCII code - uint8_t bus = (uint8_t)pArg[0].RecoverString()[3] - 48; - - // According to STM : "At a minimum, the clock frequency should be twice the required communication frequency." - // So maximum useable frequency is CoreClock / 2. - // SPI2 or SPI3 are on APB1, so divide max frequency by four. - stack.SetResult_I4 ((bus == 2 or bus == 3) ? SystemCoreClock >>= 2 : SystemCoreClock >> 1); - } - NANOCLR_NOCLEANUP_NOLABEL(); -} - -HRESULT Library_win_dev_spi_native_Windows_Devices_Spi_SpiBusInfo::get_MinClockFrequency___I4( CLR_RT_StackFrame& stack ) -{ - NANOCLR_HEADER(); - { - CLR_RT_HeapBlock* pArg = &(stack.Arg1()); - - // spiBus is an ASCII string with the bus name in format 'SPIn' - // need to grab 'n' from the string and convert to the integer value from the ASCII code - uint8_t bus = (uint8_t)pArg[0].RecoverString()[3] - 48; - - // Max prescaler value = 256 - // SPI2 or SPI3 are on APB1, so divide max frequency by four. - stack.SetResult_I4 ((bus == 2 or bus == 3) ? SystemCoreClock >>= 9 : SystemCoreClock >> 8); - } - NANOCLR_NOCLEANUP_NOLABEL(); -} diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.Spi/win_dev_spi_native_Windows_Devices_Spi_SpiController.cpp b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.Spi/win_dev_spi_native_Windows_Devices_Spi_SpiController.cpp deleted file mode 100644 index 17e41c9763..0000000000 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.Spi/win_dev_spi_native_Windows_Devices_Spi_SpiController.cpp +++ /dev/null @@ -1,44 +0,0 @@ -// -// Copyright (c) 2018 The nanoFramework project contributors -// See LICENSE file in the project root for full license information. -// - - -#include "win_dev_spi_native_target.h" - - -HRESULT Library_win_dev_spi_native_Windows_Devices_Spi_SpiController::GetDeviceSelector___STATIC__STRING( CLR_RT_StackFrame& stack ) -{ - NANOCLR_HEADER(); - { - // declare the device selector string whose max size is "SPI1,SPI2,SPI3,SPI4,SPI5,SPI6," + terminator and init with the terminator - char deviceSelectorString[ 30 + 1] = { 0 }; - - #if STM32_SPI_USE_SPI1 - strcat(deviceSelectorString, "SPI1,"); - #endif - #if STM32_SPI_USE_SPI2 - strcat(deviceSelectorString, "SPI2,"); - #endif - #if STM32_SPI_USE_SPI3 - strcat(deviceSelectorString, "SPI3,"); - #endif - #if STM32_SPI_USE_SPI4 - strcat(deviceSelectorString, "SPI4,"); - #endif - #if STM32_SPI_USE_SPI5 - strcat(deviceSelectorString, "SPI5,"); - #endif - #if STM32_SPI_USE_SPI6 - strcat(deviceSelectorString, "SPI6,"); - #endif - - // replace the last comma with a terminator - deviceSelectorString[hal_strlen_s(deviceSelectorString) - 1] = '\0'; - - // because the caller is expecting a result to be returned - // we need set a return result in the stack argument using the appropriate SetResult according to the variable type (a string here) - stack.SetResult_String(deviceSelectorString); - } - NANOCLR_NOCLEANUP_NOLABEL(); -} diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.Spi/win_dev_spi_native_Windows_Devices_Spi_SpiDevice.cpp b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.Spi/win_dev_spi_native_Windows_Devices_Spi_SpiDevice.cpp deleted file mode 100644 index 08363f6569..0000000000 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.Spi/win_dev_spi_native_Windows_Devices_Spi_SpiDevice.cpp +++ /dev/null @@ -1,842 +0,0 @@ -// -// Copyright (c) 2017 The nanoFramework project contributors -// See LICENSE file in the project root for full license information. -// - - -#include -#include -#include -#include -#include -#include -#include "win_dev_spi_native_target.h" - - -// define this type here to make it shorter and improve code readability -typedef Library_win_dev_spi_native_Windows_Devices_Spi_SpiConnectionSettings SpiConnectionSettings; - - -///////////////////////////////////////////////////// -// SPI PAL strucs declared in win_dev_spi_native.h // -///////////////////////////////////////////////////// -#if STM32_SPI_USE_SPI1 -NF_PAL_SPI SPI1_PAL; -#endif -#if STM32_SPI_USE_SPI2 -NF_PAL_SPI SPI2_PAL; -#endif -#if STM32_SPI_USE_SPI3 -NF_PAL_SPI SPI3_PAL; -#endif -#if STM32_SPI_USE_SPI4 -NF_PAL_SPI SPI4_PAL; -#endif -#if STM32_SPI_USE_SPI5 -NF_PAL_SPI SPI5_PAL; -#endif -#if STM32_SPI_USE_SPI6 -NF_PAL_SPI SPI6_PAL; -#endif - -static void SpiCallback(SPIDriver *spip) -{ - (void)spip; - - NATIVE_INTERRUPT_START - - NF_PAL_SPI* palSpi = NULL; - - #if STM32_SPI_USE_SPI1 - if (spip == &SPID1) - { - palSpi = &SPI1_PAL; - } - #endif - #if STM32_SPI_USE_SPI2 - if (spip == &SPID2) - { - palSpi = &SPI2_PAL; - } - #endif - #if STM32_SPI_USE_SPI3 - if (spip == &SPID3) - { - palSpi = &SPI3_PAL; - } - #endif - #if STM32_SPI_USE_SPI4 - if (spip == &SPID4) - { - palSpi = &SPI4_PAL; - } - #endif - #if STM32_SPI_USE_SPI5 - if (spip == &SPID5) - { - palSpi = &SPI5_PAL; - } - #endif - #if STM32_SPI_USE_SPI6 - if (spip == &SPID6) - { - palSpi = &SPI6_PAL; - } - #endif - - // check if there is any Rx operation due - if(palSpi->SequentialTxRx) - { - // yes there is! - // clear flag and... - palSpi->SequentialTxRx = false; - - // ... start it - spiStartReceive(palSpi->Driver, palSpi->ReadSize, palSpi->ReadBuffer); - } - else - { - // all done here! - - spiUnselect(palSpi->Driver); - - // fire event for SPI transaction complete - Events_Set( SYSTEM_EVENT_FLAG_SPI_MASTER ); - } - - NATIVE_INTERRUPT_END -}; - -// Computes the SPI peripheral baud rate according to the requested frequency -uint16_t ComputeBaudRate(uint8_t busIndex, int32_t requestedFrequency, int32_t& actualFrequency) -{ - uint16_t divider = 0; - int32_t maxSpiFrequency; - - #if defined(STM32L0XX) - - // SP1 is feed by APB2 (STM32_PCLK2) - actualFrequency = STM32_PCLK2; - - // SPI2 is feed by APB1 (STM32_PCLK1) - if (busIndex == 1) - { - actualFrequency = STM32_PCLK1; - } - - // from datasheet - maxSpiFrequency = 12000000; - - #elif defined(STM32F0XX) - - (void)busIndex; - - // STM32F0 SPI is always feed by APB1 - actualFrequency = STM32_PCLK1; - - // from datasheet - maxSpiFrequency = 18000000; - - #elif defined(STM32F4XX) || defined(STM32F7XX) - - // SP1, SPI4, SPI5 and SPI6 are feed by APB2 (STM32_PCLK2) - actualFrequency = STM32_PCLK2; - - // SPI2 and SPI3 are feed by APB1 (STM32_PCLK1) - if (busIndex == 2 || busIndex == 3) - { - actualFrequency = STM32_PCLK1; - } - - // this is not really accurate because there are different max SPI clocks depending on which APB clock source if feeding the SPI - // because ChibiOS doesn't offer that we have to go with minimum common denominator - maxSpiFrequency = STM32_SPII2S_MAX; - - #elif defined(STM32H7XX) - - // SP1, SPI4, SPI5 and SPI6 are feed by APB2 (STM32_PCLK2) - actualFrequency = STM32_PCLK2; - maxSpiFrequency = STM32_SPI456_MAX; - - // SPI1, SPI2 and SPI3 are feed by APB1 (STM32_PCLK1) - if (busIndex == 2 || busIndex == 3) - { - actualFrequency = STM32_PCLK1; - maxSpiFrequency = STM32_SPI123_MAX; - } - - #else - - #error "Error setting max SPI frequency. Check if the target series is defined." - - #endif - - - // when requested frequency is 0, means that the developer hasn't set ClockFrequency in SpiConnectionSettings - // default to the max possible SPI frequency - if(requestedFrequency == 0) - { - requestedFrequency = maxSpiFrequency; - } - - for( ; divider < 8; divider++) - { - actualFrequency = actualFrequency / 2; - - if(actualFrequency <= requestedFrequency) - { - // best match for the requested frequency - // just check if it's below the max SPI frequency - if(actualFrequency <= maxSpiFrequency) - { - // we are good with this value - break; - } - } - } - - // the baud rate bits are in the position B5:3 so need to left shit the divider value - return divider << 3; -} - -// Give a complete low-level SPI configuration from user's managed connectionSettings -void GetSPIConfig(int busIndex, CLR_RT_HeapBlock* config, SPIConfig* llConfig, bool bufferIs16bits) -{ - int32_t actualFrequency; - - // clear values - llConfig->cr1 = 0; - llConfig->cr2 = 0; - - // get chip select pin - int csPin = config[ SpiConnectionSettings::FIELD___csLine ].NumericByRef().s4; - - // SPI mode - switch (config[ SpiConnectionSettings::FIELD___spiMode ].NumericByRef().s4) - { - case SpiMode_Mode1: - llConfig->cr1 |= SPI_CR1_CPHA; - break; - - case SpiMode_Mode2: - llConfig->cr1 |= SPI_CR1_CPOL; - break; - - case SpiMode_Mode3: - llConfig->cr1 |= SPI_CR1_CPHA | SPI_CR1_CPOL; - break; - - default: // Default to Mode0 if invalid mode specified - break; - } - - // compute baud rate of SPI peripheral according to the requested frequency - llConfig->cr1 |= ComputeBaudRate(busIndex, config[ SpiConnectionSettings::FIELD___clockFrequency ].NumericByRef().s4, actualFrequency); - - // set data transfer length according to SPI connection settings and... - // ... buffer data size. Have to use the shortest one. - if (config[ SpiConnectionSettings::FIELD___databitLength ].NumericByRef().s4 == 16) - { - // databitLength is 16bits - - if(bufferIs16bits) - { - // Set data transfer length to 16 bits - #ifdef STM32F4XX - llConfig->cr1 |= SPI_CR1_DFF; - #endif - #ifdef STM32F7XX - llConfig->cr2 = SPI_CR2_DS_3 | SPI_CR2_DS_2 | SPI_CR2_DS_1 | SPI_CR2_DS_0; - #endif - // Sets the order of bytes transmission : MSB first or LSB first - int bitOrder = config[ SpiConnectionSettings::FIELD___bitOrder ].NumericByRef().s4; - if (bitOrder == DataBitOrder_LSB) - { - llConfig->cr1 |= SPI_CR1_LSBFIRST; - } - } - else - { - // have to force transfer length to 8bit - #ifdef STM32F4XX - llConfig->cr1 &= ~SPI_CR1_DFF; - #endif - #ifdef STM32F7XX - llConfig->cr2 = SPI_CR2_DS_2 | SPI_CR2_DS_1 | SPI_CR2_DS_0; - #endif - } - } - else - { - // databitLength is 8bits - - if(bufferIs16bits) - { - // have to force transfer length to 16bit - #ifdef STM32F4XX - llConfig->cr1 |= SPI_CR1_DFF; - #endif - #ifdef STM32F7XX - llConfig->cr2 = SPI_CR2_DS_3 | SPI_CR2_DS_2 | SPI_CR2_DS_1 | SPI_CR2_DS_0; - #endif - - } - else - { - // set transfer length to 8bits - #ifdef STM32F4XX - llConfig->cr1 &= ~SPI_CR1_DFF; - #endif - #ifdef STM32F7XX - llConfig->cr2 |= SPI_CR2_DS_2 | SPI_CR2_DS_1 | SPI_CR2_DS_0; - #endif - } - } - - // Create the low level configuration - #if (SPI_SUPPORTS_CIRCULAR == TRUE) - llConfig->circular = SPI_USE_CIRCULAR; - #endif - - llConfig->end_cb = SpiCallback; - - // make sure the CS pin is properly configured as GPIO, output & pushpull - palSetPadMode( GPIO_PORT(csPin), csPin % 16, (PAL_STM32_OSPEED_HIGHEST | PAL_MODE_OUTPUT_PUSHPULL) ); - - // being SPI CS active low, default it to high - palSetPad(GPIO_PORT(csPin), csPin % 16); - - // set port&pad for CS pin - llConfig->ssport = GPIO_PORT(csPin); - llConfig->sspad = csPin % 16; -} - -// estimate the time required to perform the SPI transaction -bool IsLongRunningOperation(uint32_t writeSize, uint32_t readSize, bool bufferIs16bits, float byteTime, uint32_t& estimatedDurationMiliseconds) -{ - if(bufferIs16bits) - { - // double the buffers size - writeSize = 2 * writeSize; - readSize = 2 * readSize; - } - - estimatedDurationMiliseconds = byteTime * (writeSize + readSize); - - if(estimatedDurationMiliseconds > CLR_RT_Thread::c_TimeQuantum_Milliseconds) - { - // total operation time will exceed thread quantum, so this is a long running operation - return true; - } - else - { - return false; - } -} - -HRESULT Library_win_dev_spi_native_Windows_Devices_Spi_SpiDevice::NativeTransfer___VOID__SZARRAY_U1__SZARRAY_U1__BOOLEAN( CLR_RT_StackFrame& stack ) -{ - return NativeTransfer( stack, false ); -} - -HRESULT Library_win_dev_spi_native_Windows_Devices_Spi_SpiDevice::NativeTransfer___VOID__SZARRAY_U2__SZARRAY_U2__BOOLEAN( CLR_RT_StackFrame& stack ) -{ - return NativeTransfer( stack, true ); -} -HRESULT Library_win_dev_spi_native_Windows_Devices_Spi_SpiDevice::NativeTransfer( CLR_RT_StackFrame& stack, bool bufferIs16bits ) -{ - NANOCLR_HEADER(); - { - NF_PAL_SPI* palSpi = NULL; - uint8_t busIndex; - bool fullDuplex; - bool isLongRunningOperation = false; - - CLR_RT_HeapBlock hbTimeout; - CLR_INT64* timeout; - bool eventResult = true; - uint32_t estimatedDurationMiliseconds; - - // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); - - // get a pointer to the managed spi connectionSettings object instance - CLR_RT_HeapBlock* pConfig = pThis[ FIELD___connectionSettings ].Dereference(); - - // get bus index - // this is coded with a multiplication, need to perform and int division to get the number - // see the comments in the SpiDevice() constructor in managed code for details - busIndex = (uint8_t)(pThis[ FIELD___deviceId ].NumericByRef().s4 / 1000); - - // get the PAL struct for the SPI bus - switch (busIndex) - { - #if STM32_SPI_USE_SPI1 - case 1: - palSpi = &SPI1_PAL; - break; - #endif - #if STM32_SPI_USE_SPI2 - case 2: - palSpi = &SPI2_PAL; - break; - #endif - #if STM32_SPI_USE_SPI3 - case 3: - palSpi = &SPI3_PAL; - break; - #endif - #if STM32_SPI_USE_SPI4 - case 4: - palSpi = &SPI4_PAL; - break; - #endif - #if STM32_SPI_USE_SPI5 - case 5: - palSpi = &SPI5_PAL; - break; - #endif - #if STM32_SPI_USE_SPI6 - case 6: - palSpi = &SPI6_PAL; - break; - #endif - default: - // the requested SPI bus is not valid - NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); - break; - } - - // Are we using SPI full-duplex for transfer? - fullDuplex = (bool)stack.Arg3().NumericByRef().u1; - - // dereference the write and read buffers from the arguments - CLR_RT_HeapBlock_Array* writeBuffer = stack.Arg1().DereferenceArray(); - if (writeBuffer != NULL) - { - // get the size of the buffer by reading the number of elements in the CLR_RT_HeapBlock_Array - palSpi->WriteSize = writeBuffer->m_numOfElements; - } - - CLR_RT_HeapBlock_Array* readBuffer = stack.Arg2().DereferenceArray(); - if (readBuffer != NULL) - { - // get the size of the buffer by reading the number of elements in the CLR_RT_HeapBlock_Array - palSpi->ReadSize = readBuffer->m_numOfElements; - } - - // check if this is a long running operation - isLongRunningOperation = IsLongRunningOperation(palSpi->WriteSize, palSpi->ReadSize, bufferIs16bits, palSpi->ByteTime, (uint32_t&)estimatedDurationMiliseconds); - - if(isLongRunningOperation) - { - // if this is a long running operation, set a timeout equal to the estimated transaction duration in milliseconds - // this value has to be in ticks to be properly loaded by SetupTimeoutFromTicks() below - hbTimeout.SetInteger((CLR_INT64)estimatedDurationMiliseconds * TIME_CONVERSION__TO_MILLISECONDS); - - NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks( hbTimeout, timeout )); - - // protect the buffers from GC so DMA can find them where they are supposed to be - CLR_RT_ProtectFromGC gcWriteBuffer( *writeBuffer ); - CLR_RT_ProtectFromGC gcReadBuffer( *readBuffer ); - } - - // setup the operation and init buffers - if(!isLongRunningOperation || stack.m_customState == 1) - { - // get the LL SPI configuration, depending on user's managed parameters and buffer element size - GetSPIConfig(busIndex, pConfig, &palSpi->Configuration, bufferIs16bits); - - // if this is not a long run operation we'll be using the async API thus operations are sequencial - // need to remove the callback from the SPI LL config - if(!isLongRunningOperation) - { - palSpi->Configuration.end_cb = NULL; - } - - if (writeBuffer != NULL) - { - // set DMA write buffer - if(bufferIs16bits) - { - // buffer data width is 16bits - // get the pointer to the write buffer as UINT16 because it's really an UINT16 (2 bytes) - palSpi->WriteBuffer = (uint8_t*)writeBuffer->GetFirstElementUInt16(); - - // flush DMA buffer to ensure cache coherency - // (only required for Cortex-M7) - cacheBufferFlush(palSpi->WriteBuffer, (palSpi->WriteSize * 2)); - } - else - { - // buffer data width is 8bits - // get the pointer to the write buffer as BYTE - palSpi->WriteBuffer = (uint8_t*)writeBuffer->GetFirstElement(); - - // flush DMA buffer to ensure cache coherency - // (only required for Cortex-M7) - cacheBufferFlush(palSpi->WriteBuffer, palSpi->WriteSize); - } - } - - if (readBuffer != NULL) - { - // set DMA read buffer - if(palSpi->ReadSize > 0) - { - if(bufferIs16bits) - { - // buffer data width is 16bits - palSpi->ReadBuffer = (uint8_t*)readBuffer->GetFirstElementUInt16(); - } - else - { - // buffer data width is 8bits - // get the pointer to the read buffer as BYTE - palSpi->ReadBuffer = (uint8_t*)readBuffer->GetFirstElement(); - } - } - } - - // because the bus access is shared, acquire and select the appropriate bus - spiAcquireBus(palSpi->Driver); - spiStart(palSpi->Driver, &palSpi->Configuration); - - // just to satisfy the driver ceremony, no actual implementation for STM32 - spiSelect(palSpi->Driver); - } - - if(isLongRunningOperation) - { - // this is a long running operation and hasn't started yet - // perform SPI operation using driver's ASYNC API - if(stack.m_customState == 1) - { - if (palSpi->WriteSize != 0 && palSpi->ReadSize != 0) - { - // Transmit+Receive - if (fullDuplex) - { - // Full duplex - // single operation, clear flag - palSpi->SequentialTxRx = false; - - // Uses the largest buffer size as transfer size - spiStartExchange(palSpi->Driver, palSpi->WriteSize > palSpi->ReadSize ? palSpi->WriteSize : palSpi->ReadSize, palSpi->WriteBuffer, palSpi->ReadBuffer); - } - else - { - // flag that an Rx is required after the Tx operation completes - palSpi->SequentialTxRx = true; - - // start send operation - spiStartSend(palSpi->Driver, palSpi->WriteSize, palSpi->WriteBuffer); - // receive operation will be started in the callback after the above completes - } - } - else - { - // Transmit only or Receive only - if (palSpi->ReadSize != 0) - { - // single operation, clear flag - palSpi->SequentialTxRx = false; - - // start receive - spiStartReceive(palSpi->Driver, palSpi->ReadSize, palSpi->ReadBuffer); - } - else - { - // single operation, clear flag - palSpi->SequentialTxRx = false; - - // start send - spiStartSend(palSpi->Driver, palSpi->WriteSize, palSpi->WriteBuffer); - } - } - - // bump custom state - stack.m_customState = 2; - } - } - else - { - // this is NOT a long running operation - // perform SPI operation using driver's SYNC API - if (palSpi->WriteSize != 0 && palSpi->ReadSize != 0) - { - // Transmit+Receive - if (fullDuplex) - { - // Full duplex - // Uses the largest buffer size as transfer size - spiExchange(palSpi->Driver, palSpi->WriteSize > palSpi->ReadSize ? palSpi->WriteSize : palSpi->ReadSize, palSpi->WriteBuffer, palSpi->ReadBuffer); - } - else - { - // send operation - spiSend(palSpi->Driver, palSpi->WriteSize, palSpi->WriteBuffer); - // receive operation - spiReceive(palSpi->Driver, palSpi->ReadSize, palSpi->ReadBuffer); - } - } - else - { - // Transmit only or Receive only - if (palSpi->ReadSize != 0) - { - // receive - spiReceive(palSpi->Driver, palSpi->ReadSize, palSpi->ReadBuffer); - } - else - { - // send - spiSend(palSpi->Driver, palSpi->WriteSize, palSpi->WriteBuffer); - } - } - - // just to satisfy the driver ceremony, no actual implementation for STM32 - spiUnselect(palSpi->Driver); - - // Release the bus - spiReleaseBus(palSpi->Driver); - } - - while(eventResult) - { - if(!isLongRunningOperation) - { - // this is not a long running operation so nothing to do here - break; - } - - if(palSpi->Driver->state == SPI_READY) - { - // SPI driver is ready meaning that the SPI transaction(s) is(are) completed - break; - } - - // non-blocking wait allowing other threads to run while we wait for the Spi transaction to complete - NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.WaitEvents( stack.m_owningThread, *timeout, CLR_RT_ExecutionEngine::c_Event_SpiMaster, eventResult )); - } - - if(isLongRunningOperation) - { - // pop timeout heap block from stack - stack.PopValue(); - } - - if(eventResult) - { - spiReleaseBus(palSpi->Driver); - - // event occurred - if(palSpi->ReadSize > 0) - { - // because this was a Read transaction, need to copy from DMA buffer to managed buffer - if(bufferIs16bits) - { - // buffer data width is 16bits - - // invalidate cache over read buffer to ensure that content from DMA is read - // (only required for Cortex-M7) - // get the pointer to the read buffer as UINT16 because it's really an UINT16 (2 bytes) - cacheBufferInvalidate(palSpi->ReadBuffer, (palSpi->ReadSize * 2)); - } - else - { - // buffer data width is 8bits - - // invalidate cache over read buffer to ensure that content from DMA is read - // (only required for Cortex-M7) - // get the pointer to the read buffer as BYTE - cacheBufferInvalidate(palSpi->ReadBuffer, palSpi->ReadSize); - } - } - } - - // null pointers and vars - pThis = NULL; - pConfig = NULL; - } - NANOCLR_NOCLEANUP(); -} - -HRESULT Library_win_dev_spi_native_Windows_Devices_Spi_SpiDevice::NativeInit___VOID( CLR_RT_StackFrame& stack ) -{ - NANOCLR_HEADER(); - - uint8_t busIndex; - NF_PAL_SPI* palSpi; - int32_t actualFrequency = 0; - CLR_RT_HeapBlock* pConfig; - - // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); - - // get a pointer to the managed spi connectionSettings object instance - pConfig = pThis[ FIELD___connectionSettings ].Dereference(); - - // get bus index - // this is coded with a multiplication, need to perform and int division to get the number - // see the comments in the SpiDevice() constructor in managed code for details - busIndex = (uint8_t)(pThis[ FIELD___deviceId ].NumericByRef().s4 / 1000); - - // config GPIO pins used by the SPI peripheral - // init the PAL struct for this SPI bus and assign the respective driver - // all this occurs if not already done - // why do we need this? because several SPIDevice objects can be created associated to the same bus - switch (busIndex) - { - #if STM32_SPI_USE_SPI1 - case 1: - if(SPI1_PAL.Driver == NULL) - { - ConfigPins_SPI1(); - - SPI1_PAL.Driver = &SPID1; - palSpi = &SPI1_PAL; - } - break; - #endif - - #if STM32_SPI_USE_SPI2 - case 2: - if(SPI2_PAL.Driver == NULL) - { - ConfigPins_SPI2(); - - SPI2_PAL.Driver = &SPID2; - palSpi = &SPI2_PAL; - } - break; - #endif - - #if STM32_SPI_USE_SPI3 - case 3: - if(SPI3_PAL.Driver == NULL) - { - ConfigPins_SPI3(); - - SPI3_PAL.Driver = &SPID3; - palSpi = &SPI3_PAL; - } - break; - #endif - - #if STM32_SPI_USE_SPI4 - case 4: - if(SPI4_PAL.Driver == NULL) - { - ConfigPins_SPI4(); - - SPI4_PAL.Driver = &SPID4; - palSpi = &SPI4_PAL; - } - break; - #endif - - #if STM32_SPI_USE_SPI5 - case 5: - if(SPI5_PAL.Driver == NULL) - { - ConfigPins_SPI5(); - - SPI5_PAL.Driver = &SPID5; - palSpi = &SPI5_PAL; - } - break; - #endif - - #if STM32_SPI_USE_SPI6 - case 6: - if(SPI6_PAL.Driver == NULL) - { - ConfigPins_SPI6(); - - SPI6_PAL.Driver = &SPID6; - palSpi = &SPI6_PAL; - } - break; - #endif - - default: - // this SPI bus is not valid - NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); - break; - } - - // compute rough estimate on the time to tx/rx a byte (in milliseconds) - ComputeBaudRate(busIndex, pConfig[ SpiConnectionSettings::FIELD___clockFrequency ].NumericByRef().s4, actualFrequency); - palSpi->ByteTime = (1.0 / actualFrequency) * 1000.0; - - NANOCLR_NOCLEANUP(); -} - -HRESULT Library_win_dev_spi_native_Windows_Devices_Spi_SpiDevice::DisposeNative___VOID( CLR_RT_StackFrame& stack ) -{ - NANOCLR_HEADER(); - - uint8_t busIndex; - - // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); - - // get bus index - // this is coded with a multiplication, need to perform and int division to get the number - // see the comments in the SpiDevice() constructor in managed code for details - busIndex = (uint8_t)(pThis[ FIELD___deviceId ].NumericByRef().s4 / 1000); - - // get the PAL struct for the SPI bus - switch (busIndex) - { - #if STM32_SPI_USE_SPI1 - case 1: - spiStop(&SPID1); - SPI1_PAL.Driver = NULL; - break; - #endif - - #if STM32_SPI_USE_SPI2 - case 2: - spiStop(&SPID2); - SPI2_PAL.Driver = NULL; - break; - #endif - - #if STM32_SPI_USE_SPI3 - case 3: - spiStop(&SPID3); - SPI3_PAL.Driver = NULL; - break; - #endif - - #if STM32_SPI_USE_SPI4 - case 4: - spiStop(&SPID4); - SPI4_PAL.Driver = NULL; - break; - #endif - - #if STM32_SPI_USE_SPI5 - case 5: - spiStop(&SPID5); - SPI5_PAL.Driver = NULL; - break; - #endif - - #if STM32_SPI_USE_SPI6 - case 6: - spiStop(&SPID6); - SPI6_PAL.Driver = NULL; - break; - #endif - - default: - // the requested SPI bus is not valid - NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); - break; - } - - NANOCLR_NOCLEANUP(); -} diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.Spi/win_dev_spi_native_target.h b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.Spi/win_dev_spi_native_target.h index bdd3e19438..84d1938f28 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.Spi/win_dev_spi_native_target.h +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.Spi/win_dev_spi_native_target.h @@ -1,67 +1,63 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // - #ifndef _WIN_DEV_SPI_NATIVE_TARGET_H_ #define _WIN_DEV_SPI_NATIVE_TARGET_H_ #include #include -// struct representing the SPI +// struct representing the SPI bus struct NF_PAL_SPI { - SPIDriver* Driver; - SPIConfig Configuration; - float ByteTime; + int BusIndex; + SPIDriver *Driver; + SPIConfig Configuration; + + SPI_Callback Callback; + bool SequentialTxRx; + bool BufferIs16bits; - uint8_t* WriteBuffer; + uint8_t *WriteBuffer; uint16_t WriteSize; - uint8_t* ReadBuffer; + uint8_t *ReadBuffer; uint16_t ReadSize; }; -/////////////////////////////////////////// -// declaration of the the SPI PAL strucs // -/////////////////////////////////////////// -#if STM32_SPI_USE_SPI1 - extern NF_PAL_SPI SPI1_PAL; -#endif -#if STM32_SPI_USE_SPI2 - extern NF_PAL_SPI SPI2_PAL; -#endif -#if STM32_SPI_USE_SPI3 - extern NF_PAL_SPI SPI3_PAL; -#endif -#if STM32_SPI_USE_SPI4 - extern NF_PAL_SPI SPI4_PAL; -#endif -#if STM32_SPI_USE_SPI5 - extern NF_PAL_SPI SPI5_PAL; -#endif -#if STM32_SPI_USE_SPI6 - extern NF_PAL_SPI SPI6_PAL; -#endif - // the following macro defines a function that configures the GPIO pins for an STM32 SPI peripheral // it gets called in the Windows_Devices_SPi_SPiDevice::NativeInit function // this is required because the SPI peripherals can use multiple GPIO configuration combinations -#define SPI_CONFIG_PINS(num, gpio_port_sck, sck_pin, gpio_port_miso, miso_pin, gpio_port_mosi, mosi_pin, alternate_function) void ConfigPins_SPI##num() \ -{ \ - palSetPadMode(gpio_port_sck, sck_pin, \ - (PAL_MODE_ALTERNATE(alternate_function) | \ - PAL_STM32_OSPEED_HIGHEST | PAL_STM32_PUPDR_FLOATING | PAL_STM32_OTYPE_PUSHPULL) ); \ - palSetPadMode(gpio_port_miso, miso_pin, \ - (PAL_MODE_ALTERNATE(alternate_function) | \ - PAL_STM32_OSPEED_HIGHEST | PAL_STM32_PUPDR_FLOATING | PAL_STM32_OTYPE_PUSHPULL) ); \ - palSetPadMode(gpio_port_mosi, mosi_pin, \ - (PAL_MODE_ALTERNATE(alternate_function) | \ - PAL_STM32_OSPEED_HIGHEST | PAL_STM32_PUPDR_FLOATING | PAL_STM32_OTYPE_PUSHPULL) ); \ -} +#define SPI_CONFIG_PINS( \ + num, \ + gpio_port_sck, \ + sck_pin, \ + gpio_port_miso, \ + miso_pin, \ + gpio_port_mosi, \ + mosi_pin, \ + alternate_function) \ + void ConfigPins_SPI##num() \ + { \ + palSetPadMode( \ + gpio_port_sck, \ + sck_pin, \ + (PAL_MODE_ALTERNATE(alternate_function) | PAL_STM32_OSPEED_HIGHEST | PAL_STM32_PUPDR_FLOATING | \ + PAL_STM32_OTYPE_PUSHPULL)); \ + palSetPadMode( \ + gpio_port_miso, \ + miso_pin, \ + (PAL_MODE_ALTERNATE(alternate_function) | PAL_STM32_OSPEED_HIGHEST | PAL_STM32_PUPDR_FLOATING | \ + PAL_STM32_OTYPE_PUSHPULL)); \ + palSetPadMode( \ + gpio_port_mosi, \ + mosi_pin, \ + (PAL_MODE_ALTERNATE(alternate_function) | PAL_STM32_OSPEED_HIGHEST | PAL_STM32_PUPDR_FLOATING | \ + PAL_STM32_OTYPE_PUSHPULL)); \ + } ////////////////////////////////////////////////////////////////////////////////////////////// // when an SPI is defined the declarations below will have the real function/configuration // @@ -74,4 +70,4 @@ void ConfigPins_SPI4(); void ConfigPins_SPI5(); void ConfigPins_SPI6(); -#endif //_WIN_DEV_SPI_NATIVE_TARGET_H_ +#endif //_WIN_DEV_SPI_NATIVE_TARGET_H_ diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Networking.Sockets/win_net_sockets_native_Windows_Networking_Sockets_SocketNative.cpp b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Networking.Sockets/win_net_sockets_native_Windows_Networking_Sockets_SocketNative.cpp index ceba4d66b0..8c714bbe11 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Networking.Sockets/win_net_sockets_native_Windows_Networking_Sockets_SocketNative.cpp +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Networking.Sockets/win_net_sockets_native_Windows_Networking_Sockets_SocketNative.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // @@ -7,40 +7,44 @@ #include "win_net_sockets_native_target.h" // TODO - Check if required, for now just ignore -#define SwapEndianIfBEc16(x) (x) +#define SwapEndianIfBEc16(x) (x) -HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::socket___STATIC__I4__I4__I4__I4( CLR_RT_StackFrame& stack ) +HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::socket___STATIC__I4__I4__I4__I4( + CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); - CLR_INT32 family = stack.Arg0().NumericByRef().s4; - CLR_INT32 type = stack.Arg1().NumericByRef().s4; + CLR_INT32 family = stack.Arg0().NumericByRef().s4; + CLR_INT32 type = stack.Arg1().NumericByRef().s4; CLR_INT32 protocol = stack.Arg2().NumericByRef().s4; - + CLR_INT32 nonBlocking = 1; - CLR_INT32 sock = SOCK_socket( family, type, protocol ); - - NANOCLR_CHECK_HRESULT(ThrowOnError( stack, sock )); - - NANOCLR_CHECK_HRESULT(ThrowOnError( stack, SOCK_ioctl( sock, SOCK_FIONBIO, &nonBlocking ) )); + CLR_INT32 sock = SOCK_socket(family, type, protocol); + + NANOCLR_CHECK_HRESULT(ThrowOnError(stack, sock)); + + NANOCLR_CHECK_HRESULT(ThrowOnError(stack, SOCK_ioctl(sock, SOCK_FIONBIO, &nonBlocking))); - stack.SetResult_I4( sock ); + stack.SetResult_I4(sock); NANOCLR_NOCLEANUP(); } -HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::bind___STATIC__VOID__OBJECT__SZARRAY_U1( CLR_RT_StackFrame& stack ) +HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::bind___STATIC__VOID__OBJECT__SZARRAY_U1( + CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); - return BindConnectHelper( stack, true ); + return BindConnectHelper(stack, true); } -HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::connect___STATIC__VOID__OBJECT__SZARRAY_U1__BOOLEAN( CLR_RT_StackFrame& stack ) +HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: + connect___STATIC__VOID__OBJECT__SZARRAY_U1__BOOLEAN(CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); - return BindConnectHelper( stack, false ); + return BindConnectHelper(stack, false); } -HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::send___STATIC__I4__OBJECT__SZARRAY_U1__I4__I4__I4__I4( CLR_RT_StackFrame& stack ) +HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: + send___STATIC__I4__OBJECT__SZARRAY_U1__I4__I4__I4__I4(CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); @@ -49,7 +53,8 @@ HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: NANOCLR_NOCLEANUP(); } -HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::recv___STATIC__I4__OBJECT__SZARRAY_U1__I4__I4__I4__I4( CLR_RT_StackFrame& stack ) +HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: + recv___STATIC__I4__OBJECT__SZARRAY_U1__I4__I4__I4__I4(CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); @@ -58,83 +63,87 @@ HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: NANOCLR_NOCLEANUP(); } -HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::close___STATIC__I4__OBJECT( CLR_RT_StackFrame& stack ) +HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::close___STATIC__I4__OBJECT( + CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); CLR_INT32 handle, ret; - CLR_RT_HeapBlock* socket = stack.Arg0().Dereference(); FAULT_ON_NULL(socket); - - handle = socket[ FIELD__m_Handle ].NumericByRef().s4; + CLR_RT_HeapBlock *socket = stack.Arg0().Dereference(); + FAULT_ON_NULL(socket); + + handle = socket[FIELD__m_Handle].NumericByRef().s4; - ret = SOCK_close( handle ); - - //If a socket gets closed, we need to make sure to wake up any threads that are waiting on it. - Events_Set( SYSTEM_EVENT_FLAG_SOCKET ); + ret = SOCK_close(handle); + + // If a socket gets closed, we need to make sure to wake up any threads that are waiting on it. + Events_Set(SYSTEM_EVENT_FLAG_SOCKET); + + stack.SetResult_I4(ret); - stack.SetResult_I4( ret ); - NANOCLR_NOCLEANUP(); } -HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::listen___STATIC__VOID__OBJECT__I4( CLR_RT_StackFrame& stack ) +HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::listen___STATIC__VOID__OBJECT__I4( + CLR_RT_StackFrame &stack) { NATIVE_PROFILE_CLR_NETWORK(); NANOCLR_HEADER(); - CLR_RT_HeapBlock* socket = stack.Arg0().Dereference(); + CLR_RT_HeapBlock *socket = stack.Arg0().Dereference(); CLR_INT32 handle; CLR_INT32 backlog = stack.Arg1().NumericByRef().s4; CLR_INT32 ret; FAULT_ON_NULL(socket); - handle = socket[ FIELD__m_Handle ].NumericByRef().s4; + handle = socket[FIELD__m_Handle].NumericByRef().s4; - ret = SOCK_listen( handle, backlog ); + ret = SOCK_listen(handle, backlog); - NANOCLR_CHECK_HRESULT(ThrowOnError( stack, ret )); + NANOCLR_CHECK_HRESULT(ThrowOnError(stack, ret)); NANOCLR_NOCLEANUP(); } -HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::accept___STATIC__I4__OBJECT( CLR_RT_StackFrame& stack ) +HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::accept___STATIC__I4__OBJECT( + CLR_RT_StackFrame &stack) { NATIVE_PROFILE_CLR_NETWORK(); NANOCLR_HEADER(); - CLR_RT_HeapBlock* socket = stack.Arg0().Dereference(); + CLR_RT_HeapBlock *socket = stack.Arg0().Dereference(); CLR_INT32 handle; CLR_INT32 ret; CLR_INT32 nonBlocking = 1; FAULT_ON_NULL(socket); - handle = socket[ FIELD__m_Handle ].NumericByRef().s4; - + handle = socket[FIELD__m_Handle].NumericByRef().s4; /* Because we could have been a rescheduled call due to a prior call that would have blocked, we need to see - * if our handle has been shutdown before continuing. */ + * if our handle has been shutdown before continuing. */ if (handle == DISPOSED_HANDLE) { ThrowError(stack, CLR_E_OBJECT_DISPOSED); - NANOCLR_SET_AND_LEAVE (CLR_E_PROCESS_EXCEPTION); + NANOCLR_SET_AND_LEAVE(CLR_E_PROCESS_EXCEPTION); } - ret = SOCK_accept( handle, NULL, NULL ); + ret = SOCK_accept(handle, NULL, NULL); - if(ret != SOCK_SOCKET_ERROR) + if (ret != SOCK_SOCKET_ERROR) { - NANOCLR_CHECK_HRESULT(ThrowOnError( stack, SOCK_ioctl( ret, SOCK_FIONBIO, &nonBlocking ) )); + NANOCLR_CHECK_HRESULT(ThrowOnError(stack, SOCK_ioctl(ret, SOCK_FIONBIO, &nonBlocking))); } - NANOCLR_CHECK_HRESULT(ThrowOnError( stack, ret )); + NANOCLR_CHECK_HRESULT(ThrowOnError(stack, ret)); - stack.SetResult_I4( ret ); + stack.SetResult_I4(ret); NANOCLR_NOCLEANUP(); } -HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::getaddrinfo___STATIC__VOID__STRING__BYREF_STRING__BYREF_SZARRAY_SZARRAY_U1( CLR_RT_StackFrame& stack ) +HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: + getaddrinfo___STATIC__VOID__STRING__BYREF_STRING__BYREF_SZARRAY_SZARRAY_U1(CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); @@ -143,7 +152,8 @@ HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: NANOCLR_NOCLEANUP(); } -HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::shutdown___STATIC__VOID__OBJECT__I4__BYREF_I4( CLR_RT_StackFrame& stack ) +HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: + shutdown___STATIC__VOID__OBJECT__I4__BYREF_I4(CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); @@ -152,7 +162,8 @@ HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: NANOCLR_NOCLEANUP(); } -HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::sendto___STATIC__I4__OBJECT__SZARRAY_U1__I4__I4__I4__I4__SZARRAY_U1( CLR_RT_StackFrame& stack ) +HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: + sendto___STATIC__I4__OBJECT__SZARRAY_U1__I4__I4__I4__I4__SZARRAY_U1(CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); @@ -161,7 +172,8 @@ HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: NANOCLR_NOCLEANUP(); } -HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::recvfrom___STATIC__I4__OBJECT__SZARRAY_U1__I4__I4__I4__I4__BYREF_SZARRAY_U1( CLR_RT_StackFrame& stack ) +HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: + recvfrom___STATIC__I4__OBJECT__SZARRAY_U1__I4__I4__I4__I4__BYREF_SZARRAY_U1(CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); @@ -170,7 +182,8 @@ HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: NANOCLR_NOCLEANUP(); } -HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::getpeername___STATIC__VOID__OBJECT__BYREF_SZARRAY_U1( CLR_RT_StackFrame& stack ) +HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: + getpeername___STATIC__VOID__OBJECT__BYREF_SZARRAY_U1(CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); @@ -179,7 +192,8 @@ HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: NANOCLR_NOCLEANUP(); } -HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::getsockname___STATIC__VOID__OBJECT__BYREF_SZARRAY_U1( CLR_RT_StackFrame& stack ) +HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: + getsockname___STATIC__VOID__OBJECT__BYREF_SZARRAY_U1(CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); @@ -188,7 +202,8 @@ HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: NANOCLR_NOCLEANUP(); } -HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::getsockopt___STATIC__VOID__OBJECT__I4__I4__SZARRAY_U1( CLR_RT_StackFrame& stack ) +HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: + getsockopt___STATIC__VOID__OBJECT__I4__I4__SZARRAY_U1(CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); @@ -197,7 +212,8 @@ HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: NANOCLR_NOCLEANUP(); } -HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::setsockopt___STATIC__VOID__OBJECT__I4__I4__SZARRAY_U1( CLR_RT_StackFrame& stack ) +HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: + setsockopt___STATIC__VOID__OBJECT__I4__I4__SZARRAY_U1(CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); @@ -206,7 +222,8 @@ HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: NANOCLR_NOCLEANUP(); } -HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::poll___STATIC__BOOLEAN__OBJECT__I4__I4( CLR_RT_StackFrame& stack ) +HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::poll___STATIC__BOOLEAN__OBJECT__I4__I4( + CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); @@ -215,7 +232,8 @@ HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: NANOCLR_NOCLEANUP(); } -HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::ioctl___STATIC__VOID__OBJECT__U4__BYREF_U4( CLR_RT_StackFrame& stack ) +HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: + ioctl___STATIC__VOID__OBJECT__U4__BYREF_U4(CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); @@ -224,16 +242,16 @@ HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: NANOCLR_NOCLEANUP(); } - - //--// -HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::BindConnectHelper( CLR_RT_StackFrame& stack, bool fBind ) +HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::BindConnectHelper( + CLR_RT_StackFrame &stack, + bool fBind) { NATIVE_PROFILE_CLR_NETWORK(); NANOCLR_HEADER(); - CLR_RT_HeapBlock* socket = stack.Arg0().Dereference(); + CLR_RT_HeapBlock *socket = stack.Arg0().Dereference(); CLR_INT32 handle; SOCK_sockaddr addr; CLR_UINT32 addrLen = sizeof(addr); @@ -241,83 +259,91 @@ HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: bool fThrowOnWouldBlock = false; FAULT_ON_NULL(socket); - handle = socket[ FIELD__m_Handle ].NumericByRef().s4; + handle = socket[FIELD__m_Handle].NumericByRef().s4; - NANOCLR_CHECK_HRESULT(MarshalSockAddress( &addr, addrLen, stack.Arg1() )); + NANOCLR_CHECK_HRESULT(MarshalSockAddress(&addr, addrLen, stack.Arg1())); - if(fBind) + if (fBind) { - ret = SOCK_bind( handle, &addr, addrLen ); + ret = SOCK_bind(handle, &addr, addrLen); } else { - ret = SOCK_connect( handle, &addr, addrLen ); - + ret = SOCK_connect(handle, &addr, addrLen); + fThrowOnWouldBlock = (stack.Arg2().NumericByRefConst().s4 != 0); - - if(!fThrowOnWouldBlock && SOCK_getlasterror() == SOCK_EWOULDBLOCK) + + if (!fThrowOnWouldBlock && SOCK_getlasterror() == SOCK_EWOULDBLOCK) { - NANOCLR_SET_AND_LEAVE(S_OK); + NANOCLR_SET_AND_LEAVE(S_OK); } } - NANOCLR_CHECK_HRESULT(ThrowOnError( stack, ret )); + NANOCLR_CHECK_HRESULT(ThrowOnError(stack, ret)); NANOCLR_NOCLEANUP(); } -HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::MarshalSockAddress( CLR_RT_HeapBlock& blkDst, const struct SOCK_sockaddr* addrSrc, CLR_UINT32 addrLenSrc ) +HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::MarshalSockAddress( + CLR_RT_HeapBlock &blkDst, + const struct SOCK_sockaddr *addrSrc, + CLR_UINT32 addrLenSrc) { NATIVE_PROFILE_CLR_NETWORK(); NANOCLR_HEADER(); - CLR_RT_HeapBlock_Array* arr = NULL; + CLR_RT_HeapBlock_Array *arr = NULL; + + CLR_RT_HeapBlock blkArr; + blkArr.SetObjectReference(NULL); + CLR_RT_ProtectFromGC gc(blkArr); + SOCK_sockaddr_in *dst; + SOCK_sockaddr_in *src = (SOCK_sockaddr_in *)addrSrc; + + NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_Array::CreateInstance(blkArr, addrLenSrc, g_CLR_RT_WellKnownTypes.m_UInt8)); - CLR_RT_HeapBlock blkArr; blkArr.SetObjectReference( NULL ); - CLR_RT_ProtectFromGC gc( blkArr ); - SOCK_sockaddr_in* dst; - SOCK_sockaddr_in* src = (SOCK_sockaddr_in*)addrSrc; - - NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_Array::CreateInstance( blkArr, addrLenSrc, g_CLR_RT_WellKnownTypes.m_UInt8 )); - arr = blkArr.DereferenceArray(); _ASSERTE(arr); - dst = (SOCK_sockaddr_in*)arr->GetFirstElement(); + dst = (SOCK_sockaddr_in *)arr->GetFirstElement(); - dst->sin_family = SwapEndianIfBEc16(src->sin_family); - dst->sin_port = src->sin_port; + dst->sin_family = SwapEndianIfBEc16(src->sin_family); + dst->sin_port = src->sin_port; dst->sin_addr.S_un.S_addr = src->sin_addr.S_un.S_addr; memcpy(dst->sin_zero, src->sin_zero, sizeof(dst->sin_zero)); _ASSERTE(blkDst.DataType() == DATATYPE_BYREF || blkDst.DataType() == DATATYPE_ARRAY_BYREF); - NANOCLR_CHECK_HRESULT(blkArr.StoreToReference( blkDst, 0 )); + NANOCLR_CHECK_HRESULT(blkArr.StoreToReference(blkDst, 0)); NANOCLR_NOCLEANUP(); } -HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::MarshalSockAddress( struct SOCK_sockaddr* addrDst, CLR_UINT32& addrLen, const CLR_RT_HeapBlock& blkSockAddress ) -{ +HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::MarshalSockAddress( + struct SOCK_sockaddr *addrDst, + CLR_UINT32 &addrLen, + const CLR_RT_HeapBlock &blkSockAddress) +{ NATIVE_PROFILE_CLR_NETWORK(); NANOCLR_HEADER(); - CLR_RT_HeapBlock_Array* ptrSockAddress; - SOCK_sockaddr_in* dst = (SOCK_sockaddr_in*)addrDst; - SOCK_sockaddr_in* src; + CLR_RT_HeapBlock_Array *ptrSockAddress; + SOCK_sockaddr_in *dst = (SOCK_sockaddr_in *)addrDst; + SOCK_sockaddr_in *src; - ptrSockAddress = blkSockAddress.DereferenceArray(); + ptrSockAddress = blkSockAddress.DereferenceArray(); FAULT_ON_NULL(ptrSockAddress); - if(ptrSockAddress->m_numOfElements > addrLen) NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); + if (ptrSockAddress->m_numOfElements > addrLen) + NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); - src = (SOCK_sockaddr_in*)ptrSockAddress->GetFirstElement(); + src = (SOCK_sockaddr_in *)ptrSockAddress->GetFirstElement(); - dst->sin_family = SwapEndianIfBEc16(src->sin_family); - dst->sin_port = src->sin_port; - dst->sin_addr.S_un.S_addr = src->sin_addr.S_un.S_addr; //already in network byte order + dst->sin_family = SwapEndianIfBEc16(src->sin_family); + dst->sin_port = src->sin_port; + dst->sin_addr.S_un.S_addr = src->sin_addr.S_un.S_addr; // already in network byte order memcpy(dst->sin_zero, src->sin_zero, sizeof(dst->sin_zero)); @@ -326,14 +352,15 @@ HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: NANOCLR_NOCLEANUP(); } -// HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::SendRecvHelper( CLR_RT_StackFrame& stack, bool fSend, bool fAddress ) +// HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::SendRecvHelper( CLR_RT_StackFrame& +// stack, bool fSend, bool fAddress ) // { // NATIVE_PROFILE_CLR_NETWORK(); // NANOCLR_HEADER(); // CLR_RT_HeapBlock* socket = stack.Arg0().Dereference(); // CLR_INT32 handle; -// CLR_RT_HeapBlock_Array* arrData = stack.Arg1().DereferenceArray(); +// CLR_RT_HeapBlock_Array* arrData = stack.Arg1().DereferenceArray(); // CLR_UINT32 offset = stack.Arg2().NumericByRef().u4; // CLR_UINT32 count = stack.Arg3().NumericByRef().u4; // CLR_INT32 flags = stack.Arg4().NumericByRef().s4; @@ -348,7 +375,7 @@ HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: // FAULT_ON_NULL(socket); // FAULT_ON_NULL(arrData); - + // handle = socket[ FIELD__m_Handle ].NumericByRef().s4; // /* Because we could have been a rescheduled call due to a prior call that would have blocked, we need to see @@ -359,11 +386,10 @@ HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: // NANOCLR_SET_AND_LEAVE (CLR_E_PROCESS_EXCEPTION); // } -// if(offset + count > arrData->m_numOfElements) NANOCLR_SET_AND_LEAVE(CLR_E_INDEX_OUT_OF_RANGE); - +// if(offset + count > arrData->m_numOfElements) NANOCLR_SET_AND_LEAVE(CLR_E_INDEX_OUT_OF_RANGE); // hbTimeout.SetInteger( timeout_ms ); - + // NANOCLR_CHECK_HRESULT(stack.SetupTimeout( hbTimeout, timeout )); // // @@ -372,7 +398,7 @@ HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: // if(stack.m_customState == 1) // { // stack.PushValueI4( 0 ); - + // stack.m_customState = 2; // } @@ -393,14 +419,15 @@ HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: // if(ret != 0) break; // // non-blocking - allow other threads to run while we wait for handle activity -// NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.WaitEvents( stack.m_owningThread, *timeout, CLR_RT_ExecutionEngine::c_Event_Socket, fRes )); +// NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.WaitEvents( stack.m_owningThread, *timeout, Event_Socket, +// fRes )); // } // // timeout expired // if(!fRes) // { // ret = SOCK_SOCKET_ERROR; - + // ThrowError( stack, SOCK_ETIMEDOUT ); // NANOCLR_SET_AND_LEAVE( CLR_E_PROCESS_EXCEPTION ); @@ -427,7 +454,7 @@ HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: // else // { // CLR_RT_HeapBlock* pBlkAddr = blkAddr.Dereference(); - + // NANOCLR_CHECK_HRESULT(MarshalSockAddress( &addr, addrLen, *pBlkAddr )); // bytes = SOCK_recvfrom( handle, (char*)buf, count, flags, &addr, (int*)&addrLen ); @@ -454,26 +481,26 @@ HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: // if(bytes == SOCK_SOCKET_ERROR) // { // CLR_INT32 err = SOCK_getlasterror(); - + // if(err != SOCK_EWOULDBLOCK) // { // ret = SOCK_SOCKET_ERROR; // break; // } - + // continue; // } // // zero recv bytes indicates the handle has been closed. -// else if(!fSend && (bytes == 0)) +// else if(!fSend && (bytes == 0)) // { // break; // } - + // buf += bytes; // totReadWrite += bytes; // count -= bytes; -// stack.m_evalStack[ 1 ].NumericByRef().s4 = totReadWrite; +// stack.m_evalStack[ 1 ].NumericByRef().s4 = totReadWrite; // // receive returns immediately after receiving bytes. // if(!fSend && (totReadWrite > 0)) @@ -485,7 +512,7 @@ HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: // stack.PopValue(); // totReadWrite // stack.PopValue(); // Timeout - + // NANOCLR_CHECK_HRESULT(ThrowOnError( stack, ret )); // stack.SetResult_I4( totReadWrite ); @@ -493,100 +520,107 @@ HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: // NANOCLR_NOCLEANUP(); // } -HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::SockOptHelper( CLR_RT_StackFrame& stack, bool fGet ) +HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::SockOptHelper( + CLR_RT_StackFrame &stack, + bool fGet) { NATIVE_PROFILE_CLR_NETWORK(); NANOCLR_HEADER(); - CLR_RT_HeapBlock* socket = stack.Arg0().Dereference(); + CLR_RT_HeapBlock *socket = stack.Arg0().Dereference(); CLR_INT32 handle; - CLR_INT32 level = stack.Arg1().NumericByRef().s4; + CLR_INT32 level = stack.Arg1().NumericByRef().s4; CLR_INT32 optname = stack.Arg2().NumericByRef().s4; - CLR_RT_HeapBlock_Array* arrOpt = stack.Arg3().DereferenceArray(); - char* optval; + CLR_RT_HeapBlock_Array *arrOpt = stack.Arg3().DereferenceArray(); + char *optval; CLR_INT32 optlen; CLR_INT32 ret; FAULT_ON_NULL(socket); - handle = socket[ FIELD__m_Handle ].NumericByRef().s4; + handle = socket[FIELD__m_Handle].NumericByRef().s4; FAULT_ON_NULL(arrOpt); - - optval = (char*)arrOpt->GetFirstElement(); + + optval = (char *)arrOpt->GetFirstElement(); optlen = arrOpt->m_numOfElements; - if(fGet) + if (fGet) { - ret = SOCK_getsockopt( handle, level, optname, optval, &optlen ); - _ASSERTE( optlen <= (CLR_INT32)arrOpt->m_numOfElements ); + ret = SOCK_getsockopt(handle, level, optname, optval, &optlen); + _ASSERTE(optlen <= (CLR_INT32)arrOpt->m_numOfElements); } else { - ret = SOCK_setsockopt( handle, level, optname, optval, optlen ); + ret = SOCK_setsockopt(handle, level, optname, optval, optlen); } - NANOCLR_CHECK_HRESULT(ThrowOnError( stack, ret )); + NANOCLR_CHECK_HRESULT(ThrowOnError(stack, ret)); NANOCLR_NOCLEANUP(); } -HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::SockNameHelper( CLR_RT_StackFrame& stack, bool fPeer ) +HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::SockNameHelper( + CLR_RT_StackFrame &stack, + bool fPeer) { NATIVE_PROFILE_CLR_NETWORK(); NANOCLR_HEADER(); - CLR_RT_HeapBlock* socket = stack.Arg0().Dereference(); + CLR_RT_HeapBlock *socket = stack.Arg0().Dereference(); CLR_INT32 handle; CLR_INT32 ret; - + struct SOCK_sockaddr addr; CLR_INT32 addrLen = sizeof(addr); FAULT_ON_NULL(socket); - handle = socket[ FIELD__m_Handle ].NumericByRef().s4; + handle = socket[FIELD__m_Handle].NumericByRef().s4; - if(fPeer) + if (fPeer) { - ret = SOCK_getpeername( handle, &addr, &addrLen ); + ret = SOCK_getpeername(handle, &addr, &addrLen); } else { - ret = SOCK_getsockname( handle, &addr, &addrLen ); + ret = SOCK_getsockname(handle, &addr, &addrLen); } - - NANOCLR_CHECK_HRESULT(ThrowOnError( stack, ret )); - - NANOCLR_CHECK_HRESULT(MarshalSockAddress( stack.Arg1(), &addr, addrLen )); - - NANOCLR_NOCLEANUP(); -} + NANOCLR_CHECK_HRESULT(ThrowOnError(stack, ret)); + NANOCLR_CHECK_HRESULT(MarshalSockAddress(stack.Arg1(), &addr, addrLen)); + NANOCLR_NOCLEANUP(); +} -void Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::ThrowError( CLR_RT_StackFrame& stack, CLR_INT32 errorCode ) -{ +void Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::ThrowError( + CLR_RT_StackFrame &stack, + CLR_INT32 errorCode) +{ NATIVE_PROFILE_CLR_NETWORK(); // CLR_RT_HeapBlock& res = stack.m_owningThread->m_currentException; - - // if((Library_corlib_native_System_Exception::CreateInstance( res, g_CLR_RT_WellKnownTypes.m_SocketException, CLR_E_FAIL, &stack )) == S_OK) + + // if((Library_corlib_native_System_Exception::CreateInstance( res, g_CLR_RT_WellKnownTypes.m_SocketException, + // CLR_E_FAIL, &stack )) == S_OK) // { - // res.Dereference()[ Library_system_sockets_System_Net_Sockets_SocketException::FIELD___errorCode ].SetInteger( errorCode ); + // res.Dereference()[ Library_system_sockets_System_Net_Sockets_SocketException::FIELD___errorCode ].SetInteger( + // errorCode ); // } } -HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::ThrowOnError( CLR_RT_StackFrame& stack, CLR_INT32 res ) -{ +HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::ThrowOnError( + CLR_RT_StackFrame &stack, + CLR_INT32 res) +{ NATIVE_PROFILE_CLR_NETWORK(); NANOCLR_HEADER(); - if(res == SOCK_SOCKET_ERROR) - { + if (res == SOCK_SOCKET_ERROR) + { CLR_INT32 err = SOCK_getlasterror(); - ThrowError( stack, err ); + ThrowError(stack, err); - NANOCLR_SET_AND_LEAVE( CLR_E_PROCESS_EXCEPTION ); + NANOCLR_SET_AND_LEAVE(CLR_E_PROCESS_EXCEPTION); } NANOCLR_NOCLEANUP(); diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Networking.Sockets/win_net_sockets_native_target.h b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Networking.Sockets/win_net_sockets_native_target.h index 90131221da..172ae30e1e 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Networking.Sockets/win_net_sockets_native_target.h +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Networking.Sockets/win_net_sockets_native_target.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. //--------------------------------------------------------------------------- diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Storage/win_storage_native_Windows_Storage_Devices_SDCard.cpp b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Storage/win_storage_native_Windows_Storage_Devices_SDCard.cpp index 4c10bd7e4c..23268d9a55 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Storage/win_storage_native_Windows_Storage_Devices_SDCard.cpp +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Storage/win_storage_native_Windows_Storage_Devices_SDCard.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Storage/win_storage_native_Windows_Storage_FileIO.cpp b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Storage/win_storage_native_Windows_Storage_FileIO.cpp index b84c2a9244..e18cfe0eb4 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Storage/win_storage_native_Windows_Storage_FileIO.cpp +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Storage/win_storage_native_Windows_Storage_FileIO.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // @@ -26,51 +26,51 @@ typedef Library_win_storage_native_Windows_Storage_StorageFile StorageFile; ////////////////////////////////////////// enum FileOperationResult { - FileOperationResult_OK = 0, - FileOperationResult_Error = 10, - FileOperationResult_NoFile = 20, - FileOperationResult_InvalidDrive = 30, + FileOperationResult_OK = 0, + FileOperationResult_Error = 10, + FileOperationResult_NoFile = 20, + FileOperationResult_InvalidDrive = 30, }; ////////////////////////////////////////// struct FileOperation { - #if (HAL_USE_SDC == TRUE) || (HAL_USBH_USE_MSD == TRUE) - FIL* FatFile; - #endif - #if USE_SPIFFS_FOR_STORAGE - spiffs_file* SpiffsFile; - #endif - char* Content; - uint32_t ContentLength; +#if (HAL_USE_SDC == TRUE) || (HAL_USBH_USE_MSD == TRUE) + FIL *FatFile; +#endif +#if USE_SPIFFS_FOR_STORAGE + spiffs_file *SpiffsFile; +#endif + char *Content; + uint32_t ContentLength; }; // this is the FileIO working thread // because FatFS is supposed to be atomic we won't have any concurrent threads -static thread_t* fileIoWorkingThread; +static thread_t *fileIoWorkingThread; // ReadText working thread static THD_FUNCTION(ReadTextWorkingThread, arg) { FileOperationResult opResult = FileOperationResult_OK; - FileOperation* fileIoOperation = (FileOperation*)arg; + FileOperation *fileIoOperation = (FileOperation *)arg; // need an extra one for the terminator uint32_t readLength = fileIoOperation->ContentLength + 1; - #if ((HAL_USE_SDC == TRUE) || (HAL_USBH_USE_MSD == TRUE)) - if(fileIoOperation->FatFile != NULL) +#if ((HAL_USE_SDC == TRUE) || (HAL_USBH_USE_MSD == TRUE)) + if (fileIoOperation->FatFile != NULL) { // read string - if(f_gets((TCHAR*)fileIoOperation->Content, readLength, fileIoOperation->FatFile)) + if (f_gets((TCHAR *)fileIoOperation->Content, readLength, fileIoOperation->FatFile)) { // operation succesfull } else { - switch((FRESULT)f_error(fileIoOperation->FatFile)) + switch ((FRESULT)f_error(fileIoOperation->FatFile)) { case FR_NO_FILE: opResult = FileOperationResult_NoFile; @@ -79,7 +79,7 @@ static THD_FUNCTION(ReadTextWorkingThread, arg) case FR_INVALID_DRIVE: opResult = FileOperationResult_InvalidDrive; break; - + default: opResult = FileOperationResult_Error; break; @@ -91,13 +91,13 @@ static THD_FUNCTION(ReadTextWorkingThread, arg) // free memory platform_free(fileIoOperation->FatFile); - } - #endif - #if USE_SPIFFS_FOR_STORAGE - if(fileIoOperation->SpiffsFile != NULL) +#endif +#if USE_SPIFFS_FOR_STORAGE + if (fileIoOperation->SpiffsFile != NULL) { - uint32_t bytesRead = SPIFFS_read(&fs, *fileIoOperation->SpiffsFile, fileIoOperation->Content, fileIoOperation->ContentLength); + uint32_t bytesRead = + SPIFFS_read(&fs, *fileIoOperation->SpiffsFile, fileIoOperation->Content, fileIoOperation->ContentLength); if (bytesRead == fileIoOperation->ContentLength) { @@ -115,7 +115,7 @@ static THD_FUNCTION(ReadTextWorkingThread, arg) // free memory platform_free(fileIoOperation->SpiffsFile); } - #endif +#endif // free memory platform_free(fileIoOperation); @@ -131,18 +131,18 @@ static THD_FUNCTION(WriteTextWorkingThread, arg) { FileOperationResult opResult = FileOperationResult_OK; - FileOperation* fileIoOperation = (FileOperation*)arg; + FileOperation *fileIoOperation = (FileOperation *)arg; - #if ((HAL_USE_SDC == TRUE) || (HAL_USBH_USE_MSD == TRUE)) - if(fileIoOperation->FatFile != NULL) +#if ((HAL_USE_SDC == TRUE) || (HAL_USBH_USE_MSD == TRUE)) + if (fileIoOperation->FatFile != NULL) { - if(f_puts(fileIoOperation->Content, fileIoOperation->FatFile) == (int)fileIoOperation->ContentLength) + if (f_puts(fileIoOperation->Content, fileIoOperation->FatFile) == (int)fileIoOperation->ContentLength) { // expected number of bytes written } else { - switch((FRESULT)f_error(fileIoOperation->FatFile)) + switch ((FRESULT)f_error(fileIoOperation->FatFile)) { case FR_NO_FILE: opResult = FileOperationResult_NoFile; @@ -151,7 +151,7 @@ static THD_FUNCTION(WriteTextWorkingThread, arg) case FR_INVALID_DRIVE: opResult = FileOperationResult_InvalidDrive; break; - + default: opResult = FileOperationResult_Error; break; @@ -163,13 +163,13 @@ static THD_FUNCTION(WriteTextWorkingThread, arg) // free memory platform_free(fileIoOperation->FatFile); - } - #endif - #if USE_SPIFFS_FOR_STORAGE - if(fileIoOperation->SpiffsFile != NULL) +#endif +#if USE_SPIFFS_FOR_STORAGE + if (fileIoOperation->SpiffsFile != NULL) { - if (SPIFFS_write(&fs, *fileIoOperation->SpiffsFile, fileIoOperation->Content, fileIoOperation->ContentLength) < 0) + if (SPIFFS_write(&fs, *fileIoOperation->SpiffsFile, fileIoOperation->Content, fileIoOperation->ContentLength) < + 0) { // failed to write expected number of bytes opResult = FileOperationResult_Error; @@ -181,13 +181,13 @@ static THD_FUNCTION(WriteTextWorkingThread, arg) // free memory platform_free(fileIoOperation->SpiffsFile); } - #endif +#endif platform_free(fileIoOperation); // fire event for FileIO operation complete Events_Set(SYSTEM_EVENT_FLAG_STORAGE_IO); - + chThdExit((msg_t)opResult); } @@ -196,23 +196,23 @@ static THD_FUNCTION(WriteBinaryWorkingThread, arg) { FileOperationResult opResult = FileOperationResult_OK; - FileOperation* fileIoOperation = (FileOperation*)arg; + FileOperation *fileIoOperation = (FileOperation *)arg; - #if ((HAL_USE_SDC == TRUE) || (HAL_USBH_USE_MSD == TRUE)) - if(fileIoOperation->FatFile != NULL) +#if ((HAL_USE_SDC == TRUE) || (HAL_USBH_USE_MSD == TRUE)) + if (fileIoOperation->FatFile != NULL) { - UINT bytesWritten; + UINT bytesWritten; - FRESULT operationResult = f_write(fileIoOperation->FatFile, fileIoOperation->Content, fileIoOperation->ContentLength, &bytesWritten); + FRESULT operationResult = + f_write(fileIoOperation->FatFile, fileIoOperation->Content, fileIoOperation->ContentLength, &bytesWritten); - if( (operationResult == FR_OK) && - (bytesWritten == fileIoOperation->ContentLength)) + if ((operationResult == FR_OK) && (bytesWritten == fileIoOperation->ContentLength)) { // expected number of bytes written } else { - switch((FRESULT)f_error(fileIoOperation->FatFile)) + switch ((FRESULT)f_error(fileIoOperation->FatFile)) { case FR_NO_FILE: opResult = FileOperationResult_NoFile; @@ -221,7 +221,7 @@ static THD_FUNCTION(WriteBinaryWorkingThread, arg) case FR_INVALID_DRIVE: opResult = FileOperationResult_InvalidDrive; break; - + default: opResult = FileOperationResult_Error; break; @@ -233,13 +233,13 @@ static THD_FUNCTION(WriteBinaryWorkingThread, arg) // free memory platform_free(fileIoOperation->FatFile); - } - #endif - #if USE_SPIFFS_FOR_STORAGE - if(fileIoOperation->SpiffsFile != NULL) +#endif +#if USE_SPIFFS_FOR_STORAGE + if (fileIoOperation->SpiffsFile != NULL) { - if (SPIFFS_write(&fs, *fileIoOperation->SpiffsFile, fileIoOperation->Content, fileIoOperation->ContentLength) < 0) + if (SPIFFS_write(&fs, *fileIoOperation->SpiffsFile, fileIoOperation->Content, fileIoOperation->ContentLength) < + 0) { // failed to write expected number of bytes opResult = FileOperationResult_Error; @@ -251,14 +251,14 @@ static THD_FUNCTION(WriteBinaryWorkingThread, arg) // free memory platform_free(fileIoOperation->SpiffsFile); } - #endif +#endif // free memory platform_free(fileIoOperation); // fire event for FileIO operation complete Events_Set(SYSTEM_EVENT_FLAG_STORAGE_IO); - + chThdExit((msg_t)opResult); } @@ -267,25 +267,25 @@ static THD_FUNCTION(ReadBinaryWorkingThread, arg) { FileOperationResult opResult = FileOperationResult_OK; - FileOperation* fileIoOperation = (FileOperation*)arg; + FileOperation *fileIoOperation = (FileOperation *)arg; - #if ((HAL_USE_SDC == TRUE) || (HAL_USBH_USE_MSD == TRUE)) - if(fileIoOperation->FatFile != NULL) +#if ((HAL_USE_SDC == TRUE) || (HAL_USBH_USE_MSD == TRUE)) + if (fileIoOperation->FatFile != NULL) { UINT bytesRead; - FileOperation* fileIoOperation = (FileOperation*)arg; + FileOperation *fileIoOperation = (FileOperation *)arg; - FRESULT operationResult = f_read(fileIoOperation->FatFile, fileIoOperation->Content, fileIoOperation->ContentLength, &bytesRead); + FRESULT operationResult = + f_read(fileIoOperation->FatFile, fileIoOperation->Content, fileIoOperation->ContentLength, &bytesRead); - if( (operationResult == FR_OK) && - (bytesRead == fileIoOperation->ContentLength)) + if ((operationResult == FR_OK) && (bytesRead == fileIoOperation->ContentLength)) { // expected number of bytes read } else { - switch((FRESULT)f_error(fileIoOperation->FatFile)) + switch ((FRESULT)f_error(fileIoOperation->FatFile)) { case FR_NO_FILE: opResult = FileOperationResult_NoFile; @@ -294,7 +294,7 @@ static THD_FUNCTION(ReadBinaryWorkingThread, arg) case FR_INVALID_DRIVE: opResult = FileOperationResult_InvalidDrive; break; - + default: opResult = FileOperationResult_Error; break; @@ -306,13 +306,13 @@ static THD_FUNCTION(ReadBinaryWorkingThread, arg) // free memory platform_free(fileIoOperation->FatFile); - } - #endif - #if USE_SPIFFS_FOR_STORAGE - if(fileIoOperation->SpiffsFile != NULL) +#endif +#if USE_SPIFFS_FOR_STORAGE + if (fileIoOperation->SpiffsFile != NULL) { - uint32_t bytesRead = SPIFFS_read(&fs, *fileIoOperation->SpiffsFile, fileIoOperation->Content, fileIoOperation->ContentLength); + uint32_t bytesRead = + SPIFFS_read(&fs, *fileIoOperation->SpiffsFile, fileIoOperation->Content, fileIoOperation->ContentLength); if (bytesRead == fileIoOperation->ContentLength) { @@ -330,95 +330,97 @@ static THD_FUNCTION(ReadBinaryWorkingThread, arg) // free memory platform_free(fileIoOperation->SpiffsFile); } - #endif +#endif // free memory platform_free(fileIoOperation); // fire event for FileIO operation complete Events_Set(SYSTEM_EVENT_FLAG_STORAGE_IO); - + chThdExit((msg_t)opResult); } //////////////////////////////////////////////// // Developer notes: -// Depending on the content size these operations have the potential to be a long running ones as the string or buffer is written to the storage. -// Despite we are not (yet!) async this is better handled by spawning a thread where the actual data transfer occurs and not blocking the execution. -// The underlying RTOS inheritably takes care of making this happen "in the background". -// When the operation is completed a CLR event is fired and the thread execution resumes. -// Being hard to estimate the expected duration of the operation (depends on storage hardware, CPU clock, transfer speed, etc) -// the timeout is set to an infinite timeout -// the catch is that the working thread MUST ALWAYS return at some point +// Depending on the content size these operations have the potential to be a long running ones as the string or buffer +// is written to the storage. Despite we are not (yet!) async this is better handled by spawning a thread where the +// actual data transfer occurs and not blocking the execution. The underlying RTOS inheritably takes care of making this +// happen "in the background". When the operation is completed a CLR event is fired and the thread execution resumes. +// Being hard to estimate the expected duration of the operation (depends on storage hardware, CPU clock, transfer +// speed, etc) the timeout is set to an infinite timeout the catch is that the working thread MUST ALWAYS return at some +// point //////////////////////////////////////////////// -HRESULT Library_win_storage_native_Windows_Storage_FileIO::WriteBytes___STATIC__VOID__WindowsStorageIStorageFile__SZARRAY_U1( CLR_RT_StackFrame& stack ) +HRESULT Library_win_storage_native_Windows_Storage_FileIO:: + WriteBytes___STATIC__VOID__WindowsStorageIStorageFile__SZARRAY_U1(CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); - CLR_RT_HeapBlock_Array* bufferArray; + CLR_RT_HeapBlock_Array *bufferArray; - CLR_RT_HeapBlock hbTimeout; - CLR_INT64* timeout; - bool eventResult = true; + CLR_RT_HeapBlock hbTimeout; + CLR_INT64 *timeout; + bool eventResult = true; char workingDrive[DRIVE_LETTER_LENGTH]; - const char* filePath; - char* workingBuffer = NULL; - FileOperation* fileIoOperation; + const char *filePath; + char *workingBuffer = NULL; + FileOperation *fileIoOperation; - char* buffer; - uint32_t bufferLength; + char *buffer; + uint32_t bufferLength; - #if ((HAL_USE_SDC == TRUE) || (HAL_USBH_USE_MSD == TRUE)) - FIL* fatFile = NULL; - FRESULT operationResult; - #endif - #if (USE_SPIFFS_FOR_STORAGE == TRUE) - spiffs_file* spiffsFile = NULL; - #endif +#if ((HAL_USE_SDC == TRUE) || (HAL_USBH_USE_MSD == TRUE)) + FIL *fatFile = NULL; + FRESULT operationResult; +#endif +#if (USE_SPIFFS_FOR_STORAGE == TRUE) + spiffs_file *spiffsFile = NULL; +#endif // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); - + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + // get a pointer to the buffer bufferArray = stack.Arg1().DereferenceArray(); - buffer = (char*)bufferArray->GetFirstElement(); + buffer = (char *)bufferArray->GetFirstElement(); bufferLength = bufferArray->m_numOfElements; // get a pointer to the file path - filePath = pThis[ StorageFile::FIELD___path ].DereferenceString()->StringText(); + filePath = pThis[StorageFile::FIELD___path].DereferenceString()->StringText(); // !! need to cast to CLR_INT64 otherwise it wont setup a proper timeout infinite hbTimeout.SetInteger((CLR_INT64)-1); - NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks( hbTimeout, timeout )); - - if(stack.m_customState == 1) - { + NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks(hbTimeout, timeout)); + + if (stack.m_customState == 1) + { // copy the first 2 letters of the path for the drive // path is 'D:\folder\file.txt', so we need 'D:' memcpy(workingDrive, filePath, DRIVE_LETTER_LENGTH); - if(WORKING_DRIVE_IS_INTERNAL_DRIVE) + if (WORKING_DRIVE_IS_INTERNAL_DRIVE) { - #if (USE_SPIFFS_FOR_STORAGE == TRUE) +#if (USE_SPIFFS_FOR_STORAGE == TRUE) // SPIFFS drive workflow // create file struct - spiffsFile = (spiffs_file*)platform_malloc(sizeof(spiffs_file)); + spiffsFile = (spiffs_file *)platform_malloc(sizeof(spiffs_file)); // check allocation - if(spiffsFile == NULL) + if (spiffsFile == NULL) { NANOCLR_SET_AND_LEAVE(CLR_E_OUT_OF_MEMORY); } // get file name removing the drive letter - workingBuffer = (char*)platform_malloc(SPIFFS_OBJ_NAME_LEN); + workingBuffer = (char *)platform_malloc(SPIFFS_OBJ_NAME_LEN); // sanity check for successfull malloc - if(workingBuffer == NULL) + if (workingBuffer == NULL) { // failed to allocate memory NANOCLR_SET_AND_LEAVE(CLR_E_OUT_OF_MEMORY); @@ -426,22 +428,22 @@ HRESULT Library_win_storage_native_Windows_Storage_FileIO::WriteBytes___STATIC__ memcpy(workingBuffer, (filePath + 3), SPIFFS_OBJ_NAME_LEN - 3); *spiffsFile = SPIFFS_open(&fs, workingBuffer, SPIFFS_TRUNC | SPIFFS_RDWR, 0); - if(*spiffsFile < 0) + if (*spiffsFile < 0) { NANOCLR_SET_AND_LEAVE(CLR_E_FILE_NOT_FOUND); } - #endif +#endif } else { - #if ((HAL_USE_SDC == TRUE) || (HAL_USBH_USE_MSD == TRUE)) +#if ((HAL_USE_SDC == TRUE) || (HAL_USBH_USE_MSD == TRUE)) // FatFS workflow // create file struct - fatFile = (FIL*)platform_malloc(sizeof(FIL)); + fatFile = (FIL *)platform_malloc(sizeof(FIL)); // check allocation - if(fatFile == NULL) + if (fatFile == NULL) { NANOCLR_SET_AND_LEAVE(CLR_E_OUT_OF_MEMORY); } @@ -449,66 +451,72 @@ HRESULT Library_win_storage_native_Windows_Storage_FileIO::WriteBytes___STATIC__ // open file (which is supposed to already exist) // need to use FA_OPEN_ALWAYS because we are writting the file content from start operationResult = f_open(fatFile, filePath, FA_OPEN_ALWAYS | FA_WRITE); - - if(operationResult != FR_OK) + + if (operationResult != FR_OK) { NANOCLR_SET_AND_LEAVE(CLR_E_FILE_NOT_FOUND); } - #endif +#endif } // protect the content buffer from GC so the working thread can access those - CLR_RT_ProtectFromGC gcContent( *bufferArray ); + CLR_RT_ProtectFromGC gcContent(*bufferArray); // setup FileIO operation - fileIoOperation = (FileOperation*)platform_malloc(sizeof(FileOperation)); + fileIoOperation = (FileOperation *)platform_malloc(sizeof(FileOperation)); - #if ((HAL_USE_SDC == TRUE) || (HAL_USBH_USE_MSD == TRUE)) +#if ((HAL_USE_SDC == TRUE) || (HAL_USBH_USE_MSD == TRUE)) fileIoOperation->FatFile = fatFile; - #endif - #if USE_SPIFFS_FOR_STORAGE +#endif +#if USE_SPIFFS_FOR_STORAGE fileIoOperation->SpiffsFile = spiffsFile; - #endif +#endif fileIoOperation->Content = buffer; fileIoOperation->ContentLength = bufferLength; // spawn working thread to perform the write transaction - fileIoWorkingThread = chThdCreateFromHeap(NULL, THD_WORKING_AREA_SIZE(2048), - "STWT", NORMALPRIO, WriteBinaryWorkingThread, fileIoOperation); - - if(fileIoWorkingThread == NULL) + fileIoWorkingThread = chThdCreateFromHeap( + NULL, + THD_WORKING_AREA_SIZE(2048), + "STWT", + NORMALPRIO, + WriteBinaryWorkingThread, + fileIoOperation); + + if (fileIoWorkingThread == NULL) { NANOCLR_SET_AND_LEAVE(CLR_E_PROCESS_EXCEPTION); } // bump custom state stack.m_customState = 2; - } - while(eventResult) + while (eventResult) { // non-blocking wait allowing other threads to run while we wait for the write operation to complete - NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.WaitEvents( stack.m_owningThread, *timeout, CLR_RT_ExecutionEngine::c_Event_StorageIo, eventResult )); + NANOCLR_CHECK_HRESULT( + g_CLR_RT_ExecutionEngine.WaitEvents(stack.m_owningThread, *timeout, Event_StorageIo, eventResult)); - if(eventResult) + if (eventResult) { // event occurred - // ChibiOS requirement: need to call chThdWait on working thread in order to have it's memory released to the heap, otherwise it won't be returned + // ChibiOS requirement: need to call chThdWait on working thread in order to have it's memory released to + // the heap, otherwise it won't be returned FileOperationResult result = (FileOperationResult)chThdWait(fileIoWorkingThread); - if(result == FileOperationResult_Error) + if (result == FileOperationResult_Error) { - NANOCLR_SET_AND_LEAVE( CLR_E_FILE_IO ); + NANOCLR_SET_AND_LEAVE(CLR_E_FILE_IO); } - else if(result == FileOperationResult_NoFile) + else if (result == FileOperationResult_NoFile) { - NANOCLR_SET_AND_LEAVE( CLR_E_FILE_NOT_FOUND ); + NANOCLR_SET_AND_LEAVE(CLR_E_FILE_NOT_FOUND); } - else if(result == FileOperationResult_InvalidDrive) + else if (result == FileOperationResult_InvalidDrive) { // failed to change drive NANOCLR_SET_AND_LEAVE(CLR_E_VOLUME_NOT_FOUND); @@ -519,7 +527,7 @@ HRESULT Library_win_storage_native_Windows_Storage_FileIO::WriteBytes___STATIC__ } else { - NANOCLR_SET_AND_LEAVE( CLR_E_TIMEOUT ); + NANOCLR_SET_AND_LEAVE(CLR_E_TIMEOUT); } } @@ -528,7 +536,7 @@ HRESULT Library_win_storage_native_Windows_Storage_FileIO::WriteBytes___STATIC__ NANOCLR_CLEANUP(); - if(workingBuffer != NULL) + if (workingBuffer != NULL) { platform_free(workingBuffer); } @@ -536,66 +544,68 @@ HRESULT Library_win_storage_native_Windows_Storage_FileIO::WriteBytes___STATIC__ NANOCLR_CLEANUP_END(); } -HRESULT Library_win_storage_native_Windows_Storage_FileIO::WriteText___STATIC__VOID__WindowsStorageIStorageFile__STRING( CLR_RT_StackFrame& stack ) +HRESULT Library_win_storage_native_Windows_Storage_FileIO::WriteText___STATIC__VOID__WindowsStorageIStorageFile__STRING( + CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); - CLR_RT_HeapBlock_String* content; + CLR_RT_HeapBlock_String *content; - CLR_RT_HeapBlock hbTimeout; - CLR_INT64* timeout; - bool eventResult = true; + CLR_RT_HeapBlock hbTimeout; + CLR_INT64 *timeout; + bool eventResult = true; char workingDrive[DRIVE_LETTER_LENGTH]; - const char* filePath; - char* workingBuffer = NULL; - FileOperation* fileIoOperation; - - #if ((HAL_USE_SDC == TRUE) || (HAL_USBH_USE_MSD == TRUE)) - FIL* fatFile = NULL; - FRESULT operationResult; - #endif - #if (USE_SPIFFS_FOR_STORAGE == TRUE) - spiffs_file* spiffsFile = NULL; - #endif + const char *filePath; + char *workingBuffer = NULL; + FileOperation *fileIoOperation; + +#if ((HAL_USE_SDC == TRUE) || (HAL_USBH_USE_MSD == TRUE)) + FIL *fatFile = NULL; + FRESULT operationResult; +#endif +#if (USE_SPIFFS_FOR_STORAGE == TRUE) + spiffs_file *spiffsFile = NULL; +#endif // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); - + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + // get a pointer to the content content = stack.Arg1().DereferenceString(); // get a pointer to the file path - filePath = pThis[ StorageFile::FIELD___path ].DereferenceString()->StringText(); + filePath = pThis[StorageFile::FIELD___path].DereferenceString()->StringText(); // !! need to cast to CLR_INT64 otherwise it wont setup a proper timeout infinite hbTimeout.SetInteger((CLR_INT64)-1); - NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks( hbTimeout, timeout )); - - if(stack.m_customState == 1) - { + NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks(hbTimeout, timeout)); + + if (stack.m_customState == 1) + { // copy the first 2 letters of the path for the drive // path is 'D:\folder\file.txt', so we need 'D:' memcpy(workingDrive, filePath, DRIVE_LETTER_LENGTH); - if(WORKING_DRIVE_IS_INTERNAL_DRIVE) + if (WORKING_DRIVE_IS_INTERNAL_DRIVE) { - #if (USE_SPIFFS_FOR_STORAGE == TRUE) +#if (USE_SPIFFS_FOR_STORAGE == TRUE) // SPIFFS drive workflow // create file struct - spiffsFile = (spiffs_file*)platform_malloc(sizeof(spiffs_file)); + spiffsFile = (spiffs_file *)platform_malloc(sizeof(spiffs_file)); // check allocation - if(spiffsFile == NULL) + if (spiffsFile == NULL) { NANOCLR_SET_AND_LEAVE(CLR_E_OUT_OF_MEMORY); } // get file name removing the drive letter - workingBuffer = (char*)platform_malloc(SPIFFS_OBJ_NAME_LEN); + workingBuffer = (char *)platform_malloc(SPIFFS_OBJ_NAME_LEN); // sanity check for successfull malloc - if(workingBuffer == NULL) + if (workingBuffer == NULL) { // failed to allocate memory NANOCLR_SET_AND_LEAVE(CLR_E_OUT_OF_MEMORY); @@ -603,22 +613,22 @@ HRESULT Library_win_storage_native_Windows_Storage_FileIO::WriteText___STATIC__V memcpy(workingBuffer, (filePath + 3), SPIFFS_OBJ_NAME_LEN - 3); *spiffsFile = SPIFFS_open(&fs, workingBuffer, SPIFFS_TRUNC | SPIFFS_RDWR, 0); - if(*spiffsFile < 0) + if (*spiffsFile < 0) { NANOCLR_SET_AND_LEAVE(CLR_E_FILE_NOT_FOUND); } - #endif +#endif } else { - #if ((HAL_USE_SDC == TRUE) || (HAL_USBH_USE_MSD == TRUE)) +#if ((HAL_USE_SDC == TRUE) || (HAL_USBH_USE_MSD == TRUE)) // FatFS workflow // create file struct - fatFile = (FIL*)platform_malloc(sizeof(FIL)); + fatFile = (FIL *)platform_malloc(sizeof(FIL)); // check allocation - if(fatFile == NULL) + if (fatFile == NULL) { NANOCLR_SET_AND_LEAVE(CLR_E_OUT_OF_MEMORY); } @@ -626,36 +636,41 @@ HRESULT Library_win_storage_native_Windows_Storage_FileIO::WriteText___STATIC__V // open file (which is supposed to already exist) // need to use FA_OPEN_ALWAYS because we are writting the file content from start operationResult = f_open(fatFile, filePath, FA_OPEN_ALWAYS | FA_WRITE); - - if(operationResult != FR_OK) + + if (operationResult != FR_OK) { NANOCLR_SET_AND_LEAVE(CLR_E_FILE_NOT_FOUND); } - #endif +#endif } // protect the content buffer from GC so the working thread can access those - CLR_RT_ProtectFromGC gcContent( *content ); + CLR_RT_ProtectFromGC gcContent(*content); // setup FileIO operation - fileIoOperation = (FileOperation*)platform_malloc(sizeof(FileOperation)); + fileIoOperation = (FileOperation *)platform_malloc(sizeof(FileOperation)); - #if ((HAL_USE_SDC == TRUE) || (HAL_USBH_USE_MSD == TRUE)) +#if ((HAL_USE_SDC == TRUE) || (HAL_USBH_USE_MSD == TRUE)) fileIoOperation->FatFile = fatFile; - #endif - #if USE_SPIFFS_FOR_STORAGE +#endif +#if USE_SPIFFS_FOR_STORAGE fileIoOperation->SpiffsFile = spiffsFile; - #endif +#endif - fileIoOperation->Content = (char*)content->StringText(); + fileIoOperation->Content = (char *)content->StringText(); fileIoOperation->ContentLength = hal_strlen_s(fileIoOperation->Content); // spawn working thread to perform the write transaction - fileIoWorkingThread = chThdCreateFromHeap(NULL, THD_WORKING_AREA_SIZE(2048), - "STWT", NORMALPRIO, WriteTextWorkingThread, fileIoOperation); - - if(fileIoWorkingThread == NULL) + fileIoWorkingThread = chThdCreateFromHeap( + NULL, + THD_WORKING_AREA_SIZE(2048), + "STWT", + NORMALPRIO, + WriteTextWorkingThread, + fileIoOperation); + + if (fileIoWorkingThread == NULL) { NANOCLR_SET_AND_LEAVE(CLR_E_PROCESS_EXCEPTION); } @@ -664,27 +679,29 @@ HRESULT Library_win_storage_native_Windows_Storage_FileIO::WriteText___STATIC__V stack.m_customState = 2; } - while(eventResult) + while (eventResult) { // non-blocking wait allowing other threads to run while we wait for the write operation to complete - NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.WaitEvents( stack.m_owningThread, *timeout, CLR_RT_ExecutionEngine::c_Event_StorageIo, eventResult )); + NANOCLR_CHECK_HRESULT( + g_CLR_RT_ExecutionEngine.WaitEvents(stack.m_owningThread, *timeout, Event_StorageIo, eventResult)); - if(eventResult) + if (eventResult) { // event occurred - // ChibiOS requirement: need to call chThdWait on working thread in order to have it's memory released to the heap, otherwise it won't be returned + // ChibiOS requirement: need to call chThdWait on working thread in order to have it's memory released to + // the heap, otherwise it won't be returned FileOperationResult result = (FileOperationResult)chThdWait(fileIoWorkingThread); - if(result == FileOperationResult_Error) + if (result == FileOperationResult_Error) { - NANOCLR_SET_AND_LEAVE( CLR_E_FILE_IO ); + NANOCLR_SET_AND_LEAVE(CLR_E_FILE_IO); } - else if(result == FileOperationResult_NoFile) + else if (result == FileOperationResult_NoFile) { - NANOCLR_SET_AND_LEAVE( CLR_E_FILE_NOT_FOUND ); + NANOCLR_SET_AND_LEAVE(CLR_E_FILE_NOT_FOUND); } - else if(result == FileOperationResult_InvalidDrive) + else if (result == FileOperationResult_InvalidDrive) { // failed to change drive NANOCLR_SET_AND_LEAVE(CLR_E_VOLUME_NOT_FOUND); @@ -695,7 +712,7 @@ HRESULT Library_win_storage_native_Windows_Storage_FileIO::WriteText___STATIC__V } else { - NANOCLR_SET_AND_LEAVE( CLR_E_TIMEOUT ); + NANOCLR_SET_AND_LEAVE(CLR_E_TIMEOUT); } } @@ -704,7 +721,7 @@ HRESULT Library_win_storage_native_Windows_Storage_FileIO::WriteText___STATIC__V NANOCLR_CLEANUP(); - if(workingBuffer != NULL) + if (workingBuffer != NULL) { platform_free(workingBuffer); } @@ -712,62 +729,64 @@ HRESULT Library_win_storage_native_Windows_Storage_FileIO::WriteText___STATIC__V NANOCLR_CLEANUP_END(); } -HRESULT Library_win_storage_native_Windows_Storage_FileIO::ReadBufferNative___STATIC__VOID__WindowsStorageIStorageFile__BYREF_SZARRAY_U1( CLR_RT_StackFrame& stack ) +HRESULT Library_win_storage_native_Windows_Storage_FileIO:: + ReadBufferNative___STATIC__VOID__WindowsStorageIStorageFile__BYREF_SZARRAY_U1(CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); - - CLR_RT_HeapBlock hbTimeout; - CLR_INT64* timeout; - bool eventResult = true; - uint32_t fileSize = 0; + + CLR_RT_HeapBlock hbTimeout; + CLR_INT64 *timeout; + bool eventResult = true; + uint32_t fileSize = 0; char workingDrive[DRIVE_LETTER_LENGTH]; - const char* filePath; - char* workingBuffer = NULL; - FileOperation* fileIoOperation; - - #if ((HAL_USE_SDC == TRUE) || (HAL_USBH_USE_MSD == TRUE)) - FIL* fatFile = NULL; - FRESULT operationResult; - #endif - #if (USE_SPIFFS_FOR_STORAGE == TRUE) - spiffs_file* spiffsFile = NULL; - #endif + const char *filePath; + char *workingBuffer = NULL; + FileOperation *fileIoOperation; + +#if ((HAL_USE_SDC == TRUE) || (HAL_USBH_USE_MSD == TRUE)) + FIL *fatFile = NULL; + FRESULT operationResult; +#endif +#if (USE_SPIFFS_FOR_STORAGE == TRUE) + spiffs_file *spiffsFile = NULL; +#endif // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); // !! need to cast to CLR_INT64 otherwise it wont setup a proper timeout infinite hbTimeout.SetInteger((CLR_INT64)-1); - NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks( hbTimeout, timeout )); + NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks(hbTimeout, timeout)); // get a pointer to the file path - filePath = pThis[ StorageFile::FIELD___path ].DereferenceString()->StringText(); - - if(stack.m_customState == 1) + filePath = pThis[StorageFile::FIELD___path].DereferenceString()->StringText(); + + if (stack.m_customState == 1) { // copy the first 2 letters of the path for the drive // path is 'D:\folder\file.txt', so we need 'D:' memcpy(workingDrive, filePath, DRIVE_LETTER_LENGTH); - if(WORKING_DRIVE_IS_INTERNAL_DRIVE) + if (WORKING_DRIVE_IS_INTERNAL_DRIVE) { - #if (USE_SPIFFS_FOR_STORAGE == TRUE) +#if (USE_SPIFFS_FOR_STORAGE == TRUE) // SPIFFS drive workflow // create file struct - spiffsFile = (spiffs_file*)platform_malloc(sizeof(spiffs_file)); + spiffsFile = (spiffs_file *)platform_malloc(sizeof(spiffs_file)); // check allocation - if(spiffsFile == NULL) + if (spiffsFile == NULL) { NANOCLR_SET_AND_LEAVE(CLR_E_OUT_OF_MEMORY); } // get file name removing the drive letter - workingBuffer = (char*)platform_malloc(SPIFFS_OBJ_NAME_LEN); + workingBuffer = (char *)platform_malloc(SPIFFS_OBJ_NAME_LEN); // sanity check for successfull malloc - if(workingBuffer == NULL) + if (workingBuffer == NULL) { // failed to allocate memory NANOCLR_SET_AND_LEAVE(CLR_E_OUT_OF_MEMORY); @@ -775,7 +794,7 @@ HRESULT Library_win_storage_native_Windows_Storage_FileIO::ReadBufferNative___ST memcpy(workingBuffer, (filePath + 3), SPIFFS_OBJ_NAME_LEN - 3); *spiffsFile = SPIFFS_open(&fs, workingBuffer, SPIFFS_RDONLY, 0); - if(*spiffsFile < 0) + if (*spiffsFile < 0) { NANOCLR_SET_AND_LEAVE(CLR_E_FILE_NOT_FOUND); } @@ -787,70 +806,76 @@ HRESULT Library_win_storage_native_Windows_Storage_FileIO::ReadBufferNative___ST // we are only interested in the file size fileSize = fileInfo.size; - #endif +#endif } else { - #if ((HAL_USE_SDC == TRUE) || (HAL_USBH_USE_MSD == TRUE)) +#if ((HAL_USE_SDC == TRUE) || (HAL_USBH_USE_MSD == TRUE)) // FatFS workflow // create file struct - fatFile = (FIL*)platform_malloc(sizeof(FIL)); + fatFile = (FIL *)platform_malloc(sizeof(FIL)); // check allocation - if(fatFile == NULL) + if (fatFile == NULL) { NANOCLR_SET_AND_LEAVE(CLR_E_OUT_OF_MEMORY); } // open file (which is supposed to already exist) operationResult = f_open(fatFile, filePath, FA_OPEN_EXISTING | FA_READ); - - if(operationResult != FR_OK) + + if (operationResult != FR_OK) { NANOCLR_SET_AND_LEAVE(CLR_E_FILE_NOT_FOUND); } // get file details - FILINFO fileInfo; + FILINFO fileInfo; f_stat(filePath, &fileInfo); // we are only interested in the file size fileSize = fileInfo.fsize; - #endif +#endif } CLR_RT_HeapBlock buffer; - buffer.SetObjectReference( NULL ); - CLR_RT_ProtectFromGC gc2( buffer ); + buffer.SetObjectReference(NULL); + CLR_RT_ProtectFromGC gc2(buffer); // create a new byte array with the appropriate size (and type) - NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_Array::CreateInstance( buffer, (CLR_INT32)fileSize, g_CLR_RT_WellKnownTypes.m_UInt8 )); + NANOCLR_CHECK_HRESULT( + CLR_RT_HeapBlock_Array::CreateInstance(buffer, (CLR_INT32)fileSize, g_CLR_RT_WellKnownTypes.m_UInt8)); // store this to the argument passed byref - NANOCLR_CHECK_HRESULT(buffer.StoreToReference( stack.Arg1(), 0 )); + NANOCLR_CHECK_HRESULT(buffer.StoreToReference(stack.Arg1(), 0)); // get a pointer to the buffer array to improve readability on the code ahead - CLR_RT_HeapBlock_Array* bufferArray = buffer.DereferenceArray(); + CLR_RT_HeapBlock_Array *bufferArray = buffer.DereferenceArray(); // setup FileIO operation - fileIoOperation = (FileOperation*)platform_malloc(sizeof(FileOperation)); + fileIoOperation = (FileOperation *)platform_malloc(sizeof(FileOperation)); - #if ((HAL_USE_SDC == TRUE) || (HAL_USBH_USE_MSD == TRUE)) +#if ((HAL_USE_SDC == TRUE) || (HAL_USBH_USE_MSD == TRUE)) fileIoOperation->FatFile = fatFile; - #endif - #if USE_SPIFFS_FOR_STORAGE +#endif +#if USE_SPIFFS_FOR_STORAGE fileIoOperation->SpiffsFile = spiffsFile; - #endif +#endif - fileIoOperation->Content = (char*)bufferArray->GetFirstElement(); + fileIoOperation->Content = (char *)bufferArray->GetFirstElement(); fileIoOperation->ContentLength = bufferArray->m_numOfElements; // spawn working thread to perform the read transaction - fileIoWorkingThread = chThdCreateFromHeap(NULL, THD_WORKING_AREA_SIZE(2048), - "STRB", NORMALPRIO, ReadBinaryWorkingThread, fileIoOperation); - - if(fileIoWorkingThread == NULL) + fileIoWorkingThread = chThdCreateFromHeap( + NULL, + THD_WORKING_AREA_SIZE(2048), + "STRB", + NORMALPRIO, + ReadBinaryWorkingThread, + fileIoOperation); + + if (fileIoWorkingThread == NULL) { NANOCLR_SET_AND_LEAVE(CLR_E_PROCESS_EXCEPTION); } @@ -859,27 +884,29 @@ HRESULT Library_win_storage_native_Windows_Storage_FileIO::ReadBufferNative___ST stack.m_customState = 2; } - while(eventResult) + while (eventResult) { // non-blocking wait allowing other threads to run while we wait for the write operation to complete - NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.WaitEvents( stack.m_owningThread, *timeout, CLR_RT_ExecutionEngine::c_Event_StorageIo, eventResult )); + NANOCLR_CHECK_HRESULT( + g_CLR_RT_ExecutionEngine.WaitEvents(stack.m_owningThread, *timeout, Event_StorageIo, eventResult)); - if(eventResult) + if (eventResult) { // event occurred - // ChibiOS requirement: need to call chThdWait on working thread in order to have it's memory released to the heap, otherwise it won't be returned + // ChibiOS requirement: need to call chThdWait on working thread in order to have it's memory released to + // the heap, otherwise it won't be returned FileOperationResult result = (FileOperationResult)chThdWait(fileIoWorkingThread); - if(result == FileOperationResult_Error) + if (result == FileOperationResult_Error) { - NANOCLR_SET_AND_LEAVE( CLR_E_FILE_IO ); + NANOCLR_SET_AND_LEAVE(CLR_E_FILE_IO); } - else if(result == FileOperationResult_NoFile) + else if (result == FileOperationResult_NoFile) { - NANOCLR_SET_AND_LEAVE( CLR_E_FILE_NOT_FOUND ); + NANOCLR_SET_AND_LEAVE(CLR_E_FILE_NOT_FOUND); } - else if(result == FileOperationResult_InvalidDrive) + else if (result == FileOperationResult_InvalidDrive) { // failed to change drive NANOCLR_SET_AND_LEAVE(CLR_E_VOLUME_NOT_FOUND); @@ -890,7 +917,7 @@ HRESULT Library_win_storage_native_Windows_Storage_FileIO::ReadBufferNative___ST } else { - NANOCLR_SET_AND_LEAVE( CLR_E_TIMEOUT ); + NANOCLR_SET_AND_LEAVE(CLR_E_TIMEOUT); } } @@ -899,7 +926,7 @@ HRESULT Library_win_storage_native_Windows_Storage_FileIO::ReadBufferNative___ST NANOCLR_CLEANUP(); - if(workingBuffer != NULL) + if (workingBuffer != NULL) { platform_free(workingBuffer); } @@ -907,62 +934,64 @@ HRESULT Library_win_storage_native_Windows_Storage_FileIO::ReadBufferNative___ST NANOCLR_CLEANUP_END(); } -HRESULT Library_win_storage_native_Windows_Storage_FileIO::ReadTextNative___STATIC__VOID__WindowsStorageIStorageFile__BYREF_STRING( CLR_RT_StackFrame& stack ) +HRESULT Library_win_storage_native_Windows_Storage_FileIO:: + ReadTextNative___STATIC__VOID__WindowsStorageIStorageFile__BYREF_STRING(CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); - CLR_RT_HeapBlock hbTimeout; - CLR_INT64* timeout; - bool eventResult = true; - uint32_t fileSize = 0; + CLR_RT_HeapBlock hbTimeout; + CLR_INT64 *timeout; + bool eventResult = true; + uint32_t fileSize = 0; char workingDrive[DRIVE_LETTER_LENGTH]; - const char* filePath; - char* workingBuffer = NULL; - FileOperation* fileIoOperation; - - #if ((HAL_USE_SDC == TRUE) || (HAL_USBH_USE_MSD == TRUE)) - FIL* fatFile = NULL; - FRESULT operationResult; - #endif - #if (USE_SPIFFS_FOR_STORAGE == TRUE) - spiffs_file* spiffsFile = NULL; - #endif + const char *filePath; + char *workingBuffer = NULL; + FileOperation *fileIoOperation; + +#if ((HAL_USE_SDC == TRUE) || (HAL_USBH_USE_MSD == TRUE)) + FIL *fatFile = NULL; + FRESULT operationResult; +#endif +#if (USE_SPIFFS_FOR_STORAGE == TRUE) + spiffs_file *spiffsFile = NULL; +#endif // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); // !! need to cast to CLR_INT64 otherwise it wont setup a proper timeout infinite hbTimeout.SetInteger((CLR_INT64)-1); - NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks( hbTimeout, timeout )); + NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks(hbTimeout, timeout)); // get a pointer to the file path - filePath = pThis[ StorageFile::FIELD___path ].DereferenceString()->StringText(); - - if(stack.m_customState == 1) + filePath = pThis[StorageFile::FIELD___path].DereferenceString()->StringText(); + + if (stack.m_customState == 1) { // copy the first 2 letters of the path for the drive // path is 'D:\folder\file.txt', so we need 'D:' memcpy(workingDrive, filePath, DRIVE_LETTER_LENGTH); - if(WORKING_DRIVE_IS_INTERNAL_DRIVE) + if (WORKING_DRIVE_IS_INTERNAL_DRIVE) { - #if (USE_SPIFFS_FOR_STORAGE == TRUE) +#if (USE_SPIFFS_FOR_STORAGE == TRUE) // SPIFFS drive workflow // create file struct - spiffsFile = (spiffs_file*)platform_malloc(sizeof(spiffs_file)); + spiffsFile = (spiffs_file *)platform_malloc(sizeof(spiffs_file)); // check allocation - if(spiffsFile == NULL) + if (spiffsFile == NULL) { NANOCLR_SET_AND_LEAVE(CLR_E_OUT_OF_MEMORY); } // get file name removing the drive letter - workingBuffer = (char*)platform_malloc(SPIFFS_OBJ_NAME_LEN); + workingBuffer = (char *)platform_malloc(SPIFFS_OBJ_NAME_LEN); // sanity check for successfull malloc - if(workingBuffer == NULL) + if (workingBuffer == NULL) { // failed to allocate memory NANOCLR_SET_AND_LEAVE(CLR_E_OUT_OF_MEMORY); @@ -970,7 +999,7 @@ HRESULT Library_win_storage_native_Windows_Storage_FileIO::ReadTextNative___STAT memcpy(workingBuffer, (filePath + 3), SPIFFS_OBJ_NAME_LEN - 3); *spiffsFile = SPIFFS_open(&fs, workingBuffer, SPIFFS_RDONLY, 0); - if(*spiffsFile < 0) + if (*spiffsFile < 0) { NANOCLR_SET_AND_LEAVE(CLR_E_FILE_NOT_FOUND); } @@ -982,71 +1011,76 @@ HRESULT Library_win_storage_native_Windows_Storage_FileIO::ReadTextNative___STAT // we are only interested in the file size fileSize = fileInfo.size; - #endif +#endif } else { - #if ((HAL_USE_SDC == TRUE) || (HAL_USBH_USE_MSD == TRUE)) +#if ((HAL_USE_SDC == TRUE) || (HAL_USBH_USE_MSD == TRUE)) // FatFS workflow // create file struct - fatFile = (FIL*)platform_malloc(sizeof(FIL)); + fatFile = (FIL *)platform_malloc(sizeof(FIL)); // check allocation - if(fatFile == NULL) + if (fatFile == NULL) { NANOCLR_SET_AND_LEAVE(CLR_E_OUT_OF_MEMORY); } // open file (which is supposed to already exist) operationResult = f_open(fatFile, filePath, FA_OPEN_EXISTING | FA_READ); - - if(operationResult != FR_OK) + + if (operationResult != FR_OK) { NANOCLR_SET_AND_LEAVE(CLR_E_FILE_NOT_FOUND); } // get file details - FILINFO fileInfo; + FILINFO fileInfo; f_stat(filePath, &fileInfo); // we are only interested in the file size fileSize = fileInfo.fsize; - #endif +#endif } // create a new string object with the appropriate size - CLR_RT_HeapBlock hbText; - hbText.SetObjectReference( NULL ); - CLR_RT_ProtectFromGC gc( hbText ); + CLR_RT_HeapBlock hbText; + hbText.SetObjectReference(NULL); + CLR_RT_ProtectFromGC gc(hbText); - CLR_RT_HeapBlock_String* textString = CLR_RT_HeapBlock_String::CreateInstance( hbText, (CLR_UINT32)fileSize ); + CLR_RT_HeapBlock_String *textString = CLR_RT_HeapBlock_String::CreateInstance(hbText, (CLR_UINT32)fileSize); FAULT_ON_NULL(textString); // store this to the argument passed byref - NANOCLR_CHECK_HRESULT(hbText.StoreToReference( stack.Arg1(), 0 )); + NANOCLR_CHECK_HRESULT(hbText.StoreToReference(stack.Arg1(), 0)); // get a pointer to the buffer array to improve readability on the code ahead hbText.DereferenceString(); // setup FileIO operation - fileIoOperation = (FileOperation*)platform_malloc(sizeof(FileOperation)); + fileIoOperation = (FileOperation *)platform_malloc(sizeof(FileOperation)); - #if ((HAL_USE_SDC == TRUE) || (HAL_USBH_USE_MSD == TRUE)) +#if ((HAL_USE_SDC == TRUE) || (HAL_USBH_USE_MSD == TRUE)) fileIoOperation->FatFile = fatFile; - #endif - #if USE_SPIFFS_FOR_STORAGE +#endif +#if USE_SPIFFS_FOR_STORAGE fileIoOperation->SpiffsFile = spiffsFile; - #endif +#endif - fileIoOperation->Content = (char*)textString->StringText(); + fileIoOperation->Content = (char *)textString->StringText(); fileIoOperation->ContentLength = fileSize; // spawn working thread to perform the read transaction - fileIoWorkingThread = chThdCreateFromHeap(NULL, THD_WORKING_AREA_SIZE(2048), - "STRT", NORMALPRIO, ReadTextWorkingThread, fileIoOperation); - - if(fileIoWorkingThread == NULL) + fileIoWorkingThread = chThdCreateFromHeap( + NULL, + THD_WORKING_AREA_SIZE(2048), + "STRT", + NORMALPRIO, + ReadTextWorkingThread, + fileIoOperation); + + if (fileIoWorkingThread == NULL) { NANOCLR_SET_AND_LEAVE(CLR_E_PROCESS_EXCEPTION); } @@ -1055,27 +1089,29 @@ HRESULT Library_win_storage_native_Windows_Storage_FileIO::ReadTextNative___STAT stack.m_customState = 2; } - while(eventResult) + while (eventResult) { // non-blocking wait allowing other threads to run while we wait for the write operation to complete - NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.WaitEvents( stack.m_owningThread, *timeout, CLR_RT_ExecutionEngine::c_Event_StorageIo, eventResult )); + NANOCLR_CHECK_HRESULT( + g_CLR_RT_ExecutionEngine.WaitEvents(stack.m_owningThread, *timeout, Event_StorageIo, eventResult)); - if(eventResult) + if (eventResult) { // event occurred - // ChibiOS requirement: need to call chThdWait on working thread in order to have it's memory released to the heap, otherwise it won't be returned + // ChibiOS requirement: need to call chThdWait on working thread in order to have it's memory released to + // the heap, otherwise it won't be returned FileOperationResult result = (FileOperationResult)chThdWait(fileIoWorkingThread); - if(result == FileOperationResult_Error) + if (result == FileOperationResult_Error) { - NANOCLR_SET_AND_LEAVE( CLR_E_FILE_IO ); + NANOCLR_SET_AND_LEAVE(CLR_E_FILE_IO); } - else if(result == FileOperationResult_NoFile) + else if (result == FileOperationResult_NoFile) { - NANOCLR_SET_AND_LEAVE( CLR_E_FILE_NOT_FOUND ); + NANOCLR_SET_AND_LEAVE(CLR_E_FILE_NOT_FOUND); } - else if(result == FileOperationResult_InvalidDrive) + else if (result == FileOperationResult_InvalidDrive) { // failed to change drive NANOCLR_SET_AND_LEAVE(CLR_E_VOLUME_NOT_FOUND); @@ -1086,7 +1122,7 @@ HRESULT Library_win_storage_native_Windows_Storage_FileIO::ReadTextNative___STAT } else { - NANOCLR_SET_AND_LEAVE( CLR_E_TIMEOUT ); + NANOCLR_SET_AND_LEAVE(CLR_E_TIMEOUT); } } @@ -1095,7 +1131,7 @@ HRESULT Library_win_storage_native_Windows_Storage_FileIO::ReadTextNative___STAT NANOCLR_CLEANUP(); - if(workingBuffer != NULL) + if (workingBuffer != NULL) { platform_free(workingBuffer); } diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Storage/win_storage_native_Windows_Storage_StorageFile.cpp b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Storage/win_storage_native_Windows_Storage_StorageFile.cpp index dbb07cfc46..344146d3b6 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Storage/win_storage_native_Windows_Storage_StorageFile.cpp +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Storage/win_storage_native_Windows_Storage_StorageFile.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Storage/win_storage_native_Windows_Storage_StorageFolder.cpp b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Storage/win_storage_native_Windows_Storage_StorageFolder.cpp index f1032454ea..64ecc3e461 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Storage/win_storage_native_Windows_Storage_StorageFolder.cpp +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Storage/win_storage_native_Windows_Storage_StorageFolder.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Storage/win_storage_native_target.h b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Storage/win_storage_native_target.h index ac692517c8..30b3056be1 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Storage/win_storage_native_target.h +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Storage/win_storage_native_target.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/WireProtocol_App_Interface.c b/targets/CMSIS-OS/ChibiOS/nanoCLR/WireProtocol_App_Interface.c index 7582fbfcff..64fa3d2ec3 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/WireProtocol_App_Interface.c +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/WireProtocol_App_Interface.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/WireProtocol_MonitorCommands.c b/targets/CMSIS-OS/ChibiOS/nanoCLR/WireProtocol_MonitorCommands.c index 3a3646b0ff..c7a76457c3 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/WireProtocol_MonitorCommands.c +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/WireProtocol_MonitorCommands.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/mbedtls_entropy_hardware_pool.c b/targets/CMSIS-OS/ChibiOS/nanoCLR/mbedtls_entropy_hardware_pool.c index 99a8416a34..97b96d0d41 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/mbedtls_entropy_hardware_pool.c +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/mbedtls_entropy_hardware_pool.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/nanoCRT.cpp b/targets/CMSIS-OS/ChibiOS/nanoCLR/nanoCRT.cpp index 10f9097271..6e4189e2f8 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/nanoCRT.cpp +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/nanoCRT.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/nanoFramework.Devices.Can/nf_devices_can_native_nanoFramework_Devices_Can_CanController.cpp b/targets/CMSIS-OS/ChibiOS/nanoCLR/nanoFramework.Devices.Can/nf_devices_can_native_nanoFramework_Devices_Can_CanController.cpp index 798fa59aaa..89f58df027 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/nanoFramework.Devices.Can/nf_devices_can_native_nanoFramework_Devices_Can_CanController.cpp +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/nanoFramework.Devices.Can/nf_devices_can_native_nanoFramework_Devices_Can_CanController.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/nanoFramework.Devices.Can/nf_devices_can_native_target.h b/targets/CMSIS-OS/ChibiOS/nanoCLR/nanoFramework.Devices.Can/nf_devices_can_native_target.h index 4421120698..68b20e6bf5 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/nanoFramework.Devices.Can/nf_devices_can_native_target.h +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/nanoFramework.Devices.Can/nf_devices_can_native_target.h @@ -1,9 +1,8 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // - #ifndef _NF_DEVICES_CAN_NATIVE_TARGET_H_ #define _NF_DEVICES_CAN_NATIVE_TARGET_H_ @@ -11,49 +10,56 @@ #include "target_nf_devices_can_config.h" #include - -// struct representing the CAN -struct NF_PAL_CAN +// struct representing the CAN +typedef struct { - CANDriver* Driver; - CANConfig Configuration; - thread_t* ReceiverThread; + CANDriver *Driver; + CANConfig Configuration; + thread_t *ReceiverThread; HAL_RingBuffer MsgRingBuffer; - CANRxFrame* MsgBuffer; -}; + CANRxFrame *MsgBuffer; +} NF_PAL_CAN; /////////////////////////////////////////// // declaration of the CAN PAL strucs // /////////////////////////////////////////// #if STM32_CAN_USE_CAN1 - extern NF_PAL_CAN Can1_PAL; +extern NF_PAL_CAN Can1_PAL; #endif #if STM32_CAN_USE_CAN2 - extern NF_PAL_CAN Can2_PAL; +extern NF_PAL_CAN Can2_PAL; #endif #if STM32_CAN_USE_CAN3 - extern NF_PAL_CAN Can3_PAL; +extern NF_PAL_CAN Can3_PAL; #endif // the following macro defines a function that configures the GPIO pins for a STM32 CAN -// it gets called in the can_lld_start function// this is required because the CAN peripherals can use multiple GPIO configuration combinations -#define CAN_CONFIG_PINS(num, gpio_port_tx, gpio_port_rx, tx_pin, rx_pin, alternate_function) void ConfigPins_CAN##num() { \ - palSetPadMode(gpio_port_tx, tx_pin, PAL_MODE_ALTERNATE(alternate_function) | PAL_STM32_OTYPE_PUSHPULL \ - | PAL_STM32_OSPEED_HIGHEST | PAL_STM32_MODE_ALTERNATE); \ - palSetPadMode(gpio_port_rx, rx_pin, PAL_MODE_ALTERNATE(alternate_function) | PAL_STM32_OTYPE_PUSHPULL \ - | PAL_STM32_OSPEED_HIGHEST | PAL_STM32_MODE_ALTERNATE); \ -} +// it gets called in the can_lld_start function// this is required because the CAN peripherals can use multiple GPIO +// configuration combinations +#define CAN_CONFIG_PINS(num, gpio_port_tx, gpio_port_rx, tx_pin, rx_pin, alternate_function) \ + void ConfigPins_CAN##num() \ + { \ + palSetPadMode( \ + gpio_port_tx, \ + tx_pin, \ + PAL_MODE_ALTERNATE(alternate_function) | PAL_STM32_OTYPE_PUSHPULL | PAL_STM32_OSPEED_HIGHEST | \ + PAL_STM32_MODE_ALTERNATE); \ + palSetPadMode( \ + gpio_port_rx, \ + rx_pin, \ + PAL_MODE_ALTERNATE(alternate_function) | PAL_STM32_OTYPE_PUSHPULL | PAL_STM32_OSPEED_HIGHEST | \ + PAL_STM32_MODE_ALTERNATE); \ + } /////////////////////////////////////////////////////////////////////////////////////////// -// when a CAN is defined the declarations below will have the real function/configuration +// when a CAN is defined the declarations below will have the real function/configuration // in the target folder @ target_nf_devices_can_config.cpp /////////////////////////////////////////////////////////////////////////////////////////// void ConfigPins_CAN1(); void ConfigPins_CAN2(); void ConfigPins_CAN3(); - ///////////////////////////////////// // CAN Msg buffers // // these live in the target folder // @@ -62,16 +68,18 @@ extern CANRxFrame Can1_MsgBuffer[]; extern CANRxFrame Can2_MsgBuffer[]; extern CANRxFrame Can3_MsgBuffer[]; -// -#define CAN_INIT(num, buffer_size) void Init_Can##num() { \ - Can##num##_PAL.MsgBuffer = Can##num##_MsgBuffer; \ - Can##num##_PAL.MsgRingBuffer.Initialize( Can##num##_PAL.MsgBuffer, buffer_size); \ -} +// +#define CAN_INIT(num, buffer_size) \ + void Init_Can##num() \ + { \ + Can##num##_PAL.MsgBuffer = Can##num##_MsgBuffer; \ + Can##num##_PAL.MsgRingBuffer.Initialize(Can##num##_PAL.MsgBuffer, buffer_size); \ + } -// when a CAN is defined the declarations below will have the real function/configuration +// when a CAN is defined the declarations below will have the real function/configuration // in the target folder @ target_nf_devices_can_config.cpp void Init_Can1(); void Init_Can2(); void Init_Can3(); -#endif //_NF_DEVICES_CAN_NATIVE_TARGET_H_ +#endif //_NF_DEVICES_CAN_NATIVE_TARGET_H_ diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/nanoFramework.Devices.OneWire/nf_devices_onewire_native_nanoFramework_Devices_OneWire_OneWireController.cpp b/targets/CMSIS-OS/ChibiOS/nanoCLR/nanoFramework.Devices.OneWire/nf_devices_onewire_native_nanoFramework_Devices_OneWire_OneWireController.cpp index 08345362a2..124838a0e5 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/nanoFramework.Devices.OneWire/nf_devices_onewire_native_nanoFramework_Devices_OneWire_OneWireController.cpp +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/nanoFramework.Devices.OneWire/nf_devices_onewire_native_nanoFramework_Devices_OneWire_OneWireController.cpp @@ -1,12 +1,12 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // #include "nf_devices_onewire_native_target.h" // working thread to execute long running 1-Wire operations -static thread_t* OneWireWorkingThread; +static thread_t *OneWireWorkingThread; // struct for working threads OneWireFindStruct FindStruct; @@ -16,7 +16,7 @@ static THD_FUNCTION(OneWireFindFirstWorkingThread, arg) { msg_t deviceFound; - OneWireFindStruct* findStruct = (OneWireFindStruct*)arg; + OneWireFindStruct *findStruct = (OneWireFindStruct *)arg; deviceFound = oneWireFindFirst(findStruct->DoReset, findStruct->AlarmOnly); @@ -30,7 +30,7 @@ static THD_FUNCTION(OneWireFindNextWorkingThread, arg) { msg_t deviceFound; - OneWireFindStruct* findStruct = (OneWireFindStruct*)arg; + OneWireFindStruct *findStruct = (OneWireFindStruct *)arg; deviceFound = oneWireFindNext(findStruct->DoReset, findStruct->AlarmOnly); @@ -40,78 +40,83 @@ static THD_FUNCTION(OneWireFindNextWorkingThread, arg) chThdExit(deviceFound); } - -HRESULT Library_nf_devices_onewire_native_nanoFramework_Devices_OneWire_OneWireController::TouchReset___BOOLEAN( CLR_RT_StackFrame& stack ) +HRESULT Library_nf_devices_onewire_native_nanoFramework_Devices_OneWire_OneWireController::TouchReset___BOOLEAN( + CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); volatile bool reset = oneWireTouchReset(); - stack.SetResult_Boolean( reset ) ; + stack.SetResult_Boolean(reset); NANOCLR_NOCLEANUP_NOLABEL(); } -HRESULT Library_nf_devices_onewire_native_nanoFramework_Devices_OneWire_OneWireController::TouchBit___BOOLEAN__BOOLEAN( CLR_RT_StackFrame& stack ) +HRESULT Library_nf_devices_onewire_native_nanoFramework_Devices_OneWire_OneWireController::TouchBit___BOOLEAN__BOOLEAN( + CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); bool value = stack.Arg1().NumericByRefConst().u1 != 0; - stack.SetResult_Boolean( oneWireTouchBit(value) ) ; + stack.SetResult_Boolean(oneWireTouchBit(value)); NANOCLR_NOCLEANUP_NOLABEL(); } -HRESULT Library_nf_devices_onewire_native_nanoFramework_Devices_OneWire_OneWireController::TouchByte___U1__U1( CLR_RT_StackFrame& stack ) +HRESULT Library_nf_devices_onewire_native_nanoFramework_Devices_OneWire_OneWireController::TouchByte___U1__U1( + CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); uint8_t value = (uint8_t)stack.Arg1().NumericByRefConst().u1; uint8_t result = oneWireTouchByte(value); - stack.SetResult_U1( result ) ; + stack.SetResult_U1(result); NANOCLR_NOCLEANUP_NOLABEL(); } -HRESULT Library_nf_devices_onewire_native_nanoFramework_Devices_OneWire_OneWireController::WriteByte___U1__U1( CLR_RT_StackFrame& stack ) +HRESULT Library_nf_devices_onewire_native_nanoFramework_Devices_OneWire_OneWireController::WriteByte___U1__U1( + CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); uint8_t cmd = (uint8_t)stack.Arg1().NumericByRefConst().u1; uint8_t result = oneWireWriteByte(cmd); - stack.SetResult_U1( result ) ; + stack.SetResult_U1(result); NANOCLR_NOCLEANUP_NOLABEL(); } -HRESULT Library_nf_devices_onewire_native_nanoFramework_Devices_OneWire_OneWireController::ReadByte___U1( CLR_RT_StackFrame& stack ) +HRESULT Library_nf_devices_onewire_native_nanoFramework_Devices_OneWire_OneWireController::ReadByte___U1( + CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); uint8_t result = oneWireReadByte(); - stack.SetResult_U1( result ) ; + stack.SetResult_U1(result); NANOCLR_NOCLEANUP_NOLABEL(); } -HRESULT Library_nf_devices_onewire_native_nanoFramework_Devices_OneWire_OneWireController::FindFirstDevice___BOOLEAN__BOOLEAN__BOOLEAN( CLR_RT_StackFrame& stack ) +HRESULT Library_nf_devices_onewire_native_nanoFramework_Devices_OneWire_OneWireController:: + FindFirstDevice___BOOLEAN__BOOLEAN__BOOLEAN(CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); - uint8_t* serialNumberPointer; + uint8_t *serialNumberPointer; msg_t oneWireOperationResult = FALSE; - CLR_RT_HeapBlock hbTimeout; - CLR_INT64* timeout; - bool eventResult = true; + CLR_RT_HeapBlock hbTimeout; + CLR_INT64 *timeout; + bool eventResult = true; // set an infinite timeout to wait forever for the operation to complete // this value has to be in ticks to be properly loaded by SetupTimeoutFromTicks() below hbTimeout.SetInteger((CLR_INT64)-1); - NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks( hbTimeout, timeout )); + NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks(hbTimeout, timeout)); // this is going to be used to check for the right event in case of simultaneous 1-Wire operations - if(stack.m_customState == 1) + if (stack.m_customState == 1) { FindStruct.DoReset = stack.Arg1().NumericByRefConst().u1 != 0; FindStruct.AlarmOnly = stack.Arg2().NumericByRefConst().u1 != 0; @@ -120,81 +125,90 @@ HRESULT Library_nf_devices_onewire_native_nanoFramework_Devices_OneWire_OneWireC oneWireAcquireModule(); // spawn working thread to perform the 1-Wire operations - OneWireWorkingThread = chThdCreateFromHeap(NULL, THD_WORKING_AREA_SIZE(256), - "OWWT", NORMALPRIO, OneWireFindFirstWorkingThread, &FindStruct); + OneWireWorkingThread = chThdCreateFromHeap( + NULL, + THD_WORKING_AREA_SIZE(256), + "OWWT", + NORMALPRIO, + OneWireFindFirstWorkingThread, + &FindStruct); // bump custom state - stack.m_customState = 2; + stack.m_customState = 2; } - while(eventResult) + while (eventResult) { - if(OneWireWorkingThread->state == CH_STATE_FINAL) + if (OneWireWorkingThread->state == CH_STATE_FINAL) { // OneWire working thread is now complete break; } // non-blocking wait allowing other threads to run while we wait for the 1-Wire operations to complete - NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.WaitEvents( stack.m_owningThread, *timeout, CLR_RT_ExecutionEngine::c_Event_OneWireMaster, eventResult )); + NANOCLR_CHECK_HRESULT( + g_CLR_RT_ExecutionEngine.WaitEvents(stack.m_owningThread, *timeout, Event_OneWireMaster, eventResult)); } - if(eventResult) + if (eventResult) { // event occurred - // ChibiOS requirement: need to call chThdWait for working thread in order to have it's memory released to the heap, otherwise it won't be returned + // ChibiOS requirement: need to call chThdWait for working thread in order to have it's memory released to the + // heap, otherwise it won't be returned oneWireOperationResult = chThdWait(OneWireWorkingThread); - + oneWireReleaseModule(); // get the result from the working thread execution - if(oneWireOperationResult) + if (oneWireOperationResult) { // if a device was found update serialNumber field in managed class - + // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); // get a pointer to the serial number field in the OneWireController instance - CLR_RT_HeapBlock_Array* serialNumberField = pThis[ FIELD___serialNumber ].DereferenceArray(); + CLR_RT_HeapBlock_Array *serialNumberField = pThis[FIELD___serialNumber].DereferenceArray(); _ASSERTE(serialNumberField->m_numOfElements == 8); // get a pointer to the first element of the byte array - serialNumberPointer = (uint8_t*)serialNumberField->GetFirstElement(); + serialNumberPointer = (uint8_t *)serialNumberField->GetFirstElement(); oneWireSerialNum(serialNumberPointer, TRUE); } } - + // pop timeout heap block from stack stack.PopValue(); // set result - stack.SetResult_Boolean( oneWireOperationResult ); + stack.SetResult_Boolean(oneWireOperationResult); NANOCLR_NOCLEANUP(); } -HRESULT Library_nf_devices_onewire_native_nanoFramework_Devices_OneWire_OneWireController::FindNextDevice___BOOLEAN__BOOLEAN__BOOLEAN( CLR_RT_StackFrame& stack ) +HRESULT Library_nf_devices_onewire_native_nanoFramework_Devices_OneWire_OneWireController:: + FindNextDevice___BOOLEAN__BOOLEAN__BOOLEAN(CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); - uint8_t* serialNumberPointer; - msg_t oneWireOperationResult = FALSE; + uint8_t *serialNumberPointer; + msg_t oneWireOperationResult = FALSE; - CLR_RT_HeapBlock hbTimeout; - CLR_INT64* timeout; - bool eventResult = true; + CLR_RT_HeapBlock hbTimeout; + CLR_INT64 *timeout; + bool eventResult = true; // set an infinite timeout to wait forever for the operation to complete // this value has to be in ticks to be properly loaded by SetupTimeoutFromTicks() below hbTimeout.SetInteger((CLR_INT64)-1); - NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks( hbTimeout, timeout )); + NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks(hbTimeout, timeout)); // this is going to be used to check for the right event in case of simultaneous 1-Wire operations - if(stack.m_customState == 1) + if (stack.m_customState == 1) { FindStruct.DoReset = stack.Arg1().NumericByRefConst().u1 != 0; FindStruct.AlarmOnly = stack.Arg2().NumericByRefConst().u1 != 0; @@ -203,49 +217,57 @@ HRESULT Library_nf_devices_onewire_native_nanoFramework_Devices_OneWire_OneWireC oneWireAcquireModule(); // spawn working thread to perform the 1-Wire operations - OneWireWorkingThread = chThdCreateFromHeap(NULL, THD_WORKING_AREA_SIZE(256), - "OWWT", NORMALPRIO, OneWireFindNextWorkingThread, &FindStruct); + OneWireWorkingThread = chThdCreateFromHeap( + NULL, + THD_WORKING_AREA_SIZE(256), + "OWWT", + NORMALPRIO, + OneWireFindNextWorkingThread, + &FindStruct); // bump custom state - stack.m_customState = 2; + stack.m_customState = 2; } - while(eventResult) + while (eventResult) { - if(OneWireWorkingThread->state == CH_STATE_FINAL) + if (OneWireWorkingThread->state == CH_STATE_FINAL) { // OneWire working thread is now complete break; } // non-blocking wait allowing other threads to run while we wait for the 1-Wire operations to complete - NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.WaitEvents( stack.m_owningThread, *timeout, CLR_RT_ExecutionEngine::c_Event_OneWireMaster, eventResult )); + NANOCLR_CHECK_HRESULT( + g_CLR_RT_ExecutionEngine.WaitEvents(stack.m_owningThread, *timeout, Event_OneWireMaster, eventResult)); } - if(eventResult) + if (eventResult) { // event occurred - // ChibiOS requirement: need to call chThdWait for working thread in order to have it's memory released to the heap, otherwise it won't be returned + // ChibiOS requirement: need to call chThdWait for working thread in order to have it's memory released to the + // heap, otherwise it won't be returned oneWireOperationResult = chThdWait(OneWireWorkingThread); oneWireReleaseModule(); - + // get the result from the working thread execution - if(oneWireOperationResult) + if (oneWireOperationResult) { // update serialNumber field - + // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); // get a pointer to the serial number field in the OneWireController instance - CLR_RT_HeapBlock_Array* serialNumberField = pThis[ FIELD___serialNumber ].DereferenceArray(); + CLR_RT_HeapBlock_Array *serialNumberField = pThis[FIELD___serialNumber].DereferenceArray(); _ASSERTE(serialNumberField->m_numOfElements == 8); // get a pointer to the first element of the byte array - serialNumberPointer = (uint8_t*)serialNumberField->GetFirstElement(); + serialNumberPointer = (uint8_t *)serialNumberField->GetFirstElement(); oneWireSerialNum(serialNumberPointer, TRUE); } @@ -255,7 +277,7 @@ HRESULT Library_nf_devices_onewire_native_nanoFramework_Devices_OneWire_OneWireC stack.PopValue(); // set result - stack.SetResult_Boolean( oneWireOperationResult ); + stack.SetResult_Boolean(oneWireOperationResult); NANOCLR_NOCLEANUP(); } diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/nanoFramework.Devices.OneWire/nf_devices_onewire_native_target.h b/targets/CMSIS-OS/ChibiOS/nanoCLR/nanoFramework.Devices.OneWire/nf_devices_onewire_native_target.h index f89b8d1c8d..61a2cdd1fe 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/nanoFramework.Devices.OneWire/nf_devices_onewire_native_target.h +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/nanoFramework.Devices.OneWire/nf_devices_onewire_native_target.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/nanoFramework.Hardware.Stm32/nf_hardware_stm32_native.cpp b/targets/CMSIS-OS/ChibiOS/nanoCLR/nanoFramework.Hardware.Stm32/nf_hardware_stm32_native.cpp index d0fc2da9ac..ff15c46246 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/nanoFramework.Hardware.Stm32/nf_hardware_stm32_native.cpp +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/nanoFramework.Hardware.Stm32/nf_hardware_stm32_native.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/nanoFramework.Hardware.Stm32/nf_hardware_stm32_native.h b/targets/CMSIS-OS/ChibiOS/nanoCLR/nanoFramework.Hardware.Stm32/nf_hardware_stm32_native.h index 6366721bc7..1b48a7ad6d 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/nanoFramework.Hardware.Stm32/nf_hardware_stm32_native.h +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/nanoFramework.Hardware.Stm32/nf_hardware_stm32_native.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/nanoFramework.Hardware.Stm32/nf_hardware_stm32_native_nanoFramework_Hardware_Stm32_BackupMemory.cpp b/targets/CMSIS-OS/ChibiOS/nanoCLR/nanoFramework.Hardware.Stm32/nf_hardware_stm32_native_nanoFramework_Hardware_Stm32_BackupMemory.cpp index d75a399d85..7a6ab762ad 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/nanoFramework.Hardware.Stm32/nf_hardware_stm32_native_nanoFramework_Hardware_Stm32_BackupMemory.cpp +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/nanoFramework.Hardware.Stm32/nf_hardware_stm32_native_nanoFramework_Hardware_Stm32_BackupMemory.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/nanoFramework.Hardware.Stm32/nf_hardware_stm32_native_nanoFramework_Hardware_Stm32_Power.cpp b/targets/CMSIS-OS/ChibiOS/nanoCLR/nanoFramework.Hardware.Stm32/nf_hardware_stm32_native_nanoFramework_Hardware_Stm32_Power.cpp index 83854bb6b8..fb9721049a 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/nanoFramework.Hardware.Stm32/nf_hardware_stm32_native_nanoFramework_Hardware_Stm32_Power.cpp +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/nanoFramework.Hardware.Stm32/nf_hardware_stm32_native_nanoFramework_Hardware_Stm32_Power.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/nanoFramework.Hardware.Stm32/nf_hardware_stm32_native_nanoFramework_Hardware_Stm32_RTC.cpp b/targets/CMSIS-OS/ChibiOS/nanoCLR/nanoFramework.Hardware.Stm32/nf_hardware_stm32_native_nanoFramework_Hardware_Stm32_RTC.cpp index 089cb6b66b..77a6cc1963 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/nanoFramework.Hardware.Stm32/nf_hardware_stm32_native_nanoFramework_Hardware_Stm32_RTC.cpp +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/nanoFramework.Hardware.Stm32/nf_hardware_stm32_native_nanoFramework_Hardware_Stm32_RTC.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/nanoFramework.Hardware.Stm32/nf_hardware_stm32_native_nanoFramework_Hardware_Stm32_Utilities.cpp b/targets/CMSIS-OS/ChibiOS/nanoCLR/nanoFramework.Hardware.Stm32/nf_hardware_stm32_native_nanoFramework_Hardware_Stm32_Utilities.cpp index 4d2d2525f5..339723e34f 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/nanoFramework.Hardware.Stm32/nf_hardware_stm32_native_nanoFramework_Hardware_Stm32_Utilities.cpp +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/nanoFramework.Hardware.Stm32/nf_hardware_stm32_native_nanoFramework_Hardware_Stm32_Utilities.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/nanoFramework.Runtime.Native/nf_rt_native_nanoFramework_Runtime_Native_Rtc.cpp b/targets/CMSIS-OS/ChibiOS/nanoCLR/nanoFramework.Runtime.Native/nf_rt_native_nanoFramework_Runtime_Native_Rtc.cpp index 735f3323e1..613317b385 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/nanoFramework.Runtime.Native/nf_rt_native_nanoFramework_Runtime_Native_Rtc.cpp +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/nanoFramework.Runtime.Native/nf_rt_native_nanoFramework_Runtime_Native_Rtc.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/targetHAL.cpp b/targets/CMSIS-OS/ChibiOS/nanoCLR/targetHAL.cpp index 5852708d93..a7f52c41c4 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/targetHAL.cpp +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/targetHAL.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // @@ -9,15 +9,31 @@ #include #include #include +#include #include #include +#if (HAL_USE_CAN == TRUE) +#include +#endif +#if (HAL_USE_I2C == TRUE) +#include +#endif +#if (HAL_USE_SPI == TRUE) +#include +#endif +#if (HAL_USE_UART == TRUE) +#include "win_dev_serial_native_target.h" +#endif + // global mutex protecting the internal state of the interpreter, including event flags -//mutex_t interpreterGlobalMutex; +// mutex_t interpreterGlobalMutex; + +// because nanoHAL_Initialize/Uninitialize needs to be called in both C and C++ we need a proxy to allow it to be called +// in 'C' +extern "C" +{ -// because nanoHAL_Initialize/Uninitialize needs to be called in both C and C++ we need a proxy to allow it to be called in 'C' -extern "C" { - void nanoHAL_Initialize_C() { nanoHAL_Initialize(); @@ -32,10 +48,10 @@ extern "C" { void nanoHAL_Initialize() { // initialize global mutex - //chMtxObjectInit(&interpreterGlobalMutex); + // chMtxObjectInit(&interpreterGlobalMutex); HAL_CONTINUATION::InitializeList(); - HAL_COMPLETION ::InitializeList(); + HAL_COMPLETION ::InitializeList(); BlockStorageList_Initialize(); @@ -45,10 +61,10 @@ void nanoHAL_Initialize() BlockStorageList_InitializeDevices(); // clear managed heap region - unsigned char* heapStart = NULL; - unsigned int heapSize = 0; + unsigned char *heapStart = NULL; + unsigned int heapSize = 0; - ::HeapLocation( heapStart, heapSize ); + ::HeapLocation(heapStart, heapSize); memset(heapStart, 0, heapSize); ConfigurationManager_Initialize(); @@ -58,16 +74,80 @@ void nanoHAL_Initialize() CPU_GPIO_Initialize(); // no PAL events required until now - //PalEvent_Initialize(); - - // Initialise Network Stack + // PalEvent_Initialize(); + +#if (HAL_USE_CAN == TRUE) + +#if STM32_CAN_USE_CAN1 + Can1_PAL.Driver = NULL; +#endif +#if STM32_CAN_USE_CAN2 + Can2_PAL.Driver = NULL; +#endif +#if STM32_CAN_USE_CAN3 + Can3_PAL.Driver = NULL; +#endif + +#endif + +#if (HAL_USE_I2C == TRUE) + +#if STM32_I2C_USE_I2C1 + I2C1_PAL.Driver = NULL; +#endif +#if STM32_I2C_USE_I2C2 + I2C2_PAL.Driver = NULL; +#endif +#if STM32_I2C_USE_I2C3 + I2C3_PAL.Driver = NULL; +#endif +#if STM32_I2C_USE_I2C4 + I2C4_PAL.Driver = NULL; +#endif + +#endif + +#if (HAL_USE_SPI == TRUE) + nanoSPI_Initialize(); +#endif + +#if (HAL_USE_UART == TRUE) + +#if NF_SERIAL_COMM_STM32_UART_USE_USART1 + Uart1_PAL.UartDriver = NULL; +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_USART2 + Uart2_PAL.UartDriver = NULL; +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_USART3 + Uart3_PAL.UartDriver = NULL; +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_UART4 + Uart4_PAL.UartDriver = NULL; +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_UART5 + Uart5_PAL.UartDriver = NULL; +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_USART6 + Uart6_PAL.UartDriver = NULL; +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_UART7 + Uart7_PAL.UartDriver = NULL; +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_UART8 + Uart8_PAL.UartDriver = NULL; +#endif + +#endif + + // Initialise Network Stack Network_Initialize(); } void nanoHAL_Uninitialize() { // release the global mutex, just in case it's locked somewhere - //chMtxUnlock(&interpreterGlobalMutex); + // chMtxUnlock(&interpreterGlobalMutex); // TODO check for s_rebootHandlers // for(int i = 0; i< ARRAYSIZE(s_rebootHandlers); i++) @@ -80,138 +160,105 @@ void nanoHAL_Uninitialize() // { // break; // } - // } + // } SOCKETS_CloseConnections(); - #if !defined(HAL_REDUCESIZE) +#if !defined(HAL_REDUCESIZE) // TODO need to call this but it's preventing the debug session from starting - //Network_Uninitialize(); - #endif + // Network_Uninitialize(); +#endif BlockStorageList_UnInitializeDevices(); - // need to be sure that all mutexes for drivers that use them are released + // need to be sure that: + // - all mutexes for drivers that use them are released + // - all drivers are stopped + #if (HAL_USE_SPI == TRUE) + nanoSPI_Uninitialize(); +#endif + +#if (HAL_USE_CAN == TRUE) - #if STM32_SPI_USE_SPI1 - spiReleaseBus(&SPID1); - #endif - #if STM32_SPI_USE_SPI2 - spiReleaseBus(&SPID2); - #endif - #if STM32_SPI_USE_SPI3 - spiReleaseBus(&SPID3); - #endif - #if STM32_SPI_USE_SPI4 - spiReleaseBus(&SPID4); - #endif - #if STM32_SPI_USE_SPI5 - spiReleaseBus(&SPID5); - #endif - #if STM32_SPI_USE_SPI6 - spiReleaseBus(&SPID6); - #endif +#if STM32_CAN_USE_CAN1 + canStop(&CAND1); +#endif +#if STM32_CAN_USE_CAN2 + canStop(&CAND2); +#endif +#if STM32_CAN_USE_CAN3 + canStop(&CAND3); +#endif #endif #if (HAL_USE_I2C == TRUE) - #if STM32_I2C_USE_I2C1 +#if STM32_I2C_USE_I2C1 i2cReleaseBus(&I2CD1); - #endif - #if STM32_I2C_USE_I2C2 + i2cStop(&I2CD1); +#endif +#if STM32_I2C_USE_I2C2 i2cReleaseBus(&I2CD2); - #endif - #if STM32_I2C_USE_I2C3 + i2cStop(&I2CD2); +#endif +#if STM32_I2C_USE_I2C3 i2cReleaseBus(&I2CD3); - #endif - #if STM32_I2C_USE_I2C4 + i2cStop(&I2CD3); +#endif +#if STM32_I2C_USE_I2C4 i2cReleaseBus(&I2CD4); - #endif + i2cStop(&I2CD4); +#endif + +#endif +#if (HAL_USE_SPI == TRUE) + nanoSPI_Uninitialize(); #endif #if (HAL_USE_UART == TRUE) - #if NF_SERIAL_COMM_STM32_UART_USE_USART1 +#if NF_SERIAL_COMM_STM32_UART_USE_USART1 uartReleaseBus(&UARTD1); - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_USART2 + uartStop(&UARTD1); +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_USART2 uartReleaseBus(&UARTD2); - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_USART3 + uartStop(&UARTD2); +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_USART3 uartReleaseBus(&UARTD3); - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_UART4 + uartStop(&UARTD3); +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_UART4 uartReleaseBus(&UARTD4); - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_UART5 + uartStop(&UARTD4); +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_UART5 uartReleaseBus(&UARTD5); - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_USART6 + uartStop(&UARTD5); +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_USART6 uartReleaseBus(&UARTD6); - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_UART7 + uartStop(&UARTD6); +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_UART7 uartReleaseBus(&UARTD7); - #endif - #if NF_SERIAL_COMM_STM32_UART_USE_UART8 + uartStop(&UARTD7); +#endif +#if NF_SERIAL_COMM_STM32_UART_USE_UART8 uartReleaseBus(&UARTD8); - #endif + uartStop(&UARTD8); +#endif #endif CPU_GPIO_Uninitialize(); Events_Uninitialize(); - - HAL_CONTINUATION::Uninitialize(); - HAL_COMPLETION ::Uninitialize(); -} - -volatile int32_t SystemStates[SYSTEM_STATE_TOTAL_STATES]; - -void SystemState_SetNoLock(SYSTEM_STATE_type state) -{ - SystemStates[state]++; -} - -void SystemState_ClearNoLock(SYSTEM_STATE_type state) -{ - SystemStates[state]--; -} - -bool SystemState_QueryNoLock(SYSTEM_STATE_type state) -{ - return (SystemStates[state] > 0) ? true : false; -} -void SystemState_Set(SYSTEM_STATE_type state) -{ - GLOBAL_LOCK(); - - SystemState_SetNoLock(state); - - GLOBAL_UNLOCK(); -} - -void SystemState_Clear(SYSTEM_STATE_type state) -{ - GLOBAL_LOCK(); - - SystemState_ClearNoLock(state ); - - GLOBAL_UNLOCK(); + HAL_CONTINUATION::Uninitialize(); + HAL_COMPLETION ::Uninitialize(); } - -bool SystemState_Query(SYSTEM_STATE_type state) -{ - bool systemStateCopy = false; - GLOBAL_LOCK(); - - systemStateCopy = SystemState_QueryNoLock(state); - - GLOBAL_UNLOCK(); - - return systemStateCopy; -} diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/targetHAL_Power.c b/targets/CMSIS-OS/ChibiOS/nanoCLR/targetHAL_Power.c index 766376dec0..1addae9261 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/targetHAL_Power.c +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/targetHAL_Power.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/targetHAL_Time.cpp b/targets/CMSIS-OS/ChibiOS/nanoCLR/targetHAL_Time.cpp index de1fa4a9e7..4cb3121c3d 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/targetHAL_Time.cpp +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/targetHAL_Time.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/targetHAL_Watchdog.c b/targets/CMSIS-OS/ChibiOS/nanoCLR/targetHAL_Watchdog.c index 3c86bef131..7cdf23ab5f 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/targetHAL_Watchdog.c +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/targetHAL_Watchdog.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/targetPAL.c b/targets/CMSIS-OS/ChibiOS/nanoCLR/targetPAL.c index 8c63f2e704..b18d03d64f 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/targetPAL.c +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/targetPAL.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/targetPAL_Events.cpp b/targets/CMSIS-OS/ChibiOS/nanoCLR/targetPAL_Events.cpp index 23d616b6e0..dc633a1504 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/targetPAL_Events.cpp +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/targetPAL_Events.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // @@ -13,132 +13,79 @@ uint64_t CPU_MillisecondsToTicks(uint64_t ticks); // timer for bool events static virtual_timer_t boolEventsTimer; -uint32_t systemEvents; -set_Event_Callback g_Event_Callback = NULL; -void* g_Event_Callback_Arg = NULL; - -bool Events_Initialize() -{ - NATIVE_PROFILE_PAL_EVENTS(); - - // init events - GLOBAL_LOCK(); - systemEvents = 0; - GLOBAL_UNLOCK(); - - return true; -} - -bool Events_Uninitialize() +bool Events_Uninitialize_Platform() { - NATIVE_PROFILE_PAL_EVENTS(); - chVTReset(&boolEventsTimer); return true; } -void Events_Set( uint32_t events ) -{ - NATIVE_PROFILE_PAL_EVENTS(); - - // set events - GLOBAL_LOCK(); - systemEvents |= events; - GLOBAL_UNLOCK(); - - if( g_Event_Callback != NULL ) - { - g_Event_Callback( g_Event_Callback_Arg ); - } -} - -uint32_t Events_Get( uint32_t eventsOfInterest ) -{ - NATIVE_PROFILE_PAL_EVENTS(); - - // get the requested flags from system events state and... - uint32_t returnEvents = (systemEvents & eventsOfInterest); - - // ... clear the requested flags atomically - GLOBAL_LOCK(); - systemEvents &= ~eventsOfInterest; - GLOBAL_UNLOCK(); - - // give the caller notice of just the events they asked for ( and were cleared already ) - return returnEvents; -} - -uint32_t Events_MaskedRead( uint32_t eventsOfInterest ) +static void local_Events_SetBoolTimer_Callback(void *arg) { NATIVE_PROFILE_PAL_EVENTS(); - return (systemEvents & eventsOfInterest); -} - -static void local_Events_SetBoolTimer_Callback( void* arg ) -{ - NATIVE_PROFILE_PAL_EVENTS(); - bool* timerCompleteFlag = (bool*)arg; + bool *timerCompleteFlag = (bool *)arg; *timerCompleteFlag = true; } -void Events_SetCallback( set_Event_Callback pfn, void* arg ) +void Events_SetBoolTimer(bool *timerCompleteFlag, uint32_t millisecondsFromNow) { NATIVE_PROFILE_PAL_EVENTS(); - g_Event_Callback = pfn; - g_Event_Callback_Arg = arg; -} - -void Events_SetBoolTimer( bool* timerCompleteFlag, uint32_t millisecondsFromNow ) -{ - NATIVE_PROFILE_PAL_EVENTS(); - - if(timerCompleteFlag != NULL) + if (timerCompleteFlag != NULL) { // no need to stop the timer even if it's running because the API does it anyway - if (port_is_isr_context()){ - chVTSetI(&boolEventsTimer, TIME_MS2I(millisecondsFromNow), local_Events_SetBoolTimer_Callback, timerCompleteFlag); - } - else{ - chVTSet(&boolEventsTimer, TIME_MS2I(millisecondsFromNow), local_Events_SetBoolTimer_Callback, timerCompleteFlag); - } + if (port_is_isr_context()) + { + chVTSetI( + &boolEventsTimer, + TIME_MS2I(millisecondsFromNow), + local_Events_SetBoolTimer_Callback, + timerCompleteFlag); + } + else + { + chVTSet( + &boolEventsTimer, + TIME_MS2I(millisecondsFromNow), + local_Events_SetBoolTimer_Callback, + timerCompleteFlag); + } } } -uint32_t Events_WaitForEvents( uint32_t powerLevel, uint32_t wakeupSystemEvents, uint32_t timeoutMilliseconds ) +uint32_t Events_WaitForEvents(uint32_t powerLevel, uint32_t wakeupSystemEvents, uint32_t timeoutMilliseconds) { // schedule an interrupt for this far in the future // timeout is in milliseconds, need to convert to ticks - uint64_t countsRemaining = CPU_MillisecondsToTicks( timeoutMilliseconds ); + uint64_t countsRemaining = CPU_MillisecondsToTicks(timeoutMilliseconds); #if defined(HAL_PROFILE_ENABLED) Events_WaitForEvents_Calls++; #endif - uint64_t expireTimeInTicks = HAL_Time_CurrentSysTicks() + countsRemaining; + uint64_t expireTimeInTicks = HAL_Time_CurrentSysTicks() + countsRemaining; bool runContinuations = true; - while(true) + while (true) { EVENTS_HEART_BEAT; - uint32_t events = Events_MaskedRead( wakeupSystemEvents ); - if(events) + uint32_t events = Events_MaskedRead(wakeupSystemEvents); + if (events) { return events; } - if(expireTimeInTicks <= HAL_Time_CurrentSysTicks()) + if (expireTimeInTicks <= HAL_Time_CurrentSysTicks()) { break; } // first check and possibly run any continuations // but only if we have slept after stalling - if(runContinuations && !SystemState_QueryNoLock(SYSTEM_STATE_NO_CONTINUATIONS)) + if (runContinuations && !SystemState_QueryNoLock(SYSTEM_STATE_NO_CONTINUATIONS)) { // if we stall on time, don't check again until after we sleep runContinuations = HAL_CONTINUATION::Dequeue_And_Execute(); @@ -148,14 +95,14 @@ uint32_t Events_WaitForEvents( uint32_t powerLevel, uint32_t wakeupSystemEvents, // try stalled continuations again after sleeping runContinuations = true; - HAL_COMPLETION::WaitForInterrupts(expireTimeInTicks, powerLevel, wakeupSystemEvents ); + HAL_COMPLETION::WaitForInterrupts(expireTimeInTicks, powerLevel, wakeupSystemEvents); } // no events, pass control to the OS osThreadYield(); // check if reboot or exit flags were set when the other OS threads executed - if(CLR_EE_DBG_IS(RebootPending) || CLR_EE_DBG_IS(ExitPending)) + if (CLR_EE_DBG_IS(RebootPending) || CLR_EE_DBG_IS(ExitPending)) { break; } diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/targetPAL_Time.cpp b/targets/CMSIS-OS/ChibiOS/nanoCLR/targetPAL_Time.cpp index f398463549..8ac76fee1b 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/targetPAL_Time.cpp +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/targetPAL_Time.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/targetRandom.cpp b/targets/CMSIS-OS/ChibiOS/nanoCLR/targetRandom.cpp index 1b5aa12f72..38ebd8034c 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/targetRandom.cpp +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/targetRandom.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // #include "Core.h" diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/target_platform.h.in b/targets/CMSIS-OS/ChibiOS/nanoCLR/target_platform.h.in index 2794c9b0af..3be14d416a 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/target_platform.h.in +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/target_platform.h.in @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/common/startup/ARMCMx/devices/TICC3200/cmparams.h b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/common/startup/ARMCMx/devices/TICC3200/cmparams.h index a98242b1bc..eee84d6054 100644 --- a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/common/startup/ARMCMx/devices/TICC3200/cmparams.h +++ b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/common/startup/ARMCMx/devices/TICC3200/cmparams.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/include/dummy_includes/hal_community.h b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/include/dummy_includes/hal_community.h index 27cb0645be..d9a05a254e 100644 --- a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/include/dummy_includes/hal_community.h +++ b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/include/dummy_includes/hal_community.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/include/hal_nf_community.h b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/include/hal_nf_community.h index cf26a969ab..4df57c3861 100644 --- a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/include/hal_nf_community.h +++ b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/include/hal_nf_community.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/include/stm32_crc/hal_stm32_crc.h b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/include/stm32_crc/hal_stm32_crc.h index 9ac3191082..03c0286c89 100644 --- a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/include/stm32_crc/hal_stm32_crc.h +++ b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/include/stm32_crc/hal_stm32_crc.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/include/stm32_flash/hal_stm32_flash.h b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/include/stm32_flash/hal_stm32_flash.h index 84a8d69d40..a298f7669f 100644 --- a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/include/stm32_flash/hal_stm32_flash.h +++ b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/include/stm32_flash/hal_stm32_flash.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/include/stm32_fsmc/hal_stm32_fsmc.h b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/include/stm32_fsmc/hal_stm32_fsmc.h index 257e5a9d5a..6f457556d1 100644 --- a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/include/stm32_fsmc/hal_stm32_fsmc.h +++ b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/include/stm32_fsmc/hal_stm32_fsmc.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2014 Uladzimir Pylinsky aka barthess // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/include/stm32_onewire/hal_stm32_onewire.h b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/include/stm32_onewire/hal_stm32_onewire.h index ae461da6a5..8dcb5b3439 100644 --- a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/include/stm32_onewire/hal_stm32_onewire.h +++ b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/include/stm32_onewire/hal_stm32_onewire.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/include/stm32_qspi/hal_stm32_qspi.h b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/include/stm32_qspi/hal_stm32_qspi.h index 15791ad72a..935326ed9e 100644 --- a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/include/stm32_qspi/hal_stm32_qspi.h +++ b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/include/stm32_qspi/hal_stm32_qspi.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/include/stm32_rng/hal_stm32_rng.h b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/include/stm32_rng/hal_stm32_rng.h index ba528d84ba..b291ed10a5 100644 --- a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/include/stm32_rng/hal_stm32_rng.h +++ b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/include/stm32_rng/hal_stm32_rng.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/CRCv1/crc_lld.c b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/CRCv1/crc_lld.c index 53c72a3302..e2bb2db81a 100644 --- a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/CRCv1/crc_lld.c +++ b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/CRCv1/crc_lld.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2016 STMicroelectronics. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/CRCv1/crc_lld.h b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/CRCv1/crc_lld.h index a865eb5a95..fed8e5e515 100644 --- a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/CRCv1/crc_lld.h +++ b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/CRCv1/crc_lld.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FLASHv1/flash_lld.c b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FLASHv1/flash_lld.c index 4020e2be17..d4bbf7fc52 100644 --- a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FLASHv1/flash_lld.c +++ b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FLASHv1/flash_lld.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2016 STMicroelectronics. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FLASHv1/flash_lld.h b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FLASHv1/flash_lld.h index ff0efb7a55..98222261f0 100644 --- a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FLASHv1/flash_lld.h +++ b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FLASHv1/flash_lld.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FLASHv2/flash_lld.c b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FLASHv2/flash_lld.c index 7a38ebc622..180183d356 100644 --- a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FLASHv2/flash_lld.c +++ b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FLASHv2/flash_lld.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2016 STMicroelectronics. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FLASHv2/flash_lld.h b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FLASHv2/flash_lld.h index 611052f7ce..e631268ed8 100644 --- a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FLASHv2/flash_lld.h +++ b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FLASHv2/flash_lld.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2016 STMicroelectronics. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FLASHv3/flash_lld.c b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FLASHv3/flash_lld.c index 49228e4510..4b4dee34fe 100644 --- a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FLASHv3/flash_lld.c +++ b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FLASHv3/flash_lld.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2016 STMicroelectronics. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FLASHv3/flash_lld.h b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FLASHv3/flash_lld.h index b9a77d8ae0..c98db3803c 100644 --- a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FLASHv3/flash_lld.h +++ b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FLASHv3/flash_lld.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FSMCv1/fsmc_nand_lld.c b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FSMCv1/fsmc_nand_lld.c index 7f6efd61f8..f0bc32aabc 100644 --- a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FSMCv1/fsmc_nand_lld.c +++ b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FSMCv1/fsmc_nand_lld.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2014 Uladzimir Pylinsky aka barthess // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FSMCv1/fsmc_nand_lld.h b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FSMCv1/fsmc_nand_lld.h index 38e6e51377..33ae68c6b0 100644 --- a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FSMCv1/fsmc_nand_lld.h +++ b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FSMCv1/fsmc_nand_lld.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2014 Uladzimir Pylinsky aka barthess // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FSMCv1/fsmc_sdram_lld.c b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FSMCv1/fsmc_sdram_lld.c index 8efa372e85..8c0f682a76 100644 --- a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FSMCv1/fsmc_sdram_lld.c +++ b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FSMCv1/fsmc_sdram_lld.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2014 Uladzimir Pylinsky aka barthess and Nick Klimov aka progfin // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FSMCv1/fsmc_sdram_lld.h b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FSMCv1/fsmc_sdram_lld.h index 20fe8587f1..17f40d8925 100644 --- a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FSMCv1/fsmc_sdram_lld.h +++ b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FSMCv1/fsmc_sdram_lld.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2014 Uladzimir Pylinsky aka barthess and Nick Klimov aka progfin // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FSMCv1/fsmc_sram_lld.c b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FSMCv1/fsmc_sram_lld.c index 436759c77f..a8b4c0f27a 100644 --- a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FSMCv1/fsmc_sram_lld.c +++ b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FSMCv1/fsmc_sram_lld.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2014 Uladzimir Pylinsky aka barthess // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FSMCv1/fsmc_sram_lld.h b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FSMCv1/fsmc_sram_lld.h index 1d10d377e6..03e59cb5cf 100644 --- a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FSMCv1/fsmc_sram_lld.h +++ b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FSMCv1/fsmc_sram_lld.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2014 Uladzimir Pylinsky aka barthess // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/ONEWIREv1/onewire_lld.c b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/ONEWIREv1/onewire_lld.c index bd57bf4cae..189ebf03d2 100644 --- a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/ONEWIREv1/onewire_lld.c +++ b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/ONEWIREv1/onewire_lld.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2016 STMicroelectronics. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/ONEWIREv1/onewire_lld.h b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/ONEWIREv1/onewire_lld.h index 2676cb7bf0..8748d6dc1c 100644 --- a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/ONEWIREv1/onewire_lld.h +++ b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/ONEWIREv1/onewire_lld.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2016 STMicroelectronics. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/QSPIv1/qspi_lld.c b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/QSPIv1/qspi_lld.c index 8b85550453..cf2f57e4c6 100644 --- a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/QSPIv1/qspi_lld.c +++ b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/QSPIv1/qspi_lld.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2016 STMicroelectronics. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/QSPIv1/qspi_lld.h b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/QSPIv1/qspi_lld.h index 7102e79a09..6864eed72b 100644 --- a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/QSPIv1/qspi_lld.h +++ b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/QSPIv1/qspi_lld.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2016 STMicroelectronics. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/RNGv1/rng_lld.c b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/RNGv1/rng_lld.c index 8d63b463c0..3562b8d6d9 100644 --- a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/RNGv1/rng_lld.c +++ b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/RNGv1/rng_lld.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2016 STMicroelectronics. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/RNGv1/rng_lld.h b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/RNGv1/rng_lld.h index 85660e16bb..2b889fac5e 100644 --- a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/RNGv1/rng_lld.h +++ b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/RNGv1/rng_lld.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2016 STMicroelectronics. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/src/hal_community.c b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/src/hal_community.c index 3ab1e78656..1f05c33df4 100644 --- a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/src/hal_community.c +++ b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/src/hal_community.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/src/stm32_crc/hal_stm32_crc.c b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/src/stm32_crc/hal_stm32_crc.c index 0be1fbf4ac..42184fb298 100644 --- a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/src/stm32_crc/hal_stm32_crc.c +++ b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/src/stm32_crc/hal_stm32_crc.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/src/stm32_flash/hal_stm32_flash.c b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/src/stm32_flash/hal_stm32_flash.c index 3c5e350c61..02825cbf68 100644 --- a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/src/stm32_flash/hal_stm32_flash.c +++ b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/src/stm32_flash/hal_stm32_flash.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/src/stm32_fsmc/hal_stm32_fsmc.c b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/src/stm32_fsmc/hal_stm32_fsmc.c index 5d5e3b6d4c..7e3817b8c8 100644 --- a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/src/stm32_fsmc/hal_stm32_fsmc.c +++ b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/src/stm32_fsmc/hal_stm32_fsmc.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2014 Uladzimir Pylinsky aka barthess // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/src/stm32_onewire/hal_stm32_onewire.c b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/src/stm32_onewire/hal_stm32_onewire.c index fb36da6e37..f870be22cd 100644 --- a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/src/stm32_onewire/hal_stm32_onewire.c +++ b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/src/stm32_onewire/hal_stm32_onewire.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/src/stm32_qspi/hal_stm32_qspi.c b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/src/stm32_qspi/hal_stm32_qspi.c index 121a8c8d7f..2ba6f64618 100644 --- a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/src/stm32_qspi/hal_stm32_qspi.c +++ b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/src/stm32_qspi/hal_stm32_qspi.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/src/stm32_rng/hal_stm32_rng.c b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/src/stm32_rng/hal_stm32_rng.c index 7d526d25f1..55ab92978d 100644 --- a/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/src/stm32_rng/hal_stm32_rng.c +++ b/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/src/stm32_rng/hal_stm32_rng.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/spiffs/CMakeLists.txt b/targets/CMSIS-OS/ChibiOS/spiffs/CMakeLists.txt index f868eac1de..bcb1c7b090 100644 --- a/targets/CMSIS-OS/ChibiOS/spiffs/CMakeLists.txt +++ b/targets/CMSIS-OS/ChibiOS/spiffs/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/targets/CMSIS-OS/ChibiOS/spiffs/hal_spiffs.c b/targets/CMSIS-OS/ChibiOS/spiffs/hal_spiffs.c index e6108a7e24..9252f5facc 100644 --- a/targets/CMSIS-OS/ChibiOS/spiffs/hal_spiffs.c +++ b/targets/CMSIS-OS/ChibiOS/spiffs/hal_spiffs.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/spiffs/hal_spiffs.h b/targets/CMSIS-OS/ChibiOS/spiffs/hal_spiffs.h index 1b8d23cb6d..936dc16543 100644 --- a/targets/CMSIS-OS/ChibiOS/spiffs/hal_spiffs.h +++ b/targets/CMSIS-OS/ChibiOS/spiffs/hal_spiffs.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/LwIP/nf_api_msg.c b/targets/CMSIS-OS/LwIP/nf_api_msg.c index b9ac0cfd63..1c1f2bfd00 100644 --- a/targets/CMSIS-OS/LwIP/nf_api_msg.c +++ b/targets/CMSIS-OS/LwIP/nf_api_msg.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2001-2004 Swedish Institute of Computer Science. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/LwIP/nf_sockets.c b/targets/CMSIS-OS/LwIP/nf_sockets.c index 4dc0c28a04..2a7b654b70 100644 --- a/targets/CMSIS-OS/LwIP/nf_sockets.c +++ b/targets/CMSIS-OS/LwIP/nf_sockets.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2001-2004 Swedish Institute of Computer Science. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/LwIP/nf_sys_arch.c b/targets/CMSIS-OS/LwIP/nf_sys_arch.c index 86169cb8eb..67a0735818 100644 --- a/targets/CMSIS-OS/LwIP/nf_sys_arch.c +++ b/targets/CMSIS-OS/LwIP/nf_sys_arch.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2001-2004 Swedish Institute of Computer Science. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/common/CMakeLists.txt b/targets/CMSIS-OS/common/CMakeLists.txt index b0df1bf25f..ef8babf714 100644 --- a/targets/CMSIS-OS/common/CMakeLists.txt +++ b/targets/CMSIS-OS/common/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/targets/CMSIS-OS/common/Include/CMakeLists.txt b/targets/CMSIS-OS/common/Include/CMakeLists.txt index c6747eaa58..6bbc2e8311 100644 --- a/targets/CMSIS-OS/common/Include/CMakeLists.txt +++ b/targets/CMSIS-OS/common/Include/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/targets/CMSIS-OS/common/Include/swo.h.in b/targets/CMSIS-OS/common/Include/swo.h.in index 5629a8d3d3..4dc1a1673a 100644 --- a/targets/CMSIS-OS/common/Include/swo.h.in +++ b/targets/CMSIS-OS/common/Include/swo.h.in @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/common/swo.cpp b/targets/CMSIS-OS/common/swo.cpp index 809306d94e..32e96a0630 100644 --- a/targets/CMSIS-OS/common/swo.cpp +++ b/targets/CMSIS-OS/common/swo.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/common/syscalls.c b/targets/CMSIS-OS/common/syscalls.c index d53b751731..6f47e6fdbc 100644 --- a/targets/CMSIS-OS/common/syscalls.c +++ b/targets/CMSIS-OS/common/syscalls.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/nanoBooter/CMakeLists.txt b/targets/CMSIS-OS/nanoBooter/CMakeLists.txt index 0753c7f36d..ffad1b1e18 100644 --- a/targets/CMSIS-OS/nanoBooter/CMakeLists.txt +++ b/targets/CMSIS-OS/nanoBooter/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/targets/CMSIS-OS/nanoCLR/CMakeLists.txt b/targets/CMSIS-OS/nanoCLR/CMakeLists.txt index 4bbd64326d..c2c059a6a4 100644 --- a/targets/CMSIS-OS/nanoCLR/CMakeLists.txt +++ b/targets/CMSIS-OS/nanoCLR/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/targets/FreeRTOS/CMakeLists.txt b/targets/FreeRTOS/CMakeLists.txt index aad51b2390..bd9204ae27 100644 --- a/targets/FreeRTOS/CMakeLists.txt +++ b/targets/FreeRTOS/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # @@ -7,11 +7,11 @@ include(binutils.arm-none-eabi) include(binutils.FreeRTOS) include(nf_utils) -# check if FREERTOS_SOURCE was specified or if it's empty (default is empty) -set(NO_FREERTOS_SOURCE TRUE) -if(FREERTOS_SOURCE) - if(NOT "${FREERTOS_SOURCE}" STREQUAL "") - set(NO_FREERTOS_SOURCE FALSE) +# check if RTOS_SOURCE_FOLDER was specified or if it's empty (default is empty) +set(NO_RTOS_SOURCE_FOLDER TRUE) +if(RTOS_SOURCE_FOLDER) + if(NOT "${RTOS_SOURCE_FOLDER}" STREQUAL "") + set(NO_RTOS_SOURCE_FOLDER FALSE) endif() endif() @@ -28,7 +28,7 @@ if(NOT "${TOOL_SRECORD_PREFIX}" STREQUAL "") endif() endif() -if(NO_FREERTOS_SOURCE) +if(NO_RTOS_SOURCE_FOLDER) # no FreeRTOS source specified, download it from it's repo # check for Git (needed here for advanced warning to user if it's not installed) @@ -52,7 +52,7 @@ if(NO_FREERTOS_SOURCE) # check if build was requested with a specifc FreeRTOS version if(FREERTOS_VERSION_EMPTY) # no FreeRTOS version actualy specified, must be empty which is fine, we'll default to a known good version - set(FREERTOS_VERSION_TAG "V10.3.1-kernel-only") + set(FREERTOS_VERSION_TAG "V10.4.1-kernel-only") else() # set SVN tag set(FREERTOS_VERSION_TAG "${FREERTOS_VERSION}") @@ -81,7 +81,7 @@ if(NO_FREERTOS_SOURCE) PREFIX FreeRTOS SOURCE_DIR ${CMAKE_BINARY_DIR}/FreeRTOS_Source GIT_REPOSITORY https://github.com/FreeRTOS/FreeRTOS-Kernel.git - GIT_TAG ${FREERTOS_VERSION_TAG} # target specified branch + GIT_TAG ${RTOS_VERSION} # target specified branch GIT_SHALLOW 1 # download only the tip of the branch, not the complete history TIMEOUT 10 LOG_DOWNLOAD 1 @@ -95,21 +95,21 @@ else() # FreeRTOS source was specified # sanity check is source path exists - if(EXISTS "${FREERTOS_SOURCE}/") - message(STATUS "RTOS is: FreeRTOS (source from: ${FREERTOS_SOURCE})") + if(EXISTS "${RTOS_SOURCE_FOLDER}/") + message(STATUS "RTOS is: FreeRTOS (source from: ${RTOS_SOURCE_FOLDER})") # check if we already have the sources, no need to copy again NF_DIRECTORY_EXISTS_NOT_EMPTY(${CMAKE_BINARY_DIR}/FreeRTOS_Source/ SOURCE_EXISTS) if(NOT ${SOURCE_EXISTS}) - file(COPY "${FREERTOS_SOURCE}/" DESTINATION "${CMAKE_BINARY_DIR}/FreeRTOS_Source/lib/FreeRTOS") + file(COPY "${RTOS_SOURCE_FOLDER}/" DESTINATION "${CMAKE_BINARY_DIR}/FreeRTOS_Source/lib/FreeRTOS") else() - message(STATUS "Using local cache of FreeRTOS source from ${FREERTOS_SOURCE}") + message(STATUS "Using local cache of FreeRTOS source from ${RTOS_SOURCE_FOLDER}") endif() set(FREERTOS_INCLUDE_DIR ${CMAKE_BINARY_DIR}/FreeRTOS_Source/lib/include) else() - message(FATAL_ERROR "Couldn't find FreeRTOS source at ${FREERTOS_SOURCE}/") + message(FATAL_ERROR "Couldn't find FreeRTOS source at ${RTOS_SOURCE_FOLDER}/") endif() # add FreeRTOS as external project diff --git a/targets/FreeRTOS/NXP/CMakeLists.txt b/targets/FreeRTOS/NXP/CMakeLists.txt index 734b6ea915..8e7dc15269 100644 --- a/targets/FreeRTOS/NXP/CMakeLists.txt +++ b/targets/FreeRTOS/NXP/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/targets/FreeRTOS/NXP/LwIP/arch/cc.h b/targets/FreeRTOS/NXP/LwIP/arch/cc.h index 0b7915bd08..a852d1c933 100644 --- a/targets/FreeRTOS/NXP/LwIP/arch/cc.h +++ b/targets/FreeRTOS/NXP/LwIP/arch/cc.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2001-2004 Swedish Institute of Computer Science. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/LwIP/arch/perf.h b/targets/FreeRTOS/NXP/LwIP/arch/perf.h index ea05f8bc3a..b21c0d8106 100644 --- a/targets/FreeRTOS/NXP/LwIP/arch/perf.h +++ b/targets/FreeRTOS/NXP/LwIP/arch/perf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2001-2003 Swedish Institute of Computer Science. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/LwIP/arch/sys_arch.h b/targets/FreeRTOS/NXP/LwIP/arch/sys_arch.h index 45c30b2b5a..b85b7f4dd8 100644 --- a/targets/FreeRTOS/NXP/LwIP/arch/sys_arch.h +++ b/targets/FreeRTOS/NXP/LwIP/arch/sys_arch.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2001-2003 Swedish Institute of Computer Science. All rights reserved. // Portions Copyright (c) 2013-2016, Freescale Semiconductor, Inc. All rights reserved. // Portions Copyright 2016-2017 NXP All rights reserved. diff --git a/targets/FreeRTOS/NXP/LwIP/ethernetif.c b/targets/FreeRTOS/NXP/LwIP/ethernetif.c index 2bd0135c25..28dc0d1b93 100644 --- a/targets/FreeRTOS/NXP/LwIP/ethernetif.c +++ b/targets/FreeRTOS/NXP/LwIP/ethernetif.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2001-2004 Swedish Institute of Computer Science. All rights reserved. // Portions Copyright (c) 2013-2016, Freescale Semiconductor, Inc. All rights reserved. // Portions Copyright 2016-2019 NXP All rights reserved. diff --git a/targets/FreeRTOS/NXP/LwIP/ethernetif.h b/targets/FreeRTOS/NXP/LwIP/ethernetif.h index bfb5e8e50b..9af72b51f5 100644 --- a/targets/FreeRTOS/NXP/LwIP/ethernetif.h +++ b/targets/FreeRTOS/NXP/LwIP/ethernetif.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2001-2003 Swedish Institute of Computer Science. All rights reserved. // Portions Copyright (c) 2013-2016, Freescale Semiconductor, Inc. All rights reserved. // Portions Copyright 2016-2017 NXP All rights reserved. diff --git a/targets/FreeRTOS/NXP/LwIP/nf_api_msg.c b/targets/FreeRTOS/NXP/LwIP/nf_api_msg.c index aaa2bae297..1c1f2bfd00 100644 --- a/targets/FreeRTOS/NXP/LwIP/nf_api_msg.c +++ b/targets/FreeRTOS/NXP/LwIP/nf_api_msg.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2001-2004 Swedish Institute of Computer Science. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/LwIP/nf_lwipthread.c b/targets/FreeRTOS/NXP/LwIP/nf_lwipthread.c index a2f0edfff1..f62c575945 100644 --- a/targets/FreeRTOS/NXP/LwIP/nf_lwipthread.c +++ b/targets/FreeRTOS/NXP/LwIP/nf_lwipthread.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/LwIP/nf_lwipthread.h b/targets/FreeRTOS/NXP/LwIP/nf_lwipthread.h index 913b33471e..f0e526ee0e 100644 --- a/targets/FreeRTOS/NXP/LwIP/nf_lwipthread.h +++ b/targets/FreeRTOS/NXP/LwIP/nf_lwipthread.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/LwIP/nf_sockets.c b/targets/FreeRTOS/NXP/LwIP/nf_sockets.c index 30a91d452e..e1935e9b3e 100644 --- a/targets/FreeRTOS/NXP/LwIP/nf_sockets.c +++ b/targets/FreeRTOS/NXP/LwIP/nf_sockets.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2001-2004 Swedish Institute of Computer Science. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/LwIP/nf_sys_arch.c b/targets/FreeRTOS/NXP/LwIP/nf_sys_arch.c index 8df65c7581..bacc21b943 100644 --- a/targets/FreeRTOS/NXP/LwIP/nf_sys_arch.c +++ b/targets/FreeRTOS/NXP/LwIP/nf_sys_arch.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2001-2003 Swedish Institute of Computer Science. All rights reserved. // Portions Copyright (c) 2013-2016, Freescale Semiconductor, Inc. All rights reserved. // Copyright 2016-2019 NXP All rights reserved. diff --git a/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/CMakeLists.txt b/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/CMakeLists.txt index f56e41f073..a6e40f249a 100644 --- a/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/CMakeLists.txt +++ b/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/FreeRTOSConfig.h b/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/FreeRTOSConfig.h index 3dcf625c0f..90861ca106 100644 --- a/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/FreeRTOSConfig.h +++ b/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/FreeRTOSConfig.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/cmake-variants.TEMPLATE-MIMXRT1060.json b/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/cmake-variants.json similarity index 71% rename from cmake-variants.TEMPLATE-MIMXRT1060.json rename to targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/cmake-variants.json index af0aefdd99..394a5bfb09 100644 --- a/cmake-variants.TEMPLATE-MIMXRT1060.json +++ b/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/cmake-variants.json @@ -1,67 +1,60 @@ -{ - "buildType": { - "default": "MinSizeRel", - "choices": { - "debug": { - "short": "Debug", - "long": "Emit debug information without performing optimizations", - "buildType": "Debug" - }, - "release": { - "short": "Release", - "long": "Enable optimizations, omit debug info", - "buildType": "Release" - }, - "minsize": { - "short": "MinSizeRel", - "long": "Optimize for smallest binary size", - "buildType": "MinSizeRel" - }, - "reldeb": { - "short": "RelWithDebInfo", - "long": "Perform optimizations AND include debugging information", - "buildType": "RelWithDebInfo" - } - } - }, - "linkage": { - "default": "", - "choices": { - "MIMXRT1060_EVK": { - "short": "MIMXRT1060_EVK", - "settings": { - "BUILD_VERSION": "0.9.99.999", - "CMAKE_TOOLCHAIN_FILE" : "CMake/toolchain.arm-none-eabi.cmake", - "TOOLCHAIN_PREFIX": "C:/nanoFramework_Tools/GNU_ARM_Toolchain/8 2019-q3-update", - "TOOL_SRECORD_PREFIX" : "c:/nanoFramework_Tools/srecord/", - "TARGET_SERIES": "IMXRT10xx", - "SUPPORT_ANY_BASE_CONVERSION": "ON", - "RTOS": "FREERTOS", - "FREERTOS_BOARD": "NXP_MIMXRT1060_EVK", - "FREERTOS_VERSION": "v1.4.8", - "CMSIS_VERSION": "5.5.1", - "FATFS_VERSION": "R0.13c", - "LWIP_VERSION": "STABLE-2_0_3_RELEASE", - "NF_BUILD_RTM": "OFF", - "NF_FEATURE_DEBUGGER": "ON", - "NF_FEATURE_HAS_SDCARD": "ON", - "NF_FEATURE_RTC": "ON", - "NF_FEATURE_HAS_CONFIG_BLOCK": "ON", - "NF_SECURITY_OPENSSL": "OFF", - "API_Windows.Devices.Gpio": "ON", - "API_Windows.Devices.Spi": "OFF", - "API_Windows.Devices.I2c": "OFF", - "API_Windows.Devices.Adc": "OFF", - "API_Windows.Devices.Pwm": "OFF", - "API_Windows.Devices.Wifi": "OFF", - "API_Windows.Devices.SerialCommunication": "ON", - "API_nanoFramework.ResourceManager": "ON", - "API_nanoFramework.System.Collections": "ON", - "API_System.Net": "ON", - "API_System.Math": "ON", - "API_Windows.Storage": "ON" - } - } - } - } +{ + "buildType": { + "default": "debug", + "choices": { + "debug": { + "short": "Debug", + "long": "Emit debug information without performing optimizations", + "buildType": "Debug" + }, + "minsize": { + "short": "MinSizeRel", + "long": "Optimize for smallest binary size", + "buildType": "MinSizeRel" + }, + "reldeb": { + "short": "RelWithDebInfo", + "long": "Perform optimizations AND include debugging information", + "buildType": "RelWithDebInfo" + } + } + }, + "linkage": { + "default": "", + "choices": { + "NXP_MIMXRT1060_EVK": { + "short": "NXP_MIMXRT1060_EVK", + "settings": { + "BUILD_VERSION": "0.9.99.999", + "CMAKE_TOOLCHAIN_FILE": "CMake/toolchain.arm-none-eabi.cmake", + "TOOLCHAIN_PREFIX": "", + "TOOL_SRECORD_PREFIX": "", + "TARGET_SERIES": "IMXRT10xx", + "SUPPORT_ANY_BASE_CONVERSION": "ON", + "RTOS": "FREERTOS", + "FREERTOS_BOARD": "NXP_MIMXRT1060_EVK", + "FREERTOS_VERSION": "v1.4.8", + "CMSIS_VERSION": "5.5.1", + "FATFS_VERSION": "R0.13c", + "LWIP_VERSION": "STABLE-2_0_3_RELEASE", + "NF_BUILD_RTM": "OFF", + "NF_FEATURE_DEBUGGER": "ON", + "NF_FEATURE_HAS_SDCARD": "ON", + "NF_FEATURE_RTC": "ON", + "NF_FEATURE_HAS_CONFIG_BLOCK": "ON", + "API_Windows.Devices.Gpio": "ON", + "API_Windows.Devices.Spi": "OFF", + "API_Windows.Devices.I2c": "OFF", + "API_Windows.Devices.Adc": "OFF", + "API_Windows.Devices.Pwm": "OFF", + "API_Windows.Devices.Wifi": "OFF", + "API_Windows.Devices.SerialCommunication": "ON", + "API_nanoFramework.ResourceManager": "ON", + "API_nanoFramework.System.Collections": "ON", + "API_System.Net": "ON", + "API_System.Math": "ON" + } + } + } + } } \ No newline at end of file diff --git a/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/launch.json b/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/launch.json new file mode 100644 index 0000000000..f18b75231b --- /dev/null +++ b/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/launch.json @@ -0,0 +1,87 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "NXP_MIMXRT1060_EVK", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/Build/nanoCLR.elf", + "stopAtEntry": false, + "cwd": "${workspaceFolder}", + "environment": [], + "externalConsole": true, + "MIMode": "gdb", + "miDebuggerPath": "/bin/arm-none-eabi-gdb.exe", + "setupCommands": [ + { + "text": "set breakpoint pending on" + }, + { + "text": "-enable-pretty-printing" + }, + { + "text": "set python print-stack none" + }, + { + "text": "set print object on" + }, + { + "text": "set print sevenbit-strings on" + }, + { + "text": "set charset ISO-8859-1" + }, + { + "text": "set auto-solib-add on" + }, + { + "text": "file /Build/nanoCLR.elf" + }, + { + "text": "set non-stop on" + }, + { + "text": "set pagination off" + }, + { + "text": "set mi-async" + }, + { + "text": "set remotetimeout 60" + }, + { + "text": "target extended-remote | C:/nxp/MCUXpressoIDE_10.2.1_795/ide/bin/crt_emu_cm_redlink.exe -g -mi -2 -pMIMXRT1062xxxxA -vendor=NXP --reset= -cache=disable --flash-dir=C:/nxp/MCUXpressoIDE_10.2.1_795/ide/bin/Flash --flash-driver=MIMXRT1060_SFDP_QSPI.cfx --no-packed" + }, + { + "text": "set mem inaccessible-by-default off" + }, + { + "text": "mon ondisconnect cont" + }, + { + "text": "set arm force-mode thumb" + }, + { + "text": "set remote hardware-breakpoint-limit 6" + }, + { + "text": "mon semihost enable" + }, + { + "text": "load" + }, + { + "text": "thbreak main" + } + ], + "launchCompleteCommand": "None", + "logging": { + "moduleLoad": false, + "trace": false, + "engineLogging": false, + "programOutput": true, + "exceptions": true + } + } + ] +} \ No newline at end of file diff --git a/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/lwipopts.h b/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/lwipopts.h index dabc44b3ca..6fefab2466 100644 --- a/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/lwipopts.h +++ b/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/lwipopts.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/nanoBooter/CMakeLists.txt b/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/nanoBooter/CMakeLists.txt index adc7c82b73..ceddaca49f 100644 --- a/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/nanoBooter/CMakeLists.txt +++ b/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/nanoBooter/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/nanoBooter/MIMXRT10xx.ld b/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/nanoBooter/MIMXRT10xx.ld index 576ecdbb63..2e1e5661aa 100644 --- a/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/nanoBooter/MIMXRT10xx.ld +++ b/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/nanoBooter/MIMXRT10xx.ld @@ -1,6 +1,6 @@ /* // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2008 - 2013 Code Red Technologies Ltd. All rights reserved. // Portions Copyright (c) 2013-2019 NXP Semiconductors. All rights reserved. // See LICENSE file in the project root for full license information. diff --git a/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/nanoBooter/WireProtocol_App_Interface.c b/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/nanoBooter/WireProtocol_App_Interface.c index d2be2eebe5..055e05b48f 100644 --- a/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/nanoBooter/WireProtocol_App_Interface.c +++ b/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/nanoBooter/WireProtocol_App_Interface.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/nanoBooter/WireProtocol_MonitorCommands.c b/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/nanoBooter/WireProtocol_MonitorCommands.c index 0445d525e5..6322ae71cd 100644 --- a/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/nanoBooter/WireProtocol_MonitorCommands.c +++ b/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/nanoBooter/WireProtocol_MonitorCommands.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/nanoBooter/main.c b/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/nanoBooter/main.c index c3ae953227..645d2e0a9d 100644 --- a/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/nanoBooter/main.c +++ b/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/nanoBooter/main.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/nanoBooter/target_board.h.in b/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/nanoBooter/target_board.h.in index 499cc3528e..3a35d1874b 100644 --- a/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/nanoBooter/target_board.h.in +++ b/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/nanoBooter/target_board.h.in @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/nanoCLR/CMakeLists.txt b/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/nanoCLR/CMakeLists.txt index 12202805e3..efc3fad32c 100644 --- a/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/nanoCLR/CMakeLists.txt +++ b/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/nanoCLR/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/nanoCLR/MIMXRT10xx.ld b/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/nanoCLR/MIMXRT10xx.ld index 79b3a05248..2f963b773e 100644 --- a/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/nanoCLR/MIMXRT10xx.ld +++ b/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/nanoCLR/MIMXRT10xx.ld @@ -1,6 +1,6 @@ /* // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2008 - 2013 Code Red Technologies Ltd. All rights reserved. // Portions Copyright (c) 2013-2019 NXP Semiconductors. All rights reserved. // See LICENSE file in the project root for full license information. diff --git a/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/nanoCLR/main.c b/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/nanoCLR/main.c index 24c5627e74..3a1be00dc0 100644 --- a/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/nanoCLR/main.c +++ b/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/nanoCLR/main.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/nanoCLR/target_board.h.in b/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/nanoCLR/target_board.h.in index 08bbfa7b5b..d0b8c150da 100644 --- a/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/nanoCLR/target_board.h.in +++ b/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/nanoCLR/target_board.h.in @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/target_BlockStorage.c b/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/target_BlockStorage.c index c4fa4dcb06..5e7af3a58e 100644 --- a/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/target_BlockStorage.c +++ b/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/target_BlockStorage.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/target_BlockStorage.h b/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/target_BlockStorage.h index aa50b1b7f2..8a56d0eee0 100644 --- a/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/target_BlockStorage.h +++ b/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/target_BlockStorage.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/target_common.c b/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/target_common.c index 187882ef84..5746746016 100644 --- a/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/target_common.c +++ b/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/target_common.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/target_common.h.in b/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/target_common.h.in index 40ee9d08b1..964d9c9af7 100644 --- a/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/target_common.h.in +++ b/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/target_common.h.in @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/target_lwip_sntp_opts.h b/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/target_lwip_sntp_opts.h index 8cabc85f88..a0f52fe8e3 100644 --- a/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/target_lwip_sntp_opts.h +++ b/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/target_lwip_sntp_opts.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/target_system_devices_dac_config.cpp b/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/target_system_devices_dac_config.cpp index dcab049076..5b6a31838f 100644 --- a/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/target_system_devices_dac_config.cpp +++ b/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/target_system_devices_dac_config.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/target_windows_devices_i2c_config.cpp b/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/target_windows_devices_i2c_config.cpp index de20b594f4..f0c7909f0a 100644 --- a/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/target_windows_devices_i2c_config.cpp +++ b/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/target_windows_devices_i2c_config.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/target_windows_devices_serialcommunication_config.cpp b/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/target_windows_devices_serialcommunication_config.cpp index 4845bf12ac..949567e829 100644 --- a/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/target_windows_devices_serialcommunication_config.cpp +++ b/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/target_windows_devices_serialcommunication_config.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/target_windows_devices_serialcommunication_config.h b/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/target_windows_devices_serialcommunication_config.h index 088b626084..a5efb34c5f 100644 --- a/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/target_windows_devices_serialcommunication_config.h +++ b/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/target_windows_devices_serialcommunication_config.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/target_windows_storage_config.h b/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/target_windows_storage_config.h index d7b7376bc0..949567e829 100644 --- a/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/target_windows_storage_config.h +++ b/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/target_windows_storage_config.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/common/CMakeLists.txt b/targets/FreeRTOS/NXP/common/CMakeLists.txt index 44803280c8..315de5a32f 100644 --- a/targets/FreeRTOS/NXP/common/CMakeLists.txt +++ b/targets/FreeRTOS/NXP/common/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/targets/FreeRTOS/NXP/common/Device_BlockStorage.c b/targets/FreeRTOS/NXP/common/Device_BlockStorage.c index 07559f6cb6..a130ca2a08 100644 --- a/targets/FreeRTOS/NXP/common/Device_BlockStorage.c +++ b/targets/FreeRTOS/NXP/common/Device_BlockStorage.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/common/Target_BlockStorage_iMXRTFlashDriver.c b/targets/FreeRTOS/NXP/common/Target_BlockStorage_iMXRTFlashDriver.c index f894e98f8a..b5d5322a9c 100644 --- a/targets/FreeRTOS/NXP/common/Target_BlockStorage_iMXRTFlashDriver.c +++ b/targets/FreeRTOS/NXP/common/Target_BlockStorage_iMXRTFlashDriver.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/common/Target_Windows_Storage.c b/targets/FreeRTOS/NXP/common/Target_Windows_Storage.c index b6f7f52b5e..8f0f46c390 100644 --- a/targets/FreeRTOS/NXP/common/Target_Windows_Storage.c +++ b/targets/FreeRTOS/NXP/common/Target_Windows_Storage.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/common/WireProtocol_HAL_Interface.c b/targets/FreeRTOS/NXP/common/WireProtocol_HAL_Interface.c index d322066d8c..7384e7d7fc 100644 --- a/targets/FreeRTOS/NXP/common/WireProtocol_HAL_Interface.c +++ b/targets/FreeRTOS/NXP/common/WireProtocol_HAL_Interface.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/common/board/board.c b/targets/FreeRTOS/NXP/common/board/board.c index afa6aee60e..c403629a15 100644 --- a/targets/FreeRTOS/NXP/common/board/board.c +++ b/targets/FreeRTOS/NXP/common/board/board.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright 2018 NXP. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/common/board/board.h b/targets/FreeRTOS/NXP/common/board/board.h index b05b7fcf72..bbb68c66ca 100644 --- a/targets/FreeRTOS/NXP/common/board/board.h +++ b/targets/FreeRTOS/NXP/common/board/board.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright 2018 NXP. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/common/board/clock_config.c b/targets/FreeRTOS/NXP/common/board/clock_config.c index d0b0e003d3..0a1722d6a4 100644 --- a/targets/FreeRTOS/NXP/common/board/clock_config.c +++ b/targets/FreeRTOS/NXP/common/board/clock_config.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright 2018 NXP. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/common/board/clock_config.h b/targets/FreeRTOS/NXP/common/board/clock_config.h index 07e6591eeb..6899008d9d 100644 --- a/targets/FreeRTOS/NXP/common/board/clock_config.h +++ b/targets/FreeRTOS/NXP/common/board/clock_config.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright 2018 NXP. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/common/board/fsl_phy.c b/targets/FreeRTOS/NXP/common/board/fsl_phy.c index 1d08107744..ffe6b102a1 100644 --- a/targets/FreeRTOS/NXP/common/board/fsl_phy.c +++ b/targets/FreeRTOS/NXP/common/board/fsl_phy.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2015, Freescale Semiconductor, Inc. All rights reserved. // Portions Copyright 2016-2017 NXP All rights reserved. // See LICENSE file in the project root for full license information. diff --git a/targets/FreeRTOS/NXP/common/board/fsl_phy.h b/targets/FreeRTOS/NXP/common/board/fsl_phy.h index 626879dd88..0e68d4445f 100644 --- a/targets/FreeRTOS/NXP/common/board/fsl_phy.h +++ b/targets/FreeRTOS/NXP/common/board/fsl_phy.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2015, Freescale Semiconductor, Inc. All rights reserved. // Portions Copyright 2016-2017 NXP All rights reserved. // See LICENSE file in the project root for full license information. diff --git a/targets/FreeRTOS/NXP/common/board/peripherals.c b/targets/FreeRTOS/NXP/common/board/peripherals.c index 3d7377deaf..5bab7e0c58 100644 --- a/targets/FreeRTOS/NXP/common/board/peripherals.c +++ b/targets/FreeRTOS/NXP/common/board/peripherals.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright 2018 NXP. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/common/board/peripherals.h b/targets/FreeRTOS/NXP/common/board/peripherals.h index e36e9c6ce6..664b667841 100644 --- a/targets/FreeRTOS/NXP/common/board/peripherals.h +++ b/targets/FreeRTOS/NXP/common/board/peripherals.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright 2018 NXP. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/common/board/pin_mux.c b/targets/FreeRTOS/NXP/common/board/pin_mux.c index 13564d8e48..257c06f0d8 100644 --- a/targets/FreeRTOS/NXP/common/board/pin_mux.c +++ b/targets/FreeRTOS/NXP/common/board/pin_mux.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright 2018 NXP. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/common/board/pin_mux.h b/targets/FreeRTOS/NXP/common/board/pin_mux.h index 36339f1f8e..661db4cde3 100644 --- a/targets/FreeRTOS/NXP/common/board/pin_mux.h +++ b/targets/FreeRTOS/NXP/common/board/pin_mux.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright 2018 NXP. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/common/component/serial_manager/serial_manager.c b/targets/FreeRTOS/NXP/common/component/serial_manager/serial_manager.c index c191eb479c..d85ea93c60 100644 --- a/targets/FreeRTOS/NXP/common/component/serial_manager/serial_manager.c +++ b/targets/FreeRTOS/NXP/common/component/serial_manager/serial_manager.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright 2018 NXP. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/common/component/serial_manager/serial_manager.h b/targets/FreeRTOS/NXP/common/component/serial_manager/serial_manager.h index 4adf0df257..677a0c2e8c 100644 --- a/targets/FreeRTOS/NXP/common/component/serial_manager/serial_manager.h +++ b/targets/FreeRTOS/NXP/common/component/serial_manager/serial_manager.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright 2018 NXP. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/common/component/serial_manager/serial_port_uart.c b/targets/FreeRTOS/NXP/common/component/serial_manager/serial_port_uart.c index 937a528d82..69772e17bc 100644 --- a/targets/FreeRTOS/NXP/common/component/serial_manager/serial_port_uart.c +++ b/targets/FreeRTOS/NXP/common/component/serial_manager/serial_port_uart.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright 2018 NXP. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/common/component/serial_manager/serial_port_uart.h b/targets/FreeRTOS/NXP/common/component/serial_manager/serial_port_uart.h index 81efa8497e..84e5514c9b 100644 --- a/targets/FreeRTOS/NXP/common/component/serial_manager/serial_port_uart.h +++ b/targets/FreeRTOS/NXP/common/component/serial_manager/serial_port_uart.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright 2018 NXP. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/common/component/uart/lpuart_adapter.c b/targets/FreeRTOS/NXP/common/component/uart/lpuart_adapter.c index 87ecafc741..218878cb50 100644 --- a/targets/FreeRTOS/NXP/common/component/uart/lpuart_adapter.c +++ b/targets/FreeRTOS/NXP/common/component/uart/lpuart_adapter.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright 2018 NXP. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/common/component/uart/uart.h b/targets/FreeRTOS/NXP/common/component/uart/uart.h index 6406f72c16..7808c62d08 100644 --- a/targets/FreeRTOS/NXP/common/component/uart/uart.h +++ b/targets/FreeRTOS/NXP/common/component/uart/uart.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright 2018 NXP. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/common/device/MIMXRT1062.h b/targets/FreeRTOS/NXP/common/device/MIMXRT1062.h index dfdbaea2ad..356e542890 100644 --- a/targets/FreeRTOS/NXP/common/device/MIMXRT1062.h +++ b/targets/FreeRTOS/NXP/common/device/MIMXRT1062.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright 1997-2016 Freescale Semiconductor, Inc.. All rights reserved. // Portions Copyright 2016-2018 NXP. All rights reserved. // See LICENSE file in the project root for full license information. diff --git a/targets/FreeRTOS/NXP/common/device/MIMXRT1062_features.h b/targets/FreeRTOS/NXP/common/device/MIMXRT1062_features.h index b78849b5c1..36b7fd503f 100644 --- a/targets/FreeRTOS/NXP/common/device/MIMXRT1062_features.h +++ b/targets/FreeRTOS/NXP/common/device/MIMXRT1062_features.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright 2016 Freescale Semiconductor, Inc.. All rights reserved. // Portions Copyright 2016-2018 NXP. All rights reserved. // See LICENSE file in the project root for full license information. diff --git a/targets/FreeRTOS/NXP/common/device/fsl_device_registers.h b/targets/FreeRTOS/NXP/common/device/fsl_device_registers.h index 2a7441f639..538b13147a 100644 --- a/targets/FreeRTOS/NXP/common/device/fsl_device_registers.h +++ b/targets/FreeRTOS/NXP/common/device/fsl_device_registers.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright 2018 NXP. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/common/device/system_MIMXRT1062.c b/targets/FreeRTOS/NXP/common/device/system_MIMXRT1062.c index 2b34dca890..971414cf68 100644 --- a/targets/FreeRTOS/NXP/common/device/system_MIMXRT1062.c +++ b/targets/FreeRTOS/NXP/common/device/system_MIMXRT1062.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright 2016 Freescale Semiconductor, Inc.. All rights reserved. // Portions Copyright 2016-2018 NXP. All rights reserved. // See LICENSE file in the project root for full license information. diff --git a/targets/FreeRTOS/NXP/common/device/system_MIMXRT1062.h b/targets/FreeRTOS/NXP/common/device/system_MIMXRT1062.h index c51bde357e..cd576f8435 100644 --- a/targets/FreeRTOS/NXP/common/device/system_MIMXRT1062.h +++ b/targets/FreeRTOS/NXP/common/device/system_MIMXRT1062.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright 2016 Freescale Semiconductor, Inc.. All rights reserved. // Portions Copyright 2016-2018 NXP. All rights reserved. // See LICENSE file in the project root for full license information. diff --git a/targets/FreeRTOS/NXP/common/drivers/freertos/fsl_lpuart_freertos.c b/targets/FreeRTOS/NXP/common/drivers/freertos/fsl_lpuart_freertos.c index 2a222b8f98..849ab0eed3 100644 --- a/targets/FreeRTOS/NXP/common/drivers/freertos/fsl_lpuart_freertos.c +++ b/targets/FreeRTOS/NXP/common/drivers/freertos/fsl_lpuart_freertos.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2015, Freescale Semiconductor, Inc. All rights reserved. // Portions Copyright 2016-2017 NXP. All rights reserved. // See LICENSE file in the project root for full license information. diff --git a/targets/FreeRTOS/NXP/common/drivers/fsl_cache.c b/targets/FreeRTOS/NXP/common/drivers/fsl_cache.c index 503d187a6b..2913c96cd4 100644 --- a/targets/FreeRTOS/NXP/common/drivers/fsl_cache.c +++ b/targets/FreeRTOS/NXP/common/drivers/fsl_cache.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. // Portions Copyright 2016-2017 NXP All rights reserved. // See LICENSE file in the project root for full license information. diff --git a/targets/FreeRTOS/NXP/common/drivers/fsl_cache.h b/targets/FreeRTOS/NXP/common/drivers/fsl_cache.h index 491cc6b5c2..13f39754f1 100644 --- a/targets/FreeRTOS/NXP/common/drivers/fsl_cache.h +++ b/targets/FreeRTOS/NXP/common/drivers/fsl_cache.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. // Portions Copyright 2016-2017 NXP All rights reserved. // See LICENSE file in the project root for full license information. diff --git a/targets/FreeRTOS/NXP/common/drivers/fsl_clock.c b/targets/FreeRTOS/NXP/common/drivers/fsl_clock.c index 7d43e7b89f..6bd8868ed7 100644 --- a/targets/FreeRTOS/NXP/common/drivers/fsl_clock.c +++ b/targets/FreeRTOS/NXP/common/drivers/fsl_clock.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright 2018 NXP. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/common/drivers/fsl_clock.h b/targets/FreeRTOS/NXP/common/drivers/fsl_clock.h index fad8707822..1d39a55daa 100644 --- a/targets/FreeRTOS/NXP/common/drivers/fsl_clock.h +++ b/targets/FreeRTOS/NXP/common/drivers/fsl_clock.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright 2018 NXP. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/common/drivers/fsl_common.c b/targets/FreeRTOS/NXP/common/drivers/fsl_common.c index 77b1d11373..55c8b479c9 100644 --- a/targets/FreeRTOS/NXP/common/drivers/fsl_common.c +++ b/targets/FreeRTOS/NXP/common/drivers/fsl_common.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright 2018 NXP. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/common/drivers/fsl_common.h b/targets/FreeRTOS/NXP/common/drivers/fsl_common.h index f0b36852a4..4b9b18d2f5 100644 --- a/targets/FreeRTOS/NXP/common/drivers/fsl_common.h +++ b/targets/FreeRTOS/NXP/common/drivers/fsl_common.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright 2018 NXP. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/common/drivers/fsl_enet.c b/targets/FreeRTOS/NXP/common/drivers/fsl_enet.c index 48c455b91a..1cfb262207 100644 --- a/targets/FreeRTOS/NXP/common/drivers/fsl_enet.c +++ b/targets/FreeRTOS/NXP/common/drivers/fsl_enet.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2015 - 2016, Freescale Semiconductor, Inc. All rights reserved. // Portions Copyright 2016-2017 NXP. All rights reserved. // See LICENSE file in the project root for full license information. diff --git a/targets/FreeRTOS/NXP/common/drivers/fsl_enet.h b/targets/FreeRTOS/NXP/common/drivers/fsl_enet.h index 2be3739808..d391cfb709 100644 --- a/targets/FreeRTOS/NXP/common/drivers/fsl_enet.h +++ b/targets/FreeRTOS/NXP/common/drivers/fsl_enet.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2015 - 2016, Freescale Semiconductor, Inc. All rights reserved. // Portions Copyright 2016-2017 NXP. All rights reserved. // See LICENSE file in the project root for full license information. diff --git a/targets/FreeRTOS/NXP/common/drivers/fsl_flexspi.c b/targets/FreeRTOS/NXP/common/drivers/fsl_flexspi.c index 4107929e93..d888f1a63b 100644 --- a/targets/FreeRTOS/NXP/common/drivers/fsl_flexspi.c +++ b/targets/FreeRTOS/NXP/common/drivers/fsl_flexspi.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. // Portions Copyright 2016-2017 NXP. All rights reserved. // See LICENSE file in the project root for full license information. diff --git a/targets/FreeRTOS/NXP/common/drivers/fsl_flexspi.h b/targets/FreeRTOS/NXP/common/drivers/fsl_flexspi.h index 2e07011021..677463d673 100644 --- a/targets/FreeRTOS/NXP/common/drivers/fsl_flexspi.h +++ b/targets/FreeRTOS/NXP/common/drivers/fsl_flexspi.h @@ -1,6 +1,6 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. // Portions Copyright 2016-2017 NXP. All rights reserved. // See LICENSE file in the project root for full license information. diff --git a/targets/FreeRTOS/NXP/common/drivers/fsl_gpio.c b/targets/FreeRTOS/NXP/common/drivers/fsl_gpio.c index 143dcaf111..87891e8c3b 100644 --- a/targets/FreeRTOS/NXP/common/drivers/fsl_gpio.c +++ b/targets/FreeRTOS/NXP/common/drivers/fsl_gpio.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. // Portions Copyright 2016-2017 NXP. All rights reserved. // See LICENSE file in the project root for full license information. diff --git a/targets/FreeRTOS/NXP/common/drivers/fsl_gpio.h b/targets/FreeRTOS/NXP/common/drivers/fsl_gpio.h index 7645f2817b..763ea9fffc 100644 --- a/targets/FreeRTOS/NXP/common/drivers/fsl_gpio.h +++ b/targets/FreeRTOS/NXP/common/drivers/fsl_gpio.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. // Portions Copyright 2016-2017 NXP. All rights reserved. // See LICENSE file in the project root for full license information. diff --git a/targets/FreeRTOS/NXP/common/drivers/fsl_gpio_ext.c b/targets/FreeRTOS/NXP/common/drivers/fsl_gpio_ext.c index 82d5178a77..67ebc7dfde 100644 --- a/targets/FreeRTOS/NXP/common/drivers/fsl_gpio_ext.c +++ b/targets/FreeRTOS/NXP/common/drivers/fsl_gpio_ext.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/common/drivers/fsl_gpio_ext.h b/targets/FreeRTOS/NXP/common/drivers/fsl_gpio_ext.h index e0658e04b0..416e24b990 100644 --- a/targets/FreeRTOS/NXP/common/drivers/fsl_gpio_ext.h +++ b/targets/FreeRTOS/NXP/common/drivers/fsl_gpio_ext.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/common/drivers/fsl_iomuxc.h b/targets/FreeRTOS/NXP/common/drivers/fsl_iomuxc.h index 491dc7d157..28bf005fe1 100644 --- a/targets/FreeRTOS/NXP/common/drivers/fsl_iomuxc.h +++ b/targets/FreeRTOS/NXP/common/drivers/fsl_iomuxc.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. // Portions Copyright 2016-2017 NXP. All rights reserved. // See LICENSE file in the project root for full license information. diff --git a/targets/FreeRTOS/NXP/common/drivers/fsl_lpuart.c b/targets/FreeRTOS/NXP/common/drivers/fsl_lpuart.c index 8dc9841e3e..721887ed0f 100644 --- a/targets/FreeRTOS/NXP/common/drivers/fsl_lpuart.c +++ b/targets/FreeRTOS/NXP/common/drivers/fsl_lpuart.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2015-2016, Freescale Semiconductor, Inc. All rights reserved. // Portions Copyright 2016-2017 NXP. All rights reserved. // See LICENSE file in the project root for full license information. diff --git a/targets/FreeRTOS/NXP/common/drivers/fsl_lpuart.h b/targets/FreeRTOS/NXP/common/drivers/fsl_lpuart.h index d68e6e5cdb..3e2d6c45b8 100644 --- a/targets/FreeRTOS/NXP/common/drivers/fsl_lpuart.h +++ b/targets/FreeRTOS/NXP/common/drivers/fsl_lpuart.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2015-2016, Freescale Semiconductor, Inc. All rights reserved. // Portions Copyright 2016-2017 NXP. All rights reserved. // See LICENSE file in the project root for full license information. diff --git a/targets/FreeRTOS/NXP/common/drivers/fsl_semc.c b/targets/FreeRTOS/NXP/common/drivers/fsl_semc.c index 219fc39095..a08dc80a34 100644 --- a/targets/FreeRTOS/NXP/common/drivers/fsl_semc.c +++ b/targets/FreeRTOS/NXP/common/drivers/fsl_semc.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright 2017-2018 NXP. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/common/drivers/fsl_semc.h b/targets/FreeRTOS/NXP/common/drivers/fsl_semc.h index e74841ac92..83596c267f 100644 --- a/targets/FreeRTOS/NXP/common/drivers/fsl_semc.h +++ b/targets/FreeRTOS/NXP/common/drivers/fsl_semc.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright 2017-2018 NXP. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/common/drivers/fsl_snvs_lp.c b/targets/FreeRTOS/NXP/common/drivers/fsl_snvs_lp.c index fe58493650..3f2a105748 100644 --- a/targets/FreeRTOS/NXP/common/drivers/fsl_snvs_lp.c +++ b/targets/FreeRTOS/NXP/common/drivers/fsl_snvs_lp.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. // Portions Copyright (c) 2017, NXP All rights reserved. // See LICENSE file in the project root for full license information. diff --git a/targets/FreeRTOS/NXP/common/drivers/fsl_snvs_lp.h b/targets/FreeRTOS/NXP/common/drivers/fsl_snvs_lp.h index aa09975c62..427c4661e7 100644 --- a/targets/FreeRTOS/NXP/common/drivers/fsl_snvs_lp.h +++ b/targets/FreeRTOS/NXP/common/drivers/fsl_snvs_lp.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. // Portions Copyright (c) 2017, NXP All rights reserved. // See LICENSE file in the project root for full license information. diff --git a/targets/FreeRTOS/NXP/common/drivers/fsl_trng.c b/targets/FreeRTOS/NXP/common/drivers/fsl_trng.c index 2ebbef8a6e..58c00caa16 100644 --- a/targets/FreeRTOS/NXP/common/drivers/fsl_trng.c +++ b/targets/FreeRTOS/NXP/common/drivers/fsl_trng.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright 2017-2018 NXP. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/common/drivers/fsl_trng.h b/targets/FreeRTOS/NXP/common/drivers/fsl_trng.h index 450d1f99ef..6b15847b5e 100644 --- a/targets/FreeRTOS/NXP/common/drivers/fsl_trng.h +++ b/targets/FreeRTOS/NXP/common/drivers/fsl_trng.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright 2017-2018 NXP. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/common/drivers/fsl_usdhc.c b/targets/FreeRTOS/NXP/common/drivers/fsl_usdhc.c index 7a1086e610..19548f36fb 100644 --- a/targets/FreeRTOS/NXP/common/drivers/fsl_usdhc.c +++ b/targets/FreeRTOS/NXP/common/drivers/fsl_usdhc.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. // Portions Copyright 2016-2017 NXP All rights reserved. // See LICENSE file in the project root for full license information. diff --git a/targets/FreeRTOS/NXP/common/drivers/fsl_usdhc.h b/targets/FreeRTOS/NXP/common/drivers/fsl_usdhc.h index 386f0f7061..2ab4347f46 100644 --- a/targets/FreeRTOS/NXP/common/drivers/fsl_usdhc.h +++ b/targets/FreeRTOS/NXP/common/drivers/fsl_usdhc.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. // Portions Copyright 2016-2017 NXP All rights reserved. // See LICENSE file in the project root for full license information. diff --git a/targets/FreeRTOS/NXP/common/platform_BlockStorage.c b/targets/FreeRTOS/NXP/common/platform_BlockStorage.c index 3e64d96a82..ca3a7a4ab0 100644 --- a/targets/FreeRTOS/NXP/common/platform_BlockStorage.c +++ b/targets/FreeRTOS/NXP/common/platform_BlockStorage.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/common/sdmmc/inc/fsl_sd.h b/targets/FreeRTOS/NXP/common/sdmmc/inc/fsl_sd.h index a74307093c..53a08d434f 100644 --- a/targets/FreeRTOS/NXP/common/sdmmc/inc/fsl_sd.h +++ b/targets/FreeRTOS/NXP/common/sdmmc/inc/fsl_sd.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2015, Freescale Semiconductor, Inc. All rights reserved. // Portions Copyright 2016-2018 NXP All rights reserved. // See LICENSE file in the project root for full license information. diff --git a/targets/FreeRTOS/NXP/common/sdmmc/inc/fsl_sdmmc_common.h b/targets/FreeRTOS/NXP/common/sdmmc/inc/fsl_sdmmc_common.h index 1ec70d30a9..d0220d5648 100644 --- a/targets/FreeRTOS/NXP/common/sdmmc/inc/fsl_sdmmc_common.h +++ b/targets/FreeRTOS/NXP/common/sdmmc/inc/fsl_sdmmc_common.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2015, Freescale Semiconductor, Inc. All rights reserved. // Portions Copyright 2016-2018 NXP All rights reserved. // See LICENSE file in the project root for full license information. diff --git a/targets/FreeRTOS/NXP/common/sdmmc/inc/fsl_sdmmc_host.h b/targets/FreeRTOS/NXP/common/sdmmc/inc/fsl_sdmmc_host.h index e4524fd7aa..5389841eb1 100644 --- a/targets/FreeRTOS/NXP/common/sdmmc/inc/fsl_sdmmc_host.h +++ b/targets/FreeRTOS/NXP/common/sdmmc/inc/fsl_sdmmc_host.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2015, Freescale Semiconductor, Inc. All rights reserved. // Portions Copyright 2016-2018 NXP All rights reserved. // See LICENSE file in the project root for full license information. diff --git a/targets/FreeRTOS/NXP/common/sdmmc/inc/fsl_sdmmc_spec.h b/targets/FreeRTOS/NXP/common/sdmmc/inc/fsl_sdmmc_spec.h index 3dfd9832c3..5ceffa2d06 100644 --- a/targets/FreeRTOS/NXP/common/sdmmc/inc/fsl_sdmmc_spec.h +++ b/targets/FreeRTOS/NXP/common/sdmmc/inc/fsl_sdmmc_spec.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2015, Freescale Semiconductor, Inc. All rights reserved. // Portions Copyright 2016-2018 NXP All rights reserved. // See LICENSE file in the project root for full license information. diff --git a/targets/FreeRTOS/NXP/common/sdmmc/port/fsl_sdmmc_event.c b/targets/FreeRTOS/NXP/common/sdmmc/port/fsl_sdmmc_event.c index b9f27fc21f..7d4154c76e 100644 --- a/targets/FreeRTOS/NXP/common/sdmmc/port/fsl_sdmmc_event.c +++ b/targets/FreeRTOS/NXP/common/sdmmc/port/fsl_sdmmc_event.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2015, Freescale Semiconductor, Inc. All rights reserved. // Portions Copyright 2016-2018 NXP All rights reserved. // See LICENSE file in the project root for full license information. diff --git a/targets/FreeRTOS/NXP/common/sdmmc/port/fsl_sdmmc_event.h b/targets/FreeRTOS/NXP/common/sdmmc/port/fsl_sdmmc_event.h index 90941b9bce..651e61b8ea 100644 --- a/targets/FreeRTOS/NXP/common/sdmmc/port/fsl_sdmmc_event.h +++ b/targets/FreeRTOS/NXP/common/sdmmc/port/fsl_sdmmc_event.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2015, Freescale Semiconductor, Inc. All rights reserved. // Portions Copyright 2016-2018 NXP All rights reserved. // See LICENSE file in the project root for full license information. diff --git a/targets/FreeRTOS/NXP/common/sdmmc/port/fsl_sdmmc_host.c b/targets/FreeRTOS/NXP/common/sdmmc/port/fsl_sdmmc_host.c index ae89a87411..a6b7a1e6ab 100644 --- a/targets/FreeRTOS/NXP/common/sdmmc/port/fsl_sdmmc_host.c +++ b/targets/FreeRTOS/NXP/common/sdmmc/port/fsl_sdmmc_host.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2015, Freescale Semiconductor, Inc. All rights reserved. // Portions Copyright 2016-2018 NXP All rights reserved. // See LICENSE file in the project root for full license information. diff --git a/targets/FreeRTOS/NXP/common/sdmmc/src/fsl_sd.c b/targets/FreeRTOS/NXP/common/sdmmc/src/fsl_sd.c index 005a25db53..9a8ef916e8 100644 --- a/targets/FreeRTOS/NXP/common/sdmmc/src/fsl_sd.c +++ b/targets/FreeRTOS/NXP/common/sdmmc/src/fsl_sd.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2015, Freescale Semiconductor, Inc. All rights reserved. // Portions Copyright 2016-2018 NXP All rights reserved. // See LICENSE file in the project root for full license information. diff --git a/targets/FreeRTOS/NXP/common/sdmmc/src/fsl_sdmmc_common.c b/targets/FreeRTOS/NXP/common/sdmmc/src/fsl_sdmmc_common.c index fb3bd49e3b..c37966848e 100644 --- a/targets/FreeRTOS/NXP/common/sdmmc/src/fsl_sdmmc_common.c +++ b/targets/FreeRTOS/NXP/common/sdmmc/src/fsl_sdmmc_common.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2015, Freescale Semiconductor, Inc. All rights reserved. // Portions Copyright 2016-2018 NXP All rights reserved. // See LICENSE file in the project root for full license information. diff --git a/targets/FreeRTOS/NXP/common/startup/startup_mimxrt1062.c b/targets/FreeRTOS/NXP/common/startup/startup_mimxrt1062.c index 375a9e7b39..20da658a58 100644 --- a/targets/FreeRTOS/NXP/common/startup/startup_mimxrt1062.c +++ b/targets/FreeRTOS/NXP/common/startup/startup_mimxrt1062.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright 2016-2018 NXP. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/common/targetHAL_ConfigurationManager.cpp b/targets/FreeRTOS/NXP/common/targetHAL_ConfigurationManager.cpp index 302b948528..23b6f33a1b 100644 --- a/targets/FreeRTOS/NXP/common/targetHAL_ConfigurationManager.cpp +++ b/targets/FreeRTOS/NXP/common/targetHAL_ConfigurationManager.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/common/utilities/flexspi_nor_flash_ops.c b/targets/FreeRTOS/NXP/common/utilities/flexspi_nor_flash_ops.c index d9907ac701..f1f45169f9 100644 --- a/targets/FreeRTOS/NXP/common/utilities/flexspi_nor_flash_ops.c +++ b/targets/FreeRTOS/NXP/common/utilities/flexspi_nor_flash_ops.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. // Portions Copyright 2016-2018 NXP. All rights reserved. // See LICENSE file in the project root for full license information. diff --git a/targets/FreeRTOS/NXP/common/utilities/flexspi_nor_flash_ops.h b/targets/FreeRTOS/NXP/common/utilities/flexspi_nor_flash_ops.h index 5f3f1eff4b..cd6284adaa 100644 --- a/targets/FreeRTOS/NXP/common/utilities/flexspi_nor_flash_ops.h +++ b/targets/FreeRTOS/NXP/common/utilities/flexspi_nor_flash_ops.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/common/utilities/fsl_debug_console.c b/targets/FreeRTOS/NXP/common/utilities/fsl_debug_console.c index 835400f8f9..cd9f724781 100644 --- a/targets/FreeRTOS/NXP/common/utilities/fsl_debug_console.c +++ b/targets/FreeRTOS/NXP/common/utilities/fsl_debug_console.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright 1999-2000 MOTOROLA, INC., Inc. All rights reserved. // Portions Copyright (c) 2015, Freescale Semiconductor, Inc. All rights reserved. // Portions Copyright 2016-2018 NXP. All rights reserved. diff --git a/targets/FreeRTOS/NXP/common/utilities/fsl_debug_console.h b/targets/FreeRTOS/NXP/common/utilities/fsl_debug_console.h index aa1abe15f4..31cf2224e6 100644 --- a/targets/FreeRTOS/NXP/common/utilities/fsl_debug_console.h +++ b/targets/FreeRTOS/NXP/common/utilities/fsl_debug_console.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2013-2015, Freescale Semiconductor, Inc. All rights reserved. // Portions Copyright 2016-2018 NXP. All rights reserved. // See LICENSE file in the project root for full license information. diff --git a/targets/FreeRTOS/NXP/common/utilities/fsl_debug_console_conf.h b/targets/FreeRTOS/NXP/common/utilities/fsl_debug_console_conf.h index 060bb515b2..1587f10481 100644 --- a/targets/FreeRTOS/NXP/common/utilities/fsl_debug_console_conf.h +++ b/targets/FreeRTOS/NXP/common/utilities/fsl_debug_console_conf.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright 2017-2018 NXP. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/common/utilities/fsl_str.c b/targets/FreeRTOS/NXP/common/utilities/fsl_str.c index d327f08291..97b1a88588 100644 --- a/targets/FreeRTOS/NXP/common/utilities/fsl_str.c +++ b/targets/FreeRTOS/NXP/common/utilities/fsl_str.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright 2017 NXP. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/common/utilities/fsl_str.h b/targets/FreeRTOS/NXP/common/utilities/fsl_str.h index 78c9879c3a..8a157a4b56 100644 --- a/targets/FreeRTOS/NXP/common/utilities/fsl_str.h +++ b/targets/FreeRTOS/NXP/common/utilities/fsl_str.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright 2017 NXP. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/common/xip/evkmimxrt1060_flexspi_nor_config.c b/targets/FreeRTOS/NXP/common/xip/evkmimxrt1060_flexspi_nor_config.c index 08fa5d07e6..b87118943d 100644 --- a/targets/FreeRTOS/NXP/common/xip/evkmimxrt1060_flexspi_nor_config.c +++ b/targets/FreeRTOS/NXP/common/xip/evkmimxrt1060_flexspi_nor_config.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright 2018 NXP. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/common/xip/evkmimxrt1060_flexspi_nor_config.h b/targets/FreeRTOS/NXP/common/xip/evkmimxrt1060_flexspi_nor_config.h index d762c1cf4e..08cf07a66e 100644 --- a/targets/FreeRTOS/NXP/common/xip/evkmimxrt1060_flexspi_nor_config.h +++ b/targets/FreeRTOS/NXP/common/xip/evkmimxrt1060_flexspi_nor_config.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright 2018 NXP. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/common/xip/fsl_flexspi_nor_boot.c b/targets/FreeRTOS/NXP/common/xip/fsl_flexspi_nor_boot.c index 5bd7ffa0a5..b568d019dd 100644 --- a/targets/FreeRTOS/NXP/common/xip/fsl_flexspi_nor_boot.c +++ b/targets/FreeRTOS/NXP/common/xip/fsl_flexspi_nor_boot.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright 2017 NXP. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/common/xip/fsl_flexspi_nor_boot.h b/targets/FreeRTOS/NXP/common/xip/fsl_flexspi_nor_boot.h index e7c25cfec7..fce5d0b6d8 100644 --- a/targets/FreeRTOS/NXP/common/xip/fsl_flexspi_nor_boot.h +++ b/targets/FreeRTOS/NXP/common/xip/fsl_flexspi_nor_boot.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright 2017 NXP. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/fatfs/diskio.c b/targets/FreeRTOS/NXP/fatfs/diskio.c index ddcf883e4e..3ae6366413 100644 --- a/targets/FreeRTOS/NXP/fatfs/diskio.c +++ b/targets/FreeRTOS/NXP/fatfs/diskio.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2015, Freescale Semiconductor, Inc. // Portions Copyright 2016-2018 NXP // See LICENSE file in the project root for full license information. diff --git a/targets/FreeRTOS/NXP/fatfs/fsl_sd_disk.h b/targets/FreeRTOS/NXP/fatfs/fsl_sd_disk.h index b440222b4c..ee9f9186c9 100644 --- a/targets/FreeRTOS/NXP/fatfs/fsl_sd_disk.h +++ b/targets/FreeRTOS/NXP/fatfs/fsl_sd_disk.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2015, Freescale Semiconductor, Inc. // Portions Copyright 2016 NXP // See LICENSE file in the project root for full license information. diff --git a/targets/FreeRTOS/NXP/include/CMakeLists.txt b/targets/FreeRTOS/NXP/include/CMakeLists.txt index 1f48698d6b..c1481d93f1 100644 --- a/targets/FreeRTOS/NXP/include/CMakeLists.txt +++ b/targets/FreeRTOS/NXP/include/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/targets/FreeRTOS/NXP/include/TargetPAL.h b/targets/FreeRTOS/NXP/include/TargetPAL.h index 477e3254e8..ff6a68e78a 100644 --- a/targets/FreeRTOS/NXP/include/TargetPAL.h +++ b/targets/FreeRTOS/NXP/include/TargetPAL.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/include/Target_BlockStorage_iMXRTFlashDriver.h b/targets/FreeRTOS/NXP/include/Target_BlockStorage_iMXRTFlashDriver.h index 0b893e8643..fbfabe3119 100644 --- a/targets/FreeRTOS/NXP/include/Target_BlockStorage_iMXRTFlashDriver.h +++ b/targets/FreeRTOS/NXP/include/Target_BlockStorage_iMXRTFlashDriver.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/include/Target_Windows_Storage.h b/targets/FreeRTOS/NXP/include/Target_Windows_Storage.h index 5a6c356cfb..2cd12b7583 100644 --- a/targets/FreeRTOS/NXP/include/Target_Windows_Storage.h +++ b/targets/FreeRTOS/NXP/include/Target_Windows_Storage.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/include/platform_target_capabilities.h b/targets/FreeRTOS/NXP/include/platform_target_capabilities.h index e96158da28..6c377d19af 100644 --- a/targets/FreeRTOS/NXP/include/platform_target_capabilities.h +++ b/targets/FreeRTOS/NXP/include/platform_target_capabilities.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/nanoBooter/CMakeLists.txt b/targets/FreeRTOS/NXP/nanoBooter/CMakeLists.txt index d7a552ab86..44459815c6 100644 --- a/targets/FreeRTOS/NXP/nanoBooter/CMakeLists.txt +++ b/targets/FreeRTOS/NXP/nanoBooter/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/targets/FreeRTOS/NXP/nanoBooter/WireProtocol_App_Interface.c b/targets/FreeRTOS/NXP/nanoBooter/WireProtocol_App_Interface.c index d2be2eebe5..055e05b48f 100644 --- a/targets/FreeRTOS/NXP/nanoBooter/WireProtocol_App_Interface.c +++ b/targets/FreeRTOS/NXP/nanoBooter/WireProtocol_App_Interface.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/nanoBooter/WireProtocol_MonitorCommands.c b/targets/FreeRTOS/NXP/nanoBooter/WireProtocol_MonitorCommands.c index 67b9968d6d..e0ae8c8d3e 100644 --- a/targets/FreeRTOS/NXP/nanoBooter/WireProtocol_MonitorCommands.c +++ b/targets/FreeRTOS/NXP/nanoBooter/WireProtocol_MonitorCommands.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // @@ -20,7 +20,7 @@ ////////////////////////////////////////////////////////////////////// // helper functions -int NanoBooter_GetReleaseInfo(ReleaseInfo* releaseInfo) +int NanoBooter_GetReleaseInfo(ReleaseInfo *releaseInfo) { releaseInfo->version.usMajor = VERSION_MAJOR; releaseInfo->version.usMinor = VERSION_MINOR; @@ -35,12 +35,12 @@ int NanoBooter_GetReleaseInfo(ReleaseInfo* releaseInfo) return true; } -static int AccessMemory(uint32_t location, uint32_t lengthInBytes, uint8_t* buffer, int32_t mode, uint32_t* errorCode) +static int AccessMemory(uint32_t location, uint32_t lengthInBytes, uint8_t *buffer, int32_t mode, uint32_t *errorCode) { // reset error code *errorCode = AccessMemoryErrorCode_NoError; - - switch(mode) + + switch (mode) { case AccessMemory_Write: // use FLASH driver to perform write operation @@ -52,9 +52,10 @@ static int AccessMemory(uint32_t location, uint32_t lengthInBytes, uint8_t* buff case AccessMemory_Check: return iMXRTFlexSPIDriver_IsBlockErased(NULL, location, lengthInBytes); - + case AccessMemory_Read: - return iMXRTFlexSPIDriver_Read(NULL, location, lengthInBytes, buffer);; + return iMXRTFlexSPIDriver_Read(NULL, location, lengthInBytes, buffer); + ; default: // default return is FALSE @@ -64,29 +65,28 @@ static int AccessMemory(uint32_t location, uint32_t lengthInBytes, uint8_t* buff //////////////////////////////////////////////////// -int Monitor_Ping(WP_Message* message) +int Monitor_Ping(WP_Message *message) { - if((message->m_header.m_flags & WP_Flags_c_Reply) == 0) + if ((message->m_header.m_flags & WP_Flags_c_Reply) == 0) { Monitor_Ping_Reply cmdReply; cmdReply.m_source = Monitor_Ping_c_Ping_Source_NanoBooter; cmdReply.m_dbg_flags = 0; - #if defined(WP_IMPLEMENTS_CRC32) - cmdReply.m_dbg_flags |= Monitor_Ping_c_Ping_WPFlag_SupportsCRC32; - #endif +#if defined(WP_IMPLEMENTS_CRC32) + cmdReply.m_dbg_flags |= Monitor_Ping_c_Ping_WPFlag_SupportsCRC32; +#endif - // Wire Protocol packet size - #if (WP_PACKET_SIZE == 512) +// Wire Protocol packet size +#if (WP_PACKET_SIZE == 512) cmdReply.m_dbg_flags |= Monitor_Ping_c_PacketSize_0512; - #elif (WP_PACKET_SIZE == 256) +#elif (WP_PACKET_SIZE == 256) cmdReply.m_dbg_flags |= Monitor_Ping_c_PacketSize_0256; - #elif (WP_PACKET_SIZE == 128) +#elif (WP_PACKET_SIZE == 128) cmdReply.m_dbg_flags |= Monitor_Ping_c_PacketSize_0128; - #elif (WP_PACKET_SIZE == 1024) +#elif (WP_PACKET_SIZE == 1024) cmdReply.m_dbg_flags |= Monitor_Ping_c_PacketSize_1024; - #endif - +#endif WP_ReplyToCommand(message, true, false, &cmdReply, sizeof(cmdReply)); } @@ -94,70 +94,71 @@ int Monitor_Ping(WP_Message* message) return true; } -int Monitor_OemInfo(WP_Message* message) +int Monitor_OemInfo(WP_Message *message) { - if((message->m_header.m_flags & WP_Flags_c_Reply) == 0) + if ((message->m_header.m_flags & WP_Flags_c_Reply) == 0) { - Monitor_OemInfo_Reply cmdReply; - + Monitor_OemInfo_Reply cmdReply; + bool fOK = NanoBooter_GetReleaseInfo(&cmdReply.m_releaseInfo) == true; - + WP_ReplyToCommand(message, fOK, false, &cmdReply, sizeof(cmdReply)); } return true; } -int Monitor_ReadMemory(WP_Message* message) +int Monitor_ReadMemory(WP_Message *message) { - CLR_DBG_Commands_Monitor_ReadMemory* cmd = (CLR_DBG_Commands_Monitor_ReadMemory*)message->m_payload; + CLR_DBG_Commands_Monitor_ReadMemory *cmd = (CLR_DBG_Commands_Monitor_ReadMemory *)message->m_payload; - unsigned char buf[ 1024 ]; - unsigned int len = cmd->length; if(len > sizeof(buf)) len = sizeof(buf); + unsigned char buf[1024]; + unsigned int len = cmd->length; + if (len > sizeof(buf)) + len = sizeof(buf); uint32_t errorCode; - AccessMemory(cmd->address, len, buf, AccessMemory_Read, &errorCode ); + AccessMemory(cmd->address, len, buf, AccessMemory_Read, &errorCode); WP_ReplyToCommand(message, true, false, buf, len); return true; } -int Monitor_WriteMemory(WP_Message* message) +int Monitor_WriteMemory(WP_Message *message) { - CLR_DBG_Commands_Monitor_WriteMemory* cmd = (CLR_DBG_Commands_Monitor_WriteMemory*)message->m_payload; + CLR_DBG_Commands_Monitor_WriteMemory *cmd = (CLR_DBG_Commands_Monitor_WriteMemory *)message->m_payload; CLR_DBG_Commands_Monitor_WriteMemory_Reply cmdReply; - // TODO: not sure if we really need this // if(!m_signedDataState.VerifyContiguousData(cmd->m_address, cmd->m_length)) // { // m_signedDataState.EraseMemoryAndReset(); - + // return false; // } // TODO: not sure if we really need this // nanoBooter_OnStateChange(State_MemoryWrite, (void*)cmd->m_address); - // assume at RAM, directly use the original address - AccessMemory(cmd->address, cmd->length, cmd->data, AccessMemory_Write, &cmdReply.ErrorCode); - + // assume at RAM, directly use the original address + AccessMemory(cmd->address, cmd->length, cmd->data, AccessMemory_Write, &cmdReply); + WP_ReplyToCommand(message, true, false, &cmdReply, sizeof(cmdReply)); return true; } -int Monitor_Reboot(WP_Message* message) +int Monitor_Reboot(WP_Message *message) { - Monitor_Reboot_Command* cmd = (Monitor_Reboot_Command*)message->m_payload; + Monitor_Reboot_Command *cmd = (Monitor_Reboot_Command *)message->m_payload; WP_ReplyToCommand(message, true, false, NULL, 0); - if(cmd != NULL) + if (cmd != NULL) { // only reset if we are not trying to get into the bootloader - if((cmd->m_flags & Monitor_Reboot_c_EnterBootloader) != Monitor_Reboot_c_EnterBootloader) + if ((cmd->m_flags & Monitor_Reboot_c_EnterBootloader) != Monitor_Reboot_c_EnterBootloader) { // RESET CPU // because ChibiOS relies on CMSIS it's recommended to make use of the CMSIS API @@ -168,36 +169,36 @@ int Monitor_Reboot(WP_Message* message) return true; } -int Monitor_EraseMemory(WP_Message* message) +int Monitor_EraseMemory(WP_Message *message) { - CLR_DBG_Commands_Monitor_EraseMemory* cmd = (CLR_DBG_Commands_Monitor_EraseMemory*)message->m_payload; + CLR_DBG_Commands_Monitor_EraseMemory *cmd = (CLR_DBG_Commands_Monitor_EraseMemory *)message->m_payload; CLR_DBG_Commands_Monitor_EraseMemory_Reply cmdReply; // TODO: not sure if we really need this // nanoBooter_OnStateChange( State_MemoryErase, (void*)cmd->m_address ); - - AccessMemory(cmd->address, cmd->length, NULL, AccessMemory_Erase, &cmdReply.ErrorCode); + + AccessMemory(cmd->address, cmd->length, NULL, AccessMemory_Erase, &cmdReply); WP_ReplyToCommand(message, true, false, &cmdReply, sizeof(cmdReply)); - + return true; } -int Monitor_QueryConfiguration(WP_Message* message) +int Monitor_QueryConfiguration(WP_Message *message) { - bool success = false; + bool success = false; // include handling of configuration block only if feature is available - #if (HAS_CONFIG_BLOCK == TRUE) +#if (HAS_CONFIG_BLOCK == TRUE) - Monitor_QueryConfiguration_Command *cmd = (Monitor_QueryConfiguration_Command*)message->m_payload; - int size = 0; + Monitor_QueryConfiguration_Command *cmd = (Monitor_QueryConfiguration_Command *)message->m_payload; + int size = 0; - switch((DeviceConfigurationOption)cmd->Configuration) + switch ((DeviceConfigurationOption)cmd->Configuration) { case DeviceConfigurationOption_Network: - // TODO missing implementation for now + // TODO missing implementation for now break; case DeviceConfigurationOption_Wireless80211Network: @@ -210,34 +211,34 @@ int Monitor_QueryConfiguration(WP_Message* message) break; default: - break; + break; } - if(!success) + if (!success) { - WP_ReplyToCommand( message, success, false, NULL, size ); + WP_ReplyToCommand(message, success, false, NULL, size); } - #else +#else (void)message; - #endif // (HAS_CONFIG_BLOCK == TRUE) +#endif // (HAS_CONFIG_BLOCK == TRUE) return success; } -int Monitor_UpdateConfiguration(WP_Message* message) +int Monitor_UpdateConfiguration(WP_Message *message) { bool success = false; // include handling of configuration block only if feature is available - #if (HAS_CONFIG_BLOCK == TRUE) - - Monitor_UpdateConfiguration_Command* cmd = (Monitor_UpdateConfiguration_Command*)message->m_payload; +#if (HAS_CONFIG_BLOCK == TRUE) + + Monitor_UpdateConfiguration_Command *cmd = (Monitor_UpdateConfiguration_Command *)message->m_payload; Monitor_UpdateConfiguration_Reply cmdReply; - switch((DeviceConfigurationOption)cmd->Configuration) + switch ((DeviceConfigurationOption)cmd->Configuration) { case DeviceConfigurationOption_Network: case DeviceConfigurationOption_Wireless80211Network: @@ -251,58 +252,58 @@ int Monitor_UpdateConfiguration(WP_Message* message) WP_ReplyToCommand(message, success, false, &cmdReply, sizeof(cmdReply)); - #else +#else (void)message; - #endif // (HAS_CONFIG_BLOCK == TRUE) +#endif // (HAS_CONFIG_BLOCK == TRUE) return success; } -int Monitor_CheckMemory(WP_Message* message) +int Monitor_CheckMemory(WP_Message *message) { bool ret = false; - CLR_DBG_Commands_Monitor_CheckMemory* cmd = (CLR_DBG_Commands_Monitor_CheckMemory*)message->m_payload; + CLR_DBG_Commands_Monitor_CheckMemory *cmd = (CLR_DBG_Commands_Monitor_CheckMemory *)message->m_payload; CLR_DBG_Commands_Monitor_CheckMemory_Reply cmdReply; uint32_t errorCode; - ret = AccessMemory(cmd->address, cmd->length, (uint8_t*)&cmdReply.crc, AccessMemory_Check, &errorCode); + ret = AccessMemory(cmd->address, cmd->length, (uint8_t *)&cmdReply, AccessMemory_Check, &errorCode); WP_ReplyToCommand(message, ret, false, &cmdReply, sizeof(cmdReply)); return ret; } -int Monitor_MemoryMap(WP_Message* message) +int Monitor_MemoryMap(WP_Message *message) { MemoryMap_Range map[2]; // if(m_signedDataState.CheckDirty()) // { // m_signedDataState.EraseMemoryAndReset(); - + // return false; // } map[0].m_address = HalSystemConfig.RAM1.Base; - map[0].m_length = HalSystemConfig.RAM1.Size; - map[0].m_flags = Monitor_MemoryMap_c_RAM; + map[0].m_length = HalSystemConfig.RAM1.Size; + map[0].m_flags = Monitor_MemoryMap_c_RAM; map[1].m_address = HalSystemConfig.FLASH1.Base; - map[1].m_length = HalSystemConfig.FLASH1.Size; - map[1].m_flags = Monitor_MemoryMap_c_FLASH; + map[1].m_length = HalSystemConfig.FLASH1.Size; + map[1].m_flags = Monitor_MemoryMap_c_FLASH; WP_ReplyToCommand(message, true, false, map, sizeof(map)); return true; } -int Monitor_FlashSectorMap(WP_Message* message) +int Monitor_FlashSectorMap(WP_Message *message) { - if((message->m_header.m_flags & WP_Flags_c_Reply) == 0) + if ((message->m_header.m_flags & WP_Flags_c_Reply) == 0) { struct Flash_BlockRegionInfo { @@ -316,54 +317,55 @@ int Monitor_FlashSectorMap(WP_Message* message) unsigned int rangeCount = 0; unsigned int rangeIndex = 0; - for(int cnt = 0; cnt < 2; cnt++) + for (int cnt = 0; cnt < 2; cnt++) { - BlockStorageDevice* device = BlockStorageList_GetFirstDevice(); + BlockStorageDevice *device = BlockStorageList_GetFirstDevice(); - if(device == NULL) + if (device == NULL) { WP_ReplyToCommand(message, true, false, NULL, 0); return false; } - if(cnt == 1) + if (cnt == 1) { - pData = (struct Flash_BlockRegionInfo*)platform_malloc(rangeCount * sizeof(struct Flash_BlockRegionInfo)); + pData = + (struct Flash_BlockRegionInfo *)platform_malloc(rangeCount * sizeof(struct Flash_BlockRegionInfo)); - if(pData == NULL) + if (pData == NULL) { WP_ReplyToCommand(message, true, false, NULL, 0); return false; } } - DeviceBlockInfo* deviceInfo = BlockStorageDevice_GetDeviceInfo(device); + DeviceBlockInfo *deviceInfo = BlockStorageDevice_GetDeviceInfo(device); - for(unsigned int i = 0; i < deviceInfo->NumRegions; i++) + for (unsigned int i = 0; i < deviceInfo->NumRegions; i++) { - const BlockRegionInfo* pRegion = &deviceInfo->Regions[ i ]; + const BlockRegionInfo *pRegion = &deviceInfo->Regions[i]; - for(unsigned int j = 0; j < pRegion->NumBlockRanges; j++) + for (unsigned int j = 0; j < pRegion->NumBlockRanges; j++) { - if(cnt == 0) + if (cnt == 0) { rangeCount++; } else { - pData[ rangeIndex ].StartAddress = BlockRegionInfo_BlockAddress(pRegion, pRegion->BlockRanges[ j ].StartBlock); - pData[ rangeIndex ].NumBlocks = BlockRange_GetBlockCount(pRegion->BlockRanges[j]); - pData[ rangeIndex ].BytesPerBlock = pRegion->BytesPerBlock; - pData[ rangeIndex ].Usage = pRegion->BlockRanges[ j ].RangeType & BlockRange_USAGE_MASK; + pData[rangeIndex].StartAddress = + BlockRegionInfo_BlockAddress(pRegion, pRegion->BlockRanges[j].StartBlock); + pData[rangeIndex].NumBlocks = BlockRange_GetBlockCount(pRegion->BlockRanges[j]); + pData[rangeIndex].BytesPerBlock = pRegion->BytesPerBlock; + pData[rangeIndex].Usage = pRegion->BlockRanges[j].RangeType & BlockRange_USAGE_MASK; rangeIndex++; } } } } - - WP_ReplyToCommand(message, true, false, (void*)pData, rangeCount * sizeof(struct Flash_BlockRegionInfo)); + WP_ReplyToCommand(message, true, false, (void *)pData, rangeCount * sizeof(struct Flash_BlockRegionInfo)); platform_free(pData); } diff --git a/targets/FreeRTOS/NXP/nanoCLR/CMakeLists.txt b/targets/FreeRTOS/NXP/nanoCLR/CMakeLists.txt index d3332a8e98..2e63da1fc7 100644 --- a/targets/FreeRTOS/NXP/nanoCLR/CMakeLists.txt +++ b/targets/FreeRTOS/NXP/nanoCLR/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/targets/FreeRTOS/NXP/nanoCLR/Memory.cpp b/targets/FreeRTOS/NXP/nanoCLR/Memory.cpp index 5a950868ca..0bc908e590 100644 --- a/targets/FreeRTOS/NXP/nanoCLR/Memory.cpp +++ b/targets/FreeRTOS/NXP/nanoCLR/Memory.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/nanoCLR/TargetHAL_Spi.h b/targets/FreeRTOS/NXP/nanoCLR/TargetHAL_Spi.h new file mode 100644 index 0000000000..de9423a03c --- /dev/null +++ b/targets/FreeRTOS/NXP/nanoCLR/TargetHAL_Spi.h @@ -0,0 +1,15 @@ +// +// Copyright (c) .NET Foundation and Contributors +// See LICENSE file in the project root for full license information. +// + +#ifndef _TARGET_HAL_SPI_H_ +#define _TARGET_HAL_SPI_H_ 1 + +// # of spi buses +#define NUM_SPI_BUSES 0 + +// Maximum number of devices per SPI bus +#define MAX_SPI_DEVICES 4 + +#endif //_TARGET_HAL_SPI_H_ diff --git a/targets/FreeRTOS/NXP/nanoCLR/Target_Network.cpp b/targets/FreeRTOS/NXP/nanoCLR/Target_Network.cpp index fa5ee092b1..f48660475c 100644 --- a/targets/FreeRTOS/NXP/nanoCLR/Target_Network.cpp +++ b/targets/FreeRTOS/NXP/nanoCLR/Target_Network.cpp @@ -1,6 +1,6 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/nanoCLR/Windows.Devices.Gpio/cpu_gpio.cpp b/targets/FreeRTOS/NXP/nanoCLR/Windows.Devices.Gpio/cpu_gpio.cpp index 14450ff3f7..c3716d3fae 100644 --- a/targets/FreeRTOS/NXP/nanoCLR/Windows.Devices.Gpio/cpu_gpio.cpp +++ b/targets/FreeRTOS/NXP/nanoCLR/Windows.Devices.Gpio/cpu_gpio.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // @@ -13,131 +13,130 @@ #include "timers.h" -#define GPIO_MAX_PINS 160 // 5 Ports * 32 bits ? -#define GPIO_BITS_PORT 16 // 16 bits per gpio port -#define TOTAL_GPIO_PORTS ((GPIO_MAX_PINS + (GPIO_BITS_PORT - 1)) / GPIO_BITS_PORT) +#define GPIO_MAX_PINS 160 // 5 Ports * 32 bits ? +#define GPIO_BITS_PORT 16 // 16 bits per gpio port +#define TOTAL_GPIO_PORTS ((GPIO_MAX_PINS + (GPIO_BITS_PORT - 1)) / GPIO_BITS_PORT) // Structure to hold information about input pin struct gpio_input_state { - GPIO_PIN pinNumber; // Pin number - TimerHandle_t debounceTimer; // debounce timer for this Pin - GPIO_INTERRUPT_SERVICE_ROUTINE isrPtr; // Ptr to user ISR or null - uint32_t debounceMs; // debounce Millsecs, no debonce=0 - uint8_t mode; // Interrupt mode - void * param; // Param to user isr call - bool expected; // Expected state for debounce handler - bool waitingDebounce; // True if waiting for debounce timer to complete + GPIO_PIN pinNumber; // Pin number + TimerHandle_t debounceTimer; // debounce timer for this Pin + GPIO_INTERRUPT_SERVICE_ROUTINE isrPtr; // Ptr to user ISR or null + uint32_t debounceMs; // debounce Millsecs, no debonce=0 + uint8_t mode; // Interrupt mode + void *param; // Param to user isr call + bool expected; // Expected state for debounce handler + bool waitingDebounce; // True if waiting for debounce timer to complete }; // Array of gpio_input_state ptrs for each gpio port // each port (GPIO1 to GPIO5) has a low & high 16 bit port. -typedef gpio_input_state * statePortArray[GPIO_BITS_PORT]; +typedef gpio_input_state *statePortArray[GPIO_BITS_PORT]; // For each 16 bit gpio port we have a ptr to an array ptrs to gpio_input_state // These are initialised only when an input gpio bit is enabled keeping memory use to the minimum -static statePortArray * port_array[TOTAL_GPIO_PORTS]; +static statePortArray *port_array[TOTAL_GPIO_PORTS]; // Array of bits for saving reserved state -static uint16_t pinReserved[TOTAL_GPIO_PORTS]; - +static uint16_t pinReserved[TOTAL_GPIO_PORTS]; // this is an utility define to get a port number from our "encoded" pin number // pin 0 -> (GPIO_MAX_PINS - 1) // i.e Port 0 = Pins 0 to 15, port 1 = pins 16 to 31 etc -#define GetIoPort(pinNumber) (pinNumber/GPIO_BITS_PORT) -#define GetIoBit(pinNumber) (pinNumber%GPIO_BITS_PORT) -#define IsValidGpioPin(pinNumber) (pinNumber < GPIO_MAX_PINS) - +#define GetIoPort(pinNumber) (pinNumber / GPIO_BITS_PORT) +#define GetIoBit(pinNumber) (pinNumber % GPIO_BITS_PORT) +#define IsValidGpioPin(pinNumber) (pinNumber < GPIO_MAX_PINS) void Gpio_DebounceHandler(TimerHandle_t xTimer) { - gpio_input_state* pGpio = (gpio_input_state*)pvTimerGetTimerID(xTimer); - if (pGpio->isrPtr) - { - bool actual =(GpioPinValue)GPIO_PinRead(GPIO_BASE(pGpio->pinNumber), GPIO_PIN(pGpio->pinNumber)); - if (actual == pGpio->expected) - { - pGpio->isrPtr(pGpio->pinNumber, actual, pGpio->param); - if (pGpio->mode == GPIO_INT_EDGE_BOTH) - { // both edges - pGpio->expected ^= 1; // update expected state - } - } - } - - pGpio->waitingDebounce = false; + gpio_input_state *pState = (gpio_input_state *)pvTimerGetTimerID(xTimer); + + bool actual = (GpioPinValue)GPIO_PinRead(GPIO_BASE(pState->pinNumber), GPIO_PIN(pState->pinNumber)); + + if (actual == pState->expected) + { + pState->isrPtr(pState->pinNumber, actual); + + if (pState->mode == GPIO_INT_EDGE_BOTH) + { // both edges + pState->expected ^= 1; // update expected state + } + } + + pState->waitingDebounce = false; } -void GPIO_Main_IRQHandler( int portIndex, GPIO_Type * portBase ) +void GPIO_Main_IRQHandler(int portIndex, GPIO_Type *portBase) { - BaseType_t xHigherPriorityTaskWoken = pdFALSE; - // Get interrupting pins - uint32_t intPins = GPIO_PortGetInterruptFlags(portBase); + BaseType_t xHigherPriorityTaskWoken = pdFALSE; + // Get interrupting pins + uint32_t intPins = GPIO_PortGetInterruptFlags(portBase); - // clear the interrupt status + // clear the interrupt status GPIO_PortClearInterruptFlags(portBase, intPins); - if (portIndex % 2) - { - // use the upper 16 bits for odd ports - intPins >>= 16; - } - else - { - // use the lower 16 bits for even ports - intPins &= 0xFFFF; - } - - // This port been initialised ? - statePortArray * inputStates = port_array[portIndex]; - if ( inputStates ) - { - uint32_t bitNumber = 0; - - // Handle all pins with pending interrupt - while(intPins) - { - if ( intPins & 0x01 ) - { - // Interupt on pin ? - gpio_input_state * pGpio = (*inputStates)[bitNumber]; - // Do we have gpio_input_state setup for this pin ? - if (pGpio) - { - // Ignore any pin changes during debounce - if (!pGpio->waitingDebounce) - { - // If user ISR available then call it - if (pGpio->isrPtr) - { - // If debounce timer defined then first wait for it to expire - if (pGpio->debounceMs > 0) - { - pGpio->waitingDebounce = true; - - // Start Debounce timer - xTimerChangePeriodFromISR(pGpio->debounceTimer, pdMS_TO_TICKS(pGpio->debounceMs), &xHigherPriorityTaskWoken); - } - else - { - GpioPinValue PinState = (GpioPinValue)GPIO_PinRead(GPIO_BASE(pGpio->pinNumber), GPIO_PIN(pGpio->pinNumber)); - pGpio->isrPtr(pGpio->pinNumber, PinState, pGpio->param); - } - } - } - } // if pin setup in nanoFramework - } // if interrupt - - intPins>>=1; - bitNumber++; - } // while - } - - portYIELD_FROM_ISR( xHigherPriorityTaskWoken ); + if (portIndex % 2) + { + // use the upper 16 bits for odd ports + intPins >>= 16; + } + else + { + // use the lower 16 bits for even ports + intPins &= 0xFFFF; + } + + // This port been initialised ? + statePortArray *inputStates = port_array[portIndex]; + if (inputStates) + { + uint32_t bitNumber = 0; + + // Handle all pins with pending interrupt + while (intPins) + { + if (intPins & 0x01) + { + // Interupt on pin ? + gpio_input_state *pState = (*inputStates)[bitNumber]; + + // Do we have gpio_input_state setup for this pin ? + if (pState) + { + // Ignore any pin changes during debounce + if (!pState->waitingDebounce) + { + // If debounce timer defined then first wait for it to expire + if (pState->debounceMs > 0) + { + pState->waitingDebounce = true; + + // Start Debounce timer + xTimerChangePeriodFromISR( + pState->debounceTimer, + pdMS_TO_TICKS(pState->debounceMs), + &xHigherPriorityTaskWoken); + } + else + { + GpioPinValue PinState = + (GpioPinValue)GPIO_PinRead(GPIO_BASE(pState->pinNumber), GPIO_PIN(pState->pinNumber)); + pState->isrPtr(pState->pinNumber, PinState); + } + } + } // if pin setup in nanoFramework + } // if interrupt + + intPins >>= 1; + bitNumber++; + } // while + } + + portYIELD_FROM_ISR(xHigherPriorityTaskWoken); // Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping - // exception return operation might vector to incorrect interrupt + // exception return operation might vector to incorrect interrupt #if defined __CORTEX_M && (__CORTEX_M == 4U) __DSB(); #endif @@ -145,205 +144,209 @@ void GPIO_Main_IRQHandler( int portIndex, GPIO_Type * portBase ) extern "C" { -// Gpio ISR handler for GPIO port 1 bits 0-15 -void GPIO1_Combined_0_15_IRQHandler(void) -{ - GPIO_Main_IRQHandler( 0, GPIO1 ); -} -// Gpio ISR handler for GPIO port 1 bits 16-31 -void GPIO1_Combined_16_31_IRQHandler(void) -{ - GPIO_Main_IRQHandler( 1, GPIO1 ); -} -// Gpio ISR handler for GPIO port 2 bits 0-15 -void GPIO2_Combined_0_15_IRQHandler(void) -{ - GPIO_Main_IRQHandler( 2, GPIO2 ); -} -// Gpio ISR handler for GPIO port 2 bits 16-31 - -// TODO: this handler is used to sdcard detect -// void GPIO2_Combined_16_31_IRQHandler(void) -// { -// GPIO_Main_IRQHandler( 3, GPIO2 ); -// } -// Gpio ISR handler for GPIO port 3 bits 0-15 -void GPIO3_Combined_0_15_IRQHandler(void) -{ - GPIO_Main_IRQHandler( 4, GPIO3 ); -} -// Gpio ISR handler for GPIO port 3 bits 16-31 -void GPIO3_Combined_16_31_IRQHandler(void) -{ - GPIO_Main_IRQHandler( 5, GPIO3 ); -} -// Gpio ISR handler for GPIO port 4 bits 0-15 -void GPIO4_Combined_0_15_IRQHandler(void) -{ - GPIO_Main_IRQHandler( 6, GPIO4 ); -} -// Gpio ISR handler for GPIO port 4 bits 16-31 -void GPIO4_Combined_16_31_IRQHandler(void) -{ - GPIO_Main_IRQHandler( 7, GPIO4 ); -} -// Gpio ISR handler for GPIO port 5 bits 0-15 -void GPIO5_Combined_0_15_IRQHandler(void) -{ - GPIO_Main_IRQHandler( 8, GPIO5 ); -} -// Gpio ISR handler for GPIO port 5 bits 16-31 -void GPIO5_Combined_16_31_IRQHandler(void) -{ - GPIO_Main_IRQHandler( 9, GPIO5 ); -} + // Gpio ISR handler for GPIO port 1 bits 0-15 + void GPIO1_Combined_0_15_IRQHandler(void) + { + GPIO_Main_IRQHandler(0, GPIO1); + } + // Gpio ISR handler for GPIO port 1 bits 16-31 + void GPIO1_Combined_16_31_IRQHandler(void) + { + GPIO_Main_IRQHandler(1, GPIO1); + } + // Gpio ISR handler for GPIO port 2 bits 0-15 + void GPIO2_Combined_0_15_IRQHandler(void) + { + GPIO_Main_IRQHandler(2, GPIO2); + } + // Gpio ISR handler for GPIO port 2 bits 16-31 + + // TODO: this handler is used to sdcard detect + // void GPIO2_Combined_16_31_IRQHandler(void) + // { + // GPIO_Main_IRQHandler( 3, GPIO2 ); + // } + // Gpio ISR handler for GPIO port 3 bits 0-15 + void GPIO3_Combined_0_15_IRQHandler(void) + { + GPIO_Main_IRQHandler(4, GPIO3); + } + // Gpio ISR handler for GPIO port 3 bits 16-31 + void GPIO3_Combined_16_31_IRQHandler(void) + { + GPIO_Main_IRQHandler(5, GPIO3); + } + // Gpio ISR handler for GPIO port 4 bits 0-15 + void GPIO4_Combined_0_15_IRQHandler(void) + { + GPIO_Main_IRQHandler(6, GPIO4); + } + // Gpio ISR handler for GPIO port 4 bits 16-31 + void GPIO4_Combined_16_31_IRQHandler(void) + { + GPIO_Main_IRQHandler(7, GPIO4); + } + // Gpio ISR handler for GPIO port 5 bits 0-15 + void GPIO5_Combined_0_15_IRQHandler(void) + { + GPIO_Main_IRQHandler(8, GPIO5); + } + // Gpio ISR handler for GPIO port 5 bits 16-31 + void GPIO5_Combined_16_31_IRQHandler(void) + { + GPIO_Main_IRQHandler(9, GPIO5); + } } // Get pointer to gpio_input_state for Gpio pin // return NULL if not found -gpio_input_state * GetInputState(GPIO_PIN pinNumber ) +gpio_input_state *GetInputState(GPIO_PIN pinNumber) { - int port = GetIoPort(pinNumber); - int bit = GetIoBit(pinNumber); + int port = GetIoPort(pinNumber); + int bit = GetIoBit(pinNumber); - if ( port_array[port] == NULL) return NULL; + if (port_array[port] == NULL) + return NULL; - statePortArray * inputStates = port_array[port]; - return *inputStates[bit]; + statePortArray *inputStates = port_array[port]; + return *inputStates[bit]; } // Allocate a new gpio_input_state and add to end of list // if already exist then just return current ptr -gpio_input_state * AllocateGpioInputState(GPIO_PIN pinNumber) +gpio_input_state *AllocateGpioInputState(GPIO_PIN pinNumber) { - int port = GetIoPort(pinNumber); - int bit = GetIoBit(pinNumber); - - if ( port_array[port] == NULL) - { - port_array[port] = (statePortArray*)platform_malloc(sizeof(statePortArray)); - if (port_array[port] == NULL ) return NULL; - - memset(port_array[port], 0, sizeof(statePortArray) ); - } - - statePortArray * inputStates = port_array[port]; - - gpio_input_state * pGpio = (*inputStates)[bit]; - if (pGpio == NULL) - { - pGpio = (gpio_input_state *)platform_malloc(sizeof(gpio_input_state)); - memset(pGpio, 0, sizeof(gpio_input_state)); - pGpio->pinNumber = pinNumber; - (*inputStates)[bit] = pGpio; - } - return pGpio; + int port = GetIoPort(pinNumber); + int bit = GetIoBit(pinNumber); + + if (port_array[port] == NULL) + { + port_array[port] = (statePortArray *)platform_malloc(sizeof(statePortArray)); + if (port_array[port] == NULL) + return NULL; + + memset(port_array[port], 0, sizeof(statePortArray)); + } + + statePortArray *inputStates = port_array[port]; + + gpio_input_state *pState = (*inputStates)[bit]; + if (pState == NULL) + { + pState = (gpio_input_state *)platform_malloc(sizeof(gpio_input_state)); + memset(pState, 0, sizeof(gpio_input_state)); + pState->pinNumber = pinNumber; + (*inputStates)[bit] = pState; + } + return pState; } // Delete gpio_input_state from List and tidy up ( Timer & ISR handler ) void DeleteInputState(GPIO_PIN pinNumber) { - int port = GetIoPort(pinNumber); - int bit = GetIoBit(pinNumber); - - statePortArray* inputStates = port_array[port]; - if ( inputStates == NULL ) return; - - gpio_input_state * pGpio = (*inputStates)[bit]; - if (pGpio) - { - if (pGpio->debounceTimer != 0) - { - xTimerDelete(pGpio->debounceTimer, 100); - } - - // Remove interrupt associatted with pin - gpio_pin_config_t config = {kGPIO_DigitalInput, 0, kGPIO_NoIntmode }; - GPIO_PinInit(GPIO_BASE(pinNumber), GPIO_PIN(pinNumber), &config); - - platform_free(pGpio); - (*inputStates)[bit] = NULL; - } + int port = GetIoPort(pinNumber); + int bit = GetIoBit(pinNumber); + + statePortArray *inputStates = port_array[port]; + if (inputStates == NULL) + return; + + gpio_input_state *pState = (*inputStates)[bit]; + if (pState) + { + if (pState->debounceTimer != 0) + { + xTimerDelete(pState->debounceTimer, 100); + } + + // Remove interrupt associatted with pin + gpio_pin_config_t config = {kGPIO_DigitalInput, 0, kGPIO_NoIntmode}; + GPIO_PinInit(GPIO_BASE(pinNumber), GPIO_PIN(pinNumber), &config); + + platform_free(pState); + (*inputStates)[bit] = NULL; + } } - -bool CPU_GPIO_Initialize() +bool CPU_GPIO_Initialize() { - // All port ptrs are null - memset(port_array, 0, sizeof(port_array)); + // All port ptrs are null + memset(port_array, 0, sizeof(port_array)); + + // Make sure all pins are not reserved + memset(pinReserved, 0, sizeof(pinReserved)); - // Make sure all pins are not reserved - memset(pinReserved, 0, sizeof(pinReserved)); - - return true; + return true; } -bool CPU_GPIO_Uninitialize() +bool CPU_GPIO_Uninitialize() { - // First remove any active pin states - for(int pinNumber=0; pinNumber < GPIO_MAX_PINS; pinNumber++) - { - DeleteInputState(pinNumber); - } - - // Remove statePortArray if any - for(int port=0; port < TOTAL_GPIO_PORTS; port++) - { - statePortArray* inputStates = port_array[port]; - if ( inputStates != NULL ) - { - platform_free(port_array[port]); // free up inputStates array - port_array[port] = NULL; - } - } - - return true; + // First remove any active pin states + for (int pinNumber = 0; pinNumber < GPIO_MAX_PINS; pinNumber++) + { + DeleteInputState(pinNumber); + } + + // Remove statePortArray if any + for (int port = 0; port < TOTAL_GPIO_PORTS; port++) + { + statePortArray *inputStates = port_array[port]; + if (inputStates != NULL) + { + platform_free(port_array[port]); // free up inputStates array + port_array[port] = NULL; + } + } + + return true; } // Set/reset reserved state of pin -bool CPU_GPIO_ReservePin(GPIO_PIN pinNumber, bool fReserve) +bool CPU_GPIO_ReservePin(GPIO_PIN pinNumber, bool fReserve) { - // Check if valid pin number - if (!IsValidGpioPin(pinNumber)) return false; - - int port = pinNumber >> 4; - int bit = 1 << (pinNumber & 0x0F); - - GLOBAL_LOCK(); - - if (fReserve) - { - if (pinReserved[port] & bit) - { - GLOBAL_UNLOCK(); - return false; // already reserved - } - - pinReserved[port] |= bit; - } - else - { - pinReserved[port] &= ~bit; - } - - GLOBAL_UNLOCK(); - return true; + // Check if valid pin number + if (!IsValidGpioPin(pinNumber)) + return false; + + int port = pinNumber >> 4; + int bit = 1 << (pinNumber & 0x0F); + + GLOBAL_LOCK(); + + if (fReserve) + { + if (pinReserved[port] & bit) + { + GLOBAL_UNLOCK(); + return false; // already reserved + } + + pinReserved[port] |= bit; + } + else + { + pinReserved[port] &= ~bit; + } + + GLOBAL_UNLOCK(); + return true; } // Return if Pin is reserved bool CPU_GPIO_PinIsBusy(GPIO_PIN pinNumber) { - // Check if valid pin number - if (!IsValidGpioPin(pinNumber)) return false; + // Check if valid pin number + if (!IsValidGpioPin(pinNumber)) + return false; - int port = pinNumber >> 4, sh = pinNumber & 0x0F; - return (pinReserved[port] >> sh) & 1; + int port = pinNumber >> 4, sh = pinNumber & 0x0F; + return (pinReserved[port] >> sh) & 1; } // Return maximum number of pins int32_t CPU_GPIO_GetPinCount() { - return GPIO_MAX_PINS; + return GPIO_MAX_PINS; } // Get current state of pin @@ -361,78 +364,98 @@ void CPU_GPIO_SetPinState(GPIO_PIN pinNumber, GpioPinValue PinState) // Toggle pin state void CPU_GPIO_TogglePinState(GPIO_PIN pinNumber) { - GPIO_PortToggle(GPIO_BASE(pinNumber), 0x1u << GPIO_PIN(pinNumber)); + GPIO_PortToggle(GPIO_BASE(pinNumber), 0x1u << GPIO_PIN(pinNumber)); } // // CPU_GPIO_EnableInputPin // Enable input pin // -bool CPU_GPIO_EnableInputPin(GPIO_PIN pinNumber, CLR_UINT64 debounceTimeMilliseconds, GPIO_INTERRUPT_SERVICE_ROUTINE pin_ISR, void* isr_Param, GPIO_INT_EDGE intEdge, GpioPinDriveMode driveMode) +bool CPU_GPIO_EnableInputPin( + GPIO_PIN pinNumber, + CLR_UINT64 debounceTimeMilliseconds, + GPIO_INTERRUPT_SERVICE_ROUTINE pinISR, + void *isrParam, + GPIO_INT_EDGE intEdge, + GpioPinDriveMode driveMode) { - gpio_input_state * pGpio; - - // Check if valid pin number - if (!IsValidGpioPin(pinNumber)) return false; - - // Check Input drive mode - if (driveMode >= (int)GpioPinDriveMode_Output) - return false; - - if (!CPU_GPIO_SetDriveMode(pinNumber, driveMode)) - return false; - - pGpio = AllocateGpioInputState(pinNumber); - - // Map nanoFRamework Interrupt edge to NXP edge - // NONE=0, EDGE_LOW=1, EDGE_HIGH=2, EDGE_BOTH=3, LEVEL_HIGH=4, LEVEL_LOW - const gpio_interrupt_mode_t mapint[6] = { kGPIO_NoIntmode, kGPIO_IntFallingEdge, kGPIO_IntRisingEdge, kGPIO_IntRisingOrFallingEdge, kGPIO_IntHighLevel, kGPIO_IntLowLevel }; - - // enable interupt mode with correct edge - gpio_pin_config_t config = {kGPIO_DigitalInput, 0, mapint[intEdge] }; - GPIO_PinInit(GPIO_BASE(pinNumber), GPIO_PIN(pinNumber), &config); - - // Enable GPIO pin interrupt - IRQn_Type isrNo = (IRQn_Type)(GPIO1_Combined_0_15_IRQn + GetIoPort(pinNumber)); - NVIC_SetPriority(isrNo, 8U); - EnableIRQ(isrNo); - GPIO_PortEnableInterrupts(GPIO_BASE(pinNumber), 1U << GetIoBit(pinNumber)); - GPIO_PortClearInterruptFlags(GPIO_BASE(pinNumber), 1U << GetIoBit(pinNumber)); - - // Initialise Gpio state structure - pGpio->isrPtr = pin_ISR; - pGpio->mode = intEdge; - pGpio->param = (void *)isr_Param; - pGpio->debounceMs = (uint32_t)(debounceTimeMilliseconds); - - // Set up expected new value for debounce - if ( pGpio->debounceMs > 0) - { - if (pGpio->debounceTimer == 0) - { - // Create timer if it doesn't already exist for this pin - pGpio->debounceTimer = xTimerCreate("debounce", 100, pdFALSE, (void*)pGpio, Gpio_DebounceHandler); - } - switch (intEdge) - { - case GPIO_INT_NONE: - case GPIO_INT_EDGE_LOW: - case GPIO_INT_LEVEL_LOW: - pGpio->expected = false; - break; - - case GPIO_INT_EDGE_HIGH: - case GPIO_INT_LEVEL_HIGH: - pGpio->expected = true; - break; - - case GPIO_INT_EDGE_BOTH: - pGpio->expected = !CPU_GPIO_GetPinState(pinNumber); // Use NOT current state - break; - } - } - - return true; + gpio_input_state *pState; + + // Check if valid pin number + if (!IsValidGpioPin(pinNumber)) + return false; + + // Check Input drive mode + if (driveMode >= (int)GpioPinDriveMode_Output) + return false; + + if (!CPU_GPIO_SetDriveMode(pinNumber, driveMode)) + return false; + + pState = AllocateGpioInputState(pinNumber); + + if (pinISR != NULL && (pState->isrPtr == NULL)) + { + // enable interupt mode with correct edge + gpio_pin_config_t config = {kGPIO_DigitalInput, 0, kGPIO_IntRisingOrFallingEdge}; + GPIO_PinInit(GPIO_BASE(pinNumber), GPIO_PIN(pinNumber), &config); + + // Enable GPIO pin interrupt + IRQn_Type isrNo = (IRQn_Type)(GPIO1_Combined_0_15_IRQn + GetIoPort(pinNumber)); + NVIC_SetPriority(isrNo, 8U); + EnableIRQ(isrNo); + GPIO_PortEnableInterrupts(GPIO_BASE(pinNumber), 1U << GetIoBit(pinNumber)); + GPIO_PortClearInterruptFlags(GPIO_BASE(pinNumber), 1U << GetIoBit(pinNumber)); + + // store parameters & configs + pState->isrPtr = pinISR; + pState->mode = intEdge; + pState->param = (void *)isrParam; + pState->debounceMs = (uint32_t)(debounceTimeMilliseconds); + + // Set up expected new value for debounce + if (pState->debounceMs > 0) + { + if (pState->debounceTimer == 0) + { + // Create timer if it doesn't already exist for this pin + pState->debounceTimer = xTimerCreate("debounce", 100, pdFALSE, (void *)pState, Gpio_DebounceHandler); + } + switch (intEdge) + { + case GPIO_INT_NONE: + case GPIO_INT_EDGE_LOW: + case GPIO_INT_LEVEL_LOW: + pState->expected = false; + break; + + case GPIO_INT_EDGE_HIGH: + case GPIO_INT_LEVEL_HIGH: + pState->expected = true; + break; + + case GPIO_INT_EDGE_BOTH: + pState->expected = !CPU_GPIO_GetPinState(pinNumber); // Use NOT current state + break; + } + } + } + else if (pinISR == NULL && (pState->isrPtr != NULL)) + { + // there is no managed handler setup anymore + // remove INT handler + + // disable interrupt + GPIO_PortDisableInterrupts(GPIO_BASE(pinNumber), 1U << GetIoBit(pinNumber)); + + // clear parameters & configs + pState->isrPtr = NULL; + pState->mode = GPIO_INT_NONE; + pState->param = NULL; + pState->debounceMs = 0; + } + + return true; } // Enable an output pin @@ -442,135 +465,137 @@ bool CPU_GPIO_EnableInputPin(GPIO_PIN pinNumber, CLR_UINT64 debounceTimeMillisec // driveMode - Drive mode and resistors // return - True if succesful, false invalid pin, pin not putput, invalid drive mode for ouptput // -bool CPU_GPIO_EnableOutputPin(GPIO_PIN pinNumber, GpioPinValue InitialState, GpioPinDriveMode driveMode) +bool CPU_GPIO_EnableOutputPin(GPIO_PIN pinNumber, GpioPinValue InitialState, GpioPinDriveMode driveMode) { - // Check if valid pin number - if (!IsValidGpioPin(pinNumber)) return false; + // Check if valid pin number + if (!IsValidGpioPin(pinNumber)) + return false; - // check is output drive mode - if (driveMode < (int)GpioPinDriveMode_Output) return false; + // check is output drive mode + if (driveMode < (int)GpioPinDriveMode_Output) + return false; - if (CPU_GPIO_SetDriveMode(pinNumber, driveMode) == false) return false; + if (CPU_GPIO_SetDriveMode(pinNumber, driveMode) == false) + return false; - CPU_GPIO_SetPinState(pinNumber, InitialState); + CPU_GPIO_SetPinState(pinNumber, InitialState); - return true; + return true; } void CPU_GPIO_DisablePin(GPIO_PIN pinNumber, GpioPinDriveMode driveMode, uint32_t alternateFunction) { - GLOBAL_LOCK(); + GLOBAL_LOCK(); - CPU_GPIO_SetDriveMode(pinNumber, driveMode); + CPU_GPIO_SetDriveMode(pinNumber, driveMode); - DeleteInputState(pinNumber); - - if (alternateFunction) - { + DeleteInputState(pinNumber); + + if (alternateFunction) + { GPIO_PinMux(GPIO_PORT(pinNumber), GPIO_PIN(pinNumber), alternateFunction); - } + } - GLOBAL_UNLOCK(); + GLOBAL_UNLOCK(); - CPU_GPIO_ReservePin(pinNumber, false); + CPU_GPIO_ReservePin(pinNumber, false); } - // Validate pin and set drive mode // return true if ok bool CPU_GPIO_SetDriveMode(GPIO_PIN pinNumber, GpioPinDriveMode driveMode) { - // Check if valid pin number - if (!IsValidGpioPin(pinNumber)) return false; - - gpio_pin_direction_t direction; - uint32_t pinConfig; - - switch (driveMode) - { - case GpioPinDriveMode_Input: - direction = kGPIO_DigitalInput; - pinConfig = GPIO_IO; - break; - - case GpioPinDriveMode_InputPullDown: - direction = kGPIO_DigitalInput; - pinConfig = GPIO_IN_PULLDOWN; - break; - - case GpioPinDriveMode_InputPullUp: - direction = kGPIO_DigitalInput; - pinConfig = GPIO_IN_PULLUP; - break; - - case GpioPinDriveMode_Output: - direction = kGPIO_DigitalOutput; - pinConfig = GPIO_IO; - break; - - case GpioPinDriveMode_OutputOpenDrain: - direction = kGPIO_DigitalOutput; - pinConfig = GPIO_OUT_OPENDRAIN; - break; - - default: - // all other modes are NOT supported - return false; - } - - gpio_pin_config_t config = {direction, 0, kGPIO_NoIntmode}; - - GPIO_PinMux(GPIO_PORT(pinNumber), GPIO_PIN(pinNumber), 0x5u); - GPIO_PinConfig(GPIO_PORT(pinNumber), GPIO_PIN(pinNumber), pinConfig); - GPIO_PinInit(GPIO_BASE(pinNumber), GPIO_PIN(pinNumber), &config); - - return true; + // Check if valid pin number + if (!IsValidGpioPin(pinNumber)) + return false; + + gpio_pin_direction_t direction; + uint32_t pinConfig; + + switch (driveMode) + { + case GpioPinDriveMode_Input: + direction = kGPIO_DigitalInput; + pinConfig = GPIO_IO; + break; + + case GpioPinDriveMode_InputPullDown: + direction = kGPIO_DigitalInput; + pinConfig = GPIO_IN_PULLDOWN; + break; + + case GpioPinDriveMode_InputPullUp: + direction = kGPIO_DigitalInput; + pinConfig = GPIO_IN_PULLUP; + break; + + case GpioPinDriveMode_Output: + direction = kGPIO_DigitalOutput; + pinConfig = GPIO_IO; + break; + + case GpioPinDriveMode_OutputOpenDrain: + direction = kGPIO_DigitalOutput; + pinConfig = GPIO_OUT_OPENDRAIN; + break; + + default: + // all other modes are NOT supported + return false; + } + + gpio_pin_config_t config = {direction, 0, kGPIO_NoIntmode}; + + GPIO_PinMux(GPIO_PORT(pinNumber), GPIO_PIN(pinNumber), 0x5u); + GPIO_PinConfig(GPIO_PORT(pinNumber), GPIO_PIN(pinNumber), pinConfig); + GPIO_PinInit(GPIO_BASE(pinNumber), GPIO_PIN(pinNumber), &config); + + return true; } bool CPU_GPIO_DriveModeSupported(GPIO_PIN pinNumber, GpioPinDriveMode driveMode) { - // Check if valid pin number - if (!IsValidGpioPin(pinNumber)) return false; - - bool driveModeSupported = false; - - // check if the requested drive mode is supported - if ((driveMode == GpioPinDriveMode_Input) || - (driveMode == GpioPinDriveMode_InputPullDown) || - (driveMode == GpioPinDriveMode_InputPullUp) || - (driveMode == GpioPinDriveMode_Output) || - (driveMode == GpioPinDriveMode_OutputOpenDrain)) - { - driveModeSupported = true; - } - - return driveModeSupported; + // Check if valid pin number + if (!IsValidGpioPin(pinNumber)) + return false; + + bool driveModeSupported = false; + + // check if the requested drive mode is supported + if ((driveMode == GpioPinDriveMode_Input) || (driveMode == GpioPinDriveMode_InputPullDown) || + (driveMode == GpioPinDriveMode_InputPullUp) || (driveMode == GpioPinDriveMode_Output) || + (driveMode == GpioPinDriveMode_OutputOpenDrain)) + { + driveModeSupported = true; + } + + return driveModeSupported; } uint32_t CPU_GPIO_GetPinDebounce(GPIO_PIN pinNumber) { - // Check if valid pin number - if (IsValidGpioPin(pinNumber)) - { - gpio_input_state * ptr = GetInputState(pinNumber); - if (ptr) - return ptr->debounceMs; - } - - return 0; + // Check if valid pin number + if (IsValidGpioPin(pinNumber)) + { + gpio_input_state *ptr = GetInputState(pinNumber); + if (ptr) + return ptr->debounceMs; + } + + return 0; } bool CPU_GPIO_SetPinDebounce(GPIO_PIN pinNumber, CLR_UINT64 debounceTimeMilliseconds) { - // Check if valid pin number - if (IsValidGpioPin(pinNumber)) - { - gpio_input_state * ptr = GetInputState(pinNumber); - if (ptr) - { - ptr->debounceMs = (uint32_t)(debounceTimeMilliseconds); - return true; - } - } - return false; + // Check if valid pin number + if (IsValidGpioPin(pinNumber)) + { + gpio_input_state *ptr = GetInputState(pinNumber); + if (ptr) + { + ptr->debounceMs = (uint32_t)(debounceTimeMilliseconds); + return true; + } + } + return false; } diff --git a/targets/FreeRTOS/NXP/nanoCLR/Windows.Devices.Gpio/win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter.cpp b/targets/FreeRTOS/NXP/nanoCLR/Windows.Devices.Gpio/win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter.cpp index 8873f80938..ffa0fab8ff 100644 --- a/targets/FreeRTOS/NXP/nanoCLR/Windows.Devices.Gpio/win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter.cpp +++ b/targets/FreeRTOS/NXP/nanoCLR/Windows.Devices.Gpio/win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/nanoCLR/Windows.Devices.Gpio/win_dev_gpio_native_target.h b/targets/FreeRTOS/NXP/nanoCLR/Windows.Devices.Gpio/win_dev_gpio_native_target.h index 3f6a77b94e..1883d1db7f 100644 --- a/targets/FreeRTOS/NXP/nanoCLR/Windows.Devices.Gpio/win_dev_gpio_native_target.h +++ b/targets/FreeRTOS/NXP/nanoCLR/Windows.Devices.Gpio/win_dev_gpio_native_target.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/nanoCLR/Windows.Devices.I2c/win_dev_i2c_native_Windows_Devices_I2C_I2cDevice.cpp b/targets/FreeRTOS/NXP/nanoCLR/Windows.Devices.I2c/win_dev_i2c_native_Windows_Devices_I2C_I2cDevice.cpp index 453be2d160..aef413aef0 100644 --- a/targets/FreeRTOS/NXP/nanoCLR/Windows.Devices.I2c/win_dev_i2c_native_Windows_Devices_I2C_I2cDevice.cpp +++ b/targets/FreeRTOS/NXP/nanoCLR/Windows.Devices.I2c/win_dev_i2c_native_Windows_Devices_I2C_I2cDevice.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/nanoCLR/Windows.Devices.I2c/win_dev_i2c_native_Windows_Devices_I2c_I2cController.cpp b/targets/FreeRTOS/NXP/nanoCLR/Windows.Devices.I2c/win_dev_i2c_native_Windows_Devices_I2c_I2cController.cpp index 8e1f64dfeb..d7c0266917 100644 --- a/targets/FreeRTOS/NXP/nanoCLR/Windows.Devices.I2c/win_dev_i2c_native_Windows_Devices_I2c_I2cController.cpp +++ b/targets/FreeRTOS/NXP/nanoCLR/Windows.Devices.I2c/win_dev_i2c_native_Windows_Devices_I2c_I2cController.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/nanoCLR/Windows.Devices.I2c/win_dev_i2c_native_target.h b/targets/FreeRTOS/NXP/nanoCLR/Windows.Devices.I2c/win_dev_i2c_native_target.h index 175e4cbd7e..3ba97e0ff3 100644 --- a/targets/FreeRTOS/NXP/nanoCLR/Windows.Devices.I2c/win_dev_i2c_native_target.h +++ b/targets/FreeRTOS/NXP/nanoCLR/Windows.Devices.I2c/win_dev_i2c_native_target.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/nanoCLR/Windows.Devices.SerialCommunication/win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice.cpp b/targets/FreeRTOS/NXP/nanoCLR/Windows.Devices.SerialCommunication/win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice.cpp index 98828376a7..6c8c5eb637 100644 --- a/targets/FreeRTOS/NXP/nanoCLR/Windows.Devices.SerialCommunication/win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice.cpp +++ b/targets/FreeRTOS/NXP/nanoCLR/Windows.Devices.SerialCommunication/win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // @@ -11,740 +11,800 @@ static LPUART_Type *const lpuart_bases[] = LPUART_BASE_PTRS; -// Static UART config/data structs. +// Static UART config/data structs. static NF_PAL_UART Uart_PAL1, Uart_PAL2, Uart_PAL3, Uart_PAL4, Uart_PAL5, Uart_PAL6, Uart_PAL7, Uart_PAL8; -// Array of pointers to above config UART structs. -NF_PAL_UART *const Uart_PAL[]{NULL, &Uart_PAL1, &Uart_PAL2, &Uart_PAL3, &Uart_PAL4, &Uart_PAL5, &Uart_PAL6, &Uart_PAL7, &Uart_PAL8}; +// Array of pointers to above config UART structs. +NF_PAL_UART *const + Uart_PAL[]{NULL, &Uart_PAL1, &Uart_PAL2, &Uart_PAL3, &Uart_PAL4, &Uart_PAL5, &Uart_PAL6, &Uart_PAL7, &Uart_PAL8}; -// Task firing up event after receiving wanted amount of bytes +// Task firing up event after receiving wanted amount of bytes static void vREvent(void *pvParameters) { - // This is main UART struct, holding config, handlers, and the rest of variables.d - (void)pvParameters; - uint32_t ulNotifiedValue; - - while (1) - { - xTaskNotifyWait(pdFALSE, // Don't clear bits on entry. - 0xffffffff, // Clear all bits on exit. - &ulNotifiedValue, // Stores the notified value. - portMAX_DELAY); - - // Check is there event from task reading bytes. - if ((ulNotifiedValue & 0x02) != 0) + // This is main UART struct, holding config, handlers, and the rest of variables.d + (void)pvParameters; + uint32_t ulNotifiedValue; + + while (1) { - Events_Set(SYSTEM_EVENT_FLAG_COM_IN); + xTaskNotifyWait( + pdFALSE, // Don't clear bits on entry. + 0xffffffff, // Clear all bits on exit. + &ulNotifiedValue, // Stores the notified value. + portMAX_DELAY); + + // Check is there event from task reading bytes. + if ((ulNotifiedValue & 0x02) != 0) + { + Events_Set(SYSTEM_EVENT_FLAG_COM_IN); + } } - } } -// Task for transmitting data through blocking uart -static void vWEvent(void *pvParameters) +// Task for transmitting data through blocking uart +static void vWEvent(void *pvParameters) { - uint32_t ulNotifiedValue; - uint8_t *uartNum_p = (uint8_t *)pvParameters; - uint8_t uartNum = *uartNum_p; - NF_PAL_UART *palUart = Uart_PAL[uartNum]; - - while (1) - { - xTaskNotifyWait(pdFALSE, // Don't clear bits on entry. - 0xffffffff, // Clear all bits on exit. - &ulNotifiedValue, // Stores the notified value. - portMAX_DELAY); - - if ((ulNotifiedValue & 0x01) != 0) + uint32_t ulNotifiedValue; + uint8_t *uartNum_p = (uint8_t *)pvParameters; + uint8_t uartNum = *uartNum_p; + NF_PAL_UART *palUart = Uart_PAL[uartNum]; + + while (1) { - LPUART_WriteBlocking(lpuart_bases[uartNum], palUart->xfer.data, palUart->xfer.dataSize); - Events_Set(SYSTEM_EVENT_FLAG_COM_OUT); + xTaskNotifyWait( + pdFALSE, // Don't clear bits on entry. + 0xffffffff, // Clear all bits on exit. + &ulNotifiedValue, // Stores the notified value. + portMAX_DELAY); + + if ((ulNotifiedValue & 0x01) != 0) + { + LPUART_WriteBlocking(lpuart_bases[uartNum], palUart->xfer.data, palUart->xfer.dataSize); + Events_Set(SYSTEM_EVENT_FLAG_COM_OUT); + } } - } } -static void UART_Handle(LPUART_Type *base, uint8_t uartNum) +static void UART_Handle(LPUART_Type *base, uint8_t uartNum) { - NATIVE_INTERRUPT_START - uint32_t status; - BaseType_t xHigherPriorityTaskWoken = pdFALSE; - NF_PAL_UART *palUart = Uart_PAL[uartNum]; - - status = LPUART_GetStatusFlags(base); + NATIVE_INTERRUPT_START + uint32_t status; + BaseType_t xHigherPriorityTaskWoken = pdFALSE; + NF_PAL_UART *palUart = Uart_PAL[uartNum]; - if (kLPUART_RxOverrunFlag & status) - { + status = LPUART_GetStatusFlags(base); - // Clear overrun flag, otherwise the RX does not work. - base->STAT |= 1U << LPUART_STAT_OR_SHIFT; - } + if (kLPUART_RxOverrunFlag & status) + { - if (kLPUART_RxDataRegFullFlag & status) - { - char byte = LPUART_ReadByte(base); - // push char to ring buffer - // don't care about the success of the operation, if it's full we are droping the char anyway - palUart->RxRingBuffer.Push((uint8_t)byte); + // Clear overrun flag, otherwise the RX does not work. + base->STAT |= 1U << LPUART_STAT_OR_SHIFT; + } - // is there a read operation going on? - if (palUart->RxBytesToRead > 0) + if (kLPUART_RxDataRegFullFlag & status) { - // check if the requested bytes are available in the buffer - if (palUart->RxRingBuffer.Length() >= palUart->RxBytesToRead) - { - // reset Rx bytes to read count - palUart->RxBytesToRead = 0; + char byte = LPUART_ReadByte(base); + // push char to ring buffer + // don't care about the success of the operation, if it's full we are droping the char anyway + palUart->RxRingBuffer.Push((uint8_t)byte); + + // is there a read operation going on? + if (palUart->RxBytesToRead > 0) + { + // check if the requested bytes are available in the buffer + if (palUart->RxRingBuffer.Length() >= palUart->RxBytesToRead) + { + // reset Rx bytes to read count + palUart->RxBytesToRead = 0; - // Notify task that we want to receive data. - xTaskNotifyFromISR(palUart->xRTaskToNotify, 0x02, eSetBits, &xHigherPriorityTaskWoken); - } + // Notify task that we want to receive data. + xTaskNotifyFromISR(palUart->xRTaskToNotify, 0x02, eSetBits, &xHigherPriorityTaskWoken); + } + } } - } - portYIELD_FROM_ISR(xHigherPriorityTaskWoken); - NATIVE_INTERRUPT_END + portYIELD_FROM_ISR(xHigherPriorityTaskWoken); + NATIVE_INTERRUPT_END } // Override of the default MIMXRT1060 UART interrupt routines to simple UART_Handle function, which // reads 1 byte of input data to RTOS stream buffer, if theres buffer overflow it drops data and clears interrupts. -extern "C" +extern "C" { -// LPUART8 is currently used for debugging, disable it or will collide with debugger -// void LPUART1_IRQHandler(void) { UART_Handle(LPUART1, 1); } -void LPUART2_IRQHandler(void) { UART_Handle(LPUART2, 2); } -void LPUART3_IRQHandler(void) { UART_Handle(LPUART3, 3); } -void LPUART4_IRQHandler(void) { UART_Handle(LPUART4, 4); } -void LPUART5_IRQHandler(void) { UART_Handle(LPUART5, 5); } -void LPUART6_IRQHandler(void) { UART_Handle(LPUART6, 6); } -void LPUART7_IRQHandler(void) { UART_Handle(LPUART7, 7); } -void LPUART8_IRQHandler(void) { UART_Handle(LPUART8, 8); } + // LPUART8 is currently used for debugging, disable it or will collide with debugger + // void LPUART1_IRQHandler(void) { UART_Handle(LPUART1, 1); } + void LPUART2_IRQHandler(void) + { + UART_Handle(LPUART2, 2); + } + void LPUART3_IRQHandler(void) + { + UART_Handle(LPUART3, 3); + } + void LPUART4_IRQHandler(void) + { + UART_Handle(LPUART4, 4); + } + void LPUART5_IRQHandler(void) + { + UART_Handle(LPUART5, 5); + } + void LPUART6_IRQHandler(void) + { + UART_Handle(LPUART6, 6); + } + void LPUART7_IRQHandler(void) + { + UART_Handle(LPUART7, 7); + } + void LPUART8_IRQHandler(void) + { + UART_Handle(LPUART8, 8); + } } -// Deinitialize serial port and allocated free memory -HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::NativeDispose___VOID(CLR_RT_StackFrame &stack) +// Deinitialize serial port and allocated free memory +HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::NativeDispose___VOID( + CLR_RT_StackFrame &stack) { - NANOCLR_HEADER(); - { - CLR_RT_HeapBlock *pThis = stack.This(); - FAULT_ON_NULL(pThis); + NANOCLR_HEADER(); + { + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); - uint8_t uartNum = 0; - LPUART_Type *base = NULL; + uint8_t uartNum = 0; + LPUART_Type *base = NULL; - uartNum = pThis[FIELD___portIndex].NumericByRef().s4; - base = lpuart_bases[uartNum]; + uartNum = pThis[FIELD___portIndex].NumericByRef().s4; + base = lpuart_bases[uartNum]; - // Quit if parameters or device is invalid or out of range - if (uartNum >= (sizeof(Uart_PAL) / sizeof(Uart_PAL[0])) || base == NULL) - { - NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); - } + // Quit if parameters or device is invalid or out of range + if (uartNum >= (sizeof(Uart_PAL) / sizeof(Uart_PAL[0])) || base == NULL) + { + NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); + } - NF_PAL_UART *palUart = Uart_PAL[uartNum]; + NF_PAL_UART *palUart = Uart_PAL[uartNum]; - // Free ring buffers memory - free(palUart->TxBuffer); - free(palUart->RxBuffer); + // Free ring buffers memory + free(palUart->TxBuffer); + free(palUart->RxBuffer); - // Deinitialize device and delete FreeRTOS idle tasks - LPUART_Deinit(base); - vTaskDelete(palUart->xRTaskToNotify); - vTaskDelete(palUart->xWTaskToNotify); - } - NANOCLR_NOCLEANUP(); + // Deinitialize device and delete FreeRTOS idle tasks + LPUART_Deinit(base); + vTaskDelete(palUart->xRTaskToNotify); + vTaskDelete(palUart->xWTaskToNotify); + } + NANOCLR_NOCLEANUP(); } -// Initialise a new Serial port, allocate buffer memory and create FreeRTOS idle tasks -HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::NativeInit___VOID(CLR_RT_StackFrame &stack) +// Initialise a new Serial port, allocate buffer memory and create FreeRTOS idle tasks +HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::NativeInit___VOID( + CLR_RT_StackFrame &stack) { - NANOCLR_HEADER(); - { - CLR_RT_HeapBlock *pThis = stack.This(); - FAULT_ON_NULL(pThis); - - status_t status = 0; - uint8_t uartNum = 0; - lpuart_config_t *config = NULL; - LPUART_Type *base = NULL; - - uartNum = pThis[FIELD___portIndex].NumericByRef().s4; - config = &Uart_PAL[uartNum]->uartCfg; - base = lpuart_bases[uartNum]; - - // Quit if parameters or device is invalid or out of range - if (uartNum >= (sizeof(Uart_PAL) / sizeof(Uart_PAL[0])) || config == NULL || base == NULL) + NANOCLR_HEADER(); { - NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); - } + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); - NF_PAL_UART *palUart = Uart_PAL[uartNum]; + status_t status = 0; + uint8_t uartNum = 0; + lpuart_config_t *config = NULL; + LPUART_Type *base = NULL; - // Allocate memory for TX and RX circular buffer - palUart->TxBuffer = (uint8_t *)malloc(UART_TX_BUFER_SIZE * sizeof(uint8_t)); - if (palUart->TxBuffer == NULL) - { - NANOCLR_SET_AND_LEAVE(CLR_E_OUT_OF_MEMORY); - } + uartNum = pThis[FIELD___portIndex].NumericByRef().s4; + config = &Uart_PAL[uartNum]->uartCfg; + base = lpuart_bases[uartNum]; - palUart->RxBuffer = (uint8_t *)malloc(UART_RX_BUFER_SIZE * sizeof(uint8_t)); - if (palUart->RxBuffer == NULL) - { - free(palUart->TxBuffer); - NANOCLR_SET_AND_LEAVE(CLR_E_OUT_OF_MEMORY); - } + // Quit if parameters or device is invalid or out of range + if (uartNum >= (sizeof(Uart_PAL) / sizeof(Uart_PAL[0])) || config == NULL || base == NULL) + { + NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); + } - // Initialize TX and RX buffer - palUart->TxRingBuffer.Initialize(palUart->TxBuffer, UART_TX_BUFER_SIZE); - palUart->TxOngoingCount = 0; - palUart->WatchChar = 0; - palUart->RxRingBuffer.Initialize(palUart->RxBuffer, UART_RX_BUFER_SIZE); - palUart->RxBytesToRead = 0; + NF_PAL_UART *palUart = Uart_PAL[uartNum]; - // Get default config structure for initializing given UART peripheral and enable TX, RX - LPUART_GetDefaultConfig(config); - config->enableRx = true; - config->enableTx = true; + // Allocate memory for TX and RX circular buffer + palUart->TxBuffer = (uint8_t *)malloc(UART_TX_BUFER_SIZE * sizeof(uint8_t)); + if (palUart->TxBuffer == NULL) + { + NANOCLR_SET_AND_LEAVE(CLR_E_OUT_OF_MEMORY); + } - // FreeRTOS Task needs parameter data survive after this function finish, so write this parameter to Uart_PAL structure. - palUart->uartNum = uartNum; + palUart->RxBuffer = (uint8_t *)malloc(UART_RX_BUFER_SIZE * sizeof(uint8_t)); + if (palUart->RxBuffer == NULL) + { + free(palUart->TxBuffer); + NANOCLR_SET_AND_LEAVE(CLR_E_OUT_OF_MEMORY); + } - // Enable RX interrupts - EnableIRQ((IRQn_Type)(19 + uartNum)); - NVIC_SetPriority((IRQn_Type)(19 + uartNum), UART_INTERRUPT_PRIO); + // Initialize TX and RX buffer + palUart->TxRingBuffer.Initialize(palUart->TxBuffer, UART_TX_BUFER_SIZE); + palUart->TxOngoingCount = 0; + palUart->WatchChar = 0; + palUart->RxRingBuffer.Initialize(palUart->RxBuffer, UART_RX_BUFER_SIZE); + palUart->RxBytesToRead = 0; - // Initialize UART peripheral with default config - status = LPUART_Init(base, config, GetSrcFreq()); - if (status != kStatus_Success) - { - NANOCLR_SET_AND_LEAVE(CLR_E_IO); - } + // Get default config structure for initializing given UART peripheral and enable TX, RX + LPUART_GetDefaultConfig(config); + config->enableRx = true; + config->enableTx = true; - // Create idle task waiting for read/write. - BaseType_t xReturned = - xTaskCreate(vREvent, "UART Read Event", configMINIMAL_STACK_SIZE, (void *)palUart, configMAX_PRIORITIES - 1, &palUart->xRTaskToNotify); - if (xReturned == errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY) - { - NANOCLR_SET_AND_LEAVE(CLR_E_OUT_OF_MEMORY); - } + // FreeRTOS Task needs parameter data survive after this function finish, so write this parameter to Uart_PAL + // structure. + palUart->uartNum = uartNum; - xReturned = xTaskCreate(vWEvent, "UART Read Event", configMINIMAL_STACK_SIZE, (void *)palUart, configMAX_PRIORITIES, &palUart->xWTaskToNotify); - if (xReturned == errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY) - { - NANOCLR_SET_AND_LEAVE(CLR_E_OUT_OF_MEMORY); + // Enable RX interrupts + EnableIRQ((IRQn_Type)(19 + uartNum)); + NVIC_SetPriority((IRQn_Type)(19 + uartNum), UART_INTERRUPT_PRIO); + + // Initialize UART peripheral with default config + status = LPUART_Init(base, config, GetSrcFreq()); + if (status != kStatus_Success) + { + NANOCLR_SET_AND_LEAVE(CLR_E_IO); + } + + // Create idle task waiting for read/write. + BaseType_t xReturned = xTaskCreate( + vREvent, + "UART Read Event", + configMINIMAL_STACK_SIZE, + (void *)palUart, + configMAX_PRIORITIES - 1, + &palUart->xRTaskToNotify); + if (xReturned == errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY) + { + NANOCLR_SET_AND_LEAVE(CLR_E_OUT_OF_MEMORY); + } + + xReturned = xTaskCreate( + vWEvent, + "UART Read Event", + configMINIMAL_STACK_SIZE, + (void *)palUart, + configMAX_PRIORITIES, + &palUart->xWTaskToNotify); + if (xReturned == errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY) + { + NANOCLR_SET_AND_LEAVE(CLR_E_OUT_OF_MEMORY); + } } - } - NANOCLR_NOCLEANUP(); + NANOCLR_NOCLEANUP(); } -// Set up serial port Configuration -HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::NativeConfig___VOID(CLR_RT_StackFrame &stack) +// Set up serial port Configuration +HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::NativeConfig___VOID( + CLR_RT_StackFrame &stack) { - NANOCLR_HEADER(); - { - CLR_RT_HeapBlock *pThis = stack.This(); - FAULT_ON_NULL(pThis); + NANOCLR_HEADER(); + { + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); - status_t status = 0; - uint8_t uartNum = 0; - lpuart_config_t *config = NULL; - LPUART_Type *base = NULL; + status_t status = 0; + uint8_t uartNum = 0; + lpuart_config_t *config = NULL; + LPUART_Type *base = NULL; - uartNum = pThis[FIELD___portIndex].NumericByRef().s4; - config = &Uart_PAL[uartNum]->uartCfg; - base = lpuart_bases[uartNum]; + uartNum = pThis[FIELD___portIndex].NumericByRef().s4; + config = &Uart_PAL[uartNum]->uartCfg; + base = lpuart_bases[uartNum]; - if (uartNum >= (sizeof(Uart_PAL) / sizeof(Uart_PAL[0])) || config == NULL || base == NULL) - { - NANOCLR_SET_AND_LEAVE(CLR_E_IO); - } + if (uartNum >= (sizeof(Uart_PAL) / sizeof(Uart_PAL[0])) || config == NULL || base == NULL) + { + NANOCLR_SET_AND_LEAVE(CLR_E_IO); + } - config->baudRate_Bps = (uint32_t)pThis[FIELD___baudRate].NumericByRef().s4; + config->baudRate_Bps = (uint32_t)pThis[FIELD___baudRate].NumericByRef().s4; - switch (pThis[FIELD___dataBits].NumericByRef().s4) - { - default: - NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); - break; - case 7: - config->dataBitsCount = kLPUART_SevenDataBits; - break; - case 8: - config->dataBitsCount = kLPUART_EightDataBits; - break; - } + switch (pThis[FIELD___dataBits].NumericByRef().s4) + { + default: + NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); + break; + case 7: + config->dataBitsCount = kLPUART_SevenDataBits; + break; + case 8: + config->dataBitsCount = kLPUART_EightDataBits; + break; + } - switch (pThis[FIELD___parity].NumericByRef().s4) - { - default: - NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); - break; - case SerialParity_None: - config->parityMode = kLPUART_ParityDisabled; - break; - case SerialParity_Even: - config->parityMode = kLPUART_ParityEven; - break; - case SerialParity_Odd: - config->parityMode = kLPUART_ParityOdd; - break; - } + switch (pThis[FIELD___parity].NumericByRef().s4) + { + default: + NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); + break; + case SerialParity_None: + config->parityMode = kLPUART_ParityDisabled; + break; + case SerialParity_Even: + config->parityMode = kLPUART_ParityEven; + break; + case SerialParity_Odd: + config->parityMode = kLPUART_ParityOdd; + break; + } - switch (pThis[FIELD___stopBits].NumericByRef().s4) - { - default: - NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); - break; - case SerialStopBitCount_One: - config->stopBitCount = kLPUART_OneStopBit; - break; - case SerialStopBitCount_Two: - config->stopBitCount = kLPUART_TwoStopBit; - break; - } + switch (pThis[FIELD___stopBits].NumericByRef().s4) + { + default: + NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); + break; + case SerialStopBitCount_One: + config->stopBitCount = kLPUART_OneStopBit; + break; + case SerialStopBitCount_Two: + config->stopBitCount = kLPUART_TwoStopBit; + break; + } - // write config to UART peripheral - status = LPUART_Init(base, config, GetSrcFreq()); - if (status != kStatus_Success) - { - NANOCLR_SET_AND_LEAVE(CLR_E_IO); - } + // write config to UART peripheral + status = LPUART_Init(base, config, GetSrcFreq()); + if (status != kStatus_Success) + { + NANOCLR_SET_AND_LEAVE(CLR_E_IO); + } - // Enable interrupts after setting configuration - // Disable transmitter and receiver - base->CTRL &= ~(1U << 19); - base->CTRL &= ~(1U << 18); - // Enable receiver interrupt - base->CTRL |= 1U << LPUART_CTRL_RIE_SHIFT; - // Enable receiver ovverun interrupt - base->CTRL |= 1U << LPUART_CTRL_ORIE_SHIFT; - // Renable transmitter and receiver - base->CTRL |= 1U << 19; - base->CTRL |= 1U << 18; - } - NANOCLR_NOCLEANUP(); + // Enable interrupts after setting configuration + // Disable transmitter and receiver + base->CTRL &= ~(1U << 19); + base->CTRL &= ~(1U << 18); + // Enable receiver interrupt + base->CTRL |= 1U << LPUART_CTRL_RIE_SHIFT; + // Enable receiver ovverun interrupt + base->CTRL |= 1U << LPUART_CTRL_ORIE_SHIFT; + // Renable transmitter and receiver + base->CTRL |= 1U << 19; + base->CTRL |= 1U << 18; + } + NANOCLR_NOCLEANUP(); } -// Write data into buffer -HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::NativeWrite___VOID__SZARRAY_U1(CLR_RT_StackFrame &stack) +// Write data into buffer +HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::NativeWrite___VOID__SZARRAY_U1( + CLR_RT_StackFrame &stack) { - NANOCLR_HEADER(); - { - // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock *pThis = stack.This(); - FAULT_ON_NULL(pThis); + NANOCLR_HEADER(); + { + // get a pointer to the managed object instance and check that it's not NULL + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); - uint8_t *data = NULL; - uint8_t uartNum = 0; - size_t length = 0; + uint8_t *data = NULL; + uint8_t uartNum = 0; + size_t length = 0; - if (pThis[FIELD___disposed].NumericByRef().u1 != 0) - { - NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); - } + if (pThis[FIELD___disposed].NumericByRef().u1 != 0) + { + NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); + } - // Get UART device number - uartNum = pThis[FIELD___portIndex].NumericByRef().s4; + // Get UART device number + uartNum = pThis[FIELD___portIndex].NumericByRef().s4; - // Quit if parameters or device is invalid or out of range - if (uartNum >= (sizeof(Uart_PAL) / sizeof(Uart_PAL[0]))) - { - NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); - } + // Quit if parameters or device is invalid or out of range + if (uartNum >= (sizeof(Uart_PAL) / sizeof(Uart_PAL[0]))) + { + NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); + } - NF_PAL_UART *palUart = Uart_PAL[uartNum]; + NF_PAL_UART *palUart = Uart_PAL[uartNum]; - // dereference the data buffer from the argument - CLR_RT_HeapBlock_Array *dataBuffer = stack.Arg1().DereferenceArray(); + // dereference the data buffer from the argument + CLR_RT_HeapBlock_Array *dataBuffer = stack.Arg1().DereferenceArray(); - // get a the pointer to the array by using the first element of the array - data = dataBuffer->GetFirstElement(); + // get a the pointer to the array by using the first element of the array + data = dataBuffer->GetFirstElement(); - // get the size of the buffer - length = dataBuffer->m_numOfElements; + // get the size of the buffer + length = dataBuffer->m_numOfElements; - // check if there is enough room in the buffer - if (palUart->TxRingBuffer.Capacity() - palUart->TxRingBuffer.Length() < length) - { - // not enough room in the buffer - NANOCLR_SET_AND_LEAVE(CLR_E_BUFFER_TOO_SMALL); - } + // check if there is enough room in the buffer + if (palUart->TxRingBuffer.Capacity() - palUart->TxRingBuffer.Length() < length) + { + // not enough room in the buffer + NANOCLR_SET_AND_LEAVE(CLR_E_BUFFER_TOO_SMALL); + } - // push data to buffer - size_t bytesWritten = palUart->TxRingBuffer.Push(data, length); + // push data to buffer + size_t bytesWritten = palUart->TxRingBuffer.Push(data, length); - // check if all requested bytes were written - if (bytesWritten != length) - { - // not sure if this is the best exception to throw here... - NANOCLR_SET_AND_LEAVE(CLR_E_IO); - } + // check if all requested bytes were written + if (bytesWritten != length) + { + // not sure if this is the best exception to throw here... + NANOCLR_SET_AND_LEAVE(CLR_E_IO); + } - // need to update the _unstoredBufferLength field in the SerialDeviceOutputStream - // get pointer to outputStream field - CLR_RT_HeapBlock *outputStream = pThis[Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::FIELD___outputStream].Dereference(); - // get pointer to _unstoredBufferLength field and udpate field value - outputStream[Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDeviceOutputStream::FIELD___unstoredBufferLength].NumericByRef().s4 = palUart->TxRingBuffer.Length(); - } - NANOCLR_NOCLEANUP(); + // need to update the _unstoredBufferLength field in the SerialDeviceOutputStream + // get pointer to outputStream field + CLR_RT_HeapBlock *outputStream = + pThis[Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::FIELD___outputStream] + .Dereference(); + // get pointer to _unstoredBufferLength field and udpate field value + outputStream[Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDeviceOutputStream:: + FIELD___unstoredBufferLength] + .NumericByRef() + .s4 = palUart->TxRingBuffer.Length(); + } + NANOCLR_NOCLEANUP(); } -// Store - Send buffer and wait -HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::NativeStore___U4(CLR_RT_StackFrame &stack) +// Store - Send buffer and wait +HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::NativeStore___U4( + CLR_RT_StackFrame &stack) { - NANOCLR_HEADER(); - { - NF_PAL_UART *palUart = NULL; + NANOCLR_HEADER(); + { + NF_PAL_UART *palUart = NULL; - size_t length = 0; + size_t length = 0; - int64_t *timeoutTicks; - bool eventResult = true; - bool txOk = false; + int64_t *timeoutTicks; + bool eventResult = true; + bool txOk = false; - // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock *pThis = stack.This(); - FAULT_ON_NULL(pThis); + // get a pointer to the managed object instance and check that it's not NULL + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); - if (pThis[FIELD___disposed].NumericByRef().u1 != 0) - { - NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); - } + if (pThis[FIELD___disposed].NumericByRef().u1 != 0) + { + NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); + } - uint8_t uartNum = pThis[FIELD___portIndex].NumericByRef().s4; + uint8_t uartNum = pThis[FIELD___portIndex].NumericByRef().s4; - // Quit if parameters or device is invalid or out of range - if (uartNum >= (sizeof(Uart_PAL) / sizeof(Uart_PAL[0]))) - { - NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); - } + // Quit if parameters or device is invalid or out of range + if (uartNum >= (sizeof(Uart_PAL) / sizeof(Uart_PAL[0]))) + { + NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); + } - palUart = Uart_PAL[uartNum]; + palUart = Uart_PAL[uartNum]; - // as we are transsmiting data, we can discard recive buffer - // assuming that we can't RX and TX simultaneously - size_t rx_size = 0; - palUart->RxRingBuffer.Push(1); - rx_size = palUart->RxRingBuffer.Length(); - palUart->RxRingBuffer.Pop(rx_size); + // as we are transsmiting data, we can discard recive buffer + // assuming that we can't RX and TX simultaneously + size_t rx_size = 0; + palUart->RxRingBuffer.Push(1); + rx_size = palUart->RxRingBuffer.Length(); + palUart->RxRingBuffer.Pop(rx_size); - // setup timeout from _writeTimeout field - NANOCLR_CHECK_HRESULT( stack.SetupTimeoutFromTimeSpan(pThis[ FIELD___writeTimeout ], timeoutTicks) ); + // setup timeout from _writeTimeout field + NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTimeSpan(pThis[FIELD___writeTimeout], timeoutTicks)); - // push dummy length value onto the eval stack - // this is going to be used to store how many bytes where buffered to Tx - if (stack.m_customState == 1) - { - stack.PushValueI4(0); - // bump custom state so the read value above is pushed only once - stack.m_customState = 2; - } + // push dummy length value onto the eval stack + // this is going to be used to store how many bytes where buffered to Tx + if (stack.m_customState == 1) + { + stack.PushValueI4(0); + // bump custom state so the read value above is pushed only once + stack.m_customState = 2; + } - // check if there is anything the buffer - if (palUart->TxRingBuffer.Length() > 0) - { - // check if there is a TX operation ongoing - if (palUart->TxOngoingCount == 0) - { - // OK to Tx - txOk = true; - } - else - { - // need to wait for the ongoing operation to complete before starting a new one - } - } + // check if there is anything the buffer + if (palUart->TxRingBuffer.Length() > 0) + { + // check if there is a TX operation ongoing + if (palUart->TxOngoingCount == 0) + { + // OK to Tx + txOk = true; + } + else + { + // need to wait for the ongoing operation to complete before starting a new one + } + } - if (txOk) - { - // Optimize buffer for sequential reading - palUart->TxRingBuffer.OptimizeSequence(); + if (txOk) + { + // Optimize buffer for sequential reading + palUart->TxRingBuffer.OptimizeSequence(); - // Get data length available in the buffer - length = palUart->TxRingBuffer.Length(); + // Get data length available in the buffer + length = palUart->TxRingBuffer.Length(); - // Push to the stack how many bytes bytes where buffered for Tx - stack.m_evalStack[1].NumericByRef().s4 = length; + // Push to the stack how many bytes bytes where buffered for Tx + stack.m_evalStack[1].NumericByRef().s4 = length; - // Set TX ongoing count - palUart->TxOngoingCount = length; + // Set TX ongoing count + palUart->TxOngoingCount = length; - // Set transfer structure to nano ring buffer - palUart->xfer.data = (uint8_t *)palUart->TxRingBuffer.Reader(); - palUart->xfer.dataSize = length; - // Notify task that we want to transmit data. - xTaskNotify(palUart->xWTaskToNotify, 0x01, eSetBits); - } + // Set transfer structure to nano ring buffer + palUart->xfer.data = (uint8_t *)palUart->TxRingBuffer.Reader(); + palUart->xfer.dataSize = length; + // Notify task that we want to transmit data. + xTaskNotify(palUart->xWTaskToNotify, 0x01, eSetBits); + } - NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.WaitEvents(stack.m_owningThread, *timeoutTicks, CLR_RT_ExecutionEngine::c_Event_SerialPortOut, eventResult)); + NANOCLR_CHECK_HRESULT( + g_CLR_RT_ExecutionEngine.WaitEvents(stack.m_owningThread, *timeoutTicks, Event_SerialPortOut, eventResult)); - if (eventResult) - { - // Notify the task that the transmission is complete. - // pop elements from ring buffer, just pop - palUart->TxRingBuffer.Pop(palUart->TxOngoingCount); + if (eventResult) + { + // Notify the task that the transmission is complete. + // pop elements from ring buffer, just pop + palUart->TxRingBuffer.Pop(palUart->TxOngoingCount); - // reset Tx ongoing count - palUart->TxOngoingCount = 0; + // reset Tx ongoing count + palUart->TxOngoingCount = 0; - length = stack.m_evalStack[1].NumericByRef().s4; - } - else - { - palUart->TxRingBuffer.Pop(palUart->TxOngoingCount); - palUart->TxOngoingCount = 0; - NANOCLR_SET_AND_LEAVE(CLR_E_TIMEOUT); - } + length = stack.m_evalStack[1].NumericByRef().s4; + } + else + { + palUart->TxRingBuffer.Pop(palUart->TxOngoingCount); + palUart->TxOngoingCount = 0; + NANOCLR_SET_AND_LEAVE(CLR_E_TIMEOUT); + } - // pop length and timeout heap block from stack - stack.PopValue(); - stack.PopValue(); + // pop length and timeout heap block from stack + stack.PopValue(); + stack.PopValue(); - stack.SetResult_U4(length); - } - NANOCLR_NOCLEANUP(); + stack.SetResult_U4(length); + } + NANOCLR_NOCLEANUP(); } -HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::NativeRead___U4__SZARRAY_U1__I4__I4(CLR_RT_StackFrame &stack) +HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice:: + NativeRead___U4__SZARRAY_U1__I4__I4(CLR_RT_StackFrame &stack) { - NANOCLR_HEADER(); - { - CLR_RT_HeapBlock_Array *dataBuffer = NULL; - CLR_RT_HeapBlock *pThis = stack.This(); - FAULT_ON_NULL(pThis); - int64_t *timeoutTicks; - InputStreamOptions options = InputStreamOptions_None; + NANOCLR_HEADER(); + { + CLR_RT_HeapBlock_Array *dataBuffer = NULL; + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + int64_t *timeoutTicks; + InputStreamOptions options = InputStreamOptions_None; - bool eventResult = true; + bool eventResult = true; - uint8_t uartNum = 0; - size_t bytesRead = 0; - size_t bytesToRead = 0; - size_t dataLength = 0; + uint8_t uartNum = 0; + size_t bytesRead = 0; + size_t bytesToRead = 0; + size_t dataLength = 0; - uint8_t *data = NULL; + uint8_t *data = NULL; - size_t count = 0; + size_t count = 0; - if (pThis[FIELD___disposed].NumericByRef().u1 != 0) - { - NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); - } + if (pThis[FIELD___disposed].NumericByRef().u1 != 0) + { + NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); + } - uartNum = pThis[FIELD___portIndex].NumericByRef().s4; + uartNum = pThis[FIELD___portIndex].NumericByRef().s4; - // Quit if parameters or device is invalid or out of range - if (uartNum >= (sizeof(Uart_PAL) / sizeof(Uart_PAL[0]))) - { - NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); - } + // Quit if parameters or device is invalid or out of range + if (uartNum >= (sizeof(Uart_PAL) / sizeof(Uart_PAL[0]))) + { + NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); + } - NF_PAL_UART *palUart = Uart_PAL[uartNum]; + NF_PAL_UART *palUart = Uart_PAL[uartNum]; - // get how many bytes are requested to read - count = stack.Arg2().NumericByRef().s4; + // get how many bytes are requested to read + count = stack.Arg2().NumericByRef().s4; - // Dereference the data buffer from the argument - dataBuffer = stack.Arg1().DereferenceArray(); + // Dereference the data buffer from the argument + dataBuffer = stack.Arg1().DereferenceArray(); - // get a the pointer to the array by using the first element of the array - data = dataBuffer->GetFirstElement(); + // get a the pointer to the array by using the first element of the array + data = dataBuffer->GetFirstElement(); - // get the length of the data buffer - dataLength = dataBuffer->m_numOfElements; + // get the length of the data buffer + dataLength = dataBuffer->m_numOfElements; - // Get the InputStreamOptions option - // TODO: Implement transfer options. - options = (InputStreamOptions)stack.Arg3().NumericByRef().s4; + // Get the InputStreamOptions option + // TODO: Implement transfer options. + options = (InputStreamOptions)stack.Arg3().NumericByRef().s4; - // setup timeout from _readTimeout field - NANOCLR_CHECK_HRESULT( stack.SetupTimeoutFromTimeSpan(pThis[ FIELD___readTimeout ], timeoutTicks)); + // setup timeout from _readTimeout field + NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTimeSpan(pThis[FIELD___readTimeout], timeoutTicks)); - // Check what's avaliable in Rx ring buffer - if (palUart->RxRingBuffer.Length() >= count) - { - // read from Rx ring buffer - bytesToRead = count; + // Check what's avaliable in Rx ring buffer + if (palUart->RxRingBuffer.Length() >= count) + { + // read from Rx ring buffer + bytesToRead = count; - // is the read ahead option enabled? - if (options == InputStreamOptions_ReadAhead) { + // is the read ahead option enabled? + if (options == InputStreamOptions_ReadAhead) + { - // yes, check how many bytes we can store in the buffer argument - if (dataLength < palUart->RxRingBuffer.Length()) { - // read as many bytes has the buffer can hold - bytesToRead = dataLength; - } else { - // read everything that's available in the ring buffer - bytesToRead = palUart->RxRingBuffer.Length(); - } - } + // yes, check how many bytes we can store in the buffer argument + if (dataLength < palUart->RxRingBuffer.Length()) + { + // read as many bytes has the buffer can hold + bytesToRead = dataLength; + } + else + { + // read everything that's available in the ring buffer + bytesToRead = palUart->RxRingBuffer.Length(); + } + } - // we have enough bytes, skip wait for event - eventResult = false; + // we have enough bytes, skip wait for event + eventResult = false; - // clear event by getting it - Events_Get(SYSTEM_EVENT_FLAG_COM_IN); - } - else - { + // clear event by getting it + Events_Get(SYSTEM_EVENT_FLAG_COM_IN); + } + else + { - if (stack.m_customState == 1) { + if (stack.m_customState == 1) + { - // not enough bytes available, have to read from UART - palUart->RxBytesToRead = count; + // not enough bytes available, have to read from UART + palUart->RxBytesToRead = count; - // clear event by getting it - Events_Get(SYSTEM_EVENT_FLAG_COM_IN); + // clear event by getting it + Events_Get(SYSTEM_EVENT_FLAG_COM_IN); - // don't read anything from the buffer yet - bytesToRead = 0; - } - } + // don't read anything from the buffer yet + bytesToRead = 0; + } + } - while (eventResult) - { - if (stack.m_customState == 1) - { - if (bytesToRead > 0) - { - // enough bytes available - eventResult = false; - } - else - { // need to read from the UART - // update custom state - stack.m_customState = 2; - } - } - else - { - // wait for event - NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.WaitEvents(stack.m_owningThread, *timeoutTicks, CLR_RT_ExecutionEngine::c_Event_SerialPortIn, eventResult)); - if (!eventResult) - { - // event timeout - // compute how many bytes to read - // considering the InputStreamOptions read ahead option - if (options == InputStreamOptions_ReadAhead) - { - // yes, check how many bytes we can store in the buffer argument - if (dataLength < palUart->RxRingBuffer.Length()) + while (eventResult) + { + if (stack.m_customState == 1) { - // read as many bytes has the buffer can hold - bytesToRead = dataLength; - } - else + if (bytesToRead > 0) + { + // enough bytes available + eventResult = false; + } + else + { // need to read from the UART + // update custom state + stack.m_customState = 2; + } + } + else { - // read everything that's available in the ring buffer - bytesToRead = palUart->RxRingBuffer.Length(); + // wait for event + NANOCLR_CHECK_HRESULT( + g_CLR_RT_ExecutionEngine + .WaitEvents(stack.m_owningThread, *timeoutTicks, Event_SerialPortIn, eventResult)); + if (!eventResult) + { + // event timeout + // compute how many bytes to read + // considering the InputStreamOptions read ahead option + if (options == InputStreamOptions_ReadAhead) + { + // yes, check how many bytes we can store in the buffer argument + if (dataLength < palUart->RxRingBuffer.Length()) + { + // read as many bytes has the buffer can hold + bytesToRead = dataLength; + } + else + { + // read everything that's available in the ring buffer + bytesToRead = palUart->RxRingBuffer.Length(); + } + } + if (options == InputStreamOptions_Partial) + { + // take InputStreamOptions_Partial as default and read requested quantity or what's available + bytesToRead = count; + + if (count > palUart->RxRingBuffer.Length()) + { + // need to adjust because there aren't enough bytes available + bytesToRead = palUart->RxRingBuffer.Length(); + } + } + // If InputStreamOptions is set to None return timeout exception + NANOCLR_SET_AND_LEAVE(CLR_E_TIMEOUT); + } } - } - if (options == InputStreamOptions_Partial) - { - // take InputStreamOptions_Partial as default and read requested quantity or what's available - bytesToRead = count; + } - if (count > palUart->RxRingBuffer.Length()) { - // need to adjust because there aren't enough bytes available - bytesToRead = palUart->RxRingBuffer.Length(); - } - } - // If InputStreamOptions is set to None return timeout exception - NANOCLR_SET_AND_LEAVE(CLR_E_TIMEOUT); + if (bytesToRead > 0) + { + // pop the requested bytes from the ring buffer + bytesRead = palUart->RxRingBuffer.Pop(data, bytesToRead); } - } - } - if (bytesToRead > 0) - { - // pop the requested bytes from the ring buffer - bytesRead = palUart->RxRingBuffer.Pop(data, bytesToRead); + // pop timeout heap block from stack and return how many bytes were read + stack.PopValue(); + stack.SetResult_U4(bytesRead); } - - // pop timeout heap block from stack and return how many bytes were read - stack.PopValue(); - stack.SetResult_U4(bytesRead); - } - NANOCLR_NOCLEANUP(); + NANOCLR_NOCLEANUP(); } -HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::NativeSetWatchChar___VOID(CLR_RT_StackFrame &stack) +HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::NativeSetWatchChar___VOID( + CLR_RT_StackFrame &stack) { - NANOCLR_HEADER(); - { - // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock *pThis = stack.This(); - FAULT_ON_NULL(pThis); + NANOCLR_HEADER(); + { + // get a pointer to the managed object instance and check that it's not NULL + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); - // Choose the driver for this SerialDevice - uint8_t uartNum = (uint8_t)pThis[FIELD___portIndex].NumericByRef().s4; + // Choose the driver for this SerialDevice + uint8_t uartNum = (uint8_t)pThis[FIELD___portIndex].NumericByRef().s4; - // Quit if parameters or device is invalid or out of range - if (uartNum >= (sizeof(Uart_PAL) / sizeof(Uart_PAL[0]))) - { - NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); - } + // Quit if parameters or device is invalid or out of range + if (uartNum >= (sizeof(Uart_PAL) / sizeof(Uart_PAL[0]))) + { + NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); + } - NF_PAL_UART *palUart = Uart_PAL[uartNum]; + NF_PAL_UART *palUart = Uart_PAL[uartNum]; - // set watch char - palUart->WatchChar = (uint8_t)pThis[FIELD___watchChar].NumericByRef().u1; - } - NANOCLR_NOCLEANUP(); + // set watch char + palUart->WatchChar = (uint8_t)pThis[FIELD___watchChar].NumericByRef().u1; + } + NANOCLR_NOCLEANUP(); } -HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::get_BytesToRead___U4(CLR_RT_StackFrame &stack) +HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::get_BytesToRead___U4( + CLR_RT_StackFrame &stack) { - NANOCLR_HEADER(); - { + NANOCLR_HEADER(); + { - CLR_RT_HeapBlock *pThis = stack.This(); - FAULT_ON_NULL(pThis); + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); - uint8_t uartNum = 0; - size_t read_count = 0; + uint8_t uartNum = 0; + size_t read_count = 0; - if (pThis[FIELD___disposed].NumericByRef().u1 != 0) - { - NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); - } + if (pThis[FIELD___disposed].NumericByRef().u1 != 0) + { + NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); + } - uartNum = pThis[FIELD___portIndex].NumericByRef().s4; + uartNum = pThis[FIELD___portIndex].NumericByRef().s4; - // Quit if parameters or device is invalid or out of range - if (uartNum >= (sizeof(Uart_PAL) / sizeof(Uart_PAL[0]))) - { - NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); - } + // Quit if parameters or device is invalid or out of range + if (uartNum >= (sizeof(Uart_PAL) / sizeof(Uart_PAL[0]))) + { + NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); + } - NF_PAL_UART *palUart = Uart_PAL[uartNum]; - read_count = palUart->RxBytesToRead; + NF_PAL_UART *palUart = Uart_PAL[uartNum]; + read_count = palUart->RxBytesToRead; - stack.SetResult_U4(read_count); - } - NANOCLR_NOCLEANUP(); + stack.SetResult_U4(read_count); + } + NANOCLR_NOCLEANUP(); } -// Return available devices -HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::GetDeviceSelector___STATIC__STRING(CLR_RT_StackFrame &stack) +// Return available devices +HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice:: + GetDeviceSelector___STATIC__STRING(CLR_RT_StackFrame &stack) { - NANOCLR_HEADER(); - char deviceSelectorString[41] = {0}; - int len = 0; - for (uint8_t i = 1; i < (sizeof(Uart_PAL) / sizeof(Uart_PAL[0])); i++) - { - if (Uart_PAL[i] != NULL) + NANOCLR_HEADER(); + char deviceSelectorString[41] = {0}; + int len = 0; + for (uint8_t i = 1; i < (sizeof(Uart_PAL) / sizeof(Uart_PAL[0])); i++) { - char com[6] = "COM1,"; - com[3] = i + '0'; - len += 5; - strcat(deviceSelectorString, com); + if (Uart_PAL[i] != NULL) + { + char com[6] = "COM1,"; + com[3] = i + '0'; + len += 5; + strcat(deviceSelectorString, com); + } } - } - // remove trailing comma - deviceSelectorString[len - 1] = 0; - - // because the caller is expecting a result to be returned - // we need set a return result in the stack argument using the a ppropriate SetResult according to the variable type (a string here) - stack.SetResult_String(deviceSelectorString); - NANOCLR_NOCLEANUP_NOLABEL(); + // remove trailing comma + deviceSelectorString[len - 1] = 0; + + // because the caller is expecting a result to be returned + // we need set a return result in the stack argument using the a ppropriate SetResult according to the variable type + // (a string here) + stack.SetResult_String(deviceSelectorString); + NANOCLR_NOCLEANUP_NOLABEL(); } diff --git a/targets/FreeRTOS/NXP/nanoCLR/Windows.Devices.SerialCommunication/win_dev_serial_native_target.h b/targets/FreeRTOS/NXP/nanoCLR/Windows.Devices.SerialCommunication/win_dev_serial_native_target.h index 757f0303fd..3edd19c5d0 100644 --- a/targets/FreeRTOS/NXP/nanoCLR/Windows.Devices.SerialCommunication/win_dev_serial_native_target.h +++ b/targets/FreeRTOS/NXP/nanoCLR/Windows.Devices.SerialCommunication/win_dev_serial_native_target.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/nanoCLR/Windows.Storage/win_storage_native_Windows_Storage_Devices_SDCard.cpp b/targets/FreeRTOS/NXP/nanoCLR/Windows.Storage/win_storage_native_Windows_Storage_Devices_SDCard.cpp index 4c10bd7e4c..23268d9a55 100644 --- a/targets/FreeRTOS/NXP/nanoCLR/Windows.Storage/win_storage_native_Windows_Storage_Devices_SDCard.cpp +++ b/targets/FreeRTOS/NXP/nanoCLR/Windows.Storage/win_storage_native_Windows_Storage_Devices_SDCard.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/nanoCLR/Windows.Storage/win_storage_native_Windows_Storage_FileIO.cpp b/targets/FreeRTOS/NXP/nanoCLR/Windows.Storage/win_storage_native_Windows_Storage_FileIO.cpp index 5223466426..6f54c48f56 100644 --- a/targets/FreeRTOS/NXP/nanoCLR/Windows.Storage/win_storage_native_Windows_Storage_FileIO.cpp +++ b/targets/FreeRTOS/NXP/nanoCLR/Windows.Storage/win_storage_native_Windows_Storage_FileIO.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // @@ -19,222 +19,239 @@ typedef Library_win_storage_native_Windows_Storage_StorageFile StorageFile; struct FileOperation { - const char* FileName; - char* Content; - uint32_t ContentLength; + const char *FileName; + char *Content; + uint32_t ContentLength; }; // this is the FileIO working thread static volatile FRESULT threadOperationResult; // ReadText working thread -static void ReadTextWorkingThread(void *arg) { +static void ReadTextWorkingThread(void *arg) +{ - FileOperation *fileIoOperation = reinterpret_cast(arg); + FileOperation *fileIoOperation = reinterpret_cast(arg); - FIL file; + FIL file; - // need an extra one for the terminator - uint32_t readLength = fileIoOperation->ContentLength + 1; + // need an extra one for the terminator + uint32_t readLength = fileIoOperation->ContentLength + 1; - // open file (which is supposed to already exist) - // need to use FA_OPEN_EXISTING because we are reading an existing file content from start - threadOperationResult = f_open(&file, fileIoOperation->FileName, FA_OPEN_EXISTING | FA_READ); + // open file (which is supposed to already exist) + // need to use FA_OPEN_EXISTING because we are reading an existing file content from start + threadOperationResult = f_open(&file, fileIoOperation->FileName, FA_OPEN_EXISTING | FA_READ); - if (threadOperationResult != FR_OK) { - // free memory - platform_free(fileIoOperation); - Events_Set(SYSTEM_EVENT_FLAG_STORAGE_IO); - vTaskDelete(NULL); - } + if (threadOperationResult != FR_OK) + { + // free memory + platform_free(fileIoOperation); + Events_Set(SYSTEM_EVENT_FLAG_STORAGE_IO); + vTaskDelete(NULL); + } - // read string - if (!(f_gets((TCHAR *)fileIoOperation->Content, readLength, &file))) - { - threadOperationResult = (FRESULT)f_error(&file); - } + // read string + if (!(f_gets((TCHAR *)fileIoOperation->Content, readLength, &file))) + { + threadOperationResult = (FRESULT)f_error(&file); + } - // close file - f_close(&file); + // close file + f_close(&file); - // free memory - platform_free(fileIoOperation); + // free memory + platform_free(fileIoOperation); - // fire event for FileIO operation complete - Events_Set(SYSTEM_EVENT_FLAG_STORAGE_IO); + // fire event for FileIO operation complete + Events_Set(SYSTEM_EVENT_FLAG_STORAGE_IO); - vTaskDelete(NULL); + vTaskDelete(NULL); } // WriteText working thread -static void WriteTextWorkingThread(void *arg) { +static void WriteTextWorkingThread(void *arg) +{ - FileOperation *fileIoOperation = reinterpret_cast(arg); + FileOperation *fileIoOperation = reinterpret_cast(arg); - FIL file; + FIL file; - // open file (which is supposed to already exist) - // need to use FA_OPEN_ALWAYS because we are writting the file content from start - threadOperationResult = f_open(&file, fileIoOperation->FileName, FA_OPEN_ALWAYS | FA_WRITE); + // open file (which is supposed to already exist) + // need to use FA_OPEN_ALWAYS because we are writting the file content from start + threadOperationResult = f_open(&file, fileIoOperation->FileName, FA_OPEN_ALWAYS | FA_WRITE); - if (threadOperationResult != FR_OK) { - // free memory - platform_free(fileIoOperation); - Events_Set(SYSTEM_EVENT_FLAG_STORAGE_IO); - vTaskDelete(NULL); - } + if (threadOperationResult != FR_OK) + { + // free memory + platform_free(fileIoOperation); + Events_Set(SYSTEM_EVENT_FLAG_STORAGE_IO); + vTaskDelete(NULL); + } - if (f_puts(fileIoOperation->Content, &file) != (int)fileIoOperation->ContentLength) - { - threadOperationResult = FR_DISK_ERR; - } + if (f_puts(fileIoOperation->Content, &file) != (int)fileIoOperation->ContentLength) + { + threadOperationResult = FR_DISK_ERR; + } - // close file - f_close(&file); + // close file + f_close(&file); - // free memory - platform_free(fileIoOperation); + // free memory + platform_free(fileIoOperation); - // fire event for FileIO operation complete - Events_Set(SYSTEM_EVENT_FLAG_STORAGE_IO); + // fire event for FileIO operation complete + Events_Set(SYSTEM_EVENT_FLAG_STORAGE_IO); - vTaskDelete(NULL); + vTaskDelete(NULL); } // WriteBinary working thread -static void WriteBinaryWorkingThread(void *arg) { - UINT bytesWritten; +static void WriteBinaryWorkingThread(void *arg) +{ + UINT bytesWritten; - FileOperation *fileIoOperation = reinterpret_cast(arg); + FileOperation *fileIoOperation = reinterpret_cast(arg); - FIL file; + FIL file; - // open file (which is supposed to already exist) - // need to use FA_OPEN_ALWAYS because we are writting the file content from start - threadOperationResult = f_open(&file, fileIoOperation->FileName, FA_OPEN_ALWAYS | FA_WRITE); + // open file (which is supposed to already exist) + // need to use FA_OPEN_ALWAYS because we are writting the file content from start + threadOperationResult = f_open(&file, fileIoOperation->FileName, FA_OPEN_ALWAYS | FA_WRITE); - if (threadOperationResult != FR_OK) { - // free memory - platform_free(fileIoOperation); - Events_Set(SYSTEM_EVENT_FLAG_STORAGE_IO); - vTaskDelete(NULL); - } + if (threadOperationResult != FR_OK) + { + // free memory + platform_free(fileIoOperation); + Events_Set(SYSTEM_EVENT_FLAG_STORAGE_IO); + vTaskDelete(NULL); + } - threadOperationResult = f_write(&file, fileIoOperation->Content, fileIoOperation->ContentLength, &bytesWritten); - if (bytesWritten != fileIoOperation->ContentLength) - { - threadOperationResult = FR_DISK_ERR; - } - // close file - f_close(&file); + threadOperationResult = f_write(&file, fileIoOperation->Content, fileIoOperation->ContentLength, &bytesWritten); + if (bytesWritten != fileIoOperation->ContentLength) + { + threadOperationResult = FR_DISK_ERR; + } + // close file + f_close(&file); - // free memory - platform_free(fileIoOperation); + // free memory + platform_free(fileIoOperation); - // fire event for FileIO operation complete - Events_Set(SYSTEM_EVENT_FLAG_STORAGE_IO); + // fire event for FileIO operation complete + Events_Set(SYSTEM_EVENT_FLAG_STORAGE_IO); - vTaskDelete(NULL); + vTaskDelete(NULL); } // ReadBinary working thread -static void ReadBinaryWorkingThread(void *arg) { - - FileOperation *fileIoOperation = reinterpret_cast(arg); +static void ReadBinaryWorkingThread(void *arg) +{ - FIL file; + FileOperation *fileIoOperation = reinterpret_cast(arg); - // need an extra one for the terminator - UINT bytesRead = fileIoOperation->ContentLength + 1; + FIL file; - // open file (which is supposed to already exist) - // need to use FA_OPEN_EXISTING because we are reading an existing file content from start - threadOperationResult = f_open(&file, fileIoOperation->FileName, FA_OPEN_EXISTING | FA_READ); + // need an extra one for the terminator + UINT bytesRead = fileIoOperation->ContentLength + 1; - if (threadOperationResult != FR_OK) { - // free memory - platform_free(fileIoOperation); - Events_Set(SYSTEM_EVENT_FLAG_STORAGE_IO); - vTaskDelete(NULL); - } + // open file (which is supposed to already exist) + // need to use FA_OPEN_EXISTING because we are reading an existing file content from start + threadOperationResult = f_open(&file, fileIoOperation->FileName, FA_OPEN_EXISTING | FA_READ); - threadOperationResult = f_read(&file, fileIoOperation->Content, fileIoOperation->ContentLength, &bytesRead); + if (threadOperationResult != FR_OK) + { + // free memory + platform_free(fileIoOperation); + Events_Set(SYSTEM_EVENT_FLAG_STORAGE_IO); + vTaskDelete(NULL); + } - if (bytesRead != fileIoOperation->ContentLength) { - threadOperationResult = FR_DISK_ERR; - } + threadOperationResult = f_read(&file, fileIoOperation->Content, fileIoOperation->ContentLength, &bytesRead); - // close file - f_close(&file); + if (bytesRead != fileIoOperation->ContentLength) + { + threadOperationResult = FR_DISK_ERR; + } - platform_free(fileIoOperation); + // close file + f_close(&file); - // fire event for FileIO operation complete - Events_Set(SYSTEM_EVENT_FLAG_STORAGE_IO); + platform_free(fileIoOperation); - vTaskDelete(NULL); + // fire event for FileIO operation complete + Events_Set(SYSTEM_EVENT_FLAG_STORAGE_IO); + + vTaskDelete(NULL); } //////////////////////////////////////////////// // Developer notes: -// Depending on the content size these operations have the potential to be a long running ones as the string or buffer is written to the storage. -// Despite we are not (yet!) async this is better handled by spawning a thread where the actual data transfer occurs and not blocking the execution. -// The underlying RTOS inheritably takes care of making this happen "in the background". -// When the operation is completed a CLR event is fired and the thread execution resumes. -// Being hard to estimate the expected duration of the operation (depends on storage hardware, CPU clock, transfer speed, etc) -// the timeout is set to an infinite timeout -// the catch is that the working thread MUST ALWAYS return at some point +// Depending on the content size these operations have the potential to be a long running ones as the string or buffer +// is written to the storage. Despite we are not (yet!) async this is better handled by spawning a thread where the +// actual data transfer occurs and not blocking the execution. The underlying RTOS inheritably takes care of making this +// happen "in the background". When the operation is completed a CLR event is fired and the thread execution resumes. +// Being hard to estimate the expected duration of the operation (depends on storage hardware, CPU clock, transfer +// speed, etc) the timeout is set to an infinite timeout the catch is that the working thread MUST ALWAYS return at some +// point //////////////////////////////////////////////// -HRESULT Library_win_storage_native_Windows_Storage_FileIO::WriteBytes___STATIC__VOID__WindowsStorageIStorageFile__SZARRAY_U1( CLR_RT_StackFrame& stack ) +HRESULT Library_win_storage_native_Windows_Storage_FileIO:: + WriteBytes___STATIC__VOID__WindowsStorageIStorageFile__SZARRAY_U1(CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); - CLR_RT_HeapBlock_Array* bufferArray; + CLR_RT_HeapBlock_Array *bufferArray; - CLR_RT_HeapBlock hbTimeout; - CLR_INT64* timeout; - bool eventResult = true; + CLR_RT_HeapBlock hbTimeout; + CLR_INT64 *timeout; + bool eventResult = true; - const TCHAR* filePath; - - char* buffer; - uint32_t bufferLength; + const TCHAR *filePath; + + char *buffer; + uint32_t bufferLength; // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); - + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + // get a pointer to the buffer bufferArray = stack.Arg1().DereferenceArray(); - buffer = (char*)bufferArray->GetFirstElement(); + buffer = (char *)bufferArray->GetFirstElement(); bufferLength = bufferArray->m_numOfElements; // get a pointer to the file path - filePath = (TCHAR*)pThis[ StorageFile::FIELD___path ].DereferenceString()->StringText(); + filePath = (TCHAR *)pThis[StorageFile::FIELD___path].DereferenceString()->StringText(); // !! need to cast to CLR_INT64 otherwise it wont setup a proper timeout infinite hbTimeout.SetInteger((CLR_INT64)-1); - NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks( hbTimeout, timeout )); - - if(stack.m_customState == 1) - { + NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks(hbTimeout, timeout)); + + if (stack.m_customState == 1) + { // protect the content buffer from GC so the working thread can access those - CLR_RT_ProtectFromGC gcContent( *bufferArray ); + CLR_RT_ProtectFromGC gcContent(*bufferArray); // setup FileIO operation FileOperation *fileIoOperation = reinterpret_cast(platform_malloc(sizeof(FileOperation))); - //fileIoOperation->File = file; + // fileIoOperation->File = file; fileIoOperation->FileName = filePath; fileIoOperation->Content = buffer; fileIoOperation->ContentLength = bufferLength; // spawn working thread to perform the write transaction BaseType_t ret; - ret = xTaskCreate(WriteBinaryWorkingThread, "WriteBin", configMINIMAL_STACK_SIZE + 600, fileIoOperation, configMAX_PRIORITIES - 2, NULL); + ret = xTaskCreate( + WriteBinaryWorkingThread, + "WriteBin", + configMINIMAL_STACK_SIZE + 600, + fileIoOperation, + configMAX_PRIORITIES - 2, + NULL); if (ret != pdPASS) { @@ -242,27 +259,28 @@ HRESULT Library_win_storage_native_Windows_Storage_FileIO::WriteBytes___STATIC__ } // bump custom state - stack.m_customState = 2; + stack.m_customState = 2; } - while(eventResult) + while (eventResult) { // non-blocking wait allowing other threads to run while we wait for the write operation to complete - NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.WaitEvents( stack.m_owningThread, *timeout, CLR_RT_ExecutionEngine::c_Event_StorageIo, eventResult )); + NANOCLR_CHECK_HRESULT( + g_CLR_RT_ExecutionEngine.WaitEvents(stack.m_owningThread, *timeout, Event_StorageIo, eventResult)); - if(eventResult) + if (eventResult) { // event occurred - if(threadOperationResult == FR_DISK_ERR) + if (threadOperationResult == FR_DISK_ERR) { - NANOCLR_SET_AND_LEAVE( CLR_E_FILE_IO ); + NANOCLR_SET_AND_LEAVE(CLR_E_FILE_IO); } - else if(threadOperationResult == FR_NO_FILE) + else if (threadOperationResult == FR_NO_FILE) { - NANOCLR_SET_AND_LEAVE( CLR_E_FILE_NOT_FOUND ); + NANOCLR_SET_AND_LEAVE(CLR_E_FILE_NOT_FOUND); } - else if(threadOperationResult == FR_INVALID_DRIVE) + else if (threadOperationResult == FR_INVALID_DRIVE) { // failed to change drive NANOCLR_SET_AND_LEAVE(CLR_E_VOLUME_NOT_FOUND); @@ -273,7 +291,7 @@ HRESULT Library_win_storage_native_Windows_Storage_FileIO::WriteBytes___STATIC__ } else { - NANOCLR_SET_AND_LEAVE( CLR_E_TIMEOUT ); + NANOCLR_SET_AND_LEAVE(CLR_E_TIMEOUT); } } // pop timeout heap block from stack @@ -282,144 +300,162 @@ HRESULT Library_win_storage_native_Windows_Storage_FileIO::WriteBytes___STATIC__ NANOCLR_NOCLEANUP(); } -HRESULT Library_win_storage_native_Windows_Storage_FileIO::WriteText___STATIC__VOID__WindowsStorageIStorageFile__STRING(CLR_RT_StackFrame &stack) { - NANOCLR_HEADER(); +HRESULT Library_win_storage_native_Windows_Storage_FileIO::WriteText___STATIC__VOID__WindowsStorageIStorageFile__STRING( + CLR_RT_StackFrame &stack) +{ + NANOCLR_HEADER(); - CLR_RT_HeapBlock_String *content; + CLR_RT_HeapBlock_String *content; - CLR_RT_HeapBlock hbTimeout; - CLR_INT64 *timeout; - bool eventResult = true; + CLR_RT_HeapBlock hbTimeout; + CLR_INT64 *timeout; + bool eventResult = true; - const TCHAR *filePath; + const TCHAR *filePath; - // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock *pThis = stack.This(); - FAULT_ON_NULL(pThis); + // get a pointer to the managed object instance and check that it's not NULL + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); - // get a pointer to the content - content = stack.Arg1().DereferenceString(); + // get a pointer to the content + content = stack.Arg1().DereferenceString(); - // get a pointer to the file path - filePath = (TCHAR *)pThis[StorageFile::FIELD___path].DereferenceString()->StringText(); + // get a pointer to the file path + filePath = (TCHAR *)pThis[StorageFile::FIELD___path].DereferenceString()->StringText(); - // !! need to cast to CLR_INT64 otherwise it wont setup a proper timeout infinite - hbTimeout.SetInteger((CLR_INT64)-1); + // !! need to cast to CLR_INT64 otherwise it wont setup a proper timeout infinite + hbTimeout.SetInteger((CLR_INT64)-1); - NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks(hbTimeout, timeout)); + NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks(hbTimeout, timeout)); - if (stack.m_customState == 1) - { - // protect the StorageFile and the content buffer from GC so the working thread can access those - CLR_RT_ProtectFromGC gcStorageFile(*pThis); - CLR_RT_ProtectFromGC gcContent(*content); + if (stack.m_customState == 1) + { + // protect the StorageFile and the content buffer from GC so the working thread can access those + CLR_RT_ProtectFromGC gcStorageFile(*pThis); + CLR_RT_ProtectFromGC gcContent(*content); - // setup FileIO operation - FileOperation *fileIoOperation = reinterpret_cast(platform_malloc(sizeof(FileOperation))); + // setup FileIO operation + FileOperation *fileIoOperation = reinterpret_cast(platform_malloc(sizeof(FileOperation))); - fileIoOperation->FileName = filePath; - fileIoOperation->Content = (char *)content->StringText(); - fileIoOperation->ContentLength = hal_strlen_s(fileIoOperation->Content); + fileIoOperation->FileName = filePath; + fileIoOperation->Content = (char *)content->StringText(); + fileIoOperation->ContentLength = hal_strlen_s(fileIoOperation->Content); - // spawn working thread to perform the write transaction - BaseType_t ret; - ret = xTaskCreate(WriteTextWorkingThread, "WriteText", configMINIMAL_STACK_SIZE + 400, fileIoOperation, configMAX_PRIORITIES - 2, NULL); + // spawn working thread to perform the write transaction + BaseType_t ret; + ret = xTaskCreate( + WriteTextWorkingThread, + "WriteText", + configMINIMAL_STACK_SIZE + 400, + fileIoOperation, + configMAX_PRIORITIES - 2, + NULL); - if (ret != pdPASS) - { - NANOCLR_SET_AND_LEAVE(CLR_E_PROCESS_EXCEPTION); + if (ret != pdPASS) + { + NANOCLR_SET_AND_LEAVE(CLR_E_PROCESS_EXCEPTION); + } + + // bump custom state + stack.m_customState = 2; } - // bump custom state - stack.m_customState = 2; - } + while (eventResult) + { + // non-blocking wait allowing other threads to run while we wait for the write operation to complete + NANOCLR_CHECK_HRESULT( + g_CLR_RT_ExecutionEngine.WaitEvents(stack.m_owningThread, *timeout, Event_StorageIo, eventResult)); - while (eventResult) - { - // non-blocking wait allowing other threads to run while we wait for the write operation to complete - NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.WaitEvents(stack.m_owningThread, *timeout, CLR_RT_ExecutionEngine::c_Event_StorageIo, eventResult)); + if (eventResult) + { + // event occurred + if (threadOperationResult == FR_DISK_ERR) + { + NANOCLR_SET_AND_LEAVE(CLR_E_FILE_IO); + } + else if (threadOperationResult == FR_NO_FILE) + { + NANOCLR_SET_AND_LEAVE(CLR_E_FILE_NOT_FOUND); + } + else if (threadOperationResult == FR_INVALID_DRIVE) + { + // failed to change drive + NANOCLR_SET_AND_LEAVE(CLR_E_VOLUME_NOT_FOUND); + } - if (eventResult) - { - // event occurred - if (threadOperationResult == FR_DISK_ERR) - { - NANOCLR_SET_AND_LEAVE(CLR_E_FILE_IO); - } - else if (threadOperationResult == FR_NO_FILE) - { - NANOCLR_SET_AND_LEAVE(CLR_E_FILE_NOT_FOUND); - } - else if (threadOperationResult == FR_INVALID_DRIVE) - { - // failed to change drive - NANOCLR_SET_AND_LEAVE(CLR_E_VOLUME_NOT_FOUND); - } - - // done here - break; - } - else - { - NANOCLR_SET_AND_LEAVE(CLR_E_TIMEOUT); + // done here + break; + } + else + { + NANOCLR_SET_AND_LEAVE(CLR_E_TIMEOUT); + } } - } - // pop timeout heap block from stack - stack.PopValue(); + // pop timeout heap block from stack + stack.PopValue(); - NANOCLR_NOCLEANUP(); + NANOCLR_NOCLEANUP(); } -HRESULT Library_win_storage_native_Windows_Storage_FileIO::ReadBufferNative___STATIC__VOID__WindowsStorageIStorageFile__BYREF_SZARRAY_U1( CLR_RT_StackFrame& stack ) +HRESULT Library_win_storage_native_Windows_Storage_FileIO:: + ReadBufferNative___STATIC__VOID__WindowsStorageIStorageFile__BYREF_SZARRAY_U1(CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); - - CLR_RT_HeapBlock hbTimeout; - CLR_INT64* timeout; - bool eventResult = true; - const TCHAR* filePath; + CLR_RT_HeapBlock hbTimeout; + CLR_INT64 *timeout; + bool eventResult = true; + + const TCHAR *filePath; // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); // !! need to cast to CLR_INT64 otherwise it wont setup a proper timeout infinite hbTimeout.SetInteger((CLR_INT64)-1); - NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks( hbTimeout, timeout )); + NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks(hbTimeout, timeout)); // get a pointer to the file path - filePath = (TCHAR*)pThis[ StorageFile::FIELD___path ].DereferenceString()->StringText(); - - if(stack.m_customState == 1) + filePath = (TCHAR *)pThis[StorageFile::FIELD___path].DereferenceString()->StringText(); + + if (stack.m_customState == 1) { // get file details static FILINFO fileInfo; f_stat(filePath, &fileInfo); CLR_RT_HeapBlock buffer; - buffer.SetObjectReference( NULL ); - CLR_RT_ProtectFromGC gc2( buffer ); + buffer.SetObjectReference(NULL); + CLR_RT_ProtectFromGC gc2(buffer); // create a new byte array with the appropriate size (and type) - NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_Array::CreateInstance( buffer, (CLR_INT32)fileInfo.fsize, g_CLR_RT_WellKnownTypes.m_UInt8 )); + NANOCLR_CHECK_HRESULT( + CLR_RT_HeapBlock_Array::CreateInstance(buffer, (CLR_INT32)fileInfo.fsize, g_CLR_RT_WellKnownTypes.m_UInt8)); // store this to the argument passed byref - NANOCLR_CHECK_HRESULT(buffer.StoreToReference( stack.Arg1(), 0 )); + NANOCLR_CHECK_HRESULT(buffer.StoreToReference(stack.Arg1(), 0)); // get a pointer to the buffer array to improve readability on the code ahead - CLR_RT_HeapBlock_Array* bufferArray = buffer.DereferenceArray(); + CLR_RT_HeapBlock_Array *bufferArray = buffer.DereferenceArray(); // setup FileIO operation FileOperation *fileIoOperation = reinterpret_cast(platform_malloc(sizeof(FileOperation))); fileIoOperation->FileName = filePath; - fileIoOperation->Content = (char*)bufferArray->GetFirstElement(); + fileIoOperation->Content = (char *)bufferArray->GetFirstElement(); fileIoOperation->ContentLength = bufferArray->m_numOfElements; // spawn working thread to perform the read transaction BaseType_t ret; - ret = xTaskCreate(ReadBinaryWorkingThread, "ReadBin", configMINIMAL_STACK_SIZE + 600, fileIoOperation, configMAX_PRIORITIES - 2, NULL); + ret = xTaskCreate( + ReadBinaryWorkingThread, + "ReadBin", + configMINIMAL_STACK_SIZE + 600, + fileIoOperation, + configMAX_PRIORITIES - 2, + NULL); if (ret != pdPASS) { @@ -428,27 +464,27 @@ HRESULT Library_win_storage_native_Windows_Storage_FileIO::ReadBufferNative___ST // bump custom state stack.m_customState = 2; - } - while(eventResult) + while (eventResult) { // non-blocking wait allowing other threads to run while we wait for the write operation to complete - NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.WaitEvents( stack.m_owningThread, *timeout, CLR_RT_ExecutionEngine::c_Event_StorageIo, eventResult )); + NANOCLR_CHECK_HRESULT( + g_CLR_RT_ExecutionEngine.WaitEvents(stack.m_owningThread, *timeout, Event_StorageIo, eventResult)); - if(eventResult) + if (eventResult) { // event occurred - if(threadOperationResult == FR_DISK_ERR) + if (threadOperationResult == FR_DISK_ERR) { - NANOCLR_SET_AND_LEAVE( CLR_E_FILE_IO ); + NANOCLR_SET_AND_LEAVE(CLR_E_FILE_IO); } - else if(threadOperationResult == FR_NO_FILE) + else if (threadOperationResult == FR_NO_FILE) { - NANOCLR_SET_AND_LEAVE( CLR_E_FILE_NOT_FOUND ); + NANOCLR_SET_AND_LEAVE(CLR_E_FILE_NOT_FOUND); } - else if(threadOperationResult == FR_INVALID_DRIVE) + else if (threadOperationResult == FR_INVALID_DRIVE) { // failed to change drive NANOCLR_SET_AND_LEAVE(CLR_E_VOLUME_NOT_FOUND); @@ -458,7 +494,7 @@ HRESULT Library_win_storage_native_Windows_Storage_FileIO::ReadBufferNative___ST } else { - NANOCLR_SET_AND_LEAVE( CLR_E_TIMEOUT ); + NANOCLR_SET_AND_LEAVE(CLR_E_TIMEOUT); } } // pop timeout heap block from stack @@ -467,97 +503,111 @@ HRESULT Library_win_storage_native_Windows_Storage_FileIO::ReadBufferNative___ST NANOCLR_NOCLEANUP(); } -HRESULT Library_win_storage_native_Windows_Storage_FileIO::ReadTextNative___STATIC__VOID__WindowsStorageIStorageFile__BYREF_STRING(CLR_RT_StackFrame &stack) { - NANOCLR_HEADER(); +HRESULT Library_win_storage_native_Windows_Storage_FileIO:: + ReadTextNative___STATIC__VOID__WindowsStorageIStorageFile__BYREF_STRING(CLR_RT_StackFrame &stack) +{ + NANOCLR_HEADER(); - CLR_RT_HeapBlock hbTimeout; - CLR_INT64 *timeout; - bool eventResult = true; + CLR_RT_HeapBlock hbTimeout; + CLR_INT64 *timeout; + bool eventResult = true; - const TCHAR *filePath; + const TCHAR *filePath; - static FILINFO fileInfo; + static FILINFO fileInfo; - // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock *pThis = stack.This(); - FAULT_ON_NULL(pThis); + // get a pointer to the managed object instance and check that it's not NULL + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); - // !! need to cast to CLR_INT64 otherwise it wont setup a proper timeout infinite - hbTimeout.SetInteger((CLR_INT64)-1); + // !! need to cast to CLR_INT64 otherwise it wont setup a proper timeout infinite + hbTimeout.SetInteger((CLR_INT64)-1); - NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks(hbTimeout, timeout)); + NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks(hbTimeout, timeout)); - // get a pointer to the file path - filePath = (TCHAR *)pThis[StorageFile::FIELD___path].DereferenceString()->StringText(); + // get a pointer to the file path + filePath = (TCHAR *)pThis[StorageFile::FIELD___path].DereferenceString()->StringText(); - if (stack.m_customState == 1) { - // protect the StorageFile and the content buffer from GC so the working thread can access those - CLR_RT_ProtectFromGC gcStorageFile(*pThis); + if (stack.m_customState == 1) + { + // protect the StorageFile and the content buffer from GC so the working thread can access those + CLR_RT_ProtectFromGC gcStorageFile(*pThis); - // get file details - f_stat(filePath, &fileInfo); + // get file details + f_stat(filePath, &fileInfo); - // create a new string object with the appropriate size - CLR_RT_HeapBlock hbText; - hbText.SetObjectReference(NULL); - CLR_RT_ProtectFromGC gc(hbText); + // create a new string object with the appropriate size + CLR_RT_HeapBlock hbText; + hbText.SetObjectReference(NULL); + CLR_RT_ProtectFromGC gc(hbText); - CLR_RT_HeapBlock_String *textString = CLR_RT_HeapBlock_String::CreateInstance(hbText, (CLR_UINT32)fileInfo.fsize); - FAULT_ON_NULL(textString); + CLR_RT_HeapBlock_String *textString = + CLR_RT_HeapBlock_String::CreateInstance(hbText, (CLR_UINT32)fileInfo.fsize); + FAULT_ON_NULL(textString); - // store this to the argument passed byref - NANOCLR_CHECK_HRESULT(hbText.StoreToReference(stack.Arg1(), 0)); + // store this to the argument passed byref + NANOCLR_CHECK_HRESULT(hbText.StoreToReference(stack.Arg1(), 0)); - // setup FileIO operation - FileOperation *fileIoOperation = (FileOperation *)platform_malloc(sizeof(FileOperation)); + // setup FileIO operation + FileOperation *fileIoOperation = (FileOperation *)platform_malloc(sizeof(FileOperation)); - fileIoOperation->FileName = filePath; - fileIoOperation->Content = (char *)textString->StringText(); - fileIoOperation->ContentLength = fileInfo.fsize; + fileIoOperation->FileName = filePath; + fileIoOperation->Content = (char *)textString->StringText(); + fileIoOperation->ContentLength = fileInfo.fsize; - // spawn working thread to perform the read transaction - BaseType_t ret; - ret = xTaskCreate(ReadTextWorkingThread, "ReadText", configMINIMAL_STACK_SIZE + 300, fileIoOperation, configMAX_PRIORITIES - 2, NULL); + // spawn working thread to perform the read transaction + BaseType_t ret; + ret = xTaskCreate( + ReadTextWorkingThread, + "ReadText", + configMINIMAL_STACK_SIZE + 300, + fileIoOperation, + configMAX_PRIORITIES - 2, + NULL); + + if (ret != pdPASS) + { + NANOCLR_SET_AND_LEAVE(CLR_E_PROCESS_EXCEPTION); + } - if (ret != pdPASS) { - NANOCLR_SET_AND_LEAVE(CLR_E_PROCESS_EXCEPTION); + // bump custom state + stack.m_customState = 2; } - // bump custom state - stack.m_customState = 2; - } - - while (eventResult) { - // non-blocking wait allowing other threads to run while we wait for the write operation to complete - NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.WaitEvents(stack.m_owningThread, *timeout, CLR_RT_ExecutionEngine::c_Event_StorageIo, eventResult)); - - if (eventResult) { - // event occurred - - if (threadOperationResult == FR_DISK_ERR) - { - NANOCLR_SET_AND_LEAVE(CLR_E_FILE_IO); - } - else if (threadOperationResult == FR_NO_FILE) - { - NANOCLR_SET_AND_LEAVE(CLR_E_FILE_NOT_FOUND); - } - else if (threadOperationResult == FR_INVALID_DRIVE) - { - // failed to change drive - NANOCLR_SET_AND_LEAVE(CLR_E_VOLUME_NOT_FOUND); - } - - // done here - break; - } - else + while (eventResult) { - NANOCLR_SET_AND_LEAVE(CLR_E_TIMEOUT); + // non-blocking wait allowing other threads to run while we wait for the write operation to complete + NANOCLR_CHECK_HRESULT( + g_CLR_RT_ExecutionEngine.WaitEvents(stack.m_owningThread, *timeout, Event_StorageIo, eventResult)); + + if (eventResult) + { + // event occurred + + if (threadOperationResult == FR_DISK_ERR) + { + NANOCLR_SET_AND_LEAVE(CLR_E_FILE_IO); + } + else if (threadOperationResult == FR_NO_FILE) + { + NANOCLR_SET_AND_LEAVE(CLR_E_FILE_NOT_FOUND); + } + else if (threadOperationResult == FR_INVALID_DRIVE) + { + // failed to change drive + NANOCLR_SET_AND_LEAVE(CLR_E_VOLUME_NOT_FOUND); + } + + // done here + break; + } + else + { + NANOCLR_SET_AND_LEAVE(CLR_E_TIMEOUT); + } } - } - // pop timeout heap block from stack - stack.PopValue(); + // pop timeout heap block from stack + stack.PopValue(); - NANOCLR_NOCLEANUP(); + NANOCLR_NOCLEANUP(); } diff --git a/targets/FreeRTOS/NXP/nanoCLR/Windows.Storage/win_storage_native_Windows_Storage_StorageFile.cpp b/targets/FreeRTOS/NXP/nanoCLR/Windows.Storage/win_storage_native_Windows_Storage_StorageFile.cpp index 50b965d809..6236e4ebf5 100644 --- a/targets/FreeRTOS/NXP/nanoCLR/Windows.Storage/win_storage_native_Windows_Storage_StorageFile.cpp +++ b/targets/FreeRTOS/NXP/nanoCLR/Windows.Storage/win_storage_native_Windows_Storage_StorageFile.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2020 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/nanoCLR/Windows.Storage/win_storage_native_Windows_Storage_StorageFolder.cpp b/targets/FreeRTOS/NXP/nanoCLR/Windows.Storage/win_storage_native_Windows_Storage_StorageFolder.cpp index b7d4b12ce2..8b2635c93c 100644 --- a/targets/FreeRTOS/NXP/nanoCLR/Windows.Storage/win_storage_native_Windows_Storage_StorageFolder.cpp +++ b/targets/FreeRTOS/NXP/nanoCLR/Windows.Storage/win_storage_native_Windows_Storage_StorageFolder.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2020 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // @@ -11,16 +11,16 @@ // flags for file system ready extern bool sdCardFileSystemReady; -void CombinePath(char * outpath, const char * path1, const char * path2) +void CombinePath(char *outpath, const char *path1, const char *path2) { - strcat(outpath, path1); - - // Add "\" to path if required - if (outpath[hal_strlen_s(outpath) - 1] != '\\') - { - strcat(outpath, "\\"); - } - strcat(outpath, path2); + strcat(outpath, path1); + + // Add "\" to path if required + if (outpath[hal_strlen_s(outpath) - 1] != '\\') + { + strcat(outpath, "\\"); + } + strcat(outpath, path2); } SYSTEMTIME GetDateTime(uint16_t date, uint16_t time) @@ -46,18 +46,19 @@ SYSTEMTIME GetDateTime(uint16_t date, uint16_t time) return fileTime; } -HRESULT Library_win_storage_native_Windows_Storage_StorageFolder::GetRemovableStorageFoldersNative___SZARRAY_WindowsStorageStorageFolder( CLR_RT_StackFrame& stack ) +HRESULT Library_win_storage_native_Windows_Storage_StorageFolder:: + GetRemovableStorageFoldersNative___SZARRAY_WindowsStorageStorageFolder(CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); uint32_t driveCount = 0; - CLR_RT_HeapBlock* storageFolder; + CLR_RT_HeapBlock *storageFolder; CLR_RT_TypeDef_Index storageFolderTypeDef; - CLR_RT_HeapBlock& top = stack.PushValueAndClear(); + CLR_RT_HeapBlock &top = stack.PushValueAndClear(); // is the SD card file system ready? - if(sdCardFileSystemReady) + if (sdCardFileSystemReady) { // add count driveCount++; @@ -65,28 +66,28 @@ HRESULT Library_win_storage_native_Windows_Storage_StorageFolder::GetRemovableSt // start composing the reply // find type definition, don't bother checking the result as it exists for sure - g_CLR_RT_TypeSystem.FindTypeDef( "StorageFolder", "Windows.Storage", storageFolderTypeDef ); + g_CLR_RT_TypeSystem.FindTypeDef("StorageFolder", "Windows.Storage", storageFolderTypeDef); // create an array of - NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_Array::CreateInstance( top, driveCount, storageFolderTypeDef )); + NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_Array::CreateInstance(top, driveCount, storageFolderTypeDef)); - if(driveCount > 0) + if (driveCount > 0) { // there are driver present and enumerated // get a pointer to the first object in the array (which is of type ) - storageFolder = (CLR_RT_HeapBlock*)top.DereferenceArray()->GetFirstElement(); + storageFolder = (CLR_RT_HeapBlock *)top.DereferenceArray()->GetFirstElement(); // create an instance of NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.NewObjectFromIndex(*storageFolder, storageFolderTypeDef)); // loop until we've loaded all the possible drives // because we are iterating through an enum, need to use its integer values - for(uint16_t driveIterator = 0; driveIterator < driveCount; driveIterator++ ) + for (uint16_t driveIterator = 0; driveIterator < driveCount; driveIterator++) { char workingDrive[sizeof(DRIVE_PATH_LENGTH)]; // fill the folder name and path - switch(driveIterator) + switch (driveIterator) { case 0: memcpy(workingDrive, INDEX0_DRIVE_PATH, DRIVE_PATH_LENGTH); @@ -106,14 +107,18 @@ HRESULT Library_win_storage_native_Windows_Storage_StorageFolder::GetRemovableSt CLR_RT_HeapBlock *hbObj = storageFolder->Dereference(); // set the managed fields - NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_String::CreateInstance( hbObj[ Library_win_storage_native_Windows_Storage_StorageFolder::FIELD___name ], workingDrive )); - NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_String::CreateInstance( hbObj[ Library_win_storage_native_Windows_Storage_StorageFolder::FIELD___path ], workingDrive )); + NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_String::CreateInstance( + hbObj[Library_win_storage_native_Windows_Storage_StorageFolder::FIELD___name], + workingDrive)); + NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_String::CreateInstance( + hbObj[Library_win_storage_native_Windows_Storage_StorageFolder::FIELD___path], + workingDrive)); // malloc stringBuffer to work with FS - char* stringBuffer = (char*)malloc(FF_LFN_BUF + 1); + char *stringBuffer = (char *)malloc(FF_LFN_BUF + 1); // sanity check for successfull malloc - if(stringBuffer == NULL) + if (stringBuffer == NULL) { // failed to allocate memory NANOCLR_SET_AND_LEAVE(CLR_E_OUT_OF_MEMORY); @@ -124,11 +129,12 @@ HRESULT Library_win_storage_native_Windows_Storage_StorageFolder::GetRemovableSt memset(stringBuffer, 0, FF_LFN_BUF + 1); // read the drive volume label - // don't bother checking the result, if anything goes wrong we'll end up with an empty string which is OK + // don't bother checking the result, if anything goes wrong we'll end up with an empty string which is + // OK f_getlabel(workingDrive, stringBuffer, NULL); // add the driver letter separated it with an empty space, if the volume label isn't empty - if(*stringBuffer != '\0') + if (*stringBuffer != '\0') { strcat(stringBuffer, " "); } @@ -137,8 +143,9 @@ HRESULT Library_win_storage_native_Windows_Storage_StorageFolder::GetRemovableSt strcat(stringBuffer, ")"); // set the field with the volume label - NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_String::CreateInstance( hbObj[ Library_win_storage_native_Windows_Storage_StorageFolder::FIELD___name ], stringBuffer )); - + NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_String::CreateInstance( + hbObj[Library_win_storage_native_Windows_Storage_StorageFolder::FIELD___name], + stringBuffer)); // free stringBuffer free(stringBuffer); @@ -152,13 +159,14 @@ HRESULT Library_win_storage_native_Windows_Storage_StorageFolder::GetRemovableSt NANOCLR_NOCLEANUP(); } -HRESULT Library_win_storage_native_Windows_Storage_StorageFolder::GetInternalStorageFoldersNative___SZARRAY_WindowsStorageStorageFolder(CLR_RT_StackFrame& stack) +HRESULT Library_win_storage_native_Windows_Storage_StorageFolder:: + GetInternalStorageFoldersNative___SZARRAY_WindowsStorageStorageFolder(CLR_RT_StackFrame &stack) { -NANOCLR_HEADER(); + NANOCLR_HEADER(); { CLR_RT_TypeDef_Index storageFolderTypeDef; - CLR_RT_HeapBlock& top = stack.PushValue(); + CLR_RT_HeapBlock &top = stack.PushValue(); // start composing the reply // find type definition, don't bother checking the result as it exists for sure @@ -170,38 +178,41 @@ NANOCLR_HEADER(); NANOCLR_NOCLEANUP(); } -HRESULT Library_win_storage_native_Windows_Storage_StorageFolder::GetStorageFoldersNative___SZARRAY_WindowsStorageStorageFolder( CLR_RT_StackFrame& stack ) +HRESULT Library_win_storage_native_Windows_Storage_StorageFolder:: + GetStorageFoldersNative___SZARRAY_WindowsStorageStorageFolder(CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); - CLR_RT_TypeDef_Index storageFolderTypeDef; - CLR_RT_HeapBlock* storageFolder; - CLR_RT_HeapBlock* hbObj; - SYSTEMTIME fileInfoTime; + CLR_RT_TypeDef_Index storageFolderTypeDef; + CLR_RT_HeapBlock *storageFolder; + CLR_RT_HeapBlock *hbObj; + SYSTEMTIME fileInfoTime; - const char* workingPath; + const char *workingPath; - DIR currentDirectory; - FRESULT operationResult; - static FILINFO fileInfo; - uint16_t directoryCount = 0; - char* stringBuffer = NULL; - char* workingBuffer = NULL; + DIR currentDirectory; + FRESULT operationResult; + static FILINFO fileInfo; + uint16_t directoryCount = 0; + char *stringBuffer = NULL; + char *workingBuffer = NULL; - CLR_RT_HeapBlock& top = stack.PushValue(); + CLR_RT_HeapBlock &top = stack.PushValue(); // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); - + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + // get a pointer to the path in managed field - workingPath = pThis[ Library_win_storage_native_Windows_Storage_StorageFolder::FIELD___path ].DereferenceString()->StringText(); + workingPath = + pThis[Library_win_storage_native_Windows_Storage_StorageFolder::FIELD___path].DereferenceString()->StringText(); // open directory operationResult = f_opendir(¤tDirectory, workingPath); - if(operationResult != FR_OK) + if (operationResult != FR_OK) { - if(operationResult == FR_INVALID_DRIVE) + if (operationResult == FR_INVALID_DRIVE) { // failed to change drive NANOCLR_SET_AND_LEAVE(CLR_E_VOLUME_NOT_FOUND); @@ -209,10 +220,10 @@ HRESULT Library_win_storage_native_Windows_Storage_StorageFolder::GetStorageFold // error or directory empty // find type, don't bother checking the result as it exists for sure - g_CLR_RT_TypeSystem.FindTypeDef( "StorageFolder", "Windows.Storage", storageFolderTypeDef ); + g_CLR_RT_TypeSystem.FindTypeDef("StorageFolder", "Windows.Storage", storageFolderTypeDef); // create an array of - NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_Array::CreateInstance( top, directoryCount, storageFolderTypeDef )); + NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_Array::CreateInstance(top, directoryCount, storageFolderTypeDef)); } else { @@ -225,7 +236,7 @@ HRESULT Library_win_storage_native_Windows_Storage_StorageFolder::GetStorageFold { // read next directory item operationResult = f_readdir(¤tDirectory, &fileInfo); - + // break on error or at end of dir if (operationResult != FR_OK || fileInfo.fname[0] == 0) { @@ -236,31 +247,29 @@ HRESULT Library_win_storage_native_Windows_Storage_StorageFolder::GetStorageFold // but skip if: // - has system attribute set // - has hidden attribute set - if ((fileInfo.fattrib & AM_DIR) && - !(fileInfo.fattrib & AM_SYS) && - !(fileInfo.fattrib & AM_HID)) + if ((fileInfo.fattrib & AM_DIR) && !(fileInfo.fattrib & AM_SYS) && !(fileInfo.fattrib & AM_HID)) { directoryCount++; } } // find type, don't bother checking the result as it exists for sure - g_CLR_RT_TypeSystem.FindTypeDef( "StorageFolder", "Windows.Storage", storageFolderTypeDef ); + g_CLR_RT_TypeSystem.FindTypeDef("StorageFolder", "Windows.Storage", storageFolderTypeDef); // create an array of - NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_Array::CreateInstance( top, directoryCount, storageFolderTypeDef )); - + NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_Array::CreateInstance(top, directoryCount, storageFolderTypeDef)); + // get a pointer to the first object in the array (which is of type ) - storageFolder = (CLR_RT_HeapBlock*)top.DereferenceArray()->GetFirstElement(); + storageFolder = (CLR_RT_HeapBlock *)top.DereferenceArray()->GetFirstElement(); - if(directoryCount > 0) + if (directoryCount > 0) { // allocate memory for buffers - stringBuffer = (char*)malloc(FF_LFN_BUF + 1); - workingBuffer = (char*)malloc(2 * FF_LFN_BUF + 1); + stringBuffer = (char *)malloc(FF_LFN_BUF + 1); + workingBuffer = (char *)malloc(2 * FF_LFN_BUF + 1); // sanity check for successfull malloc - if(stringBuffer == NULL || workingBuffer == NULL) + if (stringBuffer == NULL || workingBuffer == NULL) { // failed to allocate memory NANOCLR_SET_AND_LEAVE(CLR_E_OUT_OF_MEMORY); @@ -269,12 +278,12 @@ HRESULT Library_win_storage_native_Windows_Storage_StorageFolder::GetStorageFold // perform 2nd pass // need to rewind the directory read index first f_readdir(¤tDirectory, NULL); - + for (;;) { // read next directory item operationResult = f_readdir(¤tDirectory, &fileInfo); - + // break on error or at end of dir if (operationResult != FR_OK || fileInfo.fname[0] == 0) { @@ -285,41 +294,48 @@ HRESULT Library_win_storage_native_Windows_Storage_StorageFolder::GetStorageFold // but skip if: // - has system attribute set // - has hidden attribute set - if ((fileInfo.fattrib & AM_DIR) && - !(fileInfo.fattrib & AM_SYS) && - !(fileInfo.fattrib & AM_HID)) + if ((fileInfo.fattrib & AM_DIR) && !(fileInfo.fattrib & AM_SYS) && !(fileInfo.fattrib & AM_HID)) { // create an instance of - NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.NewObjectFromIndex(*storageFolder, storageFolderTypeDef)); + NANOCLR_CHECK_HRESULT( + g_CLR_RT_ExecutionEngine.NewObjectFromIndex(*storageFolder, storageFolderTypeDef)); // dereference the object in order to reach its fields hbObj = storageFolder->Dereference(); // directory name - NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_String::CreateInstance( hbObj[ Library_win_storage_native_Windows_Storage_StorageFolder::FIELD___name ], fileInfo.fname )); + NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_String::CreateInstance( + hbObj[Library_win_storage_native_Windows_Storage_StorageFolder::FIELD___name], + fileInfo.fname)); // clear working buffer memset(workingBuffer, 0, 2 * FF_LFN_BUF + 1); // compose directory path CombinePath(workingBuffer, workingPath, fileInfo.fname); - - NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_String::CreateInstance( hbObj[ Library_win_storage_native_Windows_Storage_StorageFolder::FIELD___path ], workingBuffer )); - + + NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_String::CreateInstance( + hbObj[Library_win_storage_native_Windows_Storage_StorageFolder::FIELD___path], + workingBuffer)); + // compute directory date fileInfoTime = GetDateTime(fileInfo.fdate, fileInfo.ftime); - // get a reference to the dateCreated managed field... - CLR_RT_HeapBlock& timestampFieldRef = hbObj[Library_win_storage_native_Windows_Storage_StorageFolder::FIELD___dateCreated]; + // get a reference to the dateCreated managed field... + CLR_RT_HeapBlock ×tampFieldRef = + hbObj[Library_win_storage_native_Windows_Storage_StorageFolder::FIELD___dateCreated]; // create an instance of - NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.NewObjectFromIndex(timestampFieldRef, g_CLR_RT_WellKnownTypes.m_DateTime)); + NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.NewObjectFromIndex( + timestampFieldRef, + g_CLR_RT_WellKnownTypes.m_DateTime)); // get reference to this object - CLR_RT_HeapBlock *hbDateTime = timestampFieldRef.Dereference(); + CLR_RT_HeapBlock *hbDateTime = timestampFieldRef.Dereference(); // get reference to ticks field - CLR_RT_HeapBlock &dateTimeTickField = hbDateTime[Library_corlib_native_System_DateTime::FIELD___ticks]; + CLR_RT_HeapBlock &dateTimeTickField = + hbDateTime[Library_corlib_native_System_DateTime::FIELD___ticks]; CLR_INT64 *pRes = (CLR_INT64 *)&dateTimeTickField.NumericByRef().s8; // ...and set it with the fileInfoTime - *pRes = HAL_Time_ConvertFromSystemTime( &fileInfoTime ); + *pRes = HAL_Time_ConvertFromSystemTime(&fileInfoTime); // move the storage folder pointer to the next item in the array storageFolder++; @@ -334,11 +350,11 @@ HRESULT Library_win_storage_native_Windows_Storage_StorageFolder::GetStorageFold f_closedir(¤tDirectory); // free buffers memory, if allocated - if(stringBuffer != NULL) + if (stringBuffer != NULL) { free(stringBuffer); } - if(workingBuffer != NULL) + if (workingBuffer != NULL) { free(workingBuffer); } @@ -346,32 +362,34 @@ HRESULT Library_win_storage_native_Windows_Storage_StorageFolder::GetStorageFold NANOCLR_CLEANUP_END(); } -HRESULT Library_win_storage_native_Windows_Storage_StorageFolder::GetStorageFilesNative___SZARRAY_WindowsStorageStorageFile__U4__U4( CLR_RT_StackFrame& stack ) +HRESULT Library_win_storage_native_Windows_Storage_StorageFolder:: + GetStorageFilesNative___SZARRAY_WindowsStorageStorageFile__U4__U4(CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); - CLR_RT_TypeDef_Index storageFileTypeDef; - CLR_RT_HeapBlock* storageFile; - CLR_RT_HeapBlock* hbObj; - SYSTEMTIME fileInfoTime; + CLR_RT_TypeDef_Index storageFileTypeDef; + CLR_RT_HeapBlock *storageFile; + CLR_RT_HeapBlock *hbObj; + SYSTEMTIME fileInfoTime; - const char* workingPath; + const char *workingPath; char workingDrive[DRIVE_LETTER_LENGTH]; uint32_t startIndex; uint32_t maxItemsToRetrieve; - DIR currentDirectory; - FRESULT operationResult; - static FILINFO fileInfo; - uint16_t fileCount = 0; - char* stringBuffer = NULL; - char* workingBuffer = NULL; + DIR currentDirectory; + FRESULT operationResult; + static FILINFO fileInfo; + uint16_t fileCount = 0; + char *stringBuffer = NULL; + char *workingBuffer = NULL; - CLR_RT_HeapBlock& top = stack.PushValue(); + CLR_RT_HeapBlock &top = stack.PushValue(); // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); // get start index startIndex = stack.Arg1().NumericByRef().u4; @@ -381,22 +399,26 @@ HRESULT Library_win_storage_native_Windows_Storage_StorageFolder::GetStorageFile // copy the first 2 letters of the path for the drive // path is 'D:\folder\file.txt', so we need 'D:' - memcpy(workingDrive, pThis[ Library_win_storage_native_Windows_Storage_StorageFolder::FIELD___path ].DereferenceString()->StringText(), DRIVE_LETTER_LENGTH); - + memcpy( + workingDrive, + pThis[Library_win_storage_native_Windows_Storage_StorageFolder::FIELD___path].DereferenceString()->StringText(), + DRIVE_LETTER_LENGTH); + // get a pointer to the path in managed field - workingPath = pThis[ Library_win_storage_native_Windows_Storage_StorageFolder::FIELD___path ].DereferenceString()->StringText(); + workingPath = + pThis[Library_win_storage_native_Windows_Storage_StorageFolder::FIELD___path].DereferenceString()->StringText(); // open directory operationResult = f_opendir(¤tDirectory, workingPath); - if(operationResult != FR_OK) + if (operationResult != FR_OK) { // error or directory empty // find type, don't bother checking the result as it exists for sure - g_CLR_RT_TypeSystem.FindTypeDef( "StorageFile", "Windows.Storage", storageFileTypeDef ); + g_CLR_RT_TypeSystem.FindTypeDef("StorageFile", "Windows.Storage", storageFileTypeDef); // create an array of - NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_Array::CreateInstance( top, fileCount, storageFileTypeDef )); + NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_Array::CreateInstance(top, fileCount, storageFileTypeDef)); } else { @@ -411,7 +433,7 @@ HRESULT Library_win_storage_native_Windows_Storage_StorageFolder::GetStorageFile { // read next directory item operationResult = f_readdir(¤tDirectory, &fileInfo); - + // break on error or at end of dir if (operationResult != FR_OK || fileInfo.fname[0] == 0) { @@ -422,13 +444,10 @@ HRESULT Library_win_storage_native_Windows_Storage_StorageFolder::GetStorageFile // but skip if: // - has system attribute set // - has hidden attribute set - if ((fileInfo.fattrib & AM_ARC) && - !(fileInfo.fattrib & AM_SYS) && - !(fileInfo.fattrib & AM_HID)) + if ((fileInfo.fattrib & AM_ARC) && !(fileInfo.fattrib & AM_SYS) && !(fileInfo.fattrib & AM_HID)) { // check if this file is within the requested parameters - if( (itemIndex >= startIndex) && - (fileCount < maxItemsToRetrieve)) + if ((itemIndex >= startIndex) && (fileCount < maxItemsToRetrieve)) { fileCount++; } @@ -438,22 +457,22 @@ HRESULT Library_win_storage_native_Windows_Storage_StorageFolder::GetStorageFile } // find type, don't bother checking the result as it exists for sure - g_CLR_RT_TypeSystem.FindTypeDef( "StorageFile", "Windows.Storage", storageFileTypeDef ); + g_CLR_RT_TypeSystem.FindTypeDef("StorageFile", "Windows.Storage", storageFileTypeDef); // create an array of - NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_Array::CreateInstance( top, fileCount, storageFileTypeDef )); - + NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_Array::CreateInstance(top, fileCount, storageFileTypeDef)); + // get a pointer to the first object in the array (which is of type ) - storageFile = (CLR_RT_HeapBlock*)top.DereferenceArray()->GetFirstElement(); + storageFile = (CLR_RT_HeapBlock *)top.DereferenceArray()->GetFirstElement(); - if(fileCount > 0) + if (fileCount > 0) { // allocate memory for buffers - stringBuffer = (char*)malloc(FF_LFN_BUF + 1); - workingBuffer = (char*)malloc(2 * FF_LFN_BUF + 1); + stringBuffer = (char *)malloc(FF_LFN_BUF + 1); + workingBuffer = (char *)malloc(2 * FF_LFN_BUF + 1); // sanity check for successfull malloc - if(stringBuffer == NULL || workingBuffer == NULL) + if (stringBuffer == NULL || workingBuffer == NULL) { // failed to allocate memory NANOCLR_SET_AND_LEAVE(CLR_E_OUT_OF_MEMORY); @@ -467,12 +486,11 @@ HRESULT Library_win_storage_native_Windows_Storage_StorageFolder::GetStorageFile itemIndex = 0; fileCount = 0; - for (;;) { // read next directory item operationResult = f_readdir(¤tDirectory, &fileInfo); - + // break on error or at end of dir if (operationResult != FR_OK || fileInfo.fname[0] == 0) { @@ -483,22 +501,22 @@ HRESULT Library_win_storage_native_Windows_Storage_StorageFolder::GetStorageFile // but skip if: // - has system attribute set // - has hidden attribute set - if ((fileInfo.fattrib & AM_ARC) && - !(fileInfo.fattrib & AM_SYS) && - !(fileInfo.fattrib & AM_HID)) + if ((fileInfo.fattrib & AM_ARC) && !(fileInfo.fattrib & AM_SYS) && !(fileInfo.fattrib & AM_HID)) { // check if this file is within the requested parameters - if( (itemIndex >= startIndex) && - (fileCount < maxItemsToRetrieve)) + if ((itemIndex >= startIndex) && (fileCount < maxItemsToRetrieve)) { // create an instance of - NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.NewObjectFromIndex(*storageFile, storageFileTypeDef)); + NANOCLR_CHECK_HRESULT( + g_CLR_RT_ExecutionEngine.NewObjectFromIndex(*storageFile, storageFileTypeDef)); // dereference the object in order to reach its fields hbObj = storageFile->Dereference(); // file name - NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_String::CreateInstance( hbObj[ Library_win_storage_native_Windows_Storage_StorageFile::FIELD___name ], fileInfo.fname )); + NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_String::CreateInstance( + hbObj[Library_win_storage_native_Windows_Storage_StorageFile::FIELD___name], + fileInfo.fname)); // clear working buffer memset(workingBuffer, 0, 2 * FF_LFN_BUF + 1); @@ -506,22 +524,28 @@ HRESULT Library_win_storage_native_Windows_Storage_StorageFolder::GetStorageFile // compose file path CombinePath(workingBuffer, workingPath, fileInfo.fname); - NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_String::CreateInstance( hbObj[ Library_win_storage_native_Windows_Storage_StorageFile::FIELD___path ], workingBuffer )); + NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_String::CreateInstance( + hbObj[Library_win_storage_native_Windows_Storage_StorageFile::FIELD___path], + workingBuffer)); // compute directory date fileInfoTime = GetDateTime(fileInfo.fdate, fileInfo.ftime); // get a reference to the dateCreated managed field... - CLR_RT_HeapBlock& timestampFieldRef = hbObj[Library_win_storage_native_Windows_Storage_StorageFile::FIELD___dateCreated]; + CLR_RT_HeapBlock ×tampFieldRef = + hbObj[Library_win_storage_native_Windows_Storage_StorageFile::FIELD___dateCreated]; // create an instance of - NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.NewObjectFromIndex(timestampFieldRef, g_CLR_RT_WellKnownTypes.m_DateTime)); + NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.NewObjectFromIndex( + timestampFieldRef, + g_CLR_RT_WellKnownTypes.m_DateTime)); // get reference to this object - CLR_RT_HeapBlock *hbDateTime = timestampFieldRef.Dereference(); + CLR_RT_HeapBlock *hbDateTime = timestampFieldRef.Dereference(); // get reference to ticks field - CLR_RT_HeapBlock &dateTimeTickField = hbDateTime[Library_corlib_native_System_DateTime::FIELD___ticks]; + CLR_RT_HeapBlock &dateTimeTickField = + hbDateTime[Library_corlib_native_System_DateTime::FIELD___ticks]; CLR_INT64 *pRes = (CLR_INT64 *)&dateTimeTickField.NumericByRef().s8; // ...and set it with the fileInfoTime - *pRes = HAL_Time_ConvertFromSystemTime( &fileInfoTime ); + *pRes = HAL_Time_ConvertFromSystemTime(&fileInfoTime); // move the storage folder pointer to the next item in the array storageFile++; @@ -539,10 +563,10 @@ HRESULT Library_win_storage_native_Windows_Storage_StorageFolder::GetStorageFile { // empty directory // find type, don't bother checking the result as it exists for sure - g_CLR_RT_TypeSystem.FindTypeDef( "StorageFile", "Windows.Storage", storageFileTypeDef ); + g_CLR_RT_TypeSystem.FindTypeDef("StorageFile", "Windows.Storage", storageFileTypeDef); // create an array of - NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_Array::CreateInstance( top, fileCount, storageFileTypeDef )); + NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_Array::CreateInstance(top, fileCount, storageFileTypeDef)); } } @@ -552,11 +576,11 @@ HRESULT Library_win_storage_native_Windows_Storage_StorageFolder::GetStorageFile f_closedir(¤tDirectory); // free buffers memory, if allocated - if(stringBuffer != NULL) + if (stringBuffer != NULL) { free(stringBuffer); } - if(workingBuffer != NULL) + if (workingBuffer != NULL) { free(workingBuffer); } @@ -564,82 +588,88 @@ HRESULT Library_win_storage_native_Windows_Storage_StorageFolder::GetStorageFile NANOCLR_CLEANUP_END(); } -struct FileOperation { - const char *FilePath; - uint8_t mode; - enum CreationCollisionOption options; +struct FileOperation +{ + const char *FilePath; + uint8_t mode; + enum CreationCollisionOption options; }; // this is the FileIO working thread static volatile FRESULT threadOperationResult; // CreateFile working thread -static void CreateFileWorkingThread(void *arg) { +static void CreateFileWorkingThread(void *arg) +{ - FileOperation *fileIoOperation = reinterpret_cast(arg); + FileOperation *fileIoOperation = reinterpret_cast(arg); - // create file struct - FIL file; + // create file struct + FIL file; - // open file - FRESULT operationResult = f_open(&file, fileIoOperation->FilePath, fileIoOperation->mode); + // open file + FRESULT operationResult = f_open(&file, fileIoOperation->FilePath, fileIoOperation->mode); - // process operation result according to creation options - if ((operationResult == FR_EXIST) && (fileIoOperation->options == CreationCollisionOption_FailIfExists)) { - // file already exists - threadOperationResult = FR_EXIST; - f_close(&file); - return; - } - if ((operationResult == FR_NO_FILE) && (fileIoOperation->options == CreationCollisionOption_OpenIfExists)) { - // file doesn't exist - threadOperationResult = FR_NO_FILE; - f_close(&file); - return; - } + // process operation result according to creation options + if ((operationResult == FR_EXIST) && (fileIoOperation->options == CreationCollisionOption_FailIfExists)) + { + // file already exists + threadOperationResult = FR_EXIST; + f_close(&file); + return; + } + if ((operationResult == FR_NO_FILE) && (fileIoOperation->options == CreationCollisionOption_OpenIfExists)) + { + // file doesn't exist + threadOperationResult = FR_NO_FILE; + f_close(&file); + return; + } - threadOperationResult = FR_OK; + threadOperationResult = FR_OK; - // close file - f_close(&file); + // close file + f_close(&file); - // free memory - free((void *)fileIoOperation->FilePath); - free(fileIoOperation); + // free memory + free((void *)fileIoOperation->FilePath); + free(fileIoOperation); - // fire event for FileIO operation complete - Events_Set(SYSTEM_EVENT_FLAG_STORAGE_IO); + // fire event for FileIO operation complete + Events_Set(SYSTEM_EVENT_FLAG_STORAGE_IO); - vTaskDelete(NULL); + vTaskDelete(NULL); } -HRESULT Library_win_storage_native_Windows_Storage_StorageFolder::CreateFileNative___WindowsStorageStorageFile__STRING__U4( CLR_RT_StackFrame& stack ) +HRESULT Library_win_storage_native_Windows_Storage_StorageFolder:: + CreateFileNative___WindowsStorageStorageFile__STRING__U4(CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); - - CLR_RT_HeapBlock hbTimeout; - CLR_INT64* timeout; - bool eventResult = true; - CLR_RT_TypeDef_Index storageFileTypeDef; - CLR_RT_HeapBlock* storageFile; + CLR_RT_HeapBlock hbTimeout; + CLR_INT64 *timeout; + bool eventResult = true; + + CLR_RT_TypeDef_Index storageFileTypeDef; + CLR_RT_HeapBlock *storageFile; - const char* fileName; - const char* workingPath; + const char *fileName; + const char *workingPath; CreationCollisionOption options; - - char* filePath = NULL; + char *filePath = NULL; // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); // get creation collision options options = (CreationCollisionOption)stack.Arg2().NumericByRef().u4; - + // get a pointer to the StorageFolder path in managed field - workingPath = pThis[ Library_win_storage_native_Windows_Storage_StorageFolder::FIELD___path ].DereferenceString()->StringText(); + workingPath = + pThis[Library_win_storage_native_Windows_Storage_StorageFolder::FIELD___path].DereferenceString()->StringText(); // get a pointer to the desired file name fileName = stack.Arg1().DereferenceString()->StringText(); @@ -647,16 +677,16 @@ HRESULT Library_win_storage_native_Windows_Storage_StorageFolder::CreateFileNati // !! need to cast to CLR_INT64 otherwise it wont setup a proper timeout infinite hbTimeout.SetInteger((CLR_INT64)-1); - NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks( hbTimeout, timeout )); + NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks(hbTimeout, timeout)); - if(stack.m_customState == 1) - { + if (stack.m_customState == 1) + { // setup file path - filePath = (char*)malloc(2 * FF_LFN_BUF + 1); + filePath = (char *)malloc(2 * FF_LFN_BUF + 1); // sanity check for successfull malloc - if(filePath == NULL) + if (filePath == NULL) { // failed to allocate memory NANOCLR_SET_AND_LEAVE(CLR_E_OUT_OF_MEMORY); @@ -683,7 +713,7 @@ HRESULT Library_win_storage_native_Windows_Storage_StorageFolder::CreateFileNati case CreationCollisionOption_OpenIfExists: modeFlags = FA_OPEN_ALWAYS; break; - + case CreationCollisionOption_GenerateUniqueName: // this operation is not supported in nanoFramework NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); @@ -701,7 +731,13 @@ HRESULT Library_win_storage_native_Windows_Storage_StorageFolder::CreateFileNati // spawn working thread to perform the write transaction BaseType_t ret; - ret = xTaskCreate(CreateFileWorkingThread, "CreateFile", configMINIMAL_STACK_SIZE + 600, fileOperation, configMAX_PRIORITIES - 2, NULL); + ret = xTaskCreate( + CreateFileWorkingThread, + "CreateFile", + configMINIMAL_STACK_SIZE + 600, + fileOperation, + configMAX_PRIORITIES - 2, + NULL); if (ret != pdPASS) { @@ -709,31 +745,32 @@ HRESULT Library_win_storage_native_Windows_Storage_StorageFolder::CreateFileNati } // bump custom state - stack.m_customState = 2; + stack.m_customState = 2; } - while(eventResult) + while (eventResult) { // non-blocking wait allowing other threads to run while we wait for the write operation to complete - NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.WaitEvents( stack.m_owningThread, *timeout, CLR_RT_ExecutionEngine::c_Event_StorageIo, eventResult )); + NANOCLR_CHECK_HRESULT( + g_CLR_RT_ExecutionEngine.WaitEvents(stack.m_owningThread, *timeout, Event_StorageIo, eventResult)); - if(eventResult) + if (eventResult) { // event occurred - if(threadOperationResult == FR_DISK_ERR) + if (threadOperationResult == FR_DISK_ERR) { - NANOCLR_SET_AND_LEAVE( CLR_E_FILE_IO ); + NANOCLR_SET_AND_LEAVE(CLR_E_FILE_IO); } - else if(threadOperationResult == FR_NO_FILE) + else if (threadOperationResult == FR_NO_FILE) { - NANOCLR_SET_AND_LEAVE( CLR_E_FILE_NOT_FOUND ); + NANOCLR_SET_AND_LEAVE(CLR_E_FILE_NOT_FOUND); } - else if(threadOperationResult == FR_EXIST) + else if (threadOperationResult == FR_EXIST) { - NANOCLR_SET_AND_LEAVE( CLR_E_PATH_ALREADY_EXISTS); + NANOCLR_SET_AND_LEAVE(CLR_E_PATH_ALREADY_EXISTS); } - else if(threadOperationResult == FR_INVALID_DRIVE) + else if (threadOperationResult == FR_INVALID_DRIVE) { // failed to change drive NANOCLR_SET_AND_LEAVE(CLR_E_VOLUME_NOT_FOUND); @@ -744,19 +781,19 @@ HRESULT Library_win_storage_native_Windows_Storage_StorageFolder::CreateFileNati // compose return object // find type, don't bother checking the result as it exists for sure - g_CLR_RT_TypeSystem.FindTypeDef( "StorageFile", "Windows.Storage", storageFileTypeDef ); + g_CLR_RT_TypeSystem.FindTypeDef("StorageFile", "Windows.Storage", storageFileTypeDef); // create a NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.NewObjectFromIndex(stack.PushValue(), storageFileTypeDef)); - + // get a handle to the storage file storageFile = stack.TopValue().Dereference(); // setup file path - filePath = (char*)malloc(2 * FF_LFN_BUF + 1); + filePath = (char *)malloc(2 * FF_LFN_BUF + 1); // sanity check for successfull malloc - if(filePath == NULL) + if (filePath == NULL) { // failed to allocate memory NANOCLR_SET_AND_LEAVE(CLR_E_OUT_OF_MEMORY); @@ -769,19 +806,25 @@ HRESULT Library_win_storage_native_Windows_Storage_StorageFolder::CreateFileNati CombinePath(filePath, workingPath, fileName); // file name - NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_String::CreateInstance( storageFile[ Library_win_storage_native_Windows_Storage_StorageFile::FIELD___name ], fileName )); + NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_String::CreateInstance( + storageFile[Library_win_storage_native_Windows_Storage_StorageFile::FIELD___name], + fileName)); - NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_String::CreateInstance( storageFile[ Library_win_storage_native_Windows_Storage_StorageFile::FIELD___path ], filePath )); + NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_String::CreateInstance( + storageFile[Library_win_storage_native_Windows_Storage_StorageFile::FIELD___path], + filePath)); // get a reference to the dateCreated managed field... - CLR_RT_HeapBlock& timestampFieldRef = storageFile[Library_win_storage_native_Windows_Storage_StorageFile::FIELD___dateCreated]; - // create an instance of - NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.NewObjectFromIndex(timestampFieldRef, g_CLR_RT_WellKnownTypes.m_DateTime)); - // get reference to this object - CLR_RT_HeapBlock *hbDateTime = timestampFieldRef.Dereference(); - // get reference to ticks field - CLR_RT_HeapBlock &dateTimeTickField = hbDateTime[Library_corlib_native_System_DateTime::FIELD___ticks]; - CLR_INT64 *pRes = (CLR_INT64 *)&dateTimeTickField.NumericByRef().s8; + CLR_RT_HeapBlock ×tampFieldRef = + storageFile[Library_win_storage_native_Windows_Storage_StorageFile::FIELD___dateCreated]; + // create an instance of + NANOCLR_CHECK_HRESULT( + g_CLR_RT_ExecutionEngine.NewObjectFromIndex(timestampFieldRef, g_CLR_RT_WellKnownTypes.m_DateTime)); + // get reference to this object + CLR_RT_HeapBlock *hbDateTime = timestampFieldRef.Dereference(); + // get reference to ticks field + CLR_RT_HeapBlock &dateTimeTickField = hbDateTime[Library_corlib_native_System_DateTime::FIELD___ticks]; + CLR_INT64 *pRes = (CLR_INT64 *)&dateTimeTickField.NumericByRef().s8; // ...and set it with the current DateTime *pRes = HAL_Time_CurrentDateTime(false); @@ -792,48 +835,50 @@ HRESULT Library_win_storage_native_Windows_Storage_StorageFolder::CreateFileNati } else { - NANOCLR_SET_AND_LEAVE( CLR_E_TIMEOUT ); + NANOCLR_SET_AND_LEAVE(CLR_E_TIMEOUT); } } - - NANOCLR_NOCLEANUP(); } -HRESULT Library_win_storage_native_Windows_Storage_StorageFolder::CreateFolderNative___WindowsStorageStorageFolder__STRING__U4( CLR_RT_StackFrame& stack ) +HRESULT Library_win_storage_native_Windows_Storage_StorageFolder:: + CreateFolderNative___WindowsStorageStorageFolder__STRING__U4(CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); - CLR_RT_TypeDef_Index storageFolderTypeDef; - CLR_RT_HeapBlock* storageFolder; + CLR_RT_TypeDef_Index storageFolderTypeDef; + CLR_RT_HeapBlock *storageFolder; - const char* folderName; - const char* workingPath; + const char *folderName; + const char *workingPath; CreationCollisionOption options; - static FILINFO fileInfo; - SYSTEMTIME fileInfoTime; - FRESULT operationResult; - char* folderPath = NULL; + static FILINFO fileInfo; + SYSTEMTIME fileInfoTime; + FRESULT operationResult; + char *folderPath = NULL; { // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); // get creation collision options options = (CreationCollisionOption)stack.Arg2().NumericByRef().u4; - + // get a pointer to the path in managed field - workingPath = pThis[ Library_win_storage_native_Windows_Storage_StorageFolder::FIELD___path ].DereferenceString()->StringText(); + workingPath = pThis[Library_win_storage_native_Windows_Storage_StorageFolder::FIELD___path] + .DereferenceString() + ->StringText(); // get a pointer to the desired folder name folderName = stack.Arg1().DereferenceString()->StringText(); - folderPath = (char*)malloc(2 * FF_LFN_BUF + 1); + folderPath = (char *)malloc(2 * FF_LFN_BUF + 1); // sanity check for successfull malloc - if(folderPath == NULL) + if (folderPath == NULL) { // failed to allocate memory NANOCLR_SET_AND_LEAVE(CLR_E_OUT_OF_MEMORY); @@ -843,9 +888,9 @@ HRESULT Library_win_storage_native_Windows_Storage_StorageFolder::CreateFolderNa memset(folderPath, 0, 2 * FF_LFN_BUF + 1); // compose folder path - CombinePath(folderPath, workingPath, folderName); - - //check if folder exists + CombinePath(folderPath, workingPath, folderName); + + // check if folder exists operationResult = f_stat(folderPath, &fileInfo); if (operationResult == FR_OK) @@ -855,7 +900,7 @@ HRESULT Library_win_storage_native_Windows_Storage_StorageFolder::CreateFolderNa // folder already exists NANOCLR_SET_AND_LEAVE(CLR_E_PATH_ALREADY_EXISTS); } - else if (options == CreationCollisionOption_ReplaceExisting) + else if (options == CreationCollisionOption_ReplaceExisting) { // remove folder operationResult = f_unlink(folderPath); @@ -866,17 +911,17 @@ HRESULT Library_win_storage_native_Windows_Storage_StorageFolder::CreateFolderNa } else if (operationResult == FR_DENIED) { - //folder is propably not empty - //TODO - add recursive deletion of directories and files + // folder is propably not empty + // TODO - add recursive deletion of directories and files NANOCLR_SET_AND_LEAVE(CLR_E_FILE_IO); } // create directory operationResult = f_mkdir(folderPath); - if(operationResult == FR_OK) + if (operationResult == FR_OK) { - f_stat(folderPath, &fileInfo); + f_stat(folderPath, &fileInfo); } else { @@ -886,18 +931,18 @@ HRESULT Library_win_storage_native_Windows_Storage_StorageFolder::CreateFolderNa } else if (options == CreationCollisionOption_GenerateUniqueName) { - //TODO - add generating unique name + // TODO - add generating unique name NANOCLR_SET_AND_LEAVE(CLR_E_FILE_IO); } - } + } else if (operationResult == FR_NO_FILE) { // create directory operationResult = f_mkdir(folderPath); - if(operationResult == FR_OK) + if (operationResult == FR_OK) { - f_stat(folderPath, &fileInfo); + f_stat(folderPath, &fileInfo); } else { @@ -908,40 +953,46 @@ HRESULT Library_win_storage_native_Windows_Storage_StorageFolder::CreateFolderNa // compose return object // find type, don't bother checking the result as it exists for sure - g_CLR_RT_TypeSystem.FindTypeDef( "StorageFolder", "Windows.Storage", storageFolderTypeDef ); + g_CLR_RT_TypeSystem.FindTypeDef("StorageFolder", "Windows.Storage", storageFolderTypeDef); // create a NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.NewObjectFromIndex(stack.PushValue(), storageFolderTypeDef)); - + // get a handle to the storage folder storageFolder = stack.TopValue().Dereference(); // folder name - NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_String::CreateInstance( storageFolder[ Library_win_storage_native_Windows_Storage_StorageFolder::FIELD___name ], folderName )); + NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_String::CreateInstance( + storageFolder[Library_win_storage_native_Windows_Storage_StorageFolder::FIELD___name], + folderName)); - NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_String::CreateInstance( storageFolder[ Library_win_storage_native_Windows_Storage_StorageFolder::FIELD___path ], folderPath )); + NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_String::CreateInstance( + storageFolder[Library_win_storage_native_Windows_Storage_StorageFolder::FIELD___path], + folderPath)); // get the date time details and fill in the managed field // compute directory date fileInfoTime = GetDateTime(fileInfo.fdate, fileInfo.ftime); // get a reference to the dateCreated managed field and set it with the fileInfoTime - CLR_RT_HeapBlock& timestampFieldRef = storageFolder[Library_win_storage_native_Windows_Storage_StorageFolder::FIELD___dateCreated]; + CLR_RT_HeapBlock ×tampFieldRef = + storageFolder[Library_win_storage_native_Windows_Storage_StorageFolder::FIELD___dateCreated]; // create an instance of - NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.NewObjectFromIndex(timestampFieldRef, g_CLR_RT_WellKnownTypes.m_DateTime)); + NANOCLR_CHECK_HRESULT( + g_CLR_RT_ExecutionEngine.NewObjectFromIndex(timestampFieldRef, g_CLR_RT_WellKnownTypes.m_DateTime)); // get reference to this object - CLR_RT_HeapBlock *hbDateTime = timestampFieldRef.Dereference(); + CLR_RT_HeapBlock *hbDateTime = timestampFieldRef.Dereference(); // get reference to ticks field CLR_RT_HeapBlock &dateTimeTickField = hbDateTime[Library_corlib_native_System_DateTime::FIELD___ticks]; CLR_INT64 *pRes = (CLR_INT64 *)&dateTimeTickField.NumericByRef().s8; - + // ...and set it with the fileInfoTime - *pRes = HAL_Time_ConvertFromSystemTime( &fileInfoTime ); + *pRes = HAL_Time_ConvertFromSystemTime(&fileInfoTime); } NANOCLR_CLEANUP(); // free buffer memory, if allocated - if(folderPath != NULL) + if (folderPath != NULL) { free(folderPath); } @@ -949,37 +1000,44 @@ HRESULT Library_win_storage_native_Windows_Storage_StorageFolder::CreateFolderNa NANOCLR_CLEANUP_END(); } -HRESULT Library_win_storage_native_Windows_Storage_StorageFolder::DeleteFolderNative___VOID(CLR_RT_StackFrame& stack) +HRESULT Library_win_storage_native_Windows_Storage_StorageFolder::DeleteFolderNative___VOID(CLR_RT_StackFrame &stack) { - NANOCLR_HEADER(); + NANOCLR_HEADER(); - const char* workingPath; + const char *workingPath; // need extra room for the change dir command char workingDrive[DRIVE_LETTER_LENGTH + 2]; - FRESULT operationResult; - - // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); - - // get a pointer to the path in managed field - workingPath = pThis[Library_win_storage_native_Windows_Storage_StorageFolder::FIELD___path].DereferenceString()->StringText(); - - // remove folder - operationResult = f_unlink(workingPath); - if (operationResult == FR_INVALID_NAME) - { - // Invalid path - NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); - } - else if (operationResult == FR_DENIED) - { + FRESULT operationResult; + + // get a pointer to the managed object instance and check that it's not NULL + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + + // get a pointer to the path in managed field + workingPath = + pThis[Library_win_storage_native_Windows_Storage_StorageFolder::FIELD___path].DereferenceString()->StringText(); + + // remove folder + operationResult = f_unlink(workingPath); + if (operationResult == FR_INVALID_NAME) + { + // Invalid path + NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); + } + else if (operationResult == FR_DENIED) + { // this could be because the folder is not empty or because it's the current folder - + // change directory to the parent directory using f_chdir("2:..") // copy the first 2 letters of the path for the drive // path is 'D:\folder\file.txt', so we need 'D:' - memcpy(workingDrive, pThis[Library_win_storage_native_Windows_Storage_StorageFolder::FIELD___path ].DereferenceString()->StringText(), DRIVE_LETTER_LENGTH); + memcpy( + workingDrive, + pThis[Library_win_storage_native_Windows_Storage_StorageFolder::FIELD___path] + .DereferenceString() + ->StringText(), + DRIVE_LETTER_LENGTH); // make sure there is a terminator workingDrive[2] = '\0'; strcat(workingDrive, ".."); @@ -1000,104 +1058,110 @@ HRESULT Library_win_storage_native_Windows_Storage_StorageFolder::DeleteFolderNa // something else is failing NANOCLR_SET_AND_LEAVE(CLR_E_FILE_IO); } - } - else if (operationResult != FR_OK) - { - // folder doesn't exist + } + else if (operationResult != FR_OK) + { + // folder doesn't exist NANOCLR_SET_AND_LEAVE(CLR_E_DIRECTORY_NOT_FOUND); - } + } - NANOCLR_CLEANUP(); + NANOCLR_CLEANUP(); - NANOCLR_CLEANUP_END(); + NANOCLR_CLEANUP_END(); } -HRESULT Library_win_storage_native_Windows_Storage_StorageFolder::RenameFolderNative___VOID__STRING(CLR_RT_StackFrame& stack) +HRESULT Library_win_storage_native_Windows_Storage_StorageFolder::RenameFolderNative___VOID__STRING( + CLR_RT_StackFrame &stack) { - NANOCLR_HEADER(); + NANOCLR_HEADER(); - const char* workingPath; - const char* desiredPath; - FRESULT operationResult; + const char *workingPath; + const char *desiredPath; + FRESULT operationResult; - // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + // get a pointer to the managed object instance and check that it's not NULL + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); - // get a pointer to the path in managed field - workingPath = pThis[Library_win_storage_native_Windows_Storage_StorageFolder::FIELD___path].DereferenceString()->StringText(); + // get a pointer to the path in managed field + workingPath = + pThis[Library_win_storage_native_Windows_Storage_StorageFolder::FIELD___path].DereferenceString()->StringText(); - // get a pointer to the desired folder name - desiredPath = stack.Arg1().DereferenceString()->StringText(); + // get a pointer to the desired folder name + desiredPath = stack.Arg1().DereferenceString()->StringText(); - // rename folder - operationResult = f_rename(workingPath, desiredPath); - if (operationResult == FR_INVALID_NAME) - { - // invalid path - NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); - } - else if (operationResult != FR_OK) - { - // folder doesn't exist - NANOCLR_SET_AND_LEAVE(CLR_E_DIRECTORY_NOT_FOUND); - } + // rename folder + operationResult = f_rename(workingPath, desiredPath); + if (operationResult == FR_INVALID_NAME) + { + // invalid path + NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); + } + else if (operationResult != FR_OK) + { + // folder doesn't exist + NANOCLR_SET_AND_LEAVE(CLR_E_DIRECTORY_NOT_FOUND); + } - NANOCLR_CLEANUP(); + NANOCLR_CLEANUP(); - NANOCLR_CLEANUP_END(); + NANOCLR_CLEANUP_END(); } -HRESULT Library_win_storage_native_Windows_Storage_StorageFolder::GetFolderNative___WindowsStorageStorageFolder__STRING(CLR_RT_StackFrame& stack) +HRESULT Library_win_storage_native_Windows_Storage_StorageFolder::GetFolderNative___WindowsStorageStorageFolder__STRING( + CLR_RT_StackFrame &stack) { - NANOCLR_HEADER(); + NANOCLR_HEADER(); - CLR_RT_TypeDef_Index storageFolderTypeDef; - CLR_RT_HeapBlock* storageFolder; + CLR_RT_TypeDef_Index storageFolderTypeDef; + CLR_RT_HeapBlock *storageFolder; - const char* folderName; - const char* workingPath; + const char *folderName; + const char *workingPath; - FILINFO fileInfo; - SYSTEMTIME fileInfoTime; + FILINFO fileInfo; + SYSTEMTIME fileInfoTime; - FRESULT operationResult; - char* folderPath = NULL; + FRESULT operationResult; + char *folderPath = NULL; - // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + // get a pointer to the managed object instance and check that it's not NULL + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); - // get a pointer to the path in managed field - workingPath = pThis[Library_win_storage_native_Windows_Storage_StorageFolder::FIELD___path].DereferenceString()->StringText(); + // get a pointer to the path in managed field + workingPath = + pThis[Library_win_storage_native_Windows_Storage_StorageFolder::FIELD___path].DereferenceString()->StringText(); - // get a pointer to the desired folder name - folderName = stack.Arg1().DereferenceString()->StringText(); + // get a pointer to the desired folder name + folderName = stack.Arg1().DereferenceString()->StringText(); - folderPath = (char*)malloc(2 * FF_LFN_BUF + 1); + folderPath = (char *)malloc(2 * FF_LFN_BUF + 1); - // sanity check for successfull malloc - if (folderPath == NULL) - { - // failed to allocate memory - NANOCLR_SET_AND_LEAVE(CLR_E_OUT_OF_MEMORY); - } + // sanity check for successfull malloc + if (folderPath == NULL) + { + // failed to allocate memory + NANOCLR_SET_AND_LEAVE(CLR_E_OUT_OF_MEMORY); + } - // clear working buffer - memset(folderPath, 0, 2 * FF_LFN_BUF + 1); + // clear working buffer + memset(folderPath, 0, 2 * FF_LFN_BUF + 1); - // compose folder path - CombinePath(folderPath, workingPath, folderName); + // compose folder path + CombinePath(folderPath, workingPath, folderName); - // check if directory exists - operationResult = f_stat(folderPath, &fileInfo); - if (operationResult != FR_OK) - { - // folder doesn't exist - NANOCLR_SET_AND_LEAVE(CLR_E_DIRECTORY_NOT_FOUND); - } + // check if directory exists + operationResult = f_stat(folderPath, &fileInfo); + if (operationResult != FR_OK) + { + // folder doesn't exist + NANOCLR_SET_AND_LEAVE(CLR_E_DIRECTORY_NOT_FOUND); + } else { // is this a file? - if ( !(fileInfo.fattrib & AM_DIR) ) + if (!(fileInfo.fattrib & AM_DIR)) { // Path represents a file NANOCLR_SET_AND_LEAVE(CLR_E_DIRECTORY_NOT_FOUND); @@ -1115,35 +1179,41 @@ HRESULT Library_win_storage_native_Windows_Storage_StorageFolder::GetFolderNativ storageFolder = stack.TopValue().Dereference(); // folder name - NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_String::CreateInstance(storageFolder[Library_win_storage_native_Windows_Storage_StorageFolder::FIELD___name], folderName)); + NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_String::CreateInstance( + storageFolder[Library_win_storage_native_Windows_Storage_StorageFolder::FIELD___name], + folderName)); - NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_String::CreateInstance(storageFolder[Library_win_storage_native_Windows_Storage_StorageFolder::FIELD___path], folderPath)); + NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_String::CreateInstance( + storageFolder[Library_win_storage_native_Windows_Storage_StorageFolder::FIELD___path], + folderPath)); // get the date time details and fill in the managed field // compute directory date fileInfoTime = GetDateTime(fileInfo.fdate, fileInfo.ftime); // get a reference to the dateCreated managed field... - CLR_RT_HeapBlock& timestampFieldRef = storageFolder[Library_win_storage_native_Windows_Storage_StorageFolder::FIELD___dateCreated]; - // create an instance of - NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.NewObjectFromIndex(timestampFieldRef, g_CLR_RT_WellKnownTypes.m_DateTime)); - // get reference to this object - CLR_RT_HeapBlock *hbDateTime = timestampFieldRef.Dereference(); - // get reference to ticks field - CLR_RT_HeapBlock &dateTimeTickField = hbDateTime[Library_corlib_native_System_DateTime::FIELD___ticks]; - CLR_INT64 *pRes = (CLR_INT64 *)&dateTimeTickField.NumericByRef().s8; + CLR_RT_HeapBlock ×tampFieldRef = + storageFolder[Library_win_storage_native_Windows_Storage_StorageFolder::FIELD___dateCreated]; + // create an instance of + NANOCLR_CHECK_HRESULT( + g_CLR_RT_ExecutionEngine.NewObjectFromIndex(timestampFieldRef, g_CLR_RT_WellKnownTypes.m_DateTime)); + // get reference to this object + CLR_RT_HeapBlock *hbDateTime = timestampFieldRef.Dereference(); + // get reference to ticks field + CLR_RT_HeapBlock &dateTimeTickField = hbDateTime[Library_corlib_native_System_DateTime::FIELD___ticks]; + CLR_INT64 *pRes = (CLR_INT64 *)&dateTimeTickField.NumericByRef().s8; // ...and set it with the fileInfoTime *pRes = HAL_Time_ConvertFromSystemTime(&fileInfoTime); } } - NANOCLR_CLEANUP(); + NANOCLR_CLEANUP(); - // free buffer memory, if allocated - if (folderPath != NULL) - { - free(folderPath); - } + // free buffer memory, if allocated + if (folderPath != NULL) + { + free(folderPath); + } - NANOCLR_CLEANUP_END(); + NANOCLR_CLEANUP_END(); } diff --git a/targets/FreeRTOS/NXP/nanoCLR/Windows.Storage/win_storage_native_target.h b/targets/FreeRTOS/NXP/nanoCLR/Windows.Storage/win_storage_native_target.h index e6f5e9a554..3b2455c83b 100644 --- a/targets/FreeRTOS/NXP/nanoCLR/Windows.Storage/win_storage_native_target.h +++ b/targets/FreeRTOS/NXP/nanoCLR/Windows.Storage/win_storage_native_target.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/nanoCLR/nanoFramework.Runtime.Native/nf_rt_native_nanoFramework_Runtime_Native_Rtc.cpp b/targets/FreeRTOS/NXP/nanoCLR/nanoFramework.Runtime.Native/nf_rt_native_nanoFramework_Runtime_Native_Rtc.cpp index 31e4ceb341..e6f468a520 100644 --- a/targets/FreeRTOS/NXP/nanoCLR/nanoFramework.Runtime.Native/nf_rt_native_nanoFramework_Runtime_Native_Rtc.cpp +++ b/targets/FreeRTOS/NXP/nanoCLR/nanoFramework.Runtime.Native/nf_rt_native_nanoFramework_Runtime_Native_Rtc.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/nanoCLR/nanoHAL.cpp b/targets/FreeRTOS/NXP/nanoCLR/nanoHAL.cpp index 29f748c050..a971e00292 100644 --- a/targets/FreeRTOS/NXP/nanoCLR/nanoHAL.cpp +++ b/targets/FreeRTOS/NXP/nanoCLR/nanoHAL.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/nanoCLR/targetHAL.cpp b/targets/FreeRTOS/NXP/nanoCLR/targetHAL.cpp index 8b6d34d94c..df8c633cac 100644 --- a/targets/FreeRTOS/NXP/nanoCLR/targetHAL.cpp +++ b/targets/FreeRTOS/NXP/nanoCLR/targetHAL.cpp @@ -1,43 +1,47 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // #include #include #include +#include #include #include // // Reboot handlers clean up on reboot // -static ON_SOFT_REBOOT_HANDLER s_rebootHandlers[16] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; +static ON_SOFT_REBOOT_HANDLER s_rebootHandlers[16] = + {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; void HAL_AddSoftRebootHandler(ON_SOFT_REBOOT_HANDLER handler) { - for(unsigned int i=0; i 0) ? true : false; -} - -void SystemState_Set(SYSTEM_STATE_type state) -{ - GLOBAL_LOCK(); - - SystemState_SetNoLock(state); - - GLOBAL_UNLOCK(); -} - -void SystemState_Clear(SYSTEM_STATE_type state) -{ - GLOBAL_LOCK(); - - SystemState_ClearNoLock(state ); - - GLOBAL_UNLOCK(); -} - -bool SystemState_Query(SYSTEM_STATE_type state) -{ - GLOBAL_LOCK(); - - bool systemStateCopy = SystemState_QueryNoLock(state); - - GLOBAL_UNLOCK(); - - return systemStateCopy; + HAL_COMPLETION ::Uninitialize(); } diff --git a/targets/FreeRTOS/NXP/nanoCLR/targetHAL_Network.cpp b/targets/FreeRTOS/NXP/nanoCLR/targetHAL_Network.cpp index 180cf33074..9927f4432e 100644 --- a/targets/FreeRTOS/NXP/nanoCLR/targetHAL_Network.cpp +++ b/targets/FreeRTOS/NXP/nanoCLR/targetHAL_Network.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/nanoCLR/targetHAL_Power.c b/targets/FreeRTOS/NXP/nanoCLR/targetHAL_Power.c index 9685481010..c72c3b3baa 100644 --- a/targets/FreeRTOS/NXP/nanoCLR/targetHAL_Power.c +++ b/targets/FreeRTOS/NXP/nanoCLR/targetHAL_Power.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/nanoCLR/targetHAL_Time.cpp b/targets/FreeRTOS/NXP/nanoCLR/targetHAL_Time.cpp index 4267f4e34f..a3af625e04 100644 --- a/targets/FreeRTOS/NXP/nanoCLR/targetHAL_Time.cpp +++ b/targets/FreeRTOS/NXP/nanoCLR/targetHAL_Time.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/nanoCLR/targetHAL_Time.h b/targets/FreeRTOS/NXP/nanoCLR/targetHAL_Time.h index 359ea69119..ff10614003 100644 --- a/targets/FreeRTOS/NXP/nanoCLR/targetHAL_Time.h +++ b/targets/FreeRTOS/NXP/nanoCLR/targetHAL_Time.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/NXP/nanoCLR/targetRandom.cpp b/targets/FreeRTOS/NXP/nanoCLR/targetRandom.cpp index 14093420f7..ba5c272d86 100644 --- a/targets/FreeRTOS/NXP/nanoCLR/targetRandom.cpp +++ b/targets/FreeRTOS/NXP/nanoCLR/targetRandom.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // #include "Core.h" diff --git a/targets/FreeRTOS/common/CMakeLists.txt b/targets/FreeRTOS/common/CMakeLists.txt index d8a9b04238..345104443c 100644 --- a/targets/FreeRTOS/common/CMakeLists.txt +++ b/targets/FreeRTOS/common/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/targets/FreeRTOS/common/WireProtocol_ReceiverThread.c b/targets/FreeRTOS/common/WireProtocol_ReceiverThread.c index e0efaecabf..1bc34c405f 100644 --- a/targets/FreeRTOS/common/WireProtocol_ReceiverThread.c +++ b/targets/FreeRTOS/common/WireProtocol_ReceiverThread.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/common/hardfault.c b/targets/FreeRTOS/common/hardfault.c index 68c4f560de..67749b7a10 100644 --- a/targets/FreeRTOS/common/hardfault.c +++ b/targets/FreeRTOS/common/hardfault.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/common/include/TargetPAL_BlockStorage.h b/targets/FreeRTOS/common/include/TargetPAL_BlockStorage.h index 805c2e320d..de9364c773 100644 --- a/targets/FreeRTOS/common/include/TargetPAL_BlockStorage.h +++ b/targets/FreeRTOS/common/include/TargetPAL_BlockStorage.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/common/include/WireProtocol_ReceiverThread.h b/targets/FreeRTOS/common/include/WireProtocol_ReceiverThread.h index 3e4ee537bc..67e400353c 100644 --- a/targets/FreeRTOS/common/include/WireProtocol_ReceiverThread.h +++ b/targets/FreeRTOS/common/include/WireProtocol_ReceiverThread.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/lwipopts.h b/targets/FreeRTOS/common/include/lwipopts.h similarity index 76% rename from targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/lwipopts.h rename to targets/FreeRTOS/common/include/lwipopts.h index beecddbf64..1a370120ac 100644 --- a/targets/CMSIS-OS/ChibiOS/ORGPAL_PALTHREE/lwipopts.h +++ b/targets/FreeRTOS/common/include/lwipopts.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2001-2004 Swedish Institute of Computer Science, All Rights Reserved // See LICENSE file in the project root for full license information. // @@ -11,9 +11,9 @@ /* * Copyright (c) 2001-2004 Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, @@ -22,33 +22,32 @@ * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. + * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT - * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * OF SUCH DAMAGE. * * This file is part of the lwIP TCP/IP stack. - * + * * Author: Adam Dunkels * */ #ifndef __LWIPOPT_H__ #define __LWIPOPT_H__ - #define _REENT_ONLY #define set_errno(err) #include +#include #include -#include /* ----------------------------------------------- @@ -62,15 +61,15 @@ * allocation and deallocation. */ #ifndef SYS_LIGHTWEIGHT_PROT -#define SYS_LIGHTWEIGHT_PROT 1 +#define SYS_LIGHTWEIGHT_PROT 1 #endif -/** +/** * NO_SYS==1: Provides VERY minimal functionality. Otherwise, * use lwIP facilities. */ #ifndef NO_SYS -#define NO_SYS 0 +#define NO_SYS 0 #endif /** @@ -78,7 +77,7 @@ * Mainly for compatibility to old versions. */ #ifndef NO_SYS_NO_TIMERS -#define NO_SYS_NO_TIMERS 0 +#define NO_SYS_NO_TIMERS 0 #endif // empty on purpose @@ -89,7 +88,7 @@ * one included in your C library */ #ifndef MEMCPY -#define MEMCPY(dst,src,len) memcpy(dst,src,len) +#define MEMCPY(dst, src, len) memcpy(dst, src, len) #endif /** @@ -97,7 +96,7 @@ * call to memcpy() if the length is known at compile time and is small. */ #ifndef SMEMCPY -#define SMEMCPY(dst,src,len) memcpy(dst,src,len) +#define SMEMCPY(dst, src, len) memcpy(dst, src, len) #endif /* @@ -111,16 +110,16 @@ * already use it. */ #ifndef MEM_LIBC_MALLOC -#define MEM_LIBC_MALLOC 1 +#define MEM_LIBC_MALLOC 1 #endif /** -* MEMP_MEM_MALLOC==1: Use mem_malloc/mem_free instead of the lwip pool allocator. -* Especially useful with MEM_LIBC_MALLOC but handle with care regarding execution -* speed and usage from interrupts! -*/ + * MEMP_MEM_MALLOC==1: Use mem_malloc/mem_free instead of the lwip pool allocator. + * Especially useful with MEM_LIBC_MALLOC but handle with care regarding execution + * speed and usage from interrupts! + */ #ifndef MEMP_MEM_MALLOC -#define MEMP_MEM_MALLOC 1 +#define MEMP_MEM_MALLOC 1 #endif /** @@ -129,7 +128,7 @@ * 2 byte alignment -> #define MEM_ALIGNMENT 2 */ #ifndef MEM_ALIGNMENT -#define MEM_ALIGNMENT 4 +#define MEM_ALIGNMENT 4 #endif /** @@ -137,7 +136,7 @@ * a lot of data that needs to be copied, this should be set high. */ #ifndef MEM_SIZE -#define MEM_SIZE (16 * 1024) +#define MEM_SIZE (16 * 1024) #endif /** @@ -146,7 +145,7 @@ * Default is one big array for all pools */ #ifndef MEMP_SEPARATE_POOLS -#define MEMP_SEPARATE_POOLS 0 +#define MEMP_SEPARATE_POOLS 0 #endif /** @@ -159,7 +158,7 @@ * memp_malloc() or memp_free() is called (useful but slow!) */ #ifndef MEMP_OVERFLOW_CHECK -#define MEMP_OVERFLOW_CHECK 0 +#define MEMP_OVERFLOW_CHECK 0 #endif /** @@ -167,7 +166,7 @@ * sure that there are no cycles in the linked lists. */ #ifndef MEMP_SANITY_CHECK -#define MEMP_SANITY_CHECK 0 +#define MEMP_SANITY_CHECK 0 #endif /** @@ -177,7 +176,7 @@ * To use this, MEMP_USE_CUSTOM_POOLS also has to be enabled. */ #ifndef MEM_USE_POOLS -#define MEM_USE_POOLS 0 +#define MEM_USE_POOLS 0 #endif /** @@ -185,17 +184,17 @@ * bigger pool - WARNING: THIS MIGHT WASTE MEMORY but it can make a system more * reliable. */ #ifndef MEM_USE_POOLS_TRY_BIGGER_POOL -#define MEM_USE_POOLS_TRY_BIGGER_POOL 0 +#define MEM_USE_POOLS_TRY_BIGGER_POOL 0 #endif /** * MEMP_USE_CUSTOM_POOLS==1: whether to include a user file lwippools.h * that defines additional pools beyond the "standard" ones required - * by lwIP. If you set this to 1, you must have lwippools.h in your - * inlude path somewhere. + * by lwIP. If you set this to 1, you must have lwippools.h in your + * inlude path somewhere. */ #ifndef MEMP_USE_CUSTOM_POOLS -#define MEMP_USE_CUSTOM_POOLS 0 +#define MEMP_USE_CUSTOM_POOLS 0 #endif /** @@ -228,7 +227,7 @@ /** * LWIP_IPV6==1: Enable IPv6 */ -#define LWIP_IPV6 0 +#define LWIP_IPV6 0 /* ------------------------------------------------ @@ -241,7 +240,7 @@ * this should be set high. */ #ifndef MEMP_NUM_PBUF -#define MEMP_NUM_PBUF 16 +#define MEMP_NUM_PBUF 16 #endif /** @@ -249,7 +248,7 @@ * (requires the LWIP_RAW option) */ #ifndef MEMP_NUM_RAW_PCB -#define MEMP_NUM_RAW_PCB 4 +#define MEMP_NUM_RAW_PCB 4 #endif /** @@ -258,7 +257,7 @@ * (requires the LWIP_UDP option) */ #ifndef MEMP_NUM_UDP_PCB -#define MEMP_NUM_UDP_PCB 4 +#define MEMP_NUM_UDP_PCB 4 #endif /** @@ -266,7 +265,7 @@ * (requires the LWIP_TCP option) */ #ifndef MEMP_NUM_TCP_PCB -#define MEMP_NUM_TCP_PCB 5 +#define MEMP_NUM_TCP_PCB 5 #endif /** @@ -274,7 +273,7 @@ * (requires the LWIP_TCP option) */ #ifndef MEMP_NUM_TCP_PCB_LISTEN -#define MEMP_NUM_TCP_PCB_LISTEN 8 +#define MEMP_NUM_TCP_PCB_LISTEN 8 #endif /** @@ -282,7 +281,7 @@ * (requires the LWIP_TCP option) */ #ifndef MEMP_NUM_TCP_SEG -#define MEMP_NUM_TCP_SEG 16 +#define MEMP_NUM_TCP_SEG 16 #endif /** @@ -290,7 +289,7 @@ * reassembly (whole packets, not fragments!) */ #ifndef MEMP_NUM_REASSDATA -#define MEMP_NUM_REASSDATA 5 +#define MEMP_NUM_REASSDATA 5 #endif /** @@ -301,7 +300,7 @@ * where the packet is not yet sent when netif->output returns. */ #ifndef MEMP_NUM_FRAG_PBUF -#define MEMP_NUM_FRAG_PBUF 15 +#define MEMP_NUM_FRAG_PBUF 15 #endif /** @@ -311,7 +310,7 @@ * (requires the ARP_QUEUEING option) */ #ifndef MEMP_NUM_ARP_QUEUE -#define MEMP_NUM_ARP_QUEUE 30 +#define MEMP_NUM_ARP_QUEUE 30 #endif /** @@ -321,7 +320,7 @@ * (requires the LWIP_IGMP option) */ #ifndef MEMP_NUM_IGMP_GROUP -#define MEMP_NUM_IGMP_GROUP 8 +#define MEMP_NUM_IGMP_GROUP 8 #endif /** @@ -331,7 +330,9 @@ * The formula expects settings to be either '0' or '1'. */ #ifndef MEMP_NUM_SYS_TIMEOUT -#define MEMP_NUM_SYS_TIMEOUT (LWIP_TCP + IP_REASSEMBLY + LWIP_ARP + (2*LWIP_DHCP) + LWIP_AUTOIP + LWIP_IGMP + LWIP_DNS + PPP_SUPPORT + (LWIP_IPV6 ? (1 + LWIP_IPV6_REASS + LWIP_IPV6_MLD) : 0)) +#define MEMP_NUM_SYS_TIMEOUT \ + (LWIP_TCP + IP_REASSEMBLY + LWIP_ARP + (2 * LWIP_DHCP) + LWIP_AUTOIP + LWIP_IGMP + LWIP_DNS + PPP_SUPPORT + \ + (LWIP_IPV6 ? (1 + LWIP_IPV6_REASS + LWIP_IPV6_MLD) : 0)) #endif /** @@ -339,7 +340,7 @@ * (only needed if you use the sequential API, like api_lib.c) */ #ifndef MEMP_NUM_NETBUF -#define MEMP_NUM_NETBUF 2 +#define MEMP_NUM_NETBUF 2 #endif /** @@ -347,32 +348,32 @@ * (only needed if you use the sequential API, like api_lib.c) */ #ifndef MEMP_NUM_NETCONN -#define MEMP_NUM_NETCONN 4 +#define MEMP_NUM_NETCONN 4 #endif /** * MEMP_NUM_TCPIP_MSG_API: the number of struct tcpip_msg, which are used - * for callback/timeout API communication. + * for callback/timeout API communication. * (only needed if you use tcpip.c) */ #ifndef MEMP_NUM_TCPIP_MSG_API -#define MEMP_NUM_TCPIP_MSG_API 8 +#define MEMP_NUM_TCPIP_MSG_API 8 #endif /** * MEMP_NUM_TCPIP_MSG_INPKT: the number of struct tcpip_msg, which are used - * for incoming packets. + * for incoming packets. * (only needed if you use tcpip.c) */ #ifndef MEMP_NUM_TCPIP_MSG_INPKT -#define MEMP_NUM_TCPIP_MSG_INPKT 8 +#define MEMP_NUM_TCPIP_MSG_INPKT 8 #endif /** * MEMP_NUM_SNMP_NODE: the number of leafs in the SNMP tree. */ #ifndef MEMP_NUM_SNMP_NODE -#define MEMP_NUM_SNMP_NODE 50 +#define MEMP_NUM_SNMP_NODE 50 #endif /** @@ -380,7 +381,7 @@ * Every branch has one leaf (MEMP_NUM_SNMP_NODE) at least! */ #ifndef MEMP_NUM_SNMP_ROOTNODE -#define MEMP_NUM_SNMP_ROOTNODE 30 +#define MEMP_NUM_SNMP_ROOTNODE 30 #endif /** @@ -389,7 +390,7 @@ * 1 for output) */ #ifndef MEMP_NUM_SNMP_VARBIND -#define MEMP_NUM_SNMP_VARBIND 2 +#define MEMP_NUM_SNMP_VARBIND 2 #endif /** @@ -398,7 +399,7 @@ * (1 for the value read and 2 for OIDs - input and output) */ #ifndef MEMP_NUM_SNMP_VALUE -#define MEMP_NUM_SNMP_VALUE 3 +#define MEMP_NUM_SNMP_VALUE 3 #endif /** @@ -406,7 +407,7 @@ * (before freeing the corresponding memory using lwip_freeaddrinfo()). */ #ifndef MEMP_NUM_NETDB -#define MEMP_NUM_NETDB 1 +#define MEMP_NUM_NETDB 1 #endif /** @@ -414,7 +415,7 @@ * if DNS_LOCAL_HOSTLIST_IS_DYNAMIC==1. */ #ifndef MEMP_NUM_LOCALHOSTLIST -#define MEMP_NUM_LOCALHOSTLIST 1 +#define MEMP_NUM_LOCALHOSTLIST 1 #endif /** @@ -422,14 +423,14 @@ * interfaces (only used with PPPOE_SUPPORT==1) */ #ifndef MEMP_NUM_PPPOE_INTERFACES -#define MEMP_NUM_PPPOE_INTERFACES 1 +#define MEMP_NUM_PPPOE_INTERFACES 1 #endif /** - * PBUF_POOL_SIZE: the number of buffers in the pbuf pool. + * PBUF_POOL_SIZE: the number of buffers in the pbuf pool. */ #ifndef PBUF_POOL_SIZE -#define PBUF_POOL_SIZE 16 +#define PBUF_POOL_SIZE 16 #endif /* @@ -441,14 +442,14 @@ * LWIP_ARP==1: Enable ARP functionality. */ #ifndef LWIP_ARP -#define LWIP_ARP 1 +#define LWIP_ARP 1 #endif /** * ARP_TABLE_SIZE: Number of active MAC-IP address pairs cached. */ #ifndef ARP_TABLE_SIZE -#define ARP_TABLE_SIZE 10 +#define ARP_TABLE_SIZE 10 #endif /** @@ -459,7 +460,7 @@ * packet in a row to an IP address that is not in the ARP cache. */ #ifndef ARP_QUEUEING -#define ARP_QUEUEING 0 +#define ARP_QUEUEING 0 #endif /** @@ -473,7 +474,7 @@ * Also notice that this slows down input processing of every IP packet! */ #ifndef ETHARP_TRUST_IP_MAC -#define ETHARP_TRUST_IP_MAC 0 +#define ETHARP_TRUST_IP_MAC 0 #endif /** @@ -485,14 +486,14 @@ * that returns 1 to accept a packet or 0 to drop a packet. */ #ifndef ETHARP_SUPPORT_VLAN -#define ETHARP_SUPPORT_VLAN 0 +#define ETHARP_SUPPORT_VLAN 0 #endif /** LWIP_ETHERNET==1: enable ethernet support for PPPoE even though ARP * might be disabled */ #ifndef LWIP_ETHERNET -#define LWIP_ETHERNET (LWIP_ARP || PPPOE_SUPPORT) +#define LWIP_ETHERNET (LWIP_ARP || PPPOE_SUPPORT) #endif /** ETH_PAD_SIZE: number of bytes added before the ethernet header to ensure @@ -501,14 +502,14 @@ * on a 32-bit boundary, so setting this to 2 can speed up 32-bit-platforms. */ #ifndef ETH_PAD_SIZE -#define ETH_PAD_SIZE 0 +#define ETH_PAD_SIZE 0 #endif /** ETHARP_SUPPORT_STATIC_ENTRIES==1: enable code to support static ARP table * entries (using etharp_add_static_entry/etharp_remove_static_entry). */ #ifndef ETHARP_SUPPORT_STATIC_ENTRIES -#define ETHARP_SUPPORT_STATIC_ENTRIES 0 +#define ETHARP_SUPPORT_STATIC_ENTRIES 0 #endif /* @@ -522,7 +523,7 @@ * interface, define this to 0. */ #ifndef IP_FORWARD -#define IP_FORWARD 0 +#define IP_FORWARD 0 #endif /** @@ -531,7 +532,7 @@ * IP_OPTIONS_ALLOWED==1: IP options are allowed (but not parsed). */ #ifndef IP_OPTIONS_ALLOWED -#define IP_OPTIONS_ALLOWED 1 +#define IP_OPTIONS_ALLOWED 1 #endif /** @@ -540,7 +541,7 @@ * via IP_FRAG. */ #ifndef IP_REASSEMBLY -#define IP_REASSEMBLY 1 +#define IP_REASSEMBLY 1 #endif /** @@ -549,7 +550,7 @@ * controlled via IP_REASSEMBLY. */ #ifndef IP_FRAG -#define IP_FRAG 1 +#define IP_FRAG 1 #endif /** @@ -558,7 +559,7 @@ * in this time, the whole packet is discarded. */ #ifndef IP_REASS_MAXAGE -#define IP_REASS_MAXAGE 3 +#define IP_REASS_MAXAGE 3 #endif /** @@ -568,7 +569,7 @@ * packets even if the maximum amount of fragments is enqueued for reassembly! */ #ifndef IP_REASS_MAX_PBUFS -#define IP_REASS_MAX_PBUFS 10 +#define IP_REASS_MAX_PBUFS 10 #endif /** @@ -579,7 +580,7 @@ * ATTENTION: IP_FRAG_USES_STATIC_BUF==1 may not be used for DMA-enabled MACs! */ #ifndef IP_FRAG_USES_STATIC_BUF -#define IP_FRAG_USES_STATIC_BUF 0 +#define IP_FRAG_USES_STATIC_BUF 0 #endif /** @@ -587,14 +588,14 @@ * (requires IP_FRAG_USES_STATIC_BUF==1) */ #if IP_FRAG_USES_STATIC_BUF && !defined(IP_FRAG_MAX_MTU) -#define IP_FRAG_MAX_MTU 1500 +#define IP_FRAG_MAX_MTU 1500 #endif /** * IP_DEFAULT_TTL: Default value for Time-To-Live used by transport layers. */ #ifndef IP_DEFAULT_TTL -#define IP_DEFAULT_TTL 255 +#define IP_DEFAULT_TTL 255 #endif /** @@ -603,7 +604,7 @@ * on recv operations, you also have to set IP_SOF_BROADCAST_RECV=1. */ #ifndef IP_SOF_BROADCAST -#define IP_SOF_BROADCAST 0 +#define IP_SOF_BROADCAST 0 #endif /** @@ -611,7 +612,7 @@ * filter on recv operations. */ #ifndef IP_SOF_BROADCAST_RECV -#define IP_SOF_BROADCAST_RECV 0 +#define IP_SOF_BROADCAST_RECV 0 #endif /** @@ -646,28 +647,28 @@ * Be careful, disable that make your product non-compliant to RFC1122 */ #ifndef LWIP_ICMP -#define LWIP_ICMP 1 +#define LWIP_ICMP 1 #endif /** * ICMP_TTL: Default value for Time-To-Live used by ICMP packets. */ #ifndef ICMP_TTL -#define ICMP_TTL (IP_DEFAULT_TTL) +#define ICMP_TTL (IP_DEFAULT_TTL) #endif /** * LWIP_BROADCAST_PING==1: respond to broadcast pings (default is unicast only) */ #ifndef LWIP_BROADCAST_PING -#define LWIP_BROADCAST_PING 0 +#define LWIP_BROADCAST_PING 0 #endif /** * LWIP_MULTICAST_PING==1: respond to multicast pings (default is unicast only) */ #ifndef LWIP_MULTICAST_PING -#define LWIP_MULTICAST_PING 0 +#define LWIP_MULTICAST_PING 0 #endif /* @@ -679,14 +680,14 @@ * LWIP_RAW==1: Enable application layer to hook into the IP layer itself. */ #ifndef LWIP_RAW -#define LWIP_RAW 1 +#define LWIP_RAW 1 #endif /** * LWIP_RAW==1: Enable application layer to hook into the IP layer itself. */ #ifndef RAW_TTL -#define RAW_TTL (IP_DEFAULT_TTL) +#define RAW_TTL (IP_DEFAULT_TTL) #endif /* @@ -698,17 +699,17 @@ * LWIP_DHCP==1: Enable DHCP module. */ #ifndef LWIP_DHCP -#define LWIP_DHCP 1 +#define LWIP_DHCP 1 #endif /** * DHCP_DOES_ARP_CHECK==1: Do an ARP check on the offered address. */ #ifndef DHCP_DOES_ARP_CHECK -#define DHCP_DOES_ARP_CHECK ((LWIP_DHCP) && (LWIP_ARP)) +#define DHCP_DOES_ARP_CHECK ((LWIP_DHCP) && (LWIP_ARP)) #endif -#define LWIP_DHCP_CHECK_LINK_UP 1 +#define LWIP_DHCP_CHECK_LINK_UP 1 /* ------------------------------------ @@ -719,7 +720,7 @@ * LWIP_AUTOIP==1: Enable AUTOIP module. */ #ifndef LWIP_AUTOIP -#define LWIP_AUTOIP 0 +#define LWIP_AUTOIP 0 #endif /** @@ -727,7 +728,7 @@ * the same interface at the same time. */ #ifndef LWIP_DHCP_AUTOIP_COOP -#define LWIP_DHCP_AUTOIP_COOP 0 +#define LWIP_DHCP_AUTOIP_COOP 0 #endif /** @@ -738,7 +739,7 @@ * AutoIP. */ #ifndef LWIP_DHCP_AUTOIP_COOP_TRIES -#define LWIP_DHCP_AUTOIP_COOP_TRIES 9 +#define LWIP_DHCP_AUTOIP_COOP_TRIES 9 #endif /* @@ -751,7 +752,7 @@ * transport. */ #ifndef LWIP_SNMP -#define LWIP_SNMP 0 +#define LWIP_SNMP 0 #endif /** @@ -760,7 +761,7 @@ * Does not have to be changed unless external MIBs answer request asynchronously */ #ifndef SNMP_CONCURRENT_REQUESTS -#define SNMP_CONCURRENT_REQUESTS 1 +#define SNMP_CONCURRENT_REQUESTS 1 #endif /** @@ -768,16 +769,16 @@ * destination is required */ #ifndef SNMP_TRAP_DESTINATIONS -#define SNMP_TRAP_DESTINATIONS 1 +#define SNMP_TRAP_DESTINATIONS 1 #endif /** - * SNMP_PRIVATE_MIB: + * SNMP_PRIVATE_MIB: * When using a private MIB, you have to create a file 'private_mib.h' that contains * a 'struct mib_array_node mib_private' which contains your MIB. */ #ifndef SNMP_PRIVATE_MIB -#define SNMP_PRIVATE_MIB 0 +#define SNMP_PRIVATE_MIB 0 #endif /** @@ -786,7 +787,7 @@ * Unsafe requests are disabled by default! */ #ifndef SNMP_SAFE_REQUESTS -#define SNMP_SAFE_REQUESTS 1 +#define SNMP_SAFE_REQUESTS 1 #endif /** @@ -794,7 +795,7 @@ * MEMP_SNMP_VALUE elements. */ #ifndef SNMP_MAX_OCTET_STRING_LEN -#define SNMP_MAX_OCTET_STRING_LEN 127 +#define SNMP_MAX_OCTET_STRING_LEN 127 #endif /** @@ -803,7 +804,7 @@ * This affects the size of MEMP_SNMP_VALUE elements. */ #ifndef SNMP_MAX_TREE_DEPTH -#define SNMP_MAX_TREE_DEPTH 15 +#define SNMP_MAX_TREE_DEPTH 15 #endif /** @@ -811,7 +812,7 @@ * SNMP_MAX_OCTET_STRING_LEN and SNMP_MAX_TREE_DEPTH. */ #ifndef SNMP_MAX_VALUE_SIZE -#define SNMP_MAX_VALUE_SIZE LWIP_MAX((SNMP_MAX_OCTET_STRING_LEN)+1, sizeof(s32_t)*(SNMP_MAX_TREE_DEPTH)) +#define SNMP_MAX_VALUE_SIZE LWIP_MAX((SNMP_MAX_OCTET_STRING_LEN) + 1, sizeof(s32_t) * (SNMP_MAX_TREE_DEPTH)) #endif /* @@ -820,10 +821,10 @@ ---------------------------------- */ /** - * LWIP_IGMP==1: Turn on IGMP module. + * LWIP_IGMP==1: Turn on IGMP module. */ #ifndef LWIP_IGMP -#define LWIP_IGMP 0 +#define LWIP_IGMP 0 #endif /* @@ -836,32 +837,32 @@ * transport. */ #ifndef LWIP_DNS -#define LWIP_DNS 1 +#define LWIP_DNS 1 #endif /** DNS maximum number of entries to maintain locally. */ #ifndef DNS_TABLE_SIZE -#define DNS_TABLE_SIZE 4 +#define DNS_TABLE_SIZE 4 #endif /** DNS maximum host name length supported in the name table. */ #ifndef DNS_MAX_NAME_LENGTH -#define DNS_MAX_NAME_LENGTH 256 +#define DNS_MAX_NAME_LENGTH 256 #endif /** The maximum of DNS servers */ #ifndef DNS_MAX_SERVERS -#define DNS_MAX_SERVERS 2 +#define DNS_MAX_SERVERS 2 #endif /** DNS do a name checking between the query and the response. */ #ifndef DNS_DOES_NAME_CHECK -#define DNS_DOES_NAME_CHECK 1 +#define DNS_DOES_NAME_CHECK 1 #endif /** DNS message max. size. Default value is RFC compliant. */ #ifndef DNS_MSG_SIZE -#define DNS_MSG_SIZE 512 +#define DNS_MSG_SIZE 512 #endif /** DNS_LOCAL_HOSTLIST: Implements a local host-to-address list. If enabled, @@ -875,13 +876,13 @@ * that returns the IP address or INADDR_NONE if not found. */ #ifndef DNS_LOCAL_HOSTLIST -#define DNS_LOCAL_HOSTLIST 0 +#define DNS_LOCAL_HOSTLIST 0 #endif /* DNS_LOCAL_HOSTLIST */ /** If this is turned on, the local host-list can be dynamically changed * at runtime. */ #ifndef DNS_LOCAL_HOSTLIST_IS_DYNAMIC -#define DNS_LOCAL_HOSTLIST_IS_DYNAMIC 0 +#define DNS_LOCAL_HOSTLIST_IS_DYNAMIC 0 #endif /* DNS_LOCAL_HOSTLIST_IS_DYNAMIC */ /* @@ -893,28 +894,28 @@ * LWIP_UDP==1: Turn on UDP. */ #ifndef LWIP_UDP -#define LWIP_UDP 1 +#define LWIP_UDP 1 #endif /** * LWIP_UDPLITE==1: Turn on UDP-Lite. (Requires LWIP_UDP) */ #ifndef LWIP_UDPLITE -#define LWIP_UDPLITE 0 +#define LWIP_UDPLITE 0 #endif /** * UDP_TTL: Default Time-To-Live value. */ #ifndef UDP_TTL -#define UDP_TTL (IP_DEFAULT_TTL) +#define UDP_TTL (IP_DEFAULT_TTL) #endif /** * LWIP_NETBUF_RECVINFO==1: append destination addr and port to every netbuf. */ #ifndef LWIP_NETBUF_RECVINFO -#define LWIP_NETBUF_RECVINFO 0 +#define LWIP_NETBUF_RECVINFO 0 #endif /* @@ -926,36 +927,36 @@ * LWIP_TCP==1: Turn on TCP. */ #ifndef LWIP_TCP -#define LWIP_TCP 1 +#define LWIP_TCP 1 #endif /** * TCP_TTL: Default Time-To-Live value. */ #ifndef TCP_TTL -#define TCP_TTL (IP_DEFAULT_TTL) +#define TCP_TTL (IP_DEFAULT_TTL) #endif /** - * TCP_WND: The size of a TCP window. This must be at least + * TCP_WND: The size of a TCP window. This must be at least * (2 * TCP_MSS) for things to work well */ #ifndef TCP_WND -#define TCP_WND (4 * TCP_MSS) -#endif +#define TCP_WND (4 * TCP_MSS) +#endif /** * TCP_MAXRTX: Maximum number of retransmissions of data segments. */ #ifndef TCP_MAXRTX -#define TCP_MAXRTX 12 +#define TCP_MAXRTX 12 #endif /** * TCP_SYNMAXRTX: Maximum number of retransmissions of SYN segments. */ #ifndef TCP_SYNMAXRTX -#define TCP_SYNMAXRTX 6 +#define TCP_SYNMAXRTX 6 #endif /** @@ -963,7 +964,7 @@ * Define to 0 if your device is low on memory. */ #ifndef TCP_QUEUE_OOSEQ -#define TCP_QUEUE_OOSEQ (LWIP_TCP) +#define TCP_QUEUE_OOSEQ (LWIP_TCP) #endif /** @@ -974,7 +975,7 @@ * an upper limit on the MSS advertised by the remote host. */ #ifndef TCP_MSS -#define TCP_MSS 1480 +#define TCP_MSS 1480 #endif /** @@ -986,16 +987,15 @@ * netif used for a connection and limits the MSS if it would be too big otherwise. */ #ifndef TCP_CALCULATE_EFF_SEND_MSS -#define TCP_CALCULATE_EFF_SEND_MSS 1 +#define TCP_CALCULATE_EFF_SEND_MSS 1 #endif - /** * TCP_SND_BUF: TCP sender buffer space (bytes). * To achieve good performance, this should be at least 2 * TCP_MSS. */ #ifndef TCP_SND_BUF -#define TCP_SND_BUF (2 * TCP_MSS) +#define TCP_SND_BUF (2 * TCP_MSS) #endif /** @@ -1003,7 +1003,7 @@ * as much as (2 * TCP_SND_BUF/TCP_MSS) for things to work. */ #ifndef TCP_SND_QUEUELEN -#define TCP_SND_QUEUELEN ((4 * (TCP_SND_BUF) + (TCP_MSS - 1))/(TCP_MSS)) +#define TCP_SND_QUEUELEN ((4 * (TCP_SND_BUF) + (TCP_MSS - 1)) / (TCP_MSS)) #endif /** @@ -1012,7 +1012,7 @@ * TCP snd_buf for select to return writable (combined with TCP_SNDQUEUELOWAT). */ #ifndef TCP_SNDLOWAT -#define TCP_SNDLOWAT LWIP_MIN(LWIP_MAX(((TCP_SND_BUF)/2), (2 * TCP_MSS) + 1), (TCP_SND_BUF) - 1) +#define TCP_SNDLOWAT LWIP_MIN(LWIP_MAX(((TCP_SND_BUF) / 2), (2 * TCP_MSS) + 1), (TCP_SND_BUF)-1) #endif /** @@ -1021,7 +1021,7 @@ * this number, select returns writable (combined with TCP_SNDLOWAT). */ #ifndef TCP_SNDQUEUELOWAT -#define TCP_SNDQUEUELOWAT LWIP_MAX(((TCP_SND_QUEUELEN)/2), 5) +#define TCP_SNDQUEUELOWAT LWIP_MAX(((TCP_SND_QUEUELEN) / 2), 5) #endif /** @@ -1029,7 +1029,7 @@ * Default is 0 (no limit). Only valid for TCP_QUEUE_OOSEQ==0. */ #ifndef TCP_OOSEQ_MAX_BYTES -#define TCP_OOSEQ_MAX_BYTES 0 +#define TCP_OOSEQ_MAX_BYTES 0 #endif /** @@ -1037,14 +1037,14 @@ * Default is 0 (no limit). Only valid for TCP_QUEUE_OOSEQ==0. */ #ifndef TCP_OOSEQ_MAX_PBUFS -#define TCP_OOSEQ_MAX_PBUFS 0 +#define TCP_OOSEQ_MAX_PBUFS 0 #endif /** * TCP_LISTEN_BACKLOG: Enable the backlog option for tcp listen pcb. */ #ifndef TCP_LISTEN_BACKLOG -#define TCP_LISTEN_BACKLOG 1 +#define TCP_LISTEN_BACKLOG 1 #endif /** @@ -1053,7 +1053,7 @@ * 0xff is the maximum (u8_t). */ #ifndef TCP_DEFAULT_LISTEN_BACKLOG -#define TCP_DEFAULT_LISTEN_BACKLOG 0xff +#define TCP_DEFAULT_LISTEN_BACKLOG 0xff #endif /** @@ -1071,14 +1071,14 @@ * TCP_MSS/4: Try to create 4 fragments or less per TCP packet. */ #ifndef TCP_OVERSIZE -#define TCP_OVERSIZE TCP_MSS +#define TCP_OVERSIZE TCP_MSS #endif /** * LWIP_TCP_TIMESTAMPS==1: support the TCP timestamp option. */ #ifndef LWIP_TCP_TIMESTAMPS -#define LWIP_TCP_TIMESTAMPS 0 +#define LWIP_TCP_TIMESTAMPS 0 #endif /** @@ -1086,7 +1086,7 @@ * explicit window update */ #ifndef TCP_WND_UPDATE_THRESHOLD -#define TCP_WND_UPDATE_THRESHOLD (TCP_WND / 4) +#define TCP_WND_UPDATE_THRESHOLD (TCP_WND / 4) #endif /** @@ -1097,11 +1097,10 @@ * for the event. This is the default. */ #if !defined(LWIP_EVENT_API) && !defined(LWIP_CALLBACK_API) -#define LWIP_EVENT_API 0 -#define LWIP_CALLBACK_API 1 +#define LWIP_EVENT_API 0 +#define LWIP_CALLBACK_API 1 #endif - /* ---------------------------------- ---------- Pbuf options ---------- @@ -1113,7 +1112,7 @@ * Ethernet. */ #ifndef PBUF_LINK_HLEN -#define PBUF_LINK_HLEN (14 + ETH_PAD_SIZE) +#define PBUF_LINK_HLEN (14 + ETH_PAD_SIZE) #endif /** @@ -1122,7 +1121,7 @@ * TCP_MSS, IP header, and link header. */ #ifndef PBUF_POOL_BUFSIZE -#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(TCP_MSS+40+PBUF_LINK_HLEN) +#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(TCP_MSS + 40 + PBUF_LINK_HLEN) #endif /* @@ -1135,14 +1134,14 @@ * field. */ #ifndef LWIP_NETIF_HOSTNAME -#define LWIP_NETIF_HOSTNAME 1 +#define LWIP_NETIF_HOSTNAME 1 #endif /** * LWIP_NETIF_API==1: Support netif api (in netifapi.c) */ #ifndef LWIP_NETIF_API -#define LWIP_NETIF_API 0 +#define LWIP_NETIF_API 0 #endif /** @@ -1150,7 +1149,7 @@ * changes its up/down status (i.e., due to DHCP IP acquistion) */ #ifndef LWIP_NETIF_STATUS_CALLBACK -#define LWIP_NETIF_STATUS_CALLBACK 1 +#define LWIP_NETIF_STATUS_CALLBACK 1 #endif /** @@ -1158,7 +1157,7 @@ * whenever the link changes (i.e., link down) */ #ifndef LWIP_NETIF_LINK_CALLBACK -#define LWIP_NETIF_LINK_CALLBACK 1 +#define LWIP_NETIF_LINK_CALLBACK 1 #endif /** @@ -1166,7 +1165,7 @@ * when a netif has been removed */ #ifndef LWIP_NETIF_REMOVE_CALLBACK -#define LWIP_NETIF_REMOVE_CALLBACK 0 +#define LWIP_NETIF_REMOVE_CALLBACK 0 #endif /** @@ -1177,7 +1176,7 @@ * if you have a tiny ARP table or if there never are concurrent connections. */ #ifndef LWIP_NETIF_HWADDRHINT -#define LWIP_NETIF_HWADDRHINT 0 +#define LWIP_NETIF_HWADDRHINT 0 #endif /** @@ -1185,7 +1184,7 @@ * address equal to the netif IP address, looping them back up the stack. */ #ifndef LWIP_NETIF_LOOPBACK -#define LWIP_NETIF_LOOPBACK 0 +#define LWIP_NETIF_LOOPBACK 0 #endif /** @@ -1193,7 +1192,7 @@ * sending for each netif (0 = disabled) */ #ifndef LWIP_LOOPBACK_MAX_PBUFS -#define LWIP_LOOPBACK_MAX_PBUFS 0 +#define LWIP_LOOPBACK_MAX_PBUFS 0 #endif /** @@ -1210,7 +1209,7 @@ * the main application loop. */ #ifndef LWIP_NETIF_LOOPBACK_MULTITHREADING -#define LWIP_NETIF_LOOPBACK_MULTITHREADING (!NO_SYS) +#define LWIP_NETIF_LOOPBACK_MULTITHREADING (!NO_SYS) #endif /** @@ -1223,7 +1222,7 @@ * @todo: TCP and IP-frag do not work with this, yet: */ #ifndef LWIP_NETIF_TX_SINGLE_PBUF -#define LWIP_NETIF_TX_SINGLE_PBUF 0 +#define LWIP_NETIF_TX_SINGLE_PBUF 0 #endif /* LWIP_NETIF_TX_SINGLE_PBUF */ /* @@ -1235,7 +1234,7 @@ * LWIP_HAVE_LOOPIF==1: Support loop interface (127.0.0.1) and loopif.c */ #ifndef LWIP_HAVE_LOOPIF -#define LWIP_HAVE_LOOPIF 0 +#define LWIP_HAVE_LOOPIF 0 #endif /* @@ -1247,7 +1246,7 @@ * LWIP_HAVE_SLIPIF==1: Support slip interface and slipif.c */ #ifndef LWIP_HAVE_SLIPIF -#define LWIP_HAVE_SLIPIF 0 +#define LWIP_HAVE_SLIPIF 0 #endif /* @@ -1259,7 +1258,7 @@ * TCPIP_THREAD_NAME: The name assigned to the main tcpip thread. */ #ifndef TCPIP_THREAD_NAME -#define TCPIP_THREAD_NAME "tcpip_thread" +#define TCPIP_THREAD_NAME "tcpip_thread" #endif /** @@ -1268,7 +1267,7 @@ * sys_thread_new() when the thread is created. */ #ifndef TCPIP_THREAD_STACKSIZE -#define TCPIP_THREAD_STACKSIZE 1024 +#define TCPIP_THREAD_STACKSIZE 1024 #endif /** @@ -1277,7 +1276,7 @@ * sys_thread_new() when the thread is created. */ #ifndef TCPIP_THREAD_PRIO -#define TCPIP_THREAD_PRIO (NORMALPRIO) +#define TCPIP_THREAD_PRIO (NORMALPRIO) #endif /** @@ -1286,14 +1285,14 @@ * sys_mbox_new() when tcpip_init is called. */ #ifndef TCPIP_MBOX_SIZE -#define TCPIP_MBOX_SIZE MEMP_NUM_PBUF +#define TCPIP_MBOX_SIZE MEMP_NUM_PBUF #endif /** * SLIPIF_THREAD_NAME: The name assigned to the slipif_loop thread. */ #ifndef SLIPIF_THREAD_NAME -#define SLIPIF_THREAD_NAME "slipif_loop" +#define SLIPIF_THREAD_NAME "slipif_loop" #endif /** @@ -1302,7 +1301,7 @@ * sys_thread_new() when the thread is created. */ #ifndef SLIPIF_THREAD_STACKSIZE -#define SLIPIF_THREAD_STACKSIZE 1024 +#define SLIPIF_THREAD_STACKSIZE 1024 #endif /** @@ -1311,14 +1310,14 @@ * sys_thread_new() when the thread is created. */ #ifndef SLIPIF_THREAD_PRIO -#define SLIPIF_THREAD_PRIO (NORMALPRIO) +#define SLIPIF_THREAD_PRIO (NORMALPRIO) #endif /** * PPP_THREAD_NAME: The name assigned to the pppInputThread. */ #ifndef PPP_THREAD_NAME -#define PPP_THREAD_NAME "pppInputThread" +#define PPP_THREAD_NAME "pppInputThread" #endif /** @@ -1327,7 +1326,7 @@ * sys_thread_new() when the thread is created. */ #ifndef PPP_THREAD_STACKSIZE -#define PPP_THREAD_STACKSIZE 1024 +#define PPP_THREAD_STACKSIZE 1024 #endif /** @@ -1336,14 +1335,14 @@ * sys_thread_new() when the thread is created. */ #ifndef PPP_THREAD_PRIO -#define PPP_THREAD_PRIO (NORMALPRIO) +#define PPP_THREAD_PRIO (NORMALPRIO) #endif /** * DEFAULT_THREAD_NAME: The name assigned to any other lwIP thread. */ #ifndef DEFAULT_THREAD_NAME -#define DEFAULT_THREAD_NAME "lwIP" +#define DEFAULT_THREAD_NAME "lwIP" #endif /** @@ -1352,7 +1351,7 @@ * sys_thread_new() when the thread is created. */ #ifndef DEFAULT_THREAD_STACKSIZE -#define DEFAULT_THREAD_STACKSIZE 1024 +#define DEFAULT_THREAD_STACKSIZE 1024 #endif /** @@ -1361,7 +1360,7 @@ * sys_thread_new() when the thread is created. */ #ifndef DEFAULT_THREAD_PRIO -#define DEFAULT_THREAD_PRIO (NORMALPRIO) +#define DEFAULT_THREAD_PRIO (NORMALPRIO) #endif /** @@ -1370,7 +1369,7 @@ * to sys_mbox_new() when the recvmbox is created. */ #ifndef DEFAULT_RAW_RECVMBOX_SIZE -#define DEFAULT_RAW_RECVMBOX_SIZE 4 +#define DEFAULT_RAW_RECVMBOX_SIZE 4 #endif /** @@ -1379,7 +1378,7 @@ * to sys_mbox_new() when the recvmbox is created. */ #ifndef DEFAULT_UDP_RECVMBOX_SIZE -#define DEFAULT_UDP_RECVMBOX_SIZE 4 +#define DEFAULT_UDP_RECVMBOX_SIZE 4 #endif /** @@ -1388,7 +1387,7 @@ * to sys_mbox_new() when the recvmbox is created. */ #ifndef DEFAULT_TCP_RECVMBOX_SIZE -#define DEFAULT_TCP_RECVMBOX_SIZE 40 +#define DEFAULT_TCP_RECVMBOX_SIZE 40 #endif /** @@ -1397,7 +1396,7 @@ * sys_mbox_new() when the acceptmbox is created. */ #ifndef DEFAULT_ACCEPTMBOX_SIZE -#define DEFAULT_ACCEPTMBOX_SIZE 4 +#define DEFAULT_ACCEPTMBOX_SIZE 4 #endif /* @@ -1410,7 +1409,7 @@ * Don't use it if you're not an active lwIP project member */ #ifndef LWIP_TCPIP_CORE_LOCKING -#define LWIP_TCPIP_CORE_LOCKING 0 +#define LWIP_TCPIP_CORE_LOCKING 0 #endif /** @@ -1418,21 +1417,21 @@ * Don't use it if you're not an active lwIP project member */ #ifndef LWIP_TCPIP_CORE_LOCKING_INPUT -#define LWIP_TCPIP_CORE_LOCKING_INPUT 0 +#define LWIP_TCPIP_CORE_LOCKING_INPUT 0 #endif /** * LWIP_NETCONN==1: Enable Netconn API (require to use api_lib.c) */ #ifndef LWIP_NETCONN -#define LWIP_NETCONN 1 +#define LWIP_NETCONN 1 #endif /** LWIP_TCPIP_TIMEOUT==1: Enable tcpip_timeout/tcpip_untimeout tod create * timers running in tcpip_thread from another thread. */ #ifndef LWIP_TCPIP_TIMEOUT -#define LWIP_TCPIP_TIMEOUT 1 +#define LWIP_TCPIP_TIMEOUT 1 #endif /* @@ -1444,7 +1443,7 @@ * LWIP_SOCKET==1: Enable Socket API (require to use sockets.c) */ #ifndef LWIP_SOCKET -#define LWIP_SOCKET 1 +#define LWIP_SOCKET 1 #endif /** @@ -1452,7 +1451,7 @@ * (only used if you use sockets.c) */ #ifndef LWIP_COMPAT_SOCKETS -#define LWIP_COMPAT_SOCKETS 1 +#define LWIP_COMPAT_SOCKETS 1 #endif /** @@ -1461,7 +1460,7 @@ * names (read, write & close). (only used if you use sockets.c) */ #ifndef LWIP_POSIX_SOCKETS_IO_NAMES -#define LWIP_POSIX_SOCKETS_IO_NAMES 1 +#define LWIP_POSIX_SOCKETS_IO_NAMES 1 #endif /** @@ -1470,7 +1469,7 @@ * in seconds. (does not require sockets.c, and will affect tcp.c) */ #ifndef LWIP_TCP_KEEPALIVE -#define LWIP_TCP_KEEPALIVE 0 +#define LWIP_TCP_KEEPALIVE 0 #endif /** @@ -1478,7 +1477,7 @@ * SO_SNDTIMEO processing. */ #ifndef LWIP_SO_SNDTIMEO -#define LWIP_SO_SNDTIMEO 1 +#define LWIP_SO_SNDTIMEO 1 #endif /** @@ -1486,33 +1485,33 @@ * SO_RCVTIMEO processing. */ #ifndef LWIP_SO_RCVTIMEO -#define LWIP_SO_RCVTIMEO 1 +#define LWIP_SO_RCVTIMEO 1 #endif /** - * LWIP_SO_LINGER==1: Enable linger option for sockets/netconns + * LWIP_SO_LINGER==1: Enable linger option for sockets/netconns */ -#define LWIP_SO_LINGER 1 +#define LWIP_SO_LINGER 1 /** * LWIP_SO_RCVBUF==1: Enable SO_RCVBUF processing. */ #ifndef LWIP_SO_RCVBUF -#define LWIP_SO_RCVBUF 1 +#define LWIP_SO_RCVBUF 1 #endif /** * If LWIP_SO_RCVBUF is used, this is the default value for recv_bufsize. */ #ifndef RECV_BUFSIZE_DEFAULT -#define RECV_BUFSIZE_DEFAULT INT_MAX +#define RECV_BUFSIZE_DEFAULT INT_MAX #endif /** * SO_REUSE==1: Enable SO_REUSEADDR option. */ #ifndef SO_REUSE -#define SO_REUSE 1 +#define SO_REUSE 1 #endif /** @@ -1521,7 +1520,7 @@ * WARNING: Adds a memcpy for every packet if passing to more than one pcb! */ #ifndef SO_REUSE_RXTOALL -#define SO_REUSE_RXTOALL 1 +#define SO_REUSE_RXTOALL 1 #endif /* @@ -1533,7 +1532,7 @@ * LWIP_STATS==1: Enable statistics collection in lwip_stats. */ #ifndef LWIP_STATS -#define LWIP_STATS 0 +#define LWIP_STATS 0 #endif #if LWIP_STATS @@ -1542,28 +1541,28 @@ * LWIP_STATS_DISPLAY==1: Compile in the statistics output functions. */ #ifndef LWIP_STATS_DISPLAY -#define LWIP_STATS_DISPLAY 0 +#define LWIP_STATS_DISPLAY 0 #endif /** * LINK_STATS==1: Enable link stats. */ #ifndef LINK_STATS -#define LINK_STATS 1 +#define LINK_STATS 1 #endif /** * ETHARP_STATS==1: Enable etharp stats. */ #ifndef ETHARP_STATS -#define ETHARP_STATS (LWIP_ARP) +#define ETHARP_STATS (LWIP_ARP) #endif /** * IP_STATS==1: Enable IP stats. */ #ifndef IP_STATS -#define IP_STATS 1 +#define IP_STATS 1 #endif /** @@ -1571,21 +1570,21 @@ * on if using either frag or reass. */ #ifndef IPFRAG_STATS -#define IPFRAG_STATS (IP_REASSEMBLY || IP_FRAG) +#define IPFRAG_STATS (IP_REASSEMBLY || IP_FRAG) #endif /** * ICMP_STATS==1: Enable ICMP stats. */ #ifndef ICMP_STATS -#define ICMP_STATS 1 +#define ICMP_STATS 1 #endif /** * IGMP_STATS==1: Enable IGMP stats. */ #ifndef IGMP_STATS -#define IGMP_STATS (LWIP_IGMP) +#define IGMP_STATS (LWIP_IGMP) #endif /** @@ -1593,7 +1592,7 @@ * UDP enabled, otherwise off. */ #ifndef UDP_STATS -#define UDP_STATS (LWIP_UDP) +#define UDP_STATS (LWIP_UDP) #endif /** @@ -1601,43 +1600,43 @@ * enabled, otherwise off. */ #ifndef TCP_STATS -#define TCP_STATS (LWIP_TCP) +#define TCP_STATS (LWIP_TCP) #endif /** * MEM_STATS==1: Enable mem.c stats. */ #ifndef MEM_STATS -#define MEM_STATS ((MEM_LIBC_MALLOC == 0) && (MEM_USE_POOLS == 0)) +#define MEM_STATS ((MEM_LIBC_MALLOC == 0) && (MEM_USE_POOLS == 0)) #endif /** * MEMP_STATS==1: Enable memp.c pool stats. */ #ifndef MEMP_STATS -#define MEMP_STATS (MEMP_MEM_MALLOC == 0) +#define MEMP_STATS (MEMP_MEM_MALLOC == 0) #endif /** * SYS_STATS==1: Enable system stats (sem and mbox counts, etc). */ #ifndef SYS_STATS -#define SYS_STATS (NO_SYS == 0) +#define SYS_STATS (NO_SYS == 0) #endif #else -#define LINK_STATS 0 -#define IP_STATS 0 -#define IPFRAG_STATS 0 -#define ICMP_STATS 0 -#define IGMP_STATS 0 -#define UDP_STATS 0 -#define TCP_STATS 0 -#define MEM_STATS 0 -#define MEMP_STATS 0 -#define SYS_STATS 0 -#define LWIP_STATS_DISPLAY 0 +#define LINK_STATS 0 +#define IP_STATS 0 +#define IPFRAG_STATS 0 +#define ICMP_STATS 0 +#define IGMP_STATS 0 +#define UDP_STATS 0 +#define TCP_STATS 0 +#define MEM_STATS 0 +#define MEMP_STATS 0 +#define SYS_STATS 0 +#define LWIP_STATS_DISPLAY 0 #endif /* LWIP_STATS */ @@ -1650,21 +1649,21 @@ * PPP_SUPPORT==1: Enable PPP. */ #ifndef PPP_SUPPORT -#define PPP_SUPPORT 0 +#define PPP_SUPPORT 0 #endif /** * PPPOE_SUPPORT==1: Enable PPP Over Ethernet */ #ifndef PPPOE_SUPPORT -#define PPPOE_SUPPORT 0 +#define PPPOE_SUPPORT 0 #endif /** * PPPOS_SUPPORT==1: Enable PPP Over Serial */ #ifndef PPPOS_SUPPORT -#define PPPOS_SUPPORT PPP_SUPPORT +#define PPPOS_SUPPORT PPP_SUPPORT #endif #if PPP_SUPPORT @@ -1673,106 +1672,106 @@ * NUM_PPP: Max PPP sessions. */ #ifndef NUM_PPP -#define NUM_PPP 1 +#define NUM_PPP 1 #endif /** * PAP_SUPPORT==1: Support PAP. */ #ifndef PAP_SUPPORT -#define PAP_SUPPORT 0 +#define PAP_SUPPORT 0 #endif /** * CHAP_SUPPORT==1: Support CHAP. */ #ifndef CHAP_SUPPORT -#define CHAP_SUPPORT 0 +#define CHAP_SUPPORT 0 #endif /** * MSCHAP_SUPPORT==1: Support MSCHAP. CURRENTLY NOT SUPPORTED! DO NOT SET! */ #ifndef MSCHAP_SUPPORT -#define MSCHAP_SUPPORT 0 +#define MSCHAP_SUPPORT 0 #endif /** * CBCP_SUPPORT==1: Support CBCP. CURRENTLY NOT SUPPORTED! DO NOT SET! */ #ifndef CBCP_SUPPORT -#define CBCP_SUPPORT 0 +#define CBCP_SUPPORT 0 #endif /** * CCP_SUPPORT==1: Support CCP. CURRENTLY NOT SUPPORTED! DO NOT SET! */ #ifndef CCP_SUPPORT -#define CCP_SUPPORT 0 +#define CCP_SUPPORT 0 #endif /** * VJ_SUPPORT==1: Support VJ header compression. */ #ifndef VJ_SUPPORT -#define VJ_SUPPORT 0 +#define VJ_SUPPORT 0 #endif /** * MD5_SUPPORT==1: Support MD5 (see also CHAP). */ #ifndef MD5_SUPPORT -#define MD5_SUPPORT 0 +#define MD5_SUPPORT 0 #endif /* * Timeouts */ #ifndef FSM_DEFTIMEOUT -#define FSM_DEFTIMEOUT 6 /* Timeout time in seconds */ +#define FSM_DEFTIMEOUT 6 /* Timeout time in seconds */ #endif #ifndef FSM_DEFMAXTERMREQS -#define FSM_DEFMAXTERMREQS 2 /* Maximum Terminate-Request transmissions */ +#define FSM_DEFMAXTERMREQS 2 /* Maximum Terminate-Request transmissions */ #endif #ifndef FSM_DEFMAXCONFREQS -#define FSM_DEFMAXCONFREQS 10 /* Maximum Configure-Request transmissions */ +#define FSM_DEFMAXCONFREQS 10 /* Maximum Configure-Request transmissions */ #endif #ifndef FSM_DEFMAXNAKLOOPS -#define FSM_DEFMAXNAKLOOPS 5 /* Maximum number of nak loops */ +#define FSM_DEFMAXNAKLOOPS 5 /* Maximum number of nak loops */ #endif #ifndef UPAP_DEFTIMEOUT -#define UPAP_DEFTIMEOUT 6 /* Timeout (seconds) for retransmitting req */ +#define UPAP_DEFTIMEOUT 6 /* Timeout (seconds) for retransmitting req */ #endif #ifndef UPAP_DEFREQTIME -#define UPAP_DEFREQTIME 30 /* Time to wait for auth-req from peer */ +#define UPAP_DEFREQTIME 30 /* Time to wait for auth-req from peer */ #endif #ifndef CHAP_DEFTIMEOUT -#define CHAP_DEFTIMEOUT 6 /* Timeout time in seconds */ +#define CHAP_DEFTIMEOUT 6 /* Timeout time in seconds */ #endif #ifndef CHAP_DEFTRANSMITS -#define CHAP_DEFTRANSMITS 10 /* max # times to send challenge */ +#define CHAP_DEFTRANSMITS 10 /* max # times to send challenge */ #endif /* Interval in seconds between keepalive echo requests, 0 to disable. */ #ifndef LCP_ECHOINTERVAL -#define LCP_ECHOINTERVAL 0 +#define LCP_ECHOINTERVAL 0 #endif /* Number of unanswered echo requests before failure. */ #ifndef LCP_MAXECHOFAILS -#define LCP_MAXECHOFAILS 3 +#define LCP_MAXECHOFAILS 3 #endif /* Max Xmit idle time (in jiffies) before resend flag char. */ #ifndef PPP_MAXIDLEFLAG -#define PPP_MAXIDLEFLAG 100 +#define PPP_MAXIDLEFLAG 100 #endif /* @@ -1783,24 +1782,24 @@ * (XXX - these constants should simply be shared by lcp.c instead * of living in lcp.h) */ -#define PPP_MTU 1500 /* Default MTU (size of Info field) */ +#define PPP_MTU 1500 /* Default MTU (size of Info field) */ #ifndef PPP_MAXMTU /* #define PPP_MAXMTU 65535 - (PPP_HDRLEN + PPP_FCSLEN) */ -#define PPP_MAXMTU 1500 /* Largest MTU we allow */ +#define PPP_MAXMTU 1500 /* Largest MTU we allow */ #endif -#define PPP_MINMTU 64 -#define PPP_MRU 1500 /* default MRU = max length of info field */ -#define PPP_MAXMRU 1500 /* Largest MRU we allow */ +#define PPP_MINMTU 64 +#define PPP_MRU 1500 /* default MRU = max length of info field */ +#define PPP_MAXMRU 1500 /* Largest MRU we allow */ #ifndef PPP_DEFMRU -#define PPP_DEFMRU 296 /* Try for this */ +#define PPP_DEFMRU 296 /* Try for this */ #endif -#define PPP_MINMRU 128 /* No MRUs below this */ +#define PPP_MINMRU 128 /* No MRUs below this */ #ifndef MAXNAMELEN -#define MAXNAMELEN 256 /* max length of hostname or name for auth */ +#define MAXNAMELEN 256 /* max length of hostname or name for auth */ #endif #ifndef MAXSECRETLEN -#define MAXSECRETLEN 256 /* max length of password or secret */ +#define MAXSECRETLEN 256 /* max length of password or secret */ #endif #endif /* PPP_SUPPORT */ @@ -1814,49 +1813,49 @@ * CHECKSUM_GEN_IP==1: Generate checksums in software for outgoing IP packets. */ #ifndef CHECKSUM_GEN_IP -#define CHECKSUM_GEN_IP 1 +#define CHECKSUM_GEN_IP 1 #endif - + /** * CHECKSUM_GEN_UDP==1: Generate checksums in software for outgoing UDP packets. */ #ifndef CHECKSUM_GEN_UDP -#define CHECKSUM_GEN_UDP 1 +#define CHECKSUM_GEN_UDP 1 #endif - + /** * CHECKSUM_GEN_TCP==1: Generate checksums in software for outgoing TCP packets. */ #ifndef CHECKSUM_GEN_TCP -#define CHECKSUM_GEN_TCP 1 +#define CHECKSUM_GEN_TCP 1 #endif /** * CHECKSUM_GEN_ICMP==1: Generate checksums in software for outgoing ICMP packets. */ #ifndef CHECKSUM_GEN_ICMP -#define CHECKSUM_GEN_ICMP 1 +#define CHECKSUM_GEN_ICMP 1 #endif - + /** * CHECKSUM_CHECK_IP==1: Check checksums in software for incoming IP packets. */ #ifndef CHECKSUM_CHECK_IP -#define CHECKSUM_CHECK_IP 1 +#define CHECKSUM_CHECK_IP 1 #endif - + /** * CHECKSUM_CHECK_UDP==1: Check checksums in software for incoming UDP packets. */ #ifndef CHECKSUM_CHECK_UDP -#define CHECKSUM_CHECK_UDP 1 +#define CHECKSUM_CHECK_UDP 1 #endif /** * CHECKSUM_CHECK_TCP==1: Check checksums in software for incoming TCP packets. */ #ifndef CHECKSUM_CHECK_TCP -#define CHECKSUM_CHECK_TCP 1 +#define CHECKSUM_CHECK_TCP 1 #endif /** @@ -1864,7 +1863,7 @@ * application buffers to pbufs. */ #ifndef LWIP_CHECKSUM_ON_COPY -#define LWIP_CHECKSUM_ON_COPY 0 +#define LWIP_CHECKSUM_ON_COPY 0 #endif /* @@ -1906,7 +1905,7 @@ * messages are written. */ #ifndef LWIP_DBG_MIN_LEVEL -#define LWIP_DBG_MIN_LEVEL LWIP_DBG_LEVEL_ALL +#define LWIP_DBG_MIN_LEVEL LWIP_DBG_LEVEL_ALL #endif /** @@ -1914,140 +1913,140 @@ * debug messages of certain types. */ #ifndef LWIP_DBG_TYPES_ON -#define LWIP_DBG_TYPES_ON LWIP_DBG_OFF +#define LWIP_DBG_TYPES_ON LWIP_DBG_OFF #endif /** * ETHARP_DEBUG: Enable debugging in etharp.c. */ #ifndef ETHARP_DEBUG -#define ETHARP_DEBUG LWIP_DBG_OFF +#define ETHARP_DEBUG LWIP_DBG_OFF #endif /** * NETIF_DEBUG: Enable debugging in netif.c. */ #ifndef NETIF_DEBUG -#define NETIF_DEBUG LWIP_DBG_OFF +#define NETIF_DEBUG LWIP_DBG_OFF #endif /** * PBUF_DEBUG: Enable debugging in pbuf.c. */ #ifndef PBUF_DEBUG -#define PBUF_DEBUG LWIP_DBG_OFF +#define PBUF_DEBUG LWIP_DBG_OFF #endif /** * API_LIB_DEBUG: Enable debugging in api_lib.c. */ #ifndef API_LIB_DEBUG -#define API_LIB_DEBUG LWIP_DBG_OFF +#define API_LIB_DEBUG LWIP_DBG_OFF #endif /** * API_MSG_DEBUG: Enable debugging in api_msg.c. */ #ifndef API_MSG_DEBUG -#define API_MSG_DEBUG LWIP_DBG_OFF +#define API_MSG_DEBUG LWIP_DBG_OFF #endif /** * SOCKETS_DEBUG: Enable debugging in sockets.c. */ #ifndef SOCKETS_DEBUG -#define SOCKETS_DEBUG LWIP_DBG_OFF +#define SOCKETS_DEBUG LWIP_DBG_OFF #endif /** * ICMP_DEBUG: Enable debugging in icmp.c. */ #ifndef ICMP_DEBUG -#define ICMP_DEBUG LWIP_DBG_OFF +#define ICMP_DEBUG LWIP_DBG_OFF #endif /** * IGMP_DEBUG: Enable debugging in igmp.c. */ #ifndef IGMP_DEBUG -#define IGMP_DEBUG LWIP_DBG_OFF +#define IGMP_DEBUG LWIP_DBG_OFF #endif /** * INET_DEBUG: Enable debugging in inet.c. */ #ifndef INET_DEBUG -#define INET_DEBUG LWIP_DBG_OFF +#define INET_DEBUG LWIP_DBG_OFF #endif /** * IP_DEBUG: Enable debugging for IP. */ #ifndef IP_DEBUG -#define IP_DEBUG LWIP_DBG_OFF +#define IP_DEBUG LWIP_DBG_OFF #endif /** * IP_REASS_DEBUG: Enable debugging in ip_frag.c for both frag & reass. */ #ifndef IP_REASS_DEBUG -#define IP_REASS_DEBUG LWIP_DBG_OFF +#define IP_REASS_DEBUG LWIP_DBG_OFF #endif /** * RAW_DEBUG: Enable debugging in raw.c. */ #ifndef RAW_DEBUG -#define RAW_DEBUG LWIP_DBG_OFF +#define RAW_DEBUG LWIP_DBG_OFF #endif /** * MEM_DEBUG: Enable debugging in mem.c. */ #ifndef MEM_DEBUG -#define MEM_DEBUG LWIP_DBG_OFF +#define MEM_DEBUG LWIP_DBG_OFF #endif /** * MEMP_DEBUG: Enable debugging in memp.c. */ #ifndef MEMP_DEBUG -#define MEMP_DEBUG LWIP_DBG_OFF +#define MEMP_DEBUG LWIP_DBG_OFF #endif /** * SYS_DEBUG: Enable debugging in sys.c. */ #ifndef SYS_DEBUG -#define SYS_DEBUG LWIP_DBG_OFF +#define SYS_DEBUG LWIP_DBG_OFF #endif /** * TIMERS_DEBUG: Enable debugging in timers.c. */ #ifndef TIMERS_DEBUG -#define TIMERS_DEBUG LWIP_DBG_OFF +#define TIMERS_DEBUG LWIP_DBG_OFF #endif /** * TCP_DEBUG: Enable debugging for TCP. */ #ifndef TCP_DEBUG -#define TCP_DEBUG LWIP_DBG_OFF +#define TCP_DEBUG LWIP_DBG_OFF #endif /** * TCP_INPUT_DEBUG: Enable debugging in tcp_in.c for incoming debug. */ #ifndef TCP_INPUT_DEBUG -#define TCP_INPUT_DEBUG LWIP_DBG_OFF +#define TCP_INPUT_DEBUG LWIP_DBG_OFF #endif /** * TCP_FR_DEBUG: Enable debugging in tcp_in.c for fast retransmit. */ #ifndef TCP_FR_DEBUG -#define TCP_FR_DEBUG LWIP_DBG_OFF +#define TCP_FR_DEBUG LWIP_DBG_OFF #endif /** @@ -2055,108 +2054,108 @@ * timeout. */ #ifndef TCP_RTO_DEBUG -#define TCP_RTO_DEBUG LWIP_DBG_OFF +#define TCP_RTO_DEBUG LWIP_DBG_OFF #endif /** * TCP_CWND_DEBUG: Enable debugging for TCP congestion window. */ #ifndef TCP_CWND_DEBUG -#define TCP_CWND_DEBUG LWIP_DBG_OFF +#define TCP_CWND_DEBUG LWIP_DBG_OFF #endif /** * TCP_WND_DEBUG: Enable debugging in tcp_in.c for window updating. */ #ifndef TCP_WND_DEBUG -#define TCP_WND_DEBUG LWIP_DBG_OFF +#define TCP_WND_DEBUG LWIP_DBG_OFF #endif /** * TCP_OUTPUT_DEBUG: Enable debugging in tcp_out.c output functions. */ #ifndef TCP_OUTPUT_DEBUG -#define TCP_OUTPUT_DEBUG LWIP_DBG_OFF +#define TCP_OUTPUT_DEBUG LWIP_DBG_OFF #endif /** * TCP_RST_DEBUG: Enable debugging for TCP with the RST message. */ #ifndef TCP_RST_DEBUG -#define TCP_RST_DEBUG LWIP_DBG_OFF +#define TCP_RST_DEBUG LWIP_DBG_OFF #endif /** * TCP_QLEN_DEBUG: Enable debugging for TCP queue lengths. */ #ifndef TCP_QLEN_DEBUG -#define TCP_QLEN_DEBUG LWIP_DBG_OFF +#define TCP_QLEN_DEBUG LWIP_DBG_OFF #endif /** * UDP_DEBUG: Enable debugging in UDP. */ #ifndef UDP_DEBUG -#define UDP_DEBUG LWIP_DBG_OFF +#define UDP_DEBUG LWIP_DBG_OFF #endif /** * TCPIP_DEBUG: Enable debugging in tcpip.c. */ #ifndef TCPIP_DEBUG -#define TCPIP_DEBUG LWIP_DBG_OFF +#define TCPIP_DEBUG LWIP_DBG_OFF #endif /** * PPP_DEBUG: Enable debugging for PPP. */ #ifndef PPP_DEBUG -#define PPP_DEBUG LWIP_DBG_OFF +#define PPP_DEBUG LWIP_DBG_OFF #endif /** * SLIP_DEBUG: Enable debugging in slipif.c. */ #ifndef SLIP_DEBUG -#define SLIP_DEBUG LWIP_DBG_OFF +#define SLIP_DEBUG LWIP_DBG_OFF #endif /** * DHCP_DEBUG: Enable debugging in dhcp.c. */ #ifndef DHCP_DEBUG -#define DHCP_DEBUG LWIP_DBG_OFF +#define DHCP_DEBUG LWIP_DBG_OFF #endif /** * AUTOIP_DEBUG: Enable debugging in autoip.c. */ #ifndef AUTOIP_DEBUG -#define AUTOIP_DEBUG LWIP_DBG_OFF +#define AUTOIP_DEBUG LWIP_DBG_OFF #endif /** * SNMP_MSG_DEBUG: Enable debugging for SNMP messages. */ #ifndef SNMP_MSG_DEBUG -#define SNMP_MSG_DEBUG LWIP_DBG_OFF +#define SNMP_MSG_DEBUG LWIP_DBG_OFF #endif /** * SNMP_MIB_DEBUG: Enable debugging for SNMP MIBs. */ #ifndef SNMP_MIB_DEBUG -#define SNMP_MIB_DEBUG LWIP_DBG_OFF +#define SNMP_MIB_DEBUG LWIP_DBG_OFF #endif /** * DNS_DEBUG: Enable debugging for DNS. */ #ifndef DNS_DEBUG -#define DNS_DEBUG LWIP_DBG_OFF +#define DNS_DEBUG LWIP_DBG_OFF #endif -// in order to enable the lwIP debug output the bellow has to be uncomment and +// in order to enable the lwIP debug output the below has to be uncomment and // the options above changed to LWIP_DBG_ON for the features that are to output debug information //#define LWIP_DEBUG 1 diff --git a/targets/FreeRTOS/common/include/targetHAL.h b/targets/FreeRTOS/common/include/targetHAL.h index 88e423288b..ca5b97fae0 100644 --- a/targets/FreeRTOS/common/include/targetHAL.h +++ b/targets/FreeRTOS/common/include/targetHAL.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // @@ -9,32 +9,43 @@ #include "FreeRTOS.h" #include #include "cmsis_gcc.h" +// TODO +// #include // global mutex protecting the internal state of the interpreter, including event flags -#define GLOBAL_LOCK(); UBaseType_t uxSavedInterruptStatus = 0; \ - if (xPortIsInsideInterrupt() == pdTRUE) { \ - uxSavedInterruptStatus = taskENTER_CRITICAL_FROM_ISR();\ - } else { portENTER_CRITICAL(); } -#define GLOBAL_UNLOCK(); if (xPortIsInsideInterrupt() == pdTRUE) { \ - taskEXIT_CRITICAL_FROM_ISR( uxSavedInterruptStatus ); \ - } else { portEXIT_CRITICAL(); } +#define GLOBAL_LOCK() \ + ; \ + UBaseType_t uxSavedInterruptStatus = 0; \ + if (xPortIsInsideInterrupt() == pdTRUE) \ + { \ + uxSavedInterruptStatus = taskENTER_CRITICAL_FROM_ISR(); \ + } \ + else \ + { \ + portENTER_CRITICAL(); \ + } +#define GLOBAL_UNLOCK() \ + ; \ + if (xPortIsInsideInterrupt() == pdTRUE) \ + { \ + taskEXIT_CRITICAL_FROM_ISR(uxSavedInterruptStatus); \ + } \ + else \ + { \ + portEXIT_CRITICAL(); \ + } // platform dependent delay -#define PLATFORM_DELAY(milliSecs) vTaskDelay(milliSecs / portTICK_PERIOD_MS); +#define PLATFORM_DELAY(milliSecs) vTaskDelay(milliSecs / portTICK_PERIOD_MS); // Definitions for Sockets/Network -#define GLOBAL_LOCK_SOCKETS(x) +#define GLOBAL_LOCK_SOCKETS(x) -#define PLATFORM_DEPENDENT__SOCKETS_MAX_COUNT 16 +// TODO +// get number of sockets from lwIP options +// #define PLATFORM_DEPENDENT__SOCKETS_MAX_COUNT MEMP_NUM_NETCONN -#define LPCSTR const char* - - -// these macros are to be used at entry/exit of native interrupt handlers -#define NATIVE_INTERRUPT_START SystemState_SetNoLock( SYSTEM_STATE_ISR ); \ - SystemState_SetNoLock( SYSTEM_STATE_NO_CONTINUATIONS ); -#define NATIVE_INTERRUPT_END SystemState_ClearNoLock( SYSTEM_STATE_NO_CONTINUATIONS ); \ - SystemState_ClearNoLock( SYSTEM_STATE_ISR ); +#define LPCSTR const char * // TODO: Doesn't seem to be defined anywhere, used clr corlib math #define INT32 int32_t @@ -43,7 +54,7 @@ #if !defined(BUILD_RTM) -#define HARD_BREAKPOINT() HARD_Breakpoint() +#define HARD_BREAKPOINT() HARD_Breakpoint() // #if defined(_DEBUG) // #define DEBUG_HARD_BREAKPOINT() HARD_Breakpoint() @@ -56,7 +67,7 @@ // #define HARD_BREAKPOINT() // #define DEBUG_HARD_BREAKPOINT() -#endif // !defined(BUILD_RTM) +#endif // !defined(BUILD_RTM) #define NANOCLR_STOP() CPU_Reset(); @@ -67,11 +78,11 @@ // The implementation should is to be provided by each target at target_common.h.in // //////////////////////////////////////////////////////////////////////////////////////////////////// #if defined(BUILD_RTM) - #define EVENTS_HEART_BEAT +#define EVENTS_HEART_BEAT #else - #ifndef EVENTS_HEART_BEAT - #define EVENTS_HEART_BEAT __asm__ __volatile__ ("nop") - #endif // EVENTS_HEART_BEAT +#ifndef EVENTS_HEART_BEAT +#define EVENTS_HEART_BEAT __asm__ __volatile__("nop") +#endif // EVENTS_HEART_BEAT #endif extern int HeapBegin; diff --git a/targets/FreeRTOS/common/include/targetHAL_Time.h b/targets/FreeRTOS/common/include/targetHAL_Time.h index 359ea69119..ff10614003 100644 --- a/targets/FreeRTOS/common/include/targetHAL_Time.h +++ b/targets/FreeRTOS/common/include/targetHAL_Time.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/common/include/targetPAL_Time.h b/targets/FreeRTOS/common/include/targetPAL_Time.h index 30c22f2403..7a3b1eaa2a 100644 --- a/targets/FreeRTOS/common/include/targetPAL_Time.h +++ b/targets/FreeRTOS/common/include/targetPAL_Time.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/common/nanoCLR/CLR_Startup_Thread.c b/targets/FreeRTOS/common/nanoCLR/CLR_Startup_Thread.c index 0acbc0bda9..89ba869e72 100644 --- a/targets/FreeRTOS/common/nanoCLR/CLR_Startup_Thread.c +++ b/targets/FreeRTOS/common/nanoCLR/CLR_Startup_Thread.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/common/nanoCLR/CLR_Startup_Thread.h b/targets/FreeRTOS/common/nanoCLR/CLR_Startup_Thread.h index 71f1872a66..f1d67f2020 100644 --- a/targets/FreeRTOS/common/nanoCLR/CLR_Startup_Thread.h +++ b/targets/FreeRTOS/common/nanoCLR/CLR_Startup_Thread.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/common/nanoCLR/CMakeLists.txt b/targets/FreeRTOS/common/nanoCLR/CMakeLists.txt index 5ad64921c1..b6ea88464e 100644 --- a/targets/FreeRTOS/common/nanoCLR/CMakeLists.txt +++ b/targets/FreeRTOS/common/nanoCLR/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/targets/FreeRTOS/common/nanoCLR/WireProtocol_App_Interface.c b/targets/FreeRTOS/common/nanoCLR/WireProtocol_App_Interface.c index 21259693d8..64fa3d2ec3 100644 --- a/targets/FreeRTOS/common/nanoCLR/WireProtocol_App_Interface.c +++ b/targets/FreeRTOS/common/nanoCLR/WireProtocol_App_Interface.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/common/nanoCLR/nanoCRT.cpp b/targets/FreeRTOS/common/nanoCLR/nanoCRT.cpp index 45e1fa3ecb..3fcee4d9cd 100644 --- a/targets/FreeRTOS/common/nanoCLR/nanoCRT.cpp +++ b/targets/FreeRTOS/common/nanoCLR/nanoCRT.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/common/nanoCLR/targetPAL_Events.cpp b/targets/FreeRTOS/common/nanoCLR/targetPAL_Events.cpp index 37fa7bfe9d..a58db86edf 100644 --- a/targets/FreeRTOS/common/nanoCLR/targetPAL_Events.cpp +++ b/targets/FreeRTOS/common/nanoCLR/targetPAL_Events.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // @@ -10,139 +10,79 @@ #include "FreeRTOS.h" #include "timers.h" - uint64_t CPU_MillisecondsToTicks(uint64_t ticks); // timer for bool events static TimerHandle_t boolEventsTimer; -volatile uint32_t systemEvents; - -static void local_Events_SetBoolTimer_Callback( TimerHandle_t xTimer ); +static void local_Events_SetBoolTimer_Callback(TimerHandle_t xTimer); -set_Event_Callback g_Event_Callback = NULL; -void* g_Event_Callback_Arg = NULL; - -bool Events_Initialize() +bool Events_Initialize_Platform() { - NATIVE_PROFILE_PAL_EVENTS(); + boolEventsTimer = xTimerCreate("boolEventsTimer", 10, pdFALSE, (void *)0, local_Events_SetBoolTimer_Callback); - // init events - GLOBAL_LOCK(); - systemEvents = 0; - GLOBAL_UNLOCK(); - - boolEventsTimer = xTimerCreate( "boolEventsTimer", 10, pdFALSE, (void *)0, local_Events_SetBoolTimer_Callback); - return true; } -bool Events_Uninitialize() +bool Events_Uninitialize_Platform() { - NATIVE_PROFILE_PAL_EVENTS(); + xTimerDelete(boolEventsTimer, 0); - xTimerDelete(boolEventsTimer,0); - return true; } -void Events_Set( uint32_t events ) -{ - NATIVE_PROFILE_PAL_EVENTS(); - - // set events - GLOBAL_LOCK(); - systemEvents |= events; - GLOBAL_UNLOCK(); - - if( g_Event_Callback != NULL ) - { - g_Event_Callback( g_Event_Callback_Arg ); - } -} - -uint32_t Events_Get( uint32_t eventsOfInterest ) +static void local_Events_SetBoolTimer_Callback(TimerHandle_t xTimer) { NATIVE_PROFILE_PAL_EVENTS(); - - // get the requested flags from system events state and... - uint32_t returnEvents = (systemEvents & eventsOfInterest); - - // ... clear the requested flags atomically - GLOBAL_LOCK(); - systemEvents &= ~eventsOfInterest; - GLOBAL_UNLOCK(); - - // give the caller notice of just the events they asked for ( and were cleared already ) - return returnEvents; -} - -uint32_t Events_MaskedRead( uint32_t eventsOfInterest ) -{ - NATIVE_PROFILE_PAL_EVENTS(); - return (systemEvents & eventsOfInterest); -} - -static void local_Events_SetBoolTimer_Callback( TimerHandle_t xTimer ) -{ - NATIVE_PROFILE_PAL_EVENTS(); - bool* timerCompleteFlag = (bool*)pvTimerGetTimerID( xTimer ); + bool *timerCompleteFlag = (bool *)pvTimerGetTimerID(xTimer); *timerCompleteFlag = true; } -void Events_SetCallback( set_Event_Callback pfn, void* arg ) -{ - NATIVE_PROFILE_PAL_EVENTS(); - - g_Event_Callback = pfn; - g_Event_Callback_Arg = arg; -} - -void Events_SetBoolTimer( bool* timerCompleteFlag, uint32_t millisecondsFromNow ) +void Events_SetBoolTimer(bool *timerCompleteFlag, uint32_t millisecondsFromNow) { NATIVE_PROFILE_PAL_EVENTS(); // we assume only 1 can be active, abort previous just in case - xTimerStop( boolEventsTimer, 0 ); + xTimerStop(boolEventsTimer, 0); - if(timerCompleteFlag != NULL) + if (timerCompleteFlag != NULL) { - vTimerSetTimerID( boolEventsTimer, (void*) timerCompleteFlag ); - xTimerChangePeriod( boolEventsTimer, millisecondsFromNow / portTICK_PERIOD_MS, 0 ); + vTimerSetTimerID(boolEventsTimer, (void *)timerCompleteFlag); + xTimerChangePeriod(boolEventsTimer, millisecondsFromNow / portTICK_PERIOD_MS, 0); } } -uint32_t Events_WaitForEvents( uint32_t powerLevel, uint32_t wakeupSystemEvents, uint32_t timeoutMilliseconds ) +uint32_t Events_WaitForEvents(uint32_t powerLevel, uint32_t wakeupSystemEvents, uint32_t timeoutMilliseconds) { // schedule an interrupt for this far in the future // timeout is in milliseconds, need to convert to ticks uint64_t countsRemaining = CPU_MillisecondsToTicks(timeoutMilliseconds); - #if defined(HAL_PROFILE_ENABLED) +#if defined(HAL_PROFILE_ENABLED) Events_WaitForEvents_Calls++; - #endif +#endif - uint64_t expireTimeInTicks = HAL_Time_CurrentSysTicks() + countsRemaining; + uint64_t expireTimeInTicks = HAL_Time_CurrentSysTicks() + countsRemaining; bool runContinuations = true; - while(true) + while (true) { EVENTS_HEART_BEAT; - uint32_t events = Events_MaskedRead( wakeupSystemEvents ); - if(events) + uint32_t events = Events_MaskedRead(wakeupSystemEvents); + if (events) { return events; } - if(expireTimeInTicks <= HAL_Time_CurrentSysTicks()) + if (expireTimeInTicks <= HAL_Time_CurrentSysTicks()) { break; } // first check and possibly run any continuations // but only if we have slept after stalling - if(runContinuations && !SystemState_QueryNoLock(SYSTEM_STATE_NO_CONTINUATIONS)) + if (runContinuations && !SystemState_QueryNoLock(SYSTEM_STATE_NO_CONTINUATIONS)) { // if we stall on time, don't check again until after we sleep runContinuations = HAL_CONTINUATION::Dequeue_And_Execute(); @@ -152,14 +92,14 @@ uint32_t Events_WaitForEvents( uint32_t powerLevel, uint32_t wakeupSystemEvents, // try stalled continuations again after sleeping runContinuations = true; - HAL_COMPLETION::WaitForInterrupts(expireTimeInTicks, powerLevel, wakeupSystemEvents ); + HAL_COMPLETION::WaitForInterrupts(expireTimeInTicks, powerLevel, wakeupSystemEvents); } // no events, pass control to the OS taskYIELD(); - + // check if reboot or exit flags were set when the other OS threads executed - if(CLR_EE_DBG_IS(RebootPending) || CLR_EE_DBG_IS(ExitPending)) + if (CLR_EE_DBG_IS(RebootPending) || CLR_EE_DBG_IS(ExitPending)) { break; } @@ -177,6 +117,6 @@ void FreeManagedEvent(uint8_t category, uint8_t subCategory, uint16_t data1, uin (void)subCategory; (void)data1; (void)data2; - + NATIVE_PROFILE_PAL_EVENTS(); } diff --git a/targets/FreeRTOS/common/nanoCLR/targetPAL_Time.cpp b/targets/FreeRTOS/common/nanoCLR/targetPAL_Time.cpp index 3c250d25a4..f239a15b0f 100644 --- a/targets/FreeRTOS/common/nanoCLR/targetPAL_Time.cpp +++ b/targets/FreeRTOS/common/nanoCLR/targetPAL_Time.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/common/nanoCLR/targetPAL_Time.h b/targets/FreeRTOS/common/nanoCLR/targetPAL_Time.h index 30c22f2403..7a3b1eaa2a 100644 --- a/targets/FreeRTOS/common/nanoCLR/targetPAL_Time.h +++ b/targets/FreeRTOS/common/nanoCLR/targetPAL_Time.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/common/platform_heap.c b/targets/FreeRTOS/common/platform_heap.c index 4a2fe242ae..684fbb6399 100644 --- a/targets/FreeRTOS/common/platform_heap.c +++ b/targets/FreeRTOS/common/platform_heap.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/common/targetHAL.c b/targets/FreeRTOS/common/targetHAL.c index 57750250d8..c54a788ed0 100644 --- a/targets/FreeRTOS/common/targetHAL.c +++ b/targets/FreeRTOS/common/targetHAL.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS/common/targetHAL_Time.cpp b/targets/FreeRTOS/common/targetHAL_Time.cpp index 346989a732..e9a94160d0 100644 --- a/targets/FreeRTOS/common/targetHAL_Time.cpp +++ b/targets/FreeRTOS/common/targetHAL_Time.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/CMakeLists.txt b/targets/FreeRTOS_ESP32/CMakeLists.txt index 5d64776d35..47744625a7 100644 --- a/targets/FreeRTOS_ESP32/CMakeLists.txt +++ b/targets/FreeRTOS_ESP32/CMakeLists.txt @@ -1,111 +1,6 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # include(nf_utils) - -# if mbed TLS is enabled add it to the build -if(USE_SECURITY_MBEDTLS_OPTION) - - # check if MBEDTLS_SOURCE was specified or if it's empty (default is empty) - set(NO_MBEDTLS_SOURCE TRUE) - - if(MBEDTLS_SOURCE) - if(NOT "${MBEDTLS_SOURCE}" STREQUAL "") - set(NO_MBEDTLS_SOURCE FALSE) - endif() - endif() - - # set options for mbed TLS - option(ENABLE_TESTING "no testing when building mbed TLS." OFF) - - if(NO_MBEDTLS_SOURCE) - # no mbed TLS source specified, download it from it's repo - - # check for Git (needed here for advanced warning to user if it's not installed) - find_package(Git) - - # check if Git was found, if not report to user and abort - if(NOT GIT_EXECUTABLE) - message(FATAL_ERROR "error: could not find Git, make sure you have it installed.") - endif() - - # set tag for currently supported version - set(MBEDTLS_GIT_TAG "mbedtls-2.16.3") - - # need to setup a separate CMake project to download the code from the GitHub repository - # otherwise it won't be available before the actual build step - configure_file("${PROJECT_SOURCE_DIR}/CMake/mbedTLS.CMakeLists.cmake.in" - "${CMAKE_BINARY_DIR}/mbedTLS_Download/CMakeLists.txt") - - # setup CMake project for mbedTLS download - execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . - RESULT_VARIABLE result - WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/mbedTLS_Download") - - # run build on mbedTLS download CMake project to perform the download - execute_process(COMMAND ${CMAKE_COMMAND} --build . - RESULT_VARIABLE result - WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/mbedTLS_Download") - - # add mbedTLS as external project - ExternalProject_Add( - mbedTLS - PREFIX mbedTLS - SOURCE_DIR ${CMAKE_BINARY_DIR}/mbedTLS_Source - GIT_REPOSITORY https://github.com/nanoframework/mbedtls - GIT_TAG ${MBEDTLS_GIT_TAG} # target specified branch - GIT_SHALLOW 1 # download only the tip of the branch, not the complete history - TIMEOUT 10 - LOG_DOWNLOAD 1 - - # Disable all other steps - CONFIGURE_COMMAND "" - BUILD_COMMAND "" - INSTALL_COMMAND "" - ) - - else() - # mbedTLS source was specified - - # sanity check is source path exists - if(EXISTS "${MBEDTLS_SOURCE}/") - - # check if we already have the sources, no need to copy again - NF_DIRECTORY_EXISTS_NOT_EMPTY(${CMAKE_BINARY_DIR}/mbedTLS_Source/ SOURCE_EXISTS) - - if(NOT ${SOURCE_EXISTS}) - message(STATUS "mbedTLS source from: ${MBEDTLS_SOURCE}") - file(COPY "${MBEDTLS_SOURCE}/" DESTINATION "${CMAKE_BINARY_DIR}/mbedTLS_Source") - else() - message(STATUS "Using local cache of mbedTLS source from ${MBEDTLS_SOURCE}") - endif() - - set(MBEDTLS_INCLUDE_DIR ${CMAKE_BINARY_DIR}/mbedTLS_Source/include) - else() - message(FATAL_ERROR "Couldn't find mbedTLS source at ${MBEDTLS_SOURCE}/") - endif() - - # add mbedTLS as external project - ExternalProject_Add( - mbedTLS - PREFIX mbedTLS - SOURCE_DIR ${CMAKE_BINARY_DIR}/mbedTLS_Source - - # Disable all other steps - CONFIGURE_COMMAND "" - BUILD_COMMAND "" - INSTALL_COMMAND "" - ) - - endif() - - # get source dir for mbedTLS CMake project - ExternalProject_Get_Property(mbedTLS SOURCE_DIR) - - set(mbedTLS_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/3rdparty/humblelogging/include") - set(mbedTLS_LIBRARIES "${CMAKE_SHARED_LIBRARY_PREFIX}mbedTLS${CMAKE_SHARED_LIBRARY_SUFFIX}") - include_directories(${mbedTLS_INCLUDE_DIRS}) - -endif() diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/CMakeLists.txt b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/CMakeLists.txt index a0581ac140..c810f859b3 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/CMakeLists.txt +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # @@ -58,10 +58,9 @@ add_subdirectory("nanoCLR") # mbed TLS requires a config file if(USE_SECURITY_MBEDTLS_OPTION) - # this seems to be only option to properly set a compiler define through the command line that needs to be a string literal - file(TO_CMAKE_PATH "${PROJECT_SOURCE_DIR}/src/PAL/COM/sockets/ssl/mbedTLS/nf_mbedtls_config.h" MBED_CONFILE) - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMBEDTLS_CONFIG_FILE=\"<${MBED_CONFILE}>\"") - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMBEDTLS_CONFIG_FILE=\"<${MBED_CONFILE}>\"") + # # this seems to be only option to properly set a compiler define through the command line that needs to be a string literal + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMBEDTLS_CONFIG_FILE=\"<${PROJECT_SOURCE_DIR}/src/PAL/COM/sockets/ssl/mbedTLS/nf_mbedtls_config.h>\"") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMBEDTLS_CONFIG_FILE=\"<${PROJECT_SOURCE_DIR}/src/PAL/COM/sockets/ssl/mbedTLS/nf_mbedtls_config.h>\"") endif() # Build the networking components as a separate library @@ -74,10 +73,8 @@ if(USE_NETWORKING_OPTION) ) endif() -# add dependency for security provider mbedTLS -if(USE_SECURITY_MBEDTLS_OPTION) - add_dependencies(NetworkLib mbedTLS) -endif() +# Add Library for all NanoFramework Api +add_library(NanoApiLib STATIC ${TARGET_NANO_APIS_SOURCES} ) ####################### # nanoCLR executable @@ -102,9 +99,6 @@ add_executable( ${NF_CoreCLR_SOURCES} ${NF_Debugger_SOURCES} ${NF_Diagnostics_SOURCES} - - # # sources for nanoFramework APIs - ${TARGET_NANO_APIS_SOURCES} ) # Add link flags @@ -114,6 +108,8 @@ if(USE_SECURITY_MBEDTLS_OPTION) add_dependencies(${NANOCLR_PROJECT_NAME}.elf NetworkLib) endif() +add_dependencies(${NANOCLR_PROJECT_NAME}.elf NanoApiLib) + #message( "project libs:${PROJECT_LINK_LIBS} " ) set(LIBPATHSAVE "") foreach( IDF_libraries ${PROJECT_LINK_LIBS} ) @@ -166,11 +162,12 @@ foreach( IDF_libraries ${PROJECT_LINK_LIBS} ) endforeach( IDF_libraries ) - if(USE_NETWORKING_OPTION) set_property(TARGET ${NANOCLR_PROJECT_NAME}.elf APPEND_STRING PROPERTY LINK_FLAGS " -L${CMAKE_CURRENT_BINARY_DIR} -lNetworkLib " ) endif() +set_property(TARGET ${NANOCLR_PROJECT_NAME}.elf APPEND_STRING PROPERTY LINK_FLAGS " -Wl,--whole-archive -L${CMAKE_CURRENT_BINARY_DIR} -lNanoApiLib -Wl,--no-whole-archive " ) + set_property(TARGET ${NANOCLR_PROJECT_NAME}.elf APPEND_STRING PROPERTY LINK_FLAGS " -lgcc -lstdc++ -lgcov -Wl,--end-group -Wl,-EL ") # include common directories @@ -225,9 +222,23 @@ if(USE_NETWORKING_OPTION) set_target_properties(NetworkLib PROPERTIES COMPILE_FLAGS " -w " ) endif() + target_include_directories(NanoApiLib PUBLIC + # directories for nanoFramework libraries + ${CMAKE_CURRENT_BINARY_DIR}/nanoCLR + ${NF_CoreCLR_INCLUDE_DIRS} + + ${TARGET_ESP32_IDF_INCLUDES} + + # includes for nanoFramework APIs + ${TARGET_NANO_APIS_INCLUDES} +) + # set platform for NanoClr target_compile_definitions(${NANOCLR_PROJECT_NAME}.elf PUBLIC "-DPLATFORM_ESP32 " ) +# set platform for NanoApiLib +target_compile_definitions(NanoApiLib PUBLIC "-DPLATFORM_ESP32 " ) + # build types that have debugging capabilities AND are NOT RTM have to have the define 'NANOCLR_ENABLE_SOURCELEVELDEBUGGING' if((NOT NF_BUILD_RTM) OR NF_FEATURE_DEBUGGER) target_compile_definitions(${NANOCLR_PROJECT_NAME}.elf PUBLIC "-DNANOCLR_ENABLE_SOURCELEVELDEBUGGING ") @@ -272,6 +283,11 @@ if(USE_NETWORKING_OPTION) add_dependencies(${NANOCLR_PROJECT_NAME}.elf NetworkLib) endif() +# need to tweak this in case this path variable is empty +if(NOT EXECUTABLE_OUTPUT_PATH) + set(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/build) +endif() + # Create bin file from elf set(GEN_ESP32_BIN_PATH ${EXECUTABLE_OUTPUT_PATH} ) set(NANOCLR_BIN_FILE ${GEN_ESP32_BIN_PATH}/${NANOCLR_PROJECT_NAME}.bin) @@ -281,7 +297,7 @@ set(GEN_ESP32PART_PY_FILE ${ESP32_IDF_PATH}/components/partition_table/gen_esp32 add_custom_command( TARGET ${NANOCLR_PROJECT_NAME}.elf POST_BUILD COMMAND ${ESPTOOL_PY_FILE} ${ESPTOOL_PY_FLAGS} -o ${NANOCLR_BIN_FILE} ${EXECUTABLE_OUTPUT_PATH}/${NANOCLR_PROJECT_NAME}.elf - COMMENT "Generate nanoClr BIN file for deployment" ) + COMMENT "Generate nanoCLR BIN file for deployment" ) # # Create partition table add_custom_command( TARGET ${NANOCLR_PROJECT_NAME}.elf POST_BUILD diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/IDF/CMakeLists.txt b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/IDF/CMakeLists.txt index 562e4ae83a..96153121fb 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/IDF/CMakeLists.txt +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/IDF/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/CLR_Startup_Thread.h b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/CLR_Startup_Thread.h index 3c394ef4be..7c3f0f07d7 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/CLR_Startup_Thread.h +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/CLR_Startup_Thread.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/Esp32_DeviceMapping.h b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/Esp32_DeviceMapping.h index c3eacf548c..1980d53c83 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/Esp32_DeviceMapping.h +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/Esp32_DeviceMapping.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // @@ -11,10 +11,21 @@ #define _ESP32_DEVICEMAPPING_ // Default I2C gpio pins -#define I2C1_DATA 18 -#define I2C1_CLOCK 19 -#define I2C2_DATA 25 -#define I2C2_CLOCK 26 +#define I2C1_DATA 18 +#define I2C1_CLOCK 19 +#define I2C2_DATA 25 +#define I2C2_CLOCK 26 + +// UART defines +// number of pins required to configure an UART +enum Esp32SerialPin +{ + Esp32SerialPin_Tx, + Esp32SerialPin_Rx, + Esp32SerialPin_Rts, + Esp32SerialPin_Cts, + Esp32SerialPin_Max, +}; enum Esp32_MapDeviceType { @@ -22,15 +33,16 @@ enum Esp32_MapDeviceType DEV_TYPE_SPI, DEV_TYPE_I2C, DEV_TYPE_SERIAL, - DEV_TYPE_LED_PWM, - DEV_TYPE_ADC, - DEV_TYPE_DAC, - DEV_TYPE_MAX, + DEV_TYPE_LED_PWM, + DEV_TYPE_ADC, + DEV_TYPE_DAC, + DEV_TYPE_MAX, }; -int Esp32_GetMappedDevicePins(Esp32_MapDeviceType DevType, int DevNumber, int PinIndex); -int Esp32_GetMappedDevicePinsWithFunction(uint32_t alternateFunction); +int Esp32_GetMappedDevicePins(Esp32_MapDeviceType DevType, int DevNumber, int PinIndex); +int Esp32_GetMappedDevicePinsWithFunction(uint32_t alternateFunction); -void Esp32_SetMappedDevicePins( uint8_t pin, int32_t alternateFunction ); +void Esp32_SetMappedDevicePins(uint8_t pin, int32_t alternateFunction); +void Esp32_SetMappedDevicePins(Esp32_MapDeviceType devType, int devNumber, int8_t pinIndex, int ioPinNumber); #endif //_ESP32_DEVICEMAPPING_ diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/LaunchCLR.h b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/LaunchCLR.h index 15e319ef7e..08ccbb0451 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/LaunchCLR.h +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/LaunchCLR.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/TargetHAL_Spi.h b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/TargetHAL_Spi.h new file mode 100644 index 0000000000..079c238d68 --- /dev/null +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/TargetHAL_Spi.h @@ -0,0 +1,15 @@ +// +// Copyright (c) .NET Foundation and Contributors +// See LICENSE file in the project root for full license information. +// + +#ifndef _TARGET_HAL_SPI_H_ +#define _TARGET_HAL_SPI_H_ 1 + +// # of buses, first can't be used as used by SPI flash +#define NUM_SPI_BUSES 3 + +// Maximum number of devices per SPI bus +#define MAX_SPI_DEVICES 3 + +#endif //_TARGET_HAL_SPI_H_ diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/TargetPAL_BlockStorage.h b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/TargetPAL_BlockStorage.h index 805c2e320d..de9364c773 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/TargetPAL_BlockStorage.h +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/TargetPAL_BlockStorage.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/Target_BlockStorage_Esp32FlashDriver.h b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/Target_BlockStorage_Esp32FlashDriver.h index 4fa132812c..452870f99c 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/Target_BlockStorage_Esp32FlashDriver.h +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/Target_BlockStorage_Esp32FlashDriver.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/Target_Windows_Storage.h b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/Target_Windows_Storage.h index 888c34fef1..43f7367e2c 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/Target_Windows_Storage.h +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/Target_Windows_Storage.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/WireProtocol_ReceiverThread.h b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/WireProtocol_ReceiverThread.h index c6b75c3e8d..404e9eeae6 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/WireProtocol_ReceiverThread.h +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/WireProtocol_ReceiverThread.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/esp32_os.h b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/esp32_os.h index 0dfba6f541..7537e6ce18 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/esp32_os.h +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/esp32_os.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/platform_target_capabilities.h b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/platform_target_capabilities.h index e96158da28..6c377d19af 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/platform_target_capabilities.h +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/platform_target_capabilities.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/targetHAL.h b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/targetHAL.h index d77262996c..70968ba829 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/targetHAL.h +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/targetHAL.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // @@ -7,30 +7,24 @@ #define _TARGET_HAL_H_ #include +#include #include // global mutex protecting the internal state of the interpreter, including event flags extern portMUX_TYPE globalLockMutex; -#define GLOBAL_LOCK() portENTER_CRITICAL(&globalLockMutex); -#define GLOBAL_UNLOCK() portEXIT_CRITICAL(&globalLockMutex); +#define GLOBAL_LOCK() portENTER_CRITICAL(&globalLockMutex); +#define GLOBAL_UNLOCK() portEXIT_CRITICAL(&globalLockMutex); // platform dependent delay -#define PLATFORM_DELAY(milliSecs) vTaskDelay(milliSecs); +#define PLATFORM_DELAY(milliSecs) vTaskDelay(milliSecs); // Definitions for Sockets/Network -#define GLOBAL_LOCK_SOCKETS(x) +#define GLOBAL_LOCK_SOCKETS(x) -#define PLATFORM_DEPENDENT__SOCKETS_MAX_COUNT 16 - -#define LPCSTR const char* - - -// these macros are to be used at entry/exit of native interrupt handlers -#define NATIVE_INTERRUPT_START SystemState_SetNoLock( SYSTEM_STATE_ISR ); \ - SystemState_SetNoLock( SYSTEM_STATE_NO_CONTINUATIONS ); -#define NATIVE_INTERRUPT_END SystemState_ClearNoLock( SYSTEM_STATE_NO_CONTINUATIONS ); \ - SystemState_ClearNoLock( SYSTEM_STATE_ISR ); +// get number of sockets from lwIP options +#define PLATFORM_DEPENDENT__SOCKETS_MAX_COUNT MEMP_NUM_NETCONN +#define LPCSTR const char * // TODO: Doesn't seem to be defined anywhere, used clr corlib math #define INT32 int32_t @@ -39,7 +33,7 @@ extern portMUX_TYPE globalLockMutex; #if !defined(BUILD_RTM) -#define HARD_BREAKPOINT() HARD_Breakpoint() +#define HARD_BREAKPOINT() HARD_Breakpoint() // #if defined(_DEBUG) // #define DEBUG_HARD_BREAKPOINT() HARD_Breakpoint() @@ -52,11 +46,10 @@ extern portMUX_TYPE globalLockMutex; // #define HARD_BREAKPOINT() // #define DEBUG_HARD_BREAKPOINT() -#endif // !defined(BUILD_RTM) +#endif // !defined(BUILD_RTM) #define NANOCLR_STOP() HARD_BREAKPOINT() - ///////////////////////////////////////////////////////////////////////////////////////////////////// // DEBUGGER HELPER // // The line below is meant to be used as helper on checking that the execution engine is running. // @@ -64,11 +57,11 @@ extern portMUX_TYPE globalLockMutex; // The implementation should is to be provided by each target at target_common.h.in // //////////////////////////////////////////////////////////////////////////////////////////////////// #if defined(BUILD_RTM) - #define EVENTS_HEART_BEAT +#define EVENTS_HEART_BEAT #else - #ifndef EVENTS_HEART_BEAT - #define EVENTS_HEART_BEAT __asm__ __volatile__ ("nop") - #endif // EVENTS_HEART_BEAT +#ifndef EVENTS_HEART_BEAT +#define EVENTS_HEART_BEAT __asm__ __volatile__("nop") +#endif // EVENTS_HEART_BEAT #endif extern int HeapBegin; diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/targetHAL_Power.h b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/targetHAL_Power.h index 93af4528d6..a4fcfb9811 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/targetHAL_Power.h +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/targetHAL_Power.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/targetHAL_Time.h b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/targetHAL_Time.h index e66b86ce99..4387fcc2d7 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/targetHAL_Time.h +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/targetHAL_Time.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/targetPAL.h b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/targetPAL.h index 42d1f49456..8e7c1df040 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/targetPAL.h +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/targetPAL.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/targetPAL_Time.h b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/targetPAL_Time.h index e8383973b9..0d5190dabe 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/targetPAL_Time.h +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/targetPAL_Time.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Lwip/CMakeLists.txt b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Lwip/CMakeLists.txt index e5a99638f4..349ee3e340 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Lwip/CMakeLists.txt +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Lwip/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Network/CMakeLists.txt b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Network/CMakeLists.txt index 35fff0f528..759e2490bb 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Network/CMakeLists.txt +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Network/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Network/Esp32_Ethernet_Lan8720.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Network/Esp32_Ethernet_Lan8720.cpp index 46807c18e2..b9e58d47d2 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Network/Esp32_Ethernet_Lan8720.cpp +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Network/Esp32_Ethernet_Lan8720.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Network/Esp32_SmartConfig.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Network/Esp32_SmartConfig.cpp index bf9b46c620..4eef4d9fe7 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Network/Esp32_SmartConfig.cpp +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Network/Esp32_SmartConfig.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Network/Esp32_Wireless.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Network/Esp32_Wireless.cpp index d409d95995..fe59ac84c4 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Network/Esp32_Wireless.cpp +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Network/Esp32_Wireless.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Network/Target_Network.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Network/Target_Network.cpp index e25f593b25..de13b0a4e0 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Network/Target_Network.cpp +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Network/Target_Network.cpp @@ -1,6 +1,6 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Network/targetHAL_Network.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Network/targetHAL_Network.cpp index c493c21eae..c0eb0ec3a8 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Network/targetHAL_Network.cpp +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Network/targetHAL_Network.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/README.md b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/README.md index 27c86e4741..2c861e9b29 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/README.md +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/README.md @@ -1,5 +1,7 @@ # ESP32 WROOM-32 +The current image is built with mbedTLS v2.16.2. + This reference target _fits_ all EPS32 boards carrying an ESP32-WROOM-32 module. Check the details at the documentation website [here](http://docs.nanoframework.net/content/reference-targets/esp32-wroom-32.html) diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Target_Windows_Storage.c b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Target_Windows_Storage.c index 557e977dc4..049d4e409d 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Target_Windows_Storage.c +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Target_Windows_Storage.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/cmake-variants.json b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/cmake-variants.json new file mode 100644 index 0000000000..68af67ffbf --- /dev/null +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/cmake-variants.json @@ -0,0 +1,66 @@ +{ + "buildType": { + "default": "debug", + "choices": { + "debug": { + "short": "Debug", + "long": "Emit debug information without performing optimizations", + "buildType": "Debug" + }, + "minsize": { + "short": "MinSizeRel", + "long": "Optimize for smallest binary size", + "buildType": "MinSizeRel" + }, + "reldeb": { + "short": "RelWithDebInfo", + "long": "Perform optimizations AND include debugging information", + "buildType": "RelWithDebInfo" + } + } + }, + "linkage": { + "default": "", + "choices": { + "Esp32_nanoCLR": { + "short": "Esp32_nanoCLR", + "settings": { + "BUILD_VERSION": "0.9.99.999", + "CMAKE_TOOLCHAIN_FILE": "CMake/toolchain.xtensa-esp32-elf.cmake", + "TOOLCHAIN_PREFIX": "", + "ESP32_IDF_PATH": "", + "ESP32_LIBS_PATH": "", + "EXECUTABLE_OUTPUT_PATH": "${workspaceRoot}/build", + "TARGET_SERIES": "ESP32", + "ESP32_BOARD": "ESP32_WROOM_32", + "USE_FPU": "TRUE", + "RTOS": "FREERTOS_ESP32", + "NF_BUILD_RTM": "OFF", + "NF_FEATURE_DEBUGGER": "ON", + "NF_FEATURE_RTC": "ON", + "NF_FEATURE_SUPPORT_REFLECTION": "ON", + "NF_FEATURE_HAS_CONFIG_BLOCK": "ON", + "NF_FEATURE_HAS_SDCARD": "ON", + "API_System.Net": "ON", + "NF_SECURITY_MBEDTLS": "ON", + "MBEDTLS_SOURCE": "", + "API_nanoFramework.ResourceManager": "ON", + "API_nanoFramework.System.Collections": "ON", + "API_nanoFramework.System.Text": "ON", + "API_Windows.Devices.Wifi": "ON", + "API_Windows.Devices.Adc": "ON", + "API_System.Device.Dac": "OFF", + "API_Windows.Devices.Gpio": "ON", + "API_Windows.Devices.I2c": "ON", + "API_Windows.Devices.Pwm": "ON", + "API_Windows.Devices.SerialCommunication": "ON", + "API_Windows.Devices.Spi": "ON", + "API_Windows.Networking.Sockets": "OFF", + "API_Windows.Storage": "ON", + "API_Hardware.Esp32": "ON", + "API_nanoFramework.Hardware.Esp32.Rmt": "ON" + } + } + } + } +} \ No newline at end of file diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/common/CMakeLists.txt b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/common/CMakeLists.txt index c6518ee963..4b9be44011 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/common/CMakeLists.txt +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/common/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/common/Device_BlockStorage.c b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/common/Device_BlockStorage.c index f913b4ab03..078c9f02b6 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/common/Device_BlockStorage.c +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/common/Device_BlockStorage.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/common/Esp32_DeviceMapping.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/common/Esp32_DeviceMapping.cpp index c8c637afe6..b1a3075bac 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/common/Esp32_DeviceMapping.cpp +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/common/Esp32_DeviceMapping.cpp @@ -1,73 +1,70 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // #include "Esp32_os.h" #include "Esp32_DeviceMapping.h" - -// SPI +// SPI // 2 devices // Map pins mosi, miso, clock -// -int8_t Esp32_SPI_DevicePinMap[2][3] = -{ - {GPIO_NUM_23, GPIO_NUM_25, GPIO_NUM_19}, // SPI1 - Wrover SPI display pins - {-1, -1, -1} // SPI2 - no pins assigned +// +int8_t Esp32_SPI_DevicePinMap[2][3] = { + {GPIO_NUM_23, GPIO_NUM_25, GPIO_NUM_19}, // SPI1 - Wrover SPI display pins + {-1, -1, -1} // SPI2 - no pins assigned }; -// Serial +// Serial // 3 devices COM1,COM2, COM3 ( UART_NUM_0, UART_NUM_1, UART_NUM_2 ) // Map pins Tx, RX, RTS, CTS -// Set default direct pins -int8_t Esp32_SERIAL_DevicePinMap[3][4] = -{ +// Set pins to default for UART_NUM_0 +// others assign as NONE because the default pins can be shared with serial flash and PSRAM +int8_t Esp32_SERIAL_DevicePinMap[UART_NUM_MAX][Esp32SerialPin_Max] = { // COM 1 - pins 1, 3, 19, 22 - {UART_NUM_0_TXD_DIRECT_GPIO_NUM, UART_NUM_0_RXD_DIRECT_GPIO_NUM, UART_NUM_0_RTS_DIRECT_GPIO_NUM, UART_NUM_0_CTS_DIRECT_GPIO_NUM}, - - // COM 2 - 10, 9, 6, 11 - {UART_NUM_1_TXD_DIRECT_GPIO_NUM, UART_NUM_1_RXD_DIRECT_GPIO_NUM, UART_NUM_1_RTS_DIRECT_GPIO_NUM, UART_NUM_1_CTS_DIRECT_GPIO_NUM}, - - // COM3 - 17, 16, 8, 7 - {UART_NUM_2_TXD_DIRECT_GPIO_NUM, UART_NUM_2_RXD_DIRECT_GPIO_NUM, UART_NUM_2_RTS_DIRECT_GPIO_NUM, UART_NUM_2_CTS_DIRECT_GPIO_NUM} - }; + {UART_NUM_0_TXD_DIRECT_GPIO_NUM, + UART_NUM_0_RXD_DIRECT_GPIO_NUM, + UART_NUM_0_RTS_DIRECT_GPIO_NUM, + UART_NUM_0_CTS_DIRECT_GPIO_NUM}, + + // COM 2 - all set to UART_PIN_NO_CHANGE + {UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE}, + + // COM3 - all set to UART_PIN_NO_CHANGE + {UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE}}; // ============================================= -// I2C +// I2C // 2 devices I2C1 & I2C2 // Map pins Data & Clock -int8_t Esp32_I2C_DevicePinMap[2][2] = -{ +int8_t Esp32_I2C_DevicePinMap[2][2] = { // I2C1 - pins 18, 19, {I2C1_DATA, I2C1_CLOCK}, // I2C2 - pins 25, 26 - {I2C2_DATA, I2C2_CLOCK} -}; + {I2C2_DATA, I2C2_CLOCK}}; // ============================================= -// LED PWM +// LED PWM // 16 channels LED1 to LED16 or PWM1 to PWM16 // Map pins Data & Clock -int8_t Esp32_LED_DevicePinMap[16] = -{ - // Channels ( non assigned ) - -1, // 1 - -1, // 2 - -1, // 3 - -1, // 4 - -1, // 5 - -1, // 6 - -1, // 7 - -1, // 8 - -1, // 9 - -1, // 10 - -1, // 11 - -1, // 12 - -1, // 13 - -1, // 14 - -1, // 15 - -1, // 16 +int8_t Esp32_LED_DevicePinMap[16] = { + // Channels ( non assigned ) + -1, // 1 + -1, // 2 + -1, // 3 + -1, // 4 + -1, // 5 + -1, // 6 + -1, // 7 + -1, // 8 + -1, // 9 + -1, // 10 + -1, // 11 + -1, // 12 + -1, // 13 + -1, // 14 + -1, // 15 + -1, // 16 }; // We use "ADC1" for 20 logical channels @@ -75,125 +72,154 @@ int8_t Esp32_LED_DevicePinMap[16] = // ESP32 ADC1 channels 0 - 7 // " ADC1 channel 8 - Internal Temperture sensor (VP) // " ADC1 channel 9 - Internal Hall Sensor (VN) -// " ADC2 channels 10 - 19 -int8_t Esp32_ADC_DevicePinMap[20] = -{ - // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 - 36, 37, 38, 39, 32, 33, 34, 35, 36, 39, 04, 00, 02, 15, 13, 12, 14, 27, 25, 26 -}; +// " ADC2 channels 10 - 19 +int8_t Esp32_ADC_DevicePinMap[20] = { + // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 + 36, 37, 38, 39, 32, 33, 34, 35, 36, 39, 04, 00, 02, 15, 13, 12, 14, 27, 25, 26}; // // We use "DAC1" for 2 DAC channels on ESP32 // These are fixed pins so can't be re-assigned // -int8_t Esp32_DAC_DevicePinMap[2] = +int8_t Esp32_DAC_DevicePinMap[2] = { + // 0 1 + 25, + 26}; + +void Esp32_DecodeAlternateFunction( + uint32_t alternateFunction, + Esp32_MapDeviceType &deviceType, + uint8_t & busIndex, + uint16_t & PinIndex) { - // 0 1 - 25, 26 -}; - -void Esp32_DecodeAlternateFunction(uint32_t alternateFunction, Esp32_MapDeviceType & deviceType, uint8_t & busIndex, uint16_t & PinIndex) -{ - deviceType = (Esp32_MapDeviceType)((alternateFunction >> 16) & 0x00ff); - busIndex = (uint8_t)((alternateFunction >> 8) & 0x00ff) - 1; - PinIndex = (uint16_t)(alternateFunction & 0x00ff); + deviceType = (Esp32_MapDeviceType)((alternateFunction >> 16) & 0x00ff); + busIndex = (uint8_t)((alternateFunction >> 8) & 0x00ff) - 1; + PinIndex = (uint16_t)(alternateFunction & 0x00ff); } -int Esp32_GetMappedDevicePins( Esp32_MapDeviceType deviceType, int DevNumber, int PinIndex) +int Esp32_GetMappedDevicePins(Esp32_MapDeviceType deviceType, int DevNumber, int PinIndex) { - if ( DevNumber >= 0) + if (DevNumber >= 0) { - switch( deviceType ) + switch (deviceType) { case DEV_TYPE_SPI: return (int)Esp32_SPI_DevicePinMap[DevNumber][PinIndex]; - + case DEV_TYPE_I2C: return (int)Esp32_I2C_DevicePinMap[DevNumber][PinIndex]; - - case DEV_TYPE_SERIAL: - return (int)Esp32_SERIAL_DevicePinMap[DevNumber][PinIndex]; - - case DEV_TYPE_LED_PWM: + + case DEV_TYPE_SERIAL: + return (int)Esp32_SERIAL_DevicePinMap[DevNumber][PinIndex]; + + case DEV_TYPE_LED_PWM: return (int)Esp32_LED_DevicePinMap[DevNumber]; - case DEV_TYPE_ADC: - return (int)Esp32_ADC_DevicePinMap[PinIndex]; - - case DEV_TYPE_DAC: - return (int)Esp32_DAC_DevicePinMap[PinIndex]; + case DEV_TYPE_ADC: + return (int)Esp32_ADC_DevicePinMap[PinIndex]; + + case DEV_TYPE_DAC: + return (int)Esp32_DAC_DevicePinMap[PinIndex]; - default: + default: break; }; } return -1; } -int Esp32_GetMappedDevicePinsWithFunction(uint32_t alternateFunction) +int Esp32_GetMappedDevicePinsWithFunction(uint32_t alternateFunction) { - Esp32_MapDeviceType deviceType; - uint8_t deviceIndex; - uint16_t pinIndex; + Esp32_MapDeviceType deviceType; + uint8_t deviceIndex; + uint16_t pinIndex; - Esp32_DecodeAlternateFunction(alternateFunction, deviceType, deviceIndex, pinIndex); + Esp32_DecodeAlternateFunction(alternateFunction, deviceType, deviceIndex, pinIndex); - return Esp32_GetMappedDevicePins(deviceType, deviceIndex, pinIndex); + return Esp32_GetMappedDevicePins(deviceType, deviceIndex, pinIndex); } +void Esp32_SetMappedDevicePins(Esp32_MapDeviceType deviceType, int devNumber, int8_t pinIndex, int ioPinNumber) +{ + if (devNumber >= 0) + { + switch (deviceType) + { + case DEV_TYPE_SPI: + Esp32_SPI_DevicePinMap[devNumber][pinIndex] = ioPinNumber; + + case DEV_TYPE_I2C: + Esp32_I2C_DevicePinMap[devNumber][pinIndex] = ioPinNumber; + + case DEV_TYPE_SERIAL: + Esp32_SERIAL_DevicePinMap[devNumber][pinIndex] = ioPinNumber; + + case DEV_TYPE_LED_PWM: + Esp32_LED_DevicePinMap[devNumber] = ioPinNumber; + + case DEV_TYPE_ADC: + Esp32_ADC_DevicePinMap[pinIndex] = ioPinNumber; + + case DEV_TYPE_DAC: + Esp32_DAC_DevicePinMap[pinIndex] = ioPinNumber; + + default: + break; + }; + } +} // Esp32_SetMappedDevicePins // // alternateFunction 32 bit integer where 00DDIIFF // DD= device type -// II= device index 1,2,3 etc -// FF= functional pin i.e data, clock, tx,rx -// -void Esp32_SetMappedDevicePins( uint8_t pin, int32_t alternateFunction ) +// II= device index 1,2,3 etc +// FF= functional pin i.e data, clock, tx,rx +// +void Esp32_SetMappedDevicePins(uint8_t pin, int32_t alternateFunction) { - Esp32_MapDeviceType deviceType; - uint8_t deviceIndex; - uint16_t mapping; + Esp32_MapDeviceType deviceType; + uint8_t deviceIndex; + uint16_t mapping; - Esp32_DecodeAlternateFunction(alternateFunction, deviceType, deviceIndex, mapping); + Esp32_DecodeAlternateFunction(alternateFunction, deviceType, deviceIndex, mapping); // Set the pins used by a device type / index - switch( deviceType ) + switch (deviceType) { case DEV_TYPE_GPIO: // Just opening a GPIO pin will set it to GPIO function break; case DEV_TYPE_SPI: - if (deviceIndex <= 1 && mapping <= 2) + if (deviceIndex <= 1 && mapping <= 2) { Esp32_SPI_DevicePinMap[deviceIndex][mapping] = pin; } break; case DEV_TYPE_I2C: - if (deviceIndex <= 1 && mapping <= 1) + if (deviceIndex <= 1 && mapping <= 1) { Esp32_I2C_DevicePinMap[deviceIndex][mapping] = pin; } break; - case DEV_TYPE_SERIAL: - if (deviceIndex <= 2 && mapping <= 3) - { - Esp32_SERIAL_DevicePinMap[deviceIndex][mapping] = pin; - } - break; - - case DEV_TYPE_LED_PWM: - if (deviceIndex <= 15 ) + case DEV_TYPE_SERIAL: + if (deviceIndex < UART_NUM_MAX && mapping < Esp32SerialPin_Max) { - Esp32_LED_DevicePinMap[deviceIndex] = pin; + Esp32_SERIAL_DevicePinMap[deviceIndex][mapping] = pin; } break; + case DEV_TYPE_LED_PWM: + if (deviceIndex <= 15) + { + Esp32_LED_DevicePinMap[deviceIndex] = pin; + } + break; - default: // ignore + default: // ignore break; } } diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/common/GenericPort.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/common/GenericPort.cpp index e219b941ea..e942f90ef7 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/common/GenericPort.cpp +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/common/GenericPort.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/common/Target_BlockStorage_ESP32FlashDriver.c b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/common/Target_BlockStorage_ESP32FlashDriver.c index 1021d49242..a725a368ce 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/common/Target_BlockStorage_ESP32FlashDriver.c +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/common/Target_BlockStorage_ESP32FlashDriver.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/common/WireProtocol_HAL_Interface.c b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/common/WireProtocol_HAL_Interface.c index ce87a44dce..af52f91215 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/common/WireProtocol_HAL_Interface.c +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/common/WireProtocol_HAL_Interface.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // #include diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/common/WireProtocol_ReceiverThread.c b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/common/WireProtocol_ReceiverThread.c index ba1c129232..885ea84df4 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/common/WireProtocol_ReceiverThread.c +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/common/WireProtocol_ReceiverThread.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/common/mbedtls_entropy_hardware_pool.c b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/common/mbedtls_entropy_hardware_pool.c index 542b3ddb03..0111f8499e 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/common/mbedtls_entropy_hardware_pool.c +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/common/mbedtls_entropy_hardware_pool.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/common/platform_BlockStorage.c b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/common/platform_BlockStorage.c index f1e22e9c1e..3efd11a5e2 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/common/platform_BlockStorage.c +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/common/platform_BlockStorage.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/common/platform_heap.c b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/common/platform_heap.c index 6eaecdac64..8324e9a085 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/common/platform_heap.c +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/common/platform_heap.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/common/targetHAL.c b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/common/targetHAL.c index 35dac5ad85..9ca2316799 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/common/targetHAL.c +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/common/targetHAL.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/common/targetHAL_Time.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/common/targetHAL_Time.cpp index 1de75c87f9..48104c47cc 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/common/targetHAL_Time.cpp +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/common/targetHAL_Time.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/launch.json b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/launch.json new file mode 100644 index 0000000000..b2e4d4a3e2 --- /dev/null +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/launch.json @@ -0,0 +1,146 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "ESP32_WROOM_32 - Wrover", + "type": "cppdbg", + "request": "launch", + "MIMode": "gdb", + "miDebuggerPath": "/xtensa-esp32-elf/bin/xtensa-esp32-elf-gdb.exe", + "stopAtEntry": true, + "program": "/nanoCLR.elf", + "setupCommands": [ + { + "description": "", + "text": "set logging on" + }, + { + "description": "", + "text": "target extended-remote localhost:3333" + }, + { + "description": "", + "text": "file /nanoCLR.elf" + }, + { + "description": "", + "text": "monitor reset halt" + }, + { + "description": "", + "text": "thb app_main" + }, + { + "description": "", + "text": "x $a1=0" + } + ], + "launchCompleteCommand": "exec-run", + "debugServerPath": "/bin/openocd.exe", + "debugServerArgs": "-s \"/share/openocd/scripts/\" -f interface/ftdi/esp32_devkitj_v1.cfg -f target/esp32.cfg -c \"adapter_khz 2000\" ", + "serverStarted": "Info : .*Tensilica.*0x1.", + "filterStderr": true, + "externalConsole": true, + "cwd": "${cwd}", + "logging": { + "trace": true, + "traceResponse": true, + "engineLogging": true, + "programOutput": true, + "exceptions": true, + "moduleLoad": true + } + }, + { + "name": "ESP32_WROOM_32 - OLimex OCD-H", + "type": "cppdbg", + "request": "launch", + "MIMode": "gdb", + "miDebuggerPath": "/xtensa-esp32-elf/bin/xtensa-esp32-elf-gdb.exe", + "stopAtEntry": true, + "program": "/nanoCLR.elf", + "setupCommands": [ + { + "description": "", + "text": "set logging on" + }, + { + "description": "", + "text": "target extended-remote localhost:3333" + }, + { + "description": "", + "text": "file /nanoCLR.elf" + }, + { + "description": "", + "text": "monitor reset halt" + }, + { + "description": "", + "text": "thb app_main" + }, + { + "description": "", + "text": "x $a1=0" + } + ], + "launchCompleteCommand": "exec-run", + "debugServerPath": "/bin/openocd.exe", + "debugServerArgs": "-s \"/share/openocd/scripts/\" -f interface/ftdi/olimex-arm-usb-ocd-h.cfg -f target/esp32.cfg -c \"adapter_khz 3000\" ", + "serverStarted": "Info : .*Tensilica.*0x1.", + "filterStderr": true, + "externalConsole": true, + "cwd": "${cwd}", + "logging": { + "trace": false, + "traceResponse": false, + "engineLogging": false, + "programOutput": true, + "exceptions": true, + "moduleLoad": false + } + }, + { + "name": "ESP32_WROOM_32 - Segger JLink", + "type": "cppdbg", + "request": "launch", + "MIMode": "gdb", + "miDebuggerPath": "/xtensa-esp32-elf/bin/xtensa-esp32-elf-gdb.exe", + "stopAtEntry": true, + "program": "/nanoCLR.elf", + "setupCommands": [ + { + "text": "set logging on" + }, + { + "text": "target extended-remote localhost:3333" + }, + { + "text": "file /nanoCLR.elf" + }, + { + "text": "monitor reset halt" + }, + { + "text": "x $a1=0" + } + ], + "launchCompleteCommand": "exec-run", + "debugServerPath": "/bin/openocd.exe", + "debugServerArgs": "-s \"/share/openocd/scripts/\" -f interface/jlink.cfg -f target/esp32.cfg -c \"adapter_khz 3000\" ", + "serverStarted": "Info : .*Tensilica.*0x1.", + "filterStderr": true, + "externalConsole": true, + "cwd": "${cwd}", + "logging": { + "trace": false, + "traceResponse": false, + "engineLogging": false, + "programOutput": true, + "exceptions": true, + "moduleLoad": false + } + } + ] +} diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/mbedtls_config.h b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/mbedtls_config.h index ab0f87310c..f7c2457586 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/mbedtls_config.h +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/mbedtls_config.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) 2006-2015, ARM Limited, All Rights Reserved // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/CLR_Startup_Thread.c b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/CLR_Startup_Thread.c index aa7140dcad..d0f4b6e691 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/CLR_Startup_Thread.c +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/CLR_Startup_Thread.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/CMakeLists.txt b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/CMakeLists.txt index 026e8a5792..2841fe4f9c 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/CMakeLists.txt +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Memory.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Memory.cpp index 22ea3e9637..e084ad9353 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Memory.cpp +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Memory.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/System.Device.Dac/sys_dev_dac_native_System_Device_Dac_DacChannel.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/System.Device.Dac/sys_dev_dac_native_System_Device_Dac_DacChannel.cpp new file mode 100644 index 0000000000..7018cf108d --- /dev/null +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/System.Device.Dac/sys_dev_dac_native_System_Device_Dac_DacChannel.cpp @@ -0,0 +1,97 @@ +// +// Copyright (c) .NET Foundation and Contributors +// Portions Copyright (c) Microsoft Corporation. All rights reserved. +// See LICENSE file in the project root for full license information. +// + +#include "sys_dev_dac_native_target.h" + +HRESULT Library_sys_dev_dac_native_System_Device_Dac_DacChannel::NativeWriteValue___VOID__U2(CLR_RT_StackFrame &stack) +{ + NANOCLR_HEADER(); + { + CLR_RT_HeapBlock *dacController = NULL; + int channelNumber; + int controllerId; + dac_channel_t dacChannel = DAC_CHANNEL_1; + + // Get value argumant and mask to 0 - 255 range + uint16_t value = (stack.Arg1().NumericByRefConst().u2 & 0xff); + + // get a pointer to the managed object instance and check that it's not NULL + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + + // Get channel from _channelNumber field + channelNumber = pThis[FIELD___channelNumber].NumericByRef().s4; + + // need to get the controllerId for the DAC controller of this channel + // get pointer to DacController field + dacController = pThis[FIELD___dacController].Dereference(); + + // get pointer to _controllerId field in DacController + controllerId = dacController[Library_sys_dev_dac_native_System_Device_Dac_DacController::FIELD___controllerId] + .NumericByRef() + .s4; + + // only one DAC controller, but check it anyways + if (controllerId != 1) + { + NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); + } + + switch (channelNumber) + { + case 0: + dacChannel = DAC_CHANNEL_1; + break; + + case 1: + dacChannel = DAC_CHANNEL_2; + break; + + default: + NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); + } + + dac_output_voltage(dacChannel, value); + } + NANOCLR_NOCLEANUP(); +} + +HRESULT Library_sys_dev_dac_native_System_Device_Dac_DacChannel::NativeDispose___VOID__BOOLEAN(CLR_RT_StackFrame &stack) +{ + NANOCLR_HEADER(); + + int channelNumber; + bool disposeController = false; + + // get a pointer to the managed object instance and check that it's not NULL + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + + // get disposeController flag + disposeController = (bool)stack.Arg1().NumericByRef().u1; + + if (disposeController) + { + // Get channel from _channelNumber field + channelNumber = pThis[FIELD___channelNumber].NumericByRef().s4; + + switch (channelNumber) + { + case 1: + dac_output_disable(DAC_CHANNEL_1); + break; + + case 2: + dac_output_disable(DAC_CHANNEL_2); + break; + + default: + NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); + } + } + + NANOCLR_NOCLEANUP(); +} diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/System.Device.Dac/sys_dev_dac_native_System_Device_Dac_DacController.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/System.Device.Dac/sys_dev_dac_native_System_Device_Dac_DacController.cpp new file mode 100644 index 0000000000..b7a569b34e --- /dev/null +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/System.Device.Dac/sys_dev_dac_native_System_Device_Dac_DacController.cpp @@ -0,0 +1,131 @@ +// +// Copyright (c) .NET Foundation and Contributors +// Portions Copyright (c) Microsoft Corporation. All rights reserved. +// See LICENSE file in the project root for full license information. +// + +#include "sys_dev_dac_native_target.h" + +HRESULT Library_sys_dev_dac_native_System_Device_Dac_DacController::NativeOpenChannel___VOID__I4( + CLR_RT_StackFrame &stack) +{ + NANOCLR_HEADER(); + { + int controllerId; + int channelNumber; + dac_channel_t dacChannel = DAC_CHANNEL_1; + + // get a pointer to the managed object instance and check that it's not NULL + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + + // Get channel from argument + channelNumber = stack.Arg1().NumericByRef().s4; + + // get controller ID + controllerId = pThis[FIELD___controllerId].NumericByRef().s4; + + // only one DAC controller for now, but check it anyways + if (controllerId != 1) + { + NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); + } + + switch (channelNumber) + { + case 0: + dacChannel = DAC_CHANNEL_1; + break; + + case 1: + dacChannel = DAC_CHANNEL_2; + break; + + default: + NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); + } + + // Enable DAC for this channel + dac_output_enable(dacChannel); + } + NANOCLR_NOCLEANUP(); +} + +HRESULT Library_sys_dev_dac_native_System_Device_Dac_DacController::NativeGetChannelCount___I4(CLR_RT_StackFrame &stack) +{ + NANOCLR_HEADER(); + { + int controllerId; + int channelCount = 0; + + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + + controllerId = pThis[FIELD___controllerId].NumericByRefConst().s4; + + switch (controllerId) + { + case 1: + channelCount = DacChannelCount; + break; + + default: + NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); + } + + // Return value to the managed application + stack.SetResult_I4(channelCount); + } + NANOCLR_NOCLEANUP(); +} + +HRESULT Library_sys_dev_dac_native_System_Device_Dac_DacController::NativeGetResolutionInBits___I4( + CLR_RT_StackFrame &stack) +{ + NANOCLR_HEADER(); + { + // Fixed at 8 bit + stack.SetResult_I4(DacResolutionInBits); + } + NANOCLR_NOCLEANUP_NOLABEL(); +} + +HRESULT Library_sys_dev_dac_native_System_Device_Dac_DacController::NativeInit___VOID(CLR_RT_StackFrame &stack) +{ + NANOCLR_HEADER(); + + int controllerId; + + // get a pointer to the managed object instance and check that it's not NULL + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + + // get pointer to _controllerId field in AdcController + controllerId = pThis[FIELD___controllerId].NumericByRef().s4; + + // all required initialization for DAC is already handled in ChibiOS driver + + switch (controllerId) + { + case 1: + break; + + default: + NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); + } + + NANOCLR_NOCLEANUP(); +} + +HRESULT Library_sys_dev_dac_native_System_Device_Dac_DacController::GetDeviceSelector___STATIC__STRING( + CLR_RT_StackFrame &stack) +{ + NANOCLR_HEADER(); + { + // because the caller is expecting a result to be returned + // we need set a return result in the stack argument using the appropriate SetResult according to the variable + // type (a string here) + stack.SetResult_String("DAC1"); + } + NANOCLR_NOCLEANUP_NOLABEL(); +} diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/System.Devices.Dac/sys_dev_dac_native_target.h b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/System.Device.Dac/sys_dev_dac_native_target.h similarity index 54% rename from targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/System.Devices.Dac/sys_dev_dac_native_target.h rename to targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/System.Device.Dac/sys_dev_dac_native_target.h index 1c8b761678..2cb1533eb4 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/System.Devices.Dac/sys_dev_dac_native_target.h +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/System.Device.Dac/sys_dev_dac_native_target.h @@ -1,17 +1,15 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // - #ifndef _SYS_DEV_DAC_NATIVE_TARGET_H_ #define _SYS_DEV_DAC_NATIVE_TARGET_H_ #include #include +#define DacChannelCount 2 +#define DacResolutionInBits 8 -#define DacChannelCount 2 -#define DacResolutionInBits 8 - -#endif //_SYS_DEV_DAC_NATIVE_TARGET_H_ +#endif //_SYS_DEV_DAC_NATIVE_TARGET_H_ diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/System.Devices.Dac/sys_dev_dac_native_System_Devices_Dac_DacChannel.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/System.Devices.Dac/sys_dev_dac_native_System_Devices_Dac_DacChannel.cpp deleted file mode 100644 index a2ff12862b..0000000000 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/System.Devices.Dac/sys_dev_dac_native_System_Devices_Dac_DacChannel.cpp +++ /dev/null @@ -1,98 +0,0 @@ -// -// Copyright (c) 2019 The nanoFramework project contributors -// Portions Copyright (c) Microsoft Corporation. All rights reserved. -// See LICENSE file in the project root for full license information. -// - -#include "sys_dev_dac_native_target.h" - - - -HRESULT Library_sys_dev_dac_native_System_Devices_Dac_DacChannel::NativeWriteValue___VOID__U2(CLR_RT_StackFrame& stack) -{ - NANOCLR_HEADER(); - { - CLR_RT_HeapBlock* dacController = NULL; - int channelNumber; - int controllerId; - dac_channel_t dacChannel = DAC_CHANNEL_1; - - // Get value argumant and mask to 0 - 255 range - uint16_t value = (stack.Arg1().NumericByRefConst().u2 & 0xff); - - // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); - - // Get channel from _channelNumber field - channelNumber = pThis[FIELD___channelNumber].NumericByRef().s4; - - // need to get the controllerId for the DAC controller of this channel - // get pointer to DacController field - dacController = pThis[FIELD___dacController].Dereference(); - - // get pointer to _controllerId field in DacController - controllerId = dacController[Library_sys_dev_dac_native_System_Devices_Dac_DacController::FIELD___controllerId].NumericByRef().s4; - - // only one DAC controller, but check it anyways - if (controllerId != 1) - { - NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); - } - - switch(channelNumber) - { - case 0: - dacChannel = DAC_CHANNEL_1; - break; - - case 1: - dacChannel = DAC_CHANNEL_2; - break; - - default: - NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); - } - - dac_output_voltage(dacChannel, value); - - } - NANOCLR_NOCLEANUP(); -} - -HRESULT Library_sys_dev_dac_native_System_Devices_Dac_DacChannel::NativeDispose___VOID__BOOLEAN(CLR_RT_StackFrame& stack) -{ - NANOCLR_HEADER(); - - int channelNumber; - bool disposeController = false; - - // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); - - // get disposeController flag - disposeController = (bool)stack.Arg1().NumericByRef().u1; - - - if (disposeController) - { - // Get channel from _channelNumber field - channelNumber = pThis[FIELD___channelNumber].NumericByRef().s4; - - switch (channelNumber) - { - case 1: - dac_output_disable(DAC_CHANNEL_1); - break; - - case 2: - dac_output_disable(DAC_CHANNEL_2); - break; - - default: - NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); - } - - } - - NANOCLR_NOCLEANUP(); -} diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/System.Devices.Dac/sys_dev_dac_native_System_Devices_Dac_DacController.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/System.Devices.Dac/sys_dev_dac_native_System_Devices_Dac_DacController.cpp deleted file mode 100644 index dc97db1a98..0000000000 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/System.Devices.Dac/sys_dev_dac_native_System_Devices_Dac_DacController.cpp +++ /dev/null @@ -1,124 +0,0 @@ -// -// Copyright (c) 2019 The nanoFramework project contributors -// Portions Copyright (c) Microsoft Corporation. All rights reserved. -// See LICENSE file in the project root for full license information. -// - -#include "sys_dev_dac_native_target.h" - -HRESULT Library_sys_dev_dac_native_System_Devices_Dac_DacController::NativeOpenChannel___VOID__I4(CLR_RT_StackFrame& stack) -{ - NANOCLR_HEADER(); - { - int controllerId; - int channelNumber; - dac_channel_t dacChannel = DAC_CHANNEL_1; - - // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); - - // Get channel from argument - channelNumber = stack.Arg1().NumericByRef().s4; - - // get controller ID - controllerId = pThis[FIELD___controllerId].NumericByRef().s4; - - // only one DAC controller for now, but check it anyways - if(controllerId != 1) - { - NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); - } - - switch(channelNumber) - { - case 0: - dacChannel = DAC_CHANNEL_1; - break; - - case 1: - dacChannel = DAC_CHANNEL_2; - break; - - default: - NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); - } - - // Enable DAC for this channel - dac_output_enable(dacChannel); - } - NANOCLR_NOCLEANUP(); -} - -HRESULT Library_sys_dev_dac_native_System_Devices_Dac_DacController::NativeGetChannelCount___I4(CLR_RT_StackFrame& stack) -{ - NANOCLR_HEADER(); - { - int controllerId; - int channelCount = 0; - - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); - - controllerId = pThis[ FIELD___controllerId ].NumericByRefConst().s4; - - switch(controllerId) - { - case 1: - channelCount = DacChannelCount; - break; - - default: - NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); - } - - // Return value to the managed application - stack.SetResult_I4(channelCount); - } - NANOCLR_NOCLEANUP(); -} - -HRESULT Library_sys_dev_dac_native_System_Devices_Dac_DacController::NativeGetResolutionInBits___I4(CLR_RT_StackFrame& stack) -{ - NANOCLR_HEADER(); - { - // Fixed at 8 bit - stack.SetResult_I4(DacResolutionInBits); - } - NANOCLR_NOCLEANUP_NOLABEL(); -} - -HRESULT Library_sys_dev_dac_native_System_Devices_Dac_DacController::NativeInit___VOID( CLR_RT_StackFrame& stack ) -{ - NANOCLR_HEADER(); - - int controllerId; - - // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); - - // get pointer to _controllerId field in AdcController - controllerId = pThis[FIELD___controllerId].NumericByRef().s4; - - // all required initialization for DAC is already handled in ChibiOS driver - - switch(controllerId) - { - case 1: - break; - - default: - NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); - } - - NANOCLR_NOCLEANUP(); -} - -HRESULT Library_sys_dev_dac_native_System_Devices_Dac_DacController::GetDeviceSelector___STATIC__STRING( CLR_RT_StackFrame& stack ) -{ - NANOCLR_HEADER(); - { - // because the caller is expecting a result to be returned - // we need set a return result in the stack argument using the appropriate SetResult according to the variable type (a string here) - stack.SetResult_String("DAC1"); - } - NANOCLR_NOCLEANUP_NOLABEL(); -} diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Adc/win_dev_adc_native_Windows_Devices_Adc_AdcChannel.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Adc/win_dev_adc_native_Windows_Devices_Adc_AdcChannel.cpp index 049be34933..262f866141 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Adc/win_dev_adc_native_Windows_Devices_Adc_AdcChannel.cpp +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Adc/win_dev_adc_native_Windows_Devices_Adc_AdcChannel.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Adc/win_dev_adc_native_Windows_Devices_Adc_AdcController.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Adc/win_dev_adc_native_Windows_Devices_Adc_AdcController.cpp index 53a45bad1f..1bd956fa68 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Adc/win_dev_adc_native_Windows_Devices_Adc_AdcController.cpp +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Adc/win_dev_adc_native_Windows_Devices_Adc_AdcController.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Adc/win_dev_adc_native_target.h b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Adc/win_dev_adc_native_target.h index ed808e7e92..c226544194 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Adc/win_dev_adc_native_target.h +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Adc/win_dev_adc_native_target.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Gpio/cpu_gpio.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Gpio/cpu_gpio.cpp index 40a3ae17ea..8fd746e701 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Gpio/cpu_gpio.cpp +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Gpio/cpu_gpio.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // @@ -18,77 +18,91 @@ #include "Esp32_DeviceMapping.h" -static const char* TAG = "cpu_Gpio"; +static const char *TAG = "cpu_Gpio"; -#define ESP32_Gpio_MaxPins GPIO_PIN_COUNT // 0 -> 31, 32-39 (high) +#define ESP32_Gpio_MaxPins GPIO_PIN_COUNT // 0 -> 31, 32-39 (high) #define TOTAL_GPIO_PORTS ((ESP32_Gpio_MaxPins + 15) / 16) // Double linkedlist to hold the state of each Input pin struct gpio_input_state : public HAL_DblLinkedNode { - GPIO_PIN pinNumber; // Pin number - TimerHandle_t debounceTimer; // debounce timer for this Pin - GPIO_INTERRUPT_SERVICE_ROUTINE isrPtr; // Ptr to user ISR or null - uint32_t debounceMs; // debounce Millsecs, no debonce=0 - uint8_t mode; // Interrupt mode - void * param; // Param to user isr call - bool expected; // Expected state for debounce handler - bool waitingDebounce; // True if waiting for debounce timer to complete + GPIO_PIN pinNumber; // Pin number + TimerHandle_t debounceTimer; // debounce timer for this Pin + GPIO_INTERRUPT_SERVICE_ROUTINE isrPtr; // Ptr to user ISR or null + uint32_t debounceMs; // debounce Millsecs, no debonce=0 + uint8_t mode; // Interrupt mode + void *param; // Param to user isr call + bool expected; // Expected state for debounce handler + bool waitingDebounce; // True if waiting for debounce timer to complete }; -static HAL_DblLinkedList gpioInputList; // Doulble LInkedlist for GPIO input status -static uint16_t pinReserved[TOTAL_GPIO_PORTS]; // reserved - 1 bit per pin - +static HAL_DblLinkedList gpioInputList; // Doulble LInkedlist for GPIO input status +static uint16_t pinReserved[TOTAL_GPIO_PORTS]; // reserved - 1 bit per pin // Get pointer to gpio_input_state for Gpio pin // return NULL if not found -gpio_input_state * GetInputState(GPIO_PIN pinNumber) +gpio_input_state *GetInputState(GPIO_PIN pinNumber) { - gpio_input_state * ptr = gpioInputList.FirstNode(); - while ( ptr->Next() != NULL ) - { - if (ptr->pinNumber == pinNumber) return ptr; - ptr = ptr->Next(); - } - return NULL; + gpio_input_state *ptr = gpioInputList.FirstNode(); + while (ptr->Next() != NULL) + { + if (ptr->pinNumber == pinNumber) + return ptr; + ptr = ptr->Next(); + } + return NULL; } // Allocate a new gpio_input_state and add to end of list // if already exist then just return current ptr -gpio_input_state * AllocateGpioInputState(GPIO_PIN pinNumber) +gpio_input_state *AllocateGpioInputState(GPIO_PIN pinNumber) { - gpio_input_state * ptr = GetInputState(pinNumber); - if (ptr == NULL) - { - ptr = (gpio_input_state *)platform_malloc(sizeof(gpio_input_state)); - memset(ptr, 0, sizeof(gpio_input_state)); - ptr->pinNumber = pinNumber; - gpioInputList.LinkAtBack(ptr); - - } - return ptr; + gpio_input_state *ptr = GetInputState(pinNumber); + if (ptr == NULL) + { + ptr = (gpio_input_state *)platform_malloc(sizeof(gpio_input_state)); + memset(ptr, 0, sizeof(gpio_input_state)); + ptr->pinNumber = pinNumber; + gpioInputList.LinkAtBack(ptr); + } + return ptr; } -void UnlinkInputState(gpio_input_state * pState) +void UnlinkInputState(gpio_input_state *pState) { - if (pState->debounceTimer != 0) - { - xTimerDelete(pState->debounceTimer, 100); - } + if (pState->debounceTimer != 0) + { + xTimerDelete(pState->debounceTimer, 100); + } - // Remove interrupt associatted with pin - gpio_isr_handler_remove((gpio_num_t)pState->pinNumber); + // Remove interrupt associatted with pin + gpio_isr_handler_remove((gpio_num_t)pState->pinNumber); - pState->Unlink(); - platform_free(pState); + pState->Unlink(); + platform_free(pState); } // Delete gpio_input_state from List and tidy up ( Timer & ISR handler ) void DeleteInputState(GPIO_PIN pinNumber) { - gpio_input_state * pState = GetInputState(pinNumber); - if (pState) - UnlinkInputState(pState); + gpio_input_state *pState = GetInputState(pinNumber); + if (pState) + UnlinkInputState(pState); +} + +void Esp_Gpio_fire_event(gpio_input_state *pState) +{ + bool actual = CPU_GPIO_GetPinState(pState->pinNumber); // get current pin state + if (actual == pState->expected) + { + pState->isrPtr(pState->pinNumber, actual); + + if (pState->mode == GPIO_INT_EDGE_BOTH) + { + // both edges + pState->expected ^= 1; // update expected state + } + } } // @@ -96,210 +110,230 @@ void DeleteInputState(GPIO_PIN pinNumber) // void Esp_Gpio_DebounceHandler(TimerHandle_t xTimer) { - gpio_input_state* pState = (gpio_input_state*)pvTimerGetTimerID(xTimer); - if (pState->isrPtr) - { - bool actual = CPU_GPIO_GetPinState(pState->pinNumber); // get current pin state - if (actual == pState->expected) - { - pState->isrPtr(pState->pinNumber, actual, pState->param); - if (pState->mode == GPIO_INT_EDGE_BOTH) - { // both edges - pState->expected ^= 1; // update expected state - } - } - } - - pState->waitingDebounce = false; + gpio_input_state *pState = (gpio_input_state *)pvTimerGetTimerID(xTimer); + if (pState->isrPtr) + { + Esp_Gpio_fire_event(pState); + } + + pState->waitingDebounce = false; } -bool CPU_GPIO_Initialize() +bool CPU_GPIO_Initialize() { - // Initialise Double linked list for input pin states - gpioInputList.Initialize(); - - // Make sure all pins are not reserved - memset(pinReserved, 0, sizeof(pinReserved)); - - // Reserve Pins 6-11 as used by Spi flash - for (int pinNumber = 6; pinNumber <= 11; pinNumber++) - CPU_GPIO_ReservePin(pinNumber, true); - - // Install ISR service for GPIO - esp_err_t ret = gpio_install_isr_service(0); - if (ret != ESP_OK) - { - ESP_LOGE(TAG, "Install isr service"); - return false; - } - - return true; + // Initialise Double linked list for input pin states + gpioInputList.Initialize(); + + // Make sure all pins are not reserved + memset(pinReserved, 0, sizeof(pinReserved)); + + // Reserve Pins 6-11 as used by Spi flash + for (int pinNumber = 6; pinNumber <= 11; pinNumber++) + CPU_GPIO_ReservePin(pinNumber, true); + + // Install ISR service for GPIO + esp_err_t ret = gpio_install_isr_service(0); + if (ret != ESP_OK) + { + ESP_LOGE(TAG, "Install isr service"); + return false; + } + + return true; } -bool CPU_GPIO_Uninitialize() +bool CPU_GPIO_Uninitialize() { - gpio_input_state * pGpio; + gpio_input_state *pGpio; - pGpio = gpioInputList.FirstNode(); + pGpio = gpioInputList.FirstNode(); - // Clean up input state list - while ( pGpio->Next() != NULL ) - { - UnlinkInputState(pGpio); - pGpio = pGpio->Next(); - } + // Clean up input state list + while (pGpio->Next() != NULL) + { + UnlinkInputState(pGpio); + pGpio = pGpio->Next(); + } - gpio_uninstall_isr_service(); - return true; + gpio_uninstall_isr_service(); + return true; } // Set/reset reserved state of pin -bool CPU_GPIO_ReservePin(GPIO_PIN pinNumber, bool fReserve) +bool CPU_GPIO_ReservePin(GPIO_PIN pinNumber, bool fReserve) { - // Check if valid pin number - if (!GPIO_IS_VALID_GPIO((gpio_num_t)pinNumber)) return false; - - int port = pinNumber >> 4, bit = 1 << (pinNumber & 0x0F); - GLOBAL_LOCK(); - - if (fReserve) - { - if (pinReserved[port] & bit) - { - GLOBAL_UNLOCK(); - return false; // already reserved - } - - pinReserved[port] |= bit; - } - else - { - pinReserved[port] &= ~bit; - } - - GLOBAL_UNLOCK(); - return true; + // Check if valid pin number + if (!GPIO_IS_VALID_GPIO((gpio_num_t)pinNumber)) + return false; + + int port = pinNumber >> 4, bit = 1 << (pinNumber & 0x0F); + GLOBAL_LOCK(); + + if (fReserve) + { + if (pinReserved[port] & bit) + { + GLOBAL_UNLOCK(); + return false; // already reserved + } + + pinReserved[port] |= bit; + } + else + { + pinReserved[port] &= ~bit; + } + + GLOBAL_UNLOCK(); + return true; } // Return if Pin is reserved bool CPU_GPIO_PinIsBusy(GPIO_PIN pin) { - int port = pin >> 4, sh = pin & 0x0F; - return (pinReserved[port] >> sh) & 1; + int port = pin >> 4, sh = pin & 0x0F; + return (pinReserved[port] >> sh) & 1; } // Return maximum number of pins int32_t CPU_GPIO_GetPinCount() { - return ESP32_Gpio_MaxPins; + return ESP32_Gpio_MaxPins; } // Get current state of pin GpioPinValue CPU_GPIO_GetPinState(GPIO_PIN pin) { - return (GpioPinValue)gpio_get_level((gpio_num_t)pin); + return (GpioPinValue)gpio_get_level((gpio_num_t)pin); } // Set Pin state void CPU_GPIO_SetPinState(GPIO_PIN pin, GpioPinValue PinState) { - gpio_set_level((gpio_num_t)pin, (uint32_t)PinState); + gpio_set_level((gpio_num_t)pin, (uint32_t)PinState); } // ISR called by IDF -static void gpio_isr(void * arg) +static void gpio_isr(void *arg) { - NATIVE_INTERRUPT_START - - gpio_input_state * pGpio = (gpio_input_state *)arg;; - - // Ignore any pin changes during debounce - if (pGpio->waitingDebounce) return; - - // If user ISR available then call it - if (pGpio->isrPtr) - { - if (pGpio->debounceMs > 0) - { - pGpio->waitingDebounce = true; - - if (pGpio->debounceTimer == 0) - { - // Create timer if it doesn't already exist for this pin - pGpio->debounceTimer = xTimerCreate("debounce", 100, pdFALSE, (void*)pGpio, Esp_Gpio_DebounceHandler); - } - - // Start Debounce timer - xTimerChangePeriodFromISR(pGpio->debounceTimer, pdMS_TO_TICKS(pGpio->debounceMs), pdFALSE); - } - else - { - bool PinState = gpio_get_level((gpio_num_t)pGpio->pinNumber) == 1; - pGpio->isrPtr(pGpio->pinNumber, PinState, pGpio->param); - } - } - - NATIVE_INTERRUPT_END + NATIVE_INTERRUPT_START + + gpio_input_state *pState = (gpio_input_state *)arg; + ; + + // Ignore any pin changes during debounce + if (pState->waitingDebounce) + return; + + if (pState->debounceMs > 0) + { + pState->waitingDebounce = true; + + if (pState->debounceTimer == 0) + { + // Create timer if it doesn't already exist for this pin + pState->debounceTimer = xTimerCreate("debounce", 100, pdFALSE, (void *)pState, Esp_Gpio_DebounceHandler); + } + + // Start Debounce timer (minimum 1 freeRtos tick(10ms) ) + int ticks = pdMS_TO_TICKS(pState->debounceMs); + if (ticks == 0) + ticks = 1; + xTimerChangePeriodFromISR(pState->debounceTimer, ticks, pdFALSE); + } + else + { + Esp_Gpio_fire_event(pState); + } + + NATIVE_INTERRUPT_END } -bool CPU_GPIO_EnableInputPin(GPIO_PIN pinNumber, CLR_UINT64 debounceTimeMilliseconds, GPIO_INTERRUPT_SERVICE_ROUTINE pin_ISR, void* isr_Param, GPIO_INT_EDGE intEdge, GpioPinDriveMode driveMode) +bool CPU_GPIO_EnableInputPin( + GPIO_PIN pinNumber, + CLR_UINT64 debounceTimeMilliseconds, + GPIO_INTERRUPT_SERVICE_ROUTINE pinISR, + void *isr_Param, + GPIO_INT_EDGE intEdge, + GpioPinDriveMode driveMode) { - esp_err_t ret; - gpio_input_state * pState; - - // Check Input drive mode - if (driveMode >= (int)GpioPinDriveMode_Output) - return false; - - // Set as Input GPIO_INT_EDGE intEdge, GPIO_RESISTOR ResistorState - if (!CPU_GPIO_SetDriveMode(pinNumber, driveMode)) - return false; - - pState = AllocateGpioInputState(pinNumber); - - // Link ISR ptr supplied and not already set up - // CPU_GPIO_EnableInputPin could be called a 2nd time with changed parameters - if ( (pin_ISR != NULL) && (pState->isrPtr == NULL)) - { - ret = gpio_isr_handler_add((gpio_num_t)pinNumber, gpio_isr, (void *)pState); - if (ret != ESP_OK) - { - ESP_LOGE(TAG, "Add interrupt to gpio pin failed"); - return false; - } - - // Map Interrupt edge to ESP32 edge - // NONE=0, EDGE_LOW=1, EDGE_HIGH=2, EDGE_BOTH=3, LEVEL_HIGH=4, LEVEL_LOW - uint8_t mapint[6] = { GPIO_INTR_DISABLE, GPIO_INTR_NEGEDGE ,GPIO_INTR_POSEDGE, GPIO_INTR_ANYEDGE, GPIO_INTR_HIGH_LEVEL, GPIO_INTR_LOW_LEVEL }; - gpio_set_intr_type((gpio_num_t)pinNumber, (gpio_int_type_t)mapint[intEdge]); - } - - pState->isrPtr = pin_ISR; - pState->mode = intEdge; - pState->param = (void *)isr_Param; - pState->debounceMs = (uint32_t)(debounceTimeMilliseconds); - - switch (intEdge) - { - case GPIO_INT_EDGE_LOW: - case GPIO_INT_LEVEL_LOW: - pState->expected = false; - break; - - case GPIO_INT_EDGE_HIGH: - case GPIO_INT_LEVEL_HIGH: - pState->expected = true; - break; - - case GPIO_INT_EDGE_BOTH: - pState->expected = !CPU_GPIO_GetPinState(pinNumber); // Use not current state - break; - - default: - break; - } - - return true; + esp_err_t ret; + gpio_input_state *pState; + + // Check Input drive mode + if (driveMode >= (int)GpioPinDriveMode_Output) + return false; + + // Set as Input GPIO_INT_EDGE intEdge, GPIO_RESISTOR ResistorState + if (!CPU_GPIO_SetDriveMode(pinNumber, driveMode)) + return false; + + pState = AllocateGpioInputState(pinNumber); + + // Link ISR ptr supplied and not already set up + // CPU_GPIO_EnableInputPin could be called a 2nd time with changed parameters + if (pinISR != NULL && (pState->isrPtr == NULL)) + { + ret = gpio_isr_handler_add((gpio_num_t)pinNumber, gpio_isr, (void *)pState); + if (ret != ESP_OK) + { + ESP_LOGE(TAG, "Add interrupt to gpio pin failed"); + return false; + } + + // Map Interrupt edge to ESP32 edge + // NONE=0, EDGE_LOW=1, EDGE_HIGH=2, EDGE_BOTH=3, LEVEL_HIGH=4, LEVEL_LOW + uint8_t mapint[6] = { + GPIO_INTR_DISABLE, + GPIO_INTR_NEGEDGE, + GPIO_INTR_POSEDGE, + GPIO_INTR_ANYEDGE, + GPIO_INTR_HIGH_LEVEL, + GPIO_INTR_LOW_LEVEL}; + gpio_set_intr_type((gpio_num_t)pinNumber, (gpio_int_type_t)mapint[intEdge]); + + // store parameters & configs + pState->isrPtr = pinISR; + pState->mode = intEdge; + pState->param = (void *)isr_Param; + pState->debounceMs = (uint32_t)(debounceTimeMilliseconds); + + switch (intEdge) + { + case GPIO_INT_EDGE_LOW: + case GPIO_INT_LEVEL_LOW: + pState->expected = false; + break; + + case GPIO_INT_EDGE_HIGH: + case GPIO_INT_LEVEL_HIGH: + pState->expected = true; + break; + + case GPIO_INT_EDGE_BOTH: + pState->expected = !CPU_GPIO_GetPinState(pinNumber); // Use not current state + break; + + default: + break; + } + } + else if (pinISR == NULL && (pState->isrPtr != NULL)) + { + // there is no managed handler setup anymore + // remove INT handler + + // remove callback + gpio_isr_handler_remove((gpio_num_t)pState->pinNumber); + + // clear parameters & configs + pState->isrPtr = NULL; + pState->mode = GPIO_INT_NONE; + pState->param = NULL; + pState->debounceMs = 0; + } + + return true; } // Enable an output pin @@ -309,143 +343,145 @@ bool CPU_GPIO_EnableInputPin(GPIO_PIN pinNumber, CLR_UINT64 debounceTimeMillisec // driveMode - Drive mode and resistors // return - True if succesful, false invalid pin, pin not putput, invalid drive mode for ouptput // -bool CPU_GPIO_EnableOutputPin(GPIO_PIN pinNumber, GpioPinValue InitialState, GpioPinDriveMode driveMode) +bool CPU_GPIO_EnableOutputPin(GPIO_PIN pinNumber, GpioPinValue InitialState, GpioPinDriveMode driveMode) { - // check not an output drive mode - if (driveMode < (int)GpioPinDriveMode_Output) return false; + // check not an output drive mode + if (driveMode < (int)GpioPinDriveMode_Output) + return false; - // If this is currently an input pin then clean up - DeleteInputState(pinNumber); + // If this is currently an input pin then clean up + DeleteInputState(pinNumber); - if (CPU_GPIO_SetDriveMode(pinNumber, driveMode) == false) return false; + if (CPU_GPIO_SetDriveMode(pinNumber, driveMode) == false) + return false; - CPU_GPIO_SetPinState(pinNumber, InitialState); + CPU_GPIO_SetPinState(pinNumber, InitialState); - return true; + return true; } - void CPU_GPIO_DisablePin(GPIO_PIN pinNumber, GpioPinDriveMode driveMode, uint32_t alternateFunction) { - GLOBAL_LOCK(); - - DeleteInputState(pinNumber); + GLOBAL_LOCK(); - CPU_GPIO_SetDriveMode(pinNumber, driveMode); - - if (alternateFunction != 0) - { - Esp32_SetMappedDevicePins((uint8_t)pinNumber, alternateFunction); - } + DeleteInputState(pinNumber); - GLOBAL_UNLOCK(); + CPU_GPIO_SetDriveMode(pinNumber, driveMode); - CPU_GPIO_ReservePin(pinNumber, false); -} + if (alternateFunction != 0) + { + Esp32_SetMappedDevicePins((uint8_t)pinNumber, alternateFunction); + } + + GLOBAL_UNLOCK(); + CPU_GPIO_ReservePin(pinNumber, false); +} // Validate pin and set drive mode // return true if ok bool CPU_GPIO_SetDriveMode(GPIO_PIN pinNumber, GpioPinDriveMode driveMode) { - // Valid Pin - if (!GPIO_IS_VALID_GPIO(pinNumber)) - { - return false; - } - - // Check Pin is output capable - if (driveMode >= (int)GpioPinDriveMode_Output && !GPIO_IS_VALID_OUTPUT_GPIO(pinNumber)) - { - return false; - } - - gpio_mode_t mode = GPIO_MODE_DISABLE; - gpio_pullup_t pull_up_en = GPIO_PULLUP_DISABLE; - gpio_pulldown_t pull_down_en = GPIO_PULLDOWN_DISABLE; - gpio_int_type_t intr_type = GPIO_INTR_ANYEDGE; - - switch (driveMode) - { - case GpioPinDriveMode_Input: - mode = GPIO_MODE_INPUT; - break; - case GpioPinDriveMode_InputPullDown: - mode = GPIO_MODE_INPUT; - pull_down_en = GPIO_PULLDOWN_ENABLE; - break; - case GpioPinDriveMode_InputPullUp: - mode = GPIO_MODE_INPUT; - pull_up_en = GPIO_PULLUP_ENABLE; - break; - case GpioPinDriveMode_Output: - mode = GPIO_MODE_OUTPUT; - break; - case GpioPinDriveMode_OutputOpenDrain: - mode = GPIO_MODE_OUTPUT_OD; - break; - case GpioPinDriveMode_OutputOpenDrainPullUp: - mode = GPIO_MODE_OUTPUT_OD; - pull_up_en = GPIO_PULLUP_ENABLE; - break; - case GpioPinDriveMode_OutputOpenSource: - mode = GPIO_MODE_OUTPUT_OD; - break; - case GpioPinDriveMode_OutputOpenSourcePullDown: - mode = GPIO_MODE_OUTPUT_OD; - pull_down_en = GPIO_PULLDOWN_ENABLE; - break; - } - - gpio_config_t GPIOConfig; - - GPIOConfig.pin_bit_mask = (1ULL << pinNumber); - GPIOConfig.mode = mode; - GPIOConfig.pull_up_en = pull_up_en; - GPIOConfig.pull_down_en = pull_down_en; - GPIOConfig.intr_type = intr_type; - - gpio_config(&GPIOConfig); - - return true; + // Valid Pin + if (!GPIO_IS_VALID_GPIO(pinNumber)) + { + return false; + } + + // Check Pin is output capable + if (driveMode >= (int)GpioPinDriveMode_Output && !GPIO_IS_VALID_OUTPUT_GPIO(pinNumber)) + { + return false; + } + + gpio_mode_t mode = GPIO_MODE_DISABLE; + gpio_pullup_t pull_up_en = GPIO_PULLUP_DISABLE; + gpio_pulldown_t pull_down_en = GPIO_PULLDOWN_DISABLE; + gpio_int_type_t intr_type = GPIO_INTR_ANYEDGE; + + switch (driveMode) + { + case GpioPinDriveMode_Input: + mode = GPIO_MODE_INPUT; + break; + case GpioPinDriveMode_InputPullDown: + mode = GPIO_MODE_INPUT; + pull_down_en = GPIO_PULLDOWN_ENABLE; + break; + case GpioPinDriveMode_InputPullUp: + mode = GPIO_MODE_INPUT; + pull_up_en = GPIO_PULLUP_ENABLE; + break; + case GpioPinDriveMode_Output: + mode = GPIO_MODE_OUTPUT; + break; + case GpioPinDriveMode_OutputOpenDrain: + mode = GPIO_MODE_OUTPUT_OD; + break; + case GpioPinDriveMode_OutputOpenDrainPullUp: + mode = GPIO_MODE_OUTPUT_OD; + pull_up_en = GPIO_PULLUP_ENABLE; + break; + case GpioPinDriveMode_OutputOpenSource: + mode = GPIO_MODE_OUTPUT_OD; + break; + case GpioPinDriveMode_OutputOpenSourcePullDown: + mode = GPIO_MODE_OUTPUT_OD; + pull_down_en = GPIO_PULLDOWN_ENABLE; + break; + } + + gpio_config_t GPIOConfig; + + GPIOConfig.pin_bit_mask = (1ULL << pinNumber); + GPIOConfig.mode = mode; + GPIOConfig.pull_up_en = pull_up_en; + GPIOConfig.pull_down_en = pull_down_en; + GPIOConfig.intr_type = intr_type; + + gpio_config(&GPIOConfig); + + return true; } bool CPU_GPIO_DriveModeSupported(GPIO_PIN pinNumber, GpioPinDriveMode driveMode) { - if (!GPIO_IS_VALID_GPIO(pinNumber)) return false; - - // Output & input pins any valid drivemode - if (GPIO_IS_VALID_OUTPUT_GPIO(pinNumber)) - { - return ( - driveMode >= GpioPinDriveMode_Output && - driveMode <= GpioPinDriveMode_OutputOpenSourcePullDown); - } - - // Input only pins only input drive modes - return (driveMode <= GpioPinDriveMode_InputPullUp); + if (!GPIO_IS_VALID_GPIO(pinNumber)) + return false; + + // Input & Output pins use any valid drivemode. + // Note: all output pins are also input pins + if (GPIO_IS_VALID_OUTPUT_GPIO(pinNumber)) + { + return (driveMode <= GpioPinDriveMode_OutputOpenSourcePullDown); + } + + // Input only pins only input drive modes + return (driveMode <= GpioPinDriveMode_InputPullUp); } uint32_t CPU_GPIO_GetPinDebounce(GPIO_PIN pinNumber) { - if (!GPIO_IS_VALID_GPIO(pinNumber)) return 0; + if (!GPIO_IS_VALID_GPIO(pinNumber)) + return 0; - gpio_input_state * ptr = GetInputState(pinNumber); - if (ptr) - return ptr->debounceMs; + gpio_input_state *ptr = GetInputState(pinNumber); + if (ptr) + return ptr->debounceMs; - return 0; + return 0; } bool CPU_GPIO_SetPinDebounce(GPIO_PIN pinNumber, CLR_UINT64 debounceTimeMilliseconds) { - if (!GPIO_IS_VALID_GPIO(pinNumber)) return false; - - gpio_input_state * ptr = GetInputState(pinNumber); - if (ptr) - { - ptr->debounceMs = (uint32_t)(debounceTimeMilliseconds); - return true; - } - return false; + if (!GPIO_IS_VALID_GPIO(pinNumber)) + return false; + + gpio_input_state *ptr = GetInputState(pinNumber); + if (ptr) + { + ptr->debounceMs = (uint32_t)(debounceTimeMilliseconds); + return true; + } + return false; } diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Gpio/win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Gpio/win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter.cpp index febcb9307f..4e1872de02 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Gpio/win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter.cpp +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Gpio/win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Gpio/win_dev_gpio_native_target.h b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Gpio/win_dev_gpio_native_target.h index 991e00d6ac..93dcc20789 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Gpio/win_dev_gpio_native_target.h +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Gpio/win_dev_gpio_native_target.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.I2c/win_dev_i2c_native_Windows_Devices_I2C_I2cDevice.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.I2c/win_dev_i2c_native_Windows_Devices_I2C_I2cDevice.cpp index 896e21905a..0300637da6 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.I2c/win_dev_i2c_native_Windows_Devices_I2C_I2cDevice.cpp +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.I2c/win_dev_i2c_native_Windows_Devices_I2C_I2cDevice.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.I2c/win_dev_i2c_native_Windows_Devices_I2c_I2cController.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.I2c/win_dev_i2c_native_Windows_Devices_I2c_I2cController.cpp index 0552f96c77..db4a0aae93 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.I2c/win_dev_i2c_native_Windows_Devices_I2c_I2cController.cpp +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.I2c/win_dev_i2c_native_Windows_Devices_I2c_I2cController.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.I2c/win_dev_i2c_native_target.h b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.I2c/win_dev_i2c_native_target.h index 8dd64a47db..bf7913cb39 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.I2c/win_dev_i2c_native_target.h +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.I2c/win_dev_i2c_native_target.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Pwm/win_dev_pwm_native_Windows_Devices_Pwm_PwmController.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Pwm/win_dev_pwm_native_Windows_Devices_Pwm_PwmController.cpp index c85e0e0b31..7b84b77916 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Pwm/win_dev_pwm_native_Windows_Devices_Pwm_PwmController.cpp +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Pwm/win_dev_pwm_native_Windows_Devices_Pwm_PwmController.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Pwm/win_dev_pwm_native_Windows_Devices_Pwm_PwmPin.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Pwm/win_dev_pwm_native_Windows_Devices_Pwm_PwmPin.cpp index a599d594db..cb780f3be8 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Pwm/win_dev_pwm_native_Windows_Devices_Pwm_PwmPin.cpp +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Pwm/win_dev_pwm_native_Windows_Devices_Pwm_PwmPin.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Pwm/win_dev_pwm_native_target.h b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Pwm/win_dev_pwm_native_target.h index b102b091f9..affa99c902 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Pwm/win_dev_pwm_native_target.h +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Pwm/win_dev_pwm_native_target.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.SerialCommunication/win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.SerialCommunication/win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice.cpp index fee59e2319..85206db270 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.SerialCommunication/win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice.cpp +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.SerialCommunication/win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice.cpp @@ -1,279 +1,520 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // #include #include "win_dev_serial_native_target.h" -#include "Esp32_DeviceMapping.h" +#include -// buffers size -// tx buffer size: 256 bytes -#define UART_TX_BUFER_SIZE 256 -// rx buffer size: 256 bytes -#define UART_RX_BUFER_SIZE 256 +// UART buffer size: 256 bytes +#define UART_BUFER_SIZE 256 -// in UWP the COM ports are named COM1, COM2, COM3. But ESP32 uses internally UART0, UART1, UART2. This maps the port index 1, 2 or 3 to the uart number 0, 1 or 2 -#define PORT_INDEX_TO_UART_NUM(portIndex) ((portIndex) - 1) -// in UWP the COM ports are named COM1, COM2, COM3. But ESP32 uses internally UART0, UART1, UART2. This maps the uart number 0, 1 or 2 to the port index 1, 2 or 3 -#define UART_NUM_TO_PORT_INDEX(uart_num) ((uart_num) + 1) +// in UWP the COM ports are named COM1, COM2, COM3. But ESP32 uses internally UART0, UART1, UART2. This maps the port +// index 1, 2 or 3 to the uart number 0, 1 or 2 +#define PORT_INDEX_TO_UART_NUM(portIndex) ((portIndex)-1) +// in UWP the COM ports are named COM1, COM2, COM3. But ESP32 uses internally UART0, UART1, UART2. This maps the uart +// number 0, 1 or 2 to the port index 1, 2 or 3 +#define UART_NUM_TO_PORT_INDEX(uart_num) ((uart_num) + 1) -static const char* TAG = "SerialDevice"; +static const char *TAG = "SerialDevice"; -static char Esp_Serial_Initialised_Flag[UART_NUM_MAX] = {0, 0, 0}; -static QueueHandle_t Uart_Event_Queue[UART_NUM_MAX]; -static bool Uart_Post_SerialData_Chars_Event[UART_NUM_MAX] = {true, true, true}; -CLR_RT_HeapBlock* Serial_Device_Instance[UART_NUM_MAX]; -static int Uart_writeLength[UART_NUM_MAX]; +static NF_PAL_UART Uart0_PAL; +static NF_PAL_UART Uart1_PAL; +static NF_PAL_UART Uart2_PAL; -void Esp32_Serial_UnitializeAll() +NF_PAL_UART *GetPalUartFromUartNum(int uart_num) +{ + NF_PAL_UART *palUart = NULL; + + switch (uart_num) + { + case UART_NUM_0: + // set UART PAL + palUart = &Uart0_PAL; + break; + + case UART_NUM_1: + // set UART PAL + palUart = &Uart1_PAL; + break; + + case UART_NUM_2: + // set UART PAL + palUart = &Uart2_PAL; + break; + + default: + break; + } + return palUart; +} + +void UnitializePalUart(NF_PAL_UART *palUart) { - for (int uart_num = 0; uart_num < UART_NUM_MAX; uart_num++) + if (palUart && palUart->SerialDevice) { - if (Esp_Serial_Initialised_Flag[uart_num]) + // send the exit signal to the UART event handling queue + uart_event_t event; + event.type = UART_EVENT_MAX; + xQueueSend(palUart->UartEventQueue, &event, (portTickType)0); + + // free buffers meory + platform_free(palUart->RxBuffer); + platform_free(palUart->TxBuffer); + + // null all pointers + palUart->RxBuffer = NULL; + palUart->TxBuffer = NULL; + palUart->SerialDevice = NULL; + + // delete driver + uart_driver_delete((uart_port_t)palUart->UartNum); + + // delete task, if any + if (palUart->UartEventTask) { - // Delete uart driver and send the exit signal to the UART event handling queue - uart_driver_delete((uart_port_t)uart_num); - xQueueSend(Uart_Event_Queue[uart_num], (void*)UART_EVENT_MAX, (portTickType)0); - Uart_Post_SerialData_Chars_Event[uart_num] = false; - Serial_Device_Instance[uart_num] = NULL; - Esp_Serial_Initialised_Flag[uart_num] = 0; + vTaskDelete(palUart->UartEventTask); } + + palUart->UartEventTask = NULL; + } +} + +void Esp32_Serial_UnitializeAll() +{ + for (int uart_num = 0; uart_num < UART_NUM_MAX; uart_num++) + { + // free buffers memory + UnitializePalUart(GetPalUartFromUartNum(uart_num)); } } -static void uart_event_task(void *pvParameters) +void uart_event_task(void *pvParameters) { - int uart_num = (int)pvParameters; + // get PAL UART from task parameters + NF_PAL_UART *palUart = (NF_PAL_UART *)pvParameters; + uart_event_t event; bool run = true; - - while(run) - { + bool readData; + int32_t watchCharPos; + int32_t readCount; + size_t bufferedSize; + uint8_t *buffer; + + while (run) + { // Waiting for UART event. - if(xQueueReceive(Uart_Event_Queue[uart_num], (void*)&event, (portTickType)portMAX_DELAY)) { - switch(event.type) { - // Data received + if (xQueueReceive(palUart->UartEventQueue, &event, (portTickType)portMAX_DELAY)) + { + // reset vars + readData = false; + watchCharPos = -1; + + // deal with event type + switch (event.type) + { case UART_DATA: - // only if no one is reading the chars already and only if an event handler is attached - if (Uart_Post_SerialData_Chars_Event[uart_num] && Serial_Device_Instance[uart_num][Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::FIELD___callbacksDataReceivedEvent].Dereference() != NULL) - { - // post a managed event with the port index and the chars event code; uart_num + 1 because UART0 maps to COM1 - PostManagedEvent(EVENT_SERIAL, 0, UART_NUM_TO_PORT_INDEX(uart_num), SerialData_Chars); - // supress the event for the following chars; prevents spamming with the SerialData_Chars event - // the flag will be reset if NativeRead will be called - Uart_Post_SerialData_Chars_Event[uart_num] = false; - } + // set flag + readData = true; break; - // Pattern detection used for the WatchChar + case UART_PATTERN_DET: - // only if an event handler is attached - if (Serial_Device_Instance[uart_num][Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::FIELD___callbacksDataReceivedEvent].Dereference() != NULL) - { - // post a managed event with the port index and the watch char event code; uart_num + 1 because UART0 maps to COM1 - PostManagedEvent(EVENT_SERIAL, 0, UART_NUM_TO_PORT_INDEX(uart_num), SerialData_WatchChar); - } - break; - // signal to end the task (UART_EVENT_MAX used) - case UART_EVENT_MAX: - run = false; - break; - // Others + // Pattern detection used for the WatchChar + watchCharPos = uart_pattern_get_pos(palUart->UartNum); + + // set flag + readData = true; + break; + + case UART_FIFO_OVF: + case UART_BUFFER_FULL: + uart_flush_input(palUart->UartNum); + xQueueReset(palUart->UartEventQueue); + break; + + case UART_EVENT_MAX: + // signal to end the task (UART_EVENT_MAX used) + run = false; + break; + default: break; } + + if (readData) + { + // get how many chars are buffered on RX FIFO + uart_get_buffered_data_len(palUart->UartNum, &bufferedSize); + + if (bufferedSize > 0) + { + // alloc buffer to read RX FIFO + buffer = (uint8_t *)platform_malloc(bufferedSize); + + // sanity check + if (buffer) + { + // try to read RX FIFO + readCount = uart_read_bytes(palUart->UartNum, buffer, bufferedSize, 1); + + // push to UART RX buffer + palUart->RxRingBuffer.Push(buffer, readCount); + + // free buffer + platform_free(buffer); + + // is there a read operation going on? + if (palUart->RxBytesToRead > 0) + { + // yes + // check if the requested bytes are available in the buffer... + //... or if the watch char was received + if ((palUart->RxRingBuffer.Length() >= palUart->RxBytesToRead) || (watchCharPos > -1)) + { + // reset Rx bytes to read count + palUart->RxBytesToRead = 0; + + // fire event for Rx buffer complete + Events_Set(SYSTEM_EVENT_FLAG_COM_IN); + } + } + else + { + // no read operation ongoing, so fire an event + + // post a managed event with the port index and event code (check if there is a watch char + // in the buffer or just any char) + // check if callbacks are registered so this is called only if there is anyone listening + // otherwise don't bother + if (palUart + ->SerialDevice + [Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice:: + FIELD___callbacksDataReceivedEvent] + .Dereference() != NULL) + { + PostManagedEvent( + EVENT_SERIAL, + 0, + UART_NUM_TO_PORT_INDEX(palUart->UartNum), + (watchCharPos > -1) ? SerialData_WatchChar : SerialData_Chars); + } + } + } + } + } } } - vQueueDelete(Uart_Event_Queue[uart_num]); + vTaskDelete(NULL); } -HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::NativeDispose___VOID( CLR_RT_StackFrame& stack ) +void UartTxWorkerTask(void *pvParameters) { - NANOCLR_HEADER(); + // get PAL UART from task parameters + NF_PAL_UART *palUart = (NF_PAL_UART *)pvParameters; + + // Write data directly to UART FIFO + // by design: don't bother checking the return value + uart_write_bytes(palUart->UartNum, (const char *)palUart->TxRingBuffer.Reader(), palUart->TxOngoingCount); + + // pop elements from ring buffer, just pop + palUart->TxRingBuffer.Pop(palUart->TxOngoingCount); + + // set event flag for COM OUT + Events_Set(SYSTEM_EVENT_FLAG_COM_OUT); + + // delete task + vTaskDelete(NULL); +} + +// estimate the time required to perform the TX transaction +bool IsLongRunningOperation(uint32_t bufferSize, uint32_t baudRate, uint32_t &estimatedDurationMiliseconds) +{ + // simplifying calculation assuming worst case values for stop bits + estimatedDurationMiliseconds = ((8 + 2) * bufferSize * 1000) / baudRate; + + if (estimatedDurationMiliseconds > CLR_RT_Thread::c_TimeQuantum_Milliseconds) + { + // total operation time will exceed thread quantum, so this is a long running operation + return true; + } + else { - // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); - - // Get Uart number for serial device - uart_port_t uart_num = (uart_port_t)PORT_INDEX_TO_UART_NUM(pThis[ FIELD___portIndex ].NumericByRef().s4); - // uninstall the driver and send the exit signal to the UART event handling queue - uart_driver_delete(uart_num); - xQueueSend(Uart_Event_Queue[uart_num], (void*)UART_EVENT_MAX, (portTickType)portMAX_DELAY); - Uart_Post_SerialData_Chars_Event[uart_num] = false; - Serial_Device_Instance[uart_num] = NULL; - Esp_Serial_Initialised_Flag[uart_num] = 0; - } + return false; + } +} + +HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::NativeDispose___VOID( + CLR_RT_StackFrame &stack) +{ + NANOCLR_HEADER(); + + uart_port_t uart_num; + + // get a pointer to the managed object instance and check that it's not NULL + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + + // Get Uart number for serial device + uart_num = (uart_port_t)PORT_INDEX_TO_UART_NUM(pThis[FIELD___portIndex].NumericByRef().s4); + + UnitializePalUart(GetPalUartFromUartNum(uart_num)); + NANOCLR_NOCLEANUP(); } // // Initialise a new Serial port // -HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::NativeInit___VOID( CLR_RT_StackFrame& stack ) +HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::NativeInit___VOID( + CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); + + char task_name[16]; + uart_port_t uart_num; + esp_err_t esp_err; + + NF_PAL_UART *palUart; + + // get a pointer to the managed object instance and check that it's not NULL + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + + // Get Uart number for serial device + uart_num = (uart_port_t)PORT_INDEX_TO_UART_NUM(pThis[FIELD___portIndex].NumericByRef().s4); + if (uart_num > UART_NUM_2 || uart_num < 0) { - // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); + } - // Get Uart number for serial device - uart_port_t uart_num = (uart_port_t)PORT_INDEX_TO_UART_NUM(pThis[ FIELD___portIndex ].NumericByRef().s4); - if ( uart_num > UART_NUM_2 || uart_num < 0 ) - { - NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); - } + // call the configure and abort if not OK + NANOCLR_CHECK_HRESULT(NativeConfig___VOID(stack)); - // call the configure and abort if not OK - HRESULT res = NativeConfig___VOID(stack); - if (res != S_OK) - { - NANOCLR_SET_AND_LEAVE(res); - } + palUart = GetPalUartFromUartNum(uart_num); + if (palUart == NULL) + { + NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); + } - // Install driver - esp_err_t esp_err = uart_driver_install(uart_num, - UART_RX_BUFER_SIZE, // rx_buffer_size, - UART_TX_BUFER_SIZE, // tx_buffer_size, not buffered - 20, // queue_size - &Uart_Event_Queue[uart_num], // QueueHandle_t *uart_queue ( none for now ) - 0 // intr_alloc_flags - ); - if ( esp_err != ESP_OK ) - { - ESP_LOGE( TAG, "Failed to install uart driver"); - NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); - } - - // receive the SerialData_Chars events and store the SerialDevice instance - Uart_Post_SerialData_Chars_Event[uart_num] = true; - Serial_Device_Instance[uart_num] = pThis; - - // Create a task to handle UART event from ISR - char task_name[16]; - sprintf(task_name, "uart%d_events", uart_num); - xTaskCreate(uart_event_task, task_name, 2048, (void*)uart_num, 12, NULL); - - // Ensure driver gets unitialized during soft reboot - HAL_AddSoftRebootHandler(Esp32_Serial_UnitializeAll); - Esp_Serial_Initialised_Flag[uart_num] = 1; - - Uart_writeLength[uart_num] = 0; + // alloc buffers memory + palUart->TxBuffer = (uint8_t *)platform_malloc(UART_BUFER_SIZE); + palUart->RxBuffer = (uint8_t *)platform_malloc(UART_BUFER_SIZE); + + // sanity check + if (palUart->TxBuffer == NULL || palUart->RxBuffer == NULL) + { + NANOCLR_SET_AND_LEAVE(CLR_E_OUT_OF_MEMORY); + } + + // init buffers + palUart->TxRingBuffer.Initialize(palUart->TxBuffer, UART_BUFER_SIZE); + palUart->RxRingBuffer.Initialize(palUart->RxBuffer, UART_BUFER_SIZE); + + // set/reset all the rest + palUart->SerialDevice = stack.This(); + palUart->UartNum = uart_num; + palUart->TxOngoingCount = 0; + palUart->RxBytesToRead = 0; + + // Install driver + esp_err = uart_driver_install( + uart_num, + UART_BUFER_SIZE, // rx_buffer_size, + 0, // tx_buffer_size, not buffered + 20, // queue_size + &(palUart->UartEventQueue), // QueueHandle_t *uart_queue ( none for now ) + 0 // intr_alloc_flags + ); + if (esp_err != ESP_OK) + { + ESP_LOGE(TAG, "Failed to install uart driver"); + NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); + } + + NANOCLR_CHECK_HRESULT(NativeConfig___VOID(stack)); + + // Create a task to handle UART event from ISR + sprintf(task_name, "uart%d_events", uart_num); + if (xTaskCreatePinnedToCore(uart_event_task, task_name, 2048, palUart, 12, &(palUart->UartEventTask), 1) != pdPASS) + { + ESP_LOGE(TAG, "Failed to start UART events task"); + NANOCLR_SET_AND_LEAVE(CLR_E_FAIL); } - NANOCLR_NOCLEANUP(); + + // Ensure driver gets unitialized during soft reboot + HAL_AddSoftRebootHandler(Esp32_Serial_UnitializeAll); + + NANOCLR_NOCLEANUP(); } // // Set up serial port Configuration // -HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::NativeConfig___VOID( CLR_RT_StackFrame& stack ) +HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::NativeConfig___VOID( + CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); { - uart_config_t uart_config; - + uart_config_t uart_config; + // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); // Get Uart number for serial device - uart_port_t uart_num = (uart_port_t)PORT_INDEX_TO_UART_NUM(pThis[ FIELD___portIndex ].NumericByRef().s4); - if ( uart_num > UART_NUM_2 || uart_num < 0) + uart_port_t uart_num = (uart_port_t)PORT_INDEX_TO_UART_NUM(pThis[FIELD___portIndex].NumericByRef().s4); + if (uart_num > UART_NUM_2 || uart_num < 0) { NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); } // setup configuration - // data bits / baud rate - uart_config.baud_rate = (uart_word_length_t)pThis[ FIELD___baudRate ].NumericByRef().s4; //baudrate + // baud rate + uart_config.baud_rate = (uint32_t)pThis[FIELD___baudRate].NumericByRef().s4; - switch( pThis[ FIELD___dataBits ].NumericByRef().s4 ) //data bit mode + // data bits + switch ((uint16_t)pThis[FIELD___dataBits].NumericByRef().s4) { case 5: - uart_config.data_bits = UART_DATA_5_BITS; break; + uart_config.data_bits = UART_DATA_5_BITS; + break; + case 6: - uart_config.data_bits = UART_DATA_6_BITS; break; + uart_config.data_bits = UART_DATA_6_BITS; + break; + case 7: - uart_config.data_bits = UART_DATA_7_BITS; break; + uart_config.data_bits = UART_DATA_7_BITS; + break; + case 8: - uart_config.data_bits = UART_DATA_8_BITS; break; + uart_config.data_bits = UART_DATA_8_BITS; + break; + default: NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); } - - // parity - switch ((SerialParity)pThis[ FIELD___parity ].NumericByRef().s4) + + // parity + switch ((SerialParity)pThis[FIELD___parity].NumericByRef().s4) { default: - case SerialParity_None : - uart_config.parity = UART_PARITY_DISABLE ; + case SerialParity_None: + uart_config.parity = UART_PARITY_DISABLE; break; - case SerialParity_Even : - uart_config.parity = UART_PARITY_EVEN ; + + case SerialParity_Even: + uart_config.parity = UART_PARITY_EVEN; break; - case SerialParity_Odd : - uart_config.parity = UART_PARITY_ODD ; + + case SerialParity_Odd: + uart_config.parity = UART_PARITY_ODD; break; } - - // stop bits - switch ((SerialStopBitCount)pThis[ FIELD___stopBits ].NumericByRef().s4) + + // stop bits + switch ((SerialStopBitCount)pThis[FIELD___stopBits].NumericByRef().s4) { default: - case SerialStopBitCount_One : - uart_config.stop_bits = UART_STOP_BITS_1; + case SerialStopBitCount_One: + uart_config.stop_bits = UART_STOP_BITS_1; break; - case SerialStopBitCount_OnePointFive : + + case SerialStopBitCount_OnePointFive: uart_config.stop_bits = UART_STOP_BITS_1_5; break; - case SerialStopBitCount_Two : + + case SerialStopBitCount_Two: uart_config.stop_bits = UART_STOP_BITS_2; break; } - uart_config.rx_flow_ctrl_thresh = 0; + uart_config.rx_flow_ctrl_thresh = 120; - bool EnableXonXoff = false; - switch ((SerialHandshake)pThis[ FIELD___handshake ].NumericByRef().s4) + bool EnableXonXoff = false; + switch ((SerialHandshake)pThis[FIELD___handshake].NumericByRef().s4) { - default: - case SerialHandshake_None : - uart_config.flow_ctrl = UART_HW_FLOWCTRL_DISABLE; + default: + case SerialHandshake_None: + uart_config.flow_ctrl = UART_HW_FLOWCTRL_DISABLE; + break; + + case SerialHandshake_RequestToSend: + uart_config.flow_ctrl = UART_HW_FLOWCTRL_RTS; + uart_config.rx_flow_ctrl_thresh = 122; break; - case SerialHandshake_RequestToSend : - uart_config.flow_ctrl = UART_HW_FLOWCTRL_RTS ; - uart_config.rx_flow_ctrl_thresh = 122; - break; - - case SerialHandshake_RequestToSendXOnXOff : - uart_config.flow_ctrl = UART_HW_FLOWCTRL_RTS ; - uart_config.rx_flow_ctrl_thresh = 122; - EnableXonXoff = true; + + case SerialHandshake_RequestToSendXOnXOff: + uart_config.flow_ctrl = UART_HW_FLOWCTRL_RTS; + uart_config.rx_flow_ctrl_thresh = 122; + EnableXonXoff = true; break; - case SerialHandshake_XOnXOff : - EnableXonXoff = true; + case SerialHandshake_XOnXOff: + EnableXonXoff = true; + uart_config.flow_ctrl = UART_HW_FLOWCTRL_DISABLE; break; } - uart_param_config(uart_num, &uart_config); + // Already Initialised ? + if (GetPalUartFromUartNum(uart_num)->SerialDevice) + { + int errors = 0; + + errors += uart_set_word_length(uart_num, uart_config.data_bits); + errors += uart_set_baudrate(uart_num, uart_config.baud_rate); + errors += uart_set_parity(uart_num, uart_config.parity); + errors += uart_set_stop_bits(uart_num, uart_config.stop_bits); + errors += uart_set_hw_flow_ctrl(uart_num, uart_config.flow_ctrl, uart_config.rx_flow_ctrl_thresh); + if (errors) + { + ESP_LOGE(TAG, "Failed to set UART parameters configuration"); + NANOCLR_SET_AND_LEAVE(CLR_E_FAIL); + } + } + else + { + // First time make sure UART is reset so use uart_param_config. + // If you call this once driver installed it resets UART and stop events ISR being called. + if (uart_param_config(uart_num, &uart_config) != ESP_OK) + { + ESP_LOGE(TAG, "Failed to set UART parameters configuration"); + NANOCLR_SET_AND_LEAVE(CLR_E_FAIL); + } + } - if ( EnableXonXoff ) + if (EnableXonXoff) + { uart_set_sw_flow_ctrl(uart_num, true, 20, 40); + } - // Map to currently assigned pins - int txPin = Esp32_GetMappedDevicePins(DEV_TYPE_SERIAL, uart_num, 0); - int rxPin = Esp32_GetMappedDevicePins(DEV_TYPE_SERIAL, uart_num, 1); - int rtsPin = Esp32_GetMappedDevicePins(DEV_TYPE_SERIAL, uart_num, 2); - int ctsPin = Esp32_GetMappedDevicePins(DEV_TYPE_SERIAL, uart_num, 3); + // Map to currently assigned pins + int txPin = Esp32_GetMappedDevicePins(DEV_TYPE_SERIAL, uart_num, Esp32SerialPin_Tx); + int rxPin = Esp32_GetMappedDevicePins(DEV_TYPE_SERIAL, uart_num, Esp32SerialPin_Rx); + int rtsPin = Esp32_GetMappedDevicePins(DEV_TYPE_SERIAL, uart_num, Esp32SerialPin_Rts); + int ctsPin = Esp32_GetMappedDevicePins(DEV_TYPE_SERIAL, uart_num, Esp32SerialPin_Cts); - // Don't use RTS/CTS if no hardware handshake enabled - if ( uart_config.flow_ctrl == UART_HW_FLOWCTRL_DISABLE ) - { - rtsPin = UART_PIN_NO_CHANGE; - ctsPin = UART_PIN_NO_CHANGE; - } + // check if TX, RX pins have been previously set + if (txPin == UART_PIN_NO_CHANGE || rxPin == UART_PIN_NO_CHANGE) + { + NANOCLR_SET_AND_LEAVE(CLR_E_PIN_UNAVAILABLE); + } - uart_set_pin(uart_num, txPin, rxPin, rtsPin, ctsPin); + // Don't use RTS/CTS if no hardware handshake enabled + if (uart_config.flow_ctrl == UART_HW_FLOWCTRL_DISABLE) + { + rtsPin = UART_PIN_NO_CHANGE; + ctsPin = UART_PIN_NO_CHANGE; + } + + if (uart_set_pin(uart_num, txPin, rxPin, rtsPin, ctsPin) != ESP_OK) + { + ESP_LOGE(TAG, "Failed to set UART pins"); + NANOCLR_SET_AND_LEAVE(CLR_E_FAIL); + } // null pointers and vars pThis = NULL; @@ -284,23 +525,27 @@ HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_Serial // // Write data into buffer // -HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::NativeWrite___VOID__SZARRAY_U1( CLR_RT_StackFrame& stack ) +HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::NativeWrite___VOID__SZARRAY_U1( + CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); { - uint8_t* data; + NF_PAL_UART *palUart = NULL; + + uint8_t *data; size_t length = 0; // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); - if(pThis[ FIELD___disposed ].NumericByRef().u1 != 0) + if (pThis[FIELD___disposed].NumericByRef().u1 != 0) { NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); } // dereference the data buffer from the argument - CLR_RT_HeapBlock_Array* dataBuffer = stack.Arg1().DereferenceArray(); + CLR_RT_HeapBlock_Array *dataBuffer = stack.Arg1().DereferenceArray(); // get a the pointer to the array by using the first element of the array data = dataBuffer->GetFirstElement(); @@ -309,27 +554,40 @@ HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_Serial length = (size_t)dataBuffer->m_numOfElements; // Get Uart number for serial device - uart_port_t uart_num = (uart_port_t)PORT_INDEX_TO_UART_NUM(pThis[ FIELD___portIndex ].NumericByRef().s4); - + uart_port_t uart_num = (uart_port_t)PORT_INDEX_TO_UART_NUM(pThis[FIELD___portIndex].NumericByRef().s4); - // Write data to ring bufferand start sending - size_t bytesWritten = uart_write_bytes( uart_num, (const char*)data, length); + // get pointer to PAL UART + palUart = GetPalUartFromUartNum(uart_num); + if (palUart == NULL) + { + NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); + } + + // check if there is enough room in the buffer + if (palUart->TxRingBuffer.Capacity() - palUart->TxRingBuffer.Length() < length) + { + // not enough room in the buffer + NANOCLR_SET_AND_LEAVE(CLR_E_BUFFER_TOO_SMALL); + } + + // push data to buffer + size_t bytesWritten = palUart->TxRingBuffer.Push(data, length); // check if all requested bytes were written - if(bytesWritten != length) + if (bytesWritten != length) { // not sure if this is the best exception to throw here... NANOCLR_SET_AND_LEAVE(CLR_E_FAIL); } - - Uart_writeLength[uart_num] += bytesWritten; - // // need to update the _unstoredBufferLength field in the SerialDeviceOutputStream - // // get pointer to outputStream field - // CLR_RT_HeapBlock* outputStream = pThis[Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::FIELD___outputStream].Dereference(); - - // // get pointer to _unstoredBufferLength field and udpate field value - // outputStream[Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDeviceOutputStream::FIELD___unstoredBufferLength].NumericByRef().s4 = palUart->TxRingBuffer.Length(); + // need to update the _unstoredBufferLength field in the SerialDeviceOutputStream + // get pointer to outputStream field + CLR_RT_HeapBlock *outputStream = pThis[FIELD___outputStream].Dereference(); + // get pointer to _unstoredBufferLength field and udpate field value + outputStream[Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDeviceOutputStream:: + FIELD___unstoredBufferLength] + .NumericByRef() + .s4 = palUart->TxRingBuffer.Length(); // null pointers and vars pThis = NULL; @@ -340,208 +598,417 @@ HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_Serial // // Store - Send buffer and wait // -HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::NativeStore___U4( CLR_RT_StackFrame& stack ) +HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::NativeStore___U4( + CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); + + NF_PAL_UART *palUart = NULL; + + uint32_t estimatedDurationMiliseconds; + size_t length = 0; + uart_port_t uart_num; + + int64_t *timeoutTicks; + bool eventResult = true; + bool txOk = false; + + // get a pointer to the managed object instance and check that it's not NULL + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + + if (pThis[FIELD___disposed].NumericByRef().u1 != 0) { + NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); + } - // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + // Get Uart number for serial device + uart_num = (uart_port_t)PORT_INDEX_TO_UART_NUM(pThis[FIELD___portIndex].NumericByRef().s4); + + // get pointer to PAL UART + palUart = GetPalUartFromUartNum(uart_num); + if (palUart == NULL) + { + NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); + } + + if (stack.m_customState == 0) + { + // check if this is a long running operation + palUart->IsLongRunning = IsLongRunningOperation( + palUart->TxRingBuffer.Length(), + (uint32_t)pThis[FIELD___baudRate].NumericByRef().s4, + (uint32_t &)estimatedDurationMiliseconds); + } - if(pThis[ FIELD___disposed ].NumericByRef().u1 != 0) + // check if there is anything the buffer + if (palUart->TxRingBuffer.Length() > 0) + { + // check if there is a TX operation ongoing + if (palUart->TxOngoingCount == 0) { - NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); + // OK to Tx + txOk = true; + } + else + { + // need to wait for the ongoing operation to complete before starting a new one } + } - // Get Uart number for serial device - uart_port_t uart_num = (uart_port_t)PORT_INDEX_TO_UART_NUM(pThis[ FIELD___portIndex ].NumericByRef().s4); + if (txOk) + { + // optimize buffer for sequential reading + palUart->TxRingBuffer.OptimizeSequence(); - // get value for writetimeout - // the way to access this it's somewhat convoluted but it is what it is - // get pointer to the field - CLR_RT_HeapBlock* timeout = &pThis[ Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::FIELD___writeTimeout ]; + // get data length available in the buffer + length = palUart->TxRingBuffer.Length(); - // now get a pointer to the actual value - int64_t* timeoutTicks = Library_corlib_native_System_TimeSpan::GetValuePtr( *timeout ); + if (palUart->IsLongRunning) + { + // setup timeout + NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTimeSpan(pThis[FIELD___writeTimeout], timeoutTicks)); + + // this is a long running operation and hasn't started yet + // perform operation by launching a thread to + if (stack.m_customState == 1) + { + // push to the stack how many bytes bytes where buffered for Tx + stack.PushValueI4(length); + + // set TX count + palUart->TxOngoingCount = length; - // now get the value in ticks and convert it to milliseconds - int64_t timeoutMillisecondsValue = *timeoutTicks / TIME_CONVERSION__TICKUNITS; + // Create a task to handle UART event from ISR + char task_name[16]; + sprintf(task_name, "uart%d_tx", uart_num); - // Wait for max. writetimeout timespan for data to be sent - esp_err_t esp_err = uart_wait_tx_done( uart_num, (TickType_t) timeoutMillisecondsValue / portTICK_PERIOD_MS); - if (esp_err == ESP_ERR_TIMEOUT) + if (xTaskCreate(UartTxWorkerTask, task_name, 2048, palUart, 12, NULL) != pdPASS) + { + ESP_LOGE(TAG, "Failed to start UART TX task"); + NANOCLR_SET_AND_LEAVE(CLR_E_FAIL); + } + + // bump custom state so the read value above is pushed only once + stack.m_customState = 2; + } + } + else { - NANOCLR_SET_AND_LEAVE(CLR_E_TIMEOUT); + // this is NOT a long running operation + // perform TX operation right away + + // Write data to ring buffer to start sending + // by design: don't bother checking the return value + uart_write_bytes(uart_num, (const char *)palUart->TxRingBuffer.Reader(), length); + + // pop data that was written to FIFO + // pop elements from ring buffer, just pop + palUart->TxRingBuffer.Pop(length); } - else if (esp_err != ESP_OK) + } + + while (eventResult) + { + if (!palUart->IsLongRunning) { - NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); + // this is not a long running operation so nothing to do here + break; } - // return how many bytes were send to the UART - stack.SetResult_U4(Uart_writeLength[uart_num]); + // non-blocking wait allowing other threads to run while we wait for the Tx operation to complete + NANOCLR_CHECK_HRESULT( + g_CLR_RT_ExecutionEngine.WaitEvents(stack.m_owningThread, *timeoutTicks, Event_SerialPortOut, eventResult)); - Uart_writeLength[uart_num] = 0; + if (eventResult) + { + // event occurred + // get from the eval stack how many bytes were buffered to Tx + length = stack.m_evalStack[1].NumericByRef().s4; - // null pointers and vars - pThis = NULL; + // reset Tx ongoing count + palUart->TxOngoingCount = 0; + + // done here + break; + } + else + { + NANOCLR_SET_AND_LEAVE(CLR_E_TIMEOUT); + } } + + if (palUart->IsLongRunning) + { + // pop length heap block from stack + stack.PopValue(); + + // pop timeout heap block from stack + stack.PopValue(); + } + + stack.SetResult_U4(length); + + // null pointers and vars + pThis = NULL; + NANOCLR_NOCLEANUP(); } - -HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::NativeRead___U4__SZARRAY_U1__I4__I4( CLR_RT_StackFrame& stack ) +HRESULT IRAM_ATTR + Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::NativeRead___U4__SZARRAY_U1__I4__I4( + CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); - { - uint8_t* data; - size_t dataLength = 0; - size_t count = 0; - int bytesRead = 0; - size_t toRead = 0; + CLR_RT_HeapBlock_Array *dataBuffer; + NF_PAL_UART *palUart = NULL; - InputStreamOptions options = InputStreamOptions_None; + uint8_t *data; + size_t dataLength = 0; - CLR_RT_HeapBlock* timeout; - int64_t* timeoutTicks; - int64_t timeoutMillisecondsValue; + size_t count = 0; + size_t bytesRead = 0; + size_t bytesToRead = 0; - // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + InputStreamOptions options = InputStreamOptions_None; + uart_port_t uart_num; - if(pThis[ FIELD___disposed ].NumericByRef().u1 != 0) - { - NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); - } + int64_t *timeoutTicks; + bool eventResult = true; - // dereference the data buffer from the argument - CLR_RT_HeapBlock_Array* dataBuffer = stack.Arg1().DereferenceArray(); + // get a pointer to the managed object instance and check that it's not NULL + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); - // get a the pointer to the array by using the first element of the array - data = dataBuffer->GetFirstElement(); + if (pThis[FIELD___disposed].NumericByRef().u1 != 0) + { + NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); + } + + // dereference the data buffer from the argument + dataBuffer = stack.Arg1().DereferenceArray(); + + // get a the pointer to the array by using the first element of the array + data = dataBuffer->GetFirstElement(); + + // get the length of the data buffer + dataLength = dataBuffer->m_numOfElements; - // get the length of the data buffer - dataLength = dataBuffer->m_numOfElements; + // get how many bytes are requested to read + count = stack.Arg2().NumericByRef().s4; - // get how many bytes are requested to read - count = stack.Arg2().NumericByRef().s4; + // get the InputStreamOptions option + options = (InputStreamOptions)stack.Arg3().NumericByRef().s4; + + // Get Uart number for serial device + uart_num = (uart_port_t)PORT_INDEX_TO_UART_NUM(pThis[FIELD___portIndex].NumericByRef().s4); + + // get pointer to PAL UART + palUart = GetPalUartFromUartNum(uart_num); + if (palUart == NULL) + { + NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); + } - // get the InputStreamOptions option - options = (InputStreamOptions)stack.Arg3().NumericByRef().s4; + // setup timeout from the _readtimeout heap block + NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTimeSpan(pThis[FIELD___readTimeout], timeoutTicks)); - // Get Uart number for serial device - uart_port_t uart_num = (uart_port_t)PORT_INDEX_TO_UART_NUM(pThis[ FIELD___portIndex ].NumericByRef().s4); + // figure out what's available in the Rx ring buffer + if (palUart->RxRingBuffer.Length() >= count) + { + // read from Rx ring buffer + bytesToRead = count; - // Bytes requested to read - toRead = count; - // is the read ahead option enabled? - if(options == InputStreamOptions_ReadAhead) + if (options == InputStreamOptions_ReadAhead) { // yes // check how many bytes we can store in the buffer argument - size_t bufferedLength = 0; - uart_get_buffered_data_len(uart_num, &bufferedLength); - - if(dataLength < bufferedLength ) + if (dataLength < palUart->RxRingBuffer.Length()) { // read as many bytes has the buffer can hold - toRead = dataLength; + bytesToRead = dataLength; } else { // read everything that's available in the ring buffer - toRead = bufferedLength; + bytesToRead = palUart->RxRingBuffer.Length(); } } - // get value for readtimeout - // the way to access this it's somewhat convoluted but it is what it is - // get pointer to the field - timeout = &pThis[ Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::FIELD___readTimeout ]; + // we have enough bytes, skip wait for event + eventResult = false; + + // clear event by getting it + Events_Get(SYSTEM_EVENT_FLAG_COM_IN); + } + else + { + if (stack.m_customState == 1) + { + // not enough bytes available, have to read from UART + palUart->RxBytesToRead = count; - // now get a pointer to the actual value - timeoutTicks = Library_corlib_native_System_TimeSpan::GetValuePtr( *timeout ); + // clear event by getting it + Events_Get(SYSTEM_EVENT_FLAG_COM_IN); - // now get the value in ticks and convert it to miliseconds - timeoutMillisecondsValue = *timeoutTicks / TIME_CONVERSION__TICKUNITS; + // don't read anything from the buffer yet + bytesToRead = 0; + } + } - // suppress the SerialData_Chars event during the reading of the chars; prevents spamming with the SerialData_Chars event - Uart_Post_SerialData_Chars_Event[uart_num] = false; - bytesRead = uart_read_bytes(uart_num, data, toRead, timeoutMillisecondsValue / portTICK_RATE_MS); - Uart_Post_SerialData_Chars_Event[uart_num] = true; - - if ( bytesRead < 0 ) + while (eventResult) + { + if (stack.m_customState == 1) { - NANOCLR_SET_AND_LEAVE(CLR_E_FAIL); + if (bytesToRead > 0) + { + // enough bytes available + eventResult = false; + } + else + { + // need to read from the UART + // update custom state + stack.m_customState = 2; + } + } + else + { + // wait for event + NANOCLR_CHECK_HRESULT( + g_CLR_RT_ExecutionEngine + .WaitEvents(stack.m_owningThread, *timeoutTicks, Event_SerialPortIn, eventResult)); + + if (!eventResult) + { + // event timeout + + // compute how many bytes to read + // considering the InputStreamOptions read ahead option + if (options == InputStreamOptions_ReadAhead) + { + // yes + // check how many bytes we can store in the buffer argument + if (dataLength < palUart->RxRingBuffer.Length()) + { + // read as many bytes has the buffer can hold + bytesToRead = dataLength; + } + else + { + // read everything that's available in the ring buffer + bytesToRead = palUart->RxRingBuffer.Length(); + } + } + else + { + // take InputStreamOptions_Partial as default and read requested quantity or what's available + bytesToRead = count; + + if (count > palUart->RxRingBuffer.Length()) + { + // need to adjust because there aren't enough bytes available + bytesToRead = palUart->RxRingBuffer.Length(); + } + } + } } - - // return how many bytes were read from the Rx buffer and/or UART - stack.SetResult_U4(bytesRead); } + + if (bytesToRead > 0) + { + // pop the requested bytes from the ring buffer + bytesRead = palUart->RxRingBuffer.Pop(data, bytesToRead); + } + + // pop timeout heap block from stack + stack.PopValue(); + + // return how many bytes were read + stack.SetResult_U4(bytesRead); + NANOCLR_NOCLEANUP(); } -HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::NativeSetWatchChar___VOID( CLR_RT_StackFrame& stack ) +HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::NativeSetWatchChar___VOID( + CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); - { - // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); - if(pThis[ FIELD___disposed ].NumericByRef().u1 != 0) - { - NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); - } - - // Get Uart number for serial device - uart_port_t uart_num = (uart_port_t)PORT_INDEX_TO_UART_NUM(pThis[ FIELD___portIndex ].NumericByRef().s4); - - // Get the watch char - uint8_t watchChar = (uint8_t)pThis[ FIELD___watchChar ].NumericByRef().u1; - - // Enable pattern detection for the serial device - uart_enable_pattern_det_intr(uart_num, watchChar, 1, 10000, 10, 10); - } + uart_port_t uart_num; + uint8_t watchChar; + + // get a pointer to the managed object instance and check that it's not NULL + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + + if (pThis[FIELD___disposed].NumericByRef().u1 != 0) + { + NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); + } + + // Get Uart number for serial device + uart_num = (uart_port_t)PORT_INDEX_TO_UART_NUM(pThis[FIELD___portIndex].NumericByRef().s4); + + // Get the watch char + watchChar = (uint8_t)pThis[FIELD___watchChar].NumericByRef().u1; + + // Enable pattern detection for the serial device + uart_enable_pattern_det_intr(uart_num, watchChar, 1, 10000, 10, 10); + // Reset the pattern queue length to record at most 10 pattern positions. + uart_pattern_queue_reset(uart_num, 10); + NANOCLR_NOCLEANUP(); } -HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::get_BytesToRead___U4( CLR_RT_StackFrame& stack ) +HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::get_BytesToRead___U4( + CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); - { - // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); - if(pThis[ FIELD___disposed ].NumericByRef().u1 != 0) - { - NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); - } - - // Get Uart number for serial device - uart_port_t uart_num = (uart_port_t)PORT_INDEX_TO_UART_NUM(pThis[ FIELD___portIndex ].NumericByRef().s4); - - // check how many bytes are in the buffer - size_t bufferedLength = 0; - uart_get_buffered_data_len(uart_num, &bufferedLength); - - // return how many bytes can be read from the Rx buffer - stack.SetResult_U4(bufferedLength); - } - NANOCLR_NOCLEANUP(); + NF_PAL_UART *palUart = NULL; + uart_port_t uart_num; + + // get a pointer to the managed object instance and check that it's not NULL + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + + if (pThis[FIELD___disposed].NumericByRef().u1 != 0) + { + NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); + } + + // Get Uart number for serial device + uart_num = (uart_port_t)PORT_INDEX_TO_UART_NUM(pThis[FIELD___portIndex].NumericByRef().s4); + + // get pointer to PAL UART + palUart = GetPalUartFromUartNum(uart_num); + if (palUart == NULL) + { + NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); + } + + // return how many bytes can be read from the Rx buffer + stack.SetResult_U4(palUart->RxRingBuffer.Length()); + + NANOCLR_NOCLEANUP(); } -HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::GetDeviceSelector___STATIC__STRING( CLR_RT_StackFrame& stack ) +HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice:: + GetDeviceSelector___STATIC__STRING(CLR_RT_StackFrame &stack) { - NANOCLR_HEADER(); - { - // declare the device selector string whose max size is "COM1,COM2,COM3" + terminator - char deviceSelectorString[ 15 ] = "COM1,COM2,COM3"; - - // because the caller is expecting a result to be returned - // we need set a return result in the stack argument using the appropriate SetResult according to the variable type (a string here) - stack.SetResult_String(deviceSelectorString); - } - NANOCLR_NOCLEANUP_NOLABEL(); -} \ No newline at end of file + NANOCLR_HEADER(); + { + // declare the device selector string whose max size is "COM1,COM2,COM3" + terminator + // COM1 is being used for VS debug, so it's not available + char deviceSelectorString[15] = "COM2,COM3"; + + // because the caller is expecting a result to be returned + // we need set a return result in the stack argument using the appropriate SetResult according to the variable + // type (a string here) + stack.SetResult_String(deviceSelectorString); + } + NANOCLR_NOCLEANUP_NOLABEL(); +} diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.SerialCommunication/win_dev_serial_native_target.h b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.SerialCommunication/win_dev_serial_native_target.h index 18bad9df7e..4a01788c18 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.SerialCommunication/win_dev_serial_native_target.h +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.SerialCommunication/win_dev_serial_native_target.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // @@ -8,4 +8,24 @@ #include -#endif //_WIN_DEV_SERIAL_NATIVE_TARGET_H_ +// struct representing the UART +typedef struct +{ + uart_port_t UartNum; + TaskHandle_t UartEventTask; + QueueHandle_t UartEventQueue; + + CLR_RT_HeapBlock *SerialDevice; + + HAL_RingBuffer TxRingBuffer; + uint8_t *TxBuffer; + uint16_t TxOngoingCount; + + HAL_RingBuffer RxRingBuffer; + uint8_t *RxBuffer; + uint16_t RxBytesToRead; + + bool IsLongRunning; +} NF_PAL_UART; + +#endif //_WIN_DEV_SERIAL_NATIVE_TARGET_H_ diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Spi/cpu_spi.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Spi/cpu_spi.cpp new file mode 100644 index 0000000000..39dbd44358 --- /dev/null +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Spi/cpu_spi.cpp @@ -0,0 +1,518 @@ +// +// Copyright (c) .NET Foundation and Contributors +// Portions Copyright (c) Microsoft Corporation. All rights reserved. +// See LICENSE file in the project root for full license information. +// +// +// CPU_SPI_xxxx +// +// Read / Write physical SPI bus +// + +// Esp32 has 4 SPI devices called SPI0, SPI1, HSPI and VSPI +// SPIO, SPI1 are dedicated entirely to flash +// +// HSPI("SPI1") and VSPI("SPI2") are free to use +// +// For maximum speed access the IOMUX must be used ( 80mhz ) +// if pins are through the GPIO matrix the speed is limited to 26.6mhz ( 40mhz half duplex and no dma ) +// +// SPI IOMUX ( direct pins ) +// GPIO Function +// 2 HSPIWP (WP) +// 4 HSPIHD (HD) +// 12 HSPIQ (miso) * +// 13 HSPID (mosi) * +// 14 HSPICLK (clockPin) * +// 15 HSPICS0 (cs) +// +// 5 VSPICS0 (cs) +// 18 VSPICLK (clockPin) * +// 19 VSPIQ (miso) * +// 21 VSPIHD (HD) +// 22 VSPIWP (WP) +// 23 VSPID (mosi) * +// +// The defaults pins for SPI1 are the Wrover SPI display pins +// mosiPin = GPIO_NUM_23, misoPin = GPIO_NUM_25, clockPin = GPIO_NUM_19 +// +// SPI2 - The pins are not assigned so need to be assigned. + +#include +#include +#include +#include + +#include +#include "Esp32_DeviceMapping.h" + +// Max frequency over GPIO mux pins, full duplex +#define MAX_CLOCK_FREQUENCY_GPIO_FULL 26000000 +// Max frequency over GPIO mux pins, half duplex +#define MAX_CLOCK_FREQUENCY_GPIO_HALF 40000000 +// Max over native spi pins +#define MAX_CLOCK_FREQUENCY_NATIVE 80000000 + +// Tag for ESP32 logging +static const char *TAG = "SpiDevice"; + +// struct representing the SPI transaction per bus +struct NF_PAL_SPI +{ + spi_transaction_t trans; + + int BusIndex; + SPI_OP_STATUS status; // Current status + SPI_Callback callback; + + int32_t writeSize; + int32_t readSize; + int32_t readOffset; + + bool fullDuplex; + unsigned char *originalReadData; + unsigned char *readDataBuffer; + unsigned char *writeDataBuffer; +}; + +NF_PAL_SPI nf_pal_spi[2]; + +// Remove device from bus +// return true of OK, false = error +bool CPU_SPI_Remove_Device(uint32_t deviceHandle) +{ + return spi_bus_remove_device((spi_device_handle_t)deviceHandle) != ESP_OK; +} + +// Initialise the physical SPI bus +// Bus index 0 or 1 +// return true of successful, false if error +bool CPU_SPI_Initialize(uint8_t spiBus) +{ + GPIO_PIN clockPin, misoPin, mosiPin; + + // Get pins used by spi bus + CPU_SPI_GetPins(spiBus, clockPin, misoPin, mosiPin); + + // Check pins have been configured + if (clockPin == GPIO_PIN_NONE || misoPin == GPIO_PIN_NONE || mosiPin == GPIO_PIN_NONE) + { + ESP_LOGE(TAG, "Spi pins for SPI%d not configured", spiBus); + return false; + } + + spi_bus_config_t bus_config{ + mosi_io_num : (int)mosiPin, // mosi pin + miso_io_num : (int)misoPin, // miso pin + sclk_io_num : (int)clockPin, // Clock + quadwp_io_num : -1, // Quad Write protect + quadhd_io_num : -1, // Quad Hold + max_transfer_sz : 0, // Default max transfer size ( 4096 ) + flags : 0, // SPICOMMON_BUSFLAG_* flags + intr_flags : 0 // Interrupt flags + }; + + // First available bus on ESP32 is HSPI_HOST(1) + // Try with DMA first + esp_err_t ret = spi_bus_initialize((spi_host_device_t)(spiBus + HSPI_HOST), &bus_config, spiBus + HSPI_HOST); + if (ret != ESP_OK) + { + // Try again without DMA + esp_err_t ret = spi_bus_initialize((spi_host_device_t)(spiBus + HSPI_HOST), &bus_config, 0); + if (ret != ESP_OK) + { + ESP_LOGE(TAG, "Unable to init SPI bus %d esp_err %d", spiBus + HSPI_HOST, ret); + return false; + } + } + + nf_pal_spi[spiBus].BusIndex = spiBus; + nf_pal_spi[spiBus].status = SPI_OP_STATUS::SPI_OP_READY; + + return true; +} + +// Uninitialise the bus +bool CPU_SPI_Uninitialize(uint8_t spiBus) +{ + esp_err_t ret = spi_bus_free((spi_host_device_t)(spiBus + HSPI_HOST)); + if (ret != ESP_OK) + { + ESP_LOGE(TAG, "spi_bus_free bus %d esp_err %d", spiBus + HSPI_HOST, ret); + return false; + } + + return true; +} + +// Callback when a transaction has completed +static void IRAM_ATTR spi_trans_ready(spi_transaction_t *trans) +{ + NF_PAL_SPI *pnf_pal_spi = (NF_PAL_SPI *)trans->user; + + if (pnf_pal_spi != &nf_pal_spi[0] && pnf_pal_spi != &nf_pal_spi[1]) + return; + + pnf_pal_spi->status = SPI_OP_STATUS::SPI_OP_COMPLETE; + + // Finish up half duplex, copy read data and deallocate buffer + if (!pnf_pal_spi->fullDuplex) + { + if (pnf_pal_spi->readSize) + { + // Copy the read data from allocated buffer + memcpy( + pnf_pal_spi->originalReadData, + pnf_pal_spi->readDataBuffer + pnf_pal_spi->writeSize + pnf_pal_spi->readOffset, + pnf_pal_spi->readSize); + + // free up buffers use to spoof half duplex transaction while running full duplex + heap_caps_free(pnf_pal_spi->writeDataBuffer); + heap_caps_free(pnf_pal_spi->readDataBuffer); + } + } + + // fire callback for SPI transaction complete + // only if callback set + SPI_Callback callback = (SPI_Callback)pnf_pal_spi->callback; + if (callback) + callback(pnf_pal_spi->BusIndex); +} + +// +// Convert from SPI_DEVICE_CONFIGURATION to spi_device_interface_config_t used for ESP33 +spi_device_interface_config_t GetConfig(const SPI_DEVICE_CONFIGURATION &spiDeviceConfig) +{ + int csPin = spiDeviceConfig.DeviceChipSelect; + uint8_t spiMode = spiDeviceConfig.Spi_Mode; + int clockHz = spiDeviceConfig.Clock_RateHz; + + // if clock frequency is unset use the maximum frequency + if (clockHz == 0) + { + clockHz = CPU_SPI_MaxClockFrequency(spiDeviceConfig.Spi_Bus); + } + + uint32_t flags = + (spiDeviceConfig.DataOrder16 == DataBitOrder_LSB) ? (SPI_DEVICE_TXBIT_LSBFIRST | SPI_DEVICE_RXBIT_LSBFIRST) : 0; + + // Positive Chip Select for Active + if (spiDeviceConfig.ChipSelectActive) + flags |= SPI_DEVICE_POSITIVE_CS; + + // Fill in device config + spi_device_interface_config_t dev_config{ + 0, // Command bits + 0, // Address bits + 0, // Dummy bits + spiMode, // SPi Mode + 0, // Duty cycle 50/50 + 0, // cs_ena_pretrans + 0, // cs_ena_posttrans + clockHz, // Clock speed in Hz + 0, // Input_delay_ns + csPin, // Chip select + flags, // SPI_DEVICE flags + 1, // Queue size + 0, // Callback before + spi_trans_ready, // Callback after transaction complete + }; + + return dev_config; +} + +// +// Add a device to a SPI bus +// returns device handle as uint32_t +// +uint32_t CPU_SPI_Add_Device(const SPI_DEVICE_CONFIGURATION &spiDeviceConfig) +{ + // First available bus on ESP32 is HSPI_HOST(1), so add one + spi_device_interface_config_t dev_config = GetConfig(spiDeviceConfig); + + // Add device to bus + spi_device_handle_t deviceHandle; + + // Bus index + int spiBusIndex = (spiDeviceConfig.Spi_Bus - 1); + + // First available bus on ESP32 is HSPI_HOST(1) + esp_err_t ret = spi_bus_add_device((spi_host_device_t)(spiBusIndex + HSPI_HOST), &dev_config, &deviceHandle); + if (ret != ESP_OK) + { + ESP_LOGE(TAG, "Unable to init SPI device, esp_err %d", ret); + return 0; + } + + return (uint32_t)deviceHandle; +} + +// Performs a read/write operation on 8-bit word data. +// +// Parameters +// deviceHandle +// Device handle from add_device +// sdev +// reference to SPI_DEVICE_CONFIGURATION +// wrc +// reference to SPI_WRITE_READ_SETTINGS +// writeData +// A pointer to the buffer from which the data is to be written to the device. +// writeSize +// The number of elements(8 or 16) to be written. +// readData +// A pointer to the buffer into which the data is to be read from the device. +// readSize +// The number of elements(8 or 16) to be read. +// +// return S_OK=Successful, Async started=CLR_BUSY, Error=CLR_E_OUT_OF_MEMORY, CLR_E_INVALID_PARAMETER, CLR_E_FAIL +// +HRESULT CPU_SPI_nWrite_nRead( + uint32_t deviceHandle, + SPI_DEVICE_CONFIGURATION &sdev, + SPI_WRITE_READ_SETTINGS &wrc, + uint8_t *writeData, + int32_t writeSize, + uint8_t *readData, + int32_t readSize) +{ + (void)sdev; + + NANOCLR_HEADER(); + { + unsigned char *writeDataBuffer = NULL; + unsigned char *readDataBuffer = NULL; + bool async = (wrc.callback != 0); + esp_err_t ret; + + // get data bit length + int databitLength = wrc.Bits16ReadWrite ? 16 : 8; + + // // Are we using SPI full-duplex for transfer ? + // // The SPI doesn't support half duplex operation with DMA and without DMA the receive length is limited to 4 + // bytes + // // So we run in full duplex mode all the time and simulate half duplex mode by creating a larger receive + // buffer for + // // the whole of the transaction and then copying the rx part to original buffer + // // For full duplex we just use passed buffers. + int MaxElementlength; + if (wrc.fullDuplex) + { + // for full duplex just use largest element + // TODO : There may be a problem with read data overwriting passed read buff if write size > read size + // !!!!!! + // May for this case we should always allocate a separate buffer for transfer + MaxElementlength = (readSize > writeSize) ? readSize : writeSize; + + readDataBuffer = readData; + } + else + { + // for Half-duplex its the length of both items + MaxElementlength = writeSize + readSize; + if (readSize) + MaxElementlength += wrc.readOffset; + + int maxByteDatalength = (wrc.Bits16ReadWrite) ? MaxElementlength * 2 : MaxElementlength; + + if (readSize) // Any read data then use alternative buffer with write & read data + { + // Allocate a new write and read buffers to spoof half duplex operation using full duplex so we can use + // DMA. length included write data, any dummy bytes(readOffset) and read data size + writeDataBuffer = (unsigned char *)heap_caps_malloc(maxByteDatalength, MALLOC_CAP_DMA); + if (writeDataBuffer == 0) + NANOCLR_SET_AND_LEAVE(CLR_E_OUT_OF_MEMORY); + + readDataBuffer = (unsigned char *)heap_caps_malloc(maxByteDatalength, MALLOC_CAP_DMA); + if (readDataBuffer == 0) + NANOCLR_SET_AND_LEAVE(CLR_E_OUT_OF_MEMORY); + + memset(writeDataBuffer, 0, maxByteDatalength); + memcpy(writeDataBuffer, writeData, writeSize); + writeData = writeDataBuffer; + } + } + + NF_PAL_SPI *pnf_pal_spi = &nf_pal_spi[sdev.Spi_Bus]; + + pnf_pal_spi->writeSize = writeSize; + pnf_pal_spi->readSize = readSize; + pnf_pal_spi->originalReadData = readData; + pnf_pal_spi->readDataBuffer = readDataBuffer; + pnf_pal_spi->writeDataBuffer = writeDataBuffer; + pnf_pal_spi->fullDuplex = wrc.fullDuplex; + pnf_pal_spi->readOffset = wrc.readOffset; // dummy bytes between write & read on half duplex + pnf_pal_spi->callback = wrc.callback; + + // Set up SPI Transaction + spi_transaction_t *pTrans = &pnf_pal_spi->trans; + + pTrans->flags = 0; + pTrans->cmd = 0; + pTrans->addr = 0; + // length - Full duplex is total length, half duplex the TX length + pTrans->length = databitLength * MaxElementlength; + // rxlength - Full duplex is same as length or 0, half duplex is read length + pTrans->rxlength = 0; + pTrans->user = (void *)pnf_pal_spi; + pTrans->tx_buffer = writeData; + pTrans->rx_buffer = readDataBuffer; + + // Start asynchronous SPI transaction + if (async) + { + pnf_pal_spi->callback = wrc.callback; + + ret = spi_device_queue_trans((spi_device_handle_t)deviceHandle, pTrans, portMAX_DELAY); + if (ret != ESP_OK) + { + // Error so free up buffer if Half duplex + if (!wrc.fullDuplex && readSize != 0) + { + // Clean up + heap_caps_free(writeDataBuffer); + heap_caps_free(readDataBuffer); + } + + switch (ret) + { + case ESP_ERR_NO_MEM: + NANOCLR_SET_AND_LEAVE(CLR_E_OUT_OF_MEMORY); + + case ESP_ERR_INVALID_ARG: + NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); + + default: + case ESP_ERR_INVALID_STATE: + NANOCLR_SET_AND_LEAVE(CLR_E_FAIL); + } + } + + pnf_pal_spi->status = SPI_OP_STATUS::SPI_OP_RUNNING; + + // Return Busy to indicate ASync call started and callback will be called on completion + NANOCLR_SET_AND_LEAVE(CLR_E_BUSY); + } + else + { + // Synchronous SPI operation + // Use Polling method to start and wait to complete(quickest) + ret = spi_device_polling_transmit((spi_device_handle_t)deviceHandle, pTrans); + + pnf_pal_spi->status = SPI_OP_STATUS::SPI_OP_COMPLETE; + + if (ret != ESP_OK) + { + if (!wrc.fullDuplex && readSize != 0) + { + heap_caps_free(writeDataBuffer); + heap_caps_free(readDataBuffer); + } + NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); + } + + // Finish up half duplex, done in callback + // frees buffer and copies read data + } + } + + NANOCLR_NOCLEANUP(); +} + +// Performs a read/write operation on 16-bit word data. +HRESULT CPU_SPI_nWrite16_nRead16( + uint32_t deviceHandle, + SPI_DEVICE_CONFIGURATION &sdev, + SPI_WRITE_READ_SETTINGS &swrs, + uint16_t *writePtr, + int32_t writeSize, + uint16_t *readPtr, + int32_t readSize) +{ + swrs.Bits16ReadWrite = true; + return CPU_SPI_nWrite_nRead(deviceHandle, sdev, swrs, (uint8_t *)writePtr, writeSize, (uint8_t *)readPtr, readSize); +} + +// Return status of current SPI operation +// Used to find status of an Async SPI call +SPI_OP_STATUS CPU_SPI_OP_Status(uint8_t spi_bus, uint32_t deviceHandle) +{ + (void)deviceHandle; + + NF_PAL_SPI *pnf_pal_spi = &nf_pal_spi[spi_bus]; + + return pnf_pal_spi->status; +} + +// Return map of available SPI buses as a bit map +uint32_t CPU_SPI_PortsMap() +{ + // SPI1(0x01) & SPI2(0x02) + return 0x03; +} + +// Returns the SPI clock, MISO and MOSI pin numbers for a specified SPI module. +void CPU_SPI_GetPins(uint32_t spi_bus, GPIO_PIN &clockPin, GPIO_PIN &misoPin, GPIO_PIN &mosiPin) +{ + clockPin = (GPIO_PIN)Esp32_GetMappedDevicePins(DEV_TYPE_SPI, spi_bus, 2); + misoPin = (GPIO_PIN)Esp32_GetMappedDevicePins(DEV_TYPE_SPI, spi_bus, 1); + mosiPin = (GPIO_PIN)Esp32_GetMappedDevicePins(DEV_TYPE_SPI, spi_bus, 0); +} + +// Return SPI minimum clock frequency +uint32_t CPU_SPI_MinClockFrequency(uint32_t spi_bus) +{ + (void)spi_bus; + + // TODO check what is minimum ( Min clock that can be configured on chip) + return 20000000 / 256; +} + +// Return SPI maximum clock frequency +// +// Maximum frequency will depend on current configuration +// If using native SPI pins then maximum is 80mhz +// if SPI pins are routed over GPIO matrix then 40mhz half duplex 26mhz full + +uint32_t CPU_SPI_MaxClockFrequency(uint32_t spi_bus) +{ + bool directPin = false; + + GPIO_PIN clockPin, misoPin, mosiPin; + + CPU_SPI_GetPins(spi_bus, clockPin, misoPin, mosiPin); + + // Check if direct pins being used + switch (clockPin) + { + case 14: + if (misoPin == 12 && mosiPin == 13) + directPin = true; + break; + + case 18: + if (misoPin == 19 && mosiPin == 23) + directPin = true; + break; + + default: + break; + } + + if (directPin) + return MAX_CLOCK_FREQUENCY_NATIVE; + + return MAX_CLOCK_FREQUENCY_GPIO_HALF; +} + +// +// Return the number of chip select lines available on the bus. +// +// ESP32 IDF/hardware allows only 3 devices per bus +// TODO Subtract used chip select count ? +uint32_t CPU_SPI_ChipSelectLineCount(uint32_t spi_bus) +{ + (void)spi_bus; + + return 3; +} diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Spi/win_dev_spi_native_Windows_Devices_Spi_SpiBusInfo.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Spi/win_dev_spi_native_Windows_Devices_Spi_SpiBusInfo.cpp deleted file mode 100644 index f6ee56c606..0000000000 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Spi/win_dev_spi_native_Windows_Devices_Spi_SpiBusInfo.cpp +++ /dev/null @@ -1,26 +0,0 @@ -// -// Copyright (c) 2017 The nanoFramework project contributors -// See LICENSE file in the project root for full license information. -// - - -#include "win_dev_spi_native_target.h" - - -HRESULT Library_win_dev_spi_native_Windows_Devices_Spi_SpiBusInfo::get_MaxClockFrequency___I4( CLR_RT_StackFrame& stack ) -{ - NANOCLR_HEADER(); - { - stack.SetResult_I4 ( MAX_CLOCK_FREQUENCY ); - } - NANOCLR_NOCLEANUP_NOLABEL(); -} - -HRESULT Library_win_dev_spi_native_Windows_Devices_Spi_SpiBusInfo::get_MinClockFrequency___I4( CLR_RT_StackFrame& stack ) -{ - NANOCLR_HEADER(); - { - stack.SetResult_I4 ( 1000000 ); - } - NANOCLR_NOCLEANUP_NOLABEL(); -} diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Spi/win_dev_spi_native_Windows_Devices_Spi_SpiController.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Spi/win_dev_spi_native_Windows_Devices_Spi_SpiController.cpp deleted file mode 100644 index f3ed2f0454..0000000000 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Spi/win_dev_spi_native_Windows_Devices_Spi_SpiController.cpp +++ /dev/null @@ -1,20 +0,0 @@ -// -// Copyright (c) 2017 The nanoFramework project contributors -// See LICENSE file in the project root for full license information. -// - -#include "win_dev_spi_native_target.h" - -HRESULT Library_win_dev_spi_native_Windows_Devices_Spi_SpiController::GetDeviceSelector___STATIC__STRING( CLR_RT_StackFrame& stack ) -{ - NANOCLR_HEADER(); - { - // declare the device selector string whose max size is "SPI1,SPI2" + terminator and init with the terminator - char deviceSelectorString[ 15 ] = { "SPI1,SPI2" }; // HSPI & VSPI - - // because the caller is expecting a result to be returned - // we need set a return result in the stack argument using the appropriate SetResult according to the variable type (a string here) - stack.SetResult_String(deviceSelectorString); - } - NANOCLR_NOCLEANUP_NOLABEL(); -} diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Spi/win_dev_spi_native_Windows_Devices_Spi_SpiDevice.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Spi/win_dev_spi_native_Windows_Devices_Spi_SpiDevice.cpp deleted file mode 100644 index cc64b47481..0000000000 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Spi/win_dev_spi_native_Windows_Devices_Spi_SpiDevice.cpp +++ /dev/null @@ -1,438 +0,0 @@ -// -// Copyright (c) 2017 The nanoFramework project contributors -// See LICENSE file in the project root for full license information. -// - -// Esp32 has 4 SPI devices called SPI0, SPI1, HSPI and VSPI -// SPIO, SPI1 are dedicated entirely to flash -// -// HSPI("SPI1") and VSPI("SPI2") are free to use -// -// For maximum speed access the IOMUX must be used ( 80mhz ) -// if pins are through the GPIO matrix the speed is limited to 26.6mhz ( 40mhz half duplex and no dma ) -// -// SPI IOMUX ( direct pins ) -// GPIO Function -// 2 HSPIWP (WP) -// 4 HSPIHD (HD) -// 12 HSPIQ (miso) * -// 13 HSPID (mosi) * -// 14 HSPICLK (clockPin) * -// 15 HSPICS0 (cs) -// -// 5 VSPICS0 (cs) -// 18 VSPICLK (clockPin) * -// 19 VSPIQ (miso) * -// 21 VSPIHD (HD) -// 22 VSPIWP (WP) -// 23 VSPID (mosi) * -// -// The defaults pins for SPI1 are the Wrover SPI display pins -// mosiPin = GPIO_NUM_23, misoPin = GPIO_NUM_25, clockPin = GPIO_NUM_19 -// -// SPI2 - The pins are not assigned so need to be assigned. - -#include -#include -#include -#include -#include "win_dev_spi_native_target.h" -#include "Esp32_DeviceMapping.h" - -static nfSpiBusConfig spiconfig[NUM_SPI_BUSES]; -static bool nfSpiInited = false; - - -// define this type here to make it shorter and improve code readability -typedef Library_win_dev_spi_native_Windows_Devices_Spi_SpiConnectionSettings SpiConnectionSettings; - -// Tag for ESP32 logging -static const char* TAG = "SpiDevice"; - - -// Define this to allow access to device config in spi master driver -struct spi_device_t { - QueueHandle_t trans_queue; - QueueHandle_t ret_queue; - spi_device_interface_config_t cfg; -}; - - -void Remove_Spi_Device(int bus, int deviceIndex) -{ - // Remove device from bus - spi_bus_remove_device( spiconfig[bus].deviceHandles[deviceIndex] ); - spiconfig[bus].deviceHandles[deviceIndex] = 0; - spiconfig[bus].deviceId[deviceIndex] = 0; -} - -int FindFreeDeviceSlotSpi(int bus) -{ - for (int deviceIndex = 0; deviceIndex < MAX_SPI_DEVICES; deviceIndex++) - { - if (spiconfig[bus].deviceHandles[deviceIndex] == 0) return deviceIndex; - } - return -1; -} - -// Unitialise SPI on restart -void Esp32_Spi_UnitializeAll() -{ - for (int bus = 0; bus < NUM_SPI_BUSES; bus++) - { - if (spiconfig[bus].spiBusInited) - { - // Remove any devices - for( int deviceIndex=0; deviceIndex < MAX_SPI_DEVICES; deviceIndex++) - { - if ( spiconfig[bus].deviceHandles[deviceIndex] != 0 ) - Remove_Spi_Device(bus, deviceIndex); - } - - // Delete bus driver - spi_bus_free((spi_host_device_t)bus); - spiconfig[bus].spiBusInited = false; - } - } -} - -// Inialise the SPI Bus -static void InitSpiBus( spi_host_device_t bus) -{ - int busIndex = bus - 1; - - gpio_num_t mosiPin = (gpio_num_t)Esp32_GetMappedDevicePins( DEV_TYPE_SPI, busIndex, 0); - gpio_num_t misoPin = (gpio_num_t)Esp32_GetMappedDevicePins( DEV_TYPE_SPI, busIndex, 1); - gpio_num_t clockPin = (gpio_num_t)Esp32_GetMappedDevicePins( DEV_TYPE_SPI, busIndex, 2); - - spi_bus_config_t bus_config - { - mosi_io_num: mosiPin, // mosi pin - miso_io_num : misoPin, // miso pin - sclk_io_num : clockPin, // Clock - quadwp_io_num : -1, // Quad Write protect - quadhd_io_num : -1, // Quad Hold - max_transfer_sz : 0, // Default max transfer size ( 4096 ) - flags : 0, // SPICOMMON_BUSFLAG_* flags - intr_flags : 0 // Interrupt flags - }; - - // Init with different DMA channel depending on SPI bus - esp_err_t ret = spi_bus_initialize(bus, &bus_config, bus== HSPI_HOST?1:2 ); - if ( ret != ESP_OK ) - { - ESP_LOGE( TAG, "Unable to init SPI bus"); - return; - } -} - -// Give a complete low-level SPI configuration from user's managed connectionSettings -spi_device_interface_config_t GetConfig( int bus, CLR_RT_HeapBlock* config) -{ - (void)bus; - - int csPin = config[ SpiConnectionSettings::FIELD___csLine ].NumericByRef().s4; - uint8_t spiMode = (uint8_t)config[ SpiConnectionSettings::FIELD___spiMode ].NumericByRef().s4; - int bitOrder = config[ SpiConnectionSettings::FIELD___bitOrder ].NumericByRef().s4; - int clockHz = config[ SpiConnectionSettings::FIELD___clockFrequency ].NumericByRef().s4; - - // if clock frequency is unset use the maximum frequency - if (clockHz == 0) - { - clockHz = MAX_CLOCK_FREQUENCY; - } - - //ets_printf( "Spi config cspin:%d spiMode:%d bitorder:%d clockHz:%d\n", csPin, spiMode, bitOrder, clockHz); - uint32_t flags = (bitOrder == 1) ? (SPI_DEVICE_TXBIT_LSBFIRST | SPI_DEVICE_RXBIT_LSBFIRST) : 0; - - // Fill in device config - spi_device_interface_config_t dev_config - { - 0, // Command bits - 0, // Address bits - 0, // Dummy bits - spiMode, // SPi Mode - 0, // Duty cycle 50/50 - 0, // cs_ena_pretrans - 0, // cs_ena_posttrans - clockHz, // Clock speed in Hz - 0, // Input_delay_ns - csPin, // Chip select - flags, // SPI_DEVICE flags - 1, // Queue size - 0, // Callback before - 0, // Callback after - }; - - return dev_config; -} - -// -// Add new device and return device index -// return -1 if no more devices avalaible -// -int Add_Spi_Device(int bus, CLR_RT_HeapBlock* pThis) -{ - spi_device_interface_config_t dev_config; - nfSpiBusConfig * pBusConfig = &spiconfig[bus]; - - int deviceIndex = FindFreeDeviceSlotSpi(bus); - // Check if all device slots used - if (deviceIndex < 0) return -1; - - // Get a complete low-level SPI configuration, depending on user's managed parameters - dev_config = GetConfig(bus, pThis[ Library_win_dev_spi_native_Windows_Devices_Spi_SpiDevice::FIELD___connectionSettings ].Dereference()); - - // Add device to bus - spi_device_handle_t deviceHandle; - if ( spi_bus_add_device( (spi_host_device_t)bus, &dev_config, &deviceHandle ) != ESP_OK ) - { - ESP_LOGE( TAG, "Unable to init SPI device"); - return -1; - } - - // Add next Device - pBusConfig->deviceId[deviceIndex] = pThis[ Library_win_dev_spi_native_Windows_Devices_Spi_SpiDevice::FIELD___deviceId ].NumericByRef().s4; - pBusConfig->deviceHandles[deviceIndex] = deviceHandle; - - return deviceIndex; -} - -// -// Get the Bus and device index -// return false if error -// -bool GetDevice( CLR_RT_HeapBlock* pThis, uint8_t * pBus, int * pDeviceIndex) -{ - int32_t deviceId = pThis[ Library_win_dev_spi_native_Windows_Devices_Spi_SpiDevice::FIELD___deviceId ].NumericByRef().s4; - *pBus = (uint8_t)(deviceId / 1000); - - // Find device in spiconfig - for( int index=0; index < MAX_SPI_DEVICES; index++) - { - if ( spiconfig[*pBus].deviceId[index] == deviceId ) - { - // Device found with same deviceId - *pDeviceIndex = index; - return true; - } - } - return false; -} - -HRESULT Library_win_dev_spi_native_Windows_Devices_Spi_SpiDevice::NativeTransfer___VOID__SZARRAY_U1__SZARRAY_U1__BOOLEAN( CLR_RT_StackFrame& stack ) -{ - return NativeTransfer( stack, false ); -} - -HRESULT Library_win_dev_spi_native_Windows_Devices_Spi_SpiDevice::NativeTransfer___VOID__SZARRAY_U2__SZARRAY_U2__BOOLEAN( CLR_RT_StackFrame& stack ) -{ - return NativeTransfer( stack, true ); -} - -HRESULT Library_win_dev_spi_native_Windows_Devices_Spi_SpiDevice::NativeTransfer( CLR_RT_StackFrame& stack, bool data16 ) -{ - NANOCLR_HEADER(); - { - unsigned char * writeData = NULL; - unsigned char * originalReadData = NULL; - unsigned char * readData = NULL; - int writeSize = 0; - int readSize = 0; - - stack.m_customState = 1; - - // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); - - // get a pointer to the managed spi connectionSettings object instance - CLR_RT_HeapBlock* pConfig = pThis[ FIELD___connectionSettings ].Dereference(); - - // get bus index and Device index - uint8_t bus; - int deviceIndex; - if ( GetDevice( pThis, &bus, &deviceIndex) == false ) - { - NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); - } - - // get data bit length - int databitLength = pConfig[ SpiConnectionSettings::FIELD___databitLength ].NumericByRef().s4; - if (databitLength <= 0) databitLength = 8; - if ( data16 ) databitLength = 16; - - // dereference the write and read buffers from the arguments - CLR_RT_HeapBlock_Array* writeBuffer = stack.Arg1().DereferenceArray(); - if (writeBuffer != NULL) - { - // grab the pointer to the array by getting the first element of the array - if ( data16 ) - writeData = (unsigned char * )writeBuffer->GetFirstElementUInt16(); - else - writeData = writeBuffer->GetFirstElement(); - - // get the size of the buffer by reading the number of elements in the HeapBlock array - writeSize = writeBuffer->m_numOfElements; - } - - CLR_RT_HeapBlock_Array* readBuffer = stack.Arg2().DereferenceArray(); - if (readBuffer != NULL) - { - // grab the pointer to the array by getting the first element of the array - if ( data16 ) - originalReadData = (unsigned char * )readBuffer->GetFirstElementUInt16(); - else - originalReadData = readBuffer->GetFirstElement(); - - // get the size of the buffer by reading the number of elements in the HeapBlock array - readSize = readBuffer->m_numOfElements; - } - - // Are we using SPI full-duplex for transfer ? - // The SPI doesn't support half duplex operation with DMA and without DMA the receive length is limited to 4 bytes - // So we run in full duplex mode all the time and simulate half duplex mode by creating a larger receive buffer for - // the whole of the transaction and then copying the rx part to original buffer - // For full duplex we just use passed buffers. - bool fullDuplex = (bool)stack.Arg3().NumericByRef().u1; - - int MaxDatalength; - if (fullDuplex) - { - // for full duplex just use largest element - MaxDatalength= (readSize > writeSize)? readSize: writeSize; - readData = originalReadData; - } - else - { - // for Halfduplex its the length of both items - MaxDatalength = writeSize + readSize; - - if (readSize) - { - // Allocate a new read buffer to include total length(DMA capable) - readData = (unsigned char *)heap_caps_malloc(MaxDatalength, MALLOC_CAP_DMA); - if ( readData == 0) NANOCLR_SET_AND_LEAVE(CLR_E_OUT_OF_MEMORY); - } - } - - // Set up SPI Transaction - spi_transaction_t trans_desc; - - trans_desc.flags = 0; - trans_desc.cmd = 0; - trans_desc.addr = 0; - // length - Full duplex is total length, half duplex the TX length - trans_desc.length = databitLength * MaxDatalength; - // rxlength - Full duplex is same as length or 0, half duplex is read length - trans_desc.rxlength = 0; - trans_desc.user = NULL; - trans_desc.tx_buffer = writeData; - trans_desc.rx_buffer = readData; - - // Start tranfer ( this calls spi_device_queue_trans & spi_device_get_trans_result) - // Next release of IDF has a direct plling mode that should be faster - esp_err_t ret = spi_device_transmit( spiconfig[bus].deviceHandles[deviceIndex], &trans_desc); - if ( ret != ESP_OK ) - { - if (!fullDuplex) heap_caps_free(readData); - NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); - } - - // Finish up half duplex - if (!fullDuplex) - { - if (readSize) - { - // Copy the read data - memcpy( originalReadData, readData + writeSize, readSize); - heap_caps_free(readData); - } - } - } - NANOCLR_NOCLEANUP(); -} - -HRESULT Library_win_dev_spi_native_Windows_Devices_Spi_SpiDevice::NativeInit___VOID( CLR_RT_StackFrame& stack ) -{ - NANOCLR_HEADER(); - - // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); //FAULT_ON_NULL(pThis); - - // get bus index - // this is coded with a multiplication, need to perform and int division to get the number - // see the comments in the SpiDevice() constructor in managed code for details ( 1 or 2 ) - int32_t deviceId = pThis[ FIELD___deviceId ].NumericByRef().s4; - - spi_host_device_t bus = (spi_host_device_t)( deviceId / 1000 ); - - // Check valid bus - if ( bus < HSPI_HOST || bus > VSPI_HOST ) - { - NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); - } - - if ( !nfSpiInited ) - { - for( int i=0; i -#include - -// # buses but first can't be used as SPI flash -#define NUM_SPI_BUSES 3 -#define MAX_SPI_DEVICES 3 - -// Max clock frequency is 20 MHz -#define MAX_CLOCK_FREQUENCY 20000000 - -struct nfSpiBusConfig -{ - bool spiBusInited; - int deviceId[MAX_SPI_DEVICES]; // Used to find correct device in config - spi_device_handle_t deviceHandles[MAX_SPI_DEVICES]; // Max 3 devices per bus (IDF limit ) -}; -#endif //_WIN_DEV_SPI_NATIVE_TARGET_H_ +#endif //_WIN_DEV_SPI_NATIVE_TARGET_H_ diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Wifi/win_dev_wifi_native.h b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Wifi/win_dev_wifi_native.h index 42fe779c36..90eb97ce5c 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Wifi/win_dev_wifi_native.h +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Wifi/win_dev_wifi_native.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Wifi/win_dev_wifi_native_Windows_Devices_WIFI_WifiAdapter.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Wifi/win_dev_wifi_native_Windows_Devices_WIFI_WifiAdapter.cpp index f40c3f9f61..258b0e49e9 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Wifi/win_dev_wifi_native_Windows_Devices_WIFI_WifiAdapter.cpp +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Wifi/win_dev_wifi_native_Windows_Devices_WIFI_WifiAdapter.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Networking.Sockets/win_net_sockets_native_Windows_Networking_Sockets_SocketNative.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Networking.Sockets/win_net_sockets_native_Windows_Networking_Sockets_SocketNative.cpp index 3492d2bfc1..8c714bbe11 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Networking.Sockets/win_net_sockets_native_Windows_Networking_Sockets_SocketNative.cpp +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Networking.Sockets/win_net_sockets_native_Windows_Networking_Sockets_SocketNative.cpp @@ -1,47 +1,50 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // - #include "win_net_sockets_native_target.h" // TODO - Check if required, for now just ignore -#define SwapEndianIfBEc16(x) (x) +#define SwapEndianIfBEc16(x) (x) -HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::socket___STATIC__I4__I4__I4__I4( CLR_RT_StackFrame& stack ) +HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::socket___STATIC__I4__I4__I4__I4( + CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); - CLR_INT32 family = stack.Arg0().NumericByRef().s4; - CLR_INT32 type = stack.Arg1().NumericByRef().s4; + CLR_INT32 family = stack.Arg0().NumericByRef().s4; + CLR_INT32 type = stack.Arg1().NumericByRef().s4; CLR_INT32 protocol = stack.Arg2().NumericByRef().s4; - + CLR_INT32 nonBlocking = 1; - CLR_INT32 sock = SOCK_socket( family, type, protocol ); - - NANOCLR_CHECK_HRESULT(ThrowOnError( stack, sock )); - - NANOCLR_CHECK_HRESULT(ThrowOnError( stack, SOCK_ioctl( sock, SOCK_FIONBIO, &nonBlocking ) )); + CLR_INT32 sock = SOCK_socket(family, type, protocol); + + NANOCLR_CHECK_HRESULT(ThrowOnError(stack, sock)); - stack.SetResult_I4( sock ); + NANOCLR_CHECK_HRESULT(ThrowOnError(stack, SOCK_ioctl(sock, SOCK_FIONBIO, &nonBlocking))); + + stack.SetResult_I4(sock); NANOCLR_NOCLEANUP(); } -HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::bind___STATIC__VOID__OBJECT__SZARRAY_U1( CLR_RT_StackFrame& stack ) +HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::bind___STATIC__VOID__OBJECT__SZARRAY_U1( + CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); - return BindConnectHelper( stack, true ); + return BindConnectHelper(stack, true); } -HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::connect___STATIC__VOID__OBJECT__SZARRAY_U1__BOOLEAN( CLR_RT_StackFrame& stack ) +HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: + connect___STATIC__VOID__OBJECT__SZARRAY_U1__BOOLEAN(CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); - return BindConnectHelper( stack, false ); + return BindConnectHelper(stack, false); } -HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::send___STATIC__I4__OBJECT__SZARRAY_U1__I4__I4__I4__I4( CLR_RT_StackFrame& stack ) +HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: + send___STATIC__I4__OBJECT__SZARRAY_U1__I4__I4__I4__I4(CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); @@ -50,7 +53,8 @@ HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: NANOCLR_NOCLEANUP(); } -HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::recv___STATIC__I4__OBJECT__SZARRAY_U1__I4__I4__I4__I4( CLR_RT_StackFrame& stack ) +HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: + recv___STATIC__I4__OBJECT__SZARRAY_U1__I4__I4__I4__I4(CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); @@ -59,83 +63,87 @@ HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: NANOCLR_NOCLEANUP(); } -HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::close___STATIC__I4__OBJECT( CLR_RT_StackFrame& stack ) +HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::close___STATIC__I4__OBJECT( + CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); CLR_INT32 handle, ret; - CLR_RT_HeapBlock* socket = stack.Arg0().Dereference(); FAULT_ON_NULL(socket); - - handle = socket[ FIELD__m_Handle ].NumericByRef().s4; + CLR_RT_HeapBlock *socket = stack.Arg0().Dereference(); + FAULT_ON_NULL(socket); + + handle = socket[FIELD__m_Handle].NumericByRef().s4; + + ret = SOCK_close(handle); + + // If a socket gets closed, we need to make sure to wake up any threads that are waiting on it. + Events_Set(SYSTEM_EVENT_FLAG_SOCKET); - ret = SOCK_close( handle ); - - //If a socket gets closed, we need to make sure to wake up any threads that are waiting on it. - Events_Set( SYSTEM_EVENT_FLAG_SOCKET ); + stack.SetResult_I4(ret); - stack.SetResult_I4( ret ); - NANOCLR_NOCLEANUP(); } -HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::listen___STATIC__VOID__OBJECT__I4( CLR_RT_StackFrame& stack ) +HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::listen___STATIC__VOID__OBJECT__I4( + CLR_RT_StackFrame &stack) { NATIVE_PROFILE_CLR_NETWORK(); NANOCLR_HEADER(); - CLR_RT_HeapBlock* socket = stack.Arg0().Dereference(); + CLR_RT_HeapBlock *socket = stack.Arg0().Dereference(); CLR_INT32 handle; CLR_INT32 backlog = stack.Arg1().NumericByRef().s4; CLR_INT32 ret; FAULT_ON_NULL(socket); - handle = socket[ FIELD__m_Handle ].NumericByRef().s4; + handle = socket[FIELD__m_Handle].NumericByRef().s4; - ret = SOCK_listen( handle, backlog ); + ret = SOCK_listen(handle, backlog); - NANOCLR_CHECK_HRESULT(ThrowOnError( stack, ret )); + NANOCLR_CHECK_HRESULT(ThrowOnError(stack, ret)); NANOCLR_NOCLEANUP(); } -HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::accept___STATIC__I4__OBJECT( CLR_RT_StackFrame& stack ) +HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::accept___STATIC__I4__OBJECT( + CLR_RT_StackFrame &stack) { NATIVE_PROFILE_CLR_NETWORK(); NANOCLR_HEADER(); - CLR_RT_HeapBlock* socket = stack.Arg0().Dereference(); + CLR_RT_HeapBlock *socket = stack.Arg0().Dereference(); CLR_INT32 handle; CLR_INT32 ret; CLR_INT32 nonBlocking = 1; FAULT_ON_NULL(socket); - handle = socket[ FIELD__m_Handle ].NumericByRef().s4; - + handle = socket[FIELD__m_Handle].NumericByRef().s4; /* Because we could have been a rescheduled call due to a prior call that would have blocked, we need to see - * if our handle has been shutdown before continuing. */ + * if our handle has been shutdown before continuing. */ if (handle == DISPOSED_HANDLE) { ThrowError(stack, CLR_E_OBJECT_DISPOSED); - NANOCLR_SET_AND_LEAVE (CLR_E_PROCESS_EXCEPTION); + NANOCLR_SET_AND_LEAVE(CLR_E_PROCESS_EXCEPTION); } - ret = SOCK_accept( handle, NULL, NULL ); + ret = SOCK_accept(handle, NULL, NULL); - if(ret != SOCK_SOCKET_ERROR) + if (ret != SOCK_SOCKET_ERROR) { - NANOCLR_CHECK_HRESULT(ThrowOnError( stack, SOCK_ioctl( ret, SOCK_FIONBIO, &nonBlocking ) )); + NANOCLR_CHECK_HRESULT(ThrowOnError(stack, SOCK_ioctl(ret, SOCK_FIONBIO, &nonBlocking))); } - NANOCLR_CHECK_HRESULT(ThrowOnError( stack, ret )); + NANOCLR_CHECK_HRESULT(ThrowOnError(stack, ret)); - stack.SetResult_I4( ret ); + stack.SetResult_I4(ret); NANOCLR_NOCLEANUP(); } -HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::getaddrinfo___STATIC__VOID__STRING__BYREF_STRING__BYREF_SZARRAY_SZARRAY_U1( CLR_RT_StackFrame& stack ) +HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: + getaddrinfo___STATIC__VOID__STRING__BYREF_STRING__BYREF_SZARRAY_SZARRAY_U1(CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); @@ -144,7 +152,8 @@ HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: NANOCLR_NOCLEANUP(); } -HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::shutdown___STATIC__VOID__OBJECT__I4__BYREF_I4( CLR_RT_StackFrame& stack ) +HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: + shutdown___STATIC__VOID__OBJECT__I4__BYREF_I4(CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); @@ -153,7 +162,8 @@ HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: NANOCLR_NOCLEANUP(); } -HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::sendto___STATIC__I4__OBJECT__SZARRAY_U1__I4__I4__I4__I4__SZARRAY_U1( CLR_RT_StackFrame& stack ) +HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: + sendto___STATIC__I4__OBJECT__SZARRAY_U1__I4__I4__I4__I4__SZARRAY_U1(CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); @@ -162,7 +172,8 @@ HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: NANOCLR_NOCLEANUP(); } -HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::recvfrom___STATIC__I4__OBJECT__SZARRAY_U1__I4__I4__I4__I4__BYREF_SZARRAY_U1( CLR_RT_StackFrame& stack ) +HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: + recvfrom___STATIC__I4__OBJECT__SZARRAY_U1__I4__I4__I4__I4__BYREF_SZARRAY_U1(CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); @@ -171,7 +182,8 @@ HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: NANOCLR_NOCLEANUP(); } -HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::getpeername___STATIC__VOID__OBJECT__BYREF_SZARRAY_U1( CLR_RT_StackFrame& stack ) +HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: + getpeername___STATIC__VOID__OBJECT__BYREF_SZARRAY_U1(CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); @@ -180,7 +192,8 @@ HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: NANOCLR_NOCLEANUP(); } -HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::getsockname___STATIC__VOID__OBJECT__BYREF_SZARRAY_U1( CLR_RT_StackFrame& stack ) +HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: + getsockname___STATIC__VOID__OBJECT__BYREF_SZARRAY_U1(CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); @@ -189,7 +202,8 @@ HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: NANOCLR_NOCLEANUP(); } -HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::getsockopt___STATIC__VOID__OBJECT__I4__I4__SZARRAY_U1( CLR_RT_StackFrame& stack ) +HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: + getsockopt___STATIC__VOID__OBJECT__I4__I4__SZARRAY_U1(CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); @@ -198,7 +212,8 @@ HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: NANOCLR_NOCLEANUP(); } -HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::setsockopt___STATIC__VOID__OBJECT__I4__I4__SZARRAY_U1( CLR_RT_StackFrame& stack ) +HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: + setsockopt___STATIC__VOID__OBJECT__I4__I4__SZARRAY_U1(CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); @@ -207,7 +222,8 @@ HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: NANOCLR_NOCLEANUP(); } -HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::poll___STATIC__BOOLEAN__OBJECT__I4__I4( CLR_RT_StackFrame& stack ) +HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::poll___STATIC__BOOLEAN__OBJECT__I4__I4( + CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); @@ -216,7 +232,8 @@ HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: NANOCLR_NOCLEANUP(); } -HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::ioctl___STATIC__VOID__OBJECT__U4__BYREF_U4( CLR_RT_StackFrame& stack ) +HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: + ioctl___STATIC__VOID__OBJECT__U4__BYREF_U4(CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); @@ -225,16 +242,16 @@ HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: NANOCLR_NOCLEANUP(); } - - //--// -HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::BindConnectHelper( CLR_RT_StackFrame& stack, bool fBind ) +HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::BindConnectHelper( + CLR_RT_StackFrame &stack, + bool fBind) { NATIVE_PROFILE_CLR_NETWORK(); NANOCLR_HEADER(); - CLR_RT_HeapBlock* socket = stack.Arg0().Dereference(); + CLR_RT_HeapBlock *socket = stack.Arg0().Dereference(); CLR_INT32 handle; SOCK_sockaddr addr; CLR_UINT32 addrLen = sizeof(addr); @@ -242,83 +259,91 @@ HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: bool fThrowOnWouldBlock = false; FAULT_ON_NULL(socket); - handle = socket[ FIELD__m_Handle ].NumericByRef().s4; + handle = socket[FIELD__m_Handle].NumericByRef().s4; - NANOCLR_CHECK_HRESULT(MarshalSockAddress( &addr, addrLen, stack.Arg1() )); + NANOCLR_CHECK_HRESULT(MarshalSockAddress(&addr, addrLen, stack.Arg1())); - if(fBind) + if (fBind) { - ret = SOCK_bind( handle, &addr, addrLen ); + ret = SOCK_bind(handle, &addr, addrLen); } else { - ret = SOCK_connect( handle, &addr, addrLen ); - + ret = SOCK_connect(handle, &addr, addrLen); + fThrowOnWouldBlock = (stack.Arg2().NumericByRefConst().s4 != 0); - - if(!fThrowOnWouldBlock && SOCK_getlasterror() == SOCK_EWOULDBLOCK) + + if (!fThrowOnWouldBlock && SOCK_getlasterror() == SOCK_EWOULDBLOCK) { - NANOCLR_SET_AND_LEAVE(S_OK); + NANOCLR_SET_AND_LEAVE(S_OK); } } - NANOCLR_CHECK_HRESULT(ThrowOnError( stack, ret )); + NANOCLR_CHECK_HRESULT(ThrowOnError(stack, ret)); NANOCLR_NOCLEANUP(); } -HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::MarshalSockAddress( CLR_RT_HeapBlock& blkDst, const struct SOCK_sockaddr* addrSrc, CLR_UINT32 addrLenSrc ) +HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::MarshalSockAddress( + CLR_RT_HeapBlock &blkDst, + const struct SOCK_sockaddr *addrSrc, + CLR_UINT32 addrLenSrc) { NATIVE_PROFILE_CLR_NETWORK(); NANOCLR_HEADER(); - CLR_RT_HeapBlock_Array* arr = NULL; + CLR_RT_HeapBlock_Array *arr = NULL; + + CLR_RT_HeapBlock blkArr; + blkArr.SetObjectReference(NULL); + CLR_RT_ProtectFromGC gc(blkArr); + SOCK_sockaddr_in *dst; + SOCK_sockaddr_in *src = (SOCK_sockaddr_in *)addrSrc; + + NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_Array::CreateInstance(blkArr, addrLenSrc, g_CLR_RT_WellKnownTypes.m_UInt8)); - CLR_RT_HeapBlock blkArr; blkArr.SetObjectReference( NULL ); - CLR_RT_ProtectFromGC gc( blkArr ); - SOCK_sockaddr_in* dst; - SOCK_sockaddr_in* src = (SOCK_sockaddr_in*)addrSrc; - - NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_Array::CreateInstance( blkArr, addrLenSrc, g_CLR_RT_WellKnownTypes.m_UInt8 )); - arr = blkArr.DereferenceArray(); _ASSERTE(arr); - dst = (SOCK_sockaddr_in*)arr->GetFirstElement(); + dst = (SOCK_sockaddr_in *)arr->GetFirstElement(); - dst->sin_family = SwapEndianIfBEc16(src->sin_family); - dst->sin_port = src->sin_port; + dst->sin_family = SwapEndianIfBEc16(src->sin_family); + dst->sin_port = src->sin_port; dst->sin_addr.S_un.S_addr = src->sin_addr.S_un.S_addr; memcpy(dst->sin_zero, src->sin_zero, sizeof(dst->sin_zero)); _ASSERTE(blkDst.DataType() == DATATYPE_BYREF || blkDst.DataType() == DATATYPE_ARRAY_BYREF); - NANOCLR_CHECK_HRESULT(blkArr.StoreToReference( blkDst, 0 )); + NANOCLR_CHECK_HRESULT(blkArr.StoreToReference(blkDst, 0)); NANOCLR_NOCLEANUP(); } -HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::MarshalSockAddress( struct SOCK_sockaddr* addrDst, CLR_UINT32& addrLen, const CLR_RT_HeapBlock& blkSockAddress ) -{ +HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::MarshalSockAddress( + struct SOCK_sockaddr *addrDst, + CLR_UINT32 &addrLen, + const CLR_RT_HeapBlock &blkSockAddress) +{ NATIVE_PROFILE_CLR_NETWORK(); NANOCLR_HEADER(); - CLR_RT_HeapBlock_Array* ptrSockAddress; - SOCK_sockaddr_in* dst = (SOCK_sockaddr_in*)addrDst; - SOCK_sockaddr_in* src; + CLR_RT_HeapBlock_Array *ptrSockAddress; + SOCK_sockaddr_in *dst = (SOCK_sockaddr_in *)addrDst; + SOCK_sockaddr_in *src; - ptrSockAddress = blkSockAddress.DereferenceArray(); + ptrSockAddress = blkSockAddress.DereferenceArray(); FAULT_ON_NULL(ptrSockAddress); - if(ptrSockAddress->m_numOfElements > addrLen) NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); + if (ptrSockAddress->m_numOfElements > addrLen) + NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); - src = (SOCK_sockaddr_in*)ptrSockAddress->GetFirstElement(); + src = (SOCK_sockaddr_in *)ptrSockAddress->GetFirstElement(); - dst->sin_family = SwapEndianIfBEc16(src->sin_family); - dst->sin_port = src->sin_port; - dst->sin_addr.S_un.S_addr = src->sin_addr.S_un.S_addr; //already in network byte order + dst->sin_family = SwapEndianIfBEc16(src->sin_family); + dst->sin_port = src->sin_port; + dst->sin_addr.S_un.S_addr = src->sin_addr.S_un.S_addr; // already in network byte order memcpy(dst->sin_zero, src->sin_zero, sizeof(dst->sin_zero)); @@ -327,14 +352,15 @@ HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: NANOCLR_NOCLEANUP(); } -// HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::SendRecvHelper( CLR_RT_StackFrame& stack, bool fSend, bool fAddress ) +// HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::SendRecvHelper( CLR_RT_StackFrame& +// stack, bool fSend, bool fAddress ) // { // NATIVE_PROFILE_CLR_NETWORK(); // NANOCLR_HEADER(); // CLR_RT_HeapBlock* socket = stack.Arg0().Dereference(); // CLR_INT32 handle; -// CLR_RT_HeapBlock_Array* arrData = stack.Arg1().DereferenceArray(); +// CLR_RT_HeapBlock_Array* arrData = stack.Arg1().DereferenceArray(); // CLR_UINT32 offset = stack.Arg2().NumericByRef().u4; // CLR_UINT32 count = stack.Arg3().NumericByRef().u4; // CLR_INT32 flags = stack.Arg4().NumericByRef().s4; @@ -349,7 +375,7 @@ HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: // FAULT_ON_NULL(socket); // FAULT_ON_NULL(arrData); - + // handle = socket[ FIELD__m_Handle ].NumericByRef().s4; // /* Because we could have been a rescheduled call due to a prior call that would have blocked, we need to see @@ -360,11 +386,10 @@ HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: // NANOCLR_SET_AND_LEAVE (CLR_E_PROCESS_EXCEPTION); // } -// if(offset + count > arrData->m_numOfElements) NANOCLR_SET_AND_LEAVE(CLR_E_INDEX_OUT_OF_RANGE); - +// if(offset + count > arrData->m_numOfElements) NANOCLR_SET_AND_LEAVE(CLR_E_INDEX_OUT_OF_RANGE); // hbTimeout.SetInteger( timeout_ms ); - + // NANOCLR_CHECK_HRESULT(stack.SetupTimeout( hbTimeout, timeout )); // // @@ -373,7 +398,7 @@ HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: // if(stack.m_customState == 1) // { // stack.PushValueI4( 0 ); - + // stack.m_customState = 2; // } @@ -394,14 +419,15 @@ HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: // if(ret != 0) break; // // non-blocking - allow other threads to run while we wait for handle activity -// NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.WaitEvents( stack.m_owningThread, *timeout, CLR_RT_ExecutionEngine::c_Event_Socket, fRes )); +// NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.WaitEvents( stack.m_owningThread, *timeout, Event_Socket, +// fRes )); // } // // timeout expired // if(!fRes) // { // ret = SOCK_SOCKET_ERROR; - + // ThrowError( stack, SOCK_ETIMEDOUT ); // NANOCLR_SET_AND_LEAVE( CLR_E_PROCESS_EXCEPTION ); @@ -428,7 +454,7 @@ HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: // else // { // CLR_RT_HeapBlock* pBlkAddr = blkAddr.Dereference(); - + // NANOCLR_CHECK_HRESULT(MarshalSockAddress( &addr, addrLen, *pBlkAddr )); // bytes = SOCK_recvfrom( handle, (char*)buf, count, flags, &addr, (int*)&addrLen ); @@ -455,26 +481,26 @@ HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: // if(bytes == SOCK_SOCKET_ERROR) // { // CLR_INT32 err = SOCK_getlasterror(); - + // if(err != SOCK_EWOULDBLOCK) // { // ret = SOCK_SOCKET_ERROR; // break; // } - + // continue; // } // // zero recv bytes indicates the handle has been closed. -// else if(!fSend && (bytes == 0)) +// else if(!fSend && (bytes == 0)) // { // break; // } - + // buf += bytes; // totReadWrite += bytes; // count -= bytes; -// stack.m_evalStack[ 1 ].NumericByRef().s4 = totReadWrite; +// stack.m_evalStack[ 1 ].NumericByRef().s4 = totReadWrite; // // receive returns immediately after receiving bytes. // if(!fSend && (totReadWrite > 0)) @@ -486,7 +512,7 @@ HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: // stack.PopValue(); // totReadWrite // stack.PopValue(); // Timeout - + // NANOCLR_CHECK_HRESULT(ThrowOnError( stack, ret )); // stack.SetResult_I4( totReadWrite ); @@ -494,100 +520,107 @@ HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative:: // NANOCLR_NOCLEANUP(); // } -HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::SockOptHelper( CLR_RT_StackFrame& stack, bool fGet ) +HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::SockOptHelper( + CLR_RT_StackFrame &stack, + bool fGet) { NATIVE_PROFILE_CLR_NETWORK(); NANOCLR_HEADER(); - CLR_RT_HeapBlock* socket = stack.Arg0().Dereference(); + CLR_RT_HeapBlock *socket = stack.Arg0().Dereference(); CLR_INT32 handle; - CLR_INT32 level = stack.Arg1().NumericByRef().s4; + CLR_INT32 level = stack.Arg1().NumericByRef().s4; CLR_INT32 optname = stack.Arg2().NumericByRef().s4; - CLR_RT_HeapBlock_Array* arrOpt = stack.Arg3().DereferenceArray(); - char* optval; + CLR_RT_HeapBlock_Array *arrOpt = stack.Arg3().DereferenceArray(); + char *optval; CLR_INT32 optlen; CLR_INT32 ret; FAULT_ON_NULL(socket); - handle = socket[ FIELD__m_Handle ].NumericByRef().s4; + handle = socket[FIELD__m_Handle].NumericByRef().s4; FAULT_ON_NULL(arrOpt); - - optval = (char*)arrOpt->GetFirstElement(); + + optval = (char *)arrOpt->GetFirstElement(); optlen = arrOpt->m_numOfElements; - if(fGet) + if (fGet) { - ret = SOCK_getsockopt( handle, level, optname, optval, &optlen ); - _ASSERTE( optlen <= (CLR_INT32)arrOpt->m_numOfElements ); + ret = SOCK_getsockopt(handle, level, optname, optval, &optlen); + _ASSERTE(optlen <= (CLR_INT32)arrOpt->m_numOfElements); } else { - ret = SOCK_setsockopt( handle, level, optname, optval, optlen ); + ret = SOCK_setsockopt(handle, level, optname, optval, optlen); } - NANOCLR_CHECK_HRESULT(ThrowOnError( stack, ret )); + NANOCLR_CHECK_HRESULT(ThrowOnError(stack, ret)); NANOCLR_NOCLEANUP(); } -HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::SockNameHelper( CLR_RT_StackFrame& stack, bool fPeer ) +HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::SockNameHelper( + CLR_RT_StackFrame &stack, + bool fPeer) { NATIVE_PROFILE_CLR_NETWORK(); NANOCLR_HEADER(); - CLR_RT_HeapBlock* socket = stack.Arg0().Dereference(); + CLR_RT_HeapBlock *socket = stack.Arg0().Dereference(); CLR_INT32 handle; CLR_INT32 ret; - + struct SOCK_sockaddr addr; CLR_INT32 addrLen = sizeof(addr); FAULT_ON_NULL(socket); - handle = socket[ FIELD__m_Handle ].NumericByRef().s4; + handle = socket[FIELD__m_Handle].NumericByRef().s4; - if(fPeer) + if (fPeer) { - ret = SOCK_getpeername( handle, &addr, &addrLen ); + ret = SOCK_getpeername(handle, &addr, &addrLen); } else { - ret = SOCK_getsockname( handle, &addr, &addrLen ); + ret = SOCK_getsockname(handle, &addr, &addrLen); } - - NANOCLR_CHECK_HRESULT(ThrowOnError( stack, ret )); - - NANOCLR_CHECK_HRESULT(MarshalSockAddress( stack.Arg1(), &addr, addrLen )); - - NANOCLR_NOCLEANUP(); -} + NANOCLR_CHECK_HRESULT(ThrowOnError(stack, ret)); + NANOCLR_CHECK_HRESULT(MarshalSockAddress(stack.Arg1(), &addr, addrLen)); + NANOCLR_NOCLEANUP(); +} -void Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::ThrowError( CLR_RT_StackFrame& stack, CLR_INT32 errorCode ) -{ +void Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::ThrowError( + CLR_RT_StackFrame &stack, + CLR_INT32 errorCode) +{ NATIVE_PROFILE_CLR_NETWORK(); // CLR_RT_HeapBlock& res = stack.m_owningThread->m_currentException; - - // if((Library_corlib_native_System_Exception::CreateInstance( res, g_CLR_RT_WellKnownTypes.m_SocketException, CLR_E_FAIL, &stack )) == S_OK) + + // if((Library_corlib_native_System_Exception::CreateInstance( res, g_CLR_RT_WellKnownTypes.m_SocketException, + // CLR_E_FAIL, &stack )) == S_OK) // { - // res.Dereference()[ Library_system_sockets_System_Net_Sockets_SocketException::FIELD___errorCode ].SetInteger( errorCode ); + // res.Dereference()[ Library_system_sockets_System_Net_Sockets_SocketException::FIELD___errorCode ].SetInteger( + // errorCode ); // } } -HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::ThrowOnError( CLR_RT_StackFrame& stack, CLR_INT32 res ) -{ +HRESULT Library_win_net_sockets_native_Windows_Networking_Sockets_SocketNative::ThrowOnError( + CLR_RT_StackFrame &stack, + CLR_INT32 res) +{ NATIVE_PROFILE_CLR_NETWORK(); NANOCLR_HEADER(); - if(res == SOCK_SOCKET_ERROR) - { + if (res == SOCK_SOCKET_ERROR) + { CLR_INT32 err = SOCK_getlasterror(); - ThrowError( stack, err ); + ThrowError(stack, err); - NANOCLR_SET_AND_LEAVE( CLR_E_PROCESS_EXCEPTION ); + NANOCLR_SET_AND_LEAVE(CLR_E_PROCESS_EXCEPTION); } NANOCLR_NOCLEANUP(); diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Networking.Sockets/win_net_sockets_native_target.h b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Networking.Sockets/win_net_sockets_native_target.h index e885142e6c..6d6a18d053 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Networking.Sockets/win_net_sockets_native_target.h +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Networking.Sockets/win_net_sockets_native_target.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Storage/win_storage_native_Windows_Storage_Devices_SDCard.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Storage/win_storage_native_Windows_Storage_Devices_SDCard.cpp index d92723aa11..3be524a685 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Storage/win_storage_native_Windows_Storage_Devices_SDCard.cpp +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Storage/win_storage_native_Windows_Storage_Devices_SDCard.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Storage/win_storage_native_Windows_Storage_FileIO.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Storage/win_storage_native_Windows_Storage_FileIO.cpp index 4a8bf2c48b..79926cae2a 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Storage/win_storage_native_Windows_Storage_FileIO.cpp +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Storage/win_storage_native_Windows_Storage_FileIO.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // @@ -9,51 +9,53 @@ #include #include - // defining these types here to make it shorter and improve code readability typedef Library_win_storage_native_Windows_Storage_StorageFolder StorageFolder; typedef Library_win_storage_native_Windows_Storage_StorageFile StorageFile; extern "C" { - bool Storage_InitSDCardMMC(char * vfsName, int maxFiles, bool bit1Mode); - bool Storage_InitSDCardSPI(char * vfsName, int maxFiles, int pin_Miso, int pin_Mosi, int pin_Clk, int pin_Cs); + bool Storage_InitSDCardMMC(char *vfsName, int maxFiles, bool bit1Mode); + bool Storage_InitSDCardSPI(char *vfsName, int maxFiles, int pin_Miso, int pin_Mosi, int pin_Clk, int pin_Cs); }; // Queue length for IO task -#define StorageQueueLength 4 - +#define StorageQueueLength 4 ////////////////////////////////////////// -enum FileOperationType { READ_TEXT, WRITE_TEXT, READ_BINARY, WRITE_BINARY, EXIT }; +enum FileOperationType +{ + READ_TEXT, + WRITE_TEXT, + READ_BINARY, + WRITE_BINARY, + EXIT +}; struct FileOperation { - FileOperationType Operation; - FILE* File; - char* Content; - uint32_t ContentLength; + FileOperationType Operation; + FILE *File; + char *Content; + uint32_t ContentLength; }; struct OperationResult { - FRESULT result; + FRESULT result; }; - // Queues for passing Storage IO operations to thread abd returning results static QueueHandle_t StorageInputQueue; static QueueHandle_t StorageResultQueue; - -char * ConvertToESP32Path(const char * filepath); - +char *ConvertToESP32Path(const char *filepath); // Send IO operation to Queue -BaseType_t SendIOtoQueue(FileOperationType type, FILE *file, char * content, uint32_t contentLength) +BaseType_t SendIOtoQueue(FileOperationType type, FILE *file, char *content, uint32_t contentLength) { - FileOperation fileIoOperation; + FileOperation fileIoOperation; // setup FileIO operation fileIoOperation.Operation = type; @@ -81,15 +83,15 @@ FRESULT WaitIOResult() // because FatFS is supposed to be atomic we won't have any concurrent threads // ReadText working thread -static FRESULT StorageReadText(FileOperation* fileIoOperation ) +static FRESULT StorageReadText(FileOperation *fileIoOperation) { - FRESULT operationResult; + FRESULT operationResult; // need an extra one for the terminator uint32_t readLength = fileIoOperation->ContentLength + 1; - + // read string - if (fgets(fileIoOperation->Content, readLength, fileIoOperation->File) ) + if (fgets(fileIoOperation->Content, readLength, fileIoOperation->File)) { operationResult = FR_OK; } @@ -104,15 +106,14 @@ static FRESULT StorageReadText(FileOperation* fileIoOperation ) return operationResult; } - // WriteBinary working thread -static FRESULT StorageWriteBinary(FileOperation* fileIoOperation) +static FRESULT StorageWriteBinary(FileOperation *fileIoOperation) { - FRESULT operationResult = FR_DISK_ERR; - size_t bytesWritten; + FRESULT operationResult = FR_DISK_ERR; + size_t bytesWritten; bytesWritten = fwrite(fileIoOperation->Content, 1, fileIoOperation->ContentLength, fileIoOperation->File); - if( bytesWritten == fileIoOperation->ContentLength ) + if (bytesWritten == fileIoOperation->ContentLength) { // expected number of bytes written operationResult = FR_OK; @@ -125,15 +126,14 @@ static FRESULT StorageWriteBinary(FileOperation* fileIoOperation) } // ReadBinary working thread -static FRESULT StorageReadBinary(FileOperation* fileIoOperation) +static FRESULT StorageReadBinary(FileOperation *fileIoOperation) { - FRESULT operationResult = FR_DISK_ERR; - UINT bytesRead; + FRESULT operationResult = FR_DISK_ERR; + UINT bytesRead; - bytesRead = fread( fileIoOperation->Content, 1, fileIoOperation->ContentLength, fileIoOperation->File); - + bytesRead = fread(fileIoOperation->Content, 1, fileIoOperation->ContentLength, fileIoOperation->File); - if( bytesRead == fileIoOperation->ContentLength) + if (bytesRead == fileIoOperation->ContentLength) { // expected number of bytes read operationResult = FR_OK; @@ -145,13 +145,12 @@ static FRESULT StorageReadBinary(FileOperation* fileIoOperation) return operationResult; } - void StorageIOTask(void *pvParameters) { (void)pvParameters; bool bExit = false; - struct FileOperation fileOpMessage; + struct FileOperation fileOpMessage; struct OperationResult operationResult; while (!bExit) @@ -161,39 +160,39 @@ void StorageIOTask(void *pvParameters) { switch (fileOpMessage.Operation) { - case EXIT: - bExit = true; - operationResult.result = FR_OK; - break; - - case READ_TEXT: - operationResult.result = StorageReadText(&fileOpMessage); - break; - - case READ_BINARY: - operationResult.result = StorageReadBinary(&fileOpMessage); - break; - - case WRITE_TEXT: - case WRITE_BINARY: - operationResult.result = StorageWriteBinary(&fileOpMessage); - break; - - default: - operationResult.result = FR_OK; - break; + case EXIT: + bExit = true; + operationResult.result = FR_OK; + break; + + case READ_TEXT: + operationResult.result = StorageReadText(&fileOpMessage); + break; + + case READ_BINARY: + operationResult.result = StorageReadBinary(&fileOpMessage); + break; + + case WRITE_TEXT: + case WRITE_BINARY: + operationResult.result = StorageWriteBinary(&fileOpMessage); + break; + + default: + operationResult.result = FR_OK; + break; }; // Queue result and fire event - xQueueSend(StorageResultQueue, &operationResult, portMAX_DELAY); + xQueueSend(StorageResultQueue, &operationResult, portMAX_DELAY); // fire event for FileIO operation complete - if (fileOpMessage.Operation != EXIT) - Events_Set(SYSTEM_EVENT_FLAG_STORAGE_IO); + if (fileOpMessage.Operation != EXIT) + Events_Set(SYSTEM_EVENT_FLAG_STORAGE_IO); } } - vTaskDelete(NULL); + vTaskDelete(NULL); } void CreateStorageIOTask() @@ -227,68 +226,70 @@ void Storage_Uninitialize() //////////////////////////////////////////////// // Developer notes: -// Depending on the content size these operations have the potential to be a long running ones as the string or buffer is written to the storage. -// Despite we are not (yet!) async this is better handled by spawning a thread where the actual data transfer occurs and not blocking the execution. -// The underlying RTOS inheritably takes care of making this happen "in the background". -// When the operation is completed a CLR event is fired and the thread execution resumes. -// Being hard to estimate the expected duration of the operation (depends on storage hardware, CPU clock, transfer speed, etc) -// the timeout is set to an infinite timeout -// the catch is that the working thread MUST ALWAYS return at some point +// Depending on the content size these operations have the potential to be a long running ones as the string or buffer +// is written to the storage. Despite we are not (yet!) async this is better handled by spawning a thread where the +// actual data transfer occurs and not blocking the execution. The underlying RTOS inheritably takes care of making this +// happen "in the background". When the operation is completed a CLR event is fired and the thread execution resumes. +// Being hard to estimate the expected duration of the operation (depends on storage hardware, CPU clock, transfer +// speed, etc) the timeout is set to an infinite timeout the catch is that the working thread MUST ALWAYS return at some +// point //////////////////////////////////////////////// -HRESULT Library_win_storage_native_Windows_Storage_FileIO::WriteBytes___STATIC__VOID__WindowsStorageIStorageFile__SZARRAY_U1( CLR_RT_StackFrame& stack ) +HRESULT Library_win_storage_native_Windows_Storage_FileIO:: + WriteBytes___STATIC__VOID__WindowsStorageIStorageFile__SZARRAY_U1(CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); - CLR_RT_HeapBlock_Array* bufferArray; - CLR_RT_HeapBlock hbTimeout; - CLR_INT64* timeout; - bool eventResult = true; + CLR_RT_HeapBlock_Array *bufferArray; + CLR_RT_HeapBlock hbTimeout; + CLR_INT64 *timeout; + bool eventResult = true; - char* buffer; - uint32_t bufferLength; + char *buffer; + uint32_t bufferLength; - const TCHAR* filePath; - char * workingPath = NULL; - FILE* file; - FRESULT operationResult; + const TCHAR *filePath; + char *workingPath = NULL; + FILE *file; + FRESULT operationResult; // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); - + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + // get a pointer to the buffer bufferArray = stack.Arg1().DereferenceArray(); - buffer = (char*)bufferArray->GetFirstElement(); + buffer = (char *)bufferArray->GetFirstElement(); bufferLength = bufferArray->m_numOfElements; // get a pointer to the file path - filePath = (TCHAR*)pThis[ StorageFile::FIELD___path ].DereferenceString()->StringText(); + filePath = (TCHAR *)pThis[StorageFile::FIELD___path].DereferenceString()->StringText(); // !! need to cast to CLR_INT64 otherwise it wont setup a proper timeout infinite hbTimeout.SetInteger((CLR_INT64)-1); - NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks( hbTimeout, timeout )); - - if(stack.m_customState == 1) - { + NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks(hbTimeout, timeout)); + + if (stack.m_customState == 1) + { // open file (which is supposed to already exist) // need to use FA_OPEN_ALWAYS("w+") because we are writting the file content from start workingPath = ConvertToESP32Path(filePath); file = fopen(workingPath, "w+"); - if(file == NULL) + if (file == NULL) { NANOCLR_SET_AND_LEAVE(CLR_E_FILE_NOT_FOUND); } else { // protect the StorageFile and the content buffer from GC so the working thread can access those - CLR_RT_ProtectFromGC gcStorageFile( *pThis ); - CLR_RT_ProtectFromGC gcContent( *bufferArray ); + CLR_RT_ProtectFromGC gcStorageFile(*pThis); + CLR_RT_ProtectFromGC gcContent(*bufferArray); // setup FileIO operation - if ( SendIOtoQueue(WRITE_BINARY, file, buffer, bufferLength) == errQUEUE_FULL) + if (SendIOtoQueue(WRITE_BINARY, file, buffer, bufferLength) == errQUEUE_FULL) { NANOCLR_SET_AND_LEAVE(CLR_E_PROCESS_EXCEPTION); } @@ -298,25 +299,26 @@ HRESULT Library_win_storage_native_Windows_Storage_FileIO::WriteBytes___STATIC__ } } - while(eventResult) + while (eventResult) { // non-blocking wait allowing other threads to run while we wait for the write operation to complete - NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.WaitEvents( stack.m_owningThread, *timeout, CLR_RT_ExecutionEngine::c_Event_StorageIo, eventResult )); + NANOCLR_CHECK_HRESULT( + g_CLR_RT_ExecutionEngine.WaitEvents(stack.m_owningThread, *timeout, Event_StorageIo, eventResult)); - if(eventResult) + if (eventResult) { // event occurred operationResult = WaitIOResult(); - if(operationResult == FR_DISK_ERR) + if (operationResult == FR_DISK_ERR) { - NANOCLR_SET_AND_LEAVE( CLR_E_FILE_IO ); + NANOCLR_SET_AND_LEAVE(CLR_E_FILE_IO); } - else if(operationResult == FR_NO_FILE) + else if (operationResult == FR_NO_FILE) { - NANOCLR_SET_AND_LEAVE( CLR_E_FILE_NOT_FOUND ); + NANOCLR_SET_AND_LEAVE(CLR_E_FILE_NOT_FOUND); } - else if(operationResult == FR_INVALID_DRIVE) + else if (operationResult == FR_INVALID_DRIVE) { // failed to change drive NANOCLR_SET_AND_LEAVE(CLR_E_VOLUME_NOT_FOUND); @@ -327,7 +329,7 @@ HRESULT Library_win_storage_native_Windows_Storage_FileIO::WriteBytes___STATIC__ } else { - NANOCLR_SET_AND_LEAVE( CLR_E_TIMEOUT ); + NANOCLR_SET_AND_LEAVE(CLR_E_TIMEOUT); } } @@ -345,52 +347,55 @@ HRESULT Library_win_storage_native_Windows_Storage_FileIO::WriteBytes___STATIC__ NANOCLR_CLEANUP_END(); } -HRESULT Library_win_storage_native_Windows_Storage_FileIO::WriteText___STATIC__VOID__WindowsStorageIStorageFile__STRING( CLR_RT_StackFrame& stack ) +HRESULT Library_win_storage_native_Windows_Storage_FileIO::WriteText___STATIC__VOID__WindowsStorageIStorageFile__STRING( + CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); - CLR_RT_HeapBlock_String* content; - CLR_RT_HeapBlock hbTimeout; - CLR_INT64* timeout; - bool eventResult = true; + CLR_RT_HeapBlock_String *content; + CLR_RT_HeapBlock hbTimeout; + CLR_INT64 *timeout; + bool eventResult = true; - const TCHAR* filePath; - char * workingPath = NULL; - FILE * file; - FRESULT operationResult; + const TCHAR *filePath; + char *workingPath = NULL; + FILE *file; + FRESULT operationResult; // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); - + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + // get a pointer to the content content = stack.Arg1().DereferenceString(); // get a pointer to the file path - filePath = (TCHAR*)pThis[ StorageFile::FIELD___path ].DereferenceString()->StringText(); + filePath = (TCHAR *)pThis[StorageFile::FIELD___path].DereferenceString()->StringText(); // !! need to cast to CLR_INT64 otherwise it wont setup a proper timeout infinite hbTimeout.SetInteger((CLR_INT64)-1); - NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks( hbTimeout, timeout )); - - if(stack.m_customState == 1) - { + NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks(hbTimeout, timeout)); + + if (stack.m_customState == 1) + { // open file (which is supposed to already exist) // need to use FA_OPEN_ALWAYS("w+") because we are writting the file content from start workingPath = ConvertToESP32Path(filePath); - file = fopen(workingPath, "w+" ); - if(file == NULL) + file = fopen(workingPath, "w+"); + if (file == NULL) { NANOCLR_SET_AND_LEAVE(CLR_E_FILE_NOT_FOUND); } else { // protect the StorageFile and the content buffer from GC so the working thread can access those - CLR_RT_ProtectFromGC gcStorageFile( *pThis ); - CLR_RT_ProtectFromGC gcContent( *content ); + CLR_RT_ProtectFromGC gcStorageFile(*pThis); + CLR_RT_ProtectFromGC gcContent(*content); - if (SendIOtoQueue(WRITE_TEXT, file, (char*)content->StringText(), hal_strlen_s(content->StringText())) == errQUEUE_FULL) + if (SendIOtoQueue(WRITE_TEXT, file, (char *)content->StringText(), hal_strlen_s(content->StringText())) == + errQUEUE_FULL) { NANOCLR_SET_AND_LEAVE(CLR_E_PROCESS_EXCEPTION); } @@ -400,25 +405,26 @@ HRESULT Library_win_storage_native_Windows_Storage_FileIO::WriteText___STATIC__V } } - while(eventResult) + while (eventResult) { // non-blocking wait allowing other threads to run while we wait for the write operation to complete - NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.WaitEvents( stack.m_owningThread, *timeout, CLR_RT_ExecutionEngine::c_Event_StorageIo, eventResult )); + NANOCLR_CHECK_HRESULT( + g_CLR_RT_ExecutionEngine.WaitEvents(stack.m_owningThread, *timeout, Event_StorageIo, eventResult)); - if(eventResult) + if (eventResult) { // event occurred operationResult = WaitIOResult(); - if(operationResult == FR_DISK_ERR) + if (operationResult == FR_DISK_ERR) { - NANOCLR_SET_AND_LEAVE( CLR_E_FILE_IO ); + NANOCLR_SET_AND_LEAVE(CLR_E_FILE_IO); } - else if(operationResult == FR_NO_FILE) + else if (operationResult == FR_NO_FILE) { - NANOCLR_SET_AND_LEAVE( CLR_E_FILE_NOT_FOUND ); + NANOCLR_SET_AND_LEAVE(CLR_E_FILE_NOT_FOUND); } - else if(operationResult == FR_INVALID_DRIVE) + else if (operationResult == FR_INVALID_DRIVE) { // failed to change drive NANOCLR_SET_AND_LEAVE(CLR_E_VOLUME_NOT_FOUND); @@ -429,7 +435,7 @@ HRESULT Library_win_storage_native_Windows_Storage_FileIO::WriteText___STATIC__V } else { - NANOCLR_SET_AND_LEAVE( CLR_E_TIMEOUT ); + NANOCLR_SET_AND_LEAVE(CLR_E_TIMEOUT); } } @@ -444,45 +450,47 @@ HRESULT Library_win_storage_native_Windows_Storage_FileIO::WriteText___STATIC__V platform_free(workingPath); } - NANOCLR_CLEANUP_END(); + NANOCLR_CLEANUP_END(); } -HRESULT Library_win_storage_native_Windows_Storage_FileIO::ReadBufferNative___STATIC__VOID__WindowsStorageIStorageFile__BYREF_SZARRAY_U1( CLR_RT_StackFrame& stack ) +HRESULT Library_win_storage_native_Windows_Storage_FileIO:: + ReadBufferNative___STATIC__VOID__WindowsStorageIStorageFile__BYREF_SZARRAY_U1(CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); - - CLR_RT_HeapBlock hbTimeout; - CLR_INT64* timeout; - bool eventResult = true; - const TCHAR* filePath; - char * workingPath = NULL; + CLR_RT_HeapBlock hbTimeout; + CLR_INT64 *timeout; + bool eventResult = true; - FILE* file; - struct stat fileStat; - FRESULT operationResult; + const TCHAR *filePath; + char *workingPath = NULL; + + FILE *file; + struct stat fileStat; + FRESULT operationResult; // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); // !! need to cast to CLR_INT64 otherwise it wont setup a proper timeout infinite hbTimeout.SetInteger((CLR_INT64)-1); - NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks( hbTimeout, timeout )); + NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks(hbTimeout, timeout)); // get a pointer to the file path - filePath = (TCHAR*)pThis[ StorageFile::FIELD___path ].DereferenceString()->StringText(); - - if(stack.m_customState == 1) + filePath = (TCHAR *)pThis[StorageFile::FIELD___path].DereferenceString()->StringText(); + + if (stack.m_customState == 1) { // protect the StorageFile from GC - CLR_RT_ProtectFromGC gcStorageFile( *pThis ); + CLR_RT_ProtectFromGC gcStorageFile(*pThis); // open file (which is supposed to already exist) // need to use FA_OPEN_EXISTING("r") because we are reading an existing file content from start workingPath = ConvertToESP32Path(filePath); file = fopen(workingPath, "r"); - if(file == NULL) + if (file == NULL) { NANOCLR_SET_AND_LEAVE(CLR_E_FILE_NOT_FOUND); } @@ -492,47 +500,55 @@ HRESULT Library_win_storage_native_Windows_Storage_FileIO::ReadBufferNative___ST stat(workingPath, &fileStat); CLR_RT_HeapBlock buffer; - buffer.SetObjectReference( NULL ); - CLR_RT_ProtectFromGC gc2( buffer ); + buffer.SetObjectReference(NULL); + CLR_RT_ProtectFromGC gc2(buffer); // create a new byte array with the appropriate size (and type) - NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_Array::CreateInstance(buffer, (CLR_INT32)fileStat.st_size, g_CLR_RT_WellKnownTypes.m_UInt8)); + NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_Array::CreateInstance( + buffer, + (CLR_INT32)fileStat.st_size, + g_CLR_RT_WellKnownTypes.m_UInt8)); // store this to the argument passed byref - NANOCLR_CHECK_HRESULT(buffer.StoreToReference( stack.Arg1(), 0 )); + NANOCLR_CHECK_HRESULT(buffer.StoreToReference(stack.Arg1(), 0)); // get a pointer to the buffer array to improve readability on the code ahead - CLR_RT_HeapBlock_Array* bufferArray = buffer.DereferenceArray(); + CLR_RT_HeapBlock_Array *bufferArray = buffer.DereferenceArray(); - if (SendIOtoQueue(READ_BINARY, file, (char*)bufferArray->GetFirstElement(), bufferArray->m_numOfElements) == errQUEUE_FULL) + if (SendIOtoQueue( + READ_BINARY, + file, + (char *)bufferArray->GetFirstElement(), + bufferArray->m_numOfElements) == errQUEUE_FULL) { NANOCLR_SET_AND_LEAVE(CLR_E_PROCESS_EXCEPTION); } - + // bump custom state stack.m_customState = 2; } } - while(eventResult) + while (eventResult) { // non-blocking wait allowing other threads to run while we wait for the write operation to complete - NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.WaitEvents( stack.m_owningThread, *timeout, CLR_RT_ExecutionEngine::c_Event_StorageIo, eventResult )); + NANOCLR_CHECK_HRESULT( + g_CLR_RT_ExecutionEngine.WaitEvents(stack.m_owningThread, *timeout, Event_StorageIo, eventResult)); - if(eventResult) + if (eventResult) { // event occurred operationResult = WaitIOResult(); - - if(operationResult == FR_DISK_ERR) + + if (operationResult == FR_DISK_ERR) { - NANOCLR_SET_AND_LEAVE( CLR_E_FILE_IO ); + NANOCLR_SET_AND_LEAVE(CLR_E_FILE_IO); } - else if(operationResult == FR_NO_FILE) + else if (operationResult == FR_NO_FILE) { - NANOCLR_SET_AND_LEAVE( CLR_E_FILE_NOT_FOUND ); + NANOCLR_SET_AND_LEAVE(CLR_E_FILE_NOT_FOUND); } - else if(operationResult == FR_INVALID_DRIVE) + else if (operationResult == FR_INVALID_DRIVE) { // failed to change drive NANOCLR_SET_AND_LEAVE(CLR_E_VOLUME_NOT_FOUND); @@ -543,7 +559,7 @@ HRESULT Library_win_storage_native_Windows_Storage_FileIO::ReadBufferNative___ST } else { - NANOCLR_SET_AND_LEAVE( CLR_E_TIMEOUT ); + NANOCLR_SET_AND_LEAVE(CLR_E_TIMEOUT); } } @@ -561,42 +577,44 @@ HRESULT Library_win_storage_native_Windows_Storage_FileIO::ReadBufferNative___ST NANOCLR_CLEANUP_END(); } -HRESULT Library_win_storage_native_Windows_Storage_FileIO::ReadTextNative___STATIC__VOID__WindowsStorageIStorageFile__BYREF_STRING( CLR_RT_StackFrame& stack ) +HRESULT Library_win_storage_native_Windows_Storage_FileIO:: + ReadTextNative___STATIC__VOID__WindowsStorageIStorageFile__BYREF_STRING(CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); - CLR_RT_HeapBlock hbTimeout; - CLR_INT64* timeout; - bool eventResult = true; + CLR_RT_HeapBlock hbTimeout; + CLR_INT64 *timeout; + bool eventResult = true; - const TCHAR* filePath; - char * workingPath = NULL; + const TCHAR *filePath; + char *workingPath = NULL; - FILE * file; - struct stat fileStat; - FRESULT operationResult; + FILE *file; + struct stat fileStat; + FRESULT operationResult; // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); // !! need to cast to CLR_INT64 otherwise it wont setup a proper timeout infinite hbTimeout.SetInteger((CLR_INT64)-1); - NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks( hbTimeout, timeout )); + NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks(hbTimeout, timeout)); // get a pointer to the file path - filePath = (TCHAR*)pThis[ StorageFile::FIELD___path ].DereferenceString()->StringText(); - - if(stack.m_customState == 1) + filePath = (TCHAR *)pThis[StorageFile::FIELD___path].DereferenceString()->StringText(); + + if (stack.m_customState == 1) { // protect the StorageFile and the content buffer from GC so the working thread can access those - CLR_RT_ProtectFromGC gcStorageFile( *pThis ); + CLR_RT_ProtectFromGC gcStorageFile(*pThis); // open file (which is supposed to already exist) // need to use FA_OPEN_EXISTING("r") because we are reading an existing file content from start workingPath = ConvertToESP32Path(filePath); file = fopen(workingPath, "r"); - if(file == NULL) + if (file == NULL) { NANOCLR_SET_AND_LEAVE(CLR_E_FILE_NOT_FOUND); } @@ -606,20 +624,21 @@ HRESULT Library_win_storage_native_Windows_Storage_FileIO::ReadTextNative___STAT stat(workingPath, &fileStat); // create a new string object with the appropriate size - CLR_RT_HeapBlock hbText; - hbText.SetObjectReference( NULL ); - CLR_RT_ProtectFromGC gc( hbText ); + CLR_RT_HeapBlock hbText; + hbText.SetObjectReference(NULL); + CLR_RT_ProtectFromGC gc(hbText); - CLR_RT_HeapBlock_String* textString = CLR_RT_HeapBlock_String::CreateInstance( hbText, (CLR_UINT32)fileStat.st_size ); + CLR_RT_HeapBlock_String *textString = + CLR_RT_HeapBlock_String::CreateInstance(hbText, (CLR_UINT32)fileStat.st_size); FAULT_ON_NULL(textString); // store this to the argument passed byref - NANOCLR_CHECK_HRESULT(hbText.StoreToReference( stack.Arg1(), 0 )); + NANOCLR_CHECK_HRESULT(hbText.StoreToReference(stack.Arg1(), 0)); // get a pointer to the buffer array to improve readability on the code ahead hbText.DereferenceString(); - if ( SendIOtoQueue(READ_TEXT, file, (char*)textString->StringText(), fileStat.st_size) == errQUEUE_FULL) + if (SendIOtoQueue(READ_TEXT, file, (char *)textString->StringText(), fileStat.st_size) == errQUEUE_FULL) { NANOCLR_SET_AND_LEAVE(CLR_E_PROCESS_EXCEPTION); } @@ -629,25 +648,26 @@ HRESULT Library_win_storage_native_Windows_Storage_FileIO::ReadTextNative___STAT } } - while(eventResult) + while (eventResult) { // non-blocking wait allowing other threads to run while we wait for the write operation to complete - NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.WaitEvents( stack.m_owningThread, *timeout, CLR_RT_ExecutionEngine::c_Event_StorageIo, eventResult )); + NANOCLR_CHECK_HRESULT( + g_CLR_RT_ExecutionEngine.WaitEvents(stack.m_owningThread, *timeout, Event_StorageIo, eventResult)); - if(eventResult) + if (eventResult) { // event occurred operationResult = WaitIOResult(); - if(operationResult == FR_DISK_ERR) + if (operationResult == FR_DISK_ERR) { - NANOCLR_SET_AND_LEAVE( CLR_E_FILE_IO ); + NANOCLR_SET_AND_LEAVE(CLR_E_FILE_IO); } - else if(operationResult == FR_NO_FILE) + else if (operationResult == FR_NO_FILE) { - NANOCLR_SET_AND_LEAVE( CLR_E_FILE_NOT_FOUND ); + NANOCLR_SET_AND_LEAVE(CLR_E_FILE_NOT_FOUND); } - else if(operationResult == FR_INVALID_DRIVE) + else if (operationResult == FR_INVALID_DRIVE) { // failed to change drive NANOCLR_SET_AND_LEAVE(CLR_E_VOLUME_NOT_FOUND); @@ -658,7 +678,7 @@ HRESULT Library_win_storage_native_Windows_Storage_FileIO::ReadTextNative___STAT } else { - NANOCLR_SET_AND_LEAVE( CLR_E_TIMEOUT ); + NANOCLR_SET_AND_LEAVE(CLR_E_TIMEOUT); } } diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Storage/win_storage_native_Windows_Storage_StorageFile.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Storage/win_storage_native_Windows_Storage_StorageFile.cpp index 7ab328fb05..2018883df5 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Storage/win_storage_native_Windows_Storage_StorageFile.cpp +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Storage/win_storage_native_Windows_Storage_StorageFile.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Storage/win_storage_native_Windows_Storage_StorageFolder.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Storage/win_storage_native_Windows_Storage_StorageFolder.cpp index 754adc4e78..db665257b4 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Storage/win_storage_native_Windows_Storage_StorageFolder.cpp +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Storage/win_storage_native_Windows_Storage_StorageFolder.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Storage/win_storage_native_target.h b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Storage/win_storage_native_target.h index ed4998bf62..633a42827d 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Storage/win_storage_native_target.h +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Storage/win_storage_native_target.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/WireProtocol_App_Interface.c b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/WireProtocol_App_Interface.c index 327686c373..607a88a220 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/WireProtocol_App_Interface.c +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/WireProtocol_App_Interface.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/WireProtocol_MonitorCommands.c b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/WireProtocol_MonitorCommands.c index 3a3646b0ff..c7a76457c3 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/WireProtocol_MonitorCommands.c +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/WireProtocol_MonitorCommands.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/app_main.c b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/app_main.c index 65d746a836..38a2f65161 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/app_main.c +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/app_main.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/mbedtls_entropy_hardware_pool.c b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/mbedtls_entropy_hardware_pool.c index 542b3ddb03..0111f8499e 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/mbedtls_entropy_hardware_pool.c +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/mbedtls_entropy_hardware_pool.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoCRT.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoCRT.cpp index 2a78021843..26a978187f 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoCRT.cpp +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoCRT.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoFramework.Devices.OneWire/nf_devices_onewire_native_nanoFramework_Devices_OneWire_OneWireController.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoFramework.Devices.OneWire/nf_devices_onewire_native_nanoFramework_Devices_OneWire_OneWireController.cpp index 1e8bb710ac..960e85fedd 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoFramework.Devices.OneWire/nf_devices_onewire_native_nanoFramework_Devices_OneWire_OneWireController.cpp +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoFramework.Devices.OneWire/nf_devices_onewire_native_nanoFramework_Devices_OneWire_OneWireController.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoFramework.Devices.OneWire/nf_devices_onewire_native_target.h b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoFramework.Devices.OneWire/nf_devices_onewire_native_target.h index c2979ffa32..69c0c751e3 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoFramework.Devices.OneWire/nf_devices_onewire_native_target.h +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoFramework.Devices.OneWire/nf_devices_onewire_native_target.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoFramework.Hardware.ESP32/nanoFramework_hardware_esp32_native.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoFramework.Hardware.ESP32/nanoFramework_hardware_esp32_native.cpp index 310e635f9e..09e293231d 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoFramework.Hardware.ESP32/nanoFramework_hardware_esp32_native.cpp +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoFramework.Hardware.ESP32/nanoFramework_hardware_esp32_native.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoFramework.Hardware.ESP32/nanoFramework_hardware_esp32_native.h b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoFramework.Hardware.ESP32/nanoFramework_hardware_esp32_native.h index 534b775677..b4ae0cff28 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoFramework.Hardware.ESP32/nanoFramework_hardware_esp32_native.h +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoFramework.Hardware.ESP32/nanoFramework_hardware_esp32_native.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoFramework.Hardware.ESP32/nanoFramework_hardware_esp32_native_Hardware_Esp32_Configuration.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoFramework.Hardware.ESP32/nanoFramework_hardware_esp32_native_Hardware_Esp32_Configuration.cpp index df996b8b2f..0b7149c699 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoFramework.Hardware.ESP32/nanoFramework_hardware_esp32_native_Hardware_Esp32_Configuration.cpp +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoFramework.Hardware.ESP32/nanoFramework_hardware_esp32_native_Hardware_Esp32_Configuration.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoFramework.Hardware.ESP32/nanoFramework_hardware_esp32_native_Hardware_Esp32_HighResTimer.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoFramework.Hardware.ESP32/nanoFramework_hardware_esp32_native_Hardware_Esp32_HighResTimer.cpp index c13242f9f2..1f6aef0fa1 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoFramework.Hardware.ESP32/nanoFramework_hardware_esp32_native_Hardware_Esp32_HighResTimer.cpp +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoFramework.Hardware.ESP32/nanoFramework_hardware_esp32_native_Hardware_Esp32_HighResTimer.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoFramework.Hardware.ESP32/nanoFramework_hardware_esp32_native_Hardware_Esp32_Logging.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoFramework.Hardware.ESP32/nanoFramework_hardware_esp32_native_Hardware_Esp32_Logging.cpp index ccb48919cf..36ae8432b8 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoFramework.Hardware.ESP32/nanoFramework_hardware_esp32_native_Hardware_Esp32_Logging.cpp +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoFramework.Hardware.ESP32/nanoFramework_hardware_esp32_native_Hardware_Esp32_Logging.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoFramework.Hardware.ESP32/nanoFramework_hardware_esp32_native_Hardware_Esp32_Sleep.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoFramework.Hardware.ESP32/nanoFramework_hardware_esp32_native_Hardware_Esp32_Sleep.cpp index ceffe368fe..f2077e8528 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoFramework.Hardware.ESP32/nanoFramework_hardware_esp32_native_Hardware_Esp32_Sleep.cpp +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoFramework.Hardware.ESP32/nanoFramework_hardware_esp32_native_Hardware_Esp32_Sleep.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoFramework.Hardware.Esp32.Rmt/nanoFramework_hardware_esp32_rmt_native.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoFramework.Hardware.Esp32.Rmt/nanoFramework_hardware_esp32_rmt_native.cpp new file mode 100644 index 0000000000..dc9836add9 --- /dev/null +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoFramework.Hardware.Esp32.Rmt/nanoFramework_hardware_esp32_rmt_native.cpp @@ -0,0 +1,102 @@ +// +// Copyright (c) .NET Foundation and Contributors +// See LICENSE file in the project root for full license information. +// + +#include "nanoFramework_hardware_esp32_rmt_native.h" + +static const CLR_RT_MethodHandler method_lookup[] = { + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + Library_nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_ReceiverChannel:: + NativeRxInit___I4__I4__I4, + Library_nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_ReceiverChannel:: + NativeRxStart___VOID__BOOLEAN, + Library_nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_ReceiverChannel:: + NativeRxStop___VOID, + Library_nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_ReceiverChannel:: + NativeRxGetRingBufferCount___I4, + Library_nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_ReceiverChannel:: + NativeRxGetAllItems___SZARRAY_nanoFrameworkHardwareEsp32RmtRmtCommand, + Library_nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_ReceiverChannel:: + NativeRxEnableFilter___VOID__BOOLEAN__U1, + Library_nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_ReceiverChannel:: + NativeRxSetIdleThresold___VOID__U2, + Library_nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_ReceiverChannel:: + NativeRxDispose___VOID, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + Library_nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_RmtChannel:: + NativeSetClockDivider___VOID__U1, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + Library_nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_TransmitterChannel:: + NativeInit___VOID__I4, + Library_nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_TransmitterChannel:: + NativeGetIdleLevel___BOOLEAN, + Library_nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_TransmitterChannel:: + NativeGetIsChannelIdle___BOOLEAN, + Library_nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_TransmitterChannel:: + NativeSetIsChannelIdle___VOID__BOOLEAN, + Library_nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_TransmitterChannel:: + NativeSetIdleLevel___VOID__BOOLEAN, + Library_nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_TransmitterChannel:: + NativeSetCarrierMode___VOID, + Library_nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_TransmitterChannel:: + NativeWriteItems___U4__SZARRAY_U1__BOOLEAN, + Library_nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_TransmitterChannel:: + NativeWaitTxDone___U4__I4, + Library_nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_TransmitterChannel:: + NativeDispose___VOID, + Library_nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_TransmitterChannel:: + NativeGetSourceClock___BOOLEAN, +}; + +const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_nanoFramework_Hardware_Esp32_Rmt = + {"nanoFramework.Hardware.Esp32.Rmt", 0x9A53BB44, method_lookup, {100, 0, 3, 0}}; diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoFramework.Hardware.Esp32.Rmt/nanoFramework_hardware_esp32_rmt_native.h b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoFramework.Hardware.Esp32.Rmt/nanoFramework_hardware_esp32_rmt_native.h new file mode 100644 index 0000000000..6835bc4ae2 --- /dev/null +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoFramework.Hardware.Esp32.Rmt/nanoFramework_hardware_esp32_rmt_native.h @@ -0,0 +1,110 @@ +// +// Copyright (c) .NET Foundation and Contributors +// See LICENSE file in the project root for full license information. +// + +#ifndef _NANOFRAMEWORK_HARDWARE_ESP32_RMT_NATIVE_H_ +#define _NANOFRAMEWORK_HARDWARE_ESP32_RMT_NATIVE_H_ + +#include +#include + +#include +#include +#include +#include + +#include + +// Reduce line lengths +#define ManagedRmtCommand Library_nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_RmtCommand +#define RmtChannel Library_nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_RmtChannel +#define CHANNEL(channel) static_cast(channel) + +typedef enum __nfpack SourceClock +{ + SourceClock_APB = 0, + SourceClock_REF = 1, +} SourceClock; + +struct Library_nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_RmtCommand +{ + static const int FIELD___level0 = 1; + static const int FIELD___level1 = 2; + static const int FIELD___duration0 = 3; + static const int FIELD___duration1 = 4; + + //--// +}; + +struct Library_nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_ReceiverChannel +{ + static const int FIELD___receiveTimeout = 4; + + NANOCLR_NATIVE_DECLARE(NativeRxInit___I4__I4__I4); + NANOCLR_NATIVE_DECLARE(NativeRxStart___VOID__BOOLEAN); + NANOCLR_NATIVE_DECLARE(NativeRxStop___VOID); + NANOCLR_NATIVE_DECLARE(NativeRxGetRingBufferCount___I4); + NANOCLR_NATIVE_DECLARE(NativeRxGetAllItems___SZARRAY_nanoFrameworkHardwareEsp32RmtRmtCommand); + NANOCLR_NATIVE_DECLARE(NativeRxEnableFilter___VOID__BOOLEAN__U1); + NANOCLR_NATIVE_DECLARE(NativeRxSetIdleThresold___VOID__U2); + NANOCLR_NATIVE_DECLARE(NativeRxDispose___VOID); + + //--// + + static HRESULT CreateRmtArrayOnStack( + CLR_RT_StackFrame &stack, + CLR_INT32 numItems, + CLR_RT_TypeDef_Index &rmtCommandTypeDef, + CLR_RT_HeapBlock **arrayDataPtr); + static HRESULT CreateRmtElement( + rmt_item32_t *rmtItem, + CLR_RT_HeapBlock *returnArray, + CLR_RT_TypeDef_Index &rmtCommandTypeDef); + + static esp_err_t InitRxChannel(rmt_channel_t channel, gpio_num_t gpio, int32_t rmtBufferSize, int32_t clockDiv); +}; + +struct Library_nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_RmtChannel +{ + static const int FIELD___channel = 1; + static const int FIELD___clockDivider = 2; + static const int FIELD___sourceClock = 3; + + NANOCLR_NATIVE_DECLARE(NativeSetClockDivider___VOID__U1); + + //--// + + static std::map> registredChannels; + + static bool CheckChannel(int channel); + static CLR_INT32 FindNextChannel(); +}; + +struct Library_nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_TransmitterChannel +{ + static const int FIELD___carrierEnabled = 4; + static const int FIELD___carrierHighDuration = 5; + static const int FIELD___carrierLowDuration = 6; + static const int FIELD___carrierLevel = 7; + static const int FIELD___commands = 8; + + NANOCLR_NATIVE_DECLARE(NativeInit___VOID__I4); + NANOCLR_NATIVE_DECLARE(NativeGetIdleLevel___BOOLEAN); + NANOCLR_NATIVE_DECLARE(NativeGetIsChannelIdle___BOOLEAN); + NANOCLR_NATIVE_DECLARE(NativeSetIsChannelIdle___VOID__BOOLEAN); + NANOCLR_NATIVE_DECLARE(NativeSetIdleLevel___VOID__BOOLEAN); + NANOCLR_NATIVE_DECLARE(NativeSetCarrierMode___VOID); + NANOCLR_NATIVE_DECLARE(NativeWriteItems___U4__SZARRAY_U1__BOOLEAN); + NANOCLR_NATIVE_DECLARE(NativeWaitTxDone___U4__I4); + NANOCLR_NATIVE_DECLARE(NativeDispose___VOID); + NANOCLR_NATIVE_DECLARE(NativeGetSourceClock___BOOLEAN); + + //--// + + static esp_err_t InitTxChannel(rmt_channel_t channel, gpio_num_t gpio); +}; + +extern const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_nanoFramework_Hardware_Esp32_Rmt; + +#endif //_NANOFRAMEWORK_HARDWARE_ESP32_RMT_NATIVE_H_ diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoFramework.Hardware.Esp32.Rmt/nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_ReceiverChannel.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoFramework.Hardware.Esp32.Rmt/nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_ReceiverChannel.cpp new file mode 100644 index 0000000000..786bfdc972 --- /dev/null +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoFramework.Hardware.Esp32.Rmt/nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_ReceiverChannel.cpp @@ -0,0 +1,354 @@ +// +// Copyright (c) 2020 The nanoFramework project contributors +// See LICENSE file in the project root for full license information. +// + +#include "nanoFramework_hardware_esp32_rmt_native.h" + +HRESULT Library_nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_ReceiverChannel:: + NativeRxInit___I4__I4__I4(CLR_RT_StackFrame &stack) +{ + NANOCLR_HEADER(); + + gpio_num_t gpio_number; + CLR_INT32 channel; + CLR_INT32 bufferSizeRmtItems; + CLR_INT32 clockDiv = 80; // Default + gpio_number = (gpio_num_t)stack.Arg1().NumericByRef().s1; + bufferSizeRmtItems = (CLR_INT32)stack.Arg2().NumericByRef().s1; + + channel = RmtChannel::FindNextChannel(); + if (channel < 0) + { + NANOCLR_SET_AND_LEAVE(CLR_E_DRIVER_NOT_REGISTERED); + } + + if (InitRxChannel((rmt_channel_t)channel, gpio_number, bufferSizeRmtItems, clockDiv) != ESP_OK) + { + NANOCLR_SET_AND_LEAVE(CLR_E_DRIVER_NOT_REGISTERED); + } + + stack.SetResult_I4(channel); + + NANOCLR_NOCLEANUP(); +} + +HRESULT Library_nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_ReceiverChannel:: + NativeRxStart___VOID__BOOLEAN(CLR_RT_StackFrame &stack) +{ + NANOCLR_HEADER(); + { + CLR_INT32 channel; + bool clearBuffer; + + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + + clearBuffer = stack.Arg1().NumericByRefConst().u1 != 0; + + channel = pThis[RmtChannel::FIELD___channel].NumericByRef().s4; + + if (clearBuffer) + { + RingbufHandle_t ringbufHandle; + auto err = rmt_get_ringbuf_handle((rmt_channel_t)channel, &ringbufHandle); + if (err != ESP_OK) + { + NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); + } + + // Clear ring buffer + size_t length = 0; + rmt_item32_t *rmtItems; + while ((rmtItems = (rmt_item32_t *)xRingbufferReceive(ringbufHandle, &length, 0)) != NULL) + { + // Release items back to Ringbuffer + vRingbufferReturnItem(ringbufHandle, (void *)rmtItems); + }; + } + + auto err = rmt_rx_start((rmt_channel_t)channel, clearBuffer); + if (err != ESP_OK) + { + NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_OPERATION); + } + } + NANOCLR_NOCLEANUP(); +} + +HRESULT Library_nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_ReceiverChannel:: + NativeRxStop___VOID(CLR_RT_StackFrame &stack) +{ + NANOCLR_HEADER(); + { + CLR_INT32 channel; + + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + + channel = pThis[RmtChannel::FIELD___channel].NumericByRef().s4; + + auto err = rmt_rx_stop((rmt_channel_t)channel); + if (err != ESP_OK) + { + NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_OPERATION); + } + } + NANOCLR_NOCLEANUP(); +} + +HRESULT Library_nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_ReceiverChannel:: + NativeRxGetRingBufferCount___I4(CLR_RT_StackFrame &stack) +{ + NANOCLR_HEADER(); + { + CLR_INT32 channel; + esp_err_t err; + RingbufHandle_t ringbufHandle; + + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + + channel = pThis[RmtChannel::FIELD___channel].NumericByRef().s4; + + err = rmt_get_ringbuf_handle((rmt_channel_t)channel, &ringbufHandle); + if (err != ESP_OK) + { + NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); + } + + UBaseType_t uxItemsWaiting; + vRingbufferGetInfo(ringbufHandle, NULL, NULL, NULL, &uxItemsWaiting); + + stack.SetResult_I4(uxItemsWaiting); + } + NANOCLR_NOCLEANUP(); +} + +HRESULT Library_nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_ReceiverChannel:: + CreateRmtElement(rmt_item32_t *rmtItem, CLR_RT_HeapBlock *returnArray, CLR_RT_TypeDef_Index &rmtCommandTypeDef) +{ + NANOCLR_HEADER(); + { + // create a new RmtCommand object and put it on the return array + NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.NewObjectFromIndex(*returnArray, rmtCommandTypeDef)); + + // Set each value in the struct from the rmt_item32_t data + CLR_RT_HeapBlock *dref = returnArray->Dereference(); + CLR_RT_HeapBlock &duration0FieldRef = dref[ManagedRmtCommand::FIELD___duration0]; + CLR_RT_HeapBlock &level0FieldRef = dref[ManagedRmtCommand::FIELD___level0]; + CLR_RT_HeapBlock &duration1FieldRef = dref[ManagedRmtCommand::FIELD___duration1]; + CLR_RT_HeapBlock &level1FieldRef = dref[ManagedRmtCommand::FIELD___level1]; + + int32_t *d0 = (int32_t *)&duration0FieldRef.NumericByRef().s4; + *d0 = rmtItem->duration0; + + int32_t *l0 = (int32_t *)&level0FieldRef.NumericByRef().u1; + *l0 = rmtItem->level0; + + int32_t *d1 = (int32_t *)&duration1FieldRef.NumericByRef().s4; + *d1 = rmtItem->duration1; + + int32_t *l1 = (int32_t *)&level1FieldRef.NumericByRef().u1; + *l1 = rmtItem->level1; + } + NANOCLR_NOCLEANUP(); +} + +HRESULT Library_nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_ReceiverChannel:: + CreateRmtArrayOnStack( + CLR_RT_StackFrame &stack, + CLR_INT32 numItems, + CLR_RT_TypeDef_Index &rmtCommandTypeDef, + CLR_RT_HeapBlock **arrayDataPtr) +{ + NANOCLR_HEADER(); + { + if (!g_CLR_RT_TypeSystem.FindTypeDef("RmtCommand", "nanoFramework.Hardware.Esp32.Rmt", rmtCommandTypeDef)) + { + // Type not defined, build problem + NANOCLR_SET_AND_LEAVE(CLR_E_NOT_SUPPORTED); + } + + // Create Array on top of stackof type "RmtCommand" + NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_Array::CreateInstance( + stack.PushValue(), + numItems, + rmtCommandTypeDef)); // g_CLR_RT_WellKnownTypes.m_Object )); + + // Get reference to Array + CLR_RT_HeapBlock_Array *array = stack.TopValue().DereferenceArray(); + + // Get start of array data, array of CLR_RT_HeapBlock * to RmtCommand structs + *arrayDataPtr = (CLR_RT_HeapBlock *)array->GetFirstElement(); + } + NANOCLR_NOCLEANUP(); +} + +HRESULT Library_nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_ReceiverChannel:: + NativeRxGetAllItems___SZARRAY_nanoFrameworkHardwareEsp32RmtRmtCommand(CLR_RT_StackFrame &stack) +{ + NANOCLR_HEADER(); + { + CLR_INT32 channel; + // CLR_RT_HeapBlock *pRetVal = NULL; + esp_err_t err; + RingbufHandle_t ringbufHandle; + CLR_INT32 waitMs; + rmt_item32_t *rmtItems = NULL; + + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + + channel = pThis[RmtChannel::FIELD___channel].NumericByRef().s4; + + err = rmt_get_ringbuf_handle((rmt_channel_t)channel, &ringbufHandle); + if (err != ESP_OK) + { + NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); + } + + // Timespan in 100ns ticks + CLR_INT64 *timespan = Library_corlib_native_System_TimeSpan::GetValuePtr(pThis[FIELD___receiveTimeout]); + // Convert to milli-secs for wait + waitMs = (CLR_INT32)(*timespan / TIME_CONVERSION__TO_MILLISECONDS); + + // Get next Rmt item from ring buffer + size_t length = 0; + rmtItems = (rmt_item32_t *)xRingbufferReceive(ringbufHandle, &length, pdMS_TO_TICKS(waitMs)); + if (rmtItems) + { + if (length > 0) + { + CLR_RT_HeapBlock *arrayDataPtr; + CLR_RT_TypeDef_Index rmtCommandTypeDef; + + int numItems = length / sizeof(rmt_item32_t); + + // Build Header block for Array of RmtCommands objects on top of stack + // Returns the rmtCommand type and pointer to first data ptr in array + NANOCLR_CHECK_HRESULT(CreateRmtArrayOnStack(stack, numItems, rmtCommandTypeDef, &arrayDataPtr)); + + rmt_item32_t *pData = rmtItems; + while (numItems-- > 0) + { + // Add RMT item to managed array + NANOCLR_CHECK_HRESULT(CreateRmtElement(pData, arrayDataPtr, rmtCommandTypeDef)); + + // Next item + pData++; + arrayDataPtr++; + } + } + + // Release items back to Ringbuffer + vRingbufferReturnItem(ringbufHandle, (void *)rmtItems); + } + + if (length == 0) + { + stack.SetResult_Object(NULL); + } + } + NANOCLR_NOCLEANUP(); +} + +HRESULT Library_nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_ReceiverChannel:: + NativeRxEnableFilter___VOID__BOOLEAN__U1(CLR_RT_StackFrame &stack) +{ + NANOCLR_HEADER(); + { + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + + bool enableFilter = stack.Arg1().NumericByRefConst().u1 != 0; + uint8_t threshold = stack.Arg2().NumericByRefConst().u1; + + CLR_INT32 channel = pThis[RmtChannel::FIELD___channel].NumericByRef().s4; + + esp_err_t err = rmt_set_rx_filter((rmt_channel_t)channel, enableFilter, threshold); + if (err != ESP_OK) + { + NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_OPERATION); + } + } + NANOCLR_NOCLEANUP(); +} + +HRESULT Library_nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_ReceiverChannel:: + NativeRxSetIdleThresold___VOID__U2(CLR_RT_StackFrame &stack) +{ + NANOCLR_HEADER(); + { + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + + uint16_t threshold = stack.Arg1().NumericByRefConst().u2; + + CLR_INT32 channel = pThis[RmtChannel::FIELD___channel].NumericByRef().s4; + + esp_err_t err = rmt_set_rx_idle_thresh((rmt_channel_t)channel, threshold); + if (err != ESP_OK) + { + NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); + } + } + NANOCLR_NOCLEANUP(); +} + +HRESULT Library_nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_ReceiverChannel:: + NativeRxDispose___VOID(CLR_RT_StackFrame &stack) +{ + NANOCLR_HEADER(); + { + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + + CLR_INT32 channel = pThis[RmtChannel::FIELD___channel].NumericByRef().s4; + + if (RmtChannel::registredChannels.find((rmt_channel_t)channel) == RmtChannel::registredChannels.end()) + { + NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); + } + + if (rmt_driver_uninstall((rmt_channel_t)channel) != ESP_OK) + { + hr = CLR_E_PROCESS_EXCEPTION; + } + + RmtChannel::registredChannels.erase((rmt_channel_t)channel); + } + NANOCLR_NOCLEANUP(); +} + +esp_err_t Library_nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_ReceiverChannel:: + InitRxChannel(rmt_channel_t channel, gpio_num_t gpio, int32_t bufferSizeRmtItems, int32_t clockDiv) +{ + rmt_config_t rmt_rxconfig{}; + + rmt_rxconfig.rmt_mode = RMT_MODE_RX; // Channel mode + rmt_rxconfig.channel = channel; // Channel + rmt_rxconfig.clk_div = clockDiv; // Channel counter divider + // 80,000,000 / 80 = 1,000,000 or 1us tick + rmt_rxconfig.gpio_num = gpio; // GPIO number + rmt_rxconfig.mem_block_num = 1; // number of memory blocks + + rmt_rxconfig.rx_config.filter_en = false; // No filter or theshold + rmt_rxconfig.rx_config.filter_ticks_thresh = 0; + rmt_rxconfig.rx_config.idle_threshold = 0; + auto err = rmt_config(&rmt_rxconfig); + if (err != ESP_OK) + return err; + + int32_t ringBufferSize = bufferSizeRmtItems * sizeof(rmt_item32_t); + err = rmt_driver_install(channel, ringBufferSize, 0); + if (err != ESP_OK) + return err; + + RmtChannel::registredChannels.emplace( + std::piecewise_construct, + std::forward_as_tuple(channel), + std::forward_as_tuple()); + + return ESP_OK; +} \ No newline at end of file diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoFramework.Hardware.Esp32.Rmt/nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_RmtChannel.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoFramework.Hardware.Esp32.Rmt/nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_RmtChannel.cpp new file mode 100644 index 0000000000..a5576e14c4 --- /dev/null +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoFramework.Hardware.Esp32.Rmt/nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_RmtChannel.cpp @@ -0,0 +1,62 @@ +// +// Copyright (c) 2020 The nanoFramework project contributors +// See LICENSE file in the project root for full license information. +// + +#include "nanoFramework_hardware_esp32_rmt_native.h" + +std::map> + Library_nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_RmtChannel::registredChannels; + +HRESULT Library_nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_RmtChannel:: + NativeSetClockDivider___VOID__U1(CLR_RT_StackFrame &stack) +{ + NANOCLR_HEADER(); + + int32_t channel; + uint8_t clockdiv = (uint8_t)stack.Arg1().NumericByRef().u1; + + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + + channel = (int32_t)pThis[FIELD___channel].NumericByRef().s4; + if (!CheckChannel(channel)) + { + NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); + } + + rmt_set_clk_div((rmt_channel_t)channel, clockdiv); + + NANOCLR_NOCLEANUP(); +} + +// +// Search map for next free Channel and return channel number. +// return -1 if no free channels. +// +CLR_INT32 Library_nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_RmtChannel::FindNextChannel() +{ + for (signed int channel = RMT_CHANNEL_0; channel < RMT_CHANNEL_MAX; ++channel) + { + if (registredChannels.find(CHANNEL(channel)) == registredChannels.end()) + { + return channel; + } + } + return -1; +} + +// +// Check if channel is present in map +// return true if present (valid) +// +bool Library_nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_RmtChannel::CheckChannel( + int channel) +{ + if (registredChannels.find(CHANNEL(channel)) == registredChannels.end()) + { + return false; + } + + return true; +} diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoFramework.Hardware.Esp32.Rmt/nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_TransmitterChannel.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoFramework.Hardware.Esp32.Rmt/nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_TransmitterChannel.cpp new file mode 100644 index 0000000000..0b5b6a5e86 --- /dev/null +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoFramework.Hardware.Esp32.Rmt/nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_TransmitterChannel.cpp @@ -0,0 +1,323 @@ +// +// Copyright (c) .NET Foundation and Contributors +// See LICENSE file in the project root for full license information. +// + +#include +#include "nanoFramework_hardware_esp32_rmt_native.h" + +#define DEFAULT_DIVIDER 4 + +HRESULT Library_nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_TransmitterChannel:: + NativeInit___VOID__I4(CLR_RT_StackFrame &stack) +{ + NANOCLR_HEADER(); + uint8_t gpio_number; + CLR_INT32 channel; + + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + + gpio_number = (uint8_t)stack.Arg1().NumericByRef().s1; + + channel = RmtChannel::FindNextChannel(); + + if (channel < 0) + { + hr = CLR_E_DRIVER_NOT_REGISTERED; + NANOCLR_LEAVE(); + } + + // this is always true, as we are currently only supporting this clock mode + ::RMT.conf_ch[(rmt_channel_t)channel].conf1.ref_always_on = true; + + if (InitTxChannel((rmt_channel_t)channel, (gpio_num_t)gpio_number) != ESP_OK) + { + hr = CLR_E_DRIVER_NOT_REGISTERED; + NANOCLR_LEAVE(); + } + + pThis[RmtChannel::FIELD___channel].NumericByRef().s4 = channel; + + NANOCLR_NOCLEANUP(); +} + +HRESULT Library_nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_TransmitterChannel:: + NativeGetIdleLevel___BOOLEAN(CLR_RT_StackFrame &stack) +{ + NANOCLR_HEADER(); + + int32_t channel; + bool retVal = 0; + + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + + channel = (int32_t)pThis[RmtChannel::FIELD___channel].NumericByRef().s4; + + if (!RmtChannel::CheckChannel(channel)) + { + NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); + } + + retVal = ::RMT.conf_ch[(rmt_channel_t)channel].conf1.idle_out_lv; + + stack.SetResult_Boolean(retVal); + + NANOCLR_NOCLEANUP(); +} + +HRESULT Library_nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_TransmitterChannel:: + NativeGetIsChannelIdle___BOOLEAN(CLR_RT_StackFrame &stack) +{ + NANOCLR_HEADER(); + + int32_t channel; + bool retVal = 0; + + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + + channel = (int32_t)pThis[RmtChannel::FIELD___channel].NumericByRef().s4; + + if (!RmtChannel::CheckChannel(channel)) + { + NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); + } + + retVal = ::RMT.conf_ch[(rmt_channel_t)channel].conf1.idle_out_en; + + stack.SetResult_Boolean(retVal); + + NANOCLR_NOCLEANUP(); +} + +HRESULT Library_nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_TransmitterChannel:: + NativeSetIsChannelIdle___VOID__BOOLEAN(CLR_RT_StackFrame &stack) +{ + NANOCLR_HEADER(); + + int32_t channel; + bool enabled; + + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + + channel = (int32_t)pThis[RmtChannel::FIELD___channel].NumericByRef().s4; + enabled = (bool)stack.Arg1().NumericByRef().u1; + + if (!RmtChannel::CheckChannel(channel)) + { + NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); + } + + ::RMT.conf_ch[(rmt_channel_t)channel].conf1.idle_out_en = enabled; + + NANOCLR_NOCLEANUP(); +} + +HRESULT Library_nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_TransmitterChannel:: + NativeSetIdleLevel___VOID__BOOLEAN(CLR_RT_StackFrame &stack) +{ + NANOCLR_HEADER(); + + int32_t channel; + bool idle_lvl; + + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + + channel = (int32_t)pThis[RmtChannel::FIELD___channel].NumericByRef().s4; + idle_lvl = (bool)stack.Arg1().NumericByRef().u1; + + if (!RmtChannel::CheckChannel(channel)) + { + NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); + } + + ::RMT.conf_ch[(rmt_channel_t)channel].conf1.idle_out_lv = idle_lvl; + + NANOCLR_NOCLEANUP(); +} + +HRESULT Library_nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_TransmitterChannel:: + NativeSetCarrierMode___VOID(CLR_RT_StackFrame &stack) +{ + NANOCLR_HEADER(); + + int32_t channel; + bool carier_en; + uint16_t high_lvl; + uint16_t low_level; + bool carier_lvl; + + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + + channel = (int32_t)pThis[RmtChannel::FIELD___channel].NumericByRefConst().s4; + carier_en = (bool)pThis[FIELD___carrierEnabled].NumericByRefConst().u1; + high_lvl = (uint16_t)pThis[FIELD___carrierHighDuration].NumericByRefConst().s2; + low_level = (uint16_t)pThis[FIELD___carrierLowDuration].NumericByRefConst().s2; + carier_lvl = (bool)pThis[FIELD___carrierLevel].NumericByRefConst().u1; + + if (!RmtChannel::CheckChannel(channel)) + { + NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); + } + + { + auto &ch = ::RMT.conf_ch[(rmt_channel_t)channel]; + ch.conf0.carrier_en = carier_en; + ch.conf0.carrier_out_lv = (uint32_t)carier_lvl; + auto &cdc = ::RMT.carrier_duty_ch[(rmt_channel_t)channel]; + cdc.high = high_lvl; + cdc.low = low_level; + } + + NANOCLR_NOCLEANUP(); +} + +HRESULT Library_nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_TransmitterChannel:: + NativeWriteItems___U4__SZARRAY_U1__BOOLEAN(CLR_RT_StackFrame &stack) +{ + NANOCLR_HEADER(); + + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + + { + int32_t channel = (int32_t)pThis[RmtChannel::FIELD___channel].NumericByRef().s4; + bool wait_tx_done = (bool)stack.Arg2().NumericByRef().u1; + + CLR_RT_HeapBlock_Array *data = stack.Arg1().DereferenceArray(); + char *buffer = (char *)data->GetFirstElement(); + uint32_t bufferLength = data->m_numOfElements; + + auto it = RmtChannel::registredChannels.find(CHANNEL(channel)); + if (it == RmtChannel::registredChannels.end()) + { + NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); + } + + const auto element_size = sizeof(rmt_item32_t); + if (bufferLength % element_size != 0) + { + hr = CLR_E_SERIALIZATION_VIOLATION; + NANOCLR_LEAVE(); + } + auto &d = it->second; + d.assign(bufferLength / element_size, rmt_item32_t{}); + std::memcpy(d.data(), buffer, bufferLength); + int result = rmt_write_items((rmt_channel_t)channel, d.data(), d.size(), wait_tx_done); + + stack.SetResult_U4(result); + } + + NANOCLR_NOCLEANUP(); +} + +HRESULT Library_nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_TransmitterChannel:: + NativeWaitTxDone___U4__I4(CLR_RT_StackFrame &stack) +{ + NANOCLR_HEADER(); + + int result = ESP_ERR_TIMEOUT; + + int32_t channel; + int32_t wait_time = (int32_t)stack.Arg1().NumericByRef().s4; + + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + + channel = (int32_t)pThis[RmtChannel::FIELD___channel].NumericByRef().s4; + + if (!RmtChannel::CheckChannel(channel)) + { + NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); + } + + result = rmt_wait_tx_done((rmt_channel_t)channel, wait_time); + + stack.SetResult_U4(result); + + NANOCLR_NOCLEANUP(); +} + +HRESULT Library_nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_TransmitterChannel:: + NativeDispose___VOID(CLR_RT_StackFrame &stack) +{ + NANOCLR_HEADER(); + + int32_t channel; + + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + + channel = (int32_t)pThis[RmtChannel::FIELD___channel].NumericByRef().s4; + + if (!RmtChannel::CheckChannel(channel)) + { + NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); + } + + if (rmt_driver_uninstall(CHANNEL(channel)) != ESP_OK) + { + hr = CLR_E_PROCESS_EXCEPTION; + } + + RmtChannel::registredChannels.erase(CHANNEL(channel)); + + NANOCLR_NOCLEANUP(); +} + +HRESULT Library_nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_TransmitterChannel:: + NativeGetSourceClock___BOOLEAN(CLR_RT_StackFrame &stack) +{ + NANOCLR_HEADER(); + + bool retVal = false; + + int32_t channel; + + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + + channel = (int32_t)stack.Arg0().NumericByRef().s4; + + if (!RmtChannel::CheckChannel(channel)) + { + NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); + } + + retVal = ::RMT.conf_ch[(rmt_channel_t)channel].conf1.ref_always_on; + + stack.SetResult_Boolean(retVal); + + NANOCLR_NOCLEANUP(); +} + +esp_err_t Library_nanoFramework_hardware_esp32_rmt_native_nanoFramework_Hardware_Esp32_Rmt_TransmitterChannel:: + InitTxChannel(rmt_channel_t channel, gpio_num_t gpio) +{ + rmt_config_t rmt_tx{ + RMT_MODE_TX, + channel, + DEFAULT_DIVIDER, + gpio, + 1, + {false, 38000, 50, RMT_CARRIER_LEVEL_HIGH, false, RMT_IDLE_LEVEL_LOW, true}}; + + auto err = rmt_config(&rmt_tx); + if (err != ESP_OK) + return err; + + err = rmt_driver_install(channel, 0, 0); + if (err != ESP_OK) + return err; + + RmtChannel::registredChannels.emplace( + std::piecewise_construct, + std::forward_as_tuple(channel), + std::forward_as_tuple()); + return ESP_OK; +} diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoFramework.Runtime.Native/nf_rt_native_nanoFramework_Runtime_Native_Rtc.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoFramework.Runtime.Native/nf_rt_native_nanoFramework_Runtime_Native_Rtc.cpp index e1056671c4..864436710e 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoFramework.Runtime.Native/nf_rt_native_nanoFramework_Runtime_Native_Rtc.cpp +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoFramework.Runtime.Native/nf_rt_native_nanoFramework_Runtime_Native_Rtc.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoHAL.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoHAL.cpp index 175e9e3186..a971e00292 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoHAL.cpp +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoHAL.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/targetHAL.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/targetHAL.cpp index 794702b13a..edfe10c795 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/targetHAL.cpp +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/targetHAL.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // @@ -8,46 +8,48 @@ #include #include #include +#include #include #include void Storage_Initialize(); void Storage_Uninitialize(); - extern "C" void FixUpHalSystemConfig(); extern "C" void FixUpBlockRegionInfo(); - // // Reboot handlers clean up on reboot // -static ON_SOFT_REBOOT_HANDLER s_rebootHandlers[16] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; +static ON_SOFT_REBOOT_HANDLER s_rebootHandlers[16] = + {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; void HAL_AddSoftRebootHandler(ON_SOFT_REBOOT_HANDLER handler) { - for(unsigned int i=0; i 0) ? true : false; -} - -void SystemState_Set(SYSTEM_STATE_type state) -{ - GLOBAL_LOCK(); - - SystemState_SetNoLock(state); - - GLOBAL_UNLOCK(); -} - -void SystemState_Clear(SYSTEM_STATE_type state) -{ - GLOBAL_LOCK(); - - SystemState_ClearNoLock(state ); - - GLOBAL_UNLOCK(); -} - -bool SystemState_Query(SYSTEM_STATE_type state) -{ - GLOBAL_LOCK(); - - bool systemStateCopy = SystemState_QueryNoLock(state); - - GLOBAL_UNLOCK(); - - return systemStateCopy; -} - - // Just in case storage is not configured -__nfweak void Storage_Initialize() {}; -__nfweak void Storage_Uninitialize() {}; \ No newline at end of file +__nfweak void Storage_Initialize(){}; +__nfweak void Storage_Uninitialize(){}; \ No newline at end of file diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/targetHAL_ConfigStorage.h b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/targetHAL_ConfigStorage.h index 1b15a7eb04..df7f1d3c11 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/targetHAL_ConfigStorage.h +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/targetHAL_ConfigStorage.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/targetHAL_ConfigStorageFatfs.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/targetHAL_ConfigStorageFatfs.cpp index a9569403c4..e94b57f67f 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/targetHAL_ConfigStorageFatfs.cpp +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/targetHAL_ConfigStorageFatfs.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/targetHAL_ConfigStorageNVS.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/targetHAL_ConfigStorageNVS.cpp index 6f75637073..db64447bcb 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/targetHAL_ConfigStorageNVS.cpp +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/targetHAL_ConfigStorageNVS.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/targetHAL_ConfigStorageSPIFFS.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/targetHAL_ConfigStorageSPIFFS.cpp index d1c2e4b506..ecb145bf03 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/targetHAL_ConfigStorageSPIFFS.cpp +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/targetHAL_ConfigStorageSPIFFS.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/targetHAL_ConfigurationManager.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/targetHAL_ConfigurationManager.cpp index ff570227d4..08a0bc256e 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/targetHAL_ConfigurationManager.cpp +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/targetHAL_ConfigurationManager.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/targetHAL_Power.c b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/targetHAL_Power.c index a0ff214e35..b82cb35722 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/targetHAL_Power.c +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/targetHAL_Power.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/targetHAL_Time.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/targetHAL_Time.cpp index b631c7fa46..e6fe94bf0e 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/targetHAL_Time.cpp +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/targetHAL_Time.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/targetPAL.c b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/targetPAL.c index 973fe28c33..d7dc4c8516 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/targetPAL.c +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/targetPAL.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/targetPAL_Events.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/targetPAL_Events.cpp index ca2c0af389..96c30242c5 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/targetPAL_Events.cpp +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/targetPAL_Events.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // @@ -14,134 +14,75 @@ uint64_t CPU_MillisecondsToTicks(uint64_t ticks); // timer for bool events static TimerHandle_t boolEventsTimer; -volatile uint32_t systemEvents; +static void local_Events_SetBoolTimer_Callback(TimerHandle_t xTimer); -static void local_Events_SetBoolTimer_Callback( TimerHandle_t xTimer ); - -set_Event_Callback g_Event_Callback = NULL; -void* g_Event_Callback_Arg = NULL; - -bool Events_Initialize() +bool Events_Initialize_Platform() { - NATIVE_PROFILE_PAL_EVENTS(); - - // init events - GLOBAL_LOCK(); - systemEvents = 0; - GLOBAL_UNLOCK(); + boolEventsTimer = xTimerCreate("boolEventsTimer", 10, pdFALSE, (void *)0, local_Events_SetBoolTimer_Callback); - boolEventsTimer = xTimerCreate( "boolEventsTimer", 10, pdFALSE, (void *)0, local_Events_SetBoolTimer_Callback); - return true; } -bool Events_Uninitialize() +bool Events_Uninitialize_Platform() { - NATIVE_PROFILE_PAL_EVENTS(); + xTimerDelete(boolEventsTimer, 0); - xTimerDelete(boolEventsTimer,0); - return true; } -void Events_Set( uint32_t events ) -{ - NATIVE_PROFILE_PAL_EVENTS(); - - // set events - GLOBAL_LOCK(); - systemEvents |= events; - GLOBAL_UNLOCK(); - - if( g_Event_Callback != NULL ) - { - g_Event_Callback( g_Event_Callback_Arg ); - } -} - -uint32_t Events_Get( uint32_t eventsOfInterest ) +static void local_Events_SetBoolTimer_Callback(TimerHandle_t xTimer) { NATIVE_PROFILE_PAL_EVENTS(); - // get the requested flags from system events state and... - uint32_t returnEvents = (systemEvents & eventsOfInterest); - - // ... clear the requested flags atomically - GLOBAL_LOCK(); - systemEvents &= ~eventsOfInterest; - GLOBAL_UNLOCK(); - - // give the caller notice of just the events they asked for ( and were cleared already ) - return returnEvents; -} - -uint32_t Events_MaskedRead( uint32_t eventsOfInterest ) -{ - NATIVE_PROFILE_PAL_EVENTS(); - return (systemEvents & eventsOfInterest); -} - -static void local_Events_SetBoolTimer_Callback( TimerHandle_t xTimer ) -{ - NATIVE_PROFILE_PAL_EVENTS(); - - bool* timerCompleteFlag = (bool*)pvTimerGetTimerID( xTimer ); + bool *timerCompleteFlag = (bool *)pvTimerGetTimerID(xTimer); *timerCompleteFlag = true; } -void Events_SetCallback( set_Event_Callback pfn, void* arg ) -{ - NATIVE_PROFILE_PAL_EVENTS(); - - g_Event_Callback = pfn; - g_Event_Callback_Arg = arg; -} - -void Events_SetBoolTimer( bool* timerCompleteFlag, uint32_t millisecondsFromNow ) +void Events_SetBoolTimer(bool *timerCompleteFlag, uint32_t millisecondsFromNow) { NATIVE_PROFILE_PAL_EVENTS(); // we assume only 1 can be active, abort previous just in case - xTimerStop( boolEventsTimer, 0 ); + xTimerStop(boolEventsTimer, 0); - if(timerCompleteFlag != NULL) + if (timerCompleteFlag != NULL) { - vTimerSetTimerID( boolEventsTimer, (void*) timerCompleteFlag ); - xTimerChangePeriod( boolEventsTimer, millisecondsFromNow / portTICK_PERIOD_MS, 0 ); + vTimerSetTimerID(boolEventsTimer, (void *)timerCompleteFlag); + xTimerChangePeriod(boolEventsTimer, millisecondsFromNow / portTICK_PERIOD_MS, 0); } } -uint32_t Events_WaitForEvents( uint32_t powerLevel, uint32_t wakeupSystemEvents, uint32_t timeoutMilliseconds ) +uint32_t Events_WaitForEvents(uint32_t powerLevel, uint32_t wakeupSystemEvents, uint32_t timeoutMilliseconds) { // schedule an interrupt for this far in the future // timeout is in milliseconds, need to convert to ticks uint64_t countsRemaining = CPU_MillisecondsToTicks(timeoutMilliseconds); - #if defined(HAL_PROFILE_ENABLED) +#if defined(HAL_PROFILE_ENABLED) Events_WaitForEvents_Calls++; - #endif +#endif - uint64_t expireTimeInTicks = HAL_Time_CurrentSysTicks() + countsRemaining; + uint64_t expireTimeInTicks = HAL_Time_CurrentSysTicks() + countsRemaining; bool runContinuations = true; - while(true) + while (true) { EVENTS_HEART_BEAT; - uint32_t events = Events_MaskedRead( wakeupSystemEvents ); - if(events) + uint32_t events = Events_MaskedRead(wakeupSystemEvents); + if (events) { return events; } - if(expireTimeInTicks <= HAL_Time_CurrentSysTicks()) + if (expireTimeInTicks <= HAL_Time_CurrentSysTicks()) { break; } // first check and possibly run any continuations // but only if we have slept after stalling - if(runContinuations && !SystemState_QueryNoLock(SYSTEM_STATE_NO_CONTINUATIONS)) + if (runContinuations && !SystemState_QueryNoLock(SYSTEM_STATE_NO_CONTINUATIONS)) { // if we stall on time, don't check again until after we sleep runContinuations = HAL_CONTINUATION::Dequeue_And_Execute(); @@ -151,18 +92,18 @@ uint32_t Events_WaitForEvents( uint32_t powerLevel, uint32_t wakeupSystemEvents, // try stalled continuations again after sleeping runContinuations = true; - HAL_COMPLETION::WaitForInterrupts(expireTimeInTicks, powerLevel, wakeupSystemEvents ); + HAL_COMPLETION::WaitForInterrupts(expireTimeInTicks, powerLevel, wakeupSystemEvents); } // no events, pass control to the OS taskYIELD(); - + // check if reboot or exit flags were set when the other OS threads executed - if(CLR_EE_DBG_IS(RebootPending) || CLR_EE_DBG_IS(ExitPending)) + if (CLR_EE_DBG_IS(RebootPending) || CLR_EE_DBG_IS(ExitPending)) { break; } - + // feed the watchdog... Watchdog_Reset(); } @@ -176,6 +117,6 @@ void FreeManagedEvent(uint8_t category, uint8_t subCategory, uint16_t data1, uin (void)subCategory; (void)data1; (void)data2; - + NATIVE_PROFILE_PAL_EVENTS(); } diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/targetPAL_Events.cpp.groups.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/targetPAL_Events.cpp.groups.cpp deleted file mode 100644 index 4594c31023..0000000000 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/targetPAL_Events.cpp.groups.cpp +++ /dev/null @@ -1,146 +0,0 @@ -// -// Copyright (c) 2017 The nanoFramework project contributors -// See LICENSE file in the project root for full license information. -// - -#include -#include -#include -#include - -#define ESP32_AVAILABLE_EVENTBITS 0x00ffffff - -static void local_Events_SetBoolTimer_Callback( TimerHandle_t xTimer ); - -// events timer -static TimerHandle_t boolEventsTimer; -static bool* saveTimerCompleteFlag = 0; - -EventGroupHandle_t systemEventsHigh; -EventGroupHandle_t systemEventsLow; - -set_Event_Callback g_Event_Callback = NULL; -void* g_Event_Callback_Arg = NULL; - -bool Events_Initialize() -{ - NATIVE_PROFILE_PAL_EVENTS(); - - // init events - // The Eps32 Event group is 24 bits, top 8 bits used by system - // Currently Nanoframework only uses 21 bits, see nanoHal.h - systemEventsHigh = xEventGroupCreate(); - systemEventsLow = xEventGroupCreate(); - - boolEventsTimer = xTimerCreate( "boolEventsTimer", 10, pdFALSE, (void *)0, local_Events_SetBoolTimer_Callback); - - return true; -} - -bool Events_Uninitialize() -{ - NATIVE_PROFILE_PAL_EVENTS(); - - vEventGroupDelete( systemEventsHigh ); - vEventGroupDelete( systemEventsLow); - - return true; -} - -void Events_Set( uint32_t events ) -{ - NATIVE_PROFILE_PAL_EVENTS(); -ets_printf( "Events_set %X\n", events); - // set events - xEventGroupSetBits( systemEventsHigh, events >> 16 ); - xEventGroupSetBits( systemEventsLow, events & 0x00ffff ); - - if( g_Event_Callback != NULL ) - { - g_Event_Callback( g_Event_Callback_Arg ); - } -} - -uint32_t Events_Get( uint32_t eventsOfInterest ) -{ - NATIVE_PROFILE_PAL_EVENTS(); - - // get the requested flags from system events state and... - - uint32_t returnEvents = (xEventGroupGetBits(systemEventsHigh) << 16) & xEventGroupGetBits(systemEventsLow) - - // Make off top 8 bits otherwise get exception when calling xEventGroupClearBits - uint32_t eventstoClear = ~eventsOfInterest; - - // ... clear the requested flags atomically - xEventGroupClearBits(systemEventsHigh, eventstoClear >> 16 ); - xEventGroupClearBits(systemEventsLow, eventstoClear & 0x00ffff ); - - // give the caller notice of just the events they asked for ( and were cleared already ) - return returnEvents; -} - -uint32_t Events_MaskedRead( uint32_t eventsOfInterest ) -{ - NATIVE_PROFILE_PAL_EVENTS(); - - uint32_t returnEvents = (xEventGroupGetBits(systemEventsHigh) << 16) & xEventGroupGetBits(systemEventsLow) - - return ( returnEvents & eventsOfInterest); -} - -static void local_Events_SetBoolTimer_Callback( TimerHandle_t xTimer ) -{ - NATIVE_PROFILE_PAL_EVENTS(); - - *saveTimerCompleteFlag = true; -} - -void Events_SetCallback( set_Event_Callback pfn, void* arg ) -{ - NATIVE_PROFILE_PAL_EVENTS(); - - g_Event_Callback = pfn; - g_Event_Callback_Arg = arg; -} - -void Events_SetBoolTimer( bool* timerCompleteFlag, uint32_t millisecondsFromNow ) -{ - NATIVE_PROFILE_PAL_EVENTS(); - - // we assume only 1 can be active, abort previous just in case - xTimerStop( boolEventsTimer, 0 ); - - if(timerCompleteFlag != NULL) - { - - xTimerChangePeriod( boolEventsTimer, millisecondsFromNow / portTICK_PERIOD_MS, 0 ); - -// Was going to just change existing timer but vTimerSetTimerID() does not exist in this version of FreeRTOS -// As only one timer running at a time we will just save it in global memory - saveTimerCompleteFlag = timerCompleteFlag; - // vTimerSetTimerID( boolEventsTimer, (void *)timerCompleteFlag ); - xTimerStart(boolEventsTimer, 0); - } -} - -uint32_t Events_WaitForEvents( uint32_t powerLevel, uint32_t wakeupSystemEvents, uint32_t timeoutMilliseconds ) -{ - -#if defined(HAL_PROFILE_ENABLED) - Events_WaitForEvents_Calls++; -#endif - - EventBits_t events = (xEventGroupGetBits(systemEventsHigh) << 16) & xEventGroupGetBits(systemEventsLow) - if( events == 0) { - // no events, wait for timeoutMilliseconds - vTaskDelay( timeoutMilliseconds / portTICK_PERIOD_MS ); - } - - return (uint32_t)events; -} - -void FreeManagedEvent(uint8_t category, uint8_t subCategory, uint16_t data1, uint32_t data2) -{ - NATIVE_PROFILE_PAL_EVENTS(); -} diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/targetPAL_Time.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/targetPAL_Time.cpp index fb1d356c47..6bda02dd9a 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/targetPAL_Time.cpp +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/targetPAL_Time.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/targetRandom.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/targetRandom.cpp index 061993b057..ebe748159d 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/targetRandom.cpp +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/targetRandom.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // #include "Core.h" diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/target_board.h.in b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/target_board.h.in index ae6e5f3727..4ee094ee30 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/target_board.h.in +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/target_board.h.in @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/target_platform.h.in b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/target_platform.h.in index a495f6dac5..ede8e6a93f 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/target_platform.h.in +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/target_platform.h.in @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // @@ -11,17 +11,13 @@ #ifndef _TARGET_ESP32_NANOCLR_H_ #define _TARGET_ESP32_NANOCLR_H_ +// enable SPI +#define HAL_USE_SPI @HAL_USE_SPI_OPTION@ // set when SD card is enabled #define HAL_USE_SDC @HAL_USE_SDC_OPTION@ #if defined(HAL_USE_SDC) - #define SDC_MAX_OPEN_FILES 5 - - - #endif - - #endif /* _TARGET_ESP32_NANOCLR_H_ */ diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/target_BlockStorage.c b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/target_BlockStorage.c index 6b185982d8..620b0b1698 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/target_BlockStorage.c +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/target_BlockStorage.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/target_BlockStorage.h b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/target_BlockStorage.h index aa50b1b7f2..8a56d0eee0 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/target_BlockStorage.h +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/target_BlockStorage.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/target_common.c b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/target_common.c index 022af372a8..f0ca0c7580 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/target_common.c +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/target_common.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/target_common.h.in b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/target_common.h.in index 74d44824bf..1441a4f9f6 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/target_common.h.in +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/target_common.h.in @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/target_lwip_sntp_opts.h b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/target_lwip_sntp_opts.h index 3000766425..55e9a1ca86 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/target_lwip_sntp_opts.h +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/target_lwip_sntp_opts.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/target_nf_devices_onewire_config.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/target_nf_devices_onewire_config.cpp index 76238dbec3..949567e829 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/target_nf_devices_onewire_config.cpp +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/target_nf_devices_onewire_config.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/target_nf_devices_onewire_config.h b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/target_nf_devices_onewire_config.h index 33de9b0a76..167ba490d6 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/target_nf_devices_onewire_config.h +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/target_nf_devices_onewire_config.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/target_system_devices_dac_config.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/target_system_devices_dac_config.cpp index d7b7376bc0..949567e829 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/target_system_devices_dac_config.cpp +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/target_system_devices_dac_config.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/target_windows_devices_adc_config.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/target_windows_devices_adc_config.cpp index 76238dbec3..949567e829 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/target_windows_devices_adc_config.cpp +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/target_windows_devices_adc_config.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/target_windows_devices_i2c_config.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/target_windows_devices_i2c_config.cpp index 76238dbec3..949567e829 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/target_windows_devices_i2c_config.cpp +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/target_windows_devices_i2c_config.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/target_windows_devices_serialcommunication_config.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/target_windows_devices_serialcommunication_config.cpp index 4845bf12ac..949567e829 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/target_windows_devices_serialcommunication_config.cpp +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/target_windows_devices_serialcommunication_config.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/target_windows_devices_spi_config.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/target_windows_devices_spi_config.cpp index 76238dbec3..949567e829 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/target_windows_devices_spi_config.cpp +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/target_windows_devices_spi_config.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/target_windows_storage_config.h b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/target_windows_storage_config.h index 4fe9209830..b2d2dec961 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/target_windows_storage_config.h +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/target_windows_storage_config.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/CMakeLists.txt b/targets/TI-SimpleLink/CMakeLists.txt index 262ca12ea0..456cdb36d3 100644 --- a/targets/TI-SimpleLink/CMakeLists.txt +++ b/targets/TI-SimpleLink/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # @@ -119,6 +119,7 @@ if("${TARGET_SERIES}" STREQUAL "CC32xx") set(NO_TI_XDCTOOLS_SOURCE FALSE) endif() endif() + if(NO_TI_XDCTOOLS_SOURCE) # no TI XDCTools source specified, download it from it's repo @@ -188,7 +189,7 @@ if("${TARGET_SERIES}" STREQUAL "CC32xx") # get source dir for TI XDCTools CMake project ExternalProject_Get_Property(TI_XDCTools SOURCE_DIR) - set(TI_XDCTools_INCLUDE_DIR "${CMAKE_BINARY_DIR}/TI_XDCTools_Source/packages" PARENT_SCOPE) + set(TI_XDCTools_INCLUDE_DIR ${CMAKE_BINARY_DIR}/TI_XDCTools_Source/packages/ PARENT_SCOPE) else() # TI XDCTools source was specified @@ -223,7 +224,7 @@ if("${TARGET_SERIES}" STREQUAL "CC32xx") # get source dir for TI XDCTools CMake project ExternalProject_Get_Property(TI_XDCTools SOURCE_DIR) - set(TI_XDCTools_INCLUDE_DIR ${CMAKE_BINARY_DIR}/TI_XDCTools_Source/packages PARENT_SCOPE) + set(TI_XDCTools_INCLUDE_DIR ${CMAKE_BINARY_DIR}/TI_XDCTools_Source/packages/ PARENT_SCOPE) endif() @@ -255,8 +256,8 @@ elseif( "${TARGET_SERIES}" STREQUAL "CC13x2_26x2" ) message(FATAL_ERROR "error: could not find Git, make sure you have it installed.") endif() - message(STATUS "TI SimpleLink CC13x2_26x2 SDK (latest available code from v3.20.00.68") - set(TI_SL_CC13x2_26x2_SDK_TAG "3.20.00.68") + set(TI_SL_CC13x2_26x2_SDK_TAG "4.20.01.04" CACHE INTERNAL "TI CC13x2_26x2 SDK tag") + message(STATUS "TI SimpleLink CC13x2_26x2 SDK (latest available code from v${TI_SL_CC13x2_26x2_SDK_TAG})") # need to setup a separate CMake project to download the code from the GitHub repository # otherwise it won't be available before the actual build step @@ -296,12 +297,14 @@ elseif( "${TARGET_SERIES}" STREQUAL "CC13x2_26x2" ) else() # TI SimpleLink CC13x2_26x2 SDK source was specified + set(TI_SL_CC13x2_26x2_SDK_TAG "XX.XX.XX.XX" CACHE INTERNAL "TI CC13x2_26x2 SDK tag") + # sanity check is source path exists if(EXISTS "${TI_SL_CC13x2_26x2_SDK_SOURCE}/") message(STATUS "TI SimpleLink CC13x2_26x2 SDK source from: ${TI_SL_CC13x2_26x2_SDK_SOURCE}") # check if we already have the sources, no need to copy again - NF_DIRECTORY_EXISTS_NOT_EMPTY(${CMAKE_BINARY_DIR}/TI_SL_CC13x2_26x2_SDK_SOURCE/ SOURCE_EXISTS) + NF_DIRECTORY_EXISTS_NOT_EMPTY(${CMAKE_BINARY_DIR}/SimpleLinkCC13x2_26x2Sdk_Source/ SOURCE_EXISTS) if(NOT ${SOURCE_EXISTS}) file(COPY "${TI_SL_CC13x2_26x2_SDK_SOURCE}/" DESTINATION "${CMAKE_BINARY_DIR}/SimpleLinkCC13x2_26x2Sdk_Source") @@ -309,7 +312,7 @@ elseif( "${TARGET_SERIES}" STREQUAL "CC13x2_26x2" ) message(STATUS "Using local cache of TI SimpleLink CC13x2_26x2 SDK source from ${TI_SL_CC13x2_26x2_SDK_SOURCE}") endif() - set(SimpleLinkCC13x2_26x2SDK_INCLUDE_DIR ${CMAKE_BINARY_DIR}/SimpleLinkCC13x2_26x2SdkS_Source/ti/devices/cc32xx) + set(SimpleLinkCC13x2_26x2SDK_INCLUDE_DIR ${CMAKE_BINARY_DIR}/SimpleLinkCC13x2_26x2SdkS_Source/ti/devices/cc13x2_cc26x2) else() message(FATAL_ERROR "Couldn't find TI SimpleLink CC13x2_26x2 SDK source at ${TI_SL_CC13x2_26x2_SDK_SOURCE}/") endif() @@ -330,6 +333,123 @@ elseif( "${TARGET_SERIES}" STREQUAL "CC13x2_26x2" ) ExternalProject_Get_Property(SimpleLinkCC13x2_26x2SDK SOURCE_DIR) endif() + # check if TI_SYSCONFIG_SOURCE was specified or if it's empty (default is empty) + set(NO_TI_SYSCONFIG_SOURCE TRUE) + if(TI_SYSCONFIG_SOURCE) + if(NOT "${TI_SYSCONFIG_SOURCE}" STREQUAL "") + set(NO_TI_SYSCONFIG_SOURCE FALSE) + endif() + endif() + + if(NO_TI_SYSCONFIG_SOURCE) + # no TI SysConfig source specified, download it from it's repo + + # check for Git (needed here for advanced warning to user if it's not installed) + find_package(Git) + + # check if Git was found, if not report to user and abort + if(NOT GIT_EXECUTABLE) + message(FATAL_ERROR "error: could not find Git, make sure you have it installed.") + endif() + + # TI SysConfig version + set(TI_SYSCONFIG_VERSION_EMPTY TRUE) + + # check if build was requested with a specifc TI SysConfig version + if(DEFINED TI_SYSCONFIG_VERSION) + if(NOT "${TI_SYSCONFIG_VERSION}" STREQUAL "") + set(TI_SYSCONFIG_VERSION_EMPTY FALSE) + endif() + endif() + + # TI SysConfig version + set(TI_SYSCONFIG_VERSION_EMPTY TRUE) + + # check if build was requested with a specifc TI SysConfig version + if(TI_SYSCONFIG_VERSION_EMPTY) + # no TI SysConfig version actualy specified, must be empty which is fine, we'll default to a known good version + set(TI_SYSCONFIG_VERSION_TAG "1.5.0") + else() + # set Git tag + set(TI_SYSCONFIG_VERSION_TAG "${TI_SYSCONFIG_VERSION}") + endif() + + message(STATUS "TI SysConfig ${TI_SYSCONFIG_VERSION} from GitHub repo") + + # need to setup a separate CMake project to download the code from the GitHub repository + # otherwise it won't be available before the actual build step + configure_file("${PROJECT_SOURCE_DIR}/CMake/TI_SysConfig.CMakeLists.cmake.in" + "${CMAKE_BINARY_DIR}/TI_SysConfig_Download/CMakeLists.txt") + + # setup CMake project for TI SysConfig download + execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . + RESULT_VARIABLE result + WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/TI_SysConfig_Download") + + # run build on TI SysConfig download CMake project to perform the download + execute_process(COMMAND ${CMAKE_COMMAND} --build . + RESULT_VARIABLE result + WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/TI_SysConfig_Download") + + # add TI SysConfig as external project + ExternalProject_Add( + TI_SysConfig + PREFIX TI_SysConfig + SOURCE_DIR ${CMAKE_BINARY_DIR}/TI_SysConfig_Source + GIT_REPOSITORY https://github.com/nanoframework/TI_SysConfig + GIT_TAG ${TI_SYSCONFIG_VERSION_TAG} # target specified branch + GIT_SHALLOW 1 # download only the tip of the branch, not the complete history + TIMEOUT 10 + LOG_DOWNLOAD 1 + + # Disable all other steps + INSTALL_COMMAND "" + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + ) + + # get source dir for TI SysConfig CMake project + ExternalProject_Get_Property(TI_SysConfig SOURCE_DIR) + set(TI_SysConfig_INCLUDE_DIR ${CMAKE_BINARY_DIR}/TI_SysConfig_Source/packages PARENT_SCOPE) + + else() + # TI SysConfig source was specified + + # sanity check is source path exists + if(EXISTS "${TI_SYSCONFIG_SOURCE}/") + message(STATUS "TI SysConfig (source from: ${TI_SYSCONFIG_SOURCE})") + + # check if we already have the sources, no need to copy again + NF_DIRECTORY_EXISTS_NOT_EMPTY(${CMAKE_BINARY_DIR}/TI_SysConfig_Source/ SOURCE_EXISTS) + + if(NOT ${SOURCE_EXISTS}) + file(COPY "${TI_SYSCONFIG_SOURCE}/" DESTINATION "${CMAKE_BINARY_DIR}/TI_SysConfig_Source") + else() + message(STATUS "Using local cache of TI SysConfig source from ${TI_SYSCONFIG_SOURCE}") + endif() + + else() + message(FATAL_ERROR "Couldn't find TI SysConfig source at ${TI_SYSCONFIG_SOURCE}/") + endif() + + # add TI SysConfig as external project + ExternalProject_Add( + TI_SysConfig + PREFIX TI_SysConfig + SOURCE_DIR ${CMAKE_BINARY_DIR}/TI_SysConfig_Source + # Disable all other steps + INSTALL_COMMAND "" + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + ) + + # get source dir for TI SysConfig CMake project + ExternalProject_Get_Property(TI_SysConfig SOURCE_DIR) + set(TI_SysConfig_INCLUDE_DIR "${CMAKE_BINARY_DIR}/TI_SysConfig_Source/packages" PARENT_SCOPE) + + endif() + + # check if TI_XDCTOOLS_SOURCE was specified or if it's empty (default is empty) set(NO_TI_XDCTOOLS_SOURCE TRUE) if(TI_XDCTOOLS_SOURCE) @@ -337,7 +457,7 @@ elseif( "${TARGET_SERIES}" STREQUAL "CC13x2_26x2" ) set(NO_TI_XDCTOOLS_SOURCE FALSE) endif() endif() - + if(NO_TI_XDCTOOLS_SOURCE) # no TI XDCTools source specified, download it from it's repo @@ -407,7 +527,7 @@ elseif( "${TARGET_SERIES}" STREQUAL "CC13x2_26x2" ) # get source dir for TI XDCTools CMake project ExternalProject_Get_Property(TI_XDCTools SOURCE_DIR) - set(TI_XDCTools_INCLUDE_DIR ${CMAKE_BINARY_DIR}/TI_XDCTools_Source/packages PARENT_SCOPE) + set(TI_XDCTools_INCLUDE_DIR ${CMAKE_BINARY_DIR}/TI_XDCTools_Source/packages/ PARENT_SCOPE) else() # TI XDCTools source was specified @@ -442,7 +562,7 @@ elseif( "${TARGET_SERIES}" STREQUAL "CC13x2_26x2" ) # get source dir for TI XDCTools CMake project ExternalProject_Get_Property(TI_XDCTools SOURCE_DIR) - set(TI_XDCTools_INCLUDE_DIR "${CMAKE_BINARY_DIR}/TI_XDCTools_Source/packages" PARENT_SCOPE) + set(TI_XDCTools_INCLUDE_DIR ${CMAKE_BINARY_DIR}/TI_XDCTools_Source/packages/ PARENT_SCOPE) endif() diff --git a/targets/TI-SimpleLink/Include/CLR_Startup_Thread.h b/targets/TI-SimpleLink/Include/CLR_Startup_Thread.h index 6d7f483e83..7e6bd33c63 100644 --- a/targets/TI-SimpleLink/Include/CLR_Startup_Thread.h +++ b/targets/TI-SimpleLink/Include/CLR_Startup_Thread.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/Include/CMakeLists.txt b/targets/TI-SimpleLink/Include/CMakeLists.txt index 244a83afce..5ca91e2209 100644 --- a/targets/TI-SimpleLink/Include/CMakeLists.txt +++ b/targets/TI-SimpleLink/Include/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/targets/TI-SimpleLink/Include/TargetHAL_Spi.h b/targets/TI-SimpleLink/Include/TargetHAL_Spi.h new file mode 100644 index 0000000000..5f7154ad51 --- /dev/null +++ b/targets/TI-SimpleLink/Include/TargetHAL_Spi.h @@ -0,0 +1,15 @@ +// +// Copyright (c) .NET Foundation and Contributors +// See LICENSE file in the project root for full license information. +// + +#ifndef _TARGET_HAL_SPI_H_ +#define _TARGET_HAL_SPI_H_ 1 + +// # of buses +#define NUM_SPI_BUSES 1 + +// Maximum number of devices per SPI bus +#define MAX_SPI_DEVICES 5 + +#endif //_TARGET_HAL_SPI_H_ diff --git a/targets/TI-SimpleLink/Include/TargetPAL_BlockStorage.h b/targets/TI-SimpleLink/Include/TargetPAL_BlockStorage.h index 1828f7503b..707167deef 100644 --- a/targets/TI-SimpleLink/Include/TargetPAL_BlockStorage.h +++ b/targets/TI-SimpleLink/Include/TargetPAL_BlockStorage.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/Include/Target_BlockStorage_CC13x2_26x2FlashDriver.h b/targets/TI-SimpleLink/Include/Target_BlockStorage_CC13x2_26x2FlashDriver.h index c846f6e899..46aa636b8d 100644 --- a/targets/TI-SimpleLink/Include/Target_BlockStorage_CC13x2_26x2FlashDriver.h +++ b/targets/TI-SimpleLink/Include/Target_BlockStorage_CC13x2_26x2FlashDriver.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/Include/Target_BlockStorage_CC32xxFlashDriver.h b/targets/TI-SimpleLink/Include/Target_BlockStorage_CC32xxFlashDriver.h index 7097fd80ea..445720c982 100644 --- a/targets/TI-SimpleLink/Include/Target_BlockStorage_CC32xxFlashDriver.h +++ b/targets/TI-SimpleLink/Include/Target_BlockStorage_CC32xxFlashDriver.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/Include/Target_Windows_Storage.h b/targets/TI-SimpleLink/Include/Target_Windows_Storage.h index 888c34fef1..43f7367e2c 100644 --- a/targets/TI-SimpleLink/Include/Target_Windows_Storage.h +++ b/targets/TI-SimpleLink/Include/Target_Windows_Storage.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/Include/WireProtocol_ReceiverThread.h b/targets/TI-SimpleLink/Include/WireProtocol_ReceiverThread.h index a9f2a3ab7b..6461d53f91 100644 --- a/targets/TI-SimpleLink/Include/WireProtocol_ReceiverThread.h +++ b/targets/TI-SimpleLink/Include/WireProtocol_ReceiverThread.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/Include/platform_target_capabilities.h b/targets/TI-SimpleLink/Include/platform_target_capabilities.h index b44fe07a82..ee6a734be2 100644 --- a/targets/TI-SimpleLink/Include/platform_target_capabilities.h +++ b/targets/TI-SimpleLink/Include/platform_target_capabilities.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/Include/ssl_simplelink.h b/targets/TI-SimpleLink/Include/ssl_simplelink.h index 063d426c76..be7193493f 100644 --- a/targets/TI-SimpleLink/Include/ssl_simplelink.h +++ b/targets/TI-SimpleLink/Include/ssl_simplelink.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/Include/targetHAL.h b/targets/TI-SimpleLink/Include/targetHAL.h index 4419598d48..2768d614bb 100644 --- a/targets/TI-SimpleLink/Include/targetHAL.h +++ b/targets/TI-SimpleLink/Include/targetHAL.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // @@ -12,31 +12,25 @@ #include #include -#define GLOBAL_LOCK() uint32_t taskKey = Task_disable(); -#define GLOBAL_UNLOCK() Task_restore(taskKey); +#define GLOBAL_LOCK() uint32_t taskKey = Task_disable(); +#define GLOBAL_UNLOCK() Task_restore(taskKey); // platform dependent delay -#define PLATFORM_DELAY(milliSecs) ClockP_usleep(milliSecs * 1000); +#define PLATFORM_DELAY(milliSecs) ClockP_usleep(milliSecs * 1000); // Definitions for Sockets/Network -#define GLOBAL_LOCK_SOCKETS(x) +#define GLOBAL_LOCK_SOCKETS(x) -#define PLATFORM_DEPENDENT__SOCKETS_MAX_COUNT 16 +#define PLATFORM_DEPENDENT__SOCKETS_MAX_COUNT 16 -#define LPCSTR const char* - -// these macros are to be used at entry/exit of native interrupt handlers -#define NATIVE_INTERRUPT_START SystemState_SetNoLock( SYSTEM_STATE_ISR ); \ - SystemState_SetNoLock( SYSTEM_STATE_NO_CONTINUATIONS ); -#define NATIVE_INTERRUPT_END SystemState_ClearNoLock( SYSTEM_STATE_NO_CONTINUATIONS ); \ - SystemState_ClearNoLock( SYSTEM_STATE_ISR ); +#define LPCSTR const char * #define TRUE true #define FALSE false #if !defined(BUILD_RTM) -#define HARD_BREAKPOINT() HARD_Breakpoint() +#define HARD_BREAKPOINT() HARD_Breakpoint() // #if defined(_DEBUG) // #define DEBUG_HARD_BREAKPOINT() HARD_Breakpoint() @@ -49,27 +43,27 @@ // #define HARD_BREAKPOINT() // #define DEBUG_HARD_BREAKPOINT() -#endif // !defined(BUILD_RTM) +#endif // !defined(BUILD_RTM) // map TI SimpleLink calls to UART output to nanoFramework API // this is valid only for debug buils // release and RTM build don't call these #if defined(BUILD_RTM) -#define UART_PRINT(x,...) -#define INFO_PRINT(x,...) +#define UART_PRINT(x, ...) +#define INFO_PRINT(x, ...) #else #if defined(DEBUG) || defined(_DEBUG) -#define UART_PRINT DebuggerPort_WriteProxy -#define INFO_PRINT DebuggerPort_WriteProxy +#define UART_PRINT DebuggerPort_WriteProxy +#define INFO_PRINT DebuggerPort_WriteProxy #else -#define UART_PRINT(x,...) -#define INFO_PRINT(x,...) +#define UART_PRINT(x, ...) +#define INFO_PRINT(x, ...) #endif // DEBUG @@ -84,11 +78,11 @@ // The implementation should is to be provided by each target at target_common.h.in // //////////////////////////////////////////////////////////////////////////////////////////////////// #if defined(BUILD_RTM) - #define EVENTS_HEART_BEAT +#define EVENTS_HEART_BEAT #else - #ifndef EVENTS_HEART_BEAT - #define EVENTS_HEART_BEAT __asm__ __volatile__ ("nop") - #endif // EVENTS_HEART_BEAT +#ifndef EVENTS_HEART_BEAT +#define EVENTS_HEART_BEAT __asm__ __volatile__("nop") +#endif // EVENTS_HEART_BEAT #endif extern int HeapBegin; diff --git a/targets/TI-SimpleLink/Include/targetHAL_ConfigurationManager_CC32xx.h b/targets/TI-SimpleLink/Include/targetHAL_ConfigurationManager_CC32xx.h index 4a9313626a..296bf2d562 100644 --- a/targets/TI-SimpleLink/Include/targetHAL_ConfigurationManager_CC32xx.h +++ b/targets/TI-SimpleLink/Include/targetHAL_ConfigurationManager_CC32xx.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/Include/targetHAL_Time.h b/targets/TI-SimpleLink/Include/targetHAL_Time.h index ec0f9e3e07..fc01a7deb0 100644 --- a/targets/TI-SimpleLink/Include/targetHAL_Time.h +++ b/targets/TI-SimpleLink/Include/targetHAL_Time.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/Include/targetPAL.h b/targets/TI-SimpleLink/Include/targetPAL.h index 42d1f49456..8e7c1df040 100644 --- a/targets/TI-SimpleLink/Include/targetPAL.h +++ b/targets/TI-SimpleLink/Include/targetPAL.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/Include/targetPAL_Time.h b/targets/TI-SimpleLink/Include/targetPAL_Time.h index 815979a703..7737787746 100644 --- a/targets/TI-SimpleLink/Include/targetPAL_Time.h +++ b/targets/TI-SimpleLink/Include/targetPAL_Time.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/Include/targetSimpleLinkCC32xx_LinkLocalTask.h b/targets/TI-SimpleLink/Include/targetSimpleLinkCC32xx_LinkLocalTask.h index f799a3b16c..c41e69ec13 100644 --- a/targets/TI-SimpleLink/Include/targetSimpleLinkCC32xx_LinkLocalTask.h +++ b/targets/TI-SimpleLink/Include/targetSimpleLinkCC32xx_LinkLocalTask.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Texas Instruments Incorporated. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/Include/targetSimpleLinkCC32xx_ProvisioningTask.h b/targets/TI-SimpleLink/Include/targetSimpleLinkCC32xx_ProvisioningTask.h index 3b13f6ee8f..9267500e4b 100644 --- a/targets/TI-SimpleLink/Include/targetSimpleLinkCC32xx_ProvisioningTask.h +++ b/targets/TI-SimpleLink/Include/targetSimpleLinkCC32xx_ProvisioningTask.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Texas Instruments Incorporated. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/Include/targetSimpleLinkCC32xx_Sntp.h b/targets/TI-SimpleLink/Include/targetSimpleLinkCC32xx_Sntp.h index 29ee542538..6f00b5e84f 100644 --- a/targets/TI-SimpleLink/Include/targetSimpleLinkCC32xx_Sntp.h +++ b/targets/TI-SimpleLink/Include/targetSimpleLinkCC32xx_Sntp.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Texas Instruments Incorporated. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/Include/targetSimpleLinkCC32xx_Threads.h b/targets/TI-SimpleLink/Include/targetSimpleLinkCC32xx_Threads.h index 1e81da2c17..f539928bd5 100644 --- a/targets/TI-SimpleLink/Include/targetSimpleLinkCC32xx_Threads.h +++ b/targets/TI-SimpleLink/Include/targetSimpleLinkCC32xx_Threads.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Texas Instruments Incorporated. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/Board.h b/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/Board.h deleted file mode 100644 index ff9c03f30c..0000000000 --- a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/Board.h +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Copyright (c) 2017-2019, Texas Instruments Incorporated - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of Texas Instruments Incorporated nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef __BOARD_H -#define __BOARD_H - -#define Board_CC1352R1_LAUNCHXL - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define Board_initGeneral() Board_init() /* deprecated */ - -#include "CC1352R1_LAUNCHXL.h" - -#define Board_shutDownExtFlash() CC1352R1_LAUNCHXL_shutDownExtFlash() -#define Board_wakeUpExtFlash() CC1352R1_LAUNCHXL_wakeUpExtFlash() - -/* These #defines allow us to reuse TI-RTOS across other device families */ - -#define Board_ADC0 CC1352R1_LAUNCHXL_ADC0 -#define Board_ADC1 CC1352R1_LAUNCHXL_ADC1 - -#define Board_ADCBUF0 CC1352R1_LAUNCHXL_ADCBUF0 -#define Board_ADCBUF0CHANNEL0 CC1352R1_LAUNCHXL_ADCBUF0CHANNEL0 -#define Board_ADCBUF0CHANNEL1 CC1352R1_LAUNCHXL_ADCBUF0CHANNEL1 - -#define Board_ECDH0 CC1352R1_LAUNCHXL_ECDH0 -#define Board_ECDSA0 CC1352R1_LAUNCHXL_ECDSA0 -#define Board_ECJPAKE0 CC1352R1_LAUNCHXL_ECJPAKE0 -#define Board_AESCCM0 CC1352R1_LAUNCHXL_AESCCM0 -#define Board_AESGCM0 CC1352R1_LAUNCHXL_AESGCM0 -#define Board_AESCBC0 CC1352R1_LAUNCHXL_AESCBC0 -#define Board_AESCTR0 CC1352R1_LAUNCHXL_AESCTR0 -#define Board_AESECB0 CC1352R1_LAUNCHXL_AESECB0 -#define Board_AESCTRDRBG0 CC1352R1_LAUNCHXL_AESCTRDRBG0 -#define Board_SHA20 CC1352R1_LAUNCHXL_SHA20 -#define Board_TRNG0 CC1352R1_LAUNCHXL_TRNG0 - -#define Board_DIO12 CC1352R1_LAUNCHXL_DIO12 -#define Board_DIO15 CC1352R1_LAUNCHXL_DIO15 -#define Board_DIO16_TDO CC1352R1_LAUNCHXL_DIO16_TDO -#define Board_DIO17_TDI CC1352R1_LAUNCHXL_DIO17_TDI -#define Board_DIO21 CC1352R1_LAUNCHXL_DIO21 -#define Board_DIO22 CC1352R1_LAUNCHXL_DIO22 - -#define Board_DIO23_ANALOG CC1352R1_LAUNCHXL_DIO23_ANALOG -#define Board_DIO24_ANALOG CC1352R1_LAUNCHXL_DIO24_ANALOG -#define Board_DIO25_ANALOG CC1352R1_LAUNCHXL_DIO25_ANALOG -#define Board_DIO26_ANALOG CC1352R1_LAUNCHXL_DIO26_ANALOG -#define Board_DIO27_ANALOG CC1352R1_LAUNCHXL_DIO27_ANALOG -#define Board_DIO28_ANALOG CC1352R1_LAUNCHXL_DIO28_ANALOG -#define Board_DIO29_ANALOG CC1352R1_LAUNCHXL_DIO29_ANALOG - -/* - * Board_RF_SUB1GHZ is the name generated by SysConfig. Define it - * here so that RF callback function can reference it. - */ -#define Board_RF_SUB1GHZ CC1352R1_LAUNCHXL_DIO30_RF_SUB1GHZ - -#define Board_GPIO_BUTTON0 CC1352R1_LAUNCHXL_GPIO_S1 -#define Board_GPIO_BUTTON1 CC1352R1_LAUNCHXL_GPIO_S2 -#define Board_GPIO_BTN1 CC1352R1_LAUNCHXL_GPIO_S1 -#define Board_GPIO_BTN2 CC1352R1_LAUNCHXL_GPIO_S2 -#define Board_GPIO_LED0 CC1352R1_LAUNCHXL_GPIO_LED_RED -#define Board_GPIO_LED1 CC1352R1_LAUNCHXL_GPIO_LED_GREEN -#define Board_GPIO_LED2 CC1352R1_LAUNCHXL_GPIO_LED_RED -#define Board_GPIO_RLED CC1352R1_LAUNCHXL_GPIO_LED_RED -#define Board_GPIO_GLED CC1352R1_LAUNCHXL_GPIO_LED_GREEN -#define Board_GPIO_LED_ON CC1352R1_LAUNCHXL_GPIO_LED_ON -#define Board_GPIO_LED_OFF CC1352R1_LAUNCHXL_GPIO_LED_OFF -#define Board_GPIO_TMP116_EN CC1352R1_LAUNCHXL_GPIO_TMP116_EN - -#define Board_GPTIMER0A CC1352R1_LAUNCHXL_GPTIMER0A -#define Board_GPTIMER0B CC1352R1_LAUNCHXL_GPTIMER0B -#define Board_GPTIMER1A CC1352R1_LAUNCHXL_GPTIMER1A -#define Board_GPTIMER1B CC1352R1_LAUNCHXL_GPTIMER1B -#define Board_GPTIMER2A CC1352R1_LAUNCHXL_GPTIMER2A -#define Board_GPTIMER2B CC1352R1_LAUNCHXL_GPTIMER2B -#define Board_GPTIMER3A CC1352R1_LAUNCHXL_GPTIMER3A -#define Board_GPTIMER3B CC1352R1_LAUNCHXL_GPTIMER3B - -#define Board_I2C0 CC1352R1_LAUNCHXL_I2C0 -#define Board_I2C_TMP Board_I2C0 - -#define Board_I2S0 CC1352R1_LAUNCHXL_I2S0 -#define Board_I2S_ADO CC1352R1_LAUNCHXL_I2S_ADO -#define Board_I2S_ADI CC1352R1_LAUNCHXL_I2S_ADI -#define Board_I2S_BCLK CC1352R1_LAUNCHXL_I2S_BCLK -#define Board_I2S_MCLK CC1352R1_LAUNCHXL_I2S_MCLK -#define Board_I2S_WCLK CC1352R1_LAUNCHXL_I2S_WCLK - -#define Board_NVSINTERNAL CC1352R1_LAUNCHXL_NVSCC26XX0 -#define Board_NVSEXTERNAL CC1352R1_LAUNCHXL_NVSSPI25X0 - -#define Board_PIN_BUTTON0 CC1352R1_LAUNCHXL_PIN_BTN1 -#define Board_PIN_BUTTON1 CC1352R1_LAUNCHXL_PIN_BTN2 -#define Board_PIN_BTN1 CC1352R1_LAUNCHXL_PIN_BTN1 -#define Board_PIN_BTN2 CC1352R1_LAUNCHXL_PIN_BTN2 -#define Board_PIN_LED0 CC1352R1_LAUNCHXL_PIN_RLED -#define Board_PIN_LED1 CC1352R1_LAUNCHXL_PIN_GLED -#define Board_PIN_LED2 CC1352R1_LAUNCHXL_PIN_RLED -#define Board_PIN_RLED CC1352R1_LAUNCHXL_PIN_RLED -#define Board_PIN_GLED CC1352R1_LAUNCHXL_PIN_GLED - -#define Board_PWM0 CC1352R1_LAUNCHXL_PWM0 -#define Board_PWM1 CC1352R1_LAUNCHXL_PWM1 -#define Board_PWM2 CC1352R1_LAUNCHXL_PWM2 -#define Board_PWM3 CC1352R1_LAUNCHXL_PWM3 -#define Board_PWM4 CC1352R1_LAUNCHXL_PWM4 -#define Board_PWM5 CC1352R1_LAUNCHXL_PWM5 -#define Board_PWM6 CC1352R1_LAUNCHXL_PWM6 -#define Board_PWM7 CC1352R1_LAUNCHXL_PWM7 - -#define Board_SD0 CC1352R1_LAUNCHXL_SDSPI0 - -#define Board_SPI0 CC1352R1_LAUNCHXL_SPI0 -#define Board_SPI1 CC1352R1_LAUNCHXL_SPI1 -#define Board_SPI_FLASH_CS CC1352R1_LAUNCHXL_SPI_FLASH_CS -#define Board_FLASH_CS_ON 0 -#define Board_FLASH_CS_OFF 1 - -#define Board_SPI_MASTER CC1352R1_LAUNCHXL_SPI0 -#define Board_SPI_SLAVE CC1352R1_LAUNCHXL_SPI0 -#define Board_SPI_MASTER_READY CC1352R1_LAUNCHXL_SPI_MASTER_READY -#define Board_SPI_SLAVE_READY CC1352R1_LAUNCHXL_SPI_SLAVE_READY - -#define Board_UART0 CC1352R1_LAUNCHXL_UART0 -#define Board_UART1 CC1352R1_LAUNCHXL_UART1 - -#define Board_WATCHDOG0 CC1352R1_LAUNCHXL_WATCHDOG0 - -#ifdef __cplusplus -} -#endif - -#endif /* __BOARD_H */ diff --git a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/CC1352R1_LAUNCHXL.c b/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/CC1352R1_LAUNCHXL.c deleted file mode 100644 index 3b0e72ec3d..0000000000 --- a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/CC1352R1_LAUNCHXL.c +++ /dev/null @@ -1,1127 +0,0 @@ -/* - * Copyright (c) 2017-2019, Texas Instruments Incorporated - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of Texas Instruments Incorporated nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * ====================== CC1352R1_LAUNCHXL.c =================================== - * This file is responsible for setting up the board specific items for the - * CC1352R1_LAUNCHXL board. - */ - -#include -#include -#include - -#include -#include -#include -#include - -#include "CC1352R1_LAUNCHXL.h" - -/* - * =============================== ADCBuf =============================== - */ -#include -#include - -ADCBufCC26X2_Object adcBufCC26xxObjects[CC1352R1_LAUNCHXL_ADCBUFCOUNT]; - -/* - * This table converts a virtual adc channel into a dio and internal analogue - * input signal. This table is necessary for the functioning of the adcBuf - * driver. Comment out unused entries to save flash. Dio and internal signal - * pairs are hardwired. Do not remap them in the table. You may reorder entire - * entries. The mapping of dio and internal signals is package dependent. - */ -const ADCBufCC26X2_AdcChannelLutEntry ADCBufCC26X2_adcChannelLut[CC1352R1_LAUNCHXL_ADCBUF0CHANNELCOUNT] = { - {CC1352R1_LAUNCHXL_DIO23_ANALOG, ADC_COMPB_IN_AUXIO7}, - {CC1352R1_LAUNCHXL_DIO24_ANALOG, ADC_COMPB_IN_AUXIO6}, - {CC1352R1_LAUNCHXL_DIO25_ANALOG, ADC_COMPB_IN_AUXIO5}, - {CC1352R1_LAUNCHXL_DIO26_ANALOG, ADC_COMPB_IN_AUXIO4}, - {CC1352R1_LAUNCHXL_DIO27_ANALOG, ADC_COMPB_IN_AUXIO3}, - {CC1352R1_LAUNCHXL_DIO28_ANALOG, ADC_COMPB_IN_AUXIO2}, - {CC1352R1_LAUNCHXL_DIO29_ANALOG, ADC_COMPB_IN_AUXIO1}, - {PIN_UNASSIGNED, ADC_COMPB_IN_VDDS}, - {PIN_UNASSIGNED, ADC_COMPB_IN_DCOUPL}, - {PIN_UNASSIGNED, ADC_COMPB_IN_VSS}, -}; - -const ADCBufCC26X2_HWAttrs adcBufCC26xxHWAttrs[CC1352R1_LAUNCHXL_ADCBUFCOUNT] = { - { - .intPriority = ~0, - .swiPriority = 0, - .adcChannelLut = ADCBufCC26X2_adcChannelLut, - .gpTimerUnit = CC1352R1_LAUNCHXL_GPTIMER0A, - } -}; - -const ADCBuf_Config ADCBuf_config[CC1352R1_LAUNCHXL_ADCBUFCOUNT] = { - { - &ADCBufCC26X2_fxnTable, - &adcBufCC26xxObjects[CC1352R1_LAUNCHXL_ADCBUF0], - &adcBufCC26xxHWAttrs[CC1352R1_LAUNCHXL_ADCBUF0] - }, -}; - -const uint_least8_t ADCBuf_count = CC1352R1_LAUNCHXL_ADCBUFCOUNT; - -/* - * =============================== ADC =============================== - */ -#include -#include - -ADCCC26XX_Object adcCC26xxObjects[CC1352R1_LAUNCHXL_ADCCOUNT]; - -const ADCCC26XX_HWAttrs adcCC26xxHWAttrs[CC1352R1_LAUNCHXL_ADCCOUNT] = { - { - .adcDIO = CC1352R1_LAUNCHXL_DIO23_ANALOG, - .adcCompBInput = ADC_COMPB_IN_AUXIO7, - .refSource = ADCCC26XX_FIXED_REFERENCE, - .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, - .inputScalingEnabled = true, - .triggerSource = ADCCC26XX_TRIGGER_MANUAL, - .returnAdjustedVal = false - }, - { - .adcDIO = CC1352R1_LAUNCHXL_DIO24_ANALOG, - .adcCompBInput = ADC_COMPB_IN_AUXIO6, - .refSource = ADCCC26XX_FIXED_REFERENCE, - .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, - .inputScalingEnabled = true, - .triggerSource = ADCCC26XX_TRIGGER_MANUAL, - .returnAdjustedVal = false - }, - { - .adcDIO = CC1352R1_LAUNCHXL_DIO25_ANALOG, - .adcCompBInput = ADC_COMPB_IN_AUXIO5, - .refSource = ADCCC26XX_FIXED_REFERENCE, - .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, - .inputScalingEnabled = true, - .triggerSource = ADCCC26XX_TRIGGER_MANUAL, - .returnAdjustedVal = false - }, - { - .adcDIO = CC1352R1_LAUNCHXL_DIO26_ANALOG, - .adcCompBInput = ADC_COMPB_IN_AUXIO4, - .refSource = ADCCC26XX_FIXED_REFERENCE, - .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, - .inputScalingEnabled = true, - .triggerSource = ADCCC26XX_TRIGGER_MANUAL, - .returnAdjustedVal = false - }, - { - .adcDIO = CC1352R1_LAUNCHXL_DIO27_ANALOG, - .adcCompBInput = ADC_COMPB_IN_AUXIO3, - .refSource = ADCCC26XX_FIXED_REFERENCE, - .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, - .inputScalingEnabled = true, - .triggerSource = ADCCC26XX_TRIGGER_MANUAL, - .returnAdjustedVal = false - }, - { - .adcDIO = CC1352R1_LAUNCHXL_DIO28_ANALOG, - .adcCompBInput = ADC_COMPB_IN_AUXIO2, - .refSource = ADCCC26XX_FIXED_REFERENCE, - .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, - .inputScalingEnabled = true, - .triggerSource = ADCCC26XX_TRIGGER_MANUAL, - .returnAdjustedVal = false - }, - { - .adcDIO = CC1352R1_LAUNCHXL_DIO29_ANALOG, - .adcCompBInput = ADC_COMPB_IN_AUXIO1, - .refSource = ADCCC26XX_FIXED_REFERENCE, - .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, - .inputScalingEnabled = true, - .triggerSource = ADCCC26XX_TRIGGER_MANUAL, - .returnAdjustedVal = false - }, - { - .adcDIO = PIN_UNASSIGNED, - .adcCompBInput = ADC_COMPB_IN_DCOUPL, - .refSource = ADCCC26XX_FIXED_REFERENCE, - .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, - .inputScalingEnabled = true, - .triggerSource = ADCCC26XX_TRIGGER_MANUAL, - .returnAdjustedVal = false - }, - { - .adcDIO = PIN_UNASSIGNED, - .adcCompBInput = ADC_COMPB_IN_VSS, - .refSource = ADCCC26XX_FIXED_REFERENCE, - .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, - .inputScalingEnabled = true, - .triggerSource = ADCCC26XX_TRIGGER_MANUAL, - .returnAdjustedVal = false - }, - { - .adcDIO = PIN_UNASSIGNED, - .adcCompBInput = ADC_COMPB_IN_VDDS, - .refSource = ADCCC26XX_FIXED_REFERENCE, - .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, - .inputScalingEnabled = true, - .triggerSource = ADCCC26XX_TRIGGER_MANUAL, - .returnAdjustedVal = false - } -}; - -const ADC_Config ADC_config[CC1352R1_LAUNCHXL_ADCCOUNT] = { - {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1352R1_LAUNCHXL_ADC0], &adcCC26xxHWAttrs[CC1352R1_LAUNCHXL_ADC0]}, - {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1352R1_LAUNCHXL_ADC1], &adcCC26xxHWAttrs[CC1352R1_LAUNCHXL_ADC1]}, - {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1352R1_LAUNCHXL_ADC2], &adcCC26xxHWAttrs[CC1352R1_LAUNCHXL_ADC2]}, - {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1352R1_LAUNCHXL_ADC3], &adcCC26xxHWAttrs[CC1352R1_LAUNCHXL_ADC3]}, - {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1352R1_LAUNCHXL_ADC4], &adcCC26xxHWAttrs[CC1352R1_LAUNCHXL_ADC4]}, - {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1352R1_LAUNCHXL_ADC5], &adcCC26xxHWAttrs[CC1352R1_LAUNCHXL_ADC5]}, - {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1352R1_LAUNCHXL_ADC6], &adcCC26xxHWAttrs[CC1352R1_LAUNCHXL_ADC6]}, - {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1352R1_LAUNCHXL_ADCDCOUPL], &adcCC26xxHWAttrs[CC1352R1_LAUNCHXL_ADCDCOUPL]}, - {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1352R1_LAUNCHXL_ADCVSS], &adcCC26xxHWAttrs[CC1352R1_LAUNCHXL_ADCVSS]}, - {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1352R1_LAUNCHXL_ADCVDDS], &adcCC26xxHWAttrs[CC1352R1_LAUNCHXL_ADCVDDS]}, -}; - -const uint_least8_t ADC_count = CC1352R1_LAUNCHXL_ADCCOUNT; - -/* - * =============================== ECDH =============================== - */ -#include -#include - -ECDHCC26X2_Object ecdhCC26X2Objects[CC1352R1_LAUNCHXL_ECDHCOUNT]; - -const ECDHCC26X2_HWAttrs ecdhCC26X2HWAttrs[CC1352R1_LAUNCHXL_ECDHCOUNT] = { - { - .intPriority = ~0, - } -}; - -const ECDH_Config ECDH_config[CC1352R1_LAUNCHXL_ECDHCOUNT] = { - { - .object = &ecdhCC26X2Objects[CC1352R1_LAUNCHXL_ECDH0], - .hwAttrs = &ecdhCC26X2HWAttrs[CC1352R1_LAUNCHXL_ECDH0] - }, -}; - -const uint_least8_t ECDH_count = CC1352R1_LAUNCHXL_ECDHCOUNT; - -/* - * =============================== ECDSA =============================== - */ -#include -#include - -ECDSACC26X2_Object ecdsaCC26X2Objects[CC1352R1_LAUNCHXL_ECDSACOUNT]; - -const ECDSACC26X2_HWAttrs ecdsaCC26X2HWAttrs[CC1352R1_LAUNCHXL_ECDSACOUNT] = { - { - .intPriority = ~0, - } -}; - -const ECDSA_Config ECDSA_config[CC1352R1_LAUNCHXL_ECDSACOUNT] = { - { - .object = &ecdsaCC26X2Objects[CC1352R1_LAUNCHXL_ECDSA0], - .hwAttrs = &ecdsaCC26X2HWAttrs[CC1352R1_LAUNCHXL_ECDSA0] - }, -}; - -const uint_least8_t ECDSA_count = CC1352R1_LAUNCHXL_ECDSACOUNT; - -/* - * =============================== ECJPAKE =============================== - */ -#include -#include - -ECJPAKECC26X2_Object ecjpakeCC26X2Objects[CC1352R1_LAUNCHXL_ECJPAKECOUNT]; - -const ECJPAKECC26X2_HWAttrs ecjpakeCC26X2HWAttrs[CC1352R1_LAUNCHXL_ECJPAKECOUNT] = { - { - .intPriority = ~0, - } -}; - -const ECJPAKE_Config ECJPAKE_config[CC1352R1_LAUNCHXL_ECJPAKECOUNT] = { - { - .object = &ecjpakeCC26X2Objects[CC1352R1_LAUNCHXL_ECJPAKE0], - .hwAttrs = &ecjpakeCC26X2HWAttrs[CC1352R1_LAUNCHXL_ECJPAKE0] - }, -}; - -const uint_least8_t ECJPAKE_count = CC1352R1_LAUNCHXL_ECJPAKECOUNT; - - -/* - * =============================== SHA2 =============================== - */ -#include -#include - -SHA2CC26X2_Object sha2CC26X2Objects[CC1352R1_LAUNCHXL_SHA2COUNT]; - -const SHA2CC26X2_HWAttrs sha2CC26X2HWAttrs[CC1352R1_LAUNCHXL_SHA2COUNT] = { - { - .intPriority = ~0, - } -}; - -const SHA2_Config SHA2_config[CC1352R1_LAUNCHXL_SHA2COUNT] = { - { - .object = &sha2CC26X2Objects[CC1352R1_LAUNCHXL_SHA20], - .hwAttrs = &sha2CC26X2HWAttrs[CC1352R1_LAUNCHXL_SHA20] - }, -}; - -const uint_least8_t SHA2_count = CC1352R1_LAUNCHXL_SHA2COUNT; - -/* - * =============================== AESCCM =============================== - */ -#include -#include - -AESCCMCC26XX_Object aesccmCC26XXObjects[CC1352R1_LAUNCHXL_AESCCMCOUNT]; - -const AESCCMCC26XX_HWAttrs aesccmCC26XXHWAttrs[CC1352R1_LAUNCHXL_AESCCMCOUNT] = { - { - .intPriority = ~0, - } -}; - -const AESCCM_Config AESCCM_config[CC1352R1_LAUNCHXL_AESCCMCOUNT] = { - { - .object = &aesccmCC26XXObjects[CC1352R1_LAUNCHXL_AESCCM0], - .hwAttrs = &aesccmCC26XXHWAttrs[CC1352R1_LAUNCHXL_AESCCM0] - }, -}; - -const uint_least8_t AESCCM_count = CC1352R1_LAUNCHXL_AESCCMCOUNT; - -/* - * =============================== AESGCM =============================== - */ -#include -#include - -AESGCMCC26XX_Object aesgcmCC26XXObjects[CC1352R1_LAUNCHXL_AESGCMCOUNT]; - -const AESGCMCC26XX_HWAttrs aesgcmCC26XXHWAttrs[CC1352R1_LAUNCHXL_AESGCMCOUNT] = { - { - .intPriority = ~0, - } -}; - -const AESGCM_Config AESGCM_config[CC1352R1_LAUNCHXL_AESGCMCOUNT] = { - { - .object = &aesgcmCC26XXObjects[CC1352R1_LAUNCHXL_AESGCM0], - .hwAttrs = &aesgcmCC26XXHWAttrs[CC1352R1_LAUNCHXL_AESGCM0] - }, -}; - -const uint_least8_t AESGCM_count = CC1352R1_LAUNCHXL_AESGCMCOUNT; - -/* - * =============================== AESCBC =============================== - */ -#include -#include - -AESCBCCC26XX_Object aescbcCC26XXObjects[CC1352R1_LAUNCHXL_AESCBCCOUNT]; - -const AESCBCCC26XX_HWAttrs aescbcCC26XXHWAttrs[CC1352R1_LAUNCHXL_AESCBCCOUNT] = { - { - .intPriority = ~0, - } -}; - -const AESCBC_Config AESCBC_config[CC1352R1_LAUNCHXL_AESCBCCOUNT] = { - { - .object = &aescbcCC26XXObjects[CC1352R1_LAUNCHXL_AESCBC0], - .hwAttrs = &aescbcCC26XXHWAttrs[CC1352R1_LAUNCHXL_AESCBC0] - }, -}; - -const uint_least8_t AESCBC_count = CC1352R1_LAUNCHXL_AESCBCCOUNT; - -/* - * =============================== AESCTR =============================== - */ -#include -#include - -AESCTRCC26XX_Object aesctrCC26XXObjects[CC1352R1_LAUNCHXL_AESCTRCOUNT]; - -const AESCTRCC26XX_HWAttrs aesctrCC26XXHWAttrs[CC1352R1_LAUNCHXL_AESCTRCOUNT] = { - { - .intPriority = ~0, - } -}; - -const AESCTR_Config AESCTR_config[CC1352R1_LAUNCHXL_AESCTRCOUNT] = { - { - .object = &aesctrCC26XXObjects[CC1352R1_LAUNCHXL_AESCTR0], - .hwAttrs = &aesctrCC26XXHWAttrs[CC1352R1_LAUNCHXL_AESCTR0] - }, -}; - -const uint_least8_t AESCTR_count = CC1352R1_LAUNCHXL_AESCTRCOUNT; - -/* - * =============================== AESECB =============================== - */ -#include -#include - -AESECBCC26XX_Object aesecbCC26XXObjects[CC1352R1_LAUNCHXL_AESECBCOUNT]; - -const AESECBCC26XX_HWAttrs aesecbCC26XXHWAttrs[CC1352R1_LAUNCHXL_AESECBCOUNT] = { - { - .intPriority = ~0, - } -}; - -const AESECB_Config AESECB_config[CC1352R1_LAUNCHXL_AESECBCOUNT] = { - { - .object = &aesecbCC26XXObjects[CC1352R1_LAUNCHXL_AESECB0], - .hwAttrs = &aesecbCC26XXHWAttrs[CC1352R1_LAUNCHXL_AESECB0] - }, -}; - -const uint_least8_t AESECB_count = CC1352R1_LAUNCHXL_AESECBCOUNT; - -/* - * =============================== AESCTRDRBG =============================== - */ -#include -#include - -AESCTRDRBGXX_Object aesctrdrbgXXObjects[CC1352R1_LAUNCHXL_AESCTRDRBGCOUNT]; - -const AESCTRDRBGXX_HWAttrs aesctrdrbgXXHWAttrs[CC1352R1_LAUNCHXL_AESCTRDRBGCOUNT] = { - { - .aesctrIndex = CC1352R1_LAUNCHXL_AESCTR0, - } -}; - -const AESCTRDRBG_Config AESCTRDRBG_config[CC1352R1_LAUNCHXL_AESCTRDRBGCOUNT] = { - { - .object = &aesctrdrbgXXObjects[CC1352R1_LAUNCHXL_AESCTRDRBG0], - .hwAttrs = &aesctrdrbgXXHWAttrs[CC1352R1_LAUNCHXL_AESCTRDRBG0] - }, -}; - -const uint_least8_t AESCTRDRBG_count = CC1352R1_LAUNCHXL_AESCTRDRBGCOUNT; - -/* - * =============================== TRNG =============================== - */ -#include -#include - -TRNGCC26XX_Object trngCC26XXObjects[CC1352R1_LAUNCHXL_TRNGCOUNT]; - -const TRNGCC26XX_HWAttrs trngCC26X2HWAttrs[CC1352R1_LAUNCHXL_TRNGCOUNT] = { - { - .intPriority = ~0, - .swiPriority = 0, - .samplesPerCycle = 240000, - } -}; - -const TRNG_Config TRNG_config[CC1352R1_LAUNCHXL_TRNGCOUNT] = { - { - .object = &trngCC26XXObjects[CC1352R1_LAUNCHXL_TRNG0], - .hwAttrs = &trngCC26X2HWAttrs[CC1352R1_LAUNCHXL_TRNG0] - }, -}; - -const uint_least8_t TRNG_count = CC1352R1_LAUNCHXL_TRNGCOUNT; - -/* - * =============================== Display =============================== - */ -#include -#include -#include - -#ifndef BOARD_DISPLAY_UART_STRBUF_SIZE -#define BOARD_DISPLAY_UART_STRBUF_SIZE 128 -#endif - -/* This value can be changed to 96 for use with the 430BOOST-SHARP96 BoosterPack. */ -#define BOARD_DISPLAY_SHARP_SIZE 128 - -DisplayUart_Object displayUartObject; -DisplaySharp_Object displaySharpObject; - -static char uartStringBuf[BOARD_DISPLAY_UART_STRBUF_SIZE]; -static uint_least8_t sharpDisplayBuf[BOARD_DISPLAY_SHARP_SIZE * BOARD_DISPLAY_SHARP_SIZE / 8]; - -const DisplayUart_HWAttrs displayUartHWAttrs = { - .uartIdx = CC1352R1_LAUNCHXL_UART0, - .baudRate = 115200, - .mutexTimeout = (unsigned int)(-1), - .strBuf = uartStringBuf, - .strBufLen = BOARD_DISPLAY_UART_STRBUF_SIZE, -}; - -const DisplaySharp_HWAttrsV1 displaySharpHWattrs = { - .spiIndex = CC1352R1_LAUNCHXL_SPI0, - .csPin = CC1352R1_LAUNCHXL_GPIO_LCD_CS, - .powerPin = CC1352R1_LAUNCHXL_GPIO_LCD_POWER, - .enablePin = CC1352R1_LAUNCHXL_GPIO_LCD_ENABLE, - .pixelWidth = BOARD_DISPLAY_SHARP_SIZE, - .pixelHeight = BOARD_DISPLAY_SHARP_SIZE, - .displayBuf = sharpDisplayBuf, -}; - -#ifndef BOARD_DISPLAY_USE_UART -#define BOARD_DISPLAY_USE_UART 1 -#endif -#ifndef BOARD_DISPLAY_USE_UART_ANSI -#define BOARD_DISPLAY_USE_UART_ANSI 0 -#endif -#ifndef BOARD_DISPLAY_USE_LCD -#define BOARD_DISPLAY_USE_LCD 0 -#endif - -/* - * This #if/#else is needed to workaround a problem with the - * IAR compiler. The IAR compiler doesn't like the empty array - * initialization. (IAR Error[Pe1345]) - */ -#if (BOARD_DISPLAY_USE_UART || BOARD_DISPLAY_USE_LCD) - -const Display_Config Display_config[] = { -#if (BOARD_DISPLAY_USE_UART) - { -# if (BOARD_DISPLAY_USE_UART_ANSI) - .fxnTablePtr = &DisplayUartAnsi_fxnTable, -# else /* Default to minimal UART with no cursor placement */ - .fxnTablePtr = &DisplayUartMin_fxnTable, -# endif - .object = &displayUartObject, - .hwAttrs = &displayUartHWAttrs, - }, -#endif -#if (BOARD_DISPLAY_USE_LCD) - { - .fxnTablePtr = &DisplaySharp_fxnTable, - .object = &displaySharpObject, - .hwAttrs = &displaySharpHWattrs - }, -#endif -}; - -const uint_least8_t Display_count = sizeof(Display_config) / sizeof(Display_Config); - -#else - -const Display_Config *Display_config = NULL; -const uint_least8_t Display_count = 0; - -#endif /* (BOARD_DISPLAY_USE_UART || BOARD_DISPLAY_USE_LCD) */ - -/* - * =============================== GPIO =============================== - */ -#include -#include - -/* - * Array of Pin configurations - * NOTE: The order of the pin configurations must coincide with what was - * defined in CC1352R1_LAUNCHXL.h - * NOTE: Pins not used for interrupts should be placed at the end of the - * array. Callback entries can be omitted from callbacks array to - * reduce memory usage. - */ -GPIO_PinConfig gpioPinConfigs[] = { - /* Input pins */ - GPIOCC26XX_DIO_15 | GPIO_DO_NOT_CONFIG, /* Button 0 */ - GPIOCC26XX_DIO_14 | GPIO_DO_NOT_CONFIG, /* Button 1 */ - - GPIOCC26XX_DIO_15 | GPIO_DO_NOT_CONFIG, /* CC1352R1_LAUNCHXL_SPI_MASTER_READY */ - GPIOCC26XX_DIO_21 | GPIO_DO_NOT_CONFIG, /* CC1352R1_LAUNCHXL_SPI_SLAVE_READY */ - - /* Output pins */ - GPIOCC26XX_DIO_07 | GPIO_DO_NOT_CONFIG, /* Green LED */ - GPIOCC26XX_DIO_06 | GPIO_DO_NOT_CONFIG, /* Red LED */ - GPIOCC26XX_DIO_30 | GPIO_DO_NOT_CONFIG, /* TMP116_EN */ - - /* SPI Flash CSN */ - GPIOCC26XX_DIO_20 | GPIO_DO_NOT_CONFIG, - - /* SD CS */ - GPIOCC26XX_DIO_21 | GPIO_DO_NOT_CONFIG, - - /* Sharp Display - GPIO configurations will be done in the Display files */ - GPIOCC26XX_DIO_24 | GPIO_DO_NOT_CONFIG, /* SPI chip select */ - GPIOCC26XX_DIO_22 | GPIO_DO_NOT_CONFIG, /* LCD power control */ - GPIOCC26XX_DIO_23 | GPIO_DO_NOT_CONFIG, /* LCD enable */ - -}; - -/* - * Array of callback function pointers - * NOTE: The order of the pin configurations must coincide with what was - * defined in CC1352R1_LAUNCH.h - * NOTE: Pins not used for interrupts can be omitted from callbacks array to - * reduce memory usage (if placed at end of gpioPinConfigs array). - */ -GPIO_CallbackFxn gpioCallbackFunctions[] = { - NULL, /* Button 0 */ - NULL, /* Button 1 */ - NULL, /* CC1352R1_LAUNCHXL_SPI_MASTER_READY */ - NULL, /* CC1352R1_LAUNCHXL_SPI_SLAVE_READY */ -}; - -const GPIOCC26XX_Config GPIOCC26XX_config = { - .pinConfigs = (GPIO_PinConfig *)gpioPinConfigs, - .callbacks = (GPIO_CallbackFxn *)gpioCallbackFunctions, - .numberOfPinConfigs = CC1352R1_LAUNCHXL_GPIOCOUNT, - .numberOfCallbacks = sizeof(gpioCallbackFunctions)/sizeof(GPIO_CallbackFxn), - .intPriority = (~0) -}; - -/* - * =============================== GPTimer =============================== - * Remove unused entries to reduce flash usage both in Board.c and Board.h - */ -#include - -GPTimerCC26XX_Object gptimerCC26XXObjects[CC1352R1_LAUNCHXL_GPTIMERCOUNT]; - -const GPTimerCC26XX_HWAttrs gptimerCC26xxHWAttrs[CC1352R1_LAUNCHXL_GPTIMERPARTSCOUNT] = { - { .baseAddr = GPT0_BASE, .intNum = INT_GPT0A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT0, .pinMux = GPT_PIN_0A, }, - { .baseAddr = GPT0_BASE, .intNum = INT_GPT0B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT0, .pinMux = GPT_PIN_0B, }, - { .baseAddr = GPT1_BASE, .intNum = INT_GPT1A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT1, .pinMux = GPT_PIN_1A, }, - { .baseAddr = GPT1_BASE, .intNum = INT_GPT1B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT1, .pinMux = GPT_PIN_1B, }, - { .baseAddr = GPT2_BASE, .intNum = INT_GPT2A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT2, .pinMux = GPT_PIN_2A, }, - { .baseAddr = GPT2_BASE, .intNum = INT_GPT2B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT2, .pinMux = GPT_PIN_2B, }, - { .baseAddr = GPT3_BASE, .intNum = INT_GPT3A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT3, .pinMux = GPT_PIN_3A, }, - { .baseAddr = GPT3_BASE, .intNum = INT_GPT3B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT3, .pinMux = GPT_PIN_3B, }, -}; - -const GPTimerCC26XX_Config GPTimerCC26XX_config[CC1352R1_LAUNCHXL_GPTIMERPARTSCOUNT] = { - { &gptimerCC26XXObjects[CC1352R1_LAUNCHXL_GPTIMER0], &gptimerCC26xxHWAttrs[CC1352R1_LAUNCHXL_GPTIMER0A], GPT_A }, - { &gptimerCC26XXObjects[CC1352R1_LAUNCHXL_GPTIMER0], &gptimerCC26xxHWAttrs[CC1352R1_LAUNCHXL_GPTIMER0B], GPT_B }, - { &gptimerCC26XXObjects[CC1352R1_LAUNCHXL_GPTIMER1], &gptimerCC26xxHWAttrs[CC1352R1_LAUNCHXL_GPTIMER1A], GPT_A }, - { &gptimerCC26XXObjects[CC1352R1_LAUNCHXL_GPTIMER1], &gptimerCC26xxHWAttrs[CC1352R1_LAUNCHXL_GPTIMER1B], GPT_B }, - { &gptimerCC26XXObjects[CC1352R1_LAUNCHXL_GPTIMER2], &gptimerCC26xxHWAttrs[CC1352R1_LAUNCHXL_GPTIMER2A], GPT_A }, - { &gptimerCC26XXObjects[CC1352R1_LAUNCHXL_GPTIMER2], &gptimerCC26xxHWAttrs[CC1352R1_LAUNCHXL_GPTIMER2B], GPT_B }, - { &gptimerCC26XXObjects[CC1352R1_LAUNCHXL_GPTIMER3], &gptimerCC26xxHWAttrs[CC1352R1_LAUNCHXL_GPTIMER3A], GPT_A }, - { &gptimerCC26XXObjects[CC1352R1_LAUNCHXL_GPTIMER3], &gptimerCC26xxHWAttrs[CC1352R1_LAUNCHXL_GPTIMER3B], GPT_B }, -}; - -/* - * =============================== I2C =============================== -*/ -#include -#include - -I2CCC26XX_Object i2cCC26xxObjects[CC1352R1_LAUNCHXL_I2CCOUNT]; - -const I2CCC26XX_HWAttrsV1 i2cCC26xxHWAttrs[CC1352R1_LAUNCHXL_I2CCOUNT] = { - { - .baseAddr = I2C0_BASE, - .powerMngrId = PowerCC26XX_PERIPH_I2C0, - .intNum = INT_I2C_IRQ, - .intPriority = ~0, - .swiPriority = 0, - .sdaPin = CC1352R1_LAUNCHXL_I2C0_SDA0, - .sclPin = CC1352R1_LAUNCHXL_I2C0_SCL0, - } -}; - -const I2C_Config I2C_config[CC1352R1_LAUNCHXL_I2CCOUNT] = { - { - .fxnTablePtr = &I2CCC26XX_fxnTable, - .object = &i2cCC26xxObjects[CC1352R1_LAUNCHXL_I2C0], - .hwAttrs = &i2cCC26xxHWAttrs[CC1352R1_LAUNCHXL_I2C0] - }, -}; - -const uint_least8_t I2C_count = CC1352R1_LAUNCHXL_I2CCOUNT; - -/* - * =============================== I2S =============================== -*/ -#include -#include - -I2SCC26XX_Object i2sCC26XXObjects[CC1352R1_LAUNCHXL_I2SCOUNT]; - -const I2SCC26XX_HWAttrs i2sCC26XXHWAttrs[CC1352R1_LAUNCHXL_I2SCOUNT] = { - { - .pinSD1 = CC1352R1_LAUNCHXL_I2S_ADI, - .pinSD0 = CC1352R1_LAUNCHXL_I2S_ADO, - .pinSCK = CC1352R1_LAUNCHXL_I2S_BCLK, - .pinMCLK = CC1352R1_LAUNCHXL_I2S_MCLK, - .pinWS = CC1352R1_LAUNCHXL_I2S_WCLK, - .intPriority = ~0, - } -}; - -const I2S_Config I2S_config[CC1352R1_LAUNCHXL_I2SCOUNT] = { - { - .object = &i2sCC26XXObjects[CC1352R1_LAUNCHXL_I2S0], - .hwAttrs = &i2sCC26XXHWAttrs[CC1352R1_LAUNCHXL_I2S0] - }, -}; - -const uint_least8_t I2S_count = CC1352R1_LAUNCHXL_I2SCOUNT; - -/* - * =============================== NVS =============================== - */ -#include -#include -#include - -#define NVS_REGIONS_BASE 0x48000 -#define SECTORSIZE 0x2000 -#define REGIONSIZE (SECTORSIZE * 4) - -#ifndef Board_EXCLUDE_NVS_INTERNAL_FLASH - -/* - * Reserve flash sectors for NVS driver use by placing an uninitialized byte - * array at the desired flash address. - */ -#if defined(__TI_COMPILER_VERSION__) - -/* - * Place uninitialized array at NVS_REGIONS_BASE - */ -#pragma LOCATION(flashBuf, NVS_REGIONS_BASE); -#pragma NOINIT(flashBuf); -static char flashBuf[REGIONSIZE]; - -#elif defined(__IAR_SYSTEMS_ICC__) - -/* - * Place uninitialized array at NVS_REGIONS_BASE - */ -static __no_init char flashBuf[REGIONSIZE] @ NVS_REGIONS_BASE; - -#elif defined(__GNUC__) - -/* - * Place the flash buffers in the .nvs section created in the gcc linker file. - * The .nvs section enforces alignment on a sector boundary but may - * be placed anywhere in flash memory. If desired the .nvs section can be set - * to a fixed address by changing the following in the gcc linker file: - * - * .nvs (FIXED_FLASH_ADDR) (NOLOAD) : AT (FIXED_FLASH_ADDR) { - * *(.nvs) - * } > REGION_TEXT - */ -__attribute__ ((section (".nvs"))) -static char flashBuf[REGIONSIZE]; - -#endif - -/* Allocate objects for NVS Internal Regions */ -NVSCC26XX_Object nvsCC26xxObjects[1]; - -/* Hardware attributes for NVS Internal Regions */ -const NVSCC26XX_HWAttrs nvsCC26xxHWAttrs[1] = { - { - .regionBase = (void *)flashBuf, - .regionSize = REGIONSIZE, - }, -}; - -#endif /* Board_EXCLUDE_NVS_INTERNAL_FLASH */ - -#ifndef Board_EXCLUDE_NVS_EXTERNAL_FLASH - -#define SPISECTORSIZE 0x1000 -#define SPIREGIONSIZE (SPISECTORSIZE * 32) -#define VERIFYBUFSIZE 64 - -static uint8_t verifyBuf[VERIFYBUFSIZE]; - -/* Allocate objects for NVS External Regions */ -NVSSPI25X_Object nvsSPI25XObjects[1]; - -/* Hardware attributes for NVS External Regions */ -const NVSSPI25X_HWAttrs nvsSPI25XHWAttrs[1] = { - { - .regionBaseOffset = 0, - .regionSize = SPIREGIONSIZE, - .sectorSize = SPISECTORSIZE, - .verifyBuf = verifyBuf, - .verifyBufSize = VERIFYBUFSIZE, - .spiHandle = NULL, - .spiIndex = 0, - .spiBitRate = 4000000, - .spiCsnGpioIndex = CC1352R1_LAUNCHXL_GPIO_SPI_FLASH_CS, - .statusPollDelayUs = 100, - }, -}; - -#endif /* Board_EXCLUDE_NVS_EXTERNAL_FLASH */ - -/* NVS Region index 0 and 1 refer to NVS and NVS SPI respectively */ -const NVS_Config NVS_config[CC1352R1_LAUNCHXL_NVSCOUNT] = { -#ifndef Board_EXCLUDE_NVS_INTERNAL_FLASH - { - .fxnTablePtr = &NVSCC26XX_fxnTable, - .object = &nvsCC26xxObjects[0], - .hwAttrs = &nvsCC26xxHWAttrs[0], - }, -#endif -#ifndef Board_EXCLUDE_NVS_EXTERNAL_FLASH - { - .fxnTablePtr = &NVSSPI25X_fxnTable, - .object = &nvsSPI25XObjects[0], - .hwAttrs = &nvsSPI25XHWAttrs[0], - }, -#endif -}; - -const uint_least8_t NVS_count = CC1352R1_LAUNCHXL_NVSCOUNT; - -/* - * =============================== PIN =============================== - */ -#include -#include - -const PIN_Config BoardGpioInitTable[] = { - - CC1352R1_LAUNCHXL_PIN_RLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially off */ - CC1352R1_LAUNCHXL_PIN_GLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially off */ - CC1352R1_LAUNCHXL_PIN_BTN1 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */ - CC1352R1_LAUNCHXL_PIN_BTN2 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */ - CC1352R1_LAUNCHXL_SPI_FLASH_CS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MIN, /* External flash chip select */ - CC1352R1_LAUNCHXL_UART0_RX | PIN_INPUT_EN | PIN_PULLDOWN, /* UART RX via debugger back channel */ - CC1352R1_LAUNCHXL_UART0_TX | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL, /* UART TX via debugger back channel */ - CC1352R1_LAUNCHXL_SPI0_MOSI | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI master out - slave in */ - CC1352R1_LAUNCHXL_SPI0_MISO | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI master in - slave out */ - CC1352R1_LAUNCHXL_SPI0_CLK | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI clock */ - PIN_TERMINATE -}; - -const PINCC26XX_HWAttrs PINCC26XX_hwAttrs = { - .intPriority = ~0, - .swiPriority = 0 -}; - -/* - * =============================== Power =============================== - */ -#include -#include - -const PowerCC26X2_Config PowerCC26X2_config = { - .policyInitFxn = NULL, - .policyFxn = &PowerCC26XX_standbyPolicy, - .calibrateFxn = &PowerCC26XX_calibrate, - .enablePolicy = true, - .calibrateRCOSC_LF = true, - .calibrateRCOSC_HF = true, -}; - -/* - * =============================== PWM =============================== - * Remove unused entries to reduce flash usage both in Board.c and Board.h - */ -#include -#include - -PWMTimerCC26XX_Object pwmtimerCC26xxObjects[CC1352R1_LAUNCHXL_PWMCOUNT]; - -const PWMTimerCC26XX_HwAttrs pwmtimerCC26xxHWAttrs[CC1352R1_LAUNCHXL_PWMCOUNT] = { - { .pwmPin = CC1352R1_LAUNCHXL_PWMPIN0, .gpTimerUnit = CC1352R1_LAUNCHXL_GPTIMER0A }, - { .pwmPin = CC1352R1_LAUNCHXL_PWMPIN1, .gpTimerUnit = CC1352R1_LAUNCHXL_GPTIMER0B }, - { .pwmPin = CC1352R1_LAUNCHXL_PWMPIN2, .gpTimerUnit = CC1352R1_LAUNCHXL_GPTIMER1A }, - { .pwmPin = CC1352R1_LAUNCHXL_PWMPIN3, .gpTimerUnit = CC1352R1_LAUNCHXL_GPTIMER1B }, - { .pwmPin = CC1352R1_LAUNCHXL_PWMPIN4, .gpTimerUnit = CC1352R1_LAUNCHXL_GPTIMER2A }, - { .pwmPin = CC1352R1_LAUNCHXL_PWMPIN5, .gpTimerUnit = CC1352R1_LAUNCHXL_GPTIMER2B }, - { .pwmPin = CC1352R1_LAUNCHXL_PWMPIN6, .gpTimerUnit = CC1352R1_LAUNCHXL_GPTIMER3A }, - { .pwmPin = CC1352R1_LAUNCHXL_PWMPIN7, .gpTimerUnit = CC1352R1_LAUNCHXL_GPTIMER3B }, -}; - -const PWM_Config PWM_config[CC1352R1_LAUNCHXL_PWMCOUNT] = { - { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1352R1_LAUNCHXL_PWM0], &pwmtimerCC26xxHWAttrs[CC1352R1_LAUNCHXL_PWM0] }, - { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1352R1_LAUNCHXL_PWM1], &pwmtimerCC26xxHWAttrs[CC1352R1_LAUNCHXL_PWM1] }, - { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1352R1_LAUNCHXL_PWM2], &pwmtimerCC26xxHWAttrs[CC1352R1_LAUNCHXL_PWM2] }, - { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1352R1_LAUNCHXL_PWM3], &pwmtimerCC26xxHWAttrs[CC1352R1_LAUNCHXL_PWM3] }, - { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1352R1_LAUNCHXL_PWM4], &pwmtimerCC26xxHWAttrs[CC1352R1_LAUNCHXL_PWM4] }, - { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1352R1_LAUNCHXL_PWM5], &pwmtimerCC26xxHWAttrs[CC1352R1_LAUNCHXL_PWM5] }, - { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1352R1_LAUNCHXL_PWM6], &pwmtimerCC26xxHWAttrs[CC1352R1_LAUNCHXL_PWM6] }, - { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1352R1_LAUNCHXL_PWM7], &pwmtimerCC26xxHWAttrs[CC1352R1_LAUNCHXL_PWM7] }, -}; - -const uint_least8_t PWM_count = CC1352R1_LAUNCHXL_PWMCOUNT; - -/* - * =============================== RF Driver =============================== - */ -#include - -const RFCC26XX_HWAttrsV2 RFCC26XX_hwAttrs = { - .hwiPriority = ~0, /* Lowest HWI priority */ - .swiPriority = 0, /* Lowest SWI priority */ - .xoscHfAlwaysNeeded = true, /* Keep XOSC dependency while in standby */ - .globalCallback = NULL, /* No board specific callback */ - .globalEventMask = 0 /* No events subscribed to */ -}; - -/* - * =============================== SD =============================== - */ -#include -#include - -SDSPI_Object sdspiObjects[CC1352R1_LAUNCHXL_SDCOUNT]; - -const SDSPI_HWAttrs sdspiHWAttrs[CC1352R1_LAUNCHXL_SDCOUNT] = { - { - .spiIndex = CC1352R1_LAUNCHXL_SPI0, - .spiCsGpioIndex = CC1352R1_LAUNCHXL_SDSPI_CS - } -}; - -const SD_Config SD_config[CC1352R1_LAUNCHXL_SDCOUNT] = { - { - .fxnTablePtr = &SDSPI_fxnTable, - .object = &sdspiObjects[CC1352R1_LAUNCHXL_SDSPI0], - .hwAttrs = &sdspiHWAttrs[CC1352R1_LAUNCHXL_SDSPI0] - }, -}; - -const uint_least8_t SD_count = CC1352R1_LAUNCHXL_SDCOUNT; - -/* - * =============================== SPI DMA =============================== - */ -#include -#include - -SPICC26X2DMA_Object spiCC26X2DMAObjects[CC1352R1_LAUNCHXL_SPICOUNT]; - -/* - * NOTE: The SPI instances below can be used by the SD driver to communicate - * with a SD card via SPI. The 'defaultTxBufValue' fields below are set to 0xFF - * to satisfy the SDSPI driver requirement. - */ -const SPICC26X2DMA_HWAttrs spiCC26X2DMAHWAttrs[CC1352R1_LAUNCHXL_SPICOUNT] = { - { - .baseAddr = SSI0_BASE, - .intNum = INT_SSI0_COMB, - .intPriority = ~0, - .swiPriority = 0, - .powerMngrId = PowerCC26XX_PERIPH_SSI0, - .defaultTxBufValue = 0xFF, - .rxChannelBitMask = 1< -#include - -UARTCC26XX_Object uartCC26XXObjects[CC1352R1_LAUNCHXL_UARTCOUNT]; - -uint8_t uartCC26XXRingBuffer[CC1352R1_LAUNCHXL_UARTCOUNT][32]; - -const UARTCC26XX_HWAttrsV2 uartCC26XXHWAttrs[CC1352R1_LAUNCHXL_UARTCOUNT] = { - { - .baseAddr = UART0_BASE, - .powerMngrId = PowerCC26XX_PERIPH_UART0, - .intNum = INT_UART0_COMB, - .intPriority = ~0, - .swiPriority = 0, - .txPin = CC1352R1_LAUNCHXL_UART0_TX, - .rxPin = CC1352R1_LAUNCHXL_UART0_RX, - .ctsPin = PIN_UNASSIGNED, - .rtsPin = PIN_UNASSIGNED, - .ringBufPtr = uartCC26XXRingBuffer[CC1352R1_LAUNCHXL_UART0], - .ringBufSize = sizeof(uartCC26XXRingBuffer[CC1352R1_LAUNCHXL_UART0]), - .txIntFifoThr = UARTCC26XX_FIFO_THRESHOLD_1_8, - .rxIntFifoThr = UARTCC26XX_FIFO_THRESHOLD_4_8, - .errorFxn = NULL - }, - { - .baseAddr = UART1_BASE, - .powerMngrId = PowerCC26X2_PERIPH_UART1, - .intNum = INT_UART1_COMB, - .intPriority = ~0, - .swiPriority = 0, - .txPin = CC1352R1_LAUNCHXL_UART1_TX, - .rxPin = CC1352R1_LAUNCHXL_UART1_RX, - .ctsPin = PIN_UNASSIGNED, - .rtsPin = PIN_UNASSIGNED, - .ringBufPtr = uartCC26XXRingBuffer[CC1352R1_LAUNCHXL_UART1], - .ringBufSize = sizeof(uartCC26XXRingBuffer[CC1352R1_LAUNCHXL_UART1]), - .txIntFifoThr = UARTCC26XX_FIFO_THRESHOLD_1_8, - .rxIntFifoThr = UARTCC26XX_FIFO_THRESHOLD_4_8, - .errorFxn = NULL - } -}; - -const UART_Config UART_config[CC1352R1_LAUNCHXL_UARTCOUNT] = { - { - .fxnTablePtr = &UARTCC26XX_fxnTable, - .object = &uartCC26XXObjects[CC1352R1_LAUNCHXL_UART0], - .hwAttrs = &uartCC26XXHWAttrs[CC1352R1_LAUNCHXL_UART0] - }, - { - .fxnTablePtr = &UARTCC26XX_fxnTable, - .object = &uartCC26XXObjects[CC1352R1_LAUNCHXL_UART1], - .hwAttrs = &uartCC26XXHWAttrs[CC1352R1_LAUNCHXL_UART1] - }, -}; - -const uint_least8_t UART_count = CC1352R1_LAUNCHXL_UARTCOUNT; - -/* - * =============================== UDMA =============================== - */ -#include - -UDMACC26XX_Object udmaObjects[CC1352R1_LAUNCHXL_UDMACOUNT]; - -const UDMACC26XX_HWAttrs udmaHWAttrs[CC1352R1_LAUNCHXL_UDMACOUNT] = { - { - .baseAddr = UDMA0_BASE, - .powerMngrId = PowerCC26XX_PERIPH_UDMA, - .intNum = INT_DMA_ERR, - .intPriority = ~0 - } -}; - -const UDMACC26XX_Config UDMACC26XX_config[CC1352R1_LAUNCHXL_UDMACOUNT] = { - { - .object = &udmaObjects[CC1352R1_LAUNCHXL_UDMA0], - .hwAttrs = &udmaHWAttrs[CC1352R1_LAUNCHXL_UDMA0] - }, -}; - - - -/* - * =============================== Watchdog =============================== - */ -#include -#include - -WatchdogCC26XX_Object watchdogCC26XXObjects[CC1352R1_LAUNCHXL_WATCHDOGCOUNT]; - -const WatchdogCC26XX_HWAttrs watchdogCC26XXHWAttrs[CC1352R1_LAUNCHXL_WATCHDOGCOUNT] = { - { - .baseAddr = WDT_BASE, - .reloadValue = 1000 /* Reload value in milliseconds */ - }, -}; - -const Watchdog_Config Watchdog_config[CC1352R1_LAUNCHXL_WATCHDOGCOUNT] = { - { - .fxnTablePtr = &WatchdogCC26XX_fxnTable, - .object = &watchdogCC26XXObjects[CC1352R1_LAUNCHXL_WATCHDOG0], - .hwAttrs = &watchdogCC26XXHWAttrs[CC1352R1_LAUNCHXL_WATCHDOG0] - }, -}; - -const uint_least8_t Watchdog_count = CC1352R1_LAUNCHXL_WATCHDOGCOUNT; - -/* - * Board-specific initialization function to disable external flash. - * This function is defined in the file CC1352R1_LAUNCHXL_fxns.c - */ -extern void Board_initHook(void); - -/* - * ======== CC1352R1_LAUNCHXL_initGeneral ======== - */ -void CC1352R1_LAUNCHXL_initGeneral(void) -{ - Power_init(); - - if (PIN_init(BoardGpioInitTable) != PIN_SUCCESS) { - /* Error with PIN_init */ - while (1); - } - - /* Perform board-specific initialization */ - Board_initHook(); -} - -/* - * ======== Board_init ======== - */ -void Board_init(void) -{ - CC1352R1_LAUNCHXL_initGeneral(); -} diff --git a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/CC1352R1_LAUNCHXL.h b/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/CC1352R1_LAUNCHXL.h deleted file mode 100644 index 7a8905337f..0000000000 --- a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/CC1352R1_LAUNCHXL.h +++ /dev/null @@ -1,502 +0,0 @@ -/* - * Copyright (c) 2017-2019, Texas Instruments Incorporated - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of Texas Instruments Incorporated nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -/** =========================================================================== - * @file CC1352R1_LAUNCHXL.h - * - * @brief CC1352R1_LAUNCHXL Board Specific header file. - * - * The CC1352R1_LAUNCHXL header file should be included in an application as - * follows: - * @code - * #include "CC1352R1_LAUNCHXL.h" - * @endcode - * - * =========================================================================== - */ -#ifndef __CC1352R1_LAUNCHXL_BOARD_H__ -#define __CC1352R1_LAUNCHXL_BOARD_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes */ -#include -#include - -/* Externs */ -extern const PIN_Config BoardGpioInitTable[]; - -/* Defines */ -#define CC1352R1_LAUNCHXL - -/* Mapping of pins to board signals using general board aliases - * - */ - -/* Mapping of pins to board signals using general board aliases - * - */ -/* Analog Capable DIOs */ -#define CC1352R1_LAUNCHXL_DIO23_ANALOG IOID_23 -#define CC1352R1_LAUNCHXL_DIO24_ANALOG IOID_24 -#define CC1352R1_LAUNCHXL_DIO25_ANALOG IOID_25 -#define CC1352R1_LAUNCHXL_DIO26_ANALOG IOID_26 -#define CC1352R1_LAUNCHXL_DIO27_ANALOG IOID_27 -#define CC1352R1_LAUNCHXL_DIO28_ANALOG IOID_28 -#define CC1352R1_LAUNCHXL_DIO29_ANALOG IOID_29 - -/* Digital IOs */ -#define CC1352R1_LAUNCHXL_DIO12 IOID_12 -#define CC1352R1_LAUNCHXL_DIO15 IOID_15 -#define CC1352R1_LAUNCHXL_DIO16_TDO IOID_16 -#define CC1352R1_LAUNCHXL_DIO17_TDI IOID_17 -#define CC1352R1_LAUNCHXL_DIO21 IOID_21 -#define CC1352R1_LAUNCHXL_DIO22 IOID_22 -#define CC1352R1_LAUNCHXL_DIO30 IOID_30 - -/* Discrete Inputs */ -#define CC1352R1_LAUNCHXL_PIN_BTN1 IOID_15 -#define CC1352R1_LAUNCHXL_PIN_BTN2 IOID_14 - -/* GPIO */ -#define CC1352R1_LAUNCHXL_GPIO_LED_ON 1 -#define CC1352R1_LAUNCHXL_GPIO_LED_OFF 0 - -/* I2C */ -#define CC1352R1_LAUNCHXL_I2C0_SCL0 IOID_4 -#define CC1352R1_LAUNCHXL_I2C0_SDA0 IOID_5 - -/* I2S */ -#define CC1352R1_LAUNCHXL_I2S_ADO IOID_25 -#define CC1352R1_LAUNCHXL_I2S_ADI IOID_26 -#define CC1352R1_LAUNCHXL_I2S_BCLK IOID_27 -#define CC1352R1_LAUNCHXL_I2S_MCLK PIN_UNASSIGNED -#define CC1352R1_LAUNCHXL_I2S_WCLK IOID_28 - -/* LEDs */ -#define CC1352R1_LAUNCHXL_PIN_LED_ON 1 -#define CC1352R1_LAUNCHXL_PIN_LED_OFF 0 -#define CC1352R1_LAUNCHXL_PIN_RLED IOID_6 -#define CC1352R1_LAUNCHXL_PIN_GLED IOID_7 - -/* PWM Outputs */ -#define CC1352R1_LAUNCHXL_PWMPIN0 CC1352R1_LAUNCHXL_PIN_RLED -#define CC1352R1_LAUNCHXL_PWMPIN1 CC1352R1_LAUNCHXL_PIN_GLED -#define CC1352R1_LAUNCHXL_PWMPIN2 PIN_UNASSIGNED -#define CC1352R1_LAUNCHXL_PWMPIN3 PIN_UNASSIGNED -#define CC1352R1_LAUNCHXL_PWMPIN4 PIN_UNASSIGNED -#define CC1352R1_LAUNCHXL_PWMPIN5 PIN_UNASSIGNED -#define CC1352R1_LAUNCHXL_PWMPIN6 PIN_UNASSIGNED -#define CC1352R1_LAUNCHXL_PWMPIN7 PIN_UNASSIGNED - -/* SPI */ -#define CC1352R1_LAUNCHXL_SPI_FLASH_CS IOID_20 -#define CC1352R1_LAUNCHXL_FLASH_CS_ON 0 -#define CC1352R1_LAUNCHXL_FLASH_CS_OFF 1 - -/* SPI Board */ -#define CC1352R1_LAUNCHXL_SPI0_MISO IOID_8 /* RF1.20 */ -#define CC1352R1_LAUNCHXL_SPI0_MOSI IOID_9 /* RF1.18 */ -#define CC1352R1_LAUNCHXL_SPI0_CLK IOID_10 /* RF1.16 */ -#define CC1352R1_LAUNCHXL_SPI0_CSN IOID_11 -#define CC1352R1_LAUNCHXL_SPI1_MISO PIN_UNASSIGNED -#define CC1352R1_LAUNCHXL_SPI1_MOSI PIN_UNASSIGNED -#define CC1352R1_LAUNCHXL_SPI1_CLK PIN_UNASSIGNED -#define CC1352R1_LAUNCHXL_SPI1_CSN PIN_UNASSIGNED - -/* UART Board */ -#define CC1352R1_LAUNCHXL_UART0_RX IOID_12 /* RXD */ -#define CC1352R1_LAUNCHXL_UART0_TX IOID_13 /* TXD */ -#define CC1352R1_LAUNCHXL_UART0_CTS IOID_19 /* CTS */ -#define CC1352R1_LAUNCHXL_UART0_RTS IOID_18 /* RTS */ -#define CC1352R1_LAUNCHXL_UART1_RX PIN_UNASSIGNED -#define CC1352R1_LAUNCHXL_UART1_TX PIN_UNASSIGNED -#define CC1352R1_LAUNCHXL_UART1_CTS PIN_UNASSIGNED -#define CC1352R1_LAUNCHXL_UART1_RTS PIN_UNASSIGNED -/* For backward compatibility */ -#define CC1352R1_LAUNCHXL_UART_RX CC1352R1_LAUNCHXL_UART0_RX -#define CC1352R1_LAUNCHXL_UART_TX CC1352R1_LAUNCHXL_UART0_TX -#define CC1352R1_LAUNCHXL_UART_CTS CC1352R1_LAUNCHXL_UART0_CTS -#define CC1352R1_LAUNCHXL_UART_RTS CC1352R1_LAUNCHXL_UART0_RTS - -/*! - * @brief Initialize the general board specific settings - * - * This function initializes the general board specific settings. - */ -void CC1352R1_LAUNCHXL_initGeneral(void); - -/*! - * @brief Shut down the external flash present on the board files - * - * This function bitbangs the SPI sequence necessary to turn off - * the external flash on LaunchPads. - */ -void CC1352R1_LAUNCHXL_shutDownExtFlash(void); - -/*! - * @brief Wake up the external flash present on the board files - * - * This function toggles the chip select for the amount of time needed - * to wake the chip up. - */ -void CC1352R1_LAUNCHXL_wakeUpExtFlash(void); - -/*! - * @def CC1352R1_LAUNCHXL_ADCBufName - * @brief Enum of ADCs - */ -typedef enum CC1352R1_LAUNCHXL_ADCBufName { - CC1352R1_LAUNCHXL_ADCBUF0 = 0, - - CC1352R1_LAUNCHXL_ADCBUFCOUNT -} CC1352R1_LAUNCHXL_ADCBufName; - -/*! - * @def CC1352R1_LAUNCHXL_ADCBuf0SourceName - * @brief Enum of ADCBuf channels - */ -typedef enum CC1352R1_LAUNCHXL_ADCBuf0ChannelName { - CC1352R1_LAUNCHXL_ADCBUF0CHANNEL0 = 0, - CC1352R1_LAUNCHXL_ADCBUF0CHANNEL1, - CC1352R1_LAUNCHXL_ADCBUF0CHANNEL2, - CC1352R1_LAUNCHXL_ADCBUF0CHANNEL3, - CC1352R1_LAUNCHXL_ADCBUF0CHANNEL4, - CC1352R1_LAUNCHXL_ADCBUF0CHANNEL5, - CC1352R1_LAUNCHXL_ADCBUF0CHANNEL6, - CC1352R1_LAUNCHXL_ADCBUF0CHANNELVDDS, - CC1352R1_LAUNCHXL_ADCBUF0CHANNELDCOUPL, - CC1352R1_LAUNCHXL_ADCBUF0CHANNELVSS, - - CC1352R1_LAUNCHXL_ADCBUF0CHANNELCOUNT -} CC1352R1_LAUNCHXL_ADCBuf0ChannelName; - -/*! - * @def CC1352R1_LAUNCHXL_ADCName - * @brief Enum of ADCs - */ -typedef enum CC1352R1_LAUNCHXL_ADCName { - CC1352R1_LAUNCHXL_ADC0 = 0, - CC1352R1_LAUNCHXL_ADC1, - CC1352R1_LAUNCHXL_ADC2, - CC1352R1_LAUNCHXL_ADC3, - CC1352R1_LAUNCHXL_ADC4, - CC1352R1_LAUNCHXL_ADC5, - CC1352R1_LAUNCHXL_ADC6, - CC1352R1_LAUNCHXL_ADCDCOUPL, - CC1352R1_LAUNCHXL_ADCVSS, - CC1352R1_LAUNCHXL_ADCVDDS, - - CC1352R1_LAUNCHXL_ADCCOUNT -} CC1352R1_LAUNCHXL_ADCName; - -/*! - * @def CC1352R1_LAUNCHXL_ECDHName - * @brief Enum of ECDH names - */ -typedef enum CC1352R1_LAUNCHXL_ECDHName { - CC1352R1_LAUNCHXL_ECDH0 = 0, - - CC1352R1_LAUNCHXL_ECDHCOUNT -} CC1352R1_LAUNCHXL_ECDHName; - -/*! - * @def CC1352R1_LAUNCHXL_ECDSAName - * @brief Enum of ECDSA names - */ -typedef enum CC1352R1_LAUNCHXL_ECDSAName { - CC1352R1_LAUNCHXL_ECDSA0 = 0, - - CC1352R1_LAUNCHXL_ECDSACOUNT -} CC1352R1_LAUNCHXL_ECDSAName; - -/*! - * @def CC1352R1_LAUNCHXL_ECJPAKEName - * @brief Enum of ECJPAKE names - */ -typedef enum CC1352R1_LAUNCHXL_ECJPAKEName { - CC1352R1_LAUNCHXL_ECJPAKE0 = 0, - - CC1352R1_LAUNCHXL_ECJPAKECOUNT -} CC1352R1_LAUNCHXL_ECJPAKEName; - -/*! - * @def CC1352R1_LAUNCHXL_AESCCMName - * @brief Enum of AESCCM names - */ -typedef enum CC1352R1_LAUNCHXL_AESCCMName { - CC1352R1_LAUNCHXL_AESCCM0 = 0, - - CC1352R1_LAUNCHXL_AESCCMCOUNT -} CC1352R1_LAUNCHXL_AESCCMName; - -/*! - * @def CC1352R1_LAUNCHXL_AESGCMName - * @brief Enum of AESGCM names - */ -typedef enum CC1352R1_LAUNCHXL_AESGCMName { - CC1352R1_LAUNCHXL_AESGCM0 = 0, - - CC1352R1_LAUNCHXL_AESGCMCOUNT -} CC1352R1_LAUNCHXL_AESGCMName; - -/*! - * @def CC1352R1_LAUNCHXL_AESCBCName - * @brief Enum of AESCBC names - */ -typedef enum CC1352R1_LAUNCHXL_AESCBCName { - CC1352R1_LAUNCHXL_AESCBC0 = 0, - - CC1352R1_LAUNCHXL_AESCBCCOUNT -} CC1352R1_LAUNCHXL_AESCBCName; - -/*! - * @def CC1352R1_LAUNCHXL_AESCTRName - * @brief Enum of AESCTR names - */ -typedef enum CC1352R1_LAUNCHXL_AESCTRName { - CC1352R1_LAUNCHXL_AESCTR0 = 0, - - CC1352R1_LAUNCHXL_AESCTRCOUNT -} CC1352R1_LAUNCHXL_AESCTRName; - -/*! - * @def CC1352R1_LAUNCHXL_AESECBName - * @brief Enum of AESECB names - */ -typedef enum CC1352R1_LAUNCHXL_AESECBName { - CC1352R1_LAUNCHXL_AESECB0 = 0, - - CC1352R1_LAUNCHXL_AESECBCOUNT -} CC1352R1_LAUNCHXL_AESECBName; - -/*! - * @def CC1352R1_LAUNCHXL_AESCTRDRBGName - * @brief Enum of AESCTRDRBG names - */ -typedef enum CC1352R1_LAUNCHXL_AESCTRDRBGName { - CC1352R1_LAUNCHXL_AESCTRDRBG0 = 0, - - CC1352R1_LAUNCHXL_AESCTRDRBGCOUNT -} CC1352R1_LAUNCHXL_AESCTRDRBGName; - -/*! - * @def CC1352R1_LAUNCHXL_SHA2Name - * @brief Enum of SHA2 names - */ -typedef enum CC1352R1_LAUNCHXL_SHA2Name { - CC1352R1_LAUNCHXL_SHA20 = 0, - - CC1352R1_LAUNCHXL_SHA2COUNT -} CC1352R1_LAUNCHXL_SHA2Name; - -/*! - * @def CC1352R1_LAUNCHXL_TRNGName - * @brief Enum of TRNG names - */ -typedef enum CC1352R1_LAUNCHXL_TRNGName { - CC1352R1_LAUNCHXL_TRNG0 = 0, - - CC1352R1_LAUNCHXL_TRNGCOUNT -} CC1352R1_LAUNCHXL_TRNGName; - -/*! - * @def CC1352R1_LAUNCHXL_GPIOName - * @brief Enum of GPIO names - */ -typedef enum CC1352R1_LAUNCHXL_GPIOName { - CC1352R1_LAUNCHXL_GPIO_S1 = 0, - CC1352R1_LAUNCHXL_GPIO_S2, - CC1352R1_LAUNCHXL_SPI_MASTER_READY, - CC1352R1_LAUNCHXL_SPI_SLAVE_READY, - CC1352R1_LAUNCHXL_GPIO_LED_GREEN, - CC1352R1_LAUNCHXL_GPIO_LED_RED, - CC1352R1_LAUNCHXL_GPIO_TMP116_EN, - CC1352R1_LAUNCHXL_GPIO_SPI_FLASH_CS, - CC1352R1_LAUNCHXL_SDSPI_CS, - CC1352R1_LAUNCHXL_GPIO_LCD_CS, - CC1352R1_LAUNCHXL_GPIO_LCD_POWER, - CC1352R1_LAUNCHXL_GPIO_LCD_ENABLE, - CC1352R1_LAUNCHXL_GPIOCOUNT -} CC1352R1_LAUNCHXL_GPIOName; - -/*! - * @def CC1352R1_LAUNCHXL_GPTimerName - * @brief Enum of GPTimer parts - */ -typedef enum CC1352R1_LAUNCHXL_GPTimerName { - CC1352R1_LAUNCHXL_GPTIMER0A = 0, - CC1352R1_LAUNCHXL_GPTIMER0B, - CC1352R1_LAUNCHXL_GPTIMER1A, - CC1352R1_LAUNCHXL_GPTIMER1B, - CC1352R1_LAUNCHXL_GPTIMER2A, - CC1352R1_LAUNCHXL_GPTIMER2B, - CC1352R1_LAUNCHXL_GPTIMER3A, - CC1352R1_LAUNCHXL_GPTIMER3B, - - CC1352R1_LAUNCHXL_GPTIMERPARTSCOUNT -} CC1352R1_LAUNCHXL_GPTimerName; - -/*! - * @def CC1352R1_LAUNCHXL_GPTimers - * @brief Enum of GPTimers - */ -typedef enum CC1352R1_LAUNCHXL_GPTimers { - CC1352R1_LAUNCHXL_GPTIMER0 = 0, - CC1352R1_LAUNCHXL_GPTIMER1, - CC1352R1_LAUNCHXL_GPTIMER2, - CC1352R1_LAUNCHXL_GPTIMER3, - - CC1352R1_LAUNCHXL_GPTIMERCOUNT -} CC1352R1_LAUNCHXL_GPTimers; - -/*! - * @def CC1352R1_LAUNCHXL_I2CName - * @brief Enum of I2C names - */ -typedef enum CC1352R1_LAUNCHXL_I2CName { - CC1352R1_LAUNCHXL_I2C0 = 0, - - CC1352R1_LAUNCHXL_I2CCOUNT -} CC1352R1_LAUNCHXL_I2CName; - -/*! - * @def CC1352R1_LAUNCHXL_I2SName - * @brief Enum of I2S names - */ -typedef enum CC1352R1_LAUNCHXL_I2SName { - CC1352R1_LAUNCHXL_I2S0 = 0, - - CC1352R1_LAUNCHXL_I2SCOUNT -} CC1352R1_LAUNCHXL_I2SName; - -/*! - * @def CC1352R1_LAUNCHXL_PDMName - * @brief Enum of I2S names - */ -typedef enum CC1352R1_LAUNCHXL_PDMCOUNT { - CC1352R1_LAUNCHXL_PDM0 = 0, - - CC1352R1_LAUNCHXL_PDMCOUNT -} CC1352R1_LAUNCHXL_PDMName; - -/*! - * @def CC1352R1_LAUNCHXL_NVSName - * @brief Enum of NVS names - */ -typedef enum CC1352R1_LAUNCHXL_NVSName { -#ifndef Board_EXCLUDE_NVS_INTERNAL_FLASH - CC1352R1_LAUNCHXL_NVSCC26XX0 = 0, -#endif -#ifndef Board_EXCLUDE_NVS_EXTERNAL_FLASH - CC1352R1_LAUNCHXL_NVSSPI25X0, -#endif - - CC1352R1_LAUNCHXL_NVSCOUNT -} CC1352R1_LAUNCHXL_NVSName; - -/*! - * @def CC1352R1_LAUNCHXL_PWM - * @brief Enum of PWM outputs - */ -typedef enum CC1352R1_LAUNCHXL_PWMName { - CC1352R1_LAUNCHXL_PWM0 = 0, - CC1352R1_LAUNCHXL_PWM1, - CC1352R1_LAUNCHXL_PWM2, - CC1352R1_LAUNCHXL_PWM3, - CC1352R1_LAUNCHXL_PWM4, - CC1352R1_LAUNCHXL_PWM5, - CC1352R1_LAUNCHXL_PWM6, - CC1352R1_LAUNCHXL_PWM7, - - CC1352R1_LAUNCHXL_PWMCOUNT -} CC1352R1_LAUNCHXL_PWMName; - -/*! - * @def CC1352R1_LAUNCHXL_SDName - * @brief Enum of SD names - */ -typedef enum CC1352R1_LAUNCHXL_SDName { - CC1352R1_LAUNCHXL_SDSPI0 = 0, - - CC1352R1_LAUNCHXL_SDCOUNT -} CC1352R1_LAUNCHXL_SDName; - -/*! - * @def CC1352R1_LAUNCHXL_SPIName - * @brief Enum of SPI names - */ -typedef enum CC1352R1_LAUNCHXL_SPIName { - CC1352R1_LAUNCHXL_SPI0 = 0, - CC1352R1_LAUNCHXL_SPI1, - - CC1352R1_LAUNCHXL_SPICOUNT -} CC1352R1_LAUNCHXL_SPIName; - -/*! - * @def CC1352R1_LAUNCHXL_UARTName - * @brief Enum of UARTs - */ -typedef enum CC1352R1_LAUNCHXL_UARTName { - CC1352R1_LAUNCHXL_UART0 = 0, - CC1352R1_LAUNCHXL_UART1, - - CC1352R1_LAUNCHXL_UARTCOUNT -} CC1352R1_LAUNCHXL_UARTName; - -/*! - * @def CC1352R1_LAUNCHXL_UDMAName - * @brief Enum of DMA buffers - */ -typedef enum CC1352R1_LAUNCHXL_UDMAName { - CC1352R1_LAUNCHXL_UDMA0 = 0, - - CC1352R1_LAUNCHXL_UDMACOUNT -} CC1352R1_LAUNCHXL_UDMAName; - -/*! - * @def CC1352R1_LAUNCHXL_WatchdogName - * @brief Enum of Watchdogs - */ -typedef enum CC1352R1_LAUNCHXL_WatchdogName { - CC1352R1_LAUNCHXL_WATCHDOG0 = 0, - - CC1352R1_LAUNCHXL_WATCHDOGCOUNT -} CC1352R1_LAUNCHXL_WatchdogName; - - -#ifdef __cplusplus -} -#endif - -#endif /* __CC1352R1_LAUNCHXL_BOARD_H__ */ diff --git a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/CC1352R1_LAUNCHXL_fxns.c b/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/CC1352R1_LAUNCHXL_fxns.c index bdf2960ec8..a4d3bd12b6 100644 --- a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/CC1352R1_LAUNCHXL_fxns.c +++ b/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/CC1352R1_LAUNCHXL_fxns.c @@ -42,7 +42,6 @@ #include #include -#include #include #include @@ -57,12 +56,13 @@ void CC1352R1_LAUNCHXL_sendExtFlashByte(PIN_Handle pinHandle, uint8_t byte) /* SPI Flash CS */ PIN_setOutputValue(pinHandle, IOID_20, 0); - for (i = 0; i < 8; i++) { - PIN_setOutputValue(pinHandle, IOID_10, 0); /* SPI Flash CLK */ + for (i = 0; i < 8; i++) + { + PIN_setOutputValue(pinHandle, IOID_10, 0); /* SPI Flash CLK */ /* SPI Flash MOSI */ PIN_setOutputValue(pinHandle, IOID_9, (byte >> (7 - i)) & 0x01); - PIN_setOutputValue(pinHandle, IOID_10, 1); /* SPI Flash CLK */ + PIN_setOutputValue(pinHandle, IOID_10, 1); /* SPI Flash CLK */ /* * Waste a few cycles to keep the CLK high for at @@ -72,8 +72,8 @@ void CC1352R1_LAUNCHXL_sendExtFlashByte(PIN_Handle pinHandle, uint8_t byte) CPUdelay(8); } - PIN_setOutputValue(pinHandle, IOID_10, 0); /* CLK */ - PIN_setOutputValue(pinHandle, IOID_20, 1); /* CS */ + PIN_setOutputValue(pinHandle, IOID_10, 0); /* CLK */ + PIN_setOutputValue(pinHandle, IOID_20, 1); /* CS */ /* * Keep CS high at least 40 us @@ -89,10 +89,8 @@ void CC1352R1_LAUNCHXL_wakeUpExtFlash(void) { PIN_Config extFlashPinTable[] = { /* SPI Flash CS */ - IOID_20 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | - PIN_INPUT_DIS | PIN_DRVSTR_MED, - PIN_TERMINATE - }; + IOID_20 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_INPUT_DIS | PIN_DRVSTR_MED, + PIN_TERMINATE}; PIN_State extFlashPinState; PIN_Handle extFlashPinHandle = PIN_open(&extFlashPinState, extFlashPinTable); @@ -125,18 +123,14 @@ void CC1352R1_LAUNCHXL_shutDownExtFlash(void) PIN_Config extFlashPinTable[] = { /* SPI Flash CS*/ - IOID_20 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | - PIN_INPUT_DIS | PIN_DRVSTR_MED, + IOID_20 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_INPUT_DIS | PIN_DRVSTR_MED, /* SPI Flash CLK */ - IOID_10 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | - PIN_INPUT_DIS | PIN_DRVSTR_MED, + IOID_10 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_INPUT_DIS | PIN_DRVSTR_MED, /* SPI Flash MOSI */ - IOID_9 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | - PIN_INPUT_DIS | PIN_DRVSTR_MED, + IOID_9 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_INPUT_DIS | PIN_DRVSTR_MED, /* SPI Flash MISO */ IOID_8 | PIN_INPUT_EN | PIN_PULLDOWN, - PIN_TERMINATE - }; + PIN_TERMINATE}; PIN_State extFlashPinState; PIN_Handle extFlashPinHandle = PIN_open(&extFlashPinState, extFlashPinTable); diff --git a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/CMakeLists.txt b/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/CMakeLists.txt index afdf7b33d7..9da645ee53 100644 --- a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/CMakeLists.txt +++ b/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # @@ -37,6 +37,64 @@ add_subdirectory("common") # add_subdirectory("nanoBooter") add_subdirectory("nanoCLR") +####################################### + +# copy Sys Config file to build directory +add_custom_command( + OUTPUT + ${CMAKE_CURRENT_BINARY_DIR}/TI_CC1352R1_LAUNCHXL.syscfg + COMMAND ${CMAKE_COMMAND} -E copy + ${CMAKE_CURRENT_SOURCE_DIR}/TI_CC1352R1_LAUNCHXL.syscfg + ${CMAKE_CURRENT_BINARY_DIR}/TI_CC1352R1_LAUNCHXL.syscfg + COMMENT "Copy TI-RTOS configuration file to build directory" +) + +# execute Sys Config with configuration file +add_custom_command( + OUTPUT + ${CMAKE_CURRENT_BINARY_DIR}/syscfg/ti_devices_config.c + ${CMAKE_CURRENT_BINARY_DIR}/syscfg/ti_drivers_config.c + ${CMAKE_CURRENT_BINARY_DIR}/syscfg/ti_easylink_config.c + ${CMAKE_CURRENT_BINARY_DIR}/syscfg/ti_radio_config.c + + DEPENDS + ${CMAKE_CURRENT_BINARY_DIR}/TI_CC1352R1_LAUNCHXL.syscfg + + COMMAND ${CMAKE_BINARY_DIR}/TI_SysConfig_Source/sysconfig_cli.bat -s "${PROJECT_BINARY_DIR}/SimpleLinkCC13x2_26x2SDK_Source/.metadata/product.json" -o "syscfg" --compiler gcc TI_CC1352R1_LAUNCHXL.syscfg + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMENT "Generate configuration files" +) + +###################################### + +# need to copy the configuration file to the build directory +# because the obj files resulting from TI-RTOS build are placed in the same directory as the configuration file +if(CMAKE_BUILD_TYPE MATCHES Debug OR CMAKE_BUILD_TYPE MATCHES RelWithDebInfo) + set(TI_RTOS_CONFIG_FILE ti-rtos-debug.cfg) +else() + set(TI_RTOS_CONFIG_FILE ti-rtos-release.cfg) +endif() + +# need to use a specific target because TARGET dependency PRE_BUILT doesn't work on NINJA build files + +add_custom_target( + COPY_TIRTOS_CONFIG + + COMMAND ${CMAKE_COMMAND} -E copy + ${CMAKE_CURRENT_SOURCE_DIR}/${TI_RTOS_CONFIG_FILE} + ${CMAKE_CURRENT_BINARY_DIR}/${TI_RTOS_CONFIG_FILE} + COMMENT "Copy TI-RTOS configuration file to build directory" +) + +add_custom_target( + TIRTOS_CONFIG + + COMMAND ${CMAKE_BINARY_DIR}/TI_XDCTools_Source/xs.exe --xdcpath="${PROJECT_BINARY_DIR}/SimpleLinkCC13x2_26x2SDK_Source/source\;${PROJECT_BINARY_DIR}/SimpleLinkCC13x2_26x2SDK_Source/kernel/tirtos/packages" xdc.tools.configuro -o configPkg -t gnu.targets.arm.M4F -p ti.platforms.simplelink:CC1352 -r release -c "${TOOLCHAIN_PREFIX}" --compileOptions " -DDeviceFamily_CC13X2 " "${CMAKE_CURRENT_BINARY_DIR}/${TI_RTOS_CONFIG_FILE}" + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + + COMMENT "Generate TI-RTOS configuration" +) + ####################### # nanoCLR executable @@ -44,11 +102,10 @@ add_executable( # executables for project, project sources ${NANOCLR_PROJECT_NAME}.elf - "${CMAKE_CURRENT_SOURCE_DIR}/ccfg.c" - "${CMAKE_CURRENT_SOURCE_DIR}/target_common.c" - "${CMAKE_CURRENT_SOURCE_DIR}/target_Power.c" - "${CMAKE_CURRENT_SOURCE_DIR}/CC1352R1_LAUNCHXL.c" - "${CMAKE_CURRENT_SOURCE_DIR}/CC1352R1_LAUNCHXL_fxns.c" + # ${CMAKE_CURRENT_SOURCE_DIR}/ccfg.c + ${CMAKE_CURRENT_SOURCE_DIR}/target_common.c + ${CMAKE_CURRENT_SOURCE_DIR}/target_Power.c + ${CMAKE_CURRENT_SOURCE_DIR}/CC1352R1_LAUNCHXL_fxns.c ${COMMON_PROJECT_SOURCES} ${NANOCLR_PROJECT_SOURCES} @@ -61,6 +118,11 @@ add_executable( ${WireProtocol_SOURCES} + ${CMAKE_CURRENT_BINARY_DIR}/syscfg/ti_devices_config.c + ${CMAKE_CURRENT_BINARY_DIR}/syscfg/ti_drivers_config.c + ${CMAKE_CURRENT_BINARY_DIR}/syscfg/ti_easylink_config.c + ${CMAKE_CURRENT_BINARY_DIR}/syscfg/ti_radio_config.c + # sources for nanoFramework libraries ${NF_CoreCLR_SOURCES} ${NF_Debugger_SOURCES} @@ -73,73 +135,53 @@ add_executable( target_link_libraries( ${NANOCLR_PROJECT_NAME}.elf - ${PROJECT_BINARY_DIR}/SimpleLinkCC13x2_26x2SDK_Source/ti/display/lib/display.am4fg - ${PROJECT_BINARY_DIR}/SimpleLinkCC13x2_26x2SDK_Source/ti/grlib/lib/gcc/m4f/grlib.a - ${PROJECT_BINARY_DIR}/SimpleLinkCC13x2_26x2SDK_Source/ti/drivers/rf/lib/rf_multiMode_cc13x2.am4fg - ${PROJECT_BINARY_DIR}/SimpleLinkCC13x2_26x2SDK_Source/ti/drivers/lib/drivers_cc13x2.am4fg + ${PROJECT_BINARY_DIR}/SimpleLinkCC13x2_26x2SDK_Source/source/ti/display/lib/display.am4fg + ${PROJECT_BINARY_DIR}/SimpleLinkCC13x2_26x2SDK_Source/source/ti/grlib/lib/gcc/m4f/grlib.a + ${PROJECT_BINARY_DIR}/SimpleLinkCC13x2_26x2SDK_Source/source/ti/drivers/rf/lib/rf_multiMode_cc13x2.am4fg + ${PROJECT_BINARY_DIR}/SimpleLinkCC13x2_26x2SDK_Source/source/ti/drivers/lib/drivers_cc13x2.am4fg + ${PROJECT_BINARY_DIR}/SimpleLinkCC13x2_26x2SDK_Source/source/ti/devices/cc13x2_cc26x2/driverlib/bin/gcc/driverlib.lib ${PROJECT_BINARY_DIR}/SimpleLinkCC13x2_26x2SDK_Source/kernel/tirtos/packages/ti/dpl/lib/dpl_cc13x2.am4fg - ${PROJECT_BINARY_DIR}/SimpleLinkCC13x2_26x2SDK_Source/ti/devices/cc13x2_cc26x2/driverlib/bin/gcc/driverlib.lib - # ${PROJECT_BINARY_DIR}/SimpleLinkCC13x2_26x2SDK_Source/kernel/tirtos/packages/gnu/targets/arm/libs/install-native/arm-none-eabi/lib/thumb/v7e-m/fpv4-sp/hard/libc.a - ${PROJECT_BINARY_DIR}/SimpleLinkCC13x2_26x2SDK_Source/kernel/tirtos/packages/gnu/targets/arm/libs/install-native/arm-none-eabi/lib/thumb/v7e-m/fpv4-sp/hard/libm.a - ${PROJECT_BINARY_DIR}/SimpleLinkCC13x2_26x2SDK_Source/kernel/tirtos/packages/gnu/targets/arm/libs/install-native/arm-none-eabi/lib/thumb/v7e-m/fpv4-sp/hard/libnosys.a + ${PROJECT_BINARY_DIR}/SimpleLinkCC13x2_26x2SDK_Source/kernel/tirtos/packages/gnu/targets/arm/libs/install-native/arm-none-eabi/lib/thumb/v7e-m/hard/libm.a + ${PROJECT_BINARY_DIR}/SimpleLinkCC13x2_26x2SDK_Source/kernel/tirtos/packages/gnu/targets/arm/libs/install-native/arm-none-eabi/lib/thumb/v7e-m/hard/libnosys.a ) -# add dependency from TI SimpleLink CC13x2_26x2 SDK and XDCTools (this is required to make sure that those repos are downloaded before the build starts) -add_dependencies(${NANOCLR_PROJECT_NAME}.elf TI_XDCTools) +# add dependency from TI SimpleLink CC13x2_26x2 SDK, TI SysConfig and XDCTools (this is required to make sure that those repos are downloaded before the build starts) +add_dependencies(${NANOCLR_PROJECT_NAME}.elf TI_SysConfig) add_dependencies(${NANOCLR_PROJECT_NAME}.elf SimpleLinkCC13x2_26x2SDK) - -###################################### - -# need to copy the configuration file to the build directory -# because the obj files resulting from TI-RTOS build are placed in the same directory as the configuration file -if(CMAKE_BUILD_TYPE MATCHES Debug OR CMAKE_BUILD_TYPE MATCHES RelWithDebInfo) - set(TI_RTOS_CONFIG_FILE ti-rtos-debug.cfg) -else() - set(TI_RTOS_CONFIG_FILE ti-rtos-release.cfg) -endif() - -add_custom_command( - TARGET ${NANOCLR_PROJECT_NAME}.elf PRE_BUILD - COMMAND ${CMAKE_COMMAND} -E copy - ${CMAKE_CURRENT_SOURCE_DIR}/${TI_RTOS_CONFIG_FILE} - ${CMAKE_CURRENT_BINARY_DIR}/${TI_RTOS_CONFIG_FILE} - COMMENT "Copy TI-RTOS configuration file to build directory" -) - -add_custom_command( - TARGET ${NANOCLR_PROJECT_NAME}.elf PRE_BUILD - COMMAND ${CMAKE_BINARY_DIR}/TI_XDCTools_Source/xs.exe --xdcpath="${PROJECT_BINARY_DIR}/SimpleLinkCC13x2_26x2SDK_Source\;${PROJECT_BINARY_DIR}/SimpleLinkCC13x2_26x2SDK_Source/kernel/tirtos/packages\;" xdc.tools.configuro -o configPkg -t gnu.targets.arm.M4F -p ti.platforms.simplelink:CC1352P1F3 -r release -c "${TOOLCHAIN_PREFIX}" --compileOptions "-DDeviceFamily_CC13X2" "${CMAKE_CURRENT_BINARY_DIR}/${TI_RTOS_CONFIG_FILE}" - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMENT "Generate TI-RTOS configuration" -) +add_dependencies(${NANOCLR_PROJECT_NAME}.elf COPY_TIRTOS_CONFIG) +add_dependencies(${NANOCLR_PROJECT_NAME}.elf TIRTOS_CONFIG) +add_dependencies(TIRTOS_CONFIG TI_XDCTools) +add_dependencies(TIRTOS_CONFIG COPY_TIRTOS_CONFIG) ############################# # include common directories include_directories( ${CMAKE_CURRENT_BINARY_DIR} - "${CMAKE_CURRENT_SOURCE_DIR}" - "${CMAKE_CURRENT_SOURCE_DIR}/common" - "${PROJECT_SOURCE_DIR}/src/CLR/Core" - "${PROJECT_SOURCE_DIR}/src/CLR/Include" - "${PROJECT_SOURCE_DIR}/src/HAL/Include" - "${PROJECT_SOURCE_DIR}/src/PAL/Include" + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/common + ${PROJECT_SOURCE_DIR}/src/CLR/Core + ${PROJECT_SOURCE_DIR}/src/CLR/Include + ${PROJECT_SOURCE_DIR}/src/HAL/Include + ${PROJECT_SOURCE_DIR}/src/PAL/Include - "${WireProtocol_INCLUDE_DIRS}" - "${TI_SimpleLink_INCLUDE_DIRS}" + ${WireProtocol_INCLUDE_DIRS} + ${TI_SimpleLink_INCLUDE_DIRS} ${TI_XDCTools_INCLUDE_DIR} - "${TARGET_TI_SimpleLink_COMMON_INCLUDE_DIRS}" + ${CMAKE_CURRENT_BINARY_DIR}/syscfg + + ${TARGET_TI_SimpleLink_COMMON_INCLUDE_DIRS} ) # include directories for nanoCLR target_include_directories(${NANOCLR_PROJECT_NAME}.elf PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/nanoCLR - "${CMAKE_CURRENT_SOURCE_DIR}/nanoCLR" + ${CMAKE_CURRENT_SOURCE_DIR}/nanoCLR - "${TARGET_TI_SimpleLink_NANOCLR_INCLUDE_DIRS}" + ${TARGET_TI_SimpleLink_NANOCLR_INCLUDE_DIRS} # directories for nanoFramework libraries ${NF_CoreCLR_INCLUDE_DIRS} @@ -156,9 +198,6 @@ nf_set_compiler_options(${NANOCLR_PROJECT_NAME}.elf) # set compiler definitions nf_set_compiler_definitions(${NANOCLR_PROJECT_NAME}.elf -DDeviceFamily_CC13X2 ) -# set compiler definitions pertaining PHY types availability -nf_set_compiler_definitions(${NANOCLR_PROJECT_NAME}.elf -DSUPPORT_PHY_CUSTOM -DSUPPORT_PHY_50KBPS2GFSK -DSUPPORT_PHY_5KBPSSLLR -DSUPPORT_PHY_200KBPS2GFSK ) - # set linker files if(CMAKE_BUILD_TYPE MATCHES Debug OR CMAKE_BUILD_TYPE MATCHES RelWithDebInfo) nf_set_linker_file(${NANOCLR_PROJECT_NAME}.elf ${CMAKE_CURRENT_SOURCE_DIR}/nanoCLR/CC13x2_26x2_CLR-DEBUG.ld) diff --git a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/TI_CC1352R1_LAUNCHXL.syscfg b/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/TI_CC1352R1_LAUNCHXL.syscfg new file mode 100644 index 0000000000..e8cded8fad --- /dev/null +++ b/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/TI_CC1352R1_LAUNCHXL.syscfg @@ -0,0 +1,55 @@ +/** + * These arguments were used when this file was generated. They will be automatically applied on subsequent loads + * via the GUI or CLI. Run CLI with '--help' for additional information on how to override these arguments. + * @cliArgs --board "/ti/boards/CC1352R1_LAUNCHXL" --product "simplelink_cc13x2_26x2_sdk@4.20.01.04" + * @versions {"data":"2020090214","timestamp":"2020090214","tool":"1.6.0+1543","templates":"2020090214"} + */ + +/** + * Import the modules used in this configuration. + */ +const CCFG = scripting.addModule("/ti/devices/CCFG"); +const ADC = scripting.addModule("/ti/drivers/ADC", {}, false); +const ADC1 = ADC.addInstance(); +const DMA = scripting.addModule("/ti/drivers/DMA"); +const RTOS = scripting.addModule("/ti/drivers/RTOS"); +const UART2 = scripting.addModule("/ti/drivers/UART2", {}, false); +const UART21 = UART2.addInstance(); +const easylink = scripting.addModule("/ti/easylink/easylink"); + +/** + * Write custom configuration values to the imported modules. + */ +CCFG.forceVddr = true; +CCFG.ccfgTemplate.$name = "ti_devices_CCFGTemplate0"; + +ADC1.$name = "ADC_0"; +ADC1.samplingDuration = "170 us"; +ADC1.adcPinInstance.$name = "CONFIG_PIN_0"; + +UART21.$hardware = system.deviceData.board.components.XDS110UART; +UART21.$name = "UART0"; +UART21.txPinInstance.$name = "CONFIG_PIN_2"; +UART21.rxPinInstance.$name = "CONFIG_PIN_3"; +UART21.uart.$assign = "UART0"; + +easylink.EasyLink_Phy_5kbpsSlLr = true; +easylink.defaultPhy = "EasyLink_Phy_5kbpsSlLr"; +easylink.EasyLink_Phy_50kbps2gfsk = true; +easylink.EasyLink_Phy_200kbps2gfsk = true; +easylink.EasyLink_Phy_Custom = false; +easylink.addrFilters = ""; +easylink.enableAddrFilter = false; +easylink.radioConfigEasylinkPhy5kbpssllr.codeExportConfig.$name = "ti_devices_radioconfig_code_export_param1"; +easylink.radioConfigEasylinkPhy50kbps2gfsk.codeExportConfig.$name = "ti_devices_radioconfig_code_export_param2"; +easylink.radioConfigEasylinkPhy200kbps2gfsk.codeExportConfig.$name = "ti_devices_radioconfig_code_export_param3"; + +/** + * Pinmux solution for unlocked pins/peripherals. This ensures that minor changes to the automatic solver in a future + * version of the tool will not impact the pinmux you originally saw. These lines can be completely deleted in order to + * re-solve from scratch. + */ +ADC1.adc.$suggestSolution = "ADC0"; +ADC1.adc.adcPin.$suggestSolution = "boosterpack.2"; +UART21.uart.txPin.$suggestSolution = "boosterpack.4"; +UART21.uart.rxPin.$suggestSolution = "boosterpack.3"; diff --git a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/ccfg.c b/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/ccfg.c deleted file mode 100644 index 8890e81178..0000000000 --- a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/ccfg.c +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2015-2017, Texas Instruments Incorporated - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of Texas Instruments Incorporated nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * ======== ccfg.c ======== - * Customer Configuration for CC26xx and CC13xx devices. This file is used to - * configure Boot ROM, start-up code, and SW radio behaviour. - * - * By default, driverlib startup_files/ccfg.c settings are used. However, if - * changes are required there are two means to do so: - * - * 1. Remove this file and copy driverlib's startup_files/ccfg.c file in - * its place. Make all changes to the file. Changes made are local to - * the project and will not affect other projects. - * - * 2. Perform changes to driverlib startup_files/ccfg.c file. Changes - * made to this file will be applied to all projects. This file must - * remain unmodified. - */ - -#include -#include DeviceFamily_constructPath(startup_files/ccfg.c) diff --git a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/cmake-variants.json b/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/cmake-variants.json new file mode 100644 index 0000000000..29001e1e22 --- /dev/null +++ b/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/cmake-variants.json @@ -0,0 +1,58 @@ +{ + "buildType": { + "default": "debug", + "choices": { + "debug": { + "short": "Debug", + "long": "Emit debug information without performing optimizations", + "buildType": "Debug" + }, + "minsize": { + "short": "MinSizeRel", + "long": "Optimize for smallest binary size", + "buildType": "MinSizeRel" + }, + "reldeb": { + "short": "RelWithDebInfo", + "long": "Perform optimizations AND include debugging information", + "buildType": "RelWithDebInfo" + } + } + }, + "linkage": { + "default": "", + "choices": { + "TI_CC1352R1_LAUNCHXL": { + "short": "TI_CC1352R1_LAUNCHXL", + "settings": { + "BUILD_VERSION": "0.9.99.999", + "CMAKE_TOOLCHAIN_FILE": "CMake/toolchain.arm-none-eabi.cmake", + "TOOLCHAIN_PREFIX": "", + "RTOS": "TI_SIMPLELINK", + "TARGET_SERIES": "CC13x2_26x2", + "TI_BOARD": "TI_CC1352R1_LAUNCHXL", + "TI_SL_CC13x2_26x2_SDK_SOURCE": "", + "TI_XDCTOOLS_SOURCE": "", + "TI_SYSCONFIG_SOURCE": "", + "SUPPORT_ANY_BASE_CONVERSION": "OFF", + "NF_FEATURE_DEBUGGER": "ON", + "NF_FEATURE_RTC": "ON", + "NF_FEATURE_HAS_SDCARD": "OFF", + "NF_BUILD_RTM": "OFF", + "API_System.Math": "ON", + "API_Windows.Devices.Gpio": "ON", + "API_Windows.Devices.Spi": "OFF", + "API_Windows.Devices.I2c": "OFF", + "API_Windows.Devices.Pwm": "OFF", + "API_Windows.Devices.Adc": "ON", + "API_Windows.Devices.SerialCommunication": "OFF", + "API_nanoFramework.ResourceManager": "OFF", + "API_nanoFramework.System.Collections": "OFF", + "API_nanoFramework.System.Text": "OFF", + "API_nanoFramework.TI.EasyLink": "ON", + "API_nanoFramework.Hardware.TI": "ON" + } + } + } + } +} diff --git a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/common/CMakeLists.txt b/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/common/CMakeLists.txt index 42be0d5f5a..3b62894577 100644 --- a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/common/CMakeLists.txt +++ b/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/common/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/common/Device_BlockStorage-DEBUG.c b/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/common/Device_BlockStorage-DEBUG.c index 4e182303f4..87e1de67d3 100644 --- a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/common/Device_BlockStorage-DEBUG.c +++ b/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/common/Device_BlockStorage-DEBUG.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // @@ -7,61 +7,57 @@ #include // 8k blocks -const BlockRange BlockRange1[] = -{ +const BlockRange BlockRange1[] = { // the last block is reserved for Customer Configuration Area and Bootloader Backdoor configuration // so we don't take it into account for the map - { BlockRange_BLOCKTYPE_CODE , 0 , 27 }, // 0x00000000 nanoCLR - { BlockRange_BLOCKTYPE_DEPLOYMENT , 28 , 42 }, // 0x00038000 deployment + {BlockRange_BLOCKTYPE_CODE, 0, 30}, // 0x00000000 nanoCLR + {BlockRange_BLOCKTYPE_DEPLOYMENT, 31, 42}, // 0x0003E000 deployment }; -const BlockRegionInfo BlockRegions[] = -{ - { - (0), // no attributes for this region - 0x00000000, // start address for block region - 43, // total number of blocks in this region - 0x2000, // total number of bytes per block - ARRAYSIZE_CONST_EXPR(BlockRange1), - BlockRange1, - } -}; +const BlockRegionInfo BlockRegions[] = {{ + (0), // no attributes for this region + 0x00000000, // start address for block region + 43, // total number of blocks in this region + 0x2000, // total number of bytes per block + ARRAYSIZE_CONST_EXPR(BlockRange1), + BlockRange1, +}}; -const DeviceBlockInfo Device_BlockInfo = -{ +const DeviceBlockInfo Device_BlockInfo = { (MediaAttribute_SupportsXIP), - 2, // UINT32 BytesPerSector - ARRAYSIZE_CONST_EXPR(BlockRegions), // UINT32 NumRegions; - (BlockRegionInfo*)BlockRegions, // const BlockRegionInfo* pRegions; + 2, // UINT32 BytesPerSector + ARRAYSIZE_CONST_EXPR(BlockRegions), // UINT32 NumRegions; + (BlockRegionInfo *)BlockRegions, // const BlockRegionInfo* pRegions; }; -MEMORY_MAPPED_NOR_BLOCK_CONFIG Device_BlockStorageConfig = -{ - { // BLOCK_CONFIG +MEMORY_MAPPED_NOR_BLOCK_CONFIG Device_BlockStorageConfig = { + { + // BLOCK_CONFIG { - 0, // GPIO_PIN Pin; - false, // BOOL ActiveState; + 0, // GPIO_PIN Pin; + false, // BOOL ActiveState; }, - (DeviceBlockInfo*)&Device_BlockInfo, // BlockDeviceinfo + (DeviceBlockInfo *)&Device_BlockInfo, // BlockDeviceinfo }, - { // CPU_MEMORY_CONFIG - 0, // UINT8 CPU_MEMORY_CONFIG::ChipSelect; - true, // UINT8 CPU_MEMORY_CONFIG::ReadOnly; - 0, // UINT32 CPU_MEMORY_CONFIG::WaitStates; - 0, // UINT32 CPU_MEMORY_CONFIG::ReleaseCounts; - 16, // UINT32 CPU_MEMORY_CONFIG::BitWidth; - 0x08000000, // UINT32 CPU_MEMORY_CONFIG::BaseAddress; - 0x00200000, // UINT32 CPU_MEMORY_CONFIG::SizeInBytes; - 0, // UINT8 CPU_MEMORY_CONFIG::XREADYEnable - 0, // UINT8 CPU_MEMORY_CONFIG::ByteSignalsForRead - 0, // UINT8 CPU_MEMORY_CONFIG::ExternalBufferEnable + { + // CPU_MEMORY_CONFIG + 0, // UINT8 CPU_MEMORY_CONFIG::ChipSelect; + true, // UINT8 CPU_MEMORY_CONFIG::ReadOnly; + 0, // UINT32 CPU_MEMORY_CONFIG::WaitStates; + 0, // UINT32 CPU_MEMORY_CONFIG::ReleaseCounts; + 16, // UINT32 CPU_MEMORY_CONFIG::BitWidth; + 0x08000000, // UINT32 CPU_MEMORY_CONFIG::BaseAddress; + 0x00200000, // UINT32 CPU_MEMORY_CONFIG::SizeInBytes; + 0, // UINT8 CPU_MEMORY_CONFIG::XREADYEnable + 0, // UINT8 CPU_MEMORY_CONFIG::ByteSignalsForRead + 0, // UINT8 CPU_MEMORY_CONFIG::ExternalBufferEnable }, - 0, // UINT32 ChipProtection; - 0, // UINT32 ManufacturerCode; - 0, // UINT32 DeviceCode; + 0, // UINT32 ChipProtection; + 0, // UINT32 ManufacturerCode; + 0, // UINT32 DeviceCode; }; -BlockStorageDevice Device_BlockStorage; +BlockStorageDevice Device_BlockStorage; diff --git a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/common/Device_BlockStorage.c b/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/common/Device_BlockStorage.c index dd12871ef3..c751df2be4 100644 --- a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/common/Device_BlockStorage.c +++ b/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/common/Device_BlockStorage.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // @@ -7,61 +7,57 @@ #include // 8k blocks -const BlockRange BlockRange1[] = -{ +const BlockRange BlockRange1[] = { // the last block is reserved for Customer Configuration Area and Bootloader Backdoor configuration // so we don't take it into account for the map - { BlockRange_BLOCKTYPE_CODE , 0 , 19 }, // 0x00000000 nanoCLR - { BlockRange_BLOCKTYPE_DEPLOYMENT , 20 , 42 }, // 0x00028000 deployment + {BlockRange_BLOCKTYPE_CODE, 0, 21}, // 0x00000000 nanoCLR + {BlockRange_BLOCKTYPE_DEPLOYMENT, 22, 42}, // 0x0002C000 deployment }; -const BlockRegionInfo BlockRegions[] = -{ - { - (0), // no attributes for this region - 0x00000000, // start address for block region - 43, // total number of blocks in this region - 0x2000, // total number of bytes per block - ARRAYSIZE_CONST_EXPR(BlockRange1), - BlockRange1, - } -}; +const BlockRegionInfo BlockRegions[] = {{ + (0), // no attributes for this region + 0x00000000, // start address for block region + 43, // total number of blocks in this region + 0x2000, // total number of bytes per block + ARRAYSIZE_CONST_EXPR(BlockRange1), + BlockRange1, +}}; -const DeviceBlockInfo Device_BlockInfo = -{ +const DeviceBlockInfo Device_BlockInfo = { (MediaAttribute_SupportsXIP), - 2, // UINT32 BytesPerSector - ARRAYSIZE_CONST_EXPR(BlockRegions), // UINT32 NumRegions; - (BlockRegionInfo*)BlockRegions, // const BlockRegionInfo* pRegions; + 2, // UINT32 BytesPerSector + ARRAYSIZE_CONST_EXPR(BlockRegions), // UINT32 NumRegions; + (BlockRegionInfo *)BlockRegions, // const BlockRegionInfo* pRegions; }; -MEMORY_MAPPED_NOR_BLOCK_CONFIG Device_BlockStorageConfig = -{ - { // BLOCK_CONFIG +MEMORY_MAPPED_NOR_BLOCK_CONFIG Device_BlockStorageConfig = { + { + // BLOCK_CONFIG { - 0, // GPIO_PIN Pin; - false, // BOOL ActiveState; + 0, // GPIO_PIN Pin; + false, // BOOL ActiveState; }, - (DeviceBlockInfo*)&Device_BlockInfo, // BlockDeviceinfo + (DeviceBlockInfo *)&Device_BlockInfo, // BlockDeviceinfo }, - { // CPU_MEMORY_CONFIG - 0, // UINT8 CPU_MEMORY_CONFIG::ChipSelect; - true, // UINT8 CPU_MEMORY_CONFIG::ReadOnly; - 0, // UINT32 CPU_MEMORY_CONFIG::WaitStates; - 0, // UINT32 CPU_MEMORY_CONFIG::ReleaseCounts; - 16, // UINT32 CPU_MEMORY_CONFIG::BitWidth; - 0x08000000, // UINT32 CPU_MEMORY_CONFIG::BaseAddress; - 0x00200000, // UINT32 CPU_MEMORY_CONFIG::SizeInBytes; - 0, // UINT8 CPU_MEMORY_CONFIG::XREADYEnable - 0, // UINT8 CPU_MEMORY_CONFIG::ByteSignalsForRead - 0, // UINT8 CPU_MEMORY_CONFIG::ExternalBufferEnable + { + // CPU_MEMORY_CONFIG + 0, // UINT8 CPU_MEMORY_CONFIG::ChipSelect; + true, // UINT8 CPU_MEMORY_CONFIG::ReadOnly; + 0, // UINT32 CPU_MEMORY_CONFIG::WaitStates; + 0, // UINT32 CPU_MEMORY_CONFIG::ReleaseCounts; + 16, // UINT32 CPU_MEMORY_CONFIG::BitWidth; + 0x08000000, // UINT32 CPU_MEMORY_CONFIG::BaseAddress; + 0x00200000, // UINT32 CPU_MEMORY_CONFIG::SizeInBytes; + 0, // UINT8 CPU_MEMORY_CONFIG::XREADYEnable + 0, // UINT8 CPU_MEMORY_CONFIG::ByteSignalsForRead + 0, // UINT8 CPU_MEMORY_CONFIG::ExternalBufferEnable }, - 0, // UINT32 ChipProtection; - 0, // UINT32 ManufacturerCode; - 0, // UINT32 DeviceCode; + 0, // UINT32 ChipProtection; + 0, // UINT32 ManufacturerCode; + 0, // UINT32 DeviceCode; }; -BlockStorageDevice Device_BlockStorage; +BlockStorageDevice Device_BlockStorage; diff --git a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/easylink/easylink_config.c b/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/easylink/easylink_config.c deleted file mode 100644 index 60e2dac227..0000000000 --- a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/easylink/easylink_config.c +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright (c) 2015-2019, Texas Instruments Incorporated - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of Texas Instruments Incorporated nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/***** Includes *****/ -#include "EasyLink.h" -#include "Board.h" - -/* TI Drivers */ -#include -#include - -#ifdef Board_SYSCONFIG_PREVIEW -#include -#else -#include -#include -#endif - -#if (defined Board_CC2650_LAUNCHXL) || (defined Board_CC26X2R1_LAUNCHXL) -#define RF_TX_POWER_TABLE NULL -#define RF_TX_POWER_TABLE_SIZE 0 -#else -#define RF_TX_POWER_TABLE (RF_TxPowerTable_Entry *)RF_PROP_txPowerTable -#define RF_TX_POWER_TABLE_SIZE RF_PROP_TX_POWER_TABLE_SIZE -#endif//(defined Board_CC2650_LAUNCHXL) || (defined Board_CC26X2R1_LAUNCHXL) - -EasyLink_RfSetting EasyLink_supportedPhys[] = { -#if defined(SUPPORT_PHY_CUSTOM) - {.EasyLink_phyType = EasyLink_Phy_Custom, - .RF_pProp = &RF_prop, -#if (defined(DeviceFamily_CC26X0R2) || defined(DeviceFamily_CC26X0)) - .RF_uCmdPropRadio.RF_pCmdPropRadioSetup = &RF_cmdPropRadioSetup, -#else - .RF_uCmdPropRadio.RF_pCmdPropRadioDivSetup = &RF_cmdPropRadioDivSetup, -#endif // (defined(DeviceFamily_CC26X0R2) || defined(DeviceFamily_CC26X0)) - .RF_pCmdFs = &RF_cmdFs, - .RF_pCmdPropTx = &RF_cmdPropTx, - .RF_pCmdPropTxAdv = NULL, - .RF_pCmdPropRxAdv = &RF_cmdPropRxAdv_preDef, - .RF_pTxPowerTable = RF_TX_POWER_TABLE, - .RF_txPowerTableSize = RF_TX_POWER_TABLE_SIZE - }, -#endif //defined(SUPPORT_PHY_CUSTOM) -#if defined(SUPPORT_PHY_50KBPS2GFSK) - {.EasyLink_phyType = EasyLink_Phy_50kbps2gfsk, - .RF_pProp = &RF_prop_fsk, - .RF_uCmdPropRadio.RF_pCmdPropRadioDivSetup = &RF_cmdPropRadioDivSetup_fsk, - .RF_pCmdFs = &RF_cmdFs_preDef, - .RF_pCmdPropTx = &RF_cmdPropTx, - .RF_pCmdPropTxAdv = NULL, - .RF_pCmdPropRxAdv = &RF_cmdPropRxAdv_preDef, - .RF_pTxPowerTable = RF_TX_POWER_TABLE, - .RF_txPowerTableSize = RF_TX_POWER_TABLE_SIZE - }, -#endif //defined(SUPPORT_PHY_50KBPS2GFSK) -#if defined(SUPPORT_PHY_5KBPSSLLR) - {.EasyLink_phyType = EasyLink_Phy_5kbpsSlLr, - .RF_pProp = &RF_prop_sl_lr, - .RF_uCmdPropRadio.RF_pCmdPropRadioDivSetup = &RF_cmdPropRadioDivSetup_sl_lr, - .RF_pCmdFs = &RF_cmdFs_preDef, - .RF_pCmdPropTx = &RF_cmdPropTx, - .RF_pCmdPropTxAdv = NULL, - .RF_pCmdPropRxAdv = &RF_cmdPropRxAdv_preDef, - .RF_pTxPowerTable = RF_TX_POWER_TABLE, - .RF_txPowerTableSize = RF_TX_POWER_TABLE_SIZE - }, -#endif //defined(SUPPORT_PHY_5KBPSSLLR) -#if defined(SUPPORT_PHY_625BPSLRM) - {.EasyLink_phyType = EasyLink_Phy_625bpsLrm, - .RF_pProp = &RF_prop_lrm, - .RF_uCmdPropRadio.RF_pCmdPropRadioDivSetup = &RF_cmdPropRadioDivSetup_lrm, - .RF_pCmdFs = &RF_cmdFs_preDef, - .RF_pCmdPropTx = &RF_cmdPropTx, - .RF_pCmdPropTxAdv = NULL, - .RF_pCmdPropRxAdv = &RF_cmdPropRxAdv_preDef, - .RF_pTxPowerTable = RF_TX_POWER_TABLE, - .RF_txPowerTableSize = RF_TX_POWER_TABLE_SIZE - }, -#endif //defined(SUPPORT_PHY_625BPSLRM) -#if defined(SUPPORT_PHY_2_4_200KBPS2GFSK) - {.EasyLink_phyType = EasyLink_Phy_2_4_200kbps2gfsk, - .RF_pProp = &RF_prop_2_4G_fsk, - .RF_uCmdPropRadio.RF_pCmdPropRadioSetup = &RF_cmdPropRadioSetup_2_4G_fsk, - .RF_pCmdFs = &RF_cmdFs_preDef, - .RF_pCmdPropTx = &RF_cmdPropTx, - .RF_pCmdPropTxAdv = NULL, - .RF_pCmdPropRxAdv = &RF_cmdPropRxAdv_preDef, - .RF_pTxPowerTable = RF_TX_POWER_TABLE, - .RF_txPowerTableSize = RF_TX_POWER_TABLE_SIZE - }, -#endif //defined(SUPPORT_PHY_2_4_200KBPS2GFSK) -#if defined(SUPPORT_PHY_2_4_100KBPS2GFSK) - {.EasyLink_phyType = EasyLink_Phy_2_4_100kbps2gfsk, - .RF_pProp = &RF_prop_2_4G_fsk, - .RF_uCmdPropRadio.RF_pCmdPropRadioSetup = &RF_cmdPropRadioSetup_2_4G_fsk_100, - .RF_pCmdFs = &RF_cmdFs_preDef, - .RF_pCmdPropTx = &RF_cmdPropTx, - .RF_pCmdPropTxAdv = NULL, - .RF_pCmdPropRxAdv = &RF_cmdPropRxAdv_preDef, - .RF_pTxPowerTable = RF_TX_POWER_TABLE, - .RF_txPowerTableSize = RF_TX_POWER_TABLE_SIZE - }, -#endif //defined(SUPPORT_PHY_2_4_100KBPS2GFSK) -#if defined(SUPPORT_PHY_2_4_250KBPS2GFSK) - {.EasyLink_phyType = EasyLink_Phy_2_4_250kbps2gfsk, - .RF_pProp = &RF_prop_2_4G_fsk, - .RF_uCmdPropRadio.RF_pCmdPropRadioSetup = &RF_cmdPropRadioSetup_2_4G_fsk, - .RF_pCmdFs = &RF_cmdFs_preDef, - .RF_pCmdPropTx = &RF_cmdPropTx, - .RF_pCmdPropTxAdv = NULL, - .RF_pCmdPropRxAdv = &RF_cmdPropRxAdv_preDef, - .RF_pTxPowerTable = RF_TX_POWER_TABLE, - .RF_txPowerTableSize = RF_TX_POWER_TABLE_SIZE - }, -#endif //defined(SUPPORT_PHY_2_4_250KBPS2GFSK) -#if defined(SUPPORT_PHY_200KBPS2GFSK) - {.EasyLink_phyType = EasyLink_Phy_200kbps2gfsk, - .RF_pProp = &RF_prop_fsk_200kbps, - .RF_uCmdPropRadio.RF_pCmdPropRadioDivSetup = &RF_cmdPropRadioDivSetup_fsk_200kbps, - .RF_pCmdFs = &RF_cmdFs_preDef, - .RF_pCmdPropTx = NULL, - .RF_pCmdPropTxAdv = &RF_cmdPropTxAdv_preDef, - .RF_pCmdPropRxAdv = &RF_cmdPropRxAdv_preDef, - .RF_pTxPowerTable = RF_TX_POWER_TABLE, - .RF_txPowerTableSize = RF_TX_POWER_TABLE_SIZE - }, -#endif //defined(SUPPORT_PHY_50KBPS2GFSK) -}; - -const uint8_t EasyLink_numSupportedPhys = sizeof(EasyLink_supportedPhys)/sizeof(EasyLink_RfSetting); diff --git a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/easylink_config.h b/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/easylink_config.h deleted file mode 100644 index 3247f1a449..0000000000 --- a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/easylink_config.h +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (c) 2015-2017, Texas Instruments Incorporated - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of Texas Instruments Incorporated nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -//***************************************************************************** -/*! -\addtogroup EasyLink Easylink - -@{ -*/ -//***************************************************************************** -#ifndef EASYLINK_CONFIG_H_ -#define EASYLINK_CONFIG_H_ - -//***************************************************************************** -// -// If building with a C++ compiler, make all of the definitions in this header -// have a C binding. -// -//***************************************************************************** -#ifdef __cplusplus -extern "C" -{ -#endif - -//! \brief Defines the address that will accompany each packet sent from this -//! device when EASYLINK_USE_DEFAULT_ADDR is true. It can also be thought of as -//! this device's own address. Organized in little endian format (e.g.an address -//! of 0xABCD should be defined as {0xCD,0xAB}) -#define EASYLINK_DEFAULT_ADDR {0xAA} - -//! \brief When false, the Easylink stack expects the application to provide an -//! accompanying address for each EasyLink_TxPacket passed to the -//! EasyLink_transmit(), EasyLink_transmitAsync(), and -//! EasyLink_transmitCcaAsync() APIs. Otherwise, these APIs will use the address -//! defined in EASYLINK_DEFAULT_ADDR -#define EASYLINK_USE_DEFAULT_ADDR false - -//! \brief Defines the largest Tx/Rx payload that the interface can support -#define EASYLINK_MAX_DATA_LENGTH 128 - -//! \brief Defines the default address size for rx and tx operations -#define EASYLINK_ADDR_SIZE 1 - -//! \brief Enables of disables address filtering by default -#define EASYLINK_ENABLE_ADDR_FILTERING true - -//! \brief The table for setting the Rx Address Filters -#define EASYLINK_NUM_ADDR_FILTER 1 - -//! \brief The table for setting the Rx Address Filters -#define EASYLINK_ADDR_FILTER_TABLE {0xAA} - -//! \brief Defines the time for the radio to return to idle after inactivity -#define EASYLINK_IDLE_TIMEOUT EasyLink_ms_To_RadioTime(1) - -//! \brief Enables or disables the application to use multiple RF clients -#define EASYLINK_ENABLE_MULTI_CLIENT false - -//! \brief Defines the relative time from async RX start to timeout. A value of -//! 0 means no timeout -#define EASYLINK_ASYNC_RX_TIMEOUT EasyLink_ms_To_RadioTime(0) - -//! \brief Minimum CCA back-off window in units of -//! EASYLINK_CCA_BACKOFF_TIMEUNITS, as a power of 2 -#define EASYLINK_MIN_CCA_BACKOFF_WINDOW 5 - -//! \brief Maximum CCA back-off window in units of -//! EASYLINK_CCA_BACKOFF_TIMEUNITS, as a power of 2 -#define EASYLINK_MAX_CCA_BACKOFF_WINDOW 8 - -//! \brief The back-off time units in microseconds -#define EASYLINK_CCA_BACKOFF_TIMEUNITS 250 - -//! \brief RSSI threshold for Clear Channel Assessment (CCA) -#define EASYLINK_CS_RSSI_THRESHOLD_DBM -80 - -//! \brief Time for which the channel RSSI must remain below the specified -//! threshold for the channel to be considered idle -#define EASYLINK_CHANNEL_IDLE_TIME_US 5000 - -//! \brief EasyLink default parameter configuration -#define EASYLINK_PARAM_CONFIG \ - {.ui32ModType = EasyLink_Phy_Custom, \ - .pClientEventCb = NULL, \ - .nClientEventMask = 0, \ - .pGrnFxn = (EasyLink_GetRandomNumber)rand\ - } - -#ifdef __cplusplus -} -#endif - - -#endif //EASYLINK_CONFIG_H_ - -//***************************************************************************** -// -//! Close the Doxygen group. -//! @} -// -//***************************************************************************** diff --git a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/launch.json b/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/launch.json new file mode 100644 index 0000000000..9e78413482 --- /dev/null +++ b/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/launch.json @@ -0,0 +1,58 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "TI_CC1352R1_LAUNCHXL nanoCLR", + "type": "cppdbg", + "request": "launch", + "MIMode": "gdb", + "miDebuggerPath": "/bin/arm-none-eabi-gdb.exe", + "targetArchitecture": "ARM", + "program": "${workspaceRoot}/build/nanoCLR.elf", + "setupCommands": [ + { + "text": "target extended-remote localhost:3333" + }, + { + "text": "monitor reset_config none separate" + }, + { + "text": "monitor reset halt" + }, + { + "text": "monitor flash write_image erase \"/build/nanoCLR.hex\" " + }, + { + "text": "file /build/nanoCLR.elf" + }, + { + "text": "set output-radix 16", + "description": "set the default numeric base to 16", + "ignoreFailures": false + } + ], + "customLaunchSetupCommands": [ + { + "text": "monitor reset_config none separate" + }, + { + "text": "monitor reset halt" + } + ], + "logging": { + "moduleLoad": false, + "trace": false, + "engineLogging": false, + "programOutput": true, + "exceptions": true + }, + "debugServerPath": "/bin/openocd.exe", + "debugServerArgs": "-s \"/share/openocd/scripts/\" -f board/ti_cc13x2_launchpad.cfg", + "serverStarted": "Listening on port 3333 for gdb connections", + "filterStderr": true, + "externalConsole": false, + "stopAtEntry": true, + "cwd": "${cwd}" + } + ] +} \ No newline at end of file diff --git a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/nanoCLR/CC13x2_26x2_CLR-DEBUG.ld b/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/nanoCLR/CC13x2_26x2_CLR-DEBUG.ld index f9c23d6690..c85b9538c1 100644 --- a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/nanoCLR/CC13x2_26x2_CLR-DEBUG.ld +++ b/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/nanoCLR/CC13x2_26x2_CLR-DEBUG.ld @@ -1,50 +1,46 @@ /* - @file cc26x2r1f.lds - @brief CC26x2R1F rev2 linker configuration file for GNU compiler. - - Revised $Date$ - Revision $Revision$ - - This file is auto-generated. - - Copyright (C) 2017 Texas Instruments Incorporated - http:www.ti.com/ - - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Texas Instruments Incorporated nor the names of - its contributors may be used to endorse or promote products derived - from this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ + * Copyright (c) 2017-2020, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* + * ======== CC1352R1_LAUNCHXL_TIRTOS.lds ======== + * Default Linker script for the Texas Instruments CC1352R1 + */ -STACKSIZE = 2048; +STACKSIZE = 3072; HEAPSIZE = 0x3000; /* Size of heap buffer used by HeapMem */ MEMORY { /* original flash LENGTH was 0x00057fa8 */ - FLASH (RX) : ORIGIN = 0x00000000, LENGTH = 0x00038000 + FLASH (RX) : ORIGIN = 0x00000000, LENGTH = 0x0003E000 /* * Customer Configuration Area and Bootloader Backdoor configuration in * flash, 40 bytes @@ -101,30 +97,50 @@ SECTIONS { * DMA channels must always be allocated at a fixed offset from the DMA base address. * --------- DO NOT MODIFY ----------- */ + DMA_UART0_RX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x10); + DMA_UART0_TX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x20); DMA_SPI0_RX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x30); DMA_SPI0_TX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x40); + DMA_UART1_RX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x50); + DMA_UART1_TX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x60); DMA_ADC_PRI_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x70); DMA_GPT0A_PRI_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x90); DMA_SPI1_RX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x100); DMA_SPI1_TX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x110); + DMA_UART0_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x210); + DMA_UART0_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x220); DMA_SPI0_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x230); DMA_SPI0_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x240); + DMA_UART1_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x250); + DMA_UART1_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x260); DMA_ADC_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x270); DMA_GPT0A_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x290); DMA_SPI1_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x300); DMA_SPI1_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x310); /* - * Allocate SPI0, SPI1, ADC, and GPTimer0 DMA descriptors at absolute addresses. + * Allocate UART0, UART1, SPI0, SPI1, ADC, and GPTimer0 DMA descriptors at absolute addresses. * --------- DO NOT MODIFY ----------- */ + UDMACC26XX_uart0RxControlTableEntry_is_placed = 0; + .dmaUart0RxControlTableEntry DMA_UART0_RX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART0_RX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart0RxControlTableEntry)} > REGION_DATA + + UDMACC26XX_uart0TxControlTableEntry_is_placed = 0; + .dmaUart0TxControlTableEntry DMA_UART0_TX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART0_TX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart0TxControlTableEntry)} > REGION_DATA + UDMACC26XX_dmaSpi0RxControlTableEntry_is_placed = 0; .dmaSpi0RxControlTableEntry DMA_SPI0_RX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI0_RX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi0RxControlTableEntry)} > REGION_DATA UDMACC26XX_dmaSpi0TxControlTableEntry_is_placed = 0; .dmaSpi0TxControlTableEntry DMA_SPI0_TX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI0_TX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi0TxControlTableEntry)} > REGION_DATA + UDMACC26XX_uart1RxControlTableEntry_is_placed = 0; + .dmaUart1RxControlTableEntry DMA_UART1_RX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART1_RX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart1RxControlTableEntry)} > REGION_DATA + + UDMACC26XX_uart1TxControlTableEntry_is_placed = 0; + .dmaUart1TxControlTableEntry DMA_UART1_TX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART1_TX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart1TxControlTableEntry)} > REGION_DATA + UDMACC26XX_dmaADCPriControlTableEntry_is_placed = 0; .dmaADCPriControlTableEntry DMA_ADC_PRI_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_ADC_PRI_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaADCPriControlTableEntry)} > REGION_DATA @@ -137,12 +153,24 @@ SECTIONS { UDMACC26XX_dmaSpi1TxControlTableEntry_is_placed = 0; .dmaSpi1TxControlTableEntry DMA_SPI1_TX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI1_TX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi1TxControlTableEntry)} > REGION_DATA + UDMACC26XX_uart0RxAltControlTableEntry_is_placed = 0; + .dmaUart0RxAltControlTableEntry DMA_UART0_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART0_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart0RxAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_uart0TxAltControlTableEntry_is_placed = 0; + .dmaUart0TxAltControlTableEntry DMA_UART0_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART0_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart0TxAltControlTableEntry)} > REGION_DATA + UDMACC26XX_dmaSpi0RxAltControlTableEntry_is_placed = 0; .dmaSpi0RxAltControlTableEntry DMA_SPI0_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI0_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi0RxAltControlTableEntry)} > REGION_DATA UDMACC26XX_dmaSpi0TxAltControlTableEntry_is_placed = 0; .dmaSpi0TxAltControlTableEntry DMA_SPI0_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI0_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi0TxAltControlTableEntry)} > REGION_DATA + UDMACC26XX_uart1RxAltControlTableEntry_is_placed = 0; + .dmaUart1RxAltControlTableEntry DMA_UART1_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART1_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart1RxAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_uart1TxAltControlTableEntry_is_placed = 0; + .dmaUart1TxAltControlTableEntry DMA_UART1_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART1_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart1TxAltControlTableEntry)} > REGION_DATA + UDMACC26XX_dmaADCAltControlTableEntry_is_placed = 0; .dmaADCAltControlTableEntry DMA_ADC_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_ADC_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaADCAltControlTableEntry)} > REGION_DATA @@ -190,6 +218,7 @@ SECTIONS { .rodata : { *(.rodata) *(.rodata.*) + *(.rodata_*) } > REGION_TEXT AT> REGION_TEXT .data : ALIGN(4) { @@ -211,7 +240,6 @@ SECTIONS { *(.ARM.extab* .gnu.linkonce.armextab.*) } > REGION_ARM_EXTAB AT> REGION_ARM_EXTAB - .nvs (NOLOAD) : ALIGN(0x2000) { *(.nvs) } > REGION_TEXT diff --git a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/nanoCLR/CC13x2_26x2_CLR.ld b/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/nanoCLR/CC13x2_26x2_CLR.ld index 76a8577807..aa8ee8f09c 100644 --- a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/nanoCLR/CC13x2_26x2_CLR.ld +++ b/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/nanoCLR/CC13x2_26x2_CLR.ld @@ -1,42 +1,38 @@ /* - @file cc26x2r1f.lds - @brief CC26x2R1F rev2 linker configuration file for GNU compiler. - - Revised $Date$ - Revision $Revision$ - - This file is auto-generated. - - Copyright (C) 2017 Texas Instruments Incorporated - http:www.ti.com/ - - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of Texas Instruments Incorporated nor the names of - its contributors may be used to endorse or promote products derived - from this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ + * Copyright (c) 2017-2020, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* + * ======== CC1352R1_LAUNCHXL_TIRTOS.lds ======== + * Default Linker script for the Texas Instruments CC1352R1 + */ STACKSIZE = 2048; HEAPSIZE = 0x2500; /* Size of heap buffer used by HeapMem */ @@ -44,7 +40,7 @@ HEAPSIZE = 0x2500; /* Size of heap buffer used by HeapMem */ MEMORY { /* original flash LENGTH was 0x00057fa8 */ - FLASH (RX) : ORIGIN = 0x00000000, LENGTH = 0x00028000 + FLASH (RX) : ORIGIN = 0x00000000, LENGTH = 0x0002C000 /* * Customer Configuration Area and Bootloader Backdoor configuration in * flash, 40 bytes @@ -101,30 +97,50 @@ SECTIONS { * DMA channels must always be allocated at a fixed offset from the DMA base address. * --------- DO NOT MODIFY ----------- */ + DMA_UART0_RX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x10); + DMA_UART0_TX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x20); DMA_SPI0_RX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x30); DMA_SPI0_TX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x40); + DMA_UART1_RX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x50); + DMA_UART1_TX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x60); DMA_ADC_PRI_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x70); DMA_GPT0A_PRI_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x90); DMA_SPI1_RX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x100); DMA_SPI1_TX_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x110); + DMA_UART0_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x210); + DMA_UART0_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x220); DMA_SPI0_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x230); DMA_SPI0_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x240); + DMA_UART1_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x250); + DMA_UART1_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x260); DMA_ADC_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x270); DMA_GPT0A_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x290); DMA_SPI1_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x300); DMA_SPI1_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS = (UDMACC26XX_CONFIG_BASE + 0x310); /* - * Allocate SPI0, SPI1, ADC, and GPTimer0 DMA descriptors at absolute addresses. + * Allocate UART0, UART1, SPI0, SPI1, ADC, and GPTimer0 DMA descriptors at absolute addresses. * --------- DO NOT MODIFY ----------- */ + UDMACC26XX_uart0RxControlTableEntry_is_placed = 0; + .dmaUart0RxControlTableEntry DMA_UART0_RX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART0_RX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart0RxControlTableEntry)} > REGION_DATA + + UDMACC26XX_uart0TxControlTableEntry_is_placed = 0; + .dmaUart0TxControlTableEntry DMA_UART0_TX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART0_TX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart0TxControlTableEntry)} > REGION_DATA + UDMACC26XX_dmaSpi0RxControlTableEntry_is_placed = 0; .dmaSpi0RxControlTableEntry DMA_SPI0_RX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI0_RX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi0RxControlTableEntry)} > REGION_DATA UDMACC26XX_dmaSpi0TxControlTableEntry_is_placed = 0; .dmaSpi0TxControlTableEntry DMA_SPI0_TX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI0_TX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi0TxControlTableEntry)} > REGION_DATA + UDMACC26XX_uart1RxControlTableEntry_is_placed = 0; + .dmaUart1RxControlTableEntry DMA_UART1_RX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART1_RX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart1RxControlTableEntry)} > REGION_DATA + + UDMACC26XX_uart1TxControlTableEntry_is_placed = 0; + .dmaUart1TxControlTableEntry DMA_UART1_TX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART1_TX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart1TxControlTableEntry)} > REGION_DATA + UDMACC26XX_dmaADCPriControlTableEntry_is_placed = 0; .dmaADCPriControlTableEntry DMA_ADC_PRI_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_ADC_PRI_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaADCPriControlTableEntry)} > REGION_DATA @@ -137,12 +153,24 @@ SECTIONS { UDMACC26XX_dmaSpi1TxControlTableEntry_is_placed = 0; .dmaSpi1TxControlTableEntry DMA_SPI1_TX_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI1_TX_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi1TxControlTableEntry)} > REGION_DATA + UDMACC26XX_uart0RxAltControlTableEntry_is_placed = 0; + .dmaUart0RxAltControlTableEntry DMA_UART0_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART0_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart0RxAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_uart0TxAltControlTableEntry_is_placed = 0; + .dmaUart0TxAltControlTableEntry DMA_UART0_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART0_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart0TxAltControlTableEntry)} > REGION_DATA + UDMACC26XX_dmaSpi0RxAltControlTableEntry_is_placed = 0; .dmaSpi0RxAltControlTableEntry DMA_SPI0_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI0_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi0RxAltControlTableEntry)} > REGION_DATA UDMACC26XX_dmaSpi0TxAltControlTableEntry_is_placed = 0; .dmaSpi0TxAltControlTableEntry DMA_SPI0_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_SPI0_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaSpi0TxAltControlTableEntry)} > REGION_DATA + UDMACC26XX_uart1RxAltControlTableEntry_is_placed = 0; + .dmaUart1RxAltControlTableEntry DMA_UART1_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART1_RX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart1RxAltControlTableEntry)} > REGION_DATA + + UDMACC26XX_uart1TxAltControlTableEntry_is_placed = 0; + .dmaUart1TxAltControlTableEntry DMA_UART1_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_UART1_TX_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaUart1TxAltControlTableEntry)} > REGION_DATA + UDMACC26XX_dmaADCAltControlTableEntry_is_placed = 0; .dmaADCAltControlTableEntry DMA_ADC_ALT_CONTROL_TABLE_ENTRY_ADDRESS (NOLOAD) : AT (DMA_ADC_ALT_CONTROL_TABLE_ENTRY_ADDRESS) {*(.dmaADCAltControlTableEntry)} > REGION_DATA @@ -190,6 +218,7 @@ SECTIONS { .rodata : { *(.rodata) *(.rodata.*) + *(.rodata_*) } > REGION_TEXT AT> REGION_TEXT .data : ALIGN(4) { @@ -211,7 +240,6 @@ SECTIONS { *(.ARM.extab* .gnu.linkonce.armextab.*) } > REGION_ARM_EXTAB AT> REGION_ARM_EXTAB - .nvs (NOLOAD) : ALIGN(0x2000) { *(.nvs) } > REGION_TEXT diff --git a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/nanoCLR/CMakeLists.txt b/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/nanoCLR/CMakeLists.txt index c61dda6ef2..f5fab75926 100644 --- a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/nanoCLR/CMakeLists.txt +++ b/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/nanoCLR/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/nanoCLR/main.c b/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/nanoCLR/main.c index 8d8590bf0d..4a27773439 100644 --- a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/nanoCLR/main.c +++ b/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/nanoCLR/main.c @@ -1,10 +1,11 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // #include #include +#include // RTOS header files #include @@ -13,18 +14,39 @@ #include // board Header files -#include +#include + +#include +// clang-format off +#include DeviceFamily_constructPath(inc/hw_prcm.h) +#include DeviceFamily_constructPath(driverlib/sys_ctrl.h) +// clang-format on ////////////////////////////// // Stack size in bytes -#define THREADSTACKSIZE 2048 +#define THREADSTACKSIZE 2048 Task_Handle receiverHandle; Task_Handle clrHandle; CLR_SETTINGS clrSettings; +// this define has to match the one in cpu_gpio.cpp +#define GPIO_MAX_PINS 16 + +// these are declared in cpu_gpio.cpp +extern GPIO_PinConfig gpioPinConfigs[GPIO_MAX_PINS]; +extern GPIO_CallbackFxn gpioCallbackFunctions[GPIO_MAX_PINS]; + +// this has to be define in a C file, otherwise the linker can't replace the weak one declared in the SDK driver library +const GPIOCC26XX_Config GPIOCC26XX_config = { + .pinConfigs = (GPIO_PinConfig *)gpioPinConfigs, + .callbacks = (GPIO_CallbackFxn *)gpioCallbackFunctions, + .numberOfPinConfigs = GPIO_MAX_PINS, + .numberOfCallbacks = GPIO_MAX_PINS, + .intPriority = (~0)}; + extern void ReceiverThread(UArg arg0, UArg arg1); extern void CLRStartupThread(UArg arg0, UArg arg1); @@ -32,8 +54,12 @@ int main(void) { Task_Params taskParams; + // get and store reset reason + // must be called before PIN_init() + WakeupReasonStore = SysCtrlResetSourceGet(); + // Call board init functions - Board_initGeneral(); + Board_init(); // setup Task thread Task_Params_init(&taskParams); @@ -44,14 +70,15 @@ int main(void) receiverHandle = Task_create((Task_FuncPtr)ReceiverThread, &taskParams, Error_IGNORE); if (receiverHandle == NULL) { - while (1); + while (1) + ; } - // CLR settings to launch CLR thread + // CLR settings to launch CLR thread (void)memset(&clrSettings, 0, sizeof(CLR_SETTINGS)); - clrSettings.MaxContextSwitches = 50; - clrSettings.WaitForDebugger = false; + clrSettings.MaxContextSwitches = 50; + clrSettings.WaitForDebugger = false; clrSettings.EnterDebuggerLoopAfterExit = true; // setup CLR task @@ -61,18 +88,26 @@ int main(void) clrHandle = Task_create(CLRStartupThread, &taskParams, Error_IGNORE); if (clrHandle == NULL) { - while (1); + while (1) + ; } GPIO_init(); - UART_init(); + ADC_init(); ConfigUART(); - // Switch off all LEDs on board - GPIO_write(Board_GPIO_RLED, Board_GPIO_LED_OFF); - GPIO_write(Board_GPIO_GLED, Board_GPIO_LED_OFF); - BIOS_start(); return (0); } + +/////////////////////////////////////////////////////////////////////// +// need this dummy implementation here (started with SDK 4.20.01.04) // +/////////////////////////////////////////////////////////////////////// +void __attribute__((naked)) _exit(int code) +{ + (void)code; + + for (;;) + ; +} diff --git a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/nanoCLR/nanoHAL.cpp b/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/nanoCLR/nanoHAL.cpp index 076a50fc68..a971e00292 100644 --- a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/nanoCLR/nanoHAL.cpp +++ b/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/nanoCLR/nanoHAL.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/nanoCLR/target_board.h.in b/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/nanoCLR/target_board.h.in index 25bf6abd7a..3d24fd3ffd 100644 --- a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/nanoCLR/target_board.h.in +++ b/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/nanoCLR/target_board.h.in @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/smartrf_settings/smartrf_settings.c b/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/smartrf_settings/smartrf_settings.c deleted file mode 100644 index 9a06172b11..0000000000 --- a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/smartrf_settings/smartrf_settings.c +++ /dev/null @@ -1,227 +0,0 @@ -//********************************************************************************* -// Generated by SmartRF Studio version 2.13.0 (build #164) -// Tested for SimpleLink SDK version: CC13x2 SDK 2.40.xx.xx -// Device: CC1352R Rev. 2.1 -// -//********************************************************************************* - - -//********************************************************************************* -// Parameter summary -// Address: 0 -// Address0: 0xAA -// Address1: 0xBB -// Frequency: 868.00000 MHz -// Data Format: Serial mode disable -// Deviation: 25.000 kHz -// pktLen: 30 -// 802.15.4g Mode: 0 -// Select bit order to transmit PSDU octets:: 1 -// Packet Length Config: Variable -// Max Packet Length: 255 -// Packet Length: 30 -// Packet Data: 255 -// RX Filter BW: 98.0 kHz -// Symbol Rate: 50.00000 kBaud -// Sync Word Length: 32 Bits -// TX Power: 14 dBm (requires define CCFG_FORCE_VDDR_HH = 1 in ccfg.c, see CC13xx/CC26xx Technical Reference Manual) -// Whitening: No whitening - -#include -#include DeviceFamily_constructPath(driverlib/rf_mailbox.h) -#include DeviceFamily_constructPath(driverlib/rf_common_cmd.h) -#include DeviceFamily_constructPath(driverlib/rf_prop_cmd.h) -#include -//#include DeviceFamily_constructPath(rf_patches/rf_patch_cpe_prop.h) -#include DeviceFamily_constructPath(rf_patches/rf_patch_cpe_multi_protocol.h) -#include "smartrf_settings.h" - - -// TI-RTOS RF Mode Object -RF_Mode RF_prop = -{ - .rfMode = RF_MODE_AUTO, - .cpePatchFxn = &rf_patch_cpe_multi_protocol, //&rf_patch_cpe_prop, - .mcePatchFxn = 0, - .rfePatchFxn = 0, -}; - -// Overrides for CMD_PROP_RADIO_DIV_SETUP -uint32_t pOverrides[] = -{ - // override_prop_common.xml - // DC/DC regulator: In Tx, use DCDCCTL5[3:0]=0x7 (DITHER_EN=0 and IPEAK=7). - (uint32_t)0x00F788D3, - // override_tc106.xml - // Tx: Configure PA ramp time, PACTL2.RC=0x3 (in ADI0, set PACTL2[4:3]=0x3) - ADI_2HALFREG_OVERRIDE(0,16,0x8,0x8,17,0x1,0x1), - // Rx: Set AGC reference level to 0x1A (default: 0x2E) - HW_REG_OVERRIDE(0x609C,0x001A), - // Rx: Set RSSI offset to adjust reported RSSI by -1 dB (default: -2), trimmed for external bias and differential configuration - (uint32_t)0x000188A3, - // Rx: Set anti-aliasing filter bandwidth to 0xD (in ADI0, set IFAMPCTL3[7:4]=0xD) - ADI_HALFREG_OVERRIDE(0,61,0xF,0xD), - // Tx: Set wait time before turning off ramp to 0x1A (default: 0x1F) - HW_REG_OVERRIDE(0x6028,0x001A), -#if (CCFG_FORCE_VDDR_HH) - // TX power override - // Tx: Set PA trim to max to maximize its output power (in ADI0, set PACTL0=0xF8) - ADI_REG_OVERRIDE(0,12,0xF8), -#endif - (uint32_t)0xFFFFFFFF, -}; - -// CMD_PROP_RADIO_DIV_SETUP -// Proprietary Mode Radio Setup Command for All Frequency Bands -rfc_CMD_PROP_RADIO_DIV_SETUP_t RF_cmdPropRadioDivSetup = -{ - .commandNo = 0x3807, - .status = 0x0000, - .pNextOp = 0, // INSERT APPLICABLE POINTER: (uint8_t*)&xxx - .startTime = 0x00000000, - .startTrigger.triggerType = 0x0, - .startTrigger.bEnaCmd = 0x0, - .startTrigger.triggerNo = 0x0, - .startTrigger.pastTrig = 0x0, - .condition.rule = 0x1, - .condition.nSkip = 0x0, - .modulation.modType = 0x1, - .modulation.deviation = 0x64, - .modulation.deviationStepSz = 0x0, - .symbolRate.preScale = 0xF, - .symbolRate.rateWord = 0x8000, - .symbolRate.decimMode = 0x0, - .rxBw = 0x52, - .preamConf.nPreamBytes = 0x4, - .preamConf.preamMode = 0x0, - .formatConf.nSwBits = 0x20, - .formatConf.bBitReversal = 0x0, - .formatConf.bMsbFirst = 0x1, - .formatConf.fecMode = 0x0, - .formatConf.whitenMode = 0x0, - .config.frontEndMode = 0x0, - .config.biasMode = 0x1, - .config.analogCfgMode = 0x0, - .config.bNoFsPowerUp = 0x0, - .txPower = 0x013F, - .pRegOverride = pOverrides, - .centerFreq = 0x0364, - .intFreq = 0x8000, - .loDivider = 0x05, -}; - -// CMD_FS -// Frequency Synthesizer Programming Command -rfc_CMD_FS_t RF_cmdFs = -{ - .commandNo = 0x0803, - .status = 0x0000, - .pNextOp = 0, // INSERT APPLICABLE POINTER: (uint8_t*)&xxx - .startTime = 0x00000000, - .startTrigger.triggerType = 0x0, - .startTrigger.bEnaCmd = 0x0, - .startTrigger.triggerNo = 0x0, - .startTrigger.pastTrig = 0x0, - .condition.rule = 0x1, - .condition.nSkip = 0x0, - .frequency = 0x0364, - .fractFreq = 0x0000, - .synthConf.bTxMode = 0x0, - .synthConf.refFreq = 0x0, - .__dummy0 = 0x00, - .__dummy1 = 0x00, - .__dummy2 = 0x00, - .__dummy3 = 0x0000, -}; - -// CMD_PROP_TX -// Proprietary Mode Transmit Command -rfc_CMD_PROP_TX_t RF_cmdPropTx = -{ - .commandNo = 0x3801, - .status = 0x0000, - .pNextOp = 0, // INSERT APPLICABLE POINTER: (uint8_t*)&xxx - .startTime = 0x00000000, - .startTrigger.triggerType = 0x0, - .startTrigger.bEnaCmd = 0x0, - .startTrigger.triggerNo = 0x0, - .startTrigger.pastTrig = 0x0, - .condition.rule = 0x1, - .condition.nSkip = 0x0, - .pktConf.bFsOff = 0x0, - .pktConf.bUseCrc = 0x1, - .pktConf.bVarLen = 0x1, - .pktLen = 0x1E, // SET APPLICATION PAYLOAD LENGTH - .syncWord = 0x930B51DE, - .pPkt = 0, // INSERT APPLICABLE POINTER: (uint8_t*)&xxx -}; - -// CMD_PROP_RX -// Proprietary Mode Receive Command -rfc_CMD_PROP_RX_t RF_cmdPropRx = -{ - .commandNo = 0x3802, - .status = 0x0000, - .pNextOp = 0, // INSERT APPLICABLE POINTER: (uint8_t*)&xxx - .startTime = 0x00000000, - .startTrigger.triggerType = 0x0, - .startTrigger.bEnaCmd = 0x0, - .startTrigger.triggerNo = 0x0, - .startTrigger.pastTrig = 0x0, - .condition.rule = 0x1, - .condition.nSkip = 0x0, - .pktConf.bFsOff = 0x0, - .pktConf.bRepeatOk = 0x0, - .pktConf.bRepeatNok = 0x0, - .pktConf.bUseCrc = 0x1, - .pktConf.bVarLen = 0x1, - .pktConf.bChkAddress = 0x0, - .pktConf.endType = 0x0, - .pktConf.filterOp = 0x0, - .rxConf.bAutoFlushIgnored = 0x0, - .rxConf.bAutoFlushCrcErr = 0x0, - .rxConf.bIncludeHdr = 0x1, - .rxConf.bIncludeCrc = 0x0, - .rxConf.bAppendRssi = 0x0, - .rxConf.bAppendTimestamp = 0x0, - .rxConf.bAppendStatus = 0x1, - .syncWord = 0x930B51DE, - .maxPktLen = 0xFF, // MAKE SURE DATA ENTRY IS LARGE ENOUGH - .address0 = 0xAA, - .address1 = 0xBB, - .endTrigger.triggerType = 0x1, - .endTrigger.bEnaCmd = 0x0, - .endTrigger.triggerNo = 0x0, - .endTrigger.pastTrig = 0x0, - .endTime = 0x00000000, - .pQueue = 0, // INSERT APPLICABLE POINTER: (dataQueue_t*)&xxx - .pOutput = 0, // INSERT APPLICABLE POINTER: (uint8_t*)&xxx -}; - -// CMD_TX_TEST -// Transmitter Test Command -rfc_CMD_TX_TEST_t RF_cmdTxTest = -{ - .commandNo = 0x0808, - .status = 0x0000, - .pNextOp = 0, // INSERT APPLICABLE POINTER: (uint8_t*)&xxx - .startTime = 0x00000000, - .startTrigger.triggerType = 0x0, - .startTrigger.bEnaCmd = 0x0, - .startTrigger.triggerNo = 0x0, - .startTrigger.pastTrig = 0x0, - .condition.rule = 0x1, - .condition.nSkip = 0x0, - .config.bUseCw = 0x0, - .config.bFsOff = 0x1, - .config.whitenMode = 0x2, - .__dummy0 = 0x00, - .txWord = 0xAAAA, - .__dummy1 = 0x00, - .endTrigger.triggerType = 0x1, - .endTrigger.bEnaCmd = 0x0, - .endTrigger.triggerNo = 0x0, - .endTrigger.pastTrig = 0x0, - .syncWord = 0x930B51DE, - .endTime = 0x00000000, -}; diff --git a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/smartrf_settings/smartrf_settings.h b/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/smartrf_settings/smartrf_settings.h deleted file mode 100644 index dff117386e..0000000000 --- a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/smartrf_settings/smartrf_settings.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef _SMARTRF_SETTINGS_H_ -#define _SMARTRF_SETTINGS_H_ - - -//********************************************************************************* -// Generated by SmartRF Studio version 2.13.0 (build #164) -// Tested for SimpleLink SDK version: CC13x2 SDK 2.40.xx.xx -// Device: CC1352R Rev. 2.1 -// -//********************************************************************************* - -#include -#include DeviceFamily_constructPath(driverlib/rf_mailbox.h) -#include DeviceFamily_constructPath(driverlib/rf_common_cmd.h) -#include DeviceFamily_constructPath(driverlib/rf_prop_cmd.h) -#include - -// TI-RTOS RF Mode Object -extern RF_Mode RF_prop; - -// RF Core API commands -extern rfc_CMD_PROP_RADIO_DIV_SETUP_t RF_cmdPropRadioDivSetup; -extern rfc_CMD_FS_t RF_cmdFs; -extern rfc_CMD_PROP_TX_t RF_cmdPropTx; -extern rfc_CMD_PROP_RX_t RF_cmdPropRx; -extern rfc_CMD_TX_TEST_t RF_cmdTxTest; - -// RF Core API Overrides -extern uint32_t pOverrides[]; - -#endif // _SMARTRF_SETTINGS_H_ diff --git a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/smartrf_settings/smartrf_settings_predefined.c b/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/smartrf_settings/smartrf_settings_predefined.c deleted file mode 100644 index 8acd751be1..0000000000 --- a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/smartrf_settings/smartrf_settings_predefined.c +++ /dev/null @@ -1,372 +0,0 @@ -//********************************************************************************* -// Generated by SmartRF Studio version 2.13.0 (build #164) -// Tested for SimpleLink SDK version: CC13x2 SDK 2.40.xx.xx -// Device: CC1352R Rev. 2.1 -// -//********************************************************************************* - - -#include -#include DeviceFamily_constructPath(driverlib/rf_mailbox.h) -#include DeviceFamily_constructPath(driverlib/rf_common_cmd.h) -#include DeviceFamily_constructPath(driverlib/rf_prop_cmd.h) -//#include DeviceFamily_constructPath(rf_patches/rf_patch_cpe_prop.h) -#include DeviceFamily_constructPath(rf_patches/rf_patch_cpe_multi_protocol.h) -#include -#include "smartrf_settings_predefined.h" - -// TI-RTOS RF Mode Object -RF_Mode RF_prop_fsk = -{ - .rfMode = RF_MODE_AUTO, - .cpePatchFxn = &rf_patch_cpe_multi_protocol, //&rf_patch_cpe_prop, - .mcePatchFxn = 0, - .rfePatchFxn = 0, -}; - -RF_Mode RF_prop_sl_lr = -{ - .rfMode = RF_MODE_AUTO, - .cpePatchFxn = &rf_patch_cpe_multi_protocol, //&rf_patch_cpe_prop, - .mcePatchFxn = 0, - .rfePatchFxn = 0, -}; - -RF_Mode RF_prop_fsk_200kbps = -{ - .rfMode = RF_MODE_AUTO, - .cpePatchFxn = &rf_patch_cpe_multi_protocol, //&rf_patch_cpe_prop, - .mcePatchFxn = 0, - .rfePatchFxn = 0, -}; - -// TX Power table -// The RF_TxPowerTable_DEFAULT_PA_ENTRY and RF_TxPowerTable_HIGH_PA_ENTRY macro is defined in RF.h. -// The following arguments are required: -// RF_TxPowerTable_DEFAULT_PA_ENTRY(bias, gain, boost coefficient) -// RF_TxPowerTable_HIGH_PA_ENTRY(bias, ibboost, boost, coefficient, ldoTrim) -// See the Technical Reference Manual for further details about the "txPower" Command field. -// The PA settings require the CCFG_FORCE_VDDR_HH = 0 unless stated otherwise. -RF_TxPowerTable_Entry RF_PROP_txPowerTable[RF_PROP_TX_POWER_TABLE_SIZE] = -{ - {-20, RF_TxPowerTable_DEFAULT_PA_ENTRY(0, 3, 0, 2) }, - {-15, RF_TxPowerTable_DEFAULT_PA_ENTRY(1, 3, 0, 3) }, - {-10, RF_TxPowerTable_DEFAULT_PA_ENTRY(2, 3, 0, 5) }, - {-5, RF_TxPowerTable_DEFAULT_PA_ENTRY(4, 3, 0, 5) }, - {0, RF_TxPowerTable_DEFAULT_PA_ENTRY(8, 3, 0, 8) }, - {1, RF_TxPowerTable_DEFAULT_PA_ENTRY(9, 3, 0, 9) }, - {2, RF_TxPowerTable_DEFAULT_PA_ENTRY(10, 3, 0, 9) }, - {3, RF_TxPowerTable_DEFAULT_PA_ENTRY(11, 3, 0, 10) }, - {4, RF_TxPowerTable_DEFAULT_PA_ENTRY(13, 3, 0, 11) }, - {5, RF_TxPowerTable_DEFAULT_PA_ENTRY(14, 3, 0, 14) }, - {6, RF_TxPowerTable_DEFAULT_PA_ENTRY(17, 3, 0, 16) }, - {7, RF_TxPowerTable_DEFAULT_PA_ENTRY(20, 3, 0, 19) }, - {8, RF_TxPowerTable_DEFAULT_PA_ENTRY(24, 3, 0, 22) }, - {9, RF_TxPowerTable_DEFAULT_PA_ENTRY(28, 3, 0, 31) }, - {10, RF_TxPowerTable_DEFAULT_PA_ENTRY(18, 2, 0, 31) }, - {11, RF_TxPowerTable_DEFAULT_PA_ENTRY(26, 2, 0, 51) }, - {12, RF_TxPowerTable_DEFAULT_PA_ENTRY(16, 0, 0, 82) }, - // The original PA value (12.5 dBm) has been rounded to an integer value. - {13, RF_TxPowerTable_DEFAULT_PA_ENTRY(36, 0, 0, 89) }, - // This setting requires CCFG_FORCE_VDDR_HH = 1. - {14, RF_TxPowerTable_DEFAULT_PA_ENTRY(63, 0, 1, 0) }, - RF_TxPowerTable_TERMINATION_ENTRY -}; - -// Overrides for CMD_PROP_RADIO_DIV_SETUP FSK -uint32_t pOverrides_fsk[] = -{ - // override_prop_common.xml - // DC/DC regulator: In Tx, use DCDCCTL5[3:0]=0x7 (DITHER_EN=0 and IPEAK=7). - (uint32_t)0x00F788D3, - // override_tc106.xml - // Tx: Configure PA ramp time, PACTL2.RC=0x3 (in ADI0, set PACTL2[4:3]=0x3) - ADI_2HALFREG_OVERRIDE(0,16,0x8,0x8,17,0x1,0x1), - // Rx: Set AGC reference level to 0x1A (default: 0x2E) - HW_REG_OVERRIDE(0x609C,0x001A), - // Rx: Set RSSI offset to adjust reported RSSI by -1 dB (default: -2), trimmed for external bias and differential configuration - (uint32_t)0x000188A3, - // Rx: Set anti-aliasing filter bandwidth to 0xD (in ADI0, set IFAMPCTL3[7:4]=0xD) - ADI_HALFREG_OVERRIDE(0,61,0xF,0xD), - // Tx: Set wait time before turning off ramp to 0x1A (default: 0x1F) - HW_REG_OVERRIDE(0x6028,0x001A), -#if (CCFG_FORCE_VDDR_HH) - // TX power override - // Tx: Set PA trim to max to maximize its output power (in ADI0, set PACTL0=0xF8) - ADI_REG_OVERRIDE(0,12,0xF8), -#endif - (uint32_t)0xFFFFFFFF, -}; - -// Overrides for CMD_RADIO_DIV_SETUP SIMPLELINK LONGRANGE -uint32_t pOverrides_sl_lr[] = -{ - // override_prop_common.xml - // DC/DC regulator: In Tx, use DCDCCTL5[3:0]=0x7 (DITHER_EN=0 and IPEAK=7). - (uint32_t)0x00F788D3, - // override_phy_simplelink_long_range_dsss2.xml - // PHY: Configure DSSS SF=2 for payload data - HW_REG_OVERRIDE(0x5068,0x0100), //DSSSx2 5kbps - //HW_REG_OVERRIDE(0x5068,0x030C), // DSSSx4 2.5kbps - //HW_REG_OVERRIDE(0x5068,0x073C), // DSSSx8 1.25kbps - // override_tc480_tc481_tc482.xml - // Tx: Configure PA ramp time, PACTL2.RC=0x3 (in ADI0, set PACTL2[4:3]=0x3) - ADI_2HALFREG_OVERRIDE(0,16,0x8,0x8,17,0x1,0x1), - // Rx: Set AGC reference level to 0x17 (default: 0x2E) - HW_REG_OVERRIDE(0x609C,0x0017), - // Rx: Set RSSI offset to adjust reported RSSI by -2 dB (default: -2), trimmed for external bias and differential configuration - (uint32_t)0x000288A3, - // Rx: Set anti-aliasing filter bandwidth to 0xD (in ADI0, set IFAMPCTL3[7:4]=0xD) - ADI_HALFREG_OVERRIDE(0,61,0xF,0xD), - // Tx: Set wait time before turning off ramp to 0x1A (default: 0x1F) - HW_REG_OVERRIDE(0x6028,0x001A), -#if (CCFG_FORCE_VDDR_HH) - // TX power override - // Tx: Set PA trim to max to maximize its output power (in ADI0, set PACTL0=0xF8) - ADI_REG_OVERRIDE(0,12,0xF8), -#endif - (uint32_t)0xFFFFFFFF, -}; - -// Overrides for CMD_PROP_RADIO_DIV_SETUP FSK 200KBPS -uint32_t pOverrides_fsk_200kbps[] = -{ - // override_prop_common.xml - // DC/DC regulator: In Tx, use DCDCCTL5[3:0]=0x7 (DITHER_EN=0 and IPEAK=7). - (uint32_t)0x00F788D3, - // override_tc146.xml - // Tx: Configure PA ramp time, PACTL2.RC=0x3 (in ADI0, set PACTL2[4:3]=0x3) - ADI_2HALFREG_OVERRIDE(0,16,0x8,0x8,17,0x1,0x1), - // Tx: Configure PA ramping, set wait time before turning off (0x1A ticks of 16/24 us = 17.3 us). - HW_REG_OVERRIDE(0x6028,0x001A), - // Rx: Set AGC reference level to 0x16 (default: 0x2E) - HW_REG_OVERRIDE(0x609C,0x0016), - // Rx: Set RSSI offset to adjust reported RSSI by -1 dB (default: -2), trimmed for external bias and differential configuration - (uint32_t)0x000188A3, - // Rx: Set anti-aliasing filter bandwidth to 0x8 (in ADI0, set IFAMPCTL3[7:4]=0x8) - ADI_HALFREG_OVERRIDE(0,61,0xF,0x8), -#if (CCFG_FORCE_VDDR_HH) - // TX power override - // Tx: Set PA trim to max to maximize its output power (in ADI0, set PACTL0=0xF8) - ADI_REG_OVERRIDE(0,12,0xF8), -#endif - (uint32_t)0xFFFFFFFF -}; - -// CMD_PROP_RADIO_DIV_SETUP FSK -rfc_CMD_PROP_RADIO_DIV_SETUP_t RF_cmdPropRadioDivSetup_fsk = -{ - .commandNo = 0x3807, - .status = 0x0000, - .pNextOp = 0, // INSERT APPLICABLE POINTER: (uint8_t*)&xxx - .startTime = 0x00000000, - .startTrigger.triggerType = 0x0, - .startTrigger.bEnaCmd = 0x0, - .startTrigger.triggerNo = 0x0, - .startTrigger.pastTrig = 0x0, - .condition.rule = 0x1, - .condition.nSkip = 0x0, - .modulation.modType = 0x1, - .modulation.deviation = 0x64, - .modulation.deviationStepSz = 0x0, - .symbolRate.preScale = 0xF, - .symbolRate.rateWord = 0x8000, - .symbolRate.decimMode = 0x0, - .rxBw = 0x52, - .preamConf.nPreamBytes = 0x4, - .preamConf.preamMode = 0x0, - .formatConf.nSwBits = 0x20, - .formatConf.bBitReversal = 0x0, - .formatConf.bMsbFirst = 0x1, - .formatConf.fecMode = 0x0, - .formatConf.whitenMode = 0x0, - .config.frontEndMode = 0x0, - .config.biasMode = 0x1, - .config.analogCfgMode = 0x0, - .config.bNoFsPowerUp = 0x0, - .txPower = 0x013F, - .pRegOverride = pOverrides_fsk, - .centerFreq = 0x0364, - .intFreq = 0x8000, - .loDivider = 0x05, -}; - -// CMD_PROP_RADIO_DIV_SETUP SIMPLELING LONGRANGE -rfc_CMD_PROP_RADIO_DIV_SETUP_t RF_cmdPropRadioDivSetup_sl_lr = -{ - .commandNo = 0x3807, - .status = 0x0000, - .pNextOp = 0, // INSERT APPLICABLE POINTER: (uint8_t*)&xxx - .startTime = 0x00000000, - .startTrigger.triggerType = 0x0, - .startTrigger.bEnaCmd = 0x0, - .startTrigger.triggerNo = 0x0, - .startTrigger.pastTrig = 0x0, - .condition.rule = 0x1, - .condition.nSkip = 0x0, - .modulation.modType = 0x1, - .modulation.deviation = 0x14, - .modulation.deviationStepSz = 0x0, - .symbolRate.preScale = 0xF, - .symbolRate.rateWord = 0x3333, - .symbolRate.decimMode = 0x0, - .rxBw = 0x4C, - .preamConf.nPreamBytes = 0x2, - .preamConf.preamMode = 0x0, - .formatConf.nSwBits = 0x20, - .formatConf.bBitReversal = 0x0, - .formatConf.bMsbFirst = 0x0, - .formatConf.fecMode = 0x8, - .formatConf.whitenMode = 0x1, - .config.frontEndMode = 0x0, - .config.biasMode = 0x1, - .config.analogCfgMode = 0x0, - .config.bNoFsPowerUp = 0x0, - .txPower = 0x013F, - .pRegOverride = pOverrides_sl_lr, - .centerFreq = 0x0364, - .intFreq = 0x8000, - .loDivider = 0x05, -}; - -// CMD_PROP_RADIO_DIV_SETUP FSK 200 KBPS -// Proprietary Mode Radio Setup Command for All Frequency Bands -rfc_CMD_PROP_RADIO_DIV_SETUP_t RF_cmdPropRadioDivSetup_fsk_200kbps = -{ - .commandNo = 0x3807, - .status = 0x0000, - .pNextOp = 0, // INSERT APPLICABLE POINTER: (uint8_t*)&xxx - .startTime = 0x00000000, - .startTrigger.triggerType = 0x0, - .startTrigger.bEnaCmd = 0x0, - .startTrigger.triggerNo = 0x0, - .startTrigger.pastTrig = 0x0, - .condition.rule = 0x1, - .condition.nSkip = 0x0, - .modulation.modType = 0x1, - .modulation.deviation = 0xC8, - .modulation.deviationStepSz = 0x0, - .symbolRate.preScale = 0xF, - .symbolRate.rateWord = 0x20000, - .symbolRate.decimMode = 0x0, - .rxBw = 0x59, - .preamConf.nPreamBytes = 0x7, - .preamConf.preamMode = 0x0, - .formatConf.nSwBits = 0x18, - .formatConf.bBitReversal = 0x0, - .formatConf.bMsbFirst = 0x1, - .formatConf.fecMode = 0x0, - .formatConf.whitenMode = 0x7, - .config.frontEndMode = 0x0, - .config.biasMode = 0x1, - .config.analogCfgMode = 0x0, - .config.bNoFsPowerUp = 0x0, - .txPower = 0x013F, - .pRegOverride = pOverrides_fsk_200kbps, - .centerFreq = 0x0364, - .intFreq = 0x0999, - .loDivider = 0x05 -}; - -// CMD_FS -rfc_CMD_FS_t RF_cmdFs_preDef = -{ - .commandNo = 0x0803, - .status = 0x0000, - .pNextOp = 0, // INSERT APPLICABLE POINTER: (uint8_t*)&xxx - .startTime = 0x00000000, - .startTrigger.triggerType = 0x0, - .startTrigger.bEnaCmd = 0x0, - .startTrigger.triggerNo = 0x0, - .startTrigger.pastTrig = 0x0, - .condition.rule = 0x1, - .condition.nSkip = 0x0, - .frequency = 0x0364, - .fractFreq = 0x0000, - .synthConf.bTxMode = 0x0, - .synthConf.refFreq = 0x0, - .__dummy0 = 0x00, - .__dummy1 = 0x00, - .__dummy2 = 0x00, - .__dummy3 = 0x0000, -}; - -// CMD_PROP_TX_ADV -rfc_CMD_PROP_TX_ADV_t RF_cmdPropTxAdv_preDef = -{ - .commandNo = 0x3803, - .status = 0x0000, - .pNextOp = 0, // INSERT APPLICABLE POINTER: (uint8_t*)&xxx - .startTime = 0x00000000, - .startTrigger.triggerType = 0x2, - .startTrigger.bEnaCmd = 0x0, - .startTrigger.triggerNo = 0x0, - .startTrigger.pastTrig = 0x1, - .condition.rule = 0x1, - .condition.nSkip = 0x0, - .pktConf.bFsOff = 0x0, - .pktConf.bUseCrc = 0x1, - .pktConf.bCrcIncSw = 0x0, - .pktConf.bCrcIncHdr = 0x0, - .numHdrBits = 0x10, - .pktLen = 0x0014, - .startConf.bExtTxTrig = 0x0, - .startConf.inputMode = 0x0, - .startConf.source = 0x0, - .preTrigger.triggerType = 0x4, - .preTrigger.bEnaCmd = 0x0, - .preTrigger.triggerNo = 0x0, - .preTrigger.pastTrig = 0x1, - .preTime = 0x00000000, - .syncWord = 0x0055904E, - .pPkt = 0, // INSERT APPLICABLE POINTER: (uint8_t*)&xxx -}; - -// CMD_PROP_RX_ADV -rfc_CMD_PROP_RX_ADV_t RF_cmdPropRxAdv_preDef = -{ - .commandNo = 0x3804, - .status = 0x0000, - .pNextOp = 0, // INSERT APPLICABLE POINTER: (uint8_t*)&xxx - .startTime = 0x00000000, - .startTrigger.triggerType = 0x0, - .startTrigger.bEnaCmd = 0x0, - .startTrigger.triggerNo = 0x0, - .startTrigger.pastTrig = 0x0, - .condition.rule = 0x1, - .condition.nSkip = 0x0, - .pktConf.bFsOff = 0x0, - .pktConf.bRepeatOk = 0x0, - .pktConf.bRepeatNok = 0x0, - .pktConf.bUseCrc = 0x1, - .pktConf.bCrcIncSw = 0x0, - .pktConf.bCrcIncHdr = 0x0, - .pktConf.endType = 0x0, - .pktConf.filterOp = 0x1, - .rxConf.bAutoFlushIgnored = 0x0, - .rxConf.bAutoFlushCrcErr = 0x0, - .rxConf.bIncludeHdr = 0x1, - .rxConf.bIncludeCrc = 0x0, - .rxConf.bAppendRssi = 0x0, - .rxConf.bAppendTimestamp = 0x0, - .rxConf.bAppendStatus = 0x0, - .syncWord0 = 0x0055904E, - .syncWord1 = 0x00000000, - .maxPktLen = 0x00FF, - .hdrConf.numHdrBits = 0x10, - .hdrConf.lenPos = 0x0, - .hdrConf.numLenBits = 0x8, - .addrConf.addrType = 0x0, - .addrConf.addrSize = 0x0, - .addrConf.addrPos = 0x0, - .addrConf.numAddr = 0x0, - .lenOffset = 0xFC, - .endTrigger.triggerType = 0x1, - .endTrigger.bEnaCmd = 0x0, - .endTrigger.triggerNo = 0x0, - .endTrigger.pastTrig = 0x0, - .endTime = 0x00000000, - .pAddr = 0, // INSERT APPLICABLE POINTER: (uint8_t*)&xxx - .pQueue = 0, // INSERT APPLICABLE POINTER: (dataQueue_t*)&xxx - .pOutput = 0, // INSERT APPLICABLE POINTER: (uint8_t*)&xxx -}; diff --git a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/smartrf_settings/smartrf_settings_predefined.h b/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/smartrf_settings/smartrf_settings_predefined.h deleted file mode 100644 index af2f55d1eb..0000000000 --- a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/smartrf_settings/smartrf_settings_predefined.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef _SMARTRF_SETTINGS_PREDEFINED_H_ -#define _SMARTRF_SETTINGS_PREDEFINED_H_ - - -//********************************************************************************* -// Generated by SmartRF Studio version 2.13.0 (build #164) -// Tested for SimpleLink SDK version: CC13x2 SDK 2.40.xx.xx -// Device: CC1352R Rev. 2.1 -// -//********************************************************************************* - - -#include -#include DeviceFamily_constructPath(driverlib/rf_mailbox.h) -#include DeviceFamily_constructPath(driverlib/rf_common_cmd.h) -#include DeviceFamily_constructPath(driverlib/rf_prop_cmd.h) - -#include - - -// TX Power table size definition -#define RF_PROP_TX_POWER_TABLE_SIZE 20 - -// TX Power Table Object -extern RF_TxPowerTable_Entry RF_PROP_txPowerTable[]; - - -/* RF Core API commands */ -/* RF command pointers for easylink */ -extern RF_Mode RF_prop_fsk; -extern RF_Mode RF_prop_sl_lr; -extern RF_Mode RF_prop_fsk_200kbps; - -extern rfc_CMD_PROP_RADIO_DIV_SETUP_t RF_cmdPropRadioDivSetup_fsk; -extern rfc_CMD_PROP_RADIO_DIV_SETUP_t RF_cmdPropRadioDivSetup_sl_lr; -extern rfc_CMD_PROP_RADIO_DIV_SETUP_t RF_cmdPropRadioDivSetup_fsk_200kbps; - -extern rfc_CMD_FS_t RF_cmdFs_preDef; -extern rfc_CMD_PROP_TX_ADV_t RF_cmdPropTxAdv_preDef; -extern rfc_CMD_PROP_RX_ADV_t RF_cmdPropRxAdv_preDef; - -extern uint32_t pOverrides_fsk[]; -extern uint32_t pOverrides_sl_lr[]; -extern uint32_t pOverrides_fsk_200kbps[]; - -#endif // _SMARTRF_SETTINGS_PREDEFINED_H_ diff --git a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/target_BlockStorage.c b/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/target_BlockStorage.c index a69657bb6c..dd6b9b2742 100644 --- a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/target_BlockStorage.c +++ b/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/target_BlockStorage.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/target_BlockStorage.h b/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/target_BlockStorage.h index f28f448474..e3afd93c53 100644 --- a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/target_BlockStorage.h +++ b/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/target_BlockStorage.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/target_Power.c b/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/target_Power.c index 88ce5becd9..eb91babfee 100644 --- a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/target_Power.c +++ b/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/target_Power.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/target_common.c b/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/target_common.c index 7aabc92290..a8a6e11f34 100644 --- a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/target_common.c +++ b/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/target_common.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/target_common.h.in b/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/target_common.h.in index e2f95b404d..87881863da 100644 --- a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/target_common.h.in +++ b/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/target_common.h.in @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // @@ -13,6 +13,8 @@ #include +#define TARGETINFOSTRING "@CMAKE_BUILD_TYPE@ build with TI CC13x2_26x2 SDK v@TI_SL_CC13x2_26x2_SDK_TAG@" + ///////////////////////////////////////////////////////////////////////////////////////// // The following addresses and sizes should be filled in according to the SoC data-sheet // they also must be coherent with what's in the linker file for nanoBooter and nanoCLR @@ -48,9 +50,9 @@ ///////////////////////////////////// #if defined(DEBUG) - #define MANAGED_HEAP_SIZE (35*1024) + #define MANAGED_HEAP_SIZE (29*1024) #else - #define MANAGED_HEAP_SIZE (42*1024) + #define MANAGED_HEAP_SIZE (37*1024) #endif ///////////////////////////////////// diff --git a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/target_windows_devices_adc_config.cpp b/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/target_windows_devices_adc_config.cpp new file mode 100644 index 0000000000..949567e829 --- /dev/null +++ b/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/target_windows_devices_adc_config.cpp @@ -0,0 +1,8 @@ +// +// Copyright (c) .NET Foundation and Contributors +// See LICENSE file in the project root for full license information. +// + +/////////////////////////////////////////////////////////////////////////////////////////////////// +// THIS FILE IS BLANK ON PURPOSE BECAUSE THIS TARGET DOESN'T REQUIRE THIS SPECIFIC CONFIGURATION // +/////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/target_windows_devices_gpio.h b/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/target_windows_devices_gpio.h new file mode 100644 index 0000000000..cd46fb9070 --- /dev/null +++ b/targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/target_windows_devices_gpio.h @@ -0,0 +1,12 @@ +// +// Copyright (c) .NET Foundation and Contributors +// See LICENSE file in the project root for full license information. +// + +#ifndef _TARGET_WINDOWS_DEVICES_GPIO_H_ +#define _TARGET_WINDOWS_DEVICES_GPIO_H_ + +// max number of GPIO pins +#define GPIO_PINS_COUNT 32 + +#endif // _TARGET_WINDOWS_DEVICES_GPIO_H_ diff --git a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/Board.h b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/Board.h index 62d2198344..15e66413aa 100644 --- a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/Board.h +++ b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/Board.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Texas Instruments Incorporated. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/CC3220SF_LAUNCHXL.c b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/CC3220SF_LAUNCHXL.c index 104e686272..291e3a6e4a 100644 --- a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/CC3220SF_LAUNCHXL.c +++ b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/CC3220SF_LAUNCHXL.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Texas Instruments Incorporated. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/CC3220SF_LAUNCHXL.h b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/CC3220SF_LAUNCHXL.h index 438f06c406..e0a880605d 100644 --- a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/CC3220SF_LAUNCHXL.h +++ b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/CC3220SF_LAUNCHXL.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Texas Instruments Incorporated. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/CMakeLists.txt b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/CMakeLists.txt index 45cf978532..66bbf81dd3 100644 --- a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/CMakeLists.txt +++ b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/cmake-variants.json b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/cmake-variants.json new file mode 100644 index 0000000000..21aa5aa161 --- /dev/null +++ b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/cmake-variants.json @@ -0,0 +1,55 @@ +{ + "buildType": { + "default": "debug", + "choices": { + "debug": { + "short": "Debug", + "long": "Emit debug information without performing optimizations", + "buildType": "Debug" + }, + "minsize": { + "short": "MinSizeRel", + "long": "Optimize for smallest binary size", + "buildType": "MinSizeRel" + }, + "reldeb": { + "short": "RelWithDebInfo", + "long": "Perform optimizations AND include debugging information", + "buildType": "RelWithDebInfo" + } + } + }, + "linkage": { + "default": "", + "choices": { + "TI_CC3220SF_LAUNCHXL": { + "short": "TI_CC3220SF_LAUNCHXL", + "settings": { + "BUILD_VERSION": "0.9.99.999", + "CMAKE_TOOLCHAIN_FILE": "CMake/toolchain.arm-none-eabi.cmake", + "TOOLCHAIN_PREFIX": "", + "RTOS": "TI_SIMPLELINK", + "TARGET_SERIES": "CC32xx", + "TI_BOARD": "TI_CC3220SF_LAUNCHXL", + "TI_SL_CC32xx_SDK_SOURCE": "", + "SUPPORT_ANY_BASE_CONVERSION": "OFF", + "NF_FEATURE_DEBUGGER": "ON", + "NF_FEATURE_RTC": "ON", + "NF_FEATURE_HAS_SDCARD": "OFF", + "NF_FEATURE_HAS_CONFIG_BLOCK": "ON", + "NF_BUILD_RTM": "OFF", + "API_System.Math": "ON", + "API_Windows.Devices.Gpio": "ON", + "API_Windows.Devices.Spi": "ON", + "API_Windows.Devices.I2c": "ON", + "API_Windows.Devices.Pwm": "ON", + "API_Windows.Devices.SerialCommunication": "OFF", + "API_System.Net": "ON", + "API_nanoFramework.ResourceManager": "OFF", + "API_nanoFramework.System.Collections": "ON", + "API_nanoFramework.System.Text": "ON" + } + } + } + } +} diff --git a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/common/CMakeLists.txt b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/common/CMakeLists.txt index 42be0d5f5a..3b62894577 100644 --- a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/common/CMakeLists.txt +++ b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/common/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2017 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/common/Device_BlockStorage-DEBUG.c b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/common/Device_BlockStorage-DEBUG.c index 478cd4e9b1..e93f27cd2f 100644 --- a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/common/Device_BlockStorage-DEBUG.c +++ b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/common/Device_BlockStorage-DEBUG.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/common/Device_BlockStorage.c b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/common/Device_BlockStorage.c index 8b8b95b655..a553771f36 100644 --- a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/common/Device_BlockStorage.c +++ b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/common/Device_BlockStorage.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/launch.json b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/launch.json new file mode 100644 index 0000000000..4f8326fa07 --- /dev/null +++ b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/launch.json @@ -0,0 +1,51 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "TI_CC3220SF_LAUNCHXL nanoCLR", + "type": "cppdbg", + "request": "launch", + "MIMode": "gdb", + "miDebuggerPath": "/bin/arm-none-eabi-gdb.exe", + "targetArchitecture": "ARM", + "program": "${workspaceRoot}/build/nanoCLR.elf", + "setupCommands": [ + { + "text": "-target-select remote localhost:3333" + }, + { + "text": "-file-exec-and-symbols /build/nanoCLR.elf" + }, + { + "text": "-interpreter-exec console \"monitor endian little\"" + }, + { + "text": "-interpreter-exec console \"monitor reset\"" + }, + { + "text": "-interpreter-exec console \"monitor halt\"" + }, + { + "text": "-interpreter-exec console \"monitor arm semihosting enable\"" + }, + { + "text": "-target-download" + } + ], + "logging": { + "moduleLoad": false, + "trace": false, + "engineLogging": false, + "programOutput": true, + "exceptions": true + }, + "debugServerPath": "/bin/openocd.exe", + "debugServerArgs": "-s \"/share/openocd/scripts/\" -f board/ti_cc3220sf_launchpad.cfg", + "serverStarted": "Listening on port 3333 for gdb connections", + "filterStderr": true, + "externalConsole": false, + "stopAtEntry": true, + "cwd": "${cwd}" + } + ] +} \ No newline at end of file diff --git a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/managed_helpers/TI_CC3220SF_LAUNCHXL.Gpio.cs b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/managed_helpers/TI_CC3220SF_LAUNCHXL.Gpio.cs index 1a9adc02d3..ace3b6054e 100644 --- a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/managed_helpers/TI_CC3220SF_LAUNCHXL.Gpio.cs +++ b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/managed_helpers/TI_CC3220SF_LAUNCHXL.Gpio.cs @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/managed_helpers/package.nuspec b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/managed_helpers/package.nuspec index 8553a224bd..f28685703d 100644 --- a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/managed_helpers/package.nuspec +++ b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/managed_helpers/package.nuspec @@ -18,7 +18,7 @@ https://github.com/nanoframework https://secure.gravatar.com/avatar/97d0e092247f0716db6d4b47b7d1d1ad https://github.com/nanoframework/nf-interpreter/blob/develop/LICENSE.md - Copyright (c) 2019 The nanoFramework project contributors + Copyright (c) .NET Foundation and Contributors nanoFramework, nano Framework, NETNF, NETMF, Micro Framework,.net diff --git a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/nanoCLR/CC3220SF_CLR-DEBUG.ld b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/nanoCLR/CC3220SF_CLR-DEBUG.ld index 240e17aeba..45b57d5731 100644 --- a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/nanoCLR/CC3220SF_CLR-DEBUG.ld +++ b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/nanoCLR/CC3220SF_CLR-DEBUG.ld @@ -1,6 +1,6 @@ /* // -// Copyright (c) 2020 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Copyright (c) 2016-2018, Texas Instruments Incorporated // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/nanoCLR/CC3220SF_CLR.ld b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/nanoCLR/CC3220SF_CLR.ld index 06f0f87799..fdfea9f388 100644 --- a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/nanoCLR/CC3220SF_CLR.ld +++ b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/nanoCLR/CC3220SF_CLR.ld @@ -1,6 +1,6 @@ /* // -// Copyright (c) 2020 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Copyright (c) 2016-2018, Texas Instruments Incorporated // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/nanoCLR/CMakeLists.txt b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/nanoCLR/CMakeLists.txt index 605070bbaa..6fef105869 100644 --- a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/nanoCLR/CMakeLists.txt +++ b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/nanoCLR/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/nanoCLR/main.c b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/nanoCLR/main.c index af1d6ac255..805802dce7 100644 --- a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/nanoCLR/main.c +++ b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/nanoCLR/main.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/nanoCLR/nanoHAL.cpp b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/nanoCLR/nanoHAL.cpp index 076a50fc68..a971e00292 100644 --- a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/nanoCLR/nanoHAL.cpp +++ b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/nanoCLR/nanoHAL.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/nanoCLR/target_board.h.in b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/nanoCLR/target_board.h.in index 25bf6abd7a..3d24fd3ffd 100644 --- a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/nanoCLR/target_board.h.in +++ b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/nanoCLR/target_board.h.in @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/nanoCLR/ti_drivers_net_wifi_Config.c b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/nanoCLR/ti_drivers_net_wifi_Config.c index 8806c8f011..a023593685 100644 --- a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/nanoCLR/ti_drivers_net_wifi_Config.c +++ b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/nanoCLR/ti_drivers_net_wifi_Config.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Texas Instruments Incorporated. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/target_BlockStorage.c b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/target_BlockStorage.c index ab075246ab..9970fc8c80 100644 --- a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/target_BlockStorage.c +++ b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/target_BlockStorage.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/target_BlockStorage.h b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/target_BlockStorage.h index aa50b1b7f2..8a56d0eee0 100644 --- a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/target_BlockStorage.h +++ b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/target_BlockStorage.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/target_Power.c b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/target_Power.c index 5ab9791148..e151247fcc 100644 --- a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/target_Power.c +++ b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/target_Power.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/target_common.c b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/target_common.c index 7aabc92290..a8a6e11f34 100644 --- a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/target_common.c +++ b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/target_common.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/target_common.h.in b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/target_common.h.in index 318dd3cc7c..fe05c3ce65 100644 --- a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/target_common.h.in +++ b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/target_common.h.in @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // @@ -13,6 +13,8 @@ #include +#define TARGETINFOSTRING "@CMAKE_BUILD_TYPE@ build with TI SL CC32xx SDK v3.10.00.04" + ///////////////////////////////////////////////////////////////////////////////////////// // The following addresses and sizes should be filled in according to the SoC data-sheet // they also must be coherent with what's in the linker file for nanoBooter and nanoCLR diff --git a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/target_sntp_opts.h b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/target_sntp_opts.h index ecd95c61d1..3d42dcfe5b 100644 --- a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/target_sntp_opts.h +++ b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/target_sntp_opts.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/target_windows_devices_adc_config.cpp b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/target_windows_devices_adc_config.cpp index d7b7376bc0..949567e829 100644 --- a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/target_windows_devices_adc_config.cpp +++ b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/target_windows_devices_adc_config.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/target_windows_devices_gpio.h b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/target_windows_devices_gpio.h new file mode 100644 index 0000000000..cd46fb9070 --- /dev/null +++ b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/target_windows_devices_gpio.h @@ -0,0 +1,12 @@ +// +// Copyright (c) .NET Foundation and Contributors +// See LICENSE file in the project root for full license information. +// + +#ifndef _TARGET_WINDOWS_DEVICES_GPIO_H_ +#define _TARGET_WINDOWS_DEVICES_GPIO_H_ + +// max number of GPIO pins +#define GPIO_PINS_COUNT 32 + +#endif // _TARGET_WINDOWS_DEVICES_GPIO_H_ diff --git a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/target_windows_devices_i2c_config.cpp b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/target_windows_devices_i2c_config.cpp index 76238dbec3..949567e829 100644 --- a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/target_windows_devices_i2c_config.cpp +++ b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/target_windows_devices_i2c_config.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/target_windows_devices_pwm_config.h b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/target_windows_devices_pwm_config.h index e3c11018ca..2bc65d1723 100644 --- a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/target_windows_devices_pwm_config.h +++ b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/target_windows_devices_pwm_config.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/target_windows_devices_spi_config.cpp b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/target_windows_devices_spi_config.cpp index 76238dbec3..949567e829 100644 --- a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/target_windows_devices_spi_config.cpp +++ b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/target_windows_devices_spi_config.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/ti-rtos-debug.cfg b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/ti-rtos-debug.cfg index f7eaed6553..c1fb8c3bde 100644 --- a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/ti-rtos-debug.cfg +++ b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/ti-rtos-debug.cfg @@ -1,6 +1,6 @@ /* // -// Copyright (c) 2020 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Copyright (c) 2016-2018, Texas Instruments Incorporated // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/ti-rtos-release.cfg b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/ti-rtos-release.cfg index bd0d5a7f2b..0720c9171c 100644 --- a/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/ti-rtos-release.cfg +++ b/targets/TI-SimpleLink/TI_CC3220SF_LAUNCHXL/ti-rtos-release.cfg @@ -1,6 +1,6 @@ /* // -// Copyright (c) 2020 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Copyright (c) 2016-2018, Texas Instruments Incorporated // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/common/CC13x2_26x2Flash_BlockStorageInterface.c b/targets/TI-SimpleLink/common/CC13x2_26x2Flash_BlockStorageInterface.c index 7d74869c59..e8c9c1fdfe 100644 --- a/targets/TI-SimpleLink/common/CC13x2_26x2Flash_BlockStorageInterface.c +++ b/targets/TI-SimpleLink/common/CC13x2_26x2Flash_BlockStorageInterface.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/common/CC32xxFlash_BlockStorageInterface.c b/targets/TI-SimpleLink/common/CC32xxFlash_BlockStorageInterface.c index 0af51e547b..314f8015b6 100644 --- a/targets/TI-SimpleLink/common/CC32xxFlash_BlockStorageInterface.c +++ b/targets/TI-SimpleLink/common/CC32xxFlash_BlockStorageInterface.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/common/CMakeLists.txt b/targets/TI-SimpleLink/common/CMakeLists.txt index e2834343b7..919b298c71 100644 --- a/targets/TI-SimpleLink/common/CMakeLists.txt +++ b/targets/TI-SimpleLink/common/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/targets/TI-SimpleLink/common/GenericPort.cpp b/targets/TI-SimpleLink/common/GenericPort.cpp index 5629083bd0..a937d7e221 100644 --- a/targets/TI-SimpleLink/common/GenericPort.cpp +++ b/targets/TI-SimpleLink/common/GenericPort.cpp @@ -1,14 +1,18 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // #include #include -#include +#include #include +#include -extern UART_Handle uart; +// UART operations timeout +#define UART_TIMEOUT_MILLISECONDS 500000 + +extern UART2_Handle uart; extern SemaphoreP_Handle uartMutex; // developer note: @@ -19,15 +23,15 @@ extern "C" uint32_t DebuggerPort_WriteProxy(const char *format, ...) va_list arg; uint32_t chars = 0; - if( CLR_EE_DBG_IS_NOT( Enabled ) ) + if (CLR_EE_DBG_IS_NOT(Enabled)) { - if(SemaphoreP_pend(uartMutex, UART_WAIT_FOREVER) == SemaphoreP_OK) + if (SemaphoreP_pend(uartMutex, UART2_WAIT_FOREVER) == SemaphoreP_OK) { - va_start( arg, format ); + va_start(arg, format); - chars = CLR_Debug::PrintfV( format, arg ); + chars = CLR_Debug::PrintfV(format, arg); - va_end( arg ); + va_end(arg); SemaphoreP_post(uartMutex); } @@ -36,17 +40,18 @@ extern "C" uint32_t DebuggerPort_WriteProxy(const char *format, ...) return chars; } -uint32_t GenericPort_Write( int portNum, const char* data, size_t size ) +uint32_t GenericPort_Write(int portNum, const char *data, size_t size) { (void)portNum; + size_t bytesWritten; - if( CLR_EE_DBG_IS_NOT( Enabled ) ) + if (CLR_EE_DBG_IS_NOT(Enabled)) { // debugger port is NOT in use, OK to output to UART // send characters directly to the UART port - UART_write(uart, data, size); + UART2_writeTimeout(uart, data, size, &bytesWritten, UART_TIMEOUT_MILLISECONDS / Clock_tickPeriod); - return size; + return bytesWritten; } return (uint32_t)size; diff --git a/targets/TI-SimpleLink/common/Target_BlockStorage_CC13x2_26x2FlashDriver.c b/targets/TI-SimpleLink/common/Target_BlockStorage_CC13x2_26x2FlashDriver.c index 04ef06adf0..5b6495734a 100644 --- a/targets/TI-SimpleLink/common/Target_BlockStorage_CC13x2_26x2FlashDriver.c +++ b/targets/TI-SimpleLink/common/Target_BlockStorage_CC13x2_26x2FlashDriver.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/common/Target_BlockStorage_CC32xxFlashDriver.c b/targets/TI-SimpleLink/common/Target_BlockStorage_CC32xxFlashDriver.c index 41f07d897f..5d47a36be9 100644 --- a/targets/TI-SimpleLink/common/Target_BlockStorage_CC32xxFlashDriver.c +++ b/targets/TI-SimpleLink/common/Target_BlockStorage_CC32xxFlashDriver.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/common/WireProtocol_HAL_Interface.c b/targets/TI-SimpleLink/common/WireProtocol_HAL_Interface.c index 5e54cabd55..47eafd749a 100644 --- a/targets/TI-SimpleLink/common/WireProtocol_HAL_Interface.c +++ b/targets/TI-SimpleLink/common/WireProtocol_HAL_Interface.c @@ -1,17 +1,21 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // // #include -#include +#include +#include #include #include #include #include #include -UART_Handle uart = NULL; +// UART operations timeout +#define UART_TIMEOUT_MILLISECONDS 500000 + +UART2_Handle uart = NULL; WP_Message inboundMessage; @@ -19,33 +23,34 @@ WP_Message inboundMessage; //////////////////////////////////////////////////////////////////////////////////////////////// // The functions below are the ones that need to be ported to new channels/HALs when required // These are to be considered as a reference implementations when working on new ports -// +// // This reference implementation provides communication through: -// - serial port (UART/USART) +// - serial port (UART/USART) // //////////////////////////////////////////////////////////////////////////////////////////////// -int WP_ReceiveBytes(uint8_t* ptr, uint16_t* size) +int WP_ReceiveBytes(uint8_t *ptr, uint16_t *size) { // save for latter comparison uint16_t requestedSize = *size; + size_t read; - //int readData = 0; + // int readData = 0; // sanity check for request of 0 size - if(*size) + if (*size) { ////////////////////////////////////////////////////////// // PORTING CHANGE REQUIRED HERE // ////////////////////////////////////////////////////////// // change here to read (size) bytes from the input stream - // preferably with read timeout and being able to check + // preferably with read timeout and being able to check // if the requested number of bytes was actually read ////////////////////////////////////////////////////////// - + // non blocking read from serial port with 500ms timeout - size_t read = UART_read(uart, ptr, requestedSize); + UART2_readTimeout(uart, ptr, requestedSize, &read, UART_TIMEOUT_MILLISECONDS / Clock_tickPeriod); - ptr += read; + ptr += read; *size -= read; // check if the requested read matches the actual read count @@ -55,7 +60,7 @@ int WP_ReceiveBytes(uint8_t* ptr, uint16_t* size) return true; } -int WP_TransmitMessage(WP_Message* message) +int WP_TransmitMessage(WP_Message *message) { uint32_t writeResult; bool operationResult = false; @@ -64,21 +69,31 @@ int WP_TransmitMessage(WP_Message* message) // PORTING CHANGE REQUIRED HERE // /////////////////////////////////////////////////////////// // change here to write (size) bytes to the output stream - // preferably with timeout and being able to check + // preferably with timeout and being able to check // if the write was successfull or at least buffered ////////////////////////////////////////////////////////// - TRACE( TRACE_HEADERS, "TXMSG: 0x%08X, 0x%08X, 0x%08X\n", message->m_header.m_cmd, message->m_header.m_flags, message->m_header.m_size ); + TRACE( + TRACE_HEADERS, + "TXMSG: 0x%08X, 0x%08X, 0x%08X\n", + message->m_header.m_cmd, + message->m_header.m_flags, + message->m_header.m_size); // write header to uart - writeResult = UART_write(uart, (const void *)&message->m_header, sizeof(message->m_header)); - - if(writeResult == sizeof(message->m_header)) + UART2_writeTimeout( + uart, + (const void *)&message->m_header, + sizeof(message->m_header), + &writeResult, + UART_TIMEOUT_MILLISECONDS / Clock_tickPeriod); + + if (writeResult == sizeof(message->m_header)) { operationResult = true; // if there is anything on the payload send it to the output stream - if(message->m_header.m_size && message->m_payload) + if (message->m_header.m_size && message->m_payload) { /////////////////////////////////////////////////////////// // PORTING CHANGE REQUIRED HERE // @@ -89,13 +104,18 @@ int WP_TransmitMessage(WP_Message* message) // reset flag operationResult = false; - writeResult = UART_write(uart, (const void *)message->m_payload, message->m_header.m_size); + UART2_writeTimeout( + uart, + (const void *)message->m_payload, + message->m_header.m_size, + &writeResult, + UART_TIMEOUT_MILLISECONDS / Clock_tickPeriod); - if(writeResult == message->m_header.m_size) + if (writeResult == message->m_header.m_size) { operationResult = true; - TRACE0( TRACE_ERRORS, "TXMSG: OK\n"); + TRACE0(TRACE_ERRORS, "TXMSG: OK\n"); } } } diff --git a/targets/TI-SimpleLink/common/WireProtocol_ReceiverThread.c b/targets/TI-SimpleLink/common/WireProtocol_ReceiverThread.c index 1b85bf9775..f097bf7fb3 100644 --- a/targets/TI-SimpleLink/common/WireProtocol_ReceiverThread.c +++ b/targets/TI-SimpleLink/common/WireProtocol_ReceiverThread.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/common/easylink/EasyLink.c b/targets/TI-SimpleLink/common/easylink/EasyLink.c index 2f1d625813..f076115b88 100644 --- a/targets/TI-SimpleLink/common/easylink/EasyLink.c +++ b/targets/TI-SimpleLink/common/easylink/EasyLink.c @@ -30,9 +30,12 @@ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +// need this here as we are importing it from the SDK +// clang-format off + /***** Includes *****/ #include "EasyLink.h" -#include "easylink_config.h" +#include "ti_easylink_config.h" #include #include #include @@ -44,15 +47,9 @@ #include #endif //USE_DMM -#include "Board.h" - /* TI Drivers */ -#ifdef Board_SYSCONFIG_PREVIEW -#include -#else -#include -#include -#endif +#include +#include /* BIOS Header files */ #include @@ -74,8 +71,8 @@ #include DeviceFamily_constructPath(inc/hw_ccfg_simple_struct.h) union setupCmd_t{ -#if (defined Board_CC1352P1_LAUNCHXL) || (defined Board_CC1352P_2_LAUNCHXL) || \ - (defined Board_CC1352P_4_LAUNCHXL) +#if ((defined LAUNCHXL_CC1352P1) || (defined LAUNCHXL_CC1352P_2) || \ + (defined LAUNCHXL_CC1352P_4)) rfc_CMD_PROP_RADIO_DIV_SETUP_PA_t divSetup; #else rfc_CMD_PROP_RADIO_DIV_SETUP_t divSetup; @@ -83,6 +80,8 @@ union setupCmd_t{ rfc_CMD_PROP_RADIO_SETUP_t setup; }; +// Enable Activity profiling +// #define EASYLINK_ACTIVITY_PROFILING //Primary IEEE address location #define EASYLINK_PRIMARY_IEEE_ADDR_LOCATION (FCFG1_BASE + FCFG1_O_MAC_15_4_0) //Secondary IEEE address location @@ -209,6 +208,9 @@ static bool rfModeMultiClient = EASYLINK_ENABLE_MULTI_CLIENT; //Async Rx timeout value static uint32_t asyncRxTimeOut = EASYLINK_ASYNC_RX_TIMEOUT; +// Current Command Priority +static uint32_t cmdPriority = EasyLink_Priority_Normal; + //local commands, contents will be defined by modulation type static union setupCmd_t EasyLink_cmdPropRadioSetup; static rfc_CMD_FS_t EasyLink_cmdFs; @@ -239,6 +241,10 @@ static Semaphore_Handle busyMutex; //Handle for last Async command, which is needed by EasyLink_abort static RF_CmdHandle asyncCmdHndl = EASYLINK_RF_CMD_HANDLE_INVALID; +// Command schedule parameters, needed by the DMM to schedule commands in a +// multi-client setup +static RF_ScheduleCmdParams schParams_prop; + /* Set Default parameters structure */ static const EasyLink_Params EasyLink_defaultParams = EASYLINK_PARAM_CONFIG; @@ -255,6 +261,12 @@ void EasyLink_Params_init(EasyLink_Params *params) *params = EasyLink_defaultParams; } +// Generate the activity table value +static uint32_t genActivityTableValue(EasyLink_Activity activity, EasyLink_Priority priority) +{ + return((activity << 16) | priority); +} + //Create an Advanced Tx command from a Tx Command void createTxAdvFromTx(rfc_CMD_PROP_TX_ADV_t *dst, rfc_CMD_PROP_TX_t *src) { @@ -285,6 +297,10 @@ static void txDoneCallback(RF_Handle h, RF_CmdHandle ch, RF_EventMask e) { status = EasyLink_Status_Aborted; } + else if(e == (RF_EventCmdCancelled | RF_EventCmdPreempted)) + { + status = EasyLink_Status_Cmd_Rejected; + } else { status = EasyLink_Status_Tx_Error; @@ -368,13 +384,20 @@ static uint32_t calculateCmdTime(EasyLink_TxPacket *txPacket) //Callback for Clear Channel Assessment Done static void ccaDoneCallback(RF_Handle h, RF_CmdHandle ch, RF_EventMask e) { - RF_ScheduleCmdParams schParams_prop; EasyLink_Status status = EasyLink_Status_Tx_Error; RF_Op* pCmd = RF_getCmdOp(h, ch); bool bCcaRunAgain = false; static uint8_t be = EASYLINK_MIN_CCA_BACKOFF_WINDOW; static uint32_t backOffTime; + schParams_prop.startTime = 0U; + schParams_prop.startType = RF_StartNotSpecified; + schParams_prop.allowDelay = RF_AllowDelayNone; + schParams_prop.endTime = 0U; + schParams_prop.endType = RF_EndNotSpecified; + schParams_prop.duration = 0U; + schParams_prop.activityInfo = genActivityTableValue(EasyLink_Activity_Tx, (EasyLink_Priority)cmdPriority); + asyncCmdHndl = EASYLINK_RF_CMD_HANDLE_INVALID; if (e & RF_EventLastCmdDone) @@ -425,7 +448,8 @@ static void ccaDoneCallback(RF_Handle h, RF_CmdHandle ch, RF_EventMask e) // for a clear channel (CCA) before sending a packet if(rfModeMultiClient) { - schParams_prop.priority = RF_PriorityHigh; + schParams_prop.startTime = pCmd->startTime; + schParams_prop.startType = RF_StartAbs; asyncCmdHndl = RF_scheduleCmd(rfHandle, (RF_Op*)&EasyLink_cmdPropCs, &schParams_prop, ccaDoneCallback, EASYLINK_RF_EVENT_MASK); } @@ -449,13 +473,20 @@ static void ccaDoneCallback(RF_Handle h, RF_CmdHandle ch, RF_EventMask e) } - else if ( (e & RF_EventCmdAborted) || (e & RF_EventCmdCancelled ) || (e & RF_EventCmdPreempted ) ) + else if ((e & RF_EventCmdAborted) || (e & RF_EventCmdCancelled) || (e & RF_EventCmdPreempted)) { //Release now so user callback can call EasyLink API's Semaphore_post(busyMutex); // Reset the number of retries be = EASYLINK_MIN_CCA_BACKOFF_WINDOW; - status = EasyLink_Status_Aborted; + if(e == (RF_EventCmdCancelled | RF_EventCmdPreempted)) + { + status = EasyLink_Status_Cmd_Rejected; + } + else + { + status = EasyLink_Status_Aborted; + } } else { @@ -547,7 +578,14 @@ static void rxDoneCallback(RF_Handle h, RF_CmdHandle ch, RF_EventMask e) //Release now so user callback can call EasyLink API's Semaphore_post(busyMutex); asyncCmdHndl = EASYLINK_RF_CMD_HANDLE_INVALID; - status = EasyLink_Status_Aborted; + if(e == (RF_EventCmdCancelled | RF_EventCmdPreempted)) + { + status = EasyLink_Status_Cmd_Rejected; + } + else + { + status = EasyLink_Status_Aborted; + } } if (rxCb != NULL) @@ -571,6 +609,14 @@ static EasyLink_Status enableTestMode(EasyLink_CtrlOption mode) static rfc_CMD_TX_TEST_t txTestCmd = {0}; static rfc_CMD_RX_TEST_t rxTestCmd = {0}; + schParams_prop.startTime = 0U; + schParams_prop.startType = RF_StartNotSpecified; + schParams_prop.allowDelay = RF_AllowDelayNone; + schParams_prop.endTime = 0U; + schParams_prop.endType = RF_EndNotSpecified; + schParams_prop.duration = 0U; + schParams_prop.activityInfo = genActivityTableValue(EasyLink_Activity_Rx, (EasyLink_Priority)cmdPriority); + if((!configured) || suspended) { return EasyLink_Status_Config_Error; @@ -625,9 +671,17 @@ static EasyLink_Status enableTestMode(EasyLink_CtrlOption mode) txTestCmd.endTrigger.triggerType = TRIG_NEVER; /* Post command and store Cmd Handle for future abort */ - asyncCmdHndl = RF_postCmd(rfHandle, (RF_Op*)&txTestCmd, - RF_PriorityNormal, asyncCmdCallback, - EASYLINK_RF_EVENT_MASK); + if(rfModeMultiClient) + { + asyncCmdHndl = RF_scheduleCmd(rfHandle, (RF_Op*)&txTestCmd, + &schParams_prop, asyncCmdCallback, EASYLINK_RF_EVENT_MASK); + } + else + { + asyncCmdHndl = RF_postCmd(rfHandle, (RF_Op*)&txTestCmd, + RF_PriorityNormal, asyncCmdCallback, + EASYLINK_RF_EVENT_MASK); + } /* Has command completed? */ uint16_t count = 0; @@ -667,9 +721,18 @@ static EasyLink_Status enableTestMode(EasyLink_CtrlOption mode) rxTestCmd.endTrigger.triggerType = TRIG_NEVER; /* Post command and store Cmd Handle for future abort */ - asyncCmdHndl = RF_postCmd(rfHandle, (RF_Op*)&rxTestCmd, - RF_PriorityNormal, asyncCmdCallback, - EASYLINK_RF_EVENT_MASK); + if(rfModeMultiClient) + { + asyncCmdHndl = RF_scheduleCmd(rfHandle, (RF_Op*)&rxTestCmd, + &schParams_prop, txDoneCallback, EASYLINK_RF_EVENT_MASK); + } + else + { + asyncCmdHndl = RF_postCmd(rfHandle, (RF_Op*)&rxTestCmd, + RF_PriorityNormal, asyncCmdCallback, + EASYLINK_RF_EVENT_MASK); + } + if(EasyLink_CmdHandle_isValid(asyncCmdHndl)) { status = EasyLink_Status_Success; @@ -683,6 +746,19 @@ static EasyLink_Status enableTestMode(EasyLink_CtrlOption mode) return status; } +#if defined(EASYLINK_ACTIVITY_PROFILING) +uint32_t numCmdFlush = 0U; +static void activityPreemptCb(xdc_UArg arg) +{ + if(arg) + { + /* Flush all commands from the queue */ + (void)RF_flushCmd((RF_Handle)arg, RF_CMDHANDLE_FLUSH_ALL, RF_ABORT_PREEMPTION); + numCmdFlush++; + } +} +#endif // EASYLINK_ACTIVITY_PROFILING + EasyLink_Status EasyLink_init(EasyLink_Params *params) { if (params == NULL) @@ -715,7 +791,10 @@ EasyLink_Status EasyLink_init(EasyLink_Params *params) rfParams.nClientEventMask = EasyLink_params.nClientEventMask; } + rfParams.nID = RF_STACK_ID_EASYLINK; rfParamsConfigured = 1; + // Initialize the schedule parameters + RF_ScheduleCmdParams_init(&schParams_prop); } // Assign the random number generator function pointer to the global @@ -786,6 +865,11 @@ EasyLink_Status EasyLink_init(EasyLink_Params *params) useDivRadioSetup= false; rfConfigOk = true; } + else if((ChipInfo_ChipFamilyIs_CC13x2_CC26x2()) && (ChipInfo_GetChipType() != CHIP_TYPE_CC1312)) + { + useDivRadioSetup= true; + rfConfigOk = true; + } break; case EasyLink_Phy_2_4_200kbps2gfsk: @@ -802,6 +886,11 @@ EasyLink_Status EasyLink_init(EasyLink_Params *params) useDivRadioSetup= false; rfConfigOk = true; } + else if((ChipInfo_ChipFamilyIs_CC13x2_CC26x2()) && (ChipInfo_GetChipType() != CHIP_TYPE_CC1312)) + { + useDivRadioSetup= true; + rfConfigOk = true; + } break; case EasyLink_Phy_5kbpsSlLr: @@ -809,7 +898,7 @@ EasyLink_Status EasyLink_init(EasyLink_Params *params) { useDivRadioSetup= true; rfConfigOk = true; -#if (defined Board_CC1352P_4_LAUNCHXL) +#if (defined LAUNCHXL_CC1352P_4) // CC1352P-4 SLR operates at 433.92 MHz EasyLink_cmdFs.frequency = 0x01B1; EasyLink_cmdFs.fractFreq = 0xEB9A; @@ -821,7 +910,7 @@ EasyLink_Status EasyLink_init(EasyLink_Params *params) if((ChipInfo_GetChipType() == CHIP_TYPE_CC1312) || (ChipInfo_GetChipType() == CHIP_TYPE_CC1352) || (ChipInfo_GetChipType() == CHIP_TYPE_CC1352P)) { -#if !defined(Board_CC1352P_4_LAUNCHXL) +#if !defined(LAUNCHXL_CC1352P_4) // This mode is not supported in the 433 MHz band useDivRadioSetup= true; rfConfigOk = true; @@ -829,7 +918,6 @@ EasyLink_Status EasyLink_init(EasyLink_Params *params) } break; - default: // Invalid PHY setting rfConfigOk = false; break; @@ -882,8 +970,8 @@ EasyLink_Status EasyLink_init(EasyLink_Params *params) // Copy the PHY settings to the EasyLink PHY variable if(useDivRadioSetup) { -#if (defined Board_CC1352P1_LAUNCHXL) || (defined Board_CC1352P_2_LAUNCHXL) || \ - (defined Board_CC1352P_4_LAUNCHXL) +#if ((defined LAUNCHXL_CC1352P1) || (defined LAUNCHXL_CC1352P_2) || \ + (defined LAUNCHXL_CC1352P_4)) memcpy(&EasyLink_cmdPropRadioSetup.divSetup, (rfSetting->RF_uCmdPropRadio.RF_pCmdPropRadioDivSetup), sizeof(rfc_CMD_PROP_RADIO_DIV_SETUP_PA_t)); #else memcpy(&EasyLink_cmdPropRadioSetup.divSetup, (rfSetting->RF_uCmdPropRadio.RF_pCmdPropRadioDivSetup), sizeof(rfc_CMD_PROP_RADIO_DIV_SETUP_t)); @@ -975,9 +1063,27 @@ EasyLink_Status EasyLink_init(EasyLink_Params *params) EasyLink_cmdPropRxAdv.pQueue = &dataQueue; EasyLink_cmdPropRxAdv.pOutput = (uint8_t*)&rxStatistics; - //Set the frequency - RF_runCmd(rfHandle, (RF_Op*)&EasyLink_cmdFs, RF_PriorityNormal, 0, //asyncCmdCallback, - EASYLINK_RF_EVENT_MASK); + if (rfModeMultiClient) + { + /* Set params */ + schParams_prop.startTime = 0U; + schParams_prop.startType = RF_StartNotSpecified; + schParams_prop.allowDelay = RF_AllowDelayNone; + schParams_prop.endTime = 0U; + schParams_prop.endType = RF_EndNotSpecified; + schParams_prop.duration = 0U; + schParams_prop.activityInfo = genActivityTableValue(EasyLink_Activity_Tx, (EasyLink_Priority)cmdPriority); + + //Set the frequency + (void)RF_runScheduleCmd(rfHandle, (RF_Op*)&EasyLink_cmdFs, &schParams_prop, 0, //asyncCmdCallback, + EASYLINK_RF_EVENT_MASK); + } + else + { + //Set the frequency + (void)RF_runCmd(rfHandle, (RF_Op*)&EasyLink_cmdFs, RF_PriorityNormal, 0, //asyncCmdCallback, + EASYLINK_RF_EVENT_MASK); + } //Create a semaphore for blocking commands Semaphore_Params semParams; @@ -1006,8 +1112,24 @@ EasyLink_Status EasyLink_init(EasyLink_Params *params) configured = 1; - return EasyLink_Status_Success; +#if defined(EASYLINK_ACTIVITY_PROFILING) +/* 10 ms interrupt period based on 10us clock tick */ +#define EASYLINK_ACTIVITY_PROFILING_PREEMPT_TIMEOUT (1000) + + static Clock_Handle EasyLink_activityClock = NULL; + /* Create a clock instance to periodically flush all RF commands */ + Clock_Params clkparams; + Clock_Params_init(&clkparams); + clkparams.startFlag = FALSE; + clkparams.period = EASYLINK_ACTIVITY_PROFILING_PREEMPT_TIMEOUT; + clkparams.arg = (xdc_UArg)rfHandle; + EasyLink_activityClock = Clock_create((Clock_FuncPtr)activityPreemptCb, + EASYLINK_ACTIVITY_PROFILING_PREEMPT_TIMEOUT, &clkparams, NULL); + Clock_start(EasyLink_activityClock); +#endif // EASYLINK_ACTIVITY_PROFILING + + return EasyLink_Status_Success; } EasyLink_Status EasyLink_setFrequency(uint32_t ui32Frequency) @@ -1033,6 +1155,15 @@ EasyLink_Status EasyLink_setFrequency(uint32_t ui32Frequency) EasyLink_cmdFs.frequency = centerFreq; EasyLink_cmdFs.fractFreq = fractFreq; + /* Set params */ + schParams_prop.startTime = 0U; + schParams_prop.startType = RF_StartNotSpecified; + schParams_prop.allowDelay = RF_AllowDelayNone; + schParams_prop.endTime = 0U; + schParams_prop.endType = RF_EndNotSpecified; + schParams_prop.duration = 0U; + schParams_prop.activityInfo = genActivityTableValue(EasyLink_Activity_Tx, (EasyLink_Priority)cmdPriority); + #if (!defined(DeviceFamily_CC26X0R2) && !defined(DeviceFamily_CC26X0)) /* If the command type is CMD_PROP_RADIO_DIV_SETUP then set the center frequency * to the same band as the FS command @@ -1041,15 +1172,35 @@ EasyLink_Status EasyLink_setFrequency(uint32_t ui32Frequency) (EasyLink_cmdPropRadioSetup.divSetup.centerFreq != centerFreq)) { EasyLink_cmdPropRadioSetup.divSetup.centerFreq = centerFreq; - /* Run the Setup Command */ - (void)RF_runCmd(rfHandle, (RF_Op*)&EasyLink_cmdPropRadioSetup, - RF_PriorityNormal, 0, EASYLINK_RF_EVENT_MASK); + + if (rfModeMultiClient) + { + /* Run the Setup Command */ + (void)RF_runScheduleCmd(rfHandle, (RF_Op*)&EasyLink_cmdPropRadioSetup, + &schParams_prop, 0, EASYLINK_RF_EVENT_MASK); + } + else + { + /* Run the Setup Command */ + (void)RF_runCmd(rfHandle, (RF_Op*)&EasyLink_cmdPropRadioSetup, + RF_PriorityNormal, 0, EASYLINK_RF_EVENT_MASK); + } } #endif - /* Run command */ - RF_EventMask result = RF_runCmd(rfHandle, (RF_Op*)&EasyLink_cmdFs, - RF_PriorityNormal, 0, EASYLINK_RF_EVENT_MASK); + RF_EventMask result; + if (rfModeMultiClient) + { + /* Run command */ + result = RF_runScheduleCmd(rfHandle, (RF_Op*)&EasyLink_cmdFs, + &schParams_prop, 0, EASYLINK_RF_EVENT_MASK); + } + else + { + /* Run command */ + result = RF_runCmd(rfHandle, (RF_Op*)&EasyLink_cmdFs, + RF_PriorityNormal, 0, EASYLINK_RF_EVENT_MASK); + } if((result & RF_EventLastCmdDone) && (EasyLink_cmdFs.status == DONE_OK)) { @@ -1090,11 +1241,11 @@ EasyLink_Status EasyLink_setRfPower(int8_t i8TxPowerDbm) return EasyLink_Status_Busy_Error; } -#if (defined Board_CC1310_LAUNCHXL) || (defined Board_CC1350_LAUNCHXL) || \ - (defined Board_CC1350STK) || (defined Board_CC1350_LAUNCHXL_433) || \ - (defined Board_CC1312R1_LAUNCHXL) || (defined Board_CC1352R1_LAUNCHXL) || \ - (defined Board_CC1352P1_LAUNCHXL) || (defined Board_CC1352P_2_LAUNCHXL) || \ - (defined Board_CC1352P_4_LAUNCHXL) || (defined Board_CC2640R2_LAUNCHXL) +#if (defined CONFIG_CC1352R1F3RGZ) || (defined CONFIG_CC1312R1F3RGZ) || \ + (defined CONFIG_CC2652R1FRGZ) || (defined CONFIG_CC1312R1_LAUNCHXL) || \ + (defined CONFIG_CC1352R1_LAUNCHXL) || (defined CONFIG_CC26X2R1_LAUNCHXL) || \ + (defined LAUNCHXL_CC1352P1) || (defined LAUNCHXL_CC1352P_2) || \ + (defined LAUNCHXL_CC1352P_4) RF_TxPowerTable_Entry *rfPowerTable = NULL; RF_TxPowerTable_Value newValue; @@ -1121,14 +1272,12 @@ EasyLink_Status EasyLink_setRfPower(int8_t i8TxPowerDbm) if((newValue.paType == RF_TxPowerTable_DefaultPA) && (i8TxPowerDbm == rfPowerTable[rfPowerTableSize-2].power)) { -#if !(defined Board_CC2640R2_LAUNCHXL) //Release the busyMutex Semaphore_post(busyMutex); // The desired power level is set to the maximum supported under the // default PA settings, but the boost mode (CCFG_FORCE_VDDR_HH) is not // turned on return EasyLink_Status_Config_Error; -#endif } #else // dummy read to avoid build warnings @@ -1217,11 +1366,11 @@ EasyLink_Status EasyLink_getRfPower(int8_t *pi8TxPowerDbm) return EasyLink_Status_Config_Error; } -#if (defined Board_CC1310_LAUNCHXL) || (defined Board_CC1350_LAUNCHXL) || \ - (defined Board_CC1350STK) || (defined Board_CC1350_LAUNCHXL_433) || \ - (defined Board_CC1312R1_LAUNCHXL) || (defined Board_CC1352R1_LAUNCHXL) || \ - (defined Board_CC1352P1_LAUNCHXL) || (defined Board_CC1352P_2_LAUNCHXL) || \ - (defined Board_CC1352P_4_LAUNCHXL) || (defined Board_CC2640R2_LAUNCHXL) +#if (defined CONFIG_CC1352R1F3RGZ) || (defined CONFIG_CC1312R1F3RGZ) || \ + (defined CONFIG_CC2652R1FRGZ) || (defined CONFIG_CC1312R1_LAUNCHXL) || \ + (defined CONFIG_CC1352R1_LAUNCHXL) || (defined CONFIG_CC26X2R1_LAUNCHXL) || \ + (defined LAUNCHXL_CC1352P1) || (defined LAUNCHXL_CC1352P_2) || \ + (defined LAUNCHXL_CC1352P_4) uint8_t rfPowerTableSize = 0; RF_TxPowerTable_Entry *rfPowerTable = NULL; @@ -1244,9 +1393,7 @@ EasyLink_Status EasyLink_getRfPower(int8_t *pi8TxPowerDbm) if((currValue.paType == RF_TxPowerTable_DefaultPA) && (txPowerDbm == rfPowerTable[rfPowerTableSize-2].power)) { -#if !(defined Board_CC2640R2_LAUNCHXL) txPowerDbm = rfPowerTable[rfPowerTableSize-3].power; -#endif } #else // dummy read to avoid build warnings @@ -1305,10 +1452,17 @@ EasyLink_Status EasyLink_getAbsTime(uint32_t *pui32AbsTime) EasyLink_Status EasyLink_transmit(EasyLink_TxPacket *txPacket) { EasyLink_Status status = EasyLink_Status_Tx_Error; - RF_ScheduleCmdParams schParams_prop; RF_CmdHandle cmdHdl; uint32_t cmdTime; + schParams_prop.startTime = 0U; + schParams_prop.startType = RF_StartNotSpecified; + schParams_prop.allowDelay = RF_AllowDelayNone; + schParams_prop.endTime = 0U; + schParams_prop.endType = RF_EndNotSpecified; + schParams_prop.duration = 0U; + schParams_prop.activityInfo = genActivityTableValue(EasyLink_Activity_Tx, (EasyLink_Priority)cmdPriority); + if ( (!configured) || suspended) { return EasyLink_Status_Config_Error; @@ -1323,7 +1477,6 @@ EasyLink_Status EasyLink_transmit(EasyLink_TxPacket *txPacket) return EasyLink_Status_Busy_Error; } - if(useIeeeHeader) { uint16_t ieeeHdr = EASYLINK_IEEE_HDR_CREATE(EASYLINK_IEEE_HDR_CRC_2BYTE, EASYLINK_IEEE_HDR_WHTNG_EN, (txPacket->len + addrSize + sizeof(ieeeHdr))); @@ -1361,20 +1514,27 @@ EasyLink_Status EasyLink_transmit(EasyLink_TxPacket *txPacket) EasyLink_cmdPropTxAdv.startTrigger.triggerType = TRIG_ABSTIME; EasyLink_cmdPropTxAdv.startTrigger.pastTrig = 1; EasyLink_cmdPropTxAdv.startTime = txPacket->absTime; - schParams_prop.endTime = EasyLink_cmdPropTxAdv.startTime + EasyLink_ms_To_RadioTime(cmdTime); + schParams_prop.startTime = txPacket->absTime; + schParams_prop.startType = RF_StartAbs; + schParams_prop.duration = EasyLink_ms_To_RadioTime(cmdTime); + schParams_prop.endTime = EasyLink_cmdPropTxAdv.startTime + EasyLink_ms_To_RadioTime(cmdTime); + schParams_prop.endType = RF_EndAbs; } else { EasyLink_cmdPropTxAdv.startTrigger.triggerType = TRIG_NOW; EasyLink_cmdPropTxAdv.startTrigger.pastTrig = 1; - EasyLink_cmdPropTxAdv.startTime = 0; - schParams_prop.endTime = RF_getCurrentTime() + EasyLink_ms_To_RadioTime(cmdTime); + EasyLink_cmdPropTxAdv.startTime = 0U; + schParams_prop.startTime = 0U; + schParams_prop.startType = RF_StartNotSpecified; + schParams_prop.duration = EasyLink_ms_To_RadioTime(cmdTime); + schParams_prop.endTime = RF_getCurrentTime() + EasyLink_ms_To_RadioTime(cmdTime); + schParams_prop.endType = RF_EndAbs; } // Send packet if(rfModeMultiClient) { - schParams_prop.priority = RF_PriorityHigh; cmdHdl = RF_scheduleCmd(rfHandle, (RF_Op*)&EasyLink_cmdPropTxAdv, &schParams_prop, 0, EASYLINK_RF_EVENT_MASK); } @@ -1387,7 +1547,11 @@ EasyLink_Status EasyLink_transmit(EasyLink_TxPacket *txPacket) // Wait for Command to complete RF_EventMask result = RF_pendCmd(rfHandle, cmdHdl, EASYLINK_RF_EVENT_MASK); - if (result & RF_EventLastCmdDone) + if (result == (RF_EventCmdCancelled | RF_EventCmdPreempted)) + { + status = EasyLink_Status_Cmd_Rejected; + } + else if (result & RF_EventLastCmdDone) { status = EasyLink_Status_Success; } @@ -1401,9 +1565,16 @@ EasyLink_Status EasyLink_transmit(EasyLink_TxPacket *txPacket) EasyLink_Status EasyLink_transmitAsync(EasyLink_TxPacket *txPacket, EasyLink_TxDoneCb cb) { EasyLink_Status status = EasyLink_Status_Tx_Error; - RF_ScheduleCmdParams schParams_prop; uint32_t cmdTime; + schParams_prop.startTime = 0U; + schParams_prop.startType = RF_StartNotSpecified; + schParams_prop.allowDelay = RF_AllowDelayNone; + schParams_prop.endTime = 0U; + schParams_prop.endType = RF_EndNotSpecified; + schParams_prop.duration = 0U; + schParams_prop.activityInfo = genActivityTableValue(EasyLink_Activity_Tx, (EasyLink_Priority)cmdPriority); + //Check if not configure or already an Async command being performed if ( (!configured) || suspended) { @@ -1463,20 +1634,27 @@ EasyLink_Status EasyLink_transmitAsync(EasyLink_TxPacket *txPacket, EasyLink_TxD EasyLink_cmdPropTxAdv.startTrigger.triggerType = TRIG_ABSTIME; EasyLink_cmdPropTxAdv.startTrigger.pastTrig = 1; EasyLink_cmdPropTxAdv.startTime = txPacket->absTime; - schParams_prop.endTime = EasyLink_cmdPropTxAdv.startTime + EasyLink_ms_To_RadioTime(cmdTime); + schParams_prop.startTime = txPacket->absTime; + schParams_prop.startType = RF_StartAbs; + schParams_prop.duration = EasyLink_ms_To_RadioTime(cmdTime); + schParams_prop.endTime = EasyLink_cmdPropTxAdv.startTime + EasyLink_ms_To_RadioTime(cmdTime); + schParams_prop.endType = RF_EndAbs; } else { EasyLink_cmdPropTxAdv.startTrigger.triggerType = TRIG_NOW; EasyLink_cmdPropTxAdv.startTrigger.pastTrig = 1; EasyLink_cmdPropTxAdv.startTime = 0; - schParams_prop.endTime = RF_getCurrentTime() + EasyLink_ms_To_RadioTime(cmdTime); + schParams_prop.startTime = 0U; + schParams_prop.startType = RF_StartNotSpecified; + schParams_prop.duration = EasyLink_ms_To_RadioTime(cmdTime); + schParams_prop.endTime = RF_getCurrentTime() + EasyLink_ms_To_RadioTime(cmdTime); + schParams_prop.endType = RF_EndAbs; } // Send packet if(rfModeMultiClient) { - schParams_prop.priority = RF_PriorityHigh; asyncCmdHndl = RF_scheduleCmd(rfHandle, (RF_Op*)&EasyLink_cmdPropTxAdv, &schParams_prop, txDoneCallback, EASYLINK_RF_EVENT_MASK); } @@ -1499,9 +1677,16 @@ EasyLink_Status EasyLink_transmitAsync(EasyLink_TxPacket *txPacket, EasyLink_TxD EasyLink_Status EasyLink_transmitCcaAsync(EasyLink_TxPacket *txPacket, EasyLink_TxDoneCb cb) { EasyLink_Status status = EasyLink_Status_Tx_Error; - RF_ScheduleCmdParams schParams_prop; uint32_t cmdTime; + schParams_prop.startTime = 0U; + schParams_prop.startType = RF_StartNotSpecified; + schParams_prop.allowDelay = RF_AllowDelayNone; + schParams_prop.endTime = 0U; + schParams_prop.endType = RF_EndNotSpecified; + schParams_prop.duration = 0U; + schParams_prop.activityInfo = genActivityTableValue(EasyLink_Activity_Tx, (EasyLink_Priority)cmdPriority); + //Check if not configure or already an Async command being performed, or //if a random number generator function is not provided if ( (!configured) || suspended || (!getRN)) @@ -1566,20 +1751,27 @@ EasyLink_Status EasyLink_transmitCcaAsync(EasyLink_TxPacket *txPacket, EasyLink_ EasyLink_cmdPropCs.startTrigger.triggerType = TRIG_ABSTIME; EasyLink_cmdPropCs.startTrigger.pastTrig = 1; EasyLink_cmdPropCs.startTime = txPacket->absTime; - schParams_prop.endTime = EasyLink_cmdPropCs.startTime + EasyLink_ms_To_RadioTime(cmdTime); + schParams_prop.startTime = txPacket->absTime; + schParams_prop.startType = RF_StartAbs; + schParams_prop.duration = EasyLink_ms_To_RadioTime(cmdTime); + schParams_prop.endTime = EasyLink_cmdPropCs.startTime + EasyLink_ms_To_RadioTime(cmdTime); + schParams_prop.endType = RF_EndAbs; } else { EasyLink_cmdPropCs.startTrigger.triggerType = TRIG_NOW; EasyLink_cmdPropCs.startTrigger.pastTrig = 1; EasyLink_cmdPropCs.startTime = 0; - schParams_prop.endTime = RF_getCurrentTime() + EasyLink_ms_To_RadioTime(cmdTime); + schParams_prop.startTime = 0; + schParams_prop.startType = RF_StartNotSpecified; + schParams_prop.duration = EasyLink_ms_To_RadioTime(cmdTime); + schParams_prop.endTime = RF_getCurrentTime() + EasyLink_ms_To_RadioTime(cmdTime); + schParams_prop.endType = RF_EndAbs; } // Check for a clear channel (CCA) before sending a packet if(rfModeMultiClient) { - schParams_prop.priority = RF_PriorityHigh; asyncCmdHndl = RF_scheduleCmd(rfHandle, (RF_Op*)&EasyLink_cmdPropCs, &schParams_prop, ccaDoneCallback, EASYLINK_RF_EVENT_MASK); } @@ -1605,7 +1797,14 @@ EasyLink_Status EasyLink_receive(EasyLink_RxPacket *rxPacket) RF_EventMask result; rfc_dataEntryGeneral_t *pDataEntry; RF_CmdHandle rx_cmd; - RF_ScheduleCmdParams schParams_prop; + + schParams_prop.startTime = 0U; + schParams_prop.startType = RF_StartNotSpecified; + schParams_prop.allowDelay = RF_AllowDelayNone; + schParams_prop.endTime = 0U; + schParams_prop.endType = RF_EndNotSpecified; + schParams_prop.duration = 0U; + schParams_prop.activityInfo = genActivityTableValue(EasyLink_Activity_Rx, (EasyLink_Priority)cmdPriority); if ( (!configured) || suspended) { @@ -1631,12 +1830,16 @@ EasyLink_Status EasyLink_receive(EasyLink_RxPacket *rxPacket) EasyLink_cmdPropRxAdv.startTrigger.triggerType = TRIG_ABSTIME; EasyLink_cmdPropRxAdv.startTrigger.pastTrig = 1; EasyLink_cmdPropRxAdv.startTime = rxPacket->absTime; + schParams_prop.startTime = rxPacket->absTime; + schParams_prop.startType = RF_StartAbs; } else { EasyLink_cmdPropRxAdv.startTrigger.triggerType = TRIG_NOW; EasyLink_cmdPropRxAdv.startTrigger.pastTrig = 1; EasyLink_cmdPropRxAdv.startTime = 0; + schParams_prop.startTime = 0U; + schParams_prop.startType = RF_StartNotSpecified; } if (rxPacket->rxTimeout != 0) @@ -1644,12 +1847,16 @@ EasyLink_Status EasyLink_receive(EasyLink_RxPacket *rxPacket) EasyLink_cmdPropRxAdv.endTrigger.triggerType = TRIG_ABSTIME; EasyLink_cmdPropRxAdv.endTrigger.pastTrig = 1; EasyLink_cmdPropRxAdv.endTime = RF_getCurrentTime() + rxPacket->rxTimeout; + schParams_prop.endTime = EasyLink_cmdPropRxAdv.endTime; + schParams_prop.endType = RF_EndAbs; } else { EasyLink_cmdPropRxAdv.endTrigger.triggerType = TRIG_NEVER; EasyLink_cmdPropRxAdv.endTrigger.pastTrig = 1; EasyLink_cmdPropRxAdv.endTime = 0; + schParams_prop.endTime = 0U; + schParams_prop.endType = RF_EndNotSpecified; } //Clear the Rx statistics structure @@ -1657,10 +1864,6 @@ EasyLink_Status EasyLink_receive(EasyLink_RxPacket *rxPacket) if(rfModeMultiClient) { - /* assume high priority */ - schParams_prop.priority = RF_PriorityHigh; - schParams_prop.endTime = EasyLink_cmdPropRxAdv.endTime; - rx_cmd = RF_scheduleCmd(rfHandle, (RF_Op*)&EasyLink_cmdPropRxAdv, &schParams_prop, 0, EASYLINK_RF_EVENT_MASK); } @@ -1730,6 +1933,10 @@ EasyLink_Status EasyLink_receive(EasyLink_RxPacket *rxPacket) status = EasyLink_Status_Rx_Error; } } + else if (result == (RF_EventCmdCancelled | RF_EventCmdPreempted)) + { + status = EasyLink_Status_Cmd_Rejected; + } //Release the busyMutex Semaphore_post(busyMutex); @@ -1741,7 +1948,14 @@ EasyLink_Status EasyLink_receiveAsync(EasyLink_ReceiveCb cb, uint32_t absTime) { EasyLink_Status status = EasyLink_Status_Rx_Error; rfc_dataEntryGeneral_t *pDataEntry; - RF_ScheduleCmdParams schParams_prop; + + schParams_prop.startTime = 0U; + schParams_prop.startType = RF_StartNotSpecified; + schParams_prop.allowDelay = RF_AllowDelayNone; + schParams_prop.endTime = 0U; + schParams_prop.endType = RF_EndNotSpecified; + schParams_prop.duration = 0U; + schParams_prop.activityInfo = genActivityTableValue(EasyLink_Activity_Rx, (EasyLink_Priority)cmdPriority); //Check if not configure of already an Async command being performed if ( (!configured) || suspended) @@ -1774,12 +1988,16 @@ EasyLink_Status EasyLink_receiveAsync(EasyLink_ReceiveCb cb, uint32_t absTime) EasyLink_cmdPropRxAdv.startTrigger.triggerType = TRIG_ABSTIME; EasyLink_cmdPropRxAdv.startTrigger.pastTrig = 1; EasyLink_cmdPropRxAdv.startTime = absTime; + schParams_prop.startTime = absTime; + schParams_prop.startType = RF_StartAbs; } else { EasyLink_cmdPropRxAdv.startTrigger.triggerType = TRIG_NOW; EasyLink_cmdPropRxAdv.startTrigger.pastTrig = 1; EasyLink_cmdPropRxAdv.startTime = 0; + schParams_prop.startTime = 0U; + schParams_prop.startType = RF_StartNotSpecified; } if (asyncRxTimeOut != 0) @@ -1787,12 +2005,16 @@ EasyLink_Status EasyLink_receiveAsync(EasyLink_ReceiveCb cb, uint32_t absTime) EasyLink_cmdPropRxAdv.endTrigger.triggerType = TRIG_ABSTIME; EasyLink_cmdPropRxAdv.endTrigger.pastTrig = 1; EasyLink_cmdPropRxAdv.endTime = RF_getCurrentTime() + asyncRxTimeOut; + schParams_prop.endTime = EasyLink_cmdPropRxAdv.endTime; + schParams_prop.endType = RF_EndAbs; } else { EasyLink_cmdPropRxAdv.endTrigger.triggerType = TRIG_NEVER; EasyLink_cmdPropRxAdv.endTrigger.pastTrig = 1; EasyLink_cmdPropRxAdv.endTime = 0; + schParams_prop.endTime = 0U; + schParams_prop.endType = RF_EndNotSpecified; } //Clear the Rx statistics structure @@ -1800,10 +2022,6 @@ EasyLink_Status EasyLink_receiveAsync(EasyLink_ReceiveCb cb, uint32_t absTime) if(rfModeMultiClient) { - /* assume high priority */ - schParams_prop.priority = RF_PriorityHigh; - schParams_prop.endTime = EasyLink_cmdPropRxAdv.endTime; - asyncCmdHndl = RF_scheduleCmd(rfHandle, (RF_Op*)&EasyLink_cmdPropRxAdv, &schParams_prop, rxDoneCallback, EASYLINK_RF_EVENT_MASK); } @@ -1953,6 +2171,13 @@ EasyLink_Status EasyLink_setCtrl(EasyLink_CtrlOption Ctrl, uint32_t ui32Value) asyncRxTimeOut = ui32Value; status = EasyLink_Status_Success; break; + case EasyLink_Ctrl_Cmd_Priority: + if(ui32Value < EasyLink_Priority_NEntries) + { + cmdPriority = (EasyLink_Priority)ui32Value; + status = EasyLink_Status_Success; + } + break; case EasyLink_Ctrl_Test_Tone: status = enableTestMode(EasyLink_Ctrl_Test_Tone); break; @@ -1989,6 +2214,10 @@ EasyLink_Status EasyLink_getCtrl(EasyLink_CtrlOption Ctrl, uint32_t* pui32Value) *pui32Value = asyncRxTimeOut; status = EasyLink_Status_Success; break; + case EasyLink_Ctrl_Cmd_Priority: + *pui32Value = cmdPriority; + status = EasyLink_Status_Success; + break; case EasyLink_Ctrl_Test_Tone: case EasyLink_Ctrl_Test_Signal: case EasyLink_Ctrl_Rx_Test_Tone: @@ -2037,3 +2266,6 @@ EasyLink_Status EasyLink_getIeeeAddr(uint8_t *ieeeAddr) return status; } + +// need this here as we are importing it from the SDK +// clang-format on diff --git a/targets/TI-SimpleLink/common/easylink/EasyLink.h b/targets/TI-SimpleLink/common/easylink/EasyLink.h index 1c2fcefda9..1d803144e3 100644 --- a/targets/TI-SimpleLink/common/easylink/EasyLink.h +++ b/targets/TI-SimpleLink/common/easylink/EasyLink.h @@ -82,6 +82,7 @@ code. The EasyLink_Status code are: - EasyLink_Status_Rx_Timeout - EasyLink_Status_Busy_Error - EasyLink_Status_Aborted +- EasyLink_Status_Cmd_Rejected # Power Management # The TI-RTOS power management framework will try to put the device into the most @@ -135,6 +136,8 @@ Packet structure: */ +// need this here as we are importing it from the SDK +// clang-format off //***************************************************************************** #ifndef Easylink__include @@ -155,11 +158,12 @@ extern "C" #include #include #include -#include "easylink_config.h" -#include "Board.h" +#include "ti_easylink_config.h" +#include "ti_drivers_config.h" +#include "ti_radio_config.h" //! \brief EasyLink API Version -#define EASYLINK_API_VERSION "EasyLink-v2.60.00" +#define EASYLINK_API_VERSION "EasyLink-v3.10.01" //! \brief defines the Tx/Rx Max Address Size #define EASYLINK_MAX_ADDR_SIZE 8 @@ -192,7 +196,8 @@ typedef enum EasyLink_Status_Rx_Timeout = 7, //!< Rx Error EasyLink_Status_Rx_Buffer_Error = 8, //!< Rx Buffer Error EasyLink_Status_Busy_Error = 9, //!< Busy Error - EasyLink_Status_Aborted = 10 //!< Command stopped or aborted + EasyLink_Status_Aborted = 10, //!< Command stopped or aborted + EasyLink_Status_Cmd_Rejected = 11, //!< Command Rejected by RF Driver (Scheduling conflict) } EasyLink_Status; @@ -238,12 +243,36 @@ typedef enum EasyLink_Ctrl_AsyncRx_TimeOut = 3, //!< Relative time in ticks from Async //!< Rx start to TimeOut. A value of //!< 0 means no timeout - - EasyLink_Ctrl_Test_Tone = 4, //!< Enable/Disable Test mode for Tone - EasyLink_Ctrl_Test_Signal = 5, //!< Enable/Disable Test mode for Signal - EasyLink_Ctrl_Rx_Test_Tone = 6, //!< Enable/Disable Rx Test mode for Tone + EasyLink_Ctrl_Cmd_Priority = 4, //!< Set the command priority with a value + //!< from EasyLink_Priority + EasyLink_Ctrl_Test_Tone = 5, //!< Enable/Disable Test mode for Tone + EasyLink_Ctrl_Test_Signal = 6, //!< Enable/Disable Test mode for Signal + EasyLink_Ctrl_Rx_Test_Tone = 7, //!< Enable/Disable Rx Test mode for Tone } EasyLink_CtrlOption; +//! \brief Activity table +//! +//! +--------------+--------------------------------------+ +//! | Activity | Priority | +//! +--------------+------------+------------+------------+ +//! | | Normal | High | Urgent | +//! | TX | 0X03090000 | 0X03090001 | 0X03090002 | +//! | RX | 0X03070000 | 0X03070001 | 0X03070002 | +//! +--------------+--------------------------------------+ +//! +typedef enum{ + EasyLink_Activity_Tx = 0x309, //!< Activity code for the Tx operation + EasyLink_Activity_Rx = 0x307, //!< Activity code for the Rx operation +}EasyLink_Activity; + +//! \brief Transmit and Receive Command Priority - These are only applicable in +//! a multi-client use-case +typedef enum{ + EasyLink_Priority_Normal = 0x0, + EasyLink_Priority_High = 0x1, + EasyLink_Priority_Urgent = 0x2, + EasyLink_Priority_NEntries +}EasyLink_Priority; //! \brief EasyLink 32-bit Random number generator function type used in the //! clear channel assessment algorithm. @@ -266,8 +295,8 @@ typedef struct RF_Mode *RF_pProp; //!< Pointer to RF Mode Command union{ -#if (defined Board_CC1352P1_LAUNCHXL) || (defined Board_CC1352P_2_LAUNCHXL) || \ - (defined Board_CC1352P_4_LAUNCHXL) +#if ((defined LAUNCHXL_CC1352P1) || (defined LAUNCHXL_CC1352P_2) || \ + (defined LAUNCHXL_CC1352P_4)) rfc_CMD_PROP_RADIO_DIV_SETUP_PA_t *RF_pCmdPropRadioDivSetup; #else rfc_CMD_PROP_RADIO_DIV_SETUP_t *RF_pCmdPropRadioDivSetup; @@ -294,7 +323,6 @@ typedef struct uint8_t dstAddr[8]; //!< Destination address uint32_t absTime; //!< Absolute time to Tx packet (0 for immediate) //!< Layer will use last SeqNum used + 1 - uint8_t len; //!< Payload Length uint8_t payload[EASYLINK_MAX_DATA_LENGTH]; //!< Payload } EasyLink_TxPacket; @@ -307,7 +335,6 @@ typedef struct uint32_t absTime; //!< Absolute time to turn on Rx when passed //!< (0 for immediate), Or Absolute time that packet was Rx //!< when returned. - uint32_t rxTimeout; //!< Relative time in ticks from Rx start to Rx TimeOut //!< a value of 0 means no timeout uint8_t len; //!< length of RX'ed packet @@ -661,3 +688,6 @@ extern EasyLink_Status EasyLink_getCtrl(EasyLink_CtrlOption Ctrl, //! @} // //***************************************************************************** + +// need this here as we are importing it from the SDK +// clang-format on diff --git a/targets/TI-SimpleLink/common/nanoSupport_CRC32.c b/targets/TI-SimpleLink/common/nanoSupport_CRC32.c index 8f051510c1..0337b82bf2 100644 --- a/targets/TI-SimpleLink/common/nanoSupport_CRC32.c +++ b/targets/TI-SimpleLink/common/nanoSupport_CRC32.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/common/platformHAL.c b/targets/TI-SimpleLink/common/platformHAL.c index 92fc4de228..3281a3d4c4 100644 --- a/targets/TI-SimpleLink/common/platformHAL.c +++ b/targets/TI-SimpleLink/common/platformHAL.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/common/platformHAL_Time.cpp b/targets/TI-SimpleLink/common/platformHAL_Time.cpp index 11adb03976..6adf4ffc69 100644 --- a/targets/TI-SimpleLink/common/platformHAL_Time.cpp +++ b/targets/TI-SimpleLink/common/platformHAL_Time.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/common/platform_heap.c b/targets/TI-SimpleLink/common/platform_heap.c index d2507def1a..4c356201ab 100644 --- a/targets/TI-SimpleLink/common/platform_heap.c +++ b/targets/TI-SimpleLink/common/platform_heap.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/common/simplelink_sockets.cpp b/targets/TI-SimpleLink/common/simplelink_sockets.cpp index 76b74cfa1e..15e80306af 100644 --- a/targets/TI-SimpleLink/common/simplelink_sockets.cpp +++ b/targets/TI-SimpleLink/common/simplelink_sockets.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Texas Instruments Incorporated. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/common/simplelink_sockets.h b/targets/TI-SimpleLink/common/simplelink_sockets.h index d7cf746528..ef72260bbe 100644 --- a/targets/TI-SimpleLink/common/simplelink_sockets.h +++ b/targets/TI-SimpleLink/common/simplelink_sockets.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Texas Instruments Incorporated. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/common/simplelink_sockets_functions.cpp b/targets/TI-SimpleLink/common/simplelink_sockets_functions.cpp index 7da6fce498..f76bd12a7a 100644 --- a/targets/TI-SimpleLink/common/simplelink_sockets_functions.cpp +++ b/targets/TI-SimpleLink/common/simplelink_sockets_functions.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Texas Instruments Incorporated. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/common/sockets_simplelink.cpp b/targets/TI-SimpleLink/common/sockets_simplelink.cpp index 55f2d36243..a0ed3f49d4 100644 --- a/targets/TI-SimpleLink/common/sockets_simplelink.cpp +++ b/targets/TI-SimpleLink/common/sockets_simplelink.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Texas Instruments Incorporated. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/common/ssl_simplelink.cpp b/targets/TI-SimpleLink/common/ssl_simplelink.cpp index 8b2935dfd1..dc366080ac 100644 --- a/targets/TI-SimpleLink/common/ssl_simplelink.cpp +++ b/targets/TI-SimpleLink/common/ssl_simplelink.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Texas Instruments Incorporated. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/common/syscalls.c b/targets/TI-SimpleLink/common/syscalls.c index 64a76ea61a..809a22675a 100644 --- a/targets/TI-SimpleLink/common/syscalls.c +++ b/targets/TI-SimpleLink/common/syscalls.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/common/targetHAL_ConfigurationManager_CC13x2_26x2.cpp b/targets/TI-SimpleLink/common/targetHAL_ConfigurationManager_CC13x2_26x2.cpp index 1361b1b78f..d7d99dde35 100644 --- a/targets/TI-SimpleLink/common/targetHAL_ConfigurationManager_CC13x2_26x2.cpp +++ b/targets/TI-SimpleLink/common/targetHAL_ConfigurationManager_CC13x2_26x2.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/common/targetHAL_ConfigurationManager_CC32xx.cpp b/targets/TI-SimpleLink/common/targetHAL_ConfigurationManager_CC32xx.cpp index 2dd3844d74..a1c91d570b 100644 --- a/targets/TI-SimpleLink/common/targetHAL_ConfigurationManager_CC32xx.cpp +++ b/targets/TI-SimpleLink/common/targetHAL_ConfigurationManager_CC32xx.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/nanoCLR/CLR_Startup_Thread.c b/targets/TI-SimpleLink/nanoCLR/CLR_Startup_Thread.c index d4fa8cbbb6..f25634d307 100644 --- a/targets/TI-SimpleLink/nanoCLR/CLR_Startup_Thread.c +++ b/targets/TI-SimpleLink/nanoCLR/CLR_Startup_Thread.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/nanoCLR/CMakeLists.txt b/targets/TI-SimpleLink/nanoCLR/CMakeLists.txt index fbb86360fa..1cf6060253 100644 --- a/targets/TI-SimpleLink/nanoCLR/CMakeLists.txt +++ b/targets/TI-SimpleLink/nanoCLR/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 The nanoFramework project contributors +# Copyright (c) .NET Foundation and Contributors # See LICENSE file in the project root for full license information. # diff --git a/targets/TI-SimpleLink/nanoCLR/Memory.cpp b/targets/TI-SimpleLink/nanoCLR/Memory.cpp index e488b377c9..c75d785ac1 100644 --- a/targets/TI-SimpleLink/nanoCLR/Memory.cpp +++ b/targets/TI-SimpleLink/nanoCLR/Memory.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/nanoCLR/Windows.Devices.Adc/win_dev_adc_native_Windows_Devices_Adc_AdcChannel.cpp b/targets/TI-SimpleLink/nanoCLR/Windows.Devices.Adc/win_dev_adc_native_Windows_Devices_Adc_AdcChannel.cpp index 85b09785e0..62a1ed9faa 100644 --- a/targets/TI-SimpleLink/nanoCLR/Windows.Devices.Adc/win_dev_adc_native_Windows_Devices_Adc_AdcChannel.cpp +++ b/targets/TI-SimpleLink/nanoCLR/Windows.Devices.Adc/win_dev_adc_native_Windows_Devices_Adc_AdcChannel.cpp @@ -1,14 +1,11 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // #include "win_dev_adc_native_target.h" -// // this has to be an array because ChibiOS ADC API expects that -// static adcsample_t sampleBuffer[1 * 1]; - #ifdef __GNUC__ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-function" @@ -25,13 +22,15 @@ #pragma GCC diagnostic pop #endif +extern const ADC_Config ADC_config[]; -HRESULT Library_win_dev_adc_native_Windows_Devices_Adc_AdcChannel::NativeReadValue___I4( CLR_RT_StackFrame& stack ) +HRESULT Library_win_dev_adc_native_Windows_Devices_Adc_AdcChannel::NativeReadValue___I4(CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); { // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); // Get channel from _channelNumber field int channelNumber = pThis[FIELD___channelNumber].NumericByRef().s4; @@ -41,28 +40,47 @@ HRESULT Library_win_dev_adc_native_Windows_Devices_Adc_AdcChannel::NativeReadVal ADC_Params params; ADC_Params_init(¶ms); - ADC_Handle adcHandler = ADC_open(channelNumber, ¶ms); FAULT_ON_NULL(adcHandler); + ADC_Handle adcHandler = ADC_open(channelNumber, ¶ms); + FAULT_ON_NULL(adcHandler); + + // sanity check + if (adcHandler == NULL) + { + NANOCLR_SET_AND_LEAVE(CLR_E_FAIL); + } int_fast16_t res = ADC_convert(adcHandler, &adcValue0); - if (res == ADC_STATUS_SUCCESS) + // close ADC + ADC_close(adcHandler); + + if (res == ADC_STATUS_SUCCESS) { - adcValue0MicroVolt = ADC_convertRawToMicroVolts(adcHandler, adcValue0); + // get the raw value converted to micro volts + adcValue0MicroVolt = ADC_convertToMicroVolts(adcHandler, adcValue0); + + // after the conversion need to get the value has if it was the raw one + // the multiplier is 4096 (corresponding to 12bits) + double rawValue = + (adcValue0MicroVolt / (double)((ADCCC26XX_HWAttrs *)ADC_config[channelNumber].hwAttrs)->refVoltage) * + 4096; + + // load back to integer to return a proper value + adcValue0 = rawValue; + + // set result with reading value + stack.SetResult_I4(adcValue0); } else { + // read operation failed NANOCLR_SET_AND_LEAVE(CLR_E_FAIL); } - - - ADC_close(adcHandler); - - stack.SetResult_I4(adcValue0MicroVolt); } NANOCLR_NOCLEANUP(); } -HRESULT Library_win_dev_adc_native_Windows_Devices_Adc_AdcChannel::NativeDisposeChannel___VOID( CLR_RT_StackFrame& stack ) +HRESULT Library_win_dev_adc_native_Windows_Devices_Adc_AdcChannel::NativeDisposeChannel___VOID(CLR_RT_StackFrame &stack) { (void)stack; diff --git a/targets/TI-SimpleLink/nanoCLR/Windows.Devices.Adc/win_dev_adc_native_Windows_Devices_Adc_AdcController.cpp b/targets/TI-SimpleLink/nanoCLR/Windows.Devices.Adc/win_dev_adc_native_Windows_Devices_Adc_AdcController.cpp index de4b4c17e6..7dc4cbc53e 100644 --- a/targets/TI-SimpleLink/nanoCLR/Windows.Devices.Adc/win_dev_adc_native_Windows_Devices_Adc_AdcController.cpp +++ b/targets/TI-SimpleLink/nanoCLR/Windows.Devices.Adc/win_dev_adc_native_Windows_Devices_Adc_AdcController.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/nanoCLR/Windows.Devices.Adc/win_dev_adc_native_target.h b/targets/TI-SimpleLink/nanoCLR/Windows.Devices.Adc/win_dev_adc_native_target.h index 6aaa808f2b..f98b66be95 100644 --- a/targets/TI-SimpleLink/nanoCLR/Windows.Devices.Adc/win_dev_adc_native_target.h +++ b/targets/TI-SimpleLink/nanoCLR/Windows.Devices.Adc/win_dev_adc_native_target.h @@ -1,14 +1,14 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // - #ifndef _WIN_DEV_ADC_NATIVE_TARGET_H_ #define _WIN_DEV_ADC_NATIVE_TARGET_H_ #include "Board.h" #include +#include #include -#endif //_WIN_DEV_ADC_NATIVE_TARGET_H_ +#endif //_WIN_DEV_ADC_NATIVE_TARGET_H_ diff --git a/targets/TI-SimpleLink/nanoCLR/Windows.Devices.Gpio/cpu_gpio.cpp b/targets/TI-SimpleLink/nanoCLR/Windows.Devices.Gpio/cpu_gpio.cpp index 2f9ea74a2e..3278135465 100644 --- a/targets/TI-SimpleLink/nanoCLR/Windows.Devices.Gpio/cpu_gpio.cpp +++ b/targets/TI-SimpleLink/nanoCLR/Windows.Devices.Gpio/cpu_gpio.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // @@ -9,302 +9,505 @@ #include #include +#include +#include + +#define GPIO_MAX_PINS 16 + +// SimpleLink doesn't follow the port&pin design pattern, there are no ports, just GPIO pins +#define TOTAL_GPIO_PORTS 1 + +#define EMPTY_PIN 0xFFFF + +// Array of Pin configurations +GPIO_PinConfig gpioPinConfigs[] = { + GPIO_DO_NOT_CONFIG | EMPTY_PIN, + GPIO_DO_NOT_CONFIG | EMPTY_PIN, + GPIO_DO_NOT_CONFIG | EMPTY_PIN, + GPIO_DO_NOT_CONFIG | EMPTY_PIN, + GPIO_DO_NOT_CONFIG | EMPTY_PIN, + GPIO_DO_NOT_CONFIG | EMPTY_PIN, + GPIO_DO_NOT_CONFIG | EMPTY_PIN, + GPIO_DO_NOT_CONFIG | EMPTY_PIN, + GPIO_DO_NOT_CONFIG | EMPTY_PIN, + GPIO_DO_NOT_CONFIG | EMPTY_PIN, + GPIO_DO_NOT_CONFIG | EMPTY_PIN, + GPIO_DO_NOT_CONFIG | EMPTY_PIN, + GPIO_DO_NOT_CONFIG | EMPTY_PIN, + GPIO_DO_NOT_CONFIG | EMPTY_PIN, + GPIO_DO_NOT_CONFIG | EMPTY_PIN, + GPIO_DO_NOT_CONFIG | EMPTY_PIN, +}; -#define GPIO_MAX_PINS 16 -#define TOTAL_GPIO_PORTS ((GPIO_MAX_PINS + 15) / 16) +// Array of callback function pointers +GPIO_CallbackFxn gpioCallbackFunctions[GPIO_MAX_PINS]; // Gpio input state structure struct gpio_input_state : public HAL_DblLinkedNode { - GPIO_PIN pinNumber; // Pin number - Clock_Handle debounceTimer; // debounce timer for this Pin - GPIO_INTERRUPT_SERVICE_ROUTINE isrPtr; // Ptr to user ISR or null - uint32_t debounceMs; // debounce Millsecs, no debonce=0 - uint8_t mode; // Interrupt mode - void * param; // Param to user isr call - bool expected; // Expected state for debounce handler - bool waitingDebounce; // True if waiting for debounce timer to complete + // Pin number + GPIO_PIN pinNumber; + + // pin config index + uint8_t pinConfigIndex; + + // debounce timer for this Pin + Clock_Handle debounceTimer; + + // poniter to user ISR or null + GPIO_INTERRUPT_SERVICE_ROUTINE isrPtr; + + // debounce millsecs, no debonce=0 + uint32_t debounceMs; + + // interrupt mode + uint8_t mode; + + // param to user IRS call + void *param; + + // expected state for debounce handler + uint_fast8_t expected; + + // flag for waiting for debounce timer to complete + bool waitingDebounce; }; -// Array holds pointers to gpio_input_state for active input pins -static gpio_input_state * gpioInputState[GPIO_MAX_PINS]; +// Double Linked list for GPIO input status +static HAL_DblLinkedList gpioInputList; + +// array to store reserved state of GPIO pins +// not need to use this because we already keep track of the pins with the gpioPinConfigs +// static uint8_t pinReserved[TOTAL_GPIO_PORTS]; + +// Get pointer to gpio_input_state for GPIO pin +// return NULL if not found +gpio_input_state *GetInputState(GPIO_PIN pinNumber) +{ + gpio_input_state *pState = gpioInputList.FirstNode(); + + while (pState->Next() != NULL) + { + if (pState->pinNumber == pinNumber) + { + return pState; + } + + pState = pState->Next(); + } + + return NULL; +} + +// Get pointer to gpio_input_state for GPIO pin +// return NULL if not found +gpio_input_state *GetInputStateByConfigIndex(uint8_t pinConfigIndex) +{ + gpio_input_state *pState = gpioInputList.FirstNode(); + + while (pState->Next() != NULL) + { + if (pState->pinConfigIndex == pinConfigIndex) + { + return pState; + } + + pState = pState->Next(); + } + + return NULL; +} + +// find a free slot in the pin config array +int8_t FindFreePinConfig() +{ + for (uint8_t index = 0; index < GPIO_MAX_PINS; index++) + { + if ((uint16_t)gpioPinConfigs[index] == EMPTY_PIN) + { + // found a free slot! + return index; + } + } + + return -1; +} + +// find a pin number in the pin config array +int8_t FindPinConfig(GPIO_PIN pinNumber) +{ + for (uint8_t index = 0; index < GPIO_MAX_PINS; index++) + { + // need to mask the gpioPinConfigs item to get only the 8 LSbits where the pin number is stored + if ((uint8_t)gpioPinConfigs[index] == pinNumber) + { + // found a free slot! + return index; + } + } -// Array of bits for saving reserved state -static uint16_t pinReserved[TOTAL_GPIO_PORTS]; + return -1; +} -// Allocate a new gpio_input_state and update gpioInputState array +// Allocate a new gpio_input_state and add to end of list // if already exist then just return current ptr -gpio_input_state * AllocateGpioInputState(GPIO_PIN pinNumber) +gpio_input_state *AllocateGpioInputState(GPIO_PIN pinNumber) +{ + gpio_input_state *pState = GetInputState(pinNumber); + + if (pState == NULL) + { + // found a free slot! + pState = (gpio_input_state *)platform_malloc(sizeof(gpio_input_state)); + + // sanity check + if (pState != NULL) + { + memset(pState, 0, sizeof(gpio_input_state)); + + // store the pin number + pState->pinNumber = pinNumber; + + gpioInputList.LinkAtBack(pState); + } + } + + return pState; +} + +void UnlinkInputState(gpio_input_state *pState) { - gpio_input_state * ptr = gpioInputState[pinNumber]; - if (ptr == NULL) - { - ptr = (gpio_input_state *)platform_malloc(sizeof(gpio_input_state)); - memset(ptr, 0, sizeof(gpio_input_state)); - - ptr->pinNumber = pinNumber; - gpioInputState[pinNumber] = ptr; - } - return ptr; + if (pState->debounceTimer != 0) + { + Clock_delete(&pState->debounceTimer); + } + + // Remove interrupt associated with pin + // it's OK to do always this, no matter if interrupts are enabled or not + GPIO_disableInt(pState->pinConfigIndex); + + // remove callback + gpioCallbackFunctions[pState->pinConfigIndex] = NULL; + + // unlink from list + pState->Unlink(); + + // free memory + platform_free(pState); } // Delete gpio_input_state from array and tidy up ( Timer & ISR handler ) void DeleteGpioInputState(GPIO_PIN pinNumber) { - if (pinNumber < GPIO_MAX_PINS) - { - gpio_input_state * pState = gpioInputState[pinNumber]; - if ( pState ) - { - if (pState->debounceTimer != 0) - { - Clock_delete(&pState->debounceTimer); - } - - // Remove interrupt associated with pin - // it's OK to do always this, no matter if interrupts are enabled or not - GPIO_disableInt(pState->pinNumber); - - platform_free(pState); - - gpioInputState[pinNumber] = NULL; - } - } + gpio_input_state *pState = GetInputState(pinNumber); + + if (pState) + { + UnlinkInputState(pState); + } } // // Debounce Handler, called when timer is complete // -static void debounceTimer_Callback(UArg arg) +static void DebounceTimerCallback(UArg arg) { - int16_t index = (int16_t)arg; - - gpio_input_state * pState = gpioInputState[index]; - - if (pState->isrPtr) - { - // get current pin state - bool actual = CPU_GPIO_GetPinState(pState->pinNumber); - if (actual == pState->expected) - { - pState->isrPtr(pState->pinNumber, actual, pState->param); - - if (pState->mode == GPIO_INT_EDGE_BOTH) - { - // both edges - // update expected state - pState->expected ^= 1; - } - } - } - - pState->waitingDebounce = false; + NATIVE_INTERRUPT_START + + gpio_input_state *pState = GetInputStateByConfigIndex((int16_t)arg); + + if (pState) + { + // get current pin state + uint_fast8_t pinState = GPIO_read(pState->pinConfigIndex); + + if (pinState == pState->expected) + { + // post a managed event with the current pin reading + pState->isrPtr(pState->pinNumber, pinState); + } + + pState->waitingDebounce = false; + } } -// Gpio event callback +// GPIO event callback static void GpioEventCallback(uint_least8_t index) { - NATIVE_INTERRUPT_START - - gpio_input_state * pState = gpioInputState[index]; - - // Any pin set up here ? - if (pState != NULL) - { - // Ignore any pin changes during debounce timeout - if (!pState->waitingDebounce) - { - // If calling ISR available then call it - if (pState->isrPtr) - { - // Debounce time set ? - if (pState->debounceMs > 0) - { - // Yes, set up debounce timer - pState->waitingDebounce = true; - - // Timer created yet ? - if (pState->debounceTimer == 0) - { - // setup timer - Clock_Params params; - - Clock_Params_init(¶ms); - params.arg = (UArg)index; - params.startFlag = false; - params.period = 0; - - // Create and start timer - pState->debounceTimer = Clock_create(debounceTimer_Callback, pState->debounceMs / Clock_tickPeriod, ¶ms, Error_IGNORE); - } - else - { - // timer already exists - // set timeout - Clock_setTimeout(pState->debounceTimer, pState->debounceMs / Clock_tickPeriod); - } - - // start timer - Clock_start(pState->debounceTimer); - } - else - { - // No debounce so just call ISR with current pin state - uint_fast8_t pinState = GPIO_read(pState->pinNumber); - pState->isrPtr(pState->pinNumber, pinState, pState->param); - } - } - } - } - - NATIVE_INTERRUPT_END + NATIVE_INTERRUPT_START + + gpio_input_state *pState = GetInputStateByConfigIndex(index); + + // Any pin set up here ? + if (pState != NULL) + { + // Ignore any pin changes during debounce timeout + if (!pState->waitingDebounce) + { + uint_fast8_t pinState = GPIO_read(pState->pinConfigIndex); + + // Debounce time set ? + if (pState->debounceMs > 0) + { + // Yes, set up debounce timer + pState->waitingDebounce = true; + + // store expected state + pState->expected = pinState; + + // timer already exists + // set timeout as we are using a one-shot timer + Clock_setTimeout(pState->debounceTimer, pState->debounceMs * 1000 / Clock_tickPeriod); + + // start timer + Clock_start(pState->debounceTimer); + } + else + { + // No debounce so just post a managed event with the current pin reading + pState->isrPtr(pState->pinNumber, pinState); + } + } + } + + NATIVE_INTERRUPT_END } -bool CPU_GPIO_Initialize() +bool CPU_GPIO_Initialize() { - // set gpioState ptrs to NULL - memset(gpioInputState, 0, sizeof(gpioInputState)); + // Initialise Double linked list for input pin states + gpioInputList.Initialize(); + + // clear GPIO pin configs + for (uint8_t index = 0; index < GPIO_MAX_PINS; index++) + { + gpioPinConfigs[index] == GPIO_DO_NOT_CONFIG | EMPTY_PIN; + } + + // clear callbacks + memset(gpioCallbackFunctions, 0, sizeof(gpioCallbackFunctions)); - // Make sure all pins are not reserved - memset(pinReserved, 0, sizeof(pinReserved)); - - return true; + return true; } -bool CPU_GPIO_Uninitialize() +bool CPU_GPIO_Uninitialize() { - // Clean up input list - for(int index; index < GPIO_MAX_PINS; index++) - { - DeleteGpioInputState(index); - } + NANOCLR_FOREACH_NODE(gpio_input_state, pGpio, gpioInputList) + { + UnlinkInputState(pGpio); + } + NANOCLR_FOREACH_NODE_END(); - return true; + return true; } // Set/reset reserved state of pin -bool CPU_GPIO_ReservePin(GPIO_PIN pinNumber, bool fReserve) +bool CPU_GPIO_ReservePin(GPIO_PIN pinNumber, bool fReserve) { - // Check if valid pin number 0 - 15 - if ( pinNumber >= GPIO_MAX_PINS ) return false; - - int port = pinNumber >> 4, bit = 1 << (pinNumber & 0x0F); - GLOBAL_LOCK(); - - if (fReserve) - { - if (pinReserved[port] & bit) - { - GLOBAL_UNLOCK(); - return false; // already reserved - } - - pinReserved[port] |= bit; - } - else - { - pinReserved[port] &= ~bit; - } - - GLOBAL_UNLOCK(); - return true; + // Check if this is a valid GPIO pin + if (pinNumber >= GPIO_PINS_COUNT) + { + return false; + } + + GLOBAL_LOCK(); + + uint8_t index = FindPinConfig(pinNumber); + + if (fReserve) + { + if (index < 0) + { + // pin already in use + + GLOBAL_UNLOCK(); + + return false; + } + else + { + // pin not being used, get the next free slot + index = FindFreePinConfig(); + + // reserve pin + gpioPinConfigs[index] = pinNumber; + } + } + else + { + gpioPinConfigs[index] == GPIO_DO_NOT_CONFIG | EMPTY_PIN; + } + + GLOBAL_UNLOCK(); + + return true; } // Return if Pin is reserved -bool CPU_GPIO_PinIsBusy(GPIO_PIN pin) +bool CPU_GPIO_PinIsBusy(GPIO_PIN pinNumber) { - int port = pin >> 4, sh = pin & 0x0F; - return (pinReserved[port] >> sh) & 1; + return (FindPinConfig(pinNumber) >= 0); } // Return maximum number of pins int32_t CPU_GPIO_GetPinCount() { - return GPIO_MAX_PINS; + return GPIO_MAX_PINS; } // Get current state of pin GpioPinValue CPU_GPIO_GetPinState(GPIO_PIN pinNumber) { - return (GpioPinValue)GPIO_read(pinNumber); + // get index of pin in config array + uint8_t pinConfigIndex = FindPinConfig(pinNumber); + + if (pinConfigIndex >= 0) + { + return (GpioPinValue)GPIO_read(pinConfigIndex); + } } // Set Pin state -void CPU_GPIO_SetPinState(GPIO_PIN pinNumber, GpioPinValue PinState) +void CPU_GPIO_SetPinState(GPIO_PIN pinNumber, GpioPinValue pinState) { - GPIO_write(pinNumber, PinState); + // get index of pin in config array + uint8_t pinConfigIndex = FindPinConfig(pinNumber); + + if (pinConfigIndex >= 0) + { + GPIO_write(pinConfigIndex, pinState); + } } // Toggle pin state void CPU_GPIO_TogglePinState(GPIO_PIN pinNumber) { - GPIO_toggle(pinNumber); + uint8_t pinConfigIndex = FindPinConfig(pinNumber); + + if (pinConfigIndex >= 0) + { + GPIO_toggle(pinConfigIndex); + } } // Enable gpio pin for input -bool CPU_GPIO_EnableInputPin(GPIO_PIN pinNumber, CLR_UINT64 debounceTimeMilliseconds, GPIO_INTERRUPT_SERVICE_ROUTINE pin_ISR, void* isr_Param, GPIO_INT_EDGE intEdge, GpioPinDriveMode driveMode) +bool CPU_GPIO_EnableInputPin( + GPIO_PIN pinNumber, + CLR_UINT64 debounceTimeMilliseconds, + GPIO_INTERRUPT_SERVICE_ROUTINE pinISR, + void *isrParam, + GPIO_INT_EDGE intEdge, + GpioPinDriveMode driveMode) { - gpio_input_state * pState; - - // Check if valid pin number 0 - 15 - if ( pinNumber >= GPIO_MAX_PINS ) return false; - - // Check Input drive mode - if (driveMode >= (int)GpioPinDriveMode_Output) - return false; - - if (!CPU_GPIO_SetDriveMode(pinNumber, driveMode)) - return false; - - pState = AllocateGpioInputState(pinNumber); - - // Link ISR ptr supplied and not already set up - // CPU_GPIO_EnableInputPin could be called a 2nd time with changed parameters - if ( (pin_ISR != NULL) && (pState->isrPtr == NULL)) - { - // get current config - GPIO_PinConfig currentPinConfig; - GPIO_getConfig(pinNumber, ¤tPinConfig); - - // Map Interrupt edge to Ti-SimpleLink edge definitions - // NONE=0, EDGE_LOW=1, EDGE_HIGH=2, EDGE_BOTH=3, LEVEL_HIGH=4, LEVEL_LOW - GPIO_PinConfig mapint[6] = - { GPIO_CFG_IN_INT_NONE, GPIO_CFG_IN_INT_FALLING, GPIO_CFG_IN_INT_RISING, GPIO_CFG_IN_INT_BOTH_EDGES, GPIO_CFG_IN_INT_LOW, GPIO_CFG_IN_INT_HIGH }; - - currentPinConfig = mapint[6] | currentPinConfig; - - // set interrupt on both edges - GPIO_setConfig(pinNumber, currentPinConfig | mapint[6] ); - GPIO_setCallback(pinNumber, GpioEventCallback); - - } - - pState->isrPtr = pin_ISR; - pState->mode = intEdge; - pState->param = (void *)isr_Param; - pState->debounceMs = (uint32_t)(debounceTimeMilliseconds); - - switch (intEdge) - { - case GPIO_INT_EDGE_LOW: - case GPIO_INT_LEVEL_LOW: - pState->expected = false; - break; - - case GPIO_INT_EDGE_HIGH: - case GPIO_INT_LEVEL_HIGH: - pState->expected = true; - break; - - case GPIO_INT_EDGE_BOTH: - pState->expected = !CPU_GPIO_GetPinState(pinNumber); // Use inverse of current pin state - break; - - default: - break; - } - - return true; + gpio_input_state *pState; + + // Check Input drive mode + if (driveMode >= (int)GpioPinDriveMode_Output) + { + return false; + } + + pState = AllocateGpioInputState(pinNumber); + + // get the index of this GPIO in pin config array + // and store it + pState->pinConfigIndex = FindPinConfig(pinNumber); + + // set default input config for GPIO pin + gpioPinConfigs[pState->pinConfigIndex] |= PIN_INPUT_EN | PIN_NOPULL | PIN_IRQ_DIS; + + if (!CPU_GPIO_SetDriveMode(pState->pinConfigIndex, driveMode)) + { + return false; + } + + // Link ISR ptr supplied and not already set up + // CPU_GPIO_EnableInputPin could be called a 2nd time with changed parameters + if (pinISR != NULL && (pState->isrPtr == NULL)) + { + // get current config + GPIO_PinConfig currentPinConfig; + GPIO_getConfig(pState->pinConfigIndex, ¤tPinConfig); + + // set interrupt on both edges + GPIO_setConfig(pState->pinConfigIndex, currentPinConfig | GPIO_CFG_IN_INT_BOTH_EDGES); + // set callback + GPIO_setCallback(pState->pinConfigIndex, GpioEventCallback); + // enable INT + GPIO_enableInt(pState->pinConfigIndex); + + // store parameters & configs + pState->isrPtr = pinISR; + pState->mode = intEdge; + pState->param = isrParam; + pState->debounceMs = (uint32_t)(debounceTimeMilliseconds); + + // create timer if not there yet + if (pState->debounceMs > 0 && pState->debounceTimer == NULL) + { + // setup timer + Clock_Params params; + + Clock_Params_init(¶ms); + params.arg = (UArg)pState->pinConfigIndex; + params.startFlag = FALSE; + // period it's 0 because we are using a one-shot timer + params.period = 0; + + // create timer + // set timeout as we are using a one-shot timer + pState->debounceTimer = Clock_create( + DebounceTimerCallback, + pState->debounceMs * 1000 / Clock_tickPeriod, + ¶ms, + Error_IGNORE); + } + + switch (intEdge) + { + case GPIO_INT_EDGE_LOW: + case GPIO_INT_LEVEL_LOW: + pState->expected = false; + break; + + case GPIO_INT_EDGE_HIGH: + case GPIO_INT_LEVEL_HIGH: + pState->expected = true; + break; + + case GPIO_INT_EDGE_BOTH: + // Use inverse of current pin state + pState->expected = !CPU_GPIO_GetPinState(pState->pinConfigIndex); + break; + + default: + break; + } + } + else if (pinISR == NULL && (pState->isrPtr != NULL)) + { + // there is no managed handler setup anymore + // remove INT handler + + // get current config + GPIO_PinConfig currentPinConfig; + GPIO_getConfig(pState->pinConfigIndex, ¤tPinConfig); + + // disable interrupt + GPIO_disableInt(pState->pinConfigIndex); + // remove callback + GPIO_setCallback(pState->pinConfigIndex, NULL); + // remove interrupt config + GPIO_setConfig(pState->pinConfigIndex, currentPinConfig | GPIO_CFG_IN_INT_NONE); + + // clear parameters & configs + pState->isrPtr = NULL; + pState->mode = GPIO_INT_NONE; + pState->param = NULL; + pState->debounceMs = 0; + } + + return true; } // Enable an output pin @@ -314,80 +517,93 @@ bool CPU_GPIO_EnableInputPin(GPIO_PIN pinNumber, CLR_UINT64 debounceTimeMillisec // driveMode - Drive mode and resistors // return - True if succesful, false invalid pin, pin not putput, invalid drive mode for ouptput // -bool CPU_GPIO_EnableOutputPin(GPIO_PIN pinNumber, GpioPinValue InitialState, GpioPinDriveMode driveMode) +bool CPU_GPIO_EnableOutputPin(GPIO_PIN pinNumber, GpioPinValue InitialState, GpioPinDriveMode driveMode) { - // Check if valid pin number 0 - 15 - if ( pinNumber >= GPIO_MAX_PINS ) return false; + // check is output drive mode + if (driveMode < (int)GpioPinDriveMode_Output) + { + return false; + } + + // If this is currently an input pin then clean up + DeleteGpioInputState(pinNumber); - // check is output drive mode - if (driveMode < (int)GpioPinDriveMode_Output) return false; + // get free slot in pin config array + uint8_t pinConfigIndex = FindPinConfig(pinNumber); - // If this is currently an input pin then clean up - DeleteGpioInputState(pinNumber); + // set the GPIO pin as output + gpioPinConfigs[pinConfigIndex] |= GPIO_CFG_OUT_STD; - if (CPU_GPIO_SetDriveMode(pinNumber, driveMode) == false) return false; + if (CPU_GPIO_SetDriveMode(pinConfigIndex, driveMode) == false) + { + return false; + } - CPU_GPIO_SetPinState(pinNumber, InitialState); + CPU_GPIO_SetPinState(pinNumber, InitialState); - return true; + return true; } void CPU_GPIO_DisablePin(GPIO_PIN pinNumber, GpioPinDriveMode driveMode, uint32_t alternateFunction) { - GLOBAL_LOCK(); - - DeleteGpioInputState(pinNumber); + GLOBAL_LOCK(); - CPU_GPIO_SetDriveMode(pinNumber, driveMode); - - if (alternateFunction) - { - GPIO_setConfig(pinNumber, alternateFunction); - } + uint8_t pinConfigIndex = FindPinConfig(pinNumber); - GLOBAL_UNLOCK(); + if (pinConfigIndex >= 0) + { + DeleteGpioInputState(pinNumber); - CPU_GPIO_ReservePin(pinNumber, false); -} + CPU_GPIO_SetDriveMode(pinConfigIndex, driveMode); + + if (alternateFunction) + { + GPIO_setConfig(pinConfigIndex, alternateFunction); + } + GLOBAL_UNLOCK(); -// Validate pin and set drive mode + CPU_GPIO_ReservePin(pinNumber, false); + } +} + +// Set drive mode +// pinNumber is the index of the corresponding PIN config in array // return true if ok -bool CPU_GPIO_SetDriveMode(GPIO_PIN pinNumber, GpioPinDriveMode driveMode) +bool CPU_GPIO_SetDriveMode(GPIO_PIN pinConfigIndex, GpioPinDriveMode driveMode) { - if (pinNumber >= GPIO_MAX_PINS) return false; - - // disable interrupt as default - GPIO_disableInt(pinNumber); + // get current config + GPIO_PinConfig currentPinConfig; + GPIO_getConfig(pinConfigIndex, ¤tPinConfig); switch (driveMode) { case GpioPinDriveMode_Input: - GPIO_setConfig(pinNumber, GPIO_CFG_IN_NOPULL); + GPIO_setConfig(pinConfigIndex, currentPinConfig | GPIO_CFG_IN_NOPULL); break; case GpioPinDriveMode_InputPullDown: - GPIO_setConfig(pinNumber, GPIO_CFG_IN_PD); + GPIO_setConfig(pinConfigIndex, currentPinConfig | GPIO_CFG_IN_PD); break; case GpioPinDriveMode_InputPullUp: - GPIO_setConfig(pinNumber, GPIO_CFG_IN_PU); + GPIO_setConfig(pinConfigIndex, currentPinConfig | GPIO_CFG_IN_PU); break; case GpioPinDriveMode_Output: - GPIO_setConfig(pinNumber, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW); + GPIO_setConfig(pinConfigIndex, currentPinConfig | GPIO_CFG_OUT_STD | GPIO_CFG_OUT_STR_MED); break; case GpioPinDriveMode_OutputOpenDrain: - GPIO_setConfig(pinNumber, GPIO_CFG_OUT_OD_NOPULL); + GPIO_setConfig(pinConfigIndex, currentPinConfig | GPIO_CFG_OUT_OD_NOPULL); break; case GpioPinDriveMode_OutputOpenDrainPullUp: - GPIO_setConfig(pinNumber, GPIO_CFG_OUT_OD_PU); + GPIO_setConfig(pinConfigIndex, currentPinConfig | GPIO_CFG_OUT_OD_PU); break; case GpioPinDriveMode_OutputOpenSourcePullDown: - GPIO_setConfig(pinNumber, GPIO_CFG_OUT_OD_PD); + GPIO_setConfig(pinConfigIndex, currentPinConfig | GPIO_CFG_OUT_OD_PD); break; default: @@ -395,48 +611,46 @@ bool CPU_GPIO_SetDriveMode(GPIO_PIN pinNumber, GpioPinDriveMode driveMode) return false; } - return true; + return true; } bool CPU_GPIO_DriveModeSupported(GPIO_PIN pinNumber, GpioPinDriveMode driveMode) { - bool driveModeSupported = false; - - // check if the requested drive mode is supported by SimpleLink - if ((driveMode == GpioPinDriveMode_Input) || - (driveMode == GpioPinDriveMode_InputPullDown) || - (driveMode == GpioPinDriveMode_InputPullUp) || - (driveMode == GpioPinDriveMode_Output) || - (driveMode == GpioPinDriveMode_OutputOpenDrain) || - (driveMode == GpioPinDriveMode_OutputOpenDrainPullUp) || - (driveMode == GpioPinDriveMode_OutputOpenSourcePullDown)) - { - driveModeSupported = true; - } + (void)pinNumber; + + bool driveModeSupported = false; + + // check if the requested drive mode is supported by SimpleLink + if ((driveMode == GpioPinDriveMode_Input) || (driveMode == GpioPinDriveMode_InputPullDown) || + (driveMode == GpioPinDriveMode_InputPullUp) || (driveMode == GpioPinDriveMode_Output) || + (driveMode == GpioPinDriveMode_OutputOpenDrain) || (driveMode == GpioPinDriveMode_OutputOpenDrainPullUp) || + (driveMode == GpioPinDriveMode_OutputOpenSourcePullDown)) + { + driveModeSupported = true; + } - return driveModeSupported; + return driveModeSupported; } uint32_t CPU_GPIO_GetPinDebounce(GPIO_PIN pinNumber) { - if (pinNumber >= GPIO_MAX_PINS) return false; + gpio_input_state *pState = GetInputState(pinNumber); - gpio_input_state * ptr = gpioInputState[pinNumber]; - if (ptr) - return ptr->debounceMs; + _ASSERTE(pState == NULL); - return 0; + return pState->debounceMs; } bool CPU_GPIO_SetPinDebounce(GPIO_PIN pinNumber, CLR_UINT64 debounceTimeMilliseconds) { - if (pinNumber >= GPIO_MAX_PINS) return false; - - gpio_input_state * ptr = gpioInputState[pinNumber]; - if (ptr) - { - ptr->debounceMs = (uint32_t)(debounceTimeMilliseconds); - return true; - } - return false; + gpio_input_state *pState = GetInputState(pinNumber); + + // can only change the debounce in pin state if the pin has already been configured as input + // if not, doesn't matter, because the new debounce will be used next time it's required + if (pState != NULL) + { + pState->debounceMs = (uint32_t)(debounceTimeMilliseconds); + } + + return true; } diff --git a/targets/TI-SimpleLink/nanoCLR/Windows.Devices.Gpio/win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter.cpp b/targets/TI-SimpleLink/nanoCLR/Windows.Devices.Gpio/win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter.cpp index b802d5debd..fa1b358fa7 100644 --- a/targets/TI-SimpleLink/nanoCLR/Windows.Devices.Gpio/win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter.cpp +++ b/targets/TI-SimpleLink/nanoCLR/Windows.Devices.Gpio/win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/nanoCLR/Windows.Devices.Gpio/win_dev_gpio_native_target.h b/targets/TI-SimpleLink/nanoCLR/Windows.Devices.Gpio/win_dev_gpio_native_target.h index c5ef7d962b..5c700030c0 100644 --- a/targets/TI-SimpleLink/nanoCLR/Windows.Devices.Gpio/win_dev_gpio_native_target.h +++ b/targets/TI-SimpleLink/nanoCLR/Windows.Devices.Gpio/win_dev_gpio_native_target.h @@ -1,16 +1,16 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // - #ifndef _WIN_DEV_GPIO_NATIVE_TARGET_H_ #define _WIN_DEV_GPIO_NATIVE_TARGET_H_ #include +#include -#include "rom.h" +#include "rom.h" // #include "rom_map.h" #include #include @@ -19,4 +19,4 @@ #include #include -#endif //_WIN_DEV_GPIO_NATIVE_TARGET_H_ +#endif //_WIN_DEV_GPIO_NATIVE_TARGET_H_ diff --git a/targets/TI-SimpleLink/nanoCLR/Windows.Devices.I2c/win_dev_i2c_native_Windows_Devices_I2C_I2cDevice.cpp b/targets/TI-SimpleLink/nanoCLR/Windows.Devices.I2c/win_dev_i2c_native_Windows_Devices_I2C_I2cDevice.cpp index 99ec20d4c2..3fa0457a86 100644 --- a/targets/TI-SimpleLink/nanoCLR/Windows.Devices.I2c/win_dev_i2c_native_Windows_Devices_I2C_I2cDevice.cpp +++ b/targets/TI-SimpleLink/nanoCLR/Windows.Devices.I2c/win_dev_i2c_native_Windows_Devices_I2C_I2cDevice.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // @@ -23,31 +23,33 @@ void HostI2C_CallbackFxn(I2C_Handle handle, I2C_Transaction *transaction, bool t NATIVE_INTERRUPT_END } -HRESULT Library_win_dev_i2c_native_Windows_Devices_I2c_I2cDevice::NativeInit___VOID( CLR_RT_StackFrame& stack ) +HRESULT Library_win_dev_i2c_native_Windows_Devices_I2c_I2cDevice::NativeInit___VOID(CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); { - NF_PAL_I2C* palI2c = NULL; + NF_PAL_I2C *palI2c = NULL; // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); - + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + // get a pointer to the managed I2C connectionSettings object instance - CLR_RT_HeapBlock* pConfig = pThis[ FIELD___connectionSettings ].Dereference(); + CLR_RT_HeapBlock *pConfig = pThis[FIELD___connectionSettings].Dereference(); // get bus index // this is coded with a multiplication, need to perform and int division to get the number // see the comments in the I2cDevice() constructor in managed code for details - uint8_t busIndex = (uint8_t)(pThis[ FIELD___deviceId ].NumericByRef().s4 / 1000); + uint8_t busIndex = (uint8_t)(pThis[FIELD___deviceId].NumericByRef().s4 / 1000); // config GPIO pins used by the I2C peripheral // init the PAL struct for this I2C bus and assign the respective driver // all this occurs if not already done - // why do we need to check if this is already done? because several I2cDevice objects can be created associated to the same bus just using different addresses + // why do we need to check if this is already done? because several I2cDevice objects can be created associated + // to the same bus just using different addresses switch (busIndex) { case 1: - if(I2C1_PAL.i2c == NULL) + if (I2C1_PAL.i2c == NULL) { palI2c = &I2C1_PAL; } @@ -61,42 +63,48 @@ HRESULT Library_win_dev_i2c_native_Windows_Devices_I2c_I2cDevice::NativeInit___V // Create I2C for usage I2C_Params_init(&palI2c->i2cParams); - palI2c->i2cParams.bitRate = (I2cBusSpeed)pConfig[ I2cConnectionSettings::FIELD___busSpeed ].NumericByRef().s4 == I2cBusSpeed_StandardMode ? I2C_100kHz : I2C_400kHz; + palI2c->i2cParams.bitRate = + (I2cBusSpeed)pConfig[I2cConnectionSettings::FIELD___busSpeed].NumericByRef().s4 == I2cBusSpeed_StandardMode + ? I2C_100kHz + : I2C_400kHz; palI2c->i2cParams.transferMode = I2C_MODE_CALLBACK; palI2c->i2cParams.transferCallbackFxn = HostI2C_CallbackFxn; - palI2c->i2c = I2C_open(Board_I2C0, &palI2c->i2cParams); FAULT_ON_NULL(palI2c->i2c); - palI2c->i2cTransaction.slaveAddress = (I2cBusSpeed)pConfig[ I2cConnectionSettings::FIELD___slaveAddress ].NumericByRef().s4; + palI2c->i2c = I2C_open(Board_I2C0, &palI2c->i2cParams); + FAULT_ON_NULL(palI2c->i2c); + palI2c->i2cTransaction.slaveAddress = + (I2cBusSpeed)pConfig[I2cConnectionSettings::FIELD___slaveAddress].NumericByRef().s4; } NANOCLR_NOCLEANUP(); } -HRESULT Library_win_dev_i2c_native_Windows_Devices_I2c_I2cDevice::NativeDispose___VOID__BOOLEAN( CLR_RT_StackFrame& stack ) +HRESULT Library_win_dev_i2c_native_Windows_Devices_I2c_I2cDevice::NativeDispose___VOID__BOOLEAN( + CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); uint8_t busIndex; - NF_PAL_I2C* palI2c = NULL; bool disposeController = false; // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); // get disposeController disposeController = (bool)stack.Arg0().NumericByRef().u1; - if(disposeController) + if (disposeController) { // get bus index // this is coded with a multiplication, need to perform and int division to get the number // see the comments in the I2cDevice() constructor in managed code for details - busIndex = (uint8_t)(pThis[ FIELD___deviceId ].NumericByRef().s4 / 1000); + busIndex = (uint8_t)(pThis[FIELD___deviceId].NumericByRef().s4 / 1000); // get the driver for the I2C bus switch (busIndex) { case 1: // deactivates the I2C peripheral - I2C_close(palI2c->i2c); + I2C_close(I2C1_PAL.i2c); I2C1_PAL.i2c == NULL; break; @@ -105,30 +113,31 @@ HRESULT Library_win_dev_i2c_native_Windows_Devices_I2c_I2cDevice::NativeDispose_ NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); break; } - } NANOCLR_NOCLEANUP(); } -HRESULT Library_win_dev_i2c_native_Windows_Devices_I2c_I2cDevice::NativeTransmit___WindowsDevicesI2cI2cTransferResult__SZARRAY_U1__SZARRAY_U1( CLR_RT_StackFrame& stack ) +HRESULT Library_win_dev_i2c_native_Windows_Devices_I2c_I2cDevice:: + NativeTransmit___WindowsDevicesI2cI2cTransferResult__SZARRAY_U1__SZARRAY_U1(CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); { uint8_t busIndex; - NF_PAL_I2C* palI2c = NULL; + NF_PAL_I2C *palI2c = NULL; - CLR_RT_HeapBlock hbTimeout; - CLR_INT64* timeout; - bool eventResult = true; - uint32_t estimatedDurationMiliseconds; + CLR_RT_HeapBlock hbTimeout; + CLR_INT64 *timeout; + bool eventResult = true; + uint32_t estimatedDurationMiliseconds; - CLR_RT_HeapBlock_Array* writeBuffer; - CLR_RT_HeapBlock_Array* readBuffer; - CLR_RT_HeapBlock* result; + CLR_RT_HeapBlock_Array *writeBuffer; + CLR_RT_HeapBlock_Array *readBuffer; + CLR_RT_HeapBlock *result; // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); // // get pointer to connection settings field // CLR_RT_HeapBlock* connectionSettings = pThis[ FIELD___connectionSettings ].Dereference(); @@ -136,12 +145,12 @@ HRESULT Library_win_dev_i2c_native_Windows_Devices_I2c_I2cDevice::NativeTransmit // get bus index // this is coded with a multiplication, need to perform and int division to get the number // see the comments in the I2cDevice() constructor in managed code for details - busIndex = (uint8_t)(pThis[ FIELD___deviceId ].NumericByRef().s4 / 1000); + busIndex = (uint8_t)(pThis[FIELD___deviceId].NumericByRef().s4 / 1000); // get the driver for the I2C bus switch (busIndex) { - case 1 : + case 1: palI2c = &I2C1_PAL; break; default: @@ -180,52 +189,58 @@ HRESULT Library_win_dev_i2c_native_Windows_Devices_I2c_I2cDevice::NativeTransmit // !! need to cast to CLR_INT64 otherwise it wont setup a proper timeout infinite hbTimeout.SetInteger((CLR_INT64)-1); - NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks( hbTimeout, timeout )); - + NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks(hbTimeout, timeout)); + // protect the buffers from GC so DMA can find them where they are supposed to be - CLR_RT_ProtectFromGC gcWriteBuffer( *writeBuffer ); - CLR_RT_ProtectFromGC gcReadBuffer( *readBuffer ); + CLR_RT_ProtectFromGC gcWriteBuffer(*writeBuffer); + CLR_RT_ProtectFromGC gcReadBuffer(*readBuffer); if (writeBuffer != NULL) { - palI2c->i2cTransaction.writeBuf = (uint8_t*)writeBuffer->GetFirstElement(); + palI2c->i2cTransaction.writeBuf = (uint8_t *)writeBuffer->GetFirstElement(); } if (readBuffer != NULL) { - palI2c->i2cTransaction.readBuf = (uint8_t*)readBuffer->GetFirstElement(); + palI2c->i2cTransaction.readBuf = (uint8_t *)readBuffer->GetFirstElement(); } - + // perform I2C transaction using driver's callback which will set the appropriate event on completion - if(stack.m_customState == 1) + if (stack.m_customState == 1) { I2C_transfer(palI2c->i2c, &palI2c->i2cTransaction); - + // bump custom state stack.m_customState = 2; } - while(eventResult) + while (eventResult) { // non-blocking wait allowing other threads to run while we wait for the I2C transaction to complete - NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.WaitEvents( stack.m_owningThread, *timeout, CLR_RT_ExecutionEngine::c_Event_I2cMaster, eventResult )); + NANOCLR_CHECK_HRESULT( + g_CLR_RT_ExecutionEngine.WaitEvents(stack.m_owningThread, *timeout, Event_I2cMaster, eventResult)); - if(eventResult) + if (eventResult) { // event occurred // create the return object (I2cTransferResult) - // only at this point we are sure that there will be a return from this thread so it's OK to use the managed stack - CLR_RT_HeapBlock& top = stack.PushValueAndClear(); - NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.NewObjectFromIndex(top, g_CLR_RT_WellKnownTypes.m_I2cTransferResult)); - result = top.Dereference(); FAULT_ON_NULL(result); + // only at this point we are sure that there will be a return from this thread so it's OK to use the + // managed stack + CLR_RT_HeapBlock &top = stack.PushValueAndClear(); + NANOCLR_CHECK_HRESULT( + g_CLR_RT_ExecutionEngine.NewObjectFromIndex(top, g_CLR_RT_WellKnownTypes.m_I2cTransferResult)); + result = top.Dereference(); + FAULT_ON_NULL(result); // successfull transaction // set the result field - result[ Library_win_dev_i2c_native_Windows_Devices_I2c_I2cTransferResult::FIELD___status ].SetInteger((CLR_UINT32)I2cTransferStatus_FullTransfer); + result[Library_win_dev_i2c_native_Windows_Devices_I2c_I2cTransferResult::FIELD___status].SetInteger( + (CLR_UINT32)I2cTransferStatus_FullTransfer); // set the bytes transferred field - result[ Library_win_dev_i2c_native_Windows_Devices_I2c_I2cTransferResult::FIELD___bytesTransferred ].SetInteger((CLR_UINT32)(palI2c->i2cTransaction.writeCount + palI2c->i2cTransaction.readCount)); + result[Library_win_dev_i2c_native_Windows_Devices_I2c_I2cTransferResult::FIELD___bytesTransferred] + .SetInteger((CLR_UINT32)(palI2c->i2cTransaction.writeCount + palI2c->i2cTransaction.readCount)); // done here break; @@ -238,7 +253,6 @@ HRESULT Library_win_dev_i2c_native_Windows_Devices_I2c_I2cDevice::NativeTransmit // pop timeout heap block from stack stack.PopValue(); - } NANOCLR_NOCLEANUP(); } diff --git a/targets/TI-SimpleLink/nanoCLR/Windows.Devices.I2c/win_dev_i2c_native_Windows_Devices_I2c_I2cController.cpp b/targets/TI-SimpleLink/nanoCLR/Windows.Devices.I2c/win_dev_i2c_native_Windows_Devices_I2c_I2cController.cpp index c3006aa3f2..3169bc71f3 100644 --- a/targets/TI-SimpleLink/nanoCLR/Windows.Devices.I2c/win_dev_i2c_native_Windows_Devices_I2c_I2cController.cpp +++ b/targets/TI-SimpleLink/nanoCLR/Windows.Devices.I2c/win_dev_i2c_native_Windows_Devices_I2c_I2cController.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/nanoCLR/Windows.Devices.I2c/win_dev_i2c_native_target.h b/targets/TI-SimpleLink/nanoCLR/Windows.Devices.I2c/win_dev_i2c_native_target.h index 853b552330..8c3300a634 100644 --- a/targets/TI-SimpleLink/nanoCLR/Windows.Devices.I2c/win_dev_i2c_native_target.h +++ b/targets/TI-SimpleLink/nanoCLR/Windows.Devices.I2c/win_dev_i2c_native_target.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // @@ -10,17 +10,17 @@ #include "Board.h" #include -// struct representing the I2C -struct NF_PAL_I2C +// struct representing the I2C +typedef struct { - I2C_Handle i2c; - I2C_Params i2cParams; + I2C_Handle i2c; + I2C_Params i2cParams; I2C_Transaction i2cTransaction; -}; +} NF_PAL_I2C; /////////////////////////////////////////// // declaration of the the I2C PAL strucs // /////////////////////////////////////////// extern NF_PAL_I2C I2C1_PAL; -#endif //_WIN_DEV_I2C_NATIVE_TARGET_H_ +#endif //_WIN_DEV_I2C_NATIVE_TARGET_H_ diff --git a/targets/TI-SimpleLink/nanoCLR/Windows.Devices.Pwm/win_dev_pwm_native_Windows_Devices_Pwm_PwmController.cpp b/targets/TI-SimpleLink/nanoCLR/Windows.Devices.Pwm/win_dev_pwm_native_Windows_Devices_Pwm_PwmController.cpp index 9b11039aa5..708c60848d 100644 --- a/targets/TI-SimpleLink/nanoCLR/Windows.Devices.Pwm/win_dev_pwm_native_Windows_Devices_Pwm_PwmController.cpp +++ b/targets/TI-SimpleLink/nanoCLR/Windows.Devices.Pwm/win_dev_pwm_native_Windows_Devices_Pwm_PwmController.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/nanoCLR/Windows.Devices.Pwm/win_dev_pwm_native_Windows_Devices_Pwm_PwmPin.cpp b/targets/TI-SimpleLink/nanoCLR/Windows.Devices.Pwm/win_dev_pwm_native_Windows_Devices_Pwm_PwmPin.cpp index 7c6bf15b66..c5dacc477b 100644 --- a/targets/TI-SimpleLink/nanoCLR/Windows.Devices.Pwm/win_dev_pwm_native_Windows_Devices_Pwm_PwmPin.cpp +++ b/targets/TI-SimpleLink/nanoCLR/Windows.Devices.Pwm/win_dev_pwm_native_Windows_Devices_Pwm_PwmPin.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/nanoCLR/Windows.Devices.Pwm/win_dev_pwm_native_target.h b/targets/TI-SimpleLink/nanoCLR/Windows.Devices.Pwm/win_dev_pwm_native_target.h index b6f2523a5c..623c3294e4 100644 --- a/targets/TI-SimpleLink/nanoCLR/Windows.Devices.Pwm/win_dev_pwm_native_target.h +++ b/targets/TI-SimpleLink/nanoCLR/Windows.Devices.Pwm/win_dev_pwm_native_target.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/nanoCLR/Windows.Devices.Spi/CPU_SPI.cpp b/targets/TI-SimpleLink/nanoCLR/Windows.Devices.Spi/CPU_SPI.cpp new file mode 100644 index 0000000000..e26a99df7f --- /dev/null +++ b/targets/TI-SimpleLink/nanoCLR/Windows.Devices.Spi/CPU_SPI.cpp @@ -0,0 +1,254 @@ +// +// Copyright (c) .NET Foundation and Contributors +// Portions Copyright (c) Microsoft Corporation. All rights reserved. +// See LICENSE file in the project root for full license information. +// +// +// CPU_SPI_xxxx +// +// Read / Write physical SPI bus +// + +#include +#include +#include +#include + +#include +#include "Board.h" +#include + +// struct representing the SPI +struct NF_PAL_SPI +{ + SPI_Handle masterSpi; + SPI_Params spiParams; + SPI_Transaction *transactions; + uint8_t transactionCount; + SPI_OP_STATUS status; + SPI_Callback callback; +}; + +///////////////////////////////////////////////////// +// SPI PAL strucs declared in win_dev_spi_native.h // +///////////////////////////////////////////////////// +NF_PAL_SPI SPI1_PAL; + +void SpiCallback(SPI_Handle handle, SPI_Transaction *transaction) +{ + NATIVE_INTERRUPT_START + + // are there any other transactions pending? + if (SPI1_PAL.transactionCount) + { + // start transfer of next transaction + SPI_transfer(SPI1_PAL.masterSpi, &SPI1_PAL.transactions[SPI1_PAL.transactionCount--]); + } + else + { + // no more transactions + // fire callback for SPI transaction complete + SPI1_PAL.status = SPI_OP_COMPLETE; + SPI1_PAL.callback(0); + } + + NATIVE_INTERRUPT_END +} + +// Give a complete low-level SPI configuration from SPI_DEVICE_CONFIGURATION +void GetSPIConfig(const SPI_DEVICE_CONFIGURATION &spiDeviceConfig, SPI_WRITE_READ_SETTINGS &wrc) +{ + SPI_Params spiParams; + + // Open SPI as slave (default) + SPI_Params_init(&spiParams); + spiParams.frameFormat = (SPI_FrameFormat)spiDeviceConfig.Spi_Mode; + + // default to slave + // spiParams.mode = spiDeviceConfig.BusMode == SpiBusMode_master ? SPI_MASTER : SPI_SLAVE; + spiParams.mode = SPI_SLAVE; + + spiParams.transferCallbackFxn = SpiCallback; + spiParams.dataSize = wrc.Bits16ReadWrite ? 16 : 8; + spiParams.bitRate = spiDeviceConfig.Clock_RateHz; + + spiParams.transferMode = SPI_MODE_CALLBACK; + + SPI1_PAL.masterSpi = SPI_open(Board_SPI_SLAVE, &spiParams); + + SPI1_PAL.status = SPI_OP_READY; + SPI1_PAL.callback = wrc.callback; +} + +bool CPU_SPI_Initialize(uint8_t bus) +{ + (void)bus; + return true; +} + +bool CPU_SPI_Uninitialize(uint8_t bus) +{ + (void)bus; + + SPI_close(SPI1_PAL.masterSpi); + return true; +} + +// Performs a read/write operation on 8-bit word data. +// +// Parameters +// deviceHandle +// Device handle from add_device +// sdev +// reference to SPI_DEVICE_CONFIGURATION +// wrc +// reference to SPI_WRITE_READ_SETTINGS +// writeData +// A pointer to the buffer from which the data is to be written to the device. +// writeSize +// The number of elements(8 or 16) to be written. +// readData +// A pointer to the buffer into which the data is to be read from the device. +// readSize +// The number of elements(8 or 16) to be read. +// +// return S_OK=Successful, Async started=CLR_BUSY, Error=CLR_E_OUT_OF_MEMORY, CLR_E_INVALID_PARAMETER, CLR_E_FAIL +// + +// TODO The SPI driver in TI-RTOS doesn't handle the Chip select +// TODO This needs to be added to this driver +HRESULT CPU_SPI_nWrite_nRead( + uint32_t deviceHandle, + SPI_DEVICE_CONFIGURATION &sdev, + SPI_WRITE_READ_SETTINGS &wrc, + uint8_t *writeData, + int32_t writeSize, + uint8_t *readData, + int32_t readSize) +{ + (void)deviceHandle; + + NANOCLR_HEADER(); + { + unsigned char *readDataBuffer = NULL; + + GetSPIConfig(sdev, wrc); + + if (wrc.fullDuplex) + { + // we'll be doing this on a single transaction + SPI1_PAL.transactions = (SPI_Transaction *)platform_malloc(sizeof(SPI_Transaction)); + SPI1_PAL.transactionCount = 1; + } + else + { + // sequential io we need two transactions + SPI1_PAL.transactions = (SPI_Transaction *)platform_malloc(sizeof(SPI_Transaction) * 2); + SPI1_PAL.transactionCount = 2; + } + + // check allocation + if (SPI1_PAL.transactions == NULL) + { + NANOCLR_SET_AND_LEAVE(CLR_E_OUT_OF_MEMORY); + } + + if (writeSize) + { + // get the size of the buffer by reading the number of elements in the CLR_RT_HeapBlock_Array + SPI1_PAL.transactions[0].count = writeSize; + + // buffer data width is 8bit or 16bits + // get the pointer to the write buffer which is ptrs to UINT16 (2 bytes) or UINT8_t data + SPI1_PAL.transactions[0].txBuf = writeData; + } + + if (wrc.fullDuplex) + { + if (readSize) + { + // buffer data 16bit or 8bit data + SPI1_PAL.transactions[0].rxBuf = readData; + } + } + else + { + // on a sequential transmition we TX first and then RX as 2nd transaction + if (readSize) + { + // get the size of the buffer by reading the number of elements in the CLR_RT_HeapBlock_Array + SPI1_PAL.transactions[1].count = readSize; + SPI1_PAL.transactions[1].rxBuf = readData; + } + } + + // start transfer of 1st transaction + SPI_transfer(SPI1_PAL.masterSpi, &SPI1_PAL.transactions[0]); + + // take one from pending transcations counter + SPI1_PAL.transactionCount--; + + SPI1_PAL.status = SPI_OP_RUNNING; + + // Inform caller async operation started + NANOCLR_SET_AND_LEAVE(CLR_E_BUSY); + } + + NANOCLR_NOCLEANUP(); +} + +// Performs a read/write operation on 16-bit word data. +HRESULT CPU_SPI_nWrite16_nRead16( + uint32_t deviceHandle, + SPI_DEVICE_CONFIGURATION &sdev, + SPI_WRITE_READ_SETTINGS &swrs, + uint16_t *writePtr, + int32_t writeSize, + uint16_t *readPtr, + int32_t readSize) +{ + swrs.Bits16ReadWrite = true; + return CPU_SPI_nWrite_nRead(deviceHandle, sdev, swrs, (uint8_t *)writePtr, writeSize, (uint8_t *)readPtr, readSize); +} + +// Return status of current SPI operation +// Used to find status of an Async SPI call ( Not supported ), just return complete +SPI_OP_STATUS CPU_SPI_OP_STATUS(uint8_t spi_bus, uint32_t deviceHandle) +{ + (void)spi_bus; + (void)deviceHandle; + + return SPI1_PAL.status; +} + +// Return map of available SPI buses as a bit map +uint32_t CPU_SPI_PortsMap() +{ + // SPI1(0x01) + return 0x01; +} + +// Return SPI minimum clock frequency +uint32_t CPU_SPI_MinClockFrequency(uint32_t spi_bus) +{ + (void)spi_bus; + + // TODO check what is minimum ( min clock that can be configured on chip, master only) + return 10000000 / 256; +} + +// Return SPI maximum clock frequency +uint32_t CPU_SPI_MaxClockFrequency(uint32_t spi_bus) +{ + return 40000000; +} + +// +// Return the number of chip select lines available on the bus. +// TODO this still needs to be sorted as no CS handling +uint32_t CPU_SPI_ChipSelectLineCount(uint32_t spi_bus) +{ + (void)spi_bus; + + return 5; +} \ No newline at end of file diff --git a/targets/TI-SimpleLink/nanoCLR/Windows.Devices.Spi/win_dev_spi_native_Windows_Devices_Spi_SpiBusInfo.cpp b/targets/TI-SimpleLink/nanoCLR/Windows.Devices.Spi/win_dev_spi_native_Windows_Devices_Spi_SpiBusInfo.cpp deleted file mode 100644 index 7754a7e74f..0000000000 --- a/targets/TI-SimpleLink/nanoCLR/Windows.Devices.Spi/win_dev_spi_native_Windows_Devices_Spi_SpiBusInfo.cpp +++ /dev/null @@ -1,28 +0,0 @@ -// -// Copyright (c) 2017 The nanoFramework project contributors -// See LICENSE file in the project root for full license information. -// - - -#include "win_dev_spi_native_target.h" - - -HRESULT Library_win_dev_spi_native_Windows_Devices_Spi_SpiBusInfo::get_MaxClockFrequency___I4( CLR_RT_StackFrame& stack ) -{ - NANOCLR_HEADER(); - { - // return dummy value - stack.SetResult_I4 (0); - } - NANOCLR_NOCLEANUP_NOLABEL(); -} - -HRESULT Library_win_dev_spi_native_Windows_Devices_Spi_SpiBusInfo::get_MinClockFrequency___I4( CLR_RT_StackFrame& stack ) -{ - NANOCLR_HEADER(); - { - // return dummy value - stack.SetResult_I4 (0); - } - NANOCLR_NOCLEANUP_NOLABEL(); -} diff --git a/targets/TI-SimpleLink/nanoCLR/Windows.Devices.Spi/win_dev_spi_native_Windows_Devices_Spi_SpiController.cpp b/targets/TI-SimpleLink/nanoCLR/Windows.Devices.Spi/win_dev_spi_native_Windows_Devices_Spi_SpiController.cpp deleted file mode 100644 index ba60fb4107..0000000000 --- a/targets/TI-SimpleLink/nanoCLR/Windows.Devices.Spi/win_dev_spi_native_Windows_Devices_Spi_SpiController.cpp +++ /dev/null @@ -1,22 +0,0 @@ -// -// Copyright (c) 2018 The nanoFramework project contributors -// See LICENSE file in the project root for full license information. -// - - -#include "win_dev_spi_native_target.h" - - -HRESULT Library_win_dev_spi_native_Windows_Devices_Spi_SpiController::GetDeviceSelector___STATIC__STRING( CLR_RT_StackFrame& stack ) -{ - NANOCLR_HEADER(); - { - // declare the device selector string whose max size is "SPI1" + terminator and init with the terminator - char deviceSelectorString[] = { "SPI1" }; - - // because the caller is expecting a result to be returned - // we need set a return result in the stack argument using the appropriate SetResult according to the variable type (a string here) - stack.SetResult_String(deviceSelectorString); - } - NANOCLR_NOCLEANUP_NOLABEL(); -} diff --git a/targets/TI-SimpleLink/nanoCLR/Windows.Devices.Spi/win_dev_spi_native_Windows_Devices_Spi_SpiDevice.cpp b/targets/TI-SimpleLink/nanoCLR/Windows.Devices.Spi/win_dev_spi_native_Windows_Devices_Spi_SpiDevice.cpp deleted file mode 100644 index 85fdfd4675..0000000000 --- a/targets/TI-SimpleLink/nanoCLR/Windows.Devices.Spi/win_dev_spi_native_Windows_Devices_Spi_SpiDevice.cpp +++ /dev/null @@ -1,262 +0,0 @@ -// -// Copyright (c) 2017 The nanoFramework project contributors -// See LICENSE file in the project root for full license information. -// - - -#include -#include "win_dev_spi_native_target.h" - -// define this type here to make it shorter and improve code readability -typedef Library_win_dev_spi_native_Windows_Devices_Spi_SpiConnectionSettings SpiConnectionSettings; - - -///////////////////////////////////////////////////// -// SPI PAL strucs declared in win_dev_spi_native.h // -///////////////////////////////////////////////////// -NF_PAL_SPI SPI1_PAL; - - -void SpiCallback(SPI_Handle handle, SPI_Transaction *transaction) -{ - NATIVE_INTERRUPT_START - - // are there any other transactions pending? - if(SPI1_PAL.transactionCount) - { - // start transfer of 1st transaction - SPI_transfer(SPI1_PAL.masterSpi, &SPI1_PAL.transactions[SPI1_PAL.transactionCount--]); - } - else - { - // no more transactions - // fire event for SPI transaction complete - Events_Set( SYSTEM_EVENT_FLAG_SPI_MASTER ); - } - - NATIVE_INTERRUPT_END -} - -// Give a complete low-level SPI configuration from user's managed connectionSettings -void GetSPIConfig(int busIndex, CLR_RT_HeapBlock* config, bool bufferIs16bits) -{ - SPI_Params spiParams; - - // Open SPI as slave (default) - SPI_Params_init(&spiParams); - spiParams.frameFormat = (SPI_FrameFormat)config[ SpiConnectionSettings::FIELD___spiMode ].NumericByRef().s4; - spiParams.transferMode = SPI_MODE_CALLBACK; - spiParams.mode = SPI_SLAVE; - spiParams.transferCallbackFxn = SpiCallback; - spiParams.dataSize = bufferIs16bits ? 16 : 8; - spiParams.bitRate = (uint32_t)config[ SpiConnectionSettings::FIELD___clockFrequency ].NumericByRef().s4; - SPI1_PAL.masterSpi = SPI_open(Board_SPI_SLAVE, &spiParams); -} - -HRESULT Library_win_dev_spi_native_Windows_Devices_Spi_SpiDevice::NativeTransfer___VOID__SZARRAY_U1__SZARRAY_U1__BOOLEAN( CLR_RT_StackFrame& stack ) -{ - return NativeTransfer( stack, false ); -} - -HRESULT Library_win_dev_spi_native_Windows_Devices_Spi_SpiDevice::NativeTransfer___VOID__SZARRAY_U2__SZARRAY_U2__BOOLEAN( CLR_RT_StackFrame& stack ) -{ - return NativeTransfer( stack, true ); -} - -HRESULT Library_win_dev_spi_native_Windows_Devices_Spi_SpiDevice::NativeTransfer( CLR_RT_StackFrame& stack, bool bufferIs16bits ) -{ - NANOCLR_HEADER(); - { - bool fullDuplex; - - CLR_RT_HeapBlock hbTimeout; - CLR_INT64* timeout; - bool eventResult = true; - - // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); - - // get a pointer to the managed spi connectionSettings object instance - CLR_RT_HeapBlock* pConfig = pThis[ FIELD___connectionSettings ].Dereference(); - - // Are we using SPI full-duplex for transfer? - fullDuplex = (bool)stack.Arg3().NumericByRef().u1; - - // dereference the write and read buffers from the arguments - CLR_RT_HeapBlock_Array* writeBuffer = stack.Arg1().DereferenceArray(); - CLR_RT_HeapBlock_Array* readBuffer = stack.Arg2().DereferenceArray(); - - // set a timeout to an infinite timeout - // the catch is that the working thread MUST ALWAYS return at some point - // !! need to cast to CLR_INT64 otherwise it wont setup a proper timeout infinite - hbTimeout.SetInteger((CLR_INT64)-1); - - NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks( hbTimeout, timeout )); - - // protect the buffers from GC so DMA can find them where they are supposed to be - CLR_RT_ProtectFromGC gcWriteBuffer( *writeBuffer ); - CLR_RT_ProtectFromGC gcReadBuffer( *readBuffer ); - - // setup the operation and init buffers - if(stack.m_customState == 1) - { - // get the LL SPI configuration, depending on user's managed parameters and buffer element size - GetSPIConfig(0, pConfig, bufferIs16bits); // index '0' in this case is a dummy value... there is only one SPI available - - // alloc mem for transactions - if(fullDuplex) - { - // we'll be doing this on a single transaction - SPI1_PAL.transactions = (SPI_Transaction*)platform_malloc(sizeof(SPI_Transaction)); - SPI1_PAL.transactionCount = 1; - } - else - { - // we need two transactions - SPI1_PAL.transactions = (SPI_Transaction*)platform_malloc(sizeof(SPI_Transaction) * 2); - SPI1_PAL.transactionCount = 2; - } - - // check allocation - if(SPI1_PAL.transactions == NULL) - { - NANOCLR_SET_AND_LEAVE(CLR_E_OUT_OF_MEMORY); - } - else - { - if(fullDuplex) - { - if (writeBuffer != NULL) - { - // get the size of the buffer by reading the number of elements in the CLR_RT_HeapBlock_Array - SPI1_PAL.transactions[0].count = writeBuffer->m_numOfElements; - - // set DMA write buffer - if(bufferIs16bits) - { - // buffer data width is 16bits - // get the pointer to the write buffer as UINT16 because it's really an UINT16 (2 bytes) - SPI1_PAL.transactions[0].txBuf = (uint16_t*)writeBuffer->GetFirstElementUInt16(); - } - else - { - // buffer data width is 8bits - // get the pointer to the write buffer as BYTE - SPI1_PAL.transactions[0].txBuf = (uint8_t*)writeBuffer->GetFirstElement(); - } - } - - if (readBuffer != NULL) - { - // we are in full duplex, the count for the SPI transaction was already set on the write - - if(bufferIs16bits) - { - // buffer data width is 16bits - SPI1_PAL.transactions[0].rxBuf = (uint16_t*)readBuffer->GetFirstElementUInt16(); - } - else - { - // buffer data width is 8bits - // get the pointer to the read buffer as BYTE - SPI1_PAL.transactions[0].rxBuf = (uint8_t*)readBuffer->GetFirstElement(); - } - } - } - else - { - // on a sequential transmition we TX first and then RX - - // TX on 1st transaction - if (writeBuffer != NULL) - { - // get the size of the buffer by reading the number of elements in the CLR_RT_HeapBlock_Array - SPI1_PAL.transactions[0].count = writeBuffer->m_numOfElements; - - // set DMA write buffer - if(bufferIs16bits) - { - // buffer data width is 16bits - // get the pointer to the write buffer as UINT16 because it's really an UINT16 (2 bytes) - SPI1_PAL.transactions[0].txBuf = (uint16_t*)writeBuffer->GetFirstElementUInt16(); - } - else - { - // buffer data width is 8bits - // get the pointer to the write buffer as BYTE - SPI1_PAL.transactions[0].txBuf = (uint8_t*)writeBuffer->GetFirstElement(); - } - } - - // RX on 2nd transaction - if (readBuffer != NULL) - { - // get the size of the buffer by reading the number of elements in the CLR_RT_HeapBlock_Array - SPI1_PAL.transactions[1].count = readBuffer->m_numOfElements; - - if(bufferIs16bits) - { - // buffer data width is 16bits - SPI1_PAL.transactions[1].rxBuf = (uint16_t*)readBuffer->GetFirstElementUInt16(); - } - else - { - // buffer data width is 8bits - // get the pointer to the read buffer as BYTE - SPI1_PAL.transactions[1].rxBuf = (uint8_t*)readBuffer->GetFirstElement(); - } - } - } - - // start transfer of 1st transaction - SPI_transfer(SPI1_PAL.masterSpi, &SPI1_PAL.transactions[0]); - - // take one from pending transcations counter - SPI1_PAL.transactionCount--; - - // bump custom state - stack.m_customState = 2; - } - } - - while(eventResult) - { - // non-blocking wait allowing other threads to run while we wait for the Spi transaction to complete - NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.WaitEvents( stack.m_owningThread, *timeout, CLR_RT_ExecutionEngine::c_Event_SpiMaster, eventResult )); - - if(!eventResult) - { - // timeout occurred - NANOCLR_SET_AND_LEAVE(CLR_E_TIMEOUT); - } - } - - // pop timeout heap block from stack - stack.PopValue(); - - // null pointers and vars - pThis = NULL; - pConfig = NULL; - } - NANOCLR_NOCLEANUP(); -} - -HRESULT Library_win_dev_spi_native_Windows_Devices_Spi_SpiDevice::NativeInit___VOID( CLR_RT_StackFrame& stack ) -{ - (void)stack; - - NANOCLR_HEADER(); - - NANOCLR_NOCLEANUP(); -} - -HRESULT Library_win_dev_spi_native_Windows_Devices_Spi_SpiDevice::DisposeNative___VOID( CLR_RT_StackFrame& stack ) -{ - (void)stack; - - NANOCLR_HEADER(); - - SPI_close(SPI1_PAL.masterSpi); - - NANOCLR_NOCLEANUP_NOLABEL(); -} diff --git a/targets/TI-SimpleLink/nanoCLR/Windows.Devices.Spi/win_dev_spi_native_target.h b/targets/TI-SimpleLink/nanoCLR/Windows.Devices.Spi/win_dev_spi_native_target.h index 59a2c75894..85ed0273a0 100644 --- a/targets/TI-SimpleLink/nanoCLR/Windows.Devices.Spi/win_dev_spi_native_target.h +++ b/targets/TI-SimpleLink/nanoCLR/Windows.Devices.Spi/win_dev_spi_native_target.h @@ -1,9 +1,8 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // - #ifndef _WIN_DEV_SPI_NATIVE_TARGET_H_ #define _WIN_DEV_SPI_NATIVE_TARGET_H_ @@ -18,6 +17,8 @@ struct NF_PAL_SPI SPI_Params spiParams; SPI_Transaction* transactions; uint8_t transactionCount; + SPI_OP_STATUS status; + SPI_Callback callback; }; /////////////////////////////////////////// @@ -25,4 +26,4 @@ struct NF_PAL_SPI /////////////////////////////////////////// extern NF_PAL_SPI SPI1_PAL; -#endif //_WIN_DEV_SPI_NATIVE_TARGET_H_ +#endif //_WIN_DEV_SPI_NATIVE_TARGET_H_ diff --git a/targets/TI-SimpleLink/nanoCLR/WireProtocol_App_Interface.c b/targets/TI-SimpleLink/nanoCLR/WireProtocol_App_Interface.c index 21259693d8..64fa3d2ec3 100644 --- a/targets/TI-SimpleLink/nanoCLR/WireProtocol_App_Interface.c +++ b/targets/TI-SimpleLink/nanoCLR/WireProtocol_App_Interface.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/nanoCLR/WireProtocol_MonitorCommands.c b/targets/TI-SimpleLink/nanoCLR/WireProtocol_MonitorCommands.c index 74e05b66ff..c7a76457c3 100644 --- a/targets/TI-SimpleLink/nanoCLR/WireProtocol_MonitorCommands.c +++ b/targets/TI-SimpleLink/nanoCLR/WireProtocol_MonitorCommands.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/nanoCLR/nanoCRT.cpp b/targets/TI-SimpleLink/nanoCLR/nanoCRT.cpp index 45e1fa3ecb..3fcee4d9cd 100644 --- a/targets/TI-SimpleLink/nanoCLR/nanoCRT.cpp +++ b/targets/TI-SimpleLink/nanoCLR/nanoCRT.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/nanoCLR/nanoFramework.Hardware.TI/nf_hardware_ti_native.cpp b/targets/TI-SimpleLink/nanoCLR/nanoFramework.Hardware.TI/nf_hardware_ti_native.cpp new file mode 100644 index 0000000000..ad3f4b5ea4 --- /dev/null +++ b/targets/TI-SimpleLink/nanoCLR/nanoFramework.Hardware.TI/nf_hardware_ti_native.cpp @@ -0,0 +1,31 @@ +// +// Copyright (c) .NET Foundation and Contributors +// See LICENSE file in the project root for full license information. +// + +#include "nf_hardware_ti_native.h" + +// clang-format off + +static const CLR_RT_MethodHandler method_lookup[] = +{ + NULL, + NULL, + Library_nf_hardware_ti_native_nanoFramework_Hardware_TI_Power::ConfigureWakeupFromGpioPin___STATIC__VOID__SZARRAY_nanoFrameworkHardwareTIPowerPinWakeupConfig, + Library_nf_hardware_ti_native_nanoFramework_Hardware_TI_Power::get_SourceOfReset___STATIC__nanoFrameworkHardwareTIPowerResetSource, + Library_nf_hardware_ti_native_nanoFramework_Hardware_TI_Power::NativeEnterShutdownMode___STATIC__VOID, + Library_nf_hardware_ti_native_nanoFramework_Hardware_TI_Power::NativeEnterStandbyMode___STATIC__VOID__SystemTimeSpan, + NULL, + NULL, + Library_nf_hardware_ti_native_nanoFramework_Hardware_TI_Utilities::NativeGetIeeeAddress___STATIC__SZARRAY_U1, +}; + +const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_nanoFramework_Hardware_TI = +{ + "nanoFramework.Hardware.TI", + 0x8A9130A3, + method_lookup, + { 100, 0, 0, 3 } +}; + +// clang-format on diff --git a/targets/TI-SimpleLink/nanoCLR/nanoFramework.Hardware.TI/nf_hardware_ti_native.h b/targets/TI-SimpleLink/nanoCLR/nanoFramework.Hardware.TI/nf_hardware_ti_native.h new file mode 100644 index 0000000000..b72e5d952d --- /dev/null +++ b/targets/TI-SimpleLink/nanoCLR/nanoFramework.Hardware.TI/nf_hardware_ti_native.h @@ -0,0 +1,69 @@ +// +// Copyright (c) .NET Foundation and Contributors +// See LICENSE file in the project root for full license information. +// + +#ifndef _NF_HARDWARE_TI_NATIVE_H_ +#define _NF_HARDWARE_TI_NATIVE_H_ + +#include +#include +#include +#include + +#include +#include +#include +#include + +// clang-format off +#include DeviceFamily_constructPath(inc/hw_prcm.h) +#include DeviceFamily_constructPath(driverlib/sys_ctrl.h) +// clang-format on + +typedef enum __nfpack Power_PinPullUpDown +{ + Power_PinPullUpDown_None = 2147483648, + Power_PinPullUpDown_PullUp = 2147491840, + Power_PinPullUpDown_PullDown = 2147500032, +} Power_PinPullUpDown; + +typedef enum __nfpack Power_PinWakeupEdge +{ + Power_PinWakeupEdge_None = 0, + Power_PinWakeupEdge_PositiveEdge = 402653184, + Power_PinWakeupEdge_NegativeEdge = 268435456, +} Power_PinWakeupEdge; + +struct Library_nf_hardware_ti_native_nanoFramework_Hardware_TI_Power +{ + NANOCLR_NATIVE_DECLARE( + ConfigureWakeupFromGpioPin___STATIC__VOID__SZARRAY_nanoFrameworkHardwareTIPowerPinWakeupConfig); + NANOCLR_NATIVE_DECLARE(get_SourceOfReset___STATIC__nanoFrameworkHardwareTIPowerResetSource); + NANOCLR_NATIVE_DECLARE(NativeEnterShutdownMode___STATIC__VOID); + NANOCLR_NATIVE_DECLARE(NativeEnterStandbyMode___STATIC__VOID__SystemTimeSpan); + + //--// +}; + +struct Library_nf_hardware_ti_native_nanoFramework_Hardware_TI_Power__PinWakeupConfig +{ + static const int FIELD___pin = 1; + static const int FIELD___wakeupConfig = 2; + static const int FIELD___pinPullUpDown = 3; + + //--// +}; + +struct Library_nf_hardware_ti_native_nanoFramework_Hardware_TI_Utilities +{ + static const int FIELD_STATIC___deviceIeeeAddress = 0; + + NANOCLR_NATIVE_DECLARE(NativeGetIeeeAddress___STATIC__SZARRAY_U1); + + //--// +}; + +extern const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_nanoFramework_Hardware_TI; + +#endif //_NF_HARDWARE_TI_NATIVE_H_ diff --git a/targets/TI-SimpleLink/nanoCLR/nanoFramework.Hardware.TI/nf_hardware_ti_native_nanoFramework_Hardware_TI_Power.cpp b/targets/TI-SimpleLink/nanoCLR/nanoFramework.Hardware.TI/nf_hardware_ti_native_nanoFramework_Hardware_TI_Power.cpp new file mode 100644 index 0000000000..f7161a7872 --- /dev/null +++ b/targets/TI-SimpleLink/nanoCLR/nanoFramework.Hardware.TI/nf_hardware_ti_native_nanoFramework_Hardware_TI_Power.cpp @@ -0,0 +1,127 @@ +// +// Copyright (c) .NET Foundation and Contributors +// See LICENSE file in the project root for full license information. +// + +#include "nf_hardware_ti_native.h" + +// declare a shorter type to make code readable +typedef Library_nf_hardware_ti_native_nanoFramework_Hardware_TI_Power__PinWakeupConfig PinWakeupConfig; + +HRESULT Library_nf_hardware_ti_native_nanoFramework_Hardware_TI_Power:: + ConfigureWakeupFromGpioPin___STATIC__VOID__SZARRAY_nanoFrameworkHardwareTIPowerPinWakeupConfig( + CLR_RT_StackFrame &stack) +{ + NANOCLR_HEADER(); + + int32_t configCount; + int32_t index = 0; + PIN_Config *wakeupConfigurations = NULL; + CLR_RT_HeapBlock *pinWakeupConfig = NULL; + + CLR_RT_HeapBlock_Array *configArray = stack.Arg0().DereferenceArray(); + FAULT_ON_NULL(configArray); + + // how many configurations are in the array + configCount = configArray->m_numOfElements; + + if (configCount > 0) + { + // allocate config array + // need an extra position to store the "terminator" + wakeupConfigurations = (PIN_Config *)platform_malloc((configCount + 1) * sizeof(PIN_Config)); + + // check allocation + if (wakeupConfigurations != NULL) + { + // clear memory + memset(wakeupConfigurations, 0, configCount * sizeof(PIN_Config)); + + // build the array of configuration + while (index < configCount) + { + // get a pointer to the configuration + pinWakeupConfig = ((CLR_RT_HeapBlock *)configArray->GetElement(index))->Dereference(); + + // get pin number + wakeupConfigurations[index] = PIN_ID(pinWakeupConfig[PinWakeupConfig::FIELD___pin].NumericByRef().s4); + + // pin is always input + wakeupConfigurations[index] |= PIN_INPUT_EN; + + // grab and set pullup/down option + wakeupConfigurations[index] |= + (Power_PinPullUpDown)pinWakeupConfig[PinWakeupConfig::FIELD___pinPullUpDown].NumericByRef().u4; + + // grab and set wakeup option + wakeupConfigurations[index] |= + (Power_PinWakeupEdge)pinWakeupConfig[PinWakeupConfig::FIELD___wakeupConfig].NumericByRef().u4; + + // move to the next configuration element + index++; + } + + // add "terminator" to the array + wakeupConfigurations[index] = PIN_TERMINATE; + + // configure DIO for wakeup from shutdown + PINCC26XX_setWakeup(wakeupConfigurations); + + // done here, free memory + platform_free(wakeupConfigurations); + } + else + { + // failed to allocate memory + NANOCLR_SET_AND_LEAVE(CLR_E_OUT_OF_MEMORY); + } + } + + NANOCLR_NOCLEANUP(); +} + +HRESULT Library_nf_hardware_ti_native_nanoFramework_Hardware_TI_Power:: + get_SourceOfReset___STATIC__nanoFrameworkHardwareTIPowerResetSource(CLR_RT_StackFrame &stack) +{ + NANOCLR_HEADER(); + + stack.SetResult_U4(WakeupReasonStore); + + NANOCLR_NOCLEANUP(); +} + +HRESULT Library_nf_hardware_ti_native_nanoFramework_Hardware_TI_Power::NativeEnterShutdownMode___STATIC__VOID( + CLR_RT_StackFrame &stack) +{ + NANOCLR_HEADER(); + + Power_shutdown(0, 0); + + NANOCLR_NOCLEANUP(); +} + +HRESULT Library_nf_hardware_ti_native_nanoFramework_Hardware_TI_Power:: + NativeEnterStandbyMode___STATIC__VOID__SystemTimeSpan(CLR_RT_StackFrame &stack) +{ + NANOCLR_HEADER(); + + CLR_UINT64 standbyDurationMilsec; + + // debounceTimeout field its a TimeSpan, which is a primitive type stored as an heap block, therefore needs to + // be accessed indirectly + CLR_INT64 *standbyDuration = Library_corlib_native_System_TimeSpan::GetValuePtr(stack.Arg0()); + FAULT_ON_NULL(standbyDuration); + + standbyDurationMilsec = *(CLR_UINT64 *)standbyDuration / TIME_CONVERSION__TO_SECONDS; + + ClockP_sleep(standbyDurationMilsec); + + // need to reset the CPU after waking from standby + CPU_Reset(); + + ////////////////////////////////////// + // THE EXECUTION NEVER REACHES HERE // + ////////////////////////////////////// + + NANOCLR_NOCLEANUP(); +} diff --git a/targets/TI-SimpleLink/nanoCLR/nanoFramework.Hardware.TI/nf_hardware_ti_native_nanoFramework_Hardware_TI_Utilities.cpp b/targets/TI-SimpleLink/nanoCLR/nanoFramework.Hardware.TI/nf_hardware_ti_native_nanoFramework_Hardware_TI_Utilities.cpp new file mode 100644 index 0000000000..a280c829ee --- /dev/null +++ b/targets/TI-SimpleLink/nanoCLR/nanoFramework.Hardware.TI/nf_hardware_ti_native_nanoFramework_Hardware_TI_Utilities.cpp @@ -0,0 +1,28 @@ +// +// Copyright (c) .NET Foundation and Contributors +// See LICENSE file in the project root for full license information. +// + +#include "nf_hardware_ti_native.h" + +HRESULT Library_nf_hardware_ti_native_nanoFramework_Hardware_TI_Utilities::NativeGetIeeeAddress___STATIC__SZARRAY_U1( + CLR_RT_StackFrame &stack) +{ + NANOCLR_HEADER(); + + uint8_t *ieeeAddress; + + // create pointer to return object + CLR_RT_HeapBlock &top = stack.PushValueAndClear(); + + // dereference the byte array from the static field + NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_Array::CreateInstance(top, 8, g_CLR_RT_WellKnownTypes.m_UInt8)); + + ieeeAddress = top.DereferenceArray()->GetFirstElement(); + FAULT_ON_NULL(ieeeAddress); + + // OK to ignore return result because the only possible error is thrown on null pointer + EasyLink_getIeeeAddr(ieeeAddress); + + NANOCLR_NOCLEANUP(); +} diff --git a/targets/TI-SimpleLink/nanoCLR/nanoFramework.TI.EasyLink/nf_ti_easylink.cpp b/targets/TI-SimpleLink/nanoCLR/nanoFramework.TI.EasyLink/nf_ti_easylink.cpp index e8a386801c..e40f9b390b 100644 --- a/targets/TI-SimpleLink/nanoCLR/nanoFramework.TI.EasyLink/nf_ti_easylink.cpp +++ b/targets/TI-SimpleLink/nanoCLR/nanoFramework.TI.EasyLink/nf_ti_easylink.cpp @@ -1,10 +1,12 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // #include "nf_ti_easylink.h" +// clang-format off + static const CLR_RT_MethodHandler method_lookup[] = { NULL, @@ -32,6 +34,7 @@ static const CLR_RT_MethodHandler method_lookup[] = NULL, NULL, NULL, + NULL, Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController::GetConfiguration___U4__nanoFrameworkTIEasyLinkControlOption, NULL, NULL, @@ -41,17 +44,19 @@ static const CLR_RT_MethodHandler method_lookup[] = Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController::DisposeNative___VOID, Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController::UpdateRxAddressFilterNative___VOID, Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController::InitNative___U1, - Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController::ReceiveNative___U1__BYREF_nanoFrameworkTIEasyLinkReceivedPacket__I4, + Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController::ReceiveNative___U1__BYREF_nanoFrameworkTIEasyLinkReceivedPacket__SystemTimeSpan, Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController::SetConfigurationNative___U1__nanoFrameworkTIEasyLinkControlOption__U4, Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController::SetFrequencyNative___U1__U4, Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController::SetRfPowerNative___U1__I1, - Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController::TransmitNative___U1__nanoFrameworkTIEasyLinkTransmitPacket__I4__I4, + Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController::TransmitNative___U1__nanoFrameworkTIEasyLinkTransmitPacket__SystemTimeSpan__SystemTimeSpan, }; const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_nanoFramework_TI_EasyLink = { "nanoFramework.TI.EasyLink", - 0xEC93F5DE, + 0x948DBCF9, method_lookup, - { 100, 0, 0, 2 } + { 100, 0, 0, 3 } }; + +// clang-format on diff --git a/targets/TI-SimpleLink/nanoCLR/nanoFramework.TI.EasyLink/nf_ti_easylink.h b/targets/TI-SimpleLink/nanoCLR/nanoFramework.TI.EasyLink/nf_ti_easylink.h index 5c166ca5e5..5b95412f5f 100644 --- a/targets/TI-SimpleLink/nanoCLR/nanoFramework.TI.EasyLink/nf_ti_easylink.h +++ b/targets/TI-SimpleLink/nanoCLR/nanoFramework.TI.EasyLink/nf_ti_easylink.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // @@ -9,9 +9,14 @@ #include #include #include +#include +#include // TI-RTOS Header files #include +#include +#include +#include // Board Header files #include @@ -25,7 +30,6 @@ struct Library_nf_ti_easylink_nanoFramework_TI_EasyLink_TransmitPacket static const int FIELD___payload = 2; //--// - }; struct Library_nf_ti_easylink_nanoFramework_TI_EasyLink_ReceivedPacket @@ -37,7 +41,6 @@ struct Library_nf_ti_easylink_nanoFramework_TI_EasyLink_ReceivedPacket static const int FIELD___rxTimeout = 5; //--// - }; struct Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController @@ -57,18 +60,17 @@ struct Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController NANOCLR_NATIVE_DECLARE(DisposeNative___VOID); NANOCLR_NATIVE_DECLARE(UpdateRxAddressFilterNative___VOID); NANOCLR_NATIVE_DECLARE(InitNative___U1); - NANOCLR_NATIVE_DECLARE(ReceiveNative___U1__BYREF_nanoFrameworkTIEasyLinkReceivedPacket__I4); + NANOCLR_NATIVE_DECLARE(ReceiveNative___U1__BYREF_nanoFrameworkTIEasyLinkReceivedPacket__SystemTimeSpan); NANOCLR_NATIVE_DECLARE(SetConfigurationNative___U1__nanoFrameworkTIEasyLinkControlOption__U4); NANOCLR_NATIVE_DECLARE(SetFrequencyNative___U1__U4); NANOCLR_NATIVE_DECLARE(SetRfPowerNative___U1__I1); - NANOCLR_NATIVE_DECLARE(TransmitNative___U1__nanoFrameworkTIEasyLinkTransmitPacket__I4__I4); + NANOCLR_NATIVE_DECLARE(TransmitNative___U1__nanoFrameworkTIEasyLinkTransmitPacket__SystemTimeSpan__SystemTimeSpan); //--// - static HRESULT UpdateRxAddressFilter( CLR_RT_StackFrame& stack ); - + static HRESULT UpdateRxAddressFilter(CLR_RT_StackFrame &stack); }; extern const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_nanoFramework_TI_EasyLink; -#endif //_NF_TI_EASYLINK_H_ +#endif //_NF_TI_EASYLINK_H_ diff --git a/targets/TI-SimpleLink/nanoCLR/nanoFramework.TI.EasyLink/nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController.cpp b/targets/TI-SimpleLink/nanoCLR/nanoFramework.TI.EasyLink/nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController.cpp index 7c20081d5b..dc1898449b 100644 --- a/targets/TI-SimpleLink/nanoCLR/nanoFramework.TI.EasyLink/nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController.cpp +++ b/targets/TI-SimpleLink/nanoCLR/nanoFramework.TI.EasyLink/nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController.cpp @@ -1,15 +1,29 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // #include "nf_ti_easylink.h" +#include +#include typedef Library_nf_ti_easylink_nanoFramework_TI_EasyLink_TransmitPacket TransmitPacket; typedef Library_nf_ti_easylink_nanoFramework_TI_EasyLink_ReceivedPacket ReceivedPacket; +#define RADIO_EVENT_ALL 0xFFFFFFFF +#define RADIO_EVENT_TX_PACKET (uint32_t)(1 << 0) +#define RADIO_EVENT_RX (uint32_t)(1 << 1) +#define RADIO_EVENT_ABORT (uint32_t)(1 << 2) + static EasyLink_RxPacket latestRxPacket; +static EasyLink_TxPacket packetToTx; static EasyLink_Status latestOperationStatus; +static EasyLink_Params easyLink_params; + +// developer note: these are NOT static so they are visible during debug +Task_Struct easyLinkTask; +Event_Struct radioOperationEvent; +Event_Handle radioOperationEventHandle; // handler for TX operation done static void TxDone(EasyLink_Status status) @@ -22,7 +36,7 @@ static void TxDone(EasyLink_Status status) } // handler for RX operation done -static void RxDone(EasyLink_RxPacket* rxPacket, EasyLink_Status status) +static void RxDone(EasyLink_RxPacket *rxPacket, EasyLink_Status status) { // store status latestOperationStatus = status; @@ -38,7 +52,73 @@ static void RxDone(EasyLink_RxPacket* rxPacket, EasyLink_Status status) Events_Set(SYSTEM_EVENT_FLAG_RADIO); } -HRESULT Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController::get_AbsoluteTime___U4( CLR_RT_StackFrame& stack ) +// EasyLink Task +void EasyLinkTask(UArg arg0, UArg arg1) +{ + (void)arg0; + (void)arg1; + + // init EasyLink + latestOperationStatus = EasyLink_init(&easyLink_params); + + if (latestOperationStatus == EasyLink_Status_Success) + { + // EasyLink init successfull + // OK to proceed + + // fire CLR event + Events_Set(SYSTEM_EVENT_FLAG_RADIO); + + while (1) + { + // wait for RADIO events + uint32_t events = Event_pend(radioOperationEventHandle, 0, RADIO_EVENT_ALL, BIOS_WAIT_FOREVER); + + if (events & RADIO_EVENT_TX_PACKET) + { + // set priority for the transmission + EasyLink_setCtrl(EasyLink_Ctrl_Cmd_Priority, (uint32_t)EasyLink_Priority_Normal); + + // start async transmission + latestOperationStatus = EasyLink_transmitAsync(&packetToTx, TxDone); + + if (latestOperationStatus != EasyLink_Status_Success) + { + // something went wrong! + // fire CLR event + Events_Set(SYSTEM_EVENT_FLAG_RADIO); + } + } + + if (events & RADIO_EVENT_RX) + { + // start async receive + latestOperationStatus = EasyLink_receiveAsync(RxDone, 0); + + if (latestOperationStatus != EasyLink_Status_Success) + { + // something went wrong! + // fire CLR event + Events_Set(SYSTEM_EVENT_FLAG_RADIO); + } + } + + if (events & RADIO_EVENT_ABORT) + { + latestOperationStatus = EasyLink_abort(); + + // fire CLR event + Events_Set(SYSTEM_EVENT_FLAG_RADIO); + } + } + } + + // fire event for EasyLink abort completed + Events_Set(SYSTEM_EVENT_FLAG_RADIO); +} + +HRESULT Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController::get_AbsoluteTime___U4( + CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); @@ -46,7 +126,7 @@ HRESULT Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController::get uint32_t absoluteTime; status = EasyLink_getAbsTime(&absoluteTime); - if(status != EasyLink_Status_Success) + if (status != EasyLink_Status_Success) { NANOCLR_SET_AND_LEAVE(CLR_E_FAIL); } @@ -57,7 +137,7 @@ HRESULT Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController::get NANOCLR_NOCLEANUP(); } -HRESULT Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController::get_Rssi___I1( CLR_RT_StackFrame& stack ) +HRESULT Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController::get_Rssi___I1(CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); @@ -65,7 +145,7 @@ HRESULT Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController::get int8_t rssi; status = EasyLink_getRssi(&rssi); - if(status != EasyLink_Status_Success) + if (status != EasyLink_Status_Success) { NANOCLR_SET_AND_LEAVE(CLR_E_FAIL); } @@ -76,14 +156,15 @@ HRESULT Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController::get NANOCLR_NOCLEANUP(); } -HRESULT Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController::get_Frequency___U4( CLR_RT_StackFrame& stack ) +HRESULT Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController::get_Frequency___U4( + CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); uint32_t status; status = EasyLink_getFrequency(); - if(status == EasyLink_Status_Config_Error) + if (status == EasyLink_Status_Config_Error) { NANOCLR_SET_AND_LEAVE(CLR_E_FAIL); } @@ -94,7 +175,7 @@ HRESULT Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController::get NANOCLR_NOCLEANUP(); } -HRESULT Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController::get_RfPower___I1( CLR_RT_StackFrame& stack ) +HRESULT Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController::get_RfPower___I1(CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); @@ -102,7 +183,7 @@ HRESULT Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController::get int8_t power; status = EasyLink_getRfPower(&power); - if(status != EasyLink_Status_Success) + if (status != EasyLink_Status_Success) { NANOCLR_SET_AND_LEAVE(CLR_E_FAIL); } @@ -113,7 +194,8 @@ HRESULT Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController::get NANOCLR_NOCLEANUP(); } -HRESULT Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController::get_IeeeAddress___SZARRAY_U1( CLR_RT_StackFrame& stack ) +HRESULT Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController::get_IeeeAddress___SZARRAY_U1( + CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); @@ -122,19 +204,20 @@ HRESULT Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController::get NANOCLR_NOCLEANUP(); } -HRESULT Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController::GetConfiguration___U4__nanoFrameworkTIEasyLinkControlOption( CLR_RT_StackFrame& stack ) +HRESULT Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController:: + GetConfiguration___U4__nanoFrameworkTIEasyLinkControlOption(CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); EasyLink_Status status; - EasyLink_CtrlOption option; + EasyLink_CtrlOption option; uint32_t optionValue; // get control option from argument option = (EasyLink_CtrlOption)stack.Arg0().NumericByRef().u4; status = EasyLink_getCtrl(option, &optionValue); - if(status != EasyLink_Status_Success) + if (status != EasyLink_Status_Success) { NANOCLR_SET_AND_LEAVE(CLR_E_FAIL); } @@ -145,179 +228,290 @@ HRESULT Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController::Get NANOCLR_NOCLEANUP(); } -HRESULT Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController::DisposeNative___VOID( CLR_RT_StackFrame& stack ) +HRESULT Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController::DisposeNative___VOID( + CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); - (void)stack; + CLR_RT_HeapBlock hbTimeout; + CLR_INT64 *timeoutTicks; + CLR_INT32 timeout_ms; + bool eventResult = true; // stop any ongoing async operation that could be occurring // don't bother checking the return result - EasyLink_abort(); + + // set timeout + // !! need to cast to CLR_INT64 otherwise it wont setup a proper timeout infinite + hbTimeout.SetInteger((CLR_INT64)-1); + NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks(hbTimeout, timeoutTicks)); + + if (stack.m_customState == 1) + { + // bump custom state + stack.m_customState = 2; + } + + while (eventResult) + { + // non-blocking wait allowing other threads to run while we wait for the receive operation to complete + NANOCLR_CHECK_HRESULT( + g_CLR_RT_ExecutionEngine.WaitEvents(stack.m_owningThread, *timeoutTicks, Event_Radio, eventResult)); + + Task_destruct(&easyLinkTask); + + Event_destruct(&radioOperationEvent); + + if (eventResult) + { + // event occurred!! + } + else + { + // timeout occurred + // nothing else that can be done here + } + + // done here + break; + } + + // pop timeout heap block from stack + stack.PopValue(); NANOCLR_NOCLEANUP(); } -HRESULT Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController::UpdateRxAddressFilterNative___VOID( CLR_RT_StackFrame& stack ) +HRESULT Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController::UpdateRxAddressFilterNative___VOID( + CLR_RT_StackFrame &stack) { return UpdateRxAddressFilter(stack); } -HRESULT Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController::InitNative___U1( CLR_RT_StackFrame& stack ) +HRESULT Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController::InitNative___U1(CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); uint8_t i = 0; - EasyLink_Status status; EasyLink_PhyType phyType = (EasyLink_PhyType)0; - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + Task_Params taskParams; - // Initialize the EasyLink parameters to their default values - EasyLink_Params easyLink_params; - EasyLink_Params_init(&easyLink_params); + CLR_RT_HeapBlock hbTimeout; + CLR_INT64 *timeoutTicks; + CLR_INT32 timeout_ms; + bool eventResult = true; - // get managed Phy Type - phyType = (EasyLink_PhyType)(pThis[ FIELD___phyType ].NumericByRef().u1); + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + + // set timeout + // !! need to cast to CLR_INT64 otherwise it wont setup a proper timeout infinite + hbTimeout.SetInteger((CLR_INT64)-1); + NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks(hbTimeout, timeoutTicks)); - // check if this PHY config is supported - while(i < EasyLink_numSupportedPhys) + if (stack.m_customState == 1) { - if(EasyLink_supportedPhys[i].EasyLink_phyType == phyType) + // initialize the EasyLink parameters to their default values + EasyLink_Params_init(&easyLink_params); + + // get managed Phy Type + phyType = (EasyLink_PhyType)(pThis[FIELD___phyType].NumericByRef().u1); + + // check if this PHY config is supported + while (i < EasyLink_numSupportedPhys) { - break; + if (EasyLink_supportedPhys[i].EasyLink_phyType == phyType) + { + break; + } + i++; } - i++; - } - if(i == EasyLink_numSupportedPhys) - { - NANOCLR_SET_AND_LEAVE(CLR_E_NOT_SUPPORTED); - } + if (i == EasyLink_numSupportedPhys) + { + NANOCLR_SET_AND_LEAVE(CLR_E_NOT_SUPPORTED); + } + + easyLink_params.ui32ModType = phyType; + + // Create event used internally for state changes + Event_Params eventParam; + Event_Params_init(&eventParam); + Event_construct(&radioOperationEvent, &eventParam); + radioOperationEventHandle = Event_handle(&radioOperationEvent); + + // setup Task thread + Task_Params_init(&taskParams); + taskParams.stackSize = 1024; + taskParams.priority = 4; - easyLink_params.ui32ModType = phyType; + // create task + Task_construct(&easyLinkTask, EasyLinkTask, &taskParams, NULL); - // Initialize EasyLink - status = EasyLink_init(&easyLink_params); - if(status != EasyLink_Status_Success) + // bump custom state + stack.m_customState = 2; + } + + while (eventResult) { - // fail to start - stack.SetResult_U1(status); + // non-blocking wait allowing other threads to run while we wait for the receive operation to complete + NANOCLR_CHECK_HRESULT( + g_CLR_RT_ExecutionEngine.WaitEvents(stack.m_owningThread, *timeoutTicks, Event_Radio, eventResult)); - NANOCLR_SET_AND_LEAVE(S_OK); + if (eventResult) + { + // event occurred!! + if (latestOperationStatus == EasyLink_Status_Success) + { + // need to setup Rx address, if any is set + UpdateRxAddressFilter(stack); + } + } + else + { + // timeout occurred + // nothing else that can be done here + } + + // done here + break; } - latestOperationStatus = EasyLink_Status_Success; + // pop timeout heap block from stack + stack.PopValue(); - stack.SetResult_U1(status); + // return operation status + stack.SetResult_U1(latestOperationStatus); NANOCLR_NOCLEANUP(); } -HRESULT Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController::ReceiveNative___U1__BYREF_nanoFrameworkTIEasyLinkReceivedPacket__I4( CLR_RT_StackFrame& stack ) +HRESULT Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController:: + ReceiveNative___U1__BYREF_nanoFrameworkTIEasyLinkReceivedPacket__SystemTimeSpan(CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); - CLR_RT_TypeDef_Index receivedPacketTypeDef; - CLR_RT_HeapBlock_Array* buffer; - CLR_RT_HeapBlock rxTimeout; - CLR_RT_HeapBlock* packet; - CLR_RT_HeapBlock hbObj; + CLR_RT_TypeDef_Index receivedPacketTypeDef; + CLR_RT_HeapBlock_Array *buffer; + CLR_RT_HeapBlock rxTimeout; + CLR_RT_HeapBlock *packet; + CLR_RT_HeapBlock hbObj; - CLR_INT64* timeoutTicks; - CLR_INT32 timeout_ms; - EasyLink_Status status; - bool eventResult = true; + CLR_INT64 *timeoutDuration; + CLR_UINT64 timeoutMiliseconds; + CLR_INT64 *timeoutTicks; + bool eventResult = true; // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); - + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + // check disposed - if(pThis[ FIELD___disposed ].NumericByRef().u1 != 0) + if (pThis[FIELD___disposed].NumericByRef().u1 != 0) { - // don't throw if the execution has reached here from an aborted async operation - if( latestOperationStatus == EasyLink_Status_Aborted) - { - // return operation status - stack.SetResult_U1(latestOperationStatus); - - NANOCLR_SET_AND_LEAVE(S_OK); - } - else - { - // has to throw exception on all other situations - NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); - } + // has to throw exception on all other situations + NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); } - + // get value for timeout parameter - timeout_ms = stack.Arg2().NumericByRef().s4; + // timeout parameter its a TimeSpan, which is a primitive type stored as an heap block, therefore needs to + // be accessed indirectly + timeoutDuration = Library_corlib_native_System_TimeSpan::GetValuePtr(stack.Arg2()); + FAULT_ON_NULL(timeoutDuration); - // set timeout - rxTimeout.SetInteger( timeout_ms ); - NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks( rxTimeout, timeoutTicks )); + // check for .NET infinite timeout (-1) + if (*(CLR_UINT64 *)timeoutDuration == -1) + { + // "convert" to EasyLink infinite timeout + timeoutMiliseconds = 0; + } + else + { + timeoutMiliseconds = *(CLR_UINT64 *)timeoutDuration / TIME_CONVERSION__TO_MILLISECONDS; + } + + // set thread timeout + // wait forever because EasyLink timeout will make this work + rxTimeout.SetInteger((CLR_INT64)-1); + NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks(rxTimeout, timeoutTicks)); + + // set timeout for EasyLink, only required on the 1st pass + if (stack.m_customState == 1) + { + // EasyLink RX timeout + EasyLink_setCtrl(EasyLink_Ctrl_AsyncRx_TimeOut, EasyLink_ms_To_RadioTime(timeoutMiliseconds)); + } // setup the operation - if(stack.m_customState == 1) + if (stack.m_customState == 1) { // enter receive mode - status = EasyLink_receiveAsync(RxDone, 0); - if(status != EasyLink_Status_Success) - { - // fail to start - stack.SetResult_U1(status); - - NANOCLR_SET_AND_LEAVE(S_OK); - } + Event_post(radioOperationEventHandle, RADIO_EVENT_RX); // bump custom state stack.m_customState = 2; } - while(eventResult) + while (eventResult) { // non-blocking wait allowing other threads to run while we wait for the receive operation to complete - NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.WaitEvents( stack.m_owningThread, *timeoutTicks, CLR_RT_ExecutionEngine::c_Event_Radio, eventResult )); + NANOCLR_CHECK_HRESULT( + g_CLR_RT_ExecutionEngine.WaitEvents(stack.m_owningThread, *timeoutTicks, Event_Radio, eventResult)); // set to NULL and protect from GC - hbObj.SetObjectReference( NULL ); - CLR_RT_ProtectFromGC gc1( hbObj ); + hbObj.SetObjectReference(NULL); + CLR_RT_ProtectFromGC gc1(hbObj); - if(eventResult) + if (eventResult) { // event occurred!! - // check operation status - if( latestOperationStatus == EasyLink_Status_Success) + if (stack.m_customState == 2) { - // RX operation successful, OK to populate class - - // need to create ReceivedPacket object to return on "out" argument - // find type definition, don't bother checking the result as it exists for sure - g_CLR_RT_TypeSystem.FindTypeDef( "ReceivedPacket", "nanoFramework.TI.EasyLink", receivedPacketTypeDef ); - - // create instance of - NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.NewObjectFromIndex(hbObj, receivedPacketTypeDef)); - - // need to dereference to access class fields - packet = hbObj.Dereference(); - - // fill fields - packet[ ReceivedPacket::FIELD___rxTimeout ].NumericByRef().u4 = latestRxPacket.rxTimeout; - packet[ ReceivedPacket::FIELD___rssi ].NumericByRef().s1 = latestRxPacket.rssi; - packet[ ReceivedPacket::FIELD___absoluteTime ].NumericByRef().u4 = latestRxPacket.absTime; - - // address it's an array - NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_Array::CreateInstance( packet[ ReceivedPacket::FIELD___address ], (CLR_UINT32)ARRAYSIZE(latestRxPacket.dstAddr), g_CLR_RT_WellKnownTypes.m_UInt8 )); - buffer = packet[ ReceivedPacket::FIELD___address ].DereferenceArray(); - // copy address - memcpy(buffer->GetFirstElement(), latestRxPacket.dstAddr, ARRAYSIZE(latestRxPacket.dstAddr)); - - // payload it's an array - NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_Array::CreateInstance( packet[ ReceivedPacket::FIELD___payload ], (CLR_UINT32)ARRAYSIZE(latestRxPacket.payload), g_CLR_RT_WellKnownTypes.m_UInt8 )); - buffer = packet[ ReceivedPacket::FIELD___payload ].DereferenceArray(); - // copy payload content - memcpy(buffer->GetFirstElement(), latestRxPacket.payload, ARRAYSIZE(latestRxPacket.payload)); + // receive operation ongoing + + // check operation status + if (latestOperationStatus == EasyLink_Status_Success) + { + // RX operation successful, OK to populate class + + // need to create ReceivedPacket object to return on "out" argument + // find type definition, don't bother checking the result as it exists for sure + g_CLR_RT_TypeSystem.FindTypeDef( + "ReceivedPacket", + "nanoFramework.TI.EasyLink", + receivedPacketTypeDef); + + // create instance of + NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.NewObjectFromIndex(hbObj, receivedPacketTypeDef)); + + // need to dereference to access class fields + packet = hbObj.Dereference(); + + // fill fields + packet[ReceivedPacket::FIELD___rxTimeout].NumericByRef().u4 = latestRxPacket.rxTimeout; + packet[ReceivedPacket::FIELD___rssi].NumericByRef().s1 = latestRxPacket.rssi; + packet[ReceivedPacket::FIELD___absoluteTime].NumericByRef().u4 = latestRxPacket.absTime; + + // address it's an array + NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_Array::CreateInstance( + packet[ReceivedPacket::FIELD___address], + (CLR_UINT32)ARRAYSIZE(latestRxPacket.dstAddr), + g_CLR_RT_WellKnownTypes.m_UInt8)); + buffer = packet[ReceivedPacket::FIELD___address].DereferenceArray(); + // copy address + memcpy(buffer->GetFirstElement(), latestRxPacket.dstAddr, ARRAYSIZE(latestRxPacket.dstAddr)); + + // payload it's an array + NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_Array::CreateInstance( + packet[ReceivedPacket::FIELD___payload], + (CLR_UINT32)ARRAYSIZE(latestRxPacket.payload), + g_CLR_RT_WellKnownTypes.m_UInt8)); + buffer = packet[ReceivedPacket::FIELD___payload].DereferenceArray(); + // copy payload content + memcpy(buffer->GetFirstElement(), latestRxPacket.payload, ARRAYSIZE(latestRxPacket.payload)); + } } // done here @@ -327,28 +521,21 @@ HRESULT Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController::Rec { // timeout occurred - // stop ongoing RX async operation - // don't bother checking the return result - EasyLink_abort(); - - // set return - latestOperationStatus = EasyLink_Status_Aborted; - - // instead of throwing a timeout exception return OK - // the failure it's already on the return result - // done here - break; + break; } } - // sanity check - _ASSERTE(stack.Arg1().DataType() == DATATYPE_BYREF); + if (latestOperationStatus == EasyLink_Status_Success) + { + // sanity check + _ASSERTE(stack.Arg1().DataType() == DATATYPE_BYREF); - // packet it's passed as "out" meaning BYREF - // need to store the ReceivedPacket object in its reference - // hbObj it's either NULL or it's a properly formated ReceivedPacket object - NANOCLR_CHECK_HRESULT(hbObj.StoreToReference( stack.Arg1(), 0 )); + // packet it's passed as "out" meaning BYREF + // need to store the ReceivedPacket object in its reference + // hbObj it's either NULL or it's a properly formated ReceivedPacket object + NANOCLR_CHECK_HRESULT(hbObj.StoreToReference(stack.Arg1(), 0)); + } // pop timeout heap block from stack stack.PopValue(); @@ -359,12 +546,13 @@ HRESULT Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController::Rec NANOCLR_NOCLEANUP(); } -HRESULT Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController::SetConfigurationNative___U1__nanoFrameworkTIEasyLinkControlOption__U4( CLR_RT_StackFrame& stack ) +HRESULT Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController:: + SetConfigurationNative___U1__nanoFrameworkTIEasyLinkControlOption__U4(CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); EasyLink_Status status; - EasyLink_CtrlOption option; + EasyLink_CtrlOption option; uint32_t optionValue; // get control option @@ -379,7 +567,8 @@ HRESULT Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController::Set NANOCLR_NOCLEANUP(); } -HRESULT Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController::SetFrequencyNative___U1__U4( CLR_RT_StackFrame& stack ) +HRESULT Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController::SetFrequencyNative___U1__U4( + CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); @@ -390,14 +579,15 @@ HRESULT Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController::Set frequency = (uint16_t)stack.Arg0().NumericByRef().u4; status = EasyLink_setFrequency(frequency); - + // set result to the operation return status stack.SetResult_U1(status); NANOCLR_NOCLEANUP(); } -HRESULT Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController::SetRfPowerNative___U1__I1( CLR_RT_StackFrame& stack ) +HRESULT Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController::SetRfPowerNative___U1__I1( + CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); @@ -408,135 +598,150 @@ HRESULT Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController::Set power = (int8_t)stack.Arg0().NumericByRef().u1; status = EasyLink_setRfPower(power); - + // set result to the operation return status stack.SetResult_U1(status); NANOCLR_NOCLEANUP(); } -HRESULT Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController::TransmitNative___U1__nanoFrameworkTIEasyLinkTransmitPacket__I4__I4( CLR_RT_StackFrame& stack ) +HRESULT Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController:: + TransmitNative___U1__nanoFrameworkTIEasyLinkTransmitPacket__SystemTimeSpan__SystemTimeSpan(CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); - CLR_RT_HeapBlock_Array* payloadBuffer; - CLR_RT_HeapBlock_Array* address; - CLR_RT_HeapBlock txTimeout; - CLR_RT_HeapBlock* packet; + CLR_RT_HeapBlock_Array *payloadBuffer; + CLR_RT_HeapBlock_Array *address; + CLR_RT_HeapBlock txTimeout; + CLR_RT_HeapBlock *packet; - CLR_INT64* timeoutTicks; - CLR_INT32 timeout_ms; - uint32_t dueTime; - uint32_t absTime; - EasyLink_Status status; - EasyLink_TxPacket txPacket = { {0}, 0, 0, {0} }; - bool eventResult = true; + CLR_INT64 *timeoutDuration; + CLR_INT64 *dueTimeDuration; + CLR_UINT64 timeoutMiliseconds; + CLR_UINT64 dueTimeMiliseconds; + CLR_INT64 *timeoutTicks; + uint32_t absTime; + bool eventResult = true; // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); - + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); + // check disposed - if(pThis[ FIELD___disposed ].NumericByRef().u1 != 0) + if (pThis[FIELD___disposed].NumericByRef().u1 != 0) { - // don't throw if the execution has reached here from an aborted async operation - if( latestOperationStatus == EasyLink_Status_Aborted) - { - // return operation status - stack.SetResult_U1(latestOperationStatus); - - NANOCLR_SET_AND_LEAVE(S_OK); - } - else - { - // has to throw exception on all other situations - NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); - } + // has to throw exception on all other situations + NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); } // get value for timeout parameter - timeout_ms = stack.Arg2().NumericByRef().s4; + // timeout parameter its a TimeSpan, which is a primitive type stored as an heap block, therefore needs to + // be accessed indirectly + timeoutDuration = Library_corlib_native_System_TimeSpan::GetValuePtr(stack.Arg2()); + FAULT_ON_NULL(timeoutDuration); - // set timeout - txTimeout.SetInteger( timeout_ms ); + // check for .NET infinite timeout (-1) + if (*(CLR_UINT64 *)timeoutDuration == -1) + { + // "convert" to EasyLink infinite timeout + timeoutMiliseconds = 0; + } + else + { + timeoutMiliseconds = *(CLR_UINT64 *)timeoutDuration / TIME_CONVERSION__TO_MILLISECONDS; + } - NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks( txTimeout, timeoutTicks )); + // set timeout, if any + if (timeoutMiliseconds > 0) + { + // add 100ms to allow EasyLink timeout to occur before CLR thread timeout + txTimeout.SetInteger(timeoutMiliseconds + 100); + } + else + { + // no timeout so wait forever + txTimeout.SetInteger((CLR_INT64)-1); + } + NANOCLR_CHECK_HRESULT(stack.SetupTimeoutFromTicks(txTimeout, timeoutTicks)); // setup the operation and init buffers - if(stack.m_customState == 1) + if (stack.m_customState == 1) { // get pointer to managed TransmitPacket - packet = stack.Arg1().Dereference(); FAULT_ON_NULL(packet); + packet = stack.Arg1().Dereference(); + FAULT_ON_NULL(packet); + + // clear packet + memset(&packetToTx, 0, sizeof(EasyLink_TxPacket)); // dereference the payload buffer - payloadBuffer = packet[ TransmitPacket::FIELD___payload ].DereferenceArray(); + payloadBuffer = packet[TransmitPacket::FIELD___payload].DereferenceArray(); // get payload length - txPacket.len = payloadBuffer->m_numOfElements; + packetToTx.len = payloadBuffer->m_numOfElements; // copy buffer to packet - memcpy(txPacket.payload, payloadBuffer->GetFirstElement(), txPacket.len); + memcpy(packetToTx.payload, payloadBuffer->GetFirstElement(), packetToTx.len); // dereference the address buffer - address = packet[ TransmitPacket::FIELD___address ].DereferenceArray(); - - // get payload length - txPacket.len = payloadBuffer->m_numOfElements; + address = packet[TransmitPacket::FIELD___address].DereferenceArray(); // copy buffer to packet - memcpy(txPacket.dstAddr, address->GetFirstElement(), address->m_numOfElements); + memcpy(packetToTx.dstAddr, address->GetFirstElement(), address->m_numOfElements); + + // get dueTime managed parameter - // get dueTime managed argument - dueTime = stack.Arg3().NumericByRef().s4; + // dueTime parameter its a TimeSpan, which is a primitive type stored as an heap block, therefore needs to + // be accessed indirectly + dueTimeDuration = Library_corlib_native_System_TimeSpan::GetValuePtr(stack.Arg3()); + FAULT_ON_NULL(dueTimeDuration); - if(dueTime > 0) + dueTimeMiliseconds = *(CLR_UINT64 *)dueTimeDuration / TIME_CONVERSION__TO_MILLISECONDS; + + if (dueTimeMiliseconds > 0) { EasyLink_getAbsTime(&absTime); - txPacket.absTime = absTime + EasyLink_ms_To_RadioTime(dueTime); + packetToTx.absTime = absTime + EasyLink_ms_To_RadioTime(dueTimeMiliseconds); } - // start transmission - status = EasyLink_transmitAsync(&txPacket, TxDone); - if(status != EasyLink_Status_Success) - { - // fail to start - stack.SetResult_U1(status); + // set priority for the transmission + EasyLink_setCtrl(EasyLink_Ctrl_Cmd_Priority, (uint32_t)EasyLink_Priority_Normal); - NANOCLR_SET_AND_LEAVE(S_OK); - } + // signal event to start transmission + Event_post(radioOperationEventHandle, RADIO_EVENT_TX_PACKET); // bump custom state stack.m_customState = 2; } - while(eventResult) + while (eventResult) { // non-blocking wait allowing other threads to run while we wait for the transmit operation to complete - NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.WaitEvents( stack.m_owningThread, *timeoutTicks, CLR_RT_ExecutionEngine::c_Event_Radio, eventResult )); - - if(eventResult) + NANOCLR_CHECK_HRESULT( + g_CLR_RT_ExecutionEngine.WaitEvents(stack.m_owningThread, *timeoutTicks, Event_Radio, eventResult)); + + if (eventResult) { // event occurred - - // done here - break; } else { // timeout occurred - - // stop ongoing TX async operation - // don't bother checking the return result - EasyLink_abort(); - // set return - latestOperationStatus = EasyLink_Status_Aborted; + latestOperationStatus = EasyLink_Status_Tx_Error; - // instead of throwing a timeout exception return OK + // instead of throwing a timeout exception return OK // the failure it's already on the return result + } - // done here - break; + if ((latestOperationStatus != EasyLink_Status_Success) && (latestOperationStatus != EasyLink_Status_Aborted)) + { + // abort EasyLink operation + Event_post(radioOperationEventHandle, RADIO_EVENT_ABORT); } + + // done here + break; } // pop timeout heap block from stack @@ -547,40 +752,43 @@ HRESULT Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController::Tra NANOCLR_NOCLEANUP(); } -// To make it more efficient this processing is separated, making it reusable -HRESULT Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController::UpdateRxAddressFilter( CLR_RT_StackFrame& stack ) +// To make it more efficient this processing is separated, making it reusable +HRESULT Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController::UpdateRxAddressFilter( + CLR_RT_StackFrame &stack) { NANOCLR_HEADER(); - uint8_t* addressTable = NULL; - uint8_t* addressTableCursor = NULL; + uint8_t *addressTable = NULL; + uint8_t *addressTableCursor = NULL; uint8_t addressSize; // need to initialize these because they are passed by ref int addressCount = 0, capacity = 0; - CLR_RT_HeapBlock_Array* addressList = NULL; + CLR_RT_HeapBlock_Array *addressList = NULL; - CLR_RT_HeapBlock_Array* address; - CLR_RT_HeapBlock* addressField; + CLR_RT_HeapBlock_Array *address; + CLR_RT_HeapBlock *addressField; // get a pointer to the managed object instance and check that it's not NULL - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + CLR_RT_HeapBlock *pThis = stack.This(); + FAULT_ON_NULL(pThis); - addressField = &pThis[ FIELD___addressFilter ]; + addressField = &pThis[FIELD___addressFilter]; - NANOCLR_CHECK_HRESULT(CLR_RT_ArrayListHelper::ExtractArrayFromArrayList( *addressField, addressList, addressCount, capacity )); + NANOCLR_CHECK_HRESULT( + CLR_RT_ArrayListHelper::ExtractArrayFromArrayList(*addressField, addressList, addressCount, capacity)); - if(addressCount > 0) + if (addressCount > 0) { //... and size of the addressese (assuming that all of them, if any others, have the same length) - address = ((CLR_RT_HeapBlock_Array*)addressList->GetFirstElement())->DereferenceArray(); + address = ((CLR_RT_HeapBlock_Array *)addressList->GetFirstElement())->DereferenceArray(); addressSize = address->m_numOfElements; // allocate memory for the address table to be built - addressTable = (uint8_t*)platform_malloc( addressCount * addressSize ); - + addressTable = (uint8_t *)platform_malloc(addressCount * addressSize); + // sanity check - if( addressTable == NULL ) + if (addressTable == NULL) { // mem allocation failed NANOCLR_SET_AND_LEAVE(CLR_E_OUT_OF_MEMORY); @@ -591,10 +799,10 @@ HRESULT Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController::Upd // now loop through the collection to fill the table // have to use the items count and NOT the number of elements because that's the array list capacity - for(int i = 0; i < addressCount; i++) + for (int i = 0; i < addressCount; i++) { - address = ((CLR_RT_HeapBlock_Array*)addressList->GetElement(i))->DereferenceArray(); - if(address != NULL) + address = ((CLR_RT_HeapBlock_Array *)addressList->GetElement(i))->DereferenceArray(); + if (address != NULL) { memcpy(addressTableCursor, address->GetFirstElement(), addressSize); @@ -606,7 +814,7 @@ HRESULT Library_nf_ti_easylink_nanoFramework_TI_EasyLink_EasyLinkController::Upd EasyLink_enableRxAddrFilter(addressTable, addressCount, addressSize); } - if(addressTable != NULL) + if (addressTable != NULL) { platform_free(addressTable); } diff --git a/targets/TI-SimpleLink/nanoCLR/targetHAL.cpp b/targets/TI-SimpleLink/nanoCLR/targetHAL.cpp index 809a4c348a..7a32fd0ed0 100644 --- a/targets/TI-SimpleLink/nanoCLR/targetHAL.cpp +++ b/targets/TI-SimpleLink/nanoCLR/targetHAL.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // @@ -7,39 +7,55 @@ #include #include #include +#include #include #include // #include +#if (HAL_USE_I2C_OPTION == TRUE) +#include +#include +#endif +#if (HAL_USE_SPI_OPTION == TRUE) +#include +#include +#endif +#if (HAL_USE_SPI == ON) +#include +#endif + // // Reboot handlers clean up on reboot // -static ON_SOFT_REBOOT_HANDLER s_rebootHandlers[16] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; +static ON_SOFT_REBOOT_HANDLER s_rebootHandlers[16] = + {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; void HAL_AddSoftRebootHandler(ON_SOFT_REBOOT_HANDLER handler) { - for(unsigned int i=0; i 0) ? true : false; -} - -void SystemState_Set(SYSTEM_STATE_type state) -{ - GLOBAL_LOCK(); - - SystemState_SetNoLock(state); + CPU_GPIO_Uninitialize(); - GLOBAL_UNLOCK(); -} +#if (HAL_USE_I2C_OPTION == TRUE) + I2C_close(I2C1_PAL.i2c); +#endif -void SystemState_Clear(SYSTEM_STATE_type state) -{ - GLOBAL_LOCK(); +#if (HAL_USE_SPI_OPTION == TRUE) + SPI_close(SPI1_PAL.masterSpi); +#endif - SystemState_ClearNoLock(state ); - - GLOBAL_UNLOCK(); -} +#if (HAL_USE_EASYLINK == ON) + EasyLink_abort(); +#endif -bool SystemState_Query(SYSTEM_STATE_type state) -{ - GLOBAL_LOCK(); - - bool systemStateCopy = SystemState_QueryNoLock(state); - - GLOBAL_UNLOCK(); + Events_Uninitialize(); - return systemStateCopy; + HAL_CONTINUATION::Uninitialize(); + HAL_COMPLETION ::Uninitialize(); } diff --git a/targets/TI-SimpleLink/nanoCLR/targetHAL_Power.c b/targets/TI-SimpleLink/nanoCLR/targetHAL_Power.c index d4d53ef04c..1260ed88e9 100644 --- a/targets/TI-SimpleLink/nanoCLR/targetHAL_Power.c +++ b/targets/TI-SimpleLink/nanoCLR/targetHAL_Power.c @@ -1,18 +1,27 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // #include +uint32_t WakeupReasonStore; + // CPU sleep is not currently implemented in this target -inline void CPU_Sleep(SLEEP_LEVEL_type level, uint64_t wakeEvents){ (void)level; (void)wakeEvents; }; +inline void CPU_Sleep(SLEEP_LEVEL_type level, uint64_t wakeEvents) +{ + (void)level; + (void)wakeEvents; +}; -inline bool CPU_IsSoftRebootSupported() { return true; }; +inline bool CPU_IsSoftRebootSupported() +{ + return true; +}; void CPU_SetPowerMode(PowerLevel_type powerLevel) { - switch(powerLevel) + switch (powerLevel) { case PowerLevel__Off: // gracefully shutdown everything diff --git a/targets/TI-SimpleLink/nanoCLR/targetHAL_Time.cpp b/targets/TI-SimpleLink/nanoCLR/targetHAL_Time.cpp index 63cd53a562..d169212fe2 100644 --- a/targets/TI-SimpleLink/nanoCLR/targetHAL_Time.cpp +++ b/targets/TI-SimpleLink/nanoCLR/targetHAL_Time.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/nanoCLR/targetPAL.c b/targets/TI-SimpleLink/nanoCLR/targetPAL.c index 51da2f4993..1c5f99b465 100644 --- a/targets/TI-SimpleLink/nanoCLR/targetPAL.c +++ b/targets/TI-SimpleLink/nanoCLR/targetPAL.c @@ -1,13 +1,15 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // -#include +#include #include #include -extern UART_Handle uart; +#include + +extern UART2_Handle uart; SemaphoreP_Handle uartMutex; @@ -19,7 +21,8 @@ SemaphoreP_Handle uartMutex; void dummyFunction(void) __attribute__((used)); // Never called. -void dummyFunction(void) { +void dummyFunction(void) +{ vTaskSwitchContext(); localProgramStart(); } @@ -27,40 +30,42 @@ void dummyFunction(void) { // configure UART void ConfigUART() { - UART_Params uartParams; + UART2_Params uartParams; // Create a UART with data processing off - UART_Params_init(&uartParams); + UART2_Params_init(&uartParams); - uartParams.writeDataMode = UART_DATA_BINARY; - uartParams.readDataMode = UART_DATA_BINARY; - uartParams.readEcho = UART_ECHO_OFF; + uartParams.writeMode = UART2_Mode_BLOCKING; + uartParams.readMode = UART2_Mode_BLOCKING; uartParams.baudRate = 921600; + uartParams.readReturnMode = UART2_ReadReturnMode_FULL; - uart = UART_open(Board_UART0, &uartParams); + uart = UART2_open(UART0, &uartParams); if (uart == NULL) { // UART_open() failed - while (1); + while (1) + ; } uartMutex = SemaphoreP_createBinary(1); if (uartMutex == NULL) { // failed to create semaphore - while (1); - } + while (1) + ; + } } void __error__(char *pcFilename, unsigned long ulLine) { - // - // Something horrible happened! You need to look - // at file "pcFilename" at line "ulLine" to see - // what error is being reported. - // - while(1) - { - } + // + // Something horrible happened! You need to look + // at file "pcFilename" at line "ulLine" to see + // what error is being reported. + // + while (1) + { + } } diff --git a/targets/TI-SimpleLink/nanoCLR/targetPAL_Events.cpp b/targets/TI-SimpleLink/nanoCLR/targetPAL_Events.cpp index 4586c2848a..d0affd12df 100644 --- a/targets/TI-SimpleLink/nanoCLR/targetPAL_Events.cpp +++ b/targets/TI-SimpleLink/nanoCLR/targetPAL_Events.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // @@ -15,24 +15,12 @@ uint64_t CPU_MillisecondsToTicks(uint64_t ticks); // timer for bool events static Clock_Handle boolEventsTimer; -static bool* saveTimerCompleteFlag = 0; +static bool *saveTimerCompleteFlag = 0; -volatile uint32_t systemEvents; +static void local_Events_SetBoolTimer_Callback(UArg arg); -static void local_Events_SetBoolTimer_Callback( UArg arg ); - -set_Event_Callback g_Event_Callback = NULL; -void* g_Event_Callback_Arg = NULL; - -bool Events_Initialize() +bool Events_Initialize_Platform() { - NATIVE_PROFILE_PAL_EVENTS(); - - // init events - GLOBAL_LOCK(); - systemEvents = 0; - GLOBAL_UNLOCK(); - Clock_Params params; Clock_Params_init(¶ms); @@ -45,53 +33,14 @@ bool Events_Initialize() return true; } -bool Events_Uninitialize() +bool Events_Uninitialize_Platform() { - NATIVE_PROFILE_PAL_EVENTS(); - Clock_stop(boolEventsTimer); - - return true; -} - -void Events_Set( uint32_t events ) -{ - NATIVE_PROFILE_PAL_EVENTS(); - - // set events - GLOBAL_LOCK(); - systemEvents |= events; - GLOBAL_UNLOCK(); - - if( g_Event_Callback != NULL ) - { - g_Event_Callback( g_Event_Callback_Arg ); - } -} -uint32_t Events_Get( uint32_t eventsOfInterest ) -{ - NATIVE_PROFILE_PAL_EVENTS(); - - // get the requested flags from system events state and... - uint32_t returnEvents = (systemEvents & eventsOfInterest); - - // ... clear the requested flags atomically - GLOBAL_LOCK(); - systemEvents &= ~eventsOfInterest; - GLOBAL_UNLOCK(); - - // give the caller notice of just the events they asked for ( and were cleared already ) - return returnEvents; -} - -uint32_t Events_MaskedRead( uint32_t eventsOfInterest ) -{ - NATIVE_PROFILE_PAL_EVENTS(); - return (systemEvents & eventsOfInterest); + return true; } -static void local_Events_SetBoolTimer_Callback( UArg arg ) +static void local_Events_SetBoolTimer_Callback(UArg arg) { NATIVE_PROFILE_PAL_EVENTS(); @@ -100,63 +49,54 @@ static void local_Events_SetBoolTimer_Callback( UArg arg ) *saveTimerCompleteFlag = true; } -void Events_SetCallback( set_Event_Callback pfn, void* arg ) -{ - NATIVE_PROFILE_PAL_EVENTS(); - - g_Event_Callback = pfn; - g_Event_Callback_Arg = arg; -} - -void Events_SetBoolTimer( bool* timerCompleteFlag, uint32_t millisecondsFromNow ) +void Events_SetBoolTimer(bool *timerCompleteFlag, uint32_t millisecondsFromNow) { NATIVE_PROFILE_PAL_EVENTS(); // we assume only 1 can be active, abort previous just in case Clock_stop(boolEventsTimer); - if(timerCompleteFlag != NULL) + if (timerCompleteFlag != NULL) { // As only one timer running at a time we will just save it saveTimerCompleteFlag = timerCompleteFlag; - // need to convert from milliseconds to ticks - Clock_setPeriod(boolEventsTimer, millisecondsFromNow * (1000 / Clock_tickPeriod)); + Clock_setPeriod(boolEventsTimer, millisecondsFromNow); Clock_start(boolEventsTimer); } } -uint32_t Events_WaitForEvents( uint32_t powerLevel, uint32_t wakeupSystemEvents, uint32_t timeoutMilliseconds ) +uint32_t Events_WaitForEvents(uint32_t powerLevel, uint32_t wakeupSystemEvents, uint32_t timeoutMilliseconds) { // schedule an interrupt for this far in the future // timeout is in milliseconds, need to convert to ticks uint64_t countsRemaining = CPU_MillisecondsToTicks(timeoutMilliseconds); - #if defined(HAL_PROFILE_ENABLED) +#if defined(HAL_PROFILE_ENABLED) Events_WaitForEvents_Calls++; - #endif +#endif - uint64_t expireTimeInTicks = HAL_Time_CurrentSysTicks() + countsRemaining; + uint64_t expireTimeInTicks = HAL_Time_CurrentSysTicks() + countsRemaining; bool runContinuations = true; - while(true) + while (true) { EVENTS_HEART_BEAT; - uint32_t events = Events_MaskedRead( wakeupSystemEvents ); - if(events) + uint32_t events = Events_MaskedRead(wakeupSystemEvents); + if (events) { return events; } - if(expireTimeInTicks <= HAL_Time_CurrentSysTicks()) + if (expireTimeInTicks <= HAL_Time_CurrentSysTicks()) { break; } // first check and possibly run any continuations // but only if we have slept after stalling - if(runContinuations && !SystemState_QueryNoLock(SYSTEM_STATE_NO_CONTINUATIONS)) + if (runContinuations && !SystemState_QueryNoLock(SYSTEM_STATE_NO_CONTINUATIONS)) { // if we stall on time, don't check again until after we sleep runContinuations = HAL_CONTINUATION::Dequeue_And_Execute(); @@ -166,18 +106,18 @@ uint32_t Events_WaitForEvents( uint32_t powerLevel, uint32_t wakeupSystemEvents, // try stalled continuations again after sleeping runContinuations = true; - HAL_COMPLETION::WaitForInterrupts(expireTimeInTicks, powerLevel, wakeupSystemEvents ); + HAL_COMPLETION::WaitForInterrupts(expireTimeInTicks, powerLevel, wakeupSystemEvents); } // no events, pass control to the OS Task_yield(); - + // check if reboot or exit flags were set when the other OS threads executed - if(CLR_EE_DBG_IS(RebootPending) || CLR_EE_DBG_IS(ExitPending)) + if (CLR_EE_DBG_IS(RebootPending) || CLR_EE_DBG_IS(ExitPending)) { break; } - + // feed the watchdog... Watchdog_Reset(); } @@ -191,6 +131,6 @@ void FreeManagedEvent(uint8_t category, uint8_t subCategory, uint16_t data1, uin (void)subCategory; (void)data1; (void)data2; - + NATIVE_PROFILE_PAL_EVENTS(); } diff --git a/targets/TI-SimpleLink/nanoCLR/targetPAL_Time.cpp b/targets/TI-SimpleLink/nanoCLR/targetPAL_Time.cpp index 75b3cb0556..2e6ff7c2ba 100644 --- a/targets/TI-SimpleLink/nanoCLR/targetPAL_Time.cpp +++ b/targets/TI-SimpleLink/nanoCLR/targetPAL_Time.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // @@ -10,7 +10,7 @@ static Clock_Handle nextEventTimer; -static void NextEventTimer_Callback( UArg arg ) +static void NextEventTimer_Callback(UArg arg) { (void)arg; @@ -39,23 +39,23 @@ HRESULT Time_Uninitialize() return S_OK; } -void Time_SetCompare ( uint64_t compareValueTicks ) +void Time_SetCompare(uint64_t compareValueTicks) { - if(compareValueTicks == 0) + if (compareValueTicks == 0) { - // compare value is 0 so dequeue and schedule immediately + // compare value is 0 so dequeue and schedule immediately HAL_COMPLETION::DequeueAndExec(); } - else if(compareValueTicks == HAL_COMPLETION_IDLE_VALUE) + else if (compareValueTicks == HAL_COMPLETION_IDLE_VALUE) { // wait for infinity, don't need to do anything here return; - } + } else { - if (HAL_Time_CurrentSysTicks() >= compareValueTicks) - { - // already missed the event, dequeue and execute immediately + if (HAL_Time_CurrentSysTicks() >= compareValueTicks) + { + // already missed the event, dequeue and execute immediately HAL_COMPLETION::DequeueAndExec(); } else @@ -63,11 +63,11 @@ void Time_SetCompare ( uint64_t compareValueTicks ) // need to stop the timer, in case it's running Clock_stop(nextEventTimer); - // compareValueTicks is the time (in sys ticks) that is being requested to fire an HAL_COMPLETION::DequeueAndExec() - // need to subtract the current system time to set when the timer will fire + // compareValueTicks is the time (in sys ticks) that is being requested to fire an + // HAL_COMPLETION::DequeueAndExec() need to subtract the current system time to set when the timer will fire compareValueTicks -= HAL_Time_CurrentSysTicks(); - - if (compareValueTicks == 0) + + if (compareValueTicks == 0) { // compare value is 0 so dequeue and execute immediately // no need to call the timer @@ -75,7 +75,8 @@ void Time_SetCompare ( uint64_t compareValueTicks ) return; } - Clock_setPeriod(nextEventTimer, compareValueTicks); + // need to convert from milliseconds to ticks + Clock_setPeriod(nextEventTimer, compareValueTicks / Clock_tickPeriod); Clock_start(nextEventTimer); } } diff --git a/targets/TI-SimpleLink/nanoCLR/targetSimpleLinkCC32xx_LinkLocalTask.c b/targets/TI-SimpleLink/nanoCLR/targetSimpleLinkCC32xx_LinkLocalTask.c index 58e2f7cb60..848ba1468e 100644 --- a/targets/TI-SimpleLink/nanoCLR/targetSimpleLinkCC32xx_LinkLocalTask.c +++ b/targets/TI-SimpleLink/nanoCLR/targetSimpleLinkCC32xx_LinkLocalTask.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Texas Instruments Incorporated. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/nanoCLR/targetSimpleLinkCC32xx_ProvisioningTask.c b/targets/TI-SimpleLink/nanoCLR/targetSimpleLinkCC32xx_ProvisioningTask.c index 5342272461..1eaaa2a43e 100644 --- a/targets/TI-SimpleLink/nanoCLR/targetSimpleLinkCC32xx_ProvisioningTask.c +++ b/targets/TI-SimpleLink/nanoCLR/targetSimpleLinkCC32xx_ProvisioningTask.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Texas Instruments Incorporated. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/nanoCLR/targetSimpleLinkCC32xx_Sntp.c b/targets/TI-SimpleLink/nanoCLR/targetSimpleLinkCC32xx_Sntp.c index da138f8b54..789a7cbaba 100644 --- a/targets/TI-SimpleLink/nanoCLR/targetSimpleLinkCC32xx_Sntp.c +++ b/targets/TI-SimpleLink/nanoCLR/targetSimpleLinkCC32xx_Sntp.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Texas Instruments Incorporated. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/nanoCLR/targetSimpleLinkCC32xx_Threads.c b/targets/TI-SimpleLink/nanoCLR/targetSimpleLinkCC32xx_Threads.c index b99b924a51..7db4b20cc8 100644 --- a/targets/TI-SimpleLink/nanoCLR/targetSimpleLinkCC32xx_Threads.c +++ b/targets/TI-SimpleLink/nanoCLR/targetSimpleLinkCC32xx_Threads.c @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Texas Instruments Incorporated. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/TI-SimpleLink/nanoCLR/target_platform.h.in b/targets/TI-SimpleLink/nanoCLR/target_platform.h.in index bfb0d3ebdf..55e70ecb0e 100644 --- a/targets/TI-SimpleLink/nanoCLR/target_platform.h.in +++ b/targets/TI-SimpleLink/nanoCLR/target_platform.h.in @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // @@ -11,7 +11,19 @@ #ifndef _TARGET_TI_SIMPLELINK_NANOCLR_H_ #define _TARGET_TI_SIMPLELINK_NANOCLR_H_ +// enable SPI +#define HAL_USE_SPI @HAL_USE_SPI_OPTION@ + // enable SNTP app #define SL_APP_SNTP @NF_NETWORKING_SNTP@ +// enable I2C +#define HAL_USE_I2C @HAL_USE_I2C_OPTION@ + +// enable SPI +#define HAL_USE_SPI @HAL_USE_SPI_OPTION@ + +// enable EasyLink +#define HAL_USE_EASYLINK @API_nanoFramework.TI.EasyLink@ + #endif /* _TARGET_TI_SIMPLELINK_NANOCLR_H_ */ diff --git a/targets/os/win32/Include/TargetHAL_Spi.h b/targets/os/win32/Include/TargetHAL_Spi.h new file mode 100644 index 0000000000..975489e00a --- /dev/null +++ b/targets/os/win32/Include/TargetHAL_Spi.h @@ -0,0 +1,16 @@ +// +// Copyright (c) .NET Foundation and Contributors +// See LICENSE file in the project root for full license information. +// + +#ifndef _TARGET_HAL_SPI_H_ +#define _TARGET_HAL_SPI_H_ 1 + + +// # of buses +#define NUM_SPI_BUSES 0 + +// Maximum number of devices per SPI bus +#define MAX_SPI_DEVICES 5 + +#endif //_TARGET_HAL_SPI_H_ diff --git a/targets/os/win32/Include/TargetPAL_BlockStorage.h b/targets/os/win32/Include/TargetPAL_BlockStorage.h index c18cb8086c..1b9fe002c8 100644 --- a/targets/os/win32/Include/TargetPAL_BlockStorage.h +++ b/targets/os/win32/Include/TargetPAL_BlockStorage.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/os/win32/Include/Target_Windows_Storage.h b/targets/os/win32/Include/Target_Windows_Storage.h index 888c34fef1..43f7367e2c 100644 --- a/targets/os/win32/Include/Target_Windows_Storage.h +++ b/targets/os/win32/Include/Target_Windows_Storage.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/os/win32/Include/targetHAL.h b/targets/os/win32/Include/targetHAL.h index 287b1d37fd..9338e0b8cd 100644 --- a/targets/os/win32/Include/targetHAL.h +++ b/targets/os/win32/Include/targetHAL.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // @@ -8,26 +8,29 @@ // #include +// set min possible number of sockets +#define PLATFORM_DEPENDENT__SOCKETS_MAX_COUNT 1 + #if defined(_WIN32) #define NANOCLR_STOP() ::DebugBreak() -#pragma warning( error : 4706 ) // error C4706: assignment within conditional expression +#pragma warning(error : 4706) // error C4706: assignment within conditional expression #endif #if !defined(BUILD_RTM) inline void __cdecl HARD_Breakpoint() { - if(::IsDebuggerPresent()) + if (::IsDebuggerPresent()) { ::DebugBreak(); } } -#define HARD_BREAKPOINT() HARD_Breakpoint() +#define HARD_BREAKPOINT() HARD_Breakpoint() inline bool Target_ConfigUpdateRequiresErase() -{ - return true; +{ + return true; } // #if defined(_DEBUG) @@ -41,19 +44,21 @@ inline bool Target_ConfigUpdateRequiresErase() // #define HARD_BREAKPOINT() // #define DEBUG_HARD_BREAKPOINT() -#endif // !defined(BUILD_RTM) - +#endif // !defined(BUILD_RTM) -inline bool Target_HasNanoBooter() { return false; }; +inline bool Target_HasNanoBooter() +{ + return false; +}; inline uint32_t GetPlatformCapabilities() -{ - return 0; +{ + return 0; }; inline uint32_t GetTargetCapabilities() { - return 0; + return 0; }; #endif //_TARGET_HAL_H_ diff --git a/targets/os/win32/Include/targetHAL_Power.h b/targets/os/win32/Include/targetHAL_Power.h index 30060ef3aa..d03023431a 100644 --- a/targets/os/win32/Include/targetHAL_Power.h +++ b/targets/os/win32/Include/targetHAL_Power.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/os/win32/Include/targetHAL_Time.h b/targets/os/win32/Include/targetHAL_Time.h index 0c580877d7..e4feeb8e52 100644 --- a/targets/os/win32/Include/targetHAL_Time.h +++ b/targets/os/win32/Include/targetHAL_Time.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/os/win32/Include/targetPAL_time.h b/targets/os/win32/Include/targetPAL_time.h index 5e999482a5..7737787746 100644 --- a/targets/os/win32/Include/targetPAL_time.h +++ b/targets/os/win32/Include/targetPAL_time.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/os/win32/Include/target_BlockStorage.h b/targets/os/win32/Include/target_BlockStorage.h index aa50b1b7f2..8a56d0eee0 100644 --- a/targets/os/win32/Include/target_BlockStorage.h +++ b/targets/os/win32/Include/target_BlockStorage.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/os/win32/nanoCLR/CLRStartup.cpp b/targets/os/win32/nanoCLR/CLRStartup.cpp index cefd8d66df..b82826eddb 100644 --- a/targets/os/win32/nanoCLR/CLRStartup.cpp +++ b/targets/os/win32/nanoCLR/CLRStartup.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/os/win32/nanoCLR/Events.cpp b/targets/os/win32/nanoCLR/Events.cpp index 32da6a6740..d879048e3f 100644 --- a/targets/os/win32/nanoCLR/Events.cpp +++ b/targets/os/win32/nanoCLR/Events.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/os/win32/nanoCLR/FileStore_Win32.cpp b/targets/os/win32/nanoCLR/FileStore_Win32.cpp index 9dea424ac5..cd8f22129b 100644 --- a/targets/os/win32/nanoCLR/FileStore_Win32.cpp +++ b/targets/os/win32/nanoCLR/FileStore_Win32.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/os/win32/nanoCLR/Memory.cpp b/targets/os/win32/nanoCLR/Memory.cpp index 9cd138e3ed..a173199cb4 100644 --- a/targets/os/win32/nanoCLR/Memory.cpp +++ b/targets/os/win32/nanoCLR/Memory.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/os/win32/nanoCLR/PAL/COMDirector_stubs.cpp b/targets/os/win32/nanoCLR/PAL/COMDirector_stubs.cpp index 73ba695c09..1a69e034a4 100644 --- a/targets/os/win32/nanoCLR/PAL/COMDirector_stubs.cpp +++ b/targets/os/win32/nanoCLR/PAL/COMDirector_stubs.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/os/win32/nanoCLR/PAL/ConfigHelper_stubs.cpp b/targets/os/win32/nanoCLR/PAL/ConfigHelper_stubs.cpp index bf4258b0fd..1b56bd8371 100644 --- a/targets/os/win32/nanoCLR/PAL/ConfigHelper_stubs.cpp +++ b/targets/os/win32/nanoCLR/PAL/ConfigHelper_stubs.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/os/win32/nanoCLR/PAL/Target_BlockStorage.cpp b/targets/os/win32/nanoCLR/PAL/Target_BlockStorage.cpp index 3d7d734907..ee28a6f545 100644 --- a/targets/os/win32/nanoCLR/PAL/Target_BlockStorage.cpp +++ b/targets/os/win32/nanoCLR/PAL/Target_BlockStorage.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/os/win32/nanoCLR/PAL/Watchdog_stubs.cpp b/targets/os/win32/nanoCLR/PAL/Watchdog_stubs.cpp index 3c5522ad98..ddd227ee64 100644 --- a/targets/os/win32/nanoCLR/PAL/Watchdog_stubs.cpp +++ b/targets/os/win32/nanoCLR/PAL/Watchdog_stubs.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/os/win32/nanoCLR/PAL/blockstorageList_stubs.cpp b/targets/os/win32/nanoCLR/PAL/blockstorageList_stubs.cpp index 63eefb00db..49b010e156 100644 --- a/targets/os/win32/nanoCLR/PAL/blockstorageList_stubs.cpp +++ b/targets/os/win32/nanoCLR/PAL/blockstorageList_stubs.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/os/win32/nanoCLR/PAL/time_stubs.cpp b/targets/os/win32/nanoCLR/PAL/time_stubs.cpp index db7097523d..33b70df13a 100644 --- a/targets/os/win32/nanoCLR/PAL/time_stubs.cpp +++ b/targets/os/win32/nanoCLR/PAL/time_stubs.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/os/win32/nanoCLR/ParseOptions_Win32.cpp b/targets/os/win32/nanoCLR/ParseOptions_Win32.cpp index a4e31d4d99..3de1907036 100644 --- a/targets/os/win32/nanoCLR/ParseOptions_Win32.cpp +++ b/targets/os/win32/nanoCLR/ParseOptions_Win32.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/os/win32/nanoCLR/Target_BlockStorage.cpp b/targets/os/win32/nanoCLR/Target_BlockStorage.cpp index 4384d8fd59..2daec6ca08 100644 --- a/targets/os/win32/nanoCLR/Target_BlockStorage.cpp +++ b/targets/os/win32/nanoCLR/Target_BlockStorage.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/os/win32/nanoCLR/Various.cpp b/targets/os/win32/nanoCLR/Various.cpp index 331eff9050..4b21e58453 100644 --- a/targets/os/win32/nanoCLR/Various.cpp +++ b/targets/os/win32/nanoCLR/Various.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/os/win32/nanoCLR/WatchDog.cpp b/targets/os/win32/nanoCLR/WatchDog.cpp index 9303b20e20..71a108fe74 100644 --- a/targets/os/win32/nanoCLR/WatchDog.cpp +++ b/targets/os/win32/nanoCLR/WatchDog.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/os/win32/nanoCLR/Windows.Devices.Gpio/cpu_gpio.cpp b/targets/os/win32/nanoCLR/Windows.Devices.Gpio/cpu_gpio.cpp index 08572e4a49..848af654a3 100644 --- a/targets/os/win32/nanoCLR/Windows.Devices.Gpio/cpu_gpio.cpp +++ b/targets/os/win32/nanoCLR/Windows.Devices.Gpio/cpu_gpio.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2019 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/os/win32/nanoCLR/Windows.Devices.Gpio/win_dev_gpio_native.cpp b/targets/os/win32/nanoCLR/Windows.Devices.Gpio/win_dev_gpio_native.cpp index a81fb0a8eb..feafe66ec2 100644 --- a/targets/os/win32/nanoCLR/Windows.Devices.Gpio/win_dev_gpio_native.cpp +++ b/targets/os/win32/nanoCLR/Windows.Devices.Gpio/win_dev_gpio_native.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/os/win32/nanoCLR/Windows.Devices.Gpio/win_dev_gpio_native.h b/targets/os/win32/nanoCLR/Windows.Devices.Gpio/win_dev_gpio_native.h index 5b795fbbd4..8071dd64b0 100644 --- a/targets/os/win32/nanoCLR/Windows.Devices.Gpio/win_dev_gpio_native.h +++ b/targets/os/win32/nanoCLR/Windows.Devices.Gpio/win_dev_gpio_native.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/os/win32/nanoCLR/Windows.Devices.Gpio/win_dev_gpio_native_Windows_Devices_Gpio_GpioController.cpp b/targets/os/win32/nanoCLR/Windows.Devices.Gpio/win_dev_gpio_native_Windows_Devices_Gpio_GpioController.cpp index d97752d46d..2e116443df 100644 --- a/targets/os/win32/nanoCLR/Windows.Devices.Gpio/win_dev_gpio_native_Windows_Devices_Gpio_GpioController.cpp +++ b/targets/os/win32/nanoCLR/Windows.Devices.Gpio/win_dev_gpio_native_Windows_Devices_Gpio_GpioController.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/os/win32/nanoCLR/Windows.Devices.Gpio/win_dev_gpio_native_Windows_Devices_Gpio_GpioPin.cpp b/targets/os/win32/nanoCLR/Windows.Devices.Gpio/win_dev_gpio_native_Windows_Devices_Gpio_GpioPin.cpp index 7ffbd96827..9af580328e 100644 --- a/targets/os/win32/nanoCLR/Windows.Devices.Gpio/win_dev_gpio_native_Windows_Devices_Gpio_GpioPin.cpp +++ b/targets/os/win32/nanoCLR/Windows.Devices.Gpio/win_dev_gpio_native_Windows_Devices_Gpio_GpioPin.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/os/win32/nanoCLR/Windows.Devices.Spi/cpu_spi.cpp b/targets/os/win32/nanoCLR/Windows.Devices.Spi/cpu_spi.cpp new file mode 100644 index 0000000000..8f5db1175c --- /dev/null +++ b/targets/os/win32/nanoCLR/Windows.Devices.Spi/cpu_spi.cpp @@ -0,0 +1,100 @@ +// +// Copyright (c) .NET Foundation and Contributors +// Portions Copyright (c) Microsoft Corporation. All rights reserved. +// See LICENSE file in the project root for full license information. +// +// +// CPU_SPI_xxxx +// +// Read / Write physical SPI bus +// + +#include +#include +#include +#include + + +// Remove device from bus +// return true of OK, false = error +bool CPU_SPI_Remove_Device(uint32_t deviceHandle) +{ + return spi_bus_remove_device((spi_device_handle_t)deviceHandle) != ESP_OK; +} +// Performs a read/write operation on 8-bit word data. +// +// Parameters +// deviceHandle +// Device handle from add_device +// sdev +// reference to SPI_DEVICE_CONFIGURATION +// wrc +// reference to SPI_WRITE_READ_SETTINGS +// writeData +// A pointer to the buffer from which the data is to be written to the device. +// writeSize +// The number of elements(8 or 16) to be written. +// readData +// A pointer to the buffer into which the data is to be read from the device. +// readSize +// The number of elements(8 or 16) to be read. +// +// return S_OK=Successful, Async started=CLR_BUSY, Error=CLR_E_OUT_OF_MEMORY, CLR_E_INVALID_PARAMETER, CLR_E_FAIL +// +HRESULT CPU_SPI_nWrite_nRead(uint32_t deviceHandle, SPI_DEVICE_CONFIGURATION & sdev, SPI_WRITE_READ_SETTINGS & wrc, uint8_t* writeData, int32_t writeSize, uint8_t* readData, int32_t readSize) +{ + (void)deviceHandle; + (void)sdev; + (void)wrc; + (void)writeData; + (void)writeSize; + (void)readData; + (void)readSize; + + return CLR_E_FAIL; +} + +// Performs a read/write operation on 16-bit word data. +HRESULT CPU_SPI_nWrite16_nRead16(uint32_t deviceHandle, SPI_DEVICE_CONFIGURATION & sdev, SPI_WRITE_READ_SETTINGS & swrs, uint16_t * writePtr, int32_t writeSize, uint16_t * readPtr, int32_t readSize) +{ + swrs.Bits16ReadWrite = true; + return CPU_SPI_nWrite_nRead(deviceHandle, sdev, swrs, (uint8_t *)writePtr, writeSize, (uint8_t *)readPtr, readSize); +} + +// Return map of available SPI buses as a bit map +uint32_t CPU_SPI_PortsMap() +{ + return 0x00; +} + +// Returns the SPI clock, MISO and MOSI pin numbers for a specified SPI module. +void CPU_SPI_GetPins( uint32_t spi_bus, GPIO_PIN& clockPin, GPIO_PIN& misoPin, GPIO_PIN& mosiPin ) +{ + clockPin = -1; + misoPin = -1; + mosiPin = -1; +} + +// Return SPI minimum clock frequency +uint32_t CPU_SPI_MinClockFrequency( uint32_t spi_bus ) +{ + (void)spi_bus; + + return 0; +} + +// Return SPI maximum clock frequency + +uint32_t CPU_SPI_MaxClockFrequency( uint32_t spi_bus ) +{ + return 1000000; +} + +// +// Return the number of chip select lines available on the bus. +uint32_t CPU_SPI_ChipSelectLineCount(uint32_t spi_bus) +{ + (void)spi_bus; + + return 5; +} \ No newline at end of file diff --git a/targets/os/win32/nanoCLR/Windows.Devices.Spi/win_dev_spi_native.cpp b/targets/os/win32/nanoCLR/Windows.Devices.Spi/win_dev_spi_native.cpp index 120dedcb82..29c6d7ef9c 100644 --- a/targets/os/win32/nanoCLR/Windows.Devices.Spi/win_dev_spi_native.cpp +++ b/targets/os/win32/nanoCLR/Windows.Devices.Spi/win_dev_spi_native.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/os/win32/nanoCLR/Windows.Devices.Spi/win_dev_spi_native.h b/targets/os/win32/nanoCLR/Windows.Devices.Spi/win_dev_spi_native.h index e86272f651..bc884677ad 100644 --- a/targets/os/win32/nanoCLR/Windows.Devices.Spi/win_dev_spi_native.h +++ b/targets/os/win32/nanoCLR/Windows.Devices.Spi/win_dev_spi_native.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/os/win32/nanoCLR/Windows.Devices.Spi/win_dev_spi_native_Windows_Devices_Spi_SpiBusInfo.cpp b/targets/os/win32/nanoCLR/Windows.Devices.Spi/win_dev_spi_native_Windows_Devices_Spi_SpiBusInfo.cpp index 2df23f29bc..9db38713eb 100644 --- a/targets/os/win32/nanoCLR/Windows.Devices.Spi/win_dev_spi_native_Windows_Devices_Spi_SpiBusInfo.cpp +++ b/targets/os/win32/nanoCLR/Windows.Devices.Spi/win_dev_spi_native_Windows_Devices_Spi_SpiBusInfo.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/os/win32/nanoCLR/Windows.Devices.Spi/win_dev_spi_native_Windows_Devices_Spi_SpiDevice.cpp b/targets/os/win32/nanoCLR/Windows.Devices.Spi/win_dev_spi_native_Windows_Devices_Spi_SpiDevice.cpp index 45fc56995a..4c0bcaaf3c 100644 --- a/targets/os/win32/nanoCLR/Windows.Devices.Spi/win_dev_spi_native_Windows_Devices_Spi_SpiDevice.cpp +++ b/targets/os/win32/nanoCLR/Windows.Devices.Spi/win_dev_spi_native_Windows_Devices_Spi_SpiDevice.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // @@ -7,6 +7,33 @@ #include "stdafx.h" #include "win_dev_spi_native.h" +//SPIConfig spi_cfg; + +/////////////////////////////////////////////////////////////////////////////////////// +// !!! KEEP IN SYNC WITH Windows.Devices.Spi.SpiMode (in managed code) !!! // +/////////////////////////////////////////////////////////////////////////////////////// +// +//enum DataBitOrder +//{ +// DataBitOrder_MSB = 0, +// DataBitOrder_LSB = 1 +//}; +// +///////////////////////////////////////////////////////////////////////////////////////// +//// !!! KEEP IN SYNC WITH Windows.Devices.Spi.SpiMode (in managed code) !!! // +///////////////////////////////////////////////////////////////////////////////////////// +// +//enum SpiModes +//{ +// SpiMode_Mode0 = 0, +// SpiMode_Mode1 = 1, +// SpiMode_Mode2 = 2, +// SpiMode_Mode3 = 3 +//}; + +/////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////// + // define this type here to make it shorter and improve code readability typedef Library_win_dev_spi_native_Windows_Devices_Spi_SpiConnectionSettings SpiConnectionSettings; diff --git a/targets/os/win32/nanoCLR/Windows.Devices.Spi/win_dev_spi_native_target.h b/targets/os/win32/nanoCLR/Windows.Devices.Spi/win_dev_spi_native_target.h new file mode 100644 index 0000000000..dc56ae1180 --- /dev/null +++ b/targets/os/win32/nanoCLR/Windows.Devices.Spi/win_dev_spi_native_target.h @@ -0,0 +1,11 @@ +// +// Copyright (c) .NET Foundation and Contributors +// See LICENSE file in the project root for full license information. +// + +#ifndef _WIN_DEV_SPI_NATIVE_TARGET_H_ +#define _WIN_DEV_SPI_NATIVE_TARGET_H_ + +#include + +#endif //_WIN_DEV_SPI_NATIVE_TARGET_H_ diff --git a/targets/os/win32/nanoCLR/main.cpp b/targets/os/win32/nanoCLR/main.cpp index 87cada1a84..f6907b2a04 100644 --- a/targets/os/win32/nanoCLR/main.cpp +++ b/targets/os/win32/nanoCLR/main.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // #include "stdafx.h" diff --git a/targets/os/win32/nanoCLR/nanoFramework.Runtime.Events/nf_rt_events_native.cpp b/targets/os/win32/nanoCLR/nanoFramework.Runtime.Events/nf_rt_events_native.cpp index f43fd3ef10..6600479eaf 100644 --- a/targets/os/win32/nanoCLR/nanoFramework.Runtime.Events/nf_rt_events_native.cpp +++ b/targets/os/win32/nanoCLR/nanoFramework.Runtime.Events/nf_rt_events_native.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/os/win32/nanoCLR/nanoFramework.Runtime.Events/nf_rt_events_native.h b/targets/os/win32/nanoCLR/nanoFramework.Runtime.Events/nf_rt_events_native.h index 1796137470..a101325eff 100644 --- a/targets/os/win32/nanoCLR/nanoFramework.Runtime.Events/nf_rt_events_native.h +++ b/targets/os/win32/nanoCLR/nanoFramework.Runtime.Events/nf_rt_events_native.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/os/win32/nanoCLR/nanoFramework.Runtime.Events/nf_rt_events_native_nanoFramework_Runtime_Events_EventSink.cpp b/targets/os/win32/nanoCLR/nanoFramework.Runtime.Events/nf_rt_events_native_nanoFramework_Runtime_Events_EventSink.cpp index f5e3366124..4b3e3d97c6 100644 --- a/targets/os/win32/nanoCLR/nanoFramework.Runtime.Events/nf_rt_events_native_nanoFramework_Runtime_Events_EventSink.cpp +++ b/targets/os/win32/nanoCLR/nanoFramework.Runtime.Events/nf_rt_events_native_nanoFramework_Runtime_Events_EventSink.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/os/win32/nanoCLR/nanoFramework.Runtime.Events/nf_rt_events_native_nanoFramework_Runtime_Events_NativeEventDispatcher.cpp b/targets/os/win32/nanoCLR/nanoFramework.Runtime.Events/nf_rt_events_native_nanoFramework_Runtime_Events_NativeEventDispatcher.cpp index 2948ced25f..7dc0619181 100644 --- a/targets/os/win32/nanoCLR/nanoFramework.Runtime.Events/nf_rt_events_native_nanoFramework_Runtime_Events_NativeEventDispatcher.cpp +++ b/targets/os/win32/nanoCLR/nanoFramework.Runtime.Events/nf_rt_events_native_nanoFramework_Runtime_Events_NativeEventDispatcher.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/os/win32/nanoCLR/nanoFramework.Runtime.Events/nf_rt_events_native_nanoFramework_Runtime_Events_WeakDelegate.cpp b/targets/os/win32/nanoCLR/nanoFramework.Runtime.Events/nf_rt_events_native_nanoFramework_Runtime_Events_WeakDelegate.cpp index 0ec99f7149..b565d47c50 100644 --- a/targets/os/win32/nanoCLR/nanoFramework.Runtime.Events/nf_rt_events_native_nanoFramework_Runtime_Events_WeakDelegate.cpp +++ b/targets/os/win32/nanoCLR/nanoFramework.Runtime.Events/nf_rt_events_native_nanoFramework_Runtime_Events_WeakDelegate.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/os/win32/nanoCLR/platform_heap.cpp b/targets/os/win32/nanoCLR/platform_heap.cpp index 42706d9479..7951ca5807 100644 --- a/targets/os/win32/nanoCLR/platform_heap.cpp +++ b/targets/os/win32/nanoCLR/platform_heap.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // diff --git a/targets/os/win32/nanoCLR/platform_selector.h b/targets/os/win32/nanoCLR/platform_selector.h index 97cfc5a2da..78c03c8caf 100644 --- a/targets/os/win32/nanoCLR/platform_selector.h +++ b/targets/os/win32/nanoCLR/platform_selector.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/os/win32/nanoCLR/stdafx.cpp b/targets/os/win32/nanoCLR/stdafx.cpp index 968af34dc7..ce04bd60e3 100644 --- a/targets/os/win32/nanoCLR/stdafx.cpp +++ b/targets/os/win32/nanoCLR/stdafx.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // // stdafx.cpp : source file that includes just the standard includes diff --git a/targets/os/win32/nanoCLR/stdafx.h b/targets/os/win32/nanoCLR/stdafx.h index 9678d3eb32..910a542604 100644 --- a/targets/os/win32/nanoCLR/stdafx.h +++ b/targets/os/win32/nanoCLR/stdafx.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // // stdafx.h : include file for standard system include files, diff --git a/targets/os/win32/nanoCLR/targetHAL_Time.cpp b/targets/os/win32/nanoCLR/targetHAL_Time.cpp index 8ca94f9241..c55dc26f89 100644 --- a/targets/os/win32/nanoCLR/targetHAL_Time.cpp +++ b/targets/os/win32/nanoCLR/targetHAL_Time.cpp @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. // diff --git a/targets/os/win32/nanoCLR/targetver.h b/targets/os/win32/nanoCLR/targetver.h index 357aac41a8..5bf1f6f1c9 100644 --- a/targets/os/win32/nanoCLR/targetver.h +++ b/targets/os/win32/nanoCLR/targetver.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// Copyright (c) .NET Foundation and Contributors // See LICENSE file in the project root for full license information. // #pragma once diff --git a/version.json b/version.json index 5952bb2326..34db01cc91 100644 --- a/version.json +++ b/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json", - "version": "1.4.2", + "version": "1.5.0", "assemblyVersion": { "precision": "revision" },