Wednesday, 8 January 2014

A MOOC and a Contest to begin the New Year on a happy note!

Grave this Opportunity with "University of Texas, Austin " 
 by taking online free course on
"UT.6.01x Embedded Systems - Shape the World "


This is a hands-on, learn-by-doing course that shows you how to build solutions to real-world problems using embedded systems. Each student will purchase a Texas Instruments TM4C123 microcontroller kit and a few electronic components. This microcontroller has a state of the art ARM Cortex M4 processor.
 "At the conclusion of this course you will be able to build your own arcade-style game on NOKIA LCD."






  • Title of the course – UT6.01x – Embedded Systems – Shape the world
  • Duration of the course – 15 weeks
  • Who is teaching the course? – Prof. Jonathan Valvano and Prof. Ramesh Yerraballi of UT, Austin
  • Who can take the course? Anyone who wishes to learn about embedded systems!
  • When is this course starting? Jan 24, 2014
  • How many hours do I need to spend in a week? – At least 10 hours a week. (Ekalavya perhaps spent more.)
  • What prerequisites are needed? You must be familiar with C programming, Digital Design, and concepts of Computer Architecture.
  • What is the nature of the course? – Apart from lectures, you will have hands-on assignments which you must complete to benefit from the course. (Imagine Ekalavya just taking a theory class on archery.)
  • What will I need to take the course? You will also need access to a good Internet connection.  If you intend to do the experiments in the convenience of your home, you will need a TM4C123 TIVA Launchpad and some parts (resistors, LED, wires, etc.) – these are explained in Swanland’s blog; you can purchase the components from the links provided therein. You will benefit from a copy of the book from Prof. Valvano – Introduction to Embedded Systems – Vol 1. While it is best to buy yourself a copy, you can also benefit from the course landing page.
  • How can I enroll? Visit this website to get started.
  • Will I get a certificate? If you enroll for the free course and audit the class, you  will not receive any certification. If you formally enrol and complete the course, you will receive a certification that can be useful when you go job hunting.
  • What is the course website? – Here it is: http://users.ece.utexas.edu/~valvano/edX/




Sunday, 8 December 2013

Linux Boot Process ; How Computer Boots Up ??

Linux Boot Process ; How Computer Boots Up ??

The PC boot process is a 3-stage boot process that begins with the BIOS executing a short program that is stored in the Master Boot Record (MBR) of the first physical drive. Since this stage 1 boot loader needs to fit in the MBR, it is limited to 512 bytes and is normally written in assembly language.
  There are a number of boot loaders that can load Linux.

     ● GRUB and LILO are the most commonly use  ones on X86 hardware.
       
     ● EFI is used on the Intel® Itanium® family.



Step by Step & Detailed Linux Boot Process

First Power On the System (PC). After this BIOS will take place.

BIOS :-

Once System start, first step BIOS (Basic Input Output System) will do POST (Power On Self Test). The POST will check all hardware connected to system working correctly or not. Once POST completes, it flushes from the memory, but the BIOS runtime services remain and it searches for devices for bootable disk, that order of preference defined in the complementary metal oxide semiconductor (CMOS) settings. A boot device can be a floppy disk, a CD-ROM, a partition on a hard disk, a device on the network, or even a USB flash memory stick.

Once BIOS detects the bootable device then it executes the MBR (Master Boot Recorder).
1st Stage of the Boot Loader.
MBR is 1st sector (512 Bytes) of the 1st bootable device. In 512 bytes, 3 parts are there :

i. 1st 446 bytes has primary boot loader information.
ii. Next 64 bytes for Partitions (16+16+16+16) for this reason only we are able to make 4 Primary Partitions.
iii. Next 2 bytes for validation check of MBR. (Magic Number)

Now the MBR Loads in to RAM.
First Stage of the boot loader loads it-self in to memory, & finds the second stage boot loader, this is done by looking through the active partition table. When it finds an active partition, it scans the remaining partitions in the table to ensure that they are all inactive. After this verification the active partition’s boot record is reads from the RAM, and it will execute it.
In simple MBR loads the GRUB (Grand Unified Boot loader) from 1st sector of the 1st bootable partition(HDD).

GRUB :-
GRUB has the knowledge of the file system, but older Linux loader LILO didn’t understand filesystem.
The stage 2 boot loader presents a boot menu to the user based on /boot/grub/grub.conf or menu.lst. This contains a boot script. GRUB displays a splash screen, waits for few seconds, if you don’t enter anything, it loads the default kernel image as specified in the grub configuration file.
Here the sample of grub.conf file.
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS Linux (2.6.32-220.2.1.el6.x86_64)
root (hd0,0)
kernel /vmlinuz-2.6.32-220.2.1.el6.x86_64 ro root=UUID=92a892bc-b9cd-45a4-be09-4c2df953b2f1 rd_NO_LUKS rd_NO_LVM rd_NO_MD rd_NO_DM LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYBOARDTYPE=pc KEYTABLE=us crashkernel=auto rhgb quiet
initrd /initramfs-2.6.32-220.2.1.el6.x86_64.img
———————————————————————————————
hd0,0 : In this hd0 means the first Hard Disk,& “,0 Means 1st partition. Your Kernel & Initrd presented in the first partition of the first HDD.
In second line will see kernel /vmlinuz.x.x.x.. Instead of /boot/vmlinuz.x.x.x because hd0,0 is boot partition, For third line is also same.

KERNEL :-
Once kernel take place to load,
Mounts the root file system as specified in the “root=” in grub.conf file as read only, to avoid the problem with fsck, compressed kernel image. Typically this is a zImage (compressed image, less than 512KB) or a bzImage (big compressed image, greater than 512KB), that has been previously compressed with zlib. At the head of this kernel image is a routine that does some minimal amount of hardware setup and then decompresses the kernel contained within the kernel image and places it into high memory.
When the kernel is loaded, it immediately initializes and configures the computer’s memory and configures the various hardware attached to the system, including all processors, I/O subsystems, and storage devices. It then looks for the compressed initrd image in a predetermined location in memory, decompresses it, mounts it, and loads all necessary drivers. Next, it initializes virtual devices related to the file system, such as LVM or software RAID before unmounting the initrd disk image and freeing up all the memory the disk image once occupied.
During the boot of the kernel, the initial-RAM disk (initrd) that was loaded into memory by the stage 2 boot loader is copied into RAM and mounted. This initrd serves as a temporary root file system in RAM and allows the kernel to fully boot without having to mount any physical disks. Since the necessary modules needed to interface with peripherals can be part of the initrd, the kernel can be very small, but still support a large number of possible hardware configurations. After the kernel is booted, the root file system is pivoted (via pivot_root) where the initrd root file system is unmounted and the real root file system is mounted.

INIT :-
After the kernel is booted and initialized, the kernel starts the first user-space application.
In a Linux system, the first application started is commonly /sbin/init. INIT is the 1st Process of the linux system, It’s PSID is 1.
First, it runs the/etc/rc.d/rc.sysinit script, which sets the environment path, starts swap, checks the file systems, and executes all other steps required for system initialization. For example, most systems use a clock, so on them rc.sysinit reads the /etc/sysconfig/clock configuration file to initialize the hardware clock.
The init command then runs the /etc/inittab script to decide which run level os has to come up.

   Most Linux distributions use the following standard run levels 0-6.
  
   0. System halt. (Do NOT set initdefault to this)
   1. Single-user mode. S and s may also be used here.
   2. Multi-user mode with no remote networking.
   3. Multi-user mode with networking. This is the standard
      operating mode of a non-GUI based system. All
      networking daemons are running.
   4. Unused.
   5. Multi-user mode with a GUI. This mode has most of the
      same daemons as run level 3 plus it is running the X
      Window System with a display and window manager.
   6. Reboot. (Do NOT set initdefault to this)

INIT identifies the default run level from /etc/inittab , After this the init command sets the source function library, /etc/rc.d/init.d/functions, for the system, which configures how to start, kill, and determine the PID of a program.
The init program starts all of the background processes by looking in the appropriate rc directory for the runlevel specified as default in /etc/inittab. The rc directories are numbered to corresponds to the runlevel they represent. For instance, /etc/rc.d/rc5.d/ is the directory for runlevel 5.
In /etc/rc.d/rc5.d/ directory what are all files starting with “K” those responsible for Kill the process when system is rebooting or shouting down. And Starting “S” those responsible for Start the process.
After the system is finished booting, it is possible to log in as root and execute these same scripts to start and stop services. For instance, the command/etc/rc.d/init.d/httpd stop stops the Apache HTTP Server.
Each of the symbolic links are numbered to dictate start order. The order in which the services are started or stopped can be altered by changing this number. The lower the number, the earlier it is started. Those symbolic links with the same number are started alphabetically.
One of the last things the init program executes is the /etc/rc.d/rc.local file. This file is useful for system customization.
After the init command has progressed through the appropriate rc directory for the runlevel, the /etc/inittab script forks an /sbin/mingetty process for each virtual console (login prompt) allocated to the runlevel. Runlevels 2 through 5 has all six virtual consoles, while runlevel 1 (single user mode) has one and runlevels 0 and 6 have none. The /sbin/mingetty process opens communication pathways to tty devices, sets their modes, prints the login prompt, accepts the user’s username and password and initiates the login process.
In runlevel 5, the /etc/inittab runs a script called /etc/X11/prefdm. The prefdm script executes the preferred X display manager — gdm, kdm, or xdm, depending on the contents of the /etc/sysconfig/desktop file.
Once finished, the system is operating on runlevel 5 and displaying a login screen.
****************** END of the Boot Process *****************

Monday, 28 October 2013

CCS_Programme 03: Implement DFT and IDFT usign Fixed Point Technique in Code Composer Studio

// fixed point implemention of dft and IDFT




#include <stdio.h>

#include <math.h>

#include "input32_DFT_IDFT_float.h"

#include "input32_DFT_IDFT_fixed.h"




#define N 32

#define PI (float)3.1416

#define Q15 (unsigned int)32768

#define Q14 (unsigned int)(Q15>>1)

#define Q8 (unsigned int)256




typedef struct {

float real[N];

float imag[N];


}complex;

complex xn,Xk,xc;



//Declare Structure for storing fixed point numbers

typedef struct {

int real[N];

int imag[N];


}complex_fix;

complex_fix xnn,Xkk,xcc;



float chk_real_fix_dft[N];

float chk_imag_fix_dft[N];

float chk_real_fix_idft[N];

float chk_imag_fix_idft[N];




//declare function prototype for DFT and IDFT Calculation
void dft_fix(complex_fix *g,complex_fix *G,int len);

void idft_fix(complex_fix *g,complex_fix *G,int len);




void main()
{
int n;

 //input values for DFT Calculation

for(n=0;n<N;n++)


{

xn.real[n] = x[n];

xn.imag[n] = 0;

}


//input values for DFT Calculation using Fixed point Technique

for(n=0;n<N;n++)


{

xnn.real[n] = x_fix[n];

xnn.imag[n] = 0;

}

 dft_fix(&xnn,&Xkk,N);

printf ("DFT Fixed Point done\n");


idft_fix(&xcc,&Xkk,N);

printf ("IDFT Fixed Point done\n");


}



void dft_fix(complex_fix *g,complex_fix *G,int len)


{

int n,k;

float alp,alpha,angle =0;

int cf,sf;

long prod1,prod2,sum1 = 0,sum2 = 0;



alp = (2*PI/N);


for (k=0;k<len;k++)


{

G->real[k] = 0;

G->imag[k] = 0;

alpha = alp*k;

angle = 0;

sum1 = 0;

sum2 = 0;

for(n=0;n<len;n++)


{

cf = cos(angle)*Q14; //SI1F14

sf = sin(angle)*Q14; //SI1F14



prod1 = ((long)cf*(long)g->real[n]); //SSI1F29

prod1 += ((long)sf*(long)g->imag[n]); //SSI1F29

prod1 = prod1<<1; //SI1F30



prod2 = ((long)cf*(long)g->imag[n]); //SSI1F29

prod2 -= ((long)sf*(long)g->real[n]); //SSI1F29

prod2 = prod2<<1; //SI1F30



sum1 = sum1+(prod1>>5); //SI6F25

sum2 = sum2+(prod2>>5); //SI6F25



angle = angle+alpha;

}


G->real[k] = (int)(sum1>>16); //SI6F9

chk_real_fix_dft[k] = (float)G->real[k]/(Q15>>6);



G->imag[k] = (int)(sum2>>16); //SI6F9

chk_imag_fix_dft[k] = (float)G->imag[k]/(Q15>>6);


}

}



void idft_fix(complex_fix *g,complex_fix *G,int len)


{

int n,k;

float alp,angle=0,alpha;

int cf,sf;

long prod1,prod2,sum1=0,sum2=0;



alp = (2*PI/N);


for(n=0;n<len;n++)


{

g->real[n] = 0;

g->imag[n] = 0;

alpha = alp*n;

angle = 0;

sum1 =0;

sum2 = 0;


for(k=0;k<len;k++)


{

cf = cos(angle)*Q14; //SI1F14

sf = sin(angle)*Q14; //SI1F14



prod1 = ((long)cf*(long)G->real[k]); //SSI7F23

prod1 -= ((long)sf*(long)G->imag[k]);

prod1 = prod1<<1; //SI7F24



prod2 = ((long)cf*(long)G->imag[k]);

prod2 += ((long)sf*(long)G->real[k]); //SSI7F23

prod2 = prod2<<1; //SI7F24



sum1 = sum1 + (prod1>>5); //SI12F19

sum2 = sum2 + (prod2>>5); //SI12F19


angle = angle +alpha;

}


g->real[n] = (int)(sum1>>16); //SI7F8

chk_real_fix_idft[n] = (float)g->real[n]/(Q15>>7); //for testing CCS calculating with MATLAB Calculation



g->imag[n] = (int)(sum2>>16);

chk_imag_fix_idft[n] = (float)g->imag[n]/(Q15>>7); //for testing CCS calculation with MATLAB Calculation


}

}

MATLAB Programme 03: Implement DFT and IDFT in MATLAB using Fixed point Technique

% Algorithm for Calculating DFT and IDFT using Fixed and Floating Point Technique
clcclear all
close all

N = 32;
M = 16;
x = 0.4 * [ones(1,M),zeros(1,(N-M))];


Q15 = 2^15;
x_fix = fix(Q15 *x); 

X = dft(x,N);
xc = idft(X,N);
stem(real(xc));


%Generate input values for fixed point

fid = fopen('input32_DFT_IDFT_fixed.h','w');
fprintf (fid,'#ifndef\t_INPUT_FIXED_H\n');
fprintf (fid,'#define\t_INPUT_FIXED_H\n');
fprintf (fid,'#define\tSIZE\t%d\n',length(x_fix));
fprintf (fid,'int\tx_fix[SIZE]\t=\t{');
fprintf (fid,'%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,\n',x_fix);
fseek (fid,-1,0);fprintf (fid,'};\n');
fprintf (fid,'#endif\n');
fclose (fid);

%it will generate input file with coefficent of input signal..
 

Thursday, 24 October 2013

CCS_Programme 02: Implement DFT and IDFT usign Floating Point Technique in Code Composer Studio

// DFT and IDFT implementation in CCS V4 using floating point technique
//file name: dft_idft.c
// in this programme input signal is sinusoidal whose coefficent are generated using MATLAB (see previous //post)

#include <stdio.h>
#include <math.h>
#include "input.h"

#define N 32                      //for 32 point DFT and IDFT
#define PI (float)3.1416

typedef struct{
float real[N];
float imag[N];
}complex;

complex xn,Xk,xc;

void dft(complex *g,complex *G,int len);
void idft(complex *g,complex *G,int len);

void main()
{
int n;
for(n=0;n<N;n++)
{
xn.real[n] = x[n];
xn.imag[n] = 0;
}
dft(&xn,&Xk,N);
        printf("DFT done\n");
idft(&xc,&Xk,N);
printf ("IDFT done\n");
}

void dft(complex *g,complex *G,int len)
{
int n,k;
float c,s,alpha,alp,angle=0;

alp = (2*PI/N);
for (k=0;k<len;k++)
{
G->real[k] = 0;
G->imag[k] = 0;
alpha = alp*k;
angle = 0;
for (n=0;n<len;n++)
{
c = cos((angle));
s = sin((angle));
G->real[k] += ((c*g->real[n])+(s*g->imag[n]));
G->imag[k] += ((c*g->imag[n])-(s*g->real[n]));
angle = angle+alpha;
}
}
}

void idft(complex *g,complex *G,int len)
{
int n,k;
float c,s,alpha,alp,angle=0;

alp = (2*PI/N);
for (n=0;n<len;n++)
{
g->real[n] = 0;
g->imag[n] = 0;
alpha = alp*n;
angle = 0;
for (k=0;k<len;k++)
{
c = cos((angle));
s = sin((angle));
g->real[n] += ((c*G->real[k])-(s*G->imag[k]));
g->imag[n] += ((c*G->imag[k])+(s*G->real[k]));
angle = angle+alpha;
}
g->real[n]=g->real[n]/N;
g->imag[n]=g->imag[n]/N;
}
}


// check result of CCS (from watch window) with MATLAB computation result ... you will find that both result are same...

Thursday, 17 October 2013

MATLAB Programme 02: Implement DFT and IDFT in MATLAB using floating point Technique



% MATLAB Programme for implemention of DFT and IDFT using floating point technique

% in this programme input signal is sinusoidal signal whose 
amplitude is 0.9.
% this programme generate another coefficient file input.h which is input signal coefficient
% in matlab if we declare function definition then we give definition of function in another file and name of this file is  same as function calling name. in this programme we use two function "dft" and " idft " . whose definition give in another two file dft.m and idft.m

%****************************************************************
%file name :    spectrum.m 

clc; % for clearing window
close all; % for closing previous graphical window
clear all; % for clearing previously values


fs = 8000;
f0 = 1000;
cycles = 4;
N = fix(cycles*fs/f0);
n = 0:1:N-1;
amp = 0.9;
ts = 1/fs;
x = amp*sin(2*pi*f0*n*ts);

X = dft(x,N);

fid = fopen('input.h','w');
fprintf (fid,'#ifndef\t_INPUT_H_\n');
fprintf (fid,'#define\t_INPUT_H_\n\n');
fprintf (fid,'#define\tSIZE\t%d\n\n',length(x));
fprintf (fid,'float\tx[SIZE]\t=\t{');
fprintf (fid,'%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,\n',x);
fprintf (fid,'};\n\n');
fprintf (fid,'#endif\n');
fclose(fid);

xc = idft(X,N);


stem(real(xc));




%*********************************************************

%function defination
%file name :   dft.m

function X= dft(x,N)

for k=0:1:N-1
    X(k+1) = 0;
    for n=0:1:N-1
        X(k+1) = X(k+1) + (x(n+1)*exp(-j*2*pi*n*k/N));
    end

end



%********************************************************

%function defination
%file name :   idft.m


function x= idft(X,N)

for n=0:1:N-1
    x(n+1) = 0;
    for k=0:1:N-1
        x(n+1) = x(n+1) + (X(k+1)*exp(j*2*pi*n*k/N));
    end
end


x=x/N;

%*********************************************************


for implementing DFT and IDFT in Code Composer Studio V4 visit to another post CCS_Programme 02: Implement DFT and IDFT usign Floating Point Technique in Code Composer Studio....

MATLAB Programme 01: Implement DFT Without using inbuilt function

DFT Implementation


DFT is used to convert a signal sample array x(n) of size 1 x N to signal spectral component array X(k) of size 1 x N.
 
 
 
%programme
 
clc;close all;

clear all;

xn = input('Enter the sequence');
 
 
ln = length(xn);
xk = zeros(1,ln);
ixk = zeros(1,ln);
 
%Calculating DFT
for k=0:ln-1
   for n=0:ln-1
xk(k+1) = xk(k+1)+(xn(n+1)*exp((-i)*2*pi*k*n/ln));
 
   end
end
%hear xk(k+1); because of in matlab array index start form 1

 
t = 0:ln-1;
subplot(3,2,1);
stem(t,xn);
title ('Input Sequence x(n)');
xlabel('Time Index');
ylabel('Amplitude');
 
t = 0:ln-1;
subplot(3,2,2);
stem(t,xk);
ylabel ('Amplitude');
title ('X(K)');
xlabel ('K');

 

 
t = 0:ln-1;
subplot(3,2,3);
stem(t,abs(xk));
 
 
ylabel ('Amplitude');
xlabel ('K');
title ('Magnitude Response');
 
 
t = 0:ln-1;
subplot(3,2,4);
stem(t,angle(xk));
 
ylabel('Phase');
xlabel('K');
title ('Phase Response');


%-------------------------------------------------------------------%

%Output
%Enter the sequence[ 1 2 3 3 2 1]