1 /** \file fsm.h 2 * \brief finite state machine header file 3 * 4 * \see fsm.c 5 */ 6 7 /**************************************************************************** 8 **+-----------------------------------------------------------------------+** 9 **| |** 10 **| Copyright(c) 1998 - 2008 Texas Instruments. All rights reserved. |** 11 **| All rights reserved. |** 12 **| |** 13 **| Redistribution and use in source and binary forms, with or without |** 14 **| modification, are permitted provided that the following conditions |** 15 **| are met: |** 16 **| |** 17 **| * Redistributions of source code must retain the above copyright |** 18 **| notice, this list of conditions and the following disclaimer. |** 19 **| * Redistributions in binary form must reproduce the above copyright |** 20 **| notice, this list of conditions and the following disclaimer in |** 21 **| the documentation and/or other materials provided with the |** 22 **| distribution. |** 23 **| * Neither the name Texas Instruments nor the names of its |** 24 **| contributors may be used to endorse or promote products derived |** 25 **| from this software without specific prior written permission. |** 26 **| |** 27 **| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |** 28 **| "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |** 29 **| LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |** 30 **| A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |** 31 **| OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |** 32 **| SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |** 33 **| LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |** 34 **| DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |** 35 **| THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |** 36 **| (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |** 37 **| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |** 38 **| |** 39 **+-----------------------------------------------------------------------+** 40 ****************************************************************************/ 41 42 /***************************************************************************/ 43 /* */ 44 /* MODULE: fsm.h */ 45 /* PURPOSE: Finite State Machine API */ 46 /* */ 47 /***************************************************************************/ 48 49 #ifndef __FSM_H__ 50 #define __FSM_H__ 51 52 #include "osTIType.h" 53 #include "commonTypes.h" 54 55 /* Constants */ 56 #define MAX_DESC_STRING_LEN 64 57 58 59 /* Enumerations */ 60 61 /* Typedefs */ 62 63 /** state transition function */ 64 typedef TI_STATUS (*fsm_eventActivation_t)(UINT8 *currState, UINT8 event, void* data); 65 66 /** action function type definition */ 67 typedef TI_STATUS (*fsm_Action_t)(void* pData); 68 69 /* Structures */ 70 71 /* State\Event cell */ 72 typedef struct 73 { 74 UINT8 nextState; /**< next state in transition */ 75 fsm_Action_t actionFunc; /**< action function */ 76 } fsm_actionCell_t; 77 78 /** matrix type */ 79 typedef fsm_actionCell_t* fsm_Matrix_t; 80 81 /** general FSM structure */ 82 typedef struct 83 { 84 fsm_Matrix_t stateEventMatrix; /**< State\Event matrix */ 85 UINT8 MaxNoOfStates; /**< Max Number of states in the matrix */ 86 UINT8 MaxNoOfEvents; /**< Max Number of events in the matrix */ 87 UINT8 ActiveNoOfStates; /**< Active Number of states in the matrix */ 88 UINT8 ActiveNoOfEvents; /**< Active Number of events in the matrix */ 89 fsm_eventActivation_t transitionFunc; /**< State transition function */ 90 } fsm_stateMachine_t; 91 92 /* External data definitions */ 93 94 /* External functions definitions */ 95 96 /* Function prototypes */ 97 98 TI_STATUS fsm_Create(TI_HANDLE hOs, 99 fsm_stateMachine_t **pFsm, 100 UINT8 MaxNoOfStates, 101 UINT8 MaxNoOfEvents); 102 103 TI_STATUS fsm_Unload(TI_HANDLE hOs, 104 fsm_stateMachine_t *pFsm); 105 106 TI_STATUS fsm_Config(fsm_stateMachine_t *pFsm, 107 fsm_Matrix_t pMatrix, 108 UINT8 ActiveNoOfStates, 109 UINT8 ActiveNoOfEvents, 110 fsm_eventActivation_t transFunc, 111 TI_HANDLE hOs); 112 113 TI_STATUS fsm_Event(fsm_stateMachine_t *pFsm, 114 UINT8 *currentState, 115 UINT8 event, 116 void *pData); 117 118 TI_STATUS fsm_GetNextState(fsm_stateMachine_t *pFsm, 119 UINT8 currentState, 120 UINT8 event, 121 UINT8 *nextState); 122 123 124 TI_STATUS action_nop(void *pData); 125 126 127 #endif /* __FSM_H__ */ 128