Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start of MPDO support #29

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions src/co_pdo.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,59 @@ void co_pdo_pack (co_net_t * net, co_pdo_t * pdo)
}
}

static int co_mpdo_unpack (co_net_t * net, co_pdo_t * pdo)
{
bool is_dam = bitslice_get (&pdo->frame, 7, 1);
uint8_t node = bitslice_get (&pdo->frame, 0, 7);
uint16_t index = bitslice_get (&pdo->frame, 8, 16);
uint8_t subindex = bitslice_get (&pdo->frame, 24, 8);
uint32_t value = bitslice_get (&pdo->frame, 32, 32);
const co_obj_t * obj;
const co_entry_t * entry;

if (is_dam)
{
if (node != 0 && node != net->node)
return 0;

obj = co_obj_find (net, index);
if (obj == NULL)
goto error;

entry = co_entry_find (net, obj, subindex);
if (entry == NULL || !(entry->flags & OD_WRITE))
goto error;

if (co_od_set_value (net, obj, entry, subindex, value))
goto error;

} else {
/* TODO: Support SAM-MPDO Consumer using dispatcher list. */
}

return 0;

error:
if (node != 0)
return co_emcy_tx (net, 0x8230, 0, NULL);

return 0;
}

void co_pdo_unpack (co_net_t * net, co_pdo_t * pdo)
{
unsigned int ix;
unsigned int offset = 0;

if (pdo->number_of_mappings >= 0xFE)
{
/* TODO: Each MPDO frame contains the info whether it's SAM or DAM,
* so what difference does it make if the configuration here is 0xFE
* or 0xFF?? */
co_mpdo_unpack(net, pdo);
return;
}

for (ix = 0; ix < pdo->number_of_mappings; ix++)
{
const co_entry_t * entry = pdo->entries[ix];
Expand All @@ -121,6 +169,13 @@ static uint32_t co_pdo_mapping_validate (co_pdo_t * pdo, uint8_t number_of_mappi
{
int ix;

/* Check if MPDO */
if (number_of_mappings >= 0xFE)
{
pdo->bitlength = 64;
return 0;
}

/* Mappings array bounds check */
if (number_of_mappings > MAX_PDO_ENTRIES)
return CO_SDO_ABORT_PDO_LENGTH;
Expand Down