Friday, October 31, 2008

Embedded Coding Style

My recent tryst with some "C" code written in Assembly like fashion has forced me to write this article up. I have been programming embedded systems for quite some time now. For those who are not aware, most of the embedded processors ( for the automotive domain) come with substantial amount of RAM and ROM spaces. Hence, it makes sense to write some what architectured code ( if not 100% for efficiency and optimization reasons).
"C" coding can get pretty messy sometimes if we dont architecture the code appropriately because of the very nature of language. "C" is a procedure oriented language and hence doesnot provide very clean natural organization of data ( like in case of C++, where classes can be used to hold all the logical data and operations together). Hence, personally i have used structures in C to hold all my data-memebers in a single nutshell.
There are some good and bad parts about a Structure. The good part is that it encapuslates all the data i need into one shell. The bad part is padding. If you dont arrange the members in your struct carefully you will end up eating up more memory than you would really need. Typically arrange the smallest member on the top and progressively the bigger ones so that there are fewer padding holes created in your stucture variable.
The other hint that i got from both Nec and CC compilers is to use scopes sensibly. What that means? Simply, choose a scope for a variable based on needs. There is not much gained by making all your variables global. Hence, as far as possible try to limit the scope of your variables to whatever is the minium needed. Also try to ensure that scope you have chosen, explain the logical boundaries of the variable
Ex.
void My_StateMachine(void)
{
switch(state) /* make state global if there is something which is using the state outside of this function, else make it a static inside the function */
}

Why am i telling you all this? Well you already know the answer in the first line of this article. It is much simpler to maintain software where the scope of variables are limited logically. Too many Globals means that too many blocks of softwares can change the variables in your system. This can lead to hard to solve bugs in future.

Monday, October 27, 2008

TV Games Shows - Beckoning a RatRace

In recent few months there has been a spur in the number of TV games shows and competitions esepcially for children. It is a wonderful moment for the veiwer and the parents alike to see the children perform in front of the camera. I loved to see these competitions and enjoy them a lot. However, As I see more of these I observed something disturbing.
There seems to be a rat-race that has been started by the parents to ensure that their child is in front of the camera for the longest duration. This in turn boils down to a lot of pressure on the young shoulders to perform well in the competitions. To add fuel to the fire, there are comments by judges which encourage more competitive spirit and emphasize on practice. While, I agree with the comment of the judges when it comes to the hardwork part, I do not agree with the part of competition. I feel it is not correct on our part to pressurize the young minds to get into the competitive mode at such an early stage.
Personally, I have always been encouraged to compete with others in very mode of life by my parents. After running the Rat-Race for 18 long years i realized that somewhere in this run i forgot to enjoy the journey. While i fully appreciate the fact that being compentitive is very essential, One must also realize that what is more important is that one enjoys his childhood.

I read a statement in a cafe once which stated,
"Goal is important, but it is more important to enjoy the journey to the Goal"

I find that remarks from the judges and the attitude of the parents concentrate only toward the first part of the statement. What we forget is the second part of the statement. The children as also in a very awkward situation, because it is very difficult for them to explain the situation. It is wrong on our part to assume their silence as their consent to our veiwpoint for them.

Sunday, October 26, 2008

Ubuntu - Installation adventure

When Srinivas told me that UBUNTU was becoming one of he most preffered flavors of LINUX i did not believe in his words. After a bit of pondering and browsing around i finally thought let me give it a shot. I downloaded the 700 mb installer. Ubuntu's latest flavor 8.x has some cool features which really are helpful for a Windows lover (Read Unix illiterate) like me.
My Sunday morning started of with writing the *.iso file into a CD. Be sure you do this at a slow speed because I wrote it at maximum speed on a "NOT" so good cd and the installer failed!!.
You can install this version of UBUNTU like you would do any other software like MSOFFICE. No need of formatting or making a new partition...When you reboot your PC you will get an option of using ubuntu. Aint that cool....you cant do that even with windows ;-).

However, if you thought that my life was all rosy...beware!!..Life is never rosy...I figured out that i could not get the needed resolution on my wide screen monitor. Infact, i also realized that i had to download the NVIDIA dirvers to make this thing really usable. I am no LINUX geek, i just wanted to own a decent OS :-(. However, I did not give up and started of by downloading the NVIDIA drivers from their website. However, a lot of command lines are needed to run it and there are a few things that is needed to get it running. I stuggled with various things try to first get the resolution right thinking that i will install the drivers later...BIG mistake...Get the driver installed first then do the rest. You will have to configure the Router before you can connect to the net. I made a list of things that i would need to look up and downloaded the pages from my windows partition and then used them as a guide to get my Ubuntu talk to external world via the router.
The NVIDIA drivers need to be compiled for the UBUNTU kernal, hence you will have to use the Synaptic Manager to download Libc libraries. Stop the Xserver by using
sudo /etc/init.d/gdm stop
run the executable that you have via
sudo sh DriverName.run
then restart it using startx or /etc/init.d/gdm start
and then you should be done.
You will also get all the missing resolution and speed that you were looking for...
And trust me it was a moment of Triumph for me as i loved the graphics and the clarity. It was really worth the effort...One step towards making friends with TUX.

Saturday, October 25, 2008

No Smokin!!

On the 2nd of OCT, 08, The law against smoking in public places was passed and officially atlest it was an offence to indulge in smoking in public places. I would consider this as a very bold step because it is not something which would have been easy to get through especially with big companies involved in manufacturing of cigarettes.

As i write this it is almost about 3 weeks since this law was made. I have seen a lot of agencies supporting this cause ( willingly or unwillingly) and have put up banners and notice boards with messages stating the law. However, I guess a lot more needs to be just done than putting these messages and banners. In a country like India where the rules are heavily controlled by big-shots sitting in Air-Conditioned chambers, it is extremly optimistic to assume that the law would be incorporated in just a few weeks. I am sure it is not a very rare site to see government officials and Police officials smoking in public places and voilating the law themselves. However, what I still appreicate is that finally a rule was passed and it was considered necessary to make it an offence.

Personally, I dont mind people smoking. I have always believed that it is an individual's responsibility to decide what is good or bad for him, provided he does not effect any other individual without his consent. However, more often than not public smoking causes inconvenience to other bystanders. Hence, I belive the government should go another step further and instead of marking all places with "No Smoking" signs, should also mark a small set of places as "Smoking Zones". Though this might not go too well with a lot of people who consider smoking as a crime, I would say that this way both the non-smoker and the smoker is happy in his own way. There is no need to dictate one's lifestyle here, all that is needed is isolate the ill-effects of ones from the others.