Wednesday, 14 July 2010

JamVM : JAVA Virtual Machine for Atmel NGW100

I have been very busy with a project in my university and I could not write about JamVM (Java Virtual Machine that could be used in Atmel NGW100) as I promised.

You can get binaries of JamVM in http://avr32linux.org/twiki/bin/view/Main/JamVM. You will simply copy those files to your NGW100. Before you work on this, make sure that classpath is configured and copied in your system as I described in my earlier post.

At the beginning of my project I was not sure whether Java is appropriate for NGW100. There are already a lot of arguments about the speed of Java in desktop computers. So I hesitated to use Java instead of C. But my concerns turned out to be unnecessary regarding the performance of Java on NGW100. I have written network programs both in TCP and UDP, used JNI for some C based binary files and used sound API for some sound I/O. In all those subjects I did not faced with a problem of performance. Yet, I do not know if I design a bigger project maybe the performance would be an issue. However as I said, there was no problems at all. And more importantly it is fun to code in JAVA instead of using deadly pointers in C :)

Hope this will help.

JAVA/C# Parameter Passing

I have been recently faced with an argument in some JAVA communities that whether JAVA uses Pass by Value or Pass by Reference in parameter passing. Well actually this discussion based on the paradigm object orientation of JAVA.

You might think that since JAVA is pure object-oriented programming language then it would have been using pass by reference for its parameter passing. However there is a slight difference in JAVA in this idea. To be certain let's clearly state that, JAVA uses Pass by Value for parameter passing. There is no doubt about it. But, the copy of parameter is not the value of parameter itself, instead, copy its reference. Things get weird at this point.

Let me give an example with the garbage collection system. We know that the space for a variable in memory is released when there is no reference pointed to that object anymore. At this step, garbage collection automatically free up that memory space for you.

public static void main(String[] args){
MyObject o = new MyObject();
doSomething(o);
}
public static void doSomething(MyObject o){
o = null;
}

First of all above code will not cause MyObject o be destroyed by garbage collection.
Well if JAVA used Pass by Reference, MyObject o's memory space would be released and there would be no way around in the main method to use that created object after doSomething() method. However, it's not the case. Since JAVA copies the reference when you invoke doSomething() method, JVM will create a new reference variable. So there will be 2 references pointing the o object in the memory. If we give "null" value to one of them, the other will still hold the location information of that object. Which, in turn, concludes that JAVA is Pass by Value. But do not let the name deceives you, yes it includes "Value" but always remember that address of a memory segment is also a value in programming languages. Furthermore there is nothing in JAVA to support Pass by Reference.

Since the article name indicates a comparison we will also talk about C#. C# is almost the same as JAVA with an important difference in parameter passing. There are 2 keywords in C# which are out and ref and they are used to specify parameters in method invocation. If you use those keywords you will be able to use Pass by Reference idiom. I'm not going to give details but one of them requires initialization of parameter before passing to a method, that's the only difference.

I think people really should read the documentation, documentation is really helpful in this manner. With the combination of classic programming language idioms and the documentation everything is crystal clear about this Parameter Passing issue.

Monday, 22 March 2010

Recovering Corrupted/Malfunctioned GRUB in Linux

This problem is actually not related to NGW100 :) However I wanted to give solution how to recover your corrupted/crashed GRUB menu due to some reasons. Well, most common reason for GRUB to crash is a new Windows installation over Linux which is a process that writes specific information to your PC's boot sequence. People are having great difficulty if their GRUB is crashed. They may even cannot boot any of the installed operating system. So in this article I'm gonna try to help recovering your GRUB.

All the operations below must be done with administration privileges.

1. First of all you should get a Live CD of any Linux distro. In my situation I'm using Ubuntu CD to boot my computer.

2. After booting your Ubuntu using Installation CD or Live CD(earlier versions of Ubuntu, now you can use Installation CD as Live CD) you need to get yourself into Linux's terminal.

3. Well only information you need at this moment is what partition has what operating system. Fortunately GRUB's setup will help you decide those partitions. Unlike most of humans(yea, yea)
GRUB starts to count from 0 not 1. So lets say you have 2 HD's in your computer first one is hd0 and 2nd one is hd1.Same rule will be applied to your partitions. If your Linux operating system is installed in your first hard-disk and 2nd partition then you have (hd0,1).

4. Based on our previous assumption you need to get to grub interpreter by typing grub. After that follow the codes below:

grub> root (hd0,1)
grub> setup (hd0)
grub> quit


Now you can reboot your computer safely into your operating systems :)

P.S: fdisk -l will give you some information about your hard-disks, partitions and operating systems. If you're not sure where your operating system (mainly your linux partition) then I suggest you to use that information.

Thursday, 18 March 2010

C Compiler Installation on Atmel's NGW100




As a developer working in different systems is sometimes really painful. What I've encountered as a problem so far is compiler installation on NGW100. Well, if you're a beginner you might not see this as an easy job to do. First of all it's not sufficient to have programming background but you have to know a bit of UNIX operating systems in other words today's so called Linux distros.

NGW100 is one of those systems, since it has different processor you cannot use your regular compiler. Furthermore, those compiler designers probably are not supporting NGW100. So you need to know two things before you get yourself on the road:

1. What cross-compiling is
2. How to handle NGW100's configuration.

Cross compiling is a compiling process where your target machine, that your executable program work on, and your developer machine is different. What you have to do is, you need to compile your source code with a given or self-generated compiler. In Atmel's NGW100 it's called avr32-linux-gcc. Atmel actually does not provide that compiler directly but you need to do some UNIX operations under a Linux distro. In our situation that compiler is kinda cross compiler.

I've tried to overcome this problem using different distros. Unfortunately there's only one distro that I used and succeeded which is Ubuntu 9.04. I've also tried newer versions of Ubuntu without a luck. So I recommend to use Ubuntu 9.04 for developing purposes under Linux. Again I've to confess that I've no knowledge about how to handle these problems under Windows or Mac. Anyway, you can install Ubuntu 9.04 or you can use Ubuntu 9.04 as a Live CD which you can use Ubuntu without installing on your hard-drive.

First thing to do is to install toolchain and buildroot which is provided by Atmel. You can find those packages in Atmel's web-site for Ubuntu 9.04.
At this point start installing toolchain and make yourself sure that you've installed these packages:

avr32program avr32gdbproxy avr32trace avrfwupgrade libavr32ocd libavrtools libelfdwarfparser

After that download buildroot extract it to some directory before installing it you need to make some configurations.
1. First configure menuconfig under buildroot extraction folder using this compilation will open a window that you need to pick some properties of your NGW100, choose correct values for your system and save.

make menuconfig


2. Similar to that you need to prepare source by

make source

3. And final step is compiling the whole by

make

After the compilation process is completed most probably your PATH variables are not set to point avr32-linux-gcc compiler. So you need to add avr32-linux-gcc 's path to PATH variable in UNIX system by:
export PATH=$PATH:(avr32-linux-gcc's path) without paranteses.

*Your avr32-linux-gcc program is placed under (buildroot's path)/build_avr32/staging_dir/usr/bin. So you need to give your actual path to the export command above.

So, if you've done all successfully then you should be able to use your avr32-linux-gcc everywhere in your terminal.

Last thing is try some C code on your machine. Just write some hello world code in your developing machine which might be:

#include
int main(){
printf("SUCCEEDED!!");
return 0;
}


You'll compile this hello.c source code with:

avr32-linux-gcc hello.c -o hello

And you need to transfer your hello file which is executable in your NGW100 system.
Now you can execute and see your success on your screen :)

Well my purpose actually is developing Java on my NGW100 I'll also explain how to do it soon. But if you can't wait to do so I suggest you to check JamVM virtual machine that can work on Atmel's NGW100. It's just a quick hint for Java developers from me. It's somehow a bit more trickier but hopefully you'll enjoy what you're doing while using JAVA on NGW100.

Tuesday, 12 January 2010

Welcome aboard !

Hi Folks,
For a long time I was thinking about starting a new blog related to IT world. Since my education gives me some strength about the products of this huge world I want to place my ideas, my practical experiences and some technological reviews on the net. By this way I might able to see what I was thinking of rather than trying to recall my past information. As you see, sharing information - unfortunately - is not the primary objection here. But on the other hand, I'm very confident that you'll find useful information for your IT life. I'm gonna try to keep this blog updated.

Hopefully my first entries will be about Atmel's microcomputer which is a my new toy I'm playing with. For now, I'm trying to reshape my knowledge about it, I'm gonna publish several articles as soon as they are ready for people who are eager to read and understand without any other scientific background.