[etherlab-dev] [PATCH] FoE support for read BUSY (ETG.1020 Section 15)
Dave Page
dave.page at gleeble.com
Wed Jan 22 03:49:24 CET 2014
Hi,
My slave needs to indicate busy when reading files over FoE (as it
goes out to a slow serial EEPROM).
A small change was required to make the BUSY OpCode transition to
the correct state in fsm_foe.c,
and have the subsequent FoE Ack.req show the correct PacketNo IAW
ETG.1020 Section 15
"FoE Extension."
The attached patch includes the FoE PacketNo length fix from Gavin
Lambert
This patch is tested working with my slave (based on a patched
Beckhoff SSC).
Best regards - Dave Page
-------------- next part --------------
diff --git a/master/fsm_foe.c b/master/fsm_foe.c
--- a/master/fsm_foe.c
+++ b/master/fsm_foe.c
@@ -730,17 +730,18 @@ void ec_fsm_foe_state_data_check(
/** Start reading data.
*/
void ec_fsm_foe_state_data_read(
ec_fsm_foe_t *fsm, /**< FoE statemachine. */
ec_datagram_t *datagram /**< Datagram to use. */
)
{
size_t rec_size;
- uint8_t *data, opCode, packet_no, mbox_prot;
+ uint32_t packet_no;
+ uint8_t *data, opCode, mbox_prot;
ec_slave_t *slave = fsm->slave;
#ifdef DEBUG_FOE
EC_SLAVE_DBG(fsm->slave, 0, "%s()\n", __func__);
#endif
if (fsm->datagram->state != EC_DATAGRAM_RECEIVED) {
@@ -768,19 +769,24 @@ void ec_fsm_foe_state_data_read(
mbox_prot);
ec_foe_set_rx_error(fsm, FOE_PROT_ERROR);
return;
}
opCode = EC_READ_U8(data);
if (opCode == EC_FOE_OPCODE_BUSY) {
+ fsm->rx_expected_packet_no--;
if (ec_foe_prepare_send_ack(fsm, datagram)) {
ec_foe_set_rx_error(fsm, FOE_PROT_ERROR);
}
+ fsm->state = ec_fsm_foe_state_sent_ack;
+#ifdef DEBUG_FOE
+ EC_SLAVE_DBG(fsm->slave, 0, "%s() busy. Next pkt %u\n", __func__, fsm->rx_expected_packet_no);
+#endif
return;
}
if (opCode == EC_FOE_OPCODE_ERR) {
fsm->request->error_code = EC_READ_U32(data + 2);
EC_SLAVE_ERR(slave, "Received FoE Error Request (code 0x%08x).\n",
fsm->request->error_code);
if (rec_size > 6) {
@@ -795,19 +801,20 @@ void ec_fsm_foe_state_data_read(
if (opCode != EC_FOE_OPCODE_DATA) {
EC_SLAVE_ERR(slave, "Received OPCODE %x, expected %x.\n",
opCode, EC_FOE_OPCODE_DATA);
fsm->request->error_code = 0x00000000;
ec_foe_set_rx_error(fsm, FOE_OPCODE_ERROR);
return;
}
- packet_no = EC_READ_U16(data + 2);
+ packet_no = EC_READ_U32(data + 2);
if (packet_no != fsm->rx_expected_packet_no) {
- EC_SLAVE_ERR(slave, "Received unexpected packet number.\n");
+ EC_SLAVE_ERR(slave, "Received packet number %u, expected %u.\n",
+ packet_no, fsm->rx_expected_packet_no);
ec_foe_set_rx_error(fsm, FOE_PACKETNO_ERROR);
return;
}
rec_size -= EC_FOE_HEADER_SIZE;
if (fsm->rx_buffer_size >= fsm->rx_buffer_offset + rec_size) {
memcpy(fsm->rx_buffer + fsm->rx_buffer_offset,
@@ -883,17 +890,17 @@ void ec_fsm_foe_state_sent_ack(
ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
if (fsm->rx_last_packet) {
fsm->rx_expected_packet_no = 0;
fsm->request->data_size = fsm->rx_buffer_offset;
fsm->state = ec_fsm_foe_end;
}
else {
- fsm->rx_expected_packet_no++;
+ fsm->rx_expected_packet_no++; // this should not be incremented when BUSY
fsm->retries = EC_FSM_RETRIES;
fsm->state = ec_fsm_foe_state_data_check;
}
}
/*****************************************************************************/
/** Set an error code and go to the send error state.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dave_page.vcf
Type: text/x-vcard
Size: 314 bytes
Desc: not available
URL: <http://lists.etherlab.org/pipermail/etherlab-dev/attachments/20140122/11733cd8/attachment-0003.vcf>
More information about the Etherlab-dev
mailing list