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
+2 -2
View File
@@ -154,7 +154,7 @@ bl_update_main(int argc, char *argv[])
}
PX4_INFO("image validated, erasing bootloader...");
usleep(10000);
px4_usleep(10000);
/* prevent other tasks from running while we do this */
sched_lock();
@@ -232,7 +232,7 @@ setopt(void)
/* program the new option value */
*optcr = (*optcr & ~opt_mask) | opt_bits | (1 << 1);
usleep(1000);
px4_usleep(1000);
if ((*optcr & opt_mask) == opt_bits) {
PX4_INFO("option bits set");
+4 -4
View File
@@ -210,7 +210,7 @@ esc_calib_main(int argc, char *argv[])
orb_copy(ORB_ID_VEHICLE_ATTITUDE_CONTROLS, act_sub, &actuators);
/* wait 50 ms */
usleep(50000);
px4_usleep(50000);
/* now expect nothing changed on that topic */
bool orb_updated;
@@ -261,7 +261,7 @@ esc_calib_main(int argc, char *argv[])
}
/* rate limit to ~ 20 Hz */
usleep(50000);
px4_usleep(50000);
}
/* open for ioctl only */
@@ -338,7 +338,7 @@ esc_calib_main(int argc, char *argv[])
}
/* rate limit to ~ 20 Hz */
usleep(50000);
px4_usleep(50000);
}
printf("Low PWM set: %d\n"
@@ -378,7 +378,7 @@ esc_calib_main(int argc, char *argv[])
}
/* rate limit to ~ 20 Hz */
usleep(50000);
px4_usleep(50000);
}
/* disarm */
+7 -7
View File
@@ -112,7 +112,7 @@ static void run_led_test1()
led_control.priority = led_control_s::MAX_PRIORITY;
publish_led_control(led_control);
usleep(200 * 1000);
px4_usleep(200 * 1000);
// generate some pattern
for (int round = led_control_s::COLOR_RED; round <= led_control_s::COLOR_WHITE; ++round) {
@@ -121,25 +121,25 @@ static void run_led_test1()
led_control.mode = led_control_s::MODE_ON;
led_control.color = round;
publish_led_control(led_control);
usleep(80 * 1000);
px4_usleep(80 * 1000);
}
usleep(100 * 1000);
px4_usleep(100 * 1000);
led_control.led_mask = 0xff;
for (int i = 0; i < 3; ++i) {
led_control.mode = led_control_s::MODE_ON;
publish_led_control(led_control);
usleep(100 * 1000);
px4_usleep(100 * 1000);
led_control.mode = led_control_s::MODE_OFF;
publish_led_control(led_control);
usleep(100 * 1000);
px4_usleep(100 * 1000);
}
usleep(200 * 1000);
px4_usleep(200 * 1000);
}
usleep(500 * 1000);
px4_usleep(500 * 1000);
// reset
led_control.led_mask = 0xff;
+1 -1
View File
@@ -133,7 +133,7 @@ static int
load(const char *devname, const char *fname, bool append)
{
// sleep a while to ensure device has been set up
usleep(20000);
px4_usleep(20000);
int dev;
+2 -2
View File
@@ -273,7 +273,7 @@ int prepare(int fd, unsigned long *max_channels)
orb_copy(ORB_ID_VEHICLE_ATTITUDE_CONTROLS, act_sub, &actuators);
/* wait 50 ms */
usleep(50000);
px4_usleep(50000);
/* now expect nothing changed on that topic */
bool orb_updated;
@@ -409,7 +409,7 @@ int motor_ramp_thread_main(int argc, char *argv[])
}
// rate limit
usleep(2000);
px4_usleep(2000);
}
if (fd >= 0) {
+4 -3
View File
@@ -51,6 +51,7 @@
************************************************************************************/
#include <px4_config.h>
#include <px4_time.h>
#include <sys/types.h>
#include <stdint.h>
@@ -228,7 +229,7 @@ static int at24c_eraseall(FAR struct at24c_dev_s *priv)
while (I2C_TRANSFER(priv->dev, &msgv[0], 1) < 0) {
fwarn("erase stall\n");
usleep(10000);
px4_usleep(10000);
}
}
@@ -341,7 +342,7 @@ static ssize_t at24c_bread(FAR struct mtd_dev_s *dev, off_t startblock,
}
finfo("read stall");
usleep(1000);
px4_usleep(1000);
/* We should normally only be here on the first read after
* a write.
@@ -430,7 +431,7 @@ static ssize_t at24c_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, size_t
}
finfo("write stall");
usleep(1000);
px4_usleep(1000);
/* We expect to see a number of retries per write cycle as we
* poll for write completion.
+4 -4
View File
@@ -703,7 +703,7 @@ pwm_main(int argc, char *argv[])
/* Delay longer than the max Oneshot duration */
usleep(2542);
px4_usleep(2542);
#ifdef __PX4_NUTTX
/* Trigger all timer's channels in Oneshot mode to fire
@@ -828,13 +828,13 @@ err_out_no_test:
}
if (phase == 1) {
usleep(steps_timings_us[steps_timing_index] / phase_maxcount);
px4_usleep(steps_timings_us[steps_timing_index] / phase_maxcount);
} else if (phase == 0) {
usleep(50000);
px4_usleep(50000);
} else if (phase == 2) {
usleep(50000);
px4_usleep(50000);
} else {
break;
+1 -1
View File
@@ -107,7 +107,7 @@ int reboot_main(int argc, char *argv[])
return -1;
}
while (1) { usleep(1); } // this command should not return on success
while (1) { px4_usleep(1); } // this command should not return on success
return 0;
}
+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");
+1 -1
View File
@@ -121,7 +121,7 @@ top_main(int argc, char *argv[])
}
}
usleep(200000);
px4_usleep(200000);
}
curr_time = hrt_absolute_time();
@@ -69,7 +69,7 @@ void listener(listener_print_topic_cb cb, const orb_id_t &id, unsigned num_msgs,
updated = true;
} else {
usleep(500);
px4_usleep(500);
}
if (updated) {
+3 -3
View File
@@ -207,7 +207,7 @@ tune_control_main(int argc, char *argv[])
tune_control.silence = (uint32_t)silence;
tune_control.strength = (uint8_t)strength;
publish_tune_control(tune_control);
usleep(duration + silence);
px4_usleep(duration + silence);
exit_counter++;
// exit if the loop is doing too many iterations
@@ -237,7 +237,7 @@ tune_control_main(int argc, char *argv[])
while (tunes.get_next_tune(frequency, duration, silence, strength) > 0) {
PX4_INFO("frequency: %d, duration %d, silence %d, strength%d",
frequency, duration, silence, strength);
usleep(500000);
px4_usleep(500000);
exit_counter++;
// exit if the loop is doing too many iterations
@@ -256,7 +256,7 @@ tune_control_main(int argc, char *argv[])
publish_tune_control(tune_control);
// We wait the maximum update interval to ensure
// The stop will not be overwritten
usleep(tunes.get_maximum_update_interval());
px4_usleep(tunes.get_maximum_update_interval());
} else {
usage();