SyterKit 0.4.0.x
SyterKit is a bare-metal framework
Loading...
Searching...
No Matches
Functions | Variables
timer.c File Reference
#include <io.h>
#include <log.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <sys-clk.h>
#include <timer.h>
#include <types.h>
Include dependency graph for timer.c:

Functions

int __attribute__ ((weak))
 Detect the current high-speed oscillator (HOSC) frequency.
 
void set_timer_count ()
 Set the timer count based on the detected HOSC frequency.
 
uint64_t get_arch_counter (void)
 Get the architecture-specific counter value.
 
uint32_t time_ms (void)
 Get the current time in milliseconds.
 
uint64_t time_us (void)
 Get the current time in microseconds.
 
void udelay (uint32_t us)
 Delay execution for a specified number of microseconds.
 
void mdelay (uint32_t ms)
 Delay execution for a specified number of milliseconds.
 
void sdelay (uint32_t loops)
 Delay execution for a specified number of loops (microseconds).
 
uint32_t get_init_timestamp ()
 Get the initialization timestamp.
 

Variables

static uint32_t init_timestamp
 Timestamp for initialization.
 
uint8_t current_hosc_freq
 Current frequency of the high-speed oscillator (HOSC) in MHz.
 

Function Documentation

◆ __attribute__()

int __attribute__ ( (weak)  )

Detect the current high-speed oscillator (HOSC) frequency.

This function enables the HOSC frequency detection and reads the detected frequency value. It determines if the frequency is closer to 24 MHz or 40 MHz based on the measured counter value.

Returns
Current HOSC frequency in MHz (either 24 or 40).

◆ get_arch_counter()

uint64_t get_arch_counter ( void  )

Get the architecture-specific counter value.

This function reads a high-resolution timer counter and ensures that the values are read consistently.

Returns
Current counter value as a 64-bit integer.

◆ get_init_timestamp()

uint32_t get_init_timestamp ( )

Get the initialization timestamp.

This function returns the timestamp that was set during initialization.

Returns
The initialization timestamp in microseconds.

◆ mdelay()

void mdelay ( uint32_t  ms)

Delay execution for a specified number of milliseconds.

This function converts milliseconds to microseconds and calls the udelay function to implement the delay.

Parameters
msNumber of milliseconds to delay.

◆ sdelay()

void sdelay ( uint32_t  loops)

Delay execution for a specified number of loops (microseconds).

Delay execution for a specified number of loops (treated as microseconds).

This function directly calls udelay with the specified number of loops, which is treated as microseconds.

Parameters
loopsNumber of microsecond loops to delay.

◆ set_timer_count()

void set_timer_count ( )

Set the timer count based on the detected HOSC frequency.

Set timer count.

This function calls the frequency detection routine and initializes the timestamp based on the current time in microseconds.

◆ time_ms()

uint32_t time_ms ( void  )

Get the current time in milliseconds.

This function calculates the current time by dividing the architecture counter value by the current HOSC frequency (in MHz) scaled to milliseconds.

Returns
Current time in milliseconds.

◆ time_us()

uint64_t time_us ( void  )

Get the current time in microseconds.

This function calculates the current time by dividing the architecture counter value by the current HOSC frequency (in MHz).

Returns
Current time in microseconds.

◆ udelay()

void udelay ( uint32_t  us)

Delay execution for a specified number of microseconds.

This function uses a busy-wait loop to create a delay for the specified number of microseconds.

Parameters
usNumber of microseconds to delay.

Variable Documentation

◆ current_hosc_freq

uint8_t current_hosc_freq

Current frequency of the high-speed oscillator (HOSC) in MHz.

Current high-speed oscillator frequency.

◆ init_timestamp

uint32_t init_timestamp
static

Timestamp for initialization.