Measuring the timing of GPIO input GetPinLevel high

I’m working with ultrasonic ping sensor interfacing with Toradex platform.
Sensor works on basic principle of setting a GPIO pin as output HIGH and then LOW, so that sending a signal burst. After 5 microsecond delay, the GPIO pin should receive the signal in INPUT mode and calculate the timing between signal transmission and reception.

Is there any method to measure the timing of signal?

Is there any internal millis() function which I can marking time reference at beginning and end?

Thanks for your support.

It’s not possible to measure so short interval on user (application) level with accepted accuracy. You have an option to write a kernel level driver or use external circuitry. How precise should be a an interval measurement?

Hi Alex, Thanks for the clarification. I have to measure the distance based on the time interval so it need to be very precise.

As per my previous question regarding driver issue, I am not able interface Arduino (as external circuitry). So wanted to interface the intended sensor directly on Toradex eval board.

As you suggested, writing the application at kernel level, I hope it is like writing device driver. Is it very difficult to do? Could you send me some relevant links to help me accomplish this task?

Here a link to interrupt latency information and how to write an ISR

However, you may better look at one of our modules supporting heterogeneous multicore. There you have a dedicated M4 micro-controller core which could do this task. Our Colibri VF61 and i.MX7 support this. Also upcoming i.MX 8QuadMax and i.MX 8X will support this.
Please have a look at this blog post: Developing Real-Time Systems on Application Processors
And: FreeRTOS on the Cortex-M4 of a Colibri iMX7 | Toradex Developer Center

In this case you also do not load the main CPU cores with loads in case you do the pinging constantly.

Another approach would be to look at the HW timer unit many of the Toradex modules support. Some can use external pins for trigger and capture.

If you have a ready to use solution on Arduino - you can connect it to Colbri using SPI, UART or I2C bus. This way you don’t need a USB driver. However it’s much more efficient to use an M4 core at iMX7 module as Daniel mentioned.

You’re right. I used UART A pins to get data directly from microcotroller board and it is working. I shall consider the option of iMX7 with heterogeneous multicore solution during deployment phase.