Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements in STM32 I2C native implementation #671

Merged
merged 2 commits into from
Apr 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/CLR/Core/CLR_RT_StackFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1112,7 +1112,8 @@ void CLR_RT_StackFrame::NegateResult()

//--//

// input HeapBlock has timeout value in ticks
// input HeapBlock has timeout value **IN TICKS**
// sometimes you have to force a cast to (CLR_INT64) otherwise the set operations will fail because of the var size mismatch
HRESULT CLR_RT_StackFrame::SetupTimeoutFromTicks( CLR_RT_HeapBlock& input, CLR_INT64*& output )
{
NATIVE_PROFILE_CLR_CORE();
Expand Down
4 changes: 2 additions & 2 deletions src/CLR/Core/Hardware/Hardware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ void CLR_HW_Hardware::ProcessActivity()
eventsCLR |= CLR_RT_ExecutionEngine::c_Event_Socket;
}

if(events & SYSTEM_EVENT_FLAG_IO)
if(events & SYSTEM_EVENT_FLAG_I2C_MASTER)
{
eventsCLR |= CLR_RT_ExecutionEngine::c_Event_IO;
eventsCLR |= CLR_RT_ExecutionEngine::c_Event_I2cMaster;
}

if(eventsCLR)
Expand Down
2 changes: 2 additions & 0 deletions src/CLR/Core/TypeSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2655,6 +2655,8 @@ static const TypeIndexLookup c_TypeIndexLookup[] =

TIL( "System.Net.Sockets" , "SocketException" , m_SocketException ),

TIL( "Windows.Devices.I2c" , "I2cTransferResult" , m_I2cTransferResult ),

#undef TIL
};

Expand Down
4 changes: 2 additions & 2 deletions src/CLR/Include/nanoCLR_Hardware.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ struct CLR_HW_Hardware
static const CLR_UINT32 c_Default_WakeupEvents = SYSTEM_EVENT_FLAG_COM_IN |
SYSTEM_EVENT_FLAG_COM_OUT |
SYSTEM_EVENT_FLAG_SYSTEM_TIMER |
SYSTEM_EVENT_FLAG_I2C_MASTER |
SYSTEM_EVENT_HW_INTERRUPT |
SYSTEM_EVENT_FLAG_SOCKET |
SYSTEM_EVENT_FLAG_DEBUGGER_ACTIVITY |
SYSTEM_EVENT_FLAG_MESSAGING_ACTIVITY|
SYSTEM_EVENT_FLAG_IO ;
SYSTEM_EVENT_FLAG_MESSAGING_ACTIVITY;

//--//

Expand Down
18 changes: 10 additions & 8 deletions src/CLR/Include/nanoCLR_Runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -1238,6 +1238,8 @@ struct CLR_RT_WellKnownTypes

CLR_RT_TypeDef_Index m_SocketException;

CLR_RT_TypeDef_Index m_I2cTransferResult;

PROHIBIT_COPY_CONSTRUCTORS(CLR_RT_WellKnownTypes);
};

Expand Down Expand Up @@ -2727,14 +2729,14 @@ extern bool g_CLR_RT_fBadStack;

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_IO = 0x00000080;
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_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_I2cMaster = 0x00000080;
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.


////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
3 changes: 2 additions & 1 deletion src/HAL/Include/nanoHAL_v2.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ typedef enum SLEEP_LEVEL
//#define SYSTEM_EVENT_FLAG_SPI 0x00008000
//#define SYSTEM_EVENT_FLAG_OEM_RESERVED_1 0x00020000
//#define SYSTEM_EVENT_FLAG_OEM_RESERVED_2 0x00040000
#define SYSTEM_EVENT_FLAG_IO 0x00080000
//#define SYSTEM_EVENT_FLAG_UNUSED_0x00080000 0x00080000
//#define SYSTEM_EVENT_FLAG_UNUSED_0x00100000 0x00100000


Expand All @@ -63,6 +63,7 @@ typedef enum SLEEP_LEVEL
//#define SYSTEM_EVENT_FLAG_UNUSED_0x01000000 0x01000000
//#define SYSTEM_EVENT_FLAG_UNUSED_0x02000000 0x02000000
//#define SYSTEM_EVENT_FLAG_UNUSED_0x04000000 0x04000000
#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
Expand Down
5 changes: 5 additions & 0 deletions targets/CMSIS-OS/ChibiOS/MBN_QUAIL/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ endif()
# sources for target specifc stuff related with APIs
list(APPEND API_RELATED_TARGET_SOURCES "")

# Windows.Devices.I2c
if(API_Windows.Devices.I2c)
list(APPEND API_RELATED_TARGET_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/target_windows_devices_i2c_config.cpp")
endif()

# Windows.Devices.SerialCommunication
if(API_Windows.Devices.SerialCommunication)
list(APPEND API_RELATED_TARGET_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/target_windows_devices_serialcommunication_config.cpp")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// Copyright (c) 2018 The nanoFramework project contributors
// See LICENSE file in the project root for full license information.
//

#include "win_dev_i2c_native.h"

//////////
// I2C1 //
//////////

// buffers size
// tx buffer size (in bytes)
#define I2C1_WR_SIZE 100
// rx buffer size (in bytes)
#define I2C1_RD_SIZE 100

// buffers declaration
// buffers that are R/W by DMA are recommended to be aligned with 32 bytes cache page size boundary
// because of issues with cache coherency and DMA (this is particularly important with Cortex-M7 because of cache)
#if defined(__GNUC__)
__attribute__((aligned (32)))
#endif
uint8_t I2C1_WriteBuffer[I2C1_WR_SIZE];
#if defined(__GNUC__)
__attribute__((aligned (32)))
#endif
uint8_t I2C1_ReadBuffer[I2C1_RD_SIZE];

// initialization for I2C1
I2C_INIT(1, I2C1_WR_SIZE, I2C1_RD_SIZE)

// un-initialization for I2C1
I2C_UNINIT(1)
15 changes: 10 additions & 5 deletions targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,21 @@ endif()
# sources for target specifc stuff related with APIs
list(APPEND API_RELATED_TARGET_SOURCES "")

# Windows.Devices.SerialCommunication
if(API_Windows.Devices.SerialCommunication)
list(APPEND API_RELATED_TARGET_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/target_windows_devices_serialcommunication_config.cpp")
endif()

# Windows.Devices.Adc
if(API_Windows.Devices.Adc)
list(APPEND API_RELATED_TARGET_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/target_windows_devices_adc_config.cpp")
endif()

# Windows.Devices.I2c
if(API_Windows.Devices.I2c)
list(APPEND API_RELATED_TARGET_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/target_windows_devices_i2c_config.cpp")
endif()

# Windows.Devices.SerialCommunication
if(API_Windows.Devices.SerialCommunication)
list(APPEND API_RELATED_TARGET_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/target_windows_devices_serialcommunication_config.cpp")
endif()

#######################################

add_subdirectory("common")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// Copyright (c) 2018 The nanoFramework project contributors
// See LICENSE file in the project root for full license information.
//

#include "win_dev_i2c_native.h"

//////////
// I2C1 //
//////////

// buffers size
// tx buffer size (in bytes)
#define I2C1_WR_SIZE 100
// rx buffer size (in bytes)
#define I2C1_RD_SIZE 100

// buffers declaration
// buffers that are R/W by DMA are recommended to be aligned with 32 bytes cache page size boundary
// because of issues with cache coherency and DMA (this is particularly important with Cortex-M7 because of cache)
#if defined(__GNUC__)
__attribute__((aligned (32)))
#endif
uint8_t I2C1_WriteBuffer[I2C1_WR_SIZE];
#if defined(__GNUC__)
__attribute__((aligned (32)))
#endif
uint8_t I2C1_ReadBuffer[I2C1_RD_SIZE];

// initialization for I2C1
I2C_INIT(1, I2C1_WR_SIZE, I2C1_RD_SIZE)

// un-initialization for I2C1
I2C_UNINIT(1)
15 changes: 10 additions & 5 deletions targets/CMSIS-OS/ChibiOS/ST_NUCLEO144_F746ZG/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,21 @@ endif()
# sources for target specifc stuff related with APIs
list(APPEND API_RELATED_TARGET_SOURCES "")

# Windows.Devices.SerialCommunication
if(API_Windows.Devices.SerialCommunication)
list(APPEND API_RELATED_TARGET_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/target_windows_devices_serialcommunication_config.cpp")
endif()

# Windows.Devices.Adc
if(API_Windows.Devices.Adc)
list(APPEND API_RELATED_TARGET_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/target_windows_devices_adc_config.cpp")
endif()

# Windows.Devices.I2c
if(API_Windows.Devices.I2c)
list(APPEND API_RELATED_TARGET_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/target_windows_devices_i2c_config.cpp")
endif()

# Windows.Devices.SerialCommunication
if(API_Windows.Devices.SerialCommunication)
list(APPEND API_RELATED_TARGET_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/target_windows_devices_serialcommunication_config.cpp")
endif()

#######################################

add_subdirectory("common")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//
// Copyright (c) 2018 The nanoFramework project contributors
// See LICENSE file in the project root for full license information.
//

#include "win_dev_i2c_native.h"

//////////
// I2C1 //
//////////

// buffers size
// tx buffer size (in bytes)
#define I2C1_WR_SIZE 100
// rx buffer size (in bytes)
#define I2C1_RD_SIZE 100

// buffers declaration
// buffers that are R/W by DMA are recommended to be aligned with 32 bytes cache page size boundary
// because of issues with cache coherency and DMA (this is particularly important with Cortex-M7 because of cache)
#if defined(__GNUC__)
__attribute__((aligned (32)))
#endif
uint8_t I2C1_WriteBuffer[I2C1_WR_SIZE];
#if defined(__GNUC__)
__attribute__((aligned (32)))
#endif
uint8_t I2C1_ReadBuffer[I2C1_RD_SIZE];

// initialization for I2C1
I2C_INIT(1, I2C1_WR_SIZE, I2C1_RD_SIZE)

// un-initialization for I2C1
I2C_UNINIT(1)

//////////
// I2C2 //
//////////

// buffers size
// tx buffer size (in bytes)
#define I2C2_WR_SIZE 100
// rx buffer size (in bytes)
#define I2C2_RD_SIZE 100

// buffers declaration
// buffers that are R/W by DMA are recommended to be aligned with 32 bytes cache page size boundary
// because of issues with cache coherency and DMA (this is particularly important with Cortex-M7 because of cache)
#if defined(__GNUC__)
__attribute__((aligned (32)))
#endif
uint8_t I2C2_WriteBuffer[I2C2_WR_SIZE];
#if defined(__GNUC__)
__attribute__((aligned (32)))
#endif
uint8_t I2C2_ReadBuffer[I2C2_RD_SIZE];

// initialization for I2C2
I2C_INIT(2, I2C2_WR_SIZE, I2C2_RD_SIZE)

// un-initialization for I2C2
I2C_UNINIT(2)
15 changes: 10 additions & 5 deletions targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,21 @@ endif()
# sources for target specifc stuff related with APIs
list(APPEND API_RELATED_TARGET_SOURCES "")

# Windows.Devices.SerialCommunication
if(API_Windows.Devices.SerialCommunication)
list(APPEND API_RELATED_TARGET_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/target_windows_devices_serialcommunication_config.cpp")
endif()

# Windows.Devices.Adc
if(API_Windows.Devices.Adc)
list(APPEND API_RELATED_TARGET_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/target_windows_devices_adc_config.cpp")
endif()

# Windows.Devices.I2c
if(API_Windows.Devices.I2c)
list(APPEND API_RELATED_TARGET_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/target_windows_devices_i2c_config.cpp")
endif()

# Windows.Devices.SerialCommunication
if(API_Windows.Devices.SerialCommunication)
list(APPEND API_RELATED_TARGET_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/target_windows_devices_serialcommunication_config.cpp")
endif()

#######################################

add_subdirectory("common")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// Copyright (c) 2018 The nanoFramework project contributors
// See LICENSE file in the project root for full license information.
//

#include "win_dev_i2c_native.h"

//////////
// I2C3 //
//////////

// buffers size
// write buffer size (in bytes)
#define I2C3_WR_SIZE 100
// read buffer size (in bytes)
#define I2C3_RD_SIZE 100

// buffers declaration
// buffers that are R/W by DMA are recommended to be aligned with 32 bytes cache page size boundary
// because of issues with cache coherency and DMA (this is particularly important with Cortex-M7 because of cache)
#if defined(__GNUC__)
__attribute__((aligned (32)))
#endif
uint8_t I2C3_WriteBuffer[I2C3_WR_SIZE];
#if defined(__GNUC__)
__attribute__((aligned (32)))
#endif
uint8_t I2C3_ReadBuffer[I2C3_RD_SIZE];

// initialization of I2C3 PAL structure
I2C_INIT(3, I2C3_WR_SIZE, I2C3_RD_SIZE)

// un-initialization of I2C3 PAL structure
I2C_UNINIT(3)
15 changes: 10 additions & 5 deletions targets/CMSIS-OS/ChibiOS/ST_STM32F4_DISCOVERY/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,21 @@ endif()
# sources for target specifc stuff related with APIs
list(APPEND API_RELATED_TARGET_SOURCES "")

# Windows.Devices.SerialCommunication
if(API_Windows.Devices.SerialCommunication)
list(APPEND API_RELATED_TARGET_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/target_windows_devices_serialcommunication_config.cpp")
endif()

# Windows.Devices.Adc
if(API_Windows.Devices.Adc)
list(APPEND API_RELATED_TARGET_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/target_windows_devices_adc_config.cpp")
endif()

# Windows.Devices.I2c
if(API_Windows.Devices.I2c)
list(APPEND API_RELATED_TARGET_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/target_windows_devices_i2c_config.cpp")
endif()

# Windows.Devices.SerialCommunication
if(API_Windows.Devices.SerialCommunication)
list(APPEND API_RELATED_TARGET_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/target_windows_devices_serialcommunication_config.cpp")
endif()

#######################################

add_subdirectory("common")
Expand Down
Loading