|
1 /* |
|
2 This file is part of CanFestival, a library implementing CanOpen Stack. |
|
3 |
|
4 Copyright (C): Cosateq GmbH & Co.KG |
|
5 http://www.cosateq.com/ |
|
6 http://www.scale-rt.com/ |
|
7 |
|
8 See COPYING file for copyrights details. |
|
9 |
|
10 This library is free software; you can redistribute it and/or |
|
11 modify it under the terms of the GNU Lesser General Public |
|
12 License as published by the Free Software Foundation; either |
|
13 version 2.1 of the License, or (at your option) any later version. |
|
14 |
|
15 This library is distributed in the hope that it will be useful, |
|
16 but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
18 Lesser General Public License for more details. |
|
19 |
|
20 You should have received a copy of the GNU Lesser General Public |
|
21 License along with this library; if not, write to the Free Software |
|
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
23 */ |
|
24 |
|
25 /* |
|
26 example for application with CO-PCICAN card. |
|
27 */ |
|
28 |
|
29 #include <linux/module.h> |
|
30 #include <linux/comedi.h> |
|
31 #include <linux/comedilib.h> |
|
32 #include "canfestival.h" |
|
33 |
|
34 /* only for mdelay() */ |
|
35 #include <linux/delay.h> |
|
36 |
|
37 MODULE_LICENSE("GPL"); |
|
38 |
|
39 #define CHTX 2 /* channel number of the CO-PCICAN */ |
|
40 #define CHRX 0 /* channel number of the CO-PCICAN */ |
|
41 |
|
42 void mySyncHandler( CO_Data* d ) |
|
43 { |
|
44 printk( "test_copcican_comedi: got a SYNC message...\n" ); |
|
45 } |
|
46 |
|
47 static int main( void ) |
|
48 { |
|
49 s_BOARD bd; |
|
50 CO_Data myData; |
|
51 CAN_PORT port; |
|
52 Message myMessage; |
|
53 const char busname[] = "/dev/comedi0"; |
|
54 const char baudrate[] = "1M"; |
|
55 comedi_t *dev; |
|
56 |
|
57 memset( &myData, 0x00, sizeof(CO_Data) ); |
|
58 myData.CurrentCommunicationState.csSYNC = 1; |
|
59 myData.post_sync = mySyncHandler; |
|
60 bd.busname = (char*)busname; |
|
61 bd.baudrate = (char*)baudrate; |
|
62 |
|
63 printk( "test_copcican_comedi: This example sends three SYNCs from port#%u to port#%u with a CO-PCICAN card\n", CHTX, CHRX ); |
|
64 |
|
65 /* direction: 0=RX, 1=TX */ |
|
66 co_pcican_select_channel( CHRX, 0 ); |
|
67 co_pcican_select_channel( CHTX, 1 ); |
|
68 |
|
69 port = canOpen( &bd, &myData ); |
|
70 |
|
71 if( port == NULL ) |
|
72 { |
|
73 /* something strange happenend */ |
|
74 return 0; |
|
75 } |
|
76 |
|
77 /* get device pointer to control the opened device */ |
|
78 dev = get_dev_of_port( port ); |
|
79 |
|
80 co_pcican_enter_config_mode( dev ); |
|
81 co_pcican_configure_selected_channel( dev, &bd, 0 ); |
|
82 co_pcican_configure_selected_channel( dev, &bd, 1 ); |
|
83 co_pcican_enter_run_mode( dev ); |
|
84 |
|
85 memset( &myMessage, 0x00, sizeof(Message) ); |
|
86 myMessage.cob_id = 0x80; /* SYNC message */ |
|
87 myMessage.len = 1; |
|
88 myMessage.data[0] = 0xA5; |
|
89 |
|
90 /* SEND HERE */ |
|
91 canSend( port, &myMessage ); |
|
92 |
|
93 myMessage.data[0] = 0x5A; |
|
94 canSend( port, &myMessage ); |
|
95 |
|
96 myMessage.data[0] = 0xA5; |
|
97 canSend( port, &myMessage ); |
|
98 |
|
99 /* mySyncHandler() is called by the receive thread and shows a received SYNC message in the kernel log */ |
|
100 mdelay( 1*1000 ); /* 1s */ |
|
101 |
|
102 canClose( &myData ); |
|
103 |
|
104 return 0; |
|
105 } |
|
106 |
|
107 static int init(void) |
|
108 { |
|
109 printk("test_copcican_comedi for CanFestival loaded\n"); |
|
110 |
|
111 return main(); |
|
112 } |
|
113 |
|
114 static void exit(void) |
|
115 { |
|
116 printk("test_copcican_comedi unloaded\n"); |
|
117 } |
|
118 |
|
119 module_init(init); |
|
120 module_exit(exit); |