From ab1a1c1f0826b9ec789aad9ad6051a052aec94f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Sim=C3=B5es?= Date: Tue, 26 Jun 2018 15:18:45 +0100 Subject: [PATCH] Update native implementation of serial comm MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - To support nanoframework/lib-Windows.Devices.SerialCommunication#26 ** WIP for ESP32 ** Signed-off-by: José Simões --- .../win_dev_serial_native.cpp | 3 +- .../win_dev_serial_native.h | 1 + ...vices_SerialCommunication_SerialDevice.cpp | 65 +++++++++++++++++++ .../win_dev_serial_native.cpp | 3 +- .../win_dev_serial_native.h | 1 + ...vices_SerialCommunication_SerialDevice.cpp | 17 +++-- 6 files changed, 82 insertions(+), 8 deletions(-) diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.SerialCommunication/win_dev_serial_native.cpp b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.SerialCommunication/win_dev_serial_native.cpp index 79b096f5be..685eb2acdc 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.SerialCommunication/win_dev_serial_native.cpp +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.SerialCommunication/win_dev_serial_native.cpp @@ -27,6 +27,7 @@ static const CLR_RT_MethodHandler method_lookup[] = NULL, NULL, NULL, + Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::get_BytesToRead___U4, NULL, NULL, NULL, @@ -77,7 +78,7 @@ static const CLR_RT_MethodHandler method_lookup[] = const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_Windows_Devices_SerialCommunication = { "Windows.Devices.SerialCommunication", - 0x2B84D4FF, + 0x469DDCFE, method_lookup, { 1, 0, 0, 0 } }; diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.SerialCommunication/win_dev_serial_native.h b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.SerialCommunication/win_dev_serial_native.h index dd3c6becf5..b5ca3e6e23 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.SerialCommunication/win_dev_serial_native.h +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/Windows.Devices.SerialCommunication/win_dev_serial_native.h @@ -72,6 +72,7 @@ struct Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialD static const int FIELD___watchChar = 16; static const int FIELD___callbacksDataReceivedEvent = 17; + NANOCLR_NATIVE_DECLARE(get_BytesToRead___U4); NANOCLR_NATIVE_DECLARE(NativeDispose___VOID); NANOCLR_NATIVE_DECLARE(NativeInit___VOID); NANOCLR_NATIVE_DECLARE(NativeConfig___VOID); 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 926ff2f33c..432a751f0a 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 @@ -1056,6 +1056,71 @@ HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_Serial NANOCLR_NOCLEANUP(); } +HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::get_BytesToRead___U4( CLR_RT_StackFrame& stack ) +{ + NANOCLR_HEADER(); + { + 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); + + // Choose the driver for this SerialDevice + switch ((int)pThis[ FIELD___portIndex ].NumericByRef().s4) + { + #if STM32_UART_USE_USART1 + case 1 : + palUart = &Uart1_PAL; + break; + #endif + #if STM32_UART_USE_USART2 + case 2 : + palUart = &Uart2_PAL; + break; + #endif + #if STM32_UART_USE_USART3 + case 3 : + palUart = &Uart3_PAL; + break; + #endif + #if STM32_UART_USE_UART4 + case 4 : + palUart = &Uart4_PAL; + break; + #endif + #if STM32_UART_USE_UART5 + case 5 : + palUart = &Uart5_PAL; + break; + #endif + #if STM32_UART_USE_USART6 + case 6 : + palUart = &Uart6_PAL; + break; + #endif + #if STM32_UART_USE_UART7 + case 7 : + palUart = &Uart7_PAL; + break; + #endif + #if STM32_UART_USE_UART8 + case 8 : + palUart = &Uart8_PAL; + break; + #endif + default: + // this COM port is not valid + NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); + break; + } + + // get length of Rx ring 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 ) { NANOCLR_HEADER(); diff --git a/targets/FreeRTOS/ESP32_DevKitC/nanoCLR/Windows.Devices.SerialCommunication/win_dev_serial_native.cpp b/targets/FreeRTOS/ESP32_DevKitC/nanoCLR/Windows.Devices.SerialCommunication/win_dev_serial_native.cpp index 79b096f5be..685eb2acdc 100644 --- a/targets/FreeRTOS/ESP32_DevKitC/nanoCLR/Windows.Devices.SerialCommunication/win_dev_serial_native.cpp +++ b/targets/FreeRTOS/ESP32_DevKitC/nanoCLR/Windows.Devices.SerialCommunication/win_dev_serial_native.cpp @@ -27,6 +27,7 @@ static const CLR_RT_MethodHandler method_lookup[] = NULL, NULL, NULL, + Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::get_BytesToRead___U4, NULL, NULL, NULL, @@ -77,7 +78,7 @@ static const CLR_RT_MethodHandler method_lookup[] = const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_Windows_Devices_SerialCommunication = { "Windows.Devices.SerialCommunication", - 0x2B84D4FF, + 0x469DDCFE, method_lookup, { 1, 0, 0, 0 } }; diff --git a/targets/FreeRTOS/ESP32_DevKitC/nanoCLR/Windows.Devices.SerialCommunication/win_dev_serial_native.h b/targets/FreeRTOS/ESP32_DevKitC/nanoCLR/Windows.Devices.SerialCommunication/win_dev_serial_native.h index 341f217b7d..4bb14a7f1f 100644 --- a/targets/FreeRTOS/ESP32_DevKitC/nanoCLR/Windows.Devices.SerialCommunication/win_dev_serial_native.h +++ b/targets/FreeRTOS/ESP32_DevKitC/nanoCLR/Windows.Devices.SerialCommunication/win_dev_serial_native.h @@ -71,6 +71,7 @@ struct Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialD static const int FIELD___watchChar = 16; static const int FIELD___callbacksDataReceivedEvent = 17; + NANOCLR_NATIVE_DECLARE(get_BytesToRead___U4); NANOCLR_NATIVE_DECLARE(NativeDispose___VOID); NANOCLR_NATIVE_DECLARE(NativeInit___VOID); NANOCLR_NATIVE_DECLARE(NativeConfig___VOID); diff --git a/targets/FreeRTOS/ESP32_DevKitC/nanoCLR/Windows.Devices.SerialCommunication/win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice.cpp b/targets/FreeRTOS/ESP32_DevKitC/nanoCLR/Windows.Devices.SerialCommunication/win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice.cpp index 6db13ab49a..06cb60c21a 100644 --- a/targets/FreeRTOS/ESP32_DevKitC/nanoCLR/Windows.Devices.SerialCommunication/win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice.cpp +++ b/targets/FreeRTOS/ESP32_DevKitC/nanoCLR/Windows.Devices.SerialCommunication/win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice.cpp @@ -476,15 +476,20 @@ HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_Serial HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::NativeSetWatchChar___VOID( CLR_RT_StackFrame& stack ) { - (void) stack; + NANOCLR_HEADER(); + + NANOCLR_SET_AND_LEAVE(stack.NotImplementedStub()); + + NANOCLR_NOCLEANUP(); +} +HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::get_BytesToRead___U4( CLR_RT_StackFrame& stack ) +{ NANOCLR_HEADER(); - { - // set watch char - // (uint8_t)pThis[ FIELD___watchChar ].NumericByRef().u1; - } - NANOCLR_NOCLEANUP_NOLABEL(); + NANOCLR_SET_AND_LEAVE(stack.NotImplementedStub()); + + NANOCLR_NOCLEANUP(); } HRESULT Library_win_dev_serial_native_Windows_Devices_SerialCommunication_SerialDevice::GetDeviceSelector___STATIC__STRING( CLR_RT_StackFrame& stack )