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