Thursday, November 10, 2011

Wake-up enable for UART

Requirement
=========
Suspend the device to RAM. It should wake up on any key press from UART.

First Method
=============
This can be done by just adding  "no_console_suspend" to bootargs.
By doing this during suspends to RAM, Uart clk src will be kept alive.

Second Method
==============
For this method, hardware should have the capability to wake-up from UART interrupt.

All devices in the device model has two flags to control the wake-up events. They are "can_wakeup" and "wakeup" flags in

struct device {
....
struct dev_pm_info power;
....
}

struct dev_pm_info {
.......
unsigned int can_wakeup:1;
struct wakeup_source *wakeup;
........
}

Flag can_wakeup is initialized by the device driver code by using device_set_wakeup_capable().
And, device_set_wakeup_enable(&dev, 1) will initiallize the struct wakeup_source and add in the list of wake-able sources.

can_wakeup is used to mark whether the hardware can support the wake-up. For most of the devices wake-up will be NULL by default. But used by drivers like power buttons, keyboards and Ethernet.

I want to configure UART as my wake-up source, this patch does it on kernel-3.0.1

diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index ab2e6e7..2bae1aa 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -2401,7 +2401,7 @@ int uart_add_one_port(struct uart_driver *drv, struct uart_port *uport)
tty_dev = tty_register_device(drv->tty_driver, uport->line, uport->dev);
if (likely(!IS_ERR(tty_dev))) {
device_init_wakeup(tty_dev, 1);
- device_set_wakeup_enable(tty_dev, 0);
+ device_set_wakeup_enable(tty_dev, 1);
} else
printk(KERN_ERR "Cannot register tty device on line %d\n",
uport->line);

Then I tested it with echo mem > /sys/power/state

The device is able to wake-up from my UART1 interrupt which is also my console.

Now my board has many UART. I want to configure the UART2 as wake-able source, but my console is on UART1.

From the command prompt,
cat /dev/ttyS1 &

this done to initialize the UART2 port

And opened UART2 serial port on second instance of minicom. Then entering any character on second minicom wake-up my device.

Tuesday, September 27, 2011

Andriod Toolbox

Android comes with a user space utility called Toolbox which is not busybox. It is at system/core/toolbox. But with very limited features.

For using the busybox,

1) Git clone from http://git.busybox.net/busybox/
2) To cross compile with arm tool-chain and building it as static, used the following command.
$ make -j32 CROSS_COMPILE=/projects/mob_tools/CodeSourcery/Sourcery_G++_Lite/bin/arm-none-linux-gnueabi- -I/projects/mob_tools/CodeSourcery/Sourcery_G++_Lite/arm-none-linux-gnueabi/libc/usr/include/ CFLAGS=--static
3) for installing the busybox,

Building Individual Components in Android

Run

source build/envsetup.sh

Then you can use mm command to compile any Android.mk individually

For example to compile the android Toolbox.

cd system/core/toolbox.

mm

Wednesday, March 16, 2011

Free Electrons

http://free-electrons.com/

They offer free training materials about Linux kernel. And their blog is interesting to read to keep you updated about the current kernel developments.

Thursday, March 10, 2011

System revision

Development boards usally have many version. Because no board can be perfect first time. So in the process of improving the boards we end up in many system revisions. One way of doing this is to dedicate few gpio lines(may be 3 in this case you can have 2^3 = 8 board versions). Disadvantage of this way is thay you will end up waisting 3 gpios. Another way is to use the ADC for this purpose. The mechanism is to connect two resitance in series and varry the resistance amoung the boards. Measure the voltage across one resitor and find out the board.
For example, R1 = 100K and R2 = 100K. R1 and R2 are in series with volatge of 3.3V. So the voltage drop across R2 will be 1.65V, which we measured using ADC and decision is made.

In C110 processor we use ADC with resolution of 12 bits so the range is 0 to 4095. But the voltage range is 0 to 3.3V. Now we need to map adc value to our voltage range.

Here is the mathematics,
3.3V = 4095 units of ADC
1 unit of ADC = 3300 mV/4095 = 0.8058mv
for 3.3 v adc value is 4095 units( ie 3300/0.8058)

So in our case we need 1.65V or 1650 mV. So the adc value should read 2047(ie 1650/0.8058)

Tuesday, March 8, 2011

NOR Vs NAND

NOR
Access - linear random
Replace - ROM
Cost - expensive
Density - low
Earse time - 1 second
Programing - byte by byte
OOB data - no
NAND
Access - pagewise
Replace - mass strorage
Cost - cheap
Density - high
Earse time - 2 ms
Programming - pagewise, must be erased before
OOB - yes

yaffs2 and nand drivers

The crespo board was booting android with system and data partititons on the Movi-nand. Now the task is to move this to the one-nand memory. The main area to be modified is at the bootloader where partitons are defined. This will be passed to kernel as ATAGS. so modified the partition table to point the system and the data partitions to nand. Then edited the init.herring.rc file to
mount yaffs2 mtd@system /system wait ro
mount yaffs2 mtd@userdata /data wait noatime nosuid nodev

Next is to create yaffs2 filesystem. Initally I used the command,
./out/host/linux-x86/bin/mkyaffs2image out/target/product/crespo/system sytem.img
But file system was not mounting with this. The reason was that by default mkyaffs2image utility used page size as 2048 and spare area(OOM) as 64. Later when I checked the data sheet of the One-nand, it was 4096 and 128 respectively. So modifed the command to,
./out/host/linux-x86/bin/mkyaffs2image -c 4096 -s 128 out target/product/crespo/system system.img

But this time Odin was giving and flashing failure. So I checked the size of the system.img. It was 155MB and compared with the size of the system partitions which was only 152MB. So that was the reason for flashing failure. After stealling some space from data partiton, flashing works. And the yaffs2 filesystem was successfully mounted. :-)

If you want to know more about the NAND and Yaffs2 File System here is a good link.

Monday, March 7, 2011

The power of Vim

Command line is one of the main thing most of the people hate about the Linux. But the power of linux comes form command line. Yes its a bit hard to learn and remember all the commands and keywords. But it worth learning. In my humble opinion its is the fastest editor than any GUI apps. Code travesing is so easy. Here I m presenting some of the vim command I frequently use. Read and move fast on your coding and debugging....

Travesing the code. ============= This is the first thing an editor should provide, to traverse through the code. To go to any reference, use

1) g + ] . This will list all the instance of the definition of a variable of a function if there are more than one. Press the number to go to the definition you prefer. To return back, 2) CTRL + t

This works with ctags. Before using the short cut keys, you should create the database using the command(Ctags -R). This command will create tags file.

To search any string in the current file, prese esc and type / Another way is using (SHIFT + *). Move to variable or function name and press (SHIFT + *). It will move to the next instance in the file. Then you can use " n" to move to next instance and "SHIFT + n" to search in backward direction. "SHIFT + g" will move to the end of the file. ":number" will move to the corresponding line number. If you want to find the end of any loops, put the cursor on the bracket and press "SHIFT + %"

"CTRL + e" to move down "CTRL + y" to move up. EDITING For selecting the lines, I use virtual mode. Press "v" then use the arrow keys to select as many line as you want. Then press "y". Use "p" to paste. To delete any blank space before the lines, use coloumn virtual mode by pressing "CTRL + v"

For auto completion, type till whatever you remember and use "CTRL + p" For substitution, %s/arun/avin/gc If you remove gc it will substitute all the instances of arun with avin without asking. If I want to copy from another file, use the following format, e filename Then use virtual mode and copy then type "e + #" . This will bring back to our old file. Then use "p" for pasting. Copying the format: If you want to format a code like intentation etc. Make few lines of code mannualy and then select the reset of the code along with the modified one in visual mode. Then press "=". The rest of the code will also get the intentation.

Undo and Redo
==============
press "u" for undo and
press "ctrl + r" for redo.


To use Marks
==============
http://vim.wikia.com/wiki/Using_marks


How do I repeat an edit on multiple lines in vim?

How do I repeate an edit on multiple lines ?
=================================

lets say for the text
abc1234
def5678
xyz3456

if you hit CTRL  + V with your cursor over the 1, use arrow keys twice to go down two columns, then Shift + i + ,  Then press ESC, your text would look like this:

abc,1234
def,5678
xyz,3456

.Vimrc
==============
Below are the thing to find in my .vimrc



Multiple copies(Vim copy paste buffers)
============================

"ay12 – create a buffer named ‘a’ with 12 lines in it
"ayw – create a buffer named ‘a’ with 1 word in it
"ap – put the contents of buffer named ‘a’

Please note that the named buffer can be any single letter between a – z

Usage: lets say you are writing a new driver and you want to type some words frequently. You can save them to the buffer.

For eg these two words are pmic_tw123 and PMIC_TW123

keep the cursor at the "pmic_tw123" and type "ayw. This creats a buffer named a and copies pmic_tw123 to it

keep the cursor at the "PMIC_TW123" and type "byw. This creates a buffer named b and copies PMIC_TW123 to it.

To paste use "ap and "bp.

We are actually using registers feature of the Vim. you can see the yanked words by issues :registers 

Similarly you can create for lines too.