Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
src/systick.cpp@1:6f18bb7a77a5, 2018-11-15 (annotated)
- Committer:
- dionigi
- Date:
- Thu Nov 15 17:19:20 2018 +0000
- Revision:
- 1:6f18bb7a77a5
Added assignment3 files
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dionigi | 1:6f18bb7a77a5 | 1 | #include "systick.h" |
dionigi | 1:6f18bb7a77a5 | 2 | #include "mbed.h" |
dionigi | 1:6f18bb7a77a5 | 3 | #include "globals.h" |
dionigi | 1:6f18bb7a77a5 | 4 | |
dionigi | 1:6f18bb7a77a5 | 5 | void systickFunction() { |
dionigi | 1:6f18bb7a77a5 | 6 | // Update global counter |
dionigi | 1:6f18bb7a77a5 | 7 | millis++; |
dionigi | 1:6f18bb7a77a5 | 8 | |
dionigi | 1:6f18bb7a77a5 | 9 | /** |
dionigi | 1:6f18bb7a77a5 | 10 | * Assignment 3ab: Do something with your controllers here, |
dionigi | 1:6f18bb7a77a5 | 11 | * maybe update them? (hint hint) |
dionigi | 1:6f18bb7a77a5 | 12 | **/ |
dionigi | 1:6f18bb7a77a5 | 13 | mainController.update(); |
dionigi | 1:6f18bb7a77a5 | 14 | } |
dionigi | 1:6f18bb7a77a5 | 15 | |
dionigi | 1:6f18bb7a77a5 | 16 | void Systick::start() { |
dionigi | 1:6f18bb7a77a5 | 17 | /** |
dionigi | 1:6f18bb7a77a5 | 18 | * Assignment 3a: Start your systick function (above). |
dionigi | 1:6f18bb7a77a5 | 19 | * Hint: use 'm_systicker', the Ticker variable (systick.h). |
dionigi | 1:6f18bb7a77a5 | 20 | **/ |
dionigi | 1:6f18bb7a77a5 | 21 | m_systicker.attach_us(&systickFunction, 1000); |
dionigi | 1:6f18bb7a77a5 | 22 | } |
dionigi | 1:6f18bb7a77a5 | 23 | |
dionigi | 1:6f18bb7a77a5 | 24 | void Systick::stop() { |
dionigi | 1:6f18bb7a77a5 | 25 | /** |
dionigi | 1:6f18bb7a77a5 | 26 | * Assignment 3a: Stop the systick (use "detach" function of the Ticker class). |
dionigi | 1:6f18bb7a77a5 | 27 | **/ |
dionigi | 1:6f18bb7a77a5 | 28 | m_systicker.detach(); |
dionigi | 1:6f18bb7a77a5 | 29 | } |
dionigi | 1:6f18bb7a77a5 | 30 | |
dionigi | 1:6f18bb7a77a5 | 31 | Systick::Systick() { |
dionigi | 1:6f18bb7a77a5 | 32 | // A little bit of magic; if you want to know why, ask Robert |
dionigi | 1:6f18bb7a77a5 | 33 | NVIC_SetPriority(TIM5_IRQn, 255); |
dionigi | 1:6f18bb7a77a5 | 34 | } |
dionigi | 1:6f18bb7a77a5 | 35 | |
dionigi | 1:6f18bb7a77a5 | 36 | void Systick::wait(float sec) { |
dionigi | 1:6f18bb7a77a5 | 37 | // Utility function: allows you to wait while using systick. |
dionigi | 1:6f18bb7a77a5 | 38 | int init = millis; |
dionigi | 1:6f18bb7a77a5 | 39 | |
dionigi | 1:6f18bb7a77a5 | 40 | float num_ticks = sec / SYS_TICK_TIME; |
dionigi | 1:6f18bb7a77a5 | 41 | |
dionigi | 1:6f18bb7a77a5 | 42 | while (millis - init < num_ticks) |
dionigi | 1:6f18bb7a77a5 | 43 | ; |
dionigi | 1:6f18bb7a77a5 | 44 | } |