aboutsummaryrefslogtreecommitdiff
path: root/module/timer
diff options
context:
space:
mode:
authorElieva Pignat <Elieva.Pignat@arm.com>2018-07-27 09:20:15 +0100
committerronald-cron-arm <39518861+ronald-cron-arm@users.noreply.github.com>2018-09-04 15:05:04 +0200
commit6bc132d9829067098de1a8bc57942274b716c5b1 (patch)
treeba18639e10d26672e07e62dac968e1bfe586b48a /module/timer
parentb36d15b2096472bd26b74c17fcbf89fcdb2cc97a (diff)
timer: alarm triggers a callback function
When an alarm is triggered a callback function is called instead of sending an event to the module or element that set the alarm. That way an alarm trigger does not necessarily generate an event and for example register polling can be done more effectively. Change-Id: I7ef16976c8f90e3f772ae57056f5891636533170 Signed-off-by: Elieva Pignat <Elieva.Pignat@arm.com>
Diffstat (limited to 'module/timer')
-rw-r--r--module/timer/include/mod_timer.h16
-rw-r--r--module/timer/src/mod_timer.c29
2 files changed, 14 insertions, 31 deletions
diff --git a/module/timer/include/mod_timer.h b/module/timer/include/mod_timer.h
index 1caca802..34c522c6 100644
--- a/module/timer/include/mod_timer.h
+++ b/module/timer/include/mod_timer.h
@@ -253,9 +253,7 @@ struct mod_timer_alarm_api {
/*!
* \brief Start an alarm so it will trigger after a specified time.
*
- * \details When an alarm is triggered, an event with identifier
- * \p event_id will be sent to the entity that is bound to the alarm.
- * The first word of the event's parameter will be set to \p param.
+ * \details When an alarm is triggered, \p callback is called.
*
* If the alarm is periodic, it will automatically be started again
* with the same time delay after it triggers.
@@ -264,13 +262,16 @@ struct mod_timer_alarm_api {
* case, internally, the alarm will be stopped then started again with
* the new configuration.
*
+ * \warning \p callback will be called from within an interrupt service
+ * routine.
+ *
* \param alarm_id Sub-element identifier of the alarm.
- * \param event_id Identifier of the event the caller is expecting.
* \param milliseconds The time delay, given in milliseconds, until the
* alarm should trigger.
* \param type \ref MOD_TIMER_ALARM_TYPE_ONCE or
* \ref MOD_TIMER_ALARM_TYPE_PERIODIC.
- * \param param Word-size parameter for the event.
+ * \param callback Pointer to the callback function.
+ * \param param Parameter given to the callback function when called.
*
* \pre \p alarm_id must be a valid sub-element alarm identifier that has
* previously been bound to.
@@ -280,7 +281,7 @@ struct mod_timer_alarm_api {
int (*start)(fwk_id_t alarm_id,
unsigned int milliseconds,
enum mod_timer_alarm_type type,
- fwk_id_t event_id,
+ void (*callback)(uintptr_t param),
uintptr_t param);
/*!
@@ -290,9 +291,6 @@ struct mod_timer_alarm_api {
* alarm from triggering. This does not undo the binding of the alarm
* and it can be started again afterwards.
*
- * Any pending alarm events associated with the alarm are not cancelled
- * or removed when the alarm is stopped.
- *
* \param alarm_id Sub-element identifier of the alarm item.
*
* \pre \p alarm_id must be a valid sub-element alarm identifier that has
diff --git a/module/timer/src/mod_timer.c b/module/timer/src/mod_timer.c
index 8fc61399..e398af7b 100644
--- a/module/timer/src/mod_timer.c
+++ b/module/timer/src/mod_timer.c
@@ -48,11 +48,9 @@ struct alarm_ctx {
uint32_t microseconds;
/* Timestamp of the time this alarm will trigger */
uint64_t timestamp;
- /* Identifier of the entity to send the alarm event to */
- fwk_id_t listener;
- /* Identifier of the event the listener is expecting to receive */
- fwk_id_t event_id;
- /* Parameter of the event */
+ /* Pointer to the callback function */
+ void (*callback)(uintptr_t param);
+ /* Parameter of the callback function */
uintptr_t param;
/* Flag indicating if this alarm if periodic */
bool periodic;
@@ -416,7 +414,7 @@ static int alarm_stop(fwk_id_t alarm_id)
static int alarm_start(fwk_id_t alarm_id,
unsigned int milliseconds,
enum mod_timer_alarm_type type,
- fwk_id_t event_id,
+ void (*callback)(uintptr_t param),
uintptr_t param)
{
int status;
@@ -439,7 +437,7 @@ static int alarm_start(fwk_id_t alarm_id,
milliseconds = FWK_MIN(milliseconds, UINT32_MAX / 1000);
/* Populate alarm item */
- alarm->event_id = event_id;
+ alarm->callback = callback;
alarm->param = param;
alarm->periodic =
(type == MOD_TIMER_ALARM_TYPE_PERIODIC ? true : false);
@@ -471,7 +469,6 @@ static void timer_isr(uintptr_t ctx_ptr)
struct alarm_ctx *alarm;
struct dev_ctx *ctx = (struct dev_ctx *)ctx_ptr;
uint64_t timestamp = 0;
- struct fwk_event event;
assert(ctx != NULL);
@@ -489,19 +486,8 @@ static void timer_isr(uintptr_t ctx_ptr)
alarm->started = false;
- event = (struct fwk_event) {
- .source_id = fwk_module_id_timer,
- .target_id = alarm->listener,
- .id = alarm->event_id,
- };
-
- memcpy(event.params, &alarm->param, sizeof(alarm->param));
-
- status = fwk_thread_put_event(&event);
- if (status != FWK_SUCCESS)
- log_api->log(MOD_LOG_GROUP_WARNING,
- "[Timer] Warning: Alarm was triggered but event could not "
- "be pushed. Error code: %i\n", status);
+ /* Execute the callback function */
+ alarm->callback(alarm->param);
if (alarm->periodic) {
/* Put this alarm back into the active queue */
@@ -631,7 +617,6 @@ static int timer_process_bind_request(fwk_id_t requester_id,
}
alarm_ctx->bound = true;
- alarm_ctx->listener = requester_id;
*api = &alarm_api;
return FWK_SUCCESS;