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_TYPES_H
12 #define CSR_WIFI_FSM_TYPES_H
14 #include <linux/types.h>
15 #include "csr_macro.h"
16 #include "csr_sched.h"
18 #ifdef CSR_WIFI_FSM_MUTEX_ENABLE
19 #include "csr_framework_ext.h"
22 #include "csr_wifi_fsm.h"
24 #define CSR_WIFI_FSM_MAX_TRANSITION_HISTORY 10
28 * FSM event list header.
31 * Singly linked list of events.
33 typedef struct CsrWifiFsmEventList
35 CsrWifiFsmEvent *first;
36 CsrWifiFsmEvent *last;
37 } CsrWifiFsmEventList;
45 * Composite Id made up of the type, dest and a unique id so
46 * CsrWifiFsmRemoveTimer knows where to look when removing the timer
48 typedef struct CsrWifiFsmTimerId
52 CsrSchedQid destination;
61 * All timer MUST have this struct as the FIRST member.
62 * The first members of the structure MUST remain compatable
63 * with the CsrWifiFsmEvent so that timers are just specialised events
65 typedef struct CsrWifiFsmTimer
69 CsrSchedQid destination;
72 /* Private pointer to allow an optimal Event list */
73 struct CsrWifiFsmTimer *next;
75 CsrWifiFsmTimerId timerid;
85 * Allows the wrapping of alien events that do not use CsrWifiFsmEvent
86 * as the first member of the Event struct
90 CsrWifiFsmEvent event;
92 } CsrWifiFsmAlienEvent;
97 * FSM timer list header.
100 * Singly linked list of timers.
102 typedef struct CsrWifiFsmTimerList
104 CsrWifiFsmTimer *first;
105 CsrWifiFsmTimer *last;
107 } CsrWifiFsmTimerList;
111 * Process Entry Function Pointer
114 * Defines the entry function for a processes.
115 * Called at process initialisation.
117 * @param[in] context : FSM context
122 typedef void (*CsrWifiFsmProcEntryFnPtr)(CsrWifiFsmContext *context);
126 * Process Transition Function Pointer
129 * Defines a transition function for a processes.
130 * Called when an event causes a transition on a process
132 * @param[in] CsrWifiFsmContext* : FSM context
133 * @param[in] void* : FSM data (can be NULL)
134 * @param[in] const CsrWifiFsmEvent* : event to process
139 typedef void (*CsrWifiFsmTransitionFnPtr)(CsrWifiFsmContext *context, void *fsmData, const CsrWifiFsmEvent *event);
143 * Process reset/shutdown Function Pointer
146 * Defines the reset/shutdown function for a processes.
147 * Called to reset or shutdown an fsm.
149 * @param[in] context : FSM context
154 typedef void (*CsrWifiFsmProcResetFnPtr)(CsrWifiFsmContext *context);
158 * FSM Default Destination CallbackFunction Pointer
161 * Defines the default destination function for the FSM
162 * to call when an event does not have a valid destination.
165 * @param[in] context : External context
168 * u16 a valid destination OR CSR_WIFI_FSM_ENV
170 typedef u16 (*CsrWifiFsmDestLookupCallbackPtr)(void *context, const CsrWifiFsmEvent *event);
173 #ifdef CSR_WIFI_FSM_DUMP_ENABLE
176 * Trace Dump Function Pointer
179 * Called when we want to trace the FSM
181 * @param[in] context : FSM context
182 * @param[in] id : fsm id
187 typedef void (*CsrWifiFsmDumpFnPtr)(CsrWifiFsmContext *context, void *fsmData);
192 * Event ID to transition function entry
195 * Event ID to Transition Entry in a state table.
200 CsrWifiFsmTransitionFnPtr transition;
201 #ifdef CSR_LOG_ENABLE
202 const char *transitionName;
204 } CsrWifiFsmEventEntry;
208 * Single State's Transition Table
211 * Stores Data for a single State's event to
212 * transition functions mapping
218 const CsrWifiFsmEventEntry *eventEntryArray; /* array of transition function pointers for state */
219 #ifdef CSR_LOG_ENABLE
221 const char *stateName;
223 } CsrWifiFsmTableEntry;
227 * Process State Transtion table
230 * Stores Data for a processes State to transition table
234 u16 numStates; /* number of states */
235 const CsrWifiFsmTableEntry *aStateEventMatrix; /* state event matrix */
236 } CsrWifiFsmTransitionFunctionTable;
240 * Const Process definition
243 * Constant process specification.
244 * This is ALL the non dynamic data that defines
249 const char *processName;
251 const CsrWifiFsmTransitionFunctionTable transitionTable;
252 const CsrWifiFsmTableEntry unhandledTransitions;
253 const CsrWifiFsmTableEntry ignoreFunctions;
254 const CsrWifiFsmProcEntryFnPtr entryFn;
255 const CsrWifiFsmProcResetFnPtr resetFn;
256 #ifdef CSR_WIFI_FSM_DUMP_ENABLE
257 const CsrWifiFsmDumpFnPtr dumpFn; /* Called to dump fsm specific trace if not NULL */
259 } CsrWifiFsmProcessStateMachine;
261 #ifdef CSR_WIFI_FSM_DUMP_ENABLE
264 * Storage for state transition info
268 u16 transitionNumber;
269 CsrWifiFsmEvent event;
272 CsrWifiFsmTransitionFnPtr transitionFn;
273 u16 transitionCount; /* number consecutive of times this transition was seen */
274 #ifdef CSR_LOG_ENABLE
275 const char *transitionName;
277 } CsrWifiFsmTransitionRecord;
281 * Storage for the last state X transitions
286 CsrWifiFsmTransitionRecord records[CSR_WIFI_FSM_MAX_TRANSITION_HISTORY];
287 } CsrWifiFsmTransitionRecords;
292 * Dynamic Process data
295 * Dynamic process data that is used to keep track of the
296 * state and data for a process instance
300 const CsrWifiFsmProcessStateMachine *fsmInfo; /* state machine info that is constant regardless of context */
301 u16 instanceId; /* Runtime process id */
302 u16 state; /* Current state */
303 void *params; /* Instance user data */
304 CsrWifiFsmEventList savedEventQueue; /* The saved event queue */
305 struct CsrWifiFsmInstanceEntry *subFsm; /* Sub Fsm instance data */
306 struct CsrWifiFsmInstanceEntry *subFsmCaller; /* The Fsm instance that created the SubFsm and should be used for callbacks*/
307 #ifdef CSR_WIFI_FSM_DUMP_ENABLE
308 CsrWifiFsmTransitionRecords transitionRecords; /* Last X transitions in the FSM */
310 } CsrWifiFsmInstanceEntry;
314 * OnCreate Callback Function Pointer
317 * Called when an fsm is created.
319 * @param[in] extContext : External context
320 * @param[in] instance : FSM instance
325 typedef void (*CsrWifiFsmOnCreateFnPtr)(void *extContext, const CsrWifiFsmInstanceEntry *instance);
329 * OnTransition Callback Function Pointer
332 * Called when an event is processed by a fsm
334 * @param[in] extContext : External context
335 * @param[in] eventEntryArray : Entry data
336 * @param[in] event : Event
341 typedef void (*CsrWifiFsmOnTransitionFnPtr)(void *extContext, const CsrWifiFsmEventEntry *eventEntryArray, const CsrWifiFsmEvent *event);
345 * OnStateChange Callback Function Pointer
348 * Called when CsrWifiFsmNextState is called
350 * @param[in] extContext : External context
355 typedef void (*CsrWifiFsmOnStateChangeFnPtr)(void *extContext, u16 nextstate);
359 * OnIgnore,OnError or OnInvalid Callback Function Pointer
362 * Called when an event is processed by a fsm
364 * @param[in] extContext : External context
365 * @param[in] event : Event
370 typedef void (*CsrWifiFsmOnEventFnPtr)(void *extContext, const CsrWifiFsmEvent *event);
374 * Toplevel FSM context data
377 * Holds ALL FSM static and dynamic data for a FSM
379 struct CsrWifiFsmContext
381 CsrWifiFsmEventList eventQueue; /* The internal event queue */
382 CsrWifiFsmEventList externalEventQueue; /* The external event queue */
383 #ifdef CSR_WIFI_FSM_MUTEX_ENABLE
384 CsrMutexHandle externalEventQueueLock; /* The external event queue mutex */
386 u32 timeOffset; /* Amount to adjust the TimeOfDayMs by */
387 CsrWifiFsmTimerList timerQueue; /* The internal timer queue */
388 u8 useTempSaveList; /* Should the temp save list be used */
389 CsrWifiFsmEventList tempSaveList; /* The temp save event queue */
390 CsrWifiFsmEvent *eventForwardedOrSaved; /* The event that was forwarded or Saved */
391 u16 maxProcesses; /* Size of instanceArray */
392 u16 numProcesses; /* Current number allocated in instanceArray */
393 CsrWifiFsmInstanceEntry *instanceArray; /* Array of processes for this component */
394 CsrWifiFsmInstanceEntry *ownerInstance; /* The Process that owns currentInstance (SubFsm support) */
395 CsrWifiFsmInstanceEntry *currentInstance; /* Current Process that is executing */
396 CsrWifiFsmExternalWakupCallbackPtr externalEventFn; /* External event Callback */
397 CsrWifiFsmOnEventFnPtr appIgnoreCallback; /* Application Ignore event Callback */
398 CsrWifiFsmDestLookupCallbackPtr appEvtDstCallback; /* Application Lookup event Destination Function*/
400 void *applicationContext; /* Internal fsm application context */
401 void *externalContext; /* External context (set by the user of the fsm)*/
402 CsrLogTextTaskId loggingTaskId; /* Task Id to use in any logging output */
404 #ifndef CSR_WIFI_FSM_SCHEDULER_DISABLED
405 CsrSchedTid schedTimerId; /* Scheduler TimerId for use in Scheduler Tasks */
406 u32 schedTimerNexttimeoutMs; /* Next timeout time for the current timer */
409 #ifdef CSR_WIFI_FSM_MUTEX_ENABLE
410 #ifdef CSR_WIFI_FSM_TRANSITION_LOCK
411 CsrMutexHandle transitionLock; /* Lock when calling transition functions */
415 #ifdef CSR_LOG_ENABLE
416 CsrWifiFsmOnCreateFnPtr onCreate; /* Debug Transition Callback */
417 CsrWifiFsmOnTransitionFnPtr onTransition; /* Debug Transition Callback */
418 CsrWifiFsmOnTransitionFnPtr onUnhandedCallback; /* Unhanded event Callback */
419 CsrWifiFsmOnStateChangeFnPtr onStateChange; /* Debug State Change Callback */
420 CsrWifiFsmOnEventFnPtr onIgnoreCallback; /* Ignore event Callback */
421 CsrWifiFsmOnEventFnPtr onSaveCallback; /* Save event Callback */
422 CsrWifiFsmOnEventFnPtr onErrorCallback; /* Error event Callback */
423 CsrWifiFsmOnEventFnPtr onInvalidCallback; /* Invalid event Callback */
425 #ifdef CSR_WIFI_FSM_DUMP_ENABLE
426 u16 masterTransitionNumber; /* Increments on every transition */
430 #endif /* CSR_WIFI_FSM_TYPES_H */