1 /*****************************************************************************
3 (c) Cambridge Silicon Radio Limited 2011
4 All rights reserved and confidential information of CSR
6 Refer to LICENSE.txt included with this source for details
9 *****************************************************************************/
11 #ifndef CSR_WIFI_FSM_H
12 #define CSR_WIFI_FSM_H
14 #include "csr_prim_defs.h"
15 #include "csr_log_text.h"
16 #include "csr_wifi_fsm_event.h"
18 /* including this file for CsrWifiInterfaceMode*/
19 #include "csr_wifi_common.h"
21 #define CSR_WIFI_FSM_ENV (0xFFFF)
25 * Toplevel FSM context data
28 * Holds ALL FSM static and dynamic data for a FSM
30 typedef struct CsrWifiFsmContext CsrWifiFsmContext;
34 * FSM External Wakeup CallbackFunction Pointer
37 * Defines the external wakeup function for the FSM
38 * to call when an external event is injected into the systen
40 * @param[in] context : External context
45 typedef void (*CsrWifiFsmExternalWakupCallbackPtr)(void *context);
49 * Initialises a top level FSM context
52 * Initialises the FSM Context to an initial state and allocates
53 * space for "maxProcesses" number of instances
55 * @param[in] osaContext : OSA context
56 * @param[in] applicationContext : Internal fsm application context
57 * @param[in] externalContext : External context
58 * @param[in] maxProcesses : Max processes to allocate room for
61 * CsrWifiFsmContext* fsm context
63 extern CsrWifiFsmContext* CsrWifiFsmInit(void *applicationContext, void *externalContext, u16 maxProcesses, CsrLogTextTaskId loggingTaskId);
67 * Resets the FSM's back to first conditions
70 * This function is used to free any dynamic resources allocated for the
71 * given context by CsrWifiFsmInit().
72 * The FSM's reset function is called to cleanup any fsm specific memory
73 * The reset funtion does NOT need to free the fsm data pointer as
74 * CsrWifiFsmShutdown() will do it.
75 * the FSM's init function is call again to reinitialise the FSM context.
76 * CsrWifiFsmReset() should NEVER be called when CsrWifiFsmExecute() is running.
78 * @param[in] context : FSM context
83 extern void CsrWifiFsmReset(CsrWifiFsmContext *context);
87 * Frees resources allocated by CsrWifiFsmInit
90 * This function is used to free any dynamic resources allocated for the
91 * given context by CsrWifiFsmInit(), prior to complete termination of
93 * The FSM's reset function is called to cleanup any fsm specific memory.
94 * The reset funtion does NOT need to free the fsm data pointer as
95 * CsrWifiFsmShutdown() will do it.
96 * CsrWifiFsmShutdown() should NEVER be called when CsrWifiFsmExecute() is running.
98 * @param[in] context : FSM context
103 extern void CsrWifiFsmShutdown(CsrWifiFsmContext *context);
107 * Executes the fsm context
110 * Executes the FSM context and runs until ALL events in the context are processed.
111 * When no more events are left to process then CsrWifiFsmExecute() returns to a time
112 * specifying when to next call the CsrWifiFsmExecute()
113 * Scheduling, threading, blocking and external event notification are outside
114 * the scope of the FSM and CsrWifiFsmExecute().
116 * @param[in] context : FSM context
119 * u32 Time in ms until next timeout or 0xFFFFFFFF for no timer set
121 extern u32 CsrWifiFsmExecute(CsrWifiFsmContext *context);
125 * Adds an event to the FSM context's external event queue for processing
128 * Adds an event to the contexts external queue
129 * This is thread safe and adds an event to the fsm's external event queue.
131 * @param[in] context : FSM context
132 * @param[in] event : event to add to the event queue
133 * @param[in] source : source of the event (this can be a synergy task queue or an fsm instance id)
134 * @param[in] destination : destination of the event (This can be a fsm instance id or CSR_WIFI_FSM_ENV)
135 * @param[in] id : event id
140 extern void CsrWifiFsmSendEventExternal(CsrWifiFsmContext *context, CsrWifiFsmEvent *event, u16 source, u16 destination, CsrPrim primtype, u16 id);
144 * Adds an Alien event to the FSM context's external event queue for processing
147 * Adds an event to the contexts external queue
148 * This is thread safe and adds an event to the fsm's external event queue.
150 * @param[in] context : FSM context
151 * @param[in] event : event to add to the event queue
152 * @param[in] source : source of the event (this can be a synergy task queue or an fsm instance id)
153 * @param[in] destination : destination of the event (This can be a fsm instance id or CSR_WIFI_FSM_ENV)
154 * @param[in] id : event id
156 #define CsrWifiFsmSendAlienEventExternal(_context, _alienEvent, _source, _destination, _primtype, _id) \
158 CsrWifiFsmAlienEvent *_evt = kmalloc(sizeof(CsrWifiFsmAlienEvent), GFP_KERNEL); \
159 _evt->alienEvent = _alienEvent; \
160 CsrWifiFsmSendEventExternal(_context, (CsrWifiFsmEvent *)_evt, _source, _destination, _primtype, _id); \
166 * Current time of day in ms
168 * @param[in] context : FSM context
173 extern u32 CsrWifiFsmGetTimeOfDayMs(CsrWifiFsmContext *context);
177 * Gets the time until the next FSM timer expiry
180 * Returns the next timeout time or 0 if no timers are set.
182 * @param[in] context : FSM context
185 * u32 Time in ms until next timeout or 0xFFFFFFFF for no timer set
187 extern u32 CsrWifiFsmGetNextTimeout(CsrWifiFsmContext *context);
191 * Fast forwards the fsm timers by ms Milliseconds
193 * @param[in] context : FSM context
194 * @param[in] ms : Milliseconds to fast forward by
199 extern void CsrWifiFsmFastForward(CsrWifiFsmContext *context, u16 ms);
203 * shift the current time of day by ms amount
206 * usefull to speed up tests where time needs to pass
208 * @param[in] context : FSM context
209 * @param[in] ms : ms to adjust time by
214 extern void CsrWifiFsmTestAdvanceTime(CsrWifiFsmContext *context, u32 ms);
218 * Check if the fsm has events to process
220 * @param[in] context : FSM context
223 * u8 returns TRUE if there are events for the FSM to process
225 extern u8 CsrWifiFsmHasEvents(CsrWifiFsmContext *context);
229 * function that installs the contexts wakeup function
231 * @param[in] context : FSM context
232 * @param[in] callback : Callback function pointer
237 extern void CsrWifiFsmInstallWakeupCallback(CsrWifiFsmContext *context, CsrWifiFsmExternalWakupCallbackPtr callback);
239 #endif /* CSR_WIFI_FSM_H */