Friday, March 19, 2010

Data Types in C Language

common definitions of integral types
Implicit specifier(s) Explicit specifier Number of bits Unambiguous type
signed char same 8 int8_t
unsigned char same 8 uint8_t
char one of the above 8 int8_t or uint8_t
short signed short int 16 int16_t
unsigned short unsigned short int 16 uint16_t
int signed int 16 or 32 int16_t or int32_t
unsigned unsigned int 16 or 32 uint16_t or uint32_t
long signed long int 32 or 64 int32_t or int64_t
unsigned long unsigned long int 32 or 64 uint32_t or uint64_t
long long[1] signed long long int 64 int64_t
unsigned long long[1] unsigned long long int 64 uint64_t
 

 

 
Specific integral type limits
Specifier Common Equivalent Signing Bits Bytes Minimum Value Maximum Value
int8_t signed char Signed 8 1 −128 127
uint8_t unsigned char Unsigned 8 1 0 255
int16_t short Signed 16 2 −32,768 32,767
uint16_t unsigned short Unsigned 16 2 0 65,535
int32_t int Signed 32 4 −2,147,483,648 2,147,483,647
uint32_t unsigned int Unsigned 32 4 0 4,294,967,295
int64_t long long Signed 64 8 −9,223,372,036,854,775,808 9,223,372,036,854,775,807
uint64_t unsigned long long Unsigned 64 8 0 18,446,744,073,709,551,615        

Wednesday, March 10, 2010

Solution for : No rule to make target `kernel/bounds.c', needed by `kernel/bounds.s'

Error:
make -C /lib/modules/2.6.28-11-generic/build M= modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.28-11-generic'
  CHK     include/linux/version.h
  CHK     include/linux/utsrelease.h
  SYMLINK include/asm -> include/asm-x86
  HOSTCC  scripts/basic/fixdep
  HOSTCC  scripts/basic/docproc
  HOSTCC  scripts/basic/hash
make[2]: *** No rule to make target `kernel/bounds.c', needed by `kernel/bounds.s'\
.  Stop.
make[1]: *** [prepare0] Error 2

Solution for this is :
siva@ubuntu:/usr/src$ sudo apt-get --reinstall install linux-headers-`uname -r`
Reading package lists... Done
Building dependency tree
Reading state information... Done
0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 304 not upgraded.
Need to get 0B/668kB of archives.
After this operation, 0B of additional disk space will be used.
Do you want to continue [Y/n]? y


Then my module was succesfully compiled as follows:
siva@ubuntu:~/ldd/ydevice$ make
make -C /lib/modules/2.6.28-11-generic/build M=/home/siva/ldd/ydevice modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.28-11-generic'
  CC [M]  /home/siva/ldd/ydevice/ydevice.o
  Building modules, stage 2.
  MODPOST 1 modules
  CC      /home/siva/ldd/ydevice/ydevice.mod.o
  LD [M]  /home/siva/ldd/ydevice/ydevice.ko
make[1]: Leaving directory `/usr/src/linux-headers-2.6.28-11-generic'

Thanks to : http://ubuntuforums.org/showthread.php?t=1047374

Saturday, March 6, 2010

Version control of files using "hg" for your local system

Repository Maintenance

Maintaining a Subversion repository can be a daunting task, mostly due to the complexities inherent in systems which have a database backend. Doing the task well is all about knowing the tools—what they are, when to use them, and how to use them. This section will introduce you to the repository administration tools provided by hg, and how to wield them to accomplish tasks such as repository migrations, upgrades, backups and cleanups.

hg - mercurial is a open source version control 
At first the hg must be installed so do the following command.
sudo apt-get install mercurial

Prepare Mercurial
As first step, you should teach Mercurial your name. For that you open the file ~/.hgrc with a text-editor and add the ui section (user interaction) with your username:
[ui]
username = Mr. Johnson
 Initialize the project
Now you add a new folder in which you want to work
$ hg init project
Add files and track them
$ cd project
$ (add files)
$ hg add
 Note:
You can also go into an existing directory with files and init the repository there.
$ cd project
$ hg init
Alternatively you can add only specific files instead of all files in the directory. Mercurial will then track only these files and won't know about the others. The following tells mercurial to track all files whose names begin with "file0" as well as file10, file11 and file12.
$ hg add file0* file10 file11 file12
Save changes
$ (do some changes)
see which files changed, which have been added or removed, and which aren't tracked yet
$ hg status
see the exact changes
$ hg diff
commit the changes.
$ hg commit
now an editor pops up and asks you for a commit message. Upon saving and closing the editor, your changes have been stored by Mercurial.
Note:
You can also supply the commit message directly via hg commit -m 'MESSAGE'.
Move and copy files
When you copy or move files, you should tell Mercurial to do the copy or move or you, so it can track the relationship between the files.
Remember to commit after moving or copying. From the basic commands only commit creates a new revision
$ hg cp original copy
$ hg commit
(enter the commit message)
$ hg mv original target
$ hg commit
(enter the commit message)
Now you have two files, "copy" and "target", and Mercurial knows how they are related.

Check your history
$ hg log
This prints a list of changesets along with their date, the user who committed them (you) and their commit message.
To see a certain revision, you can use the -r switch (--revision). To also see the diff of the displayed revisions, there's the -p switch (--patch)
$ hg log -p -r 3

The procedure given for hg is so simple, if you follow up the commands and get practised with your local system then the other repository maintenances will be easy.So get practised with this hg and enjoy it.
Thanks to : http://mercurial.selenic.com/guide/



Friday, March 5, 2010

What is difference between interest rate stated as per annum and just interest rate as a percentage?

Best explained this way:
1) a friend asks for a loan of $1,000 for a couple of months. You say, OK but I want 10% Interest when you pay me back! When you friend pays you back the $1,000 he or she has to add 10% of the initial loan which equals $1,100.00.
2) You go to the bank and want to open an account paying 5.45% per annum on a 6 month CD (Certificate of Deposit) You give the bank 10,000. When you cash in your CD in 6 months, you'll have earned -
1/2 of $545 or $272.50 -- how did that happen?
The bank is only paying 5.45% per YEAR - you only loaned the bank 10,000 for 1/2 year.
The Math:
5.45 divided by 12 months equals: 0.454 x 6 Months Equals 2.7249996 x 10,000 - 272.50 rounded off. Hope this helps

An interest rate as a percentage is the one flat rate you must pay. Interest rate per annum is a compound interest, determined every year that the loan (or whatever) has not been paid back. Say, if you owed me $100 with a 1% per annum interest rate. You have to pay me back $101. If you have not repaid the loan, the next year you would have to pay me an extra 1% of $101, and so on.

Thanks to : http://wiki.answers.com

Tuesday, March 2, 2010

How to read man page of open system call function.

The manual is generally split into eight numbered sections, organized as follows (on BSD, Unix and Linux):
Section     Description
1     General commands
2     System calls
3     C library functions
4     Special files (usually devices, those found in /dev) and drivers
5     File formats and conventions
6     Games and screensavers
7     Miscellanea
8     System administration commands and daemons

In general if you read a man page of
man open
it will give a man page of  openvt - start a program on a new virtual terminal.We are not in need of this, we are in need of open system calls function man page.so to read this you have to update your man page.

The man page can be update as follows.
Install development man pages
Use apt-get command:
$ sudo apt-get install manpages-dev
so now you are ready to read the man page of open system call.
now type the following command in the terminal as below

man 2 open
this will give the man page of open, creat - open and possibly create a file or device.

Thanks to:
wikipedia and ubuntu forums

How to install sdcc with 8051 support libraries

Generally when you install a sdcc we normally use the following step.

sudo apt-get install sdcc

the above command line will install sdcc but nowadays it doesnt support mcs51 8051 libraries so it is better uninstall the older version of sdcc and install sdcc-nf.

If you are not aware of the procedure how to remove the older version of sdcc and install sdcc-nf , then follow the steps given below.

dpkg --listfiles sdcc-libraries-nf
apt-cache show sdcc-nf
dpkg --list | grep sdcc
apt-cache search sdcc
sdcc --version
echo $PATH

the above commands will say about your older version of sdcc and its libraries.


the following command will remove the older version of sdcc

sudo dpkg --remove sdcc





the following command will install the newer version of sdcc-nf 

sudo apt-get install sdcc-nf

So now we are ready to use the 8051 related libraries.

Thanks to :
My Frnds and website resources provided by internet.

Monday, March 1, 2010

How-to: Install Ubuntu Linux on a usb pendrive

This tutorial will show how-to install Ubuntu on a usb stick. Even though this tutorial uses Ubuntu as its base distribution, you could virtually use any type of Linux liveCD distribution.
Being able to run Linux out of a usb bar is a great way to enjoy the live CD experience (being able to use Linux on any computer you might get by) and the big advantage of being easier to carry around than a CD.

1. Requirements

In order to reproduce this tutorial, you will need a few items such as:
  • a ubuntu liveCD
  • a usb bar of at least 1G
  • a running Linux operating system
Now that you have all this, it is time to prepare you USB bar do host the Ubuntu liveCD files.

2. Setting up the USB disk

2.1. Finding the device

In the first place, you need to plug your usb drive and check under which device it is associated. To find out the device, run:
$ sudo fdisk -l
On my system, the device appears as being /dev/sdb, I will therefore use /dev/sdb as a reference for this tutorial, please replace it accordingly to your system (might be sda, sdc ...).
Once you found your device, you are going to create the partitions.
Using the wrong device name might destroy your system partition, please double check

2.2. Making the partitions

Make sure every of your already mounted partition are unmounted:

$sudo umount /dev/sdb1
and then launch fdisk, a tool to edit partition under linux:
sudo fdisk /dev/sdb
We are going delete all the partition and then create 2 new partition: one fat partition of 750M which will host the files from the live CD iso, and the rest on another partition.
At fdisk prompt type d x where x is the partition number (you can simply type d if you only have one partition), then:
  • n to create a new partition
  • p to make it primary
  • 1 so it is the first primary partition
  • Accept the default or type 1 to start from the first cylinder
  • +750M to make it 750 Meg big
  • a to toggle the partition active for boot
  • 1 to choose the 1 partition
  • t to change the partition type
  • 6 to set it to FAT16
Now we have out first partition set up, let's create the second one:
  • n to create yet again a new partition
  • p to make it primary
  • 2 to be the second partition
  • Accept the default by typing Enter
  • Accept the default to make your partition as big as possible
  • Finally, type w to write the change to your usb pendrive
Partitions are now created, let's format them.

2.3. Formatting the partitions

The first partition is going to be formated as a FAT filesystem of size 16 and we are going to attribute it the label "liveusb".
$ sudo mkfs.vfat -F 16 -n liveusb /dev/sdb1
The second partition is going to be of type ext2 with a blocksize of 4096 bytes and the label casper-rw. Mind that it has to be labeled as casper-rw otherwise the tutorial won't work!.
$ sudo mkfs.ext2 -b 4096 -L casper-rw /dev/sdb2
At this stage, our usb pendrive is ready to host the liveCD image. Now, let's copy the files to the usb bar.

3.1. Mounting Ubuntu liveCd image

In the first place we need to mount our ubuntu iso. Depending if you have the .iso file or the CD, there is 2 different ways of mounting it.

3.1.1. Mounting from the CD

People using Ubuntu or any other user-friendly distro, might just have to insert the cd and it will be mounted automatically. If this is not the case:
$ sudo mount /media/cdrom
should mount it.

3.1.2. Mounting from an .iso image file

We will need to create a temporary directory, let say /tmp/ubuntu-livecd and then mount our iso (I will be using a feisty fawn iso).
$ mkdir /tmp/ubuntu-livecd
$ sudo mount -o loop /path/to/feisty-desktop-i386.iso /tmp/ubuntu-livecd
Once the cd image is ready, it is time to mount the newly created usb bar partitions:

3.2. Mounting the usb bar partitions

Same here, you might be able to get both your partition by simply replugging the usb pendrive, partition might appears as: /media/liveusb and /media/casper-rw. If this is not the case, then you will need to mount them manually:
$ mkdir /tmp/liveusb
$ sudo mount /dev/sdb1 /tmp/liveusb
All the partitions we need are now mounted, let's copy the files.

3.3. Copying the files to the usb bar

Let positionned yourself on the CD image directory (in my case: /tmp/ubuntu-livecd , but it might be /media/cdrom , and copy at the root of your usb first partition:
  • the directories: 'casper', 'disctree', 'dists', 'install', 'pics', 'pool', 'preseed', '.disk'
  • The content of directory 'isolinux'
  • and files 'md5sum.txt', 'README.diskdefines', 'ubuntu.ico'
  • as well as files: 'casper/vmlinuz', 'casper/initrd.gz' and 'install/mt86plus'
$ cd /tmp/ubuntu-livecd
$ sudo cp -rf casper disctree dists install pics pool preseed .disk isolinux/* md5sum.txt README.diskdefines ubuntu.ico casper/vmlinuz casper/initrd.gz install/mt86plus /tmp/liveusb/

When i did the above procedure disctree  ubuntu.ico was not available in my /tmp/ubuntu-livecd so dont worry about that two folders and proceed with your further steps.

It might complain about symbolic links not being able to create, you can ignore this.
Now let's go to the first partition of your usb disk and rename isolinux.cfg to syslinux.cfg:
$ cd /tmp/liveusb
$ sudo mv isolinux.cfg syslinux.cfg
change /tmp/liveusb according to your settings

Edit syslinux.cfg so it looks like:

DEFAULT persistent
GFXBOOT bootlogo
GFXBOOT-BACKGROUND 0xB6875A
APPEND  file=preseed/ubuntu.seed boot=casper initrd=initrd.gz ramdisk_size=1048576 root=/dev/ram rw quiet splash --
LABEL persistent
  menu label ^Start Ubuntu in persistent mode
  kernel vmlinuz
  append  file=preseed/ubuntu.seed boot=casper persistent initrd=initrd.gz ramdisk_size=1048576 root=/dev/ram rw quiet splash --
LABEL live
  menu label ^Start or install Ubuntu
  kernel vmlinuz
  append  file=preseed/ubuntu.seed boot=casper initrd=initrd.gz ramdisk_size=1048576 root=/dev/ram rw quiet splash --
LABEL xforcevesa
  menu label Start Ubuntu in safe ^graphics mode
  kernel vmlinuz
  append  file=preseed/ubuntu.seed boot=casper xforcevesa initrd=initrd.gz ramdisk_size=1048576 root=/dev/ram rw quiet splash --
LABEL check
  menu label ^Check CD for defects
  kernel vmlinuz
  append  boot=casper integrity-check initrd=initrd.gz ramdisk_size=1048576 root=/dev/ram rw quiet splash --
LABEL memtest
  menu label ^Memory test
  kernel mt86plus
  append -
LABEL hd
  menu label ^Boot from first hard disk
  localboot 0x80
  append -
DISPLAY isolinux.txt
TIMEOUT 300
PROMPT 1
F1 f1.txt
F2 f2.txt
F3 f3.txt
F4 f4.txt
F5 f5.txt
F6 f6.txt
F7 f7.txt
F8 f8.txt
F9 f9.txt
F0 f10.txt
Woof, finally we have our usb disk almost usuable. We have a last thing to do: make the usb bootable.

3.4. Making the usb bar bootable.

in order to make our usb disk bootable, we need to install syslinux and mtools:
$ sudo apt-get install syslinux mtools
And finally unmount /dev/sdb1 and make it bootable:
$ cd
$ sudo umount /tmp/liveusb
$ sudo syslinux -f /dev/sdb1
Here we are :D , reboot, set your BIOS to boot from the usb bar and enjoy Ubuntu linux from a pendrive

4. Troubleshooting

If you are having trouble booting on the usb bar, this might be due to your MBR being corrupted. In order to fix it up, you can use lilo (I installed lilo on my box only for thid purpose).
$ lilo -M /dev/sdb
will fix the MBR on device /dev/sdb
Come on go ahead and use your Ubuntu Linux on a usb pendrive - happily wherever you go.
Thanks to :
http://www.debuntu.org/how-to-install-ubuntu-linux-on-usb-bar 
My office colleagues who helped me