EmbLogic's Blog

work on character driver : operations on open & release.

CHARACTER DEVICE DEVELOPMENT:

OPEN: CLOSE:

—————————-
revision 1.6
date: 2014/02/15 09:26:13; author: root; state: Exp; lines: +3 -0
*** empty log message ***
—————————-
revision 1.5
date: 2014/02/15 09:19:22; author: root; state: Exp; lines: +3 -1
release prototype use
and release: name used
—————————-
revision 1.4
date: 2014/02/15 06:19:27; author: root; state: Exp; lines: +6 -7
sync
—————————-
revision 1.3
date: 2014/02/14 11:05:24; author: root; state: Exp; lines: +1 -1
sync
—————————-
revision 1.2
date: 2014/02/14 10:48:51; author: root; state: Exp; lines: +2 -0
extern struct Scull_dev *scull_dev ,*lscull_dev;
—————————-
revision 1.1
date: 2014/02/14 10:13:55; author: root; state: Exp;

RCS file: ./init.c,v
Working file: init.c

Posted in Uncategorized | Leave a comment

Unregistering a character device driver from device table

There are some points which we have to note down while working in character device driver:
1. The second argument of unregister_chrdev_region function means the number of devices to unregister from the device table ….  should be matched with the third argument of alloc_chrdev_region function. Else the driver entry will not remove from the device table.

RCS file: clean.c,v
Working file: clean.c
head: 1.5
branch:
locks: strict
raghav: 1.5
access list:
symbolic names:
keyword substitution: kv
total revisions: 5;    selected revisions: 5
description:
included the unregister_chrdev_region to unregister the device
to do so we need the major minor number.
which we’ll get from the first argv of alloc_chrdev_region
as i am using seperate files so , i have to use this dev_t dev as a extern in exit function
—————————-
revision 1.5    locked by: raghav;
date: 2014/02/13 11:20:48;  author: raghav;  state: Exp;  lines: +2 -0
adding kfree function to free the allocated memory of struct sculldev after removing and un registering the device
—————————-
revision 1.4
date: 2014/02/13 10:19:28;  author: raghav;  state: Exp;  lines: +1 -1
Error detected: In the second argument of unregister_chrdev_region func() we have to input only that number of drivers which we have registered.
suppose if we have register our driver for 10 devices then in the unregister fun() we have to unregister 10 devices i.e give 10 in the second argument of unregister function.
—————————-
revision 1.3
date: 2014/02/13 10:18:05;  author: raghav;  state: Exp;  lines: +6 -5
Error in un registering the driver from the driver table
—————————-
revision 1.2
date: 2014/02/13 06:09:06;  author: raghav;  state: Exp;  lines: +3 -5
included the unregister_chrdev_region to unregister the driver, but here its return type is void
—————————-
revision 1.1
date: 2014/02/13 05:58:43;  author: raghav;  state: Exp;
Initial revision
=============================================================================

Posted in Uncategorized | Leave a comment

Code to demonstrate how to create a copy of a single linked list in C.

RCS file: copy_linked_list.c,v
Working file: copy_linked_list.c
head: 1.14
branch:
locks: strict
access list:
symbolic names:
keyword substitution: kv
total revisions: 14;    selected revisions: 14
description:
Code to demonstrate how to copy an already existing linked list.
—————————-
revision 1.14
date: 2014/02/15 01:32:47;  author: root;  state: Exp;  lines: +15 -2
Status:Copy of a linked list is created successfully.
Previously there was a small bug which was discovered and fixed by including several checks.
—————————-
revision 1.13
date: 2014/02/15 01:23:04;  author: root;  state: Exp;  lines: +7 -2
Logical error fixed.
—————————-
revision 1.12
date: 2014/02/15 01:17:35;  author: root;  state: Exp;  lines: +5 -4
Prototype of the copy_linked_list() function is changed to return the starting address of the new copy of the linked list.
Creating a new function to display the neewly created linked list.
—————————-
revision 1.11
date: 2014/02/15 01:15:00;  author: root;  state: Exp;  lines: +37 -1
copy_linked_list() function is implemented.
Checking…….
—————————-
revision 1.10
date: 2014/02/14 17:49:17;  author: root;  state: Exp;  lines: +1 -0
Logical error fixed.
Issue:The value of temp was not updated.
—————————-
revision 1.9
date: 2014/02/14 17:47:07;  author: root;  state: Exp;  lines: +11 -2
display_list() function is implemented inside the program.
An extra value is getting displayed.
Checking…..
—————————-
revision 1.8
date: 2014/02/14 17:38:08;  author: root;  state: Exp;  lines: +1 -0
Segmentation fault ocurred while running the program because after allocating a node the starting address of it is not returned to the main function.
Logical error fixed.
—————————-
revision 1.7
date: 2014/02/14 17:26:50;  author: root;  state: Exp;  lines: +37 -1
create_node function is implemented inside main() to insert the nodes in the linked list.
Checking….
—————————-
revision 1.6
date: 2014/02/14 17:05:57;  author: root;  state: Exp;  lines: +17 -1
create_list() function is called that will create the start node in the linked list inside which no value is stored.
Prototype of the create_list() function is declared.
Checking….
—————————-
revision 1.5
date: 2014/02/14 16:57:46;  author: root;  state: Exp;  lines: +1 -0
Header file:<stdlib.h> is included to support exit() function.
—————————-
revision 1.4
date: 2014/02/14 16:55:28;  author: root;  state: Exp;  lines: +20 -0
exit() function is included in the main program in case the user wants to end the program.
—————————-
revision 1.3
date: 2014/02/14 16:46:37;  author: root;  state: Exp;  lines: +12 -0
A Main menu is prepared to provide the user with the available options.
Checking…
—————————-
revision 1.2
date: 2014/02/14 16:40:16;  author: root;  state: Exp;  lines: +6 -0
A structure is defined of type node.Two pointers of type struct node are declared inside main().
—————————-
revision 1.1
date: 2014/02/14 16:38:17;  author: root;  state: Exp;
Initial revision
=============================================================================

Posted in Data Structures with C | Leave a comment

Adding a character device driver to the system using cdev_add

Implementing cdev_add and cdev_init
RCS file: header.h,v
Working file: header.h
head: 1.4
branch:
locks: strict
raghav: 1.4
access list:
symbolic names:
keyword substitution: kv
total revisions: 4;    selected revisions: 4
description:
This is a seperate header file where i have included all the necessary header file required for writing character
including linux/init.h and linux/module.h
—————————-
revision 1.4    locked by: raghav;
date: 2014/02/13 11:01:53;  author: raghav;  state: Exp;  lines: +33 -1
<included <linux/slab> for kalloc function to allocate memory to struct scull_dev
—————————-
revision 1.3
date: 2014/02/13 05:47:34;  author: raghav;  state: Exp;  lines: +0 -1
header file <init.h> is included to support module_init and module_exit
—————————-
revision 1.2
date: 2014/02/13 05:24:24;  author: raghav;  state: Exp;  lines: +0 -1
Included the module licence GPL to make it authorized
—————————-
revision 1.1
date: 2014/02/13 05:23:05;  author: raghav;  state: Exp;
Initial revision
=============================================================================
RCS file: entry.c,v
Working file: entry.c
head: 1.9
branch:
locks:
raghav: 1.9
access list:
symbolic names:
keyword substitution: kv
total revisions: 9;    selected revisions: 9
description:
program to insert a driver file inside our kernel
—————————-
revision 1.9    locked by: raghav;
date: 2014/02/13 11:12:56;  author: raghav;  state: Exp;  lines: +24 -14
cdev_add function is added the character device to the system
—————————-
revision 1.8
date: 2014/02/13 06:55:08;  author: raghav;  state: Exp;  lines: +8 -3
*** empty log message ***
—————————-
revision 1.7
date: 2014/02/13 05:43:43;  author: raghav;  state: Exp;  lines: +10 -15
included the alloc_chrdev_region to register the driver number and get the major and minor number using its first argument dev
Major no is allocated by kernel and minor no is allocated by driver to devices
—————————-
revision 1.6
date: 2014/02/11 12:33:38;  author: raghav;  state: Exp;  lines: +2 -2
ERROR: i was using name function name “out” for exit function
Now i changed it to outo , and now it works without showing any bug
—————————-
revision 1.5
date: 2014/02/11 12:31:14;  author: raghav;  state: Exp;  lines: +2 -1
ERROR: forget to write retern 0 in init function
—————————-
revision 1.4
date: 2014/02/11 12:27:34;  author: raghav;  state: Exp;  lines: +5 -5
creating  a seperate Makefile to execute both files init.o and exit.o
This make file is important as we can’t compile out init func seperately
—————————-
revision 1.3
date: 2014/02/11 12:17:12;  author: raghav;  state: Exp;  lines: +14 -0
using module init function to insert the file inside the kernel and exit function is used to remove the file from kernel
Make sure dont use the same function name as init and exit are built in name and already defined inside kernels else it will create a problem
—————————-
revision 1.2
date: 2014/02/11 12:12:17;  author: raghav;  state: Exp;  lines: +2 -1
Inclluding linux/module.h and linux/init.h
and including MODULE_LICENCE
—————————-
revision 1.1
date: 2014/02/11 12:10:44;  author: raghav;  state: Exp;
Initial revision
=============================================================================
RCS file: clean.c,v
Working file: clean.c
head: 1.5
branch:
locks: strict
raghav: 1.5
access list:
symbolic names:
keyword substitution: kv
total revisions: 5;    selected revisions: 5
description:
included the unregister_chrdev_region to unregister the device
to do so we need the major minor number.
which we’ll get from the first argv of alloc_chrdev_region
as i am using seperate files so , i have to use this dev_t dev as a extern in exit function
—————————-
revision 1.5    locked by: raghav;
date: 2014/02/13 11:20:48;  author: raghav;  state: Exp;  lines: +2 -0
adding kfree function to free the allocated memory of struct sculldev after removing and un registering the device
—————————-
revision 1.4
date: 2014/02/13 10:19:28;  author: raghav;  state: Exp;  lines: +1 -1
Error detected: In the second argument of unregister_chrdev_region func() we have to input only that number of drivers which we have registered.
suppose if we have register our driver for 10 devices then in the unregister fun() we have to unregister 10 devices i.e give 10 in the second argument of unregister function.
—————————-
revision 1.3
date: 2014/02/13 10:18:05;  author: raghav;  state: Exp;  lines: +6 -5
Error in un registering the driver from the driver table
—————————-
revision 1.2
date: 2014/02/13 06:09:06;  author: raghav;  state: Exp;  lines: +3 -5
included the unregister_chrdev_region to unregister the driver, but here its return type is void
—————————-
revision 1.1
date: 2014/02/13 05:58:43;  author: raghav;  state: Exp;
Initial revision
=============================================================================

Posted in Uncategorized | Leave a comment

Problem in registering and unregistering driver in kernel

There are some problems which we faced in un- registering the driver

1. there is no return type of unregister_chrdev_region , so you can check the result only by using vim /proc/devices after rmmod command

2. suppose if you are registering 10 devices using  alloc_chrdev_region then you have to give 10 on the second argument of unregister_chrdev_region function, else it will not remove the driver entry from the driver table.

RCS file: clean.c,v
Working file: clean.c
head: 1.4
branch:
locks: strict
access list:
symbolic names:
keyword substitution: kv
total revisions: 4;    selected revisions: 4
description:
included the unregister_chrdev_region to unregister the device
to do so we need the major minor number.
which we’ll get from the first argv of alloc_chrdev_region
as i am using seperate files so , i have to use this dev_t dev as a extern in exit function
—————————-
revision 1.4
date: 2014/02/13 10:19:28;  author: raghav;  state: Exp;  lines: +1 -1
Error detected: In the second argument of unregister_chrdev_region func() we have to input only that number of drivers which we have registered.
suppose if we have register our driver for 10 devices then in the unregister fun() we have to unregister 10 devices i.e give 10 in the second argument of unregister function.
—————————-
revision 1.3
date: 2014/02/13 10:18:05;  author: raghav;  state: Exp;  lines: +6 -5
Error in un registering the driver from the driver table
—————————-
revision 1.2
date: 2014/02/13 06:09:06;  author: raghav;  state: Exp;  lines: +3 -5
included the unregister_chrdev_region to unregister the driver, but here its return type is void
—————————-
revision 1.1
date: 2014/02/13 05:58:43;  author: raghav;  state: Exp;
Initial revision
=============================================================================

Posted in Uncategorized | Leave a comment

Registering a character device driver with Major and Minor number in kernel

RCS file: header.h,v
Working file: header.h
head: 1.3
branch:
locks: strict
raghav: 1.3
access list:
symbolic names:
keyword substitution: kv
total revisions: 3;    selected revisions: 3
description:
This is a seperate header file where i have included all the necessary header file required for writing character
including linux/init.h and linux/module.h
—————————-
revision 1.3    locked by: raghav;
date: 2014/02/13 05:47:34;  author: raghav;  state: Exp;  lines: +0 -1
header file <init.h> is included to support module_init and module_exit
—————————-
revision 1.2
date: 2014/02/13 05:24:24;  author: raghav;  state: Exp;  lines: +0 -1
Included the module licence GPL to make it authorized
—————————-
revision 1.1
date: 2014/02/13 05:23:05;  author: raghav;  state: Exp;
Initial revision
=============================================================================
RCS file: entry.c,v
Working file: entry.c
head: 1.7
branch:
locks: strict
raghav: 1.7
access list:
symbolic names:
keyword substitution: kv
total revisions: 7;    selected revisions: 7
description:
program to insert a driver file inside our kernel
—————————-
revision 1.7    locked by: raghav;
date: 2014/02/13 05:43:43;  author: raghav;  state: Exp;  lines: +10 -15
included the alloc_chrdev_region to register the driver number and get the major and minor number using its first argument dev
Major no is allocated by kernel and minor no is allocated by driver to devices
—————————-
revision 1.6
date: 2014/02/11 12:33:38;  author: raghav;  state: Exp;  lines: +2 -2
ERROR: i was using name function name “out” for exit function
Now i changed it to outo , and now it works without showing any bug
—————————-
revision 1.5
date: 2014/02/11 12:31:14;  author: raghav;  state: Exp;  lines: +2 -1
ERROR: forget to write retern 0 in init function
—————————-
revision 1.4
date: 2014/02/11 12:27:34;  author: raghav;  state: Exp;  lines: +5 -5
creating  a seperate Makefile to execute both files init.o and exit.o
This make file is important as we can’t compile out init func seperately
—————————-
revision 1.3
date: 2014/02/11 12:17:12;  author: raghav;  state: Exp;  lines: +14 -0
using module init function to insert the file inside the kernel and exit function is used to remove the file from kernel
Make sure dont use the same function name as init and exit are built in name and already defined inside kernels else it will create a problem
—————————-
revision 1.2
date: 2014/02/11 12:12:17;  author: raghav;  state: Exp;  lines: +2 -1
Inclluding linux/module.h and linux/init.h
and including MODULE_LICENCE
—————————-
revision 1.1
date: 2014/02/11 12:10:44;  author: raghav;  state: Exp;
Initial revision
=============================================================================
RCS file: clean.c,v
Working file: clean.c
head: 1.2
branch:
locks: strict
raghav: 1.2
access list:
symbolic names:
keyword substitution: kv
total revisions: 2;    selected revisions: 2
description:
included the unregister_chrdev_region to unregister the device
to do so we need the major minor number.
which we’ll get from the first argv of alloc_chrdev_region
as i am using seperate files so , i have to use this dev_t dev as a extern in exit function
—————————-
revision 1.2    locked by: raghav;
date: 2014/02/13 06:09:06;  author: raghav;  state: Exp;  lines: +3 -5
included the unregister_chrdev_region to unregister the driver, but here its return type is void
—————————-
revision 1.1
date: 2014/02/13 05:58:43;  author: raghav;  state: Exp;
Initial revision
=============================================================================

Posted in Uncategorized | Leave a comment

GDB

What is gdb?
“GNU Debugger”
A debugger for several languages, including C and C++
It allows you to inspect what the program is doing at a certain
point during execution.
Errors like segmentation faults may be easier to find with the
help of gdb.
http://sourceware.org/gdb/current/onlinedocs/gdb toc.html
online manual
GDB Tutorial
-
Additional step when compiling program
Normally, you would compile a program like:
gcc [flags] -o
For example:
gcc -Wall -Werror -ansi -pedantic-errors prog1.c -o prog1.x
Now you add a -g option to enable built-in debugging support
(which gdb needs):
gcc [other flags] -g -o
For example:
gcc -Wall -Werror -ansi -pedantic-errors -g prog1.c -o prog1.x
GDB Tutorial
Starting up gdb
Just try “gdb” or “gdb prog1.x.” You’ll get a prompt that looks
like this:
(gdb)
If you didn’t specify a program to debug, you’ll have to load it in
now:
(gdb) file prog1.x
Here, prog1.x is the program you want to load, and “file” is the
command to load it.
GDB Tutorial
Before we go any further
gdb has an interactive shell, much like the one you use as soon as
you log into the linux grace machines. It can recall history with the
arrow keys, auto-complete words (most of the time) with the TAB
key, and has other nice features.
Tip
If you’re ever confused about a command or just want more
information, use the “help” command, with or without an
argument:
(gdb) help [command]
You should get a nice description and maybe some more useful
tidbits. . .
GDB Tutorial
Running the program
To run the program, just use:
(gdb) run
This runs the program.
If it has no serious problems (i.e. the normal program didn’t
get a segmentation fault, etc.), the program should run fine
here too.
If the program did have issues, then you (should) get some
useful information like the line number where it crashed, and
parameters to the function that caused the error:
Program received signal SIGSEGV, Segmentation fault.
0×0000000000400524 in sum array region (arr=0x7fffc902a270, r1=2, c1=5,
r2=4, c2=6) at sum-array-region2.c:12
GDB Tutorial
So what if I have bugs?
Okay, so you’ve run it successfully. But you don’t need gdb for
that. What if the program isn’t working?
Basic idea
Chances are if this is the case, you don’t want to run the program
without any stopping, breaking, etc. Otherwise, you’ll just rush past the
error and never find the root of the issue. So, you’ll want to step through
your code a bit at a time, until you arrive upon the error.
This brings us to the next set of commands. . .
GDB Tutorial
Setting breakpoints
Breakpoints can be used to stop the program run in the middle, at
a designated point. The simplest way is the command “break.”
This sets a breakpoint at a specified file-line pair:
(gdb) break file1.c:6
This sets a breakpoint at line 6, of file1.c. Now, if the program
ever reaches that location when running, the program will pause
and prompt you for another command.
Tip
You can set as many breakpoints as you want, and the program
should stop execution if it reaches any of them.
GDB Tutorial
More fun with breakpoints
You can also tell gdb to break at a particular function. Suppose
you have a function my func:
int my func(int a, char *b);
You can break anytime this function is called:
(gdb) break my func
GDB Tutorial
Now what?
Once you’ve set a breakpoint, you can try using the run
command again. This time, it should stop where you tell it to
(unless a fatal error occurs before reaching that point).
You can proceed onto the next breakpoint by typing
“continue” (Typing run again would restart the program
from the beginning, which isn’t very useful.)
(gdb) continue
You can single-step (execute just the next line of code) by
typing “step.” This gives you really fine-grained control over
how the program proceeds. You can do this a lot…
(gdb) step
GDB Tutorial
Now what? (even more!)
Similar to “step,” the “next” command single-steps as well,
except this one doesn’t execute each line of a sub-routine, it
just treats it as one instruction.
(gdb) next
Tip
Typing “step” or “next” a lot of times can be tedious. If you just
press ENTER, gdb will repeat the same command you just gave it.
You can do this a bunch of times.
GDB Tutorial
Querying other aspects of the program
So far you’ve learned how to interrupt program flow at fixed,
specified points, and how to continue stepping line-by-line.
However, sooner or later you’re going to want to see things
like the values of variables, etc. This might be useful in
debugging. :)
The print command prints the value of the variable
specified, and print/x prints the value in hexadecimal:
(gdb) print my var
(gdb) print/x my var
GDB Tutorial
Setting watchpoints
Whereas breakpoints interrupt the program at a particular line or
function, watchpoints act on variables. They pause the program
whenever a watched variable’s value is modified. For example, the
following watch command:
(gdb) watch my var
Now, whenever my var’s value is modified, the program will
interrupt and print out the old and new values.
Tip
You may wonder how gdb determines which variable named my var to watch if there
is more than one declared in your program. The answer (perhaps unfortunately) is
that it relies upon the variable’s scope, relative to where you are in the program at the
time of the watch. This just means that you have to remember the tricky nuances of
scope and extent :(.
GDB Tutorial
Example programs
Some example files are found in
~/212public/gdb-examples/broken.c on the linux grace
machines.
Contains several functions that each should cause a
segmentation fault. (Try commenting out calls to all but one
in main())
The errors may be easy, but try using gdb to inspect the code.
GDB Tutorial
Other useful commands
backtrace – produces a stack trace of the function calls that
lead to a seg fault (should remind you of Java exceptions)
where – same as backtrace; you can think of this version as
working even when you’re still in the middle of the program
finish – runs until the current function is finished
delete – deletes a specified breakpoint
info breakpoints – shows information about all declared
breakpoints
Look at sections 5 and 9 of the manual mentioned at the beginning
of this tutorial to find other useful commands, or just try help.
GDB Tutorial
gdb with Emacs
Emacs also has built-in support for gdb. To learn about it, go here:

http://tedlab.mit.edu/~dr/gdbintro.html

GDB Tutorial
More about breakpoints
Breakpoints by themselves may seem too tedious. You have to
keep stepping, and stepping, and stepping. . .
Basic idea
Once we develop an idea for what the error could be (like dereferencing a
NULL pointer, or going past the bounds of an array), we probably only
care if such an event happens; we don’t want to break at each iteration
regardless.
So ideally, we’d like to condition on a particular requirement (or set
of requirements). Using conditional breakpoints allow us to
accomplish this goal. . .
GDB Tutorial
Conditional breakpoints
Just like regular breakpoints, except that you get to specify some
criterion that must be met for the breakpoint to trigger. We use
the same break command as before:
(gdb) break file1.c:6 if i >= ARRAYSIZE
This command sets a breakpoint at line 6 of file file1.c, which
triggers only if the variable i is greater than or equal to the size of
the array (which probably is bad if line 6 does something like
arr[i]). Conditional breakpoints can most likely avoid all the
unnecessary stepping, etc.
GDB

Posted in Uncategorized | Leave a comment

SPI Protocol

SPI(Serial Peripheral Interface):-

SPI (Serial Peripheral Interface) bus, which is commonly used for communication between integrated circuits or sensors .It is a serial master-slave Synchronous Protocol . It comes built in on many microcontrollers and SOC. The SPI serial bus was originally established by Motorola. Today, it is one of the most common communication buses used by integrated circuit manufactures for device to processor or FPGA control. Examples include ADCs, DACs, sensors, and board-only products. I
Although it is not regulated as a standard by IEEE or another organization, most devices adhere to common set of rules described .

SPI is a synchronous serial data link that operates in full duplex. That is, signals carrying data go in both directions simultaneously. Devices communicate using a master/slave protocol, in which the
master starts the data frame. When the master generates a clock then selects a slave device, data may be transferred in either or both directions simultaneously. It is up to the master and slave devices to know whether a received byte is meaningful. This may require a device to discard the received byte in a transmit only” frame or generate a dummy byte for a “receive only” frame.

It uses four wires Serial ClocK (SCLK), Chip Select (CS), Master Out Slave In (MOSI), Master In Slave Out (MISO).

Basic Connections :-
The four typical SPI signals include:
clock (SCLK) – This signal is generated by the Master. Other signals in the transmission change based on the timing of edges from this clock.
master data output, slave data input (MOSI) – This line is the output from the Master to the slave. Transmits bit-by-bit synchronized with Master clock edges.
master data input, slave data output (MISO) – This line is the output from all the slaves connected. Transmits bit-by-bit from the slave synchronized with Master clock edges.
chip select (CS) or slave select (SS) – This is a bank of signals where each line goes to individual slaves in the system. One line is asserted at a time to enable communicate with the corresponding slave.

MOSI is used for shifting data into the slave device, and MISO is used for shifting data out of the slave device. Because the SPI bus has dedicated wires for transmitting and receiving data, it can operate in full-duplex mode, unlike the I 2C bus. The typical speed of
operation of SPI is in the low-megahertz range, unlike the mid-kilohertz range on I2C, so the former yields higher throughput.
SPI peripherals available in the market today include Radio Frequency (RF) chips, smart card interfaces, EEPROMs, RTCs, touch sensors, and ADC

Basic Transmission Step-by-Step
1. The Master drives a particular SS line low to initiate communication with the corresponding slave.
2. Once the selected SS is low, one edge (rising or falling) of the SCLK signals the devices (Master and Slave) to toggle the MOSI and MISO to the correct bit of data being transmitted.
3. The other edge of the SCLK line (rising or falling) signals the devices to register the bits on the MOSI and MISO, effectively reading the bit into the device.
4. The transmission continues in this fashion until the devices have exchanged the specified number of bits (usually 8,16, or 32)
5. After the transmission is complete the Master pulls the SS line for the slave back high and either goes to another slave on the network or reinitiates the transmission with the same slave by
pulling the corresponding1 SS line back to low.

Posted in Uncategorized | Leave a comment

Project 01-Multiple Data Compression & encryption using iterative technique.

RCS file: ./header.h,v
Working file: ./header.h
head: 1.4
branch:
locks: strict
root: 1.4
access list:
symbolic names:
keyword substitution: kv
total revisions: 4;    selected revisions: 4
description:
give prototyp for open_file().
give prototyp for read_file().
—————————-
revision 1.4    locked by: root;
date: 2014/03/01 11:48:44;  author: root;  state: Exp;  lines: +2 -0
give prototyp for compression().
give prototyp for compress4().
give prototyp for code_length().
—————————-
revision 1.3
date: 2014/03/01 11:13:06;  author: root;  state: Exp;  lines: +1 -0
give prototyp for code_length().
—————————-
revision 1.2
date: 2014/03/01 11:06:41;  author: root;  state: Exp;  lines: +1 -0
give prototyp for create_marray().
—————————-
revision 1.1
date: 2014/03/01 10:52:47;  author: root;  state: Exp;
Initial revision

RCS file: ./mdc.c,v
Working file: ./mdc.c
head: 1.4
branch:
locks: strict
root: 1.4
access list:
symbolic names:
keyword substitution: kv
total revisions: 4;    selected revisions: 4
description:
call open_file() from main().
call read_file() from main().
—————————-
revision 1.4    locked by: root;
date: 2014/03/01 11:47:18;  author: root;  state: Exp;  lines: +74 -0
call compression() from main().
inside compression() call compress4() for code_length=4.
—————————-
revision 1.3
date: 2014/03/01 11:12:35;  author: root;  state: Exp;  lines: +25 -4
call code_length() from main().
—————————-
revision 1.2
date: 2014/03/01 11:03:53;  author: root;  state: Exp;  lines: +34 -1
call create_marray() from main().
—————————-
revision 1.1
date: 2014/03/01 10:52:43;  author: root;  state: Exp;
Initial revision

 

 

Posted in Project 2: Multiple Data Compression and Encryption | Leave a comment

/dev directory

The /dev directory contains the special device files for all the devices. The device files are created during installation, and later with the /dev/MAKEDEV script. The /dev/MAKEDEV.local is a script written by the system administrator that creates local-only device files or links (i.e. those that are not part of the standard MAKEDEV, such as device files for some non-standard device driver).All hardware files are present in /dev(Device ) folder. If we observe the /dev folder you can find files/folders related to different hardware’s present in the machine.Below are some hardware files and their uses and explanation.

1. /dev/alarm

This is a hardware file used to keep track of time when system goes hibernation or suspended when it is idle. When your system goes hibernation most of your hardware will be shutdown, HDD rotation is reduced to as low as possible in order to save power. This file is very much useful to keep track of system time, to do calender updates to user etc. You can say in other words that /dev/alarm will have current time status. This file is used in portable devices such as laptops and mobiles mostly.

2. /dev/autofs

This file is used to mount remote directories locally. This is done automatically when user tries to login by mounting remote directory. The mounting is done by using this hardware file. With out this hardware file we can not do automount in a Linux box.

3. /dev/block folder

This folder is legacy location for your block devices. This is still existing to support legacy applications.

4. /dev/cdrom, /dev/dvd, /dev/cdrw, /dev/dvd-rw etc

These files corresponds to Compact-Disk(/dev/cdrom or /dev/cdrw) hardware or to Digital Versatile Disk(/dev/dvd or /dev/dvd-rw) hardware. These files are required to mount your local CDrom and DVD’s so that you can access the content of the file.

5. /dev/char

This is the folder where char files are located in legacy machines. This is still kept to support legacy applications.

6. /dev/console, /dev/tty, /dev/tty1 to /dev/tty63, /dev/ttyS, /dev/ttyS0 to /dev/ttyS31 files and /dev/pts folder

These device files are called as terminals or consoles which are char files used for communication between user and system. /dev/console file is used in Runlevel1 1 and none of these terminals are available for access on runlevel 1. tty(Teletype) is a device file to do remote connection so that we can work remotely The name is derived from typewriters which are default communicating devices in early stages of Computers. The terminals range from tty0 to tty63 and serial port terminals(ttys or ttyS) are from 0 to 31.

7. /dev/loop(/dev/loop0 to /dev/loop7)

A loop device is a Pseudo device useful for mounting Virtual CD(ISO files), HDD etc. The loop devices are useful for mounting already formatted drive and access the data in a folder mounted on different filesystem. Virtual devices are nothing but a hardware file created by kernel/OS so that we can use them as a physical drives. These loop devices are also used by virtual softwares such as KVM, VMWARE to mount CD-ROM’s, HDD(.img files for example) as physical devices in your Virtual machine.

8. /dev/sda, /dev/hda etc

These files corresponding to hard disks and storage devices such as USB hard disks, SATA disks and External HDD’s. For Intel machines you may find /dev/hda, /dev/hdb, /dev/hdc, /dev/hdd corresponds to Primary master, Primary slave, Secondary master and Secondary Slave devices. Partitions with in disks are created as /dev/sda1, sda2 etc and so on.

9. /dev/random and /dev/urandom

Used for generating random chars for Kernel purpose.

10. /dev/null and /dev/zero

Used for generating empty files, observing unwanted outputs etc.

11. /dev/ppp

This file is used to connect your mobile or GPRS/3G enabled devices to connect and communicate. This is pseudo file which communicates with GPRS enabled hardware file to send data.

Posted in Uncategorized | Leave a comment

Write a Program to calculate hcf and lcm of three numbers and also input number from user.

#include<stdio.h>
int main()
{

int i,l,a,b,c;
int lcm=1,hcf=1;
int prime[26]={1,2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};

printf(“enter the numbers”);
scanf(“%d%d%d”,&a,&b,&c);

for(i=1;i<26;i++)
{
l=prime[i];
if(a%l==0 && b%l==0 && c%l==0)
{
hcf*=l;
}
else
{
if(a%l==0)
lcm*=l;

if(b%l==0)
lcm*=l;

if(c%l==0)
lcm*=l;
}

}
}

printf(“\nHcf of three number %d %d %d is %d”,a,b,c,hcf);
lcm=lcm*hcf;
printf(“\nLcm of three number %d %d %d is %d\n”,a,b,c,lcm);
}

Posted in Uncategorized | Leave a comment

Inserting a file inside a Kernel file system

RCS file: entry.c,v
Working file: entry.c
head: 1.6
branch:
locks: strict
raghav: 1.6
access list:
symbolic names:
keyword substitution: kv
total revisions: 6;    selected revisions: 6
description:
program to insert a driver file inside our kernel
—————————-
revision 1.6    locked by: raghav;
date: 2014/02/11 12:33:38;  author: raghav;  state: Exp;  lines: +2 -2
ERROR: i was using name function name “out” for exit function
Now i changed it to outo , and now it works without showing any bug
—————————-
revision 1.5
date: 2014/02/11 12:31:14;  author: raghav;  state: Exp;  lines: +2 -1
ERROR: forget to write retern 0 in init function
—————————-
revision 1.4
date: 2014/02/11 12:27:34;  author: raghav;  state: Exp;  lines: +5 -5
creating  a seperate Makefile to execute both files init.o and exit.o
This make file is important as we can’t compile out init func seperately
—————————-
revision 1.3
date: 2014/02/11 12:17:12;  author: raghav;  state: Exp;  lines: +14 -0
using module init function to insert the file inside the kernel and exit function is used to remove the file from kernel
Make sure dont use the same function name as init and exit are built in name and already defined inside kernels else it will create a problem
—————————-
revision 1.2
date: 2014/02/11 12:12:17;  author: raghav;  state: Exp;  lines: +2 -1
Inclluding linux/module.h and linux/init.h
and including MODULE_LICENCE
—————————-
revision 1.1
date: 2014/02/11 12:10:44;  author: raghav;  state: Exp;
Initial revision
=============================================================================

Posted in Uncategorized | Leave a comment

Introduction to Character Device Drivers and Kernel Symbol Table

Character Device Drivers:-

Character special files or character devices relate to devices through which the system transmits data one character at a time by, for example, getchar. These device nodes often serve for stream communication with devices such as mice, keyboards, virtual terminals, and serial modems, and usually do not support random access to data.

In most implementations, character devices use unbuffered input and output routines. The system reads each character from the device immediately or writes each character to the device immediately.

There are two major ways for a kernel module to talk to processes. One is through device files (like the files in the /dev directory), the other is to use the proc file system. Since one of the major reasons to write something in the kernel is to support some kind of hardware device, we’ll begin with device files.

The original purpose of device files is to allow processes to communicate with device drivers in the kernel, and through them with physical devices (modems, terminals, etc.). The way this is implemented is the following.

Each device driver, which is responsible for some type of hardware, is assigned its own major number. The list of drivers and their major numbers is available in /proc/devices. Each physical device managed by a device driver is assigned a minor number. The /dev directory is supposed to include a special file, called a device file, for each of those devices, whether or not it’s really installed on the system.

Kernel Symbol Table:-

In programming language, a symbol is either a variable or a function. Or more generally, we can say, a symbol is a name representing an space in the memory, which stores data (variable, for reading and writing) or instructions (function, for executing). To make life easier for cooperation among various kernel function unit, there are thousands of global symbols in Linux kernel.

In general,when we have to use some variable or function outside the scope we use EXTERN or Declare globally similarly in kernel space we use symbol table .Once we EXPORT a module to symbol table it become a part of kernel .On that kernel any user can import that module .The table contains the addresses of global kernel items—functions and variables—that are needed to implement modularized drivers. When a module is loaded, any symbol exported by the module becomes part of the kernel symbol table.you can stack new modules on top of other modules. Module stacking is implemented in the mainstream kernel sources as well.

Posted in Uncategorized | Leave a comment

Adding two numbers without using operators

we have provided many utilities in printf ,in which one of it is adding two positive number (only for positive numbers).here it goes like this,

we all now that printf() On success,returns the total number of characters written. On failure, a negative number is returned.now the new thing might some of you know that ,The “%*d” format specifier causes printf() to read two integers from its arguments, the first to set the field width and the second here it is a decimal number(depends on specifier).

now using           printf(“%*c%*c”,a,’  ‘,b,’  ‘);     we can get the sum of the number of a and b;

but how:- the first specifier * will be width (suppose a=3 and b=2) which gives the width 3 and 2 respectively and the second is blank spaces that means the blank spaces will print on 3rd and 2nd widths and printf will return 5 is is the sum (a+b=5)

sample program

printf(“enter the 1st number\n”);
scanf(“%d”,&a);
printf(“enter the 2nd number\n”);
scanf(“%d”,&b);

printf(“%d”,printf(“%*c%*c”,a,’ ‘,b,’ ‘));
By Mukund and Abhilash

Posted in Uncategorized | Leave a comment

Process Management

Any application that runs on a Linux system is assigned a process ID or PID. This is a numerical representation of the instance of the application on the system. It is used by the system administrator who may have to debug or terminate processes by referencing the PID. Process Management is the series of tasks a System Administrator completes to monitor, manage, and maintain instances of running applications.

Multitasking

Process Management beings with an understanding concept of Multitasking. Linux is what is referred to as a preemptive multitasking operating system. Preemptive multitasking systems rely on a scheduler. The function of the scheduler is to control the process that is currently using the CPU.

so there is parent process and child process. The process which creates another process is called parent process and latter is called child process. And each process has its own PID i.e. process identity number to distinguish the child from the parent.

To get these process IDs, we use following functions

a)      getpid() // to get the current process id

b)      getppid() // to get the creator/ parent process id

There are three methods of creating a process:

a)      Create a process with the use  of loader from file system.

b)      Create a process from the code segment of the current program using system call

c)      Duplication of the program

To create a process using this method (Duplicate) is done by using “fork()”

fork function is a special function use to create a child process from a parent process. Using fork(), child process shares the code segment of its parent but both processes have different physical address. After completion of the child process, child process returns its control to parent and the parent process returns its control to the shell.

child PID= parent PID + 1

PPID of child = PID of parent

fork() function returns three values

a)      0 (zero)    :  if the process is executed by child

b)      +ve value :  means child is created and +ve value is child’s PID

c)      -ve value  :  ERROR…! i.e. child process is not created

and we can use these values to know which process  is executing.

Posted in Project 03: Client Server Communication using Linux and IPC | Leave a comment