2014年7月30日 星期三

Lubuntu 使用

調整

終端機

  • sakura https://newtoypia.blogspot.com/2018/09/sakura.html
    • 設定檔 ~/.config/sakura/sakura.conf。關閉最後分頁時產生或覆蓋。
  • lilyterm:按照說明下載 0.9.9.4 編譯安裝
    • 2021/09/01 Focal 需要 git 下載編譯安裝才可以。
    • 2020/10/08 for lubuntu 20.04 LTS 'Focal Fossa': 直接使用套件 Backspace 鍵、git grep 等不正常,下載 Testing 版編譯安裝可正常使用。
    • 2020/10/08-1:git 下載編譯安裝也可以
      git clone https://github.com/Tetralet/LilyTerm.git
      cd LilyTerm
      ./configure --prefix=/usr --sysconfdir=/etc/xdg
      make
      sudo make install
    • 2019/05/28 for 18.04 LTS 'Bionic Beaver':直接使用套件
    • 常常當掉
  • LXTerminal
  • QTerminal

開發環境

檔案軟體

  • pdf
    • Firefox
    • 安裝 adobereader (只有 32-bit 版本,所以需要安裝 i386 環境):到官網下載後,會自動出現 GDebi 來安裝[參考]。我安裝的是繁體中文版 AdobeReader 8.1.7-1.i386。另外有英文版 9.5.5
    • pdf 編輯:參考《Linux 下編輯 PDF 檔的工具》,我安裝 pdfshuffler
  • odp 簡報:sudo apt-get install libreoffice-impress
  • 影音編輯 AVIDEMUX:試過剪裁可用
  • chm:chmsee
  • 備份光碟
  • 編碼轉換:iconv -f big5 -t utf-8 big5.txt -o utf8.txt #big-5 轉 utf-8
  • 圖片列印
  • Typora 跨平臺的 Markdown 檔案編輯器 [官方連結](沒用過)
    wget -qO - https://typora.io/linux/public-key.asc | sudo apt-key add -
    sudo add-apt-repository 'deb https://typora.io/linux ./'
    sudo apt-get update
    sudo apt-get install typora
    
  • Joplin 跨平臺的筆記軟體,支援 Markdown 語法 [官方連結]。(沒用過)
    wget -O - https://raw.githubusercontent.com/laurent22/joplin/master/Joplin_install_and_update.sh | bash
  • HackMD 是台灣人開發的線上共筆軟體,不需要安裝,支援 Markdown 語法,官方連結
  • 尚未使用
    • TMidity++:Midi
    • Tracker:動態影像分析軟體
    • ImageJ:靜態影像分析軟體
    • SciDAVis:科學數據分析軟體
    • GeoGebra:函數繪圖軟體
    • Stellarium:星座盤
    • yEd:流程圖繪製軟體
    • Blender:3D 建模軟體
    • Freeplane:心智圖軟體

網路服務

安裝工具軟體
  • VirtualBox 虛擬電腦
  • 虛擬 Windows 作業系統:wine與ie
  • gnome screenshot:做螢幕區塊擷取
  • 星座盤 
參考來源
  1. Lubuntu 13.10 安裝與使用
其它參考:
最後更新 20201008

2014年7月23日 星期三

AM335x Programmable Realtime Unit

AM3356/7/8/9 (如 BeagleBone Black) 都有 PRU-ICSS (Programmable Real-Time Unit Subsystem and Industrial Communication Subsystem)。

  • Supports Protocols such as EtherCAT®, PROFIBUS, PROFINET, EtherNet/IP™, and More
  • 2x PRU:兩個額外有自己的程式碼和記憶體的處理器,可用來作接近硬體的、即時的工作,減輕主處理器的負擔。
    • 32-Bit Load/Store RISC Processor @ 200 MHz
    • 8KB of Instruction RAM With Single-Error Detection (Parity)
    • 8KB of Data RAM With Single-Error Detection (Parity)
    • Single-Cycle 32-Bit Multiplier With 64-Bit Accumulator
    • Enhanced GPIO Module Provides Shift-In/Out Support and Parallel Latch on External Signal
  • 12KB of Shared RAM With Single-Error Detection (Parity)
  • Three 120-Byte Register Banks Accessible by Each PRU
  • Interrupt Controller (INTC) for Handling System Input Events
  • Local Interconnect Bus for Connecting Internal and External Masters to the Resources Inside the PRU-ICSS
  • 內部週邊
    • 1x UART Port With Flow Control Pins, Supports up to 12 Mbps
    • 1x Enhanced Capture (eCAP) Module
    • 2x MII Ethernet Ports that Support Industrial Ethernet, such as EtherCAT
    • 1x MDIO Port

應用

2014年7月16日 星期三

One AVR Web Server

http://www.theresistornetwork.com/2013/03/fun-with-embedded-http-servers.html
http://hackaday.com/2013/04/03/embedded-web-server-is-all-about-clever-formatting/ 
  • 硬體:Olimex MOD-IO development board (ATmega16 CPU) + ENC28J60 Ethernet controller (SPI 界面)
  • 使用 TuxGraphics TCP/IP stack,包含 Web Server
  • 壓縮網頁資料 (yui-compressor + gzip) 給 C 使用
    %.css.h: %.css
        yui-compressor --type css $^ > $^.min
        gzip -c $^.min > $^.gz
        xxd -i $^.gz | sed -e 's/.\[\]\ =/\[\]\ PROGMEM\ =/g' | sed -e 's/unsigned/const/g' > $@
        rm -f $^.gz $^.min
    
  • 由於只有 1kB RAM,限制 response 大小大約 700 bytes.
  • 顯示 AVR logo:用 Inkscape 縮小 SVG 檔,並用 vim stripped the rest of the cruft
  • 用 AJAX 動態取得 JSON 格式的 Uptime、Total HTTP Requrest 及 Relay Status
  • HTTP authentication 以及控制 relay
相關文章:Eembeddedd Web Server

2014年7月14日 星期一

libubox runqueue

主要是三個函數:runqueue_init()、runqueue_task_add()、runqueue_process_add()

runqueue_init():初始化

runqueue_task_add():將 task 加到 runqueue,並在 1 ms 後嘗試執行,可限制最多同時跑多少 task,也可以限制 task 最久跑多久。嘗試執行時 runqueue 已經空了,沒有 task 待執行或執行中,1 ms 後執行 empty_cb()。

runqueue_process_add():讓 runqueue 知道 task 結束,方便啟動下個 task。

應用參考:OpenWrt /sbin/init

相關:safe_list、uloop
參考來源:libubox

libubox uloop

uloop 是 libubox 的一部份,其功能包括
  • timeout:再多久執行指定函數
  • 執行 child process,結束時執行指定的函數
  • fd 事件發生時執行指定函數。(使用 kqueue 或 epoll)
uloop 使用
  1. 呼叫 uloop_init() 初始化
  2. 註冊 timeout、process、或 fd
    • timeout 透過 uloop_timeout_add() 或 uloop_timeout_set() 註冊,uloop_timeout_cancel() 取消 timeout,uloop_timeout_remaining() 查詢多久 timeout
    • uloop_process_add() 註冊 child process
    • uloop_fd_add() 註冊 fd,uloop_fd_delete() 移除
  3. 呼叫 uloop_run() 執行 uloop 工作迴圈,直到取消。可透過 uloop_end() 取消或用 SIGINT 或 SIGTERM kill
  4. 取消執行後可呼叫 uloop_done() 清掉所有註冊的 timeout 及 child process
應用參考:

2014年7月9日 星期三

OpenWrt boot

OpenWrt 的開機可以分成 bootloader、kernel、preinit、init 階段。

bootloader 階段

  • 硬體初始化及測試
  • 載入 kernel image:Downloading Kernel Image and Initial Ram Disk: 從 flash 或網路載入到記憶體, 需要時作解壓縮。
  • 設定 Linux kernel 需要的開機參數。
  • 跳到 Kernel Entry Point,控制權轉移到 Linux kernel。

kernel 階段

一般 Linux 電腦開機在 kernel 階段最後會去執行 /sbin/init,而 OpenWrt 是去執行 /etc/preinit,進入 preinit 階段。

preinit 階段

/etc/preinit 是 shell script,會載入 /lib/preinit 下更多的 shell script 依序執行,最後掛載根目錄後會去執行 busybox 提供的 /sbin/init,進入 init 階段。

init 階段

/sbin/init 執行哪些程式,由 /etc/inittab 決定。/etc/inittab 有四的欄位,格式是 tty:runlevel;action:command,其中 tty 是 optional,runlevel 沒用到,action 決定執行順序及時機,command 是執行的指令。init 依據 action,依序執行 sysinit → wait → once 的指令,然後進入無窮迴圈執行不斷重新執行 respawn 跟 askfirst 的指令。askfirst 跟 respawn 的差別只是多了等候連接的 tty 按 Enter。但在 NOMMU 處理器無法等候,所以兩者是一樣的。除了上述所提 action 外,還有其它 action:ctrlaltdel (SIGINT 時執行)、shutdown (SIGUSR1, SIGTERM, SIGUSR2 時執行) 跟 restart (SIGQUIT 時執行)。ctrlaltdel 通常設成執行重開機,restart 會重開機,而 shutdown 可能重開機或者關閉電源。

OpenWrt 的 inittab 依處理器或板子不同而有所不同,基本上大概的樣子是
::sysinit:/etc/init.d/rcS S boot
::shutdown:/etc/init.d/rcS K shutdown
ttyS0::askfirst:/bin/ash --login
tty1::askfirst:/bin/ash --login

所以開機時執行 /etc/init.d/rcS S boot,也就是依序執行 /etc/rc.d/ 下,所有 S 開頭的程式裡的 boot() 功能。/etc/rc.d/ 下的程式是連結到 /etc/init.d/ 下的命令檔,這些命令檔大多會帶入 /etc/rc.common,提供預設的動作函數,boot() 預設是執行 start()。也會帶入 /lib/functions.sh (一些共同的函數,包括 config_ 開頭的函數)、/lib/config/uci.sh (uci_ 開頭存取 uci 的函數)、及 /lib/functions/service.sh (使用 busybox start-stop-daemon 提供 service_ 開頭的函數)。

第一個執行的 rc.d 程式通常是 boot,再來可能是 sysctl、ubus、firewall、network

設定

OpenWrt 的設定用 UCI,並提供標準的命令檔函數以便於存取,放在 /etc/functions.sh (也就是 /lib/functions.sh)。

. /etc/functions.sh #載入

config_load config_file # 載入設定檔

如果要特別的回呼,要在 config_load 之前設好 config_cb() 或 option_cb()。config_cb() 每遇到一個新 section 或設定檔載入完畢時呼叫,有兩個參數 -- section type 跟 section name。option_cb() 每個 option 或 list 時呼叫,一樣有兩個參數 -- option name 跟 option value。config_cb() 裡可以修改 option_cb(),讓每個 section 可以有不同的 option_cb()。變數 CONFIG_SECTION 紀錄目前 section 的 ID。

以下對記憶體處理:
  • config_foreach function-called [section-name [function-args ...]]
    • 補充 function-called 的參數
  • config_get variable-stored section-id option-name [default-value]
  • config_set section-id option-name value
  • config_list_foreach section-id  list-name function-called [function-args...]
    • 補充 function-called 的參數
  • config_get_bool:跟 config_get 一樣,多了把 on, true, enabled 取得為 1
參考:http://wiki.openwrt.org/doc/devel/config-scripting

Wi-Fi 啟用

Wi-Fi 預設的設定檔是 /etc/config/wireless。/sbin/wifi 啟用 Wi-Fi,有 detect、up、跟 down 三種動作。在開機 init 階段的 boot 時執行 /sbin/wifi detect,產生設定檔;network 時的 start() 最後執行 /sbin/wifi down 跟 /sbin/wifi up 動作來啟用 Wi-Fi。

/sbin/wifi 整理:
  • 三種動作
    • detect:偵測 Wi-Fi,產生 /etc/config/wireless
    • down:停用 Wi-Fi
    • up (沒指定或其它):啟用 Wi-Fi
  • 載入共用函數 /lib/functions.sh。
  • 載入 /lib/wifi/ 下所有的 .sh:每個 .sh 檔是跟 Wi-Fi 驅動程式搭配,會附加 driver 名稱到 DRIVERS 變數,讓 /sbin/wifi 知道有什麼 driver,並提供 detect_driver()、scan_driver()、disable_driver()、enable_driver() 函數,為完成上述三種動作所需要。
  • 執行 scan_wifi 來載入設定檔。設定檔有一些 type 為 wifi-device 跟 wifi-iface 的 section,一個 wifi-device 可以有多個 wifi-iface。載入過程中,會將 wifi-device 的 section-name 附加到 DEVICES 變數,並把其對應的 wifi-iface 的 section-name 設到 wifi-device 的 vifs 選項,以便後續利用
  • 最後依動作執行對應的函數。
  • 提供的函數
    • find_net_config()
    • bridge_interface()
    • prepare_key_wep()
    • wifi_fix_hwmode()
    • wifi_updown:動作 up 或 down 時執行
      • down → wifi_updown disable→對每個 DEVICES 的 type,也就是 driver 名稱,執行 scan_driver() 跟 disable_driver()
      • up (沒指定或其它)→wifi_updown enable→會先執行 wifi_updown disable,並重新 scan_wifi。如果設定不是 disabled,執行 scan_driver() 跟 enable_driver()
    • wifi_detect:動作 detect 執行的函數, 對每個 DRIVERS 執行 detect_driver(),產生設定檔。最終設定檔會存到 /etc/config/wireless
    • start_net ifname network vifmac:啟用界面,將網路界面 ifname 連到 network 網域。vifmac 作用待研究。
    • set_wifi_up()
    • set_wifi_down
    • scan_wifi
  • 執行 scan_wifi 來載入預設的 Wi-Fi 設定檔
/ib/wifi/*.sh 整理
  • 附加 driver 名稱到 DRIVERS 變數,讓 /sbin/wifi 知道有什麼 driver
  • 提供的函數
    • detect_driver():只有 detect 動作用到,偵測 Wi-Fi 界面,輸出設定檔
    • scan_driver():up 跟 down 動作都會用到,掃描 wifi-iface 的 mode,設定 ifname。wifi-device 設 phy 及重設 vifs
    • enable_driver():
    • disable_driver():
/etc/config/wireless 範例:
config wifi-device radio0 # section name 給 wifi-iface 的 device 選項對應用
        option type     driver # driver 名稱,對應函數 detect_driver(), scan_driver(), enable_driver(), disable_driver()
        option channel  11
        option disabled 1 # 非必要,是否 disabled

config wifi-iface
        option device   radio0 # 對應到 wifi-device
        option mode   ap # 運作模式
        option network  lan # 搭到哪個網域使用
        option ssid     SSID
        option encryption none
完整的 wireless 設定參考 http://wiki.openwrt.org/doc/uci/wireless

參考來源

busybox init/init.c

FT2232D


gnICE (v1.0)
gnICE+ (v1.1, v1.2)
GPIO 控制
其他
  • FT2232D 的前身是 lead free 的 FT2232C -- FT2232L,加上 CPU-type FIFO interface mode 及工業操作溫度。還有更新的 FT2232H 支援 Hi-speed USB。
  • 檔案備份

SIP header Via

所有 SIP 訊息 都要有 Via,縮寫 v。一開始的 UAC 和後續途經的每個 proxy 都會疊加一個 Via 放傳送的位址,依序作為回應的路徑。 格式 sent-protocol sent-by [ ;branch= branch ][ ; 參數 ...] s...