|
1 /* |
|
2 This file is part of CanFestival, a library implementing CanOpen Stack. |
|
3 ____ _ _ _ |
|
4 / ___| / \ | \ | | ___ _ __ ___ _ __ |
|
5 | | / _ \ | \| |/ _ \| '_ \ / _ \ '_ \ |
|
6 | |___ / ___ \| |\ | (_) | |_) | __/ | | | |
|
7 \____/_/ \_\_| \_|\___/| .__/ \___|_| |_| |
|
8 |_| |
|
9 ____ _ |
|
10 / ___|__ _ _ __ __ _ __| | __ _ |
|
11 | | / _` | '_ \ / _` |/ _` |/ _` | |
|
12 | |__| (_| | | | | (_| | (_| | (_| | |
|
13 \____\__,_|_| |_|\__,_|\__,_|\__,_| |
|
14 |
|
15 canfestival@canopencanada.ca |
|
16 /_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ |
|
17 |
|
18 See COPYING file for copyrights details. |
|
19 |
|
20 This library is free software; you can redistribute it and/or |
|
21 modify it under the terms of the GNU Lesser General Public |
|
22 License as published by the Free Software Foundation; either |
|
23 version 2.1 of the License, or (at your option) any later version. |
|
24 |
|
25 This library is distributed in the hope that it will be useful, |
|
26 but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
27 MARKETING or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
28 Lesser General Public License for more details. |
|
29 |
|
30 You should have received a copy of the GNU Lesser General Public |
|
31 License along with this library; if not, write to the Free Software |
|
32 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
33 */ |
|
34 |
|
35 |
|
36 CanFestival driver for the Philips ARM7 model LPC2138 , with a Philips |
|
37 SJA1000 CAN controler, and running on the eCOS operating system. |
|
38 |
|
39 Driver Features: |
|
40 Full CANfestival-3 support including: |
|
41 DS-150/205: CAN Power Management Layer specification (sleep/wake-up) |
|
42 DS-201: CAN low level layer |
|
43 DS-301: CANopen Application layer and Communication Profile (basic CANopen specification) |
|
44 DS-303-1: LED diagnostic usage (led.c) |
|
45 DS-305: Layer Setting Service (lss.c) to set the baudrateand node ID in a PnP fashion. |
|
46 NVRAM: Non Volatil Ram (nvram.c) Full support for internal Philips IAT programming FLASH mode |
|
47 |
|
48 |
|
49 To use this driver, you need to proceed to do all these steps. |
|
50 NB: We choose to leave this driver in .o object code to keep the capability |
|
51 to make on-the-fly redefinition of some parameters for all examples. |
|
52 |
|
53 Step 1 |
|
54 ----------- |
|
55 Have a developpement workstation. To build everything, we chose to use |
|
56 an old AMD K6/2-300Mhz running with FreeBSD-5.2-RELEASE freely available |
|
57 at http://www.freebsd.org/. |
|
58 To install freebsd, download the two floppy images from |
|
59 ftp://ftp.freebsd.org/pub/FreeBSD/releases/i386/5.2-RELEASE/floppies |
|
60 and copy them to a simple floppy disk by typeing: |
|
61 dd if=./image.dd of=/dev/fd0 |
|
62 dd if=./image2.dd of=/dev/fd0 |
|
63 and proceed to boot on them. |
|
64 You can use Linux or Windows also or any other O/S where you can use GCC. |
|
65 |
|
66 on FreeBSD, you need to configure the serial port by editing the /etc/rc/serial |
|
67 config file by adding this entry: |
|
68 |
|
69 lpc2000 () { |
|
70 # Philips LPC2000 serial port configuration for 57600 bauds connection. |
|
71 |
|
72 ci=$1; shift |
|
73 co=$1; shift |
|
74 |
|
75 for i in $* |
|
76 do |
|
77 # Lock clocal on, hupcl off. |
|
78 # XON-XOFF printer |
|
79 stty < /dev/ttyi${ci}${i} clocal -hupcl ixon -imaxbel -ixany -ixoff -crtscts 57600 |
|
80 stty < /dev/ttyl${ci}${i} clocal hupcl |
|
81 stty < /dev/cuai${co}${i} clocal -hupcl ixon -imaxbel -ixany -ixoff -crtscts 57600 |
|
82 stty < /dev/cual${co}${i} clocal hupcl |
|
83 done |
|
84 } |
|
85 |
|
86 ############### |
|
87 lpc2000 d a 0 1 # to configure COM1 and COM2, mean, /dev/cuaa0 and /dev/cuaa1 |
|
88 ############### |
|
89 |
|
90 Step 2 |
|
91 ----------- |
|
92 Find an upload tool to be able to flash the LPC2138. |
|
93 We found the lpc2isp at the address: |
|
94 |
|
95 http://guest.engelschall.com/~martin/lpc21xx/isp/index.html |
|
96 |
|
97 You can use this upload script to call it with proper arguments. |
|
98 |
|
99 #!/bin/sh |
|
100 lpc21isp -term -control build/terminal.hex /dev/cuaa1 57600 14746 |
|
101 |
|
102 |
|
103 Step 3 |
|
104 ----------- |
|
105 Proceed to build a GCC cross compiler to be able to produce ARM7TDMI compatible |
|
106 binary. Go to the port directory of your FreeBSD |
|
107 |
|
108 cd /usr/ports/devel/arm-elf-binutils |
|
109 gmake install |
|
110 |
|
111 cd /usr/ports/devel/arm-elf-gcc295 |
|
112 gmake install |
|
113 |
|
114 And add the installation binary PATH to your environment variables. |
|
115 |
|
116 cd /etc |
|
117 vi profile |
|
118 |
|
119 export PATH=$PATH:/usr/local/armelf/bin |
|
120 |
|
121 |
|
122 Step 4 |
|
123 ----------- |
|
124 Build an eCOS tree for the LPC2138. |
|
125 Download eCOS from http://www.ecoscentric.com and proceed to compile |
|
126 the configtool program. |
|
127 |
|
128 cd /usr/ports/devel/ecos-tools/ |
|
129 gmake install |
|
130 |
|
131 untar our special package for eCOS named eCOS-OLIMEX-p2138.tgz in |
|
132 the eCOS three on your files system. |
|
133 |
|
134 Start now your configtool for eCOS: |
|
135 configtool |
|
136 |
|
137 Choose the right target |
|
138 For our purpose, we choose to use an OLIMEX P2138 target board. |
|
139 This target is not in the list, we created it from a derivative of |
|
140 the OLIMEX P2106. We simply selected an other processor in the pulldown menu |
|
141 of the configtool. The LPC2138. Adjust some memory capacity, and that's it. |
|
142 |
|
143 When all you need is properly selected in the configtool, you click on |
|
144 Save_As and you suggest a name like My2138. |
|
145 After, you click on Generate Build Tree. |
|
146 cd My2138_build |
|
147 gmake depend |
|
148 gmake |
|
149 gmake install |
|
150 And now you have you own eCOS tree for your project in My2138_install |
|
151 |
|
152 Step 5 |
|
153 ----------- |
|
154 Prepare the hardware board for this project. We chose to use an |
|
155 http://www.olimex.com/ board, the P2138. |
|
156 Any other LPC2138 evaluation could made the job. |
|
157 On the P2138 board, we have a little area that we can use to solder |
|
158 the SJA1000 controler. |
|
159 See can_controler.gif to know how to solder all wires. |
|
160 |
|
161 Warning: If you want to use different GPIO (General Purpose Input Output) |
|
162 pin to fit with your own project, |
|
163 you can choose a different one, but you need |
|
164 to be sure to properly define then in the lpc2138_pinout.h |
|
165 |
|
166 Step 6 |
|
167 ----------- |
|
168 Put the CANfestival-3.tar.gz stuff in My2138_install/src/CANfestival-3 |
|
169 cd My2138_install/src/CANfestival-3 |
|
170 ./configure target=ecos-lpc2138-sja1000 |
|
171 gmake |
|
172 cd My2138_install/lib |
|
173 ln -s My2138_install/src/CANfestival-3/src/libcanfestival.a |
|
174 cd My2138_install/src |
|
175 ln -s My2138_install/src/CANfestival-3/driver/ecos-lpc2138-sja1000 |
|
176 |
|
177 Step 7 |
|
178 ----------- |
|
179 Now you are ready to build our demo. |
|
180 cd My2138_install/src/CANfestival-3/examples/DS-406Master_ecos |
|
181 gmake |
|
182 |
|
183 cd My2138_install/src/CANfestival-3/examples/TerminalSlave_ecos |
|
184 gmake |
|
185 Step 8 |
|
186 ----------- |
|
187 To test, upload both .hex file to both targets with lpc21isp and |
|
188 see the DS-406 absolut rotary encoder transmiting his absolute value to the |
|
189 terminal. |
|
190 |
|
191 For more info about this project, see http://www.oremeq.qc.ca/ |
|
192 Step 9 |
|
193 ----------- |
|
194 For your own project, you can copy all the examples files in your own |
|
195 directory and modify them. |
|
196 |
|
197 What is important to understand is: |
|
198 |
|
199 driver/ecos_lpc2138_sja1000: |
|
200 |
|
201 build_baudrate.c is a commande line tool to generate the proper |
|
202 timing file for your sja1000 regarding your sja1000 clk. |
|
203 see the Makefile for adjustment. |
|
204 |
|
205 canOpenDriver.c is the only link between the libcanfestival and |
|
206 the hardware. |
|
207 f_can_send |
|
208 f_can_receive |
|
209 interrupts |
|
210 nvram_save/load |
|
211 baudrate |
|
212 |
|
213 eCOS-OLIMEX-p2138.tgz eCOS package for the OLIMEX p2138 evaluation board |
|
214 you have to untar that files in your eCOS three. |
|
215 |
|
216 sja1000.c containe only function for initialization or |
|
217 configuration of the CAN controler. All this stuff is |
|
218 _not_ use by the libcanfestival. You have to call them |
|
219 from your main() to enable CAN with your needed configuration. |
|
220 |
|
221 hardware init |
|
222 |
|
223 lpc2138.c All the basic stuff to run the LPC2138 |
|
224 iat_flash user programmable internal flash of the lpc2138 |
|
225 |
|
226 lpc2138_pinout.h Is your LPC2138 pinout definition. Modify this file |
|
227 if you want to redefine your pinout affectation. |
|
228 |
|
229 time_slicer.c eCOS implementation of the CANfestival scheduler. |
|
230 settimer |
|
231 alarm |
|
232 |
|
233 applicfg.h is your configuration file for the libcanfestival |
|
234 |
|
235 lpc2138_pinout.h define all your GPIO to fit macros. |
|
236 |
|
237 |
|
238 objdictedit: |
|
239 Objdictedit will produce the dictionary. |
|
240 Generate your dictionnary. (Or use an already made YourFile.od with |
|
241 the tool: objdictgen.py |
|
242 The job is to implement all functions define in the YourFIle.c in |
|
243 your own project files. |
|
244 |
|
245 Enjoye!!!! |
|
246 Canopen Canada core team |
|
247 canfestival@canopencanada.ca |