Wednesday, February 11, 2015
Linux I2C Driver
linux-source/Documentation/i2c/ has lot of the information you'd need. .../writing-clients.txt is a good place to start.
Have a look at the online version:
https://www.kernel.org/doc/Documentation/i2c/writing-clients
There is an okay sort of a tutorial at:
http://renjucnair.blogspot.ca/2012/01/writing-i2c-client-driver.html
Here is a good commentary on someone writing an i2c driver and has a tutorial feel to it:
http://www.embedded-bits.co.uk/2009/i2c-in-the-2632-linux-kernel/
Here is some sample code:
http://code.google.com/p/ldd-templates/source/browse/drivers/i2c/sample-i2c-client.c
Reference
http://stackoverflow.com/questions/16728587/i2c-driver-in-linux
Saturday, December 27, 2014
Getopt
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int
main (int argc, char **argv)
{
int aflag = 0;
int bflag = 0;
char *cvalue = NULL;
int index;
int c;
opterr = 0;
while ((c = getopt (argc, argv, "abc:")) != -1)
switch (c)
{
case 'a':
aflag = 1;
break;
case 'b':
bflag = 1;
break;
case 'c':
cvalue = optarg;
break;
case '?':
if (optopt == 'c')
fprintf (stderr, "Option -%c requires an argument.\n", optopt);
else if (isprint (optopt))
fprintf (stderr, "Unknown option `-%c'.\n", optopt);
else
fprintf (stderr,
"Unknown option character `\\x%x'.\n",
optopt);
return 1;
default:
abort ();
}
printf ("aflag = %d, bflag = %d, cvalue = %s\n",
aflag, bflag, cvalue);
for (index = optind; index < argc; index++)
printf ("Non-option argument %s\n", argv[index]);
return 0;
}
Here are some examples showing what this program prints with different combinations of arguments:
% testopt
aflag = 0, bflag = 0, cvalue = (null)
% testopt -a -b
aflag = 1, bflag = 1, cvalue = (null)
% testopt -ab
aflag = 1, bflag = 1, cvalue = (null)
% testopt -c foo
aflag = 0, bflag = 0, cvalue = foo
% testopt -cfoo
aflag = 0, bflag = 0, cvalue = foo
% testopt arg1
aflag = 0, bflag = 0, cvalue = (null)
Non-option argument arg1
% testopt -a arg1
aflag = 1, bflag = 0, cvalue = (null)
Non-option argument arg1
% testopt -c foo arg1
aflag = 0, bflag = 0, cvalue = foo
Non-option argument arg1
% testopt -a -- -b
aflag = 1, bflag = 0, cvalue = (null)
Non-option argument -b
% testopt -a -
aflag = 1, bflag = 0, cvalue = (null)
Non-option argument -
An option character in this string can be followed by a colon (‘:’) to indicate that it takes a required argument. If an option character is followed by two colons (‘::’), its argument is optional.
This optarg is set by getopt
to point at the value of the option argument, for those options that accept arguments.
Reference
[1] http://www.gnu.org/software/libc/manual/html_node/Using-Getopt.html
[2] http://www.gnu.org/software/libc/manual/html_node/Example-of-Getopt.html
Wednesday, December 24, 2014
MAKEFILE built-in function
How to implement built-in function as below
Text-processing function
https://www.gnu.org/software/make/manual/html_node/Text-Functions.html#Text-Functions
$(patsubst %.c,%.o,x.c.c bar.c)
Result: ‘x.c.o bar.o’
$(sort foo bar lose)
Result:‘bar foo lose’
$(word 2, foo bar baz)
Result:‘bar’
Filename manipulate function
https://www.gnu.org/software/make/manual/html_node/File-Name-Functions.html
$(dir src/foo.c hacks)
Result:‘src/ ./’
$(notdir src/foo.c hacks)
Result:‘foo.c hacks’
$(suffix src/foo.c src-1.0/bar.c hacks)
Result:‘.c .c’
$(addprefix src/,foo bar)
Result:‘src/foo src/bar’
Friday, December 19, 2014
linux command – grep
dmesg | grep -i usb
[option]
“-i” ignore the case.
cat /var/log/dmesg | less
Reference
http://manpages.ubuntu.com/manpages/utopic/man1/dmesg.1.html
Thursday, December 4, 2014
scatter
Reference
http://www.keil.com/support/man/docs/uv4/uv4_dg_l51loc.htm
Keil BL51 Locate
http://www.keil.com/support/man/docs/armlink/armlink_pge1362075691804.htm
http://www.keil.com/forum/14954/scatter-file/
http://www.keil.com/support/man/docs/armlink/armlink_pge1362075656353.htm
http://www.keil.com/support/docs/3237.htm
http://www.keil.com/support/man/docs/ARMCC/ARMCC_chr1359124982450.htm
Monday, December 1, 2014
Understanding lvalues and rvalues in C and C++
lvalues stands for left-values and rvalues is right-values[2]
lvalue is an expression referring to an object
Data storage for rvalues describes in ASM.[1]
mov #1, n
we could see 1 is a contant number, not a variable. the rvalue 1 never appears as an object in the data space.
Reference
[1] http://ieng9.ucsd.edu/~cs30x/Lvalues%20and%20Rvalues.htm
[2] http://www.c4learn.com/c-programming/c-r-value-expression/
[3] http://eli.thegreenplace.net/2011/12/15/understanding-lvalues-and-rvalues-in-c-and-c experitment
Register Transfer Level Design with Verilog (1) [ebook]
設計程式之所以有趣不外乎是它的千變萬化,同樣的結果卻有不同的寫法。 但這些不同寫法當中也並沒有分誰對誰錯,也沒有制定標準來規範何事該用何解。 這也就是我們設計者的珍貴!! [1] Primitive Instantiations 在Verilog中最基本的邏輯...
-
在之前的文章中有提到UEFI的系統大概可以區分兩個階段,起初是Boot Service再來就是Runtime Service(RS)如紅框所涵蓋的程序都可以稱為RS。 區分這兩個Service最重要的一項轉類點函數為 ExitBootServices()...
-
Handle的類型主要可以區分為這三種 executable image (drivers, application) – Agent Handles devices (network controller, hard drive partitions) – Cont...
-
Shell> devices 透過這個指令可以觀察目前UEFI內有幾個硬體被控制著。也提供不少的訊息給設計者,如 TYPE是說明此設備是 [R] Root Controller [B] Bus Controller [D] Device Controller ...