master/fsm_sii.c
changeset 754 0b47b49c5976
parent 753 7ba5f9cd8f7e
child 755 178353fc47e5
equal deleted inserted replaced
753:7ba5f9cd8f7e 754:0b47b49c5976
   103 */
   103 */
   104 
   104 
   105 void ec_fsm_sii_write(ec_fsm_sii_t *fsm, /**< finite state machine */
   105 void ec_fsm_sii_write(ec_fsm_sii_t *fsm, /**< finite state machine */
   106                       ec_slave_t *slave, /**< slave to read from */
   106                       ec_slave_t *slave, /**< slave to read from */
   107                       uint16_t offset, /**< offset to read from */
   107                       uint16_t offset, /**< offset to read from */
   108                       const uint16_t *value, /**< pointer to 2 bytes of data */
   108                       const uint8_t *value, /**< pointer to 2 bytes of data */
   109                       ec_fsm_sii_addressing_t mode /**< addressing scheme */
   109                       ec_fsm_sii_addressing_t mode /**< addressing scheme */
   110                       )
   110                       )
   111 {
   111 {
   112     fsm->state = ec_fsm_sii_state_start_writing;
   112     fsm->state = ec_fsm_sii_state_start_writing;
   113     fsm->slave = slave;
   113     fsm->slave = slave;
   125 
   125 
   126 int ec_fsm_sii_exec(ec_fsm_sii_t *fsm /**< finite state machine */)
   126 int ec_fsm_sii_exec(ec_fsm_sii_t *fsm /**< finite state machine */)
   127 {
   127 {
   128     fsm->state(fsm);
   128     fsm->state(fsm);
   129 
   129 
   130     return fsm->state != ec_fsm_sii_state_end && fsm->state != ec_fsm_sii_state_error;
   130     return fsm->state != ec_fsm_sii_state_end
       
   131 		&& fsm->state != ec_fsm_sii_state_error;
   131 }
   132 }
   132 
   133 
   133 /*****************************************************************************/
   134 /*****************************************************************************/
   134 
   135 
   135 /**
   136 /**
   141 {
   142 {
   142     return fsm->state == ec_fsm_sii_state_end;
   143     return fsm->state == ec_fsm_sii_state_end;
   143 }
   144 }
   144 
   145 
   145 /******************************************************************************
   146 /******************************************************************************
   146  *  SII state machine
   147  * state functions
   147  *****************************************************************************/
   148  *****************************************************************************/
   148 
   149 
   149 /**
   150 /**
   150    SII state: START READING.
   151    SII state: START READING.
   151    Starts reading the slave information interface.
   152    Starts reading the slave information interface.
   152 */
   153 */
   153 
   154 
   154 void ec_fsm_sii_state_start_reading(ec_fsm_sii_t *fsm /**< finite state machine */)
   155 void ec_fsm_sii_state_start_reading(
       
   156 		ec_fsm_sii_t *fsm /**< finite state machine */
       
   157 		)
   155 {
   158 {
   156     ec_datagram_t *datagram = fsm->datagram;
   159     ec_datagram_t *datagram = fsm->datagram;
   157 
   160 
   158     // initiate read operation
   161     // initiate read operation
   159     switch (fsm->mode) {
   162     switch (fsm->mode) {
   177 /**
   180 /**
   178    SII state: READ CHECK.
   181    SII state: READ CHECK.
   179    Checks, if the SII-read-datagram has been sent and issues a fetch datagram.
   182    Checks, if the SII-read-datagram has been sent and issues a fetch datagram.
   180 */
   183 */
   181 
   184 
   182 void ec_fsm_sii_state_read_check(ec_fsm_sii_t *fsm /**< finite state machine */)
   185 void ec_fsm_sii_state_read_check(
       
   186 		ec_fsm_sii_t *fsm /**< finite state machine */
       
   187 		)
   183 {
   188 {
   184     ec_datagram_t *datagram = fsm->datagram;
   189     ec_datagram_t *datagram = fsm->datagram;
   185 
   190 
   186     if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
   191     if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
   187         return;
   192         return;
   224 /**
   229 /**
   225    SII state: READ FETCH.
   230    SII state: READ FETCH.
   226    Fetches the result of an SII-read datagram.
   231    Fetches the result of an SII-read datagram.
   227 */
   232 */
   228 
   233 
   229 void ec_fsm_sii_state_read_fetch(ec_fsm_sii_t *fsm /**< finite state machine */)
   234 void ec_fsm_sii_state_read_fetch(
       
   235 		ec_fsm_sii_t *fsm /**< finite state machine */
       
   236 		)
   230 {
   237 {
   231     ec_datagram_t *datagram = fsm->datagram;
   238     ec_datagram_t *datagram = fsm->datagram;
   232 
   239 
   233     if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
   240     if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
   234         return;
   241         return;
   300 /**
   307 /**
   301    SII state: START WRITING.
   308    SII state: START WRITING.
   302    Starts reading the slave information interface.
   309    Starts reading the slave information interface.
   303 */
   310 */
   304 
   311 
   305 void ec_fsm_sii_state_start_writing(ec_fsm_sii_t *fsm /**< finite state machine */)
   312 void ec_fsm_sii_state_start_writing(
       
   313 		ec_fsm_sii_t *fsm /**< finite state machine */
       
   314 		)
   306 {
   315 {
   307     ec_datagram_t *datagram = fsm->datagram;
   316     ec_datagram_t *datagram = fsm->datagram;
   308 
   317 
   309     // initiate write operation
   318     // initiate write operation
   310     ec_datagram_npwr(datagram, fsm->slave->station_address, 0x502, 8);
   319     ec_datagram_npwr(datagram, fsm->slave->station_address, 0x502, 8);
   321 
   330 
   322 /**
   331 /**
   323    SII state: WRITE CHECK.
   332    SII state: WRITE CHECK.
   324 */
   333 */
   325 
   334 
   326 void ec_fsm_sii_state_write_check(ec_fsm_sii_t *fsm /**< finite state machine */)
   335 void ec_fsm_sii_state_write_check(
       
   336 		ec_fsm_sii_t *fsm /**< finite state machine */
       
   337 		)
   327 {
   338 {
   328     ec_datagram_t *datagram = fsm->datagram;
   339     ec_datagram_t *datagram = fsm->datagram;
   329 
   340 
   330     if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
   341     if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
   331         return;
   342         return;
   359 
   370 
   360 /**
   371 /**
   361    SII state: WRITE CHECK 2.
   372    SII state: WRITE CHECK 2.
   362 */
   373 */
   363 
   374 
   364 void ec_fsm_sii_state_write_check2(ec_fsm_sii_t *fsm /**< finite state machine */)
   375 void ec_fsm_sii_state_write_check2(
       
   376 		ec_fsm_sii_t *fsm /**< finite state machine */
       
   377 		)
   365 {
   378 {
   366     ec_datagram_t *datagram = fsm->datagram;
   379     ec_datagram_t *datagram = fsm->datagram;
   367 
   380 
   368     if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
   381     if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
   369         return;
   382         return;
   415 
   428 
   416 /**
   429 /**
   417    State: ERROR.
   430    State: ERROR.
   418 */
   431 */
   419 
   432 
   420 void ec_fsm_sii_state_error(ec_fsm_sii_t *fsm /**< finite state machine */)
   433 void ec_fsm_sii_state_error(
       
   434 		ec_fsm_sii_t *fsm /**< finite state machine */
       
   435 		)
   421 {
   436 {
   422 }
   437 }
   423 
   438 
   424 /*****************************************************************************/
   439 /*****************************************************************************/
   425 
   440 
   426 /**
   441 /**
   427    State: END.
   442    State: END.
   428 */
   443 */
   429 
   444 
   430 void ec_fsm_sii_state_end(ec_fsm_sii_t *fsm /**< finite state machine */)
   445 void ec_fsm_sii_state_end(
   431 {
   446 		ec_fsm_sii_t *fsm /**< finite state machine */
   432 }
   447 		)
   433 
   448 {
   434 /*****************************************************************************/
   449 }
       
   450 
       
   451 /*****************************************************************************/