Rob Griffith / Mbed 2 deprecated rat_code

Dependencies:   mbed QEI

Revision:
1:6f18bb7a77a5
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/systick.cpp	Thu Nov 15 17:19:20 2018 +0000
@@ -0,0 +1,44 @@
+#include "systick.h"
+#include "mbed.h"
+#include "globals.h"
+
+void systickFunction() {
+    // Update global counter
+    millis++;
+
+    /**
+     * Assignment 3ab: Do something with your controllers here,
+     * maybe update them? (hint hint)
+     **/
+     mainController.update();
+}
+
+void Systick::start() {
+    /**
+     * Assignment 3a: Start your systick function (above).
+     * Hint: use 'm_systicker', the Ticker variable (systick.h).
+     **/
+     m_systicker.attach_us(&systickFunction, 1000);
+}
+
+void Systick::stop() {
+    /**
+     * Assignment 3a: Stop the systick (use "detach" function of the Ticker class).
+     **/
+     m_systicker.detach();
+}
+
+Systick::Systick() {
+    // A little bit of magic; if you want to know why, ask Robert
+    NVIC_SetPriority(TIM5_IRQn, 255);
+}
+
+void Systick::wait(float sec) {
+    // Utility function: allows you to wait while using systick.
+    int init = millis;
+    
+    float num_ticks = sec / SYS_TICK_TIME;
+
+    while (millis - init < num_ticks)
+        ;
+}
\ No newline at end of file