How to use TSC on thor Jetson 7.1

如何获取TSC output 信号的准确时间?
我们将TSC 作为 camera sensor 的帧同步信号,将这个时间 和camera sensor 数据关联,如何获取TSC output 信号的准确时间?

please see-also similar topic for reference, Topic 303499.

Hi JerryChang,
in Topic 303499. it read TSC timestamp by gpio/i2c irq . not have gpio get this timestamp
but i only need read TSC start run time and TSC generator edges time

hello 870251475,

you may loading the cam_cdi_tsc.ko kernel module for checking /dev/cdi_tsc.
please refer to kernel sources, $public_sources/kernel_src/kernel/ootm/nvidia-public/drivers/media/platform/tegra/cdi/cam_cdi_tsc.c

as you can see, /dev/cdi_tsc is controlled through the cam_cdi_tsc.
here’s code snippet for IOCTL.

static long cdi_tsc_chardev_ioctl(...)
{
    ...
    case _IOC_NR(CDI_TSC_FSYNC):

see-also Thor’s device tree for TSC.
you may enable one generator in device tree and configure frequency, duty_cycle accordingly.
$public_sources/r39.2.0/Linux_for_Tegra/source/kernel_src/hardware/nvidia/t264/nv-public/tegra264.dtsi

        /* TSC Signal Generators */
        tsc_sig_gen@c230000 {
                compatible = "nvidia,tegra264-cam-cdi-tsc";

please refer to Jetson Thor Series Modules Pinmux Template.
you may also configure pinmux, so TSC_EDGE_OUT0 reaches the required carrier-board pin.

from camera side, you may refer to Argus::Ext::ISensorTimestampTsc::getSensorSofTimestampTsc() to return the VI HW (SOF) timestamp based on TSC.

hello JerryChang,

i use /dev/cdi_tsc, TSC_EDGE_OUT0 can work good ,

from camera side, you may refer to Argus::Ext::ISensorTimestampTsc::getSensorSofTimestampTsc() to return the VI HW (SOF) timestamp based on TSC.
— what works need BSP do (how camera sersor know useing TSC hor PWM)? camera sensor need do somethings ?

hello 870251475,

it’s getSensorSofTimestampTsc() to obtain camera timestamps from RCE.
RCE timestamp is calculated from TSC to obtain the SOF/EOF timestamps.
you may use TSC timestamp for synchronization with the system time.
please see-also Argus samples for reference, such as.. Argus/public/samples/syncStereo/main.cpp

Hi JerryChang:

按照你说的逻辑,RCE时间戳和TSC_EDGE_OUT没有关系?相机触发不使用TSC_EDGE_OUT,getSensorSofTimestampTsc()也能正常获取RCE相机时间戳?

no, it doesn’t meant they’re no relationship.

the flow looks like below..
TSC_EDGE_OUT → sensor trigger → sensor/CSI latency → VI detects SOF → SOF TSC timestamp

let me have clarification. getSensorSofTimestampTsc() works even when the sensor does not use TSC_EDGE_OUT.
getSensorSofTimestampTsc() returns the VI hardware SOF timestamp for each captured frame in the TSC time domain.
however, TSC_EDGE_OUT is a separate signal generator, which used only when Tegra supplies the sensor trigger. if it is used, its scheduled edges, and the VI SOF timestamps share the same TSC timebase and can be correlated.

那是否可以获取TSC output 信号输出的时间?如果不行,我使用TSC outout去触发IMU,也记录不到触发IMU的时间了(IMU没有DR信号给到thor这边)?

hello 870251475,

the current /dev/cdi_tsc API does not expose the hardware capture timestamp.

however, you may refer to kernel sources, Thor uses 1 ns per TSC tick.
$public_sources/kernel_src/kernel/ootm/nvidia-public/drivers/media/platform/tegra/cdi/cam_cdi_tsc.c
besides.. start_tsc = current_tsc + 100 ms + offset_ms
note, 100ms preparation margin coming from below..

/* Time (ms) offset for the TSC signal generators */
#define TSC_GENX_START_OFFSET_MS                (100)

hence.. you may have implementation to obtain the scheduled TSC_EDGE_OUT rising-edge time.