Skip to content

Commit

Permalink
Fix #158: add API to get configured clock rate
Browse files Browse the repository at this point in the history
  • Loading branch information
terrillmoore committed Apr 21, 2019
1 parent d372e8f commit 0446bab
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/CatenaBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions src/CatenaFeatherM0.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 3 additions & 0 deletions src/CatenaStm32L0.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
90 changes: 90 additions & 0 deletions src/lib/stm32/stm32l0/CatenaStm32L0_GetSystemClockRate.cpp
Original file line number Diff line number Diff line change
@@ -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 <Arduino.h>

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 ****/

0 comments on commit 0446bab

Please sign in to comment.