etisserant@0: /*
etisserant@0: This file is part of CanFestival, a library implementing CanOpen Stack.
etisserant@0:   ____    _    _   _
etisserant@0:  / ___|  / \  | \ | | ___  _ __   ___ _ __
etisserant@0: | |     / _ \ |  \| |/ _ \| '_ \ / _ \ '_ \
etisserant@0: | |___ / ___ \| |\  | (_) | |_) |  __/ | | |
etisserant@0:  \____/_/   \_\_| \_|\___/| .__/ \___|_| |_|
etisserant@0:                           |_|
etisserant@0:           ____                      _
etisserant@0:          / ___|__ _ _ __   __ _  __| | __ _
etisserant@0:         | |   / _` | '_ \ / _` |/ _` |/ _` |
etisserant@0:         | |__| (_| | | | | (_| | (_| | (_| |
etisserant@0:          \____\__,_|_| |_|\__,_|\__,_|\__,_|
etisserant@0: 
etisserant@0:                    canfestival@canopencanada.ca
etisserant@0: /_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
etisserant@0: 
etisserant@0: See COPYING file for copyrights details.
etisserant@0: 
etisserant@0: This library is free software; you can redistribute it and/or
etisserant@0: modify it under the terms of the GNU Lesser General Public
etisserant@0: License as published by the Free Software Foundation; either
etisserant@0: version 2.1 of the License, or (at your option) any later version.
etisserant@0: 
etisserant@0: This library is distributed in the hope that it will be useful,
etisserant@0: but WITHOUT ANY WARRANTY; without even the implied warranty of
etisserant@0: MARKETING or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
etisserant@0: Lesser General Public License for more details.
etisserant@0: 
etisserant@0: You should have received a copy of the GNU Lesser General Public
etisserant@0: License along with this library; if not, write to the Free Software
etisserant@0: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
etisserant@0: */
etisserant@0: 
etisserant@0: 
etisserant@0: CanFestival driver for the Philips ARM7 model LPC2138 , with a Philips
etisserant@0: SJA1000 CAN controler, and running on the eCOS operating system.
etisserant@0: 
etisserant@0: Driver Features:
etisserant@0: Full CANfestival-3 support including:
etisserant@0: DS-150/205: CAN Power Management Layer specification (sleep/wake-up)
etisserant@0: DS-201: CAN low level layer
etisserant@0: DS-301: CANopen Application layer and Communication Profile (basic CANopen specification)
etisserant@0: DS-303-1: LED diagnostic usage (led.c)
etisserant@0: DS-305: Layer Setting Service (lss.c) to set the baudrateand node ID in a PnP fashion.
etisserant@0: NVRAM: Non Volatil Ram (nvram.c) Full support for internal Philips IAT programming FLASH mode
etisserant@0: 
etisserant@0: 
etisserant@0: To use this driver, you need to proceed to do all these steps.
etisserant@0: NB: We choose to leave this driver in .o object code to keep the capability
etisserant@0: to make on-the-fly redefinition of some parameters for all examples.
etisserant@0: 
etisserant@0: Step 1
etisserant@0: -----------
etisserant@0: Have a developpement workstation. To build everything, we chose to use
etisserant@0: an old AMD K6/2-300Mhz running with FreeBSD-5.2-RELEASE freely available
etisserant@0: at http://www.freebsd.org/.
etisserant@0: To install freebsd, download the two floppy images from
etisserant@0: ftp://ftp.freebsd.org/pub/FreeBSD/releases/i386/5.2-RELEASE/floppies
etisserant@0: and copy them to a simple floppy disk by typeing:
etisserant@0: 	dd if=./image.dd of=/dev/fd0
etisserant@0: 	dd if=./image2.dd of=/dev/fd0
etisserant@0: and proceed to boot on them.
etisserant@0: You can use Linux or Windows also or any other O/S where you can use GCC.
etisserant@0: 
etisserant@0: on FreeBSD, you need to configure the serial port by editing the /etc/rc/serial
etisserant@0: config file by adding this entry:
etisserant@0: 
etisserant@0: lpc2000 () {
etisserant@0:         # Philips LPC2000 serial port configuration for 57600 bauds connection.
etisserant@0: 
etisserant@0:         ci=$1; shift
etisserant@0:         co=$1; shift
etisserant@0: 
etisserant@0:         for i in $*
etisserant@0:         do
etisserant@0:                 # Lock clocal on, hupcl off.
etisserant@0:                 # XON-XOFF printer
etisserant@0:                 stty < /dev/ttyi${ci}${i} clocal -hupcl ixon -imaxbel -ixany -ixoff -crtscts 57600
etisserant@0:                 stty < /dev/ttyl${ci}${i} clocal  hupcl
etisserant@0:                 stty < /dev/cuai${co}${i} clocal -hupcl ixon -imaxbel -ixany -ixoff -crtscts 57600
etisserant@0:                 stty < /dev/cual${co}${i} clocal  hupcl
etisserant@0:         done
etisserant@0: }
etisserant@0: 
etisserant@0: ###############
etisserant@0: lpc2000		d a 0 1  # to configure COM1 and COM2, mean, /dev/cuaa0 and /dev/cuaa1
etisserant@0: ###############
etisserant@0: 
etisserant@0: Step 2
etisserant@0: -----------
etisserant@0: Find an upload tool to be able to flash the LPC2138.
etisserant@0: We found the lpc2isp at the address: 
etisserant@0: 
etisserant@0: 	http://guest.engelschall.com/~martin/lpc21xx/isp/index.html
etisserant@0: 
etisserant@0:  You can use this upload script to call it with proper arguments.
etisserant@0: 
etisserant@0: #!/bin/sh
etisserant@0: lpc21isp -term -control build/terminal.hex /dev/cuaa1 57600 14746
etisserant@0: 
etisserant@0: 
etisserant@0: Step 3
etisserant@0: -----------
etisserant@0: Proceed to build a GCC cross compiler to be able to produce ARM7TDMI compatible
etisserant@0: binary. Go to the port directory of your FreeBSD
etisserant@0: 
etisserant@0: 	cd /usr/ports/devel/arm-elf-binutils
etisserant@0: 	gmake install
etisserant@0: 
etisserant@0: 	cd /usr/ports/devel/arm-elf-gcc295
etisserant@0: 	gmake install
etisserant@0: 
etisserant@0: And add the installation binary PATH to your environment variables. 
etisserant@0: 
etisserant@0: 	cd /etc
etisserant@0: 	vi profile
etisserant@0: 
etisserant@0: 		export PATH=$PATH:/usr/local/armelf/bin
etisserant@0: 
etisserant@0: 
etisserant@0: Step 4
etisserant@0: -----------
etisserant@0: Build an eCOS tree for the LPC2138.
etisserant@0: Download eCOS from  http://www.ecoscentric.com  and proceed to compile
etisserant@0: the configtool program.  
etisserant@0: 
etisserant@0: 	cd /usr/ports/devel/ecos-tools/
etisserant@0: 	gmake install
etisserant@0: 
etisserant@0: 	untar our special package for eCOS named  eCOS-OLIMEX-p2138.tgz in 
etisserant@0: 	the eCOS three on your files system.
etisserant@0: 
etisserant@0: Start now your configtool for eCOS:
etisserant@0: 	configtool 
etisserant@0: 
etisserant@0: Choose the right target 
etisserant@0: For our purpose, we choose to use an OLIMEX P2138 target board.
etisserant@0: This target is not in the list, we created it from a derivative of
etisserant@0: the OLIMEX P2106. We simply selected an other processor in the pulldown menu
etisserant@0: of the configtool. The LPC2138. Adjust some memory capacity, and that's it.
etisserant@0: 
etisserant@0: When all you need is properly selected in the configtool, you click on
etisserant@0: Save_As and you suggest a name like My2138. 
etisserant@0: After, you click on Generate Build Tree.
etisserant@0: 	cd My2138_build
etisserant@0: 	gmake depend
etisserant@0: 	gmake
etisserant@0: 	gmake install
etisserant@0:  And now you have you own eCOS tree for your project in  My2138_install
etisserant@0: 
etisserant@0: Step 5
etisserant@0: -----------
etisserant@0: Prepare the hardware board for this project. We chose to use an
etisserant@0: http://www.olimex.com/  board, the P2138.
etisserant@0: Any other LPC2138 evaluation could made the job.
etisserant@0: On the P2138 board, we have a little area that we can use to solder
etisserant@0: the SJA1000 controler.
etisserant@0: See can_controler.gif to know how to solder all wires.
etisserant@0: 
etisserant@0: Warning: If you want to use different GPIO (General Purpose Input Output)
etisserant@0: pin to fit with your own project, 
etisserant@0: you can choose a different one, but you need
etisserant@0: to be sure to properly define then in the lpc2138_pinout.h
etisserant@0: 
etisserant@0: Step 6
etisserant@0: -----------
etisserant@0: Put the CANfestival-3.tar.gz stuff in My2138_install/src/CANfestival-3
etisserant@0: 	cd My2138_install/src/CANfestival-3
etisserant@0: 	./configure target=ecos-lpc2138-sja1000
etisserant@0: 	gmake
etisserant@0: 	cd My2138_install/lib
etisserant@0: 	ln -s My2138_install/src/CANfestival-3/src/libcanfestival.a
etisserant@0: 	cd My2138_install/src 
etisserant@0: 	ln -s My2138_install/src/CANfestival-3/driver/ecos-lpc2138-sja1000
etisserant@0: 
etisserant@0: Step 7
etisserant@0: -----------
etisserant@0: Now you are ready to build our demo.
etisserant@0:   cd My2138_install/src/CANfestival-3/examples/DS-406Master_ecos
etisserant@0: 	gmake
etisserant@0: 
etisserant@0:   cd My2138_install/src/CANfestival-3/examples/TerminalSlave_ecos
etisserant@0: 	gmake
etisserant@0: Step 8
etisserant@0: -----------
etisserant@0: To test, upload both .hex file to both targets with lpc21isp and
etisserant@0: see the DS-406 absolut rotary encoder transmiting his absolute value to the
etisserant@0: terminal.
etisserant@0: 
etisserant@0: 	For more info about this project, see http://www.oremeq.qc.ca/
etisserant@0: Step 9
etisserant@0: -----------
etisserant@0: For your own project, you can copy all the examples files in your own
etisserant@0: directory and modify them.
etisserant@0: 
etisserant@0: What is important to understand is:
etisserant@0: 
etisserant@0: driver/ecos_lpc2138_sja1000:
etisserant@0: 
etisserant@0: 	build_baudrate.c is a commande line tool to generate the proper
etisserant@0: 		timing file for your sja1000 regarding your sja1000 clk.
etisserant@0: 			see the Makefile for adjustment.
etisserant@0: 
etisserant@0: 	canOpenDriver.c is the only link between the libcanfestival and
etisserant@0: 		the hardware.
etisserant@0: 			f_can_send
etisserant@0: 			f_can_receive
etisserant@0: 			interrupts
etisserant@0: 			nvram_save/load
etisserant@0: 			baudrate
etisserant@0: 
etisserant@0: 	eCOS-OLIMEX-p2138.tgz  eCOS package for the OLIMEX p2138 evaluation board
etisserant@0: 		you have to untar that files in your eCOS three.
etisserant@0: 		
etisserant@0: 	sja1000.c containe only function for initialization or 
etisserant@0: 		configuration of the CAN controler. All this stuff is
etisserant@0: 		_not_ use by the libcanfestival. You have to call them
etisserant@0: 		from your main() to enable CAN with your needed configuration.
etisserant@0: 
etisserant@0: 		hardware init 
etisserant@0: 			
etisserant@0: 	lpc2138.c All the basic stuff to run the LPC2138
etisserant@0: 		iat_flash  user programmable internal flash of the lpc2138
etisserant@0: 
etisserant@0: 	lpc2138_pinout.h  Is your LPC2138 pinout definition. Modify this file
etisserant@0: 		if you want to redefine your pinout affectation.
etisserant@0: 
etisserant@0: 	time_slicer.c  eCOS implementation of the CANfestival scheduler.
etisserant@0: 		settimer
etisserant@0: 		alarm
etisserant@0: 
etisserant@0: 	applicfg.h is your configuration file for the libcanfestival
etisserant@0: 
etisserant@0: 	lpc2138_pinout.h define all your GPIO to fit macros.
etisserant@0: 
etisserant@0: 
etisserant@0: objdictedit:
etisserant@0: 	Objdictedit  will produce the dictionary.
etisserant@0: 	Generate your dictionnary. (Or use an already made YourFile.od with
etisserant@0: 	the tool: objdictgen.py
etisserant@0: 	The job is to implement all functions define in the YourFIle.c in
etisserant@0: 		your own project files.
etisserant@0: 
etisserant@0: Enjoye!!!!	
etisserant@0: 		Canopen Canada core team
etisserant@0: 		canfestival@canopencanada.ca