2012/02/15

Device Driver, firmware, middleware, Software ArchitectureSoftware Framework,

Device Driver
對下控制硬體,對上提供介面,讓上層軟體可藉此和硬體溝通。
舉例:printer driver、display driver。

Firmware
指的是控制硬體的低階軟體。
比起Device Driver,定義其實比較不精確。舉例來說,控制電視的軟體叫Firmware,但其實裡面又可以分AP、Middleware、Driver、RTOS。
舉例:PC的BIOS、控制電視的軟體。

(Embedded) Middleware
存在於上層AP與底層OS之間的軟體或韌體,提供服務給AP使用。
舉例:Remote Procedure Call、Database Access Engine。

Software Architecture
定義系統中的軟體元件,以及元件之間彼此的關連性。

Software Framework
把常用的功能包裝起來,提供給AP使用,讓AP不需要處理其中繁瑣的問題。
舉例:各種Application Framework。

Multimedia Framework
提供多媒體功能的Software Framework。
舉例:Linux GStreamer、Microsoft Windows DirectShow、Java Media Framework。

參考
http://murphymind.blogspot.com/2009/05/firmwaremiddlewaremultimedia-framework.html

2012/02/14

這個wordpress論壇外掛- simple:press

1: 請先上simple:press的網站的下載網頁

http://simple-press.com/download/

 

 

2: 像我是wordpress 3.3.1版, 所以對應下載 simple:press 4.5.1


– 請依照 1. 2. 3. 4 (其中3可以先跳過)
– 1) 下載程式壓縮擋到plugin底下, 再unzip
– 2) 可以下載skin擋到 /wp-content/plugins/simple-press/styles/skins/
– 4) 可以找出繁中版 解壓縮到 /wp-content/plugins/simple-forum/languages/
 

 

2012/02/13

wordpress 好用的圖片切換 pic slider外掛

 

 

給大家關鍵字

1. Meteor Slides

這個介面還滿簡潔的

而且有後台有獨立的控制區域

但不支援外連, 必須使用自己上傳的特色圖片是一個缺點

 

 

 

2. Promotion Slider

我要外連圖片所以使用這款

還不錯, 可以直接設定外連圖的網址

還可以直接設定目標連結網址

 

2012/02/01

android的 low power: LP0 LP1 LP2

下面這個commit就是tegra的Low power概念整合到Linux kernel
後來應該被修改很多次,
其中的註解將lower power狀態說的很清楚

ARM: tegra: Add suspend support
http://nv-tegra.nvidia.com/gitweb/?p=linux-2.6.git;a=commit;h=d9c01b3ce93ce4ab3bff842f726a1924ffdef860

Tegra supports three low power modes that involve powering down the CPU.

LP2 powers down both CPU cores and the GICs, but leaves the core
peripherals, including the memory controller and the legacy
interrupt controller, enabled. The legacy interrupt controller
is used as the wakeup source, and any interrupt can wake the device.
LP2 can be used in idle.

LP1 is the same as LP2, but in addition turns off the memory
controller and puts the DDR memory in self-refresh. Any interrupt
can wake the device. LP1 could be used in idle if no peripherals
are doing DMA.

LP0 turns off everything in the SoC except the RTC and a power
management controller, both of which run off a 32 kHz clock.
The power management controller has 32 wake sources, all other
interrupts can not be used to wake from LP0.

These low power modes power-gate the main CPU complex, requiring a
full processor state save and restore from a reset vector.

Platform-specific data (power good times, PMU capabilities, etc.) must be
specified when registering the suspend operations to ensure that platform
power sequencing restrictions are maintained.

In both LP0 and LP1, SDRAM is placed into self-refresh. in order to safely
perform this transition, the final shutdown procedure responsible for

* turning off the MMU and L1 data cache
* putting memory into self-refresh
* setting the DDR pads to the lowest power state
* and turning off PLLs

is copied into IRAM (at the address TEGRA_IRAM_BASE + SZ_4K) at the
start of the suspend process.

In LP1 mode (like LP2), the CPU is reset and executes the code specified
at the EVP reset vector. Since SDRAM is in self-refresh, this code must
also be located in IRAM, and it must re-enable DRAM before restoring the
full context. In this implementation, it enables the CPU on PLLP, enables
PLLC and PLLM, restores the SCLK burst policy, and jumps to the LP2 reset
vector to restore the rest of the system (MMU, PLLX, coresite, etc.). The
LP2 reset vector is expected to be found in PMC_SCRATCH1, and is
initialized during system-bootup.

In LP0 mode, the core voltage domain is also shutoff. As a result, all
of the volatile state in the core voltage domain (e.g., pinmux registers,
clock registers, etc.) must be saved to memory so that it can be restored
after the system resumes. A limited set of wakeups are available from LP0,
and the correct levels for the wakeups must be programmed into the PMC
wakepad configuration register prior to system shutdown. On resume, the
system resets into the boot ROM,
and the boot ROM restores SDRAM and other
system state using values saved during kernel initialization in the PMC
scratch registers.

Resuming from LP0 requires the boot ROM to supply a signed recovery codeblob
to the kernel;
the kernel expects that the length and address of this blob
is supplied with the lp0_vec= command line argument; if not present, suspend-
to-LP0 will be disabled

For simplicity, the outer cache is shutdown for both LP0 and LP1; it
is possible to optimize the LP1 routine to bypass outer cache shutdown
and restart.

Includes fixes from:
Scott Williams
Aleksandr Frid
Vik Kasivajhula
Bharat Nihalani
James Wylder
Allen Martin

2012/01/31

擷取螢幕方便小軟體 PicPick

有時候鍵盤上的prtSrn會失效
這時候可以試看看 alt + prtSrn

如果還會失效
有可能有些檔案有防擷取功能

可以試看看PicPick

PicPick一個免費又好用的螢幕擷取軟體,它可以抓取全螢幕或是局部的畫面,而且操作也很簡單,還具備了一般最常用到的基本圖像處理功能。
軟體名稱:PicPick 3.0.7 免安裝版
軟體版本: 3.0.7
語言界面: 繁體中文
官方網頁:http://picpick.wiziple.net/
檔案下載:Download

2012/01/17

windows 8 : 兼具方塊磚與傳統介面

看到這台 lenovo未來概念機
結合平板與筆電的windows8系統
滿接近我會買的程度了

首先雖然 android已經有平板+鍵盤的概念
但是android本來就是設計給touch 手指滑動的介面
如果透過滑鼠或是實體鍵盤, 還是怪怪的
這是我個人觀感啦, 畢竟asus 變形平板還是賣得不錯, 但是我很少看到有人操作它的鍵盤呀….

轉頭看 windows 8
雖然只是介面多了metro的平板touch
也保留原本傳統介面
不知道是技術問題, 還是包袱太大無法甩開
但也是windows的價值- 使用者熟悉的操作介面

如果我買了這樣一台windows8 平板+鍵盤
最好是可拆式的
這樣我就可以外出的時候,
只需要帶著window8平板, 透過touch螢幕去控制
一回到家,
只需要把平板裝上實體鍵盤和滑鼠, 就變成一般筆電

當然CPU效能雖不用太好, 但是也不能太差
為什麼說不用太好, 因為之後就是雲端運算了
大多數的儲存裝置與運算都是上網就可以操作
為什麼說也不能太差,
因為雖然我不玩重度3D影像遊戲
但我也是會看影片, 玩玩基本的遊戲
所以CPU不可以太慢…

期待未來這樣的產品上市

http://chinese.engadget.com/2012/01/09/lenovos-ideapad-yoga-convertible-tablet-runs-windows-8-is-set/

2012/01/10

android 使用 linux LED driver 來控制GPIO 的LED行為

Linux Kernel’s LED driver
一般embedded system廠商控制LED都是透過GPIO的high/low操作
所以不會使用linux kernel內的預設LED功能, 而是自己寫獨立的driver
但是因為正統方式應該要配合Linux Kernel會比較有系統
kernel/drivers/leds


先到kernel作make menuconfig
將LED功能打開

+CONFIG_NEW_LEDS=y
+CONFIG_LEDS_CLASS=y
+
+#
+# LED drivers
+#
+CONFIG_LEDS_GPIO_PLATFORM=y
+CONFIG_LEDS_TRIGGERS=y


去kernel/driver/led底下
作出客製化的修改

Makefile

# LED Platform Drivers
+#++
+obj-y += leds-xxxx.o
+#–

從led-gpio.c 改寫成另一份檔案 led-xxxx.c

1: 可以改寫 led_dat->platform_gpio_blink_set = blink_set;
2: 改寫 gpio_led_work()
反正就是接到led的driver的API, 如led_on(), led_off()

Access介面node:

ledtrig-timer.c:78: static DEVICE_ATTR(delay_on, 0644, led_delay_on_show, led_delay_on_store);

順便提到, led-class: always implement blinking

在2010年時候, kernel/driver/leds
由 Johannes Berg 新增一個功能 led-class: always implement blinking
led-class: always implement blinking

—
Currently, blinking LEDs can be awkward because it is not guaranteed that
all LEDs implement blinking. The trigger that wants it to blink then
needs to implement its own timer solution.

Rather than require that, add led_blink_set() API that triggers can use.
This function will attempt to use hw blinking, but if that fails
implements a timer for it. To stop blinking again, brightness_set() also
needs to be wrapped into API that will stop the software blink.

As a result of this, the timer trigger becomes a very trivial one, and
hopefully we can finally see triggers using blinking as well because it’s
always easy to use.

Signed-off-by: Johannes Berg
Acked-by: Richard Purdie
Signed-off-by: Andrew Morton
Signed-off-by: Linus Torvalds

這是近年來 kernel/driver/leds 比較大的修改


如何注册gpio-led平台设备:
(如果是android系統, 應該是寫在 kernel/arch/arm/mach-tegra/board-xxxxx.c)

例子如下:
#define GPIO_LED3 138
#define GPIO_LED4 139

static struct gpio_led gpio_leds[] = {
{
.name = “led3”,
.default_trigger = “heartbeat”,
.gpio = GPIO_LED3,
.active_low = 1,
.default_state = LEDS_GPIO_DEFSTATE_OFF,
},
{
.name = “led4”,
.gpio = GPIO_LED4,
.active_low = 1,
.default_state = LEDS_GPIO_DEFSTATE_OFF,
},
};

static struct gpio_led_platform_data gpio_led_info = {
.leds = gpio_leds,
.num_leds = ARRAY_SIZE(gpio_leds),
};

static struct platform_device leds_gpio = {
.name = “leds-gpio”,
.id = -1,
.dev = {
.platform_data = &gpio_led_info,
},
};
最后调用platform_device_register(&leds_gpio)将LED设备注册到内核中。注册之前一定要保证编号为138和139的两个端口是可用的。
成功注册之后,系统中便会出现名为led3和led4的两个led_classdev了。由于是用gpio模拟led,所以对gpio-led设置的亮度,只要不是0就是全亮(gpio只有两个状态)。
对于可能睡眠的gpio,gpio-led会借助于工作队列去设置亮度,所以不用担心会被阻塞。


做完了以上的kernel部分
想要往上讓android系統可以控制光的話, 要使用android光系統

修改:
device/nvidia/common/liblights/lights.c 裡面的
open_lights() 和改寫 set_light_backlight()變成控制LED

修改:
frameworks/base/services/java/com/android/server/BatteryService.java 裡面的
updateLightsLocked()


參考:
led子系统
http://blog.csdn.net/yuanlulu/article/details/6438841

内核中led触发器实例
http://blog.csdn.net/yuanlulu/article/details/6438847

2012/01/04

Linux程式設計教學手冊 Beginning Linux Programming (第四版)


這本書的英文原文版在網路上可以下載 (自己google一下吧)

看了書本內容後
覺得這一本可以推薦給初學linux或是想更扎實linux基本功的人使用
不像一般的作業系統(OS)書本那樣理論, 這本書Linux程式設計教學手冊以linux作業系統的實例方式
讓讀者可以更快更精準的進入linux為平台的開發世界

據說原文版已經到第五版了 …

英文簡介:
introduce you to developing programs for Linux and other UIX-style operating systems. It discusses thoroughly all you need to be a good Linux programmer. The book. written by N Matthew and R Stones. encompasses a gamut of topics including both the basics of compiling programs. linking to libraries. terminal input and output. to more advanced topics like writing applications for the GNOME and KDE. data storing using MySQL, debugging etc. It tells you how to make the most of the standard Linux development tools and how to build graphical user interfaces for the X Windows system. The authors introduce appropriate programming theories for each topic with many practical examples and illustrations.
This is a good book for programmers and developers who want to enhance their skills in Linux to be able to create custom applications.

目錄:

第 一 章 Linux介紹
第 二 章 Shell程式設計
第 三 章 檔案處理
第 四 章 Linux的環境
第 五 章 終端機(terminal)
第 六 章 使用curses管理文字視窗
第 七 章 資料管理
第 八 章 MySQL
第 九 章 開發工具
第 十 章 除錯
第十一章 處理程序(process)和信號(signal)
第十二章 POSIX執行緒(thread)
第十三章 處理程序間的通訊:管線(pipe)
第十四章 號誌(semaphore)、共享記憶體(shared memory)、
第十五章 訊息佇列(message queue)
第十六章 網路程式設計:socket
第十七章 使用GTK+設計GNOME視窗程式
第十八章 使用QT設計KDE視窗程式
第十九章 標準化的Linux

博客來的書本介紹:

 基於前三版的成功經驗,第四版仍然延續教學的方式,一步步地引領讀者,讓讀者可以迅速在Linux和Unix相關的作業系統下開發程式。作者本身是相當有經驗的Linux程式設計員,所以讓此書可以涵蓋廣泛的主題,讓讀者暸解Linux的資源,讓讀者可以迅速開發程式。

  讀者將從基本的主題(編譯程式、聯結函式庫、處理終端機的輸出輸入),最後近入進階主題(設計GNOME和KDE的應用程式、使用MySQL儲存資料和除錯等)。在每個主題中,作者都會先介紹理論,隨即利用真實的程式範例,一步步的說明,引導讀者如何應用和實際開發程式。相信Linux的新鮮人也可以快速地開發出Linux的程式。

從本書您將學到什麼:

*使用標準的Linux C函式庫和其它工具。
*編譯標準的Linux開發工具。
*基本的系統呼叫(system calls)、檔案輸出與輸入、處理程序間通訊(interprocess communication)和shell設計。
*使用GTK+或Qt工具,設計圖形化的使用者介面。
*利用sockets,設計TCP/IP網路程式。
*設計相容於不同Linux發行版本的程式。

2012/01/03

nvidia 針對 I2C arbitration lost 提出作法 (android / tegra)

一種I2C會發生的issue, arbitration lost的中文可以稱作”仲裁損失”

若是發生這種狀態的話, 有一種workaround的方式處理, 就是將此I2C切換為GPIO 啟用/關閉後, I2C就變正常了

nvidia 也針對這個issue提出作法, 且以GPL授權發布在網路上

 

/* * arch/arm/mach-tegra/i2c_error_recovery.c * * Copyright (c) 2011, NVIDIA Corporation. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. */

 

arm: tegra: cardhu: Added I2C arbitration lost recovery mechanism

連結

Added the code for arbitration lost recovery mechanism for i2c
driver and Initialize gpio number for i2c clock and data as
part of platform data.

用 git cherry-pick 處理專案 push/pull request

A-B-C-D-E-F              (master)
………………….\
……………………G          (topic)

1: 先切出一個另外的branch (ex: topic)
2: 在這個branch (ex: topic)上做修改與撰寫程式碼
3: 在這個branch (ex: topic)上作: git add / git commit
4: 切回master 作: git cherry-pick xxxxxxxxxx / git push

 

 

 

git cherry-pick 321d76f # 只合併特定其中一個 commit。如果要合併多個,可以加上 -n 指令就不會先幫你 commit,這樣可以多 pick幾個要合併的 commit,最後再 git commit 即可。

2012/01/02

電子電路: VCC, VDD, VSS 定義與區分

在電子電路中,常可以看到VCC、VDD和VSS三種不同的符號,它們有什麼區別呢?

一、解釋

VCC:C=circuit 表示電路的意思, 即接入電路的電壓;

VDD:D=device 表示器件的意思, 即器件內部的工作電壓;

VSS:S=series 表示公共連接的意思,通常指電路公共接地端電壓。

二、說明

1、對於數字電路來說,VCC是電路的供電電壓,VDD是芯片的工作電壓(通常Vcc>Vdd),VSS是接地點。

2、有些IC既有VDD引腳又有VCC引腳,說明這種器件自身帶有電壓轉換功能。

3、在場效應管(或COMS器件)中,VDD為漏極,VSS為源極,VDD和VSS指的是元件引腳,而不表示供電電壓。

2011/12/28

gpio 隨手記

gpio_get_value()

=> __gpio_get_value()    定義在位置 kernel/drivers/gpio/gpiolib.c

 

2011/12/27

什麼是system call ?

System Call(系統呼叫)

    1. Def:

作為user program執行時與OS之間的溝通介面,當user program需要OS提供服務時,藉由呼叫system call(伴隨trap to monitor mode)通知OS,OS可依據system call ID查表,啟動service routine執行,得到結果,再傳回給user program,完成服務請求

    1. System Call種類:(P3-8~3-9)
      1. Process Control
      2. File Management
      3. Device Management
      4. Information Maintenance
      5. Communication
    2. system call的參數傳遞

有三種方法:

    1. 法一:利用registers儲存參數
      • 優:快速
      • 缺:不適用於參數多時。
        ∵register數目有限,參數不能太多
    2. 法二:將參數存在memory中的某個表格或Block,同時將此表格的起始位址存在一個register中,將此register傳給OS:
      • 優:適用於參數多時
        ∵ 可存參數較多
      • 缺:速度較慢
        ∵不限制參數的數目與長度
    3. 法三:利用system stack保存參數
      • push(保存)參數
      • OS利用POP取出參數
      • 不限制參數的數目及長度

 

Linux 驅動程式的大架構中,system call 是屬於第一層的架構;本文以一個 Linux 範例程式來展示 user application 與 Linux 驅動程式的關係。

作者/陳俊宏
www.jollen.org

System Call 與驅動程式的關係

System call 是 user application 與 Linux device driver 的溝通介面。

User application 透過呼叫 system call 來「叫起」driver 的 task,user application 要呼叫 system call 必須呼叫 GNU C 所提供的「wrapper function」,每個 system call 都會對應到 driver 內的一個 task,此 task 即是 file_operation 函數指標所指的函數。

 

Linux 驅動程式與 user application 間的溝通方式是透過 system call,實際上 user application 是以 device file 與裝置驅動程式溝通。要達成此目的,驅動程式必須建構在此「file」之上,因此 Linux 驅動程式必須透過 VFS(virtual file system)層來實作 system call。

一個簡單的範例

/dev目錄下的檔案稱為device file,是 user application 用來與硬體裝置溝通的介面。以下是一個簡單的範例:

int main(int argc, char *argv[]){    int devfd;    devfd = open("/dev/debug", O_RDONLY);    if (devfd == -1) { printf("Can't open /dev/debug\n"); return -1;    }    ioctl(devfd, IOCTL_WRITE, num);    close(devfd);    return 0;}

當我們打開/dev/debug檔案時,範例所呼叫open()函數會叫起支援/dev/debug驅動程式的對應函數;同理,我們對/dev/debug執行ioctl()函數時,也會叫起驅動程式的相對應函數。

範例中的open()與ioctl()函數皆是GLIBC裡的函數,「叫起」驅動程式函數的動作涉及user space與kernel space的切換,此動作藉由system call介面來完成。設計一個支援”/dev/debug”裝置的驅動程式則是Linux驅動程式設計師所要負責的工作。

–jollen

2011/12/20

程式碼可以用tag方式: 將vim當作source insight 來使用

Trace source at vim
幾個步驟大綱:

  • Introduce
  • Install
  • Setup
  • Tag Your Codebase
  • Text Editor
  • 進階版

[Introduce ]

•Source Insight
–Good IDE
–Good at Windows platform
–Bad Overload files
•But what if you …
–Non-Windows platform (BSD, Linux, …)
–Command line interface (CLI)
–Dislike brute force search : find / grep

[Tools ]

•vim
•ctags
•taglist

[Install ]

安裝vim:

• apt-get install vim

安裝ctags:

• apt-get install exuberant-ctags

然後到Taglist網站去下載zip檔

• Download taglist
–Steps:
• 下載後解壓縮該檔案
# unzip taglist_45.zip
Archive: taglist_45.zip
inflating: plugin/taglist.vim
inflating: doc/taglist.txt
• 將plugin及doc複製到家目錄的”.vim”這個目錄裏,如果不存在就建一個新的”.vim”

[setup ]

在vim裏設定功能鍵F7 – 用它來開啟/關閉taglist功能

• 在/etc/vim/vimrc裏加入下面1行

map <f7> :Tlist<CR>

[Tag Your Codebase ]
最後一個步驟,到你的原始程式目錄裏輸入
會把此目錄底下的檔案, 建立tag的資訊
所以如果很多檔案就會很久, 我通常都會縮小範圍

ctags -R -h ".h.c.cpp.java"

開啟vim xxx.c按F7
你就會看見如下圖的結果

按鍵功能:
F7 : 可以 Enable / Disable ctags
Ctrl + w + w: 可以Switch window

—

左視窗Left side (Tag List):
按Enter就會自動跳到相對應的函式或定義

—

右視窗Right side:
Ctrl + ] : 可以跳到游標所指function的implement 位置
Ctrl + t : 可以返回到剛剛的位置

[進階版 ]

•apt-get install cscope
•Download
–Unzip and put these plugin files to
•~ /.vim/plugin

•Modify /etc/vim/vimrc
” Open and close all the three plugins on the same time
‚nmap <F8> :TrinityToggleAll<CR>
” Open and close the srcexpl.vim separately
‚nmap <F9> :TrinityToggleSourceExplorer<CR>
ƒ
ƒ” Open and close the taglist.vim separately
„nmap <F10> :TrinityToggleTagList<CR>
…
…” Open and close the NERD_tree.vim separately
†nmap <F11> :TrinityToggleNERDTree<CR>
‡
‡set mouse=nv

[參考]: