source: trunk/MagicSoft/Cosy/incl/gendef.h@ 5138

Last change on this file since 5138 was 731, checked in by tbretz, 24 years ago
*** empty log message ***
File size: 13.2 KB
Line 
1/* -*-C-*-
2 * gendef.h - CANopen; home of generic definitions
3 *
4 *-----------------------------------------------------------------------
5 *
6 * Copyright (c) 1998 JANZ Computer AG
7 * All Rights Reserved
8 *
9 * Permission is hereby granted to licensees of JANZ Computer AG
10 * products to use or abstract this computer program for the sole
11 * purpose of implementing a product based on JANZ Computer AG
12 * products. No other rights to reproduce, use, or disseminate
13 * this computer program, whether in part or in whole, are granted.
14 *
15 * JANZ Computer AG makes no representation or warranties with respect
16 * to the performance of this computer program, and specifically
17 * disclaims any responsibility for any damages, special or consequential,
18 * connected with the use of this program.
19 *
20 * JANZ Computer AG products are not authorized for use as critical
21 * components in life support devices or systems without the express
22 * written approval of JANZ Computer AG.
23 *
24 *-----------------------------------------------------------------------
25 *
26 * $Id: gendef.h,v 1.1 2001-04-09 13:32:55 tbretz Exp $
27 *
28 *-----------------------------------------------------------------------
29 *
30 * $Log: not supported by cvs2svn $
31 * Revision 1.7 2000/02/18 11:22:11 jens
32 * adding variable in global variable structure: incomingSdoBehaviour
33 *
34 * Revision 1.6 1999/10/29 11:07:51 gerd
35 * Add support for Linux.
36 *
37 * Revision 1.5 1999/09/16 14:50:02 gerd
38 * Add support for PSOS
39 *
40 * Revision 1.4 1999/09/06 14:20:54 wolfgang
41 * Add macros and variable for MS-DOS.
42 *
43 * Revision 1.3 1999/06/18 12:08:15 jens
44 * made VMOD-ICAN/CAN104 dependend headers conditional (CAL_CANOPEN_CLAMPED)
45 * made pdoTagTables available at CAL_CANOPEN_CLAMPED-section only
46 *
47 * Revision 1.2 1999/06/10 14:10:36 wolfgang
48 * Add NT40 part for CANopen stuff.
49 *
50 * Revision 1.1 1999/03/08 16:55:13 jens
51 * Initial revision
52 *
53 *
54 *-----------------------------------------------------------------------
55 */
56
57#ifndef gendef_DEFINED
58#define gendef_DEFINED
59
60#ifdef __cplusplus
61extern "C" {
62#endif
63
64#ifdef WIN95
65#include <windows.h>
66#endif
67
68#ifdef WIN_NT40
69#include <windows.h>
70#endif
71
72#include "icanconf.h"
73#include "calconf.h"
74#include "cms.h"
75
76#include "bcan.h"
77
78#ifndef CAL_CANOPEN_CLAMPED
79#include "mican.h"
80#include "dpm.h"
81#include "can_lib.h"
82#endif
83
84#include <stdio.h>
85#include <string.h>
86
87#ifdef WIN95
88
89#define LCL_SLEEP(sleepTimeInMs) \
90 Sleep(sleepTimeInMs)
91
92#define CREATE_SEMAPHORE(pSecure, initCount, maxCount, pName) \
93 CreateSemaphore(pSecure, initCount, maxCount, pName);
94
95#define WAIT_FOR_SEMAPHORE(semId, howLong) \
96 WaitForSingleObject(semId, howLong)
97
98#define RELEASE_SEMAPHORE(semId, count, addrPrevCount) \
99 ReleaseSemaphore(semId, count, addrPrevCount)
100#endif
101
102
103#ifdef WIN_NT40
104
105#define LCL_SLEEP(sleepTimeInMs) \
106 Sleep(sleepTimeInMs)
107
108#define CREATE_SEMAPHORE(pSecure, initCount, maxCount, pName) \
109 CreateSemaphore(pSecure, initCount, maxCount, pName);
110
111#define WAIT_FOR_SEMAPHORE(semId, howLong) \
112 WaitForSingleObject(semId, howLong)
113
114#define RELEASE_SEMAPHORE(semId, count, addrPrevCount) \
115 ReleaseSemaphore(semId, count, addrPrevCount)
116
117#endif
118
119#ifdef VXWORKS
120#include <taskLib.h>
121#include <sysLib.h>
122
123#define INFINITE 0
124
125#define LCL_SLEEP(sleepTimeInMs) \
126 taskDelay(((sleepTimeInMs * 100) / (100000 / sysClkRateGet())) + 1)
127
128#define CREATE_SEMAPHORE(pSecure, initCount, maxCount, pName) \
129 semBCreate(SEM_Q_FIFO, (SEM_B_STATE)initCount);
130
131#define WAIT_FOR_SEMAPHORE(semId, howLong) \
132 semTake(semId, WAIT_FOREVER)
133
134#define RELEASE_SEMAPHORE(semId, count, addrPrevCount) \
135 semGive(semId)
136#endif
137
138#ifdef MSDOS
139
140#define LCL_SLEEP(sleepTimeInMs) \
141 delay(sleepTimeInMs)
142
143#define WAIT_FOR_SEMAPHORE(semId, howLong) \
144 {do{delay(100);}while(((myVars->pMsgHandler)((void*)myVars))==1);}
145
146#define RELEASE_SEMAPHORE(semId, count, addrPrevCount)
147
148#endif
149
150#ifdef PSOS
151#include "sysdep.h"
152#include <types.h>
153#include <psos.h>
154#include <configs.h>
155#include <bspfuncs.h>
156#include <drv_intf.h>
157#include <stdlib.h>
158
159#include "defs.h"
160
161
162extern NODE_CT *anchor;
163
164/* The following functions are used to translate vxWorks functions */
165/* to pSOS+ system calls */
166/* This functions will be removed within later versions. */
167
168static int
169semBCreate(int options, int state)
170{
171 unsigned long semid;
172 char semname[4];
173
174 semname[0] = 'S';
175 semname[1] = 'M';
176 semname[2] = '0';
177 semname[3] = '0';
178
179 if(sm_create(semname, (unsigned long)state,
180 SM_GLOBAL | SM_FIFO, &semid) != 0)
181 return(0);
182
183 return((int)semid);
184}
185
186/* end of vxWorks to pSOS+ translation */
187
188#define CLOCKS_PER_SEC (anchor->psosct->kc_ticks2sec)
189
190#define LCL_SLEEP(sleepTimeInMs) \
191 tm_wkafter(((sleepTimeInMs * 100) / (100000 / CLOCKS_PER_SEC)) + 1)
192
193#define CREATE_SEMAPHORE(pSecure, initCount, maxCount, pName) \
194 semBCreate(0, (int)initCount);
195
196#define WAIT_FOR_SEMAPHORE(semId, howLong) \
197 sm_p((unsigned long)semId, SM_WAIT, 0)
198
199#define RELEASE_SEMAPHORE(semId, count, addrPrevCount) \
200 sm_v(semId);
201
202#endif
203
204#ifdef LINUX
205#include <unistd.h>
206#include <sys/ipc.h>
207#include <sys/sem.h>
208
209#define WAIT_FOREVER 0
210
211extern int semBCreate(int options, int initCount);
212extern int semTake(int semId, int timeout);
213extern int semGive(int semId);
214
215#if 0
216static int
217semBCreate(int options, int initCount)
218{
219 int semId;
220
221 if((semId = semget(IPC_PRIVATE, 1, 0766|IPC_CREAT)) < 0) {
222 return(0);
223 }
224
225 if(semctl(semId, 0, SETVAL, (union semun) initCount) < 0) {
226 return(0);
227 }
228
229 return((int)semId);
230}
231
232static int
233semTake(int semId, int timeout)
234{
235 static struct sembuf semaphor;
236
237 semaphor.sem_op = -1;
238 semaphor.sem_flg = SEM_UNDO;
239
240 return( (int)semop(semId, &semaphor, 1) );
241}
242
243static int
244semGive(int semId)
245{
246 static struct sembuf semaphor;
247
248 semaphor.sem_op = 1;
249 semaphor.sem_flg = SEM_UNDO;
250
251 return( (int)semop(semId, &semaphor, 1) );
252}
253#endif
254
255#define LCL_SLEEP(sleepTimeInMs) (void)usleep(sleepTimeInMs * 1000)
256
257
258#define CREATE_SEMAPHORE(pSecure, initCount, maxCount, pName) \
259 semBCreate(0, (int)initCount);
260
261#define WAIT_FOR_SEMAPHORE(semId, howLong) \
262 semTake(semId, WAIT_FOREVER)
263
264#define RELEASE_SEMAPHORE(semId, count, addrPrevCount) \
265 semGive(semId)
266
267#endif /* LINUX */
268
269/*
270 * generic variable types
271 */
272#define LWORD_t unsigned long
273#define WORD_t unsigned short
274#define BYTE_t unsigned char
275
276#define LWORDS_t long
277#define WORDS_t short
278#define BYTES_t char
279
280#define VOID_t void
281
282#define INT_t int
283
284/*
285 * CANopen specific structures/defines
286 */
287
288/*
289 * Translation: CANopen data-type -> machine data-type
290 */
291#define Boolean char
292
293#define Integer8 char
294#define Integer16 short
295#define Integer32 long
296
297#define Signed8 char
298#define Signed16 short
299#define Signed32 long
300
301#define Unsigned8 unsigned char
302#define Unsigned16 unsigned short
303#define Unsigned32 unsigned long
304
305#define FloatingPoint float
306
307#define VisString char
308
309
310/*
311 * machine dependant size of data-type
312 */
313#define Boolean_size sizeof(char)
314
315#define Integer8_size sizeof(char)
316#define Integer16_size (2 * sizeof(char))
317#define Integer32_size (4 * sizeof(char))
318#define Integer64_size (8 * sizeof(char))
319
320#define Signed8_size sizeof(char)
321#define Signed16_size (2 * sizeof(char))
322#define Signed32_size (4 * sizeof(char))
323#define Signed64_size (8 * sizeof(char))
324
325#define Unsigned8_size sizeof(char)
326#define Unsigned16_size (2 * sizeof(char))
327#define Unsigned32_size (4 * sizeof(char))
328#define Unsigned64_size (8 * sizeof(char))
329
330
331
332#define FloatingPoint_size sizeof(float)
333
334#define VisString_size (255 * sizeof(char))
335
336
337struct dataType64bit {
338 LWORD_t highBytes;
339 LWORD_t lowBytes;
340};
341
342
343#define NIL (void *)0
344
345/* define values for FALSE and TRUE */
346
347#ifndef MSDOS
348
349#ifdef LINUX
350#define TRUE 1
351#define FALSE 0
352#else
353#ifndef TRUE
354#define TRUE 0
355#endif
356
357#ifndef FALSE
358#define FALSE (-1)
359#endif
360#endif
361
362#else
363#define TRUE 1
364#define FALSE 0
365#endif
366
367#ifdef CAL_CANOPEN_CLAMPED
368 #define LCL_NIL_CMSO NIL_CMSO
369#else
370 #define LCL_NIL_CMSO 0
371#endif
372
373
374struct Node {
375 struct Node *Next; /* next node */
376 WORD_t objDicIndex; /* data stored in node */
377 VOID_t *pEntry; /* pointer to entry of object dictionary */
378};
379
380struct hashTabs {
381 struct Node **pComProfHashTab;
382 struct Node **pManProfHashTab;
383 struct Node **pDevProfHashTab;
384 struct Node **pDataTypHashTab;
385 struct Node **pIec1131ProfHashTab;
386};
387
388struct pdoDataArray {
389 BYTE_t data[8];
390 BYTE_t arrivedLength;
391};
392
393struct mSpErrField {
394 BYTE_t mSpErrData[5];
395};
396
397#define NIL_SDO_DATA_AREA (struct sdoDataArea *)0
398
399#define NUM_OF_TAG_BYTES 64 /* will be enough for 512 (* 2) PDOs */
400#define RX_PDO_TAG 0
401#define TX_PDO_TAG 1
402
403#define SDO_ARRIVED 1
404#define PDO_ARRIVED 2
405
406
407#define NUM_BIT_RATE_TABLE_ENTRY 9
408#define CANOPEN_DEFAULT_BIT_RATE 4
409
410struct baudTable {
411 WORD_t bitMacro;
412 WORD_t bitRate;
413};
414
415/* Code switch settings for LMT configuration */
416#define CS_SET_BIT_RATE 0xf0
417#define CS_SET_DEFAULT_BIT_RATE 0x00
418
419/*
420 * Place of global variables
421 */
422
423
424struct globVars {
425 struct hashTabs haTab; /* place where pointer to */
426 /* hash tables are stored */
427
428 BYTE_t nodeState; /* current CANopen slave node state */
429 BYTE_t nodeClass; /* NMT node-class of slave node to create */
430
431 /* global entries from DCF: [DeviceCommisioning] */
432 BYTE_t nodeId; /* CANopen node ID */
433 BYTE_t nodeName[7]; /* CANopen LMT node name */
434 WORD_t bitRateMacro; /* current CANopen CAN-Bus-bit-rate */
435
436 struct baudTable bitRateTable[NUM_BIT_RATE_TABLE_ENTRY]; /* CANopen bit-rate-table */
437
438
439 /* field which holds manufacturer specific error for EMCY */
440 struct mSpErrField myManSpErrorField;
441
442 /*
443 * Holding number of TPDOs and RPDOs
444 */
445 BYTE_t numRxPdo;
446 BYTE_t numTxPdo;
447
448 /*
449 * behaviour on incoming SDOs in relationship to Slave nodeState
450 */
451 BYTE_t incomingSdoBehaviour;
452
453#ifdef CAL_CANOPEN_CLAMPED
454 /*
455 * This table holds a tag if data which are
456 * mapped to a PDO (txDataTable) or if data
457 * of a PDO (rxDataTable) had changed. The
458 * Table is bit oriented and holds 512 RxPDOs
459 * and 512 TxPDOs
460 */
461 BYTE_t rxPdoTagTable[NUM_OF_TAG_BYTES];
462 BYTE_t txPdoTagTable[NUM_OF_TAG_BYTES];
463
464 /*
465 * Holding a table, where data[8] of each RPDO
466 * is hold to grant access without scrolling
467 * through Object Dictionary
468 */
469 struct pdoDataArray *dataTablePdo;
470
471 /*
472 * This variable gives a chance to decide,
473 * if the tag entry in the PDO-change-array
474 * was caused by a PDO arrival or by SDO-
475 * communication.
476 */
477 BYTE_t lastDataFromPdoSdo;
478
479 /* This linked list holds the created (and enabled, coded!) TPDOs */
480 struct pdoSendList *pPdoSendList;
481
482#endif
483 /*
484 * array to hold temp VisString-OD-data
485 */
486 char charBuf[256];
487
488#ifndef CAL_CANOPEN_CLAMPED
489 /* stuff for communication to VMOD-ICAN3 */
490 Message msgBufferTx; /* message buffer */
491 int fd; /* file descriptor of module */
492 WORD_t cmsDefinitionTimeout; /* timeout in milliseconds to */
493 /* wait for module response at */
494 /* cms definition services */
495 char lastCmsDefinitionName[13]; /* ID from VMOD-ICAN3 at definition response */
496 WORD_t lastCmsDefinitionId; /* ID from VMOD-ICAN3 at definition response */
497
498
499 /* for CANopen manager functionality: */
500 WORD_t variableSDOIdToIcan3;
501 WORD_t variableSDOIdFromIcan3;
502 WORD_t sdoResponseTimeout; /* timeout in milliseconds to */
503 /* wait for peer nodes' SDO response */
504 BYTE_t sdoRxBuffer[256]; /* place for SDO data exchange (Rx) */
505 BYTE_t sdoTxBuffer[256]; /* place for SDO data exchange (Tx) */
506 BYTE_t sdoValidData; /* number of received SDO data */
507 BYTE_t sdoResponse; /* flag for answer of peer SDO */
508
509#ifdef WIN95
510 HANDLE hThreadCopSlv; /* thread handle */
511#endif
512#ifdef VXWORKS
513 int hThreadCopSlv; /* task ID */
514#endif
515#ifdef PSOS
516 unsigned long hThreadCopSlv; /* task ID */
517#endif
518#ifdef LINUX
519 unsigned long hThreadCopSlv; /* task ID */
520#endif
521#ifdef WIN_NT40
522 HANDLE hThreadCopSlv; /* thread handle */
523#endif
524
525#ifdef WIN95
526 HANDLE hSemCopSlv;
527 HANDLE hSemIcanCom; /* semaphore for thread-save comunication */
528 /* between receive thread and lib */
529#endif
530
531#ifdef WIN_NT40
532 HANDLE hSemCopSlv;
533 HANDLE hSemIcanCom; /* semaphore for thread-save comunication */
534 /* between receive thread and lib */
535 HANDLE hSemPlainQueue; /* semaphore to signal application that a message is */
536 /* inside the to-host plain queue */
537 HANDLE hSemFastQueue; /* semaphore to signal application that a message is */
538 /* inside the to-host fast queue */
539#endif
540
541#ifdef VXWORKS
542 SEM_ID hSemCopSlv;
543 SEM_ID hSemIcanCom; /* semaphore for thread-save comunication */
544 /* between receive thread and lib */
545#endif
546#ifdef PSOS
547 SEM_ID hSemCopSlv;
548 SEM_ID hSemIcanCom; /* semaphore for thread-save comunication */
549 /* between receive thread and lib */
550#endif
551#ifdef LINUX
552 int hSemCopSlv;
553 int hSemIcanCom; /* semaphore for thread-save comunication */
554 /* between receive thread and lib */
555#endif
556
557#ifdef MSDOS
558 int (*pMsgHandler) (void*);
559#endif
560 int tIdCopSlv;
561 Message msgBufferRx;
562
563 LWORD_t usedDpmCount; /* variable for objects interfacing to DPM, */
564 /* counts the actual offset to start of PP-area */
565
566 int (*drvRead)(); /* driver function to call on internal DPM-read */
567 void (*drvWrite)(); /* driver function to call on internal DPM-write */
568#endif
569
570};
571
572
573#if KDEBUG==1
574/* DEBUG tool KPRINTF */
575extern long freeMemDebug;
576#endif
577
578#ifdef __cplusplus
579}
580#endif
581
582#endif /* !gendef_DEFINED */
Note: See TracBrowser for help on using the repository browser.