source: trunk/Cosy/incl/cms.h@ 12582

Last change on this file since 12582 was 731, checked in by tbretz, 24 years ago
*** empty log message ***
File size: 17.8 KB
Line 
1/*-----------------------------------------------------------------------------
2cms.h -- CAN Message Specification CMS
3
4Copyright (c) 1994 JANZ Computer AG
5All Rights Reserved
6
7Created 94/10/11 by Soenke Hansen
8Version 1.32 of 99/06/18
9
10Definitions and type definitions for COB's and CMS Objects.
11Prototypes of functions defined in cms.c.
12
13-----------------------------------------------------------------------------*/
14
15
16#ifndef cms_DEFINED
17#define cms_DEFINED
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
23#include "defs.h"
24
25#define COB_LEN 8 /* max. data length of CAN message */
26#define CMS_NAME_LEN 13 /* cf. CiA/DS207 */
27#define COB_NAME_LEN 14 /* CMS_NAME_LEN + 1 */
28
29
30/* COB types */
31#define COB_RECEIVE 0
32#define COB_TRANSMIT 1
33
34
35/* Kinds of CMS objects */
36#define CMS_VARIABLE 0x0000
37#define CMS_VARSET 0x1000
38#define CMS_DOMAIN 0x2000
39#define CMS_EVENT 0x3000
40#define cmso_kind(type) ((type) & 0xf000)
41
42/* Classes of CMS objects */
43#define CMS_BASIC 0x0100
44#define CMS_MULTIPLEXED 0x0200
45#define CMS_CONTROLLED 0x0100
46#define CMS_UNCONTROLLED 0x0200
47#define CMS_STORED 0x0300
48#define cmso_class(type) ((type) & 0x0300)
49
50/* User types of CMS objects */
51#define CMS_CLIENT 0x0010
52#define CMS_SERVER 0x0020
53#define cmso_user(type) ((type) & 0x0030)
54
55/* Access types of Variables */
56#define CMS_READ_ONLY 0x0001
57#define CMS_WRITE_ONLY 0x0002
58#define CMS_READ_WRITE 0x0003
59#define cmso_access(type) ((type) & 0x0007)
60
61
62#ifdef FIRMWARE
63
64/* CAN Communication Object */
65struct cob {
66 BYTE_t tc; /* COB type and class */
67 BYTE_t prio; /* priority */
68 WORD_t inht; /* inhibit time */
69 WORD_t head; /* COB head (descriptor) */
70 BYTE_t *nmcms; /* name of CMS object */
71 BYTE_t nmsfx; /* suffix of COB name */
72 struct calo *co; /* parent CAL object */
73 struct cob *next; /* list of used COBs */
74};
75
76#define NIL_COB (struct cob *)0
77
78/* Set and get COB attributes */
79#define cob_length(cob) ((cob)->head & 0x000f)
80#define cob_tc(t,c) (((c) & 0x07) | (((t) & 0x01) << 4))
81#define cob_class(cob) ((cob)->tc & 0x07)
82#define cob_type(cob) (((cob)->tc >> 4) & 0x01)
83
84
85/* Data set size type (for domains) */
86#if TYPEDEFS == 1
87typedef unsigned long DSIZE_t; /* 32 bit unsigned integer */
88#else
89#define DSIZE_t unsigned long
90#endif
91
92/* Components of messages in domain call-backs */
93#define dom_spec u.m2.r /* sub-specifier MS_DOM_* */
94#define dom_reason u.m2.b[0] /* reason for failure */
95
96#define cms_spec u.m2.r /* cms sub-specifier MS_CMS_DATA */
97#define cms_id u.m2.d /* cms object id */
98#define cms_failure u.m2.b[0] /* cms failure code */
99
100/* Location of data set size in message. */
101#define dsize_in_msg(m) (&(m)->u.m2.b[4])
102
103/* Convert between data set size and an array of 4 bytes */
104#define dsize_from_bytes(b) ((DSIZE_t)(b)[0] + ((DSIZE_t)(b)[1] << 8) + \
105 ((DSIZE_t)(b)[2] << 16) + ((DSIZE_t)(b)[3] << 24))
106
107/* Domain specific state */
108struct domain {
109 BYTE_t *data; /* data buffer provided by application */
110 DSIZE_t len; /* allocated length of buffer */
111 DSIZE_t rlen; /* actual length of data received */
112 DSIZE_t dsize; /* data set size if positive */
113 BYTE_t ics; /* initial command specifier */
114 BYTE_t cs; /* segment command spec. except for "n" */
115 BYTE_t csb; /* backup of command specifier */
116 BYTE_t more; /* more data blocks to be transferred? */
117 BYTE_t pos; /* position in CAN message buffer */
118 BYTE_t mux[3]; /* buffer for multiplexer */
119 int muxlen; /* length of multiplexer */
120 struct message *dm; /* delayed message */
121 WORD_t config; /* some configurations */
122 int pend_ack; /* flags for pending acknowlegdes */
123 int del_ack; /* does delayed message need ack? */
124 int delayed; /* set if delay occurs */
125};
126
127#endif /* FIRMWARE */
128
129
130/* Flags in config/pend_ack */
131#define CMS_INHIBIT_CONFIG 1 /* multiplexor */
132/* flags will be interpreted as default inhibit time (for CANopen PDOs) */
133
134#define CMS_DOMAIN_GENERAL_CONFIG 0 /* multiplexor */
135#define DOM_ACKNOWLEDGE (1<<0)
136#define DOM_SDO_EVERY_STATE_ACTIV (1<<8)
137#define DOM_RCPT_ACKNOWLEDGE (1<<1)
138
139/* Flags for configuring CMS domains at their creation */
140#define DOM_SDO_DBT_CAPABILITY (1<<0)
141 /* Flag specifies, if it is allowed to distribute the SDO-CMS
142 * object`s identifier by DBT services in preparing phases
143 * (CAL boot up for CANopen slaves).
144 */
145
146#ifdef FIRMWARE
147
148/* Domains must be in the idle state to accept service requests. */
149#define dom_set_idle(dom) ((dom)->ics = 0xff)
150#define dom_is_idle(dom) ((dom)->ics == 0xff)
151
152#define dom_is_delayed(dom) ((dom)->delayed != 0)
153
154/* True if the COB is a data COB with type COB_RECEIVE or is a remote COB
155 with type COB_TRANSMIT */
156#define cob_accept(cob) ((((cob)->head ^ (WORD_t)((cob)->tc)) & 0x0010) == 0)
157
158
159
160/* This linked list holds the created (and enabled, coded!) TPDOs */
161struct pdoSendList {
162 struct cmso *cmsIdOfPdo; /* cms object id of TPDO */
163 struct pdoSendList *next; /* pointer to next object */
164};
165#define NIL_PDO_SEND_LIST (struct pdoSendList *)0
166
167struct pdoMapList {
168#ifdef CAL_CANOPEN_CLAMPED
169 LWORD_t cmsObjectMappingEntry;
170#else
171 unsigned char *offsetInDpm;
172#endif
173 BYTE_t mapLength;
174 struct pdoMapList *next;
175};
176#define NIL_PDO_MAP_LIST (struct pdoMapList *)0
177
178/* CANopen add on to CMS Object; is only used at PDOs */
179struct copAddOn {
180 BYTE_t transType;
181 BYTE_t actualTransCount;
182 BYTE_t state;
183 struct pdoMapList *mapList;
184};
185#define NIL_COP_ADD_ON (struct copAddOn *)0
186/* values of state of PDO */
187#define BIT_PDO_ENABLED (1 << 0)
188#define BIT_PDO_DISABLED (0 << 0)
189
190
191
192/* CMS Object */
193struct cmso {
194 BYTE_t *name; /* name of CMS Object */
195 WORD_t type; /* var/dom/evt,bas/mux,user,access */
196 BYTE_t *buf; /* buffer pointer */
197 BYTE_t dbuf[COB_LEN]; /* data buffer */
198 BYTE_t mux; /* save multiplexor here */
199 struct domain *dom; /* domain specific */
200 WORD_t flags; /* special flags for internal use */
201 WORD_t tid; /* id for usage with timer timeout ? */
202 WORD_t hid; /* host assigned object id */
203 OBJECT adata; /* application data */
204 void (*ahdl)(); /* application handler CMS messages */
205 struct cob *cobs; /* list of used COBs */
206 struct cob rxcob; /* receive COB */
207 struct cob txcob; /* transmit COB */
208 struct cmso *next; /* list of CMS Objects */
209 OBJECT obj; /* associated CAL Object */
210#ifdef nodef
211 perhaps TODO: inhibit the possibility to send user-data in cms-objects
212 which will be driven by e.g. TPU irqs and get their data from module!
213 BYTE_t canopen_flags /* signals special canopen behavior */
214 /* of cms-object (e.g. TIME, SYNC) */
215#endif
216 struct copAddOn *canOpenControls;
217};
218
219#define NIL_CMSO (struct cmso *)0
220
221#endif /* FIRMWARE */
222
223/* Various flags */
224#define INHIBITED 0x01
225#define TX_REQUEST 0x02
226#define TX_REQUEST_CON 0x04
227#define ENABLED 0x08
228
229#define OUTSTANDING 0x10
230#define RW_REQUEST_MASK 0x20
231#define WRITE_REQUEST 0x20
232
233
234/* Timer/BCAN request Id modifiers */
235#define REQ_INHIBIT_TIME (0x1000 & ~CALID_MASK)
236#define REQ_CON_TIMEOUT (0x2000 & ~CALID_MASK)
237
238#ifdef FIRMWARE
239
240/* Disable CMS Definition services */
241extern int DisableDefCms(void);
242
243/* Enable CMS Definition services */
244extern void EnableDefCms(void);
245
246/* Check if CMS Definition services are disabled */
247extern int IsDisabledDefCms(void);
248
249/* Initialize the CMS Object Directory */
250extern void InitCms(WORD_t);
251
252/* Create a CMS Object */
253struct cmso *NewCmsO(BYTE_t *);
254
255/* Create a special CMS Object without adding it to directory */
256struct cmso *NewCmsONoDBT(BYTE_t *);
257
258/* Set host assigned id for a CMS Object */
259void SetCmsOhid(struct cmso *co, WORD_t id);
260
261/* Delete a CMS Object */
262extern void DeleteCmsO(struct cmso *);
263
264/* Get a CMS Object by name */
265extern struct cmso *GetCmsO(BYTE_t *);
266
267/* Get next CMS Object. Used when looping through the defined CMS Objects. */
268extern struct cmso *GetNextCmsO(int);
269
270/* Get next COB used by a CMS Object. */
271extern struct cob *GetNextCobCms(int);
272
273/* Construct COB name */
274extern void cob_name(struct cob *, BYTE_t *);
275
276/* Invocation of (remote) CMS service for a CMS object. */
277extern int cms_invoke(struct cmso *, BYTE_t *, int);
278
279/* Handler for non-CAN messages to CMS objects. */
280extern void cms_no_can_hdl(struct cmso *, struct message *);
281
282
283/*------ Application handler function --------------------------------------*/
284
285/* Default application handler for CMS objects. */
286extern void DfltApplHdlCms(struct cmso *, struct message *);
287#define NIL_AHDL DfltApplHdlCms
288
289#endif /* FIRMWARE */
290
291/* Specific flags for JANZ */
292#define CMS_USE_HOST_ID (1<<0)
293
294
295/*------ CMS Variables -----------------------------------------------------*/
296
297#ifdef FIRMWARE
298
299/* Definition of a CMS Multiplexed Variable */
300struct cmso *MultiplexedVariable(
301 BYTE_t *, /* name of CMS object to be created */
302 WORD_t , /* user and access type */
303 int , /* length of data type (<=8) */
304 int , /* range: [0,7] */
305 OBJECT , /* application data */
306 void (*)() /* appl. handler for CMS messages */
307);
308
309
310/* Definition of a CMS Basic Variable */
311extern struct cmso *BasicVariable(
312 BYTE_t *, /* name of CMS object to be created */
313 WORD_t , /* user and access type */
314 int , /* length of data type (<=8) */
315 int , /* range: [0,7] */
316 OBJECT , /* application data */
317 void (*)() /* appl. handler for CAN data frames */
318);
319
320/* Definition of a CMS Basic Variable for SYNC features */
321extern struct cmso *BasicVariableSYNC(
322 BYTE_t *, /* name of CMS object to be created */
323 WORD_t , /* user and access type */
324 int , /* length of data type (<=8) */
325 int , /* range: [0,7] */
326 OBJECT , /* application data */
327 void (*)(), /* appl. handler for CAN data frames */
328 WORD_t, /* predefined transmit ID */
329 WORD_t, /* predefined receive ID */
330 BYTE_t /* DBT capibilities */
331);
332
333/* Update Read-Only Variable in Server */
334extern int UpdateVariable(struct cmso *, BYTE_t *);
335
336/* Client requests Write Variable Service */
337extern int WriteVariableReq(struct cmso *, BYTE_t *);
338
339/* Client requests Read Variable Service */
340extern int ReadVariableReq(struct cmso *);
341
342/* Client requests Write Variable Service for multiplexed variables. */
343int WriteMultiplexedVariableReq(struct cmso *co, int mux, BYTE_t *value);
344
345/* Client requests Read Variable Service. */
346int ReadMultiplexedVariableReq(struct cmso *co, int mux);
347
348
349/* Server responds to a Write Variable Service */
350int WriteVariableRes(struct cmso *, int , BYTE_t *);
351
352/* Server responds to a Write Variable Service */
353int ReadVariableRes(struct cmso *co, int status, BYTE_t *value);
354
355
356
357/*------ CMS Events --------------------------------------------------------*/
358
359/* Definition of a CMS Uncontrolled Event */
360extern struct cmso *UncontrolledEvent(
361 BYTE_t *, /* name of CMS object to be created */
362 WORD_t , /* user type */
363 int , /* length of data type (<=7) */
364 int , /* range: [0,7] */
365 OBJECT , /* application data */
366 void (*)() /* appl. handler for CMS messages */
367);
368
369/* Definition of a CMS Controlled Event */
370extern struct cmso *ControlledEvent(
371 BYTE_t *, /* name of CMS object to be created */
372 WORD_t , /* user type */
373 int , /* length of data type (<=7) */
374 int , /* range: [0,7] */
375 OBJECT , /* application data */
376 void (*)() /* appl. handler for CMS messages */
377);
378
379/* Definition of a CMS Stored Event */
380extern struct cmso *StoredEvent(
381 BYTE_t *, /* name of CMS object to be created */
382 WORD_t , /* user and access type */
383 int , /* length of data type (<=8) */
384 int , /* range: [0,7] */
385 OBJECT , /* application data */
386 void (*)() /* appl. handler for CMS messages */
387);
388
389/* Definition of a Stored Event for CANopen TIMESTAMP object */
390extern struct cmso *StoredEventTS(
391 BYTE_t *, /* name of CMS object to be created */
392 WORD_t , /* user and access type */
393 int , /* length of data type (<=8) */
394 int , /* range: [0,7] */
395 OBJECT , /* application data */
396 void (*)(), /* appl. handler for CAN data frames */
397 WORD_t, /* predefined transmit ID */
398 WORD_t, /* predefined receive ID */
399 BYTE_t /* DBT capibilities */
400);
401
402/* Definition of a Stored Event for CANopen EMERGENCY object */
403extern struct cmso *StoredEventEMCY(
404 BYTE_t *, /* name of CMS object to be created */
405 WORD_t , /* user and access type */
406 int , /* length of data type (<=8) */
407 int , /* range: [0,7] */
408 OBJECT , /* application data */
409 void (*)(), /* appl. handler for CAN data frames */
410 WORD_t, /* predefined transmit ID */
411 WORD_t, /* predefined receive ID */
412 BYTE_t /* DBT capibilities */
413);
414
415/* Definition of a Stored Event for CANopen PDO */
416extern struct cmso *StoredEventPDO(
417 BYTE_t *, /* name of CMS object to be created */
418 WORD_t , /* user and access type */
419 int , /* length of data type (<=8) */
420 int , /* range: [0,7] */
421 OBJECT , /* application data */
422 void (*)(), /* appl. handler for CAN data frames */
423 WORD_t, /* predefined transmit ID */
424 WORD_t, /* predefined receive ID */
425 BYTE_t /* DBT capibilities */
426);
427
428/* Notify Event service. */
429extern int NotifyEvent(struct cmso *, BYTE_t *);
430
431/* Store Event service. */
432extern int StoreEvent(struct cmso *, BYTE_t *, int);
433
434/* Read Event service. */
435extern int ReadEvent(struct cmso *);
436
437/* Set Event Control State service. */
438extern int SetControlEventReq(struct cmso *, int);
439extern int SetControlEventRes(struct cmso *, int, int, BYTE_t *);
440
441/*-------- CMS Domains ------------------------------------------------------*/
442
443/* Implemented in cmsdom.c */
444
445/* Definition of a CMS Domain */
446extern struct cmso *Domain(
447 BYTE_t *, /* name of CMS object to be created */
448 WORD_t , /* class and user type */
449 int , /* multiplexer length (<=3) */
450 int , /* range: [0,7] */
451 OBJECT , /* application data */
452 void (*)() /* appl. handler for CMS messages */
453);
454
455/* Definition of a CMS Domain for CANopen SDOs */
456extern struct cmso *DomainSDO(
457 BYTE_t *, /* name of CMS object to be created */
458 WORD_t , /* class and user type */
459 int , /* multiplexer length (<=3) */
460 int , /* range: [0,7] */
461 OBJECT , /* application data */
462 void (*)(), /* appl. handler for CMS messages */
463 WORD_t Tx_SDO_ID, /* Transmit SDO ID as seen by node */
464 WORD_t Rx_SDO_ID, /* Receive SDO ID as seen by node */
465 BYTE_t dbt_cap /* DBT capability flag of CANopen node */
466);
467
468/* Abort Domain Transfer */
469extern void DomAbortReq(
470 struct cmso *, /* Domain CMS object */
471 BYTE_t * /* nil or 4 bytes */
472);
473
474/* Client requests the statrt of normal domain download.
475 Subsequently transfer of the data block, if provided by the client,
476 will start. Expedited transfer will be chosen iff 0<dsize<=4, len==dsize,
477 and exped!=0 (expedited enabled) else normal transfer is started.
478 The client is called back on service completion or else for more data. */
479extern int DomDownloadStartReq(
480 struct cmso *, /* the domain handle */
481 BYTE_t *, /* multiplexor */
482 BYTE_t *, /* (first) data block to be downloaded */
483 DSIZE_t , /* length of (first) data block */
484 DSIZE_t , /* data set size if > 0 */
485 int , /* enable expedited transfer */
486 int /* true if more blocks will follow */
487);
488
489/* Client request the continuation of a download and provides the next
490 data block to be transfered after having received to confirmation
491 for the previous block if any. If the client provides no data (len==0)
492 then the service completes successfully. If more is true then the
493 client wishes to be asked for additional data blocks. */
494extern int DomDownloadContReq(
495 struct cmso *, /* the domain handle */
496 BYTE_t *, /* (next) data block to transmit/receive */
497 DSIZE_t , /* allocated length of data block */
498 int /* true if more blocks will follow */
499);
500
501/* Server responds to download request providing a receive buffer for
502 data to be downloaded. The buffer must be able to hold 7 bytes
503 at least. */
504extern int DomDownloadRes(
505 struct cmso *, /* the domain handle */
506 BYTE_t *, /* (next) data block to transmit/receive */
507 DSIZE_t /* allocated length of data block */
508);
509
510/* Client requests initialization of a domain upload.
511 The client will be called back to to receive expedited data or to
512 provide buffers to receive data blocks of a normal transfer.
513 Note that the server decides about using normal or expedited transfer. */
514extern int DomUploadStartReq(
515 struct cmso *, /* the domain handle */
516 BYTE_t * /* multiplexor */
517);
518
519/* The server received a domain upload indication. The server
520 responds by calling the following function to accept the upload
521 request. Expedited transfer will be chosen iff 0<dsize<=4, len==dsize,
522 and exped!=0 (expedited enabled) else normal transfer is started.
523 In case of multiplexed domains the data must be consistent with
524 the multiplexor received on indication.
525 The server will be called back for more data to be uploaded if necessary.
526 The server will be called back on completion of the service. */
527extern int DomUploadRes(
528 struct cmso *, /* the domain handle */
529 BYTE_t *, /* (first) data block to be uploaded */
530 DSIZE_t , /* length of (first) data block */
531 DSIZE_t , /* data set size if > 0 */
532 int , /* enable expedited transfer */
533 int /* true if more blocks will follow */
534);
535
536/* Client requested the continuation of a upload. Server provides the next
537 data block to be transfered. If the server provides no data (len==0)
538 then the service completes successfully. If more is true then the
539 server wishes to be asked for additional data blocks. */
540extern int DomUploadContRes(
541 struct cmso *, /* the domain handle */
542 BYTE_t *, /* (next) data block to transmit/receive */
543 DSIZE_t , /* allocated length of data block */
544 int /* true if more blocks will follow */
545);
546
547extern void DomHostAcknowledgeRes(
548 struct cmso *co
549);
550
551extern void DomRcptAcknowledgeReq(
552 struct cmso *co
553);
554
555#endif /* FIRMWARE */
556
557/* bitpositions in cs */
558#define D_MORE (1 << 0) /* more date will follow */
559#define D_EXPED (1 << 1) /* inhibit expedited data transfer */
560#define D_SUCCESS (1 << 2) /* success indication */
561
562#ifdef __cplusplus
563}
564#endif
565
566#endif /* !cms_DEFINED */
Note: See TracBrowser for help on using the repository browser.