at24cm0x 1.0
at24cm0x driver library
Loading...
Searching...
No Matches
systick.c File Reference

Implements the SysTick utility functions. More...

#include "systick.h"
Include dependency graph for systick.c:

Functions

void systick_init (void)
 Initializes the SysTick timer module.
void systick_reset (void)
 Resets the SysTick timer value.
void systick_tick (void)
 Increments the SysTick timer tick counter.
unsigned int systick_current (void)
 Returns the current SysTick tick counter value.
void systick_timer_set (SYSTICK_Timer *timer, unsigned int delay_ticks)
 Sets and starts a SysTick software timer.
SYSTICK_Timer_Status systick_timer_elapsed (SYSTICK_Timer *timer)
 Checks whether a SysTick software timer has expired.
unsigned int systick_timer_remaining (SYSTICK_Timer *timer)
 Returns the remaining time before a SysTick timer expires.
void systick_timer_wait (unsigned int ticks)
 Blocks execution for a specified number of SysTick ticks.
void systick_timer_cancel (SYSTICK_Timer *timer)
 Cancels a running SysTick software timer.

Variables

volatile unsigned int systick_tick_value

Detailed Description

Implements the SysTick utility functions.

This file provides the implementation of the SysTick utility functions declared in systick.h. It manages a software timer based on the SysTick peripheral, allowing for non-blocking delays and periodic tasks.

Author
g.raf
Date
2026-01-24
Version
1.0 Release
Note
This file is part of a larger project and subject to the license specified in the repository. For updates and the complete revision history, see the GitHub repository.
See also
https://github.com/0x007e/utils-systick "Systick GitHub Repository"

Function Documentation

◆ systick_current()

unsigned int systick_current ( void )

Returns the current SysTick tick counter value.

This function reads the current value of the internal SysTick tick counter (systick_tick_value) in an atomic operation to prevent race conditions during concurrent access from interrupts. The returned value represents the elapsed system ticks since the last reset or initialization of the SysTick module.

Returns
The current SysTick tick counter value.
Note
The access is performed inside an ATOMIC_BLOCK to ensure data consistency when interrupts may update the tick value.
Here is the caller graph for this function:

◆ systick_init()

void systick_init ( void )

Initializes the SysTick timer module.

This function initializes the SysTick timer by resetting its internal state and preparing it for subsequent use. It calls systick_reset() to ensure the timer starts from a known default state.

Typically, this function should be called once during system initialization before any SysTick-based timing operations are performed.

Note
This function does not start the timer automatically; it only resets
and initializes the SysTick module.
Here is the call graph for this function:

◆ systick_reset()

void systick_reset ( void )

Resets the SysTick timer value.

This function clears the internal SysTick tick counter by setting systick_tick_value to zero. It ensures that the timer restarts counting from the beginning, which is useful during initialization or when restarting time measurements.

Note
This function does not alter the SysTick configuration or status. It only resets the tick counter value.
Here is the caller graph for this function:

◆ systick_tick()

void systick_tick ( void )

Increments the SysTick timer tick counter.

This function increases the internal systick_tick_value by one. It should be called periodically—typically from the SysTick interrupt service routine—to maintain an accurate system tick counter used for software timing and scheduling operations.

Note
This function must be invoked at a constant rate to ensure correct timekeeping for all SysTick-based timers.

◆ systick_timer_cancel()

void systick_timer_cancel ( SYSTICK_Timer * timer)

Cancels a running SysTick software timer.

This function stops a SysTick timer by setting its status to SYSTICK_Timer_Expired, effectively marking it as completed regardless of its current tick count. Once canceled, the timer will be considered expired and will no longer count down or trigger expiration checks.

Parameters
[in,out]timerPointer to the SysTick timer instance to cancel.
Note
This function does not modify the timer’s expiration value; it only updates the status flag to indicate expiration.

◆ systick_timer_elapsed()

SYSTICK_Timer_Status systick_timer_elapsed ( SYSTICK_Timer * timer)

Checks whether a SysTick software timer has expired.

This function determines if the specified SYSTICK_Timer instance has reached its expiration tick value. If the current SysTick count has passed the timer's expire value, the timer status is updated to SYSTICK_Timer_Expired. Otherwise, the timer remains in the running state.

Parameters
[in,out]timerPointer to the SysTick timer instance to check.
Returns
The current status of the timer:
Note
The comparison uses signed arithmetic to handle counter wraparound
conditions correctly when the SysTick tick counter overflows.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ systick_timer_remaining()

unsigned int systick_timer_remaining ( SYSTICK_Timer * timer)

Returns the remaining time before a SysTick timer expires.

This function calculates the number of SysTick ticks remaining until the specified SYSTICK_Timer instance reaches its expiration value. If the timer has already expired, its status is updated to SYSTICK_Timer_Expired, and the function returns zero.

Parameters
[in,out]timerPointer to the SysTick timer instance to query.
Returns
The number of SysTick ticks remaining until expiration, or 0 if the timer has already expired.
Note
The comparison uses signed arithmetic to correctly handle counter wraparound when the SysTick tick counter overflows.
Here is the call graph for this function:

◆ systick_timer_set()

void systick_timer_set ( SYSTICK_Timer * timer,
unsigned int delay_ticks )

Sets and starts a SysTick software timer.

This function initializes a given SYSTICK_Timer instance by setting its expiration tick value relative to the current SysTick count. The timer is configured to expire after the specified number of delay_ticks and marked as running.

Parameters
[in,out]timerPointer to the SysTick timer instance to configure.
[in]delay_ticksNumber of SysTick ticks after which the timer should expire.
Note
The timer must be periodically checked (e.g., via systick_timer_expired()) to determine when it has reached its expiration.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ systick_timer_wait()

void systick_timer_wait ( unsigned int ticks)

Blocks execution for a specified number of SysTick ticks.

This function creates a temporary SYSTICK_Timer instance and waits until it expires. The function blocks program execution by polling the timer status in a busy-wait loop, using a NOP instruction for each iteration to prevent compiler optimization and reduce power consumption on some architectures.

Parameters
[in]ticksThe number of SysTick ticks to wait before returning.
Note
This is a blocking delay function and should only be used when precise timing is required, and multitasking is not critical. For non-blocking timing, use SYSTICK_Timer with periodic checks via systick_timer_elapsed() instead.
Here is the call graph for this function:

Variable Documentation

◆ systick_tick_value

volatile unsigned int systick_tick_value