Elijah Stanger-Jones / mbed-dev-f303
Committer:
elijahsj
Date:
Mon Nov 09 00:02:47 2020 -0500
Revision:
1:8a094db1347f
test

Who changed what in which revision?

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