mirror of
https://github.com/OpenEtherCATsociety/SOEM.git
synced 2026-02-05 16:50:36 +08:00
Run clang-format on sources
Change-Id: Ide59897b87104bfb71e953b7f8dace00e441e245
This commit is contained in:
@@ -13,14 +13,13 @@
|
||||
#define _ec_base_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int ecx_setupdatagram(ecx_portt *port, void *frame, uint8 com, uint8 idx, uint16 ADP, uint16 ADO, uint16 length, void *data);
|
||||
uint16 ecx_adddatagram(ecx_portt *port, void *frame, uint8 com, uint8 idx, boolean more, uint16 ADP, uint16 ADO, uint16 length, void *data);
|
||||
int ecx_BWR(ecx_portt *port, uint16 ADP,uint16 ADO,uint16 length,void *data,int timeout);
|
||||
int ecx_BRD(ecx_portt *port, uint16 ADP,uint16 ADO,uint16 length,void *data,int timeout);
|
||||
int ecx_BWR(ecx_portt *port, uint16 ADP, uint16 ADO, uint16 length, void *data, int timeout);
|
||||
int ecx_BRD(ecx_portt *port, uint16 ADP, uint16 ADO, uint16 length, void *data, int timeout);
|
||||
int ecx_APRD(ecx_portt *port, uint16 ADP, uint16 ADO, uint16 length, void *data, int timeout);
|
||||
int ecx_ARMW(ecx_portt *port, uint16 ADP, uint16 ADO, uint16 length, void *data, int timeout);
|
||||
int ecx_FRMW(ecx_portt *port, uint16 ADP, uint16 ADO, uint16 length, void *data, int timeout);
|
||||
|
||||
@@ -13,33 +13,32 @@
|
||||
#define _ec_coe_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** max entries in Object Description list */
|
||||
#define EC_MAXODLIST 1024
|
||||
#define EC_MAXODLIST 1024
|
||||
|
||||
/** max entries in Object Entry list */
|
||||
#define EC_MAXOELIST 256
|
||||
#define EC_MAXOELIST 256
|
||||
|
||||
/* Storage for object description list */
|
||||
typedef struct
|
||||
{
|
||||
/** slave number */
|
||||
uint16 Slave;
|
||||
uint16 Slave;
|
||||
/** number of entries in list */
|
||||
uint16 Entries;
|
||||
uint16 Entries;
|
||||
/** array of indexes */
|
||||
uint16 Index[EC_MAXODLIST];
|
||||
uint16 Index[EC_MAXODLIST];
|
||||
/** array of datatypes, see EtherCAT specification */
|
||||
uint16 DataType[EC_MAXODLIST];
|
||||
uint16 DataType[EC_MAXODLIST];
|
||||
/** array of object codes, see EtherCAT specification */
|
||||
uint8 ObjectCode[EC_MAXODLIST];
|
||||
uint8 ObjectCode[EC_MAXODLIST];
|
||||
/** number of subindexes for each index */
|
||||
uint8 MaxSub[EC_MAXODLIST];
|
||||
uint8 MaxSub[EC_MAXODLIST];
|
||||
/** textual description of each index */
|
||||
char Name[EC_MAXODLIST][EC_MAXNAME+1];
|
||||
char Name[EC_MAXODLIST][EC_MAXNAME + 1];
|
||||
} ec_ODlistt;
|
||||
|
||||
/* storage for object list entry information */
|
||||
@@ -48,7 +47,7 @@ typedef struct
|
||||
/** number of entries in list */
|
||||
uint16 Entries;
|
||||
/** array of value infos, see EtherCAT specification */
|
||||
uint8 ValueInfo[EC_MAXOELIST];
|
||||
uint8 ValueInfo[EC_MAXOELIST];
|
||||
/** array of value infos, see EtherCAT specification */
|
||||
uint16 DataType[EC_MAXOELIST];
|
||||
/** array of bit lengths, see EtherCAT specification */
|
||||
@@ -56,7 +55,7 @@ typedef struct
|
||||
/** array of object access bits, see EtherCAT specification */
|
||||
uint16 ObjAccess[EC_MAXOELIST];
|
||||
/** textual description of each index */
|
||||
char Name[EC_MAXOELIST][EC_MAXNAME+1];
|
||||
char Name[EC_MAXOELIST][EC_MAXNAME + 1];
|
||||
} ec_OElistt;
|
||||
|
||||
void ecx_SDOerror(ecx_contextt *context, uint16 Slave, uint16 Index, uint8 SubIdx, int32 AbortCode);
|
||||
@@ -64,8 +63,8 @@ int ecx_SDOread(ecx_contextt *context, uint16 slave, uint16 index, uint8 subinde
|
||||
boolean CA, int *psize, void *p, int timeout);
|
||||
int ecx_SDOwrite(ecx_contextt *context, uint16 Slave, uint16 Index, uint8 SubIndex,
|
||||
boolean CA, int psize, const void *p, int Timeout);
|
||||
int ecx_RxPDO(ecx_contextt *context, uint16 Slave, uint16 RxPDOnumber , int psize, const void *p);
|
||||
int ecx_TxPDO(ecx_contextt *context, uint16 slave, uint16 TxPDOnumber , int *psize, void *p, int timeout);
|
||||
int ecx_RxPDO(ecx_contextt *context, uint16 Slave, uint16 RxPDOnumber, int psize, const void *p);
|
||||
int ecx_TxPDO(ecx_contextt *context, uint16 slave, uint16 TxPDOnumber, int *psize, void *p, int timeout);
|
||||
int ecx_readPDOmap(ecx_contextt *context, uint16 Slave, uint32 *Osize, uint32 *Isize);
|
||||
int ecx_readPDOmapCA(ecx_contextt *context, uint16 Slave, int Thread_n, uint32 *Osize, uint32 *Isize);
|
||||
int ecx_readODlist(ecx_contextt *context, uint16 Slave, ec_ODlistt *pODlist);
|
||||
|
||||
@@ -13,12 +13,11 @@
|
||||
#define _ec_config_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define EC_NODEOFFSET 0x1000
|
||||
#define EC_TEMPNODE 0xffff
|
||||
#define EC_NODEOFFSET 0x1000
|
||||
#define EC_TEMPNODE 0xffff
|
||||
|
||||
int ecx_config_init(ecx_contextt *context, uint8 usetable);
|
||||
int ecx_config_map_group(ecx_contextt *context, void *pIOmap, uint8 group);
|
||||
|
||||
@@ -13,8 +13,7 @@
|
||||
#define _EC_ECATDC_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
boolean ecx_configdc(ecx_contextt *context);
|
||||
|
||||
@@ -13,37 +13,36 @@
|
||||
#define _ec_eoe_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "soem/soem.h"
|
||||
|
||||
/* use maximum size for EOE mailbox data - mbxheader and 2x frameinfo */
|
||||
#define EC_MAXEOEDATA (EC_MAXMBX - (sizeof(ec_mbxheadert) +\
|
||||
sizeof(uint16_t) +\
|
||||
#define EC_MAXEOEDATA (EC_MAXMBX - (sizeof(ec_mbxheadert) + \
|
||||
sizeof(uint16_t) + \
|
||||
sizeof(uint16_t)))
|
||||
|
||||
/** DNS length according to ETG 1000.6 */
|
||||
#define EOE_DNS_NAME_LENGTH 32
|
||||
#define EOE_DNS_NAME_LENGTH 32
|
||||
/** Ethernet address length not including VLAN */
|
||||
#define EOE_ETHADDR_LENGTH 6
|
||||
#define EOE_ETHADDR_LENGTH 6
|
||||
/** IPv4 address length */
|
||||
#define EOE_IP4_LENGTH sizeof(uint32_t)
|
||||
#define EOE_IP4_LENGTH sizeof(uint32_t)
|
||||
|
||||
#define EOE_MAKEU32(a,b,c,d) (((uint32_t)((a) & 0xff) << 24) | \
|
||||
((uint32_t)((b) & 0xff) << 16) | \
|
||||
((uint32_t)((c) & 0xff) << 8) | \
|
||||
(uint32_t)((d) & 0xff))
|
||||
#define EOE_MAKEU32(a, b, c, d) (((uint32_t)((a) & 0xff) << 24) | \
|
||||
((uint32_t)((b) & 0xff) << 16) | \
|
||||
((uint32_t)((c) & 0xff) << 8) | \
|
||||
(uint32_t)((d) & 0xff))
|
||||
|
||||
#if !defined(EC_BIG_ENDIAN) && defined(EC_LITTLE_ENDIAN)
|
||||
|
||||
#define EOE_HTONS(x) ((((x) & 0x00ffUL) << 8) | (((x) & 0xff00UL) >> 8))
|
||||
#define EOE_NTOHS(x) EOE_HTONS(x)
|
||||
#define EOE_HTONL(x) ((((x) & 0x000000ffUL) << 24) | \
|
||||
(((x) & 0x0000ff00UL) << 8) | \
|
||||
(((x) & 0x00ff0000UL) >> 8) | \
|
||||
(((x) & 0xff000000UL) >> 24))
|
||||
(((x) & 0x0000ff00UL) << 8) | \
|
||||
(((x) & 0x00ff0000UL) >> 8) | \
|
||||
(((x) & 0xff000000UL) >> 24))
|
||||
#define EOE_NTOHL(x) EOE_HTONL(x)
|
||||
#else
|
||||
#define EOE_HTONS(x) (x)
|
||||
@@ -53,50 +52,50 @@ extern "C"
|
||||
#endif /* !defined(EC_BIG_ENDIAN) && defined(EC_LITTLE_ENDIAN) */
|
||||
|
||||
/** Get one byte from the 4-byte address */
|
||||
#define eoe_ip4_addr1(ipaddr) (((const uint8_t*)(&(ipaddr)->addr))[0])
|
||||
#define eoe_ip4_addr2(ipaddr) (((const uint8_t*)(&(ipaddr)->addr))[1])
|
||||
#define eoe_ip4_addr3(ipaddr) (((const uint8_t*)(&(ipaddr)->addr))[2])
|
||||
#define eoe_ip4_addr4(ipaddr) (((const uint8_t*)(&(ipaddr)->addr))[3])
|
||||
#define eoe_ip4_addr1(ipaddr) (((const uint8_t *)(&(ipaddr)->addr))[0])
|
||||
#define eoe_ip4_addr2(ipaddr) (((const uint8_t *)(&(ipaddr)->addr))[1])
|
||||
#define eoe_ip4_addr3(ipaddr) (((const uint8_t *)(&(ipaddr)->addr))[2])
|
||||
#define eoe_ip4_addr4(ipaddr) (((const uint8_t *)(&(ipaddr)->addr))[3])
|
||||
|
||||
/** Set an IP address given by the four byte-parts */
|
||||
#define EOE_IP4_ADDR_TO_U32(ipaddr,a,b,c,d) \
|
||||
(ipaddr)->addr = EOE_HTONL(EOE_MAKEU32(a,b,c,d))
|
||||
#define EOE_IP4_ADDR_TO_U32(ipaddr, a, b, c, d) \
|
||||
(ipaddr)->addr = EOE_HTONL(EOE_MAKEU32(a, b, c, d))
|
||||
|
||||
/** Header frame info 1 */
|
||||
#define EOE_HDR_FRAME_TYPE_OFFSET 0
|
||||
#define EOE_HDR_FRAME_TYPE (0xF << 0)
|
||||
#define EOE_HDR_FRAME_TYPE_SET(x) (((x) & 0xF) << 0)
|
||||
#define EOE_HDR_FRAME_TYPE_GET(x) (((x) >> 0) & 0xF)
|
||||
#define EOE_HDR_FRAME_PORT_OFFSET 4
|
||||
#define EOE_HDR_FRAME_PORT (0xF << 4)
|
||||
#define EOE_HDR_FRAME_PORT_SET(x) ((uint16)(((x) & 0xF) << 4))
|
||||
#define EOE_HDR_FRAME_PORT_GET(x) (((x) >> 4) & 0xF)
|
||||
#define EOE_HDR_LAST_FRAGMENT_OFFSET 8
|
||||
#define EOE_HDR_LAST_FRAGMENT (0x1 << 8)
|
||||
#define EOE_HDR_LAST_FRAGMENT_SET(x) (((x) & 0x1) << 8)
|
||||
#define EOE_HDR_LAST_FRAGMENT_GET(x) (((x) >> 8) & 0x1)
|
||||
#define EOE_HDR_TIME_APPEND_OFFSET 9
|
||||
#define EOE_HDR_TIME_APPEND (0x1 << 9)
|
||||
#define EOE_HDR_TIME_APPEND_SET(x) (((x) & 0x1) << 9)
|
||||
#define EOE_HDR_TIME_APPEND_GET(x) (((x) >> 9) & 0x1)
|
||||
#define EOE_HDR_TIME_REQUEST_OFFSET 10
|
||||
#define EOE_HDR_TIME_REQUEST (0x1 << 10)
|
||||
#define EOE_HDR_TIME_REQUEST_SET(x) (((x) & 0x1) << 10)
|
||||
#define EOE_HDR_TIME_REQUEST_GET(x) (((x) >> 10) & 0x1)
|
||||
#define EOE_HDR_FRAME_TYPE_OFFSET 0
|
||||
#define EOE_HDR_FRAME_TYPE (0xF << 0)
|
||||
#define EOE_HDR_FRAME_TYPE_SET(x) (((x) & 0xF) << 0)
|
||||
#define EOE_HDR_FRAME_TYPE_GET(x) (((x) >> 0) & 0xF)
|
||||
#define EOE_HDR_FRAME_PORT_OFFSET 4
|
||||
#define EOE_HDR_FRAME_PORT (0xF << 4)
|
||||
#define EOE_HDR_FRAME_PORT_SET(x) ((uint16)(((x) & 0xF) << 4))
|
||||
#define EOE_HDR_FRAME_PORT_GET(x) (((x) >> 4) & 0xF)
|
||||
#define EOE_HDR_LAST_FRAGMENT_OFFSET 8
|
||||
#define EOE_HDR_LAST_FRAGMENT (0x1 << 8)
|
||||
#define EOE_HDR_LAST_FRAGMENT_SET(x) (((x) & 0x1) << 8)
|
||||
#define EOE_HDR_LAST_FRAGMENT_GET(x) (((x) >> 8) & 0x1)
|
||||
#define EOE_HDR_TIME_APPEND_OFFSET 9
|
||||
#define EOE_HDR_TIME_APPEND (0x1 << 9)
|
||||
#define EOE_HDR_TIME_APPEND_SET(x) (((x) & 0x1) << 9)
|
||||
#define EOE_HDR_TIME_APPEND_GET(x) (((x) >> 9) & 0x1)
|
||||
#define EOE_HDR_TIME_REQUEST_OFFSET 10
|
||||
#define EOE_HDR_TIME_REQUEST (0x1 << 10)
|
||||
#define EOE_HDR_TIME_REQUEST_SET(x) (((x) & 0x1) << 10)
|
||||
#define EOE_HDR_TIME_REQUEST_GET(x) (((x) >> 10) & 0x1)
|
||||
|
||||
/** Header frame info 2 */
|
||||
#define EOE_HDR_FRAG_NO_OFFSET 0
|
||||
#define EOE_HDR_FRAG_NO (0x3F << 0)
|
||||
#define EOE_HDR_FRAG_NO_SET(x) ((uint16)(((x) & 0x3F) << 0))
|
||||
#define EOE_HDR_FRAG_NO_GET(x) (((x) >> 0) & 0x3F)
|
||||
#define EOE_HDR_FRAME_OFFSET_OFFSET 6
|
||||
#define EOE_HDR_FRAME_OFFSET (0x3F << 6)
|
||||
#define EOE_HDR_FRAME_OFFSET_SET(x) ((uint16)(((x) & 0x3F) << 6))
|
||||
#define EOE_HDR_FRAME_OFFSET_GET(x) (((x) >> 6) & 0x3F)
|
||||
#define EOE_HDR_FRAME_NO_OFFSET 12
|
||||
#define EOE_HDR_FRAME_NO (0xF << 12)
|
||||
#define EOE_HDR_FRAME_NO_SET(x) ((uint16)(((x) & 0xF) << 12))
|
||||
#define EOE_HDR_FRAME_NO_GET(x) (((x) >> 12) & 0xF)
|
||||
#define EOE_HDR_FRAG_NO_OFFSET 0
|
||||
#define EOE_HDR_FRAG_NO (0x3F << 0)
|
||||
#define EOE_HDR_FRAG_NO_SET(x) ((uint16)(((x) & 0x3F) << 0))
|
||||
#define EOE_HDR_FRAG_NO_GET(x) (((x) >> 0) & 0x3F)
|
||||
#define EOE_HDR_FRAME_OFFSET_OFFSET 6
|
||||
#define EOE_HDR_FRAME_OFFSET (0x3F << 6)
|
||||
#define EOE_HDR_FRAME_OFFSET_SET(x) ((uint16)(((x) & 0x3F) << 6))
|
||||
#define EOE_HDR_FRAME_OFFSET_GET(x) (((x) >> 6) & 0x3F)
|
||||
#define EOE_HDR_FRAME_NO_OFFSET 12
|
||||
#define EOE_HDR_FRAME_NO (0xF << 12)
|
||||
#define EOE_HDR_FRAME_NO_SET(x) ((uint16)(((x) & 0xF) << 12))
|
||||
#define EOE_HDR_FRAME_NO_GET(x) (((x) >> 12) & 0xF)
|
||||
|
||||
/** EOE param */
|
||||
#define EOE_PARAM_OFFSET 4
|
||||
@@ -108,30 +107,30 @@ extern "C"
|
||||
#define EOE_PARAM_DNS_NAME_INCLUDE (0x1 << 5)
|
||||
|
||||
/** EoE frame types */
|
||||
#define EOE_FRAG_DATA 0
|
||||
#define EOE_INIT_RESP_TIMESTAMP 1
|
||||
#define EOE_INIT_REQ 2 /* Spec SET IP REQ */
|
||||
#define EOE_INIT_RESP 3 /* Spec SET IP RESP */
|
||||
#define EOE_SET_ADDR_FILTER_REQ 4
|
||||
#define EOE_SET_ADDR_FILTER_RESP 5
|
||||
#define EOE_GET_IP_PARAM_REQ 6
|
||||
#define EOE_GET_IP_PARAM_RESP 7
|
||||
#define EOE_GET_ADDR_FILTER_REQ 8
|
||||
#define EOE_GET_ADDR_FILTER_RESP 9
|
||||
#define EOE_FRAG_DATA 0
|
||||
#define EOE_INIT_RESP_TIMESTAMP 1
|
||||
#define EOE_INIT_REQ 2 /* Spec SET IP REQ */
|
||||
#define EOE_INIT_RESP 3 /* Spec SET IP RESP */
|
||||
#define EOE_SET_ADDR_FILTER_REQ 4
|
||||
#define EOE_SET_ADDR_FILTER_RESP 5
|
||||
#define EOE_GET_IP_PARAM_REQ 6
|
||||
#define EOE_GET_IP_PARAM_RESP 7
|
||||
#define EOE_GET_ADDR_FILTER_REQ 8
|
||||
#define EOE_GET_ADDR_FILTER_RESP 9
|
||||
|
||||
/** EoE parameter result codes */
|
||||
#define EOE_RESULT_SUCCESS 0x0000
|
||||
#define EOE_RESULT_UNSPECIFIED_ERROR 0x0001
|
||||
#define EOE_RESULT_UNSUPPORTED_FRAME_TYPE 0x0002
|
||||
#define EOE_RESULT_NO_IP_SUPPORT 0x0201
|
||||
#define EOE_RESULT_NO_DHCP_SUPPORT 0x0202
|
||||
#define EOE_RESULT_NO_FILTER_SUPPORT 0x0401
|
||||
|
||||
#define EOE_RESULT_SUCCESS 0x0000
|
||||
#define EOE_RESULT_UNSPECIFIED_ERROR 0x0001
|
||||
#define EOE_RESULT_UNSUPPORTED_FRAME_TYPE 0x0002
|
||||
#define EOE_RESULT_NO_IP_SUPPORT 0x0201
|
||||
#define EOE_RESULT_NO_DHCP_SUPPORT 0x0202
|
||||
#define EOE_RESULT_NO_FILTER_SUPPORT 0x0401
|
||||
|
||||
/** EOE ip4 address in network order */
|
||||
typedef struct eoe_ip4_addr {
|
||||
typedef struct eoe_ip4_addr
|
||||
{
|
||||
uint32_t addr;
|
||||
}eoe_ip4_addr_t;
|
||||
} eoe_ip4_addr_t;
|
||||
|
||||
/** EOE ethernet address */
|
||||
PACKED_BEGIN
|
||||
@@ -159,8 +158,8 @@ typedef struct eoe_param
|
||||
} eoe_param_t;
|
||||
|
||||
/** EOE structure.
|
||||
* Used to interpret EoE mailbox packets.
|
||||
*/
|
||||
* Used to interpret EoE mailbox packets.
|
||||
*/
|
||||
PACKED_BEGIN
|
||||
typedef struct PACKED
|
||||
{
|
||||
@@ -176,36 +175,36 @@ typedef struct PACKED
|
||||
PACKED_END
|
||||
|
||||
int ecx_EOEdefinehook(ecx_contextt *context, void *hook);
|
||||
int ecx_EOEsetIp(ecx_contextt *context,
|
||||
uint16 slave,
|
||||
uint8 port,
|
||||
eoe_param_t * ipparam,
|
||||
int timeout);
|
||||
int ecx_EOEgetIp(ecx_contextt *context,
|
||||
uint16 slave,
|
||||
uint8 port,
|
||||
eoe_param_t * ipparam,
|
||||
int timeout);
|
||||
int ecx_EOEsend(ecx_contextt *context,
|
||||
uint16 slave,
|
||||
uint8 port,
|
||||
int psize,
|
||||
void *p,
|
||||
int timeout);
|
||||
int ecx_EOErecv(ecx_contextt *context,
|
||||
uint16 slave,
|
||||
uint8 port,
|
||||
int * psize,
|
||||
void *p,
|
||||
int timeout);
|
||||
int ecx_EOEsetIp(ecx_contextt *context,
|
||||
uint16 slave,
|
||||
uint8 port,
|
||||
eoe_param_t *ipparam,
|
||||
int timeout);
|
||||
int ecx_EOEgetIp(ecx_contextt *context,
|
||||
uint16 slave,
|
||||
uint8 port,
|
||||
eoe_param_t *ipparam,
|
||||
int timeout);
|
||||
int ecx_EOEsend(ecx_contextt *context,
|
||||
uint16 slave,
|
||||
uint8 port,
|
||||
int psize,
|
||||
void *p,
|
||||
int timeout);
|
||||
int ecx_EOErecv(ecx_contextt *context,
|
||||
uint16 slave,
|
||||
uint8 port,
|
||||
int *psize,
|
||||
void *p,
|
||||
int timeout);
|
||||
int ecx_EOEreadfragment(
|
||||
ec_mbxbuft * MbxIn,
|
||||
uint8 * rxfragmentno,
|
||||
uint16 * rxframesize,
|
||||
uint16 * rxframeoffset,
|
||||
uint16 * rxframeno,
|
||||
int * psize,
|
||||
void *p);
|
||||
ec_mbxbuft *MbxIn,
|
||||
uint8 *rxfragmentno,
|
||||
uint16 *rxframesize,
|
||||
uint16 *rxframeoffset,
|
||||
uint16 *rxframeno,
|
||||
int *psize,
|
||||
void *p);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -13,8 +13,7 @@
|
||||
#define _ec_foe_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int ecx_FOEdefinehook(ecx_contextt *context, void *hook);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -13,16 +13,15 @@
|
||||
#define _ec_print_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
const char* ec_sdoerror2string( uint32 sdoerrorcode);
|
||||
char* ec_ALstatuscode2string( uint16 ALstatuscode);
|
||||
char* ec_soeerror2string( uint16 errorcode);
|
||||
char* ec_mbxerror2string( uint16 errorcode);
|
||||
char* ecx_err2string(const ec_errort Ec);
|
||||
char* ecx_elist2string(ecx_contextt *context);
|
||||
const char *ec_sdoerror2string(uint32 sdoerrorcode);
|
||||
char *ec_ALstatuscode2string(uint16 ALstatuscode);
|
||||
char *ec_soeerror2string(uint16 errorcode);
|
||||
char *ec_mbxerror2string(uint16 errorcode);
|
||||
char *ecx_err2string(const ec_errort Ec);
|
||||
char *ecx_elist2string(ecx_contextt *context);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -13,34 +13,33 @@
|
||||
#define _ec_soe_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define EC_SOE_DATASTATE_B 0x01
|
||||
#define EC_SOE_NAME_B 0x02
|
||||
#define EC_SOE_ATTRIBUTE_B 0x04
|
||||
#define EC_SOE_UNIT_B 0x08
|
||||
#define EC_SOE_MIN_B 0x10
|
||||
#define EC_SOE_MAX_B 0x20
|
||||
#define EC_SOE_VALUE_B 0x40
|
||||
#define EC_SOE_DEFAULT_B 0x80
|
||||
#define EC_SOE_DATASTATE_B 0x01
|
||||
#define EC_SOE_NAME_B 0x02
|
||||
#define EC_SOE_ATTRIBUTE_B 0x04
|
||||
#define EC_SOE_UNIT_B 0x08
|
||||
#define EC_SOE_MIN_B 0x10
|
||||
#define EC_SOE_MAX_B 0x20
|
||||
#define EC_SOE_VALUE_B 0x40
|
||||
#define EC_SOE_DEFAULT_B 0x80
|
||||
|
||||
#define EC_SOE_MAXNAME 60
|
||||
#define EC_SOE_MAXMAPPING 64
|
||||
#define EC_SOE_MAXNAME 60
|
||||
#define EC_SOE_MAXMAPPING 64
|
||||
|
||||
#define EC_IDN_MDTCONFIG 24
|
||||
#define EC_IDN_ATCONFIG 16
|
||||
#define EC_IDN_MDTCONFIG 24
|
||||
#define EC_IDN_ATCONFIG 16
|
||||
|
||||
/** SoE name structure */
|
||||
PACKED_BEGIN
|
||||
typedef struct PACKED
|
||||
{
|
||||
/** current length in bytes of list */
|
||||
uint16 currentlength;
|
||||
uint16 currentlength;
|
||||
/** maximum length in bytes of list */
|
||||
uint16 maxlength;
|
||||
char name[EC_SOE_MAXNAME];
|
||||
uint16 maxlength;
|
||||
char name[EC_SOE_MAXNAME];
|
||||
} ec_SoEnamet;
|
||||
PACKED_END
|
||||
|
||||
@@ -49,15 +48,15 @@ PACKED_BEGIN
|
||||
typedef struct PACKED
|
||||
{
|
||||
/** current length in bytes of list */
|
||||
uint16 currentlength;
|
||||
uint16 currentlength;
|
||||
/** maximum length in bytes of list */
|
||||
uint16 maxlength;
|
||||
uint16 maxlength;
|
||||
union
|
||||
{
|
||||
uint8 byte[8];
|
||||
uint16 word[4];
|
||||
uint32 dword[2];
|
||||
uint64 lword[1];
|
||||
uint8 byte[8];
|
||||
uint16 word[4];
|
||||
uint32 dword[2];
|
||||
uint64 lword[1];
|
||||
};
|
||||
} ec_SoElistt;
|
||||
PACKED_END
|
||||
@@ -67,50 +66,50 @@ PACKED_BEGIN
|
||||
typedef struct PACKED
|
||||
{
|
||||
/** current length in bytes of list */
|
||||
uint16 currentlength;
|
||||
uint16 currentlength;
|
||||
/** maximum length in bytes of list */
|
||||
uint16 maxlength;
|
||||
uint16 idn[EC_SOE_MAXMAPPING];
|
||||
uint16 maxlength;
|
||||
uint16 idn[EC_SOE_MAXMAPPING];
|
||||
} ec_SoEmappingt;
|
||||
PACKED_END
|
||||
|
||||
#define EC_SOE_LENGTH_1 0x00
|
||||
#define EC_SOE_LENGTH_2 0x01
|
||||
#define EC_SOE_LENGTH_4 0x02
|
||||
#define EC_SOE_LENGTH_8 0x03
|
||||
#define EC_SOE_TYPE_BINARY 0x00
|
||||
#define EC_SOE_TYPE_UINT 0x01
|
||||
#define EC_SOE_TYPE_INT 0x02
|
||||
#define EC_SOE_TYPE_HEX 0x03
|
||||
#define EC_SOE_TYPE_STRING 0x04
|
||||
#define EC_SOE_TYPE_IDN 0x05
|
||||
#define EC_SOE_TYPE_FLOAT 0x06
|
||||
#define EC_SOE_TYPE_PARAMETER 0x07
|
||||
#define EC_SOE_LENGTH_1 0x00
|
||||
#define EC_SOE_LENGTH_2 0x01
|
||||
#define EC_SOE_LENGTH_4 0x02
|
||||
#define EC_SOE_LENGTH_8 0x03
|
||||
#define EC_SOE_TYPE_BINARY 0x00
|
||||
#define EC_SOE_TYPE_UINT 0x01
|
||||
#define EC_SOE_TYPE_INT 0x02
|
||||
#define EC_SOE_TYPE_HEX 0x03
|
||||
#define EC_SOE_TYPE_STRING 0x04
|
||||
#define EC_SOE_TYPE_IDN 0x05
|
||||
#define EC_SOE_TYPE_FLOAT 0x06
|
||||
#define EC_SOE_TYPE_PARAMETER 0x07
|
||||
|
||||
/** SoE attribute structure */
|
||||
PACKED_BEGIN
|
||||
typedef struct PACKED
|
||||
{
|
||||
/** evaluation factor for display purposes */
|
||||
uint32 evafactor :16;
|
||||
uint32 evafactor : 16;
|
||||
/** length of IDN element(s) */
|
||||
uint32 length :2;
|
||||
uint32 length : 2;
|
||||
/** IDN is list */
|
||||
uint32 list :1;
|
||||
uint32 list : 1;
|
||||
/** IDN is command */
|
||||
uint32 command :1;
|
||||
uint32 command : 1;
|
||||
/** datatype */
|
||||
uint32 datatype :3;
|
||||
uint32 reserved1 :1;
|
||||
uint32 datatype : 3;
|
||||
uint32 reserved1 : 1;
|
||||
/** decimals to display if float datatype */
|
||||
uint32 decimals :4;
|
||||
uint32 decimals : 4;
|
||||
/** write protected in pre-op */
|
||||
uint32 wppreop :1;
|
||||
uint32 wppreop : 1;
|
||||
/** write protected in safe-op */
|
||||
uint32 wpsafeop :1;
|
||||
uint32 wpsafeop : 1;
|
||||
/** write protected in op */
|
||||
uint32 wpop :1;
|
||||
uint32 reserved2 :1;
|
||||
uint32 wpop : 1;
|
||||
uint32 reserved2 : 1;
|
||||
} ec_SoEattributet;
|
||||
PACKED_END
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -13,92 +13,94 @@
|
||||
|
||||
#include "ee_x86_64_tsc.h"
|
||||
|
||||
#define USECS_PER_SEC 1000000
|
||||
#define NSECS_PER_SEC 1000000000
|
||||
#define USECS_PER_SEC 1000000
|
||||
#define NSECS_PER_SEC 1000000000
|
||||
|
||||
uint64_t osEE_x86_64_tsc_read(void);
|
||||
|
||||
void ee_usleep(uint32 usec);
|
||||
|
||||
inline int osal_usleep (uint32 usec)
|
||||
inline int osal_usleep(uint32 usec)
|
||||
{
|
||||
ee_usleep(usec);
|
||||
return 0;
|
||||
ee_usleep(usec);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int osal_gettimeofday(struct timeval *tv, struct timezone *tz)
|
||||
{
|
||||
uint64_t time = osEE_x86_64_tsc_read();
|
||||
tv->tv_sec = time/NSECS_PER_SEC;
|
||||
tv->tv_sec += 946684800UL; /* EtherCAT uses 2000-01-01 as epoch start */
|
||||
tv->tv_usec = (time%NSECS_PER_SEC)/1000;
|
||||
return 0;
|
||||
uint64_t time = osEE_x86_64_tsc_read();
|
||||
tv->tv_sec = time / NSECS_PER_SEC;
|
||||
tv->tv_sec += 946684800UL; /* EtherCAT uses 2000-01-01 as epoch start */
|
||||
tv->tv_usec = (time % NSECS_PER_SEC) / 1000;
|
||||
return 0;
|
||||
}
|
||||
|
||||
ec_timet osal_current_time(void)
|
||||
{
|
||||
struct timeval current_time;
|
||||
ec_timet ret;
|
||||
struct timeval current_time;
|
||||
ec_timet ret;
|
||||
|
||||
osal_gettimeofday(¤t_time, 0);
|
||||
ret.sec = current_time.tv_sec;
|
||||
ret.usec = current_time.tv_usec;
|
||||
return ret;
|
||||
osal_gettimeofday(¤t_time, 0);
|
||||
ret.sec = current_time.tv_sec;
|
||||
ret.usec = current_time.tv_usec;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void osal_time_diff(ec_timet *start, ec_timet *end, ec_timet *diff)
|
||||
{
|
||||
if (end->usec < start->usec) {
|
||||
diff->sec = end->sec - start->sec - 1;
|
||||
diff->usec = end->usec + USECS_PER_SEC - start->usec;
|
||||
} else {
|
||||
diff->sec = end->sec - start->sec;
|
||||
diff->usec = end->usec - start->usec;
|
||||
}
|
||||
if (end->usec < start->usec)
|
||||
{
|
||||
diff->sec = end->sec - start->sec - 1;
|
||||
diff->usec = end->usec + USECS_PER_SEC - start->usec;
|
||||
}
|
||||
else
|
||||
{
|
||||
diff->sec = end->sec - start->sec;
|
||||
diff->usec = end->usec - start->usec;
|
||||
}
|
||||
}
|
||||
|
||||
void osal_timer_start(osal_timert *self, uint32 timeout_usec)
|
||||
{
|
||||
struct timeval start_time;
|
||||
struct timeval timeout;
|
||||
struct timeval stop_time;
|
||||
struct timeval start_time;
|
||||
struct timeval timeout;
|
||||
struct timeval stop_time;
|
||||
|
||||
osal_gettimeofday(&start_time, 0);
|
||||
timeout.tv_sec = timeout_usec / USECS_PER_SEC;
|
||||
timeout.tv_usec = timeout_usec % USECS_PER_SEC;
|
||||
timeradd(&start_time, &timeout, &stop_time);
|
||||
osal_gettimeofday(&start_time, 0);
|
||||
timeout.tv_sec = timeout_usec / USECS_PER_SEC;
|
||||
timeout.tv_usec = timeout_usec % USECS_PER_SEC;
|
||||
timeradd(&start_time, &timeout, &stop_time);
|
||||
|
||||
self->stop_time.sec = stop_time.tv_sec;
|
||||
self->stop_time.usec = stop_time.tv_usec;
|
||||
self->stop_time.sec = stop_time.tv_sec;
|
||||
self->stop_time.usec = stop_time.tv_usec;
|
||||
}
|
||||
|
||||
boolean osal_timer_is_expired (osal_timert *self)
|
||||
boolean osal_timer_is_expired(osal_timert *self)
|
||||
{
|
||||
struct timeval current_time;
|
||||
struct timeval stop_time;
|
||||
int is_not_yet_expired;
|
||||
struct timeval current_time;
|
||||
struct timeval stop_time;
|
||||
int is_not_yet_expired;
|
||||
|
||||
osal_gettimeofday (¤t_time, 0);
|
||||
stop_time.tv_sec = self->stop_time.sec;
|
||||
stop_time.tv_usec = self->stop_time.usec;
|
||||
is_not_yet_expired = timercmp (¤t_time, &stop_time, <);
|
||||
/* OSEE_PRINT("current: %d:%d -- expire: %d:%d -- result: %d\n", */
|
||||
/* current_time.tv_sec, */
|
||||
/* current_time.tv_usec, */
|
||||
/* stop_time.tv_sec, */
|
||||
/* stop_time.tv_usec, */
|
||||
/* is_not_yet_expired); */
|
||||
osal_gettimeofday(¤t_time, 0);
|
||||
stop_time.tv_sec = self->stop_time.sec;
|
||||
stop_time.tv_usec = self->stop_time.usec;
|
||||
is_not_yet_expired = timercmp(¤t_time, &stop_time, <);
|
||||
/* OSEE_PRINT("current: %d:%d -- expire: %d:%d -- result: %d\n", */
|
||||
/* current_time.tv_sec, */
|
||||
/* current_time.tv_usec, */
|
||||
/* stop_time.tv_sec, */
|
||||
/* stop_time.tv_usec, */
|
||||
/* is_not_yet_expired); */
|
||||
|
||||
return is_not_yet_expired == FALSE;
|
||||
return is_not_yet_expired == FALSE;
|
||||
}
|
||||
|
||||
void *osal_malloc(size_t size)
|
||||
{
|
||||
return malloc(size);
|
||||
return malloc(size);
|
||||
}
|
||||
|
||||
void osal_free(void *ptr)
|
||||
{
|
||||
free(ptr);
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,8 +8,7 @@
|
||||
#define _osal_defs_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <sys/time.h>
|
||||
@@ -22,12 +21,15 @@ extern "C"
|
||||
#ifdef EC_DEBUG
|
||||
#define EC_PRINT OSEE_PRINT
|
||||
#else
|
||||
#define EC_PRINT(...) do {} while (0)
|
||||
#define EC_PRINT(...) \
|
||||
do \
|
||||
{ \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
#ifndef PACKED
|
||||
#define PACKED_BEGIN
|
||||
#define PACKED __attribute__((__packed__))
|
||||
#define PACKED __attribute__((__packed__))
|
||||
#define PACKED_END
|
||||
#endif
|
||||
|
||||
|
||||
@@ -11,79 +11,79 @@
|
||||
static int64_t sysfrequency;
|
||||
static double qpc2usec;
|
||||
|
||||
#define USECS_PER_SEC 1000000
|
||||
#define USECS_PER_SEC 1000000
|
||||
|
||||
int osal_gettimeofday (struct timeval *tv, struct timezone *tz)
|
||||
int osal_gettimeofday(struct timeval *tv, struct timezone *tz)
|
||||
{
|
||||
return gettimeofday (tv, tz);
|
||||
return gettimeofday(tv, tz);
|
||||
}
|
||||
|
||||
ec_timet osal_current_time (void)
|
||||
ec_timet osal_current_time(void)
|
||||
{
|
||||
struct timeval current_time;
|
||||
ec_timet return_value;
|
||||
|
||||
osal_gettimeofday (¤t_time, 0);
|
||||
osal_gettimeofday(¤t_time, 0);
|
||||
return_value.sec = current_time.tv_sec;
|
||||
return_value.usec = current_time.tv_usec;
|
||||
return return_value;
|
||||
}
|
||||
|
||||
void osal_timer_start (osal_timert * self, uint32 timeout_usec)
|
||||
void osal_timer_start(osal_timert *self, uint32 timeout_usec)
|
||||
{
|
||||
struct timeval start_time;
|
||||
struct timeval timeout;
|
||||
struct timeval stop_time;
|
||||
|
||||
osal_gettimeofday (&start_time, 0);
|
||||
osal_gettimeofday(&start_time, 0);
|
||||
timeout.tv_sec = timeout_usec / USECS_PER_SEC;
|
||||
timeout.tv_usec = timeout_usec % USECS_PER_SEC;
|
||||
timeradd (&start_time, &timeout, &stop_time);
|
||||
timeradd(&start_time, &timeout, &stop_time);
|
||||
|
||||
self->stop_time.sec = stop_time.tv_sec;
|
||||
self->stop_time.usec = stop_time.tv_usec;
|
||||
}
|
||||
|
||||
boolean osal_timer_is_expired (osal_timert * self)
|
||||
boolean osal_timer_is_expired(osal_timert *self)
|
||||
{
|
||||
struct timeval current_time;
|
||||
struct timeval stop_time;
|
||||
int is_not_yet_expired;
|
||||
|
||||
osal_gettimeofday (¤t_time, 0);
|
||||
osal_gettimeofday(¤t_time, 0);
|
||||
stop_time.tv_sec = self->stop_time.sec;
|
||||
stop_time.tv_usec = self->stop_time.usec;
|
||||
is_not_yet_expired = timercmp (¤t_time, &stop_time, <);
|
||||
is_not_yet_expired = timercmp(¤t_time, &stop_time, <);
|
||||
|
||||
return is_not_yet_expired == FALSE;
|
||||
}
|
||||
|
||||
int osal_usleep(uint32 usec)
|
||||
{
|
||||
RtSleepEx (usec / 1000);
|
||||
RtSleepEx(usec / 1000);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Mutex is not needed when running single threaded */
|
||||
|
||||
void osal_mtx_lock(osal_mutex_t * mtx)
|
||||
void osal_mtx_lock(osal_mutex_t *mtx)
|
||||
{
|
||||
/* RtWaitForSingleObject((HANDLE)mtx, INFINITE); */
|
||||
/* RtWaitForSingleObject((HANDLE)mtx, INFINITE); */
|
||||
}
|
||||
|
||||
void osal_mtx_unlock(osal_mutex_t * mtx)
|
||||
void osal_mtx_unlock(osal_mutex_t *mtx)
|
||||
{
|
||||
/* RtReleaseMutex((HANDLE)mtx); */
|
||||
/* RtReleaseMutex((HANDLE)mtx); */
|
||||
}
|
||||
|
||||
int osal_mtx_lock_timeout(osal_mutex_t * mtx, uint32_t time_ms)
|
||||
int osal_mtx_lock_timeout(osal_mutex_t *mtx, uint32_t time_ms)
|
||||
{
|
||||
/* return RtWaitForSingleObject((HANDLE)mtx, time_ms); */
|
||||
return 0;
|
||||
/* return RtWaitForSingleObject((HANDLE)mtx, time_ms); */
|
||||
return 0;
|
||||
}
|
||||
|
||||
osal_mutex_t * osal_mtx_create(void)
|
||||
osal_mutex_t *osal_mtx_create(void)
|
||||
{
|
||||
/* return (void*)RtCreateMutex(NULL, FALSE, NULL); */
|
||||
return (void *)0;
|
||||
/* return (void*)RtCreateMutex(NULL, FALSE, NULL); */
|
||||
return (void *)0;
|
||||
}
|
||||
|
||||
@@ -8,34 +8,36 @@
|
||||
#define _osal_defs_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// define if debug printf is needed
|
||||
//#define EC_DEBUG
|
||||
// #define EC_DEBUG
|
||||
|
||||
#ifdef EC_DEBUG
|
||||
#define EC_PRINT printf
|
||||
#else
|
||||
#define EC_PRINT(...) do {} while (0)
|
||||
#define EC_PRINT(...) \
|
||||
do \
|
||||
{ \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
#ifndef PACKED
|
||||
#ifdef _MSC_VER
|
||||
#define PACKED_BEGIN __pragma(pack(push, 1))
|
||||
#define PACKED
|
||||
#define PACKED_END __pragma(pack(pop))
|
||||
#elif defined(__GNUC__)
|
||||
#define PACKED_BEGIN
|
||||
#define PACKED __attribute__((__packed__))
|
||||
#define PACKED_END
|
||||
#endif
|
||||
#ifdef _MSC_VER
|
||||
#define PACKED_BEGIN __pragma(pack(push, 1))
|
||||
#define PACKED
|
||||
#define PACKED_END __pragma(pack(pop))
|
||||
#elif defined(__GNUC__)
|
||||
#define PACKED_BEGIN
|
||||
#define PACKED __attribute__((__packed__))
|
||||
#define PACKED_END
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define OSAL_THREAD_HANDLE RTHANDLE
|
||||
#define OSAL_THREAD_FUNC void
|
||||
#define OSAL_THREAD_FUNC_RT void
|
||||
#define OSAL_THREAD_HANDLE RTHANDLE
|
||||
#define OSAL_THREAD_FUNC void
|
||||
#define OSAL_THREAD_FUNC_RT void
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -11,9 +11,9 @@
|
||||
#include <string.h>
|
||||
#include <osal.h>
|
||||
|
||||
#define USECS_PER_SEC 1000000
|
||||
#define USECS_PER_SEC 1000000
|
||||
|
||||
int osal_usleep (uint32 usec)
|
||||
int osal_usleep(uint32 usec)
|
||||
{
|
||||
struct timespec ts;
|
||||
ts.tv_sec = usec / USECS_PER_SEC;
|
||||
@@ -36,11 +36,13 @@ ec_timet osal_current_time(void)
|
||||
|
||||
void osal_time_diff(ec_timet *start, ec_timet *end, ec_timet *diff)
|
||||
{
|
||||
if (end->usec < start->usec) {
|
||||
if (end->usec < start->usec)
|
||||
{
|
||||
diff->sec = end->sec - start->sec - 1;
|
||||
diff->usec = end->usec + 1000000 - start->usec;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
diff->sec = end->sec - start->sec;
|
||||
diff->usec = end->usec - start->usec;
|
||||
}
|
||||
@@ -61,7 +63,7 @@ static void osal_getrelativetime(struct timeval *tv)
|
||||
tv->tv_usec = ts.tv_nsec / 1000;
|
||||
}
|
||||
|
||||
void osal_timer_start(osal_timert * self, uint32 timeout_usec)
|
||||
void osal_timer_start(osal_timert *self, uint32 timeout_usec)
|
||||
{
|
||||
struct timeval start_time;
|
||||
struct timeval timeout;
|
||||
@@ -76,7 +78,7 @@ void osal_timer_start(osal_timert * self, uint32 timeout_usec)
|
||||
self->stop_time.usec = stop_time.tv_usec;
|
||||
}
|
||||
|
||||
boolean osal_timer_is_expired (osal_timert * self)
|
||||
boolean osal_timer_is_expired(osal_timert *self)
|
||||
{
|
||||
struct timeval current_time;
|
||||
struct timeval stop_time;
|
||||
@@ -102,15 +104,15 @@ void osal_free(void *ptr)
|
||||
|
||||
int osal_thread_create(void *thandle, int stacksize, void *func, void *param)
|
||||
{
|
||||
int ret;
|
||||
pthread_attr_t attr;
|
||||
pthread_t *threadp;
|
||||
int ret;
|
||||
pthread_attr_t attr;
|
||||
pthread_t *threadp;
|
||||
|
||||
threadp = thandle;
|
||||
pthread_attr_init(&attr);
|
||||
pthread_attr_setstacksize(&attr, stacksize);
|
||||
ret = pthread_create(threadp, &attr, func, param);
|
||||
if(ret < 0)
|
||||
if (ret < 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -119,24 +121,24 @@ int osal_thread_create(void *thandle, int stacksize, void *func, void *param)
|
||||
|
||||
int osal_thread_create_rt(void *thandle, int stacksize, void *func, void *param)
|
||||
{
|
||||
int ret;
|
||||
pthread_attr_t attr;
|
||||
struct sched_param schparam;
|
||||
pthread_t *threadp;
|
||||
int ret;
|
||||
pthread_attr_t attr;
|
||||
struct sched_param schparam;
|
||||
pthread_t *threadp;
|
||||
|
||||
threadp = thandle;
|
||||
pthread_attr_init(&attr);
|
||||
pthread_attr_setstacksize(&attr, stacksize);
|
||||
ret = pthread_create(threadp, &attr, func, param);
|
||||
pthread_attr_destroy(&attr);
|
||||
if(ret < 0)
|
||||
if (ret < 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
memset(&schparam, 0, sizeof(schparam));
|
||||
schparam.sched_priority = 40;
|
||||
ret = pthread_setschedparam(*threadp, SCHED_FIFO, &schparam);
|
||||
if(ret < 0)
|
||||
if (ret < 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -148,8 +150,8 @@ void *osal_mutex_create(void)
|
||||
{
|
||||
pthread_mutexattr_t mutexattr;
|
||||
osal_mutext *mutex;
|
||||
mutex = (osal_mutext *)osal_malloc (sizeof(osal_mutext));
|
||||
if(mutex)
|
||||
mutex = (osal_mutext *)osal_malloc(sizeof(osal_mutext));
|
||||
if (mutex)
|
||||
{
|
||||
pthread_mutexattr_init(&mutexattr);
|
||||
pthread_mutexattr_setprotocol(&mutexattr, PTHREAD_PRIO_INHERIT);
|
||||
@@ -166,10 +168,10 @@ void osal_mutex_destroy(void *mutex)
|
||||
|
||||
void osal_mutex_lock(void *mutex)
|
||||
{
|
||||
pthread_mutex_lock((osal_mutext *) mutex);
|
||||
pthread_mutex_lock((osal_mutext *)mutex);
|
||||
}
|
||||
|
||||
void osal_mutex_unlock(void *mutex)
|
||||
{
|
||||
pthread_mutex_unlock((osal_mutext *) mutex);
|
||||
pthread_mutex_unlock((osal_mutext *)mutex);
|
||||
}
|
||||
|
||||
@@ -8,31 +8,33 @@
|
||||
#define _osal_defs_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// define if debug printf is needed
|
||||
//#define EC_DEBUG
|
||||
// #define EC_DEBUG
|
||||
|
||||
#ifdef EC_DEBUG
|
||||
#define EC_PRINT printf
|
||||
#else
|
||||
#define EC_PRINT(...) do {} while (0)
|
||||
#define EC_PRINT(...) \
|
||||
do \
|
||||
{ \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
#ifndef PACKED
|
||||
#define PACKED_BEGIN
|
||||
#define PACKED __attribute__((__packed__))
|
||||
#define PACKED __attribute__((__packed__))
|
||||
#define PACKED_END
|
||||
#endif
|
||||
|
||||
#include <pthread.h>
|
||||
#define OSAL_THREAD_HANDLE pthread_t *
|
||||
#define OSAL_THREAD_FUNC void
|
||||
#define OSAL_THREAD_HANDLE pthread_t *
|
||||
#define OSAL_THREAD_FUNC void
|
||||
#define OSAL_THREAD_FUNC_RT void
|
||||
|
||||
#define osal_mutext pthread_mutex_t
|
||||
#define osal_mutext pthread_mutex_t
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -11,9 +11,9 @@
|
||||
#include <string.h>
|
||||
#include <osal.h>
|
||||
|
||||
#define USECS_PER_SEC 1000000
|
||||
#define USECS_PER_SEC 1000000
|
||||
|
||||
int osal_usleep (uint32 usec)
|
||||
int osal_usleep(uint32 usec)
|
||||
{
|
||||
struct timespec ts;
|
||||
ts.tv_sec = usec / USECS_PER_SEC;
|
||||
@@ -26,7 +26,7 @@ int osal_gettimeofday(struct timeval *tv, struct timezone *tz)
|
||||
{
|
||||
struct timespec ts;
|
||||
int return_value;
|
||||
(void)tz; /* Not used */
|
||||
(void)tz; /* Not used */
|
||||
|
||||
/* Use clock_gettime to prevent possible live-lock.
|
||||
* Gettimeofday uses CLOCK_REALTIME that can get NTP timeadjust.
|
||||
@@ -51,17 +51,19 @@ ec_timet osal_current_time(void)
|
||||
|
||||
void osal_time_diff(ec_timet *start, ec_timet *end, ec_timet *diff)
|
||||
{
|
||||
if (end->usec < start->usec) {
|
||||
if (end->usec < start->usec)
|
||||
{
|
||||
diff->sec = end->sec - start->sec - 1;
|
||||
diff->usec = end->usec + 1000000 - start->usec;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
diff->sec = end->sec - start->sec;
|
||||
diff->usec = end->usec - start->usec;
|
||||
}
|
||||
}
|
||||
|
||||
void osal_timer_start(osal_timert * self, uint32 timeout_usec)
|
||||
void osal_timer_start(osal_timert *self, uint32 timeout_usec)
|
||||
{
|
||||
struct timeval start_time;
|
||||
struct timeval timeout;
|
||||
@@ -76,7 +78,7 @@ void osal_timer_start(osal_timert * self, uint32 timeout_usec)
|
||||
self->stop_time.usec = stop_time.tv_usec;
|
||||
}
|
||||
|
||||
boolean osal_timer_is_expired (osal_timert * self)
|
||||
boolean osal_timer_is_expired(osal_timert *self)
|
||||
{
|
||||
struct timeval current_time;
|
||||
struct timeval stop_time;
|
||||
@@ -102,15 +104,15 @@ void osal_free(void *ptr)
|
||||
|
||||
int osal_thread_create(void *thandle, int stacksize, void *func, void *param)
|
||||
{
|
||||
int ret;
|
||||
pthread_attr_t attr;
|
||||
pthread_t *threadp;
|
||||
int ret;
|
||||
pthread_attr_t attr;
|
||||
pthread_t *threadp;
|
||||
|
||||
threadp = thandle;
|
||||
pthread_attr_init(&attr);
|
||||
pthread_attr_setstacksize(&attr, stacksize);
|
||||
ret = pthread_create(threadp, &attr, func, param);
|
||||
if(ret < 0)
|
||||
if (ret < 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -119,24 +121,24 @@ int osal_thread_create(void *thandle, int stacksize, void *func, void *param)
|
||||
|
||||
int osal_thread_create_rt(void *thandle, int stacksize, void *func, void *param)
|
||||
{
|
||||
int ret;
|
||||
pthread_attr_t attr;
|
||||
struct sched_param schparam;
|
||||
pthread_t *threadp;
|
||||
int ret;
|
||||
pthread_attr_t attr;
|
||||
struct sched_param schparam;
|
||||
pthread_t *threadp;
|
||||
|
||||
threadp = thandle;
|
||||
pthread_attr_init(&attr);
|
||||
pthread_attr_setstacksize(&attr, stacksize);
|
||||
ret = pthread_create(threadp, &attr, func, param);
|
||||
pthread_attr_destroy(&attr);
|
||||
if(ret < 0)
|
||||
if (ret < 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
memset(&schparam, 0, sizeof(schparam));
|
||||
schparam.sched_priority = 40;
|
||||
ret = pthread_setschedparam(*threadp, SCHED_FIFO, &schparam);
|
||||
if(ret < 0)
|
||||
if (ret < 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -8,28 +8,30 @@
|
||||
#define _osal_defs_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// define if debug printf is needed
|
||||
//#define EC_DEBUG
|
||||
// #define EC_DEBUG
|
||||
|
||||
#ifdef EC_DEBUG
|
||||
#define EC_PRINT printf
|
||||
#else
|
||||
#define EC_PRINT(...) do {} while (0)
|
||||
#define EC_PRINT(...) \
|
||||
do \
|
||||
{ \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
#ifndef PACKED
|
||||
#define PACKED_BEGIN
|
||||
#define PACKED __attribute__((__packed__))
|
||||
#define PACKED __attribute__((__packed__))
|
||||
#define PACKED_END
|
||||
#endif
|
||||
|
||||
#include <pthread.h>
|
||||
#define OSAL_THREAD_HANDLE pthread_t *
|
||||
#define OSAL_THREAD_FUNC void
|
||||
#define OSAL_THREAD_HANDLE pthread_t *
|
||||
#define OSAL_THREAD_FUNC void
|
||||
#define OSAL_THREAD_FUNC_RT void
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
39
osal/osal.h
39
osal/osal.h
@@ -8,8 +8,7 @@
|
||||
#define _osal_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "osal_defs.h"
|
||||
@@ -18,36 +17,36 @@ extern "C"
|
||||
|
||||
/* General types */
|
||||
#ifndef TRUE
|
||||
#define TRUE 1
|
||||
#define TRUE 1
|
||||
#endif
|
||||
#ifndef FALSE
|
||||
#define FALSE 0
|
||||
#define FALSE 0
|
||||
#endif
|
||||
typedef uint8_t boolean;
|
||||
typedef int8_t int8;
|
||||
typedef int16_t int16;
|
||||
typedef int32_t int32;
|
||||
typedef uint8_t uint8;
|
||||
typedef uint16_t uint16;
|
||||
typedef uint32_t uint32;
|
||||
typedef int64_t int64;
|
||||
typedef uint64_t uint64;
|
||||
typedef float float32;
|
||||
typedef double float64;
|
||||
typedef uint8_t boolean;
|
||||
typedef int8_t int8;
|
||||
typedef int16_t int16;
|
||||
typedef int32_t int32;
|
||||
typedef uint8_t uint8;
|
||||
typedef uint16_t uint16;
|
||||
typedef uint32_t uint32;
|
||||
typedef int64_t int64;
|
||||
typedef uint64_t uint64;
|
||||
typedef float float32;
|
||||
typedef double float64;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32 sec; /*< Seconds elapsed since the Epoch (Jan 1, 1970) */
|
||||
uint32 usec; /*< Microseconds elapsed since last second boundary */
|
||||
uint32 sec; /*< Seconds elapsed since the Epoch (Jan 1, 1970) */
|
||||
uint32 usec; /*< Microseconds elapsed since last second boundary */
|
||||
} ec_timet;
|
||||
|
||||
typedef struct osal_timer
|
||||
{
|
||||
ec_timet stop_time;
|
||||
ec_timet stop_time;
|
||||
} osal_timert;
|
||||
|
||||
void osal_timer_start(osal_timert * self, uint32 timeout_us);
|
||||
boolean osal_timer_is_expired(osal_timert * self);
|
||||
void osal_timer_start(osal_timert *self, uint32 timeout_us);
|
||||
boolean osal_timer_is_expired(osal_timert *self);
|
||||
int osal_usleep(uint32 usec);
|
||||
ec_timet osal_current_time(void);
|
||||
void osal_time_diff(ec_timet *start, ec_timet *end, ec_timet *diff);
|
||||
|
||||
@@ -11,9 +11,9 @@
|
||||
#include <string.h>
|
||||
#include <osal.h>
|
||||
|
||||
#define USECS_PER_SEC 1000000
|
||||
#define USECS_PER_SEC 1000000
|
||||
|
||||
int osal_usleep (uint32 usec)
|
||||
int osal_usleep(uint32 usec)
|
||||
{
|
||||
struct timespec ts;
|
||||
ts.tv_sec = usec / USECS_PER_SEC;
|
||||
@@ -26,7 +26,7 @@ int osal_gettimeofday(struct timeval *tv, struct timezone *tz)
|
||||
{
|
||||
struct timespec ts;
|
||||
int return_value;
|
||||
(void)tz; /* Not used */
|
||||
(void)tz; /* Not used */
|
||||
|
||||
/* Use clock_gettime to prevent possible live-lock.
|
||||
* Gettimeofday uses CLOCK_REALTIME that can get NTP timeadjust.
|
||||
@@ -51,17 +51,19 @@ ec_timet osal_current_time(void)
|
||||
|
||||
void osal_time_diff(ec_timet *start, ec_timet *end, ec_timet *diff)
|
||||
{
|
||||
if (end->usec < start->usec) {
|
||||
if (end->usec < start->usec)
|
||||
{
|
||||
diff->sec = end->sec - start->sec - 1;
|
||||
diff->usec = end->usec + 1000000 - start->usec;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
diff->sec = end->sec - start->sec;
|
||||
diff->usec = end->usec - start->usec;
|
||||
}
|
||||
}
|
||||
|
||||
void osal_timer_start(osal_timert * self, uint32 timeout_usec)
|
||||
void osal_timer_start(osal_timert *self, uint32 timeout_usec)
|
||||
{
|
||||
struct timeval start_time;
|
||||
struct timeval timeout;
|
||||
@@ -76,7 +78,7 @@ void osal_timer_start(osal_timert * self, uint32 timeout_usec)
|
||||
self->stop_time.usec = stop_time.tv_usec;
|
||||
}
|
||||
|
||||
boolean osal_timer_is_expired (osal_timert * self)
|
||||
boolean osal_timer_is_expired(osal_timert *self)
|
||||
{
|
||||
struct timeval current_time;
|
||||
struct timeval stop_time;
|
||||
@@ -102,15 +104,15 @@ void osal_free(void *ptr)
|
||||
|
||||
int osal_thread_create(void *thandle, int stacksize, void *func, void *param)
|
||||
{
|
||||
int ret;
|
||||
pthread_attr_t attr;
|
||||
pthread_t *threadp;
|
||||
int ret;
|
||||
pthread_attr_t attr;
|
||||
pthread_t *threadp;
|
||||
|
||||
threadp = thandle;
|
||||
pthread_attr_init(&attr);
|
||||
pthread_attr_setstacksize(&attr, stacksize);
|
||||
ret = pthread_create(threadp, &attr, func, param);
|
||||
if(ret < 0)
|
||||
if (ret < 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -119,24 +121,24 @@ int osal_thread_create(void *thandle, int stacksize, void *func, void *param)
|
||||
|
||||
int osal_thread_create_rt(void *thandle, int stacksize, void *func, void *param)
|
||||
{
|
||||
int ret;
|
||||
pthread_attr_t attr;
|
||||
struct sched_param schparam;
|
||||
pthread_t *threadp;
|
||||
int ret;
|
||||
pthread_attr_t attr;
|
||||
struct sched_param schparam;
|
||||
pthread_t *threadp;
|
||||
|
||||
threadp = thandle;
|
||||
pthread_attr_init(&attr);
|
||||
pthread_attr_setstacksize(&attr, stacksize);
|
||||
ret = pthread_create(threadp, &attr, func, param);
|
||||
pthread_attr_destroy(&attr);
|
||||
if(ret < 0)
|
||||
if (ret < 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
memset(&schparam, 0, sizeof(schparam));
|
||||
schparam.sched_priority = 40;
|
||||
ret = pthread_setschedparam(*threadp, SCHED_FIFO, &schparam);
|
||||
if(ret < 0)
|
||||
if (ret < 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -8,28 +8,30 @@
|
||||
#define _osal_defs_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// define if debug printf is needed
|
||||
//#define EC_DEBUG
|
||||
// #define EC_DEBUG
|
||||
|
||||
#ifdef EC_DEBUG
|
||||
#define EC_PRINT printf
|
||||
#else
|
||||
#define EC_PRINT(...) do {} while (0)
|
||||
#define EC_PRINT(...) \
|
||||
do \
|
||||
{ \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
#ifndef PACKED
|
||||
#define PACKED_BEGIN
|
||||
#define PACKED __attribute__((__packed__))
|
||||
#define PACKED __attribute__((__packed__))
|
||||
#define PACKED_END
|
||||
#endif
|
||||
|
||||
#include <pthread.h>
|
||||
#define OSAL_THREAD_HANDLE pthread_t *
|
||||
#define OSAL_THREAD_FUNC void
|
||||
#define OSAL_THREAD_HANDLE pthread_t *
|
||||
#define OSAL_THREAD_FUNC void
|
||||
#define OSAL_THREAD_FUNC_RT void
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -10,29 +10,29 @@
|
||||
#include <sys/time.h>
|
||||
#include <config.h>
|
||||
|
||||
#define USECS_PER_SEC 1000000
|
||||
#define USECS_PER_TICK (USECS_PER_SEC / CFG_TICKS_PER_SECOND)
|
||||
#define USECS_PER_SEC 1000000
|
||||
#define USECS_PER_TICK (USECS_PER_SEC / CFG_TICKS_PER_SECOND)
|
||||
|
||||
int gettimeofday(struct timeval *tp, void *tzp)
|
||||
{
|
||||
tick_t tick = tick_get();
|
||||
tick_t ticks_left;
|
||||
|
||||
ASSERT (tp != NULL);
|
||||
ASSERT(tp != NULL);
|
||||
|
||||
tp->tv_sec = tick / CFG_TICKS_PER_SECOND;
|
||||
|
||||
ticks_left = tick % CFG_TICKS_PER_SECOND;
|
||||
tp->tv_usec = ticks_left * USECS_PER_TICK;
|
||||
ASSERT (tp->tv_usec < USECS_PER_SEC);
|
||||
ASSERT(tp->tv_usec < USECS_PER_SEC);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int osal_usleep (uint32 usec)
|
||||
int osal_usleep(uint32 usec)
|
||||
{
|
||||
tick_t ticks = (usec / USECS_PER_TICK) + 1;
|
||||
task_delay (ticks);
|
||||
task_delay(ticks);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -41,12 +41,12 @@ int osal_gettimeofday(struct timeval *tv, struct timezone *tz)
|
||||
return gettimeofday(tv, tz);
|
||||
}
|
||||
|
||||
ec_timet osal_current_time (void)
|
||||
ec_timet osal_current_time(void)
|
||||
{
|
||||
struct timeval current_time;
|
||||
ec_timet return_value;
|
||||
|
||||
gettimeofday (¤t_time, 0);
|
||||
gettimeofday(¤t_time, 0);
|
||||
return_value.sec = current_time.tv_sec;
|
||||
return_value.usec = current_time.tv_usec;
|
||||
return return_value;
|
||||
@@ -54,41 +54,43 @@ ec_timet osal_current_time (void)
|
||||
|
||||
void osal_time_diff(ec_timet *start, ec_timet *end, ec_timet *diff)
|
||||
{
|
||||
if (end->usec < start->usec) {
|
||||
if (end->usec < start->usec)
|
||||
{
|
||||
diff->sec = end->sec - start->sec - 1;
|
||||
diff->usec = end->usec + 1000000 - start->usec;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
diff->sec = end->sec - start->sec;
|
||||
diff->usec = end->usec - start->usec;
|
||||
}
|
||||
}
|
||||
|
||||
void osal_timer_start (osal_timert * self, uint32 timeout_usec)
|
||||
void osal_timer_start(osal_timert *self, uint32 timeout_usec)
|
||||
{
|
||||
struct timeval start_time;
|
||||
struct timeval timeout;
|
||||
struct timeval stop_time;
|
||||
|
||||
gettimeofday (&start_time, 0);
|
||||
gettimeofday(&start_time, 0);
|
||||
timeout.tv_sec = timeout_usec / USECS_PER_SEC;
|
||||
timeout.tv_usec = timeout_usec % USECS_PER_SEC;
|
||||
timeradd (&start_time, &timeout, &stop_time);
|
||||
timeradd(&start_time, &timeout, &stop_time);
|
||||
|
||||
self->stop_time.sec = stop_time.tv_sec;
|
||||
self->stop_time.usec = stop_time.tv_usec;
|
||||
}
|
||||
|
||||
boolean osal_timer_is_expired (osal_timert * self)
|
||||
boolean osal_timer_is_expired(osal_timert *self)
|
||||
{
|
||||
struct timeval current_time;
|
||||
struct timeval stop_time;
|
||||
int is_not_yet_expired;
|
||||
|
||||
gettimeofday (¤t_time, 0);
|
||||
gettimeofday(¤t_time, 0);
|
||||
stop_time.tv_sec = self->stop_time.sec;
|
||||
stop_time.tv_usec = self->stop_time.usec;
|
||||
is_not_yet_expired = timercmp (¤t_time, &stop_time, <);
|
||||
is_not_yet_expired = timercmp(¤t_time, &stop_time, <);
|
||||
|
||||
return is_not_yet_expired == false;
|
||||
}
|
||||
@@ -105,8 +107,8 @@ void osal_free(void *ptr)
|
||||
|
||||
int osal_thread_create(void *thandle, int stacksize, void *func, void *param)
|
||||
{
|
||||
thandle = task_spawn ("worker", func, 6,stacksize, param);
|
||||
if(!thandle)
|
||||
thandle = task_spawn("worker", func, 6, stacksize, param);
|
||||
if (!thandle)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -115,8 +117,8 @@ int osal_thread_create(void *thandle, int stacksize, void *func, void *param)
|
||||
|
||||
int osal_thread_create_rt(void *thandle, int stacksize, void *func, void *param)
|
||||
{
|
||||
thandle = task_spawn ("worker_rt", func, 15 ,stacksize, param);
|
||||
if(!thandle)
|
||||
thandle = task_spawn("worker_rt", func, 15, stacksize, param);
|
||||
if (!thandle)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -130,15 +132,15 @@ void *osal_mutex_create(void)
|
||||
|
||||
void osal_mutex_destroy(void *mutex)
|
||||
{
|
||||
mtx_destroy (mutex);
|
||||
mtx_destroy(mutex);
|
||||
}
|
||||
|
||||
void osal_mutex_lock(void *mutex)
|
||||
{
|
||||
mtx_lock (mutex);
|
||||
mtx_lock(mutex);
|
||||
}
|
||||
|
||||
void osal_mutex_unlock(void *mutex)
|
||||
{
|
||||
mtx_unlock (mutex);
|
||||
mtx_unlock(mutex);
|
||||
}
|
||||
|
||||
@@ -8,30 +8,32 @@
|
||||
#define _osal_defs_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// define if debug printf is needed
|
||||
//#define EC_DEBUG
|
||||
// #define EC_DEBUG
|
||||
|
||||
#ifdef EC_DEBUG
|
||||
#define EC_PRINT printf
|
||||
#else
|
||||
#define EC_PRINT(...) do {} while (0)
|
||||
#define EC_PRINT(...) \
|
||||
do \
|
||||
{ \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
#ifndef PACKED
|
||||
#define PACKED_BEGIN
|
||||
#define PACKED __attribute__((__packed__))
|
||||
#define PACKED __attribute__((__packed__))
|
||||
#define PACKED_END
|
||||
#endif
|
||||
|
||||
#define OSAL_THREAD_HANDLE task_t *
|
||||
#define OSAL_THREAD_FUNC void
|
||||
#define OSAL_THREAD_HANDLE task_t *
|
||||
#define OSAL_THREAD_FUNC void
|
||||
#define OSAL_THREAD_FUNC_RT void
|
||||
|
||||
#define osal_mutext mtx_t *
|
||||
#define osal_mutext mtx_t *
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -14,68 +14,67 @@
|
||||
#include <vxWorks.h>
|
||||
#include <taskLib.h>
|
||||
|
||||
#define timercmp(a, b, CMP) \
|
||||
(((a)->tv_sec == (b)->tv_sec) ? ((a)->tv_usec CMP(b)->tv_usec) : ((a)->tv_sec CMP(b)->tv_sec))
|
||||
#define timeradd(a, b, result) \
|
||||
do \
|
||||
{ \
|
||||
(result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \
|
||||
(result)->tv_usec = (a)->tv_usec + (b)->tv_usec; \
|
||||
if ((result)->tv_usec >= 1000000) \
|
||||
{ \
|
||||
++(result)->tv_sec; \
|
||||
(result)->tv_usec -= 1000000; \
|
||||
} \
|
||||
} while (0)
|
||||
#define timersub(a, b, result) \
|
||||
do \
|
||||
{ \
|
||||
(result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
|
||||
(result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
|
||||
if ((result)->tv_usec < 0) \
|
||||
{ \
|
||||
--(result)->tv_sec; \
|
||||
(result)->tv_usec += 1000000; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define timercmp(a, b, CMP) \
|
||||
(((a)->tv_sec == (b)->tv_sec) ? \
|
||||
((a)->tv_usec CMP (b)->tv_usec) : \
|
||||
((a)->tv_sec CMP (b)->tv_sec))
|
||||
#define timeradd(a, b, result) \
|
||||
do { \
|
||||
(result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \
|
||||
(result)->tv_usec = (a)->tv_usec + (b)->tv_usec; \
|
||||
if ((result)->tv_usec >= 1000000) \
|
||||
{ \
|
||||
++(result)->tv_sec; \
|
||||
(result)->tv_usec -= 1000000; \
|
||||
} \
|
||||
} while (0)
|
||||
#define timersub(a, b, result) \
|
||||
do { \
|
||||
(result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
|
||||
(result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
|
||||
if ((result)->tv_usec < 0) { \
|
||||
--(result)->tv_sec; \
|
||||
(result)->tv_usec += 1000000; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define USECS_PER_SEC 1000000
|
||||
#define USECS_PER_SEC 1000000
|
||||
|
||||
/* OBS! config worker threads must have higher prio that task running ec_configuration */
|
||||
#define ECAT_TASK_PRIO_HIGH 20 /* Priority for high performance network task */
|
||||
#define ECAT_TASK_PRIO_LOW 80 /* Priority for high performance network task */
|
||||
#define ECAT_STACK_SIZE 10000 /* Stack size for high performance task */
|
||||
static int ecatTaskOptions = VX_SUPERVISOR_MODE | VX_UNBREAKABLE;
|
||||
static int ecatTaskIndex = 0;
|
||||
#define ECAT_TASK_PRIO_HIGH 20 /* Priority for high performance network task */
|
||||
#define ECAT_TASK_PRIO_LOW 80 /* Priority for high performance network task */
|
||||
#define ECAT_STACK_SIZE 10000 /* Stack size for high performance task */
|
||||
static int ecatTaskOptions = VX_SUPERVISOR_MODE | VX_UNBREAKABLE;
|
||||
static int ecatTaskIndex = 0;
|
||||
|
||||
#ifndef use_task_delay
|
||||
#define use_task_delay 1
|
||||
#endif
|
||||
|
||||
int osal_usleep (uint32 usec)
|
||||
int osal_usleep(uint32 usec)
|
||||
{
|
||||
#if (use_task_delay == 1)
|
||||
/* Task delay 0 only yields */
|
||||
/* Task delay 0 only yields */
|
||||
taskDelay(usec / 1000);
|
||||
return 0;
|
||||
#else
|
||||
/* The suspension may be longer than requested due to the rounding up of
|
||||
* the request to the timer's resolution or to other scheduling activities
|
||||
* (e.g., a higher priority task intervenes).
|
||||
*/
|
||||
/* The suspension may be longer than requested due to the rounding up of
|
||||
* the request to the timer's resolution or to other scheduling activities
|
||||
* (e.g., a higher priority task intervenes).
|
||||
*/
|
||||
struct timespec ts;
|
||||
ts.tv_sec = usec / USECS_PER_SEC;
|
||||
ts.tv_nsec = (usec % USECS_PER_SEC) * 1000;
|
||||
return nanosleep(&ts, NULL);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
int osal_gettimeofday(struct timeval *tv, struct timezone *tz)
|
||||
{
|
||||
struct timespec ts;
|
||||
int return_value;
|
||||
(void)tz; /* Not used */
|
||||
(void)tz; /* Not used */
|
||||
|
||||
/* Use clock_gettime CLOCK_MONOTONIC to a avoid NTP time adjustments */
|
||||
return_value = clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
@@ -97,17 +96,19 @@ ec_timet osal_current_time(void)
|
||||
|
||||
void osal_time_diff(ec_timet *start, ec_timet *end, ec_timet *diff)
|
||||
{
|
||||
if (end->usec < start->usec) {
|
||||
if (end->usec < start->usec)
|
||||
{
|
||||
diff->sec = end->sec - start->sec - 1;
|
||||
diff->usec = end->usec + 1000000 - start->usec;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
diff->sec = end->sec - start->sec;
|
||||
diff->usec = end->usec - start->usec;
|
||||
}
|
||||
}
|
||||
|
||||
void osal_timer_start(osal_timert * self, uint32 timeout_usec)
|
||||
void osal_timer_start(osal_timert *self, uint32 timeout_usec)
|
||||
{
|
||||
struct timeval start_time;
|
||||
struct timeval timeout;
|
||||
@@ -122,7 +123,7 @@ void osal_timer_start(osal_timert * self, uint32 timeout_usec)
|
||||
self->stop_time.usec = stop_time.tv_usec;
|
||||
}
|
||||
|
||||
boolean osal_timer_is_expired (osal_timert * self)
|
||||
boolean osal_timer_is_expired(osal_timert *self)
|
||||
{
|
||||
struct timeval current_time;
|
||||
struct timeval stop_time;
|
||||
@@ -149,40 +150,39 @@ void osal_free(void *ptr)
|
||||
int osal_thread_create(void *thandle, int stacksize, void *func, void *param)
|
||||
{
|
||||
char task_name[20];
|
||||
TASK_ID * tid = (TASK_ID *)thandle;
|
||||
FUNCPTR func_ptr = func;
|
||||
TASK_ID *tid = (TASK_ID *)thandle;
|
||||
FUNCPTR func_ptr = func;
|
||||
_Vx_usr_arg_t arg1 = (_Vx_usr_arg_t)param;
|
||||
|
||||
snprintf(task_name,sizeof(task_name),"worker_%d",ecatTaskIndex++);
|
||||
snprintf(task_name, sizeof(task_name), "worker_%d", ecatTaskIndex++);
|
||||
|
||||
*tid = taskSpawn (task_name, ECAT_TASK_PRIO_LOW,
|
||||
ecatTaskOptions, ECAT_STACK_SIZE,
|
||||
func_ptr, arg1, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
||||
if(*tid == TASK_ID_ERROR)
|
||||
*tid = taskSpawn(task_name, ECAT_TASK_PRIO_LOW,
|
||||
ecatTaskOptions, ECAT_STACK_SIZE,
|
||||
func_ptr, arg1, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
||||
if (*tid == TASK_ID_ERROR)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int osal_thread_create_rt(void *thandle, int stacksize, void *func, void *param)
|
||||
{
|
||||
char task_name[20];
|
||||
TASK_ID * tid = (TASK_ID *)thandle;
|
||||
FUNCPTR func_ptr = func;
|
||||
TASK_ID *tid = (TASK_ID *)thandle;
|
||||
FUNCPTR func_ptr = func;
|
||||
_Vx_usr_arg_t arg1 = (_Vx_usr_arg_t)param;
|
||||
|
||||
snprintf(task_name,sizeof(task_name),"worker_rt_%d",ecatTaskIndex++);
|
||||
snprintf(task_name, sizeof(task_name), "worker_rt_%d", ecatTaskIndex++);
|
||||
|
||||
*tid = taskSpawn (task_name, ECAT_TASK_PRIO_HIGH,
|
||||
ecatTaskOptions, ECAT_STACK_SIZE,
|
||||
func_ptr, arg1, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
||||
*tid = taskSpawn(task_name, ECAT_TASK_PRIO_HIGH,
|
||||
ecatTaskOptions, ECAT_STACK_SIZE,
|
||||
func_ptr, arg1, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
||||
|
||||
if(*tid == TASK_ID_ERROR)
|
||||
if (*tid == TASK_ID_ERROR)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,22 +8,25 @@
|
||||
#define _osal_defs_
|
||||
|
||||
// define if debug printf is needed
|
||||
//#define EC_DEBUG
|
||||
// #define EC_DEBUG
|
||||
|
||||
#ifdef EC_DEBUG
|
||||
#define EC_PRINT printf
|
||||
#else
|
||||
#define EC_PRINT(...) do {} while (0)
|
||||
#define EC_PRINT(...) \
|
||||
do \
|
||||
{ \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
#ifndef PACKED
|
||||
#define PACKED_BEGIN
|
||||
#define PACKED __attribute__((__packed__))
|
||||
#define PACKED __attribute__((__packed__))
|
||||
#define PACKED_END
|
||||
#endif
|
||||
|
||||
#define OSAL_THREAD_HANDLE TASK_ID
|
||||
#define OSAL_THREAD_FUNC void
|
||||
#define OSAL_THREAD_HANDLE TASK_ID
|
||||
#define OSAL_THREAD_FUNC void
|
||||
#define OSAL_THREAD_FUNC_RT void
|
||||
|
||||
#endif
|
||||
|
||||
@@ -11,13 +11,13 @@
|
||||
static int64_t sysfrequency;
|
||||
static double qpc2usec;
|
||||
|
||||
#define USECS_PER_SEC 1000000
|
||||
#define USECS_PER_SEC 1000000
|
||||
|
||||
static int osal_getrelativetime(struct timeval *tv, struct timezone *tz)
|
||||
{
|
||||
int64_t wintime, usecs;
|
||||
(void)tz;
|
||||
if(!sysfrequency)
|
||||
if (!sysfrequency)
|
||||
{
|
||||
timeBeginPeriod(1);
|
||||
QueryPerformanceFrequency((LARGE_INTEGER *)&sysfrequency);
|
||||
@@ -43,7 +43,7 @@ int osal_gettimeofday(struct timeval *tv, struct timezone *tz)
|
||||
* following factors are required for the conversion from days to 100 ns steps:
|
||||
*
|
||||
* 86.400 seconds per day; 1.000.000 microseconds per second; 10 * 100 ns per microsecond
|
||||
*/
|
||||
*/
|
||||
int64 offset = -134774LL * 86400LL * 1000000LL * 10LL;
|
||||
|
||||
GetSystemTimeAsFileTime(&system_time);
|
||||
@@ -58,12 +58,12 @@ int osal_gettimeofday(struct timeval *tv, struct timezone *tz)
|
||||
return 1;
|
||||
}
|
||||
|
||||
ec_timet osal_current_time (void)
|
||||
ec_timet osal_current_time(void)
|
||||
{
|
||||
struct timeval current_time;
|
||||
ec_timet return_value;
|
||||
|
||||
osal_gettimeofday (¤t_time, 0);
|
||||
osal_gettimeofday(¤t_time, 0);
|
||||
return_value.sec = current_time.tv_sec;
|
||||
return_value.usec = current_time.tv_usec;
|
||||
return return_value;
|
||||
@@ -71,41 +71,43 @@ ec_timet osal_current_time (void)
|
||||
|
||||
void osal_time_diff(ec_timet *start, ec_timet *end, ec_timet *diff)
|
||||
{
|
||||
if (end->usec < start->usec) {
|
||||
if (end->usec < start->usec)
|
||||
{
|
||||
diff->sec = end->sec - start->sec - 1;
|
||||
diff->usec = end->usec + 1000000 - start->usec;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
diff->sec = end->sec - start->sec;
|
||||
diff->usec = end->usec - start->usec;
|
||||
}
|
||||
}
|
||||
|
||||
void osal_timer_start (osal_timert *self, uint32 timeout_usec)
|
||||
void osal_timer_start(osal_timert *self, uint32 timeout_usec)
|
||||
{
|
||||
struct timeval start_time;
|
||||
struct timeval timeout;
|
||||
struct timeval stop_time;
|
||||
|
||||
osal_getrelativetime (&start_time, 0);
|
||||
osal_getrelativetime(&start_time, 0);
|
||||
timeout.tv_sec = timeout_usec / USECS_PER_SEC;
|
||||
timeout.tv_usec = timeout_usec % USECS_PER_SEC;
|
||||
timeradd (&start_time, &timeout, &stop_time);
|
||||
timeradd(&start_time, &timeout, &stop_time);
|
||||
|
||||
self->stop_time.sec = stop_time.tv_sec;
|
||||
self->stop_time.usec = stop_time.tv_usec;
|
||||
}
|
||||
|
||||
boolean osal_timer_is_expired (osal_timert *self)
|
||||
boolean osal_timer_is_expired(osal_timert *self)
|
||||
{
|
||||
struct timeval current_time;
|
||||
struct timeval stop_time;
|
||||
int is_not_yet_expired;
|
||||
|
||||
osal_getrelativetime (¤t_time, 0);
|
||||
osal_getrelativetime(¤t_time, 0);
|
||||
stop_time.tv_sec = self->stop_time.sec;
|
||||
stop_time.tv_usec = self->stop_time.usec;
|
||||
is_not_yet_expired = timercmp (¤t_time, &stop_time, <);
|
||||
is_not_yet_expired = timercmp(¤t_time, &stop_time, <);
|
||||
|
||||
return is_not_yet_expired == FALSE;
|
||||
}
|
||||
@@ -114,11 +116,12 @@ int osal_usleep(uint32 usec)
|
||||
{
|
||||
osal_timert qtime;
|
||||
osal_timer_start(&qtime, usec);
|
||||
if(usec >= 1000)
|
||||
if (usec >= 1000)
|
||||
{
|
||||
SleepEx(usec / 1000, FALSE);
|
||||
}
|
||||
while(!osal_timer_is_expired(&qtime));
|
||||
while (!osal_timer_is_expired(&qtime))
|
||||
;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -134,8 +137,8 @@ void osal_free(void *ptr)
|
||||
|
||||
int osal_thread_create(void *thandle, int stacksize, void *func, void *param)
|
||||
{
|
||||
*(OSAL_THREAD_HANDLE*)thandle = CreateThread(NULL, stacksize, func, param, 0, NULL);
|
||||
if(!thandle)
|
||||
*(OSAL_THREAD_HANDLE *)thandle = CreateThread(NULL, stacksize, func, param, 0, NULL);
|
||||
if (!thandle)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -155,20 +158,20 @@ int osal_thread_create_rt(void *thandle, int stacksize, void *func, void *param)
|
||||
|
||||
void *osal_mutex_create(void)
|
||||
{
|
||||
return CreateMutex (NULL, FALSE, NULL);
|
||||
return CreateMutex(NULL, FALSE, NULL);
|
||||
}
|
||||
|
||||
void osal_mutex_destroy(void *mutex)
|
||||
{
|
||||
CloseHandle (mutex);
|
||||
CloseHandle(mutex);
|
||||
}
|
||||
|
||||
void osal_mutex_lock(void *mutex)
|
||||
{
|
||||
WaitForSingleObject (mutex, INFINITE);
|
||||
WaitForSingleObject(mutex, INFINITE);
|
||||
}
|
||||
|
||||
void osal_mutex_unlock(void *mutex)
|
||||
{
|
||||
ReleaseMutex (mutex);
|
||||
ReleaseMutex(mutex);
|
||||
}
|
||||
|
||||
@@ -8,38 +8,40 @@
|
||||
#define _osal_defs_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN // Exclude some conflicting definitions in windows header
|
||||
#include <windows.h>
|
||||
// define if debug printf is needed
|
||||
//#define EC_DEBUG
|
||||
// #define EC_DEBUG
|
||||
|
||||
#ifdef EC_DEBUG
|
||||
#define EC_PRINT printf
|
||||
#else
|
||||
#define EC_PRINT(...) do {} while (0)
|
||||
#define EC_PRINT(...) \
|
||||
do \
|
||||
{ \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
#ifndef PACKED
|
||||
#define PACKED
|
||||
#ifdef __GNUC__
|
||||
#define PACKED_BEGIN _Pragma("pack(push,1)")
|
||||
#define PACKED_END _Pragma("pack(pop)")
|
||||
#define PACKED_END _Pragma("pack(pop)")
|
||||
#else
|
||||
#define PACKED_BEGIN __pragma(pack(push, 1))
|
||||
#define PACKED_END __pragma(pack(pop))
|
||||
#define PACKED_END __pragma(pack(pop))
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#define OSAL_THREAD_HANDLE HANDLE
|
||||
#define OSAL_THREAD_FUNC void
|
||||
#define OSAL_THREAD_HANDLE HANDLE
|
||||
#define OSAL_THREAD_FUNC void
|
||||
#define OSAL_THREAD_FUNC_RT void
|
||||
|
||||
#define osal_mutext CRITICAL_SECTION
|
||||
#define osal_mutext CRITICAL_SECTION
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -9,29 +9,32 @@
|
||||
|
||||
/* Convenience macros for operations on timevals.
|
||||
NOTE: `timercmp' does not work for >= or <=. */
|
||||
# define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec)
|
||||
# define timeradd(a, b, result) \
|
||||
do { \
|
||||
(result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \
|
||||
(result)->tv_usec = (a)->tv_usec + (b)->tv_usec; \
|
||||
if ((result)->tv_usec >= 1000000) \
|
||||
{ \
|
||||
++(result)->tv_sec; \
|
||||
(result)->tv_usec -= 1000000; \
|
||||
} \
|
||||
} while (0)
|
||||
# define timersub(a, b, result) \
|
||||
do { \
|
||||
(result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
|
||||
(result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
|
||||
if ((result)->tv_usec < 0) { \
|
||||
--(result)->tv_sec; \
|
||||
(result)->tv_usec += 1000000; \
|
||||
} \
|
||||
} while (0)
|
||||
#define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec)
|
||||
#define timeradd(a, b, result) \
|
||||
do \
|
||||
{ \
|
||||
(result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \
|
||||
(result)->tv_usec = (a)->tv_usec + (b)->tv_usec; \
|
||||
if ((result)->tv_usec >= 1000000) \
|
||||
{ \
|
||||
++(result)->tv_sec; \
|
||||
(result)->tv_usec -= 1000000; \
|
||||
} \
|
||||
} while (0)
|
||||
#define timersub(a, b, result) \
|
||||
do \
|
||||
{ \
|
||||
(result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
|
||||
(result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
|
||||
if ((result)->tv_usec < 0) \
|
||||
{ \
|
||||
--(result)->tv_sec; \
|
||||
(result)->tv_usec += 1000000; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
struct timezone;
|
||||
// currently the tz parameter is ignored in the win32 implmentation.
|
||||
int osal_gettimeofday (struct timeval *tv, struct timezone *tz);
|
||||
int osal_gettimeofday(struct timeval *tv, struct timezone *tz);
|
||||
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -13,77 +13,76 @@
|
||||
#define _nicdrvh_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
/** socket connection used */
|
||||
int *sock;
|
||||
/** tx buffer */
|
||||
ec_bufT (*txbuf)[EC_MAXBUF];
|
||||
/** tx buffer lengths */
|
||||
int (*txbuflength)[EC_MAXBUF];
|
||||
/** temporary receive buffer */
|
||||
ec_bufT *tempbuf;
|
||||
/** rx buffers */
|
||||
ec_bufT (*rxbuf)[EC_MAXBUF];
|
||||
/** rx buffer status fields */
|
||||
int (*rxbufstat)[EC_MAXBUF];
|
||||
/** received MAC source address (middle word) */
|
||||
int (*rxsa)[EC_MAXBUF];
|
||||
/** socket connection used */
|
||||
int *sock;
|
||||
/** tx buffer */
|
||||
ec_bufT (*txbuf)[EC_MAXBUF];
|
||||
/** tx buffer lengths */
|
||||
int (*txbuflength)[EC_MAXBUF];
|
||||
/** temporary receive buffer */
|
||||
ec_bufT *tempbuf;
|
||||
/** rx buffers */
|
||||
ec_bufT (*rxbuf)[EC_MAXBUF];
|
||||
/** rx buffer status fields */
|
||||
int (*rxbufstat)[EC_MAXBUF];
|
||||
/** received MAC source address (middle word) */
|
||||
int (*rxsa)[EC_MAXBUF];
|
||||
} ec_stackT;
|
||||
|
||||
/** pointer structure to buffers for redundant port */
|
||||
typedef struct
|
||||
{
|
||||
ec_stackT stack;
|
||||
int sockhandle;
|
||||
/** rx buffers */
|
||||
ec_bufT rxbuf[EC_MAXBUF];
|
||||
/** rx buffer status */
|
||||
int rxbufstat[EC_MAXBUF];
|
||||
/** rx MAC source address */
|
||||
int rxsa[EC_MAXBUF];
|
||||
/** temporary rx buffer */
|
||||
ec_bufT tempinbuf;
|
||||
ec_stackT stack;
|
||||
int sockhandle;
|
||||
/** rx buffers */
|
||||
ec_bufT rxbuf[EC_MAXBUF];
|
||||
/** rx buffer status */
|
||||
int rxbufstat[EC_MAXBUF];
|
||||
/** rx MAC source address */
|
||||
int rxsa[EC_MAXBUF];
|
||||
/** temporary rx buffer */
|
||||
ec_bufT tempinbuf;
|
||||
} ecx_redportt;
|
||||
|
||||
/** pointer structure to buffers, vars and mutexes for port instantiation */
|
||||
typedef struct
|
||||
{
|
||||
ec_stackT stack;
|
||||
int sockhandle;
|
||||
/** rx buffers */
|
||||
ec_bufT rxbuf[EC_MAXBUF];
|
||||
/** rx buffer status */
|
||||
int rxbufstat[EC_MAXBUF];
|
||||
/** rx MAC source address */
|
||||
int rxsa[EC_MAXBUF];
|
||||
/** temporary rx buffer */
|
||||
ec_bufT tempinbuf;
|
||||
/** temporary rx buffer status */
|
||||
int tempinbufs;
|
||||
/** transmit buffers */
|
||||
ec_bufT txbuf[EC_MAXBUF];
|
||||
/** transmit buffer lengths */
|
||||
int txbuflength[EC_MAXBUF];
|
||||
/** temporary tx buffer */
|
||||
ec_bufT txbuf2;
|
||||
/** temporary tx buffer length */
|
||||
int txbuflength2;
|
||||
/** last used frame index */
|
||||
uint8 lastidx;
|
||||
/** current redundancy state */
|
||||
int redstate;
|
||||
/** pointer to redundancy port and buffers */
|
||||
ecx_redportt *redport;
|
||||
ec_stackT stack;
|
||||
int sockhandle;
|
||||
/** rx buffers */
|
||||
ec_bufT rxbuf[EC_MAXBUF];
|
||||
/** rx buffer status */
|
||||
int rxbufstat[EC_MAXBUF];
|
||||
/** rx MAC source address */
|
||||
int rxsa[EC_MAXBUF];
|
||||
/** temporary rx buffer */
|
||||
ec_bufT tempinbuf;
|
||||
/** temporary rx buffer status */
|
||||
int tempinbufs;
|
||||
/** transmit buffers */
|
||||
ec_bufT txbuf[EC_MAXBUF];
|
||||
/** transmit buffer lengths */
|
||||
int txbuflength[EC_MAXBUF];
|
||||
/** temporary tx buffer */
|
||||
ec_bufT txbuf2;
|
||||
/** temporary tx buffer length */
|
||||
int txbuflength2;
|
||||
/** last used frame index */
|
||||
uint8 lastidx;
|
||||
/** current redundancy state */
|
||||
int redstate;
|
||||
/** pointer to redundancy port and buffers */
|
||||
ecx_redportt *redport;
|
||||
|
||||
/** Device id in the device pool */
|
||||
int dev_id;
|
||||
/** Device id in the device pool */
|
||||
int dev_id;
|
||||
|
||||
// TODO: add mutex support
|
||||
// TODO: add mutex support
|
||||
} ecx_portt;
|
||||
|
||||
extern const uint16 priMAC[3];
|
||||
@@ -97,7 +96,7 @@ uint8 ecx_getindex(ecx_portt *port);
|
||||
int ecx_outframe(ecx_portt *port, uint8 idx, int sock);
|
||||
int ecx_outframe_red(ecx_portt *port, uint8 idx);
|
||||
int ecx_waitinframe(ecx_portt *port, uint8 idx, int timeout);
|
||||
int ecx_srconfirm(ecx_portt *port, uint8 idx,int timeout);
|
||||
int ecx_srconfirm(ecx_portt *port, uint8 idx, int timeout);
|
||||
|
||||
int ecx_inframe(ecx_portt *port, uint8 idx, int stacknumber);
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#define __ntohs(x) be16toh(x)
|
||||
#endif
|
||||
|
||||
ec_adaptert adapters [DEVS_MAX_NB];
|
||||
ec_adaptert adapters[DEVS_MAX_NB];
|
||||
|
||||
/**
|
||||
* Host to Network byte order (i.e. to big endian).
|
||||
@@ -31,8 +31,8 @@ ec_adaptert adapters [DEVS_MAX_NB];
|
||||
*/
|
||||
inline uint16 oshw_htons(uint16 host)
|
||||
{
|
||||
// __htons() is provided by the bare-metal x86 compiler
|
||||
return __htons(host);
|
||||
// __htons() is provided by the bare-metal x86 compiler
|
||||
return __htons(host);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -43,29 +43,32 @@ inline uint16 oshw_htons(uint16 host)
|
||||
*/
|
||||
inline uint16 oshw_ntohs(uint16 network)
|
||||
{
|
||||
// __ntohs() is provided by the bare-metal x86 compiler
|
||||
return __ntohs(network);
|
||||
// __ntohs() is provided by the bare-metal x86 compiler
|
||||
return __ntohs(network);
|
||||
}
|
||||
|
||||
/** Create list over available network adapters.
|
||||
* @return First element in linked list of adapters
|
||||
*/
|
||||
ec_adaptert* oshw_find_adapters(void)
|
||||
ec_adaptert *oshw_find_adapters(void)
|
||||
{
|
||||
ec_adaptert *ret = NULL;
|
||||
if (eth_discover_devices() >= 0) {
|
||||
for (int i = 0;; ++i) {
|
||||
struct eth_device *dev = eth_get_device(i);
|
||||
if (dev == NULL) {
|
||||
adapters[i-1].next = NULL;
|
||||
break;
|
||||
}
|
||||
strncpy(adapters[i].name, dev->name, MAX_DEVICE_NAME);
|
||||
adapters[i].next = &adapters[i+1];
|
||||
}
|
||||
ret = &(adapters[0]);
|
||||
}
|
||||
return ret;
|
||||
ec_adaptert *ret = NULL;
|
||||
if (eth_discover_devices() >= 0)
|
||||
{
|
||||
for (int i = 0;; ++i)
|
||||
{
|
||||
struct eth_device *dev = eth_get_device(i);
|
||||
if (dev == NULL)
|
||||
{
|
||||
adapters[i - 1].next = NULL;
|
||||
break;
|
||||
}
|
||||
strncpy(adapters[i].name, dev->name, MAX_DEVICE_NAME);
|
||||
adapters[i].next = &adapters[i + 1];
|
||||
}
|
||||
ret = &(adapters[0]);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/** Free memory allocated memory used by adapter collection.
|
||||
@@ -77,4 +80,3 @@ void oshw_free_adapters(ec_adaptert *adapter)
|
||||
}
|
||||
|
||||
extern int ec_slavecount;
|
||||
|
||||
|
||||
@@ -21,8 +21,8 @@ extern "C" {
|
||||
|
||||
uint16 oshw_htons(uint16 hostshort);
|
||||
uint16 oshw_ntohs(uint16 networkshort);
|
||||
ec_adaptert* oshw_find_adapters(void);
|
||||
void oshw_free_adapters(ec_adaptert * adapter);
|
||||
ec_adaptert *oshw_find_adapters(void);
|
||||
void oshw_free_adapters(ec_adaptert *adapter);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -50,29 +50,28 @@ enum
|
||||
ECT_RED_DOUBLE
|
||||
};
|
||||
|
||||
|
||||
/** Primary source MAC address used for EtherCAT.
|
||||
* This address is not the MAC address used from the NIC.
|
||||
* EtherCAT does not care about MAC addressing, but it is used here to
|
||||
* differentiate the route the packet traverses through the EtherCAT
|
||||
* segment. This is needed to find out the packet flow in redundant
|
||||
* configurations. */
|
||||
const uint16 priMAC[3] = { 0x0101, 0x0101, 0x0101 };
|
||||
const uint16 priMAC[3] = {0x0101, 0x0101, 0x0101};
|
||||
/** Secondary source MAC address used for EtherCAT. */
|
||||
const uint16 secMAC[3] = { 0x0404, 0x0404, 0x0404 };
|
||||
const uint16 secMAC[3] = {0x0404, 0x0404, 0x0404};
|
||||
|
||||
/** second MAC word is used for identification */
|
||||
#define RX_PRIM priMAC[1]
|
||||
#define RX_PRIM priMAC[1]
|
||||
/** second MAC word is used for identification */
|
||||
#define RX_SEC secMAC[1]
|
||||
#define RX_SEC secMAC[1]
|
||||
|
||||
#define ECAT_PRINT_INFO printf
|
||||
#define ECAT_PRINT_WARN printf
|
||||
#define ECAT_PRINT_ERROR printf
|
||||
#define ECAT_PRINT_INFO printf
|
||||
#define ECAT_PRINT_WARN printf
|
||||
#define ECAT_PRINT_ERROR printf
|
||||
|
||||
/* HPE port settings */
|
||||
const unsigned long interrupt_mode = NO_INTERRUPT;
|
||||
const unsigned long phy_settings = SPEED_100 | DUPLEX_FULL;
|
||||
const unsigned long phy_settings = SPEED_100 | DUPLEX_FULL;
|
||||
|
||||
/** Basic setup to connect NIC to socket.
|
||||
* @param[in] ifname = Name of NIC device, f.e. "eth0"
|
||||
@@ -88,19 +87,26 @@ int ecx_setupnic(ecx_portt *port, const char *ifname, int secondary)
|
||||
int i;
|
||||
int dontWaitForLink = 0;
|
||||
int result = 1;
|
||||
HPE_CONFIG_OPTIONS conf = { 0, 0, NULL};
|
||||
HPE_CONFIG_OPTIONS conf = {0, 0, NULL};
|
||||
|
||||
status = hpeOpen(ifname, phy_settings, interrupt_mode, &(port->handle));
|
||||
if (status != E_OK)
|
||||
{
|
||||
ECAT_PRINT_ERROR("hpeOpen failed with status %04x ", status);
|
||||
if(status == E_EXIST) ECAT_PRINT_ERROR("E_EXIST\n");
|
||||
else if(status == E_STATE) ECAT_PRINT_ERROR("E_STATE\n");
|
||||
else if(status == E_PARAM) ECAT_PRINT_ERROR("E_PARAM\n");
|
||||
else if(status == E_INVALID_ADDR) ECAT_PRINT_ERROR("E_INVALID_ADDR\n");
|
||||
else if(status == E_IO) ECAT_PRINT_ERROR("E_IO\n");
|
||||
else if(status == E_TIME) ECAT_PRINT_ERROR("E_TIME\n");
|
||||
else ECAT_PRINT_ERROR("UNKNOWN\n");
|
||||
if (status == E_EXIST)
|
||||
ECAT_PRINT_ERROR("E_EXIST\n");
|
||||
else if (status == E_STATE)
|
||||
ECAT_PRINT_ERROR("E_STATE\n");
|
||||
else if (status == E_PARAM)
|
||||
ECAT_PRINT_ERROR("E_PARAM\n");
|
||||
else if (status == E_INVALID_ADDR)
|
||||
ECAT_PRINT_ERROR("E_INVALID_ADDR\n");
|
||||
else if (status == E_IO)
|
||||
ECAT_PRINT_ERROR("E_IO\n");
|
||||
else if (status == E_TIME)
|
||||
ECAT_PRINT_ERROR("E_TIME\n");
|
||||
else
|
||||
ECAT_PRINT_ERROR("UNKNOWN\n");
|
||||
result = 0;
|
||||
goto end;
|
||||
}
|
||||
@@ -119,28 +125,29 @@ int ecx_setupnic(ecx_portt *port, const char *ifname, int secondary)
|
||||
time(&now);
|
||||
do
|
||||
{
|
||||
status = hpeGetMediaStatus(port->handle, &mstat);
|
||||
if (status != E_OK)
|
||||
{
|
||||
ECAT_PRINT_ERROR("hpeGetMediaStatus failed with status %04x\n", status);
|
||||
result = 0;
|
||||
goto end;
|
||||
}
|
||||
if (mstat.media_speed == SPEED_NONE)
|
||||
{
|
||||
RtSleepEx(1000);
|
||||
time(&t);
|
||||
}
|
||||
} while (mstat.media_speed == SPEED_NONE && t < (now+10));
|
||||
status = hpeGetMediaStatus(port->handle, &mstat);
|
||||
if (status != E_OK)
|
||||
{
|
||||
ECAT_PRINT_ERROR("hpeGetMediaStatus failed with status %04x\n", status);
|
||||
result = 0;
|
||||
goto end;
|
||||
}
|
||||
if (mstat.media_speed == SPEED_NONE)
|
||||
{
|
||||
RtSleepEx(1000);
|
||||
time(&t);
|
||||
}
|
||||
} while (mstat.media_speed == SPEED_NONE && t < (now + 10));
|
||||
|
||||
if (((mstat.media_speed & phy_settings) == 0) || ((mstat.media_duplex & phy_settings) == 0)) {
|
||||
if (((mstat.media_speed & phy_settings) == 0) || ((mstat.media_duplex & phy_settings) == 0))
|
||||
{
|
||||
ECAT_PRINT_ERROR("Media not connected as requested: speed=%u, duplex=%u\n",
|
||||
mstat.media_speed, mstat.media_duplex);
|
||||
mstat.media_speed, mstat.media_duplex);
|
||||
result = 0;
|
||||
goto end;
|
||||
}
|
||||
|
||||
status= hpeGetMacAddress(port->handle, mac);
|
||||
status = hpeGetMacAddress(port->handle, mac);
|
||||
if (status != E_OK)
|
||||
{
|
||||
ECAT_PRINT_ERROR("hpeGetMacAddress failed with status %04x\n", status);
|
||||
@@ -149,7 +156,7 @@ int ecx_setupnic(ecx_portt *port, const char *ifname, int secondary)
|
||||
}
|
||||
|
||||
/* allocate 2 receive buffers and attach them */
|
||||
status = hpeAllocateReceiveBufferSet(port->handle, &(port->rx_buffers), EC_MAXBUF, EC_BUFSIZE);
|
||||
status = hpeAllocateReceiveBufferSet(port->handle, &(port->rx_buffers), EC_MAXBUF, EC_BUFSIZE);
|
||||
if (status != E_OK)
|
||||
{
|
||||
ECAT_PRINT_ERROR("hpeAllocateReceiveBufferSet failed with status %04x\n", status);
|
||||
@@ -178,16 +185,16 @@ int ecx_setupnic(ecx_portt *port, const char *ifname, int secondary)
|
||||
{
|
||||
port->redstate = ECT_RED_NONE;
|
||||
/* Init regions */
|
||||
port->getindex_region = CreateRtRegion (PRIORITY_QUEUING);
|
||||
port->rx_region = CreateRtRegion (PRIORITY_QUEUING);
|
||||
port->tx_region = CreateRtRegion (PRIORITY_QUEUING);
|
||||
port->getindex_region = CreateRtRegion(PRIORITY_QUEUING);
|
||||
port->rx_region = CreateRtRegion(PRIORITY_QUEUING);
|
||||
port->tx_region = CreateRtRegion(PRIORITY_QUEUING);
|
||||
port->lastidx = 0;
|
||||
port->stack.txbuf = &(port->txbuf);
|
||||
port->stack.txbuf = &(port->txbuf);
|
||||
port->stack.txbuflength = &(port->txbuflength);
|
||||
port->stack.tempbuf = &(port->tempinbuf);
|
||||
port->stack.rxbuf = &(port->rxbuf);
|
||||
port->stack.rxbufstat = &(port->rxbufstat);
|
||||
port->stack.rxsa = &(port->rxsa);
|
||||
port->stack.tempbuf = &(port->tempinbuf);
|
||||
port->stack.rxbuf = &(port->rxbuf);
|
||||
port->stack.rxbufstat = &(port->rxbufstat);
|
||||
port->stack.rxsa = &(port->rxsa);
|
||||
}
|
||||
|
||||
/* setup ethernet headers in tx buffers so we don't have to repeat it */
|
||||
@@ -223,7 +230,7 @@ int ecx_closenic(ecx_portt *port)
|
||||
for (i = 0; i < EC_MAXBUF; i++)
|
||||
{
|
||||
FreeRtMemory(port->tx_buffers[i]);
|
||||
port->tx_buffers[i] = NULL;
|
||||
port->tx_buffers[i] = NULL;
|
||||
}
|
||||
}
|
||||
if (port->rx_buffers)
|
||||
@@ -231,7 +238,7 @@ int ecx_closenic(ecx_portt *port)
|
||||
hpeFreeReceiveBufferSet(port->handle, &(port->rx_buffers));
|
||||
}
|
||||
|
||||
status= hpeClose(port->handle);
|
||||
status = hpeClose(port->handle);
|
||||
if (status != E_OK)
|
||||
{
|
||||
ECAT_PRINT_ERROR("hpeClose failed with status %04x\n", status);
|
||||
@@ -285,7 +292,7 @@ uint8 ecx_getindex(ecx_portt *port)
|
||||
}
|
||||
}
|
||||
port->rxbufstat[idx] = EC_BUF_ALLOC;
|
||||
if ( port->redstate != ECT_RED_NONE)
|
||||
if (port->redstate != ECT_RED_NONE)
|
||||
{
|
||||
port->redport->rxbufstat[idx] = EC_BUF_ALLOC;
|
||||
}
|
||||
@@ -338,23 +345,23 @@ int ecx_outframe(ecx_portt *port, uint8 idx, int stacknumber)
|
||||
// wait for transmit to complete
|
||||
do
|
||||
{
|
||||
result = hpeGetTransmitterState(port->handle, &txstate) == E_OK && txstate == HPE_TXBUSY;
|
||||
result = hpeGetTransmitterState(port->handle, &txstate) == E_OK && txstate == HPE_TXBUSY;
|
||||
} while (result && retries-- > 0);
|
||||
|
||||
if (result)
|
||||
{
|
||||
result = -1;
|
||||
goto end;
|
||||
result = -1;
|
||||
goto end;
|
||||
}
|
||||
|
||||
log_RT_event('S',(WORD)2);
|
||||
log_RT_event('S', (WORD)2);
|
||||
status = hpeAttachTransmitBufferSet(port->handle, port->tx_buffers[idx]);
|
||||
if (status != E_OK)
|
||||
{
|
||||
result = -2;
|
||||
goto end;
|
||||
}
|
||||
log_RT_event('S',(WORD)3);
|
||||
log_RT_event('S', (WORD)3);
|
||||
|
||||
(*stack->rxbufstat)[idx] = EC_BUF_TX;
|
||||
status = hpeStartTransmitter(port->handle);
|
||||
@@ -365,7 +372,7 @@ int ecx_outframe(ecx_portt *port, uint8 idx, int stacknumber)
|
||||
goto end;
|
||||
}
|
||||
|
||||
log_RT_event('S',(WORD)4);
|
||||
log_RT_event('S', (WORD)4);
|
||||
result = lp;
|
||||
|
||||
end:
|
||||
@@ -393,15 +400,15 @@ int ecx_outframe_red(ecx_portt *port, uint8 idx)
|
||||
{
|
||||
ehp = (ec_etherheadert *)&(port->txbuf2);
|
||||
/* use dummy frame for secondary socket transmit (BRD) */
|
||||
datagramP = (ec_comt*)&(port->txbuf2)[ETH_HEADERSIZE];
|
||||
datagramP = (ec_comt *)&(port->txbuf2)[ETH_HEADERSIZE];
|
||||
/* write index to frame */
|
||||
datagramP->index = idx;
|
||||
/* rewrite MAC source address 1 to secondary */
|
||||
ehp->sa1 = oshw_htons(secMAC[1]);
|
||||
/* transmit over secondary socket */
|
||||
//send(sockhandle2, &ec_txbuf2, ec_txbuflength2 , 0);
|
||||
// OBS! redundant not ACTIVE for BFIN, just added to compile
|
||||
//ASSERT (0);
|
||||
// send(sockhandle2, &ec_txbuf2, ec_txbuflength2 , 0);
|
||||
// OBS! redundant not ACTIVE for BFIN, just added to compile
|
||||
// ASSERT (0);
|
||||
hpeAttachTransmitBufferSet(port->redport->handle, port->tx_buffers[idx]);
|
||||
port->redport->rxbufstat[idx] = EC_BUF_TX;
|
||||
status = hpeStartTransmitter(port->redport->handle);
|
||||
@@ -434,17 +441,17 @@ static int ecx_recvpkt(ecx_portt *port, int stacknumber)
|
||||
stack = &(port->redport->stack);
|
||||
}
|
||||
|
||||
log_RT_event('R',(WORD)2);
|
||||
log_RT_event('R', (WORD)2);
|
||||
|
||||
status = hpeGetReceiveBuffer(port->handle, &rxbuffer);
|
||||
if (status == E_OK)
|
||||
{
|
||||
memcpy(stack->tempbuf,rxbuffer->ptr, rxbuffer->used);
|
||||
bytesrx = rxbuffer->used;
|
||||
port->tempinbufs = bytesrx;
|
||||
// TODO case no interrupt
|
||||
memcpy(stack->tempbuf, rxbuffer->ptr, rxbuffer->used);
|
||||
bytesrx = rxbuffer->used;
|
||||
port->tempinbufs = bytesrx;
|
||||
// TODO case no interrupt
|
||||
}
|
||||
log_RT_event('R',(WORD)3);
|
||||
log_RT_event('R', (WORD)3);
|
||||
|
||||
return (bytesrx > 0);
|
||||
}
|
||||
@@ -466,9 +473,9 @@ static int ecx_recvpkt(ecx_portt *port, int stacknumber)
|
||||
*/
|
||||
int ecx_inframe(ecx_portt *port, uint8 idx, int stacknumber)
|
||||
{
|
||||
uint16 l;
|
||||
int rval;
|
||||
uint8 idxf;
|
||||
uint16 l;
|
||||
int rval;
|
||||
uint8 idxf;
|
||||
ec_etherheadert *ehp;
|
||||
ec_comt *ecp;
|
||||
ec_stackT *stack;
|
||||
@@ -486,7 +493,7 @@ int ecx_inframe(ecx_portt *port, uint8 idx, int stacknumber)
|
||||
rval = EC_NOFRAME;
|
||||
rxbuf = &(*stack->rxbuf)[idx];
|
||||
/* check if requested index is already in buffer ? */
|
||||
if ((idx < EC_MAXBUF) && ( (*stack->rxbufstat)[idx] == EC_BUF_RCVD))
|
||||
if ((idx < EC_MAXBUF) && ((*stack->rxbufstat)[idx] == EC_BUF_RCVD))
|
||||
{
|
||||
l = (*rxbuf)[0] + ((uint16)((*rxbuf)[1] & 0x0f) << 8);
|
||||
/* return WKC */
|
||||
@@ -501,11 +508,11 @@ int ecx_inframe(ecx_portt *port, uint8 idx, int stacknumber)
|
||||
if (ecx_recvpkt(port, stacknumber))
|
||||
{
|
||||
rval = EC_OTHERFRAME;
|
||||
ehp = (ec_etherheadert*)(stack->tempbuf);
|
||||
ehp = (ec_etherheadert *)(stack->tempbuf);
|
||||
/* check if it is an EtherCAT frame */
|
||||
if (ehp->etype == oshw_htons(ETH_P_ECAT))
|
||||
{
|
||||
ecp =(ec_comt*)(&(*stack->tempbuf)[ETH_HEADERSIZE]);
|
||||
ecp = (ec_comt *)(&(*stack->tempbuf)[ETH_HEADERSIZE]);
|
||||
l = etohs(ecp->elength) & 0x0fff;
|
||||
idxf = ecp->index;
|
||||
/* found index equals requested index ? */
|
||||
@@ -556,7 +563,7 @@ int ecx_inframe(ecx_portt *port, uint8 idx, int stacknumber)
|
||||
static int ecx_waitinframe_red(ecx_portt *port, uint8 idx, osal_timert *timer)
|
||||
{
|
||||
osal_timert timer2;
|
||||
int wkc = EC_NOFRAME;
|
||||
int wkc = EC_NOFRAME;
|
||||
int wkc2 = EC_NOFRAME;
|
||||
int primrx, secrx;
|
||||
|
||||
@@ -569,7 +576,7 @@ static int ecx_waitinframe_red(ecx_portt *port, uint8 idx, osal_timert *timer)
|
||||
{
|
||||
/* only read frame if not already in */
|
||||
if (wkc <= EC_NOFRAME)
|
||||
wkc = ecx_inframe(port, idx, 0);
|
||||
wkc = ecx_inframe(port, idx, 0);
|
||||
/* only try secondary if in redundant mode */
|
||||
if (port->redstate != ECT_RED_NONE)
|
||||
{
|
||||
@@ -579,7 +586,7 @@ static int ecx_waitinframe_red(ecx_portt *port, uint8 idx, osal_timert *timer)
|
||||
wkc2 = ecx_inframe(port, idx, 1);
|
||||
}
|
||||
}
|
||||
/* wait for both frames to arrive or timeout */
|
||||
/* wait for both frames to arrive or timeout */
|
||||
} while (((wkc <= EC_NOFRAME) || (wkc2 <= EC_NOFRAME)) && !osal_timer_is_expired(timer));
|
||||
/* only do redundant functions when in redundant mode */
|
||||
if (port->redstate != ECT_RED_NONE)
|
||||
@@ -593,7 +600,7 @@ static int ecx_waitinframe_red(ecx_portt *port, uint8 idx, osal_timert *timer)
|
||||
|
||||
/* primary socket got secondary frame and secondary socket got primary frame */
|
||||
/* normal situation in redundant mode */
|
||||
if ( ((primrx == RX_SEC) && (secrx == RX_PRIM)) )
|
||||
if (((primrx == RX_SEC) && (secrx == RX_PRIM)))
|
||||
{
|
||||
/* copy secondary buffer to primary */
|
||||
memcpy(&(port->rxbuf[idx]), &(port->redport->rxbuf[idx]), port->txbuflength[idx] - ETH_HEADERSIZE);
|
||||
@@ -601,20 +608,20 @@ static int ecx_waitinframe_red(ecx_portt *port, uint8 idx, osal_timert *timer)
|
||||
}
|
||||
/* primary socket got nothing or primary frame, and secondary socket got secondary frame */
|
||||
/* we need to resend TX packet */
|
||||
if ( ((primrx == 0) && (secrx == RX_SEC)) ||
|
||||
((primrx == RX_PRIM) && (secrx == RX_SEC)) )
|
||||
if (((primrx == 0) && (secrx == RX_SEC)) ||
|
||||
((primrx == RX_PRIM) && (secrx == RX_SEC)))
|
||||
{
|
||||
/* If both primary and secondary have partial connection retransmit the primary received
|
||||
* frame over the secondary socket. The result from the secondary received frame is a combined
|
||||
* frame that traversed all slaves in standard order. */
|
||||
if ( (primrx == RX_PRIM) && (secrx == RX_SEC) )
|
||||
if ((primrx == RX_PRIM) && (secrx == RX_SEC))
|
||||
{
|
||||
/* copy primary rx to tx buffer */
|
||||
memcpy(&(port->txbuf[idx][ETH_HEADERSIZE]), &(port->rxbuf[idx]), port->txbuflength[idx] - ETH_HEADERSIZE);
|
||||
}
|
||||
osal_timer_start (&timer2, EC_TIMEOUTRET);
|
||||
osal_timer_start(&timer2, EC_TIMEOUTRET);
|
||||
/* resend secondary tx */
|
||||
ecx_outframe(port,idx,1);
|
||||
ecx_outframe(port, idx, 1);
|
||||
do
|
||||
{
|
||||
/* retrieve frame */
|
||||
@@ -650,13 +657,13 @@ int ecx_waitinframe(ecx_portt *port, uint8 idx, int timeout)
|
||||
/* Allow us to consume MAX buffer number of frames */
|
||||
do
|
||||
{
|
||||
wkc = ecx_inframe(port, idx, 0);
|
||||
wkc = ecx_inframe(port, idx, 0);
|
||||
loop_cnt++;
|
||||
} while (wkc <= EC_NOFRAME && (loop_cnt <= EC_MAXBUF));
|
||||
}
|
||||
else
|
||||
{
|
||||
osal_timer_start (&timer, timeout);
|
||||
osal_timer_start(&timer, timeout);
|
||||
wkc = ecx_waitinframe_red(port, idx, &timer);
|
||||
}
|
||||
|
||||
@@ -679,7 +686,7 @@ int ecx_srconfirm(ecx_portt *port, uint8 idx, int timeout)
|
||||
int wkc = EC_NOFRAME;
|
||||
osal_timert timer1;
|
||||
|
||||
osal_timer_start (&timer1, timeout);
|
||||
osal_timer_start(&timer1, timeout);
|
||||
/* tx frame on primary and if in redundant mode a dummy on secondary */
|
||||
ecx_outframe_red(port, idx);
|
||||
wkc = ecx_waitinframe_red(port, idx, &timer1);
|
||||
|
||||
@@ -21,24 +21,24 @@
|
||||
typedef struct
|
||||
{
|
||||
/** socket connection used */
|
||||
int *sock;
|
||||
int *sock;
|
||||
/** tx buffer */
|
||||
ec_bufT (*txbuf)[EC_MAXBUF];
|
||||
ec_bufT (*txbuf)[EC_MAXBUF];
|
||||
/** tx buffer lengths */
|
||||
int (*txbuflength)[EC_MAXBUF];
|
||||
int (*txbuflength)[EC_MAXBUF];
|
||||
/** temporary receive buffer */
|
||||
ec_bufT *tempbuf;
|
||||
ec_bufT *tempbuf;
|
||||
/** rx buffers */
|
||||
ec_bufT (*rxbuf)[EC_MAXBUF];
|
||||
ec_bufT (*rxbuf)[EC_MAXBUF];
|
||||
/** rx buffer status fields */
|
||||
int (*rxbufstat)[EC_MAXBUF];
|
||||
int (*rxbufstat)[EC_MAXBUF];
|
||||
/** received MAC source address (middle word) */
|
||||
int (*rxsa)[EC_MAXBUF];
|
||||
int (*rxsa)[EC_MAXBUF];
|
||||
} ec_stackT;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
ec_stackT stack;
|
||||
ec_stackT stack;
|
||||
/** rx buffers */
|
||||
ec_bufT rxbuf[EC_MAXBUF];
|
||||
/** rx buffer status */
|
||||
@@ -48,43 +48,43 @@ typedef struct
|
||||
/** temporary rx buffer */
|
||||
ec_bufT tempinbuf;
|
||||
/* Intime */
|
||||
HPEHANDLE handle;
|
||||
HPEHANDLE handle;
|
||||
HPERXBUFFERSET *rx_buffers;
|
||||
HPETXBUFFERSET *tx_buffers[EC_MAXBUF];
|
||||
} ecx_redportt;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
ec_stackT stack;
|
||||
ec_stackT stack;
|
||||
/** rx buffers */
|
||||
ec_bufT rxbuf[EC_MAXBUF];
|
||||
ec_bufT rxbuf[EC_MAXBUF];
|
||||
/** rx buffer status */
|
||||
int rxbufstat[EC_MAXBUF];
|
||||
int rxbufstat[EC_MAXBUF];
|
||||
/** rx MAC source address */
|
||||
int rxsa[EC_MAXBUF];
|
||||
int rxsa[EC_MAXBUF];
|
||||
/** temporary rx buffer */
|
||||
ec_bufT tempinbuf;
|
||||
ec_bufT tempinbuf;
|
||||
/** temporary rx buffer status */
|
||||
int tempinbufs;
|
||||
int tempinbufs;
|
||||
/** transmit buffers */
|
||||
ec_bufT txbuf[EC_MAXBUF];
|
||||
ec_bufT txbuf[EC_MAXBUF];
|
||||
/** transmit buffer lengths */
|
||||
int txbuflength[EC_MAXBUF];
|
||||
int txbuflength[EC_MAXBUF];
|
||||
/** temporary tx buffer */
|
||||
ec_bufT txbuf2;
|
||||
ec_bufT txbuf2;
|
||||
/** temporary tx buffer length */
|
||||
int txbuflength2;
|
||||
int txbuflength2;
|
||||
/** last used frame index */
|
||||
uint8 lastidx;
|
||||
uint8 lastidx;
|
||||
/** current redundancy state */
|
||||
int redstate;
|
||||
int redstate;
|
||||
/** pointer to redundancy port and buffers */
|
||||
ecx_redportt *redport;
|
||||
RTHANDLE getindex_region;
|
||||
RTHANDLE tx_region;
|
||||
RTHANDLE rx_region;
|
||||
ecx_redportt *redport;
|
||||
RTHANDLE getindex_region;
|
||||
RTHANDLE tx_region;
|
||||
RTHANDLE rx_region;
|
||||
/* Intime */
|
||||
HPEHANDLE handle;
|
||||
HPEHANDLE handle;
|
||||
HPERXBUFFERSET *rx_buffers;
|
||||
HPETXBUFFERSET *tx_buffers[EC_MAXBUF];
|
||||
} ecx_portt;
|
||||
@@ -92,10 +92,10 @@ typedef struct
|
||||
extern const uint16 priMAC[3];
|
||||
extern const uint16 secMAC[3];
|
||||
|
||||
//extern ecx_portt ecx_port;
|
||||
//extern ecx_redportt ecx_redport;
|
||||
// extern ecx_portt ecx_port;
|
||||
// extern ecx_redportt ecx_redport;
|
||||
|
||||
int ec_setupnic(const char * ifname, int secondary);
|
||||
int ec_setupnic(const char *ifname, int secondary);
|
||||
int ec_closenic(void);
|
||||
void ec_setupheader(void *p);
|
||||
void ec_setbufstat(uint8 idx, int bufstat);
|
||||
@@ -103,15 +103,15 @@ uint8 ec_getindex(void);
|
||||
int ec_outframe(uint8 idx, int sock);
|
||||
int ec_outframe_red(uint8 idx);
|
||||
int ec_waitinframe(uint8 idx, int timeout);
|
||||
int ec_srconfirm(uint8 idx,int timeout);
|
||||
int ec_srconfirm(uint8 idx, int timeout);
|
||||
|
||||
int ecx_setupnic(ecx_portt *port, const char * ifname, int secondary);
|
||||
int ecx_setupnic(ecx_portt *port, const char *ifname, int secondary);
|
||||
int ecx_closenic(ecx_portt *port);
|
||||
void ecx_setbufstat(ecx_portt *port, uint8 idx, int bufstat);
|
||||
uint8 ecx_getindex(ecx_portt *port);
|
||||
int ecx_outframe(ecx_portt *port, uint8 idx, int sock);
|
||||
int ecx_outframe_red(ecx_portt *port, uint8 idx);
|
||||
int ecx_waitinframe(ecx_portt *port, uint8 idx, int timeout);
|
||||
int ecx_srconfirm(ecx_portt *port, uint8 idx,int timeout);
|
||||
int ecx_srconfirm(ecx_portt *port, uint8 idx, int timeout);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -13,9 +13,9 @@
|
||||
* Note that Ethercat uses little endian byte order, except for the Ethernet
|
||||
* header which is big endian as usual.
|
||||
*/
|
||||
uint16 oshw_htons (uint16 host)
|
||||
uint16 oshw_htons(uint16 host)
|
||||
{
|
||||
uint16 network = htons (host);
|
||||
uint16 network = htons(host);
|
||||
return network;
|
||||
}
|
||||
|
||||
@@ -25,16 +25,16 @@ uint16 oshw_htons (uint16 host)
|
||||
* Note that Ethercat uses little endian byte order, except for the Ethernet
|
||||
* header which is big endian as usual.
|
||||
*/
|
||||
uint16 oshw_ntohs (uint16 network)
|
||||
uint16 oshw_ntohs(uint16 network)
|
||||
{
|
||||
uint16 host = ntohs (network);
|
||||
uint16 host = ntohs(network);
|
||||
return host;
|
||||
}
|
||||
|
||||
/* Create list over available network adapters.
|
||||
* @return First element in linked list of adapters
|
||||
*/
|
||||
ec_adaptert * oshw_find_adapters (void)
|
||||
ec_adaptert *oshw_find_adapters(void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
@@ -43,7 +43,6 @@ ec_adaptert * oshw_find_adapters (void)
|
||||
* @param[in] adapter = First element in linked list of adapters
|
||||
* EC_NOFRAME.
|
||||
*/
|
||||
void oshw_free_adapters (ec_adaptert * adapter)
|
||||
void oshw_free_adapters(ec_adaptert *adapter)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -19,10 +19,10 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
uint16 oshw_htons (uint16 hostshort);
|
||||
uint16 oshw_ntohs (uint16 networkshort);
|
||||
ec_adaptert * oshw_find_adapters (void);
|
||||
void oshw_free_adapters (ec_adaptert * adapter);
|
||||
uint16 oshw_htons(uint16 hostshort);
|
||||
uint16 oshw_ntohs(uint16 networkshort);
|
||||
ec_adaptert *oshw_find_adapters(void);
|
||||
void oshw_free_adapters(ec_adaptert *adapter);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -59,26 +59,25 @@ enum
|
||||
ECT_RED_DOUBLE
|
||||
};
|
||||
|
||||
|
||||
/** Primary source MAC address used for EtherCAT.
|
||||
* This address is not the MAC address used from the NIC.
|
||||
* EtherCAT does not care about MAC addressing, but it is used here to
|
||||
* differentiate the route the packet traverses through the EtherCAT
|
||||
* segment. This is needed to find out the packet flow in redundant
|
||||
* configurations. */
|
||||
const uint16 priMAC[3] = { 0x0101, 0x0101, 0x0101 };
|
||||
const uint16 priMAC[3] = {0x0101, 0x0101, 0x0101};
|
||||
/** Secondary source MAC address used for EtherCAT. */
|
||||
const uint16 secMAC[3] = { 0x0404, 0x0404, 0x0404 };
|
||||
const uint16 secMAC[3] = {0x0404, 0x0404, 0x0404};
|
||||
|
||||
/** second MAC word is used for identification */
|
||||
#define RX_PRIM priMAC[1]
|
||||
/** second MAC word is used for identification */
|
||||
#define RX_SEC secMAC[1]
|
||||
#define RX_SEC secMAC[1]
|
||||
|
||||
static void ecx_clear_rxbufstat(int *rxbufstat)
|
||||
{
|
||||
int i;
|
||||
for(i = 0; i < EC_MAXBUF; i++)
|
||||
for (i = 0; i < EC_MAXBUF; i++)
|
||||
{
|
||||
rxbufstat[i] = EC_BUF_EMPTY;
|
||||
}
|
||||
@@ -94,7 +93,7 @@ int ecx_setupnic(ecx_portt *port, const char *ifname, int secondary)
|
||||
{
|
||||
int i;
|
||||
int r, rval, ifindex;
|
||||
// struct timeval timeout;
|
||||
// struct timeval timeout;
|
||||
struct ifreq ifr;
|
||||
struct sockaddr_ll sll;
|
||||
int *psock;
|
||||
@@ -109,14 +108,14 @@ int ecx_setupnic(ecx_portt *port, const char *ifname, int secondary)
|
||||
/* when using secondary socket it is automatically a redundant setup */
|
||||
psock = &(port->redport->sockhandle);
|
||||
*psock = -1;
|
||||
port->redstate = ECT_RED_DOUBLE;
|
||||
port->redport->stack.sock = &(port->redport->sockhandle);
|
||||
port->redport->stack.txbuf = &(port->txbuf);
|
||||
port->redstate = ECT_RED_DOUBLE;
|
||||
port->redport->stack.sock = &(port->redport->sockhandle);
|
||||
port->redport->stack.txbuf = &(port->txbuf);
|
||||
port->redport->stack.txbuflength = &(port->txbuflength);
|
||||
port->redport->stack.tempbuf = &(port->redport->tempinbuf);
|
||||
port->redport->stack.rxbuf = &(port->redport->rxbuf);
|
||||
port->redport->stack.rxbufstat = &(port->redport->rxbufstat);
|
||||
port->redport->stack.rxsa = &(port->redport->rxsa);
|
||||
port->redport->stack.tempbuf = &(port->redport->tempinbuf);
|
||||
port->redport->stack.rxbuf = &(port->redport->rxbuf);
|
||||
port->redport->stack.rxbufstat = &(port->redport->rxbufstat);
|
||||
port->redport->stack.rxsa = &(port->redport->rxsa);
|
||||
ecx_clear_rxbufstat(&(port->redport->rxbufstat[0]));
|
||||
}
|
||||
else
|
||||
@@ -128,35 +127,35 @@ int ecx_setupnic(ecx_portt *port, const char *ifname, int secondary)
|
||||
else
|
||||
{
|
||||
pthread_mutexattr_init(&mutexattr);
|
||||
pthread_mutexattr_setprotocol(&mutexattr , PTHREAD_PRIO_INHERIT);
|
||||
pthread_mutexattr_setprotocol(&mutexattr, PTHREAD_PRIO_INHERIT);
|
||||
pthread_mutex_init(&(port->getindex_mutex), &mutexattr);
|
||||
pthread_mutex_init(&(port->tx_mutex) , &mutexattr);
|
||||
pthread_mutex_init(&(port->rx_mutex) , &mutexattr);
|
||||
port->sockhandle = -1;
|
||||
port->lastidx = 0;
|
||||
port->redstate = ECT_RED_NONE;
|
||||
port->stack.sock = &(port->sockhandle);
|
||||
port->stack.txbuf = &(port->txbuf);
|
||||
pthread_mutex_init(&(port->tx_mutex), &mutexattr);
|
||||
pthread_mutex_init(&(port->rx_mutex), &mutexattr);
|
||||
port->sockhandle = -1;
|
||||
port->lastidx = 0;
|
||||
port->redstate = ECT_RED_NONE;
|
||||
port->stack.sock = &(port->sockhandle);
|
||||
port->stack.txbuf = &(port->txbuf);
|
||||
port->stack.txbuflength = &(port->txbuflength);
|
||||
port->stack.tempbuf = &(port->tempinbuf);
|
||||
port->stack.rxbuf = &(port->rxbuf);
|
||||
port->stack.rxbufstat = &(port->rxbufstat);
|
||||
port->stack.rxsa = &(port->rxsa);
|
||||
port->stack.tempbuf = &(port->tempinbuf);
|
||||
port->stack.rxbuf = &(port->rxbuf);
|
||||
port->stack.rxbufstat = &(port->rxbufstat);
|
||||
port->stack.rxsa = &(port->rxsa);
|
||||
ecx_clear_rxbufstat(&(port->rxbufstat[0]));
|
||||
psock = &(port->sockhandle);
|
||||
}
|
||||
/* we use RAW packet socket, with packet type ETH_P_ECAT */
|
||||
*psock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ECAT));
|
||||
if(*psock < 0)
|
||||
if (*psock < 0)
|
||||
return 0;
|
||||
|
||||
r = 0;
|
||||
/*
|
||||
timeout.tv_sec = 0;
|
||||
timeout.tv_usec = 1;
|
||||
r |= setsockopt(*psock, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout));
|
||||
r |= setsockopt(*psock, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(timeout));
|
||||
*/
|
||||
/*
|
||||
timeout.tv_sec = 0;
|
||||
timeout.tv_usec = 1;
|
||||
r |= setsockopt(*psock, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout));
|
||||
r |= setsockopt(*psock, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(timeout));
|
||||
*/
|
||||
i = 1;
|
||||
r |= setsockopt(*psock, SOL_SOCKET, SO_DONTROUTE, &i, sizeof(i));
|
||||
/* connect socket to NIC by name */
|
||||
@@ -228,7 +227,7 @@ uint8 ecx_getindex(ecx_portt *port)
|
||||
uint8 idx;
|
||||
uint8 cnt;
|
||||
|
||||
pthread_mutex_lock( &(port->getindex_mutex) );
|
||||
pthread_mutex_lock(&(port->getindex_mutex));
|
||||
|
||||
idx = port->lastidx + 1;
|
||||
/* index can't be larger than buffer array */
|
||||
@@ -252,7 +251,7 @@ uint8 ecx_getindex(ecx_portt *port)
|
||||
port->redport->rxbufstat[idx] = EC_BUF_ALLOC;
|
||||
port->lastidx = idx;
|
||||
|
||||
pthread_mutex_unlock( &(port->getindex_mutex) );
|
||||
pthread_mutex_unlock(&(port->getindex_mutex));
|
||||
|
||||
return idx;
|
||||
}
|
||||
@@ -317,21 +316,21 @@ int ecx_outframe_red(ecx_portt *port, uint8 idx)
|
||||
rval = ecx_outframe(port, idx, 0);
|
||||
if (port->redstate != ECT_RED_NONE)
|
||||
{
|
||||
pthread_mutex_lock( &(port->tx_mutex) );
|
||||
pthread_mutex_lock(&(port->tx_mutex));
|
||||
ehp = (ec_etherheadert *)&(port->txbuf2);
|
||||
/* use dummy frame for secondary socket transmit (BRD) */
|
||||
datagramP = (ec_comt*)&(port->txbuf2[ETH_HEADERSIZE]);
|
||||
datagramP = (ec_comt *)&(port->txbuf2[ETH_HEADERSIZE]);
|
||||
/* write index to frame */
|
||||
datagramP->index = idx;
|
||||
/* rewrite MAC source address 1 to secondary */
|
||||
ehp->sa1 = htons(secMAC[1]);
|
||||
/* transmit over secondary socket */
|
||||
port->redport->rxbufstat[idx] = EC_BUF_TX;
|
||||
if (send(port->redport->sockhandle, &(port->txbuf2), port->txbuflength2 , 0) == -1)
|
||||
if (send(port->redport->sockhandle, &(port->txbuf2), port->txbuflength2, 0) == -1)
|
||||
{
|
||||
port->redport->rxbufstat[idx] = EC_BUF_EMPTY;
|
||||
}
|
||||
pthread_mutex_unlock( &(port->tx_mutex) );
|
||||
pthread_mutex_unlock(&(port->tx_mutex));
|
||||
}
|
||||
|
||||
return rval;
|
||||
@@ -380,9 +379,9 @@ static int ecx_recvpkt(ecx_portt *port, int stacknumber)
|
||||
*/
|
||||
int ecx_inframe(ecx_portt *port, uint8 idx, int stacknumber)
|
||||
{
|
||||
uint16 l;
|
||||
int rval;
|
||||
uint8 idxf;
|
||||
uint16 l;
|
||||
int rval;
|
||||
uint8 idxf;
|
||||
ec_etherheadert *ehp;
|
||||
ec_comt *ecp;
|
||||
ec_stackT *stack;
|
||||
@@ -424,12 +423,12 @@ int ecx_inframe(ecx_portt *port, uint8 idx, int stacknumber)
|
||||
else if (ecx_recvpkt(port, stacknumber))
|
||||
{
|
||||
rval = EC_OTHERFRAME;
|
||||
ehp =(ec_etherheadert*)(stack->tempbuf);
|
||||
ehp = (ec_etherheadert *)(stack->tempbuf);
|
||||
/* check if it is an EtherCAT frame */
|
||||
if (ehp->etype == htons(ETH_P_ECAT))
|
||||
{
|
||||
stack->rxcnt++;
|
||||
ecp =(ec_comt*)(&(*stack->tempbuf)[ETH_HEADERSIZE]);
|
||||
ecp = (ec_comt *)(&(*stack->tempbuf)[ETH_HEADERSIZE]);
|
||||
l = etohs(ecp->elength) & 0x0fff;
|
||||
idxf = ecp->index;
|
||||
/* found index equals requested index ? */
|
||||
@@ -463,8 +462,7 @@ int ecx_inframe(ecx_portt *port, uint8 idx, int stacknumber)
|
||||
}
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock( &(port->rx_mutex) );
|
||||
|
||||
pthread_mutex_unlock(&(port->rx_mutex));
|
||||
}
|
||||
|
||||
/* WKC if matching frame found */
|
||||
@@ -486,7 +484,7 @@ int ecx_inframe(ecx_portt *port, uint8 idx, int stacknumber)
|
||||
static int ecx_waitinframe_red(ecx_portt *port, uint8 idx, osal_timert *timer)
|
||||
{
|
||||
osal_timert timer2;
|
||||
int wkc = EC_NOFRAME;
|
||||
int wkc = EC_NOFRAME;
|
||||
int wkc2 = EC_NOFRAME;
|
||||
int primrx, secrx;
|
||||
|
||||
@@ -497,14 +495,14 @@ static int ecx_waitinframe_red(ecx_portt *port, uint8 idx, osal_timert *timer)
|
||||
struct pollfd fds[2];
|
||||
struct pollfd *fdsp;
|
||||
int poll_err = 0;
|
||||
struct timespec timeout_spec = { 0, 0 };
|
||||
struct timespec timeout_spec = {0, 0};
|
||||
timeout_spec.tv_nsec = 50 * 1000;
|
||||
ec_stackT *stack;
|
||||
stack = &(port->stack);
|
||||
fds[0].fd = *stack->sock;
|
||||
fds[0].events = POLLIN;
|
||||
int pollcnt = 1;
|
||||
if(port->redstate != ECT_RED_NONE)
|
||||
if (port->redstate != ECT_RED_NONE)
|
||||
{
|
||||
pollcnt = 2;
|
||||
stack = &(port->redport->stack);
|
||||
@@ -515,11 +513,11 @@ static int ecx_waitinframe_red(ecx_portt *port, uint8 idx, osal_timert *timer)
|
||||
do
|
||||
{
|
||||
poll_err = ppoll(fdsp, pollcnt, &timeout_spec, NULL);
|
||||
if(poll_err >= 0)
|
||||
if (poll_err >= 0)
|
||||
{
|
||||
/* only read frame if not already in */
|
||||
if (wkc <= EC_NOFRAME)
|
||||
wkc = ecx_inframe(port, idx, 0);
|
||||
wkc = ecx_inframe(port, idx, 0);
|
||||
/* only try secondary if in redundant mode */
|
||||
if (port->redstate != ECT_RED_NONE)
|
||||
{
|
||||
@@ -528,7 +526,7 @@ static int ecx_waitinframe_red(ecx_portt *port, uint8 idx, osal_timert *timer)
|
||||
wkc2 = ecx_inframe(port, idx, 1);
|
||||
}
|
||||
}
|
||||
/* wait for both frames to arrive or timeout */
|
||||
/* wait for both frames to arrive or timeout */
|
||||
} while (((wkc <= EC_NOFRAME) || (wkc2 <= EC_NOFRAME)) && !osal_timer_is_expired(timer));
|
||||
/* only do redundant functions when in redundant mode */
|
||||
if (port->redstate != ECT_RED_NONE)
|
||||
@@ -542,7 +540,7 @@ static int ecx_waitinframe_red(ecx_portt *port, uint8 idx, osal_timert *timer)
|
||||
|
||||
/* primary socket got secondary frame and secondary socket got primary frame */
|
||||
/* normal situation in redundant mode */
|
||||
if ( ((primrx == RX_SEC) && (secrx == RX_PRIM)) )
|
||||
if (((primrx == RX_SEC) && (secrx == RX_PRIM)))
|
||||
{
|
||||
/* copy secondary buffer to primary */
|
||||
memcpy(&(port->rxbuf[idx]), &(port->redport->rxbuf[idx]), port->txbuflength[idx] - ETH_HEADERSIZE);
|
||||
@@ -550,18 +548,18 @@ static int ecx_waitinframe_red(ecx_portt *port, uint8 idx, osal_timert *timer)
|
||||
}
|
||||
/* primary socket got nothing or primary frame, and secondary socket got secondary frame */
|
||||
/* we need to resend TX packet */
|
||||
if ( ((primrx == 0) && (secrx == RX_SEC)) ||
|
||||
((primrx == RX_PRIM) && (secrx == RX_SEC)) )
|
||||
if (((primrx == 0) && (secrx == RX_SEC)) ||
|
||||
((primrx == RX_PRIM) && (secrx == RX_SEC)))
|
||||
{
|
||||
/* If both primary and secondary have partial connection retransmit the primary received
|
||||
* frame over the secondary socket. The result from the secondary received frame is a combined
|
||||
* frame that traversed all slaves in standard order. */
|
||||
if ( (primrx == RX_PRIM) && (secrx == RX_SEC) )
|
||||
if ((primrx == RX_PRIM) && (secrx == RX_SEC))
|
||||
{
|
||||
/* copy primary rx to tx buffer */
|
||||
memcpy(&(port->txbuf[idx][ETH_HEADERSIZE]), &(port->rxbuf[idx]), port->txbuflength[idx] - ETH_HEADERSIZE);
|
||||
}
|
||||
osal_timer_start (&timer2, EC_TIMEOUTRET);
|
||||
osal_timer_start(&timer2, EC_TIMEOUTRET);
|
||||
/* resend secondary tx */
|
||||
ecx_outframe(port, idx, 1);
|
||||
do
|
||||
@@ -594,7 +592,7 @@ int ecx_waitinframe(ecx_portt *port, uint8 idx, int timeout)
|
||||
int wkc;
|
||||
osal_timert timer;
|
||||
|
||||
osal_timer_start (&timer, timeout);
|
||||
osal_timer_start(&timer, timeout);
|
||||
wkc = ecx_waitinframe_red(port, idx, &timer);
|
||||
|
||||
return wkc;
|
||||
@@ -617,24 +615,24 @@ int ecx_srconfirm(ecx_portt *port, uint8 idx, int timeout)
|
||||
int wkc = EC_NOFRAME;
|
||||
osal_timert timer1, timer2;
|
||||
|
||||
osal_timer_start (&timer1, timeout);
|
||||
osal_timer_start(&timer1, timeout);
|
||||
do
|
||||
{
|
||||
/* tx frame on primary and if in redundant mode a dummy on secondary */
|
||||
ecx_outframe_red(port, idx);
|
||||
if (timeout < EC_TIMEOUTRET)
|
||||
{
|
||||
osal_timer_start (&timer2, timeout);
|
||||
osal_timer_start(&timer2, timeout);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* normally use partial timeout for rx */
|
||||
osal_timer_start (&timer2, EC_TIMEOUTRET);
|
||||
osal_timer_start(&timer2, EC_TIMEOUTRET);
|
||||
}
|
||||
/* get frame from primary or if in redundant mode possibly from secondary */
|
||||
wkc = ecx_waitinframe_red(port, idx, &timer2);
|
||||
/* wait for answer with WKC>=0 or otherwise retry until timeout */
|
||||
} while ((wkc <= EC_NOFRAME) && !osal_timer_is_expired (&timer1));
|
||||
/* wait for answer with WKC>=0 or otherwise retry until timeout */
|
||||
} while ((wkc <= EC_NOFRAME) && !osal_timer_is_expired(&timer1));
|
||||
|
||||
return wkc;
|
||||
}
|
||||
|
||||
@@ -13,8 +13,7 @@
|
||||
#define _nicdrvh_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <pthread.h>
|
||||
@@ -23,27 +22,27 @@ extern "C"
|
||||
typedef struct
|
||||
{
|
||||
/** socket connection used */
|
||||
int *sock;
|
||||
int *sock;
|
||||
/** tx buffer */
|
||||
ec_bufT (*txbuf)[EC_MAXBUF];
|
||||
ec_bufT (*txbuf)[EC_MAXBUF];
|
||||
/** tx buffer lengths */
|
||||
int (*txbuflength)[EC_MAXBUF];
|
||||
int (*txbuflength)[EC_MAXBUF];
|
||||
/** temporary receive buffer */
|
||||
ec_bufT *tempbuf;
|
||||
ec_bufT *tempbuf;
|
||||
/** rx buffers */
|
||||
ec_bufT (*rxbuf)[EC_MAXBUF];
|
||||
ec_bufT (*rxbuf)[EC_MAXBUF];
|
||||
/** rx buffer status fields */
|
||||
int (*rxbufstat)[EC_MAXBUF];
|
||||
int (*rxbufstat)[EC_MAXBUF];
|
||||
/** received MAC source address (middle word) */
|
||||
int (*rxsa)[EC_MAXBUF];
|
||||
uint64 rxcnt;
|
||||
int (*rxsa)[EC_MAXBUF];
|
||||
uint64 rxcnt;
|
||||
} ec_stackT;
|
||||
|
||||
/** pointer structure to buffers for redundant port */
|
||||
typedef struct
|
||||
{
|
||||
ec_stackT stack;
|
||||
int sockhandle;
|
||||
ec_stackT stack;
|
||||
int sockhandle;
|
||||
/** rx buffers */
|
||||
ec_bufT rxbuf[EC_MAXBUF];
|
||||
/** rx buffer status */
|
||||
@@ -57,8 +56,8 @@ typedef struct
|
||||
/** pointer structure to buffers, vars and mutexes for port instantiation */
|
||||
typedef struct
|
||||
{
|
||||
ec_stackT stack;
|
||||
int sockhandle;
|
||||
ec_stackT stack;
|
||||
int sockhandle;
|
||||
/** rx buffers */
|
||||
ec_bufT rxbuf[EC_MAXBUF];
|
||||
/** rx buffer status */
|
||||
@@ -92,14 +91,14 @@ extern const uint16 priMAC[3];
|
||||
extern const uint16 secMAC[3];
|
||||
|
||||
void ec_setupheader(void *p);
|
||||
int ecx_setupnic(ecx_portt *port, const char * ifname, int secondary);
|
||||
int ecx_setupnic(ecx_portt *port, const char *ifname, int secondary);
|
||||
int ecx_closenic(ecx_portt *port);
|
||||
void ecx_setbufstat(ecx_portt *port, uint8 idx, int bufstat);
|
||||
uint8 ecx_getindex(ecx_portt *port);
|
||||
int ecx_outframe(ecx_portt *port, uint8 idx, int sock);
|
||||
int ecx_outframe_red(ecx_portt *port, uint8 idx);
|
||||
int ecx_waitinframe(ecx_portt *port, uint8 idx, int timeout);
|
||||
int ecx_srconfirm(ecx_portt *port, uint8 idx,int timeout);
|
||||
int ecx_srconfirm(ecx_portt *port, uint8 idx, int timeout);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
*/
|
||||
uint16 oshw_htons(uint16 host)
|
||||
{
|
||||
uint16 network = htons (host);
|
||||
uint16 network = htons(host);
|
||||
return network;
|
||||
}
|
||||
|
||||
@@ -32,28 +32,27 @@ uint16 oshw_htons(uint16 host)
|
||||
*/
|
||||
uint16 oshw_ntohs(uint16 network)
|
||||
{
|
||||
uint16 host = ntohs (network);
|
||||
uint16 host = ntohs(network);
|
||||
return host;
|
||||
}
|
||||
|
||||
/** Create list over available network adapters.
|
||||
* @return First element in linked list of adapters
|
||||
*/
|
||||
ec_adaptert * oshw_find_adapters(void)
|
||||
ec_adaptert *oshw_find_adapters(void)
|
||||
{
|
||||
int i;
|
||||
struct if_nameindex *ids;
|
||||
ec_adaptert * adapter;
|
||||
ec_adaptert * prev_adapter = NULL;
|
||||
ec_adaptert * ret_adapter = NULL;
|
||||
|
||||
ec_adaptert *adapter;
|
||||
ec_adaptert *prev_adapter = NULL;
|
||||
ec_adaptert *ret_adapter = NULL;
|
||||
|
||||
/* Iterate all devices and create a local copy holding the name and
|
||||
* description.
|
||||
*/
|
||||
|
||||
ids = if_nameindex ();
|
||||
for(i = 0; ids[i].if_index != 0; i++)
|
||||
ids = if_nameindex();
|
||||
for (i = 0; ids[i].if_index != 0; i++)
|
||||
{
|
||||
adapter = (ec_adaptert *)malloc(sizeof(ec_adaptert));
|
||||
/* If we got more than one adapter save link list pointer to previous
|
||||
@@ -74,10 +73,10 @@ ec_adaptert * oshw_find_adapters(void)
|
||||
|
||||
if (ids[i].if_name)
|
||||
{
|
||||
strncpy(adapter->name, ids[i].if_name, EC_MAXLEN_ADAPTERNAME);
|
||||
adapter->name[EC_MAXLEN_ADAPTERNAME-1] = '\0';
|
||||
strncpy(adapter->desc, ids[i].if_name, EC_MAXLEN_ADAPTERNAME);
|
||||
adapter->desc[EC_MAXLEN_ADAPTERNAME-1] = '\0';
|
||||
strncpy(adapter->name, ids[i].if_name, EC_MAXLEN_ADAPTERNAME);
|
||||
adapter->name[EC_MAXLEN_ADAPTERNAME - 1] = '\0';
|
||||
strncpy(adapter->desc, ids[i].if_name, EC_MAXLEN_ADAPTERNAME);
|
||||
adapter->desc[EC_MAXLEN_ADAPTERNAME - 1] = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -88,7 +87,7 @@ ec_adaptert * oshw_find_adapters(void)
|
||||
prev_adapter = adapter;
|
||||
}
|
||||
|
||||
if_freenameindex (ids);
|
||||
if_freenameindex(ids);
|
||||
|
||||
return ret_adapter;
|
||||
}
|
||||
@@ -97,21 +96,21 @@ ec_adaptert * oshw_find_adapters(void)
|
||||
* @param[in] adapter = First element in linked list of adapters
|
||||
* EC_NOFRAME.
|
||||
*/
|
||||
void oshw_free_adapters(ec_adaptert * adapter)
|
||||
void oshw_free_adapters(ec_adaptert *adapter)
|
||||
{
|
||||
ec_adaptert * next_adapter;
|
||||
ec_adaptert *next_adapter;
|
||||
/* Iterate the linked list and free all elements holding
|
||||
* adapter information
|
||||
*/
|
||||
if(adapter)
|
||||
if (adapter)
|
||||
{
|
||||
next_adapter = adapter->next;
|
||||
free (adapter);
|
||||
free(adapter);
|
||||
while (next_adapter)
|
||||
{
|
||||
adapter = next_adapter;
|
||||
next_adapter = adapter->next;
|
||||
free (adapter);
|
||||
free(adapter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,8 +21,8 @@ extern "C" {
|
||||
|
||||
uint16 oshw_htons(uint16 hostshort);
|
||||
uint16 oshw_ntohs(uint16 networkshort);
|
||||
ec_adaptert * oshw_find_adapters(void);
|
||||
void oshw_free_adapters(ec_adaptert * adapter);
|
||||
ec_adaptert *oshw_find_adapters(void);
|
||||
void oshw_free_adapters(ec_adaptert *adapter);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -31,7 +31,6 @@
|
||||
* This layer is fully transparent for the higher layers.
|
||||
*/
|
||||
|
||||
|
||||
#include <assert.h>
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
@@ -44,10 +43,10 @@
|
||||
/** Redundancy modes */
|
||||
enum
|
||||
{
|
||||
/** No redundancy, single NIC mode */
|
||||
ECT_RED_NONE,
|
||||
/** Double redundant NIC connection */
|
||||
ECT_RED_DOUBLE
|
||||
/** No redundancy, single NIC mode */
|
||||
ECT_RED_NONE,
|
||||
/** Double redundant NIC connection */
|
||||
ECT_RED_DOUBLE
|
||||
};
|
||||
|
||||
/** Primary source MAC address used for EtherCAT.
|
||||
@@ -56,21 +55,21 @@ enum
|
||||
* differentiate the route the packet traverses through the EtherCAT
|
||||
* segment. This is needed to fund out the packet flow in redundant
|
||||
* configurations. */
|
||||
const uint16 priMAC[3] = { 0x0101, 0x0101, 0x0101 };
|
||||
const uint16 priMAC[3] = {0x0101, 0x0101, 0x0101};
|
||||
/** Secondary source MAC address used for EtherCAT. */
|
||||
const uint16 secMAC[3] = { 0x0404, 0x0404, 0x0404 };
|
||||
const uint16 secMAC[3] = {0x0404, 0x0404, 0x0404};
|
||||
|
||||
/** second MAC word is used for identification */
|
||||
#define RX_PRIM priMAC[1]
|
||||
/** second MAC word is used for identification */
|
||||
#define RX_SEC secMAC[1]
|
||||
#define RX_SEC secMAC[1]
|
||||
|
||||
static char errbuf[PCAP_ERRBUF_SIZE];
|
||||
|
||||
static void ecx_clear_rxbufstat(int *rxbufstat)
|
||||
{
|
||||
int i;
|
||||
for(i = 0; i < EC_MAXBUF; i++)
|
||||
for (i = 0; i < EC_MAXBUF; i++)
|
||||
{
|
||||
rxbufstat[i] = EC_BUF_EMPTY;
|
||||
}
|
||||
@@ -96,14 +95,14 @@ int ecx_setupnic(ecx_portt *port, const char *ifname, int secondary)
|
||||
/* when using secondary socket it is automatically a redundant setup */
|
||||
psock = &(port->redport->sockhandle);
|
||||
*psock = NULL;
|
||||
port->redstate = ECT_RED_DOUBLE;
|
||||
port->redport->stack.sock = &(port->redport->sockhandle);
|
||||
port->redport->stack.txbuf = &(port->txbuf);
|
||||
port->redstate = ECT_RED_DOUBLE;
|
||||
port->redport->stack.sock = &(port->redport->sockhandle);
|
||||
port->redport->stack.txbuf = &(port->txbuf);
|
||||
port->redport->stack.txbuflength = &(port->txbuflength);
|
||||
port->redport->stack.tempbuf = &(port->redport->tempinbuf);
|
||||
port->redport->stack.rxbuf = &(port->redport->rxbuf);
|
||||
port->redport->stack.rxbufstat = &(port->redport->rxbufstat);
|
||||
port->redport->stack.rxsa = &(port->redport->rxsa);
|
||||
port->redport->stack.tempbuf = &(port->redport->tempinbuf);
|
||||
port->redport->stack.rxbuf = &(port->redport->rxbuf);
|
||||
port->redport->stack.rxbufstat = &(port->redport->rxbufstat);
|
||||
port->redport->stack.rxsa = &(port->redport->rxsa);
|
||||
ecx_clear_rxbufstat(&(port->redport->rxbufstat[0]));
|
||||
}
|
||||
else
|
||||
@@ -117,16 +116,16 @@ int ecx_setupnic(ecx_portt *port, const char *ifname, int secondary)
|
||||
pthread_mutex_init(&(port->getindex_mutex), NULL);
|
||||
pthread_mutex_init(&(port->tx_mutex), NULL);
|
||||
pthread_mutex_init(&(port->rx_mutex), NULL);
|
||||
port->sockhandle = NULL;
|
||||
port->lastidx = 0;
|
||||
port->redstate = ECT_RED_NONE;
|
||||
port->stack.sock = &(port->sockhandle);
|
||||
port->stack.txbuf = &(port->txbuf);
|
||||
port->sockhandle = NULL;
|
||||
port->lastidx = 0;
|
||||
port->redstate = ECT_RED_NONE;
|
||||
port->stack.sock = &(port->sockhandle);
|
||||
port->stack.txbuf = &(port->txbuf);
|
||||
port->stack.txbuflength = &(port->txbuflength);
|
||||
port->stack.tempbuf = &(port->tempinbuf);
|
||||
port->stack.rxbuf = &(port->rxbuf);
|
||||
port->stack.rxbufstat = &(port->rxbufstat);
|
||||
port->stack.rxsa = &(port->rxsa);
|
||||
port->stack.tempbuf = &(port->tempinbuf);
|
||||
port->stack.rxbuf = &(port->rxbuf);
|
||||
port->stack.rxbufstat = &(port->rxbufstat);
|
||||
port->stack.rxsa = &(port->rxsa);
|
||||
ecx_clear_rxbufstat(&(port->rxbufstat[0]));
|
||||
psock = &(port->sockhandle);
|
||||
}
|
||||
@@ -143,7 +142,7 @@ int ecx_setupnic(ecx_portt *port, const char *ifname, int secondary)
|
||||
rval = pcap_setnonblock(*psock, 1, errbuf);
|
||||
if (rval != 0)
|
||||
{
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < EC_MAXBUF; i++)
|
||||
@@ -295,10 +294,10 @@ int ecx_outframe_red(ecx_portt *port, uint8 idx)
|
||||
rval = ecx_outframe(port, idx, 0);
|
||||
if (port->redstate != ECT_RED_NONE)
|
||||
{
|
||||
pthread_mutex_lock( &(port->tx_mutex) );
|
||||
pthread_mutex_lock(&(port->tx_mutex));
|
||||
ehp = (ec_etherheadert *)&(port->txbuf2);
|
||||
/* use dummy frame for secondary socket transmit (BRD) */
|
||||
datagramP = (ec_comt*)&(port->txbuf2[ETH_HEADERSIZE]);
|
||||
datagramP = (ec_comt *)&(port->txbuf2[ETH_HEADERSIZE]);
|
||||
/* write index to frame */
|
||||
datagramP->index = idx;
|
||||
/* rewrite MAC source address 1 to secondary */
|
||||
@@ -309,7 +308,7 @@ int ecx_outframe_red(ecx_portt *port, uint8 idx)
|
||||
{
|
||||
port->redport->rxbufstat[idx] = EC_BUF_EMPTY;
|
||||
}
|
||||
pthread_mutex_unlock( &(port->tx_mutex) );
|
||||
pthread_mutex_unlock(&(port->tx_mutex));
|
||||
}
|
||||
|
||||
return rval;
|
||||
@@ -324,8 +323,8 @@ static int ecx_recvpkt(ecx_portt *port, int stacknumber)
|
||||
{
|
||||
int lp, bytesrx;
|
||||
ec_stackT *stack;
|
||||
struct pcap_pkthdr * header;
|
||||
unsigned char const * pkt_data;
|
||||
struct pcap_pkthdr *header;
|
||||
unsigned char const *pkt_data;
|
||||
int res;
|
||||
|
||||
if (!stacknumber)
|
||||
@@ -339,7 +338,7 @@ static int ecx_recvpkt(ecx_portt *port, int stacknumber)
|
||||
lp = sizeof(port->tempinbuf);
|
||||
|
||||
res = pcap_next_ex(*stack->sock, &header, &pkt_data);
|
||||
if (res <=0 )
|
||||
if (res <= 0)
|
||||
{
|
||||
port->tempinbufs = 0;
|
||||
return 0;
|
||||
@@ -373,9 +372,9 @@ static int ecx_recvpkt(ecx_portt *port, int stacknumber)
|
||||
*/
|
||||
int ecx_inframe(ecx_portt *port, uint8 idx, int stacknumber)
|
||||
{
|
||||
uint16 l;
|
||||
int rval;
|
||||
uint8 idxf;
|
||||
uint16 l;
|
||||
int rval;
|
||||
uint8 idxf;
|
||||
ec_etherheadert *ehp;
|
||||
ec_comt *ecp;
|
||||
ec_stackT *stack;
|
||||
@@ -407,11 +406,11 @@ int ecx_inframe(ecx_portt *port, uint8 idx, int stacknumber)
|
||||
if (ecx_recvpkt(port, stacknumber))
|
||||
{
|
||||
rval = EC_OTHERFRAME;
|
||||
ehp =(ec_etherheadert*)(stack->tempbuf);
|
||||
ehp = (ec_etherheadert *)(stack->tempbuf);
|
||||
/* check if it is an EtherCAT frame */
|
||||
if (ehp->etype == htons(ETH_P_ECAT))
|
||||
{
|
||||
ecp =(ec_comt*)(&(*stack->tempbuf)[ETH_HEADERSIZE]);
|
||||
ecp = (ec_comt *)(&(*stack->tempbuf)[ETH_HEADERSIZE]);
|
||||
l = etohs(ecp->elength) & 0x0fff;
|
||||
idxf = ecp->index;
|
||||
/* found index equals requested index ? */
|
||||
@@ -445,8 +444,7 @@ int ecx_inframe(ecx_portt *port, uint8 idx, int stacknumber)
|
||||
}
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock( &(port->rx_mutex) );
|
||||
|
||||
pthread_mutex_unlock(&(port->rx_mutex));
|
||||
}
|
||||
|
||||
/* WKC if matching frame found */
|
||||
@@ -468,7 +466,7 @@ int ecx_inframe(ecx_portt *port, uint8 idx, int stacknumber)
|
||||
static int ecx_waitinframe_red(ecx_portt *port, uint8 idx, osal_timert *timer)
|
||||
{
|
||||
osal_timert timer2;
|
||||
int wkc = EC_NOFRAME;
|
||||
int wkc = EC_NOFRAME;
|
||||
int wkc2 = EC_NOFRAME;
|
||||
int primrx, secrx;
|
||||
|
||||
@@ -479,7 +477,7 @@ static int ecx_waitinframe_red(ecx_portt *port, uint8 idx, osal_timert *timer)
|
||||
{
|
||||
/* only read frame if not already in */
|
||||
if (wkc <= EC_NOFRAME)
|
||||
wkc = ecx_inframe(port, idx, 0);
|
||||
wkc = ecx_inframe(port, idx, 0);
|
||||
/* only try secondary if in redundant mode */
|
||||
if (port->redstate != ECT_RED_NONE)
|
||||
{
|
||||
@@ -487,7 +485,7 @@ static int ecx_waitinframe_red(ecx_portt *port, uint8 idx, osal_timert *timer)
|
||||
if (wkc2 <= EC_NOFRAME)
|
||||
wkc2 = ecx_inframe(port, idx, 1);
|
||||
}
|
||||
/* wait for both frames to arrive or timeout */
|
||||
/* wait for both frames to arrive or timeout */
|
||||
} while (((wkc <= EC_NOFRAME) || (wkc2 <= EC_NOFRAME)) && !osal_timer_is_expired(timer));
|
||||
/* only do redundant functions when in redundant mode */
|
||||
if (port->redstate != ECT_RED_NONE)
|
||||
@@ -501,7 +499,7 @@ static int ecx_waitinframe_red(ecx_portt *port, uint8 idx, osal_timert *timer)
|
||||
|
||||
/* primary socket got secondary frame and secondary socket got primary frame */
|
||||
/* normal situation in redundant mode */
|
||||
if ( ((primrx == RX_SEC) && (secrx == RX_PRIM)) )
|
||||
if (((primrx == RX_SEC) && (secrx == RX_PRIM)))
|
||||
{
|
||||
/* copy secondary buffer to primary */
|
||||
memcpy(&(port->rxbuf[idx]), &(port->redport->rxbuf[idx]), port->txbuflength[idx] - ETH_HEADERSIZE);
|
||||
@@ -509,18 +507,18 @@ static int ecx_waitinframe_red(ecx_portt *port, uint8 idx, osal_timert *timer)
|
||||
}
|
||||
/* primary socket got nothing or primary frame, and secondary socket got secondary frame */
|
||||
/* we need to resend TX packet */
|
||||
if ( ((primrx == 0) && (secrx == RX_SEC)) ||
|
||||
((primrx == RX_PRIM) && (secrx == RX_SEC)) )
|
||||
if (((primrx == 0) && (secrx == RX_SEC)) ||
|
||||
((primrx == RX_PRIM) && (secrx == RX_SEC)))
|
||||
{
|
||||
/* If both primary and secondary have partial connection retransmit the primary received
|
||||
* frame over the secondary socket. The result from the secondary received frame is a combined
|
||||
* frame that traversed all slaves in standard order. */
|
||||
if ( (primrx == RX_PRIM) && (secrx == RX_SEC) )
|
||||
if ((primrx == RX_PRIM) && (secrx == RX_SEC))
|
||||
{
|
||||
/* copy primary rx to tx buffer */
|
||||
memcpy(&(port->txbuf[idx][ETH_HEADERSIZE]), &(port->rxbuf[idx]), port->txbuflength[idx] - ETH_HEADERSIZE);
|
||||
}
|
||||
osal_timer_start (&timer2, EC_TIMEOUTRET);
|
||||
osal_timer_start(&timer2, EC_TIMEOUTRET);
|
||||
/* resend secondary tx */
|
||||
ecx_outframe(port, idx, 1);
|
||||
do
|
||||
@@ -553,7 +551,7 @@ int ecx_waitinframe(ecx_portt *port, uint8 idx, int timeout)
|
||||
int wkc;
|
||||
osal_timert timer;
|
||||
|
||||
osal_timer_start (&timer, timeout);
|
||||
osal_timer_start(&timer, timeout);
|
||||
wkc = ecx_waitinframe_red(port, idx, &timer);
|
||||
|
||||
return wkc;
|
||||
@@ -576,24 +574,24 @@ int ecx_srconfirm(ecx_portt *port, uint8 idx, int timeout)
|
||||
int wkc = EC_NOFRAME;
|
||||
osal_timert timer1, timer2;
|
||||
|
||||
osal_timer_start (&timer1, timeout);
|
||||
osal_timer_start(&timer1, timeout);
|
||||
do
|
||||
{
|
||||
/* tx frame on primary and if in redundant mode a dummy on secondary */
|
||||
ecx_outframe_red(port, idx);
|
||||
if (timeout < EC_TIMEOUTRET)
|
||||
{
|
||||
osal_timer_start (&timer2, timeout);
|
||||
osal_timer_start(&timer2, timeout);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* normally use partial timeout for rx */
|
||||
osal_timer_start (&timer2, EC_TIMEOUTRET);
|
||||
osal_timer_start(&timer2, EC_TIMEOUTRET);
|
||||
}
|
||||
/* get frame from primary or if in redundant mode possibly from secondary */
|
||||
wkc = ecx_waitinframe_red(port, idx, &timer2);
|
||||
/* wait for answer with WKC>=0 or otherwise retry until timeout */
|
||||
} while ((wkc <= EC_NOFRAME) && !osal_timer_is_expired (&timer1));
|
||||
/* wait for answer with WKC>=0 or otherwise retry until timeout */
|
||||
} while ((wkc <= EC_NOFRAME) && !osal_timer_is_expired(&timer1));
|
||||
|
||||
return wkc;
|
||||
}
|
||||
|
||||
@@ -13,8 +13,7 @@
|
||||
#define _nicdrvh_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <pcap/pcap.h>
|
||||
@@ -23,26 +22,26 @@ extern "C"
|
||||
typedef struct
|
||||
{
|
||||
/** socket connection used */
|
||||
pcap_t **sock;
|
||||
pcap_t **sock;
|
||||
/** tx buffer */
|
||||
ec_bufT (*txbuf)[EC_MAXBUF];
|
||||
ec_bufT (*txbuf)[EC_MAXBUF];
|
||||
/** tx buffer lengths */
|
||||
int (*txbuflength)[EC_MAXBUF];
|
||||
int (*txbuflength)[EC_MAXBUF];
|
||||
/** temporary receive buffer */
|
||||
ec_bufT *tempbuf;
|
||||
ec_bufT *tempbuf;
|
||||
/** rx buffers */
|
||||
ec_bufT (*rxbuf)[EC_MAXBUF];
|
||||
ec_bufT (*rxbuf)[EC_MAXBUF];
|
||||
/** rx buffer status fields */
|
||||
int (*rxbufstat)[EC_MAXBUF];
|
||||
int (*rxbufstat)[EC_MAXBUF];
|
||||
/** received MAC source address (middle word) */
|
||||
int (*rxsa)[EC_MAXBUF];
|
||||
int (*rxsa)[EC_MAXBUF];
|
||||
} ec_stackT;
|
||||
|
||||
/** pointer structure to buffers for redundant port */
|
||||
typedef struct
|
||||
{
|
||||
ec_stackT stack;
|
||||
pcap_t *sockhandle;
|
||||
ec_stackT stack;
|
||||
pcap_t *sockhandle;
|
||||
/** rx buffers */
|
||||
ec_bufT rxbuf[EC_MAXBUF];
|
||||
/** rx buffer status */
|
||||
@@ -56,8 +55,8 @@ typedef struct
|
||||
/** pointer structure to buffers, vars and mutexes for port instantiation */
|
||||
typedef struct
|
||||
{
|
||||
ec_stackT stack;
|
||||
pcap_t *sockhandle;
|
||||
ec_stackT stack;
|
||||
pcap_t *sockhandle;
|
||||
/** rx buffers */
|
||||
ec_bufT rxbuf[EC_MAXBUF];
|
||||
/** rx buffer status */
|
||||
@@ -91,14 +90,14 @@ extern const uint16 priMAC[3];
|
||||
extern const uint16 secMAC[3];
|
||||
|
||||
void ec_setupheader(void *p);
|
||||
int ecx_setupnic(ecx_portt *port, const char * ifname, int secondary);
|
||||
int ecx_setupnic(ecx_portt *port, const char *ifname, int secondary);
|
||||
int ecx_closenic(ecx_portt *port);
|
||||
void ecx_setbufstat(ecx_portt *port, uint8 idx, int bufstat);
|
||||
uint8 ecx_getindex(ecx_portt *port);
|
||||
int ecx_outframe(ecx_portt *port, uint8 idx, int sock);
|
||||
int ecx_outframe_red(ecx_portt *port, uint8 idx);
|
||||
int ecx_waitinframe(ecx_portt *port, uint8 idx, int timeout);
|
||||
int ecx_srconfirm(ecx_portt *port, uint8 idx,int timeout);
|
||||
int ecx_srconfirm(ecx_portt *port, uint8 idx, int timeout);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
*/
|
||||
uint16 oshw_htons(uint16 host)
|
||||
{
|
||||
uint16 network = htons (host);
|
||||
uint16 network = htons(host);
|
||||
return network;
|
||||
}
|
||||
|
||||
@@ -33,28 +33,27 @@ uint16 oshw_htons(uint16 host)
|
||||
*/
|
||||
uint16 oshw_ntohs(uint16 network)
|
||||
{
|
||||
uint16 host = ntohs (network);
|
||||
uint16 host = ntohs(network);
|
||||
return host;
|
||||
}
|
||||
|
||||
/** Create list over available network adapters.
|
||||
* @return First element in linked list of adapters
|
||||
*/
|
||||
ec_adaptert * oshw_find_adapters(void)
|
||||
ec_adaptert *oshw_find_adapters(void)
|
||||
{
|
||||
int i;
|
||||
struct if_nameindex *ids;
|
||||
ec_adaptert * adapter;
|
||||
ec_adaptert * prev_adapter;
|
||||
ec_adaptert * ret_adapter = NULL;
|
||||
|
||||
ec_adaptert *adapter;
|
||||
ec_adaptert *prev_adapter;
|
||||
ec_adaptert *ret_adapter = NULL;
|
||||
|
||||
/* Iterate all devices and create a local copy holding the name and
|
||||
* description.
|
||||
*/
|
||||
|
||||
ids = if_nameindex ();
|
||||
for(i = 0; ids[i].if_index != 0; i++)
|
||||
ids = if_nameindex();
|
||||
for (i = 0; ids[i].if_index != 0; i++)
|
||||
{
|
||||
adapter = (ec_adaptert *)malloc(sizeof(ec_adaptert));
|
||||
/* If we got more than one adapter save link list pointer to previous
|
||||
@@ -75,10 +74,10 @@ ec_adaptert * oshw_find_adapters(void)
|
||||
|
||||
if (ids[i].if_name)
|
||||
{
|
||||
strncpy(adapter->name, ids[i].if_name, EC_MAXLEN_ADAPTERNAME);
|
||||
adapter->name[EC_MAXLEN_ADAPTERNAME-1] = '\0';
|
||||
strncpy(adapter->desc, ids[i].if_name, EC_MAXLEN_ADAPTERNAME);
|
||||
adapter->desc[EC_MAXLEN_ADAPTERNAME-1] = '\0';
|
||||
strncpy(adapter->name, ids[i].if_name, EC_MAXLEN_ADAPTERNAME);
|
||||
adapter->name[EC_MAXLEN_ADAPTERNAME - 1] = '\0';
|
||||
strncpy(adapter->desc, ids[i].if_name, EC_MAXLEN_ADAPTERNAME);
|
||||
adapter->desc[EC_MAXLEN_ADAPTERNAME - 1] = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -89,7 +88,7 @@ ec_adaptert * oshw_find_adapters(void)
|
||||
prev_adapter = adapter;
|
||||
}
|
||||
|
||||
if_freenameindex (ids);
|
||||
if_freenameindex(ids);
|
||||
|
||||
return ret_adapter;
|
||||
}
|
||||
@@ -98,21 +97,21 @@ ec_adaptert * oshw_find_adapters(void)
|
||||
* @param[in] adapter = First element in linked list of adapters
|
||||
* EC_NOFRAME.
|
||||
*/
|
||||
void oshw_free_adapters(ec_adaptert * adapter)
|
||||
void oshw_free_adapters(ec_adaptert *adapter)
|
||||
{
|
||||
ec_adaptert * next_adapter;
|
||||
ec_adaptert *next_adapter;
|
||||
/* Iterate the linked list and free all elements holding
|
||||
* adapter information
|
||||
*/
|
||||
if(adapter)
|
||||
if (adapter)
|
||||
{
|
||||
next_adapter = adapter->next;
|
||||
free (adapter);
|
||||
free(adapter);
|
||||
while (next_adapter)
|
||||
{
|
||||
adapter = next_adapter;
|
||||
next_adapter = adapter->next;
|
||||
free (adapter);
|
||||
free(adapter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,8 +21,8 @@ extern "C" {
|
||||
|
||||
uint16 oshw_htons(uint16 hostshort);
|
||||
uint16 oshw_ntohs(uint16 networkshort);
|
||||
ec_adaptert * oshw_find_adapters(void);
|
||||
void oshw_free_adapters(ec_adaptert * adapter);
|
||||
ec_adaptert *oshw_find_adapters(void);
|
||||
void oshw_free_adapters(ec_adaptert *adapter);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -58,26 +58,25 @@ enum
|
||||
ECT_RED_DOUBLE
|
||||
};
|
||||
|
||||
|
||||
/** Primary source MAC address used for EtherCAT.
|
||||
* This address is not the MAC address used from the NIC.
|
||||
* EtherCAT does not care about MAC addressing, but it is used here to
|
||||
* differentiate the route the packet traverses through the EtherCAT
|
||||
* segment. This is needed to find out the packet flow in redundant
|
||||
* configurations. */
|
||||
const uint16 priMAC[3] = { 0x0201, 0x0101, 0x0101 };
|
||||
const uint16 priMAC[3] = {0x0201, 0x0101, 0x0101};
|
||||
/** Secondary source MAC address used for EtherCAT. */
|
||||
const uint16 secMAC[3] = { 0x0604, 0x0404, 0x0404 };
|
||||
const uint16 secMAC[3] = {0x0604, 0x0404, 0x0404};
|
||||
|
||||
/** second MAC word is used for identification */
|
||||
#define RX_PRIM priMAC[1]
|
||||
/** second MAC word is used for identification */
|
||||
#define RX_SEC secMAC[1]
|
||||
#define RX_SEC secMAC[1]
|
||||
|
||||
static void ecx_clear_rxbufstat(int *rxbufstat)
|
||||
{
|
||||
int i;
|
||||
for(i = 0; i < EC_MAXBUF; i++)
|
||||
for (i = 0; i < EC_MAXBUF; i++)
|
||||
{
|
||||
rxbufstat[i] = EC_BUF_EMPTY;
|
||||
}
|
||||
@@ -110,14 +109,14 @@ int ecx_setupnic(ecx_portt *port, const char *ifname, int secondary)
|
||||
/* when using secondary socket it is automatically a redundant setup */
|
||||
bpf = &(port->redport->sockhandle);
|
||||
*bpf = -1;
|
||||
port->redstate = ECT_RED_DOUBLE;
|
||||
port->redport->stack.sock = &(port->redport->sockhandle);
|
||||
port->redport->stack.txbuf = &(port->txbuf);
|
||||
port->redstate = ECT_RED_DOUBLE;
|
||||
port->redport->stack.sock = &(port->redport->sockhandle);
|
||||
port->redport->stack.txbuf = &(port->txbuf);
|
||||
port->redport->stack.txbuflength = &(port->txbuflength);
|
||||
port->redport->stack.tempbuf = &(port->redport->tempinbuf);
|
||||
port->redport->stack.rxbuf = &(port->redport->rxbuf);
|
||||
port->redport->stack.rxbufstat = &(port->redport->rxbufstat);
|
||||
port->redport->stack.rxsa = &(port->redport->rxsa);
|
||||
port->redport->stack.tempbuf = &(port->redport->tempinbuf);
|
||||
port->redport->stack.rxbuf = &(port->redport->rxbuf);
|
||||
port->redport->stack.rxbufstat = &(port->redport->rxbufstat);
|
||||
port->redport->stack.rxsa = &(port->redport->rxsa);
|
||||
ecx_clear_rxbufstat(&(port->redport->rxbufstat[0]));
|
||||
}
|
||||
else
|
||||
@@ -129,89 +128,97 @@ int ecx_setupnic(ecx_portt *port, const char *ifname, int secondary)
|
||||
else
|
||||
{
|
||||
pthread_mutex_init(&(port->getindex_mutex), NULL);
|
||||
pthread_mutex_init(&(port->tx_mutex) , NULL);
|
||||
pthread_mutex_init(&(port->rx_mutex) , NULL);
|
||||
port->sockhandle = -1;
|
||||
port->lastidx = 0;
|
||||
port->redstate = ECT_RED_NONE;
|
||||
port->stack.sock = &(port->sockhandle);
|
||||
port->stack.txbuf = &(port->txbuf);
|
||||
pthread_mutex_init(&(port->tx_mutex), NULL);
|
||||
pthread_mutex_init(&(port->rx_mutex), NULL);
|
||||
port->sockhandle = -1;
|
||||
port->lastidx = 0;
|
||||
port->redstate = ECT_RED_NONE;
|
||||
port->stack.sock = &(port->sockhandle);
|
||||
port->stack.txbuf = &(port->txbuf);
|
||||
port->stack.txbuflength = &(port->txbuflength);
|
||||
port->stack.tempbuf = &(port->tempinbuf);
|
||||
port->stack.rxbuf = &(port->rxbuf);
|
||||
port->stack.rxbufstat = &(port->rxbufstat);
|
||||
port->stack.rxsa = &(port->rxsa);
|
||||
port->stack.tempbuf = &(port->tempinbuf);
|
||||
port->stack.rxbuf = &(port->rxbuf);
|
||||
port->stack.rxbufstat = &(port->rxbufstat);
|
||||
port->stack.rxsa = &(port->rxsa);
|
||||
ecx_clear_rxbufstat(&(port->rxbufstat[0]));
|
||||
bpf = &(port->sockhandle);
|
||||
}
|
||||
|
||||
/* Open a bpf file descriptor */
|
||||
*bpf = -1;
|
||||
for(i = 0; *bpf == -1 && i < maxbpffile; ++i)
|
||||
for (i = 0; *bpf == -1 && i < maxbpffile; ++i)
|
||||
{
|
||||
sprintf(fname, "/dev/bpf%i", i);
|
||||
*bpf = open(fname, O_RDWR);
|
||||
sprintf(fname, "/dev/bpf%i", i);
|
||||
*bpf = open(fname, O_RDWR);
|
||||
}
|
||||
|
||||
if(*bpf == -1)
|
||||
if (*bpf == -1)
|
||||
{
|
||||
/* Failed to open bpf */
|
||||
perror("Could not open bpf\n");
|
||||
return 0;
|
||||
/* Failed to open bpf */
|
||||
perror("Could not open bpf\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Need to hand the same buffer size as bpf expects,
|
||||
force bpf to use our buffer size! */
|
||||
uint buffer_len = sizeof(ec_bufT);
|
||||
if (ioctl(*bpf, BIOCSBLEN, &buffer_len) == -1) {
|
||||
perror("BIOCGBLEN");
|
||||
if (ioctl(*bpf, BIOCSBLEN, &buffer_len) == -1)
|
||||
{
|
||||
perror("BIOCGBLEN");
|
||||
}
|
||||
|
||||
if (buffer_len < 1518) {
|
||||
printf("buffer_len %d < 1518\n", buffer_len);
|
||||
return 0;
|
||||
|
||||
if (buffer_len < 1518)
|
||||
{
|
||||
printf("buffer_len %d < 1518\n", buffer_len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* connect bpf to NIC by name */
|
||||
strcpy(ifr.ifr_name, ifname);
|
||||
if(ioctl(*bpf, BIOCSETIF, &ifr) == -1) {
|
||||
perror("BIOCSETIF");
|
||||
return 0;
|
||||
if (ioctl(*bpf, BIOCSETIF, &ifr) == -1)
|
||||
{
|
||||
perror("BIOCSETIF");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Set required bpf options */
|
||||
|
||||
/* Activate immediate mode */
|
||||
if (ioctl(*bpf, BIOCIMMEDIATE, &true_val) == -1) {
|
||||
perror("BIOCIMMEDIATE");
|
||||
return 0;
|
||||
if (ioctl(*bpf, BIOCIMMEDIATE, &true_val) == -1)
|
||||
{
|
||||
perror("BIOCIMMEDIATE");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Set interface in promiscuous mode */
|
||||
if (ioctl(*bpf, BIOCPROMISC, &true_val) == -1) {
|
||||
perror("BIOCPROMISC");
|
||||
return 0;
|
||||
if (ioctl(*bpf, BIOCPROMISC, &true_val) == -1)
|
||||
{
|
||||
perror("BIOCPROMISC");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* Allow to have custom source address */
|
||||
if (ioctl(*bpf, BIOCSHDRCMPLT, &true_val) == -1) {
|
||||
perror("BIOCSHDRCMPLT");
|
||||
return 0;
|
||||
if (ioctl(*bpf, BIOCSHDRCMPLT, &true_val) == -1)
|
||||
{
|
||||
perror("BIOCSHDRCMPLT");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Listen only to incomming messages */
|
||||
uint direction = BPF_D_IN;
|
||||
if (ioctl(*bpf, BIOCSDIRECTION, &direction) == -1) {
|
||||
perror("BIOCSDIRECTION");
|
||||
return 0;
|
||||
if (ioctl(*bpf, BIOCSDIRECTION, &direction) == -1)
|
||||
{
|
||||
perror("BIOCSDIRECTION");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Set read timeout */
|
||||
timeout.tv_sec = 0;
|
||||
timeout.tv_sec = 0;
|
||||
timeout.tv_usec = 11000;
|
||||
if (ioctl(*bpf, BIOCSRTIMEOUT, &timeout) == -1) {
|
||||
perror("BIOCSRTIMEOUT");
|
||||
return 0;
|
||||
if (ioctl(*bpf, BIOCSRTIMEOUT, &timeout) == -1)
|
||||
{
|
||||
perror("BIOCSRTIMEOUT");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* setup ethernet headers in tx buffers so we don't have to repeat it */
|
||||
@@ -266,7 +273,7 @@ uint8 ecx_getindex(ecx_portt *port)
|
||||
uint8 idx;
|
||||
uint8 cnt;
|
||||
|
||||
pthread_mutex_lock( &(port->getindex_mutex) );
|
||||
pthread_mutex_lock(&(port->getindex_mutex));
|
||||
|
||||
idx = port->lastidx + 1;
|
||||
/* index can't be larger than buffer array */
|
||||
@@ -290,7 +297,7 @@ uint8 ecx_getindex(ecx_portt *port)
|
||||
port->redport->rxbufstat[idx] = EC_BUF_ALLOC;
|
||||
port->lastidx = idx;
|
||||
|
||||
pthread_mutex_unlock( &(port->getindex_mutex) );
|
||||
pthread_mutex_unlock(&(port->getindex_mutex));
|
||||
|
||||
return idx;
|
||||
}
|
||||
@@ -327,9 +334,9 @@ int ecx_outframe(ecx_portt *port, uint8 idx, int stacknumber)
|
||||
stack = &(port->redport->stack);
|
||||
}
|
||||
lp = (*stack->txbuflength)[idx];
|
||||
//rval = send(*stack->sock, (*stack->txbuf)[idx], lp, 0);
|
||||
// rval = send(*stack->sock, (*stack->txbuf)[idx], lp, 0);
|
||||
(*stack->rxbufstat)[idx] = EC_BUF_TX;
|
||||
rval = write (*stack->sock,(*stack->txbuf)[idx], lp);
|
||||
rval = write(*stack->sock, (*stack->txbuf)[idx], lp);
|
||||
if (rval == -1)
|
||||
{
|
||||
(*stack->rxbufstat)[idx] = EC_BUF_EMPTY;
|
||||
@@ -356,22 +363,22 @@ int ecx_outframe_red(ecx_portt *port, uint8 idx)
|
||||
rval = ecx_outframe(port, idx, 0);
|
||||
if (port->redstate != ECT_RED_NONE)
|
||||
{
|
||||
pthread_mutex_lock( &(port->tx_mutex) );
|
||||
pthread_mutex_lock(&(port->tx_mutex));
|
||||
ehp = (ec_etherheadert *)&(port->txbuf2);
|
||||
/* use dummy frame for secondary socket transmit (BRD) */
|
||||
datagramP = (ec_comt*)&(port->txbuf2[ETH_HEADERSIZE]);
|
||||
datagramP = (ec_comt *)&(port->txbuf2[ETH_HEADERSIZE]);
|
||||
/* write index to frame */
|
||||
datagramP->index = idx;
|
||||
/* rewrite MAC source address 1 to secondary */
|
||||
ehp->sa1 = htons(secMAC[1]);
|
||||
/* transmit over secondary socket */
|
||||
//send(port->redport->sockhandle, &(port->txbuf2), port->txbuflength2 , 0);
|
||||
// send(port->redport->sockhandle, &(port->txbuf2), port->txbuflength2 , 0);
|
||||
port->redport->rxbufstat[idx] = EC_BUF_TX;
|
||||
if (write(port->redport->sockhandle, &(port->txbuf2), port->txbuflength2) == -1)
|
||||
{
|
||||
(*stack->rxbufstat)[idx] = EC_BUF_EMPTY;
|
||||
}
|
||||
pthread_mutex_unlock( &(port->tx_mutex) );
|
||||
pthread_mutex_unlock(&(port->tx_mutex));
|
||||
}
|
||||
|
||||
return rval;
|
||||
@@ -396,7 +403,7 @@ static int ecx_recvpkt(ecx_portt *port, int stacknumber)
|
||||
stack = &(port->redport->stack);
|
||||
}
|
||||
lp = sizeof(port->tempinbuf);
|
||||
//bytesrx = recv(*stack->sock, (*stack->tempbuf), lp, 0);
|
||||
// bytesrx = recv(*stack->sock, (*stack->tempbuf), lp, 0);
|
||||
bytesrx = read(*stack->sock, (*stack->tempbuf), lp);
|
||||
port->tempinbufs = bytesrx;
|
||||
|
||||
@@ -421,9 +428,9 @@ static int ecx_recvpkt(ecx_portt *port, int stacknumber)
|
||||
*/
|
||||
int ecx_inframe(ecx_portt *port, uint8 idx, int stacknumber)
|
||||
{
|
||||
uint16 l;
|
||||
int rval;
|
||||
uint8 idxf;
|
||||
uint16 l;
|
||||
int rval;
|
||||
uint8 idxf;
|
||||
ec_etherheadert *ehp;
|
||||
ec_comt *ecp;
|
||||
ec_stackT *stack;
|
||||
@@ -457,12 +464,12 @@ int ecx_inframe(ecx_portt *port, uint8 idx, int stacknumber)
|
||||
/* The data read from /dev/bpf includes an extra header, skip it. */
|
||||
struct bpf_hdr *bpfh = (struct bpf_hdr *)(stack->tempbuf);
|
||||
rval = EC_OTHERFRAME;
|
||||
ehp =(ec_etherheadert*)(*stack->tempbuf + bpfh->bh_hdrlen);
|
||||
ehp = (ec_etherheadert *)(*stack->tempbuf + bpfh->bh_hdrlen);
|
||||
/* check if it is an EtherCAT frame */
|
||||
if (ehp->etype == htons(ETH_P_ECAT))
|
||||
{
|
||||
/* The EtherCAT header follows the ethernet frame header. */
|
||||
ecp =(ec_comt*)(&ehp[1]);
|
||||
ecp = (ec_comt *)(&ehp[1]);
|
||||
l = etohs(ecp->elength) & 0x0fff;
|
||||
idxf = ecp->index;
|
||||
/* found index equals requested index ? */
|
||||
@@ -496,8 +503,7 @@ int ecx_inframe(ecx_portt *port, uint8 idx, int stacknumber)
|
||||
}
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock( &(port->rx_mutex) );
|
||||
|
||||
pthread_mutex_unlock(&(port->rx_mutex));
|
||||
}
|
||||
|
||||
/* WKC if matching frame found */
|
||||
@@ -519,7 +525,7 @@ int ecx_inframe(ecx_portt *port, uint8 idx, int stacknumber)
|
||||
static int ecx_waitinframe_red(ecx_portt *port, uint8 idx, osal_timert *timer)
|
||||
{
|
||||
osal_timert timer2;
|
||||
int wkc = EC_NOFRAME;
|
||||
int wkc = EC_NOFRAME;
|
||||
int wkc2 = EC_NOFRAME;
|
||||
int primrx, secrx;
|
||||
|
||||
@@ -530,7 +536,7 @@ static int ecx_waitinframe_red(ecx_portt *port, uint8 idx, osal_timert *timer)
|
||||
{
|
||||
/* only read frame if not already in */
|
||||
if (wkc <= EC_NOFRAME)
|
||||
wkc = ecx_inframe(port, idx, 0);
|
||||
wkc = ecx_inframe(port, idx, 0);
|
||||
/* only try secondary if in redundant mode */
|
||||
if (port->redstate != ECT_RED_NONE)
|
||||
{
|
||||
@@ -538,7 +544,7 @@ static int ecx_waitinframe_red(ecx_portt *port, uint8 idx, osal_timert *timer)
|
||||
if (wkc2 <= EC_NOFRAME)
|
||||
wkc2 = ecx_inframe(port, idx, 1);
|
||||
}
|
||||
/* wait for both frames to arrive or timeout */
|
||||
/* wait for both frames to arrive or timeout */
|
||||
} while (((wkc <= EC_NOFRAME) || (wkc2 <= EC_NOFRAME)) && !osal_timer_is_expired(timer));
|
||||
/* only do redundant functions when in redundant mode */
|
||||
if (port->redstate != ECT_RED_NONE)
|
||||
@@ -552,7 +558,7 @@ static int ecx_waitinframe_red(ecx_portt *port, uint8 idx, osal_timert *timer)
|
||||
|
||||
/* primary socket got secondary frame and secondary socket got primary frame */
|
||||
/* normal situation in redundant mode */
|
||||
if ( ((primrx == RX_SEC) && (secrx == RX_PRIM)) )
|
||||
if (((primrx == RX_SEC) && (secrx == RX_PRIM)))
|
||||
{
|
||||
/* copy secondary buffer to primary */
|
||||
memcpy(&(port->rxbuf[idx]), &(port->redport->rxbuf[idx]), port->txbuflength[idx] - ETH_HEADERSIZE);
|
||||
@@ -560,18 +566,18 @@ static int ecx_waitinframe_red(ecx_portt *port, uint8 idx, osal_timert *timer)
|
||||
}
|
||||
/* primary socket got nothing or primary frame, and secondary socket got secondary frame */
|
||||
/* we need to resend TX packet */
|
||||
if ( ((primrx == 0) && (secrx == RX_SEC)) ||
|
||||
((primrx == RX_PRIM) && (secrx == RX_SEC)) )
|
||||
if (((primrx == 0) && (secrx == RX_SEC)) ||
|
||||
((primrx == RX_PRIM) && (secrx == RX_SEC)))
|
||||
{
|
||||
/* If both primary and secondary have partial connection retransmit the primary received
|
||||
* frame over the secondary socket. The result from the secondary received frame is a combined
|
||||
* frame that traversed all slaves in standard order. */
|
||||
if ( (primrx == RX_PRIM) && (secrx == RX_SEC) )
|
||||
if ((primrx == RX_PRIM) && (secrx == RX_SEC))
|
||||
{
|
||||
/* copy primary rx to tx buffer */
|
||||
memcpy(&(port->txbuf[idx][ETH_HEADERSIZE]), &(port->rxbuf[idx]), port->txbuflength[idx] - ETH_HEADERSIZE);
|
||||
}
|
||||
osal_timer_start (&timer2, EC_TIMEOUTRET);
|
||||
osal_timer_start(&timer2, EC_TIMEOUTRET);
|
||||
/* resend secondary tx */
|
||||
ecx_outframe(port, idx, 1);
|
||||
do
|
||||
@@ -604,7 +610,7 @@ int ecx_waitinframe(ecx_portt *port, uint8 idx, int timeout)
|
||||
int wkc;
|
||||
osal_timert timer;
|
||||
|
||||
osal_timer_start (&timer, timeout);
|
||||
osal_timer_start(&timer, timeout);
|
||||
wkc = ecx_waitinframe_red(port, idx, &timer);
|
||||
|
||||
return wkc;
|
||||
@@ -627,24 +633,24 @@ int ecx_srconfirm(ecx_portt *port, uint8 idx, int timeout)
|
||||
int wkc = EC_NOFRAME;
|
||||
osal_timert timer1, timer2;
|
||||
|
||||
osal_timer_start (&timer1, timeout);
|
||||
osal_timer_start(&timer1, timeout);
|
||||
do
|
||||
{
|
||||
/* tx frame on primary and if in redundant mode a dummy on secondary */
|
||||
ecx_outframe_red(port, idx);
|
||||
if (timeout < EC_TIMEOUTRET)
|
||||
{
|
||||
osal_timer_start (&timer2, timeout);
|
||||
osal_timer_start(&timer2, timeout);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* normally use partial timeout for rx */
|
||||
osal_timer_start (&timer2, EC_TIMEOUTRET);
|
||||
osal_timer_start(&timer2, EC_TIMEOUTRET);
|
||||
}
|
||||
/* get frame from primary or if in redundant mode possibly from secondary */
|
||||
wkc = ecx_waitinframe_red(port, idx, &timer2);
|
||||
/* wait for answer with WKC>=0 or otherwise retry until timeout */
|
||||
} while ((wkc <= EC_NOFRAME) && !osal_timer_is_expired (&timer1));
|
||||
/* wait for answer with WKC>=0 or otherwise retry until timeout */
|
||||
} while ((wkc <= EC_NOFRAME) && !osal_timer_is_expired(&timer1));
|
||||
|
||||
return wkc;
|
||||
}
|
||||
|
||||
@@ -13,8 +13,7 @@
|
||||
#define _nicdrvh_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <pthread.h>
|
||||
@@ -23,26 +22,26 @@ extern "C"
|
||||
typedef struct
|
||||
{
|
||||
/** socket connection used */
|
||||
int *sock;
|
||||
int *sock;
|
||||
/** tx buffer */
|
||||
ec_bufT (*txbuf)[EC_MAXBUF];
|
||||
ec_bufT (*txbuf)[EC_MAXBUF];
|
||||
/** tx buffer lengths */
|
||||
int (*txbuflength)[EC_MAXBUF];
|
||||
int (*txbuflength)[EC_MAXBUF];
|
||||
/** temporary receive buffer */
|
||||
ec_bufT *tempbuf;
|
||||
ec_bufT *tempbuf;
|
||||
/** rx buffers */
|
||||
ec_bufT (*rxbuf)[EC_MAXBUF];
|
||||
ec_bufT (*rxbuf)[EC_MAXBUF];
|
||||
/** rx buffer status fields */
|
||||
int (*rxbufstat)[EC_MAXBUF];
|
||||
int (*rxbufstat)[EC_MAXBUF];
|
||||
/** received MAC source address (middle word) */
|
||||
int (*rxsa)[EC_MAXBUF];
|
||||
int (*rxsa)[EC_MAXBUF];
|
||||
} ec_stackT;
|
||||
|
||||
/** pointer structure to buffers for redundant port */
|
||||
typedef struct
|
||||
{
|
||||
ec_stackT stack;
|
||||
int sockhandle;
|
||||
ec_stackT stack;
|
||||
int sockhandle;
|
||||
/** rx buffers */
|
||||
ec_bufT rxbuf[EC_MAXBUF];
|
||||
/** rx buffer status */
|
||||
@@ -56,8 +55,8 @@ typedef struct
|
||||
/** pointer structure to buffers, vars and mutexes for port instantiation */
|
||||
typedef struct
|
||||
{
|
||||
ec_stackT stack;
|
||||
int sockhandle;
|
||||
ec_stackT stack;
|
||||
int sockhandle;
|
||||
/** rx buffers */
|
||||
ec_bufT rxbuf[EC_MAXBUF];
|
||||
/** rx buffer status */
|
||||
@@ -91,14 +90,14 @@ extern const uint16 priMAC[3];
|
||||
extern const uint16 secMAC[3];
|
||||
|
||||
void ec_setupheader(void *p);
|
||||
int ecx_setupnic(ecx_portt *port, const char * ifname, int secondary);
|
||||
int ecx_setupnic(ecx_portt *port, const char *ifname, int secondary);
|
||||
int ecx_closenic(ecx_portt *port);
|
||||
void ecx_setbufstat(ecx_portt *port, uint8 idx, int bufstat);
|
||||
uint8 ecx_getindex(ecx_portt *port);
|
||||
int ecx_outframe(ecx_portt *port, uint8 idx, int sock);
|
||||
int ecx_outframe_red(ecx_portt *port, uint8 idx);
|
||||
int ecx_waitinframe(ecx_portt *port, uint8 idx, int timeout);
|
||||
int ecx_srconfirm(ecx_portt *port, uint8 idx,int timeout);
|
||||
int ecx_srconfirm(ecx_portt *port, uint8 idx, int timeout);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
*/
|
||||
uint16 oshw_htons(uint16 host)
|
||||
{
|
||||
uint16 network = htons (host);
|
||||
uint16 network = htons(host);
|
||||
return network;
|
||||
}
|
||||
|
||||
@@ -33,28 +33,27 @@ uint16 oshw_htons(uint16 host)
|
||||
*/
|
||||
uint16 oshw_ntohs(uint16 network)
|
||||
{
|
||||
uint16 host = ntohs (network);
|
||||
uint16 host = ntohs(network);
|
||||
return host;
|
||||
}
|
||||
|
||||
/** Create list over available network adapters.
|
||||
* @return First element in linked list of adapters
|
||||
*/
|
||||
ec_adaptert * oshw_find_adapters(void)
|
||||
ec_adaptert *oshw_find_adapters(void)
|
||||
{
|
||||
int i;
|
||||
struct if_nameindex *ids;
|
||||
ec_adaptert * adapter;
|
||||
ec_adaptert * prev_adapter;
|
||||
ec_adaptert * ret_adapter = NULL;
|
||||
|
||||
ec_adaptert *adapter;
|
||||
ec_adaptert *prev_adapter;
|
||||
ec_adaptert *ret_adapter = NULL;
|
||||
|
||||
/* Iterate all devices and create a local copy holding the name and
|
||||
* description.
|
||||
*/
|
||||
|
||||
ids = if_nameindex ();
|
||||
for(i = 0; ids[i].if_index != 0; i++)
|
||||
ids = if_nameindex();
|
||||
for (i = 0; ids[i].if_index != 0; i++)
|
||||
{
|
||||
adapter = (ec_adaptert *)malloc(sizeof(ec_adaptert));
|
||||
/* If we got more than one adapter save link list pointer to previous
|
||||
@@ -75,10 +74,10 @@ ec_adaptert * oshw_find_adapters(void)
|
||||
|
||||
if (ids[i].if_name)
|
||||
{
|
||||
strncpy(adapter->name, ids[i].if_name, EC_MAXLEN_ADAPTERNAME);
|
||||
adapter->name[EC_MAXLEN_ADAPTERNAME-1] = '\0';
|
||||
strncpy(adapter->desc, ids[i].if_name, EC_MAXLEN_ADAPTERNAME);
|
||||
adapter->desc[EC_MAXLEN_ADAPTERNAME-1] = '\0';
|
||||
strncpy(adapter->name, ids[i].if_name, EC_MAXLEN_ADAPTERNAME);
|
||||
adapter->name[EC_MAXLEN_ADAPTERNAME - 1] = '\0';
|
||||
strncpy(adapter->desc, ids[i].if_name, EC_MAXLEN_ADAPTERNAME);
|
||||
adapter->desc[EC_MAXLEN_ADAPTERNAME - 1] = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -89,7 +88,7 @@ ec_adaptert * oshw_find_adapters(void)
|
||||
prev_adapter = adapter;
|
||||
}
|
||||
|
||||
if_freenameindex (ids);
|
||||
if_freenameindex(ids);
|
||||
|
||||
return ret_adapter;
|
||||
}
|
||||
@@ -98,21 +97,21 @@ ec_adaptert * oshw_find_adapters(void)
|
||||
* @param[in] adapter = First element in linked list of adapters
|
||||
* EC_NOFRAME.
|
||||
*/
|
||||
void oshw_free_adapters(ec_adaptert * adapter)
|
||||
void oshw_free_adapters(ec_adaptert *adapter)
|
||||
{
|
||||
ec_adaptert * next_adapter;
|
||||
ec_adaptert *next_adapter;
|
||||
/* Iterate the linked list and free all elements holding
|
||||
* adapter information
|
||||
*/
|
||||
if(adapter)
|
||||
if (adapter)
|
||||
{
|
||||
next_adapter = adapter->next;
|
||||
free (adapter);
|
||||
free(adapter);
|
||||
while (next_adapter)
|
||||
{
|
||||
adapter = next_adapter;
|
||||
next_adapter = adapter->next;
|
||||
free (adapter);
|
||||
free(adapter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,8 +21,8 @@ extern "C" {
|
||||
|
||||
uint16 oshw_htons(uint16 hostshort);
|
||||
uint16 oshw_ntohs(uint16 networkshort);
|
||||
ec_adaptert * oshw_find_adapters(void);
|
||||
void oshw_free_adapters(ec_adaptert * adapter);
|
||||
ec_adaptert *oshw_find_adapters(void);
|
||||
void oshw_free_adapters(ec_adaptert *adapter);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -22,8 +22,7 @@
|
||||
#include <types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct fec_mac_address
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user