add support for legacy static PDO mapping

Add possibility to use static PDO mapping. Upgrade XMC43 bare-metal
example to SOESv3.0 and use the static mapping.
pull/52/head
Andreas Karlsson 2019-04-09 12:05:20 +02:00 committed by Hans-Erik Floryd
parent 5770a66558
commit e600a515c5
6 changed files with 111 additions and 47 deletions

View File

@ -38,7 +38,7 @@
#define MAX_RXPDO_SIZE 42
#define MAX_TXPDO_SIZE 42
#define MAX_MAPPINGS_SM2 1
#define MAX_MAPPINGS_SM3 2
#define MAX_MAPPINGS_SM2 0
#define MAX_MAPPINGS_SM3 0
#endif /* __ECAT_OPTIONS_H__ */

View File

@ -24,6 +24,9 @@ _Rbuffer Rb;
_Wbuffer Wb;
_Cbuffer Cb;
uint8_t * rxpdo = (uint8_t *)&Wb.LED;
uint8_t * txpdo = (uint8_t *)&Rb.button;
uint32_t encoder_scale;
uint32_t encoder_scale_mirror;

View File

@ -16,21 +16,27 @@
#include <cc.h>
CC_PACKED_BEGIN
typedef struct
{
uint8_t state;
uint8_t button;
uint32_t encoder;
} _Rbuffer;
}CC_PACKED _Rbuffer;
CC_PACKED_END
CC_PACKED_BEGIN
typedef struct
{
uint8_t LED;
} _Wbuffer;
}CC_PACKED _Wbuffer;
CC_PACKED_END
CC_PACKED_BEGIN
typedef struct
{
uint32_t reset_counter;
} _Cbuffer;
}CC_PACKED _Cbuffer;
CC_PACKED_END
#endif

View File

@ -21,8 +21,18 @@ _ESCvar ESCvar;
/* Private variables */
static volatile int watchdog;
#if MAX_MAPPINGS_SM2 > 0
static uint8_t rxpdo[MAX_RXPDO_SIZE] __attribute__((aligned (8)));
#else
extern uint8_t * rxpdo;
#endif
#if MAX_MAPPINGS_SM3 > 0
static uint8_t txpdo[MAX_TXPDO_SIZE] __attribute__((aligned (8)));
#else
extern uint8_t * txpdo;
#endif
/** Function to pre-qualify the incoming SDO download.
*
@ -98,7 +108,10 @@ void TXPDO_update (void)
}
else
{
COE_pdoPack (txpdo, ESCvar.sm3mappings, SMmap3);
if (MAX_MAPPINGS_SM3 > 0)
{
COE_pdoPack (txpdo, ESCvar.sm3mappings, SMmap3);
}
ESC_write (ESC_SM3_sma, txpdo, ESCvar.ESC_SM3_sml);
}
}
@ -114,7 +127,10 @@ void RXPDO_update (void)
else
{
ESC_read (ESC_SM2_sma, rxpdo, ESCvar.ESC_SM2_sml);
COE_pdoUnpack (rxpdo, ESCvar.sm2mappings, SMmap2);
if (MAX_MAPPINGS_SM2 > 0)
{
COE_pdoUnpack (rxpdo, ESCvar.sm2mappings, SMmap2);
}
}
}

View File

@ -69,6 +69,16 @@ int32_t SDO_findobject (uint16_t index)
* Calculate the size in Bytes of RxPDO or TxPDOs by adding the
* objects in SyncManager SDO 1C1x.
*
* A list of mapped objects is created for fast lookup of
* dynamically mapped process data. The max size of the list (@a
* max_mappings) can be set to 0 if dynamic processdata is not
* supported.
*
* The output variable @a nmappings is set to 0 if dynamic processdata
* is not supported. It is set to the number of mapped objects if
* dynamic processdata is supported, or -1 if the mapping was
* incorrect.
* @param[in] index = SM index
* @param[out] nmappings = number of mapped objects in SM, or -1 if
* mapping is invalid
@ -76,7 +86,7 @@ int32_t SDO_findobject (uint16_t index)
* @param[out] max_mappings = max number of mapped objects in SM
* @return size of RxPDO or TxPDOs in Bytes.
*/
uint16_t sizeOfPDO (uint16_t index, int * nmappings,_SMmap * mappings,
uint16_t sizeOfPDO (uint16_t index, int * nmappings, _SMmap * mappings,
int max_mappings)
{
uint16_t offset = 0, hobj;
@ -116,46 +126,72 @@ uint16_t sizeOfPDO (uint16_t index, int * nmappings,_SMmap * mappings,
for (c = 1; c <= maxsub; c++)
{
uint32_t value = OBJ_VALUE_FETCH (value, objd[c]);
uint16_t index = value >> 16;
uint8_t subindex = (value >> 8) & 0xFF;
uint8_t bitlength = value & 0xFF;
const _objd * mapping;
if (mapIx == max_mappings)
if (max_mappings > 0)
{
/* Too many mapped objects */
*nmappings = -1;
return 0;
}
uint16_t index = value >> 16;
uint8_t subindex = (value >> 8) & 0xFF;
const _objd * mapping;
DPRINT ("%04x:%02x @ %d\n", index, subindex, offset);
nidx = SDO_findobject (index);
if (nidx >= 0)
{
int16_t nsub;
nsub = SDO_findsubindex (nidx, subindex);
if (nsub < 0)
if (mapIx == max_mappings)
{
mapping = NULL;
/* Too many mapped objects */
*nmappings = -1;
return 0;
}
mapping = &SDOobjects[nidx].objdesc[nsub];
}
else
{
mapping = NULL;
}
DPRINT ("%04x:%02x @ %d\n", index, subindex, offset);
mappings[mapIx].obj = mapping;
mappings[mapIx++].offset = offset;
if (index == 0 && subindex == 0)
{
/* Padding element */
mapping = NULL;
}
else
{
nidx = SDO_findobject (index);
if (nidx >= 0)
{
int16_t nsub;
nsub = SDO_findsubindex (nidx, subindex);
if (nsub < 0)
{
/* Mapped subindex does not exist */
*nmappings = -1;
return 0;
}
mapping = &SDOobjects[nidx].objdesc[nsub];
}
else
{
/* Mapped index does not exist */
*nmappings = -1;
return 0;
}
}
mappings[mapIx].obj = mapping;
mappings[mapIx++].offset = offset;
}
offset += bitlength;
}
}
}
}
*nmappings = mapIx;
if (max_mappings > 0)
{
*nmappings = mapIx;
}
else
{
*nmappings = 0;
}
return BITS2BYTES (offset);
}

View File

@ -119,26 +119,29 @@
#define SM3_act 1
#endif
/* Max processdata size (outputs) */
#ifndef MAX_RXPDO_SIZE
#define MAX_RXPDO_SIZE 128
#endif
/* Max processdata size (inputs) */
#ifndef MAX_TXPDO_SIZE
#define MAX_TXPDO_SIZE 128
#endif
/* Max number of mapped objects in SM2 */
/* Max number of dynamically mapped objects in SM2. May be 0 to
disable dynamic processdata. */
#ifndef MAX_MAPPINGS_SM2
#define MAX_MAPPINGS_SM2 16
#endif
/* Max number of mapped objects in SM3 */
/* Max number of dynamically mapped objects in SM3. May be 0 to
disable dynamic processdata. */
#ifndef MAX_MAPPINGS_SM3
#define MAX_MAPPINGS_SM3 16
#endif
/* _Static_assert (SM2_sma + 3 * MAX_INPUT_SIZE < SM3_sma); */
/* Max processdata size (outputs). Only used if MAX_MAPPINGS_SM2 is
non-zero. */
#ifndef MAX_RXPDO_SIZE
#define MAX_RXPDO_SIZE 128
#endif
/* Max processdata size (inputs). Only used if MAX_MAPPINGS_SM3 is
non-zero. */
#ifndef MAX_TXPDO_SIZE
#define MAX_TXPDO_SIZE 128
#endif
#endif /* __options__ */