3 /*****************************************************************************
5 (c) Cambridge Silicon Radio Limited 2010
6 All rights reserved and confidential information of CSR
8 Refer to LICENSE.txt included with this source for details
11 *****************************************************************************/
12 #include <linux/types.h>
19 /* An identifier issued by the scheduler. */
20 typedef u32 CsrSchedIdentifier;
22 /* A task identifier */
23 typedef u16 CsrSchedTaskId;
25 /* A queue identifier */
26 typedef u16 CsrSchedQid;
27 #define CSR_SCHED_QID_INVALID ((CsrSchedQid) 0xFFFF)
29 /* A message identifier */
30 typedef CsrSchedIdentifier CsrSchedMsgId;
32 /* A timer event identifier */
33 typedef CsrSchedIdentifier CsrSchedTid;
34 #define CSR_SCHED_TID_INVALID ((CsrSchedTid) 0)
36 /* Scheduler entry functions share this structure */
37 typedef void (*schedEntryFunction_t)(void **inst);
40 #define CSR_SCHED_TIME_MAX ((CsrTime) 0xFFFFFFFF)
41 #define CSR_SCHED_MILLISECOND ((CsrTime) (1000))
42 #define CSR_SCHED_SECOND ((CsrTime) (1000 * CSR_SCHED_MILLISECOND))
43 #define CSR_SCHED_MINUTE ((CsrTime) (60 * CSR_SCHED_SECOND))
45 /* Queue and primitive that identifies the environment */
46 #define CSR_SCHED_TASK_ID 0xFFFF
47 #define CSR_SCHED_PRIM (CSR_SCHED_TASK_ID)
48 #define CSR_SCHED_EXCLUDED_MODULE_QUEUE 0xFFFF
51 * Background interrupt definitions
53 typedef u16 CsrSchedBgint;
54 #define CSR_SCHED_BGINT_INVALID ((CsrSchedBgint) 0xFFFF)
56 typedef void (*CsrSchedBgintHandler)(void *);
58 /*----------------------------------------------------------------------------*
63 * Register a background interrupt handler function with the scheduler.
64 * When CsrSchedBgint() is called from the foreground (e.g. an interrupt
65 * routine) the registered function is called.
67 * If "cb" is null then the interrupt is effectively disabled. If a
68 * no bgints are available, CSR_SCHED_BGINT_INVALID is returned, otherwise
69 * a CsrSchedBgint value is returned to be used in subsequent calls to
70 * CsrSchedBgint(). id is a possibly NULL identifier used for logging
74 * CsrSchedBgint -- CSR_SCHED_BGINT_INVALID denotes failure to obtain a CsrSchedBgintSet.
76 *----------------------------------------------------------------------------*/
77 CsrSchedBgint CsrSchedBgintReg(CsrSchedBgintHandler cb,
81 /*----------------------------------------------------------------------------*
86 * Unregister a background interrupt handler function.
88 * ``irq'' is a background interrupt handle previously obtained
89 * from a call to CsrSchedBgintReg().
94 *----------------------------------------------------------------------------*/
95 void CsrSchedBgintUnreg(CsrSchedBgint bgint);
97 /*----------------------------------------------------------------------------*
102 * Set background interrupt.
107 *----------------------------------------------------------------------------*/
108 void CsrSchedBgintSet(CsrSchedBgint bgint);
110 /*----------------------------------------------------------------------------*
115 * Sends a message consisting of the integer "mi" and the void * pointer
116 * "mv" to the message queue "q".
118 * "mi" and "mv" are neither inspected nor changed by the scheduler - the
119 * task that owns "q" is expected to make sense of the values. "mv" may
123 * If "mv" is not null then it will typically be a chunk of kmalloc()ed
124 * memory, though there is no need for it to be so. Tasks should normally
125 * obey the convention that when a message built with kmalloc()ed memory
126 * is given to CsrSchedMessagePut() then ownership of the memory is ceded to the
127 * scheduler - and eventually to the recipient task. I.e., the receiver of
128 * the message will be expected to kfree() the message storage.
133 *----------------------------------------------------------------------------*/
134 #if defined(CSR_LOG_ENABLE) && defined(CSR_LOG_INCLUDE_FILE_NAME_AND_LINE_NUMBER)
135 void CsrSchedMessagePutStringLog(CsrSchedQid q,
140 #define CsrSchedMessagePut(q, mi, mv) CsrSchedMessagePutStringLog((q), (mi), (mv), __LINE__, __FILE__)
142 void CsrSchedMessagePut(CsrSchedQid q,
147 /*----------------------------------------------------------------------------*
149 * CsrSchedMessageBroadcast
152 * Sends a message to all tasks.
154 * The user must supply a "factory function" that is called once
155 * for every task that exists. The "factory function", msg_build_func,
156 * must allocate and initialise the message and set the msg_build_ptr
157 * to point to the message when done.
165 *----------------------------------------------------------------------------*/
166 #if defined(CSR_LOG_ENABLE) && defined(CSR_LOG_INCLUDE_FILE_NAME_AND_LINE_NUMBER)
167 void CsrSchedMessageBroadcastStringLog(u16 mi,
168 void *(*msg_build_func)(void *),
172 #define CsrSchedMessageBroadcast(mi, fn, ptr) CsrSchedMessageBroadcastStringLog((mi), (fn), (ptr), __LINE__, __FILE__)
174 void CsrSchedMessageBroadcast(u16 mi,
175 void *(*msg_build_func)(void *),
176 void *msg_build_ptr);
179 /*----------------------------------------------------------------------------*
184 * Obtains a message from the message queue belonging to the calling task.
185 * The message consists of one or both of a u16 and a void *.
188 * u8 - TRUE if a message has been obtained from the queue, else FALSE.
189 * If a message is taken from the queue, then "*pmi" and "*pmv" are set to
190 * the "mi" and "mv" passed to CsrSchedMessagePut() respectively.
192 * "pmi" and "pmv" can be null, in which case the corresponding value from
193 * them message is discarded.
195 *----------------------------------------------------------------------------*/
196 u8 CsrSchedMessageGet(u16 *pmi, void **pmv);
198 /*----------------------------------------------------------------------------*
203 * Causes the void function "fn" to be called with the arguments
204 * "fniarg" and "fnvarg" after "delay" has elapsed.
206 * "delay" must be less than half the range of a CsrTime.
208 * CsrSchedTimerSet() does nothing with "fniarg" and "fnvarg" except
209 * deliver them via a call to "fn()". (Unless CsrSchedTimerCancel()
210 * is used to prevent delivery.)
213 * The function will be called at or after "delay"; the actual delay will
214 * depend on the timing behaviour of the scheduler's tasks.
217 * CsrSchedTid - A timed event identifier, can be used in CsrSchedTimerCancel().
219 *----------------------------------------------------------------------------*/
220 #if defined(CSR_LOG_ENABLE) && defined(CSR_LOG_INCLUDE_FILE_NAME_AND_LINE_NUMBER)
221 CsrSchedTid CsrSchedTimerSetStringLog(CsrTime delay,
222 void (*fn)(u16 mi, void *mv),
227 #define CsrSchedTimerSet(d, fn, fni, fnv) CsrSchedTimerSetStringLog((d), (fn), (fni), (fnv), __LINE__, __FILE__)
229 CsrSchedTid CsrSchedTimerSet(CsrTime delay,
230 void (*fn)(u16 mi, void *mv),
235 /*----------------------------------------------------------------------------*
237 * CsrSchedTimerCancel
240 * Attempts to prevent the timed event with identifier "eventid" from
244 * u8 - TRUE if cancelled, FALSE if the event has already occurred.
246 *----------------------------------------------------------------------------*/
247 #if defined(CSR_LOG_ENABLE) && defined(CSR_LOG_INCLUDE_FILE_NAME_AND_LINE_NUMBER)
248 u8 CsrSchedTimerCancelStringLog(CsrSchedTid eventid,
253 #define CsrSchedTimerCancel(e, pmi, pmv) CsrSchedTimerCancelStringLog((e), (pmi), (pmv), __LINE__, __FILE__)
255 u8 CsrSchedTimerCancel(CsrSchedTid eventid,
260 /*----------------------------------------------------------------------------*
262 * CsrSchedTaskQueueGet
265 * Return the queue identifier for the currently running queue
268 * CsrSchedQid - The current task queue identifier, or 0xFFFF if not available.
270 *----------------------------------------------------------------------------*/
271 CsrSchedQid CsrSchedTaskQueueGet(void);
274 /*----------------------------------------------------------------------------*
276 * CsrSchedTaskQueueGet
279 * Return the queue identifier for the currently running queue
282 * char - The current task queue identifier, or 0xFFFF if not available.
284 *----------------------------------------------------------------------------*/
285 char* CsrSchedTaskNameGet(CsrSchedQid );