diff --git a/src/CatenaBase.h b/src/CatenaBase.h index 18af32c..3389f98 100644 --- a/src/CatenaBase.h +++ b/src/CatenaBase.h @@ -91,7 +91,7 @@ Revision history: #define CATENA_ARDUINO_PLATFORM_VERSION_CALC(major, minor, patch, local) \ (((major) << 24u) | ((minor) << 16u) | ((patch) << 8u) | (local)) -#define CATENA_ARDUINO_PLATFORM_VERSION CATENA_ARDUINO_PLATFORM_VERSION_CALC(0, 14, 0, 61) /* v0.14.0.61 */ +#define CATENA_ARDUINO_PLATFORM_VERSION CATENA_ARDUINO_PLATFORM_VERSION_CALC(0, 14, 0, 62) /* v0.14.0.62 */ #define CATENA_ARDUINO_PLATFORM_VERSION_GET_MAJOR(v) \ (((v) >> 24u) & 0xFFu) @@ -264,6 +264,10 @@ class CatenaBase inline uint32_t GetPlatformFlags(void); + // get system clock rate in Hz; must be overridden + virtual uint64_t GetSystemClockRate(void) const = 0; + + // start the Catena framework. virtual bool begin(void); virtual const char *CatenaName(void) const = 0; // requires that an override be provided. diff --git a/src/CatenaFeatherM0.h b/src/CatenaFeatherM0.h index b08d811..be96603 100644 --- a/src/CatenaFeatherM0.h +++ b/src/CatenaFeatherM0.h @@ -81,6 +81,12 @@ class CatenaFeatherM0 : public CatenaSamd21 PIN_STATUS_LED = 13, }; + // get system clock rate in Hz. Always fixed for Feathers. + virtual uint64_t GetSystemClockRate(void) const override + { + return 48 * 1000 * 1000; + } + // methods virtual bool begin() override; diff --git a/src/CatenaStm32L0.h b/src/CatenaStm32L0.h index ddc6564..f917d1d 100644 --- a/src/CatenaStm32L0.h +++ b/src/CatenaStm32L0.h @@ -93,6 +93,9 @@ class CatenaStm32L0 : public CatenaStm32 uint32_t Multiplier = 1 ) const; + // get system clock rate in Hz; must be overridden + virtual uint64_t GetSystemClockRate(void) const override; + // read the current battery voltage, in engineering units virtual float ReadVbat(void) const = 0; virtual float ReadVbus(void) const = 0; diff --git a/src/lib/stm32/stm32l0/CatenaStm32L0_GetSystemClockRate.cpp b/src/lib/stm32/stm32l0/CatenaStm32L0_GetSystemClockRate.cpp new file mode 100644 index 0000000..e796d7e --- /dev/null +++ b/src/lib/stm32/stm32l0/CatenaStm32L0_GetSystemClockRate.cpp @@ -0,0 +1,90 @@ +/* + +Module: CatenaStm32L0_GetSystemClockRate.cpp + +Function: + CatenaStm32L0::GetSystemClockRate() + +Copyright notice: + See accompanying license + +Author: + Terry Moore, MCCI Corporation April 2019 + +*/ + +#ifdef ARDUINO_ARCH_STM32 + +#include "CatenaStm32L0.h" + +#include + +using namespace McciCatena; + +/****************************************************************************\ +| +| Manifest constants & typedefs. +| +\****************************************************************************/ + + +/****************************************************************************\ +| +| Read-only data. +| +\****************************************************************************/ + + + +/****************************************************************************\ +| +| Variables. +| +\****************************************************************************/ + + +/* + +Name: CatenaStm32L0::GetSystemCLockRate + +Function: + Return the system clock rate + +Definition: + virtual uint64_t CatenaStm32L0::GetSystemClockRate( + void + ) const override; + +Description: + The clock rate returned is the value set at compile time + by CATENA_CFG_SYSCLK. The value we return is the correct + nominal value, in Hz. + +Returns: + Analog value + +*/ + +uint64_t CatenaStm32L0::GetSystemClockRate( + void + ) const + { + switch (CATENA_CFG_SYSCLK) + { + case 2: + return 2097 * 1000; + case 4: + return 4194 * 1000; + case 16: + return 16 * 1000 * 1000; + case 24: + return 24 * 1000 * 1000; + default: + case 32: + return 32 * 1000 * 1000; + } + } + +#endif // ARDUINO_ARCH_STM32 + +/**** end of CatenaStm32L0_GetSystemClockRate.cpp ****/