master/fsm.h
changeset 238 b4960499098f
child 246 0bf7c769de06
equal deleted inserted replaced
237:7b3126cf6dab 238:b4960499098f
       
     1 /******************************************************************************
       
     2  *
       
     3  *  $Id$
       
     4  *
       
     5  *  Copyright (C) 2006  Florian Pose, Ingenieurgemeinschaft IgH
       
     6  *
       
     7  *  This file is part of the IgH EtherCAT Master.
       
     8  *
       
     9  *  The IgH EtherCAT Master is free software; you can redistribute it
       
    10  *  and/or modify it under the terms of the GNU General Public License
       
    11  *  as published by the Free Software Foundation; version 2 of the License.
       
    12  *
       
    13  *  The IgH EtherCAT Master is distributed in the hope that it will be
       
    14  *  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    16  *  GNU General Public License for more details.
       
    17  *
       
    18  *  You should have received a copy of the GNU General Public License
       
    19  *  along with the IgH EtherCAT Master; if not, write to the Free Software
       
    20  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
       
    21  *
       
    22  *****************************************************************************/
       
    23 
       
    24 /**
       
    25    \file
       
    26    EtherCAT finite state machines.
       
    27 */
       
    28 
       
    29 /*****************************************************************************/
       
    30 
       
    31 #ifndef __EC_STATES__
       
    32 #define __EC_STATES__
       
    33 
       
    34 #include "../include/ecrt.h"
       
    35 #include "command.h"
       
    36 #include "slave.h"
       
    37 
       
    38 /*****************************************************************************/
       
    39 
       
    40 typedef struct ec_fsm ec_fsm_t;
       
    41 
       
    42 /*****************************************************************************/
       
    43 
       
    44 /**
       
    45    Finite state machine of an EtherCAT master.
       
    46 */
       
    47 
       
    48 struct ec_fsm
       
    49 {
       
    50     ec_master_t *master; /**< master the FSM runs on */
       
    51     ec_slave_t *slave; /**< slave the FSM runs on */
       
    52     ec_command_t command; /**< command used in the state machine */
       
    53 
       
    54     void (*master_state)(ec_fsm_t *); /**< master state function */
       
    55     unsigned int master_slaves_responding; /**< number of responding slaves */
       
    56     ec_slave_state_t master_slave_states; /**< states of responding slaves */
       
    57 
       
    58     void (*slave_state)(ec_fsm_t *); /**< slave state function */
       
    59     uint8_t slave_sii_num; /**< SII value iteration counter */
       
    60     uint8_t *slave_cat_data; /**< temporary memory for category data */
       
    61     uint16_t slave_cat_offset; /**< current category word offset in EEPROM */
       
    62     uint16_t slave_cat_data_offset; /**< current offset in category data */
       
    63     uint16_t slave_cat_type; /**< type of current category */
       
    64     uint16_t slave_cat_words; /**< number of words of current category */
       
    65 
       
    66     void (*sii_state)(ec_fsm_t *); /**< SII state function */
       
    67     uint16_t sii_offset; /**< input: offset in SII */
       
    68     uint32_t sii_result; /**< output: read SII value (32bit) */
       
    69 };
       
    70 
       
    71 /*****************************************************************************/
       
    72 
       
    73 int ec_fsm_init(ec_fsm_t *, ec_master_t *);
       
    74 void ec_fsm_clear(ec_fsm_t *);
       
    75 void ec_fsm_reset(ec_fsm_t *);
       
    76 void ec_fsm_execute(ec_fsm_t *);
       
    77 int ec_fsm_idle(const ec_fsm_t *);
       
    78 
       
    79 /*****************************************************************************/
       
    80 
       
    81 #endif