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

Add native implementation of Devices.Can #1087

Merged
merged 27 commits into from
Dec 6, 2018
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
293b19e
Add native support for Devices.Can
josesimoes Dec 4, 2018
b3dbf60
Add native support for Devices.Can
josesimoes Dec 4, 2018
999d1d8
Add entry for Devices.Can in CMake for native assemblies
josesimoes Dec 4, 2018
00d3258
Add native support for Devices.Can
josesimoes Dec 4, 2018
4588d7c
Add native support for Devices.Can
josesimoes Dec 4, 2018
099f64b
Add native support for Devices.Can
josesimoes Dec 4, 2018
23a670b
Add entry for Devices.Can in CMake for native assemblies
josesimoes Dec 4, 2018
426b024
Add native support for Devices.Can
josesimoes Dec 4, 2018
b488576
Work on CAN native
sjmneves Dec 5, 2018
edb9f41
Merge
sjmneves Dec 5, 2018
96650b5
Work on replacing events with callbacks
sjmneves Dec 5, 2018
b6208ff
Further work on CAN native code
sjmneves Dec 6, 2018
14a8884
Add native support for Devices.Can
josesimoes Dec 4, 2018
6004fa9
Add native support for Devices.Can
josesimoes Dec 4, 2018
3ac5844
Add entry for Devices.Can in CMake for native assemblies
josesimoes Dec 4, 2018
2a489b4
Add native support for Devices.Can
josesimoes Dec 4, 2018
d2d80f4
Add native support for Devices.Can
josesimoes Dec 4, 2018
25485d3
Add native support for Devices.Can
josesimoes Dec 4, 2018
f9693de
Add native support for Devices.Can
josesimoes Dec 4, 2018
3d53409
Work on CAN native
sjmneves Dec 5, 2018
6da8d82
Work on replacing events with callbacks
sjmneves Dec 5, 2018
6940d25
Further work on CAN native code
sjmneves Dec 6, 2018
802dd0f
Merge branch 'work-417-add-support-can' of https://github.com/Eclo/nf…
sjmneves Dec 6, 2018
78290f1
Changes following code review
sjmneves Dec 6, 2018
f02ca3e
Enable CAN drivers for STM32 series
sjmneves Dec 6, 2018
712e4cb
CAN enabled build option
sjmneves Dec 6, 2018
8798072
Enabled CAN on mcu config for STM32F429 and STM32F769
sjmneves Dec 6, 2018
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
6 changes: 3 additions & 3 deletions CMake/Modules/CHIBIOS_STM32F4xx_sources.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ set(CHIBIOS_PORT_SRCS
hal_lld.c

hal_adc_lld.c
#hal_can_lld.c
hal_can_lld.c
josesimoes marked this conversation as resolved.
Show resolved Hide resolved
#hal_dac_lld.c
stm32_dma.c
hal_ext_lld.c
Expand Down Expand Up @@ -59,7 +59,7 @@ foreach(SRC_FILE ${CHIBIOS_PORT_SRCS})

${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/STM32F4xx
${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/ADCv2
#${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/CANv1
${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/CANv1
#${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/DACv1
${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/DMAv2
${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/EXTIv1
Expand Down Expand Up @@ -88,7 +88,7 @@ list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/common/
list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/common/ext/ST/STM32F4xx)

list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/ADCv2)
#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/CANv1)
#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/DMAv2)
list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/EXTIv1)
Expand Down
40 changes: 40 additions & 0 deletions CMake/Modules/FindnanoFramework.Devices.Can.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#
# Copyright (c) 2018 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}/nanoFramework.Devices.Can")


# set include directories
list(APPEND nanoFramework.Devices.Can_INCLUDE_DIRS "${BASE_PATH_FOR_THIS_MODULE}")
list(APPEND nanoFramework.Devices.Can_INCLUDE_DIRS "${TARGET_BASE_LOCATION}")

# source files
set(nanoFramework.Devices.Can_SRCS

nf_devices_can_native_nanoFramework_Devices_Can_CanController.cpp
nf_devices_can_native.cpp

target_nf_devices_can_config.cpp
)

foreach(SRC_FILE ${nanoFramework.Devices.Can_SRCS})
set(nanoFramework.Devices.Can_SRC_FILE SRC_FILE-NOTFOUND)
find_file(nanoFramework.Devices.Can_SRC_FILE ${SRC_FILE}
PATHS
"${BASE_PATH_FOR_THIS_MODULE}"
"${TARGET_BASE_LOCATION}"

CMAKE_FIND_ROOT_PATH_BOTH
)
# message("${SRC_FILE} >> ${nanoFramework.Devices.Can_SRC_FILE}") # debug helper
list(APPEND nanoFramework.Devices.Can_SOURCES ${nanoFramework.Devices.Can_SRC_FILE})
endforeach()


include(FindPackageHandleStandardArgs)

FIND_PACKAGE_HANDLE_STANDARD_ARGS(nanoFramework.Devices.Can DEFAULT_MSG nanoFramework.Devices.Can_INCLUDE_DIRS nanoFramework.Devices.Can_SOURCES)
7 changes: 7 additions & 0 deletions CMake/Modules/NF_NativeAssemblies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# and the namespace designation is 'Windows.Devices.Gpio'
###########################################################################################

option(API_nanoFramework.Devices.Can "option for nanoFramework.Devices.Can")
option(API_nanoFramework.Devices.OneWire "option for nanoFramework.Devices.OneWire")
option(API_nanoFramework.Networking.Sntp "option for nanoFramework.Networking.Sntp")
option(API_nanoFramework.Runtime.Events "option for nanoFramework.Runtime.Events API")
Expand Down Expand Up @@ -83,6 +84,12 @@ macro(ParseNativeAssemblies)
PerformSettingsForApiEntry("nanoFramework.Hardware.Stm32")
endif()

# nanoFramework.Devices.Can
if(API_nanoFramework.Devices.Can)
##### API name here (doted name)
PerformSettingsForApiEntry("nanoFramework.Devices.Can")
endif()

# nanoFramework.Devices.OneWire
if(API_nanoFramework.Devices.OneWire)
##### API name here (doted name)
Expand Down
10 changes: 9 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,13 @@ else()
endif()


if(API_nanoFramework.Devices.Can)
set(HAL_USE_CAN_OPTION TRUE CACHE INTERNAL "HAL CAN for nanoFramework.Devices.Can")
else()
set(HAL_USE_CAN_OPTION FALSE CACHE INTERNAL "HAL CAN for nanoFramework.Devices.Can")
endif()


#################################################################
# manage dependent APIs required for some API namespaces
#################################################################
Expand All @@ -466,7 +473,8 @@ if( API_nanoFramework.Devices.OneWire OR
API_System.Net OR
API_Windows.Devices.Gpio OR
API_Windows.Devices.SerialCommunication OR
API_Windows.Networking.Sockets)
API_Windows.Networking.Sockets OR
API_nanoFramework.Devices.Can)

# these APIs requires nanoFramework.Runtime.Events
set(API_nanoFramework.Runtime.Events ON CACHE INTERNAL "enable of API_nanoFramework.Runtime.Events")
Expand Down
1 change: 1 addition & 0 deletions cmake-variants.TEMPLATE.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"NF_SECURITY_OPENSSL" : "OFF-default-ON-to-add-network-security-from-OpenSSL",
"NF_SECURITY_MBEDTLS" : "OFF-default-ON-to-add-network-security-from-mbedTLS",
"MBEDTLS_SOURCE" : "<path-to-mbedtls-source-mind-the-forward-slashes>",
"API_nanoFramework.Devices.Can" : "OFF-default-ON-to-add-this-API",
"API_nanoFramework.Devices.OneWire" : "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",
Expand Down
1 change: 1 addition & 0 deletions src/PAL/Include/nanoPAL_Events.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#define EVENT_SERIAL 30
#define EVENT_NETWORK 40
#define EVENT_WIFI 50
#define EVENT_CAN 60

////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@
/**
* @brief Enables the CAN subsystem.
*/
#if !defined(HAL_USE_CAN) || defined(__DOXYGEN__)
#define HAL_USE_CAN FALSE
#endif
// this option is set at target_platform.h (from config file)
josesimoes marked this conversation as resolved.
Show resolved Hide resolved
// #if !defined(HAL_USE_CAN) || defined(__DOXYGEN__)
// #define HAL_USE_CAN FALSE
// #endif

/**
* @brief Enables the cryptographic subsystem.
Expand Down Expand Up @@ -243,7 +244,7 @@
* @brief Enforces the driver to use direct callbacks rather than OSAL events.
*/
#if !defined(CAN_ENFORCE_USE_CALLBACKS) || defined(__DOXYGEN__)
#define CAN_ENFORCE_USE_CALLBACKS FALSE
#define CAN_ENFORCE_USE_CALLBACKS TRUE
josesimoes marked this conversation as resolved.
Show resolved Hide resolved
#endif

/*===========================================================================*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,10 @@
#define HAL_USE_STM32_ONEWIRE TRUE
#endif

// enables STM32 Can driver
josesimoes marked this conversation as resolved.
Show resolved Hide resolved
#if !defined(HAL_USE_STM32_CAN)
#define HAL_USE_STM32_CAN TRUE
#endif

#endif // _HALCONF_NF_H_

Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@
/*
* CAN driver system settings.
*/
#define STM32_CAN_USE_CAN1 FALSE
#define STM32_CAN_USE_CAN2 FALSE
#define STM32_CAN_USE_CAN1 TRUE
josesimoes marked this conversation as resolved.
Show resolved Hide resolved
#define STM32_CAN_USE_CAN2 TRUE
#define STM32_CAN_CAN1_IRQ_PRIORITY 11
#define STM32_CAN_CAN2_IRQ_PRIORITY 11

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
josesimoes marked this conversation as resolved.
Show resolved Hide resolved
// Copyright (c) 2018 The nanoFramework project contributors
// See LICENSE file in the project root for full license information.
//

#include <hal.h>
#include "target_nf_devices_can_config.h"
#include <nf_devices_can_native.h>

///////////
// CAN1 //
///////////

// pin configuration for CAN1
// port for TX pin is: GPIOB
// TX pin: is GPIOB_09
// port for RX pin is: GPIOB
// RX pin: is GPIOB_08
// GPIO alternate pin function is 9 (see "Table 9. STM32F405xx and STM32F407xx alternate function mapping" in STM32F405xx/STM32F407xx datasheet)
CAN_CONFIG_PINS(1, GPIOB, GPIOB, 9, 8, 9)

// buffer
CANRxFrame Can1_MsgBuffer[CAN1_RX_BUFFER_SIZE];

// initialization for CAN1
CAN_INIT(1, CAN1_RX_BUFFER_SIZE)

///////////
// CAN2 //
///////////

// pin configuration for CAN2
// port for TX pin is: GPIOB
// TX pin: is GPIOB_06
// port for RX pin is: GPIOB
// RX pin: is GPIOB_05
// GPIO alternate pin function is 9 (see "Table 9. STM32F405xx and STM32F407xx alternate function mapping" in STM32F405xx/STM32F407xx datasheet)
CAN_CONFIG_PINS(2, GPIOB, GPIOB, 6, 5, 9)

// buffer
CANRxFrame Can2_MsgBuffer[CAN2_RX_BUFFER_SIZE];

// initialization for CAN1
CAN_INIT(2, CAN2_RX_BUFFER_SIZE)
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// Copyright (c) 2018 The nanoFramework project contributors
// See LICENSE file in the project root for full license information.
//


//////////
// CAN1 //
//////////

// enable CAN1
#define NF_CAN_STM32_CAN_USE_CAN1 TRUE

// buffers size
#define CAN1_RX_BUFFER_SIZE 16

//////////
// CAN2 //
//////////

// enable CAN2
#define NF_CAN_STM32_CAN_USE_CAN2 TRUE

// buffers size
#define CAN2_RX_BUFFER_SIZE 16
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
//
// Copyright (c) 2018 The nanoFramework project contributors
// See LICENSE file in the project root for full license information.
//

#include "nf_devices_can_native.h"

static const CLR_RT_MethodHandler method_lookup[] =
{
NULL,
NULL,
NULL,
NULL,
Library_nf_devices_can_native_nanoFramework_Devices_Can_CanController::WriteMessage___VOID__nanoFrameworkDevicesCanCanMessage,
NULL,
NULL,
NULL,
NULL,
Library_nf_devices_can_native_nanoFramework_Devices_Can_CanController::GetMessage___nanoFrameworkDevicesCanCanMessage,
Library_nf_devices_can_native_nanoFramework_Devices_Can_CanController::DisposeNative___VOID,
Library_nf_devices_can_native_nanoFramework_Devices_Can_CanController::NativeInit___VOID,
Library_nf_devices_can_native_nanoFramework_Devices_Can_CanController::NativeUpdateCallbacks___VOID,
NULL,
Library_nf_devices_can_native_nanoFramework_Devices_Can_CanController::GetDeviceSelector___STATIC__STRING,
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,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
};

const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_nanoFramework_Devices_Can =
{
"nanoFramework.Devices.Can",
0xD2E9416A,
method_lookup,
{ 1, 0, 0, 1 }
};
Loading