這篇文章受密碼保護,請輸入密碼後查看內容。
- Nov 03 Wed 2010 10:32
-
洛克斯
- Nov 01 Mon 2010 13:05
-
const modifier
const的位置決定修飾的對像,如 char const *p表示修飾的是*p,所以不能用*p='a',而p這個address是可以修改的,比如p=&q。
如果是char* const p,則表示修飾的是p這個address。所以可以用*p='a',而不能p=&q。這兩個是相反的例子。
再來是都不能修改的狀況,const char* const p,則*p跟p都不能再賦值了。
最後const是左修飾,所以 const char跟 char const是一樣的意思。
如果是char* const p,則表示修飾的是p這個address。所以可以用*p='a',而不能p=&q。這兩個是相反的例子。
再來是都不能修改的狀況,const char* const p,則*p跟p都不能再賦值了。
最後const是左修飾,所以 const char跟 char const是一樣的意思。
- Oct 28 Thu 2010 15:41
-
(LDM) linux device model (三) asoc driver registration
先從幾個重要的structure 看起,並以wm8580為例,這些屬於platform driver,請見smdkc100_wm8580.c:
platform device註冊
snd_soc_device: audio subsystem
這個結構是platform device註冊最主要的,註冊就是利用這個結構來填platform drvdata。
platform device註冊
snd_soc_device: audio subsystem
這個結構是platform device註冊最主要的,註冊就是利用這個結構來填platform drvdata。
- Oct 27 Wed 2010 10:38
-
scope
variable的modifier定義其特性,這次討論static與extern:
static variable: 其值是會保留在記憶體的,不隨著離開其scope而消失 (只initialize一次)。
extern variable: 該變數已在其他地方(包括其他file)被定義過了,存取的方式是先宣告為extern,再來存取。
看例子:
static variable: 其值是會保留在記憶體的,不隨著離開其scope而消失 (只initialize一次)。
extern variable: 該變數已在其他地方(包括其他file)被定義過了,存取的方式是先宣告為extern,再來存取。
看例子:
- Oct 26 Tue 2010 16:31
-
unsigned vs signed
已知
1. int 4 bytes = 32 bits, char 1 byte = 8bits
2. 負數以2's complement 儲存
3. %d是signed integer %u是unsigned integer。做型別轉換時,需要做sign extention,方式為不足的bit補其符號(即正補0,負補1)。
1. int 4 bytes = 32 bits, char 1 byte = 8bits
2. 負數以2's complement 儲存
3. %d是signed integer %u是unsigned integer。做型別轉換時,需要做sign extention,方式為不足的bit補其符號(即正補0,負補1)。
- Oct 22 Fri 2010 12:24
-
(LDM) linux device model (二)
新增一個bus的範例程式如下,這個範例新增了一個bus叫testbus。這是一個空的bus,只有基本的sysfs entry,沒有任何的device和driver註冊到該bus,所以/sys/bus/testbus下的devices和drivers folder都是空的。
範例程式很短,一目了然,不需要說明。
空的bus
#include <linux/module.h>
#include <linux/kobject.h>
#include <linux/device.h>
static int test_bus_match(struct device* device, struct device_driver* driver);
extern struct bus_type test_bus_type;
struct bus_type test_bus_type =
{
.name = "testbus",
.match= test_bus_match
};
EXPORT_SYMBOL(test_bus_type); //export這個structure,若有driver要掛上可以引用
static int test_bus_match(struct device* device, struct device_driver* driver)
{
printk(" in bus match\n");
return 0;
}
EXPORT_SYMBOL(test_bus_match);
static int test_bus_init(void)
{
int res;
if((res = bus_register(&test_bus_type)))
{
if(!res )
{
bus_unregister(&test_bus_type);
printk("res=%d\n",res);
}
return res;
}
return 0;
}
static void test_bus_exit(void)
{
bus_unregister(&test_bus_type);
}
MODULE_LICENSE("GPL");
module_init(test_bus_init);
module_exit(test_bus_exit);
範例程式很短,一目了然,不需要說明。
空的bus
#include <linux/module.h>
#include <linux/kobject.h>
#include <linux/device.h>
static int test_bus_match(struct device* device, struct device_driver* driver);
extern struct bus_type test_bus_type;
struct bus_type test_bus_type =
{
.name = "testbus",
.match= test_bus_match
};
EXPORT_SYMBOL(test_bus_type); //export這個structure,若有driver要掛上可以引用
static int test_bus_match(struct device* device, struct device_driver* driver)
{
printk(" in bus match\n");
return 0;
}
EXPORT_SYMBOL(test_bus_match);
static int test_bus_init(void)
{
int res;
if((res = bus_register(&test_bus_type)))
{
if(!res )
{
bus_unregister(&test_bus_type);
printk("res=%d\n",res);
}
return res;
}
return 0;
}
static void test_bus_exit(void)
{
bus_unregister(&test_bus_type);
}
MODULE_LICENSE("GPL");
module_init(test_bus_init);
module_exit(test_bus_exit);
- Oct 21 Thu 2010 16:59
-
(LDM) linux device model (一)
循著前人的分享,為自己的理解做記錄。
三角關係
Linux Device Model由bus, device, driver所組成。其關係為:
bus是cpu與device溝通的橋樑,而driver賦與device行為的能力。因此有人說,device是男人,driver是女人,而bus則是媒人。媒人有match的功能,讓男人與女人彼此
認識。在coldplug的時代,男人先登記後,由媒人去match女人。而後來的hotplug,則讓女人先提供資訊,讓後來有意願的男人match。
device與driver對bus而言,就沒有一定誰先誰後了。
三角關係
Linux Device Model由bus, device, driver所組成。其關係為:
bus是cpu與device溝通的橋樑,而driver賦與device行為的能力。因此有人說,device是男人,driver是女人,而bus則是媒人。媒人有match的功能,讓男人與女人彼此
認識。在coldplug的時代,男人先登記後,由媒人去match女人。而後來的hotplug,則讓女人先提供資訊,讓後來有意願的男人match。
device與driver對bus而言,就沒有一定誰先誰後了。
- Oct 20 Wed 2010 19:04
-
__init: 開機完成後釋放記憶體
build-in module 的init function會加上__init這個字樣,這是指當kernel做完這個module_init function後,即可釋放其resource,因為到下一次開機之前都不會再執行到了。其定義在include/linux/init.h:
#define __init __section(.init.text) __cold notrace
這是讓gcc知道當compile時,把這個fucntion放到text section。當initialize完成後即可釋放memory。開機完成後,看到的Freeing unused kernel memory: xxx k就是釋放的結果。
同樣的,在module_exit的前面也要加上__exit。
#define __init __section(.init.text) __cold notrace
這是讓gcc知道當compile時,把這個fucntion放到text section。當initialize完成後即可釋放memory。開機完成後,看到的Freeing unused kernel memory: xxx k就是釋放的結果。
同樣的,在module_exit的前面也要加上__exit。
- Oct 18 Mon 2010 14:23
-
vermagic

系統整合時,常常會跟driver有關,不管是port driver還是拿廠商build好的driver。開發環境不同時,很可能會有driver跟 kernel版號不同的情況,而產生類似"-1 Invalid module format" 這樣的錯誤訊息。如果kernel 版本差別不大,是有機會可以modprobe成功,看看結果如何。而不用卡在版號不同,插不進去的loop裡。
在kernel裡,先disable modules version: