mbed-os

Dependents:   cobaLCDJoyMotor_Thread odometry_omni_3roda_v3 odometry_omni_3roda_v1 odometry_omni_3roda_v2 ... more

Committer:
be_bryan
Date:
Mon Dec 11 17:54:04 2017 +0000
Revision:
0:b74591d5ab33
motor ++

Who changed what in which revision?

UserRevisionLine numberNew contents of line
be_bryan 0:b74591d5ab33 1 /* mbed Microcontroller Library
be_bryan 0:b74591d5ab33 2 * Copyright (c) 2006-2013 ARM Limited
be_bryan 0:b74591d5ab33 3 *
be_bryan 0:b74591d5ab33 4 * Licensed under the Apache License, Version 2.0 (the "License");
be_bryan 0:b74591d5ab33 5 * you may not use this file except in compliance with the License.
be_bryan 0:b74591d5ab33 6 * You may obtain a copy of the License at
be_bryan 0:b74591d5ab33 7 *
be_bryan 0:b74591d5ab33 8 * http://www.apache.org/licenses/LICENSE-2.0
be_bryan 0:b74591d5ab33 9 *
be_bryan 0:b74591d5ab33 10 * Unless required by applicable law or agreed to in writing, software
be_bryan 0:b74591d5ab33 11 * distributed under the License is distributed on an "AS IS" BASIS,
be_bryan 0:b74591d5ab33 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
be_bryan 0:b74591d5ab33 13 * See the License for the specific language governing permissions and
be_bryan 0:b74591d5ab33 14 * limitations under the License.
be_bryan 0:b74591d5ab33 15 */
be_bryan 0:b74591d5ab33 16 #include "drivers/Ticker.h"
be_bryan 0:b74591d5ab33 17
be_bryan 0:b74591d5ab33 18 #include "drivers/TimerEvent.h"
be_bryan 0:b74591d5ab33 19 #include "platform/FunctionPointer.h"
be_bryan 0:b74591d5ab33 20 #include "hal/ticker_api.h"
be_bryan 0:b74591d5ab33 21 #include "platform/mbed_critical.h"
be_bryan 0:b74591d5ab33 22
be_bryan 0:b74591d5ab33 23 namespace mbed {
be_bryan 0:b74591d5ab33 24
be_bryan 0:b74591d5ab33 25 void Ticker::detach() {
be_bryan 0:b74591d5ab33 26 core_util_critical_section_enter();
be_bryan 0:b74591d5ab33 27 remove();
be_bryan 0:b74591d5ab33 28 // unlocked only if we were attached (we locked it) and this is not low power ticker
be_bryan 0:b74591d5ab33 29 if(_function && _lock_deepsleep) {
be_bryan 0:b74591d5ab33 30 sleep_manager_unlock_deep_sleep();
be_bryan 0:b74591d5ab33 31 }
be_bryan 0:b74591d5ab33 32
be_bryan 0:b74591d5ab33 33 _function = 0;
be_bryan 0:b74591d5ab33 34 core_util_critical_section_exit();
be_bryan 0:b74591d5ab33 35 }
be_bryan 0:b74591d5ab33 36
be_bryan 0:b74591d5ab33 37 void Ticker::setup(us_timestamp_t t) {
be_bryan 0:b74591d5ab33 38 core_util_critical_section_enter();
be_bryan 0:b74591d5ab33 39 remove();
be_bryan 0:b74591d5ab33 40 _delay = t;
be_bryan 0:b74591d5ab33 41 insert_absolute(_delay + ticker_read_us(_ticker_data));
be_bryan 0:b74591d5ab33 42 core_util_critical_section_exit();
be_bryan 0:b74591d5ab33 43 }
be_bryan 0:b74591d5ab33 44
be_bryan 0:b74591d5ab33 45 void Ticker::handler() {
be_bryan 0:b74591d5ab33 46 insert_absolute(event.timestamp + _delay);
be_bryan 0:b74591d5ab33 47 if (_function) {
be_bryan 0:b74591d5ab33 48 _function();
be_bryan 0:b74591d5ab33 49 }
be_bryan 0:b74591d5ab33 50 }
be_bryan 0:b74591d5ab33 51
be_bryan 0:b74591d5ab33 52 } // namespace mbed