diff options
-rw-r--r-- | examples/test-systick.cpp | 60 | ||||
-rw-r--r-- | libmaple/systick.c | 7 | ||||
-rw-r--r-- | libmaple/systick.h | 1 | ||||
-rw-r--r-- | wirish/SystemTick.cpp | 40 | ||||
-rw-r--r-- | wirish/SystemTick.h | 43 | ||||
-rw-r--r-- | wirish/rules.mk | 1 | ||||
-rw-r--r-- | wirish/wirish.h | 1 |
7 files changed, 68 insertions, 85 deletions
diff --git a/examples/test-systick.cpp b/examples/test-systick.cpp new file mode 100644 index 0000000..247892d --- /dev/null +++ b/examples/test-systick.cpp @@ -0,0 +1,60 @@ +// Tests the SysTick enable/disable functions +// +#include "wirish.h" +#include "systick.h" + +#define LED_PIN 13 +#define PWM_PIN 2 +#define BUT 38 + +void setup() +{ + /* Set up the LED to blink */ + pinMode(LED_PIN, OUTPUT); + + /* Turn on PWM on pin PWM_PIN */ + pinMode(PWM_PIN, PWM); + pwmWrite(PWM_PIN, 0x8000); + + pinMode(BUT, INPUT_PULLDOWN); +} + +int toggle = 0; +long time = 0; + +void loop() { + toggle ^= 1; + digitalWrite(LED_PIN, toggle); + + // An artificial delay + int16 i = 1; + float j = 1; + for(i=0; i<6553; i++) { + j = sqrt(j) + 1; + } + + if(digitalRead(BUT)) { + systick_disable(); + } else { + systick_resume(); + } + + //SerialUSB.println(micros()); // there is a bug with this + 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 (1) { + loop(); + } + return 0; +} diff --git a/libmaple/systick.c b/libmaple/systick.c index 456ac2f..9fbb152 100644 --- a/libmaple/systick.c +++ b/libmaple/systick.c @@ -58,6 +58,13 @@ void systick_disable() { __write(SYSTICK_CSR, SYSTICK_SRC_HCLK); } +void systick_resume() { + /* re-enable init registers without changing relead_val */ + __write(SYSTICK_CSR, SYSTICK_SRC_HCLK | + SYSTICK_ENABLE | + SYSTICK_TICKINT); +} + void SysTickHandler(void) { systick_timer_millis++; } diff --git a/libmaple/systick.h b/libmaple/systick.h index 86284f8..80e2fde 100644 --- a/libmaple/systick.h +++ b/libmaple/systick.h @@ -44,6 +44,7 @@ extern "C"{ void systick_init(uint32 reload_val); void systick_disable(); +void systick_resume(); static inline uint32 systick_get_count(void) { return __read(SYSTICK_CNT); diff --git a/wirish/SystemTick.cpp b/wirish/SystemTick.cpp deleted file mode 100644 index 8631a70..0000000 --- a/wirish/SystemTick.cpp +++ /dev/null @@ -1,40 +0,0 @@ -/* ***************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Marti F. Bolivar. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * ****************************************************************************/ - -#include "SystemTick.h" -#include "systick.h" -#include "time.h" - -SysTick::SysTick(void) { -} - -void SysTick::begin(void) { - systick_init(MAPLE_RELOAD_VAL); -} - -void SysTick::end(void) { - systick_disable(); -} - -SysTick SystemTick; diff --git a/wirish/SystemTick.h b/wirish/SystemTick.h deleted file mode 100644 index f0dd876..0000000 --- a/wirish/SystemTick.h +++ /dev/null @@ -1,43 +0,0 @@ -/* ***************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Marti F. Bolivar. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * ****************************************************************************/ - -/** - * @brief wrapper class for starting and stopping SysTick interrupts. - */ - -#ifndef _SYSTEMTICK_H_ -#define _SYSTEMTICK_H_ - -#include "systick.h" - -class SysTick { - public: - SysTick(void); - void begin(void); - void end(void); -}; - -extern SysTick SystemTick; - -#endif diff --git a/wirish/rules.mk b/wirish/rules.mk index 18d93b2..cb5a69f 100644 --- a/wirish/rules.mk +++ b/wirish/rules.mk @@ -26,7 +26,6 @@ cppSRCS_$(d) := wirish_math.cpp \ usb_serial.cpp \ HardwareTimer.cpp \ cxxabi-compat.cpp \ - SystemTick.cpp cFILES_$(d) := $(cSRCS_$(d):%=$(d)/%) cppFILES_$(d) := $(cppSRCS_$(d):%=$(d)/%) diff --git a/wirish/wirish.h b/wirish/wirish.h index d293901..7ede77c 100644 --- a/wirish/wirish.h +++ b/wirish/wirish.h @@ -45,7 +45,6 @@ #include "HardwareSPI.h" #include "HardwareSerial.h" #include "usb_serial.h" -#include "SystemTick.h" #include "HardwareTimer.h" #endif |