STM32 Traffic Control
Loading...
Searching...
No Matches
systick.c File Reference

SysTick timer configuration and millisecond utilities. More...

#include "uart.h"
#include "systick.h"
#include "controller.h"
#include <stdio.h>
#include <stdint.h>
#include "stm32f446xx.h"

Macros

#define SYSTICK_LOAD_VAL   16000
#define CTRL_ENABLE   (1U<<0)
#define CTRL_CLKSRC   (1U<<2)
#define CTRL_COUNTFLAG   (1U<<16)

Functions

void SysTick_Handler (void)
 SysTick interrupt handler called every 1 millisecond.
void systick_init (void)
 Initialize the SysTick timer for 1ms tick interrupts.
uint32_t systickGetMillis (void)
 Get the current system uptime in milliseconds.
void systickDelayMs (int delay)
 Busy-wait delay for a specified number of milliseconds.

Variables

volatile uint32_t systickMillis = 0

Detailed Description

SysTick timer configuration and millisecond utilities.

This module configures the Cortex-M4 SysTick timer to generate a 1 ms tick interrupt. It maintains a global millisecond counter ('systickMillis`) and provides functions with time retrieval and busy-wait delays.

Macro Definition Documentation

◆ CTRL_CLKSRC

#define CTRL_CLKSRC   (1U<<2)

◆ CTRL_COUNTFLAG

#define CTRL_COUNTFLAG   (1U<<16)

◆ CTRL_ENABLE

#define CTRL_ENABLE   (1U<<0)

◆ SYSTICK_LOAD_VAL

#define SYSTICK_LOAD_VAL   16000

Function Documentation

◆ SysTick_Handler()

void SysTick_Handler ( void )

SysTick interrupt handler called every 1 millisecond.

Increments the global milliseocnd counter and calls application-specific timeout functions:

Note
This interrupt handler is invoked by the Cortex-M4 SysTick hardware every millisecond (or configured tick period)

◆ systick_init()

void systick_init ( void )

Initialize the SysTick timer for 1ms tick interrupts.

Configures the SysTick LOAD register and control register to generate interrupts every millisecond based on the system clock.

◆ systickDelayMs()

void systickDelayMs ( int delay)

Busy-wait delay for a specified number of milliseconds.

Uses systickGetMillis() to implement a simple blocking delay.

Parameters
delayNumber of milliseconds to wait
Note
This is a blocking function and will halt CPU execution. Do not use in time-critical or interrupt-sensitive code.

◆ systickGetMillis()

uint32_t systickGetMillis ( void )

Get the current system uptime in milliseconds.

Returns the number of milliseconds elapsed since SysTick initialization.

Returns
Current millisecond count

Variable Documentation

◆ systickMillis

volatile uint32_t systickMillis = 0