millis

Dependents:   millis_demo PIDHeater Base_Hybrid_V3 Base_Hybrid_V2 ... more

Committer:
lisper
Date:
Fri Oct 31 08:06:55 2014 +0000
Revision:
0:736e6cc31bcd
add millis

Who changed what in which revision?

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