CANTram Framework 1.0.1
Dieses Framework ermöglicht die Nutzung der CANTram Hardware, einer Mikrocontroller basierten mdoularen Steuerung.
Loading...
Searching...
No Matches
HardwareResource Class Referenceabstract

Base class for hardware resources like UART, SPI, I2C, PWM, etc. More...

#include <HardwareResource.h>

Inheritance diagram for HardwareResource:

Public Types

enum  Type {
  UART , SPI , I2C , PWM ,
  CAN
}
 Enumeration of hardware resource types. More...

Public Member Functions

virtual Type getType ()=0
 Get the hardware resource type.
virtual bool reset ()
 Reset the hardware resource to a known default state.
bool requestUsage ()
 Request a usage slot for this resource.
uint8_t getUsages ()
 Get the current number of usages of this resource.
bool isUsed ()
 Check if the resource is currently used.
virtual uint8_t getRemainingUsages ()
 Get remaining usage capacity for this resource.

Protected Member Functions

 HardwareResource ()=default
 Default constructor.
virtual uint8_t getMaxUsages ()
 Get the maximum simultaneous usages allowed for this resource.

Protected Attributes

uint8_t usages =0
 Current usage counter.

Detailed Description

Base class for hardware resources like UART, SPI, I2C, PWM, etc.

HardwareResource provides a common interface for resources managed by CANTramCore. It implements usage counting and default reset/usage behaviour. Derived classes must implement getType() and may override getMaxUsages() and reset() as required.

Member Enumeration Documentation

◆ Type

Enumeration of hardware resource types.

Used to identify the concrete resource type when requesting or attaching resources.

Enumerator
UART 

UART type.

SPI 

SPI type.

I2C 

I2C type.

PWM 

PWM type.

CAN 

CAN type.

Constructor & Destructor Documentation

◆ HardwareResource()

HardwareResource::HardwareResource ( )
protecteddefault

Default constructor.

Protected to prevent direct instantiation of the abstract base class.

Member Function Documentation

◆ getMaxUsages()

virtual uint8_t HardwareResource::getMaxUsages ( )
inlineprotectedvirtual

Get the maximum simultaneous usages allowed for this resource.

Default implementation returns 1. Override in derived classes to permit multiple users.

Returns
uint8_t Maximum number of concurrent usages allowed.

Reimplemented in ESP32PWMCore, I2CCore, and PWMCore.

Here is the caller graph for this function:

◆ getRemainingUsages()

virtual uint8_t HardwareResource::getRemainingUsages ( )
inlinevirtual

Get remaining usage capacity for this resource.

Computes remaining usages as max usages minus current usages. Can be overridden by derived classes if needed.

Returns
uint8_t Number of remaining usages available.
Here is the call graph for this function:

◆ getType()

virtual Type HardwareResource::getType ( )
pure virtual

Get the hardware resource type.

Must be implemented by derived classes to return the correct Type enum value.

Returns
Type The type of the hardware resource.

Implemented in ESP32_CANCore, I2CCore, PWMCore, and UARTCore.

Here is the caller graph for this function:

◆ getUsages()

uint8_t HardwareResource::getUsages ( )
inline

Get the current number of usages of this resource.

Returns the number of modules that have requested/are using this hardware resource.

Returns
uint8_t Current usage count.

◆ isUsed()

bool HardwareResource::isUsed ( )
inline

Check if the resource is currently used.

Returns true when at least one usage has been requested.

Returns
true if the resource is in use, false otherwise.

◆ requestUsage()

bool HardwareResource::requestUsage ( )
inline

Request a usage slot for this resource.

Increments the internal usage counter if the resource has remaining capacity. If the resource is already at its maximum usages, the request is rejected and an error is logged.

Returns
true if the usage request was granted, false if the resource is already fully used.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ reset()

virtual bool HardwareResource::reset ( )
inlinevirtual

Reset the hardware resource to a known default state.

Default implementation clears the usage counter and logs the reset. Derived classes should call the base implementation and perform any additional hardware-specific reset steps.

Returns
true if the reset succeeded, false otherwise.

Reimplemented in CANCore, ESP32_CANCore, ESP32_I2CCore, ESP32_UART, ESP32PWMCore, I2CCore, and UARTCore.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ usages

uint8_t HardwareResource::usages =0
protected

Current usage counter.

Tracks how many clients/modules have requested this resource.


The documentation for this class was generated from the following file:
  • C:/Users/leowa/Documents/PlatformIO/Projects/CANTramFrameworkUsage/lib/CANTramFramework/include/HardwareResource.h