examples/tty/tty.c
author Florian Pose <fp@igh-essen.com>
Mon, 14 Dec 2009 13:25:50 +0100
changeset 1586 eb9185dfa8ac
parent 1581 e51cf2af3ff9
child 1613 070b4b420ab1
permissions -rw-r--r--
Merged changes by Martin Troxler.
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/******************************************************************************
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
 *  $Id$
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
1326
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1239
diff changeset
     5
 *  Copyright (C) 2006-2008  Florian Pose, Ingenieurgemeinschaft IgH
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
 *
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
 *  This file is part of the IgH EtherCAT Master.
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     8
 *
1326
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1239
diff changeset
     9
 *  The IgH EtherCAT Master is free software; you can redistribute it and/or
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1239
diff changeset
    10
 *  modify it under the terms of the GNU General Public License version 2, as
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1239
diff changeset
    11
 *  published by the Free Software Foundation.
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1239
diff changeset
    12
 *
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1239
diff changeset
    13
 *  The IgH EtherCAT Master is distributed in the hope that it will be useful,
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1239
diff changeset
    14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1239
diff changeset
    15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1239
diff changeset
    16
 *  Public License for more details.
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1239
diff changeset
    17
 *
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1239
diff changeset
    18
 *  You should have received a copy of the GNU General Public License along
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1239
diff changeset
    19
 *  with the IgH EtherCAT Master; if not, write to the Free Software
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    21
 *
1363
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    22
 *  ---
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    23
 *
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    24
 *  The license mentioned above concerns the source code only. Using the
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    25
 *  EtherCAT technology and brand is only permitted in compliance with the
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    26
 *  industrial property and similar rights of Beckhoff Automation GmbH.
246
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 226
diff changeset
    27
 *
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
 *****************************************************************************/
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
1501
59990318c95b Added semaphore header distinction in minimal example.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
    30
#include <linux/version.h>
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
#include <linux/module.h>
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
#include <linux/timer.h>
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
#include <linux/interrupt.h>
1239
b50b93faaf3e Used ERR_PTR() macro for return value of ecrt_request_master().
Florian Pose <fp@igh-essen.com>
parents: 1212
diff changeset
    34
#include <linux/err.h>
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
1501
59990318c95b Added semaphore header distinction in minimal example.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
    36
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)
59990318c95b Added semaphore header distinction in minimal example.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
    37
#include <linux/semaphore.h>
59990318c95b Added semaphore header distinction in minimal example.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
    38
#else
59990318c95b Added semaphore header distinction in minimal example.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
    39
#include <asm/semaphore.h>
59990318c95b Added semaphore header distinction in minimal example.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
    40
#endif
59990318c95b Added semaphore header distinction in minimal example.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
    41
223
daa5e5656b35 Applied new path information to example modules.
Florian Pose <fp@igh-essen.com>
parents: 220
diff changeset
    42
#include "../../include/ecrt.h" // EtherCAT realtime interface
1573
74bf584564b8 Create tty.
Florian Pose <fp@igh-essen.com>
parents: 1567
diff changeset
    43
#include "../../include/ectty.h" // EtherCAT TTY interface
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
820
f8e6f5966cce Cleaned up mini module.
Florian Pose <fp@igh-essen.com>
parents: 818
diff changeset
    45
/*****************************************************************************/
f8e6f5966cce Cleaned up mini module.
Florian Pose <fp@igh-essen.com>
parents: 818
diff changeset
    46
858
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 851
diff changeset
    47
// Module parameters
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    48
#define FREQUENCY 100
858
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 851
diff changeset
    49
1171
de880622f253 Alternative Pdo assignment for el3162.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
    50
// Optional features
1567
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
    51
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
    52
#define PFX "ec_tty_example: "
820
f8e6f5966cce Cleaned up mini module.
Florian Pose <fp@igh-essen.com>
parents: 818
diff changeset
    53
f8e6f5966cce Cleaned up mini module.
Florian Pose <fp@igh-essen.com>
parents: 818
diff changeset
    54
/*****************************************************************************/
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    55
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    56
// EtherCAT
612
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 551
diff changeset
    57
static ec_master_t *master = NULL;
818
b6c87ae254c9 Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
    58
static ec_master_state_t master_state = {};
1500
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1378
diff changeset
    59
struct semaphore master_sem;
818
b6c87ae254c9 Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
    60
612
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 551
diff changeset
    61
static ec_domain_t *domain1 = NULL;
818
b6c87ae254c9 Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
    62
static ec_domain_state_t domain1_state = {};
b6c87ae254c9 Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
    63
1080
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 1061
diff changeset
    64
// Timer
820
f8e6f5966cce Cleaned up mini module.
Florian Pose <fp@igh-essen.com>
parents: 818
diff changeset
    65
static struct timer_list timer;
f8e6f5966cce Cleaned up mini module.
Florian Pose <fp@igh-essen.com>
parents: 818
diff changeset
    66
f8e6f5966cce Cleaned up mini module.
Florian Pose <fp@igh-essen.com>
parents: 818
diff changeset
    67
/*****************************************************************************/
f8e6f5966cce Cleaned up mini module.
Florian Pose <fp@igh-essen.com>
parents: 818
diff changeset
    68
f8e6f5966cce Cleaned up mini module.
Florian Pose <fp@igh-essen.com>
parents: 818
diff changeset
    69
// process data
f8e6f5966cce Cleaned up mini module.
Florian Pose <fp@igh-essen.com>
parents: 818
diff changeset
    70
static uint8_t *domain1_pd; // process data memory
f8e6f5966cce Cleaned up mini module.
Florian Pose <fp@igh-essen.com>
parents: 818
diff changeset
    71
1567
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
    72
#define BusCouplerPos  0, 0
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
    73
#define SerialPos      0, 1
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
    74
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
    75
#define Beckhoff_EK1100 0x00000002, 0x044c2c52
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
    76
#define Beckhoff_EL6002 0x00000002, 0x17723052
1179
c0e6adec1aee Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents: 1171
diff changeset
    77
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
    78
// offsets for PDO entries
1567
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
    79
static unsigned int off_ctrl;
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
    80
static unsigned int off_tx;
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
    81
static unsigned int off_status;
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
    82
static unsigned int off_rx;
820
f8e6f5966cce Cleaned up mini module.
Florian Pose <fp@igh-essen.com>
parents: 818
diff changeset
    83
1080
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 1061
diff changeset
    84
const static ec_pdo_entry_reg_t domain1_regs[] = {
1567
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
    85
    {SerialPos,  Beckhoff_EL6002, 0x7001, 0x01, &off_ctrl},
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
    86
    {SerialPos,  Beckhoff_EL6002, 0x7000, 0x11, &off_tx},
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
    87
    {SerialPos,  Beckhoff_EL6002, 0x6001, 0x01, &off_status},
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
    88
    {SerialPos,  Beckhoff_EL6002, 0x6000, 0x11, &off_rx},
1080
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 1061
diff changeset
    89
    {}
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 1061
diff changeset
    90
};
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 1061
diff changeset
    91
088a61306930 Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents: 1061
diff changeset
    92
static unsigned int counter = 0;
1567
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
    93
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
    94
typedef enum {
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
    95
    SER_REQUEST_INIT,
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
    96
    SER_WAIT_FOR_INIT_RESPONSE,
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
    97
    SER_READY
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
    98
} serial_state_t;
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
    99
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   100
typedef struct {
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   101
    size_t max_tx_data_size;
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   102
    size_t max_rx_data_size;
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   103
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   104
    uint8_t *tx_data;
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   105
    uint8_t tx_data_size;
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   106
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   107
    serial_state_t state;
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   108
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   109
    uint8_t tx_request_toggle;
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   110
    uint8_t tx_accepted_toggle;
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   111
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   112
    uint8_t rx_request_toggle;
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   113
    uint8_t rx_accepted_toggle;
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   114
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   115
    uint16_t control;
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   116
} serial_device_t;
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   117
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   118
static serial_device_t *ser = NULL;
1573
74bf584564b8 Create tty.
Florian Pose <fp@igh-essen.com>
parents: 1567
diff changeset
   119
static ec_tty_t *tty = NULL;
1567
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   120
        
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   121
/*****************************************************************************/
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   122
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   123
/* Slave 1, "EL6002"
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   124
 * Vendor ID:       0x00000002
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   125
 * Product code:    0x17723052
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   126
 * Revision number: 0x00100000
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   127
 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   128
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   129
ec_pdo_entry_info_t slave_1_pdo_entries[] = {
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   130
   {0x7001, 0x01, 16}, /* Ctrl */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   131
   {0x7000, 0x11, 8}, /* Data Out 0 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   132
   {0x7000, 0x12, 8}, /* Data Out 1 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   133
   {0x7000, 0x13, 8}, /* Data Out 2 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   134
   {0x7000, 0x14, 8}, /* Data Out 3 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   135
   {0x7000, 0x15, 8}, /* Data Out 4 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   136
   {0x7000, 0x16, 8}, /* Data Out 5 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   137
   {0x7000, 0x17, 8}, /* Data Out 6 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   138
   {0x7000, 0x18, 8}, /* Data Out 7 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   139
   {0x7000, 0x19, 8}, /* Data Out 8 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   140
   {0x7000, 0x1a, 8}, /* Data Out 9 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   141
   {0x7000, 0x1b, 8}, /* Data Out 10 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   142
   {0x7000, 0x1c, 8}, /* Data Out 11 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   143
   {0x7000, 0x1d, 8}, /* Data Out 12 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   144
   {0x7000, 0x1e, 8}, /* Data Out 13 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   145
   {0x7000, 0x1f, 8}, /* Data Out 14 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   146
   {0x7000, 0x20, 8}, /* Data Out 15 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   147
   {0x7000, 0x21, 8}, /* Data Out 16 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   148
   {0x7000, 0x22, 8}, /* Data Out 17 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   149
   {0x7000, 0x23, 8}, /* Data Out 18 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   150
   {0x7000, 0x24, 8}, /* Data Out 19 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   151
   {0x7000, 0x25, 8}, /* Data Out 20 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   152
   {0x7000, 0x26, 8}, /* Data Out 21 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   153
   {0x7011, 0x01, 16}, /* Ctrl */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   154
   {0x7010, 0x11, 8}, /* Data Out 0 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   155
   {0x7010, 0x12, 8}, /* Data Out 1 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   156
   {0x7010, 0x13, 8}, /* Data Out 2 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   157
   {0x7010, 0x14, 8}, /* Data Out 3 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   158
   {0x7010, 0x15, 8}, /* Data Out 4 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   159
   {0x7010, 0x16, 8}, /* Data Out 5 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   160
   {0x7010, 0x17, 8}, /* Data Out 6 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   161
   {0x7010, 0x18, 8}, /* Data Out 7 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   162
   {0x7010, 0x19, 8}, /* Data Out 8 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   163
   {0x7010, 0x1a, 8}, /* Data Out 9 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   164
   {0x7010, 0x1b, 8}, /* Data Out 10 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   165
   {0x7010, 0x1c, 8}, /* Data Out 11 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   166
   {0x7010, 0x1d, 8}, /* Data Out 12 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   167
   {0x7010, 0x1e, 8}, /* Data Out 13 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   168
   {0x7010, 0x1f, 8}, /* Data Out 14 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   169
   {0x7010, 0x20, 8}, /* Data Out 15 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   170
   {0x7010, 0x21, 8}, /* Data Out 16 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   171
   {0x7010, 0x22, 8}, /* Data Out 17 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   172
   {0x7010, 0x23, 8}, /* Data Out 18 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   173
   {0x7010, 0x24, 8}, /* Data Out 19 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   174
   {0x7010, 0x25, 8}, /* Data Out 20 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   175
   {0x7010, 0x26, 8}, /* Data Out 21 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   176
   {0x6001, 0x01, 16}, /* Status */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   177
   {0x6000, 0x11, 8}, /* Data In 0 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   178
   {0x6000, 0x12, 8}, /* Data In 1 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   179
   {0x6000, 0x13, 8}, /* Data In 2 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   180
   {0x6000, 0x14, 8}, /* Data In 3 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   181
   {0x6000, 0x15, 8}, /* Data In 4 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   182
   {0x6000, 0x16, 8}, /* Data In 5 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   183
   {0x6000, 0x17, 8}, /* Data In 6 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   184
   {0x6000, 0x18, 8}, /* Data In 7 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   185
   {0x6000, 0x19, 8}, /* Data In 8 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   186
   {0x6000, 0x1a, 8}, /* Data In 9 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   187
   {0x6000, 0x1b, 8}, /* Data In 10 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   188
   {0x6000, 0x1c, 8}, /* Data In 11 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   189
   {0x6000, 0x1d, 8}, /* Data In 12 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   190
   {0x6000, 0x1e, 8}, /* Data In 13 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   191
   {0x6000, 0x1f, 8}, /* Data In 14 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   192
   {0x6000, 0x20, 8}, /* Data In 15 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   193
   {0x6000, 0x21, 8}, /* Data In 16 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   194
   {0x6000, 0x22, 8}, /* Data In 17 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   195
   {0x6000, 0x23, 8}, /* Data In 18 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   196
   {0x6000, 0x24, 8}, /* Data In 19 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   197
   {0x6000, 0x25, 8}, /* Data In 20 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   198
   {0x6000, 0x26, 8}, /* Data In 21 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   199
   {0x6011, 0x01, 16}, /* Status */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   200
   {0x6010, 0x11, 8}, /* Data In 0 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   201
   {0x6010, 0x12, 8}, /* Data In 1 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   202
   {0x6010, 0x13, 8}, /* Data In 2 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   203
   {0x6010, 0x14, 8}, /* Data In 3 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   204
   {0x6010, 0x15, 8}, /* Data In 4 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   205
   {0x6010, 0x16, 8}, /* Data In 5 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   206
   {0x6010, 0x17, 8}, /* Data In 6 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   207
   {0x6010, 0x18, 8}, /* Data In 7 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   208
   {0x6010, 0x19, 8}, /* Data In 8 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   209
   {0x6010, 0x1a, 8}, /* Data In 9 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   210
   {0x6010, 0x1b, 8}, /* Data In 10 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   211
   {0x6010, 0x1c, 8}, /* Data In 11 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   212
   {0x6010, 0x1d, 8}, /* Data In 12 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   213
   {0x6010, 0x1e, 8}, /* Data In 13 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   214
   {0x6010, 0x1f, 8}, /* Data In 14 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   215
   {0x6010, 0x20, 8}, /* Data In 15 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   216
   {0x6010, 0x21, 8}, /* Data In 16 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   217
   {0x6010, 0x22, 8}, /* Data In 17 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   218
   {0x6010, 0x23, 8}, /* Data In 18 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   219
   {0x6010, 0x24, 8}, /* Data In 19 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   220
   {0x6010, 0x25, 8}, /* Data In 20 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   221
   {0x6010, 0x26, 8}, /* Data In 21 */
1171
de880622f253 Alternative Pdo assignment for el3162.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
   222
};
de880622f253 Alternative Pdo assignment for el3162.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
   223
1567
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   224
ec_pdo_info_t slave_1_pdos[] = {
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   225
   {0x1604, 23, slave_1_pdo_entries + 0}, /* COM RxPDO-Map Outputs Ch.1 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   226
   {0x1605, 23, slave_1_pdo_entries + 23}, /* COM RxPDO-Map Outputs Ch.2 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   227
   {0x1a04, 23, slave_1_pdo_entries + 46}, /* COM TxPDO-Map Inputs Ch.1 */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   228
   {0x1a05, 23, slave_1_pdo_entries + 69}, /* COM TxPDO-Map Inputs Ch.2 */
1179
c0e6adec1aee Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents: 1171
diff changeset
   229
};
c0e6adec1aee Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents: 1171
diff changeset
   230
1567
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   231
ec_sync_info_t slave_1_syncs[] = {
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   232
   {0, EC_DIR_OUTPUT, 0, NULL, EC_WD_DISABLE},
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   233
   {1, EC_DIR_INPUT, 0, NULL, EC_WD_DISABLE},
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   234
   {2, EC_DIR_OUTPUT, 2, slave_1_pdos + 0, EC_WD_DISABLE},
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   235
   {3, EC_DIR_INPUT, 2, slave_1_pdos + 2, EC_WD_DISABLE},
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   236
   {0xff}
1171
de880622f253 Alternative Pdo assignment for el3162.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
   237
};
1567
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   238
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   239
/****************************************************************************/
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   240
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   241
int serial_init(serial_device_t *ser, size_t max_tx, size_t max_rx)
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   242
{
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   243
    ser->max_tx_data_size = max_tx;
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   244
    ser->max_rx_data_size = max_rx;
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   245
    ser->tx_data = NULL;
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   246
    ser->tx_data_size = 0;
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   247
    ser->state = SER_REQUEST_INIT;
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   248
    ser->tx_request_toggle = 0;
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   249
    ser->rx_accepted_toggle = 0;
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   250
    ser->control = 0x0000;
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   251
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   252
    if (max_tx > 0) {
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   253
        ser->tx_data = kmalloc(max_tx, GFP_KERNEL);
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   254
        if (ser->tx_data == NULL) {
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   255
            return -ENOMEM;
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   256
        }
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   257
    }
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   258
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   259
    return 0;
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   260
}
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   261
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   262
/****************************************************************************/
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   263
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   264
void serial_clear(serial_device_t *ser)
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   265
{
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   266
    if (ser->tx_data) {
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   267
        kfree(ser->tx_data);
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   268
    }
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   269
}
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   270
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   271
/****************************************************************************/
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   272
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   273
void serial_run(serial_device_t *ser, uint16_t status, uint8_t *rx_data)
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   274
{
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   275
    uint8_t tx_accepted_toggle, rx_request_toggle;
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   276
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   277
    switch (ser->state) {
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   278
        case SER_READY:
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   279
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   280
            /* Send data */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   281
            
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   282
            tx_accepted_toggle = status & 0x0001;
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   283
            if (tx_accepted_toggle != ser->tx_accepted_toggle) { // ready
1575
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1573
diff changeset
   284
                ser->tx_data_size =
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1573
diff changeset
   285
                    ectty_tx_data(tty, ser->tx_data, ser->max_tx_data_size);
17598f2332b6 Send direction works!
Florian Pose <fp@igh-essen.com>
parents: 1573
diff changeset
   286
                if (ser->tx_data_size) {
1567
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   287
                    printk(KERN_INFO PFX "Sending %u bytes.\n", ser->tx_data_size);
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   288
                    ser->tx_request_toggle = !ser->tx_request_toggle;
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   289
                    ser->tx_accepted_toggle = tx_accepted_toggle;
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   290
                }
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   291
            }
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   292
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   293
            /* Receive data */
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   294
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   295
            rx_request_toggle = status & 0x0002;
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   296
            if (rx_request_toggle != ser->rx_request_toggle) {
1577
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   297
                uint8_t rx_data_size = status >> 8;
1567
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   298
                ser->rx_request_toggle = rx_request_toggle;
1577
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   299
                printk(KERN_INFO PFX "Received %u bytes.\n", rx_data_size);
fa3f66b783c1 Implemented reading direction of tty driver.
Florian Pose <fp@igh-essen.com>
parents: 1575
diff changeset
   300
                ectty_rx_data(tty, rx_data, rx_data_size);
1567
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   301
                ser->rx_accepted_toggle = !ser->rx_accepted_toggle;
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   302
            }
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   303
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   304
            ser->control =
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   305
                ser->tx_request_toggle |
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   306
                ser->rx_accepted_toggle << 1 |
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   307
                ser->tx_data_size << 8;
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   308
            break;
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   309
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   310
        case SER_REQUEST_INIT:
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   311
            if (status & (1 << 2)) {
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   312
                ser->control = 0x0000;
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   313
                ser->state = SER_WAIT_FOR_INIT_RESPONSE;
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   314
            } else {
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   315
                ser->control = 1 << 2; // CW.2, request initialization
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   316
            }
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   317
            break;
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   318
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   319
        case SER_WAIT_FOR_INIT_RESPONSE:
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   320
            if (!(status & (1 << 2))) {
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   321
                printk(KERN_INFO PFX "Init successful.\n");
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   322
                ser->tx_accepted_toggle = 1;
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   323
                ser->control = 0x0000;
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   324
                ser->state = SER_READY;
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   325
            }
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   326
            break;
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   327
    }
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   328
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   329
}
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1179
diff changeset
   330
858
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 851
diff changeset
   331
/*****************************************************************************/
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 851
diff changeset
   332
818
b6c87ae254c9 Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   333
void check_domain1_state(void)
b6c87ae254c9 Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   334
{
b6c87ae254c9 Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   335
    ec_domain_state_t ds;
b6c87ae254c9 Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   336
1500
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1378
diff changeset
   337
    down(&master_sem);
818
b6c87ae254c9 Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   338
    ecrt_domain_state(domain1, &ds);
1500
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1378
diff changeset
   339
    up(&master_sem);
1022
8e49b519e6ba Implemented ecrt_slave_config_state(); minor changes in
Florian Pose <fp@igh-essen.com>
parents: 909
diff changeset
   340
818
b6c87ae254c9 Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   341
    if (ds.working_counter != domain1_state.working_counter)
1022
8e49b519e6ba Implemented ecrt_slave_config_state(); minor changes in
Florian Pose <fp@igh-essen.com>
parents: 909
diff changeset
   342
        printk(KERN_INFO PFX "Domain1: WC %u.\n", ds.working_counter);
818
b6c87ae254c9 Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   343
    if (ds.wc_state != domain1_state.wc_state)
1022
8e49b519e6ba Implemented ecrt_slave_config_state(); minor changes in
Florian Pose <fp@igh-essen.com>
parents: 909
diff changeset
   344
        printk(KERN_INFO PFX "Domain1: State %u.\n", ds.wc_state);
818
b6c87ae254c9 Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   345
b6c87ae254c9 Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   346
    domain1_state = ds;
b6c87ae254c9 Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   347
}
b6c87ae254c9 Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   348
b6c87ae254c9 Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   349
/*****************************************************************************/
b6c87ae254c9 Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   350
b6c87ae254c9 Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   351
void check_master_state(void)
b6c87ae254c9 Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   352
{
b6c87ae254c9 Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   353
    ec_master_state_t ms;
b6c87ae254c9 Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   354
1500
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1378
diff changeset
   355
    down(&master_sem);
818
b6c87ae254c9 Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   356
    ecrt_master_state(master, &ms);
1500
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1378
diff changeset
   357
    up(&master_sem);
818
b6c87ae254c9 Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   358
1022
8e49b519e6ba Implemented ecrt_slave_config_state(); minor changes in
Florian Pose <fp@igh-essen.com>
parents: 909
diff changeset
   359
    if (ms.slaves_responding != master_state.slaves_responding)
8e49b519e6ba Implemented ecrt_slave_config_state(); minor changes in
Florian Pose <fp@igh-essen.com>
parents: 909
diff changeset
   360
        printk(KERN_INFO PFX "%u slave(s).\n", ms.slaves_responding);
8e49b519e6ba Implemented ecrt_slave_config_state(); minor changes in
Florian Pose <fp@igh-essen.com>
parents: 909
diff changeset
   361
    if (ms.al_states != master_state.al_states)
8e49b519e6ba Implemented ecrt_slave_config_state(); minor changes in
Florian Pose <fp@igh-essen.com>
parents: 909
diff changeset
   362
        printk(KERN_INFO PFX "AL states: 0x%02X.\n", ms.al_states);
8e49b519e6ba Implemented ecrt_slave_config_state(); minor changes in
Florian Pose <fp@igh-essen.com>
parents: 909
diff changeset
   363
    if (ms.link_up != master_state.link_up)
8e49b519e6ba Implemented ecrt_slave_config_state(); minor changes in
Florian Pose <fp@igh-essen.com>
parents: 909
diff changeset
   364
        printk(KERN_INFO PFX "Link is %s.\n", ms.link_up ? "up" : "down");
818
b6c87ae254c9 Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   365
b6c87ae254c9 Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   366
    master_state = ms;
b6c87ae254c9 Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   367
}
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   368
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   369
/*****************************************************************************/
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   370
820
f8e6f5966cce Cleaned up mini module.
Florian Pose <fp@igh-essen.com>
parents: 818
diff changeset
   371
void cyclic_task(unsigned long data)
f8e6f5966cce Cleaned up mini module.
Florian Pose <fp@igh-essen.com>
parents: 818
diff changeset
   372
{
818
b6c87ae254c9 Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   373
    // receive process data
1500
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1378
diff changeset
   374
    down(&master_sem);
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 280
diff changeset
   375
    ecrt_master_receive(master);
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   376
    ecrt_domain_process(domain1);
1500
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1378
diff changeset
   377
    up(&master_sem);
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   378
818
b6c87ae254c9 Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   379
    // check process data state (optional)
b6c87ae254c9 Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   380
    check_domain1_state();
512
24292123d174 Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents: 509
diff changeset
   381
24292123d174 Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents: 509
diff changeset
   382
    if (counter) {
24292123d174 Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents: 509
diff changeset
   383
        counter--;
858
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 851
diff changeset
   384
    } else { // do this at 1 Hz
512
24292123d174 Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents: 509
diff changeset
   385
        counter = FREQUENCY;
818
b6c87ae254c9 Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   386
b6c87ae254c9 Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   387
        // check for master state (optional)
b6c87ae254c9 Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   388
        check_master_state();
1567
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   389
    }
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   390
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   391
    serial_run(ser, EC_READ_U16(domain1_pd + off_status), domain1_pd + off_rx);
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   392
    EC_WRITE_U16(domain1_pd + off_ctrl, ser->control);
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   393
    memcpy(domain1_pd + off_tx, ser->tx_data, 22);
818
b6c87ae254c9 Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   394
b6c87ae254c9 Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   395
    // send process data
1500
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1378
diff changeset
   396
    down(&master_sem);
509
87baea61d0c7 Adjusted examples to 1.2.0 interface changes.
Florian Pose <fp@igh-essen.com>
parents: 472
diff changeset
   397
    ecrt_domain_queue(domain1);
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 280
diff changeset
   398
    ecrt_master_send(master);
1500
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1378
diff changeset
   399
    up(&master_sem);
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   400
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   401
    // restart timer
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   402
    timer.expires += HZ / FREQUENCY;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   403
    add_timer(&timer);
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   404
}
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   405
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   406
/*****************************************************************************/
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   407
1513
60ca68d853b8 Re-added callback data pointer, because it is necessary for some applications.
Florian Pose <fp@igh-essen.com>
parents: 1501
diff changeset
   408
void send_callback(void *cb_data)
60ca68d853b8 Re-added callback data pointer, because it is necessary for some applications.
Florian Pose <fp@igh-essen.com>
parents: 1501
diff changeset
   409
{
60ca68d853b8 Re-added callback data pointer, because it is necessary for some applications.
Florian Pose <fp@igh-essen.com>
parents: 1501
diff changeset
   410
    ec_master_t *m = (ec_master_t *) cb_data;
60ca68d853b8 Re-added callback data pointer, because it is necessary for some applications.
Florian Pose <fp@igh-essen.com>
parents: 1501
diff changeset
   411
    down(&master_sem);
60ca68d853b8 Re-added callback data pointer, because it is necessary for some applications.
Florian Pose <fp@igh-essen.com>
parents: 1501
diff changeset
   412
    ecrt_master_send_ext(m);
60ca68d853b8 Re-added callback data pointer, because it is necessary for some applications.
Florian Pose <fp@igh-essen.com>
parents: 1501
diff changeset
   413
    up(&master_sem);
60ca68d853b8 Re-added callback data pointer, because it is necessary for some applications.
Florian Pose <fp@igh-essen.com>
parents: 1501
diff changeset
   414
}
60ca68d853b8 Re-added callback data pointer, because it is necessary for some applications.
Florian Pose <fp@igh-essen.com>
parents: 1501
diff changeset
   415
60ca68d853b8 Re-added callback data pointer, because it is necessary for some applications.
Florian Pose <fp@igh-essen.com>
parents: 1501
diff changeset
   416
/*****************************************************************************/
60ca68d853b8 Re-added callback data pointer, because it is necessary for some applications.
Florian Pose <fp@igh-essen.com>
parents: 1501
diff changeset
   417
60ca68d853b8 Re-added callback data pointer, because it is necessary for some applications.
Florian Pose <fp@igh-essen.com>
parents: 1501
diff changeset
   418
void receive_callback(void *cb_data)
60ca68d853b8 Re-added callback data pointer, because it is necessary for some applications.
Florian Pose <fp@igh-essen.com>
parents: 1501
diff changeset
   419
{
60ca68d853b8 Re-added callback data pointer, because it is necessary for some applications.
Florian Pose <fp@igh-essen.com>
parents: 1501
diff changeset
   420
    ec_master_t *m = (ec_master_t *) cb_data;
60ca68d853b8 Re-added callback data pointer, because it is necessary for some applications.
Florian Pose <fp@igh-essen.com>
parents: 1501
diff changeset
   421
    down(&master_sem);
60ca68d853b8 Re-added callback data pointer, because it is necessary for some applications.
Florian Pose <fp@igh-essen.com>
parents: 1501
diff changeset
   422
    ecrt_master_receive(m);
1500
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1378
diff changeset
   423
    up(&master_sem);
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   424
}
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   425
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   426
/*****************************************************************************/
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   427
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   428
int __init init_mini_module(void)
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   429
{
1239
b50b93faaf3e Used ERR_PTR() macro for return value of ecrt_request_master().
Florian Pose <fp@igh-essen.com>
parents: 1212
diff changeset
   430
    int ret = -1;
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 654
diff changeset
   431
    ec_slave_config_t *sc;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 654
diff changeset
   432
    
612
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 551
diff changeset
   433
    printk(KERN_INFO PFX "Starting...\n");
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   434
1567
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   435
    ser = kmalloc(sizeof(*ser), GFP_KERNEL);
1573
74bf584564b8 Create tty.
Florian Pose <fp@igh-essen.com>
parents: 1567
diff changeset
   436
    if (!ser) {
1567
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   437
        printk(KERN_ERR PFX "Failed to allocate serial device object.\n");
1573
74bf584564b8 Create tty.
Florian Pose <fp@igh-essen.com>
parents: 1567
diff changeset
   438
        ret = -ENOMEM;
74bf584564b8 Create tty.
Florian Pose <fp@igh-essen.com>
parents: 1567
diff changeset
   439
        goto out_return;
74bf584564b8 Create tty.
Florian Pose <fp@igh-essen.com>
parents: 1567
diff changeset
   440
    }
74bf584564b8 Create tty.
Florian Pose <fp@igh-essen.com>
parents: 1567
diff changeset
   441
1567
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   442
    ret = serial_init(ser, 22, 22);
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   443
    if (ret) {
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   444
        printk(KERN_ERR PFX "Failed to init serial device object.\n");
1573
74bf584564b8 Create tty.
Florian Pose <fp@igh-essen.com>
parents: 1567
diff changeset
   445
        goto out_free_serial;
74bf584564b8 Create tty.
Florian Pose <fp@igh-essen.com>
parents: 1567
diff changeset
   446
    }
74bf584564b8 Create tty.
Florian Pose <fp@igh-essen.com>
parents: 1567
diff changeset
   447
74bf584564b8 Create tty.
Florian Pose <fp@igh-essen.com>
parents: 1567
diff changeset
   448
    tty = ectty_create();
74bf584564b8 Create tty.
Florian Pose <fp@igh-essen.com>
parents: 1567
diff changeset
   449
    if (IS_ERR(tty)) {
74bf584564b8 Create tty.
Florian Pose <fp@igh-essen.com>
parents: 1567
diff changeset
   450
        printk(KERN_ERR PFX "Failed to create tty.\n");
74bf584564b8 Create tty.
Florian Pose <fp@igh-essen.com>
parents: 1567
diff changeset
   451
        ret = PTR_ERR(tty);
74bf584564b8 Create tty.
Florian Pose <fp@igh-essen.com>
parents: 1567
diff changeset
   452
        goto out_serial;
1567
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   453
    }
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   454
    
1239
b50b93faaf3e Used ERR_PTR() macro for return value of ecrt_request_master().
Florian Pose <fp@igh-essen.com>
parents: 1212
diff changeset
   455
    master = ecrt_request_master(0);
1378
1853f6c0b9b2 Removed IS_ERR() from minimal example.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   456
    if (!master) {
1853f6c0b9b2 Removed IS_ERR() from minimal example.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   457
        ret = -EBUSY; 
1239
b50b93faaf3e Used ERR_PTR() macro for return value of ecrt_request_master().
Florian Pose <fp@igh-essen.com>
parents: 1212
diff changeset
   458
        printk(KERN_ERR PFX "Requesting master 0 failed.\n");
1573
74bf584564b8 Create tty.
Florian Pose <fp@igh-essen.com>
parents: 1567
diff changeset
   459
        goto out_tty;
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   460
    }
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   461
1579
326d47aa986c applied komax patch to version r1822
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1501
diff changeset
   462
    sema_init(&master_sem, 1);
1513
60ca68d853b8 Re-added callback data pointer, because it is necessary for some applications.
Florian Pose <fp@igh-essen.com>
parents: 1501
diff changeset
   463
    ecrt_master_callbacks(master, send_callback, receive_callback, master);
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   464
612
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 551
diff changeset
   465
    printk(KERN_INFO PFX "Registering domain...\n");
509
87baea61d0c7 Adjusted examples to 1.2.0 interface changes.
Florian Pose <fp@igh-essen.com>
parents: 472
diff changeset
   466
    if (!(domain1 = ecrt_master_create_domain(master))) {
612
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 551
diff changeset
   467
        printk(KERN_ERR PFX "Domain creation failed!\n");
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 551
diff changeset
   468
        goto out_release_master;
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 551
diff changeset
   469
    }
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 551
diff changeset
   470
1567
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   471
    // Create configuration for bus coupler
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   472
    sc = ecrt_master_slave_config(master, BusCouplerPos, Beckhoff_EK1100);
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   473
    if (!sc)
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   474
        return -1;
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   475
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   476
    if (!(sc = ecrt_master_slave_config(
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   477
                    master, SerialPos, Beckhoff_EL6002))) {
1022
8e49b519e6ba Implemented ecrt_slave_config_state(); minor changes in
Florian Pose <fp@igh-essen.com>
parents: 909
diff changeset
   478
        printk(KERN_ERR PFX "Failed to get slave configuration.\n");
1567
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   479
        return -1;
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   480
    }
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   481
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   482
    printk("Configuring PDOs...\n");
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   483
    if (ecrt_slave_config_pdos(sc, EC_END, slave_1_syncs)) {
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   484
        printk(KERN_ERR PFX "Failed to configure PDOs.\n");
1567
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   485
        return -1;
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   486
    }
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   487
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 654
diff changeset
   488
    if (ecrt_domain_reg_pdo_entry_list(domain1, domain1_regs)) {
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   489
        printk(KERN_ERR PFX "PDO entry registration failed!\n");
1567
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   490
        return -1;
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   491
    }
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 799
diff changeset
   492
612
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 551
diff changeset
   493
    printk(KERN_INFO PFX "Activating master...\n");
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   494
    if (ecrt_master_activate(master)) {
612
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 551
diff changeset
   495
        printk(KERN_ERR PFX "Failed to activate master!\n");
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 799
diff changeset
   496
        goto out_release_master;
1567
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   497
    }
1babaa430b7b Added tty example.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   498
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 799
diff changeset
   499
    // Get internal process data for domain
820
f8e6f5966cce Cleaned up mini module.
Florian Pose <fp@igh-essen.com>
parents: 818
diff changeset
   500
    domain1_pd = ecrt_domain_data(domain1);
612
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 551
diff changeset
   501
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 551
diff changeset
   502
    printk(KERN_INFO PFX "Starting cyclic sample thread.\n");
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   503
    init_timer(&timer);
820
f8e6f5966cce Cleaned up mini module.
Florian Pose <fp@igh-essen.com>
parents: 818
diff changeset
   504
    timer.function = cyclic_task;
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   505
    timer.expires = jiffies + 10;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   506
    add_timer(&timer);
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   507
612
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 551
diff changeset
   508
    printk(KERN_INFO PFX "Started.\n");
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   509
    return 0;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   510
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 799
diff changeset
   511
out_release_master:
654
8278e1e27010 Minor changes in minimal example.
Florian Pose <fp@igh-essen.com>
parents: 643
diff changeset
   512
    printk(KERN_ERR PFX "Releasing master...\n");
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   513
    ecrt_release_master(master);
1573
74bf584564b8 Create tty.
Florian Pose <fp@igh-essen.com>
parents: 1567
diff changeset
   514
out_tty:
74bf584564b8 Create tty.
Florian Pose <fp@igh-essen.com>
parents: 1567
diff changeset
   515
    ectty_free(tty);
74bf584564b8 Create tty.
Florian Pose <fp@igh-essen.com>
parents: 1567
diff changeset
   516
out_serial:
74bf584564b8 Create tty.
Florian Pose <fp@igh-essen.com>
parents: 1567
diff changeset
   517
    serial_clear(ser);
74bf584564b8 Create tty.
Florian Pose <fp@igh-essen.com>
parents: 1567
diff changeset
   518
out_free_serial:
74bf584564b8 Create tty.
Florian Pose <fp@igh-essen.com>
parents: 1567
diff changeset
   519
    kfree(ser);
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 799
diff changeset
   520
out_return:
654
8278e1e27010 Minor changes in minimal example.
Florian Pose <fp@igh-essen.com>
parents: 643
diff changeset
   521
    printk(KERN_ERR PFX "Failed to load. Aborting.\n");
1239
b50b93faaf3e Used ERR_PTR() macro for return value of ecrt_request_master().
Florian Pose <fp@igh-essen.com>
parents: 1212
diff changeset
   522
    return ret;
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   523
}
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   524
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   525
/*****************************************************************************/
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   526
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   527
void __exit cleanup_mini_module(void)
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   528
{
612
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 551
diff changeset
   529
    printk(KERN_INFO PFX "Stopping...\n");
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   530
449
3caf8ff4d8a2 Moved functionality of ecrt_master_deactivate() (now deprecated) to ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   531
    del_timer_sync(&timer);
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 799
diff changeset
   532
612
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 551
diff changeset
   533
    printk(KERN_INFO PFX "Releasing master...\n");
449
3caf8ff4d8a2 Moved functionality of ecrt_master_deactivate() (now deprecated) to ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   534
    ecrt_release_master(master);
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   535
1573
74bf584564b8 Create tty.
Florian Pose <fp@igh-essen.com>
parents: 1567
diff changeset
   536
    ectty_free(tty);
74bf584564b8 Create tty.
Florian Pose <fp@igh-essen.com>
parents: 1567
diff changeset
   537
    serial_clear(ser);
74bf584564b8 Create tty.
Florian Pose <fp@igh-essen.com>
parents: 1567
diff changeset
   538
    kfree(ser);
74bf584564b8 Create tty.
Florian Pose <fp@igh-essen.com>
parents: 1567
diff changeset
   539
654
8278e1e27010 Minor changes in minimal example.
Florian Pose <fp@igh-essen.com>
parents: 643
diff changeset
   540
    printk(KERN_INFO PFX "Unloading.\n");
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   541
}
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   542
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   543
/*****************************************************************************/
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   544
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   545
MODULE_LICENSE("GPL");
512
24292123d174 Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents: 509
diff changeset
   546
MODULE_AUTHOR("Florian Pose <fp@igh-essen.com>");
24292123d174 Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents: 509
diff changeset
   547
MODULE_DESCRIPTION("EtherCAT minimal test environment");
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   548
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   549
module_init(init_mini_module);
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   550
module_exit(cleanup_mini_module);
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   551
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   552
/*****************************************************************************/