mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #2199 from neilt6/rtos-timer-update
[RTOS] Updated RtosTimer to use Callbackpull/2218/head
commit
239f31b437
|
@ -23,19 +23,21 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "mbed.h"
|
||||||
#include "cmsis_os.h"
|
#include "cmsis_os.h"
|
||||||
#include "mbed_error.h"
|
#include "mbed_error.h"
|
||||||
|
|
||||||
namespace rtos {
|
namespace rtos {
|
||||||
|
|
||||||
RtosTimer::RtosTimer(void (*periodic_task)(void const *argument), os_timer_type type, void *argument) {
|
void RtosTimer::constructor(mbed::Callback<void()> func, os_timer_type type) {
|
||||||
#ifdef CMSIS_OS_RTX
|
#ifdef CMSIS_OS_RTX
|
||||||
_timer.ptimer = periodic_task;
|
_timer.ptimer = (void (*)(const void *))Callback<void()>::thunk;
|
||||||
|
|
||||||
memset(_timer_data, 0, sizeof(_timer_data));
|
memset(_timer_data, 0, sizeof(_timer_data));
|
||||||
_timer.timer = _timer_data;
|
_timer.timer = _timer_data;
|
||||||
#endif
|
#endif
|
||||||
_timer_id = osTimerCreate(&_timer, type, argument);
|
_function = func;
|
||||||
|
_timer_id = osTimerCreate(&_timer, type, &_function);
|
||||||
}
|
}
|
||||||
|
|
||||||
osStatus RtosTimer::start(uint32_t millisec) {
|
osStatus RtosTimer::start(uint32_t millisec) {
|
||||||
|
|
|
@ -24,6 +24,8 @@
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "cmsis_os.h"
|
#include "cmsis_os.h"
|
||||||
|
#include "Callback.h"
|
||||||
|
#include "toolchain.h"
|
||||||
|
|
||||||
namespace rtos {
|
namespace rtos {
|
||||||
|
|
||||||
|
@ -36,21 +38,41 @@ namespace rtos {
|
||||||
*/
|
*/
|
||||||
class RtosTimer {
|
class RtosTimer {
|
||||||
public:
|
public:
|
||||||
/** Create and Start timer.
|
/** Create timer.
|
||||||
@param task name of the timer call back function.
|
@param func function to be executed by this timer.
|
||||||
@param type osTimerOnce for one-shot or osTimerPeriodic for periodic behaviour. (default: osTimerPeriodic)
|
@param type osTimerOnce for one-shot or osTimerPeriodic for periodic behaviour. (default: osTimerPeriodic)
|
||||||
@param argument argument to the timer call back function. (default: NULL)
|
@param argument argument to the timer call back function. (default: NULL)
|
||||||
|
@deprecated Replaced with RtosTimer(Callback<void()>, os_timer_type)
|
||||||
|
*/
|
||||||
|
MBED_DEPRECATED("Replaced with RtosTimer(Callback<void()>, os_timer_type)")
|
||||||
|
RtosTimer(void (*func)(void const *argument), os_timer_type type=osTimerPeriodic, void *argument=NULL) {
|
||||||
|
constructor(mbed::Callback<void()>(argument, (void (*)(void *))func), type);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Create timer.
|
||||||
|
@param func function to be executed by this timer.
|
||||||
|
@param type osTimerOnce for one-shot or osTimerPeriodic for periodic behaviour. (default: osTimerPeriodic)
|
||||||
*/
|
*/
|
||||||
RtosTimer(void (*task)(void const *argument),
|
RtosTimer(mbed::Callback<void()> func, os_timer_type type=osTimerPeriodic) {
|
||||||
os_timer_type type=osTimerPeriodic,
|
constructor(func, type);
|
||||||
void *argument=NULL);
|
}
|
||||||
|
|
||||||
|
/** 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 behaviour. (default: osTimerPeriodic)
|
||||||
|
*/
|
||||||
|
template <typename T, typename M>
|
||||||
|
RtosTimer(T *obj, M method, os_timer_type type=osTimerPeriodic) {
|
||||||
|
constructor(mbed::Callback<void()>(obj, method), type);
|
||||||
|
}
|
||||||
|
|
||||||
/** Stop the timer.
|
/** Stop the timer.
|
||||||
@return status code that indicates the execution status of the function.
|
@return status code that indicates the execution status of the function.
|
||||||
*/
|
*/
|
||||||
osStatus stop(void);
|
osStatus stop(void);
|
||||||
|
|
||||||
/** start a timer.
|
/** Start the timer.
|
||||||
@param millisec time delay value of the timer.
|
@param millisec time delay value of the timer.
|
||||||
@return status code that indicates the execution status of the function.
|
@return status code that indicates the execution status of the function.
|
||||||
*/
|
*/
|
||||||
|
@ -59,6 +81,11 @@ public:
|
||||||
~RtosTimer();
|
~RtosTimer();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// Required to share definitions without
|
||||||
|
// delegated constructors
|
||||||
|
void constructor(mbed::Callback<void()> func, os_timer_type type);
|
||||||
|
|
||||||
|
mbed::Callback<void()> _function;
|
||||||
osTimerId _timer_id;
|
osTimerId _timer_id;
|
||||||
osTimerDef_t _timer;
|
osTimerDef_t _timer;
|
||||||
#if defined(CMSIS_OS_RTX) && !defined(__MBED_CMSIS_RTOS_CM)
|
#if defined(CMSIS_OS_RTX) && !defined(__MBED_CMSIS_RTOS_CM)
|
||||||
|
|
Loading…
Reference in New Issue