Skip to content

Commit cc77085

Browse files
committed
Make it possible to trigger only PDOs for a specific object
The event used to trigger event-based PDOs is not necessarily the same for all PDOs, however there is no API to trigger the transmission of anything but all enabled PDOs. Add a job type and supporting functions to trigger only PDOs which have a specified object mapped. Also add documentation and prototype that was missing for co_pdo_event(). Signed-off-by: Andreas Fritiofson <andreas.fritiofson@unjo.com> Change-Id: Iff3bd08585866d774a11bd6ecd7b5d58bb0fdfdc
1 parent 845798b commit cc77085

File tree

5 files changed

+112
-0
lines changed

5 files changed

+112
-0
lines changed

include/co_api.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,32 @@ CO_EXPORT void co_nmt (co_client_t * client, co_nmt_cmd_t cmd, uint8_t node);
394394
*/
395395
CO_EXPORT void co_sync (co_client_t * client);
396396

397+
/**
398+
* Trigger event-based PDOs
399+
*
400+
* This function triggers transmission of all event-based PDOs.
401+
*
402+
* @param client client handle
403+
*
404+
* @return 0 on success
405+
*/
406+
CO_EXPORT int co_pdo_event (co_client_t * client);
407+
408+
/**
409+
* Triggers event-based PDOs containing a specific object
410+
*
411+
* This function triggers transmission of all event-based PDOs
412+
* that map the specified object.
413+
*
414+
* @param client client handle
415+
* @param index index
416+
* @param subindex subindex
417+
*
418+
* @return 0 on success
419+
*/
420+
CO_EXPORT int co_pdo_obj_event (co_client_t * client, uint16_t index,
421+
uint8_t subindex);
422+
397423
/**
398424
* Read dictionary object entry
399425
*

src/co_main.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ void co_main (void * arg)
130130
co_handle_rx (net);
131131
break;
132132
case CO_JOB_PDO_EVENT:
133+
case CO_JOB_PDO_OBJ_EVENT:
133134
co_pdo_job (net, job);
134135
break;
135136
case CO_JOB_SDO_READ:
@@ -225,6 +226,21 @@ int co_pdo_event (co_client_t * client)
225226
return 0;
226227
}
227228

229+
int co_pdo_obj_event (co_client_t * client, uint16_t index, uint8_t subindex)
230+
{
231+
co_net_t * net = client->net;
232+
co_job_t * job = &client->job;
233+
234+
job->client = client;
235+
job->callback = NULL;
236+
job->type = CO_JOB_PDO_OBJ_EVENT;
237+
job->pdo.index = index;
238+
job->pdo.subindex = subindex;
239+
240+
os_mbox_post (net->mbox, job, OS_WAIT_FOREVER);
241+
return 0;
242+
}
243+
228244
int co_sdo_read (
229245
co_client_t * client,
230246
uint8_t node,

src/co_main.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ typedef enum co_job_type
9494
CO_JOB_PERIODIC,
9595
CO_JOB_RX,
9696
CO_JOB_PDO_EVENT,
97+
CO_JOB_PDO_OBJ_EVENT,
9798
CO_JOB_SDO_READ,
9899
CO_JOB_SDO_WRITE,
99100
CO_JOB_SDO_UPLOAD,
@@ -131,6 +132,13 @@ typedef struct co_emcy_job
131132
uint8_t value;
132133
} co_emcy_job_t;
133134

135+
/** Parameters for PDO job */
136+
typedef struct co_pdo_job
137+
{
138+
uint16_t index;
139+
uint8_t subindex;
140+
} co_pdo_job_t;
141+
134142
/** Generic job */
135143
typedef struct co_job
136144
{
@@ -139,6 +147,7 @@ typedef struct co_job
139147
{
140148
co_sdo_job_t sdo;
141149
co_emcy_job_t emcy;
150+
co_pdo_job_t pdo;
142151
};
143152
uint32_t timestamp;
144153
struct co_client * client;

src/co_pdo.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,50 @@ void co_pdo_trigger (co_net_t * net)
594594
}
595595
}
596596

597+
void co_pdo_trigger_with_obj (co_net_t * net, uint16_t index, uint8_t subindex)
598+
{
599+
unsigned int ix;
600+
uint8_t n;
601+
const co_obj_t * obj;
602+
const co_entry_t * entry;
603+
604+
/* Find mapped object */
605+
obj = co_obj_find (net, index);
606+
if (obj == NULL)
607+
return;
608+
609+
/* Find mapped entry */
610+
entry = co_entry_find (net, obj, subindex);
611+
if (entry == NULL)
612+
return;
613+
614+
/* Check that object is mappable */
615+
if ((entry->flags & OD_TPDO) == 0)
616+
return;
617+
618+
/* Transmit event-driven TPDOs, queue acyclic TPDOs */
619+
for (ix = 0; ix < MAX_TX_PDO; ix++)
620+
{
621+
co_pdo_t * pdo = &net->pdo_tx[ix];
622+
623+
for (n = 0; n < pdo->number_of_mappings; n++)
624+
{
625+
if (pdo->entries[n] == entry)
626+
{
627+
if (IS_EVENT (pdo->transmission_type))
628+
{
629+
co_pdo_transmit (net, pdo);
630+
}
631+
else if (IS_ACYCLIC (pdo->transmission_type))
632+
{
633+
pdo->queued = true;
634+
}
635+
break;
636+
}
637+
}
638+
}
639+
}
640+
597641
int co_pdo_sync (co_net_t * net, uint8_t * msg, size_t dlc)
598642
{
599643
unsigned int ix;
@@ -761,6 +805,9 @@ void co_pdo_job (co_net_t * net, co_job_t * job)
761805
case CO_JOB_PDO_EVENT:
762806
co_pdo_trigger (net);
763807
break;
808+
case CO_JOB_PDO_OBJ_EVENT:
809+
co_pdo_trigger_with_obj (net, job->pdo.index, job->pdo.subindex);
810+
break;
764811
default:
765812
CC_ASSERT (0);
766813
}

src/co_pdo.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,20 @@ int co_pdo_timer (co_net_t * net, uint32_t now);
116116
*/
117117
void co_pdo_trigger (co_net_t * net);
118118

119+
/**
120+
* PDO trigger with object
121+
*
122+
* This function triggers an event on event-driven and acyclic
123+
* TPDOs that map the specified object. Event-driven TPDOs will be
124+
* transmitted immediately while acyclic TPDOs will be queued for
125+
* transmission at next SYNC.
126+
*
127+
* @param net network handle
128+
* @param index index
129+
* @param subindex subindex
130+
*/
131+
void co_pdo_trigger_with_obj (co_net_t * net, uint16_t index, uint8_t subindex);
132+
119133
/**
120134
* Start PDO job
121135
*

0 commit comments

Comments
 (0)