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