-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathdrvTip810.html
More file actions
1397 lines (1014 loc) · 33.9 KB
/
drvTip810.html
File metadata and controls
1397 lines (1014 loc) · 33.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<HTML>
<HEAD>
<TITLE>drvTip810 - CAN Bus Driver </TITLE>
<META NAME="Author" CONTENT="Andrew Johnson" />
<META NAME="Description"
CONTENT="How to use the Tip810 CANbus driver software" />
<META NAME="KeyWords"
CONTENT="vxWorks, EPICS, CANbus, TEWS, TIP810, drvTip810" />
<META NAME="Version"
CONTENT="$Id$"/>
</HEAD>
<BODY>
<H1 ALIGN=CENTER>drvTip810 - CAN Bus Driver </H1>
<P ALIGN=CENTER>TEWS TIP810 Driver for EPICS<BR>
Version 2.9</P>
<P ALIGN=CENTER><I>Andrew Johnson
<A HREF="mailto:anj@aps.anl.gov"><anj@aps.anl.gov></A></I></P>
<H2>Contents</H2>
<UL>
<LI><A HREF="#section1">Introduction</A> </LI>
<LI><A HREF="#section2">TIP810 Driver Usage</A></LI>
<UL>
<LI><A HREF="#t810Create">t810Create</A> </LI>
<LI><A HREF="#t810Shutdown">t810Shutdown</A> </LI>
<LI><A HREF="#t810Initialise">t810Initialise</A> </LI>
<LI><A HREF="#t810Report">t810Report</A> </LI>
<LI><A HREF="#canTest">canTest</A> </LI>
</UL>
<LI><A HREF="#section3">Routines for CANbus Applications</A></LI>
<UL>
<LI><A HREF="#canOpen">canOpen</A> </LI>
<LI><A HREF="#canIoParse">canIoParse</A> </LI>
<LI><A HREF="#canWrite">canWrite</A> </LI>
<LI><A HREF="#canMessage">canMessage</A> </LI>
<LI><A HREF="#canMsgDelete">canMsgDelete</A> </LI>
<LI><A HREF="#canSignal">canSignal</A> </LI>
<LI><A HREF="#canBusReset">canBusReset</A> </LI>
<LI><A HREF="#canBusStop">canBusStop</A> </LI>
<LI><A HREF="#canBusRestart">canBusRestart</A> </LI>
<LI><A HREF="#canRead">canRead</A> </LI>
</UL>
</UL>
<HR>
<H2><A NAME="section1"></A>1. Introduction</H2>
<P>This document describes the software interface to the TEWS TIP810
Industry-Pack Module for EPICS. This software is an IPAC Module Driver and uses
the services of the drvIpac Industry Pack Driver to interface to the IPAC
Carrier Board - see the accompanying document
<A HREF="drvIpac.html">drvIpac - Industry Pack Driver</A> for details of this
driver software. The device support routines provided for use with EPICS are
described in the document
<A HREF="devCan.html">devCan - CAN Bus Device Support</A> which briefly covers
the use of the various record types supported.</P>
<P>The following routines provided by this driver are described in detail
below:</P>
<UL>
<LI><A HREF="#t810Create">t810Create</A> </LI>
<LI><A HREF="#t810Shutdown">t810Shutdown</A> </LI>
<LI><A HREF="#t810Initialise">t810Initialise</A> </LI>
<LI><A HREF="#t810Report">t810Report</A> </LI>
<LI><A HREF="#canTest">canTest</A> </LI>
<LI><A HREF="#canOpen">canOpen</A> </LI>
<LI><A HREF="#canIoParse">canIoParse</A> </LI>
<LI><A HREF="#canWrite">canWrite</A> </LI>
<LI><A HREF="#canMessage">canMessage</A> </LI>
<LI><A HREF="#canMsgDelete">canMsgDelete</A> </LI>
<LI><A HREF="#canSignal">canSignal</A> </LI>
<LI><A HREF="#canBusReset">canBusReset</A> </LI>
<LI><A HREF="#canBusStop">canBusStop</A> </LI>
<LI><A HREF="#canBusRestart">canBusRestart</A> </LI>
<LI><A HREF="#canRead">canRead</A> </LI>
</UL>
<HR>
<H2><A NAME="section2"></A>2. TIP810 Driver Usage</H2>
<P>The software provides an interface to higher level software which, other
than device initialisation, is not specific to the TIP810 but could be used
with a CANbus driver for a different hardware interface. The interface to the
higher level software is provided in two header files: <I>canBus.h</I>
contains all of the generic CANbus definitions and declarations, while
<I>drvTip810.h</I> incorporates the additional declarations and definitions
which are specific to the TIP810 module. The
routines which are specific to the TIP810 or meant for use from the vxWorks
shell are described individually in this section, while the generic CANbus
interface routines are described in <A HREF="#section3">section 3</A> below.
</P>
<P>The TEWS TIP810 IP module contains a Philips pca82c200 stand-alone
CAN-controller chip which performs all of the CANbus interfacing functions.
The interface to this chip is defined in a separate header file
<I>pca82c200.h</I> which declares the register interface structure and the
bit-patterns for the various on-chip registers.</P>
<P>The CAN-controller chip does not contain the necessary interrupt vector
logic required by the IndustryPack interface however, so the TIP810 module
implements this in additional logic, including a register to hold the vector
number to be used.</P>
<HR>
<H3><A NAME="t810Create"></A>t810Create()</H3>
<P>Registers a new TIP810 device with the driver. In EPICS, this is registered
as an iocsh command.</P>
<PRE>int t810Create (char *pbusName, int card, int slot,
int irqNum, int busRate);</PRE>
<H4>Parameters</H4>
<DL>
<DT><TT>char *pbusName</TT></DT>
<DD>String which comprises a unique identifier for this particular CAN Bus. This
must be a static string which should not be changed while the driver is loaded
and running (vxWorks and EPICS IOC shell string literals have this property).
While <TT>t810Create()</TT> enforces no restrictions on the characters which may
be used in the name, if the <TT>canIoParse()</TT> routine is used the name
should contain alphanumeric characters only.</DD>
<DT><TT>int card, int slot</TT></DT>
<DD>Ipac Driver carrier and slot numbers which identify the IPAC module,
for use with drvIpac.</DD>
<DT><TT>int irqNum</TT></DT>
<DD>Interrupt vector number allocated for this device.</DD>
<DT><TT>int busRate</TT></DT>
<DD>CAN bus rate in Kbits/sec. This parameter can have one of the values
given in the following table. Other rates will require modifications to
the driver source code. The Kvaser standard uses different bit timings
which are not compatible with those used by Tews and so require special
bit-rate entries.</DD>
</DL>
<BLOCKQUOTE><TABLE BORDER=1 >
<TR BGCOLOR="#FFFFFF">
<TD><B><TT>busRate</TT></B></TD>
<TD><B><I>CANbus bit rate</I></B></TD>
</TR>
<TR>
<TD> 5</TD>
<TD>5 Kbits/sec</TD>
</TR>
<TR>
<TD> 10</TD>
<TD>10 Kbits/sec</TD>
</TR>
<TR>
<TD> 20</TD>
<TD>20 Kbits/sec</TD>
</TR>
<TR>
<TD> 50</TD>
<TD>50 Kbits/sec</TD>
</TR>
<TR>
<TD> 100</TD>
<TD>100 Kbits/sec</TD>
</TR>
<TR>
<TD> 125</TD>
<TD>125 Kbits/sec</TD>
</TR>
<TR>
<TD> 250</TD>
<TD>250 Kbits/sec</TD>
</TR>
<TR>
<TD> 500</TD>
<TD>500 Kbits/sec</TD>
</TR>
<TR>
<TD> 1000</TD>
<TD>1000 Kbits/sec</TD>
</TR>
<TR>
<TD> 1600</TD>
<TD>1600 Kbits/sec</TD>
</TR>
<TR>
<TD> -125</TD>
<TD>Kvaser 125 Kbits/sec</TD>
</TR>
<TR>
<TD> -250</TD>
<TD>Kvaser 250 Kbits/sec</TD>
</TR>
<TR>
<TD> -500</TD>
<TD>Kvaser 500 Kbits/sec</TD>
</TR>
<TR>
<TD> -1000</TD>
<TD>Kvaser 1000 Kbits/sec</TD>
</TR>
</TABLE></BLOCKQUOTE>
<H4>Description</H4>
<P>This routine will usually be called from the IOC start-up script. It is used
to inform the driver about each TIP810 module which it is to control, providing
information on how to find the module (the IPAC carrier and slot numbers) and
what CANbus bit rate is to be used. Each module is given a name which is matched
during calls to the <TT>canOpen()</TT> routine to identify the particular module
again.</P>
<P>The code checks that the given name and card/slot numbers are unique and
point to a real Tews TIP810 module, then it creates a new device table and
initialises it and some of the chip registers. At this stage the device is not
activated but held in the reset state.</P>
<H4>Returns</H4>
<BLOCKQUOTE>
<PRE>int</PRE>
</BLOCKQUOTE>
<DL>
<BLOCKQUOTE><TABLE BORDER=1 >
<TR BGCOLOR="#FFFFFF">
<TD><B>Symbol/Value</B></TD>
<TD><B>Meaning</B></TD>
</TR>
<TR>
<TD>0</TD>
<TD>OK</TD>
</TR>
<TR>
<TD>S_t810_badBusRate</TD>
<TD>Bus Rate not supported</TD>
</TR>
<TR>
<TD>S_t810_duplicateDevice</TD>
<TD>another TIP810 already using given name and/or IPAC address </TD>
</TR>
<TR>
<TD>(drvIpac)</TD>
<TD>errors returned by <TT>ipmValidate()</TT> </TD>
</TR>
<TR>
<TD>ENOMEM</TD>
<TD><TT>malloc()</TT> returned NULL</TD>
</TR>
</TABLE></BLOCKQUOTE>
</DL>
<H4>Example</H4>
<BLOCKQUOTE>
<PRE>iocsh> t810Create("CAN1", 0, 1, 0x60, 500)
Value = 0</PRE>
</BLOCKQUOTE>
<HR>
<H3><A NAME="t810Shutdown"></A>t810Shutdown()</H3>
<P>Shutdown routine, resets all devices to stop interrupts.</P>
<PRE>int t810Shutdown(void *dummy);</PRE>
<H4>Parameters</H4>
<DL>
<DT><TT>void *dummy</TT></DT>
<DD>This parameter is not used by the routine but is required to allow it to be
used as an <TT>epicsAtExit()</TT> routine.</DD>
</DL>
<H4>Description</H4>
<P>When <TT>t810Initialise()</TT> is called, this routine will be registered as
an <TT>epicsAtExit()</TT> callback. It resets the CAN controller chips on all
known TIP810 modules when called. It can also be run by applications programs to
turn off all the module drivers in the event of some catastrophic failure, but
it may be necessary to reinitialise the drivers to re-enable them
afterwards.</P>
<H4>Returns</H4>
<BLOCKQUOTE>
<PRE>void</PRE>
</BLOCKQUOTE>
<HR>
<H3><A NAME="t810Initialise"></A>t810Initialise()</H3>
<P>Initialise driver and all registered hardware.</P>
<PRE>int t810Initialise(void);</PRE>
<H4>Parameters</H4>
<DL>
<DT><TT>void</TT></DT>
<DD>None.</DD>
</DL>
<H4>Description</H4>
<P>This routine is called during <TT>iocInit()</TT>, which must be placed after
all <TT>t810Create()</TT> calls in the start-up script. It creates a message
queue to hold received messages and starts a task named <TT>canRecvTask</TT> to
distribute them to the routines that have asked to be informed about them.
Finally it completes the initialisation of the CAN controller chip and interrupt
vector registers for all known TIP810 devices and starts them running.</P>
<H4>Returns</H4>
<BLOCKQUOTE>
<PRE>int</PRE>
</BLOCKQUOTE>
<BLOCKQUOTE><TABLE BORDER=1 >
<TR BGCOLOR="#FFFFFF">
<TD><B>Symbol/Value</B></TD>
<TD><B>Meaning</B></TD>
</TR>
<TR>
<TD>0</TD>
<TD>OK</TD>
</TR>
<TR>
<TD>ENOMEM</TD>
<TD><TT>malloc()</TT> returned NULL</TD>
</TR>
<TR>
<TD>(drvIpac)</TD>
<TD>errors from <TT>ipmIntConnect()</TT></TD>
</TR>
</TABLE></BLOCKQUOTE>
<HR>
<H3><A NAME="t810Report"></A>t810Report()</H3>
<P>Display a report giving the status of all TEWS TIP810 devices. This is
registered as an iocsh command.</P>
<PRE>int t810Report(int interest);</PRE>
<H4>Parameters</H4>
<DL>
<DT><TT>int interest</TT></DT>
<DD>Interest level, indicating how much detail is required and what information
to show.</DD>
</DL>
<H4>Description</H4>
<P>Outputs (to stdout) a list of all the TIP810 devices created, their
IP carrier & slot numbers and the bus name string. For <TT>interest=1</TT>
it adds message and error statistics; for <TT>interest=2</TT> it lists
all CAN IDs for which a call-back has been registered; for <TT>interest=3</TT>
the status of the CAN controller chip is given.</P>
<H4>Returns</H4>
<BLOCKQUOTE>
<PRE>int</PRE>
</BLOCKQUOTE>
<BLOCKQUOTE><TABLE BORDER=1 >
<TR BGCOLOR="#FFFFFF">
<TD><B>Symbol/Value</B></TD>
<TD><B>Meaning</B></TD>
</TR>
<TR>
<TD>0</TD>
<TD>OK</TD>
</TR>
<TR>
<TD>S_t810_badDevice </TD>
<TD>Bad or corrupted internal device table found</TD>
</TR>
</TABLE></BLOCKQUOTE>
<H4>Examples</H4>
<BLOCKQUOTE>
<PRE>iocsh> t810Report(1)
TEWS tip810 CANbus Ip Modules
'CAN1' : IP Carrier 0 Slot 1, bus rate 500 Kbits/sec
Messages Sent : 75
Messages Received : 43
Message Overruns : 0
Discarded Messages : 4
Last Discarded ID : 0x206
Error Interrupts : 0
Bus Off Events : 0
-> t810Report(2)
TEWS tip810 CANbus Ip Modules
'CAN1' : IP Carrier 0 Slot 1, bus rate 500 Kbits/sec
Callbacks registered:
0x1c 0x1d 0x1e 0x1f 0x200 0x202 0x204
canRead Status : Idle
-> t810Report(3)
TEWS tip810 CANbus Ip Modules
'CAN1' : IP Carrier 0 Slot 1, bus rate 500 Kbits/sec
pca82c200 Chip Status:
Bus Status : Bus-On
Error Status : Ok
Data Overrun : Ok
Receive Status : Idle
Receive Buffer Status : Empty
Transmit Status : Idle
Transmission Complete : Complete
Transmit Buffer Access : Released</PRE>
</BLOCKQUOTE>
<HR>
<H3><A NAME="canTest"></A>canTest()</H3>
<P>Test routine, sends a single test message to the named CANbus.</P>
<PRE>int canTest (char *pbusName, canID_t identifier, int rtr,
int length, char *data);</PRE>
<H4>Parameters</H4>
<DL>
<DT><TT>char *pbusName</TT></DT>
<DD>Device name identifying the particular TIP810 device to use.</DD>
<DT><TT>canID_t identifier</TT></DT>
<DD>The CANbus message identifier to send.</DD>
<DT><TT>int rtr</TT></DT>
<DD>0 for a normal CAN message, non-zero to send a Remote Transmission
Request packet.</DD>
<DT><TT>int length</TT></DT>
<DD>Number of bytes in the data field for this CANbus message type.</DD>
<DT><TT>char *data</TT></DT>
<DD>Pointer to the data to be sent. Ignored for RTR packets.</DD>
</DL>
<H4>Description</H4>
<P>This routine is provided as a diagnostic, to allow the system developer
to generate CANbus messages and RTR packets from the vxWorks shell. It
should not be used from within an application. It makes use of the <TT>canOpen()</TT>
and <TT>canWrite()</TT> routines, and responds to errors reported by those
routines by printing a message and returning -1.</P>
<H4>Returns</H4>
<BLOCKQUOTE>
<PRE>int</PRE>
</BLOCKQUOTE>
<BLOCKQUOTE><TABLE BORDER=1 >
<TR BGCOLOR="#FFFFFF">
<TD><B>Symbol/Value</B></TD>
<TD><B>Meaning</B></TD>
</TR>
<TR>
<TD>0</TD>
<TD>OK</TD>
</TR>
<TR>
<TD>-1</TD>
<TD>Error</TD>
</TR>
</TABLE></BLOCKQUOTE>
<H4>Example</H4>
<BLOCKQUOTE>
<PRE>iocsh> canTest "CAN1", 0x33, 0, 4, "STOP"</PRE>
</BLOCKQUOTE>
<HR>
<H2><A NAME="section3"></A>3. Routines for CANbus Applications </H2>
<H3><A NAME="canOpen"></A>canOpen()</H3>
<P>Return device pointer for given CAN bus name.</P>
<PRE>int canOpen(char *busName, canBusID_t *pbusID);</PRE>
<H4>Parameters</H4>
<DL>
<DT><TT>char *busName</TT></DT>
<DD>Device name that identifies the particular TIP810 device to use.</DD>
<DT><TT>canBusID_t *pbusID</TT></DT>
<DD>Pointer to a <TT>canBusID_t</TT> to hold the device identifier.</DD>
</DL>
<H4>Description</H4>
<P>Searches through the list of registered TIP810 devices for one which matches
the name given, and returns a device identifier for it. This identifier is a
required parameter for all of the remaining can driver routines. String
searching in this manner is not particularly fast if several devices have been
registered so this routine is intended to be used mainly when an application
starts up. It may be used as often as desired however - there is no associated
<TT>canClose()</TT> routine.</P>
<H4>Returns</H4>
<BLOCKQUOTE>
<PRE>int</PRE>
</BLOCKQUOTE>
<BLOCKQUOTE><TABLE BORDER=1 >
<TR BGCOLOR="#FFFFFF">
<TD><B>Symbol/Value</B></TD>
<TD><B>Meaning</B></TD>
</TR>
<TR>
<TD>0</TD>
<TD>OK</TD>
</TR>
<TR>
<TD>S_can_noDevice</TD>
<TD>No matching device name found.</TD>
</TR>
</TABLE></BLOCKQUOTE>
<H4>Example</H4>
<BLOCKQUOTE>
<PRE>canBusID_t can1;
if (canOpen("CAN1", &can1)) {
printf("Can't open CAN1\n");
return -1;
}</PRE>
</BLOCKQUOTE>
<HR>
<H3><A NAME="canIoParse"></A>canIoParse()</H3>
<P>Parse a CAN address string into a canIo_t structure</P>
<PRE>int canIoParse(char *canString, canIo_t *pcanIo);</PRE>
<H4>Parameters</H4>
<DL>
<DT><TT>const char *canString</TT></DT>
<DD>Address string to be converted.</DD>
<DT><TT>canIo_t *pcanIo</TT></DT>
<DD>Pointer to a structure which will be used to return the converted address
information.</DD>
</DL>
<H4>Description</H4>
<P><TT>canIoParse()</TT> is used by the EPICS device support routines to
convert record hardware addresses, but can be used by any application with
similar requirements. It is intended to provide a standard way of converting
the parameters which are needed to specify a portion of a particular CANbus
message type from an ASCII string to their binary representation as a structure.
The <TT>canIo_t</TT> structure is defined as a typedef in the <i>canBus.h</i>
header as follows:</P>
<BLOCKQUOTE>
<PRE>typedef struct {
char *busName;
double timeout;
canID_t identifier;
epicsUInt16 offset;
epicsInt32 parameter;
char *paramStr;
canBusID_t canBusID;
} canIo_t;</PRE>
</BLOCKQUOTE>
<P>The address string passed to this routine consists of a series of elements,
some of which are optional.</P>
<UL>
<I>busName</I>[<TT><B>/</B></TT><I>timeout</I>]<TT><B>:</B></TT><I>identifier</I>[<TT><B>+</B></TT><I>n</I>..][<TT><B>.</B></TT><I>offset</I>]<I>parameter</I>
</UL>
<P>The first element is the bus name, which should consist of alphanumeric
characters only. The name is terminated immediately before the first
"<TT>/</TT>" or "<TT>:</TT>" character in the string, and
after omitting any leading white-space the characters forming the bus name are
copied to a newly allocated buffer, the address of which is placed in
<TT>pcanIo->busName</TT>.</P>
<P>An oblique stroke ("<TT>/</TT>") after the bus name introduces an
optional timeout element, which is an integer number of milli-seconds to wait
for a response for this particular type of message. This is converted into
seconds as a double and placed in <TT>pcanIo->timeout</TT>. If no timeout
element is included, the timeout is set to -1.0 which means wait forever.</P>
<P>The CANbus message identifier is preceded by a colon
("<TT>:</TT>"), and must result in one of the legal CANbus identifiers
in the range 0 through 2047 (with holes). The identifier itself can be specified
as a single number, or in several parts separated by plus signs, which are all
summed. The numbers here can be given in any of the standard 'C' formats as
converted by <TT>strtol()</TT>, so negative, hex or octal numbers may be used as
desired.</P>
<P>If the identifier is followed by a decimal point ("<TT>.</TT>"),
the following element is an optional byte offset into the CANbus message. The
offset is stored as an unsigned 16-bit integer (using <TT>strtoul()</TT> again
for the conversion), but to remain within the limits of the message buffer it
should be restricted to a maximum value of seven. The converted value is placed
in <TT>pcanIo->offset</TT>, which defaults to zero if no offset is given.</P>
<P>The final element is a general-purpose parameter, introduced by a space or
tab character. The value is first converted to a signed 32-bit integer using
<TT>strtol()</TT> which is placed in <TT>pcanIo->parameter</TT>. A pointer to
any remaining characters is placed in <TT>pcanIo->paramStr</TT>.</P>
<P>If the string is successfully converted without errors, canIoParse will
also call <TT>canOpen()</TT> to initialise the <TT>pcanIo->canBusID</TT>
bus identifier.</P>
<H4>Returns</H4>
<BLOCKQUOTE>
<PRE>int</PRE>
</BLOCKQUOTE>
<BLOCKQUOTE><TABLE BORDER=1 >
<TR BGCOLOR="#FFFFFF">
<TD><B>Symbol/Value</B></TD>
<TD><B>Meaning</B></TD>
</TR>
<TR>
<TD>0</TD>
<TD>OK</TD>
</TR>
<TR>
<TD>S_can_badAddress</TD>
<TD>illegal input string or NULL input parameters</TD>
</TR>
<TR>
<TD>S_can_noDevice</TD>
<TD>No matching device name found</TD>
</TR>
<TR>
<TD>ENOMEM</TD>
<TD><TT>malloc()</TT> returned NULL</TD>
</TR>
</TABLE></BLOCKQUOTE>
<H4>Example</H4>
<BLOCKQUOTE>
<PRE>canIo_t myIo;
int status;
status = canIoParse("CAN1/20:0126.4 0xfff", &myIo)
if (status) {
printf("Address string rejected\n");
return -1;
}</PRE>
</BLOCKQUOTE>
<HR>
<H3><A NAME="canWrite"></A>canWrite()</H3>
<P>Writes a message to the given CANbus</P>
<PRE>int canWrite (canBusID_t busID, const canMessage_t *pmessage, int timeout);</PRE>
<H4>Parameters</H4>
<DL>
<DT><TT>canBusID_t busID</TT></DT>
<DD>CANbus device identifier, obtained from <TT>canOpen()</TT></DD>
<DT><TT>const canMessage_t *pmessage</TT></DT>
<DD>The message to be transmitted.</DD>
<DT><TT>double timeout</TT></DT>
<DD>Delay in seconds, indicating how long to wait for exclusive access to the
TIP810 module. A negative delay means want forever.</DD>
</DL>
<H4>Description</H4>
<P>This routine is called to transmit a message on a particular CANbus.
The <TT>canMessage_t</TT> type is defined as the following structure in
<I>canBus.h</I>:</P>
<BLOCKQUOTE>
<PRE>typedef struct {
canID_t identifier; /* 0 .. 2047 with holes! */
enum {
SEND = 0, RTR = 1
} rtr; /* Remote Transmission Request */
epicsUInt8 length; /* 0 .. 8 */
epicsUInt8 data[CAN_DATA_SIZE]; /* CAN_DATA_SIZE = 8 */
} canMessage_t;</PRE>
</BLOCKQUOTE>
<P>When called, <TT>canWrite()</TT> obtains exclusive access to the TIP810
transmission buffer, converts the message into the correct form for the
interface chip and copies it to the hardware registers. Finally it sends a
Transmit Message command to the chip. The exclusive access semaphore will be
released by the Interrupt Service Routine when it receives a notification from
the chip that the message has been transmitted successfully.</P>
<H4>Returns</H4>
<BLOCKQUOTE>
<PRE>int</PRE>
</BLOCKQUOTE>
<BLOCKQUOTE><TABLE BORDER=1 >
<TR BGCOLOR="#FFFFFF">
<TD><B>Symbol/Value</B></TD>
<TD><B>Meaning</B></TD>
</TR>
<TR>
<TD>0</TD>
<TD>OK</TD>
</TR>
<TR>
<TD>S_t810_badDevice</TD>
<TD>canBusID not valid</TD>
</TR>
<TR>
<TD>S_can_badMessage</TD>
<TD>invalid field in the message buffer</TD>
</TR>
<TR>
<TD>S_t810_transmitterBusy</TD>
<TD>system fault somewhere</TD>
</TR>
<TR>
<TD>S_t810_timeout</TD>
<TD>transmit semaphore timed out</TD>
</TR>
</TABLE></BLOCKQUOTE>
<H4>Example</H4>
<BLOCKQUOTE>
<PRE>canIo_t myIo;
canMessage_t message;
char data[] = "STOP";
int status;
status = canIoParse("CAN1/20:0126 0xfff", &myIo);
if (status == OK) {
message.identifier = myIo.identifier;
message.rtr = SEND;
message.length = strlen(data);
memcpy(&message.data[0], data, message.length);
status = canWrite(myIo.canBusID, &message, myIo.timeout);
}</PRE>
</BLOCKQUOTE>
<HR>
<H3><A NAME="canMessage"></A>canMessage()</H3>
<P>Register CAN message call-back</P>
<PRE>int canMessage(canBusID_t busID, canID_t identifier,
canMsgCallback_t *pcallback, void *pprivate);</PRE>
<H4>Parameters</H4>
<DL>
<DT><TT>canBusID_t busID</TT></DT>
<DD>CANbus device identifier, obtained from <TT>canOpen()</TT></DD>
<DT><TT>canID_t identifier</TT></DT>
<DD>The CAN message identifier for which call-backs are required.</DD>
<DT><TT>canMsgCallback_t *pcallback</TT></DT>
<DD>The address of the routine to be called whenever matching messages
are received.</DD>
<DT><TT>void *pprivate</TT></DT>
<DD>A parameter which is passed to the call-back routine to help it identify
its context.</DD>
</DL>
<H4>Description</H4>
<P>This routine is used to add a call-back routine for a particular CAN message
identifier on the given CANbus. Call-backs can be registered for any CAN message
identifier, and there can be more than one call-back using the same ID - all
routines are called in turn when a message with the relevant identifier is
received. The call-back routine must not change the message at all, and should
copy any information it needs from the message buffer before returning.
Processing should still be kept to a minimum though as the callback is executed
in a single high priority thread which services all TIP810 devices. The
call-back routine's prototype is defined as a <TT>canMsgCallback_t</TT>:</P>
<PRE>void callback(void *pprivate, const canMessage_t *pmessage);</PRE>
<P>The <TT>pprivate</TT> value supplied when the call-back is registered with
<TT>canMessage()</TT> will be passed to the call-back routine with each message
to allow it to identify its context.</P>
<H4>Returns</H4>
<BLOCKQUOTE>
<PRE>int</PRE>
</BLOCKQUOTE>
<BLOCKQUOTE><TABLE BORDER=1 >
<TR BGCOLOR="#FFFFFF">
<TD><B>Symbol/Value</B></TD>
<TD><B>Meaning</B></TD>
</TR>
<TR>
<TD>0</TD>
<TD>OK</TD>
</TR>
<TR>
<TD>S_can_badMessage</TD>
<TD>bad identifier or NULL call-back routine</TD>
</TR>
<TR>
<TD>S_can_badDevice</TD>
<TD>bad device pointer</TD>
</TR>
<TR>
<TD>ENOMEM</TD>
<TD><TT>malloc()</TT> returned NULL</TD>
</TR>
</TABLE></BLOCKQUOTE>
<H4>Example</H4>
<BLOCKQUOTE>
<PRE>void myCallback(void *ctx, const canMessage_t *pmessage) {
/* Update value whenever message arrives */
short *pvalue = ctx;
memcpy(pvalue, &pmessage->data[0], sizeof(short));
}
...
int status;
static short value;
status = canMessage(myIo.canBusID, myIo.identifier, myCallback, &value);</PRE>
</BLOCKQUOTE>
<HR>
<H3><A NAME="canMsgDelete"></A>canMsgDelete()</H3>
<P>Delete CAN message call-back</P>
<PRE>int canMsgDelete(canBusID_t busID, canID_t identifier,
canMsgCallback_t *pcallback, void *pprivate);</PRE>
<H4>Parameters</H4>
<DL>
<DT><TT>canBusID_t busID</TT></DT>
<DD>CANbus device identifier, obtained from <TT>canOpen()</TT></DD>
<DT><TT>canID_t identifier</TT></DT>
<DD>The CAN message identifier for which call-backs were registered.</DD>
<DT><TT>canMsgCallback_t *pcallback</TT></DT>
<DD>The address of the routine being called whenever matching messages
were received.</DD>
<DT><TT>void *pprivate</TT></DT>
<DD>The parameter passed to the call-back routine to help it identify
its context.</DD>
</DL>
<H4>Description</H4>
<P>This routine is used to remove a call-back routine already registerd for a particular CAN
message identifier on the given CANbus.</P>
<P>Exactly the same parameters given when the call-back was registered with
<TT>canMessage()</TT> must be passed to <TT>canMsgDelete()</TT> for it to be
successfully deleted.</P>
<H4>Returns</H4>
<BLOCKQUOTE>
<PRE>int</PRE>