Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 114

EXPERIMENT 1: Open source software such as Linux flavors will be used.

Ability to use industry standard tools for Verification and validation. AIM: To Port a compressed Embedded Linux kernel image (Linux 2.6 Kernel) to the RAM of ARM9 Processor and network the Linux-bootable ARM9 Single Board Computer to PC through Ethernet to display a message. TYPE OF PROTOBOARD USED: EXPLORER ARM-9 DEVELOPMENT BOARD HOW TO START WITH TRITON IDE Double click on the icon-Triton on your Desktop Select the workspace in which you can create all

your projects as shown in the figure below. Click OK.

Select workspace & Click OK

Compiled by R. Mohan Kumar Asst. Prof (Sr.Gr)/ECE

EMBEDDED SYSTEMS LAB MANUAL

Triton IDE C/C++ Environment opens as shown in below figure in which you can create new project, open existing one etc.

To create new project go to Project menu Then click Project New C Project. You will get below figure.

Compiled by R. Mohan Kumar Asst. Prof( Sr.Gr)/ECE CE

EMBEDDED SYSTEMS LAB MANUAL

In the Project Name field, type name of the project as display. Do not use spaces or special characters in the project name.

Select the Target as per the board you have. i.e.ARM9 Select the Variant from the variant list. i.e.AT91SAM9260

Select Operating System as per your requirement. Here we should select Linux as the operating system Select the Port from Port field. i.e.COM1

Select the Baud Rate from dropdown list.i.e.38400 Compiled by R. Mohan Kumar Asst. Prof( Sr.Gr)/ECE CE

EMBEDDED SYSTEMS LAB MANUAL

Select the Build options as SDRAM, Download options as ISP Utility, Debug as MONITOR. You can also change the location of project. For that, uncheck use default location and then browse your location. Check Create Project Using Template. then click NEXT

Enter the various fields & Click NEXT

Below screen will appear, Debug and Release configurations would be checked. Select the type of project that you want to build. By default Project Type is Executable (Gnu)

Compiled by R. Mohan Kumar Asst. Prof( Sr.Gr)/ECE CE

EMBEDDED SYSTEMS LAB MANUAL

Uncheck debug mode & click FINISH

Debug-Project can be debugged on target board using serial JTAG and Ethernet Release-Project is run on Target board without debugging Uncheck the debug and click FINISH

The project is created and opened in the IDE. You should see the following components:

To create a new file, CLICK FILE > NEW > SOURCE FILE Browse the source folder location & enter source filename display.c

Compiled by R. Mohan Kumar Asst. Prof( Sr.Gr)/ECE CE

EMBEDDED SYSTEMS LAB MANUAL

Select new Source File

The Projects window contains a tree view of the components of the project, source files and file properties.

Compiled by R. Mohan Kumar Asst. Prof( Sr.Gr)/ECE CE

EMBEDDED SYSTEMS LAB MANUAL

Enter your Project Code here

You can enter the code in the display.c file.

You can double click the display.c tab in the Editor view to expand the view.

/************************************************************** Display.c ***************************************************************/ #include<stdio.h> int main() { int i = 0; for(;i<5;i++) { printf("\n%d HDL SOLUTIONS...",i); } return 0; }

Compiled by R. Mohan Kumar Asst. Prof( Sr.Gr)/ECE CE

EMBEDDED SYSTEMS LAB MANUAL

Save the display.c by choosing File > Save.

You will notice an asterisk in front of the file name on the tab in the Editor view (Workspace). The asterisk indicates that the file has changed, but has not been saved. So, save the file for every modification in the program.

To compile project you need to select Release mode.

Debug mode: This creates an executable hex file which you, after downloading on the target board, are able to debug. Release mode: This creates an executable hex file which you can download on the target board, but you wont be able to debug.

To build project in Release mode---Right click on the DISPLAY project and point to Active Build Configuration and select Release as shown in the below screen

Select the Release mode & Build your Project

To Build Project right click on DISPLAY project and select Build Project.

Compiled by R. Mohan Kumar Asst. Prof( Sr.Gr)/ECE CE

EMBEDDED SYSTEMS LAB MANUAL

If

Click Build Console view to check for any errors as shown in the below figure. your project has built successful display.hex will be created.

If there are any errors in the project Build Console view will display the error messages and from Build Output view you can check the location of errors in your code. When you build the project, the display.hex is generated

Compiled by R. Mohan Kumar Asst. Prof( Sr.Gr)/ECE CE

EMBEDDED SYSTEMS LAB MANUAL

SWITCH ON THE POWER SUPPLY OF ARM 9 SINGLE BOARD COMPUTER Output on HyperTerminal

Open

Triton IDE; from TOOLS menu, click Hyper terminal and set the Baud rate as 38400

Set baud rate as 38400 for HyperTerminal output

Compiled by R. Mohan Kumar Asst. Prof( Sr.Gr)/ECE CE

EMBEDDED SYSTEMS LAB MANUAL

Type ls to check the list of files, then press enter

Compiled by R. Mohan Kumar Asst. Prof( Sr.Gr)/ECE CE

EMBEDDED SYSTEMS LAB MANUAL

Type cd /var/lib/tftpboot, then press enter

Compiled by R. Mohan Kumar Asst. Prof( Sr.Gr)/ECE CE

EMBEDDED SYSTEMS LAB MANUAL

Type ls, then press enter

Enter your system IP address. Type ping 192.168.0.12, then press enter

To stop the running process, press CONTROL+C

Compiled by R. Mohan Kumar Asst. Prof( Sr.Gr)/ECE CE

EMBEDDED SYSTEMS LAB MANUAL

To Create a new file in Linux, type touch <your filename>. This command creates an empty file.

Compiled by R. Mohan Kumar Asst. Prof( Sr.Gr)/ECE CE

EMBEDDED SYSTEMS LAB MANUAL

touch display.out Then press enter

Type ls, then press enter It creates your file name display.out

Compiled by R. Mohan Kumar Asst. Prof( Sr.Gr)/ECE CE

EMBEDDED SYSTEMS LAB MANUAL

To change the file permission to read/write & execution operation , Type chmod 777 display.out then press enter & type ls, then press enter.

(To get permission to receive/execute the file from your ARM9 EMB linux OS)

It shows the output file name display.out

Compiled by R. Mohan Kumar Asst. Prof( Sr.Gr)/ECE CE

EMBEDDED SYSTEMS LAB MANUAL

Go to Start. Go to Run mode Open the command prompt

Compiled by R. Mohan Kumar Asst. Prof( Sr.Gr)/ECE CE

EMBEDDED SYSTEMS LAB MANUAL

Type Oasis\ide\workspace, then press enter

Type c:\windows\system32\ping 192.168.0.240 ,then press enter

Compiled by R. Mohan Kumar Asst. Prof( Sr.Gr)/ECE CE

EMBEDDED SYSTEMS LAB MANUAL

Type cd display then cd release, then press enter

Type dir to check your output file, then press enter

Compiled by R. Mohan Kumar Asst. Prof( Sr.Gr)/ECE CE

EMBEDDED SYSTEMS LAB MANUAL

Type c:\windows\system32\tftp i 192.168.0.240 put display.out, then press enter

Minimize the run mode and open the HyperTerminal window

Type ./display.out then enter, you will see the output message on hyper terminal window

Compiled by R. Mohan Kumar Asst. Prof( Sr.Gr)/ECE CE

EMBEDDED SYSTEMS LAB MANUAL

RESULT:
We create the open source software in C/C++ and implement to the ARM9 Linux Boot Shell with simple printing our message in linux kernel. We are able to create source codes for Mutex, Semaphore, Fork, Pipes, Message Send & Receiving and Socket Server Programming, etc.,. The sample codes are given in Appendix A.

Compiled by R. Mohan Kumar Asst. Prof( Sr.Gr)/ECE CE

EMBEDDED SYSTEMS LAB MANUAL

EXPERIMENT 2: High level language programming (C, C++) and porting it on a processor. Aim: To implement the I/O Porting using the external peripheral devices in ARM7 Processor (UART, STEPPER MOTOR, Graphical LCD Display, LED Display, SEVEN SEGMENT Display, KEYPAD, ADC/DAC, SD/MMC, I2C, SPI, I2S, CAN, LIN, USB, PCI, Ethernet). TYPE OF PROTOBOARD USED: Spirit-II / Voyager II ARM-7 Protoboard HOW TO START WITH TRITON IDE

Double click on the icon-Triton on your Desktop

Select the workspace in which you can create all your projects as shown in the figure below. Click OK.

Select workspace & Click OK

Triton IDE C/C++ Environment opens as shown in below figure in which you can create new project, open existing one etc.
Compiled by R. Mohan Kumar Asst. Prof( Sr.Gr)/ECE CE

EMBEDDED SYSTEMS LAB MANUAL

To create new project go to Project menu Then click Project New C Project. You will get below figure.

t Selec New t ojec C pr

Compiled by R. Mohan Kumar Asst. Prof( Sr.Gr)/ECE CE

EMBEDDED SYSTEMS LAB MANUAL

In the Project Name field, type name of the project as LED. Do not use spaces or special characters in the project name.

Select the Target as per the board you have. i.e.ARM7 Select the Variant from the variant list. i.e.LPC2148

Select Operating System as per your requirement. Here we should select NONE as the operating system Select the Port from Port field. i.e.COM1 Select the Baud Rate from dropdown list.i.e.38400

Select the Build options as ROM, Download options as ISP Utility, Debug as MONITOR.

You can also change the location of project. For that, uncheck use default location and then browse your location.
Compiled by R. Mohan Kumar Asst. Prof( Sr.Gr)/ECE CE

EMBEDDED SYSTEMS LAB MANUAL

Check Create Project Using Template. then click NEXT

Enter the various fields & Click NEXT

Below screen will appear, select Debug and Release configurations.

Select the type of project that you want to build. By default Project Type is Executable (Gnu)

Compiled by R. Mohan Kumar Asst. Prof( Sr.Gr)/ECE CE

EMBEDDED SYSTEMS LAB MANUAL

Uncheck debug mode & click FINISH

Debug-Project can be debugged on target board using serial JTAG and Ethernet Release-Project is run on Target board without debugging Uncheck the debug and click FINISH The project is created and opened in the IDE. You should see the following components: o The Projects window contains a tree view of the components of the project, source files and file properties.
o

The Source Editor window with a file called LED_main.c open.

Compiled by R. Mohan Kumar Asst. Prof( Sr.Gr)/ECE CE

EMBEDDED SYSTEMS LAB MANUAL

You can enter the code in the LED_main.c file, by replacing the line: //TODO: You can write your code at here

Enter your Project Code here

You can double click the LED_main.c tab in the Editor view to expand the view.
***************************************************************

LED_main.c
***************************************************************/ int main(void){ #include<LPC21xx.H> #include<BOARD.H> *IODIR0=0X007F8000; *IOCLR0=0X007F8000; int i; while(1) { *IOSET0=0X007F8000; for(i=0;i<200000;i++); *IOCLR0=0X007F8000; for(i=0;i<200000;i++); } return 0;
Compiled by R. Mohan Kumar Asst. Prof( Sr.Gr)/ECE CE

EMBEDDED SYSTEMS LAB MANUAL

Save the LED_main.c by choosing File > Save.

You will notice an asterisk in front of the file name on the tab in the Editor view (Workspace). The asterisk indicates that the file has changed, but has not been saved. So, save the file for every modification in the program.

To compile project you need to select Release mode.

Debug mode: This creates an executable hex file which you, after downloading on the target board, is able to step-by-step debugging. Release mode: This creates an executable hex file which you can download on the target board but you wont be able to debug.

To build project in Release mode---Right click on the LED project and point to Active Build Configuration and select Release as shown in the below screen.

Select the Release mode & Build your Project

To Build Project right click on LED project and select Build

Project.
Compiled by R. Mohan Kumar Asst. Prof( Sr.Gr)/ECE CE

EMBEDDED SYSTEMS LAB MANUAL

Open the build console view to check for any errors as shown in the below figure.

If your project has built successful, LED.hex will Compiled by R. Mohan Kumar Asst. Prof( Sr.Gr)/ECE CE

be created.

EMBEDDED SYSTEMS LAB MANUAL

If there are any errors in the project, Build Console view will display the error messages and from Build Output view you can check the location of errors in your code. When you build the project, the led.hex is generated.

You can see where the new file is generated by opening the C/C++ Projects view and expanding the LED project node as shown in the following figure.

Here LED.hex file is created which is to be downloaded on target board and run the program.
Right

click on the LED.hex file generated and click Download as shown below.

Compiled by R. Mohan Kumar Asst. Prof( Sr.Gr)/ECE CE

EMBEDDED SYSTEMS LAB MANUAL

Right click the *.hex file & click DOWNLOAD

Connect the hardware kit with the serial connector and power supply provided. Switch on the hardware kit. Put the switch in ISP mode for the program to be downloaded.

Right click on the LED.hex file and download the executable file on to the board. Once, the program is downloaded, shift the mode from ISP to RUN and reset the board to verify the output.

Compiled by R. Mohan Kumar Asst. Prof( Sr.Gr)/ECE CE

EMBEDDED SYSTEMS LAB MANUAL

DETAILS OF ON BOARD INTERFACES Switch S1- Power ON/OFF the board Switch S2- Reset switch Switch S7- To select ISP or RUN mode
NAME OF INTERFACES LED & DIP SWITCH BUZZER RELAY PIN CONFIGURATION LED (P0.15 to P0.22) Switch (P0.2 to P0.6) & (P0.8 to P0.10) Buzzer (P0.7) Relay (P1.26) OUTPUT STATUS LED-input Switch-output Buzzer-output Relay-output SETTINGS & DESCRIPTIONS 8 LEDs on by DIP switch Connect JP8 to ON /OFF buzzer Connect CN14 (3 pin connector )to ON relay Connect CN13 (6 pin connector )to ON motor Connect JP6 (1-2)to drive segment Connect JP3 (1-2) for LCD Numbers display on 7-Segment by keypad Connect JP5 (1-2) for ADC

STEPPER MOTOR

Stepper motor (P0.11 to P0.14) 7-Segment (P1.16 to P1.23) LCD (P1.16 to P1.23) and (P0.28 to P0.29) keypad (P0.2 to P0.9) ADC POT connected in (P0.28)

Stepper motoroutput 7-Segment-output (0-9,A-F) display LCD-output Given message display 4x4 matrix Keypad-input 7-Segment-output Output on HyperTerminal

7-SEGMENT

LCD

KEYPAD

ADC

Output on HyperTerminal to verify the output of ADC Program


Compiled by R. Mohan Kumar Asst. Prof( Sr.Gr)/ECE CE

EMBEDDED SYSTEMS LAB MANUAL

Once, the program is downloaded, open Triton IDE.

From TOOLS menu ,click Hyper terminal and set the Baud rate as 38400 Then shift the mode from ISP to RUN and reset the board to verify the output on the hyper terminal

Set baud rate as 38400 for HyperTerminal output

RESULT: We create and implement the simple I/O Porting with LEDs using the GPIO ports in ARM7 Processor. We are able to create and I/O porting of the peripherals like UART, STEPPER MOTOR, Graphical / Text LCD, LED, SEVEN SEGMENT Display, KEYPAD, ADC/DAC, SD/MMC, I2C, SPI, I2S, CAN, LIN, USB, PCI, Ethernet. The sample codes are given in Appendix B.

Compiled by R. Mohan Kumar Asst. Prof( Sr.Gr)/ECE CE

EMBEDDED SYSTEMS LAB MANUAL

EXPERIMENT 3: Create FSM of a typical application and implement on an FPGA. AIM: To create the Finite State Machine for Traffic Light Controller and implement using Xilinx Spartan 3 (XC3S400) FPGA. Traffic Light controller is implemented on FPGA and verified using Traffic Light Interface Module. There are simple rules for traffic lights on one node, and complex ways of regulating a whole infrastructure of them. It is necessary to adjust general algorithms.Spartan-3 - IM includes a TRAFFIC LIGHT Interface Module. This module is interfaced to the Trainer using 60 pin FRC cable. DESIGN DESCRIPTION: Initially all Red Lights will be ON (South, West, North, East, Pedestrian) Green Lights will be ON, Right, Left & Straight paths are free for Traffic. Yellow Phase will be ON, respective left & pedestrian paths are free for traffic. Same flow is repeated for all four paths. (South, west, north, east). Flowchart:-

To implement Traffic Light controller refer the Compiled by R. Mohan Kumar Asst. Prof( Sr.Gr)/ECE CE

waveform given below

EMBEDDED SYSTEMS LAB MANUAL

Algorithm is implemented in VHDL with a 13 state Finite State Machine. Refer Fig

Compiled by R. Mohan Kumar Asst. Prof( Sr.Gr)/ECE CE

EMBEDDED SYSTEMS LAB MANUAL

Fig: State Diagram for Traffic Light Controller

Abbreviation used:
South PSG Pedestrian South Green PSR Pedestrian South Red RS Right South LS Left South SS Straight South YS Yellow South REDS Red South North PNR- Pedestrian North red West PWR Pedestrian West Red PWG Pedestrian West Green RW Right West LW Left West SW South West YW Yellow West REDW Red West East PEG Pedestrian East green

Compiled by R. Mohan Kumar Asst. Prof( Sr.Gr)/ECE CE

EMBEDDED SYSTEMS LAB MANUAL

PNG Pedestrian North green RN Right North LN Left North SN Straight North YN - Yellow North
REDN Red North

PER Pedestrian Ease Red RE Right East LE Left East SE Straight East YE Yellow East
REDE Red East

EXPERIMENTAL SET UP:

Figure shows the Traffic Light Interface to SPARTAN-3 FPGA

Compiled by R. Mohan Kumar Asst. Prof( Sr.Gr)/ECE CE

EMBEDDED SYSTEMS LAB MANUAL

COMPONENT DIAGRAM

VHD CODE FOR TRAFFIC LIGHT CONTROLLER


library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; ---- Uncomment the following library declaration if instantiating ---- any Xilinx primitives in this code. --library UNISIM; --use UNISIM.VComponents.all; entity traffic_fsm is Port ( CLK_4M,RESET : in std_logic; TRC_LS,TRC_LW,TRC_LN,TRC_LE: out std_logic; TRC_SS,TRC_SW,TRC_SN,TRC_SE: out std_logic; TRC_RS,TRC_RW,TRC_RN,TRC_RE : out std_logic; TRC_REDS,TRC_REDW,TRC_REDN,TRC_REDE : out std_logic; TRC_YS,TRC_YW,TRC_YN,TRC_YE : out std_logic; TRC_PSR,TRC_PWR,TRC_PNR,TRC_PER : out std_logic; TRC_PSG,TRC_PWG,TRC_PNG,TRC_PEG : out std_logic); end traffic_fsm; --*********************** Abbreviation used *************************** --South PSG ? Pedestrian south (Green) -PSR ? Pedestrian south (Red) -TRC_SS ? Straight south Compiled by R. Mohan Kumar Asst. Prof( Sr.Gr)/ECE CE

EMBEDDED SYSTEMS LAB MANUAL -TRC_RS ? Right south -TRC_LS ? Left south--TRC_YS ? Yellow south -REDS ? Red south ---West PWR ? Pedestrian west (red ) -PWG ? Pedestrian west (Green) -TRC_SW ? South west -TRC_RW ? Right west -TRC_LW ? Left west -TRC_YW ? Yellow west -REDW ? Red west ---North PNR- Pedestrian north red -PNG ? Pedestrian north green -TRC_SN ? Straight North -TRC_RN ? Right north -TRC_LN ? Left North -TRC_YN - Yellow north -REDN ? Red north --East PEG ? Pedestrian East (green) -PER ? Pedestrian Ease (Red) -TRC_SE? Straight East -RE ? Right East -TRC_LE ? Left East -TRC_YE ? Yellow east -REDE ? Red east ********************************************************************** architecture Behavioral of traffic_fsm is type state is (start,south_g,south_orange,south_r,west_g,west_orange, west_r,east_g,east_orange,east_r,north_g,north_orange,north_r); signal ps , ns : state; signal div : std_logic_vector(30 downto 0); signal clk_s : std_logic; signal cnt : std_logic_vector(3 downto 0) ; begin --*************************** Divider ************************** process(CLK_4M,RESET) begin if(RESET = '1') then div <= (others => '0'); elsif(CLK_4M'event and CLK_4M = '1') then div <= div + 1; end if; end process; clk_s <= div(20); --*************************** Counter ************************** process(clk_s ,RESET) begin if(RESET = '1') then cnt <= (others => '0'); Compiled by R. Mohan Kumar Asst. Prof( Sr.Gr)/ECE CE

EMBEDDED SYSTEMS LAB MANUAL elsif(clk_s'event and clk_s = '0') then cnt <= cnt + 1; end if; end process; --*************************** Memory_logic ********************* process(clk_s,RESET) begin if (RESET = '1')then ps <= start; elsif(clk_s'event and clk_s = '1') then ps <= ns; end if; end process; --*************************** Input_logic ********************** process(ps) begin case ps is when start => ns <= south_g; when south_g => if(cnt = 10)then ns <= south_orange; else ns <= south_g; end if; when south_orange => if(cnt = 14) then ns <= south_r; else ns <= south_orange; end if; when south_r => if(cnt = 15)then ns <= west_g; else ns <= south_r; end if; when west_g => if(cnt = 10) then ns <= west_orange; else ns <= west_g; end if; when west_orange => if(cnt = 14) then ns <= west_r; else ns <= west_orange; end if; when west_r => Compiled by R. Mohan Kumar Asst. Prof( Sr.Gr)/ECE CE

EMBEDDED SYSTEMS LAB MANUAL if(cnt = 15 )then ns <= north_g; else ns <= west_r; end if; when north_g => if(cnt = 10)then ns <= north_orange; else ns <= north_g; end if; when north_orange => if(cnt = 14)then ns <= north_r; else ns <= north_orange; end if; when north_r => if(cnt = 15)then ns <= east_g; else ns <= north_r; end if; when east_g => if(cnt = 10)then ns <= east_orange; else ns <= east_g; end if; when east_orange => if(cnt = 14)then ns <= east_r; else ns <= east_orange; end if; when east_r => if(cnt = 15)then ns <= south_g; else ns <= east_r; end if; when others => ns <= start; end case; end process; --*************************** Output_logic ************************** process(ps) begin TRC_REDS <= '0'; TRC_REDW <= '0'; TRC_REDN <= '0'; Compiled by R. Mohan Kumar Asst. Prof( Sr.Gr)/ECE CE TRC_REDE <= '0'; TRC_RS <= '0'; TRC_RW <= '0'; TRC_RN <= '0'; TRC_RE <= '0';

EMBEDDED SYSTEMS LAB MANUAL TRC_SS <= '0'; TRC_SW <= '0'; TRC_SN <= '0'; TRC_SE<= '0'; TRC_LS <= '0'; TRC_LW <= '0'; TRC_LN <= '0'; TRC_LE <= '0'; TRC_PSG <= '0'; TRC_PWG <= '0'; TRC_PNG <= '0'; TRC_PEG <= '0'; TRC_YS <= '0'; TRC_YW <= '0'; TRC_YN <= '0'; TRC_RS <= '1'; TRC_SS <= '1'; TRC_LE <= '1'; TRC_REDW <= '1'; TRC_REDN <= '1'; TRC_REDE <= '1'; TRC_PSR <= '1'; TRC_PWR <= '1'; TRC_PNR <= '1'; TRC_PER <= '1'; when south_orange => TRC_PNG <= '1'; TRC_LE <= '1'; TRC_LS <= '1'; TRC_YS <= '1'; TRC_REDW <= '1'; TRC_REDN <= '1'; TRC_REDE <= '1'; TRC_PSR <= '1'; TRC_PWR <= '1'; TRC_PER <= '1'; when south_r => TRC_LS <= '1'; TRC_REDW <= '1'; TRC_REDN <= '1'; TRC_REDE <= '1'; TRC_PSR <= '1'; TRC_PWR <= '1'; TRC_PNR <= '1'; TRC_PER <= '1'; when west_g => TRC_LW <= '1'; TRC_LS <= '1'; TRC_RW <= '1'; TRC_SW <= '1'; TRC_REDS <= '1'; TRC_REDN <= '1'; Compiled by R. Mohan Kumar Asst. Prof( Sr.Gr)/ECE CE TRC_YE <= '0'; TRC_PSR <= '0'; TRC_PWR <= '0'; TRC_PNR <= '0'; TRC_PER <= '0'; case ps is when start => TRC_REDS <= '1'; TRC_REDW <= '1'; TRC_REDN <= '1'; TRC_REDE <= '1'; when south_g => TRC_LS <= '1'; TRC_REDE <= '1'; TRC_PSR <= '1'; TRC_PWR <= '1'; TRC_PNR <= '1'; TRC_PER <= '1'; when west_orange => TRC_LW <= '1'; TRC_LS <= '1'; TRC_PEG <= '1'; TRC_YW <= '1'; TRC_REDS <= '1'; TRC_REDN <= '1'; TRC_REDE <= '1'; TRC_PSR <= '1'; TRC_PWR <= '1'; TRC_PNR <= '1'; when west_r => TRC_LW <= '1'; TRC_REDS <= '1'; TRC_REDN <= '1'; TRC_REDE <= '1'; TRC_PSR <= '1'; TRC_PWR <= '1'; TRC_PNR <= '1'; TRC_PER <= '1'; when north_g => TRC_LN <= '1'; TRC_RN <= '1'; TRC_SN <= '1'; TRC_LW <= '1'; TRC_REDS <= '1'; TRC_REDW <= '1'; TRC_REDE <= '1'; TRC_PSR <= '1'; TRC_PWR <= '1'; TRC_PNR <= '1'; TRC_PER <= '1';

EMBEDDED SYSTEMS LAB MANUAL when north_orange => TRC_LN <= '1'; TRC_LW <= '1'; TRC_PSG <= '1'; TRC_YN <= '1'; TRC_REDS <= '1'; TRC_REDW <= '1'; TRC_REDE <= '1'; TRC_PWR <= '1'; TRC_PNR <= '1'; TRC_PER <= '1'; when north_r => TRC_LN <= '1'; TRC_REDS <= '1'; TRC_REDW <= '1'; TRC_REDE <= '1'; TRC_PSR <= '1'; TRC_PWR <= '1'; TRC_PNR <= '1'; TRC_PER <= '1'; TRC_PNR <= '1'; TRC_PER <= '0'; when east_r => TRC_LE <= '1'; TRC_REDS <= '1'; TRC_REDW <= '1'; TRC_REDN <= '1'; TRC_PSR <= '1'; TRC_PWR <= '1'; TRC_PNR <= '1'; TRC_PER <= '1'; when others => TRC_REDS <= '0'; TRC_REDW <= '0'; TRC_REDN <= '0'; TRC_REDE <= '0'; TRC_RS <= '0'; TRC_RW <= '0'; TRC_RN <= '0'; TRC_RE <= '0'; TRC_SS <= '0'; TRC_SW <= '0'; TRC_SN <= '0'; TRC_SE<= '0'; TRC_LS <= '0'; TRC_LW <= '0'; TRC_LN <= '0'; TRC_LE <= '0'; TRC_PSG <= '0'; TRC_PWG <= '0'; TRC_PNG <= '0'; TRC_PEG <= '0'; TRC_YS <= '0'; TRC_YW <= '0'; TRC_YN <= '0'; TRC_YE <= '0'; TRC_PSR <= '0'; TRC_PWR <= '0'; TRC_PNR <= '0'; TRC_PER <= '0'; end case; end process; end Behavioral;--

when east_g => TRC_RE <= '1'; TRC_SE<= '1'; TRC_LE <= '1'; TRC_LN <= '1'; TRC_REDS <= '1'; TRC_REDW <= '1'; TRC_REDN <= '1'; TRC_PSR <= '1'; TRC_PWR <= '1'; TRC_PNR <= '1'; TRC_PER <= '1'; when east_orange => TRC_LN <= '1'; TRC_LE <= '1'; TRC_PWG <= '1'; TRC_YE <= '1'; TRC_REDS <= '1'; TRC_REDW <= '1'; TRC_REDN <= '1'; TRC_PSR <= '1';

Description of above Code: To Start the Traffic light controller


1.

Initially the Red light of all the directions is ON.

Compiled by R. Mohan Kumar Asst. Prof( Sr.Gr)/ECE CE

EMBEDDED SYSTEMS LAB MANUAL 2.

Traffic starts from the South Direction; hence the green light of South direction goes ON. The signals that are ON, now are : TRC_LS (left south) 1. TRC_RS (right south) 1. TRC_SS (straight south) 1. TRC_LE (left east) 1. TRC_REDW (red west) 1. TRC_REDN (red north) 1. TRC_REDE (red east) 1. TRC_PSG (pedestrian south red) 1. TRC_PWG (pedestrian west red) 1. TRC_PNG (pedestrian north red) 1. TRC_PEG (pedestrian east red) 1. Similarly when Yellow light of South direction is ON then the signals that are ON now are

TRC_LS (left south) 1. TRC_YS (yellow south) 1. TRC_LE (left east) 1. TRC_REDW (red west) 1. TRC_REDN (red north) 1. TRC_REDE (red east) 1. TRC_PSR (pedestrian south red) 1. TRC_PWR (pedestrian west red) 1. TRC_PNR (pedestrian north red) 1. TRC_PER (pedestrian east red) 1.

Similarly when Red light of South direction is ON then the signals that are ON now are

TRC_LS (left south) 1. TRC_REDW (red west) 1. TRC_REDN (red north) 1. TRC_REDE (red east) 1. TRC_PSR (pedestrian south red) 1. TRC_PWR (pedestrian west red) 1. TRC_PNR (pedestrian north red) 1. TRC_PER (pedestrian east red) 1.

Compiled by R. Mohan Kumar Asst. Prof( Sr.Gr)/ECE CE

EMBEDDED SYSTEMS LAB MANUAL

During this time all ways are Blocked for 1 second except left south ( ls -1 ) and so on. After that it goes clockwise for all Direction (i.e.:- South then West then North then East) similarly.

Compiled by R. Mohan Kumar Asst. Prof( Sr.Gr)/ECE CE

EMBEDDED SYSTEMS LAB MANUAL

Traffic light controller Interface to SPARTAN-3 FPGA


net net CLK_4M RESET loc = loc = p181; p182; net net net net net net net TRC_LS TRC_LW TRC_LN TRC_LE loc = loc = loc = loc = p150 P130 P125 p107 #J3-25 #J3-6 #J3-9 #J3-20 net net net net net net net net TRC_SS TRC_SW TRC_SN TRC_SE loc = loc = loc = loc = p152 P146 p123 p115 #J3-26 #J3-4 #J3-11 #J3-17 net net net net net net net net TRC_RS TRC_RW TRC_RN TRC_RE loc = loc = loc = loc = p111 P147 P122 P114 #J3-23 #J3-3 #J3-12 #J3-18 net net net net net TRC_REDS loc = p108 #J3-21 TRC_PSG TRC_PWG TRC_PNG TRC_PEG loc = loc = loc = loc = p12 P148 p128 P116 #J3-28 #J3-2 #J3-7 #J3-16 TRC_PSR TRC_PWR TRC_PNR TRC_PER loc = loc = loc = loc = P13 p149 p117 P124 #J3-27 #J3-1 #J3-10 #J3-15 TRC_YS TRC_YW TRC_YN TRC_YE loc = loc = loc = loc = p113 P131 P119 p106 #J3-24 #J3-5 #J3-14 #J3-19 TRC_REDW TRC_REDN TRC_REDE loc = loc = loc = P126 P120 p109 #J3-8 #J3-13 #J3-22

Compiled by R. Mohan Kumar Asst. Prof( Sr.Gr)/ECE CE

EMBEDDED SYSTEMS LAB MANUAL

HOW TO START WITH Xilinx ISE


[XILINX ISE 9.1 is preferred for low configuration PCs]

Double click on the icon-Xilinx ISE 9.1i on your Desktop (or) Start---All Programs---Xilinx ISE 9.1i---Project Manager

Compiled by R. Mohan Kumar Asst. Prof( Sr.Gr)/ECE CE

EMBEDDED SYSTEMS LAB MANUAL

WORK SPACE SOURCE WINDO W

TRANSCRIP T
PROCESS WINDOW

Create a new ISE project which will target the FPGA device on the Spartan-3 IM demo board. To create a new project: 1. SelectFile > New Project... The New Project Wizard appears. 2. Type tutorial in the Project Name field. 3 Enter or browse to a location (directory path) for the new project. A tutorial subdirectory is created automatically. 4. Verify that HDL is selected from the Top-Level Source Type list. 5. Click Next to move to the device properties page.

Enter the Project Name and Location , then click NEXT

Compiled by R. Mohan Kumar Asst. Prof( Sr.Gr)/ECE CE

EMBEDDED SYSTEMS LAB MANUAL

6. Fill in the properti es in the table as shown below: Product Category: All Family: Spartan3
Compiled by R. Mohan Kumar Asst. Prof( Sr.Gr)/ECE CE

EMBEDDED SYSTEMS LAB MANUAL

Device: XC3S400 Package: PQ208 Speed Grade: -4 Top-Level Source Type: HDL Synthesis Tool: XST (VHDL/Verilog) Simul ator: ISE Simulator (VHDL/Verilog) Preferred Language: Verilog (or VHDL)
Verify that Enable Enhanced Design Summary is selected. Leave the default values in the remaining fields.

Click next to proceed to the Create New Source window in the New Project Wizard. At the end of the next section, your new project will be complete.

Create an HDL Source In th is section, you w ill create the top-level HDL file for your design. Determine the language that you wish to use for the tutorial. Then, continue either to the Creating a VHDL Source section below, or skip to the Creating a Verilog
Compiled by R. Mohan Kumar Asst. Prof( Sr.Gr)/ECE CE

EMBEDDED SYSTEMS LAB MANUAL

Source section. Creating a Verilog Source Create the top-level Verilog source file for the project as follows: 1. Click New Source in the New Project dialog box. 2. Select Verilog Module as the source type in the New Source dialog box. 3. Type in the file name counter. 4. Verify that the Add to Project checkbox is selected. 5. Click Next. 6. Declare the ports for the counter design by filling in the port informa tion as shown below:

Compiled by R. Mohan Kumar Asst. Prof( Sr.Gr)/ECE CE

EMBEDDED SYSTEMS LAB MANUAL

Click next, and then Finish in the New Source Information dialog box to complete the new source file template. 8. Click Next, then Next, then Finish.
7.

Creating a VHDL Source Create a VHDL source file for the project as follows: 1. Click the New Source button in the New Project Wizard. 2. Select VHDL Module as the source type. 3. Type in the file name counter. 4. Verify that the Add to project checkbox is selected. 5. Click Next. 6. Declare the ports for the counter design by filling in the port informa tion as shown below:

Compiled by R. Mohan Kumar Asst. Prof( Sr.Gr)/ECE CE

EMBEDDED SYSTEMS LAB MANUAL

7. Click next, and then Finish in the New Source Wizard - Summary dialog box to complete the new source file template. 8. Click Next, then Next, then Finish.

The source file containing the entity/a rchitecture pair displays the Workspace, and the counter displays in the Source tab, as shown below:

Click on the symbol of FPGA device ,then right click to select New source

Compiled by R. Mohan Kumar Asst. Prof( Sr.Gr)/ECE CE

EMBEDDED SYSTEMS LAB MANUAL

Write the VHDL code in VHDL editor

Testing the Traffic Controller design on the FPGA board Once design is synthesized successfully it is ready to be implemented on FPGA.
Step 1: The first step for implementation is to generate constraint file. The constraint

file specifies the FPGA pins used for accessing the design.

Compiled by R. Mohan Kumar Asst. Prof( Sr.Gr)/ECE CE

EMBEDDED SYSTEMS LAB MANUAL

Step 2:

To create new UCF file. Right click on the device name and select NEW SOURCE. Select IMPLEMENTATION CONSTRAINT FILE in NEW SOURCE WIZARD and give suitable name for the Project. Click NEXT for the DEFINE MODULE Window.

Compiled by R. Mohan Kumar Asst. Prof( Sr.Gr)/ECE CE

EMBEDDED SYSTEMS LAB MANUAL

Step 3:

Click on the UCF File (Traffic_Light.ucf) and Select the Edit Constraints (Text). Write the constraint file as shown in figure below.

For implementing your design, from the source window select Generate Programming File from the process menu.

Compiled by R. Mohan Kumar Asst. Prof( Sr.Gr)/ECE CE

Step 4:

Procedure for downloading using iMPACT Boundary Scan Mode 1. Right click on Configure Device (iMPACT) -> and Say RUN or Double click on Configure Device (iMPACT). 2. Right click in workspace and select Initialize chain .The device is seen. 3. Right click on the device and select Program.

TRAFFIC LIGHT CONTROLLER ON 4 ROAD JUNCTIONS

NORTH

W E S T

E A S T

SOUTH

TRAFFIC LIGHT CONTROLLER ON OUTPUT LEDS

RESULT: We had done the Finite State Machine for Traffic Light Controller and implement using Xilinx Spartan 3 (XC3S400) FPGA.

EXPERIMENT 4: Application development, download partition between FPGA and ARM on Performance characteristics. AIM: To create and analyze performance between ARM and FPGA Processor application using a simple 4-bit counter program. TYPE OF PROTOBOARD USED: Herculis ARM-FPGA Fusion Board PROCEDURE: 1. Create and Generate the Hex file for 4 bit Counter C / C++ program with Triton IDE.
/************************************************************

ARM_Counter.c
************************************************************/ #define ALL 0x00FF0000 #define ALL 0x00FF0000 #include<LPC21xx.h> void delay (unsigned int); int main(void) { *IODIR0=0x00002000; *IODIR1=0x00FF0000; *IOCLR1=0x00FF0000; *IOSET1=0x00FF0000; *IOCLR0=0x00002000; //*IOSET0=0x00002000; while(1) { *IOSET1=0x00010000; //1 delay(400000); *IOCLR1=0x00FF0000; delay(150000); *IOSET1=0x00040000; //2 delay(400000); *IOCLR1=0x00FF0000; delay(150000); *IOSET1=0x00050000; //3 delay(400000); *IOCLR1=0x00FF0000; delay(150000); *IOSET1=0x00020000; //4 delay(400000);

*IOCLR1=0x00FF0000; delay(150000); *IOSET1=0x00060000; //5 delay(400000); *IOCLR1=0x00FF0000; delay(150000); *IOSET1=0x00030000; //6 delay(400000); *IOCLR1=0x00FF0000; delay(150000); *IOSET1=0x00070000; //7 delay(400000); *IOCLR1=0x00FF0000; delay(150000); *IOSET1=0x00080000; //8 delay(400000); *IOCLR1=0x00FF0000; delay(150000); *IOSET1=0x00090000; //9 delay(400000); *IOCLR1=0x00FF0000; delay(150000); *IOSET1=0x000c0000; //10 delay(400000); *IOCLR1=0x00FF0000; delay(150000); *IOSET1=0x000a0000; //11 delay(400000); *IOCLR1=0x00FF0000; delay(150000); *IOSET1=0x000b0000; //12 delay(400000); *IOCLR1=0x00FF0000; delay(150000); *IOSET1=0x000d0000; //13 delay(400000); *IOCLR1=0x00FF0000; delay(150000); *IOSET1=0x000e0000; //14 delay(400000); *IOCLR1=0x00FF0000; delay(150000); *IOSET1=0x000f0000; //15 delay(400000); *IOCLR1=0x00FF0000; delay(150000); *IOSET1=0x00000000; //16 delay(400000); *IOCLR1=0x00FF0000; delay(150000);

delay(400000); } return 0; } void delay(unsigned int count) { while(count!=0) count--; }


2.

Download the ARM_Counter.Hex file into ARM+FPGA Fusion Board and RUN the file. In that , ARM7s LED outputs are connected with Output LED LD8 to LD11 Create and Generate the Bit file for 4 bit Counter in VHDL program with Xilinx ISE.

3.

4.

/************************************************************

FPGA_Counter.vhd
************************************************************/ library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity fpga_counter is Port ( RESET : in STD_LOGIC; CLK_4M : in STD_LOGIC; COUNTER : out STD_LOGIC_VECTOR (4 downto 0)); end fpga_counter; architecture Behavioral of fpga_counter is SIGNAL CLKDIV : STD_LOGIC_VECTOR(30 DOWNTO 0); SIGNAL CNTR : STD_LOGIC_VECTOR(4 DOWNTO 0); SIGNAL en0,en1,en2,en3 : STD_LOGIC; begin PROCESS(RESET,CLK_4M) BEGIN IF(RESET = '1') THEN CLKDIV <= (OTHERS =>'0'); ELSIF(CLK_4M'EVENT AND CLK_4M = '1')THEN CLKDIV <= CLKDIV + '1'; END IF;

END PROCESS; PROCESS(RESET,CLK_4M,clkdiv) BEGIN IF(RESET = '1') THEN en1 <= '0'; en2 <= '0'; ELSIF(CLK_4M'EVENT AND CLK_4M = '1')THEN en1 <= CLKDIV (20); en2 <= en1; END IF; END PROCESS; en0 <= en1 and (not en2); PROCESS(RESET,CLK_4M,en0) BEGIN IF(RESET = '1') THEN CNTR <= (OTHERS =>'0'); ELSIF(CLK_4M'EVENT AND CLK_4M = '1')THEN IF(en0 = '1')THEN CNTR <= CNTR + '1'; END IF; END IF; END PROCESS; COUNTER <= CNTR; end Behavioral; -------------------------------------------------------UCF File for ARM+FPGA Fusion Board -------------------------------------------------------net "CLK_4M" loc = "p79"; net "RESET" loc = "p113"; net "COUNTER<0>" loc = "p61"; net "COUNTER<1>" loc = "p63"; net "COUNTER<2>" loc = "p64"; net "COUNTER<3>" loc = "p62";
5. Download the FPGA_Counter.bit file in to ARM+FPGA Fusion Board. 6. Now check the FPGA Counter output in LD1 to LD4 and verify the ARM and FPGA

Counter delay variations.

RESULT: We create and analyze performance between ARM and FPGA Processor with 4bit counter application by Xilinx ISE and Triton. Then, verify the speed and performance of Counter on ARM+FPGA Fusion Board. We able to create applications like UART and RTC based application on Fusion Board similarly.

EXPERIMENT 5: Application development & Hardware and Software Partitioning. AIM: To Partition the FPGA using SOC concept and implement a simple 4-bit Counter program with a Embedded Core TYPE OF PROTOBOARD USED: Herculis ARM-FPGA Fusion Board Introduction This lab guides you through the process of using Xilinx Platform Studio (XPS) to create a simple processor system. An MHS file and design netlists will be created. Objectives After completing this lab, you will be able to: Create an XPS project by using Base System Builder (BSB) Create a Counter hardware design by using Xilinx IPs available in the Embedded Design Kit

Procedure
The purpose of the lab exercises is to walk you through a complete hardware and software processor system design. Each lab will build upon the previous lab. In this lab, you will use the BSB of the XPS system to create a processor system consisting of the following processor IP: Microblaze DCM OPB bus OPB BRAM controller BRAM GPIO LEDs for displaying results

Figure 1-1. Processor IP

This lab comprises three primary steps: You will create a project using Base System Builder, analyze the project created, and generate the processor system netlists. Below each general instruction for a given procedure, you will find accompanying step-by-step directions and illustrated figures providing more detail for performing the general instruction. If you feel confident about a specific instruction, feel free to skip the step-by-step directions and move on to the next general instruction in the procedure.

Open the Project Step 1 Launch Xilinx Platform Studio (XPS) and create a project file in D:/mb/ by using Base System Builder. Select the Microblaze processor, the processor clock frequency as 32 MHz, the bus clock frequency as 32 MHz, and no debug interface.
1. Open XPS by selecting Start Programs Xilinx Platform

Studio 8.1i Xilinx Platform Studio

! Do not select Platform Studio SDK; this opens the Software Development Kit IDE. !

2. Select Base System Builder Wizard and Click Ok

Figure 1-2. New Base System Builder-Based Project Creation

This opens the Create New Project Using Base System Builder Wizard dialog box.

Figure 1-3. Create New Project Using Base System Builder Wizard Dialog Box

3. Specify the Project File as D:/mb/system.xmp and click <OK> 4. Select the I would like to create a new design option 5. Click Next to display the Select Board dialog box. Select I would

like to create system for Custom board.

Figure 1-4. Select I would like to create a system for custom board

6. Click Next to display the Select Processor dialog box

7.

Choose the FPGA device configuration

Figure 1-5. Select Processor Dialog Box

8. Select Microblaze as the processor , spartan3 as a architecture,

xc3s400 as device, PQ208 as a package, -4 as a speed grade.

9. Click Next to display the Configure Microblaze dialog box. Specify

settings to match the following: Reference Clock Frequency: 4 MHz This the external clock source on the board you are using. This clock will be used to generate the processor and bus clocks. The values allowed may depend on the FPGA or board you are using because certain on-chip resources (DCMs) may be required to perform clock division or multiplication. Processor Bus Clock Frequency: 4 MHz Reset polarity Active High Debug Interface: No debug Local memory (data and instruction) 8kB Cache setup No cache

Figure 1-6. Configure Microblaze Dialog Box

Select LEDs as the external device.

10. Click Next to display the Configure IO Interfaces dialog box. Click

on add device and select the GPIO option in IO interface type. Select LEDS under Device tab and click OK. Select 4 under GPIO Data width tab and leave the remaining parameters with the default settings. Refer to Figure 1-7. Note that the number of peripherals that appear on each window will depend on the resolution of your monitor.

Figure 1-7. Configure IO Interfaces Dialog Box

11. Click <Next> to display the Add Internal Peripherals dialog box.

At this point you could click Add Peripheral to add additional internal peripherals.

Figure 1-8. Add Internal Peripherals Dialog Box

12. Click <Next> to display the Software Configuration dialog box

Figure 1-9. Software Configuration Dialog Box

13. Click <Next> to view the memory configuration options

Figure 1-10. Configure Memory Test Application

14. Click Next to display the System Created dialog box which

summarizes the system being created. Note that the address map for the peripheral may differ.

Figure 1-11. System Created Dialog Box

15. Click Generate

A congratulations dialog box appears, indicating the files that BSB has created.
16. Click Finish to finish generating the project 17. Click <OK> when the Next Step dialog appears

Analyze the Created Project Step 2 Under the Project tab, study the created project files and view the project in block diagram view.

Figure 2-1.

18. Under the XPS Project tab, click on Generate and view Block

Diagram to open a block diagram view


19. Observe the various components that are used in the design

Figure 2-2. Block Diagram View of the Generated Project

You will see the Microblaze processor, dlmb_if_cntlr, ilmb_if_cntlr connected to the Microblaze processor side. Notice that the opb_gpio LEDs, opb_gpio LEDs_1 are connected to the opb bus.
?
1.

Right-click the LEDs block in system assembly view and click on configure IP, go through the various fields, and complete the following: Base address: High address: GPIO Data Bus Width: Channel 1 is bidirectional: Channel 1 is input only:

2. Why do you think that the DCM_module instances do not have connections to any of the other blocks in the design? ________________________________________________ ________________________________________________

Notice that you can change the parameters (such as base address, address range, or C_BAUDRATE) here to reflect the design specifications.
20. Close the block diagram view without saving any changes

The block diagram viewer is useful for viewing the overall system and bus connectivity. For more detail, you will utilize other tools. Generate the Hardware Netlists Step 3

Using PlatGen, generate the hardware netlist.


21. Open MHS file and change the following lines PORT fpga_0_LEDS_GPIO_d_out_pin = fpga_0_LEDS_GPIO_d_out, DIR = 0, VEC = [0:3] To PORT fpga_0_LEDS_GPIO_d_out_pin = fpga_0_LEDS_GPIO_d_out, DIR = 0, VEC = [3:0]

And save the changes.

22. In XPS, select hardware Generate Netlist or click

in the

toolbar

23. Observe the netlist generation in the console window as the generation

progresses
24. Open Windows Explorer by selecting Start Programs

Accessories Windows Explorer

25. Browse to the mb project directory

Several directories containing VHDL wrappers and implementation netlists have been created.
?

3. List the directories that were created.

________________________________________________________________

Generate the Hardware Bitstream Step 4


26. In project information area, Select Project, open UCF file by double

clicking over it given in Project Files. Enter the pin constraints and uncomment them. The dedicated ucf is provided at the end of this document.
27. In XPS, select hardware Generate Bitstream. 28. Observe the bitstream generation in the console window as the

generation progresses Generate the Software Libraries Step 5

29. In XPS, select software Generate Libraries and BSPs. 30. Observe the Libraries generation in the console window as the

generation progresses
31. Observe the xparameters.h file created in the testapp_memory under

applications tab

Writing C code

Step 6

32. In XPS, under Application tab, select Project: Testapp_memory

open TestApp_Memory.c.

33. Write the C code application in the workspace.

34. Source code for this project is given at the end of this document.

35.

In XPS, select software Build all users applications.

36.Observe the elf file generation in the console window as the generation progresses. 37.Create and Generate the Bit file for 4 bit Counter in VHDL program with Xilinx ISE.
/************************************************************

FPGA_Counter.vhd
************************************************************/ library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity fpga_counter is Port ( RESET : in STD_LOGIC; CLK_4M : in STD_LOGIC; COUNTER : out STD_LOGIC_VECTOR (8 downto 0)); end fpga_counter;

architecture Behavioral of fpga_counter is SIGNAL CLKDIV : STD_LOGIC_VECTOR(30 DOWNTO 0); SIGNAL CNTR : STD_LOGIC_VECTOR(4 DOWNTO 0); SIGNAL en0,en1,en2,en3 : STD_LOGIC; begin PROCESS(RESET,CLK_4M) BEGIN IF(RESET = '1') THEN CLKDIV <= (OTHERS =>'0'); ELSIF(CLK_4M'EVENT AND CLK_4M = '1')THEN CLKDIV <= CLKDIV + '1'; END IF; END PROCESS; PROCESS(RESET,CLK_4M,clkdiv) BEGIN IF(RESET = '1') THEN en1 <= '0'; en2 <= '0'; ELSIF(CLK_4M'EVENT AND CLK_4M = '1')THEN en1 <= CLKDIV (20); en2 <= en1; END IF; END PROCESS; en0 <= en1 and (not en2); PROCESS(RESET,CLK_4M,en0) BEGIN IF(RESET = '1') THEN CNTR <= (OTHERS =>'0'); ELSIF(CLK_4M'EVENT AND CLK_4M = '1')THEN IF(en0 = '1')THEN CNTR <= CNTR + '1'; END IF; END IF; END PROCESS; COUNTER <= CNTR; end Behavioral;

-------------------------------------------------------UCF File for ARM+FPGA Fusion Board -------------------------------------------------------net "CLK_4M" loc = "p79"; net "RESET" loc = "p113"; net "COUNTER<0>" loc = "p61"; net "COUNTER<1>" loc = "p63"; net "COUNTER<2>" loc = "p64"; net "COUNTER<3>" loc = "p62"; net "COUNTER<4>" loc = "p58"; net "COUNTER<5>" loc = "p57"; net "COUNTER<6>" loc = "p54"; net "COUNTER<7>" loc = "p52";

38.

In ISE, select Device Configuration update Bitstream to generate the download.bit file Step 7

Downloading into FPGA


39.

Open Impact software by selecting Start Programs Xilinx ISE 9.1i Accessories iMPACT.

40.

Impact project dialog box will open. Select create a new project (.ipf) option and click on OK. This will open Welcome to iMPACT dialog box.

41.

Keep the default setting Configure devices using Boundary-Scan [JTAG]. Click on Finish. This will identify the device xc3s400.

41. In the Assign New Configuration File, select the download.bit file from implementation directory of your ISE project. Click on Open. The download.bit file will be assigned to the FPGA. Right click on the device and Click on Program to configure the FPGA with download.bit file. 43. Download the download.bit file in to ARM+FPGA Fusion Board.
42.

44. Now

check the FPGA Counter output in LD1 to LD4 for softwarehardware partitioned output ie., through embedded core of FPGA and LD5 to LD8 for direct FPGA output.

Base System Builder can be used in XPS to create a project. Several files including an MHS file representing the processor system and a PBD file representing the schematic vieware created. After the system has been defined, the netlist of the processor system can be created. Answers Right-click the top LEDS block, configure IP and go through the various fields, and complete the following: Instance name: Base address: High address: GPIO Data Bus Width: Channel 1 is bidirectional: Channel 1 is Input only: LEDS 0x40020000 0x4002ffff 4 FALSE FALSE

Why do you think that the DCM_module instance does not have connections to any of the other blocks in the design?

This module generate signals which are area connected to almost every module in the design. For example, the clock signal generated by DCM_module is connected to the processor and opb controller. List the directories that were created. data etc hdl implementation pcores mb_0 synthesis TestApp_Memory __xps

Completed MHS File


PARAMETER VERSION = 2.1.0 PORT fpga_0_LEDS_GPIO_d_out_pin = fpga_0_LEDS_GPIO_d_out, DIR = O, VEC = [3:0] PORT sys_clk_pin = dcm_clk_s, DIR = I, SIGIS = DCMCLK PORT sys_rst_pin = sys_rst_s, DIR = I BEGIN microblaze PARAMETER INSTANCE = microblaze_0 PARAMETER HW_VER = 4.00.a PARAMETER C_USE_FPU = 0 BUS_INTERFACE DLMB = dlmb BUS_INTERFACE ILMB = ilmb BUS_INTERFACE DOPB = mb_opb BUS_INTERFACE IOPB = mb_opb PORT CLK = sys_clk_s END BEGIN lmb_v10 PARAMETER INSTANCE = ilmb PARAMETER HW_VER = 1.00.a PARAMETER C_EXT_RESET_HIGH = 1 PORT SYS_Rst = sys_rst_s PORT LMB_Clk = sys_clk_s END BEGIN lmb_v10 PARAMETER INSTANCE = dlmb PARAMETER HW_VER = 1.00.a PARAMETER C_EXT_RESET_HIGH = 1 PORT SYS_Rst = sys_rst_s PORT LMB_Clk = sys_clk_s END BEGIN lmb_bram_if_cntlr PARAMETER INSTANCE = dlmb_cntlr PARAMETER HW_VER = 1.00.b PARAMETER C_BASEADDR = 0x00000000 PARAMETER C_HIGHADDR = 0x00001fff BUS_INTERFACE SLMB = dlmb BUS_INTERFACE BRAM_PORT = dlmb_port END BEGIN lmb_bram_if_cntlr PARAMETER INSTANCE = ilmb_cntlr PARAMETER HW_VER = 1.00.b PARAMETER C_BASEADDR = 0x00000000

PARAMETER C_HIGHADDR = 0x00001fff BUS_INTERFACE SLMB = ilmb BUS_INTERFACE BRAM_PORT = ilmb_port END BEGIN bram_block PARAMETER INSTANCE = lmb_bram PARAMETER HW_VER = 1.00.a BUS_INTERFACE PORTA = ilmb_port BUS_INTERFACE PORTB = dlmb_port END BEGIN opb_v20 PARAMETER INSTANCE = mb_opb PARAMETER HW_VER = 1.10.c PARAMETER C_EXT_RESET_HIGH = 1 PORT SYS_Rst = sys_rst_s PORT OPB_Clk = sys_clk_s END BEGIN opb_gpio PARAMETER INSTANCE = LEDS PARAMETER HW_VER = 3.01.b PARAMETER C_GPIO_WIDTH = 4 PARAMETER C_IS_DUAL = 0 PARAMETER C_ALL_INPUTS = 0 PARAMETER C_IS_BIDIR = 0 PARAMETER C_BASEADDR = 0x40020000 PARAMETER C_HIGHADDR = 0x4002ffff BUS_INTERFACE SOPB = mb_opb PORT OPB_Clk = sys_clk_s PORT GPIO_d_out = fpga_0_LEDS_GPIO_d_out END BEGIN dcm_module PARAMETER INSTANCE = dcm_0 PARAMETER HW_VER = 1.00.a PARAMETER C_CLK0_BUF = TRUE PARAMETER C_CLKIN_PERIOD = 31.250000 PARAMETER C_CLK_FEEDBACK = 1X PARAMETER C_DLL_FREQUENCY_MODE = LOW PARAMETER C_EXT_RESET_HIGH = 1 PORT CLKIN = dcm_clk_s PORT CLK0 = sys_clk_s PORT CLKFB = sys_clk_s PORT RST = net_gnd PORT LOCKED = dcm_0_lock END

Completed .ucf File


Net sys_clk_pin LOC=p181; Net sys_rst_pin LOC=p182; ## System level constraints Net sys_clk_pin TNM_NET = sys_clk_pin; TIMESPEC TS_sys_clk_pin = PERIOD sys_clk_pin 250000 ps; Net sys_rst_pin TIG; ## IO Devices constraints #### Module LEDS constraints Net fpga_0_LEDS_GPIO_d_out_pin<0> LOC=p58; Net fpga_0_LEDS_GPIO_d_out_pin<1> LOC=p61; Net fpga_0_LEDS_GPIO_d_out_pin<2> LOC=p62; Net fpga_0_LEDS_GPIO_d_out_pin<3> LOC=p63;

Completed .c File
#include "xparameters.h" #include "xutil.h" #include "xio.h" #include "xgpio_l.h" main () { long count = 0, i; while(1){ XGpio_mSetDataReg(XPAR_LEDS_BASEADDR, 1, count); count = count + 1; for(i=0; i<10000000; i++); } }

RESULT: We create an embedded core through software partitioning of the actual hardware and implement a simple 4-bit counter application by Xilinx EDK Tool. Then verify the speed and performance of Partition on FPGA processor. In these Xilinx EDK, performs many kind of processing in Partitioning.

EXPERIMENT 6: Implementation of a wireless communication protocol on an embedded system AIM: To implement wireless communication protocol (like. ZigBee / Bluetooth / RF / RFID / GPS & WiFi) on an Embedded System. PROCEDURE FOR ZIGBEE Aim: To Interface a ZigBee module with ARM7 TYPE OF PROTOBOARD USED: Spirit-II/Voyager-II ARM-7 Protoboard 2 Nos Zigbee Transceiver Pair - 1 Pair Theory of Operation: Zigbee is a specification for a suite of high level communication protocols using small, low powered digital radios based on IEEE 802.15.4-2003 standard and are used extensively for Wireless Home Area Networks (WHANs), such as wireless light switches with lamps, electrical meters with in-home displays etc. ZigBee is targeted towards at RF applications that require a low data rate, long battery life and secure networking. Procedure and Observation: 1. Open Triton IDE. 2. Select a workspace and create a new Project ZIGBEE_LPC2148 3. Write in the program for ZIGBEE_LPC2148 as provided in the Documentation CD and ignore step 3 or else click File menu -> Add Project ->Existing Project into Workspace and click next. 4. If importing project browse the Documentation CD and select ZIGBEE_LPC2148 and also check option Copy projects into workspace and click finish. 5. Save the file, build the Project in Release Mode and generate hex file (ZIGBEE_LPC2148.hex) 6. Download the hex file to ARM7 Board. 7. Disconnect ARM7 UART1 from the PCs COM port. 8. Connect the ZigBee module to ARM7 board using the provided male to male serial cable. 9. Attach USB A to B cable between PCs USB port and the USB connector on ARM7 Processor add-on board. 10.Repeat steps 6, 7, 8 and 9 for another ARM7 board. 11.Slide RUN/ISP switch into Run mode and press momentarily.

12.Once the initialization is over type anything into one hyper terminal and that will be visible in the other hyper terminal. RESULT: We interfaced two ZigBee modules to two separate ARM7 protoboards and established communication between them. These ZigBee modules can be configured in various Network Topologies and are a drop-in replacement wireless applications such as Home Automation and Wireless Sensor Networks. PROCEDURE FOR BLUETOOTH Aim: To Interface a Bluetooth connected to ARM7 with a Computer TYPE OF PROTOBOARD USED: Spirit-II/Voyager-II ARM-7 Protoboard 1 No. Bluetooth Interface Module with dongle - 1 No. Theory of Operation: Conceived by Ericsson in 1994 as a wireless replacement to RS232 bluetooth today is a wireless technology for exchanging data over short distances (using short wavelength radio transmissions) and creating PANs (Personal Area Networks) with high levels of security. Utilizing the frequency hopping spread spectrum the modulation details of which are as under Basic data rate Keying) Extended Rate Keying) Extended Rate 1Mbit/s 2 Mbit/s 3 Mbit/s 8 GFSK (Gaussian Frequency Shift /4 DPSK (Differential Phase Shift DPSK (Differential Phase Shift Keying)

Procedure and Observation: 1. Open Triton IDE. 2. Select a workspace and create a new Project Bluetooth_LPC2148 3. Write in the program for Bluetooth_LPC2148 as provided in the Documentation CD and ignore step 3 or else click File menu -> Add Project ->Existing Project into Workspace and click next. 4. If importing project browse the Documentation CD and select Bluetooth_LPC2148 and also check option Copy projects into workspace and click finish. 5. Save the file, build the Project in Release Mode and generate hex file (Bluetooth_LPC2148.hex)

Download the hex file to ARM7 Board and Disconnect ARM7 UART1 from the PCs COM port. 7. Connect the Bluetooth module to ARM7 board using the provided male to male serial cable. 8. Attach USB A to B cable between PCs USB port and the USB connector on ARM7 Processor add-on board. 9. Slide RUN/ISP switch into Run mode and press momentarily and Power on the bluetooth addon board. 10.If Computer finds a new device and asks for drivers browse and upload the drivers for this cable provided in the Documentation CD. 11.Check the virtual COM port number on device manager. 12.Open a Hyper terminal with the found COM port number and select baud rate as 115200 13.Connect the provided USB Bluetooth Dongle to any of the Computers free USB port. 14.Wait for the automatic installation of the bluetooth software. 15.Double click the bluetooth icon visible in the system tray and use the software for searching and connecting to the bluetooth module. 16.If asked for a passkey the default passkey is 8888. 17.When connected open the device manager to again see the assigned outgoing COM port number. 18.Open hyper terminal for the COM port and type anything. This will be visible on another HT.
6.

RESULT: File transfer between a PC and ARM7 Protoboard through Bluetooth Interface is studied. PROCEDURE FOR RF MODULE Aim: To interface a RF Module to ARM7 Processor. TYPE OF PROTOBOARD USED: Spirit-II/Voyager-II ARM-7 Protoboard 2 Nos RF Transceiver Pair - 1 Pair Theory of Operation: In this exercise we establish communication between two RF modules from Nordic Semiconductors. These modules work in the ISM band of 2.4 GHz and have a SPI interface through which they are controlled and configured. Being a transceiver they establish full duplex communication. Communication between ARM7 and RF module are also of two types. They are

command mode and data mode. In command mode we tell the module that we will be using it as a transmitter or receiver etc. In data mode we either send or receive data depending on the operating mode. Procedure and Observation: 1. Open Triton IDE. 2. Select a workspace and create a new Project nordic_rf24l01p_LPC2148 3. Write in the program for nordic_rf24l01p_LPC2148 as provided in the Documentation CD and ignore step 3 or else click File menu -> Add Project ->Existing Project into Workspace and click next. 4. If importing project browse the Documentation CD and select nordic_rf24l01p_LPC2148 and also check option Copy projects into workspace and click finish. 5. Now open file nordic_rf24l01p_LPC2148_main.c and scroll to line number 16 6. Assign values to NRF24l01_MODE_TX as 1 and to NRF24l01_MODE_RX as 0 so that it looks like for Transmitter Enable. #define NRF24l01_MODE_TX 1 #define NRF24l01_MODE_RX0 7. Save the file, build the Project in Release Mode and generate hex file (nordic_rf24l01p_LPC2148.hex) 8. Download the hex file to ARM7 Board. 9. Reverse the assigned values for NRF24l01_MODE so that they look like for Receiver Enable. #define NRF24l01_MODE_TX 0 #define NRF24l01_MODE_RX1 10.Repeat step 7. 11. Download into another ARM7 board and not the one to which we had downloaded earlier. 12.Connect two separate RF modules to these two ARM7 boards to their appropriate connectors. One ARM7 board will act as a transmitter and the other as a receiver. 13.Connect these two boards to two different computers and open HyperTerminal in each one of them at baud rate 115200. 14.Slide RUN/ISP switch into Run mode and press momentarily. 15.Both these Hyper Terminals will give some initialization prints and at the end will tell the operating mode in which they are configured. 16.The board that is in Tx mode will ask for characters to send after initialization as completed. Type in anything and that will be visible on the hyper terminal connected on other board.

RESULT: File transfer between a PC and ARM7 Protoboard through an ISM band 2.4Ghz RF module pair over SPI is studied. This interface can be used in applications like Remote Monitoring, Wireless data transfer, Wireless Sensor Networks etc.

PROCEDURE FOR RFID SERIAL COMMUNICATION MODULE Aim: To Interface a RFID module with an ARM7 LPC2148 board and detect codes from various RFID cards. TYPE OF PROTOBOARD USED: Spirit-II/Voyager-II ARM-7 Protoboard 1 No RFID with tags - 1 Set Procedure and Observation: 1. Open Triton IDE. 2. Select a workspace and create a new Project VCOM_LPC2148. 3. Write in the program for VCOM_LPC2148 as provided in the Documentation CD and skip step 3 or else click File menu -> Add Project ->Existing Project into Workspace and click next. 4. If importing a project browse the Documentation CD and select VCOM_LPC2148 and also check option Copy projects into workspace and click finish. 5. Build the Project in Release Mode and generate hex file (VCOM_LPC2148.hex) 6. Download the hex file to ARM7 Board. 7. Disconnect ARM7 UART1 from the PCs COM port. 8. Connect the RF-ID module to ARM7 board using the provided male to male serial cable. 9. Attach USB A to B cable between PCs USB port and the USB connector on ARM7 Processor add-on board. 10.Slide RUN/ISP switch into Run mode and press momentarily. 11.If Computer finds a new device and asks for drivers browse and upload the drivers for this cable provided in the Documentation CD. 12.Check the virtual COM port number on device manager. 13.Open a Hyper terminal with the found COM port number and select baud rate as 115200

14.Ensure that the RFID module is powered ON and bring the RFID card near to the detector. 15.On the HyperTerminal we will be able to view the RF ID of the card. RESULT: We will now be able to detect RFID codes and can use it in various applications such as Smart Home Security Systems, Automated Attendance Systems, Automated Toll Tax Collection, and Automated Parking Ticket System. PROCEDURE FOR GPS MODULE Aim: To Interface GPS module to ARM7 TYPE OF PROTOBOARD USED: Spirit-II/Voyager-II ARM-7 Protoboard 1 No. GPS Module - 1 No. Theory of Operation: GPS technology assists us in knowing our exact location on the surface of the earth with the use of Satellites in Middle Order Orbit. These satellites relay the information and the receivers receive the data and perform triangulation to get the exact co-ordinates. Any standard GPS device spits out data in NMEA (National Marine Electronics Association) format which is a combined electrical and data specification for communication by marine electronic devices. The NMEA for GPS is NMEA-0183 which is an ASCII based data sentence. Interfacing a GPS device is the method to receive the NMEA sentence into our microcontroller so that it can be later parsed to obtain parameters such as Latitude, Longitude and Altitude etc. The GPS has a RS232 based interface through which it spits out data. So we will be interfacing the UART of the ARM7 to the GPS in this exercise. Procedure and Observation: 1. Open Triton IDE. 2. Select a workspace and create a new Project GPS_LPC2148 3. Write in the program for GPS_LPC2148 as provided in the Documentation CD and ignore step 3 or else click File menu -> Add Project ->Existing Project into Workspace and click next.

4. If importing project browse the Documentation CD and select GPS_LPC2148 and also check option Copy projects into workspace and click finish. 5. Save the file, build the Project in Release Mode and generate hex file (GPS_LPC2148.hex) 6. Download the hex file to ARM7 Board. 7. Disconnect ARM7 UART1 from the PCs COM port. 8. Connect the GPS module to ARM7 board using the provided male to male serial cable. 9. Attach USB A to B cable between PCs USB port and the USB connector on ARM7 Processor add-on board. 10.Slide RUN/ISP switch into Run mode and press momentarily. 11.If Computer finds a new device and asks for drivers browse and upload the drivers for this cable provided in the Documentation CD. 12.Check the virtual COM port number on device manager. 13.Open a Hyper terminal with the found COM port number and select baud rate as 115200 14.Ensure that the GPS module is powered ON. 15.On the HyperTerminal we will be able to view the GPS NMEA 0813 data sentences. RESULT: We Interfaced a GPS module with ARM7 board which can be used in numerous applications such as Navigation, Tectonics, Geo-fencing, Geocaching, Way-marking, Geo-tagging etc. PROCEDURE FOR WIFI NOTE: For performing this experiment the LAB has to be WiFi enabled Aim: To Interface a WiFi module connected to ARM7 with a Local Area Network and also to a Computer on the Network. TYPE OF PROTOBOARD USED: Spirit-II/Voyager-II ARM-7 Protoboard 1 No WiFi Transceiver with Wireless Router - 1 Set Theory of Operation: Based on IEEE 802.11 standard which uses both directsequence spread spectrum and multiple-carrier orthogonal frequency division multiplexing. The exercise here is to make an ARM device discoverable in network and transfer data to and fro.

Procedure and Observation: 1. Open Triton IDE. 2. Select a workspace and create a new Project WiFi_LPC2148 3. Write in the program for WiFi_LPC2148 as provided in the Documentation CD and ignore step 3 or else click File menu -> Add Project ->Existing Project into Workspace and click next. 4. If importing project browse the Documentation CD and select WiFi_LPC2148 and also check option Copy projects into workspace and click finish. 5. Save the file, build the Project in Release Mode and generate hex file (WiFi_LPC2148.hex) 6. Download the hex file to ARM7 Board. 7. Disconnect ARM7 UART1 from the PCs COM port. 8. Connect the WiFi module to ARM7 board using the provided male to male serial cable. 9. Attach USB A to B cable between PCs USB port and the USB connector on ARM7 Processor add-on board. 10.Slide RUN/ISP switch into Run mode and press momentarily. 11. Power on the WiFi addon board. 12.If Computer finds a new device and asks for drivers browse and upload the drivers for this cable provided in the Documentation CD. 13.Check the virtual COM port number on device manager. 14.Open a Hyper terminal with the found COM port number and select baud rate as 115200 and type in the following commands. [ Also documented is the expected result ] 15.$$$ to get into command mode 16.scan to scan available networks 17.join <network name> to join an available network 18.set ip gateway XXX.XXX.XXX.XXX to set the Gateway IP Address of the module 19.set ip host XXX.XXX.XXX.XXX to set the Host IP Address of the module 20.open XXX.XXX.XXX.XXX 23 to open port 23 TCP port of the module 21.On the Computer whose IP address which has been opened run Hercules Software provided on the Documentation CD. 22.Connect to the WiFi module through a TCP port and type anything which will be visible on the HyperTerminal to which the ARM board is connected. RESULT: Accelerated file transfer between a PC and ARM7 Protoboard through WiFi Interface is studied.

APPENDIX A
Sample Linux Programs for ARM-9 : /*************************************************************** Display.c ***************************************************************/ #include<stdio.h> int main() { int i = 0; for(;i<5;i++) { printf("\n%d HDL SOLUTIONS...",i); } return 0; } /***************************************************************

Mutex.c (Thread malfunctioning in File Sharing)


***************************************************************/ #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <string.h> #include <pthread.h> #include <semaphore.h> void *thread_func(void *arg); pthread_mutex_t mutex; #define WORK_SIZE 1024 char warea[WORK_SIZE]; int time_to_exit=0; int main() { int res; pthread_t thrd; void *thread_res;

res = pthread_mutex_init(&mutex,NULL); // Initialize the mutex if(res != 0){ printf("Mutex not initialised\n"); exit(EXIT_FAILURE); } res = pthread_create(&thrd,NULL,thread_func,NULL); if(res != 0){ printf("thread creation failed\n"); exit(EXIT_FAILURE); } // Start New thread pthread_mutex_lock(&mutex); printf("\nInput some text. type 'end' to finish\n"); while(!time_to_exit){ fgets(warea,WORK_SIZE,stdin); pthread_mutex_unlock(&mutex); while(1){ pthread_mutex_lock(&mutex); if(warea[0] != '\0'){ pthread_mutex_unlock(&mutex); sleep(1); } else{ break; } } } pthread_mutex_unlock(&mutex); printf("waiting for thrd to finish...\n"); res = pthread_join(thrd,&thread_res); if(res != 0){ printf("thread join failed\n"); exit(EXIT_FAILURE); } printf("Thread joined\n"); pthread_mutex_destroy(&mutex); exit(EXIT_SUCCESS); } void *thread_func(void *arg) { sleep(1); pthread_mutex_lock(&mutex); while(strncmp("end",warea,3) != 0){

printf("No. of characters = %d \n",strlen(warea) - 1); warea[0] = '\0'; pthread_mutex_unlock(&mutex); sleep(1); pthread_mutex_lock(&mutex); while(warea[0] == '\0') { pthread_mutex_unlock(&mutex); sleep(1); pthread_mutex_lock(&mutex); } } time_to_exit = 1; warea[0] = '\0'; pthread_mutex_unlock(&mutex); pthread_exit(0); } /*************************************************************** Semaphore.c ***************************************************************/ #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <string.h> #include <pthread.h> #include <semaphore.h> void *thread_func(void *arg); sem_t sem; #define WORK_SIZE 50 char warea[WORK_SIZE]; int main() { int res; pthread_t thrd; void *thread_res; res = sem_init(&sem,0,0); if(res != 0){ printf("Semaphore not initialised\n"); exit(EXIT_FAILURE); }

res = pthread_create(&thrd,NULL,thread_func,NULL); if(res != 0){ printf("thread creation failed\n"); exit(EXIT_FAILURE); } printf("\nInput text: type 'exit' to finish\n"); while(strncmp("exit",warea,3) != 0){ fgets(warea,WORK_SIZE,stdin); sem_post(&sem); } printf("waiting for thrd to finish...\n"); res = pthread_join(thrd,&thread_res); if(res != 0){ printf("thread join failed\n"); exit(EXIT_FAILURE); } printf("Thread joined\n"); sem_destroy(&sem); exit(EXIT_SUCCESS); } void *thread_func(void *arg) { sem_wait(&sem); while(strncmp("exit",warea,3) != 0){ printf("No. of characters = %d \n",strlen(warea) - 1); sem_wait(&sem); } pthread_exit(NULL); } /*************************************************************** Pipes.c ***************************************************************/ #include <unistd.h> #include <stdlib.h> #include <stdio.h> #include <string.h> int main() { FILE *read_fp; char buffer[BUFSIZ + 1]; int chars_read;

memset(buffer, '\0', sizeof(buffer)); read_fp = popen("uname -a", "r"); if (read_fp != NULL) { chars_read = fread(buffer, sizeof(char), BUFSIZ, read_fp); if (chars_read > 0) { printf("Output was:-\n%s\n", buffer); } pclose(read_fp); exit(EXIT_SUCCESS); } exit(EXIT_FAILURE); }

/*************************************************************** Fork.c ***************************************************************/ #include <stdlib.h> #include <stdio.h> #include <unistd.h> int main () { pid_t pid; pid = fork(); if(pid == 0) { /* Child process: * When fork() returns 0, we are in * the child process. * Here we count up to ten, one each second. */ int j; for(j=0; j < 10; j++) { printf("child: %d\n", j); sleep(1); } _exit(0); /* Note that we do not use exit() */ } else if(pid > 0) { /* Parent process: * Otherwise, we are in the parent process. * Again we count up to ten. */ int i; for(i=0; i < 10; i++) { printf("parent: %d\n", i); sleep(1); }

} else { /* Error handling. */ fprintf(stderr, "couldn't fork"); exit(1); } return 0; } /*************************************************************** Message_send.c ***************************************************************/ #include <stdlib.h> #include <stdio.h> #include <string.h> #include <errno.h> #include <unistd.h> #include <sys/types.h> #include <sys/ipc.h> #include <sys/msg.h> #define MAX_TEXT 512 struct my_msg_st { long int my_msg_type; char some_text[MAX_TEXT]; }; int main() { int running = 1; struct my_msg_st some_data; int msgid; char buffer[BUFSIZ]; msgid = msgget((key_t)1234, 0666 | IPC_CREAT); if (msgid == -1) { fprintf(stderr, "msgget failed with error: %d\n", errno); exit(EXIT_FAILURE); } while(running) { printf("Enter some text: "); fgets(buffer, BUFSIZ, stdin); some_data.my_msg_type = 1; strcpy(some_data.some_text, buffer);

if (msgsnd(msgid, (void *)&some_data, MAX_TEXT, 0) == -1) { fprintf(stderr, "msgsnd failed\n"); exit(EXIT_FAILURE); } if (strncmp(buffer, "end", 3) == 0) { running = 0; } } exit(EXIT_SUCCESS); } /*************************************************************** Message_receive.c ***************************************************************/ #include <stdlib.h> #include <stdio.h> #include <string.h> #include <errno.h> #include <unistd.h> #include <sys/types.h> #include <sys/ipc.h> #include <sys/msg.h> struct my_msg_st { long int my_msg_type; char some_text[BUFSIZ]; }; int main() { int running = 1; int msgid; struct my_msg_st some_data; long int msg_to_receive = 0; msgid = msgget((key_t)1234, 0666 | IPC_CREAT); if (msgid == -1) { fprintf(stderr, "msgget failed with error: %d\n", errno); exit(EXIT_FAILURE); } while(running) { if (msgrcv(msgid, (void *)&some_data, BUFSIZ, msg_to_receive, 0) == -1) { fprintf(stderr, "msgrcv failed with error: %d\n", errno); exit(EXIT_FAILURE); }

printf("You wrote: %s", some_data.some_text); if (strncmp(some_data.some_text, "end", 3) == 0) { running = 0; } } if (msgctl(msgid, IPC_RMID, 0) == -1) { fprintf(stderr, "msgctl(IPC_RMID) failed\n"); exit(EXIT_FAILURE); } exit(EXIT_SUCCESS); } *************************************************************** Socket_server.c ***************************************************************/ #include <sys/types.h> #include <sys/socket.h> #include <sys/un.h> #include <stdio.h> #include <unistd.h> #define ADDRESS "server_socket" /* addr to connect */

int main() { int server_sockfd, client_sockfd; int server_len, client_len; struct sockaddr_un server_address; struct sockaddr_un client_address; //Remove any old sockets and create an unnamed socket for the serve unlink("server_socket"); server_sockfd = socket(AF_UNIX, SOCK_STREAM, 0); //Name the socket server_address.sun_family = AF_UNIX; strcpy(server_address.sun_path, "server_socket"); server_len = sizeof(server_address); bind(server_sockfd, (struct sockaddr *)&server_address, server_len); //Create a connetion queue and wait for clients listen(server_sockfd, 5); while(1) { char ch; printf ("server waiting\n");

//Accept a connection client_len = sizeof(client_address); client_sockfd = accept(server_sockfd,(struct sockaddrr *)&client_address, &client_len); //Read and write to client on client_sockfd read(client_sockfd, &ch, 1); ch++; write(client_sockfd, &ch, 1); close(client_sockfd); } }

/*************************************************************** Socket_client.c ***************************************************************/ #include <sys/types.h> #include <sys/socket.h> #include <sys/un.h> #include <stdio.h> #include <unistd.h> #define ADDRESS "server_socket" /* addr to connect */ int main() { int sockfd; int len; struct sockaddr_un address; int result; char ch ='A'; // Create a socket for the client sockfd = socket (AF_UNIX, SOCK_STREAM, 0); // Name the socket as agreed with the server address.sun_family = AF_UNIX; strcpy(address.sun_path, "server_socket"); len = sizeof(address); //Connect our socket to server's socket result = connect(sockfd, (struct sockaddr *)&address, len); if (result == -1){ perror("oops: client1"); exit(1); } //You can now read a nd write via sockfd write(sockfd, &ch, 1); read (sockfd, &ch, 1); printf ("char from server = %c\n", ch); close(sockfd); exit(0); }

APPENDIX B
SAMPLE ARM7 PROGRAMS
LED SWITCH /***********************************************************************

DIP_SWITCH.c
************************************************************************/ #include <lpc21xx.h> int main(void) { // *IODIR0=*IODIR0 | 0X000000F7C; // *IOSET0 = 0X000000F7C; int i; while(1) { *IODIR0 =*IODIR0 | 0x007f8000; //Set Direction of LED *IOCLR0 = 0x007f8000; //Clear all LED's *IOSET0 = ((*IOPIN0 & 0X000000F7C) << 12); for(i=0;i<200000;i++); for(i=0;i<20000;i++); } *IOSET0 = 0X000000F7C; return 0;

// // }

/***********************************************************************

Buzzer.c
************************************************************************/ #include <lpc21xx.h> #include <BOARD.H> int main(void) { int i; *IODIR0=*IODIR0 | 0X00008000; while(1) { *IOSET0=0X00008000; for(i=0;i<90000;i++); *IOCLR0=0X00008000; for(i=0;i<90000;i++); } return 0; }

/**************************************************************************

Relay.c ***************************************************************/
#include <lpc21xx.h> #include <BOARD.H> int main(void) { *IODIR1=*IODIR1 |0X04000000; *IOSET1 = 0X04000000; int i ; while(1) { *IOSET1 = 0X04000000; for(i=0;i<90000;i++); for(i=0;i<90000;i++); *IOCLR1 = 0X04000000; for(i=0;i<90000;i++); for(i=0;i<90000;i++); } return 0; } /*********************************************************************** 7 Segment.c ************************************************************************/ #include <LPC21xx.H> void delay(void); int main(void) { *PINSEL2= *PINSEL2 & 0xFFFFFFF3; *IODIR1 = 0X017F0000; *IODIR0 = 0x12000800; // *IOSET0 = 0x00000800; //select Seven Segment S1 ,S3,S4 *IOSET0 = 0x12000800; //select Seven Segment S1 ,S3,S4 //*IOSET1 = 0X01000000; //Select Seven Segment S2 *IOCLR1 = 0X007F0000; while(1) { *IOCLR1 = 0Xff000; delay(); //Clear Data Bit

*IOSET1 = 0x3F0000; delay(); *IOCLR1 = 0Xff0000; *IOSET1 = 0x060000; delay(); *IOCLR1 = 0Xff0000; *IOSET1 = 0x5b0000; delay(); *IOCLR1 = 0Xff0000; *IOSET1 = 0x4f0000; delay(); *IOCLR1 = 0Xff0000; *IOSET1 = 0x660000; delay(); *IOCLR1 = 0Xff0000; *IOSET1 = 0x6d0000; delay(); *IOCLR1 = 0Xff0000; *IOSET1 = 0x7d0000; delay(); *IOCLR1 = 0Xff0000; *IOSET1 = 0x070000; delay(); *IOCLR1 = 0Xff0000; *IOSET1 = 0x7f0000; delay(); *IOCLR1 = 0Xff0000; *IOSET1 = 0x6f0000; delay(); *IOCLR1 = 0Xff0000; *IOSET1 = 0x770000; delay(); *IOCLR1 = 0xff0000; *IOSET1 = 0x7c0000; delay(); *IOCLR1 = 0xff0000; *IOSET1 = 0x390000; delay(); *IOCLR1 = 0xff0000; *IOSET1 = 0x5e0000; delay(); *IOCLR1 = 0xff0000; *IOSET1 = 0x790000; delay(); *IOCLR1 = 0xff0000; *IOSET1 = 0x710000; delay(); *IOCLR1 = 0xff0000; *IOSET1 = 0x860000; delay();

//Display 0 //Display 1 //Display 2 //Display 3 //Display 4 //Display 5 //Display 6 //Display 7 //Display 8 //Display 9 //Display A //Display B //Display C //Display D //Display E //Display F

*IOCLR1 = 0xff0000; *IOSET1 = 0x800000; delay(); *IOSET1 = 0x000000; delay(); } } void delay(void) { int j; for (j=0;j<100000;j++); for (j=0;j<100000;j++); for (j=0;j<100000;j++); for (j=0;j<100000;j++); for (j=0;j<100000;j++); } /*********************************************************************** LCD.c ************************************************************************/ #include <LPC21xx.H> #include<board.h> void lcdcmd(unsigned int); void lcddata(unsigned int); void delay_lcd(void); void DisplayLCD(char *str, int len); int main(void) { *IODIR1=0X00FF0000; *IODIR0=0x30000000; lcdcmd(0x38); lcdcmd(0x0e); lcdcmd(0x01); lcdcmd(0x06); lcdcmd(0x84); DisplayLCD("RAM", 3); while(1); } void lcdcmd(unsigned int cmddata) { *IOCLR1=0X00FF0000; *IOCLR0=0x10000000; cmddata = cmddata << 16; *IOSET1=cmddata; *IOCLR0=0x20000000; delay_lcd(); *IOSET0=0x20000000; delay_lcd();

return; } void DisplayLCD(char *str, int len) { while(len-- != 0) { lcddata(*str); str++; } } void lcddata(unsigned int outdata) { *IOCLR1=0x00FF0000; *IOSET0=0x10000000; outdata = outdata << 16; *IOSET1=outdata; *IOSET0=0x20000000; delay_lcd(); *IOCLR0=0x20000000; delay_lcd(); return; } void delay_lcd(void) { int j; for (j=0;j<500;j++); return; } /***********************************************************************

Stepper_Motor.c
************************************************************************/ #include <LPC21xx.h> int main(void) { unsigned long int i; *PINSEL0 = *PINSEL0 & (0XFFFF87FF); *IODIR0 = *IODIR0 | (0X00007800); while(1) { *IOSET0 = 0x00002800; for(i=0;i<2500;i++); *IOCLR0 = 0x00002800; for(i=0;i<2500;i++); *IOSET0= 0x00003000; //Feeding 6

//Feeding 5

for(i=0;i<2500;i++); *IOCLR0 = 0x00003000; for(i=0;i<2500;i++); *IOSET0 = 0x00005000; for(i=0;i<2500;i++); *IOCLR0 = 0x00005000; for(i=0;i<2500;i++); *IOSET0 = 0x00004800; for(i=0;i<2500;i++); *IOCLR0 = 0x00004800; for(i=0;i<2500;i++); } return 0; }

//Feeding 9

//Feeding A

/***********************************************************************

Keypad.c
************************************************************************/ #include<LPC21xx.h> #include<ucos.h> /*#include<lcd1.h>*/ #define KEYPORTDIR *IODIR0 #define KEYPORTSET *IOSET0 #define KEYPORTCLR *IOCLR0 #define rowpattern 0x04 #define colpattern 0x40 //unsigned char numarray[]={0x2d,0x3f,0x3b,0x79,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; unsigned char numarray[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; static char num[4][4]={ {1,4,7,0}, {2,5,8,0}, {3,6,9,0}, {0,0,0,0} }; void delay(long y) { long x=0; while(x!=y) x++; } // to print given number on 7-segment display void putnum_7seg(unsigned char n) { *IOSET1 = (numarray[n]<<16) ;

//*IODIR1 = 0xff0000; // segment pins as output //*IOPIN1 = (unsigned int) (numarray[n]<<16) ; } // clear 7 segment display void clear_7seg() { *IOCLR1 = 0X00FF0000; //Clear Data Bit //*IODIR1 = 0xff0000; // segment pins as output //*IOPIN1 = (unsigned int) (0x00<<16) ; } unsigned char detectkey() { int col=0,row=0,x; *IODIR0 = *IODIR0 | 0x03fc; xyz: for(col=0;col<4;col++) { *IOCLR0 = *IOCLR0 | (~(0x0200>>col)); *IOSET0 = *IOSET0 | (0x0200>>col); x= (*IOPIN0 & 0x3c)>>2; if(x == 0x01) { row = 0; q_printf("\n Key from %d th row and %d column",col+1, row+1); return num[row][col]; } if(x == 0x02) { row=1; q_printf("\n Key from %d th row and %d column",col+1,row+1); return num[row][col]; } if(x == 0x04) { row = 2; q_printf("\n Key from %d th row and %d column",col+1,row+1); return num[row][col]; } if(x == 0x08) { row = 3; q_printf("\n Key from %d th row and %d column",col+1,row+1); return num[row][col]; } } goto xyz; }

void debounce() { unsigned int i=10000; while(i<=10000) i--; } unsigned int getch_keypadto7seg() { unsigned char temp,nexttemp; temp = detectkey(); debounce(); nexttemp = detectkey(); if( nexttemp == temp) return nexttemp; else return 0; } int main() { unsigned char ch; // write your program here *PINSEL2= *PINSEL2 & 0xFFFFFFF3; *IODIR1 = 0X017F0000; *IODIR0 = 0x10000000; *IOSET0 = 0x10000000; //select Seven Segment S1 ,S3,S4 *IOSET1 = 0X01000000; //Select Seven Segment S2 *IOCLR1 = 0X00FF0000; //Clear Data Bit

while(1) { ch= getch_keypadto7seg(); clear_7seg(); putnum_7seg(ch); } return 0; }

/***********************************************************************

ADC.c
************************************************************************/ #include <LPC22xx.h> #include <board.h> int main(void) { unsigned int adcdata; *PINSEL1 = *PINSEL1 & 0XFCFFFFFF; *PINSEL1 = *PINSEL1 | 0X01000000; //*ADCR = 0X01210301; // Channel 0 , Clock 4Mhz, Burst Mode, 11 clocks per 10 bit , //AD conversion is operational, start conversion *ADCR = 0X01210302; // Channel 1 , Clock 4Mhz, Burst Mode, 11 clocks per 10 bit , //AD conversion is operational, start conversion while(1) { if(*ADDR&0X80000000) { adcdata = (*ADDR&0X0000FFC0); adcdata = adcdata >> 6; q_printf ("%x \n",adcdata); } } return 0; ************************************************************************/

You might also like