Cascoda SDK
Cascoda SDK for building software to run with CA-821x transceivers
cascoda_tasklet.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019, Cascoda Ltd.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * 3. Neither the name of the copyright holder nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
40 #ifndef CASCODA_TASKLET_H
41 #define CASCODA_TASKLET_H
42 
43 #include <stdbool.h>
44 #include <stdint.h>
45 
46 #include "ca821x_error.h"
47 
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51 
58 typedef ca_error (*ca_tasklet_callback)(void *context);
59 
65 typedef struct ca_tasklet
66 {
68  void *context;
69  struct ca_tasklet *next;
70  uint32_t fireTime;
71  uint8_t scheduled : 1;
73 
83 
94 ca_error TASKLET_ScheduleDelta(ca_tasklet *aTasklet, uint32_t aTimeDelta, void *aContext);
95 
107 ca_error TASKLET_ScheduleAbs(ca_tasklet *aTasklet, uint32_t aTimeNow, uint32_t aTimeAbs, void *aContext);
108 
117 ca_error TASKLET_GetScheduledTime(ca_tasklet *aTasklet, uint32_t *aTimeAbs);
118 
127 ca_error TASKLET_GetScheduledTimeDelta(ca_tasklet *aTasklet, uint32_t *aTimeDelta);
128 
137 
147 bool TASKLET_IsQueued(ca_tasklet *aTasklet);
148 
156 ca_error TASKLET_GetTimeToNext(uint32_t *aTimeDelta);
157 
164 
165 #ifdef __cplusplus
166 }
167 #endif
168 
169 #endif //CASCODA_TASKLET_H
170 
Global error declarations for use across the Cascoda SDK.
ca_error TASKLET_Init(ca_tasklet *aTasklet, ca_tasklet_callback aCallback)
Initialise a tasklet to a stable state, and register its associated callback function.
Definition: cascoda_tasklet.c:59
struct ca_tasklet ca_tasklet
Internal tasklet state structure.
ca_error(* ca_tasklet_callback)(void *context)
Function pointer typedef for tasklet callbacks.
Definition: cascoda_tasklet.h:58
ca_error TASKLET_GetScheduledTime(ca_tasklet *aTasklet, uint32_t *aTimeAbs)
Get the time that the tasklet is scheduled to be called.
Definition: cascoda_tasklet.c:110
bool TASKLET_IsQueued(ca_tasklet *aTasklet)
Query whether a tasklet is currently scheduled.
Definition: cascoda_tasklet.c:157
ca_error TASKLET_Process(void)
Process the callbacks for any tasklets that are scheduled to happen now or in the past.
Definition: cascoda_tasklet.c:175
ca_error TASKLET_GetScheduledTimeDelta(ca_tasklet *aTasklet, uint32_t *aTimeDelta)
Get the time delta until a tasklet is scheduled to be called.
Definition: cascoda_tasklet.c:119
ca_error TASKLET_Cancel(ca_tasklet *aTasklet)
Cancel a scheduled tasklet if it is scheduled.
Definition: cascoda_tasklet.c:128
ca_error TASKLET_GetTimeToNext(uint32_t *aTimeDelta)
Get the time delta until the next tasklet is scheduled to occur.
Definition: cascoda_tasklet.c:162
ca_error TASKLET_ScheduleAbs(ca_tasklet *aTasklet, uint32_t aTimeNow, uint32_t aTimeAbs, void *aContext)
Schedule a tasklet to be called in the future, at aTimeAbs milliseconds.
Definition: cascoda_tasklet.c:76
ca_error TASKLET_ScheduleDelta(ca_tasklet *aTasklet, uint32_t aTimeDelta, void *aContext)
Schedule a tasklet to be called in the future, by aTimeDelta milliseconds.
Definition: cascoda_tasklet.c:70
ca_error
Cascoda error type.
Definition: ca821x_error.h:51
Internal tasklet state structure.
Definition: cascoda_tasklet.h:66
uint8_t scheduled
Internal: Is this tasklet scheduled?
Definition: cascoda_tasklet.h:71
uint32_t fireTime
Internal: The next time at which the tasklet is due to trigger.
Definition: cascoda_tasklet.h:70
void * context
Internal: The context that will be passed to the callback when it is called.
Definition: cascoda_tasklet.h:68
struct ca_tasklet * next
Internal: The next tasklet in the sorted tasklet linkedlist.
Definition: cascoda_tasklet.h:69
ca_tasklet_callback callback
Internal: The callback that will be called when the tasklet is triggered.
Definition: cascoda_tasklet.h:67