1 /* 2 * GenSM.h 3 * 4 * Copyright(c) 1998 - 2009 Texas Instruments. All rights reserved. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 11 * * Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * * Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in 15 * the documentation and/or other materials provided with the 16 * distribution. 17 * * Neither the name Texas Instruments nor the names of its 18 * contributors may be used to endorse or promote products derived 19 * from this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33 34 /** \file GenSM.h 35 * \brief Generic state machine declarations 36 * 37 * \see GenSM.c 38 */ 39 40 41 #ifndef __GENSM_H__ 42 #define __GENSM_H__ 43 44 #include "tidef.h" 45 46 /* action function type definition */ 47 typedef void (*TGenSM_action) (void *pData); 48 49 50 /* State/Event cell */ 51 typedef struct 52 { 53 TI_UINT32 uNextState; /**< next state in transition */ 54 TGenSM_action fAction; /**< action function */ 55 } TGenSM_actionCell; 56 57 58 59 /* 60 * matrix type 61 * Although the state-machine matrix is actually a two-dimensional array, it is treated as a single 62 * dimension array, since the size of each dimeansion is only known in run-time 63 */ 64 typedef TGenSM_actionCell *TGenSM_matrix; 65 66 67 /* generic state machine object structure */ 68 typedef struct 69 { 70 TI_HANDLE hOS; /**< OS handle */ 71 TI_HANDLE hReport; /**< report handle */ 72 TGenSM_matrix tMatrix; /**< next state/action matrix */ 73 TI_UINT32 uStateNum; /**< Number of states in the matrix */ 74 TI_UINT32 uEventNum; /**< Number of events in the matrix */ 75 TI_UINT32 uCurrentState; /**< Current state */ 76 TI_UINT32 uEvent; /**< Last event sent */ 77 void *pData; /**< Last event data */ 78 TI_BOOL bEventPending; /**< Event pending indicator */ 79 TI_BOOL bInAction; /**< Evenet execution indicator */ 80 TI_UINT32 uModuleLogIndex; /**< Module index to use for printouts */ 81 TI_INT8 *pGenSMName; /**< state machine name */ 82 TI_INT8 **pStateDesc; /**< State description strings */ 83 TI_INT8 **pEventDesc; /**< Event description strings */ 84 } TGenSM; 85 86 TI_HANDLE genSM_Create (TI_HANDLE hOS); 87 void genSM_Unload (TI_HANDLE hGenSM); 88 void genSM_Init (TI_HANDLE hGenSM, TI_HANDLE hReport); 89 void genSM_SetDefaults (TI_HANDLE hGenSM, TI_UINT32 uStateNum, TI_UINT32 uEventNum, 90 TGenSM_matrix pMatrix, TI_UINT32 uInitialState, TI_INT8 *pGenSMName, 91 TI_INT8 **pStateDesc, TI_INT8 **pEventDesc, TI_UINT32 uModuleLogIndex); 92 void genSM_Event (TI_HANDLE hGenSM, TI_UINT32 uEvent, void *pData); 93 TI_UINT32 genSM_GetCurrentState (TI_HANDLE hGenSM); 94 95 #endif /* __GENSM_H__ */ 96 97