Monday, February 28, 2011

Calling 'shell' from C/C++ code under Linux

See man page for those functions. Popen is better than system if want see return value of shell.

system()
popen()
pclose()

Network check

IFCONFIG
----------------------
$ifconfig
$ifconfig eth0 up
$ifconfig eth0 down

NETSTAT
-------------------
$netstat
Usage: netstat [-laentuwxr]

Display networking information

Options:
-l Display listening server sockets
-a Display all sockets (default: connected)
-e Display other/more information
-n Don't resolve names
-t Tcp sockets
-u Udp sockets
-w Raw sockets
-x Unix sockets
-r Display routing table




[root@GsnCommsModule user]# netstat -l
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 (null):13000 (null):* LISTEN
tcp 0 0 (null):ssh (null):* LISTEN
Active UNIX domain sockets (only servers)
Proto RefCnt Flags Type State I-Node Path


BUSY BOX SHOW NETWORK INFTERFACE
---------------------------------
$ ip addr show
To show the kernel routing table use:
$ ip route show

Tuesday, February 22, 2011

System back up using TAR Ball

[1] http://ubuntuforums.org/archive/index.php/t-194938.html
[2] http://www.cyberciti.biz/faq/linux-unix-extracting-specific-files/ --- Untar part of tar ball


EXCLUDE SOME FOLDERS WHEN DOING TAR BALL
--------------------------------------------
[root@localhost media]# tar -cvzpP --file=/mnt/200GSys/backuproot.tar.gz --exclude={/mnt/*,/boot/*,/home/*,/opt/*} /



INCLUDE MULTIPLE FOLDERS WHEN DOING TAR BALL
----------------------------------------------
tar -cvzpP --file=/home/q.yang/$NAME /home/q.yang/CodeSourcery /home/q.yang/devel /home/q.yang/Documents /home/q.yang/Download /home/q.yang/EclipseCDT /home/q.yang/JavaDev /home/q.yang/lpc3250



SAMPLE BACK UP SHELL
-----------------------------
[q.yang@localhost ~]$ cat tar_quentin_home_data.sh

NAME='Linux_Quentin_Home_bkup'_$(date +%g%m%d%H).tar.gz

if [ -f "$NAME" ]
then
echo "File $NAME exist already."
return
fi

touch $NAME

#find . -name "*.java" -mtime -$TimeRange -exec tar -uvf $NAME {} \;
#echo "source files of last $TimeRange days"
#find . -name "*.java" -mtime -$TimeRange -exec ls -all -ct {} \;
echo "tar -cvzpP --file=/home/q.yang/$NAME /home/q.yang/CodeSourcery /home/q.yang/devel /home/q.yang/Documents /home/q.yang/Download /home/q.yang/EclipseCDT /home/q.yang/JavaDev /home/q.yang/lpc3250 /home/q.yang/root_user_cmd_list.txt /home/q.yang/rpmbuild /home/q.yang/tar_quentin_home_data.sh /home/q.yang/.bash_profile /home/q.yang/.bash_history /home/q.yang/.bash_logout"


tar -cvzpP --file=/home/q.yang/$NAME /home/q.yang/CodeSourcery /home/q.yang/devel /home/q.yang/Documents /home/q.yang/Download /home/q.yang/EclipseCDT /home/q.yang/JavaDev /home/q.yang/lpc3250 /home/q.yang/root_user_cmd_list.txt /home/q.yang/rpmbuild /home/q.yang/tar_quentin_home_data.sh /home/q.yang/.bash_profile /home/q.yang/.bash_history /home/q.yang/.bash_logout



SAMPLE OF UNTAR TAR BALL
-----------------------------
[root@localhost q.yang]# cat /home/l.lu/untar_luke_home_usr_data.sh

#NAME='Linux_Luke_Home_Data__bkup'_$(date +%g%m%d%H).tar.gz
NAME=$1
OUTDIR=$2

if [ -f "$NAME" ]
then
echo "About to untar $NAME"
else
echo "File '$NAME' does not exist."
echo ""
echo "Sample running this shell 'untar_luke_home_usr_data.sh':"
echo ""
echo ". untar_luke_home_usr_data.sh Linux_Luke_Home_Data__bkup_$(date +%g%m%d%H).tar.gz"
echo ""
return
fi

mkdir $OUTDIR

echo "tar -xzvf $NAME -C $OUTDIR/"
tar -xzvf $NAME -C $OUTDIR/


ISSUES USING SYSTEM TAR COMMAND
-------------------------------------------------
When tar -xzvf on another Linux machine. I had a many complains of not able to change ownership.

This is one discussion about this issue on 'stackoverflow'.
"how to keep file ownership while using tar"
http://stackoverflow.com/questions/17273798/how-to-keep-file-ownership-while-using-tar

Someone recommended that using pure perl rather than system command to do archive and restore.
Below is a good link of how to use perl to do advance archive and restore.
http://perldoc.perl.org/Archive/Tar.html

Tuesday, February 15, 2011

Message based different level of Linux App Debugging.

Different level of debugging message from CommsModule-HS



DEBUG:ThdID1185617040 : 0x00
DEBUG:ThdID1185617040 : 0x00
DEBUG:ThdID1185617040 : 0x64 d
DEBUG:ThdID1185617040 : 0x53 S
DEBUG:ThdID1185617040 : 0x73 s
DEBUG:ThdID1185617040 : 0x41 A
DEBUG:ThdID1185617040 : 0x00
DEBUG:ThdID1185617040 : 0xF2 ò
DEBUG:ThdID1185617040 : 0x13
INF:ThdID1185617040 : SpiComm Thread exit.

DEBUG:ThdID1160451216 : Trace SPI Synch Head 0x0C

WARN:ThdID1160451216 : Wrong SPI Synch Head 0xC

DEBUG:ThdID1160451216 : Trace SPI Synch Head 0x41

DEBUG:ThdID1160451216 : Trace SPI Synch Head 0x74

DEBUG:ThdID1160451216 : Received SpiPktInPipe head: 0x0C At

DEBUG:ThdID1160451216 : received head of spi packet 8 Bytes

DEBUG:ThdID1160451216 : Received spi packet head 12 Bytes in total.

INF:ThdID1160451216 : 0x0C At 0x0000 0x64 SsA
INF:ThdID1160451216 : PwrViewStk get valid reply from SpiComm.

DEBUG:ThdID1160451216 : Received PwrView Synch Head PV*VB-

DEBUG:ThdID1160451216 : received data 2 Bytes

DEBUG:ThdID1160451216 : Received PwrView head 4 Bytes in total.

INF:ThdID1160451216 : PwrViewStk get Msg and about to process.

INF:ThdID1160451216 : SpiComm Thd is created by PwrView Stk to do solicited report.
Thread 1160451216:SpiComm Thread 1194005648 is created.

DEBUG:ThdID1160451216 : Sent Spi Packet :
DEBUG:ThdID1160451216 : 0x07
DEBUG:ThdID1160451216 : 0x41 A
DEBUG:ThdID1160451216 : 0x74 t
DEBUG:ThdID1160451216 : 0x00
DEBUG:ThdID1160451216 : 0x00
DEBUG:ThdID1160451216 : 0x64 d
DEBUG:ThdID1160451216 : 0x53 S
DEBUG:ThdID1160451216 : 0x6D m
DEBUG:ThdID1160451216 : 0x43 C
DEBUG:ThdID1160451216 : 0x30 0
DEBUG:ThdID1160451216 : 0xF2 ò
DEBUG:ThdID1160451216 : 0x13
INF:ThdID1160451216 : Passed on Single PwrView Msg.

INF:ThdID1194005648 : Spi Thread is created by Protocol Stack.
spi mode: 0
bits per word: 8
max speed: 8000000 Hz (8000 KHz)

DEBUG:ThdID1194005648 : Trace SPI Synch Head 0x07

WARN:ThdID1194005648 : Wrong SPI Synch Head 0x7

DEBUG:ThdID1194005648 : Trace SPI Synch Head 0x41

DEBUG:ThdID1194005648 : Trace SPI Synch Head 0x74

DEBUG:ThdID1194005648 : Received SpiPktInPipe head: 0x07 At

DEBUG:ThdID1194005648 : received head of spi packet 8 Bytes

DEBUG:ThdID1194005648 : Received spi packet head 12 Bytes in total.

INF:ThdID1194005648 : At 0x0000 0x64 mC0ò 0x13F2, 0x51

DEBUG:ThdID1194005648 : Wait 4 GsnHost Tx Ack.

DEBUG:ThdID1194005648 : GsnHost Acked Cmd Tx.

DEBUG:ThdID1194005648 : Received Synch Head on SpiComm Bus.At

DEBUG:ThdID1194005648 : Received SpiComm Version on SpiComm Bus.0x0000

DEBUG:ThdID1194005648 : received data 8 Bytes

DEBUG:ThdID1194005648 : Received Spi head 12 Bytes in total on Spi Bus.

DEBUG:ThdID1194005648 : GsnHost Acked Rx.

DEBUG:ThdID1194005648 : Received Expected GsnHost Rly.

INF:ThdID1194005648 : At 0x0000 0x64 sA
DEBUG:ThdID1194005648 : Sent Spi Packet :
DEBUG:ThdID1194005648 : 0x0C

DEBUG:ThdID1194005648 : 0x41 A
DEBUG:ThdID1194005648 : 0x74 t
DEBUG:ThdID1194005648 : 0x00
DEBUG:ThdID1194005648 : 0x00
DEBUG:ThdID1194005648 : 0x64 d
DEBUG:ThdID1194005648 : 0x53 S
DEBUG:ThdID1194005648 : 0x73 s
DEBUG:ThdID1194005648 : 0x41 A
DEBUG:ThdID1194005648 : 0x00
DEBUG:ThdID1194005648 : 0xF2 ò
DEBUG:ThdID1194005648 : 0x13
INF:ThdID1194005648 : SpiComm Thread exit.

DEBUG:ThdID1160451216 : Trace SPI Synch Head 0x0C

WARN:ThdID1160451216 : Wrong SPI Synch Head 0xC

DEBUG:ThdID1160451216 : Trace SPI Synch Head 0x41

DEBUG:ThdID1160451216 : Trace SPI Synch Head 0x74

DEBUG:ThdID1160451216 : Received SpiPktInPipe head: 0x0C At

DEBUG:ThdID1160451216 : received head of spi packet 8 Bytes

DEBUG:ThdID1160451216 : Received spi packet head 12 Bytes in total.

INF:ThdID1160451216 : 0x0C At 0x0000 0x64 SsA
INF:ThdID1160451216 : PwrViewStk get valid reply from SpiComm.

DEBUG:ThdID1160451216 : Received PwrView Synch Head PV*VK-

DEBUG:ThdID1160451216 : received data 2 Bytes

DEBUG:ThdID1160451216 : Received PwrView head 4 Bytes in total.

INF:ThdID1160451216 : PwrViewStk get Msg and about to process.

INF:ThdID1160451216 : SpiComm Thd is created by PwrView Stk to do solicited report.
Thread 1160451216:SpiComm Thread 1202394256 is created.

DEBUG:ThdID1160451216 : Sent Spi Packet :
DEBUG:ThdID1160451216 : 0x07
DEBUG:ThdID1160451216 : 0x41 A
DEBUG:ThdID1160451216 : 0x74 t
DEBUG:ThdID1160451216 : 0x00
DEBUG:ThdID1160451216 : 0x00
DEBUG:ThdID1160451216 : 0x64 d
DEBUG:ThdID1160451216 : 0x53 S
DEBUG:ThdID1160451216 : 0x6D m
DEBUG:ThdID1160451216 : 0x43 C
DEBUG:ThdID1160451216 : 0x30 0
DEBUG:ThdID1160451216 : 0xF2 ò
DEBUG:ThdID1160451216 : 0x13
INF:ThdID1160451216 : Passed on Single PwrView Msg.

INF:ThdID1202394256 : Spi Thread is created by Protocol Stack.
spi mode: 0
bits per word: 8
max speed: 8000000 Hz (8000 KHz)

DEBUG:ThdID1202394256 : Trace SPI Synch Head 0x07

WARN:ThdID1202394256 : Wrong SPI Synch Head 0x7

DEBUG:ThdID1202394256 : Trace SPI Synch Head 0x41

DEBUG:ThdID1202394256 : Trace SPI Synch Head 0x74

DEBUG:ThdID1202394256 : Received SpiPktInPipe head: 0x07 At

DEBUG:ThdID1202394256 : received head of spi packet 8 Bytes

DEBUG:ThdID1202394256 : Received spi packet head 12 Bytes in total.

INF:ThdID1202394256 : At 0x0000 0x64 mC0ò 0x13F2, 0x51

DEBUG:ThdID1202394256 : Wait 4 GsnHost Tx Ack.

DEBUG:ThdID1202394256 : GsnHost Acked Cmd Tx.

DEBUG:ThdID1202394256 : Received Synch Head on SpiComm Bus.At

DEBUG:ThdID1202394256 : Received SpiComm Version on SpiComm Bus.0x0000

DEBUG:ThdID1202394256 : received data 8 Bytes

DEBUG:ThdID1202394256 : Received Spi head 12 Bytes in total on Spi Bus.

DEBUG:ThdID1202394256 : GsnHost Acked Rx.

DEBUG:ThdID1202394256 : Received Expected GsnHost Rly.

INF:ThdID1202394256 : At 0x0000 0x64 sA
DEBUG:ThdID1202394256 : Sent Spi Packet :
DEBUG:ThdID1202394256 : 0x0C

DEBUG:ThdID1202394256 : 0x41 A
DEBUG:ThdID1202394256 : 0x74 t
DEBUG:ThdID1202394256 : 0x00
DEBUG:ThdID1202394256 : 0x00
DEBUG:ThdID1202394256 : 0x64 d
DEBUG:ThdID1202394256 : 0x53 S
DEBUG:ThdID1202394256 : 0x73 s
DEBUG:ThdID1202394256 : 0x41 A
DEBUG:ThdID1202394256 : 0x00
DEBUG:ThdID1202394256 : 0xF2 ò
DEBUG:ThdID1202394256 : 0x13
INF:ThdID1202394256 : SpiComm Thread exit.

DEBUG:ThdID1160451216 : Trace SPI Synch Head 0x0C

WARN:ThdID1160451216 : Wrong SPI Synch Head 0xC

DEBUG:ThdID1160451216 : Trace SPI Synch Head 0x41

DEBUG:ThdID1160451216 : Trace SPI Synch Head 0x74

DEBUG:ThdID1160451216 : Received SpiPktInPipe head: 0x0C At

DEBUG:ThdID1160451216 : received head of spi packet 8 Bytes

DEBUG:ThdID1160451216 : Received spi packet head 12 Bytes in total.

INF:ThdID1160451216 : 0x0C At 0x0000 0x64 SsA
INF:ThdID1160451216 : PwrViewStk get valid reply from SpiComm.

INF:ThdID1073863104 : TcpListen socket closed after inactive time out 0 Bytes return.

DEBUG:ThdID1073863104 : No TCP Listen socket avaiable./n
INF:ThdID1160451216 : PwrView Stack thread exit.

Monday, February 14, 2011

GPIO Interrupt in Linux

[1] http://bec-systems.com/site/281/how-to-implement-an-interrupt-driven-gpio-input-in-linux
[2] Linux Device Drivers 3rd Edition.
[3] http://blackfin.uclinux.org/gf/project/uclinux-dist/forum/?_forum_action=ForumMessageBrowse&thread_id=23417&action=ForumBrowse
[4] http://docs.blackfin.uclinux.org/doku.php?id=linux-kernel:drivers:simple-gpio
[5] http://docs.blackfin.uclinux.org/doku.php?id=linux-kernel:drivers:gpio-sysfs
[6] http://docs.blackfin.uclinux.org/doku.php?id=linux-kernel:interrupts#gpio_interrupt_processing

[7] http://osdir.com/ml/android-platform/2010-01/msg00294.html
[8] http://linux.derkeiler.com/Mailing-Lists/Kernel/2009-06/msg04562.html Proposed PATCH for Gpiolib.c/h


irqs.h (x:\lpc3250\ltib-qs\rpm\BUILD\linux-2.6.34\arch\arm\mach-lpc32xx\include\mach)
irq.c (x:\lpc3250\ltib-qs\rpm\BUILD\linux-2.6.34\arch\arm\mach-lpc32xx)
phy3250.c (x:\lpc3250\ltib-qs\rpm\BUILD\linux-2.6.34\arch\arm\mach-lpc32xx) line202 static struct amba_device lpc32xx_ssp0_device

gpiolib.c (x:\lpc3250\ltib-qs\rpm\BUILD\linux-2.6.34\arch\arm\mach-lpc32xx)line 351
static struct lpc32xx_gpio_chip lpc32xx_gpiochip[] = {
{
.chip = {
.label = "gpio_p0",
.direction_input = lpc32xx_gpio_dir_input_p012,
.get = lpc32xx_gpio_get_value_p012,
.direction_output = lpc32xx_gpio_dir_output_p012,
.set = lpc32xx_gpio_set_value_p012,
.request = lpc32xx_gpio_request,
.base = LPC32XX_GPIO_P0_GRP,
.ngpio = LPC32XX_GPIO_P0_MAX,
.names = gpio_p0_names,
.can_sleep = 0,
},
.gpio_grp = &gpio_grp_regs_p0,
},


you cannot write an IRQ handler in userspace, it needs to be in kernel space.

What you will probably end up with is a loadable kernel module containing your interrupt handler and a pseudo-file interface to the variables it manipulates. The interrupt handler executes in its own context. The pseudo-file interface will execute in the kernel context, so be careful to protect the data it shares with the interrupt handler using the appropriate semaphores. You will use file operations at the pseudo-file as a bridge from your user-space program to the kernel space variables manipulated by the interrupt handler.[3]

You will find out when you get into the literature that pseudo-files are not real files and don't have the overhead of actually writing stuff in persistent store. They are ways of using read(), write() and ioctl() functions on file handles from user space to invoke functionality in the kernel. From your application you open a file handle to your pseudo-file and when you call these functions on it code you have added to the kernel springs to life. There is a framework that takes care of the transition from user- to kernel-space. Inside the kernel, your functions can share variables with your interrupt service routine.

This is all standard Linux stuff and you may find out more from general Linux forums (in addition to the right books). [3]



[root@GsnCommsModule user]# cat /proc/interrupts
CPU0
9: 44 - serial
16: 4760671 - LPC32XX Timer Tick
20: 1018101 - pl022
21: 0 - pl022
28: 103638 - DMA
29: 901999 - eth0
50: 0 - pnx-i2c
51: 0 - pnx-i2c
52: 0 - rtc-lpc32xx
59: 216 - ohci_hcd:usb1
63: 45 - pnx-i2c
Err: 0

Sunday, February 6, 2011

TV Program Collection.

Window 7 Home Premium
1 posts


[1] http://www.sevenforums.com/media-center/76521-tv-tuners-what-file-format-can-i-burn-dvd.html

---------------------------
Using Windows 7 Media Center = .WTV format
If you use Windows 7 Media Center Edition to run your tuners, then it will record the file in a new format: WTV. Not many converters know how to handle WTV since it is new to Windows 7. There is an option when you right click on a file, to convert it to .dvr-ms format, the older one that many of the converters DO support.

I right click and convert to .dvr-ms. I then load that into VideoRedo, remove commercials, and then save as .MPG. I then can use traditional DVD authoring apps to convert to .VOB and burn to DVD.

Regards,

Gayle Snedecor

-----------------------
Windows Live DVD Burner burns usable DVDs off of whatever format Media Center records them into... It sems to be a 2 pass operation, the first I assume is a conversion.

Use it with Movie Maker, which I use to remove commercials (or split where you want to), and you even get indexing to jump to where each split in your configuration is. After seeing what I can do with standard Windows tools, I am not bothering to upgrade my Nero. I rarely use the copy of version 8 that I have.

Wednesday, February 2, 2011

FW:中国“嵌入式系统之父”何立民细谈物联网

[1]http://www.esmchina.com/ART_8800113671_d534bb20_no.HTM?click_from=1000048340,8637877352,20110110,ESMCOL,ARTICLE_ALERT

绝大多数半导体集成电路元器件都会进入到嵌入式应用市场。随着嵌入式应用系统的SoC化,大部分半导体元器件与软件会以IP化方式进入到嵌入式应用市场。嵌入式系统应用将从基于半导体元器件的应用转向基于软、硬件平台的应用。即在一个通用的软硬件平台基础上开发出个性化产品。


ESMC:元器件和软件技术进步将对嵌入式应用设计带来什么影响?您如何看待多核处理器发展趋势?

何:嵌入式应用的产业模式应该是基于知识平台的扇形产业模式。最新元器件和软件技术的进步应体现在嵌入式产品平台的建设上。随着硬件平台的成熟与普及,软件技术会越来越显现出它的重要地位。

最早的多核技术出现在嵌入式系统应用中。目前,许多嵌入式处理器的内部总线都支持多核技术,多核技术会成为嵌入式应用的常规技术。有了支持多核技术的内部总线,多核软件技术不会有什么困难。



ESMC:您认为未来哪些内核将成为嵌入式市场的主流选择?为什么?

何:从上世纪70年代开始的MCU时代,一直是百花齐放的时代。ARM公司诞生后,局面有了变化,未来有可能形成ARM系列一枝独秀的局面,这是由ARM公司的产业性质与扇形产业生态体系所决定的。因为,在MCU的扇形产业生态体系中,ARM公司是居于半导体厂家之上的知识产权公司。在MCU知识产权领域ARM公司一家独大的情况下,ARM系列会逐渐成为MCU市场的主流选择。目前,ARM系列的主流形势业已出现,只要ARM公司的经营不出现意外,这种形势还会不断强化。