====== ビルトインアプリケーションの追加 ====== [[xg_series_devel:boot_firmware:start]] までで、NuttX のシェル(NuttShell) が起動するところまで確認できました。\\ NuttX は便利なシェルが利用できますので、アプリケーションの開発方法としては、 * アプリケーションは各機能を **Task/Thread** に小分けにして、**プロセス間通信**((MessageQueue, Mutex, Semaphore などが利用できます。[[http://nuttx.org/Documentation/NuttxUserGuide.html|こちら]]を参照してください。)) で全体の機能を実現 * 各機能を実装したタスクを **NuttShellから起動** するビルトインアプリケーションを実装 * 起動時に NuttShell から各タスクを自動起動する (/etc/init.d/rcS から)(([[http://nuttx.org/Documentation/NuttShell.html#startupscript|こちら]]を参照)) というふうに実装するとデバッグが容易になります。 そこで、まずはビルトインアプリケーションをどのように作るか、について記載します。 ※ マニュアルは [[https://cwiki.apache.org/confluence/display/NUTTX/Custom+Application+Directories]] にあります。 \\ ===== 準備 ===== NuttX のソースを clone した2つのディレクトリのうち、アプリケーションは **apps/** ディレクトリ以下に作成します。\\ 編集したあとでも元に戻せるよう、新しい作業用ブランチを作成します。 develop:~/src/NuttX_XG50$ cd apps/ develop:~/src/NuttX_XG50/apps$ git checkout -b hello_test Switched to a new branch 'hello_test' \\ ===== 作業 ===== ==== ディレクトリ、ファイルの追加 ==== **apps/** ディレクトリ以下は、下のようになっています。 develop:~/src/NuttX_XG50/apps$ ls -lnF total 260 -rw-rw-r-- 1 1000 1000 4166 3月 7 09:15 Application.mk drwxrwxr-x 14 1000 1000 4096 3月 8 14:53 BearSSL/ -rw-rw-r-- 1 1000 1000 8793 3月 7 09:15 COPYING -rw-rw-r-- 1 1000 1000 145150 3月 7 09:17 ChangeLog.txt -rw-rw-r-- 1 1000 1000 2797 3月 7 09:15 Directory.mk -rw-rw-r-- 1 1000 1000 3095 3月 7 09:15 Make.defs -rw-rw-r-- 1 1000 1000 5297 3月 7 09:15 Makefile -rw-rw-r-- 1 1000 1000 9111 3月 7 09:15 README.txt drwxrwxr-x 3 1000 1000 4096 3月 8 14:56 builtin/ drwxrwxr-x 6 1000 1000 4096 3月 8 14:49 canutils/ drwxrwxr-x 121 1000 1000 4096 3月 8 14:49 examples/ drwxrwxr-x 7 1000 1000 4096 3月 8 14:49 fsutils/ drwxrwxr-x 3 1000 1000 4096 3月 8 14:49 gpsutils/ drwxrwxr-x 9 1000 1000 4096 3月 8 14:49 graphics/ drwxrwxr-x 3 1000 1000 4096 3月 7 09:15 import/ drwxrwxr-x 14 1000 1000 4096 3月 7 09:17 include/ drwxrwxr-x 7 1000 1000 4096 3月 8 14:49 interpreters/ drwxrwxr-x 7 1000 1000 4096 3月 7 09:15 modbus/ drwxrwxr-x 23 1000 1000 4096 3月 8 14:49 netutils/ drwxrwxr-x 2 1000 1000 4096 3月 8 14:56 nshlib/ drwxrwxr-x 6 1000 1000 4096 3月 8 14:56 platform/ drwxrwxr-x 34 1000 1000 4096 3月 8 14:49 system/ drwxrwxr-x 2 1000 1000 4096 3月 7 09:15 tools/ drwxrwxr-x 5 1000 1000 4096 3月 8 14:49 wireless/ develop:~/src/NuttX_XG50/apps$ \\ テストなので、適当に **test** というディレクトリを作り作業を進めます。 develop:~/src/NuttX_XG50/apps$ ls -lnF total 264 -rw-rw-r-- 1 1000 1000 4166 3月 7 09:15 Application.mk drwxrwxr-x 14 1000 1000 4096 3月 8 14:53 BearSSL/ -rw-rw-r-- 1 1000 1000 8793 3月 7 09:15 COPYING -rw-rw-r-- 1 1000 1000 145150 3月 7 09:17 ChangeLog.txt -rw-rw-r-- 1 1000 1000 2797 3月 7 09:15 Directory.mk -rw-rw-r-- 1 1000 1000 3095 3月 7 09:15 Make.defs -rw-rw-r-- 1 1000 1000 5297 3月 7 09:15 Makefile -rw-rw-r-- 1 1000 1000 9111 3月 7 09:15 README.txt drwxrwxr-x 3 1000 1000 4096 3月 8 14:56 builtin/ drwxrwxr-x 6 1000 1000 4096 3月 8 14:49 canutils/ drwxrwxr-x 121 1000 1000 4096 3月 8 14:49 examples/ drwxrwxr-x 7 1000 1000 4096 3月 8 14:49 fsutils/ drwxrwxr-x 3 1000 1000 4096 3月 8 14:49 gpsutils/ drwxrwxr-x 9 1000 1000 4096 3月 8 14:49 graphics/ drwxrwxr-x 3 1000 1000 4096 3月 7 09:15 import/ drwxrwxr-x 14 1000 1000 4096 3月 7 09:17 include/ drwxrwxr-x 7 1000 1000 4096 3月 8 14:49 interpreters/ drwxrwxr-x 7 1000 1000 4096 3月 7 09:15 modbus/ drwxrwxr-x 23 1000 1000 4096 3月 8 14:49 netutils/ drwxrwxr-x 2 1000 1000 4096 3月 8 14:56 nshlib/ drwxrwxr-x 6 1000 1000 4096 3月 8 14:56 platform/ drwxrwxr-x 34 1000 1000 4096 3月 8 14:49 system/ drwxrwxr-x 2 1000 1000 4096 3月 8 15:00 test/ <-------- drwxrwxr-x 2 1000 1000 4096 3月 7 09:15 tools/ drwxrwxr-x 5 1000 1000 4096 3月 8 14:49 wireless/ develop:~/src/NuttX_XG50/apps$ \\ 作成した **test** ディレクトリ以下に、 * Kconfig * Make.defs * Makefile * hello_main.c (プログラムソース) を作成します。 # # For a description of the syntax of this configuration file, # see the file kconfig-language.txt in the NuttX tools repository. # config APP_HELLO bool "\"Hello, World!\" example" default n ---help--- Enable the \"Hello, World!\" example if APP_HELLO config APP_HELLO_PROGNAME string "Program name" default "hello" depends on BUILD_KERNEL ---help--- This is the name of the program that will be use when the NSH ELF program is installed. config APP_HELLO_PRIORITY int "Hello task priority" default 100 config APP_HELLO_STACKSIZE int "Hello stack size" default 2048 endif ifeq ($(CONFIG_APP_HELLO),y) CONFIGURED_APPS += test endif -include $(TOPDIR)/Make.defs # Hello, World! built-in application info CONFIG_APP_HELLO_PRIORITY ?= SCHED_PRIORITY_DEFAULT CONFIG_APP_HELLO_STACKSIZE ?= 2048 APPNAME = hello PRIORITY = $(CONFIG_APP_HELLO_PRIORITY) STACKSIZE = $(CONFIG_APP_HELLO_STACKSIZE) # Hello, World! Example ASRCS = CSRCS = MAINSRC = hello_main.c CONFIG_APP_HELLO_PROGNAME ?= hello$(EXEEXT) PROGNAME = $(CONFIG_APP_HELLO_PROGNAME) include $(APPDIR)/Application.mk #include #include int hello_main(int argc, char *argv[]) { printf("Hello, World!!\n"); return 0; } \\ ==== config の変更 ==== **nuttx/** ディレクトリで ''make clean'' した後で ''make menuconfig'' を実行します。\\ Linux Kernel と同じような画面になります。 {{:xg_series_devel:add_builtin_command:menuconfig_01.png|make menuconfig}} \\ **Application Configuration** から **"Hello, World!" example** を選択します。 {{:xg_series_devel:add_builtin_command:menuconfig_02.png|Application Configuration}} {{:xg_series_devel:add_builtin_command:menuconfig_03.png|Hello, World!}} \\ **** -> **** を選び、config の編集内容を反映させます。 {{:xg_series_devel:add_builtin_command:menuconfig_04.png|exit}} {{:xg_series_devel:add_builtin_command:menuconfig_05.png|save configuration}} \\ ==== ビルド ==== ビルドを行います。 develop:~/src/NuttX_XG50/nuttx$ make ... 略 ... make[1]: Leaving directory '/home/kikuchi/src/NuttX_XG50/nuttx/arch/arm/src' CP: nuttx.hex CP: nuttx.bin develop:~/src/NuttX_XG50/nuttx$ \\ ==== 実機への書き込みと実行 ==== [[xg_series_devel:boot_firmware:start]] と同じ手順で、XG-50 に書き込んで実行してみます。 NuttShell (NSH) nsh> help help usage: help [-v] [] [ dirname false mkfatfs pwd time ? date free mkfifo reboot true basename dd help mkrd rm uname break df hexdump mh rmdir umount cat dmesg kill mount set unset cd echo ls mv sh usleep cp exec mb mw sleep xd cmp exit mkdir ps test Builtin Apps: cu hello <---- 増えている i2c sudoku nsh> ビルトインアプリケーションとして **hello** が出てきました。\\ さっそく実行してみます。 nsh> hello Hello, World!! nsh> きちんと動作しました! \\