IgH EtherCAT Master  1.5.3
module.c File Reference

EtherCAT master driver module. More...

Go to the source code of this file.

Macros

#define MAX_MASTERS   32
 Maximum number of masters. More...
 
#define EC_MAX_MAC_STRING_SIZE   (3 * ETH_ALEN)
 Maximum MAC string size.
 

Functions

int __init ec_init_module (void)
 Module initialization. More...
 
void __exit ec_cleanup_module (void)
 Module cleanup. More...
 
static int ec_mac_parse (uint8_t *mac, const char *src, int allow_empty)
 Parse a MAC address from a string. More...
 
unsigned int ec_master_count (void)
 Get the number of masters.
 
int ec_mac_equal (const uint8_t *mac1, const uint8_t *mac2)
 
ssize_t ec_mac_print (const uint8_t *mac, char *buffer)
 Print a MAC address to a buffer. More...
 
int ec_mac_is_zero (const uint8_t *mac)
 
int ec_mac_is_broadcast (const uint8_t *mac)
 
void ec_print_data (const uint8_t *data, size_t size)
 Outputs frame contents for debugging purposes. More...
 
void ec_print_data_diff (const uint8_t *d1, const uint8_t *d2, size_t size)
 Outputs frame contents and differences for debugging purposes. More...
 
size_t ec_state_string (uint8_t states, char *buffer, uint8_t multi)
 Prints slave states in clear text. More...
 
ec_device_tecdev_offer (struct net_device *net_dev, ec_pollfunc_t poll, struct module *module)
 Offers an EtherCAT device to a certain master. More...
 
ec_master_tecrt_request_master_err (unsigned int master_index)
 Request a master. More...
 
ec_master_tecrt_request_master (unsigned int master_index)
 Requests an EtherCAT master for realtime operation. More...
 
void ecrt_release_master (ec_master_t *master)
 Releases a requested EtherCAT master. More...
 
unsigned int ecrt_version_magic (void)
 Returns the version magic of the realtime interface. More...
 

Variables

static char * main_devices [MAX_MASTERS]
 Main devices parameter. More...
 
static unsigned int master_count
 Number of masters. More...
 
static char * backup_devices [MAX_MASTERS]
 Backup devices parameter. More...
 
static unsigned int backup_count
 Number of backup devices. More...
 
static unsigned int debug_level
 Debug level parameter. More...
 
static unsigned int run_on_cpu = 0xffffffff
 Bind created kernel threads to a cpu. More...
 
static ec_master_tmasters
 Array of masters. More...
 
static struct semaphore master_sem
 Master semaphore. More...
 
dev_t device_number
 Device number for master cdevs. More...
 
struct class * class
 Device class. More...
 
static uint8_t macs [MAX_MASTERS][2][ETH_ALEN]
 MAC addresses. More...
 
char * ec_master_version_str = EC_MASTER_VERSION
 Version string. More...
 
const char * ec_device_names [2]
 Device names. More...
 
const ec_request_state_t ec_request_state_translation_table []
 Global request state type translation table. More...
 

Detailed Description

EtherCAT master driver module.

Definition in file module.c.

Macro Definition Documentation

◆ MAX_MASTERS

#define MAX_MASTERS   32

Maximum number of masters.

Definition at line 46 of file module.c.

Function Documentation

◆ ec_init_module()

int __init ec_init_module ( void  )

Module initialization.

Initializes master_count masters.

Returns
0 on success, else < 0

Definition at line 101 of file module.c.

◆ ec_cleanup_module()

void __exit ec_cleanup_module ( void  )

Module cleanup.

Clears all master instances.

Definition at line 188 of file module.c.

◆ ec_mac_parse()

static int ec_mac_parse ( uint8_t *  mac,
const char *  src,
int  allow_empty 
)
static

Parse a MAC address from a string.

The MAC address must match the regular expression "([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}".

Returns
0 on success, else < 0

Definition at line 310 of file module.c.

◆ ec_mac_equal()

int ec_mac_equal ( const uint8_t *  mac1,
const uint8_t *  mac2 
)
Returns
true, if two MAC addresses are equal.
Parameters
mac1First MAC address.
mac2Second MAC address.

Definition at line 223 of file module.c.

◆ ec_mac_print()

ssize_t ec_mac_print ( const uint8_t *  mac,
char *  buffer 
)

Print a MAC address to a buffer.

The buffer size must be at least EC_MAX_MAC_STRING_SIZE.

Returns
number of bytes written.
Parameters
macMAC address
bufferTarget buffer.

Definition at line 249 of file module.c.

◆ ec_mac_is_zero()

int ec_mac_is_zero ( const uint8_t *  mac)
Returns
true, if the MAC address is all-zero.
Parameters
macMAC address.

Definition at line 270 of file module.c.

◆ ec_mac_is_broadcast()

int ec_mac_is_broadcast ( const uint8_t *  mac)
Returns
true, if the given MAC address is the broadcast address.
Parameters
macMAC address.

Definition at line 288 of file module.c.

◆ ec_print_data()

void ec_print_data ( const uint8_t *  data,
size_t  size 
)

Outputs frame contents for debugging purposes.

If the data block is larger than 256 bytes, only the first 128 and the last 128 bytes will be shown

Parameters
datapointer to data
sizenumber of bytes to output

Definition at line 348 of file module.c.

◆ ec_print_data_diff()

void ec_print_data_diff ( const uint8_t *  d1,
const uint8_t *  d2,
size_t  size 
)

Outputs frame contents and differences for debugging purposes.

Parameters
d1first data
d2second data
sizenumber of bytes to output

Definition at line 376 of file module.c.

◆ ec_state_string()

size_t ec_state_string ( uint8_t  states,
char *  buffer,
uint8_t  multi 
)

Prints slave states in clear text.

Returns
Size of the created string.
Parameters
statesslave states
buffertarget buffer (min. EC_STATE_STRING_SIZE bytes)
multiShow multi-state mask.

Definition at line 405 of file module.c.

◆ ecrt_request_master_err()

ec_master_t* ecrt_request_master_err ( unsigned int  master_index)

Request a master.

Same as ecrt_request_master(), but with ERR_PTR() return value.

Returns
Requested master.
Parameters
master_indexMaster index.

Definition at line 541 of file module.c.

Variable Documentation

◆ main_devices

char* main_devices[MAX_MASTERS]
static

Main devices parameter.

Definition at line 57 of file module.c.

◆ master_count

unsigned int master_count
static

Number of masters.

Definition at line 58 of file module.c.

◆ backup_devices

char* backup_devices[MAX_MASTERS]
static

Backup devices parameter.

Definition at line 59 of file module.c.

◆ backup_count

unsigned int backup_count
static

Number of backup devices.

Definition at line 60 of file module.c.

◆ debug_level

unsigned int debug_level
static

Debug level parameter.

Definition at line 61 of file module.c.

◆ run_on_cpu

unsigned int run_on_cpu = 0xffffffff
static

Bind created kernel threads to a cpu.

Default do not bind

Definition at line 62 of file module.c.

◆ masters

ec_master_t* masters
static

Array of masters.

Definition at line 64 of file module.c.

◆ master_sem

struct semaphore master_sem
static

Master semaphore.

Definition at line 65 of file module.c.

◆ device_number

dev_t device_number

Device number for master cdevs.

Definition at line 67 of file module.c.

◆ class

struct class* class

Device class.

Definition at line 68 of file module.c.

◆ macs

uint8_t macs[MAX_MASTERS][2][ETH_ALEN]
static

MAC addresses.

Definition at line 70 of file module.c.

◆ ec_master_version_str

char* ec_master_version_str = EC_MASTER_VERSION

Version string.

Definition at line 72 of file module.c.

◆ ec_device_names

const char* ec_device_names[2]
Initial value:
= {
"main",
"backup"
}

Device names.

Definition at line 469 of file module.c.

◆ ec_request_state_translation_table

const ec_request_state_t ec_request_state_translation_table[]
Initial value:
= {
}
Not requested.
Definition: ecrt.h:547
Request is being processed.
Definition: ecrt.h:548
Request was processed successfully.
Definition: ecrt.h:549
Request processing failed.
Definition: ecrt.h:550

Global request state type translation table.

Translates an internal request state to an external one.

Definition at line 662 of file module.c.