Replacing usleep with px4_usleep

This is a step towards isolating time from the system.
This commit is contained in:
Julian Oes
2018-12-22 10:32:18 +01:00
parent e485885344
commit 5b9dea5604
112 changed files with 339 additions and 305 deletions
+1 -1
View File
@@ -70,7 +70,7 @@ int HRTTest::main()
appState.setRunning(true);
hrt_abstime t = hrt_absolute_time();
usleep(1000000);
px4_usleep(1000000);
hrt_abstime elt = hrt_elapsed_time(&t);
PX4_INFO("Elapsed time %llu in 1 sec (usleep)\n", (unsigned long long)elt);
PX4_INFO("Start time %llu\n", (unsigned long long)t);
+2 -1
View File
@@ -36,6 +36,7 @@
* Test for the analog to digital converter.
*/
#include <px4_time.h>
#include <px4_config.h>
#include <px4_posix.h>
#include <px4_log.h>
@@ -78,7 +79,7 @@ int test_adc(int argc, char *argv[])
}
printf("\n");
usleep(150000);
px4_usleep(150000);
}
printf("\t ADC test successful.\n");
+1 -1
View File
@@ -108,7 +108,7 @@ task_main(int argc, char *argv[])
PX4_INFO("task %d: %.0f%%", my_id, (double)i * 100.0f / NUM_MISSIONS_TEST);
}
usleep(rand() & ((64 * 1024) - 1));
px4_usleep(rand() & ((64 * 1024) - 1));
}
hrt_abstime rstart = hrt_absolute_time();
+3 -2
View File
@@ -43,6 +43,7 @@
* Included Files
****************************************************************************/
#include <px4_time.h>
#include <px4_config.h>
#include <px4_defines.h>
#include <px4_log.h>
@@ -220,11 +221,11 @@ int test_hott_telemetry(int argc, char *argv[])
0x00, 0x00, 0x00, 0x7d, 0x12
};
usleep(5000);
px4_usleep(5000);
for (unsigned int i = 0; i < sizeof(response); i++) {
write(fd, &response[i], 1);
usleep(1000);
px4_usleep(1000);
}
PX4_INFO("PASS: Response sent to the HoTT receiver device. Voltage should now show 2.5V.");
+3 -3
View File
@@ -191,7 +191,7 @@ int test_hrt(int argc, char *argv[])
for (i = 0; i < 10; i++) {
prev = hrt_absolute_time();
gettimeofday(&tv1, nullptr);
usleep(100000);
px4_usleep(100000);
now = hrt_absolute_time();
gettimeofday(&tv2, nullptr);
printf("%lu (%lu/%lu), %lu (%lu/%lu), %lu\n",
@@ -201,7 +201,7 @@ int test_hrt(int argc, char *argv[])
fflush(stdout);
}
usleep(1000000);
px4_usleep(1000000);
printf("one-second ticks\n");
@@ -209,7 +209,7 @@ int test_hrt(int argc, char *argv[])
hrt_call_after(&call, 1000000, nullptr, nullptr);
while (!hrt_called(&call)) {
usleep(1000);
px4_usleep(1000);
}
printf("tick\n");
+17 -17
View File
@@ -69,7 +69,7 @@ bool HysteresisTest::_zero_case()
ut_assert_true(hysteresis.get_state());
// A wait won't change anything.
usleep(1000 * f);
px4_usleep(1000 * f);
hysteresis.update();
ut_assert_true(hysteresis.get_state());
@@ -86,20 +86,20 @@ bool HysteresisTest::_change_after_time()
// Change to true.
hysteresis.set_state_and_update(true);
ut_assert_false(hysteresis.get_state());
usleep(4000 * f);
px4_usleep(4000 * f);
hysteresis.update();
ut_assert_false(hysteresis.get_state());
usleep(2000 * f);
px4_usleep(2000 * f);
hysteresis.update();
ut_assert_true(hysteresis.get_state());
// Change back to false.
hysteresis.set_state_and_update(false);
ut_assert_true(hysteresis.get_state());
usleep(1000 * f);
px4_usleep(1000 * f);
hysteresis.update();
ut_assert_true(hysteresis.get_state());
usleep(3000 * f);
px4_usleep(3000 * f);
hysteresis.update();
ut_assert_false(hysteresis.get_state());
@@ -115,10 +115,10 @@ bool HysteresisTest::_hysteresis_changed()
// Change to true.
hysteresis.set_state_and_update(true);
ut_assert_false(hysteresis.get_state());
usleep(3000 * f);
px4_usleep(3000 * f);
hysteresis.update();
ut_assert_false(hysteresis.get_state());
usleep(3000 * f);
px4_usleep(3000 * f);
hysteresis.update();
ut_assert_true(hysteresis.get_state());
@@ -128,10 +128,10 @@ bool HysteresisTest::_hysteresis_changed()
// Change back to false.
hysteresis.set_state_and_update(false);
ut_assert_true(hysteresis.get_state());
usleep(7000 * f);
px4_usleep(7000 * f);
hysteresis.update();
ut_assert_true(hysteresis.get_state());
usleep(5000 * f);
px4_usleep(5000 * f);
hysteresis.update();
ut_assert_false(hysteresis.get_state());
@@ -147,20 +147,20 @@ bool HysteresisTest::_change_after_multiple_sets()
// Change to true.
hysteresis.set_state_and_update(true);
ut_assert_false(hysteresis.get_state());
usleep(3000 * f);
px4_usleep(3000 * f);
hysteresis.set_state_and_update(true);
ut_assert_false(hysteresis.get_state());
usleep(3000 * f);
px4_usleep(3000 * f);
hysteresis.set_state_and_update(true);
ut_assert_true(hysteresis.get_state());
// Change to false.
hysteresis.set_state_and_update(false);
ut_assert_true(hysteresis.get_state());
usleep(3000 * f);
px4_usleep(3000 * f);
hysteresis.set_state_and_update(false);
ut_assert_true(hysteresis.get_state());
usleep(3000 * f);
px4_usleep(3000 * f);
hysteresis.set_state_and_update(false);
ut_assert_false(hysteresis.get_state());
@@ -175,23 +175,23 @@ bool HysteresisTest::_take_change_back()
// Change to true.
hysteresis.set_state_and_update(true);
ut_assert_false(hysteresis.get_state());
usleep(3000 * f);
px4_usleep(3000 * f);
hysteresis.update();
ut_assert_false(hysteresis.get_state());
// Change your mind to false.
hysteresis.set_state_and_update(false);
ut_assert_false(hysteresis.get_state());
usleep(6000 * f);
px4_usleep(6000 * f);
hysteresis.update();
ut_assert_false(hysteresis.get_state());
// And true again
hysteresis.set_state_and_update(true);
ut_assert_false(hysteresis.get_state());
usleep(3000 * f);
px4_usleep(3000 * f);
hysteresis.update();
ut_assert_false(hysteresis.get_state());
usleep(3000 * f);
px4_usleep(3000 * f);
hysteresis.update();
ut_assert_true(hysteresis.get_state());
+2 -1
View File
@@ -35,6 +35,7 @@
* Included Files
****************************************************************************/
#include <px4_time.h>
#include <px4_config.h>
#include <px4_posix.h>
@@ -120,7 +121,7 @@ int test_led(int argc, char *argv[])
}
ledon = !ledon;
usleep(60000);
px4_usleep(60000);
}
/* Go back to default */
+1 -1
View File
@@ -65,7 +65,7 @@ void unlock()
}
#define PERF(name, op, count) do { \
usleep(1000); \
px4_usleep(1000); \
reset(); \
perf_counter_t p = perf_alloc(PC_ELAPSED, name); \
for (int i = 0; i < count; i++) { \
@@ -65,7 +65,7 @@ void unlock()
}
#define PERF(name, op, count) do { \
usleep(1000); \
px4_usleep(1000); \
reset(); \
perf_counter_t p = perf_alloc(PC_ELAPSED, name); \
for (int i = 0; i < count; i++) { \
@@ -67,7 +67,7 @@ void unlock()
}
#define PERF(name, op, count) do { \
usleep(1000); \
px4_usleep(1000); \
reset(); \
perf_counter_t p = perf_alloc(PC_ELAPSED, name); \
for (int i = 0; i < count; i++) { \
@@ -70,7 +70,7 @@ void unlock()
}
#define PERF(name, op, count) do { \
usleep(1000); \
px4_usleep(1000); \
reset(); \
perf_counter_t p = perf_alloc(PC_ELAPSED, name); \
for (int i = 0; i < count; i++) { \
+3 -3
View File
@@ -451,7 +451,7 @@ bool MixerTest::mixerTest()
}
}
usleep(sleep_quantum_us);
px4_usleep(sleep_quantum_us);
sleepcount++;
if (sleepcount % 10 == 0) {
@@ -516,7 +516,7 @@ bool MixerTest::mixerTest()
}
}
usleep(sleep_quantum_us);
px4_usleep(sleep_quantum_us);
sleepcount++;
if (sleepcount % 10 == 0) {
@@ -566,7 +566,7 @@ bool MixerTest::mixerTest()
}
}
usleep(sleep_quantum_us);
px4_usleep(sleep_quantum_us);
sleepcount++;
if (sleepcount % 10 == 0) {
+5 -5
View File
@@ -151,7 +151,7 @@ test_mount(int argc, char *argv[])
PX4_INFO("\n SUCCESSFULLY PASSED FSYNC'ED WRITES, CONTINUTING WITHOUT FSYNC");
fsync(fileno(stdout));
fsync(fileno(stderr));
usleep(20000);
px4_usleep(20000);
}
}
@@ -186,7 +186,7 @@ test_mount(int argc, char *argv[])
printf("unpower the system immediately (within 0.5s) when the hash (#) sign appears\n");
fsync(fileno(stdout));
fsync(fileno(stderr));
usleep(50000);
px4_usleep(50000);
for (unsigned a = 0; a < alignments; a++) {
@@ -236,7 +236,7 @@ test_mount(int argc, char *argv[])
printf(".");
fsync(fileno(stdout));
fsync(fileno(stderr));
usleep(200000);
px4_usleep(200000);
px4_close(fd);
fd = px4_open(PX4_STORAGEDIR "/testfile", O_RDONLY);
@@ -282,7 +282,7 @@ test_mount(int argc, char *argv[])
fsync(fileno(stdout));
fsync(fileno(stderr));
usleep(20000);
px4_usleep(20000);
close(cmd_fd);
@@ -290,7 +290,7 @@ test_mount(int argc, char *argv[])
PX4_INFO("Iteration done, rebooting..");
fsync(fileno(stdout));
fsync(fileno(stderr));
usleep(50000);
px4_usleep(50000);
px4_systemreset(false);
/* never going to get here */
+2 -1
View File
@@ -37,6 +37,7 @@
*
*/
#include <px4_time.h>
#include <px4_config.h>
#include <sys/types.h>
@@ -136,7 +137,7 @@ int test_ppm_loopback(int argc, char *argv[])
/* read low-level values from FMU or IO RC inputs (PPM, Spektrum, S.Bus) */
struct input_rc_s rc_input;
orb_copy(ORB_ID(input_rc), _rc_sub, &rc_input);
usleep(100000);
px4_usleep(100000);
/* open PPM input and expect values close to the output values */
+1 -1
View File
@@ -67,7 +67,7 @@ int test_rc(int argc, char *argv[])
struct input_rc_s rc_input;
struct input_rc_s rc_last;
orb_copy(ORB_ID(input_rc), _rc_sub, &rc_input);
usleep(100000);
px4_usleep(100000);
/* open PPM input and expect values close to the output values */
+5 -4
View File
@@ -38,6 +38,7 @@
* @author Lorenz Meier <lm@inf.ethz.ch>
*/
#include <px4_time.h>
#include <px4_config.h>
#include <px4_posix.h>
@@ -101,7 +102,7 @@ accel(int argc, char *argv[], const char *path)
}
/* wait at least 100ms, sensor should have data after no more than 20ms */
usleep(100000);
px4_usleep(100000);
/* read data - expect samples */
ret = px4_read(fd, &buf, sizeof(buf));
@@ -151,7 +152,7 @@ gyro(int argc, char *argv[], const char *path)
}
/* wait at least 5 ms, sensor should have data after that */
usleep(5000);
px4_usleep(5000);
/* read data - expect samples */
ret = px4_read(fd, &buf, sizeof(buf));
@@ -196,7 +197,7 @@ mag(int argc, char *argv[], const char *path)
}
/* wait at least 5 ms, sensor should have data after that */
usleep(5000);
px4_usleep(5000);
/* read data - expect samples */
ret = px4_read(fd, &buf, sizeof(buf));
@@ -241,7 +242,7 @@ baro(int argc, char *argv[], const char *path)
}
/* wait at least 5 ms, sensor should have data after that */
usleep(5000);
px4_usleep(5000);
/* read data - expect samples */
ret = px4_read(fd, &buf, sizeof(buf));
+2 -1
View File
@@ -37,6 +37,7 @@
*
*/
#include <px4_time.h>
#include <px4_config.h>
#include <sys/types.h>
@@ -113,7 +114,7 @@ int test_servo(int argc, char *argv[])
goto out;
}
usleep(5000000);
px4_usleep(5000000);
printf("Advancing channel 0 to 1500\n");
result = ioctl(fd, PWM_SERVO_SET(0), 1500);
printf("Advancing channel 1 to 1800\n");
+2 -1
View File
@@ -35,6 +35,7 @@
* Included Files
****************************************************************************/
#include <px4_time.h>
#include <px4_config.h>
#include <px4_defines.h>
@@ -57,7 +58,7 @@ int test_sleep(int argc, char *argv[])
fflush(stdout);
for (unsigned int i = 0; i < nsleeps; i++) {
usleep(100000);
px4_usleep(100000);
}
printf("\t Sleep test successful.\n");