Warten beim Empfangen der Prozessdaten, Bugfix und kleinere Verbesserungen.
This commit is contained in:
parent
da79bcaff6
commit
16a7734a19
|
|
@ -112,7 +112,7 @@ void EtherCAT_command_write(EtherCAT_command_t *cmd,
|
||||||
const unsigned char *data)
|
const unsigned char *data)
|
||||||
{
|
{
|
||||||
if (node_address == 0x0000)
|
if (node_address == 0x0000)
|
||||||
EC_DBG(KERN_WARNING "WARNING: Using node address 0x0000!\n");
|
EC_DBG(KERN_WARNING "EtherCAT: Using node address 0x0000!\n");
|
||||||
|
|
||||||
ECAT_FUNC_HEADER;
|
ECAT_FUNC_HEADER;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -253,28 +253,30 @@ int EtherCAT_device_send(EtherCAT_device_t *ecd,
|
||||||
|
|
||||||
@param ecd EtherCAT-Gerät
|
@param ecd EtherCAT-Gerät
|
||||||
@param data Zeiger auf den Speicherbereich, in den die
|
@param data Zeiger auf den Speicherbereich, in den die
|
||||||
empfangenen Daten kopiert werden sollen
|
empfangenen Daten kopiert werden sollen
|
||||||
@param size Größe des angegebenen Speicherbereichs
|
|
||||||
|
|
||||||
@return Anzahl der kopierten Bytes bei Erfolg, sonst < 0
|
@return Anzahl der kopierten Bytes bei Erfolg, sonst < 0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int EtherCAT_device_receive(EtherCAT_device_t *ecd,
|
int EtherCAT_device_receive(EtherCAT_device_t *ecd,
|
||||||
unsigned char *data,
|
unsigned char *data)
|
||||||
unsigned int size)
|
|
||||||
{
|
{
|
||||||
int cnt;
|
|
||||||
|
|
||||||
if (ecd->state != ECAT_DS_RECEIVED)
|
if (ecd->state != ECAT_DS_RECEIVED)
|
||||||
{
|
{
|
||||||
EC_DBG(KERN_ERR "EtherCAT: receive - Nothing received!\n");
|
EC_DBG(KERN_ERR "EtherCAT: receive - Nothing received!\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
cnt = min(ecd->rx_data_length, size);
|
if (ecd->rx_data_length > ECAT_FRAME_BUFFER_SIZE)
|
||||||
memcpy(data,ecd->rx_data, cnt);
|
{
|
||||||
|
EC_DBG(KERN_ERR "EtherCAT: receive - Reveived frame too long (%i Bytes)!\n",
|
||||||
|
ecd->rx_data_length);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return cnt;
|
memcpy(data, ecd->rx_data, ecd->rx_data_length);
|
||||||
|
|
||||||
|
return ecd->rx_data_length;
|
||||||
}
|
}
|
||||||
|
|
||||||
/***************************************************************/
|
/***************************************************************/
|
||||||
|
|
|
||||||
|
|
@ -77,7 +77,7 @@ int EtherCAT_device_open(EtherCAT_device_t *);
|
||||||
int EtherCAT_device_close(EtherCAT_device_t *);
|
int EtherCAT_device_close(EtherCAT_device_t *);
|
||||||
|
|
||||||
int EtherCAT_device_send(EtherCAT_device_t *, unsigned char *, unsigned int);
|
int EtherCAT_device_send(EtherCAT_device_t *, unsigned char *, unsigned int);
|
||||||
int EtherCAT_device_receive(EtherCAT_device_t *, unsigned char *, unsigned int);
|
int EtherCAT_device_receive(EtherCAT_device_t *, unsigned char *);
|
||||||
void EtherCAT_device_call_isr(EtherCAT_device_t *);
|
void EtherCAT_device_call_isr(EtherCAT_device_t *);
|
||||||
|
|
||||||
void EtherCAT_device_debug(EtherCAT_device_t *);
|
void EtherCAT_device_debug(EtherCAT_device_t *);
|
||||||
|
|
|
||||||
|
|
@ -15,17 +15,7 @@
|
||||||
/**
|
/**
|
||||||
Maximale Größe eines EtherCAT-Frames
|
Maximale Größe eines EtherCAT-Frames
|
||||||
*/
|
*/
|
||||||
#define ECAT_FRAME_BUFFER_SIZE 1600
|
#define ECAT_FRAME_BUFFER_SIZE 1500
|
||||||
|
|
||||||
/**
|
|
||||||
Anzahl der Kommandos in einem Master-Kommandoring
|
|
||||||
*/
|
|
||||||
#define ECAT_COMMAND_RING_SIZE 10
|
|
||||||
|
|
||||||
/**
|
|
||||||
Anzahl der Versuche beim Asynchronen Senden/Empfangen
|
|
||||||
*/
|
|
||||||
#define ECAT_NUM_RETRIES 10
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
NULL-Define, falls noch nicht definiert.
|
NULL-Define, falls noch nicht definiert.
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@
|
||||||
|
|
||||||
@param master Zeiger auf den zu initialisierenden
|
@param master Zeiger auf den zu initialisierenden
|
||||||
EtherCAT-Master
|
EtherCAT-Master
|
||||||
@param dev Zeiger auf das EtherCAT-gerät, mit dem der
|
@param dev Zeiger auf das EtherCAT-Gerät, mit dem der
|
||||||
Master arbeiten soll
|
Master arbeiten soll
|
||||||
|
|
||||||
@return 0 bei Erfolg, sonst < 0 (= dev ist NULL)
|
@return 0 bei Erfolg, sonst < 0 (= dev ist NULL)
|
||||||
|
|
@ -96,10 +96,12 @@ int EtherCAT_simple_send_receive(EtherCAT_master_t *master,
|
||||||
|
|
||||||
if (EtherCAT_simple_send(master, cmd) < 0) return -1;
|
if (EtherCAT_simple_send(master, cmd) < 0) return -1;
|
||||||
|
|
||||||
tries_left = 100;
|
EtherCAT_device_call_isr(master->dev);
|
||||||
while (cmd->state == ECAT_CS_SENT && tries_left)
|
|
||||||
|
tries_left = 1000;
|
||||||
|
while (master->dev->state == ECAT_DS_SENT && tries_left)
|
||||||
{
|
{
|
||||||
udelay(10);
|
udelay(1);
|
||||||
EtherCAT_device_call_isr(master->dev);
|
EtherCAT_device_call_isr(master->dev);
|
||||||
tries_left--;
|
tries_left--;
|
||||||
}
|
}
|
||||||
|
|
@ -137,6 +139,13 @@ int EtherCAT_simple_send(EtherCAT_master_t *master,
|
||||||
|
|
||||||
length = cmd->data_length + 12;
|
length = cmd->data_length + 12;
|
||||||
framelength = length + 2;
|
framelength = length + 2;
|
||||||
|
|
||||||
|
if (framelength > ECAT_FRAME_BUFFER_SIZE)
|
||||||
|
{
|
||||||
|
EC_DBG(KERN_ERR "EtherCAT: Frame too long (%i)!\n", framelength);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (framelength < 46) framelength = 46;
|
if (framelength < 46) framelength = 46;
|
||||||
|
|
||||||
if (master->debug_level > 0)
|
if (master->debug_level > 0)
|
||||||
|
|
@ -223,32 +232,32 @@ int EtherCAT_simple_send(EtherCAT_master_t *master,
|
||||||
int EtherCAT_simple_receive(EtherCAT_master_t *master,
|
int EtherCAT_simple_receive(EtherCAT_master_t *master,
|
||||||
EtherCAT_command_t *cmd)
|
EtherCAT_command_t *cmd)
|
||||||
{
|
{
|
||||||
unsigned int rx_data_length, length;
|
unsigned int length;
|
||||||
|
int receive_ret;
|
||||||
unsigned char command_type, command_index;
|
unsigned char command_type, command_index;
|
||||||
|
|
||||||
rx_data_length = EtherCAT_device_receive(master->dev, master->rx_data,
|
if ((receive_ret = EtherCAT_device_receive(master->dev,
|
||||||
ECAT_FRAME_BUFFER_SIZE);
|
master->rx_data)) < 0)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (rx_data_length < 2)
|
master->rx_data_length = (unsigned int) receive_ret;
|
||||||
|
|
||||||
|
if (master->rx_data_length < 2)
|
||||||
{
|
{
|
||||||
EC_DBG(KERN_ERR "EtherCAT: Received frame with incomplete EtherCAT header!\n");
|
EC_DBG(KERN_ERR "EtherCAT: Received frame with incomplete EtherCAT header!\n");
|
||||||
EC_DBG(KERN_DEBUG "EtherCAT: tx_data content:\n");
|
output_debug_data(master);
|
||||||
output_debug_data(master->tx_data, master->tx_data_length);
|
|
||||||
EC_DBG(KERN_DEBUG "EtherCAT: rx_data content:\n");
|
|
||||||
output_debug_data(master->rx_data, rx_data_length);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Länge des gesamten Frames prüfen
|
// Länge des gesamten Frames prüfen
|
||||||
length = ((master->rx_data[1] & 0x07) << 8) | (master->rx_data[0] & 0xFF);
|
length = ((master->rx_data[1] & 0x07) << 8) | (master->rx_data[0] & 0xFF);
|
||||||
|
|
||||||
if (length > rx_data_length)
|
if (length > master->rx_data_length)
|
||||||
{
|
{
|
||||||
EC_DBG(KERN_ERR "EtherCAT: Received corrupted frame (length does not match)!\n");
|
EC_DBG(KERN_ERR "EtherCAT: Received corrupted frame (length does not match)!\n");
|
||||||
EC_DBG(KERN_DEBUG "EtherCAT: tx_data content:\n");
|
output_debug_data(master);
|
||||||
output_debug_data(master->tx_data, master->tx_data_length);
|
|
||||||
EC_DBG(KERN_DEBUG "EtherCAT: rx_data content:\n");
|
|
||||||
output_debug_data(master->rx_data, rx_data_length);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -256,13 +265,10 @@ int EtherCAT_simple_receive(EtherCAT_master_t *master,
|
||||||
command_index = master->rx_data[2 + 1];
|
command_index = master->rx_data[2 + 1];
|
||||||
length = (master->rx_data[2 + 6] & 0xFF) | ((master->rx_data[2 + 7] & 0x07) << 8);
|
length = (master->rx_data[2 + 6] & 0xFF) | ((master->rx_data[2 + 7] & 0x07) << 8);
|
||||||
|
|
||||||
if (rx_data_length - 2 < length + 12)
|
if (master->rx_data_length - 2 < length + 12)
|
||||||
{
|
{
|
||||||
EC_DBG(KERN_ERR "EtherCAT: Received frame with incomplete command data!\n");
|
EC_DBG(KERN_ERR "EtherCAT: Received frame with incomplete command data!\n");
|
||||||
EC_DBG(KERN_DEBUG "EtherCAT: tx_data content:\n");
|
output_debug_data(master);
|
||||||
output_debug_data(master->tx_data, master->tx_data_length);
|
|
||||||
EC_DBG(KERN_DEBUG "EtherCAT: rx_data content:\n");
|
|
||||||
output_debug_data(master->rx_data, rx_data_length);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -283,10 +289,7 @@ int EtherCAT_simple_receive(EtherCAT_master_t *master,
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
EC_DBG(KERN_WARNING "EtherCAT: WARNING - Send/Receive anomaly!\n");
|
EC_DBG(KERN_WARNING "EtherCAT: WARNING - Send/Receive anomaly!\n");
|
||||||
EC_DBG(KERN_DEBUG "EtherCAT: tx_data content:\n");
|
output_debug_data(master);
|
||||||
output_debug_data(master->tx_data, master->tx_data_length);
|
|
||||||
EC_DBG(KERN_DEBUG "EtherCAT: rx_data content:\n");
|
|
||||||
output_debug_data(master->rx_data, rx_data_length);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
master->dev->state = ECAT_DS_READY;
|
master->dev->state = ECAT_DS_READY;
|
||||||
|
|
@ -991,8 +994,24 @@ int EtherCAT_write_process_data(EtherCAT_master_t *master)
|
||||||
|
|
||||||
int EtherCAT_read_process_data(EtherCAT_master_t *master)
|
int EtherCAT_read_process_data(EtherCAT_master_t *master)
|
||||||
{
|
{
|
||||||
|
unsigned int tries_left;
|
||||||
|
|
||||||
EtherCAT_device_call_isr(master->dev);
|
EtherCAT_device_call_isr(master->dev);
|
||||||
|
|
||||||
|
tries_left = 1000;
|
||||||
|
while (master->dev->state == ECAT_DS_SENT && tries_left)
|
||||||
|
{
|
||||||
|
udelay(1);
|
||||||
|
EtherCAT_device_call_isr(master->dev);
|
||||||
|
tries_left--;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!tries_left)
|
||||||
|
{
|
||||||
|
EC_DBG(KERN_ERR "EtherCAT: Timeout while receiving process data!\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (EtherCAT_simple_receive(master, &master->process_data_command) < 0)
|
if (EtherCAT_simple_receive(master, &master->process_data_command) < 0)
|
||||||
{
|
{
|
||||||
EC_DBG(KERN_ERR "EtherCAT: Could not receive cyclic command!\n");
|
EC_DBG(KERN_ERR "EtherCAT: Could not receive cyclic command!\n");
|
||||||
|
|
@ -1028,41 +1047,6 @@ void EtherCAT_clear_process_data(EtherCAT_master_t *master)
|
||||||
|
|
||||||
/***************************************************************/
|
/***************************************************************/
|
||||||
|
|
||||||
/**
|
|
||||||
Setzt einen Byte-Wert im Speicher.
|
|
||||||
|
|
||||||
@param data Startadresse
|
|
||||||
@param offset Byte-Offset
|
|
||||||
@param value Wert
|
|
||||||
*/
|
|
||||||
|
|
||||||
void set_byte(unsigned char *data,
|
|
||||||
unsigned int offset,
|
|
||||||
unsigned char value)
|
|
||||||
{
|
|
||||||
data[offset] = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/***************************************************************/
|
|
||||||
|
|
||||||
/**
|
|
||||||
Setzt einen Word-Wert im Speicher.
|
|
||||||
|
|
||||||
@param data Startadresse
|
|
||||||
@param offset Byte-Offset
|
|
||||||
@param value Wert
|
|
||||||
*/
|
|
||||||
|
|
||||||
void set_word(unsigned char *data,
|
|
||||||
unsigned int offset,
|
|
||||||
unsigned int value)
|
|
||||||
{
|
|
||||||
data[offset] = value & 0xFF;
|
|
||||||
data[offset + 1] = (value & 0xFF00) >> 8;
|
|
||||||
}
|
|
||||||
|
|
||||||
/***************************************************************/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Gibt Frame-Inhalte zwecks Debugging aus.
|
Gibt Frame-Inhalte zwecks Debugging aus.
|
||||||
|
|
||||||
|
|
@ -1070,14 +1054,28 @@ void set_word(unsigned char *data,
|
||||||
@param length Länge der Daten
|
@param length Länge der Daten
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void output_debug_data(unsigned char *data, unsigned int length)
|
void output_debug_data(const EtherCAT_master_t *master)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
|
EC_DBG(KERN_DEBUG "EtherCAT: tx_data content (%i Bytes):\n",
|
||||||
|
master->tx_data_length);
|
||||||
|
|
||||||
EC_DBG(KERN_DEBUG);
|
EC_DBG(KERN_DEBUG);
|
||||||
for (i = 0; i < length; i++)
|
for (i = 0; i < master->tx_data_length; i++)
|
||||||
{
|
{
|
||||||
EC_DBG("%02X ", data[i]);
|
EC_DBG("%02X ", master->tx_data[i]);
|
||||||
|
if ((i + 1) % 16 == 0) EC_DBG("\n" KERN_DEBUG);
|
||||||
|
}
|
||||||
|
EC_DBG("\n");
|
||||||
|
|
||||||
|
EC_DBG(KERN_DEBUG "EtherCAT: rx_data content (%i Bytes):\n",
|
||||||
|
master->rx_data_length);
|
||||||
|
|
||||||
|
EC_DBG(KERN_DEBUG);
|
||||||
|
for (i = 0; i < master->rx_data_length; i++)
|
||||||
|
{
|
||||||
|
EC_DBG("%02X ", master->rx_data[i]);
|
||||||
if ((i + 1) % 16 == 0) EC_DBG("\n" KERN_DEBUG);
|
if ((i + 1) % 16 == 0) EC_DBG("\n" KERN_DEBUG);
|
||||||
}
|
}
|
||||||
EC_DBG("\n");
|
EC_DBG("\n");
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,7 @@ typedef struct
|
||||||
unsigned char rx_data[ECAT_FRAME_BUFFER_SIZE]; /**< Statische Speicher für
|
unsigned char rx_data[ECAT_FRAME_BUFFER_SIZE]; /**< Statische Speicher für
|
||||||
eine Kopie des Rx-Buffers
|
eine Kopie des Rx-Buffers
|
||||||
im EtherCAT-Gerät */
|
im EtherCAT-Gerät */
|
||||||
|
unsigned int rx_data_length; /**< Länge der Daten im Empfangsspeicher */
|
||||||
|
|
||||||
unsigned char *process_data; /**< Zeiger auf Speicher mit Prozessdaten */
|
unsigned char *process_data; /**< Zeiger auf Speicher mit Prozessdaten */
|
||||||
unsigned int process_data_length; /**< Länge der Prozessdaten */
|
unsigned int process_data_length; /**< Länge der Prozessdaten */
|
||||||
|
|
@ -82,9 +83,7 @@ int EtherCAT_read_process_data(EtherCAT_master_t *);
|
||||||
void EtherCAT_clear_process_data(EtherCAT_master_t *);
|
void EtherCAT_clear_process_data(EtherCAT_master_t *);
|
||||||
|
|
||||||
// Private functions
|
// Private functions
|
||||||
void set_byte(unsigned char *, unsigned int, unsigned char);
|
void output_debug_data(const EtherCAT_master_t *);
|
||||||
void set_word(unsigned char *, unsigned int, unsigned int);
|
|
||||||
void output_debug_data(unsigned char *, unsigned int);
|
|
||||||
|
|
||||||
/***************************************************************/
|
/***************************************************************/
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue