Skip to content

Commit a5cc00b

Browse files
Magnus JohanssonDaniel Udd
authored andcommitted
c-open: Fix cached status. Fix SDO 7B last packet. Add cb_notify event.
Tested-by: Daniel Udd <[email protected]> Reviewed-by: Daniel Udd <[email protected]>
1 parent 1b07023 commit a5cc00b

File tree

14 files changed

+176
-118
lines changed

14 files changed

+176
-118
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ set(MAX_RX_PDO "4"
106106
set(MAX_ERRORS "4"
107107
CACHE STRING "max size of error list")
108108

109-
set(SDO_TIMEOUT "100"
109+
set(SDO_TIMEOUT "200"
110110
CACHE STRING "timeout in ms for ongoing SDO transfers")
111111

112112
set(CO_THREAD_PRIO "10"

include/co_api.h

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -172,34 +172,37 @@ typedef enum co_otype
172172
OTYPE_RECORD = 0x09,
173173
} co_otype_t;
174174

175+
#define DTYPE_FLAG_ATOMIC (1 << 31)
176+
#define DTYPE_MASK 0x7FFFFFFF
177+
175178
/** Dictionary datatypes. See CiA 301 7.4.7 */
176179
typedef enum co_dtype
177180
{
178-
DTYPE_BOOLEAN = 0x0001,
179-
DTYPE_INTEGER8 = 0x0002,
180-
DTYPE_INTEGER16 = 0x0003,
181-
DTYPE_INTEGER32 = 0x0004,
182-
DTYPE_UNSIGNED8 = 0x0005,
183-
DTYPE_UNSIGNED16 = 0x0006,
184-
DTYPE_UNSIGNED32 = 0x0007,
185-
DTYPE_REAL32 = 0x0008,
181+
DTYPE_BOOLEAN = DTYPE_FLAG_ATOMIC | 0x0001,
182+
DTYPE_INTEGER8 = DTYPE_FLAG_ATOMIC | 0x0002,
183+
DTYPE_INTEGER16 = DTYPE_FLAG_ATOMIC | 0x0003,
184+
DTYPE_INTEGER32 = DTYPE_FLAG_ATOMIC | 0x0004,
185+
DTYPE_UNSIGNED8 = DTYPE_FLAG_ATOMIC | 0x0005,
186+
DTYPE_UNSIGNED16 = DTYPE_FLAG_ATOMIC | 0x0006,
187+
DTYPE_UNSIGNED32 = DTYPE_FLAG_ATOMIC | 0x0007,
188+
DTYPE_REAL32 = DTYPE_FLAG_ATOMIC | 0x0008,
186189
DTYPE_VISIBLE_STRING = 0x0009,
187190
DTYPE_OCTET_STRING = 0x000A,
188191
DTYPE_UNICODE_STRING = 0x000B,
189192
DTYPE_TIME_OF_DAY = 0x000C,
190193
DTYPE_TIME_DIFFERENCE = 0x000D,
191194
DTYPE_DOMAIN = 0x000F,
192195
DTYPE_INTEGER24 = 0x0010,
193-
DTYPE_REAL64 = 0x0011,
196+
DTYPE_REAL64 = DTYPE_FLAG_ATOMIC | 0x0011,
194197
DTYPE_INTEGER40 = 0x0012,
195198
DTYPE_INTEGER48 = 0x0013,
196199
DTYPE_INTEGER56 = 0x0014,
197-
DTYPE_INTEGER64 = 0x0015,
200+
DTYPE_INTEGER64 = DTYPE_FLAG_ATOMIC | 0x0015,
198201
DTYPE_UNSIGNED24 = 0x0016,
199202
DTYPE_UNSIGNED40 = 0x0018,
200203
DTYPE_UNSIGNED48 = 0x0019,
201204
DTYPE_UNSIGNED56 = 0x001A,
202-
DTYPE_UNSIGNED64 = 0x001B,
205+
DTYPE_UNSIGNED64 = DTYPE_FLAG_ATOMIC | 0x001B,
203206
DTYPE_PDO_COMM_PARAM = 0x0020,
204207
DTYPE_PDO_MAPPING = 0x0021,
205208
DTYPE_SDO_PARAM = 0x0022,
@@ -223,11 +226,19 @@ typedef enum co_dtype
223226
/** Access function event */
224227
typedef enum od_event
225228
{
226-
OD_EVENT_READ, /**< Read subindex */
227-
OD_EVENT_WRITE, /**< Write subindex */
228-
OD_EVENT_RESTORE, /**< Restore default value */
229+
OD_EVENT_READ, /**< Read subindex */
230+
OD_EVENT_WRITE, /**< Write subindex */
231+
OD_EVENT_RESTORE, /**< Restore default value */
229232
} od_event_t;
230233

234+
/** Notify event */
235+
typedef enum od_notify_event
236+
{
237+
OD_NOTIFY_ACCESSED,
238+
OD_NOTIFY_VALUE_SET,
239+
OD_NOTIFY_SDO_RECEIVED,
240+
} od_notify_event_t;
241+
231242
struct co_obj;
232243
struct co_entry;
233244

@@ -317,7 +328,7 @@ typedef struct co_cfg
317328
uint8_t msef[5]);
318329

319330
/** Notify callback */
320-
void (*cb_notify) (co_net_t * net, uint16_t index, uint8_t subindex);
331+
void (*cb_notify) (co_net_t * net, uint16_t index, uint8_t subindex, od_notify_event_t event, uint32_t value);
321332

322333
/** Function to open dictionary store */
323334
void * (*open) (co_store_t store, co_mode_t mode);

src/co_main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ int co_sdo_read (
277277
job->sdo.subindex = subindex;
278278
job->sdo.data = data;
279279
job->sdo.remain = size;
280+
job->sdo.cached = false;
280281
job->callback = co_job_callback;
281282
job->timestamp = os_tick_current();
282283
job->type = CO_JOB_SDO_READ;
@@ -306,6 +307,7 @@ int co_sdo_write (
306307
job->sdo.subindex = subindex;
307308
job->sdo.data = (uint8_t *)data;
308309
job->sdo.remain = size;
310+
job->sdo.cached = false;
309311
job->callback = co_job_callback;
310312
job->timestamp = os_tick_current();
311313
job->type = CO_JOB_SDO_WRITE;

src/co_main.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ struct co_net
277277
uint8_t msef[5]);
278278

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

282282
/** Function to open dictionary store */
283283
void * (*open) (co_store_t store, co_mode_t mode);

src/co_od.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,18 @@ static int co_subindex_equals (
3636
return entry->subindex == subindex;
3737
}
3838

39-
static void co_od_notify (
39+
void co_od_notify (
4040
co_net_t * net,
4141
const co_obj_t * obj,
4242
const co_entry_t * entry,
43-
uint8_t subindex)
43+
uint8_t subindex,
44+
od_notify_event_t event,
45+
uint32_t value)
4446
{
4547
if (entry->flags & OD_NOTIFY)
4648
{
4749
if (net->cb_notify)
48-
net->cb_notify (net, obj->index, subindex);
50+
net->cb_notify (net, obj->index, subindex, event, value);
4951
}
5052
}
5153

@@ -221,7 +223,7 @@ uint32_t co_od_set_value (
221223
uint32_t v = value;
222224

223225
result = obj->access (net, OD_EVENT_WRITE, obj, entry, subindex, &v);
224-
co_od_notify (net, obj, entry, subindex);
226+
co_od_notify (net, obj, entry, subindex, OD_NOTIFY_ACCESSED, 0);
225227
return result;
226228
}
227229

@@ -262,7 +264,7 @@ uint32_t co_od_set_value (
262264
return CO_SDO_ABORT_GENERAL;
263265
}
264266

265-
co_od_notify (net, obj, entry, subindex);
267+
co_od_notify (net, obj, entry, subindex, OD_NOTIFY_VALUE_SET, 0);
266268
return 0;
267269
}
268270

src/co_od.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,27 @@ uint32_t co_od_set_value (
271271
uint8_t subindex,
272272
uint64_t value);
273273

274+
/**
275+
* Trigger notification callback
276+
*
277+
* This functions triggers the notification callback of the subindex,
278+
* if any.
279+
*
280+
* @param net network handle
281+
* @param obj object descriptor
282+
* @param entry entry descriptor
283+
* @param subindex subindex
284+
* @param event event type
285+
* @param value optional value
286+
*/
287+
void co_od_notify (
288+
co_net_t * net,
289+
const co_obj_t * obj,
290+
const co_entry_t * entry,
291+
uint8_t subindex,
292+
od_notify_event_t event,
293+
uint32_t value);
294+
274295
#ifdef __cplusplus
275296
}
276297
#endif

src/co_sdo_client.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,15 @@ static int co_sdo_tx_download_init_rsp (
154154
memcpy (&msg[1], job->sdo.data, size);
155155

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

160158
job->sdo.toggle = 0;
161-
162159
job->sdo.data += size;
163160
job->sdo.remain -= size;
164161
job->sdo.total += size;
165162

163+
if (job->sdo.remain == 0)
164+
msg[0] |= CO_SDO_C;
165+
166166
os_channel_send (net->channel, 0x600 + node, msg, sizeof (msg));
167167
}
168168

@@ -209,13 +209,14 @@ static int co_sdo_tx_download_seg_rsp (
209209
msg[0] = CO_SDO_CCS_DOWNLOAD_SEG_REQ | ((7 - (size & 0x07)) << 1);
210210
if (job->sdo.toggle)
211211
msg[0] |= CO_SDO_TOGGLE;
212-
if (size < 7)
213-
msg[0] |= CO_SDO_C;
214212

215213
job->sdo.data += size;
216214
job->sdo.remain -= size;
217215
job->sdo.total += size;
218216

217+
if (job->sdo.remain == 0)
218+
msg[0] |= CO_SDO_C;
219+
219220
os_channel_send (net->channel, 0x600 + node, msg, sizeof (msg));
220221
}
221222

0 commit comments

Comments
 (0)