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

Work on Devices.Spi #428

Merged
merged 1 commit into from
Aug 16, 2017
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
18 changes: 18 additions & 0 deletions targets/CMSIS-OS/ChibiOS/Include/targetPAL.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// Copyright (c) 2017 The nanoFramework project contributors
// See LICENSE file in the project root for full license information.
//

#ifndef _GPIO_PORT
#define _GPIO_PORT

#include <hal.h>


// Contains available GPIO ports for the current board
extern stm32_gpio_t* gpioPort[];

//Gets the GPIO according to a pin number
#define GPIO_PORT(pin) (gpioPort[pin/16])

#endif
1 change: 1 addition & 0 deletions targets/CMSIS-OS/ChibiOS/nanoCLR/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ list(APPEND TARGET_CHIBIOS_NANOCLR_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/WireProto
list(APPEND TARGET_CHIBIOS_NANOCLR_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/WireProtocol_MonitorCommands.c)
list(APPEND TARGET_CHIBIOS_NANOCLR_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/Aborts_CortexM3.cpp)
list(APPEND TARGET_CHIBIOS_NANOCLR_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/CLR_Startup_Thread.c")
list(APPEND TARGET_CHIBIOS_NANOCLR_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/targetPAL.c")

# append target HAL source files
list(APPEND TARGET_CHIBIOS_NANOCLR_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/targetHAL_Time.cpp")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <hal.h>
#include <cmsis_os.h>

#include <targetPAL.h>
#include "win_dev_gpio_native.h"

///////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -40,38 +41,6 @@ enum GpioPinValue
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////

stm32_gpio_t* gpioPort[] = { GPIOA, GPIOB
#if STM32_HAS_GPIOC
, GPIOC
#endif
#if STM32_HAS_GPIOD
, GPIOD
#endif
#if STM32_HAS_GPIOE
, GPIOE
#endif
#if STM32_HAS_GPIOF
, GPIOF
#endif
#if STM32_HAS_GPIOG
, GPIOG
#endif
#if STM32_HAS_GPIOH
, GPIOH
#endif
#if STM32_HAS_GPIOI
, GPIOI
#endif
#if STM32_HAS_GPIOJ
, GPIOJ
#endif
#if STM32_HAS_GPIOK
, GPIOK
#endif
};

#define GPIO_PORT(pin) (gpioPort[pin/16])


void IsrProcedure( GPIO_PIN pin, bool pinState, void* context )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@ static const CLR_RT_MethodHandler method_lookup[] =
NULL,
NULL,
NULL,
Library_win_dev_spi_native_Windows_Devices_Spi_SpiDevice::NativeTransfer___VOID__STRING__SZARRAY_U1__SZARRAY_U1__BOOLEAN,
Library_win_dev_spi_native_Windows_Devices_Spi_SpiDevice::NativeTransfer___VOID__STRING__SZARRAY_U2__SZARRAY_U2__BOOLEAN,
NULL,
NULL,
NULL,
Library_win_dev_spi_native_Windows_Devices_Spi_SpiDevice::NativeTransfer___VOID__SZARRAY_U1__SZARRAY_U1__BOOLEAN,
Library_win_dev_spi_native_Windows_Devices_Spi_SpiDevice::NativeTransfer___VOID__SZARRAY_U2__SZARRAY_U2__BOOLEAN,
Library_win_dev_spi_native_Windows_Devices_Spi_SpiDevice::NativeInit___VOID,
NULL,
NULL,
Expand All @@ -61,6 +64,6 @@ static const CLR_RT_MethodHandler method_lookup[] =
const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_Windows_Devices_Spi =
{
"Windows.Devices.Spi",
0xD124F515,
0x3A9E993E,
method_lookup
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@
#include <nanoCLR_Interop.h>
#include <nanoCLR_Runtime.h>
#include <nanoCLR_Checks.h>
#include <hal.h>

struct nfSPIConfig
{
SPIConfig Configuration;
SPIDriver * Driver;
};

struct Library_win_dev_spi_native_Windows_Devices_Spi_SpiBusInfo
{
Expand All @@ -31,6 +37,16 @@ struct Library_win_dev_spi_native_Windows_Devices_Spi_SpiConnectionSettings
static const int FIELD___databitLength = 3;
static const int FIELD___spiMode = 4;
static const int FIELD___spiSharingMode = 5;
static const int FIELD___bitOrder = 6;


//--//

};

struct Library_win_dev_spi_native_Windows_Devices_Spi_SpiController
{
static const int FIELD_STATIC__DeviceCollection = 0;


//--//
Expand All @@ -45,16 +61,18 @@ struct Library_win_dev_spi_native_Windows_Devices_Spi_SpiDevice
static const int FIELD___connectionSettings = 4;
static const int FIELD___disposedValue = 5;

NANOCLR_NATIVE_DECLARE(NativeTransfer___VOID__STRING__SZARRAY_U1__SZARRAY_U1__BOOLEAN);
NANOCLR_NATIVE_DECLARE(NativeTransfer___VOID__STRING__SZARRAY_U2__SZARRAY_U2__BOOLEAN);
NANOCLR_NATIVE_DECLARE(NativeTransfer___VOID__SZARRAY_U1__SZARRAY_U1__BOOLEAN);
NANOCLR_NATIVE_DECLARE(NativeTransfer___VOID__SZARRAY_U2__SZARRAY_U2__BOOLEAN);
NANOCLR_NATIVE_DECLARE(NativeInit___VOID);
NANOCLR_NATIVE_DECLARE(DisposeNative___VOID);
NANOCLR_NATIVE_DECLARE(GetDeviceSelector___STATIC__STRING);

//--//

static uint16_t ComputePrescaler (uint8_t bus, int32_t requestedFrequency);
static nfSPIConfig GetConfig(int bus, CLR_RT_HeapBlock* config);
};

extern const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_Windows_Devices_Spi;

#endif //_WIN_DEV_SPI_NATIVE_H_
#endif //_WIN_DEV_SPI_NATIVE_H_
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,16 @@ HRESULT Library_win_dev_spi_native_Windows_Devices_Spi_SpiBusInfo::get_MaxClockF
{
NANOCLR_HEADER();
{
CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis);

signed int retVal = 48000000;

stack.SetResult_I4( retVal );
CLR_RT_HeapBlock* pArg = &(stack.Arg1());

// spiBus is an ASCII string with the bus name in format 'SPIn'
// need to grab 'n' from the string and convert to the integer value from the ASCII code
uint8_t bus = (uint8_t)pArg[0].RecoverString()[3] - 48;

// According to STM : "At a minimum, the clock frequency should be twice the required communication frequency."
// So maximum useable frequency is CoreClock / 2.
// SPI2 or SPI3 are on APB1, so divide max frequency by four.
stack.SetResult_I4 ((bus == 2 or bus == 3) ? SystemCoreClock >>= 2 : SystemCoreClock >> 1);
}
NANOCLR_NOCLEANUP();
}
Expand All @@ -24,11 +29,15 @@ HRESULT Library_win_dev_spi_native_Windows_Devices_Spi_SpiBusInfo::get_MinClockF
{
NANOCLR_HEADER();
{
CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis);

signed int retVal = 1000000;

stack.SetResult_I4( retVal );
CLR_RT_HeapBlock* pArg = &(stack.Arg1());

// spiBus is an ASCII string with the bus name in format 'SPIn'
// need to grab 'n' from the string and convert to the integer value from the ASCII code
uint8_t bus = (uint8_t)pArg[0].RecoverString()[3] - 48;

// Max prescaler value = 256
// SPI2 or SPI3 are on APB1, so divide max frequency by four.
stack.SetResult_I4 ((bus == 2 or bus == 3) ? SystemCoreClock >>= 9 : SystemCoreClock >> 8);
}
NANOCLR_NOCLEANUP();
}
Loading