Here is the description from the Arduino site about what pulseIn() does:
Reads a pulse (either HIGH or LOW) on a pin. For example, if value is HIGH, pulseIn() waits for the pin to go HIGH, starts timing, then waits for the pin to go LOW and stops timing. Returns the length of the pulse in microseconds. Gives up and returns 0 if no pulse starts within a specified time out.
So basically, pulseIn() returns the total time during the pin is HIGH (or LOW). You have to subtract Tend - Tstart. That is the value to return. I will recommend you to check the pulseIn.cpp file. You will find the code of the function and you can take advantage of it to write your own version of it. The file is in this location: C:\...\arduino-1.5.3-Intel.1.0.4\hardware\arduino\x86\cores\arduino\pulseIn.cpp.
Intel Galileo Gen 2 Eurobot videos :-
that pulsein.cpp library looked quite difficult to me so i just used the time.h library to calculate the time when the echo pin is off and on and then subtract both the time as you said.I used this function echo->read() to read the values.Finally the ultrasonic sensor is working with Mraa library.
i am stuck on a very basic thing actualy the sensor has four pins two i/o and two pins + - to 5v.i am already using my galileo's 5v slot so what i do is i connect the + and - pin to the other galileo boards pins,the code doesnt work i even tried connecting one wire between the grounds of both the boards.Cannot find the issue.
The 4-pin ultrasonic sensors have a pin-out like the one in the picture below:
The 5V pin goes to the power supply, so it should be connected to the 5V output in the Galileo header. The GND pin should be connected to the GND pin in the Galileo header. The other two pins should be conected to a GPIO each.
Please check this thread, it might be useful for you: How can ı make 4pins ultrasonic sensor works?(In coding part).