Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers nfc_scheduler.h Source File

nfc_scheduler.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2014-2018, ARM Limited, All Rights Reserved
00003  * SPDX-License-Identifier: Apache-2.0
00004  *
00005  * Licensed under the Apache License, Version 2.0 (the "License"); you may
00006  * not use this file except in compliance with the License.
00007  * You may obtain a copy of the License at
00008  *
00009  * http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00013  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 /**
00018  * \file nfc_scheduler.h
00019  * \copyright Copyright (c) ARM Ltd 2014
00020  * \author Donatien Garnier
00021  */
00022 /** \addtogroup Core
00023  *  @{
00024  *  \name Scheduler
00025  *  @{
00026  */
00027 
00028 #ifndef NFC_SCHEDULER_H_
00029 #define NFC_SCHEDULER_H_
00030 
00031 #include "stack/nfc_common.h"
00032 
00033 #ifdef __cplusplus
00034 extern "C" {
00035 #endif
00036 
00037 #define EVENT_NONE         0
00038 #define EVENT_TIMEOUT      1
00039 #define EVENT_ABORTED      2
00040 #define EVENT_HW_INTERRUPT 4
00041 
00042 struct __nfc_timer;
00043 typedef struct __nfc_timer nfc_scheduler_timer_t;
00044 
00045 struct __nfc_task;
00046 typedef struct __nfc_task nfc_task_t;
00047 
00048 typedef struct __scheduler {
00049     nfc_task_t *pNext;
00050     nfc_scheduler_timer_t *pTimer;
00051 } nfc_scheduler_t;
00052 
00053 typedef void (*nfc_task_fn)(uint32_t events, void *pUserData);
00054 
00055 struct __nfc_task {
00056     uint32_t events;
00057     int64_t timeout; //millisecs
00058     int64_t timeoutInitial;
00059 
00060     nfc_task_fn fn;
00061     void *pUserData;
00062 
00063     nfc_task_t *pNext;
00064 };
00065 
00066 void nfc_scheduler_timer_init(nfc_scheduler_timer_t *timer);
00067 
00068 void nfc_scheduler_timer_start(nfc_scheduler_timer_t *timer);
00069 
00070 uint32_t nfc_scheduler_timer_get(nfc_scheduler_timer_t *timer);
00071 
00072 void nfc_scheduler_timer_stop(nfc_scheduler_timer_t *timer);
00073 
00074 void nfc_scheduler_timer_reset(nfc_scheduler_timer_t *timer);
00075 
00076 /** Init scheduler
00077  * \param pScheduler scheduler instance to init
00078  * \param pTimer timer instance
00079  */
00080 void nfc_scheduler_init(nfc_scheduler_t *pScheduler, nfc_scheduler_timer_t *pTimer);
00081 
00082 /** Iterate through all tasks
00083  * \param pScheduler scheduler instance
00084  * \param events mask of events (except EVENT_TIMEOUT) that have been raised since this function last returned (0 on first call)
00085  * \return time after which this function must be called again if no other event arises
00086  */
00087 uint32_t nfc_scheduler_iteration(nfc_scheduler_t *pScheduler, uint32_t events);
00088 
00089 /** Queue a task to execute
00090  * \param pScheduler scheduler instance
00091  * \param pTask task to queue
00092  *
00093  */
00094 void nfc_scheduler_queue_task(nfc_scheduler_t *pScheduler, nfc_task_t *pTask);
00095 
00096 /** Remove a task to execute
00097  * \param pScheduler scheduler instance
00098  * \param pTask task to remove
00099  * \param abort abort task if queued
00100  */
00101 void nfc_scheduler_dequeue_task(nfc_scheduler_t *pScheduler, bool abort, nfc_task_t *pTask);
00102 
00103 /** Initialize task with the following parameters
00104  * \param pTask task to initialize
00105  * \param events events on which to call task
00106  * \param timeout if relevant
00107  * \param fn function to be called
00108  * \param pUserData data that will be passed to function
00109  */
00110 void task_init(nfc_task_t *pTask, uint32_t events, uint32_t timeout, nfc_task_fn fn, void *pUserData);
00111 
00112 #ifdef __cplusplus
00113 }
00114 #endif
00115 
00116 #endif /* NFC_SCHEDULER_H_ */
00117 
00118 /**
00119  * @}
00120  * @}
00121  * */
00122