2009-08-16 13:07:24 +00:00
|
|
|
/*
|
2015-01-11 13:56:55 +00:00
|
|
|
ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2013-05-11 06:08:17 +00:00
|
|
|
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
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2013-05-11 06:08:17 +00:00
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2013-05-11 06:08:17 +00:00
|
|
|
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.
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2011-06-27 15:00:05 +00:00
|
|
|
* @file evtimer.c
|
|
|
|
* @brief Events Generator Timer code.
|
|
|
|
*
|
2009-08-16 13:07:24 +00:00
|
|
|
* @addtogroup event_timer
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2009-12-08 17:37:49 +00:00
|
|
|
#include "ch.h"
|
2009-08-16 13:07:24 +00:00
|
|
|
#include "evtimer.h"
|
|
|
|
|
2013-09-20 12:25:11 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* Module local definitions. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Module exported variables. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Module local types. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Module local variables. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Module local functions. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2009-08-16 13:07:24 +00:00
|
|
|
static void tmrcb(void *p) {
|
2013-09-20 12:25:11 +00:00
|
|
|
event_timer_t *etp = p;
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2013-09-20 12:25:11 +00:00
|
|
|
chSysLockFromISR();
|
2009-08-16 13:07:24 +00:00
|
|
|
chEvtBroadcastI(&etp->et_es);
|
2013-09-20 12:25:11 +00:00
|
|
|
chVTDoSetI(&etp->et_vt, etp->et_interval, tmrcb, etp);
|
|
|
|
chSysUnlockFromISR();
|
2009-08-16 13:07:24 +00:00
|
|
|
}
|
|
|
|
|
2013-09-20 12:25:11 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* Module exported functions. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2009-08-16 13:07:24 +00:00
|
|
|
/**
|
2013-09-20 12:25:11 +00:00
|
|
|
* @brief Initializes an @p event_timer_t structure.
|
2009-08-16 13:07:24 +00:00
|
|
|
*
|
2013-09-20 12:25:11 +00:00
|
|
|
* @param[out] etp the @p event_timer_t structure to be initialized
|
|
|
|
* @param[in] time the interval in system ticks
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2013-09-20 12:25:11 +00:00
|
|
|
void evtObjectInit(event_timer_t *etp, systime_t time) {
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2013-09-20 12:25:11 +00:00
|
|
|
chEvtObjectInit(&etp->et_es);
|
|
|
|
chVTObjectInit(&etp->et_vt);
|
|
|
|
etp->et_interval = time;
|
2009-08-16 13:07:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-09-20 12:25:11 +00:00
|
|
|
* @brief Starts the timer
|
|
|
|
* @details If the timer was already running then the function has no effect.
|
2009-08-16 13:07:24 +00:00
|
|
|
*
|
2013-09-20 12:25:11 +00:00
|
|
|
* @param[in] etp pointer to an initialized @p event_timer_t structure.
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2013-09-20 12:25:11 +00:00
|
|
|
void evtStart(event_timer_t *etp) {
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2013-09-20 12:25:11 +00:00
|
|
|
chVTSet(&etp->et_vt, etp->et_interval, tmrcb, etp);
|
2009-08-16 13:07:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @} */
|