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

c-open: Fix cached status. Fix SDO 7B last packet. Add cb_notify event. #56

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ set(MAX_RX_PDO "4"
set(MAX_ERRORS "4"
CACHE STRING "max size of error list")

set(SDO_TIMEOUT "100"
set(SDO_TIMEOUT "200"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes the default timeout for every user of c-open. Note that this is an option that can be adjusted locally if a particular application has different requirements.

CACHE STRING "timeout in ms for ongoing SDO transfers")

set(CO_THREAD_PRIO "10"
Expand Down
16 changes: 12 additions & 4 deletions include/co_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,19 @@ typedef enum co_dtype
/** Access function event */
typedef enum od_event
{
OD_EVENT_READ, /**< Read subindex */
OD_EVENT_WRITE, /**< Write subindex */
OD_EVENT_RESTORE, /**< Restore default value */
OD_EVENT_READ, /**< Read subindex */
OD_EVENT_WRITE, /**< Write subindex */
OD_EVENT_RESTORE, /**< Restore default value */
} od_event_t;

/** Notify event */
typedef enum od_notify_event
{
OD_NOTIFY_ACCESSED,
OD_NOTIFY_VALUE_SET,
OD_NOTIFY_SDO_RECEIVED,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are both ACCESSED and VALUE_SET required? They are both called from co_od_set_value and it seems that the only difference is whether the user has specified that the object has an accessor function or not.

SDO_RECEIVED seems to be used when an object larger than 64 bits is being downloaded and will be called for every partial update with the size received so far. So the value in this case is a size. This should be documented. There should also be a test that verifies the functionality.

} od_notify_event_t;

struct co_obj;
struct co_entry;

Expand Down Expand Up @@ -317,7 +325,7 @@ typedef struct co_cfg
uint8_t msef[5]);

/** Notify callback */
void (*cb_notify) (co_net_t * net, uint16_t index, uint8_t subindex);
void (*cb_notify) (co_net_t * net, uint16_t index, uint8_t subindex, od_notify_event_t event, uint32_t value);

/** Function to open dictionary store */
void * (*open) (co_store_t store, co_mode_t mode);
Expand Down
2 changes: 2 additions & 0 deletions src/co_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ int co_sdo_read (
job->sdo.subindex = subindex;
job->sdo.data = data;
job->sdo.remain = size;
job->sdo.cached = false;
job->callback = co_job_callback;
job->timestamp = os_tick_current();
job->type = CO_JOB_SDO_READ;
Expand Down Expand Up @@ -306,6 +307,7 @@ int co_sdo_write (
job->sdo.subindex = subindex;
job->sdo.data = (uint8_t *)data;
job->sdo.remain = size;
job->sdo.cached = false;
job->callback = co_job_callback;
job->timestamp = os_tick_current();
job->type = CO_JOB_SDO_WRITE;
Expand Down
2 changes: 1 addition & 1 deletion src/co_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ struct co_net
uint8_t msef[5]);

/** Notify callback */
void (*cb_notify) (co_net_t * net, uint16_t index, uint8_t subindex);
void (*cb_notify) (co_net_t * net, uint16_t index, uint8_t subindex, od_notify_event_t event, uint32_t value);

/** Function to open dictionary store */
void * (*open) (co_store_t store, co_mode_t mode);
Expand Down
12 changes: 7 additions & 5 deletions src/co_od.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,18 @@ static int co_subindex_equals (
return entry->subindex == subindex;
}

static void co_od_notify (
void co_od_notify (
co_net_t * net,
const co_obj_t * obj,
const co_entry_t * entry,
uint8_t subindex)
uint8_t subindex,
od_notify_event_t event,
uint32_t value)
{
if (entry->flags & OD_NOTIFY)
{
if (net->cb_notify)
net->cb_notify (net, obj->index, subindex);
net->cb_notify (net, obj->index, subindex, event, value);
}
}

Expand Down Expand Up @@ -221,7 +223,7 @@ uint32_t co_od_set_value (
uint32_t v = value;

result = obj->access (net, OD_EVENT_WRITE, obj, entry, subindex, &v);
co_od_notify (net, obj, entry, subindex);
co_od_notify (net, obj, entry, subindex, OD_NOTIFY_ACCESSED, 0);
return result;
}

Expand Down Expand Up @@ -262,7 +264,7 @@ uint32_t co_od_set_value (
return CO_SDO_ABORT_GENERAL;
}

co_od_notify (net, obj, entry, subindex);
co_od_notify (net, obj, entry, subindex, OD_NOTIFY_VALUE_SET, 0);
return 0;
}

Expand Down
21 changes: 21 additions & 0 deletions src/co_od.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,27 @@ uint32_t co_od_set_value (
uint8_t subindex,
uint64_t value);

/**
* Trigger notification callback
*
* This functions triggers the notification callback of the subindex,
* if any.
*
* @param net network handle
* @param obj object descriptor
* @param entry entry descriptor
* @param subindex subindex
* @param event event type
* @param value optional value
*/
void co_od_notify (
co_net_t * net,
const co_obj_t * obj,
const co_entry_t * entry,
uint8_t subindex,
od_notify_event_t event,
uint32_t value);

#ifdef __cplusplus
}
#endif
Expand Down
11 changes: 6 additions & 5 deletions src/co_sdo_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,15 @@ static int co_sdo_tx_download_init_rsp (
memcpy (&msg[1], job->sdo.data, size);

msg[0] = CO_SDO_CCS_DOWNLOAD_SEG_REQ | ((7 - (size & 0x07)) << 1);
if (size < 7)
msg[0] |= CO_SDO_C;

job->sdo.toggle = 0;

job->sdo.data += size;
job->sdo.remain -= size;
job->sdo.total += size;

if (job->sdo.remain == 0)
msg[0] |= CO_SDO_C;

os_channel_send (net->channel, 0x600 + node, msg, sizeof (msg));
}

Expand Down Expand Up @@ -209,13 +209,14 @@ static int co_sdo_tx_download_seg_rsp (
msg[0] = CO_SDO_CCS_DOWNLOAD_SEG_REQ | ((7 - (size & 0x07)) << 1);
if (job->sdo.toggle)
msg[0] |= CO_SDO_TOGGLE;
if (size < 7)
msg[0] |= CO_SDO_C;

job->sdo.data += size;
job->sdo.remain -= size;
job->sdo.total += size;

if (job->sdo.remain == 0)
msg[0] |= CO_SDO_C;

os_channel_send (net->channel, 0x600 + node, msg, sizeof (msg));
}

Expand Down
Loading