mbed-os
Dependents: cobaLCDJoyMotor_Thread odometry_omni_3roda_v3 odometry_omni_3roda_v1 odometry_omni_3roda_v2 ... more
rtos/RtosTimer.cpp@0:b74591d5ab33, 2017-12-11 (annotated)
- Committer:
- be_bryan
- Date:
- Mon Dec 11 17:54:04 2017 +0000
- Revision:
- 0:b74591d5ab33
motor ++
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
be_bryan | 0:b74591d5ab33 | 1 | /* mbed Microcontroller Library |
be_bryan | 0:b74591d5ab33 | 2 | * Copyright (c) 2006-2012 ARM Limited |
be_bryan | 0:b74591d5ab33 | 3 | * |
be_bryan | 0:b74591d5ab33 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
be_bryan | 0:b74591d5ab33 | 5 | * of this software and associated documentation files (the "Software"), to deal |
be_bryan | 0:b74591d5ab33 | 6 | * in the Software without restriction, including without limitation the rights |
be_bryan | 0:b74591d5ab33 | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
be_bryan | 0:b74591d5ab33 | 8 | * copies of the Software, and to permit persons to whom the Software is |
be_bryan | 0:b74591d5ab33 | 9 | * furnished to do so, subject to the following conditions: |
be_bryan | 0:b74591d5ab33 | 10 | * |
be_bryan | 0:b74591d5ab33 | 11 | * The above copyright notice and this permission notice shall be included in |
be_bryan | 0:b74591d5ab33 | 12 | * all copies or substantial portions of the Software. |
be_bryan | 0:b74591d5ab33 | 13 | * |
be_bryan | 0:b74591d5ab33 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
be_bryan | 0:b74591d5ab33 | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
be_bryan | 0:b74591d5ab33 | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
be_bryan | 0:b74591d5ab33 | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
be_bryan | 0:b74591d5ab33 | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
be_bryan | 0:b74591d5ab33 | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
be_bryan | 0:b74591d5ab33 | 20 | * SOFTWARE. |
be_bryan | 0:b74591d5ab33 | 21 | */ |
be_bryan | 0:b74591d5ab33 | 22 | #include "rtos/RtosTimer.h" |
be_bryan | 0:b74591d5ab33 | 23 | |
be_bryan | 0:b74591d5ab33 | 24 | #include <string.h> |
be_bryan | 0:b74591d5ab33 | 25 | |
be_bryan | 0:b74591d5ab33 | 26 | #include "mbed.h" |
be_bryan | 0:b74591d5ab33 | 27 | #include "platform/mbed_error.h" |
be_bryan | 0:b74591d5ab33 | 28 | |
be_bryan | 0:b74591d5ab33 | 29 | namespace rtos { |
be_bryan | 0:b74591d5ab33 | 30 | |
be_bryan | 0:b74591d5ab33 | 31 | void RtosTimer::constructor(mbed::Callback<void()> func, os_timer_type type) { |
be_bryan | 0:b74591d5ab33 | 32 | _function = func; |
be_bryan | 0:b74591d5ab33 | 33 | memset(&_obj_mem, 0, sizeof(_obj_mem)); |
be_bryan | 0:b74591d5ab33 | 34 | osTimerAttr_t attr = { 0 }; |
be_bryan | 0:b74591d5ab33 | 35 | attr.cb_mem = &_obj_mem; |
be_bryan | 0:b74591d5ab33 | 36 | attr.cb_size = sizeof(_obj_mem); |
be_bryan | 0:b74591d5ab33 | 37 | _id = osTimerNew((void (*)(void *))Callback<void()>::thunk, type, &_function, &attr); |
be_bryan | 0:b74591d5ab33 | 38 | MBED_ASSERT(_id); |
be_bryan | 0:b74591d5ab33 | 39 | } |
be_bryan | 0:b74591d5ab33 | 40 | |
be_bryan | 0:b74591d5ab33 | 41 | osStatus RtosTimer::start(uint32_t millisec) { |
be_bryan | 0:b74591d5ab33 | 42 | return osTimerStart(_id, millisec); |
be_bryan | 0:b74591d5ab33 | 43 | } |
be_bryan | 0:b74591d5ab33 | 44 | |
be_bryan | 0:b74591d5ab33 | 45 | osStatus RtosTimer::stop(void) { |
be_bryan | 0:b74591d5ab33 | 46 | return osTimerStop(_id); |
be_bryan | 0:b74591d5ab33 | 47 | } |
be_bryan | 0:b74591d5ab33 | 48 | |
be_bryan | 0:b74591d5ab33 | 49 | RtosTimer::~RtosTimer() { |
be_bryan | 0:b74591d5ab33 | 50 | osTimerDelete(_id); |
be_bryan | 0:b74591d5ab33 | 51 | } |
be_bryan | 0:b74591d5ab33 | 52 | |
be_bryan | 0:b74591d5ab33 | 53 | } |