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
18 #include "csr_prim_defs.h"
19 #include "csr_log_text.h"
20 #include "csr_wifi_fsm_event.h"
22 /* including this file for CsrWifiInterfaceMode*/
23 #include "csr_wifi_common.h"
25 #define CSR_WIFI_FSM_ENV (0xFFFF)
29 * Toplevel FSM context data
32 * Holds ALL FSM static and dynamic data for a FSM
34 typedef struct CsrWifiFsmContext CsrWifiFsmContext;
38 * FSM External Wakeup CallbackFunction Pointer
41 * Defines the external wakeup function for the FSM
42 * to call when an external event is injected into the systen
44 * @param[in] context : External context
49 typedef void (*CsrWifiFsmExternalWakupCallbackPtr)(void *context);
53 * Initialises a top level FSM context
56 * Initialises the FSM Context to an initial state and allocates
57 * space for "maxProcesses" number of instances
59 * @param[in] osaContext : OSA context
60 * @param[in] applicationContext : Internal fsm application context
61 * @param[in] externalContext : External context
62 * @param[in] maxProcesses : Max processes to allocate room for
65 * CsrWifiFsmContext* fsm context
67 extern CsrWifiFsmContext* CsrWifiFsmInit(void *applicationContext, void *externalContext, u16 maxProcesses, CsrLogTextTaskId loggingTaskId);
71 * Resets the FSM's back to first conditions
74 * This function is used to free any dynamic resources allocated for the
75 * given context by CsrWifiFsmInit().
76 * The FSM's reset function is called to cleanup any fsm specific memory
77 * The reset funtion does NOT need to free the fsm data pointer as
78 * CsrWifiFsmShutdown() will do it.
79 * the FSM's init function is call again to reinitialise the FSM context.
80 * CsrWifiFsmReset() should NEVER be called when CsrWifiFsmExecute() is running.
82 * @param[in] context : FSM context
87 extern void CsrWifiFsmReset(CsrWifiFsmContext *context);
91 * Frees resources allocated by CsrWifiFsmInit
94 * This function is used to free any dynamic resources allocated for the
95 * given context by CsrWifiFsmInit(), prior to complete termination of
97 * The FSM's reset function is called to cleanup any fsm specific memory.
98 * The reset funtion does NOT need to free the fsm data pointer as
99 * CsrWifiFsmShutdown() will do it.
100 * CsrWifiFsmShutdown() should NEVER be called when CsrWifiFsmExecute() is running.
102 * @param[in] context : FSM context
107 extern void CsrWifiFsmShutdown(CsrWifiFsmContext *context);
111 * Executes the fsm context
114 * Executes the FSM context and runs until ALL events in the context are processed.
115 * When no more events are left to process then CsrWifiFsmExecute() returns to a time
116 * specifying when to next call the CsrWifiFsmExecute()
117 * Scheduling, threading, blocking and external event notification are outside
118 * the scope of the FSM and CsrWifiFsmExecute().
120 * @param[in] context : FSM context
123 * u32 Time in ms until next timeout or 0xFFFFFFFF for no timer set
125 extern u32 CsrWifiFsmExecute(CsrWifiFsmContext *context);
129 * Adds an event to the FSM context's external event queue for processing
132 * Adds an event to the contexts external queue
133 * This is thread safe and adds an event to the fsm's external event queue.
135 * @param[in] context : FSM context
136 * @param[in] event : event to add to the event queue
137 * @param[in] source : source of the event (this can be a synergy task queue or an fsm instance id)
138 * @param[in] destination : destination of the event (This can be a fsm instance id or CSR_WIFI_FSM_ENV)
139 * @param[in] id : event id
144 extern void CsrWifiFsmSendEventExternal(CsrWifiFsmContext *context, CsrWifiFsmEvent *event, u16 source, u16 destination, CsrPrim primtype, u16 id);
148 * Adds an Alien event to the FSM context's external event queue for processing
151 * Adds an event to the contexts external queue
152 * This is thread safe and adds an event to the fsm's external event queue.
154 * @param[in] context : FSM context
155 * @param[in] event : event to add to the event queue
156 * @param[in] source : source of the event (this can be a synergy task queue or an fsm instance id)
157 * @param[in] destination : destination of the event (This can be a fsm instance id or CSR_WIFI_FSM_ENV)
158 * @param[in] id : event id
160 #define CsrWifiFsmSendAlienEventExternal(_context, _alienEvent, _source, _destination, _primtype, _id) \
162 CsrWifiFsmAlienEvent *_evt = kmalloc(sizeof(CsrWifiFsmAlienEvent), GFP_KERNEL); \
163 _evt->alienEvent = _alienEvent; \
164 CsrWifiFsmSendEventExternal(_context, (CsrWifiFsmEvent *)_evt, _source, _destination, _primtype, _id); \
170 * Current time of day in ms
172 * @param[in] context : FSM context
177 extern u32 CsrWifiFsmGetTimeOfDayMs(CsrWifiFsmContext *context);
181 * Gets the time until the next FSM timer expiry
184 * Returns the next timeout time or 0 if no timers are set.
186 * @param[in] context : FSM context
189 * u32 Time in ms until next timeout or 0xFFFFFFFF for no timer set
191 extern u32 CsrWifiFsmGetNextTimeout(CsrWifiFsmContext *context);
195 * Fast forwards the fsm timers by ms Milliseconds
197 * @param[in] context : FSM context
198 * @param[in] ms : Milliseconds to fast forward by
203 extern void CsrWifiFsmFastForward(CsrWifiFsmContext *context, u16 ms);
207 * shift the current time of day by ms amount
210 * usefull to speed up tests where time needs to pass
212 * @param[in] context : FSM context
213 * @param[in] ms : ms to adjust time by
218 extern void CsrWifiFsmTestAdvanceTime(CsrWifiFsmContext *context, u32 ms);
222 * Check if the fsm has events to process
224 * @param[in] context : FSM context
227 * u8 returns TRUE if there are events for the FSM to process
229 extern u8 CsrWifiFsmHasEvents(CsrWifiFsmContext *context);
233 * function that installs the contexts wakeup function
235 * @param[in] context : FSM context
236 * @param[in] callback : Callback function pointer
241 extern void CsrWifiFsmInstallWakeupCallback(CsrWifiFsmContext *context, CsrWifiFsmExternalWakupCallbackPtr callback);
247 #endif /* CSR_WIFI_FSM_H */