millis code
millis.cpp@0:b6a22ecd3b4f, 2020-09-24 (annotated)
- Committer:
- SomeRandomBloke
- Date:
- Thu Sep 24 19:10:54 2020 +0000
- Revision:
- 0:b6a22ecd3b4f
Frist push
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
SomeRandomBloke | 0:b6a22ecd3b4f | 1 | #include "mbed.h" |
SomeRandomBloke | 0:b6a22ecd3b4f | 2 | #include "millis.h" |
SomeRandomBloke | 0:b6a22ecd3b4f | 3 | /* |
SomeRandomBloke | 0:b6a22ecd3b4f | 4 | millis.cpp |
SomeRandomBloke | 0:b6a22ecd3b4f | 5 | Copyright (c) 2016 Zoltan Hudak <hudakz@inbox.com> |
SomeRandomBloke | 0:b6a22ecd3b4f | 6 | All rights reserved. |
SomeRandomBloke | 0:b6a22ecd3b4f | 7 | |
SomeRandomBloke | 0:b6a22ecd3b4f | 8 | This program is free software: you can redistribute it and/or modify |
SomeRandomBloke | 0:b6a22ecd3b4f | 9 | it under the terms of the GNU General Public License as published by |
SomeRandomBloke | 0:b6a22ecd3b4f | 10 | the Free Software Foundation, either version 3 of the License, or |
SomeRandomBloke | 0:b6a22ecd3b4f | 11 | (at your option) any later version. |
SomeRandomBloke | 0:b6a22ecd3b4f | 12 | |
SomeRandomBloke | 0:b6a22ecd3b4f | 13 | This program is distributed in the hope that it will be useful, |
SomeRandomBloke | 0:b6a22ecd3b4f | 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
SomeRandomBloke | 0:b6a22ecd3b4f | 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
SomeRandomBloke | 0:b6a22ecd3b4f | 16 | GNU General Public License for more details. |
SomeRandomBloke | 0:b6a22ecd3b4f | 17 | |
SomeRandomBloke | 0:b6a22ecd3b4f | 18 | You should have received a copy of the GNU General Public License |
SomeRandomBloke | 0:b6a22ecd3b4f | 19 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
SomeRandomBloke | 0:b6a22ecd3b4f | 20 | */ |
SomeRandomBloke | 0:b6a22ecd3b4f | 21 | |
SomeRandomBloke | 0:b6a22ecd3b4f | 22 | volatile unsigned long _millis; |
SomeRandomBloke | 0:b6a22ecd3b4f | 23 | //Ticker millisTimer; |
SomeRandomBloke | 0:b6a22ecd3b4f | 24 | Timer millisTimer; |
SomeRandomBloke | 0:b6a22ecd3b4f | 25 | |
SomeRandomBloke | 0:b6a22ecd3b4f | 26 | void millis_Handler(void) { |
SomeRandomBloke | 0:b6a22ecd3b4f | 27 | _millis++; |
SomeRandomBloke | 0:b6a22ecd3b4f | 28 | } |
SomeRandomBloke | 0:b6a22ecd3b4f | 29 | |
SomeRandomBloke | 0:b6a22ecd3b4f | 30 | void millisStart(void) { |
SomeRandomBloke | 0:b6a22ecd3b4f | 31 | // millisTimer.attach_us(callback(&millis_Handler), 100); |
SomeRandomBloke | 0:b6a22ecd3b4f | 32 | millisTimer.start(); |
SomeRandomBloke | 0:b6a22ecd3b4f | 33 | } |
SomeRandomBloke | 0:b6a22ecd3b4f | 34 | |
SomeRandomBloke | 0:b6a22ecd3b4f | 35 | |
SomeRandomBloke | 0:b6a22ecd3b4f | 36 | void millisStop(void) { |
SomeRandomBloke | 0:b6a22ecd3b4f | 37 | // millisTimer.detach(); |
SomeRandomBloke | 0:b6a22ecd3b4f | 38 | millisTimer.stop(); |
SomeRandomBloke | 0:b6a22ecd3b4f | 39 | } |
SomeRandomBloke | 0:b6a22ecd3b4f | 40 | |
SomeRandomBloke | 0:b6a22ecd3b4f | 41 | |
SomeRandomBloke | 0:b6a22ecd3b4f | 42 | unsigned long millis(void) { |
SomeRandomBloke | 0:b6a22ecd3b4f | 43 | return millisTimer.read_ms(); |
SomeRandomBloke | 0:b6a22ecd3b4f | 44 | // return _millis; |
SomeRandomBloke | 0:b6a22ecd3b4f | 45 | } |