-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into servo_motor_test
- Loading branch information
Showing
9 changed files
with
175 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Makefile for user application | ||
|
||
# Specify this directory relative to the current application. | ||
TOCK_USERLAND_BASE_DIR = ../../.. | ||
|
||
# Which files to compile. | ||
C_SRCS := $(wildcard *.c) | ||
|
||
# Include userland master makefile. Contains rules and flags for actually | ||
# building the application. | ||
include $(TOCK_USERLAND_BASE_DIR)/AppMakefile.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Test Multiple Alarms (With Overflow) | ||
|
||
This tests the virtual alarms available to userspace. It sets two | ||
alarms, first one that overflows the alarm, such that its expiration | ||
is small in absolute value (but shouldn't fire until after the clock | ||
overflows) and one after 1s. When successful, the second (1s) alarm | ||
should fire after 1 second, while the first alarm should wait to fire | ||
until after the clock overflows (approximately 7 minutes if the clock | ||
is at 32kHz). | ||
|
||
If the virtual alarm library is buggy, this test might fail by | ||
scheduling the 1 second alarm _after_ the longer wrapping alarm, and | ||
it won't fire immediately. | ||
|
||
# Example Output | ||
|
||
Correct: | ||
|
||
``` | ||
2 10512380 10511329 | ||
1 3 1 | ||
``` | ||
|
||
Incorrect: | ||
|
||
(after no output for an entire clock overflow, e.g. ~7 minutes) | ||
|
||
``` | ||
1 3 1 | ||
2 10512341 10511329 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
#include <libtock-sync/services/alarm.h> | ||
|
||
static void event_cb(uint32_t now, uint32_t expiration, void* ud) { | ||
int i = (int)ud; | ||
printf("%d %lu %lu\n", i, now, expiration); | ||
} | ||
|
||
int main(void) { | ||
libtock_alarm_t t1; | ||
libtock_alarm_t t2; | ||
|
||
uint32_t now; | ||
libtock_alarm_command_read(&now); | ||
|
||
uint32_t overflow_ms = libtock_alarm_ticks_to_ms(UINT32_MAX); | ||
|
||
libtock_alarm_in_ms(overflow_ms, event_cb, (void*)1, &t1); | ||
libtock_alarm_in_ms(1000, event_cb, (void*)2, &t2); | ||
|
||
while (1) { | ||
yield(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Makefile for user application | ||
|
||
# Specify this directory relative to the current application. | ||
TOCK_USERLAND_BASE_DIR = ../../.. | ||
|
||
# Which files to compile. | ||
C_SRCS := $(wildcard *.c) | ||
|
||
# Include userland master makefile. Contains rules and flags for actually | ||
# building the application. | ||
include $(TOCK_USERLAND_BASE_DIR)/AppMakefile.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Test Multiple Alarms (Simple) | ||
|
||
This tests the virtual alarms available to userspace. It sets two | ||
repeating alarms, at 500ms and 1s respectively, each prints the alarm | ||
index (1 or 2), current tick and alarm expiration to the console. When | ||
successful, both alarms should fire and alarm 1 should fire twice as | ||
often as alarm 2. | ||
|
||
## Example Output | ||
|
||
Correct: | ||
|
||
```sh | ||
1 6316032 6314240 | ||
2 10512384 10510592 | ||
1 10512384 10511104 | ||
1 14722560 14720768 | ||
2 18903552 18901760 | ||
1 18919680 18917632 | ||
1 23116544 23114752 | ||
2 27294720 27292928 | ||
... | ||
``` | ||
|
||
(Note that timestamps, the second and third column, and exact ordering of `1` and `2` will differ by execution) | ||
|
||
Incorrect: | ||
|
||
```sh | ||
1 7254784 7252992 | ||
2 11451136 11449344 | ||
2 19842304 19840512 | ||
2 28233472 28231680 | ||
2 36624640 36622848 | ||
2 45015808 45014016 | ||
2 53406976 53405184 | ||
... | ||
``` | ||
|
||
Note that only alarm `2` appears after the first `1`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
#include <libtock-sync/services/alarm.h> | ||
|
||
static void event_cb(uint32_t now, uint32_t expiration, void* ud) { | ||
int i = (int)ud; | ||
printf("%d %lu %lu\n", i, now, expiration); | ||
} | ||
|
||
int main(void) { | ||
libtock_alarm_t t1; | ||
libtock_alarm_t t2; | ||
|
||
libtock_alarm_repeating_every_ms(500, event_cb, (void*)1, &t1); | ||
libtock_alarm_repeating_every_ms(1000, event_cb, (void*)2, &t2); | ||
|
||
while (1) { | ||
yield(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters