memmon.h

A memory monitor module that uses the task_sched.h scheduler to periodically execute a task that sends messages about the content of specified memory locations via the task_tlv.h module.  The set of monitored memory locations can be updated while the task scheduler is running.

Summary
memmon.hA memory monitor module that uses the task_sched.h scheduler to periodically execute a task that sends messages about the content of specified memory locations via the task_tlv.h module.
Data Types
Variables
memmon_ptrThe type of pointers to memory locations in the memory monitor API.
memmon_cptrThe type of pointers to constant memory locations in the memory monitor API.
Macros
MEMMON_MAKE_PTRConverts a pointer to an arbitrary type into a pointer that is compatible with the memory monitor API (a memmon_ptr), without triggering compiler warnings.
MEMMON_MAKE_CPTRConverts a pointer to an arbitrary type into a pointer-to-constant that is compatible with the memory monitor API (a memmon_cptr), without triggering compiler warnings.
memmon_specSpecifies a memory monitor.
Variables
ptrPointer to the memory location to monitor.
sizeSize in bytes of the memory location to monitor.
delay_divNotification rate divisor to apply to the monitor.
delay_countUsed internally by the memory monitor task to keep track of the number of task executions since the lastest notification was sent.
memmon_headerSpecifies the byte format of a memory monitor notification header.
Variables
mon_iIndex number of the memory monitor.
ptrAddress of the monitored memory location.
Global Variables
Macros
MEMMON_MAX_SIZEMaximum size in bytes of a monitored memory location.
Variables
memmon_max_monitorsThe maximum number of simultaneously registered memory monitors.
memmon_n_monitorsThe number of registered memory monitors.
memmon_msg_countNumber of notification attempts made by the memory monitor task.
memmon_drop_countNumber of failed notification attempts made by the memory monitor task.
memmon_free_ramAvailable unused RAM in bytes.
API Functions
Functions
memmon_get_free_ramObtains the amount of available unused RAM.
memmon_initInitializes the memory monitor module.
memmon_addRegisters a memory monitor.
memmon_removeUnregisters a memory monitor with a specified index number.
memmon_remove_ptrUnregisters a memory monitor monitoring a specified location.
memmon_shutdownShuts down the memory monitor module.

Data Types

Summary
Variables
memmon_ptrThe type of pointers to memory locations in the memory monitor API.
memmon_cptrThe type of pointers to constant memory locations in the memory monitor API.
Macros
MEMMON_MAKE_PTRConverts a pointer to an arbitrary type into a pointer that is compatible with the memory monitor API (a memmon_ptr), without triggering compiler warnings.
MEMMON_MAKE_CPTRConverts a pointer to an arbitrary type into a pointer-to-constant that is compatible with the memory monitor API (a memmon_cptr), without triggering compiler warnings.

Variables

memmon_ptr

typedef uint8_t *memmon_ptr

The type of pointers to memory locations in the memory monitor API.

memmon_cptr

typedef const uint8_t *memmon_cptr

The type of pointers to constant memory locations in the memory monitor API.

Macros

MEMMON_MAKE_PTR

Converts a pointer to an arbitrary type into a pointer that is compatible with the memory monitor API (a memmon_ptr), without triggering compiler warnings.  Function-like macro.

Parameters

PA pointer.  The macro will evaluate to a pointer containing the same address as this pointer.

Returns

A memmon_ptr containing the same address as P.

MEMMON_MAKE_CPTR

Converts a pointer to an arbitrary type into a pointer-to-constant that is compatible with the memory monitor API (a memmon_cptr), without triggering compiler warnings.  Function-like macro.

Parameters

PA pointer.  The macro will evaluate to a pointer containing the same address as this pointer.

Returns

A memmon_cptr containing the same address as P.

memmon_spec

typedef struct memmon_spec

Specifies a memory monitor.

Summary
Variables
ptrPointer to the memory location to monitor.
sizeSize in bytes of the memory location to monitor.
delay_divNotification rate divisor to apply to the monitor.
delay_countUsed internally by the memory monitor task to keep track of the number of task executions since the lastest notification was sent.

Variables

ptr

memmon_cptr ptr

Pointer to the memory location to monitor.

size

uint8_t size

Size in bytes of the memory location to monitor.

delay_div

uint8_t delay_div

Notification rate divisor to apply to the monitor.  The monitored memory location will be read and the obtained value sent in a TLV notification message once for every delay_div executions of the memory monitor task.

delay_count

uint8_t delay_count

Used internally by the memory monitor task to keep track of the number of task executions since the lastest notification was sent.

memmon_header

typedef struct __attribute__ ((__packed__)) memmon_header

Specifies the byte format of a memory monitor notification header.

Summary
Variables
mon_iIndex number of the memory monitor.
ptrAddress of the monitored memory location.

Variables

mon_i

uint8_t mon_i

Index number of the memory monitor.

ptr

memmon_cptr ptr

Address of the monitored memory location.

Global Variables

Summary
Macros
MEMMON_MAX_SIZEMaximum size in bytes of a monitored memory location.
Variables
memmon_max_monitorsThe maximum number of simultaneously registered memory monitors.
memmon_n_monitorsThe number of registered memory monitors.
memmon_msg_countNumber of notification attempts made by the memory monitor task.
memmon_drop_countNumber of failed notification attempts made by the memory monitor task.
memmon_free_ramAvailable unused RAM in bytes.

Macros

MEMMON_MAX_SIZE

Maximum size in bytes of a monitored memory location.  Constant macro.

Variables

memmon_max_monitors

extern uint8_t memmon_max_monitors

The maximum number of simultaneously registered memory monitors.

CAUTION: Do not update this variable in external code, unless you know what you’re doing.

memmon_n_monitors

extern uint8_t memmon_n_monitors

The number of registered memory monitors.

CAUTION: Do not update this variable in external code, unless you know what you’re doing.

memmon_msg_count

extern uint16_t memmon_msg_count

Number of notification attempts made by the memory monitor task.

NOTE: This will roll over to zero if the number of notification attempts exceeds UINT16_MAX.

memmon_drop_count

extern uint16_t memmon_drop_count

Number of failed notification attempts made by the memory monitor task.

NOTE: This will roll over to zero if the number of failed notification attempts exceeds UINT16_MAX.

memmon_free_ram

extern ptrdiff_t memmon_free_ram

Available unused RAM in bytes.  Updated at the start of each execution of the memory monitor task.  Uses memmon_get_free_ram to obtain the amount of unused RAM.

API Functions

Summary
Functions
memmon_get_free_ramObtains the amount of available unused RAM.
memmon_initInitializes the memory monitor module.
memmon_addRegisters a memory monitor.
memmon_removeUnregisters a memory monitor with a specified index number.
memmon_remove_ptrUnregisters a memory monitor monitoring a specified location.
memmon_shutdownShuts down the memory monitor module.

Functions

memmon_get_free_ram

ptrdiff_t memmon_get_free_ram(void)

Obtains the amount of available unused RAM.

NOTE: This function can be used even if the memory monitor module hasn’t been initialized with memmon_init.

Returns

Available free RAM in bytes.

memmon_init

void memmon_init(uint8_t task_num_cat,
uint8_t max_mon,
memmon_spec *mon_array,
sched_time delay,
uint8_t tlv_typ,
uint8_t inm_dstadr)

Initializes the memory monitor module.  Creates the memory monitor task.

CAUTION: This function MUST be called before any memory monitors are registered.

Parameters

task_num_catA TCSB value (see sched_task) containing the task instance and category numbers that should be used by the memory monitor task.  (The sleep bit is ignored.)
max_monMaximum number of simultaneously registered memory monitors.
mon_arrayPointer to memory where memmon_spec structs representing registered memory monitors should be stored.  The specified memory location MUST be large enough to store at least max_mon such structs and remain valid until memmon_shutdown is called.
delayScheduler delay of the memory monitor task.
tlv_typTLV message type identifier to use for memory monitor notification messages (TTLV_MSG_T_MEMMON_DATA is recommended).
inm_dstadrINM destination address to use for memory monitor notification messages.

memmon_add

uint8_t memmon_add(const memmon_spec *mon)

Registers a memory monitor.

Parameters

monPointer to a memmon_spec specifying the monitor to register.

Returns

The index number of the registered memory monitor, or memmon_max_monitors if the monitor couldn’t be registered.

memmon_remove

uint8_t memmon_remove(uint8_t mon_i)

Unregisters a memory monitor with a specified index number.

Parameters

mon_iIndex number of the monitor to unregister.

Returns

A true value if and only if mon_i was the index number of a registered monitor that was removed by this call.

memmon_remove_ptr

uint8_t memmon_remove_ptr(memmon_cptr mon_ptr)

Unregisters a memory monitor monitoring a specified location.

Parameters

mon_ptrAddress of the memory location monitored by the monitor to unregister.

Returns

A true value if and only if a matching registered memory monitor was found and removed by this call.

memmon_shutdown

void memmon_shutdown(void)

Shuts down the memory monitor module.  Stops the memory monitor task.

A task scheduler for AVR microcontrollers.
Task-based TLV (TTLV) communication module for ATmega microcontrollers.
typedef uint8_t *memmon_ptr
The type of pointers to memory locations in the memory monitor API.
typedef const uint8_t *memmon_cptr
The type of pointers to constant memory locations in the memory monitor API.
typedef struct memmon_spec
Specifies a memory monitor.
memmon_cptr ptr
Pointer to the memory location to monitor.
uint8_t size
Size in bytes of the memory location to monitor.
uint8_t delay_div
Notification rate divisor to apply to the monitor.
uint8_t delay_count
Used internally by the memory monitor task to keep track of the number of task executions since the lastest notification was sent.
typedef struct __attribute__ ((__packed__)) memmon_header
Specifies the byte format of a memory monitor notification header.
uint8_t mon_i
Index number of the memory monitor.
memmon_cptr ptr
Address of the monitored memory location.
extern uint8_t memmon_max_monitors
The maximum number of simultaneously registered memory monitors.
extern uint8_t memmon_n_monitors
The number of registered memory monitors.
extern uint16_t memmon_msg_count
Number of notification attempts made by the memory monitor task.
extern uint16_t memmon_drop_count
Number of failed notification attempts made by the memory monitor task.
extern ptrdiff_t memmon_free_ram
Available unused RAM in bytes.
ptrdiff_t memmon_get_free_ram(void)
Obtains the amount of available unused RAM.
void memmon_init(uint8_t task_num_cat,
uint8_t max_mon,
memmon_spec *mon_array,
sched_time delay,
uint8_t tlv_typ,
uint8_t inm_dstadr)
Initializes the memory monitor module.
uint8_t memmon_add(const memmon_spec *mon)
Registers a memory monitor.
uint8_t memmon_remove(uint8_t mon_i)
Unregisters a memory monitor with a specified index number.
uint8_t memmon_remove_ptr(memmon_cptr mon_ptr)
Unregisters a memory monitor monitoring a specified location.
void memmon_shutdown(void)
Shuts down the memory monitor module.
typedef struct sched_task
Represents an instance of a task that can be scheduled for execution.
Memory monitor notification.
Close