master/fsm_foe.c
changeset 2601 9b36a16271e6
parent 2594 9b33888de6c3
child 2602 66a4df6c9ffa
equal deleted inserted replaced
2600:1a969896d52e 2601:9b36a16271e6
    40 #include "fsm_foe.h"
    40 #include "fsm_foe.h"
    41 #include "foe.h"
    41 #include "foe.h"
    42 
    42 
    43 /*****************************************************************************/
    43 /*****************************************************************************/
    44 
    44 
    45 /** Maximum time in ms to wait for responses when reading out the dictionary.
    45 /** Maximum time in jiffies to wait for responses when reading out the
    46  */
    46  * dictionary.
    47 #define EC_FSM_FOE_TIMEOUT 3000
    47  */
       
    48 #define EC_FSM_FOE_TIMEOUT_JIFFIES (3 * HZ)
    48 
    49 
    49 /** Size of the FoE header.
    50 /** Size of the FoE header.
    50  */
    51  */
    51 #define EC_FOE_HEADER_SIZE 6
    52 #define EC_FOE_HEADER_SIZE 6
    52 // uint8_t  OpCode
    53 // uint8_t  OpCode
   363         return;
   364         return;
   364     }
   365     }
   365 
   366 
   366     if (!ec_slave_mbox_check(fsm->datagram)) {
   367     if (!ec_slave_mbox_check(fsm->datagram)) {
   367         // slave did not put anything in the mailbox yet
   368         // slave did not put anything in the mailbox yet
   368         unsigned long diff_ms = (fsm->datagram->jiffies_received -
   369         if (time_after(datagram->jiffies_received,
   369                 fsm->jiffies_start) * 1000 / HZ;
   370                     fsm->jiffies_start + EC_FSM_FOE_TIMEOUT_JIFFIES)) {
   370         if (diff_ms >= EC_FSM_FOE_TIMEOUT) {
       
   371             ec_foe_set_tx_error(fsm, FOE_TIMEOUT_ERROR);
   371             ec_foe_set_tx_error(fsm, FOE_TIMEOUT_ERROR);
   372             EC_SLAVE_ERR(slave, "Timeout while waiting for ack response.\n");
   372             EC_SLAVE_ERR(slave, "Timeout while waiting for ack response.\n");
   373             return;
   373             return;
   374         }
   374         }
   375 
   375 
   702         ec_datagram_print_wc_error(fsm->datagram);
   702         ec_datagram_print_wc_error(fsm->datagram);
   703         return;
   703         return;
   704     }
   704     }
   705 
   705 
   706     if (!ec_slave_mbox_check(fsm->datagram)) {
   706     if (!ec_slave_mbox_check(fsm->datagram)) {
   707         unsigned long diff_ms = (fsm->datagram->jiffies_received -
   707         if (time_after(datagram->jiffies_received,
   708                 fsm->jiffies_start) * 1000 / HZ;
   708                     fsm->jiffies_start + EC_FSM_FOE_TIMEOUT_JIFFIES)) {
   709         if (diff_ms >= EC_FSM_FOE_TIMEOUT) {
       
   710             ec_foe_set_tx_error(fsm, FOE_TIMEOUT_ERROR);
   709             ec_foe_set_tx_error(fsm, FOE_TIMEOUT_ERROR);
   711             EC_SLAVE_ERR(slave, "Timeout while waiting for ack response.\n");
   710             EC_SLAVE_ERR(slave, "Timeout while waiting for ack response.\n");
   712             return;
   711             return;
   713         }
   712         }
   714 
   713