src/pdo.c
author etisserant
Tue, 19 Aug 2008 18:02:02 +0200
changeset 508 08adb8d4b098
parent 497 a040156aa72f
child 524 b94067330319
permissions -rw-r--r--
Added more correct signal handling to unix timers.
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     1
/*
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
     2
  This file is part of CanFestival, a library implementing CanOpen
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
     3
  Stack.
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
     4
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
     5
  Copyright (C): Edouard TISSERANT and Francis DUPIN
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
     6
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
     7
  See COPYING file for copyrights details.
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
     8
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
     9
  This library is free software; you can redistribute it and/or
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    10
  modify it under the terms of the GNU Lesser General Public
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    11
  License as published by the Free Software Foundation; either
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    12
  version 2.1 of the License, or (at your option) any later version.
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    13
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    14
  This library is distributed in the hope that it will be useful,
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    15
  but WITHOUT ANY WARRANTY; without even the implied warranty of
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    16
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    17
  Lesser General Public License for more details.
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    18
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    19
  You should have received a copy of the GNU Lesser General Public
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    20
  License along with this library; if not, write to the Free Software
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    21
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    22
  USA
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    23
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    24
#include "pdo.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    25
#include "objacces.h"
149
fe50ada8020b Changes in the API:
etisserant
parents: 90
diff changeset
    26
#include "canfestival.h"
370
6fecf36df407 Fixed some endianization problems caused by switch to UNS16 for cob_id member in CAN messages. To be continued.
etisserant
parents: 365
diff changeset
    27
#include "sysdep.h"
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    28
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    29
/*!
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    30
** @file   pdo.c
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    31
** @author Edouard TISSERANT and Francis DUPIN
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    32
** @date   Tue Jun  5 09:32:32 2007
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    33
**
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    34
** @brief
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    35
**
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    36
**
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    37
*/
235
f812bf6b7237 Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents: 217
diff changeset
    38
f812bf6b7237 Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents: 217
diff changeset
    39
/*!
f812bf6b7237 Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents: 217
diff changeset
    40
**
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    41
**
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    42
** @param d
235
f812bf6b7237 Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents: 217
diff changeset
    43
** @param TPDO_com TPDO communication parameters OD entry
f812bf6b7237 Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents: 217
diff changeset
    44
** @param TPDO_map TPDO mapping parameters OD entry
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    45
**
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    46
** @return
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    47
**/
235
f812bf6b7237 Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents: 217
diff changeset
    48
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
    49
UNS8
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
    50
buildPDO (CO_Data * d, UNS8 numPdo, Message * pdo)
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
    51
{
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
    52
  const indextable *TPDO_com = d->objdict + d->firstIndex->PDO_TRS + numPdo;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
    53
  const indextable *TPDO_map =
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
    54
    d->objdict + d->firstIndex->PDO_TRS_MAP + numPdo;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
    55
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
    56
  UNS8 prp_j = 0x00;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
    57
  UNS8 offset = 0x00;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
    58
  const UNS8 *pMappingCount = (UNS8 *) TPDO_map->pSubindex[0].pObject;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
    59
428
25b06f59f123 Endianization fix in pdo.c
etisserant
parents: 426
diff changeset
    60
  pdo->cob_id = UNS16_LE(*(UNS32*)TPDO_com->pSubindex[1].pObject & 0x7FF);
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
    61
  pdo->rtr = NOT_A_REQUEST;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
    62
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
    63
  MSG_WAR (0x3009, "  PDO CobId is : ",
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
    64
           *(UNS32 *) TPDO_com->pSubindex[1].pObject);
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
    65
  MSG_WAR (0x300D, "  Number of objects mapped : ", *pMappingCount);
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
    66
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
    67
  do
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
    68
    {
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
    69
      UNS8 dataType;            /* Unused */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
    70
      UNS8 tmp[] = { 0, 0, 0, 0, 0, 0, 0, 0 };  /* temporary space to hold bits */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
    71
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
    72
      /* pointer fo the var which holds the mapping parameter of an mapping entry  */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
    73
      UNS32 *pMappingParameter =
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
    74
        (UNS32 *) TPDO_map->pSubindex[prp_j + 1].pObject;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
    75
      UNS16 index = (UNS16) ((*pMappingParameter) >> 16);
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
    76
      UNS8 Size = (UNS8) (*pMappingParameter & (UNS32) 0x000000FF);     /* Size in bits */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
    77
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
    78
      /* get variable only if Size != 0 and Size is lower than remaining bits in the PDO */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
    79
      if (Size && ((offset + Size) <= 64))
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
    80
        {
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
    81
          UNS8 ByteSize = 1 + ((Size - 1) >> 3);        /*1->8 => 1 ; 9->16 => 2, ... */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
    82
          UNS8 subIndex =
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
    83
            (UNS8) (((*pMappingParameter) >> (UNS8) 8) & (UNS32) 0x000000FF);
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
    84
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
    85
          MSG_WAR (0x300F, "  got mapping parameter : ", *pMappingParameter);
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
    86
          MSG_WAR (0x3050, "    at index : ", TPDO_map->index);
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
    87
          MSG_WAR (0x3051, "    sub-index : ", prp_j + 1);
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
    88
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
    89
          if (getODentry (d, index, subIndex, tmp, &ByteSize, &dataType, 0) !=
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
    90
              OD_SUCCESSFUL)
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
    91
            {
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
    92
              MSG_ERR (0x1013,
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
    93
                       " Couldn't find mapped variable at index-subindex-size : ",
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
    94
                       (UNS16) (*pMappingParameter));
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
    95
              return 0xFF;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
    96
            }
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
    97
          /* copy bit per bit in little endian */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
    98
          CopyBits (Size, ((UNS8 *) tmp), 0, 0,
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
    99
                    (UNS8 *) & pdo->data[offset >> 3], offset % 8, 0);
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   100
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   101
          offset += Size;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   102
        }
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   103
      prp_j++;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   104
    }
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   105
  while (prp_j < *pMappingCount);
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   106
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   107
  pdo->len = 1 + ((offset - 1) >> 3);
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   108
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   109
  MSG_WAR (0x3015, "  End scan mapped variable", 0);
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   110
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   111
  return 0;
235
f812bf6b7237 Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents: 217
diff changeset
   112
}
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   113
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   114
/*!
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   115
**
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   116
**
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   117
** @param d
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   118
** @param cobId
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   119
**
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   120
** @return
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   121
**/
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   122
UNS8
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   123
sendPDOrequest (CO_Data * d, UNS16 RPDOIndex)
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   124
{
447
c9d01296d6d9 Endianess patch from Edward Karpicz, Lithuania :-)
etisserant
parents: 428
diff changeset
   125
  UNS32 *pwCobId;
236
905677ed00f3 Full preliminary implementation of TPDO transmit type:
etisserant
parents: 235
diff changeset
   126
  UNS16 offset = d->firstIndex->PDO_RCV;
905677ed00f3 Full preliminary implementation of TPDO transmit type:
etisserant
parents: 235
diff changeset
   127
  UNS16 lastIndex = d->lastIndex->PDO_RCV;
905677ed00f3 Full preliminary implementation of TPDO transmit type:
etisserant
parents: 235
diff changeset
   128
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   129
  /* Sending the request only if the cobid have been found on the PDO
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   130
     receive */
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   131
  /* part dictionary */
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   132
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   133
  MSG_WAR (0x3930, "sendPDOrequest RPDO Index : ", RPDOIndex);
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   134
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   135
  if (offset && RPDOIndex >= 0x1400)
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   136
    {
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   137
      offset += RPDOIndex - 0x1400;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   138
      if (offset <= lastIndex)
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   139
        {
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   140
          /* get the CobId */
447
c9d01296d6d9 Endianess patch from Edward Karpicz, Lithuania :-)
etisserant
parents: 428
diff changeset
   141
          pwCobId = d->objdict[offset].pSubindex[1].pObject;
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   142
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   143
          MSG_WAR (0x3930, "sendPDOrequest cobId is : ", *pwCobId);
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   144
          {
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   145
            Message pdo;
447
c9d01296d6d9 Endianess patch from Edward Karpicz, Lithuania :-)
etisserant
parents: 428
diff changeset
   146
            pdo.cob_id = UNS16_LE(*pwCobId);
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   147
            pdo.rtr = REQUEST;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   148
            pdo.len = 0;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   149
            return canSend (d->canHandle, &pdo);
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   150
          }
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   151
        }
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   152
    }
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   153
  MSG_ERR (0x1931, "sendPDOrequest : RPDO Index not found : ", RPDOIndex);
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   154
  return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   155
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   156
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   157
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   158
/*!
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   159
**
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   160
**
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   161
** @param d
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   162
** @param m
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   163
**
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   164
** @return
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   165
**/
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   166
UNS8
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   167
proceedPDO (CO_Data * d, Message * m)
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   168
{
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   169
  UNS8 numPdo;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   170
  UNS8 numMap;                  /* Number of the mapped varable */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   171
  UNS8 *pMappingCount = NULL;   /* count of mapped objects... */
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   172
  /* pointer to the var which is mapped to a pdo... */
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   173
  /*  void *     pMappedAppObject = NULL;   */
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   174
  /* pointer fo the var which holds the mapping parameter of an
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   175
     mapping entry */
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   176
  UNS32 *pMappingParameter = NULL;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   177
  UNS8 *pTransmissionType = NULL;       /* pointer to the transmission
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   178
                                           type */
447
c9d01296d6d9 Endianess patch from Edward Karpicz, Lithuania :-)
etisserant
parents: 428
diff changeset
   179
  UNS32 *pwCobId = NULL;
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   180
  UNS8 Size;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   181
  UNS8 offset;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   182
  UNS8 status;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   183
  UNS32 objDict;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   184
  UNS16 offsetObjdict;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   185
  UNS16 lastIndex;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   186
235
f812bf6b7237 Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents: 217
diff changeset
   187
  status = state2;
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   188
447
c9d01296d6d9 Endianess patch from Edward Karpicz, Lithuania :-)
etisserant
parents: 428
diff changeset
   189
  MSG_WAR (0x3935, "proceedPDO, cobID : ", (UNS16_LE(m->cob_id) & 0x7ff));
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   190
  offset = 0x00;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   191
  numPdo = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   192
  numMap = 0;
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   193
  if ((*m).rtr == NOT_A_REQUEST)
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   194
    {                           /* The PDO received is not a
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   195
                                   request. */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   196
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   197
      offsetObjdict = d->firstIndex->PDO_RCV;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   198
      lastIndex = d->lastIndex->PDO_RCV;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   199
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   200
      /* study of all the PDO stored in the dictionary */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   201
      if (offsetObjdict)
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   202
        while (offsetObjdict <= lastIndex)
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   203
          {
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   204
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   205
            switch (status)
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   206
              {
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   207
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   208
              case state2:
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   209
                /* get CobId of the dictionary correspondant to the received
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   210
                   PDO */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   211
                pwCobId =
447
c9d01296d6d9 Endianess patch from Edward Karpicz, Lithuania :-)
etisserant
parents: 428
diff changeset
   212
                  d->objdict[offsetObjdict].pSubindex[1].pObject;
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   213
                /* check the CobId coherance */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   214
                /*pwCobId is the cobId read in the dictionary at the state 3
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   215
                 */
447
c9d01296d6d9 Endianess patch from Edward Karpicz, Lithuania :-)
etisserant
parents: 428
diff changeset
   216
                if (*pwCobId == UNS16_LE(m->cob_id))
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   217
                  {
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   218
                    /* The cobId is recognized */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   219
                    status = state4;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   220
                    MSG_WAR (0x3936, "cobId found at index ",
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   221
                             0x1400 + numPdo);
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   222
                    break;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   223
                  }
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   224
                else
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   225
                  {
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   226
                    /* cobId received does not match with those write in the
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   227
                       dictionnary */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   228
                    numPdo++;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   229
                    offsetObjdict++;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   230
                    status = state2;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   231
                    break;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   232
                  }
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   233
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   234
              case state4:     /* Get Mapped Objects Number */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   235
                /* The cobId of the message received has been found in the
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   236
                   dictionnary. */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   237
                offsetObjdict = d->firstIndex->PDO_RCV_MAP;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   238
                lastIndex = d->lastIndex->PDO_RCV_MAP;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   239
                pMappingCount =
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   240
                  (UNS8 *) (d->objdict + offsetObjdict +
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   241
                            numPdo)->pSubindex[0].pObject;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   242
                numMap = 0;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   243
                while (numMap < *pMappingCount)
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   244
                  {
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   245
                    UNS8 tmp[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   246
                    UNS8 ByteSize;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   247
                    pMappingParameter =
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   248
                      (UNS32 *) (d->objdict + offsetObjdict +
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   249
                                 numPdo)->pSubindex[numMap + 1].pObject;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   250
                    if (pMappingParameter == NULL)
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   251
                      {
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   252
                        MSG_ERR (0x1937, "Couldn't get mapping parameter : ",
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   253
                                 numMap + 1);
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   254
                        return 0xFF;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   255
                      }
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   256
                    /* Get the addresse of the mapped variable. */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   257
                    /* detail of *pMappingParameter : */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   258
                    /* The 16 hight bits contains the index, the medium 8 bits
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   259
                       contains the subindex, */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   260
                    /* and the lower 8 bits contains the size of the mapped
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   261
                       variable. */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   262
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   263
                    Size = (UNS8) (*pMappingParameter & (UNS32) 0x000000FF);
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   264
497
a040156aa72f cosmetic changes to pdo.c
etisserant
parents: 474
diff changeset
   265
                    /* set variable only if Size != 0 and 
a040156aa72f cosmetic changes to pdo.c
etisserant
parents: 474
diff changeset
   266
                     * Size is lower than remaining bits in the PDO */
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   267
                    if (Size && ((offset + Size) <= (m->len << 3)))
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   268
                      {
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   269
                        /* copy bit per bit in little endian */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   270
                        CopyBits (Size, (UNS8 *) & m->data[offset >> 3],
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   271
                                  offset % 8, 0, ((UNS8 *) tmp), 0, 0);
497
a040156aa72f cosmetic changes to pdo.c
etisserant
parents: 474
diff changeset
   272
                        /*1->8 => 1 ; 9->16 =>2, ... */
a040156aa72f cosmetic changes to pdo.c
etisserant
parents: 474
diff changeset
   273
                        ByteSize = 1 + ((Size - 1) >> 3);
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   274
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   275
                        objDict =
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   276
                          setODentry (d, (UNS16) ((*pMappingParameter) >> 16),
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   277
                                      (UNS8) (((*pMappingParameter) >> 8) &
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   278
                                              0xFF), tmp, &ByteSize, 0);
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   279
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   280
                        if (objDict != OD_SUCCESSFUL)
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   281
                          {
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   282
                            MSG_ERR (0x1938,
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   283
                                     "error accessing to the mapped var : ",
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   284
                                     numMap + 1);
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   285
                            MSG_WAR (0x2939, "         Mapped at index : ",
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   286
                                     (*pMappingParameter) >> 16);
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   287
                            MSG_WAR (0x2940, "                subindex : ",
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   288
                                     ((*pMappingParameter) >> 8) & 0xFF);
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   289
                            return 0xFF;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   290
                          }
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   291
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   292
                        MSG_WAR (0x3942,
497
a040156aa72f cosmetic changes to pdo.c
etisserant
parents: 474
diff changeset
   293
                                 "Variable updated by PDO cobid : ",
447
c9d01296d6d9 Endianess patch from Edward Karpicz, Lithuania :-)
etisserant
parents: 428
diff changeset
   294
                                 UNS16_LE(m->cob_id));
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   295
                        MSG_WAR (0x3943, "         Mapped at index : ",
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   296
                                 (*pMappingParameter) >> 16);
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   297
                        MSG_WAR (0x3944, "                subindex : ",
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   298
                                 ((*pMappingParameter) >> 8) & 0xFF);
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   299
                        offset += Size;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   300
                      }
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   301
                    numMap++;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   302
                  }             /* end loop while on mapped variables */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   303
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   304
                return 0;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   305
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   306
              }                 /* end switch status */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   307
          }                     /* end while */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   308
    }                           /* end if Donnees */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   309
  else if ((*m).rtr == REQUEST)
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   310
    {
447
c9d01296d6d9 Endianess patch from Edward Karpicz, Lithuania :-)
etisserant
parents: 428
diff changeset
   311
      MSG_WAR (0x3946, "Receive a PDO request cobId : ", UNS16_LE(m->cob_id));
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   312
      status = state1;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   313
      offsetObjdict = d->firstIndex->PDO_TRS;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   314
      lastIndex = d->lastIndex->PDO_TRS;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   315
      if (offsetObjdict)
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   316
        while (offsetObjdict <= lastIndex)
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   317
          {
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   318
            /* study of all PDO stored in the objects dictionary */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   319
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   320
            switch (status)
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   321
              {
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   322
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   323
              case state1:     /* check the CobId */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   324
                /* get CobId of the dictionary which match to the received PDO
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   325
                 */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   326
                pwCobId =
447
c9d01296d6d9 Endianess patch from Edward Karpicz, Lithuania :-)
etisserant
parents: 428
diff changeset
   327
                   (d->objdict +
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   328
                             offsetObjdict)->pSubindex[1].pObject;
447
c9d01296d6d9 Endianess patch from Edward Karpicz, Lithuania :-)
etisserant
parents: 428
diff changeset
   329
                if (*pwCobId == UNS16_LE(m->cob_id))
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   330
                  {
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   331
                    status = state4;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   332
                    break;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   333
                  }
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   334
                else
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   335
                  {
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   336
                    numPdo++;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   337
                    offsetObjdict++;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   338
                  }
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   339
                status = state1;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   340
                break;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   341
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   342
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   343
              case state4:     /* check transmission type */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   344
                pTransmissionType =
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   345
                  (UNS8 *) d->objdict[offsetObjdict].pSubindex[2].pObject;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   346
                /* If PDO is to be sampled and send on RTR, do it */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   347
                if ((*pTransmissionType == TRANS_RTR))
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   348
                  {
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   349
                    status = state5;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   350
                    break;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   351
                  }
497
a040156aa72f cosmetic changes to pdo.c
etisserant
parents: 474
diff changeset
   352
                /* RTR_SYNC means data prepared at SYNC, transmitted on RTR */
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   353
                else if ((*pTransmissionType == TRANS_RTR_SYNC))
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   354
                  {
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   355
                    if (d->PDO_status[numPdo].
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   356
                        transmit_type_parameter & PDO_RTR_SYNC_READY)
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   357
                      {
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   358
                        /*Data ready, just send */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   359
                        canSend (d->canHandle,
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   360
                                 &d->PDO_status[numPdo].last_message);
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   361
                        return 0;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   362
                      }
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   363
                    else
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   364
                      {
497
a040156aa72f cosmetic changes to pdo.c
etisserant
parents: 474
diff changeset
   365
                        /* if SYNC did never occur, transmit current data */
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   366
                        /* DS301 do not tell what to do in such a case... */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   367
                        MSG_ERR (0x1947,
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   368
                                 "Not ready RTR_SYNC TPDO send current data : ",
447
c9d01296d6d9 Endianess patch from Edward Karpicz, Lithuania :-)
etisserant
parents: 428
diff changeset
   369
                                 UNS16_LE(m->cob_id));
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   370
                        status = state5;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   371
                      }
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   372
                    break;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   373
                  }
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   374
                else if ((*pTransmissionType == TRANS_EVENT_PROFILE) ||
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   375
                         (*pTransmissionType == TRANS_EVENT_SPECIFIC))
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   376
                  {
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   377
                    /* Zap all timers and inhibit flag */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   378
                    d->PDO_status[numPdo].event_timer =
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   379
                      DelAlarm (d->PDO_status[numPdo].event_timer);
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   380
                    d->PDO_status[numPdo].inhibit_timer =
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   381
                      DelAlarm (d->PDO_status[numPdo].inhibit_timer);
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   382
                    d->PDO_status[numPdo].transmit_type_parameter &=
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   383
                      ~PDO_INHIBITED;
497
a040156aa72f cosmetic changes to pdo.c
etisserant
parents: 474
diff changeset
   384
                    /* Call  PDOEventTimerAlarm for this TPDO, 
a040156aa72f cosmetic changes to pdo.c
etisserant
parents: 474
diff changeset
   385
                     * this will trigger emission et reset timers */
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   386
                    PDOEventTimerAlarm (d, numPdo);
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   387
                    return 0;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   388
                  }
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   389
                else
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   390
                  {
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   391
                    /* The requested PDO is not to send on request. So, does
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   392
                       nothing. */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   393
                    MSG_WAR (0x2947, "PDO is not to send on request : ",
447
c9d01296d6d9 Endianess patch from Edward Karpicz, Lithuania :-)
etisserant
parents: 428
diff changeset
   394
                             UNS16_LE(m->cob_id));
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   395
                    return 0xFF;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   396
                  }
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   397
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   398
              case state5:     /* build and send requested PDO */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   399
                {
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   400
                  Message pdo;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   401
                  if (buildPDO (d, numPdo, &pdo))
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   402
                    {
447
c9d01296d6d9 Endianess patch from Edward Karpicz, Lithuania :-)
etisserant
parents: 428
diff changeset
   403
                      MSG_ERR (0x1948, " Couldn't build TPDO n�", numPdo);
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   404
                      return 0xFF;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   405
                    }
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   406
                  canSend (d->canHandle, &pdo);
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   407
                  return 0;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   408
                }
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   409
              }                 /* end switch status */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   410
          }                     /* end while */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   411
    }                           /* end if Requete */
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   412
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   413
  return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   414
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   415
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   416
/*!
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   417
**
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   418
**
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   419
** @param NbBits
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   420
** @param SrcByteIndex
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   421
** @param SrcBitIndex
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   422
** @param SrcBigEndian
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   423
** @param DestByteIndex
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   424
** @param DestBitIndex
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   425
** @param DestBigEndian
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   426
**/
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   427
void
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   428
CopyBits (UNS8 NbBits, UNS8 * SrcByteIndex, UNS8 SrcBitIndex,
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   429
          UNS8 SrcBigEndian, UNS8 * DestByteIndex, UNS8 DestBitIndex,
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   430
          UNS8 DestBigEndian)
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   431
{
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   432
  /* This loop copy as many bits that it can each time, crossing */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   433
  /* successively bytes */
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   434
  // boundaries from LSB to MSB.
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   435
  while (NbBits > 0)
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   436
    {
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   437
      /* Bit missalignement between src and dest */
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   438
      INTEGER8 Vect = DestBitIndex - SrcBitIndex;
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   439
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   440
      /* We can now get src and align it to dest */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   441
      UNS8 Aligned =
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   442
        Vect > 0 ? *SrcByteIndex << Vect : *SrcByteIndex >> -Vect;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   443
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   444
      /* Compute the nb of bit we will be able to copy */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   445
      UNS8 BoudaryLimit = (Vect > 0 ? 8 - DestBitIndex : 8 - SrcBitIndex);
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   446
      UNS8 BitsToCopy = BoudaryLimit > NbBits ? NbBits : BoudaryLimit;
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   447
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   448
      /* Create a mask that will serve in: */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   449
      UNS8 Mask =
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   450
        ((0xff << (DestBitIndex + BitsToCopy)) |
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   451
         (0xff >> (8 - DestBitIndex)));
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   452
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   453
      /* - Filtering src */
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   454
      UNS8 Filtered = Aligned & ~Mask;
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   455
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   456
      /* - and erase bits where we write, preserve where we don't */
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   457
      *DestByteIndex &= Mask;
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   458
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   459
      /* Then write. */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   460
      *DestByteIndex |= Filtered;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   461
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   462
      /*Compute next time cursors for src */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   463
      if ((SrcBitIndex += BitsToCopy) > 7)      /* cross boundary ? */
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   464
        {
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   465
          SrcBitIndex = 0;      /* First bit */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   466
          SrcByteIndex += (SrcBigEndian ? -1 : 1);      /* Next byte */
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   467
        }
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   468
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   469
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   470
      /*Compute next time cursors for dest */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   471
      if ((DestBitIndex += BitsToCopy) > 7)
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   472
        {
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   473
          DestBitIndex = 0;     /* First bit */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   474
          DestByteIndex += (DestBigEndian ? -1 : 1);    /* Next byte */
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   475
        }
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   476
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   477
      /*And decrement counter. */
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   478
      NbBits -= BitsToCopy;
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   479
    }
201
2966cd34162a Boolean variable mapped in PDO
greg
parents: 149
diff changeset
   480
2966cd34162a Boolean variable mapped in PDO
greg
parents: 149
diff changeset
   481
}
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   482
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   483
/*!
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   484
**
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   485
**
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   486
** @param d
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   487
**
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   488
** @return
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   489
**/
235
f812bf6b7237 Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents: 217
diff changeset
   490
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   491
UNS8
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   492
sendPDOevent (CO_Data * d)
235
f812bf6b7237 Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents: 217
diff changeset
   493
{
f812bf6b7237 Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents: 217
diff changeset
   494
  /* Calls _sendPDOevent specifying it is not a sync event */
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   495
  return _sendPDOevent (d, 0);
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   496
}
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   497
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   498
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   499
void
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   500
PDOEventTimerAlarm (CO_Data * d, UNS32 pdoNum)
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   501
{
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   502
  /* This is needed to avoid deletion of re-attribuated timer */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   503
  d->PDO_status[pdoNum].event_timer = TIMER_NONE;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   504
  /* force emission of PDO by artificially changing last emitted */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   505
  d->PDO_status[pdoNum].last_message.cob_id = 0;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   506
  _sendPDOevent (d, 0);         /* not a Sync Event */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   507
}
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   508
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   509
void
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   510
PDOInhibitTimerAlarm (CO_Data * d, UNS32 pdoNum)
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   511
{
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   512
  /* This is needed to avoid deletion of re-attribuated timer */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   513
  d->PDO_status[pdoNum].inhibit_timer = TIMER_NONE;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   514
  /* Remove inhibit flag */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   515
  d->PDO_status[pdoNum].transmit_type_parameter &= ~PDO_INHIBITED;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   516
  _sendPDOevent (d, 0);         /* not a Sync Event */
235
f812bf6b7237 Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents: 217
diff changeset
   517
}
f812bf6b7237 Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents: 217
diff changeset
   518
f812bf6b7237 Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents: 217
diff changeset
   519
/*!
f812bf6b7237 Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents: 217
diff changeset
   520
**
f812bf6b7237 Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents: 217
diff changeset
   521
**
f812bf6b7237 Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents: 217
diff changeset
   522
** @param d
f812bf6b7237 Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents: 217
diff changeset
   523
** @param isSyncEvent
f812bf6b7237 Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents: 217
diff changeset
   524
**
f812bf6b7237 Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents: 217
diff changeset
   525
** @return
f812bf6b7237 Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents: 217
diff changeset
   526
**/
f812bf6b7237 Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents: 217
diff changeset
   527
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   528
UNS8
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   529
_sendPDOevent (CO_Data * d, UNS8 isSyncEvent)
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   530
{
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   531
  UNS8 pdoNum = 0x00;           /* number of the actual processed pdo-nr. */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   532
  UNS8 *pTransmissionType = NULL;
235
f812bf6b7237 Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents: 217
diff changeset
   533
  UNS8 status = state3;
f812bf6b7237 Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents: 217
diff changeset
   534
  UNS16 offsetObjdict = d->firstIndex->PDO_TRS;
f812bf6b7237 Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents: 217
diff changeset
   535
  UNS16 offsetObjdictMap = d->firstIndex->PDO_TRS_MAP;
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   536
  UNS16 lastIndex = d->lastIndex->PDO_TRS;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   537
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   538
  /* study all PDO stored in the objects dictionary */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   539
  if (offsetObjdict)
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   540
    {
497
a040156aa72f cosmetic changes to pdo.c
etisserant
parents: 474
diff changeset
   541
      Message pdo;/* = Message_Initializer;*/
a040156aa72f cosmetic changes to pdo.c
etisserant
parents: 474
diff changeset
   542
      memset(&pdo, 0, sizeof(pdo));
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   543
      while (offsetObjdict <= lastIndex)
235
f812bf6b7237 Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents: 217
diff changeset
   544
        {
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   545
          switch (status)
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   546
            {
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   547
            case state3:
497
a040156aa72f cosmetic changes to pdo.c
etisserant
parents: 474
diff changeset
   548
              if ( /* bSubCount always 5 with objdictedit -> check disabled */
a040156aa72f cosmetic changes to pdo.c
etisserant
parents: 474
diff changeset
   549
                   /*d->objdict[offsetObjdict].bSubCount < 5 ||*/
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   550
                   /* check if TPDO is not valid */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   551
                   *(UNS32 *) d->objdict[offsetObjdict].pSubindex[1].
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   552
                   pObject & 0x80000000)
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   553
                {
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   554
                  MSG_WAR (0x3960, "Not a valid PDO ", 0x1800 + pdoNum);
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   555
                  /*Go next TPDO */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   556
                  status = state11;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   557
                  break;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   558
                }
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   559
              /* get the PDO transmission type */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   560
              pTransmissionType =
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   561
                (UNS8 *) d->objdict[offsetObjdict].pSubindex[2].pObject;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   562
              MSG_WAR (0x3962, "Reading PDO at index : ", 0x1800 + pdoNum);
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   563
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   564
              /* check if transmission type is SYNCRONOUS */
497
a040156aa72f cosmetic changes to pdo.c
etisserant
parents: 474
diff changeset
   565
              /* message transmited every n SYNC with n=TransmissionType */
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   566
              if (isSyncEvent &&
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   567
                  (*pTransmissionType >= TRANS_SYNC_MIN) &&
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   568
                  (*pTransmissionType <= TRANS_SYNC_MAX) &&
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   569
                  (++d->PDO_status[pdoNum].transmit_type_parameter ==
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   570
                   *pTransmissionType))
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   571
                {
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   572
                  /*Reset count of SYNC */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   573
                  d->PDO_status[pdoNum].transmit_type_parameter = 0;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   574
                  MSG_WAR (0x3964, "  PDO is on SYNCHRO. Trans type : ",
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   575
                           *pTransmissionType);
497
a040156aa72f cosmetic changes to pdo.c
etisserant
parents: 474
diff changeset
   576
                  memset(&pdo, 0, sizeof(pdo));
a040156aa72f cosmetic changes to pdo.c
etisserant
parents: 474
diff changeset
   577
                  /*{
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   578
                    Message msg_init = Message_Initializer;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   579
                    pdo = msg_init;
497
a040156aa72f cosmetic changes to pdo.c
etisserant
parents: 474
diff changeset
   580
                  }*/
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   581
                  if (buildPDO (d, pdoNum, &pdo))
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   582
                    {
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   583
                      MSG_ERR (0x1906, " Couldn't build TPDO number : ",
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   584
                               pdoNum);
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   585
                      status = state11;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   586
                      break;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   587
                    }
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   588
                  status = state5;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   589
                  /* If transmission RTR, with data sampled on SYNC */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   590
                }
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   591
              else if (isSyncEvent && (*pTransmissionType == TRANS_RTR_SYNC))
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   592
                {
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   593
                  if (buildPDO
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   594
                      (d, pdoNum, &d->PDO_status[pdoNum].last_message))
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   595
                    {
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   596
                      MSG_ERR (0x1966, " Couldn't build TPDO number : ",
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   597
                               pdoNum);
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   598
                      d->PDO_status[pdoNum].transmit_type_parameter &=
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   599
                        ~PDO_RTR_SYNC_READY;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   600
                    }
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   601
                  else
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   602
                    {
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   603
                      d->PDO_status[pdoNum].transmit_type_parameter |=
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   604
                        PDO_RTR_SYNC_READY;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   605
                    }
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   606
                  status = state11;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   607
                  break;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   608
                  /* If transmission on Event and not inhibited, check for changes */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   609
                }
426
8011552b1319 Preliminary support for TRANS_SYNC_ACYCLIC (0) transmit type.
etisserant
parents: 425
diff changeset
   610
              else
8011552b1319 Preliminary support for TRANS_SYNC_ACYCLIC (0) transmit type.
etisserant
parents: 425
diff changeset
   611
                if ((isSyncEvent
8011552b1319 Preliminary support for TRANS_SYNC_ACYCLIC (0) transmit type.
etisserant
parents: 425
diff changeset
   612
                     && (*pTransmissionType == TRANS_SYNC_ACYCLIC))
8011552b1319 Preliminary support for TRANS_SYNC_ACYCLIC (0) transmit type.
etisserant
parents: 425
diff changeset
   613
                    ||
8011552b1319 Preliminary support for TRANS_SYNC_ACYCLIC (0) transmit type.
etisserant
parents: 425
diff changeset
   614
                    ((*pTransmissionType == TRANS_EVENT_PROFILE
8011552b1319 Preliminary support for TRANS_SYNC_ACYCLIC (0) transmit type.
etisserant
parents: 425
diff changeset
   615
                      || *pTransmissionType == TRANS_EVENT_SPECIFIC)
8011552b1319 Preliminary support for TRANS_SYNC_ACYCLIC (0) transmit type.
etisserant
parents: 425
diff changeset
   616
                     && !(d->PDO_status[pdoNum].
8011552b1319 Preliminary support for TRANS_SYNC_ACYCLIC (0) transmit type.
etisserant
parents: 425
diff changeset
   617
                          transmit_type_parameter & PDO_INHIBITED)))
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   618
                {
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   619
                  MSG_WAR (0x3968, "  PDO is on EVENT. Trans type : ",
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   620
                           *pTransmissionType);
497
a040156aa72f cosmetic changes to pdo.c
etisserant
parents: 474
diff changeset
   621
                  memset(&pdo, 0, sizeof(pdo));
a040156aa72f cosmetic changes to pdo.c
etisserant
parents: 474
diff changeset
   622
                  /*{
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   623
                    Message msg_init = Message_Initializer;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   624
                    pdo = msg_init;
497
a040156aa72f cosmetic changes to pdo.c
etisserant
parents: 474
diff changeset
   625
                  }*/
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   626
                  if (buildPDO (d, pdoNum, &pdo))
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   627
                    {
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   628
                      MSG_ERR (0x3907, " Couldn't build TPDO number : ",
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   629
                               pdoNum);
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   630
                      status = state11;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   631
                      break;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   632
                    }
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   633
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   634
                  /*Compare new and old PDO */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   635
                  if (d->PDO_status[pdoNum].last_message.cob_id == pdo.cob_id
497
a040156aa72f cosmetic changes to pdo.c
etisserant
parents: 474
diff changeset
   636
                      && d->PDO_status[pdoNum].last_message.len == pdo.len
a040156aa72f cosmetic changes to pdo.c
etisserant
parents: 474
diff changeset
   637
                      && memcmp(d->PDO_status[pdoNum].last_message.data, 
474
09c8c4b6c7df Fixed alignments problems on some 32bit target such as ARM or Xscale.
etisserant
parents: 447
diff changeset
   638
							pdo.data, 8) == 0
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   639
                    )
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   640
                    {
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   641
                      /* No changes -> go to next pdo */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   642
                      status = state11;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   643
                    }
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   644
                  else
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   645
                    {
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   646
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   647
                      UNS16 EventTimerDuration;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   648
                      UNS16 InhibitTimerDuration;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   649
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   650
                      MSG_WAR (0x306A, "Changes TPDO number : ", pdoNum);
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   651
                      /* Changes detected -> transmit message */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   652
                      EventTimerDuration =
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   653
                        *(UNS16 *) d->objdict[offsetObjdict].pSubindex[5].
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   654
                        pObject;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   655
                      InhibitTimerDuration =
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   656
                        *(UNS16 *) d->objdict[offsetObjdict].pSubindex[3].
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   657
                        pObject;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   658
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   659
                      status = state5;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   660
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   661
                      /* Start both event_timer and inhibit_timer */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   662
                      if (EventTimerDuration)
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   663
                        {
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   664
                          DelAlarm (d->PDO_status[pdoNum].event_timer);
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   665
                          d->PDO_status[pdoNum].event_timer =
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   666
                            SetAlarm (d, pdoNum, &PDOEventTimerAlarm,
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   667
                                      MS_TO_TIMEVAL (EventTimerDuration), 0);
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   668
                        }
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   669
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   670
                      if (InhibitTimerDuration)
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   671
                        {
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   672
                          DelAlarm (d->PDO_status[pdoNum].inhibit_timer);
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   673
                          d->PDO_status[pdoNum].inhibit_timer =
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   674
                            SetAlarm (d, pdoNum, &PDOInhibitTimerAlarm,
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   675
                                      US_TO_TIMEVAL (InhibitTimerDuration *
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   676
                                                     100), 0);
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   677
                          /* and inhibit TPDO */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   678
                          d->PDO_status[pdoNum].transmit_type_parameter |=
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   679
                            PDO_INHIBITED;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   680
                        }
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   681
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   682
                    }
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   683
                }
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   684
              else
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   685
                {
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   686
                  MSG_WAR (0x306C,
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   687
                           "  PDO is not on EVENT or synchro or not at this SYNC. Trans type : ",
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   688
                           *pTransmissionType);
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   689
                  status = state11;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   690
                }
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   691
              break;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   692
            case state5:       /*Send the pdo */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   693
              /*store_as_last_message */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   694
              d->PDO_status[pdoNum].last_message = pdo;
447
c9d01296d6d9 Endianess patch from Edward Karpicz, Lithuania :-)
etisserant
parents: 428
diff changeset
   695
              MSG_WAR (0x396D, "sendPDO cobId :", UNS16_LE(pdo.cob_id));
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   696
              MSG_WAR (0x396E, "     Nb octets  : ", pdo.len);
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   697
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   698
              canSend (d->canHandle, &pdo);
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   699
              status = state11;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   700
              break;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   701
            case state11:      /*Go to next TPDO */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   702
              pdoNum++;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   703
              offsetObjdict++;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   704
              offsetObjdictMap++;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   705
              MSG_WAR (0x3970, "next pdo index : ", pdoNum);
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   706
              status = state3;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   707
              break;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   708
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   709
            default:
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   710
              MSG_ERR (0x1972, "Unknown state has been reached : %d", status);
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   711
              return 0xFF;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   712
            }                   /* end switch case */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   713
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   714
        }                       /* end while */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   715
    }
235
f812bf6b7237 Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents: 217
diff changeset
   716
  return 0;
f812bf6b7237 Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents: 217
diff changeset
   717
}
f812bf6b7237 Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents: 217
diff changeset
   718
236
905677ed00f3 Full preliminary implementation of TPDO transmit type:
etisserant
parents: 235
diff changeset
   719
/*!
905677ed00f3 Full preliminary implementation of TPDO transmit type:
etisserant
parents: 235
diff changeset
   720
**
905677ed00f3 Full preliminary implementation of TPDO transmit type:
etisserant
parents: 235
diff changeset
   721
**
905677ed00f3 Full preliminary implementation of TPDO transmit type:
etisserant
parents: 235
diff changeset
   722
** @param d
905677ed00f3 Full preliminary implementation of TPDO transmit type:
etisserant
parents: 235
diff changeset
   723
** @param OD_entry
905677ed00f3 Full preliminary implementation of TPDO transmit type:
etisserant
parents: 235
diff changeset
   724
** @param bSubindex 
905677ed00f3 Full preliminary implementation of TPDO transmit type:
etisserant
parents: 235
diff changeset
   725
** @return always 0
905677ed00f3 Full preliminary implementation of TPDO transmit type:
etisserant
parents: 235
diff changeset
   726
**/
905677ed00f3 Full preliminary implementation of TPDO transmit type:
etisserant
parents: 235
diff changeset
   727
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   728
UNS32
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   729
TPDO_Communication_Parameter_Callback (CO_Data * d,
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   730
                                       const indextable * OD_entry,
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   731
                                       UNS8 bSubindex)
236
905677ed00f3 Full preliminary implementation of TPDO transmit type:
etisserant
parents: 235
diff changeset
   732
{
905677ed00f3 Full preliminary implementation of TPDO transmit type:
etisserant
parents: 235
diff changeset
   733
  /* If PDO are actives */
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   734
  if (d->CurrentCommunicationState.csPDO)
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   735
    switch (bSubindex)
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   736
      {
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   737
      case 2:                  /* Changed transmition type */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   738
      case 3:                  /* Changed inhibit time */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   739
      case 5:                  /* Changed event time */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   740
        {
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   741
          const indextable *TPDO_com = d->objdict + d->firstIndex->PDO_TRS;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   742
          UNS8 numPdo = OD_entry - TPDO_com;    /* number of the actual processed pdo-nr. */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   743
236
905677ed00f3 Full preliminary implementation of TPDO transmit type:
etisserant
parents: 235
diff changeset
   744
          /* Zap all timers and inhibit flag */
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   745
          d->PDO_status[numPdo].event_timer =
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   746
            DelAlarm (d->PDO_status[numPdo].event_timer);
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   747
          d->PDO_status[numPdo].inhibit_timer =
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   748
            DelAlarm (d->PDO_status[numPdo].inhibit_timer);
236
905677ed00f3 Full preliminary implementation of TPDO transmit type:
etisserant
parents: 235
diff changeset
   749
          d->PDO_status[numPdo].transmit_type_parameter = 0;
905677ed00f3 Full preliminary implementation of TPDO transmit type:
etisserant
parents: 235
diff changeset
   750
          /* Call  PDOEventTimerAlarm for this TPDO, this will trigger emission et reset timers */
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   751
          PDOEventTimerAlarm (d, numPdo);
236
905677ed00f3 Full preliminary implementation of TPDO transmit type:
etisserant
parents: 235
diff changeset
   752
          return 0;
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   753
        }
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   754
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   755
      default:                 /* other subindex are ignored */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   756
        break;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   757
      }
236
905677ed00f3 Full preliminary implementation of TPDO transmit type:
etisserant
parents: 235
diff changeset
   758
  return 0;
905677ed00f3 Full preliminary implementation of TPDO transmit type:
etisserant
parents: 235
diff changeset
   759
}
905677ed00f3 Full preliminary implementation of TPDO transmit type:
etisserant
parents: 235
diff changeset
   760
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   761
void
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   762
PDOInit (CO_Data * d)
235
f812bf6b7237 Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents: 217
diff changeset
   763
{
236
905677ed00f3 Full preliminary implementation of TPDO transmit type:
etisserant
parents: 235
diff changeset
   764
  /* For each TPDO mapping parameters */
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   765
  UNS16 pdoIndex = 0x1800;      /* OD index of TDPO */
236
905677ed00f3 Full preliminary implementation of TPDO transmit type:
etisserant
parents: 235
diff changeset
   766
905677ed00f3 Full preliminary implementation of TPDO transmit type:
etisserant
parents: 235
diff changeset
   767
  UNS16 offsetObjdict = d->firstIndex->PDO_TRS;
905677ed00f3 Full preliminary implementation of TPDO transmit type:
etisserant
parents: 235
diff changeset
   768
  UNS16 lastIndex = d->lastIndex->PDO_TRS;
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   769
  if (offsetObjdict)
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   770
    while (offsetObjdict <= lastIndex)
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   771
      {
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   772
        /* Assign callbacks to sensible TPDO mapping subindexes */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   773
        UNS32 errorCode;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   774
        ODCallback_t *CallbackList;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   775
        /* Find callback list */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   776
        scanIndexOD (d, pdoIndex, &errorCode, &CallbackList);
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   777
        if (errorCode == OD_SUCCESSFUL && CallbackList)
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   778
          {
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   779
            /*Assign callbacks to corresponding subindex */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   780
            /* Transmission type */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   781
            CallbackList[2] = &TPDO_Communication_Parameter_Callback;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   782
            /* Inhibit time */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   783
            CallbackList[3] = &TPDO_Communication_Parameter_Callback;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   784
            /* Event timer */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   785
            CallbackList[5] = &TPDO_Communication_Parameter_Callback;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   786
          }
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   787
        pdoIndex++;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   788
        offsetObjdict++;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   789
      }
236
905677ed00f3 Full preliminary implementation of TPDO transmit type:
etisserant
parents: 235
diff changeset
   790
905677ed00f3 Full preliminary implementation of TPDO transmit type:
etisserant
parents: 235
diff changeset
   791
  /* Trigger a non-sync event */
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   792
  _sendPDOevent (d, 0);
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   793
}
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   794
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   795
void
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   796
PDOStop (CO_Data * d)
235
f812bf6b7237 Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents: 217
diff changeset
   797
{
236
905677ed00f3 Full preliminary implementation of TPDO transmit type:
etisserant
parents: 235
diff changeset
   798
  /* For each TPDO mapping parameters */
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   799
  UNS8 pdoNum = 0x00;           /* number of the actual processed pdo-nr. */
235
f812bf6b7237 Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents: 217
diff changeset
   800
  UNS16 offsetObjdict = d->firstIndex->PDO_TRS;
f812bf6b7237 Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents: 217
diff changeset
   801
  UNS16 lastIndex = d->lastIndex->PDO_TRS;
425
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   802
  if (offsetObjdict)
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   803
    while (offsetObjdict <= lastIndex)
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   804
      {
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   805
        /* Delete TPDO timers */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   806
        d->PDO_status[pdoNum].event_timer =
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   807
          DelAlarm (d->PDO_status[pdoNum].event_timer);
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   808
        d->PDO_status[pdoNum].inhibit_timer =
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   809
          DelAlarm (d->PDO_status[pdoNum].inhibit_timer);
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   810
        /* Reset transmit type parameter */
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   811
        d->PDO_status[pdoNum].transmit_type_parameter = 0;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   812
        d->PDO_status[pdoNum].last_message.cob_id = 0;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   813
        pdoNum++;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   814
        offsetObjdict++;
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   815
      }
4bc4706528ae re-indented pdo.c
etisserant
parents: 380
diff changeset
   816
}