initial

Dependencies:   mbed

Committer:
yihui
Date:
Mon Jan 11 02:32:24 2016 +0000
Revision:
0:638edba3adf6
initial

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yihui 0:638edba3adf6 1 /* mbed Microcontroller Library
yihui 0:638edba3adf6 2 * Copyright (c) 2006-2013 ARM Limited
yihui 0:638edba3adf6 3 *
yihui 0:638edba3adf6 4 * Licensed under the Apache License, Version 2.0 (the "License");
yihui 0:638edba3adf6 5 * you may not use this file except in compliance with the License.
yihui 0:638edba3adf6 6 * You may obtain a copy of the License at
yihui 0:638edba3adf6 7 *
yihui 0:638edba3adf6 8 * http://www.apache.org/licenses/LICENSE-2.0
yihui 0:638edba3adf6 9 *
yihui 0:638edba3adf6 10 * Unless required by applicable law or agreed to in writing, software
yihui 0:638edba3adf6 11 * distributed under the License is distributed on an "AS IS" BASIS,
yihui 0:638edba3adf6 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
yihui 0:638edba3adf6 13 * See the License for the specific language governing permissions and
yihui 0:638edba3adf6 14 * limitations under the License.
yihui 0:638edba3adf6 15 */
yihui 0:638edba3adf6 16 #include "TimerEvent.h"
yihui 0:638edba3adf6 17 #include "cmsis.h"
yihui 0:638edba3adf6 18
yihui 0:638edba3adf6 19 #include <stddef.h>
yihui 0:638edba3adf6 20 #include "ticker_api.h"
yihui 0:638edba3adf6 21 #include "us_ticker_api.h"
yihui 0:638edba3adf6 22
yihui 0:638edba3adf6 23 namespace mbed {
yihui 0:638edba3adf6 24
yihui 0:638edba3adf6 25 TimerEvent::TimerEvent() : event(), _ticker_data(get_us_ticker_data()) {
yihui 0:638edba3adf6 26 ticker_set_handler(_ticker_data, (&TimerEvent::irq));
yihui 0:638edba3adf6 27 }
yihui 0:638edba3adf6 28
yihui 0:638edba3adf6 29 TimerEvent::TimerEvent(const ticker_data_t *data) : event(), _ticker_data(data) {
yihui 0:638edba3adf6 30 ticker_set_handler(_ticker_data, (&TimerEvent::irq));
yihui 0:638edba3adf6 31 }
yihui 0:638edba3adf6 32
yihui 0:638edba3adf6 33 void TimerEvent::irq(uint32_t id) {
yihui 0:638edba3adf6 34 TimerEvent *timer_event = (TimerEvent*)id;
yihui 0:638edba3adf6 35 timer_event->handler();
yihui 0:638edba3adf6 36 }
yihui 0:638edba3adf6 37
yihui 0:638edba3adf6 38 TimerEvent::~TimerEvent() {
yihui 0:638edba3adf6 39 remove();
yihui 0:638edba3adf6 40 }
yihui 0:638edba3adf6 41
yihui 0:638edba3adf6 42 // insert in to linked list
yihui 0:638edba3adf6 43 void TimerEvent::insert(timestamp_t timestamp) {
yihui 0:638edba3adf6 44 ticker_insert_event(_ticker_data, &event, timestamp, (uint32_t)this);
yihui 0:638edba3adf6 45 }
yihui 0:638edba3adf6 46
yihui 0:638edba3adf6 47 void TimerEvent::remove() {
yihui 0:638edba3adf6 48 ticker_remove_event(_ticker_data, &event);
yihui 0:638edba3adf6 49 }
yihui 0:638edba3adf6 50
yihui 0:638edba3adf6 51 } // namespace mbed