millis
Dependents: newTicker_demo projekt_Si4703 ModbusRTU-RS232 FoodComputerARM-alpha
millis.cpp@0:9492904126e9, 2014-10-31 (annotated)
- Committer:
- lisper
- Date:
- Fri Oct 31 08:01:02 2014 +0000
- Revision:
- 0:9492904126e9
timer;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lisper | 0:9492904126e9 | 1 | /******************************************************************************* |
lisper | 0:9492904126e9 | 2 | * This file is part of the millis library. * |
lisper | 0:9492904126e9 | 3 | * * |
lisper | 0:9492904126e9 | 4 | * millis is free software: you can redistribute it and/or * |
lisper | 0:9492904126e9 | 5 | * modify it under the terms of the GNU General Public License as * |
lisper | 0:9492904126e9 | 6 | * published by the Free Software Foundation, either version 3 of * |
lisper | 0:9492904126e9 | 7 | * the License, or any later version. * |
lisper | 0:9492904126e9 | 8 | * * |
lisper | 0:9492904126e9 | 9 | * millis is distributed in the hope that it will be useful, * |
lisper | 0:9492904126e9 | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
lisper | 0:9492904126e9 | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
lisper | 0:9492904126e9 | 12 | * GNU Lesser General Public License for more details. * |
lisper | 0:9492904126e9 | 13 | * * |
lisper | 0:9492904126e9 | 14 | * millis is distributed in the hope that it will be useful, * |
lisper | 0:9492904126e9 | 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
lisper | 0:9492904126e9 | 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
lisper | 0:9492904126e9 | 17 | * GNU Lesser General Public License for more details. * |
lisper | 0:9492904126e9 | 18 | * * |
lisper | 0:9492904126e9 | 19 | * You should have received a copy of the GNU Lesser General Public * |
lisper | 0:9492904126e9 | 20 | * License along with millis. If not, see * |
lisper | 0:9492904126e9 | 21 | * <http://www.gnu.org/licenses/>. * |
lisper | 0:9492904126e9 | 22 | ******************************************************************************/ |
lisper | 0:9492904126e9 | 23 | |
lisper | 0:9492904126e9 | 24 | /* |
lisper | 0:9492904126e9 | 25 | * Copyright: DFRobot |
lisper | 0:9492904126e9 | 26 | * name: millis |
lisper | 0:9492904126e9 | 27 | * version: 1.0 |
lisper | 0:9492904126e9 | 28 | * Author: lisper (lisper.li@dfrobot.com) |
lisper | 0:9492904126e9 | 29 | * Date: 2014-10-30 |
lisper | 0:9492904126e9 | 30 | * Description: millis library for mbed |
lisper | 0:9492904126e9 | 31 | */ |
lisper | 0:9492904126e9 | 32 | |
lisper | 0:9492904126e9 | 33 | #include "mbed.h" |
lisper | 0:9492904126e9 | 34 | #include "millis.h" |
lisper | 0:9492904126e9 | 35 | |
lisper | 0:9492904126e9 | 36 | static volatile uint32_t millisValue = 0; |
lisper | 0:9492904126e9 | 37 | |
lisper | 0:9492904126e9 | 38 | static Ticker ticker; |
lisper | 0:9492904126e9 | 39 | |
lisper | 0:9492904126e9 | 40 | void millisTicker () |
lisper | 0:9492904126e9 | 41 | { |
lisper | 0:9492904126e9 | 42 | millisValue ++; |
lisper | 0:9492904126e9 | 43 | } |
lisper | 0:9492904126e9 | 44 | |
lisper | 0:9492904126e9 | 45 | uint32_t millis () |
lisper | 0:9492904126e9 | 46 | { |
lisper | 0:9492904126e9 | 47 | return millisValue; |
lisper | 0:9492904126e9 | 48 | } |
lisper | 0:9492904126e9 | 49 | |
lisper | 0:9492904126e9 | 50 | void setMillis (uint32_t theValue) { |
lisper | 0:9492904126e9 | 51 | millisValue = theValue; |
lisper | 0:9492904126e9 | 52 | } |
lisper | 0:9492904126e9 | 53 | |
lisper | 0:9492904126e9 | 54 | void startMillis () { |
lisper | 0:9492904126e9 | 55 | ticker.attach (millisTicker, 0.001); |
lisper | 0:9492904126e9 | 56 | } |
lisper | 0:9492904126e9 | 57 | |
lisper | 0:9492904126e9 | 58 | void stopMillis () { |
lisper | 0:9492904126e9 | 59 | ticker.detach (); |
lisper | 0:9492904126e9 | 60 | } |
lisper | 0:9492904126e9 | 61 | |
lisper | 0:9492904126e9 | 62 |