BA
/
BaBoRo1
Erste version der Software für der Prototyp
mbed-os/drivers/TimerEvent.cpp@4:75df35ef4fb6, 2018-03-30 (annotated)
- Committer:
- borlanic
- Date:
- Fri Mar 30 14:07:05 2018 +0000
- Revision:
- 4:75df35ef4fb6
- Parent:
- 0:380207fcb5c1
commentar
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
borlanic | 0:380207fcb5c1 | 1 | /* mbed Microcontroller Library |
borlanic | 0:380207fcb5c1 | 2 | * Copyright (c) 2006-2013 ARM Limited |
borlanic | 0:380207fcb5c1 | 3 | * |
borlanic | 0:380207fcb5c1 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
borlanic | 0:380207fcb5c1 | 5 | * you may not use this file except in compliance with the License. |
borlanic | 0:380207fcb5c1 | 6 | * You may obtain a copy of the License at |
borlanic | 0:380207fcb5c1 | 7 | * |
borlanic | 0:380207fcb5c1 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
borlanic | 0:380207fcb5c1 | 9 | * |
borlanic | 0:380207fcb5c1 | 10 | * Unless required by applicable law or agreed to in writing, software |
borlanic | 0:380207fcb5c1 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
borlanic | 0:380207fcb5c1 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
borlanic | 0:380207fcb5c1 | 13 | * See the License for the specific language governing permissions and |
borlanic | 0:380207fcb5c1 | 14 | * limitations under the License. |
borlanic | 0:380207fcb5c1 | 15 | */ |
borlanic | 0:380207fcb5c1 | 16 | #include "drivers/TimerEvent.h" |
borlanic | 0:380207fcb5c1 | 17 | #include "cmsis.h" |
borlanic | 0:380207fcb5c1 | 18 | |
borlanic | 0:380207fcb5c1 | 19 | #include <stddef.h> |
borlanic | 0:380207fcb5c1 | 20 | #include "hal/ticker_api.h" |
borlanic | 0:380207fcb5c1 | 21 | #include "hal/us_ticker_api.h" |
borlanic | 0:380207fcb5c1 | 22 | |
borlanic | 0:380207fcb5c1 | 23 | namespace mbed { |
borlanic | 0:380207fcb5c1 | 24 | |
borlanic | 0:380207fcb5c1 | 25 | TimerEvent::TimerEvent() : event(), _ticker_data(get_us_ticker_data()) { |
borlanic | 0:380207fcb5c1 | 26 | ticker_set_handler(_ticker_data, (&TimerEvent::irq)); |
borlanic | 0:380207fcb5c1 | 27 | } |
borlanic | 0:380207fcb5c1 | 28 | |
borlanic | 0:380207fcb5c1 | 29 | TimerEvent::TimerEvent(const ticker_data_t *data) : event(), _ticker_data(data) { |
borlanic | 0:380207fcb5c1 | 30 | ticker_set_handler(_ticker_data, (&TimerEvent::irq)); |
borlanic | 0:380207fcb5c1 | 31 | } |
borlanic | 0:380207fcb5c1 | 32 | |
borlanic | 0:380207fcb5c1 | 33 | void TimerEvent::irq(uint32_t id) { |
borlanic | 0:380207fcb5c1 | 34 | TimerEvent *timer_event = (TimerEvent*)id; |
borlanic | 0:380207fcb5c1 | 35 | timer_event->handler(); |
borlanic | 0:380207fcb5c1 | 36 | } |
borlanic | 0:380207fcb5c1 | 37 | |
borlanic | 0:380207fcb5c1 | 38 | TimerEvent::~TimerEvent() { |
borlanic | 0:380207fcb5c1 | 39 | remove(); |
borlanic | 0:380207fcb5c1 | 40 | } |
borlanic | 0:380207fcb5c1 | 41 | |
borlanic | 0:380207fcb5c1 | 42 | // insert in to linked list |
borlanic | 0:380207fcb5c1 | 43 | void TimerEvent::insert(timestamp_t timestamp) { |
borlanic | 0:380207fcb5c1 | 44 | ticker_insert_event(_ticker_data, &event, timestamp, (uint32_t)this); |
borlanic | 0:380207fcb5c1 | 45 | } |
borlanic | 0:380207fcb5c1 | 46 | |
borlanic | 0:380207fcb5c1 | 47 | void TimerEvent::insert_absolute(us_timestamp_t timestamp) { |
borlanic | 0:380207fcb5c1 | 48 | ticker_insert_event_us(_ticker_data, &event, timestamp, (uint32_t)this); |
borlanic | 0:380207fcb5c1 | 49 | } |
borlanic | 0:380207fcb5c1 | 50 | |
borlanic | 0:380207fcb5c1 | 51 | void TimerEvent::remove() { |
borlanic | 0:380207fcb5c1 | 52 | ticker_remove_event(_ticker_data, &event); |
borlanic | 0:380207fcb5c1 | 53 | } |
borlanic | 0:380207fcb5c1 | 54 | |
borlanic | 0:380207fcb5c1 | 55 | } // namespace mbed |