|
Embedded Artistry Framework
Embedded Systems C++ Framework
|
Interfaces and components for building a virtual hardware platform. More...
|
Classes | |
| class | embvm::TimerManager< TMaxTimers, TLock, TTimeUnit, TTimeoutCallback, TTimerDevice > |
| Timer Manager Class. More... | |
| class | embvm::VirtualHwPlatformBase< THWPlatform > |
| Virtual Hardware Platform Base. More... | |
Interfaces and components for building a virtual hardware platform.
| class embvm::TimerManager |
Timer Manager Class.
The Timer Manager takes a hardware timer and uses it to produce a number of software timers.
An alternative structure accomplishing this task is the callback_timer provided by ETL in callback_timer.h, which uses a tick() function: https://www.etlcpp.com/callback_timer.html
| TMaxTimers | The maximum number of software timers that can be created. Size 0 indicates dynamic memory will be used. All other sizes will enable static memory allocation. |
| TLock | The type of lock interface to use. Default is embutil::nop_lock, which disables locking. To enable locking, declare TimerManager with a functional lock type. using TimerManager_t = embvm::TimerManager<0, std::mutex>; |
| TTimeUnit | The time-keeping units. The default embvm::timer::timer_period_t is inherited from the Timer base class. This can be overriden to provide a specific timer resolution (e.g. 1ms instead of 1us). TTimeUnit is limited by the granularity that the Timer can support. |
| TTimeoutCallback | The storage type for the callback function. |
| TTimerDevice | The type of timer device that this class will manage. The default Timer type is the base class that framework timers derive from. |

Public Types | |
| using | DispatcherFunc = stdext::inplace_function< void(const TTimeoutCallback &)> |
| The function prototype for the Dispatcher. More... | |
Public Member Functions | |
| TimerManager (TTimerDevice &timer) noexcept | |
| Create a TimerManager without a dispatcher. More... | |
| TimerManager (TTimerDevice &timer, const DispatcherFunc &dispatcher) noexcept | |
| Create a TimerManager with a dispatcher. More... | |
| ~TimerManager () noexcept | |
| Destroy the TimerManager. More... | |
| TimerManager (const TimerManager &)=delete | |
| Deleted copy constructor. More... | |
| const TimerManager & | operator= (const TimerManager &)=delete |
| Deleted copy assignment operator. More... | |
| TimerManager (TimerManager &&)=delete | |
| Deleted move constructor. More... | |
| TimerManager & | operator= (TimerManager &&)=delete |
| Deleted move assignment operator. More... | |
| TimerHandle | allocate () noexcept |
| Allocate a new software timer. More... | |
Private Types | |
| using | TimeRep_t = typename TTimeUnit::rep |
| Alias for the time unit representation (e.g., uint32_t, uint64_t) More... | |
| using | TTimerQueueType = typename std::conditional<(TMaxTimers==0), std::list< delayInfo >, etl::list< delayInfo, TMaxTimers > >::type |
| Type definition for the underlying timer queue. More... | |
| using | TQueueHandle = typename TTimerQueueType::iterator |
| Convenience alias for the queue handle type. More... | |
| using | TScheduledQueueType = typename std::conditional<(TMaxTimers==0), std::vector< TQueueHandle >, etl::vector< TQueueHandle, TMaxTimers > >::type |
| Convenience type for the queue of scheduled timers. More... | |
Private Member Functions | |
| void | TimerManagerDispatch (const TTimeoutCallback &op) noexcept |
| TimerManager Default Dispatch Function. More... | |
| void | TimerInterruptHandler () noexcept |
| TimerManager's Timer Interrupt Handler. More... | |
| void | addToScheduledQueue (TQueueHandle handle) noexcept |
| void | popScheduledQueueFront () noexcept |
| void | lockAndPopScheduledQueueFront () noexcept |
| void | adjustScheduledTimerCount (TTimeUnit time_base) noexcept |
| void | startNextTimer () noexcept |
| auto | stopRunningTimer () noexcept |
| void | schedule (TQueueHandle handle, TTimeUnit delay, const TTimeoutCallback &func, embvm::timer::config config) noexcept |
| void | schedule (TQueueHandle handle, TTimeUnit delay, TTimeoutCallback &&func, embvm::timer::config config) noexcept |
| bool | cancel (TQueueHandle handle) noexcept |
| Returns false if no wait was scheduled or if the callback was already called Returns true if cancelled successfully. More... | |
| void | deleteTimer (TQueueHandle handle) noexcept |
| void | sortScheduledQueue () noexcept |
| void | clearExpiredTimers () noexcept |
Private Attributes | |
| const DispatcherFunc | dispatcher_ |
| TTimerQueueType | timer_list_ {} |
| TScheduledQueueType | scheduled_queue_ {} |
| TLock | scheduled_q_lock_ |
| TLock | timer_list_lock_ |
| TTimerDevice & | timer_hw_ |
Friends | |
| class | TimerManager::TimerHandle |
| The timer handle can call private TimerManager functions. More... | |
| using embvm::TimerManager< TMaxTimers, TLock, TTimeUnit, TTimeoutCallback, TTimerDevice >::DispatcherFunc = stdext::inplace_function<void(const TTimeoutCallback&)> |
The function prototype for the Dispatcher.
The dispacher uses inplace_function regardless of static or dynamic memory allocation.
|
private |
Alias for the time unit representation (e.g., uint32_t, uint64_t)
|
private |
Convenience alias for the queue handle type.
A list iterator is used because iterators remain valid even with insertion/deletions
|
private |
Convenience type for the queue of scheduled timers.
This queue is used to manage the list of currently scheduled timers.
The size of the scheduled queue will be <= the size of the allocated queue.
The type changes depending on whether static or dynamic memory allocation is being used (dynamic memory is indicated by TMaxTimers == 0)
|
private |
Type definition for the underlying timer queue.
This type is used to manage timers which have been allocated.
The type changes depending on whether static or dynamic memory allocation is being used (dynamic memory is indicated by TMaxTimers == 0)
|
inlineexplicitnoexcept |
Create a TimerManager without a dispatcher.
Creating a TimerManager without a dispatcher will result in the manager invoking the functions.
When no dispatcher is used, timer callbacks are called directly by the TimerManager.
| timer | The timer hardware instance which the TimerManager will manage. |
|
inlineexplicitnoexcept |
Create a TimerManager with a dispatcher.
Creates a TimerManager class with an external dispatcher. When a timer expires, the TimerManager forwards the callback to the dispatcher, rather than executing the callbacks directly. Using a dispatcher improves timer latency, as the manager is focused only on managing timers.
| timer | The timer hardware instance which the TimerManager will manage. |
| dispatcher | Specifies a function which will dispatch all timer callbacks. Use TimerManager with a dispatch queue, or other type of system event queue. |
|
inlinenoexcept |
Destroy the TimerManager.
On destruction, the TimerManager stops the underlying timer hardware and unregisters the TimerManager's timer interrupt callback.
|
delete |
Deleted copy constructor.
|
delete |
Deleted move constructor.
|
inlineprivatenoexcept |
Referenced by embvm::TimerManager< 0, std::mutex >::schedule().
|
inlineprivatenoexcept |
|
inlinenoexcept |
Allocate a new software timer.
Allocates a new timer in the TimerManager and returns a handle to the user.
Referenced by BlinkySimulatorHWPlatform::allocateTimer(), and FWDemoSimulatorHWPlatform::allocateTimer().
|
inlineprivatenoexcept |
Returns false if no wait was scheduled or if the callback was already called Returns true if cancelled successfully.
|
inlineprivatenoexcept |
|
inlineprivatenoexcept |
|
inlineprivatenoexcept |
Referenced by embvm::TimerManager< 0, std::mutex >::cancel().
|
delete |
Deleted copy assignment operator.
|
delete |
Deleted move assignment operator.
|
inlineprivatenoexcept |
|
inlineprivatenoexcept |
|
inlineprivatenoexcept |
|
inlineprivatenoexcept |
Referenced by embvm::TimerManager< 0, std::mutex >::addToScheduledQueue().
|
inlineprivatenoexcept |
|
inlineprivatenoexcept |
|
inlineprivatenoexcept |
TimerManager's Timer Interrupt Handler.
TimerManager registers its own interrupt with the Timer hardware driver. When the timer interrupt fires, we account for the time that has elapsed, clear all scheduled timers, and restart the timer hardware with the next timeout request.
Note that this must work with an interrupt bottom-half handler because locking calls are used here. It cannot be called directly in an ISR context!
Referenced by embvm::TimerManager< 0, std::mutex >::TimerManager().
|
inlineprivatenoexcept |
TimerManager Default Dispatch Function.
If no external dispatcher is provided, TimerManager has one which just executes the operation by default.
| op | The callback function object to execute. |
|
friend |
The timer handle can call private TimerManager functions.
|
private |
Referenced by embvm::TimerManager< 0, std::mutex >::clearExpiredTimers().
|
private |
Referenced by embvm::TimerManager< 0, std::mutex >::addToScheduledQueue(), embvm::TimerManager< 0, std::mutex >::adjustScheduledTimerCount(), embvm::TimerManager< 0, std::mutex >::cancel(), embvm::TimerManager< 0, std::mutex >::clearExpiredTimers(), embvm::TimerManager< 0, std::mutex >::lockAndPopScheduledQueueFront(), embvm::TimerManager< 0, std::mutex >::sortScheduledQueue(), embvm::TimerManager< 0, std::mutex >::startNextTimer(), embvm::TimerManager< 0, std::mutex >::stopRunningTimer(), and embvm::TimerManager< 0, std::mutex >::~TimerManager().
|
private |
Referenced by embvm::TimerManager< 0, std::mutex >::addToScheduledQueue(), embvm::TimerManager< 0, std::mutex >::adjustScheduledTimerCount(), embvm::TimerManager< 0, std::mutex >::cancel(), embvm::TimerManager< 0, std::mutex >::clearExpiredTimers(), embvm::TimerManager< 0, std::mutex >::popScheduledQueueFront(), embvm::TimerManager< 0, std::mutex >::sortScheduledQueue(), and embvm::TimerManager< 0, std::mutex >::startNextTimer().
|
private |
Referenced by embvm::TimerManager< 0, std::mutex >::startNextTimer(), embvm::TimerManager< 0, std::mutex >::stopRunningTimer(), embvm::TimerManager< 0, std::mutex >::TimerInterruptHandler(), embvm::TimerManager< 0, std::mutex >::TimerManager(), and embvm::TimerManager< 0, std::mutex >::~TimerManager().
|
private |
|
private |
| class embvm::VirtualHwPlatformBase |
Virtual Hardware Platform Base.
This class provides the common interfaces and behaviors that virtual hardware platforms must implement. Some functionality is common to all platforms (name functions).
Functions whose names are appended with _ are meant to be supplied by the derived hardware platform:
Derived classes may supply additional functions as required. The functions above are the common required functions that all hardware platforms must supply.
This class uses the docs/development/patterns/crtp.md ["CRTP pattern"] rather than virtual inheritance. To derive from this class, do the following:
| THWPlatform | the derived HW platform implementation (CRTP pattern) |

Public Member Functions | |
| VirtualHwPlatformBase (const char *name) noexcept | |
| Create a named virtual hardware platform. More... | |
| VirtualHwPlatformBase (const std::string &name) noexcept | |
| Create a named virtual hardware platform. More... | |
| VirtualHwPlatformBase (const std::string_view &name) noexcept | |
| Create a named virtual hardware platform. More... | |
| ~VirtualHwPlatformBase ()=default | |
| Default destructor. More... | |
| VirtualHwPlatformBase (const VirtualHwPlatformBase &)=delete | |
| Deleted copy constructor. More... | |
| const VirtualHwPlatformBase & | operator= (const VirtualHwPlatformBase &)=delete |
| Deleted copy assignment operator. More... | |
| VirtualHwPlatformBase (VirtualHwPlatformBase &&)=delete | |
| Deleted move constructor. More... | |
| VirtualHwPlatformBase & | operator= (VirtualHwPlatformBase &&)=delete |
| Deleted move assignment operator. More... | |
| constexpr const std::string_view & | name () const noexcept |
| Returns the Virtual HW Platform's name. More... | |
| constexpr const char * | name_cstr () const noexcept |
| Returns the platform name as a cstring for C API compatibility. More... | |
| void | initProcessor () noexcept |
| Initialize the processor. More... | |
| void | init () noexcept |
| Initialize the hardware platform. More... | |
| void | soft_reset () noexcept |
| Perform a soft reset of the system (chip reset) More... | |
| void | hard_reset () noexcept |
| Perform a hard reset of the system (power cycle) More... | |
| void | shutdown () noexcept |
| Shutdown the system. More... | |
Static Public Member Functions | |
| static void | earlyInitHook () noexcept |
| Perform any special initialization steps. More... | |
Private Attributes | |
| const std::string_view | name_ |
|
inlineexplicitnoexcept |
Create a named virtual hardware platform.
| name | C-string containing the hardware platform name |
|
inlineexplicitnoexcept |
Create a named virtual hardware platform.
| name | std::string containing the hardware platform name Note: VirtualHwPlatformBase uses a std::string_view, so the std::string must remain valid throughout the lifetime of VirtualHwPlatformBase. |
|
inlineexplicitnoexcept |
Create a named virtual hardware platform.
| name | std::string_view containing the hardware platform name Note: VirtualHwPlatformBase uses a std::string_view, so the std::string_view must remain valid throughout the lifetime of VirtualHwPlatformBase. |
|
default |
Default destructor.
|
delete |
Deleted copy constructor.
|
delete |
Deleted move constructor.
|
inlinestaticnoexcept |
Perform any special initialization steps.
The earlyInitHook_() function must be implemented by the derived class as a static function.
These functions run before the C Run-time setup functions are called, and normal functionality (e.g. OS concepts) are not available.
Early initialization steps represent any super early code that needs to execute. For example, DRAM might need to be initialized before the boot process can relocate memory to its proper location in memory.
These functions are declared static to prevent you from easily using drivers within their confines
|
inlinenoexcept |
Perform a hard reset of the system (power cycle)
The hard_reset_() function must be implemented by the derived class.
A hard reset is intended to perform a full power cycle of the system.
Platforms which do not support a hard reset should default to calling soft_reset().
|
inlinenoexcept |
Initialize the hardware platform.
The init_() function must be implemented by the derived class.
Perform any hardware platform initialization steps, such as preparing peripherals for use, setting up callbacks, etc.
Referenced by nRF52DK_FrameworkDemoPlatform::initHWPlatform_(), FrameworkDemoSimPlatform::initHWPlatform_(), and UnitTestPlatform::initHWPlatform_().
|
inlinenoexcept |
Initialize the processor.
The initProcessor_() function must be implemented by the derived class.
Perform any steps necessary for initializing the processor & processor peripheral devices for use.
Note that this is only intended to be processor initialization. Platform initialization nis handled by the init() function.
This function will likely invoke the VirtualProcessor::init() function, but the order and actual initialization process is left to the derived class.
Referenced by nRF52DK_FrameworkDemoPlatform::initProcessor_(), FrameworkDemoSimPlatform::initProcessor_(), and UnitTestPlatform::initProcessor_().
|
inlinenoexcept |
Returns the Virtual HW Platform's name.
Referenced by UnitTestPlatform::hwPlatformName().
|
inlinenoexcept |
Returns the platform name as a cstring for C API compatibility.
Referenced by UnitTestPlatform::hwPlatformName_cstr().
|
delete |
Deleted copy assignment operator.
|
delete |
Deleted move assignment operator.
|
inlinenoexcept |
Shutdown the system.
The shutdown_() function must be implemented by the derived class.
If your platform supports shutdown capability, take the proper steps to initiate a shutdown.
If the platform does not support shutdown capability, implement your shutdown_() function as an assert to notify users trying to call this API. You could also leave the shutdown_() function undefined. Anyone who calls the shutdown() function on a platform with an undefined shutdown_() function will encounter a compiler error.
The shutdown function is not expected to return.
|
inlinenoexcept |
Perform a soft reset of the system (chip reset)
The soft_reset_() function must be implemnted by the derived class.
A soft reset is intended to reset the program to the beginning without performing a full power cycle.
A good strategy is to just call virtual processor's reset() function, if one is provided.
|
private |
1.8.15