customized mbed library sources for nrf51822
Dependents: Grove_Node Potentiometer BLE_Beacon I2C_Scanner
common/TimerEvent.cpp@0:700cadd8b708, 2014-11-04 (annotated)
- Committer:
- yihui
- Date:
- Tue Nov 04 07:38:53 2014 +0000
- Revision:
- 0:700cadd8b708
customized mbed-src library for nrf51822
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yihui | 0:700cadd8b708 | 1 | /* mbed Microcontroller Library |
yihui | 0:700cadd8b708 | 2 | * Copyright (c) 2006-2013 ARM Limited |
yihui | 0:700cadd8b708 | 3 | * |
yihui | 0:700cadd8b708 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
yihui | 0:700cadd8b708 | 5 | * you may not use this file except in compliance with the License. |
yihui | 0:700cadd8b708 | 6 | * You may obtain a copy of the License at |
yihui | 0:700cadd8b708 | 7 | * |
yihui | 0:700cadd8b708 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
yihui | 0:700cadd8b708 | 9 | * |
yihui | 0:700cadd8b708 | 10 | * Unless required by applicable law or agreed to in writing, software |
yihui | 0:700cadd8b708 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
yihui | 0:700cadd8b708 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
yihui | 0:700cadd8b708 | 13 | * See the License for the specific language governing permissions and |
yihui | 0:700cadd8b708 | 14 | * limitations under the License. |
yihui | 0:700cadd8b708 | 15 | */ |
yihui | 0:700cadd8b708 | 16 | #include "TimerEvent.h" |
yihui | 0:700cadd8b708 | 17 | #include "cmsis.h" |
yihui | 0:700cadd8b708 | 18 | |
yihui | 0:700cadd8b708 | 19 | #include <stddef.h> |
yihui | 0:700cadd8b708 | 20 | |
yihui | 0:700cadd8b708 | 21 | namespace mbed { |
yihui | 0:700cadd8b708 | 22 | |
yihui | 0:700cadd8b708 | 23 | TimerEvent::TimerEvent() : event() { |
yihui | 0:700cadd8b708 | 24 | us_ticker_set_handler((&TimerEvent::irq)); |
yihui | 0:700cadd8b708 | 25 | } |
yihui | 0:700cadd8b708 | 26 | |
yihui | 0:700cadd8b708 | 27 | void TimerEvent::irq(uint32_t id) { |
yihui | 0:700cadd8b708 | 28 | TimerEvent *timer_event = (TimerEvent*)id; |
yihui | 0:700cadd8b708 | 29 | timer_event->handler(); |
yihui | 0:700cadd8b708 | 30 | } |
yihui | 0:700cadd8b708 | 31 | |
yihui | 0:700cadd8b708 | 32 | TimerEvent::~TimerEvent() { |
yihui | 0:700cadd8b708 | 33 | remove(); |
yihui | 0:700cadd8b708 | 34 | } |
yihui | 0:700cadd8b708 | 35 | |
yihui | 0:700cadd8b708 | 36 | // insert in to linked list |
yihui | 0:700cadd8b708 | 37 | void TimerEvent::insert(timestamp_t timestamp) { |
yihui | 0:700cadd8b708 | 38 | us_ticker_insert_event(&event, timestamp, (uint32_t)this); |
yihui | 0:700cadd8b708 | 39 | } |
yihui | 0:700cadd8b708 | 40 | |
yihui | 0:700cadd8b708 | 41 | void TimerEvent::remove() { |
yihui | 0:700cadd8b708 | 42 | us_ticker_remove_event(&event); |
yihui | 0:700cadd8b708 | 43 | } |
yihui | 0:700cadd8b708 | 44 | |
yihui | 0:700cadd8b708 | 45 | } // namespace mbed |