From d4eb87c111d905a928f77ebbf0cf5d4b224e5c89 Mon Sep 17 00:00:00 2001 From: Adrian Soundy Date: Wed, 10 Jul 2019 08:25:54 +1200 Subject: [PATCH 1/5] ChangeCounter 1 --- CMake/Modules/FindWindows.Devices.Gpio.cmake | 1 + .../win_dev_gpio_native.cpp | 148 +++++----- .../win_dev_gpio_native.h | 30 +++ ...Windows_Devices_Gpio_GpioChangeCounter.cpp | 82 ++++++ .../ESP32_WROOM_32/Include/esp32_os.h | 1 + ...Windows_Devices_Gpio_GpioChangeCounter.cpp | 252 ++++++++++++++++++ ...Windows_Devices_Gpio_GpioChangeCounter.cpp | 82 ++++++ 7 files changed, 531 insertions(+), 65 deletions(-) create mode 100644 targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.Gpio/win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter.cpp create mode 100644 targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Gpio/win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter.cpp create mode 100644 targets/TI-SimpleLink/nanoCLR/Windows.Devices.Gpio/win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter.cpp diff --git a/CMake/Modules/FindWindows.Devices.Gpio.cmake b/CMake/Modules/FindWindows.Devices.Gpio.cmake index b720ecff01..7cda082a85 100644 --- a/CMake/Modules/FindWindows.Devices.Gpio.cmake +++ b/CMake/Modules/FindWindows.Devices.Gpio.cmake @@ -22,6 +22,7 @@ set(Windows.Devices.Gpio_SRCS # class library source files win_dev_gpio_native_Windows_Devices_Gpio_GpioController.cpp win_dev_gpio_native_Windows_Devices_Gpio_GpioPin.cpp + win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter.cpp win_dev_gpio_native.cpp # core source files diff --git a/src/Windows.Devices.Gpio/win_dev_gpio_native.cpp b/src/Windows.Devices.Gpio/win_dev_gpio_native.cpp index 103a091336..fb7bfd618d 100644 --- a/src/Windows.Devices.Gpio/win_dev_gpio_native.cpp +++ b/src/Windows.Devices.Gpio/win_dev_gpio_native.cpp @@ -10,75 +10,93 @@ static const CLR_RT_MethodHandler method_lookup[] = { - NULL, - NULL, - NULL, - NULL, - Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioController::get_PinCount___I4, - 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, - NULL, - Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::Read___WindowsDevicesGpioGpioPinValue, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::Toggle___VOID, - NULL, - Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::DisposeNative___VOID, - Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::NativeIsDriveModeSupported___BOOLEAN__WindowsDevicesGpioGpioPinDriveMode, - Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::NativeSetDriveMode___VOID__WindowsDevicesGpioGpioPinDriveMode, - Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::NativeInit___BOOLEAN__I4, - Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::NativeSetDebounceTimeout___VOID, - Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::WriteNative___VOID__WindowsDevicesGpioGpioPinValue, - Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::NativeSetAlternateFunction___VOID__I4, - 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, + NULL, + Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeInit___VOID, + Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeRead___U8__BOOLEAN, + Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeStart___VOID, + Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeStop___VOID, + Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeReset___VOID, + Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeDispose___VOID, + NULL, + NULL, + NULL, + NULL, + Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioController::get_PinCount___I4, + 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, + NULL, + Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::Read___WindowsDevicesGpioGpioPinValue, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::Toggle___VOID, + NULL, + Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::DisposeNative___VOID, + Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::NativeIsDriveModeSupported___BOOLEAN__WindowsDevicesGpioGpioPinDriveMode, + Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::NativeSetDriveMode___VOID__WindowsDevicesGpioGpioPinDriveMode, + Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::NativeInit___BOOLEAN__I4, + Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::NativeSetDebounceTimeout___VOID, + Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::WriteNative___VOID__WindowsDevicesGpioGpioPinValue, + Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::NativeSetAlternateFunction___VOID__I4, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, }; const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_Windows_Devices_Gpio = { - "Windows.Devices.Gpio", - 0xF3FBAE36, + "Windows.Devices.Gpio", + 0x21C0164A, method_lookup, { 100, 1, 0, 0 } }; diff --git a/src/Windows.Devices.Gpio/win_dev_gpio_native.h b/src/Windows.Devices.Gpio/win_dev_gpio_native.h index d2d8f81172..984246939a 100644 --- a/src/Windows.Devices.Gpio/win_dev_gpio_native.h +++ b/src/Windows.Devices.Gpio/win_dev_gpio_native.h @@ -41,6 +41,36 @@ enum GpioPinValue /////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////// +struct Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCount +{ + static const int FIELD__Count = 1; + static const int FIELD__RelativeTime = 2; + + + //--// + +}; + +struct Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter +{ + static const int FIELD___pinNumber = 1; + static const int FIELD___Polarity = 2; + static const int FIELD___CountActive = 3; + static const int FIELD__ReadTime = 4; + static const int FIELD___syncLock = 5; + static const int FIELD___disposedValue = 6; + + NANOCLR_NATIVE_DECLARE(NativeInit___VOID); + NANOCLR_NATIVE_DECLARE(NativeRead___U8__BOOLEAN); + NANOCLR_NATIVE_DECLARE(NativeStart___VOID); + NANOCLR_NATIVE_DECLARE(NativeStop___VOID); + NANOCLR_NATIVE_DECLARE(NativeReset___VOID); + NANOCLR_NATIVE_DECLARE(NativeDispose___VOID); + + //--// + +}; + struct Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioController { static const int FIELD_STATIC___syncLock = 0; 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 new file mode 100644 index 0000000000..6d9a2cdd64 --- /dev/null +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.Gpio/win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter.cpp @@ -0,0 +1,82 @@ +// +// 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 "win_dev_gpio_native.h" + +HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeInit___VOID( CLR_RT_StackFrame& stack ) +{ + NANOCLR_HEADER(); + { + //CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + + //int16_t pinNumber = pThis[ FIELD___pinNumber ].NumericByRefConst().s4; + + NANOCLR_SET_AND_LEAVE(CLR_E_NOT_SUPPORTED); + } + NANOCLR_NOCLEANUP(); +} + +HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeRead___U8__BOOLEAN( CLR_RT_StackFrame& stack ) +{ + NANOCLR_HEADER(); + { + + } + NANOCLR_NOCLEANUP(); +} + +HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeStart___VOID( CLR_RT_StackFrame& stack ) +{ + NANOCLR_HEADER(); + { + //CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + + //int pinNumber = pThis[ FIELD___pinNumber ].NumericByRefConst().s4; + + //GpioChangePolarity polarity = (GpioChangePolarity)pThis[ FIELD___Polarity ].NumericByRefConst().s4; + + + // TODO + + + } + NANOCLR_NOCLEANUP(); +} + +HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeStop___VOID( CLR_RT_StackFrame& stack ) +{ + NANOCLR_HEADER(); + { + //CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + + //int pinNumber = pThis[ FIELD___pinNumber ].NumericByRefConst().s4; + + } + NANOCLR_NOCLEANUP(); +} + +HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeReset___VOID( CLR_RT_StackFrame& stack ) +{ + NANOCLR_HEADER(); + { + //CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + + //int pinNumber = pThis[ FIELD___pinNumber ].NumericByRefConst().s4; + } + NANOCLR_NOCLEANUP(); +} + +HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeDispose___VOID( CLR_RT_StackFrame& stack ) +{ + NANOCLR_HEADER(); + { + //CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + + //int pinNumber = pThis[ FIELD___pinNumber ].NumericByRefConst().s4; + + } + NANOCLR_NOCLEANUP(); +} 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 05a0f9d9af..1aacffeecf 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/esp32_os.h +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/esp32_os.h @@ -30,6 +30,7 @@ #include "adc.h" #include "timer.h" #include "esp_spiffs.h" +#include "pcnt.h" // Uncomment to support Ethernet //#define ESP32_ETHERNET_SUPPORT 1 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 new file mode 100644 index 0000000000..0c9f4e6993 --- /dev/null +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Gpio/win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter.cpp @@ -0,0 +1,252 @@ +// +// Copyright (c) 2017 The nanoFramework project contributors +// Portions Copyright (c) Microsoft Corporation. All rights reserved. +// See LICENSE file in the project root for full license information. +// + +#include "win_dev_gpio_native.h" + +// Map Gpio number to 1 of 8 ESP32 counters, -1 = not mapped +static int8_t IsrInstalled = 0; +static int8_t GpioCounterMap[8] = {-1,-1,-1,-1,-1,-1,-1,-1}; +static uint32_t HighCount[8]; + +enum GpioChangePolarity +{ + Both, Falling, Rising +}; + +// Interrupt routine used to catch overflows so we can have a 32 bit counter +static void IRAM_ATTR pcnt_intr_handler(void *arg) +{ + uint32_t intr_status = PCNT.int_st.val; + + for (int i = 0; i < PCNT_UNIT_MAX; i++) { + if (intr_status & (BIT(i))) { + + uint32_t status = PCNT.status_unit[i].val; + // Hit high limit 0x4000 + if (status & PCNT_STATUS_H_LIM_M) + { + HighCount[i]++; + } + + PCNT.int_clr.val = BIT(i); + } + } +} + + + +// Find an unused counter, returns counter index or -1 if not found +static int FindFreeCounter(int gpioPin) +{ + int counterIndex; + + for( counterIndex=0; counterIndex<8; counterIndex++) + { + if (GpioCounterMap[counterIndex] == -1 ) + { + GpioCounterMap[counterIndex] = gpioPin; + return counterIndex; + } + } + return -1; +} + +// Find the index of counter for a gpio pin, returns index or -1 if not found +static int FindCounterForGpio(int gpioPin) +{ + int counterIndex; + + for( counterIndex=0; counterIndex<8; counterIndex++) + { + if (GpioCounterMap[counterIndex] == gpioPin) return counterIndex; + } + return -1; +} + +// Initalise the counter +// return true if ok +static bool InitialiseCounter(int counterIndex, int gpioNum, bool countRising, bool countFalling) +{ + esp_err_t ec; + + // Prepare configuration for the PCNT unit */ + pcnt_config_t pcnt_config; + + // Set PCNT input signal and control GPIOs + pcnt_config.pulse_gpio_num = gpioNum; + pcnt_config.ctrl_gpio_num = PCNT_PIN_NOT_USED; // ignore + + pcnt_config.channel = PCNT_CHANNEL_0; + pcnt_config.unit = (pcnt_unit_t)counterIndex; + + // What to do on the positive / negative edge of pulse input? + pcnt_config.pos_mode = countRising ? PCNT_COUNT_INC : PCNT_COUNT_DIS; // positive edge count ? + pcnt_config.neg_mode = countFalling ? PCNT_COUNT_INC : PCNT_COUNT_DIS; // falling edge count ? + + // What to do when control input is low or high? + pcnt_config.lctrl_mode = PCNT_MODE_KEEP; // Keep the primary counter mode if low + pcnt_config.hctrl_mode = PCNT_MODE_KEEP; // Keep the primary counter mode if high + + // Set the maximum and minimum limit values to watch + pcnt_config.counter_h_lim = 0x4000; + pcnt_config.counter_l_lim = 0; + + //* Initialize PCNT unit + ec = pcnt_unit_config(&pcnt_config); + if ( ec != ESP_OK) return false; + + return true; +} + +HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeInit___VOID( CLR_RT_StackFrame& stack ) +{ + NANOCLR_HEADER(); + { + CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + + int16_t pinNumber = pThis[ FIELD___pinNumber ].NumericByRefConst().s4; + + int index = FindFreeCounter(pinNumber); + if ( index == -1 ) + { + // NO free counters + NANOCLR_SET_AND_LEAVE(CLR_E_NOT_SUPPORTED); + } + } + NANOCLR_NOCLEANUP(); +} + +HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeRead___U8__BOOLEAN( CLR_RT_StackFrame& stack ) +{ + NANOCLR_HEADER(); + { + CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + + int pinNumber = pThis[ FIELD___pinNumber ].NumericByRefConst().s4; + + int counterIndex = FindCounterForGpio(pinNumber); + if ( counterIndex == -1 ) { NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); } + + int16_t counter; + + pcnt_get_counter_value((pcnt_unit_t)counterIndex, &counter); + + // Combine to make a 32 bit value + uint32_t totalCount = (HighCount[counterIndex] << 14) + counter; + + // Return value to the managed application + stack.SetResult_U4( totalCount ) ; + + } + NANOCLR_NOCLEANUP(); +} + +HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeStart___VOID( CLR_RT_StackFrame& stack ) +{ + NANOCLR_HEADER(); + { + bool countRising = false; + bool countFalling = false; + + CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + + int pinNumber = pThis[ FIELD___pinNumber ].NumericByRefConst().s4; + + int counterIndex = FindCounterForGpio(pinNumber); + if ( counterIndex == -1 ) { NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); } + + GpioChangePolarity polarity = (GpioChangePolarity)pThis[ FIELD___Polarity ].NumericByRefConst().s4; + + switch(polarity) + { + case Both : countRising = true; countFalling = true; break; + case Rising: countRising = true; break; + case Falling: countFalling = true; break; + } + + if ( !InitialiseCounter(counterIndex, pinNumber, countRising, countFalling) ) + { NANOCLR_SET_AND_LEAVE(CLR_E_NOT_SUPPORTED); } + + // pcnt_set_filter_value((pcnt_unit_t)counterIndex, 10); + // pcnt_filter_enable((pcnt_unit_t)counterIndex); + + pcnt_event_enable((pcnt_unit_t)counterIndex, PCNT_EVT_H_LIM); + + pcnt_counter_pause((pcnt_unit_t)counterIndex); + + pcnt_counter_clear((pcnt_unit_t)counterIndex); + HighCount[counterIndex] = 0; + + // Register ISR handler and enable interrupts for PCNT unit */ + if ( IsrInstalled == 0) + { + pcnt_isr_register(pcnt_intr_handler, NULL, 0, NULL); + IsrInstalled = 1; + } + + // enable interrupts for PCNT unit + pcnt_intr_enable((pcnt_unit_t)counterIndex); + + pcnt_counter_resume((pcnt_unit_t)counterIndex); + } + NANOCLR_NOCLEANUP(); +} + +HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeStop___VOID( CLR_RT_StackFrame& stack ) +{ + NANOCLR_HEADER(); + { + CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + + int pinNumber = pThis[ FIELD___pinNumber ].NumericByRefConst().s4; + + int counterIndex = FindCounterForGpio(pinNumber); + if ( counterIndex == -1 ) { NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); } + + pcnt_counter_pause((pcnt_unit_t)counterIndex); + } + NANOCLR_NOCLEANUP(); +} + +HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeReset___VOID( CLR_RT_StackFrame& stack ) +{ + NANOCLR_HEADER(); + { + CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + + int pinNumber = pThis[ FIELD___pinNumber ].NumericByRefConst().s4; + + int counterIndex = FindCounterForGpio(pinNumber); + if ( counterIndex == -1 ) { NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); } + + pcnt_counter_pause((pcnt_unit_t)counterIndex); + pcnt_counter_clear((pcnt_unit_t)counterIndex); + HighCount[counterIndex] = 0; + } + NANOCLR_NOCLEANUP(); +} + +HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeDispose___VOID( CLR_RT_StackFrame& stack ) +{ + NANOCLR_HEADER(); + { + CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + + int pinNumber = pThis[ FIELD___pinNumber ].NumericByRefConst().s4; + + int counterIndex = FindCounterForGpio(pinNumber); + if ( counterIndex == -1 ) { NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); } + + pcnt_intr_disable((pcnt_unit_t)counterIndex); + + // Disable counter, remove gpio pin + InitialiseCounter( counterIndex, PCNT_PIN_NOT_USED, false, false); + + // Clear counter / gpio mapping + GpioCounterMap[counterIndex] = -1; + } + NANOCLR_NOCLEANUP(); +} 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 new file mode 100644 index 0000000000..6d9a2cdd64 --- /dev/null +++ b/targets/TI-SimpleLink/nanoCLR/Windows.Devices.Gpio/win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter.cpp @@ -0,0 +1,82 @@ +// +// 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 "win_dev_gpio_native.h" + +HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeInit___VOID( CLR_RT_StackFrame& stack ) +{ + NANOCLR_HEADER(); + { + //CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + + //int16_t pinNumber = pThis[ FIELD___pinNumber ].NumericByRefConst().s4; + + NANOCLR_SET_AND_LEAVE(CLR_E_NOT_SUPPORTED); + } + NANOCLR_NOCLEANUP(); +} + +HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeRead___U8__BOOLEAN( CLR_RT_StackFrame& stack ) +{ + NANOCLR_HEADER(); + { + + } + NANOCLR_NOCLEANUP(); +} + +HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeStart___VOID( CLR_RT_StackFrame& stack ) +{ + NANOCLR_HEADER(); + { + //CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + + //int pinNumber = pThis[ FIELD___pinNumber ].NumericByRefConst().s4; + + //GpioChangePolarity polarity = (GpioChangePolarity)pThis[ FIELD___Polarity ].NumericByRefConst().s4; + + + // TODO + + + } + NANOCLR_NOCLEANUP(); +} + +HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeStop___VOID( CLR_RT_StackFrame& stack ) +{ + NANOCLR_HEADER(); + { + //CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + + //int pinNumber = pThis[ FIELD___pinNumber ].NumericByRefConst().s4; + + } + NANOCLR_NOCLEANUP(); +} + +HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeReset___VOID( CLR_RT_StackFrame& stack ) +{ + NANOCLR_HEADER(); + { + //CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + + //int pinNumber = pThis[ FIELD___pinNumber ].NumericByRefConst().s4; + } + NANOCLR_NOCLEANUP(); +} + +HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeDispose___VOID( CLR_RT_StackFrame& stack ) +{ + NANOCLR_HEADER(); + { + //CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + + //int pinNumber = pThis[ FIELD___pinNumber ].NumericByRefConst().s4; + + } + NANOCLR_NOCLEANUP(); +} From 3c2aea5ec7ee50cbc27c0abbb3fd2b855ff2b024 Mon Sep 17 00:00:00 2001 From: Adrian Soundy Date: Sun, 21 Jul 2019 15:09:24 +1200 Subject: [PATCH 2/5] Chage Counter rev 2 Fixes after testing --- .../win_dev_gpio_native.cpp | 6 +- .../win_dev_gpio_native.h | 17 +- ...Windows_Devices_Gpio_GpioChangeCounter.cpp | 11 - ...Windows_Devices_Gpio_GpioChangeCounter.cpp | 389 ++++++++++-------- ...io_native_Windows_Devices_Gpio_GpioPin.cpp | 22 +- ...Windows_Devices_Gpio_GpioChangeCounter.cpp | 18 +- 6 files changed, 248 insertions(+), 215 deletions(-) diff --git a/src/Windows.Devices.Gpio/win_dev_gpio_native.cpp b/src/Windows.Devices.Gpio/win_dev_gpio_native.cpp index fb7bfd618d..8f94879ce8 100644 --- a/src/Windows.Devices.Gpio/win_dev_gpio_native.cpp +++ b/src/Windows.Devices.Gpio/win_dev_gpio_native.cpp @@ -22,11 +22,11 @@ static const CLR_RT_MethodHandler method_lookup[] = NULL, NULL, NULL, + NULL, Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeInit___VOID, Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeRead___U8__BOOLEAN, Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeStart___VOID, Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeStop___VOID, - Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeReset___VOID, Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeDispose___VOID, NULL, NULL, @@ -96,7 +96,7 @@ static const CLR_RT_MethodHandler method_lookup[] = const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_Windows_Devices_Gpio = { "Windows.Devices.Gpio", - 0x21C0164A, - method_lookup, + 0xD7F65BB7, + method_lookup, { 100, 1, 0, 0 } }; diff --git a/src/Windows.Devices.Gpio/win_dev_gpio_native.h b/src/Windows.Devices.Gpio/win_dev_gpio_native.h index 984246939a..87c045bdd5 100644 --- a/src/Windows.Devices.Gpio/win_dev_gpio_native.h +++ b/src/Windows.Devices.Gpio/win_dev_gpio_native.h @@ -38,6 +38,18 @@ enum GpioPinValue GpioPinValue_High, }; +/////////////////////////////////////////////////////////////////////////////////// +// !!! KEEP IN SYNC WITH Windows.Devices.Gpio.GpioChangePolarity (in managed code) !!! // +/////////////////////////////////////////////////////////////////////////////////// + +enum GpioChangePolarity +{ + Both = 0, + Falling, + Rising +}; + + /////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////// @@ -54,9 +66,9 @@ struct Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCount struct Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter { static const int FIELD___pinNumber = 1; - static const int FIELD___Polarity = 2; + static const int FIELD___polarity = 2; static const int FIELD___CountActive = 3; - static const int FIELD__ReadTime = 4; + static const int FIELD___readTime = 4; static const int FIELD___syncLock = 5; static const int FIELD___disposedValue = 6; @@ -64,7 +76,6 @@ struct Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter NANOCLR_NATIVE_DECLARE(NativeRead___U8__BOOLEAN); NANOCLR_NATIVE_DECLARE(NativeStart___VOID); NANOCLR_NATIVE_DECLARE(NativeStop___VOID); - NANOCLR_NATIVE_DECLARE(NativeReset___VOID); NANOCLR_NATIVE_DECLARE(NativeDispose___VOID); //--// 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 6d9a2cdd64..f731dd766b 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 @@ -58,17 +58,6 @@ HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::Nati NANOCLR_NOCLEANUP(); } -HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeReset___VOID( CLR_RT_StackFrame& stack ) -{ - NANOCLR_HEADER(); - { - //CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); - - //int pinNumber = pThis[ FIELD___pinNumber ].NumericByRefConst().s4; - } - NANOCLR_NOCLEANUP(); -} - HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeDispose___VOID( CLR_RT_StackFrame& stack ) { NANOCLR_HEADER(); 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 0c9f4e6993..2dd9a39453 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,252 +1,293 @@ // -// Copyright (c) 2017 The nanoFramework project contributors +// 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 "win_dev_gpio_native.h" -// Map Gpio number to 1 of 8 ESP32 counters, -1 = not mapped +// Map Gpio pin number to 1 of 8 ESP32 counters, -1 = not mapped +// Each pulse counter is a 16 bit signed value. +// The managed code requires a 64 bit counter so we accumulate the overflows in an interrupt when count gets to 0x7fff + static int8_t IsrInstalled = 0; -static int8_t GpioCounterMap[8] = {-1,-1,-1,-1,-1,-1,-1,-1}; -static uint32_t HighCount[8]; +static int8_t GpioCounterMap[8] = { -1,-1,-1,-1,-1,-1,-1,-1 }; +static uint64_t OverflowCount[8]; -enum GpioChangePolarity -{ - Both, Falling, Rising -}; +#define MAX_COUNTER_VALUE 0x7fff + +extern void Remove_Gpio_Interrupt(gpio_num_t pinNumber); -// Interrupt routine used to catch overflows so we can have a 32 bit counter + +// Interrupt routine used to catch overflows so we can have a 64 bit counter static void IRAM_ATTR pcnt_intr_handler(void *arg) { - uint32_t intr_status = PCNT.int_st.val; - - for (int i = 0; i < PCNT_UNIT_MAX; i++) { - if (intr_status & (BIT(i))) { - - uint32_t status = PCNT.status_unit[i].val; - // Hit high limit 0x4000 - if (status & PCNT_STATUS_H_LIM_M) - { - HighCount[i]++; - } - - PCNT.int_clr.val = BIT(i); - } - } -} + (void)arg; + + uint32_t intr_status = PCNT.int_st.val; + for (int i = 0; i < PCNT_UNIT_MAX; i++) + { + if (intr_status & (BIT(i))) + { + + uint32_t status = PCNT.status_unit[i].val; + // Hit high limit MAX_COUNTER_VALUE + if (status & PCNT_STATUS_H_LIM_M) + { + OverflowCount[i] += MAX_COUNTER_VALUE; + } + + PCNT.int_clr.val = BIT(i); + } + } +} // Find an unused counter, returns counter index or -1 if not found static int FindFreeCounter(int gpioPin) { - int counterIndex; - - for( counterIndex=0; counterIndex<8; counterIndex++) - { - if (GpioCounterMap[counterIndex] == -1 ) - { - GpioCounterMap[counterIndex] = gpioPin; - return counterIndex; - } - } - return -1; + int counterIndex; + + for (counterIndex = 0; counterIndex < 8; counterIndex++) + { + if (GpioCounterMap[counterIndex] == -1) + { + GpioCounterMap[counterIndex] = gpioPin; + return counterIndex; + } + } + return -1; } // Find the index of counter for a gpio pin, returns index or -1 if not found static int FindCounterForGpio(int gpioPin) { - int counterIndex; + int counterIndex; - for( counterIndex=0; counterIndex<8; counterIndex++) - { - if (GpioCounterMap[counterIndex] == gpioPin) return counterIndex; - } - return -1; + for (counterIndex = 0; counterIndex < 8; counterIndex++) + { + if (GpioCounterMap[counterIndex] == gpioPin) return counterIndex; + } + return -1; } -// Initalise the counter +// Initalise the ESP32 counter // return true if ok static bool InitialiseCounter(int counterIndex, int gpioNum, bool countRising, bool countFalling) { - esp_err_t ec; + esp_err_t ec; - // Prepare configuration for the PCNT unit */ - pcnt_config_t pcnt_config; + // Prepare configuration for the PCNT unit */ + pcnt_config_t pcnt_config; - // Set PCNT input signal and control GPIOs - pcnt_config.pulse_gpio_num = gpioNum; - pcnt_config.ctrl_gpio_num = PCNT_PIN_NOT_USED; // ignore + // Set PCNT input signal and control GPIOs + pcnt_config.pulse_gpio_num = gpioNum; + pcnt_config.ctrl_gpio_num = PCNT_PIN_NOT_USED; // ignore - pcnt_config.channel = PCNT_CHANNEL_0; - pcnt_config.unit = (pcnt_unit_t)counterIndex; + pcnt_config.channel = PCNT_CHANNEL_0; + pcnt_config.unit = (pcnt_unit_t)counterIndex; - // What to do on the positive / negative edge of pulse input? - pcnt_config.pos_mode = countRising ? PCNT_COUNT_INC : PCNT_COUNT_DIS; // positive edge count ? - pcnt_config.neg_mode = countFalling ? PCNT_COUNT_INC : PCNT_COUNT_DIS; // falling edge count ? - - // What to do when control input is low or high? - pcnt_config.lctrl_mode = PCNT_MODE_KEEP; // Keep the primary counter mode if low - pcnt_config.hctrl_mode = PCNT_MODE_KEEP; // Keep the primary counter mode if high + // What to do on the positive / negative edge of pulse input? + pcnt_config.pos_mode = countRising ? PCNT_COUNT_INC : PCNT_COUNT_DIS; // positive edge count ? + pcnt_config.neg_mode = countFalling ? PCNT_COUNT_INC : PCNT_COUNT_DIS; // falling edge count ? - // Set the maximum and minimum limit values to watch - pcnt_config.counter_h_lim = 0x4000; - pcnt_config.counter_l_lim = 0; + // What to do when control input is low or high? + pcnt_config.lctrl_mode = PCNT_MODE_KEEP; // Keep the primary counter mode if low + pcnt_config.hctrl_mode = PCNT_MODE_KEEP; // Keep the primary counter mode if high - //* Initialize PCNT unit - ec = pcnt_unit_config(&pcnt_config); - if ( ec != ESP_OK) return false; + // Set the maximum and minimum limit values to watch + pcnt_config.counter_h_lim = MAX_COUNTER_VALUE; + pcnt_config.counter_l_lim = 0; - return true; + //* Initialize PCNT unit + ec = pcnt_unit_config(&pcnt_config); + if (ec != ESP_OK) return false; + + return true; } -HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeInit___VOID( CLR_RT_StackFrame& stack ) +HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeInit___VOID(CLR_RT_StackFrame& stack) { - NANOCLR_HEADER(); - { - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); - - int16_t pinNumber = pThis[ FIELD___pinNumber ].NumericByRefConst().s4; - - int index = FindFreeCounter(pinNumber); - if ( index == -1 ) - { - // NO free counters - NANOCLR_SET_AND_LEAVE(CLR_E_NOT_SUPPORTED); - } - } - NANOCLR_NOCLEANUP(); + NANOCLR_HEADER(); + { + CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + + int16_t pinNumber = pThis[FIELD___pinNumber].NumericByRefConst().s4; + + int index = FindFreeCounter(pinNumber); + if (index == -1) + { + // No free counters + NANOCLR_SET_AND_LEAVE(CLR_E_NOT_SUPPORTED); + } + + // Make sure GPIO pin doesn't have a GPIO Isr asscoiatted with it otherwise it will not support + // faster count frequencies + Remove_Gpio_Interrupt((gpio_num_t)pinNumber); + } + NANOCLR_NOCLEANUP(); } -HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeRead___U8__BOOLEAN( CLR_RT_StackFrame& stack ) +HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeRead___U8__BOOLEAN(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); - int pinNumber = pThis[ FIELD___pinNumber ].NumericByRefConst().s4; + // check if object has been disposed + if (pThis[Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::FIELD___disposedValue].NumericByRef().u1 != 0) + { + NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); + } - int counterIndex = FindCounterForGpio(pinNumber); - if ( counterIndex == -1 ) { NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); } + int pinNumber = pThis[FIELD___pinNumber].NumericByRefConst().s4; - int16_t counter; + int counterIndex = FindCounterForGpio(pinNumber); + if (counterIndex == -1) + { + NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); + } - pcnt_get_counter_value((pcnt_unit_t)counterIndex, &counter); + bool resetAfterRead = (bool)stack.Arg0().NumericByRef().u1; - // Combine to make a 32 bit value - uint32_t totalCount = (HighCount[counterIndex] << 14) + counter; + int16_t counter; - // Return value to the managed application - stack.SetResult_U4( totalCount ) ; - - } - NANOCLR_NOCLEANUP(); -} + pcnt_get_counter_value((pcnt_unit_t)counterIndex, &counter); -HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeStart___VOID( CLR_RT_StackFrame& stack ) -{ - NANOCLR_HEADER(); - { - bool countRising = false; - bool countFalling = false; + // relativeTime Read Time, Number of micro seconds since boot + int64_t relativeTime = esp_timer_get_time(); - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + // Combine to make a 64 bit value + uint64_t totalCount = OverflowCount[counterIndex] + (uint64_t)counter; - int pinNumber = pThis[ FIELD___pinNumber ].NumericByRefConst().s4; + if (resetAfterRead) + { + pcnt_counter_clear((pcnt_unit_t)counterIndex); + OverflowCount[counterIndex] = 0; + } - int counterIndex = FindCounterForGpio(pinNumber); - if ( counterIndex == -1 ) { NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); } - GpioChangePolarity polarity = (GpioChangePolarity)pThis[ FIELD___Polarity ].NumericByRefConst().s4; + // Return results + // Update the Relative _readTime field (convert micro sec to 100ns ticks) + *&pThis[FIELD___readTime].NumericByRef().s8 = (relativeTime * 10); - switch(polarity) - { - case Both : countRising = true; countFalling = true; break; - case Rising: countRising = true; break; - case Falling: countFalling = true; break; - } + // Return value to the managed application + stack.SetResult_U8(totalCount); - if ( !InitialiseCounter(counterIndex, pinNumber, countRising, countFalling) ) - { NANOCLR_SET_AND_LEAVE(CLR_E_NOT_SUPPORTED); } + } + NANOCLR_NOCLEANUP(); +} - // pcnt_set_filter_value((pcnt_unit_t)counterIndex, 10); - // pcnt_filter_enable((pcnt_unit_t)counterIndex); +HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeStart___VOID(CLR_RT_StackFrame& stack) +{ + NANOCLR_HEADER(); + { + bool countRising = false; + bool countFalling = false; - pcnt_event_enable((pcnt_unit_t)counterIndex, PCNT_EVT_H_LIM); + CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); - pcnt_counter_pause((pcnt_unit_t)counterIndex); - - pcnt_counter_clear((pcnt_unit_t)counterIndex); - HighCount[counterIndex] = 0; + // check if object has been disposed + if (pThis[Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::FIELD___disposedValue].NumericByRef().u1 != 0) + { + NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); + } - // Register ISR handler and enable interrupts for PCNT unit */ - if ( IsrInstalled == 0) - { - pcnt_isr_register(pcnt_intr_handler, NULL, 0, NULL); - IsrInstalled = 1; - } + int pinNumber = pThis[FIELD___pinNumber].NumericByRefConst().s4; - // enable interrupts for PCNT unit - pcnt_intr_enable((pcnt_unit_t)counterIndex); + int counterIndex = FindCounterForGpio(pinNumber); + if (counterIndex == -1) + { + NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); + } - pcnt_counter_resume((pcnt_unit_t)counterIndex); - } - NANOCLR_NOCLEANUP(); -} + GpioChangePolarity polarity = (GpioChangePolarity)pThis[FIELD___polarity].NumericByRefConst().s4; -HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeStop___VOID( CLR_RT_StackFrame& stack ) -{ - NANOCLR_HEADER(); - { - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + switch (polarity) + { + case Both: countRising = true; countFalling = true; break; + case Rising: countRising = true; break; + case Falling: countFalling = true; break; + } - int pinNumber = pThis[ FIELD___pinNumber ].NumericByRefConst().s4; + if (!InitialiseCounter(counterIndex, pinNumber, countRising, countFalling)) + { + NANOCLR_SET_AND_LEAVE(CLR_E_NOT_SUPPORTED); + } - int counterIndex = FindCounterForGpio(pinNumber); - if ( counterIndex == -1 ) { NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); } + // Posible filter ( debounce ) future. + // pcnt_set_filter_value((pcnt_unit_t)counterIndex, 10); + // pcnt_filter_enable((pcnt_unit_t)counterIndex); - pcnt_counter_pause((pcnt_unit_t)counterIndex); - } - NANOCLR_NOCLEANUP(); -} + pcnt_event_enable((pcnt_unit_t)counterIndex, PCNT_EVT_H_LIM); -HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeReset___VOID( CLR_RT_StackFrame& stack ) -{ - NANOCLR_HEADER(); - { - CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + pcnt_counter_pause((pcnt_unit_t)counterIndex); + + pcnt_counter_clear((pcnt_unit_t)counterIndex); + OverflowCount[counterIndex] = 0; - int pinNumber = pThis[ FIELD___pinNumber ].NumericByRefConst().s4; + // Register ISR handler and enable interrupts for PCNT unit */ + if (IsrInstalled == 0) + { + pcnt_isr_register(pcnt_intr_handler, NULL, 0, NULL); + IsrInstalled = 1; + } - int counterIndex = FindCounterForGpio(pinNumber); - if ( counterIndex == -1 ) { NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); } + // enable interrupts for PCNT unit + pcnt_intr_enable((pcnt_unit_t)counterIndex); - pcnt_counter_pause((pcnt_unit_t)counterIndex); - pcnt_counter_clear((pcnt_unit_t)counterIndex); - HighCount[counterIndex] = 0; - } - NANOCLR_NOCLEANUP(); + pcnt_counter_resume((pcnt_unit_t)counterIndex); + } + NANOCLR_NOCLEANUP(); +} + +HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeStop___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_GpioChangeCounter::FIELD___disposedValue].NumericByRef().u1 != 0) + { + NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED); + } + + int pinNumber = pThis[FIELD___pinNumber].NumericByRefConst().s4; + + int counterIndex = FindCounterForGpio(pinNumber); + if (counterIndex == -1) + { + NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); + } + + pcnt_counter_pause((pcnt_unit_t)counterIndex); + } + NANOCLR_NOCLEANUP(); } -HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeDispose___VOID( CLR_RT_StackFrame& stack ) +HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::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); - int pinNumber = pThis[ FIELD___pinNumber ].NumericByRefConst().s4; + int pinNumber = pThis[FIELD___pinNumber].NumericByRefConst().s4; - int counterIndex = FindCounterForGpio(pinNumber); - if ( counterIndex == -1 ) { NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); } + int counterIndex = FindCounterForGpio(pinNumber); + if (counterIndex == -1) + { + NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); + } - pcnt_intr_disable((pcnt_unit_t)counterIndex); + pcnt_intr_disable((pcnt_unit_t)counterIndex); - // Disable counter, remove gpio pin - InitialiseCounter( counterIndex, PCNT_PIN_NOT_USED, false, false); + // Disable counter, remove gpio pin + InitialiseCounter(counterIndex, PCNT_PIN_NOT_USED, false, false); - // Clear counter / gpio mapping - GpioCounterMap[counterIndex] = -1; - } - NANOCLR_NOCLEANUP(); + // Clear counter / gpio mapping + GpioCounterMap[counterIndex] = -1; + } + NANOCLR_NOCLEANUP(); } diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Gpio/win_dev_gpio_native_Windows_Devices_Gpio_GpioPin.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Gpio/win_dev_gpio_native_Windows_Devices_Gpio_GpioPin.cpp index 8e61d73de7..7aafaade0c 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Gpio/win_dev_gpio_native_Windows_Devices_Gpio_GpioPin.cpp +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/Windows.Devices.Gpio/win_dev_gpio_native_Windows_Devices_Gpio_GpioPin.cpp @@ -83,6 +83,18 @@ void Add_Gpio_Interrupt(gpio_num_t pinNumber) } +void Remove_Gpio_Interrupt(gpio_num_t pinNumber) +{ + if (channelPinMapping[pinNumber] != NULL) + { + // Remove from interrupts + gpio_isr_handler_remove((gpio_num_t)pinNumber); + + // clear this channel in channel pin mapping + channelPinMapping[pinNumber] = NULL; + } +} + HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::Read___WindowsDevicesGpioGpioPinValue( CLR_RT_StackFrame& stack ) { NANOCLR_HEADER(); @@ -147,15 +159,7 @@ HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::DisposeNative_ // releases the pin int16_t pinNumber = pThis[ FIELD___pinNumber ].NumericByRefConst().s4; - - if ( channelPinMapping[pinNumber] != NULL ) - { - // Remove from interrupts - gpio_isr_handler_remove((gpio_num_t)pinNumber); - - // clear this channel in channel pin mapping - channelPinMapping[pinNumber] = NULL; - } + Remove_Gpio_Interrupt((gpio_num_t)pinNumber); } NANOCLR_NOCLEANUP(); } 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 6d9a2cdd64..10e5a359d0 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 @@ -23,7 +23,9 @@ HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::Nati { NANOCLR_HEADER(); { - + //CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + //int pinNumber = pThis[ FIELD___pinNumber ].NumericByRefConst().s4; + } NANOCLR_NOCLEANUP(); } @@ -37,9 +39,6 @@ HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::Nati //int pinNumber = pThis[ FIELD___pinNumber ].NumericByRefConst().s4; //GpioChangePolarity polarity = (GpioChangePolarity)pThis[ FIELD___Polarity ].NumericByRefConst().s4; - - - // TODO } @@ -58,17 +57,6 @@ HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::Nati NANOCLR_NOCLEANUP(); } -HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeReset___VOID( CLR_RT_StackFrame& stack ) -{ - NANOCLR_HEADER(); - { - //CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); - - //int pinNumber = pThis[ FIELD___pinNumber ].NumericByRefConst().s4; - } - NANOCLR_NOCLEANUP(); -} - HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeDispose___VOID( CLR_RT_StackFrame& stack ) { NANOCLR_HEADER(); From 1e1c932d96ddad6e2507db1831dc4bf3ffc9b3f4 Mon Sep 17 00:00:00 2001 From: Adrian Soundy Date: Thu, 25 Jul 2019 20:36:19 +1200 Subject: [PATCH 3/5] Change counter rev 3 --- .../win_dev_gpio_native.h | 12 +++++----- ...Windows_Devices_Gpio_GpioChangeCounter.cpp | 1 + ...Windows_Devices_Gpio_GpioChangeCounter.cpp | 22 ++++++++++++++----- ...Windows_Devices_Gpio_GpioChangeCounter.cpp | 1 + 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/Windows.Devices.Gpio/win_dev_gpio_native.h b/src/Windows.Devices.Gpio/win_dev_gpio_native.h index 87c045bdd5..8422022790 100644 --- a/src/Windows.Devices.Gpio/win_dev_gpio_native.h +++ b/src/Windows.Devices.Gpio/win_dev_gpio_native.h @@ -66,11 +66,12 @@ struct Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCount struct Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter { static const int FIELD___pinNumber = 1; - static const int FIELD___polarity = 2; - static const int FIELD___CountActive = 3; - static const int FIELD___readTime = 4; - static const int FIELD___syncLock = 5; - static const int FIELD___disposedValue = 6; + static const int FIELD___inputMode = 2; + static const int FIELD___polarity = 3; + static const int FIELD___CountActive = 4; + static const int FIELD___readTime = 5; + static const int FIELD___syncLock = 6; + static const int FIELD___disposedValue = 7; NANOCLR_NATIVE_DECLARE(NativeInit___VOID); NANOCLR_NATIVE_DECLARE(NativeRead___U8__BOOLEAN); @@ -82,6 +83,7 @@ struct Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter }; + struct Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioController { static const int FIELD_STATIC___syncLock = 0; 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 f731dd766b..1eedfc3654 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 @@ -13,6 +13,7 @@ HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::Nati //CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); //int16_t pinNumber = pThis[ FIELD___pinNumber ].NumericByRefConst().s4; + //bool InputMode = (bool)pThis[FIELD___inputMode].NumericByRefConst().u1; NANOCLR_SET_AND_LEAVE(CLR_E_NOT_SUPPORTED); } 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 2dd9a39453..3bdc6d4b5f 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 @@ -115,16 +115,26 @@ HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::Nati int16_t pinNumber = pThis[FIELD___pinNumber].NumericByRefConst().s4; - int index = FindFreeCounter(pinNumber); - if (index == -1) + bool InputMode = (bool)pThis[FIELD___inputMode].NumericByRefConst().u1; + if (InputMode) { - // No free counters + int index = FindFreeCounter(pinNumber); + if (index == -1) + { + // No free counters + NANOCLR_SET_AND_LEAVE(CLR_E_NOT_SUPPORTED); + } + + // Make sure GPIO pin doesn't have a GPIO Isr asscoiatted with it otherwise it will not support + // faster count frequencies + Remove_Gpio_Interrupt((gpio_num_t)pinNumber); + } + else + { + // Output not currently supported NANOCLR_SET_AND_LEAVE(CLR_E_NOT_SUPPORTED); } - // Make sure GPIO pin doesn't have a GPIO Isr asscoiatted with it otherwise it will not support - // faster count frequencies - Remove_Gpio_Interrupt((gpio_num_t)pinNumber); } NANOCLR_NOCLEANUP(); } 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 10e5a359d0..3fd1b418f0 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 @@ -13,6 +13,7 @@ HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::Nati //CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); //int16_t pinNumber = pThis[ FIELD___pinNumber ].NumericByRefConst().s4; + //bool InputMode = (bool)pThis[FIELD___inputMode].NumericByRefConst().u1; NANOCLR_SET_AND_LEAVE(CLR_E_NOT_SUPPORTED); } From 3174a2100d787429783aeeb29f513f78f7642722 Mon Sep 17 00:00:00 2001 From: Adrian Soundy Date: Thu, 25 Jul 2019 23:50:04 +1200 Subject: [PATCH 4/5] Fixes so build completes --- ...Windows_Devices_Gpio_GpioChangeCounter.cpp | 26 ++++-- ...Windows_Devices_Gpio_GpioChangeCounter.cpp | 89 +++++++++++-------- 2 files changed, 72 insertions(+), 43 deletions(-) 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 1eedfc3654..d6c6623a48 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 @@ -8,6 +8,8 @@ HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeInit___VOID( CLR_RT_StackFrame& stack ) { + (void)stack; + NANOCLR_HEADER(); { //CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); @@ -22,16 +24,21 @@ HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::Nati HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeRead___U8__BOOLEAN( CLR_RT_StackFrame& stack ) { - NANOCLR_HEADER(); + (void)stack; + + NANOCLR_HEADER(); { - + NANOCLR_SET_AND_LEAVE(CLR_E_NOT_SUPPORTED); + } NANOCLR_NOCLEANUP(); } HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeStart___VOID( CLR_RT_StackFrame& stack ) { - NANOCLR_HEADER(); + (void)stack; + + NANOCLR_HEADER(); { //CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); @@ -41,7 +48,8 @@ HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::Nati // TODO - + NANOCLR_SET_AND_LEAVE(CLR_E_NOT_SUPPORTED); + } NANOCLR_NOCLEANUP(); @@ -49,11 +57,14 @@ HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::Nati HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeStop___VOID( CLR_RT_StackFrame& stack ) { - NANOCLR_HEADER(); + (void)stack; + + NANOCLR_HEADER(); { //CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); //int pinNumber = pThis[ FIELD___pinNumber ].NumericByRefConst().s4; + NANOCLR_SET_AND_LEAVE(CLR_E_NOT_SUPPORTED); } NANOCLR_NOCLEANUP(); @@ -61,11 +72,14 @@ HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::Nati HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeDispose___VOID( CLR_RT_StackFrame& stack ) { - NANOCLR_HEADER(); + (void)stack; + + NANOCLR_HEADER(); { //CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); //int pinNumber = pThis[ FIELD___pinNumber ].NumericByRefConst().s4; + NANOCLR_SET_AND_LEAVE(CLR_E_NOT_SUPPORTED); } NANOCLR_NOCLEANUP(); 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 3fd1b418f0..87c7fcd47b 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 @@ -6,66 +6,81 @@ #include "win_dev_gpio_native.h" -HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeInit___VOID( CLR_RT_StackFrame& stack ) +HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeInit___VOID(CLR_RT_StackFrame& stack) { - NANOCLR_HEADER(); - { - //CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + (void)stack; - //int16_t pinNumber = pThis[ FIELD___pinNumber ].NumericByRefConst().s4; + NANOCLR_HEADER(); + { + //CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + + //int16_t pinNumber = pThis[ FIELD___pinNumber ].NumericByRefConst().s4; //bool InputMode = (bool)pThis[FIELD___inputMode].NumericByRefConst().u1; NANOCLR_SET_AND_LEAVE(CLR_E_NOT_SUPPORTED); - } - NANOCLR_NOCLEANUP(); + } + NANOCLR_NOCLEANUP(); } -HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeRead___U8__BOOLEAN( CLR_RT_StackFrame& stack ) +HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeRead___U8__BOOLEAN(CLR_RT_StackFrame& stack) { - NANOCLR_HEADER(); - { - //CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); - //int pinNumber = pThis[ FIELD___pinNumber ].NumericByRefConst().s4; + (void)stack; + + NANOCLR_HEADER(); + { + NANOCLR_SET_AND_LEAVE(CLR_E_NOT_SUPPORTED); - } - NANOCLR_NOCLEANUP(); + } + NANOCLR_NOCLEANUP(); } -HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeStart___VOID( CLR_RT_StackFrame& stack ) +HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeStart___VOID(CLR_RT_StackFrame& stack) { - NANOCLR_HEADER(); - { - //CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + (void)stack; + + NANOCLR_HEADER(); + { + //CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + + //int pinNumber = pThis[ FIELD___pinNumber ].NumericByRefConst().s4; + + //GpioChangePolarity polarity = (GpioChangePolarity)pThis[ FIELD___Polarity ].NumericByRefConst().s4; + + + // TODO + NANOCLR_SET_AND_LEAVE(CLR_E_NOT_SUPPORTED); - //int pinNumber = pThis[ FIELD___pinNumber ].NumericByRefConst().s4; - //GpioChangePolarity polarity = (GpioChangePolarity)pThis[ FIELD___Polarity ].NumericByRefConst().s4; - - } - NANOCLR_NOCLEANUP(); + NANOCLR_NOCLEANUP(); } -HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeStop___VOID( CLR_RT_StackFrame& stack ) +HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeStop___VOID(CLR_RT_StackFrame& stack) { - NANOCLR_HEADER(); - { - //CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + (void)stack; - //int pinNumber = pThis[ FIELD___pinNumber ].NumericByRefConst().s4; + NANOCLR_HEADER(); + { + //CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + + //int pinNumber = pThis[ FIELD___pinNumber ].NumericByRefConst().s4; + NANOCLR_SET_AND_LEAVE(CLR_E_NOT_SUPPORTED); - } - NANOCLR_NOCLEANUP(); + } + NANOCLR_NOCLEANUP(); } -HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeDispose___VOID( CLR_RT_StackFrame& stack ) +HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter::NativeDispose___VOID(CLR_RT_StackFrame& stack) { - NANOCLR_HEADER(); - { - //CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); + (void)stack; + + NANOCLR_HEADER(); + { + //CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis); - //int pinNumber = pThis[ FIELD___pinNumber ].NumericByRefConst().s4; + //int pinNumber = pThis[ FIELD___pinNumber ].NumericByRefConst().s4; + NANOCLR_SET_AND_LEAVE(CLR_E_NOT_SUPPORTED); - } - NANOCLR_NOCLEANUP(); + } + NANOCLR_NOCLEANUP(); } From d6f8a2636e8f82a53ea779193f35f6045c8cac5e Mon Sep 17 00:00:00 2001 From: Adrian Soundy Date: Fri, 26 Jul 2019 00:41:18 +1200 Subject: [PATCH 5/5] Bump version --- src/Windows.Devices.Gpio/win_dev_gpio_native.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Windows.Devices.Gpio/win_dev_gpio_native.cpp b/src/Windows.Devices.Gpio/win_dev_gpio_native.cpp index 8f94879ce8..3bd063a426 100644 --- a/src/Windows.Devices.Gpio/win_dev_gpio_native.cpp +++ b/src/Windows.Devices.Gpio/win_dev_gpio_native.cpp @@ -98,5 +98,5 @@ const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_Windows_Devices_Gpio = "Windows.Devices.Gpio", 0xD7F65BB7, method_lookup, - { 100, 1, 0, 0 } + { 100, 1, 1, 0 } };