aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test-systick.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test-systick.cpp')
-rw-r--r--tests/test-systick.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/test-systick.cpp b/tests/test-systick.cpp
new file mode 100644
index 0000000..356f302
--- /dev/null
+++ b/tests/test-systick.cpp
@@ -0,0 +1,49 @@
+// Tests the SysTick enable/disable functions
+
+#include <wirish/wirish.h>
+#include <libmaple/systick.h>
+
+void setup() {
+ pinMode(BOARD_LED_PIN, OUTPUT);
+ pinMode(BOARD_BUTTON_PIN, INPUT);
+}
+
+bool disable = true;
+long time = 0;
+
+void loop() {
+ volatile int i = 0;
+ toggleLED();
+
+ // An artificial delay
+ for(i = 0; i < 150000; i++)
+ ;
+
+ if (isButtonPressed()) {
+ if (disable) {
+ systick_disable();
+ SerialUSB.println("Disabling SysTick");
+ } else {
+ SerialUSB.println("Re-enabling SysTick");
+ systick_enable();
+ }
+ disable = !disable;
+ }
+
+ SerialUSB.println(millis());
+}
+
+// Force init to be called *first*, i.e. before static object allocation.
+// Otherwise, statically allocated object that need libmaple may fail.
+__attribute__((constructor)) void premain() {
+ init();
+}
+
+int main(void) {
+ setup();
+
+ while (true) {
+ loop();
+ }
+ return 0;
+}