EtherCAT VxWorks SNARF Mux driver. More...
#include <vxWorks.h>
#include <ctype.h>
#include <string.h>
#include <stdio.h>
#include <muxLib.h>
#include <ipProto.h>
#include <wvLib.h>
#include <sysLib.h>
#include "oshw.h"
#include "osal.h"
#include "nicdrv.h"
Go to the source code of this file.
Macros | |
#define | ECAT_RECV_FAILED 0x664 |
#define | ECAT_RECV_OK 0x665 |
#define | ECAT_RECV_RETRY_OK 0x666 |
#define | ECAT_SEND_COMPLETE 0x676 |
#define | ECAT_SEND_FAILED 0x677 |
#define | ECAT_SEND_START 0x675 |
#define | ECAT_STACK_RECV 0x667 |
#define | IF_NAME_SIZE 8 |
#define | NIC_DEBUG /* Print debugging info? */ |
#define | NIC_LOGMSG(x, a, b, c, d, e, f) |
#define | NIC_WVEVENT(a, b, c) |
#define | RX_PRIM priMAC[1] |
#define | RX_SEC secMAC[1] |
#define | USECS_PER_SEC 1000000 |
Enumerations | |
enum | { ECT_RED_NONE, ECT_RED_DOUBLE } |
Functions | |
static int | ec_outfram_send (ETHERCAT_PKT_DEV *pPktDev, int idx, void *buf, int len) |
void | ec_setupheader (void *p) |
static void | ecx_clear_rxbufstat (int *rxbufstat) |
int | ecx_closenic (ecx_portt *port) |
int | ecx_getindex (ecx_portt *port) |
int | ecx_inframe (ecx_portt *port, int idx, int stacknumber, int timeout) |
int | ecx_outframe (ecx_portt *port, int idx, int stacknumber) |
int | ecx_outframe_red (ecx_portt *port, int idx) |
static int | ecx_recvpkt (ecx_portt *port, int idx, int stacknumber, M_BLK_ID *pMblk, int timeout) |
void | ecx_setbufstat (ecx_portt *port, int idx, int bufstat) |
int | ecx_setupnic (ecx_portt *port, const char *ifname, int secondary) |
int | ecx_srconfirm (ecx_portt *port, int idx, int timeout) |
int | ecx_waitinframe (ecx_portt *port, int idx, int timeout) |
static int | ecx_waitinframe_red (ecx_portt *port, int idx, osal_timert *timer, int timeout) |
static int | mux_rx_callback (void *pCookie, long type, M_BLK_ID pMblk, LL_HDR_INFO *llHdrInfo, void *muxUserArg) |
void | print_nicversion (void) |
Variables | |
const uint16 | priMAC [3] = { 0x0101, 0x0101, 0x0101 } |
const uint16 | secMAC [3] = { 0x0404, 0x0404, 0x0404 } |
static unsigned int | usec_per_tick = 1000 |
EtherCAT VxWorks SNARF Mux driver.
Low level interface functions to send and receive EtherCAT packets. EtherCAT has the property that packets are only send by the master, and the send packets always return in the receive buffer. There can be multiple packets "on the wire" before they return. To combine the received packets with the original send packets a buffer system is installed. The identifier is put in the index item of the EtherCAT header. The index is stored and compared when a frame is received. If there is a match the packet can be combined with the transmit packet and returned to the higher level function.
If EtherCAT is run in parallel with normal IP traffic and EtherCAT have a dedicated NIC, instantiate an extra tNetX task and redirect the NIC workQ to be handle by the extra tNetX task, if needed raise the tNetX task prio. This prevents from having tNet0 becoming a bottleneck.
The "redundant" option will configure two Mux drivers and two NIC interfaces. Slaves are connected to both interfaces, one on the IN port and one on the OUT port. Packets are send via both interfaces. Any one of the connections (also an interconnect) can be removed and the slaves are still serviced with packets. The software layer will detect the possible failure modes and compensate. If needed the packets from interface A are resend through interface B. This layer if fully transparent for the higher layers.
Definition in file vxworks/nicdrv.c.
#define ECAT_RECV_FAILED 0x664 |
Definition at line 50 of file vxworks/nicdrv.c.
#define ECAT_RECV_OK 0x665 |
Definition at line 51 of file vxworks/nicdrv.c.
#define ECAT_RECV_RETRY_OK 0x666 |
Definition at line 52 of file vxworks/nicdrv.c.
#define ECAT_SEND_COMPLETE 0x676 |
Definition at line 55 of file vxworks/nicdrv.c.
#define ECAT_SEND_FAILED 0x677 |
Definition at line 56 of file vxworks/nicdrv.c.
#define ECAT_SEND_START 0x675 |
Definition at line 54 of file vxworks/nicdrv.c.
#define ECAT_STACK_RECV 0x667 |
Definition at line 53 of file vxworks/nicdrv.c.
#define IF_NAME_SIZE 8 |
Definition at line 75 of file vxworks/nicdrv.c.
#define NIC_DEBUG /* Print debugging info? */ |
Definition at line 47 of file vxworks/nicdrv.c.
#define NIC_LOGMSG | ( | x, | |
a, | |||
b, | |||
c, | |||
d, | |||
e, | |||
f | |||
) |
Definition at line 60 of file vxworks/nicdrv.c.
#define NIC_WVEVENT | ( | a, | |
b, | |||
c | |||
) |
Definition at line 64 of file vxworks/nicdrv.c.
#define RX_PRIM priMAC[1] |
second MAC word is used for identification
Definition at line 98 of file vxworks/nicdrv.c.
#define RX_SEC secMAC[1] |
second MAC word is used for identification
Definition at line 100 of file vxworks/nicdrv.c.
#define USECS_PER_SEC 1000000 |
Definition at line 103 of file vxworks/nicdrv.c.
anonymous enum |
Redundancy modes
Enumerator | |
---|---|
ECT_RED_NONE |
No redundancy, single NIC mode |
ECT_RED_DOUBLE |
Double redundant NIC connection |
Definition at line 78 of file vxworks/nicdrv.c.
|
static |
Low level transmit buffer over mux layer 2 driver
[in] | pPktDev | = packet device to send buffer over |
[in] | idx | = index in tx buffer array |
[in] | buf | = buff to send |
[in] | len | = bytes to send |
Definition at line 426 of file vxworks/nicdrv.c.
void ec_setupheader | ( | void * | p | ) |
Fill buffer with ethernet header structure. Destination MAC is always broadcast. Ethertype is always ETH_P_ECAT.
[out] | p | = buffer |
Definition at line 357 of file vxworks/nicdrv.c.
|
static |
Definition at line 109 of file vxworks/nicdrv.c.
|
inline |
Close sockets used
[in] | port | = port context struct |
Definition at line 291 of file vxworks/nicdrv.c.
int ecx_getindex | ( | ecx_portt * | port | ) |
Get new frame identifier index and allocate corresponding rx buffer.
[in] | port | = port context struct |
Definition at line 374 of file vxworks/nicdrv.c.
int ecx_inframe | ( | ecx_portt * | port, |
int | idx, | ||
int | stacknumber, | ||
int | timeout | ||
) |
Non blocking receive frame function. Uses RX buffer and index to combine read frame with transmitted frame. Frames are received by separate receiver task tNet0 (default), tNet0 fetch what frame index and store a reference to the received frame in matching MsgQ. The stack user tasks fetch the frame reference and copies the frame the the RX buffer, when done it free the frame buffer allocated by the Mux.
[in] | port | = port context struct |
[in] | idx | = requested index of frame |
[in] | stacknumber | = 0=primary 1=secondary stack |
[in] | timeout | = timeout in us |
Definition at line 731 of file vxworks/nicdrv.c.
int ecx_outframe | ( | ecx_portt * | port, |
int | idx, | ||
int | stacknumber | ||
) |
High level transmit buffer over mux layer 2 driver, passing buffer and packet device to send on as arguments
[in] | port | = port context holding reference to packet device |
[in] | idx | = index in tx buffer array |
[in] | stacknumber | = 0=Primary 1=Secondary stack |
Definition at line 503 of file vxworks/nicdrv.c.
int ecx_outframe_red | ( | ecx_portt * | port, |
int | idx | ||
) |
High level transmit frame to send as index.
[in] | port | = port context |
[in] | idx | = index in tx buffer array |
Definition at line 540 of file vxworks/nicdrv.c.
|
static |
Non blocking or blocking read, if we use timeout we pass minimum 1 tick.
[in] | port | = port context struct |
[in] | pMblk | = mBlk for received frame |
[in] | timeout | = timeout in us |
Definition at line 681 of file vxworks/nicdrv.c.
void ecx_setbufstat | ( | ecx_portt * | port, |
int | idx, | ||
int | bufstat | ||
) |
Set rx buffer status.
[in] | port | = port context struct |
[in] | idx | = index in buffer array |
[in] | bufstat | = status to set |
Definition at line 411 of file vxworks/nicdrv.c.
int ecx_setupnic | ( | ecx_portt * | port, |
const char * | ifname, | ||
int | secondary | ||
) |
Basic setup to connect NIC to socket.
[in] | port | = port context struct |
[in] | ifname | = Name of NIC device, f.e. "gei0" |
[in] | secondary | = if >0 then use secondary stack instead of primary |
Definition at line 129 of file vxworks/nicdrv.c.
int ecx_srconfirm | ( | ecx_portt * | port, |
int | idx, | ||
int | timeout | ||
) |
Blocking send and receive frame function. Used for non processdata frames. A datagram is build into a frame and transmitted via this function. It waits for an answer and returns the workcounter. The function retries if time is left and the result is WKC=0 or no frame received.
The function calls ec_outframe_red() and ec_waitinframe_red().
[in] | port | = port context struct |
[in] | idx | = index of frame |
[in] | timeout | = timeout in us |
Definition at line 907 of file vxworks/nicdrv.c.
int ecx_waitinframe | ( | ecx_portt * | port, |
int | idx, | ||
int | timeout | ||
) |
Blocking receive frame function. Calls ec_waitinframe_red().
[in] | port | = port context struct |
[in] | idx | = requested index of frame |
[in] | timeout | = timeout in us |
Definition at line 884 of file vxworks/nicdrv.c.
|
static |
Blocking redundant receive frame function. If redundant mode is not active then it skips the secondary stack and redundancy functions. In redundant mode it waits for both (primary and secondary) frames to come in. The result goes in an decision tree that decides, depending on the route of the packet and its possible missing arrival, how to reroute the original packet to get the data in an other try.
[in] | port | = port context struct |
[in] | idx | = requested index of frame |
[in] | timer | = absolute timeout time |
[in] | timeout | = timeout in us |
Definition at line 795 of file vxworks/nicdrv.c.
|
static |
Receive hook called by Mux driver.
Call back routine registered as hook with mux layer 2 driver
[in] | pCookie | = Mux cookie |
[in] | type | = received type |
[in] | pMblk | = the received packet reference |
[in] | llHdrInfo | = header info |
[in] | muxUserArg | = assigned reference to packet device when init called |
Definition at line 581 of file vxworks/nicdrv.c.
void print_nicversion | ( | void | ) |
Definition at line 118 of file vxworks/nicdrv.c.
const uint16 priMAC[3] = { 0x0101, 0x0101, 0x0101 } |
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.
Definition at line 93 of file vxworks/nicdrv.c.
const uint16 secMAC[3] = { 0x0404, 0x0404, 0x0404 } |
Secondary source MAC address used for EtherCAT.
Definition at line 95 of file vxworks/nicdrv.c.
|
static |
Definition at line 104 of file vxworks/nicdrv.c.