Skip to content

Commit 21e8d71

Browse files
committed
Fix PDOs sending remote frames instead of actual data
If a TPDO communication parameter has the RTR bit set, meaning remote transmission requests are not allowed for this PDO, the PDO transmission will send an RTR frame instead of the data when it's triggered, due to a missing mask on the COB-ID when sending the frame. Also audit other cases of calling os_channel_send() without masking and as a result, replace hard-coded mask constants in SYNC sending (one of which was incorrect!) with the appropriate macro. Include the extended-frame bit in the mask to support 29-bit frames if these should be configured in any COB-ID; it makes little sense to include all 29 ID bits in the mask if the extended-frame flag is left out.
1 parent fbf6ecf commit 21e8d71

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

src/co_main.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ extern "C" {
3535

3636
#define CO_BYTELENGTH(bitlength) (((bitlength) + 7) / 8)
3737

38-
#define CO_RTR_MASK BIT (30)
39-
#define CO_EXT_MASK BIT (29)
40-
#define CO_ID_MASK 0x1FFFFFFF
38+
#define CO_RTR_MASK BIT (30)
39+
#define CO_EXT_MASK BIT (29)
40+
#define CO_ID_MASK 0x1FFFFFFF
41+
#define CO_EXTID_MASK (CO_EXT_MASK | CO_ID_MASK)
4142

4243
#define CO_COBID_INVALID BIT (31)
4344
#define CO_NODE_GET(id) ((id)&0x7F)

src/co_pdo.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ static void co_pdo_transmit (co_net_t * net, co_pdo_t * pdo)
538538
/* Transmit PDO */
539539
co_pdo_pack (net, pdo);
540540
dlc = CO_BYTELENGTH (pdo->bitlength);
541-
os_channel_send (net->channel, pdo->cobid, &pdo->frame, dlc);
541+
os_channel_send (net->channel, pdo->cobid & CO_EXTID_MASK, &pdo->frame, dlc);
542542
pdo->timestamp = now;
543543
pdo->queued = false;
544544
}
@@ -685,7 +685,7 @@ void co_pdo_rx (co_net_t * net, uint32_t id, void * msg, size_t dlc)
685685

686686
if (id & CO_RTR_MASK)
687687
{
688-
id &= ~CO_RTR_MASK;
688+
id &= CO_EXTID_MASK;
689689
for (ix = 0; ix < MAX_TX_PDO; ix++)
690690
{
691691
co_pdo_t * pdo = &net->pdo_tx[ix];

src/co_sync.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ int co_sync_timer (co_net_t * net, uint32_t now)
157157
co_put_uint8 (msg, sync->counter);
158158
os_channel_send (
159159
net->channel,
160-
sync->cobid & 0x1FFFFFF,
160+
sync->cobid & CO_EXTID_MASK,
161161
msg,
162162
sizeof (msg));
163163

@@ -166,7 +166,7 @@ int co_sync_timer (co_net_t * net, uint32_t now)
166166
}
167167
else
168168
{
169-
os_channel_send (net->channel, sync->cobid & 0x1FFFFFFF, NULL, 0);
169+
os_channel_send (net->channel, sync->cobid & CO_EXTID_MASK, NULL, 0);
170170
}
171171

172172
/* Call user callback */

0 commit comments

Comments
 (0)