diff --git a/.travis.yml b/.travis.yml index 7827206d2e..ac9e207016 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,12 +17,12 @@ matrix: - env: TRAVIS_EMPTY_JOB_WORKAROUND=true include: - - env: CMAKE_OPTIONS="-DTOOLCHAIN_PREFIX=/home/travis/gcc-arm-none-eabi-5_2-2015q4 -DCHIBIOS_BOARD=ST_STM32F4_DISCOVERY -DTARGET_SERIES=STM32F4xx -DUSE_FPU=TRUE -DCMAKE_BUILD_TYPE=MinSizeRel -DNF_FEATURE_DEBUGGER=TRUE " - - env: CMAKE_OPTIONS="-DTOOLCHAIN_PREFIX=/home/travis/gcc-arm-none-eabi-5_2-2015q4 -DCHIBIOS_BOARD=ST_STM32F429I_DISCOVERY -DTARGET_SERIES=STM32F4xx -DUSE_FPU=TRUE -DCMAKE_BUILD_TYPE=MinSizeRel -DNF_FEATURE_DEBUGGER=TRUE " - - env: CMAKE_OPTIONS="-DTOOLCHAIN_PREFIX=/home/travis/gcc-arm-none-eabi-5_2-2015q4 -DCHIBIOS_BOARD=ST_NUCLEO64_F091RC -DTARGET_SERIES=STM32F0xx -DCMAKE_BUILD_TYPE=MinSizeRel -DNF_FEATURE_DEBUGGER=TRUE " - - env: CMAKE_OPTIONS="-DTOOLCHAIN_PREFIX=/home/travis/gcc-arm-none-eabi-5_2-2015q4 -DCHIBIOS_BOARD=ST_NUCLEO144_F746ZG -DTARGET_SERIES=STM32F7xx -DUSE_FPU=TRUE -DCMAKE_BUILD_TYPE=MinSizeRel -DNF_FEATURE_DEBUGGER=TRUE " - - env: CMAKE_OPTIONS="-DTOOLCHAIN_PREFIX=/home/travis/gcc-arm-none-eabi-5_2-2015q4 -DCHIBIOS_BOARD=MBN_QUAIL -DTARGET_SERIES=STM32F4xx -DUSE_FPU=TRUE -DCMAKE_BUILD_TYPE=MinSizeRel -DNF_FEATURE_DEBUGGER=TRUE " - - env: CMAKE_OPTIONS="-DTOOLCHAIN_PREFIX=/home/travis/gcc-arm-none-eabi-5_2-2015q4 -DCHIBIOS_BOARD=ST_STM32F769I_DISCOVERY -DTARGET_SERIES=STM32F7xx -DUSE_FPU=TRUE -DCMAKE_BUILD_TYPE=MinSizeRel -DNF_FEATURE_DEBUGGER=TRUE " + - env: CMAKE_OPTIONS="-DTOOLCHAIN_PREFIX=/home/travis/gcc-arm-none-eabi-5_2-2015q4 -DCHIBIOS_BOARD=ST_STM32F4_DISCOVERY -DTARGET_SERIES=STM32F4xx -DUSE_FPU=TRUE -DCMAKE_BUILD_TYPE=MinSizeRel -DNF_FEATURE_DEBUGGER=TRUE -DNF_FEATURE_RTC=ON " + - env: CMAKE_OPTIONS="-DTOOLCHAIN_PREFIX=/home/travis/gcc-arm-none-eabi-5_2-2015q4 -DCHIBIOS_BOARD=ST_STM32F429I_DISCOVERY -DTARGET_SERIES=STM32F4xx -DUSE_FPU=TRUE -DCMAKE_BUILD_TYPE=MinSizeRel -DNF_FEATURE_DEBUGGER=TRUE -DNF_FEATURE_RTC=ON " + - env: CMAKE_OPTIONS="-DTOOLCHAIN_PREFIX=/home/travis/gcc-arm-none-eabi-5_2-2015q4 -DCHIBIOS_BOARD=ST_NUCLEO64_F091RC -DTARGET_SERIES=STM32F0xx -DCMAKE_BUILD_TYPE=MinSizeRel -DNF_FEATURE_DEBUGGER=TRUE -DNF_FEATURE_RTC=ON " + - env: CMAKE_OPTIONS="-DTOOLCHAIN_PREFIX=/home/travis/gcc-arm-none-eabi-5_2-2015q4 -DCHIBIOS_BOARD=ST_NUCLEO144_F746ZG -DTARGET_SERIES=STM32F7xx -DUSE_FPU=TRUE -DCMAKE_BUILD_TYPE=MinSizeRel -DNF_FEATURE_DEBUGGER=TRUE -DNF_FEATURE_RTC=ON " + - env: CMAKE_OPTIONS="-DTOOLCHAIN_PREFIX=/home/travis/gcc-arm-none-eabi-5_2-2015q4 -DCHIBIOS_BOARD=MBN_QUAIL -DTARGET_SERIES=STM32F4xx -DUSE_FPU=TRUE -DCMAKE_BUILD_TYPE=MinSizeRel -DNF_FEATURE_DEBUGGER=TRUE -DNF_FEATURE_RTC=ON " + - env: CMAKE_OPTIONS="-DTOOLCHAIN_PREFIX=/home/travis/gcc-arm-none-eabi-5_2-2015q4 -DCHIBIOS_BOARD=ST_STM32F769I_DISCOVERY -DTARGET_SERIES=STM32F7xx -DUSE_FPU=TRUE -DCMAKE_BUILD_TYPE=MinSizeRel -DNF_FEATURE_DEBUGGER=TRUE -DNF_FEATURE_RTC=ON " ## cache GCC toolchain to speedup next builds cache: diff --git a/CMake/Modules/FindNF_CoreCLR.cmake b/CMake/Modules/FindNF_CoreCLR.cmake index 1f27b9ca9d..2f2bed6562 100644 --- a/CMake/Modules/FindNF_CoreCLR.cmake +++ b/CMake/Modules/FindNF_CoreCLR.cmake @@ -141,7 +141,7 @@ set(NF_CoreCLR_SRCS Messaging_stub.cpp # HAL - HAL_Time.cpp + nanoHAL_Time.cpp # PAL nanoPAL_BlockStorage.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 58b8a615b6..f1bd3e7e93 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -218,6 +218,16 @@ if(NF_FEATURE_DEBUGGER) endif() endif() +################################################################# +# RTC (real time clock) (default is OFF so RTC is NOT included) +option(NF_FEATURE_RTC "option to use hardware RTC") + +if(NF_FEATURE_RTC) + set(HAL_USE_RTC_OPTION TRUE CACHE INTERNAL "NF feature RTC") +else() + set(HAL_USE_RTC_OPTION FALSE CACHE INTERNAL "NF feature RTC") +endif() + ################################################################# ################################################################# diff --git a/cmake-variants.TEMPLATE.json b/cmake-variants.TEMPLATE.json index 96f235b03c..d97be89a98 100644 --- a/cmake-variants.TEMPLATE.json +++ b/cmake-variants.TEMPLATE.json @@ -36,7 +36,8 @@ "CHIBIOS_SOURCE" : "", "CHIBIOS_BOARD" : "", "NF_FEATURE_DEBUGGER" : "TRUE-to-include-nF-debugger", - "API_Windows.Devices.Gpio" : "OFF" + "NF_FEATURE_RTC" : "OFF-default-ON-to-enable-hardware-RTC", + "API_Windows.Devices.Gpio" : "OFF-default-ON-to-add-this-API" } }, "OPTION2_NAME_HERE": { @@ -51,7 +52,8 @@ "CHIBIOS_SOURCE" : "", "CHIBIOS_BOARD" : "", "NF_FEATURE_DEBUGGER" : "TRUE-to-include-nF-debugger", - "API_Windows.Devices.Gpio" : "OFF" + "NF_FEATURE_RTC" : "OFF-default-ON-to-enable-hardware-RTC", + "API_Windows.Devices.Gpio" : "OFF-default-ON-to-add-this-API" } }, "default$": "", diff --git a/docs/architecture/date-and-time.md b/docs/architecture/date-and-time.md new file mode 100644 index 0000000000..2ed8dabb27 --- /dev/null +++ b/docs/architecture/date-and-time.md @@ -0,0 +1,36 @@ +# Date and Time + +**About this document** + +This document describes how **nanoFramework** handles Date & Time and the available option regarding this matter. + + +## UTC and local time + +Time (and date) is fundamental for the inner works of **nanoFramework**. But an application running on top of it can make use of it, or not, thus making relevant the discussion and evaluation of the related features and associated code. +Because **nanoFramework** runs on constrained resources platforms inclusion of features that increase both RAM and FLASH usage has to be considered and evaluated. + +[`DateTime`](https://msdn.microsoft.com/en-us/library/system.datetime(v=vs.110).aspx) supports the use of Local and UTC times by its [`DateTime.Kind`](https://msdn.microsoft.com/en-us/library/system.datetime.kind(v=vs.110).aspx) property. Supporting this requires adding several _blocks_ such as: an API for setting the platform timezone, handling the huge number of available timezones, managing the daylight savings changes, manage conversion to/from the different kinds, etc. + +Considering all the above, **nanoFramework** addresses this matter providing the _absolute minimal viable_ options. +There is support for `DateTime` (obviously) but all DateTime are considered UTC. There is no support for `DateTime.Kind.Local`, setting timezone or converting to/from the different kinds. +If an application requires this, it has to implement it at its own level. + + +## Time source + +The _time base_ source is, by default, the `SysTick` available in the CMSIS RTOS API. +This is the _source_ of the time when a `DateTime` object is instantiated. + +Because almost all hardware platforms capable of running **nanoFramework** include an hardware [RTC](https://en.wikipedia.org/wiki/Real-time_clock) this peripheral can be used as the _source_ for time objects. +Note that for all other internals of **nanoFramework** the CMSIS RTOS API `SysTick` keeps being used as the time base. + +This option is exposed to the board designer by the `NF_FEATURE_RTC` configuration option. Setting it to `ON` when calling CMake brings in the RTC subsystem and all the calls to `DateTime` make use of the time base provided by this peripheral. + + +## RTC and hardware + +Leveraging the RTC hardware peripheral allows several interesting/valuable features: +- more accurate timekeeping (when compared with a regular timer); +- possibility for timekeeping in sleep/deep sleep modes; +- setting alarms to wake-up the system at a future time; diff --git a/src/CLR/CorLib/corlib_native_System_DateTime.cpp b/src/CLR/CorLib/corlib_native_System_DateTime.cpp index eb737dd44e..4aa8aca021 100644 --- a/src/CLR/CorLib/corlib_native_System_DateTime.cpp +++ b/src/CLR/CorLib/corlib_native_System_DateTime.cpp @@ -176,25 +176,10 @@ HRESULT Library_corlib_native_System_DateTime::get_UtcNow___STATIC__SystemDateTi NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - // TODO: move to target platform layer - //CLR_INT64* pRes = NewObject( stack ); - //SYSTEMTIME st; - //RTCDateTime _dateTime; - - //rtcGetTime(&RTCD1, &_dateTime); - //st.wMilliseconds =(unsigned short) (_dateTime.millisecond % 1000); - //_dateTime.millisecond /= 1000; - //st.wSecond = (unsigned short) (_dateTime.millisecond % 60); - //_dateTime.millisecond /= 60; - //st.wMinute = (unsigned short) (_dateTime.millisecond % 60); - //_dateTime.millisecond /= 60; - //st.wMinute = (unsigned short) (_dateTime.millisecond % 24); - //st.wDay = (unsigned short) _dateTime.day; - //st.wMonth = (unsigned short) _dateTime.month; - //st.wYear = (unsigned short) _dateTime.year; - //st.wDayOfWeek = (unsigned short) _dateTime.dayofweek; - - //*pRes = HAL_Time_FromSystemTime( &st ); + CLR_INT64* pRes = NewObject( stack ); + + // request full date&time + *pRes = HAL_Time_CurrentDateTime(false) | s_UTCMask; NANOCLR_NOCLEANUP_NOLABEL(); } @@ -204,17 +189,10 @@ HRESULT Library_corlib_native_System_DateTime::get_Today___STATIC__SystemDateTim NATIVE_PROFILE_CLR_CORE(); NANOCLR_HEADER(); - // TODO: move to target platform layer - // CLR_INT64* pRes = NewObject( stack ); - //SYSTEMTIME st; - // RTCDateTime _dateTime; - - // rtcGetTime(&RTCD1, &_dateTime); - // st.wDay = (unsigned short) _dateTime.day; - // st.wMonth = (unsigned short) _dateTime.month; - // st.wYear = (unsigned short) _dateTime.year; + CLR_INT64* pRes = NewObject( stack ); - // *pRes = HAL_Time_FromSystemTime( &st ); + // request date part only + *pRes = HAL_Time_CurrentDateTime(true) | s_UTCMask; NANOCLR_NOCLEANUP_NOLABEL(); } @@ -293,6 +271,6 @@ void Library_corlib_native_System_DateTime::Compress( CLR_RT_StackFrame& stack, if(val) { - *val = HAL_Time_FromSystemTime( &st ); + *val = HAL_Time_ConvertFromSystemTime( &st ); } } diff --git a/src/CLR/Core/CLR_RT_HeapBlock_Timer.cpp b/src/CLR/Core/CLR_RT_HeapBlock_Timer.cpp index ab2f1ed4f4..0a301f394b 100644 --- a/src/CLR/Core/CLR_RT_HeapBlock_Timer.cpp +++ b/src/CLR/Core/CLR_RT_HeapBlock_Timer.cpp @@ -182,7 +182,7 @@ void CLR_RT_HeapBlock_Timer::AdjustNextFixedExpire( const SYSTEMTIME& systemTime } st.wMilliseconds = 0; - baseTime = HAL_Time_FromSystemTime( &st ); + baseTime = HAL_Time_ConvertFromSystemTime( &st ); m_timeExpire = fNext ? baseTime + add : baseTime; m_timeFrequency = add; diff --git a/src/HAL/Include/nanoHAL_Time.h b/src/HAL/Include/nanoHAL_Time.h index 31ada3ce45..c16214da06 100644 --- a/src/HAL/Include/nanoHAL_Time.h +++ b/src/HAL/Include/nanoHAL_Time.h @@ -46,6 +46,14 @@ signed long long HAL_Time_SysTicksToTime(unsigned int sysTicks); +/// +/// System time and date for DateTime managed class. +/// This value will be provided by the system tick or from an RTC if hardware support exists and if the board designer has enabled it in the configuration options. +/// The datePartOnly allows returning only the date part with the time fields zeroed. +/// +/// Returns current time in 100ns elapsed since 1/1/1601:00:00:00.000 UTC. +signed long long HAL_Time_CurrentDateTime(bool datePartOnly); + /// /// Time according to this system. /// @@ -80,7 +88,7 @@ HRESULT HAL_Time_AccDaysInMonth(signed int year, signed int month, signed int* d /// Converts SYSTEMTIME structure to 64bit time, which is assumed as an offset from 1/1/1601:00:00:00.000 in 100ns. /// /// Time value. -signed long long HAL_Time_FromSystemTime(const SYSTEMTIME* systemTime); +signed long long HAL_Time_ConvertFromSystemTime(const SYSTEMTIME* systemTime); /// APIs to convert between types // FIXME bool HAL_Time_TimeSpanToStringEx( const signed long long& ticks, char*& buf, size_t& len ); diff --git a/src/HAL/HAL_Time.cpp b/src/HAL/nanoHAL_Time.cpp similarity index 95% rename from src/HAL/HAL_Time.cpp rename to src/HAL/nanoHAL_Time.cpp index 75aa1d80e8..140836d187 100644 --- a/src/HAL/HAL_Time.cpp +++ b/src/HAL/nanoHAL_Time.cpp @@ -27,7 +27,10 @@ signed long long HAL_Time_CurrentTime() return HAL_Time_SysTicksToTime( HAL_Time_CurrentSysTicks() ); }; -signed long long HAL_Time_FromSystemTime(const SYSTEMTIME* systemTime) +/// +/// Converts a SYSTEMTIME value to HAL time value +/// +signed long long HAL_Time_ConvertFromSystemTime(const SYSTEMTIME* systemTime) { signed long long r = YEARS_TO_DAYS(systemTime->wYear) + MONTH_TO_DAYS(systemTime->wYear, systemTime->wMonth) + systemTime->wDay - 1; r = (((( (r * HOURS_TO_DAY) + systemTime->wHour) * MINUTES_TO_HOUR + systemTime->wMinute) * SECONDS_TO_MINUTES + systemTime->wSecond ) * MILLISECONDS_TO_SECONDS + systemTime->wMilliseconds) * TIMEUNIT_TO_MILLISECONDS; diff --git a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoCLR/halconf.h b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoCLR/halconf.h index 4f2b837358..6f1921d70b 100644 --- a/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoCLR/halconf.h +++ b/targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoCLR/halconf.h @@ -18,6 +18,7 @@ #ifndef HALCONF_H #define HALCONF_H +#include #include "mcuconf.h" /** @@ -107,9 +108,10 @@ /** * @brief Enables the RTC subsystem. */ -#if !defined(HAL_USE_RTC) || defined(__DOXYGEN__) -#define HAL_USE_RTC TRUE -#endif +// this option is set at target_board.h (from config file) +// #if !defined(HAL_USE_RTC) || defined(__DOXYGEN__) +// #define HAL_USE_RTC TRUE +// #endif /** * @brief Enables the SDC subsystem. diff --git a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO144_F746ZG/nanoCLR/halconf.h b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO144_F746ZG/nanoCLR/halconf.h index 521ba5dfe3..c51fefc49a 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO144_F746ZG/nanoCLR/halconf.h +++ b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO144_F746ZG/nanoCLR/halconf.h @@ -18,6 +18,7 @@ #ifndef HALCONF_H #define HALCONF_H +#include #include "mcuconf.h" /** @@ -114,9 +115,10 @@ /** * @brief Enables the RTC subsystem. */ -#if !defined(HAL_USE_RTC) || defined(__DOXYGEN__) -#define HAL_USE_RTC TRUE -#endif +// this option is set at target_board.h (from config file) +// #if !defined(HAL_USE_RTC) || defined(__DOXYGEN__) +// #define HAL_USE_RTC TRUE +// #endif /** * @brief Enables the SDC subsystem. diff --git a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoCLR/halconf.h b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoCLR/halconf.h index 36d116c0af..0846d20992 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoCLR/halconf.h +++ b/targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/nanoCLR/halconf.h @@ -18,6 +18,7 @@ #ifndef HALCONF_H #define HALCONF_H +#include #include "mcuconf.h" /** @@ -107,9 +108,10 @@ /** * @brief Enables the RTC subsystem. */ -#if !defined(HAL_USE_RTC) || defined(__DOXYGEN__) -#define HAL_USE_RTC TRUE -#endif +// this option is set at target_board.h (from config file) +// #if !defined(HAL_USE_RTC) || defined(__DOXYGEN__) +// #define HAL_USE_RTC TRUE +// #endif /** * @brief Enables the SDC subsystem. diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoCLR/halconf.h b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoCLR/halconf.h index abfd799582..6b293e5bdb 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoCLR/halconf.h +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F429I_DISCOVERY/nanoCLR/halconf.h @@ -18,6 +18,7 @@ #ifndef HALCONF_H #define HALCONF_H +#include #include "mcuconf.h" /** @@ -107,9 +108,10 @@ /** * @brief Enables the RTC subsystem. */ -#if !defined(HAL_USE_RTC) || defined(__DOXYGEN__) -#define HAL_USE_RTC TRUE -#endif +// this option is set at target_board.h (from config file) +// #if !defined(HAL_USE_RTC) || defined(__DOXYGEN__) +// #define HAL_USE_RTC TRUE +// #endif /** * @brief Enables the SDC subsystem. diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F4_DISCOVERY/nanoCLR/halconf.h b/targets/CMSIS-OS/ChibiOS/ST_STM32F4_DISCOVERY/nanoCLR/halconf.h index 7523cbe2c8..843149bf48 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F4_DISCOVERY/nanoCLR/halconf.h +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F4_DISCOVERY/nanoCLR/halconf.h @@ -18,6 +18,7 @@ #ifndef HALCONF_H #define HALCONF_H +#include #include "mcuconf.h" /** @@ -107,9 +108,10 @@ /** * @brief Enables the RTC subsystem. */ -#if !defined(HAL_USE_RTC) || defined(__DOXYGEN__) -#define HAL_USE_RTC TRUE -#endif +// this option is set at target_board.h (from config file) +// #if !defined(HAL_USE_RTC) || defined(__DOXYGEN__) +// #define HAL_USE_RTC TRUE +// #endif /** * @brief Enables the SDC subsystem. diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/halconf.h b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/halconf.h index 6d1717d190..e207dde581 100644 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/halconf.h +++ b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/halconf.h @@ -18,6 +18,7 @@ #ifndef HALCONF_H #define HALCONF_H +#include #include "mcuconf.h" /** @@ -114,9 +115,10 @@ /** * @brief Enables the RTC subsystem. */ -#if !defined(HAL_USE_RTC) || defined(__DOXYGEN__) -#define HAL_USE_RTC TRUE -#endif +// this option is set at target_board.h (from config file) +// #if !defined(HAL_USE_RTC) || defined(__DOXYGEN__) +// #define HAL_USE_RTC TRUE +// #endif /** * @brief Enables the SDC subsystem. diff --git a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/halconf.h.bak b/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/halconf.h.bak deleted file mode 100644 index 6f7da2980d..0000000000 --- a/targets/CMSIS-OS/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/halconf.h.bak +++ /dev/null @@ -1,378 +0,0 @@ -// -// Copyright (c) 2017 The nanoFramework project contributors -// Portions Copyright (c) 2006..2015 Giovanni Di Sirio. All rights reserved. -// See LICENSE file in the project root for full license information. -// - -/** - * @file templates/halconf.h - * @brief HAL configuration header. - * @details HAL configuration file, this file allows to enable or disable the - * various device drivers from your application. You may also use - * this file in order to override the device drivers default settings. - * - * @addtogroup HAL_CONF - * @{ - */ - -#ifndef HALCONF_H -#define HALCONF_H - -#include "mcuconf.h" - -/** - * @brief Enables the PAL subsystem. - */ -#if !defined(HAL_USE_PAL) || defined(__DOXYGEN__) -#define HAL_USE_PAL TRUE -#endif - -/** - * @brief Enables the ADC subsystem. - */ -#if !defined(HAL_USE_ADC) || defined(__DOXYGEN__) -#define HAL_USE_ADC FALSE -#endif - -/** - * @brief Enables the CAN subsystem. - */ -#if !defined(HAL_USE_CAN) || defined(__DOXYGEN__) -#define HAL_USE_CAN FALSE -#endif - -/** - * @brief Enables the DAC subsystem. - */ -#if !defined(HAL_USE_DAC) || defined(__DOXYGEN__) -#define HAL_USE_DAC FALSE -#endif - -/** - * @brief Enables the EXT subsystem. - */ -#if !defined(HAL_USE_EXT) || defined(__DOXYGEN__) -#define HAL_USE_EXT FALSE -#endif - -/** - * @brief Enables the GPT subsystem. - */ -#if !defined(HAL_USE_GPT) || defined(__DOXYGEN__) -#define HAL_USE_GPT FALSE -#endif - -/** - * @brief Enables the I2C subsystem. - */ -#if !defined(HAL_USE_I2C) || defined(__DOXYGEN__) -#define HAL_USE_I2C FALSE -#endif - -/** - * @brief Enables the I2S subsystem. - */ -#if !defined(HAL_USE_I2S) || defined(__DOXYGEN__) -#define HAL_USE_I2S FALSE -#endif - -/** - * @brief Enables the ICU subsystem. - */ -#if !defined(HAL_USE_ICU) || defined(__DOXYGEN__) -#define HAL_USE_ICU FALSE -#endif - -/** - * @brief Enables the MAC subsystem. - */ -#if !defined(HAL_USE_MAC) || defined(__DOXYGEN__) -#define HAL_USE_MAC FALSE -#endif - -/** - * @brief Enables the MMC_SPI subsystem. - */ -#if !defined(HAL_USE_MMC_SPI) || defined(__DOXYGEN__) -#define HAL_USE_MMC_SPI FALSE -#endif - -/** - * @brief Enables the PWM subsystem. - */ -#if !defined(HAL_USE_PWM) || defined(__DOXYGEN__) -#define HAL_USE_PWM FALSE -#endif - -/** - * @brief Enables the QSPI subsystem. - */ -#if !defined(HAL_USE_QSPI) || defined(__DOXYGEN__) -#define HAL_USE_QSPI FALSE -#endif - -/** - * @brief Enables the RTC subsystem. - */ -#if !defined(HAL_USE_RTC) || defined(__DOXYGEN__) -#define HAL_USE_RTC FALSE -#endif - -/** - * @brief Enables the SDC subsystem. - */ -#if !defined(HAL_USE_SDC) || defined(__DOXYGEN__) -#define HAL_USE_SDC FALSE -#endif - -/** - * @brief Enables the SERIAL subsystem. - */ -#if !defined(HAL_USE_SERIAL) || defined(__DOXYGEN__) -#define HAL_USE_SERIAL TRUE -#endif - -/** - * @brief Enables the SERIAL over USB subsystem. - */ -#if !defined(HAL_USE_SERIAL_USB) || defined(__DOXYGEN__) -#define HAL_USE_SERIAL_USB TRUE -#endif - -/** - * @brief Enables the SPI subsystem. - */ -#if !defined(HAL_USE_SPI) || defined(__DOXYGEN__) -#define HAL_USE_SPI FALSE -#endif - -/** - * @brief Enables the UART subsystem. - */ -#if !defined(HAL_USE_UART) || defined(__DOXYGEN__) -#define HAL_USE_UART FALSE -#endif - -/** - * @brief Enables the USB subsystem. - */ -#if !defined(HAL_USE_USB) || defined(__DOXYGEN__) -#define HAL_USE_USB TRUE -#endif - -/** - * @brief Enables the WDG subsystem. - */ -#if !defined(HAL_USE_WDG) || defined(__DOXYGEN__) -#define HAL_USE_WDG FALSE -#endif - -/*===========================================================================*/ -/* ADC driver related settings. */ -/*===========================================================================*/ - -/** - * @brief Enables synchronous APIs. - * @note Disabling this option saves both code and data space. - */ -#if !defined(ADC_USE_WAIT) || defined(__DOXYGEN__) -#define ADC_USE_WAIT TRUE -#endif - -/** - * @brief Enables the @p adcAcquireBus() and @p adcReleaseBus() APIs. - * @note Disabling this option saves both code and data space. - */ -#if !defined(ADC_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__) -#define ADC_USE_MUTUAL_EXCLUSION TRUE -#endif - -/*===========================================================================*/ -/* CAN driver related settings. */ -/*===========================================================================*/ - -/** - * @brief Sleep mode related APIs inclusion switch. - */ -#if !defined(CAN_USE_SLEEP_MODE) || defined(__DOXYGEN__) -#define CAN_USE_SLEEP_MODE TRUE -#endif - -/*===========================================================================*/ -/* I2C driver related settings. */ -/*===========================================================================*/ - -/** - * @brief Enables the mutual exclusion APIs on the I2C bus. - */ -#if !defined(I2C_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__) -#define I2C_USE_MUTUAL_EXCLUSION TRUE -#endif - -/*===========================================================================*/ -/* MAC driver related settings. */ -/*===========================================================================*/ - -/** - * @brief Enables an event sources for incoming packets. - */ -#if !defined(MAC_USE_ZERO_COPY) || defined(__DOXYGEN__) -#define MAC_USE_ZERO_COPY FALSE -#endif - -/** - * @brief Enables an event sources for incoming packets. - */ -#if !defined(MAC_USE_EVENTS) || defined(__DOXYGEN__) -#define MAC_USE_EVENTS TRUE -#endif - -/*===========================================================================*/ -/* MMC_SPI driver related settings. */ -/*===========================================================================*/ - -/** - * @brief Delays insertions. - * @details If enabled this options inserts delays into the MMC waiting - * routines releasing some extra CPU time for the threads with - * lower priority, this may slow down the driver a bit however. - * This option is recommended also if the SPI driver does not - * use a DMA channel and heavily loads the CPU. - */ -#if !defined(MMC_NICE_WAITING) || defined(__DOXYGEN__) -#define MMC_NICE_WAITING TRUE -#endif - -/*===========================================================================*/ -/* SDC driver related settings. */ -/*===========================================================================*/ - -/** - * @brief Number of initialization attempts before rejecting the card. - * @note Attempts are performed at 10mS intervals. - */ -#if !defined(SDC_INIT_RETRY) || defined(__DOXYGEN__) -#define SDC_INIT_RETRY 100 -#endif - -/** - * @brief Include support for MMC cards. - * @note MMC support is not yet implemented so this option must be kept - * at @p FALSE. - */ -#if !defined(SDC_MMC_SUPPORT) || defined(__DOXYGEN__) -#define SDC_MMC_SUPPORT FALSE -#endif - -/** - * @brief Delays insertions. - * @details If enabled this options inserts delays into the MMC waiting - * routines releasing some extra CPU time for the threads with - * lower priority, this may slow down the driver a bit however. - */ -#if !defined(SDC_NICE_WAITING) || defined(__DOXYGEN__) -#define SDC_NICE_WAITING TRUE -#endif - -/*===========================================================================*/ -/* SERIAL driver related settings. */ -/*===========================================================================*/ - -/** - * @brief Default bit rate. - * @details Configuration parameter, this is the baud rate selected for the - * default configuration. - */ -#if !defined(SERIAL_DEFAULT_BITRATE) || defined(__DOXYGEN__) -#define SERIAL_DEFAULT_BITRATE 115200 -#endif - -/** - * @brief Serial buffers size. - * @details Configuration parameter, you can change the depth of the queue - * buffers depending on the requirements of your application. - * @note The default is 16 bytes for both the transmission and receive - * buffers. - */ -#if !defined(SERIAL_BUFFERS_SIZE) || defined(__DOXYGEN__) -#define SERIAL_BUFFERS_SIZE 16 -#endif - -/*===========================================================================*/ -/* SERIAL_USB driver related setting. */ -/*===========================================================================*/ - -/** - * @brief Serial over USB buffers size. - * @details Configuration parameter, the buffer size must be a multiple of - * the USB data endpoint maximum packet size. - * @note The default is 256 bytes for both the transmission and receive - * buffers. - */ -#if !defined(SERIAL_USB_BUFFERS_SIZE) || defined(__DOXYGEN__) -#define SERIAL_USB_BUFFERS_SIZE 256 -#endif - -/** - * @brief Serial over USB number of buffers. - * @note The default is 2 buffers. - */ -#if !defined(SERIAL_USB_BUFFERS_NUMBER) || defined(__DOXYGEN__) -#define SERIAL_USB_BUFFERS_NUMBER 2 -#endif - -/*===========================================================================*/ -/* SPI driver related settings. */ -/*===========================================================================*/ - -/** - * @brief Enables synchronous APIs. - * @note Disabling this option saves both code and data space. - */ -#if !defined(SPI_USE_WAIT) || defined(__DOXYGEN__) -#define SPI_USE_WAIT TRUE -#endif - -/** - * @brief Enables the @p spiAcquireBus() and @p spiReleaseBus() APIs. - * @note Disabling this option saves both code and data space. - */ -#if !defined(SPI_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__) -#define SPI_USE_MUTUAL_EXCLUSION TRUE -#endif - -/*===========================================================================*/ -/* UART driver related settings. */ -/*===========================================================================*/ - -/** - * @brief Enables synchronous APIs. - * @note Disabling this option saves both code and data space. - */ -#if !defined(UART_USE_WAIT) || defined(__DOXYGEN__) -#define UART_USE_WAIT FALSE -#endif - -/** - * @brief Enables the @p uartAcquireBus() and @p uartReleaseBus() APIs. - * @note Disabling this option saves both code and data space. - */ -#if !defined(UART_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__) -#define UART_USE_MUTUAL_EXCLUSION FALSE -#endif - -/*===========================================================================*/ -/* USB driver related settings. */ -/*===========================================================================*/ - -/** - * @brief Enables synchronous APIs. - * @note Disabling this option saves both code and data space. - */ -#if !defined(USB_USE_WAIT) || defined(__DOXYGEN__) -#define USB_USE_WAIT FALSE -#endif - -#endif /* HALCONF_H */ - -/** @} */ \ No newline at end of file diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/CMakeLists.txt b/targets/CMSIS-OS/ChibiOS/nanoCLR/CMakeLists.txt index 840aef5a4b..34c09a8b83 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/CMakeLists.txt +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/CMakeLists.txt @@ -5,6 +5,10 @@ include(NF_API_Namespaces) +# add header file with common target definitions +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/target_platform.h.in" + "${CMAKE_CURRENT_BINARY_DIR}/target_platform.h" @ONLY) + # append target ChibiOS nanoCLR source files list(APPEND TARGET_CHIBIOS_NANOCLR_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/WireProtocol_App_Interface.c) list(APPEND TARGET_CHIBIOS_NANOCLR_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/WireProtocol_MonitorCommands.c) @@ -36,6 +40,7 @@ set(TARGET_CHIBIOS_NANOCLR_SOURCES ${TARGET_CHIBIOS_NANOCLR_SOURCES} CACHE INTER # append target ChibiOS nanoCLR include directory list(APPEND TARGET_CHIBIOS_NANOCLR_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}) +list(APPEND TARGET_CHIBIOS_NANOCLR_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR}) list(APPEND TARGET_CHIBIOS_NANOCLR_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/src/CLR/Core) # make var global diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/targetHAL_Time.cpp b/targets/CMSIS-OS/ChibiOS/nanoCLR/targetHAL_Time.cpp index c92a60f0f9..ca6e5f6e5d 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoCLR/targetHAL_Time.cpp +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/targetHAL_Time.cpp @@ -5,6 +5,9 @@ #include #include +#include +#include +#include // Converts CMSIS sysTicks to .NET ticks (100 nanoseconds) signed __int64 HAL_Time_SysTicksToTime(unsigned int sysTicks) { @@ -17,3 +20,50 @@ signed __int64 HAL_Time_SysTicksToTime(unsigned int sysTicks) { // need to convert from microseconds to 100 nanoseconds return microsecondsFromSysTicks * 10; } + +// Returns the current date time from the system tick or from the RTC if it's available (this depends on the respective configuration option) +signed __int64 HAL_Time_CurrentDateTime(bool datePartOnly) +{ +#if defined(HAL_USE_RTC) + + // use RTC to get date time + SYSTEMTIME st; + RTCDateTime _dateTime; + + rtcGetTime(&RTCD1, &_dateTime); + + st.wDay = (unsigned short) _dateTime.day; + st.wMonth = (unsigned short) _dateTime.month; + st.wYear = (unsigned short) _dateTime.year; + st.wDayOfWeek = (unsigned short) _dateTime.dayofweek; + + // zero 'time' fields if date part only is required + if(datePartOnly) + { + st.wMilliseconds = 0; + st.wSecond = 0; + st.wMinute = 0; + st.wMinute = 0; + } + else + { + // full date&time required, fill in 'time' fields too + + st.wMilliseconds =(unsigned short) (_dateTime.millisecond % 1000); + _dateTime.millisecond /= 1000; + st.wSecond = (unsigned short) (_dateTime.millisecond % 60); + _dateTime.millisecond /= 60; + st.wMinute = (unsigned short) (_dateTime.millisecond % 60); + _dateTime.millisecond /= 60; + st.wMinute = (unsigned short) (_dateTime.millisecond % 24); + } + + return HAL_Time_ConvertFromSystemTime( &st ); + +#else + + // use system ticks + return HAL_Time_SysTicksToTime( HAL_Time_CurrentSysTicks() ); + +#endif +}; diff --git a/targets/CMSIS-OS/ChibiOS/nanoCLR/target_platform.h.in b/targets/CMSIS-OS/ChibiOS/nanoCLR/target_platform.h.in new file mode 100644 index 0000000000..892c636258 --- /dev/null +++ b/targets/CMSIS-OS/ChibiOS/nanoCLR/target_platform.h.in @@ -0,0 +1,17 @@ +// +// Copyright (c) 2017 The nanoFramework project contributors +// See LICENSE file in the project root for full license information. +// + +////////////////////////////////////////////////////////////////////////////// +// This file was automatically generated by a tool. // +// Any changes you make here will be overwritten when it's generated again. // +////////////////////////////////////////////////////////////////////////////// + +#ifndef _TARGET_CHIBIOS_NANOCLR_H_ +#define _TARGET_CHIBIOS_NANOCLR_H_ + +// set preference to enable (or not) the RTC subsystem +#define HAL_USE_RTC @HAL_USE_RTC_OPTION@ + +#endif /* _TARGET_CHIBIOS_NANOCLR_H_ */ diff --git a/targets/os/win32/nanoCLR/PAL/time_stubs.cpp b/targets/os/win32/nanoCLR/PAL/time_stubs.cpp index 9ab83ee874..e64aff2dd2 100644 --- a/targets/os/win32/nanoCLR/PAL/time_stubs.cpp +++ b/targets/os/win32/nanoCLR/PAL/time_stubs.cpp @@ -50,7 +50,7 @@ bool HAL_Time_ToSystemTime(signed long long time, SYSTEMTIME* systemTime) return FALSE; } -signed __int64 HAL_Time_FromSystemTime(const SYSTEMTIME* systemTime) +signed __int64 HAL_Time_ConvertFromSystemTime(const SYSTEMTIME* systemTime) { return 0; } diff --git a/targets/os/win32/nanoCLR/nanoCLR.vcxproj b/targets/os/win32/nanoCLR/nanoCLR.vcxproj index cb0a79f781..7aec7f5d14 100644 --- a/targets/os/win32/nanoCLR/nanoCLR.vcxproj +++ b/targets/os/win32/nanoCLR/nanoCLR.vcxproj @@ -180,7 +180,7 @@ - + Use diff --git a/targets/os/win32/nanoCLR/nanoCLR.vcxproj.filters b/targets/os/win32/nanoCLR/nanoCLR.vcxproj.filters index 4c5b15703b..261670789e 100644 --- a/targets/os/win32/nanoCLR/nanoCLR.vcxproj.filters +++ b/targets/os/win32/nanoCLR/nanoCLR.vcxproj.filters @@ -53,9 +53,6 @@ Source Files - - Source Files - Source Files @@ -95,5 +92,8 @@ Source Files\PAL + + Source Files + \ No newline at end of file diff --git a/targets/os/win32/nanoCLR/Time.cpp b/targets/os/win32/nanoCLR/targetHAL_Time.cpp similarity index 88% rename from targets/os/win32/nanoCLR/Time.cpp rename to targets/os/win32/nanoCLR/targetHAL_Time.cpp index 826cf50c4b..876a3daa09 100644 --- a/targets/os/win32/nanoCLR/Time.cpp +++ b/targets/os/win32/nanoCLR/targetHAL_Time.cpp @@ -39,6 +39,27 @@ signed __int64 HAL_Time_CurrentTime() return 0; // UNDONE: FIXME: EmulatorNative::GetITimeDriver()->CurrentTime(); } +signed __int64 HAL_Time_CurrentDateTime(bool datePartOnly) +{ + if (datePartOnly) + { + SYSTEMTIME st; + HAL_Time_ToSystemTime(HAL_Time_CurrentTime(), &st); + + st.wHour = 0; + st.wMinute = 0; + st.wSecond = 0; + st.wMilliseconds = 0; + + return HAL_Time_ConvertFromSystemTime(&st); + } + else + { + // on Windows we'll just return what is the current time from HAL + return HAL_Time_CurrentTime(); + } +} + void HAL_Time_GetDriftParameters ( signed int* a, signed int* b, signed __int64* c ) { *a = 1;