Zephyr TTCPS Counter Driver Support

This page gives an overview of the TTC counter Zephyr driver, which ships as part of the zephyr-amd repository.

HW Features

The TTC provides three independent timer/counter channels. Each channel has a 16-bit or 32-bit programmable counter and can be driven by the internal clock or an external clock source. Each channel supports:

  1. Independent up or down counting

  2. Interval, match, and overflow interrupts

  3. Programmable prescaler

  4. Waveform (PWM) output

The driver exposes each of the three timer channels as a separate Zephyr counter device through the counter subsystem.

For further details, refer to the Versal Gen 2 Technical Reference Manual (AM026).

Design Notes

  • N/A

Implementation

Features Supported

  1. Each TTC timer channel exposed as an independent counter device

  2. Set and get counter top value

  3. Alarm callbacks on match

  4. Overflow (top value) callback

  5. Programmable clock frequency and prescaler

Missing Features

  • Waveform (PWM) output mode is not supported.

Known Issues

  • N/A

Limitations

  • N/A

Kernel Configuration

CONFIG_COUNTER=y
CONFIG_COUNTER_XLNX_TTC=y

Device Tree

ttc0_timer0: counter0@f1dc0000 {
    compatible = "xlnx,ttc-counter";
    status = "okay";
    reg = <0xf1dc0000 0x1000>;
    timer-id = <0>;
    clock-frequency = <149998505>;
    interrupts = <GIC_SPI 43 IRQ_TYPE_LEVEL IRQ_DEFAULT_PRIORITY>;
    timer-width = <32>;
};

ttc0_timer1: counter1@f1dc0000 {
    compatible = "xlnx,ttc-counter";
    status = "okay";
    reg = <0xf1dc0000 0x1000>;
    timer-id = <1>;
    clock-frequency = <149998505>;
    interrupts = <GIC_SPI 44 IRQ_TYPE_LEVEL IRQ_DEFAULT_PRIORITY>;
    timer-width = <32>;
};

ttc0_timer2: counter2@f1dc0000 {
    compatible = "xlnx,ttc-counter";
    status = "okay";
    reg = <0xf1dc0000 0x1000>;
    timer-id = <2>;
    clock-frequency = <149998505>;
    interrupts = <GIC_SPI 45 IRQ_TYPE_LEVEL IRQ_DEFAULT_PRIORITY>;
    timer-width = <32>;
};

Driver Stack Size

  • TBA

Test Platform

  • Versal NET

  • Versal Gen 2

Test SoC Architecture

  • RPU - R52 core

  • APU - A78 core

Testing Sequence

  • Build a Zephyr application for the R52 or A78 core

    • west build -p -b <board> <sample application path>

  • Run the Zephyr ELF on the target platform.

Example Tests

Test Name

Example Source

Description

Counter basic API

tests/drivers/counter/counter_basic_api/

This directory holds the counter_basic and counter_no_callback suites, which together validate the counter driver API, covering start and stop, set and get top value, single-shot and periodic alarms, and counter read-back.

Code Coverage

  • TBA

Expected Output

*** Booting Zephyr OS build xilinx_v2026.1 ***
Running TESTSUITE counter_basic
===================================================================
START - test_all_channels
 PASS - test_all_channels in 3.117 seconds
===================================================================
START - test_cancelled_alarm_does_not_expire
 PASS - test_cancelled_alarm_does_not_expire in 23.187 seconds
===================================================================
START - test_late_alarm
 PASS - test_late_alarm in 2.405 seconds
===================================================================
START - test_late_alarm_error
 PASS - test_late_alarm_error in 2.405 seconds
===================================================================
START - test_multiple_alarms
 PASS - test_multiple_alarms in 3.687 seconds
===================================================================
START - test_set_top_value_with_alarm
 PASS - test_set_top_value_with_alarm in 4.994 seconds
===================================================================
START - test_short_relative_alarm
 SKIP - test_short_relative_alarm in 2.428 seconds
===================================================================
START - test_single_shot_alarm_notop
 PASS - test_single_shot_alarm_notop in 4.068 seconds
===================================================================
START - test_single_shot_alarm_top
 PASS - test_single_shot_alarm_top in 4.157 seconds
===================================================================
START - test_valid_function_without_alarm
 PASS - test_valid_function_without_alarm in 2.429 seconds
===================================================================
TESTSUITE counter_basic succeeded
Running TESTSUITE counter_no_callback
===================================================================
START - test_set_top_value_without_alarm
 PASS - test_set_top_value_without_alarm in 2.523 seconds
===================================================================
TESTSUITE counter_no_callback succeeded

------ TESTSUITE SUMMARY START ------

SUITE PASS - 100.00% [counter_basic]: pass = 9, fail = 0, skip = 1, total = 10 duration = 52.877 seconds
 - PASS - [counter_basic.test_all_channels] duration = 3.117 seconds
 - PASS - [counter_basic.test_cancelled_alarm_does_not_expire] duration = 23.187 seconds
 - PASS - [counter_basic.test_late_alarm] duration = 2.405 seconds
 - PASS - [counter_basic.test_late_alarm_error] duration = 2.405 seconds
 - PASS - [counter_basic.test_multiple_alarms] duration = 3.687 seconds
 - PASS - [counter_basic.test_set_top_value_with_alarm] duration = 4.994 seconds
 - SKIP - [counter_basic.test_short_relative_alarm] duration = 2.428 seconds
 - PASS - [counter_basic.test_single_shot_alarm_notop] duration = 4.068 seconds
 - PASS - [counter_basic.test_single_shot_alarm_top] duration = 4.157 seconds
 - PASS - [counter_basic.test_valid_function_without_alarm] duration = 2.429 seconds

SUITE PASS - 100.00% [counter_no_callback]: pass = 1, fail = 0, skip = 0, total = 1 duration = 2.523 seconds
 - PASS - [counter_no_callback.test_set_top_value_without_alarm] duration = 2.523 seconds

------ TESTSUITE SUMMARY END ------

===================================================================
PROJECT EXECUTION SUCCESSFUL

Performance Metric

  • TBA

Mainline Status

Driver Source Path

  • drivers/counter/counter_xlnx_ttc.c

MISRA C Report