master/command.c
changeset 195 674071846ee3
parent 144 fdc24bf62f80
child 197 b9a6e2c22745
child 1618 5cff10efb927
equal deleted inserted replaced
194:c21e7c12dd50 195:674071846ee3
     1 /******************************************************************************
     1 /******************************************************************************
     2  *
     2  *
     3  *  c o m m a n d . c
     3  *  c o m m a n d . c
     4  *
     4  *
     5  *  Methoden für ein EtherCAT-Kommando.
     5  *  Methods of an EtherCAT command.
     6  *
     6  *
     7  *  $Id$
     7  *  $Id$
     8  *
     8  *
     9  *****************************************************************************/
     9  *****************************************************************************/
    10 
    10 
    29     return 0;
    29     return 0;
    30 
    30 
    31 /*****************************************************************************/
    31 /*****************************************************************************/
    32 
    32 
    33 /**
    33 /**
    34    EtherCAT-Kommando-Konstruktor.
    34    Command constructor.
    35 */
    35 */
    36 
    36 
    37 void ec_command_init(ec_command_t *command)
    37 void ec_command_init(ec_command_t *command)
    38 {
    38 {
    39     command->type = EC_CMD_NONE;
    39     command->type = EC_CMD_NONE;
    47 }
    47 }
    48 
    48 
    49 /*****************************************************************************/
    49 /*****************************************************************************/
    50 
    50 
    51 /**
    51 /**
    52    EtherCAT-Kommando-Destruktor.
    52    Command destructor.
    53 */
    53 */
    54 
    54 
    55 void ec_command_clear(ec_command_t *command)
    55 void ec_command_clear(ec_command_t *command)
    56 {
    56 {
    57     if (command->data) kfree(command->data);
    57     if (command->data) kfree(command->data);
    58 }
    58 }
    59 
    59 
    60 /*****************************************************************************/
    60 /*****************************************************************************/
    61 
    61 
    62 /**
    62 /**
    63    Alloziert Speicher.
    63    Allocates command data memory.
       
    64    \return 0 in case of success, else < 0
    64 */
    65 */
    65 
    66 
    66 int ec_command_prealloc(ec_command_t *command, size_t size)
    67 int ec_command_prealloc(ec_command_t *command, size_t size)
    67 {
    68 {
    68     if (size <= command->mem_size) return 0;
    69     if (size <= command->mem_size) return 0;
    83 }
    84 }
    84 
    85 
    85 /*****************************************************************************/
    86 /*****************************************************************************/
    86 
    87 
    87 /**
    88 /**
    88    Initialisiert ein EtherCAT-NPRD-Kommando.
    89    Initializes an EtherCAT NPRD command.
    89 
       
    90    Node-adressed physical read.
    90    Node-adressed physical read.
       
    91    \return 0 in case of success, else < 0
    91 */
    92 */
    92 
    93 
    93 int ec_command_nprd(ec_command_t *command,
    94 int ec_command_nprd(ec_command_t *command,
    94                     /**< EtherCAT-Rahmen */
    95                     /**< EtherCAT command */
    95                     uint16_t node_address,
    96                     uint16_t node_address,
    96                     /**< Adresse des Knotens (Slaves) */
    97                     /**< configured station address */
    97                     uint16_t offset,
    98                     uint16_t offset,
    98                     /**< Physikalische Speicheradresse im Slave */
    99                     /**< physical memory address */
    99                     size_t data_size
   100                     size_t data_size
   100                     /**< Länge der zu lesenden Daten */
   101                     /**< number of bytes to read */
   101                     )
   102                     )
   102 {
   103 {
   103     if (unlikely(node_address == 0x0000))
   104     if (unlikely(node_address == 0x0000))
   104         EC_WARN("Using node address 0x0000!\n");
   105         EC_WARN("Using node address 0x0000!\n");
   105 
   106 
   111 }
   112 }
   112 
   113 
   113 /*****************************************************************************/
   114 /*****************************************************************************/
   114 
   115 
   115 /**
   116 /**
   116    Initialisiert ein EtherCAT-NPWR-Kommando.
   117    Initializes an EtherCAT NPWR command.
   117 
       
   118    Node-adressed physical write.
   118    Node-adressed physical write.
       
   119    \return 0 in case of success, else < 0
   119 */
   120 */
   120 
   121 
   121 int ec_command_npwr(ec_command_t *command,
   122 int ec_command_npwr(ec_command_t *command,
   122                     /**< EtherCAT-Rahmen */
   123                     /**< EtherCAT command */
   123                     uint16_t node_address,
   124                     uint16_t node_address,
   124                     /**< Adresse des Knotens (Slaves) */
   125                     /**< configured station address */
   125                     uint16_t offset,
   126                     uint16_t offset,
   126                     /**< Physikalische Speicheradresse im Slave */
   127                     /**< physical memory address */
   127                     size_t data_size
   128                     size_t data_size
   128                     /**< Länge der zu schreibenden Daten */
   129                     /**< number of bytes to write */
   129                     )
   130                     )
   130 {
   131 {
   131     if (unlikely(node_address == 0x0000))
   132     if (unlikely(node_address == 0x0000))
   132         EC_WARN("Using node address 0x0000!\n");
   133         EC_WARN("Using node address 0x0000!\n");
   133 
   134 
   139 }
   140 }
   140 
   141 
   141 /*****************************************************************************/
   142 /*****************************************************************************/
   142 
   143 
   143 /**
   144 /**
   144    Initialisiert ein EtherCAT-APRD-Kommando.
   145    Initializes an EtherCAT APRD command.
   145 
       
   146    Autoincrement physical read.
   146    Autoincrement physical read.
       
   147    \return 0 in case of success, else < 0
   147 */
   148 */
   148 
   149 
   149 int ec_command_aprd(ec_command_t *command,
   150 int ec_command_aprd(ec_command_t *command,
   150                     /**< EtherCAT-Rahmen */
   151                     /**< EtherCAT command */
   151                     uint16_t ring_position,
   152                     uint16_t ring_position,
   152                     /**< Position des Slaves im Bus */
   153                     /**< auto-increment position */
   153                     uint16_t offset,
   154                     uint16_t offset,
   154                     /**< Physikalische Speicheradresse im Slave */
   155                     /**< physical memory address */
   155                     size_t data_size
   156                     size_t data_size
   156                     /**< Länge der zu lesenden Daten */
   157                     /**< number of bytes to read */
   157                     )
   158                     )
   158 {
   159 {
   159     EC_FUNC_HEADER;
   160     EC_FUNC_HEADER;
   160     command->type = EC_CMD_APRD;
   161     command->type = EC_CMD_APRD;
   161     command->address.physical.slave = (int16_t) ring_position * (-1);
   162     command->address.physical.slave = (int16_t) ring_position * (-1);
   164 }
   165 }
   165 
   166 
   166 /*****************************************************************************/
   167 /*****************************************************************************/
   167 
   168 
   168 /**
   169 /**
   169    Initialisiert ein EtherCAT-APWR-Kommando.
   170    Initializes an EtherCAT APWR command.
   170 
       
   171    Autoincrement physical write.
   171    Autoincrement physical write.
       
   172    \return 0 in case of success, else < 0
   172 */
   173 */
   173 
   174 
   174 int ec_command_apwr(ec_command_t *command,
   175 int ec_command_apwr(ec_command_t *command,
   175                     /**< EtherCAT-Rahmen */
   176                     /**< EtherCAT command */
   176                     uint16_t ring_position,
   177                     uint16_t ring_position,
   177                     /**< Position des Slaves im Bus */
   178                     /**< auto-increment position */
   178                     uint16_t offset,
   179                     uint16_t offset,
   179                     /**< Physikalische Speicheradresse im Slave */
   180                     /**< physical memory address */
   180                     size_t data_size
   181                     size_t data_size
   181                     /**< Länge der zu schreibenden Daten */
   182                     /**< number of bytes to write */
   182                     )
   183                     )
   183 {
   184 {
   184     EC_FUNC_HEADER;
   185     EC_FUNC_HEADER;
   185     command->type = EC_CMD_APWR;
   186     command->type = EC_CMD_APWR;
   186     command->address.physical.slave = (int16_t) ring_position * (-1);
   187     command->address.physical.slave = (int16_t) ring_position * (-1);
   189 }
   190 }
   190 
   191 
   191 /*****************************************************************************/
   192 /*****************************************************************************/
   192 
   193 
   193 /**
   194 /**
   194    Initialisiert ein EtherCAT-BRD-Kommando.
   195    Initializes an EtherCAT BRD command.
   195 
       
   196    Broadcast read.
   196    Broadcast read.
       
   197    \return 0 in case of success, else < 0
   197 */
   198 */
   198 
   199 
   199 int ec_command_brd(ec_command_t *command,
   200 int ec_command_brd(ec_command_t *command,
   200                    /**< EtherCAT-Rahmen */
   201                    /**< EtherCAT command */
   201                    uint16_t offset,
   202                    uint16_t offset,
   202                    /**< Physikalische Speicheradresse im Slave */
   203                    /**< physical memory address */
   203                    size_t data_size
   204                    size_t data_size
   204                    /**< Länge der zu lesenden Daten */
   205                    /**< number of bytes to read */
   205                    )
   206                    )
   206 {
   207 {
   207     EC_FUNC_HEADER;
   208     EC_FUNC_HEADER;
   208     command->type = EC_CMD_BRD;
   209     command->type = EC_CMD_BRD;
   209     command->address.physical.slave = 0x0000;
   210     command->address.physical.slave = 0x0000;
   212 }
   213 }
   213 
   214 
   214 /*****************************************************************************/
   215 /*****************************************************************************/
   215 
   216 
   216 /**
   217 /**
   217    Initialisiert ein EtherCAT-BWR-Kommando.
   218    Initializes an EtherCAT BWR command.
   218 
       
   219    Broadcast write.
   219    Broadcast write.
       
   220    \return 0 in case of success, else < 0
   220 */
   221 */
   221 
   222 
   222 int ec_command_bwr(ec_command_t *command,
   223 int ec_command_bwr(ec_command_t *command,
   223                    /**< EtherCAT-Rahmen */
   224                    /**< EtherCAT command */
   224                    uint16_t offset,
   225                    uint16_t offset,
   225                    /**< Physikalische Speicheradresse im Slave */
   226                    /**< physical memory address */
   226                    size_t data_size
   227                    size_t data_size
   227                    /**< Länge der zu schreibenden Daten */
   228                    /**< number of bytes to write */
   228                    )
   229                    )
   229 {
   230 {
   230     EC_FUNC_HEADER;
   231     EC_FUNC_HEADER;
   231     command->type = EC_CMD_BWR;
   232     command->type = EC_CMD_BWR;
   232     command->address.physical.slave = 0x0000;
   233     command->address.physical.slave = 0x0000;
   235 }
   236 }
   236 
   237 
   237 /*****************************************************************************/
   238 /*****************************************************************************/
   238 
   239 
   239 /**
   240 /**
   240    Initialisiert ein EtherCAT-LRW-Kommando.
   241    Initializes an EtherCAT LRW command.
   241 
       
   242    Logical read write.
   242    Logical read write.
       
   243    \return 0 in case of success, else < 0
   243 */
   244 */
   244 
   245 
   245 int ec_command_lrw(ec_command_t *command,
   246 int ec_command_lrw(ec_command_t *command,
   246                    /**< EtherCAT-Rahmen */
   247                    /**< EtherCAT command */
   247                    uint32_t offset,
   248                    uint32_t offset,
   248                    /**< Logische Startadresse */
   249                    /**< logical address */
   249                    size_t data_size
   250                    size_t data_size
   250                    /**< Länge der zu lesenden/schreibenden Daten */
   251                    /**< number of bytes to read/write */
   251                    )
   252                    )
   252 {
   253 {
   253     EC_FUNC_HEADER;
   254     EC_FUNC_HEADER;
   254     command->type = EC_CMD_LRW;
   255     command->type = EC_CMD_LRW;
   255     command->address.logical = offset;
   256     command->address.logical = offset;
   256     EC_FUNC_FOOTER;
   257     EC_FUNC_FOOTER;
   257 }
   258 }
   258 
   259 
   259 /*****************************************************************************/
   260 /*****************************************************************************/
   260 
       
   261 /* Emacs-Konfiguration
       
   262 ;;; Local Variables: ***
       
   263 ;;; c-basic-offset:4 ***
       
   264 ;;; End: ***
       
   265 */