Mbed OS Reference
Loading...
Searching...
No Matches
nfc_scheduler.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2014-2018, ARM Limited, All Rights Reserved
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may
6 * not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17/**
18 * \file nfc_scheduler.h
19 * \copyright Copyright (c) ARM Ltd 2014
20 * \author Donatien Garnier
21 */
22/** \addtogroup nfc-scheduler Scheduler
23 * \ingroup nfc
24 * @{
25 * \name Scheduler
26 * @{
27 */
28
29#ifndef NFC_SCHEDULER_H_
30#define NFC_SCHEDULER_H_
31
32#include "stack/nfc_common.h"
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
38#define EVENT_NONE 0
39#define EVENT_TIMEOUT 1
40#define EVENT_ABORTED 2
41#define EVENT_HW_INTERRUPT 4
42
43struct __nfc_timer;
44typedef struct __nfc_timer nfc_scheduler_timer_t;
45
46struct __nfc_task;
47typedef struct __nfc_task nfc_task_t;
48
49typedef struct __scheduler {
50 nfc_task_t *pNext;
51 nfc_scheduler_timer_t *pTimer;
53
54typedef void (*nfc_task_fn)(uint32_t events, void *pUserData);
55
56struct __nfc_task {
57 uint32_t events;
58 int64_t timeout; //millisecs
59 int64_t timeoutInitial;
60
61 nfc_task_fn fn;
62 void *pUserData;
63
64 nfc_task_t *pNext;
65};
66
67void nfc_scheduler_timer_init(nfc_scheduler_timer_t *timer);
68
69void nfc_scheduler_timer_start(nfc_scheduler_timer_t *timer);
70
71uint32_t nfc_scheduler_timer_get(nfc_scheduler_timer_t *timer);
72
73void nfc_scheduler_timer_stop(nfc_scheduler_timer_t *timer);
74
75void nfc_scheduler_timer_reset(nfc_scheduler_timer_t *timer);
76
77/** Init scheduler
78 * \param pScheduler scheduler instance to init
79 * \param pTimer timer instance
80 */
81void nfc_scheduler_init(nfc_scheduler_t *pScheduler, nfc_scheduler_timer_t *pTimer);
82
83/** Iterate through all tasks
84 * \param pScheduler scheduler instance
85 * \param events mask of events (except EVENT_TIMEOUT) that have been raised since this function last returned (0 on first call)
86 * \return time after which this function must be called again if no other event arises
87 */
88uint32_t nfc_scheduler_iteration(nfc_scheduler_t *pScheduler, uint32_t events);
89
90/** Queue a task to execute
91 * \param pScheduler scheduler instance
92 * \param pTask task to queue
93 *
94 */
96
97/** Remove a task to execute
98 * \param pScheduler scheduler instance
99 * \param pTask task to remove
100 * \param abort abort task if queued
101 */
102void nfc_scheduler_dequeue_task(nfc_scheduler_t *pScheduler, bool abort, nfc_task_t *pTask);
103
104/** Initialize task with the following parameters
105 * \param pTask task to initialize
106 * \param events events on which to call task
107 * \param timeout if relevant
108 * \param fn function to be called
109 * \param pUserData data that will be passed to function
110 */
111void task_init(nfc_task_t *pTask, uint32_t events, uint32_t timeout, nfc_task_fn fn, void *pUserData);
112
113#ifdef __cplusplus
114}
115#endif
116
117#endif /* NFC_SCHEDULER_H_ */
118
119/**
120 * @}
121 * @}
122 * */
123
void nfc_scheduler_queue_task(nfc_scheduler_t *pScheduler, nfc_task_t *pTask)
Queue a task to execute.
void nfc_scheduler_dequeue_task(nfc_scheduler_t *pScheduler, bool abort, nfc_task_t *pTask)
Remove a task to execute.
void nfc_scheduler_init(nfc_scheduler_t *pScheduler, nfc_scheduler_timer_t *pTimer)
Init scheduler.
uint32_t nfc_scheduler_iteration(nfc_scheduler_t *pScheduler, uint32_t events)
Iterate through all tasks.
void task_init(nfc_task_t *pTask, uint32_t events, uint32_t timeout, nfc_task_fn fn, void *pUserData)
Initialize task with the following parameters.