mirror of https://github.com/ARMmbed/mbed-os.git
Remove RtosTimer deprecated class and its APIs
parent
aa6fd58804
commit
8ae2ab404a
|
@ -1,369 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2017 ARM Limited
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#if !defined(MBED_CONF_RTOS_PRESENT)
|
||||
#error [NOT_SUPPORTED] RTOS timer test cases require RTOS to run
|
||||
#else
|
||||
|
||||
#include "mbed.h"
|
||||
#include "greentea-client/test_env.h"
|
||||
#include "unity.h"
|
||||
#include "utest.h"
|
||||
#include "rtos.h"
|
||||
|
||||
using namespace utest::v1;
|
||||
|
||||
#define DELAY_MS 50
|
||||
#define DELTA_MS 5
|
||||
#define RESTART_DELAY_MS 10
|
||||
#define DELAY2_MS 30
|
||||
|
||||
#if RESTART_DELAY_MS >= DELAY_MS
|
||||
#error invalid RESTART_DELAY_MS value
|
||||
#else
|
||||
|
||||
#if !DEVICE_USTICKER
|
||||
#error [NOT_SUPPORTED] test not supported
|
||||
#else
|
||||
|
||||
class Stopwatch: public Timer {
|
||||
private:
|
||||
Semaphore _sem;
|
||||
|
||||
public:
|
||||
Stopwatch() :
|
||||
Timer(), _sem(1)
|
||||
{
|
||||
}
|
||||
|
||||
~Stopwatch()
|
||||
{
|
||||
}
|
||||
|
||||
void start(void)
|
||||
{
|
||||
_sem.try_acquire();
|
||||
Timer::start();
|
||||
}
|
||||
|
||||
void stop(void)
|
||||
{
|
||||
Timer::stop();
|
||||
_sem.release();
|
||||
}
|
||||
|
||||
int32_t wait_until_stopped(uint32_t millisec = osWaitForever)
|
||||
{
|
||||
core_util_critical_section_enter();
|
||||
int running = _running;
|
||||
core_util_critical_section_exit();
|
||||
if (!running) {
|
||||
return 1;
|
||||
}
|
||||
return _sem.try_acquire_for(millisec);
|
||||
}
|
||||
};
|
||||
|
||||
void sem_callback(Semaphore *sem)
|
||||
{
|
||||
sem->release();
|
||||
}
|
||||
|
||||
/** Test one-shot not restarted when elapsed
|
||||
*
|
||||
* Given a one-shot RtosTimer
|
||||
* When the timer is started
|
||||
* and given time elapses
|
||||
* Then timer stops
|
||||
* and elapsed time matches given delay
|
||||
* and timer stays stopped
|
||||
*/
|
||||
void test_oneshot_not_restarted()
|
||||
{
|
||||
Stopwatch stopwatch;
|
||||
RtosTimer rtostimer(mbed::callback(&stopwatch, &Stopwatch::stop), osTimerOnce);
|
||||
|
||||
stopwatch.start();
|
||||
osStatus status = rtostimer.start(DELAY_MS);
|
||||
TEST_ASSERT_EQUAL(osOK, status);
|
||||
|
||||
int32_t slots = stopwatch.wait_until_stopped();
|
||||
TEST_ASSERT_EQUAL(1, slots);
|
||||
TEST_ASSERT_INT_WITHIN(DELTA_MS, DELAY_MS, stopwatch.read_ms());
|
||||
stopwatch.start();
|
||||
|
||||
slots = stopwatch.wait_until_stopped(DELAY_MS + DELTA_MS);
|
||||
TEST_ASSERT_EQUAL(0, slots);
|
||||
|
||||
#if !MBED_TRAP_ERRORS_ENABLED
|
||||
status = rtostimer.stop();
|
||||
TEST_ASSERT_EQUAL(osErrorResource, status);
|
||||
#endif
|
||||
}
|
||||
|
||||
/** Test periodic repeats continuously
|
||||
*
|
||||
* Given a periodic RtosTimer
|
||||
* When timer is started
|
||||
* and given time elapses
|
||||
* Then timer repeats its operation
|
||||
* When timer is stopped
|
||||
* Then timer stops operation
|
||||
*/
|
||||
void test_periodic_repeats()
|
||||
{
|
||||
Stopwatch stopwatch;
|
||||
RtosTimer rtostimer(mbed::callback(&stopwatch, &Stopwatch::stop), osTimerPeriodic);
|
||||
|
||||
stopwatch.start();
|
||||
osStatus status = rtostimer.start(DELAY_MS);
|
||||
TEST_ASSERT_EQUAL(osOK, status);
|
||||
|
||||
int32_t slots = stopwatch.wait_until_stopped();
|
||||
int t1 = stopwatch.read_ms();
|
||||
stopwatch.reset();
|
||||
stopwatch.start();
|
||||
TEST_ASSERT_EQUAL(1, slots);
|
||||
TEST_ASSERT_INT_WITHIN(DELTA_MS, DELAY_MS, t1);
|
||||
|
||||
slots = stopwatch.wait_until_stopped();
|
||||
TEST_ASSERT_EQUAL(1, slots);
|
||||
TEST_ASSERT_INT_WITHIN(DELTA_MS, DELAY_MS, stopwatch.read_ms());
|
||||
stopwatch.start();
|
||||
|
||||
status = rtostimer.stop();
|
||||
TEST_ASSERT_EQUAL(osOK, status);
|
||||
|
||||
slots = stopwatch.wait_until_stopped(DELAY_MS + DELTA_MS);
|
||||
TEST_ASSERT_EQUAL(0, slots);
|
||||
|
||||
#if !MBED_TRAP_ERRORS_ENABLED
|
||||
status = rtostimer.stop();
|
||||
TEST_ASSERT_EQUAL(osErrorResource, status);
|
||||
#endif
|
||||
}
|
||||
|
||||
/** Test timer can be started again
|
||||
*
|
||||
* Given a one-shot Rtosimer
|
||||
* When the timer is started
|
||||
* and given time elapses
|
||||
* Then timer stops
|
||||
* When the timer is started again
|
||||
* and given time elapses
|
||||
* Then timer stops again
|
||||
*/
|
||||
void test_start_again()
|
||||
{
|
||||
Semaphore sem(0, 1);
|
||||
RtosTimer rtostimer(mbed::callback(sem_callback, &sem), osTimerOnce);
|
||||
|
||||
osStatus status = rtostimer.start(DELAY_MS);
|
||||
TEST_ASSERT_EQUAL(osOK, status);
|
||||
|
||||
bool acquired = sem.try_acquire_for(DELAY_MS + DELTA_MS);
|
||||
TEST_ASSERT(acquired);
|
||||
|
||||
#if !MBED_TRAP_ERRORS_ENABLED
|
||||
status = rtostimer.stop();
|
||||
TEST_ASSERT_EQUAL(osErrorResource, status);
|
||||
#endif
|
||||
|
||||
status = rtostimer.start(DELAY_MS);
|
||||
TEST_ASSERT_EQUAL(osOK, status);
|
||||
|
||||
acquired = sem.try_acquire_for(DELAY_MS + DELTA_MS);
|
||||
TEST_ASSERT(acquired);
|
||||
|
||||
#if !MBED_TRAP_ERRORS_ENABLED
|
||||
status = rtostimer.stop();
|
||||
TEST_ASSERT_EQUAL(osErrorResource, status);
|
||||
#endif
|
||||
}
|
||||
|
||||
/** Test timer restart updates delay
|
||||
*
|
||||
* Given a one-shot RtosTimer
|
||||
* When the timer is started
|
||||
* and @a start is called again with a different delay before given time elapses
|
||||
* and updated delay elapses
|
||||
* Then timer stops
|
||||
* and time elapsed since the second @a start call matches updated delay
|
||||
*/
|
||||
void test_restart_updates_delay()
|
||||
{
|
||||
Stopwatch stopwatch;
|
||||
RtosTimer rtostimer(mbed::callback(&stopwatch, &Stopwatch::stop), osTimerOnce);
|
||||
|
||||
stopwatch.start();
|
||||
osStatus status = rtostimer.start(DELAY_MS);
|
||||
TEST_ASSERT_EQUAL(osOK, status);
|
||||
|
||||
int32_t slots = stopwatch.wait_until_stopped(RESTART_DELAY_MS);
|
||||
TEST_ASSERT_EQUAL(0, slots);
|
||||
|
||||
stopwatch.reset();
|
||||
stopwatch.start();
|
||||
status = rtostimer.start(DELAY2_MS);
|
||||
TEST_ASSERT_EQUAL(osOK, status);
|
||||
|
||||
slots = stopwatch.wait_until_stopped();
|
||||
TEST_ASSERT_EQUAL(1, slots);
|
||||
TEST_ASSERT_INT_WITHIN(DELTA_MS, DELAY2_MS, stopwatch.read_ms());
|
||||
|
||||
#if !MBED_TRAP_ERRORS_ENABLED
|
||||
status = rtostimer.stop();
|
||||
TEST_ASSERT_EQUAL(osErrorResource, status);
|
||||
#endif
|
||||
}
|
||||
|
||||
/** Test timer is created in stopped state
|
||||
*
|
||||
* Given a one-shot RtosTimer
|
||||
* When the timer has not been started
|
||||
* Then the timer is stopped
|
||||
*/
|
||||
void test_created_stopped()
|
||||
{
|
||||
RtosTimer rtostimer(mbed::callback(sem_callback, (Semaphore *) NULL), osTimerOnce);
|
||||
#if !MBED_TRAP_ERRORS_ENABLED
|
||||
osStatus status = rtostimer.stop();
|
||||
TEST_ASSERT_EQUAL(osErrorResource, status);
|
||||
#endif
|
||||
}
|
||||
|
||||
/** Test one-shot can be stopped
|
||||
*
|
||||
* Given a one-shot RtosTimer
|
||||
* When the timer is started
|
||||
* and timer is stopped while still running
|
||||
* Then timer stops operation
|
||||
*/
|
||||
void test_stop()
|
||||
{
|
||||
Semaphore sem(0, 1);
|
||||
RtosTimer rtostimer(mbed::callback(sem_callback, &sem), osTimerOnce);
|
||||
|
||||
osStatus status = rtostimer.start(DELAY_MS);
|
||||
TEST_ASSERT_EQUAL(osOK, status);
|
||||
|
||||
bool acquired = sem.try_acquire_for(RESTART_DELAY_MS);
|
||||
TEST_ASSERT_FALSE(acquired);
|
||||
|
||||
status = rtostimer.stop();
|
||||
TEST_ASSERT_EQUAL(osOK, status);
|
||||
|
||||
acquired = sem.try_acquire_for(DELAY_MS + DELTA_MS);
|
||||
TEST_ASSERT_FALSE(acquired);
|
||||
|
||||
#if !MBED_TRAP_ERRORS_ENABLED
|
||||
status = rtostimer.stop();
|
||||
TEST_ASSERT_EQUAL(osErrorResource, status);
|
||||
#endif
|
||||
}
|
||||
|
||||
/** Test timer started with infinite delay
|
||||
*
|
||||
* Given a one-shot RtosTimer
|
||||
* When the timer is started with @a osWaitForever delay
|
||||
* Then @a start return status is @a osOK
|
||||
*/
|
||||
void test_wait_forever()
|
||||
{
|
||||
RtosTimer rtostimer(mbed::callback(sem_callback, (Semaphore *) NULL), osTimerOnce);
|
||||
|
||||
osStatus status = rtostimer.start(osWaitForever);
|
||||
TEST_ASSERT_EQUAL(osOK, status);
|
||||
|
||||
status = rtostimer.stop();
|
||||
TEST_ASSERT_EQUAL(osOK, status);
|
||||
}
|
||||
|
||||
#if !MBED_TRAP_ERRORS_ENABLED
|
||||
/** Test timer started with zero delay
|
||||
*
|
||||
* Given a one-shot RtosTimer
|
||||
* When the timer is started with 0 delay
|
||||
* Then @a start return status is @a osErrorParameter
|
||||
*/
|
||||
void test_no_wait()
|
||||
{
|
||||
RtosTimer rtostimer(mbed::callback(sem_callback, (Semaphore *) NULL), osTimerOnce);
|
||||
|
||||
osStatus status = rtostimer.start(0);
|
||||
TEST_ASSERT_EQUAL(osErrorParameter, status);
|
||||
|
||||
status = rtostimer.stop();
|
||||
TEST_ASSERT_EQUAL(osErrorResource, status);
|
||||
}
|
||||
|
||||
void rtostimer_isr_call(RtosTimer *rtostimer)
|
||||
{
|
||||
osStatus status = rtostimer->start(DELAY_MS);
|
||||
TEST_ASSERT_EQUAL(osErrorISR, status);
|
||||
|
||||
status = rtostimer->stop();
|
||||
TEST_ASSERT_EQUAL(osErrorISR, status);
|
||||
}
|
||||
|
||||
/** Test timer method calls from an ISR fail
|
||||
*
|
||||
* Given a one-shot RtosTimer
|
||||
* When a timer method is called from an ISR
|
||||
* Then method return status is @a osErrorISR
|
||||
*/
|
||||
void test_isr_calls_fail()
|
||||
{
|
||||
RtosTimer rtostimer(mbed::callback(sem_callback, (Semaphore *) NULL), osTimerOnce);
|
||||
|
||||
Ticker ticker;
|
||||
ticker.attach(mbed::callback(rtostimer_isr_call, &rtostimer), (float) DELAY_MS / 1000.0);
|
||||
|
||||
wait_ms(DELAY_MS + DELTA_MS);
|
||||
}
|
||||
#endif // !MBED_TRAP_ERRORS_ENABLED
|
||||
|
||||
utest::v1::status_t test_setup(const size_t number_of_cases)
|
||||
{
|
||||
GREENTEA_SETUP(10, "default_auto");
|
||||
return verbose_test_setup_handler(number_of_cases);
|
||||
}
|
||||
|
||||
Case cases[] = {
|
||||
Case("One-shot not restarted when elapsed", test_oneshot_not_restarted),
|
||||
Case("Periodic repeats continuously", test_periodic_repeats),
|
||||
Case("Stopped timer can be started again", test_start_again),
|
||||
Case("Restart changes timeout", test_restart_updates_delay),
|
||||
Case("Timer can be stopped", test_stop),
|
||||
Case("Timer is created in stopped state", test_created_stopped),
|
||||
Case("Timer started with infinite delay", test_wait_forever),
|
||||
#if !MBED_TRAP_ERRORS_ENABLED
|
||||
Case("Timer started with zero delay", test_no_wait),
|
||||
Case("Calls from ISR fail", test_isr_calls_fail)
|
||||
#endif
|
||||
};
|
||||
|
||||
Specification specification(test_setup, cases);
|
||||
|
||||
int main()
|
||||
{
|
||||
return !Harness::run(specification);
|
||||
}
|
||||
|
||||
#endif // !DEVICE_USTICKER
|
||||
#endif // RESTART_DELAY_MS >= DELAY_MS
|
||||
#endif
|
|
@ -20,8 +20,6 @@ Files licensed under MIT:
|
|||
- rtos.h
|
||||
- rtos_handlers.h
|
||||
- rtos_idle.h
|
||||
- RtosTimer.cpp
|
||||
- RtosTimer.h
|
||||
- Semaphore.cpp
|
||||
- Semaphore.h
|
||||
- ThisThread.cpp
|
||||
|
|
195
rtos/RtosTimer.h
195
rtos/RtosTimer.h
|
@ -1,195 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2019 ARM Limited
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
#ifndef RTOS_TIMER_H
|
||||
#define RTOS_TIMER_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "rtos/mbed_rtos_types.h"
|
||||
#include "rtos/mbed_rtos_storage.h"
|
||||
#include "platform/Callback.h"
|
||||
#include "platform/NonCopyable.h"
|
||||
#include "platform/mbed_toolchain.h"
|
||||
#include "rtos/mbed_rtos1_types.h"
|
||||
|
||||
#if MBED_CONF_RTOS_PRESENT || defined(DOXYGEN_ONLY)
|
||||
|
||||
namespace rtos {
|
||||
/** \addtogroup rtos-public-api */
|
||||
/** @{*/
|
||||
|
||||
/**
|
||||
* \defgroup rtos_RtosTimer RtosTimer class
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** The RtosTimer class allow creating and and controlling of timer functions in the system.
|
||||
A timer function is called when a time period expires whereby both on-shot and
|
||||
periodic timers are possible. A timer can be started, restarted, or stopped.
|
||||
|
||||
Timers are handled in the thread osTimerThread.
|
||||
Callback functions run under control of this thread and may use CMSIS-RTOS API calls.
|
||||
|
||||
@deprecated
|
||||
The RtosTimer has been superseded by the EventQueue. The RtosTimer and EventQueue duplicate
|
||||
the functionality of timing events outside of interrupt context, however the EventQueue
|
||||
has additional features to handle deferring other events to multiple contexts.
|
||||
|
||||
For an example, the following code shows a simple use of the RtosTimer:
|
||||
@code
|
||||
DigitalOut led(LED1);
|
||||
void blink() {
|
||||
led = !led;
|
||||
}
|
||||
|
||||
RtosTimer timer(&blink);
|
||||
int main() {
|
||||
timer.start(1000); // call blink every 1s
|
||||
ThisThread::sleep_for(5000);
|
||||
timer.stop(); // stop after 5s
|
||||
}
|
||||
@endcode
|
||||
|
||||
This is the above example rewritten to use the EventQueue:
|
||||
@code
|
||||
DigitalOut led(LED1);
|
||||
void blink() {
|
||||
led = !led;
|
||||
}
|
||||
|
||||
EventQueue queue(4*EVENTS_EVENT_SIZE);
|
||||
int main() {
|
||||
int blink_id = queue.call_every(1000, &blink); // call blink every 1s
|
||||
queue.dispatch(5000);
|
||||
queue.cancel(blink_id); // stop after 5s
|
||||
}
|
||||
@endcode
|
||||
|
||||
@note
|
||||
Memory considerations: The timer control structures will be created on current thread's stack, both for the mbed OS
|
||||
and underlying RTOS objects (static or dynamic RTOS memory pools are not being used).
|
||||
*/
|
||||
class RtosTimer : private mbed::NonCopyable<RtosTimer> {
|
||||
public:
|
||||
/** Create timer.
|
||||
@param func function to be executed by this timer.
|
||||
@param type osTimerOnce for one-shot or osTimerPeriodic for periodic behavior. (default: osTimerPeriodic)
|
||||
@param argument argument to the timer call back function. (default: nullptr)
|
||||
@deprecated Replaced with RtosTimer(Callback<void()>, os_timer_type)
|
||||
@deprecated
|
||||
The RtosTimer has been superseded by the EventQueue. See RtosTimer.h for more details
|
||||
|
||||
@note You cannot call this function from ISR context.
|
||||
*/
|
||||
MBED_DEPRECATED_SINCE("mbed-os-5.1",
|
||||
"Replaced with RtosTimer(Callback<void()>, os_timer_type)")
|
||||
MBED_DEPRECATED_SINCE("mbed-os-5.2",
|
||||
"The RtosTimer has been superseded by the EventQueue. See RtosTimer.h for more details")
|
||||
RtosTimer(void (*func)(void const *argument), os_timer_type type = osTimerPeriodic, void *argument = nullptr)
|
||||
{
|
||||
constructor(mbed::callback((void (*)(void *))func, argument), type);
|
||||
}
|
||||
|
||||
/** Create timer.
|
||||
@param func function to be executed by this timer.
|
||||
@param type osTimerOnce for one-shot or osTimerPeriodic for periodic behavior. (default: osTimerPeriodic)
|
||||
@deprecated
|
||||
The RtosTimer has been superseded by the EventQueue. See RtosTimer.h for more details
|
||||
|
||||
@note You cannot call this function from ISR context.
|
||||
*/
|
||||
MBED_DEPRECATED_SINCE("mbed-os-5.2",
|
||||
"The RtosTimer has been superseded by the EventQueue. See RtosTimer.h for more details")
|
||||
RtosTimer(mbed::Callback<void()> func, os_timer_type type = osTimerPeriodic)
|
||||
{
|
||||
constructor(func, type);
|
||||
}
|
||||
|
||||
/** Create timer.
|
||||
@param obj pointer to the object to call the member function on.
|
||||
@param method member function to be executed by this timer.
|
||||
@param type osTimerOnce for one-shot or osTimerPeriodic for periodic behavior. (default: osTimerPeriodic)
|
||||
@deprecated
|
||||
The RtosTimer constructor does not support cv-qualifiers. Replaced by
|
||||
RtosTimer(callback(obj, method), os_timer_type).
|
||||
@deprecated
|
||||
The RtosTimer has been superseded by the EventQueue. See RtosTimer.h for more details
|
||||
|
||||
@note You cannot call this function from ISR context.
|
||||
*/
|
||||
template <typename T, typename M>
|
||||
MBED_DEPRECATED_SINCE("mbed-os-5.1",
|
||||
"The RtosTimer constructor does not support cv-qualifiers. Replaced by "
|
||||
"RtosTimer(callback(obj, method), os_timer_type).")
|
||||
MBED_DEPRECATED_SINCE("mbed-os-5.2",
|
||||
"The RtosTimer has been superseded by the EventQueue. See RtosTimer.h for more details")
|
||||
RtosTimer(T *obj, M method, os_timer_type type = osTimerPeriodic)
|
||||
{
|
||||
constructor(mbed::callback(obj, method), type);
|
||||
}
|
||||
|
||||
/** Stop the timer.
|
||||
@return status code that indicates the execution status of the function:
|
||||
@a osOK the timer has been stopped.
|
||||
@a osErrorISR @a stop cannot be called from interrupt service routines.
|
||||
@a osErrorParameter internal error.
|
||||
@a osErrorResource the timer is not running.
|
||||
|
||||
@note You cannot call this function from ISR context.
|
||||
*/
|
||||
osStatus stop(void);
|
||||
|
||||
/** Start or restart the timer.
|
||||
@param millisec non-zero value of the timer.
|
||||
@return status code that indicates the execution status of the function:
|
||||
@a osOK the timer has been started or restarted.
|
||||
@a osErrorISR @a start cannot be called from interrupt service routines.
|
||||
@a osErrorParameter internal error or incorrect parameter value.
|
||||
@a osErrorResource internal error (the timer is in an invalid timer state).
|
||||
|
||||
@note You cannot call this function from ISR context.
|
||||
*/
|
||||
osStatus start(uint32_t millisec);
|
||||
|
||||
/** RtosTimer destructor
|
||||
*
|
||||
* @note You cannot call this function from ISR context.
|
||||
*/
|
||||
~RtosTimer();
|
||||
|
||||
private:
|
||||
// Required to share definitions without
|
||||
// delegated constructors
|
||||
void constructor(mbed::Callback<void()> func, os_timer_type type);
|
||||
|
||||
osTimerId_t _id;
|
||||
mbed_rtos_storage_timer_t _obj_mem;
|
||||
mbed::Callback<void()> _function;
|
||||
};
|
||||
/** @}*/
|
||||
/** @}*/
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -29,7 +29,6 @@
|
|||
#include "rtos/Thread.h"
|
||||
#include "rtos/ThisThread.h"
|
||||
#include "rtos/Mutex.h"
|
||||
#include "rtos/RtosTimer.h"
|
||||
#include "rtos/Semaphore.h"
|
||||
#include "rtos/Mail.h"
|
||||
#include "rtos/MemoryPool.h"
|
||||
|
|
|
@ -1,61 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2012 ARM Limited
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
#include "rtos/RtosTimer.h"
|
||||
#include "platform/Callback.h"
|
||||
#include "platform/mbed_error.h"
|
||||
#include "platform/mbed_assert.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#if MBED_CONF_RTOS_PRESENT
|
||||
|
||||
namespace rtos {
|
||||
|
||||
void RtosTimer::constructor(mbed::Callback<void()> func, os_timer_type type)
|
||||
{
|
||||
_function = func;
|
||||
osTimerAttr_t attr = { 0 };
|
||||
attr.cb_mem = &_obj_mem;
|
||||
attr.cb_size = sizeof(_obj_mem);
|
||||
_id = osTimerNew(mbed::Callback<void()>::thunk, type, &_function, &attr);
|
||||
MBED_ASSERT(_id);
|
||||
}
|
||||
|
||||
osStatus RtosTimer::start(uint32_t millisec)
|
||||
{
|
||||
return osTimerStart(_id, millisec);
|
||||
}
|
||||
|
||||
osStatus RtosTimer::stop(void)
|
||||
{
|
||||
return osTimerStop(_id);
|
||||
}
|
||||
|
||||
RtosTimer::~RtosTimer()
|
||||
{
|
||||
osTimerDelete(_id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue