2011年9月19日 星期一

Android Sensor Path

Application layer: application
Application Framwork : Sensor Manager
Sensor JNI
Libraries: Sensor Manager <--> Sensor Service <--> Sensor HAL
Kernel : Input dirver subsystem and Event Dev
Sensor driver


# Sensor Manager Application Layer: /frameworks/base/core/java/android/hardware folder
# Sensor JNI layer: /frameworks/base/core/jni/android_hardware_SensorManager.cpp file
# Sensor Manager Library: /frameworks/base/libs/gui folder
# Sensor Service: /frameworks/base/services/sensorservice folder
# Sensor HAL: /hardware/ti/omap3/libsensors folder
# Accelerometer Sensor driver: /drivers/input/misc/xxxxx.c file



Note: Android 2.3 change the sensor service as Native Sensor code.

2011年9月7日 星期三

Linux script : backslash "\"

backslash "\" : escape next special characters

Ex:
echo "Path is $PATH" ---> This will show $PATH content
echo "Path is \$PATH" ---> This will show $PATH string

The backslash wiil remove the specail meaning of dollar($) sign

Linux script : echo -e

echo -e "My name is \t test"

You will see the My name is test

-e: enable backslash ascapes

The backslash-escaped characters


\a     alert (bell)
\b backspace
\e an escape character
\f form feed
\n new line
\r carriage return
\t horizontal tab
\v vertical tab
\\ backslash
\' single quote
\nnn the eight-bit character whose value is the octal value nnn (one to three digits)
\xHH the eight-bit character whose value is the hexadecimal value HH (one or two hex digits)
\cx a control-x character
reference :http://bash.cyberciti.biz/guide/Quoting

Linux script: Quoting

http://bash.cyberciti.biz/guide/Quoting

The double quote " : variable and command will be run

The single quote ' : variable and command will not be run

Ex:
echo "$PATH" --> The $PATH will be expand
echo '$PATH' --> The $PATH will not be expand

echo "$(date)" --> show date
echo '$(date)' --> only show $(date)

2011年9月6日 星期二

Linux script: grep in a test/if statement

http://www.unix.com/shell-programming-scripting/57761-using-grep-test-if-statement.html
exampe1:

cd ${PATH}

if [ 'grep SOME_STRING $PATH/$LOGFILE' ]
then
rm ${FILE}
./anotherScript
else
exit 1
fi
exit 1


Example 2:
cd ${PATH}

if [ $(grep -c SOME_STRING $PATH/$LOGFILE) -ne 0 ]
then
rm ${FILE}
./anotherScript
else
exit 1
fi

exit 0

Exampe 3:
cd ${PATH}

grep -q SOME_STRING $PATH/$LOGFILE
if [ $? -eq 0 ]
then
rm ${FILE}
./anotherScript
else
exit 1
fi

exit 0

Linux script : 2>&1

2>&1 表示將stderr導向輸出stdout

0: stdin
1: stdout
2: stderr

exampe: # /tmp/test.sh > /tmp/test.log 2&1

2011年9月5日 星期一

Using printk debug

Using printk debug
There three method
1. KERN_EMERG to KERN_DEBUG
- pr_energe to pr_debug

2. Change the kernel command line
- loglevel = parameter
We can refer Kernel/doc/kernel-parameters.txt

3. Change the printk level after bootup
- /proc/sys/kernel/printk
ex: echo 8 > /proc/sys/kernel/printk
Then read /proc/kmsg

- /proc/sysrq-trigger

You can modify the #DEFAULT_CONSOLE_LOGLEVEL 8
at kernel/prink source code

There are prink tips andd tricks
1. CONFIG_PRINTK_TIME

2. CONFIG_EARLY_PRINTK
- CONFIG_DEBUG_LL and added some patch

3. CONFIG_LOG_BUF_SHIFT
- you can use the dmesg to change the printk buffer
"dmesg -s 128000" this mean we open 128k buffer


You can open the kernel configuration with #make menuconfig
kernel hacking --> <> show timming information as printks
<> debug filesystem
<> kernel low-level debugging function


There are two topic need to study
- debug system
debug system at /sys/kernel/debug
You can mount it by mount -t debugfs none /sys/kernel/debug
Or write it in /etc/fstab
debugfs /sys/kernel/debug debugfs 0 0

- dynamic debug
- CONFIG_DYNAMIC_DEBUG
- Operate on pr_debug or dev_dbg

linux script :Using while loop

http://www.cyberciti.biz/faq/bash-while-loop/

bash while loop syntax


while [ condition ]
do
command1
command2
command3
done
================================
Example:
#!/bin/bash
x=1
while [ $x -le 5 ]
do
echo "Welcome $x times"
x=$(( $x + 1 ))
done



=======================================

#!/bin/bash
while :
do
echo "infinite loops [ hit CTRL+C to stop]"
done
==========================================

Conditional while loop exit with break statement


while [ condition ]
do
statements1 #Executed as long as condition is true and/or, up to a disaster-condition if any.
statements2
if (disaster-condition)
then
break #Abandon the while lopp.
fi
statements3 #While good and, no disaster-condition.
done

2011年9月1日 星期四

linux driver sample : only init

Makefile:
===============================================================
KDIR :=/work/kernel/android-2.6.35
PWD := $(shell pwd)
ARCH=arm
CROSS_COMPILE=/work/tools/arm-2010q1/bin/arm-none-linux-gnueabi-
CC=$(CROSS_COMPILE)gcc
LD=$(CROSS_COMPILE)ld

obj-m := foo.o

all:
$(MAKE) -C $(KDIR) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) M=$(PWD) modules

clean:
rm -rf *.o *~ core.depend .*.cmd *.ko *.mod.c .tmp_versions
===============================================================


source code:
===============================================================

#include "linux/module.h"
#include "linux/kernel.h"
#include "linux/init.h"

static int __init foo_init(void)
{
printk("foo module init !!! \n");
return 0;
}
static void __exit foo_exit(void)
{
printk("foo module exit !!!! \n");
}

module_init(foo_init);
module_exit(foo_exit);

===============================================================