florent ollivier / Mbed 2 deprecated Gyro

Dependencies:   mbed

Committer:
flo__
Date:
Mon Mar 28 15:54:19 2022 +0000
Revision:
0:b435eadf76b4
28/03/2022

Who changed what in which revision?

UserRevisionLine numberNew contents of line
flo__ 0:b435eadf76b4 1 /* mbed Microcontroller Library
flo__ 0:b435eadf76b4 2 * Copyright (c) 2006-2012 ARM Limited
flo__ 0:b435eadf76b4 3 *
flo__ 0:b435eadf76b4 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
flo__ 0:b435eadf76b4 5 * of this software and associated documentation files (the "Software"), to deal
flo__ 0:b435eadf76b4 6 * in the Software without restriction, including without limitation the rights
flo__ 0:b435eadf76b4 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
flo__ 0:b435eadf76b4 8 * copies of the Software, and to permit persons to whom the Software is
flo__ 0:b435eadf76b4 9 * furnished to do so, subject to the following conditions:
flo__ 0:b435eadf76b4 10 *
flo__ 0:b435eadf76b4 11 * The above copyright notice and this permission notice shall be included in
flo__ 0:b435eadf76b4 12 * all copies or substantial portions of the Software.
flo__ 0:b435eadf76b4 13 *
flo__ 0:b435eadf76b4 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
flo__ 0:b435eadf76b4 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
flo__ 0:b435eadf76b4 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
flo__ 0:b435eadf76b4 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
flo__ 0:b435eadf76b4 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
flo__ 0:b435eadf76b4 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
flo__ 0:b435eadf76b4 20 * SOFTWARE.
flo__ 0:b435eadf76b4 21 */
flo__ 0:b435eadf76b4 22 #include "rtos/RtosTimer.h"
flo__ 0:b435eadf76b4 23
flo__ 0:b435eadf76b4 24 #include <string.h>
flo__ 0:b435eadf76b4 25
flo__ 0:b435eadf76b4 26 #include "mbed.h"
flo__ 0:b435eadf76b4 27 #include "cmsis_os.h"
flo__ 0:b435eadf76b4 28 #include "platform/mbed_error.h"
flo__ 0:b435eadf76b4 29
flo__ 0:b435eadf76b4 30 namespace rtos {
flo__ 0:b435eadf76b4 31
flo__ 0:b435eadf76b4 32 void RtosTimer::constructor(mbed::Callback<void()> func, os_timer_type type) {
flo__ 0:b435eadf76b4 33 #ifdef CMSIS_OS_RTX
flo__ 0:b435eadf76b4 34 _timer.ptimer = (void (*)(const void *))Callback<void()>::thunk;
flo__ 0:b435eadf76b4 35
flo__ 0:b435eadf76b4 36 memset(_timer_data, 0, sizeof(_timer_data));
flo__ 0:b435eadf76b4 37 _timer.timer = _timer_data;
flo__ 0:b435eadf76b4 38 #endif
flo__ 0:b435eadf76b4 39 _function = func;
flo__ 0:b435eadf76b4 40 _timer_id = osTimerCreate(&_timer, type, &_function);
flo__ 0:b435eadf76b4 41 }
flo__ 0:b435eadf76b4 42
flo__ 0:b435eadf76b4 43 osStatus RtosTimer::start(uint32_t millisec) {
flo__ 0:b435eadf76b4 44 return osTimerStart(_timer_id, millisec);
flo__ 0:b435eadf76b4 45 }
flo__ 0:b435eadf76b4 46
flo__ 0:b435eadf76b4 47 osStatus RtosTimer::stop(void) {
flo__ 0:b435eadf76b4 48 return osTimerStop(_timer_id);
flo__ 0:b435eadf76b4 49 }
flo__ 0:b435eadf76b4 50
flo__ 0:b435eadf76b4 51 RtosTimer::~RtosTimer() {
flo__ 0:b435eadf76b4 52 osTimerDelete(_timer_id);
flo__ 0:b435eadf76b4 53 }
flo__ 0:b435eadf76b4 54
flo__ 0:b435eadf76b4 55 }