fp@27: /****************************************************************************** fp@27: * fp@27: * ec_module.c fp@27: * fp@27: * EtherCAT-Master-Treiber fp@27: * fp@27: * Autoren: Wilhelm Hagemeister, Florian Pose fp@27: * fp@27: * $Id$ fp@27: * fp@27: * (C) Copyright IgH 2005 fp@27: * Ingenieurgemeinschaft IgH fp@27: * Heinz-Bäcker Str. 34 fp@27: * D-45356 Essen fp@27: * Tel.: +49 201/61 99 31 fp@27: * Fax.: +49 201/61 98 36 fp@27: * E-mail: sp@igh-essen.com fp@27: * fp@27: ******************************************************************************/ fp@27: fp@27: #include fp@27: #include fp@27: #include fp@27: fp@27: #include "ec_module.h" fp@27: fp@27: /******************************************************************************/ fp@27: fp@27: #define SUBVERSION_ID "$Id$" fp@27: fp@27: int ecat_master_count = 1; fp@27: EtherCAT_master_t *ecat_masters = NULL; fp@27: fp@27: /******************************************************************************/ fp@27: fp@27: MODULE_AUTHOR ("Wilhelm Hagemeister , Florian Pose "); fp@27: MODULE_DESCRIPTION ("EtherCAT master driver module"); fp@27: MODULE_LICENSE("GPL"); fp@27: MODULE_VERSION(SUBVERSION_ID); fp@27: fp@27: module_param(ecat_master_count, int, 1); fp@27: MODULE_PARM_DESC(ecat_master_count, "Number of EtherCAT master to initialize."); fp@27: fp@27: module_init(ecat_init_module); fp@27: module_exit(ecat_cleanup_module); fp@27: fp@27: EXPORT_SYMBOL(EtherCAT_master); fp@27: fp@27: /******************************************************************************/ fp@27: fp@27: /** fp@27: Init-Funktion des EtherCAT-Master-Treibermodules fp@27: fp@27: Initialisiert soviele Master, wie im Parameter ecat_master_count fp@27: angegeben wurde (Default ist 1). fp@27: fp@27: @returns 0, wenn alles o.k., -1 bei ungueltiger Anzahl Master fp@27: oder zu wenig Speicher. fp@27: */ fp@27: fp@27: int __init ecat_init_module(void) fp@27: { fp@27: unsigned int i; fp@27: fp@27: printk(KERN_ERR "EtherCAT: Master driver %s\n", SUBVERSION_ID); fp@27: fp@27: if (ecat_master_count < 1) fp@27: { fp@27: printk(KERN_ERR "EtherCAT: Error - Illegal ecat_master_count: %i\n", fp@27: ecat_master_count); fp@27: return -1; fp@27: } fp@27: fp@27: printk(KERN_ERR "EtherCAT: Initializing %i EtherCAT master(s)...\n", fp@27: ecat_master_count); fp@27: fp@27: if ((ecat_masters = (EtherCAT_master_t *) kmalloc(sizeof(EtherCAT_master_t) fp@27: * ecat_master_count, fp@27: GFP_KERNEL)) == NULL) fp@27: { fp@27: printk(KERN_ERR "EtherCAT: Could not allocate memory for EtherCAT master(s)!\n"); fp@27: return -1; fp@27: } fp@27: fp@27: for (i = 0; i < ecat_master_count; i++) fp@27: { fp@27: EtherCAT_master_init(&ecat_masters[i]); fp@27: } fp@27: fp@27: printk(KERN_ERR "EtherCAT: Master driver initialized.\n"); fp@27: fp@27: return 0; fp@27: } fp@27: fp@27: /******************************************************************************/ fp@27: fp@27: /** fp@27: Cleanup-Funktion des EtherCAT-Master-Treibermoduls fp@27: fp@27: Entfernt alle Master-Instanzen. fp@27: */ fp@27: fp@27: void __exit ecat_cleanup_module(void) fp@27: { fp@27: unsigned int i; fp@27: fp@27: printk(KERN_ERR "EtherCAT: Cleaning up master driver...\n"); fp@27: fp@27: if (ecat_masters) fp@27: { fp@27: for (i = 0; i < ecat_master_count; i++) fp@27: { fp@27: EtherCAT_master_clear(&ecat_masters[i]); fp@27: } fp@27: fp@27: kfree(ecat_masters); fp@27: } fp@27: fp@27: printk(KERN_ERR "EtherCAT: Master driver cleaned up.\n"); fp@27: } fp@27: fp@27: /******************************************************************************/ fp@27: fp@27: /** fp@27: Gibt einen Zeiger auf einen bestimmten EtherCAT-Master zurueck. fp@27: fp@27: @param index Index des gewuenschten Masters fp@27: @returns Zeiger auf EtherCAT-Master oder NULL, wenn Parameter ungueltig. fp@27: */ fp@27: fp@27: EtherCAT_master_t *EtherCAT_master(int index) fp@27: { fp@27: if (index < 0 || index >= ecat_master_count) fp@27: { fp@27: printk(KERN_ERR "EtherCAT: Master %i does not exist!\n", index); fp@27: return NULL; fp@27: } fp@27: fp@27: return &ecat_masters[index]; fp@27: } fp@27: fp@27: /******************************************************************************/