1 /* 2 * fsm.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 fsm.h 35 * \brief finite state machine header file 36 * 37 * \see fsm.c 38 */ 39 40 41 /***************************************************************************/ 42 /* */ 43 /* MODULE: fsm.h */ 44 /* PURPOSE: Finite State Machine API */ 45 /* */ 46 /***************************************************************************/ 47 48 #ifndef __FSM_H__ 49 #define __FSM_H__ 50 51 #include "tidef.h" 52 #include "commonTypes.h" 53 54 /* Constants */ 55 #define MAX_DESC_STRING_LEN 64 56 57 58 /* Enumerations */ 59 60 /* Typedefs */ 61 62 /** state transition function */ 63 typedef TI_STATUS (*fsm_eventActivation_t)(TI_UINT8 *currState, TI_UINT8 event, void* data); 64 65 /** action function type definition */ 66 typedef TI_STATUS (*fsm_Action_t)(void* pData); 67 68 /* Structures */ 69 70 /* State\Event cell */ 71 typedef struct 72 { 73 TI_UINT8 nextState; /**< next state in transition */ 74 fsm_Action_t actionFunc; /**< action function */ 75 } fsm_actionCell_t; 76 77 /** matrix type */ 78 typedef fsm_actionCell_t* fsm_Matrix_t; 79 80 /** general FSM structure */ 81 typedef struct 82 { 83 fsm_Matrix_t stateEventMatrix; /**< State\Event matrix */ 84 TI_UINT8 MaxNoOfStates; /**< Max Number of states in the matrix */ 85 TI_UINT8 MaxNoOfEvents; /**< Max Number of events in the matrix */ 86 TI_UINT8 ActiveNoOfStates; /**< Active Number of states in the matrix */ 87 TI_UINT8 ActiveNoOfEvents; /**< Active Number of events in the matrix */ 88 fsm_eventActivation_t transitionFunc; /**< State transition function */ 89 } fsm_stateMachine_t; 90 91 /* External data definitions */ 92 93 /* External functions definitions */ 94 95 /* Function prototypes */ 96 97 TI_STATUS fsm_Create(TI_HANDLE hOs, 98 fsm_stateMachine_t **pFsm, 99 TI_UINT8 MaxNoOfStates, 100 TI_UINT8 MaxNoOfEvents); 101 102 TI_STATUS fsm_Unload(TI_HANDLE hOs, 103 fsm_stateMachine_t *pFsm); 104 105 TI_STATUS fsm_Config(fsm_stateMachine_t *pFsm, 106 fsm_Matrix_t pMatrix, 107 TI_UINT8 ActiveNoOfStates, 108 TI_UINT8 ActiveNoOfEvents, 109 fsm_eventActivation_t transFunc, 110 TI_HANDLE hOs); 111 112 TI_STATUS fsm_Event(fsm_stateMachine_t *pFsm, 113 TI_UINT8 *currentState, 114 TI_UINT8 event, 115 void *pData); 116 117 TI_STATUS fsm_GetNextState(fsm_stateMachine_t *pFsm, 118 TI_UINT8 currentState, 119 TI_UINT8 event, 120 TI_UINT8 *nextState); 121 122 123 TI_STATUS action_nop(void *pData); 124 125 126 #endif /* __FSM_H__ */ 127