分享到plurk 分享到twitter 分享到facebook

版本 c6cdda39317e42385ce72c142289849d9786dd13

embedded/Lab5

Changes from c6cdda39317e42385ce72c142289849d9786dd13 to current

---
title: Lab5: RTOS modifications
toc: no
...

預期目標
-------
* 搭配`第五周</embedded/2012w4>`_課程進度
- 複習[第二周](/embedded/2012w2)、[第三周](/embedded/2012w3),與[第五周](/embedded/2012w5)進度
- 實際整合一個既有的程式碼到 FreeRTOS 環境中
- 體驗系統整合的流程及技術挑戰
- 為期末專題累積若干可重用的軟體元件

預先準備
-------
- 安裝 lcov
  * sudo apt-get install lcov

- 取得最新 Labs 內容 (與之前 [Lab3](/embedded/Lab3) 操作相似):

.. code-block:: prettyprint

    git clone git://gitcafe.com/embedded2012/Labs.git
    cd Labs/Lab-5


Code Coverage
--------------
- GNU code coverage tool `gcov<http://gcc.gnu.org/onlinedocs/gcc/Gcov.html>`_ is generally used to dump the coverage data when the program exits
- GNU code coverage tool [gcov](http://gcc.gnu.org/onlinedocs/gcc/Gcov.html) is generally used to dump the coverage data when the program exits
  * for some embedded systems or for server processes you need a means to dump coverage data of particular situations, i.e. when a client connects.

- Code quality analysis for embedded systems
  * Memory management with Valgrind
  * Code coverage testing with Gcov

- `Code Quality Analysis Toolset for Embedded Systems<http://www.eclipsecon.org/2008/sub/attachments/Code_Quality_Analysis_Toolset_for_Embedded_Systems.pdf>`_
- `Using gcov and lcov<http://www.slideshare.net/maguschen/using-gcov-and-lcov>`_
- [Code Quality Analysis Toolset for Embedded Systems](http://www.eclipsecon.org/2008/sub/attachments/Code_Quality_Analysis_Toolset_for_Embedded_Systems.pdf)
- [Using gcov and lcov](http://www.slideshare.net/maguschen/using-gcov-and-lcov)
- 新酷音輸入法系統的核心函式庫 (libchewing) 分析
  * http://kanru.info/chewing/lcov-check

執行時期輸出 gcov 資料
--------------------
- `Dumping gcov data at runtime - a simple example<https://www.osadl.org/fileadmin/dam/interface/docbook/howtos/coverage.pdf>`_
- [Dumping gcov data at runtime - a simple example](https://www.osadl.org/fileadmin/dam/interface/docbook/howtos/coverage.pdf)
- Instructions for invoking gcov

.. code-block:: prettyprint

  cd Lab-5/coverage
  make
  make run
  gcov hello

- Reference output

.. code-block:: prettyprint

  File ’hello.c’
  Lines executed:100.00% of 15
  hello.c:creating ’hello.c.gcov’

- Analyze gcov output

.. code-block:: prettyprint

    tail hello.c.gcov

- Reference output

.. code-block:: prettyprint

    1:
    34: new_action.sa_flags = 0;
    -:
    35:
    1:
    36: sigaction(SIGUSR1, NULL, &old_action);
    1:
    37: if (old_action.sa_handler != SIG_IGN)
    1:
    38:
    sigaction (SIGUSR1, &new_action, NULL);
    -:
    39:
    -:
    40: /* infinite loop - to exemplify dumping coverage data while program runs */
    186275468151:
    41: for(n = 0; ; n++)
    372550936302:
    42:
    i++;
    -:
    43:}

作業
----
- 研讀檔案系統 (romfs) 的實做方法
  * Lab-5/filesys

- 要求整合檔案系統到 FreeRTOS 中,並在 UART 顯示檔案系統 (romfs) 中 test.txt 的內容
- 最終預期在 filesys 目錄下,當 ``make qemuauto`` 執行後,會自動啟動 QEMU + GDB + FreeRTOS,並在 5 秒後 kill QEMU/GDB,最終的終端機畫面為 test.txt 的檔案內容
  * 在 QEMU 啟動的參數可改為 ``-serial stdio``,即可要求 QEMU 將 UART 導向到 Host 端的 stdio

- 提示:
  * 可在 Host 端先行測試與驗證以下檔案:
    - romfs.c
    - hash-djb2.c
    - filesystem.c
    - fio.c

  * 會需要修改到 linker script 以及 SRAM 的配置
  * 會需要補充基本的標準 C 函式,讓系統得以運作