aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--Makefile31
-rw-r--r--apps/ChangeLog.txt71
-rw-r--r--apps/Makefile71
-rw-r--r--apps/examples/Kconfig158
-rw-r--r--apps/examples/Make.defs28
-rw-r--r--apps/examples/Makefile55
-rw-r--r--apps/examples/README.txt174
-rw-r--r--apps/examples/adc/Makefile21
-rw-r--r--apps/examples/adc/adc_main.c7
-rw-r--r--apps/examples/buttons/Makefile21
-rw-r--r--apps/examples/can/Makefile21
-rw-r--r--apps/examples/cdcacm/Makefile19
-rw-r--r--apps/examples/hello/Makefile19
-rw-r--r--apps/examples/helloxx/Makefile23
-rw-r--r--apps/examples/mm/Makefile21
-rw-r--r--apps/examples/mount/Makefile21
-rw-r--r--apps/examples/nsh/Makefile21
-rw-r--r--apps/examples/null/Makefile21
-rw-r--r--apps/examples/ostest/Kconfig27
-rw-r--r--apps/examples/ostest/Makefile19
-rw-r--r--apps/examples/ostest/roundrobin.c156
-rw-r--r--apps/examples/pipe/Makefile21
-rw-r--r--apps/examples/poll/Makefile22
-rw-r--r--apps/examples/pwm/Makefile21
-rw-r--r--apps/examples/pwm/pwm_main.c1
-rw-r--r--apps/examples/qencoder/Makefile19
-rw-r--r--apps/examples/romfs/Makefile24
-rw-r--r--apps/examples/serloop/Makefile21
-rw-r--r--apps/examples/watchdog/Makefile19
-rw-r--r--apps/interpreters/Kconfig4
-rw-r--r--apps/interpreters/Make.defs4
-rw-r--r--apps/interpreters/Makefile32
-rw-r--r--apps/interpreters/ficl/Kconfig4
-rw-r--r--apps/interpreters/ficl/Makefile29
-rw-r--r--apps/namedapp/Makefile32
-rw-r--r--apps/nshlib/Kconfig100
-rw-r--r--apps/nshlib/Makefile61
-rw-r--r--apps/nshlib/README.txt74
-rw-r--r--apps/nshlib/nsh.h77
-rw-r--r--apps/nshlib/nsh_apps.c41
-rw-r--r--apps/nshlib/nsh_consolemain.c8
-rw-r--r--apps/nshlib/nsh_dbgcmds.c64
-rw-r--r--apps/nshlib/nsh_netcmds.c327
-rw-r--r--apps/nshlib/nsh_netinit.c14
-rw-r--r--apps/nshlib/nsh_parse.c63
-rw-r--r--apps/px4/tests/test_time.c8
-rw-r--r--apps/px4/tests/tests_main.c85
-rw-r--r--apps/system/Makefile33
-rw-r--r--apps/system/free/Makefile28
-rw-r--r--apps/system/i2c/Makefile27
-rw-r--r--apps/system/install/Makefile27
-rw-r--r--apps/system/readline/Makefile24
-rw-r--r--nuttx/COPYING51
-rw-r--r--nuttx/ChangeLog334
-rw-r--r--nuttx/Kconfig112
-rw-r--r--nuttx/Makefile622
-rw-r--r--nuttx/Makefile.unix749
-rw-r--r--nuttx/Makefile.win740
-rw-r--r--nuttx/README.txt163
-rw-r--r--nuttx/ReleaseNotes269
-rw-r--r--nuttx/TODO152
-rw-r--r--nuttx/arch/Kconfig19
-rw-r--r--nuttx/arch/arm/Kconfig32
-rw-r--r--nuttx/arch/arm/include/elf.h243
-rw-r--r--nuttx/arch/arm/include/stm32/chip.h200
-rw-r--r--nuttx/arch/arm/include/stm32/stm32f10xxx_irq.h58
-rw-r--r--nuttx/arch/arm/src/Makefile148
-rw-r--r--nuttx/arch/arm/src/armv7-m/Kconfig51
-rw-r--r--nuttx/arch/arm/src/armv7-m/Toolchain.defs266
-rw-r--r--nuttx/arch/arm/src/armv7-m/memcpy.S351
-rw-r--r--nuttx/arch/arm/src/armv7-m/up_elf.c450
-rw-r--r--nuttx/arch/arm/src/armv7-m/up_exception.S4
-rw-r--r--nuttx/arch/arm/src/armv7-m/up_hardfault.c4
-rw-r--r--nuttx/arch/arm/src/armv7-m/up_memcpy.S416
-rw-r--r--nuttx/arch/arm/src/common/arm-elf.h (renamed from nuttx/lib/string/lib_memset.c)38
-rw-r--r--nuttx/arch/arm/src/stm32/Kconfig629
-rw-r--r--nuttx/arch/arm/src/stm32/Make.defs32
-rw-r--r--nuttx/arch/arm/src/stm32/chip/stm32_eth.h8
-rw-r--r--nuttx/arch/arm/src/stm32/chip/stm32_flash.h1
-rw-r--r--nuttx/arch/arm/src/stm32/chip/stm32f100_pinmap.h190
-rw-r--r--nuttx/arch/arm/src/stm32/chip/stm32f103vc_pinmap.h2
-rw-r--r--nuttx/arch/arm/src/stm32/chip/stm32f103ze_pinmap.h98
-rw-r--r--nuttx/arch/arm/src/stm32/chip/stm32f105vb_pinmap.h2
-rw-r--r--nuttx/arch/arm/src/stm32/chip/stm32f107vc_pinmap.h2
-rw-r--r--nuttx/arch/arm/src/stm32/chip/stm32f10xxx_gpio.h23
-rw-r--r--nuttx/arch/arm/src/stm32/chip/stm32f10xxx_memorymap.h61
-rw-r--r--nuttx/arch/arm/src/stm32/chip/stm32f10xxx_rcc.h78
-rw-r--r--nuttx/arch/arm/src/stm32/chip/stm32f10xxx_vectors.h72
-rw-r--r--nuttx/arch/arm/src/stm32/chip/stm32f20xxx_pinmap.h2
-rw-r--r--nuttx/arch/arm/src/stm32/chip/stm32f40xxx_pinmap.h2
-rw-r--r--nuttx/arch/arm/src/stm32/stm32_adc.h2
-rw-r--r--nuttx/arch/arm/src/stm32/stm32_eth.c11
-rw-r--r--nuttx/arch/arm/src/stm32/stm32_eth.h35
-rw-r--r--nuttx/arch/arm/src/stm32/stm32_i2c.c385
-rw-r--r--nuttx/arch/arm/src/stm32/stm32_lowputc.c75
-rw-r--r--nuttx/arch/arm/src/stm32/stm32_otgfsdev.c26
-rw-r--r--nuttx/arch/arm/src/stm32/stm32_otgfshost.c53
-rw-r--r--nuttx/arch/arm/src/stm32/stm32_qencoder.c1
-rw-r--r--nuttx/arch/arm/src/stm32/stm32_serial.c154
-rw-r--r--nuttx/arch/arm/src/stm32/stm32_uart.h14
-rw-r--r--nuttx/arch/arm/src/stm32/stm32f10xxx_rcc.c56
-rw-r--r--nuttx/arch/arm/src/stm32/stm32f20xxx_rcc.c4
-rw-r--r--nuttx/arch/arm/src/stm32/stm32f40xxx_rcc.c4
-rw-r--r--nuttx/binfmt/Kconfig63
-rw-r--r--nuttx/binfmt/Makefile76
-rw-r--r--nuttx/binfmt/binfmt_dumpmodule.c17
-rw-r--r--nuttx/binfmt/binfmt_exec.c2
-rw-r--r--nuttx/binfmt/binfmt_execmodule.c103
-rw-r--r--nuttx/binfmt/binfmt_exepath.c286
-rw-r--r--nuttx/binfmt/binfmt_globals.c2
-rw-r--r--nuttx/binfmt/binfmt_internal.h2
-rw-r--r--nuttx/binfmt/binfmt_loadmodule.c127
-rw-r--r--nuttx/binfmt/binfmt_register.c2
-rw-r--r--nuttx/binfmt/binfmt_unloadmodule.c113
-rw-r--r--nuttx/binfmt/binfmt_unregister.c2
-rw-r--r--nuttx/binfmt/elf.c323
-rw-r--r--nuttx/binfmt/libelf/Make.defs58
-rw-r--r--nuttx/binfmt/libelf/libelf.h341
-rw-r--r--nuttx/binfmt/libelf/libelf_addrenv.c176
-rw-r--r--nuttx/binfmt/libelf/libelf_bind.c334
-rw-r--r--nuttx/binfmt/libelf/libelf_load.c288
-rw-r--r--nuttx/binfmt/libelf/libelf_read.c165
-rw-r--r--nuttx/binfmt/libelf/libelf_unload.c114
-rw-r--r--nuttx/binfmt/libnxflat/Kconfig5
-rw-r--r--nuttx/binfmt/libnxflat/Make.defs25
-rw-r--r--nuttx/binfmt/libnxflat/libnxflat.h136
-rw-r--r--nuttx/binfmt/libnxflat/libnxflat_addrenv.c235
-rw-r--r--nuttx/binfmt/libnxflat/libnxflat_bind.c185
-rw-r--r--nuttx/binfmt/libnxflat/libnxflat_init.c7
-rw-r--r--nuttx/binfmt/libnxflat/libnxflat_load.c76
-rw-r--r--nuttx/binfmt/libnxflat/libnxflat_read.c14
-rw-r--r--nuttx/binfmt/libnxflat/libnxflat_uninit.c7
-rw-r--r--nuttx/binfmt/libnxflat/libnxflat_unload.c22
-rw-r--r--nuttx/binfmt/libnxflat/libnxflat_verify.c9
-rw-r--r--nuttx/binfmt/nxflat.c41
-rw-r--r--nuttx/binfmt/symtab_findbyname.c2
-rw-r--r--nuttx/binfmt/symtab_findbyvalue.c2
-rw-r--r--nuttx/binfmt/symtab_findorderedbyname.c2
-rw-r--r--nuttx/binfmt/symtab_findorderedbyvalue.c2
-rw-r--r--nuttx/configs/README.txt216
-rw-r--r--nuttx/configs/px4fmu/common/Make.defs35
-rwxr-xr-xnuttx/configs/px4fmu/nsh/defconfig9
-rw-r--r--nuttx/configs/px4fmu/src/Makefile14
-rw-r--r--nuttx/configs/px4io/common/Make.defs43
-rw-r--r--nuttx/configs/px4io/src/Makefile9
-rw-r--r--nuttx/drivers/Kconfig76
-rw-r--r--nuttx/drivers/Makefile60
-rw-r--r--nuttx/drivers/analog/Make.defs6
-rw-r--r--nuttx/drivers/analog/adc.c15
-rw-r--r--nuttx/drivers/bch/Make.defs4
-rw-r--r--nuttx/drivers/input/Make.defs8
-rw-r--r--nuttx/drivers/input/max11802.c1313
-rw-r--r--nuttx/drivers/input/max11802.h167
-rw-r--r--nuttx/drivers/lcd/Kconfig81
-rw-r--r--nuttx/drivers/lcd/Make.defs6
-rw-r--r--nuttx/drivers/lcd/ug-2864ambag01.c1161
-rw-r--r--nuttx/drivers/lcd/ug-9664hswag01.c15
-rw-r--r--nuttx/drivers/loop.c2
-rw-r--r--nuttx/drivers/mmcsd/Make.defs16
-rw-r--r--nuttx/drivers/mmcsd/mmcsd_sdio.c8
-rw-r--r--nuttx/drivers/mmcsd/mmcsd_spi.c11
-rw-r--r--nuttx/drivers/mtd/Make.defs4
-rw-r--r--nuttx/drivers/mtd/at25.c708
-rw-r--r--nuttx/drivers/mtd/ftl.c31
-rw-r--r--nuttx/drivers/net/e1000.c307
-rw-r--r--nuttx/drivers/net/e1000.h4
-rw-r--r--nuttx/drivers/net/vnet.c333
-rw-r--r--nuttx/drivers/power/Make.defs4
-rw-r--r--nuttx/drivers/sensors/Make.defs4
-rw-r--r--nuttx/drivers/serial/Kconfig36
-rw-r--r--nuttx/drivers/serial/serial.c6
-rw-r--r--nuttx/drivers/usbdev/Make.defs2
-rw-r--r--nuttx/drivers/usbdev/pl2303.c2
-rw-r--r--nuttx/drivers/usbdev/usbmsc.h2
-rw-r--r--nuttx/drivers/usbhost/Make.defs6
-rw-r--r--nuttx/drivers/wireless/Make.defs8
-rw-r--r--nuttx/fs/Makefile18
-rw-r--r--nuttx/fs/fs_stat.c7
-rw-r--r--nuttx/graphics/Makefile98
-rw-r--r--nuttx/graphics/nxfonts/Makefile.sources14
-rw-r--r--nuttx/graphics/nxglib/Makefile.sources52
-rw-r--r--nuttx/graphics/nxglib/nxglib_splitline.c389
-rw-r--r--nuttx/graphics/nxmu/nx_bitmap.c29
-rw-r--r--nuttx/graphics/nxmu/nx_block.c2
-rw-r--r--nuttx/graphics/nxmu/nx_getrectangle.c30
-rw-r--r--nuttx/graphics/nxmu/nxfe.h21
-rw-r--r--nuttx/graphics/nxmu/nxmu_kbdin.c2
-rw-r--r--nuttx/graphics/nxmu/nxmu_mouse.c46
-rw-r--r--nuttx/graphics/nxmu/nxmu_redrawreq.c2
-rw-r--r--nuttx/graphics/nxmu/nxmu_reportposition.c2
-rw-r--r--nuttx/graphics/nxmu/nxmu_sendwindow.c44
-rw-r--r--nuttx/graphics/nxmu/nxmu_server.c10
-rw-r--r--nuttx/graphics/nxsu/nx_mousein.c30
-rw-r--r--nuttx/graphics/nxtk/nxtk_events.c39
-rw-r--r--nuttx/graphics/nxtk/nxtk_filltrapwindow.c11
-rw-r--r--nuttx/graphics/nxtk/nxtk_getwindow.c11
-rw-r--r--nuttx/graphics/nxtk/nxtk_internal.h5
-rw-r--r--nuttx/graphics/nxtk/nxtk_subwindowmove.c12
-rw-r--r--nuttx/include/cxx/cmath62
-rw-r--r--nuttx/include/cxx/cstdbool9
-rw-r--r--nuttx/include/cxx/cstdio12
-rw-r--r--nuttx/include/cxx/cstdlib1
-rw-r--r--nuttx/include/debug.h25
-rw-r--r--nuttx/include/elf32.h352
-rw-r--r--nuttx/include/net/if.h9
-rw-r--r--nuttx/include/nuttx/arch.h290
-rw-r--r--nuttx/include/nuttx/binfmt/binfmt.h (renamed from nuttx/include/nuttx/binfmt.h)175
-rw-r--r--nuttx/include/nuttx/binfmt/elf.h340
-rw-r--r--nuttx/include/nuttx/binfmt/nxflat.h (renamed from nuttx/include/nuttx/nxflat.h)85
-rw-r--r--nuttx/include/nuttx/binfmt/symtab.h (renamed from nuttx/include/nuttx/symtab.h)10
-rw-r--r--nuttx/include/nuttx/compiler.h25
-rw-r--r--nuttx/include/nuttx/float.h225
-rw-r--r--nuttx/include/nuttx/fs/fs.h17
-rw-r--r--nuttx/include/nuttx/i2c.h31
-rw-r--r--nuttx/include/nuttx/input/keypad.h54
-rw-r--r--nuttx/include/nuttx/input/max11802.h175
-rw-r--r--nuttx/include/nuttx/lcd/ug-2864ambag01.h245
-rw-r--r--nuttx/include/nuttx/lcd/ug-9664hswag01.h15
-rw-r--r--nuttx/include/nuttx/math.h270
-rw-r--r--nuttx/include/nuttx/mtd.h3
-rw-r--r--nuttx/include/nuttx/net/ioctl.h6
-rw-r--r--nuttx/include/nuttx/net/uip/uip-arch.h4
-rw-r--r--nuttx/include/nuttx/power/pm.h6
-rw-r--r--nuttx/include/nuttx/sched.h38
-rw-r--r--nuttx/include/nuttx/usb/cdcacm.h2
-rw-r--r--nuttx/include/nuttx/usb/usbdev_trace.h4
-rw-r--r--nuttx/include/nuttx/vt100.h4
-rw-r--r--nuttx/include/nuttx/wqueue.h24
-rw-r--r--nuttx/include/stdbool.h35
-rw-r--r--nuttx/include/stdio.h7
-rw-r--r--nuttx/include/termios.h30
-rw-r--r--nuttx/include/unistd.h1
-rw-r--r--nuttx/lib/Makefile98
-rw-r--r--nuttx/lib/README.txt82
-rw-r--r--nuttx/lib/stdlib/lib_rand.c220
-rw-r--r--nuttx/libc/Kconfig (renamed from nuttx/lib/Kconfig)111
-rw-r--r--nuttx/libc/Makefile145
-rw-r--r--nuttx/libc/README.txt85
-rw-r--r--nuttx/libc/dirent/Make.defs (renamed from nuttx/lib/dirent/Make.defs)2
-rw-r--r--nuttx/libc/dirent/lib_readdirr.c (renamed from nuttx/lib/dirent/lib_readdirr.c)2
-rw-r--r--nuttx/libc/dirent/lib_telldir.c (renamed from nuttx/lib/dirent/lib_telldir.c)2
-rw-r--r--nuttx/libc/fixedmath/Make.defs (renamed from nuttx/lib/math/Make.defs)10
-rw-r--r--nuttx/libc/fixedmath/lib_b16atan2.c (renamed from nuttx/lib/math/lib_b16atan2.c)2
-rw-r--r--nuttx/libc/fixedmath/lib_b16cos.c (renamed from nuttx/lib/math/lib_b16cos.c)2
-rw-r--r--nuttx/libc/fixedmath/lib_b16sin.c (renamed from nuttx/lib/math/lib_b16sin.c)2
-rw-r--r--nuttx/libc/fixedmath/lib_fixedmath.c (renamed from nuttx/lib/math/lib_fixedmath.c)2
-rw-r--r--nuttx/libc/fixedmath/lib_rint.c (renamed from nuttx/lib/math/lib_rint.c)2
-rw-r--r--nuttx/libc/lib.csv (renamed from nuttx/lib/lib.csv)0
-rw-r--r--nuttx/libc/lib_internal.h (renamed from nuttx/lib/lib_internal.h)57
-rw-r--r--nuttx/libc/libgen/Make.defs (renamed from nuttx/lib/libgen/Make.defs)2
-rw-r--r--nuttx/libc/libgen/lib_basename.c (renamed from nuttx/lib/libgen/lib_basename.c)2
-rw-r--r--nuttx/libc/libgen/lib_dirname.c (renamed from nuttx/lib/libgen/lib_dirname.c)2
-rw-r--r--nuttx/libc/math/Kconfig26
-rw-r--r--nuttx/libc/math/Make.defs62
-rw-r--r--nuttx/libc/math/lib_acos.c46
-rw-r--r--nuttx/libc/math/lib_acosf.c41
-rw-r--r--nuttx/libc/math/lib_acosl.c46
-rw-r--r--nuttx/libc/math/lib_asin.c69
-rw-r--r--nuttx/libc/math/lib_asinf.c65
-rw-r--r--nuttx/libc/math/lib_asinl.c69
-rw-r--r--nuttx/libc/math/lib_atan.c48
-rw-r--r--nuttx/libc/math/lib_atan2.c86
-rw-r--r--nuttx/libc/math/lib_atan2f.c81
-rw-r--r--nuttx/libc/math/lib_atan2l.c87
-rw-r--r--nuttx/libc/math/lib_atanf.c43
-rw-r--r--nuttx/libc/math/lib_atanl.c48
-rw-r--r--nuttx/libc/math/lib_ceil.c52
-rw-r--r--nuttx/libc/math/lib_ceilf.c47
-rw-r--r--nuttx/libc/math/lib_ceill.c52
-rw-r--r--nuttx/libc/math/lib_cos.c46
-rw-r--r--nuttx/libc/math/lib_cosf.c41
-rw-r--r--nuttx/libc/math/lib_cosh.c47
-rw-r--r--nuttx/libc/math/lib_coshf.c42
-rw-r--r--nuttx/libc/math/lib_coshl.c47
-rw-r--r--nuttx/libc/math/lib_cosl.c46
-rw-r--r--nuttx/libc/math/lib_exp.c126
-rw-r--r--nuttx/libc/math/lib_expf.c112
-rw-r--r--nuttx/libc/math/lib_expl.c126
-rw-r--r--nuttx/libc/math/lib_fabs.c46
-rw-r--r--nuttx/libc/math/lib_fabsf.c41
-rw-r--r--nuttx/libc/math/lib_fabsl.c46
-rw-r--r--nuttx/libc/math/lib_floor.c52
-rw-r--r--nuttx/libc/math/lib_floorf.c47
-rw-r--r--nuttx/libc/math/lib_floorl.c52
-rw-r--r--nuttx/libc/math/lib_fmod.c52
-rw-r--r--nuttx/libc/math/lib_fmodf.c47
-rw-r--r--nuttx/libc/math/lib_fmodl.c52
-rw-r--r--nuttx/libc/math/lib_frexp.c47
-rw-r--r--nuttx/libc/math/lib_frexpf.c42
-rw-r--r--nuttx/libc/math/lib_frexpl.c47
-rw-r--r--nuttx/libc/math/lib_ldexp.c46
-rw-r--r--nuttx/libc/math/lib_ldexpf.c41
-rw-r--r--nuttx/libc/math/lib_ldexpl.c46
-rw-r--r--nuttx/libc/math/lib_libexpi.c103
-rw-r--r--nuttx/libc/math/lib_libsqrtapprox.c50
-rw-r--r--nuttx/libc/math/lib_log.c82
-rw-r--r--nuttx/libc/math/lib_log10.c46
-rw-r--r--nuttx/libc/math/lib_log10f.c41
-rw-r--r--nuttx/libc/math/lib_log10l.c46
-rw-r--r--nuttx/libc/math/lib_log2.c46
-rw-r--r--nuttx/libc/math/lib_log2f.c41
-rw-r--r--nuttx/libc/math/lib_log2l.c46
-rw-r--r--nuttx/libc/math/lib_logf.c77
-rw-r--r--nuttx/libc/math/lib_logl.c80
-rw-r--r--nuttx/libc/math/lib_modf.c58
-rw-r--r--nuttx/libc/math/lib_modff.c55
-rw-r--r--nuttx/libc/math/lib_modfl.c61
-rw-r--r--nuttx/libc/math/lib_pow.c46
-rw-r--r--nuttx/libc/math/lib_powf.c41
-rw-r--r--nuttx/libc/math/lib_powl.c46
-rw-r--r--nuttx/libc/math/lib_round.c40
-rw-r--r--nuttx/libc/math/lib_roundf.c38
-rw-r--r--nuttx/libc/math/lib_roundl.c40
-rw-r--r--nuttx/libc/math/lib_sin.c114
-rw-r--r--nuttx/libc/math/lib_sinf.c104
-rw-r--r--nuttx/libc/math/lib_sinh.c47
-rw-r--r--nuttx/libc/math/lib_sinhf.c42
-rw-r--r--nuttx/libc/math/lib_sinhl.c47
-rw-r--r--nuttx/libc/math/lib_sinl.c114
-rw-r--r--nuttx/libc/math/lib_sqrt.c99
-rw-r--r--nuttx/libc/math/lib_sqrtf.c84
-rw-r--r--nuttx/libc/math/lib_sqrtl.c101
-rw-r--r--nuttx/libc/math/lib_tan.c46
-rw-r--r--nuttx/libc/math/lib_tanf.c41
-rw-r--r--nuttx/libc/math/lib_tanh.c49
-rw-r--r--nuttx/libc/math/lib_tanhf.c44
-rw-r--r--nuttx/libc/math/lib_tanhl.c49
-rw-r--r--nuttx/libc/math/lib_tanl.c46
-rw-r--r--nuttx/libc/misc/Make.defs (renamed from nuttx/lib/misc/Make.defs)2
-rw-r--r--nuttx/libc/misc/lib_crc32.c (renamed from nuttx/lib/misc/lib_crc32.c)2
-rw-r--r--nuttx/libc/misc/lib_dbg.c (renamed from nuttx/lib/misc/lib_dbg.c)2
-rw-r--r--nuttx/libc/misc/lib_dumpbuffer.c (renamed from nuttx/lib/misc/lib_dumpbuffer.c)2
-rw-r--r--nuttx/libc/misc/lib_filesem.c (renamed from nuttx/lib/misc/lib_filesem.c)2
-rw-r--r--nuttx/libc/misc/lib_init.c (renamed from nuttx/lib/misc/lib_init.c)2
-rw-r--r--nuttx/libc/misc/lib_match.c (renamed from nuttx/lib/misc/lib_match.c)2
-rw-r--r--nuttx/libc/misc/lib_sendfile.c (renamed from nuttx/lib/misc/lib_sendfile.c)2
-rw-r--r--nuttx/libc/misc/lib_streamsem.c (renamed from nuttx/lib/misc/lib_streamsem.c)2
-rw-r--r--nuttx/libc/mqueue/Make.defs (renamed from nuttx/lib/mqueue/Make.defs)2
-rw-r--r--nuttx/libc/mqueue/mq_getattr.c (renamed from nuttx/lib/mqueue/mq_getattr.c)2
-rw-r--r--nuttx/libc/mqueue/mq_setattr.c (renamed from nuttx/lib/mqueue/mq_setattr.c)2
-rw-r--r--nuttx/libc/net/Make.defs (renamed from nuttx/lib/net/Make.defs)2
-rw-r--r--nuttx/libc/net/lib_etherntoa.c (renamed from nuttx/lib/net/lib_etherntoa.c)2
-rw-r--r--nuttx/libc/net/lib_htonl.c (renamed from nuttx/lib/net/lib_htonl.c)2
-rw-r--r--nuttx/libc/net/lib_htons.c (renamed from nuttx/lib/net/lib_htons.c)2
-rw-r--r--nuttx/libc/net/lib_inetaddr.c (renamed from nuttx/lib/net/lib_inetaddr.c)2
-rw-r--r--nuttx/libc/net/lib_inetntoa.c (renamed from nuttx/lib/net/lib_inetntoa.c)2
-rw-r--r--nuttx/libc/net/lib_inetntop.c (renamed from nuttx/lib/net/lib_inetntop.c)2
-rw-r--r--nuttx/libc/net/lib_inetpton.c (renamed from nuttx/lib/net/lib_inetpton.c)2
-rw-r--r--nuttx/libc/pthread/Make.defs (renamed from nuttx/lib/pthread/Make.defs)2
-rw-r--r--nuttx/libc/pthread/pthread_attrdestroy.c (renamed from nuttx/lib/pthread/pthread_attrdestroy.c)2
-rw-r--r--nuttx/libc/pthread/pthread_attrgetinheritsched.c (renamed from nuttx/lib/pthread/pthread_attrgetinheritsched.c)2
-rw-r--r--nuttx/libc/pthread/pthread_attrgetschedparam.c (renamed from nuttx/lib/pthread/pthread_attrgetschedparam.c)2
-rw-r--r--nuttx/libc/pthread/pthread_attrgetschedpolicy.c (renamed from nuttx/lib/pthread/pthread_attrgetschedpolicy.c)2
-rw-r--r--nuttx/libc/pthread/pthread_attrgetstacksize.c (renamed from nuttx/lib/pthread/pthread_attrgetstacksize.c)2
-rw-r--r--nuttx/libc/pthread/pthread_attrinit.c (renamed from nuttx/lib/pthread/pthread_attrinit.c)2
-rw-r--r--nuttx/libc/pthread/pthread_attrsetinheritsched.c (renamed from nuttx/lib/pthread/pthread_attrsetinheritsched.c)2
-rw-r--r--nuttx/libc/pthread/pthread_attrsetschedparam.c (renamed from nuttx/lib/pthread/pthread_attrsetschedparam.c)2
-rw-r--r--nuttx/libc/pthread/pthread_attrsetschedpolicy.c (renamed from nuttx/lib/pthread/pthread_attrsetschedpolicy.c)2
-rw-r--r--nuttx/libc/pthread/pthread_attrsetstacksize.c (renamed from nuttx/lib/pthread/pthread_attrsetstacksize.c)2
-rw-r--r--nuttx/libc/pthread/pthread_barrierattrdestroy.c (renamed from nuttx/lib/pthread/pthread_barrierattrdestroy.c)2
-rw-r--r--nuttx/libc/pthread/pthread_barrierattrgetpshared.c (renamed from nuttx/lib/pthread/pthread_barrierattrgetpshared.c)2
-rw-r--r--nuttx/libc/pthread/pthread_barrierattrinit.c (renamed from nuttx/lib/pthread/pthread_barrierattrinit.c)2
-rw-r--r--nuttx/libc/pthread/pthread_barrierattrsetpshared.c (renamed from nuttx/lib/pthread/pthread_barrierattrsetpshared.c)2
-rw-r--r--nuttx/libc/pthread/pthread_condattrdestroy.c (renamed from nuttx/lib/pthread/pthread_condattrdestroy.c)2
-rw-r--r--nuttx/libc/pthread/pthread_condattrinit.c (renamed from nuttx/lib/pthread/pthread_condattrinit.c)2
-rw-r--r--nuttx/libc/pthread/pthread_mutexattrdestroy.c (renamed from nuttx/lib/pthread/pthread_mutexattrdestroy.c)2
-rw-r--r--nuttx/libc/pthread/pthread_mutexattrgetpshared.c (renamed from nuttx/lib/pthread/pthread_mutexattrgetpshared.c)2
-rw-r--r--nuttx/libc/pthread/pthread_mutexattrgettype.c (renamed from nuttx/lib/pthread/pthread_mutexattrgettype.c)2
-rw-r--r--nuttx/libc/pthread/pthread_mutexattrinit.c (renamed from nuttx/lib/pthread/pthread_mutexattrinit.c)2
-rw-r--r--nuttx/libc/pthread/pthread_mutexattrsetpshared.c (renamed from nuttx/lib/pthread/pthread_mutexattrsetpshared.c)2
-rw-r--r--nuttx/libc/pthread/pthread_mutexattrsettype.c (renamed from nuttx/lib/pthread/pthread_mutexattrsettype.c)2
-rw-r--r--nuttx/libc/queue/Make.defs (renamed from nuttx/lib/queue/Make.defs)2
-rw-r--r--nuttx/libc/queue/dq_addafter.c (renamed from nuttx/lib/queue/dq_addafter.c)2
-rw-r--r--nuttx/libc/queue/dq_addbefore.c (renamed from nuttx/lib/queue/dq_addbefore.c)2
-rw-r--r--nuttx/libc/queue/dq_addfirst.c (renamed from nuttx/lib/queue/dq_addfirst.c)2
-rw-r--r--nuttx/libc/queue/dq_addlast.c (renamed from nuttx/lib/queue/dq_addlast.c)2
-rw-r--r--nuttx/libc/queue/dq_rem.c (renamed from nuttx/lib/queue/dq_rem.c)2
-rw-r--r--nuttx/libc/queue/dq_remfirst.c (renamed from nuttx/lib/queue/dq_remfirst.c)2
-rw-r--r--nuttx/libc/queue/dq_remlast.c (renamed from nuttx/lib/queue/dq_remlast.c)2
-rw-r--r--nuttx/libc/queue/sq_addafter.c (renamed from nuttx/lib/queue/sq_addafter.c)2
-rw-r--r--nuttx/libc/queue/sq_addfirst.c (renamed from nuttx/lib/queue/sq_addfirst.c)2
-rw-r--r--nuttx/libc/queue/sq_addlast.c (renamed from nuttx/lib/queue/sq_addlast.c)2
-rw-r--r--nuttx/libc/queue/sq_rem.c (renamed from nuttx/lib/queue/sq_rem.c)2
-rw-r--r--nuttx/libc/queue/sq_remafter.c (renamed from nuttx/lib/queue/sq_remafter.c)2
-rw-r--r--nuttx/libc/queue/sq_remfirst.c (renamed from nuttx/lib/queue/sq_remfirst.c)2
-rw-r--r--nuttx/libc/queue/sq_remlast.c (renamed from nuttx/lib/queue/sq_remlast.c)2
-rw-r--r--nuttx/libc/sched/Make.defs (renamed from nuttx/lib/sched/Make.defs)2
-rw-r--r--nuttx/libc/sched/sched_getprioritymax.c (renamed from nuttx/lib/sched/sched_getprioritymax.c)2
-rw-r--r--nuttx/libc/sched/sched_getprioritymin.c (renamed from nuttx/lib/sched/sched_getprioritymin.c)2
-rw-r--r--nuttx/libc/semaphore/Make.defs (renamed from nuttx/lib/semaphore/Make.defs)2
-rw-r--r--nuttx/libc/semaphore/sem_getvalue.c (renamed from nuttx/lib/semaphore/sem_getvalue.c)2
-rw-r--r--nuttx/libc/semaphore/sem_init.c (renamed from nuttx/lib/semaphore/sem_init.c)2
-rw-r--r--nuttx/libc/signal/Make.defs (renamed from nuttx/lib/signal/Make.defs)2
-rw-r--r--nuttx/libc/signal/sig_addset.c (renamed from nuttx/lib/signal/sig_addset.c)2
-rw-r--r--nuttx/libc/signal/sig_delset.c (renamed from nuttx/lib/signal/sig_delset.c)2
-rw-r--r--nuttx/libc/signal/sig_emptyset.c (renamed from nuttx/lib/signal/sig_emptyset.c)2
-rw-r--r--nuttx/libc/signal/sig_fillset.c (renamed from nuttx/lib/signal/sig_fillset.c)2
-rw-r--r--nuttx/libc/signal/sig_ismember.c (renamed from nuttx/lib/signal/sig_ismember.c)2
-rw-r--r--nuttx/libc/stdio/Make.defs (renamed from nuttx/lib/stdio/Make.defs)36
-rw-r--r--nuttx/libc/stdio/lib_asprintf.c (renamed from nuttx/lib/stdio/lib_asprintf.c)2
-rw-r--r--nuttx/libc/stdio/lib_avsprintf.c (renamed from nuttx/lib/stdio/lib_avsprintf.c)2
-rw-r--r--nuttx/libc/stdio/lib_clearerr.c69
-rw-r--r--nuttx/libc/stdio/lib_dtoa.c (renamed from nuttx/lib/stdio/lib_dtoa.c)2
-rw-r--r--nuttx/libc/stdio/lib_fclose.c (renamed from nuttx/lib/stdio/lib_fclose.c)2
-rw-r--r--nuttx/libc/stdio/lib_feof.c77
-rw-r--r--nuttx/libc/stdio/lib_ferror.c90
-rw-r--r--nuttx/libc/stdio/lib_fflush.c (renamed from nuttx/lib/stdio/lib_fflush.c)2
-rw-r--r--nuttx/libc/stdio/lib_fgetc.c (renamed from nuttx/lib/stdio/lib_fgetc.c)2
-rw-r--r--nuttx/libc/stdio/lib_fgetpos.c (renamed from nuttx/lib/stdio/lib_fgetpos.c)2
-rw-r--r--nuttx/libc/stdio/lib_fgets.c (renamed from nuttx/lib/stdio/lib_fgets.c)4
-rw-r--r--nuttx/libc/stdio/lib_fileno.c (renamed from nuttx/lib/stdio/lib_fileno.c)2
-rw-r--r--nuttx/libc/stdio/lib_fopen.c (renamed from nuttx/lib/stdio/lib_fopen.c)2
-rw-r--r--nuttx/libc/stdio/lib_fprintf.c (renamed from nuttx/lib/stdio/lib_fprintf.c)2
-rw-r--r--nuttx/libc/stdio/lib_fputc.c (renamed from nuttx/lib/stdio/lib_fputc.c)2
-rw-r--r--nuttx/libc/stdio/lib_fputs.c (renamed from nuttx/lib/stdio/lib_fputs.c)2
-rw-r--r--nuttx/libc/stdio/lib_fread.c (renamed from nuttx/lib/stdio/lib_fread.c)2
-rw-r--r--nuttx/libc/stdio/lib_fseek.c (renamed from nuttx/lib/stdio/lib_fseek.c)2
-rw-r--r--nuttx/libc/stdio/lib_fsetpos.c (renamed from nuttx/lib/stdio/lib_fsetpos.c)2
-rw-r--r--nuttx/libc/stdio/lib_ftell.c (renamed from nuttx/lib/stdio/lib_ftell.c)2
-rw-r--r--nuttx/libc/stdio/lib_fwrite.c (renamed from nuttx/lib/stdio/lib_fwrite.c)2
-rw-r--r--nuttx/libc/stdio/lib_gets.c (renamed from nuttx/lib/stdio/lib_gets.c)2
-rw-r--r--nuttx/libc/stdio/lib_libdtoa.c (renamed from nuttx/lib/stdio/lib_libdtoa.c)2
-rw-r--r--nuttx/libc/stdio/lib_libfflush.c (renamed from nuttx/lib/stdio/lib_libfflush.c)2
-rw-r--r--nuttx/libc/stdio/lib_libflushall.c (renamed from nuttx/lib/stdio/lib_libflushall.c)2
-rw-r--r--nuttx/libc/stdio/lib_libfread.c (renamed from nuttx/lib/stdio/lib_libfread.c)33
-rw-r--r--nuttx/libc/stdio/lib_libfwrite.c (renamed from nuttx/lib/stdio/lib_libfwrite.c)2
-rw-r--r--nuttx/libc/stdio/lib_libnoflush.c (renamed from nuttx/lib/stdio/lib_libnoflush.c)2
-rw-r--r--nuttx/libc/stdio/lib_libsprintf.c (renamed from nuttx/lib/stdio/lib_libsprintf.c)2
-rw-r--r--nuttx/libc/stdio/lib_libvsprintf.c (renamed from nuttx/lib/stdio/lib_libvsprintf.c)4
-rw-r--r--nuttx/libc/stdio/lib_lowinstream.c (renamed from nuttx/lib/stdio/lib_lowinstream.c)2
-rw-r--r--nuttx/libc/stdio/lib_lowoutstream.c (renamed from nuttx/lib/stdio/lib_lowoutstream.c)2
-rw-r--r--nuttx/libc/stdio/lib_lowprintf.c (renamed from nuttx/lib/stdio/lib_lowprintf.c)2
-rw-r--r--nuttx/libc/stdio/lib_meminstream.c (renamed from nuttx/lib/stdio/lib_meminstream.c)2
-rw-r--r--nuttx/libc/stdio/lib_memoutstream.c (renamed from nuttx/lib/stdio/lib_memoutstream.c)2
-rw-r--r--nuttx/libc/stdio/lib_nullinstream.c (renamed from nuttx/lib/stdio/lib_nullinstream.c)2
-rw-r--r--nuttx/libc/stdio/lib_nulloutstream.c (renamed from nuttx/lib/stdio/lib_nulloutstream.c)2
-rw-r--r--nuttx/libc/stdio/lib_perror.c (renamed from nuttx/lib/stdio/lib_perror.c)2
-rw-r--r--nuttx/libc/stdio/lib_printf.c (renamed from nuttx/lib/stdio/lib_printf.c)2
-rw-r--r--nuttx/libc/stdio/lib_puts.c (renamed from nuttx/lib/stdio/lib_puts.c)2
-rw-r--r--nuttx/libc/stdio/lib_rawinstream.c (renamed from nuttx/lib/stdio/lib_rawinstream.c)2
-rw-r--r--nuttx/libc/stdio/lib_rawoutstream.c (renamed from nuttx/lib/stdio/lib_rawoutstream.c)2
-rw-r--r--nuttx/libc/stdio/lib_rawprintf.c (renamed from nuttx/lib/stdio/lib_rawprintf.c)17
-rw-r--r--nuttx/libc/stdio/lib_rdflush.c (renamed from nuttx/lib/stdio/lib_rdflush.c)2
-rw-r--r--nuttx/libc/stdio/lib_snprintf.c (renamed from nuttx/lib/stdio/lib_snprintf.c)2
-rw-r--r--nuttx/libc/stdio/lib_sprintf.c (renamed from nuttx/lib/stdio/lib_sprintf.c)2
-rw-r--r--nuttx/libc/stdio/lib_sscanf.c (renamed from nuttx/lib/stdio/lib_sscanf.c)2
-rw-r--r--nuttx/libc/stdio/lib_stdinstream.c (renamed from nuttx/lib/stdio/lib_stdinstream.c)2
-rw-r--r--nuttx/libc/stdio/lib_stdoutstream.c (renamed from nuttx/lib/stdio/lib_stdoutstream.c)2
-rw-r--r--nuttx/libc/stdio/lib_syslogstream.c (renamed from nuttx/lib/stdio/lib_syslogstream.c)2
-rw-r--r--nuttx/libc/stdio/lib_ungetc.c (renamed from nuttx/lib/stdio/lib_ungetc.c)2
-rw-r--r--nuttx/libc/stdio/lib_vfprintf.c (renamed from nuttx/lib/stdio/lib_vfprintf.c)2
-rw-r--r--nuttx/libc/stdio/lib_vprintf.c (renamed from nuttx/lib/stdio/lib_vprintf.c)2
-rw-r--r--nuttx/libc/stdio/lib_vsnprintf.c (renamed from nuttx/lib/stdio/lib_vsnprintf.c)2
-rw-r--r--nuttx/libc/stdio/lib_vsprintf.c (renamed from nuttx/lib/stdio/lib_vsprintf.c)4
-rw-r--r--nuttx/libc/stdio/lib_wrflush.c (renamed from nuttx/lib/stdio/lib_wrflush.c)2
-rw-r--r--nuttx/libc/stdio/lib_zeroinstream.c (renamed from nuttx/lib/stdio/lib_zeroinstream.c)2
-rw-r--r--nuttx/libc/stdlib/Make.defs (renamed from nuttx/lib/stdlib/Make.defs)2
-rw-r--r--nuttx/libc/stdlib/lib_abort.c (renamed from nuttx/lib/stdlib/lib_abort.c)2
-rw-r--r--nuttx/libc/stdlib/lib_abs.c (renamed from nuttx/lib/stdlib/lib_abs.c)2
-rw-r--r--nuttx/libc/stdlib/lib_imaxabs.c (renamed from nuttx/lib/stdlib/lib_imaxabs.c)2
-rw-r--r--nuttx/libc/stdlib/lib_labs.c (renamed from nuttx/lib/stdlib/lib_labs.c)2
-rw-r--r--nuttx/libc/stdlib/lib_llabs.c (renamed from nuttx/lib/stdlib/lib_llabs.c)2
-rw-r--r--nuttx/libc/stdlib/lib_qsort.c (renamed from nuttx/lib/stdlib/lib_qsort.c)2
-rw-r--r--nuttx/libc/stdlib/lib_rand.c277
-rw-r--r--nuttx/libc/string/Make.defs (renamed from nuttx/lib/string/Make.defs)12
-rw-r--r--nuttx/libc/string/lib_checkbase.c (renamed from nuttx/lib/string/lib_checkbase.c)2
-rw-r--r--nuttx/libc/string/lib_isbasedigit.c (renamed from nuttx/lib/string/lib_isbasedigit.c)2
-rw-r--r--nuttx/libc/string/lib_memccpy.c (renamed from nuttx/lib/string/lib_memccpy.c)2
-rw-r--r--nuttx/libc/string/lib_memchr.c (renamed from nuttx/lib/string/lib_memchr.c)2
-rw-r--r--nuttx/libc/string/lib_memcmp.c (renamed from nuttx/lib/string/lib_memcmp.c)6
-rw-r--r--nuttx/libc/string/lib_memcpy.c (renamed from nuttx/lib/string/lib_memcpy.c)2
-rw-r--r--nuttx/libc/string/lib_memmove.c (renamed from nuttx/lib/string/lib_memmove.c)17
-rw-r--r--nuttx/libc/string/lib_memset.c188
-rw-r--r--nuttx/libc/string/lib_skipspace.c (renamed from nuttx/lib/string/lib_skipspace.c)2
-rw-r--r--nuttx/libc/string/lib_strcasecmp.c (renamed from nuttx/lib/string/lib_strcasecmp.c)2
-rw-r--r--nuttx/libc/string/lib_strcasestr.c (renamed from nuttx/lib/string/lib_strcasestr.c)6
-rw-r--r--nuttx/libc/string/lib_strcat.c (renamed from nuttx/lib/string/lib_strcat.c)2
-rw-r--r--nuttx/libc/string/lib_strchr.c (renamed from nuttx/lib/string/lib_strchr.c)4
-rw-r--r--nuttx/libc/string/lib_strcmp.c (renamed from nuttx/lib/string/lib_strcmp.c)2
-rw-r--r--nuttx/libc/string/lib_strcpy.c (renamed from nuttx/lib/string/lib_strcpy.c)2
-rw-r--r--nuttx/libc/string/lib_strcspn.c (renamed from nuttx/lib/string/lib_strcspn.c)2
-rw-r--r--nuttx/libc/string/lib_strdup.c (renamed from nuttx/lib/string/lib_strdup.c)2
-rw-r--r--nuttx/libc/string/lib_strerror.c (renamed from nuttx/lib/string/lib_strerror.c)2
-rw-r--r--nuttx/libc/string/lib_strlen.c (renamed from nuttx/lib/string/lib_strlen.c)2
-rw-r--r--nuttx/libc/string/lib_strncasecmp.c (renamed from nuttx/lib/string/lib_strncasecmp.c)2
-rw-r--r--nuttx/libc/string/lib_strncat.c (renamed from nuttx/lib/string/lib_strncat.c)2
-rw-r--r--nuttx/libc/string/lib_strncmp.c (renamed from nuttx/lib/string/lib_strncmp.c)2
-rw-r--r--nuttx/libc/string/lib_strncpy.c (renamed from nuttx/lib/string/lib_strncpy.c)2
-rw-r--r--nuttx/libc/string/lib_strndup.c (renamed from nuttx/lib/string/lib_strndup.c)2
-rw-r--r--nuttx/libc/string/lib_strnlen.c (renamed from nuttx/lib/string/lib_strnlen.c)4
-rw-r--r--nuttx/libc/string/lib_strpbrk.c (renamed from nuttx/lib/string/lib_strpbrk.c)2
-rw-r--r--nuttx/libc/string/lib_strrchr.c (renamed from nuttx/lib/string/lib_strrchr.c)2
-rw-r--r--nuttx/libc/string/lib_strspn.c (renamed from nuttx/lib/string/lib_strspn.c)2
-rw-r--r--nuttx/libc/string/lib_strstr.c (renamed from nuttx/lib/string/lib_strstr.c)6
-rw-r--r--nuttx/libc/string/lib_strtod.c (renamed from nuttx/lib/string/lib_strtod.c)2
-rw-r--r--nuttx/libc/string/lib_strtok.c (renamed from nuttx/lib/string/lib_strtok.c)2
-rw-r--r--nuttx/libc/string/lib_strtokr.c (renamed from nuttx/lib/string/lib_strtokr.c)2
-rw-r--r--nuttx/libc/string/lib_strtol.c (renamed from nuttx/lib/string/lib_strtol.c)2
-rw-r--r--nuttx/libc/string/lib_strtoll.c (renamed from nuttx/lib/string/lib_strtoll.c)2
-rw-r--r--nuttx/libc/string/lib_strtoul.c (renamed from nuttx/lib/string/lib_strtoul.c)2
-rw-r--r--nuttx/libc/string/lib_strtoull.c (renamed from nuttx/lib/string/lib_strtoull.c)2
-rw-r--r--nuttx/libc/string/lib_vikmemcpy.c348
-rw-r--r--nuttx/libc/termios/Make.defs (renamed from nuttx/lib/termios/Make.defs)2
-rw-r--r--nuttx/libc/termios/lib_cfgetspeed.c (renamed from nuttx/lib/termios/lib_cfgetspeed.c)2
-rw-r--r--nuttx/libc/termios/lib_cfsetspeed.c (renamed from nuttx/lib/termios/lib_cfsetspeed.c)9
-rw-r--r--nuttx/libc/termios/lib_tcflush.c (renamed from nuttx/lib/termios/lib_tcflush.c)2
-rw-r--r--nuttx/libc/termios/lib_tcgetattr.c (renamed from nuttx/lib/termios/lib_tcgetattr.c)2
-rw-r--r--nuttx/libc/termios/lib_tcsetattr.c (renamed from nuttx/lib/termios/lib_tcsetattr.c)2
-rw-r--r--nuttx/libc/time/Make.defs (renamed from nuttx/lib/time/Make.defs)2
-rw-r--r--nuttx/libc/time/lib_calendar2utc.c (renamed from nuttx/lib/time/lib_calendar2utc.c)2
-rw-r--r--nuttx/libc/time/lib_daysbeforemonth.c (renamed from nuttx/lib/time/lib_daysbeforemonth.c)2
-rw-r--r--nuttx/libc/time/lib_gmtime.c (renamed from nuttx/lib/time/lib_gmtime.c)2
-rw-r--r--nuttx/libc/time/lib_gmtimer.c (renamed from nuttx/lib/time/lib_gmtimer.c)2
-rw-r--r--nuttx/libc/time/lib_isleapyear.c (renamed from nuttx/lib/time/lib_isleapyear.c)2
-rw-r--r--nuttx/libc/time/lib_mktime.c (renamed from nuttx/lib/time/lib_mktime.c)2
-rw-r--r--nuttx/libc/time/lib_strftime.c (renamed from nuttx/lib/time/lib_strftime.c)2
-rw-r--r--nuttx/libc/time/lib_time.c (renamed from nuttx/lib/time/lib_time.c)2
-rw-r--r--nuttx/libc/unistd/Make.defs (renamed from nuttx/lib/unistd/Make.defs)2
-rw-r--r--nuttx/libc/unistd/lib_chdir.c (renamed from nuttx/lib/unistd/lib_chdir.c)2
-rw-r--r--nuttx/libc/unistd/lib_getcwd.c (renamed from nuttx/lib/unistd/lib_getcwd.c)2
-rw-r--r--nuttx/libc/unistd/lib_getopt.c (renamed from nuttx/lib/unistd/lib_getopt.c)2
-rw-r--r--nuttx/libc/unistd/lib_getoptargp.c (renamed from nuttx/lib/unistd/lib_getoptargp.c)2
-rw-r--r--nuttx/libc/unistd/lib_getoptindp.c (renamed from nuttx/lib/unistd/lib_getoptindp.c)2
-rw-r--r--nuttx/libc/unistd/lib_getoptoptp.c (renamed from nuttx/lib/unistd/lib_getoptoptp.c)2
-rw-r--r--nuttx/libxx/Kconfig42
-rw-r--r--nuttx/libxx/Makefile73
-rw-r--r--nuttx/libxx/README.txt5
-rw-r--r--nuttx/libxx/libxx_cxa_atexit.cxx146
-rw-r--r--nuttx/libxx/libxx_eabi_atexit.cxx23
-rw-r--r--nuttx/libxx/libxx_internal.hxx67
-rw-r--r--nuttx/libxx/libxx_stdthrow.cxx74
-rw-r--r--nuttx/mm/Makefile17
-rw-r--r--nuttx/mm/Makefile.test18
-rw-r--r--nuttx/mm/mm_graninit.c2
-rw-r--r--nuttx/mm/mm_initialize.c6
-rw-r--r--nuttx/net/Makefile14
-rw-r--r--nuttx/net/net_poll.c2
-rw-r--r--nuttx/net/netdev_ioctl.c151
-rw-r--r--nuttx/net/uip/uip_icmpping.c2
-rw-r--r--nuttx/sched/Kconfig35
-rw-r--r--nuttx/sched/Makefile16
-rw-r--r--nuttx/sched/atexit.c16
-rw-r--r--nuttx/sched/clock_time2ticks.c2
-rw-r--r--nuttx/sched/env_clearenv.c2
-rw-r--r--nuttx/sched/env_internal.h2
-rw-r--r--nuttx/sched/env_release.c4
-rw-r--r--nuttx/sched/mq_open.c3
-rw-r--r--nuttx/sched/on_exit.c5
-rw-r--r--nuttx/sched/os_bringup.c19
-rw-r--r--nuttx/sched/os_start.c4
-rw-r--r--nuttx/sched/pause.c (renamed from nuttx/lib/stdio/lib_vdprintf.c)67
-rw-r--r--nuttx/sched/prctl.c6
-rw-r--r--nuttx/sched/pthread_create.c63
-rw-r--r--nuttx/sched/sched_getscheduler.c1
-rw-r--r--nuttx/sched/sched_releasetcb.c6
-rw-r--r--nuttx/sched/sem_open.c3
-rw-r--r--nuttx/sched/sleep.c2
-rw-r--r--nuttx/sched/task_exithook.c5
-rw-r--r--nuttx/sched/usleep.c2
-rw-r--r--nuttx/sched/work_thread.c6
-rw-r--r--nuttx/syscall/Makefile47
-rw-r--r--nuttx/tools/Config.mk157
-rw-r--r--nuttx/tools/Makefile.export12
-rw-r--r--nuttx/tools/Makefile.host112
-rw-r--r--nuttx/tools/README.txt111
-rw-r--r--nuttx/tools/b16.c121
-rw-r--r--nuttx/tools/cfgparser.c2
-rwxr-xr-xnuttx/tools/configure.sh92
-rwxr-xr-xnuttx/tools/copydir.bat102
-rwxr-xr-xnuttx/tools/copydir.sh (renamed from nuttx/tools/winlink.sh)2
-rw-r--r--nuttx/tools/define.bat178
-rwxr-xr-xnuttx/tools/define.sh8
-rwxr-xr-xnuttx/tools/incdir.bat165
-rwxr-xr-xnuttx/tools/incdir.sh40
-rwxr-xr-xnuttx/tools/link.bat89
-rw-r--r--nuttx/tools/mkconfig.c2
-rw-r--r--nuttx/tools/mkdeps.bat173
-rw-r--r--nuttx/tools/mkdeps.c721
-rwxr-xr-xnuttx/tools/mkdeps.sh2
-rwxr-xr-xnuttx/tools/mkromfsimg.sh2
-rw-r--r--nuttx/tools/mksymtab.c2
-rwxr-xr-xnuttx/tools/unlink.bat71
583 files changed, 26671 insertions, 4634 deletions
diff --git a/.gitignore b/.gitignore
index be32a0c63..ef0ed3c4c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -49,3 +49,4 @@ mavlink/include/mavlink/v0.9/
.swp
core
.gdbinit
+mkdeps
diff --git a/Makefile b/Makefile
index d9469bb49..f91e75d0b 100644
--- a/Makefile
+++ b/Makefile
@@ -28,12 +28,8 @@ UPLOADER = $(PX4BASE)/Tools/px_uploader.py
# What are we currently configured for?
#
CONFIGURED = $(PX4BASE)/.configured
-ifeq ($(wildcard $(CONFIGURED)),)
-# the $(CONFIGURED) target will make this a reality before building
-export TARGET = px4fmu
-$(shell echo $(TARGET) > $(CONFIGURED))
-else
-export TARGET = $(shell cat $(CONFIGURED))
+ifneq ($(wildcard $(CONFIGURED)),)
+export TARGET := $(shell cat $(CONFIGURED))
endif
#
@@ -59,12 +55,13 @@ $(FIRMWARE_BUNDLE): $(FIRMWARE_BINARY) $(MKFW) $(FIRMWARE_PROTOTYPE)
@$(MKFW) --prototype $(FIRMWARE_PROTOTYPE) \
--git_identity $(PX4BASE) \
--image $(FIRMWARE_BINARY) > $@
+
#
# Build the firmware binary.
#
.PHONY: $(FIRMWARE_BINARY)
-$(FIRMWARE_BINARY): configure_$(TARGET) setup_$(TARGET)
- @echo Building $@
+$(FIRMWARE_BINARY): setup_$(TARGET) configure-check
+ @echo Building $@ for $(TARGET)
@make -C $(NUTTX_SRC) -r $(MQUIET) all
@cp $(NUTTX_SRC)/nuttx.bin $@
@@ -73,19 +70,26 @@ $(FIRMWARE_BINARY): configure_$(TARGET) setup_$(TARGET)
# and makes it current.
#
configure_px4fmu:
-ifneq ($(TARGET),px4fmu)
+ @echo Configuring for px4fmu
@make -C $(PX4BASE) distclean
-endif
@cd $(NUTTX_SRC)/tools && /bin/sh configure.sh px4fmu/nsh
@echo px4fmu > $(CONFIGURED)
configure_px4io:
-ifneq ($(TARGET),px4io)
+ @echo Configuring for px4io
@make -C $(PX4BASE) distclean
-endif
@cd $(NUTTX_SRC)/tools && /bin/sh configure.sh px4io/io
@echo px4io > $(CONFIGURED)
+configure-check:
+ifeq ($(wildcard $(CONFIGURED)),)
+ @echo
+ @echo "Not configured - use 'make configure_px4fmu' or 'make configure_px4io' first"
+ @echo
+ @exit 1
+endif
+
+
#
# Per-configuration additional targets
#
@@ -96,6 +100,9 @@ setup_px4fmu:
setup_px4io:
+# fake target to make configure-check happy if TARGET is not set
+setup_:
+
#
# Firmware uploading.
#
diff --git a/apps/ChangeLog.txt b/apps/ChangeLog.txt
index 7375adccf..0695747f8 100644
--- a/apps/ChangeLog.txt
+++ b/apps/ChangeLog.txt
@@ -33,7 +33,7 @@
6.3 2011-05-15 Gregory Nutt <gnutt@nuttx.org>
- * apps/interpreter: Add a directory to hold interpreters. The Pascal add-
+ * apps/interpreter: Add a directory to hold interpreters. The Pascal add-
on module now installs and builds under this directory.
* apps/interpreter/ficl: Added logic to build Ficl (the "Forth Inspired
Command Language"). See http://ficl.sourceforge.net/.
@@ -349,7 +349,7 @@
* apps/NxWidgets/Kconfig: Add option to turn on the memory monitor
feature of the NxWidgets/NxWM unit tests.
-6.23 2012-xx-xx Gregory Nutt <gnutt@nuttx.org>
+6.23 2012-11-05 Gregory Nutt <gnutt@nuttx.org>
* vsn: Moved all NSH commands from vsn/ to system/. Deleted the vsn/
directory.
@@ -368,3 +368,70 @@
recent check-ins (Darcy Gong).
* apps/netutils/webclient/webclient.c: Fix another but that I introduced
when I was trying to add correct handling for loss of connection (Darcy Gong)
+ * apps/nshlib/nsh_telnetd.c: Add support for login to Telnet session via
+ username and password (Darcy Gong).
+ * apps/netutils/resolv/resolv.c (and files using the DNS resolver): Various
+ DNS address resolution improvements from Darcy Gong.
+ * apps/nshlib/nsh_netcmds.c: The ping command now passes a maximum round
+ trip time to uip_icmpping(). This allows pinging of hosts on complex
+ networks where the ICMP ECHO round trip time may exceed the ping interval.
+ * apps/examples/nxtext/nxtext_main.c: Fix bad conditional compilation
+ when CONFIG_NX_KBD is not defined. Submitted by Petteri Aimonen.
+ * apps/examples/nximage/nximage_main.c: Add a 5 second delay after the
+ NX logo is presented so that there is time for the image to be verified.
+ Suggested by Petteri Aimonen.
+ * apps/Makefile: Small change that reduces the number of shell invocations
+ by one (Mike Smith).
+ * apps/examples/elf: Test example for the ELF loader.
+ * apps/examples/elf: The ELF module test example appears fully functional.
+ * apps/netutils/json: Add a snapshot of the cJSON project. Contributed by
+ Darcy Gong.
+ * apps/examples/json: Test example for cJSON from Darcy Gong
+ * apps/nshlib/nsh_netinit.c: Fix static IP DNS problem (Darcy Gong)
+ * apps/netutils/resolv/resolv.c: DNS fixes from Darcy Gong.
+ * COPYING: Licensing information added.
+ * apps/netutils/codec and include/netutils/urldecode.h, base64.h, and md5.h:
+ A port of the BASE46, MD5 and URL CODEC library from Darcy Gong.
+ * nsnlib/nsh_codeccmd.c: NSH commands to use the CODEC library.
+ Contributed by Darcy Gong.
+ * apps/examples/wgetjson: Test example contributed by Darcy Gong
+ * apps/examples/cxxtest: A test for the uClibc++ library provided by
+ Qiang Yu and the RGMP team.
+ * apps/netutils/webclient, apps/netutils.codes, and apps/examples/wgetjson:
+ Add support for wget POST interface. Contributed by Darcy Gong.
+ * apps/examples/relays: A relay example contributed by Darcy Gong.
+ * apps/nshlib/nsh_netcmds: Add ifup and ifdown commands (from Darcy
+ Gong).
+ * apps/nshlib/nsh_netcmds: Extend the ifconfig command so that it
+ supports setting IP addresses, network masks, name server addresses,
+ and hardware address (from Darcy Gong).
+
+6.24 2012-12-20 Gregory Nutt <gnutt@nuttx.org>
+
+ * apps/examples/ostest/roundrobin.c: Replace large tables with
+ algorithmic prime number generation. This allows the roundrobin
+ test to run on platforms with minimal SRAM (Freddie Chopin).
+ * apps/nshlib/nsh_dbgcmds.c: Add hexdump command to dump the contents
+ of a file (or character device) to the console Contributed by Petteri
+ Aimonen.
+ * apps/examples/modbus: Fixes from Freddie Chopin
+ * apps/examples/modbus/Kconfig: Kconfig logic for FreeModBus contributed
+ by Freddie Chopin.
+ * Makefile, */Makefile: Various fixes for Windows native build. Now uses
+ make foreach loops instead of shell loops.
+ * apps/examples/elf/test/*/Makefile: OSX doesn't support install -D, use
+ mkdir -p then install without the -D. From Mike Smith.
+ * apps/examples/relays/Makefile: Reduced stack requirement (Darcy Gong).
+ * apps/nshlib and apps/netutils/dhcpc: Extend the NSH ifconfig command plus
+ various DHCPC improvements(Darcy Gong).
+ * apps/nshlib/nsh_apps.c: Fix compilation errors when CONFIG_NSH_DISABLEBG=y.
+ From Freddie Chopin.
+ * Rename CONFIG_PCODE and CONFIG_FICL as CONFIG_INTERPRETERS_PCODE and
+ CONFIG_INTERPRETERS_FICL for consistency with other configuration naming.
+ * apps/examples/keypadtest: A keypad test example contributed by Denis
+ Carikli.
+ * apps/examples/elf and nxflat: If CONFIG_BINFMT_EXEPATH is defined, these
+ tests will now use a relative path to the program and expect the binfmt/
+ logic to find the absolute path to the program using the PATH variable.
+
+6.25 2013-xx-xx Gregory Nutt <gnutt@nuttx.org>
diff --git a/apps/Makefile b/apps/Makefile
index 11d95bc19..f0de58e25 100644
--- a/apps/Makefile
+++ b/apps/Makefile
@@ -107,7 +107,7 @@ endif
# Create the list of available applications (INSTALLED_APPS)
define ADD_BUILTIN
-INSTALLED_APPS += ${shell if [ -r $1/Makefile ]; then echo "$1"; fi}
+ INSTALLED_APPS += $(if $(wildcard $1$(DELIM)Makefile),$1,)
endef
$(foreach BUILTIN, $(CONFIGURED_APPS), $(eval $(call ADD_BUILTIN,$(BUILTIN))))
@@ -120,8 +120,10 @@ INSTALLED_APPS += $(EXTERNAL_APPS)
# provided by the user (possibly as a symbolic link) to add libraries and
# applications to the standard build from the repository.
-INSTALLED_APPS += ${shell if [ -r external/Makefile ]; then echo "external"; fi}
-SUBDIRS += ${shell if [ -r external/Makefile ]; then echo "external"; fi}
+EXTERNAL_DIR := $(dir $(wildcard external$(DELIM)Makefile))
+
+INSTALLED_APPS += $(EXTERNAL_DIR)
+SUBDIRS += $(EXTERNAL_DIR)
# The final build target
@@ -133,48 +135,81 @@ all: $(BIN)
.PHONY: $(INSTALLED_APPS) context depend clean distclean
$(INSTALLED_APPS):
- @$(MAKE) -C $@ TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)";
+ $(Q) $(MAKE) -C $@ TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)"
$(BIN): $(INSTALLED_APPS)
- @( for obj in $(OBJS) ; do \
- $(call ARCHIVE, $@, $${obj}); \
- done ; )
.context:
- @for dir in $(INSTALLED_APPS) ; do \
+ifeq ($(CONFIG_WINDOWS_NATIVE),y)
+ $(Q) for %%G in ($(INSTALLED_APPS)) do ( \
+ if exist %%G\.context del /f /q %%G\.context \
+ $(MAKE) -C %%G TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" context \
+ )
+else
+ $(Q) for dir in $(INSTALLED_APPS) ; do \
rm -f $$dir/.context ; \
- $(MAKE) -C $$dir TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" context ; \
+ $(MAKE) -C $$dir TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" context ; \
done
- @touch $@
+endif
+ $(Q) touch $@
context: .context
.depend: context Makefile $(SRCS)
- @for dir in $(INSTALLED_APPS) ; do \
+ifeq ($(CONFIG_WINDOWS_NATIVE),y)
+ $(Q) for %%G in ($(INSTALLED_APPS)) do ( \
+ if exist %%G\.depend del /f /q %%G\.depend \
+ $(MAKE) -C %%G TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" depend \
+ )
+else
+ $(Q) for dir in $(INSTALLED_APPS) ; do \
rm -f $$dir/.depend ; \
- $(MAKE) -C $$dir TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" depend ; \
+ $(MAKE) -C $$dir TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" depend ; \
done
- @touch $@
+endif
+ $(Q) touch $@
depend: .depend
clean:
- @for dir in $(SUBDIRS) ; do \
+ifeq ($(CONFIG_WINDOWS_NATIVE),y)
+ $(Q) for %%G in ($(SUBDIRS)) do ( \
+ $(MAKE) -C %%G clean TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" \
+ )
+else
+ $(Q) for dir in $(SUBDIRS) ; do \
$(MAKE) -C $$dir clean TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)"; \
done
- @rm -f $(BIN) *~ .*.swp *.o
+endif
+ $(call DELFILE, $(BIN))
$(call CLEAN)
distclean: # clean
- @for dir in $(SUBDIRS) ; do \
+ifeq ($(CONFIG_WINDOWS_NATIVE),y)
+ $(Q) for %%G in ($(SUBDIRS)) do ( \
+ $(MAKE) -C %%G distclean TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" \
+ )
+ $(call DELFILE, .config)
+ $(call DELFILE, .context)
+ $(call DELFILE, .depend)
+ $(Q) ( if exist external ( \
+ echo ********************************************************" \
+ echo * The external directory/link must be removed manually *" \
+ echo ********************************************************" \
+ )
+else
+ $(Q) for dir in $(SUBDIRS) ; do \
$(MAKE) -C $$dir distclean TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)"; \
done
- @rm -f .config .context .depend
- @( if [ -e external ]; then \
+ $(call DELFILE, .config)
+ $(call DELFILE, .context)
+ $(call DELFILE, .depend)
+ $(Q) ( if [ -e external ]; then \
echo "********************************************************"; \
echo "* The external directory/link must be removed manually *"; \
echo "********************************************************"; \
fi; \
)
+endif
diff --git a/apps/examples/Kconfig b/apps/examples/Kconfig
index 865268add..ae5f0a61a 100644
--- a/apps/examples/Kconfig
+++ b/apps/examples/Kconfig
@@ -3,206 +3,60 @@
# see misc/tools/kconfig-language.txt.
#
-menu "ADC Example"
source "$APPSDIR/examples/adc/Kconfig"
-endmenu
-
-menu "Buttons Example"
source "$APPSDIR/examples/buttons/Kconfig"
-endmenu
-
-menu "CAN Example"
source "$APPSDIR/examples/can/Kconfig"
-endmenu
-
-menu "USB CDC/ACM Class Driver Example"
source "$APPSDIR/examples/cdcacm/Kconfig"
-endmenu
-
-menu "USB composite Class Driver Example"
source "$APPSDIR/examples/composite/Kconfig"
-endmenu
-
-menu "DHCP Server Example"
+source "$APPSDIR/examples/cxxtest/Kconfig"
source "$APPSDIR/examples/dhcpd/Kconfig"
-endmenu
-
-menu "FTP Client Example"
+source "$APPSDIR/examples/elf/Kconfig"
source "$APPSDIR/examples/ftpc/Kconfig"
-endmenu
-
-menu "FTP Server Example"
source "$APPSDIR/examples/ftpd/Kconfig"
-endmenu
-
-menu "\"Hello, World!\" Example"
source "$APPSDIR/examples/hello/Kconfig"
-endmenu
-
-menu "\"Hello, World!\" C++ Example"
source "$APPSDIR/examples/helloxx/Kconfig"
-endmenu
-
-menu "USB HID Keyboard Example"
+source "$APPSDIR/examples/json/Kconfig"
source "$APPSDIR/examples/hidkbd/Kconfig"
-endmenu
-
-menu "IGMP Example"
+source "$APPSDIR/examples/keypadtest/Kconfig"
source "$APPSDIR/examples/igmp/Kconfig"
-endmenu
-
-menu "LCD Read/Write Example"
source "$APPSDIR/examples/lcdrw/Kconfig"
-endmenu
-
-menu "Memory Management Example"
source "$APPSDIR/examples/mm/Kconfig"
-endmenu
-
-menu "File System Mount Example"
source "$APPSDIR/examples/mount/Kconfig"
-endmenu
-
-menu "FreeModBus Example"
source "$APPSDIR/examples/modbus/Kconfig"
-endmenu
-
-menu "Network Test Example"
source "$APPSDIR/examples/nettest/Kconfig"
-endmenu
-
-menu "NuttShell (NSH) Example"
source "$APPSDIR/examples/nsh/Kconfig"
-endmenu
-
-menu "NULL Example"
source "$APPSDIR/examples/null/Kconfig"
-endmenu
-
-menu "NX Graphics Example"
source "$APPSDIR/examples/nx/Kconfig"
-endmenu
-
-menu "NxConsole Example"
source "$APPSDIR/examples/nxconsole/Kconfig"
-endmenu
-
-menu "NXFFS File System Example"
source "$APPSDIR/examples/nxffs/Kconfig"
-endmenu
-
-menu "NXFLAT Example"
source "$APPSDIR/examples/nxflat/Kconfig"
-endmenu
-
-menu "NX Graphics \"Hello, World!\" Example"
source "$APPSDIR/examples/nxhello/Kconfig"
-endmenu
-
-menu "NX Graphics image Example"
source "$APPSDIR/examples/nximage/Kconfig"
-endmenu
-
-menu "NX Graphics lines Example"
source "$APPSDIR/examples/nxlines/Kconfig"
-endmenu
-
-menu "NX Graphics Text Example"
source "$APPSDIR/examples/nxtext/Kconfig"
-endmenu
-
-menu "OS Test Example"
source "$APPSDIR/examples/ostest/Kconfig"
-endmenu
-
-menu "Pascal \"Hello, World!\"example"
source "$APPSDIR/examples/pashello/Kconfig"
-endmenu
-
-menu "Pipe Example"
source "$APPSDIR/examples/pipe/Kconfig"
-endmenu
-
-menu "Poll Example"
source "$APPSDIR/examples/poll/Kconfig"
-endmenu
-
-menu "Pulse Width Modulation (PWM) Example"
source "$APPSDIR/examples/pwm/Kconfig"
-endmenu
-
-menu "Quadrature Encoder Example"
source "$APPSDIR/examples/qencoder/Kconfig"
-endmenu
-
-menu "RGMP Example"
+source "$APPSDIR/examples/relays/Kconfig"
source "$APPSDIR/examples/rgmp/Kconfig"
-endmenu
-
-menu "ROMFS Example"
source "$APPSDIR/examples/romfs/Kconfig"
-endmenu
-
-menu "sendmail Example"
source "$APPSDIR/examples/sendmail/Kconfig"
-endmenu
-
-menu "Serial Loopback Example"
source "$APPSDIR/examples/serloop/Kconfig"
-endmenu
-
-menu "Telnet Daemon Example"
source "$APPSDIR/examples/telnetd/Kconfig"
-endmenu
-
-menu "THTTPD Web Server Example"
source "$APPSDIR/examples/thttpd/Kconfig"
-endmenu
-
-menu "TIFF Generation Example"
source "$APPSDIR/examples/tiff/Kconfig"
-endmenu
-
-menu "Touchscreen Example"
source "$APPSDIR/examples/touchscreen/Kconfig"
-endmenu
-
-menu "UDP Example"
source "$APPSDIR/examples/udp/Kconfig"
-endmenu
-
-menu "UDP Discovery Daemon Example"
source "$APPSDIR/examples/discover/Kconfig"
-endmenu
-
-menu "uIP Web Server Example"
source "$APPSDIR/examples/uip/Kconfig"
-endmenu
-
-menu "USB Serial Test Example"
source "$APPSDIR/examples/usbserial/Kconfig"
-endmenu
-
-menu "USB Mass Storage Class Example"
source "$APPSDIR/examples/usbstorage/Kconfig"
-endmenu
-
-menu "USB Serial Terminal Example"
source "$APPSDIR/examples/usbterm/Kconfig"
-endmenu
-
-menu "Watchdog timer Example"
source "$APPSDIR/examples/watchdog/Kconfig"
-endmenu
-
-menu "wget Example"
source "$APPSDIR/examples/wget/Kconfig"
-endmenu
-
-menu "WLAN Example"
+source "$APPSDIR/examples/wgetjson/Kconfig"
source "$APPSDIR/examples/wlan/Kconfig"
-endmenu
-
-menu "XML RPC Example"
source "$APPSDIR/examples/xmlrpc/Kconfig"
-endmenu
diff --git a/apps/examples/Make.defs b/apps/examples/Make.defs
index d03b976d2..91f1331df 100644
--- a/apps/examples/Make.defs
+++ b/apps/examples/Make.defs
@@ -54,6 +54,10 @@ ifeq ($(CONFIG_EXAMPLES_COMPOSITE),y)
CONFIGURED_APPS += examples/composite
endif
+ifeq ($(CONFIG_EXAMPLES_CXXTEST),y)
+CONFIGURED_APPS += examples/cxxtest
+endif
+
ifeq ($(CONFIG_EXAMPLES_DHCPD),y)
CONFIGURED_APPS += examples/dhcpd
endif
@@ -62,6 +66,10 @@ ifeq ($(CONFIG_EXAMPLES_DISCOVER),y)
CONFIGURED_APPS += examples/discover
endif
+ifeq ($(CONFIG_EXAMPLES_ELF),y)
+CONFIGURED_APPS += examples/elf
+endif
+
ifeq ($(CONFIG_EXAMPLES_FTPC),y)
CONFIGURED_APPS += examples/ftpc
endif
@@ -86,6 +94,14 @@ ifeq ($(CONFIG_EXAMPLES_IGMP),y)
CONFIGURED_APPS += examples/igmp
endif
+ifeq ($(CONFIG_EXAMPLES_JSON),y)
+CONFIGURED_APPS += examples/json
+endif
+
+ifeq ($(CONFIG_EXAMPLES_KEYPADTEST),y)
+CONFIGURED_APPS += examples/keypadtest
+endif
+
ifeq ($(CONFIG_EXAMPLES_LCDRW),y)
CONFIGURED_APPS += examples/lcdrw
endif
@@ -94,6 +110,10 @@ ifeq ($(CONFIG_EXAMPLES_MM),y)
CONFIGURED_APPS += examples/mm
endif
+ifeq ($(CONFIG_EXAMPLES_MODBUS),y)
+CONFIGURED_APPS += examples/modbus
+endif
+
ifeq ($(CONFIG_EXAMPLES_MOUNT),y)
CONFIGURED_APPS += examples/mount
endif
@@ -166,6 +186,10 @@ ifeq ($(CONFIG_EXAMPLES_QENCODER),y)
CONFIGURED_APPS += examples/qencoder
endif
+ifeq ($(CONFIG_EXAMPLES_RELAYS),y)
+CONFIGURED_APPS += examples/relays
+endif
+
ifeq ($(CONFIG_EXAMPLES_RGMP),y)
CONFIGURED_APPS += examples/rgmp
endif
@@ -226,6 +250,10 @@ ifeq ($(CONFIG_EXAMPLES_WGET),y)
CONFIGURED_APPS += examples/wget
endif
+ifeq ($(CONFIG_EXAMPLES_WGETJSON),y)
+CONFIGURED_APPS += examples/wgetjson
+endif
+
ifeq ($(CONFIG_EXAMPLES_WLAN),y)
CONFIGURED_APPS += examples/wlan
endif
diff --git a/apps/examples/Makefile b/apps/examples/Makefile
index 453f99ce7..bdbfd4de8 100644
--- a/apps/examples/Makefile
+++ b/apps/examples/Makefile
@@ -37,12 +37,12 @@
# Sub-directories
-SUBDIRS = adc buttons can cdcacm composite dhcpd discover ftpc ftpd hello
-SUBDIRS += helloxx hidkbd igmp lcdrw mm modbus mount nettest nsh null nx
-SUBDIRS += nxconsole nxffs nxflat nxhello nximage nxlines nxtext ostest
-SUBDIRS += pashello pipe poll pwm qencoder rgmp romfs serloop telnetd
-SUBDIRS += thttpd tiff touchscreen udp uip usbserial sendmail usbstorage
-SUBDIRS += usbterm watchdog wget wlan
+SUBDIRS = adc buttons can cdcacm composite cxxtest dhcpd discover elf ftpc
+SUBDIRS += ftpd hello helloxx hidkbd igmp json keypadtest lcdrw mm modbus mount
+SUBDIRS += nettest nsh null nx nxconsole nxffs nxflat nxhello nximage
+SUBDIRS += nxlines nxtext ostest pashello pipe poll pwm qencoder relays
+SUBDIRS += rgmp romfs serloop telnetd thttpd tiff touchscreen udp uip
+SUBDIRS += usbserial sendmail usbstorage usbterm watchdog wget wgetjson wlan
# Sub-directories that might need context setup. Directories may need
# context setup for a variety of reasons, but the most common is because
@@ -57,8 +57,8 @@ SUBDIRS += usbterm watchdog wget wlan
CNTXTDIRS = pwm
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
-CNTXTDIRS += adc can cdcacm composite discover ftpd dhcpd modbus nettest
-CNTXTDIRS += qencoder telnetd watchdog
+CNTXTDIRS += adc can cdcacm composite cxxtest dhcpd discover ftpd json keypadtest
+CNTXTDIRS += modbus nettest nxlines relays qencoder telnetd watchdog wgetjson
endif
ifeq ($(CONFIG_EXAMPLES_HELLO_BUILTIN),y)
@@ -79,9 +79,6 @@ endif
ifeq ($(CONFIG_EXAMPLES_NXIMAGE_BUILTIN),y)
CNTXTDIRS += nximage
endif
-ifeq ($(CONFIG_EXAMPLES_LINES_BUILTIN),y)
-CNTXTDIRS += nxlines
-endif
ifeq ($(CONFIG_EXAMPLES_NXTEXT_BUILTIN),y)
CNTXTDIRS += nxtext
endif
@@ -105,27 +102,25 @@ all: nothing
.PHONY: nothing context depend clean distclean
+define SDIR_template
+$(1)_$(2):
+ $(Q) $(MAKE) -C $(1) $(2) TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)"
+endef
+
+$(foreach SDIR, $(CNTXTDIRS), $(eval $(call SDIR_template,$(SDIR),context)))
+$(foreach SDIR, $(SUBDIRS), $(eval $(call SDIR_template,$(SDIR),depend)))
+$(foreach SDIR, $(SUBDIRS), $(eval $(call SDIR_template,$(SDIR),clean)))
+$(foreach SDIR, $(SUBDIRS), $(eval $(call SDIR_template,$(SDIR),distclean)))
+
nothing:
-context:
- @for dir in $(CNTXTDIRS) ; do \
- $(MAKE) -C $$dir context TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)"; \
- done
-
-depend:
- @for dir in $(SUBDIRS) ; do \
- $(MAKE) -C $$dir depend TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)"; \
- done
-
-clean:
- @for dir in $(SUBDIRS) ; do \
- $(MAKE) -C $$dir clean TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)"; \
- done
-
-distclean: clean
- @for dir in $(SUBDIRS) ; do \
- $(MAKE) -C $$dir distclean TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)"; \
- done
+context: $(foreach SDIR, $(CNTXTDIRS), $(SDIR)_context)
+
+depend: $(foreach SDIR, $(SUBDIRS), $(SDIR)_depend)
+
+clean: $(foreach SDIR, $(SUBDIRS), $(SDIR)_clean)
+
+distclean: clean $(foreach SDIR, $(SUBDIRS), $(SDIR)_distclean)
-include Make.dep
diff --git a/apps/examples/README.txt b/apps/examples/README.txt
index 763427e32..e40a63be9 100644
--- a/apps/examples/README.txt
+++ b/apps/examples/README.txt
@@ -239,6 +239,29 @@ examples/composite
CONFIG_EXAMPLES_COMPOSITE_TRACEINTERRUPTS
Show interrupt-related events.
+examples/cxxtest
+^^^^^^^^^^^^^^^^
+
+ This is a test of the C++ standard library. At present a port of the uClibc++
+ C++ library is available. Due to licensinging issues, the uClibc++ C++ library
+ is not included in the NuttX source tree by default, but must be installed
+ (see misc/uClibc++/README.txt for installation).
+
+ The NuttX setting that are required include:
+
+ CONFIG_HAVE_CXX=y
+ CONFIG_HAVE_CXXINITIALIZE=y
+ CONFIG_UCLIBCXX=y
+
+ Additional uClibc++ settings may be required in your build environment.
+
+ The uClibc++ test includes simple test of:
+
+ - iostreams,
+ - STL,
+ - RTTI, and
+ - Exceptions
+
examples/dhcpd
^^^^^^^^^^^^^^
@@ -297,6 +320,68 @@ examples/discover
CONFIG_EXAMPLES_DISCOVER_DRIPADDR - Router IP address
CONFIG_EXAMPLES_DISCOVER_NETMASK - Network Mask
+examples/elf
+^^^^^^^^^^^^
+
+ This example builds a small ELF loader test case. This includes several
+ test programs under examples/elf tests. These tests are build using
+ the relocatable ELF format and installed in a ROMFS file system. At run time,
+ each program in the ROMFS file system is executed. Requires CONFIG_ELF.
+ Other configuration options:
+
+ CONFIG_EXAMPLES_ELF_DEVMINOR - The minor device number of the ROMFS block.
+ For example, the N in /dev/ramN. Used for registering the RAM block driver
+ that will hold the ROMFS file system containing the ELF executables to be
+ tested. Default: 0
+
+ CONFIG_EXAMPLES_ELF_DEVPATH - The path to the ROMFS block driver device. This
+ must match EXAMPLES_ELF_DEVMINOR. Used for registering the RAM block driver
+ that will hold the ROMFS file system containing the ELF executables to be
+ tested. Default: "/dev/ram0"
+
+ NOTES:
+
+ 1. CFLAGS should be provided in CELFFLAGS. RAM and FLASH memory regions
+ may require long allcs. For ARM, this might be:
+
+ CELFFLAGS = $(CFLAGS) -mlong-calls
+
+ Similarly for C++ flags which must be provided in CXXELFFLAGS.
+
+ 2. Your top-level nuttx/Make.defs file must alos include an approproate definition,
+ LDELFFLAGS, to generate a relocatable ELF object. With GNU LD, this should
+ include '-r' and '-e main' (or _main on some platforms).
+
+ LDELFFLAGS = -r -e main
+
+ If you use GCC to link, you make also need to include '-nostdlib' or
+ '-nostartfiles' and '-nodefaultlibs'.
+
+ 3. This example also requires genromfs. genromfs can be build as part of the
+ nuttx toolchain. Or can built from the genromfs sources that can be found
+ at misc/tools/genromfs-0.5.2.tar.gz. In any event, the PATH variable must
+ include the path to the genromfs executable.
+
+ 4. ELF size: The ELF files in this example are, be default, quite large
+ because they include a lot of "build garbage". You can greatly reduce the
+ size of the ELF binaries are using the 'objcopy --strip-unneeded' command to
+ remove un-necessary information from the ELF files.
+
+ 5. Simulator. You cannot use this example with the the NuttX simulator on
+ Cygwin. That is because the Cygwin GCC does not generate ELF file but
+ rather some Windows-native binary format.
+
+ If you really want to do this, you can create a NuttX x86 buildroot toolchain
+ and use that be build the ELF executables for the ROMFS file system.
+
+ 6. Linker scripts. You might also want to use a linker scripts to combine
+ sections better. An example linker script is at nuttx/binfmt/libelf/gnu-elf.ld.
+ That example might have to be tuned for your particular linker output to
+ position additional sections correctly. The GNU LD LDELFFLAGS then might
+ be:
+
+ LDELFFLAGS = -r -e main -T$(TOPDIR)/binfmt/libelf/gnu-elf.ld
+
examples/ftpc
^^^^^^^^^^^^^
@@ -482,6 +567,32 @@ examples/igmp
CONFIGURED_APPS += uiplib
+examples/json
+^^^^^^^^^^^^^
+
+ This example exercises the cJSON implementation at apps/netutils/json.
+ This example contains logic taken from the cJSON project:
+
+ http://sourceforge.net/projects/cjson/
+
+ The example corresponds to SVN revision r42 (with lots of changes for
+ NuttX coding standards). As of r42, the SVN repository was last updated
+ on 2011-10-10 so I presume that the code is stable and there is no risk
+ of maintaining duplicate logic in the NuttX repository.
+
+examples/keypadtest
+^^^^^^^^^^^^^^^^^^^
+
+ This is a generic keypad test example. It is similar to the USB hidkbd
+ example, but makes no assumptions about the underlying keyboard interface.
+ It uses the interfaces of include/nuttx/input/keypad.h.
+
+ CONFIG_EXAMPLES_KEYPADTEST - Selects the keypadtest example (only need
+ if the mconf/Kconfig tool is used.
+
+ CONFIG_EXAMPLES_KEYPAD_DEVNAME - The name of the keypad device that will
+ be opened in order to perform the keypad test. Default: "/dev/keypad"
+
examples/lcdrw
^^^^^^^^^^^^^^
@@ -496,6 +607,11 @@ examples/lcdrw
* CONFIG_EXAMPLES_LDCRW_YRES
LCD Y resolution. Default: 320
+ NOTE: This test exercises internal lcd driver interfaces. As such, it
+ relies on internal OS interfaces that are not normally available to a
+ user-space program. As a result, this example cannot be used if a
+ NuttX is built as a protected, supervisor kernel (CONFIG_NUTTX_KERNEL).
+
examples/mm
^^^^^^^^^^^
@@ -838,8 +954,6 @@ examplex/nxlines
The following configuration options can be selected:
- CONFIG_EXAMPLES_NXLINES_BUILTIN -- Build the NXLINES example as a "built-in"
- that can be executed from the NSH command line
CONFIG_EXAMPLES_NXLINES_VPLANE -- The plane to select from the frame-
buffer driver for use in the test. Default: 0
CONFIG_EXAMPLES_NXLINES_DEVNO - The LCD device to select from the LCD
@@ -877,6 +991,9 @@ examplex/nxlines
FAR struct fb_vtable_s *up_nxdrvinit(unsigned int devno);
#endif
+ CONFIG_NSH_BUILTIN_APPS - Build the NX lines examples as an NSH built-in
+ function.
+
examples/nxtext
^^^^^^^^^^^^^^^
@@ -984,6 +1101,17 @@ examples/ostest
Specifies the number of threads to create in the barrier
test. The default is 8 but a smaller number may be needed on
systems without sufficient memory to start so many threads.
+ * CONFIG_EXAMPLES_OSTEST_RR_RANGE
+ During round-robin scheduling test two threads are created. Each of the threads
+ searches for prime numbers in the configurable range, doing that configurable
+ number of times.
+ This value specifies the end of search range and together with number of runs
+ allows to configure the length of this test - it should last at least a few
+ tens of seconds. Allowed values [1; 32767], default 10000
+ * CONFIG_EXAMPLES_OSTEST_RR_RUNS
+ During round-robin scheduling test two threads are created. Each of the threads
+ searches for prime numbers in the configurable range, doing that configurable
+ number of times.
examples/pashello
^^^^^^^^^^^^^^^^^
@@ -1110,17 +1238,28 @@ examples/qencoder
Specific configuration options for this example include:
- CONFIG_EXAMPLES_QENCODER_DEVPATH - The path to the QE device. Default:
- /dev/qe0
- CONFIG_EXAMPLES_QENCODER_NSAMPLES - If CONFIG_NSH_BUILTIN_APPS
- is defined, then the number of samples is provided on the command line
- and this value is ignored. Otherwise, this number of samples is
- collected and the program terminates. Default: Samples are collected
- indefinitely.
- CONFIG_EXAMPLES_QENCODER_DELAY - This value provides the delay (in
- milliseonds) between each sample. If CONFIG_NSH_BUILTIN_APPS
- is defined, then this value is the default delay if no other delay is
- provided on the command line. Default: 100 milliseconds
+ CONFIG_EXAMPLES_QENCODER_DEVPATH - The path to the QE device. Default:
+ /dev/qe0
+ CONFIG_EXAMPLES_QENCODER_NSAMPLES - If CONFIG_NSH_BUILTIN_APPS
+ is defined, then the number of samples is provided on the command line
+ and this value is ignored. Otherwise, this number of samples is
+ collected and the program terminates. Default: Samples are collected
+ indefinitely.
+ CONFIG_EXAMPLES_QENCODER_DELAY - This value provides the delay (in
+ milliseonds) between each sample. If CONFIG_NSH_BUILTIN_APPS
+ is defined, then this value is the default delay if no other delay is
+ provided on the command line. Default: 100 milliseconds
+
+examples/relays
+^^^^^^^^^^^^^^^
+
+ Requires CONFIG_ARCH_RELAYS.
+ Contributed by Darcy Gong.
+
+ NOTE: This test exercises internal relay driver interfaces. As such, it
+ relies on internal OS interfaces that are not normally available to a
+ user-space program. As a result, this example cannot be used if a
+ NuttX is built as a protected, supervisor kernel (CONFIG_NUTTX_KERNEL).
examples/rgmp
^^^^^^^^^^^^^
@@ -1672,7 +1811,16 @@ examples/wget
CONFIGURED_APPS += resolv
CONFIGURED_APPS += webclient
+examples/wget
+^^^^^^^^^^^^^
+
+ Uses wget to get a JSON encoded file, then decodes the file.
+
+ CONFIG_EXAMPLES_WDGETJSON_MAXSIZE - Max. JSON Buffer Size
+ CONFIG_EXAMPLES_EXAMPLES_WGETJSON_URL - wget URL
+
examples/xmlrpc
+^^^^^^^^^^^^^^^
This example exercises the "Embeddable Lightweight XML-RPC Server" which
is discussed at:
diff --git a/apps/examples/adc/Makefile b/apps/examples/adc/Makefile
index 6357dfc3d..69862b383 100644
--- a/apps/examples/adc/Makefile
+++ b/apps/examples/adc/Makefile
@@ -1,7 +1,7 @@
############################################################################
# apps/examples/adc/Makefile
#
-# Copyright (C) 2011 Gregory Nutt. All rights reserved.
+# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
@@ -48,10 +48,14 @@ COBJS = $(CSRCS:.c=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS)
OBJS = $(AOBJS) $(COBJS)
+ifeq ($(CONFIG_WINDOWS_NATIVE),y)
+ BIN = ..\..\libapps$(LIBEXT)
+else
ifeq ($(WINTOOL),y)
- BIN = "${shell cygpath -w $(APPDIR)/libapps$(LIBEXT)}"
+ BIN = ..\\..\\libapps$(LIBEXT)
else
- BIN = "$(APPDIR)/libapps$(LIBEXT)"
+ BIN = ../../libapps$(LIBEXT)
+endif
endif
ROOTDEPPATH = --dep-path .
@@ -76,9 +80,7 @@ $(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
.built: $(OBJS)
- @( for obj in $(OBJS) ; do \
- $(call ARCHIVE, $(BIN), $${obj}); \
- done ; )
+ $(call ARCHIVE, $(BIN), $(OBJS))
@touch .built
.context:
@@ -90,16 +92,17 @@ endif
context: .context
.depend: Makefile $(SRCS)
- @$(MKDEP) $(ROOTDEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
+ @$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
- @rm -f *.o *~ .*.swp .built
+ $(call DELFILE, .built)
$(call CLEAN)
distclean: clean
- @rm -f Make.dep .depend
+ $(call DELFILE, Make.dep)
+ $(call DELFILE, .depend)
-include Make.dep
diff --git a/apps/examples/adc/adc_main.c b/apps/examples/adc/adc_main.c
index 404fba8c1..553658fee 100644
--- a/apps/examples/adc/adc_main.c
+++ b/apps/examples/adc/adc_main.c
@@ -289,7 +289,7 @@ int adc_main(int argc, char *argv[])
{
message("adc_main: open %s failed: %d\n", g_adcstate.devpath, errno);
errval = 2;
- goto errout_with_dev;
+ goto errout;
}
/* Now loop the appropriate number of times, displaying the collected
@@ -357,6 +357,11 @@ int adc_main(int argc, char *argv[])
}
}
+ close(fd);
+ return OK;
+
+ /* Error exits */
+
errout_with_dev:
close(fd);
diff --git a/apps/examples/buttons/Makefile b/apps/examples/buttons/Makefile
index 25d1ef2c2..77c1cd67d 100644
--- a/apps/examples/buttons/Makefile
+++ b/apps/examples/buttons/Makefile
@@ -1,7 +1,7 @@
############################################################################
# apps/examples/buttons/Makefile
#
-# Copyright (C) 2011 Gregory Nutt. All rights reserved.
+# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
@@ -48,10 +48,14 @@ COBJS = $(CSRCS:.c=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS)
OBJS = $(AOBJS) $(COBJS)
+ifeq ($(CONFIG_WINDOWS_NATIVE),y)
+ BIN = ..\..\libapps$(LIBEXT)
+else
ifeq ($(WINTOOL),y)
- BIN = "${shell cygpath -w $(APPDIR)/libapps$(LIBEXT)}"
+ BIN = ..\\..\\libapps$(LIBEXT)
else
- BIN = "$(APPDIR)/libapps$(LIBEXT)"
+ BIN = ../../libapps$(LIBEXT)
+endif
endif
ROOTDEPPATH = --dep-path .
@@ -76,9 +80,7 @@ $(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
.built: $(OBJS)
- @( for obj in $(OBJS) ; do \
- $(call ARCHIVE, $(BIN), $${obj}); \
- done ; )
+ $(call ARCHIVE, $(BIN), $(OBJS))
@touch .built
.context:
@@ -90,16 +92,17 @@ endif
context: .context
.depend: Makefile $(SRCS)
- @$(MKDEP) $(ROOTDEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
+ @$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
- @rm -f *.o *~ .*.swp .built
+ $(call DELFILE, .built)
$(call CLEAN)
distclean: clean
- @rm -f Make.dep .depend
+ $(call DELFILE, Make.dep)
+ $(call DELFILE, .depend)
-include Make.dep
diff --git a/apps/examples/can/Makefile b/apps/examples/can/Makefile
index c6dc5af84..8924797e3 100644
--- a/apps/examples/can/Makefile
+++ b/apps/examples/can/Makefile
@@ -1,7 +1,7 @@
############################################################################
# apps/examples/can/Makefile
#
-# Copyright (C) 2011 Gregory Nutt. All rights reserved.
+# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
@@ -48,10 +48,14 @@ COBJS = $(CSRCS:.c=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS)
OBJS = $(AOBJS) $(COBJS)
+ifeq ($(CONFIG_WINDOWS_NATIVE),y)
+ BIN = ..\..\libapps$(LIBEXT)
+else
ifeq ($(WINTOOL),y)
- BIN = "${shell cygpath -w $(APPDIR)/libapps$(LIBEXT)}"
+ BIN = ..\\..\\libapps$(LIBEXT)
else
- BIN = "$(APPDIR)/libapps$(LIBEXT)"
+ BIN = ../../libapps$(LIBEXT)
+endif
endif
ROOTDEPPATH = --dep-path .
@@ -76,9 +80,7 @@ $(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
.built: $(OBJS)
- @( for obj in $(OBJS) ; do \
- $(call ARCHIVE, $(BIN), $${obj}); \
- done ; )
+ $(call ARCHIVE, $(BIN), $(OBJS))
@touch .built
.context:
@@ -90,16 +92,17 @@ endif
context: .context
.depend: Makefile $(SRCS)
- @$(MKDEP) $(ROOTDEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
+ @$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
- @rm -f *.o *~ .*.swp .built
+ $(call DELFILE, .built)
$(call CLEAN)
distclean: clean
- @rm -f Make.dep .depend
+ $(call DELFILE, Make.dep)
+ $(call DELFILE, .depend)
-include Make.dep
diff --git a/apps/examples/cdcacm/Makefile b/apps/examples/cdcacm/Makefile
index 3fa886d56..e8d03807d 100644
--- a/apps/examples/cdcacm/Makefile
+++ b/apps/examples/cdcacm/Makefile
@@ -48,10 +48,14 @@ COBJS = $(CSRCS:.c=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS)
OBJS = $(AOBJS) $(COBJS)
+ifeq ($(CONFIG_WINDOWS_NATIVE),y)
+ BIN = ..\..\libapps$(LIBEXT)
+else
ifeq ($(WINTOOL),y)
- BIN = "${shell cygpath -w $(APPDIR)/libapps$(LIBEXT)}"
+ BIN = ..\\..\\libapps$(LIBEXT)
else
- BIN = "$(APPDIR)/libapps$(LIBEXT)"
+ BIN = ../../libapps$(LIBEXT)
+endif
endif
ROOTDEPPATH = --dep-path .
@@ -80,9 +84,7 @@ $(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
.built: $(OBJS)
- @( for obj in $(OBJS) ; do \
- $(call ARCHIVE, $(BIN), $${obj}); \
- done ; )
+ $(call ARCHIVE, $(BIN), $(OBJS))
@touch .built
.context:
@@ -93,17 +95,18 @@ $(COBJS): %$(OBJEXT): %.c
context: .context
.depend: Makefile $(SRCS)
- @$(MKDEP) $(ROOTDEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
+ @$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
- @rm -f *.o *~ .*.swp .built
+ $(call DELFILE, .built)
$(call CLEAN)
distclean: clean
- @rm -f Make.dep .depend
+ $(call DELFILE, Make.dep)
+ $(call DELFILE, .depend)
-include Make.dep
diff --git a/apps/examples/hello/Makefile b/apps/examples/hello/Makefile
index 1d78d723e..560b0da35 100644
--- a/apps/examples/hello/Makefile
+++ b/apps/examples/hello/Makefile
@@ -54,10 +54,14 @@ COBJS = $(CSRCS:.c=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS)
OBJS = $(AOBJS) $(COBJS)
+ifeq ($(CONFIG_WINDOWS_NATIVE),y)
+ BIN = ..\..\libapps$(LIBEXT)
+else
ifeq ($(WINTOOL),y)
- BIN = "${shell cygpath -w $(APPDIR)/libapps$(LIBEXT)}"
+ BIN = ..\\..\\libapps$(LIBEXT)
else
- BIN = "$(APPDIR)/libapps$(LIBEXT)"
+ BIN = ../../libapps$(LIBEXT)
+endif
endif
ROOTDEPPATH = --dep-path .
@@ -76,9 +80,7 @@ $(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
.built: $(OBJS)
- @( for obj in $(OBJS) ; do \
- $(call ARCHIVE, $(BIN), $${obj}); \
- done ; )
+ $(call ARCHIVE, $(BIN), $(OBJS))
@touch .built
.context:
@@ -90,16 +92,17 @@ endif
context: .context
.depend: Makefile $(SRCS)
- @$(MKDEP) $(ROOTDEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
+ @$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
- @rm -f *.o *~ .*.swp .built
+ $(call DELFILE, .built)
$(call CLEAN)
distclean: clean
- @rm -f Make.dep .depend
+ $(call DELFILE, Make.dep)
+ $(call DELFILE, .depend)
-include Make.dep
diff --git a/apps/examples/helloxx/Makefile b/apps/examples/helloxx/Makefile
index 8e85eab23..062da7d58 100644
--- a/apps/examples/helloxx/Makefile
+++ b/apps/examples/helloxx/Makefile
@@ -1,7 +1,7 @@
############################################################################
# apps/examples/helloxx/Makefile
#
-# Copyright (C) 2009-2011 Gregory Nutt. All rights reserved.
+# Copyright (C) 2009-2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
@@ -50,10 +50,14 @@ CXXOBJS = $(CXXSRCS:.cxx=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS) $(CXXSRCS)
OBJS = $(AOBJS) $(COBJS) $(CXXOBJS)
+ifeq ($(CONFIG_WINDOWS_NATIVE),y)
+ BIN = ..\..\libapps$(LIBEXT)
+else
ifeq ($(WINTOOL),y)
- BIN = "${shell cygpath -w $(APPDIR)/libapps$(LIBEXT)}"
+ BIN = ..\\..\\libapps$(LIBEXT)
else
- BIN = "$(APPDIR)/libapps$(LIBEXT)"
+ BIN = ../../libapps$(LIBEXT)
+endif
endif
ROOTDEPPATH = --dep-path .
@@ -69,7 +73,7 @@ STACKSIZE = 2048
VPATH =
all: .built
-.PHONY: clean depend disclean chkcxx
+.PHONY: clean depend distclean chkcxx
chkcxx:
ifneq ($(CONFIG_HAVE_CXX),y)
@@ -93,9 +97,7 @@ $(CXXOBJS): %$(OBJEXT): %.cxx
$(call COMPILEXX, $<, $@)
.built: chkcxx $(OBJS)
- @( for obj in $(OBJS) ; do \
- $(call ARCHIVE, $(BIN), $${obj}); \
- done ; )
+ $(call ARCHIVE, $(BIN), $(OBJS))
@touch .built
.context:
@@ -107,16 +109,17 @@ endif
context: .context
.depend: Makefile $(SRCS)
- @$(MKDEP) $(ROOTDEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
+ @$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
- @rm -f *.o *~ .*.swp .built
+ $(call DELFILE, .built)
$(call CLEAN)
distclean: clean
- @rm -f Make.dep .depend
+ $(call DELFILE, Make.dep)
+ $(call DELFILE, .depend)
-include Make.dep
diff --git a/apps/examples/mm/Makefile b/apps/examples/mm/Makefile
index 24ed4926f..5ba7f4eec 100644
--- a/apps/examples/mm/Makefile
+++ b/apps/examples/mm/Makefile
@@ -1,7 +1,7 @@
############################################################################
# apps/examples/mm/Makefile
#
-# Copyright (C) 2011 Gregory Nutt. All rights reserved.
+# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
@@ -48,10 +48,14 @@ COBJS = $(CSRCS:.c=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS)
OBJS = $(AOBJS) $(COBJS)
+ifeq ($(CONFIG_WINDOWS_NATIVE),y)
+ BIN = ..\..\libapps$(LIBEXT)
+else
ifeq ($(WINTOOL),y)
- BIN = "${shell cygpath -w $(APPDIR)/libapps$(LIBEXT)}"
+ BIN = ..\\..\\libapps$(LIBEXT)
else
- BIN = "$(APPDIR)/libapps$(LIBEXT)"
+ BIN = ../../libapps$(LIBEXT)
+endif
endif
ROOTDEPPATH = --dep-path .
@@ -70,24 +74,23 @@ $(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
.built: $(OBJS)
- @( for obj in $(OBJS) ; do \
- $(call ARCHIVE, $(BIN), $${obj}); \
- done ; )
+ $(call ARCHIVE, $(BIN), $(OBJS))
@touch .built
context:
.depend: Makefile $(SRCS)
- @$(MKDEP) $(ROOTDEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
+ @$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
- @rm -f *.o *~ .*.swp .built
+ $(call DELFILE, .built)
$(call CLEAN)
distclean: clean
- @rm -f Make.dep .depend
+ $(call DELFILE, Make.dep)
+ $(call DELFILE, .depend)
-include Make.dep
diff --git a/apps/examples/mount/Makefile b/apps/examples/mount/Makefile
index 69cf970cf..133bdfa1f 100644
--- a/apps/examples/mount/Makefile
+++ b/apps/examples/mount/Makefile
@@ -1,7 +1,7 @@
############################################################################
# apps/Makefile
#
-# Copyright (C) 2007-2008, 2010-2010 Gregory Nutt. All rights reserved.
+# Copyright (C) 2007-2008, 2010-2010, 2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
@@ -48,10 +48,14 @@ COBJS = $(CSRCS:.c=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS)
OBJS = $(AOBJS) $(COBJS)
+ifeq ($(CONFIG_WINDOWS_NATIVE),y)
+ BIN = ..\..\libapps$(LIBEXT)
+else
ifeq ($(WINTOOL),y)
- BIN = "${shell cygpath -w $(APPDIR)/libapps$(LIBEXT)}"
+ BIN = ..\\..\\libapps$(LIBEXT)
else
- BIN = "$(APPDIR)/libapps$(LIBEXT)"
+ BIN = ../../libapps$(LIBEXT)
+endif
endif
ROOTDEPPATH = --dep-path .
@@ -70,24 +74,23 @@ $(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
.built: $(OBJS)
- @( for obj in $(OBJS) ; do \
- $(call ARCHIVE, $(BIN), $${obj}); \
- done ; )
+ $(call ARCHIVE, $(BIN), $(OBJS))
@touch .built
context:
.depend: Makefile $(SRCS)
- @$(MKDEP) $(ROOTDEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
+ @$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
- @rm -f *.o *~ .*.swp .built
+ $(call DELFILE, .built)
$(call CLEAN)
distclean: clean
- @rm -f Make.dep .depend
+ $(call DELFILE, Make.dep)
+ $(call DELFILE, .depend)
-include Make.dep
diff --git a/apps/examples/nsh/Makefile b/apps/examples/nsh/Makefile
index bad40fb2e..c7d212fc2 100644
--- a/apps/examples/nsh/Makefile
+++ b/apps/examples/nsh/Makefile
@@ -1,7 +1,7 @@
############################################################################
# apps/examples/nsh/Makefile
#
-# Copyright (C) 2007-2008, 2010-2011 Gregory Nutt. All rights reserved.
+# Copyright (C) 2007-2008, 2010-2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
@@ -48,10 +48,14 @@ COBJS = $(CSRCS:.c=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS)
OBJS = $(AOBJS) $(COBJS)
+ifeq ($(CONFIG_WINDOWS_NATIVE),y)
+ BIN = ..\..\libapps$(LIBEXT)
+else
ifeq ($(WINTOOL),y)
- BIN = "${shell cygpath -w $(APPDIR)/libapps$(LIBEXT)}"
+ BIN = ..\\..\\libapps$(LIBEXT)
else
- BIN = "$(APPDIR)/libapps$(LIBEXT)"
+ BIN = ../../libapps$(LIBEXT)
+endif
endif
ROOTDEPPATH = --dep-path .
@@ -70,24 +74,23 @@ $(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
.built: $(OBJS)
- @( for obj in $(OBJS) ; do \
- $(call ARCHIVE, $(BIN), $${obj}); \
- done ; )
+ $(call ARCHIVE, $(BIN), $(OBJS))
@touch .built
context:
.depend: Makefile $(SRCS)
- @$(MKDEP) $(ROOTDEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
+ @$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
- @rm -f *.o *~ .*.swp .built
+ $(call DELFILE, .built)
$(call CLEAN)
distclean: clean
- @rm -f Make.dep .depend
+ $(call DELFILE, Make.dep)
+ $(call DELFILE, .depend)
-include Make.dep
diff --git a/apps/examples/null/Makefile b/apps/examples/null/Makefile
index 634120600..47ec4cdaf 100644
--- a/apps/examples/null/Makefile
+++ b/apps/examples/null/Makefile
@@ -1,7 +1,7 @@
############################################################################
# examples/null/Makefile
#
-# Copyright (C) 2007-2008, 2010-2011 Gregory Nutt. All rights reserved.
+# Copyright (C) 2007-2008, 2010-2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
@@ -48,10 +48,14 @@ COBJS = $(CSRCS:.c=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS)
OBJS = $(AOBJS) $(COBJS)
+ifeq ($(CONFIG_WINDOWS_NATIVE),y)
+ BIN = ..\..\libapps$(LIBEXT)
+else
ifeq ($(WINTOOL),y)
- BIN = "${shell cygpath -w $(APPDIR)/libapps$(LIBEXT)}"
+ BIN = ..\\..\\libapps$(LIBEXT)
else
- BIN = "$(APPDIR)/libapps$(LIBEXT)"
+ BIN = ../../libapps$(LIBEXT)
+endif
endif
ROOTDEPPATH = --dep-path .
@@ -70,24 +74,23 @@ $(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
.built: $(OBJS)
- @( for obj in $(OBJS) ; do \
- $(call ARCHIVE, $(BIN), $${obj}); \
- done ; )
+ $(call ARCHIVE, $(BIN), $(OBJS))
@touch .built
context:
.depend: Makefile $(SRCS)
- @$(MKDEP) $(ROOTDEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
+ @$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
- @rm -f *.o *~ .*.swp .built
+ $(call DELFILE, .built)
$(call CLEAN)
distclean: clean
- @rm -f Make.dep .depend
+ $(call DELFILE, Make.dep)
+ $(call DELFILE, .depend)
-include Make.dep
diff --git a/apps/examples/ostest/Kconfig b/apps/examples/ostest/Kconfig
index 0da7e4ce3..c3fe8f21d 100644
--- a/apps/examples/ostest/Kconfig
+++ b/apps/examples/ostest/Kconfig
@@ -39,4 +39,31 @@ config EXAMPLES_OSTEST_NBARRIER_THREADS
is 8 but a smaller number may be needed on systems without sufficient memory
to start so many threads.
+config EXAMPLES_OSTEST_RR_RANGE
+ int "Round-robin test - end of search range"
+ default 10000
+ range 1 32767
+ ---help---
+ During round-robin scheduling test two threads are created. Each of the threads
+ searches for prime numbers in the configurable range, doing that configurable
+ number of times.
+
+ This value specifies the end of search range and together with number of runs
+ allows to configure the length of this test - it should last at least a few
+ tens of seconds. Allowed values [1; 32767], default 10000
+
+config EXAMPLES_OSTEST_RR_RUNS
+ int "Round-robin test - number of runs"
+ default 10
+ range 1 32767
+ ---help---
+ During round-robin scheduling test two threads are created. Each of the threads
+ searches for prime numbers in the configurable range, doing that configurable
+ number of times.
+
+ This value specifies the number of times the thread searches the range for
+ prime numbers and together with end of search range allows to configure the
+ length of this test - it should last at least a few tens of seconds. Allowed
+ values [1; 32767], default 10
+
endif
diff --git a/apps/examples/ostest/Makefile b/apps/examples/ostest/Makefile
index 374964b39..3e78c64e8 100644
--- a/apps/examples/ostest/Makefile
+++ b/apps/examples/ostest/Makefile
@@ -98,10 +98,14 @@ COBJS = $(CSRCS:.c=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS)
OBJS = $(AOBJS) $(COBJS)
+ifeq ($(CONFIG_WINDOWS_NATIVE),y)
+ BIN = ..\..\libapps$(LIBEXT)
+else
ifeq ($(WINTOOL),y)
- BIN = "${shell cygpath -w $(APPDIR)/libapps$(LIBEXT)}"
+ BIN = ..\\..\\libapps$(LIBEXT)
else
- BIN = "$(APPDIR)/libapps$(LIBEXT)"
+ BIN = ../../libapps$(LIBEXT)
+endif
endif
ROOTDEPPATH = --dep-path .
@@ -120,9 +124,7 @@ $(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
.built: $(OBJS)
- @( for obj in $(OBJS) ; do \
- $(call ARCHIVE, $(BIN), $${obj}); \
- done ; )
+ $(call ARCHIVE, $(BIN), $(OBJS))
@touch .built
.context:
@@ -134,16 +136,17 @@ endif
context: .context
.depend: Makefile $(SRCS)
- @$(MKDEP) $(ROOTDEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
+ @$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
- @rm -f *.o *~ .*.swp .built
+ $(call DELFILE, .built)
$(call CLEAN)
distclean: clean
- @rm -f Make.dep .depend
+ $(call DELFILE, Make.dep)
+ $(call DELFILE, .depend)
-include Make.dep
diff --git a/apps/examples/ostest/roundrobin.c b/apps/examples/ostest/roundrobin.c
index 5167a857e..bfd344df3 100644
--- a/apps/examples/ostest/roundrobin.c
+++ b/apps/examples/ostest/roundrobin.c
@@ -1,7 +1,7 @@
/********************************************************************************
* examples/ostest/roundrobin.c
*
- * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2007, 2008, 2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -39,6 +39,7 @@
#include <nuttx/config.h>
#include <stdio.h>
+#include <stdbool.h>
#include "ostest.h"
#if CONFIG_RR_INTERVAL > 0
@@ -47,115 +48,87 @@
* Definitions
********************************************************************************/
-/* This number may need to be tuned for different processor speeds. Since these
- * arrays must be large to very correct SCHED_RR behavior, this test may require
- * too much memory on many targets.
- */
+/* This numbers should be tuned for different processor speeds via .config file.
+ * With default values the test takes about 30s on Cortex-M3 @ 24MHz. With 32767
+ * range and 10 runs it takes ~320s. */
-/* #define CONFIG_NINTEGERS 32768 Takes forever on 60Mhz ARM7 */
-
-#define CONFIG_NINTEGERS 2048
-
-/********************************************************************************
- * Private Data
- ********************************************************************************/
+#ifndef CONFIG_EXAMPLES_OSTEST_RR_RANGE
+# define CONFIG_EXAMPLES_OSTEST_RR_RANGE 10000
+# warning "CONFIG_EXAMPLES_OSTEST_RR_RANGE undefined, using default value = 10000"
+#elif (CONFIG_EXAMPLES_OSTEST_RR_RANGE < 1) || (CONFIG_EXAMPLES_OSTEST_RR_RANGE > 32767)
+# define CONFIG_EXAMPLES_OSTEST_RR_RANGE 10000
+# warning "Invalid value of CONFIG_EXAMPLES_OSTEST_RR_RANGE, using default value = 10000"
+#endif
-static int prime1[CONFIG_NINTEGERS];
-static int prime2[CONFIG_NINTEGERS];
+#ifndef CONFIG_EXAMPLES_OSTEST_RR_RUNS
+# define CONFIG_EXAMPLES_OSTEST_RR_RUNS 10
+# warning "CONFIG_EXAMPLES_OSTEST_RR_RUNS undefined, using default value = 10"
+#elif (CONFIG_EXAMPLES_OSTEST_RR_RUNS < 1) || (CONFIG_EXAMPLES_OSTEST_RR_RUNS > 32767)
+# define CONFIG_EXAMPLES_OSTEST_RR_RUNS 10
+# warning "Invalid value of CONFIG_EXAMPLES_OSTEST_RR_RUNS, using default value = 10"
+#endif
/********************************************************************************
* Private Functions
********************************************************************************/
/********************************************************************************
- * Name: dosieve
+ * Name: get_primes
*
* Description
- * This implements a "sieve of aristophanes" algorithm for finding prime number.
- * Credit for this belongs to someone, but I am not sure who anymore. Anyway,
- * the only purpose here is that we need some algorithm that takes a long period
- * of time to execute.
- *
+ * This function searches for prime numbers in the most primitive way possible.
********************************************************************************/
-static void dosieve(int *prime)
+static void get_primes(int *count, int *last)
{
- int a,d;
- int i;
- int j;
-
- a = 2;
- d = a;
-
- for (i = 0; i < CONFIG_NINTEGERS; i++)
- {
- prime[i] = i+2;
- }
-
- for (i = 1; i < 10; i++)
+ int number;
+ int local_count = 0;
+ *last = 0; // to make compiler happy
+
+ for (number = 1; number < CONFIG_EXAMPLES_OSTEST_RR_RANGE; number++)
+ {
+ int div;
+ bool is_prime = true;
+
+ for (div = 2; div <= number / 2; div++)
+ if (number % div == 0)
+ {
+ is_prime = false;
+ break;
+ }
+
+ if (is_prime)
{
- for (j = 0; j < CONFIG_NINTEGERS; j++)
- {
- d = a + d;
- if (d < CONFIG_NINTEGERS)
- {
- prime[d]=0;
- }
- }
- a++;
- d = a;
- i++;
- }
-
+ local_count++;
+ *last = number;
#if 0 /* We don't really care what the numbers are */
- for (i = 0, j= 0; i < CONFIG_NINTEGERS; i++)
- {
- if (prime[i] != 0)
- {
- printf(" Prime %d: %d\n", j, prime[i]);
- j++;
- }
- }
+ printf(" Prime %d: %d\n", local_count, number);
#endif
-}
-
-/********************************************************************************
- * Name: sieve1
- ********************************************************************************/
-
-static void *sieve1(void *parameter)
-{
- int i;
-
- printf("sieve1 started\n");
-
- for (i = 0; i < 1000; i++)
- {
- dosieve(prime1);
}
+ }
- printf("sieve1 finished\n");
-
- pthread_exit(NULL);
- return NULL; /* To keep some compilers happy */
+ *count = local_count;
}
/********************************************************************************
- * Name: sieve2
+ * Name: get_primes_thread
********************************************************************************/
-static void *sieve2(void *parameter)
+static void *get_primes_thread(void *parameter)
{
- int i;
+ int id = (int)parameter;
+ int i, count, last;
- printf("sieve2 started\n");
+ printf("get_primes_thread id=%d started, looking for primes < %d, doing %d run(s)\n",
+ id, CONFIG_EXAMPLES_OSTEST_RR_RANGE, CONFIG_EXAMPLES_OSTEST_RR_RUNS);
- for (i = 0; i < 1000; i++)
+ for (i = 0; i < CONFIG_EXAMPLES_OSTEST_RR_RUNS; i++)
{
- dosieve(prime2);
+ get_primes(&count, &last);
}
- printf("sieve2 finished\n");
+ printf("get_primes_thread id=%d finished, found %d primes, last one was %d\n",
+ id, count, last);
pthread_exit(NULL);
return NULL; /* To keep some compilers happy */
@@ -171,14 +144,13 @@ static void *sieve2(void *parameter)
void rr_test(void)
{
- pthread_t sieve1_thread;
- pthread_t sieve2_thread;
+ pthread_t get_primes1_thread;
+ pthread_t get_primes2_thread;
struct sched_param sparam;
pthread_attr_t attr;
pthread_addr_t result;
int status;
- printf("rr_test: Starting sieve1 thread \n");
status = pthread_attr_init(&attr);
if (status != OK)
{
@@ -203,29 +175,31 @@ void rr_test(void)
}
else
{
- printf("rr_test: Set thread policty to SCHED_RR\n");
+ printf("rr_test: Set thread policy to SCHED_RR\n");
}
- status = pthread_create(&sieve1_thread, &attr, sieve1, NULL);
+ printf("rr_test: Starting first get_primes_thread\n");
+
+ status = pthread_create(&get_primes1_thread, &attr, get_primes_thread, (void*)1);
if (status != 0)
{
printf("rr_test: Error in thread 1 creation, status=%d\n", status);
}
- printf("rr_test: Starting sieve1 thread \n");
+ printf("rr_test: Starting second get_primes_thread\n");
- status = pthread_create(&sieve2_thread, &attr, sieve2, NULL);
+ status = pthread_create(&get_primes2_thread, &attr, get_primes_thread, (void*)2);
if (status != 0)
{
printf("rr_test: Error in thread 2 creation, status=%d\n", status);
}
- printf("rr_test: Waiting for sieves to complete -- this should take awhile\n");
+ printf("rr_test: Waiting for threads to complete -- this should take awhile\n");
printf("rr_test: If RR scheduling is working, they should start and complete at\n");
printf("rr_test: about the same time\n");
- pthread_join(sieve2_thread, &result);
- pthread_join(sieve1_thread, &result);
+ pthread_join(get_primes2_thread, &result);
+ pthread_join(get_primes1_thread, &result);
printf("rr_test: Done\n");
}
diff --git a/apps/examples/pipe/Makefile b/apps/examples/pipe/Makefile
index 956c911b3..bed319085 100644
--- a/apps/examples/pipe/Makefile
+++ b/apps/examples/pipe/Makefile
@@ -1,7 +1,7 @@
############################################################################
# apps/examples/pipe/Makefile
#
-# Copyright (C) 2008, 2010-2011 Gregory Nutt. All rights reserved.
+# Copyright (C) 2008, 2010-2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
@@ -48,10 +48,14 @@ COBJS = $(CSRCS:.c=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS)
OBJS = $(AOBJS) $(COBJS)
+ifeq ($(CONFIG_WINDOWS_NATIVE),y)
+ BIN = ..\..\libapps$(LIBEXT)
+else
ifeq ($(WINTOOL),y)
- BIN = "${shell cygpath -w $(APPDIR)/libapps$(LIBEXT)}"
+ BIN = ..\\..\\libapps$(LIBEXT)
else
- BIN = "$(APPDIR)/libapps$(LIBEXT)"
+ BIN = ../../libapps$(LIBEXT)
+endif
endif
ROOTDEPPATH = --dep-path .
@@ -70,24 +74,23 @@ $(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
.built: $(OBJS)
- @( for obj in $(OBJS) ; do \
- $(call ARCHIVE, $(BIN), $${obj}); \
- done ; )
+ $(call ARCHIVE, $(BIN), $(OBJS))
@touch .built
context:
.depend: Makefile $(SRCS)
- @$(MKDEP) $(ROOTDEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
+ @$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
- @rm -f *.o *~ .*.swp .built
+ $(call DELFILE, .built)
$(call CLEAN)
distclean: clean
- @rm -f Make.dep .depend
+ $(call DELFILE, Make.dep)
+ $(call DELFILE, .depend)
-include Make.dep
diff --git a/apps/examples/poll/Makefile b/apps/examples/poll/Makefile
index aef61d199..13173f125 100644
--- a/apps/examples/poll/Makefile
+++ b/apps/examples/poll/Makefile
@@ -1,7 +1,7 @@
############################################################################
# apps/examples/poll/Makefile
#
-# Copyright (C) 2008, 2010-2011 Gregory Nutt. All rights reserved.
+# Copyright (C) 2008, 2010-2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
@@ -48,10 +48,14 @@ COBJS = $(CSRCS:.c=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS)
OBJS = $(AOBJS) $(COBJS)
+ifeq ($(CONFIG_WINDOWS_NATIVE),y)
+ BIN = ..\..\libapps$(LIBEXT)
+else
ifeq ($(WINTOOL),y)
- BIN = "${shell cygpath -w $(APPDIR)/libapps$(LIBEXT)}"
+ BIN = ..\\..\\libapps$(LIBEXT)
else
- BIN = "$(APPDIR)/libapps$(LIBEXT)"
+ BIN = ../../libapps$(LIBEXT)
+endif
endif
ROOTDEPPATH = --dep-path .
@@ -70,25 +74,25 @@ $(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
.built: $(OBJS)
- @( for obj in $(OBJS) ; do \
- $(call ARCHIVE, $(BIN), $${obj}); \
- done ; )
+ $(call ARCHIVE, $(BIN), $(OBJS))
@touch .built
context:
.depend: Makefile $(SRCS)
- @$(MKDEP) $(ROOTDEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
+ @$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
@touch $@
# Register application
depend: .depend
clean:
- @rm -f *.o *~ .*.swp .built
+ $(call DELFILE, .built)
$(call CLEAN)
distclean: clean
- @rm -f Make.dep .depend host
+ $(call DELFILE, Make.dep)
+ $(call DELFILE, .depend)
+ $(call DELFILE, host$(HOSTEXEEXT))
-include Make.dep
diff --git a/apps/examples/pwm/Makefile b/apps/examples/pwm/Makefile
index efbdb048e..3a6f2520a 100644
--- a/apps/examples/pwm/Makefile
+++ b/apps/examples/pwm/Makefile
@@ -1,7 +1,7 @@
############################################################################
# apps/examples/pwm/Makefile
#
-# Copyright (C) 2011 Gregory Nutt. All rights reserved.
+# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
@@ -48,10 +48,14 @@ COBJS = $(CSRCS:.c=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS)
OBJS = $(AOBJS) $(COBJS)
+ifeq ($(CONFIG_WINDOWS_NATIVE),y)
+ BIN = ..\..\libapps$(LIBEXT)
+else
ifeq ($(WINTOOL),y)
- BIN = "${shell cygpath -w $(APPDIR)/libapps$(LIBEXT)}"
+ BIN = ..\\..\\libapps$(LIBEXT)
else
- BIN = "$(APPDIR)/libapps$(LIBEXT)"
+ BIN = ../../libapps$(LIBEXT)
+endif
endif
ROOTDEPPATH = --dep-path .
@@ -76,9 +80,7 @@ $(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
.built: $(OBJS)
- @( for obj in $(OBJS) ; do \
- $(call ARCHIVE, $(BIN), $${obj}); \
- done ; )
+ $(call ARCHIVE, $(BIN), $(OBJS))
@touch .built
.context:
@@ -88,16 +90,17 @@ $(COBJS): %$(OBJEXT): %.c
context: .context
.depend: Makefile $(SRCS)
- @$(MKDEP) $(ROOTDEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
+ @$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
- @rm -f *.o *~ .*.swp .built
+ $(call DELFILE, .built)
$(call CLEAN)
distclean: clean
- @rm -f Make.dep .depend
+ $(call DELFILE, Make.dep)
+ $(call DELFILE, .depend)
-include Make.dep
diff --git a/apps/examples/pwm/pwm_main.c b/apps/examples/pwm/pwm_main.c
index 775bdba6b..a46c10f55 100644
--- a/apps/examples/pwm/pwm_main.c
+++ b/apps/examples/pwm/pwm_main.c
@@ -48,6 +48,7 @@
#include <fcntl.h>
#include <errno.h>
#include <debug.h>
+#include <string.h>
#include <nuttx/pwm.h>
diff --git a/apps/examples/qencoder/Makefile b/apps/examples/qencoder/Makefile
index 3f3fc9def..7d2427c6b 100644
--- a/apps/examples/qencoder/Makefile
+++ b/apps/examples/qencoder/Makefile
@@ -48,10 +48,14 @@ COBJS = $(CSRCS:.c=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS)
OBJS = $(AOBJS) $(COBJS)
+ifeq ($(CONFIG_WINDOWS_NATIVE),y)
+ BIN = ..\..\libapps$(LIBEXT)
+else
ifeq ($(WINTOOL),y)
- BIN = "${shell cygpath -w $(APPDIR)/libapps$(LIBEXT)}"
+ BIN = ..\\..\\libapps$(LIBEXT)
else
- BIN = "$(APPDIR)/libapps$(LIBEXT)"
+ BIN = ../../libapps$(LIBEXT)
+endif
endif
ROOTDEPPATH = --dep-path .
@@ -76,9 +80,7 @@ $(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
.built: $(OBJS)
- @( for obj in $(OBJS) ; do \
- $(call ARCHIVE, $(BIN), $${obj}); \
- done ; )
+ $(call ARCHIVE, $(BIN), $(OBJS))
@touch .built
.context:
@@ -90,16 +92,17 @@ endif
context: .context
.depend: Makefile $(SRCS)
- @$(MKDEP) $(ROOTDEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
+ @$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
- @rm -f *.o *~ .*.swp .built
+ $(call DELFILE, .built)
$(call CLEAN)
distclean: clean
- @rm -f Make.dep .depend
+ $(call DELFILE, Make.dep)
+ $(call DELFILE, .depend)
-include Make.dep
diff --git a/apps/examples/romfs/Makefile b/apps/examples/romfs/Makefile
index ba930b77d..2b02952ed 100644
--- a/apps/examples/romfs/Makefile
+++ b/apps/examples/romfs/Makefile
@@ -1,7 +1,7 @@
############################################################################
# apps/examples/romfs/Makefile
#
-# Copyright (C) 2008, 2010-2011 Gregory Nutt. All rights reserved.
+# Copyright (C) 2008, 2010-2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
@@ -48,10 +48,14 @@ COBJS = $(CSRCS:.c=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS)
OBJS = $(AOBJS) $(COBJS)
+ifeq ($(CONFIG_WINDOWS_NATIVE),y)
+ BIN = ..\..\libapps$(LIBEXT)
+else
ifeq ($(WINTOOL),y)
- BIN = "${shell cygpath -w $(APPDIR)/libapps$(LIBEXT)}"
+ BIN = ..\\..\\libapps$(LIBEXT)
else
- BIN = "$(APPDIR)/libapps$(LIBEXT)"
+ BIN = ../../libapps$(LIBEXT)
+endif
endif
ROOTDEPPATH = --dep-path .
@@ -61,7 +65,7 @@ ROOTDEPPATH = --dep-path .
VPATH =
all: .built
-.PHONY: checkgenromfs clean depend disclean
+.PHONY: checkgenromfs clean depend distclean
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
@@ -86,26 +90,26 @@ romfs_testdir.h : testdir.img
@xxd -i $< >$@ || { echo "xxd of $< failed" ; exit 1 ; }
.built: romfs_testdir.h $(OBJS)
- @( for obj in $(OBJS) ; do \
- $(call ARCHIVE, $(BIN), $${obj}); \
- done ; )
+ $(call ARCHIVE, $(BIN), $(OBJS))
@touch .built
context:
.depend: Makefile $(SRCS)
- @$(MKDEP) $(ROOTDEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
+ @$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
@touch $@
# Register application
depend: .depend
clean:
- @rm -f *.o *~ .*.swp .built
+ $(call DELFILE, .built)
$(call CLEAN)
distclean: clean
- @rm -f Make.dep .depend testdir.img
+ $(call DELFILE, Make.dep)
+ $(call DELFILE, .depend)
+ $(call DELFILE, testdir.img)
-include Make.dep
diff --git a/apps/examples/serloop/Makefile b/apps/examples/serloop/Makefile
index e1c415cdd..4a262884b 100644
--- a/apps/examples/serloop/Makefile
+++ b/apps/examples/serloop/Makefile
@@ -1,7 +1,7 @@
############################################################################
# apps/examples/serloop/Makefile
#
-# Copyright (C) 2008, 2010-2011 Gregory Nutt. All rights reserved.
+# Copyright (C) 2008, 2010-2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
@@ -48,10 +48,14 @@ COBJS = $(CSRCS:.c=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS)
OBJS = $(AOBJS) $(COBJS)
+ifeq ($(CONFIG_WINDOWS_NATIVE),y)
+ BIN = ..\..\libapps$(LIBEXT)
+else
ifeq ($(WINTOOL),y)
- BIN = "${shell cygpath -w $(APPDIR)/libapps$(LIBEXT)}"
+ BIN = ..\\..\\libapps$(LIBEXT)
else
- BIN = "$(APPDIR)/libapps$(LIBEXT)"
+ BIN = ../../libapps$(LIBEXT)
+endif
endif
ROOTDEPPATH = --dep-path .
@@ -70,26 +74,25 @@ $(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
.built: $(OBJS)
- @( for obj in $(OBJS) ; do \
- $(call ARCHIVE, $(BIN), $${obj}); \
- done ; )
+ $(call ARCHIVE, $(BIN), $(OBJS))
@touch .built
context:
.depend: Makefile $(SRCS)
- @$(MKDEP) $(ROOTDEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
+ @$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
@touch $@
# Register application
depend: .depend
clean:
- @rm -f *.o *~ .*.swp .built
+ $(call DELFILE, .built)
$(call CLEAN)
distclean: clean
- @rm -f Make.dep .depend
+ $(call DELFILE, Make.dep)
+ $(call DELFILE, .depend)
-include Make.dep
diff --git a/apps/examples/watchdog/Makefile b/apps/examples/watchdog/Makefile
index d2739dbb0..9890959fb 100644
--- a/apps/examples/watchdog/Makefile
+++ b/apps/examples/watchdog/Makefile
@@ -48,10 +48,14 @@ COBJS = $(CSRCS:.c=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS)
OBJS = $(AOBJS) $(COBJS)
+ifeq ($(CONFIG_WINDOWS_NATIVE),y)
+ BIN = ..\..\libapps$(LIBEXT)
+else
ifeq ($(WINTOOL),y)
- BIN = "${shell cygpath -w $(APPDIR)/libapps$(LIBEXT)}"
+ BIN = ..\\..\\libapps$(LIBEXT)
else
- BIN = "$(APPDIR)/libapps$(LIBEXT)"
+ BIN = ../../libapps$(LIBEXT)
+endif
endif
ROOTDEPPATH = --dep-path .
@@ -76,9 +80,7 @@ $(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
.built: $(OBJS)
- @( for obj in $(OBJS) ; do \
- $(call ARCHIVE, $(BIN), $${obj}); \
- done ; )
+ $(call ARCHIVE, $(BIN), $(OBJS))
@touch .built
.context:
@@ -88,16 +90,17 @@ $(COBJS): %$(OBJEXT): %.c
context: .context
.depend: Makefile $(SRCS)
- @$(MKDEP) $(ROOTDEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
+ @$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
- @rm -f *.o *~ .*.swp .built
+ $(call DELFILE, .built)
$(call CLEAN)
distclean: clean
- @rm -f Make.dep .depend
+ $(call DELFILE, Make.dep)
+ $(call DELFILE, .depend)
-include Make.dep
diff --git a/apps/interpreters/Kconfig b/apps/interpreters/Kconfig
index 34cbf2eee..6e7d1ac4f 100644
--- a/apps/interpreters/Kconfig
+++ b/apps/interpreters/Kconfig
@@ -7,7 +7,7 @@ comment "Interpreters"
source "$APPSDIR/interpreters/ficl/Kconfig"
-config PCODE
+config INTERPRETERS_PCODE
bool "Pascal p-code interpreter"
default n
---help---
@@ -16,6 +16,6 @@ config PCODE
configuration implies that you have performed the required installation of the
Pascal run-time code.
-if PCODE
+if INTERPRETERS_PCODE
endif
diff --git a/apps/interpreters/Make.defs b/apps/interpreters/Make.defs
index 2fc4b26d4..5d808d5d6 100644
--- a/apps/interpreters/Make.defs
+++ b/apps/interpreters/Make.defs
@@ -34,10 +34,10 @@
#
############################################################################
-ifeq ($(CONFIG_PCODE),y)
+ifeq ($(CONFIG_INTERPRETERS_PCODE),y)
CONFIGURED_APPS += interpreters/pcode
endif
-ifeq ($(CONFIG_FICL),y)
+ifeq ($(CONFIG_INTERPRETERS_FICL),y)
CONFIGURED_APPS += interpreters/ficl
endif
diff --git a/apps/interpreters/Makefile b/apps/interpreters/Makefile
index 5901fc830..867d45f99 100644
--- a/apps/interpreters/Makefile
+++ b/apps/interpreters/Makefile
@@ -33,7 +33,7 @@
#
############################################################################
--include $(TOPDIR)/.config # Current configuration
+-include $(TOPDIR)/.config
# Sub-directories containing interpreter runtime
@@ -41,30 +41,36 @@ SUBDIRS = pcode ficl
# Create the list of installed runtime modules (INSTALLED_DIRS)
+ifeq ($(CONFIG_WINDOWS_NATIVE),y)
+define ADD_DIRECTORY
+INSTALLED_DIRS += ${shell if exist $1\Makefile (echo $1)}
+endef
+else
define ADD_DIRECTORY
INSTALLED_DIRS += ${shell if [ -r $1/Makefile ]; then echo "$1"; fi}
endef
+endif
$(foreach DIR, $(SUBDIRS), $(eval $(call ADD_DIRECTORY,$(DIR))))
all: nothing
.PHONY: nothing context depend clean distclean
+define SDIR_template
+$(1)_$(2):
+ $(Q) $(MAKE) -C $(1) $(2) TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)"
+endef
+
+$(foreach SDIR, $(INSTALLED_DIRS), $(eval $(call SDIR_template,$(SDIR),depend)))
+$(foreach SDIR, $(INSTALLED_DIRS), $(eval $(call SDIR_template,$(SDIR),clean)))
+$(foreach SDIR, $(INSTALLED_DIRS), $(eval $(call SDIR_template,$(SDIR),distclean)))
+
nothing:
context:
-depend:
- @for dir in $(INSTALLED_DIRS) ; do \
- $(MAKE) -C $$dir depend TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)"; \
- done
+depend: $(foreach SDIR, $(INSTALLED_DIRS), $(SDIR)_depend)
-clean:
- @for dir in $(INSTALLED_DIRS) ; do \
- $(MAKE) -C $$dir clean TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)"; \
- done
+clean: $(foreach SDIR, $(INSTALLED_DIRS), $(SDIR)_clean)
-distclean: clean
- @for dir in $(INSTALLED_DIRS) ; do \
- $(MAKE) -C $$dir distclean TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)"; \
- done
+distclean: clean $(foreach SDIR, $(INSTALLED_DIRS), $(SDIR)_distclean)
diff --git a/apps/interpreters/ficl/Kconfig b/apps/interpreters/ficl/Kconfig
index 1860a1591..ba6a7bc35 100644
--- a/apps/interpreters/ficl/Kconfig
+++ b/apps/interpreters/ficl/Kconfig
@@ -3,7 +3,7 @@
# see misc/tools/kconfig-language.txt.
#
-config FICL
+config INTERPRETERS_FICL
bool "Ficl Forth interpreter"
default n
---help---
@@ -11,6 +11,6 @@ config FICL
apps/interpreters/ficl directory. Use of this configuration assumes
that you have performed the required installation of the Ficl run-time code.
-if FICL
+if INTERPRETERS_FICL
endif
diff --git a/apps/interpreters/ficl/Makefile b/apps/interpreters/ficl/Makefile
index fb953964e..990630fb8 100644
--- a/apps/interpreters/ficl/Makefile
+++ b/apps/interpreters/ficl/Makefile
@@ -1,7 +1,7 @@
############################################################################
# apps/interpreters/ficl/Makefile
#
-# Copyright (C) 2011 Gregory Nutt. All rights reserved.
+# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
@@ -35,14 +35,11 @@
BUILDDIR := ${shell pwd | sed -e 's/ /\\ /g'}
--include $(TOPDIR)/.config
-include $(TOPDIR)/Make.defs
include $(APPDIR)/Make.defs
# Tools
-INCDIR = $(TOPDIR)/tools/incdir.sh
-
ifeq ($(WINTOOL),y)
INCDIROPT = -w
endif
@@ -69,10 +66,14 @@ COBJS = $(CSRCS:.c=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS)
OBJS = $(AOBJS) $(COBJS)
+ifeq ($(CONFIG_WINDOWS_NATIVE),y)
+ BIN = ..\..\libapps$(LIBEXT)
+else
ifeq ($(WINTOOL),y)
- BIN = "${shell cygpath -w $(APPDIR)/libapps$(LIBEXT)}"
+ BIN = ..\\..\\libapps$(LIBEXT)
else
- BIN = "$(APPDIR)/libapps$(LIBEXT)"
+ BIN = ../../libapps$(LIBEXT)
+endif
endif
ROOT_DEPPATH = --dep-path .
@@ -95,24 +96,24 @@ debug:
@#echo "CFLAGS: $(CFLAGS)"
.built: debug $(OBJS)
- @( for obj in $(OBJS) ; do \
- $(call ARCHIVE, $(BIN), $${obj}); \
- done ; )
- @touch .built
+ $(call ARCHIVE, $(BIN), $(OBJS))
+ $(Q) touch .built
context:
.depend: debug Makefile $(SRCS)
- @$(MKDEP) $(ROOT_DEPPATH) $(SRC_DEPPATH) $(FICL_DEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
- @touch $@
+ $(Q) $(MKDEP) $(ROOT_DEPPATH) $(SRC_DEPPATH) $(FICL_DEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
+ $(Q) touch $@
depend: .depend
clean:
- @rm -f *.o *~ .*.swp .built
+ $(call DELFILE, .context)
+ $(call DELFILE, .built)
$(call CLEAN)
distclean: clean
- @rm -f Make.dep .depend
+ $(call DELFILE, Make.dep)
+ $(call DELFILE, .depend)
-include Make.dep
diff --git a/apps/namedapp/Makefile b/apps/namedapp/Makefile
index 6b0fd6a05..a88c73567 100644
--- a/apps/namedapp/Makefile
+++ b/apps/namedapp/Makefile
@@ -1,7 +1,7 @@
############################################################################
# apps/nshlib/Makefile
#
-# Copyright (C) 2011 Gregory Nutt. All rights reserved.
+# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
@@ -54,10 +54,14 @@ COBJS = $(CSRCS:.c=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS)
OBJS = $(AOBJS) $(COBJS)
+ifeq ($(CONFIG_WINDOWS_NATIVE),y)
+ BIN = ..\libapps$(LIBEXT)
+else
ifeq ($(WINTOOL),y)
- BIN = "${shell cygpath -w $(APPDIR)/libapps$(LIBEXT)}"
+ BIN = ..\\libapps$(LIBEXT)
else
- BIN = "$(APPDIR)/libapps$(LIBEXT)"
+ BIN = ../libapps$(LIBEXT)
+endif
endif
ROOTDEPPATH = --dep-path .
@@ -75,32 +79,32 @@ $(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
.built: $(OBJS)
- @( for obj in $(OBJS) ; do \
- $(call ARCHIVE, $(BIN), $${obj}); \
- done ; )
- @touch .built
+ $(call ARCHIVE, $(BIN), $(OBJS))
+ $(Q) touch .built
.context:
@echo "/* List of application requirements, generated during make context. */" > namedapp_list.h
@echo "/* List of application entry points, generated during make context. */" > namedapp_proto.h
- @touch $@
+ $(Q) touch $@
context: .context
.depend: Makefile $(SRCS)
- @$(MKDEP) $(ROOTDEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
- @touch $@
+ $(Q) $(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
+ $(Q) touch $@
depend: .depend
clean:
- @rm -f *.o *~ .*.swp .built
+ $(call DELFILE, .built)
$(call CLEAN)
distclean: clean
- @rm -f .context Make.dep .depend
- @rm -f namedapp_list.h
- @rm -f namedapp_proto.h
+ $(call DELFILE, .context)
+ $(call DELFILE, Make.dep)
+ $(call DELFILE, .depend)
+ $(call DELFILE, namedapp_list.h)
+ $(call DELFILE, namedapp_proto.h)
-include Make.dep
diff --git a/apps/nshlib/Kconfig b/apps/nshlib/Kconfig
index d12a32973..17b107b8f 100644
--- a/apps/nshlib/Kconfig
+++ b/apps/nshlib/Kconfig
@@ -23,122 +23,194 @@ config NSH_BUILTIN_APPS
(NAMEDAPP).
menu "Disable Individual commands"
+
+config NSH_DISABLE_BASE64DEC
+ bool "Disable base64dec"
+ default n
+ depends on NETUTILS_CODECS && CODECS_BASE64
+
+config NSH_DISABLE_BASE64ENC
+ bool "Disable base64enc"
+ default n
+ depends on NETUTILS_CODECS && CODECS_BASE64
+
config NSH_DISABLE_CAT
bool "Disable cat"
default n
+
config NSH_DISABLE_CD
bool "Disable cd"
default n
+
config NSH_DISABLE_CP
bool "Disable cp"
default n
+
config NSH_DISABLE_DD
bool "Disable dd"
default n
+
config NSH_DISABLE_ECHO
bool "Disable echo"
default n
+
config NSH_DISABLE_EXEC
bool "Disable exec"
default n
+
config NSH_DISABLE_EXIT
bool "Disable exit"
default n
+
config NSH_DISABLE_FREE
bool "Disable free"
default n
+
config NSH_DISABLE_GET
bool "Disable get"
default n
+
config NSH_DISABLE_HELP
bool "Disable help"
default n
+
+config NSH_DISABLE_HEXDUMP
+ bool "Disable hexdump"
+ default n
+
config NSH_DISABLE_IFCONFIG
bool "Disable ifconfig"
default n
+
config NSH_DISABLE_KILL
bool "Disable kill"
default n
+
config NSH_DISABLE_LOSETUP
bool "Disable losetup"
default n
+
config NSH_DISABLE_LS
bool "Disable ls"
default n
+
config NSH_DISABLE_MB
bool "Disable mb"
default n
+
+config NSH_DISABLE_MD5
+ bool "Disable md5"
+ default n
+ depends on NETUTILS_CODECS && CODECS_HASH_MD5
+
config NSH_DISABLE_MKDIR
bool "Disable mkdir"
default n
+
config NSH_DISABLE_MKFATFS
bool "Disable mkfatfs"
default n
+
config NSH_DISABLE_MKFIFO
bool "Disable mkfifo"
default n
+
config NSH_DISABLE_MKRD
bool "Disable mkrd"
default n
+
config NSH_DISABLE_MH
bool "Disable mh"
default n
+
config NSH_DISABLE_MOUNT
bool "Disable mount"
default n
+
config NSH_DISABLE_MW
bool "Disable mw"
default n
+
config NSH_DISABLE_NSFMOUNT
bool "Disable nfsmount"
default n
+
config NSH_DISABLE_PS
bool "Disable ps"
default n
+
config NSH_DISABLE_PING
bool "Disable ping"
default n
+
config NSH_DISABLE_PUT
bool "Disable put"
default n
+
config NSH_DISABLE_PWD
bool "Disable pwd"
default n
+
config NSH_DISABLE_RM
bool "Disable rm"
default n
+
config NSH_DISABLE_RMDIR
bool "Disable rmdir"
default n
+
config NSH_DISABLE_SET
bool "Disable set"
default n
+
config NSH_DISABLE_SH
bool "Disable sh"
default n
+
config NSH_DISABLE_SLEEP
bool "Disable sleep"
default n
+
config NSH_DISABLE_TEST
bool "Disable test"
default n
+
config NSH_DISABLE_UMOUNT
bool "Disable umount"
default n
+
config NSH_DISABLE_UNSET
bool "Disable unset"
default n
+
+config NSH_DISABLE_URLDECODE
+ bool "Disable urldecode"
+ default n
+ depends on NETUTILS_CODECS && CODECS_URLCODE
+
+config NSH_DISABLE_URLENCODE
+ bool "Disable urlencode"
+ default n
+ depends on NETUTILS_CODECS && CODECS_URLCODE
+
config NSH_DISABLE_USLEEP
bool "Disable usleep"
default n
+
config NSH_DISABLE_WGET
bool "Disable wget"
default n
+
config NSH_DISABLE_XD
bool "Disable xd"
default n
+
endmenu
+config NSH_CODECS_BUFSIZE
+ int "File buffer size used by CODEC commands"
+ default 128
+
config NSH_FILEIOSIZE
int "NSH I/O buffer size"
default 1024
@@ -490,7 +562,7 @@ config NSH_DHCPC
config NSH_IPADDR
hex "Target IP address"
- default 0x10000002
+ default 0xa0000002
depends on NSH_LIBRARY && NET && !NSH_DHCPC
---help---
If NSH_DHCPC is NOT set, then the static IP address must be provided.
@@ -499,7 +571,7 @@ config NSH_IPADDR
config NSH_DRIPADDR
hex "Router IP address"
- default 0x10000001
+ default 0xa0000001
depends on NSH_LIBRARY && NET && !NSH_DHCPC
---help---
Default router IP address (aka, Gateway). This is a 32-bit integer
@@ -513,6 +585,21 @@ config NSH_NETMASK
Network mask. This is a 32-bit integer value in host order. So, as
an example, 0xffffff00 would be 255.255.255.0.
+config NSH_DNS
+ bool "Use DNS"
+ default n
+ depends on NSH_LIBRARY && NET && NET_UDP && NET_BROADCAST
+ ---help---
+ Configure to use a DNS.
+
+config NSH_DNSIPADDR
+ hex "DNS IP address"
+ default 0xa0000001
+ depends on NSH_DNS
+ ---help---
+ Configure the DNS address. This is a 32-bit integer value in host
+ order. So, as an example, 0xa0000001 would be 10.0.0.1.
+
config NSH_NOMAC
bool "Hardware has no MAC address"
default n
@@ -520,3 +607,12 @@ config NSH_NOMAC
---help---
Set if your ethernet hardware has no built-in MAC address.
If set, a bogus MAC will be assigned.
+
+config NSH_MAX_ROUNDTRIP
+ int "Max Ping Round-Trip (DSEC)"
+ default 20
+ depends on NSH_LIBRARY && NET && !NSH_DISABLE_PING
+ ---help---
+ This is the maximum round trip for a response to a ICMP ECHO request.
+ It is in units of deciseconds. The default is 20 (2 seconds).
+
diff --git a/apps/nshlib/Makefile b/apps/nshlib/Makefile
index f616374bf..73325e899 100644
--- a/apps/nshlib/Makefile
+++ b/apps/nshlib/Makefile
@@ -39,64 +39,72 @@ include $(APPDIR)/Make.defs
# NSH Library
-ASRCS =
-CSRCS = nsh_init.c nsh_parse.c nsh_console.c nsh_fscmds.c nsh_ddcmd.c \
+ASRCS =
+CSRCS = nsh_init.c nsh_parse.c nsh_console.c nsh_fscmds.c nsh_ddcmd.c \
nsh_proccmds.c nsh_mmcmds.c nsh_envcmds.c nsh_dbgcmds.c
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
-CSRCS += nsh_apps.c
+CSRCS += nsh_apps.c
endif
ifeq ($(CONFIG_NSH_ROMFSETC),y)
-CSRCS += nsh_romfsetc.c
+CSRCS += nsh_romfsetc.c
endif
ifeq ($(CONFIG_NET),y)
-CSRCS += nsh_netinit.c nsh_netcmds.c
+CSRCS += nsh_netinit.c nsh_netcmds.c
endif
ifeq ($(CONFIG_RTC),y)
-CSRCS += nsh_timcmds.c
+CSRCS += nsh_timcmds.c
endif
ifneq ($(CONFIG_DISABLE_MOUNTPOINT),y)
-CSRCS += nsh_mntcmds.c
+CSRCS += nsh_mntcmds.c
endif
ifeq ($(CONFIG_NSH_CONSOLE),y)
-CSRCS += nsh_consolemain.c
+CSRCS += nsh_consolemain.c
endif
ifeq ($(CONFIG_NSH_TELNET),y)
-CSRCS += nsh_telnetd.c
+CSRCS += nsh_telnetd.c
endif
ifneq ($(CONFIG_NSH_DISABLESCRIPT),y)
-CSRCS += nsh_test.c
+CSRCS += nsh_test.c
endif
ifeq ($(CONFIG_USBDEV),y)
-CSRCS += nsh_usbdev.c
+CSRCS += nsh_usbdev.c
endif
-AOBJS = $(ASRCS:.S=$(OBJEXT))
-COBJS = $(CSRCS:.c=$(OBJEXT))
+ifeq ($(CONFIG_NETUTILS_CODECS),y)
+CSRCS += nsh_codeccmd.c
+endif
+
+AOBJS = $(ASRCS:.S=$(OBJEXT))
+COBJS = $(CSRCS:.c=$(OBJEXT))
-SRCS = $(ASRCS) $(CSRCS)
-OBJS = $(AOBJS) $(COBJS)
+SRCS = $(ASRCS) $(CSRCS)
+OBJS = $(AOBJS) $(COBJS)
+ifeq ($(CONFIG_WINDOWS_NATIVE),y)
+ BIN = ..\libapps$(LIBEXT)
+else
ifeq ($(WINTOOL),y)
- BIN = "${shell cygpath -w $(APPDIR)/libapps$(LIBEXT)}"
+ BIN = ..\\libapps$(LIBEXT)
else
- BIN = "$(APPDIR)/libapps$(LIBEXT)"
+ BIN = ../libapps$(LIBEXT)
+endif
endif
-ROOTDEPPATH = --dep-path .
-VPATH =
+ROOTDEPPATH = --dep-path .
+VPATH =
# Build targets
-all: .built
+all: .built
.PHONY: context .depend depend clean distclean
$(AOBJS): %$(OBJEXT): %.S
@@ -106,26 +114,25 @@ $(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
.built: $(OBJS)
- @( for obj in $(OBJS) ; do \
- $(call ARCHIVE, $(BIN), $${obj}); \
- done ; )
+ $(call ARCHIVE, $(BIN), $(OBJS))
@touch .built
context:
.depend: Makefile $(SRCS)
- @$(MKDEP) $(ROOTDEPPATH) \
- $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
+ @$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
- @rm -f *.o *~ .*.swp .built
+ $(call DELFILE, .built)
$(call CLEAN)
distclean: clean
- @rm -f Make.dep .depend
+ $(call DELFILE, .context)
+ $(call DELFILE, Make.dep)
+ $(call DELFILE, .depend)
-include Make.dep
diff --git a/apps/nshlib/README.txt b/apps/nshlib/README.txt
index 0f6aee759..bc626e699 100644
--- a/apps/nshlib/README.txt
+++ b/apps/nshlib/README.txt
@@ -235,6 +235,10 @@ o test <expression>
integer -gt integer | integer -le integer |
integer -lt integer | integer -ne integer
+o base64dec [-w] [-f] <string or filepath>
+
+o base64dec [-w] [-f] <string or filepath>
+
o cat <path> [<path> [<path> ...]]
This command copies and concatentates all of the files at <path>
@@ -381,7 +385,11 @@ o help [-v] [<cmd>]
<cmd>
Show full command usage only for this command
-o ifconfig
+o hexdump <file or device>
+
+ Dump data in hexadecimal format from a file or character device.
+
+o ifconfig [nic_name [<ip-address>|dhcp]] [dr|gw|gateway <dr-address>] [netmask <net-mask>] [dns <dns-address>] [hw <hw-mac>]
Show the current configuration of the network, for example:
@@ -392,6 +400,22 @@ o ifconfig
if uIP statistics are enabled (CONFIG_NET_STATISTICS), then
this command will also show the detailed state of uIP.
+o ifdown <nic-name>
+
+ Take down the interface identified by the name <nic-name>.
+
+ Example:
+
+ ifdown eth0
+
+o ifup <nic-name>
+
+ Bring up down the interface identified by the name <nic-name>.
+
+ Example:
+
+ ifup eth0
+
o kill -<signal> <pid>
Send the <signal> to the task identified by <pid>.
@@ -449,6 +473,8 @@ o ls [-lRs] <dir-path>
-l Show size and mode information along with the filenames
in the listing.
+o md5 [-f] <string or filepath>
+
o mb <hex-address>[=<hex-value>][ <hex-byte-count>]
o mh <hex-address>[=<hex-value>][ <hex-byte-count>]
o mw <hex-address>[=<hex-value>][ <hex-byte-count>]
@@ -781,6 +807,10 @@ o unset <name>
nsh>
+ o urldecode [-f] <string or filepath>
+
+ o urlencode [-f] <string or filepath>
+
o usleep <usec>
Pause execution (sleep) of <usec> microseconds.
@@ -826,6 +856,8 @@ Command Dependencies on Configuration Settings
Command Depends on Configuration
---------- --------------------------
[ !CONFIG_NSH_DISABLESCRIPT
+ base64dec CONFIG_NETUTILS_CODECS && CONFIG_CODECS_BASE64
+ base64enc CONFIG_NETUTILS_CODECS && CONFIG_CODECS_BASE64
cat CONFIG_NFILE_DESCRIPTORS > 0
cd !CONFIG_DISABLE_ENVIRON && CONFIG_NFILE_DESCRIPTORS > 0
cp CONFIG_NFILE_DESCRIPTORS > 0
@@ -837,10 +869,14 @@ Command Dependencies on Configuration Settings
free --
get CONFIG_NET && CONFIG_NET_UDP && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NET_BUFSIZE >= 558 (see note 1)
help --
+ hexdump CONFIG_NFILE_DESCRIPTORS > 0
ifconfig CONFIG_NET
+ ifdown CONFIG_NET
+ ifup CONFIG_NET
kill !CONFIG_DISABLE_SIGNALS
losetup !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0
ls CONFIG_NFILE_DESCRIPTORS > 0
+ md5 CONFIG_NETUTILS_CODECS && CONFIG_CODECS_HASH_MD5
mb,mh,mw ---
mkdir !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_WRITABLE (see note 4)
mkfatfs !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_FAT
@@ -861,6 +897,8 @@ Command Dependencies on Configuration Settings
test !CONFIG_NSH_DISABLESCRIPT
umount !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_READABLE
unset !CONFIG_DISABLE_ENVIRON
+ urldecode CONFIG_NETUTILS_CODECS && CONFIG_CODECS_URLCODE
+ urlencode CONFIG_NETUTILS_CODECS && CONFIG_CODECS_URLCODE
usleep !CONFIG_DISABLE_SIGNALS
get CONFIG_NET && CONFIG_NET_TCP && CONFIG_NFILE_DESCRIPTORS > 0
xd ---
@@ -880,20 +918,22 @@ In addition, each NSH command can be individually disabled via one of the follow
settings. All of these settings make the configuration of NSH potentially complex but
also allow it to squeeze into very small memory footprints.
- CONFIG_NSH_DISABLE_CAT, CONFIG_NSH_DISABLE_CD, CONFIG_NSH_DISABLE_CP,
- CONFIG_NSH_DISABLE_DD, CONFIG_NSH_DISABLE_DF, CONFIG_NSH_DISABLE_ECHO,
- CONFIG_NSH_DISABLE_EXEC, CONFIG_NSH_DISABLE_EXIT, CONFIG_NSH_DISABLE_FREE,
- CONFIG_NSH_DISABLE_GET, CONFIG_NSH_DISABLE_HELP, CONFIG_NSH_DISABLE_IFCONFIG,
- CONFIG_NSH_DISABLE_KILL, CONFIG_NSH_DISABLE_LOSETUP, CONFIG_NSH_DISABLE_LS,
- CONFIG_NSH_DISABLE_MB, CONFIG_NSH_DISABLE_MKDIR, CONFIG_NSH_DISABLE_MKFATFS,
- CONFIG_NSH_DISABLE_MKFIFO, CONFIG_NSH_DISABLE_MKRD, CONFIG_NSH_DISABLE_MH,
- CONFIG_NSH_DISABLE_MOUNT, CONFIG_NSH_DISABLE_MW, CONFIG_NSH_DISABLE_MV,
- CONFIG_NSH_DISABLE_NFSMOUNT, CONFIG_NSH_DISABLE_PS, CONFIG_NSH_DISABLE_PING,
- CONFIG_NSH_DISABLE_PUT, CONFIG_NSH_DISABLE_PWD, CONFIG_NSH_DISABLE_RM,
- CONFIG_NSH_DISABLE_RMDIR, CONFIG_NSH_DISABLE_SET, CONFIG_NSH_DISABLE_SH,
- CONFIG_NSH_DISABLE_SLEEP, CONFIG_NSH_DISABLE_TEST, CONFIG_NSH_DISABLE_UMOUNT,
- CONFIG_NSH_DISABLE_UNSET, CONFIG_NSH_DISABLE_USLEEP, CONFIG_NSH_DISABLE_WGET,
- CONFIG_NSH_DISABLE_XD
+ CONFIG_NSH_DISABLE_BASE64DEC, CONFIG_NSH_DISABLE_BASE64ENC, CONFIG_NSH_DISABLE_CAT,
+ CONFIG_NSH_DISABLE_CD, CONFIG_NSH_DISABLE_CP, CONFIG_NSH_DISABLE_DD,
+ CONFIG_NSH_DISABLE_DF, CONFIG_NSH_DISABLE_ECHO, CONFIG_NSH_DISABLE_EXEC,
+ CONFIG_NSH_DISABLE_EXIT, CONFIG_NSH_DISABLE_FREE, CONFIG_NSH_DISABLE_GET,
+ CONFIG_NSH_DISABLE_HELP, CONFIG_NSH_DISABLE_HEXDUMP, CONFIG_NSH_DISABLE_IFCONFIG,
+ CONFIG_NSH_DISABLE_IFUPDOWN, CONFIG_NSH_DISABLE_KILL, CONFIG_NSH_DISABLE_LOSETUP,
+ CONFIG_NSH_DISABLE_LS, CONFIG_NSH_DISABLE_MD5 CONFIG_NSH_DISABLE_MB,
+ CONFIG_NSH_DISABLE_MKDIR, CONFIG_NSH_DISABLE_MKFATFS, CONFIG_NSH_DISABLE_MKFIFO,
+ CONFIG_NSH_DISABLE_MKRD, CONFIG_NSH_DISABLE_MH, CONFIG_NSH_DISABLE_MOUNT,
+ CONFIG_NSH_DISABLE_MW, CONFIG_NSH_DISABLE_MV, CONFIG_NSH_DISABLE_NFSMOUNT,
+ CONFIG_NSH_DISABLE_PS, CONFIG_NSH_DISABLE_PING, CONFIG_NSH_DISABLE_PUT,
+ CONFIG_NSH_DISABLE_PWD, CONFIG_NSH_DISABLE_RM, CONFIG_NSH_DISABLE_RMDIR,
+ CONFIG_NSH_DISABLE_SET, CONFIG_NSH_DISABLE_SH, CONFIG_NSH_DISABLE_SLEEP,
+ CONFIG_NSH_DISABLE_TEST, CONFIG_NSH_DISABLE_UMOUNT, CONFIG_NSH_DISABLE_UNSET,
+ CONFIG_NSH_DISABLE_URLDECODE, CONFIG_NSH_DISABLE_URLENCODE, CONFIG_NSH_DISABLE_USLEEP,
+ CONFIG_NSH_DISABLE_WGET, CONFIG_NSH_DISABLE_XD
Verbose help output can be suppressed by defining CONFIG_NSH_HELP_TERSE. In that
case, the help command is still available but will be slightly smaller.
@@ -1084,6 +1124,10 @@ NSH-Specific Configuration Settings
Set if your ethernet hardware has no built-in MAC address.
If set, a bogus MAC will be assigned.
+ * CONFIG_NSH_MAX_ROUNDTRIP
+ This is the maximum round trip for a response to a ICMP ECHO request.
+ It is in units of deciseconds. The default is 20 (2 seconds).
+
If you use DHCPC, then some special configuration network options are
required. These include:
diff --git a/apps/nshlib/nsh.h b/apps/nshlib/nsh.h
index 7188477ce..a046a384f 100644
--- a/apps/nshlib/nsh.h
+++ b/apps/nshlib/nsh.h
@@ -47,6 +47,7 @@
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
+#include <unistd.h>
#include <errno.h>
#include <nuttx/usb/usbdev_trace.h>
@@ -215,6 +216,15 @@
#endif /* CONFIG_NSH_TELNET_LOGIN */
+/* CONFIG_NSH_MAX_ROUNDTRIP - This is the maximum round trip for a response to
+ * a ICMP ECHO request. It is in units of deciseconds. The default is 20
+ * (2 seconds).
+ */
+
+#ifndef CONFIG_NSH_MAX_ROUNDTRIP
+# define CONFIG_NSH_MAX_ROUNDTRIP 20
+#endif
+
/* Verify support for ROMFS /etc directory support options */
#ifdef CONFIG_NSH_ROMFSETC
@@ -258,12 +268,36 @@
# undef CONFIG_NSH_ROMFSSECTSIZE
#endif
-/* This is the maximum number of arguments that will be accepted for a command */
-#ifdef CONFIG_NSH_MAX_ARGUMENTS
-# define NSH_MAX_ARGUMENTS CONFIG_NSH_MAX_ARGUMENTS
-#else
-# define NSH_MAX_ARGUMENTS 10
+/* This is the maximum number of arguments that will be accepted for a
+ * command. Here we attempt to select the smallest number possible depending
+ * upon the of commands that are available. Most commands use six or fewer
+ * arguments, but there are a few that require more.
+ *
+ * This value is also configurable with CONFIG_NSH_MAXARGUMENTS. This
+ * configurability is necessary since there may also be external, "built-in"
+ * commands that require more commands than NSH is aware of.
+ */
+
+#ifndef CONFIG_NSH_MAXARGUMENTS
+# define CONFIG_NSH_MAXARGUMENTS 6
#endif
+
+#if CONFIG_NSH_MAXARGUMENTS < 11
+# if defined(CONFIG_NET) && !defined(CONFIG_NSH_DISABLE_IFCONFIG)
+# undef CONFIG_NSH_MAXARGUMENTS
+# define CONFIG_NSH_MAXARGUMENTS 11
+# endif
+#endif
+
+#if CONFIG_NSH_MAXARGUMENTS < 7
+# if defined(CONFIG_NET_UDP) && CONFIG_NFILE_DESCRIPTORS > 0
+# if !defined(CONFIG_NSH_DISABLE_GET) || !defined(CONFIG_NSH_DISABLE_PUT)
+# undef CONFIG_NSH_MAXARGUMENTS
+# define CONFIG_NSH_MAXARGUMENTS 7
+# endif
+# endif
+#endif
+
/* strerror() produces much nicer output but is, however, quite large and
* will only be used if CONFIG_NSH_STRERROR is defined. Note that the strerror
* interface must also have been enabled with CONFIG_LIBC_STRERROR.
@@ -507,7 +541,7 @@ void nsh_usbtrace(void);
#ifndef CONFIG_NSH_DISABLE_XD
int cmd_xd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
#endif
-
+
#if !defined(CONFIG_NSH_DISABLESCRIPT) && !defined(CONFIG_NSH_DISABLE_TEST)
int cmd_test(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
int cmd_lbracket(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
@@ -529,6 +563,9 @@ void nsh_usbtrace(void);
# ifndef CONFIG_NSH_DISABLE_DD
int cmd_dd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
# endif
+# ifndef CONFIG_NSH_DISABLE_HEXDUMP
+ int cmd_hexdump(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
+# endif
# ifndef CONFIG_NSH_DISABLE_LS
int cmd_ls(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
# endif
@@ -595,6 +632,10 @@ void nsh_usbtrace(void);
# ifndef CONFIG_NSH_DISABLE_IFCONFIG
int cmd_ifconfig(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
# endif
+# ifndef CONFIG_NSH_DISABLE_IFUPDOWN
+ int cmd_ifup(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
+ int cmd_ifdown(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
+# endif
#if defined(CONFIG_NET_UDP) && CONFIG_NFILE_DESCRIPTORS > 0
# ifndef CONFIG_NSH_DISABLE_GET
int cmd_get(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
@@ -643,4 +684,28 @@ void nsh_usbtrace(void);
# endif
#endif /* CONFIG_DISABLE_SIGNALS */
+#if defined(CONFIG_NETUTILS_CODECS) && defined(CONFIG_CODECS_BASE64)
+# ifndef CONFIG_NSH_DISABLE_BASE64DEC
+ int cmd_base64decode(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
+# endif
+# ifndef CONFIG_NSH_DISABLE_BASE64ENC
+ int cmd_base64encode(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
+# endif
+#endif
+
+#if defined(CONFIG_NETUTILS_CODECS) && defined(CONFIG_CODECS_HASH_MD5)
+# ifndef CONFIG_NSH_DISABLE_MD5
+ int cmd_md5(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
+# endif
+#endif
+
+#if defined(CONFIG_NETUTILS_CODECS) && defined(CONFIG_CODECS_URLCODE)
+# ifndef CONFIG_NSH_DISABLE_URLDECODE
+ int cmd_urlencode(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
+# endif
+# ifndef CONFIG_NSH_DISABLE_URLENCODE
+ int cmd_urldecode(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
+# endif
+#endif
+
#endif /* __APPS_NSHLIB_NSH_H */
diff --git a/apps/nshlib/nsh_apps.c b/apps/nshlib/nsh_apps.c
index e335c2e2c..7dbaf9ba8 100644
--- a/apps/nshlib/nsh_apps.c
+++ b/apps/nshlib/nsh_apps.c
@@ -122,13 +122,28 @@ int nsh_execapp(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
ret = exec_namedapp(cmd, (FAR const char **)argv);
if (ret >= 0)
{
- /* The application was successfully started (but still blocked because the
- * scheduler is locked). If the application was not backgrounded, then we
- * need to wait here for the application to exit.
+ /* The application was successfully started (but still blocked because
+ * the scheduler is locked). If the application was not backgrounded,
+ * then we need to wait here for the application to exit. These really
+ * only works works with the following options:
+ *
+ * - CONFIG_NSH_DISABLEBG - Do not run commands in background
+ * - CONFIG_SCHED_WAITPID - Required to run external commands in
+ * foreground
+ *
+ * These concepts do not apply cleanly to the external applications.
*/
#ifdef CONFIG_SCHED_WAITPID
+
+ /* CONFIG_SCHED_WAITPID is selected, so we may run the command in
+ * foreground unless we were specifically requested to run the command
+ * in background (and running commands in background is enabled).
+ */
+
+# ifndef CONFIG_NSH_DISABLEBG
if (vtbl->np.np_bg == false)
+# endif /* CONFIG_NSH_DISABLEBG */
{
int rc = 0;
@@ -155,8 +170,25 @@ int nsh_execapp(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
*/
}
}
+# ifndef CONFIG_NSH_DISABLEBG
else
-#endif
+# endif /* CONFIG_NSH_DISABLEBG */
+#endif /* CONFIG_SCHED_WAITPID */
+
+ /* We get here if either:
+ *
+ * - CONFIG_SCHED_WAITPID is not selected meaning that all commands
+ * have to be run in background, or
+ * - CONFIG_SCHED_WAITPID and CONFIG_NSH_DISABLEBG are both selected, but the
+ * user requested to run the command in background.
+ *
+ * NOTE that the case of a) CONFIG_SCHED_WAITPID is not selected and
+ * b) CONFIG_NSH_DISABLEBG selected cannot be supported. In that event, all
+ * commands will have to run in background. The waitpid() API must be
+ * available to support running the command in foreground.
+ */
+
+#if !defined(CONFIG_SCHED_WAITPID) || !defined(CONFIG_NSH_DISABLEBG)
{
struct sched_param param;
sched_getparam(0, &param);
@@ -168,6 +200,7 @@ int nsh_execapp(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
ret = OK;
}
+#endif /* !CONFIG_SCHED_WAITPID || !CONFIG_NSH_DISABLEBG */
}
sched_unlock();
diff --git a/apps/nshlib/nsh_consolemain.c b/apps/nshlib/nsh_consolemain.c
index 6b51be470..f05447a64 100644
--- a/apps/nshlib/nsh_consolemain.c
+++ b/apps/nshlib/nsh_consolemain.c
@@ -160,11 +160,11 @@ int nsh_consolemain(int argc, char *argv[])
}
}
- /* Clean up */
+ /* Clean up. We do not get here, but this is necessary to keep some
+ * compilers happy. But others will complain that this code is not
+ * reachable.
+ */
nsh_exit(&pstate->cn_vtbl, 0);
-
- /* We do not get here, but this is necessary to keep some compilers happy */
-
return OK;
}
diff --git a/apps/nshlib/nsh_dbgcmds.c b/apps/nshlib/nsh_dbgcmds.c
index 384b377f3..85a4ccb9c 100644
--- a/apps/nshlib/nsh_dbgcmds.c
+++ b/apps/nshlib/nsh_dbgcmds.c
@@ -46,6 +46,10 @@
#include <string.h>
#include <errno.h>
+#if CONFIG_NFILE_DESCRIPTORS > 0
+# include <fcntl.h>
+#endif
+
#include "nsh.h"
#include "nsh_console.h"
@@ -99,7 +103,7 @@ int mem_parse(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv,
pcvalue++;
lvalue = (unsigned long)strtol(pcvalue, NULL, 16);
- if (lvalue > 0xffffffff)
+ if (lvalue > 0xffffffffL)
{
return -EINVAL;
}
@@ -127,6 +131,7 @@ int mem_parse(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv,
{
mem->dm_count = 1;
}
+
return OK;
}
@@ -327,7 +332,7 @@ void nsh_dumpbuffer(FAR struct nsh_vtbl_s *vtbl, const char *msg,
}
/****************************************************************************
- * Name: cmd_xd
+ * Name: cmd_xd, hex dump of memory
****************************************************************************/
#ifndef CONFIG_NSH_DISABLE_XD
@@ -353,3 +358,58 @@ int cmd_xd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
return OK;
}
#endif
+
+/****************************************************************************
+ * Name: cmd_hexdump, hex dump of files
+ ****************************************************************************/
+
+#if CONFIG_NFILE_DESCRIPTORS > 0
+#ifndef CONFIG_NSH_DISABLE_HEXDUMP
+int cmd_hexdump(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
+{
+ uint8_t buffer[IOBUFFERSIZE];
+ char msg[32];
+ int position;
+ int fd;
+ int ret = OK;
+
+ /* Open the file for reading */
+
+ fd = open(argv[1], O_RDONLY);
+ if (fd < 0)
+ {
+ nsh_output(vtbl, g_fmtcmdfailed, "hexdump", "open", NSH_ERRNO);
+ return ERROR;
+ }
+
+ position = 0;
+ for (;;)
+ {
+ int nbytesread = read(fd, buffer, IOBUFFERSIZE);
+
+ /* Check for read errors */
+
+ if (nbytesread < 0)
+ {
+ int errval = errno;
+ nsh_output(vtbl, g_fmtcmdfailed, "hexdump", "read", NSH_ERRNO_OF(errval));
+ ret = ERROR;
+ break;
+ }
+ else if (nbytesread > 0)
+ {
+ snprintf(msg, sizeof(msg), "%s at %08x", argv[1], position);
+ nsh_dumpbuffer(vtbl, msg, buffer, nbytesread);
+ position += nbytesread;
+ }
+ else
+ {
+ break; // EOF
+ }
+ }
+
+ (void)close(fd);
+ return ret;
+}
+#endif
+#endif
diff --git a/apps/nshlib/nsh_netcmds.c b/apps/nshlib/nsh_netcmds.c
index cfea5a08a..371d30460 100644
--- a/apps/nshlib/nsh_netcmds.c
+++ b/apps/nshlib/nsh_netcmds.c
@@ -51,6 +51,7 @@
#include <fcntl.h> /* Needed for open */
#include <libgen.h> /* Needed for basename */
#include <errno.h>
+#include <debug.h>
#include <nuttx/net/net.h>
#include <nuttx/clock.h>
@@ -80,6 +81,15 @@
# endif
#endif
+#if defined(CONFIG_NSH_DHCPC) || defined(CONFIG_NSH_DNS)
+# ifdef CONFIG_HAVE_GETHOSTBYNAME
+# include <netdb.h>
+# else
+# include <apps/netutils/resolv.h>
+# endif
+# include <apps/netutils/dhcpc.h>
+#endif
+
#include "nsh.h"
#include "nsh_console.h"
@@ -87,8 +97,16 @@
* Definitions
****************************************************************************/
+/* Size of the ECHO data */
+
#define DEFAULT_PING_DATALEN 56
+/* Get the larger value */
+
+#ifndef MAX
+# define MAX(a,b) (a > b ? a : b)
+#endif
+
/****************************************************************************
* Private Types
****************************************************************************/
@@ -262,14 +280,34 @@ int ifconfig_callback(FAR struct uip_driver_s *dev, void *arg)
{
struct nsh_vtbl_s *vtbl = (struct nsh_vtbl_s*)arg;
struct in_addr addr;
+ bool is_running = false;
+ int ret;
+
+ ret = uip_getifstatus(dev->d_ifname,&is_running);
+ if (ret != OK)
+ {
+ nsh_output(vtbl, "\tGet %s interface flags error: %d\n",
+ dev->d_ifname, ret);
+ }
+
+ nsh_output(vtbl, "%s\tHWaddr %s at %s\n",
+ dev->d_ifname, ether_ntoa(&dev->d_mac), (is_running)?"UP":"DOWN");
- nsh_output(vtbl, "%s\tHWaddr %s\n", dev->d_ifname, ether_ntoa(&dev->d_mac));
addr.s_addr = dev->d_ipaddr;
nsh_output(vtbl, "\tIPaddr:%s ", inet_ntoa(addr));
+
addr.s_addr = dev->d_draddr;
nsh_output(vtbl, "DRaddr:%s ", inet_ntoa(addr));
+
addr.s_addr = dev->d_netmask;
- nsh_output(vtbl, "Mask:%s\n\n", inet_ntoa(addr));
+ nsh_output(vtbl, "Mask:%s\n", inet_ntoa(addr));
+
+#if defined(CONFIG_NSH_DHCPC) || defined(CONFIG_NSH_DNS)
+ resolv_getserver(&addr);
+ nsh_output(vtbl, "\tDNSaddr:%s\n", inet_ntoa(addr));
+#endif
+
+ nsh_output(vtbl, "\n");
return OK;
}
@@ -469,6 +507,54 @@ int cmd_get(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
#endif
/****************************************************************************
+ * Name: cmd_ifup
+ ****************************************************************************/
+
+#ifndef CONFIG_NSH_DISABLE_IFUPDOWN
+int cmd_ifup(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
+{
+ FAR char *intf = NULL;
+ int ret;
+
+ if (argc != 2)
+ {
+ nsh_output(vtbl, "Please select nic_name:\n");
+ netdev_foreach(ifconfig_callback, vtbl);
+ return OK;
+ }
+
+ intf = argv[1];
+ ret = uip_ifup(intf);
+ nsh_output(vtbl, "ifup %s...%s\n", intf, (ret == OK) ? "OK" : "Failed");
+ return ret;
+}
+#endif
+
+/****************************************************************************
+ * Name: cmd_ifdown
+ ****************************************************************************/
+
+#ifndef CONFIG_NSH_DISABLE_IFUPDOWN
+int cmd_ifdown(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
+{
+ FAR char *intf = NULL;
+ int ret;
+
+ if (argc != 2)
+ {
+ nsh_output(vtbl, "Please select nic_name:\n");
+ netdev_foreach(ifconfig_callback, vtbl);
+ return OK;
+ }
+
+ intf = argv[1];
+ ret = uip_ifdown(intf);
+ nsh_output(vtbl, "ifdown %s...%s\n", intf, (ret == OK) ? "OK" : "Failed");
+ return ret;
+}
+#endif
+
+/****************************************************************************
* Name: cmd_ifconfig
****************************************************************************/
@@ -476,7 +562,20 @@ int cmd_get(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
int cmd_ifconfig(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
{
struct in_addr addr;
- in_addr_t ip;
+ in_addr_t gip;
+ int i;
+ FAR char *intf = NULL;
+ FAR char *hostip = NULL;
+ FAR char *gwip = NULL;
+ FAR char *mask = NULL;
+ FAR char *tmp = NULL;
+ FAR char *hw = NULL;
+ FAR char *dns = NULL;
+ bool badarg = false;
+ uint8_t mac[IFHWADDRLEN];
+#if defined(CONFIG_NSH_DHCPC)
+ FAR void *handle;
+#endif
/* With one or no arguments, ifconfig simply shows the status of ethernet
* device:
@@ -498,24 +597,201 @@ int cmd_ifconfig(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
* ifconfig nic_name ip_address
*/
- /* Set host ip address */
+ if (argc > 2)
+ {
+ for(i = 0; i < argc; i++)
+ {
+ if (i == 1)
+ {
+ intf = argv[i];
+ }
+ else if (i == 2)
+ {
+ hostip = argv[i];
+ }
+ else
+ {
+ tmp = argv[i];
+ if (!strcmp(tmp, "dr") || !strcmp(tmp, "gw") || !strcmp(tmp, "gateway"))
+ {
+ if (argc-1 >= i+1)
+ {
+ gwip = argv[i+1];
+ i++;
+ }
+ else
+ {
+ badarg = true;
+ }
+ }
+ else if(!strcmp(tmp, "netmask"))
+ {
+ if (argc-1 >= i+1)
+ {
+ mask = argv[i+1];
+ i++;
+ }
+ else
+ {
+ badarg = true;
+ }
+ }
+ else if(!strcmp(tmp, "hw"))
+ {
+ if (argc-1>=i+1)
+ {
+ hw = argv[i+1];
+ i++;
+ badarg = !uiplib_hwmacconv(hw, mac);
+ }
+ else
+ {
+ badarg = true;
+ }
+ }
+ else if(!strcmp(tmp, "dns"))
+ {
+ if (argc-1 >= i+1)
+ {
+ dns = argv[i+1];
+ i++;
+ }
+ else
+ {
+ badarg = true;
+ }
+ }
+ }
+ }
+ }
+
+ if (badarg)
+ {
+ nsh_output(vtbl, g_fmtargrequired, argv[0]);
+ return ERROR;
+ }
+
+ /* Set Hardware ethernet MAC addr */
+
+ if (hw)
+ {
+ ndbg("HW MAC: %s\n", hw);
+ uip_setmacaddr(intf, mac);
+ }
+
+#if defined(CONFIG_NSH_DHCPC)
+ if (!strcmp(hostip, "dhcp"))
+ {
+ /* Set DHCP addr */
+
+ ndbg("DHCPC Mode\n");
+ gip = addr.s_addr = 0;
+ }
+ else
+#endif
+ {
+ /* Set host IP address */
+
+ ndbg("Host IP: %s\n", hostip);
+ gip = addr.s_addr = inet_addr(hostip);
+ }
- ip = addr.s_addr = inet_addr(argv[2]);
- uip_sethostaddr(argv[1], &addr);
+ uip_sethostaddr(intf, &addr);
/* Set gateway */
- ip = NTOHL(ip);
- ip &= ~0x000000ff;
- ip |= 0x00000001;
+ if (gwip)
+ {
+ ndbg("Gateway: %s\n", gwip);
+ gip = addr.s_addr = inet_addr(gwip);
+ }
+ else
+ {
+ if (gip)
+ {
+ ndbg("Gateway: default\n");
+ gip = NTOHL(gip);
+ gip &= ~0x000000ff;
+ gip |= 0x00000001;
+ gip = HTONL(gip);
+ }
+
+ addr.s_addr = gip;
+ }
+
+ uip_setdraddr(intf, &addr);
+
+ /* Set network mask */
+
+ if (mask)
+ {
+ ndbg("Netmask: %s\n",mask);
+ addr.s_addr = inet_addr(mask);
+ }
+ else
+ {
+ ndbg("Netmask: Default\n");
+ addr.s_addr = inet_addr("255.255.255.0");
+ }
+
+ uip_setnetmask(intf, &addr);
- addr.s_addr = HTONL(ip);
- uip_setdraddr(argv[1], &addr);
+#if defined(CONFIG_NSH_DHCPC) || defined(CONFIG_NSH_DNS)
+ if (dns)
+ {
+ ndbg("DNS: %s\n", dns);
+ addr.s_addr = inet_addr(dns);
+ }
+ else
+ {
+ ndbg("DNS: Default\n");
+ addr.s_addr = gip;
+ }
+
+ resolv_conf(&addr);
+#endif
+
+#if defined(CONFIG_NSH_DHCPC)
+ /* Get the MAC address of the NIC */
+
+ if (!gip)
+ {
+ uip_getmacaddr("eth0", mac);
+
+ /* Set up the DHCPC modules */
+
+ handle = dhcpc_open(&mac, IFHWADDRLEN);
+
+ /* Get an IP address. Note that there is no logic for renewing the IP address in this
+ * example. The address should be renewed in ds.lease_time/2 seconds.
+ */
+
+ if (handle)
+ {
+ struct dhcpc_state ds;
- /* Set netmask */
+ (void)dhcpc_request(handle, &ds);
+ uip_sethostaddr("eth0", &ds.ipaddr);
- addr.s_addr = inet_addr("255.255.255.0");
- uip_setnetmask(argv[1], &addr);
+ if (ds.netmask.s_addr != 0)
+ {
+ uip_setnetmask("eth0", &ds.netmask);
+ }
+
+ if (ds.default_router.s_addr != 0)
+ {
+ uip_setdraddr("eth0", &ds.default_router);
+ }
+
+ if (ds.dnsaddr.s_addr != 0)
+ {
+ resolv_conf(&ds.dnsaddr);
+ }
+
+ dhcpc_close(handle);
+ }
+ }
+#endif
return OK;
}
@@ -536,6 +812,7 @@ int cmd_ping(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
uint32_t start;
uint32_t next;
uint32_t dsec = 10;
+ uint32_t maxwait;
uint16_t id;
bool badarg = false;
int count = 10;
@@ -599,7 +876,7 @@ int cmd_ping(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
if (optind == argc-1)
{
staddr = argv[optind];
- if (!uiplib_ipaddrconv(staddr, (FAR unsigned char*)&ipaddr))
+ if (dns_gethostip(staddr, &ipaddr) < 0)
{
goto errout;
}
@@ -619,16 +896,26 @@ int cmd_ping(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
id = ping_newid();
+ /* The maximum wait for a response will be the larger of the inter-ping time and
+ * the configured maximum round-trip time.
+ */
+
+ maxwait = MAX(dsec, CONFIG_NSH_MAX_ROUNDTRIP);
+
/* Loop for the specified count */
- nsh_output(vtbl, "PING %s %d bytes of data\n", staddr, DEFAULT_PING_DATALEN);
+ nsh_output(vtbl, "PING %d.%d.%d.%d %d bytes of data\n",
+ (ipaddr ) & 0xff, (ipaddr >> 8 ) & 0xff,
+ (ipaddr >> 16 ) & 0xff, (ipaddr >> 24 ) & 0xff,
+ DEFAULT_PING_DATALEN);
+
start = g_system_timer;
for (i = 1; i <= count; i++)
{
/* Send the ECHO request and wait for the response */
next = g_system_timer;
- seqno = uip_ping(ipaddr, id, i, DEFAULT_PING_DATALEN, dsec);
+ seqno = uip_ping(ipaddr, id, i, DEFAULT_PING_DATALEN, maxwait);
/* Was any response returned? We can tell if a non-negative sequence
* number was returned.
@@ -636,7 +923,7 @@ int cmd_ping(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
if (seqno >= 0 && seqno <= i)
{
- /* Get the elpased time from the time that the request was
+ /* Get the elapsed time from the time that the request was
* sent until the response was received. If we got a response
* to an earlier request, then fudge the elpased time.
*/
@@ -644,7 +931,7 @@ int cmd_ping(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
elapsed = TICK2MSEC(g_system_timer - next);
if (seqno < i)
{
- elapsed += 100*dsec*(i - seqno);
+ elapsed += 100 * dsec * (i - seqno);
}
/* Report the receipt of the reply */
@@ -662,7 +949,7 @@ int cmd_ping(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
elapsed = TICK2DSEC(g_system_timer - next);
if (elapsed < dsec)
{
- usleep(100000*dsec);
+ usleep(100000 * (dsec - elapsed));
}
}
diff --git a/apps/nshlib/nsh_netinit.c b/apps/nshlib/nsh_netinit.c
index bc845c4ed..58d238312 100644
--- a/apps/nshlib/nsh_netinit.c
+++ b/apps/nshlib/nsh_netinit.c
@@ -47,7 +47,7 @@
#include <net/if.h>
#include <apps/netutils/uiplib.h>
-#if defined(CONFIG_NSH_DHCPC)
+#if defined(CONFIG_NSH_DHCPC) || defined(CONFIG_NSH_DNS)
# include <apps/netutils/resolv.h>
# include <apps/netutils/dhcpc.h>
#endif
@@ -60,6 +60,10 @@
* Definitions
****************************************************************************/
+#if defined(CONFIG_NSH_DRIPADDR) && !defined(CONFIG_NSH_DNSIPADDR)
+# define CONFIG_NSH_DNSIPADDR CONFIG_NSH_DRIPADDR
+#endif
+
/****************************************************************************
* Private Types
****************************************************************************/
@@ -125,10 +129,14 @@ int nsh_netinit(void)
addr.s_addr = HTONL(CONFIG_NSH_NETMASK);
uip_setnetmask("eth0", &addr);
-#if defined(CONFIG_NSH_DHCPC)
+#if defined(CONFIG_NSH_DHCPC) || defined(CONFIG_NSH_DNS)
/* Set up the resolver */
resolv_init();
+#if defined(CONFIG_NSH_DNS)
+ addr.s_addr = HTONL(CONFIG_NSH_DNSIPADDR);
+ resolv_conf(&addr);
+#endif
#endif
#if defined(CONFIG_NSH_DHCPC)
@@ -148,7 +156,7 @@ int nsh_netinit(void)
{
struct dhcpc_state ds;
(void)dhcpc_request(handle, &ds);
- uip_sethostaddr("eth1", &ds.ipaddr);
+ uip_sethostaddr("eth0", &ds.ipaddr);
if (ds.netmask.s_addr != 0)
{
uip_setnetmask("eth0", &ds.netmask);
diff --git a/apps/nshlib/nsh_parse.c b/apps/nshlib/nsh_parse.c
index df2f7c3e3..27068acff 100644
--- a/apps/nshlib/nsh_parse.c
+++ b/apps/nshlib/nsh_parse.c
@@ -73,19 +73,19 @@
/* Argument list size
*
* argv[0]: The command name.
- * argv[1]: The beginning of argument (up to NSH_MAX_ARGUMENTS)
+ * argv[1]: The beginning of argument (up to CONFIG_NSH_MAXARGUMENTS)
* argv[argc-3]: Possibly '>' or '>>'
* argv[argc-2]: Possibly <file>
* argv[argc-1]: Possibly '&' (if pthreads are enabled)
* argv[argc]: NULL terminating pointer
*
- * Maximum size is NSH_MAX_ARGUMENTS+5
+ * Maximum size is CONFIG_NSH_MAXARGUMENTS+5
*/
#ifndef CONFIG_NSH_DISABLEBG
-# define MAX_ARGV_ENTRIES (NSH_MAX_ARGUMENTS+5)
+# define MAX_ARGV_ENTRIES (CONFIG_NSH_MAXARGUMENTS+5)
#else
-# define MAX_ARGV_ENTRIES (NSH_MAX_ARGUMENTS+4)
+# define MAX_ARGV_ENTRIES (CONFIG_NSH_MAXARGUMENTS+4)
#endif
/* Help command summary layout */
@@ -146,16 +146,25 @@ static const char g_failure[] = "1";
static const struct cmdmap_s g_cmdmap[] =
{
#if !defined(CONFIG_NSH_DISABLESCRIPT) && !defined(CONFIG_NSH_DISABLE_TEST)
- { "[", cmd_lbracket, 4, NSH_MAX_ARGUMENTS, "<expression> ]" },
+ { "[", cmd_lbracket, 4, CONFIG_NSH_MAXARGUMENTS, "<expression> ]" },
#endif
#ifndef CONFIG_NSH_DISABLE_HELP
{ "?", cmd_help, 1, 1, NULL },
#endif
+#if defined(CONFIG_NETUTILS_CODECS) && defined(CONFIG_CODECS_BASE64)
+# ifndef CONFIG_NSH_DISABLE_BASE64DEC
+ { "base64dec", cmd_base64decode, 2, 4, "[-w] [-f] <string or filepath>" },
+# endif
+# ifndef CONFIG_NSH_DISABLE_BASE64ENC
+ { "base64enc", cmd_base64encode, 2, 4, "[-w] [-f] <string or filepath>" },
+# endif
+#endif
+
#if CONFIG_NFILE_DESCRIPTORS > 0
# ifndef CONFIG_NSH_DISABLE_CAT
- { "cat", cmd_cat, 2, NSH_MAX_ARGUMENTS, "<path> [<path> [<path> ...]]" },
+ { "cat", cmd_cat, 2, CONFIG_NSH_MAXARGUMENTS, "<path> [<path> [<path> ...]]" },
# endif
#ifndef CONFIG_DISABLE_ENVIRON
# ifndef CONFIG_NSH_DISABLE_CD
@@ -187,9 +196,9 @@ static const struct cmdmap_s g_cmdmap[] =
#ifndef CONFIG_NSH_DISABLE_ECHO
# ifndef CONFIG_DISABLE_ENVIRON
- { "echo", cmd_echo, 0, NSH_MAX_ARGUMENTS, "[<string|$name> [<string|$name>...]]" },
+ { "echo", cmd_echo, 0, CONFIG_NSH_MAXARGUMENTS, "[<string|$name> [<string|$name>...]]" },
# else
- { "echo", cmd_echo, 0, NSH_MAX_ARGUMENTS, "[<string> [<string>...]]" },
+ { "echo", cmd_echo, 0, CONFIG_NSH_MAXARGUMENTS, "[<string> [<string>...]]" },
# endif
#endif
@@ -217,10 +226,20 @@ static const struct cmdmap_s g_cmdmap[] =
{ "help", cmd_help, 1, 3, "[-v] [<cmd>]" },
# endif
#endif
+
+#if CONFIG_NFILE_DESCRIPTORS > 0
+#ifndef CONFIG_NSH_DISABLE_HEXDUMP
+ { "hexdump", cmd_hexdump, 2, 2, "<file or device>" },
+#endif
+#endif
#ifdef CONFIG_NET
# ifndef CONFIG_NSH_DISABLE_IFCONFIG
- { "ifconfig", cmd_ifconfig, 1, 3, "[nic_name [ip]]" },
+ { "ifconfig", cmd_ifconfig, 1, 11, "[nic_name [<ip-address>|dhcp]] [dr|gw|gateway <dr-address>] [netmask <net-mask>] [dns <dns-address>] [hw <hw-mac>]" },
+# endif
+# ifndef CONFIG_NSH_DISABLE_IFUPDOWN
+ { "ifdown", cmd_ifdown, 2, 2, "<nic_name>" },
+ { "ifup", cmd_ifup, 2, 2, "<nic_name>" },
# endif
#endif
@@ -246,6 +265,12 @@ static const struct cmdmap_s g_cmdmap[] =
{ "mb", cmd_mb, 2, 3, "<hex-address>[=<hex-value>][ <hex-byte-count>]" },
#endif
+#if defined(CONFIG_NETUTILS_CODECS) && defined(CONFIG_CODECS_HASH_MD5)
+# ifndef CONFIG_NSH_DISABLE_MD5
+ { "md5", cmd_md5, 2, 3, "[-f] <string or filepath>" },
+# endif
+#endif
+
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_WRITABLE)
# ifndef CONFIG_NSH_DISABLE_MKDIR
{ "mkdir", cmd_mkdir, 2, 2, "<path>" },
@@ -348,7 +373,7 @@ static const struct cmdmap_s g_cmdmap[] =
#endif
#if !defined(CONFIG_NSH_DISABLESCRIPT) && !defined(CONFIG_NSH_DISABLE_TEST)
- { "test", cmd_test, 3, NSH_MAX_ARGUMENTS, "<expression>" },
+ { "test", cmd_test, 3, CONFIG_NSH_MAXARGUMENTS, "<expression>" },
#endif
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_READABLE)
@@ -363,6 +388,15 @@ static const struct cmdmap_s g_cmdmap[] =
# endif
#endif
+#if defined(CONFIG_NETUTILS_CODECS) && defined(CONFIG_CODECS_URLCODE)
+# ifndef CONFIG_NSH_DISABLE_URLDECODE
+ { "urldecode", cmd_urldecode, 2, 3, "[-f] <string or filepath>" },
+# endif
+# ifndef CONFIG_NSH_DISABLE_URLENCODE
+ { "urlencode", cmd_urlencode, 2, 3, "[-f] <string or filepath>" },
+# endif
+#endif
+
#ifndef CONFIG_DISABLE_SIGNALS
# ifndef CONFIG_NSH_DISABLE_USLEEP
{ "usleep", cmd_usleep, 2, 2, "<usec>" },
@@ -378,6 +412,7 @@ static const struct cmdmap_s g_cmdmap[] =
#ifndef CONFIG_NSH_DISABLE_XD
{ "xd", cmd_xd, 3, 3, "<hex-address> <byte-count>" },
#endif
+
{ NULL, NULL, 1, 1, NULL }
};
@@ -711,7 +746,7 @@ static int nsh_execute(FAR struct nsh_vtbl_s *vtbl, int argc, char *argv[])
*
* argv[0]: The command name. This is argv[0] when the arguments
* are, finally, received by the command vtblr
- * argv[1]: The beginning of argument (up to NSH_MAX_ARGUMENTS)
+ * argv[1]: The beginning of argument (up to CONFIG_NSH_MAXARGUMENTS)
* argv[argc]: NULL terminating pointer
*/
@@ -1318,13 +1353,13 @@ int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline)
* of argv is:
*
* argv[0]: The command name.
- * argv[1]: The beginning of argument (up to NSH_MAX_ARGUMENTS)
+ * argv[1]: The beginning of argument (up to CONFIG_NSH_MAXARGUMENTS)
* argv[argc-3]: Possibly '>' or '>>'
* argv[argc-2]: Possibly <file>
* argv[argc-1]: Possibly '&'
* argv[argc]: NULL terminating pointer
*
- * Maximum size is NSH_MAX_ARGUMENTS+5
+ * Maximum size is CONFIG_NSH_MAXARGUMENTS+5
*/
argv[0] = cmd;
@@ -1398,7 +1433,7 @@ int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline)
/* Check if the maximum number of arguments was exceeded */
- if (argc > NSH_MAX_ARGUMENTS)
+ if (argc > CONFIG_NSH_MAXARGUMENTS)
{
nsh_output(vtbl, g_fmttoomanyargs, cmd);
}
diff --git a/apps/px4/tests/test_time.c b/apps/px4/tests/test_time.c
index 25bf02c31..8a164f3fc 100644
--- a/apps/px4/tests/test_time.c
+++ b/apps/px4/tests/test_time.c
@@ -95,7 +95,7 @@ cycletime(void)
lasttime = cycles;
- return (basetime + cycles) / 168;
+ return (basetime + cycles) / 168; /* XXX magic number */
}
/****************************************************************************
@@ -133,9 +133,9 @@ int test_time(int argc, char *argv[])
lowdelta = abs(delta / 100);
/* loop checking the time */
- for (unsigned i = 0; i < 100000; i++) {
+ for (unsigned i = 0; i < 100; i++) {
- usleep(rand() * 10);
+ usleep(rand());
uint32_t flags = irqsave();
@@ -154,7 +154,7 @@ int test_time(int argc, char *argv[])
fprintf(stderr, "h %llu c %llu d %lld\n", h, c, delta - lowdelta);
}
- printf("Maximum jitter %lld\n", maxdelta);
+ printf("Maximum jitter %lldus\n", maxdelta);
return 0;
}
diff --git a/apps/px4/tests/tests_main.c b/apps/px4/tests/tests_main.c
index 9fb5ac482..5bedd257b 100644
--- a/apps/px4/tests/tests_main.c
+++ b/apps/px4/tests/tests_main.c
@@ -86,33 +86,35 @@ const struct {
#define OPT_NOALLTEST (1<<1)
#define OPT_NOJIGTEST (1<<2)
} tests[] = {
- {"led", test_led, 0, 0},
- {"int", test_int, 0, 0},
- {"float", test_float, 0, 0},
- {"sensors", test_sensors, 0, 0},
- {"gpio", test_gpio, OPT_NOJIGTEST | OPT_NOALLTEST, 0},
- {"hrt", test_hrt, OPT_NOJIGTEST | OPT_NOALLTEST, 0},
- {"ppm", test_ppm, OPT_NOJIGTEST | OPT_NOALLTEST, 0},
- {"servo", test_servo, OPT_NOJIGTEST | OPT_NOALLTEST, 0},
- {"adc", test_adc, OPT_NOJIGTEST, 0},
- {"jig_voltages", test_jig_voltages, OPT_NOALLTEST, 0},
- {"uart_loopback", test_uart_loopback, OPT_NOJIGTEST | OPT_NOALLTEST, 0},
- {"uart_baudchange", test_uart_baudchange, OPT_NOJIGTEST | OPT_NOALLTEST, 0},
- {"uart_send", test_uart_send, OPT_NOJIGTEST | OPT_NOALLTEST, 0},
- {"uart_console", test_uart_console, OPT_NOJIGTEST | OPT_NOALLTEST, 0},
- {"tone", test_tone, 0, 0},
- {"sleep", test_sleep, OPT_NOJIGTEST, 0},
- {"time", test_time, OPT_NOJIGTEST, 0},
- {"perf", test_perf, OPT_NOJIGTEST, 0},
- {"all", test_all, OPT_NOALLTEST | OPT_NOJIGTEST, 0},
- {"jig", test_jig, OPT_NOJIGTEST | OPT_NOALLTEST, 0},
- {"param", test_param, OPT_NOJIGTEST, 0},
- {"bson", test_bson, OPT_NOJIGTEST, 0},
- {"file", test_file, OPT_NOJIGTEST, 0},
- {"help", test_help, OPT_NOALLTEST | OPT_NOHELP | OPT_NOJIGTEST, 0},
- {NULL, NULL, 0, 0}
+ {"led", test_led, 0},
+ {"int", test_int, 0},
+ {"float", test_float, 0},
+ {"sensors", test_sensors, 0},
+ {"gpio", test_gpio, OPT_NOJIGTEST | OPT_NOALLTEST},
+ {"hrt", test_hrt, OPT_NOJIGTEST | OPT_NOALLTEST},
+ {"ppm", test_ppm, OPT_NOJIGTEST | OPT_NOALLTEST},
+ {"servo", test_servo, OPT_NOJIGTEST | OPT_NOALLTEST},
+ {"adc", test_adc, OPT_NOJIGTEST},
+ {"jig_voltages", test_jig_voltages, OPT_NOALLTEST},
+ {"uart_loopback", test_uart_loopback, OPT_NOJIGTEST | OPT_NOALLTEST},
+ {"uart_baudchange", test_uart_baudchange, OPT_NOJIGTEST | OPT_NOALLTEST},
+ {"uart_send", test_uart_send, OPT_NOJIGTEST | OPT_NOALLTEST},
+ {"uart_console", test_uart_console, OPT_NOJIGTEST | OPT_NOALLTEST},
+ {"tone", test_tone, 0},
+ {"sleep", test_sleep, OPT_NOJIGTEST},
+ {"time", test_time, OPT_NOJIGTEST},
+ {"perf", test_perf, OPT_NOJIGTEST},
+ {"all", test_all, OPT_NOALLTEST | OPT_NOJIGTEST},
+ {"jig", test_jig, OPT_NOJIGTEST | OPT_NOALLTEST},
+ {"param", test_param, 0},
+ {"bson", test_bson, 0},
+ {"file", test_file, 0},
+ {"help", test_help, OPT_NOALLTEST | OPT_NOHELP | OPT_NOJIGTEST},
+ {NULL, NULL, 0}
};
+#define NTESTS (sizeof(tests) / sizeof(tests[0]))
+
static int
test_help(int argc, char *argv[])
{
@@ -132,11 +134,7 @@ test_all(int argc, char *argv[])
unsigned i;
char *args[2] = {"all", NULL};
unsigned int failcount = 0;
- unsigned int testscount = 0;
-
- /* store test results */
- bool passed[(sizeof(tests) / sizeof(tests[0]))];
- memset(&passed, 0, sizeof(passed));
+ bool passed[NTESTS];
printf("\nRunning all tests...\n\n");
@@ -151,14 +149,12 @@ test_all(int argc, char *argv[])
fprintf(stderr, " [%s] \t\t\tFAIL\n", tests[i].name);
fflush(stderr);
failcount++;
-
+ passed[i] = false;
} else {
- passed[i] = true;
printf(" [%s] \t\t\tPASS\n", tests[i].name);
fflush(stdout);
+ passed[i] = true;
}
-
- testscount++;
}
}
@@ -181,7 +177,7 @@ test_all(int argc, char *argv[])
printf(" \\ \\_\\ \\_\\ \\ \\_____\\ \\ \\_____\\ \\ \\_____\\ \\ \\_\\ \\_\\ \n");
printf(" \\/_/\\/_/ \\/_____/ \\/_____/ \\/_____/ \\/_/\\/_/ \n");
printf("\n");
- printf(" All tests passed (%d of %d)\n", testscount, testscount);
+ printf(" All tests passed (%d of %d)\n", i, i);
} else {
printf(" ______ ______ __ __ \n");
@@ -190,7 +186,7 @@ test_all(int argc, char *argv[])
printf(" \\ \\_\\ \\ \\_\\ \\_\\ \\ \\_\\ \\ \\_____\\ \n");
printf(" \\/_/ \\/_/\\/_/ \\/_/ \\/_____/ \n");
printf("\n");
- printf(" Some tests failed (%d of %d)\n", failcount, testscount);
+ printf(" Some tests failed (%d of %d)\n", failcount, i);
}
printf("\n");
@@ -248,11 +244,7 @@ int test_jig(int argc, char *argv[])
unsigned i;
char *args[2] = {"jig", NULL};
unsigned int failcount = 0;
- unsigned int testscount = 0;
-
- /* store test results */
- bool passed[(sizeof(tests) / sizeof(tests[0]))];
- memset(&passed, 0, sizeof(passed));
+ bool passed[NTESTS];
printf("\nRunning all tests...\n\n");
for (i = 0; tests[i].name; i++) {
@@ -265,13 +257,12 @@ int test_jig(int argc, char *argv[])
fprintf(stderr, " [%s] \t\t\tFAIL\n", tests[i].name);
fflush(stderr);
failcount++;
+ passed[i] = false;
} else {
- passed[i] = true;
printf(" [%s] \t\t\tPASS\n", tests[i].name);
fflush(stdout);
+ passed[i] = true;
}
-
- testscount++;
}
}
@@ -292,7 +283,7 @@ int test_jig(int argc, char *argv[])
printf(" \\ \\_\\ \\_\\ \\ \\_____\\ \\ \\_____\\ \\ \\_____\\ \\ \\_\\ \\_\\ \n");
printf(" \\/_/\\/_/ \\/_____/ \\/_____/ \\/_____/ \\/_/\\/_/ \n");
printf("\n");
- printf(" All tests passed (%d of %d)\n", testscount, testscount);
+ printf(" All tests passed (%d of %d)\n", i, i);
} else {
printf(" ______ ______ __ __ \n");
printf(" /\\ ___\\ /\\ __ \\ /\\ \\ /\\ \\ \n");
@@ -300,7 +291,7 @@ int test_jig(int argc, char *argv[])
printf(" \\ \\_\\ \\ \\_\\ \\_\\ \\ \\_\\ \\ \\_____\\ \n");
printf(" \\/_/ \\/_/\\/_/ \\/_/ \\/_____/ \n");
printf("\n");
- printf(" Some tests failed (%d of %d)\n", failcount, testscount);
+ printf(" Some tests failed (%d of %d)\n", failcount, i);
}
printf("\n");
@@ -309,7 +300,7 @@ int test_jig(int argc, char *argv[])
unsigned int k;
for (k = 0; k < i; k++)
{
- if (!passed[k] && !(tests[k].options & OPT_NOJIGTEST))
+ if (!passed[i] && !(tests[k].options & OPT_NOJIGTEST))
{
printf(" [%s] to obtain details, please re-run with\n\t nsh> tests %s\n\n", tests[k].name, tests[k].name);
}
diff --git a/apps/system/Makefile b/apps/system/Makefile
index d64bb54c6..9955a6b2c 100644
--- a/apps/system/Makefile
+++ b/apps/system/Makefile
@@ -41,31 +41,36 @@ SUBDIRS = free i2c install readline poweroff ramtron sdcard sysinfo
# Create the list of installed runtime modules (INSTALLED_DIRS)
+ifeq ($(CONFIG_WINDOWS_NATIVE),y)
define ADD_DIRECTORY
-INSTALLED_DIRS += ${shell if [ -r $1/Makefile ]; then echo "$1"; fi}
+ INSTALLED_DIRS += $(if $(wildcard .\$1\Makefile),$1,)
endef
+else
+define ADD_DIRECTORY
+ INSTALLED_DIRS += $(if $(wildcard ./$1/Makefile),$1,)
+endef
+endif
$(foreach DIR, $(SUBDIRS), $(eval $(call ADD_DIRECTORY,$(DIR))))
all: nothing
.PHONY: nothing context depend clean distclean
+define SDIR_template
+$(1)_$(2):
+ $(Q) $(MAKE) -C $(1) $(2) TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)"
+endef
+
+$(foreach SDIR, $(INSTALLED_DIRS), $(eval $(call SDIR_template,$(SDIR),depend)))
+$(foreach SDIR, $(INSTALLED_DIRS), $(eval $(call SDIR_template,$(SDIR),clean)))
+$(foreach SDIR, $(INSTALLED_DIRS), $(eval $(call SDIR_template,$(SDIR),distclean)))
+
nothing:
context:
-depend:
- @for dir in $(INSTALLED_DIRS) ; do \
- $(MAKE) -C $$dir depend TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)"; \
- done
-
-clean:
- @for dir in $(INSTALLED_DIRS) ; do \
- $(MAKE) -C $$dir clean TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)"; \
- done
+depend: $(foreach SDIR, $(INSTALLED_DIRS), $(SDIR)_depend)
-distclean: clean
- @for dir in $(INSTALLED_DIRS) ; do \
- $(MAKE) -C $$dir distclean TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)"; \
- done
+clean: $(foreach SDIR, $(INSTALLED_DIRS), $(SDIR)_clean)
+distclean: clean $(foreach SDIR, $(INSTALLED_DIRS), $(SDIR)_distclean)
diff --git a/apps/system/free/Makefile b/apps/system/free/Makefile
index 7f911d81c..dada00d99 100644
--- a/apps/system/free/Makefile
+++ b/apps/system/free/Makefile
@@ -1,7 +1,7 @@
############################################################################
# apps/system/free/Makefile
#
-# Copyright (C) 2011 Uros Platise. All rights reserved.
+# Copyright (C) 2011-2012 Uros Platise. All rights reserved.
# Author: Uros Platise <uros.platise@isotel.eu>
# Gregory Nutt <gnutt@nuttx.org>
#
@@ -61,10 +61,14 @@ COBJS = $(CSRCS:.c=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS)
OBJS = $(AOBJS) $(COBJS)
+ifeq ($(CONFIG_WINDOWS_NATIVE),y)
+ BIN = ..\..\libapps$(LIBEXT)
+else
ifeq ($(WINTOOL),y)
- BIN = "${shell cygpath -w $(APPDIR)/libapps$(LIBEXT)}"
+ BIN = ..\\..\\libapps$(LIBEXT)
else
- BIN = "$(APPDIR)/libapps$(LIBEXT)"
+ BIN = ../../libapps$(LIBEXT)
+endif
endif
ROOTDEPPATH = --dep-path .
@@ -83,32 +87,32 @@ $(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
.built: $(OBJS)
- @( for obj in $(OBJS) ; do \
- $(call ARCHIVE, $(BIN), $${obj}); \
- done ; )
- @touch .built
+ $(call ARCHIVE, $(BIN), $(OBJS))
+ $(Q) touch .built
# Register application
.context:
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
- @touch $@
+ $(Q) touch $@
context: .context
# Create dependencies
.depend: Makefile $(SRCS)
- @$(MKDEP) $(ROOTDEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
- @touch $@
+ $(Q) $(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
+ $(Q) touch $@
depend: .depend
clean:
- @rm -f *.o *~ .*.swp .built
+ $(call DELFILE, .built)
$(call CLEAN)
distclean: clean
- @rm -f .context Make.dep .depend
+ $(call DELFILE, .context)
+ $(call DELFILE, Make.dep)
+ $(call DELFILE, .depend)
-include Make.dep
diff --git a/apps/system/i2c/Makefile b/apps/system/i2c/Makefile
index 00db91bb7..029d2b6fe 100644
--- a/apps/system/i2c/Makefile
+++ b/apps/system/i2c/Makefile
@@ -48,10 +48,14 @@ COBJS = $(CSRCS:.c=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS)
OBJS = $(AOBJS) $(COBJS)
+ifeq ($(CONFIG_WINDOWS_NATIVE),y)
+ BIN = ..\..\libapps$(LIBEXT)
+else
ifeq ($(WINTOOL),y)
- BIN = "${shell cygpath -w $(APPDIR)/libapps$(LIBEXT)}"
+ BIN = ..\\..\\libapps$(LIBEXT)
else
- BIN = "$(APPDIR)/libapps$(LIBEXT)"
+ BIN = ../../libapps$(LIBEXT)
+endif
endif
ROOTDEPPATH = --dep-path .
@@ -73,30 +77,29 @@ $(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
.built: $(OBJS)
- @( for obj in $(OBJS) ; do \
- $(call ARCHIVE, $(BIN), $${obj}); \
- done ; )
- @touch .built
+ $(call ARCHIVE, $(BIN), $(OBJS))
+ $(Q) touch .built
.context:
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
- @touch $@
+ $(Q) touch $@
context: .context
.depend: Makefile $(SRCS)
- @$(MKDEP) $(ROOTDEPPATH) \
- $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
- @touch $@
+ $(Q) $(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
+ $(Q) touch $@
depend: .depend
clean:
- @rm -f *.o *~ .*.swp .built
+ $(call DELFILE, .built)
$(call CLEAN)
distclean: clean
- @rm -f Make.dep .depend
+ $(call DELFILE, .context)
+ $(call DELFILE, Make.dep)
+ $(call DELFILE, .depend)
-include Make.dep
diff --git a/apps/system/install/Makefile b/apps/system/install/Makefile
index 71d82f34c..6a02d859f 100644
--- a/apps/system/install/Makefile
+++ b/apps/system/install/Makefile
@@ -2,6 +2,7 @@
# apps/system/install/Makefile
#
# Copyright (C) 2011 Uros Platise. All rights reserved.
+# Copyright (C) 2012 Gregory Nutt. All rights reserved.
# Author: Uros Platise <uros.platise@isotel.eu>
# Gregory Nutt <gnutt@nuttx.org>
#
@@ -61,10 +62,14 @@ COBJS = $(CSRCS:.c=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS)
OBJS = $(AOBJS) $(COBJS)
+ifeq ($(CONFIG_WINDOWS_NATIVE),y)
+ BIN = ..\..\libapps$(LIBEXT)
+else
ifeq ($(WINTOOL),y)
- BIN = "${shell cygpath -w $(APPDIR)/libapps$(LIBEXT)}"
+ BIN = ..\\..\\libapps$(LIBEXT)
else
- BIN = "$(APPDIR)/libapps$(LIBEXT)"
+ BIN = ../../libapps$(LIBEXT)
+endif
endif
ROOTDEPPATH = --dep-path .
@@ -83,32 +88,32 @@ $(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
.built: $(OBJS)
- @( for obj in $(OBJS) ; do \
- $(call ARCHIVE, $(BIN), $${obj}); \
- done ; )
- @touch .built
+ $(call ARCHIVE, $(BIN), $(OBJS))
+ $(Q) touch .built
# Register application
.context:
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
- @touch $@
+ $(Q) touch $@
context: .context
# Create dependencies
.depend: Makefile $(SRCS)
- @$(MKDEP) $(ROOTDEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
- @touch $@
+ $(Q) $(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
+ $(Q) touch $@
depend: .depend
clean:
- @rm -f *.o *~ .*.swp .built
+ $(call DELFILE, .built)
$(call CLEAN)
distclean: clean
- @rm -f .context Make.dep .depend
+ $(call DELFILE, .context)
+ $(call DELFILE, Make.dep)
+ $(call DELFILE, .depend)
-include Make.dep
diff --git a/apps/system/readline/Makefile b/apps/system/readline/Makefile
index 34fab7e81..3a48d324e 100644
--- a/apps/system/readline/Makefile
+++ b/apps/system/readline/Makefile
@@ -52,10 +52,14 @@ COBJS = $(CSRCS:.c=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS)
OBJS = $(AOBJS) $(COBJS)
+ifeq ($(CONFIG_WINDOWS_NATIVE),y)
+ BIN = ..\..\libapps$(LIBEXT)
+else
ifeq ($(WINTOOL),y)
- BIN = "${shell cygpath -w $(APPDIR)/libapps$(LIBEXT)}"
+ BIN = ..\\..\\libapps$(LIBEXT)
else
- BIN = "$(APPDIR)/libapps$(LIBEXT)"
+ BIN = ../../libapps$(LIBEXT)
+endif
endif
ROOTDEPPATH = --dep-path .
@@ -74,10 +78,8 @@ $(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
.built: $(OBJS)
- @( for obj in $(OBJS) ; do \
- $(call ARCHIVE, $(BIN), $${obj}); \
- done ; )
- @touch .built
+ $(call ARCHIVE, $(BIN), $(OBJS))
+ $(Q) touch .built
# Context build phase target
@@ -86,18 +88,20 @@ context:
# Dependency build phase target
.depend: Makefile $(SRCS)
- @$(MKDEP) $(ROOTDEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
- @touch $@
+ $(Q) $(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
+ $(Q) touch $@
depend: .depend
# Housekeeping targets
clean:
- @rm -f *.o *~ .*.swp .built
+ $(call DELFILE, .built)
$(call CLEAN)
distclean: clean
- @rm -f .context Make.dep .depend
+ $(call DELFILE, .context)
+ $(call DELFILE, Make.dep)
+ $(call DELFILE, .depend)
-include Make.dep
diff --git a/nuttx/COPYING b/nuttx/COPYING
index 863b81a2f..b3655265d 100644
--- a/nuttx/COPYING
+++ b/nuttx/COPYING
@@ -163,6 +163,57 @@ dtoa():
"This product includes software developed by the University of
California, Berkeley and its contributors."
+libc/string/lib_vikmemcpy.c
+^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+ If you enable CONFIG_MEMCPY_VIK, then you will build with the optimized
+ version of memcpy from Daniel Vik. Licensing information for that version
+ of memcpy() follows:
+
+ Copyright (C) 1999-2010 Daniel Vik
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any
+ damages arising from the use of this software.
+ Permission is granted to anyone to use this software for any
+ purpose, including commercial applications, and to alter it and
+ redistribute it freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you
+ must not claim that you wrote the original software. If you
+ use this software in a product, an acknowledgment in the
+ use this software in a product, an acknowledgment in the
+ product documentation would be appreciated but is not
+ required.
+
+ 2. Altered source versions must be plainly marked as such, and
+ must not be misrepresented as being the original software.
+
+ 3. This notice may not be removed or altered from any source
+ distribution.
+
+libc/math
+^^^^^^^^^
+
+ If you enable CONFIG_LIB, you will build the math library at libc/math.
+ This library was taken from the math library developed for the Rhombus
+ OS by Nick Johnson (https://github.com/nickbjohnson4224/rhombus). This
+ port was contributed by Darcy Gong. The Rhombus math library has this
+ compatible MIT license:
+
+ Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
+
+ Permission to use, copy, modify, and distribute this software for any
+ purpose with or without fee is hereby granted, provided that the above
+ copyright notice and this permission notice appear in all copies.
+
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+
Documents/rss.gif
^^^^^^^^^^^^^^^^^
diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog
index a8e045616..ed1cf39dc 100644
--- a/nuttx/ChangeLog
+++ b/nuttx/ChangeLog
@@ -3453,7 +3453,7 @@
* net/uip/uip_icmpping.c: Fix problem that prevented ping from
going outside of local network. Submitted by Darcy Gong
-6.23 2012-09-29 Gregory Nutt <gnutt@nuttx.org>
+6.23 2012-11-05 Gregory Nutt <gnutt@nuttx.org>
* arch/arm/src/stm32/stm32_rng.c, chip/stm32_rng.h, and other files:
Implementation of /dev/random using the STM32 Random Number
@@ -3470,4 +3470,334 @@
* configs/shenzhou/*/Make.defs: Now uses the new buildroot 4.6.3
EABI toolchain.
* lib/stdio/lib_libdtoa.c: Another dtoa() fix from Mike Smith.
-
+ * configs/shenzhou/src/up_adc.c: Add ADC support for the Shenzhou
+ board (Darcy Gong).
+ * configs/shenzhou/thttpd: Add a THTTPD configuration for the
+ Shenzhou board (Darcy Gong).
+ * include/termios.h and lib/termios/libcf*speed.c: The non-standard,
+ "hidden" c_speed cannot be type const or else static instantiations
+ of termios will be required to initialize it (Mike Smith).
+ * drivers/input/max11802.c/h, and include/nuttx/input max11802.h: Adds
+ support for the Maxim MAX11802 touchscreen controller (contributed by
+ Petteri Aimonen).
+ * graphics/nxtk/nxtk_events.c: Missing implementation of the blocked
+ method. This is a critical bugfix for graphics support (contributed
+ by Petteri Aimonen).
+ * drivers/usbdev/pl2303.c, drivers/usbdev/usbmsc.h, and
+ include/nuttx/usb/cdcacm.h: USB_CONFIG_ATTR_SELFPOWER vs.
+ USB_CONFIG_ATT_SELFPOWER (contributed by Petteri Aimonen).
+ * arch/arm/src/armv7-m/up_memcpy.S: An optimized memcpy() function for
+ the ARMv7-M family contributed by Mike Smith.
+ * lib/strings/lib_vikmemcpy.c: As an option, the larger but faster
+ implemementation of memcpy from Daniel Vik is now available (this is
+ from http://www.danielvik.com/2010/02/fast-memcpy-in-c.html).
+ * lib/strings/lib_memset.c: CONFIG_MEMSET_OPTSPEED will select a
+ version of memset() optimized for speed. By default, memset() is
+ optimized for size.
+ * lib/strings/lib_memset.c: CONFIG_MEMSET_64BIT will perform 64-bit
+ aligned memset() operations.
+ * arch/arm/src/stm32/stm32_adc.c: Need to put the ADC back into the
+ initial reset in the open/setup logic. Opening the ADC driver works
+ the first time, but not the second because the device is left in a
+ powered down state on the last close.
+ * configs/olimex-lpc1766stck/scripts: Replace all of the identical
+ ld.script files with the common one in this directory.
+ * configs/stm3220g-eval/scripts: Replace all of the identical
+ ld.script files with the common one in this directory.
+ * configs/hymini-stm32v/scripts: Replace all of the identical
+ ld.script files with the common one in this directory.
+ * configs/lpcxpresso-lpc1768/scripts: Replace all of the identical
+ ld.script files with the common one in this directory.
+ * binfmt/elf.c, binfmt/libelf, include/elf.h, include/nuttx/elf.h: Add
+ basic framework for loadable ELF module support. The initial check-
+ in is non-functional and is simply the framework for ELF support.
+ * include/nuttx/binfmt.h, nxflat.h, elf.h, and symtab.h: Moved to
+ include/nuttx/binfmt/.
+ * arch/sim/src/up_elf.c and arch/x86/src/common/up_elf.c: Add
+ for ELF modules.
+ * arch/arm/include/elf.h: Added ARM ELF header file.
+ * include/elf32.h: Renamed elf.h to elf32.h.
+ * configs/stm32f4discovery/ostest: Converted to use the new
+ Kconfig-based configuration system.
+ * configs/stm32f4discovery/elf and configs/stm32f4discovery/scripts/gnu-elf.ld
+ Add a configuration for testing the ARM ELF loader.
+ * binfmt/libelf: Can't use fstat(). NuttX does not yet support it. Damn!
+ * binfmt/libelf: The basic ELF module execution appears fully functional.
+ * configs/shenzhou/src/up_relays.c: Add support for relays from the
+ Shenzhou board. Contributed by Darcy Gong.
+ * lib/fixedmath: Moved the old lib/math to lib/fixedmath to make room for
+ the math library from the Rhombus OS
+ * lib/math: Now contains the math library from the Rhombus OS by Nick Johnson
+ (submitted by Darcy Gong).
+ * include/float.h: Add a first cut at the float.h header file. This
+ really should be an architecture/toolchain-specific header file. It
+ is only used if CONFIG_ARCH_FLOAT_H is defined.
+ * lib/math: Files now conform to coding standards. Separated float,
+ double, and long double versions of code into separate files so that
+ they don't draw in so much un-necessary code when doing a dumb link.
+ * binfmt/libelf: The ELF loader is working correctly with C++ static
+ constructors and destructors and all.
+ * Documentation/NuttXBinfmt.html: Add documentation of the binary loader.
+ * configs/sim/ostest: Converted to use the mconf configuration tool.
+ * configs/sim/cxxtest: New test that will be used to verify the uClibc++
+ port (eventually).
+ * include/nuttx/fs/fs.h, lib/stdio/lib_libfread.c, lib_ferror.c,
+ lib_feof.c, and lib_clearerr.c: Add support for ferror(), feof(),
+ and clearerror(). ferror() support is bogus at the moment (it
+ is equivalent to !feof()); the others should be good.
+ * configs/stm32f4discovery/include/board.h: Correct timer 2-7
+ base frequency (provided by Freddie Chopin).
+ * include/nuttx/sched.h, sched/atexit.c, and sched/task_deletehook.c:
+ If both atexit() and on_exit() are enabled, then implement atexit()
+ as just a special caseof on_exit(). This assumes that the ABI can
+ handle receipt of more call parameters than the receiving function
+ expects. That is usually the case if parameters are passed in
+ registers.
+ * libxx/libxx_cxa_atexit(): Implements __cxa_atexit()
+ * configs/stm32f4discovery/cxxtest: New test that will be used to
+ verify the uClibc++ port (eventually). The sim platform turned not
+ to be a good platform for testing uClibc++. The sim example will not
+ run because the simulator will attempt to execute the static
+ constructors before main() starts. BUT... NuttX is not initialized
+ and this results in a crash. On the STM324Discovery, I will have
+ better control over when the static constructors run.
+ * RGMP 4.0 updated from Qiany Yu.
+ * configs/*/Make.defs and configs/*/ld.script: Massive clean-up
+ and standardization of linker scripts from Freddie Chopin.
+ * net/netdev_ioctl.c: Add interface state flags and ioctl calls
+ to bring network interfaces up and down (from Darcy Gong).
+ * config/stm32f4discovery: Enable C++ exceptions. Now the entire
+ apps/examples/cxxtest works -- meaning the the uClibc++ is
+ complete and verified for the STM32 platform.
+
+6.24 2012-12-20 Gregory Nutt <gnutt@nuttx.org>
+
+ * arch/arm/src/stm32: Support for STM32F100 high density chips
+ added by Freddie Chopin.
+ * configs/stm32f100_generic: Support for generic STM32F100RC board
+ contributed by Freddie Chopin.
+ * arch/arm/src/stm32_otgfsdev.c: Partial fix from Petteri Aimonen.
+ * drivers/lcd/ug-2864ambag01.c and include/nuttx/lcd/ug_2864ambag01.h:
+ LCD driver for the Univision OLED of the same name (untested on
+ initial check-in).
+ * configs/stm32f4discovery/nxlines: Configure to use mconf/Kconfig
+ tool.
+ * configs/stm32f4discovery/src/up_ug2864ambag01.c: Board-specific
+ initialization for UG-2864AMBAG01 OLED connecte to STM32F4Disovery.
+ * libxx/libxx_stdthrow.cxx: Exception stubs from Petteri Aimonen.
+ * configs/stm32f4discovery/src/up_ug2864ambag01.c: Driver has been
+ verified on the STM32F4Discovery platform. Some tuning of the
+ configuration could improve the presentation. Lower resolution displays
+ are also more subject to the "fat, flat line bug" that I need to fix
+ someday. See http://www.nuttx.org/doku.php?id=wiki:graphics:nxgraphics
+ for a description of the fat, flat line bug.
+ * libc: Renamed nuttx/lib to nuttx/libc to make space for a true lib/
+ directory that will be forthcoming. Also rename libraries: liblib.a -> libc.a,
+ libulib.a -> libuc.a, libklib.a -> libkc.a, liblibxx.a ->libcxx.a.
+ (I will probably, eventually rename libxx to libcxx for consistency)
+ * Makefile, lib/: A new, empty directory that will hold generated libraries.
+ This simplifies the library patch calculations and lets me get rid of some
+ bash logic. The change is functional, but only partially complete;
+ additional logic is needed in the arch/*/src/Makefile's as well. Right
+ now that logic generate multiple library paths, all pointing to the lib/
+ directory.
+ * arch/*/src/Makefile: Now uses only the libraries in lib/
+ Replace bash fragments that test for board/Makefile.
+ * Makefile.win: The beginnings of a Windows-native build. This is just
+ the beginning and not yet ready for prime time use.
+ * configs/stm32f4discovery/winbuild: This is a version of the standard
+ NuttX OS test, but configured to build natively on Windows. Its only
+ real purpose is to very the native Windows build logic.
+ * tools/mkdeps.bat and tools/mkdeps.c: mkdeps.bat is a failed attempt
+ to leverage mkdeps.sh to CMD.exe. It fails because the are certain
+ critical CFLAG values that cannot be passed on the CMD.exe command line
+ (like '='). mkdeps.c is a work in progress that will, hopefully,
+ replace both mkdeps.sh and mkdeps.bat.
+ * tools/Config.mk: Centralize the definition of the script that will be
+ used to generated header file include paths for the compiler. This
+ needs to be centralized in order to support the Windows native build.
+ * tools/incdir.bat: A replacement for tools/incdir.sh for use with the
+ the Windows native build.
+ * Makefile.unix: The existing top-level Makefile has been renamed
+ Makefile.unix.
+ * Makefile: This is a new top-level Makefile that just includes
+ either Makefile.unix or Makefile.win
+ * configs/stm3240g-eval/src: Qencoder fixes from Ryan Sundberg.
+ * arch/arm/src/stm32/stm32_qencoder.c: TIM3 bug fix from Ryan Sundberg.
+ * tools/mkromfsimg.sh: Correct typo in an error message (Ryan Sundberg)
+ * arch/*/src/Makefile: Remove tftboot install and creation of System.map
+ for Windows native build. The first is a necessary change, the second
+ just needs re-implemented.
+ * configs/mirtoo: Update Mirtoo pin definitions for Release 2. Provided
+ by Konstantin Dimitrov.
+ * Fixed an uninitialized variable in the file system that can cause
+ assertions if DEBUG on (contributed by Lorenz Meier).
+ * Config.mk: Defined DELIM to be either / or \, depending upon
+ CONFIG_WINDOWS_NATIVE. This will allow me to eliminate a lot of
+ conditional logic elsewhere.
+ * nuttx/graphics: One a mouse button is pressed, continue to report all
+ mouse button events to the first window that received the the initial
+ button down event, even if the mouse attempts to drag outside the
+ window. From Petteri Aimonen.
+ * nuttx/graphics/nxmu/nx_block.c: One more fix to the NX block message
+ logic from Petteri Aimonen.
+ * include/nuttx/wqueue.h: Some basic definitions to support a user-
+ space work queue (someday in the future).
+ * graphics/nxmu: Add semaphores so buffers messages that send buffers
+ will block until the buffer data has been acted upon.
+ * graphics/nxmw: Extended the blocked messages to cover mouse movement
+ and redraw events. These will also cause problems if sent to a window
+ while it is closing.
+ * arch/several: Change UARTs are enabled for i.MX, LM3S, ez80, and M16C to
+ match how they are enabled for other architectures.
+ * configs/ez80f910200kitg: Convert to use mconf configuration.
+ * sched/pause.c: Implements the POSIX pause() function.
+ * ez80: Lots of changes to ez80 configurations and build logic as I
+ struggle to get a clean Windows build (still not working).
+ * configs/cloudctrl: Darcy Gong's CloudController board. This is a
+ small network relay development board. Based on the Shenzhou IV development
+ board design. It is based on the STM32F107VC MCU.
+ * arch/arm/src/stm32_serial.c and stm32_lowputc.c: Added optional RS-485
+ direction bit control. From Freddie Chopin.
+ * Lots of build files: ARMv7-M and MIPS32 Make.defs now include a common
+ Toolchain.defs file that can be used to manage toolchains in a more
+ configurable way. Contributed by Mike Smith
+ * configs/stm32f4discovery/winbuild and configs/cloudctrl: Adapted to use
+ Mike's Toolchain.defs.
+ * tools/configure.sh: Adapted to handle paths and setenv.bat files correctly
+ for native Windows builds.
+ * More of build files: AVR and AVR32 Make.defs now include a common
+ Toolchain.defs file that can be used to manage toolchains in a more
+ configurable way. Contributed by Mike Smith
+ * tools/incdir.sh and incdir.bat: Add -s option to generate system header
+ file paths.
+ * nuttx/arch/arm/src/arm/Toolchain.defs: Add support for more ARM toolchains
+ (from Mike Smith).
+ * arch/arm/src/stm32/stm32f40xxx_rcc.c: Enabled FLASH prefetch (from Petteri
+ Aimonen).
+ * graphics/nxtk/nxtk_filltrapwindow.c: Correct an offset problem (from
+ Peterri Aimonen).
+ * graphics/nxglib/nxglib_splitline.c: Fix error in drawing of near horizontal
+ lines (from Peterri Aimonen).
+ * sched/task_exithook.c: Missing right bracket with certain conditional
+ compilation (thanks James Goppert).
+ * arch/arm/srch/stm32/stm32_otgfshost.c: Replace timeout handling; use
+ system tick instead of frame counter. The frame counter gets reset to
+ zero at 0x3fff making it error prone.
+ * arch/arm/src/stm32/stm32f20xx_rcc.c and stm32f40xx_rcc.c: Added option
+ CONFIG_STM32_FLASH_PREFETCH. FLASH prefetch will now only be enabled
+ if this option is selected.
+ * confgs/ez80f910200zco/ostest: Now uses Kconfig/mconf configuration
+ tool. Updated to build in native Windows environment. Other ez80f910200zco
+ build scripts also updated.
+ * configs/z8f64200100kit/ostest: Update to same level as ez80 configurations.
+ * nuttx/configs/z8f64200100kit/scripts/setenv.bat: Add support for native
+ Windows build.
+ * nuttx/arch/arm/src/lpc17xx/lpc17_i2c.c: Resources not being released when
+ I2C is uninitialized.
+ * cloudctrl/src/up_chipid.c and shenzhou/src/up_chipid.c: Add functions to
+ get chip ID. Contributed by Darcy Gong. These should not be board-dependent,
+ but should be in arch/arm/src/stm32 where they can be used from any board.
+ * sched/work_thread.c: Fix backward conditional compilation. This might
+ has caused a memory leak. From Freddie Chopin.
+ * configs/<many>/Make.defs: Fix typo -wstrict-prototypes should be
+ -Wstrict-prototypes (From Denis Carilki).
+ * arch/arm/src/calapyso/calypso_keypad.c: Add Calypso keypad driver. From
+ Denis Carilki.
+ * z8encore000zco/ostest and z8f64200100kit/ostest: Converted to use Kconfig/
+ mconf configuration tool.
+ * arch/arm/src/armv7-m/up_exception.S: missing curly braces for push/pop
+ From Freddie Chopin.
+ * z8encore000zco/ostest and z8f64200100kit/ostest: Can now be modified to
+ support the Windows native builds (see corresponding README.txt files).
+ * configs/z16f2800100zcog - All configurations updated to use the ZDS-II
+ 5.0.1 toolchain.
+ * configs/z16f2800100zcog - All configurations updated to use Kconfig/mconf
+ configuration tools.
+ * configs/z16f2800100zcog/ostest - Now supports a native Windows build
+ (other ZNEO configs may also support the native build, but this has not
+ been verfiied).
+ * include/nuttx/input/keypad.h, arch/arm/src/calypso/calypso_keypad.c, and
+ configs/compal_e99/nsh_highram: First cut at a standard keypad interface
+ definition. Contributed by Denis Carikli.
+ * libc/stdlib/lib_rand.c: Always add one to result congruential generators
+ to avoid the value zero. Suggested by Freddie Chopin.
+ * tools/b16.c: Fixed precision math conversion utility.
+ * graphics/nxglib/nxglib_splitline.c: Fix the "fat, flat line bug"
+ * arch/z80/src/*/Toolchain.defs: Add dummy Toolchain.defs files for the
+ z80 family.
+ * configs/z80sim/ostest: Converted to build with the Kconfig/mconf tool.
+ Current configuration failed to build for me (Ubuntu 12.10, SDCC 3.2.0
+ pre-built for Linux) due to a glibc memory corruptionerror in SDCC.
+ * configs/z80sim/ostest: Default is now the Windows native build. See
+ configs/z80sim/README.txt for instructions to convert back to a Linux or
+ or Cygwin build.
+ * arch/z80/src/Makefile.sdccw: Renamed makefiles with extensions zdiil,
+ zdiiw, sdccl, and sdccw for the ZDS-II vs SDCC compilers and for the
+ POSIX vs Windows native builds.
+ * nuttx/drivers/mtd/ftl.c: Fix for the flash translation layer. Short
+ unaligned writes were buggy. From Petteri Aimonen.
+ * nuttx/libc/math/lib_round*.c: Add rounding functions to the math
+ library. Contributed by Petteri Aimonen.
+ * include/cxx/cstdlib: Add stroul(). From Petteri Aimonen.
+ * arch/*/include/limits.h: Change signed minimum values from, for example,
+ (-128) to (-127 - 1) to avoid overflows under certain conditions. From
+ Peterri Aimonen.
+ * graphics/nxtk/nxtk_subwindowmove.c: Previously it was very difficult to
+ do e.g. "scroll by dx, dy". When given the full window area, nxtk_subwindowmove
+ would clip the offset always to 0,0. It makes more sense for it to clip the
+ source area and not modify the offset. From Petteri Aimonen.
+ * graphics/nxtk/nxtk_getwindow.c: Clipping would change the offset of returned
+ data, and caller has no way to know what the new offset would be. This messes
+ up font drawing when the text is partially out of window, e.g. when scrolling.
+ Also from Petteri Aimonen.
+ * include/stdbool.h: Can now be disabled for C++ files if CONFIG_C99_BOOL8 is
+ defined. CONFIG_C99_BOOL8 indicates (1) that the sizeof(_Bool) is one in both
+ C and C++, and (2) the the C compiler is C99 and supports the _Bool intrinsic
+ type. Requested by Freddie Chopin.
+ * include/stdlib/lib_rand.c: Various additional changes so that the integer
+ value zero can be returned. Requested by Freddie Chopin.
+ * arch/z80/src/Makefile.sdcc*, z80/up_mem.h: Redesign Z80 build so that it
+ no longer depends on Bash scripts.
+ * configs/z80sim/nsh and pashello: Converted to (1) use the kconfig-frontends
+ configuration tool, and (2) to build natively under Windows. The NSH
+ configuration is verified; the pashello configuration needs a more TLC.
+ * tools/copydir.sh: Rename tools/winlink.sh to tools/copydir.sh
+ * tools/link.bat, unlink.bat, and copydir.bat: Add Windows counterparts
+ to the link.sh, unlink.sh, and copydir.sh Bash scripts.
+ * configs/z80sim/pashello: Now builds correctly.
+ * configs/xtrs/ostest, nsh, and pashello: Converted to (1) use the kconfig-
+ frontends configuration tool, and (2) to build natively under Windows.
+ * drivers/serial/Kconfig and sched/Kconfig: Two names for same configuration:
+ CONFIG_LOWLEVEL_CONSOLE is bogus and CONFIG_DEV_LOWCONSOLE is in the wrong
+ Kconfig file. Moved to drivers/serial/Kconfig replacing CONFIG_LOWLEVEL_CONSOLE.
+ * arch/z80/include/z180: Add header files for z180 chips. Initial versions
+ are just clones of z80 header files.
+ * arch/z80/src/z180: Add source files for z180 chips. Initial versions
+ are just clones of z80 source files.
+ * include/nuttx/arch.h: Add address environment control interfaces (for use
+ with CPUs the provide MCUs and support process-like address environments).
+ * arch/z80/src/z180/z180_mmu.*: Add MMU support for z180 tasks.
+ * configs/p112: Add very basic board support and an examples/ostest
+ configuration for the venerable P112 board.
+ * sched/os_bringup.c: If CONFIG_PATH_INITIAL is defined, then the initial
+ environment of the task started by os_bringup() will have the PATH
+ environment variable defined to be that string.
+ * binfmt/binfmt_exepath.c: If CONFIG_BINFMT_EXEPATH is defined, then this
+ file will be built. It contains logic to search for regular files at
+ the absolutes paths found in the current PATH environment variable
+ setting. This is untested and not yet hooked into the binfmt exec()
+ logic on initial check-in
+ * binfmt/binfmt_loadmodule.c: load_module() will now traverse the PATH
+ variable to locate files from their relative path.
+ * include/nuttx/arch.h and arch/z80/src/z180/z180_mmu.c: Restructure the
+ address environment interfaces so that they will better integrate with
+ binfmt/.
+ * binfmt/libelf/*, binfmt/libnxflat/* and other files: Integrate the
+ address environment interfaces. If CONFIG_ADDRENV=y, then binfmt/
+ will now create an address environment for new tasks (instead of
+ just malloc'ing the task memory).
+ * configs/stm32f4discovery/elf: Enable support/test of the PATH
+ to find executables using a relative path.
+
+6.25 2013-xx-xx Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/Kconfig b/nuttx/Kconfig
index 0fe6eb0f7..10d624efb 100644
--- a/nuttx/Kconfig
+++ b/nuttx/Kconfig
@@ -20,10 +20,75 @@ menu "Build Setup"
config EXPERIMENTAL
bool "Prompt for development and/or incomplete code/drivers"
+choice
+ prompt "Build Host Platform"
+ default HOST_LINUX
+
+config HOST_LINUX
+ bool "Linux"
+
+config HOST_OSX
+ bool "OSX"
+
+config HOST_WINDOWS
+ bool "Windows"
+
+config HOST_OTHER
+ bool "Other"
+
+endchoice
+
+choice
+ prompt "Windows Build Environment"
+ default WINDOWS_CYGWIN
+ depends on HOST_WINDOWS
+
+config WINDOWS_NATIVE
+ bool "Windows Native"
+ ---help---
+ Build natively in a CMD.exe environment with Windows style paths (like C:\cgywin\home)
+
+config WINDOWS_CYGWIN
+ bool "Cygwin"
+- --help---
+ Build natively in a Cygwin environment with POSIX style paths (like /cygdrive/c/cgywin/home)
+
+config WINDOWS_MSYS
+ bool "MSYS"
+ ---help---
+ Build natively in a Cygwin environment with POSIX style paths (like /cygdrive/c/cgywin/home)
+
+config WINDOWS_OTHER
+ bool "Windows POSIX-like environment"
+ ---help---
+ Build natively in another POSIX-like environment. Additional support may be necessary
+
+endchoice
+
+config WINDOWS_MKLINK
+ bool "Use mklink"
+ default n
+ depends on WINDOWS_NATIVE
+ ---help---
+ Use the mklink command to set up symbolic links when NuttX is
+ configured. Otherwise, configuration directories will be copied to
+ establish the configuration.
+
+ If directories are copied, then some confusion can result ("Which
+ version of the file did I modify?"). In that case, it is recommended
+ that you re-build using 'make clean_context all'. That will cause the
+ configured directories to be recopied on each build.
+
+ NOTE: This option also (1) that you have administrator privileges, (2)
+ that you are using Windows 2000 or better, and (3) that you are using
+ the NTFS file system. Select 'n' is that is not the case.
+
menu "Build Configuration"
+
config APPS_DIR
string "Application directory"
- default "../apps"
+ default "../apps" if !WINDOWS_NATIVE
+ default "..\apps" if WINDOWS_NATIVE
---help---
Identifies the directory that builds the
application to link with NuttX. Default: ../apps This symbol must be assigned
@@ -192,6 +257,17 @@ config ARCH_MATH_H
that don't select ARCH_MATH_H, the redirecting math.h header file
will stay out-of-the-way in include/nuttx/.
+config ARCH_FLOAT_H
+ bool "float.h"
+ default n
+ ---help---
+ The float.h header file defines the properties of your floating
+ point implementation. It would always be best to use your
+ toolchain's float.h header file but if none is avaiable, a default
+ float.h header file will provided if this option is selected. However
+ there is no assurance that the settings in this float.h are actually
+ correct for your platform!
+
config ARCH_STDARG_H
bool "stdarg.h"
default n
@@ -244,17 +320,24 @@ config DEBUG_ENABLE
comment "Subsystem Debug Options"
+config DEBUG_MM
+ bool "Enable Memory Manager Debug Output"
+ default n
+ ---help---
+ Enable memory management debug output (disabled by default)
+
config DEBUG_SCHED
bool "Enable Scheduler Debug Output"
default n
---help---
Enable OS debug output (disabled by default)
-config DEBUG_MM
- bool "Enable Memory Manager Debug Output"
+config DEBUG_PAGING
+ bool "Enable Demand Paging Debug Output"
default n
+ depends on PAGING
---help---
- Enable memory management debug output (disabled by default)
+ Enable demand paging debug output (disabled by default)
config DEBUG_NET
bool "Enable Network Debug Output"
@@ -311,6 +394,13 @@ config DEBUG_INPUT
Enable low level debug output from the input device drivers such as
mice and touchscreens (disabled by default)
+config DEBUG_ANALOG
+ bool "Enable Analog Device Debug Output"
+ default n
+ ---help---
+ Enable low level debug output from the analog device drivers such as
+ A/D and D/A converters (disabled by default)
+
config DEBUG_I2C
bool "Enable I2C Debug Output"
default n
@@ -325,12 +415,18 @@ config DEBUG_SPI
---help---
Enable I2C driver debug output (disabled by default)
+config DEBUG_DMA
+ bool "Enable DMA Debug Output"
+ default n
+ ---help---
+ Enable DMA-releated debug output (disabled by default)
+
config DEBUG_WATCHDOG
bool "Enable Watchdog Timer Debug Output"
default n
depends on WATCHDOG
---help---
- Enable watchdog timer debug output (disabled by default)
+ Enable watchdog timer debug output (disabled by default)
endif
@@ -375,8 +471,12 @@ menu "Memory Management"
source mm/Kconfig
endmenu
+menu "Binary Formats"
+source binfmt/Kconfig
+endmenu
+
menu "Library Routines"
-source lib/Kconfig
+source libc/Kconfig
source libxx/Kconfig
endmenu
diff --git a/nuttx/Makefile b/nuttx/Makefile
index 7a058d88e..cf7a57c83 100644
--- a/nuttx/Makefile
+++ b/nuttx/Makefile
@@ -1,7 +1,7 @@
############################################################################
# Makefile
#
-# Copyright (C) 2007-2012 Gregory Nutt. All rights reserved.
+# Copyright (C) 2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
@@ -33,619 +33,17 @@
#
############################################################################
-TOPDIR := ${shell pwd | sed -e 's/ /\\ /g'}
--include ${TOPDIR}/.config
--include ${TOPDIR}/tools/Config.mk
--include ${TOPDIR}/Make.defs
-
-# Control build verbosity
-
-ifeq ($(V),1)
-export Q :=
-else
-export Q := @
-endif
-
-# Default tools
-
-ifeq ($(DIRLINK),)
-DIRLINK = $(TOPDIR)/tools/link.sh
-DIRUNLINK = $(TOPDIR)/tools/unlink.sh
-endif
-
-# This define is passed as EXTRADEFINES for kernel-mode builds. It is also passed
-# during PASS1 (but not PASS2) context and depend targets.
-
-KDEFINE = ${shell $(TOPDIR)/tools/define.sh $(CC) __KERNEL__}
-
-# Process architecture and board-specific directories
-
-ARCH_DIR = arch/$(CONFIG_ARCH)
-ARCH_SRC = $(ARCH_DIR)/src
-ARCH_INC = $(ARCH_DIR)/include
-BOARD_DIR = configs/$(CONFIG_ARCH_BOARD)
-
-# Add-on directories. These may or may not be in place in the
-# NuttX source tree (they must be specifically installed)
+# This is a top-level "kludge" Makefile that just includes the correct
+# Makefile. If you already know the Makefile that you want, you can skip
+# this nonsense using:
#
-# CONFIG_APPS_DIR can be over-ridden from the command line or in the .config file.
-# The default value of CONFIG_APPS_DIR is ../apps. Ultimately, the application
-# will be built if APPDIR is defined. APPDIR will be defined if a directory containing
-# a Makefile is found at the path provided by CONFIG_APPS_DIR
-
-ifeq ($(CONFIG_APPS_DIR),)
-CONFIG_APPS_DIR = ../apps
-endif
-APPDIR := ${shell if [ -r $(CONFIG_APPS_DIR)/Makefile ]; then echo "$(CONFIG_APPS_DIR)"; fi}
-
-# All add-on directories.
+# make -f Makefile.unix, OR
+# make -f Makefile.win
#
-# NUTTX_ADDONS is the list of directories built into the NuttX kernel.
-# USER_ADDONS is the list of directories that will be built into the user application
-NUTTX_ADDONS := $(NX_DIR)
-USER_ADDONS :=
-
-ifeq ($(CONFIG_NUTTX_KERNEL),y)
-USER_ADDONS += $(APPDIR)
+-include .config
+ifeq ($(CONFIG_WINDOWS_NATIVE),y)
+include Makefile.win
else
-NUTTX_ADDONS += $(APPDIR)
-endif
-
-# Lists of build directories.
-#
-# FSDIRS depend on file descriptor support; NONFSDIRS do not (except for parts
-# of FSDIRS). We will exclude FSDIRS from the build if file descriptor
-# support is disabled
-# CONTEXTDIRS include directories that have special, one-time pre-build
-# requirements. Normally this includes things like auto-generation of
-# configuration specific files or creation of configurable symbolic links
-# USERDIRS - When NuttX is build is a monolithic kernel, this provides the
-# list of directories that must be built
-# OTHERDIRS - These are directories that are not built but probably should
-# be cleaned to prevent garbarge from collecting in them when changing
-# configurations.
-
-NONFSDIRS = sched $(ARCH_SRC) $(NUTTX_ADDONS)
-FSDIRS = fs drivers binfmt
-CONTEXTDIRS = $(APPDIR)
-USERDIRS =
-
-ifeq ($(CONFIG_NUTTX_KERNEL),y)
-
-NONFSDIRS += syscall
-CONTEXTDIRS += syscall
-USERDIRS += syscall lib mm $(USER_ADDONS)
-ifeq ($(CONFIG_HAVE_CXX),y)
-USERDIRS += libxx
-endif
-
-else
-
-NONFSDIRS += lib mm
-OTHERDIRS += syscall $(USER_ADDONS)
-ifeq ($(CONFIG_HAVE_CXX),y)
-NONFSDIRS += libxx
-else
-OTHERDIRS += libxx
-endif
-
-endif
-
-ifeq ($(CONFIG_NX),y)
-NONFSDIRS += graphics
-CONTEXTDIRS += graphics
-else
-OTHERDIRS += graphics
-endif
-
-# CLEANDIRS are the directories that will clean in. These are
-# all directories that we know about.
-# KERNDEPDIRS are the directories in which we will build target dependencies.
-# If NuttX and applications are built separately (CONFIG_NUTTX_KERNEL),
-# then this holds only the directories containing kernel files.
-# USERDEPDIRS. If NuttX and applications are built separately (CONFIG_NUTTX_KERNEL),
-# then this holds only the directories containing user files.
-
-CLEANDIRS = $(NONFSDIRS) $(FSDIRS) $(USERDIRS) $(OTHERDIRS)
-KERNDEPDIRS = $(NONFSDIRS)
-USERDEPDIRS = $(USERDIRS)
-
-# Add file system directories to KERNDEPDIRS (they are already in CLEANDIRS)
-
-ifeq ($(CONFIG_NFILE_DESCRIPTORS),0)
-ifeq ($(CONFIG_NET),y)
-ifneq ($(CONFIG_NSOCKET_DESCRIPTORS),0)
-KERNDEPDIRS += fs
-endif
-KERNDEPDIRS += drivers
-endif
-else
-KERNDEPDIRS += $(FSDIRS)
-endif
-
-# Add networking directories to KERNDEPDIRS and CLEANDIRS
-
-ifeq ($(CONFIG_NET),y)
-KERNDEPDIRS += net
-endif
-CLEANDIRS += net
-
-#
-# Extra objects used in the final link.
-#
-# Pass 1 1ncremental (relative) link objects should be put into the
-# processor-specific source directory (where other link objects will
-# be created). If the pass1 obect is an archive, it could go anywhere.
-
-ifeq ($(CONFIG_BUILD_2PASS),y)
-EXTRA_OBJS += $(CONFIG_PASS1_OBJECT)
-endif
-
-# NUTTXLIBS is the list of NuttX libraries that is passed to the
-# processor-specific Makefile to build the final NuttX target.
-# Libraries in FSDIRS are excluded if file descriptor support
-# is disabled.
-# USERLIBS is the list of libraries used to build the final user-space
-# application
-
-NUTTXLIBS = sched/libsched$(LIBEXT) $(ARCH_SRC)/libarch$(LIBEXT)
-USERLIBS =
-
-# Add libraries for syscall support. The C library will be needed by
-# both the kernel- and user-space builds. For now, the memory manager (mm)
-# is placed in user space (only).
-
-ifeq ($(CONFIG_NUTTX_KERNEL),y)
-NUTTXLIBS += syscall/libstubs$(LIBEXT) lib/libklib$(LIBEXT)
-USERLIBS += syscall/libproxies$(LIBEXT) lib/libulib$(LIBEXT) mm/libmm$(LIBEXT)
-else
-NUTTXLIBS += mm/libmm$(LIBEXT) lib/liblib$(LIBEXT)
-endif
-
-# Add libraries for C++ support. CXX, CXXFLAGS, and COMPILEXX must
-# be defined in Make.defs for this to work!
-
-ifeq ($(CONFIG_HAVE_CXX),y)
-ifeq ($(CONFIG_NUTTX_KERNEL),y)
-USERLIBS += libxx/liblibxx$(LIBEXT)
-else
-NUTTXLIBS += libxx/liblibxx$(LIBEXT)
-endif
-endif
-
-# Add library for application support.
-
-ifneq ($(APPDIR),)
-ifeq ($(CONFIG_NUTTX_KERNEL),y)
-USERLIBS += $(APPDIR)/libapps$(LIBEXT)
-else
-NUTTXLIBS += $(APPDIR)/libapps$(LIBEXT)
-endif
-endif
-
-# Add libraries for network support
-
-ifeq ($(CONFIG_NET),y)
-NUTTXLIBS += net/libnet$(LIBEXT)
-endif
-
-# Add libraries for file system support
-
-ifeq ($(CONFIG_NFILE_DESCRIPTORS),0)
-ifneq ($(CONFIG_NSOCKET_DESCRIPTORS),0)
-NUTTXLIBS += fs/libfs$(LIBEXT)
-endif
-ifeq ($(CONFIG_NET),y)
-NUTTXLIBS += drivers/libdrivers$(LIBEXT)
-endif
-else
-NUTTXLIBS += fs/libfs$(LIBEXT) drivers/libdrivers$(LIBEXT) binfmt/libbinfmt$(LIBEXT)
-endif
-
-# Add libraries for the NX graphics sub-system
-
-ifneq ($(NX_DIR),)
-NUTTXLIBS += $(NX_DIR)/libnx$(LIBEXT)
-endif
-
-ifeq ($(CONFIG_NX),y)
-NUTTXLIBS += graphics/libgraphics$(LIBEXT)
-endif
-
-# This is the name of the final target (relative to the top level directorty)
-
-BIN = nuttx$(EXEEXT)
-
-all: $(BIN)
-.PHONY: context clean_context check_context export subdir_clean clean subdir_distclean distclean apps_clean apps_distclean
-
-# Target used to copy include/nuttx/math.h. If CONFIG_ARCH_MATH_H is
-# defined, then there is an architecture specific math.h header file
-# that will be included indirectly from include/math.h. But first, we
-# have to copy math.h from include/nuttx/. to include/.
-
-ifeq ($(CONFIG_ARCH_MATH_H),y)
-include/math.h: include/nuttx/math.h
- @cp -f include/nuttx/math.h include/math.h
-else
-include/math.h:
-endif
-
-# Target used to copy include/nuttx/stdarg.h. If CONFIG_ARCH_STDARG_H is
-# defined, then there is an architecture specific stdarg.h header file
-# that will be included indirectly from include/stdarg.h. But first, we
-# have to copy stdarg.h from include/nuttx/. to include/.
-
-ifeq ($(CONFIG_ARCH_STDARG_H),y)
-include/stdarg.h: include/nuttx/stdarg.h
- @cp -f include/nuttx/stdarg.h include/stdarg.h
-else
-include/stdarg.h:
-endif
-
-# Targets used to build include/nuttx/version.h. Creation of version.h is
-# part of the overall NuttX configuration sequence. Notice that the
-# tools/mkversion tool is built and used to create include/nuttx/version.h
-
-tools/mkversion:
- @$(MAKE) -C tools -f Makefile.host TOPDIR="$(TOPDIR)" mkversion
-
-$(TOPDIR)/.version:
- @if [ ! -f .version ]; then \
- echo "No .version file found, creating one"; \
- tools/version.sh -v 0.0 -b 0 .version; \
- chmod 755 .version; \
- fi
-
-include/nuttx/version.h: $(TOPDIR)/.version tools/mkversion
- @tools/mkversion $(TOPDIR) > include/nuttx/version.h
-
-# Targets used to build include/nuttx/config.h. Creation of config.h is
-# part of the overall NuttX configuration sequence. Notice that the
-# tools/mkconfig tool is built and used to create include/nuttx/config.h
-
-tools/mkconfig:
- @$(MAKE) -C tools -f Makefile.host TOPDIR="$(TOPDIR)" mkconfig
-
-include/nuttx/config.h: $(TOPDIR)/.config tools/mkconfig
- @tools/mkconfig $(TOPDIR) > include/nuttx/config.h
-
-# dirlinks, and helpers
-#
-# Directories links. Most of establishing the NuttX configuration involves
-# setting up symbolic links with 'generic' directory names to specific,
-# configured directories.
-#
-# Link the apps/include directory to include/apps
-
-include/apps: Make.defs
-ifneq ($(APPDIR),)
- @if [ -d $(TOPDIR)/$(APPDIR)/include ]; then \
- $(DIRLINK) $(TOPDIR)/$(APPDIR)/include include/apps; \
- fi
-endif
-
-# Link the arch/<arch-name>/include directory to include/arch
-
-include/arch: Make.defs
- @$(DIRLINK) $(TOPDIR)/$(ARCH_DIR)/include include/arch
-
-# Link the configs/<board-name>/include directory to include/arch/board
-
-include/arch/board: include/arch Make.defs include/arch
- @$(DIRLINK) $(TOPDIR)/$(BOARD_DIR)/include include/arch/board
-
-# Link the configs/<board-name>/src dir to arch/<arch-name>/src/board
-
-$(ARCH_SRC)/board: Make.defs
- @$(DIRLINK) $(TOPDIR)/$(BOARD_DIR)/src $(ARCH_SRC)/board
-
-# Link arch/<arch-name>/include/<chip-name> to arch/<arch-name>/include/chip
-
-$(ARCH_SRC)/chip: Make.defs
-ifneq ($(CONFIG_ARCH_CHIP),)
- @$(DIRLINK) $(TOPDIR)/$(ARCH_SRC)/$(CONFIG_ARCH_CHIP) $(ARCH_SRC)/chip
-endif
-
-# Link arch/<arch-name>/src/<chip-name> to arch/<arch-name>/src/chip
-
-include/arch/chip: include/arch Make.defs
-ifneq ($(CONFIG_ARCH_CHIP),)
- @$(DIRLINK) $(TOPDIR)/$(ARCH_INC)/$(CONFIG_ARCH_CHIP) include/arch/chip
+include Makefile.unix
endif
-
-dirlinks: include/arch include/arch/board include/arch/chip $(ARCH_SRC)/board $(ARCH_SRC)/chip include/apps
-
-# context
-#
-# The context target is invoked on each target build to assure that NuttX is
-# properly configured. The basic configuration steps include creation of the
-# the config.h and version.h header files in the include/nuttx directory and
-# the establishment of symbolic links to configured directories.
-
-context: check_context include/nuttx/config.h include/nuttx/version.h include/math.h include/stdarg.h dirlinks
- @for dir in $(CONTEXTDIRS) ; do \
- $(MAKE) -C $$dir TOPDIR="$(TOPDIR)" context; \
- done
-
-# clean_context
-#
-# This is part of the distclean target. It removes all of the header files
-# and symbolic links created by the context target.
-
-clean_context:
- @rm -f include/nuttx/config.h
- @rm -f include/nuttx/version.h
- @rm -f include/math.h
- @rm -f include/stdarg.h
- @$(DIRUNLINK) include/arch/board
- @$(DIRUNLINK) include/arch/chip
- @$(DIRUNLINK) include/arch
- @$(DIRUNLINK) $(ARCH_SRC)/board
- @$(DIRUNLINK) $(ARCH_SRC)/chip
- @$(DIRUNLINK) include/apps
-
-# check_context
-#
-# This target checks if NuttX has been configured. NuttX is configured using
-# the script tools/configure.sh. That script will install certain files in
-# the top-level NuttX build directory. This target verifies that those
-# configuration files have been installed and that NuttX is ready to be built.
-
-check_context:
- @if [ ! -e ${TOPDIR}/.config -o ! -e ${TOPDIR}/Make.defs ]; then \
- echo "" ; echo "Nuttx has not been configured:" ; \
- echo " cd tools; ./configure.sh <target>" ; echo "" ; \
- exit 1 ; \
- fi
-
-# Archive targets. The target build sequency will first create a series of
-# libraries, one per configured source file directory. The final NuttX
-# execution will then be built from those libraries. The following targets
-# built those libraries.
-#
-# Possible kernel-mode builds
-
-lib/libklib$(LIBEXT): context
- @$(MAKE) -C lib TOPDIR="$(TOPDIR)" libklib$(LIBEXT) EXTRADEFINES=$(KDEFINE)
-
-sched/libsched$(LIBEXT): context
- @$(MAKE) -C sched TOPDIR="$(TOPDIR)" libsched$(LIBEXT) EXTRADEFINES=$(KDEFINE)
-
-$(ARCH_SRC)/libarch$(LIBEXT): context
- @$(MAKE) -C $(ARCH_SRC) TOPDIR="$(TOPDIR)" libarch$(LIBEXT) EXTRADEFINES=$(KDEFINE)
-
-net/libnet$(LIBEXT): context
- @$(MAKE) -C net TOPDIR="$(TOPDIR)" libnet$(LIBEXT) EXTRADEFINES=$(KDEFINE)
-
-fs/libfs$(LIBEXT): context
- @$(MAKE) -C fs TOPDIR="$(TOPDIR)" libfs$(LIBEXT) EXTRADEFINES=$(KDEFINE)
-
-drivers/libdrivers$(LIBEXT): context
- @$(MAKE) -C drivers TOPDIR="$(TOPDIR)" libdrivers$(LIBEXT) EXTRADEFINES=$(KDEFINE)
-
-binfmt/libbinfmt$(LIBEXT): context
- @$(MAKE) -C binfmt TOPDIR="$(TOPDIR)" libbinfmt$(LIBEXT) EXTRADEFINES=$(KDEFINE)
-
-graphics/libgraphics$(LIBEXT): context
- @$(MAKE) -C graphics TOPDIR="$(TOPDIR)" libgraphics$(LIBEXT) EXTRADEFINES=$(KDEFINE)
-
-syscall/libstubs$(LIBEXT): context
- @$(MAKE) -C syscall TOPDIR="$(TOPDIR)" libstubs$(LIBEXT) EXTRADEFINES=$(KDEFINE)
-
-# Possible user-mode builds
-
-lib/libulib$(LIBEXT): context
- @$(MAKE) -C lib TOPDIR="$(TOPDIR)" libulib$(LIBEXT)
-
-libxx/liblibxx$(LIBEXT): context
- @$(MAKE) -C libxx TOPDIR="$(TOPDIR)" liblibxx$(LIBEXT)
-
-mm/libmm$(LIBEXT): context
- @$(MAKE) -C mm TOPDIR="$(TOPDIR)" libmm$(LIBEXT) EXTRADEFINES=$(KDEFINE)
-
-$(APPDIR)/libapps$(LIBEXT): context
- @$(MAKE) -C $(APPDIR) TOPDIR="$(TOPDIR)" libapps$(LIBEXT)
-
-syscall/libproxies$(LIBEXT): context
- @$(MAKE) -C syscall TOPDIR="$(TOPDIR)" libproxies$(LIBEXT)
-
-# Possible non-kernel builds
-
-lib/liblib$(LIBEXT): context
- @$(MAKE) -C lib TOPDIR="$(TOPDIR)" liblib$(LIBEXT)
-
-# pass1 and pass2
-#
-# If the 2 pass build option is selected, then this pass1 target is
-# configured to built before the pass2 target. This pass1 target may, as an
-# example, build an extra link object (CONFIG_PASS1_OBJECT) which may be an
-# incremental (relative) link object, but could be a static library (archive);
-# some modification to this Makefile would be required if CONFIG_PASS1_OBJECT
-# is an archive. Exactly what is performed during pass1 or what it generates
-# is unknown to this makefule unless CONFIG_PASS1_OBJECT is defined.
-
-pass1deps: context pass1dep $(USERLIBS)
-
-pass1: pass1deps
-ifeq ($(CONFIG_BUILD_2PASS),y)
- @if [ -z "$(CONFIG_PASS1_BUILDIR)" ]; then \
- echo "ERROR: CONFIG_PASS1_BUILDIR not defined"; \
- exit 1; \
- fi
- @if [ ! -d "$(CONFIG_PASS1_BUILDIR)" ]; then \
- echo "ERROR: CONFIG_PASS1_BUILDIR does not exist"; \
- exit 1; \
- fi
- @if [ ! -f "$(CONFIG_PASS1_BUILDIR)/Makefile" ]; then \
- echo "ERROR: No Makefile in CONFIG_PASS1_BUILDIR"; \
- exit 1; \
- fi
- @$(MAKE) -C $(CONFIG_PASS1_BUILDIR) TOPDIR="$(TOPDIR)" LINKLIBS="$(NUTTXLIBS)" USERLIBS="$(USERLIBS)" "$(CONFIG_PASS1_TARGET)"
-endif
-
-pass2deps: context pass2dep $(NUTTXLIBS)
-
-pass2: pass2deps
- @$(MAKE) -C $(ARCH_SRC) TOPDIR="$(TOPDIR)" EXTRA_OBJS="$(EXTRA_OBJS)" LINKLIBS="$(NUTTXLIBS)" EXTRADEFINES=$(KDEFINE) $(BIN)
- @if [ -w /tftpboot ] ; then \
- cp -f $(BIN) /tftpboot/$(BIN).${CONFIG_ARCH}; \
- fi
-ifeq ($(CONFIG_RRLOAD_BINARY),y)
- @echo "MK: $(BIN).rr"
- @$(TOPDIR)/tools/mkimage.sh --Prefix $(CROSSDEV) $(BIN) $(BIN).rr
- @if [ -w /tftpboot ] ; then \
- cp -f $(BIN).rr /tftpboot/$\(BIN).rr.$(CONFIG_ARCH); \
- fi
-endif
-ifeq ($(CONFIG_INTELHEX_BINARY),y)
- @echo "CP: $(BIN).hex"
- @$(OBJCOPY) $(OBJCOPYARGS) -O ihex $(BIN) $(BIN).hex
-endif
-ifeq ($(CONFIG_MOTOROLA_SREC),y)
- @echo "CP: $(BIN).srec"
- @$(OBJCOPY) $(OBJCOPYARGS) -O srec $(BIN) $(BIN).srec
-endif
-ifeq ($(CONFIG_RAW_BINARY),y)
- @echo "CP: $(BIN).bin"
- @$(OBJCOPY) $(OBJCOPYARGS) -O binary $(BIN) $(BIN).bin
-endif
-
-# $(BIN)
-#
-# Create the final NuttX executable in a two pass build process. In the
-# normal case, all pass1 and pass2 dependencies are created then pass1
-# and pass2 targets are built. However, in some cases, you may need to build
-# pass1 depenencies and pass1 first, then build pass2 dependencies and pass2.
-# in that case, execute 'make pass1 pass2' from the command line.
-
-$(BIN): pass1deps pass2deps pass1 pass2
-
-# download
-#
-# This is a helper target that will rebuild NuttX and download it to the target
-# system in one step. The operation of this target depends completely upon
-# implementation of the DOWNLOAD command in the user Make.defs file. It will
-# generate an error an error if the DOWNLOAD command is not defined.
-
-download: $(BIN)
- $(call DOWNLOAD, $<)
-
-# pass1dep: Create pass1 build dependencies
-# pass2dep: Create pass2 build dependencies
-
-pass1dep: context
- @for dir in $(USERDEPDIRS) ; do \
- $(MAKE) -C $$dir TOPDIR="$(TOPDIR)" depend ; \
- done
-
-pass2dep: context
- @for dir in $(KERNDEPDIRS) ; do \
- $(MAKE) -C $$dir TOPDIR="$(TOPDIR)" EXTRADEFINES=$(KDEFINE) depend; \
- done
-
-# Configuration targets
-#
-# These targets depend on the kconfig-frontends packages. To use these, you
-# must first download and install the kconfig-frontends package from this
-# location: http://ymorin.is-a-geek.org/projects/kconfig-frontends. See
-# misc/tools/README.txt for additional information.
-
-config:
- @APPSDIR=${CONFIG_APPS_DIR} conf Kconfig
-
-oldconfig:
- @APPSDIR=${CONFIG_APPS_DIR} conf --oldconfig Kconfig
-
-menuconfig:
- @APPSDIR=${CONFIG_APPS_DIR} mconf Kconfig
-
-# export
-#
-# The export target will package the NuttX libraries and header files into
-# an exportable package. Caveats: (1) These needs some extension for the KERNEL
-# build; it needs to receive USERLIBS and create a libuser.a). (2) The logic
-# in tools/mkexport.sh only supports GCC and, for example, explicitly assumes
-# that the archiver is 'ar'
-
-export: pass2deps
- @tools/mkexport.sh -w$(WINTOOL) -t "$(TOPDIR)" -l "$(NUTTXLIBS)"
-
-# General housekeeping targets: dependencies, cleaning, etc.
-#
-# depend: Create both PASS1 and PASS2 dependencies
-# clean: Removes derived object files, archives, executables, and
-# temporary files, but retains the configuration and context
-# files and directories.
-# distclean: Does 'clean' then also removes all configuration and context
-# files. This essentially restores the directory structure
-# to its original, unconfigured stated.
-
-depend: pass1dep pass2dep
-
-subdir_clean:
- @for dir in $(CLEANDIRS) ; do \
- if [ -e $$dir/Makefile ]; then \
- $(MAKE) -C $$dir TOPDIR="$(TOPDIR)" clean ; \
- fi \
- done
- @$(MAKE) -C tools -f Makefile.host TOPDIR="$(TOPDIR)" clean
- @$(MAKE) -C mm -f Makefile.test TOPDIR="$(TOPDIR)" clean
-ifeq ($(CONFIG_BUILD_2PASS),y)
- @$(MAKE) -C $(CONFIG_PASS1_BUILDIR) TOPDIR="$(TOPDIR)" clean
-endif
-
-clean: subdir_clean
- @rm -f $(BIN) nuttx.* mm_test *.map _SAVED_APPS_config *~
- @rm -f nuttx-export*
-
-subdir_distclean:
- @for dir in $(CLEANDIRS) ; do \
- if [ -e $$dir/Makefile ]; then \
- $(MAKE) -C $$dir TOPDIR="$(TOPDIR)" distclean ; \
- fi \
- done
-
-distclean: clean subdir_distclean clean_context
-ifeq ($(CONFIG_BUILD_2PASS),y)
- @$(MAKE) -C $(CONFIG_PASS1_BUILDIR) TOPDIR="$(TOPDIR)" distclean
-endif
- @rm -f Make.defs setenv.sh .config .config.old
-
-# Application housekeeping targets. The APPDIR variable refers to the user
-# application directory. A sample apps/ directory is included with NuttX,
-# however, this is not treated as part of NuttX and may be replaced with a
-# different application directory. For the most part, the application
-# directory is treated like any other build directory in this script. However,
-# as a convenience, the following targets are included to support housekeeping
-# functions in the user application directory from the NuttX build directory.
-#
-# apps_clean: Perform the clean operation only in the user application
-# directory
-# apps_distclean: Perform the distclean operation only in the user application
-# directory. Note that the apps/.config file (inf any) is
-# preserved so that this is not a "full" distclean but more of a
-# configuration "reset." (There willnot be an apps/.config
-# file if the configuration was generated via make menuconfig).
-
-apps_clean:
-ifneq ($(APPDIR),)
- @$(MAKE) -C "$(TOPDIR)/$(APPDIR)" TOPDIR="$(TOPDIR)" clean
-endif
-
-apps_distclean:
-ifneq ($(APPDIR),)
- @if [ -r "$(TOPDIR)/$(APPDIR)/.config" ]; then \
- cp "$(TOPDIR)/$(APPDIR)/.config" _SAVED_APPS_config || \
- { echo "Copy of $(APPDIR)/.config failed" ; exit 1 ; } \
- else \
- rm -f _SAVED_APPS_config; \
- fi
- @$(MAKE) -C "$(TOPDIR)/$(APPDIR)" TOPDIR="$(TOPDIR)" distclean
- @if [ -r _SAVED_APPS_config ]; then \
- @mv _SAVED_APPS_config "$(TOPDIR)/$(APPDIR)/.config" || \
- { echo "Copy of _SAVED_APPS_config failed" ; exit 1 ; } \
- fi
-endif
-
diff --git a/nuttx/Makefile.unix b/nuttx/Makefile.unix
new file mode 100644
index 000000000..d66c06bd8
--- /dev/null
+++ b/nuttx/Makefile.unix
@@ -0,0 +1,749 @@
+############################################################################
+# Makefile.unix
+#
+# Copyright (C) 2007-2012 Gregory Nutt. All rights reserved.
+# Author: Gregory Nutt <gnutt@nuttx.org>
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in
+# the documentation and/or other materials provided with the
+# distribution.
+# 3. Neither the name NuttX nor the names of its contributors may be
+# used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+############################################################################
+
+TOPDIR := ${shell pwd | sed -e 's/ /\\ /g'}
+-include $(TOPDIR)/.config
+include $(TOPDIR)/tools/Config.mk
+-include $(TOPDIR)/Make.defs
+
+# Control build verbosity
+
+ifeq ($(V),1)
+export Q :=
+else
+export Q := @
+endif
+
+# Default tools
+
+ifeq ($(DIRLINK),)
+DIRLINK = $(TOPDIR)/tools/link.sh
+DIRUNLINK = $(TOPDIR)/tools/unlink.sh
+endif
+
+# This define is passed as EXTRADEFINES for kernel-mode builds. It is also passed
+# during PASS1 (but not PASS2) context and depend targets.
+
+KDEFINE = ${shell $(TOPDIR)/tools/define.sh "$(CC)" __KERNEL__}
+
+# Process architecture and board-specific directories
+
+ARCH_DIR = arch/$(CONFIG_ARCH)
+ARCH_SRC = $(ARCH_DIR)/src
+ARCH_INC = $(ARCH_DIR)/include
+BOARD_DIR = configs/$(CONFIG_ARCH_BOARD)
+
+# Add-on directories. These may or may not be in place in the
+# NuttX source tree (they must be specifically installed)
+#
+# CONFIG_APPS_DIR can be over-ridden from the command line or in the .config file.
+# The default value of CONFIG_APPS_DIR is ../apps. Ultimately, the application
+# will be built if APPDIR is defined. APPDIR will be defined if a directory containing
+# a Makefile is found at the path provided by CONFIG_APPS_DIR
+
+ifeq ($(CONFIG_APPS_DIR),)
+CONFIG_APPS_DIR = ../apps
+endif
+APPDIR := ${shell if [ -r $(CONFIG_APPS_DIR)/Makefile ]; then echo "$(CONFIG_APPS_DIR)"; fi}
+
+# All add-on directories.
+#
+# NUTTX_ADDONS is the list of directories built into the NuttX kernel.
+# USER_ADDONS is the list of directories that will be built into the user application
+
+NUTTX_ADDONS :=
+USER_ADDONS :=
+
+ifeq ($(CONFIG_NUTTX_KERNEL),y)
+USER_ADDONS += $(APPDIR)
+else
+NUTTX_ADDONS += $(APPDIR)
+endif
+
+# Lists of build directories.
+#
+# FSDIRS depend on file descriptor support; NONFSDIRS do not (except for parts
+# of FSDIRS). We will exclude FSDIRS from the build if file descriptor
+# support is disabled
+# CONTEXTDIRS include directories that have special, one-time pre-build
+# requirements. Normally this includes things like auto-generation of
+# configuration specific files or creation of configurable symbolic links
+# USERDIRS - When NuttX is build is a monolithic kernel, this provides the
+# list of directories that must be built
+# OTHERDIRS - These are directories that are not built but probably should
+# be cleaned to prevent garbarge from collecting in them when changing
+# configurations.
+
+NONFSDIRS = sched $(ARCH_SRC) $(NUTTX_ADDONS)
+FSDIRS = fs drivers binfmt
+CONTEXTDIRS = $(APPDIR)
+USERDIRS =
+OTHERDIRS = lib
+
+ifeq ($(CONFIG_NUTTX_KERNEL),y)
+
+NONFSDIRS += syscall
+CONTEXTDIRS += syscall
+USERDIRS += syscall libc mm $(USER_ADDONS)
+ifeq ($(CONFIG_HAVE_CXX),y)
+USERDIRS += libxx
+endif
+
+else
+
+NONFSDIRS += libc mm
+OTHERDIRS += syscall $(USER_ADDONS)
+ifeq ($(CONFIG_HAVE_CXX),y)
+NONFSDIRS += libxx
+else
+OTHERDIRS += libxx
+endif
+
+endif
+
+ifeq ($(CONFIG_NX),y)
+NONFSDIRS += graphics
+CONTEXTDIRS += graphics
+else
+OTHERDIRS += graphics
+endif
+
+# CLEANDIRS are the directories that will clean in. These are
+# all directories that we know about.
+# KERNDEPDIRS are the directories in which we will build target dependencies.
+# If NuttX and applications are built separately (CONFIG_NUTTX_KERNEL),
+# then this holds only the directories containing kernel files.
+# USERDEPDIRS. If NuttX and applications are built separately (CONFIG_NUTTX_KERNEL),
+# then this holds only the directories containing user files.
+
+CLEANDIRS = $(NONFSDIRS) $(FSDIRS) $(USERDIRS) $(OTHERDIRS)
+KERNDEPDIRS = $(NONFSDIRS)
+USERDEPDIRS = $(USERDIRS)
+
+# Add file system directories to KERNDEPDIRS (they are already in CLEANDIRS)
+
+ifeq ($(CONFIG_NFILE_DESCRIPTORS),0)
+ifeq ($(CONFIG_NET),y)
+ifneq ($(CONFIG_NSOCKET_DESCRIPTORS),0)
+KERNDEPDIRS += fs
+endif
+KERNDEPDIRS += drivers
+endif
+else
+KERNDEPDIRS += $(FSDIRS)
+endif
+
+# Add networking directories to KERNDEPDIRS and CLEANDIRS
+
+ifeq ($(CONFIG_NET),y)
+KERNDEPDIRS += net
+endif
+CLEANDIRS += net
+
+#
+# Extra objects used in the final link.
+#
+# Pass 1 1ncremental (relative) link objects should be put into the
+# processor-specific source directory (where other link objects will
+# be created). If the pass1 obect is an archive, it could go anywhere.
+
+ifeq ($(CONFIG_BUILD_2PASS),y)
+EXTRA_OBJS += $(CONFIG_PASS1_OBJECT)
+endif
+
+# NUTTXLIBS is the list of NuttX libraries that is passed to the
+# processor-specific Makefile to build the final NuttX target.
+# Libraries in FSDIRS are excluded if file descriptor support
+# is disabled.
+# USERLIBS is the list of libraries used to build the final user-space
+# application
+
+NUTTXLIBS = lib/libsched$(LIBEXT) lib/libarch$(LIBEXT)
+USERLIBS =
+
+# Add libraries for syscall support. The C library will be needed by
+# both the kernel- and user-space builds. For now, the memory manager (mm)
+# is placed in user space (only).
+
+ifeq ($(CONFIG_NUTTX_KERNEL),y)
+NUTTXLIBS += lib/libstubs$(LIBEXT) lib/libkc$(LIBEXT)
+USERLIBS += lib/libproxies$(LIBEXT) lib/libuc$(LIBEXT) lib/libmm$(LIBEXT)
+else
+NUTTXLIBS += lib/libmm$(LIBEXT) lib/libc$(LIBEXT)
+endif
+
+# Add libraries for C++ support. CXX, CXXFLAGS, and COMPILEXX must
+# be defined in Make.defs for this to work!
+
+ifeq ($(CONFIG_HAVE_CXX),y)
+ifeq ($(CONFIG_NUTTX_KERNEL),y)
+USERLIBS += lib/libcxx$(LIBEXT)
+else
+NUTTXLIBS += lib/libcxx$(LIBEXT)
+endif
+endif
+
+# Add library for application support.
+
+ifneq ($(APPDIR),)
+ifeq ($(CONFIG_NUTTX_KERNEL),y)
+USERLIBS += lib/libapps$(LIBEXT)
+else
+NUTTXLIBS += lib/libapps$(LIBEXT)
+endif
+endif
+
+# Add libraries for network support
+
+ifeq ($(CONFIG_NET),y)
+NUTTXLIBS += lib/libnet$(LIBEXT)
+endif
+
+# Add libraries for file system support
+
+ifeq ($(CONFIG_NFILE_DESCRIPTORS),0)
+ifneq ($(CONFIG_NSOCKET_DESCRIPTORS),0)
+NUTTXLIBS += lib/libfs$(LIBEXT)
+endif
+ifeq ($(CONFIG_NET),y)
+NUTTXLIBS += lib/libdrivers$(LIBEXT)
+endif
+else
+NUTTXLIBS += lib/libfs$(LIBEXT) lib/libdrivers$(LIBEXT) lib/libbinfmt$(LIBEXT)
+endif
+
+# Add libraries for the NX graphics sub-system
+
+ifeq ($(CONFIG_NX),y)
+NUTTXLIBS += lib/libgraphics$(LIBEXT)
+endif
+
+# LINKLIBS derives from NUTTXLIBS and is simply the same list with the subdirectory removed
+
+LINKLIBS = $(patsubst lib/%,%,$(NUTTXLIBS))
+
+# This is the name of the final target (relative to the top level directorty)
+
+BIN = nuttx$(EXEEXT)
+
+all: $(BIN)
+.PHONY: context clean_context check_context export subdir_clean clean subdir_distclean distclean apps_clean apps_distclean
+
+# Target used to copy include/nuttx/math.h. If CONFIG_ARCH_MATH_H is
+# defined, then there is an architecture specific math.h header file
+# that will be included indirectly from include/math.h. But first, we
+# have to copy math.h from include/nuttx/. to include/. Logic within
+# include/nuttx/math.h will hand the redirection to the architecture-
+# specific math.h header file.
+#
+# If the CONFIG_LIBM is defined, the Rhombus libm will be built at libc/math.
+# Definitions and prototypes for the Rhombus libm are also contained in
+# include/nuttx/math.h and so the file must also be copied in that case.
+#
+# If neither CONFIG_ARCH_MATH_H nor CONFIG_LIBM is defined, then no math.h
+# header file will be provided. You would want that behavior if (1) you
+# don't use libm, or (2) you want to use the math.h and libm provided
+# within your toolchain.
+
+ifeq ($(CONFIG_ARCH_MATH_H),y)
+NEED_MATH_H = y
+else
+ifeq ($(CONFIG_LIBM),y)
+NEED_MATH_H = y
+endif
+endif
+
+ifeq ($(NEED_MATH_H),y)
+include/math.h: include/nuttx/math.h
+ $(Q) cp -f include/nuttx/math.h include/math.h
+else
+include/math.h:
+endif
+
+# The float.h header file defines the properties of your floating point
+# implementation. It would always be best to use your toolchain's float.h
+# header file but if none is avaiable, a default float.h header file will
+# provided if this option is selected. However there is no assurance that
+# the settings in this float.h are actually correct for your platform!
+
+ifeq ($(CONFIG_ARCH_FLOAT_H),y)
+include/float.h: include/nuttx/float.h
+ $(Q) cp -f include/nuttx/float.h include/float.h
+else
+include/float.h:
+endif
+
+# Target used to copy include/nuttx/stdarg.h. If CONFIG_ARCH_STDARG_H is
+# defined, then there is an architecture specific stdarg.h header file
+# that will be included indirectly from include/stdarg.h. But first, we
+# have to copy stdarg.h from include/nuttx/. to include/.
+
+ifeq ($(CONFIG_ARCH_STDARG_H),y)
+include/stdarg.h: include/nuttx/stdarg.h
+ $(Q) cp -f include/nuttx/stdarg.h include/stdarg.h
+else
+include/stdarg.h:
+endif
+
+# Targets used to build include/nuttx/version.h. Creation of version.h is
+# part of the overall NuttX configuration sequence. Notice that the
+# tools/mkversion tool is built and used to create include/nuttx/version.h
+
+tools/mkversion$(HOSTEXEEXT):
+ $(Q) $(MAKE) -C tools -f Makefile.host TOPDIR="$(TOPDIR)" mkversion$(HOSTEXEEXT)
+
+$(TOPDIR)/.version:
+ $(Q) if [ ! -f .version ]; then \
+ echo "No .version file found, creating one"; \
+ tools/version.sh -v 0.0 -b 0 .version; \
+ chmod 755 .version; \
+ fi
+
+include/nuttx/version.h: $(TOPDIR)/.version tools/mkversion$(HOSTEXEEXT)
+ $(Q) tools/mkversion $(TOPDIR) > include/nuttx/version.h
+
+# Targets used to build include/nuttx/config.h. Creation of config.h is
+# part of the overall NuttX configuration sequence. Notice that the
+# tools/mkconfig tool is built and used to create include/nuttx/config.h
+
+tools/mkconfig$(HOSTEXEEXT):
+ $(Q) $(MAKE) -C tools -f Makefile.host TOPDIR="$(TOPDIR)" mkconfig$(HOSTEXEEXT)
+
+include/nuttx/config.h: $(TOPDIR)/.config tools/mkconfig$(HOSTEXEEXT)
+ $(Q) tools/mkconfig $(TOPDIR) > include/nuttx/config.h
+
+# Targets used to create dependencies
+
+tools/mkdeps$(HOSTEXEEXT):
+ $(Q) $(MAKE) -C tools -f Makefile.host TOPDIR="$(TOPDIR)" mkdeps$(HOSTEXEEXT)
+
+# dirlinks, and helpers
+#
+# Directories links. Most of establishing the NuttX configuration involves
+# setting up symbolic links with 'generic' directory names to specific,
+# configured directories.
+#
+# Link the apps/include directory to include/apps
+
+include/apps: Make.defs
+ifneq ($(APPDIR),)
+ @echo "LN: include/apps to $(APPDIR)/include"
+ $(Q) if [ -d $(TOPDIR)/$(APPDIR)/include ]; then \
+ $(DIRLINK) $(TOPDIR)/$(APPDIR)/include include/apps; \
+ fi
+endif
+
+# Link the arch/<arch-name>/include directory to include/arch
+
+include/arch: Make.defs
+ @echo "LN: include/arch to $(ARCH_DIR)/include"
+ $(Q) $(DIRLINK) $(TOPDIR)/$(ARCH_DIR)/include include/arch
+
+# Link the configs/<board-name>/include directory to include/arch/board
+
+include/arch/board: include/arch Make.defs include/arch
+ @echo "LN: include/arch/board to $(BOARD_DIR)/include"
+ $(Q) $(DIRLINK) $(TOPDIR)/$(BOARD_DIR)/include include/arch/board
+
+# Link the configs/<board-name>/src dir to arch/<arch-name>/src/board
+
+$(ARCH_SRC)/board: Make.defs
+ @echo "LN: $(ARCH_SRC)/board to $(BOARD_DIR)/src"
+ $(Q) $(DIRLINK) $(TOPDIR)/$(BOARD_DIR)/src $(ARCH_SRC)/board
+
+# Link arch/<arch-name>/include/<chip-name> to arch/<arch-name>/include/chip
+
+$(ARCH_SRC)/chip: Make.defs
+ifneq ($(CONFIG_ARCH_CHIP),)
+ @echo "LN: $(ARCH_SRC)/chip to $(ARCH_SRC)/$(CONFIG_ARCH_CHIP)"
+ $(Q) $(DIRLINK) $(TOPDIR)/$(ARCH_SRC)/$(CONFIG_ARCH_CHIP) $(ARCH_SRC)/chip
+endif
+
+# Link arch/<arch-name>/src/<chip-name> to arch/<arch-name>/src/chip
+
+include/arch/chip: include/arch Make.defs
+ifneq ($(CONFIG_ARCH_CHIP),)
+ @echo "LN: include/arch/chip to $(ARCH_INC)/$(CONFIG_ARCH_CHIP)"
+ $(Q) $(DIRLINK) $(TOPDIR)/$(ARCH_INC)/$(CONFIG_ARCH_CHIP) include/arch/chip
+endif
+
+dirlinks: include/arch include/arch/board include/arch/chip $(ARCH_SRC)/board $(ARCH_SRC)/chip include/apps
+
+# context
+#
+# The context target is invoked on each target build to assure that NuttX is
+# properly configured. The basic configuration steps include creation of the
+# the config.h and version.h header files in the include/nuttx directory and
+# the establishment of symbolic links to configured directories.
+
+context: check_context include/nuttx/config.h include/nuttx/version.h include/math.h include/float.h include/stdarg.h dirlinks
+ $(Q) for dir in $(CONTEXTDIRS) ; do \
+ $(MAKE) -C $$dir TOPDIR="$(TOPDIR)" context; \
+ done
+
+# clean_context
+#
+# This is part of the distclean target. It removes all of the header files
+# and symbolic links created by the context target.
+
+clean_context:
+ $(call DELFILE, include/nuttx/config.h)
+ $(call DELFILE, include/nuttx/version.h)
+ $(call DELFILE, include/math.h)
+ $(call DELFILE, include/stdarg.h)
+ $(Q) $(DIRUNLINK) include/arch/board
+ $(Q) $(DIRUNLINK) include/arch/chip
+ $(Q) $(DIRUNLINK) include/arch
+ $(Q) $(DIRUNLINK) $(ARCH_SRC)/board
+ $(Q) $(DIRUNLINK) $(ARCH_SRC)/chip
+ $(Q) $(DIRUNLINK) include/apps
+
+# check_context
+#
+# This target checks if NuttX has been configured. NuttX is configured using
+# the script tools/configure.sh. That script will install certain files in
+# the top-level NuttX build directory. This target verifies that those
+# configuration files have been installed and that NuttX is ready to be built.
+
+check_context:
+ $(Q) if [ ! -e ${TOPDIR}/.config -o ! -e ${TOPDIR}/Make.defs ]; then \
+ echo "" ; echo "Nuttx has not been configured:" ; \
+ echo " cd tools; ./configure.sh <target>" ; echo "" ; \
+ exit 1 ; \
+ fi
+
+# Archive targets. The target build sequency will first create a series of
+# libraries, one per configured source file directory. The final NuttX
+# execution will then be built from those libraries. The following targets
+# build those libraries.
+#
+# Possible kernel-mode builds
+
+libc/libkc$(LIBEXT): context
+ $(Q) $(MAKE) -C libc TOPDIR="$(TOPDIR)" libkc$(LIBEXT) EXTRADEFINES=$(KDEFINE)
+
+lib/libkc$(LIBEXT): libc/libkc$(LIBEXT)
+ $(Q) install libc/libkc$(LIBEXT) lib/libkc$(LIBEXT)
+
+sched/libsched$(LIBEXT): context
+ $(Q) $(MAKE) -C sched TOPDIR="$(TOPDIR)" libsched$(LIBEXT) EXTRADEFINES=$(KDEFINE)
+
+lib/libsched$(LIBEXT): sched/libsched$(LIBEXT)
+ $(Q) install sched/libsched$(LIBEXT) lib/libsched$(LIBEXT)
+
+$(ARCH_SRC)/libarch$(LIBEXT): context
+ $(Q) $(MAKE) -C $(ARCH_SRC) TOPDIR="$(TOPDIR)" libarch$(LIBEXT) EXTRADEFINES=$(KDEFINE)
+
+lib/libarch$(LIBEXT): $(ARCH_SRC)/libarch$(LIBEXT)
+ $(Q) install $(ARCH_SRC)/libarch$(LIBEXT) lib/libarch$(LIBEXT)
+
+net/libnet$(LIBEXT): context
+ $(Q) $(MAKE) -C net TOPDIR="$(TOPDIR)" libnet$(LIBEXT) EXTRADEFINES=$(KDEFINE)
+
+lib/libnet$(LIBEXT): net/libnet$(LIBEXT)
+ $(Q) install net/libnet$(LIBEXT) lib/libnet$(LIBEXT)
+
+fs/libfs$(LIBEXT): context
+ $(Q) $(MAKE) -C fs TOPDIR="$(TOPDIR)" libfs$(LIBEXT) EXTRADEFINES=$(KDEFINE)
+
+lib/libfs$(LIBEXT): fs/libfs$(LIBEXT)
+ $(Q) install fs/libfs$(LIBEXT) lib/libfs$(LIBEXT)
+
+drivers/libdrivers$(LIBEXT): context
+ $(Q) $(MAKE) -C drivers TOPDIR="$(TOPDIR)" libdrivers$(LIBEXT) EXTRADEFINES=$(KDEFINE)
+
+lib/libdrivers$(LIBEXT): drivers/libdrivers$(LIBEXT)
+ $(Q) install drivers/libdrivers$(LIBEXT) lib/libdrivers$(LIBEXT)
+
+binfmt/libbinfmt$(LIBEXT): context
+ $(Q) $(MAKE) -C binfmt TOPDIR="$(TOPDIR)" libbinfmt$(LIBEXT) EXTRADEFINES=$(KDEFINE)
+
+lib/libbinfmt$(LIBEXT): binfmt/libbinfmt$(LIBEXT)
+ $(Q) install binfmt/libbinfmt$(LIBEXT) lib/libbinfmt$(LIBEXT)
+
+graphics/libgraphics$(LIBEXT): context
+ $(Q) $(MAKE) -C graphics TOPDIR="$(TOPDIR)" libgraphics$(LIBEXT) EXTRADEFINES=$(KDEFINE)
+
+lib/libgraphics$(LIBEXT): graphics/libgraphics$(LIBEXT)
+ $(Q) install graphics/libgraphics$(LIBEXT) lib/libgraphics$(LIBEXT)
+
+syscall/libstubs$(LIBEXT): context
+ $(Q) $(MAKE) -C syscall TOPDIR="$(TOPDIR)" libstubs$(LIBEXT) EXTRADEFINES=$(KDEFINE)
+
+lib/libstubs$(LIBEXT): syscall/libstubs$(LIBEXT)
+ $(Q) install syscall/libstubs$(LIBEXT) lib/libstubs$(LIBEXT)
+
+# Possible user-mode builds
+
+libc/libuc$(LIBEXT): context
+ $(Q) $(MAKE) -C libc TOPDIR="$(TOPDIR)" libuc$(LIBEXT)
+
+lib/libuc$(LIBEXT): libc/libuc$(LIBEXT)
+ $(Q) install libc/libuc$(LIBEXT) lib/libuc$(LIBEXT)
+
+libxx/libcxx$(LIBEXT): context
+ $(Q) $(MAKE) -C libxx TOPDIR="$(TOPDIR)" libcxx$(LIBEXT)
+
+lib/libcxx$(LIBEXT): libxx/libcxx$(LIBEXT)
+ $(Q) install libxx/libcxx$(LIBEXT) lib/libcxx$(LIBEXT)
+
+mm/libmm$(LIBEXT): context
+ $(Q) $(MAKE) -C mm TOPDIR="$(TOPDIR)" libmm$(LIBEXT) EXTRADEFINES=$(KDEFINE)
+
+lib/libmm$(LIBEXT): mm/libmm$(LIBEXT)
+ $(Q) install mm/libmm$(LIBEXT) lib/libmm$(LIBEXT)
+
+$(APPDIR)/libapps$(LIBEXT): context
+ $(Q) $(MAKE) -C $(APPDIR) TOPDIR="$(TOPDIR)" libapps$(LIBEXT)
+
+lib/libapps$(LIBEXT): $(APPDIR)/libapps$(LIBEXT)
+ $(Q) install $(APPDIR)/libapps$(LIBEXT) lib/libapps$(LIBEXT)
+
+syscall/libproxies$(LIBEXT): context
+ $(Q) $(MAKE) -C syscall TOPDIR="$(TOPDIR)" libproxies$(LIBEXT)
+
+lib/libproxies$(LIBEXT): syscall/libproxies$(LIBEXT)
+ $(Q) install syscall/libproxies$(LIBEXT) lib/libproxies$(LIBEXT)
+
+# Possible non-kernel builds
+
+libc/libc$(LIBEXT): context
+ $(Q) $(MAKE) -C libc TOPDIR="$(TOPDIR)" libc$(LIBEXT)
+
+lib/libc$(LIBEXT): libc/libc$(LIBEXT)
+ $(Q) install libc/libc$(LIBEXT) lib/libc$(LIBEXT)
+
+# pass1 and pass2
+#
+# If the 2 pass build option is selected, then this pass1 target is
+# configured to built before the pass2 target. This pass1 target may, as an
+# example, build an extra link object (CONFIG_PASS1_OBJECT) which may be an
+# incremental (relative) link object, but could be a static library (archive);
+# some modification to this Makefile would be required if CONFIG_PASS1_OBJECT
+# is an archive. Exactly what is performed during pass1 or what it generates
+# is unknown to this makefule unless CONFIG_PASS1_OBJECT is defined.
+
+pass1deps: pass1dep $(USERLIBS)
+
+pass1: pass1deps
+ifeq ($(CONFIG_BUILD_2PASS),y)
+ $(Q) if [ -z "$(CONFIG_PASS1_BUILDIR)" ]; then \
+ echo "ERROR: CONFIG_PASS1_BUILDIR not defined"; \
+ exit 1; \
+ fi
+ $(Q) if [ ! -d "$(CONFIG_PASS1_BUILDIR)" ]; then \
+ echo "ERROR: CONFIG_PASS1_BUILDIR does not exist"; \
+ exit 1; \
+ fi
+ $(Q) if [ ! -f "$(CONFIG_PASS1_BUILDIR)/Makefile" ]; then \
+ echo "ERROR: No Makefile in CONFIG_PASS1_BUILDIR"; \
+ exit 1; \
+ fi
+ $(Q) $(MAKE) -C $(CONFIG_PASS1_BUILDIR) TOPDIR="$(TOPDIR)" LINKLIBS="$(LINKLIBS)" USERLIBS="$(USERLIBS)" "$(CONFIG_PASS1_TARGET)"
+endif
+
+pass2deps: pass2dep $(NUTTXLIBS)
+
+pass2: pass2deps
+ $(Q) $(MAKE) -C $(ARCH_SRC) TOPDIR="$(TOPDIR)" EXTRA_OBJS="$(EXTRA_OBJS)" LINKLIBS="$(LINKLIBS)" EXTRADEFINES=$(KDEFINE) $(BIN)
+ $(Q) if [ -w /tftpboot ] ; then \
+ cp -f $(BIN) /tftpboot/$(BIN).${CONFIG_ARCH}; \
+ fi
+ifeq ($(CONFIG_RRLOAD_BINARY),y)
+ @echo "MK: $(BIN).rr"
+ $(Q) $(TOPDIR)/tools/mkimage.sh --Prefix $(CROSSDEV) $(BIN) $(BIN).rr
+ $(Q) if [ -w /tftpboot ] ; then \
+ cp -f $(BIN).rr /tftpboot/$\(BIN).rr.$(CONFIG_ARCH); \
+ fi
+endif
+ifeq ($(CONFIG_INTELHEX_BINARY),y)
+ @echo "CP: $(BIN).hex"
+ $(Q) $(OBJCOPY) $(OBJCOPYARGS) -O ihex $(BIN) $(BIN).hex
+endif
+ifeq ($(CONFIG_MOTOROLA_SREC),y)
+ @echo "CP: $(BIN).srec"
+ $(Q) $(OBJCOPY) $(OBJCOPYARGS) -O srec $(BIN) $(BIN).srec
+endif
+ifeq ($(CONFIG_RAW_BINARY),y)
+ @echo "CP: $(BIN).bin"
+ $(Q) $(OBJCOPY) $(OBJCOPYARGS) -O binary $(BIN) $(BIN).bin
+endif
+
+# $(BIN)
+#
+# Create the final NuttX executable in a two pass build process. In the
+# normal case, all pass1 and pass2 dependencies are created then pass1
+# and pass2 targets are built. However, in some cases, you may need to build
+# pass1 depenencies and pass1 first, then build pass2 dependencies and pass2.
+# in that case, execute 'make pass1 pass2' from the command line.
+
+$(BIN): pass1deps pass2deps pass1 pass2
+
+# download
+#
+# This is a helper target that will rebuild NuttX and download it to the target
+# system in one step. The operation of this target depends completely upon
+# implementation of the DOWNLOAD command in the user Make.defs file. It will
+# generate an error an error if the DOWNLOAD command is not defined.
+
+download: $(BIN)
+ $(call DOWNLOAD, $<)
+
+# pass1dep: Create pass1 build dependencies
+# pass2dep: Create pass2 build dependencies
+
+pass1dep: context tools/mkdeps$(HOSTEXEEXT)
+ $(Q) for dir in $(USERDEPDIRS) ; do \
+ $(MAKE) -C $$dir TOPDIR="$(TOPDIR)" depend ; \
+ done
+
+pass2dep: context tools/mkdeps$(HOSTEXEEXT)
+ $(Q) for dir in $(KERNDEPDIRS) ; do \
+ $(MAKE) -C $$dir TOPDIR="$(TOPDIR)" EXTRADEFINES=$(KDEFINE) depend; \
+ done
+
+# Configuration targets
+#
+# These targets depend on the kconfig-frontends packages. To use these, you
+# must first download and install the kconfig-frontends package from this
+# location: http://ymorin.is-a-geek.org/projects/kconfig-frontends. See
+# misc/tools/README.txt for additional information.
+
+config:
+ $(Q) APPSDIR=${CONFIG_APPS_DIR} conf Kconfig
+
+oldconfig:
+ $(Q) APPSDIR=${CONFIG_APPS_DIR} conf --oldconfig Kconfig
+
+menuconfig:
+ $(Q) APPSDIR=${CONFIG_APPS_DIR} mconf Kconfig
+
+# export
+#
+# The export target will package the NuttX libraries and header files into
+# an exportable package. Caveats: (1) These needs some extension for the KERNEL
+# build; it needs to receive USERLIBS and create a libuser.a). (2) The logic
+# in tools/mkexport.sh only supports GCC and, for example, explicitly assumes
+# that the archiver is 'ar'
+
+export: pass2deps
+ $(Q) tools/mkexport.sh -w$(WINTOOL) -t "$(TOPDIR)" -l "$(NUTTXLIBS)"
+
+# General housekeeping targets: dependencies, cleaning, etc.
+#
+# depend: Create both PASS1 and PASS2 dependencies
+# clean: Removes derived object files, archives, executables, and
+# temporary files, but retains the configuration and context
+# files and directories.
+# distclean: Does 'clean' then also removes all configuration and context
+# files. This essentially restores the directory structure
+# to its original, unconfigured stated.
+
+depend: pass1dep pass2dep
+
+subdir_clean:
+ $(Q) for dir in $(CLEANDIRS) ; do \
+ if [ -e $$dir/Makefile ]; then \
+ $(MAKE) -C $$dir TOPDIR="$(TOPDIR)" clean ; \
+ fi \
+ done
+ $(Q) $(MAKE) -C tools -f Makefile.host TOPDIR="$(TOPDIR)" clean
+ $(Q) $(MAKE) -C mm -f Makefile.test TOPDIR="$(TOPDIR)" clean
+ifeq ($(CONFIG_BUILD_2PASS),y)
+ $(Q) $(MAKE) -C $(CONFIG_PASS1_BUILDIR) TOPDIR="$(TOPDIR)" clean
+endif
+
+clean: subdir_clean
+ $(call DELFILE, $(BIN))
+ $(call DELFILE, nuttx.*)
+ $(call DELFILE, mm_test)
+ $(call DELFILE, *.map)
+ $(call DELFILE, _SAVED_APPS_config)
+ $(call DELFILE, nuttx-export*)
+ $(call CLEAN)
+
+subdir_distclean:
+ $(Q) for dir in $(CLEANDIRS) ; do \
+ if [ -e $$dir/Makefile ]; then \
+ $(MAKE) -C $$dir TOPDIR="$(TOPDIR)" distclean ; \
+ fi \
+ done
+
+distclean: clean subdir_distclean clean_context
+ifeq ($(CONFIG_BUILD_2PASS),y)
+ $(Q) $(MAKE) -C $(CONFIG_PASS1_BUILDIR) TOPDIR="$(TOPDIR)" distclean
+endif
+ $(call DELFILE, Make.defs)
+ $(call DELFILE, setenv.sh)
+ $(call DELFILE, setenv.bat)
+ $(call DELFILE, .config)
+ $(call DELFILE, .config.old)
+
+# Application housekeeping targets. The APPDIR variable refers to the user
+# application directory. A sample apps/ directory is included with NuttX,
+# however, this is not treated as part of NuttX and may be replaced with a
+# different application directory. For the most part, the application
+# directory is treated like any other build directory in this script. However,
+# as a convenience, the following targets are included to support housekeeping
+# functions in the user application directory from the NuttX build directory.
+#
+# apps_clean: Perform the clean operation only in the user application
+# directory
+# apps_distclean: Perform the distclean operation only in the user application
+# directory. Note that the apps/.config file (inf any) is
+# preserved so that this is not a "full" distclean but more of a
+# configuration "reset." (There willnot be an apps/.config
+# file if the configuration was generated via make menuconfig).
+
+apps_clean:
+ifneq ($(APPDIR),)
+ $(Q) $(MAKE) -C "$(TOPDIR)/$(APPDIR)" TOPDIR="$(TOPDIR)" clean
+endif
+
+apps_distclean:
+ifneq ($(APPDIR),)
+ $(Q) if [ -r "$(TOPDIR)/$(APPDIR)/.config" ]; then \
+ cp "$(TOPDIR)/$(APPDIR)/.config" _SAVED_APPS_config || \
+ { echo "Copy of $(APPDIR)/.config failed" ; exit 1 ; } \
+ else \
+ rm -f _SAVED_APPS_config; \
+ fi
+ $(Q) $(MAKE) -C "$(TOPDIR)/$(APPDIR)" TOPDIR="$(TOPDIR)" distclean
+ $(Q) if [ -r _SAVED_APPS_config ]; then \
+ mv _SAVED_APPS_config "$(TOPDIR)/$(APPDIR)/.config" || \
+ { echo "Copy of _SAVED_APPS_config failed" ; exit 1 ; } \
+ fi
+endif
+
diff --git a/nuttx/Makefile.win b/nuttx/Makefile.win
new file mode 100644
index 000000000..34da12ad0
--- /dev/null
+++ b/nuttx/Makefile.win
@@ -0,0 +1,740 @@
+############################################################################
+# Makefile.win
+#
+# Copyright (C) 2012 Gregory Nutt. All rights reserved.
+# Author: Gregory Nutt <gnutt@nuttx.org>
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in
+# the documentation and/or other materials provided with the
+# distribution.
+# 3. Neither the name NuttX nor the names of its contributors may be
+# used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+############################################################################
+
+TOPDIR := ${shell echo %CD%}
+-include $(TOPDIR)\.config
+-include $(TOPDIR)\tools\Config.mk
+-include $(TOPDIR)\Make.defs
+
+# Control build verbosity
+
+ifeq ($(V),1)
+export Q :=
+else
+export Q := @
+endif
+
+# This define is passed as EXTRADEFINES for kernel-mode builds. It is also passed
+# during PASS1 (but not PASS2) context and depend targets.
+
+KDEFINE = ${shell $(TOPDIR)\tools\define.bat "$(CC)" __KERNEL__}
+
+# Process architecture and board-specific directories
+
+ARCH_DIR = arch\$(CONFIG_ARCH)
+ARCH_SRC = $(ARCH_DIR)\src
+ARCH_INC = $(ARCH_DIR)\include
+BOARD_DIR = configs\$(CONFIG_ARCH_BOARD)
+
+# Add-on directories. These may or may not be in place in the
+# NuttX source tree (they must be specifically installed)
+#
+# CONFIG_APPS_DIR can be over-ridden from the command line or in the .config file.
+# The default value of CONFIG_APPS_DIR is ..\apps. Ultimately, the application
+# will be built if APPDIR is defined. APPDIR will be defined if a directory containing
+# a Makefile is found at the path provided by CONFIG_APPS_DIR
+
+ifeq ($(CONFIG_APPS_DIR),)
+CONFIG_APPS_DIR = ..\apps
+endif
+APPDIR := ${shell if exist "$(CONFIG_APPS_DIR)\Makefile" echo $(CONFIG_APPS_DIR)}
+
+# All add-on directories.
+#
+# NUTTX_ADDONS is the list of directories built into the NuttX kernel.
+# USER_ADDONS is the list of directories that will be built into the user application
+
+NUTTX_ADDONS :=
+USER_ADDONS :=
+
+ifeq ($(CONFIG_NUTTX_KERNEL),y)
+USER_ADDONS += $(APPDIR)
+else
+NUTTX_ADDONS += $(APPDIR)
+endif
+
+# Lists of build directories.
+#
+# FSDIRS depend on file descriptor support; NONFSDIRS do not (except for parts
+# of FSDIRS). We will exclude FSDIRS from the build if file descriptor
+# support is disabled
+# CONTEXTDIRS include directories that have special, one-time pre-build
+# requirements. Normally this includes things like auto-generation of
+# configuration specific files or creation of configurable symbolic links
+# USERDIRS - When NuttX is build is a monolithic kernel, this provides the
+# list of directories that must be built
+# OTHERDIRS - These are directories that are not built but probably should
+# be cleaned to prevent garbarge from collecting in them when changing
+# configurations.
+
+NONFSDIRS = sched $(ARCH_SRC) $(NUTTX_ADDONS)
+FSDIRS = fs drivers binfmt
+CONTEXTDIRS = $(APPDIR)
+USERDIRS =
+OTHERDIRS = lib
+
+ifeq ($(CONFIG_NUTTX_KERNEL),y)
+
+NONFSDIRS += syscall
+CONTEXTDIRS += syscall
+USERDIRS += syscall libc mm $(USER_ADDONS)
+ifeq ($(CONFIG_HAVE_CXX),y)
+USERDIRS += libxx
+endif
+
+else
+
+NONFSDIRS += libc mm
+OTHERDIRS += syscall $(USER_ADDONS)
+ifeq ($(CONFIG_HAVE_CXX),y)
+NONFSDIRS += libxx
+else
+OTHERDIRS += libxx
+endif
+
+endif
+
+ifeq ($(CONFIG_NX),y)
+NONFSDIRS += graphics
+CONTEXTDIRS += graphics
+else
+OTHERDIRS += graphics
+endif
+
+# CLEANDIRS are the directories that will clean in. These are
+# all directories that we know about.
+# KERNDEPDIRS are the directories in which we will build target dependencies.
+# If NuttX and applications are built separately (CONFIG_NUTTX_KERNEL),
+# then this holds only the directories containing kernel files.
+# USERDEPDIRS. If NuttX and applications are built separately (CONFIG_NUTTX_KERNEL),
+# then this holds only the directories containing user files.
+
+CLEANDIRS = $(NONFSDIRS) $(FSDIRS) $(USERDIRS) $(OTHERDIRS)
+KERNDEPDIRS = $(NONFSDIRS)
+USERDEPDIRS = $(USERDIRS)
+
+# Add file system directories to KERNDEPDIRS (they are already in CLEANDIRS)
+
+ifeq ($(CONFIG_NFILE_DESCRIPTORS),0)
+ifeq ($(CONFIG_NET),y)
+ifneq ($(CONFIG_NSOCKET_DESCRIPTORS),0)
+KERNDEPDIRS += fs
+endif
+KERNDEPDIRS += drivers
+endif
+else
+KERNDEPDIRS += $(FSDIRS)
+endif
+
+# Add networking directories to KERNDEPDIRS and CLEANDIRS
+
+ifeq ($(CONFIG_NET),y)
+KERNDEPDIRS += net
+endif
+CLEANDIRS += net
+
+#
+# Extra objects used in the final link.
+#
+# Pass 1 1ncremental (relative) link objects should be put into the
+# processor-specific source directory (where other link objects will
+# be created). If the pass1 obect is an archive, it could go anywhere.
+
+ifeq ($(CONFIG_BUILD_2PASS),y)
+EXTRA_OBJS += $(CONFIG_PASS1_OBJECT)
+endif
+
+# NUTTXLIBS is the list of NuttX libraries that is passed to the
+# processor-specific Makefile to build the final NuttX target.
+# Libraries in FSDIRS are excluded if file descriptor support
+# is disabled.
+# USERLIBS is the list of libraries used to build the final user-space
+# application
+
+NUTTXLIBS = lib\libsched$(LIBEXT) lib\libarch$(LIBEXT)
+USERLIBS =
+
+# Add libraries for syscall support. The C library will be needed by
+# both the kernel- and user-space builds. For now, the memory manager (mm)
+# is placed in user space (only).
+
+ifeq ($(CONFIG_NUTTX_KERNEL),y)
+NUTTXLIBS += lib\libstubs$(LIBEXT) lib\libkc$(LIBEXT)
+USERLIBS += lib\libproxies$(LIBEXT) lib\libuc$(LIBEXT) lib\libmm$(LIBEXT)
+else
+NUTTXLIBS += lib\libmm$(LIBEXT) lib\libc$(LIBEXT)
+endif
+
+# Add libraries for C++ support. CXX, CXXFLAGS, and COMPILEXX must
+# be defined in Make.defs for this to work!
+
+ifeq ($(CONFIG_HAVE_CXX),y)
+ifeq ($(CONFIG_NUTTX_KERNEL),y)
+USERLIBS += lib\libcxx$(LIBEXT)
+else
+NUTTXLIBS += lib\libcxx$(LIBEXT)
+endif
+endif
+
+# Add library for application support.
+
+ifneq ($(APPDIR),)
+ifeq ($(CONFIG_NUTTX_KERNEL),y)
+USERLIBS += lib\libapps$(LIBEXT)
+else
+NUTTXLIBS += lib\libapps$(LIBEXT)
+endif
+endif
+
+# Add libraries for network support
+
+ifeq ($(CONFIG_NET),y)
+NUTTXLIBS += lib\libnet$(LIBEXT)
+endif
+
+# Add libraries for file system support
+
+ifeq ($(CONFIG_NFILE_DESCRIPTORS),0)
+ifneq ($(CONFIG_NSOCKET_DESCRIPTORS),0)
+NUTTXLIBS += lib\libfs$(LIBEXT)
+endif
+ifeq ($(CONFIG_NET),y)
+NUTTXLIBS += lib\libdrivers$(LIBEXT)
+endif
+else
+NUTTXLIBS += lib\libfs$(LIBEXT) lib\libdrivers$(LIBEXT) lib\libbinfmt$(LIBEXT)
+endif
+
+# Add libraries for the NX graphics sub-system
+
+ifeq ($(CONFIG_NX),y)
+NUTTXLIBS += lib\libgraphics$(LIBEXT)
+endif
+
+# LINKLIBS derives from NUTTXLIBS and is simply the same list with the subdirectory removed
+
+LINKLIBS = $(patsubst lib\\%,%,$(NUTTXLIBS))
+
+# This is the name of the final target (relative to the top level directorty)
+
+BIN = nuttx$(EXEEXT)
+
+all: $(BIN)
+.PHONY: context clean_context check_context export subdir_clean clean subdir_distclean distclean apps_clean apps_distclean
+
+# Target used to copy include\nuttx\math.h. If CONFIG_ARCH_MATH_H is
+# defined, then there is an architecture specific math.h header file
+# that will be included indirectly from include\math.h. But first, we
+# have to copy math.h from include\nuttx\. to include\. Logic within
+# include\nuttx\math.h will hand the redirection to the architecture-
+# specific math.h header file.
+#
+# If the CONFIG_LIBM is defined, the Rhombus libm will be built at libc\math.
+# Definitions and prototypes for the Rhombus libm are also contained in
+# include\nuttx\math.h and so the file must also be copied in that case.
+#
+# If neither CONFIG_ARCH_MATH_H nor CONFIG_LIBM is defined, then no math.h
+# header file will be provided. You would want that behavior if (1) you
+# don't use libm, or (2) you want to use the math.h and libm provided
+# within your toolchain.
+
+ifeq ($(CONFIG_ARCH_MATH_H),y)
+NEED_MATH_H = y
+else
+ifeq ($(CONFIG_LIBM),y)
+NEED_MATH_H = y
+endif
+endif
+
+ifeq ($(NEED_MATH_H),y)
+include\math.h: include\nuttx\math.h
+ $(Q) cp -f include\nuttx\math.h include\math.h
+else
+include\math.h:
+endif
+
+# The float.h header file defines the properties of your floating point
+# implementation. It would always be best to use your toolchain's float.h
+# header file but if none is avaiable, a default float.h header file will
+# provided if this option is selected. However there is no assurance that
+# the settings in this float.h are actually correct for your platform!
+
+ifeq ($(CONFIG_ARCH_FLOAT_H),y)
+include\float.h: include\nuttx\float.h
+ $(Q) cp -f include\nuttx\float.h include\float.h
+else
+include\float.h:
+endif
+
+# Target used to copy include\nuttx\stdarg.h. If CONFIG_ARCH_STDARG_H is
+# defined, then there is an architecture specific stdarg.h header file
+# that will be included indirectly from include\stdarg.h. But first, we
+# have to copy stdarg.h from include\nuttx\. to include\.
+
+ifeq ($(CONFIG_ARCH_STDARG_H),y)
+include\stdarg.h: include\nuttx\stdarg.h
+ $(Q) cp -f include\nuttx\stdarg.h include\stdarg.h
+else
+include\stdarg.h:
+endif
+
+# Targets used to build include\nuttx\version.h. Creation of version.h is
+# part of the overall NuttX configuration sequence. Notice that the
+# tools\mkversion tool is built and used to create include\nuttx\version.h
+
+tools\mkversion$(HOSTEXEEXT):
+ $(Q) $(MAKE) -C tools -f Makefile.host TOPDIR="$(TOPDIR)" mkversion$(HOSTEXEEXT)
+
+$(TOPDIR)\.version:
+ $(Q) if [ ! -f .version ]; then \
+ echo "No .version file found, creating one"; \
+ tools\version.sh -v 0.0 -b 0 .version; \
+ chmod 755 .version; \
+ fi
+
+include\nuttx\version.h: $(TOPDIR)\.version tools\mkversion$(HOSTEXEEXT)
+ $(Q) tools\mkversion$(HOSTEXEEXT) $(TOPDIR) > include\nuttx\version.h
+
+# Targets used to build include\nuttx\config.h. Creation of config.h is
+# part of the overall NuttX configuration sequence. Notice that the
+# tools\mkconfig tool is built and used to create include\nuttx\config.h
+
+tools\mkconfig$(HOSTEXEEXT):
+ $(Q) $(MAKE) -C tools -f Makefile.host TOPDIR="$(TOPDIR)" mkconfig$(HOSTEXEEXT)
+
+include\nuttx\config.h: $(TOPDIR)\.config tools\mkconfig$(HOSTEXEEXT)
+ $(Q) tools\mkconfig$(HOSTEXEEXT) $(TOPDIR) > include\nuttx\config.h
+
+# Targets used to create dependencies
+
+tools\mkdeps$(HOSTEXEEXT):
+ $(Q) $(MAKE) -C tools -f Makefile.host TOPDIR="$(TOPDIR)" mkdeps$(HOSTEXEEXT)
+
+# dirlinks, and helpers
+#
+# Directories links. Most of establishing the NuttX configuration involves
+# setting up symbolic links with 'generic' directory names to specific,
+# configured directories.
+#
+# Link the apps\include directory to include\apps
+
+include\apps: Make.defs
+ifneq ($(APPDIR),)
+ @echo LN: include\apps $(APPDIR)\include
+ifeq ($(CONFIG_WINDOWS_MKLINK),y)
+ $(Q) /user:administrator mklink /d include\apps $(APPDIR)\include
+else
+ $(Q) xcopy $(APPDIR)\include include\apps /c /q /s /e /y /i
+ $(Q) echo FAKELNK > include\apps\.fakelnk
+endif
+endif
+
+# Link the arch\<arch-name>\include directory to include\arch
+
+include\arch: Make.defs
+ @echo LN: include\arch to $(ARCH_DIR)\include
+ifeq ($(CONFIG_WINDOWS_MKLINK),y)
+ $(Q) /user:administrator mklink /d include\arch $(TOPDIR)\$(ARCH_DIR)\include
+else
+ $(Q) xcopy $(TOPDIR)\$(ARCH_DIR)\include include\arch /c /q /s /e /y /i
+ $(Q) echo FAKELNK > include\arch\.fakelnk
+endif
+
+# Link the configs\<board-name>\include directory to include\arch\board
+
+include\arch\board: include\arch Make.defs include\arch
+ @echo LN: include\arch\board to $(BOARD_DIR)\include
+ifeq ($(CONFIG_WINDOWS_MKLINK),y)
+ $(Q) /user:administrator mklink /d include\arch\board $(TOPDIR)\$(BOARD_DIR)\include
+else
+ $(Q) xcopy $(TOPDIR)\$(BOARD_DIR)\include include\arch\board /c /q /s /e /y /i
+ $(Q) echo FAKELNK > include\arch\board\.fakelnk
+endif
+
+# Link the configs\<board-name>\src dir to arch\<arch-name>\src\board
+
+$(ARCH_SRC)\board: Make.defs
+ @echo LN: $(ARCH_SRC)\board to $(BOARD_DIR)\src
+ifeq ($(CONFIG_WINDOWS_MKLINK),y)
+ $(Q) /user:administrator mklink /d $(ARCH_SRC)\board $(TOPDIR)\$(BOARD_DIR)\src
+else
+ $(Q) xcopy $(TOPDIR)\$(BOARD_DIR)\src $(ARCH_SRC)\board /c /q /s /e /y /i
+ $(Q) echo FAKELNK > $(ARCH_SRC)\board\.fakelnk
+endif
+
+# Link arch\<arch-name>\include\<chip-name> to arch\<arch-name>\include\chip
+
+$(ARCH_SRC)\chip: Make.defs
+ifneq ($(CONFIG_ARCH_CHIP),)
+ @echo LN: $(ARCH_SRC)\chip to $(ARCH_SRC)\$(CONFIG_ARCH_CHIP)
+ifeq ($(CONFIG_WINDOWS_MKLINK),y)
+ $(Q) /user:administrator mklink /d $(ARCH_SRC)\chip $(TOPDIR)\$(ARCH_SRC)\$(CONFIG_ARCH_CHIP)
+else
+ $(Q) xcopy $(TOPDIR)\$(ARCH_SRC)\$(CONFIG_ARCH_CHIP) $(ARCH_SRC)\chip /c /q /s /e /y /i
+ $(Q) echo FAKELNK > $(ARCH_SRC)\chip\.fakelnk
+endif
+endif
+
+# Link arch\<arch-name>\src\<chip-name> to arch\<arch-name>\src\chip
+
+include\arch\chip: include\arch Make.defs
+ifneq ($(CONFIG_ARCH_CHIP),)
+ @echo LN: include\arch\chip to $(ARCH_INC)\$(CONFIG_ARCH_CHIP)
+ifeq ($(CONFIG_WINDOWS_MKLINK),y)
+ $(Q) /user:administrator mklink /d include\arch\chip $(TOPDIR)\$(ARCH_INC)\$(CONFIG_ARCH_CHIP)
+else
+ $(Q) xcopy $(TOPDIR)\$(ARCH_INC)\$(CONFIG_ARCH_CHIP) include\arch\chip /c /q /s /e /y /i
+ $(Q) echo FAKELNK > include\arch\chip\.fakelnk
+endif
+endif
+
+dirlinks: include\arch include\arch\board include\arch\chip $(ARCH_SRC)\board $(ARCH_SRC)\chip include\apps
+
+# context
+#
+# The context target is invoked on each target build to assure that NuttX is
+# properly configured. The basic configuration steps include creation of the
+# the config.h and version.h header files in the include\nuttx directory and
+# the establishment of symbolic links to configured directories.
+
+context: check_context include\nuttx\config.h include\nuttx\version.h include\math.h include\float.h include\stdarg.h dirlinks
+ $(Q) for %%G in ($(CONTEXTDIRS)) do ( $(MAKE) -C %%G TOPDIR="$(TOPDIR)" context )
+
+# clean_context
+#
+# This is part of the distclean target. It removes all of the header files
+# and symbolic links created by the context target.
+
+clean_context:
+ $(call DELFILE, include\nuttx\config.h)
+ $(call DELFILE, include\nuttx\version.h)
+ $(call DELFILE, include\math.h)
+ $(call DELFILE, include\stdarg.h)
+ $(call DELDIR, include\arch\board)
+ $(call DELDIR, include\arch\chip)
+ $(call DELDIR, include\arch)
+ $(call DELDIR, $(ARCH_SRC)\board)
+ $(call DELDIR, $(ARCH_SRC)\chip)
+ $(call DELDIR, include\apps)
+
+# check_context
+#
+# This target checks if NuttX has been configured. NuttX is configured using
+# the script tools\configure.sh. That script will install certain files in
+# the top-level NuttX build directory. This target verifies that those
+# configuration files have been installed and that NuttX is ready to be built.
+
+check_context:
+ $(Q) if not exist $(TOPDIR)\.config echo "$(TOPDIR)\.config does not exist"
+ $(Q) if not exist $(TOPDIR)\Make.defs echo "$(TOPDIR)\Make.defs does not exist"
+
+# Archive targets. The target build sequency will first create a series of
+# libraries, one per configured source file directory. The final NuttX
+# execution will then be built from those libraries. The following targets
+# build those libraries.
+#
+# Possible kernel-mode builds
+
+libc\libkc$(LIBEXT): context
+ $(Q) $(MAKE) -C libc TOPDIR="$(TOPDIR)" libkc$(LIBEXT) EXTRADEFINES=$(KDEFINE)
+
+lib\libkc$(LIBEXT): libc\libkc$(LIBEXT)
+ $(Q) install libc\libkc$(LIBEXT) lib\libkc$(LIBEXT)
+
+sched\libsched$(LIBEXT): context
+ $(Q) $(MAKE) -C sched TOPDIR="$(TOPDIR)" libsched$(LIBEXT) EXTRADEFINES=$(KDEFINE)
+
+lib\libsched$(LIBEXT): sched\libsched$(LIBEXT)
+ $(Q) install sched\libsched$(LIBEXT) lib\libsched$(LIBEXT)
+
+$(ARCH_SRC)\libarch$(LIBEXT): context
+ $(Q) $(MAKE) -C $(ARCH_SRC) TOPDIR="$(TOPDIR)" libarch$(LIBEXT) EXTRADEFINES=$(KDEFINE)
+
+lib\libarch$(LIBEXT): $(ARCH_SRC)\libarch$(LIBEXT)
+ $(Q) install $(ARCH_SRC)\libarch$(LIBEXT) lib\libarch$(LIBEXT)
+
+net\libnet$(LIBEXT): context
+ $(Q) $(MAKE) -C net TOPDIR="$(TOPDIR)" libnet$(LIBEXT) EXTRADEFINES=$(KDEFINE)
+
+lib\libnet$(LIBEXT): net\libnet$(LIBEXT)
+ $(Q) install net\libnet$(LIBEXT) lib\libnet$(LIBEXT)
+
+fs\libfs$(LIBEXT): context
+ $(Q) $(MAKE) -C fs TOPDIR="$(TOPDIR)" libfs$(LIBEXT) EXTRADEFINES=$(KDEFINE)
+
+lib\libfs$(LIBEXT): fs\libfs$(LIBEXT)
+ $(Q) install fs\libfs$(LIBEXT) lib\libfs$(LIBEXT)
+
+drivers\libdrivers$(LIBEXT): context
+ $(Q) $(MAKE) -C drivers TOPDIR="$(TOPDIR)" libdrivers$(LIBEXT) EXTRADEFINES=$(KDEFINE)
+
+lib\libdrivers$(LIBEXT): drivers\libdrivers$(LIBEXT)
+ $(Q) install drivers\libdrivers$(LIBEXT) lib\libdrivers$(LIBEXT)
+
+binfmt\libbinfmt$(LIBEXT): context
+ $(Q) $(MAKE) -C binfmt TOPDIR="$(TOPDIR)" libbinfmt$(LIBEXT) EXTRADEFINES=$(KDEFINE)
+
+lib\libbinfmt$(LIBEXT): binfmt\libbinfmt$(LIBEXT)
+ $(Q) install binfmt\libbinfmt$(LIBEXT) lib\libbinfmt$(LIBEXT)
+
+graphics\libgraphics$(LIBEXT): context
+ $(Q) $(MAKE) -C graphics TOPDIR="$(TOPDIR)" libgraphics$(LIBEXT) EXTRADEFINES=$(KDEFINE)
+
+lib\libgraphics$(LIBEXT): graphics\libgraphics$(LIBEXT)
+ $(Q) install graphics\libgraphics$(LIBEXT) lib\libgraphics$(LIBEXT)
+
+syscall\libstubs$(LIBEXT): context
+ $(Q) $(MAKE) -C syscall TOPDIR="$(TOPDIR)" libstubs$(LIBEXT) EXTRADEFINES=$(KDEFINE)
+
+lib\libstubs$(LIBEXT): syscall\libstubs$(LIBEXT)
+ $(Q) install syscall\libstubs$(LIBEXT) lib\libstubs$(LIBEXT)
+
+# Possible user-mode builds
+
+libc\libuc$(LIBEXT): context
+ $(Q) $(MAKE) -C libc TOPDIR="$(TOPDIR)" libuc$(LIBEXT)
+
+lib\libuc$(LIBEXT): libc\libuc$(LIBEXT)
+ $(Q) install libc\libuc$(LIBEXT) lib\libuc$(LIBEXT)
+
+libxx\libcxx$(LIBEXT): context
+ $(Q) $(MAKE) -C libxx TOPDIR="$(TOPDIR)" libcxx$(LIBEXT)
+
+lib\libcxx$(LIBEXT): libxx\libcxx$(LIBEXT)
+ $(Q) install libxx\libcxx$(LIBEXT) lib\libcxx$(LIBEXT)
+
+mm\libmm$(LIBEXT): context
+ $(Q) $(MAKE) -C mm TOPDIR="$(TOPDIR)" libmm$(LIBEXT) EXTRADEFINES=$(KDEFINE)
+
+lib\libmm$(LIBEXT): mm\libmm$(LIBEXT)
+ $(Q) install mm\libmm$(LIBEXT) lib\libmm$(LIBEXT)
+
+$(APPDIR)\libapps$(LIBEXT): context
+ $(Q) $(MAKE) -C $(APPDIR) TOPDIR="$(TOPDIR)" libapps$(LIBEXT)
+
+lib\libapps$(LIBEXT): $(APPDIR)\libapps$(LIBEXT)
+ $(Q) install $(APPDIR)\libapps$(LIBEXT) lib\libapps$(LIBEXT)
+
+syscall\libproxies$(LIBEXT): context
+ $(Q) $(MAKE) -C syscall TOPDIR="$(TOPDIR)" libproxies$(LIBEXT)
+
+lib\libproxies$(LIBEXT): syscall\libproxies$(LIBEXT)
+ $(Q) install syscall\libproxies$(LIBEXT) lib\libproxies$(LIBEXT)
+
+# Possible non-kernel builds
+
+libc\libc$(LIBEXT): context
+ $(Q) $(MAKE) -C libc TOPDIR="$(TOPDIR)" libc$(LIBEXT)
+
+lib\libc$(LIBEXT): libc\libc$(LIBEXT)
+ $(Q) install libc\libc$(LIBEXT) lib\libc$(LIBEXT)
+
+# pass1 and pass2
+#
+# If the 2 pass build option is selected, then this pass1 target is
+# configured to built before the pass2 target. This pass1 target may, as an
+# example, build an extra link object (CONFIG_PASS1_OBJECT) which may be an
+# incremental (relative) link object, but could be a static library (archive);
+# some modification to this Makefile would be required if CONFIG_PASS1_OBJECT
+# is an archive. Exactly what is performed during pass1 or what it generates
+# is unknown to this makefule unless CONFIG_PASS1_OBJECT is defined.
+
+pass1deps: pass1dep $(USERLIBS)
+
+pass1: pass1deps
+ifeq ($(CONFIG_BUILD_2PASS),y)
+ $(Q) if [ -z "$(CONFIG_PASS1_BUILDIR)" ]; then \
+ echo "ERROR: CONFIG_PASS1_BUILDIR not defined"; \
+ exit 1; \
+ fi
+ $(Q) if [ ! -d "$(CONFIG_PASS1_BUILDIR)" ]; then \
+ echo "ERROR: CONFIG_PASS1_BUILDIR does not exist"; \
+ exit 1; \
+ fi
+ $(Q) if [ ! -f "$(CONFIG_PASS1_BUILDIR)\Makefile" ]; then \
+ echo "ERROR: No Makefile in CONFIG_PASS1_BUILDIR"; \
+ exit 1; \
+ fi
+ $(Q) $(MAKE) -C $(CONFIG_PASS1_BUILDIR) TOPDIR="$(TOPDIR)" LINKLIBS="$(LINKLIBS)" USERLIBS="$(USERLIBS)" "$(CONFIG_PASS1_TARGET)"
+endif
+
+pass2deps: pass2dep $(NUTTXLIBS)
+
+pass2: pass2deps
+ $(Q) $(MAKE) -C $(ARCH_SRC) TOPDIR="$(TOPDIR)" EXTRA_OBJS="$(EXTRA_OBJS)" LINKLIBS="$(LINKLIBS)" EXTRADEFINES=$(KDEFINE) $(BIN)
+ifeq ($(CONFIG_RRLOAD_BINARY),y)
+ @echo "MK: $(BIN).rr"
+ $(Q) $(TOPDIR)\tools\mkimage.sh --Prefix $(CROSSDEV) $(BIN) $(BIN).rr
+endif
+ifeq ($(CONFIG_INTELHEX_BINARY),y)
+ @echo "CP: $(BIN).hex"
+ $(Q) $(OBJCOPY) $(OBJCOPYARGS) -O ihex $(BIN) $(BIN).hex
+endif
+ifeq ($(CONFIG_MOTOROLA_SREC),y)
+ @echo "CP: $(BIN).srec"
+ $(Q) $(OBJCOPY) $(OBJCOPYARGS) -O srec $(BIN) $(BIN).srec
+endif
+ifeq ($(CONFIG_RAW_BINARY),y)
+ @echo "CP: $(BIN).bin"
+ $(Q) $(OBJCOPY) $(OBJCOPYARGS) -O binary $(BIN) $(BIN).bin
+endif
+
+# $(BIN)
+#
+# Create the final NuttX executable in a two pass build process. In the
+# normal case, all pass1 and pass2 dependencies are created then pass1
+# and pass2 targets are built. However, in some cases, you may need to build
+# pass1 depenencies and pass1 first, then build pass2 dependencies and pass2.
+# in that case, execute 'make pass1 pass2' from the command line.
+
+$(BIN): pass1deps pass2deps pass1 pass2
+
+# download
+#
+# This is a helper target that will rebuild NuttX and download it to the target
+# system in one step. The operation of this target depends completely upon
+# implementation of the DOWNLOAD command in the user Make.defs file. It will
+# generate an error an error if the DOWNLOAD command is not defined.
+
+download: $(BIN)
+ $(call DOWNLOAD, $<)
+
+# pass1dep: Create pass1 build dependencies
+# pass2dep: Create pass2 build dependencies
+
+pass1dep: context tools\mkdeps$(HOSTEXEEXT)
+ $(Q) for %%G in ($(USERDEPDIRS)) do ( $(MAKE) -C %%G TOPDIR="$(TOPDIR)" depend )
+
+pass2dep: context tools\mkdeps$(HOSTEXEEXT)
+ $(Q) for %%G in ($(KERNDEPDIRS)) do ( $(MAKE) -C %%G TOPDIR="$(TOPDIR)" EXTRADEFINES=$(KDEFINE) depend )
+
+# Configuration targets
+#
+# These targets depend on the kconfig-frontends packages. To use these, you
+# must first download and install the kconfig-frontends package from this
+# location: http://ymorin.is-a-geek.org/projects/kconfig-frontends. See
+# misc\tools\README.txt for additional information.
+
+config:
+ $(Q) APPSDIR=${CONFIG_APPS_DIR} conf Kconfig
+
+oldconfig:
+ $(Q) APPSDIR=${CONFIG_APPS_DIR} conf --oldconfig Kconfig
+
+menuconfig:
+ $(Q) APPSDIR=${CONFIG_APPS_DIR} mconf Kconfig
+
+# export
+#
+# The export target will package the NuttX libraries and header files into
+# an exportable package. Caveats: (1) These needs some extension for the KERNEL
+# build; it needs to receive USERLIBS and create a libuser.a). (2) The logic
+# in tools\mkexport.sh only supports GCC and, for example, explicitly assumes
+# that the archiver is 'ar'
+
+export: pass2deps
+ $(Q) tools\mkexport.sh -w$(WINTOOL) -t "$(TOPDIR)" -l "$(NUTTXLIBS)"
+
+# General housekeeping targets: dependencies, cleaning, etc.
+#
+# depend: Create both PASS1 and PASS2 dependencies
+# clean: Removes derived object files, archives, executables, and
+# temporary files, but retains the configuration and context
+# files and directories.
+# distclean: Does 'clean' then also removes all configuration and context
+# files. This essentially restores the directory structure
+# to its original, unconfigured stated.
+
+depend: pass1dep pass2dep
+
+subdir_clean:
+ $(Q) for %%G in ($(CLEANDIRS)) do ( if exist %%G\Makefile $(MAKE) -C %%G TOPDIR="$(TOPDIR)" clean )
+ $(Q) $(MAKE) -C tools -f Makefile.host TOPDIR="$(TOPDIR)" clean
+ $(Q) $(MAKE) -C mm -f Makefile.test TOPDIR="$(TOPDIR)" clean
+ifeq ($(CONFIG_BUILD_2PASS),y)
+ $(Q) $(MAKE) -C $(CONFIG_PASS1_BUILDIR) TOPDIR="$(TOPDIR)" clean
+endif
+
+clean: subdir_clean
+ $(call DELFILE, $(BIN))
+ $(call DELFILE, nuttx.*)
+ $(call DELFILE, mm_test)
+ $(call DELFILE, *.map)
+ $(call DELFILE, _SAVED_APPS_config)
+ $(call DELFILE, nuttx-export*)
+ $(call CLEAN)
+
+subdir_distclean:
+ $(Q) for %%G in ($(CLEANDIRS)) do ( if exist %%G\Makefile $(MAKE) -C %%G TOPDIR="$(TOPDIR)" distclean )
+
+distclean: clean subdir_distclean clean_context
+ifeq ($(CONFIG_BUILD_2PASS),y)
+ $(Q) $(MAKE) -C $(CONFIG_PASS1_BUILDIR) TOPDIR="$(TOPDIR)" distclean
+endif
+ $(call DELFILE, Make.defs)
+ $(call DELFILE, setenv.sh)
+ $(call DELFILE, setenv.bat)
+ $(call DELFILE, .config)
+ $(call DELFILE, .config.old)
+
+# Application housekeeping targets. The APPDIR variable refers to the user
+# application directory. A sample apps\ directory is included with NuttX,
+# however, this is not treated as part of NuttX and may be replaced with a
+# different application directory. For the most part, the application
+# directory is treated like any other build directory in this script. However,
+# as a convenience, the following targets are included to support housekeeping
+# functions in the user application directory from the NuttX build directory.
+#
+# apps_clean: Perform the clean operation only in the user application
+# directory
+# apps_distclean: Perform the distclean operation only in the user application
+# directory. Note that the apps\.config file (inf any) is
+# preserved so that this is not a "full" distclean but more of a
+# configuration "reset." (There willnot be an apps\.config
+# file if the configuration was generated via make menuconfig).
+
+apps_clean:
+ifneq ($(APPDIR),)
+ $(Q) $(MAKE) -C "$(TOPDIR)\$(APPDIR)" TOPDIR="$(TOPDIR)" clean
+endif
+
+apps_distclean:
+ifneq ($(APPDIR),)
+ $(call DELFILE, _SAVED_APPS_config
+ $(Q) if exist "$(TOPDIR)\$(APPDIR)\.config" ( cp "$(TOPDIR)\$(APPDIR)\.config" _SAVED_APPS_config )
+ $(Q) $(MAKE) -C "$(TOPDIR)\$(APPDIR)" TOPDIR="$(TOPDIR)" distclean
+ $(Q) if exist _SAVED_APPS_config ( mv _SAVED_APPS_config "$(TOPDIR)\$(APPDIR)\.config" )
+endif
+
diff --git a/nuttx/README.txt b/nuttx/README.txt
index d60da2d88..b9210277e 100644
--- a/nuttx/README.txt
+++ b/nuttx/README.txt
@@ -18,6 +18,8 @@ README
- Building
- Re-building
- Build Targets and Options
+ - Native Windows Build
+ - Installing GNUWin32
o Cygwin Build Problems
- Strange Path Problems
- Window Native Toolchain Issues
@@ -154,9 +156,15 @@ Notes about Header Files
Even though you should not use a foreign C-Library, you may still need
to use other, external libraries with NuttX. In particular, you may
- need to use the math library, libm.a. The math libary header file,
- math.h, is a special case. If you do nothing, the standard math.h
- header file that is provided with your toolchain will be used.
+ need to use the math library, libm.a. NuttX supports a generic, built-in
+ math library that can be enabled using CONFIG_LIBM=y. However, you may
+ still want to use a higher performance external math library that has
+ been tuned for your CPU. Sometimes such such tuned math libraries are
+ bundled with your toolchain.
+
+ The math libary header file, math.h, is a then special case. If you do
+ nothing, the standard math.h header file that is provided with your
+ toolchain will be used.
If you have a custom, architecture specific math.h header file, then
that header file should be placed at arch/<cpu>/include/math.h. There
@@ -171,6 +179,16 @@ Notes about Header Files
than to include that archicture-specific math.h header file as the
system math.h header file.
+ float.h
+
+ If you enable the generic, built-in math library, then that math library
+ will expect your toolchain to provide the standard float.h header file.
+ The float.h header file defines the properties of your floating point
+ implementation. It would always be best to use your toolchain's float.h
+ header file but if none is avaiable, a default float.h header file will
+ provided if this option is selected. However, there is no assurance that
+ the settings in this float.h are actually correct for your platform!
+
stdarg.h
In most cases, the correct version of stdarg.h is the version provided with your toolchain. However, sometimes there are issues with with using your toolchains stdarg.h. For example, it may attempt to draw in header files that do not exist in NuttX or perhaps the header files that is uses are not compatible with the NuttX header files. In those cases, you can use an architecture-specific stdarg.h header file by defining CONFIG_ARCH_STDARG_H=y.
@@ -189,7 +207,8 @@ Instantiating "Canned" Configurations
Where <board-name> is the name of your development board and <config-dir>.
Configuring NuttX requires only copying three files from the <config-dir>
-to the directly where you installed NuttX (TOPDIR):
+to the directory where you installed NuttX (TOPDIR) (and sometimes one
+additional file to the directory the NuttX application package (APPSDIR)):
Copy configs/<board-name>/<config-dir>/Make.def to ${TOPDIR}/Make.defs
@@ -211,6 +230,14 @@ to the directly where you installed NuttX (TOPDIR):
included in the build and what is not. This file is also used
to generate a C configuration header at include/nuttx/config.h.
+ Copy configs/<board-name>/<config-dir>/appconfig to ${APPSDIR}/.config
+
+ The appconfig file describes the applications that need to be
+ built in the appliction directory (APPSDIR). Not all configurations
+ have an appconfig file. This file is deprecated and will not be
+ used with new defconfig files produced with the mconf configuration
+ tool.
+
General information about configuring NuttX can be found in:
${TOPDIR}/configs/README.txt
@@ -468,6 +495,97 @@ Build Targets and Options
useful when adding new boards or tracking down compile time errors and
warnings (Contributed by Richard Cochran).
+Native Windows Build
+--------------------
+
+ The beginnings of a Windows native build are in place but still not full
+ usable as of this writing. The windows native build logic initiatiated
+ if CONFIG_WINDOWS_NATIVE=y is defined in the NuttX configuration file:
+
+ This build:
+
+ - Uses all Windows style paths
+ - Uses primarily Windows batch commands from cmd.exe, with
+ - A few extensions from GNUWin32
+
+ In this build, you cannot use a Cygwin or MSYS shell. Rather the build must
+ be performed in a Windows CMD shell. Here is a better shell than than the
+ standard issue, CMD shell: ConEmu which can be downloaded from:
+ http://code.google.com/p/conemu-maximus5/
+
+ Build Tools. The build still relies on some Unix-like commands. I use
+ the GNUWin32 tools that can be downloaded from http://gnuwin32.sourceforge.net/.
+
+ Host Compiler: I use the MingGW compiler which can be downloaded from
+ http://www.mingw.org/. If you are using GNUWin32, then it is recommended
+ the you not install the optional MSYS components as there may be conflicts.
+
+Installing GNUWin32
+-------------------
+
+The Windows native build will depend upon a few Unix-like tools that can be
+provided either by MSYS or GNUWin32. The GNUWin32 are available from
+http://gnuwin32.sourceforge.net/. GNUWin32 provides ports of tools with a
+GPL or similar open source license to modern MS-Windows (Microsoft Windows
+2000 / XP / 2003 / Vista / 2008 / 7). See
+http://gnuwin32.sourceforge.net/packages.html for a list of all of the tools
+available in the GNUWin32 package.
+
+The SourceForge project is located here:
+http://sourceforge.net/projects/gnuwin32/. The project is still being
+actively supported (although some of the Windows ports have gotten very old).
+
+Some commercial toolchains include a subset of the GNUWin32 tools in the
+installation. My recommendation is that you download the GNUWin32 tools
+directly from the sourceforge.net website so that you will know what you are
+using and can reproduce your build environment.
+
+GNUWin32 Installation Steps:
+
+The following steps will download and execute the GNUWin32 installer.
+
+1. Download GetGNUWin32-x.x.x.exe from
+ http://sourceforge.net/projects/getgnuwin32/files/. This is the
+ installer. The current version as of this writing is 0.6.3.
+
+2. Run the installer.
+
+3. Accept the license.
+
+4. Select the installation directory. My recommendation is the
+ directory that contains this README file (<this-directory>).
+
+5. After running GetGNUWin32-0.x.x.exe, you will have a new directory
+ <this-directory>/GetGNUWin32
+
+Note the the GNUWin32 installer didn't install GNUWin32. Instead, it
+installed another, smarter downloader. That downloader is the GNUWin32
+package management tool developed by the Open SSL project.
+
+The following steps probably should be performed from inside a DOS shell.
+
+6. Change to the directory created by GetGNUWin32-x.x.x.exe
+
+ cd GetGNUWin32
+
+7. Execute the download.bat script. The download.bat script will download
+ about 446 packages! Enough to have a very complete Linux-like environment
+ under the DOS shell. This will take awhile. This step only downloads
+ the packages and the next step will install the packages.
+
+ download
+
+8. This step will install the downloaded packages. The argument of the
+ install.bat script is the installation location. C:\gnuwin32 is the
+ standard install location:
+
+ install C:\gnuwin32
+
+NOTE: This installation step will install *all* GNUWin32 packages... far
+more than you will ever need. If disc space is a problem for you, you might
+need to perform a manual installation of the individual ZIP files that you
+will find in the <this directory>/GetGNUWin32/packages directory.
+
CYGWIN BUILD PROBLEMS
^^^^^^^^^^^^^^^^^^^^^
@@ -523,18 +641,16 @@ Window Native Toolchain Issues
is not a long as you might think because there is no dependency checking
if you are using a native Windows toolchain. That bring us to #3:
- 3. Dependencies are not made when using Windows versions of the GCC. This is
- because the dependencies are generated using Windows pathes which do not
- work with the Cygwin make.
+ 3. Dependencies are not made when using Windows versions of the GCC on a POSIX
+ platform (i.e., Cygwin). This is because the dependencies are generated
+ using Windows paths which do not work with the Cygwin make.
- Support has been added for making dependencies with the windows-native toolchains.
- That support can be enabled by modifying your Make.defs file as follows:
+ MKDEP = $(TOPDIR)/tools/mknulldeps.sh
- - MKDEP = $(TOPDIR)/tools/mknulldeps.sh
- + MKDEP = $(TOPDIR)/tools/mkdeps.sh --winpaths "$(TOPDIR)"
+ If you are building natively on Windows, then no such conflict exists
+ and the best selection is:
- If you have problems with the dependency build (for example, if you are not
- building on C:), then you may need to modify tools/mkdeps.sh
+ MKDEP = $(TOPDIR)/tools/mkdeps.exe
General Pre-built Toolchain Issues
@@ -629,7 +745,8 @@ nuttx
| | `-README.txt
| `- z80/
| | `- src/
- | | `- z80/README.txt
+ | | |- z80/README.txt
+ | | `- z180/README.txt, z180_mmu.txt
| `- README.txt
|- configs/
| |- amber/
@@ -728,6 +845,8 @@ nuttx
| | |- include/README.txt
| | |- src/README.txt
| | `- README.txt
+ | |- p112/
+ | | `- README.txt
| |- pcblogic-pic32mx/
| | `- README.txt
| |- pic32-starterkit/
@@ -765,6 +884,8 @@ nuttx
| | `- README.txt
| |- stm3240g-eval/
| | `- README.txt
+ | |- stm32f100rc_generic/
+ | | `- README.txt
| |- stm32f4discovery/
| | `- README.txt
| |- sure-pic32mx/
@@ -817,6 +938,8 @@ nuttx
| `- README.txt
|- lib/
| `- README.txt
+ |- libc/
+ | `- README.txt
|- libxx/
| `- README.txt
|- mm/
@@ -828,6 +951,7 @@ nuttx
apps
|- examples/
+ | |- json/README.txt
| |- pashello/README.txt
| `- README.txt
|- graphics/
@@ -843,6 +967,8 @@ apps
| | `- README.txt
| |- ftpc
| | `- README.txt
+ | |- json
+ | | `- README.txt
| |- telnetd
| | `- README.txt
| `- README.txt
@@ -864,3 +990,12 @@ apps
| `- sysinfo
| `- README.txt
`- README.txt
+
+ NxWidgets
+ |- Doxygen
+ | `- README.txt
+ |- tools
+ | `- README.txt
+ |- UnitTests
+ | `- README.txt
+ `- README.txt
diff --git a/nuttx/ReleaseNotes b/nuttx/ReleaseNotes
index b1d5f6064..02cb8158d 100644
--- a/nuttx/ReleaseNotes
+++ b/nuttx/ReleaseNotes
@@ -3171,3 +3171,272 @@ Bugfixes (see the change log for details). Some of these are very important
Vainish). Fix some field-width handling issues in sscanf()
As well as other, less critical bugs (see the ChangeLog for details)
+
+NuttX-6.23
+^^^^^^^^^^
+
+The 90th release of NuttX, Version 6.23, was made on November 5, 2012,
+and is available for download from the SourceForge website. Note
+that release consists of two tarballs: nuttx-6.23.tar.gz and
+apps-6.23.tar.gz. Both may be needed (see the top-level nuttx/README.txt
+file for build information).
+
+This release corresponds with SVN release number: r5313
+
+Note that all SVN information has been stripped from the tarballs. If you
+need the SVN configuration, you should check out directly from SVN. Revision
+r5313 should equivalent to release 6.23 of NuttX 6.23:
+
+ svn checkout -r5313 svn://svn.code.sf.net/p/nuttx/code/trunk nuttx-code
+
+Or
+
+ svn checkout -r5313 http://svn.code.sf.net/p/nuttx/code/trunk nuttx-code
+
+Additional new features and extended functionality:
+
+ * RTOS: If both atexit() and on_exit() are enabled, use on_exit() to
+ implement atexit(). Updates for RGMP 4.0.
+
+ * Binfmt: Add support for loading and executing ELF binary modules from
+ a file system.
+
+ * Drivers: Maxim MAX11802 touchscreen controller (Petteri Aimonen)
+
+ * STM32 Driver: Implementation of /dev/random using the STM32 Random Number
+ Generator (RNG).
+
+ * STM32 Boards: ADC support for the Shenzhou IV board. Relay support for
+ the Shenzhou IV board.
+
+ * C Library: Support is now included for the add-on uClibc++ C++
+ standard library support. This includes support for iostreams, strings,
+ STL, RTTI, exceptions -- the complete C++ environment. (uClibc++ is
+ provided as a separate add-on package due to licensing issues).
+
+ Optimized generic and ARM-specific memcpy() function. Optimized
+ memset() function.
+
+ Add support for ferror(), feof(), and clearerror(). Add support for
+ __cxa_atexit().
+
+ Math Library: Port of the math library from Rhombus OS by Nick Johnson
+ (Darcy Gong).
+
+ * Applications: New NSH commands: ifup, ifdown, urlencode, urldecode,
+ base64enc, bas64dec, md5 (Darcy Gong). Add support for NSH telnet login
+ (Darcy Gong). Enancements to NSH ping command to support pinging hosts
+ with very long round-trip times. Extensions to the ifconfig command
+ Darcy Gong),
+
+ Many extensions to the webclient/wget and DNS resolver logic from Darcy
+ Gong. JSON, Base64, URL encoding, and MD5 libraries contributed by Darcy
+ Gong.
+
+ New examples: ELF loader, JSON, wgetjson, cxxtest, relays.
+
+Bugfixes (see the change log for details). Some of these are very important
+(marked *critical*):
+
+ * Drivers: W25 SPI FLASH
+
+ * STM32 Drivers: ADC reset
+
+ * Graphics: Missing implementation of the blocked method (*critical*,
+ Petteri Aimonen).
+
+ * C Library: Floating point numbers in printf and related formatting functions
+ (Mike Smith), cf[get|set]speed() (Mike Smith)
+
+As well as other, less critical bugs (see the ChangeLog for details)
+
+NuttX-6.24
+^^^^^^^^^^
+
+The 91st release of NuttX, Version 6.24, was made on December 20, 2012,
+and is available for download from the SourceForge website. Note
+that release consists of two tarballs: nuttx-6.24.tar.gz and
+apps-6.24.tar.gz. Both may be needed (see the top-level nuttx/README.txt
+file for build information).
+
+This release corresponds with SVN release number: r5447
+
+Note that all SVN information has been stripped from the tarballs. If you
+need the SVN configuration information, you should check out directly from
+SVN. Revision r5447 should equivalent to release 6.24 of NuttX 6.24:
+
+ svn checkout -r5447 svn://svn.code.sf.net/p/nuttx/code/trunk nuttx-code
+
+Or (HTTP):
+
+ svn checkout -r5447 http://svn.code.sf.net/p/nuttx/code/trunk nuttx-code
+
+Additional new features and extended functionality:
+
+ * RTOS:
+
+ - Implemented the POSIX pause() function (still has some compiance
+ issues).
+ - Tasking logic is extended to support the notion of address
+ environments. An address environment is the key notion underlying
+ "process" vs. tasks. If tasks are created with address environments
+ (by binfmt), the OS will propogate that environment to child threads
+ and will destroy the address environment when the "process" exists.
+ - If support for the PATH variable is enabled, the OS start up logic
+ will create an initial environment containing the default PATH
+ setting (CONFIG_PATH_INITIAL). This initial PATH will then be
+ inherited by all tasks.
+
+ * Binfmt
+
+ - The NuttX binary loaders have been updated to support the PATH
+ environment variable. Now, if the PATH is properly defined, programs
+ can be executed from mass storage using only the file name. This
+ feature is added to support more standard behavior (eventually, NSH
+ will support execution of programs in file systems by just entering
+ the file name, perhaps in 6.25?).
+ - The NXFLAT and ELF binary loaders have been extended to create
+ address environments for any new tasks executed from the file system.
+ This feature requires that the architecture support a memory management
+ unit (MMU) and the address environment interfaces declared in
+ include/nuttx/arch.h (currently, this is only supported by the z180).
+
+ * Drivers: LCD driver for the Univision UG-2864AMBAG01 OLED
+
+ * STM32: Support for STM32F100 high density chips contributed by Freddie
+ Chopin.
+
+ * STM32 Drivers: Added optional RS-485 direction bit control (from
+ Freddie Chopin).
+
+ * STM32 Boards:
+
+ - Support for generic STM32F100RC board contributed by Freddie Chopin.
+ - stm32f4discovery/nxlines: STM32F4Discovery support for the
+ UG-2864AMBAG01 OLED.
+ - stm32f4discovery/winbuild: A version of the NuttX OS test
+ configured to build natively on Windows.
+ - stm32f4discovery/elf: Now uses the PATH variable to find ELF
+ executables.
+ - configs/cloudctrl: Added for Darcy Gong's CloudController board
+
+ * PIC32 Boards: Update the Mirtool configuration for Release 2 of the
+ Mirtoo module.
+
+ * Calypso: Add Calypso keypad driver. From Denis Cariki.
+
+ * ZiLOG:
+
+ - Add support for the z180 chip family and, specifically, for
+ the P112 retro hardware (see http://p112.feedle.net/).
+ - All ZiLOG configurations updated to use the current ZDS-II
+ and/or SDCC toolchains.
+
+ * Graphics:
+
+ - Add a semaphore handshake so that operations on buffers from
+ the NXMU client will be blocked until the NX server operates on the
+ buffer data (from Petteri Aimonen).
+ - nxtk_subwindowmove() and nxtk_getwindow(): Improvements to clipping
+ logic from Petteri Aimonen.
+
+ * C Library: lib/ sub-directory renamed libc/ (there is a new lib/ sub-
+ directory that is used to hold all archives).
+
+ * C++: Exception stubs from Petteri Aimonen.
+
+ * Applications:
+
+ - Add NSH hexdump command to dump the contents of a file (or character
+ device) to the console (contributed by Petteri Aimonen).
+ - Extend the NSH ifconfig command plus various DHCPC improvements
+ (from Darcy Gong).
+
+ * apps/examples:
+
+ - ostest: Replace large tables with algorithmic prime number
+ generation. This allows the roundrobin test to run on platforms
+ with minimal SRAM (Freddie Chopin).
+ - keypadtest: A new keypad test example contributed by Denis Carikli.
+ - elf and nxflat: If CONFIG_BINFMT_EXEPATH is defined, these examples
+ will now use a relative path to the program and expect the binfmt/
+ logic to find the absolute path to the program using the PATH
+ variable.
+
+ * Build system:
+
+ - New top-level Makefiles: Makefile.unix and Makefile.win (along with
+ numerous changes to other make-related files). This adds basic
+ support for building NuttX natively under Windows from a CMD.exe
+ window (rather than in a POSIX-like environment). This build: (1)
+ Uses all Windows style paths, (2) Uses primarily Windows batch
+ commands from cmd.exe, with (3) a few extensions from GNUWin32.
+
+ This capability should still be considered a work in progress
+ because: (1) it has not been verfied on all targets and tools,
+ and (2) still lacks some of the creature-comforts of the more
+ mature environments (like a function configure.sh script and
+ 'make menuconfig' support).
+
+ - Example Windows native builds for STM32F4Discovery, eZ80, z16f, z8,
+ Z80, and Z180.
+ - Several configurations have been converted to work the kconfig-
+ frontends mconf configuration tool: stm32f4discovery/nxlines, and
+ all eZ80, z16f, z8, Z80, and Z180 configurations.
+ - Architectures now include a common Toolchain.defs file that can be
+ used to manage toolchains in a more configurable way (most of this
+ contributed by Mike Smith).
+
+ * Build tools:
+
+ - Renamed tools/winlink.sh to tools/copydir.sh.
+ - Several new tools/scripts to support the Windows native build:
+ tools/mkdeps.bat, tools/mkdeps.c, tools/link.bat, unlink.bat, and
+ copydir.bat.
+ - tools/incdir.sh and incdir.bat now support an -s option to generate
+ system header file paths.
+ - tools/b16.c: Fixed precision math conversion utility.
+
+Bugfixes (see the change log for details). Some of these are very important
+(marked *critical*):
+
+ * RTOS: Fix some backward conditional compilation in the work queue
+ logic (Freddie Chopin).
+
+ * File System: Uninitialized variable caused assertions (from Lorenz
+ Meier).
+
+ * Drivers: Partial fix for STM32 OTGFS device drivers and fix for short,
+ unaligned writes in the flash translation layer (drivers/mtd/ftl.c),
+ both from Petteri Aimonen.
+
+ * STM32 Drivers:
+
+ - Qencoder driver and TIM3 driver fixes from Ryan Sundberg.
+ - Fix timeout delay calculation in the STM32 OTG FS host driver.
+
+ * LPC17xx Drivers: Resources not being properly released when I2C
+ driver is un-initialized.
+
+ * Graphics:
+
+ - Fix logic when the mouse drags outside of the window; fix
+ another "blocked message" handling case (both from Petteri Aimonen).
+ - nxtk_filltrapwindow(): Correct an offset problem (also from Peterri
+ Aimonen).
+ - nxglib_splitline(): Correct the "fat flat line" bug.
+
+ * C Library:
+
+ - nrand() changes to prevent coefficients from becoming zero which
+ would "lock up" the random number generate.
+ - Add rounding functions to the math library (contributed by Petteri
+ Aimonen).
+
+ * Build system: Changes to MIN definitions in all limit.h header files
+ to avoid integer overflows. For example from (-128) to (-127 - 1)
+ (from Petteri Aimonen).
+
+ * Applications: Modbus fixes from Freddie Chopin.
+
+As well as other, less critical bugs (see the ChangeLog for details)
diff --git a/nuttx/TODO b/nuttx/TODO
index 906601192..6c28bfd43 100644
--- a/nuttx/TODO
+++ b/nuttx/TODO
@@ -1,4 +1,4 @@
-NuttX TODO List (Last updated September 16, 2012)
+NuttX TODO List (Last updated November 25, 2012)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This file summarizes known NuttX bugs, limitations, inconsistencies with
@@ -14,13 +14,13 @@ nuttx/
(2) C++ Support
(6) Binary loaders (binfmt/)
(17) Network (net/, drivers/net)
- (3) USB (drivers/usbdev, drivers/usbhost)
- (11) Libraries (lib/)
+ (4) USB (drivers/usbdev, drivers/usbhost)
+ (11) Libraries (libc/, )
(9) File system/Generic drivers (fs/, drivers/)
(5) Graphics subystem (graphics/)
(1) Pascal add-on (pcode/)
(1) Documentation (Documentation/)
- (6) Build system / Toolchains
+ (8) Build system / Toolchains
(5) Linux/Cywgin simulation (arch/sim)
(6) ARM (arch/arm/)
(1) ARM/C5471 (arch/arm/src/c5471/)
@@ -32,15 +32,15 @@ nuttx/
(0) ARM/LPC43x (arch/arm/src/lpc43xx/)
(3) ARM/STR71x (arch/arm/src/str71x/)
(3) ARM/LM3S6918 (arch/arm/src/lm3s/)
- (7) ARM/STM32 (arch/arm/src/stm32/)
+ (4) ARM/STM32 (arch/arm/src/stm32/)
(3) AVR (arch/avr)
(0) Intel x86 (arch/x86)
- (4) 8051 / MCS51 (arch/8051/)
+ (5) 8051 / MCS51 (arch/8051/)
(3) MIPS/PIC32 (arch/mips)
(1) Hitachi/Renesas SH-1 (arch/sh/src/sh1)
(4) Renesas M16C/26 (arch/sh/src/m16c)
(10) z80/z8/ez80 (arch/z80/)
- (8) z16 (arch/z16/)
+ (9) z16 (arch/z16/)
(1) mc68hc1x (arch/hc)
apps/
@@ -421,7 +421,7 @@ o Binary loaders (binfmt/)
.word .LC3-(.LPIC4+4)
.word .LC4-(.LPIC5+4)
- This is good and bad. This is good because it means that .rodata.str1.1 can not
+ This is good and bad. This is good because it means that .rodata.str1.1 can now
reside in FLASH with .text and can be accessed using PC-relative addressing.
That can be accomplished by simply moving the .rodata from the .data section to
the .text section in the linker script. (The NXFLAT linker script is located at
@@ -629,8 +629,13 @@ o USB (drivers/usbdev, drivers/usbhost)
CDC/ACM serial driver might need the line coding data (that
data is not used currenly, but it might be).
-o Libraries (lib/)
- ^^^^^^^^^^^^^^^^
+ Title: USB HUB SUPPORT
+ Description: Add support for USB hubs
+ Status: Open
+ Priority: Low/Unknown. This is a feature enhancement.
+
+o Libraries (libc/)
+ ^^^^^^^^^^^^^^^^^
Title: ENVIRON
Description: The definition of environ in stdlib.h is bogus and will not
@@ -643,7 +648,7 @@ o Libraries (lib/)
Description: Need some minimal termios support... at a minimum, enough to
switch between raw and "normal" modes to support behavior like
that needed for readline().
- UPDATE: There is growing functionality in lib/termios/ and in the
+ UPDATE: There is growing functionality in libc/termios/ and in the
ioctl methods of several MCU serial drivers (stm32, lpc43, lpc17,
pic32). However, as phrased, this bug cannot yet be closed since
this "growing functionality" does not address all termios.h
@@ -708,7 +713,7 @@ o Libraries (lib/)
Priority:
Title: OLD dtoa NEEDS TO BE UPDATED
- Description: This implementation of dtoa in lib/stdio is old and will not
+ Description: This implementation of dtoa in libc/stdio is old and will not
work with some newer compilers. See
http://patrakov.blogspot.com/2009/03/dont-use-old-dtoac.html
Status: Open
@@ -716,7 +721,7 @@ o Libraries (lib/)
Title: SYSLOG INTEGRATION
Description: There are the beginnings of some system logging capabilities (see
- drivers/syslog, fs/fs_syslog.c, and lib/stdio/lib_librawprintf.c and
+ drivers/syslog, fs/fs_syslog.c, and libc/stdio/lib_librawprintf.c and
lib_liblowprintf.c. For NuttX, SYSLOG is a concept and includes,
extends, and replaces the legacy NuttX debug ouput. Some additional
integration is required to formalized this. For example:
@@ -890,23 +895,30 @@ o Build system
Description: Need a NuttX configuration tool. The number of configuration
settings has become quite large and difficult to manage manually.
Update: This task is essentially completed. But probably not for
- all platforms and all features. When do we know that the the
- features is complete and that we can switch to exclusive use of
- the tool?
+ all platforms and all features. When do we know that the feature
+ is complete and that we can switch to exclusive use of the tool?
Status: Open
Priority: Medium-low
Title: NATIVE WINDOWS BUILD
- Description: At present, NuttX builds only under Linux or Cygwin.
- Investigate the possibility of a native Windows build using
- something like the GNUWin32 tools (coreutils+make+grep+sed+uname).
+ Description: This effort is underway using MinGW-GCC and GNUWin32 tools
+ for (coreutils+make+grep+sed+uname). Current status:
+
+ 1. configs/stm32f4discovery/winbuild - builds okay natively
+ 2. configs/ez80f910200kitg - Can be reconfigured to build natively.
+ Requires some manual intervention to get a clean build.
+ See configs/ez80f910200kitg/README.txt.
+
Status: Open
Priority: Low
Title: WINDOWS DEPENDENCY GENERATION
Description: Dependency generation is currently disabled when a Windows native
- toolchain is used. I think that the only issue is that all of the
- Windows dependencies needed to be quoted in the Make.dep files.
+ toolchain is used in a POSIX-like enviornment (like Cygwin). The
+ issue is that the Windows tool generates dependencies use Windows
+ path formatting and this fails with the dependency file (Make.dep)
+ is include). Perhaps the only issue is that all of the Windows
+ dependencies needed to be quoted in the Make.dep files.
Status: Open
Priority: Low -- unless some dependency-related build issues is discovered.
@@ -953,7 +965,7 @@ o Build system
built configuration, only the multiple user mode can be supported
with the NX server residing inside of the kernel space. In
this case, most of the user end functions in graphics/nxmu
- must be moved to lib/nx and those functions must be built into
+ must be moved to libc/nx and those functions must be built into
libuser.a to be linked with the user-space code.
A similar issue exists in NSH that uses some internal OS
interfaces that would not be available in a kernel build
@@ -962,6 +974,48 @@ o Build system
Priority: Low -- the kernel build configuration is not fully fielded
yet.
+ Title: mconf NOT AVAILABLE IN NATIVE WINDOWS BUILD
+ Description: NuttX is migrating to the use of the kconfig-frontends mconf
+ tool for all configurations. In NuttX 6.24, support for native
+ Windows builds was added. However, the mconf tool does not
+ build to run natively under Windows.
+
+ Some effort was spent trying to get a clean mconf build under
+ Windows. This is documented in the message thread beginning
+ here: http://tech.groups.yahoo.com/group/nuttx/message/2900.
+ The build was successfully completed using: MinGW-GCC, MSYS,
+ additional Windows libraries, and additional MSYS libraries
+ (MSYS is a variant of Cygwin so, presumeably, Cygwin could
+ have been used as well). However, on final testing, it was
+ found that there are problems with text and numeric entry:
+ http://tech.groups.yahoo.com/group/nuttx/message/2953. This
+ was considered a show stopper and the changs were not checked
+ in.
+
+ Options: (1) Use conf (not mconf). confis the text-only
+ configuration tool, (2) fix mconf, (3) write another variant
+ of the configuration tool for windows, or (4) do all configuration
+ under Cygwin or MSYS. I am doing (4) now, but this is very
+ awkward because I have to set the apps path to ../apps (vs
+ ..\apps) and CONFIG_WINDOWS_NATIVE=n for the 'make menuconfig'
+ to run error free under windows. Very awkward!
+ Status: Open, there are some workarounds, but none are good.
+ Priority: High
+
+ Title: configure.sh NOT AVAILABLE IN NATIVE WINDOWS BUILD
+ Description: configure.sh is a Bash script and cannot be used from a Windows
+ CMD.exe window. I started a configure.bat script, but I do
+ not have the batch file programming skills to duplicate some
+ of the more complex operations.
+
+ I also considered adding a configure.c file that could be
+ compiled and then executed by configure.bat (and configure.sh?).
+ But I have not gone down that path yet.
+
+ The current work-around is to configure under Cygwin.
+ Status: Open
+ Priority: High
+
o Linux/Cywgin simulation (arch/sim)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -1344,11 +1398,6 @@ o ARM/LM3S6918 (arch/arm/src/lm3s/)
o ARM/STM32 (arch/arm/src/stm32/)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Title: NOR FLASH DRIVER
- Description: NOR Flash driver with FTL layer to support a file system.
- Status: Open
- Priority: Low
-
Title: USBSERIAL ISSUES
Description A USB device-side driver is in place but not well tested. At
present, the apps/examples/usbserial test sometimes fails. The situation
@@ -1371,11 +1420,6 @@ o ARM/STM32 (arch/arm/src/stm32/)
Status: Open
Priority: Medium-High
- Title: FSMC EXTERNAL MEMORY UNTESTED
- Description: FSMC external memory support is untested
- Status: Open
- Priority: Low
-
Title: DMA EXTENSIONS
Description: DMA logic needs to be extended. DMA2, Channel 5, will not work
because the DMA2 channels 4 & 5 share the same interrupt.
@@ -1383,12 +1427,6 @@ o ARM/STM32 (arch/arm/src/stm32/)
Priority: Low until someone needs DMA1, Channel 5 (ADC3, UART4_TX, TIM5_CH1, or
TIM8_CH2).
- Title: UNFINISHED DRIVERS
- Description: The following drivers are incomplete: DAC. The following drivers
- are untested: DMA on the F4, CAN.
- Status: Open
- Priority: Medium
-
Title: F4 SDIO MULTI-BLOCK TRANSFER FAILURES
Description: If you use a large I/O buffer to access the file system, then the
MMCSD driver will perform multiple block SD transfers. With DMA
@@ -1412,13 +1450,15 @@ o ARM/STM32 (arch/arm/src/stm32/)
Status: Open
Priority: Low (I am not even sure if this is a problem yet).
- Status: UNFINISHED STM32 F4 OTG FS HOST DRIVER
- Description: A quick-n-dirty leverage of the the LPC17xx host driver was put into
- the STM32 source to support development of the STM32 F4 OTG FS host
- driver. It is non-functional and still waiting for STM32 F4 logic
- to be added. Don't use it!
+ Title: DMA FROM EXTERNAL, FSMC MEMORY
+ Description: I have seen a problem on F1 where all SDIO DMAs work exist for
+ write DMAs from FSMC memory (i.e., from FSMC memory to SDIO).
+ Read transfers work fine (SDIO to FSMC memory). The failure is
+ a data underrun error with zero bytes of data transferred. The
+ workaround for now is to use DMA buffers allocted from internal
+ SRAM.
Status: Open
- Priority: Low (unless you need a host driver).
+ Priority: Low
o AVR (arch/avr)
^^^^^^^^^^^^^^
@@ -1507,6 +1547,16 @@ o 8051 / MCS51 (arch/8051/)
Status: Open
Priority: Low -- only because there as so many other issues with 8051
+ Title: 8051 BUILD BROKEN
+ Description: The last time I tried to build the pjrc-8051 configurtion using
+ the SDCC 3.2.1 toolchain (for Windows). I got compilation
+ errors in sched/os_bringup.c. It complained about type
+ mis-matches. What I gather from Googling, this is a problem
+ with the --stack-auto option. At any rate, this problem will
+ need to be fixed if you want to resurrect the 8051 NuttX port.
+ Status: Open
+ Priority: Low -- I don't think anyone uses the 8051 port.
+
o MIPS/PIC32(arch/mips)
^^^^^^^^^^^^^^^^^^^^^
@@ -1835,9 +1885,17 @@ o z16 (arch/z16)
Internal Error(0503) On line 2504 of "MMCSD\MMCSD_SDIO.C"
File <c3>, Args(562,46)
- Status: Open. Recommended workaround: remove mmcsd_sdio.c from
- drivers/mmcsd/Make.defs. There is no SDIO support for the Z16 anyway
- Priority: Low
+ Status: Open. Recommended workaround: remove mmcsd_sdio.c from
+ drivers/mmcsd/Make.defs. There is no SDIO support for the Z16 anyway
+ Priority: Low
+
+ Title: NATIVE BUILD PROBLEMS
+ Description: When last tested (ca.12/12), there were some missing .obj files in
+ arch/z16/src. A little additional TLC will be needed to get a
+ reliable Windows native build. As of this writing, the Cygwin
+ based build has not been re-verified.
+ Status: Open
+ Priority: Low -- I don't think anyone uses the Z16 port.
o mc68hc1x (arch/hc)
^^^^^^^^^^^^^^^^^^
diff --git a/nuttx/arch/Kconfig b/nuttx/arch/Kconfig
index bbe99c17c..f19228143 100644
--- a/nuttx/arch/Kconfig
+++ b/nuttx/arch/Kconfig
@@ -9,6 +9,7 @@ choice
config ARCH_8051
bool "8051"
+ select CUSTOM_STACK
---help---
Intel 8051 architectures and derivaties
@@ -111,12 +112,30 @@ config ARCH_DMA
bool
default n
+config ARCH_IRQPRIO
+ bool
+ default n
+
+config CUSTOM_STACK
+ bool
+ default n
+
+config ADDRENV
+ bool
+ default n
+
config ARCH_STACKDUMP
bool "Dump stack on assertions"
default n
---help---
Enable to do stack dumps after assertions
+config ENDIAN_BIG
+ bool "Big Endian Architecture"
+ default n
+ ---help---
+ Select if architecture operates using big-endian byte ordering.
+
comment "Board Settings"
config BOARD_LOOPSPERMSEC
diff --git a/nuttx/arch/arm/Kconfig b/nuttx/arch/arm/Kconfig
index 2a7ea10b5..4fce8efbf 100644
--- a/nuttx/arch/arm/Kconfig
+++ b/nuttx/arch/arm/Kconfig
@@ -4,6 +4,8 @@
#
if ARCH_ARM
+comment "ARM Options"
+
choice
prompt "ARM chip selection"
default ARCH_CHIP_STM32
@@ -44,6 +46,7 @@ config ARCH_CHIP_KINETIS
bool "Freescale Kinetis"
select ARCH_CORTEXM4
select ARCH_HAVE_MPU
+ select ARCH_IRQPRIO
---help---
Freescale Kinetis Architectures (ARM Cortex-M4)
@@ -51,6 +54,7 @@ config ARCH_CHIP_LM3S
bool "TI Stellaris"
select ARCH_CORTEXM3
select ARCH_HAVE_MPU
+ select ARCH_IRQPRIO
---help---
TI Stellaris LMS3 architecutres (ARM Cortex-M3)
@@ -58,6 +62,7 @@ config ARCH_CHIP_LPC17XX
bool "NXP LPC17xx"
select ARCH_CORTEXM3
select ARCH_HAVE_MPU
+ select ARCH_IRQPRIO
---help---
NXP LPC17xx architectures (ARM Cortex-M3)
@@ -89,6 +94,7 @@ config ARCH_CHIP_LPC43XX
select ARCH_HAVE_CMNVECTOR
select ARMV7M_CMNVECTOR
select ARCH_HAVE_MPU
+ select ARCH_IRQPRIO
---help---
NPX LPC43XX architectures (ARM Cortex-M4).
@@ -96,6 +102,7 @@ config ARCH_CHIP_SAM3U
bool "Atmel AT91SAM3U"
select ARCH_CORTEXM3
select ARCH_HAVE_MPU
+ select ARCH_IRQPRIO
---help---
Atmel AT91SAM3U architectures (ARM Cortex-M3)
@@ -104,6 +111,7 @@ config ARCH_CHIP_STM32
select ARCH_HAVE_CMNVECTOR
select ARCH_HAVE_MPU
select ARCH_HAVE_I2CRESET
+ select ARCH_IRQPRIO
---help---
STMicro STM32 architectures (ARM Cortex-M3/4).
@@ -153,6 +161,9 @@ config ARCH_CHIP
default "stm32" if ARCH_CHIP_STM32
default "str71x" if ARCH_CHIP_STR71X
+config ARCH_HAVE_CMNVECTOR
+ bool
+
config ARMV7M_CMNVECTOR
bool "Use common ARMv7-M vectors"
default n
@@ -217,12 +228,6 @@ config PAGING
If set =y in your configation file, this setting will enable the on-demand
paging feature as described in http://www.nuttx.org/NuttXDemandPaging.html.
-config ARCH_IRQPRIO
- bool "Interrupt priority"
- default y if ARCH_CORTEXM3 || ARCH_CORTEXM4
- ---help---
- Select if your board supports interrupt prioritization.
-
config BOARD_LOOPSPERMSEC
int "Delay loops per millisecond"
default 5000
@@ -239,6 +244,21 @@ config ARCH_CALIBRATION
watch to measure the 100 second delay then adjust BOARD_LOOPSPERMSEC until
the delay actually is 100 seconds.
+config DEBUG_HARDFAULT
+ bool "Verbose Hard-Fault Debug"
+ default n
+ depends on DEBUG && (ARCH_CORTEXM3 || ARCH_CORTEXM4)
+ ---help---
+ Enables verbose debug output when a hard fault is occurs. This verbose
+ output is sometimes helpful when debugging difficult hard fault problems,
+ but may be more than you typcially want to see.
+
+if ARCH_CORTEXM3 || ARCH_CORTEXM4
+source arch/arm/src/armv7-m/Kconfig
+endif
+if ARCH_ARM7TDMI || ARCH_ARM926EJS
+source arch/arm/src/arm/Kconfig
+endif
if ARCH_CHIP_C5471
source arch/arm/src/c5471/Kconfig
endif
diff --git a/nuttx/arch/arm/include/elf.h b/nuttx/arch/arm/include/elf.h
new file mode 100644
index 000000000..21b2c1c2c
--- /dev/null
+++ b/nuttx/arch/arm/include/elf.h
@@ -0,0 +1,243 @@
+/****************************************************************************
+ * arch/arm/include/syscall.h
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * Reference: "ELF for the ARM® Architecture," ARM IHI 0044D, current through
+ * ABI release 2.08, October 28, 2009, ARM Limited.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+#ifndef __ARCH_ARM_INCLUDE_ELF_H
+#define __ARCH_ARM_INCLUDE_ELF_H
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* 4.3.1 ELF Identification. Should have:
+ *
+ * e_machine = EM_ARM
+ * e_ident[EI_CLASS] = ELFCLASS32
+ * e_ident[EI_DATA] = ELFDATA2LSB (little endian) or ELFDATA2MSB (big endian)
+ */
+
+#if 0 /* Defined in include/elf32.h */
+#define EM_ARM 40
+#endif
+
+/* Table 4-2, ARM-specific e_flags */
+
+#define EF_ARM_EABI_MASK 0xff000000
+#define EF_ARM_EABI_UNKNOWN 0x00000000
+#define EF_ARM_EABI_VER1 0x01000000
+#define EF_ARM_EABI_VER2 0x02000000
+#define EF_ARM_EABI_VER3 0x03000000
+#define EF_ARM_EABI_VER4 0x04000000
+#define EF_ARM_EABI_VER5 0x05000000
+
+#define EF_ARM_BE8 0x00800000
+
+/* Table 4-4, Processor specific section types */
+
+#define SHT_ARM_EXIDX 0x70000001 /* Exception Index table */
+#define SHT_ARM_PREEMPTMAP 0x70000002 /* BPABI DLL dynamic linking pre-emption map */
+#define SHT_ARM_ATTRIBUTES 0x70000003 /* Object file compatibility attributes */
+#define SHT_ARM_DEBUGOVERLAY 0x70000004
+#define SHT_ARM_OVERLAYSECTION 0x70000005
+
+/* 4.7.1 Relocation codes
+ *
+ * S (when used on its own) is the address of the symbol.
+ * A is the addend for the relocation.
+ * P is the address of the place being relocated (derived from r_offset).
+ * Pa is the adjusted address of the place being relocated, defined as (P & 0xFFFFFFFC).
+ * T is 1 if the target symbol S has type STT_FUNC and the symbol addresses a Thumb instruction;
+ * it is 0 otherwise.
+ * B(S) is the addressing origin of the output segment defining the symbol S.
+ * GOT_ORG is the addressing origin of the Global Offset Table
+ * GOT(S) is the address of the GOT entry for the symbol S.
+ */
+
+#define R_ARM_NONE 0 /* No relocation */
+#define R_ARM_PC24 1 /* ARM ((S + A) | T) - P */
+#define R_ARM_ABS32 2 /* Data (S + A) | T */
+#define R_ARM_REL32 3 /* Data ((S + A) | T) - P */
+#define R_ARM_LDR_PC_G0 4 /* ARM S + A - P */
+#define R_ARM_ABS16 5 /* Data S + A */
+#define R_ARM_ABS12 6 /* ARM S + A */
+#define R_ARM_THM_ABS5 7 /* Thumb16 S + A */
+#define R_ARM_ABS8 8 /* Data S + A */
+#define R_ARM_SBREL32 9 /* Data ((S + A) | T) - B(S) */
+#define R_ARM_THM_CALL 10 /* Thumb32 ((S + A) | T) - P */
+#define R_ARM_THM_PC8 11 /* Thumb16 S + A - Pa */
+#define R_ARM_BREL_ADJ 12 /* Data ?B(S) + A */
+#define R_ARM_TLS_DESC 13 /* Data */
+#define R_ARM_THM_SWI8 14 /* Obsolete */
+#define R_ARM_XPC25 15 /* Obsolete */
+#define R_ARM_THM_XPC22 16 /* Obsolete */
+#define R_ARM_TLS_DTPMOD32 17 /* Data Module[S] */
+#define R_ARM_TLS_DTPOFF32 18 /* Data S + A - TLS */
+#define R_ARM_TLS_TPOFF32 19 /* Data S + A - tp */
+#define R_ARM_COPY 20 /* Miscellaneous */
+#define R_ARM_GLOB_DAT 21 /* Data (S + A) | T */
+#define R_ARM_JUMP_SLOT 22 /* Data (S + A) | T */
+#define R_ARM_RELATIVE 23 /* Data B(S) + A */
+#define R_ARM_GOTOFF32 24 /* Data ((S + A) | T) - GOT_ORG */
+#define R_ARM_BASE_PREL 25 /* Data B(S) + A - P */
+#define R_ARM_GOT_BREL 26 /* Data GOT(S) + A - GOT_ORG */
+#define R_ARM_PLT32 27 /* ARM ((S + A) | T) - P */
+#define R_ARM_CALL 28 /* ARM ((S + A) | T) - P */
+#define R_ARM_JUMP24 29 /* ARM ((S + A) | T) - P */
+#define R_ARM_THM_JUMP24 30 /* Thumb32 ((S + A) | T) - P */
+#define R_ARM_BASE_ABS 31 /* Data B(S) + A */
+#define R_ARM_ALU_PCREL_7_0 32 /* Obsolete */
+#define R_ARM_ALU_PCREL_15_8 33 /* Obsolete */
+#define R_ARM_ALU_PCREL_23_15 34 /* Obsolete */
+#define R_ARM_LDR_SBREL_11_0_NC 35 /* ARM S + A - B(S) */
+#define R_ARM_ALU_SBREL_19_12_NC 36 /* ARM S + A - B(S) */
+#define R_ARM_ALU_SBREL_27_20_CK 37 /* ARM S + A - B(S) */
+#define R_ARM_TARGET1 38 /* Miscellaneous (S + A) | T or ((S + A) | T) - P */
+#define R_ARM_SBREL31 39 /* Data ((S + A) | T) - B(S) */
+#define R_ARM_V4BX 40 /* Miscellaneous */
+#define R_ARM_TARGET2 41 /* Miscellaneous */
+#define R_ARM_PREL31 42 /* Data ((S + A) | T) - P */
+#define R_ARM_MOVW_ABS_NC 43 /* ARM (S + A) | T */
+#define R_ARM_MOVT_ABS 44 /* ARM S + A */
+#define R_ARM_MOVW_PREL_NC 45 /* ARM ((S + A) | T) - P */
+#define R_ARM_MOVT_PREL 46 /* ARM S + A - P */
+#define R_ARM_THM_MOVW_ABS_NC 47 /* Thumb32 (S + A) | T */
+#define R_ARM_THM_MOVT_ABS 48 /* Thumb32 S + A */
+#define R_ARM_THM_MOVW_PREL_NC 49 /* Thumb32 ((S + A) | T) - P */
+#define R_ARM_THM_MOVT_PREL 50 /* Thumb32 S + A - P */
+#define R_ARM_THM_JUMP19 51 /* Thumb32 ((S + A) | T) - P */
+#define R_ARM_THM_JUMP6 52 /* Thumb16 S + A - P */
+#define R_ARM_THM_ALU_PREL_11_0 53 /* Thumb32 ((S + A) | T) - Pa */
+#define R_ARM_THM_PC12 54 /* Thumb32 S + A - Pa */
+#define R_ARM_ABS32_NOI 55 /* Data S + A */
+#define R_ARM_REL32_NOI 56 /* Data S + A - P */
+#define R_ARM_ALU_PC_G0_NC 57 /* ARM ((S + A) | T) - P */
+#define R_ARM_ALU_PC_G0 58 /* ARM ((S + A) | T) - P */
+#define R_ARM_ALU_PC_G1_NC 59 /* ARM ((S + A) | T) - P */
+#define R_ARM_ALU_PC_G1 60 /* ARM ((S + A) | T) - P */
+#define R_ARM_ALU_PC_G2 61 /* ARM ((S + A) | T) - P */
+#define R_ARM_LDR_PC_G1 62 /* ARM S + A - P */
+#define R_ARM_LDR_PC_G2 63 /* ARM S + A - P */
+#define R_ARM_LDRS_PC_G0 64 /* ARM S + A - P */
+#define R_ARM_LDRS_PC_G1 65 /* ARM S + A - P */
+#define R_ARM_LDRS_PC_G2 66 /* ARM S + A - P */
+#define R_ARM_LDC_PC_G0 67 /* ARM S + A - P */
+#define R_ARM_LDC_PC_G1 68 /* ARM S + A - P */
+#define R_ARM_LDC_PC_G2 69 /* ARM S + A - P */
+#define R_ARM_ALU_SB_G0_NC 70 /* ARM ((S + A) | T) - B(S) */
+#define R_ARM_ALU_SB_G0 71 /* ARM ((S + A) | T) - B(S) */
+#define R_ARM_ALU_SB_G1_NC 72 /* ARM ((S + A) | T) - B(S) */
+#define R_ARM_ALU_SB_G1 73 /* ARM ((S + A) | T) - B(S) */
+#define R_ARM_ALU_SB_G2 74 /* ARM ((S + A) | T) - B(S) */
+#define R_ARM_LDR_SB_G0 75 /* ARM S + A - B(S) */
+#define R_ARM_LDR_SB_G1 76 /* ARM S + A - B(S) */
+#define R_ARM_LDR_SB_G2 77 /* ARM S + A - B(S) */
+#define R_ARM_LDRS_SB_G0 78 /* ARM S + A - B(S) */
+#define R_ARM_LDRS_SB_G1 79 /* ARM S + A - B(S) */
+#define R_ARM_LDRS_SB_G2 80 /* ARM S + A - B(S) */
+#define R_ARM_LDC_SB_G0 81 /* ARM S + A - B(S) */
+#define R_ARM_LDC_SB_G1 82 /* ARM S + A - B(S) */
+#define R_ARM_LDC_SB_G2 83 /* ARM S + A - B(S) */
+#define R_ARM_MOVW_BREL_NC 84 /* ARM ((S + A) | T) - B(S) */
+#define R_ARM_MOVT_BREL 85 /* ARM S + A - B(S) */
+#define R_ARM_MOVW_BREL 86 /* ARM ((S + A) | T) - B(S) */
+#define R_ARM_THM_MOVW_BREL_NC 87 /* Thumb32 ((S + A) | T) - B(S) */
+#define R_ARM_THM_MOVT_BREL 88 /* Thumb32 S + A - B(S) */
+#define R_ARM_THM_MOVW_BREL 89 /* Thumb32 ((S + A) | T) - B(S) */
+#define R_ARM_TLS_GOTDESC 90 /* Data */
+#define R_ARM_TLS_CALL 91 /* ARM */
+#define R_ARM_TLS_DESCSEQ 92 /* ARM TLS relaxation */
+#define R_ARM_THM_TLS_CALL 93 /* Thumb32 */
+#define R_ARM_PLT32_ABS 94 /* Data PLT(S) + A */
+#define R_ARM_GOT_ABS 95 /* Data GOT(S) + A */
+#define R_ARM_GOT_PREL 96 /* Data GOT(S) + A - P */
+#define R_ARM_GOT_BREL12 97 /* ARM GOT(S) + A - GOT_ORG */
+#define R_ARM_GOTOFF12 98 /* ARM S + A - GOT_ORG */
+#define R_ARM_GOTRELAX 99 /* Miscellaneous */
+#define R_ARM_GNU_VTENTRY 100 /* Data */
+#define R_ARM_GNU_VTINHERIT 101 /* Data */
+#define R_ARM_THM_JUMP11 102 /* Thumb16 S + A - P */
+#define R_ARM_THM_JUMP8 103 /* Thumb16 S + A - P */
+#define R_ARM_TLS_GD32 104 /* Data GOT(S) + A - P */
+#define R_ARM_TLS_LDM32 105 /* Data GOT(S) + A - P */
+#define R_ARM_TLS_LDO32 106 /* Data S + A - TLS */
+#define R_ARM_TLS_IE32 107 /* Data GOT(S) + A - P */
+#define R_ARM_TLS_LE32 108 /* Data S + A - tp */
+#define R_ARM_TLS_LDO12 109 /* ARM S + A - TLS */
+#define R_ARM_TLS_LE12 110 /* ARM S + A - tp */
+#define R_ARM_TLS_IE12GP 111 /* ARM GOT(S) + A - GOT_ORG */
+#define R_ARM_ME_TOO 128 /* Obsolete */
+#define R_ARM_THM_TLS_DESCSEQ16 129 /* Thumb16 */
+#define R_ARM_THM_TLS_DESCSEQ32 130 /* Thumb32 */
+
+/* 5.2.1 Platform architecture compatibility data */
+
+#define PT_ARM_ARCHEXT_FMTMSK 0xff000000
+#define PT_ARM_ARCHEXT_PROFMSK 0x00ff0000
+#define PT_ARM_ARCHEXT_ARCHMSK 0x000000ff
+
+#define PT_ARM_ARCHEXT_FMT_OS 0x00000000
+#define PT_ARM_ARCHEXT_FMT_ABI 0x01000000
+
+#define PT_ARM_ARCHEXT_PROF_NONE 0x00000000
+#define PT_ARM_ARCHEXT_PROF_ARM 0x00410000
+#define PT_ARM_ARCHEXT_PROF_RT 0x00520000
+#define PT_ARM_ARCHEXT_PROF_MC 0x004d0000
+#define PT_ARM_ARCHEXT_PROF_CLASSIC 0x00530000
+
+#define PT_ARM_ARCHEXT_ARCH_UNKNOWN 0x00
+#define PT_ARM_ARCHEXT_ARCHv4 0x01
+#define PT_ARM_ARCHEXT_ARCHv4T 0x02
+#define PT_ARM_ARCHEXT_ARCHv5T 0x03
+#define PT_ARM_ARCHEXT_ARCHv5TE 0x04
+#define PT_ARM_ARCHEXT_ARCHv5TEJ 0x05
+#define PT_ARM_ARCHEXT_ARCHv6 0x06
+#define PT_ARM_ARCHEXT_ARCHv6KZ 0x07
+#define PT_ARM_ARCHEXT_ARCHv6T2 0x08
+#define PT_ARM_ARCHEXT_ARCHv6K 0x09
+#define PT_ARM_ARCHEXT_ARCHv7 0x0a
+#define PT_ARM_ARCHEXT_ARCHv6M 0x0b
+#define PT_ARM_ARCHEXT_ARCHv6SM 0x0c
+#define PT_ARM_ARCHEXT_ARCHv7EM 0x0d
+
+/* Table 5-6, ARM-specific dynamic array tags */
+
+#define DT_ARM_RESERVED1 0x70000000
+#define DT_ARM_SYMTABSZ 0x70000001
+#define DT_ARM_PREEMPTMAP 0x70000002
+#define DT_ARM_RESERVED2 0x70000003
+
+#endif /* __ARCH_ARM_INCLUDE_ELF_H */
diff --git a/nuttx/arch/arm/include/stm32/chip.h b/nuttx/arch/arm/include/stm32/chip.h
index d01929e1c..d34c2eb4f 100644
--- a/nuttx/arch/arm/include/stm32/chip.h
+++ b/nuttx/arch/arm/include/stm32/chip.h
@@ -59,12 +59,11 @@
/* STM32 F100 Value Line ************************************************************/
#if defined(CONFIG_ARCH_CHIP_STM32F100C8) || defined(CONFIG_ARCH_CHIP_STM32F100CB) \
- || defined(CONFIG_ARCH_CHIP_STM32F100R8) || defined(CONFIG_ARCH_CHIP_STM32F100RB) \
- || defined(CONFIG_ARCH_CHIP_STM32F100V8) || defined(CONFIG_ARCH_CHIP_STM32F100VB)
+ || defined(CONFIG_ARCH_CHIP_STM32F100R8) || defined(CONFIG_ARCH_CHIP_STM32F100RB)
# define CONFIG_STM32_STM32F10XX 1 /* STM32F10xxx family */
-# undef CONFIG_STM32_LOWDENSITY /* STM32F100x, STM32F102x and STM32F103x w/ 16/32 Kbytes */
-# define CONFIG_STM32_MEDIUMDENSITY 1 /* STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */
-# undef CONFIG_STM32_HIGHDENSITY /* STM32F101x and STM32F103x w/ 256/512 Kbytes */
+# undef CONFIG_STM32_LOWDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */
+# define CONFIG_STM32_MEDIUMDENSITY 1 /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */
+# undef CONFIG_STM32_HIGHDENSITY /* STM32F100x, STM32F101x, and STM32F103x w/ 256/512 Kbytes */
# define CONFIG_STM32_VALUELINE 1 /* STM32F100x */
# undef CONFIG_STM32_CONNECTIVITYLINE /* STM32F105x and STM32F107x */
# undef CONFIG_STM32_STM32F20XX /* STM32F205x and STM32F207x */
@@ -72,10 +71,41 @@
# define STM32_NFSMC 0 /* FSMC */
# define STM32_NATIM 1 /* One advanced timer TIM1 */
# define STM32_NGTIM 3 /* 16-bit general timers TIM2,3,4 with DMA */
-# define STM32_NBTIM 0 /* No basic timers */
-# define STM32_NDMA 2 /* DMA1-2 */
+# define STM32_NBTIM 2 /* 2 basic timers: TIM6, TIM7 */
+// TODO: there are also 3 additional timers (15-17) that don't fit any existing category
+# define STM32_NDMA 1 /* DMA1 */
# define STM32_NSPI 2 /* SPI1-2 */
-# define STM32_NI2S 0 /* No I2S (?) */
+# define STM32_NI2S 0 /* No I2S */
+# define STM32_NUSART 3 /* USART1-3 */
+# define STM32_NI2C 2 /* I2C1-2 */
+# define STM32_NCAN 0 /* No CAN */
+# define STM32_NSDIO 0 /* No SDIO */
+# define STM32_NUSBOTG 0 /* No USB OTG FS/HS */
+# define STM32_NGPIO 64 /* GPIOA-D */
+# define STM32_NADC 1 /* ADC1 */
+# define STM32_NDAC 2 /* DAC 1-2 */
+# define STM32_NCRC 1 /* CRC1 */
+# define STM32_NETHERNET 0 /* No ethernet */
+# define STM32_NRNG 0 /* No random number generator (RNG) */
+# define STM32_NDCMI 0 /* No digital camera interface (DCMI) */
+
+#elif defined(CONFIG_ARCH_CHIP_STM32F100V8) || defined(CONFIG_ARCH_CHIP_STM32F100VB)
+# define CONFIG_STM32_STM32F10XX 1 /* STM32F10xxx family */
+# undef CONFIG_STM32_LOWDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */
+# define CONFIG_STM32_MEDIUMDENSITY 1 /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */
+# undef CONFIG_STM32_HIGHDENSITY /* STM32F100x, STM32F101x, and STM32F103x w/ 256/512 Kbytes */
+# define CONFIG_STM32_VALUELINE 1 /* STM32F100x */
+# undef CONFIG_STM32_CONNECTIVITYLINE /* STM32F105x and STM32F107x */
+# undef CONFIG_STM32_STM32F20XX /* STM32F205x and STM32F207x */
+# undef CONFIG_STM32_STM32F40XX /* STM32F405xx and STM32407xx families */
+# define STM32_NFSMC 0 /* FSMC */
+# define STM32_NATIM 1 /* One advanced timer TIM1 */
+# define STM32_NGTIM 3 /* 16-bit general timers TIM2,3,4 with DMA */
+# define STM32_NBTIM 2 /* 2 basic timers: TIM6, TIM7 */
+// TODO: there are also 3 additional timers (15-17) that don't fit any existing category
+# define STM32_NDMA 1 /* DMA1 */
+# define STM32_NSPI 2 /* SPI1-2 */
+# define STM32_NI2S 0 /* No I2S */
# define STM32_NUSART 3 /* USART1-3 */
# define STM32_NI2C 2 /* I2C1-2 */
# define STM32_NCAN 0 /* No CAN */
@@ -89,6 +119,70 @@
# define STM32_NRNG 0 /* No random number generator (RNG) */
# define STM32_NDCMI 0 /* No digital camera interface (DCMI) */
+/* STM32 F100 High-density value Line ************************************************************/
+
+#elif defined(CONFIG_ARCH_CHIP_STM32F100RC) || defined(CONFIG_ARCH_CHIP_STM32F100RD) \
+ || defined(CONFIG_ARCH_CHIP_STM32F100RE)
+# define CONFIG_STM32_STM32F10XX 1 /* STM32F10xxx family */
+# undef CONFIG_STM32_LOWDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */
+# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */
+# define CONFIG_STM32_HIGHDENSITY 1 /* STM32F100x, STM32F101x, and STM32F103x w/ 256/512 Kbytes */
+# define CONFIG_STM32_VALUELINE 1 /* STM32F100x */
+# undef CONFIG_STM32_CONNECTIVITYLINE /* STM32F105x and STM32F107x */
+# undef CONFIG_STM32_STM32F20XX /* STM32F205x and STM32F207x */
+# undef CONFIG_STM32_STM32F40XX /* STM32F405xx and STM32407xx families */
+# define STM32_NFSMC 0 /* FSMC */
+# define STM32_NATIM 1 /* One advanced timer TIM1 */
+# define STM32_NGTIM 4 /* 16-bit general timers TIM2,3,4,5 with DMA */
+# define STM32_NBTIM 2 /* 2 basic timers: TIM6, TIM7 */
+// TODO: there are also 6 additional timers (12-17) that don't fit any existing category
+# define STM32_NDMA 2 /* DMA1-2 */
+# define STM32_NSPI 3 /* SPI1-3 */
+# define STM32_NI2S 0 /* No I2S */
+# define STM32_NUSART 5 /* USART1-5 */
+# define STM32_NI2C 2 /* I2C1-2 */
+# define STM32_NCAN 0 /* No CAN */
+# define STM32_NSDIO 0 /* No SDIO */
+# define STM32_NUSBOTG 0 /* No USB OTG FS/HS */
+# define STM32_NGPIO 64 /* GPIOA-D */
+# define STM32_NADC 1 /* ADC1 */
+# define STM32_NDAC 2 /* DAC 1-2 */
+# define STM32_NCRC 1 /* CRC1 */
+# define STM32_NETHERNET 0 /* No ethernet */
+# define STM32_NRNG 0 /* No random number generator (RNG) */
+# define STM32_NDCMI 0 /* No digital camera interface (DCMI) */
+
+#elif defined(CONFIG_ARCH_CHIP_STM32F100VC) || defined(CONFIG_ARCH_CHIP_STM32F100VD) \
+ || defined(CONFIG_ARCH_CHIP_STM32F100VE)
+# define CONFIG_STM32_STM32F10XX 1 /* STM32F10xxx family */
+# undef CONFIG_STM32_LOWDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */
+# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */
+# define CONFIG_STM32_HIGHDENSITY 1 /* STM32F100x, STM32F101x, and STM32F103x w/ 256/512 Kbytes */
+# define CONFIG_STM32_VALUELINE 1 /* STM32F100x */
+# undef CONFIG_STM32_CONNECTIVITYLINE /* STM32F105x and STM32F107x */
+# undef CONFIG_STM32_STM32F20XX /* STM32F205x and STM32F207x */
+# undef CONFIG_STM32_STM32F40XX /* STM32F405xx and STM32407xx families */
+# define STM32_NFSMC 1 /* FSMC */
+# define STM32_NATIM 1 /* One advanced timer TIM1 */
+# define STM32_NGTIM 4 /* 16-bit general timers TIM2,3,4,5 with DMA */
+# define STM32_NBTIM 2 /* 2 basic timers: TIM6, TIM7 */
+// TODO: there are also 6 additional timers (12-17) that don't fit any existing category
+# define STM32_NDMA 2 /* DMA1-2 */
+# define STM32_NSPI 3 /* SPI1-3 */
+# define STM32_NI2S 0 /* No I2S */
+# define STM32_NUSART 5 /* USART1-5 */
+# define STM32_NI2C 2 /* I2C1-2 */
+# define STM32_NCAN 0 /* No CAN */
+# define STM32_NSDIO 0 /* No SDIO */
+# define STM32_NUSBOTG 0 /* No USB OTG FS/HS */
+# define STM32_NGPIO 80 /* GPIOA-E */
+# define STM32_NADC 1 /* ADC1 */
+# define STM32_NDAC 2 /* DAC 1-2 */
+# define STM32_NCRC 1 /* CRC1 */
+# define STM32_NETHERNET 0 /* No ethernet */
+# define STM32_NRNG 0 /* No random number generator (RNG) */
+# define STM32_NDCMI 0 /* No digital camera interface (DCMI) */
+
/* STM32 F103 High Density Family ***************************************************/
/* STM32F103RC, STM32F103RD, and STM32F103RE are all provided in 64 pin packages and differ
* only in the available FLASH and SRAM.
@@ -96,9 +190,9 @@
#elif defined(CONFIG_ARCH_CHIP_STM32F103RET6)
# define CONFIG_STM32_STM32F10XX 1 /* STM32F10xxx family */
-# undef CONFIG_STM32_LOWDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */
-# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */
-# define CONFIG_STM32_HIGHDENSITY 1 /* STM32F101x and STM32F103x w/ 256/512 Kbytes */
+# undef CONFIG_STM32_LOWDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */
+# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */
+# define CONFIG_STM32_HIGHDENSITY 1 /* STM32F100x, STM32F101x, and STM32F103x w/ 256/512 Kbytes */
# undef CONFIG_STM32_VALUELINE /* STM32F100x */
# undef CONFIG_STM32_CONNECTIVITYLINE /* STM32F105x and STM32F107x */
# undef CONFIG_STM32_STM32F20XX /* STM32F205x and STM32F207x */
@@ -129,9 +223,9 @@
#elif defined(CONFIG_ARCH_CHIP_STM32F103VCT6) || defined(CONFIG_ARCH_CHIP_STM32F103VET6)
# define CONFIG_STM32_STM32F10XX 1 /* STM32F10xxx family */
-# undef CONFIG_STM32_LOWDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */
-# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */
-# define CONFIG_STM32_HIGHDENSITY 1 /* STM32F101x and STM32F103x w/ 256/512 Kbytes */
+# undef CONFIG_STM32_LOWDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */
+# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */
+# define CONFIG_STM32_HIGHDENSITY 1 /* STM32F100x, STM32F101x, and STM32F103x w/ 256/512 Kbytes */
# undef CONFIG_STM32_VALUELINE /* STM32F100x */
# undef CONFIG_STM32_CONNECTIVITYLINE /* STM32F105x and STM32F107x */
# undef CONFIG_STM32_STM32F20XX /* STM32F205x and STM32F207x */
@@ -162,9 +256,9 @@
#elif defined(CONFIG_ARCH_CHIP_STM32F103ZET6)
# define CONFIG_STM32_STM32F10XX 1 /* STM32F10xxx family */
-# undef CONFIG_STM32_LOWDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */
-# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */
-# define CONFIG_STM32_HIGHDENSITY 1 /* STM32F101x and STM32F103x w/ 256/512 Kbytes */
+# undef CONFIG_STM32_LOWDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */
+# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */
+# define CONFIG_STM32_HIGHDENSITY 1 /* STM32F100x, STM32F101x, and STM32F103x w/ 256/512 Kbytes */
# undef CONFIG_STM32_VALUELINE /* STM32F100x */
# undef CONFIG_STM32_CONNECTIVITYLINE /* STM32F105x and STM32F107x */
# undef CONFIG_STM32_STM32F20XX /* STM32F205x and STM32F207x */
@@ -192,9 +286,9 @@
/* STM32 F105/F107 Connectivity Line *******************************************************/
#elif defined(CONFIG_ARCH_CHIP_STM32F105VBT7)
# define CONFIG_STM32_STM32F10XX 1 /* STM32F10xxx family */
-# undef CONFIG_STM32_LOWDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */
-# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */
-# undef CONFIG_STM32_HIGHDENSITY /* STM32F101x and STM32F103x w/ 256/512 Kbytes */
+# undef CONFIG_STM32_LOWDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */
+# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */
+# undef CONFIG_STM32_HIGHDENSITY /* STM32F100x, STM32F101x, and STM32F103x w/ 256/512 Kbytes */
# undef CONFIG_STM32_VALUELINE /* STM32F100x */
# define CONFIG_STM32_CONNECTIVITYLINE 1 /* STM32F105x and STM32F107x */
# undef CONFIG_STM32_STM32F20XX /* STM32F205x and STM32F207x */
@@ -221,9 +315,9 @@
#elif defined(CONFIG_ARCH_CHIP_STM32F107VC)
# define CONFIG_STM32_STM32F10XX 1 /* STM32F10xxx family */
-# undef CONFIG_STM32_LOWDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */
-# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */
-# undef CONFIG_STM32_HIGHDENSITY /* STM32F101x and STM32F103x w/ 256/512 Kbytes */
+# undef CONFIG_STM32_LOWDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */
+# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */
+# undef CONFIG_STM32_HIGHDENSITY /* STM32F100x, STM32F101x, and STM32F103x w/ 256/512 Kbytes */
# undef CONFIG_STM32_VALUELINE /* STM32F100x */
# define CONFIG_STM32_CONNECTIVITYLINE 1 /* STM32F105x and STM32F107x */
# undef CONFIG_STM32_STM32F20XX /* STM32F205x and STM32F207x */
@@ -251,9 +345,9 @@
/* STM32 F2 Family ******************************************************************/
#elif defined(CONFIG_ARCH_CHIP_STM32F207IG) /* UFBGA-176 1024Kb FLASH 128Kb SRAM */
# undef CONFIG_STM32_STM32F10XX /* STM32F10xxx family */
-# undef CONFIG_STM32_LOWDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */
-# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */
-# undef CONFIG_STM32_HIGHDENSITY /* STM32F101x and STM32F103x w/ 256/512 Kbytes */
+# undef CONFIG_STM32_LOWDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */
+# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */
+# undef CONFIG_STM32_HIGHDENSITY /* STM32F100x, STM32F101x, and STM32F103x w/ 256/512 Kbytes */
# undef CONFIG_STM32_VALUELINE /* STM32F100x */
# undef CONFIG_STM32_CONNECTIVITYLINE /* STM32F105x and STM32F107x */
# define CONFIG_STM32_STM32F20XX 1 /* STM32F205x and STM32F207x */
@@ -283,9 +377,9 @@
/* STM23 F4 Family ******************************************************************/
#elif defined(CONFIG_ARCH_CHIP_STM32F405RG) /* LQFP 64 10x10x1.4 1024Kb FLASH 192Kb SRAM */
# undef CONFIG_STM32_STM32F10XX /* STM32F10xxx family */
-# undef CONFIG_STM32_LOWDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */
-# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */
-# undef CONFIG_STM32_HIGHDENSITY /* STM32F101x and STM32F103x w/ 256/512 Kbytes */
+# undef CONFIG_STM32_LOWDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */
+# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */
+# undef CONFIG_STM32_HIGHDENSITY /* STM32F100x, STM32F101x, and STM32F103x w/ 256/512 Kbytes */
# undef CONFIG_STM32_VALUELINE /* STM32F100x */
# undef CONFIG_STM32_CONNECTIVITYLINE /* STM32F105x and STM32F107x */
# undef CONFIG_STM32_STM32F20XX /* STM32F205x and STM32F207x */
@@ -314,9 +408,9 @@
#elif defined(CONFIG_ARCH_CHIP_STM32F405VG) /* LQFP 100 14x14x1.4 1024Kb FLASH 192Kb SRAM */
# undef CONFIG_STM32_STM32F10XX /* STM32F10xxx family */
-# undef CONFIG_STM32_LOWDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */
-# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */
-# undef CONFIG_STM32_HIGHDENSITY /* STM32F101x and STM32F103x w/ 256/512 Kbytes */
+# undef CONFIG_STM32_LOWDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */
+# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */
+# undef CONFIG_STM32_HIGHDENSITY /* STM32F100x, STM32F101x, and STM32F103x w/ 256/512 Kbytes */
# undef CONFIG_STM32_VALUELINE /* STM32F100x */
# undef CONFIG_STM32_CONNECTIVITYLINE /* STM32F105x and STM32F107x */
# undef CONFIG_STM32_STM32F20XX /* STM32F205x and STM32F207x */
@@ -345,9 +439,9 @@
#elif defined(CONFIG_ARCH_CHIP_STM32F405ZG) /* LQFP 144 20x20x1.4 1024Kb FLASH 192Kb SRAM */
# undef CONFIG_STM32_STM32F10XX /* STM32F10xxx family */
-# undef CONFIG_STM32_LOWDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */
-# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */
-# undef CONFIG_STM32_HIGHDENSITY /* STM32F101x and STM32F103x w/ 256/512 Kbytes */
+# undef CONFIG_STM32_LOWDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */
+# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */
+# undef CONFIG_STM32_HIGHDENSITY /* STM32F100x, STM32F101x, and STM32F103x w/ 256/512 Kbytes */
# undef CONFIG_STM32_VALUELINE /* STM32F100x */
# undef CONFIG_STM32_CONNECTIVITYLINE /* STM32F105x and STM32F107x */
# undef CONFIG_STM32_STM32F20XX /* STM32F205x and STM32F207x */
@@ -376,9 +470,9 @@
#elif defined(CONFIG_ARCH_CHIP_STM32F407VE) /* LQFP-100 512Kb FLASH 192Kb SRAM */
# undef CONFIG_STM32_STM32F10XX /* STM32F10xxx family */
-# undef CONFIG_STM32_LOWDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */
-# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */
-# undef CONFIG_STM32_HIGHDENSITY /* STM32F101x and STM32F103x w/ 256/512 Kbytes */
+# undef CONFIG_STM32_LOWDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */
+# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */
+# undef CONFIG_STM32_HIGHDENSITY /* STM32F100x, STM32F101x, and STM32F103x w/ 256/512 Kbytes */
# undef CONFIG_STM32_VALUELINE /* STM32F100x */
# undef CONFIG_STM32_CONNECTIVITYLINE /* STM32F105x and STM32F107x */
# undef CONFIG_STM32_STM32F20XX /* STM32F205x and STM32F207x */
@@ -407,9 +501,9 @@
#elif defined(CONFIG_ARCH_CHIP_STM32F407VG) /* LQFP-100 14x14x1.4 1024Kb FLASH 192Kb SRAM */
# undef CONFIG_STM32_STM32F10XX /* STM32F10xxx family */
-# undef CONFIG_STM32_LOWDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */
-# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */
-# undef CONFIG_STM32_HIGHDENSITY /* STM32F101x and STM32F103x w/ 256/512 Kbytes */
+# undef CONFIG_STM32_LOWDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */
+# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */
+# undef CONFIG_STM32_HIGHDENSITY /* STM32F100x, STM32F101x, and STM32F103x w/ 256/512 Kbytes */
# undef CONFIG_STM32_VALUELINE /* STM32F100x */
# undef CONFIG_STM32_CONNECTIVITYLINE /* STM32F105x and STM32F107x */
# undef CONFIG_STM32_STM32F20XX /* STM32F205x and STM32F207x */
@@ -438,9 +532,9 @@
#elif defined(CONFIG_ARCH_CHIP_STM32F407ZE) /* LQFP-144 512Kb FLASH 192Kb SRAM */
# undef CONFIG_STM32_STM32F10XX /* STM32F10xxx family */
-# undef CONFIG_STM32_LOWDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */
-# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */
-# undef CONFIG_STM32_HIGHDENSITY /* STM32F101x and STM32F103x w/ 256/512 Kbytes */
+# undef CONFIG_STM32_LOWDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */
+# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */
+# undef CONFIG_STM32_HIGHDENSITY /* STM32F100x, STM32F101x, and STM32F103x w/ 256/512 Kbytes */
# undef CONFIG_STM32_VALUELINE /* STM32F100x */
# undef CONFIG_STM32_CONNECTIVITYLINE /* STM32F105x and STM32F107x */
# undef CONFIG_STM32_STM32F20XX /* STM32F205x and STM32F207x */
@@ -469,9 +563,9 @@
#elif defined(CONFIG_ARCH_CHIP_STM32F407ZG) /* LQFP 144 20x20x1.4 1024Kb FLASH 192Kb SRAM */
# undef CONFIG_STM32_STM32F10XX /* STM32F10xxx family */
-# undef CONFIG_STM32_LOWDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */
-# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */
-# undef CONFIG_STM32_HIGHDENSITY /* STM32F101x and STM32F103x w/ 256/512 Kbytes */
+# undef CONFIG_STM32_LOWDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */
+# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */
+# undef CONFIG_STM32_HIGHDENSITY /* STM32F100x, STM32F101x, and STM32F103x w/ 256/512 Kbytes */
# undef CONFIG_STM32_VALUELINE /* STM32F100x */
# undef CONFIG_STM32_CONNECTIVITYLINE /* STM32F105x and STM32F107x */
# undef CONFIG_STM32_STM32F20XX /* STM32F205x and STM32F207x */
@@ -500,9 +594,9 @@
#elif defined(CONFIG_ARCH_CHIP_STM32F407IE) /* LQFP 176 24x24x1.4 512Kb FLASH 192Kb SRAM */
# undef CONFIG_STM32_STM32F10XX /* STM32F10xxx family */
-# undef CONFIG_STM32_LOWDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */
-# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */
-# undef CONFIG_STM32_HIGHDENSITY /* STM32F101x and STM32F103x w/ 256/512 Kbytes */
+# undef CONFIG_STM32_LOWDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */
+# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */
+# undef CONFIG_STM32_HIGHDENSITY /* STM32F100x, STM32F101x, and STM32F103x w/ 256/512 Kbytes */
# undef CONFIG_STM32_VALUELINE /* STM32F100x */
# undef CONFIG_STM32_CONNECTIVITYLINE /* STM32F105x and STM32F107x */
# undef CONFIG_STM32_STM32F20XX /* STM32F205x and STM32F207x */
@@ -531,9 +625,9 @@
#elif defined(CONFIG_ARCH_CHIP_STM32F407IG) /* BGA 176; LQFP 176 24x24x1.4 1024Kb FLASH 192Kb SRAM */
# undef CONFIG_STM32_STM32F10XX /* STM32F10xxx family */
-# undef CONFIG_STM32_LOWDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */
-# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */
-# undef CONFIG_STM32_HIGHDENSITY /* STM32F101x and STM32F103x w/ 256/512 Kbytes */
+# undef CONFIG_STM32_LOWDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */
+# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */
+# undef CONFIG_STM32_HIGHDENSITY /* STM32F100x, STM32F101x, and STM32F103x w/ 256/512 Kbytes */
# undef CONFIG_STM32_VALUELINE /* STM32F100x */
# undef CONFIG_STM32_CONNECTIVITYLINE /* STM32F105x and STM32F107x */
# undef CONFIG_STM32_STM32F20XX /* STM32F205x and STM32F207x */
diff --git a/nuttx/arch/arm/include/stm32/stm32f10xxx_irq.h b/nuttx/arch/arm/include/stm32/stm32f10xxx_irq.h
index 67f4ba436..7c3f7cf95 100644
--- a/nuttx/arch/arm/include/stm32/stm32f10xxx_irq.h
+++ b/nuttx/arch/arm/include/stm32/stm32f10xxx_irq.h
@@ -61,11 +61,13 @@
* External interrupts (vectors >= 16)
*/
-#if defined(CONFIG_STM32_VALUELINE) && defined(CONFIG_STM32_MEDIUMDENSITY)
+ /* Value line devices */
+
+#if defined(CONFIG_STM32_VALUELINE)
# define STM32_IRQ_WWDG (16) /* 0: Window Watchdog interrupt */
# define STM32_IRQ_PVD (17) /* 1: PVD through EXTI Line detection interrupt */
# define STM32_IRQ_TAMPER (18) /* 2: Tamper interrupt */
-# define STM32_IRQ_RTC (19) /* 3: RTC global interrupt */
+# define STM32_IRQ_RTC (19) /* 3: RTC Wakeup through EXTI line interrupt */
# define STM32_IRQ_FLASH (20) /* 4: Flash global interrupt */
# define STM32_IRQ_RCC (21) /* 5: RCC global interrupt */
# define STM32_IRQ_EXTI0 (22) /* 6: EXTI Line 0 interrupt */
@@ -80,12 +82,18 @@
# define STM32_IRQ_DMA1CH5 (31) /* 15: DMA1 Channel 5 global interrupt */
# define STM32_IRQ_DMA1CH6 (32) /* 16: DMA1 Channel 6 global interrupt */
# define STM32_IRQ_DMA1CH7 (33) /* 17: DMA1 Channel 7 global interrupt */
-# define STM32_IRQ_ADC12 (34) /* 18: ADC1 and ADC2 global interrupt */
- /* 19-22: reserved */
+# define STM32_IRQ_ADC1 (34) /* 18: ADC1 global interrupt */
+# define STM32_IRQ_RESERVED0 (35) /* 19: Reserved 0 */
+# define STM32_IRQ_RESERVED1 (36) /* 20: Reserved 1 */
+# define STM32_IRQ_RESERVED2 (37) /* 21: Reserved 2 */
+# define STM32_IRQ_RESERVED3 (38) /* 22: Reserved 3 */
# define STM32_IRQ_EXTI95 (39) /* 23: EXTI Line[9:5] interrupts */
# define STM32_IRQ_TIM1BRK (40) /* 24: TIM1 Break interrupt */
-# define STM32_IRQ_TIM1UP (41) /* 25: TIM1 Update interrupt (TIM16 global interrupt) */
-# define STM32_IRQ_TIM1TRGCOM (42) /* 26: TIM1 Trigger and Commutation interrupts (TIM17 global interrupt) */
+# define STM32_IRQ_TIM15 (40) /* TIM15 global interrupt */
+# define STM32_IRQ_TIM1UP (41) /* 25: TIM1 Update interrupt */
+# define STM32_IRQ_TIM16 (41) /* TIM16 global interrupt */
+# define STM32_IRQ_TIM1TRGCOM (42) /* 26: TIM1 Trigger and Commutation interrupts */
+# define STM32_IRQ_TIM17 (42) /* TIM17 global interrupt */
# define STM32_IRQ_TIM1CC (43) /* 27: TIM1 Capture Compare interrupt */
# define STM32_IRQ_TIM2 (44) /* 28: TIM2 global interrupt */
# define STM32_IRQ_TIM3 (45) /* 29: TIM3 global interrupt */
@@ -100,29 +108,30 @@
# define STM32_IRQ_USART2 (54) /* 38: USART2 global interrupt */
# define STM32_IRQ_USART3 (55) /* 39: USART3 global interrupt */
# define STM32_IRQ_EXTI1510 (56) /* 40: EXTI Line[15:10] interrupts */
-# define STM32_IRQ_RTCALR (57) /* 41: RTC alarm through EXTI line interrupt */
+# define STM32_IRQ_RTCALR (57) /* 41: RTC alarms (A and B) through EXTI line interrupt */
# define STM32_IRQ_CEC (58) /* 42: CEC global interrupt */
-# if defined(CONFIG_STM32_HIGHDENSITY)
-# define STM32_IRQ_TIM12 (59) /* 43: TIM12 global interrupt */
-# define STM32_IRQ_TIM13 (60) /* 44: TIM13 global interrupt */
-# define STM32_IRQ_TIM14 (61) /* 45: TIM14 global interrupt */
- /* 46-47: reserved */
-# define STM32_IRQ_FSMC (64) /* 48: FSMC global interrupt */
- /* 49: reserved */
-# define STM32_IRQ_TIM5 (66) /* 50: TIM5 global interrupt */
-# define STM32_IRQ_SPI3 (67) /* 51: SPI1 global interrupt */
-# define STM32_IRQ_UART4 (68) /* 52: USART2 global interrupt */
-# define STM32_IRQ_UART5 (69) /* 53: USART3 global interrupt */
-# else
- /* 43-53: reserved */
-# endif
+# define STM32_IRQ_TIM12 (59) /* 43: TIM12 global interrupt */
+# define STM32_IRQ_TIM13 (60) /* 44: TIM13 global interrupt */
+# define STM32_IRQ_TIM14 (61) /* 45: TIM14 global interrupt */
+# define STM32_IRQ_RESERVED4 (62) /* 46: Reserved 4 */
+# define STM32_IRQ_RESERVED5 (63) /* 47: Reserved 5 */
+# define STM32_IRQ_FSMC (64) /* 48: FSMC global interrupt */
+# define STM32_IRQ_RESERVED6 (65) /* 49: Reserved 6 */
+# define STM32_IRQ_TIM5 (66) /* 50: TIM5 global interrupt */
+# define STM32_IRQ_SPI3 (67) /* 51: SPI3 global interrupt */
+# define STM32_IRQ_UART4 (68) /* 52: USART2 global interrupt */
+# define STM32_IRQ_UART5 (69) /* 53: USART5 global interrupt */
# define STM32_IRQ_TIM6 (70) /* 54: TIM6 global interrupt */
# define STM32_IRQ_TIM7 (71) /* 55: TIM7 global interrupt */
# define STM32_IRQ_DMA2CH1 (72) /* 56: DMA2 Channel 1 global interrupt */
# define STM32_IRQ_DMA2CH2 (73) /* 57: DMA2 Channel 2 global interrupt */
# define STM32_IRQ_DMA2CH3 (74) /* 58: DMA2 Channel 3 global interrupt */
-# define STM32_IRQ_DMA2CH45 (75) /* 59: DMA2 Channel 4 global interrupt */
-# define NR_IRQS (76)
+# define STM32_IRQ_DMA2CH45 (75) /* 59: DMA2 Channel 4 and 5 global interrupt */
+# define STM32_IRQ_DMA2CH5 (76) /* 60: DMA2 Channel 5 global interrupt */
+# define NR_IRQS (77)
+
+/* Connectivity Line Devices */
+
#elif defined(CONFIG_STM32_CONNECTIVITYLINE)
# define STM32_IRQ_WWDG (16) /* 0: Window Watchdog interrupt */
# define STM32_IRQ_PVD (17) /* 1: PVD through EXTI Line detection interrupt */
@@ -193,6 +202,9 @@
# define STM32_IRQ_CAN2SCE (82) /* 66: CAN2 SCE interrupt */
# define STM32_IRQ_OTGFS (83) /* 67: USB On The Go FS global interrupt */
# define NR_IRQS (84)
+
+/* Medium and High Density Devices */
+
#else
# define STM32_IRQ_WWDG (16) /* 0: Window Watchdog interrupt */
# define STM32_IRQ_PVD (17) /* 1: PVD through EXTI Line detection interrupt */
diff --git a/nuttx/arch/arm/src/Makefile b/nuttx/arch/arm/src/Makefile
index 74be6c18d..e44def30c 100644
--- a/nuttx/arch/arm/src/Makefile
+++ b/nuttx/arch/arm/src/Makefile
@@ -36,58 +36,90 @@
-include $(TOPDIR)/Make.defs
-include chip/Make.defs
-ARCH_SRCDIR = $(TOPDIR)/arch/$(CONFIG_ARCH)/src
ifeq ($(CONFIG_ARCH_CORTEXM3),y) # Cortex-M3 is ARMv7-M
-ARCH_SUBDIR = armv7-m
+ARCH_SUBDIR = armv7-m
else
ifeq ($(CONFIG_ARCH_CORTEXM4),y) # Cortex-M4 is ARMv7E-M
-ARCH_SUBDIR = armv7-m
+ARCH_SUBDIR = armv7-m
else
-ARCH_SUBDIR = arm
+ARCH_SUBDIR = arm
endif
endif
+ifeq ($(CONFIG_WINDOWS_NATIVE),y)
+ ARCH_SRCDIR = $(TOPDIR)\arch\$(CONFIG_ARCH)\src
+ NUTTX = "$(TOPDIR)\nuttx$(EXEEXT)"
+ CFLAGS += -I$(ARCH_SRCDIR)\chip
+ CFLAGS += -I$(ARCH_SRCDIR)\common
+ CFLAGS += -I$(ARCH_SRCDIR)\$(ARCH_SUBDIR)
+ CFLAGS += -I$(TOPDIR)\sched
+else
+ ARCH_SRCDIR = $(TOPDIR)/arch/$(CONFIG_ARCH)/src
ifeq ($(WINTOOL),y)
- NUTTX = "${shell cygpath -w $(TOPDIR)/nuttx}"
- CFLAGS += -I "${shell cygpath -w $(ARCH_SRCDIR)/chip}" \
- -I "${shell cygpath -w $(ARCH_SRCDIR)/common}" \
- -I "${shell cygpath -w $(ARCH_SRCDIR)/$(ARCH_SUBDIR)}" \
- -I "${shell cygpath -w $(TOPDIR)/sched}"
+ NUTTX = "${shell cygpath -w $(TOPDIR)/nuttx$(EXEEXT)}"
+ CFLAGS += -I "${shell cygpath -w $(ARCH_SRCDIR)/chip}"
+ CFLAGS += -I "${shell cygpath -w $(ARCH_SRCDIR)/common}"
+ CFLAGS += -I "${shell cygpath -w $(ARCH_SRCDIR)/$(ARCH_SUBDIR)}"
+ CFLAGS += -I "${shell cygpath -w $(TOPDIR)/sched}"
else
- NUTTX = $(TOPDIR)/nuttx
- CFLAGS += -I$(ARCH_SRCDIR)/chip -I$(ARCH_SRCDIR)/common \
- -I$(ARCH_SRCDIR)/$(ARCH_SUBDIR) -I$(TOPDIR)/sched
+ NUTTX = "$(TOPDIR)/nuttx$(EXEEXT)"
+ CFLAGS += -I$(ARCH_SRCDIR)/chip
+ CFLAGS += -I$(ARCH_SRCDIR)/common
+ CFLAGS += -I$(ARCH_SRCDIR)/$(ARCH_SUBDIR)
+ CFLAGS += -I$(TOPDIR)/sched
+endif
endif
-HEAD_OBJ = $(HEAD_ASRC:.S=$(OBJEXT))
+HEAD_OBJ = $(HEAD_ASRC:.S=$(OBJEXT))
+
+ASRCS = $(CHIP_ASRCS) $(CMN_ASRCS)
+AOBJS = $(ASRCS:.S=$(OBJEXT))
-ASRCS = $(CHIP_ASRCS) $(CMN_ASRCS)
-AOBJS = $(ASRCS:.S=$(OBJEXT))
+CSRCS = $(CHIP_CSRCS) $(CMN_CSRCS)
+COBJS = $(CSRCS:.c=$(OBJEXT))
-CSRCS = $(CHIP_CSRCS) $(CMN_CSRCS)
-COBJS = $(CSRCS:.c=$(OBJEXT))
+SRCS = $(ASRCS) $(CSRCS)
+OBJS = $(AOBJS) $(COBJS)
-SRCS = $(ASRCS) $(CSRCS)
-OBJS = $(AOBJS) $(COBJS)
+LDFLAGS += $(ARCHSCRIPT)
-LDFLAGS = $(ARCHSCRIPT)
-EXTRA_LIBS ?=
+EXTRA_LIBS ?=
+EXTRA_LIBPATHS ?=
+LINKLIBS ?=
+
+ifeq ($(CONFIG_WINDOWS_NATIVE),y)
+ BOARDMAKE = $(if $(wildcard .\board\Makefile),y,)
+ LIBPATHS += -L"$(TOPDIR)\lib"
+ifeq ($(BOARDMAKE),y)
+ LIBPATHS += -L"$(TOPDIR)\arch\$(CONFIG_ARCH)\src\board"
+endif
+
+else
+ BOARDMAKE = $(if $(wildcard ./board/Makefile),y,)
-LINKLIBS =
ifeq ($(WINTOOL),y)
- LIBPATHS = ${shell for path in $(LINKLIBS); do dir=`dirname $(TOPDIR)/$$path`;echo "-L\"`cygpath -w $$dir`\"";done}
- LIBPATHS += -L"${shell cygpath -w $(BOARDDIR)}"
+ LIBPATHS += -L"${shell cygpath -w "$(TOPDIR)/lib"}"
+ifeq ($(BOARDMAKE),y)
+ LIBPATHS += -L"${shell cygpath -w "$(TOPDIR)/arch/$(CONFIG_ARCH)/src/board"}"
+endif
+
else
- LIBPATHS = $(addprefix -L$(TOPDIR)/,$(dir $(LINKLIBS)))
- LIBPATHS += -L"$(BOARDDIR)"
+ LIBPATHS += -L"$(TOPDIR)/lib"
+ifeq ($(BOARDMAKE),y)
+ LIBPATHS += -L"$(TOPDIR)/arch/$(CONFIG_ARCH)/src/board"
+endif
+endif
endif
-LDLIBS = $(patsubst lib%,-l%,$(basename $(notdir $(LINKLIBS))))
-BOARDDIR = $(TOPDIR)/arch/$(CONFIG_ARCH)/src/board
+LDLIBS = $(patsubst %.a,%,$(patsubst lib%,-l%,$(LINKLIBS)))
+ifeq ($(BOARDMAKE),y)
+ LDLIBS += -lboard
+endif
-LIBGCC = "${shell $(CC) $(ARCHCPUFLAGS) -print-libgcc-file-name}"
+LIBGCC = "${shell "$(CC)" $(ARCHCPUFLAGS) -print-libgcc-file-name}"
+GCC_LIBDIR := ${shell dirname $(LIBGCC)}
-VPATH = chip:common:$(ARCH_SUBDIR)
+VPATH = chip:common:$(ARCH_SUBDIR)
all: $(HEAD_OBJ) libarch$(LIBEXT)
@@ -100,20 +132,21 @@ $(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
libarch$(LIBEXT): $(OBJS)
- @( for obj in $(OBJS) ; do \
- $(call ARCHIVE, $@, $${obj}); \
- done ; )
+ $(call ARCHIVE, $@, $(OBJS))
board/libboard$(LIBEXT):
- @$(MAKE) -C board TOPDIR="$(TOPDIR)" libboard$(LIBEXT) EXTRADEFINES=$(EXTRADEFINES)
-
-nuttx: $(HEAD_OBJ) board/libboard$(LIBEXT)
- @echo "LD: nuttx"
- @$(LD) --entry=__start $(LDFLAGS) $(LIBPATHS) -o $(NUTTX)$(EXEEXT) $(HEAD_OBJ) $(EXTRA_OBJS) \
- --start-group $(LDLIBS) -lboard $(EXTRA_LIBS) $(LIBGCC) --end-group
- @$(NM) $(NUTTX)$(EXEEXT) | \
+ $(Q) $(MAKE) -C board TOPDIR="$(TOPDIR)" libboard$(LIBEXT) EXTRADEFINES=$(EXTRADEFINES)
+
+nuttx$(EXEEXT): $(HEAD_OBJ) board/libboard$(LIBEXT)
+ $(Q) echo "LD: nuttx"
+ $(Q) $(LD) --entry=__start $(LDFLAGS) $(LIBPATHS) $(EXTRA_LIBPATHS) \
+ -o $(NUTTX)$(EXEEXT) $(HEAD_OBJ) $(EXTRA_OBJS) \
+ --start-group $(LDLIBS) $(EXTRA_LIBS) $(LIBGCC) --end-group
+ifneq ($(CONFIG_WINDOWS_NATIVE),y)
+ $(Q) $(NM) $(NUTTX)$(EXEEXT) | \
grep -v '\(compiled\)\|\(\$(OBJEXT)$$\)\|\( [aUw] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' | \
sort > $(TOPDIR)/System.map
+endif
# This is part of the top-level export target
# Note that there may not be a head object if layout is handled
@@ -121,37 +154,38 @@ nuttx: $(HEAD_OBJ) board/libboard$(LIBEXT)
export_head: board/libboard$(LIBEXT) $(HEAD_OBJ)
ifneq ($(HEAD_OBJ),)
- @if [ -d "$(EXPORT_DIR)/startup" ]; then \
+ $(Q) if [ -d "$(EXPORT_DIR)/startup" ]; then \
cp -f $(HEAD_OBJ) "$(EXPORT_DIR)/startup"; \
else \
echo "$(EXPORT_DIR)/startup does not exist"; \
- exit 1; \
- fi
+ exit 1; \
+ fi
endif
# Dependencies
.depend: Makefile chip/Make.defs $(SRCS)
- @if [ -e board/Makefile ]; then \
- $(MAKE) -C board TOPDIR="$(TOPDIR)" depend ; \
- fi
- @$(MKDEP) --dep-path chip --dep-path common --dep-path $(ARCH_SUBDIR) \
- $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
- @touch $@
+ifeq ($(BOARDMAKE),y)
+ $(Q) $(MAKE) -C board TOPDIR="$(TOPDIR)" depend
+endif
+ $(Q) $(MKDEP) --dep-path chip --dep-path common --dep-path $(ARCH_SUBDIR) \
+ "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
+ $(Q) touch $@
depend: .depend
clean:
- @if [ -e board/Makefile ]; then \
- $(MAKE) -C board TOPDIR="$(TOPDIR)" clean ; \
- fi
- @rm -f libarch$(LIBEXT) *~ .*.swp
+ifeq ($(BOARDMAKE),y)
+ $(Q) $(MAKE) -C board TOPDIR="$(TOPDIR)" clean
+endif
+ $(call DELFILE, libarch$(LIBEXT))
$(call CLEAN)
distclean: clean
- @if [ -e board/Makefile ]; then \
- $(MAKE) -C board TOPDIR="$(TOPDIR)" distclean ; \
- fi
- @rm -f Make.dep .depend
+ifeq ($(BOARDMAKE),y)
+ $(Q) $(MAKE) -C board TOPDIR="$(TOPDIR)" distclean
+endif
+ $(call DELFILE, Make.dep)
+ $(call DELFILE, .depend)
-include Make.dep
diff --git a/nuttx/arch/arm/src/armv7-m/Kconfig b/nuttx/arch/arm/src/armv7-m/Kconfig
new file mode 100644
index 000000000..dc5aa3915
--- /dev/null
+++ b/nuttx/arch/arm/src/armv7-m/Kconfig
@@ -0,0 +1,51 @@
+#
+# For a description of the syntax of this configuration file,
+# see misc/tools/kconfig-language.txt.
+#
+
+comment "ARMV7M Configuration Options"
+
+choice
+ prompt "Toolchain Selection"
+ default ARMV7M_TOOLCHAIN_CODESOURCERYW if HOST_WINDOWS
+ default ARMV7M_TOOLCHAIN_GNU_EABI if !HOST_WINDOWS
+
+config ARMV7M_TOOLCHAIN_ATOLLIC
+ bool "Atollic Lite/Pro for Windows"
+ depends on HOST_WINDOWS
+
+config ARMV7M_TOOLCHAIN_BUILDROOT
+ bool "Buildroot (Cygwin or Linux)"
+ depends on !WINDOWS_NATIVE
+
+config ARMV7M_TOOLCHAIN_CODEREDL
+ bool "CodeRed for Linux"
+ depends on HOST_LINUX
+
+config ARMV7M_TOOLCHAIN_CODEREDW
+ bool "CodeRed for Windows"
+ depends on HOST_WINDOWS
+
+config ARMV7M_TOOLCHAIN_CODESOURCERYL
+ bool "CodeSourcery GNU toolchain under Linux"
+ depends on HOST_LINUX
+
+config ARMV7M_TOOLCHAIN_CODESOURCERYW
+ bool "CodeSourcery GNU toolchain under Windows"
+ depends on HOST_WINDOWS
+
+config ARMV7M_TOOLCHAIN_DEVKITARM
+ bool "devkitARM GNU toolchain"
+ depends on HOST_WINDOWS
+
+config ARMV7M_TOOLCHAIN_GNU_EABI
+ bool "Generic GNU EABI toolchain"
+ ---help---
+ This option should work for any modern GNU toolchain (GCC 4.5 or newer)
+ configured for arm-none-eabi.
+
+config ARMV7M_TOOLCHAIN_RAISONANCE
+ bool "STMicro Raisonance for Windows"
+ depends on HOST_WINDOWS
+
+endchoice
diff --git a/nuttx/arch/arm/src/armv7-m/Toolchain.defs b/nuttx/arch/arm/src/armv7-m/Toolchain.defs
new file mode 100644
index 000000000..e214ce8bd
--- /dev/null
+++ b/nuttx/arch/arm/src/armv7-m/Toolchain.defs
@@ -0,0 +1,266 @@
+############################################################################
+# arch/arm/src/armv7-m/Toolchain.defs
+#
+# Copyright (C) 2012 Gregory Nutt. All rights reserved.
+# Author: Gregory Nutt <gnutt@nuttx.org>
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in
+# the documentation and/or other materials provided with the
+# distribution.
+# 3. Neither the name NuttX nor the names of its contributors may be
+# used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+############################################################################
+
+# Setup for the selected toolchain
+
+#
+# Handle old-style chip-specific toolchain names in the absence of
+# a new-style toolchain specification, force the selection of a single
+# toolchain and allow the selected toolchain to be overridden by a
+# command-line selection.
+#
+
+ifeq ($(filter y, \
+ $(CONFIG_LPC43_ATOLLIC_LITE) \
+ $(CONFIG_STM32_ATOLLIC_LITE) \
+ $(CONFIG_LPC43_ATOLLIC_PRO) \
+ $(CONFIG_STM32_ATOLLIC_PRO) \
+ $(CONFIG_ARMV7M_TOOLCHAIN_ATOLLIC) \
+ ),y)
+ CONFIG_ARMV7M_TOOLCHAIN ?= ATOLLIC
+endif
+ifeq ($(filter y, \
+ $(CONFIG_KINETIS_BUILDROOT) \
+ $(CONFIG_LM3S_BUILDROOT) \
+ $(CONFIG_LPC17_BUILDROOT) \
+ $(CONFIG_LPC43_BUILDROOT) \
+ $(CONFIG_SAM3U_BUILDROOT) \
+ $(CONFIG_STM32_BUILDROOT) \
+ $(CONFIG_ARMV7M_TOOLCHAIN_BUILDROOT) \
+ ),y)
+ CONFIG_ARMV7M_TOOLCHAIN ?= BUILDROOT
+endif
+ifeq ($(filter y, \
+ $(CONFIG_LPC17_CODEREDL) \
+ $(CONFIG_ARMV7M_TOOLCHAIN_CODEREDL) \
+ ),y)
+ CONFIG_ARMV7M_TOOLCHAIN ?= CODEREDL
+endif
+ifeq ($(filter y, \
+ $(CONFIG_LPC17_CODEREDW) \
+ $(CONFIG_LPC43_CODEREDW) \
+ $(CONFIG_ARMV7M_TOOLCHAIN_CODEREDW) \
+ ),y)
+ CONFIG_ARMV7M_TOOLCHAIN ?= CODEREDW
+endif
+ifeq ($(filter y, \
+ $(CONFIG_KINETIS_CODESOURCERYL) \
+ $(CONFIG_LM3S_CODESOURCERYL) \
+ $(CONFIG_LPC17_CODESOURCERYL) \
+ $(CONFIG_LPC43_CODESOURCERYL) \
+ $(CONFIG_SAM3U_CODESOURCERYL) \
+ $(CONFIG_STM32_CODESOURCERYL) \
+ $(CONFIG_ARMV7M_TOOLCHAIN_CODESOURCERYL) \
+ ),y)
+ CONFIG_ARMV7M_TOOLCHAIN ?= CODESOURCERYL
+endif
+ifeq ($(filter y, \
+ $(CONFIG_KINETIS_CODESOURCERYW) \
+ $(CONFIG_LM3S_CODESOURCERYW) \
+ $(CONFIG_LPC17_CODESOURCERYW) \
+ $(CONFIG_LPC43_CODESOURCERYW) \
+ $(CONFIG_SAM3U_CODESOURCERYW) \
+ $(CONFIG_STM32_CODESOURCERYW) \
+ $(CONFIG_ARMV7M_TOOLCHAIN_CODESOURCERYW) \
+ ),y)
+ CONFIG_ARMV7M_TOOLCHAIN ?= CODESOURCERYW
+endif
+ifeq ($(filter y, \
+ $(CONFIG_KINETIS_DEVKITARM) \
+ $(CONFIG_LM3S_DEVKITARM) \
+ $(CONFIG_LPC17_DEVKITARM) \
+ $(CONFIG_LPC43_DEVKITARM) \
+ $(CONFIG_SAM3U_DEVKITARM) \
+ $(CONFIG_STM32_DEVKITARM) \
+ $(CONFIG_ARMV7M_TOOLCHAIN_DEVKITARM) \
+ ),y)
+ CONFIG_ARMV7M_TOOLCHAIN ?= DEVKITARM
+endif
+ifeq ($(filter y, \
+ $(CONFIG_ARMV7M_TOOLCHAIN_GNU_EABI) \
+ ),y)
+ CONFIG_ARMV7M_TOOLCHAIN ?= GNU_EABI
+endif
+ifeq ($(filter y, \
+ $(CONFIG_STM32_RAISONANCE) \
+ $(CONFIG_ARMV7M_TOOLCHAIN_RAISONANCE) \
+ ),y)
+ CONFIG_ARMV7M_TOOLCHAIN ?= RAISONANCE
+endif
+
+#
+# Supported toolchains
+#
+# TODO - It's likely that all of these toolchains now support the
+# CortexM4. Since they are all GCC-based, we could almost
+# certainly simplify this further.
+#
+# Each toolchain definition should set:
+#
+# CROSSDEV The GNU toolchain triple (command prefix)
+# ARCROSSDEV If required, an alternative prefix used when
+# invoking ar and nm.
+# ARCHCPUFLAGS CPU-specific flags selecting the instruction set
+# FPU options, etc.
+# MAXOPTIMIZATION The maximum optimization level that results in
+# reliable code generation.
+#
+
+# Atollic toolchain under Windows
+
+ifeq ($(CONFIG_ARMV7M_TOOLCHAIN),ATOLLIC)
+ CROSSDEV = arm-atollic-eabi-
+ ARCROSSDEV = arm-atollic-eabi-
+ ifneq ($(CONFIG_WINDOWS_NATIVE),y)
+ WINTOOL = y
+ endif
+ ifeq ($(CONFIG_ARCH_CORTEXM4),y)
+ ifeq ($(CONFIG_ARCH_FPU),y)
+ ARCHCPUFLAGS = -mcpu=cortex-m4 -mthumb -march=armv7e-m -mfpu=fpv4-sp-d16 -mfloat-abi=hard
+ else
+ ARCHCPUFLAGS = -mcpu=cortex-m4 -mthumb -march=armv7e-m -mfloat-abi=soft
+ endif
+ else ifeq ($(CONFIG_ARCH_CORTEXM3),y)
+ ARCHCPUFLAGS = -mcpu=cortex-m3 -mthumb -mfloat-abi=soft
+ endif
+endif
+
+# NuttX buildroot under Linux or Cygwin
+
+ifeq ($(CONFIG_ARMV7M_TOOLCHAIN),BUILDROOT)
+ # OABI
+ # CROSSDEV = arm-nuttx-elf-
+ # ARCROSSDEV = arm-nuttx-elf-
+ # ARCHCPUFLAGS = -mtune=cortex-m3 -march=armv7-m -mfloat-abi=soft
+ # EABI
+ CROSSDEV = arm-nuttx-eabi-
+ ARCROSSDEV = arm-nuttx-eabi-
+ ARCHCPUFLAGS = -mcpu=cortex-m3 -mthumb -mfloat-abi=soft
+ MAXOPTIMIZATION = -Os
+endif
+
+# Code Red RedSuite under Linux
+
+ifeq ($(CONFIG_ARMV7M_TOOLCHAIN),CODEREDL)
+ CROSSDEV = arm-none-eabi-
+ ARCROSSDEV = arm-none-eabi-
+ ifeq ($(CONFIG_ARCH_CORTEXM4),y)
+ ifeq ($(CONFIG_ARCH_FPU),y)
+ ARCHCPUFLAGS = -mcpu=cortex-m4 -mthumb -march=armv7e-m -mfpu=fpv4-sp-d16 -mfloat-abi=hard
+ else
+ ARCHCPUFLAGS = -mcpu=cortex-m4 -mthumb -march=armv7e-m -mfloat-abi=soft
+ endif
+ else ifeq ($(CONFIG_ARCH_CORTEXM3),y)
+ ARCHCPUFLAGS = -mcpu=cortex-m3 -mthumb -mfloat-abi=soft
+ endif
+endif
+
+# Code Red RedSuite under Windows
+
+ifeq ($(CONFIG_ARMV7M_TOOLCHAIN),CODEREDW)
+ CROSSDEV = arm-none-eabi-
+ ARCROSSDEV = arm-none-eabi-
+ ifneq ($(CONFIG_WINDOWS_NATIVE),y)
+ WINTOOL = y
+ endif
+ ifeq ($(CONFIG_ARCH_CORTEXM4),y)
+ ifeq ($(CONFIG_ARCH_FPU),y)
+ ARCHCPUFLAGS = -mcpu=cortex-m4 -mthumb -march=armv7e-m -mfpu=fpv4-sp-d16 -mfloat-abi=hard
+ else
+ ARCHCPUFLAGS = -mcpu=cortex-m4 -mthumb -march=armv7e-m -mfloat-abi=soft
+ endif
+ else ifeq ($(CONFIG_ARCH_CORTEXM3),y)
+ ARCHCPUFLAGS = -mcpu=cortex-m3 -mthumb -mfloat-abi=soft
+ endif
+endif
+
+# CodeSourcery under Linux
+
+ifeq ($(CONFIG_ARMV7M_TOOLCHAIN),CODESOURCERYL)
+ CROSSDEV = arm-none-eabi-
+ ARCROSSDEV = arm-none-eabi-
+ ARCHCPUFLAGS = -mcpu=cortex-m3 -mthumb -mfloat-abi=soft
+ MAXOPTIMIZATION = -O2
+endif
+
+# CodeSourcery under Windows
+
+ifeq ($(CONFIG_ARMV7M_TOOLCHAIN),CODESOURCERYW)
+ CROSSDEV = arm-none-eabi-
+ ARCROSSDEV = arm-none-eabi-
+ ifneq ($(CONFIG_WINDOWS_NATIVE),y)
+ WINTOOL = y
+ endif
+ ARCHCPUFLAGS = -mcpu=cortex-m3 -mthumb -mfloat-abi=soft
+endif
+
+# devkitARM under Windows
+
+ifeq ($(CONFIG_ARMV7M_TOOLCHAIN),DEVKITARM)
+ CROSSDEV = arm-eabi-
+ ARCROSSDEV = arm-eabi-
+ ifneq ($(CONFIG_WINDOWS_NATIVE),y)
+ WINTOOL = y
+ endif
+ ARCHCPUFLAGS = -mcpu=cortex-m3 -mthumb -mfloat-abi=soft
+endif
+
+# Generic GNU EABI toolchain on OS X, Linux or any typical Posix system
+
+ifeq ($(CONFIG_ARMV7M_TOOLCHAIN),GNU_EABI)
+ CROSSDEV = arm-none-eabi-
+ ARCROSSDEV = arm-none-eabi-
+ MAXOPTIMIZATION = -O3
+ ifeq ($(CONFIG_ARCH_CORTEXM4),y)
+ ifeq ($(CONFIG_ARCH_FPU),y)
+ ARCHCPUFLAGS = -mcpu=cortex-m4 -mthumb -march=armv7e-m -mfpu=fpv4-sp-d16 -mfloat-abi=hard
+ else
+ ARCHCPUFLAGS = -mcpu=cortex-m4 -mthumb -march=armv7e-m -mfloat-abi=soft
+ endif
+ else ifeq ($(CONFIG_ARCH_CORTEXM3),y)
+ ARCHCPUFLAGS = -mcpu=cortex-m3 -mthumb -mfloat-abi=soft
+ endif
+endif
+
+# Raisonance RIDE7 under Windows
+
+ifeq ($(CONFIG_ARMV7M_TOOLCHAIN),RAISONANCE)
+ CROSSDEV = arm-none-eabi-
+ ARCROSSDEV = arm-none-eabi-
+ ifneq ($(CONFIG_WINDOWS_NATIVE),y)
+ WINTOOL = y
+ endif
+ ARCHCPUFLAGS = -mcpu=cortex-m3 -mthumb -mfloat-abi=soft
+endif
diff --git a/nuttx/arch/arm/src/armv7-m/memcpy.S b/nuttx/arch/arm/src/armv7-m/memcpy.S
deleted file mode 100644
index c6d3ff649..000000000
--- a/nuttx/arch/arm/src/armv7-m/memcpy.S
+++ /dev/null
@@ -1,351 +0,0 @@
-@
-@ armv7m-optimised memcpy, apparently in the public domain
-@
-@ Obtained via a posting on the Stellaris forum:
-@ http://e2e.ti.com/support/microcontrollers/stellaris_arm_cortex-m3_microcontroller/f/473/t/44360.aspx
-@
-@ Posted by rocksoft on Jul 24, 2008 10:19 AM
-@
-@ Hi,
-@
-@ I recently finished a "memcpy" replacement and thought it might be useful for others...
-@
-@ I've put some instructions and the code here:
-@
-@ http://www.rock-software.net/downloads/memcpy/
-@
-@ Hope it works for you as well as it did for me.
-@
-@ Liam.
-@ @
-@ ----------------------------------------------------------------------------
-
-.syntax unified
-
-.thumb
-
-.cpu cortex-m3
-
-@ ----------------------------------------------------------------------------
-
- .global memcpy
-
-
-@ ----------------------------------------------------------------------------
-@ Optimised "general" copy routine
-
-.text
-
-@ We have 16 possible alignment combinations of src and dst, this jump table directs the copy operation
-@ Bits: Src=00, Dst=00 - Long to Long copy
-@ Bits: Src=00, Dst=01 - Long to Byte before half word
-@ Bits: Src=00, Dst=10 - Long to Half word
-@ Bits: Src=00, Dst=11 - Long to Byte before long word
-@ Bits: Src=01, Dst=00 - Byte before half word to long
-@ Bits: Src=01, Dst=01 - Byte before half word to byte before half word - Same alignment
-@ Bits: Src=01, Dst=10 - Byte before half word to half word
-@ Bits: Src=01, Dst=11 - Byte before half word to byte before long word
-@ Bits: Src=10, Dst=00 - Half word to long word
-@ Bits: Src=10, Dst=01 - Half word to byte before half word
-@ Bits: Src=10, Dst=10 - Half word to half word - Same Alignment
-@ Bits: Src=10, Dst=11 - Half word to byte before long word
-@ Bits: Src=11, Dst=00 - Byte before long word to long word
-@ Bits: Src=11, Dst=01 - Byte before long word to byte before half word
-@ Bits: Src=11, Dst=11 - Byte before long word to half word
-@ Bits: Src=11, Dst=11 - Byte before long word to Byte before long word - Same alignment
-
-MEM_DataCopyTable:
- .byte (MEM_DataCopy0 - MEM_DataCopyJump) >> 1
- .byte (MEM_DataCopy1 - MEM_DataCopyJump) >> 1
- .byte (MEM_DataCopy2 - MEM_DataCopyJump) >> 1
- .byte (MEM_DataCopy3 - MEM_DataCopyJump) >> 1
- .byte (MEM_DataCopy4 - MEM_DataCopyJump) >> 1
- .byte (MEM_DataCopy5 - MEM_DataCopyJump) >> 1
- .byte (MEM_DataCopy6 - MEM_DataCopyJump) >> 1
- .byte (MEM_DataCopy7 - MEM_DataCopyJump) >> 1
- .byte (MEM_DataCopy8 - MEM_DataCopyJump) >> 1
- .byte (MEM_DataCopy9 - MEM_DataCopyJump) >> 1
- .byte (MEM_DataCopy10 - MEM_DataCopyJump) >> 1
- .byte (MEM_DataCopy11 - MEM_DataCopyJump) >> 1
- .byte (MEM_DataCopy12 - MEM_DataCopyJump) >> 1
- .byte (MEM_DataCopy13 - MEM_DataCopyJump) >> 1
- .byte (MEM_DataCopy14 - MEM_DataCopyJump) >> 1
- .byte (MEM_DataCopy15 - MEM_DataCopyJump) >> 1
-
- .align 2
-
-@ ----------------------------------------------------------------------------
-
-//#define 10 10
-
-MEM_LongCopyTable:
- .byte (MEM_LongCopyEnd - MEM_LongCopyJump) >> 1 @ 0 bytes left
- .byte 0 @ 4 bytes left
- .byte (1 * 10) >> 1 @ 8 bytes left
- .byte (2 * 10) >> 1 @ 12 bytes left
- .byte (3 * 10) >> 1 @ 16 bytes left
- .byte (4 * 10) >> 1 @ 20 bytes left
- .byte (5 * 10) >> 1 @ 24 bytes left
- .byte (6 * 10) >> 1 @ 28 bytes left
- .byte (7 * 10) >> 1 @ 32 bytes left
- .byte (8 * 10) >> 1 @ 36 bytes left
-
- .align 2
-
-@ ----------------------------------------------------------------------------
-@ r0 = destination, r1 = source, r2 = length
-
-.thumb_func
-
-memcpy:
- push {r14}
-
- @ This allows the inner workings to "assume" a minimum amount of bytes
- cmp r2, #4
- blt MEM_DataCopyBytes
-
- and r14, r0, #3 @ Get destination alignment bits
- bfi r14, r1, #2, #2 @ Get source alignment bits
- ldr r3, =MEM_DataCopyTable @ Jump table base
- tbb [r3, r14] @ Perform jump on src/dst alignment bits
-MEM_DataCopyJump:
-
- .align 4
-
-@ ----------------------------------------------------------------------------
-@ Bits: Src=01, Dst=01 - Byte before half word to byte before half word - Same alignment
-@ 3 bytes to read for long word aligning
-
-MEM_DataCopy5:
- ldrb r3, [r1], #0x01
- strb r3, [r0], #0x01
- sub r2, r2, #0x01
-
-@ ----------------------------------------------------------------------------
-@ Bits: Src=10, Dst=10 - Half word to half word - Same Alignment
-@ 2 bytes to read for long word aligning
-
-MEM_DataCopy10:
- ldrb r3, [r1], #0x01
- strb r3, [r0], #0x01
- sub r2, r2, #0x01
-
-@ ----------------------------------------------------------------------------
-@ Bits: Src=11, Dst=11 - Byte before long word to Byte before long word - Same alignment
-@ 1 bytes to read for long word aligning
-
-MEM_DataCopy15:
- ldrb r3, [r1], #0x01
- strb r3, [r0], #0x01
- sub r2, r2, #0x01
-
-@ ----------------------------------------------------------------------------
-@ Bits: Src=00, Dst=00 - Long to Long copy
-
-MEM_DataCopy0:
- @ Save regs
- push {r4-r12}
-
- cmp r2, #0x28
- blt MEM_DataCopy0_2
-
-MEM_DataCopy0_1:
- ldmia r1!, {r3-r12}
- stmia r0!, {r3-r12}
- sub r2, r2, #0x28
- cmp r2, #0x28
- bge MEM_DataCopy0_1
-
-MEM_DataCopy0_2:
- @ Copy remaining long words
- ldr r14, =MEM_LongCopyTable
- lsr r11, r2, #0x02
- tbb [r14, r11]
-
-MEM_LongCopyJump:
- ldr.w r3, [r1], #0x04 @ 4 bytes remain
- str.w r3, [r0], #0x04
- b MEM_LongCopyEnd
- ldmia.w r1!, {r3-r4} @ 8 bytes remain
- stmia.w r0!, {r3-r4}
- b MEM_LongCopyEnd
- ldmia.w r1!, {r3-r5} @ 12 bytes remain
- stmia.w r0!, {r3-r5}
- b MEM_LongCopyEnd
- ldmia.w r1!, {r3-r6} @ 16 bytes remain
- stmia.w r0!, {r3-r6}
- b MEM_LongCopyEnd
- ldmia.w r1!, {r3-r7} @ 20 bytes remain
- stmia.w r0!, {r3-r7}
- b MEM_LongCopyEnd
- ldmia.w r1!, {r3-r8} @ 24 bytes remain
- stmia.w r0!, {r3-r8}
- b MEM_LongCopyEnd
- ldmia.w r1!, {r3-r9} @ 28 bytes remain
- stmia.w r0!, {r3-r9}
- b MEM_LongCopyEnd
- ldmia.w r1!, {r3-r10} @ 32 bytes remain
- stmia.w r0!, {r3-r10}
- b MEM_LongCopyEnd
- ldmia.w r1!, {r3-r11} @ 36 bytes remain
- stmia.w r0!, {r3-r11}
-
-MEM_LongCopyEnd:
- pop {r4-r12}
- and r2, r2, #0x03 @ All the longs have been copied
-
-@ ----------------------------------------------------------------------------
-
-MEM_DataCopyBytes:
- @ Deal with up to 3 remaining bytes
- cmp r2, #0x00
- it eq
- popeq {pc}
- ldrb r3, [r1], #0x01
- strb r3, [r0], #0x01
- subs r2, r2, #0x01
- it eq
- popeq {pc}
- ldrb r3, [r1], #0x01
- strb r3, [r0], #0x01
- subs r2, r2, #0x01
- it eq
- popeq {pc}
- ldrb r3, [r1], #0x01
- strb r3, [r0], #0x01
- pop {pc}
-
- .align 4
-
-@ ----------------------------------------------------------------------------
-@ Bits: Src=01, Dst=11 - Byte before half word to byte before long word
-@ 3 bytes to read for long word aligning the source
-
-MEM_DataCopy7:
- ldrb r3, [r1], #0x01
- strb r3, [r0], #0x01
- sub r2, r2, #0x01
-
-@ ----------------------------------------------------------------------------
-@ Bits: Src=10, Dst=00 - Half word to long word
-@ 2 bytes to read for long word aligning the source
-
-MEM_DataCopy8:
- ldrb r3, [r1], #0x01
- strb r3, [r0], #0x01
- sub r2, r2, #0x01
-
-@ ----------------------------------------------------------------------------
-@ Bits: Src=11, Dst=01 - Byte before long word to byte before half word
-@ 1 byte to read for long word aligning the source
-
-MEM_DataCopy13:
- ldrb r3, [r1], #0x01
- strb r3, [r0], #0x01
- sub r2, r2, #0x01
-
-@ ----------------------------------------------------------------------------
-@ Bits: Src=00, Dst=10 - Long to Half word
-
-MEM_DataCopy2:
- cmp r2, #0x28
- blt MEM_DataCopy2_1
-
- @ Save regs
- push {r4-r12}
-MEM_DataCopy2_2:
- ldmia r1!, {r3-r12}
-
- strh r3, [r0], #0x02
-
- lsr r3, r3, #0x10
- bfi r3, r4, #0x10, #0x10
- lsr r4, r4, #0x10
- bfi r4, r5, #0x10, #0x10
- lsr r5, r5, #0x10
- bfi r5, r6, #0x10, #0x10
- lsr r6, r6, #0x10
- bfi r6, r7, #0x10, #0x10
- lsr r7, r7, #0x10
- bfi r7, r8, #0x10, #0x10
- lsr r8, r8, #0x10
- bfi r8, r9, #0x10, #0x10
- lsr r9, r9, #0x10
- bfi r9, r10, #0x10, #0x10
- lsr r10, r10, #0x10
- bfi r10, r11, #0x10, #0x10
- lsr r11, r11, #0x10
- bfi r11, r12, #0x10, #0x10
- stmia r0!, {r3-r11}
- lsr r12, r12, #0x10
- strh r12, [r0], #0x02
-
- sub r2, r2, #0x28
- cmp r2, #0x28
- bge MEM_DataCopy2_2
- pop {r4-r12}
-
-MEM_DataCopy2_1: @ Read longs and write 2 x half words
- cmp r2, #4
- blt MEM_DataCopyBytes
- ldr r3, [r1], #0x04
- strh r3, [r0], #0x02
- lsr r3, r3, #0x10
- strh r3, [r0], #0x02
- sub r2, r2, #0x04
- b MEM_DataCopy2
-
-@ ----------------------------------------------------------------------------
-@ Bits: Src=01, Dst=00 - Byte before half word to long
-@ Bits: Src=01, Dst=10 - Byte before half word to half word
-@ 3 bytes to read for long word aligning the source
-
-MEM_DataCopy4:
-MEM_DataCopy6:
- @ Read B and write B
- ldrb r3, [r1], #0x01
- strb r3, [r0], #0x01
- sub r2, r2, #0x01
-
-@ ----------------------------------------------------------------------------
-@ Bits: Src=10, Dst=01 - Half word to byte before half word
-@ Bits: Src=10, Dst=11 - Half word to byte before long word
-@ 2 bytes to read for long word aligning the source
-
-MEM_DataCopy9:
-MEM_DataCopy11:
- ldrb r3, [r1], #0x01
- strb r3, [r0], #0x01
- sub r2, r2, #0x01
-
-@ ----------------------------------------------------------------------------
-@ Bits: Src=11, Dst=00 - Byte before long word to long word
-@ Bits: Src=11, Dst=11 - Byte before long word to half word
-@ 1 byte to read for long word aligning the source
-
-MEM_DataCopy12:
-MEM_DataCopy14:
- @ Read B and write B
- ldrb r3, [r1], #0x01
- strb r3, [r0], #0x01
- sub r2, r2, #0x01
-
-@ ----------------------------------------------------------------------------
-@ Bits: Src=00, Dst=01 - Long to Byte before half word
-@ Bits: Src=00, Dst=11 - Long to Byte before long word
-
-MEM_DataCopy1: @ Read longs, write B->H->B
-MEM_DataCopy3:
- cmp r2, #4
- blt MEM_DataCopyBytes
- ldr r3, [r1], #0x04
- strb r3, [r0], #0x01
- lsr r3, r3, #0x08
- strh r3, [r0], #0x02
- lsr r3, r3, #0x10
- strb r3, [r0], #0x01
- sub r2, r2, #0x04
- b MEM_DataCopy3
-
-@ ----------------------------------------------------------------------------
-
diff --git a/nuttx/arch/arm/src/armv7-m/up_elf.c b/nuttx/arch/arm/src/armv7-m/up_elf.c
new file mode 100644
index 000000000..b838a6905
--- /dev/null
+++ b/nuttx/arch/arm/src/armv7-m/up_elf.c
@@ -0,0 +1,450 @@
+/****************************************************************************
+ * arch/arm/src/armv7-m/up_elf.c
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdlib.h>
+#include <elf32.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <arch/elf.h>
+#include <nuttx/arch.h>
+#include <nuttx/binfmt/elf.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: arch_checkarch
+ *
+ * Description:
+ * Given the ELF header in 'hdr', verify that the ELF file is appropriate
+ * for the current, configured architecture. Every architecture that uses
+ * the ELF loader must provide this function.
+ *
+ * Input Parameters:
+ * hdr - The ELF header read from the ELF file.
+ *
+ * Returned Value:
+ * True if the architecture supports this ELF file.
+ *
+ ****************************************************************************/
+
+bool arch_checkarch(FAR const Elf32_Ehdr *ehdr)
+{
+ /* Make sure it's an ARM executable */
+
+ if (ehdr->e_machine != EM_ARM)
+ {
+ bdbg("Not for ARM: e_machine=%04x\n", ehdr->e_machine);
+ return -ENOEXEC;
+ }
+
+ /* Make sure that 32-bit objects are supported */
+
+ if (ehdr->e_ident[EI_CLASS] != ELFCLASS32)
+ {
+ bdbg("Need 32-bit objects: e_ident[EI_CLASS]=%02x\n", ehdr->e_ident[EI_CLASS]);
+ return -ENOEXEC;
+ }
+
+ /* Verify endian-ness */
+
+#ifdef CONFIG_ENDIAN_BIG
+ if (ehdr->e_ident[EI_DATA] != ELFDATA2MSB)
+#else
+ if (ehdr->e_ident[EI_DATA] != ELFDATA2LSB)
+#endif
+ {
+ bdbg("Wrong endian-ness: e_ident[EI_DATA]=%02x\n", ehdr->e_ident[EI_DATA]);
+ return -ENOEXEC;
+ }
+
+ /* TODO: Check ABI here. */
+ return OK;
+}
+
+/****************************************************************************
+ * Name: arch_relocate and arch_relocateadd
+ *
+ * Description:
+ * Perform on architecture-specific ELF relocation. Every architecture
+ * that uses the ELF loader must provide this function.
+ *
+ * Input Parameters:
+ * rel - The relocation type
+ * sym - The ELF symbol structure containing the fully resolved value.
+ * addr - The address that requires the relocation.
+ *
+ * Returned Value:
+ * Zero (OK) if the relocation was successful. Otherwise, a negated errno
+ * value indicating the cause of the relocation failure.
+ *
+ ****************************************************************************/
+
+int arch_relocate(FAR const Elf32_Rel *rel, FAR const Elf32_Sym *sym,
+ uintptr_t addr)
+{
+ int32_t offset;
+ uint32_t upper_insn;
+ uint32_t lower_insn;
+
+ switch (ELF32_R_TYPE(rel->r_info))
+ {
+ case R_ARM_NONE:
+ {
+ /* No relocation */
+ }
+ break;
+
+ case R_ARM_PC24:
+ case R_ARM_CALL:
+ case R_ARM_JUMP24:
+ {
+ bvdbg("Performing PC24 [%d] link at addr %08lx [%08lx] to sym '%s' st_value=%08lx\n",
+ ELF32_R_TYPE(rel->r_info), (long)addr, (long)(*(uint32_t*)addr),
+ sym, (long)sym->st_value);
+
+ offset = (*(uint32_t*)addr & 0x00ffffff) << 2;
+ if (offset & 0x02000000)
+ {
+ offset -= 0x04000000;
+ }
+
+ offset += sym->st_value - addr;
+ if (offset & 3 || offset <= (int32_t) 0xfe000000 || offset >= (int32_t) 0x02000000)
+ {
+ bdbg(" ERROR: PC24 [%d] relocation out of range, offset=%08lx\n",
+ ELF32_R_TYPE(rel->r_info), offset);
+
+ return -EINVAL;
+ }
+
+ offset >>= 2;
+
+ *(uint32_t*)addr &= 0xff000000;
+ *(uint32_t*)addr |= offset & 0x00ffffff;
+ }
+ break;
+
+ case R_ARM_ABS32:
+ case R_ARM_TARGET1: /* New ABI: TARGET1 always treated as ABS32 */
+ {
+ bvdbg("Performing ABS32 link at addr=%08lx [%08lx] to sym=%p st_value=%08lx\n",
+ (long)addr, (long)(*(uint32_t*)addr), sym, (long)sym->st_value);
+
+ *(uint32_t*)addr += sym->st_value;
+ }
+ break;
+
+ case R_ARM_THM_CALL:
+ case R_ARM_THM_JUMP24:
+ {
+ uint32_t S;
+ uint32_t J1;
+ uint32_t J2;
+
+ /* Thumb BL and B.W instructions. Encoding:
+ *
+ * upper_insn:
+ *
+ * 1 1 1 1 1 1
+ * 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
+ * +----------+---+-------------------------------+--------------+
+ * |1 1 1 |OP1| OP2 | | 32-Bit Instructions
+ * +----------+---+--+-----+----------------------+--------------+
+ * |1 1 1 | 1 0| S | imm10 | BL Instruction
+ * +----------+------+-----+-------------------------------------+
+ *
+ * lower_insn:
+ *
+ * 1 1 1 1 1 1
+ * 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
+ * +---+---------------------------------------------------------+
+ * |OP | | 32-Bit Instructions
+ * +---+--+---+---+---+------------------------------------------+
+ * |1 1 |J1 | 1 |J2 | imm11 | BL Instruction
+ * +------+---+---+---+------------------------------------------+
+ *
+ * The branch target is encoded in these bits:
+ *
+ * S = upper_insn[10]
+ * imm10 = upper_insn[0:9]
+ * imm11 = lower_insn[0:10]
+ * J1 = lower_insn[13]
+ * J2 = lower_insn[11]
+ */
+
+ upper_insn = (uint32_t)(*(uint16_t*)addr);
+ lower_insn = (uint32_t)(*(uint16_t*)(addr + 2));
+
+ bvdbg("Performing THM_JUMP24 [%d] link at addr=%08lx [%04x %04x] to sym=%p st_value=%08lx\n",
+ ELF32_R_TYPE(rel->r_info), (long)addr, (int)upper_insn, (int)lower_insn,
+ sym, (long)sym->st_value);
+
+ /* Extract the 25-bit offset from the 32-bit instruction:
+ *
+ * offset[24] = S
+ * offset[23] = ~(J1 ^ S)
+ * offset[22] = ~(J2 ^ S)]
+ * offset[12:21] = imm10
+ * offset[1:11] = imm11
+ * offset[0] = 0
+ */
+
+ S = (upper_insn >> 10) & 1;
+ J1 = (lower_insn >> 13) & 1;
+ J2 = (lower_insn >> 11) & 1;
+
+ offset = (S << 24) | /* S - > offset[24] */
+ ((~(J1 ^ S) & 1) << 23) | /* J1 -> offset[23] */
+ ((~(J2 ^ S) & 1) << 22) | /* J2 -> offset[22] */
+ ((upper_insn & 0x03ff) << 12) | /* imm10 -> offset[12:21] */
+ ((lower_insn & 0x07ff) << 1); /* imm11 -> offset[1:11] */
+ /* 0 -> offset[0] */
+
+ /* Sign extend */
+
+ if (offset & 0x01000000)
+ {
+ offset -= 0x02000000;
+ }
+
+ /* And perform the relocation */
+
+ bvdbg(" S=%d J1=%d J2=%d offset=%08lx branch target=%08lx\n",
+ S, J1, J2, (long)offset, offset + sym->st_value - addr);
+
+ offset += sym->st_value - addr;
+
+ /* Is this a function symbol? If so, then the branch target must be
+ * an odd Thumb address
+ */
+
+ if (ELF32_ST_TYPE(sym->st_info) == STT_FUNC && (offset & 1) == 0)
+ {
+ bdbg(" ERROR: JUMP24 [%d] requires odd offset, offset=%08lx\n",
+ ELF32_R_TYPE(rel->r_info), offset);
+
+ return -EINVAL;
+ }
+
+ /* Check the range of the offset */
+
+ if (offset <= (int32_t)0xff000000 || offset >= (int32_t)0x01000000)
+ {
+ bdbg(" ERROR: JUMP24 [%d] relocation out of range, branch taget=%08lx\n",
+ ELF32_R_TYPE(rel->r_info), offset);
+
+ return -EINVAL;
+ }
+
+ /* Now, reconstruct the 32-bit instruction using the new, relocated
+ * branch target.
+ */
+
+ S = (offset >> 24) & 1;
+ J1 = S ^ (~(offset >> 23) & 1);
+ J2 = S ^ (~(offset >> 22) & 1);
+
+ upper_insn = ((upper_insn & 0xf800) | (S << 10) | ((offset >> 12) & 0x03ff));
+ *(uint16_t*)addr = (uint16_t)upper_insn;
+
+ lower_insn = ((lower_insn & 0xd000) | (J1 << 13) | (J2 << 11) | ((offset >> 1) & 0x07ff));
+ *(uint16_t*)(addr + 2) = (uint16_t)lower_insn;
+
+ bvdbg(" S=%d J1=%d J2=%d insn [%04x %04x]\n",
+ S, J1, J2, (int)upper_insn, (int)lower_insn);
+ }
+ break;
+
+ case R_ARM_V4BX:
+ {
+ bvdbg("Performing V4BX link at addr=%08lx [%08lx]\n",
+ (long)addr, (long)(*(uint32_t*)addr));
+
+ /* Preserve only Rm and the condition code */
+
+ *(uint32_t*)addr &= 0xf000000f;
+
+ /* Change instruction to 'mov pc, Rm' */
+
+ *(uint32_t*)addr |= 0x01a0f000;
+ }
+ break;
+
+ case R_ARM_PREL31:
+ {
+ bvdbg("Performing PREL31 link at addr=%08lx [%08lx] to sym=%p st_value=%08lx\n",
+ (long)addr, (long)(*(uint32_t*)addr), sym, (long)sym->st_value);
+
+ offset = *(uint32_t*)addr + sym->st_value - addr;
+ *(uint32_t*)addr = offset & 0x7fffffff;
+ }
+ break;
+
+ case R_ARM_MOVW_ABS_NC:
+ case R_ARM_MOVT_ABS:
+ {
+ bvdbg("Performing MOVx_ABS [%d] link at addr=%08lx [%08lx] to sym=%p st_value=%08lx\n",
+ ELF32_R_TYPE(rel->r_info), (long)addr, (long)(*(uint32_t*)addr),
+ sym, (long)sym->st_value);
+
+ offset = *(uint32_t*)addr;
+ offset = ((offset & 0xf0000) >> 4) | (offset & 0xfff);
+ offset = (offset ^ 0x8000) - 0x8000;
+
+ offset += sym->st_value;
+ if (ELF32_R_TYPE(rel->r_info) == R_ARM_MOVT_ABS)
+ {
+ offset >>= 16;
+ }
+
+ *(uint32_t*)addr &= 0xfff0f000;
+ *(uint32_t*)addr |= ((offset & 0xf000) << 4) | (offset & 0x0fff);
+ }
+ break;
+
+ case R_ARM_THM_MOVW_ABS_NC:
+ case R_ARM_THM_MOVT_ABS:
+ {
+ /* Thumb BL and B.W instructions. Encoding:
+ *
+ * upper_insn:
+ *
+ * 1 1 1 1 1 1
+ * 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
+ * +----------+---+-------------------------------+--------------+
+ * |1 1 1 |OP1| OP2 | | 32-Bit Instructions
+ * +----------+---+--+-----+----------------------+--------------+
+ * |1 1 1 | 1 0| i | 1 0 1 1 0 0 | imm4 | MOVT Instruction
+ * +----------+------+-----+----------------------+--------------+
+ *
+ * lower_insn:
+ *
+ * 1 1 1 1 1 1
+ * 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
+ * +---+---------------------------------------------------------+
+ * |OP | | 32-Bit Instructions
+ * +---+----------+--------------+-------------------------------+
+ * |0 | imm3 | Rd | imm8 | MOVT Instruction
+ * +---+----------+--------------+-------------------------------+
+ *
+ * The 16-bit immediate value is encoded in these bits:
+ *
+ * i = imm16[11] = upper_insn[10]
+ * imm4 = imm16[12:15] = upper_insn[3:0]
+ * imm3 = imm16[8:10] = lower_insn[14:12]
+ * imm8 = imm16[0:7] = lower_insn[7:0]
+ */
+
+ upper_insn = (uint32_t)(*(uint16_t*)addr);
+ lower_insn = (uint32_t)(*(uint16_t*)(addr + 2));
+
+ bvdbg("Performing THM_MOVx [%d] link at addr=%08lx [%04x %04x] to sym=%p st_value=%08lx\n",
+ ELF32_R_TYPE(rel->r_info), (long)addr, (int)upper_insn, (int)lower_insn,
+ sym, (long)sym->st_value);
+
+ /* Extract the 16-bit offset from the 32-bit instruction */
+
+ offset = ((upper_insn & 0x000f) << 12) | /* imm4 -> imm16[8:10] */
+ ((upper_insn & 0x0400) << 1) | /* i -> imm16[11] */
+ ((lower_insn & 0x7000) >> 4) | /* imm3 -> imm16[8:10] */
+ (lower_insn & 0x00ff); /* imm8 -> imm16[0:7] */
+
+ /* Sign extend */
+
+ offset = (offset ^ 0x8000) - 0x8000;
+
+ /* And perform the relocation */
+
+ bvdbg(" offset=%08lx branch target=%08lx\n",
+ (long)offset, offset + sym->st_value);
+
+ offset += sym->st_value;
+
+ /* Update the immediate value in the instruction. For MOVW we want the bottom
+ * 16-bits; for MOVT we want the top 16-bits.
+ */
+
+ if (ELF32_R_TYPE(rel->r_info) == R_ARM_THM_MOVT_ABS)
+ {
+ offset >>= 16;
+ }
+
+ upper_insn = ((upper_insn & 0xfbf0) | ((offset & 0xf000) >> 12) | ((offset & 0x0800) >> 1));
+ *(uint16_t*)addr = (uint16_t)upper_insn;
+
+ lower_insn = ((lower_insn & 0x8f00) | ((offset & 0x0700) << 4) | (offset & 0x00ff));
+ *(uint16_t*)(addr + 2) = (uint16_t)lower_insn;
+
+ bvdbg(" insn [%04x %04x]\n",
+ (int)upper_insn, (int)lower_insn);
+ }
+ break;
+
+ default:
+ bdbg("Unsupported relocation: %d\n", ELF32_R_TYPE(rel->r_info));
+ return -EINVAL;
+ }
+
+ return OK;
+}
+
+int arch_relocateadd(FAR const Elf32_Rela *rel, FAR const Elf32_Sym *sym,
+ uintptr_t addr)
+{
+ bdbg("RELA relocation not supported\n");
+ return -ENOSYS;
+}
+
diff --git a/nuttx/arch/arm/src/armv7-m/up_exception.S b/nuttx/arch/arm/src/armv7-m/up_exception.S
index 31d8dbb0c..c9f216027 100644
--- a/nuttx/arch/arm/src/armv7-m/up_exception.S
+++ b/nuttx/arch/arm/src/armv7-m/up_exception.S
@@ -134,9 +134,9 @@ exception_common:
#if CONFIG_ARCH_INTERRUPTSTACK > 3
ldr sp, =g_intstackbase
- push r1 /* Save the MSP on the interrupt stack */
+ push {r1} /* Save the MSP on the interrupt stack */
bl up_doirq /* R0=IRQ, R1=register save area on stack */
- pop r1 /* Recover R1=main stack pointer */
+ pop {r1} /* Recover R1=main stack pointer */
#else
msr msp, r1 /* We are using the main stack pointer */
bl up_doirq /* R0=IRQ, R1=register save area on stack */
diff --git a/nuttx/arch/arm/src/armv7-m/up_hardfault.c b/nuttx/arch/arm/src/armv7-m/up_hardfault.c
index cb3ce9e8a..c30015ad2 100644
--- a/nuttx/arch/arm/src/armv7-m/up_hardfault.c
+++ b/nuttx/arch/arm/src/armv7-m/up_hardfault.c
@@ -57,9 +57,7 @@
/* Debug output from this file may interfere with context switching! */
-#undef DEBUG_HARDFAULTS /* Define to debug hard faults */
-
-#ifdef DEBUG_HARDFAULTS
+#ifdef CONFIG_DEBUG_HARDFAULT
# define hfdbg(format, arg...) lldbg(format, ##arg)
#else
# define hfdbg(x...)
diff --git a/nuttx/arch/arm/src/armv7-m/up_memcpy.S b/nuttx/arch/arm/src/armv7-m/up_memcpy.S
new file mode 100644
index 000000000..a154cab61
--- /dev/null
+++ b/nuttx/arch/arm/src/armv7-m/up_memcpy.S
@@ -0,0 +1,416 @@
+/************************************************************************************
+ * nuttx/arch/arm/src/armv7-m/up_memcpy.S
+ *
+ * armv7m-optimised memcpy, contributed by Mike Smith. Apparently in the public
+ * domain and is re-released here under the modified BSD license:
+ *
+ * Obtained via a posting on the Stellaris forum:
+ * http://e2e.ti.com/support/microcontrollers/\
+ * stellaris_arm_cortex-m3_microcontroller/f/473/t/44360.aspx
+ *
+ * Posted by rocksoft on Jul 24, 2008 10:19 AM
+ *
+ * Hi,
+ *
+ * I recently finished a "memcpy" replacement and thought it might be useful for
+ * others...
+ *
+ * I've put some instructions and the code here:
+ *
+ * http://www.rock-software.net/downloads/memcpy/
+ *
+ * Hope it works for you as well as it did for me.
+ *
+ * Liam.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ************************************************************************************/
+
+/************************************************************************************
+ * Global Symbols
+ ************************************************************************************/
+
+ .global memcpy
+
+ .syntax unified
+ .thumb
+ .cpu cortex-m3
+ .file "up_memcpy.S"
+
+/************************************************************************************
+ * .text
+ ************************************************************************************/
+
+ .text
+
+/************************************************************************************
+ * Private Constant Data
+ ************************************************************************************/
+
+/* We have 16 possible alignment combinations of src and dst, this jump table
+ * directs the copy operation
+ *
+ * Bits: Src=00, Dst=00 - Long to Long copy
+ * Bits: Src=00, Dst=01 - Long to Byte before half word
+ * Bits: Src=00, Dst=10 - Long to Half word
+ * Bits: Src=00, Dst=11 - Long to Byte before long word
+ * Bits: Src=01, Dst=00 - Byte before half word to long
+ * Bits: Src=01, Dst=01 - Byte before half word to byte before half word -
+ * Same alignment
+ * Bits: Src=01, Dst=10 - Byte before half word to half word
+ * Bits: Src=01, Dst=11 - Byte before half word to byte before long word
+ * Bits: Src=10, Dst=00 - Half word to long word
+ * Bits: Src=10, Dst=01 - Half word to byte before half word
+ * Bits: Src=10, Dst=10 - Half word to half word - Same Alignment
+ * Bits: Src=10, Dst=11 - Half word to byte before long word
+ * Bits: Src=11, Dst=00 - Byte before long word to long word
+ * Bits: Src=11, Dst=01 - Byte before long word to byte before half word
+ * Bits: Src=11, Dst=11 - Byte before long word to half word
+ * Bits: Src=11, Dst=11 - Byte before long word to Byte before long word -
+ * Same alignment
+ */
+
+MEM_DataCopyTable:
+ .byte (MEM_DataCopy0 - MEM_DataCopyJump) >> 1
+ .byte (MEM_DataCopy1 - MEM_DataCopyJump) >> 1
+ .byte (MEM_DataCopy2 - MEM_DataCopyJump) >> 1
+ .byte (MEM_DataCopy3 - MEM_DataCopyJump) >> 1
+ .byte (MEM_DataCopy4 - MEM_DataCopyJump) >> 1
+ .byte (MEM_DataCopy5 - MEM_DataCopyJump) >> 1
+ .byte (MEM_DataCopy6 - MEM_DataCopyJump) >> 1
+ .byte (MEM_DataCopy7 - MEM_DataCopyJump) >> 1
+ .byte (MEM_DataCopy8 - MEM_DataCopyJump) >> 1
+ .byte (MEM_DataCopy9 - MEM_DataCopyJump) >> 1
+ .byte (MEM_DataCopy10 - MEM_DataCopyJump) >> 1
+ .byte (MEM_DataCopy11 - MEM_DataCopyJump) >> 1
+ .byte (MEM_DataCopy12 - MEM_DataCopyJump) >> 1
+ .byte (MEM_DataCopy13 - MEM_DataCopyJump) >> 1
+ .byte (MEM_DataCopy14 - MEM_DataCopyJump) >> 1
+ .byte (MEM_DataCopy15 - MEM_DataCopyJump) >> 1
+
+ .align 2
+
+MEM_LongCopyTable:
+ .byte (MEM_LongCopyEnd - MEM_LongCopyJump) >> 1 /* 0 bytes left */
+ .byte 0 /* 4 bytes left */
+ .byte (1 * 10) >> 1 /* 8 bytes left */
+ .byte (2 * 10) >> 1 /* 12 bytes left */
+ .byte (3 * 10) >> 1 /* 16 bytes left */
+ .byte (4 * 10) >> 1 /* 20 bytes left */
+ .byte (5 * 10) >> 1 /* 24 bytes left */
+ .byte (6 * 10) >> 1 /* 28 bytes left */
+ .byte (7 * 10) >> 1 /* 32 bytes left */
+ .byte (8 * 10) >> 1 /* 36 bytes left */
+
+ .align 2
+
+/************************************************************************************
+ * Public Functions
+ ************************************************************************************/
+/************************************************************************************
+ * Name: memcpy
+ *
+ * Description:
+ * Optimised "general" copy routine
+ *
+ * Input Parameters:
+ * r0 = destination, r1 = source, r2 = length
+ *
+ ************************************************************************************/
+
+ .thumb_func
+memcpy:
+ push {r14}
+
+ /* This allows the inner workings to "assume" a minimum amount of bytes */
+ /* Quickly check for very short copies */
+
+ cmp r2, #4
+ blt MEM_DataCopyBytes
+
+ and r14, r0, #3 /* Get destination alignment bits */
+ bfi r14, r1, #2, #2 /* Get source alignment bits */
+ ldr r3, =MEM_DataCopyTable /* Jump table base */
+ tbb [r3, r14] /* Perform jump on src/dst alignment bits */
+MEM_DataCopyJump:
+
+ .align 4
+
+/* Bits: Src=01, Dst=01 - Byte before half word to byte before half word - Same alignment
+ * 3 bytes to read for long word aligning
+ */
+
+MEM_DataCopy5:
+ ldrb r3, [r1], #0x01
+ strb r3, [r0], #0x01
+ sub r2, r2, #0x01
+
+/* Bits: Src=10, Dst=10 - Half word to half word - Same Alignment
+ * 2 bytes to read for long word aligning
+ */
+
+MEM_DataCopy10:
+ ldrb r3, [r1], #0x01
+ strb r3, [r0], #0x01
+ sub r2, r2, #0x01
+
+/* Bits: Src=11, Dst=11 - Byte before long word to Byte before long word - Same alignment
+ * 1 bytes to read for long word aligning
+ */
+
+MEM_DataCopy15:
+ ldrb r3, [r1], #0x01
+ strb r3, [r0], #0x01
+ sub r2, r2, #0x01
+
+/* Bits: Src=00, Dst=00 - Long to Long copy */
+
+MEM_DataCopy0:
+ /* Save regs that may be used by memcpy */
+
+ push {r4-r12}
+
+ /* Check for short word-aligned copy */
+
+ cmp r2, #0x28
+ blt MEM_DataCopy0_2
+
+ /* Bulk copy loop */
+
+MEM_DataCopy0_1:
+ ldmia r1!, {r3-r12}
+ stmia r0!, {r3-r12}
+ sub r2, r2, #0x28
+ cmp r2, #0x28
+ bge MEM_DataCopy0_1
+
+ /* Copy remaining long words */
+
+MEM_DataCopy0_2:
+ /* Copy remaining long words */
+
+ ldr r14, =MEM_LongCopyTable
+ lsr r11, r2, #0x02
+ tbb [r14, r11]
+
+ /* longword copy branch table anchor */
+
+MEM_LongCopyJump:
+ ldr.w r3, [r1], #0x04 /* 4 bytes remain */
+ str.w r3, [r0], #0x04
+ b MEM_LongCopyEnd
+ ldmia.w r1!, {r3-r4} /* 8 bytes remain */
+ stmia.w r0!, {r3-r4}
+ b MEM_LongCopyEnd
+ ldmia.w r1!, {r3-r5} /* 12 bytes remain */
+ stmia.w r0!, {r3-r5}
+ b MEM_LongCopyEnd
+ ldmia.w r1!, {r3-r6} /* 16 bytes remain */
+ stmia.w r0!, {r3-r6}
+ b MEM_LongCopyEnd
+ ldmia.w r1!, {r3-r7} /* 20 bytes remain */
+ stmia.w r0!, {r3-r7}
+ b MEM_LongCopyEnd
+ ldmia.w r1!, {r3-r8} /* 24 bytes remain */
+ stmia.w r0!, {r3-r8}
+ b MEM_LongCopyEnd
+ ldmia.w r1!, {r3-r9} /* 28 bytes remain */
+ stmia.w r0!, {r3-r9}
+ b MEM_LongCopyEnd
+ ldmia.w r1!, {r3-r10} /* 32 bytes remain */
+ stmia.w r0!, {r3-r10}
+ b MEM_LongCopyEnd
+ ldmia.w r1!, {r3-r11} /* 36 bytes remain */
+ stmia.w r0!, {r3-r11}
+
+MEM_LongCopyEnd:
+ pop {r4-r12}
+ and r2, r2, #0x03 /* All the longs have been copied */
+
+ /* Deal with up to 3 remaining bytes */
+
+MEM_DataCopyBytes:
+ /* Deal with up to 3 remaining bytes */
+
+ cmp r2, #0x00
+ it eq
+ popeq {pc}
+ ldrb r3, [r1], #0x01
+ strb r3, [r0], #0x01
+ subs r2, r2, #0x01
+ it eq
+ popeq {pc}
+ ldrb r3, [r1], #0x01
+ strb r3, [r0], #0x01
+ subs r2, r2, #0x01
+ it eq
+ popeq {pc}
+ ldrb r3, [r1], #0x01
+ strb r3, [r0], #0x01
+ pop {pc}
+
+ .align 4
+
+/* Bits: Src=01, Dst=11 - Byte before half word to byte before long word
+ * 3 bytes to read for long word aligning the source
+ */
+
+MEM_DataCopy7:
+ ldrb r3, [r1], #0x01
+ strb r3, [r0], #0x01
+ sub r2, r2, #0x01
+
+/* Bits: Src=10, Dst=00 - Half word to long word
+ * 2 bytes to read for long word aligning the source
+ */
+
+MEM_DataCopy8:
+ ldrb r3, [r1], #0x01
+ strb r3, [r0], #0x01
+ sub r2, r2, #0x01
+
+/* Bits: Src=11, Dst=01 - Byte before long word to byte before half word
+ * 1 byte to read for long word aligning the source
+ */
+
+MEM_DataCopy13:
+ ldrb r3, [r1], #0x01
+ strb r3, [r0], #0x01
+ sub r2, r2, #0x01
+
+/* Bits: Src=00, Dst=10 - Long to Half word */
+
+MEM_DataCopy2:
+ cmp r2, #0x28
+ blt MEM_DataCopy2_1
+
+ /* Save regs */
+
+ push {r4-r12}
+
+ /* Bulk copy loop */
+
+MEM_DataCopy2_2:
+ ldmia r1!, {r3-r12}
+
+ strh r3, [r0], #0x02
+
+ lsr r3, r3, #0x10
+ bfi r3, r4, #0x10, #0x10
+ lsr r4, r4, #0x10
+ bfi r4, r5, #0x10, #0x10
+ lsr r5, r5, #0x10
+ bfi r5, r6, #0x10, #0x10
+ lsr r6, r6, #0x10
+ bfi r6, r7, #0x10, #0x10
+ lsr r7, r7, #0x10
+ bfi r7, r8, #0x10, #0x10
+ lsr r8, r8, #0x10
+ bfi r8, r9, #0x10, #0x10
+ lsr r9, r9, #0x10
+ bfi r9, r10, #0x10, #0x10
+ lsr r10, r10, #0x10
+ bfi r10, r11, #0x10, #0x10
+ lsr r11, r11, #0x10
+ bfi r11, r12, #0x10, #0x10
+ stmia r0!, {r3-r11}
+ lsr r12, r12, #0x10
+ strh r12, [r0], #0x02
+
+ sub r2, r2, #0x28
+ cmp r2, #0x28
+ bge MEM_DataCopy2_2
+ pop {r4-r12}
+
+MEM_DataCopy2_1: /* Read longs and write 2 x half words */
+ cmp r2, #4
+ blt MEM_DataCopyBytes
+ ldr r3, [r1], #0x04
+ strh r3, [r0], #0x02
+ lsr r3, r3, #0x10
+ strh r3, [r0], #0x02
+ sub r2, r2, #0x04
+ b MEM_DataCopy2
+
+/* Bits: Src=01, Dst=00 - Byte before half word to long
+ * Bits: Src=01, Dst=10 - Byte before half word to half word
+ * 3 bytes to read for long word aligning the source
+ */
+
+MEM_DataCopy4:
+MEM_DataCopy6:
+ /* Read B and write B */
+
+ ldrb r3, [r1], #0x01
+ strb r3, [r0], #0x01
+ sub r2, r2, #0x01
+
+/* Bits: Src=10, Dst=01 - Half word to byte before half word
+ * Bits: Src=10, Dst=11 - Half word to byte before long word
+ * 2 bytes to read for long word aligning the source
+ */
+
+MEM_DataCopy9:
+MEM_DataCopy11:
+ ldrb r3, [r1], #0x01
+ strb r3, [r0], #0x01
+ sub r2, r2, #0x01
+
+/* Bits: Src=11, Dst=00 -chm Byte before long word to long word
+ * Bits: Src=11, Dst=11 - Byte before long word to half word
+ * 1 byte to read for long word aligning the source
+ */
+
+MEM_DataCopy12:
+MEM_DataCopy14:
+ /* Read B and write B */
+
+ ldrb r3, [r1], #0x01
+ strb r3, [r0], #0x01
+ sub r2, r2, #0x01
+
+/* Bits: Src=00, Dst=01 - Long to Byte before half word
+ * Bits: Src=00, Dst=11 - Long to Byte before long word
+ */
+
+MEM_DataCopy1: /* Read longs, write B->H->B */
+MEM_DataCopy3:
+ cmp r2, #4
+ blt MEM_DataCopyBytes
+ ldr r3, [r1], #0x04
+ strb r3, [r0], #0x01
+ lsr r3, r3, #0x08
+ strh r3, [r0], #0x02
+ lsr r3, r3, #0x10
+ strb r3, [r0], #0x01
+ sub r2, r2, #0x04
+ b MEM_DataCopy3
+
+ .size memcpy, .-memcpy
+ .end
diff --git a/nuttx/lib/string/lib_memset.c b/nuttx/arch/arm/src/common/arm-elf.h
index 916351b97..fac387b11 100644
--- a/nuttx/lib/string/lib_memset.c
+++ b/nuttx/arch/arm/src/common/arm-elf.h
@@ -1,7 +1,7 @@
-/************************************************************
- * lib/string/lib_memset.c
+/****************************************************************************
+ * arch/arm/src/common/arm-elf.h
*
- * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -31,29 +31,23 @@
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
- ************************************************************/
+ ****************************************************************************/
-/************************************************************
- * Compilation Switches
- ************************************************************/
+#ifndef __ARCH_ARM_SRC_ARM_ELF_H
+#define __ARCH_ARM_SRC_ARM_ELF_H
-/************************************************************
+/****************************************************************************
* Included Files
- ************************************************************/
+ ****************************************************************************/
#include <nuttx/config.h>
-#include <sys/types.h>
-#include <string.h>
-/************************************************************
- * Global Functions
- ************************************************************/
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
-#ifndef CONFIG_ARCH_MEMSET
-void *memset(void *s, int c, size_t n)
-{
- unsigned char *p = (unsigned char*)s;
- while (n-- > 0) *p++ = c;
- return s;
-}
-#endif
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+#endif /* __ARCH_ARM_SRC_ARM_ELF_H */
diff --git a/nuttx/arch/arm/src/stm32/Kconfig b/nuttx/arch/arm/src/stm32/Kconfig
index 2f9100236..99dde3209 100644
--- a/nuttx/arch/arm/src/stm32/Kconfig
+++ b/nuttx/arch/arm/src/stm32/Kconfig
@@ -34,6 +34,27 @@ config ARCH_CHIP_STM32F100RB
select STM32_STM32F10XX
select STM32_VALUELINE
+config ARCH_CHIP_STM32F100RC
+ bool "STM32F100RC"
+ select ARCH_CORTEXM3
+ select STM32_STM32F10XX
+ select STM32_VALUELINE
+ select STM32_HIGHDENSITY
+
+config ARCH_CHIP_STM32F100RD
+ bool "STM32F100RD"
+ select ARCH_CORTEXM3
+ select STM32_STM32F10XX
+ select STM32_VALUELINE
+ select STM32_HIGHDENSITY
+
+config ARCH_CHIP_STM32F100RE
+ bool "STM32F100RE"
+ select ARCH_CORTEXM3
+ select STM32_STM32F10XX
+ select STM32_VALUELINE
+ select STM32_HIGHDENSITY
+
config ARCH_CHIP_STM32F100V8
bool "STM32F100V8"
select ARCH_CORTEXM3
@@ -46,6 +67,27 @@ config ARCH_CHIP_STM32F100VB
select STM32_STM32F10XX
select STM32_VALUELINE
+config ARCH_CHIP_STM32F100VC
+ bool "STM32F100VC"
+ select ARCH_CORTEXM3
+ select STM32_STM32F10XX
+ select STM32_VALUELINE
+ select STM32_HIGHDENSITY
+
+config ARCH_CHIP_STM32F100VD
+ bool "STM32F100VD"
+ select ARCH_CORTEXM3
+ select STM32_STM32F10XX
+ select STM32_VALUELINE
+ select STM32_HIGHDENSITY
+
+config ARCH_CHIP_STM32F100VE
+ bool "STM32F100VE"
+ select ARCH_CORTEXM3
+ select STM32_STM32F10XX
+ select STM32_VALUELINE
+ select STM32_HIGHDENSITY
+
config ARCH_CHIP_STM32F103RET6
bool "STM32F103RET6"
select ARCH_CORTEXM3
@@ -108,7 +150,7 @@ config ARCH_CHIP_STM32F407VE
config ARCH_CHIP_STM32F407VG
bool "STM32F407VG"
- select ARCH_CORTEXM3
+ select ARCH_CORTEXM4
select STM32_STM32F40XX
config ARCH_CHIP_STM32F407ZE
@@ -151,37 +193,10 @@ config STM32_STM32F20XX
config STM32_STM32F40XX
bool
-choice
- prompt "Toolchain Selection"
- default STM32_CODESOURCERYW
- depends on ARCH_CHIP_STM32
-
-config STM32_CODESOURCERYW
- bool "CodeSourcery for Windows"
-
-config STM32_CODESOURCERYL
- bool "CodeSourcery for Linux"
-
-config STM32_ATOLLIC_LITE
- bool "Atollic Lite for Windows"
-
-config STM32_ATOLLIC_PRO
- bool "Atollic Pro for Windows"
-
-config STM32_DEVKITARM
- bool "DevkitARM (Windows)"
-
-config STM32_RAISONANCE
- bool "STMicro Raisonance for Windows"
-
-config STM32_BUILDROOT
- bool "NuttX buildroot (Cygwin or Linux)"
-
-endchoice
-
config STM32_DFU
bool "DFU bootloader"
default n
+ depends on !STM32_VALUELINE
---help---
Configure and position code for use with the STMicro DFU bootloader. Do
not select this option if you will load code using JTAG/SWM.
@@ -197,25 +212,13 @@ config STM32_ADC2
bool "ADC2"
default n
select STM32_ADC
+ depends on !STM32_VALUELINE
config STM32_ADC3
bool "ADC3"
default n
select STM32_ADC
-
-config STM32_CRC
- bool "CRC"
- default n
-
-config STM32_DMA1
- bool "DMA1"
- default n
- select ARCH_DMA
-
-config STM32_DMA2
- bool "DMA2"
- default n
- select ARCH_DMA
+ depends on !STM32_VALUELINE
config STM32_BKP
bool "BKP"
@@ -232,6 +235,7 @@ config STM32_CAN1
default n
select CAN
select STM32_CAN
+ depends on !STM32_VALUELINE
config STM32_CAN2
bool "CAN2"
@@ -245,11 +249,31 @@ config STM32_CCMDATARAM
default n
depends on STM32_STM32F40XX
+config STM32_CEC
+ bool "CEC"
+ default n
+ depends on STM32_VALUELINE
+
+config STM32_CRC
+ bool "CRC"
+ default n
+
config STM32_CRYP
bool "CRYP"
default n
depends on STM32_STM32F20XX || STM32_STM32F40XX
+config STM32_DMA1
+ bool "DMA1"
+ default n
+ select ARCH_DMA
+
+config STM32_DMA2
+ bool "DMA2"
+ default n
+ select ARCH_DMA
+ depends on !STM32_VALUELINE || (STM32_VALUELINE && STM32_HIGHDENSITY)
+
config STM32_DAC1
bool "DAC1"
default n
@@ -274,7 +298,7 @@ config STM32_ETHMAC
config STM32_FSMC
bool "FSMC"
default n
- depends on !STM32_CONNECTIVITYLINE
+ depends on !STM32_CONNECTIVITYLINE && (STM32_HIGHDENSITY || STM32_STM32F20XX || STM32_STM32F40XX)
config STM32_HASH
bool "HASH"
@@ -325,7 +349,7 @@ config STM32_RNG
config STM32_SDIO
bool "SDIO"
default n
- depends on !STM32_CONNECTIVITYLINE
+ depends on !STM32_CONNECTIVITYLINE && !STM32_VALUELINE
config STM32_SPI1
bool "SPI1"
@@ -342,7 +366,7 @@ config STM32_SPI2
config STM32_SPI3
bool "SPI3"
default n
- depends on STM32_CONNECTIVITYLINE || STM32_STM32F20XX || STM32_STM32F40XX
+ depends on STM32_CONNECTIVITYLINE || STM32_STM32F20XX || STM32_STM32F40XX || (STM32_VALUELINE && STM32_HIGHDENSITY)
select SPI
select STM32_SPI
@@ -382,6 +406,7 @@ config STM32_TIM7
config STM32_TIM8
bool "TIM8"
default n
+ depends on !STM32_VALUELINE
config STM32_TIM9
bool "TIM9"
@@ -401,17 +426,32 @@ config STM32_TIM11
config STM32_TIM12
bool "TIM12"
default n
- depends on STM32_STM32F20XX || STM32_STM32F40XX
+ depends on STM32_STM32F20XX || STM32_STM32F40XX || STM32_VALUELINE
config STM32_TIM13
bool "TIM13"
default n
- depends on STM32_STM32F20XX || STM32_STM32F40XX
+ depends on STM32_STM32F20XX || STM32_STM32F40XX || STM32_VALUELINE
config STM32_TIM14
bool "TIM14"
default n
- depends on STM32_STM32F20XX || STM32_STM32F40XX
+ depends on STM32_STM32F20XX || STM32_STM32F40XX || STM32_VALUELINE
+
+config STM32_TIM15
+ bool "TIM15"
+ default n
+ depends on STM32_VALUELINE
+
+config STM32_TIM16
+ bool "TIM16"
+ default n
+ depends on STM32_VALUELINE
+
+config STM32_TIM17
+ bool "TIM17"
+ default n
+ depends on STM32_VALUELINE
config STM32_USART1
bool "USART1"
@@ -447,7 +487,7 @@ config STM32_USART6
config STM32_USB
bool "USB Device"
default n
- depends on STM32_STM32F10XX
+ depends on STM32_STM32F10XX && !STM32_VALUELINE
select USBDEV
config STM32_WWDG
@@ -475,6 +515,52 @@ config STM32_CAN
menu "Alternate Pin Mapping"
choice
+ prompt "CAN1 Alternate Pin Mappings"
+ depends on STM32_STM32F10XX && STM32_CAN1
+ default STM32_CAN1_NO_REMAP
+
+config STM32_CAN1_NO_REMAP
+ bool "No pin remapping"
+
+config STM32_CAN1_REMAP1
+ bool "CAN1 alternate pin remapping #1"
+
+config STM32_CAN1_REMAP2
+ bool "CAN1 alternate pin remapping #2"
+
+endchoice
+
+config STM32_CAN2_REMAP
+ bool "CAN2 Alternate Pin Mapping"
+ default n
+ depends on STM32_CONNECTIVITYLINE && STM32_CAN2
+
+config STM32_CEC_REMAP
+ bool "CEC Alternate Pin Mapping"
+ default n
+ depends on STM32_STM32F10XX && STM32_CEC
+
+config STM32_ETH_REMAP
+ bool "Ethernet Alternate Pin Mapping"
+ default n
+ depends on STM32_CONNECTIVITYLINE && STM32_ETHMAC
+
+config STM32_I2C1_REMAP
+ bool "I2C1 Alternate Pin Mapping"
+ default n
+ depends on STM32_STM32F10XX && STM32_I2C1
+
+config STM32_SPI1_REMAP
+ bool "SPI1 Alternate Pin Mapping"
+ default n
+ depends on STM32_STM32F10XX && STM32_SPI1
+
+config STM32_SPI3_REMAP
+ bool "SPI3 Alternate Pin Mapping"
+ default n
+ depends on STM32_STM32F10XX && STM32_SPI3 && !STM32_VALUELINE
+
+choice
prompt "TIM1 Alternate Pin Mappings"
depends on STM32_STM32F10XX && STM32_TIM1
default STM32_TIM1_NO_REMAP
@@ -530,6 +616,51 @@ config STM32_TIM4_REMAP
default n
depends on STM32_STM32F10XX && STM32_TIM4
+config STM32_TIM9_REMAP
+ bool "TIM9 Alternate Pin Mapping"
+ default n
+ depends on STM32_STM32F10XX && STM32_TIM9
+
+config STM32_TIM10_REMAP
+ bool "TIM10 Alternate Pin Mapping"
+ default n
+ depends on STM32_STM32F10XX && STM32_TIM10
+
+config STM32_TIM11_REMAP
+ bool "TIM11 Alternate Pin Mapping"
+ default n
+ depends on STM32_STM32F10XX && STM32_TIM11
+
+config STM32_TIM12_REMAP
+ bool "TIM12 Alternate Pin Mapping"
+ default n
+ depends on STM32_STM32F10XX && STM32_TIM12
+
+config STM32_TIM13_REMAP
+ bool "TIM13 Alternate Pin Mapping"
+ default n
+ depends on STM32_STM32F10XX && STM32_TIM13
+
+config STM32_TIM14_REMAP
+ bool "TIM14 Alternate Pin Mapping"
+ default n
+ depends on STM32_STM32F10XX && STM32_TIM14
+
+config STM32_TIM15_REMAP
+ bool "TIM15 Alternate Pin Mapping"
+ default n
+ depends on STM32_STM32F10XX && STM32_TIM15
+
+config STM32_TIM16_REMAP
+ bool "TIM16 Alternate Pin Mapping"
+ default n
+ depends on STM32_STM32F10XX && STM32_TIM16
+
+config STM32_TIM17_REMAP
+ bool "TIM17 Alternate Pin Mapping"
+ default n
+ depends on STM32_STM32F10XX && STM32_TIM17
+
config STM32_USART1_REMAP
bool "USART1 Alternate Pin Mapping"
default n
@@ -556,48 +687,16 @@ config STM32_USART3_PARTIAL_REMAP
endchoice
-config STM32_SPI1_REMAP
- bool "SPI1 Alternate Pin Mapping"
- default n
- depends on STM32_STM32F10XX && STM32_SPI1
-
-config STM32_SPI3_REMAP
- bool "SPI3 Alternate Pin Mapping"
- default n
- depends on STM32_STM32F10XX && STM32_SPI3
-
-config STM32_I2C1_REMAP
- bool "I2C1 Alternate Pin Mapping"
- default n
- depends on STM32_STM32F10XX && STM32_I2C1
-
-choice
- prompt "CAN1 Alternate Pin Mappings"
- depends on STM32_STM32F10XX && STM32_CAN1
- default STM32_CAN1_NO_REMAP
-
-config STM32_CAN1_NO_REMAP
- bool "No pin remapping"
-
-config STM32_CAN1_REMAP1
- bool "CAN1 alternate pin remapping #1"
-
-config STM32_CAN1_REMAP2
- bool "CAN1 alternate pin remapping #2"
-
-endchoice
-
-config STM32_CAN2_REMAP
- bool "CAN2 Alternate Pin Mapping"
- default n
- depends on STM32_CONNECTIVITYLINE && STM32_CAN2
+endmenu
-config STM32_ETH_REMAP
- bool "Ethernet Alternate Pin Mapping"
+config STM32_FLASH_PREFETCH
+ bool "Enable FLASH Pre-fetch"
+ depends on STM32_STM32F20XX || STM32_STM32F40XX
default n
- depends on STM32_CONNECTIVITYLINE && STM32_ETHMAC
-
-endmenu
+ ---help---
+ Enable FLASH prefetch and F2 and F4 parts (FLASH pre-fetch is always enabled
+ on F1 parts). Some early revisions of F4 parts do not support FLASH pre-fetch
+ properly and enabling this option may interfere with ADC accuracy.
choice
prompt "JTAG Configuration"
@@ -636,9 +735,11 @@ config ARCH_BOARD_STM32_CUSTOM_CLOCKCONFIG
config STM32_CCMEXCLUDE
bool "Exclude CCM SRAM from the heap"
depends on STM32_STM32F20XX || STM32_STM32F40XX
- default y if ARCH_DMA
+ default y if ARCH_DMA || ELF
---help---
- Exclude CCM SRAM from the HEAP because it cannot be used for DMA.
+ Exclude CCM SRAM from the HEAP because (1) it cannot be used for DMA
+ and (2) it appears to be impossible to execute ELF modules from CCM
+ RAM.
config STM32_FSMC_SRAM
bool "External SRAM on FSMC"
@@ -663,6 +764,7 @@ config STM32_TIM1_PWM
config STM32_TIM1_CHANNEL
int "TIM1 PWM Output Channel"
default 1
+ range 1 4
depends on STM32_TIM1_PWM
---help---
If TIM1 is enabled for PWM usage, you also need specifies the timer output
@@ -673,7 +775,7 @@ config STM32_TIM2_PWM
default n
depends on STM32_TIM2
---help---
- Reserve timer 1 for use by PWM
+ Reserve timer 2 for use by PWM
Timer devices may be used for different purposes. One special purpose is
to generate modulated outputs for such things as motor control. If STM32_TIM2
@@ -683,6 +785,7 @@ config STM32_TIM2_PWM
config STM32_TIM2_CHANNEL
int "TIM2 PWM Output Channel"
default 1
+ range 1 4
depends on STM32_TIM2_PWM
---help---
If TIM2 is enabled for PWM usage, you also need specifies the timer output
@@ -693,7 +796,7 @@ config STM32_TIM3_PWM
default n
depends on STM32_TIM3
---help---
- Reserve timer 1 for use by PWM
+ Reserve timer 3 for use by PWM
Timer devices may be used for different purposes. One special purpose is
to generate modulated outputs for such things as motor control. If STM32_TIM3
@@ -703,6 +806,7 @@ config STM32_TIM3_PWM
config STM32_TIM3_CHANNEL
int "TIM3 PWM Output Channel"
default 1
+ range 1 4
depends on STM32_TIM3_PWM
---help---
If TIM3 is enabled for PWM usage, you also need specifies the timer output
@@ -713,7 +817,7 @@ config STM32_TIM4_PWM
default n
depends on STM32_TIM4
---help---
- Reserve timer 1 for use by PWM
+ Reserve timer 4 for use by PWM
Timer devices may be used for different purposes. One special purpose is
to generate modulated outputs for such things as motor control. If STM32_TIM4
@@ -723,6 +827,7 @@ config STM32_TIM4_PWM
config STM32_TIM4_CHANNEL
int "TIM4 PWM Output Channel"
default 1
+ range 1 4
depends on STM32_TIM4_PWM
---help---
If TIM4 is enabled for PWM usage, you also need specifies the timer output
@@ -733,7 +838,7 @@ config STM32_TIM5_PWM
default n
depends on STM32_TIM5
---help---
- Reserve timer 1 for use by PWM
+ Reserve timer 5 for use by PWM
Timer devices may be used for different purposes. One special purpose is
to generate modulated outputs for such things as motor control. If STM32_TIM5
@@ -743,6 +848,7 @@ config STM32_TIM5_PWM
config STM32_TIM5_CHANNEL
int "TIM5 PWM Output Channel"
default 1
+ range 1 4
depends on STM32_TIM5_PWM
---help---
If TIM5 is enabled for PWM usage, you also need specifies the timer output
@@ -753,7 +859,7 @@ config STM32_TIM8_PWM
default n
depends on STM32_TIM8
---help---
- Reserve timer 1 for use by PWM
+ Reserve timer 8 for use by PWM
Timer devices may be used for different purposes. One special purpose is
to generate modulated outputs for such things as motor control. If STM32_TIM8
@@ -763,6 +869,7 @@ config STM32_TIM8_PWM
config STM32_TIM8_CHANNEL
int "TIM8 PWM Output Channel"
default 1
+ range 1 4
depends on STM32_TIM8_PWM
---help---
If TIM8 is enabled for PWM usage, you also need specifies the timer output
@@ -773,7 +880,7 @@ config STM32_TIM9_PWM
default n
depends on STM32_TIM9
---help---
- Reserve timer 1 for use by PWM
+ Reserve timer 9 for use by PWM
Timer devices may be used for different purposes. One special purpose is
to generate modulated outputs for such things as motor control. If STM32_TIM9
@@ -783,6 +890,7 @@ config STM32_TIM9_PWM
config STM32_TIM9_CHANNEL
int "TIM9 PWM Output Channel"
default 1
+ range 1 4
depends on STM32_TIM9_PWM
---help---
If TIM9 is enabled for PWM usage, you also need specifies the timer output
@@ -793,7 +901,7 @@ config STM32_TIM10_PWM
default n
depends on STM32_TIM10
---help---
- Reserve timer 1 for use by PWM
+ Reserve timer 10 for use by PWM
Timer devices may be used for different purposes. One special purpose is
to generate modulated outputs for such things as motor control. If STM32_TIM10
@@ -803,6 +911,7 @@ config STM32_TIM10_PWM
config STM32_TIM10_CHANNEL
int "TIM10 PWM Output Channel"
default 1
+ range 1 4
depends on STM32_TIM10_PWM
---help---
If TIM10 is enabled for PWM usage, you also need specifies the timer output
@@ -813,7 +922,7 @@ config STM32_TIM11_PWM
default n
depends on STM32_TIM11
---help---
- Reserve timer 1 for use by PWM
+ Reserve timer 11 for use by PWM
Timer devices may be used for different purposes. One special purpose is
to generate modulated outputs for such things as motor control. If STM32_TIM11
@@ -823,6 +932,7 @@ config STM32_TIM11_PWM
config STM32_TIM11_CHANNEL
int "TIM11 PWM Output Channel"
default 1
+ range 1 4
depends on STM32_TIM11_PWM
---help---
If TIM11 is enabled for PWM usage, you also need specifies the timer output
@@ -833,7 +943,7 @@ config STM32_TIM12_PWM
default n
depends on STM32_TIM12
---help---
- Reserve timer 1 for use by PWM
+ Reserve timer 12 for use by PWM
Timer devices may be used for different purposes. One special purpose is
to generate modulated outputs for such things as motor control. If STM32_TIM12
@@ -843,6 +953,7 @@ config STM32_TIM12_PWM
config STM32_TIM12_CHANNEL
int "TIM12 PWM Output Channel"
default 1
+ range 1 4
depends on STM32_TIM12_PWM
---help---
If TIM12 is enabled for PWM usage, you also need specifies the timer output
@@ -853,7 +964,7 @@ config STM32_TIM13_PWM
default n
depends on STM32_TIM13
---help---
- Reserve timer 1 for use by PWM
+ Reserve timer 13 for use by PWM
Timer devices may be used for different purposes. One special purpose is
to generate modulated outputs for such things as motor control. If STM32_TIM13
@@ -863,6 +974,7 @@ config STM32_TIM13_PWM
config STM32_TIM13_CHANNEL
int "TIM13 PWM Output Channel"
default 1
+ range 1 4
depends on STM32_TIM13_PWM
---help---
If TIM13 is enabled for PWM usage, you also need specifies the timer output
@@ -873,7 +985,7 @@ config STM32_TIM14_PWM
default n
depends on STM32_TIM14
---help---
- Reserve timer 1 for use by PWM
+ Reserve timer 14 for use by PWM
Timer devices may be used for different purposes. One special purpose is
to generate modulated outputs for such things as motor control. If STM32_TIM14
@@ -883,11 +995,75 @@ config STM32_TIM14_PWM
config STM32_TIM14_CHANNEL
int "TIM14 PWM Output Channel"
default 1
+ range 1 4
depends on STM32_TIM14_PWM
---help---
If TIM14 is enabled for PWM usage, you also need specifies the timer output
channel {1,..,4}
+config STM32_TIM15_PWM
+ bool "TIM15 PWM"
+ default n
+ depends on STM32_TIM15
+ ---help---
+ Reserve timer 15 for use by PWM
+
+ Timer devices may be used for different purposes. One special purpose is
+ to generate modulated outputs for such things as motor control. If STM32_TIM15
+ is defined then THIS following may also be defined to indicate that
+ the timer is intended to be used for pulsed output modulation.
+
+config STM32_TIM15_CHANNEL
+ int "TIM15 PWM Output Channel"
+ default 1
+ range 1 2
+ depends on STM32_TIM15_PWM
+ ---help---
+ If TIM15 is enabled for PWM usage, you also need specifies the timer output
+ channel {1,2}
+
+config STM32_TIM16_PWM
+ bool "TIM16 PWM"
+ default n
+ depends on STM32_TIM16
+ ---help---
+ Reserve timer 16 for use by PWM
+
+ Timer devices may be used for different purposes. One special purpose is
+ to generate modulated outputs for such things as motor control. If STM32_TIM16
+ is defined then THIS following may also be defined to indicate that
+ the timer is intended to be used for pulsed output modulation.
+
+config STM32_TIM16_CHANNEL
+ int "TIM16 PWM Output Channel"
+ default 1
+ range 1 1
+ depends on STM32_TIM16_PWM
+ ---help---
+ If TIM16 is enabled for PWM usage, you also need specifies the timer output
+ channel {1}
+
+config STM32_TIM17_PWM
+ bool "TIM17 PWM"
+ default n
+ depends on STM32_TIM17
+ ---help---
+ Reserve timer 17 for use by PWM
+
+ Timer devices may be used for different purposes. One special purpose is
+ to generate modulated outputs for such things as motor control. If STM32_TIM17
+ is defined then THIS following may also be defined to indicate that
+ the timer is intended to be used for pulsed output modulation.
+
+config STM32_TIM17_CHANNEL
+ int "TIM17 PWM Output Channel"
+ default 1
+ range 1 1
+ depends on STM32_TIM17_PWM
+ ---help---
+ If TIM17 is enabled for PWM usage, you also need specifies the timer output
+ channel {1}
+
config STM32_TIM1_ADC
bool "TIM1 ADC"
default n
@@ -909,16 +1085,22 @@ choice
config STM32_TIM1_ADC1
bool "TIM1 ADC channel 1"
+ depends on STM32_ADC1
+ select HAVE_ADC1_TIMER
---help---
Reserve TIM1 to trigger ADC1
config STM32_TIM1_ADC2
bool "TIM1 ADC channel 2"
+ depends on STM32_ADC2
+ select HAVE_ADC2_TIMER
---help---
Reserve TIM1 to trigger ADC2
config STM32_TIM1_ADC3
bool "TIM1 ADC channel 3"
+ depends on STM32_ADC3
+ select HAVE_ADC3_TIMER
---help---
Reserve TIM1 to trigger ADC3
@@ -945,16 +1127,22 @@ choice
config STM32_TIM2_ADC1
bool "TIM2 ADC channel 1"
+ depends on STM32_ADC1
+ select HAVE_ADC1_TIMER
---help---
Reserve TIM2 to trigger ADC1
config STM32_TIM2_ADC2
bool "TIM2 ADC channel 2"
+ depends on STM32_ADC2
+ select HAVE_ADC2_TIMER
---help---
Reserve TIM2 to trigger ADC2
config STM32_TIM2_ADC3
bool "TIM2 ADC channel 3"
+ depends on STM32_ADC3
+ select HAVE_ADC3_TIMER
---help---
Reserve TIM2 to trigger ADC3
@@ -981,16 +1169,22 @@ choice
config STM32_TIM3_ADC1
bool "TIM3 ADC channel 1"
+ depends on STM32_ADC1
+ select HAVE_ADC1_TIMER
---help---
Reserve TIM3 to trigger ADC1
config STM32_TIM3_ADC2
bool "TIM3 ADC channel 2"
+ depends on STM32_ADC2
+ select HAVE_ADC2_TIMER
---help---
Reserve TIM3 to trigger ADC2
config STM32_TIM3_ADC3
bool "TIM3 ADC channel 3"
+ depends on STM32_ADC3
+ select HAVE_ADC3_TIMER
---help---
Reserve TIM3 to trigger ADC3
@@ -1017,16 +1211,22 @@ choice
config STM32_TIM4_ADC1
bool "TIM4 ADC channel 1"
+ depends on STM32_ADC1
+ select HAVE_ADC1_TIMER
---help---
Reserve TIM4 to trigger ADC1
config STM32_TIM4_ADC2
bool "TIM4 ADC channel 2"
+ depends on STM32_ADC2
+ select HAVE_ADC2_TIMER
---help---
Reserve TIM4 to trigger ADC2
config STM32_TIM4_ADC3
bool "TIM4 ADC channel 3"
+ depends on STM32_ADC3
+ select HAVE_ADC3_TIMER
---help---
Reserve TIM4 to trigger ADC3
@@ -1053,16 +1253,22 @@ choice
config STM32_TIM5_ADC1
bool "TIM5 ADC channel 1"
+ depends on STM32_ADC1
+ select HAVE_ADC1_TIMER
---help---
Reserve TIM5 to trigger ADC1
config STM32_TIM5_ADC2
bool "TIM5 ADC channel 2"
+ depends on STM32_ADC2
+ select HAVE_ADC2_TIMER
---help---
Reserve TIM5 to trigger ADC2
config STM32_TIM5_ADC3
bool "TIM5 ADC channel 3"
+ depends on STM32_ADC3
+ select HAVE_ADC3_TIMER
---help---
Reserve TIM5 to trigger ADC3
@@ -1089,21 +1295,81 @@ choice
config STM32_TIM8_ADC1
bool "TIM8 ADC channel 1"
+ depends on STM32_ADC1
+ select HAVE_ADC1_TIMER
---help---
Reserve TIM8 to trigger ADC1
config STM32_TIM8_ADC2
bool "TIM8 ADC channel 2"
+ depends on STM32_ADC2
+ select HAVE_ADC2_TIMER
---help---
Reserve TIM8 to trigger ADC2
config STM32_TIM8_ADC3
bool "TIM8 ADC channel 3"
+ depends on STM32_ADC3
+ select HAVE_ADC3_TIMER
---help---
Reserve TIM8 to trigger ADC3
endchoice
+config HAVE_ADC1_TIMER
+ bool
+
+config HAVE_ADC2_TIMER
+ bool
+
+config HAVE_ADC3_TIMER
+ bool
+
+config STM32_ADC1_SAMPLE_FREQUENCY
+ int "ADC1 Sampling Frequency"
+ default 100
+ depends on HAVE_ADC1_TIMER
+ ---help---
+ ADC1 sampling frequency. Default: 100Hz
+
+config STM32_ADC1_TIMTRIG
+ int "ADC1 Timer Trigger"
+ default 0
+ range 0 4
+ depends on HAVE_ADC1_TIMER
+ ---help---
+ Values 0:CC1 1:CC2 2:CC3 3:CC4 4:TRGO
+
+config STM32_ADC2_SAMPLE_FREQUENCY
+ int "ADC2 Sampling Frequency"
+ default 100
+ depends on HAVE_ADC2_TIMER
+ ---help---
+ ADC2 sampling frequency. Default: 100Hz
+
+config STM32_ADC2_TIMTRIG
+ int "ADC2 Timer Trigger"
+ default 0
+ range 0 4
+ depends on HAVE_ADC2_TIMER
+ ---help---
+ Values 0:CC1 1:CC2 2:CC3 3:CC4 4:TRGO
+
+config STM32_ADC3_SAMPLE_FREQUENCY
+ int "ADC3 Sampling Frequency"
+ default 100
+ depends on HAVE_ADC3_TIMER
+ ---help---
+ ADC3 sampling frequency. Default: 100Hz
+
+config STM32_ADC3_TIMTRIG
+ int "ADC3 Timer Trigger"
+ default 0
+ range 0 4
+ depends on HAVE_ADC3_TIMER
+ ---help---
+ Values 0:CC1 1:CC2 2:CC3 3:CC4 4:TRGO
+
config STM32_TIM1_DAC
bool "TIM1 DAC"
default n
@@ -1140,7 +1406,7 @@ config STM32_TIM2_DAC
default n
depends on STM32_TIM2 && STM32_DAC
---help---
- Reserve timer 1 for use by DAC
+ Reserve timer 2 for use by DAC
Timer devices may be used for different purposes. If STM32_TIM2 is
defined then the following may also be defined to indicate that the
@@ -1171,7 +1437,7 @@ config STM32_TIM3_DAC
default n
depends on STM32_TIM3 && STM32_DAC
---help---
- Reserve timer 1 for use by DAC
+ Reserve timer 3 for use by DAC
Timer devices may be used for different purposes. If STM32_TIM3 is
defined then the following may also be defined to indicate that the
@@ -1202,7 +1468,7 @@ config STM32_TIM4_DAC
default n
depends on STM32_TIM4 && STM32_DAC
---help---
- Reserve timer 1 for use by DAC
+ Reserve timer 4 for use by DAC
Timer devices may be used for different purposes. If STM32_TIM4 is
defined then the following may also be defined to indicate that the
@@ -1233,7 +1499,7 @@ config STM32_TIM5_DAC
default n
depends on STM32_TIM5 && STM32_DAC
---help---
- Reserve timer 1 for use by DAC
+ Reserve timer 5 for use by DAC
Timer devices may be used for different purposes. If STM32_TIM5 is
defined then the following may also be defined to indicate that the
@@ -1264,7 +1530,7 @@ config STM32_TIM6_DAC
default n
depends on STM32_TIM6 && STM32_DAC
---help---
- Reserve timer 1 for use by DAC
+ Reserve timer 6 for use by DAC
Timer devices may be used for different purposes. If STM32_TIM6 is
defined then the following may also be defined to indicate that the
@@ -1295,7 +1561,7 @@ config STM32_TIM7_DAC
default n
depends on STM32_TIM7 && STM32_DAC
---help---
- Reserve timer 1 for use by DAC
+ Reserve timer 7 for use by DAC
Timer devices may be used for different purposes. If STM32_TIM7 is
defined then the following may also be defined to indicate that the
@@ -1326,7 +1592,7 @@ config STM32_TIM8_DAC
default n
depends on STM32_TIM8 && STM32_DAC
---help---
- Reserve timer 1 for use by DAC
+ Reserve timer 8 for use by DAC
Timer devices may be used for different purposes. If STM32_TIM8 is
defined then the following may also be defined to indicate that the
@@ -1357,7 +1623,7 @@ config STM32_TIM9_DAC
default n
depends on STM32_TIM9 && STM32_DAC
---help---
- Reserve timer 1 for use by DAC
+ Reserve timer 9 for use by DAC
Timer devices may be used for different purposes. If STM32_TIM9 is
defined then the following may also be defined to indicate that the
@@ -1388,7 +1654,7 @@ config STM32_TIM10_DAC
default n
depends on STM32_TIM10 && STM32_DAC
---help---
- Reserve timer 1 for use by DAC
+ Reserve timer 10 for use by DAC
Timer devices may be used for different purposes. If STM32_TIM10 is
defined then the following may also be defined to indicate that the
@@ -1419,7 +1685,7 @@ config STM32_TIM11_DAC
default n
depends on STM32_TIM11 && STM32_DAC
---help---
- Reserve timer 1 for use by DAC
+ Reserve timer 11 for use by DAC
Timer devices may be used for different purposes. If STM32_TIM11 is
defined then the following may also be defined to indicate that the
@@ -1450,7 +1716,7 @@ config STM32_TIM12_DAC
default n
depends on STM32_TIM12 && STM32_DAC
---help---
- Reserve timer 1 for use by DAC
+ Reserve timer 12 for use by DAC
Timer devices may be used for different purposes. If STM32_TIM12 is
defined then the following may also be defined to indicate that the
@@ -1481,7 +1747,7 @@ config STM32_TIM13_DAC
default n
depends on STM32_TIM13 && STM32_DAC
---help---
- Reserve timer 1 for use by DAC
+ Reserve timer 13 for use by DAC
Timer devices may be used for different purposes. If STM32_TIM13 is
defined then the following may also be defined to indicate that the
@@ -1512,7 +1778,7 @@ config STM32_TIM14_DAC
default n
depends on STM32_TIM14 && STM32_DAC
---help---
- Reserve timer 1 for use by DAC
+ Reserve timer 14 for use by DAC
Timer devices may be used for different purposes. If STM32_TIM14 is
defined then the following may also be defined to indicate that the
@@ -1538,6 +1804,27 @@ config STM32_TIM14_DAC2
endchoice
+menu "U[S]ART Configuration"
+ depends on STM32_USART1 || STM32_USART2 || STM32_USART3 || STM32_USART4 || STM32_USART5 || STM32_USART6
+
+config USART1_RS485
+ bool "RS-485 on USART1"
+ default n
+ depends on STM32_USART1
+ ---help---
+ Enable RS-485 interface on USART1. Your board config will have to
+ provide GPIO_USART1_RS485_DIR pin definition. Currently it cannot be
+ used with USART1_RXDMA.
+
+config USART1_RS485_DIR_POLARITY
+ int "USART1 RS-485 DIR pin polarity"
+ default 1
+ range 0 1
+ depends on USART1_RS485
+ ---help---
+ Polarity of DIR pin for RS-485 on USART1. Set to state on DIR pin which
+ enables TX (0 - low / nTXEN, 1 - high / TXEN).
+
config USART1_RXDMA
bool "USART1 Rx DMA"
default n
@@ -1545,6 +1832,24 @@ config USART1_RXDMA
---help---
In high data rate usage, Rx DMA may eliminate Rx overrun errors
+config USART2_RS485
+ bool "RS-485 on USART2"
+ default n
+ depends on STM32_USART2
+ ---help---
+ Enable RS-485 interface on USART2. Your board config will have to
+ provide GPIO_USART2_RS485_DIR pin definition. Currently it cannot be
+ used with USART2_RXDMA.
+
+config USART2_RS485_DIR_POLARITY
+ int "USART2 RS-485 DIR pin polarity"
+ default 1
+ range 0 1
+ depends on USART2_RS485
+ ---help---
+ Polarity of DIR pin for RS-485 on USART2. Set to state on DIR pin which
+ enables TX (0 - low / nTXEN, 1 - high / TXEN).
+
config USART2_RXDMA
bool "USART2 Rx DMA"
default n
@@ -1552,6 +1857,24 @@ config USART2_RXDMA
---help---
In high data rate usage, Rx DMA may eliminate Rx overrun errors
+config USART3_RS485
+ bool "RS-485 on USART3"
+ default n
+ depends on STM32_USART3
+ ---help---
+ Enable RS-485 interface on USART3. Your board config will have to
+ provide GPIO_USART3_RS485_DIR pin definition. Currently it cannot be
+ used with USART3_RXDMA.
+
+config USART3_RS485_DIR_POLARITY
+ int "USART3 RS-485 DIR pin polarity"
+ default 1
+ range 0 1
+ depends on USART3_RS485
+ ---help---
+ Polarity of DIR pin for RS-485 on USART3. Set to state on DIR pin which
+ enables TX (0 - low / nTXEN, 1 - high / TXEN).
+
config USART3_RXDMA
bool "USART3 Rx DMA"
default n
@@ -1559,6 +1882,24 @@ config USART3_RXDMA
---help---
In high data rate usage, Rx DMA may eliminate Rx overrun errors
+config UART4_RS485
+ bool "RS-485 on UART4"
+ default n
+ depends on STM32_UART4
+ ---help---
+ Enable RS-485 interface on UART4. Your board config will have to
+ provide GPIO_UART4_RS485_DIR pin definition. Currently it cannot be
+ used with UART4_RXDMA.
+
+config UART4_RS485_DIR_POLARITY
+ int "UART4 RS-485 DIR pin polarity"
+ default 1
+ range 0 1
+ depends on UART4_RS485
+ ---help---
+ Polarity of DIR pin for RS-485 on UART4. Set to state on DIR pin which
+ enables TX (0 - low / nTXEN, 1 - high / TXEN).
+
config UART4_RXDMA
bool "UART4 Rx DMA"
default n
@@ -1566,6 +1907,24 @@ config UART4_RXDMA
---help---
In high data rate usage, Rx DMA may eliminate Rx overrun errors
+config UART5_RS485
+ bool "RS-485 on UART5"
+ default n
+ depends on STM32_UART5
+ ---help---
+ Enable RS-485 interface on UART5. Your board config will have to
+ provide GPIO_UART5_RS485_DIR pin definition. Currently it cannot be
+ used with UART5_RXDMA.
+
+config UART5_RS485_DIR_POLARITY
+ int "UART5 RS-485 DIR pin polarity"
+ default 1
+ range 0 1
+ depends on UART5_RS485
+ ---help---
+ Polarity of DIR pin for RS-485 on UART5. Set to state on DIR pin which
+ enables TX (0 - low / nTXEN, 1 - high / TXEN).
+
config UART5_RXDMA
bool "UART5 Rx DMA"
default n
@@ -1573,6 +1932,24 @@ config UART5_RXDMA
---help---
In high data rate usage, Rx DMA may eliminate Rx overrun errors
+config USART6_RS485
+ bool "RS-485 on USART6"
+ default n
+ depends on STM32_USART6
+ ---help---
+ Enable RS-485 interface on USART6. Your board config will have to
+ provide GPIO_USART6_RS485_DIR pin definition. Currently it cannot be
+ used with USART6_RXDMA.
+
+config USART6_RS485_DIR_POLARITY
+ int "USART6 RS-485 DIR pin polarity"
+ default 1
+ range 0 1
+ depends on USART6_RS485
+ ---help---
+ Polarity of DIR pin for RS-485 on USART6. Set to state on DIR pin which
+ enables TX (0 - low / nTXEN, 1 - high / TXEN).
+
config USART6_RXDMA
bool "USART6 Rx DMA"
default n
@@ -1589,6 +1966,8 @@ config SERIAL_TERMIOS
If this is not defined, then the terminal settings (baud, parity, etc).
are not configurable at runtime; serial streams cannot be flushed, etc..
+endmenu
+
menu "SPI Configuration"
depends on STM32_SPI
@@ -1688,6 +2067,16 @@ config STM32_PHYADDR
---help---
The 5-bit address of the PHY on the board. Default: 1
+config STM32_PHYINIT
+ bool "Board-specific PHY Initialization"
+ default n
+ ---help---
+ Some boards require specialized initialization of the PHY before it can be used.
+ This may include such things as configuring GPIOs, resetting the PHY, etc. If
+ STM32_PHYINIT is defined in the configuration then the board specific logic must
+ provide stm32_phyinitialize(); The STM32 Ethernet driver will call this function
+ one time before it first uses the PHY.
+
config STM32_MII
bool "Use MII interface"
default n
@@ -1899,14 +2288,14 @@ config STM32_OTGFS_NPTXFIFO_SIZE
depends on USBHOST && STM32_OTGFS
---help---
Size of the non-periodic Tx FIFO in 32-bit words. Default 96 (384 bytes)
-
+
config STM32_OTGFS_PTXFIFO_SIZE
int "Periodic Tx FIFO size"
default 128
depends on USBHOST && STM32_OTGFS
---help---
Size of the periodic Tx FIFO in 32-bit words. Default 96 (384 bytes)
-
+
config STM32_OTGFS_DESCSIZE
int "Descriptor Size"
default 128
@@ -1920,14 +2309,14 @@ config STM32_OTGFS_SOFINTR
depends on USBHOST && STM32_OTGFS
---help---
Enable SOF interrupts. Why would you ever want to do that?
-
+
config STM32_USBHOST_REGDEBUG
bool "Register-Level Debug"
default n
depends on USBHOST && STM32_OTGFS
---help---
Enable very low-level register access debug. Depends on DEBUG.
-
+
config STM32_USBHOST_PKTDUMP
bool "Packet Dump Debug"
default n
diff --git a/nuttx/arch/arm/src/stm32/Make.defs b/nuttx/arch/arm/src/stm32/Make.defs
index 54067a168..baa751c7d 100644
--- a/nuttx/arch/arm/src/stm32/Make.defs
+++ b/nuttx/arch/arm/src/stm32/Make.defs
@@ -41,36 +41,40 @@ endif
CMN_ASRCS = up_saveusercontext.S up_fullcontextrestore.S up_switchcontext.S
CMN_CSRCS = up_assert.c up_blocktask.c up_copystate.c \
- up_createstack.c up_mdelay.c up_udelay.c up_exit.c \
- up_initialize.c up_initialstate.c up_interruptcontext.c \
- up_memfault.c up_modifyreg8.c up_modifyreg16.c up_modifyreg32.c \
- up_releasepending.c up_releasestack.c up_reprioritizertr.c \
- up_schedulesigaction.c up_sigdeliver.c up_systemreset.c \
- up_unblocktask.c up_usestack.c up_doirq.c up_hardfault.c up_svcall.c \
- up_stackcheck.c
+ up_createstack.c up_mdelay.c up_udelay.c up_exit.c \
+ up_initialize.c up_initialstate.c up_interruptcontext.c \
+ up_memfault.c up_modifyreg8.c up_modifyreg16.c up_modifyreg32.c \
+ up_releasepending.c up_releasestack.c up_reprioritizertr.c \
+ up_schedulesigaction.c up_sigdeliver.c up_systemreset.c \
+ up_unblocktask.c up_usestack.c up_doirq.c up_hardfault.c up_svcall.c \
+ up_stackcheck.c
ifeq ($(CONFIG_ARMV7M_CMNVECTOR),y)
CMN_ASRCS += up_exception.S
CMN_CSRCS += up_vectors.c
endif
+ifeq ($(CONFIG_ARCH_MEMCPY),y)
+CMN_ASRCS += up_memcpy.S
+endif
+
ifeq ($(CONFIG_DEBUG_STACK),y)
CMN_CSRCS += up_checkstack.c
endif
-ifeq ($(CONFIG_ARCH_FPU),y)
-CMN_ASRCS += up_fpu.S
+ifeq ($(CONFIG_ELF),y)
+CMN_CSRCS += up_elf.c
endif
-ifeq ($(CONFIG_ARCH_MEMCPY),y)
-CMN_ASRCS += memcpy.S
+ifeq ($(CONFIG_ARCH_FPU),y)
+CMN_ASRCS += up_fpu.S
endif
CHIP_ASRCS =
CHIP_CSRCS = stm32_allocateheap.c stm32_start.c stm32_rcc.c stm32_lse.c \
- stm32_lsi.c stm32_gpio.c stm32_exti_gpio.c stm32_flash.c stm32_irq.c \
- stm32_timerisr.c stm32_dma.c stm32_lowputc.c stm32_serial.c \
- stm32_spi.c stm32_sdio.c stm32_tim.c stm32_i2c.c stm32_waste.c
+ stm32_lsi.c stm32_gpio.c stm32_exti_gpio.c stm32_flash.c stm32_irq.c \
+ stm32_timerisr.c stm32_dma.c stm32_lowputc.c stm32_serial.c \
+ stm32_spi.c stm32_sdio.c stm32_tim.c stm32_i2c.c stm32_waste.c
ifeq ($(CONFIG_USBDEV),y)
ifeq ($(CONFIG_STM32_USB),y)
diff --git a/nuttx/arch/arm/src/stm32/chip/stm32_eth.h b/nuttx/arch/arm/src/stm32/chip/stm32_eth.h
index a4a109d01..92a229ccc 100644
--- a/nuttx/arch/arm/src/stm32/chip/stm32_eth.h
+++ b/nuttx/arch/arm/src/stm32/chip/stm32_eth.h
@@ -835,14 +835,6 @@ struct eth_rxdesc_s
* Public Functions
****************************************************************************************************/
-#undef EXTERN
-#if defined(__cplusplus)
-#define EXTERN extern "C"
-extern "C" {
-#else
-#define EXTERN extern
-#endif
-
#endif /* __ASSEMBLY__ */
#endif /* STM32_NETHERNET > 0 */
#endif /* __ARCH_ARM_SRC_STM32_CHIP_STM32_ETH_H */
diff --git a/nuttx/arch/arm/src/stm32/chip/stm32_flash.h b/nuttx/arch/arm/src/stm32/chip/stm32_flash.h
index c2e440923..d6fcecc11 100644
--- a/nuttx/arch/arm/src/stm32/chip/stm32_flash.h
+++ b/nuttx/arch/arm/src/stm32/chip/stm32_flash.h
@@ -110,6 +110,7 @@
# define FLASH_ACR_HLFCYA (1 << 3) /* FLASH half cycle access */
# define FLASH_ACR_PRTFBE (1 << 4) /* FLASH prefetch enable */
#elif defined(CONFIG_STM32_STM32F20XX) || defined(CONFIG_STM32_STM32F40XX)
+# define FLASH_ACR_PRFTEN (1 << 8) /* FLASH prefetch enable */
# define FLASH_ACR_ICEN (1 << 9) /* Bit 9: Instruction cache enable */
# define FLASH_ACR_DCEN (1 << 10) /* Bit 10: Data cache enable */
# define FLASH_ACR_ICRST (1 << 11) /* Bit 11: Instruction cache reset */
diff --git a/nuttx/arch/arm/src/stm32/chip/stm32f100_pinmap.h b/nuttx/arch/arm/src/stm32/chip/stm32f100_pinmap.h
index 01d6e1ce0..addef0265 100644
--- a/nuttx/arch/arm/src/stm32/chip/stm32f100_pinmap.h
+++ b/nuttx/arch/arm/src/stm32/chip/stm32f100_pinmap.h
@@ -6,6 +6,8 @@
* Copyright (C) 2012 Michael Smith. All Rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
* Uros Platise <uros.platise@isotel.eu>
+ * Michael Smith
+ * Freddie Chopin <freddie_chopin@op.pl>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -49,6 +51,87 @@
* Pre-processor Definitions
************************************************************************************/
+/* Alternate Pin Functions: */
+
+/* ADC */
+
+#define GPIO_ADC1_IN0 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN0)
+#define GPIO_ADC1_IN1 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN1)
+#define GPIO_ADC1_IN2 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN2)
+#define GPIO_ADC1_IN3 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN3)
+#define GPIO_ADC1_IN4 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN4)
+#define GPIO_ADC1_IN5 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN5)
+#define GPIO_ADC1_IN6 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN6)
+#define GPIO_ADC1_IN7 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN7)
+#define GPIO_ADC1_IN8 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTB|GPIO_PIN0)
+#define GPIO_ADC1_IN9 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTB|GPIO_PIN1)
+#define GPIO_ADC1_IN10 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN0)
+#define GPIO_ADC1_IN11 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN1)
+#define GPIO_ADC1_IN12 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN2)
+#define GPIO_ADC1_IN13 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN3)
+#define GPIO_ADC1_IN14 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN4)
+#define GPIO_ADC1_IN15 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN5)
+
+/* CEC */
+#if defined(CONFIG_STM32_CEC_REMAP)
+# define GPIO_CEC (GPIO_ALT|GPIO_CNF_AFOD|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN10)
+#else
+# define GPIO_CEC (GPIO_ALT|GPIO_CNF_AFOD|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN8)
+#endif
+
+/* DAC
+ * Note from RM0041, 11.2: "Once the DAC channelx is enabled, the corresponding
+ * GPIO pin (PA4 or PA5) is automatically connected to the analog converter
+ * output (DAC_OUTx). In order to avoid parasitic consumption, the PA4 or PA5
+ * pin should first be configured to analog (AIN)."
+ */
+
+#define GPIO_DAC_OUT1 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN4)
+#define GPIO_DAC_OUT2 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN5)
+
+/* FSMC */
+
+/* TODO - VL devices in 100- and 144-pin packages have FSMC */
+
+/* I2C */
+
+#if defined(CONFIG_STM32_I2C1_REMAP)
+# define GPIO_I2C1_SCL (GPIO_ALT|GPIO_CNF_AFOD|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN8)
+# define GPIO_I2C1_SDA (GPIO_ALT|GPIO_CNF_AFOD|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN9)
+#else
+# define GPIO_I2C1_SCL (GPIO_ALT|GPIO_CNF_AFOD|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN6)
+# define GPIO_I2C1_SDA (GPIO_ALT|GPIO_CNF_AFOD|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN7)
+#endif
+#define GPIO_I2C1_SMBA (GPIO_ALT|GPIO_CNF_INFLOAT|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN5)
+
+#define GPIO_I2C2_SCL (GPIO_ALT|GPIO_CNF_AFOD|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN10)
+#define GPIO_I2C2_SDA (GPIO_ALT|GPIO_CNF_AFOD|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN11)
+#define GPIO_I2C2_SMBA (GPIO_ALT|GPIO_CNF_INFLOAT|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN12)
+
+/* SPI */
+
+#if defined(CONFIG_STM32_SPI1_REMAP)
+# define GPIO_SPI1_NSS (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN15)
+# define GPIO_SPI1_SCK (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN3)
+# define GPIO_SPI1_MISO (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|GPIO_PORTB|GPIO_PIN4)
+# define GPIO_SPI1_MOSI (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN5)
+#else
+# define GPIO_SPI1_NSS (GPIO_INPUT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTA|GPIO_PIN4)
+# define GPIO_SPI1_SCK (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTA|GPIO_PIN5)
+# define GPIO_SPI1_MISO (GPIO_INPUT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTA|GPIO_PIN6)
+# define GPIO_SPI1_MOSI (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTA|GPIO_PIN7)
+#endif
+
+#define GPIO_SPI2_NSS (GPIO_INPUT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN12)
+#define GPIO_SPI2_SCK (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN13)
+#define GPIO_SPI2_MISO (GPIO_INPUT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN14)
+#define GPIO_SPI2_MOSI (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN15)
+
+#define GPIO_SPI3_NSS (GPIO_INPUT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTA|GPIO_PIN15)
+#define GPIO_SPI3_SCK (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN3)
+#define GPIO_SPI3_MISO (GPIO_INPUT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN4)
+#define GPIO_SPI3_MOSI (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN5)
+
/* TIMERS */
#if defined(CONFIG_STM32_TIM1_FULL_REMAP)
@@ -186,6 +269,77 @@
# define GPIO_TIM4_CH4OUT (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN9)
#endif
+#define GPIO_TIM5_CH1IN (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN0)
+#define GPIO_TIM5_CH1OUT (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTA|GPIO_PIN0)
+#define GPIO_TIM5_CH2IN (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN1)
+#define GPIO_TIM5_CH2OUT (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTA|GPIO_PIN1)
+#define GPIO_TIM5_CH3IN (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN2)
+#define GPIO_TIM5_CH3OUT (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTA|GPIO_PIN2)
+#define GPIO_TIM5_CH4IN (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN3)
+#define GPIO_TIM5_CH4OUT (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTA|GPIO_PIN3)
+
+#if defined(CONFIG_STM32_TIM12_REMAP)
+# define GPIO_TIM12_CH1IN (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|GPIO_PORTB|GPIO_PIN12)
+# define GPIO_TIM12_CH1OUT (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN12)
+# define GPIO_TIM12_CH2IN (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|GPIO_PORTB|GPIO_PIN13)
+# define GPIO_TIM12_CH2OUT (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN13)
+#else
+# define GPIO_TIM12_CH1IN (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN4)
+# define GPIO_TIM12_CH1OUT (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTC|GPIO_PIN4)
+# define GPIO_TIM12_CH2IN (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN5)
+# define GPIO_TIM12_CH2OUT (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTC|GPIO_PIN5)
+#endif
+
+#if defined(CONFIG_STM32_TIM13_REMAP)
+# define GPIO_TIM13_CH1IN (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|GPIO_PORTB|GPIO_PIN0)
+# define GPIO_TIM13_CH1OUT (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN0)
+#else
+# define GPIO_TIM13_CH1IN (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN8)
+# define GPIO_TIM13_CH1OUT (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTC|GPIO_PIN8)
+#endif
+
+#if defined(CONFIG_STM32_TIM14_REMAP)
+# define GPIO_TIM14_CH1IN (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|GPIO_PORTB|GPIO_PIN1)
+# define GPIO_TIM14_CH1OUT (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN1)
+#else
+# define GPIO_TIM14_CH1IN (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN9)
+# define GPIO_TIM14_CH1OUT (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTC|GPIO_PIN9)
+#endif
+
+#if defined(CONFIG_STM32_TIM15_REMAP)
+# define GPIO_TIM15_CH1IN (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|GPIO_PORTB|GPIO_PIN14)
+# define GPIO_TIM15_CH1OUT (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN14)
+# define GPIO_TIM15_CH2IN (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|GPIO_PORTB|GPIO_PIN15)
+# define GPIO_TIM15_CH2OUT (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN15)
+#else
+# define GPIO_TIM15_CH1IN (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN2)
+# define GPIO_TIM15_CH1OUT (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTA|GPIO_PIN2)
+# define GPIO_TIM15_CH2IN (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN3)
+# define GPIO_TIM15_CH2OUT (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTA|GPIO_PIN3)
+#endif
+#define GPIO_TIM15_BKIN (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN9)
+#define GPIO_TIM15_CH1N (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN15)
+
+#if defined(CONFIG_STM32_TIM16_REMAP)
+# define GPIO_TIM16_CH1IN (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN6)
+# define GPIO_TIM16_CH1OUT (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTA|GPIO_PIN6)
+#else
+# define GPIO_TIM16_CH1IN (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|GPIO_PORTB|GPIO_PIN8)
+# define GPIO_TIM16_CH1OUT (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN8)
+#endif
+#define GPIO_TIM16_BKIN (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|GPIO_PORTB|GPIO_PIN5)
+#define GPIO_TIM16_CH1N (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN6)
+
+#if defined(CONFIG_STM32_TIM17_REMAP)
+# define GPIO_TIM17_CH1IN (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN7)
+# define GPIO_TIM17_CH1OUT (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTA|GPIO_PIN7)
+#else
+# define GPIO_TIM17_CH1IN (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|GPIO_PORTB|GPIO_PIN9)
+# define GPIO_TIM17_CH1OUT (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN9)
+#endif
+#define GPIO_TIM17_BKIN (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN10)
+#define GPIO_TIM17_CH1N (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN7)
+
/* USART */
#if defined(CONFIG_STM32_USART1_REMAP)
@@ -230,38 +384,10 @@
# define GPIO_USART3_RTS (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN14)
#endif
-/* SPI */
-
-#if defined(CONFIG_STM32_SPI1_REMAP)
-# define GPIO_SPI1_NSS (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN15)
-# define GPIO_SPI1_SCK (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN3)
-# define GPIO_SPI1_MISO (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|GPIO_PORTB|GPIO_PIN4)
-# define GPIO_SPI1_MOSI (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN5)
-#else
-# define GPIO_SPI1_NSS (GPIO_INPUT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTA|GPIO_PIN4)
-# define GPIO_SPI1_SCK (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTA|GPIO_PIN5)
-# define GPIO_SPI1_MISO (GPIO_INPUT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTA|GPIO_PIN6)
-# define GPIO_SPI1_MOSI (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTA|GPIO_PIN7)
-#endif
-
-#define GPIO_SPI2_NSS (GPIO_INPUT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN12)
-#define GPIO_SPI2_SCK (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN13)
-#define GPIO_SPI2_MISO (GPIO_INPUT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN14)
-#define GPIO_SPI2_MOSI (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN15)
-
-/* I2C */
-
-#if defined(CONFIG_STM32_I2C1_REMAP)
-# define GPIO_I2C1_SCL (GPIO_ALT|GPIO_CNF_AFOD|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN8)
-# define GPIO_I2C1_SDA (GPIO_ALT|GPIO_CNF_AFOD|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN9)
-#else
-# define GPIO_I2C1_SCL (GPIO_ALT|GPIO_CNF_AFOD|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN6)
-# define GPIO_I2C1_SDA (GPIO_ALT|GPIO_CNF_AFOD|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN7)
-#endif
-#define GPIO_I2C1_SMBA (GPIO_ALT|GPIO_CNF_INFLOAT|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN5)
+#define GPIO_UART4_TX (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTC|GPIO_PIN10)
+#define GPIO_UART4_RX (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN11)
-#define GPIO_I2C2_SCL (GPIO_ALT|GPIO_CNF_AFOD|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN10)
-#define GPIO_I2C2_SDA (GPIO_ALT|GPIO_CNF_AFOD|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN11)
-#define GPIO_I2C2_SMBA (GPIO_ALT|GPIO_CNF_INFLOAT|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN12)
+#define GPIO_UART5_TX (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTC|GPIO_PIN12)
+#define GPIO_UART5_RX (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|GPIO_PORTD|GPIO_PIN2)
#endif /* __ARCH_ARM_SRC_STM32_CHIP_STM32F100_PINMAP_H */
diff --git a/nuttx/arch/arm/src/stm32/chip/stm32f103vc_pinmap.h b/nuttx/arch/arm/src/stm32/chip/stm32f103vc_pinmap.h
index 160676802..52a513215 100644
--- a/nuttx/arch/arm/src/stm32/chip/stm32f103vc_pinmap.h
+++ b/nuttx/arch/arm/src/stm32/chip/stm32f103vc_pinmap.h
@@ -129,7 +129,7 @@
#if 0 /* Needs further investigation */
-#define GPIO_DAC_OUT1 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUTz|GPIO_PORTA|GPIO_PIN4)
+#define GPIO_DAC_OUT1 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN4)
#define GPIO_DAC_OUT2 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN5)
#endif
diff --git a/nuttx/arch/arm/src/stm32/chip/stm32f103ze_pinmap.h b/nuttx/arch/arm/src/stm32/chip/stm32f103ze_pinmap.h
index 9bcee49f5..581b026a0 100644
--- a/nuttx/arch/arm/src/stm32/chip/stm32f103ze_pinmap.h
+++ b/nuttx/arch/arm/src/stm32/chip/stm32f103ze_pinmap.h
@@ -50,53 +50,53 @@
/* ADC */
-#define GPIO_ADC1_IN0 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN0)
-#define GPIO_ADC1_IN1 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN1)
-#define GPIO_ADC1_IN2 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN2)
-#define GPIO_ADC1_IN3 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN3)
-#define GPIO_ADC1_IN4 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN4)
-#define GPIO_ADC1_IN5 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN5)
-#define GPIO_ADC1_IN6 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN6)
-#define GPIO_ADC1_IN7 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN7)
-#define GPIO_ADC1_IN8 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTB|GPIO_PIN0)
-#define GPIO_ADC1_IN9 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTB|GPIO_PIN1)
-#define GPIO_ADC1_IN10 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN0)
-#define GPIO_ADC1_IN11 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN1)
-#define GPIO_ADC1_IN12 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN2)
-#define GPIO_ADC1_IN13 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN3)
-#define GPIO_ADC1_IN14 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN4)
-#define GPIO_ADC1_IN15 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN5)
-
-#define GPIO_ADC2_IN0 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN0)
-#define GPIO_ADC2_IN1 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN1)
-#define GPIO_ADC2_IN2 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN2)
-#define GPIO_ADC2_IN3 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN3)
-#define GPIO_ADC2_IN4 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN4)
-#define GPIO_ADC2_IN5 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN5)
-#define GPIO_ADC2_IN6 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN6)
-#define GPIO_ADC2_IN7 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN7)
-#define GPIO_ADC2_IN8 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTB|GPIO_PIN0)
-#define GPIO_ADC2_IN9 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTB|GPIO_PIN1)
-#define GPIO_ADC2_IN10 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN0)
-#define GPIO_ADC2_IN11 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN1)
-#define GPIO_ADC2_IN12 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN2)
-#define GPIO_ADC2_IN13 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN3)
-#define GPIO_ADC2_IN14 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN4)
-#define GPIO_ADC2_IN15 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN5)
-
-#define GPIO_ADC3_IN0 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN0)
-#define GPIO_ADC3_IN1 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN1)
-#define GPIO_ADC3_IN2 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN2)
-#define GPIO_ADC3_IN3 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN3)
-#define GPIO_ADC3_IN4 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTF|GPIO_PIN6)
-#define GPIO_ADC3_IN5 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTF|GPIO_PIN7)
-#define GPIO_ADC3_IN6 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTF|GPIO_PIN8)
-#define GPIO_ADC3_IN7 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTF|GPIO_PIN9)
-#define GPIO_ADC3_IN8 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTF|GPIO_PIN10)
-#define GPIO_ADC3_IN10 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN0)
-#define GPIO_ADC3_IN11 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN1)
-#define GPIO_ADC3_IN12 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN2)
-#define GPIO_ADC3_IN13 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN3)
+#define GPIO_ADC1_IN0 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN0)
+#define GPIO_ADC1_IN1 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN1)
+#define GPIO_ADC1_IN2 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN2)
+#define GPIO_ADC1_IN3 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN3)
+#define GPIO_ADC1_IN4 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN4)
+#define GPIO_ADC1_IN5 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN5)
+#define GPIO_ADC1_IN6 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN6)
+#define GPIO_ADC1_IN7 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN7)
+#define GPIO_ADC1_IN8 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTB|GPIO_PIN0)
+#define GPIO_ADC1_IN9 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTB|GPIO_PIN1)
+#define GPIO_ADC1_IN10 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN0)
+#define GPIO_ADC1_IN11 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN1)
+#define GPIO_ADC1_IN12 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN2)
+#define GPIO_ADC1_IN13 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN3)
+#define GPIO_ADC1_IN14 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN4)
+#define GPIO_ADC1_IN15 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN5)
+
+#define GPIO_ADC2_IN0 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN0)
+#define GPIO_ADC2_IN1 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN1)
+#define GPIO_ADC2_IN2 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN2)
+#define GPIO_ADC2_IN3 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN3)
+#define GPIO_ADC2_IN4 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN4)
+#define GPIO_ADC2_IN5 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN5)
+#define GPIO_ADC2_IN6 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN6)
+#define GPIO_ADC2_IN7 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN7)
+#define GPIO_ADC2_IN8 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTB|GPIO_PIN0)
+#define GPIO_ADC2_IN9 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTB|GPIO_PIN1)
+#define GPIO_ADC2_IN10 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN0)
+#define GPIO_ADC2_IN11 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN1)
+#define GPIO_ADC2_IN12 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN2)
+#define GPIO_ADC2_IN13 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN3)
+#define GPIO_ADC2_IN14 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN4)
+#define GPIO_ADC2_IN15 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN5)
+
+#define GPIO_ADC3_IN0 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN0)
+#define GPIO_ADC3_IN1 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN1)
+#define GPIO_ADC3_IN2 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN2)
+#define GPIO_ADC3_IN3 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN3)
+#define GPIO_ADC3_IN4 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTF|GPIO_PIN6)
+#define GPIO_ADC3_IN5 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTF|GPIO_PIN7)
+#define GPIO_ADC3_IN6 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTF|GPIO_PIN8)
+#define GPIO_ADC3_IN7 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTF|GPIO_PIN9)
+#define GPIO_ADC3_IN8 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTF|GPIO_PIN10)
+#define GPIO_ADC3_IN10 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN0)
+#define GPIO_ADC3_IN11 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN1)
+#define GPIO_ADC3_IN12 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN2)
+#define GPIO_ADC3_IN13 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN3)
/* DAC - "Once the DAC channelx is enabled, the corresponding GPIO pin
* (PA4 or PA5) is automatically connected to the analog converter output
@@ -104,8 +104,8 @@
* should first be configured to analog (AIN)."
*/
-#define GPIO_DAC_OUT1 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTF|GPIO_PIN10)
-#define GPIO_DAC_OUT2 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PIN10)
+#define GPIO_DAC_OUT1 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN4)
+#define GPIO_DAC_OUT2 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN5)
/* TIMERS */
diff --git a/nuttx/arch/arm/src/stm32/chip/stm32f105vb_pinmap.h b/nuttx/arch/arm/src/stm32/chip/stm32f105vb_pinmap.h
index 7a5ec3381..054a7337d 100644
--- a/nuttx/arch/arm/src/stm32/chip/stm32f105vb_pinmap.h
+++ b/nuttx/arch/arm/src/stm32/chip/stm32f105vb_pinmap.h
@@ -85,7 +85,7 @@
#endif
#if 0 /* Needs further investigation */
-#define GPIO_DAC_OUT1 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUTz|GPIO_PORTA|GPIO_PIN4)
+#define GPIO_DAC_OUT1 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN4)
#define GPIO_DAC_OUT2 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN5)
#endif
diff --git a/nuttx/arch/arm/src/stm32/chip/stm32f107vc_pinmap.h b/nuttx/arch/arm/src/stm32/chip/stm32f107vc_pinmap.h
index 9bbc21479..2419620fc 100644
--- a/nuttx/arch/arm/src/stm32/chip/stm32f107vc_pinmap.h
+++ b/nuttx/arch/arm/src/stm32/chip/stm32f107vc_pinmap.h
@@ -85,7 +85,7 @@
#endif
#if 0 /* Needs further investigation */
-#define GPIO_DAC_OUT1 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUTz|GPIO_PORTA|GPIO_PIN4)
+#define GPIO_DAC_OUT1 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN4)
#define GPIO_DAC_OUT2 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN5)
#endif
diff --git a/nuttx/arch/arm/src/stm32/chip/stm32f10xxx_gpio.h b/nuttx/arch/arm/src/stm32/chip/stm32f10xxx_gpio.h
index a95d13100..d339fc15e 100644
--- a/nuttx/arch/arm/src/stm32/chip/stm32f10xxx_gpio.h
+++ b/nuttx/arch/arm/src/stm32/chip/stm32f10xxx_gpio.h
@@ -59,6 +59,7 @@
#define STM32_AFIO_EXTICR2_OFFSET 0x000c /* External interrupt configuration register 2 */
#define STM32_AFIO_EXTICR3_OFFSET 0x0010 /* External interrupt configuration register 3 */
#define STM32_AFIO_EXTICR4_OFFSET 0x0014 /* External interrupt configuration register 4 */
+#define STM32_AFIO_MAPR2_OFFSET 0x001c /* AF remap and debug I/O configuration register 2 */
/* Register Addresses ***************************************************************/
@@ -373,5 +374,27 @@
#define AFIO_EXTICR4_EXTI15_SHIFT (12) /* Bits 15-12: EXTI 15 configuration */
#define AFIO_EXTICR4_EXTI15_MASK (AFIO_EXTICR_PORT_MASK << AFIO_EXTICR4_EXTI15_SHIFT)
+/* AF remap and debug I/O configuration register 2 */
+
+#ifdef CONFIG_STM32_VALUELINE
+# define AFIO_MAPR2_TIM15_REMAP (1 << 0) /* Bit 0: TIM15 remapping */
+# define AFIO_MAPR2_TIM16_REMAP (1 << 1) /* Bit 1: TIM16 remapping */
+# define AFIO_MAPR2_TIM17_REMAP (1 << 2) /* Bit 2: TIM17 remapping */
+# define AFIO_MAPR2_CEC_REMAP (1 << 3) /* Bit 3: CEC remapping */
+# define AFIO_MAPR2_TIM1_DMA_REMAP (1 << 4) /* Bit 4: TIM1 DMA remapping */
+#else
+# define AFIO_MAPR2_TIM9_REMAP (1 << 5) /* Bit 5: TIM9 remapping */
+# define AFIO_MAPR2_TIM10_REMAP (1 << 6) /* Bit 6: TIM10 remapping */
+# define AFIO_MAPR2_TIM11_REMAP (1 << 7) /* Bit 7: TIM11 remapping */
+#endif
+#define AFIO_MAPR2_TIM13_REMAP (1 << 8) /* Bit 8: TIM13 remapping */
+#define AFIO_MAPR2_TIM14_REMAP (1 << 9) /* Bit 9: TIM14 remapping */
+#define AFIO_MAPR2_FSMC_NADV (1 << 10) /* Bit 10: NADV connect/disconnect */
+#ifdef CONFIG_STM32_VALUELINE
+# define AFIO_MAPR2_TIM67_DAC_DMA_REMAP (1 << 11) /* Bit 11: TIM67_DAC DMA remapping */
+# define AFIO_MAPR2_TIM12_REMAP (1 << 12) /* Bit 12: TIM12 remapping */
+# define AFIO_MAPR2_MISC_REMAP (1 << 13) /* Bit 13: Miscellaneous features remapping */
+#endif
+
#endif /* __ARCH_ARM_SRC_STM32_CHIP_STM32F10XXX_GPIO_H */
diff --git a/nuttx/arch/arm/src/stm32/chip/stm32f10xxx_memorymap.h b/nuttx/arch/arm/src/stm32/chip/stm32f10xxx_memorymap.h
index ed1bc2625..a1d2e26d3 100644
--- a/nuttx/arch/arm/src/stm32/chip/stm32f10xxx_memorymap.h
+++ b/nuttx/arch/arm/src/stm32/chip/stm32f10xxx_memorymap.h
@@ -60,7 +60,9 @@
#define STM32_TIM5_BASE 0x40000c00 /* 0x40000c00 - 0x40000fff: TIM5 timer */
#define STM32_TIM6_BASE 0x40001000 /* 0x40001000 - 0x400013ff: TIM6 timer */
#define STM32_TIM7_BASE 0x40001400 /* 0x40001400 - 0x400007ff: TIM7 timer */
- /* 0x40001800 - 0x40000fff: Reserved */
+#define STM32_TIM12_BASE 0x40001800 /* 0x40001800 - 0x40001bff: TIM12 timer */
+#define STM32_TIM13_BASE 0x40001c00 /* 0x40001c00 - 0x40001fff: TIM13 timer */
+#define STM32_TIM14_BASE 0x40002000 /* 0x40002000 - 0x400023ff: TIM14 timer */
#define STM32_RTC_BASE 0x40002800 /* 0x40002800 - 0x40002bff: RTC */
#define STM32_WWDG_BASE 0x40002c00 /* 0x40002C00 - 0x40002fff: Window watchdog (WWDG) */
#define STM32_IWDG_BASE 0x40003000 /* 0x40003000 - 0x400033ff: Independent watchdog (IWDG) */
@@ -83,8 +85,8 @@
#define STM32_BKP_BASE 0x40006c00 /* 0x40006c00 - 0x40006fff: Backup registers (BKP) */
#define STM32_PWR_BASE 0x40007000 /* 0x40007000 - 0x400073ff: Power control PWR */
#define STM32_DAC_BASE 0x40007400 /* 0x40007400 - 0x400077ff: DAC */
- /* 0x40007800 - 0x4000ffff: Reserved */
-
+#define STM32_CEC_BASE 0x40007800 /* 0x40007800 - 0x40007bff: CEC */
+ /* 0x40007c00 - 0x4000ffff: Reserved */
/* APB2 bus */
#define STM32_AFIO_BASE 0x40010000 /* 0x40010000 - 0x400103ff: AFIO */
@@ -102,44 +104,49 @@
#define STM32_SPI1_BASE 0x40013000 /* 0x40013000 - 0x400133ff: SPI1 */
#define STM32_TIM8_BASE 0x40013400 /* 0x40013400 - 0x400137ff: TIM8 timer */
#define STM32_USART1_BASE 0x40013800 /* 0x40013800 - 0x40013bff: USART1 */
-#define STM32_ADC3_BASE 0x40012800 /* 0x40012800 - 0x40013fff: ADC3 */
- /* 0x40014000 - 0x40017fff: Reserved */
+#define STM32_ADC3_BASE 0x40012800 /* 0x40012800 - 0x40013c00: ADC3 */
+ /* 0x40013c00 - 0x40013fff: Reserved */
+#define STM32_TIM15_BASE 0x40014400 /* 0x40014400 - 0x400147ff: TIM15 */
+#define STM32_TIM16_BASE 0x40014400 /* 0x40014400 - 0x400147ff: TIM16 */
+#define STM32_TIM17_BASE 0x40014800 /* 0x40014800 - 0x40014bff: TIM17 */
+ /* 0x40014c00 - 0x4001ffff: Reserved */
+
/* AHB bus */
-#define STM32_SDIO_BASE 0x40018000 /* 0x40018000 - 0x400183ff: SDIO */
- /* 0x40018400 - 0x40017fff: Reserved */
-#define STM32_DMA1_BASE 0x40020000 /* 0x40020000 - 0x400203ff: DMA1 */
-#define STM32_DMA2_BASE 0x40020400 /* 0x40020000 - 0x400207ff: DMA2 */
- /* 0x40020800 - 0x40020fff: Reserved */
-#define STM32_RCC_BASE 0x40021000 /* 0x40021000 - 0x400213ff: Reset and Clock control RCC */
- /* 0x40021400 - 0x40021fff: Reserved */
-#define STM32_OTGFS_BASE 0x50000000 /* 0x50000000 - 0x500003ff: USB OTG FS */
-#define STM32_FLASHIF_BASE 0x40022000 /* 0x40022000 - 0x400223ff: Flash memory interface */
-#define STM32_CRC_BASE 0x40028000 /* 0x40023000 - 0x400233ff: CRC */
- /* 0x40023400 - 0x40027fff: Reserved */
-#define STM32_ETHERNET_BASE 0x40028000 /* 0x40028000 - 0x40029fff: Ethernet */
- /* 0x40030000 - 0x4fffffff: Reserved */
+#define STM32_SDIO_BASE 0x40018000 /* 0x40018000 - 0x400183ff: SDIO */
+ /* 0x40018400 - 0x40017fff: Reserved */
+#define STM32_DMA1_BASE 0x40020000 /* 0x40020000 - 0x400203ff: DMA1 */
+#define STM32_DMA2_BASE 0x40020400 /* 0x40020000 - 0x400207ff: DMA2 */
+ /* 0x40020800 - 0x40020fff: Reserved */
+#define STM32_RCC_BASE 0x40021000 /* 0x40021000 - 0x400213ff: Reset and Clock control RCC */
+ /* 0x40021400 - 0x40021fff: Reserved */
+#define STM32_OTGFS_BASE 0x50000000 /* 0x50000000 - 0x500003ff: USB OTG FS */
+#define STM32_FLASHIF_BASE 0x40022000 /* 0x40022000 - 0x400223ff: Flash memory interface */
+#define STM32_CRC_BASE 0x40028000 /* 0x40023000 - 0x400233ff: CRC */
+ /* 0x40023400 - 0x40027fff: Reserved */
+#define STM32_ETHERNET_BASE 0x40028000 /* 0x40028000 - 0x40029fff: Ethernet */
+ /* 0x40030000 - 0x4fffffff: Reserved */
/* Peripheral BB base */
-#define STM32_PERIPHBB_BASE 0x42000000
+#define STM32_PERIPHBB_BASE 0x42000000
/* Flexible SRAM controller (FSMC) */
-#define STM32_FSMC_BANK1 0x60000000 /* 0x60000000-0x6fffffff: 256Mb NOR/SRAM */
-#define STM32_FSMC_BANK2 0x70000000 /* 0x70000000-0x7fffffff: 256Mb NAND FLASH */
-#define STM32_FSMC_BANK3 0x80000000 /* 0x80000000-0x8fffffff: 256Mb NAND FLASH */
-#define STM32_FSMC_BANK4 0x90000000 /* 0x90000000-0x9fffffff: 256Mb PC CARD*/
-#define STM32_IS_EXTSRAM(a) ((((uint32_t)(a)) & STM32_REGION_MASK) == STM32_FSMC_BANK1)
+#define STM32_FSMC_BANK1 0x60000000 /* 0x60000000-0x6fffffff: 256Mb NOR/SRAM */
+#define STM32_FSMC_BANK2 0x70000000 /* 0x70000000-0x7fffffff: 256Mb NAND FLASH */
+#define STM32_FSMC_BANK3 0x80000000 /* 0x80000000-0x8fffffff: 256Mb NAND FLASH */
+#define STM32_FSMC_BANK4 0x90000000 /* 0x90000000-0x9fffffff: 256Mb PC CARD*/
+#define STM32_IS_EXTSRAM(a) ((((uint32_t)(a)) & STM32_REGION_MASK) == STM32_FSMC_BANK1)
-#define STM32_FSMC_BASE 0xa0000000 /* 0xa0000000-0xbfffffff: 512Mb FSMC register block */
+#define STM32_FSMC_BASE 0xa0000000 /* 0xa0000000-0xbfffffff: 512Mb FSMC register block */
/* Other registers -- see armv7-m/nvic.h for standard Cortex-M3 registers in this
* address range
*/
-#define STM32_SCS_BASE 0xe000e000
-#define STM32_DEBUGMCU_BASE 0xe0042000
+#define STM32_SCS_BASE 0xe000e000
+#define STM32_DEBUGMCU_BASE 0xe0042000
#endif /* __ARCH_ARM_SRC_STM32_CHIP_STM32F10XXX_MEMORYMAP_H */
diff --git a/nuttx/arch/arm/src/stm32/chip/stm32f10xxx_rcc.h b/nuttx/arch/arm/src/stm32/chip/stm32f10xxx_rcc.h
index 60365b921..1a792b7eb 100644
--- a/nuttx/arch/arm/src/stm32/chip/stm32f10xxx_rcc.h
+++ b/nuttx/arch/arm/src/stm32/chip/stm32f10xxx_rcc.h
@@ -163,7 +163,9 @@
# define RCC_CFGR_PLLMUL_CLKx14 (12 << RCC_CFGR_PLLMUL_SHIFT) /* 1100: PLL input clock x 14 */
# define RCC_CFGR_PLLMUL_CLKx15 (13 << RCC_CFGR_PLLMUL_SHIFT) /* 1101: PLL input clock x 15 */
# define RCC_CFGR_PLLMUL_CLKx16 (14 << RCC_CFGR_PLLMUL_SHIFT) /* 111x: PLL input clock x 16 */
-#define RCC_CFGR_USBPRE (1 << 22) /* Bit 22: USB prescaler */
+#ifndef CONFIG_STM32_VALUELINE
+# define RCC_CFGR_USBPRE (1 << 22) /* Bit 22: USB prescaler */
+#endif
#define RCC_CFGR_MCO_SHIFT (24) /* Bits 26-24: Microcontroller Clock Output */
#define RCC_CFGR_MCO_MASK (0x0f << RCC_CFGR_MCO_SHIFT)
# define RCC_CFGR_NOCLK (0 << RCC_CFGR_MCO_SHIFT) /* 0xx: No clock */
@@ -207,12 +209,22 @@
#define TCC_APB2RSTR_IOPFRST (1 << 7) /* Bit 7: IO port F reset */
#define TCC_APB2RSTR_IOPGRST (1 << 8) /* Bit 8: IO port G reset */
#define RCC_APB2RSTR_ADC1RST (1 << 9) /* Bit 9: ADC 1 interface reset */
-#define RCC_APB2RSTR_ADC2RST (1 << 10) /* Bit 10: ADC 2 interface reset */
+#ifndef CONFIG_STM32_VALUELINE
+# define RCC_APB2RSTR_ADC2RST (1 << 10) /* Bit 10: ADC 2 interface reset */
+#endif
#define RCC_APB2RSTR_TIM1RST (1 << 11) /* Bit 11: TIM1 Timer reset */
#define RCC_APB2RSTR_SPI1RST (1 << 12) /* Bit 12: SPI 1 reset */
-#define RCC_APB2RSTR_TIM8RST (1 << 13) /* Bit 13: TIM8 Timer reset */
+#ifndef CONFIG_STM32_VALUELINE
+# define RCC_APB2RSTR_TIM8RST (1 << 13) /* Bit 13: TIM8 Timer reset */
+#endif
#define RCC_APB2RSTR_USART1RST (1 << 14) /* Bit 14: USART1 reset */
-#define RCC_APB2RSTR_ADC3RST (1 << 15) /* Bit 15: ADC3 interface reset */
+#ifndef CONFIG_STM32_VALUELINE
+# define RCC_APB2RSTR_ADC3RST (1 << 15) /* Bit 15: ADC3 interface reset */
+#else
+# define RCC_APB2RSTR_TIM15RST (1 << 16) /* Bit 16: TIM15 reset */
+# define RCC_APB2RSTR_TIM16RST (1 << 17) /* Bit 17: TIM16 reset */
+# define RCC_APB2RSTR_TIM17RST (1 << 18) /* Bit 18: TIM17 reset */
+#endif
/* APB1 Peripheral reset register */
@@ -222,6 +234,11 @@
#define RCC_APB1RSTR_TIM5RST (1 << 3) /* Bit 3: Timer 5 reset */
#define RCC_APB1RSTR_TIM6RST (1 << 4) /* Bit 4: Timer 6 reset */
#define RCC_APB1RSTR_TIM7RST (1 << 5) /* Bit 5: Timer 7 reset */
+#ifdef CONFIG_STM32_VALUELINE
+# define RCC_APB1RSTR_TIM12RST (1 << 6) /* Bit 6: TIM12 reset */
+# define RCC_APB1RSTR_TIM13RST (1 << 7) /* Bit 7: TIM13 reset */
+# define RCC_APB1RSTR_TIM14RST (1 << 8) /* Bit 8: TIM14 reset */
+#endif
#define RCC_APB1RSTR_WWDGRST (1 << 11) /* Bit 11: Window Watchdog reset */
#define RCC_APB1RSTR_SPI2RST (1 << 14) /* Bit 14: SPI 2 reset */
#define RCC_APB1RSTR_SPI3RST (1 << 15) /* Bit 15: SPI 3 reset */
@@ -231,12 +248,17 @@
#define RCC_APB1RSTR_UART5RST (1 << 20) /* Bit 18: UART 5 reset */
#define RCC_APB1RSTR_I2C1RST (1 << 21) /* Bit 21: I2C 1 reset */
#define RCC_APB1RSTR_I2C2RST (1 << 22) /* Bit 22: I2C 2 reset */
-#define RCC_APB1RSTR_USBRST (1 << 23) /* Bit 23: USB reset */
-#define RCC_APB1RSTR_CAN1RST (1 << 25) /* Bit 25: CAN1 reset */
-#define RCC_APB1RSTR_CAN2RST (1 << 26) /* Bit 26: CAN2 reset */
+#ifndef CONFIG_STM32_VALUELINE
+# define RCC_APB1RSTR_USBRST (1 << 23) /* Bit 23: USB reset */
+# define RCC_APB1RSTR_CAN1RST (1 << 25) /* Bit 25: CAN1 reset */
+# define RCC_APB1RSTR_CAN2RST (1 << 26) /* Bit 26: CAN2 reset */
+#endif
#define RCC_APB1RSTR_BKPRST (1 << 27) /* Bit 27: Backup interface reset */
#define RCC_APB1RSTR_PWRRST (1 << 28) /* Bit 28: Power interface reset */
#define RCC_APB1RSTR_DACRST (1 << 29) /* Bit 29: DAC interface reset */
+#ifdef CONFIG_STM32_VALUELINE
+# define RCC_APB1RSTR_CECRST (1 << 30) /* Bit 30: CEC reset */
+#endif
/* AHB Peripheral Clock enable register */
@@ -246,7 +268,9 @@
#define RCC_AHBENR_FLITFEN (1 << 4) /* Bit 4: FLITF clock enable */
#define RCC_AHBENR_CRCEN (1 << 6) /* Bit 6: CRC clock enable */
#define RCC_AHBENR_FSMCEN (1 << 8) /* Bit 8: FSMC clock enable */
-#define RCC_AHBENR_SDIOEN (1 << 10) /* Bit 10: SDIO clock enable */
+#ifndef CONFIG_STM32_VALUELINE
+# define RCC_AHBENR_SDIOEN (1 << 10) /* Bit 10: SDIO clock enable */
+#endif
#ifdef CONFIG_STM32_CONNECTIVITYLINE
# define RCC_AHBENR_ETHMACEN (1 << 14) /* Bit 14: Ethernet MAC clock enable */
# define RCC_AHBENR_ETHMACTXEN (1 << 15) /* Bit 15: Ethernet MAC TX clock enable */
@@ -272,12 +296,22 @@
#define RCC_APB2ENR_IOPFEN (1 << 7) /* Bit 7: I/O port F clock enable */
#define RCC_APB2ENR_IOPGEN (1 << 8) /* Bit 8: I/O port G clock enable */
#define RCC_APB2ENR_ADC1EN (1 << 9) /* Bit 9: ADC 1 interface clock enable */
-#define RCC_APB2ENR_ADC2EN (1 << 10) /* Bit 10: ADC 2 interface clock enable */
+#ifndef CONFIG_STM32_VALUELINE
+# define RCC_APB2ENR_ADC2EN (1 << 10) /* Bit 10: ADC 2 interface clock enable */
+#endif
#define RCC_APB2ENR_TIM1EN (1 << 11) /* Bit 11: TIM1 Timer clock enable */
#define RCC_APB2ENR_SPI1EN (1 << 12) /* Bit 12: SPI 1 clock enable */
-#define RCC_APB2ENR_TIM8EN (1 << 13) /* Bit 13: TIM8 Timer clock enable */
+#ifndef CONFIG_STM32_VALUELINE
+# define RCC_APB2ENR_TIM8EN (1 << 13) /* Bit 13: TIM8 Timer clock enable */
+#endif
#define RCC_APB2ENR_USART1EN (1 << 14) /* Bit 14: USART1 clock enable */
-#define RCC_APB2ENR_ADC3EN (1 << 15) /* Bit 14: ADC3 interface clock enable */
+#ifndef CONFIG_STM32_VALUELINE
+# define RCC_APB2ENR_ADC3EN (1 << 15) /* Bit 14: ADC3 interface clock enable */
+#else
+# define RCC_APB2ENR_TIM15EN (1 << 16) /* Bit 16: TIM15 clock enable */
+# define RCC_APB2ENR_TIM16EN (1 << 17) /* Bit 17: TIM16 clock enable */
+# define RCC_APB2ENR_TIM17EN (1 << 18) /* Bit 18: TIM17 clock enable */
+#endif
/* APB1 Peripheral Clock enable register */
@@ -287,6 +321,11 @@
#define RCC_APB1ENR_TIM5EN (1 << 3) /* Bit 3: Timer 5 clock enable */
#define RCC_APB1ENR_TIM6EN (1 << 4) /* Bit 4: Timer 6 clock enable */
#define RCC_APB1ENR_TIM7EN (1 << 5) /* Bit 5: Timer 7 clock enable */
+#ifdef CONFIG_STM32_VALUELINE
+# define RCC_APB1ENR_TIM12EN (1 << 6) /* Bit 6: Timer 12 clock enable */
+# define RCC_APB1ENR_TIM13EN (1 << 7) /* Bit 7: Timer 13 clock enable */
+# define RCC_APB1ENR_TIM14EN (1 << 8) /* Bit 8: Timer 14 clock enable */
+#endif
#define RCC_APB1ENR_WWDGEN (1 << 11) /* Bit 11: Window Watchdog clock enable */
#define RCC_APB1ENR_SPI2EN (1 << 14) /* Bit 14: SPI 2 clock enable */
#define RCC_APB1ENR_SPI3EN (1 << 15) /* Bit 15: SPI 3 clock enable */
@@ -296,12 +335,17 @@
#define RCC_APB1ENR_UART5EN (1 << 20) /* Bit 20: UART 5 clock enable */
#define RCC_APB1ENR_I2C1EN (1 << 21) /* Bit 21: I2C 1 clock enable */
#define RCC_APB1ENR_I2C2EN (1 << 22) /* Bit 22: I2C 2 clock enable */
-#define RCC_APB1ENR_USBEN (1 << 23) /* Bit 23: USB clock enable */
-#define RCC_APB1ENR_CAN1EN (1 << 25) /* Bit 25: CAN1 clock enable */
-#define RCC_APB1ENR_CAN2EN (1 << 26) /* Bit 25: CAN2 clock enable */
+#ifndef CONFIG_STM32_VALUELINE
+# define RCC_APB1ENR_USBEN (1 << 23) /* Bit 23: USB clock enable */
+# define RCC_APB1ENR_CAN1EN (1 << 25) /* Bit 25: CAN1 clock enable */
+# define RCC_APB1ENR_CAN2EN (1 << 26) /* Bit 25: CAN2 clock enable */
+#endif
#define RCC_APB1ENR_BKPEN (1 << 27) /* Bit 27: Backup interface clock enable */
#define RCC_APB1ENR_PWREN (1 << 28) /* Bit 28: Power interface clock enable */
#define RCC_APB1ENR_DACEN (1 << 29) /* Bit 29: DAC interface clock enable */
+#ifdef CONFIG_STM32_VALUELINE
+# define RCC_APB1ENR_CECEN (1 << 30) /* Bit 30: CEC clock enable */
+#endif
/* Backup domain control register */
@@ -331,7 +375,7 @@
#if defined(CONFIG_STM32_VALUELINE) || defined(CONFIG_STM32_CONNECTIVITYLINE)
-/* Clock configuration register 2 (For connectivity line only) */
+/* Clock configuration register 2 (For value line and connectivity line only) */
#define RCC_CFGR2_PREDIV1_SHIFT (0)
#define RCC_CFGR2_PREDIV1_MASK (0x0f << RCC_CFGR2_PREDIV1_SHIFT)
@@ -352,6 +396,10 @@
# define RCC_CFGR2_PREDIV1d15 (14 << RCC_CFGR2_PREDIV1_SHIFT)
# define RCC_CFGR2_PREDIV1d16 (15 << RCC_CFGR2_PREDIV1_SHIFT)
+#endif
+
+#ifdef CONFIG_STM32_CONNECTIVITYLINE
+
#define RCC_CFGR2_PREDIV2_SHIFT (4)
#define RCC_CFGR2_PREDIV2_MASK (0x0f << RCC_CFGR2_PREDIV2_SHIFT)
# define RCC_CFGR2_PREDIV2d1 (0 << RCC_CFGR2_PREDIV2_SHIFT)
diff --git a/nuttx/arch/arm/src/stm32/chip/stm32f10xxx_vectors.h b/nuttx/arch/arm/src/stm32/chip/stm32f10xxx_vectors.h
index b8d71799f..24822c37d 100644
--- a/nuttx/arch/arm/src/stm32/chip/stm32f10xxx_vectors.h
+++ b/nuttx/arch/arm/src/stm32/chip/stm32f10xxx_vectors.h
@@ -49,15 +49,77 @@
* definition that provides the number of supported vectors.
*/
-#ifdef CONFIG_ARMV7M_CMNVECTOR
+# ifdef CONFIG_ARMV7M_CMNVECTOR
-/* Reserve 60 interrupt table entries for I/O interrupts. */
+/* Reserve 61 interrupt table entries for I/O interrupts. */
-# define ARMV7M_PERIPHERAL_INTERRUPTS 60
+# define ARMV7M_PERIPHERAL_INTERRUPTS 61
#else
-# error This target requires CONFIG_ARMV7M_CMNVECTOR
-#endif /* CONFIG_ARMV7M_CMNVECTOR */
+
+VECTOR(stm32_wwdg, STM32_IRQ_WWDG) /* Vector 16+0: Window Watchdog interrupt */
+VECTOR(stm32_pvd, STM32_IRQ_PVD) /* Vector 16+1: PVD through EXTI Line detection interrupt */
+VECTOR(stm32_tamper, STM32_IRQ_TAMPER) /* Vector 16+2: Tamper interrupt */
+VECTOR(stm32_rtc, STM32_IRQ_RTC) /* Vector 16+3: RTC Wakeup through EXTI line interrupt */
+VECTOR(stm32_flash, STM32_IRQ_FLASH) /* Vector 16+4: Flash global interrupt */
+VECTOR(stm32_rcc, STM32_IRQ_RCC) /* Vector 16+5: RCC global interrupt */
+VECTOR(stm32_exti0, STM32_IRQ_EXTI0) /* Vector 16+6: EXTI Line 0 interrupt */
+VECTOR(stm32_exti1, STM32_IRQ_EXTI1) /* Vector 16+7: EXTI Line 1 interrupt */
+VECTOR(stm32_exti2, STM32_IRQ_EXTI2) /* Vector 16+8: EXTI Line 2 interrupt */
+VECTOR(stm32_exti3, STM32_IRQ_EXTI3) /* Vector 16+9: EXTI Line 3 interrupt */
+VECTOR(stm32_exti4, STM32_IRQ_EXTI4) /* Vector 16+10: EXTI Line 4 interrupt */
+VECTOR(stm32_dma1ch1, STM32_IRQ_DMA1CH1) /* Vector 16+11: DMA1 Channel 1 global interrupt */
+VECTOR(stm32_dma1ch2, STM32_IRQ_DMA1CH2) /* Vector 16+12: DMA1 Channel 2 global interrupt */
+VECTOR(stm32_dma1ch3, STM32_IRQ_DMA1CH3) /* Vector 16+13: DMA1 Channel 3 global interrupt */
+VECTOR(stm32_dma1ch4, STM32_IRQ_DMA1CH4) /* Vector 16+14: DMA1 Channel 4 global interrupt */
+VECTOR(stm32_dma1ch5, STM32_IRQ_DMA1CH5) /* Vector 16+15: DMA1 Channel 5 global interrupt */
+VECTOR(stm32_dma1ch6, STM32_IRQ_DMA1CH6) /* Vector 16+16: DMA1 Channel 6 global interrupt */
+VECTOR(stm32_dma1ch7, STM32_IRQ_DMA1CH7) /* Vector 16+17: DMA1 Channel 7 global interrupt */
+VECTOR(stm32_adc1, STM32_IRQ_ADC1) /* Vector 16+18: ADC1 global interrupt */
+UNUSED(STM32_IRQ_RESERVED0) /* Vector 16+19: Reserved 0 */
+UNUSED(STM32_IRQ_RESERVED1) /* Vector 16+20: Reserved 1 */
+UNUSED(STM32_IRQ_RESERVED2) /* Vector 16+21: Reserved 2 */
+UNUSED(STM32_IRQ_RESERVED3) /* Vector 16+22: Reserved 3 */
+VECTOR(stm32_exti95, STM32_IRQ_EXTI95) /* Vector 16+23: EXTI Line[9:5] interrupts */
+VECTOR(stm32_tim1brk, STM32_IRQ_TIM1BRK) /* Vector 16+24: TIM1 Break interrupt; TIM15 global interrupt */
+VECTOR(stm32_tim1up, STM32_IRQ_TIM1UP) /* Vector 16+25: TIM1 Update interrupt; TIM16 global interrupt */
+VECTOR(stm32_tim1trgcom, STM32_IRQ_TIM1TRGCOM) /* Vector 16+26: TIM1 Trigger and Commutation interrupts; TIM17 global interrupt */
+VECTOR(stm32_tim1cc, STM32_IRQ_TIM1CC) /* Vector 16+27: TIM1 Capture Compare interrupt */
+VECTOR(stm32_tim2, STM32_IRQ_TIM2) /* Vector 16+28: TIM2 global interrupt */
+VECTOR(stm32_tim3, STM32_IRQ_TIM3) /* Vector 16+29: TIM3 global interrupt */
+VECTOR(stm32_tim4, STM32_IRQ_TIM4) /* Vector 16+30: TIM4 global interrupt */
+VECTOR(stm32_i2c1ev, STM32_IRQ_I2C1EV) /* Vector 16+31: I2C1 event interrupt */
+VECTOR(stm32_i2c1er, STM32_IRQ_I2C1ER) /* Vector 16+32: I2C1 error interrupt */
+VECTOR(stm32_i2c2ev, STM32_IRQ_I2C2EV) /* Vector 16+33: I2C2 event interrupt */
+VECTOR(stm32_i2c2er, STM32_IRQ_I2C2ER) /* Vector 16+34: I2C2 error interrupt */
+VECTOR(stm32_spi1, STM32_IRQ_SPI1) /* Vector 16+35: SPI1 global interrupt */
+VECTOR(stm32_spi2, STM32_IRQ_SPI2) /* Vector 16+36: SPI2 global interrupt */
+VECTOR(stm32_usart1, STM32_IRQ_USART1) /* Vector 16+37: USART1 global interrupt */
+VECTOR(stm32_usart2, STM32_IRQ_USART2) /* Vector 16+38: USART2 global interrupt */
+VECTOR(stm32_usart3, STM32_IRQ_USART3) /* Vector 16+39: USART3 global interrupt */
+VECTOR(stm32_exti1510, STM32_IRQ_EXTI1510) /* Vector 16+40: EXTI Line[15:10] interrupts */
+VECTOR(stm32_rtcalr, STM32_IRQ_RTCALR) /* Vector 16+41: RTC alarms (A and B) through EXTI line interrupt */
+VECTOR(stm32_cec, STM32_IRQ_CEC) /* Vector 16+42: CEC global interrupt */
+VECTOR(stm32_tim12, STM32_IRQ_TIM12) /* Vector 16+43: TIM12 global interrupt */
+VECTOR(stm32_tim13, STM32_IRQ_TIM13) /* Vector 16+44: TIM13 global interrupt */
+VECTOR(stm32_tim14, STM32_IRQ_TIM14) /* Vector 16+45: TIM14 global interrupt */
+UNUSED(STM32_IRQ_RESERVED4) /* Vector 16+46: Reserved 4 */
+UNUSED(STM32_IRQ_RESERVED5) /* Vector 16+47: Reserved 5 */
+VECTOR(stm32_fsmc, STM32_IRQ_FSMC) /* Vector 16+48: FSMC global interrupt */
+UNUSED(STM32_IRQ_RESERVED6) /* Vector 16+49: Reserved 6 */
+VECTOR(stm32_tim5, STM32_IRQ_TIM5) /* Vector 16+50: TIM5 global interrupt */
+VECTOR(stm32_spi3, STM32_IRQ_SPI3) /* Vector 16+51: SPI3 global interrupt */
+VECTOR(stm32_uart4, STM32_IRQ_UART4) /* Vector 16+52: USART2 global interrupt */
+VECTOR(stm32_uart5, STM32_IRQ_UART5) /* Vector 16+53: USART5 global interrupt */
+VECTOR(stm32_tim6, STM32_IRQ_TIM6) /* Vector 16+54: TIM6 global interrupt */
+VECTOR(stm32_tim7, STM32_IRQ_TIM7) /* Vector 16+55: TIM7 global interrupt */
+VECTOR(stm32_dma2ch1, STM32_IRQ_DMA2CH1) /* Vector 16+56: DMA2 Channel 1 global interrupt */
+VECTOR(stm32_dma2ch2, STM32_IRQ_DMA2CH2) /* Vector 16+57: DMA2 Channel 2 global interrupt */
+VECTOR(stm32_dma2ch3, STM32_IRQ_DMA2CH3) /* Vector 16+58: DMA2 Channel 3 global interrupt */
+VECTOR(stm32_dma2ch45, STM32_IRQ_DMA2CH45) /* Vector 16+59: DMA2 Channel 4 and 5 global interrupt */
+VECTOR(stm32_dma2ch5, STM32_IRQ_DMA2CH5) /* Vector 16+60: DMA2 Channel 5 global interrupt */
+
+# endif /* CONFIG_ARMV7M_CMNVECTOR */
#elif defined(CONFIG_STM32_CONNECTIVITYLINE)
diff --git a/nuttx/arch/arm/src/stm32/chip/stm32f20xxx_pinmap.h b/nuttx/arch/arm/src/stm32/chip/stm32f20xxx_pinmap.h
index 817e747f7..699ca4fdc 100644
--- a/nuttx/arch/arm/src/stm32/chip/stm32f20xxx_pinmap.h
+++ b/nuttx/arch/arm/src/stm32/chip/stm32f20xxx_pinmap.h
@@ -222,7 +222,7 @@
#define GPIO_ETH_MII_TX_EN_2 (GPIO_ALT|GPIO_AF11|GPIO_SPEED_100MHz|GPIO_PUSHPULL|GPIO_PORTG|GPIO_PIN11)
#define GPIO_ETH_PPS_OUT_1 (GPIO_ALT|GPIO_AF11|GPIO_SPEED_100MHz|GPIO_PUSHPULL|GPIO_PORTB|GPIO_PIN5)
#define GPIO_ETH_PPS_OUT_2 (GPIO_ALT|GPIO_AF11|GPIO_SPEED_100MHz|GPIO_PUSHPULL|GPIO_PORTG|GPIO_PIN8)
-#define GPIO_ETH_RMII_CRS_DV (GPIO_ALT|GPIO_AF11|GPIO_SPEED_100MHz|GPIO_PUSHPULLGPIO_PORTA|GPIO_PIN7)
+#define GPIO_ETH_RMII_CRS_DV (GPIO_ALT|GPIO_AF11|GPIO_SPEED_100MHz|GPIO_PUSHPULL|GPIO_PORTA|GPIO_PIN7)
#define GPIO_ETH_RMII_REF_CLK (GPIO_ALT|GPIO_AF11|GPIO_SPEED_100MHz|GPIO_PUSHPULL|GPIO_PORTA|GPIO_PIN1)
#define GPIO_ETH_RMII_RXD0 (GPIO_ALT|GPIO_AF11|GPIO_SPEED_100MHz|GPIO_PUSHPULL|GPIO_PORTC|GPIO_PIN4)
#define GPIO_ETH_RMII_RXD1 (GPIO_ALT|GPIO_AF11|GPIO_SPEED_100MHz|GPIO_PUSHPULL|GPIO_PORTC|GPIO_PIN5)
diff --git a/nuttx/arch/arm/src/stm32/chip/stm32f40xxx_pinmap.h b/nuttx/arch/arm/src/stm32/chip/stm32f40xxx_pinmap.h
index ae2436a70..31e51caf0 100644
--- a/nuttx/arch/arm/src/stm32/chip/stm32f40xxx_pinmap.h
+++ b/nuttx/arch/arm/src/stm32/chip/stm32f40xxx_pinmap.h
@@ -222,7 +222,7 @@
#define GPIO_ETH_MII_TX_EN_2 (GPIO_ALT|GPIO_AF11|GPIO_SPEED_100MHz|GPIO_PUSHPULL|GPIO_PORTG|GPIO_PIN11)
#define GPIO_ETH_PPS_OUT_1 (GPIO_ALT|GPIO_AF11|GPIO_SPEED_100MHz|GPIO_PUSHPULL|GPIO_PORTB|GPIO_PIN5)
#define GPIO_ETH_PPS_OUT_2 (GPIO_ALT|GPIO_AF11|GPIO_SPEED_100MHz|GPIO_PUSHPULL|GPIO_PORTG|GPIO_PIN8)
-#define GPIO_ETH_RMII_CRS_DV (GPIO_ALT|GPIO_AF11|GPIO_SPEED_100MHz|GPIO_PUSHPULLGPIO_PORTA|GPIO_PIN7)
+#define GPIO_ETH_RMII_CRS_DV (GPIO_ALT|GPIO_AF11|GPIO_SPEED_100MHz|GPIO_PUSHPULL|GPIO_PORTA|GPIO_PIN7)
#define GPIO_ETH_RMII_REF_CLK (GPIO_ALT|GPIO_AF11|GPIO_SPEED_100MHz|GPIO_PUSHPULL|GPIO_PORTA|GPIO_PIN1)
#define GPIO_ETH_RMII_RXD0 (GPIO_ALT|GPIO_AF11|GPIO_SPEED_100MHz|GPIO_PUSHPULL|GPIO_PORTC|GPIO_PIN4)
#define GPIO_ETH_RMII_RXD1 (GPIO_ALT|GPIO_AF11|GPIO_SPEED_100MHz|GPIO_PUSHPULL|GPIO_PORTC|GPIO_PIN5)
diff --git a/nuttx/arch/arm/src/stm32/stm32_adc.h b/nuttx/arch/arm/src/stm32/stm32_adc.h
index c25da3830..7b6c13b33 100644
--- a/nuttx/arch/arm/src/stm32/stm32_adc.h
+++ b/nuttx/arch/arm/src/stm32/stm32_adc.h
@@ -281,7 +281,7 @@
#if defined(ADC1_HAVE_TIMER) || defined(ADC2_HAVE_TIMER) || defined(ADC3_HAVE_TIMER)
# define ADC_HAVE_TIMER 1
-# if defined(CONFIG_STM32_STM32F10XX) && defined(CONFIG_STM32_FORCEPOWER)
+# if defined(CONFIG_STM32_STM32F10XX) && !defined(CONFIG_STM32_FORCEPOWER)
# warning "CONFIG_STM32_FORCEPOWER must be defined to enable the timer(s)"
# endif
#else
diff --git a/nuttx/arch/arm/src/stm32/stm32_eth.c b/nuttx/arch/arm/src/stm32/stm32_eth.c
index 3054142ce..006f67142 100644
--- a/nuttx/arch/arm/src/stm32/stm32_eth.c
+++ b/nuttx/arch/arm/src/stm32/stm32_eth.c
@@ -2594,6 +2594,17 @@ static int stm32_phyinit(FAR struct stm32_ethmac_s *priv)
}
up_mdelay(PHY_RESET_DELAY);
+ /* Perform any necessary, board-specific PHY initialization */
+
+#ifdef CONFIG_STM32_PHYINIT
+ ret = stm32_phy_boardinitialize(0);
+ if (ret < 0)
+ {
+ ndbg("Failed to initialize the PHY: %d\n", ret);
+ return ret;
+ }
+#endif
+
/* Special workaround for the Davicom DM9161 PHY is required. */
#ifdef CONFIG_PHY_DM9161
diff --git a/nuttx/arch/arm/src/stm32/stm32_eth.h b/nuttx/arch/arm/src/stm32/stm32_eth.h
index f0c14b5b1..4501712b1 100644
--- a/nuttx/arch/arm/src/stm32/stm32_eth.h
+++ b/nuttx/arch/arm/src/stm32/stm32_eth.h
@@ -66,14 +66,13 @@ extern "C" {
* Function: stm32_ethinitialize
*
* Description:
- * Initialize the Ethernet driver for one interface. If the STM32 chip
- * supports multiple Ethernet controllers, then board specific logic
- * must implement up_netinitialize() and call this function to initialize
- * the desired interfaces.
+ * Initialize the Ethernet driver for one interface. If the STM32 chip supports
+ * multiple Ethernet controllers, then board specific logic must implement
+ * up_netinitialize() and call this function to initialize the desired interfaces.
*
* Parameters:
- * intf - In the case where there are multiple EMACs, this value
- * identifies which EMAC is to be initialized.
+ * intf - In the case where there are multiple EMACs, this value identifies which
+ * EMAC is to be initialized.
*
* Returned Value:
* OK on success; Negated errno on failure.
@@ -86,6 +85,30 @@ extern "C" {
EXTERN int stm32_ethinitialize(int intf);
#endif
+/************************************************************************************
+ * Function: stm32_phy_boardinitialize
+ *
+ * Description:
+ * Some boards require specialized initialization of the PHY before it can be used.
+ * This may include such things as configuring GPIOs, resetting the PHY, etc. If
+ * CONFIG_STM32_PHYINIT is defined in the configuration then the board specific
+ * logic must provide stm32_phyinitialize(); The STM32 Ethernet driver will call
+ * this function one time before it first uses the PHY.
+ *
+ * Parameters:
+ * intf - Always zero for now.
+ *
+ * Returned Value:
+ * OK on success; Negated errno on failure.
+ *
+ * Assumptions:
+ *
+ ************************************************************************************/
+
+#ifdef CONFIG_STM32_PHYINIT
+EXTERN int stm32_phy_boardinitialize(int intf);
+#endif
+
#undef EXTERN
#if defined(__cplusplus)
}
diff --git a/nuttx/arch/arm/src/stm32/stm32_i2c.c b/nuttx/arch/arm/src/stm32/stm32_i2c.c
index a4b10b55c..fd682cd5d 100644
--- a/nuttx/arch/arm/src/stm32/stm32_i2c.c
+++ b/nuttx/arch/arm/src/stm32/stm32_i2c.c
@@ -107,17 +107,23 @@
#if !defined(CONFIG_STM32_I2CTIMEOSEC) && !defined(CONFIG_STM32_I2CTIMEOMS)
# define CONFIG_STM32_I2CTIMEOSEC 0
-# define CONFIG_STM32_I2CTIMEOMS 500 /* Default is 500 milliseconds */
+# define CONFIG_STM32_I2CTIMEOMS 500 /* Default is 500 milliseconds */
#elif !defined(CONFIG_STM32_I2CTIMEOSEC)
# define CONFIG_STM32_I2CTIMEOSEC 0 /* User provided milliseconds */
#elif !defined(CONFIG_STM32_I2CTIMEOMS)
-# define CONFIG_STM32_I2CTIMEOMS 0 /* User provided seconds */
+# define CONFIG_STM32_I2CTIMEOMS 0 /* User provided seconds */
#endif
/* Interrupt wait time timeout in system timer ticks */
-#define CONFIG_STM32_I2CTIMEOTICKS \
- (SEC2TICK(CONFIG_STM32_I2CTIMEOSEC) + MSEC2TICK(CONFIG_STM32_I2CTIMEOMS))
+#ifndef CONFIG_STM32_I2CTIMEOTICKS
+# define CONFIG_STM32_I2CTIMEOTICKS \
+ (SEC2TICK(CONFIG_STM32_I2CTIMEOSEC) + MSEC2TICK(CONFIG_STM32_I2CTIMEOMS))
+#endif
+
+#ifndef CONFIG_STM32_I2C_DYNTIMEO_STARTSTOP
+# define CONFIG_STM32_I2C_DYNTIMEO_STARTSTOP TICK2USEC(CONFIG_STM32_I2CTIMEOTICKS)
+#endif
/* On the STM32F103ZE, there is an internal conflict between I2C1 and FSMC. In that
* case, it is necessary to disable FSMC before each I2C1 access and re-enable FSMC
@@ -129,6 +135,18 @@
# define I2C1_FSMC_CONFLICT
#endif
+/* Macros to convert a I2C pin to a GPIO output */
+
+#if defined(CONFIG_STM32_STM32F10XX)
+# define I2C_OUTPUT (GPIO_OUTPUT | GPIO_OUTPUT_SET | GPIO_CNF_OUTOD | \
+ GPIO_MODE_50MHz)
+#elif defined(CONFIG_STM32_STM32F20XX) || defined(CONFIG_STM32_STM32F40XX)
+# define I2C_OUTPUT (GPIO_OUTPUT | GPIO_FLOAT | GPIO_OPENDRAIN |\
+ GPIO_SPEED_50MHz | GPIO_OUTPUT_SET)
+#endif
+
+#define MKI2C_OUTPUT(p) (((p) & (GPIO_PORT_MASK | GPIO_PIN_MASK)) | I2C_OUTPUT)
+
/* Debug ****************************************************************************/
/* CONFIG_DEBUG_I2C + CONFIG_DEBUG enables general I2C debug output. */
@@ -200,18 +218,16 @@ struct stm32_trace_s
struct stm32_i2c_config_s
{
- uint32_t base; /* I2C base address */
+ uint32_t base; /* I2C base address */
+ uint32_t clk_bit; /* Clock enable bit */
+ uint32_t reset_bit; /* Reset bit */
+ uint32_t scl_pin; /* GPIO configuration for SCL as SCL */
+ uint32_t sda_pin; /* GPIO configuration for SDA as SDA */
#ifndef CONFIG_I2C_POLLED
- int ( *isr)(int, void *); /* Interrupt handler */
+ int (*isr)(int, void *); /* Interrupt handler */
+ uint32_t ev_irq; /* Event IRQ */
+ uint32_t er_irq; /* Error IRQ */
#endif
- uint32_t clk_bit; /* Clock enable bit */
- uint32_t reset_bit; /* Reset bit */
- uint32_t scl_pin; /* GPIO configuration for SCL as SCL */
- uint32_t scl_gpio; /* GPIO configuration for SCL as a GPIO */
- uint32_t sda_pin; /* GPIO configuration for SDA as SDA */
- uint32_t sda_gpio; /* GPIO configuration for SDA as a GPIO */
- uint32_t ev_irq; /* Event IRQ */
- uint32_t er_irq; /* Error IRQ */
};
/* I2C Device Private Data */
@@ -219,31 +235,31 @@ struct stm32_i2c_config_s
struct stm32_i2c_priv_s
{
const struct stm32_i2c_config_s *config; /* Port configuration */
- int refs; /* Referernce count */
- sem_t sem_excl; /* Mutual exclusion semaphore */
+ int refs; /* Referernce count */
+ sem_t sem_excl; /* Mutual exclusion semaphore */
#ifndef CONFIG_I2C_POLLED
- sem_t sem_isr; /* Interrupt wait semaphore */
+ sem_t sem_isr; /* Interrupt wait semaphore */
#endif
- volatile uint8_t intstate; /* Interrupt handshake (see enum stm32_intstate_e) */
+ volatile uint8_t intstate; /* Interrupt handshake (see enum stm32_intstate_e) */
- uint8_t msgc; /* Message count */
- struct i2c_msg_s *msgv; /* Message list */
- uint8_t *ptr; /* Current message buffer */
- int dcnt; /* Current message length */
- uint16_t flags; /* Current message flags */
+ uint8_t msgc; /* Message count */
+ struct i2c_msg_s *msgv; /* Message list */
+ uint8_t *ptr; /* Current message buffer */
+ int dcnt; /* Current message length */
+ uint16_t flags; /* Current message flags */
/* I2C trace support */
#ifdef CONFIG_I2C_TRACE
- int tndx; /* Trace array index */
- uint32_t start_time; /* Time when the trace was started */
+ int tndx; /* Trace array index */
+ uint32_t start_time; /* Time when the trace was started */
/* The actual trace data */
struct stm32_trace_s trace[CONFIG_I2C_NTRACE];
#endif
- uint32_t status; /* End of transfer SR2|SR1 status */
+ uint32_t status; /* End of transfer SR2|SR1 status */
};
/* I2C Device, Instance */
@@ -270,8 +286,11 @@ static inline void stm32_i2c_modifyreg(FAR struct stm32_i2c_priv_s *priv,
uint8_t offset, uint16_t clearbits,
uint16_t setbits);
static inline void stm32_i2c_sem_wait(FAR struct i2c_dev_s *dev);
-static inline int stm32_i2c_sem_waitdone(FAR struct stm32_i2c_priv_s *priv, int timeout_us);
-static inline void stm32_i2c_sem_waitstop(FAR struct stm32_i2c_priv_s *priv, int timeout_us);
+#ifdef CONFIG_STM32_I2C_DYNTIMEO
+static useconds_t stm32_i2c_tousecs(int msgc, FAR struct i2c_msg_s *msgs);
+#endif /* CONFIG_STM32_I2C_DYNTIMEO */
+static inline int stm32_i2c_sem_waitdone(FAR struct stm32_i2c_priv_s *priv);
+static inline void stm32_i2c_sem_waitstop(FAR struct stm32_i2c_priv_s *priv);
static inline void stm32_i2c_sem_post(FAR struct i2c_dev_s *dev);
static inline void stm32_i2c_sem_init(FAR struct i2c_dev_s *dev);
static inline void stm32_i2c_sem_destroy(FAR struct i2c_dev_s *dev);
@@ -281,7 +300,7 @@ static void stm32_i2c_tracenew(FAR struct stm32_i2c_priv_s *priv, uint32_t statu
static void stm32_i2c_traceevent(FAR struct stm32_i2c_priv_s *priv,
enum stm32_trace_e event, uint32_t parm);
static void stm32_i2c_tracedump(FAR struct stm32_i2c_priv_s *priv);
-#endif
+#endif /* CONFIG_I2C_TRACE */
static void stm32_i2c_setclock(FAR struct stm32_i2c_priv_s *priv,
uint32_t frequency);
static inline void stm32_i2c_sendstart(FAR struct stm32_i2c_priv_s *priv);
@@ -291,7 +310,7 @@ static inline uint32_t stm32_i2c_getstatus(FAR struct stm32_i2c_priv_s *priv);
#ifdef I2C1_FSMC_CONFLICT
static inline uint32_t stm32_i2c_disablefsmc(FAR struct stm32_i2c_priv_s *priv);
static inline void stm32_i2c_enablefsmc(uint32_t ahbenr);
-#endif
+#endif /* I2C1_FSMC_CONFLICT */
static int stm32_i2c_isr(struct stm32_i2c_priv_s * priv);
#ifndef CONFIG_I2C_POLLED
#ifdef CONFIG_STM32_I2C1
@@ -329,27 +348,18 @@ static int stm32_i2c_transfer(FAR struct i2c_dev_s *dev, FAR struct i2c_msg_s *m
************************************************************************************/
#ifdef CONFIG_STM32_I2C1
-# ifndef GPIO_I2C1_SCL_GPIO
-# define GPIO_I2C1_SCL_GPIO 0
-# endif
-# ifndef GPIO_I2C1_SDA_GPIO
-# define GPIO_I2C1_SDA_GPIO 0
-# endif
-
static const struct stm32_i2c_config_s stm32_i2c1_config =
{
.base = STM32_I2C1_BASE,
-#ifndef CONFIG_I2C_POLLED
- .isr = stm32_i2c1_isr,
-#endif
.clk_bit = RCC_APB1ENR_I2C1EN,
.reset_bit = RCC_APB1RSTR_I2C1RST,
.scl_pin = GPIO_I2C1_SCL,
- .scl_gpio = GPIO_I2C1_SCL_GPIO,
.sda_pin = GPIO_I2C1_SDA,
- .sda_gpio = GPIO_I2C1_SDA_GPIO,
+#ifndef CONFIG_I2C_POLLED
+ .isr = stm32_i2c1_isr,
.ev_irq = STM32_IRQ_I2C1EV,
.er_irq = STM32_IRQ_I2C1ER
+#endif
};
struct stm32_i2c_priv_s stm32_i2c1_priv =
@@ -367,27 +377,18 @@ struct stm32_i2c_priv_s stm32_i2c1_priv =
#endif
#ifdef CONFIG_STM32_I2C2
-# ifndef GPIO_I2C2_SCL_GPIO
-# define GPIO_I2C2_SCL_GPIO 0
-# endif
-# ifndef GPIO_I2C2_SDA_GPIO
-# define GPIO_I2C2_SDA_GPIO 0
-# endif
-
static const struct stm32_i2c_config_s stm32_i2c2_config =
{
.base = STM32_I2C2_BASE,
-#ifndef CONFIG_I2C_POLLED
- .isr = stm32_i2c2_isr,
-#endif
.clk_bit = RCC_APB1ENR_I2C2EN,
.reset_bit = RCC_APB1RSTR_I2C2RST,
.scl_pin = GPIO_I2C2_SCL,
- .scl_gpio = GPIO_I2C2_SCL_GPIO,
.sda_pin = GPIO_I2C2_SDA,
- .sda_gpio = GPIO_I2C2_SDA_GPIO,
+#ifndef CONFIG_I2C_POLLED
+ .isr = stm32_i2c2_isr,
.ev_irq = STM32_IRQ_I2C2EV,
.er_irq = STM32_IRQ_I2C2ER
+#endif
};
struct stm32_i2c_priv_s stm32_i2c2_priv =
@@ -405,27 +406,18 @@ struct stm32_i2c_priv_s stm32_i2c2_priv =
#endif
#ifdef CONFIG_STM32_I2C3
-# ifndef GPIO_I2C3_SCL_GPIO
-# define GPIO_I2C3_SCL_GPIO 0
-# endif
-# ifndef GPIO_I2C3_SDA_GPIO
-# define GPIO_I2C3_SDA_GPIO 0
-# endif
-
static const struct stm32_i2c_config_s stm32_i2c3_config =
{
.base = STM32_I2C3_BASE,
-#ifndef CONFIG_I2C_POLLED
- .isr = stm32_i2c3_isr,
-#endif
.clk_bit = RCC_APB1ENR_I2C3EN,
.reset_bit = RCC_APB1RSTR_I2C3RST,
.scl_pin = GPIO_I2C3_SCL,
- .scl_gpio = GPIO_I2C3_SCL_GPIO,
.sda_pin = GPIO_I2C3_SDA,
- .sda_gpio = GPIO_I2C3_SDA_GPIO,
+#ifndef CONFIG_I2C_POLLED
+ .isr = stm32_i2c3_isr,
.ev_irq = STM32_IRQ_I2C3EV,
.er_irq = STM32_IRQ_I2C3ER
+#endif
};
struct stm32_i2c_priv_s stm32_i2c3_priv =
@@ -526,6 +518,35 @@ static inline void stm32_i2c_sem_wait(FAR struct i2c_dev_s *dev)
}
/************************************************************************************
+ * Name: stm32_i2c_tousecs
+ *
+ * Description:
+ * Return a micro-second delay based on the number of bytes left to be processed.
+ *
+ ************************************************************************************/
+
+#ifdef CONFIG_STM32_I2C_DYNTIMEO
+static useconds_t stm32_i2c_tousecs(int msgc, FAR struct i2c_msg_s *msgs)
+{
+ size_t bytecount = 0;
+ int i;
+
+ /* Count the number of bytes left to process */
+
+ for (i = 0; i < msgc; i++)
+ {
+ bytecount += msgs[i].length;
+ }
+
+ /* Then return a number of microseconds based on a user provided scaling
+ * factor.
+ */
+
+ return (useconds_t)(CONFIG_STM32_I2C_DYNTIMEO_USECPERBYTE * bytecount);
+}
+#endif
+
+/************************************************************************************
* Name: stm32_i2c_sem_waitdone
*
* Description:
@@ -534,7 +555,7 @@ static inline void stm32_i2c_sem_wait(FAR struct i2c_dev_s *dev)
************************************************************************************/
#ifndef CONFIG_I2C_POLLED
-static inline int stm32_i2c_sem_waitdone(FAR struct stm32_i2c_priv_s *priv, int timeout_us)
+static inline int stm32_i2c_sem_waitdone(FAR struct stm32_i2c_priv_s *priv)
{
struct timespec abstime;
irqstate_t flags;
@@ -566,31 +587,24 @@ static inline int stm32_i2c_sem_waitdone(FAR struct stm32_i2c_priv_s *priv, int
#if CONFIG_STM32_I2CTIMEOSEC > 0
abstime.tv_sec += CONFIG_STM32_I2CTIMEOSEC;
#endif
-#if CONFIG_STM32_I2CTIMEOUS_PER_BYTE > 0
- /* Count the number of bytes left to process */
- int i;
- int bytecount = 0;
- for (i = 0; i < priv->msgc; i++)
+ /* Add a value proportional to the number of bytes in the transfer */
+
+#ifdef CONFIG_STM32_I2C_DYNTIMEO
+ abstime.tv_nsec += 1000 * stm32_i2c_tousecs(priv->msgc, priv->msgv);
+ if (abstime.tv_nsec > 1000 * 1000 * 1000)
{
- bytecount += priv->msgv[i].length;
+ abstime.tv_sec++;
+ abstime.tv_nsec -= 1000 * 1000 * 1000;
}
- abstime.tv_nsec += (CONFIG_STM32_I2CTIMEOUS_PER_BYTE * bytecount) * 1000;
+#elif CONFIG_STM32_I2CTIMEOMS > 0
+ abstime.tv_nsec += CONFIG_STM32_I2CTIMEOMS * 1000 * 1000;
if (abstime.tv_nsec > 1000 * 1000 * 1000)
{
abstime.tv_sec++;
abstime.tv_nsec -= 1000 * 1000 * 1000;
}
-#else
- #if CONFIG_STM32_I2CTIMEOMS > 0
- abstime.tv_nsec += CONFIG_STM32_I2CTIMEOMS * 1000 * 1000;
- if (abstime.tv_nsec > 1000 * 1000 * 1000)
- {
- abstime.tv_sec++;
- abstime.tv_nsec -= 1000 * 1000 * 1000;
- }
- #endif
#endif
/* Wait until either the transfer is complete or the timeout expires */
@@ -624,12 +638,21 @@ static inline int stm32_i2c_sem_waitdone(FAR struct stm32_i2c_priv_s *priv, int
return ret;
}
#else
-static inline int stm32_i2c_sem_waitdone(FAR struct stm32_i2c_priv_s *priv, int timeout_us)
+static inline int stm32_i2c_sem_waitdone(FAR struct stm32_i2c_priv_s *priv)
{
+ uint32_t timeout;
uint32_t start;
uint32_t elapsed;
int ret;
+ /* Get the timeout value */
+
+#ifdef CONFIG_STM32_I2C_DYNTIMEO
+ timeout = USEC2TICK(stm32_i2c_tousecs(priv->msgc, priv->msgv));
+#else
+ timeout = CONFIG_STM32_I2CTIMEOTICKS;
+#endif
+
/* Signal the interrupt handler that we are waiting. NOTE: Interrupts
* are currently disabled but will be temporarily re-enabled below when
* sem_timedwait() sleeps.
@@ -652,10 +675,11 @@ static inline int stm32_i2c_sem_waitdone(FAR struct stm32_i2c_priv_s *priv, int
}
/* Loop until the transfer is complete. */
- while (priv->intstate != INTSTATE_DONE && elapsed < USEC2TICK(timeout_us));
+
+ while (priv->intstate != INTSTATE_DONE && elapsed < timeout);
i2cvdbg("intstate: %d elapsed: %d threshold: %d status: %08x\n",
- priv->intstate, elapsed, USEC2TICK(timeout_us), priv->status);
+ priv->intstate, elapsed, timeout, priv->status);
/* Set the interrupt state back to IDLE */
@@ -673,13 +697,22 @@ static inline int stm32_i2c_sem_waitdone(FAR struct stm32_i2c_priv_s *priv, int
*
************************************************************************************/
-static inline void stm32_i2c_sem_waitstop(FAR struct stm32_i2c_priv_s *priv, int timeout_us)
+static inline void stm32_i2c_sem_waitstop(FAR struct stm32_i2c_priv_s *priv)
{
uint32_t start;
uint32_t elapsed;
+ uint32_t timeout;
uint32_t cr1;
uint32_t sr1;
+ /* Select a timeout */
+
+#ifdef CONFIG_STM32_I2C_DYNTIMEO
+ timeout = USEC2TICK(CONFIG_STM32_I2C_DYNTIMEO_STARTSTOP);
+#else
+ timeout = CONFIG_STM32_I2CTIMEOTICKS;
+#endif
+
/* Wait as stop might still be in progress; but stop might also
* be set because of a timeout error: "The [STOP] bit is set and
* cleared by software, cleared by hardware when a Stop condition is
@@ -712,7 +745,7 @@ static inline void stm32_i2c_sem_waitstop(FAR struct stm32_i2c_priv_s *priv, int
/* Loop until the stop is complete or a timeout occurs. */
- while (elapsed < USEC2TICK(timeout_us));
+ while (elapsed < timeout);
/* If we get here then a timeout occurred with the STOP condition
* still pending.
@@ -932,7 +965,7 @@ static void stm32_i2c_setclock(FAR struct stm32_i2c_priv_s *priv, uint32_t frequ
{
/* Fast mode speed calculation with Tlow/Thigh = 16/9 */
-#ifdef CONFIG_I2C_DUTY16_9
+#ifdef CONFIG_STM32_I2C_DUTY16_9
speed = (uint16_t)(STM32_PCLK1_FREQUENCY / (frequency * 25));
/* Set DUTY and fast speed bits */
@@ -1071,7 +1104,7 @@ static inline uint32_t stm32_i2c_disablefsmc(FAR struct stm32_i2c_priv_s *priv)
/* Is this I2C1 */
-#ifdef CONFIG_STM32_I2C2
+#if defined(CONFIG_STM32_I2C2) || defined(CONFIG_STM32_I2C3)
if (priv->config->base == STM32_I2C1_BASE)
#endif
{
@@ -1198,10 +1231,14 @@ static int stm32_i2c_isr(struct stm32_i2c_priv_s *priv)
{
stm32_i2c_traceevent(priv, I2CEVENT_RCVBYTE, priv->dcnt);
+ /* No interrupts or context switches may occur in the following
+ * sequence. Otherwise, additional bytes may be sent by the
+ * device.
+ */
+
#ifdef CONFIG_I2C_POLLED
irqstate_t state = irqsave();
#endif
-
/* Receive a byte */
*priv->ptr++ = stm32_i2c_getreg(priv, STM32_I2C_DR_OFFSET);
@@ -1217,7 +1254,6 @@ static int stm32_i2c_isr(struct stm32_i2c_priv_s *priv)
#ifdef CONFIG_I2C_POLLED
irqrestore(state);
#endif
-
}
}
@@ -1408,7 +1444,6 @@ static int stm32_i2c_init(FAR struct stm32_i2c_priv_s *priv)
/* Enable power and reset the peripheral */
modifyreg32(STM32_RCC_APB1ENR, 0, priv->config->clk_bit);
-
modifyreg32(STM32_RCC_APB1RSTR, 0, priv->config->reset_bit);
modifyreg32(STM32_RCC_APB1RSTR, priv->config->reset_bit, 0);
@@ -1428,10 +1463,10 @@ static int stm32_i2c_init(FAR struct stm32_i2c_priv_s *priv)
/* Attach ISRs */
#ifndef CONFIG_I2C_POLLED
- irq_attach(priv->config->ev_irq, priv->config->isr);
- irq_attach(priv->config->er_irq, priv->config->isr);
- up_enable_irq(priv->config->ev_irq);
- up_enable_irq(priv->config->er_irq);
+ irq_attach(priv->config->ev_irq, priv->config->isr);
+ irq_attach(priv->config->er_irq, priv->config->isr);
+ up_enable_irq(priv->config->ev_irq);
+ up_enable_irq(priv->config->er_irq);
#endif
/* Set peripheral frequency, where it must be at least 2 MHz for 100 kHz
@@ -1461,17 +1496,23 @@ static int stm32_i2c_deinit(FAR struct stm32_i2c_priv_s *priv)
stm32_i2c_putreg(priv, STM32_I2C_CR1_OFFSET, 0);
+ /* Unconfigure GPIO pins */
+
stm32_unconfiggpio(priv->config->scl_pin);
stm32_unconfiggpio(priv->config->sda_pin);
+ /* Disable and detach interrupts */
+
#ifndef CONFIG_I2C_POLLED
up_disable_irq(priv->config->ev_irq);
up_disable_irq(priv->config->er_irq);
irq_detach(priv->config->ev_irq);
irq_detach(priv->config->er_irq);
#endif
- modifyreg32(STM32_RCC_APB1ENR, priv->config->clk_bit, 0);
+ /* Disable clocking */
+
+ modifyreg32(STM32_RCC_APB1ENR, priv->config->clk_bit, 0);
return OK;
}
@@ -1533,14 +1574,14 @@ static int stm32_i2c_process(FAR struct i2c_dev_s *dev, FAR struct i2c_msg_s *ms
struct stm32_i2c_inst_s *inst = (struct stm32_i2c_inst_s *)dev;
FAR struct stm32_i2c_priv_s *priv = inst->priv;
uint32_t status = 0;
- //uint32_t ahbenr;
+ uint32_t ahbenr;
int errval = 0;
ASSERT(count);
/* Disable FSMC that shares a pin with I2C1 (LBAR) */
- (void)stm32_i2c_disablefsmc(priv);
+ ahbenr = stm32_i2c_disablefsmc(priv);
/* Wait for any STOP in progress. NOTE: If we have to disable the FSMC
* then we cannot do this at the top of the loop, unfortunately. The STOP
@@ -1548,11 +1589,7 @@ static int stm32_i2c_process(FAR struct i2c_dev_s *dev, FAR struct i2c_msg_s *ms
*/
#ifndef I2C1_FSMC_CONFLICT
- #if CONFIG_STM32_I2CTIMEOUS_START_STOP > 0
- stm32_i2c_sem_waitstop(priv, CONFIG_STM32_I2CTIMEOUS_START_STOP);
- #else
- stm32_i2c_sem_waitstop(priv, CONFIG_STM32_I2CTIMEOMS + CONFIG_STM32_I2CTIMEOSEC * 1000000);
- #endif
+ stm32_i2c_sem_waitstop(priv);
#endif
/* Clear any pending error interrupts */
@@ -1573,22 +1610,6 @@ static int stm32_i2c_process(FAR struct i2c_dev_s *dev, FAR struct i2c_msg_s *ms
priv->msgv = msgs;
priv->msgc = count;
- /* Calculate timeout values */
- int timeout_us = 0;
- #if CONFIG_STM32_I2CTIMEOUS_PER_BYTE > 0
- /* Count the number of bytes left to process */
- int i;
- int bytecount = 10;
- for (i = 0; i < count; i++)
- {
- bytecount += msgs[i].length;
- }
- timeout_us = CONFIG_STM32_I2CTIMEOUS_PER_BYTE * bytecount;
- //i2cvdbg("i2c wait: %d\n", timeout_us);
- #else
- timeout_us = CONFIG_STM32_I2CTIMEOMS + CONFIG_STM32_I2CTIMEOSEC * 1000000;
- #endif
-
/* Reset I2C trace logic */
stm32_i2c_tracereset(priv);
@@ -1608,7 +1629,7 @@ static int stm32_i2c_process(FAR struct i2c_dev_s *dev, FAR struct i2c_msg_s *ms
* the BUSY flag.
*/
- if (stm32_i2c_sem_waitdone(priv, timeout_us) < 0)
+ if (stm32_i2c_sem_waitdone(priv) < 0)
{
status = stm32_i2c_getstatus(priv);
errval = ETIMEDOUT;
@@ -1623,7 +1644,9 @@ static int stm32_i2c_process(FAR struct i2c_dev_s *dev, FAR struct i2c_msg_s *ms
*/
stm32_i2c_clrstart(priv);
- // XXX also clear busy flag in case of timeout
+
+ /* Clear busy flag in case of timeout */
+
status = priv->status & 0xffff;
}
else
@@ -1953,11 +1976,14 @@ int up_i2cuninitialize(FAR struct i2c_dev_s * dev)
*
************************************************************************************/
+#ifdef CONFIG_I2C_RESET
int up_i2creset(FAR struct i2c_dev_s * dev)
{
struct stm32_i2c_priv_s * priv;
- unsigned clock_count;
- unsigned stretch_count;
+ unsigned int clock_count;
+ unsigned int stretch_count;
+ uint32_t scl_gpio;
+ uint32_t sda_gpio;
int ret = ERROR;
irqstate_t state;
@@ -1979,83 +2005,70 @@ int up_i2creset(FAR struct i2c_dev_s * dev)
stm32_i2c_deinit(priv);
- /* If possible, use GPIO configuration to un-wedge the bus */
+ /* Use GPIO configuration to un-wedge the bus */
- if ((priv->config->scl_gpio != 0) && (priv->config->sda_gpio != 0))
+ scl_gpio = MKI2C_OUTPUT(priv->config->scl_pin);
+ sda_gpio = MKI2C_OUTPUT(priv->config->sda_pin);
+
+ /* Clock the bus until any slaves currently driving it let it go. */
+
+ clock_count = 0;
+ while (!stm32_gpioread(sda_gpio))
{
- stm32_configgpio(priv->config->scl_gpio);
- stm32_configgpio(priv->config->sda_gpio);
+ /* Give up if we have tried too hard */
- /*
- * Clock the bus until any slaves currently driving it let it go.
- */
+ if (clock_count++ > 1000)
+ {
+ goto out;
+ }
- clock_count = 0;
- while (!stm32_gpioread(priv->config->sda_gpio))
- {
+ /* Sniff to make sure that clock stretching has finished.
+ *
+ * If the bus never relaxes, the reset has failed.
+ */
+ stretch_count = 0;
+ while (!stm32_gpioread(scl_gpio))
+ {
/* Give up if we have tried too hard */
- if (clock_count++ > 1000)
+ if (stretch_count++ > 1000)
{
goto out;
}
- /*
- * Sniff to make sure that clock stretching has finished.
- *
- * If the bus never relaxes, the reset has failed.
- */
-
- stretch_count = 0;
- while (!stm32_gpioread(priv->config->scl_gpio))
- {
-
- /* Give up if we have tried too hard */
-
- if (stretch_count++ > 1000)
- {
- goto out;
- }
-
- up_udelay(10);
-
- }
-
- /* Drive SCL low */
-
- stm32_gpiowrite(priv->config->scl_gpio, 0);
- up_udelay(10);
-
- /* Drive SCL high again */
-
- stm32_gpiowrite(priv->config->scl_gpio, 1);
- up_udelay(10);
-
+ up_udelay(10);
}
- /*
- * Generate a start followed by a stop to reset slave
- * state machines.
- */
+ /* Drive SCL low */
- stm32_gpiowrite(priv->config->sda_gpio, 0);
- up_udelay(10);
- stm32_gpiowrite(priv->config->scl_gpio, 0);
- up_udelay(10);
- stm32_gpiowrite(priv->config->scl_gpio, 1);
- up_udelay(10);
- stm32_gpiowrite(priv->config->sda_gpio, 1);
+ stm32_gpiowrite(scl_gpio, 0);
up_udelay(10);
- /*
- * Revert the GPIO configuration.
- */
- stm32_unconfiggpio(priv->config->sda_gpio);
- stm32_unconfiggpio(priv->config->scl_gpio);
+ /* Drive SCL high again */
+ stm32_gpiowrite(scl_gpio, 1);
+ up_udelay(10);
}
+ /* Generate a start followed by a stop to reset slave
+ * state machines.
+ */
+
+ stm32_gpiowrite(sda_gpio, 0);
+ up_udelay(10);
+ stm32_gpiowrite(scl_gpio, 0);
+ up_udelay(10);
+ stm32_gpiowrite(scl_gpio, 1);
+ up_udelay(10);
+ stm32_gpiowrite(sda_gpio, 1);
+ up_udelay(10);
+
+ /* Revert the GPIO configuration. */
+
+ stm32_unconfiggpio(sda_gpio);
+ stm32_unconfiggpio(scl_gpio);
+
/* Re-init the port */
stm32_i2c_init(priv);
@@ -2063,11 +2076,11 @@ int up_i2creset(FAR struct i2c_dev_s * dev)
out:
- /* release the port for re-use by other clients */
+ /* Release the port for re-use by other clients */
stm32_i2c_sem_post(dev);
-
return ret;
}
+#endif /* CONFIG_I2C_RESET */
-#endif /* defined(CONFIG_STM32_I2C1) || defined(CONFIG_STM32_I2C2) || defined(CONFIG_STM32_I2C3) */
+#endif /* CONFIG_STM32_I2C1 || CONFIG_STM32_I2C2 || CONFIG_STM32_I2C3 */
diff --git a/nuttx/arch/arm/src/stm32/stm32_lowputc.c b/nuttx/arch/arm/src/stm32/stm32_lowputc.c
index 7f7205672..6cb07dad9 100644
--- a/nuttx/arch/arm/src/stm32/stm32_lowputc.c
+++ b/nuttx/arch/arm/src/stm32/stm32_lowputc.c
@@ -67,6 +67,14 @@
# define STM32_CONSOLE_2STOP CONFIG_USART1_2STOP
# define STM32_CONSOLE_TX GPIO_USART1_TX
# define STM32_CONSOLE_RX GPIO_USART1_RX
+# ifdef CONFIG_USART1_RS485
+# define STM32_CONSOLE_RS485_DIR GPIO_USART1_RS485_DIR
+# if (CONFIG_USART1_RS485_DIR_POLARITY == 0)
+# define STM32_CONSOLE_RS485_DIR_POLARITY false
+# else
+# define STM32_CONSOLE_RS485_DIR_POLARITY true
+# endif
+# endif
#elif defined(CONFIG_USART2_SERIAL_CONSOLE)
# define STM32_CONSOLE_BASE STM32_USART2_BASE
# define STM32_APBCLOCK STM32_PCLK1_FREQUENCY
@@ -76,6 +84,14 @@
# define STM32_CONSOLE_2STOP CONFIG_USART2_2STOP
# define STM32_CONSOLE_TX GPIO_USART2_TX
# define STM32_CONSOLE_RX GPIO_USART2_RX
+# ifdef CONFIG_USART2_RS485
+# define STM32_CONSOLE_RS485_DIR GPIO_USART2_RS485_DIR
+# if (CONFIG_USART2_RS485_DIR_POLARITY == 0)
+# define STM32_CONSOLE_RS485_DIR_POLARITY false
+# else
+# define STM32_CONSOLE_RS485_DIR_POLARITY true
+# endif
+# endif
#elif defined(CONFIG_USART3_SERIAL_CONSOLE)
# define STM32_CONSOLE_BASE STM32_USART3_BASE
# define STM32_APBCLOCK STM32_PCLK1_FREQUENCY
@@ -85,6 +101,14 @@
# define STM32_CONSOLE_2STOP CONFIG_USART3_2STOP
# define STM32_CONSOLE_TX GPIO_USART3_TX
# define STM32_CONSOLE_RX GPIO_USART3_RX
+# ifdef CONFIG_USART3_RS485
+# define STM32_CONSOLE_RS485_DIR GPIO_USART3_RS485_DIR
+# if (CONFIG_USART3_RS485_DIR_POLARITY == 0)
+# define STM32_CONSOLE_RS485_DIR_POLARITY false
+# else
+# define STM32_CONSOLE_RS485_DIR_POLARITY true
+# endif
+# endif
#elif defined(CONFIG_UART4_SERIAL_CONSOLE)
# define STM32_CONSOLE_BASE STM32_UART4_BASE
# define STM32_APBCLOCK STM32_PCLK1_FREQUENCY
@@ -94,6 +118,14 @@
# define STM32_CONSOLE_2STOP CONFIG_UART4_2STOP
# define STM32_CONSOLE_TX GPIO_UART4_TX
# define STM32_CONSOLE_RX GPIO_UART4_RX
+# ifdef CONFIG_UART4_RS485
+# define STM32_CONSOLE_RS485_DIR GPIO_UART4_RS485_DIR
+# if (CONFIG_UART4_RS485_DIR_POLARITY == 0)
+# define STM32_CONSOLE_RS485_DIR_POLARITY false
+# else
+# define STM32_CONSOLE_RS485_DIR_POLARITY true
+# endif
+# endif
#elif defined(CONFIG_UART5_SERIAL_CONSOLE)
# define STM32_CONSOLE_BASE STM32_UART5_BASE
# define STM32_APBCLOCK STM32_PCLK1_FREQUENCY
@@ -103,6 +135,14 @@
# define STM32_CONSOLE_2STOP CONFIG_UART5_2STOP
# define STM32_CONSOLE_TX GPIO_UART5_TX
# define STM32_CONSOLE_RX GPIO_UART5_RX
+# ifdef CONFIG_UART5_RS485
+# define STM32_CONSOLE_RS485_DIR GPIO_UART5_RS485_DIR
+# if (CONFIG_UART5_RS485_DIR_POLARITY == 0)
+# define STM32_CONSOLE_RS485_DIR_POLARITY false
+# else
+# define STM32_CONSOLE_RS485_DIR_POLARITY true
+# endif
+# endif
#elif defined(CONFIG_USART6_SERIAL_CONSOLE)
# define STM32_CONSOLE_BASE STM32_USART6_BASE
# define STM32_APBCLOCK STM32_PCLK2_FREQUENCY
@@ -112,6 +152,14 @@
# define STM32_CONSOLE_2STOP CONFIG_USART6_2STOP
# define STM32_CONSOLE_TX GPIO_USART6_TX
# define STM32_CONSOLE_RX GPIO_USART6_RX
+# ifdef CONFIG_USART6_RS485
+# define STM32_CONSOLE_RS485_DIR GPIO_USART6_RS485_DIR
+# if (CONFIG_USART6_RS485_DIR_POLARITY == 0)
+# define STM32_CONSOLE_RS485_DIR_POLARITY false
+# else
+# define STM32_CONSOLE_RS485_DIR_POLARITY true
+# endif
+# endif
#endif
/* CR1 settings */
@@ -230,10 +278,19 @@ void up_lowputc(char ch)
/* Wait until the TX data register is empty */
while ((getreg32(STM32_CONSOLE_BASE + STM32_USART_SR_OFFSET) & USART_SR_TXE) == 0);
+#if STM32_CONSOLE_RS485_DIR
+ stm32_gpiowrite(STM32_CONSOLE_RS485_DIR, STM32_CONSOLE_RS485_DIR_POLARITY);
+#endif
/* Then send the character */
putreg32((uint32_t)ch, STM32_CONSOLE_BASE + STM32_USART_DR_OFFSET);
+
+#if STM32_CONSOLE_RS485_DIR
+ while ((getreg32(STM32_CONSOLE_BASE + STM32_USART_SR_OFFSET) & USART_SR_TC) == 0);
+ stm32_gpiowrite(STM32_CONSOLE_RS485_DIR, !STM32_CONSOLE_RS485_DIR_POLARITY);
+#endif
+
#endif
}
@@ -328,7 +385,14 @@ void stm32_lowsetup(void)
#ifdef STM32_CONSOLE_TX
stm32_configgpio(STM32_CONSOLE_TX);
- stm32_configgpio(STM32_CONSOLE_TX);
+#endif
+#ifdef STM32_CONSOLE_RX
+ stm32_configgpio(STM32_CONSOLE_RX);
+#endif
+
+#if STM32_CONSOLE_RS485_DIR
+ stm32_configgpio(STM32_CONSOLE_RS485_DIR);
+ stm32_gpiowrite(STM32_CONSOLE_RS485_DIR, !STM32_CONSOLE_RS485_DIR_POLARITY);
#endif
/* Enable and configure the selected console device */
@@ -382,7 +446,14 @@ void stm32_lowsetup(void)
#ifdef STM32_CONSOLE_TX
stm32_configgpio(STM32_CONSOLE_TX);
- stm32_configgpio(STM32_CONSOLE_TX);
+#endif
+#ifdef STM32_CONSOLE_RX
+ stm32_configgpio(STM32_CONSOLE_RX);
+#endif
+
+#if STM32_CONSOLE_RS485_DIR
+ stm32_configgpio(STM32_CONSOLE_RS485_DIR);
+ stm32_gpiowrite(STM32_CONSOLE_RS485_DIR, !STM32_CONSOLE_RS485_DIR_POLARITY);
#endif
/* Enable and configure the selected console device */
diff --git a/nuttx/arch/arm/src/stm32/stm32_otgfsdev.c b/nuttx/arch/arm/src/stm32/stm32_otgfsdev.c
index 461d500ad..94772b693 100644
--- a/nuttx/arch/arm/src/stm32/stm32_otgfsdev.c
+++ b/nuttx/arch/arm/src/stm32/stm32_otgfsdev.c
@@ -3651,10 +3651,14 @@ static int stm32_epout_configure(FAR struct stm32_ep_s *privep, uint8_t eptype,
regval = stm32_getreg(regaddr);
if ((regval & OTGFS_DOEPCTL_USBAEP) == 0)
{
- regval &= ~(OTGFS_DOEPCTL_MPSIZ_MASK | OTGFS_DIEPCTL_EPTYP_MASK | OTGFS_DIEPCTL_TXFNUM_MASK);
+ if (regval & OTGFS_DOEPCTL_NAKSTS)
+ {
+ regval |= OTGFS_DOEPCTL_CNAK;
+ }
+
+ regval &= ~(OTGFS_DOEPCTL_MPSIZ_MASK | OTGFS_DOEPCTL_EPTYP_MASK);
regval |= mpsiz;
regval |= (eptype << OTGFS_DOEPCTL_EPTYP_SHIFT);
- regval |= (eptype << OTGFS_DIEPCTL_TXFNUM_SHIFT);
regval |= (OTGFS_DOEPCTL_SD0PID | OTGFS_DOEPCTL_USBAEP);
stm32_putreg(regval, regaddr);
@@ -3743,6 +3747,11 @@ static int stm32_epin_configure(FAR struct stm32_ep_s *privep, uint8_t eptype,
regval = stm32_getreg(regaddr);
if ((regval & OTGFS_DIEPCTL_USBAEP) == 0)
{
+ if (regval & OTGFS_DIEPCTL_NAKSTS)
+ {
+ regval |= OTGFS_DIEPCTL_CNAK;
+ }
+
regval &= ~(OTGFS_DIEPCTL_MPSIZ_MASK | OTGFS_DIEPCTL_EPTYP_MASK | OTGFS_DIEPCTL_TXFNUM_MASK);
regval |= mpsiz;
regval |= (eptype << OTGFS_DIEPCTL_EPTYP_SHIFT);
@@ -3900,7 +3909,7 @@ static void stm32_epout_disable(FAR struct stm32_ep_s *privep)
* Name: stm32_epin_disable
*
* Description:
- * Diable an IN endpoint will no longer be used
+ * Disable an IN endpoint when it will no longer be used
*
*******************************************************************************/
@@ -3912,6 +3921,17 @@ static void stm32_epin_disable(FAR struct stm32_ep_s *privep)
usbtrace(TRACE_EPDISABLE, privep->epphy);
+ /* After USB reset, the endpoint will already be deactivated by the
+ * hardware. Trying to disable again will just hang in the wait.
+ */
+
+ regaddr = STM32_OTGFS_DIEPCTL(privep->epphy);
+ regval = stm32_getreg(regaddr);
+ if ((regval & OTGFS_DIEPCTL_USBAEP) == 0)
+ {
+ return;
+ }
+
/* Make sure that there is no pending IPEPNE interrupt (because we are
* to poll this bit below).
*/
diff --git a/nuttx/arch/arm/src/stm32/stm32_otgfshost.c b/nuttx/arch/arm/src/stm32/stm32_otgfshost.c
index 02b12ec87..80a9392dc 100644
--- a/nuttx/arch/arm/src/stm32/stm32_otgfshost.c
+++ b/nuttx/arch/arm/src/stm32/stm32_otgfshost.c
@@ -51,6 +51,7 @@
#include <nuttx/arch.h>
#include <nuttx/kmalloc.h>
+#include <nuttx/clock.h>
#include <nuttx/usb/usb.h>
#include <nuttx/usb/usbhost.h>
@@ -149,8 +150,8 @@
#define STM32_READY_DELAY 200000 /* In loop counts */
#define STM32_FLUSH_DELAY 200000 /* In loop counts */
-#define STM32_SETUP_DELAY 5000 /* In frames */
-#define STM32_DATANAK_DELAY 5000 /* In frames */
+#define STM32_SETUP_DELAY (5000 / MSEC_PER_TICK) /* 5 seconds in system ticks */
+#define STM32_DATANAK_DELAY (5000 / MSEC_PER_TICK) /* 5 seconds in system ticks */
/* Ever-present MIN/MAX macros */
@@ -305,7 +306,9 @@ static void stm32_chan_wakeup(FAR struct stm32_usbhost_s *priv,
/* Control/data transfer logic *************************************************/
static void stm32_transfer_start(FAR struct stm32_usbhost_s *priv, int chidx);
+#if 0 /* Not used */
static inline uint16_t stm32_getframe(void);
+#endif
static int stm32_ctrl_sendsetup(FAR struct stm32_usbhost_s *priv,
FAR const struct usb_ctrlreq_s *req);
static int stm32_ctrl_senddata(FAR struct stm32_usbhost_s *priv,
@@ -1182,14 +1185,18 @@ static void stm32_transfer_start(FAR struct stm32_usbhost_s *priv, int chidx)
* Name: stm32_getframe
*
* Description:
- * Get the current frame number.
+ * Get the current frame number. The frame number (FRNUM) field increments
+ * when a new SOF is transmitted on the USB, and is cleared to 0 when it
+ * reaches 0x3fff.
*
*******************************************************************************/
+#if 0 /* Not used */
static inline uint16_t stm32_getframe(void)
{
return (uint16_t)(stm32_getreg(STM32_OTGFS_HFNUM) & OTGFS_HFNUM_FRNUM_MASK);
}
+#endif
/*******************************************************************************
* Name: stm32_ctrl_sendsetup
@@ -1203,14 +1210,14 @@ static int stm32_ctrl_sendsetup(FAR struct stm32_usbhost_s *priv,
FAR const struct usb_ctrlreq_s *req)
{
FAR struct stm32_chan_s *chan;
- uint16_t start;
- uint16_t elapsed;
+ uint32_t start;
+ uint32_t elapsed;
int ret;
/* Loop while the device reports NAK (and a timeout is not exceeded */
chan = &priv->chan[priv->ep0out];
- start = stm32_getframe();
+ start = clock_systimer();
do
{
@@ -1258,7 +1265,7 @@ static int stm32_ctrl_sendsetup(FAR struct stm32_usbhost_s *priv,
/* Get the elapsed time (in frames) */
- elapsed = stm32_getframe() - start;
+ elapsed = clock_systimer() - start;
}
while (elapsed < STM32_SETUP_DELAY);
@@ -1367,8 +1374,8 @@ static int stm32_in_transfer(FAR struct stm32_usbhost_s *priv, int chidx,
FAR uint8_t *buffer, size_t buflen)
{
FAR struct stm32_chan_s *chan;
- uint16_t start;
- uint16_t elapsed;
+ uint32_t start;
+ uint32_t elapsed;
int ret = OK;
/* Loop until the transfer completes (i.e., buflen is decremented to zero)
@@ -1379,7 +1386,7 @@ static int stm32_in_transfer(FAR struct stm32_usbhost_s *priv, int chidx,
chan->buffer = buffer;
chan->buflen = buflen;
- start = stm32_getframe();
+ start = clock_systimer();
while (chan->buflen > 0)
{
/* Set up for the wait BEFORE starting the transfer */
@@ -1447,7 +1454,7 @@ static int stm32_in_transfer(FAR struct stm32_usbhost_s *priv, int chidx,
* buffer pointer and buffer size will be unaltered.
*/
- elapsed = stm32_getframe() - start;
+ elapsed = clock_systimer() - start;
if (ret != -EAGAIN || /* Not a NAK condition OR */
elapsed >= STM32_DATANAK_DELAY || /* Timeout has elapsed OR */
chan->buflen != buflen) /* Data has been partially transferred */
@@ -1474,8 +1481,8 @@ static int stm32_out_transfer(FAR struct stm32_usbhost_s *priv, int chidx,
FAR uint8_t *buffer, size_t buflen)
{
FAR struct stm32_chan_s *chan;
- uint16_t start;
- uint16_t elapsed;
+ uint32_t start;
+ uint32_t elapsed;
size_t xfrlen;
int ret = OK;
@@ -1484,7 +1491,7 @@ static int stm32_out_transfer(FAR struct stm32_usbhost_s *priv, int chidx,
*/
chan = &priv->chan[chidx];
- start = stm32_getframe();
+ start = clock_systimer();
while (buflen > 0)
{
@@ -1569,7 +1576,7 @@ static int stm32_out_transfer(FAR struct stm32_usbhost_s *priv, int chidx,
* buffer pointer and buffer size will be unaltered.
*/
- elapsed = stm32_getframe() - start;
+ elapsed = clock_systimer() - start;
if (ret != -EAGAIN || /* Not a NAK condition OR */
elapsed >= STM32_DATANAK_DELAY || /* Timeout has elapsed OR */
chan->buflen != xfrlen) /* Data has been partially transferred */
@@ -3540,8 +3547,8 @@ static int stm32_ctrlin(FAR struct usbhost_driver_s *drvr,
{
struct stm32_usbhost_s *priv = (struct stm32_usbhost_s *)drvr;
uint16_t buflen;
- uint16_t start;
- uint16_t elapsed;
+ uint32_t start;
+ uint32_t elapsed;
int retries;
int ret;
@@ -3573,7 +3580,7 @@ static int stm32_ctrlin(FAR struct usbhost_driver_s *drvr,
/* Get the start time. Loop again until the timeout expires */
- start = stm32_getframe();
+ start = clock_systimer();
do
{
/* Handle the IN data phase (if any) */
@@ -3606,7 +3613,7 @@ static int stm32_ctrlin(FAR struct usbhost_driver_s *drvr,
/* Get the elapsed time (in frames) */
- elapsed = stm32_getframe() - start;
+ elapsed = clock_systimer() - start;
}
while (elapsed < STM32_DATANAK_DELAY);
}
@@ -3623,8 +3630,8 @@ static int stm32_ctrlout(FAR struct usbhost_driver_s *drvr,
{
struct stm32_usbhost_s *priv = (struct stm32_usbhost_s *)drvr;
uint16_t buflen;
- uint16_t start;
- uint16_t elapsed;
+ uint32_t start;
+ uint32_t elapsed;
int retries;
int ret;
@@ -3658,7 +3665,7 @@ static int stm32_ctrlout(FAR struct usbhost_driver_s *drvr,
/* Get the start time. Loop again until the timeout expires */
- start = stm32_getframe();
+ start = clock_systimer();
do
{
/* Handle the data OUT phase (if any) */
@@ -3693,7 +3700,7 @@ static int stm32_ctrlout(FAR struct usbhost_driver_s *drvr,
/* Get the elapsed time (in frames) */
- elapsed = stm32_getframe() - start;
+ elapsed = clock_systimer() - start;
}
while (elapsed < STM32_DATANAK_DELAY);
}
diff --git a/nuttx/arch/arm/src/stm32/stm32_qencoder.c b/nuttx/arch/arm/src/stm32/stm32_qencoder.c
index 8553296f9..d37614c03 100644
--- a/nuttx/arch/arm/src/stm32/stm32_qencoder.c
+++ b/nuttx/arch/arm/src/stm32/stm32_qencoder.c
@@ -607,6 +607,7 @@ static FAR struct stm32_lowerhalf_s *stm32_tim2lower(int tim)
#endif
#ifdef CONFIG_STM32_TIM3_QE
case 3:
+ return &g_tim3lower;
#endif
#ifdef CONFIG_STM32_TIM4_QE
case 4:
diff --git a/nuttx/arch/arm/src/stm32/stm32_serial.c b/nuttx/arch/arm/src/stm32/stm32_serial.c
index 0868c3cd3..aa46a8987 100644
--- a/nuttx/arch/arm/src/stm32/stm32_serial.c
+++ b/nuttx/arch/arm/src/stm32/stm32_serial.c
@@ -96,6 +96,19 @@
# endif
# endif
+/* Currently RS-485 support cannot be enabled when RXDMA is in use due to lack
+ * of testing - RS-485 support was developed on STM32F1x
+ */
+
+# if (defined(CONFIG_USART1_RXDMA) && defined(CONFIG_USART1_RS485)) || \
+ (defined(CONFIG_USART2_RXDMA) && defined(CONFIG_USART2_RS485)) || \
+ (defined(CONFIG_USART3_RXDMA) && defined(CONFIG_USART3_RS485)) || \
+ (defined(CONFIG_UART4_RXDMA) && defined(CONFIG_UART4_RS485)) || \
+ (defined(CONFIG_UART5_RXDMA) && defined(CONFIG_UART5_RS485)) || \
+ (defined(CONFIG_USART6_RXDMA) && defined(CONFIG_USART6_RS485))
+# error "RXDMA and RS-485 cannot be enabled at the same time for the same U[S]ART"
+# endif
+
/* For the F4, there are alternate DMA channels for USART1 and 6.
* Logic in the board.h file make the DMA channel selection by defining
* the following in the board.h file.
@@ -219,6 +232,11 @@ struct up_dev_s
uint32_t rxdmanext; /* Next byte in the DMA buffer to be read */
char *const rxfifo; /* Receive DMA buffer */
#endif
+
+#ifdef HAVE_RS485
+ const uint32_t rs485_dir_gpio; /* U[S]ART RS-485 DIR GPIO pin configuration */
+ const bool rs485_dir_polarity; /* U[S]ART RS-485 DIR pin state for TX enabled */
+#endif
};
/****************************************************************************
@@ -415,6 +433,15 @@ static struct up_dev_s g_usart1priv =
.rxfifo = g_usart1rxfifo,
#endif
.vector = up_interrupt_usart1,
+
+#ifdef CONFIG_USART1_RS485
+ .rs485_dir_gpio = GPIO_USART1_RS485_DIR,
+# if (CONFIG_USART1_RS485_DIR_POLARITY == 0)
+ .rs485_dir_polarity = false,
+# else
+ .rs485_dir_polarity = true,
+# endif
+#endif
};
#endif
@@ -468,6 +495,15 @@ static struct up_dev_s g_usart2priv =
.rxfifo = g_usart2rxfifo,
#endif
.vector = up_interrupt_usart2,
+
+#ifdef CONFIG_USART2_RS485
+ .rs485_dir_gpio = GPIO_USART2_RS485_DIR,
+# if (CONFIG_USART2_RS485_DIR_POLARITY == 0)
+ .rs485_dir_polarity = false,
+# else
+ .rs485_dir_polarity = true,
+# endif
+#endif
};
#endif
@@ -521,6 +557,15 @@ static struct up_dev_s g_usart3priv =
.rxfifo = g_usart3rxfifo,
#endif
.vector = up_interrupt_usart3,
+
+#ifdef CONFIG_USART3_RS485
+ .rs485_dir_gpio = GPIO_USART3_RS485_DIR,
+# if (CONFIG_USART3_RS485_DIR_POLARITY == 0)
+ .rs485_dir_polarity = false,
+# else
+ .rs485_dir_polarity = true,
+# endif
+#endif
};
#endif
@@ -570,6 +615,15 @@ static struct up_dev_s g_uart4priv =
.rxfifo = g_uart4rxfifo,
#endif
.vector = up_interrupt_uart4,
+
+#ifdef CONFIG_UART4_RS485
+ .rs485_dir_gpio = GPIO_UART4_RS485_DIR,
+# if (CONFIG_UART4_RS485_DIR_POLARITY == 0)
+ .rs485_dir_polarity = false,
+# else
+ .rs485_dir_polarity = true,
+# endif
+#endif
};
#endif
@@ -619,6 +673,15 @@ static struct up_dev_s g_uart5priv =
.rxfifo = g_uart5rxfifo,
#endif
.vector = up_interrupt_uart5,
+
+#ifdef CONFIG_UART5_RS485
+ .rs485_dir_gpio = GPIO_UART5_RS485_DIR,
+# if (CONFIG_UART5_RS485_DIR_POLARITY == 0)
+ .rs485_dir_polarity = false,
+# else
+ .rs485_dir_polarity = true,
+# endif
+#endif
};
#endif
@@ -672,6 +735,15 @@ static struct up_dev_s g_usart6priv =
.rxfifo = g_usart6rxfifo,
#endif
.vector = up_interrupt_usart6,
+
+#ifdef CONFIG_USART6_RS485
+ .rs485_dir_gpio = GPIO_USART6_RS485_DIR,
+# if (CONFIG_USART6_RS485_DIR_POLARITY == 0)
+ .rs485_dir_polarity = false,
+# else
+ .rs485_dir_polarity = true,
+# endif
+#endif
};
#endif
@@ -744,8 +816,8 @@ static void up_restoreusartint(struct up_dev_s *priv, uint16_t ie)
/* And restore the interrupt state (see the interrupt enable/usage table above) */
cr = up_serialin(priv, STM32_USART_CR1_OFFSET);
- cr &= ~(USART_CR1_RXNEIE|USART_CR1_TXEIE|USART_CR1_PEIE);
- cr |= (ie & (USART_CR1_RXNEIE|USART_CR1_TXEIE|USART_CR1_PEIE));
+ cr &= ~(USART_CR1_USED_INTS);
+ cr |= (ie & (USART_CR1_USED_INTS));
up_serialout(priv, STM32_USART_CR1_OFFSET, cr);
cr = up_serialin(priv, STM32_USART_CR3_OFFSET);
@@ -772,7 +844,7 @@ static inline void up_disableusartint(struct up_dev_s *priv, uint16_t *ie)
* USART_CR1_IDLEIE 4 USART_SR_IDLE Idle Line Detected (not used)
* USART_CR1_RXNEIE 5 USART_SR_RXNE Received Data Ready to be Read
* " " USART_SR_ORE Overrun Error Detected
- * USART_CR1_TCIE 6 USART_SR_TC Transmission Complete (not used)
+ * USART_CR1_TCIE 6 USART_SR_TC Transmission Complete (used only for RS-485)
* USART_CR1_TXEIE 7 USART_SR_TXE Transmit Data Register Empty
* USART_CR1_PEIE 8 USART_SR_PE Parity Error
*
@@ -791,7 +863,7 @@ static inline void up_disableusartint(struct up_dev_s *priv, uint16_t *ie)
* overlap. This logic would fail if we needed the break interrupt!
*/
- *ie = (cr1 & (USART_CR1_RXNEIE|USART_CR1_TXEIE|USART_CR1_PEIE)) | (cr3 & USART_CR3_EIE);
+ *ie = (cr1 & (USART_CR1_USED_INTS)) | (cr3 & USART_CR3_EIE);
}
/* Disable all interrupts */
@@ -853,18 +925,18 @@ static void up_set_format(struct uart_dev_s *dev)
* usartdiv32 = 32 * usartdiv = fCK / (baud/2)
*/
- usartdiv32 = priv->apbclock / (priv->baud >> 1);
+ usartdiv32 = priv->apbclock / (priv->baud >> 1);
- /* The mantissa part is then */
+ /* The mantissa part is then */
- mantissa = usartdiv32 >> 5;
- brr = mantissa << USART_BRR_MANT_SHIFT;
+ mantissa = usartdiv32 >> 5;
+ brr = mantissa << USART_BRR_MANT_SHIFT;
- /* The fractional remainder (with rounding) */
+ /* The fractional remainder (with rounding) */
- fraction = (usartdiv32 - (mantissa << 5) + 1) >> 1;
- brr |= fraction << USART_BRR_FRAC_SHIFT;
- up_serialout(priv, STM32_USART_BRR_OFFSET, brr);
+ fraction = (usartdiv32 - (mantissa << 5) + 1) >> 1;
+ brr |= fraction << USART_BRR_FRAC_SHIFT;
+ up_serialout(priv, STM32_USART_BRR_OFFSET, brr);
/* Configure parity mode */
@@ -946,6 +1018,14 @@ static int up_setup(struct uart_dev_s *dev)
stm32_configgpio(priv->rts_gpio);
}
+#if HAVE_RS485
+ if (priv->rs485_dir_gpio != 0)
+ {
+ stm32_configgpio(priv->rs485_dir_gpio);
+ stm32_gpiowrite(priv->rs485_dir_gpio, !priv->rs485_dir_polarity);
+ }
+#endif
+
/* Configure CR2 */
/* Clear CLKEN, CPOL, CPHA, LBCL, and interrupt enable bits */
@@ -990,13 +1070,11 @@ static int up_setup(struct uart_dev_s *dev)
regval = up_serialin(priv, STM32_USART_CR1_OFFSET);
regval |= (USART_CR1_UE|USART_CR1_TE|USART_CR1_RE);
up_serialout(priv, STM32_USART_CR1_OFFSET, regval);
-
-#endif /* CONFIG_SUPPRESS_UART_CONFIG */
+#endif
/* Set up the cached interrupt enables value */
- up_restoreusartint(priv, 0);
-
+ priv->ie = 0;
return OK;
}
@@ -1217,7 +1295,7 @@ static int up_interrupt_common(struct up_dev_s *priv)
* USART_CR1_IDLEIE 4 USART_SR_IDLE Idle Line Detected (not used)
* USART_CR1_RXNEIE 5 USART_SR_RXNE Received Data Ready to be Read
* " " USART_SR_ORE Overrun Error Detected
- * USART_CR1_TCIE 6 USART_SR_TC Transmission Complete (not used)
+ * USART_CR1_TCIE 6 USART_SR_TC Transmission Complete (used only for RS-485)
* USART_CR1_TXEIE 7 USART_SR_TXE Transmit Data Register Empty
* USART_CR1_PEIE 8 USART_SR_PE Parity Error
*
@@ -1232,6 +1310,21 @@ static int up_interrupt_common(struct up_dev_s *priv)
* being used.
*/
+#ifdef HAVE_RS485
+ /* Transmission of whole buffer is over - TC is set, TXEIE is cleared.
+ * Note - this should be first, to have the most recent TC bit value from
+ * SR register - sending data affects TC, but without refresh we will not
+ * know that...
+ */
+
+ if ((priv->sr & USART_SR_TC) != 0 && (priv->ie & USART_CR1_TCIE) != 0 &&
+ (priv->ie & USART_CR1_TXEIE) == 0)
+ {
+ stm32_gpiowrite(priv->rs485_dir_gpio, !priv->rs485_dir_polarity);
+ up_restoreusartint(priv, priv->ie & ~USART_CR1_TCIE);
+ }
+#endif
+
/* Handle incoming, receive bytes. */
if ((priv->sr & USART_SR_RXNE) != 0 && (priv->ie & USART_CR1_RXNEIE) != 0)
@@ -1265,13 +1358,14 @@ static int up_interrupt_common(struct up_dev_s *priv)
if ((priv->sr & USART_SR_TXE) != 0 && (priv->ie & USART_CR1_TXEIE) != 0)
{
- /* Transmit data regiser empty ... process outgoing bytes */
+ /* Transmit data register empty ... process outgoing bytes */
uart_xmitchars(&priv->dev);
handled = true;
}
}
- return OK;
+
+ return OK;
}
/****************************************************************************
@@ -1611,6 +1705,10 @@ static bool up_dma_rxavailable(struct uart_dev_s *dev)
static void up_send(struct uart_dev_s *dev, int ch)
{
struct up_dev_s *priv = (struct up_dev_s*)dev->priv;
+#ifdef HAVE_RS485
+ if (priv->rs485_dir_gpio != 0)
+ stm32_gpiowrite(priv->rs485_dir_gpio, priv->rs485_dir_polarity);
+#endif
up_serialout(priv, STM32_USART_DR_OFFSET, (uint32_t)ch);
}
@@ -1631,7 +1729,7 @@ static void up_txint(struct uart_dev_s *dev, bool enable)
*
* Enable Bit Status Meaning Usage
* ------------------ --- --------------- ---------------------------- ----------
- * USART_CR1_TCIE 6 USART_SR_TC Transmission Complete (not used)
+ * USART_CR1_TCIE 6 USART_SR_TC Transmission Complete (used only for RS-485)
* USART_CR1_TXEIE 7 USART_SR_TXE Transmit Data Register Empty
* USART_CR3_CTSIE 10 USART_SR_CTS CTS flag (not used)
*/
@@ -1642,7 +1740,20 @@ static void up_txint(struct uart_dev_s *dev, bool enable)
/* Set to receive an interrupt when the TX data register is empty */
#ifndef CONFIG_SUPPRESS_SERIAL_INTS
- up_restoreusartint(priv, priv->ie | USART_CR1_TXEIE);
+ uint16_t ie = priv->ie | USART_CR1_TXEIE;
+
+ /* If RS-485 is supported on this U[S]ART, then also enable the
+ * transmission complete interrupt.
+ */
+
+# ifdef HAVE_RS485
+ if (priv->rs485_dir_gpio != 0)
+ {
+ ie |= USART_CR1_TCIE;
+ }
+# endif
+
+ up_restoreusartint(priv, ie);
/* Fake a TX interrupt here by just calling uart_xmitchars() with
* interrupts disabled (note this may recurse).
@@ -1657,6 +1768,7 @@ static void up_txint(struct uart_dev_s *dev, bool enable)
up_restoreusartint(priv, priv->ie & ~USART_CR1_TXEIE);
}
+
irqrestore(flags);
}
diff --git a/nuttx/arch/arm/src/stm32/stm32_uart.h b/nuttx/arch/arm/src/stm32/stm32_uart.h
index a70923cbf..8ff6a9975 100644
--- a/nuttx/arch/arm/src/stm32/stm32_uart.h
+++ b/nuttx/arch/arm/src/stm32/stm32_uart.h
@@ -223,6 +223,20 @@
# undef SERIAL_HAVE_ONLY_DMA
#endif
+/* Is RS-485 used? */
+
+#if defined(CONFIG_USART1_RS485) || defined(CONFIG_USART2_RS485) || \
+ defined(CONFIG_USART3_RS485) || defined(CONFIG_UART4_RS485) || \
+ defined(CONFIG_UART5_RS485) || defined(CONFIG_USART6_RS485)
+# define HAVE_RS485 1
+#endif
+
+#ifdef HAVE_RS485
+# define USART_CR1_USED_INTS (USART_CR1_RXNEIE | USART_CR1_TXEIE | USART_CR1_PEIE | USART_CR1_TCIE)
+#else
+# define USART_CR1_USED_INTS (USART_CR1_RXNEIE | USART_CR1_TXEIE | USART_CR1_PEIE)
+#endif
+
/************************************************************************************
* Public Types
************************************************************************************/
diff --git a/nuttx/arch/arm/src/stm32/stm32f10xxx_rcc.c b/nuttx/arch/arm/src/stm32/stm32f10xxx_rcc.c
index 47ed5e016..ae3fa516e 100644
--- a/nuttx/arch/arm/src/stm32/stm32f10xxx_rcc.c
+++ b/nuttx/arch/arm/src/stm32/stm32f10xxx_rcc.c
@@ -92,7 +92,11 @@ static inline void rcc_reset(void)
putreg32(regval, STM32_RCC_CR);
regval = getreg32(STM32_RCC_CFGR); /* Reset PLLSRC, PLLXTPRE, PLLMUL and USBPRE bits */
- regval &= ~(RCC_CFGR_PLLSRC|RCC_CFGR_PLLXTPRE|RCC_CFGR_PLLMUL_MASK|RCC_CFGR_USBPRE);
+ regval &= ~(RCC_CFGR_PLLSRC|RCC_CFGR_PLLXTPRE|RCC_CFGR_PLLMUL_MASK
+#ifndef CONFIG_STM32_VALUELINE
+ |RCC_CFGR_USBPRE
+#endif
+ );
putreg32(regval, STM32_RCC_CFGR);
putreg32(0, STM32_RCC_CIR); /* Disable all interrupts */
@@ -224,6 +228,27 @@ static inline void rcc_enableapb1(void)
#endif
#endif
+#ifdef CONFIG_STM32_TIM12
+ /* Timer 12 clock enable */
+#ifdef CONFIG_STM32_FORCEPOWER
+ regval |= RCC_APB1ENR_TIM12EN;
+#endif
+#endif
+
+#ifdef CONFIG_STM32_TIM13
+ /* Timer 13 clock enable */
+#ifdef CONFIG_STM32_FORCEPOWER
+ regval |= RCC_APB1ENR_TIM13EN;
+#endif
+#endif
+
+#ifdef CONFIG_STM32_TIM14
+ /* Timer 14 clock enable */
+#ifdef CONFIG_STM32_FORCEPOWER
+ regval |= RCC_APB1ENR_TIM14EN;
+#endif
+#endif
+
#ifdef CONFIG_STM32_WWDG
/* Window Watchdog clock enable */
@@ -315,6 +340,13 @@ static inline void rcc_enableapb1(void)
regval |= RCC_APB1ENR_DACEN;
#endif
+
+#ifdef CONFIG_STM32_CEC
+ /* CEC clock enable */
+
+ regval |= RCC_APB1ENR_CECEN;
+#endif
+
putreg32(regval, STM32_RCC_APB1ENR);
}
@@ -404,6 +436,28 @@ static inline void rcc_enableapb2(void)
regval |= RCC_APB2ENR_ADC3EN;
#endif
+
+#ifdef CONFIG_STM32_TIM15
+ /* TIM15 Timer clock enable */
+#ifdef CONFIG_STM32_FORCEPOWER
+ regval |= RCC_APB2ENR_TIM15EN;
+#endif
+#endif
+
+#ifdef CONFIG_STM32_TIM16
+ /* TIM16 Timer clock enable */
+#ifdef CONFIG_STM32_FORCEPOWER
+ regval |= RCC_APB2ENR_TIM16EN;
+#endif
+#endif
+
+#ifdef CONFIG_STM32_TIM17
+ /* TIM17 Timer clock enable */
+#ifdef CONFIG_STM32_FORCEPOWER
+ regval |= RCC_APB2ENR_TIM17EN;
+#endif
+#endif
+
putreg32(regval, STM32_RCC_APB2ENR);
}
diff --git a/nuttx/arch/arm/src/stm32/stm32f20xxx_rcc.c b/nuttx/arch/arm/src/stm32/stm32f20xxx_rcc.c
index 335992524..ac72fb60b 100644
--- a/nuttx/arch/arm/src/stm32/stm32f20xxx_rcc.c
+++ b/nuttx/arch/arm/src/stm32/stm32f20xxx_rcc.c
@@ -631,7 +631,11 @@ static void stm32_stdclockconfig(void)
/* Enable FLASH prefetch, instruction cache, data cache, and 5 wait states */
+#ifdef STM32_FLASH_PREFETCH
+ regval = (FLASH_ACR_LATENCY_5 | FLASH_ACR_ICEN | FLASH_ACR_DCEN | FLASH_ACR_PRFTEN);
+#else
regval = (FLASH_ACR_LATENCY_5 | FLASH_ACR_ICEN | FLASH_ACR_DCEN);
+#endif
putreg32(regval, STM32_FLASH_ACR);
/* Select the main PLL as system clock source */
diff --git a/nuttx/arch/arm/src/stm32/stm32f40xxx_rcc.c b/nuttx/arch/arm/src/stm32/stm32f40xxx_rcc.c
index 45980f288..c6c0b2382 100644
--- a/nuttx/arch/arm/src/stm32/stm32f40xxx_rcc.c
+++ b/nuttx/arch/arm/src/stm32/stm32f40xxx_rcc.c
@@ -633,7 +633,11 @@ static void stm32_stdclockconfig(void)
/* Enable FLASH prefetch, instruction cache, data cache, and 5 wait states */
+#ifdef STM32_FLASH_PREFETCH
+ regval = (FLASH_ACR_LATENCY_5 | FLASH_ACR_ICEN | FLASH_ACR_DCEN | FLASH_ACR_PRFTEN);
+#else
regval = (FLASH_ACR_LATENCY_5 | FLASH_ACR_ICEN | FLASH_ACR_DCEN);
+#endif
putreg32(regval, STM32_FLASH_ACR);
/* Select the main PLL as system clock source */
diff --git a/nuttx/binfmt/Kconfig b/nuttx/binfmt/Kconfig
index ae2bf3130..495bd050f 100644
--- a/nuttx/binfmt/Kconfig
+++ b/nuttx/binfmt/Kconfig
@@ -2,3 +2,66 @@
# For a description of the syntax of this configuration file,
# see misc/tools/kconfig-language.txt.
#
+
+config BINFMT_DISABLE
+ bool "Disble BINFMT support"
+ default n
+ ---help---
+ By default, support for loadable binary formats is built. This logic
+ may be suppressed be defining this setting.
+
+if !BINFMT_DISABLE
+
+config BINFMT_EXEPATH
+ bool "Support PATH variable"
+ default n
+ depends on !DISABLE_ENVIRON
+ ---help---
+ Use the contents of the PATH environment variable to locate executable
+ files. Default: n
+
+config PATH_INITIAL
+ string "Initial PATH Value"
+ default ""
+ depends on BINFMT_EXEPATH
+ ---help---
+ The initial value of the PATH variable. This is the colon-separated
+ list of absolute paths. E.g., "/bin:/usr/bin:/sbin"
+
+config NXFLAT
+ bool "Enable the NXFLAT Binary Format"
+ default n
+ select PIC
+ ---help---
+ Enable support for the NXFLAT binary format. Default: n
+
+if NXFLAT
+source binfmt/libnxflat/Kconfig
+endif
+
+config ELF
+ bool "Enable the ELF Binary Format"
+ default n
+ ---help---
+ Enable support for the ELF binary format. Default: n
+
+if ELF
+source binfmt/libelf/Kconfig
+endif
+
+endif
+
+config PIC
+ bool
+ default n
+
+config BINFMT_CONSTRUCTORS
+ bool "C++ Static Constructor Support"
+ default n
+ depends on HAVE_CXX && ELF # FIX ME: Currently only supported for ELF
+ ---help---
+ Build in support for C++ constructors in loaded modules.
+
+config SYMTAB_ORDEREDBYNAME
+ bool "Symbol Tables Ordered by Name"
+ default n
diff --git a/nuttx/binfmt/Makefile b/nuttx/binfmt/Makefile
index b3a9269b3..8ec0d877c 100644
--- a/nuttx/binfmt/Makefile
+++ b/nuttx/binfmt/Makefile
@@ -1,7 +1,7 @@
############################################################################
# nxflat/Makefile
#
-# Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
+# Copyright (C) 2007-2009, 2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
@@ -34,69 +34,69 @@
############################################################################
-include $(TOPDIR)/Make.defs
+DELIM ?= $(strip /)
ifeq ($(WINTOOL),y)
-INCDIROPT = -w
+INCDIROPT = -w
endif
-CFLAGS += ${shell $(TOPDIR)/tools/incdir.sh $(INCDIROPT) "$(CC)" $(TOPDIR)/sched}
+CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" "$(TOPDIR)$(DELIM)sched"}
-ifeq ($(CONFIG_NXFLAT),y)
-include libnxflat/Make.defs
-LIBNXFLAT_CSRCS += nxflat.c
+# Basic BINFMT source files
+
+BINFMT_ASRCS =
+BINFMT_CSRCS = binfmt_globals.c binfmt_register.c binfmt_unregister.c
+BINFMT_CSRCS += binfmt_loadmodule.c binfmt_unloadmodule.c binfmt_execmodule.c
+BINFMT_CSRCS += binfmt_exec.c binfmt_dumpmodule.c
+
+ifeq ($(CONFIG_BINFMT_EXEPATH),y)
+BINFMT_CSRCS += binfmt_exepath.c
endif
-BINFMT_ASRCS =
-BINFMT_CSRCS = binfmt_globals.c binfmt_register.c binfmt_unregister.c \
- binfmt_loadmodule.c binfmt_unloadmodule.c binfmt_execmodule.c \
- binfmt_exec.c binfmt_dumpmodule.c
+# Symbol table source files
-SYMTAB_ASRCS =
-SYMTAB_CSRCS = symtab_findbyname.c symtab_findbyvalue.c \
- symtab_findorderedbyname.c symtab_findorderedbyvalue.c
+BINFMT_CSRCS += symtab_findbyname.c symtab_findbyvalue.c
+BINFMT_CSRCS += symtab_findorderedbyname.c symtab_findorderedbyvalue.c
-SUBDIRS = libnxflat
+# Add configured binary modules
-ASRCS = $(BINFMT_ASRCS) $(SYMTAB_ASRCS) $(LIBNXFLAT_ASRCS)
-AOBJS = $(ASRCS:.S=$(OBJEXT))
+VPATH =
+SUBDIRS =
+DEPPATH = --dep-path .
-CSRCS = $(BINFMT_CSRCS) $(SYMTAB_CSRCS) $(LIBNXFLAT_CSRCS)
-COBJS = $(CSRCS:.c=$(OBJEXT))
+include libnxflat$(DELIM)Make.defs
+include libelf$(DELIM)Make.defs
-SRCS = $(ASRCS) $(CSRCS)
-OBJS = $(AOBJS) $(COBJS)
+BINFMT_AOBJS = $(BINFMT_ASRCS:.S=$(OBJEXT))
+BINFMT_COBJS = $(BINFMT_CSRCS:.c=$(OBJEXT))
-BIN = libbinfmt$(LIBEXT)
+BINFMT_SRCS = $(BINFMT_ASRCS) $(BINFMT_CSRCS)
+BINFMT_OBJS = $(BINFMT_AOBJS) $(BINFMT_COBJS)
-VPATH = libnxflat
+BIN = libbinfmt$(LIBEXT)
-all: $(BIN)
+all: $(BIN)
-$(AOBJS): %$(OBJEXT): %.S
+$(BINFMT_AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
-$(COBJS): %$(OBJEXT): %.c
+$(BINFMT_COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
-$(BIN): $(OBJS)
- @( for obj in $(OBJS) ; do \
- $(call ARCHIVE, $@, $${obj}); \
- done ; )
+$(BIN): $(BINFMT_OBJS)
+ $(call ARCHIVE, $@, $(BINFMT_OBJS))
-.depend: Makefile $(SRCS)
- @$(MKDEP) --dep-path . --dep-path libnxflat \
- $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
- @touch $@
+.depend: Makefile $(BINFMT_SRCS)
+ $(Q) $(MKDEP) $(DEPPATH) "$(CC)" -- $(CFLAGS) -- $(BINFMT_SRCS) >Make.dep
+ $(Q) touch $@
depend: .depend
clean:
- @rm -f $(BIN) *~ .*.swp
+ $(call DELFILE, $(BIN))
$(call CLEAN)
- @( for dir in $(SUBDIRS); do \
- rm -f $${dir}/*~ $${dir}/.*.swp; \
- done ; )
distclean: clean
- @rm -f Make.dep .depend
+ $(call DELFILE, Make.dep)
+ $(call DELFILE, .depend)
-include Make.dep
diff --git a/nuttx/binfmt/binfmt_dumpmodule.c b/nuttx/binfmt/binfmt_dumpmodule.c
index 32a3fef3e..d320bc830 100644
--- a/nuttx/binfmt/binfmt_dumpmodule.c
+++ b/nuttx/binfmt/binfmt_dumpmodule.c
@@ -1,7 +1,7 @@
/****************************************************************************
* binfmt/binfmt_dumpmodule.c
*
- * Copyright (C) 2009 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2009, 2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -43,7 +43,7 @@
#include <debug.h>
#include <errno.h>
-#include <nuttx/binfmt.h>
+#include <nuttx/binfmt/binfmt.h>
#include "binfmt_internal.h"
@@ -70,7 +70,7 @@
***********************************************************************/
/***********************************************************************
- * Name: load_module
+ * Name: dump_module
*
* Description:
* Load a module into memory and prep it for execution.
@@ -90,8 +90,15 @@ int dump_module(FAR const struct binary_s *bin)
bdbg(" filename: %s\n", bin->filename);
bdbg(" argv: %p\n", bin->argv);
bdbg(" entrypt: %p\n", bin->entrypt);
- bdbg(" ispace: %p size=%d\n", bin->ispace, bin->isize);
- bdbg(" dspace: %p\n", bin->dspace);
+ bdbg(" mapped: %p size=%d\n", bin->mapped, bin->mapsize);
+ bdbg(" alloc: %p %p %p\n", bin->alloc[0], bin->alloc[1], bin->alloc[2]);
+#ifdef CONFIG_BINFMT_CONSTRUCTORS
+ bdbg(" ctors: %p nctors=%d\n", bin->ctors, bin->nctors);
+ bdbg(" dtors: %p ndtors=%d\n", bin->dtors, bin->ndtors);
+#endif
+#ifdef CONFIG_ADDRENV
+ bdbg(" addrenv: %p\n", bin->addrenv);
+#endif
bdbg(" stacksize: %d\n", bin->stacksize);
}
return OK;
diff --git a/nuttx/binfmt/binfmt_exec.c b/nuttx/binfmt/binfmt_exec.c
index c070324c3..60e8d8efd 100644
--- a/nuttx/binfmt/binfmt_exec.c
+++ b/nuttx/binfmt/binfmt_exec.c
@@ -44,7 +44,7 @@
#include <debug.h>
#include <errno.h>
-#include <nuttx/binfmt.h>
+#include <nuttx/binfmt/binfmt.h>
#include "binfmt_internal.h"
diff --git a/nuttx/binfmt/binfmt_execmodule.c b/nuttx/binfmt/binfmt_execmodule.c
index 1b511b0cb..400451c40 100644
--- a/nuttx/binfmt/binfmt_execmodule.c
+++ b/nuttx/binfmt/binfmt_execmodule.c
@@ -47,7 +47,7 @@
#include <errno.h>
#include <nuttx/arch.h>
-#include <nuttx/binfmt.h>
+#include <nuttx/binfmt/binfmt.h>
#include "os_internal.h"
#include "binfmt_internal.h"
@@ -71,6 +71,62 @@
****************************************************************************/
/****************************************************************************
+ * Name: exec_ctors
+ *
+ * Description:
+ * Execute C++ static constructors.
+ *
+ * Input Parameters:
+ * loadinfo - Load state information
+ *
+ * Returned Value:
+ * 0 (OK) is returned on success and a negated errno is returned on
+ * failure.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_BINFMT_CONSTRUCTORS
+static inline int exec_ctors(FAR const struct binary_s *binp)
+{
+ binfmt_ctor_t *ctor = binp->ctors;
+#ifdef CONFIG_ADDRENV
+ hw_addrenv_t oldenv;
+ int ret;
+#endif
+ int i;
+
+ /* Instantiate the address enviroment containing the constructors */
+
+#ifdef CONFIG_ADDRENV
+ ret = up_addrenv_select(binp->addrenv, &oldenv);
+ if (ret < 0)
+ {
+ bdbg("up_addrenv_select() failed: %d\n", ret);
+ return ret;
+ }
+#endif
+
+ /* Execute each constructor */
+
+ for (i = 0; i < binp->nctors; i++)
+ {
+ bvdbg("Calling ctor %d at %p\n", i, (FAR void *)ctor);
+
+ (*ctor)();
+ ctor++;
+ }
+
+ /* Restore the address enviroment */
+
+#ifdef CONFIG_ADDRENV
+ return up_addrenv_restore(oldenv);
+#else
+ return OK;
+#endif
+}
+#endif
+
+/****************************************************************************
* Public Functions
****************************************************************************/
@@ -87,7 +143,7 @@
*
****************************************************************************/
-int exec_module(FAR const struct binary_s *bin, int priority)
+int exec_module(FAR const struct binary_s *binp, int priority)
{
FAR _TCB *tcb;
#ifndef CONFIG_CUSTOM_STACK
@@ -100,14 +156,14 @@ int exec_module(FAR const struct binary_s *bin, int priority)
/* Sanity checking */
#ifdef CONFIG_DEBUG
- if (!bin || !bin->ispace || !bin->entrypt || bin->stacksize <= 0)
+ if (!binp || !binp->entrypt || binp->stacksize <= 0)
{
err = EINVAL;
goto errout;
}
#endif
- bdbg("Executing %s\n", bin->filename);
+ bdbg("Executing %s\n", binp->filename);
/* Allocate a TCB for the new task. */
@@ -121,7 +177,7 @@ int exec_module(FAR const struct binary_s *bin, int priority)
/* Allocate the stack for the new task */
#ifndef CONFIG_CUSTOM_STACK
- stack = (FAR uint32_t*)malloc(bin->stacksize);
+ stack = (FAR uint32_t*)malloc(binp->stacksize);
if (!tcb)
{
err = ENOMEM;
@@ -130,11 +186,13 @@ int exec_module(FAR const struct binary_s *bin, int priority)
/* Initialize the task */
- ret = task_init(tcb, bin->filename, priority, stack, bin->stacksize, bin->entrypt, bin->argv);
+ ret = task_init(tcb, binp->filename, priority, stack,
+ binp->stacksize, binp->entrypt, binp->argv);
#else
/* Initialize the task */
- ret = task_init(tcb, bin->filename, priority, stack, bin->entrypt, bin->argv);
+ ret = task_init(tcb, binp->filename, priority, stack,
+ binp->entrypt, binp->argv);
#endif
if (ret < 0)
{
@@ -143,20 +201,46 @@ int exec_module(FAR const struct binary_s *bin, int priority)
goto errout_with_stack;
}
- /* Add the DSpace address as the PIC base address */
+ /* Add the D-Space address as the PIC base address. By convention, this
+ * must be the first allocated address space.
+ */
#ifdef CONFIG_PIC
- tcb->dspace = bin->dspace;
+ tcb->dspace = binp->alloc[0];
/* Re-initialize the task's initial state to account for the new PIC base */
up_initial_state(tcb);
#endif
+ /* Assign the address environment to the task */
+
+#ifdef CONFIG_ADDRENV
+ ret = up_addrenv_assign(binp->addrenv, tcb);
+ if (ret < 0)
+ {
+ err = -ret;
+ bdbg("up_addrenv_assign() failed: %d\n", ret);
+ goto errout_with_stack;
+ }
+#endif
+
/* Get the assigned pid before we start the task */
pid = tcb->pid;
+ /* Execute all of the C++ static constructors */
+
+#ifdef CONFIG_BINFMT_CONSTRUCTORS
+ ret = exec_ctors(binp);
+ if (ret < 0)
+ {
+ err = -ret;
+ bdbg("exec_ctors() failed: %d\n", ret);
+ goto errout_with_stack;
+ }
+#endif
+
/* Then activate the task at the provided priority */
ret = task_activate(tcb);
@@ -166,6 +250,7 @@ int exec_module(FAR const struct binary_s *bin, int priority)
bdbg("task_activate() failed: %d\n", err);
goto errout_with_stack;
}
+
return (int)pid;
errout_with_stack:
diff --git a/nuttx/binfmt/binfmt_exepath.c b/nuttx/binfmt/binfmt_exepath.c
new file mode 100644
index 000000000..4fd7ad918
--- /dev/null
+++ b/nuttx/binfmt/binfmt_exepath.c
@@ -0,0 +1,286 @@
+/****************************************************************************
+ * binfmt/binfmt_exepath.c
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+#include <nuttx/kmalloc.h>
+#include <nuttx/binfmt/binfmt.h>
+
+#if !defined(CONFIG_BINFMT_DISABLE) && defined(CONFIG_BINFMT_EXEPATH)
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct exepath_s
+{
+ FAR char *next; /* Pointer to the next (unterminated) value in the PATH variable */
+ char path[1];
+};
+#define SIZEOF_EXEPATH_S(n) (sizeof(struct exepath_s) + (n) - 1)
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: exepath_init
+ *
+ * Description:
+ * Initialize for the traversal of each value in the PATH variable. The
+ * usage is sequence is as follows:
+ *
+ * 1) Call exepath_init() to initialize for the traversal. exepath_init()
+ * will return an opaque handle that can then be provided to
+ * exepath_next() and exepath_release().
+ * 2) Call exepath_next() repeatedly to examine every file that lies
+ * in the directories of the PATH variable
+ * 3) Call exepath_release() to free resources set aside by exepath_init().
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * On success, exepath_init() return a non-NULL, opaque handle that may
+ * subsequently be used in calls to exepath_next() and exepath_release().
+ * On error, a NULL handle value will be returned. The most likely cause
+ * of an error would be that the there is no value associated with the
+ * PATH variable.
+ *
+ ****************************************************************************/
+
+EXEPATH_HANDLE exepath_init(void)
+{
+ FAR struct exepath_s *exepath;
+ FAR char *path;
+
+ /* Get the value of the PATH variable */
+
+ path = getenv("PATH");
+ if (!path)
+ {
+ /* getenv() will return a NULL value if the PATH variable does not
+ * exist in the environment.
+ */
+
+ return (EXEPATH_HANDLE)NULL;
+ }
+
+ /* Allocate a container for the PATH variable contents */
+
+ exepath = (FAR struct exepath_s *)kmalloc(SIZEOF_EXEPATH_S(strlen(path) + 1));
+ if (!exepath)
+ {
+ /* Ooops.. we are out of memory */
+
+ return (EXEPATH_HANDLE)NULL;
+ }
+
+ /* Populate the container */
+
+ strcpy(exepath->path, path);
+ exepath->next = exepath->path;
+
+ /* And return the containing cast to an opaque handle */
+
+ return (EXEPATH_HANDLE)exepath;
+}
+
+ /****************************************************************************
+ * Name: exepath_next
+ *
+ * Description:
+ * Traverse all possible values in the PATH variable in attempt to find
+ * the full path to an executable file when only a relative path is
+ * provided.
+ *
+ * Input Parameters:
+ * handle - The handle value returned by exepath_init
+ * relpath - The relative path to the file to be found.
+ *
+ * Returned Value:
+ * On success, a non-NULL pointer to a null-terminated string is provided.
+ * This is the full path to a file that exists in the file system. This
+ * function will verify that the file exists (but will not verify that it
+ * is marked executable).
+ *
+ * NOTE: The string pointer return in the success case points to allocated
+ * memory. This memory must be freed by the called by calling kfree().
+ *
+ * NULL is returned if no path is found to any file with the provided
+ * 'relpath' from any absolute path in the PATH variable. In this case,
+ * there is no point in calling exepath_next() further; exepath_release()
+ * must be called to release resources set aside by expath_init().
+ *
+ ****************************************************************************/
+
+FAR char *exepath_next(EXEPATH_HANDLE handle, FAR const char *relpath)
+{
+ FAR struct exepath_s *exepath = (FAR struct exepath_s *)handle;
+ struct stat buf;
+ FAR char *endptr;
+ FAR char *path;
+ FAR char *fullpath;
+ int pathlen;
+ int ret;
+
+ /* Verify that a value handle and relative path were provided */
+
+ DEBUGASSERT(exepath && relpath);
+ DEBUGASSERT(relpath[0] != '\0' && relpath[0] != '/');
+
+ /* Loop until (1) we find a file with this relative path from one of the
+ * absolute paths in the PATH variable, or (2) all of the absolute paths
+ * in the PATH variable have been considered.
+ */
+
+ for (;;)
+ {
+ /* Make sure that exepath->next points to the beginning of a string */
+
+ path = exepath->next;
+ if (*path == '\0')
+ {
+ /* If it points to a NULL it means that either (1) the PATH varialbe
+ * is empty, or (2) we have already examined all of the paths in the
+ * path variable.
+ */
+
+ return (FAR char *)NULL;
+ }
+
+ /* Okay... 'path' points to the beginning of the string. The string may
+ * be termined either with (1) ':' which separates the path from the
+ * next path in the list, or (2) NUL which marks the end of the list.
+ */
+
+ endptr = strchr(path, ':');
+ if (!endptr)
+ {
+ /* If strchr returns NUL it means that ':' does not appear in the
+ * string. Therefore, this must be the final path in the PATH
+ * variable content.
+ */
+
+ endptr = &path[strlen(path)];
+ exepath->next = endptr;
+ DEBUGASSERT(*endptr == '\0');
+ }
+ else
+ {
+ DEBUGASSERT(*endptr == ':');
+ exepath->next = endptr + 1;
+ *endptr = '\0';
+ }
+
+ pathlen = strlen(path) + strlen(relpath) + 2;
+ fullpath = (FAR char *)kmalloc(pathlen);
+ if (!fullpath)
+ {
+ /* Failed to allocate memory */
+
+ return (FAR char *)NULL;
+ }
+
+ /* Construct the full path */
+
+ sprintf(fullpath, "%s/%s", path, relpath);
+
+ /* Verify that a regular file exists at this path */
+
+ ret = stat(fullpath, &buf);;
+ if (ret == OK && S_ISREG(buf.st_mode))
+ {
+ return fullpath;
+ }
+
+ /* Failed to stat the file. Just free the allocated memory and
+ * continue to try the next path.
+ */
+
+ kfree(fullpath);
+ }
+
+ /* We will not get here */
+}
+
+/****************************************************************************
+ * Name: exepath_release
+ *
+ * Description:
+ * Release all resources set aside by exepath_init() when the handle value
+ * was created. The handle value is invalid on return from this function.
+ * Attempts to all exepath_next() or exepath_release() with such a 'stale'
+ * handle will result in undefined (i.e., not good) behavior.
+ *
+ * Input Parameters:
+ * handle - The handle value returned by exepath_init
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+void exepath_release(EXEPATH_HANDLE handle)
+{
+ kfree(handle);
+}
+
+#endif /* !CONFIG_BINFMT_DISABLE && CONFIG_BINFMT_EXEPATH */
+
diff --git a/nuttx/binfmt/binfmt_globals.c b/nuttx/binfmt/binfmt_globals.c
index 069d3a2aa..d3246bd50 100644
--- a/nuttx/binfmt/binfmt_globals.c
+++ b/nuttx/binfmt/binfmt_globals.c
@@ -39,7 +39,7 @@
#include <nuttx/config.h>
-#include <nuttx/binfmt.h>
+#include <nuttx/binfmt/binfmt.h>
#ifndef CONFIG_BINFMT_DISABLE
diff --git a/nuttx/binfmt/binfmt_internal.h b/nuttx/binfmt/binfmt_internal.h
index da67f5350..4fab9724d 100644
--- a/nuttx/binfmt/binfmt_internal.h
+++ b/nuttx/binfmt/binfmt_internal.h
@@ -42,7 +42,7 @@
#include <nuttx/config.h>
-#include <nuttx/binfmt.h>
+#include <nuttx/binfmt/binfmt.h>
/****************************************************************************
* Pre-processor Definitions
diff --git a/nuttx/binfmt/binfmt_loadmodule.c b/nuttx/binfmt/binfmt_loadmodule.c
index 01ab8cc88..112a6b35b 100644
--- a/nuttx/binfmt/binfmt_loadmodule.c
+++ b/nuttx/binfmt/binfmt_loadmodule.c
@@ -43,7 +43,8 @@
#include <debug.h>
#include <errno.h>
-#include <nuttx/binfmt.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/binfmt/binfmt.h>
#include "binfmt_internal.h"
@@ -66,6 +67,57 @@
****************************************************************************/
/****************************************************************************
+ * Name: load_absmodule
+ *
+ * Description:
+ * Load a module into memory, bind it to an exported symbol take, and
+ * prep the module for execution. bin->filename is known to be an absolute
+ * path to the file to be loaded.
+ *
+ * Returned Value:
+ * Zero (OK) is returned on success; a negated errno value is returned on
+ * failure.
+ *
+ ****************************************************************************/
+
+static int load_absmodule(FAR struct binary_s *bin)
+{
+ FAR struct binfmt_s *binfmt;
+ int ret = -ENOENT;
+
+ bdbg("Loading %s\n", bin->filename);
+
+ /* Disabling pre-emption should be sufficient protection while accessing
+ * the list of registered binary format handlers.
+ */
+
+ sched_lock();
+
+ /* Traverse the list of registered binary format handlers. Stop
+ * when either (1) a handler recognized and loads the format, or
+ * (2) no handler recognizes the format.
+ */
+
+ for (binfmt = g_binfmts; binfmt; binfmt = binfmt->next)
+ {
+ /* Use this handler to try to load the format */
+
+ ret = binfmt->load(bin);
+ if (ret == OK)
+ {
+ /* Successfully loaded -- break out with ret == 0 */
+
+ bvdbg("Successfully loaded module %s\n", bin->filename);
+ dump_module(bin);
+ break;
+ }
+ }
+
+ sched_unlock();
+ return ret;
+}
+
+/****************************************************************************
* Public Functions
****************************************************************************/
@@ -85,42 +137,72 @@
int load_module(FAR struct binary_s *bin)
{
- FAR struct binfmt_s *binfmt;
- int ret = -ENOENT;
+ int ret = -EINVAL;
+
+ /* Verify that we were provided something to work with */
#ifdef CONFIG_DEBUG
if (bin && bin->filename)
#endif
{
- bdbg("Loading %s\n", bin->filename);
-
- /* Disabling pre-emption should be sufficient protection while
- * accessing the list of registered binary format handlers.
+ /* Were we given a relative path? Or an absolute path to the file to
+ * be loaded? Absolute paths start with '/'.
*/
- sched_lock();
+#ifdef CONFIG_BINFMT_EXEPATH
+ if (bin->filename[0] != '/')
+ {
+ FAR const char *relpath;
+ FAR char *fullpath;
+ EXEPATH_HANDLE handle;
- /* Traverse the list of registered binary format handlers. Stop
- * when either (1) a handler recognized and loads the format, or
- * (2) no handler recognizes the format.
- */
+ /* Set aside the relative path */
- for (binfmt = g_binfmts; binfmt; binfmt = binfmt->next)
- {
- /* Use this handler to try to load the format */
+ relpath = bin->filename;
+ ret = -ENOENT;
+
+ /* Initialize to traverse the PATH variable */
- ret = binfmt->load(bin);
- if (ret == OK)
+ handle = exepath_init();
+ if (handle)
{
- /* Successfully loaded -- break out with ret == 0 */
+ /* Get the next absolute file path */
- bvdbg("Successfully loaded module %s\n", bin->filename);
- dump_module(bin);
- break;
+ while ((fullpath = exepath_next(handle, relpath)) != NULL)
+ {
+ /* Try to load the file at this path */
+
+ bin->filename = fullpath;
+ ret = load_absmodule(bin);
+
+ /* Free the allocated fullpath */
+
+ kfree(fullpath);
+
+ /* Break out of the loop with ret == OK on success */
+
+ if (ret == OK)
+ {
+ break;
+ }
+ }
}
+
+ /* Restore the relative path. This is not needed for anything
+ * but debug output after the file has been loaded.
+ */
+
+ bin->filename = relpath;
}
+ else
+#endif
+ {
+ /* We already have the one and only absolute path to the file to
+ * be loaded.
+ */
- sched_unlock();
+ ret = load_absmodule(bin);
+ }
}
/* This is an end-user function. Return failures via errno */
@@ -131,6 +213,7 @@ int load_module(FAR struct binary_s *bin)
errno = -ret;
return ERROR;
}
+
return OK;
}
diff --git a/nuttx/binfmt/binfmt_register.c b/nuttx/binfmt/binfmt_register.c
index 7f6eef671..925f29353 100644
--- a/nuttx/binfmt/binfmt_register.c
+++ b/nuttx/binfmt/binfmt_register.c
@@ -44,7 +44,7 @@
#include <debug.h>
#include <errno.h>
-#include <nuttx/binfmt.h>
+#include <nuttx/binfmt/binfmt.h>
#include "binfmt_internal.h"
diff --git a/nuttx/binfmt/binfmt_unloadmodule.c b/nuttx/binfmt/binfmt_unloadmodule.c
index 04859a291..365f26a34 100644
--- a/nuttx/binfmt/binfmt_unloadmodule.c
+++ b/nuttx/binfmt/binfmt_unloadmodule.c
@@ -1,7 +1,7 @@
/****************************************************************************
* binfmt/binfmt_loadmodule.c
*
- * Copyright (C) 2009 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2009, 2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -45,7 +45,7 @@
#include <debug.h>
#include <errno.h>
-#include <nuttx/binfmt.h>
+#include <nuttx/binfmt/binfmt.h>
#include "binfmt_internal.h"
@@ -68,6 +68,62 @@
****************************************************************************/
/****************************************************************************
+ * Name: exec_dtors
+ *
+ * Description:
+ * Execute C++ static constructors.
+ *
+ * Input Parameters:
+ * loadinfo - Load state information
+ *
+ * Returned Value:
+ * 0 (OK) is returned on success and a negated errno is returned on
+ * failure.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_BINFMT_CONSTRUCTORS
+static inline int exec_dtors(FAR const struct binary_s *binp)
+{
+ binfmt_dtor_t *dtor = binp->dtors;
+#ifdef CONFIG_ADDRENV
+ hw_addrenv_t oldenv;
+ int ret;
+#endif
+ int i;
+
+ /* Instantiate the address enviroment containing the destructors */
+
+#ifdef CONFIG_ADDRENV
+ ret = up_addrenv_select(binp->addrenv, &oldenv);
+ if (ret < 0)
+ {
+ bdbg("up_addrenv_select() failed: %d\n", ret);
+ return ret;
+ }
+#endif
+
+ /* Execute each destructor */
+
+ for (i = 0; i < binp->ndtors; i++)
+ {
+ bvdbg("Calling dtor %d at %p\n", i, (FAR void *)dtor);
+
+ (*dtor)();
+ dtor++;
+ }
+
+ /* Restore the address enviroment */
+
+#ifdef CONFIG_ADDRENV
+ return up_addrenv_restore(oldenv);
+#else
+ return OK;
+#endif
+}
+#endif
+
+/****************************************************************************
* Public Functions
****************************************************************************/
@@ -76,7 +132,12 @@
*
* Description:
* Unload a (non-executing) module from memory. If the module has
- * been started (via exec_module), calling this will be fatal.
+ * been started (via exec_module) and has not exited, calling this will
+ * be fatal.
+ *
+ * However, this function must be called after the module exist. How
+ * this is done is up to your logic. Perhaps you register it to be
+ * called by on_exit()?
*
* Returned Value:
* This is a NuttX internal function so it follows the convention that
@@ -85,22 +146,52 @@
*
****************************************************************************/
-int unload_module(FAR const struct binary_s *bin)
+int unload_module(FAR const struct binary_s *binp)
{
- if (bin)
+#ifdef CONFIG_BINFMT_CONSTRUCTORS
+ int ret;
+#endif
+ int i;
+
+ if (binp)
{
- if (bin->ispace)
+ /* Execute C++ desctructors */
+
+#ifdef CONFIG_BINFMT_CONSTRUCTORS
+ ret = exec_dtors(binp);
+ if (ret < 0)
{
- bvdbg("Unmapping ISpace: %p\n", bin->ispace);
- munmap(bin->ispace, bin->isize);
+ bdbg("exec_ctors() failed: %d\n", ret);
+ set_errno(-ret);
+ return ERROR;
}
+#endif
- if (bin->dspace)
+ /* Unmap mapped address spaces */
+
+ if (binp->mapped)
+ {
+ bvdbg("Unmapping address space: %p\n", binp->mapped);
+
+ munmap(binp->mapped, binp->mapsize);
+ }
+
+ /* Free allocated address spaces */
+
+ for (i = 0; i < BINFMT_NALLOC; i++)
{
- bvdbg("Freeing DSpace: %p\n", bin->dspace);
- free(bin->dspace);
+ if (binp->alloc[i])
+ {
+ bvdbg("Freeing alloc[%d]: %p\n", i, binp->alloc[i]);
+ free((FAR void *)binp->alloc[i]);
+ }
}
+
+ /* Notice that the address environment is not destroyed. This should
+ * happen automatically when the task exits.
+ */
}
+
return OK;
}
diff --git a/nuttx/binfmt/binfmt_unregister.c b/nuttx/binfmt/binfmt_unregister.c
index b97b9b67d..f895e354d 100644
--- a/nuttx/binfmt/binfmt_unregister.c
+++ b/nuttx/binfmt/binfmt_unregister.c
@@ -44,7 +44,7 @@
#include <debug.h>
#include <errno.h>
-#include <nuttx/binfmt.h>
+#include <nuttx/binfmt/binfmt.h>
#include "binfmt_internal.h"
diff --git a/nuttx/binfmt/elf.c b/nuttx/binfmt/elf.c
new file mode 100644
index 000000000..bcebf13ca
--- /dev/null
+++ b/nuttx/binfmt/elf.c
@@ -0,0 +1,323 @@
+/****************************************************************************
+ * binfmt/elf.c
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <string.h>
+#include <elf32.h>
+#include <debug.h>
+#include <errno.h>
+
+#include <arpa/inet.h>
+#include <nuttx/binfmt/binfmt.h>
+#include <nuttx/binfmt/elf.h>
+
+#ifdef CONFIG_ELF
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* CONFIG_DEBUG, CONFIG_DEBUG_VERBOSE, and CONFIG_DEBUG_BINFMT have to be
+ * defined or CONFIG_ELF_DUMPBUFFER does nothing.
+ */
+
+#if !defined(CONFIG_DEBUG_VERBOSE) || !defined (CONFIG_DEBUG_BINFMT)
+# undef CONFIG_ELF_DUMPBUFFER
+#endif
+
+#ifndef CONFIG_ELF_STACKSIZE
+# define CONFIG_ELF_STACKSIZE 2048
+#endif
+
+#ifdef CONFIG_ELF_DUMPBUFFER
+# define elf_dumpbuffer(m,b,n) bvdbgdumpbuffer(m,b,n)
+#else
+# define elf_dumpbuffer(m,b,n)
+#endif
+
+#ifndef MIN
+# define MIN(a,b) (a < b ? a : b)
+#endif
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int elf_loadbinary(FAR struct binary_s *binp);
+#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_BINFMT)
+static void elf_dumploadinfo(FAR struct elf_loadinfo_s *loadinfo);
+#endif
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static struct binfmt_s g_elfbinfmt =
+{
+ NULL, /* next */
+ elf_loadbinary, /* load */
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: elf_dumploadinfo
+ ****************************************************************************/
+
+#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_BINFMT)
+static void elf_dumploadinfo(FAR struct elf_loadinfo_s *loadinfo)
+{
+ int i;
+
+ bdbg("LOAD_INFO:\n");
+ bdbg(" elfalloc: %08lx\n", (long)loadinfo->elfalloc);
+ bdbg(" elfsize: %ld\n", (long)loadinfo->elfsize);
+ bdbg(" filelen: %ld\n", (long)loadinfo->filelen);
+#ifdef CONFIG_BINFMT_CONSTRUCTORS
+ bdbg(" ctoralloc: %08lx\n", (long)loadinfo->ctoralloc);
+ bdbg(" ctors: %08lx\n", (long)loadinfo->ctors);
+ bdbg(" nctors: %d\n", loadinfo->nctors);
+ bdbg(" dtoralloc: %08lx\n", (long)loadinfo->dtoralloc);
+ bdbg(" dtors: %08lx\n", (long)loadinfo->dtors);
+ bdbg(" ndtors: %d\n", loadinfo->ndtors);
+#endif
+ bdbg(" filfd: %d\n", loadinfo->filfd);
+ bdbg(" symtabidx: %d\n", loadinfo->symtabidx);
+ bdbg(" strtabidx: %d\n", loadinfo->strtabidx);
+
+ bdbg("ELF Header:\n");
+ bdbg(" e_ident: %02x %02x %02x %02x\n",
+ loadinfo->ehdr.e_ident[0], loadinfo->ehdr.e_ident[1],
+ loadinfo->ehdr.e_ident[2], loadinfo->ehdr.e_ident[3]);
+ bdbg(" e_type: %04x\n", loadinfo->ehdr.e_type);
+ bdbg(" e_machine: %04x\n", loadinfo->ehdr.e_machine);
+ bdbg(" e_version: %08x\n", loadinfo->ehdr.e_version);
+ bdbg(" e_entry: %08lx\n", (long)loadinfo->ehdr.e_entry);
+ bdbg(" e_phoff: %d\n", loadinfo->ehdr.e_phoff);
+ bdbg(" e_shoff: %d\n", loadinfo->ehdr.e_shoff);
+ bdbg(" e_flags: %08x\n" , loadinfo->ehdr.e_flags);
+ bdbg(" e_ehsize: %d\n", loadinfo->ehdr.e_ehsize);
+ bdbg(" e_phentsize: %d\n", loadinfo->ehdr.e_phentsize);
+ bdbg(" e_phnum: %d\n", loadinfo->ehdr.e_phnum);
+ bdbg(" e_shentsize: %d\n", loadinfo->ehdr.e_shentsize);
+ bdbg(" e_shnum: %d\n", loadinfo->ehdr.e_shnum);
+ bdbg(" e_shstrndx: %d\n", loadinfo->ehdr.e_shstrndx);
+
+ if (loadinfo->shdr && loadinfo->ehdr.e_shnum > 0)
+ {
+ for (i = 0; i < loadinfo->ehdr.e_shnum; i++)
+ {
+ FAR Elf32_Shdr *shdr = &loadinfo->shdr[i];
+ bdbg("Sections %d:\n", i);
+ bdbg(" sh_name: %08x\n", shdr->sh_name);
+ bdbg(" sh_type: %08x\n", shdr->sh_type);
+ bdbg(" sh_flags: %08x\n", shdr->sh_flags);
+ bdbg(" sh_addr: %08x\n", shdr->sh_addr);
+ bdbg(" sh_offset: %d\n", shdr->sh_offset);
+ bdbg(" sh_size: %d\n", shdr->sh_size);
+ bdbg(" sh_link: %d\n", shdr->sh_link);
+ bdbg(" sh_info: %d\n", shdr->sh_info);
+ bdbg(" sh_addralign: %d\n", shdr->sh_addralign);
+ bdbg(" sh_entsize: %d\n", shdr->sh_entsize);
+ }
+ }
+}
+#else
+# define elf_dumploadinfo(i)
+#endif
+
+/****************************************************************************
+ * Name: elf_loadbinary
+ *
+ * Description:
+ * Verify that the file is an ELF binary and, if so, load the ELF
+ * binary into memory
+ *
+ ****************************************************************************/
+
+static int elf_loadbinary(struct binary_s *binp)
+{
+ struct elf_loadinfo_s loadinfo; /* Contains globals for libelf */
+ int ret;
+
+ bvdbg("Loading file: %s\n", binp->filename);
+
+ /* Initialize the xflat library to load the program binary. */
+
+ ret = elf_init(binp->filename, &loadinfo);
+ elf_dumploadinfo(&loadinfo);
+ if (ret != 0)
+ {
+ bdbg("Failed to initialize for load of ELF program: %d\n", ret);
+ goto errout;
+ }
+
+ /* Load the program binary */
+
+ ret = elf_load(&loadinfo);
+ elf_dumploadinfo(&loadinfo);
+ if (ret != 0)
+ {
+ bdbg("Failed to load ELF program binary: %d\n", ret);
+ goto errout_with_init;
+ }
+
+ /* Bind the program to the exported symbol table */
+
+ ret = elf_bind(&loadinfo, binp->exports, binp->nexports);
+ if (ret != 0)
+ {
+ bdbg("Failed to bind symbols program binary: %d\n", ret);
+ goto errout_with_load;
+ }
+
+ /* Return the load information */
+
+ binp->entrypt = (main_t)(loadinfo.elfalloc + loadinfo.ehdr.e_entry);
+ binp->stacksize = CONFIG_ELF_STACKSIZE;
+
+ /* Add the ELF allocation to the alloc[] only if there is no address
+ * enironment. If there is an address environment, it will automatically
+ * be freed when the function exits
+ *
+ * REVISIT: If the module is loaded then unloaded, wouldn't this cause
+ * a memory leak?
+ */
+
+#ifdef CONFIG_ADDRENV
+# warning "REVISIT"
+#else
+ binp->alloc[0] = (FAR void *)loadinfo.elfalloc;
+#endif
+
+#ifdef CONFIG_BINFMT_CONSTRUCTORS
+ /* Save information about constructors. NOTE: desctructors are not
+ * yet supported.
+ */
+
+ binp->alloc[1] = loadinfo.ctoralloc;
+ binp->ctors = loadinfo.ctors;
+ binp->nctors = loadinfo.nctors;
+
+ binp->alloc[2] = loadinfo.dtoralloc;
+ binp->dtors = loadinfo.dtors;
+ binp->ndtors = loadinfo.ndtors;
+#endif
+
+#ifdef CONFIG_ADDRENV
+ /* Save the address environment. This will be needed when the module is
+ * executed for the up_addrenv_assign() call.
+ */
+
+ binp->addrenv = loadinfo.addrenv;
+#endif
+
+ elf_dumpbuffer("Entry code", (FAR const uint8_t*)binp->entrypt,
+ MIN(loadinfo.allocsize - loadinfo.ehdr.e_entry, 512));
+
+ elf_uninit(&loadinfo);
+ return OK;
+
+errout_with_load:
+ elf_unload(&loadinfo);
+errout_with_init:
+ elf_uninit(&loadinfo);
+errout:
+ return ret;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: elf_initialize
+ *
+ * Description:
+ * ELF support is built unconditionally. However, it order to
+ * use this binary format, this function must be called during system
+ * format in order to register the ELF binary format.
+ *
+ * Returned Value:
+ * This is a NuttX internal function so it follows the convention that
+ * 0 (OK) is returned on success and a negated errno is returned on
+ * failure.
+ *
+ ****************************************************************************/
+
+int elf_initialize(void)
+{
+ int ret;
+
+ /* Register ourselves as a binfmt loader */
+
+ bvdbg("Registering ELF\n");
+
+ ret = register_binfmt(&g_elfbinfmt);
+ if (ret != 0)
+ {
+ bdbg("Failed to register binfmt: %d\n", ret);
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: elf_uninitialize
+ *
+ * Description:
+ * Unregister the ELF binary loader
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+void elf_uninitialize(void)
+{
+ unregister_binfmt(&g_elfbinfmt);
+}
+
+#endif /* CONFIG_ELF */
+
diff --git a/nuttx/binfmt/libelf/Make.defs b/nuttx/binfmt/libelf/Make.defs
new file mode 100644
index 000000000..93d95a23c
--- /dev/null
+++ b/nuttx/binfmt/libelf/Make.defs
@@ -0,0 +1,58 @@
+############################################################################
+# binfmt/libelf/Make.defs
+#
+# Copyright (C) 2012 Gregory Nutt. All rights reserved.
+# Author: Gregory Nutt <gnutt@nuttx.org>
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in
+# the documentation and/or other materials provided with the
+# distribution.
+# 3. Neither the name NuttX nor the names of its contributors may be
+# used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+############################################################################
+
+ifeq ($(CONFIG_ELF),y)
+
+# ELF application interfaces
+
+BINFMT_CSRCS += elf.c
+
+# ELF library
+
+BINFMT_CSRCS += libelf_bind.c libelf_init.c libelf_addrenv.c libelf_iobuffer.c
+BINFMT_CSRCS += libelf_load.c libelf_read.c libelf_sections.c libelf_symbols.c
+BINFMT_CSRCS += libelf_uninit.c libelf_unload.c libelf_verify.c
+
+ifeq ($(CONFIG_BINFMT_CONSTRUCTORS),y)
+BINFMT_CSRCS += libelf_ctors.c libelf_dtors.c
+endif
+
+# Hook the libelf subdirectory into the build
+
+VPATH += libelf
+SUBDIRS += libelf
+DEPPATH += --dep-path libelf
+
+endif
diff --git a/nuttx/binfmt/libelf/libelf.h b/nuttx/binfmt/libelf/libelf.h
new file mode 100644
index 000000000..04c9144f6
--- /dev/null
+++ b/nuttx/binfmt/libelf/libelf.h
@@ -0,0 +1,341 @@
+/****************************************************************************
+ * binfmt/libelf/libelf.h
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+#ifndef __BINFMT_LIBELF_LIBELF_H
+#define __BINFMT_LIBELF_LIBELF_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <elf32.h>
+
+#include <nuttx/arch.h>
+#include <nuttx/binfmt/elf.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: elf_verifyheader
+ *
+ * Description:
+ * Given the header from a possible ELF executable, verify that it is
+ * an ELF executable.
+ *
+ * Returned Value:
+ * 0 (OK) is returned on success and a negated errno is returned on
+ * failure.
+ *
+ ****************************************************************************/
+
+int elf_verifyheader(FAR const Elf32_Ehdr *header);
+
+/****************************************************************************
+ * Name: elf_read
+ *
+ * Description:
+ * Read 'readsize' bytes from the object file at 'offset'. The data is
+ * read into 'buffer.' If 'buffer' is part of the ELF address environment,
+ * then the caller is responsibile for assuring that that address
+ * environment is in place before calling this function (i.e., that
+ * elf_addrenv_select() has been called if CONFIG_ADDRENV=y).
+ *
+ * Returned Value:
+ * 0 (OK) is returned on success and a negated errno is returned on
+ * failure.
+ *
+ ****************************************************************************/
+
+int elf_read(FAR struct elf_loadinfo_s *loadinfo, FAR uint8_t *buffer,
+ size_t readsize, off_t offset);
+
+/****************************************************************************
+ * Name: elf_loadshdrs
+ *
+ * Description:
+ * Loads section headers into memory.
+ *
+ * Returned Value:
+ * 0 (OK) is returned on success and a negated errno is returned on
+ * failure.
+ *
+ ****************************************************************************/
+
+int elf_loadshdrs(FAR struct elf_loadinfo_s *loadinfo);
+
+/****************************************************************************
+ * Name: elf_findsection
+ *
+ * Description:
+ * A section by its name.
+ *
+ * Input Parameters:
+ * loadinfo - Load state information
+ * sectname - Name of the section to find
+ *
+ * Returned Value:
+ * On success, the index to the section is returned; A negated errno value
+ * is returned on failure.
+ *
+ ****************************************************************************/
+
+int elf_findsection(FAR struct elf_loadinfo_s *loadinfo,
+ FAR const char *sectname);
+
+/****************************************************************************
+ * Name: elf_findsymtab
+ *
+ * Description:
+ * Find the symbol table section.
+ *
+ * Returned Value:
+ * 0 (OK) is returned on success and a negated errno is returned on
+ * failure.
+ *
+ ****************************************************************************/
+
+int elf_findsymtab(FAR struct elf_loadinfo_s *loadinfo);
+
+/****************************************************************************
+ * Name: elf_readsym
+ *
+ * Description:
+ * Read the ELFT symbol structure at the specfied index into memory.
+ *
+ * Input Parameters:
+ * loadinfo - Load state information
+ * index - Symbol table index
+ * sym - Location to return the table entry
+ *
+ * Returned Value:
+ * 0 (OK) is returned on success and a negated errno is returned on
+ * failure.
+ *
+ ****************************************************************************/
+
+int elf_readsym(FAR struct elf_loadinfo_s *loadinfo, int index,
+ FAR Elf32_Sym *sym);
+
+/****************************************************************************
+ * Name: elf_symvalue
+ *
+ * Description:
+ * Get the value of a symbol. The updated value of the symbol is returned
+ * in the st_value field of the symbol table entry.
+ *
+ * Input Parameters:
+ * loadinfo - Load state information
+ * sym - Symbol table entry (value might be undefined)
+ * exports - The symbol table to use for resolving undefined symbols.
+ * nexports - Number of symbols in the symbol table.
+ *
+ * Returned Value:
+ * 0 (OK) is returned on success and a negated errno is returned on
+ * failure.
+ *
+ ****************************************************************************/
+
+int elf_symvalue(FAR struct elf_loadinfo_s *loadinfo, FAR Elf32_Sym *sym,
+ FAR const struct symtab_s *exports, int nexports);
+
+/****************************************************************************
+ * Name: elf_freebuffers
+ *
+ * Description:
+ * Release all working buffers.
+ *
+ * Returned Value:
+ * 0 (OK) is returned on success and a negated errno is returned on
+ * failure.
+ *
+ ****************************************************************************/
+
+int elf_freebuffers(FAR struct elf_loadinfo_s *loadinfo);
+
+/****************************************************************************
+ * Name: elf_allocbuffer
+ *
+ * Description:
+ * Perform the initial allocation of the I/O buffer, if it has not already
+ * been allocated.
+ *
+ * Returned Value:
+ * 0 (OK) is returned on success and a negated errno is returned on
+ * failure.
+ *
+ ****************************************************************************/
+
+int elf_allocbuffer(FAR struct elf_loadinfo_s *loadinfo);
+
+/****************************************************************************
+ * Name: elf_reallocbuffer
+ *
+ * Description:
+ * Increase the size of I/O buffer by the specified buffer increment.
+ *
+ * Returned Value:
+ * 0 (OK) is returned on success and a negated errno is returned on
+ * failure.
+ *
+ ****************************************************************************/
+
+int elf_reallocbuffer(FAR struct elf_loadinfo_s *loadinfo, size_t increment);
+
+/****************************************************************************
+ * Name: elf_findctors
+ *
+ * Description:
+ * Find C++ static constructors.
+ *
+ * Input Parameters:
+ * loadinfo - Load state information
+ *
+ * Returned Value:
+ * 0 (OK) is returned on success and a negated errno is returned on
+ * failure.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_BINFMT_CONSTRUCTORS
+int elf_loadctors(FAR struct elf_loadinfo_s *loadinfo);
+#endif
+
+/****************************************************************************
+ * Name: elf_loaddtors
+ *
+ * Description:
+ * Load pointers to static destructors into an in-memory array.
+ *
+ * Input Parameters:
+ * loadinfo - Load state information
+ *
+ * Returned Value:
+ * 0 (OK) is returned on success and a negated errno is returned on
+ * failure.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_BINFMT_CONSTRUCTORS
+int elf_loaddtors(FAR struct elf_loadinfo_s *loadinfo);
+#endif
+
+/****************************************************************************
+ * Name: elf_addrenv_alloc
+ *
+ * Description:
+ * Allocate memory for the ELF image (elfalloc). If CONFIG_ADDRENV=n,
+ * elfalloc will be allocated using kzalloc(). If CONFIG_ADDRENV-y, then
+ * elfalloc will be allocated using up_addrenv_create(). In either case,
+ * there will be a unique instance of elfalloc (and stack) for each
+ * instance of a process.
+ *
+ * Input Parameters:
+ * loadinfo - Load state information
+ * envsize - The size (in bytes) of the address environment needed for the
+ * ELF image.
+ *
+ * Returned Value:
+ * Zero (OK) on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+int elf_addrenv_alloc(FAR struct elf_loadinfo_s *loadinfo, size_t envsize);
+
+/****************************************************************************
+ * Name: elf_addrenv_select
+ *
+ * Description:
+ * Temporarity select the task's address environemnt.
+ *
+ * Input Parameters:
+ * loadinfo - Load state information
+ *
+ * Returned Value:
+ * Zero (OK) on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_ADDRENV
+# define elf_addrenv_select(l) up_addrenv_select((l)->addrenv, &(l)->oldenv)
+#endif
+
+/****************************************************************************
+ * Name: elf_addrenv_restore
+ *
+ * Description:
+ * Restore the address environment before elf_addrenv_select() was called..
+ *
+ * Input Parameters:
+ * loadinfo - Load state information
+ *
+ * Returned Value:
+ * Zero (OK) on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_ADDRENV
+# define elf_addrenv_restore(l) up_addrenv_restore((l)->oldenv)
+#endif
+
+/****************************************************************************
+ * Name: elf_addrenv_free
+ *
+ * Description:
+ * Release the address environment previously created by
+ * elf_addrenv_alloc(). This function is called only under certain error
+ * conditions after the the module has been loaded but not yet started.
+ * After the module has been started, the address environment will
+ * automatically be freed when the module exits.
+ *
+ * Input Parameters:
+ * loadinfo - Load state information
+ *
+ * Returned Value:
+ * None.
+ *
+ ****************************************************************************/
+
+void elf_addrenv_free(FAR struct elf_loadinfo_s *loadinfo);
+
+#endif /* __BINFMT_LIBELF_LIBELF_H */
diff --git a/nuttx/binfmt/libelf/libelf_addrenv.c b/nuttx/binfmt/libelf/libelf_addrenv.c
new file mode 100644
index 000000000..193062a54
--- /dev/null
+++ b/nuttx/binfmt/libelf/libelf_addrenv.c
@@ -0,0 +1,176 @@
+/****************************************************************************
+ * binfmt/libelf/libelf_addrenv.c
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/arch.h>
+#include <nuttx/kmalloc.h>
+
+#include "libelf.h"
+
+/****************************************************************************
+ * Pre-Processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Constant Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: elf_addrenv_alloc
+ *
+ * Description:
+ * Allocate memory for the ELF image (elfalloc). If CONFIG_ADDRENV=n,
+ * elfalloc will be allocated using kzalloc(). If CONFIG_ADDRENV-y, then
+ * elfalloc will be allocated using up_addrenv_create(). In either case,
+ * there will be a unique instance of elfalloc (and stack) for each
+ * instance of a process.
+ *
+ * Input Parameters:
+ * loadinfo - Load state information
+ * envsize - The size (in bytes) of the address environment needed for the
+ * ELF image.
+ *
+ * Returned Value:
+ * Zero (OK) on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+int elf_addrenv_alloc(FAR struct elf_loadinfo_s *loadinfo, size_t envsize)
+{
+#ifdef CONFIG_ADDRENV
+ FAR void *vaddr;
+ int ret;
+
+ /* Create an address environment for the new ELF task */
+
+ ret = up_addrenv_create(envsize, &loadinfo->addrenv);
+ if (ret < 0)
+ {
+ bdbg("ERROR: up_addrenv_create failed: %d\n", ret);
+ return ret;
+ }
+
+ /* Get the virtual address associated with the start of the address
+ * environment. This is the base address that we will need to use to
+ * access the ELF image (but only if the address environment has been
+ * selected.
+ */
+
+ ret = up_addrenv_vaddr(loadinfo->addrenv, &vaddr);
+ if (ret < 0)
+ {
+ bdbg("ERROR: up_addrenv_vaddr failed: %d\n", ret);
+ return ret;
+ }
+
+ loadinfo->elfalloc = (uintptr_t)vaddr;
+ return OK;
+#else
+ /* Allocate memory to hold the ELF image */
+
+ loadinfo->elfalloc = (uintptr_t)kzalloc(envsize);
+ if (!loadinfo->elfalloc)
+ {
+ return -ENOMEM;
+ }
+
+ return OK;
+#endif
+}
+
+/****************************************************************************
+ * Name: elf_addrenv_free
+ *
+ * Description:
+ * Release the address environment previously created by
+ * elf_addrenv_create(). This function is called only under certain error
+ * conditions after the the module has been loaded but not yet started.
+ * After the module has been started, the address environment will
+ * automatically be freed when the module exits.
+ *
+ * Input Parameters:
+ * loadinfo - Load state information
+ *
+ * Returned Value:
+ * None.
+ *
+ ****************************************************************************/
+
+void elf_addrenv_free(FAR struct elf_loadinfo_s *loadinfo)
+{
+#ifdef CONFIG_ADDRENV
+ int ret;
+
+ /* Free the address environemnt */
+
+ ret = up_addrenv_destroy(loadinfo->addrenv);
+ if (ret < 0)
+ {
+ bdbg("ERROR: up_addrenv_destroy failed: %d\n", ret);
+ }
+
+ /* Clear out all indications of the allocated address environment */
+
+ loadinfo->elfalloc = 0;
+ loadinfo->elfsize = 0;
+ loadinfo->addrenv = 0;
+#else
+ /* If there is an allocation for the ELF image, free it */
+
+ if (loadinfo->elfalloc != 0)
+ {
+ kfree((FAR void *)loadinfo->elfalloc);
+ loadinfo->elfalloc = 0;
+ }
+
+ loadinfo->elfsize = 0;
+#endif
+}
diff --git a/nuttx/binfmt/libelf/libelf_bind.c b/nuttx/binfmt/libelf/libelf_bind.c
new file mode 100644
index 000000000..ccdb5108e
--- /dev/null
+++ b/nuttx/binfmt/libelf/libelf_bind.c
@@ -0,0 +1,334 @@
+/****************************************************************************
+ * binfmt/libelf/libelf_bind.c
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdint.h>
+#include <string.h>
+#include <elf32.h>
+#include <errno.h>
+#include <assert.h>
+#include <debug.h>
+
+#include <nuttx/binfmt/elf.h>
+#include <nuttx/binfmt/symtab.h>
+
+#include "libelf.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* CONFIG_DEBUG, CONFIG_DEBUG_VERBOSE, and CONFIG_DEBUG_BINFMT have to be
+ * defined or CONFIG_ELF_DUMPBUFFER does nothing.
+ */
+
+#if !defined(CONFIG_DEBUG_VERBOSE) || !defined (CONFIG_DEBUG_BINFMT)
+# undef CONFIG_ELF_DUMPBUFFER
+#endif
+
+#ifndef CONFIG_ELF_BUFFERSIZE
+# define CONFIG_ELF_BUFFERSIZE 128
+#endif
+
+#ifdef CONFIG_ELF_DUMPBUFFER
+# define elf_dumpbuffer(m,b,n) bvdbgdumpbuffer(m,b,n)
+#else
+# define elf_dumpbuffer(m,b,n)
+#endif
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: elf_readrel
+ *
+ * Description:
+ * Read the ELF32_Rel structure into memory.
+ *
+ ****************************************************************************/
+
+static inline int elf_readrel(FAR struct elf_loadinfo_s *loadinfo,
+ FAR const Elf32_Shdr *relsec,
+ int index, FAR Elf32_Rel *rel)
+{
+ off_t offset;
+
+ /* Verify that the symbol table index lies within symbol table */
+
+ if (index < 0 || index > (relsec->sh_size / sizeof(Elf32_Rel)))
+ {
+ bdbg("Bad relocation symbol index: %d\n", index);
+ return -EINVAL;
+ }
+
+ /* Get the file offset to the symbol table entry */
+
+ offset = relsec->sh_offset + sizeof(Elf32_Rel) * index;
+
+ /* And, finally, read the symbol table entry into memory */
+
+ return elf_read(loadinfo, (FAR uint8_t*)rel, sizeof(Elf32_Rel), offset);
+}
+
+/****************************************************************************
+ * Name: elf_relocate and elf_relocateadd
+ *
+ * Description:
+ * Perform all relocations associated with a section.
+ *
+ * Returned Value:
+ * 0 (OK) is returned on success and a negated errno is returned on
+ * failure.
+ *
+ ****************************************************************************/
+
+static int elf_relocate(FAR struct elf_loadinfo_s *loadinfo, int relidx,
+ FAR const struct symtab_s *exports, int nexports)
+
+{
+ FAR Elf32_Shdr *relsec = &loadinfo->shdr[relidx];
+ FAR Elf32_Shdr *dstsec = &loadinfo->shdr[relsec->sh_info];
+ Elf32_Rel rel;
+ Elf32_Sym sym;
+ uintptr_t addr;
+ int symidx;
+ int ret;
+ int i;
+
+ /* Examine each relocation in the section. 'relsec' is the section
+ * containing the relations. 'dstsec' is the section containing the data
+ * to be relocated.
+ */
+
+ for (i = 0; i < relsec->sh_size / sizeof(Elf32_Rel); i++)
+ {
+ /* Read the relocation entry into memory */
+
+ ret = elf_readrel(loadinfo, relsec, i, &rel);
+ if (ret < 0)
+ {
+ bdbg("Section %d reloc %d: Failed to read relocation entry: %d\n",
+ relidx, i, ret);
+ return ret;
+ }
+
+ /* Get the symbol table index for the relocation. This is contained
+ * in a bit-field within the r_info element.
+ */
+
+ symidx = ELF32_R_SYM(rel.r_info);
+
+ /* Read the symbol table entry into memory */
+
+ ret = elf_readsym(loadinfo, symidx, &sym);
+ if (ret < 0)
+ {
+ bdbg("Section %d reloc %d: Failed to read symbol[%d]: %d\n",
+ relidx, i, symidx, ret);
+ return ret;
+ }
+
+ /* Get the value of the symbol (in sym.st_value) */
+
+ ret = elf_symvalue(loadinfo, &sym, exports, nexports);
+ if (ret < 0)
+ {
+ bdbg("Section %d reloc %d: Failed to get value of symbol[%d]: %d\n",
+ relidx, i, symidx, ret);
+ return ret;
+ }
+
+ /* Calculate the relocation address. */
+
+ if (rel.r_offset < 0 || rel.r_offset > dstsec->sh_size - sizeof(uint32_t))
+ {
+ bdbg("Section %d reloc %d: Relocation address out of range, offset %d size %d\n",
+ relidx, i, rel.r_offset, dstsec->sh_size);
+ return -EINVAL;
+ }
+
+ addr = dstsec->sh_addr + rel.r_offset;
+
+ /* If CONFIG_ADDRENV=y, then 'addr' lies in a virtual address space that
+ * may not be in place now. elf_addrenv_select() will temporarily
+ * instantiate that address space.
+ */
+
+#ifdef CONFIG_ADDRENV
+ ret = elf_addrenv_select(loadinfo);
+ if (ret < 0)
+ {
+ bdbg("ERROR: elf_addrenv_select() failed: %d\n", ret);
+ return ret;
+ }
+#endif
+
+ /* Now perform the architecture-specific relocation */
+
+ ret = arch_relocate(&rel, &sym, addr);
+ if (ret < 0)
+ {
+#ifdef CONFIG_ADDRENV
+ (void)elf_addrenv_restore(loadinfo);
+#endif
+ bdbg("ERROR: Section %d reloc %d: Relocation failed: %d\n", ret);
+ return ret;
+ }
+
+ /* Restore the original address environment */
+
+#ifdef CONFIG_ADDRENV
+ ret = elf_addrenv_restore(loadinfo);
+ if (ret < 0)
+ {
+ bdbg("ERROR: elf_addrenv_restore() failed: %d\n", ret);
+ return ret;
+ }
+#endif
+ }
+
+ return OK;
+}
+
+static int elf_relocateadd(FAR struct elf_loadinfo_s *loadinfo, int relidx,
+ FAR const struct symtab_s *exports, int nexports)
+{
+ bdbg("Not implemented\n");
+ return -ENOSYS;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: elf_bind
+ *
+ * Description:
+ * Bind the imported symbol names in the loaded module described by
+ * 'loadinfo' using the exported symbol values provided by 'symtab'.
+ *
+ * Returned Value:
+ * 0 (OK) is returned on success and a negated errno is returned on
+ * failure.
+ *
+ ****************************************************************************/
+
+int elf_bind(FAR struct elf_loadinfo_s *loadinfo,
+ FAR const struct symtab_s *exports, int nexports)
+{
+ int ret;
+ int i;
+
+ /* Find the symbol and string tables */
+
+ ret = elf_findsymtab(loadinfo);
+ if (ret < 0)
+ {
+ return ret;
+ }
+
+ /* Allocate an I/O buffer. This buffer is used by elf_symname() to
+ * accumulate the variable length symbol name.
+ */
+
+ ret = elf_allocbuffer(loadinfo);
+ if (ret < 0)
+ {
+ bdbg("elf_allocbuffer failed: %d\n", ret);
+ return -ENOMEM;
+ }
+
+ /* Process relocations in every allocated section */
+
+ for (i = 1; i < loadinfo->ehdr.e_shnum; i++)
+ {
+ /* Get the index to the relocation section */
+
+ int infosec = loadinfo->shdr[i].sh_info;
+ if (infosec >= loadinfo->ehdr.e_shnum)
+ {
+ continue;
+ }
+
+ /* Make sure that the section is allocated. We can't relocated
+ * sections that were not loaded into memory.
+ */
+
+ if ((loadinfo->shdr[infosec].sh_flags & SHF_ALLOC) == 0)
+ {
+ continue;
+ }
+
+ /* Process the relocations by type */
+
+ if (loadinfo->shdr[i].sh_type == SHT_REL)
+ {
+ ret = elf_relocate(loadinfo, i, exports, nexports);
+ }
+ else if (loadinfo->shdr[i].sh_type == SHT_RELA)
+ {
+ ret = elf_relocateadd(loadinfo, i, exports, nexports);
+ }
+
+ if (ret < 0)
+ {
+ break;
+ }
+ }
+
+ /* Flush the instruction cache before starting the newly loaded module */
+
+#ifdef CONFIG_ELF_ICACHE
+ arch_flushicache((FAR void*)loadinfo->elfalloc, loadinfo->elfsize);
+#endif
+
+ return ret;
+}
+
diff --git a/nuttx/binfmt/libelf/libelf_load.c b/nuttx/binfmt/libelf/libelf_load.c
new file mode 100644
index 000000000..0e4ad9798
--- /dev/null
+++ b/nuttx/binfmt/libelf/libelf_load.c
@@ -0,0 +1,288 @@
+/****************************************************************************
+ * binfmt/libelf/libelf_load.c
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <elf32.h>
+#include <assert.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/binfmt/elf.h>
+
+#include "libelf.h"
+
+/****************************************************************************
+ * Pre-Processor Definitions
+ ****************************************************************************/
+
+#define ELF_ALIGN_MASK ((1 << CONFIG_ELF_ALIGN_LOG2) - 1)
+#define ELF_ALIGNUP(a) (((unsigned long)(a) + ELF_ALIGN_MASK) & ~ELF_ALIGN_MASK)
+#define ELF_ALIGNDOWN(a) ((unsigned long)(a) & ~ELF_ALIGN_MASK)
+
+
+#ifndef MAX
+#define MAX(x,y) ((x) > (y) ? (x) : (y))
+#endif
+
+/****************************************************************************
+ * Private Constant Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: elf_elfsize
+ *
+ * Description:
+ * Calculate total memory allocation for the ELF file.
+ *
+ * Returned Value:
+ * 0 (OK) is returned on success and a negated errno is returned on
+ * failure.
+ *
+ ****************************************************************************/
+
+static void elf_elfsize(struct elf_loadinfo_s *loadinfo)
+{
+ size_t elfsize;
+ int i;
+
+ /* Accumulate the size each section into memory that is marked SHF_ALLOC */
+
+ elfsize = 0;
+ for (i = 0; i < loadinfo->ehdr.e_shnum; i++)
+ {
+ FAR Elf32_Shdr *shdr = &loadinfo->shdr[i];
+
+ /* SHF_ALLOC indicates that the section requires memory during
+ * execution.
+ */
+
+ if ((shdr->sh_flags & SHF_ALLOC) != 0)
+ {
+ elfsize += ELF_ALIGNUP(shdr->sh_size);
+ }
+ }
+
+ /* Save the allocation size */
+
+ loadinfo->elfsize = elfsize;
+}
+
+/****************************************************************************
+ * Name: elf_loadfile
+ *
+ * Description:
+ * Allocate memory for the file and read the section data into the
+ * allocated memory. Section addresses in the shdr[] are updated to point
+ * to the corresponding position in the allocated memory.
+ *
+ * Returned Value:
+ * 0 (OK) is returned on success and a negated errno is returned on
+ * failure.
+ *
+ ****************************************************************************/
+
+static inline int elf_loadfile(FAR struct elf_loadinfo_s *loadinfo)
+{
+ FAR uint8_t *dest;
+ int ret;
+ int i;
+
+ /* Allocate (and zero) memory for the ELF file. */
+
+ ret = elf_addrenv_alloc(loadinfo, loadinfo->elfsize);
+ if (ret < 0)
+ {
+ bdbg("ERROR: elf_addrenv_alloc() failed: %d\n", ret);
+ return ret;
+ }
+
+ /* Read each section into memory that is marked SHF_ALLOC + SHT_NOBITS */
+
+ bvdbg("Loaded sections:\n");
+ dest = (FAR uint8_t*)loadinfo->elfalloc;
+
+ for (i = 0; i < loadinfo->ehdr.e_shnum; i++)
+ {
+ FAR Elf32_Shdr *shdr = &loadinfo->shdr[i];
+
+ /* SHF_ALLOC indicates that the section requires memory during
+ * execution */
+
+ if ((shdr->sh_flags & SHF_ALLOC) == 0)
+ {
+ continue;
+ }
+
+ /* SHT_NOBITS indicates that there is no data in the file for the
+ * section.
+ */
+
+ if (shdr->sh_type != SHT_NOBITS)
+ {
+ /* If CONFIG_ADDRENV=y, then 'dest' lies in a virtual address space
+ * that may not be in place now. elf_addrenv_select() will
+ * temporarily instantiate that address space.
+ */
+
+#ifdef CONFIG_ADDRENV
+ ret = elf_addrenv_select(loadinfo);
+ if (ret < 0)
+ {
+ bdbg("ERROR: elf_addrenv_select() failed: %d\n", ret);
+ return ret;
+ }
+#endif
+
+ /* Read the section data from sh_offset to dest */
+
+ ret = elf_read(loadinfo, dest, shdr->sh_size, shdr->sh_offset);
+ if (ret < 0)
+ {
+ bdbg("Failed to read section %d: %d\n", i, ret);
+ return ret;
+ }
+
+ /* Restore the original address environment */
+
+#ifdef CONFIG_ADDRENV
+ ret = elf_addrenv_restore(loadinfo);
+ if (ret < 0)
+ {
+ bdbg("ERROR: elf_addrenv_restore() failed: %d\n", ret);
+ return ret;
+ }
+#endif
+ }
+
+ /* Update sh_addr to point to copy in memory */
+
+ bvdbg("%d. %08x->%08x\n", i, (long)shdr->sh_addr, (long)dest);
+ shdr->sh_addr = (uintptr_t)dest;
+
+ /* Setup the memory pointer for the next time through the loop */
+
+ dest += ELF_ALIGNUP(shdr->sh_size);
+ }
+
+ return OK;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: elf_load
+ *
+ * Description:
+ * Loads the binary into memory, allocating memory, performing relocations
+ * and inializing the data and bss segments.
+ *
+ * Returned Value:
+ * 0 (OK) is returned on success and a negated errno is returned on
+ * failure.
+ *
+ ****************************************************************************/
+
+int elf_load(FAR struct elf_loadinfo_s *loadinfo)
+{
+ int ret;
+
+ bvdbg("loadinfo: %p\n", loadinfo);
+ DEBUGASSERT(loadinfo && loadinfo->filfd >= 0);
+
+ /* Load section headers into memory */
+
+ ret = elf_loadshdrs(loadinfo);
+ if (ret < 0)
+ {
+ bdbg("elf_loadshdrs failed: %d\n", ret);
+ goto errout_with_buffers;
+ }
+
+ /* Determine total size to allocate */
+
+ elf_elfsize(loadinfo);
+
+ /* Allocate memory and load sections into memory */
+
+ ret = elf_loadfile(loadinfo);
+ if (ret < 0)
+ {
+ bdbg("elf_loadfile failed: %d\n", ret);
+ goto errout_with_buffers;
+ }
+
+ /* Load static constructors and destructors. */
+
+#ifdef CONFIG_BINFMT_CONSTRUCTORS
+ ret = elf_loadctors(loadinfo);
+ if (ret < 0)
+ {
+ bdbg("elf_loadctors failed: %d\n", ret);
+ goto errout_with_buffers;
+ }
+
+ ret = elf_loaddtors(loadinfo);
+ if (ret < 0)
+ {
+ bdbg("elf_loaddtors failed: %d\n", ret);
+ goto errout_with_buffers;
+ }
+#endif
+
+ return OK;
+
+ /* Error exits */
+
+errout_with_buffers:
+ elf_unload(loadinfo);
+ return ret;
+}
+
diff --git a/nuttx/binfmt/libelf/libelf_read.c b/nuttx/binfmt/libelf/libelf_read.c
new file mode 100644
index 000000000..f4b725183
--- /dev/null
+++ b/nuttx/binfmt/libelf/libelf_read.c
@@ -0,0 +1,165 @@
+/****************************************************************************
+ * binfmt/libelf/libelf_read.c
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <unistd.h>
+#include <string.h>
+#include <elf32.h>
+#include <debug.h>
+#include <errno.h>
+
+#include <nuttx/binfmt/elf.h>
+
+/****************************************************************************
+ * Pre-Processor Definitions
+ ****************************************************************************/
+
+#undef ELF_DUMP_READDATA /* Define to dump all file data read */
+#define DUMPER lib_rawprintf /* If ELF_DUMP_READDATA is defined, this
+ * is the API used to dump data */
+
+/****************************************************************************
+ * Private Constant Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: elf_dumpreaddata
+ ****************************************************************************/
+
+#if defined(ELF_DUMP_READDATA)
+static inline void elf_dumpreaddata(char *buffer, int buflen)
+{
+ uint32_t *buf32 = (uint32_t*)buffer;
+ int i;
+ int j;
+
+ for (i = 0; i < buflen; i += 32)
+ {
+ DUMPER("%04x:", i);
+ for (j = 0; j < 32; j += sizeof(uint32_t))
+ {
+ DUMPER(" %08x", *buf32++);
+ }
+ DUMPER("\n");
+ }
+}
+#else
+# define elf_dumpreaddata(b,n)
+#endif
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: elf_read
+ *
+ * Description:
+ * Read 'readsize' bytes from the object file at 'offset'. The data is
+ * read into 'buffer.' If 'buffer' is part of the ELF address environment,
+ * then the caller is responsibile for assuring that that address
+ * environment is in place before calling this function (i.e., that
+ * elf_addrenv_select() has been called if CONFIG_ADDRENV=y).
+ *
+ * Returned Value:
+ * 0 (OK) is returned on success and a negated errno is returned on
+ * failure.
+ *
+ ****************************************************************************/
+
+int elf_read(FAR struct elf_loadinfo_s *loadinfo, FAR uint8_t *buffer,
+ size_t readsize, off_t offset)
+{
+ ssize_t nbytes; /* Number of bytes read */
+ off_t rpos; /* Position returned by lseek */
+
+ bvdbg("Read %ld bytes from offset %ld\n", (long)readsize, (long)offset);
+
+ /* Loop until all of the requested data has been read. */
+
+ while (readsize > 0)
+ {
+ /* Seek to the next read position */
+
+ rpos = lseek(loadinfo->filfd, offset, SEEK_SET);
+ if (rpos != offset)
+ {
+ int errval = errno;
+ bdbg("Failed to seek to position %ld: %d\n", (long)offset, errval);
+ return -errval;
+ }
+
+ /* Read the file data at offset into the user buffer */
+
+ nbytes = read(loadinfo->filfd, buffer, readsize);
+ if (nbytes < 0)
+ {
+ int errval = errno;
+
+ /* EINTR just means that we received a signal */
+
+ if (errval != EINTR)
+ {
+ bdbg("Read of .data failed: %d\n", errval);
+ return -errval;
+ }
+ }
+ else if (nbytes == 0)
+ {
+ bdbg("Unexpected end of file\n");
+ return -ENODATA;
+ }
+ else
+ {
+ readsize -= nbytes;
+ buffer += nbytes;
+ offset += nbytes;
+ }
+ }
+
+ elf_dumpreaddata(buffer, readsize);
+ return OK;
+}
diff --git a/nuttx/binfmt/libelf/libelf_unload.c b/nuttx/binfmt/libelf/libelf_unload.c
new file mode 100644
index 000000000..539e5faf7
--- /dev/null
+++ b/nuttx/binfmt/libelf/libelf_unload.c
@@ -0,0 +1,114 @@
+/****************************************************************************
+ * binfmt/libelf/libelf_unload.c
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdlib.h>
+#include <debug.h>
+
+#include <nuttx/kmalloc.h>
+#include <nuttx/binfmt/elf.h>
+
+#include "libelf.h"
+
+/****************************************************************************
+ * Pre-Processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Constant Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: elf_unload
+ *
+ * Description:
+ * This function unloads the object from memory. This essentially undoes
+ * the actions of elf_load. It is called only under certain error
+ * conditions after the the module has been loaded but not yet started.
+ *
+ * Returned Value:
+ * 0 (OK) is returned on success and a negated errno is returned on
+ * failure.
+ *
+ ****************************************************************************/
+
+int elf_unload(struct elf_loadinfo_s *loadinfo)
+{
+ /* Free all working buffers */
+
+ elf_freebuffers(loadinfo);
+
+ /* Release memory holding the relocated ELF image */
+
+ elf_addrenv_free(loadinfo);
+
+ /* Release memory used to hold static constructors and destructors */
+
+#ifdef CONFIG_BINFMT_CONSTRUCTORS
+ if (loadinfo->ctoralloc != 0)
+ {
+ kfree(loadinfo->ctoralloc);
+ loadinfo->ctoralloc = NULL;
+ }
+
+ loadinfo->ctors = NULL;
+ loadinfo->nctors = 0;
+
+ if (loadinfo->dtoralloc != 0)
+ {
+ kfree(loadinfo->dtoralloc);
+ loadinfo->dtoralloc = NULL;
+ }
+
+ loadinfo->dtors = NULL;
+ loadinfo->ndtors = 0;
+#endif
+
+ return OK;
+}
+
diff --git a/nuttx/binfmt/libnxflat/Kconfig b/nuttx/binfmt/libnxflat/Kconfig
index ae2bf3130..fdb270cfb 100644
--- a/nuttx/binfmt/libnxflat/Kconfig
+++ b/nuttx/binfmt/libnxflat/Kconfig
@@ -2,3 +2,8 @@
# For a description of the syntax of this configuration file,
# see misc/tools/kconfig-language.txt.
#
+
+config NXFLAT_DUMPBUFFER
+ bool "Dump NXFLAT buffers"
+ default n
+ depends on DEBUG && DEBUG_VERBOSE
diff --git a/nuttx/binfmt/libnxflat/Make.defs b/nuttx/binfmt/libnxflat/Make.defs
index f979741e5..6a0bf1873 100644
--- a/nuttx/binfmt/libnxflat/Make.defs
+++ b/nuttx/binfmt/libnxflat/Make.defs
@@ -1,5 +1,5 @@
############################################################################
-# nxflat/lib/Make.defs
+# binfmt/libnxflat/Make.defs
#
# Copyright (C) 2009 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
@@ -33,7 +33,22 @@
#
############################################################################
-LIBNXFLAT_ASRCS =
-LIBNXFLAT_CSRCS = libnxflat_init.c libnxflat_uninit.c libnxflat_load.c \
- libnxflat_unload.c libnxflat_verify.c libnxflat_read.c \
- libnxflat_bind.c
+ifeq ($(CONFIG_NXFLAT),y)
+
+# NXFLAT application interfaces
+
+BINFMT_CSRCS += nxflat.c
+
+# NXFLAT library
+
+BINFMT_CSRCS += libnxflat_init.c libnxflat_uninit.c libnxflat_addrenv.c
+BINFMT_CSRCS += libnxflat_load.c libnxflat_unload.c libnxflat_verify.c
+BINFMT_CSRCS += libnxflat_read.c libnxflat_bind.c
+
+# Hook the libnxflat subdirectory into the build
+
+VPATH += libnxflat
+SUBDIRS += libnxflat
+DEPPATH += --dep-path libnxflat
+
+endif
diff --git a/nuttx/binfmt/libnxflat/libnxflat.h b/nuttx/binfmt/libnxflat/libnxflat.h
new file mode 100644
index 000000000..cb1cb7057
--- /dev/null
+++ b/nuttx/binfmt/libnxflat/libnxflat.h
@@ -0,0 +1,136 @@
+/****************************************************************************
+ * binfmt/libnxflat/libnxflat.h
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+#ifndef __BINFMT_LIBNXFLAT_LIBNXFLAT_H
+#define __BINFMT_LIBNXFLAT_LIBNXFLAT_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+
+#include <nuttx/arch.h>
+#include <nuttx/binfmt/nxflat.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nxflat_addrenv_alloc
+ *
+ * Description:
+ * Allocate memory for the ELF image (elfalloc). If CONFIG_ADDRENV=n,
+ * elfalloc will be allocated using kzalloc(). If CONFIG_ADDRENV-y, then
+ * elfalloc will be allocated using up_addrenv_create(). In either case,
+ * there will be a unique instance of elfalloc (and stack) for each
+ * instance of a process.
+ *
+ * Input Parameters:
+ * loadinfo - Load state information
+ * envsize - The size (in bytes) of the address environment needed for the
+ * ELF image.
+ *
+ * Returned Value:
+ * Zero (OK) on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+int nxflat_addrenv_alloc(FAR struct nxflat_loadinfo_s *loadinfo, size_t envsize);
+
+/****************************************************************************
+ * Name: nxflat_addrenv_select
+ *
+ * Description:
+ * Temporarity select the task's address environemnt.
+ *
+ * Input Parameters:
+ * loadinfo - Load state information
+ *
+ * Returned Value:
+ * Zero (OK) on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_ADDRENV
+# define nxflat_addrenv_select(l) up_addrenv_select((l)->addrenv, &(l)->oldenv)
+#endif
+
+/****************************************************************************
+ * Name: nxflat_addrenv_restore
+ *
+ * Description:
+ * Restore the address environment before nxflat_addrenv_select() was called..
+ *
+ * Input Parameters:
+ * loadinfo - Load state information
+ *
+ * Returned Value:
+ * Zero (OK) on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_ADDRENV
+# define nxflat_addrenv_restore(l) up_addrenv_restore((l)->oldenv)
+#endif
+
+/****************************************************************************
+ * Name: nxflat_addrenv_free
+ *
+ * Description:
+ * Release the address environment previously created by
+ * nxflat_addrenv_create(). This function is called only under certain
+ * error conditions after the the module has been loaded but not yet
+ * started. After the module has been started, the address environment
+ * will automatically be freed when the module exits.
+ *
+ * Input Parameters:
+ * loadinfo - Load state information
+ *
+ * Returned Value:
+ * None.
+ *
+ ****************************************************************************/
+
+void nxflat_addrenv_free(FAR struct nxflat_loadinfo_s *loadinfo);
+
+#endif /* __BINFMT_LIBNXFLAT_LIBNXFLAT_H */
diff --git a/nuttx/binfmt/libnxflat/libnxflat_addrenv.c b/nuttx/binfmt/libnxflat/libnxflat_addrenv.c
new file mode 100644
index 000000000..2d9255b28
--- /dev/null
+++ b/nuttx/binfmt/libnxflat/libnxflat_addrenv.c
@@ -0,0 +1,235 @@
+/****************************************************************************
+ * binfmt/libnxflat/libnxflat_addrenv.c
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <string.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/arch.h>
+#include <nuttx/kmalloc.h>
+
+#include "libnxflat.h"
+
+/****************************************************************************
+ * Pre-Processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Constant Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nxflat_addrenv_alloc
+ *
+ * Description:
+ * Allocate memory for the ELF image (elfalloc). If CONFIG_ADDRENV=n,
+ * elfalloc will be allocated using kzalloc(). If CONFIG_ADDRENV-y, then
+ * elfalloc will be allocated using up_addrenv_create(). In either case,
+ * there will be a unique instance of elfalloc (and stack) for each
+ * instance of a process.
+ *
+ * Input Parameters:
+ * loadinfo - Load state information
+ * envsize - The size (in bytes) of the address environment needed for the
+ * ELF image.
+ *
+ * Returned Value:
+ * Zero (OK) on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+int nxflat_addrenv_alloc(FAR struct nxflat_loadinfo_s *loadinfo, size_t envsize)
+{
+ FAR struct dspace_s *dspace;
+#ifdef CONFIG_ADDRENV
+ FAR void *vaddr;
+ hw_addrenv_t oldenv;
+ int ret;
+#endif
+
+ DEBUGASSERT(!loadinfo->dspace);
+
+ /* Allocate the struct dspace_s container for the D-Space allocation */
+
+ dspace = (FAR struct dspace_s *)kmalloc(sizeof(struct dspace_s));
+ if (dspace == 0)
+ {
+ bdbg("ERROR: Failed to allocate DSpace\n");
+ return -ENOMEM;
+ }
+
+#ifdef CONFIG_ADDRENV
+ /* Create a D-Space address environment for the new NXFLAT task */
+
+ ret = up_addrenv_create(envsize, &loadinfo->addrenv);
+ if (ret < 0)
+ {
+ bdbg("ERROR: up_addrenv_create failed: %d\n", ret);
+ goto errout_with_dspace;
+ }
+
+ /* Get the virtual address associated with the start of the address
+ * environment. This is the base address that we will need to use to
+ * access the D-Space region (but only if the address environment has been
+ * selected.
+ */
+
+ ret = up_addrenv_vaddr(loadinfo->addrenv, &vaddr);
+ if (ret < 0)
+ {
+ bdbg("ERROR: up_addrenv_vaddr failed: %d\n", ret);
+ goto errout_with_addrenv;
+ }
+
+ /* Clear all of the allocated D-Space memory. We have to temporarily
+ * selected the D-Space address environment to do this.
+ */
+
+ ret = up_addrenv_select(loadinfo->addrenv, &oldenv);
+ if (ret < 0)
+ {
+ bdbg("ERROR: up_addrenv_select failed: %d\n", ret);
+ goto errout_with_addrenv;
+ }
+
+ memset(vaddr, 0, envsize);
+
+ ret = up_addrenv_restore(oldenv);
+ if (ret < 0)
+ {
+ bdbg("ERROR: up_addrenv_restore failed: %d\n", ret);
+ goto errout_with_addrenv;
+ }
+
+ /* Success... save the fruits of our labor */
+
+ loadinfo->dspace = dspace;
+ dspace->crefs = 1;
+ dspace->region = (FAR uint8_t *)vaddr;
+ return OK;
+
+errout_with_addrenv:
+ (void)up_addrenv_destroy(loadinfo->addrenv);
+ loadinfo->addrenv = 0;
+
+errout_with_dspace:
+ kfree(dspace);
+ return ret;
+#else
+ /* Allocate (and zero) memory to hold the ELF image */
+
+ dspace->region = (FAR uint8_t *)kzalloc(envsize);
+ if (!dspace->region)
+ {
+ kfree(dspace);
+ return -ENOMEM;
+ }
+
+ loadinfo->dspace = dspace;
+ dspace->crefs = 1;
+ return OK;
+#endif
+}
+
+/****************************************************************************
+ * Name: nxflat_addrenv_free
+ *
+ * Description:
+ * Release the address environment previously created by
+ * nxflat_addrenv_create(). This function is called only under certain
+ * error conditions after the the module has been loaded but not yet
+ * started. After the module has been started, the address environment
+ * will automatically be freed when the module exits.
+ *
+ * Input Parameters:
+ * loadinfo - Load state information
+ *
+ * Returned Value:
+ * None.
+ *
+ ****************************************************************************/
+
+void nxflat_addrenv_free(FAR struct nxflat_loadinfo_s *loadinfo)
+{
+ FAR struct dspace_s *dspace;
+#ifdef CONFIG_ADDRENV
+ int ret;
+#endif
+
+ DEBUGASSERT(loadinfo);
+ dspace = loadinfo->dspace;
+
+ if (dspace)
+ {
+#ifdef CONFIG_ADDRENV
+ /* Destroy the address environment */
+
+ ret = up_addrenv_destroy(loadinfo->addrenv);
+ if (ret < 0)
+ {
+ bdbg("ERROR: up_addrenv_destroy failed: %d\n", ret);
+ }
+
+ loadinfo->addrenv = 0;
+#else
+ /* Free the allocated D-Space region */
+
+ if (dspace->region)
+ {
+ kfree(dspace->region);
+ }
+#endif
+
+ /* Now destroy the D-Space container */
+
+ DEBUGASSERT(dspace->crefs == 1);
+ kfree(dspace);
+ loadinfo->dspace = NULL;
+ }
+}
diff --git a/nuttx/binfmt/libnxflat/libnxflat_bind.c b/nuttx/binfmt/libnxflat/libnxflat_bind.c
index ca348178d..816810a46 100644
--- a/nuttx/binfmt/libnxflat/libnxflat_bind.c
+++ b/nuttx/binfmt/libnxflat/libnxflat_bind.c
@@ -38,6 +38,7 @@
****************************************************************************/
#include <nuttx/config.h>
+#include <nuttx/compiler.h>
#include <stdint.h>
#include <string.h>
@@ -47,8 +48,11 @@
#include <debug.h>
#include <arpa/inet.h>
-#include <nuttx/nxflat.h>
-#include <nuttx/symtab.h>
+
+#include <nuttx/binfmt/nxflat.h>
+#include <nuttx/binfmt/symtab.h>
+
+#include "libnxflat.h"
/****************************************************************************
* Pre-processor Definitions
@@ -229,8 +233,6 @@ static inline int nxflat_gotrelocs(FAR struct nxflat_loadinfo_s *loadinfo)
hdr = (FAR struct nxflat_hdr_s*)loadinfo->ispace;
- /* From this, we can get the list of relocation entries. */
-
/* From this, we can get the offset to the list of relocation entries */
offset = ntohl(hdr->h_relocstart);
@@ -247,11 +249,27 @@ static inline int nxflat_gotrelocs(FAR struct nxflat_loadinfo_s *loadinfo)
DEBUGASSERT(offset + nrelocs * sizeof(struct nxflat_reloc_s)
<= (loadinfo->isize + loadinfo->dsize));
- relocs = (FAR struct nxflat_reloc_s*)
+ relocs = (FAR struct nxflat_reloc_s *)
(offset - loadinfo->isize + loadinfo->dspace->region);
bvdbg("isize: %08lx dpsace: %p relocs: %p\n",
(long)loadinfo->isize, loadinfo->dspace->region, relocs);
+ /* All relocations are performed within the D-Space allocation. If
+ * CONFIG_ADDRENV=y, then that D-Space allocation lies in an address
+ * environment that may not be in place. So, in that case, we must call
+ * nxflat_addrenv_select to temporarily instantiate that address space
+ * before the relocations can be performed.
+ */
+
+#ifdef CONFIG_ADDRENV
+ ret = nxflat_addrenv_select(loadinfo);
+ if (ret < 0)
+ {
+ bdbg("ERROR: nxflat_addrenv_select() failed: %d\n", ret);
+ return ret;
+ }
+#endif
+
/* Now, traverse the relocation list of and bind each GOT relocation. */
ret = OK; /* Assume success */
@@ -259,11 +277,16 @@ static inline int nxflat_gotrelocs(FAR struct nxflat_loadinfo_s *loadinfo)
{
/* Handle the relocation by the relocation type */
+#ifdef CONFIG_CAN_PASS_STRUCTS
reloc = *relocs++;
+#else
+ memcpy(&reloc, relocs, sizeof(struct nxflat_reloc_s));
+ relocs++;
+#endif
+
result = OK;
switch (NXFLAT_RELOC_TYPE(reloc.r_info))
{
-
/* NXFLAT_RELOC_TYPE_REL32I Meaning: Object file contains a 32-bit offset
* into I-Space at the offset.
* Fixup: Add mapped I-Space address to the offset.
@@ -329,6 +352,17 @@ static inline int nxflat_gotrelocs(FAR struct nxflat_loadinfo_s *loadinfo)
nxflat_dumpbuffer("GOT", (FAR const uint8_t*)relocs, nrelocs * sizeof(struct nxflat_reloc_s));
}
#endif
+
+ /* Restore the original address environment */
+
+#ifdef CONFIG_ADDRENV
+ ret = nxflat_addrenv_restore(loadinfo);
+ if (ret < 0)
+ {
+ bdbg("ERROR: nxflat_addrenv_restore() failed: %d\n", ret);
+ }
+#endif
+
return ret;
}
@@ -346,16 +380,19 @@ static inline int nxflat_gotrelocs(FAR struct nxflat_loadinfo_s *loadinfo)
****************************************************************************/
static inline int nxflat_bindimports(FAR struct nxflat_loadinfo_s *loadinfo,
- FAR const struct symtab_s *exports,
- int nexports)
+ FAR const struct symtab_s *exports,
+ int nexports)
{
FAR struct nxflat_import_s *imports;
FAR struct nxflat_hdr_s *hdr;
- FAR const struct symtab_s *symbol;
+ FAR const struct symtab_s *symbol;
char *symname;
uint32_t offset;
uint16_t nimports;
+#ifdef CONFIG_ADDRENV
+ int ret;
+#endif
int i;
/* The NXFLAT header is the first thing at the beginning of the ISpace. */
@@ -370,6 +407,22 @@ static inline int nxflat_bindimports(FAR struct nxflat_loadinfo_s *loadinfo,
nimports = ntohs(hdr->h_importcount);
bvdbg("Imports offset: %08x nimports: %d\n", offset, nimports);
+ /* The import[] table resides within the D-Space allocation. If
+ * CONFIG_ADDRENV=y, then that D-Space allocation lies in an address
+ * environment that may not be in place. So, in that case, we must call
+ * nxflat_addrenv_select to temporarily instantiate that address space
+ * before the import[] table can be modified.
+ */
+
+#ifdef CONFIG_ADDRENV
+ ret = nxflat_addrenv_select(loadinfo);
+ if (ret < 0)
+ {
+ bdbg("ERROR: nxflat_addrenv_select() failed: %d\n", ret);
+ return ret;
+ }
+#endif
+
/* Verify that this module requires imported symbols */
if (offset != 0 && nimports > 0)
@@ -388,7 +441,7 @@ static inline int nxflat_bindimports(FAR struct nxflat_loadinfo_s *loadinfo,
offset < loadinfo->isize + loadinfo->dsize);
imports = (struct nxflat_import_s*)
- (offset - loadinfo->isize + loadinfo->dspace->region);
+ (offset - loadinfo->isize + loadinfo->dspace->region);
/* Now, traverse the list of imported symbols and attempt to bind
* each symbol to the value exported by from the exported symbol
@@ -396,41 +449,44 @@ static inline int nxflat_bindimports(FAR struct nxflat_loadinfo_s *loadinfo,
*/
for (i = 0; i < nimports; i++)
- {
- bvdbg("Import[%d] (%08p) offset: %08x func: %08x\n",
- i, &imports[i], imports[i].i_funcname, imports[i].i_funcaddress);
+ {
+ bvdbg("Import[%d] (%08p) offset: %08x func: %08x\n",
+ i, &imports[i], imports[i].i_funcname, imports[i].i_funcaddress);
- /* Get a pointer to the imported symbol name. The name itself
- * lies in the TEXT segment. But the reference to the name
- * lies in DATA segment. Therefore, the name reference should
- * have been relocated when the module was loaded.
- */
+ /* Get a pointer to the imported symbol name. The name itself
+ * lies in the TEXT segment. But the reference to the name
+ * lies in DATA segment. Therefore, the name reference should
+ * have been relocated when the module was loaded.
+ */
offset = imports[i].i_funcname;
DEBUGASSERT(offset < loadinfo->isize);
- symname = (char*)(offset + loadinfo->ispace + sizeof(struct nxflat_hdr_s));
+ symname = (char*)(offset + loadinfo->ispace + sizeof(struct nxflat_hdr_s));
- /* Find the exported symbol value for this this symbol name. */
+ /* Find the exported symbol value for this this symbol name. */
#ifdef CONFIG_SYMTAB_ORDEREDBYNAME
symbol = symtab_findorderedbyname(exports, symname, nexports);
#else
symbol = symtab_findbyname(exports, symname, nexports);
#endif
- if (!symbol)
- {
- bdbg("Exported symbol \"%s\" not found\n", symname);
+ if (!symbol)
+ {
+ bdbg("Exported symbol \"%s\" not found\n", symname);
+#ifdef CONFIG_ADDRENV
+ (void)nxflat_addrenv_restore(loadinfo);
+#endif
return -ENOENT;
- }
+ }
- /* And put this into the module's import structure. */
+ /* And put this into the module's import structure. */
- imports[i].i_funcaddress = (uint32_t)symbol->sym_value;
+ imports[i].i_funcaddress = (uint32_t)symbol->sym_value;
- bvdbg("Bound import[%d] (%08p) to export '%s' (%08x)\n",
- i, &imports[i], symname, imports[i].i_funcaddress);
- }
+ bvdbg("Bound import[%d] (%08p) to export '%s' (%08x)\n",
+ i, &imports[i], symname, imports[i].i_funcaddress);
+ }
}
/* Dump the relocation import table */
@@ -441,7 +497,74 @@ static inline int nxflat_bindimports(FAR struct nxflat_loadinfo_s *loadinfo,
nxflat_dumpbuffer("Imports", (FAR const uint8_t*)imports, nimports * sizeof(struct nxflat_import_s));
}
#endif
+
+ /* Restore the original address environment */
+
+#ifdef CONFIG_ADDRENV
+ ret = nxflat_addrenv_restore(loadinfo);
+ if (ret < 0)
+ {
+ bdbg("ERROR: nxflat_addrenv_restore() failed: %d\n", ret);
+ }
+
+ return ret;
+#else
+ return OK;
+#endif
+}
+
+/****************************************************************************
+ * Name: nxflat_clearbss
+ *
+ * Description:
+ * Clear uninitialized .bss memory
+ *
+ * Returned Value:
+ * 0 (OK) is returned on success and a negated errno is returned on
+ * failure.
+ *
+ ****************************************************************************/
+
+static inline int nxflat_clearbss(FAR struct nxflat_loadinfo_s *loadinfo)
+{
+#ifdef CONFIG_ADDRENV
+ int ret;
+#endif
+
+ /* .bss resides within the D-Space allocation. If CONFIG_ADDRENV=y, then
+ * that D-Space allocation lies in an address environment that may not be
+ * in place. So, in that case, we must call nxflat_addrenv_select to
+ * temporarily instantiate that address space before the .bss can be
+ * accessed.
+ */
+
+#ifdef CONFIG_ADDRENV
+ ret = nxflat_addrenv_select(loadinfo);
+ if (ret < 0)
+ {
+ bdbg("ERROR: nxflat_addrenv_select() failed: %d\n", ret);
+ return ret;
+ }
+#endif
+
+ /* Zero the BSS area */
+
+ memset((void*)(loadinfo->dspace->region + loadinfo->datasize), 0,
+ loadinfo->bsssize);
+
+ /* Restore the original address environment */
+
+#ifdef CONFIG_ADDRENV
+ ret = nxflat_addrenv_restore(loadinfo);
+ if (ret < 0)
+ {
+ bdbg("ERROR: nxflat_addrenv_restore() failed: %d\n", ret);
+ }
+
+ return ret;
+#else
return OK;
+#endif
}
/****************************************************************************
@@ -483,10 +606,10 @@ int nxflat_bind(FAR struct nxflat_loadinfo_s *loadinfo,
* space in the loaded file.
*/
- memset((void*)(loadinfo->dspace->region + loadinfo->datasize),
- 0, loadinfo->bsssize);
+ ret = nxflat_clearbss(loadinfo);
}
}
+
return ret;
}
diff --git a/nuttx/binfmt/libnxflat/libnxflat_init.c b/nuttx/binfmt/libnxflat/libnxflat_init.c
index 5b6375ff1..b7cac8d86 100644
--- a/nuttx/binfmt/libnxflat/libnxflat_init.c
+++ b/nuttx/binfmt/libnxflat/libnxflat_init.c
@@ -48,7 +48,7 @@
#include <errno.h>
#include <arpa/inet.h>
-#include <nuttx/nxflat.h>
+#include <nuttx/binfmt/nxflat.h>
/****************************************************************************
* Pre-Processor Definitions
@@ -112,8 +112,9 @@ int nxflat_init(const char *filename, struct nxflat_loadinfo_s *loadinfo)
loadinfo->filfd = open(filename, O_RDONLY);
if (loadinfo->filfd < 0)
{
- bdbg("Failed to open NXFLAT binary %s: %d\n", filename, ret);
- return -errno;
+ int errval = errno;
+ bdbg("Failed to open NXFLAT binary %s: %d\n", filename, errval);
+ return -errval;
}
/* Read the NXFLAT header from offset 0 */
diff --git a/nuttx/binfmt/libnxflat/libnxflat_load.c b/nuttx/binfmt/libnxflat/libnxflat_load.c
index 0991d0c2d..5f13b577a 100644
--- a/nuttx/binfmt/libnxflat/libnxflat_load.c
+++ b/nuttx/binfmt/libnxflat/libnxflat_load.c
@@ -41,6 +41,7 @@
#include <sys/types.h>
#include <sys/mman.h>
+
#include <stdint.h>
#include <stdlib.h>
#include <nxflat.h>
@@ -48,7 +49,10 @@
#include <errno.h>
#include <arpa/inet.h>
-#include <nuttx/nxflat.h>
+
+#include <nuttx/binfmt/nxflat.h>
+
+#include "libnxflat.h"
/****************************************************************************
* Pre-Processor Definitions
@@ -62,24 +66,6 @@
* Private Constant Data
****************************************************************************/
-#if defined(CONFIG_DEBUG_VERBOSE) && defined(CONFIG_DEBUG_BINFMT)
-static const char g_relocrel32i[] = "RELOC_REL32I";
-static const char g_relocrel32d[] = "RELOC_REL32D";
-static const char g_relocabs32[] = "RELOC_AB32";
-static const char g_undefined[] = "UNDEFINED";
-
-static const char *g_reloctype[] =
-{
- g_relocrel32i,
- g_relocrel32d,
- g_relocabs32,
- g_undefined
-};
-# define RELONAME(rl) g_reloctype[NXFLAT_RELOC_TYPE(rl)]
-#else
-# define RELONAME(rl) "(no name)"
-#endif
-
/****************************************************************************
* Private Functions
****************************************************************************/
@@ -161,7 +147,7 @@ int nxflat_load(struct nxflat_loadinfo_s *loadinfo)
*/
loadinfo->ispace = (uint32_t)mmap(NULL, loadinfo->isize, PROT_READ,
- MAP_SHARED|MAP_FILE, loadinfo->filfd, 0);
+ MAP_SHARED|MAP_FILE, loadinfo->filfd, 0);
if (loadinfo->ispace == (uint32_t)MAP_FAILED)
{
bdbg("Failed to map NXFLAT ISpace: %d\n", errno);
@@ -170,23 +156,37 @@ int nxflat_load(struct nxflat_loadinfo_s *loadinfo)
bvdbg("Mapped ISpace (%d bytes) at %08x\n", loadinfo->isize, loadinfo->ispace);
- /* The following call will give a pointer to the allocated but
- * uninitialized ISpace memory.
+ /* The following call allocate D-Space memory and will provide a pointer
+ * to the allocated (but still uninitialized) D-Space memory.
*/
- loadinfo->dspace = (struct dspace_s *)malloc(SIZEOF_DSPACE_S(loadinfo->dsize));
- if (loadinfo->dspace == 0)
+ ret = nxflat_addrenv_alloc(loadinfo, loadinfo->dsize);
+ if (ret < 0)
{
- bdbg("Failed to allocate DSpace\n");
- ret = -ENOMEM;
- goto errout;
+ bdbg("ERROR: nxflat_addrenv_alloc() failed: %d\n", ret);
+ return ret;
}
- loadinfo->dspace->crefs = 1;
- bvdbg("Allocated DSpace (%d bytes) at %p\n", loadinfo->dsize, loadinfo->dspace->region);
+ bvdbg("Allocated DSpace (%d bytes) at %p\n",
+ loadinfo->dsize, loadinfo->dspace->region);
- /* Now, read the data into allocated DSpace at doffset into the
- * allocated DSpace memory.
+ /* If CONFIG_ADDRENV=y, then the D-Space allocation lies in an address
+ * environment that may not be in place. So, in that case, we must call
+ * nxflat_addrenv_select to temporarily instantiate that address space
+ * it can be initialized.
+ */
+
+#ifdef CONFIG_ADDRENV
+ ret = nxflat_addrenv_select(loadinfo);
+ if (ret < 0)
+ {
+ bdbg("ERROR: nxflat_addrenv_select() failed: %d\n", ret);
+ return ret;
+ }
+#endif
+
+ /* Now, read the data into allocated DSpace at doffset into the allocated
+ * DSpace memory.
*/
ret = nxflat_read(loadinfo, (char*)loadinfo->dspace->region, dreadsize, doffset);
@@ -199,9 +199,23 @@ int nxflat_load(struct nxflat_loadinfo_s *loadinfo)
bvdbg("TEXT: %08x Entry point offset: %08x Data offset: %08x\n",
loadinfo->ispace, loadinfo->entryoffs, doffset);
+ /* Restore the original address environment */
+
+#ifdef CONFIG_ADDRENV
+ ret = nxflat_addrenv_restore(loadinfo);
+ if (ret < 0)
+ {
+ bdbg("ERROR: nxflat_addrenv_restore() failed: %d\n", ret);
+ return ret;
+ }
+#endif
+
return OK;
errout:
+#ifdef CONFIG_ADDRENV
+ (void)nxflat_addrenv_restore(loadinfo);
+#endif
(void)nxflat_unload(loadinfo);
return ret;
}
diff --git a/nuttx/binfmt/libnxflat/libnxflat_read.c b/nuttx/binfmt/libnxflat/libnxflat_read.c
index dbcd54279..8deeb0805 100644
--- a/nuttx/binfmt/libnxflat/libnxflat_read.c
+++ b/nuttx/binfmt/libnxflat/libnxflat_read.c
@@ -48,7 +48,7 @@
#include <errno.h>
#include <arpa/inet.h>
-#include <nuttx/nxflat.h>
+#include <nuttx/binfmt/nxflat.h>
/****************************************************************************
* Pre-Processor Definitions
@@ -129,8 +129,9 @@ int nxflat_read(struct nxflat_loadinfo_s *loadinfo, char *buffer, int readsize,
rpos = lseek(loadinfo->filfd, offset, SEEK_SET);
if (rpos != offset)
{
- bdbg("Failed to seek to position %d: %d\n", offset, errno);
- return -errno;
+ int errval = errno;
+ bdbg("Failed to seek to position %d: %d\n", offset, errval);
+ return -errval;
}
/* Read the file data at offset into the user buffer */
@@ -138,10 +139,11 @@ int nxflat_read(struct nxflat_loadinfo_s *loadinfo, char *buffer, int readsize,
nbytes = read(loadinfo->filfd, bufptr, bytesleft);
if (nbytes < 0)
{
- if (errno != EINTR)
+ int errval = errno;
+ if (errval != EINTR)
{
- bdbg("Read of .data failed: %d\n", errno);
- return -errno;
+ bdbg("Read of .data failed: %d\n", errval);
+ return -errval;
}
}
else if (nbytes == 0)
diff --git a/nuttx/binfmt/libnxflat/libnxflat_uninit.c b/nuttx/binfmt/libnxflat/libnxflat_uninit.c
index 5d06296c7..b9715196b 100644
--- a/nuttx/binfmt/libnxflat/libnxflat_uninit.c
+++ b/nuttx/binfmt/libnxflat/libnxflat_uninit.c
@@ -42,7 +42,8 @@
#include <unistd.h>
#include <debug.h>
#include <errno.h>
-#include <nuttx/nxflat.h>
+
+#include <nuttx/binfmt/nxflat.h>
/****************************************************************************
* Pre-Processor Definitions
@@ -57,10 +58,6 @@
****************************************************************************/
/****************************************************************************
- * Name: nxflat_swap32
- ****************************************************************************/
-
-/****************************************************************************
* Public Functions
****************************************************************************/
diff --git a/nuttx/binfmt/libnxflat/libnxflat_unload.c b/nuttx/binfmt/libnxflat/libnxflat_unload.c
index 55a2e45e6..eb1aa0343 100644
--- a/nuttx/binfmt/libnxflat/libnxflat_unload.c
+++ b/nuttx/binfmt/libnxflat/libnxflat_unload.c
@@ -40,10 +40,14 @@
#include <nuttx/config.h>
#include <sys/mman.h>
+
#include <stdlib.h>
#include <debug.h>
-#include <nuttx/nxflat.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/binfmt/nxflat.h>
+
+#include "libnxflat.h"
/****************************************************************************
* Pre-Processor Definitions
@@ -65,8 +69,9 @@
* Name: nxflat_unload
*
* Description:
- * This function unloads the object from memory. This essentially
- * undoes the actions of nxflat_load.
+ * This function unloads the object from memory. This essentially undoes
+ * the actions of nxflat_load. It is called only under certain error
+ * conditions after the the module has been loaded but not yet started.
*
* Returned Value:
* 0 (OK) is returned on success and a negated errno is returned on
@@ -76,9 +81,8 @@
int nxflat_unload(struct nxflat_loadinfo_s *loadinfo)
{
- /* Reset the contents of the info structure. */
-
/* Release the memory segments */
+ /* Release the I-Space mmap'ed file */
if (loadinfo->ispace)
{
@@ -86,12 +90,8 @@ int nxflat_unload(struct nxflat_loadinfo_s *loadinfo)
loadinfo->ispace = 0;
}
- if (loadinfo->dspace)
- {
- free((void*)loadinfo->dspace);
- loadinfo->dspace = 0;
- }
+ /* Release the D-Space address environment */
+ nxflat_addrenv_free(loadinfo);
return OK;
}
-
diff --git a/nuttx/binfmt/libnxflat/libnxflat_verify.c b/nuttx/binfmt/libnxflat/libnxflat_verify.c
index f799aca4f..20af5d2f7 100644
--- a/nuttx/binfmt/libnxflat/libnxflat_verify.c
+++ b/nuttx/binfmt/libnxflat/libnxflat_verify.c
@@ -42,8 +42,9 @@
#include <string.h>
#include <debug.h>
#include <errno.h>
+
#include <arpa/inet.h>
-#include <nuttx/nxflat.h>
+#include <nuttx/binfmt/nxflat.h>
/****************************************************************************
* Pre-processor Definitions
@@ -91,10 +92,10 @@ int nxflat_verifyheader(const struct nxflat_hdr_s *header)
if (strncmp(header->h_magic, NXFLAT_MAGIC, 4) != 0)
{
bdbg("Unrecognized magic=\"%c%c%c%c\"\n",
- header->h_magic[0], header->h_magic[1],
- header->h_magic[2], header->h_magic[3]);
+ header->h_magic[0], header->h_magic[1],
+ header->h_magic[2], header->h_magic[3]);
return -ENOEXEC;
}
+
return OK;
}
-
diff --git a/nuttx/binfmt/nxflat.c b/nuttx/binfmt/nxflat.c
index 4f5869bd9..db29941ca 100644
--- a/nuttx/binfmt/nxflat.c
+++ b/nuttx/binfmt/nxflat.c
@@ -47,8 +47,8 @@
#include <errno.h>
#include <arpa/inet.h>
-#include <nuttx/binfmt.h>
-#include <nuttx/nxflat.h>
+#include <nuttx/binfmt/binfmt.h>
+#include <nuttx/binfmt/nxflat.h>
#ifdef CONFIG_NXFLAT
@@ -158,7 +158,7 @@ static int nxflat_loadbinary(struct binary_s *binp)
nxflat_dumploadinfo(&loadinfo);
if (ret != 0)
{
- bdbg("Failed to initialize for load of NXFLT program: %d\n", ret);
+ bdbg("Failed to initialize for load of NXFLAT program: %d\n", ret);
goto errout;
}
@@ -168,7 +168,7 @@ static int nxflat_loadbinary(struct binary_s *binp)
nxflat_dumploadinfo(&loadinfo);
if (ret != 0)
{
- bdbg("Failed to load NXFLT program binary: %d\n", ret);
+ bdbg("Failed to load NXFLAT program binary: %d\n", ret);
goto errout_with_init;
}
@@ -181,16 +181,39 @@ static int nxflat_loadbinary(struct binary_s *binp)
goto errout_with_load;
}
- /* Return the load information */
+ /* Return the load information. By convention, D-space address
+ * space is stored as the first allocated memory.
+ */
binp->entrypt = (main_t)(loadinfo.ispace + loadinfo.entryoffs);
- binp->ispace = (void*)loadinfo.ispace;
- binp->dspace = (void*)loadinfo.dspace;
- binp->isize = loadinfo.isize;
+ binp->mapped = (void*)loadinfo.ispace;
+ binp->mapsize = loadinfo.isize;
binp->stacksize = loadinfo.stacksize;
+ /* Add the ELF allocation to the alloc[] only if there is no address
+ * enironment. If there is an address environment, it will automatically
+ * be freed when the function exits
+ *
+ * REVISIT: If the module is loaded then unloaded, wouldn't this cause
+ * a memory leak?
+ */
+
+#ifdef CONFIG_ADDRENV
+# warning "REVISIT"
+#else
+ binp->alloc[0] = (void*)loadinfo.dspace;
+#endif
+
+#ifdef CONFIG_ADDRENV
+ /* Save the address environment. This will be needed when the module is
+ * executed for the up_addrenv_assign() call.
+ */
+
+ binp->addrenv = loadinfo.addrenv;
+#endif
+
nxflat_dumpbuffer("Entry code", (FAR const uint8_t*)binp->entrypt,
- MIN(binp->isize - loadinfo.entryoffs,512));
+ MIN(loadinfo.isize - loadinfo.entryoffs, 512));
nxflat_uninit(&loadinfo);
return OK;
diff --git a/nuttx/binfmt/symtab_findbyname.c b/nuttx/binfmt/symtab_findbyname.c
index 201d7ba07..c0343e270 100644
--- a/nuttx/binfmt/symtab_findbyname.c
+++ b/nuttx/binfmt/symtab_findbyname.c
@@ -44,7 +44,7 @@
#include <assert.h>
#include <errno.h>
-#include <nuttx/symtab.h>
+#include <nuttx/binfmt/symtab.h>
/****************************************************************************
* Pre-processor Definitions
diff --git a/nuttx/binfmt/symtab_findbyvalue.c b/nuttx/binfmt/symtab_findbyvalue.c
index 4382ed5d8..c47d5c751 100644
--- a/nuttx/binfmt/symtab_findbyvalue.c
+++ b/nuttx/binfmt/symtab_findbyvalue.c
@@ -44,7 +44,7 @@
#include <assert.h>
#include <errno.h>
-#include <nuttx/symtab.h>
+#include <nuttx/binfmt/symtab.h>
/****************************************************************************
* Pre-processor Definitions
diff --git a/nuttx/binfmt/symtab_findorderedbyname.c b/nuttx/binfmt/symtab_findorderedbyname.c
index 61decf49a..a678788e7 100644
--- a/nuttx/binfmt/symtab_findorderedbyname.c
+++ b/nuttx/binfmt/symtab_findorderedbyname.c
@@ -44,7 +44,7 @@
#include <assert.h>
#include <errno.h>
-#include <nuttx/symtab.h>
+#include <nuttx/binfmt/symtab.h>
/****************************************************************************
* Pre-processor Definitions
diff --git a/nuttx/binfmt/symtab_findorderedbyvalue.c b/nuttx/binfmt/symtab_findorderedbyvalue.c
index 92b107856..bad4bf8cd 100644
--- a/nuttx/binfmt/symtab_findorderedbyvalue.c
+++ b/nuttx/binfmt/symtab_findorderedbyvalue.c
@@ -44,7 +44,7 @@
#include <assert.h>
#include <errno.h>
-#include <nuttx/symtab.h>
+#include <nuttx/binfmt/symtab.h>
/****************************************************************************
* Pre-processor Definitions
diff --git a/nuttx/configs/README.txt b/nuttx/configs/README.txt
index e6bde645d..21aace2af 100644
--- a/nuttx/configs/README.txt
+++ b/nuttx/configs/README.txt
@@ -103,14 +103,23 @@ Make.defs -- This makefile fragment provides architecture and
Tools: CC, LD, AR, NM, OBJCOPY, OBJDUMP
Tool options: CFLAGS, LDFLAGS
- COMPILE, ASSEMBLE, ARCHIVE, CLEAN, and MKDEP macros
When this makefile fragment runs, it will be passed TOPDIR which
is the path to the root directory of the build. This makefile
- fragment may include ${TOPDIR}/.config to perform configuration
- specific settings. For example, the CFLAGS will most likely be
+ fragment should include:
+
+ $(TOPDIR)/.config : Nuttx configuration
+ $(TOPDIR)/tools/Config.mk : Common definitions
+
+ Definitions in the Make.defs file probably depend on some of the
+ settings in the .config file. For example, the CFLAGS will most likely be
different if CONFIG_DEBUG=y.
+ The included tools/Config.mk file contains additional definitions that may
+ be overriden in the architecture-specific Make.defs file as necessary:
+
+ COMPILE, ASSEMBLE, ARCHIVE, CLEAN, and MKDEP macros
+
defconfig -- This is a configuration file similar to the Linux
configuration file. In contains variable/value pairs like:
@@ -151,6 +160,9 @@ defconfig -- This is a configuration file similar to the Linux
CONFIG_ARCH_IRQPRIO
Define if the architecture suports prioritizaton of interrupts
and the up_prioritize_irq() API.
+ CONFIG_ADDRENV
+ The CPU supports an MMU and CPU port supports provision of address
+ environments for tasks (making the, perhaps, processes).
Some architectures require a description of the RAM configuration:
@@ -171,7 +183,6 @@ defconfig -- This is a configuration file similar to the Linux
CONFIG_RAW_BINARY - make a raw binary format file used with many
different loaders using the GNU objcopy program. This option
should not be selected if you are not using the GNU toolchain.
- CONFIG_HAVE_LIBM - toolchain supports libm.a
CONFIG_HAVE_CXX - toolchain supports C++ and CXX, CXXFLAGS, and
COMPILEXX have been defined in the configurations Make.defs
file.
@@ -318,7 +329,7 @@ defconfig -- This is a configuration file similar to the Linux
CONFIG_RR_INTERVAL - The round robin timeslice will be set
this number of milliseconds; Round robin scheduling can
be disabled by setting this value to zero.
- CONFIG_SCHED_INSTRUMENTATION - enables instrumentation in
+ CONFIG_SCHED_INSTRUMENTATION - enables instrumentation in
scheduler to monitor system performance
CONFIG_TASK_NAME_SIZE - Specifies that maximum size of a
task name to save in the TCB. Useful if scheduler
@@ -346,7 +357,7 @@ defconfig -- This is a configuration file similar to the Linux
CONFIG_SEM_PREALLOCHOLDERS: This setting is only used if priority
inheritance is enabled. It defines the maximum number of
different threads (minus one) that can take counts on a
- semaphore with priority inheritance support. This may be
+ semaphore with priority inheritance support. This may be
set to zero if priority inheritance is disabled OR if you
are only using semaphores as mutexes (only one holder) OR
if no more than two threads participate using a counting
@@ -372,9 +383,6 @@ defconfig -- This is a configuration file similar to the Linux
CONFIG_SDCLONE_DISABLE. Disable cloning of all socket
desciptors by task_create() when a new task is started. If
set, all sockets will appear to be closed in the new task.
- CONFIG_NXFLAT. Enable support for the NXFLAT binary format.
- This format will support execution of NuttX binaries located
- in a ROMFS filesystem (see examples/nxflat).
CONFIG_SCHED_WORKQUEUE. Create a dedicated "worker" thread to
handle delayed processing from interrupt handlers. This feature
is required for some drivers but, if there are not complaints,
@@ -418,6 +426,39 @@ defconfig -- This is a configuration file similar to the Linux
where 'app' is the application name. If not defined, CONFIG_USER_ENTRYPOINT
defaults to user_start.
+ Binary Loaders:
+ CONFIG_BINFMT_DISABLE - By default, support for loadable binary formats
+ is built.
+ This logic may be suppressed be defining this setting.
+ CONFIG_BINFMT_CONSTRUCTORS - Build in support for C++ constructors in
+ loaded modules.
+ CONFIG_SYMTAB_ORDEREDBYNAME - Symbol tables are order by name (rather
+ than value).
+ CONFIG_NXFLAT. Enable support for the NXFLAT binary format. This format
+ will support execution of NuttX binaries located in a ROMFS filesystem
+ (see apps/examples/nxflat).
+ CONFIG_ELF - Enable support for the ELF binary format. This format will
+ support execution of ELF binaries copied from a file system and
+ relocated into RAM (see apps/examples/elf).
+
+ If CONFIG_ELF is selected, then these additional options are available:
+
+ CONFIG_ELF_ALIGN_LOG2 - Align all sections to this Log2 value: 0->1,
+ 1->2, 2->4, etc.
+ CONFIG_ELF_STACKSIZE - This is the default stack size that will will
+ be used when starting ELF binaries.
+ CONFIG_ELF_BUFFERSIZE - This is an I/O buffer that is used to access
+ the ELF file. Variable length items will need to be read (such as
+ symbol names). This is really just this initial size of the buffer;
+ it will be reallocated as necessary to hold large symbol names).
+ Default: 128
+ CONFIG_ELF_BUFFERINCR - This is an I/O buffer that is used to access
+ the ELF file. Variable length items will need to be read (such as
+ symbol names). This value specifies the size increment to use each
+ time the buffer is reallocated. Default: 32
+ CONFIG_ELF_DUMPBUFFER - Dump various ELF buffers for debug purposes.
+ This option requires CONFIG_DEBUG and CONFIG_DEBUG_VERBOSE.
+
System Logging:
CONFIG_SYSLOG enables general system logging support.
CONFIG_SYSLOG_DEVPATH - The full path to the system logging device. Default
@@ -503,7 +544,7 @@ defconfig -- This is a configuration file similar to the Linux
from the end of RAM for page tables or other system usage. The
configuration settings and linker directives must be cognizant of that:
CONFIG_PAGING_NDATA should be defined to prevent the data region from
- extending all the way to the end of memory.
+ extending all the way to the end of memory.
CONFIG_PAGING_DEFPRIO - The default, minimum priority of the page fill
worker thread. The priority of the page fill work thread will be boosted
boosted dynmically so that it matches the priority of the task on behalf
@@ -517,7 +558,7 @@ defconfig -- This is a configuration file similar to the Linux
transfer is completed. Default: Undefined (non-blocking).
CONFIG_PAGING_WORKPERIOD - The page fill worker thread will wake periodically
even if there is no mapping to do. This selection controls that wake-up
- period (in microseconds). This wake-up a failsafe that will handle any
+ period (in microseconds). This wake-up a failsafe that will handle any
cases where a single is lost (that would really be a bug and shouldn't
happen!) and also supports timeouts for case of non-blocking, asynchronous
fills (see CONFIG_PAGING_TIMEOUT_TICKS).
@@ -529,7 +570,7 @@ defconfig -- This is a configuration file similar to the Linux
Some architecture-specific settings. Defaults are architecture specific.
If you don't know what you are doing, it is best to leave these undefined
and try the system defaults:
-
+
CONFIG_PAGING_VECPPAGE - This the physical address of the page in
memory to be mapped to the vector address.
CONFIG_PAGING_VECL2PADDR - This is the physical address of the L2
@@ -552,7 +593,7 @@ defconfig -- This is a configuration file similar to the Linux
devices. CONFIG_PAGING_SDSLOT identifies the slot number of the SD
device to initialize. This must be undefined if SD is not being used.
This should be defined to be zero for the typical device that has
- only a single slot (See CONFIG_MMCSD_NSLOTS). If defined,
+ only a single slot (See CONFIG_MMCSD_NSLOTS). If defined,
CONFIG_PAGING_SDSLOT will instruct certain board-specific logic to
initialize the media in this SD slot.
CONFIG_PAGING_M25PX - Use the m25px.c FLASH driver. If this is selected,
@@ -621,6 +662,37 @@ defconfig -- This is a configuration file similar to the Linux
CONFIG_ARCH_STRNCPY, CONFIG_ARCH_STRLEN, CONFIG_ARCH_STRNLEN
CONFIG_ARCH_BZERO
+ If CONFIG_ARCH_MEMCPY is not selected, then you make also select Daniel
+ Vik's optimized implementation of memcpy():
+
+ CONFIG_MEMCPY_VIK - Select this option to use the optimized memcpy()
+ function by Daniel Vik. Select this option for improved performance
+ at the expense of increased size. See licensing information in the
+ top-level COPYING file. Default: n
+
+ And if CONFIG_MEMCPY_VIK is selected, the following tuning options are available:
+
+ CONFIG_MEMCPY_PRE_INC_PTRS - Use pre-increment of pointers. Default is
+ post increment of pointers.
+
+ CONFIG_MEMCPY_INDEXED_COPY - Copying data using array indexing. Using
+ this option, disables the CONFIG_MEMCPY_PRE_INC_PTRS option.
+
+ CONFIG_MEMCPY_64BIT - Compiles memcpy for architectures that suppport
+ 64-bit operations efficiently.
+
+ If CONFIG_ARCH_MEMSET is not selected, then the following option is
+ also available:
+
+ CONFIG_MEMSET_OPTSPEED - Select this option to use a version of memcpy()
+ optimized for speed. Default: memcpy() is optimized for size.
+
+ And if CONFIG_MEMSET_OPTSPEED is selected, the following tuning option is
+ available:
+
+ CONFIG_MEMSET_64BIT - Compiles memset() for architectures that suppport
+ 64-bit operations efficiently.
+
The architecture may provide custom versions of certain standard header
files:
@@ -663,6 +735,15 @@ defconfig -- This is a configuration file similar to the Linux
don't select CONFIG_ARCH_MATH_H, the redirecting math.h header file will
stay out-of-the-way in include/nuttx/.
+ CONFIG_ARCH_FLOAT_H
+ If you enable the generic, built-in math library, then that math library
+ will expect your toolchain to provide the standard float.h header file.
+ The float.h header file defines the properties of your floating point
+ implementation. It would always be best to use your toolchain's float.h
+ header file but if none is avaiable, a default float.h header file will
+ provided if this option is selected. However, there is no assurance that
+ the settings in this float.h are actually correct for your platform!
+
CONFIG_ARCH_STDARG_H - There is also a redirecting version of stdarg.h in
the source tree as well. It also resides out-of-the-way at include/nuttx/stdarg.h.
This is because you should normally use your toolchain's stdarg.h file. But
@@ -693,7 +774,7 @@ defconfig -- This is a configuration file similar to the Linux
If CONFIG_ARCH_ROMGETC is defined, then the architecture logic
must export the function up_romgetc(). up_romgetc() will simply
read one byte of data from the instruction space.
-
+
If CONFIG_ARCH_ROMGETC, certain C stdio functions are effected:
(1) All format strings in printf, fprintf, sprintf, etc. are
assumed to lie in FLASH (string arguments for %s are still assumed
@@ -763,7 +844,7 @@ defconfig -- This is a configuration file similar to the Linux
much sense in supporting FAT date and time unless you have a
hardware RTC or other way to get the time and date.
CONFIG_FS_NXFFS: Enable NuttX FLASH file system (NXFF) support.
- CONFIG_NXFFS_ERASEDSTATE: The erased state of FLASH.
+ CONFIG_NXFFS_ERASEDSTATE: The erased state of FLASH.
This must have one of the values of 0xff or 0x00.
Default: 0xff.
CONFIG_NXFFS_PACKTHRESHOLD: When packing flash file data,
@@ -917,7 +998,7 @@ defconfig -- This is a configuration file similar to the Linux
CONFIG_INPUT
Enables general support for input devices
-
+
CONFIG_INPUT_TSC2007
If CONFIG_INPUT is selected, then this setting will enable building
of the TI TSC2007 touchscreen driver.
@@ -932,14 +1013,14 @@ defconfig -- This is a configuration file similar to the Linux
Enables support for the SPI interface (not currenly supported)
CONFIG_STMPE811_I2C
Enables support for the I2C interface
- CONFIG_STMPE811_MULTIPLE
+ CONFIG_STMPE811_MULTIPLE
Can be defined to support multiple STMPE811 devices on board.
CONFIG_STMPE811_ACTIVELOW
Interrupt is generated by an active low signal (or falling edge).
CONFIG_STMPE811_EDGE
Interrupt is generated on an edge (vs. on the active level)
CONFIG_STMPE811_NPOLLWAITERS
- Maximum number of threads that can be waiting on poll() (ignored if
+ Maximum number of threads that can be waiting on poll() (ignored if
CONFIG_DISABLE_POLL is set).
CONFIG_STMPE811_TSC_DISABLE
Disable driver touchscreen functionality.
@@ -1048,21 +1129,21 @@ defconfig -- This is a configuration file similar to the Linux
port. The default data link layer for uIP is Ethernet. If CONFIG_NET_SLIP
is defined in the NuttX configuration file, then SLIP will be supported.
The basic differences between the SLIP and Ethernet configurations is that
- when SLIP is selected:
+ when SLIP is selected:
- * The link level header (that comes before the IP header) is omitted.
- * All MAC address processing is suppressed.
+ * The link level header (that comes before the IP header) is omitted.
+ * All MAC address processing is suppressed.
* ARP is disabled.
If CONFIG_NET_SLIP is not selected, then Ethernet will be used (there is
no need to define anything special in the configuration file to use
- Ethernet -- it is the default).
+ Ethernet -- it is the default).
CONFIG_NET_SLIP -- Enables building of the SLIP driver. SLIP requires
at least one IP protocols selected and the following additional
network settings: CONFIG_NET_NOINTS and CONFIG_NET_MULTIBUFFER.
CONFIG_NET_BUFSIZE *must* be set to 296. Other optional configuration
- settings that affect the SLIP driver: CONFIG_NET_STATISTICS.
+ settings that affect the SLIP driver: CONFIG_NET_STATISTICS.
Default: Ethernet
If SLIP is selected, then the following SLIP options are available:
@@ -1078,6 +1159,10 @@ defconfig -- This is a configuration file similar to the Linux
CONFIG_NET_DHCP_LIGHT - Reduces size of DHCP
CONFIG_NET_RESOLV_ENTRIES - Number of resolver entries
+ CONFIG_NET_RESOLV_MAXRESPONSE - This setting determines the maximum
+ size of response message that can be received by the DNS resolver.
+ The default is 96 but may need to be larger on enterprise networks
+ (perhaps 176).
THTTPD
@@ -1099,7 +1184,7 @@ defconfig -- This is a configuration file similar to the Linux
to run before killing them.
CONFIG_THTTPD_CHARSET- The default character set name to use with
text MIME types.
- CONFIG_THTTPD_IOBUFFERSIZE -
+ CONFIG_THTTPD_IOBUFFERSIZE -
CONFIG_THTTPD_INDEX_NAMES - A list of index filenames to check. The
files are searched for in this order.
CONFIG_AUTH_FILE - The file to use for authentication. If this is
@@ -1131,7 +1216,7 @@ defconfig -- This is a configuration file similar to the Linux
You can also leave both options undefined, and thttpd will not do
anything special about tildes. Enabling both options is an error.
Typical values, if they're defined, are "users" for
- CONFIG_THTTPD_TILDE_MAP1 and "public_html"forCONFIG_THTTPD_TILDE_MAP2.
+ CONFIG_THTTPD_TILDE_MAP1 and "public_html"forCONFIG_THTTPD_TILDE_MAP2.
CONFIG_THTTPD_GENERATE_INDICES
CONFIG_THTTPD_URLPATTERN - If defined, then it will be used to match
and verify referrers.
@@ -1189,7 +1274,7 @@ defconfig -- This is a configuration file similar to the Linux
USB host HID class driver. Requires CONFIG_USBHOST=y,
CONFIG_USBHOST_INT_DISABLE=n, CONFIG_NFILE_DESCRIPTORS > 0,
CONFIG_SCHED_WORKQUEUE=y, and CONFIG_DISABLE_SIGNALS=n.
-
+
CONFIG_HIDKBD_POLLUSEC
Device poll rate in microseconds. Default: 100 milliseconds.
CONFIG_HIDKBD_DEFPRIO
@@ -1208,7 +1293,7 @@ defconfig -- This is a configuration file similar to the Linux
If set to y all 231 possible scancodes will be converted to
something. Default: 104 key US keyboard.
CONFIG_HIDKBD_NODEBOUNCE
- If set to y normal debouncing is disabled. Default:
+ If set to y normal debouncing is disabled. Default:
Debounce enabled (No repeat keys).
USB host mass storage class driver. Requires CONFIG_USBHOST=y,
@@ -1245,12 +1330,12 @@ defconfig -- This is a configuration file similar to the Linux
Configure the CDC serial driver as part of a composite driver
(only if CONFIG_USBDEV_COMPOSITE is also defined)
CONFIG_CDCACM_IFNOBASE
- If the CDC driver is part of a composite device, then this may need to
+ If the CDC driver is part of a composite device, then this may need to
be defined to offset the CDC/ACM interface numbers so that they are
unique and contiguous. When used with the Mass Storage driver, the
correct value for this offset is zero.
CONFIG_CDCACM_STRBASE
- If the CDC driver is part of a composite device, then this may need to
+ If the CDC driver is part of a composite device, then this may need to
be defined to offset the CDC/ACM string numbers so that they are
unique and contiguous. When used with the Mass Storage driver, the
correct value for this offset is four (this value actuallly only needs
@@ -1309,13 +1394,13 @@ defconfig -- This is a configuration file similar to the Linux
Configure the mass storage driver as part of a composite driver
(only if CONFIG_USBDEV_COMPOSITE is also defined)
CONFIG_USBMSC_IFNOBASE
- If the CDC driver is part of a composite device, then this may need to
+ If the CDC driver is part of a composite device, then this may need to
be defined to offset the mass storage interface number so that it is
unique and contiguous. When used with the CDC/ACM driver, the
correct value for this offset is two (because of the two CDC/ACM
interfaces that will precede it).
CONFIG_USBMSC_STRBASE
- If the CDC driver is part of a composite device, then this may need to
+ If the CDC driver is part of a composite device, then this may need to
be defined to offset the mass storage string numbers so that they are
unique and contiguous. When used with the CDC/ACM driver, the
correct value for this offset is four (or perhaps 5 or 6, depending
@@ -1523,10 +1608,15 @@ configs/avr32dev1
configs/c5471evm
This is a port to the Spectrum Digital C5471 evaluation board. The
TMS320C5471 is a dual core processor from TI with an ARM7TDMI general
- purpose processor and a c54 DSP. It is also known as TMS320DA180 or just DA180.
+ purpose processor and a c54 DSP. It is also known as TMS320DA180 or just DA180.
NuttX runs on the ARM core and is built with a GNU arm-nuttx-elf toolchain*.
This port is complete and verified.
+configs/cloudctrl
+ Darcy's CloudController board. This is a small network relay development
+ board. Based on the Shenzhou IV development board design. It is based on
+ the STM32F107VC MCU.
+
configs/compal_e88 and compal_e99
These directories contain the board support for compal e88 and e99 phones.
These ports are based on patches contributed by Denis Carikli for both the
@@ -1539,23 +1629,23 @@ configs/demo9s12ne64
is code complete but has not yet been verified.
configs/ea3131
- Embedded Artists EA3131 Development board. This board is based on the
+ Embedded Artists EA3131 Development board. This board is based on the
an NXP LPC3131 MCU. This OS is built with the arm-nuttx-elf toolchain*.
STATUS: This port is complete and mature.
configs/ea3152
- Embedded Artists EA3152 Development board. This board is based on the
+ Embedded Artists EA3152 Development board. This board is based on the
an NXP LPC3152 MCU. This OS is built with the arm-nuttx-elf toolchain*.
STATUS: This port is has not be exercised well, but since it is
a simple derivative of the ea3131, it should be fully functional.
configs/eagle100
- Micromint Eagle-100 Development board. This board is based on the
+ Micromint Eagle-100 Development board. This board is based on the
an ARM Cortex-M3 MCU, the Luminary LM3S6918. This OS is built with the
arm-nuttx-elf toolchain*. STATUS: This port is complete and mature.
configs/ekk-lm3s9b96
- TI/Stellaris EKK-LM3S9B96 board. This board is based on the
+ TI/Stellaris EKK-LM3S9B96 board. This board is based on the
an EKK-LM3S9B96 which is a Cortex-M3.
configs/ez80f0910200kitg
@@ -1583,13 +1673,13 @@ configs/kwikstik-k40.
configs/lincoln60
NuttX port to the Micromint Lincoln 60 board.
-
+
configs/lm3s6432-s2e
Stellaris RDK-S2E Reference Design Kit and the MDL-S2E Ethernet to
Serial module.
configs/lm3s6965-ek
- Stellaris LM3S6965 Evaluation Kit. This board is based on the
+ Stellaris LM3S6965 Evaluation Kit. This board is based on the
an ARM Cortex-M3 MCU, the Luminary/TI LM3S6965. This OS is built with the
arm-nuttx-elf toolchain*. STATUS: This port is complete and mature.
@@ -1646,7 +1736,7 @@ configs/ntosd-dm320
toolchain*: see
http://wiki.neurostechnology.com/index.php/OSD_1.0_Developer_Home
-
+
There are some differences between the Dev Board and the currently
available commercial v1.0 Boards. See
@@ -1690,33 +1780,53 @@ configs/pcblogic-pic32mx
STATUS: Code complete but testing has been stalled due to tool related problems
(PICkit 2 does not work with the PIC32).
-configs/pic32-starterkit
+configs/p112
+ The P112 is notable because it was the first of the hobbyist single board
+ computers to reach the production stage. The P112 hobbyist computers
+ were relatively widespread and inspired other hobbyist centered home brew
+ computing projects such as N8VEM home brew computing project. The P112
+ project still maintains many devoted enthusiasts and has an online
+ repository of software and other information.
+
+ The P112 computer originated as a commercial product of "D-X Designs Pty
+ Ltd" of Australia. They describe the computer as "The P112 is a stand-alone
+ 8-bit CPU board. Typically running CP/M (tm) or a similar operating system,
+ it provides a Z80182 (Z-80 upgrade) CPU with up to 1MB of memory, serial,
+ parallel and diskette IO, and realtime clock, in a 3.5-inch drive form factor.
+ Powered solely from 5V, it draws 150mA (nominal: not including disk drives)
+ with a 16MHz CPU clock. Clock speeds up to 24.576MHz are possible."
+
+ The P112 board was last available new in 1996 by Dave Brooks. In late 2004
+ on the Usenet Newsgroup comp.os.cpm, talk about making another run of P112
+ boards was discussed. David Griffith decided to produce additional P112 kits
+ with Dave Brooks blessing and the assistance of others. In addition Terry
+ Gulczynski makes additional P112 derivative hobbyist home brew computers.
+ Hal Bower was very active in the mid 1990's on the P112 project and ported
+ the "Banked/Portable BIOS".
+
+ Dave Brooks was successfully funded through Kickstarter for and another
+ run of P112 boards in November of 2012.
+configs/pic32-starterkit
This directory contains the port of NuttX to the Microchip PIC32 Ethernet
Starter Kit (DM320004) with the Multimedia Expansion Board (MEB, DM320005).
See www.microchip.com for further information.
configs/pic32mx7mmb
-
This directory will (eventually) contain the port of NuttX to the
Mikroelektronika PIC32MX7 Multimedia Board (MMB). See
http://www.mikroe.com/ for further information.
- STATUS: Basic OS test configuration is in place, but the board does not boot.
- It looks like I will need an ICD3 in order to debug the code (PICkit3
- doesn't work for debug with this board). This effort is temporarily stalled.
-
configs/pjrc-8051
8051 Microcontroller. This port uses the PJRC 87C52 development system
and the SDCC toolchain. This port is not quite ready for prime time.
configs/qemu-i486
-
Port of NuttX to QEMU in i486 mode. This port will also run on real i486
hardwared (Google the Bifferboard).
configs/rgmp
- RGMP stands for RTOS and GPOS on Multi-Processor. RGMP is a project for
+ RGMP stands for RTOS and GPOS on Multi-Processor. RGMP is a project for
running GPOS and RTOS simultaneously on multi-processor platforms. You can
port your favorite RTOS to RGMP together with an unmodified Linux to form a
hybrid operating system. This makes your application able to use both RTOS
@@ -1757,8 +1867,14 @@ configs/stm3240g-eval
microcontroller (ARM Cortex-M4 with FPU). This port uses a GNU Cortex-M4
toolchain (such as CodeSourcery).
+configs/stm32f100rc_generic
+ STMicro STM32F100RC generic board based on STM32F100RC high-density value line
+ chip. This "generic" configuration is not very usable out-of-box, but can be
+ used as a starting point to creating new configs with similar STM32
+ high-density value line chips.
+
configs/stm32f4discovery
- STMicro STM32F4-Discovery board boased on the STMIcro STM32F407VGT6 MCU.
+ STMicro STM32F4-Discovery board based on the STMIcro STM32F407VGT6 MCU.
configs/sure-pic32mx
The "Advanced USB Storage Demo Board," Model DB-DP11215, from Sure
@@ -1795,7 +1911,7 @@ configs/vsn
configs/xtrs
TRS80 Model 3. This port uses a vintage computer based on the Z80.
- An emulator for this computer is available to run TRS80 programs on a
+ An emulator for this computer is available to run TRS80 programs on a
linux platform (http://www.tim-mann.org/xtrs.html).
configs/z16f2800100zcog
@@ -1846,7 +1962,7 @@ And if configs/<board-name>/<config-dir>/appconfig exists and your
application directory is not in the standard loction (../apps), then
you should also specify the location of the application directory on the
command line like:
-
+
cd tools
./configure.sh -a <app-dir> <board-name>/<config-dir>
diff --git a/nuttx/configs/px4fmu/common/Make.defs b/nuttx/configs/px4fmu/common/Make.defs
index 3d2df6314..52c00cd5a 100644
--- a/nuttx/configs/px4fmu/common/Make.defs
+++ b/nuttx/configs/px4fmu/common/Make.defs
@@ -39,12 +39,15 @@
# Make.defs in the per-config directories.
#
+include ${TOPDIR}/tools/Config.mk
+
#
# We only support building with the ARM bare-metal toolchain from
# https://launchpad.net/gcc-arm-embedded on Windows, Linux or Mac OS.
#
+CONFIG_ARMV7M_TOOLCHAIN := GNU_EABI
-CROSSDEV = arm-none-eabi-
+include ${TOPDIR}/arch/arm/src/armv7-m/Toolchain.defs
CC = $(CROSSDEV)gcc
CXX = $(CROSSDEV)g++
@@ -167,39 +170,11 @@ OBJEXT = .o
LIBEXT = .a
EXEEXT =
-define PREPROCESS
- @echo "CPP: $1->$2"
- @$(CPP) $(CPPFLAGS) $(abspath $1) -o $2
-endef
-
-define COMPILE
- @echo "CC: $1"
- $(Q)$(CC) -c $(CFLAGS) $(abspath $1) -o $2
-endef
-
-define COMPILEXX
- @echo "CXX: $1"
- $(Q)$(CXX) -c $(CXXFLAGS) $(abspath $1) -o $2
-endef
-
-define ASSEMBLE
- @echo "AS: $1"
- $(Q)$(CC) -c $(AFLAGS) $(abspath $1) -o $2
-endef
# produce partially-linked $1 from files in $2
define PRELINK
@echo "PRELINK: $1"
- @$(LD) -Ur -o $1 $2 && $(OBJCOPY) --localize-hidden $1
-endef
-
-define ARCHIVE
- echo "AR: $2"; \
- $(AR) $1 $2 || { echo "$(AR) $1 $2 FAILED!" ; exit 1 ; }
-endef
-
-define CLEAN
- @rm -f *.o *.a
+ $(Q) $(LD) -Ur -o $1 $2 && $(OBJCOPY) --localize-hidden $1
endef
HOSTCC = gcc
diff --git a/nuttx/configs/px4fmu/nsh/defconfig b/nuttx/configs/px4fmu/nsh/defconfig
index 52013457e..8a76f0e05 100755
--- a/nuttx/configs/px4fmu/nsh/defconfig
+++ b/nuttx/configs/px4fmu/nsh/defconfig
@@ -200,6 +200,10 @@ CONFIG_STM32_TIM9=y
CONFIG_STM32_TIM10=y
CONFIG_STM32_TIM11=y
+#
+# We want the flash prefetch on for max performance.
+#
+STM32_FLASH_PREFETCH=y
#
# Enable the MTD driver for the onboard I2C EEPROM
@@ -348,9 +352,10 @@ CONFIG_CAN2_BAUD=700000
# I2C configuration
#
CONFIG_I2C=y
-CONFIG_I2C_POLLED=y
+#CONFIG_I2C_POLLED=y
CONFIG_I2C_TRANSFER=y
CONFIG_I2C_TRACE=n
+CONFIG_I2C_RESET=y
# Allow 180 us per byte, a wide margin for the 400 KHz clock we're using
# e.g. 9.6 ms for an EEPROM page write, 0.9 ms for a MAG update
CONFIG_STM32_I2CTIMEOUS_PER_BYTE=200
@@ -747,6 +752,8 @@ CONFIG_FS_ROMFS=y
# CONFIG_MMCSD_SPICLOCK - Maximum SPI clock to drive MMC/SD card.
# Default is 20MHz, current setting 24 MHz
#
+CONFIG_MMCSD=y
+CONFIG_MMCSD_SPI=y
CONFIG_MMCSD_NSLOTS=1
CONFIG_MMCSD_READONLY=n
CONFIG_MMCSD_SPICLOCK=24000000
diff --git a/nuttx/configs/px4fmu/src/Makefile b/nuttx/configs/px4fmu/src/Makefile
index c3d6bf543..d4276f7fc 100644
--- a/nuttx/configs/px4fmu/src/Makefile
+++ b/nuttx/configs/px4fmu/src/Makefile
@@ -64,23 +64,21 @@ $(COBJS) $(LINKOBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
libboard$(LIBEXT): $(OBJS)
- @( for obj in $(OBJS) ; do \
- $(call ARCHIVE, $@, $${obj}); \
- done ; )
- touch $@
+ $(call ARCHIVE, $@, $(OBJS))
.depend: Makefile $(SRCS)
- @$(MKDEP) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
- @touch $@
+ $(Q) $(MKDEP) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
+ $(Q) touch $@
depend: .depend
clean:
- @rm -f libboard$(LIBEXT) *~ .*.swp
+ $(call DELFILE, libboard$(LIBEXT))
$(call CLEAN)
distclean: clean
- @rm -f Make.dep .depend
+ $(call DELFILE, Make.dep)
+ $(call DELFILE, .depend)
-include Make.dep
diff --git a/nuttx/configs/px4io/common/Make.defs b/nuttx/configs/px4io/common/Make.defs
index a3996a9ed..d6d52e3d2 100644
--- a/nuttx/configs/px4io/common/Make.defs
+++ b/nuttx/configs/px4io/common/Make.defs
@@ -39,12 +39,15 @@
# Make.defs in the per-config directories.
#
+include ${TOPDIR}/tools/Config.mk
+
#
# We only support building with the ARM bare-metal toolchain from
# https://launchpad.net/gcc-arm-embedded on Windows, Linux or Mac OS.
#
+CONFIG_ARMV7M_TOOLCHAIN := GNU_EABI
-CROSSDEV = arm-none-eabi-
+include ${TOPDIR}/arch/arm/src/armv7-m/Toolchain.defs
CC = $(CROSSDEV)gcc
CXX = $(CROSSDEV)g++
@@ -160,46 +163,10 @@ OBJEXT = .o
LIBEXT = .a
EXEEXT =
-# If VERBOSE is set, don't hide the compiler invocations.
-ifeq ($(VERBOSE),YES)
-_v =
-else
-_v = @
-endif
-
-define PREPROCESS
- @echo "CPP: $1->$2"
- @$(CPP) $(CPPFLAGS) $(abspath $1) -o $2
-endef
-
-define COMPILE
- @echo "CC: $1"
- $(_v)$(CC) -c $(CFLAGS) $(abspath $1) -o $2
-endef
-
-define COMPILEXX
- @echo "CXX: $1"
- $(_v)$(CXX) -c $(CXXFLAGS) $(abspath $1) -o $2
-endef
-
-define ASSEMBLE
- @echo "AS: $1"
- $(_v)$(CC) -c $(AFLAGS) $(abspath $1) -o $2
-endef
-
# produce partially-linked $1 from files in $2
define PRELINK
@echo "PRELINK: $1"
- @$(LD) -Ur -o $1 $2 && $(OBJCOPY) --localize-hidden $1
-endef
-
-define ARCHIVE
- echo "AR: $2"; \
- $(AR) $1 $2 || { echo "$(AR) $1 $2 FAILED!" ; exit 1 ; }
-endef
-
-define CLEAN
- @rm -f *.o *.a
+ $(Q) $(LD) -Ur -o $1 $2 && $(OBJCOPY) --localize-hidden $1
endef
HOSTCC = gcc
diff --git a/nuttx/configs/px4io/src/Makefile b/nuttx/configs/px4io/src/Makefile
index 144fa8549..bb9539d16 100644
--- a/nuttx/configs/px4io/src/Makefile
+++ b/nuttx/configs/px4io/src/Makefile
@@ -65,9 +65,7 @@ $(COBJS) $(LINKOBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
libboard$(LIBEXT): $(OBJS)
- @( for obj in $(OBJS) ; do \
- $(call ARCHIVE, $@, $${obj}); \
- done ; )
+ $(call ARCHIVE, $@, $(OBJS))
.depend: Makefile $(SRCS)
@$(MKDEP) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
@@ -76,10 +74,11 @@ libboard$(LIBEXT): $(OBJS)
depend: .depend
clean:
- @rm -f libboard$(LIBEXT) *~ .*.swp
+ $(call DELFILE, libboard$(LIBEXT))
$(call CLEAN)
distclean: clean
- @rm -f Make.dep .depend
+ $(call DELFILE, Make.dep)
+ $(call DELFILE, .depend)
-include Make.dep
diff --git a/nuttx/drivers/Kconfig b/nuttx/drivers/Kconfig
index 1d263ec14..8302d21b7 100644
--- a/nuttx/drivers/Kconfig
+++ b/nuttx/drivers/Kconfig
@@ -47,7 +47,8 @@ config CAN_EXTID
bool "CAN extended IDs"
default n
---help---
- Enables support for the 29-bit extended ID. Default Standard 11-bit IDs.
+ Enables support for the 29-bit extended ID. Default Standard 11-bit
+ IDs.
config CAN_FIFOSIZE
int "CAN driver I/O buffer size"
@@ -83,10 +84,10 @@ config PWM_PULSECOUNT
bool "PWM Pulse Count Support"
default n
---help---
- Some hardware will support generation of a fixed number of pulses. This
- might be used, for example to support a stepper motor. If the hardware
- will support a fixed pulse count, then this configuration should be set to
- enable the capability.
+ Some hardware will support generation of a fixed number of pulses.
+ This might be used, for example to support a stepper motor. If the
+ hardware will support a fixed pulse count, then this configuration
+ should be set to enable the capability.
endif
@@ -147,23 +148,25 @@ config SPI_OWNBUS
bool "SPI single device"
default n
---help---
- Set if there is only one active device on the SPI bus. No locking or SPI
- configuration will be performed. It is not necessary for clients to lock,
- re-configure, etc..
+ Set if there is only one active device on the SPI bus. No locking or
+ SPI configuration will be performed. It is not necessary for clients to
+ lock, re-configure, etc..
config SPI_EXCHANGE
bool "SPI exchange"
default y
---help---
- Driver supports a single exchange method (vs a recvblock() and sndblock ()methods).
+ Driver supports a single exchange method (vs a recvblock() and
+ sndblock() methods).
config SPI_CMDDATA
bool "SPI CMD/DATA"
default n
---help---
- Devices on the SPI bus require out-of-band support to distinguish command
- transfers from data transfers. Such devices will often support either 9-bit
- SPI (yech) or 8-bit SPI and a GPIO output that selects between command and data.
+ Devices on the SPI bus require out-of-band support to distinguish
+ command transfers from data transfers. Such devices will often support
+ either 9-bit SPI (yech) or 8-bit SPI and a GPIO output that selects
+ between command and data.
endif
@@ -173,35 +176,36 @@ menuconfig RTC
---help---
This selection enables configuration of a real time clock (RTCdriver.
See include/nuttx/rtc.h for further watchdog timer driver information.
- Most RTC drivers are MCU specific and may require other specific settings.
+ Most RTC drivers are MCU specific and may require other specific
+ settings.
config RTC_DATETIME
bool "Date/Time RTC Support"
default n
depends on RTC
---help---
- There are two general types of RTC: (1) A simple battery backed counter
- that keeps the time when power is down, and (2) a full date / time RTC the
- provides the date and time information, often in BCD format. If
- RTC_DATETIME is selected, it specifies this second kind of RTC. In this
- case, the RTC is used to "seed" the normal NuttX timer and the NuttX system
- timer provides for higher resolution time.
+ There are two general types of RTC: (1) A simple battery backed
+ counter that keeps the time when power is down, and (2) a full
+ date / time RTC the provides the date and time information, often in
+ BCD format. If RTC_DATETIME is selected, it specifies this second kind
+ of RTC. In this case, the RTC is used to "seed" the normal NuttX timer
+ and the NuttX system timer provides for higher resolution time.
config RTC_HIRES
bool "Hi-Res RTC Support"
default n
depends on RTC && !RTC_DATETIME
---help---
- If RTC_DATETIME not selected, then the simple, battery backed counter is
- used. There are two different implementations of such simple counters
- based on the time resolution of the counter: The typical RTC keeps time
- to resolution of 1 second, usually supporting a 32-bit time_t value. In
- this case, the RTC is used to "seed" the normal NuttX timer and the NuttX
- timer provides for higherresoution time.
+ If RTC_DATETIME not selected, then the simple, battery backed counter
+ is used. There are two different implementations of such simple
+ counters based on the time resolution of the counter: The typical RTC
+ keeps time to resolution of 1 second, usually supporting a 32-bit
+ time_t value. In this case, the RTC is used to "seed" the normal NuttX
+ timer and the NuttX timer provides for higherresoution time.
- If RTC_HIRES is enabled in the NuttX configuration, then the RTC provides
- higher resolution time and completely replaces the system timer for purpose
- of date and time.
+ If RTC_HIRES is enabled in the NuttX configuration, then the RTC
+ provides higher resolution time and completely replaces the system
+ timer for purpose of date and time.
config RTC_FREQUENCY
int "Hi-Res RTC frequency"
@@ -209,8 +213,8 @@ config RTC_FREQUENCY
depends on RTC && !RTC_DATETIME && RTC_HIRES
---help---
If RTC_HIRES is defined, then the frequency of the high resolution RTC
- must be provided. If RTC_HIRES is not defined, RTC_FREQUENCY is assumed
- to be one Hz.
+ must be provided. If RTC_HIRES is not defined, RTC_FREQUENCY is
+ assumed to be one Hz.
config RTC_ALARM
bool "RTC Alarm Support"
@@ -224,8 +228,9 @@ menuconfig WATCHDOG
bool "Watchdog Timer Support"
default n
---help---
- This selection enables building of the "upper-half" watchdog timer driver.
- See include/nuttx/watchdog.h for further watchdog timer driver information.
+ This selection enables building of the "upper-half" watchdog timer
+ driver. See include/nuttx/watchdog.h for further watchdog timer driver
+ information.
if WATCHDOG
endif
@@ -348,7 +353,8 @@ menuconfig POWER
bool "Power Management Support"
default n
---help---
- Enable building of power-related devices (battery monitors, chargers, etc).
+ Enable building of power-related devices (battery monitors, chargers,
+ etc).
if POWER
source drivers/power/Kconfig
@@ -386,8 +392,8 @@ menuconfig SERIAL
default y
---help---
Front-end character drivers for chip-specific UARTs. This provide
- some TTY-like functionality and are commonly used (but not required for)
- the NuttX system console. See also include/nuttx/serial/serial.h
+ some TTY-like functionality and are commonly used (but not required
+ for) the NuttX system console. See also include/nuttx/serial/serial.h
if SERIAL
source drivers/serial/Kconfig
diff --git a/nuttx/drivers/Makefile b/nuttx/drivers/Makefile
index 26a2ea992..aaaa67bd7 100644
--- a/nuttx/drivers/Makefile
+++ b/nuttx/drivers/Makefile
@@ -34,6 +34,7 @@
############################################################################
-include $(TOPDIR)/Make.defs
+DELIM ?= $(strip /)
ifeq ($(WINTOOL),y)
INCDIROPT = -w
@@ -48,22 +49,22 @@ VPATH = .
# files to the source file list, add its DEPPATH info, and will add
# the appropriate paths to the VPATH variable
-include analog/Make.defs
-include bch/Make.defs
-include input/Make.defs
-include lcd/Make.defs
-include mmcsd/Make.defs
-include mtd/Make.defs
-include net/Make.defs
-include pipes/Make.defs
-include power/Make.defs
-include sensors/Make.defs
-include sercomm/Make.defs
-include serial/Make.defs
-include syslog/Make.defs
-include usbdev/Make.defs
-include usbhost/Make.defs
-include wireless/Make.defs
+include analog$(DELIM)Make.defs
+include bch$(DELIM)Make.defs
+include input$(DELIM)Make.defs
+include lcd$(DELIM)Make.defs
+include mmcsd$(DELIM)Make.defs
+include mtd$(DELIM)Make.defs
+include net$(DELIM)Make.defs
+include pipes$(DELIM)Make.defs
+include power$(DELIM)Make.defs
+include sensors$(DELIM)Make.defs
+include sercomm$(DELIM)Make.defs
+include serial$(DELIM)Make.defs
+include syslog$(DELIM)Make.defs
+include usbdev$(DELIM)Make.defs
+include usbhost$(DELIM)Make.defs
+include wireless$(DELIM)Make.defs
ifneq ($(CONFIG_NFILE_DESCRIPTORS),0)
CSRCS += dev_null.c dev_zero.c loop.c
@@ -85,15 +86,15 @@ ifeq ($(CONFIG_WATCHDOG),y)
endif
endif
-AOBJS = $(ASRCS:.S=$(OBJEXT))
-COBJS = $(CSRCS:.c=$(OBJEXT))
+AOBJS = $(ASRCS:.S=$(OBJEXT))
+COBJS = $(CSRCS:.c=$(OBJEXT))
-SRCS = $(ASRCS) $(CSRCS)
-OBJS = $(AOBJS) $(COBJS)
+SRCS = $(ASRCS) $(CSRCS)
+OBJS = $(AOBJS) $(COBJS)
-BIN = libdrivers$(LIBEXT)
+BIN = libdrivers$(LIBEXT)
-all: $(BIN)
+all: $(BIN)
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
@@ -101,22 +102,21 @@ $(AOBJS): %$(OBJEXT): %.S
$(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
-$(BIN): $(OBJS)
- @( for obj in $(OBJS) ; do \
- $(call ARCHIVE, $@, $${obj}); \
- done ; )
+$(BIN): $(OBJS)
+ $(call ARCHIVE, $@, $(OBJS))
.depend: Makefile $(SRCS)
- @$(MKDEP) $(DEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
- @touch $@
+ $(Q) $(MKDEP) $(DEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
+ $(Q) touch $@
depend: .depend
clean:
- @rm -f $(BIN) *~ .*.swp
+ $(call DELFILE, $(BIN))
$(call CLEAN)
distclean: clean
- @rm -f Make.dep .depend
+ $(call DELFILE, Make.dep)
+ $(call DELFILE, .depend)
-include Make.dep
diff --git a/nuttx/drivers/analog/Make.defs b/nuttx/drivers/analog/Make.defs
index d94e39758..89cc5bd3f 100644
--- a/nuttx/drivers/analog/Make.defs
+++ b/nuttx/drivers/analog/Make.defs
@@ -1,7 +1,7 @@
############################################################################
# drivers/analog/Make.defs
#
-# Copyright (C) 2011 Gregory Nutt. All rights reserved.
+# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
@@ -76,12 +76,12 @@ endif
ifeq ($(CONFIG_DAC),y)
DEPPATH += --dep-path analog
VPATH += :analog
- CFLAGS += ${shell $(TOPDIR)/tools/incdir.sh $(INCDIROPT) "$(CC)" $(TOPDIR)/drivers/analog}
+ CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)drivers$(DELIM)analog}
else
ifeq ($(CONFIG_ADC),y)
DEPPATH += --dep-path analog
VPATH += :analog
- CFLAGS += ${shell $(TOPDIR)/tools/incdir.sh $(INCDIROPT) "$(CC)" $(TOPDIR)/drivers/analog}
+ CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)drivers$(DELIM)analog}
endif
endif
diff --git a/nuttx/drivers/analog/adc.c b/nuttx/drivers/analog/adc.c
index 84070f162..72f19452a 100644
--- a/nuttx/drivers/analog/adc.c
+++ b/nuttx/drivers/analog/adc.c
@@ -143,7 +143,7 @@ static int adc_open(FAR struct file *filep)
dev->ad_recv.af_head = 0;
dev->ad_recv.af_tail = 0;
- /* Finally, Enable the CAN RX interrupt */
+ /* Finally, Enable the ADC RX interrupt */
dev->ad_ops->ao_rxint(dev, true);
@@ -151,9 +151,11 @@ static int adc_open(FAR struct file *filep)
dev->ad_ocount = tmp;
}
+
irqrestore(flags);
}
}
+
sem_post(&dev->ad_closesem);
}
return ret;
@@ -370,6 +372,10 @@ static int adc_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
* Public Functions
****************************************************************************/
+/****************************************************************************
+ * Name: adc_receive
+ ****************************************************************************/
+
int adc_receive(FAR struct adc_dev_s *dev, uint8_t ch, int32_t data)
{
FAR struct adc_fifo_s *fifo = &dev->ad_recv;
@@ -390,7 +396,7 @@ int adc_receive(FAR struct adc_dev_s *dev, uint8_t ch, int32_t data)
if (nexttail != fifo->af_head)
{
- /* Add the new, decoded CAN message at the tail of the FIFO */
+ /* Add the new, decoded ADC sample at the tail of the FIFO */
fifo->af_buffer[fifo->af_tail].am_channel = ch;
fifo->af_buffer[fifo->af_tail].am_data = data;
@@ -403,11 +409,16 @@ int adc_receive(FAR struct adc_dev_s *dev, uint8_t ch, int32_t data)
{
sem_post(&fifo->af_sem);
}
+
err = OK;
}
return err;
}
+/****************************************************************************
+ * Name: adc_register
+ ****************************************************************************/
+
int adc_register(FAR const char *path, FAR struct adc_dev_s *dev)
{
/* Initialize the ADC device structure */
diff --git a/nuttx/drivers/bch/Make.defs b/nuttx/drivers/bch/Make.defs
index bc22df8e2..78dfbff30 100644
--- a/nuttx/drivers/bch/Make.defs
+++ b/nuttx/drivers/bch/Make.defs
@@ -1,7 +1,7 @@
############################################################################
# drivers/bch/Make.defs
#
-# Copyright (C) 2008, 2011 Gregory Nutt. All rights reserved.
+# Copyright (C) 2008, 2011-2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
@@ -46,7 +46,7 @@ CSRCS += bchlib_setup.c bchlib_teardown.c bchlib_read.c bchlib_write.c \
DEPPATH += --dep-path bch
VPATH += :bch
-CFLAGS += ${shell $(TOPDIR)/tools/incdir.sh $(INCDIROPT) "$(CC)" $(TOPDIR)/drivers/bch}
+CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)drivers$(DELIM)bch}
endif
endif
diff --git a/nuttx/drivers/input/Make.defs b/nuttx/drivers/input/Make.defs
index 6dbae268e..10e6db62f 100644
--- a/nuttx/drivers/input/Make.defs
+++ b/nuttx/drivers/input/Make.defs
@@ -1,7 +1,7 @@
############################################################################
# drivers/input/Make.defs
#
-# Copyright (C) 2011 Gregory Nutt. All rights reserved.
+# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
@@ -47,6 +47,10 @@ ifeq ($(CONFIG_INPUT_ADS7843E),y)
CSRCS += ads7843e.c
endif
+ifeq ($(CONFIG_INPUT_MAX11802),y)
+ CSRCS += max11802.c
+endif
+
ifeq ($(CONFIG_INPUT_STMPE811),y)
CSRCS += stmpe811_base.c
ifneq ($(CONFIG_INPUT_STMPE811_TSC_DISABLE),y)
@@ -67,6 +71,6 @@ endif
DEPPATH += --dep-path input
VPATH += :input
-CFLAGS += ${shell $(TOPDIR)/tools/incdir.sh $(INCDIROPT) "$(CC)" $(TOPDIR)/drivers/input}
+CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)drivers$(DELIM)input}
endif
diff --git a/nuttx/drivers/input/max11802.c b/nuttx/drivers/input/max11802.c
new file mode 100644
index 000000000..ea3883cd0
--- /dev/null
+++ b/nuttx/drivers/input/max11802.c
@@ -0,0 +1,1313 @@
+/****************************************************************************
+ * drivers/input/max11802.c
+ *
+ * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
+ * Authors: Gregory Nutt <gnutt@nuttx.org>
+ * Petteri Aimonen <jpa@nx.mail.kapsi.fi>
+ *
+ * References:
+ * "Low-Power, Ultra-Small Resistive Touch-Screen Controllers
+ * with I2C/SPI Interface" Maxim IC, Rev 3, 10/2010
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+
+#include <stdbool.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <fcntl.h>
+#include <semaphore.h>
+#include <poll.h>
+#include <wdog.h>
+#include <errno.h>
+#include <assert.h>
+#include <debug.h>
+
+#include <nuttx/kmalloc.h>
+#include <nuttx/arch.h>
+#include <nuttx/fs/fs.h>
+#include <nuttx/spi.h>
+#include <nuttx/wqueue.h>
+
+#include <nuttx/input/touchscreen.h>
+#include <nuttx/input/max11802.h>
+
+#include "max11802.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* This is a value for the threshold that guantees a big difference on the
+ * first pendown (but can't overflow).
+ */
+
+#define INVALID_THRESHOLD 0x1000
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+/* Low-level SPI helpers */
+
+#ifdef CONFIG_SPI_OWNBUS
+static inline void max11802_configspi(FAR struct spi_dev_s *spi);
+# define max11802_lock(spi)
+# define max11802_unlock(spi)
+#else
+# define max11802_configspi(spi);
+static void max11802_lock(FAR struct spi_dev_s *spi);
+static void max11802_unlock(FAR struct spi_dev_s *spi);
+#endif
+
+static uint16_t max11802_sendcmd(FAR struct max11802_dev_s *priv, uint8_t cmd, int *tags);
+
+/* Interrupts and data sampling */
+
+static void max11802_notify(FAR struct max11802_dev_s *priv);
+static int max11802_sample(FAR struct max11802_dev_s *priv,
+ FAR struct max11802_sample_s *sample);
+static int max11802_waitsample(FAR struct max11802_dev_s *priv,
+ FAR struct max11802_sample_s *sample);
+static void max11802_worker(FAR void *arg);
+static int max11802_interrupt(int irq, FAR void *context);
+
+/* Character driver methods */
+
+static int max11802_open(FAR struct file *filep);
+static int max11802_close(FAR struct file *filep);
+static ssize_t max11802_read(FAR struct file *filep, FAR char *buffer, size_t len);
+static int max11802_ioctl(FAR struct file *filep, int cmd, unsigned long arg);
+#ifndef CONFIG_DISABLE_POLL
+static int max11802_poll(FAR struct file *filep, struct pollfd *fds, bool setup);
+#endif
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/* This the the vtable that supports the character driver interface */
+
+static const struct file_operations max11802_fops =
+{
+ max11802_open, /* open */
+ max11802_close, /* close */
+ max11802_read, /* read */
+ 0, /* write */
+ 0, /* seek */
+ max11802_ioctl /* ioctl */
+#ifndef CONFIG_DISABLE_POLL
+ , max11802_poll /* poll */
+#endif
+};
+
+/* If only a single MAX11802 device is supported, then the driver state
+ * structure may as well be pre-allocated.
+ */
+
+#ifndef CONFIG_MAX11802_MULTIPLE
+static struct max11802_dev_s g_max11802;
+
+/* Otherwise, we will need to maintain allocated driver instances in a list */
+
+#else
+static struct max11802_dev_s *g_max11802list;
+#endif
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Function: max11802_lock
+ *
+ * Description:
+ * Lock the SPI bus and re-configure as necessary. This function must be
+ * to assure: (1) exclusive access to the SPI bus, and (2) to assure that
+ * the shared bus is properly configured for the touchscreen controller.
+ *
+ * Parameters:
+ * spi - Reference to the SPI driver structure
+ *
+ * Returned Value:
+ * None
+ *
+ * Assumptions:
+ *
+ ****************************************************************************/
+
+#ifndef CONFIG_SPI_OWNBUS
+static void max11802_lock(FAR struct spi_dev_s *spi)
+{
+ /* Lock the SPI bus because there are multiple devices competing for the
+ * SPI bus
+ */
+
+ (void)SPI_LOCK(spi, true);
+
+ /* We have the lock. Now make sure that the SPI bus is configured for the
+ * MAX11802 (it might have gotten configured for a different device while
+ * unlocked)
+ */
+
+ SPI_SELECT(spi, SPIDEV_TOUCHSCREEN, true);
+ SPI_SETMODE(spi, CONFIG_MAX11802_SPIMODE);
+ SPI_SETBITS(spi, 8);
+ SPI_SETFREQUENCY(spi, CONFIG_MAX11802_FREQUENCY);
+ SPI_SELECT(spi, SPIDEV_TOUCHSCREEN, false);
+}
+#endif
+
+/****************************************************************************
+ * Function: max11802_unlock
+ *
+ * Description:
+ * If we are sharing the SPI bus with other devices (CONFIG_SPI_OWNBUS
+ * undefined) then we need to un-lock the SPI bus for each transfer,
+ * possibly losing the current configuration.
+ *
+ * Parameters:
+ * spi - Reference to the SPI driver structure
+ *
+ * Returned Value:
+ * None
+ *
+ * Assumptions:
+ *
+ ****************************************************************************/
+
+#ifndef CONFIG_SPI_OWNBUS
+static void max11802_unlock(FAR struct spi_dev_s *spi)
+{
+ /* Relinquish the SPI bus. */
+
+ (void)SPI_LOCK(spi, false);
+}
+#endif
+
+/****************************************************************************
+ * Function: max11802_configspi
+ *
+ * Description:
+ * Configure the SPI for use with the MAX11802. This function should be
+ * called once during touchscreen initialization to configure the SPI
+ * bus. Note that if CONFIG_SPI_OWNBUS is not defined, then this function
+ * does nothing.
+ *
+ * Parameters:
+ * spi - Reference to the SPI driver structure
+ *
+ * Returned Value:
+ * None
+ *
+ * Assumptions:
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_SPI_OWNBUS
+static inline void max11802_configspi(FAR struct spi_dev_s *spi)
+{
+ /* Configure SPI for the MAX11802. But only if we own the SPI bus. Otherwise, don't
+ * bother because it might change.
+ */
+
+ SPI_SELECT(spi, SPIDEV_TOUCHSCREEN, true);
+ SPI_SETMODE(spi, CONFIG_MAX11802_SPIMODE);
+ SPI_SETBITS(spi, 8);
+ SPI_SETFREQUENCY(spi, CONFIG_MAX11802_FREQUENCY);
+ SPI_SELECT(spi, SPIDEV_TOUCHSCREEN, false);
+}
+#endif
+
+/****************************************************************************
+ * Name: max11802_sendcmd
+ ****************************************************************************/
+
+static uint16_t max11802_sendcmd(FAR struct max11802_dev_s *priv, uint8_t cmd, int *tags)
+{
+ uint8_t buffer[2];
+ uint16_t result;
+
+ /* Select the MAX11802 */
+
+ SPI_SELECT(priv->spi, SPIDEV_TOUCHSCREEN, true);
+
+ /* Send the command */
+
+ (void)SPI_SEND(priv->spi, cmd);
+
+ /* Read the data */
+
+ SPI_RECVBLOCK(priv->spi, buffer, 2);
+ SPI_SELECT(priv->spi, SPIDEV_TOUCHSCREEN, false);
+
+ result = ((uint16_t)buffer[0] << 8) | (uint16_t)buffer[1];
+ *tags = result & 0xF;
+ result >>= 4; // Get rid of tags
+
+ ivdbg("cmd:%02x response:%04x\n", cmd, result);
+ return result;
+}
+
+/****************************************************************************
+ * Name: max11802_notify
+ ****************************************************************************/
+
+static void max11802_notify(FAR struct max11802_dev_s *priv)
+{
+#ifndef CONFIG_DISABLE_POLL
+ int i;
+#endif
+
+ /* If there are threads waiting for read data, then signal one of them
+ * that the read data is available.
+ */
+
+ if (priv->nwaiters > 0)
+ {
+ /* After posting this semaphore, we need to exit because the sample
+ * is no longer available.
+ */
+
+ sem_post(&priv->waitsem);
+ }
+
+ /* If there are threads waiting on poll() for MAX11802 data to become available,
+ * then wake them up now. NOTE: we wake up all waiting threads because we
+ * do not know that they are going to do. If they all try to read the data,
+ * then some make end up blocking after all.
+ */
+
+#ifndef CONFIG_DISABLE_POLL
+ for (i = 0; i < CONFIG_MAX11802_NPOLLWAITERS; i++)
+ {
+ struct pollfd *fds = priv->fds[i];
+ if (fds)
+ {
+ fds->revents |= POLLIN;
+ ivdbg("Report events: %02x\n", fds->revents);
+ sem_post(fds->sem);
+ }
+ }
+#endif
+}
+
+/****************************************************************************
+ * Name: max11802_sample
+ ****************************************************************************/
+
+static int max11802_sample(FAR struct max11802_dev_s *priv,
+ FAR struct max11802_sample_s *sample)
+{
+ irqstate_t flags;
+ int ret = -EAGAIN;
+
+ /* Interrupts must be disabled when this is called to (1) prevent posting
+ * of semaphores from interrupt handlers, and (2) to prevent sampled data
+ * from changing until it has been reported.
+ */
+
+ flags = irqsave();
+
+ /* Is there new MAX11802 sample data available? */
+
+ if (priv->penchange)
+ {
+ /* Yes.. the state has changed in some way. Return a copy of the
+ * sampled data.
+ */
+
+ memcpy(sample, &priv->sample, sizeof(struct max11802_sample_s ));
+
+ /* Now manage state transitions */
+
+ if (sample->contact == CONTACT_UP)
+ {
+ /* Next.. no contact. Increment the ID so that next contact ID
+ * will be unique. X/Y positions are no longer valid.
+ */
+
+ priv->sample.contact = CONTACT_NONE;
+ priv->sample.valid = false;
+ priv->id++;
+ }
+ else if (sample->contact == CONTACT_DOWN)
+ {
+ /* First report -- next report will be a movement */
+
+ priv->sample.contact = CONTACT_MOVE;
+ }
+
+ priv->penchange = false;
+ ret = OK;
+ }
+
+ irqrestore(flags);
+ return ret;
+}
+
+/****************************************************************************
+ * Name: max11802_waitsample
+ ****************************************************************************/
+
+static int max11802_waitsample(FAR struct max11802_dev_s *priv,
+ FAR struct max11802_sample_s *sample)
+{
+ irqstate_t flags;
+ int ret;
+
+ /* Interrupts must be disabled when this is called to (1) prevent posting
+ * of semaphores from interrupt handlers, and (2) to prevent sampled data
+ * from changing until it has been reported.
+ *
+ * In addition, we will also disable pre-emption to prevent other threads
+ * from getting control while we muck with the semaphores.
+ */
+
+ sched_lock();
+ flags = irqsave();
+
+ /* Now release the semaphore that manages mutually exclusive access to
+ * the device structure. This may cause other tasks to become ready to
+ * run, but they cannot run yet because pre-emption is disabled.
+ */
+
+ sem_post(&priv->devsem);
+
+ /* Try to get the a sample... if we cannot, then wait on the semaphore
+ * that is posted when new sample data is available.
+ */
+
+ while (max11802_sample(priv, sample) < 0)
+ {
+ /* Wait for a change in the MAX11802 state */
+
+ ivdbg("Waiting..\n");
+ priv->nwaiters++;
+ ret = sem_wait(&priv->waitsem);
+ priv->nwaiters--;
+
+ if (ret < 0)
+ {
+ /* If we are awakened by a signal, then we need to return
+ * the failure now.
+ */
+
+ idbg("sem_wait: %d\n", errno);
+ DEBUGASSERT(errno == EINTR);
+ ret = -EINTR;
+ goto errout;
+ }
+ }
+
+ ivdbg("Sampled\n");
+
+ /* Re-acquire the the semaphore that manages mutually exclusive access to
+ * the device structure. We may have to wait here. But we have our sample.
+ * Interrupts and pre-emption will be re-enabled while we wait.
+ */
+
+ ret = sem_wait(&priv->devsem);
+
+errout:
+ /* Then re-enable interrupts. We might get interrupt here and there
+ * could be a new sample. But no new threads will run because we still
+ * have pre-emption disabled.
+ */
+
+ irqrestore(flags);
+
+ /* Restore pre-emption. We might get suspended here but that is okay
+ * because we already have our sample. Note: this means that if there
+ * were two threads reading from the MAX11802 for some reason, the data
+ * might be read out of order.
+ */
+
+ sched_unlock();
+ return ret;
+}
+
+/****************************************************************************
+ * Name: max11802_schedule
+ ****************************************************************************/
+
+static int max11802_schedule(FAR struct max11802_dev_s *priv)
+{
+ FAR struct max11802_config_s *config;
+ int ret;
+
+ /* Get a pointer the callbacks for convenience (and so the code is not so
+ * ugly).
+ */
+
+ config = priv->config;
+ DEBUGASSERT(config != NULL);
+
+ /* Disable further interrupts. MAX11802 interrupts will be re-enabled
+ * after the worker thread executes.
+ */
+
+ config->enable(config, false);
+
+ /* Disable the watchdog timer. It will be re-enabled in the worker thread
+ * while the pen remains down.
+ */
+
+ wd_cancel(priv->wdog);
+
+ /* Transfer processing to the worker thread. Since MAX11802 interrupts are
+ * disabled while the work is pending, no special action should be required
+ * to protected the work queue.
+ */
+
+ DEBUGASSERT(priv->work.worker == NULL);
+ ret = work_queue(HPWORK, &priv->work, max11802_worker, priv, 0);
+ if (ret != 0)
+ {
+ illdbg("Failed to queue work: %d\n", ret);
+ }
+
+ return OK;
+}
+
+/****************************************************************************
+ * Name: max11802_wdog
+ ****************************************************************************/
+
+static void max11802_wdog(int argc, uint32_t arg1, ...)
+{
+ FAR struct max11802_dev_s *priv = (FAR struct max11802_dev_s *)((uintptr_t)arg1);
+ (void)max11802_schedule(priv);
+}
+
+/****************************************************************************
+ * Name: max11802_worker
+ ****************************************************************************/
+
+static void max11802_worker(FAR void *arg)
+{
+ FAR struct max11802_dev_s *priv = (FAR struct max11802_dev_s *)arg;
+ FAR struct max11802_config_s *config;
+ uint16_t x;
+ uint16_t y;
+ uint16_t xdiff;
+ uint16_t ydiff;
+ bool pendown;
+ int ret;
+ int tags, tags2;
+
+ ASSERT(priv != NULL);
+
+ /* Get a pointer the callbacks for convenience (and so the code is not so
+ * ugly).
+ */
+
+ config = priv->config;
+ DEBUGASSERT(config != NULL);
+
+ /* Disable the watchdog timer. This is safe because it is started only
+ * by this function and this function is serialized on the worker thread.
+ */
+
+ wd_cancel(priv->wdog);
+
+ /* Lock the SPI bus so that we have exclusive access */
+
+ max11802_lock(priv->spi);
+
+ /* Start coordinate measurement */
+ (void)max11802_sendcmd(priv, MAX11802_CMD_MEASUREXY, &tags);
+
+ /* Get exclusive access to the driver data structure */
+
+ do
+ {
+ ret = sem_wait(&priv->devsem);
+
+ /* This should only fail if the wait was canceled by an signal
+ * (and the worker thread will receive a lot of signals).
+ */
+
+ DEBUGASSERT(ret == OK || errno == EINTR);
+ }
+ while (ret < 0);
+
+ /* Check for pen up or down by reading the PENIRQ GPIO. */
+
+ pendown = config->pendown(config);
+
+ /* Handle the change from pen down to pen up */
+
+ if (pendown)
+ ivdbg("\nPD\n");
+ else
+ ivdbg("\nPU\n");
+
+ if (!pendown)
+ {
+ /* The pen is up.. reset thresholding variables. */
+
+ priv->threshx = INVALID_THRESHOLD;
+ priv->threshy = INVALID_THRESHOLD;
+
+ /* Ignore the interrupt if the pen was already up (CONTACT_NONE == pen up
+ * and already reported; CONTACT_UP == pen up, but not reported)
+ */
+
+ ivdbg("\nPC%d\n", priv->sample.contact);
+
+ if (priv->sample.contact == CONTACT_NONE ||
+ priv->sample.contact == CONTACT_UP)
+
+ {
+ goto ignored;
+ }
+
+ /* The pen is up. NOTE: We know from a previous test, that this is a
+ * loss of contact condition. This will be changed to CONTACT_NONE
+ * after the loss of contact is sampled.
+ */
+
+ priv->sample.contact = CONTACT_UP;
+ }
+
+ /* It is a pen down event. If the last loss-of-contact event has not been
+ * processed yet, then we have to ignore the pen down event (or else it will
+ * look like a drag event)
+ */
+
+ else if (priv->sample.contact == CONTACT_UP)
+ {
+ /* If we have not yet processed the last pen up event, then we
+ * cannot handle this pen down event. We will have to discard it. That
+ * should be okay because we will set the timer to to sample again
+ * later.
+ */
+
+ ivdbg("Previous pen up event still in buffer\n");
+ max11802_notify(priv);
+ wd_start(priv->wdog, MAX11802_WDOG_DELAY, max11802_wdog, 1, (uint32_t)priv);
+ goto ignored;
+ }
+ else
+ {
+ /* Wait for data ready */
+ do {
+ /* Handle pen down events. First, sample positional values. */
+
+#ifdef CONFIG_MAX11802_SWAPXY
+ x = max11802_sendcmd(priv, MAX11802_CMD_YPOSITION, &tags);
+ y = max11802_sendcmd(priv, MAX11802_CMD_XPOSITION, &tags2);
+#else
+ x = max11802_sendcmd(priv, MAX11802_CMD_XPOSITION, &tags);
+ y = max11802_sendcmd(priv, MAX11802_CMD_YPOSITION, &tags2);
+#endif
+ } while (tags == 0xF || tags2 == 0xF);
+
+ /* Continue to sample the position while the pen is down */
+ wd_start(priv->wdog, MAX11802_WDOG_DELAY, max11802_wdog, 1, (uint32_t)priv);
+
+ /* Check if data is valid */
+ if ((tags & 0x03) != 0)
+ {
+ ivdbg("Touch ended before measurement\n");
+ goto ignored;
+ }
+
+ /* Perform a thresholding operation so that the results will be more stable.
+ * If the difference from the last sample is small, then ignore the event.
+ * REVISIT: Should a large change in pressure also generate a event?
+ */
+
+ xdiff = x > priv->threshx ? (x - priv->threshx) : (priv->threshx - x);
+ ydiff = y > priv->threshy ? (y - priv->threshy) : (priv->threshy - y);
+
+ /* Check the thresholds. Bail if there is no significant difference */
+
+ if (xdiff < CONFIG_MAX11802_THRESHX && ydiff < CONFIG_MAX11802_THRESHY)
+ {
+ /* Little or no change in either direction ... don't report anything. */
+
+ goto ignored;
+ }
+
+ /* When we see a big difference, snap to the new x/y thresholds */
+
+ priv->threshx = x;
+ priv->threshy = y;
+
+ /* Update the x/y position in the sample data */
+
+ priv->sample.x = priv->threshx;
+ priv->sample.y = priv->threshy;
+
+ /* The X/Y positional data is now valid */
+
+ priv->sample.valid = true;
+
+ /* If this is the first (acknowledged) pen down report, then report
+ * this as the first contact. If contact == CONTACT_DOWN, it will be
+ * set to set to CONTACT_MOVE after the contact is first sampled.
+ */
+
+ if (priv->sample.contact != CONTACT_MOVE)
+ {
+ /* First contact */
+
+ priv->sample.contact = CONTACT_DOWN;
+ }
+ }
+
+ /* Indicate the availability of new sample data for this ID */
+
+ priv->sample.id = priv->id;
+ priv->penchange = true;
+
+ /* Notify any waiters that new MAX11802 data is available */
+
+ max11802_notify(priv);
+
+ignored:
+ config->enable(config, true);
+
+ /* Release our lock on the state structure and unlock the SPI bus */
+
+ sem_post(&priv->devsem);
+ max11802_unlock(priv->spi);
+}
+
+/****************************************************************************
+ * Name: max11802_interrupt
+ ****************************************************************************/
+
+static int max11802_interrupt(int irq, FAR void *context)
+{
+ FAR struct max11802_dev_s *priv;
+ FAR struct max11802_config_s *config;
+ int ret;
+
+ /* Which MAX11802 device caused the interrupt? */
+
+#ifndef CONFIG_MAX11802_MULTIPLE
+ priv = &g_max11802;
+#else
+ for (priv = g_max11802list;
+ priv && priv->configs->irq != irq;
+ priv = priv->flink);
+
+ ASSERT(priv != NULL);
+#endif
+
+ /* Get a pointer the callbacks for convenience (and so the code is not so
+ * ugly).
+ */
+
+ config = priv->config;
+ DEBUGASSERT(config != NULL);
+
+ /* Schedule sampling to occur on the worker thread */
+
+ ret = max11802_schedule(priv);
+
+ /* Clear any pending interrupts and return success */
+
+ config->clear(config);
+ return ret;
+}
+
+/****************************************************************************
+ * Name: max11802_open
+ ****************************************************************************/
+
+static int max11802_open(FAR struct file *filep)
+{
+#ifdef CONFIG_MAX11802_REFCNT
+ FAR struct inode *inode;
+ FAR struct max11802_dev_s *priv;
+ uint8_t tmp;
+ int ret;
+
+ ivdbg("Opening\n");
+
+ DEBUGASSERT(filep);
+ inode = filep->f_inode;
+
+ DEBUGASSERT(inode && inode->i_private);
+ priv = (FAR struct max11802_dev_s *)inode->i_private;
+
+ /* Get exclusive access to the driver data structure */
+
+ ret = sem_wait(&priv->devsem);
+ if (ret < 0)
+ {
+ /* This should only happen if the wait was canceled by an signal */
+
+ DEBUGASSERT(errno == EINTR);
+ return -EINTR;
+ }
+
+ /* Increment the reference count */
+
+ tmp = priv->crefs + 1;
+ if (tmp == 0)
+ {
+ /* More than 255 opens; uint8_t overflows to zero */
+
+ ret = -EMFILE;
+ goto errout_with_sem;
+ }
+
+ /* When the reference increments to 1, this is the first open event
+ * on the driver.. and an opportunity to do any one-time initialization.
+ */
+
+ /* Save the new open count on success */
+
+ priv->crefs = tmp;
+
+errout_with_sem:
+ sem_post(&priv->devsem);
+ return ret;
+#else
+ ivdbg("Opening\n");
+ return OK;
+#endif
+}
+
+/****************************************************************************
+ * Name: max11802_close
+ ****************************************************************************/
+
+static int max11802_close(FAR struct file *filep)
+{
+#ifdef CONFIG_MAX11802_REFCNT
+ FAR struct inode *inode;
+ FAR struct max11802_dev_s *priv;
+ int ret;
+
+ ivdbg("Closing\n");
+ DEBUGASSERT(filep);
+ inode = filep->f_inode;
+
+ DEBUGASSERT(inode && inode->i_private);
+ priv = (FAR struct max11802_dev_s *)inode->i_private;
+
+ /* Get exclusive access to the driver data structure */
+
+ ret = sem_wait(&priv->devsem);
+ if (ret < 0)
+ {
+ /* This should only happen if the wait was canceled by an signal */
+
+ DEBUGASSERT(errno == EINTR);
+ return -EINTR;
+ }
+
+ /* Decrement the reference count unless it would decrement a negative
+ * value. When the count decrements to zero, there are no further
+ * open references to the driver.
+ */
+
+ if (priv->crefs >= 1)
+ {
+ priv->crefs--;
+ }
+
+ sem_post(&priv->devsem);
+#endif
+ ivdbg("Closing\n");
+ return OK;
+}
+
+/****************************************************************************
+ * Name: max11802_read
+ ****************************************************************************/
+
+static ssize_t max11802_read(FAR struct file *filep, FAR char *buffer, size_t len)
+{
+ FAR struct inode *inode;
+ FAR struct max11802_dev_s *priv;
+ FAR struct touch_sample_s *report;
+ struct max11802_sample_s sample;
+ int ret;
+
+ ivdbg("buffer:%p len:%d\n", buffer, len);
+ DEBUGASSERT(filep);
+ inode = filep->f_inode;
+
+ DEBUGASSERT(inode && inode->i_private);
+ priv = (FAR struct max11802_dev_s *)inode->i_private;
+
+ /* Verify that the caller has provided a buffer large enough to receive
+ * the touch data.
+ */
+
+ if (len < SIZEOF_TOUCH_SAMPLE_S(1))
+ {
+ /* We could provide logic to break up a touch report into segments and
+ * handle smaller reads... but why?
+ */
+
+ idbg("Unsupported read size: %d\n", len);
+ return -ENOSYS;
+ }
+
+ /* Get exclusive access to the driver data structure */
+
+ ret = sem_wait(&priv->devsem);
+ if (ret < 0)
+ {
+ /* This should only happen if the wait was canceled by an signal */
+
+ idbg("sem_wait: %d\n", errno);
+ DEBUGASSERT(errno == EINTR);
+ return -EINTR;
+ }
+
+ /* Try to read sample data. */
+
+ ret = max11802_sample(priv, &sample);
+ if (ret < 0)
+ {
+ /* Sample data is not available now. We would ave to wait to get
+ * receive sample data. If the user has specified the O_NONBLOCK
+ * option, then just return an error.
+ */
+
+ ivdbg("Sample data is not available\n");
+ if (filep->f_oflags & O_NONBLOCK)
+ {
+ ret = -EAGAIN;
+ goto errout;
+ }
+
+ /* Wait for sample data */
+
+ ret = max11802_waitsample(priv, &sample);
+ if (ret < 0)
+ {
+ /* We might have been awakened by a signal */
+
+ idbg("max11802_waitsample: %d\n", ret);
+ goto errout;
+ }
+ }
+
+ /* In any event, we now have sampled MAX11802 data that we can report
+ * to the caller.
+ */
+
+ report = (FAR struct touch_sample_s *)buffer;
+ memset(report, 0, SIZEOF_TOUCH_SAMPLE_S(1));
+ report->npoints = 1;
+ report->point[0].id = sample.id;
+ report->point[0].x = sample.x;
+ report->point[0].y = sample.y;
+
+ /* Report the appropriate flags */
+
+ if (sample.contact == CONTACT_UP)
+ {
+ /* Pen is now up. Is the positional data valid? This is important to
+ * know because the release will be sent to the window based on its
+ * last positional data.
+ */
+
+ if (sample.valid)
+ {
+ report->point[0].flags = TOUCH_UP | TOUCH_ID_VALID | TOUCH_POS_VALID;
+ }
+ else
+ {
+ report->point[0].flags = TOUCH_UP | TOUCH_ID_VALID;
+ }
+ }
+ else if (sample.contact == CONTACT_DOWN)
+ {
+ /* First contact */
+
+ report->point[0].flags = TOUCH_DOWN | TOUCH_ID_VALID | TOUCH_POS_VALID;
+ }
+ else /* if (sample->contact == CONTACT_MOVE) */
+ {
+ /* Movement of the same contact */
+
+ report->point[0].flags = TOUCH_MOVE | TOUCH_ID_VALID | TOUCH_POS_VALID;
+ }
+
+ ivdbg(" id: %d\n", report->point[0].id);
+ ivdbg(" flags: %02x\n", report->point[0].flags);
+ ivdbg(" x: %d\n", report->point[0].x);
+ ivdbg(" y: %d\n", report->point[0].y);
+
+ ret = SIZEOF_TOUCH_SAMPLE_S(1);
+
+errout:
+ sem_post(&priv->devsem);
+ ivdbg("Returning: %d\n", ret);
+ return ret;
+}
+
+/****************************************************************************
+ * Name:max11802_ioctl
+ ****************************************************************************/
+
+static int max11802_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
+{
+ FAR struct inode *inode;
+ FAR struct max11802_dev_s *priv;
+ int ret;
+
+ ivdbg("cmd: %d arg: %ld\n", cmd, arg);
+ DEBUGASSERT(filep);
+ inode = filep->f_inode;
+
+ DEBUGASSERT(inode && inode->i_private);
+ priv = (FAR struct max11802_dev_s *)inode->i_private;
+
+ /* Get exclusive access to the driver data structure */
+
+ ret = sem_wait(&priv->devsem);
+ if (ret < 0)
+ {
+ /* This should only happen if the wait was canceled by an signal */
+
+ DEBUGASSERT(errno == EINTR);
+ return -EINTR;
+ }
+
+ /* Process the IOCTL by command */
+
+ switch (cmd)
+ {
+ case TSIOC_SETFREQUENCY: /* arg: Pointer to uint32_t frequency value */
+ {
+ FAR uint32_t *ptr = (FAR uint32_t *)((uintptr_t)arg);
+ DEBUGASSERT(priv->config != NULL && ptr != NULL);
+ priv->config->frequency = SPI_SETFREQUENCY(priv->spi, *ptr);
+ }
+ break;
+
+ case TSIOC_GETFREQUENCY: /* arg: Pointer to uint32_t frequency value */
+ {
+ FAR uint32_t *ptr = (FAR uint32_t *)((uintptr_t)arg);
+ DEBUGASSERT(priv->config != NULL && ptr != NULL);
+ *ptr = priv->config->frequency;
+ }
+ break;
+
+ default:
+ ret = -ENOTTY;
+ break;
+ }
+
+ sem_post(&priv->devsem);
+ return ret;
+}
+
+/****************************************************************************
+ * Name: max11802_poll
+ ****************************************************************************/
+
+#ifndef CONFIG_DISABLE_POLL
+static int max11802_poll(FAR struct file *filep, FAR struct pollfd *fds,
+ bool setup)
+{
+ FAR struct inode *inode;
+ FAR struct max11802_dev_s *priv;
+ pollevent_t eventset;
+ int ndx;
+ int ret = OK;
+ int i;
+
+ ivdbg("setup: %d\n", (int)setup);
+ DEBUGASSERT(filep && fds);
+ inode = filep->f_inode;
+
+ DEBUGASSERT(inode && inode->i_private);
+ priv = (FAR struct max11802_dev_s *)inode->i_private;
+
+ /* Are we setting up the poll? Or tearing it down? */
+
+ ret = sem_wait(&priv->devsem);
+ if (ret < 0)
+ {
+ /* This should only happen if the wait was canceled by an signal */
+
+ DEBUGASSERT(errno == EINTR);
+ return -EINTR;
+ }
+
+ if (setup)
+ {
+ /* Ignore waits that do not include POLLIN */
+
+ if ((fds->events & POLLIN) == 0)
+ {
+ ret = -EDEADLK;
+ goto errout;
+ }
+
+ /* This is a request to set up the poll. Find an available
+ * slot for the poll structure reference
+ */
+
+ for (i = 0; i < CONFIG_MAX11802_NPOLLWAITERS; i++)
+ {
+ /* Find an available slot */
+
+ if (!priv->fds[i])
+ {
+ /* Bind the poll structure and this slot */
+
+ priv->fds[i] = fds;
+ fds->priv = &priv->fds[i];
+ break;
+ }
+ }
+
+ if (i >= CONFIG_MAX11802_NPOLLWAITERS)
+ {
+ fds->priv = NULL;
+ ret = -EBUSY;
+ goto errout;
+ }
+
+ /* Should we immediately notify on any of the requested events? */
+
+ if (priv->penchange)
+ {
+ max11802_notify(priv);
+ }
+ }
+ else if (fds->priv)
+ {
+ /* This is a request to tear down the poll. */
+
+ struct pollfd **slot = (struct pollfd **)fds->priv;
+ DEBUGASSERT(slot != NULL);
+
+ /* Remove all memory of the poll setup */
+
+ *slot = NULL;
+ fds->priv = NULL;
+ }
+
+errout:
+ sem_post(&priv->devsem);
+ return ret;
+}
+#endif
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: max11802_register
+ *
+ * Description:
+ * Configure the MAX11802 to use the provided SPI device instance. This
+ * will register the driver as /dev/inputN where N is the minor device
+ * number
+ *
+ * Input Parameters:
+ * dev - An SPI driver instance
+ * config - Persistent board configuration data
+ * minor - The input device minor number
+ *
+ * Returned Value:
+ * Zero is returned on success. Otherwise, a negated errno value is
+ * returned to indicate the nature of the failure.
+ *
+ ****************************************************************************/
+
+int max11802_register(FAR struct spi_dev_s *spi,
+ FAR struct max11802_config_s *config, int minor)
+{
+ FAR struct max11802_dev_s *priv;
+ char devname[DEV_NAMELEN];
+#ifdef CONFIG_MAX11802_MULTIPLE
+ irqstate_t flags;
+#endif
+ int ret;
+
+ ivdbg("spi: %p minor: %d\n", spi, minor);
+
+ /* Debug-only sanity checks */
+
+ DEBUGASSERT(spi != NULL && config != NULL && minor >= 0 && minor < 100);
+
+ /* Create and initialize a MAX11802 device driver instance */
+
+#ifndef CONFIG_MAX11802_MULTIPLE
+ priv = &g_max11802;
+#else
+ priv = (FAR struct max11802_dev_s *)kmalloc(sizeof(struct max11802_dev_s));
+ if (!priv)
+ {
+ idbg("kmalloc(%d) failed\n", sizeof(struct max11802_dev_s));
+ return -ENOMEM;
+ }
+#endif
+
+ /* Initialize the MAX11802 device driver instance */
+
+ memset(priv, 0, sizeof(struct max11802_dev_s));
+ priv->spi = spi; /* Save the SPI device handle */
+ priv->config = config; /* Save the board configuration */
+ priv->wdog = wd_create(); /* Create a watchdog timer */
+ priv->threshx = INVALID_THRESHOLD; /* Initialize thresholding logic */
+ priv->threshy = INVALID_THRESHOLD; /* Initialize thresholding logic */
+
+ sem_init(&priv->devsem, 0, 1); /* Initialize device structure semaphore */
+ sem_init(&priv->waitsem, 0, 0); /* Initialize pen event wait semaphore */
+
+ /* Make sure that interrupts are disabled */
+
+ config->clear(config);
+ config->enable(config, false);
+
+ /* Attach the interrupt handler */
+
+ ret = config->attach(config, max11802_interrupt);
+ if (ret < 0)
+ {
+ idbg("Failed to attach interrupt\n");
+ goto errout_with_priv;
+ }
+
+ idbg("Mode: %d Bits: 8 Frequency: %d\n",
+ CONFIG_MAX11802_SPIMODE, CONFIG_MAX11802_FREQUENCY);
+
+ /* Lock the SPI bus so that we have exclusive access */
+
+ max11802_lock(spi);
+
+ /* Configure the SPI interface */
+
+ max11802_configspi(spi);
+
+ /* Configure MAX11802 registers */
+ SPI_SELECT(priv->spi, SPIDEV_TOUCHSCREEN, true);
+ (void)SPI_SEND(priv->spi, MAX11802_CMD_MODE_WR);
+ (void)SPI_SEND(priv->spi, MAX11802_MODE);
+ SPI_SELECT(priv->spi, SPIDEV_TOUCHSCREEN, false);
+
+ SPI_SELECT(priv->spi, SPIDEV_TOUCHSCREEN, true);
+ (void)SPI_SEND(priv->spi, MAX11802_CMD_AVG_WR);
+ (void)SPI_SEND(priv->spi, MAX11802_AVG);
+ SPI_SELECT(priv->spi, SPIDEV_TOUCHSCREEN, false);
+
+ SPI_SELECT(priv->spi, SPIDEV_TOUCHSCREEN, true);
+ (void)SPI_SEND(priv->spi, MAX11802_CMD_TIMING_WR);
+ (void)SPI_SEND(priv->spi, MAX11802_TIMING);
+ SPI_SELECT(priv->spi, SPIDEV_TOUCHSCREEN, false);
+
+ SPI_SELECT(priv->spi, SPIDEV_TOUCHSCREEN, true);
+ (void)SPI_SEND(priv->spi, MAX11802_CMD_DELAY_WR);
+ (void)SPI_SEND(priv->spi, MAX11802_DELAY);
+ SPI_SELECT(priv->spi, SPIDEV_TOUCHSCREEN, false);
+
+ /* Test that the device access was successful. */
+ SPI_SELECT(priv->spi, SPIDEV_TOUCHSCREEN, true);
+ (void)SPI_SEND(priv->spi, MAX11802_CMD_MODE_RD);
+ ret = SPI_SEND(priv->spi, 0);
+ SPI_SELECT(priv->spi, SPIDEV_TOUCHSCREEN, false);
+
+ /* Unlock the bus */
+ max11802_unlock(spi);
+
+ if (ret != MAX11802_MODE)
+ {
+ idbg("max11802 mode readback failed: %02x\n", ret);
+ goto errout_with_priv;
+ }
+
+ /* Register the device as an input device */
+
+ (void)snprintf(devname, DEV_NAMELEN, DEV_FORMAT, minor);
+ ivdbg("Registering %s\n", devname);
+
+ ret = register_driver(devname, &max11802_fops, 0666, priv);
+ if (ret < 0)
+ {
+ idbg("register_driver() failed: %d\n", ret);
+ goto errout_with_priv;
+ }
+
+ /* If multiple MAX11802 devices are supported, then we will need to add
+ * this new instance to a list of device instances so that it can be
+ * found by the interrupt handler based on the recieved IRQ number.
+ */
+
+#ifdef CONFIG_MAX11802_MULTIPLE
+ priv->flink = g_max11802list;
+ g_max11802list = priv;
+ irqrestore(flags);
+#endif
+
+ /* Schedule work to perform the initial sampling and to set the data
+ * availability conditions.
+ */
+
+ ret = work_queue(HPWORK, &priv->work, max11802_worker, priv, 0);
+ if (ret != 0)
+ {
+ idbg("Failed to queue work: %d\n", ret);
+ goto errout_with_priv;
+ }
+
+ /* And return success (?) */
+
+ return OK;
+
+errout_with_priv:
+ sem_destroy(&priv->devsem);
+#ifdef CONFIG_MAX11802_MULTIPLE
+ kfree(priv);
+#endif
+ return ret;
+}
diff --git a/nuttx/drivers/input/max11802.h b/nuttx/drivers/input/max11802.h
new file mode 100644
index 000000000..b6beec045
--- /dev/null
+++ b/nuttx/drivers/input/max11802.h
@@ -0,0 +1,167 @@
+/********************************************************************************************
+ * drivers/input/max11802.h
+ *
+ * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
+ * Authors: Gregory Nutt <gnutt@nuttx.org>
+ * Petteri Aimonen <jpa@nx.mail.kapsi.fi>
+ *
+ * References:
+ * "Low-Power, Ultra-Small Resistive Touch-Screen Controllers
+ * with I2C/SPI Interface" Maxim IC, Rev 3, 10/2010
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ********************************************************************************************/
+
+#ifndef __DRIVERS_INPUT_MAX11802_H
+#define __DRIVERS_INPUT_MAX11802_H
+
+/********************************************************************************************
+ * Included Files
+ ********************************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdint.h>
+#include <semaphore.h>
+#include <poll.h>
+#include <wdog.h>
+#include <nuttx/wqueue.h>
+
+#include <nuttx/spi.h>
+#include <nuttx/clock.h>
+#include <nuttx/input/max11802.h>
+
+/********************************************************************************************
+ * Pre-Processor Definitions
+ ********************************************************************************************/
+/* Configuration ****************************************************************************/
+
+/* MAX11802 Interfaces *********************************************************************/
+
+/* LSB of register addresses specifies read (1) or write (0). */
+#define MAX11802_CMD_XPOSITION ((0x52 << 1) | 1)
+#define MAX11802_CMD_YPOSITION ((0x54 << 1) | 1)
+#define MAX11802_CMD_MEASUREXY (0x70 << 1)
+#define MAX11802_CMD_MODE_WR (0x0B << 1)
+#define MAX11802_CMD_MODE_RD ((0x0B << 1) | 1)
+#define MAX11802_CMD_AVG_WR (0x03 << 1)
+#define MAX11802_CMD_TIMING_WR (0x05 << 1)
+#define MAX11802_CMD_DELAY_WR (0x06 << 1)
+
+/* Register values to set */
+#define MAX11802_MODE 0x0E
+#define MAX11802_AVG 0x55
+#define MAX11802_TIMING 0x77
+#define MAX11802_DELAY 0x55
+
+/* Driver support **************************************************************************/
+/* This format is used to construct the /dev/input[n] device driver path. It
+ * defined here so that it will be used consistently in all places.
+ */
+
+#define DEV_FORMAT "/dev/input%d"
+#define DEV_NAMELEN 16
+
+/* Poll the pen position while the pen is down at this rate (50MS): */
+
+#define MAX11802_WDOG_DELAY ((50 + (MSEC_PER_TICK-1))/ MSEC_PER_TICK)
+
+/********************************************************************************************
+ * Public Types
+ ********************************************************************************************/
+
+/* This describes the state of one contact */
+
+enum max11802_contact_3
+{
+ CONTACT_NONE = 0, /* No contact */
+ CONTACT_DOWN, /* First contact */
+ CONTACT_MOVE, /* Same contact, possibly different position */
+ CONTACT_UP, /* Contact lost */
+};
+
+/* This structure describes the results of one MAX11802 sample */
+
+struct max11802_sample_s
+{
+ uint8_t id; /* Sampled touch point ID */
+ uint8_t contact; /* Contact state (see enum ads7843e_contact_e) */
+ bool valid; /* True: x,y contain valid, sampled data */
+ uint16_t x; /* Measured X position */
+ uint16_t y; /* Measured Y position */
+};
+
+/* This structure describes the state of one MAX11802 driver instance */
+
+struct max11802_dev_s
+{
+#ifdef CONFIG_ADS7843E_MULTIPLE
+ FAR struct ads7843e_dev_s *flink; /* Supports a singly linked list of drivers */
+#endif
+ uint8_t nwaiters; /* Number of threads waiting for MAX11802 data */
+ uint8_t id; /* Current touch point ID */
+ volatile bool penchange; /* An unreported event is buffered */
+ uint16_t threshx; /* Thresholding X value */
+ uint16_t threshy; /* Thresholding Y value */
+ sem_t devsem; /* Manages exclusive access to this structure */
+ sem_t waitsem; /* Used to wait for the availability of data */
+
+ FAR struct max11802_config_s *config; /* Board configuration data */
+ FAR struct spi_dev_s *spi; /* Saved SPI driver instance */
+ struct work_s work; /* Supports the interrupt handling "bottom half" */
+ struct max11802_sample_s sample; /* Last sampled touch point data */
+ WDOG_ID wdog; /* Poll the position while the pen is down */
+
+ /* The following is a list if poll structures of threads waiting for
+ * driver events. The 'struct pollfd' reference for each open is also
+ * retained in the f_priv field of the 'struct file'.
+ */
+
+#ifndef CONFIG_DISABLE_POLL
+ struct pollfd *fds[CONFIG_ADS7843E_NPOLLWAITERS];
+#endif
+};
+
+/********************************************************************************************
+ * Public Function Prototypes
+ ********************************************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C" {
+#else
+#define EXTERN extern
+#endif
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __DRIVERS_INPUT_ADS7843E_H */
diff --git a/nuttx/drivers/lcd/Kconfig b/nuttx/drivers/lcd/Kconfig
index 640239e63..2d20003ac 100644
--- a/nuttx/drivers/lcd/Kconfig
+++ b/nuttx/drivers/lcd/Kconfig
@@ -183,12 +183,85 @@ config NOKIA6100_RGBORD
endif
config LCD_UG9664HSWAG01
- bool "9664HSWAG01 OLED Display Module"
+ bool "UG-9664HSWAG01 OLED Display Module"
default n
---help---
- ug-9664hswag01.c. OLED Display Module, UG-9664HSWAG01", Univision
- Technology Inc. Used with the LPC Xpresso and Embedded Artists
- base board.
+ OLED Display Module, UG-9664HSWAG01, Univision Technology Inc. Used
+ with the LPCXpresso and Embedded Artists base board.
+
+ Required LCD driver settings:
+ LCD_MAXCONTRAST should be 255, but any value >0 and <=255 will be accepted.
+ LCD_MAXPOWER should be 1: 0=off, 1=on
+
+ Required SPI driver settings:
+ SPI_CMDDATA - Include support for cmd/data selection.
+
+if LCD_UG9664HSWAG01
+
+config UG9664HSWAG01_SPIMODE
+ int "UG-9664HSWAG01 SPI Mode"
+ default 0
+ ---help---
+ Controls the SPI mode
+
+config UG9664HSWAG01_FREQUENCY
+ int "UG-9664HSWAG01 SPI Frequency"
+ default 3500000
+ ---help---
+ Define to use a different bus frequency
+
+config UG9664HSWAG01_NINTERFACES
+ int "Number of UG-9664HSWAG01 Devices"
+ default 1
+ ---help---
+ Specifies the number of physical UG-9664HSWAG01 devices that will be
+ supported. NOTE: At present, this must be undefined or defined to be 1.
+
+config UG9664HSWAG01_POWER
+ bool "Power control"
+ default n
+ ---help---
+ If the hardware supports a controllable OLED a power supply, this
+ configuration should be defined. In this case the system must
+ provide an interface ug_power().
+
+endif
+
+config LCD_UG2864AMBAG01
+ bool "UG-2864AMBAG01 OLED Display Module"
+ default n
+ ---help---
+ OLED Display Module, UG-2864AMBAG01, Univision Technology Inc.
+
+ Required LCD driver settings:
+ LCD_MAXCONTRAST should be 255, but any value >0 and <=255 will be accepted.
+ LCD_MAXPOWER should be 1: 0=off, 1=on
+
+ Required SPI driver settings:
+ SPI_CMDDATA - Include support for cmd/data selection.
+
+if LCD_UG2864AMBAG01
+
+ config UG2864AMBAG01_SPIMODE
+ int "UG-2864AMBAG01 SPI Mode"
+ default 3
+ ---help---
+ Controls the SPI mode
+
+config UG2864AMBAG01_FREQUENCY
+ int "UG-2864AMBAG01 SPI Frequency"
+ default 3500000
+ ---help---
+ Define to use a different bus frequency
+
+config UG2864AMBAG01_NINTERFACES
+ int "Number of UG-2864AMBAG01 Devices"
+ default 1
+ ---help---
+ Specifies the number of physical UG-9664HSWAG01 devices that will be
+ supported. NOTE: At present, this must be undefined or defined to be 1.
+
+endif
config LCD_SSD1289
bool "LCD Based on SSD1289 Controller"
diff --git a/nuttx/drivers/lcd/Make.defs b/nuttx/drivers/lcd/Make.defs
index 26b169391..1b445b6a7 100644
--- a/nuttx/drivers/lcd/Make.defs
+++ b/nuttx/drivers/lcd/Make.defs
@@ -47,6 +47,10 @@ ifeq ($(CONFIG_LCD_NOKIA6100),y)
CSRCS += nokia6100.c
endif
+ifeq ($(CONFIG_LCD_UG2864AMBAG01),y)
+ CSRCS += ug-2864ambag01.c
+endif
+
ifeq ($(CONFIG_LCD_UG9664HSWAG01),y)
CSRCS += ug-9664hswag01.c
endif
@@ -63,6 +67,6 @@ endif
DEPPATH += --dep-path lcd
VPATH += :lcd
-CFLAGS += ${shell $(TOPDIR)/tools/incdir.sh $(INCDIROPT) "$(CC)" $(TOPDIR)/drivers/lcd}
+CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)drivers$(DELIM)lcd}
endif
diff --git a/nuttx/drivers/lcd/ug-2864ambag01.c b/nuttx/drivers/lcd/ug-2864ambag01.c
new file mode 100644
index 000000000..2a47b38eb
--- /dev/null
+++ b/nuttx/drivers/lcd/ug-2864ambag01.c
@@ -0,0 +1,1161 @@
+/**************************************************************************************
+ * drivers/lcd/ug-2864ambag01.c
+ * Driver for Univision UG-2864AMBAG01 OLED display (wih SH1101A controller) in SPI
+ * mode
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * References:
+ * 1. Product Specification (Preliminary), Part Name: OEL Display Module, Part ID:
+ * UG-2864AMBAG01, Doc No: SASI-9015-A, Univision Technology Inc.
+ * 2. SH1101A, 132 X 64 Dot Matrix OLED/PLED, Preliminary Segment/Common Driver with
+ * Controller, Sino Wealth
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ **************************************************************************************/
+/**************************************************************************************
+ * Device memory organization:
+ *
+ * +----------------------------+
+ * | Column |
+ * --------+----+---+---+---+-...-+-----+
+ * Page | 0 | 1 | 2 | 3 | ... | 131 |
+ * --------+----+---+---+---+-...-+-----+
+ * Page 0 | D0 | X | | | | |
+ * | D1 | X | | | | |
+ * | D2 | X | | | | |
+ * | D3 | X | | | | |
+ * | D4 | X | | | | |
+ * | D5 | X | | | | |
+ * | D6 | X | | | | |
+ * | D7 | X | | | | |
+ * --------+----+---+---+---+-...-+-----+
+ * Page 1 | | | | | | |
+ * --------+----+---+---+---+-...-+-----+
+ * Page 2 | | | | | | |
+ * --------+----+---+---+---+-...-+-----+
+ * Page 3 | | | | | | |
+ * --------+----+---+---+---+-...-+-----+
+ * Page 4 | | | | | | |
+ * --------+----+---+---+---+-...-+-----+
+ * Page 5 | | | | | | |
+ * --------+----+---+---+---+-...-+-----+
+ * Page 6 | | | | | | |
+ * --------+----+---+---+---+-...-+-----+
+ * Page 7 | | | | | | |
+ * --------+----+---+---+---+-...-+-----+
+ *
+ * -----------------------------------+---------------------------------------
+ * Landscape Display: | Reverse Landscape Display:
+ * --------+-----------------------+ | --------+---------------------------+
+ * | Column | | | Column |
+ * --------+---+---+---+-...-+-----+ | --------+-----+-----+-----+-...-+---+
+ * Page 0 | 0 | 1 | 2 | | 131 | | Page 7 | 131 | 130 | 129 | | 0 |
+ * --------+---+---+---+-...-+-----+ | --------+-----+-----+-----+-...-+---+
+ * Page 1 | V | | Page 6 | ^ |
+ * --------+---+---+---+-...-+-----+ | --------+-----+-----+-----+-...-+---+
+ * Page 2 | V | | Page 5 | ^ |
+ * --------+---+---+---+-...-+-----+ | --------+-----+-----+-----+-...-+---+
+ * Page 3 | V | | Page 4 | ^ |
+ * --------+---+---+---+-...-+-----+ | --------+-----+-----+-----+-...-+---+
+ * Page 4 | V | | Page 3 | ^ |
+ * --------+---+---+---+-...-+-----+ | --------+-----+-----+-----+-...-+---+
+ * Page 5 | V | | Page 2 | ^ |
+ * --------+---+---+---+-...-+-----+ | --------+-----+-----+-----+-...-+---+
+ * Page 6 | V | | Page 1 | ^ |
+ * --------+---+---+---+-...-+-----+ | --------+-----+-----+-----+-...-+---+
+ * Page 7 | V | | Page 0 | ^ |
+ * --------+---+---+---+-...-+-----+ | --------+-----+-----+-----+-...-+---+
+ * -----------------------------------+---------------------------------------
+ *
+ * -----------------------------------+---------------------------------------
+ * Portrait Display: | Reverse Portrait Display:
+ * -----------+---------------------+ | -----------+---------------------+
+ * | Page | | | Page |
+ * -----------+---+---+---+-...-+---+ | -----------+---+---+---+-...-+---+
+ * Column 0 | 0 | 1 | 2 | | 7 | | Column 131 | 7 | 6 | 5 | | 0 |
+ * -----------+---+---+---+-...-+---+ | -----------+---+---+---+-...-+---+
+ * Column 1 | > > > > > | | Column 130 | |
+ * -----------+---+---+---+-...-+---+ | -----------+---+---+---+-...-+---+
+ * Column 2 | | | Column 129 | |
+ * -----------+---+---+---+-...-+---+ | -----------+---+---+---+-...-+---+
+ * ... | | | ... | |
+ * -----------+---+---+---+-...-+---+ | -----------+---+---+---+-...-+---+
+ * Column 131 | | | Column 0 | < < < < < |
+ * -----------+---+---+---+-...-+---+ | -----------+---+---+---+-...-+---+
+ * -----------------------------------+----------------------------------------
+ **************************************************************************************/
+
+/**************************************************************************************
+ * Included Files
+ **************************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <string.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/arch.h>
+#include <nuttx/spi.h>
+#include <nuttx/lcd/lcd.h>
+#include <nuttx/lcd/ug-2864ambag01.h>
+
+#include <arch/irq.h>
+
+#ifdef CONFIG_LCD_UG2864AMBAG01
+
+/**************************************************************************************
+ * Pre-processor Definitions
+ **************************************************************************************/
+/* Configuration **********************************************************************/
+/* Limitations of the current configuration that I hope to fix someday */
+
+#if CONFIG_UG2864AMBAG01_NINTERFACES != 1
+# warning "This implementation supports only a single OLED device"
+# undef CONFIG_UG2864AMBAG01_NINTERFACES
+# define CONFIG_UG2864AMBAG01_NINTERFACES 1
+#endif
+
+#if defined(CONFIG_LCD_PORTRAIT) || defined(CONFIG_LCD_RPORTRAIT)
+# warning "No support yet for portrait modes"
+# define CONFIG_LCD_LANDSCAPE 1
+# undef CONFIG_LCD_PORTRAIT
+# undef CONFIG_LCD_RLANDSCAPE
+# undef CONFIG_LCD_RPORTRAIT
+#elif defined(CONFIG_LCD_RLANDSCAPE)
+# warning "Reverse landscape mode is untested and, hence, probably buggy"
+#endif
+
+/* SH1101A Commands *******************************************************************/
+
+#define SH1101A_SETCOLL(ad) (0x00 | ((ad) & 0x0f)) /* Set Lower Column Address: (00h - 0fh) */
+#define SH1101A_SETCOLH(ad) (0x10 | ((ad) & 0x0f)) /* Set Higher Column Address: (10h - 1fh) */
+#define SH1101A_STARTLINE(ln) (0x40 | ((ln) & 0x3f)) /* Set Display Start Line: (40h - 7fh) */
+#define SH1101A_CONTRAST_MODE (0x81) /* Set Contrast Control Register: (Double Bytes Command) */
+# define SH1101A_CONTRAST(c) (c)
+#define SH1101A_SEGREMAP(m) (0xa0 | ((m) & 0x01)) /* Set Segment Re-map: (a0h - a1h) */
+# define SH1101A_REMAPRIGHT SH1101A_SEGREMAP(0) /* Right rotation */
+# define SH1101A_REMAPPLEFT SH1101A_SEGREMAP(1) /* Left rotation */
+#define SH1101A_EDISPOFFON(s) (0xa4 | ((s) & 0x01)) /* Set Entire Display OFF/ON: (a4h - a5h) */
+# define SH1101A_EDISPOFF SH1101A_EDISPOFFON(0) /* Display off */
+# define SH1101A_EDISPON SH1101A_EDISPOFFON(1) /* Display on */
+#define SH1101A_NORMREV(s) (0xa6 | ((s) & 0x01)) /* Set Normal/Reverse Display: (a6h -a7h) */
+# define SH1101A_NORMAL SH1101A_NORMREV(0) /* Normal display */
+# define SH1101A_REVERSE SH1101A_NORMREV(1) /* Reverse display */
+#define SH1101A_MRATIO_MODE (0xa8) /* Set Multiplex Ration: (Double Bytes Command) */
+# define SH1101A_MRATIO(d) ((d) & 0x3f)
+#define SH1101A_DCDC_MODE (0xad) /* Set DC-DC OFF/ON: (Double Bytes Command) */
+# define SH1101A_DCDC_OFF (0x8a)
+ # define SH1101A_DCDC_ON (0x8b)
+#define SH1101A_DISPOFFON(s) (0xae | ((s) & 0x01)) /* Display OFF/ON: (aeh - afh) */
+# define SH1101A_DISPOFF SH1101A_DISPOFFON(0) /* Display off */
+# define SH1101A_DISPON SH1101A_DISPOFFON(1) /* Display on */
+#define SH1101A_PAGEADDR(a) (0xb0 | ((a) & 0x0f)) /* Set Page Address: (b0h - b7h) */
+#define SH1101A_SCANDIR(d) (0xc0 | ((d) & 0x08)) /* Set Common Output Scan Direction: (c0h - c8h) */
+# define SH1101A_SCANFROMCOM0 SH1101A_SCANDIR(0x00) /* Scan from COM[0] to COM[n-1]*/
+# define SH1101A_SCANTOCOM0 SH1101A_SCANDIR(0x08) /* Scan from COM[n-1] to COM[0] */
+#define SH1101A_DISPOFFS_MODE (0xd3) /* Set Display Offset: (Double Bytes Command) */
+# define SH1101A_DISPOFFS(o) ((o) & 0x3f)
+#define SH1101A_CLKDIV_SET (0xd5) /* Set Display Clock Divide Ratio/Oscillator Frequency: (Double Bytes Command) */
+# define SH1101A_CLKDIV(f,d) ((((f) & 0x0f) << 4) | ((d) & 0x0f))
+#define SH1101A_CHRGPER_SET (0xd9) /* Set Dis-charge/Pre-charge Period: (Double Bytes Command) */
+# define SH1101A_CHRGPER(d,p) ((((d) & 0x0f) << 4) | ((p) & 0x0f))
+#define SH1101A_CMNPAD_CONFIG (0xda) /* Set Common pads hardware configuration: (Double Bytes Command) */
+ #define SH1101A_CMNPAD(c) ((0x02) | ((c) & 0x10))
+#define SH1101A_VCOM_SET (0xdb) /* Set VCOM Deselect Level: (Double Bytes Command) */
+# define SH1101A_VCOM(v) (v)
+#define SH1101A_RMWSTART (0xe0) /* Read-Modify-Write: (e0h) */
+#define SH1101A_NOP (0xe3) /* NOP: (e3h) */
+#define SH1101A_END (0xee) /* End: (eeh) */
+
+#define SH1101A_WRDATA(d) (d) /* Write Display Data */
+#define SH1101A_STATUS_BUSY (0x80) /* Read Status */
+#define SH1101A_STATUS_ONOFF (0x40)
+#define SH1101A_RDDATA(d) (d) /* Read Display Data */
+
+/* Color Properties *******************************************************************/
+/* Display Resolution
+ *
+ * The SH1101A display controller can handle a resolution of 132x64. The UG-2864AMBAG01
+ * on the base board is 128x64.
+ */
+
+#define UG2864AMBAG01_DEV_XRES 128 /* Only 128 of 131 columns used */
+#define UG2864AMBAG01_DEV_YRES 64 /* 8 pages each 8 rows */
+#define UG2864AMBAG01_DEV_XOFFSET 2 /* Offset to logical column 0 */
+#define UG2864AMBAG01_DEV_PAGES 8 /* 8 pages */
+
+#if defined(CONFIG_LCD_LANDSCAPE) || defined(CONFIG_LCD_RLANDSCAPE)
+# define UG2864AMBAG01_XRES UG2864AMBAG01_DEV_XRES
+# define UG2864AMBAG01_YRES UG2864AMBAG01_DEV_YRES
+#else
+# define UG2864AMBAG01_XRES UG2864AMBAG01_DEV_YRES
+# define UG2864AMBAG01_YRES UG2864AMBAG01_DEV_XRES
+#endif
+
+/* Color depth and format */
+
+#define UG2864AMBAG01_BPP 1
+#define UG2864AMBAG01_COLORFMT FB_FMT_Y1
+
+/* Bytes per logical row and actual device row */
+
+#define UG2864AMBAG01_XSTRIDE (UG2864AMBAG01_XRES >> 3)
+#define UG2864AMBAG01_YSTRIDE (UG2864AMBAG01_YRES >> 3)
+
+/* Default contrast */
+
+#define UG2864AMBAG01_CONTRAST (128)
+
+/* The size of the shadow frame buffer or one row buffer.
+ *
+ * Frame buffer size: 128 columns x 64 rows / 8 bits-per-pixel
+ * Row size: 128 columns x 8 rows-per-page / 8 bits-per-pixel
+ */
+
+#define UG2864AMBAG01_FBSIZE (UG2864AMBAG01_XSTRIDE * UG2864AMBAG01_YRES)
+#define UG2864AMBAG01_ROWSIZE (UG2864AMBAG01_XSTRIDE)
+
+/* Bit helpers */
+
+#define LS_BIT (1 << 0)
+#define MS_BIT (1 << 7)
+
+/* Debug ******************************************************************************/
+
+#ifdef CONFIG_DEBUG_LCD
+# define lcddbg(format, arg...) dbg(format, ##arg)
+# define lcdvdbg(format, arg...) vdbg(format, ##arg)
+#else
+# define lcddbg(x...)
+# define lcdvdbg(x...)
+#endif
+
+/**************************************************************************************
+ * Private Type Definition
+ **************************************************************************************/
+
+/* This structure describes the state of this driver */
+
+struct ug2864ambag01_dev_s
+{
+ struct lcd_dev_s dev; /* Publically visible device structure */
+
+ /* Private LCD-specific information follows */
+
+ FAR struct spi_dev_s *spi; /* Cached SPI device reference */
+ uint8_t contrast; /* Current contrast setting */
+ bool on; /* true: display is on */
+
+
+ /* The SH1101A does not support reading from the display memory in SPI mode.
+ * Since there is 1 BPP and access is byte-by-byte, it is necessary to keep
+ * a shadow copy of the framebuffer memory. At 128x64, this amounts to 1KB.
+ */
+
+ uint8_t fb[UG2864AMBAG01_FBSIZE];
+};
+
+/**************************************************************************************
+ * Private Function Protototypes
+ **************************************************************************************/
+
+/* Low-level SPI helpers */
+
+#ifdef CONFIG_SPI_OWNBUS
+static inline void ug2864ambag01_configspi(FAR struct spi_dev_s *spi);
+# define ug2864ambag01_lock(spi)
+# define ug2864ambag01_unlock(spi)
+#else
+# define ug2864ambag01_configspi(spi)
+static void ug2864ambag01_lock(FAR struct spi_dev_s *spi);
+static void ug2864ambag01_unlock(FAR struct spi_dev_s *spi);
+#endif
+
+/* LCD Data Transfer Methods */
+
+static int ug2864ambag01_putrun(fb_coord_t row, fb_coord_t col,
+ FAR const uint8_t *buffer, size_t npixels);
+static int ug2864ambag01_getrun(fb_coord_t row, fb_coord_t col, FAR uint8_t *buffer,
+ size_t npixels);
+
+/* LCD Configuration */
+
+static int ug2864ambag01_getvideoinfo(FAR struct lcd_dev_s *dev,
+ FAR struct fb_videoinfo_s *vinfo);
+static int ug2864ambag01_getplaneinfo(FAR struct lcd_dev_s *dev, unsigned int planeno,
+ FAR struct lcd_planeinfo_s *pinfo);
+
+/* LCD RGB Mapping */
+
+#ifdef CONFIG_FB_CMAP
+# error "RGB color mapping not supported by this driver"
+#endif
+
+/* Cursor Controls */
+
+#ifdef CONFIG_FB_HWCURSOR
+# error "Cursor control not supported by this driver"
+#endif
+
+/* LCD Specific Controls */
+
+static int ug2864ambag01_getpower(struct lcd_dev_s *dev);
+static int ug2864ambag01_setpower(struct lcd_dev_s *dev, int power);
+static int ug2864ambag01_getcontrast(struct lcd_dev_s *dev);
+static int ug2864ambag01_setcontrast(struct lcd_dev_s *dev, unsigned int contrast);
+
+/**************************************************************************************
+ * Private Data
+ **************************************************************************************/
+
+/* This is working memory allocated by the LCD driver for each LCD device
+ * and for each color plane. This memory will hold one raster line of data.
+ * The size of the allocated run buffer must therefore be at least
+ * (bpp * xres / 8). Actual alignment of the buffer must conform to the
+ * bitwidth of the underlying pixel type.
+ *
+ * If there are multiple planes, they may share the same working buffer
+ * because different planes will not be operate on concurrently. However,
+ * if there are multiple LCD devices, they must each have unique run buffers.
+ */
+
+static uint8_t g_runbuffer[UG2864AMBAG01_ROWSIZE];
+
+/* This structure describes the overall LCD video controller */
+
+static const struct fb_videoinfo_s g_videoinfo =
+{
+ .fmt = UG2864AMBAG01_COLORFMT, /* Color format: RGB16-565: RRRR RGGG GGGB BBBB */
+ .xres = UG2864AMBAG01_XRES, /* Horizontal resolution in pixel columns */
+ .yres = UG2864AMBAG01_YRES, /* Vertical resolution in pixel rows */
+ .nplanes = 1, /* Number of color planes supported */
+};
+
+/* This is the standard, NuttX Plane information object */
+
+static const struct lcd_planeinfo_s g_planeinfo =
+{
+ .putrun = ug2864ambag01_putrun, /* Put a run into LCD memory */
+ .getrun = ug2864ambag01_getrun, /* Get a run from LCD memory */
+ .buffer = (uint8_t*)g_runbuffer, /* Run scratch buffer */
+ .bpp = UG2864AMBAG01_BPP, /* Bits-per-pixel */
+};
+
+/* This is the OLED driver instance (only a single device is supported for now) */
+
+static struct ug2864ambag01_dev_s g_oleddev =
+{
+ .dev =
+ {
+ /* LCD Configuration */
+
+ .getvideoinfo = ug2864ambag01_getvideoinfo,
+ .getplaneinfo = ug2864ambag01_getplaneinfo,
+
+ /* LCD RGB Mapping -- Not supported */
+ /* Cursor Controls -- Not supported */
+
+ /* LCD Specific Controls */
+
+ .getpower = ug2864ambag01_getpower,
+ .setpower = ug2864ambag01_setpower,
+ .getcontrast = ug2864ambag01_getcontrast,
+ .setcontrast = ug2864ambag01_setcontrast,
+ },
+};
+
+/**************************************************************************************
+ * Private Functions
+ **************************************************************************************/
+
+/**************************************************************************************
+ * Name: ug2864ambag01_configspi
+ *
+ * Description:
+ * Configure the SPI for use with the UG-2864AMBAG01
+ *
+ * Input Parameters:
+ * spi - Reference to the SPI driver structure
+ *
+ * Returned Value:
+ * None
+ *
+ * Assumptions:
+ *
+ **************************************************************************************/
+
+#ifdef CONFIG_SPI_OWNBUS
+static inline void ug2864ambag01_configspi(FAR struct spi_dev_s *spi)
+{
+ lcdvdbg("Mode: %d Bits: 8 Frequency: %d\n",
+ CONFIG_UG2864AMBAG01_SPIMODE, CONFIG_UG2864AMBAG01_FREQUENCY);
+
+ /* Configure SPI for the UG-2864AMBAG01. But only if we own the SPI bus. Otherwise,
+ * don't bother because it might change.
+ */
+
+ SPI_SETMODE(spi, CONFIG_UG2864AMBAG01_SPIMODE);
+ SPI_SETBITS(spi, 8);
+ SPI_SETFREQUENCY(spi, CONFIG_UG2864AMBAG01_FREQUENCY)
+}
+#endif
+
+/**************************************************************************************
+ * Name: ug2864ambag01_lock
+ *
+ * Description:
+ * Select the SPI, locking and re-configuring if necessary
+ *
+ * Input Parameters:
+ * spi - Reference to the SPI driver structure
+ *
+ * Returned Value:
+ * None
+ *
+ * Assumptions:
+ *
+ **************************************************************************************/
+
+#ifndef CONFIG_SPI_OWNBUS
+static inline void ug2864ambag01_lock(FAR struct spi_dev_s *spi)
+{
+ /* Lock the SPI bus if there are multiple devices competing for the SPI bus. */
+
+ SPI_LOCK(spi, true);
+
+ /* Now make sure that the SPI bus is configured for the UG-2864AMBAG01 (it
+ * might have gotten configured for a different device while unlocked)
+ */
+
+ SPI_SETMODE(spi, CONFIG_UG2864AMBAG01_SPIMODE);
+ SPI_SETBITS(spi, 8);
+ SPI_SETFREQUENCY(spi, CONFIG_UG2864AMBAG01_FREQUENCY);
+}
+#endif
+
+/**************************************************************************************
+ * Name: ug2864ambag01_unlock
+ *
+ * Description:
+ * De-select the SPI
+ *
+ * Input Parameters:
+ * spi - Reference to the SPI driver structure
+ *
+ * Returned Value:
+ * None
+ *
+ * Assumptions:
+ *
+ **************************************************************************************/
+
+#ifndef CONFIG_SPI_OWNBUS
+static inline void ug2864ambag01_unlock(FAR struct spi_dev_s *spi)
+{
+ /* De-select UG-2864AMBAG01 chip and relinquish the SPI bus. */
+
+ SPI_LOCK(spi, false);
+}
+#endif
+
+/**************************************************************************************
+ * Name: ug2864ambag01_putrun
+ *
+ * Description:
+ * This method can be used to write a partial raster line to the LCD.
+ *
+ * Input Parameters:
+ * row - Starting row to write to (range: 0 <= row < yres)
+ * col - Starting column to write to (range: 0 <= col <= xres-npixels)
+ * buffer - The buffer containing the run to be written to the LCD
+ * npixels - The number of pixels to write to the LCD
+ * (range: 0 < npixels <= xres-col)
+ *
+ **************************************************************************************/
+
+#if defined(CONFIG_LCD_LANDSCAPE) || defined(CONFIG_LCD_RLANDSCAPE)
+static int ug2864ambag01_putrun(fb_coord_t row, fb_coord_t col, FAR const uint8_t *buffer,
+ size_t npixels)
+{
+ /* Because of this line of code, we will only be able to support a single UG device */
+
+ FAR struct ug2864ambag01_dev_s *priv = (FAR struct ug2864ambag01_dev_s *)&g_oleddev;
+ FAR uint8_t *fbptr;
+ FAR uint8_t *ptr;
+ uint8_t devcol;
+ uint8_t fbmask;
+ uint8_t page;
+ uint8_t usrmask;
+ int pixlen;
+ uint8_t i;
+
+ lcdvdbg("row: %d col: %d npixels: %d\n", row, col, npixels);
+ DEBUGASSERT(buffer);
+
+ /* Clip the run to the display */
+
+ pixlen = npixels;
+ if ((unsigned int)col + (unsigned int)pixlen > (unsigned int)UG2864AMBAG01_XRES)
+ {
+ pixlen = (int)UG2864AMBAG01_XRES - (int)col;
+ }
+
+ /* Verify that some portion of the run remains on the display */
+
+ if (pixlen <= 0 || row > UG2864AMBAG01_YRES)
+ {
+ return OK;
+ }
+
+ /* Perform coordinate conversion for reverse landscape mode */
+
+#ifdef CONFIG_LCD_RLANDSCAPE
+ row = (UG2864AMBAG01_YRES-1) - row;
+ col = (UG2864AMBAG01_XRES-1) - col;
+#endif
+
+ /* Get the page number. The range of 64 lines is divided up into eight
+ * pages of 8 lines each.
+ */
+
+ page = row >> 3;
+
+ /* Update the shadow frame buffer memory. First determine the pixel
+ * position in the frame buffer memory. Pixels are organized like
+ * this:
+ *
+ * --------+---+---+---+---+-...-+-----+
+ * Segment | 0 | 1 | 2 | 3 | ... | 131 |
+ * --------+---+---+---+---+-...-+-----+
+ * D0 | | X | | | | |
+ * D1 | | X | | | | |
+ * D2 | | X | | | | |
+ * D3 | | X | | | | |
+ * D4 | | X | | | | |
+ * D5 | | X | | | | |
+ * D6 | | X | | | | |
+ * D7 | | X | | | | |
+ * --------+---+---+---+---+-...-+-----+
+ *
+ * So, in order to draw a white, horizontal line, at row 45. we
+ * would have to modify all of the bytes in page 45/8 = 5. We
+ * would have to set bit 45%8 = 5 in every byte in the page.
+ */
+
+ fbmask = 1 << (row & 7);
+ fbptr = &priv->fb[page * UG2864AMBAG01_XRES + col];
+#ifdef CONFIG_LCD_RLANDSCAPE
+ ptr = fbptr + pixlen - 1;
+#else
+ ptr = fbptr;
+#endif
+#ifdef CONFIG_NX_PACKEDMSFIRST
+ usrmask = MS_BIT;
+#else
+ usrmask = LS_BIT;
+#endif
+
+ for (i = 0; i < pixlen; i++)
+ {
+ /* Set or clear the corresponding bit */
+
+#ifdef CONFIG_LCD_RLANDSCAPE
+ if ((*buffer & usrmask) != 0)
+ {
+ *ptr-- |= fbmask;
+ }
+ else
+ {
+ *ptr-- &= ~fbmask;
+ }
+#else
+ if ((*buffer & usrmask) != 0)
+ {
+ *ptr++ |= fbmask;
+ }
+ else
+ {
+ *ptr++ &= ~fbmask;
+ }
+#endif
+
+ /* Inc/Decrement to the next source pixel */
+
+#ifdef CONFIG_NX_PACKEDMSFIRST
+ if (usrmask == LS_BIT)
+ {
+ buffer++;
+ usrmask = MS_BIT;
+ }
+ else
+ {
+ usrmask >>= 1;
+ }
+#else
+ if (usrmask == MS_BIT)
+ {
+ buffer++;
+ usrmask = LS_BIT;
+ }
+ else
+ {
+ usrmask <<= 1;
+ }
+#endif
+ }
+
+ /* Offset the column position to account for smaller horizontal
+ * display range.
+ */
+
+ devcol = col + UG2864AMBAG01_DEV_XOFFSET;
+
+ /* Lock and select device */
+
+ ug2864ambag01_lock(priv->spi);
+ SPI_SELECT(priv->spi, SPIDEV_DISPLAY, true);
+
+ /* Select command transfer */
+
+ SPI_CMDDATA(priv->spi, SPIDEV_DISPLAY, true);
+
+ /* Set the starting position for the run */
+ /* Set the column address to the XOFFSET value */
+
+ SPI_SEND(priv->spi, SH1101A_SETCOLL(devcol & 0x0f));
+ SPI_SEND(priv->spi, SH1101A_SETCOLH(devcol >> 4));
+
+ /* Set the page address */
+
+ SPI_SEND(priv->spi, SH1101A_PAGEADDR(page));
+
+ /* Select data transfer */
+
+ SPI_CMDDATA(priv->spi, SPIDEV_DISPLAY, false);
+
+ /* Then transfer all of the data */
+
+ (void)SPI_SNDBLOCK(priv->spi, fbptr, pixlen);
+
+ /* De-select and unlock the device */
+
+ SPI_SELECT(priv->spi, SPIDEV_DISPLAY, false);
+ ug2864ambag01_unlock(priv->spi);
+ return OK;
+}
+#else
+# error "Configuration not implemented"
+#endif
+
+/**************************************************************************************
+ * Name: ug2864ambag01_getrun
+ *
+ * Description:
+ * This method can be used to read a partial raster line from the LCD:
+ *
+ * Description:
+ * This method can be used to write a partial raster line to the LCD.
+ *
+ * row - Starting row to read from (range: 0 <= row < yres)
+ * col - Starting column to read read (range: 0 <= col <= xres-npixels)
+ * buffer - The buffer in which to return the run read from the LCD
+ * npixels - The number of pixels to read from the LCD
+ * (range: 0 < npixels <= xres-col)
+ *
+ **************************************************************************************/
+
+#if defined(CONFIG_LCD_LANDSCAPE) || defined(CONFIG_LCD_RLANDSCAPE)
+static int ug2864ambag01_getrun(fb_coord_t row, fb_coord_t col, FAR uint8_t *buffer,
+ size_t npixels)
+{
+ /* Because of this line of code, we will only be able to support a single UG device */
+
+ FAR struct ug2864ambag01_dev_s *priv = &g_oleddev;
+ FAR uint8_t *fbptr;
+ uint8_t page;
+ uint8_t fbmask;
+ uint8_t usrmask;
+ int pixlen;
+ uint8_t i;
+
+ lcdvdbg("row: %d col: %d npixels: %d\n", row, col, npixels);
+ DEBUGASSERT(buffer);
+
+ /* Clip the run to the display */
+
+ pixlen = npixels;
+ if ((unsigned int)col + (unsigned int)pixlen > (unsigned int)UG2864AMBAG01_XRES)
+ {
+ pixlen = (int)UG2864AMBAG01_XRES - (int)col;
+ }
+
+ /* Verify that some portion of the run is actually the display */
+
+ if (pixlen <= 0 || row > UG2864AMBAG01_YRES)
+ {
+ return -EINVAL;
+ }
+
+ /* Perform coordinate conversion for reverse landscape mode */
+
+#ifdef CONFIG_LCD_RLANDSCAPE
+ row = (UG2864AMBAG01_YRES-1) - row;
+ col = (UG2864AMBAG01_XRES-1) - col;
+#endif
+
+ /* Then transfer the display data from the shadow frame buffer memory */
+ /* Get the page number. The range of 64 lines is divided up into eight
+ * pages of 8 lines each.
+ */
+
+ page = row >> 3;
+
+ /* Update the shadow frame buffer memory. First determine the pixel
+ * position in the frame buffer memory. Pixels are organized like
+ * this:
+ *
+ * --------+---+---+---+---+-...-+-----+
+ * Segment | 0 | 1 | 2 | 3 | ... | 131 |
+ * --------+---+---+---+---+-...-+-----+
+ * D0 | | X | | | | |
+ * D1 | | X | | | | |
+ * D2 | | X | | | | |
+ * D3 | | X | | | | |
+ * D4 | | X | | | | |
+ * D5 | | X | | | | |
+ * D6 | | X | | | | |
+ * D7 | | X | | | | |
+ * --------+---+---+---+---+-...-+-----+
+ *
+ * So, in order to draw a white, horizontal line, at row 45. we
+ * would have to modify all of the bytes in page 45/8 = 5. We
+ * would have to set bit 45%8 = 5 in every byte in the page.
+ */
+
+ fbmask = 1 << (row & 7);
+#ifdef CONFIG_LCD_RLANDSCAPE
+ fbptr = &priv->fb[page * (UG2864AMBAG01_XRES-1) + col + pixlen];
+#else
+ fbptr = &priv->fb[page * UG2864AMBAG01_XRES + col];
+#endif
+#ifdef CONFIG_NX_PACKEDMSFIRST
+ usrmask = MS_BIT;
+#else
+ usrmask = LS_BIT;
+#endif
+
+ *buffer = 0;
+ for (i = 0; i < pixlen; i++)
+ {
+ /* Set or clear the corresponding bit */
+
+#ifdef CONFIG_LCD_RLANDSCAPE
+ uint8_t byte = *fbptr--;
+#else
+ uint8_t byte = *fbptr++;
+#endif
+ if ((byte & fbmask) != 0)
+ {
+ *buffer |= usrmask;
+ }
+
+ /* Inc/Decrement to the next destination pixel. Hmmmm. It looks like
+ * this logic could write past the end of the user buffer. Revisit
+ * this!
+ */
+
+#ifdef CONFIG_NX_PACKEDMSFIRST
+ if (usrmask == LS_BIT)
+ {
+ buffer++;
+ *buffer = 0;
+ usrmask = MS_BIT;
+ }
+ else
+ {
+ usrmask >>= 1;
+ }
+#else
+ if (usrmask == MS_BIT)
+ {
+ buffer++;
+ *buffer = 0;
+ usrmask = LS_BIT;
+ }
+ else
+ {
+ usrmask <<= 1;
+ }
+#endif
+ }
+
+ return OK;
+}
+#else
+# error "Configuration not implemented"
+#endif
+
+/**************************************************************************************
+ * Name: ug2864ambag01_getvideoinfo
+ *
+ * Description:
+ * Get information about the LCD video controller configuration.
+ *
+ **************************************************************************************/
+
+static int ug2864ambag01_getvideoinfo(FAR struct lcd_dev_s *dev,
+ FAR struct fb_videoinfo_s *vinfo)
+{
+ DEBUGASSERT(dev && vinfo);
+ lcdvdbg("fmt: %d xres: %d yres: %d nplanes: %d\n",
+ g_videoinfo.fmt, g_videoinfo.xres, g_videoinfo.yres, g_videoinfo.nplanes);
+ memcpy(vinfo, &g_videoinfo, sizeof(struct fb_videoinfo_s));
+ return OK;
+}
+
+/**************************************************************************************
+ * Name: ug2864ambag01_getplaneinfo
+ *
+ * Description:
+ * Get information about the configuration of each LCD color plane.
+ *
+ **************************************************************************************/
+
+static int ug2864ambag01_getplaneinfo(FAR struct lcd_dev_s *dev, unsigned int planeno,
+ FAR struct lcd_planeinfo_s *pinfo)
+{
+ DEBUGASSERT(pinfo && planeno == 0);
+ lcdvdbg("planeno: %d bpp: %d\n", planeno, g_planeinfo.bpp);
+ memcpy(pinfo, &g_planeinfo, sizeof(struct lcd_planeinfo_s));
+ return OK;
+}
+
+/**************************************************************************************
+ * Name: ug2864ambag01_getpower
+ *
+ * Description:
+ * Get the LCD panel power status (0: full off - CONFIG_LCD_MAXPOWER: full on. On
+ * backlit LCDs, this setting may correspond to the backlight setting.
+ *
+ **************************************************************************************/
+
+static int ug2864ambag01_getpower(FAR struct lcd_dev_s *dev)
+{
+ FAR struct ug2864ambag01_dev_s *priv = (FAR struct ug2864ambag01_dev_s *)dev;
+ DEBUGASSERT(priv);
+
+ lcdvdbg("power: %s\n", priv->on ? "ON" : "OFF");
+ return priv->on ? CONFIG_LCD_MAXPOWER : 0;
+}
+
+/**************************************************************************************
+ * Name: ug2864ambag01_setpower
+ *
+ * Description:
+ * Enable/disable LCD panel power (0: full off - CONFIG_LCD_MAXPOWER: full on). On
+ * backlit LCDs, this setting may correspond to the backlight setting.
+ *
+ **************************************************************************************/
+
+static int ug2864ambag01_setpower(struct lcd_dev_s *dev, int power)
+{
+ struct ug2864ambag01_dev_s *priv = (struct ug2864ambag01_dev_s *)dev;
+ DEBUGASSERT(priv && (unsigned)power <= CONFIG_LCD_MAXPOWER && priv->spi);
+
+ lcdvdbg("power: %d [%d]\n", power, priv->on ? CONFIG_LCD_MAXPOWER : 0);
+
+ /* Lock and select device */
+
+ ug2864ambag01_lock(priv->spi);
+ SPI_SELECT(priv->spi, SPIDEV_DISPLAY, true);
+
+ if (power <= 0)
+ {
+ /* Turn the display off */
+
+ (void)SPI_SEND(priv->spi, SH1101A_DISPOFF);
+ priv->on = false;
+ }
+ else
+ {
+ /* Turn the display on */
+
+ (void)SPI_SEND(priv->spi, SH1101A_DISPON); /* Display on, dim mode */
+ priv->on = true;
+ }
+
+ /* De-select and unlock the device */
+
+ SPI_SELECT(priv->spi, SPIDEV_DISPLAY, false);
+ ug2864ambag01_unlock(priv->spi);
+ return OK;
+}
+
+/**************************************************************************************
+ * Name: ug2864ambag01_getcontrast
+ *
+ * Description:
+ * Get the current contrast setting (0-CONFIG_LCD_MAXCONTRAST).
+ *
+ **************************************************************************************/
+
+static int ug2864ambag01_getcontrast(struct lcd_dev_s *dev)
+{
+ struct ug2864ambag01_dev_s *priv = (struct ug2864ambag01_dev_s *)dev;
+ DEBUGASSERT(priv);
+
+ lcdvdbg("contrast: %d\n", priv->contrast);
+ return priv->contrast;
+}
+
+/**************************************************************************************
+ * Name: ug2864ambag01_setcontrast
+ *
+ * Description:
+ * Set LCD panel contrast (0-CONFIG_LCD_MAXCONTRAST).
+ *
+ **************************************************************************************/
+
+static int ug2864ambag01_setcontrast(struct lcd_dev_s *dev, unsigned int contrast)
+{
+ struct ug2864ambag01_dev_s *priv = (struct ug2864ambag01_dev_s *)dev;
+ unsigned int scaled;
+
+ lcdvdbg("contrast: %d\n", contrast);
+ DEBUGASSERT(priv);
+
+ /* Verify the contrast value */
+
+#ifdef CONFIG_DEBUG
+ if (contrast > CONFIG_LCD_MAXCONTRAST)
+ {
+ return -EINVAL;
+ }
+#endif
+
+ /* Scale contrast: newcontrast = 255 * contrast / CONFIG_LCD_MAXCONTRAST
+ * Where contrast is in the range {1,255}
+ */
+
+#if CONFIG_LCD_MAXCONTRAST != 255
+ scaled = ((contrast << 8) - 1) / CONFIG_LCD_MAXCONTRAST;
+#else
+ scaled = contrast;
+#endif
+
+ /* Lock and select device */
+
+ ug2864ambag01_lock(priv->spi);
+ SPI_SELECT(priv->spi, SPIDEV_DISPLAY, true);
+
+ /* Select command transfer */
+
+ SPI_CMDDATA(priv->spi, SPIDEV_DISPLAY, true);
+
+ /* Set the contrast */
+
+ (void)SPI_SEND(priv->spi, SH1101A_CONTRAST_MODE); /* Set contrast control register */
+ (void)SPI_SEND(priv->spi, SH1101A_CONTRAST(scaled)); /* Data 1: Set 1 of 256 contrast steps */
+ priv->contrast = contrast;
+
+ /* De-select and unlock the device */
+
+ SPI_SELECT(priv->spi, SPIDEV_DISPLAY, false);
+ ug2864ambag01_unlock(priv->spi);
+ return OK;
+}
+
+/**************************************************************************************
+ * Public Functions
+ **************************************************************************************/
+
+/**************************************************************************************
+ * Name: ug2864ambag01_initialize
+ *
+ * Description:
+ * Initialize the UG-2864AMBAG01 video hardware. The initial state of the
+ * OLED is fully initialized, display memory cleared, and the OLED ready
+ * to use, but with the power setting at 0 (full off == sleep mode).
+ *
+ * Input Parameters:
+ *
+ * spi - A reference to the SPI driver instance.
+ * devno - A value in the range of 0 through CONFIG_UG2864AMBAG01_NINTERFACES-1.
+ * This allows support for multiple OLED devices.
+ *
+ * Returned Value:
+ *
+ * On success, this function returns a reference to the LCD object for
+ * the specified OLED. NULL is returned on any failure.
+ *
+ **************************************************************************************/
+
+FAR struct lcd_dev_s *ug2864ambag01_initialize(FAR struct spi_dev_s *spi, unsigned int devno)
+{
+ FAR struct ug2864ambag01_dev_s *priv = &g_oleddev;
+
+ lcdvdbg("Initializing\n");
+ DEBUGASSERT(spi && devno == 0);
+
+ /* Save the reference to the SPI device */
+
+ priv->spi = spi;
+
+ /* Configure the SPI */
+
+ ug2864ambag01_configspi(spi)
+
+ /* Lock and select device */
+
+ ug2864ambag01_lock(priv->spi);
+ SPI_SELECT(spi, SPIDEV_DISPLAY, true);
+
+ /* Select command transfer */
+
+ SPI_CMDDATA(spi, SPIDEV_DISPLAY, true);
+
+ /* Configure the device */
+
+ SPI_SEND(spi, SH1101A_DISPOFF); /* Display off */
+ SPI_SEND(spi, SH1101A_SETCOLL(0)); /* Set lower column address */
+ SPI_SEND(spi, SH1101A_SETCOLH(0)); /* Set higher column address */
+ SPI_SEND(spi, SH1101A_STARTLINE(0)); /* Set display start line */
+ SPI_SEND(spi, SH1101A_PAGEADDR(0)); /* Set page address */
+ SPI_SEND(spi, SH1101A_CONTRAST_MODE); /* Contrast control */
+ SPI_SEND(spi ,UG2864AMBAG01_CONTRAST); /* Default contrast */
+ SPI_SEND(spi, SH1101A_REMAPPLEFT); /* Set segment remap left */
+ SPI_SEND(spi, SH1101A_EDISPOFF); /* Normal display */
+ SPI_SEND(spi, SH1101A_NORMAL); /* Normal (un-reversed) display mode */
+ SPI_SEND(spi, SH1101A_MRATIO_MODE); /* Multiplex ratio */
+ SPI_SEND(spi, SH1101A_MRATIO(0x3f)); /* Duty = 1/64 */
+ SPI_SEND(spi, SH1101A_SCANTOCOM0); /* Com scan direction: Scan from COM[n-1] to COM[0] */
+ SPI_SEND(spi, SH1101A_DISPOFFS_MODE); /* Set display offset */
+ SPI_SEND(spi, SH1101A_DISPOFFS(0));
+ SPI_SEND(spi, SH1101A_CLKDIV_SET); /* Set clock divider */
+ SPI_SEND(spi, SH1101A_CLKDIV(0,0));
+ SPI_SEND(spi, SH1101A_CMNPAD_CONFIG); /* Set common pads */
+ SPI_SEND(spi, SH1101A_CMNPAD(0x10));
+ SPI_SEND(spi, SH1101A_VCOM_SET);
+ SPI_SEND(spi, SH1101A_VCOM(0x40));
+ SPI_SEND(spi, SH1101A_DCDC_MODE); /* DC/DC control mode: on */
+ SPI_SEND(spi, SH1101A_DCDC_ON);
+ SPI_SEND(spi, SH1101A_DISPON); /* display ON */
+
+ /* De-select and unlock the device */
+
+ SPI_SELECT(spi, SPIDEV_DISPLAY, false);
+ ug2864ambag01_unlock(priv->spi);
+
+ /* Clear the display */
+
+ up_mdelay(100);
+ ug2864ambag01_fill(&priv->dev, UG_Y1_BLACK);
+ return &priv->dev;
+}
+
+/**************************************************************************************
+ * Name: ug2864ambag01_fill
+ *
+ * Description:
+ * This non-standard method can be used to clear the entire display by writing one
+ * color to the display. This is much faster than writing a series of runs.
+ *
+ * Input Parameters:
+ * priv - Reference to private driver structure
+ *
+ * Assumptions:
+ * Caller has selected the OLED section.
+ *
+ **************************************************************************************/
+
+void ug2864ambag01_fill(FAR struct lcd_dev_s *dev, uint8_t color)
+{
+ FAR struct ug2864ambag01_dev_s *priv = &g_oleddev;
+ unsigned int page;
+
+ /* Make an 8-bit version of the selected color */
+
+ if (color & 1)
+ {
+ color = 0xff;
+ }
+ else
+ {
+ color = 0;
+ }
+
+ /* Initialize the framebuffer */
+
+ memset(priv->fb, color, UG2864AMBAG01_FBSIZE);
+
+ /* Lock and select device */
+
+ ug2864ambag01_lock(priv->spi);
+ SPI_SELECT(priv->spi, SPIDEV_DISPLAY, true);
+
+ /* Visit each page */
+
+ for (page = 0; page < UG2864AMBAG01_DEV_PAGES; page++)
+ {
+ /* Select command transfer */
+
+ SPI_CMDDATA(priv->spi, SPIDEV_DISPLAY, true);
+
+ /* Set the column address to the XOFFSET value */
+
+ SPI_SEND(priv->spi, SH1101A_SETCOLL(UG2864AMBAG01_DEV_XOFFSET));
+ SPI_SEND(priv->spi, SH1101A_SETCOLH(0));
+
+ /* Set the page address */
+
+ SPI_SEND(priv->spi, SH1101A_PAGEADDR(page));
+
+ /* Select data transfer */
+
+ SPI_CMDDATA(priv->spi, SPIDEV_DISPLAY, false);
+
+ /* Transfer one page of the selected color */
+
+ (void)SPI_SNDBLOCK(priv->spi, &priv->fb[page * UG2864AMBAG01_XRES],
+ UG2864AMBAG01_XRES);
+ }
+
+ /* De-select and unlock the device */
+
+ SPI_SELECT(priv->spi, SPIDEV_DISPLAY, false);
+ ug2864ambag01_unlock(priv->spi);
+}
+
+#endif /* CONFIG_LCD_UG2864AMBAG01 */
diff --git a/nuttx/drivers/lcd/ug-9664hswag01.c b/nuttx/drivers/lcd/ug-9664hswag01.c
index e0e8e8e3a..6ef78fca6 100644
--- a/nuttx/drivers/lcd/ug-9664hswag01.c
+++ b/nuttx/drivers/lcd/ug-9664hswag01.c
@@ -73,8 +73,6 @@
* CONFIG_UG9664HSWAG01_POWER
* If the hardware supports a controllable OLED a power supply, this
* configuration shold be defined. (See ug_power() below).
- * CONFIG_LCD_UGDEBUG - Enable detailed UG-9664HSWAG01 debug output
- * (CONFIG_DEBUG and CONFIG_VERBOSE must also be enabled).
*
* Required LCD driver settings:
* CONFIG_LCD_UG9664HSWAG01 - Enable UG-9664HSWAG01 support
@@ -119,11 +117,10 @@
#ifndef CONFIG_DEBUG
# undef CONFIG_DEBUG_VERBOSE
-# undef CONFIG_DEBUG_GRAPHICS
#endif
#ifndef CONFIG_DEBUG_VERBOSE
-# undef CONFIG_LCD_UGDEBUG
+# undef CONFIG_DEBUG_LCD
#endif
/* Check contrast selection */
@@ -182,7 +179,7 @@
#define UG_BPP 1
#define UG_COLORFMT FB_FMT_Y1
-/* Bytes per logical row andactual device row */
+/* Bytes per logical row and actual device row */
#define UG_XSTRIDE (UG_XRES >> 3) /* Pixels arrange "horizontally for user" */
#define UG_YSTRIDE (UG_YRES >> 3) /* But actual device arrangement is "vertical" */
@@ -198,10 +195,10 @@
/* Debug ******************************************************************************/
-#ifdef CONFIG_LCD_UGDEBUG
-# define ugdbg(format, arg...) vdbg(format, ##arg)
+#ifdef CONFIG_DEBUG_LCD
+# define lcddbg(format, arg...) vdbg(format, ##arg)
#else
-# define ugdbg(x...)
+# define lcddbg(x...)
#endif
/**************************************************************************************
@@ -997,7 +994,7 @@ FAR struct lcd_dev_s *ug_initialize(FAR struct spi_dev_s *spi, unsigned int devn
SPI_CMDDATA(spi, SPIDEV_DISPLAY, true);
- /* Set the starting position for the run */
+ /* Configure the device */
(void)SPI_SEND(spi, SSD1305_SETCOLL + 2); /* Set low column address */
(void)SPI_SEND(spi, SSD1305_SETCOLH + 2); /* Set high column address */
diff --git a/nuttx/drivers/loop.c b/nuttx/drivers/loop.c
index df96da59f..b5b5d82d8 100644
--- a/nuttx/drivers/loop.c
+++ b/nuttx/drivers/loop.c
@@ -215,7 +215,7 @@ static ssize_t loop_read(FAR struct inode *inode, unsigned char *buffer,
size_t start_sector, unsigned int nsectors)
{
FAR struct loop_struct_s *dev;
- size_t nbytesread;
+ ssize_t nbytesread;
off_t offset;
int ret;
diff --git a/nuttx/drivers/mmcsd/Make.defs b/nuttx/drivers/mmcsd/Make.defs
index 850456597..06e689c75 100644
--- a/nuttx/drivers/mmcsd/Make.defs
+++ b/nuttx/drivers/mmcsd/Make.defs
@@ -1,7 +1,7 @@
############################################################################
# drivers/mmcsd/Make.defs
#
-# Copyright (C) 2008, 2011 Gregory Nutt. All rights reserved.
+# Copyright (C) 2008, 2011-2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
@@ -33,14 +33,24 @@
#
############################################################################
+ifeq ($(CONFIG_MMCSD),y)
+
# Include MMC/SD drivers
-CSRCS += mmcsd_sdio.c mmcsd_spi.c mmcsd_debug.c
+ifeq ($(CONFIG_MMCSD_SDIO),y)
+CSRCS += mmcsd_sdio.c
+endif
+
+ifeq ($(CONFIG_MMCSD_SPI),y)
+CSRCS += mmcsd_spi.c mmcsd_debug.c
+endif
# Include MMC/SD driver build support
DEPPATH += --dep-path mmcsd
VPATH += :mmcsd
-CFLAGS += ${shell $(TOPDIR)/tools/incdir.sh $(INCDIROPT) "$(CC)" $(TOPDIR)/drivers/mmcsd}
+CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)drivers$(DELIM)mmcsd}
+
+endif
diff --git a/nuttx/drivers/mmcsd/mmcsd_sdio.c b/nuttx/drivers/mmcsd/mmcsd_sdio.c
index d0bc6659c..3caa61583 100644
--- a/nuttx/drivers/mmcsd/mmcsd_sdio.c
+++ b/nuttx/drivers/mmcsd/mmcsd_sdio.c
@@ -38,6 +38,9 @@
****************************************************************************/
#include <nuttx/config.h>
+
+#if defined (CONFIG_MMCSD) && defined (CONFIG_MMCSD_SDIO)
+
#include <nuttx/compiler.h>
#include <sys/types.h>
@@ -2597,7 +2600,8 @@ static int mmcsd_cardidentify(FAR struct mmcsd_state_s *priv)
* operating condition. CMD 8 is reserved on SD version 1.0 and MMC.
*
* CMD8 Argument:
- * [31:12]: Reserved (shall be set to '0') * [11:8]: Supply Voltage (VHS) 0x1 (Range: 2.7-3.6 V)
+ * [31:12]: Reserved (shall be set to '0')
+ * [11:8]: Supply Voltage (VHS) 0x1 (Range: 2.7-3.6 V)
* [7:0]: Check Pattern (recommended 0xaa)
* CMD8 Response: R7
*/
@@ -3178,3 +3182,5 @@ errout_with_alloc:
kfree(priv);
return ret;
}
+
+#endif /* defined (CONFIG_MMCSD) && defined (CONFIG_MMCSD_SDIO) */
diff --git a/nuttx/drivers/mmcsd/mmcsd_spi.c b/nuttx/drivers/mmcsd/mmcsd_spi.c
index 7dbadc55f..d437b7fea 100644
--- a/nuttx/drivers/mmcsd/mmcsd_spi.c
+++ b/nuttx/drivers/mmcsd/mmcsd_spi.c
@@ -38,6 +38,9 @@
****************************************************************************/
#include <nuttx/config.h>
+
+#if defined (CONFIG_MMCSD) && defined (CONFIG_MMCSD_SPI)
+
#include <sys/types.h>
#include <stdint.h>
@@ -508,7 +511,7 @@ static uint32_t mmcsd_sendcmd(FAR struct mmcsd_slot_s *slot,
}
break;
- /* The R3 response is 5 bytes long */
+ /* The R3 response is 5 bytes long. The first byte is identical to R1. */
case MMCSD_CMDRESP_R3:
{
@@ -520,8 +523,10 @@ static uint32_t mmcsd_sendcmd(FAR struct mmcsd_slot_s *slot,
fvdbg("CMD%d[%08x] R1=%02x OCR=%08x\n",
cmd->cmd & 0x3f, arg, response, slot->ocr);
}
+ break;
+
+ /* The R7 response is 5 bytes long. The first byte is identical to R1. */
- /* The R7 response is 5 bytes long */
case MMCSD_CMDRESP_R7:
default:
{
@@ -1876,3 +1881,5 @@ int mmcsd_spislotinitialize(int minor, int slotno, FAR struct spi_dev_s *spi)
(void)SPI_REGISTERCALLBACK(spi, mmcsd_mediachanged, (void*)slot);
return OK;
}
+
+#endif /* defined (CONFIG_MMCSD) && defined (CONFIG_MMCSD_SPI) */
diff --git a/nuttx/drivers/mtd/Make.defs b/nuttx/drivers/mtd/Make.defs
index 258e77ec9..7db7592d4 100644
--- a/nuttx/drivers/mtd/Make.defs
+++ b/nuttx/drivers/mtd/Make.defs
@@ -51,6 +51,10 @@ ifeq ($(CONFIG_MTD_W25),y)
CSRCS += w25.c
endif
+ifeq ($(CONFIG_MTD_AT25),y)
+CSRCS += at25.c
+endif
+
# Include MTD driver support
DEPPATH += --dep-path mtd
diff --git a/nuttx/drivers/mtd/at25.c b/nuttx/drivers/mtd/at25.c
new file mode 100644
index 000000000..e35b794a5
--- /dev/null
+++ b/nuttx/drivers/mtd/at25.c
@@ -0,0 +1,708 @@
+/************************************************************************************
+ * drivers/mtd/at25.c
+ * Driver for SPI-based AT25DF321 (32Mbit) flash.
+ *
+ * Copyright (C) 2009-2012 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ * Petteri Aimonen <jpa@nx.mail.kapsi.fi>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ************************************************************************************/
+
+/************************************************************************************
+ * Included Files
+ ************************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/kmalloc.h>
+#include <nuttx/fs/ioctl.h>
+#include <nuttx/spi.h>
+#include <nuttx/mtd.h>
+
+/************************************************************************************
+ * Pre-processor Definitions
+ ************************************************************************************/
+
+#ifndef CONFIG_AT25_SPIMODE
+# define CONFIG_AT25_SPIMODE SPIDEV_MODE0
+#endif
+
+/* AT25 Registers *******************************************************************/
+/* Indentification register values */
+
+#define AT25_MANUFACTURER 0x1F
+#define AT25_AT25DF321_TYPE 0x47 /* 32 M-bit */
+
+/* AT25DF321 capacity is 4,194,304 bytes:
+ * (64 sectors) * (65,536 bytes per sector)
+ * (16384 pages) * (256 bytes per page)
+ */
+
+#define AT25_AT25DF321_SECTOR_SHIFT 12 /* Sector size 1 << 12 = 4096 */
+#define AT25_AT25DF321_NSECTORS 1024
+#define AT25_AT25DF321_PAGE_SHIFT 9 /* Page size 1 << 9 = 512 */
+#define AT25_AT25DF321_NPAGES 8192
+
+/* Instructions */
+/* Command Value N Description Addr Dummy Data */
+#define AT25_WREN 0x06 /* 1 Write Enable 0 0 0 */
+#define AT25_WRDI 0x04 /* 1 Write Disable 0 0 0 */
+#define AT25_RDID 0x9f /* 1 Read Identification 0 0 1-3 */
+#define AT25_RDSR 0x05 /* 1 Read Status Register 0 0 >=1 */
+#define AT25_WRSR 0x01 /* 1 Write Status Register 0 0 1 */
+#define AT25_READ 0x03 /* 1 Read Data Bytes 3 0 >=1 */
+#define AT25_FAST_READ 0x0b /* 1 Higher speed read 3 1 >=1 */
+#define AT25_PP 0x02 /* 1 Page Program 3 0 1-256 */
+#define AT25_SE 0x20 /* 1 Sector Erase 3 0 0 */
+#define AT25_BE 0xc7 /* 1 Bulk Erase 0 0 0 */
+#define AT25_DP 0xb9 /* 2 Deep power down 0 0 0 */
+#define AT25_RES 0xab /* 2 Read Electronic Signature 0 3 >=1 */
+
+/* Status register bit definitions */
+
+#define AT25_SR_WIP (1 << 0) /* Bit 0: Write in progress bit */
+#define AT25_SR_WEL (1 << 1) /* Bit 1: Write enable latch bit */
+#define AT25_SR_EPE (1 << 5) /* Bit 5: Erase/program error */
+#define AT25_SR_UNPROT 0x00 /* Global unprotect command */
+
+#define AT25_DUMMY 0xa5
+
+/************************************************************************************
+ * Private Types
+ ************************************************************************************/
+
+/* This type represents the state of the MTD device. The struct mtd_dev_s
+ * must appear at the beginning of the definition so that you can freely
+ * cast between pointers to struct mtd_dev_s and struct at25_dev_s.
+ */
+
+struct at25_dev_s
+{
+ struct mtd_dev_s mtd; /* MTD interface */
+ FAR struct spi_dev_s *dev; /* Saved SPI interface instance */
+ uint8_t sectorshift; /* 16 or 18 */
+ uint8_t pageshift; /* 8 */
+ uint16_t nsectors; /* 128 or 64 */
+ uint32_t npages; /* 32,768 or 65,536 */
+};
+
+/************************************************************************************
+ * Private Function Prototypes
+ ************************************************************************************/
+
+/* Helpers */
+
+static void at25_lock(FAR struct spi_dev_s *dev);
+static inline void at25_unlock(FAR struct spi_dev_s *dev);
+static inline int at25_readid(struct at25_dev_s *priv);
+static void at25_waitwritecomplete(struct at25_dev_s *priv);
+static void at25_writeenable(struct at25_dev_s *priv);
+static inline void at25_sectorerase(struct at25_dev_s *priv, off_t offset);
+static inline int at25_bulkerase(struct at25_dev_s *priv);
+static inline void at25_pagewrite(struct at25_dev_s *priv, FAR const uint8_t *buffer,
+ off_t offset);
+
+/* MTD driver methods */
+
+static int at25_erase(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks);
+static ssize_t at25_bread(FAR struct mtd_dev_s *dev, off_t startblock,
+ size_t nblocks, FAR uint8_t *buf);
+static ssize_t at25_bwrite(FAR struct mtd_dev_s *dev, off_t startblock,
+ size_t nblocks, FAR const uint8_t *buf);
+static ssize_t at25_read(FAR struct mtd_dev_s *dev, off_t offset, size_t nbytes,
+ FAR uint8_t *buffer);
+static int at25_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg);
+
+/************************************************************************************
+ * Private Data
+ ************************************************************************************/
+
+/************************************************************************************
+ * Private Functions
+ ************************************************************************************/
+
+/************************************************************************************
+ * Name: at25_lock
+ ************************************************************************************/
+
+static void at25_lock(FAR struct spi_dev_s *dev)
+{
+ /* On SPI busses where there are multiple devices, it will be necessary to
+ * lock SPI to have exclusive access to the busses for a sequence of
+ * transfers. The bus should be locked before the chip is selected.
+ *
+ * This is a blocking call and will not return until we have exclusiv access to
+ * the SPI buss. We will retain that exclusive access until the bus is unlocked.
+ */
+
+ (void)SPI_LOCK(dev, true);
+
+ /* After locking the SPI bus, the we also need call the setfrequency, setbits, and
+ * setmode methods to make sure that the SPI is properly configured for the device.
+ * If the SPI buss is being shared, then it may have been left in an incompatible
+ * state.
+ */
+
+ SPI_SETMODE(dev, CONFIG_AT25_SPIMODE);
+ SPI_SETBITS(dev, 8);
+ (void)SPI_SETFREQUENCY(dev, 20000000);
+}
+
+/************************************************************************************
+ * Name: at25_unlock
+ ************************************************************************************/
+
+static inline void at25_unlock(FAR struct spi_dev_s *dev)
+{
+ (void)SPI_LOCK(dev, false);
+}
+
+/************************************************************************************
+ * Name: at25_readid
+ ************************************************************************************/
+
+static inline int at25_readid(struct at25_dev_s *priv)
+{
+ uint16_t manufacturer;
+ uint16_t memory;
+ uint16_t version;
+
+ fvdbg("priv: %p\n", priv);
+
+ /* Lock the SPI bus, configure the bus, and select this FLASH part. */
+
+ at25_lock(priv->dev);
+ SPI_SELECT(priv->dev, SPIDEV_FLASH, true);
+
+ /* Send the "Read ID (RDID)" command and read the first three ID bytes */
+
+ (void)SPI_SEND(priv->dev, AT25_RDID);
+ manufacturer = SPI_SEND(priv->dev, AT25_DUMMY);
+ memory = SPI_SEND(priv->dev, AT25_DUMMY);
+
+ /* Deselect the FLASH and unlock the bus */
+
+ SPI_SELECT(priv->dev, SPIDEV_FLASH, false);
+ at25_unlock(priv->dev);
+
+ fvdbg("manufacturer: %02x memory: %02x\n",
+ manufacturer, memory);
+
+ /* Check for a valid manufacturer and memory type */
+
+ if (manufacturer == AT25_MANUFACTURER && memory == AT25_AT25DF321_TYPE)
+ {
+ priv->sectorshift = AT25_AT25DF321_SECTOR_SHIFT;
+ priv->nsectors = AT25_AT25DF321_NSECTORS;
+ priv->pageshift = AT25_AT25DF321_PAGE_SHIFT;
+ priv->npages = AT25_AT25DF321_NPAGES;
+ return OK;
+ }
+
+ return -ENODEV;
+}
+
+/************************************************************************************
+ * Name: at25_waitwritecomplete
+ ************************************************************************************/
+
+static void at25_waitwritecomplete(struct at25_dev_s *priv)
+{
+ uint8_t status;
+
+ /* Are we the only device on the bus? */
+
+#ifdef CONFIG_SPI_OWNBUS
+
+ /* Select this FLASH part */
+
+ SPI_SELECT(priv->dev, SPIDEV_FLASH, true);
+
+ /* Send "Read Status Register (RDSR)" command */
+
+ (void)SPI_SEND(priv->dev, AT25_RDSR);
+
+ /* Loop as long as the memory is busy with a write cycle */
+
+ do
+ {
+ /* Send a dummy byte to generate the clock needed to shift out the status */
+
+ status = SPI_SEND(priv->dev, AT25_DUMMY);
+ }
+ while ((status & AT25_SR_WIP) != 0);
+
+ /* Deselect the FLASH */
+
+ SPI_SELECT(priv->dev, SPIDEV_FLASH, false);
+
+#else
+
+ /* Loop as long as the memory is busy with a write cycle */
+
+ do
+ {
+ /* Select this FLASH part */
+
+ SPI_SELECT(priv->dev, SPIDEV_FLASH, true);
+
+ /* Send "Read Status Register (RDSR)" command */
+
+ (void)SPI_SEND(priv->dev, AT25_RDSR);
+
+ /* Send a dummy byte to generate the clock needed to shift out the status */
+
+ status = SPI_SEND(priv->dev, AT25_DUMMY);
+
+ /* Deselect the FLASH */
+
+ SPI_SELECT(priv->dev, SPIDEV_FLASH, false);
+
+ /* Given that writing could take up to few tens of milliseconds, and erasing
+ * could take more. The following short delay in the "busy" case will allow
+ * other peripherals to access the SPI bus.
+ */
+
+ if ((status & AT25_SR_WIP) != 0)
+ {
+ at25_unlock(priv->dev);
+ usleep(10000);
+ at25_lock(priv->dev);
+ }
+ }
+ while ((status & AT25_SR_WIP) != 0);
+#endif
+
+ if (status & AT25_SR_EPE)
+ {
+ fdbg("Write error, status: 0x%02x\n", status);
+ }
+
+ fvdbg("Complete, status: 0x%02x\n", status);
+}
+
+/************************************************************************************
+ * Name: at25_writeenable
+ ************************************************************************************/
+
+static void at25_writeenable(struct at25_dev_s *priv)
+{
+ SPI_SELECT(priv->dev, SPIDEV_FLASH, true);
+ (void)SPI_SEND(priv->dev, AT25_WREN);
+ SPI_SELECT(priv->dev, SPIDEV_FLASH, false);
+ fvdbg("Enabled\n");
+}
+
+/************************************************************************************
+ * Name: at25_sectorerase
+ ************************************************************************************/
+
+static inline void at25_sectorerase(struct at25_dev_s *priv, off_t sector)
+{
+ off_t offset = sector << priv->sectorshift;
+
+ fvdbg("sector: %08lx\n", (long)sector);
+
+ /* Wait for any preceding write to complete. We could simplify things by
+ * perform this wait at the end of each write operation (rather than at
+ * the beginning of ALL operations), but have the wait first will slightly
+ * improve performance.
+ */
+
+ at25_waitwritecomplete(priv);
+
+ /* Send write enable instruction */
+
+ at25_writeenable(priv);
+
+ /* Select this FLASH part */
+
+ SPI_SELECT(priv->dev, SPIDEV_FLASH, true);
+
+ /* Send the "Sector Erase (SE)" instruction */
+
+ (void)SPI_SEND(priv->dev, AT25_SE);
+
+ /* Send the sector offset high byte first. For all of the supported
+ * parts, the sector number is completely contained in the first byte
+ * and the values used in the following two bytes don't really matter.
+ */
+
+ (void)SPI_SEND(priv->dev, (offset >> 16) & 0xff);
+ (void)SPI_SEND(priv->dev, (offset >> 8) & 0xff);
+ (void)SPI_SEND(priv->dev, offset & 0xff);
+
+ /* Deselect the FLASH */
+
+ SPI_SELECT(priv->dev, SPIDEV_FLASH, false);
+ fvdbg("Erased\n");
+}
+
+/************************************************************************************
+ * Name: at25_bulkerase
+ ************************************************************************************/
+
+static inline int at25_bulkerase(struct at25_dev_s *priv)
+{
+ fvdbg("priv: %p\n", priv);
+
+ /* Wait for any preceding write to complete. We could simplify things by
+ * perform this wait at the end of each write operation (rather than at
+ * the beginning of ALL operations), but have the wait first will slightly
+ * improve performance.
+ */
+
+ at25_waitwritecomplete(priv);
+
+ /* Send write enable instruction */
+
+ at25_writeenable(priv);
+
+ /* Select this FLASH part */
+
+ SPI_SELECT(priv->dev, SPIDEV_FLASH, true);
+
+ /* Send the "Bulk Erase (BE)" instruction */
+
+ (void)SPI_SEND(priv->dev, AT25_BE);
+
+ /* Deselect the FLASH */
+
+ SPI_SELECT(priv->dev, SPIDEV_FLASH, false);
+ fvdbg("Return: OK\n");
+ return OK;
+}
+
+/************************************************************************************
+ * Name: at25_pagewrite
+ ************************************************************************************/
+
+static inline void at25_pagewrite(struct at25_dev_s *priv, FAR const uint8_t *buffer,
+ off_t page)
+{
+ off_t offset = page << 8;
+
+ fvdbg("page: %08lx offset: %08lx\n", (long)page, (long)offset);
+
+ /* Wait for any preceding write to complete. We could simplify things by
+ * perform this wait at the end of each write operation (rather than at
+ * the beginning of ALL operations), but have the wait first will slightly
+ * improve performance.
+ */
+
+ at25_waitwritecomplete(priv);
+
+ /* Enable the write access to the FLASH */
+
+ at25_writeenable(priv);
+
+ /* Select this FLASH part */
+
+ SPI_SELECT(priv->dev, SPIDEV_FLASH, true);
+
+ /* Send "Page Program (PP)" command */
+
+ (void)SPI_SEND(priv->dev, AT25_PP);
+
+ /* Send the page offset high byte first. */
+
+ (void)SPI_SEND(priv->dev, (offset >> 16) & 0xff);
+ (void)SPI_SEND(priv->dev, (offset >> 8) & 0xff);
+ (void)SPI_SEND(priv->dev, offset & 0xff);
+
+ /* Then write the specified number of bytes */
+
+ SPI_SNDBLOCK(priv->dev, buffer, 256);
+
+ /* Deselect the FLASH: Chip Select high */
+
+ SPI_SELECT(priv->dev, SPIDEV_FLASH, false);
+ fvdbg("Written\n");
+}
+
+/************************************************************************************
+ * Name: at25_erase
+ ************************************************************************************/
+
+static int at25_erase(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks)
+{
+ FAR struct at25_dev_s *priv = (FAR struct at25_dev_s *)dev;
+ size_t blocksleft = nblocks;
+
+ fvdbg("startblock: %08lx nblocks: %d\n", (long)startblock, (int)nblocks);
+
+ /* Lock access to the SPI bus until we complete the erase */
+
+ at25_lock(priv->dev);
+ while (blocksleft-- > 0)
+ {
+ /* Erase each sector */
+
+ at25_sectorerase(priv, startblock);
+ startblock++;
+ }
+
+ at25_unlock(priv->dev);
+ return (int)nblocks;
+}
+
+/************************************************************************************
+ * Name: at25_bread
+ ************************************************************************************/
+
+static ssize_t at25_bread(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks,
+ FAR uint8_t *buffer)
+{
+ FAR struct at25_dev_s *priv = (FAR struct at25_dev_s *)dev;
+ ssize_t nbytes;
+
+ fvdbg("startblock: %08lx nblocks: %d\n", (long)startblock, (int)nblocks);
+
+ /* On this device, we can handle the block read just like the byte-oriented read */
+
+ nbytes = at25_read(dev, startblock << priv->pageshift, nblocks << priv->pageshift, buffer);
+ if (nbytes > 0)
+ {
+ return nbytes >> priv->pageshift;
+ }
+
+ return (int)nbytes;
+}
+
+/************************************************************************************
+ * Name: at25_bwrite
+ ************************************************************************************/
+
+static ssize_t at25_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks,
+ FAR const uint8_t *buffer)
+{
+ FAR struct at25_dev_s *priv = (FAR struct at25_dev_s *)dev;
+ size_t blocksleft = nblocks;
+
+ fvdbg("startblock: %08lx nblocks: %d\n", (long)startblock, (int)nblocks);
+
+ /* Lock the SPI bus and write each page to FLASH */
+
+ at25_lock(priv->dev);
+ while (blocksleft-- > 0)
+ {
+ at25_pagewrite(priv, buffer, startblock * 2);
+ at25_pagewrite(priv, buffer + 256, startblock * 2 + 1);
+ buffer += 1 << priv->pageshift;
+ startblock++;
+ }
+
+ at25_unlock(priv->dev);
+ return nblocks;
+}
+
+/************************************************************************************
+ * Name: at25_read
+ ************************************************************************************/
+
+static ssize_t at25_read(FAR struct mtd_dev_s *dev, off_t offset, size_t nbytes,
+ FAR uint8_t *buffer)
+{
+ FAR struct at25_dev_s *priv = (FAR struct at25_dev_s *)dev;
+
+ fvdbg("offset: %08lx nbytes: %d\n", (long)offset, (int)nbytes);
+
+ /* Wait for any preceding write to complete. We could simplify things by
+ * perform this wait at the end of each write operation (rather than at
+ * the beginning of ALL operations), but have the wait first will slightly
+ * improve performance.
+ */
+
+ at25_waitwritecomplete(priv);
+
+ /* Lock the SPI bus and select this FLASH part */
+
+ at25_lock(priv->dev);
+ SPI_SELECT(priv->dev, SPIDEV_FLASH, true);
+
+ /* Send "Read from Memory " instruction */
+
+ (void)SPI_SEND(priv->dev, AT25_READ);
+
+ /* Send the page offset high byte first. */
+
+ (void)SPI_SEND(priv->dev, (offset >> 16) & 0xff);
+ (void)SPI_SEND(priv->dev, (offset >> 8) & 0xff);
+ (void)SPI_SEND(priv->dev, offset & 0xff);
+
+ /* Then read all of the requested bytes */
+
+ SPI_RECVBLOCK(priv->dev, buffer, nbytes);
+
+ /* Deselect the FLASH and unlock the SPI bus */
+
+ SPI_SELECT(priv->dev, SPIDEV_FLASH, false);
+ at25_unlock(priv->dev);
+
+ fvdbg("return nbytes: %d\n", (int)nbytes);
+ return nbytes;
+}
+
+/************************************************************************************
+ * Name: at25_ioctl
+ ************************************************************************************/
+
+static int at25_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg)
+{
+ FAR struct at25_dev_s *priv = (FAR struct at25_dev_s *)dev;
+ int ret = -EINVAL; /* Assume good command with bad parameters */
+
+ fvdbg("cmd: %d \n", cmd);
+
+ switch (cmd)
+ {
+ case MTDIOC_GEOMETRY:
+ {
+ FAR struct mtd_geometry_s *geo = (FAR struct mtd_geometry_s *)((uintptr_t)arg);
+ if (geo)
+ {
+ /* Populate the geometry structure with information need to know
+ * the capacity and how to access the device.
+ *
+ * NOTE: that the device is treated as though it where just an array
+ * of fixed size blocks. That is most likely not true, but the client
+ * will expect the device logic to do whatever is necessary to make it
+ * appear so.
+ */
+
+ geo->blocksize = (1 << priv->pageshift);
+ geo->erasesize = (1 << priv->sectorshift);
+ geo->neraseblocks = priv->nsectors;
+ ret = OK;
+
+ fvdbg("blocksize: %d erasesize: %d neraseblocks: %d\n",
+ geo->blocksize, geo->erasesize, geo->neraseblocks);
+ }
+ }
+ break;
+
+ case MTDIOC_BULKERASE:
+ {
+ /* Erase the entire device */
+
+ at25_lock(priv->dev);
+ ret = at25_bulkerase(priv);
+ at25_unlock(priv->dev);
+ }
+ break;
+
+ case MTDIOC_XIPBASE:
+ default:
+ ret = -ENOTTY; /* Bad command */
+ break;
+ }
+
+ fvdbg("return %d\n", ret);
+ return ret;
+}
+
+/************************************************************************************
+ * Public Functions
+ ************************************************************************************/
+
+/************************************************************************************
+ * Name: at25_initialize
+ *
+ * Description:
+ * Create an initialize MTD device instance. MTD devices are not registered
+ * in the file system, but are created as instances that can be bound to
+ * other functions (such as a block or character driver front end).
+ *
+ ************************************************************************************/
+
+FAR struct mtd_dev_s *at25_initialize(FAR struct spi_dev_s *dev)
+{
+ FAR struct at25_dev_s *priv;
+ int ret;
+
+ fvdbg("dev: %p\n", dev);
+
+ /* Allocate a state structure (we allocate the structure instead of using
+ * a fixed, static allocation so that we can handle multiple FLASH devices.
+ * The current implementation would handle only one FLASH part per SPI
+ * device (only because of the SPIDEV_FLASH definition) and so would have
+ * to be extended to handle multiple FLASH parts on the same SPI bus.
+ */
+
+ priv = (FAR struct at25_dev_s *)kmalloc(sizeof(struct at25_dev_s));
+ if (priv)
+ {
+ /* Initialize the allocated structure */
+
+ priv->mtd.erase = at25_erase;
+ priv->mtd.bread = at25_bread;
+ priv->mtd.bwrite = at25_bwrite;
+ priv->mtd.read = at25_read;
+ priv->mtd.ioctl = at25_ioctl;
+ priv->dev = dev;
+
+ /* Deselect the FLASH */
+
+ SPI_SELECT(dev, SPIDEV_FLASH, false);
+
+ /* Identify the FLASH chip and get its capacity */
+
+ ret = at25_readid(priv);
+ if (ret != OK)
+ {
+ /* Unrecognized! Discard all of that work we just did and return NULL */
+
+ fdbg("Unrecognized\n");
+ kfree(priv);
+ priv = NULL;
+ }
+
+ /* Unprotect all sectors */
+
+ at25_writeenable(priv);
+ SPI_SELECT(priv->dev, SPIDEV_FLASH, true);
+ (void)SPI_SEND(priv->dev, AT25_WRSR);
+ (void)SPI_SEND(priv->dev, AT25_SR_UNPROT);
+ SPI_SELECT(priv->dev, SPIDEV_FLASH, false);
+ }
+
+ /* Return the implementation-specific state structure as the MTD device */
+
+ fvdbg("Return %p\n", priv);
+ return (FAR struct mtd_dev_s *)priv;
+}
diff --git a/nuttx/drivers/mtd/ftl.c b/nuttx/drivers/mtd/ftl.c
index cdb35aa5c..6cf8f0317 100644
--- a/nuttx/drivers/mtd/ftl.c
+++ b/nuttx/drivers/mtd/ftl.c
@@ -1,7 +1,7 @@
/****************************************************************************
* drivers/mtd/ftl.c
*
- * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2009, 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -229,6 +229,10 @@ static ssize_t ftl_flush(FAR void *priv, FAR const uint8_t *buffer,
remaining = nblocks;
if (alignedblock > startblock)
{
+ /* Check if the write is shorter than to the end of the erase block */
+
+ bool short_write = (remaining < (alignedblock - startblock));
+
/* Read the full erase block into the buffer */
rwblock = startblock & ~mask;
@@ -252,9 +256,19 @@ static ssize_t ftl_flush(FAR void *priv, FAR const uint8_t *buffer,
/* Copy the user data at the end of the buffered erase block */
offset = (startblock & mask) * dev->geo.blocksize;
- nbytes = dev->geo.erasesize - offset;
+
+ if (short_write)
+ {
+ nbytes = remaining * dev->geo.blocksize;
+ }
+ else
+ {
+ nbytes = dev->geo.erasesize - offset;
+ }
+
fvdbg("Copy %d bytes into erase block=%d at offset=%d\n",
nbytes, eraseblock, offset);
+
memcpy(dev->eblock + offset, buffer, nbytes);
/* And write the erase back to flash */
@@ -268,8 +282,16 @@ static ssize_t ftl_flush(FAR void *priv, FAR const uint8_t *buffer,
/* Then update for amount written */
- remaining -= dev->blkper - (startblock & mask);
- buffer += nbytes;
+ if (short_write)
+ {
+ remaining = 0;
+ }
+ else
+ {
+ remaining -= dev->blkper - (startblock & mask);
+ }
+
+ buffer += nbytes;
}
/* How handle full erase pages in the middle */
@@ -290,6 +312,7 @@ static ssize_t ftl_flush(FAR void *priv, FAR const uint8_t *buffer,
fvdbg("Write %d bytes into erase block=%d at offset=0\n",
dev->geo.erasesize, alignedblock);
+
nxfrd = MTD_BWRITE(dev->mtd, alignedblock, dev->blkper, buffer);
if (nxfrd != dev->blkper)
{
diff --git a/nuttx/drivers/net/e1000.c b/nuttx/drivers/net/e1000.c
index ec2b29b6a..cae6f39b4 100644
--- a/nuttx/drivers/net/e1000.c
+++ b/nuttx/drivers/net/e1000.c
@@ -60,6 +60,7 @@
#include <rgmp/pmap.h>
#include <rgmp/string.h>
#include <rgmp/stdio.h>
+#include <rgmp/utils.h>
#include <rgmp/arch/pci.h>
#include <rgmp/memio.h>
#include "e1000.h"
@@ -104,9 +105,9 @@ struct e1000_dev {
uint32_t io_mem_base;
uint32_t mem_size;
int pci_dev_id;
+ uint16_t pci_addr;
unsigned char src_mac[6];
unsigned char dst_mac[6];
- int irq;
struct irq_action int_desc;
struct tx_ring tx_ring;
struct rx_ring rx_ring;
@@ -308,16 +309,16 @@ void e1000_init(struct e1000_dev *dev)
e1000_outl(dev, E1000_FCRTH, pba*9/10);
// setup tx rings
- txd_phys = PADDR(dev->tx_ring.desc);
- kmem_phys = PADDR(dev->tx_ring.buf);
+ txd_phys = PADDR((uintptr_t)dev->tx_ring.desc);
+ kmem_phys = PADDR((uintptr_t)dev->tx_ring.buf);
for (i=0; i<CONFIG_E1000_N_TX_DESC; i++,kmem_phys+=CONFIG_E1000_BUFF_SIZE) {
- dev->tx_ring.desc[i].base_address = kmem_phys;
- dev->tx_ring.desc[i].packet_length = 0;
- dev->tx_ring.desc[i].cksum_offset = 0;
- dev->tx_ring.desc[i].cksum_origin = 0;
- dev->tx_ring.desc[i].desc_status = 1;
- dev->tx_ring.desc[i].desc_command = (1<<0)|(1<<1)|(1<<3);
- dev->tx_ring.desc[i].special_info = 0;
+ dev->tx_ring.desc[i].base_address = kmem_phys;
+ dev->tx_ring.desc[i].packet_length = 0;
+ dev->tx_ring.desc[i].cksum_offset = 0;
+ dev->tx_ring.desc[i].cksum_origin = 0;
+ dev->tx_ring.desc[i].desc_status = 1;
+ dev->tx_ring.desc[i].desc_command = (1<<0)|(1<<1)|(1<<3);
+ dev->tx_ring.desc[i].special_info = 0;
}
dev->tx_ring.tail = 0;
e1000_outl(dev, E1000_TDT, 0);
@@ -329,15 +330,15 @@ void e1000_init(struct e1000_dev *dev)
e1000_outl(dev, E1000_TXDCTL, 0x01010000);
// setup rx rings
- rxd_phys = PADDR(dev->rx_ring.desc);
- kmem_phys = PADDR(dev->rx_ring.buf);
+ rxd_phys = PADDR((uintptr_t)dev->rx_ring.desc);
+ kmem_phys = PADDR((uintptr_t)dev->rx_ring.buf);
for (i=0; i<CONFIG_E1000_N_RX_DESC; i++,kmem_phys+=CONFIG_E1000_BUFF_SIZE) {
- dev->rx_ring.desc[i].base_address = kmem_phys;
- dev->rx_ring.desc[i].packet_length = 0;
- dev->rx_ring.desc[i].packet_cksum = 0;
- dev->rx_ring.desc[i].desc_status = 0;
- dev->rx_ring.desc[i].desc_errors = 0;
- dev->rx_ring.desc[i].vlan_tag = 0;
+ dev->rx_ring.desc[i].base_address = kmem_phys;
+ dev->rx_ring.desc[i].packet_length = 0;
+ dev->rx_ring.desc[i].packet_cksum = 0;
+ dev->rx_ring.desc[i].desc_status = 0;
+ dev->rx_ring.desc[i].desc_errors = 0;
+ dev->rx_ring.desc[i].vlan_tag = 0;
}
dev->rx_ring.head = 0;
dev->rx_ring.tail = CONFIG_E1000_N_RX_DESC-1;
@@ -378,7 +379,7 @@ static int e1000_transmit(struct e1000_dev *e1000)
{
int tail = e1000->tx_ring.tail;
unsigned char *cp = (unsigned char *)
- (e1000->tx_ring.buf + tail * CONFIG_E1000_BUFF_SIZE);
+ (e1000->tx_ring.buf + tail * CONFIG_E1000_BUFF_SIZE);
int count = e1000->uip_dev.d_len;
/* Verify that the hardware is ready to send another packet. If we get
@@ -387,7 +388,7 @@ static int e1000_transmit(struct e1000_dev *e1000)
*/
if (!e1000->tx_ring.desc[tail].desc_status)
- return -1;
+ return -1;
/* Increment statistics */
@@ -445,14 +446,14 @@ static int e1000_uiptxpoll(struct uip_driver_s *dev)
*/
if (e1000->uip_dev.d_len > 0) {
- uip_arp_out(&e1000->uip_dev);
- e1000_transmit(e1000);
-
- /* Check if there is room in the device to hold another packet. If not,
- * return a non-zero value to terminate the poll.
- */
- if (!e1000->tx_ring.desc[tail].desc_status)
- return -1;
+ uip_arp_out(&e1000->uip_dev);
+ e1000_transmit(e1000);
+
+ /* Check if there is room in the device to hold another packet. If not,
+ * return a non-zero value to terminate the poll.
+ */
+ if (!e1000->tx_ring.desc[tail].desc_status)
+ return -1;
}
/* If zero is returned, the polling will continue until all connections have
@@ -483,75 +484,75 @@ static void e1000_receive(struct e1000_dev *e1000)
{
int head = e1000->rx_ring.head;
unsigned char *cp = (unsigned char *)
- (e1000->rx_ring.buf + head * CONFIG_E1000_BUFF_SIZE);
+ (e1000->rx_ring.buf + head * CONFIG_E1000_BUFF_SIZE);
int cnt;
while (e1000->rx_ring.desc[head].desc_status) {
- /* Check for errors and update statistics */
+ /* Check for errors and update statistics */
- // Here we do not handle packets that exceed packet-buffer size
- if ((e1000->rx_ring.desc[head].desc_status & 3) == 1) {
- cprintf("NIC READ: Oversized packet\n");
- goto next;
- }
+ // Here we do not handle packets that exceed packet-buffer size
+ if ((e1000->rx_ring.desc[head].desc_status & 3) == 1) {
+ cprintf("NIC READ: Oversized packet\n");
+ goto next;
+ }
- /* Check if the packet is a valid size for the uIP buffer configuration */
+ /* Check if the packet is a valid size for the uIP buffer configuration */
- // get the number of actual data-bytes in this packet
- cnt = e1000->rx_ring.desc[head].packet_length;
+ // get the number of actual data-bytes in this packet
+ cnt = e1000->rx_ring.desc[head].packet_length;
- if (cnt > CONFIG_NET_BUFSIZE || cnt < 14) {
- cprintf("NIC READ: invalid package size\n");
- goto next;
- }
+ if (cnt > CONFIG_NET_BUFSIZE || cnt < 14) {
+ cprintf("NIC READ: invalid package size\n");
+ goto next;
+ }
- /* Copy the data data from the hardware to e1000->uip_dev.d_buf. Set
- * amount of data in e1000->uip_dev.d_len
- */
+ /* Copy the data data from the hardware to e1000->uip_dev.d_buf. Set
+ * amount of data in e1000->uip_dev.d_len
+ */
- // now we try to copy these data-bytes to the UIP buffer
- memcpy(e1000->uip_dev.d_buf, cp, cnt);
- e1000->uip_dev.d_len = cnt;
+ // now we try to copy these data-bytes to the UIP buffer
+ memcpy(e1000->uip_dev.d_buf, cp, cnt);
+ e1000->uip_dev.d_len = cnt;
- /* We only accept IP packets of the configured type and ARP packets */
+ /* We only accept IP packets of the configured type and ARP packets */
#ifdef CONFIG_NET_IPv6
- if (BUF->type == HTONS(UIP_ETHTYPE_IP6))
+ if (BUF->type == HTONS(UIP_ETHTYPE_IP6))
#else
- if (BUF->type == HTONS(UIP_ETHTYPE_IP))
+ if (BUF->type == HTONS(UIP_ETHTYPE_IP))
#endif
- {
- uip_arp_ipin(&e1000->uip_dev);
- uip_input(&e1000->uip_dev);
-
- /* If the above function invocation resulted in data that should be
- * sent out on the network, the field d_len will set to a value > 0.
- */
-
- if (e1000->uip_dev.d_len > 0) {
- uip_arp_out(&e1000->uip_dev);
- e1000_transmit(e1000);
- }
- }
- else if (BUF->type == htons(UIP_ETHTYPE_ARP)) {
- uip_arp_arpin(&e1000->uip_dev);
-
- /* If the above function invocation resulted in data that should be
- * sent out on the network, the field d_len will set to a value > 0.
- */
-
- if (e1000->uip_dev.d_len > 0) {
- e1000_transmit(e1000);
- }
- }
+ {
+ uip_arp_ipin(&e1000->uip_dev);
+ uip_input(&e1000->uip_dev);
+
+ /* If the above function invocation resulted in data that should be
+ * sent out on the network, the field d_len will set to a value > 0.
+ */
+
+ if (e1000->uip_dev.d_len > 0) {
+ uip_arp_out(&e1000->uip_dev);
+ e1000_transmit(e1000);
+ }
+ }
+ else if (BUF->type == htons(UIP_ETHTYPE_ARP)) {
+ uip_arp_arpin(&e1000->uip_dev);
+
+ /* If the above function invocation resulted in data that should be
+ * sent out on the network, the field d_len will set to a value > 0.
+ */
+
+ if (e1000->uip_dev.d_len > 0) {
+ e1000_transmit(e1000);
+ }
+ }
next:
- e1000->rx_ring.desc[head].desc_status = 0;
- e1000->rx_ring.head = (head + 1) % CONFIG_E1000_N_RX_DESC;
- e1000->rx_ring.free++;
- head = e1000->rx_ring.head;
- cp = (unsigned char *)(e1000->rx_ring.buf + head * CONFIG_E1000_BUFF_SIZE);
+ e1000->rx_ring.desc[head].desc_status = 0;
+ e1000->rx_ring.head = (head + 1) % CONFIG_E1000_N_RX_DESC;
+ e1000->rx_ring.free++;
+ head = e1000->rx_ring.head;
+ cp = (unsigned char *)(e1000->rx_ring.buf + head * CONFIG_E1000_BUFF_SIZE);
}
}
@@ -615,7 +616,7 @@ static void e1000_polltimer(int argc, uint32_t arg, ...)
* the TX poll if he are unable to accept another packet for transmission.
*/
if (!e1000->tx_ring.desc[tail].desc_status)
- return;
+ return;
/* If so, update TCP timing states and poll uIP for new XMIT data. Hmmm..
* might be bug here. Does this mean if there is a transmit in progress,
@@ -651,8 +652,8 @@ static int e1000_ifup(struct uip_driver_s *dev)
struct e1000_dev *e1000 = (struct e1000_dev *)dev->d_private;
ndbg("Bringing up: %d.%d.%d.%d\n",
- dev->d_ipaddr & 0xff, (dev->d_ipaddr >> 8) & 0xff,
- (dev->d_ipaddr >> 16) & 0xff, dev->d_ipaddr >> 24 );
+ dev->d_ipaddr & 0xff, (dev->d_ipaddr >> 8) & 0xff,
+ (dev->d_ipaddr >> 16) & 0xff, dev->d_ipaddr >> 24 );
/* Initialize PHYs, the Ethernet interface, and setup up Ethernet interrupts */
e1000_init(e1000);
@@ -662,9 +663,9 @@ static int e1000_ifup(struct uip_driver_s *dev)
(void)wd_start(e1000->txpoll, E1000_WDDELAY, e1000_polltimer, 1, (uint32_t)e1000);
if (e1000_inl(e1000, E1000_STATUS) & 2)
- e1000->bifup = true;
+ e1000->bifup = true;
else
- e1000->bifup = false;
+ e1000->bifup = false;
return OK;
}
@@ -749,9 +750,9 @@ static int e1000_txavail(struct uip_driver_s *dev)
/* Ignore the notification if the interface is not yet up */
if (e1000->bifup) {
- /* Check if there is room in the hardware to hold another outgoing packet. */
- if (e1000->tx_ring.desc[tail].desc_status)
- (void)uip_poll(&e1000->uip_dev, e1000_uiptxpoll);
+ /* Check if there is room in the hardware to hold another outgoing packet. */
+ if (e1000->tx_ring.desc[tail].desc_status)
+ (void)uip_poll(&e1000->uip_dev, e1000_uiptxpoll);
}
irqrestore(flags);
@@ -779,11 +780,11 @@ static int e1000_txavail(struct uip_driver_s *dev)
#ifdef CONFIG_NET_IGMP
static int e1000_addmac(struct uip_driver_s *dev, const uint8_t *mac)
{
- struct e1000_dev *e1000 = (struct e1000_dev *)dev->d_private;
+ struct e1000_dev *e1000 = (struct e1000_dev *)dev->d_private;
- /* Add the MAC address to the hardware multicast routing table */
+ /* Add the MAC address to the hardware multicast routing table */
- return OK;
+ return OK;
}
#endif
@@ -808,15 +809,15 @@ static int e1000_addmac(struct uip_driver_s *dev, const uint8_t *mac)
#ifdef CONFIG_NET_IGMP
static int e1000_rmmac(struct uip_driver_s *dev, const uint8_t *mac)
{
- struct e1000_dev *e1000 = (struct e1000_dev *)dev->d_private;
+ struct e1000_dev *e1000 = (struct e1000_dev *)dev->d_private;
- /* Add the MAC address to the hardware multicast routing table */
+ /* Add the MAC address to the hardware multicast routing table */
- return OK;
+ return OK;
}
#endif
-irqreturn_t e1000_interrupt_handler(struct Trapframe *tf, void *dev_id)
+static irqreturn_t e1000_interrupt_handler(int irq, void *dev_id)
{
struct e1000_dev *e1000 = (struct e1000_dev *)dev_id;
@@ -826,27 +827,27 @@ irqreturn_t e1000_interrupt_handler(struct Trapframe *tf, void *dev_id)
// not for me
if (intr_cause == 0)
- return IRQ_NONE;
+ return IRQ_NONE;
/* Handle interrupts according to status bit settings */
// Link status change
if (intr_cause & (1<<2)) {
- if (e1000_inl(e1000, E1000_STATUS) & 2)
- e1000->bifup = true;
- else
- e1000->bifup = false;
+ if (e1000_inl(e1000, E1000_STATUS) & 2)
+ e1000->bifup = true;
+ else
+ e1000->bifup = false;
}
/* Check if we received an incoming packet, if so, call skel_receive() */
// Rx-descriptor Timer expired
if (intr_cause & (1<<7))
- e1000_receive(e1000);
+ e1000_receive(e1000);
// Tx queue empty
if (intr_cause & (1<<1))
- wd_cancel(e1000->txtimeout);
+ wd_cancel(e1000->txtimeout);
/* Check is a packet transmission just completed. If so, call skel_txdone.
* This may disable further Tx interrupts if there are no pending
@@ -855,17 +856,17 @@ irqreturn_t e1000_interrupt_handler(struct Trapframe *tf, void *dev_id)
// Tx-descriptor Written back
if (intr_cause & (1<<0))
- uip_poll(&e1000->uip_dev, e1000_uiptxpoll);
+ uip_poll(&e1000->uip_dev, e1000_uiptxpoll);
// Rx-Descriptors Low
if (intr_cause & (1<<4)) {
- int tail;
- tail = e1000->rx_ring.tail + e1000->rx_ring.free;
- tail %= CONFIG_E1000_N_RX_DESC;
- e1000->rx_ring.tail = tail;
- e1000->rx_ring.free = 0;
- e1000_outl(e1000, E1000_RDT, tail);
+ int tail;
+ tail = e1000->rx_ring.tail + e1000->rx_ring.free;
+ tail %= CONFIG_E1000_N_RX_DESC;
+ e1000->rx_ring.tail = tail;
+ e1000->rx_ring.free = 0;
+ e1000_outl(e1000, E1000_RDT, tail);
}
return IRQ_HANDLED;
@@ -885,20 +886,21 @@ static pci_id_t e1000_id_table[] = {
static int e1000_probe(uint16_t addr, pci_id_t id)
{
uint32_t mmio_base, mmio_size;
- uint32_t pci_cmd, size;
- int err, irq, flags;
+ uint32_t size;
+ int err;
void *kmem, *omem;
struct e1000_dev *dev;
// alloc e1000_dev memory
- dev = kzalloc(sizeof(struct e1000_dev));
- if (dev == NULL)
- return -1;
+ if ((dev = kzalloc(sizeof(struct e1000_dev))) == NULL)
+ return -1;
+
+ // save pci addr
+ dev->pci_addr = addr;
// enable device
- err = pci_enable_device(addr, PCI_RESOURCE_MEM);
- if (err)
- goto error;
+ if ((err = pci_enable_device(addr, PCI_BUS_MASTER)) < 0)
+ goto error;
// get e1000 device type
dev->pci_dev_id = id.join;
@@ -908,33 +910,20 @@ static int e1000_probe(uint16_t addr, pci_id_t id)
mmio_size = pci_resource_len(addr, 0);
err = rgmp_memmap_nocache(mmio_base, mmio_size, mmio_base);
if (err)
- goto error;
+ goto error;
dev->phy_mem_base = mmio_base;
dev->io_mem_base = mmio_base;
dev->mem_size = mmio_size;
- // make sure the controller's Bus Master capability is enabled
- pci_cmd = pci_config_readl(addr, PCI_COMMAND);
- pci_cmd |= (1<<2);
- pci_config_writel(addr, PCI_COMMAND, pci_cmd);
-
// MAC address
memset(dev->dst_mac, 0xFF, 6);
memcpy(dev->src_mac, (void *)(dev->io_mem_base+E1000_RA), 6);
- // get e1000 IRQ
- flags = 0;
- irq = pci_enable_msi(addr);
- if (irq == 0) {
- irq = pci_read_irq(addr);
- flags |= IDC_SHARE;
- }
- dev->irq = irq;
+ // IRQ setup
dev->int_desc.handler = e1000_interrupt_handler;
dev->int_desc.dev_id = dev;
- err = rgmp_request_irq(irq, &dev->int_desc, flags);
- if (err)
- goto err0;
+ if ((err = pci_request_irq(addr, &dev->int_desc, 0)) < 0)
+ goto err0;
// Here we alloc a big block of memory once and make it
// aligned to page boundary and multiple of page size. This
@@ -942,15 +931,19 @@ static int e1000_probe(uint16_t addr, pci_id_t id)
// should be mapped no-cache which will hugely reduce memory
// access performance. The page size alloc will restrict
// this bad effect only within the memory we alloc here.
+ //
+ // NEED FIX: the memalign may alloc memory continous in
+ // virtual address but dis-continous in physical address
+ // due to RGMP memory setup.
size = CONFIG_E1000_N_TX_DESC * sizeof(struct tx_desc) +
- CONFIG_E1000_N_TX_DESC * CONFIG_E1000_BUFF_SIZE +
- CONFIG_E1000_N_RX_DESC * sizeof(struct rx_desc) +
- CONFIG_E1000_N_RX_DESC * CONFIG_E1000_BUFF_SIZE;
+ CONFIG_E1000_N_TX_DESC * CONFIG_E1000_BUFF_SIZE +
+ CONFIG_E1000_N_RX_DESC * sizeof(struct rx_desc) +
+ CONFIG_E1000_N_RX_DESC * CONFIG_E1000_BUFF_SIZE;
size = ROUNDUP(size, PGSIZE);
omem = kmem = memalign(PGSIZE, size);
if (kmem == NULL) {
- err = -ENOMEM;
- goto err1;
+ err = -ENOMEM;
+ goto err1;
}
rgmp_memremap_nocache((uintptr_t)kmem, size);
@@ -991,7 +984,7 @@ static int e1000_probe(uint16_t addr, pci_id_t id)
/* Register the device with the OS so that socket IOCTLs can be performed */
err = netdev_register(&dev->uip_dev);
if (err)
- goto err2;
+ goto err2;
// insert into e1000_list
dev->next = e1000_list.next;
@@ -1000,14 +993,14 @@ static int e1000_probe(uint16_t addr, pci_id_t id)
return 0;
- err2:
+err2:
rgmp_memremap((uintptr_t)omem, size);
free(omem);
- err1:
- rgmp_free_irq(irq, &dev->int_desc);
- err0:
+err1:
+ pci_free_irq(addr);
+err0:
rgmp_memunmap(mmio_base, mmio_size);
- error:
+error:
kfree(dev);
cprintf("e1000 device probe fail: %d\n", err);
return err;
@@ -1028,21 +1021,21 @@ void e1000_mod_exit(void)
struct e1000_dev *dev;
size = CONFIG_E1000_N_TX_DESC * sizeof(struct tx_desc) +
- CONFIG_E1000_N_TX_DESC * CONFIG_E1000_BUFF_SIZE +
- CONFIG_E1000_N_RX_DESC * sizeof(struct rx_desc) +
- CONFIG_E1000_N_RX_DESC * CONFIG_E1000_BUFF_SIZE;
+ CONFIG_E1000_N_TX_DESC * CONFIG_E1000_BUFF_SIZE +
+ CONFIG_E1000_N_RX_DESC * sizeof(struct rx_desc) +
+ CONFIG_E1000_N_RX_DESC * CONFIG_E1000_BUFF_SIZE;
size = ROUNDUP(size, PGSIZE);
for (dev=e1000_list.next; dev!=NULL; dev=dev->next) {
- netdev_unregister(&dev->uip_dev);
- e1000_reset(dev);
- wd_delete(dev->txpoll);
- wd_delete(dev->txtimeout);
- rgmp_memremap((uintptr_t)dev->tx_ring.desc, size);
- free(dev->tx_ring.desc);
- rgmp_free_irq(dev->irq, &dev->int_desc);
- rgmp_memunmap((uintptr_t)dev->io_mem_base, dev->mem_size);
- kfree(dev);
+ netdev_unregister(&dev->uip_dev);
+ e1000_reset(dev);
+ wd_delete(dev->txpoll);
+ wd_delete(dev->txtimeout);
+ rgmp_memremap((uintptr_t)dev->tx_ring.desc, size);
+ free(dev->tx_ring.desc);
+ pci_free_irq(dev->pci_addr);
+ rgmp_memunmap((uintptr_t)dev->io_mem_base, dev->mem_size);
+ kfree(dev);
}
e1000_list.next = NULL;
diff --git a/nuttx/drivers/net/e1000.h b/nuttx/drivers/net/e1000.h
index 6614ad77e..63ff53e3c 100644
--- a/nuttx/drivers/net/e1000.h
+++ b/nuttx/drivers/net/e1000.h
@@ -44,9 +44,7 @@
* Included Files
****************************************************************************/
-#include <rgmp/types.h>
-#include <rgmp/trap.h>
-#include <rgmp/arch/arch.h>
+#include <stdint.h>
/****************************************************************************
* Pre-processor Definitions
diff --git a/nuttx/drivers/net/vnet.c b/nuttx/drivers/net/vnet.c
index f1e2465b9..e05a39675 100644
--- a/nuttx/drivers/net/vnet.c
+++ b/nuttx/drivers/net/vnet.c
@@ -168,30 +168,30 @@ static int vnet_transmit(FAR struct vnet_driver_s *vnet)
{
int err;
- /* Verify that the hardware is ready to send another packet. If we get
- * here, then we are committed to sending a packet; Higher level logic
- * must have assured that there is not transmission in progress.
- */
+ /* Verify that the hardware is ready to send another packet. If we get
+ * here, then we are committed to sending a packet; Higher level logic
+ * must have assured that there is not transmission in progress.
+ */
- /* Increment statistics */
+ /* Increment statistics */
- /* Send the packet: address=vnet->sk_dev.d_buf, length=vnet->sk_dev.d_len */
+ /* Send the packet: address=vnet->sk_dev.d_buf, length=vnet->sk_dev.d_len */
err = vnet_xmit(vnet->vnet, (char *)vnet->sk_dev.d_buf, vnet->sk_dev.d_len);
if (err) {
- /* Setup the TX timeout watchdog (perhaps restarting the timer) */
- //(void)wd_start(vnet->sk_txtimeout, VNET_TXTIMEOUT, vnet_txtimeout, 1, (uint32_t)vnet);
+ /* Setup the TX timeout watchdog (perhaps restarting the timer) */
+ //(void)wd_start(vnet->sk_txtimeout, VNET_TXTIMEOUT, vnet_txtimeout, 1, (uint32_t)vnet);
- // When vnet_xmit fail, it means TX buffer is full. Watchdog
- // is of no use here because no TX done INT will happen. So
- // we reset the TX buffer directly.
+ // When vnet_xmit fail, it means TX buffer is full. Watchdog
+ // is of no use here because no TX done INT will happen. So
+ // we reset the TX buffer directly.
#ifdef CONFIG_DEBUG
- cprintf("VNET: TX buffer is full\n");
+ cprintf("VNET: TX buffer is full\n");
#endif
- return ERROR;
+ return ERROR;
}
else {
- // this step may be unnecessary here
- vnet_txdone(vnet);
+ // this step may be unnecessary here
+ vnet_txdone(vnet);
}
return OK;
@@ -223,29 +223,29 @@ static int vnet_transmit(FAR struct vnet_driver_s *vnet)
static int vnet_uiptxpoll(struct uip_driver_s *dev)
{
- FAR struct vnet_driver_s *vnet = (FAR struct vnet_driver_s *)dev->d_private;
+ FAR struct vnet_driver_s *vnet = (FAR struct vnet_driver_s *)dev->d_private;
- /* If the polling resulted in data that should be sent out on the network,
- * the field d_len is set to a value > 0.
- */
+ /* If the polling resulted in data that should be sent out on the network,
+ * the field d_len is set to a value > 0.
+ */
- if (vnet->sk_dev.d_len > 0)
+ if (vnet->sk_dev.d_len > 0)
{
- uip_arp_out(&vnet->sk_dev);
- vnet_transmit(vnet);
-
- /* Check if there is room in the device to hold another packet. If not,
- * return a non-zero value to terminate the poll.
- */
- if (vnet_is_txbuff_full(vnet->vnet))
- return 1;
+ uip_arp_out(&vnet->sk_dev);
+ vnet_transmit(vnet);
+
+ /* Check if there is room in the device to hold another packet. If not,
+ * return a non-zero value to terminate the poll.
+ */
+ if (vnet_is_txbuff_full(vnet->vnet))
+ return 1;
}
- /* If zero is returned, the polling will continue until all connections have
- * been examined.
- */
+ /* If zero is returned, the polling will continue until all connections have
+ * been examined.
+ */
- return 0;
+ return 0;
}
/****************************************************************************
@@ -265,54 +265,53 @@ static int vnet_uiptxpoll(struct uip_driver_s *dev)
*
****************************************************************************/
-void rtos_vnet_recv(struct rgmp_vnet *vnet_dummy, char *data, int len)
+void rtos_vnet_recv(struct rgmp_vnet *rgmp_vnet, char *data, int len)
{
- // now only support 1 vnet
- struct vnet_driver_s *vnet = &g_vnet[0];
+ struct vnet_driver_s *vnet = rgmp_vnet->priv;
do {
- /* Check for errors and update statistics */
+ /* Check for errors and update statistics */
- /* Check if the packet is a valid size for the uIP buffer configuration */
- if (len > CONFIG_NET_BUFSIZE || len < 14) {
+ /* Check if the packet is a valid size for the uIP buffer configuration */
+ if (len > CONFIG_NET_BUFSIZE || len < 14) {
#ifdef CONFIG_DEBUG
- cprintf("VNET: receive invalid packet of size %d\n", len);
+ cprintf("VNET: receive invalid packet of size %d\n", len);
#endif
- return;
- }
+ return;
+ }
- // Copy the data data from the hardware to vnet->sk_dev.d_buf. Set
- // amount of data in vnet->sk_dev.d_len
- memcpy(vnet->sk_dev.d_buf, data, len);
- vnet->sk_dev.d_len = len;
+ // Copy the data data from the hardware to vnet->sk_dev.d_buf. Set
+ // amount of data in vnet->sk_dev.d_len
+ memcpy(vnet->sk_dev.d_buf, data, len);
+ vnet->sk_dev.d_len = len;
- /* We only accept IP packets of the configured type and ARP packets */
+ /* We only accept IP packets of the configured type and ARP packets */
#ifdef CONFIG_NET_IPv6
- if (BUF->type == HTONS(UIP_ETHTYPE_IP6))
+ if (BUF->type == HTONS(UIP_ETHTYPE_IP6))
#else
- if (BUF->type == HTONS(UIP_ETHTYPE_IP))
+ if (BUF->type == HTONS(UIP_ETHTYPE_IP))
#endif
- {
- uip_arp_ipin(&vnet->sk_dev);
- uip_input(&vnet->sk_dev);
-
- // If the above function invocation resulted in data that should be
- // sent out on the network, the field d_len will set to a value > 0.
- if (vnet->sk_dev.d_len > 0) {
- uip_arp_out(&vnet->sk_dev);
- vnet_transmit(vnet);
- }
- }
- else if (BUF->type == htons(UIP_ETHTYPE_ARP)) {
- uip_arp_arpin(&vnet->sk_dev);
-
- // If the above function invocation resulted in data that should be
- // sent out on the network, the field d_len will set to a value > 0.
- if (vnet->sk_dev.d_len > 0) {
- vnet_transmit(vnet);
- }
- }
+ {
+ uip_arp_ipin(&vnet->sk_dev);
+ uip_input(&vnet->sk_dev);
+
+ // If the above function invocation resulted in data that should be
+ // sent out on the network, the field d_len will set to a value > 0.
+ if (vnet->sk_dev.d_len > 0) {
+ uip_arp_out(&vnet->sk_dev);
+ vnet_transmit(vnet);
+ }
+ }
+ else if (BUF->type == htons(UIP_ETHTYPE_ARP)) {
+ uip_arp_arpin(&vnet->sk_dev);
+
+ // If the above function invocation resulted in data that should be
+ // sent out on the network, the field d_len will set to a value > 0.
+ if (vnet->sk_dev.d_len > 0) {
+ vnet_transmit(vnet);
+ }
+ }
}
while (0); /* While there are more packets to be processed */
}
@@ -336,17 +335,17 @@ void rtos_vnet_recv(struct rgmp_vnet *vnet_dummy, char *data, int len)
static void vnet_txdone(FAR struct vnet_driver_s *vnet)
{
- /* Check for errors and update statistics */
+ /* Check for errors and update statistics */
- /* If no further xmits are pending, then cancel the TX timeout and
- * disable further Tx interrupts.
- */
+ /* If no further xmits are pending, then cancel the TX timeout and
+ * disable further Tx interrupts.
+ */
- //wd_cancel(vnet->sk_txtimeout);
+ //wd_cancel(vnet->sk_txtimeout);
- /* Then poll uIP for new XMIT data */
+ /* Then poll uIP for new XMIT data */
- (void)uip_poll(&vnet->sk_dev, vnet_uiptxpoll);
+ (void)uip_poll(&vnet->sk_dev, vnet_uiptxpoll);
}
/****************************************************************************
@@ -370,15 +369,15 @@ static void vnet_txdone(FAR struct vnet_driver_s *vnet)
static void vnet_txtimeout(int argc, uint32_t arg, ...)
{
- FAR struct vnet_driver_s *vnet = (FAR struct vnet_driver_s *)arg;
+ FAR struct vnet_driver_s *vnet = (FAR struct vnet_driver_s *)arg;
- /* Increment statistics and dump debug info */
+ /* Increment statistics and dump debug info */
- /* Then reset the hardware */
+ /* Then reset the hardware */
- /* Then poll uIP for new XMIT data */
+ /* Then poll uIP for new XMIT data */
- (void)uip_poll(&vnet->sk_dev, vnet_uiptxpoll);
+ (void)uip_poll(&vnet->sk_dev, vnet_uiptxpoll);
}
/****************************************************************************
@@ -401,28 +400,28 @@ static void vnet_txtimeout(int argc, uint32_t arg, ...)
static void vnet_polltimer(int argc, uint32_t arg, ...)
{
- FAR struct vnet_driver_s *vnet = (FAR struct vnet_driver_s *)arg;
+ FAR struct vnet_driver_s *vnet = (FAR struct vnet_driver_s *)arg;
- /* Check if there is room in the send another TX packet. We cannot perform
- * the TX poll if he are unable to accept another packet for transmission.
- */
- if (vnet_is_txbuff_full(vnet->vnet)) {
+ /* Check if there is room in the send another TX packet. We cannot perform
+ * the TX poll if he are unable to accept another packet for transmission.
+ */
+ if (vnet_is_txbuff_full(vnet->vnet)) {
#ifdef CONFIG_DEBUG
- cprintf("VNET: TX buffer is full\n");
+ cprintf("VNET: TX buffer is full\n");
#endif
- return;
- }
+ return;
+ }
- /* If so, update TCP timing states and poll uIP for new XMIT data. Hmmm..
- * might be bug here. Does this mean if there is a transmit in progress,
- * we will missing TCP time state updates?
- */
+ /* If so, update TCP timing states and poll uIP for new XMIT data. Hmmm..
+ * might be bug here. Does this mean if there is a transmit in progress,
+ * we will missing TCP time state updates?
+ */
- (void)uip_timer(&vnet->sk_dev, vnet_uiptxpoll, VNET_POLLHSEC);
+ (void)uip_timer(&vnet->sk_dev, vnet_uiptxpoll, VNET_POLLHSEC);
- /* Setup the watchdog poll timer again */
+ /* Setup the watchdog poll timer again */
- (void)wd_start(vnet->sk_txpoll, VNET_WDDELAY, vnet_polltimer, 1, arg);
+ (void)wd_start(vnet->sk_txpoll, VNET_WDDELAY, vnet_polltimer, 1, arg);
}
/****************************************************************************
@@ -444,20 +443,20 @@ static void vnet_polltimer(int argc, uint32_t arg, ...)
static int vnet_ifup(struct uip_driver_s *dev)
{
- FAR struct vnet_driver_s *vnet = (FAR struct vnet_driver_s *)dev->d_private;
+ FAR struct vnet_driver_s *vnet = (FAR struct vnet_driver_s *)dev->d_private;
- ndbg("Bringing up: %d.%d.%d.%d\n",
- dev->d_ipaddr & 0xff, (dev->d_ipaddr >> 8) & 0xff,
- (dev->d_ipaddr >> 16) & 0xff, dev->d_ipaddr >> 24 );
+ ndbg("Bringing up: %d.%d.%d.%d\n",
+ dev->d_ipaddr & 0xff, (dev->d_ipaddr >> 8) & 0xff,
+ (dev->d_ipaddr >> 16) & 0xff, dev->d_ipaddr >> 24 );
- /* Initialize PHYs, the Ethernet interface, and setup up Ethernet interrupts */
+ /* Initialize PHYs, the Ethernet interface, and setup up Ethernet interrupts */
- /* Set and activate a timer process */
+ /* Set and activate a timer process */
- (void)wd_start(vnet->sk_txpoll, VNET_WDDELAY, vnet_polltimer, 1, (uint32_t)vnet);
+ (void)wd_start(vnet->sk_txpoll, VNET_WDDELAY, vnet_polltimer, 1, (uint32_t)vnet);
- vnet->sk_bifup = true;
- return OK;
+ vnet->sk_bifup = true;
+ return OK;
}
/****************************************************************************
@@ -478,28 +477,28 @@ static int vnet_ifup(struct uip_driver_s *dev)
static int vnet_ifdown(struct uip_driver_s *dev)
{
- FAR struct vnet_driver_s *vnet = (FAR struct vnet_driver_s *)dev->d_private;
- irqstate_t flags;
+ FAR struct vnet_driver_s *vnet = (FAR struct vnet_driver_s *)dev->d_private;
+ irqstate_t flags;
- /* Disable the Ethernet interrupt */
+ /* Disable the Ethernet interrupt */
- flags = irqsave();
+ flags = irqsave();
- /* Cancel the TX poll timer and TX timeout timers */
+ /* Cancel the TX poll timer and TX timeout timers */
- wd_cancel(vnet->sk_txpoll);
- //wd_cancel(vnet->sk_txtimeout);
+ wd_cancel(vnet->sk_txpoll);
+ //wd_cancel(vnet->sk_txtimeout);
- /* Put the the EMAC is its reset, non-operational state. This should be
- * a known configuration that will guarantee the vnet_ifup() always
- * successfully brings the interface back up.
- */
+ /* Put the the EMAC is its reset, non-operational state. This should be
+ * a known configuration that will guarantee the vnet_ifup() always
+ * successfully brings the interface back up.
+ */
- /* Mark the device "down" */
+ /* Mark the device "down" */
- vnet->sk_bifup = false;
- irqrestore(flags);
- return OK;
+ vnet->sk_bifup = false;
+ irqrestore(flags);
+ return OK;
}
/****************************************************************************
@@ -523,35 +522,35 @@ static int vnet_ifdown(struct uip_driver_s *dev)
static int vnet_txavail(struct uip_driver_s *dev)
{
- FAR struct vnet_driver_s *vnet = (FAR struct vnet_driver_s *)dev->d_private;
- irqstate_t flags;
+ FAR struct vnet_driver_s *vnet = (FAR struct vnet_driver_s *)dev->d_private;
+ irqstate_t flags;
- /* Disable interrupts because this function may be called from interrupt
- * level processing.
- */
+ /* Disable interrupts because this function may be called from interrupt
+ * level processing.
+ */
- flags = irqsave();
+ flags = irqsave();
- /* Ignore the notification if the interface is not yet up */
+ /* Ignore the notification if the interface is not yet up */
- if (vnet->sk_bifup)
+ if (vnet->sk_bifup)
{
- /* Check if there is room in the hardware to hold another outgoing packet. */
- if (vnet_is_txbuff_full(vnet->vnet)) {
+ /* Check if there is room in the hardware to hold another outgoing packet. */
+ if (vnet_is_txbuff_full(vnet->vnet)) {
#ifdef CONFIG_DEBUG
- cprintf("VNET: TX buffer is full\n");
+ cprintf("VNET: TX buffer is full\n");
#endif
- goto out;
- }
+ goto out;
+ }
- /* If so, then poll uIP for new XMIT data */
+ /* If so, then poll uIP for new XMIT data */
- (void)uip_poll(&vnet->sk_dev, vnet_uiptxpoll);
+ (void)uip_poll(&vnet->sk_dev, vnet_uiptxpoll);
}
- out:
- irqrestore(flags);
- return OK;
+out:
+ irqrestore(flags);
+ return OK;
}
/****************************************************************************
@@ -575,11 +574,11 @@ static int vnet_txavail(struct uip_driver_s *dev)
#ifdef CONFIG_NET_IGMP
static int vnet_addmac(struct uip_driver_s *dev, FAR const uint8_t *mac)
{
- FAR struct vnet_driver_s *vnet = (FAR struct vnet_driver_s *)dev->d_private;
+ FAR struct vnet_driver_s *vnet = (FAR struct vnet_driver_s *)dev->d_private;
- /* Add the MAC address to the hardware multicast routing table */
+ /* Add the MAC address to the hardware multicast routing table */
- return OK;
+ return OK;
}
#endif
@@ -604,11 +603,11 @@ static int vnet_addmac(struct uip_driver_s *dev, FAR const uint8_t *mac)
#ifdef CONFIG_NET_IGMP
static int vnet_rmmac(struct uip_driver_s *dev, FAR const uint8_t *mac)
{
- FAR struct vnet_driver_s *vnet = (FAR struct vnet_driver_s *)dev->d_private;
+ FAR struct vnet_driver_s *vnet = (FAR struct vnet_driver_s *)dev->d_private;
- /* Add the MAC address to the hardware multicast routing table */
+ /* Add the MAC address to the hardware multicast routing table */
- return OK;
+ return OK;
}
#endif
@@ -633,41 +632,41 @@ static int vnet_rmmac(struct uip_driver_s *dev, FAR const uint8_t *mac)
*
****************************************************************************/
-void vnet_initialize(void)
+int vnet_init(struct rgmp_vnet *vnet)
{
- struct vnet_driver_s *priv;
- struct rgmp_vnet *vnet = vnet_list.next;
- int i;
+ struct vnet_driver_s *priv;
+ static int i = 0;
- for (i=0; i<CONFIG_VNET_NINTERFACES; i++) {
- if (vnet == NULL)
- break;
- priv = &g_vnet[i];
+ if (i >= CONFIG_VNET_NINTERFACES)
+ return -1;
- /* Initialize the driver structure */
+ priv = &g_vnet[i++];
- memset(priv, 0, sizeof(struct vnet_driver_s));
- priv->sk_dev.d_ifup = vnet_ifup; /* I/F down callback */
- priv->sk_dev.d_ifdown = vnet_ifdown; /* I/F up (new IP address) callback */
- priv->sk_dev.d_txavail = vnet_txavail; /* New TX data callback */
+ /* Initialize the driver structure */
+
+ memset(priv, 0, sizeof(struct vnet_driver_s));
+ priv->sk_dev.d_ifup = vnet_ifup; /* I/F down callback */
+ priv->sk_dev.d_ifdown = vnet_ifdown; /* I/F up (new IP address) callback */
+ priv->sk_dev.d_txavail = vnet_txavail; /* New TX data callback */
#ifdef CONFIG_NET_IGMP
- priv->sk_dev.d_addmac = vnet_addmac; /* Add multicast MAC address */
- priv->sk_dev.d_rmmac = vnet_rmmac; /* Remove multicast MAC address */
+ priv->sk_dev.d_addmac = vnet_addmac; /* Add multicast MAC address */
+ priv->sk_dev.d_rmmac = vnet_rmmac; /* Remove multicast MAC address */
#endif
- priv->sk_dev.d_private = (void*)g_vnet; /* Used to recover private state from dev */
+ priv->sk_dev.d_private = (void*)priv; /* Used to recover private state from dev */
+
+ /* Create a watchdog for timing polling for and timing of transmisstions */
- /* Create a watchdog for timing polling for and timing of transmisstions */
+ priv->sk_txpoll = wd_create(); /* Create periodic poll timer */
+ //priv->sk_txtimeout = wd_create(); /* Create TX timeout timer */
- priv->sk_txpoll = wd_create(); /* Create periodic poll timer */
- //priv->sk_txtimeout = wd_create(); /* Create TX timeout timer */
+ priv->vnet = vnet;
+ vnet->priv = priv;
- priv->vnet = vnet;
+ /* Register the device with the OS */
- /* Register the device with the OS */
+ (void)netdev_register(&priv->sk_dev);
- (void)netdev_register(&priv->sk_dev);
- vnet = vnet->next;
- }
+ return 0;
}
#endif /* CONFIG_NET && CONFIG_NET_VNET */
diff --git a/nuttx/drivers/power/Make.defs b/nuttx/drivers/power/Make.defs
index 45c6aebc3..e3452120d 100644
--- a/nuttx/drivers/power/Make.defs
+++ b/nuttx/drivers/power/Make.defs
@@ -47,7 +47,7 @@ CSRCS += pm_activity.c pm_changestate.c pm_checkstate.c pm_initialize.c pm_regis
POWER_DEPPATH := --dep-path power
POWER_VPATH := :power
-POWER_CFLAGS := ${shell $(TOPDIR)/tools/incdir.sh $(INCDIROPT) "$(CC)" $(TOPDIR)/drivers/power}
+POWER_CFLAGS := ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)drivers$(DELIM)power}
endif
@@ -73,7 +73,7 @@ endif
POWER_DEPPATH := --dep-path power
POWER_VPATH := :power
-POWER_CFLAGS := ${shell $(TOPDIR)/tools/incdir.sh $(INCDIROPT) "$(CC)" $(TOPDIR)/drivers/power}
+POWER_CFLAGS := ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)drivers$(DELIM)power}
endif
diff --git a/nuttx/drivers/sensors/Make.defs b/nuttx/drivers/sensors/Make.defs
index 866ccb053..1713edb99 100644
--- a/nuttx/drivers/sensors/Make.defs
+++ b/nuttx/drivers/sensors/Make.defs
@@ -1,7 +1,7 @@
############################################################################
# drivers/sensors/Make.defs
#
-# Copyright (C) 2011 Gregory Nutt. All rights reserved.
+# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
@@ -57,4 +57,4 @@ endif
DEPPATH += --dep-path sensors
VPATH += :sensors
-CFLAGS += ${shell $(TOPDIR)/tools/incdir.sh $(INCDIROPT) "$(CC)" $(TOPDIR)/drivers/sensors}
+CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)drivers$(DELIM)sensors}
diff --git a/nuttx/drivers/serial/Kconfig b/nuttx/drivers/serial/Kconfig
index 43869fdec..a1e0dff49 100644
--- a/nuttx/drivers/serial/Kconfig
+++ b/nuttx/drivers/serial/Kconfig
@@ -3,10 +3,12 @@
# see misc/tools/kconfig-language.txt.
#
-config LOWLEVEL_CONSOLE
+config DEV_LOWCONSOLE
bool "Low-level console support"
default n
depends on ARCH_LOWPUTC
+ ---help---
+ Use the simple, low-level, write-only serial console driver (minimal support)
config 16550_UART
bool "16550 UART Chip support"
@@ -317,7 +319,7 @@ config STANDARD_SERIAL
bool "Enable standard \"upper-half\" serial driver"
default y if MCU_SERIAL
default n if !MCU_SERIAL
- depends on !LOWLEVEL_CONSOLE
+ depends on !DEV_LOWCONSOLE
---help---
Enable the standard, upper-half serial driver used by most MCU serial peripherals.
@@ -422,7 +424,7 @@ config UART_TXBUFSIZE
config UART_BAUD
int "baud rate"
- default 11520
+ default 115200
help
The configured BAUD of the UART.
@@ -465,7 +467,7 @@ config UART0_TXBUFSIZE
config UART0_BAUD
int "baud rate"
- default 11520
+ default 115200
help
The configured BAUD of the UART.
@@ -508,7 +510,7 @@ config USART0_TXBUFSIZE
config USART0_BAUD
int "baud rate"
- default 11520
+ default 115200
help
The configured BAUD of the USART.
@@ -551,7 +553,7 @@ config UART1_TXBUFSIZE
config UART1_BAUD
int "baud rate"
- default 11520
+ default 115200
help
The configured BAUD of the UART.
@@ -594,7 +596,7 @@ config USART1_TXBUFSIZE
config USART1_BAUD
int "baud rate"
- default 11520
+ default 115200
help
The configured BAUD of the USART.
@@ -637,7 +639,7 @@ config UART2_TXBUFSIZE
config UART2_BAUD
int "baud rate"
- default 11520
+ default 115200
help
The configured BAUD of the UART.
@@ -680,7 +682,7 @@ config USART2_TXBUFSIZE
config USART2_BAUD
int "baud rate"
- default 11520
+ default 115200
help
The configured BAUD of the USART.
@@ -723,7 +725,7 @@ config UART3_TXBUFSIZE
config UART3_BAUD
int "baud rate"
- default 11520
+ default 115200
help
The configured BAUD of the UART.
@@ -766,7 +768,7 @@ config USART3_TXBUFSIZE
config USART3_BAUD
int "baud rate"
- default 11520
+ default 115200
help
The configured BAUD of the USART.
@@ -809,7 +811,7 @@ config UART4_TXBUFSIZE
config UART4_BAUD
int "baud rate"
- default 11520
+ default 115200
help
The configured BAUD of the UART.
@@ -852,7 +854,7 @@ config USART4_TXBUFSIZE
config USART4_BAUD
int "baud rate"
- default 11520
+ default 115200
help
The configured BAUD of the USART.
@@ -895,7 +897,7 @@ config UART5_TXBUFSIZE
config UART5_BAUD
int "baud rate"
- default 11520
+ default 115200
help
The configured BAUD of the UART.
@@ -938,7 +940,7 @@ config USART5_TXBUFSIZE
config USART5_BAUD
int "baud rate"
- default 11520
+ default 115200
help
The configured BAUD of the USART.
@@ -981,7 +983,7 @@ config USART6_TXBUFSIZE
config USART6_BAUD
int "baud rate"
- default 11520
+ default 115200
help
The configured BAUD of the USART.
@@ -1024,7 +1026,7 @@ config UART6_TXBUFSIZE
config UART6_BAUD
int "baud rate"
- default 11520
+ default 115200
help
The configured BAUD of the UART.
diff --git a/nuttx/drivers/serial/serial.c b/nuttx/drivers/serial/serial.c
index da326f8c6..8987f01b8 100644
--- a/nuttx/drivers/serial/serial.c
+++ b/nuttx/drivers/serial/serial.c
@@ -233,7 +233,9 @@ static int uart_putxmitchar(FAR uart_dev_t *dev, int ch)
}
}
- /* We won't get here */
+ /* We won't get here. Some compilers may complain that this code is
+ * unreachable.
+ */
return OK;
}
@@ -252,7 +254,7 @@ static inline ssize_t uart_irqwrite(FAR uart_dev_t *dev, FAR const char *buffer,
{
int ch = *buffer++;
- /* assume that this is console text output and always do \n -> \r\n conversion */
+ /* If this is the console, then we should replace LF with CR-LF */
if (ch == '\n')
{
diff --git a/nuttx/drivers/usbdev/Make.defs b/nuttx/drivers/usbdev/Make.defs
index f1b3c405a..e43693b29 100644
--- a/nuttx/drivers/usbdev/Make.defs
+++ b/nuttx/drivers/usbdev/Make.defs
@@ -59,5 +59,5 @@ CSRCS += usbdev_trace.c usbdev_trprintf.c
DEPPATH += --dep-path usbdev
VPATH += :usbdev
-CFLAGS += ${shell $(TOPDIR)/tools/incdir.sh $(INCDIROPT) "$(CC)" $(TOPDIR)/drivers/usbdev}
+CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)drivers$(DELIM)usbdev}
endif
diff --git a/nuttx/drivers/usbdev/pl2303.c b/nuttx/drivers/usbdev/pl2303.c
index 69bf87965..95f26c185 100644
--- a/nuttx/drivers/usbdev/pl2303.c
+++ b/nuttx/drivers/usbdev/pl2303.c
@@ -132,7 +132,7 @@
/* USB Controller */
#ifndef CONFIG_USBDEV_SELFPOWERED
-# define SELFPOWERED USB_CONFIG_ATT_SELFPOWER
+# define SELFPOWERED USB_CONFIG_ATTR_SELFPOWER
#else
# define SELFPOWERED (0)
#endif
diff --git a/nuttx/drivers/usbdev/usbmsc.h b/nuttx/drivers/usbdev/usbmsc.h
index 6a5530d9d..883a49951 100644
--- a/nuttx/drivers/usbdev/usbmsc.h
+++ b/nuttx/drivers/usbdev/usbmsc.h
@@ -227,7 +227,7 @@
/* USB Controller */
#ifndef CONFIG_USBDEV_SELFPOWERED
-# define SELFPOWERED USB_CONFIG_ATT_SELFPOWER
+# define SELFPOWERED USB_CONFIG_ATTR_SELFPOWER
#else
# define SELFPOWERED (0)
#endif
diff --git a/nuttx/drivers/usbhost/Make.defs b/nuttx/drivers/usbhost/Make.defs
index fd54ab53e..ebb522695 100644
--- a/nuttx/drivers/usbhost/Make.defs
+++ b/nuttx/drivers/usbhost/Make.defs
@@ -1,7 +1,7 @@
############################################################################
# drivers/usbhost/Make.defs
#
-# Copyright (C) 2010-2011 Gregory Nutt. All rights reserved.
+# Copyright (C) 2010-2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
@@ -45,7 +45,7 @@ CSRCS += usbhost_enumerate.c usbhost_storage.c usbhost_hidkbd.c
# Include add-on USB host driver logic (see misc/drivers)
ifeq ($(CONFIG_NET),y)
- RTL8187_CSRC := ${shell if [ -f usbhost/rtl8187x.c ]; then echo "rtl8187x.c"; fi}
+ RTL8187_CSRC := ${shell if [ -f usbhost$(DELIM)rtl8187x.c ]; then echo "rtl8187x.c"; fi}
CSRCS += $(RTL8187_CSRC)
endif
endif
@@ -54,4 +54,4 @@ endif
DEPPATH += --dep-path usbhost
VPATH += :usbhost
-CFLAGS += ${shell $(TOPDIR)/tools/incdir.sh $(INCDIROPT) "$(CC)" $(TOPDIR)/drivers/usbhost}
+CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)drivers$(DELIM)usbhost}
diff --git a/nuttx/drivers/wireless/Make.defs b/nuttx/drivers/wireless/Make.defs
index f47f7666a..fa8e8acb5 100644
--- a/nuttx/drivers/wireless/Make.defs
+++ b/nuttx/drivers/wireless/Make.defs
@@ -1,7 +1,7 @@
############################################################################
# drivers/wireless/Make.defs
#
-# Copyright (C) 2011 Gregory Nutt. All rights reserved.
+# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
@@ -41,7 +41,7 @@ CSRCS += cc1101.c ISM1_868MHzGFSK100kbps.c ISM2_905MHzGFSK250kbps.c
# Include wireless build support
-DEPPATH += --dep-path wireless/cc1101
-VPATH += :wireless/cc1101
-CFLAGS += ${shell $(TOPDIR)/tools/incdir.sh $(INCDIROPT) "$(CC)" $(TOPDIR)/drivers/wireless/cc1101}
+DEPPATH += --dep-path wireless$(DELIM)cc1101
+VPATH += :wireless$(DELIM)cc1101
+CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)drivers$(DELIM)wireless$(DELIM)cc1101}
endif
diff --git a/nuttx/fs/Makefile b/nuttx/fs/Makefile
index ce952e06f..6955c164b 100644
--- a/nuttx/fs/Makefile
+++ b/nuttx/fs/Makefile
@@ -120,25 +120,21 @@ $(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
$(BIN): $(OBJS)
- @( for obj in $(OBJS) ; do \
- $(call ARCHIVE, $@, $${obj}); \
- done ; )
+ $(call ARCHIVE, $@, $(OBJS))
.depend: Makefile $(SRCS)
- @$(MKDEP) --dep-path . $(MMAPDEPPATH) $(FATDEPPATH) $(ROMFSDEPPATH) $(NXFFSDEPPATH) $(NFSDEPPATH) \
- $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
- @touch $@
+ $(Q) $(MKDEP) --dep-path . $(MMAPDEPPATH) $(FATDEPPATH) $(ROMFSDEPPATH) $(NXFFSDEPPATH) $(NFSDEPPATH) \
+ "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
+ $(Q) touch $@
depend: .depend
clean:
- @rm -f $(BIN) *~ .*.swp
+ $(call DELFILE, $(BIN))
$(call CLEAN)
- @( for dir in $(SUBDIRS); do \
- rm -f $${dir}/*~ $${dir}/.*.swp; \
- done ; )
distclean: clean
- @rm -f Make.dep .depend
+ $(call DELFILE, Make.dep)
+ $(call DELFILE, .depend)
-include Make.dep
diff --git a/nuttx/fs/fs_stat.c b/nuttx/fs/fs_stat.c
index cf27e87a6..4df25028f 100644
--- a/nuttx/fs/fs_stat.c
+++ b/nuttx/fs/fs_stat.c
@@ -1,7 +1,7 @@
/****************************************************************************
* fs/fs_stat.c
*
- * Copyright (C) 2007-2009 , 2012Gregory Nutt. All rights reserved.
+ * Copyright (C) 2007-2009, 2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -122,7 +122,8 @@ static inline int statroot(FAR struct stat *buf)
/****************************************************************************
* Name: stat
*
- * Return: Zero on success; -1 on failure with errno set:
+ * Returned Value:
+ * Zero on success; -1 on failure with errno set:
*
* EACCES Search permission is denied for one of the directories in the
* path prefix of path.
@@ -134,7 +135,7 @@ static inline int statroot(FAR struct stat *buf)
*
****************************************************************************/
-int stat(const char *path, FAR struct stat *buf)
+int stat(FAR const char *path, FAR struct stat *buf)
{
FAR struct inode *inode;
const char *relpath = NULL;
diff --git a/nuttx/graphics/Makefile b/nuttx/graphics/Makefile
index 6e549c1dd..238e14df4 100644
--- a/nuttx/graphics/Makefile
+++ b/nuttx/graphics/Makefile
@@ -33,7 +33,6 @@
#
############################################################################
--include $(TOPDIR)/.config
-include $(TOPDIR)/Make.defs
DEPPATH = --dep-path .
@@ -44,34 +43,34 @@ endif
include nxglib/Make.defs
DEPPATH += --dep-path nxglib
-CFLAGS += ${shell $(TOPDIR)/tools/incdir.sh $(INCDIROPT) "$(CC)" $(TOPDIR)/graphics/nxglib}
+CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)/graphics/nxglib}
include nxbe/Make.defs
DEPPATH += --dep-path nxbe
-CFLAGS += ${shell $(TOPDIR)/tools/incdir.sh $(INCDIROPT) "$(CC)" $(TOPDIR)/graphics/nxbe}
+CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)/graphics/nxbe}
ifeq ($(CONFIG_NX_MULTIUSER),y)
include nxmu/Make.defs
DEPPATH += --dep-path nxmu
-CFLAGS += ${shell $(TOPDIR)/tools/incdir.sh $(INCDIROPT) "$(CC)" $(TOPDIR)/graphics/nxmu}
+CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)/graphics/nxmu}
else
include nxsu/Make.defs
DEPPATH += --dep-path nxsu
-CFLAGS += ${shell $(TOPDIR)/tools/incdir.sh $(INCDIROPT) "$(CC)" $(TOPDIR)/graphics/nxsu}
+CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)/graphics/nxsu}
endif
include nxtk/Make.defs
DEPPATH += --dep-path nxtk
-CFLAGS += ${shell $(TOPDIR)/tools/incdir.sh $(INCDIROPT) "$(CC)" $(TOPDIR)/graphics/nxtk}
+CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)/graphics/nxtk}
include nxfonts/Make.defs
DEPPATH += --dep-path nxfonts
-CFLAGS += ${shell $(TOPDIR)/tools/incdir.sh $(INCDIROPT) "$(CC)" $(TOPDIR)/graphics/nxfonts}
+CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)/graphics/nxfonts}
ifeq ($(CONFIG_NXCONSOLE),y)
include nxconsole/Make.defs
DEPPATH += --dep-path nxconsole
-CFLAGS += ${shell $(TOPDIR)/tools/incdir.sh $(INCDIROPT) "$(CC)" $(TOPDIR)/graphics/nxconsole}
+CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)/graphics/nxconsole}
endif
ASRCS = $(NXGLIB_ASRCS) $(NXBE_ASRCS) $(NX_ASRCS) $(NXTK_ASRCS) $(NXFONTS_ASRCS) $(NXCON_ASRCS)
@@ -97,84 +96,84 @@ all: mklibgraphics
gen32bppsources genfontsources
gen1bppsources:
- @$(MAKE) -C nxglib -f Makefile.sources TOPDIR=$(TOPDIR) NXGLIB_BITSPERPIXEL=1 EXTRADEFINES=$(EXTRADEFINES)
- @$(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_BITSPERPIXEL=1 EXTRADEFINES=$(EXTRADEFINES)
+ $(Q) $(MAKE) -C nxglib -f Makefile.sources TOPDIR=$(TOPDIR) NXGLIB_BITSPERPIXEL=1 EXTRADEFINES=$(EXTRADEFINES)
+ $(Q) $(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_BITSPERPIXEL=1 EXTRADEFINES=$(EXTRADEFINES)
gen2bppsource:
- @$(MAKE) -C nxglib -f Makefile.sources TOPDIR=$(TOPDIR) NXGLIB_BITSPERPIXEL=2 EXTRADEFINES=$(EXTRADEFINES)
- @$(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_BITSPERPIXEL=2 EXTRADEFINES=$(EXTRADEFINES)
+ $(Q) $(MAKE) -C nxglib -f Makefile.sources TOPDIR=$(TOPDIR) NXGLIB_BITSPERPIXEL=2 EXTRADEFINES=$(EXTRADEFINES)
+ $(Q) $(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_BITSPERPIXEL=2 EXTRADEFINES=$(EXTRADEFINES)
gen4bppsource:
- @$(MAKE) -C nxglib -f Makefile.sources TOPDIR=$(TOPDIR) NXGLIB_BITSPERPIXEL=4 EXTRADEFINES=$(EXTRADEFINES)
- @$(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_BITSPERPIXEL=4 EXTRADEFINES=$(EXTRADEFINES)
+ $(Q) $(MAKE) -C nxglib -f Makefile.sources TOPDIR=$(TOPDIR) NXGLIB_BITSPERPIXEL=4 EXTRADEFINES=$(EXTRADEFINES)
+ $(Q) $(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_BITSPERPIXEL=4 EXTRADEFINES=$(EXTRADEFINES)
gen8bppsource:
- @$(MAKE) -C nxglib -f Makefile.sources TOPDIR=$(TOPDIR) NXGLIB_BITSPERPIXEL=8 EXTRADEFINES=$(EXTRADEFINES)
- @$(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_BITSPERPIXEL=8 EXTRADEFINES=$(EXTRADEFINES)
+ $(Q) $(MAKE) -C nxglib -f Makefile.sources TOPDIR=$(TOPDIR) NXGLIB_BITSPERPIXEL=8 EXTRADEFINES=$(EXTRADEFINES)
+ $(Q) $(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_BITSPERPIXEL=8 EXTRADEFINES=$(EXTRADEFINES)
gen16bppsource:
- @$(MAKE) -C nxglib -f Makefile.sources TOPDIR=$(TOPDIR) NXGLIB_BITSPERPIXEL=16 EXTRADEFINES=$(EXTRADEFINES)
- @$(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_BITSPERPIXEL=16 EXTRADEFINES=$(EXTRADEFINES)
+ $(Q) $(MAKE) -C nxglib -f Makefile.sources TOPDIR=$(TOPDIR) NXGLIB_BITSPERPIXEL=16 EXTRADEFINES=$(EXTRADEFINES)
+ $(Q) $(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_BITSPERPIXEL=16 EXTRADEFINES=$(EXTRADEFINES)
gen24bppsource:
- @$(MAKE) -C nxglib -f Makefile.sources TOPDIR=$(TOPDIR) NXGLIB_BITSPERPIXEL=24 EXTRADEFINES=$(EXTRADEFINES)
- @$(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_BITSPERPIXEL=24 EXTRADEFINES=$(EXTRADEFINES)
+ $(Q) $(MAKE) -C nxglib -f Makefile.sources TOPDIR=$(TOPDIR) NXGLIB_BITSPERPIXEL=24 EXTRADEFINES=$(EXTRADEFINES)
+ $(Q) $(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_BITSPERPIXEL=24 EXTRADEFINES=$(EXTRADEFINES)
gen32bppsources:
- @$(MAKE) -C nxglib -f Makefile.sources TOPDIR=$(TOPDIR) NXGLIB_BITSPERPIXEL=32 EXTRADEFINES=$(EXTRADEFINES)
- @$(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_BITSPERPIXEL=32 EXTRADEFINES=$(EXTRADEFINES)
+ $(Q) $(MAKE) -C nxglib -f Makefile.sources TOPDIR=$(TOPDIR) NXGLIB_BITSPERPIXEL=32 EXTRADEFINES=$(EXTRADEFINES)
+ $(Q) $(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_BITSPERPIXEL=32 EXTRADEFINES=$(EXTRADEFINES)
genfontsources:
ifeq ($(CONFIG_NXFONT_SANS23X27),y)
- @$(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=1 EXTRADEFINES=$(EXTRADEFINES)
+ $(Q) $(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=1 EXTRADEFINES=$(EXTRADEFINES)
endif
ifeq ($(CONFIG_NXFONT_SANS22X29),y)
- @$(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=2 EXTRADEFINES=$(EXTRADEFINES)
+ $(Q) $(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=2 EXTRADEFINES=$(EXTRADEFINES)
endif
ifeq ($(CONFIG_NXFONT_SANS28X37),y)
- @$(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=3 EXTRADEFINES=$(EXTRADEFINES)
+ $(Q) $(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=3 EXTRADEFINES=$(EXTRADEFINES)
endif
ifeq ($(CONFIG_NXFONT_SANS39X48),y)
- @$(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=4 EXTRADEFINES=$(EXTRADEFINES)
+ $(Q) $(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=4 EXTRADEFINES=$(EXTRADEFINES)
endif
ifeq ($(CONFIG_NXFONT_SANS17X23B),y)
- @$(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=16 EXTRADEFINES=$(EXTRADEFINES)
+ $(Q) $(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=16 EXTRADEFINES=$(EXTRADEFINES)
endif
ifeq ($(CONFIG_NXFONT_SANS20X27B),y)
- @$(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=17 EXTRADEFINES=$(EXTRADEFINES)
+ $(Q) $(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=17 EXTRADEFINES=$(EXTRADEFINES)
endif
ifeq ($(CONFIG_NXFONT_SANS22X29B),y)
- @$(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=5 EXTRADEFINES=$(EXTRADEFINES)
+ $(Q) $(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=5 EXTRADEFINES=$(EXTRADEFINES)
endif
ifeq ($(CONFIG_NXFONT_SANS28X37B),y)
- @$(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=6 EXTRADEFINES=$(EXTRADEFINES)
+ $(Q) $(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=6 EXTRADEFINES=$(EXTRADEFINES)
endif
ifeq ($(CONFIG_NXFONT_SANS40X49B),y)
- @$(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=7 EXTRADEFINES=$(EXTRADEFINES)
+ $(Q) $(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=7 EXTRADEFINES=$(EXTRADEFINES)
endif
ifeq ($(CONFIG_NXFONT_SERIF22X29),y)
- @$(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=8 EXTRADEFINES=$(EXTRADEFINES)
+ $(Q) $(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=8 EXTRADEFINES=$(EXTRADEFINES)
endif
ifeq ($(CONFIG_NXFONT_SERIF29X37),y)
- @$(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=9 EXTRADEFINES=$(EXTRADEFINES)
+ $(Q) $(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=9 EXTRADEFINES=$(EXTRADEFINES)
endif
ifeq ($(CONFIG_NXFONT_SERIF38X48),y)
- @$(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=10 EXTRADEFINES=$(EXTRADEFINES)
+ $(Q) $(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=10 EXTRADEFINES=$(EXTRADEFINES)
endif
ifeq ($(CONFIG_NXFONT_SERIF22X28B),y)
- @$(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=11 EXTRADEFINES=$(EXTRADEFINES)
+ $(Q) $(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=11 EXTRADEFINES=$(EXTRADEFINES)
endif
ifeq ($(CONFIG_NXFONT_SERIF27X38B),y)
- @$(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=12 EXTRADEFINES=$(EXTRADEFINES)
+ $(Q) $(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=12 EXTRADEFINES=$(EXTRADEFINES)
endif
ifeq ($(CONFIG_NXFONT_SERIF38X49B),y)
- @$(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=13 EXTRADEFINES=$(EXTRADEFINES)
+ $(Q) $(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=13 EXTRADEFINES=$(EXTRADEFINES)
endif
ifeq ($(CONFIG_NXFONT_SANS17X22),y)
- @$(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=14 EXTRADEFINES=$(EXTRADEFINES)
+ $(Q) $(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=14 EXTRADEFINES=$(EXTRADEFINES)
endif
ifeq ($(CONFIG_NXFONT_SANS20X26),y)
- @$(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=15 EXTRADEFINES=$(EXTRADEFINES)
+ $(Q) $(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=15 EXTRADEFINES=$(EXTRADEFINES)
endif
gensources: gen1bppsources gen2bppsource gen4bppsource gen8bppsource gen16bppsource gen24bppsource gen32bppsources genfontsources
@@ -186,30 +185,29 @@ $(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
$(BIN): $(OBJS)
- @( for obj in $(OBJS) ; do \
- $(call ARCHIVE, $@, $${obj}); \
- done ; )
+ $(call ARCHIVE, $@, $(OBJS))
mklibgraphics: gensources $(BIN)
.depend: gensources Makefile $(SRCS)
- @$(MKDEP) $(DEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
- @touch $@
+ $(Q) $(MKDEP) $(DEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
+ $(Q) touch $@
depend: .depend
context: gensources
clean:
- @$(MAKE) -C nxglib -f Makefile.sources clean TOPDIR=$(TOPDIR) EXTRADEFINES=$(EXTRADEFINES)
- @$(MAKE) -C nxfonts -f Makefile.sources clean TOPDIR=$(TOPDIR) EXTRADEFINES=$(EXTRADEFINES)
- @rm -f $(BIN) *~ .*.swp
+ $(Q) $(MAKE) -C nxglib -f Makefile.sources clean TOPDIR=$(TOPDIR) EXTRADEFINES=$(EXTRADEFINES)
+ $(Q) $(MAKE) -C nxfonts -f Makefile.sources clean TOPDIR=$(TOPDIR) EXTRADEFINES=$(EXTRADEFINES)
+ $(call DELFILE, $(BIN))
$(call CLEAN)
distclean: clean
- @$(MAKE) -C nxglib -f Makefile.sources distclean TOPDIR=$(TOPDIR) EXTRADEFINES=$(EXTRADEFINES)
- @$(MAKE) -C nxfonts -f Makefile.sources distclean TOPDIR=$(TOPDIR) EXTRADEFINES=$(EXTRADEFINES)
- @rm -f Make.dep .depend
+ $(Q) $(MAKE) -C nxglib -f Makefile.sources distclean TOPDIR=$(TOPDIR) EXTRADEFINES=$(EXTRADEFINES)
+ $(Q) $(MAKE) -C nxfonts -f Makefile.sources distclean TOPDIR=$(TOPDIR) EXTRADEFINES=$(EXTRADEFINES)
+ $(call DELFILE, Make.dep)
+ $(call DELFILE, .depend)
-include Make.dep
diff --git a/nuttx/graphics/nxfonts/Makefile.sources b/nuttx/graphics/nxfonts/Makefile.sources
index f2aa87caf..76a099dcb 100644
--- a/nuttx/graphics/nxfonts/Makefile.sources
+++ b/nuttx/graphics/nxfonts/Makefile.sources
@@ -33,7 +33,6 @@
#
############################################################################
--include $(TOPDIR)/.config
-include $(TOPDIR)/Make.defs
ifdef NXFONTS_BITSPERPIXEL
@@ -177,13 +176,14 @@ all: $(GEN_CSRC)
.PHONY : clean distclean
$(GEN_CSRC) : $(DEPENDENCY)
- @$(call PREPROCESS, $<, $(GEN_TMP))
- @cat $(GEN_TMP) | sed -e "/^#/d" >$@
- @rm -f $(GEN_TMP)
+ $(call PREPROCESS, $<, $(GEN_TMP))
+ $(Q) cat $(GEN_TMP) | sed -e "/^#/d" >$@
+ $(Q) rm -f $(GEN_TMP)
clean:
- @rm -f *~ .*.swp *.i
+ $(call DELFILE, *.i)
+ $(call CLEAN)
distclean: clean
- @rm -f nxfonts_convert_*bpp.c
- @rm -f nxfonts_bitmaps_*.c
+ $(call DELFILE, nxfonts_convert_*bpp.c)
+ $(call DELFILE, nxfonts_bitmaps_*.c)
diff --git a/nuttx/graphics/nxglib/Makefile.sources b/nuttx/graphics/nxglib/Makefile.sources
index 67f8defc3..71d6e0661 100644
--- a/nuttx/graphics/nxglib/Makefile.sources
+++ b/nuttx/graphics/nxglib/Makefile.sources
@@ -33,7 +33,6 @@
#
############################################################################
--include $(TOPDIR)/.config
-include $(TOPDIR)/Make.defs
ifeq ($(NXGLIB_BITSPERPIXEL),1)
@@ -123,53 +122,54 @@ all: $(GEN_CSRCS)
$(SETP_CSRC) : $(BLITDIR)/nxglib_setpixel.c nxglib_bitblit.h
ifneq ($(NXGLIB_BITSPERPIXEL),)
- @$(call PREPROCESS, $(BLITDIR)/nxglib_setpixel.c, $(SETP_TMP))
- @cat $(SETP_TMP) | sed -e "/^#/d" >$@
- @rm -f $(SETP_TMP)
+ $(call PREPROCESS, $(BLITDIR)/nxglib_setpixel.c, $(SETP_TMP))
+ $(Q) cat $(SETP_TMP) | sed -e "/^#/d" >$@
+ $(Q) rm -f $(SETP_TMP)
endif
$(RFILL_CSRC) : $(BLITDIR)/nxglib_fillrectangle.c nxglib_bitblit.h
ifneq ($(NXGLIB_BITSPERPIXEL),)
- @$(call PREPROCESS, $(BLITDIR)/nxglib_fillrectangle.c, $(RFILL_TMP))
- @cat $(RFILL_TMP) | sed -e "/^#/d" >$@
- @rm -f $(RFILL_TMP)
+ $(call PREPROCESS, $(BLITDIR)/nxglib_fillrectangle.c, $(RFILL_TMP))
+ $(Q) cat $(RFILL_TMP) | sed -e "/^#/d" >$@
+ $(Q) rm -f $(RFILL_TMP)
endif
$(RGET_CSRC) : $(BLITDIR)/nxglib_getrectangle.c nxglib_bitblit.h
ifneq ($(NXGLIB_BITSPERPIXEL),)
- @$(call PREPROCESS, $(BLITDIR)/nxglib_getrectangle.c, $(RGET_TMP))
- @cat $(RGET_TMP) | sed -e "/^#/d" >$@
- @rm -f $(RGET_TMP)
+ $(call PREPROCESS, $(BLITDIR)/nxglib_getrectangle.c, $(RGET_TMP))
+ $(Q) cat $(RGET_TMP) | sed -e "/^#/d" >$@
+ $(Q) rm -f $(RGET_TMP)
endif
$(TFILL_CSRC) : $(BLITDIR)/nxglib_filltrapezoid.c nxglib_bitblit.h
ifneq ($(NXGLIB_BITSPERPIXEL),)
- @$(call PREPROCESS, $(BLITDIR)/nxglib_filltrapezoid.c, $(TFILL_TMP))
- @cat $(TFILL_TMP) | sed -e "/^#/d" >$@
- @rm -f $(TFILL_TMP)
+ $(call PREPROCESS, $(BLITDIR)/nxglib_filltrapezoid.c, $(TFILL_TMP))
+ $(Q) cat $(TFILL_TMP) | sed -e "/^#/d" >$@
+ $(Q) rm -f $(TFILL_TMP)
endif
$(RMOVE_CSRC) : $(BLITDIR)/nxglib_moverectangle.c nxglib_bitblit.h
ifneq ($(NXGLIB_BITSPERPIXEL),)
- @$(call PREPROCESS, $(BLITDIR)/nxglib_moverectangle.c, $(RMOVE_TMP))
- @cat $(RMOVE_TMP) | sed -e "/^#/d" >$@
- @rm -f $(RMOVE_TMP)
+ $(call PREPROCESS, $(BLITDIR)/nxglib_moverectangle.c, $(RMOVE_TMP))
+ $(Q) cat $(RMOVE_TMP) | sed -e "/^#/d" >$@
+ $(Q) rm -f $(RMOVE_TMP)
endif
$(RCOPY_CSRC) : $(BLITDIR)/nxglib_copyrectangle.c nxglib_bitblit.h
ifneq ($(NXGLIB_BITSPERPIXEL),)
- @$(call PREPROCESS, $(BLITDIR)/nxglib_copyrectangle.c, $(RCOPY_TMP))
- @cat $(RCOPY_TMP) | sed -e "/^#/d" >$@
- @rm -f $(RCOPY_TMP)
+ $(call PREPROCESS, $(BLITDIR)/nxglib_copyrectangle.c, $(RCOPY_TMP))
+ $(Q) cat $(RCOPY_TMP) | sed -e "/^#/d" >$@
+ $(Q) rm -f $(RCOPY_TMP)
endif
clean:
- @rm -f *~ .*.swp *.i
+ $(call DELFILE, *.i)
+ $(call CLEAN)
distclean: clean
- @rm -f nxglib_setpixel_*bpp.c
- @rm -f nxglib_fillrectangle_*bpp.c
- @rm -f nxglib_getrectangle_*bpp.c
- @rm -f nxglib_filltrapezoid_*bpp.c
- @rm -f nxglib_moverectangle_*bpp.c
- @rm -f nxglib_copyrectangle_*bpp.c
+ $(call DELFILE, nxglib_setpixel_*bpp.c)
+ $(call DELFILE, nxglib_fillrectangle_*bpp.c)
+ $(call DELFILE, nxglib_getrectangle_*bpp.c)
+ $(call DELFILE, nxglib_filltrapezoid_*bpp.c)
+ $(call DELFILE, nxglib_moverectangle_*bpp.c)
+ $(call DELFILE, nxglib_copyrectangle_*bpp.c)
diff --git a/nuttx/graphics/nxglib/nxglib_splitline.c b/nuttx/graphics/nxglib/nxglib_splitline.c
index 84892b67e..fa2ccc1a0 100644
--- a/nuttx/graphics/nxglib/nxglib_splitline.c
+++ b/nuttx/graphics/nxglib/nxglib_splitline.c
@@ -1,7 +1,7 @@
/****************************************************************************
* graphics/nxglib/nxglib_splitline.c
*
- * Copyright (C) 2011 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -41,6 +41,8 @@
#include <string.h>
#include <errno.h>
+#include <stdlib.h>
+#include <debug.h>
#include <nuttx/nx/nxglib.h>
@@ -48,12 +50,16 @@
* Pre-Processor Definitions
****************************************************************************/
-#define SMALL_SIN 1966 /* 1966/65536 = 0.03 */
-
/****************************************************************************
* Private Types
****************************************************************************/
+struct b16point_s
+{
+ b16_t x;
+ b16_t y;
+};
+
/****************************************************************************
* Private Data
****************************************************************************/
@@ -66,6 +72,12 @@
* Private Functions
****************************************************************************/
+static b16_t nxgl_interpolate(b16_t x, b16_t dy, b16_t dxdy)
+{
+ b16_t dx = b16mulb16(dy, dxdy);
+ return x + dx;
+}
+
/****************************************************************************
* Public Functions
****************************************************************************/
@@ -116,15 +128,19 @@ int nxgl_splitline(FAR struct nxgl_vector_s *vector,
struct nxgl_vector_s line;
nxgl_coord_t iheight;
nxgl_coord_t iwidth;
- nxgl_coord_t iy;
- nxgl_coord_t triheight;
- nxgl_coord_t halfheight;
- b16_t adjwidth;
- b16_t xoffset;
- b16_t halfoffset;
+ nxgl_coord_t iyoffset;
+ struct b16point_s quad[4];
+ b16_t b16xoffset;
+ b16_t b16yoffset;
+ b16_t b16dxdy;
b16_t angle;
+ b16_t cosangle;
b16_t sinangle;
b16_t b16x;
+ b16_t b16y;
+
+ gvdbg("vector: (%d,%d)->(%d,%d) linewidth: %d\n",
+ vector->pt1.x, vector->pt1.y, vector->pt2.x, vector->pt2.y, linewidth);
/* First, check the linewidth */
@@ -152,7 +168,7 @@ int nxgl_splitline(FAR struct nxgl_vector_s *vector,
line.pt2.x = vector->pt1.x;
line.pt2.y = vector->pt1.y;
}
- else
+ else /* if (vector->pt1.y == vector->pt2.y) */
{
/* First degenerate case: The line is horizontal. */
@@ -173,6 +189,10 @@ int nxgl_splitline(FAR struct nxgl_vector_s *vector,
rect->pt1.y = vector->pt1.y - (linewidth >> 1);
rect->pt2.y = rect->pt1.y + linewidth - 1;
+
+ gvdbg("Horizontal rect: (%d,%d),(%d,%d)\n",
+ rect->pt1.x, rect->pt1.y, rect->pt2.x, rect->pt2.y);
+
return 2;
}
@@ -187,14 +207,21 @@ int nxgl_splitline(FAR struct nxgl_vector_s *vector,
rect->pt1.x = line.pt1.x - (linewidth >> 1);
rect->pt2.x = rect->pt1.x + linewidth - 1;
+
+ gvdbg("Vertical rect: (%d,%d),(%d,%d)\n",
+ rect->pt1.x, rect->pt1.y, rect->pt2.x, rect->pt2.y);
+
return 2;
}
/* The final degenerate case */
- if (linewidth == 1)
+ if (linewidth == 1 &&
+ abs(line.pt2.x - line.pt1.x) < (line.pt2.y - line.pt1.y))
{
- /* A line of width 1 is basically a single parallelogram of width 1 */
+ /* A close to vertical line of width 1 is basically
+ * a single parallelogram of width 1.
+ */
traps[1].top.x1 = itob16(line.pt1.x);
traps[1].top.x2 = traps[1].top.x1;
@@ -203,6 +230,11 @@ int nxgl_splitline(FAR struct nxgl_vector_s *vector,
traps[1].bot.x1 = itob16(line.pt2.x);
traps[1].bot.x2 = traps[1].bot.x1;
traps[1].bot.y = line.pt2.y;
+
+ gvdbg("Vertical traps[1]: (%08x,%08x,%d),(%08x,%08x, %d)\n",
+ traps[1].top.x1, traps[1].top.x2, traps[1].top.y,
+ traps[1].bot.x1, traps[1].bot.x2, traps[1].bot.y);
+
return 1;
}
@@ -222,103 +254,260 @@ int nxgl_splitline(FAR struct nxgl_vector_s *vector,
iwidth = line.pt1.x - line.pt2.x + 1;
}
- /* Triangle height: linewidth * cosA
- * Adjusted width: triheight / sinA
- * X offset : linewidth * linewidth / adjusted line width
+ /* Applying the line width to the line results in a rotated, rectangle.
+ * Get the Y offset from an end of the original thin line to a corner of the fat line.
+ *
+ * Angle of line: angle = atan2(iheight, iwidth)
+ * Y offset from line: b16yoffset = linewidth * cos(angle)
+ *
+ * For near verical lines, b16yoffset is be nearly zero. For near horizontal
+ * lines, b16yOffset is be about the same as linewidth.
*/
- angle = b16atan2(itob16(iheight), itob16(iwidth));
- triheight = b16toi(linewidth * b16cos(angle) + b16HALF);
- halfheight = (triheight >> 1);
+ angle = b16atan2(itob16(iheight), itob16(iwidth));
+ cosangle = b16cos(angle);
+ b16yoffset = (linewidth * cosangle + 1) >> 1;
- /* If the sine of the angle is tiny (i.e., the line is nearly horizontal),
- * then we cannot compute the adjusted width. In this case, just use
- * the width of the line bounding box.
+ /* Get the X offset from an end of the original thin line to a corner of the fat line.
+ *
+ * For near vertical lines, b16xoffset is about the same as linewidth. For near
+ * horizontal lines, b16xoffset is nearly zero.
*/
- sinangle = b16sin(angle);
- if (sinangle < SMALL_SIN)
- {
- adjwidth = itob16(iwidth);
- xoffset = 0;
- }
- else
- {
- adjwidth = b16divb16(itob16(linewidth), sinangle);
- xoffset = itob16(linewidth * linewidth);
- xoffset = b16divb16(xoffset, adjwidth);
- }
+ sinangle = b16sin(angle);
+ b16xoffset = (linewidth * sinangle + 1) >> 1;
- halfoffset = (xoffset >> 1);
+ gvdbg("height: %d width: %d angle: %08x b16yoffset: %08x b16xoffset: %08x\n",
+ iheight, iwidth, angle, b16yoffset, b16xoffset);
- /* Return the top triangle (if there is one). NOTE that the horizontal
- * (z) positions are represented with 16 bits of fraction. The vertical
- * (y) positions, on the other hand, are integer.
- */
+ /* Now we know all four points of the rotated rectangle */
- if (triheight > 0)
+ iyoffset = b16toi(b16yoffset + b16HALF);
+ if (iyoffset > 0)
{
+ /* Get the Y positions of each point */
+
+ b16y = itob16(line.pt1.y);
+ quad[0].y = b16y - b16yoffset;
+ quad[1].y = b16y + b16yoffset;
+
+ b16y = itob16(line.pt2.y);
+ quad[2].y = b16y - b16yoffset;
+ quad[3].y = b16y + b16yoffset;
+
if (line.pt1.x < line.pt2.x)
{
- /* Line is going "south east" */
-
- b16x = itob16(line.pt1.x) - halfoffset;
- iy = line.pt1.y + halfheight;
-
- traps[0].top.x1 = b16x + xoffset;
- traps[0].top.x2 = traps[0].top.x1;
- traps[0].top.y = iy - triheight + 1;
- traps[0].bot.x1 = b16x;
- traps[0].bot.x2 = b16x + adjwidth - b16ONE;
- traps[0].bot.y = iy;
-
- b16x = itob16(line.pt2.x) + halfoffset;
- iy = line.pt2.y - halfheight;
-
- traps[2].top.x1 = b16x - adjwidth + b16ONE;
- traps[2].top.x2 = b16x;
- traps[2].top.y = iy;
- traps[2].bot.x1 = b16x - xoffset;
- traps[2].bot.x2 = traps[2].bot.x1;
- traps[2].bot.y = iy + triheight - 1;
+ /* Line is going "south east". Get the X positions of each point */
+
+ b16x = itob16(line.pt1.x);
+ quad[0].x = b16x + b16xoffset;
+ quad[1].x = b16x - b16xoffset;
+
+ b16x = itob16(line.pt2.x);
+ quad[2].x = b16x + b16xoffset;
+ quad[3].x = b16x - b16xoffset;
+
+ gvdbg("Southeast: quad (%08x,%08x),(%08x,%08x),(%08x,%08x),(%08x,%08x)\n",
+ quad[0].x, quad[0].y, quad[1].x, quad[1].y,
+ quad[2].x, quad[2].y, quad[3].x, quad[3].y);
+
+ /* Now we can form the trapezoids. The top of the first trapezoid
+ * (triangle) is at quad[0]
+ */
+
+ traps[0].top.x1 = quad[0].x;
+ traps[0].top.x2 = quad[0].x;
+ traps[0].top.y = b16toi(quad[0].y + b16HALF);
+
+ /* The bottom of the first trapezoid (triangle) may be either at
+ * quad[1] or quad[2], depending upon orientation.
+ */
+
+ if (quad[1]. y < quad[2].y)
+ {
+ /* quad[1] is at the bottom left of the triangle. Interpolate
+ * to get the corresponding point on the right side.
+ *
+ * Interpolation is from quad[0] along the line quad[0]->quad[2]
+ * which as the same slope as the line (positive)
+ */
+
+ b16dxdy = itob16(iwidth) / iheight;
+
+ traps[0].bot.x1 = quad[1].x;
+ traps[0].bot.x2 = nxgl_interpolate(quad[0].x, quad[1].y - quad[0].y, b16dxdy);
+ traps[0].bot.y = b16toi(quad[1].y + b16HALF);
+
+ /* quad[1] is at the top left of the second trapezoid. quad[2} is
+ * at the bottom right of the second trapezoid. Interpolate to get
+ * corresponding point on the left side.
+ *
+ * Interpolation is from quad[1] along the line quad[1]->quad[3]
+ * which as the same slope as the line (positive)
+ */
+
+ traps[1].top.x1 = traps[0].bot.x1;
+ traps[1].top.x2 = traps[0].bot.x2;
+ traps[1].top.y = traps[0].bot.y;
+
+ traps[1].bot.x1 = nxgl_interpolate(traps[1].top.x1, quad[2].y - quad[1].y, b16dxdy);
+ traps[1].bot.x2 = quad[2].x;
+ traps[1].bot.y = b16toi(quad[2].y + b16HALF);
+ }
+ else
+ {
+ /* quad[2] is at the bottom right of the triangle. Interpolate
+ * to get the corresponding point on the left side.
+ *
+ * Interpolation is from quad[0] along the line quad[0]->quad[1]
+ * which orthogonal to the slope of the line (and negative)
+ */
+
+ b16dxdy = -itob16(iheight) / iwidth;
+
+ traps[0].bot.x1 = nxgl_interpolate(quad[0].x, quad[2].y - quad[0].y, b16dxdy);
+ traps[0].bot.x2 = quad[2].x;
+ traps[0].bot.y = b16toi(quad[2].y + b16HALF);
+
+ /* quad[2] is at the top right of the second trapezoid. quad[1} is
+ * at the bottom left of the second trapezoid. Interpolate to get
+ * corresponding point on the right side.
+ *
+ * Interpolation is from quad[2] along the line quad[2]->quad[3]
+ * which as the same slope as the previous interpolation.
+ */
+
+ traps[1].top.x1 = traps[0].bot.x1;
+ traps[1].top.x2 = traps[0].bot.x2;
+ traps[1].top.y = traps[0].bot.y;
+
+ traps[1].bot.x1 = quad[1].x;
+ traps[1].bot.x2 = nxgl_interpolate(traps[1].top.x2, quad[1].y - quad[2].y, b16dxdy);
+ traps[1].bot.y = b16toi(quad[1].y + b16HALF);
+ }
+
+ /* The final trapezond (triangle) at the bottom is new well defined */
+
+ traps[2].top.x1 = traps[1].bot.x1;
+ traps[2].top.x2 = traps[1].bot.x2;
+ traps[2].top.y = traps[1].bot.y;
+
+ traps[2].bot.x1 = quad[3].x;
+ traps[2].bot.x2 = quad[3].x;
+ traps[2].bot.y = b16toi(quad[3].y + b16HALF);
}
else
{
- /* Line is going "south west" */
-
- b16x = itob16(line.pt1.x) + halfoffset;
- iy = line.pt1.y + halfheight;
-
- traps[0].top.x1 = b16x - xoffset;
- traps[0].top.x2 = traps[0].top.x1;
- traps[0].top.y = iy - triheight + 1;
- traps[0].bot.x1 = b16x - adjwidth + b16ONE;
- traps[0].bot.x2 = b16x;
- traps[0].bot.y = iy;
-
- b16x = itob16(line.pt2.x) - halfoffset;
- iy = line.pt2.y - halfheight;
-
- traps[2].top.x1 = b16x;
- traps[2].top.x2 = b16x + adjwidth - b16ONE;
- traps[2].top.y = iy;
- traps[2].bot.x1 = b16x + xoffset;
- traps[2].bot.x2 = traps[2].bot.x1;
- traps[2].bot.y = iy + triheight - 1;
+ /* Get the X positions of each point */
+
+ b16x = itob16(line.pt1.x);
+ quad[0].x = b16x - b16xoffset;
+ quad[1].x = b16x + b16xoffset;
+
+ b16x = itob16(line.pt2.x);
+ quad[2].x = b16x - b16xoffset;
+ quad[3].x = b16x + b16xoffset;
+
+ gvdbg("Southwest: quad (%08x,%08x),(%08x,%08x),(%08x,%08x),(%08x,%08x)\n",
+ quad[0].x, quad[0].y, quad[1].x, quad[1].y,
+ quad[2].x, quad[2].y, quad[3].x, quad[3].y);
+
+ /* Now we can form the trapezoids. The top of the first trapezoid
+ * (triangle) is at quad[0]
+ */
+
+ traps[0].top.x1 = quad[0].x;
+ traps[0].top.x2 = quad[0].x;
+ traps[0].top.y = b16toi(quad[0].y + b16HALF);
+
+ /* The bottom of the first trapezoid (triangle) may be either at
+ * quad[1] or quad[2], depending upon orientation.
+ */
+
+ if (quad[1].y < quad[2].y)
+ {
+ /* quad[1] is at the bottom right of the triangle. Interpolate
+ * to get the corresponding point on the left side.
+ *
+ * Interpolation is from quad[0] along the line quad[0]->quad[2]
+ * which as the same slope as the line (negative)
+ */
+
+ b16dxdy = -itob16(iwidth) / iheight;
+
+ traps[0].bot.x1 = nxgl_interpolate(traps[0].top.x1, quad[1].y - quad[0].y, b16dxdy);
+ traps[0].bot.x2 = quad[1].x;
+ traps[0].bot.y = b16toi(quad[1].y + b16HALF);
+
+ /* quad[1] is at the top right of the second trapezoid. quad[2} is
+ * at the bottom left of the second trapezoid. Interpolate to get
+ * corresponding point on the right side.
+ *
+ * Interpolation is from quad[1] along the line quad[1]->quad[3]
+ * which as the same slope as the line (negative)
+ */
+
+ traps[1].top.x1 = traps[0].bot.x1;
+ traps[1].top.x2 = traps[0].bot.x2;
+ traps[1].top.y = traps[0].bot.y;
+
+ traps[1].bot.x1 = quad[2].x;
+ traps[1].bot.x2 = nxgl_interpolate(traps[1].top.x2, quad[2].y - quad[1].y, b16dxdy);
+ traps[1].bot.y = b16toi(quad[2].y + b16HALF);
+ }
+ else
+ {
+ /* quad[2] is at the bottom left of the triangle. Interpolate
+ * to get the corresponding point on the right side.
+ *
+ * Interpolation is from quad[0] along the line quad[0]->quad[1]
+ * which orthogonal to the slope of the line (and positive)
+ */
+
+ b16dxdy = itob16(iheight) / iwidth;
+
+ traps[0].bot.x1 = quad[2].x;
+ traps[0].bot.x2 = nxgl_interpolate(traps[0].top.x2, quad[2].y - quad[0].y, b16dxdy);
+ traps[0].bot.y = b16toi(quad[2].y + b16HALF);
+
+ /* quad[2] is at the top left of the second trapezoid. quad[1} is
+ * at the bottom right of the second trapezoid. Interpolate to get
+ * corresponding point on the left side.
+ *
+ * Interpolation is from quad[2] along the line quad[2]->quad[3]
+ * which as the same slope as the previous interpolation.
+ */
+
+ traps[1].top.x1 = traps[0].bot.x1;
+ traps[1].top.x2 = traps[0].bot.x2;
+ traps[1].top.y = traps[0].bot.y;
+
+ traps[1].bot.x1 = nxgl_interpolate(traps[1].top.x1, quad[1].y - quad[2].y, b16dxdy);
+ traps[1].bot.x2 = quad[1].x;
+ traps[1].bot.y = b16toi(quad[1].y + b16HALF);
+ }
+
+ /* The final trapezond (triangle) at the bottom is new well defined */
+
+ traps[2].top.x1 = traps[1].bot.x1;
+ traps[2].top.x2 = traps[1].bot.x2;
+ traps[2].top.y = traps[1].bot.y;
+
+ traps[2].bot.x1 = quad[3].x;
+ traps[2].bot.x2 = quad[3].x;
+ traps[2].bot.y = b16toi(quad[3].y + b16HALF);
}
- /* The center parallelogram is the horizontal edge of each triangle.
- * Note the minor inefficency: that horizontal edges are drawn twice.
- */
+ gvdbg("traps[0]: (%08x,%08x,%d),(%08x,%08x,%d)\n",
+ traps[0].top.x1, traps[0].top.x2, traps[0].top.y,
+ traps[0].bot.x1, traps[0].bot.x2, traps[0].bot.y);
+ gvdbg("traps[1]: (%08x,%08x,%d),(%08x,%08x,%d)\n",
+ traps[1].top.x1, traps[1].top.x2, traps[1].top.y,
+ traps[1].bot.x1, traps[1].bot.x2, traps[1].bot.y);
+ gvdbg("traps[2]: (%08x,%08x,%d),(%08x,%08x,%d)\n",
+ traps[2].top.x1, traps[2].top.x2, traps[2].top.y,
+ traps[2].bot.x1, traps[2].bot.x2, traps[2].bot.y);
- traps[1].top.x1 = traps[0].bot.x1;
- traps[1].top.x2 = traps[0].bot.x2;
- traps[1].top.y = traps[0].bot.y;
-
- traps[1].bot.x1 = traps[2].top.x1;
- traps[1].bot.x2 = traps[2].top.x2;
- traps[1].bot.y = traps[2].top.y;
-
return 0;
}
@@ -326,12 +515,18 @@ int nxgl_splitline(FAR struct nxgl_vector_s *vector,
* bottom. Just return the center parallelogram.
*/
- traps[1].top.x1 = itob16(line.pt1.x) - halfoffset;
- traps[1].top.x2 = traps[1].top.x1 + adjwidth - 1;
+ traps[1].top.x1 = itob16(line.pt1.x - (linewidth >> 1));
+ traps[1].top.x2 = traps[1].top.x1 + itob16(linewidth - 1);
traps[1].top.y = line.pt1.y;
-
- traps[1].bot.x1 = itob16(line.pt2.x) - halfoffset;
- traps[1].bot.x2 = traps[1].bot.x1 + adjwidth - 1;
+
+ traps[1].bot.x1 = itob16(line.pt2.x - (linewidth >> 1));
+ traps[1].bot.x2 = traps[1].bot.x1 + itob16(linewidth - 1);
traps[1].bot.y = line.pt2.y;
+
+ gvdbg("Horizontal traps[1]: (%08x,%08x,%d),(%08x,%08x, %d)\n",
+ traps[1].top.x1, traps[1].top.x2, traps[1].top.y,
+ traps[1].bot.x1, traps[1].bot.x2, traps[1].bot.y);
+
return 1;
}
+
diff --git a/nuttx/graphics/nxmu/nx_bitmap.c b/nuttx/graphics/nxmu/nx_bitmap.c
index a86eda96a..a0bd748b0 100644
--- a/nuttx/graphics/nxmu/nx_bitmap.c
+++ b/nuttx/graphics/nxmu/nx_bitmap.c
@@ -100,6 +100,8 @@ int nx_bitmap(NXWINDOW hwnd, FAR const struct nxgl_rect_s *dest,
FAR struct nxbe_window_s *wnd = (FAR struct nxbe_window_s *)hwnd;
struct nxsvrmsg_bitmap_s outmsg;
int i;
+ int ret;
+ sem_t sem_done;
#ifdef CONFIG_DEBUG
if (!wnd || !dest || !src || !origin)
@@ -124,7 +126,32 @@ int nx_bitmap(NXWINDOW hwnd, FAR const struct nxgl_rect_s *dest,
outmsg.origin.y = origin->y;
nxgl_rectcopy(&outmsg.dest, dest);
+
+ /* Create a semaphore for tracking command completion */
+
+ outmsg.sem_done = &sem_done;
+ ret = sem_init(&sem_done, 0, 0);
+
+ if (ret != OK)
+ {
+ gdbg("sem_init failed: %d\n", errno);
+ return ret;
+ }
+
/* Forward the fill command to the server */
- return nxmu_sendwindow(wnd, &outmsg, sizeof(struct nxsvrmsg_bitmap_s));
+ ret = nxmu_sendwindow(wnd, &outmsg, sizeof(struct nxsvrmsg_bitmap_s));
+
+ /* Wait that the command is completed, so that caller can release the buffer. */
+
+ if (ret == OK)
+ {
+ ret = sem_wait(&sem_done);
+ }
+
+ /* Destroy the semaphore and return. */
+
+ sem_destroy(&sem_done);
+
+ return ret;
}
diff --git a/nuttx/graphics/nxmu/nx_block.c b/nuttx/graphics/nxmu/nx_block.c
index 3a051f9d7..7b198613c 100644
--- a/nuttx/graphics/nxmu/nx_block.c
+++ b/nuttx/graphics/nxmu/nx_block.c
@@ -140,7 +140,7 @@ int nx_block(NXWINDOW hwnd, FAR void *arg)
* that it will not be blocked.
*/
- ret = nxmu_sendserver(wnd->conn, &outmsg, sizeof(struct nxbe_window_s));
+ ret = nxmu_sendserver(wnd->conn, &outmsg, sizeof(struct nxsvrmsg_blocked_s));
}
return ret;
diff --git a/nuttx/graphics/nxmu/nx_getrectangle.c b/nuttx/graphics/nxmu/nx_getrectangle.c
index f32065129..9b7d3679c 100644
--- a/nuttx/graphics/nxmu/nx_getrectangle.c
+++ b/nuttx/graphics/nxmu/nx_getrectangle.c
@@ -98,7 +98,9 @@ int nx_getrectangle(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect,
{
FAR struct nxbe_window_s *wnd = (FAR struct nxbe_window_s *)hwnd;
struct nxsvrmsg_getrectangle_s outmsg;
-
+ int ret;
+ sem_t sem_done;
+
#ifdef CONFIG_DEBUG
if (!hwnd || !rect || !dest)
{
@@ -118,7 +120,31 @@ int nx_getrectangle(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect,
nxgl_rectcopy(&outmsg.rect, rect);
+ /* Create a semaphore for tracking command completion */
+
+ outmsg.sem_done = &sem_done;
+ ret = sem_init(&sem_done, 0, 0);
+
+ if (ret != OK)
+ {
+ gdbg("sem_init failed: %d\n", errno);
+ return ret;
+ }
+
/* Forward the fill command to the server */
- return nxmu_sendwindow(wnd, &outmsg, sizeof(struct nxsvrmsg_getrectangle_s));
+ ret = nxmu_sendwindow(wnd, &outmsg, sizeof(struct nxsvrmsg_getrectangle_s));
+
+ /* Wait that the command is completed, so that caller can release the buffer. */
+
+ if (ret == OK)
+ {
+ ret = sem_wait(&sem_done);
+ }
+
+ /* Destroy the semaphore and return. */
+
+ sem_destroy(&sem_done);
+
+ return ret;
}
diff --git a/nuttx/graphics/nxmu/nxfe.h b/nuttx/graphics/nxmu/nxfe.h
index 8b6a21ef4..b9e02616c 100644
--- a/nuttx/graphics/nxmu/nxfe.h
+++ b/nuttx/graphics/nxmu/nxfe.h
@@ -392,6 +392,7 @@ struct nxsvrmsg_getrectangle_s
unsigned int plane; /* The plane number to read */
FAR uint8_t *dest; /* Memory location in which to store the graphics data */
unsigned int deststride; /* Width of the destination memory in bytes */
+ sem_t *sem_done; /* Semaphore to report when command is done. */
};
/* Fill a trapezoidal region in the window with a color */
@@ -425,6 +426,7 @@ struct nxsvrmsg_bitmap_s
FAR const void *src[CONFIG_NX_NPLANES]; /* The start of the source image. */
struct nxgl_point_s origin; /* Offset into the source image data */
unsigned int stride; /* The width of the full source image in pixels. */
+ sem_t *sem_done; /* Semaphore to report when command is done. */
};
/* Set the color of the background */
@@ -587,6 +589,25 @@ EXTERN int nxmu_sendclient(FAR struct nxfe_conn_s *conn,
FAR const void *msg, size_t msglen);
/****************************************************************************
+ * Name: nxmu_sendclientwindow
+ *
+ * Description:
+ * Send a message to the client at NX_CLIMSG_PRIO priority
+ *
+ * Input Parameters:
+ * wnd - A pointer to the back-end window structure
+ * msg - A pointer to the message to send
+ * msglen - The length of the message in bytes.
+ *
+ * Return:
+ * OK on success; ERROR on failure with errno set appropriately
+ *
+ ****************************************************************************/
+
+int nxmu_sendclientwindow(FAR struct nxbe_window_s *wnd, FAR const void *msg,
+ size_t msglen);
+
+/****************************************************************************
* Name: nxmu_openwindow
*
* Description:
diff --git a/nuttx/graphics/nxmu/nxmu_kbdin.c b/nuttx/graphics/nxmu/nxmu_kbdin.c
index 2c658009b..0308c2bfa 100644
--- a/nuttx/graphics/nxmu/nxmu_kbdin.c
+++ b/nuttx/graphics/nxmu/nxmu_kbdin.c
@@ -108,7 +108,7 @@ void nxmu_kbdin(FAR struct nxfe_state_s *fe, uint8_t nch, FAR uint8_t *ch)
outmsg->ch[i] = ch[i];
}
- (void)nxmu_sendclient(fe->be.topwnd->conn, outmsg, size);
+ (void)nxmu_sendclientwindow(fe->be.topwnd, outmsg, size);
free(outmsg);
}
}
diff --git a/nuttx/graphics/nxmu/nxmu_mouse.c b/nuttx/graphics/nxmu/nxmu_mouse.c
index 3ebe062d2..1b8f4a592 100644
--- a/nuttx/graphics/nxmu/nxmu_mouse.c
+++ b/nuttx/graphics/nxmu/nxmu_mouse.c
@@ -61,9 +61,10 @@
* Private Data
****************************************************************************/
-static struct nxgl_point_s g_mpos;
-static struct nxgl_point_s g_mrange;
-static uint8_t g_mbutton;
+static struct nxgl_point_s g_mpos;
+static struct nxgl_point_s g_mrange;
+static uint8_t g_mbutton;
+static struct nxbe_window_s *g_mwnd;
/****************************************************************************
* Public Data
@@ -129,7 +130,7 @@ int nxmu_mousereport(struct nxbe_window_s *wnd)
outmsg.buttons = g_mbutton;
nxgl_vectsubtract(&outmsg.pos, &g_mpos, &wnd->bounds.pt1);
- return nxmu_sendclient(wnd->conn, &outmsg, sizeof(struct nxclimsg_mousein_s));
+ return nxmu_sendclientwindow(wnd, &outmsg, sizeof(struct nxclimsg_mousein_s));
}
}
@@ -154,6 +155,7 @@ int nxmu_mousein(FAR struct nxfe_state_s *fe,
struct nxbe_window_s *wnd;
nxgl_coord_t x = pos->x;
nxgl_coord_t y = pos->y;
+ uint8_t oldbuttons;
int ret;
/* Clip x and y to within the bounding rectangle */
@@ -182,20 +184,36 @@ int nxmu_mousein(FAR struct nxfe_state_s *fe,
{
/* Update the mouse value */
- g_mpos.x = x;
- g_mpos.y = y;
- g_mbutton = buttons;
+ oldbuttons = g_mbutton;
+ g_mpos.x = x;
+ g_mpos.y = y;
+ g_mbutton = buttons;
- /* Pick the window to receive the mouse event. Start with
- * the top window and go down. Stop with the first window
- * that gets the mouse report
+ /* If a button is already down, regard this as part of a mouse drag
+ * event. Pass all the following events to the window where the drag
+ * started in.
+ */
+
+ if (oldbuttons && g_mwnd && g_mwnd->cb->mousein)
+ {
+ struct nxclimsg_mousein_s outmsg;
+ outmsg.msgid = NX_CLIMSG_MOUSEIN;
+ outmsg.wnd = g_mwnd;
+ outmsg.buttons = g_mbutton;
+ nxgl_vectsubtract(&outmsg.pos, &g_mpos, &g_mwnd->bounds.pt1);
+
+ return nxmu_sendclientwindow(g_mwnd, &outmsg, sizeof(struct nxclimsg_mousein_s));
+ }
+
+ /* Pick the window to receive the mouse event. Start with the top
+ * window and go down. Stop with the first window that gets the mouse
+ * report
*/
for (wnd = fe->be.topwnd; wnd; wnd = wnd->below)
{
- /* The background window normally has no callback structure
- * (unless a client has taken control of the background via
- * nx_requestbkgd()).
+ /* The background window normally has no callback structure (unless
+ * a client has taken control of the background via nx_requestbkgd()).
*/
if (wnd->cb)
@@ -207,6 +225,8 @@ int nxmu_mousein(FAR struct nxfe_state_s *fe,
}
}
}
+
+ g_mwnd = wnd;
}
return OK;
diff --git a/nuttx/graphics/nxmu/nxmu_redrawreq.c b/nuttx/graphics/nxmu/nxmu_redrawreq.c
index 32ca477a2..f54aa85a7 100644
--- a/nuttx/graphics/nxmu/nxmu_redrawreq.c
+++ b/nuttx/graphics/nxmu/nxmu_redrawreq.c
@@ -87,7 +87,7 @@ void nxfe_redrawreq(FAR struct nxbe_window_s *wnd, FAR const struct nxgl_rect_s
outmsg.more = false;
nxgl_rectoffset(&outmsg.rect, rect, -wnd->bounds.pt1.x, -wnd->bounds.pt1.y);
- (void)nxmu_sendclient(wnd->conn, &outmsg, sizeof(struct nxclimsg_redraw_s));
+ (void)nxmu_sendclientwindow(wnd, &outmsg, sizeof(struct nxclimsg_redraw_s));
}
diff --git a/nuttx/graphics/nxmu/nxmu_reportposition.c b/nuttx/graphics/nxmu/nxmu_reportposition.c
index f9b5f9daf..6ffb3f4ee 100644
--- a/nuttx/graphics/nxmu/nxmu_reportposition.c
+++ b/nuttx/graphics/nxmu/nxmu_reportposition.c
@@ -100,7 +100,7 @@ void nxfe_reportposition(FAR struct nxbe_window_s *wnd)
/* And provide this to the client */
- ret = nxmu_sendclient(wnd->conn, &outmsg, sizeof(struct nxclimsg_newposition_s));
+ ret = nxmu_sendclientwindow(wnd, &outmsg, sizeof(struct nxclimsg_newposition_s));
if (ret < 0)
{
gdbg("nxmu_sendclient failed: %d\n", errno);
diff --git a/nuttx/graphics/nxmu/nxmu_sendwindow.c b/nuttx/graphics/nxmu/nxmu_sendwindow.c
index 6f64ffff2..0826a45bc 100644
--- a/nuttx/graphics/nxmu/nxmu_sendwindow.c
+++ b/nuttx/graphics/nxmu/nxmu_sendwindow.c
@@ -112,3 +112,47 @@ int nxmu_sendwindow(FAR struct nxbe_window_s *wnd, FAR const void *msg,
return ret;
}
+
+/****************************************************************************
+ * Name: nxmu_sendclientwindow
+ *
+ * Description:
+ * Send a message to the client at NX_CLIMSG_PRIO priority
+ *
+ * Input Parameters:
+ * wnd - A pointer to the back-end window structure
+ * msg - A pointer to the message to send
+ * msglen - The length of the message in bytes.
+ *
+ * Return:
+ * OK on success; ERROR on failure with errno set appropriately
+ *
+ ****************************************************************************/
+
+int nxmu_sendclientwindow(FAR struct nxbe_window_s *wnd, FAR const void *msg,
+ size_t msglen)
+{
+ int ret = OK;
+
+ /* Sanity checking */
+
+#ifdef CONFIG_DEBUG
+ if (!wnd || !wnd->conn)
+ {
+ errno = EINVAL;
+ return ERROR;
+ }
+#endif
+
+ /* Ignore messages destined to a blocked window (no errors reported) */
+
+ if (!NXBE_ISBLOCKED(wnd))
+ {
+ /* Send the message to the server */
+
+ ret = nxmu_sendclient(wnd->conn, msg, msglen);
+ }
+
+ return ret;
+}
+
diff --git a/nuttx/graphics/nxmu/nxmu_server.c b/nuttx/graphics/nxmu/nxmu_server.c
index 2730e0ea2..cfaa5bbf5 100644
--- a/nuttx/graphics/nxmu/nxmu_server.c
+++ b/nuttx/graphics/nxmu/nxmu_server.c
@@ -451,6 +451,11 @@ int nx_runinstance(FAR const char *mqname, FAR NX_DRIVERTYPE *dev)
{
FAR struct nxsvrmsg_getrectangle_s *getmsg = (FAR struct nxsvrmsg_getrectangle_s *)buffer;
nxbe_getrectangle(getmsg->wnd, &getmsg->rect, getmsg->plane, getmsg->dest, getmsg->deststride);
+
+ if (getmsg->sem_done)
+ {
+ sem_post(getmsg->sem_done);
+ }
}
break;
@@ -471,6 +476,11 @@ int nx_runinstance(FAR const char *mqname, FAR NX_DRIVERTYPE *dev)
{
FAR struct nxsvrmsg_bitmap_s *bmpmsg = (FAR struct nxsvrmsg_bitmap_s *)buffer;
nxbe_bitmap(bmpmsg->wnd, &bmpmsg->dest, bmpmsg->src, &bmpmsg->origin, bmpmsg->stride);
+
+ if (bmpmsg->sem_done)
+ {
+ sem_post(bmpmsg->sem_done);
+ }
}
break;
diff --git a/nuttx/graphics/nxsu/nx_mousein.c b/nuttx/graphics/nxsu/nx_mousein.c
index bee4a2265..5b268358b 100644
--- a/nuttx/graphics/nxsu/nx_mousein.c
+++ b/nuttx/graphics/nxsu/nx_mousein.c
@@ -62,9 +62,10 @@
* Private Data
****************************************************************************/
-static struct nxgl_point_s g_mpos;
-static struct nxgl_point_s g_mrange;
-static uint8_t g_mbutton;
+static struct nxgl_point_s g_mpos;
+static struct nxgl_point_s g_mrange;
+static uint8_t g_mbutton;
+static struct nxbe_window_s *g_mwnd;
/****************************************************************************
* Public Data
@@ -148,6 +149,7 @@ int nx_mousein(NXHANDLE handle, nxgl_coord_t x, nxgl_coord_t y, uint8_t buttons)
{
FAR struct nxfe_state_s *fe = (FAR struct nxfe_state_s *)handle;
struct nxbe_window_s *wnd;
+ uint8_t oldbuttons;
int ret;
/* Clip x and y to within the bounding rectangle */
@@ -176,13 +178,27 @@ int nx_mousein(NXHANDLE handle, nxgl_coord_t x, nxgl_coord_t y, uint8_t buttons)
{
/* Update the mouse value */
+ oldbuttons = g_mbutton;
g_mpos.x = x;
g_mpos.y = y;
g_mbutton = buttons;
- /* Pick the window to receive the mouse event. Start with
- * the top window and go down. Step with the first window
- * that gets the mouse report
+ /* If a button is already down, regard this as part of a mouse drag
+ * event. Pass all the following events to the window where the drag
+ * started in.
+ */
+
+ if (oldbuttons && g_mwnd && g_mwnd->cb->mousein)
+ {
+ struct nxgl_point_s relpos;
+ nxgl_vectsubtract(&relpos, &g_mpos, &g_mwnd->bounds.pt1);
+ g_mwnd->cb->mousein((NXWINDOW)g_mwnd, &relpos, g_mbutton, g_mwnd->arg);
+ return OK;
+ }
+
+ /* Pick the window to receive the mouse event. Start with the top
+ * window and go down. Step with the first window that gets the mouse
+ * report
*/
for (wnd = fe->be.topwnd; wnd; wnd = wnd->below)
@@ -193,6 +209,8 @@ int nx_mousein(NXHANDLE handle, nxgl_coord_t x, nxgl_coord_t y, uint8_t buttons)
break;
}
}
+
+ g_mwnd = wnd;
}
return OK;
}
diff --git a/nuttx/graphics/nxtk/nxtk_events.c b/nuttx/graphics/nxtk/nxtk_events.c
index 33c50b7f9..facf92176 100644
--- a/nuttx/graphics/nxtk/nxtk_events.c
+++ b/nuttx/graphics/nxtk/nxtk_events.c
@@ -76,6 +76,9 @@ static void nxtk_mousein(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos,
static void nxtk_kbdin(NXWINDOW hwnd, uint8_t nch, const uint8_t *ch,
FAR void *arg);
#endif
+#ifdef CONFIG_NX_MULTIUSER
+static void nxtk_blocked(NXWINDOW hwnd, FAR void *arg1, FAR void *arg2);
+#endif
/****************************************************************************
* Private Data
@@ -95,6 +98,9 @@ const struct nx_callback_s g_nxtkcb =
#ifdef CONFIG_NX_KBD
, nxtk_kbdin /* kbdin */
#endif
+#ifdef CONFIG_NX_MULTIUSER
+ , nxtk_blocked
+#endif
};
/****************************************************************************
@@ -255,9 +261,20 @@ static void nxtk_mousein(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos,
nxgl_vectoradd(&abspos, pos, &fwnd->wnd.bounds.pt1);
+ /* In order to deliver mouse release events to the same window where the
+ * mouse down event happened, we store the initial mouse down location.
+ */
+
+ if (fwnd->mbutton == 0 && buttons != 0)
+ {
+ fwnd->mpos = abspos;
+ }
+
+ fwnd->mbutton = buttons;
+
/* Is the mouse position inside of the client window region? */
- if (fwnd->fwcb->mousein && nxgl_rectinside(&fwnd->fwrect, &abspos))
+ if (fwnd->fwcb->mousein && nxgl_rectinside(&fwnd->fwrect, &fwnd->mpos))
{
nxgl_vectsubtract(&relpos, &abspos, &fwnd->fwrect.pt1);
fwnd->fwcb->mousein((NXTKWINDOW)fwnd, &relpos, buttons, fwnd->fwarg);
@@ -265,7 +282,7 @@ static void nxtk_mousein(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos,
/* If the mouse position inside the toobar region? */
- else if (fwnd->tbcb->mousein && nxgl_rectinside(&fwnd->tbrect, &abspos))
+ else if (fwnd->tbcb->mousein && nxgl_rectinside(&fwnd->tbrect, &fwnd->mpos))
{
nxgl_vectsubtract(&relpos, &abspos, &fwnd->tbrect.pt1);
fwnd->tbcb->mousein((NXTKWINDOW)fwnd, &relpos, buttons, fwnd->tbarg);
@@ -293,5 +310,23 @@ static void nxtk_kbdin(NXWINDOW hwnd, uint8_t nch, const uint8_t *ch,
#endif
/****************************************************************************
+ * Name: nxtk_blocked
+ ****************************************************************************/
+
+#ifdef CONFIG_NX_MULTIUSER
+static void nxtk_blocked(NXWINDOW hwnd, FAR void *arg1, FAR void *arg2)
+{
+ FAR struct nxtk_framedwindow_s *fwnd = (FAR struct nxtk_framedwindow_s *)hwnd;
+
+ /* Only the client window gets keyboard input */
+
+ if (fwnd->fwcb->blocked)
+ {
+ fwnd->fwcb->blocked((NXTKWINDOW)fwnd, fwnd->fwarg, arg2);
+ }
+}
+#endif
+
+/****************************************************************************
* Public Functions
****************************************************************************/
diff --git a/nuttx/graphics/nxtk/nxtk_filltrapwindow.c b/nuttx/graphics/nxtk/nxtk_filltrapwindow.c
index c1032f1e7..55c051ffd 100644
--- a/nuttx/graphics/nxtk/nxtk_filltrapwindow.c
+++ b/nuttx/graphics/nxtk/nxtk_filltrapwindow.c
@@ -94,6 +94,7 @@ int nxtk_filltrapwindow(NXTKWINDOW hfwnd, FAR const struct nxgl_trapezoid_s *tra
{
FAR struct nxtk_framedwindow_s *fwnd = (FAR struct nxtk_framedwindow_s *)hfwnd;
struct nxgl_rect_s relclip;
+ struct nxgl_trapezoid_s reltrap;
#ifdef CONFIG_DEBUG
if (!hfwnd || !trap || !color)
@@ -103,8 +104,14 @@ int nxtk_filltrapwindow(NXTKWINDOW hfwnd, FAR const struct nxgl_trapezoid_s *tra
}
#endif
- /* Perform the fill, clipping to the client window */
+ /* Move the trapezoid from window contents area to window area */
+ nxgl_trapoffset(&reltrap, trap,
+ fwnd->fwrect.pt1.x - fwnd->wnd.bounds.pt1.x,
+ fwnd->fwrect.pt1.y - fwnd->wnd.bounds.pt1.y);
+
+ /* Perform the fill, clipping to the client window */
nxgl_rectoffset(&relclip, &fwnd->fwrect, -fwnd->wnd.bounds.pt1.x, -fwnd->wnd.bounds.pt1.y);
- return nx_filltrapezoid((NXWINDOW)hfwnd, &relclip, trap, color);
+
+ return nx_filltrapezoid((NXWINDOW)hfwnd, &relclip, &reltrap, color);
}
diff --git a/nuttx/graphics/nxtk/nxtk_getwindow.c b/nuttx/graphics/nxtk/nxtk_getwindow.c
index 121c7702a..c91f2d22f 100644
--- a/nuttx/graphics/nxtk/nxtk_getwindow.c
+++ b/nuttx/graphics/nxtk/nxtk_getwindow.c
@@ -110,12 +110,15 @@ int nxtk_getwindow(NXTKWINDOW hfwnd, FAR const struct nxgl_rect_s *rect,
}
#endif
- /* Clip the rectangle so that it lies within the sub-window bounds
- * then move the rectangle to that it is relative to the containing
- * window.
+ /* Move the rectangle to that it is relative to the containing
+ * window. If part of the rectangle lies outside the window,
+ * it will contain garbage data, but the contained area will be
+ * valid.
*/
- nxtk_subwindowclip(fwnd, &getrect, rect, &fwnd->fwrect);
+ nxgl_rectoffset(&getrect, rect,
+ fwnd->fwrect.pt1.x - fwnd->wnd.bounds.pt1.x,
+ fwnd->fwrect.pt1.y - fwnd->wnd.bounds.pt1.y);
/* Then get it */
diff --git a/nuttx/graphics/nxtk/nxtk_internal.h b/nuttx/graphics/nxtk/nxtk_internal.h
index 87a098845..3a31215d8 100644
--- a/nuttx/graphics/nxtk/nxtk_internal.h
+++ b/nuttx/graphics/nxtk/nxtk_internal.h
@@ -72,6 +72,11 @@ struct nxtk_framedwindow_s
struct nxgl_rect_s fwrect;
FAR const struct nx_callback_s *fwcb;
FAR void *fwarg;
+
+ /* Initial mouse down location */
+
+ uint8_t mbutton;
+ struct nxgl_point_s mpos;
};
/****************************************************************************
diff --git a/nuttx/graphics/nxtk/nxtk_subwindowmove.c b/nuttx/graphics/nxtk/nxtk_subwindowmove.c
index a6fd9f5dd..3c2bb7f37 100644
--- a/nuttx/graphics/nxtk/nxtk_subwindowmove.c
+++ b/nuttx/graphics/nxtk/nxtk_subwindowmove.c
@@ -112,21 +112,19 @@ void nxtk_subwindowmove(FAR struct nxtk_framedwindow_s *fwnd,
nxgl_rectintersect(&abssrc, &abssrc, &fwnd->fwrect);
- /* Clip the offset so that the source rectangle does not move out of the
- * the client sub-window.
- */
+ /* Clip the source rectangle so that destination area is within the window. */
destoffset->x = srcoffset->x;
if (destoffset->x < 0)
{
if (abssrc.pt1.x + destoffset->x < bounds->pt1.x)
{
- destoffset->x = bounds->pt1.x - abssrc.pt1.x;
+ abssrc.pt1.x = bounds->pt1.x - destoffset->x;
}
}
else if (abssrc.pt2.x + destoffset->x > bounds->pt2.x)
{
- destoffset->x = bounds->pt2.x - abssrc.pt2.x;
+ abssrc.pt2.x = bounds->pt2.x - destoffset->x;
}
destoffset->y = srcoffset->y;
@@ -134,12 +132,12 @@ void nxtk_subwindowmove(FAR struct nxtk_framedwindow_s *fwnd,
{
if (abssrc.pt1.y + destoffset->y < bounds->pt1.y)
{
- destoffset->y = bounds->pt1.y - abssrc.pt1.y;
+ abssrc.pt1.y = bounds->pt1.y - destoffset->y;
}
}
else if (abssrc.pt2.y + destoffset->y > bounds->pt2.y)
{
- destoffset->y = bounds->pt2.y - abssrc.pt2.y;
+ abssrc.pt2.y = bounds->pt2.y - destoffset->y;
}
diff --git a/nuttx/include/cxx/cmath b/nuttx/include/cxx/cmath
index 7cb3a2109..b30d5548b 100644
--- a/nuttx/include/cxx/cmath
+++ b/nuttx/include/cxx/cmath
@@ -40,6 +40,9 @@
// Included Files
//***************************************************************************
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
#include <math.h>
//***************************************************************************
@@ -48,6 +51,34 @@
namespace std
{
+#if CONFIG_HAVE_FLOAT
+ using ::acosf;
+ using ::asinf;
+ using ::atanf;
+ using ::atan2f;
+ using ::ceilf;
+ using ::cosf;
+ using ::coshf;
+ using ::expf;
+ using ::fabsf;
+ using ::floorf;
+ using ::fmodf;
+ using ::frexpf;
+ using ::ldexpf;
+ using ::logf;
+ using ::log10f;
+ using ::log2f;
+ using ::modff;
+ using ::roundf;
+ using ::powf;
+ using ::sinf;
+ using ::sinhf;
+ using ::sqrtf;
+ using ::tanf;
+ using ::tanhf;
+#endif
+
+#if CONFIG_HAVE_DOUBLE
using ::acos;
using ::asin;
using ::atan;
@@ -63,13 +94,44 @@ namespace std
using ::ldexp;
using ::log;
using ::log10;
+ using ::log2;
using ::modf;
+ using ::round;
using ::pow;
using ::sin;
using ::sinh;
using ::sqrt;
using ::tan;
using ::tanh;
+#endif
+
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+ using ::acosl;
+ using ::asinl;
+ using ::atanl;
+ using ::atan2l;
+ using ::ceill;
+ using ::cosl;
+ using ::coshl;
+ using ::expl;
+ using ::fabsl;
+ using ::floorl;
+ using ::fmodl;
+ using ::frexpl;
+ using ::ldexpl;
+ using ::logl;
+ using ::log10l;
+ using ::log2l;
+ using ::modfl;
+ using ::roundl;
+ using ::powl;
+ using ::sinl;
+ using ::sinhl;
+ using ::sqrtl;
+ using ::tanl;
+ using ::tanhl;
+#endif
+
}
#endif // __INCLUDE_CXX_CMATH
diff --git a/nuttx/include/cxx/cstdbool b/nuttx/include/cxx/cstdbool
index d2f0639d2..192fde490 100644
--- a/nuttx/include/cxx/cstdbool
+++ b/nuttx/include/cxx/cstdbool
@@ -46,4 +46,13 @@
// Namespace
//***************************************************************************
+//***************************************************************************
+// Namespace
+//***************************************************************************
+
+namespace std
+{
+ using ::_Bool8;
+}
+
#endif // __INCLUDE_CXX_CSTDBOOL
diff --git a/nuttx/include/cxx/cstdio b/nuttx/include/cxx/cstdio
index 900d429cb..6a9620e1a 100644
--- a/nuttx/include/cxx/cstdio
+++ b/nuttx/include/cxx/cstdio
@@ -52,6 +52,8 @@ namespace std
using ::FILE;
using ::fpos_t;
using ::size_t;
+
+ using ::clearerr;
using ::fclose;
using ::fflush;
using ::feof;
@@ -69,16 +71,24 @@ namespace std
using ::ftell;
using ::fwrite;
using ::gets;
+ using ::ungetc;
+
using ::printf;
using ::puts;
using ::rename;
using ::sprintf;
+ using ::asprintf;
using ::snprintf;
- using ::ungetc;
+ using ::sscanf;
+ using ::perror;
+
using ::vprintf;
using ::vfprintf;
using ::vsprintf;
+ using ::avsprintf;
using ::vsnprintf;
+ using ::vsscanf;
+
using ::fdopen;
using ::statfs;
}
diff --git a/nuttx/include/cxx/cstdlib b/nuttx/include/cxx/cstdlib
index 522f3fdb1..1bf8ed9da 100644
--- a/nuttx/include/cxx/cstdlib
+++ b/nuttx/include/cxx/cstdlib
@@ -70,6 +70,7 @@ namespace std
#endif
using ::strtol;
+ using ::strtoul;
using ::strtod;
using ::malloc;
diff --git a/nuttx/include/debug.h b/nuttx/include/debug.h
index 1f8c7d7ca..aa5efd432 100644
--- a/nuttx/include/debug.h
+++ b/nuttx/include/debug.h
@@ -571,12 +571,9 @@
* Public Function Prototypes
****************************************************************************/
-#undef EXTERN
#if defined(__cplusplus)
-#define EXTERN extern "C"
-extern "C" {
-#else
-#define EXTERN extern
+extern "C"
+{
#endif
/* These low-level debug APIs are provided by the NuttX library. If the
@@ -585,21 +582,20 @@ extern "C" {
* or the other of the following.
*/
-EXTERN int lib_rawprintf(FAR const char *format, ...);
+int lib_rawprintf(FAR const char *format, ...);
#ifdef CONFIG_ARCH_LOWPUTC
-EXTERN int lib_lowprintf(FAR const char *format, ...);
+int lib_lowprintf(FAR const char *format, ...);
#endif
/* Dump a buffer of data */
-EXTERN void lib_dumpbuffer(FAR const char *msg, FAR const uint8_t *buffer,
- unsigned int buflen);
+void lib_dumpbuffer(FAR const char *msg, FAR const uint8_t *buffer, unsigned int buflen);
/* Enable or disable debug output */
#ifdef CONFIG_DEBUG_ENABLE
-EXTERN void dbg_enable(bool enable);
+void dbg_enable(bool enable);
#endif
/* If the cross-compiler's pre-processor does not support variable length
@@ -608,23 +604,22 @@ EXTERN void dbg_enable(bool enable);
#ifndef CONFIG_CPP_HAVE_VARARGS
#ifdef CONFIG_DEBUG
-EXTERN int dbg(const char *format, ...);
+int dbg(const char *format, ...);
# ifdef CONFIG_ARCH_LOWPUTC
-EXTERN int lldbg(const char *format, ...);
+int lldbg(const char *format, ...);
# endif
# ifdef CONFIG_DEBUG_VERBOSE
-EXTERN int vdbg(const char *format, ...);
+int vdbg(const char *format, ...);
# ifdef CONFIG_ARCH_LOWPUTC
-EXTERN int llvdbg(const char *format, ...);
+int llvdbg(const char *format, ...);
# endif
#endif
#endif /* CONFIG_DEBUG */
#endif /* CONFIG_CPP_HAVE_VARARGS */
-#undef EXTERN
#if defined(__cplusplus)
}
#endif
diff --git a/nuttx/include/elf32.h b/nuttx/include/elf32.h
new file mode 100644
index 000000000..e16ae0091
--- /dev/null
+++ b/nuttx/include/elf32.h
@@ -0,0 +1,352 @@
+/****************************************************************************
+ * include/elf32.h
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * Reference: System V Application Binary Interface, Edition 4.1, March 18,
+ * 1997, The Santa Cruz Operation, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_ELF32_H
+#define __INCLUDE_ELF32_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdint.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Values for Elf32_Ehdr::e_type */
+
+#define ET_NONE 0 /* No file type */
+#define ET_REL 1 /* Relocatable file */
+#define ET_EXEC 2 /* Executable file */
+#define ET_DYN 3 /* Shared object file */
+#define ET_CORE 4 /* Core file */
+#define ET_LOPROC 0xff00 /* Processor-specific */
+#define ET_HIPROC 0xffff /* Processor-specific */
+
+/* Values for Elf32_Ehdr::e_machine (most of this were not included in the
+ * original SCO document but have been gleaned from elsewhere).
+ */
+
+#define EM_NONE 0 /* No machine */
+#define EM_M32 1 /* AT&T WE 32100 */
+#define EM_SPARC 2 /* SPARC */
+#define EM_386 3 /* Intel 80386 */
+#define EM_68K 4 /* Motorola 68000 */
+#define EM_88K 5 /* Motorola 88000 */
+#define EM_486 6 /* Intel 486+ */
+#define EM_860 7 /* Intel 80860 */
+#define EM_MIPS 8 /* MIPS R3000 Big-Endian */
+#define EM_MIPS_RS4_BE 10 /* MIPS R4000 Big-Endian */
+#define EM_PARISC 15 /* HPPA */
+#define EM_SPARC32PLUS 18 /* Sun's "v8plus" */
+#define EM_PPC 20 /* PowerPC */
+#define EM_PPC64 21 /* PowerPC64 */
+#define EM_ARM 40 /* ARM */
+#define EM_SH 42 /* SuperH */
+#define EM_SPARCV9 43 /* SPARC v9 64-bit */
+#define EM_IA_64 50 /* HP/Intel IA-64 */
+#define EM_X86_64 62 /* AMD x86-64 */
+#define EM_S390 22 /* IBM S/390 */
+#define EM_CRIS 76 /* Axis Communications 32-bit embedded processor */
+#define EM_V850 87 /* NEC v850 */
+#define EM_M32R 88 /* Renesas M32R */
+#define EM_H8_300 46
+#define EM_ALPHA 0x9026
+#define EM_CYGNUS_V850 0x9080
+#define EM_CYGNUS_M32R 0x9041
+#define EM_S390_OLD 0xa390
+#define EM_FRV 0x5441
+
+/* Values for Elf32_Ehdr::e_version */
+
+#define EV_NONE 0 /* Invalid version */
+#define EV_CURRENT 1 /* The current version */
+
+/* Ehe ELF identifier */
+
+#define EI_MAG0 0 /* File identification */
+#define EI_MAG1 1 /* " " " " */
+#define EI_MAG2 2 /* " " " " */
+#define EI_MAG3 3 /* " " " " */
+#define EI_CLASS 4 /* File class */
+#define EI_DATA 5 /* Data encoding */
+#define EI_VERSION 6 /* File version */
+#define EI_PAD 7 /* Start of padding bytes */
+#define EI_NIDENT 16 /* Size of eident[] */
+
+#define EI_MAGIC_SIZE 4
+#define EI_MAGIC {0x7f, 'E', 'L', 'F'}
+
+/* Values for EI_CLASS */
+
+#define ELFCLASSNONE 0 /* Invalid class */
+#define ELFCLASS32 1 /* 32-bit objects */
+#define ELFCLASS64 2 /* 64-bit objects */
+
+/* Values for EI_DATA */
+
+#define ELFDATANONE 0 /* Invalid data encoding */
+#define ELFDATA2LSB 1 /* Least significant byte occupying the lowest address */
+#define ELFDATA2MSB 2 /* Most significant byte occupying the lowest address */
+
+/* Figure 4-7: Special Section Indexes */
+
+#define SHN_UNDEF 0
+#define SHN_LORESERVE 0xff00
+#define SHN_LOPROC 0xff00
+#define SHN_HIPROC 0xff1f
+#define SHN_ABS 0xfff1
+#define SHN_COMMON 0xfff2
+#define SHN_HIRESERVE 0xffff
+
+/* Figure 4-9: Section Types, sh_type */
+
+#define SHT_NULL 0
+#define SHT_PROGBITS 1
+#define SHT_SYMTAB 2
+#define SHT_STRTAB 3
+#define SHT_RELA 4
+#define SHT_HASH 5
+#define SHT_DYNAMIC 6
+#define SHT_NOTE 7
+#define SHT_NOBITS 8
+#define SHT_REL 9
+#define SHT_SHLIB 10
+#define SHT_DYNSYM 11
+#define SHT_LOPROC 0x70000000
+#define SHT_HIPROC 0x7fffffff
+#define SHT_LOUSER 0x80000000
+#define SHT_HIUSER 0xffffffff
+
+/* Figure 4-11: Section Attribute Flags, sh_flags */
+
+#define SHF_WRITE 1
+#define SHF_ALLOC 2
+#define SHF_EXECINSTR 4
+#define SHF_MASKPROC 0xf0000000
+
+/* Definitions for Elf32_Sym::st_info */
+
+#define ELF32_ST_BIND(i) ((i) >> 4)
+#define ELF32_ST_TYPE(i) ((i) & 0xf)
+#define ELF32_ST_INFO(b,t) (((b) << 4) | ((t) & 0xf))
+
+/* Figure 4-16: Symbol Binding, ELF32_ST_BIND */
+
+#define STB_LOCAL 0
+#define STB_GLOBAL 1
+#define STB_WEAK 2
+#define STB_LOPROC 13
+#define STB_HIPROC 15
+
+/* Figure 4-17: Symbol Types, ELF32_ST_TYPE */
+
+#define STT_NOTYPE 0
+#define STT_OBJECT 1
+#define STT_FUNC 2
+#define STT_SECTION 3
+#define STT_FILE 4
+#define STT_LOPROC 13
+#define STT_HIPROC 15
+
+/* Definitions for Elf32_Rel*::r_info */
+
+#define ELF32_R_SYM(i) ((i) >> 8)
+#define ELF32_R_TYPE(i) ((i) & 0xff)
+#define ELF32_R_INFO(s,t) (((s)<< 8) | ((t) & 0xff))
+
+/* Figure 5-2: Segment Types, p_type */
+
+#define PT_NULL 0
+#define PT_LOAD 1
+#define PT_DYNAMIC 2
+#define PT_INTERP 3
+#define PT_NOTE 4
+#define PT_SHLIB 5
+#define PT_PHDR 6
+#define PT_LOPROC 0x70000000
+#define PT_HIPROC 0x7fffffff
+
+/* Figure 5-3: Segment Flag Bits, p_flags */
+
+#define PF_X 1 /* Execute */
+#define PF_W 2 /* Write */
+#define PF_R 4 /* Read */
+#define PF_MASKPROC 0xf0000000 /* Unspecified */
+
+/* Figure 5-10: Dynamic Array Tags, d_tag */
+
+#define DT_NULL 0 /* d_un=ignored */
+#define DT_NEEDED 1 /* d_un=d_val */
+#define DT_PLTRELSZ 2 /* d_un=d_val */
+#define DT_PLTGOT 3 /* d_un=d_ptr */
+#define DT_HASH 4 /* d_un=d_ptr */
+#define DT_STRTAB 5 /* d_un=d_ptr */
+#define DT_SYMTAB 6 /* d_un=d_ptr */
+#define DT_RELA 7 /* d_un=d_ptr */
+#define DT_RELASZ 8 /* d_un=d_val */
+#define DT_RELAENT 9 /* d_un=d_val */
+#define DT_STRSZ 10 /* d_un=d_val */
+#define DT_SYMENT 11 /* d_un=d_val */
+#define DT_INIT 12 /* d_un=d_ptr */
+#define DT_FINI 13 /* d_un=d_ptr */
+#define DT_SONAME 14 /* d_un=d_val */
+#define DT_RPATH 15 /* d_un=d_val */
+#define DT_SYMBOLIC 16 /* d_un=ignored */
+#define DT_REL 17 /* d_un=d_ptr */
+#define DT_RELSZ 18 /* d_un=d_val */
+#define DT_RELENT 19 /* d_un=d_val */
+#define DT_PLTREL 20 /* d_un=d_val */
+#define DT_DEBUG 21 /* d_un=d_ptr */
+#define DT_TEXTREL 22 /* d_un=ignored */
+#define DT_JMPREL 23 /* d_un=d_ptr */
+#define DT_BINDNOW 24 /* d_un=ignored */
+#define DT_LOPROC 0x70000000 /* d_un=unspecified */
+#define DT_HIPROC 0x7fffffff /* d_un= unspecified */
+
+/****************************************************************************
+ * Public Type Definitions
+ ****************************************************************************/
+
+/* Figure 4.2: 32-Bit Data Types */
+
+typedef uint32_t Elf32_Addr; /* Unsigned program address */
+typedef uint16_t Elf32_Half; /* Unsigned medium integer */
+typedef uint32_t Elf32_Off; /* Unsigned file offset */
+typedef int32_t Elf32_Sword; /* Signed large integer */
+typedef uint32_t Elf32_Word; /* Unsigned large integer */
+
+/* Figure 4-3: ELF Header */
+
+typedef struct
+{
+ unsigned char e_ident[EI_NIDENT];
+ Elf32_Half e_type;
+ Elf32_Half e_machine;
+ Elf32_Word e_version;
+ Elf32_Addr e_entry;
+ Elf32_Off e_phoff;
+ Elf32_Off e_shoff;
+ Elf32_Word e_flags;
+ Elf32_Half e_ehsize;
+ Elf32_Half e_phentsize;
+ Elf32_Half e_phnum;
+ Elf32_Half e_shentsize;
+ Elf32_Half e_shnum;
+ Elf32_Half e_shstrndx;
+} Elf32_Ehdr;
+
+/* Figure 4-8: Section Header */
+
+typedef struct
+{
+ Elf32_Word sh_name;
+ Elf32_Word sh_type;
+ Elf32_Word sh_flags;
+ Elf32_Addr sh_addr;
+ Elf32_Off sh_offset;
+ Elf32_Word sh_size;
+ Elf32_Word sh_link;
+ Elf32_Word sh_info;
+ Elf32_Word sh_addralign;
+ Elf32_Word sh_entsize;
+} Elf32_Shdr;
+
+/* Figure 4-15: Symbol Table Entry */
+
+typedef struct
+{
+ Elf32_Word st_name;
+ Elf32_Addr st_value;
+ Elf32_Word st_size;
+ unsigned char st_info;
+ unsigned char st_other;
+ Elf32_Half st_shndx;
+} Elf32_Sym;
+
+/* Figure 4-19: Relocation Entries */
+
+typedef struct
+{
+ Elf32_Addr r_offset;
+ Elf32_Word r_info;
+} Elf32_Rel;
+
+typedef struct
+{
+ Elf32_Addr r_offset;
+ Elf32_Word r_info;
+ Elf32_Sword r_addend;
+} Elf32_Rela;
+
+/* Figure 5-1: Program Header */
+
+typedef struct
+{
+ Elf32_Word p_type;
+ Elf32_Off p_offset;
+ Elf32_Addr p_vaddr;
+ Elf32_Addr p_paddr;
+ Elf32_Word p_filesz;
+ Elf32_Word p_memsz;
+ Elf32_Word p_flags;
+ Elf32_Word p_align;
+} Elf32_Phdr;
+
+/* Figure 5-9: Dynamic Structure */
+
+typedef struct
+{
+ Elf32_Sword d_tag;
+ union
+ {
+ Elf32_Word d_val;
+ Elf32_Addr d_ptr;
+ } d_un;
+} Elf32_Dyn;
+
+//extern Elf32_Dyn _DYNAMIC[] ;
+
+#endif /* __INCLUDE_ELF32_H */
diff --git a/nuttx/include/net/if.h b/nuttx/include/net/if.h
index e64b58563..1ff8ebc38 100644
--- a/nuttx/include/net/if.h
+++ b/nuttx/include/net/if.h
@@ -52,6 +52,10 @@
#define IF_NAMESIZE 6 /* Newer naming standard */
#define IFHWADDRLEN 6
+#define IFF_RUNNING (1 << 0)
+#define IF_FLAG_IFUP (1 << 0)
+#define IF_FLAG_IFDOWN (2 << 0)
+
/*******************************************************************************************
* Public Type Definitions
*******************************************************************************************/
@@ -72,6 +76,7 @@ struct lifreq
struct sockaddr lifru_hwaddr; /* MAC address */
int lifru_count; /* Number of devices */
int lifru_mtu; /* MTU size */
+ uint8_t lifru_flags; /* Interface flags */
} lifr_ifru;
};
@@ -82,6 +87,7 @@ struct lifreq
#define lifr_hwaddr lifr_ifru.lifru_hwaddr /* MAC address */
#define lifr_mtu lifr_ifru.lifru_mtu /* MTU */
#define lifr_count lifr_ifru.lifru_count /* Number of devices */
+#define lifr_flags lifr_ifru.lifru_flags /* interface flags */
/* This is the older I/F request that should only be used with IPv4. However, since
* NuttX only supports IPv4 or 6 (not both), we can force the older structure to
@@ -101,6 +107,7 @@ struct ifreq
struct sockaddr ifru_hwaddr; /* MAC address */
int ifru_count; /* Number of devices */
int ifru_mtu; /* MTU size */
+ uint8_t ifru_flags; /* Interface flags */
} ifr_ifru;
};
@@ -111,6 +118,7 @@ struct ifreq
#define ifr_hwaddr ifr_ifru.ifru_hwaddr /* MAC address */
#define ifr_mtu ifr_ifru.ifru_mtu /* MTU */
#define ifr_count ifr_ifru.ifru_count /* Number of devices */
+#define ifr_flags ifr_ifru.ifru_flags /* interface flags */
#else /* CONFIG_NET_IPv6 */
@@ -123,6 +131,7 @@ struct ifreq
#define ifr_hwaddr lifr_ifru.lifru_hwaddr /* MAC address */
#define ifr_mtu lifr_ifru.lifru_mtu /* MTU */
#define ifr_count lifr_ifru.lifru_count /* Number of devices */
+#define ifr_flags lifr_ifru.lifru_flags /* interface flags */
#endif /* CONFIG_NET_IPv6 */
diff --git a/nuttx/include/nuttx/arch.h b/nuttx/include/nuttx/arch.h
index bf6be1ce0..8b4b10ade 100644
--- a/nuttx/include/nuttx/arch.h
+++ b/nuttx/include/nuttx/arch.h
@@ -46,6 +46,7 @@
#include <stdint.h>
#include <stdbool.h>
#include <sched.h>
+
#include <arch/arch.h>
/****************************************************************************
@@ -67,10 +68,8 @@ typedef CODE void (*sig_deliver_t)(FAR _TCB *tcb);
****************************************************************************/
#ifdef __cplusplus
-#define EXTERN extern "C"
-extern "C" {
-#else
-#define EXTERN extern
+extern "C"
+{
#endif
/****************************************************************************
@@ -98,7 +97,7 @@ extern "C" {
*
****************************************************************************/
-EXTERN void up_initialize(void);
+void up_initialize(void);
/****************************************************************************
* Name: up_idle
@@ -114,7 +113,7 @@ EXTERN void up_initialize(void);
*
****************************************************************************/
-EXTERN void up_idle(void);
+void up_idle(void);
/****************************************************************************
* Name: up_initial_state
@@ -130,7 +129,7 @@ EXTERN void up_idle(void);
*
****************************************************************************/
-EXTERN void up_initial_state(FAR _TCB *tcb);
+void up_initial_state(FAR _TCB *tcb);
/****************************************************************************
* Name: up_create_stack
@@ -155,7 +154,7 @@ EXTERN void up_initial_state(FAR _TCB *tcb);
****************************************************************************/
#ifndef CONFIG_CUSTOM_STACK
-EXTERN int up_create_stack(FAR _TCB *tcb, size_t stack_size);
+int up_create_stack(FAR _TCB *tcb, size_t stack_size);
#endif
/****************************************************************************
@@ -180,7 +179,7 @@ EXTERN int up_create_stack(FAR _TCB *tcb, size_t stack_size);
****************************************************************************/
#ifndef CONFIG_CUSTOM_STACK
-EXTERN int up_use_stack(FAR _TCB *tcb, FAR void *stack, size_t stack_size);
+int up_use_stack(FAR _TCB *tcb, FAR void *stack, size_t stack_size);
#endif
/****************************************************************************
@@ -193,7 +192,7 @@ EXTERN int up_use_stack(FAR _TCB *tcb, FAR void *stack, size_t stack_size);
****************************************************************************/
#ifndef CONFIG_CUSTOM_STACK
-EXTERN void up_release_stack(FAR _TCB *dtcb);
+void up_release_stack(FAR _TCB *dtcb);
#endif
/****************************************************************************
@@ -216,7 +215,7 @@ EXTERN void up_release_stack(FAR _TCB *dtcb);
*
****************************************************************************/
-EXTERN void up_unblock_task(FAR _TCB *tcb);
+void up_unblock_task(FAR _TCB *tcb);
/****************************************************************************
* Name: up_block_task
@@ -242,7 +241,7 @@ EXTERN void up_unblock_task(FAR _TCB *tcb);
*
****************************************************************************/
-EXTERN void up_block_task(FAR _TCB *tcb, tstate_t task_state);
+void up_block_task(FAR _TCB *tcb, tstate_t task_state);
/****************************************************************************
* Name: up_release_pending
@@ -261,7 +260,7 @@ EXTERN void up_block_task(FAR _TCB *tcb, tstate_t task_state);
*
****************************************************************************/
-EXTERN void up_release_pending(void);
+void up_release_pending(void);
/****************************************************************************
* Name: up_reprioritize_rtr
@@ -287,7 +286,7 @@ EXTERN void up_release_pending(void);
*
****************************************************************************/
-EXTERN void up_reprioritize_rtr(FAR _TCB *tcb, uint8_t priority);
+void up_reprioritize_rtr(FAR _TCB *tcb, uint8_t priority);
/****************************************************************************
* Name: _exit
@@ -349,7 +348,7 @@ EXTERN void up_reprioritize_rtr(FAR _TCB *tcb, uint8_t priority);
****************************************************************************/
#ifndef CONFIG_DISABLE_SIGNALS
-EXTERN void up_schedule_sigaction(FAR _TCB *tcb, sig_deliver_t sigdeliver);
+void up_schedule_sigaction(FAR _TCB *tcb, sig_deliver_t sigdeliver);
#endif
/****************************************************************************
@@ -363,7 +362,7 @@ EXTERN void up_schedule_sigaction(FAR _TCB *tcb, sig_deliver_t sigdeliver);
****************************************************************************/
#ifndef CONFIG_HEAP_BASE
-EXTERN void up_allocate_heap(FAR void **heap_start, size_t *heap_size);
+void up_allocate_heap(FAR void **heap_start, size_t *heap_size);
#endif
/****************************************************************************
@@ -383,6 +382,214 @@ EXTERN void up_allocate_heap(FAR void **heap_start, size_t *heap_size);
#endif
/****************************************************************************
+ * Address Environment Interfaces
+ *
+ * Low-level interfaces used in binfmt/ to instantiate tasks with address
+ * environments. These interfaces all operate on type task_addrenv_t which
+ * is an abstract representation of a task's address environment and must be
+ * defined in arch/arch.h if CONFIG_ADDRENV is defined.
+ *
+ * up_addrenv_create - Create an address environment
+ * up_addrenv_vaddr - Returns the virtual base address of the address
+ * environment
+ * up_addrenv_select - Instantiate an address environment
+ * up_addrenv_restore - Restore an address environment
+ * up_addrenv_destroy - Destroy an address environment.
+ * up_addrenv_assign - Assign an address environment to a TCB
+ *
+ * Higher-level interfaces used by the tasking logic. These interfaces are
+ * used by the functions in sched/ and all operate on the TCB which as been
+ * assigned an address environment by up_addrenv_assign().
+ *
+ * up_addrenv_share - Clone the address environment assigned to one TCB
+ * to another. This operation is done when a pthread
+ * is created that share's the same address
+ * environment.
+ * up_addrenv_release - Release the TCBs reference to an address
+ * environment when a task/thread exits.
+ *
+ ****************************************************************************/
+/****************************************************************************
+ * Name: up_addrenv_create
+ *
+ * Description:
+ * This function is called from the binary loader logic when a new
+ * task is created in order to instantiate an address environment for the
+ * task. up_addrenv_create is essentially the allocator of the physical
+ * memory for the new task.
+ *
+ * Input Parameters:
+ * envsize - The size (in bytes) of the address environment needed by the
+ * task.
+ * addrenv - The location to return the representation of the task address
+ * environment.
+ *
+ * Returned Value:
+ * Zero (OK) on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_ADDRENV
+int up_addrenv_create(size_t envsize, FAR task_addrenv_t *addrenv);
+#endif
+
+/****************************************************************************
+ * Name: up_addrenv_vaddr
+ *
+ * Description:
+ * Return the virtual address associated with the newly create address
+ * environment. This function is used by the binary loaders in order
+ * get an address that can be used to initialize the new task.
+ *
+ * Input Parameters:
+ * addrenv - The representation of the task address environment previously
+ * returned by up_addrenv_create.
+ * vaddr - The location to return the virtual address.
+ *
+ * Returned Value:
+ * Zero (OK) on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_ADDRENV
+int up_addrenv_vaddr(FAR task_addrenv_t addrenv, FAR void **vaddr);
+#endif
+
+/****************************************************************************
+ * Name: up_addrenv_select
+ *
+ * Description:
+ * After an address environment has been established for a task (via
+ * up_addrenv_create(). This function may be called to to instantiate
+ * that address environment in the virtual address space. this might be
+ * necessary, for example, to load the code for the task from a file or
+ * to access address environment private data.
+ *
+ * Input Parameters:
+ * addrenv - The representation of the task address environment previously
+ * returned by up_addrenv_create.
+ * oldenv
+ * The address environment that was in place before up_addrenv_select().
+ * This may be used with up_addrenv_restore() to restore the original
+ * address environment that was in place before up_addrenv_select() was
+ * called. Note that this may be a task agnostic, hardware
+ * representation that is different from task_addrenv_t.
+ *
+ * Returned Value:
+ * Zero (OK) on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_ADDRENV
+int up_addrenv_select(task_addrenv_t addrenv, hw_addrenv_t *oldenv);
+#endif
+
+/****************************************************************************
+ * Name: up_addrenv_restore
+ *
+ * Description:
+ * After an address environment has been temporarilty instantiated by
+ * up_addrenv_select, this function may be called to to restore the
+ * original address environment.
+ *
+ * Input Parameters:
+ * oldenv - The hardware representation of the address environment
+ * previously returned by up_addrenv_select.
+ *
+ * Returned Value:
+ * Zero (OK) on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_ADDRENV
+int up_addrenv_restore(hw_addrenv_t oldenv);
+#endif
+
+/****************************************************************************
+ * Name: up_addrenv_destroy
+ *
+ * Description:
+ * Called from the binary loader loader during error handling to destroy
+ * the address environment previously created by up_addrenv_create().
+ *
+ * Input Parameters:
+ * addrenv - The representation of the task address environment previously
+ * returned by up_addrenv_create.
+ *
+ * Returned Value:
+ * Zero (OK) on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_ADDRENV
+int up_addrenv_destroy(task_addrenv_t addrenv);
+#endif
+
+/****************************************************************************
+ * Name: up_addrenv_assign
+ *
+ * Description:
+ * Assign an address environment to a TCB.
+ *
+ * Input Parameters:
+ * addrenv - The representation of the task address environment previously
+ * returned by up_addrenv_create.
+ * tcb - The TCB of the task to receive the address environment.
+ *
+ * Returned Value:
+ * Zero (OK) on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_ADDRENV
+int up_addrenv_assign(task_addrenv_t addrenv, FAR _TCB *tcb);
+#endif
+
+/****************************************************************************
+ * Name: up_addrenv_share
+ *
+ * Description:
+ * This function is called from the core scheduler logic when a thread
+ * is created that needs to share the address ennvironment of its parent
+ * task. In this case, the parent's address environment needs to be
+ * "cloned" for the child.
+ *
+ * Input Parameters:
+ * ptcb - The TCB of the parent task that has the address environment.
+ * ctcb - The TCB of the child thread needing the address environment.
+ *
+ * Returned Value:
+ * Zero (OK) on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_ADDRENV
+int up_addrenv_share(FAR const _TCB *ptcb, FAR _TCB *ctcb);
+#endif
+
+/****************************************************************************
+ * Name: up_addrenv_release
+ *
+ * Description:
+ * This function is called when a task or thread exits in order to release
+ * its reference to an address environment. When there are no further
+ * references to an address environment, that address environment should
+ * be destroyed.
+ *
+ * Input Parameters:
+ * tcb - The TCB of the task or thread whose the address environment will
+ * be released.
+ *
+ * Returned Value:
+ * Zero (OK) on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_ADDRENV
+int up_addrenv_release(FAR _TCB *tcb);
+#endif
+
+/****************************************************************************
* Name: up_interrupt_context
*
* Description:
@@ -391,7 +598,7 @@ EXTERN void up_allocate_heap(FAR void **heap_start, size_t *heap_size);
*
****************************************************************************/
-EXTERN bool up_interrupt_context(void);
+bool up_interrupt_context(void);
/****************************************************************************
* Name: up_enable_irq
@@ -413,7 +620,7 @@ EXTERN bool up_interrupt_context(void);
****************************************************************************/
#ifndef CONFIG_ARCH_NOINTC
-EXTERN void up_enable_irq(int irq);
+void up_enable_irq(int irq);
#endif
/****************************************************************************
@@ -431,7 +638,7 @@ EXTERN void up_enable_irq(int irq);
****************************************************************************/
#ifndef CONFIG_ARCH_NOINTC
-EXTERN void up_disable_irq(int irq);
+void up_disable_irq(int irq);
#endif
/****************************************************************************
@@ -446,7 +653,7 @@ EXTERN void up_disable_irq(int irq);
****************************************************************************/
#ifdef CONFIG_ARCH_IRQPRIO
-EXTERN int up_prioritize_irq(int irq, int priority);
+int up_prioritize_irq(int irq, int priority);
#endif
/****************************************************************************
@@ -483,7 +690,7 @@ EXTERN int up_prioritize_irq(int irq, int priority);
****************************************************************************/
#ifdef CONFIG_ARCH_ROMGETC
-EXTERN char up_romgetc(FAR const char *ptr);
+char up_romgetc(FAR const char *ptr);
#else
# define up_romgetc(ptr) (*ptr)
#endif
@@ -497,8 +704,8 @@ EXTERN char up_romgetc(FAR const char *ptr);
*
***************************************************************************/
-EXTERN void up_mdelay(unsigned int milliseconds);
-EXTERN void up_udelay(useconds_t microseconds);
+void up_mdelay(unsigned int milliseconds);
+void up_udelay(useconds_t microseconds);
/****************************************************************************
* Name: up_cxxinitialize
@@ -517,7 +724,7 @@ EXTERN void up_udelay(useconds_t microseconds);
***************************************************************************/
#if defined(CONFIG_HAVE_CXX) && defined(CONFIG_HAVE_CXXINITIALIZE)
-EXTERN void up_cxxinitialize(void);
+void up_cxxinitialize(void);
#endif
/****************************************************************************
@@ -537,7 +744,7 @@ EXTERN void up_cxxinitialize(void);
*
****************************************************************************/
-EXTERN void sched_process_timer(void);
+void sched_process_timer(void);
/****************************************************************************
* Name: irq_dispatch
@@ -549,7 +756,7 @@ EXTERN void sched_process_timer(void);
*
***************************************************************************/
-EXTERN void irq_dispatch(int irq, FAR void *context);
+void irq_dispatch(int irq, FAR void *context);
/****************************************************************************
* Board-specific button interfaces exported by the board-specific logic
@@ -571,7 +778,7 @@ EXTERN void irq_dispatch(int irq, FAR void *context);
****************************************************************************/
#ifdef CONFIG_ARCH_BUTTONS
-EXTERN void up_buttoninit(void);
+void up_buttoninit(void);
#endif
/****************************************************************************
@@ -592,7 +799,7 @@ EXTERN void up_buttoninit(void);
****************************************************************************/
#ifdef CONFIG_ARCH_BUTTONS
-EXTERN uint8_t up_buttons(void);
+uint8_t up_buttons(void);
#endif
/****************************************************************************
@@ -613,7 +820,29 @@ EXTERN uint8_t up_buttons(void);
****************************************************************************/
#ifdef CONFIG_ARCH_IRQBUTTONS
-EXTERN xcpt_t up_irqbutton(int id, xcpt_t irqhandler);
+xcpt_t up_irqbutton(int id, xcpt_t irqhandler);
+#endif
+
+/************************************************************************************
+ * Relay control functions
+ *
+ * Description:
+ * Non-standard functions for relay control.
+ *
+ ************************************************************************************/
+
+#ifdef CONFIG_ARCH_RELAYS
+void up_relaysinit(void);
+void relays_setstat(int relays, bool stat);
+bool relays_getstat(int relays);
+void relays_setstats(uint32_t relays_stat);
+uint32_t relays_getstats(void);
+void relays_onoff(int relays, uint32_t mdelay);
+void relays_onoffs(uint32_t relays_stat, uint32_t mdelay);
+void relays_resetmode(int relays);
+void relays_powermode(int relays);
+void relays_resetmodes(uint32_t relays_stat);
+void relays_powermodes(uint32_t relays_stat);
#endif
/****************************************************************************
@@ -628,9 +857,8 @@ EXTERN xcpt_t up_irqbutton(int id, xcpt_t irqhandler);
*
****************************************************************************/
-EXTERN int up_putc(int ch);
+int up_putc(int ch);
-#undef EXTERN
#ifdef __cplusplus
}
#endif
diff --git a/nuttx/include/nuttx/binfmt.h b/nuttx/include/nuttx/binfmt/binfmt.h
index 70beda393..6df5190d2 100644
--- a/nuttx/include/nuttx/binfmt.h
+++ b/nuttx/include/nuttx/binfmt/binfmt.h
@@ -1,7 +1,7 @@
/****************************************************************************
- * include/nuttx/binfmt.h
+ * include/nuttx/binfmt/binfmt.h
*
- * Copyright (C) 2009 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2009, 2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -33,34 +33,58 @@
*
****************************************************************************/
-#ifndef __INCLUDE_NUTTX_BINFMT_H
-#define __INCLUDE_NUTTX_BINFMT_H
+#ifndef __INCLUDE_NUTTX_BINFMT_BINFMT_H
+#define __INCLUDE_NUTTX_BINFMT_BINFMT_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
+
#include <sys/types.h>
#include <nxflat.h>
+
+#include <nuttx/arch.h>
#include <nuttx/sched.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
+#define BINFMT_NALLOC 3
+
/****************************************************************************
* Public Types
****************************************************************************/
+/* EXEPATH_HANDLE is an opaque handle used to traverse the absolute paths
+ * assigned to the PATH environment variable.
+ */
+
+#if !defined(CONFIG_BINFMT_DISABLE) && defined(CONFIG_BINFMT_EXEPATH)
+typedef FAR void *EXEPATH_HANDLE;
+#endif
+
+/* The type of one C++ constructor or destructor */
+
+typedef FAR void (*binfmt_ctor_t)(void);
+typedef FAR void (*binfmt_dtor_t)(void);
-/* This describes the file to be loaded */
+/* This describes the file to be loaded.
+ *
+ * NOTE 1: The 'filename' must be the full, absolute path to the file to be
+ * executed unless CONFIG_BINFMT_EXEPATH is defined. In that case,
+ * 'filename' may be a relative path; a set of candidate absolute paths
+ * will be generated using the PATH environment variable and load_module()
+ * will attempt to load each file that is found at those absolute paths.
+ */
struct symtab_s;
struct binary_s
{
/* Information provided to the loader to load and bind a module */
- FAR const char *filename; /* Full path to the binary to be loaded */
+ FAR const char *filename; /* Full path to the binary to be loaded (See NOTE 1 above) */
FAR const char **argv; /* Argument list */
FAR const struct symtab_s *exports; /* Table of exported symbols */
int nexports; /* The number of symbols in exports[] */
@@ -70,9 +94,29 @@ struct binary_s
*/
main_t entrypt; /* Entry point into a program module */
- FAR void *ispace; /* Memory-mapped, I-space (.text) address */
- FAR struct dspace_s *dspace; /* Address of the allocated .data/.bss space */
- size_t isize; /* Size of the I-space region (needed for munmap) */
+ FAR void *mapped; /* Memory-mapped, address space */
+ FAR void *alloc[BINFMT_NALLOC]; /* Allocated address spaces */
+
+ /* Constructors/destructors */
+
+#ifdef CONFIG_BINFMT_CONSTRUCTORS
+ FAR binfmt_ctor_t *ctors; /* Pointer to a list of constructors */
+ FAR binfmt_dtor_t *dtors; /* Pointer to a list of destructors */
+ uint16_t nctors; /* Number of constructors in the list */
+ uint16_t ndtors; /* Number of destructors in the list */
+#endif
+
+ /* Address environment.
+ *
+ * addrenv - This is the handle created by up_addrenv_create() that can be
+ * used to manage the tasks address space.
+ */
+
+#ifdef CONFIG_ADDRENV
+ task_addrenv_t addrenv; /* Task address environment */
+#endif
+
+ size_t mapsize; /* Size of the mapped address region (needed for munmap) */
size_t stacksize; /* Size of the stack in bytes (unallocated) */
};
@@ -88,12 +132,9 @@ struct binfmt_s
* Public Data
****************************************************************************/
-#undef EXTERN
#if defined(__cplusplus)
-#define EXTERN extern "C"
-extern "C" {
-#else
-#define EXTERN extern
+extern "C"
+{
#endif
/****************************************************************************
@@ -113,7 +154,7 @@ extern "C" {
*
****************************************************************************/
-EXTERN int register_binfmt(FAR struct binfmt_s *binfmt);
+int register_binfmt(FAR struct binfmt_s *binfmt);
/****************************************************************************
* Name: unregister_binfmt
@@ -128,7 +169,7 @@ EXTERN int register_binfmt(FAR struct binfmt_s *binfmt);
*
****************************************************************************/
-EXTERN int unregister_binfmt(FAR struct binfmt_s *binfmt);
+int unregister_binfmt(FAR struct binfmt_s *binfmt);
/****************************************************************************
* Name: load_module
@@ -144,14 +185,19 @@ EXTERN int unregister_binfmt(FAR struct binfmt_s *binfmt);
*
****************************************************************************/
-EXTERN int load_module(FAR struct binary_s *bin);
+int load_module(FAR struct binary_s *bin);
/****************************************************************************
* Name: unload_module
*
* Description:
* Unload a (non-executing) module from memory. If the module has
- * been started (via exec_module), calling this will be fatal.
+ * been started (via exec_module) and has not exited, calling this will
+ * be fatal.
+ *
+ * However, this function must be called after the module exist. How
+ * this is done is up to your logic. Perhaps you register it to be
+ * called by on_exit()?
*
* Returned Value:
* This is a NuttX internal function so it follows the convention that
@@ -160,7 +206,7 @@ EXTERN int load_module(FAR struct binary_s *bin);
*
****************************************************************************/
-EXTERN int unload_module(FAR const struct binary_s *bin);
+int unload_module(FAR const struct binary_s *bin);
/****************************************************************************
* Name: exec_module
@@ -175,7 +221,7 @@ EXTERN int unload_module(FAR const struct binary_s *bin);
*
****************************************************************************/
-EXTERN int exec_module(FAR const struct binary_s *bin, int priority);
+int exec_module(FAR const struct binary_s *bin, int priority);
/****************************************************************************
* Name: exec
@@ -197,13 +243,96 @@ EXTERN int exec_module(FAR const struct binary_s *bin, int priority);
*
****************************************************************************/
-EXTERN int exec(FAR const char *filename, FAR const char **argv,
- FAR const struct symtab_s *exports, int nexports);
+int exec(FAR const char *filename, FAR const char **argv,
+ FAR const struct symtab_s *exports, int nexports);
+
+/****************************************************************************
+ * Name: exepath_init
+ *
+ * Description:
+ * Initialize for the traversal of each value in the PATH variable. The
+ * usage is sequence is as follows:
+ *
+ * 1) Call exepath_init() to initialize for the traversal. exepath_init()
+ * will return an opaque handle that can then be provided to
+ * exepath_next() and exepath_release().
+ * 2) Call exepath_next() repeatedly to examine every file that lies
+ * in the directories of the PATH variable
+ * 3) Call exepath_release() to free resources set aside by exepath_init().
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * On success, exepath_init() return a non-NULL, opaque handle that may
+ * subsequently be used in calls to exepath_next() and exepath_release().
+ * On error, a NULL handle value will be returned. The most likely cause
+ * of an error would be that the there is no value associated with the
+ * PATH variable.
+ *
+ ****************************************************************************/
+
+#if !defined(CONFIG_BINFMT_DISABLE) && defined(CONFIG_BINFMT_EXEPATH)
+EXEPATH_HANDLE exepath_init(void);
+#endif
+
+/****************************************************************************
+ * Name: exepath_next
+ *
+ * Description:
+ * Traverse all possible values in the PATH variable in attempt to find
+ * the full path to an executable file when only a relative path is
+ * provided.
+ *
+ * Input Parameters:
+ * handle - The handle value returned by exepath_init
+ * relpath - The relative path to the file to be found.
+ *
+ * Returned Value:
+ * On success, a non-NULL pointer to a null-terminated string is provided.
+ * This is the full path to a file that exists in the file system. This
+ * function will verify that the file exists (but will not verify that it
+ * is marked executable).
+ *
+ * NOTE: The string pointer return in the success case points to allocated
+ * memory. This memory must be freed by the called by calling kfree().
+ *
+ * NULL is returned if no path is found to any file with the provided
+ * 'relpath' from any absolute path in the PATH variable. In this case,
+ * there is no point in calling exepath_next() further; exepath_release()
+ * must be called to release resources set aside by expath_init().
+ *
+ ****************************************************************************/
+
+#if !defined(CONFIG_BINFMT_DISABLE) && defined(CONFIG_BINFMT_EXEPATH)
+FAR char *exepath_next(EXEPATH_HANDLE handle, FAR const char *relpath);
+#endif
+
+/****************************************************************************
+ * Name: exepath_release
+ *
+ * Description:
+ * Release all resources set aside by exepath_init() when the handle value
+ * was created. The handle value is invalid on return from this function.
+ * Attempts to all exepath_next() or exepath_release() with such a 'stale'
+ * handle will result in undefined (i.e., not good) behavior.
+ *
+ * Input Parameters:
+ * handle - The handle value returned by exepath_init
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+#if !defined(CONFIG_BINFMT_DISABLE) && defined(CONFIG_BINFMT_EXEPATH)
+void exepath_release(EXEPATH_HANDLE handle);
+#endif
#undef EXTERN
#if defined(__cplusplus)
}
#endif
-#endif /* __INCLUDE_NUTTX_BINFMT_H */
+#endif /* __INCLUDE_NUTTX_BINFMT_BINFMT_H */
diff --git a/nuttx/include/nuttx/binfmt/elf.h b/nuttx/include/nuttx/binfmt/elf.h
new file mode 100644
index 000000000..6b6851934
--- /dev/null
+++ b/nuttx/include/nuttx/binfmt/elf.h
@@ -0,0 +1,340 @@
+/****************************************************************************
+ * include/nuttx/binfmt/elf.h
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_BINFMT_ELF_H
+#define __INCLUDE_NUTTX_BINFMT_ELF_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+
+#include <stdint.h>
+#include <stdbool.h>
+#include <elf32.h>
+
+#include <nuttx/binfmt/binfmt.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+/* Configuration ************************************************************/
+
+#ifndef CONFIG_ELF_ALIGN_LOG2
+# define CONFIG_ELF_ALIGN_LOG2 2
+#endif
+
+#ifndef CONFIG_ELF_STACKSIZE
+# define CONFIG_ELF_STACKSIZE 2048
+#endif
+
+#ifndef CONFIG_ELF_BUFFERSIZE
+# define CONFIG_ELF_BUFFERSIZE 128
+#endif
+
+#ifndef CONFIG_ELF_BUFFERINCR
+# define CONFIG_ELF_BUFFERINCR 32
+#endif
+
+/* Allocation array size and indices */
+
+#define LIBELF_ELF_ALLOC 0
+#ifdef CONFIG_BINFMT_CONSTRUCTORS
+# define LIBELF_CTORS_ALLOC 1
+# define LIBELF_CTPRS_ALLOC 2
+# define LIBELF_NALLOC 3
+#else
+# define LIBELF_NALLOC 1
+#endif
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* This struct provides a desciption of the currently loaded instantiation
+ * of an ELF binary.
+ */
+
+struct elf_loadinfo_s
+{
+ /* elfalloc is the base address of the memory that is allocated to hold the
+ * ELF program image.
+ *
+ * If CONFIG_ADDRENV=n, elfalloc will be allocated using kmalloc() (or
+ * kzalloc()). If CONFIG_ADDRENV-y, then elfalloc will be allocated using
+ * up_addrenv_create(). In either case, there will be a unique instance
+ * of elfalloc (and stack) for each instance of a process.
+ *
+ * The alloc[] array in struct binary_s will hold memory that persists after
+ * the ELF module has been loaded.
+ */
+
+ uintptr_t elfalloc; /* Memory allocated when ELF file was loaded */
+ size_t elfsize; /* Size of the ELF memory allocation */
+ off_t filelen; /* Length of the entire ELF file */
+ Elf32_Ehdr ehdr; /* Buffered ELF file header */
+ FAR Elf32_Shdr *shdr; /* Buffered ELF section headers */
+ uint8_t *iobuffer; /* File I/O buffer */
+
+ /* Constructors and destructors */
+
+#ifdef CONFIG_BINFMT_CONSTRUCTORS
+ FAR void *ctoralloc; /* Memory allocated for ctors */
+ FAR void *dtoralloc; /* Memory allocated dtors */
+ FAR binfmt_ctor_t *ctors; /* Pointer to a list of constructors */
+ FAR binfmt_dtor_t *dtors; /* Pointer to a list of destructors */
+ uint16_t nctors; /* Number of constructors */
+ uint16_t ndtors; /* Number of destructors */
+#endif
+
+ /* Address environment.
+ *
+ * addrenv - This is the handle created by up_addrenv_create() that can be
+ * used to manage the tasks address space.
+ * oldenv - This is a value returned by up_addrenv_select() that must be
+ * used to restore the current hardware address environment.
+ */
+
+#ifdef CONFIG_ADDRENV
+ task_addrenv_t addrenv; /* Task address environment */
+ hw_addrenv_t oldenv; /* Saved hardware address environment */
+#endif
+
+ uint16_t symtabidx; /* Symbol table section index */
+ uint16_t strtabidx; /* String table section index */
+ uint16_t buflen; /* size of iobuffer[] */
+ int filfd; /* Descriptor for the file being loaded */
+};
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+#undef EXTERN
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+extern "C" {
+#else
+#define EXTERN extern
+#endif
+
+/****************************************************************************
+ * These are APIs exported by libelf (but are used only by the binfmt logic):
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: elf_init
+ *
+ * Description:
+ * This function is called to configure the library to process an ELF
+ * program binary.
+ *
+ * Returned Value:
+ * 0 (OK) is returned on success and a negated errno is returned on
+ * failure.
+ *
+ ****************************************************************************/
+
+EXTERN int elf_init(FAR const char *filename,
+ FAR struct elf_loadinfo_s *loadinfo);
+
+/****************************************************************************
+ * Name: elf_uninit
+ *
+ * Description:
+ * Releases any resources committed by elf_init(). This essentially
+ * undoes the actions of elf_init.
+ *
+ * Returned Value:
+ * 0 (OK) is returned on success and a negated errno is returned on
+ * failure.
+ *
+ ****************************************************************************/
+
+EXTERN int elf_uninit(FAR struct elf_loadinfo_s *loadinfo);
+
+/****************************************************************************
+ * Name: elf_load
+ *
+ * Description:
+ * Loads the binary into memory, allocating memory, performing relocations
+ * and inializing the data and bss segments.
+ *
+ * Returned Value:
+ * 0 (OK) is returned on success and a negated errno is returned on
+ * failure.
+ *
+ ****************************************************************************/
+
+EXTERN int elf_load(FAR struct elf_loadinfo_s *loadinfo);
+
+/****************************************************************************
+ * Name: elf_bind
+ *
+ * Description:
+ * Bind the imported symbol names in the loaded module described by
+ * 'loadinfo' using the exported symbol values provided by 'symtab'.
+ *
+ * Returned Value:
+ * 0 (OK) is returned on success and a negated errno is returned on
+ * failure.
+ *
+ ****************************************************************************/
+
+struct symtab_s;
+EXTERN int elf_bind(FAR struct elf_loadinfo_s *loadinfo,
+ FAR const struct symtab_s *exports, int nexports);
+
+/****************************************************************************
+ * Name: elf_unload
+ *
+ * Description:
+ * This function unloads the object from memory. This essentially undoes
+ * the actions of elf_load. It is called only under certain error
+ * conditions after the the module has been loaded but not yet started.
+ *
+ * Returned Value:
+ * 0 (OK) is returned on success and a negated errno is returned on
+ * failure.
+ *
+ ****************************************************************************/
+
+EXTERN int elf_unload(struct elf_loadinfo_s *loadinfo);
+
+/****************************************************************************
+ * These are APIs used outside of binfmt by NuttX:
+ ****************************************************************************/
+/****************************************************************************
+ * Name: elf_initialize
+ *
+ * Description:
+ * ELF support is built unconditionally. However, it order to
+ * use this binary format, this function must be called during system
+ * format in order to register the ELF binary format.
+ *
+ * Returned Value:
+ * This is a NuttX internal function so it follows the convention that
+ * 0 (OK) is returned on success and a negated errno is returned on
+ * failure.
+ *
+ ****************************************************************************/
+
+EXTERN int elf_initialize(void);
+
+/****************************************************************************
+ * Name: elf_uninitialize
+ *
+ * Description:
+ * Unregister the ELF binary loader
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+EXTERN void elf_uninitialize(void);
+
+/****************************************************************************
+ * These are APIs must be provided by architecture-specific logic:
+ ****************************************************************************/
+/****************************************************************************
+ * Name: arch_checkarch
+ *
+ * Description:
+ * Given the ELF header in 'hdr', verify that the ELF file is appropriate
+ * for the current, configured architecture. Every architecture that uses
+ * the ELF loader must provide this function.
+ *
+ * Input Parameters:
+ * hdr - The ELF header read from the ELF file.
+ *
+ * Returned Value:
+ * True if the architecture supports this ELF file.
+ *
+ ****************************************************************************/
+
+EXTERN bool arch_checkarch(FAR const Elf32_Ehdr *hdr);
+
+/****************************************************************************
+ * Name: arch_relocate and arch_relocateadd
+ *
+ * Description:
+ * Perform on architecture-specific ELF relocation. Every architecture
+ * that uses the ELF loader must provide this function.
+ *
+ * Input Parameters:
+ * rel - The relocation type
+ * sym - The ELF symbol structure containing the fully resolved value.
+ * addr - The address that requires the relocation.
+ *
+ * Returned Value:
+ * Zero (OK) if the relocation was successful. Otherwise, a negated errno
+ * value indicating the cause of the relocation failure.
+ *
+ ****************************************************************************/
+
+EXTERN int arch_relocate(FAR const Elf32_Rel *rel, FAR const Elf32_Sym *sym,
+ uintptr_t addr);
+EXTERN int arch_relocateadd(FAR const Elf32_Rela *rel,
+ FAR const Elf32_Sym *sym, uintptr_t addr);
+
+/****************************************************************************
+ * Name: arch_flushicache
+ *
+ * Description:
+ * Flush the instruction cache.
+ *
+ * Input Parameters:
+ * addr - Start address to flush
+ * len - Number of bytes to flush
+ *
+ * Returned Value:
+ * True if the architecture supports this ELF file.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_ELF_ICACHE
+EXTERN bool arch_flushicache(FAR void *addr, size_t len);
+#endif
+
+#undef EXTERN
+#if defined(__cplusplus)
+}
+#endif
+
+#endif /* __INCLUDE_NUTTX_BINFMT_ELF_H */
diff --git a/nuttx/include/nuttx/nxflat.h b/nuttx/include/nuttx/binfmt/nxflat.h
index b6501522e..db396771b 100644
--- a/nuttx/include/nuttx/nxflat.h
+++ b/nuttx/include/nuttx/binfmt/nxflat.h
@@ -1,7 +1,7 @@
/****************************************************************************
- * include/nuttx/nxflat.h
+ * include/nuttx/binfmt/nxflat.h
*
- * Copyright (C) 2009 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2009, 2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -33,8 +33,8 @@
*
****************************************************************************/
-#ifndef __INCLUDE_NUTTX_NXFLAT_H
-#define __INCLUDE_NUTTX_NXFLAT_H
+#ifndef __INCLUDE_NUTTX_BINFMT_NXFLAT_H
+#define __INCLUDE_NUTTX_BINFMT_NXFLAT_H
/****************************************************************************
* Included Files
@@ -44,7 +44,9 @@
#include <stdint.h>
#include <nxflat.h>
+
#include <nuttx/sched.h>
+#include <nuttx/arch.h>
/****************************************************************************
* Pre-processor Definitions
@@ -61,17 +63,24 @@
struct nxflat_loadinfo_s
{
/* Instruction Space (ISpace): This region contains the nxflat file header
- * plus everything from the text section. Ideally, will have only one mmap'ed
- * text section instance in the system for each module.
+ * plus everything from the text section.
+ *
+ * The ISpace region is allocated using mmap() and, thus, can be shared by
+ * multiple tasks. Ideally, will have only one mmap'ed text section
+ * instance in the system for each module.
*/
- uint32_t ispace; /* Address where hdr/text is loaded */
+ uintptr_t ispace; /* Address where hdr/text is loaded */
uint32_t entryoffs; /* Offset from ispace to entry point */
uint32_t isize; /* Size of ispace. */
- /* Data Space (DSpace): This region contains all information that in referenced
- * as data (other than the stack which is separately allocated). There will be
- * a unique instance of DSpace (and stack) for each instance of a process.
+ /* Data Space (DSpace): This region contains all information that is
+ * referenced as data (other than the stack which is separately allocated).
+ *
+ * If CONFIG_ADDRENV=n, DSpace will be allocated using kmalloc() (or
+ * kzalloc()). If CONFIG_ADDRENV-y, then DSpace will be allocated using
+ * up_addrenv_create(). In either case, there will be a unique instance
+ * of DSpace (and stack) for each instance of a process.
*/
struct dspace_s *dspace; /* Allocated D-Space (data/bss/etc) */
@@ -85,6 +94,19 @@ struct nxflat_loadinfo_s
uint32_t relocstart; /* Start of array of struct flat_reloc */
uint16_t reloccount; /* Number of elements in reloc array */
+ /* Address environment.
+ *
+ * addrenv - This is the handle created by up_addrenv_create() that can be
+ * used to manage the tasks address space.
+ * oldenv - This is a value returned by up_addrenv_select() that must be
+ * used to restore the current hardware address environment.
+ */
+
+#ifdef CONFIG_ADDRENV
+ task_addrenv_t addrenv; /* Task address environment */
+ hw_addrenv_t oldenv; /* Saved hardware address environment */
+#endif
+
/* File descriptors */
int filfd; /* Descriptor for the file being loaded */
@@ -110,22 +132,22 @@ extern "C" {
* These are APIs exported by libnxflat (and may be used outside of NuttX):
****************************************************************************/
-/***********************************************************************
+/****************************************************************************
* Name: nxflat_verifyheader
*
* Description:
- * Given the header from a possible NXFLAT executable, verify that it
- * is an NXFLAT executable.
+ * Given the header from a possible NXFLAT executable, verify that it is
+ * an NXFLAT executable.
*
* Returned Value:
* 0 (OK) is returned on success and a negated errno is returned on
* failure.
*
- ***********************************************************************/
+ ****************************************************************************/
EXTERN int nxflat_verifyheader(const struct nxflat_hdr_s *header);
-/***********************************************************************
+/****************************************************************************
* Name: nxflat_init
*
* Description:
@@ -136,12 +158,12 @@ EXTERN int nxflat_verifyheader(const struct nxflat_hdr_s *header);
* 0 (OK) is returned on success and a negated errno is returned on
* failure.
*
- ***********************************************************************/
+ ****************************************************************************/
EXTERN int nxflat_init(const char *filename,
struct nxflat_loadinfo_s *loadinfo);
-/***********************************************************************
+/****************************************************************************
* Name: nxflat_uninit
*
* Description:
@@ -152,11 +174,11 @@ EXTERN int nxflat_init(const char *filename,
* 0 (OK) is returned on success and a negated errno is returned on
* failure.
*
- ***********************************************************************/
+ ****************************************************************************/
EXTERN int nxflat_uninit(struct nxflat_loadinfo_s *loadinfo);
-/***********************************************************************
+/****************************************************************************
* Name: nxflat_load
*
* Description:
@@ -170,11 +192,11 @@ EXTERN int nxflat_uninit(struct nxflat_loadinfo_s *loadinfo);
* 0 (OK) is returned on success and a negated errno is returned on
* failure.
*
- ***********************************************************************/
+ ****************************************************************************/
EXTERN int nxflat_load(struct nxflat_loadinfo_s *loadinfo);
-/***********************************************************************
+/****************************************************************************
* Name: nxflat_read
*
* Description:
@@ -184,12 +206,12 @@ EXTERN int nxflat_load(struct nxflat_loadinfo_s *loadinfo);
* 0 (OK) is returned on success and a negated errno is returned on
* failure.
*
- ***********************************************************************/
+ ****************************************************************************/
EXTERN int nxflat_read(struct nxflat_loadinfo_s *loadinfo, char *buffer,
int readsize, int offset);
-/***********************************************************************
+/****************************************************************************
* Name: nxflat_bind
*
* Description:
@@ -202,31 +224,32 @@ EXTERN int nxflat_read(struct nxflat_loadinfo_s *loadinfo, char *buffer,
* 0 (OK) is returned on success and a negated errno is returned on
* failure.
*
- ***********************************************************************/
+ ****************************************************************************/
struct symtab_s;
EXTERN int nxflat_bind(FAR struct nxflat_loadinfo_s *loadinfo,
FAR const struct symtab_s *exports, int nexports);
-/***********************************************************************
+/****************************************************************************
* Name: nxflat_unload
*
* Description:
- * This function unloads the object from memory. This essentially
- * undoes the actions of nxflat_load.
+ * This function unloads the object from memory. This essentially undoes
+ * the actions of nxflat_load. It is called only under certain error
+ * conditions after the the module has been loaded but not yet started.
*
* Returned Value:
* 0 (OK) is returned on success and a negated errno is returned on
* failure.
*
- ***********************************************************************/
+ ****************************************************************************/
EXTERN int nxflat_unload(struct nxflat_loadinfo_s *loadinfo);
/****************************************************************************
* These are APIs used internally only by NuttX:
****************************************************************************/
-/***********************************************************************
+/****************************************************************************
* Name: nxflat_initialize
*
* Description:
@@ -239,7 +262,7 @@ EXTERN int nxflat_unload(struct nxflat_loadinfo_s *loadinfo);
* 0 (OK) is returned on success and a negated errno is returned on
* failure.
*
- ***********************************************************************/
+ ****************************************************************************/
EXTERN int nxflat_initialize(void);
@@ -261,4 +284,4 @@ EXTERN void nxflat_uninitialize(void);
}
#endif
-#endif /* __INCLUDE_NUTTX_NXFLAT_H */
+#endif /* __INCLUDE_NUTTX_BINFMT_NXFLAT_H */
diff --git a/nuttx/include/nuttx/symtab.h b/nuttx/include/nuttx/binfmt/symtab.h
index b302ab20a..346c6099f 100644
--- a/nuttx/include/nuttx/symtab.h
+++ b/nuttx/include/nuttx/binfmt/symtab.h
@@ -1,5 +1,5 @@
/****************************************************************************
- * include/nuttx/symtab.h
+ * include/nuttx/binfmt/symtab.h
*
* Copyright (C) 2009 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
@@ -33,8 +33,8 @@
*
****************************************************************************/
-#ifndef __INCLUDE_NUTTX_SYMTAB_H
-#define __INCLUDE_NUTTX_SYMTAB_H
+#ifndef __INCLUDE_NUTTX_BINFMT_SYMTAB_H
+#define __INCLUDE_NUTTX_BINFMT_SYMTAB_H
/****************************************************************************
* Included Files
@@ -54,7 +54,7 @@
* is a fixed size array of struct symtab_s. The information is intentionally
* minimal and supports only:
*
- * 1. Function points as sym_values. Of other kinds of values need to be
+ * 1. Function pointers as sym_values. Of other kinds of values need to be
* supported, then typing information would also need to be included in
* the structure.
*
@@ -159,5 +159,5 @@ symtab_findorderedbyvalue(FAR const struct symtab_s *symtab,
}
#endif
-#endif /* __INCLUDE_NUTTX_SYMTAB_H */
+#endif /* __INCLUDE_NUTTX_BINFMT_SYMTAB_H */
diff --git a/nuttx/include/nuttx/compiler.h b/nuttx/include/nuttx/compiler.h
index d74fcbea0..6ad51ad0f 100644
--- a/nuttx/include/nuttx/compiler.h
+++ b/nuttx/include/nuttx/compiler.h
@@ -87,11 +87,16 @@
# define packed_struct __attribute__ ((packed))
-/* GCC does not support the reentrant or naked attributes */
+/* GCC does not support the reentrant attribute */
# define reentrant_function
-# define naked_function
+/* The naked attribute informs GCC that the programmer will take care of
+ * the function prolog and epilog.
+ */
+
+# define naked_function __attribute__ ((naked,no_instrument_function))
+
/* The inline_function attribute informs GCC that the function should always
* be inlined, regardless of the level of optimization. The noinline_function
* indicates that the function should never be inlined.
@@ -191,8 +196,10 @@
/* GCC supports both types double and long long */
-# define CONFIG_HAVE_DOUBLE 1
# define CONFIG_HAVE_LONG_LONG 1
+# define CONFIG_HAVE_FLOAT 1
+# define CONFIG_HAVE_DOUBLE 1
+# define CONFIG_HAVE_LONG_DOUBLE 1
/* Structures and unions can be assigned and passed as values */
@@ -255,7 +262,7 @@
* external RAM.
*/
-#if defined(__z80) || defined(__gbz80)
+#if defined(__SDCC_z80) || defined(__SDCC_z180) || defined(__SDCC_gbz80)
# define FAR
# define NEAR
# define CODE
@@ -295,7 +302,9 @@
/* SDCC does not support type long long or type double */
# undef CONFIG_HAVE_LONG_LONG
+# define CONFIG_HAVE_FLOAT 1
# undef CONFIG_HAVE_DOUBLE
+# undef CONFIG_HAVE_LONG_DOUBLE
/* Structures and unions cannot be passed as values or used
* in assignments.
@@ -398,8 +407,10 @@
* simply do not support long long or double.
*/
-# undef CONFIG_HAVE_DOUBLE
# undef CONFIG_HAVE_LONG_LONG
+# define CONFIG_HAVE_FLOAT 1
+# undef CONFIG_HAVE_DOUBLE
+# undef CONFIG_HAVE_LONG_DOUBLE
/* Structures and unions can be assigned and passed as values */
@@ -433,9 +444,11 @@
# undef CONFIG_LONG_IS_NOT_INT
# undef CONFIG_PTR_IS_NOT_INT
# undef CONFIG_HAVE_INLINE
-# define inline
+# define inline 1
# undef CONFIG_HAVE_LONG_LONG
+# define CONFIG_HAVE_FLOAT 1
# undef CONFIG_HAVE_DOUBLE
+# undef CONFIG_HAVE_LONG_DOUBLE
# undef CONFIG_CAN_PASS_STRUCTS
#endif
diff --git a/nuttx/include/nuttx/float.h b/nuttx/include/nuttx/float.h
new file mode 100644
index 000000000..a8e4aa28b
--- /dev/null
+++ b/nuttx/include/nuttx/float.h
@@ -0,0 +1,225 @@
+/****************************************************************************
+ * include/nuttx/float.h
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * Reference: http://pubs.opengroup.org/onlinepubs/009695399/basedefs/float.h.html
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_FLOAT_H
+#define __INCLUDE_NUTTX_FLOAT_H
+
+/* TODO: These values could vary with architectures toolchains. This
+ * logic should be move at least to the include/arch directory.
+ */
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Radix of exponent representation, b. */
+
+#define FLT_RADIX 2
+
+/* Number of base-FLT_RADIX digits in the floating-point significand, p. */
+
+#define FLT_MANT_DIG 24
+
+#if CONFIG_HAVE_DOUBLE
+# define DBL_MANT_DIG 53
+#else
+# define DBL_MANT_DIG FLT_MANT_DIG
+#endif
+
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+# define LDBL_MANT_DIG DBL_MANT_DIG /* FIX ME */
+#else
+# define LDBL_MANT_DIG DBL_MANT_DIG
+#endif
+
+/* Number of decimal digits, n, such that any floating-point number in the
+ * widest supported floating type with pmax radix b digits can be rounded
+ * to a floating-point number with n decimal digits and back again without
+ * change to the value.
+ */
+
+#define DECIMAL_DIG 10
+
+/* Number of decimal digits, q, such that any floating-point number with q
+ * decimal digits can be rounded into a floating-point number with p radix
+ * b digits and back again without change to the q decimal digits.
+ */
+
+#define FLT_DIG 6
+
+#if CONFIG_HAVE_DOUBLE
+# define DBL_DIG 15 /* 10 */
+#else
+# define DBL_DIG FLT_DIG
+#endif
+
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+# define LDBL_DIG DBL_DIG /* FIX ME */
+#else
+# define LDBL_DIG DBL_DIG
+#endif
+
+/* Minimum negative integer such that FLT_RADIX raised to that power minus
+ * 1 is a normalized floating-point number, emin.
+ */
+
+#define FLT_MIN_EXP (-125)
+
+#if CONFIG_HAVE_DOUBLE
+# define DBL_MIN_EXP (-1021)
+#else
+# define DBL_MIN_EXP FLT_MIN_EXP
+#endif
+
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+# define LDBL_MIN_EXP DBL_MIN_EXP /* FIX ME */
+#else
+# define LDBL_MIN_EXP DBL_MIN_EXP
+#endif
+
+/* inimum negative integer such that 10 raised to that power is in the range
+ * of normalized floating-point numbers.
+ */
+
+#define FLT_MIN_10_EXP (-37)
+
+#if CONFIG_HAVE_DOUBLE
+# define DBL_MIN_10_EXP (-307) /* -37 */
+#else
+# define DBL_MIN_10_EXP FLT_MIN_10_EXP
+#endif
+
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+# define LDBL_MIN_10_EXP DBL_MIN_10_EXP /* FIX ME */
+#else
+# define LDBL_MIN_10_EXP DBL_MIN_10_EXP
+#endif
+
+/* Maximum integer such that FLT_RADIX raised to that power minus 1 is a
+ * representable finite floating-point number, emax.
+ */
+
+#define FLT_MAX_EXP 128
+
+#if CONFIG_HAVE_DOUBLE
+# define DBL_MAX_EXP 1024
+#else
+# define DBL_MAX_EXP FLT_MAX_EXP
+#endif
+
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+# define LDBL_MAX_EXP DBL_MAX_EXP /* FIX ME */
+#else
+# define LDBL_MAX_EXP DBL_MAX_EXP
+#endif
+
+/* Maximum integer such that 10 raised to that power is in the range of
+ * representable finite floating-point numbers.
+ */
+
+#define FLT_MAX_10_EXP 38 /* 37 */
+
+#if CONFIG_HAVE_DOUBLE
+# define DBL_MAX_10_EXP 308 /* 37 */
+#else
+# define DBL_MAX_10_EXP FLT_MAX_10_EXP
+#endif
+
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+# define LDBL_MAX_10_EXP DBL_MAX_10_EXP /* FIX ME */
+#else
+# define LDBL_MAX_10_EXP DBL_MAX_10_EXP
+#endif
+
+/* Maximum representable finite floating-point number. */
+
+#define FLT_MAX 3.40282347e+38F /* 1E+37 */
+
+#if CONFIG_HAVE_DOUBLE
+# define DBL_MAX 1.7976931348623157e+308 /* 1E+37 */
+#else
+# define DBL_MAX FLT_MAX
+#endif
+
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+# define LDBL_MAX DBL_MAX /* FIX ME */
+#else
+# define LDBL_MAX DBL_MAX
+#endif
+
+/* The difference between 1 and the least value greater than 1 that is
+ * representable in the given floating-point type, b1-p.
+ */
+
+#define FLT_EPSILON 1.1920929e-07F /* 1E-5 */
+
+#if CONFIG_HAVE_DOUBLE
+# define DBL_EPSILON 2.2204460492503131e-16 /* 1E-9 */
+#else
+# define DBL_EPSILON FLT_EPSILON
+#endif
+
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+# define LDBL_EPSILON DBL_EPSILON /* FIX ME */
+#else
+# define LDBL_EPSILON DBL_EPSILON
+#endif
+
+/* Minimum normalized positive floating-point number, bemin -1. */
+
+#define FLT_MIN 1.17549435e-38F /* 1E-37 */
+
+#if CONFIG_HAVE_DOUBLE
+#define DBL_MIN 2.2250738585072014e-308 /* 1E-37 */
+#else
+# define DBL_MIN FLT_MIN
+#endif
+
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+# define LDBL_MIN DBL_MIN /* FIX ME */
+#else
+# define LDBL_MIN DBL_MIN
+#endif
+
+#endif /* __INCLUDE_NUTTX_FLOAT_H */
diff --git a/nuttx/include/nuttx/fs/fs.h b/nuttx/include/nuttx/fs/fs.h
index 81f81622f..1759310bc 100644
--- a/nuttx/include/nuttx/fs/fs.h
+++ b/nuttx/include/nuttx/fs/fs.h
@@ -51,6 +51,10 @@
/****************************************************************************
* Definitions
****************************************************************************/
+/* Stream flags for the fs_flags field of in struct file_struct */
+
+#define __FS_FLAG_EOF (1 << 0) /* EOF detected by a read operation */
+#define __FS_FLAG_ERROR (1 << 1) /* Error detected by any operation */
/****************************************************************************
* Type Definitions
@@ -172,7 +176,7 @@ struct mountpt_operations
int (*statfs)(FAR struct inode *mountpt, FAR struct statfs *buf);
- /* Operations on pathes */
+ /* Operations on paths */
int (*unlink)(FAR struct inode *mountpt, FAR const char *relpath);
int (*mkdir)(FAR struct inode *mountpt, FAR const char *relpath, mode_t mode);
@@ -270,11 +274,6 @@ struct filelist
struct file_struct
{
int fs_filedes; /* File descriptor associated with stream */
- uint16_t fs_oflags; /* Open mode flags */
-#if CONFIG_NUNGET_CHARS > 0
- uint8_t fs_nungotten; /* The number of characters buffered for ungetc */
- unsigned char fs_ungotten[CONFIG_NUNGET_CHARS];
-#endif
#if CONFIG_STDIO_BUFFER_SIZE > 0
sem_t fs_sem; /* For thread safety */
pid_t fs_holder; /* Holder of sem */
@@ -284,6 +283,12 @@ struct file_struct
FAR unsigned char *fs_bufpos; /* Current position in buffer */
FAR unsigned char *fs_bufread; /* Pointer to 1 past last buffered read char. */
#endif
+ uint16_t fs_oflags; /* Open mode flags */
+ uint8_t fs_flags; /* Stream flags */
+#if CONFIG_NUNGET_CHARS > 0
+ uint8_t fs_nungotten; /* The number of characters buffered for ungetc */
+ unsigned char fs_ungotten[CONFIG_NUNGET_CHARS];
+#endif
};
struct streamlist
diff --git a/nuttx/include/nuttx/i2c.h b/nuttx/include/nuttx/i2c.h
index ef3d9a388..23356ecd3 100644
--- a/nuttx/include/nuttx/i2c.h
+++ b/nuttx/include/nuttx/i2c.h
@@ -1,7 +1,7 @@
/****************************************************************************
* include/nuttx/i2c.h
*
- * Copyright(C) 2009-2011 Gregory Nutt. All rights reserved.
+ * Copyright(C) 2009-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -47,6 +47,16 @@
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
+/* If a dynamic timeout is selected, then a non-negative, non-zero micro-
+ * seconds per byte vale must be provided as well.
+ */
+
+#ifdef CONFIG_STM32_I2C_DYNTIMEO
+# if CONFIG_STM32_I2C_DYNTIMEO_USECPERBYTE < 1
+# warning "Ignoring CONFIG_STM32_I2C_DYNTIMEO because of CONFIG_STM32_I2C_DYNTIMEO_USECPERBYTE"
+# undef CONFIG_STM32_I2C_DYNTIMEO
+# endif
+#endif
/* I2C address calculation. Convert 7- and 10-bit address to 8-bit and
* 16-bit read/write address
@@ -323,24 +333,19 @@ EXTERN FAR struct i2c_dev_s *up_i2cinitialize(int port);
*
****************************************************************************/
-EXTERN int up_i2cuninitialize(FAR struct i2c_dev_s * dev);
+EXTERN int up_i2cuninitialize(FAR struct i2c_dev_s *dev);
-/****************************************************************************
+/************************************************************************************
* Name: up_i2creset
*
* Description:
- * Reset the port and the associated I2C bus. Useful when the bus or an
- * attached slave has become wedged or unresponsive.
+ * Reset an I2C bus
*
- * Input Parameter:
- * Device structure as returned by the up_i2cinitalize()
- *
- * Returned Value:
- * OK on success, ERROR if the bus cannot be unwedged.
- *
- ****************************************************************************/
+ ************************************************************************************/
-EXTERN int up_i2creset(FAR struct i2c_dev_s * dev);
+#ifdef CONFIG_I2C_RESET
+EXTERN int up_i2creset(FAR struct i2c_dev_s *dev);
+#endif
#undef EXTERN
#if defined(__cplusplus)
diff --git a/nuttx/include/nuttx/input/keypad.h b/nuttx/include/nuttx/input/keypad.h
new file mode 100644
index 000000000..574b421c1
--- /dev/null
+++ b/nuttx/include/nuttx/input/keypad.h
@@ -0,0 +1,54 @@
+/************************************************************************************
+ * include/nuttx/input/keypad.h
+ *
+ * Copyright (C) 2012 Denis Carikli.
+ * Author: Denis Carikli <GNUtoo@no-log.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ************************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_INPUT_KEYPAD_H
+#define __INCLUDE_NUTTX_INPUT_KEYPAD_H
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int keypad_kbdinit(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __INCLUDE_NUTTX_INPUT_KEYPAD_H */
+
diff --git a/nuttx/include/nuttx/input/max11802.h b/nuttx/include/nuttx/input/max11802.h
new file mode 100644
index 000000000..3d03bdd11
--- /dev/null
+++ b/nuttx/include/nuttx/input/max11802.h
@@ -0,0 +1,175 @@
+/****************************************************************************
+ * include/nuttx/input/max11802.h
+ *
+ * Copyright (C) 2011 Gregory Nutt. All rights reserved.
+ * Authors: Gregory Nutt <gnutt@nuttx.org>
+ * Petteri Aimonen <jpa@nx.mail.kapsi.fi>
+ *
+ * References:
+ * "Low-Power, Ultra-Small Resistive Touch-Screen Controllers
+ * with I2C/SPI Interface" Maxim IC, Rev 3, 10/2010
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_INPUT_MAX11802_H
+#define __INCLUDE_NUTTX_INPUT_MAX11802_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/spi.h>
+#include <stdbool.h>
+#include <nuttx/irq.h>
+
+#if defined(CONFIG_INPUT) && defined(CONFIG_INPUT_MAX11802)
+
+/****************************************************************************
+ * Pre-Processor Definitions
+ ****************************************************************************/
+/* Configuration ************************************************************/
+/* SPI Frequency. Default: 100KHz */
+
+#ifndef CONFIG_MAX11802_FREQUENCY
+# define CONFIG_MAX11802_FREQUENCY 100000
+#endif
+
+/* Maximum number of threads than can be waiting for POLL events */
+
+#ifndef CONFIG_MAX11802_NPOLLWAITERS
+# define CONFIG_MAX11802_NPOLLWAITERS 2
+#endif
+
+#ifndef CONFIG_MAX11802_SPIMODE
+# define CONFIG_MAX11802_SPIMODE SPIDEV_MODE0
+#endif
+
+/* Thresholds */
+
+#ifndef CONFIG_MAX11802_THRESHX
+# define CONFIG_MAX11802_THRESHX 12
+#endif
+
+#ifndef CONFIG_MAX11802_THRESHY
+# define CONFIG_MAX11802_THRESHY 12
+#endif
+
+/* Check for some required settings. This can save the user a lot of time
+ * in getting the right configuration.
+ */
+
+#ifdef CONFIG_DISABLE_SIGNALS
+# error "Signals are required. CONFIG_DISABLE_SIGNALS must not be selected."
+#endif
+
+#ifndef CONFIG_SCHED_WORKQUEUE
+# error "Work queue support required. CONFIG_SCHED_WORKQUEUE must be selected."
+#endif
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* A reference to a structure of this type must be passed to the MAX11802
+ * driver. This structure provides information about the configuration
+ * of the MAX11802 and provides some board-specific hooks.
+ *
+ * Memory for this structure is provided by the caller. It is not copied
+ * by the driver and is presumed to persist while the driver is active. The
+ * memory must be writable because, under certain circumstances, the driver
+ * may modify frequency or X plate resistance values.
+ */
+
+struct max11802_config_s
+{
+ /* Device characterization */
+
+ uint32_t frequency; /* SPI frequency */
+
+ /* IRQ/GPIO access callbacks. These operations all hidden behind
+ * callbacks to isolate the MAX11802 driver from differences in GPIO
+ * interrupt handling by varying boards and MCUs. If possible,
+ * interrupts should be configured on both rising and falling edges
+ * so that contact and loss-of-contact events can be detected.
+ *
+ * attach - Attach the MAX11802 interrupt handler to the GPIO interrupt
+ * enable - Enable or disable the GPIO interrupt
+ * clear - Acknowledge/clear any pending GPIO interrupt
+ * pendown - Return the state of the pen down GPIO input
+ */
+
+ int (*attach)(FAR struct max11802_config_s *state, xcpt_t isr);
+ void (*enable)(FAR struct max11802_config_s *state, bool enable);
+ void (*clear)(FAR struct max11802_config_s *state);
+ bool (*pendown)(FAR struct max11802_config_s *state);
+};
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C" {
+#else
+#define EXTERN extern
+#endif
+
+/****************************************************************************
+ * Name: max11802_register
+ *
+ * Description:
+ * Configure the MAX11802 to use the provided SPI device instance. This
+ * will register the driver as /dev/inputN where N is the minor device
+ * number
+ *
+ * Input Parameters:
+ * spi - An SPI driver instance
+ * config - Persistent board configuration data
+ * minor - The input device minor number
+ *
+ * Returned Value:
+ * Zero is returned on success. Otherwise, a negated errno value is
+ * returned to indicate the nature of the failure.
+ *
+ ****************************************************************************/
+
+EXTERN int max11802_register(FAR struct spi_dev_s *spi,
+ FAR struct max11802_config_s *config,
+ int minor);
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* CONFIG_INPUT && CONFIG_INPUT_MAX11802 */
+#endif /* __INCLUDE_NUTTX_INPUT_MAX11802_H */
diff --git a/nuttx/include/nuttx/lcd/ug-2864ambag01.h b/nuttx/include/nuttx/lcd/ug-2864ambag01.h
new file mode 100644
index 000000000..deb568981
--- /dev/null
+++ b/nuttx/include/nuttx/lcd/ug-2864ambag01.h
@@ -0,0 +1,245 @@
+/**************************************************************************************
+ * include/nuttx/lcd/ug-2864ambag01.h
+ * Driver for Univision UG-2864AMBAG01 OLED display (wih SH1101A controller) in SPI
+ * mode
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * References:
+ * 1. Product Specification (Preliminary), Part Name: OEL Display Module, Part ID:
+ * UG-2864AMBAG01, Doc No: SASI-9015-A, Univision Technology Inc.
+ * 2. SH1101A, 132 X 64 Dot Matrix OLED/PLED, Preliminary Segment/Common Driver with
+ * Controller, Sino Wealth
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ **************************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_UG_8264AMBAG01_H
+#define __INCLUDE_NUTTX_UG_8264AMBAG01_H
+
+/**************************************************************************************
+ * Included Files
+ **************************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdbool.h>
+
+#include <nuttx/arch.h>
+
+#ifdef CONFIG_LCD_UG2864AMBAG01
+
+/**************************************************************************************
+ * Pre-processor Definitions
+ **************************************************************************************/
+/* Configuration **********************************************************************/
+/* UG-2864AMBAG01 Configuration Settings:
+ *
+ * CONFIG_UG2864AMBAG01_SPIMODE - Controls the SPI mode
+ * CONFIG_UG2864AMBAG01_FREQUENCY - Define to use a different bus frequency
+ * CONFIG_UG2864AMBAG01_NINTERFACES - Specifies the number of physical UG-2864AMBAG01
+ * devices that will be supported.
+ *
+ * Required LCD driver settings:
+ *
+ * CONFIG_LCD_UG28AMBAG01 - Enable UG-2864AMBAG01 support
+ * CONFIG_LCD_MAXCONTRAST should be 255, but any value >0 and <=255 will be accepted.
+ * CONFIG_LCD_MAXPOWER must be 1
+ *
+ * Option LCD driver settings:
+ * CONFIG_LCD_LANDSCAPE, CONFIG_LCD_PORTRAIT, CONFIG_LCD_RLANDSCAPE, and
+ * CONFIG_LCD_RPORTRAIT - Display orientation.
+ *
+ * Required SPI driver settings:
+ * CONFIG_SPI_CMDDATA - Include support for cmd/data selection.
+ */
+
+/* SPI Interface
+ *
+ * "The serial interface consists of serial clock SCL, serial data SI, A0 and
+ * CS . SI is shifted into an 8-bit shift register on every rising edge of
+ * SCL in the order of D7, D6, … and D0. A0 is sampled on every eighth clock
+ * and the data byte in the shift register is written to the display data RAM
+ * or command register in the same clock."
+ *
+ * MODE 3:
+ * Clock polarity: High (CPOL=1)
+ * Clock phase: Sample on trailing (rising edge) (CPHA 1)
+ */
+
+#ifndef CONFIG_UG2864AMBAG01_SPIMODE
+# define CONFIG_UG2864AMBAG01_SPIMODE SPIDEV_MODE3
+#endif
+
+/* "This module determines whether the input data is interpreted as data or
+ * command. When A0 = “H”, the inputs at D7 - D0 are interpreted as data and be
+ * written to display RAM. When A0 = “L”, the inputs at D7 - D0 are interpreted
+ * as command, they will be decoded and be written to the corresponding command
+ * registers.
+ */
+
+#ifndef CONFIG_SPI_CMDDATA
+# error "CONFIG_SPI_CMDDATA must be defined in your NuttX configuration"
+#endif
+
+/* CONFIG_UG2864AMBAG01_NINTERFACES determines the number of physical interfaces
+ * that will be supported.
+ */
+
+#ifndef CONFIG_UG2864AMBAG01_NINTERFACES
+# define CONFIG_UG2864AMBAG01_NINTERFACES 1
+#endif
+
+/* Check contrast selection */
+
+#if !defined(CONFIG_LCD_MAXCONTRAST)
+# define CONFIG_LCD_MAXCONTRAST 255
+#endif
+
+#if CONFIG_LCD_MAXCONTRAST <= 0|| CONFIG_LCD_MAXCONTRAST > 255
+# error "CONFIG_LCD_MAXCONTRAST exceeds supported maximum"
+#endif
+
+#if CONFIG_LCD_MAXCONTRAST < 255
+# warning "Optimal setting of CONFIG_LCD_MAXCONTRAST is 255"
+#endif
+
+/* Check power setting */
+
+#if !defined(CONFIG_LCD_MAXPOWER)
+# define CONFIG_LCD_MAXPOWER 1
+#endif
+
+#if CONFIG_LCD_MAXPOWER != 1
+# warning "CONFIG_LCD_MAXPOWER exceeds supported maximum"
+# undef CONFIG_LCD_MAXPOWER
+# define CONFIG_LCD_MAXPOWER 1
+#endif
+
+/* Color is 1bpp monochrome with leftmost column contained in bits 0 */
+
+#ifdef CONFIG_NX_DISABLE_1BPP
+# warning "1 bit-per-pixel support needed"
+#endif
+
+/* Orientation */
+
+#if defined(CONFIG_LCD_LANDSCAPE)
+# undef CONFIG_LCD_PORTRAIT
+# undef CONFIG_LCD_RLANDSCAPE
+# undef CONFIG_LCD_RPORTRAIT
+#elif defined(CONFIG_LCD_PORTRAIT)
+# undef CONFIG_LCD_LANDSCAPE
+# undef CONFIG_LCD_RLANDSCAPE
+# undef CONFIG_LCD_RPORTRAIT
+#elif defined(CONFIG_LCD_RLANDSCAPE)
+# undef CONFIG_LCD_LANDSCAPE
+# undef CONFIG_LCD_PORTRAIT
+# undef CONFIG_LCD_RPORTRAIT
+#elif defined(CONFIG_LCD_RPORTRAIT)
+# undef CONFIG_LCD_LANDSCAPE
+# undef CONFIG_LCD_PORTRAIT
+# undef CONFIG_LCD_RLANDSCAPE
+#else
+# define CONFIG_LCD_LANDSCAPE 1
+# warning "Assuming landscape orientation"
+#endif
+
+/* Some important "colors" */
+
+#define UG_Y1_BLACK 0
+#define UG_Y1_WHITE 1
+
+/**************************************************************************************
+ * Public Types
+ **************************************************************************************/
+
+/**************************************************************************************
+ * Public Data
+ **************************************************************************************/
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/**************************************************************************************
+ * Public Function Prototypes
+ **************************************************************************************/
+
+/**************************************************************************************
+ * Name: ug2864ambag01_initialize
+ *
+ * Description:
+ * Initialize the UG-2864AMBAG01 video hardware. The initial state of the
+ * OLED is fully initialized, display memory cleared, and the OLED ready
+ * to use, but with the power setting at 0 (full off == sleep mode).
+ *
+ * Input Parameters:
+ *
+ * spi - A reference to the SPI driver instance.
+ * devno - A value in the range of 0 through CONFIG_UG2864AMBAG01_NINTERFACES-1.
+ * This allows support for multiple OLED devices.
+ *
+ * Returned Value:
+ *
+ * On success, this function returns a reference to the LCD object for
+ * the specified OLED. NULL is returned on any failure.
+ *
+ **************************************************************************************/
+
+struct lcd_dev_s; /* See include/nuttx/lcd/lcd.h */
+struct spi_dev_s; /* See include/nuttx/spi.h */
+FAR struct lcd_dev_s *ug2864ambag01_initialize(FAR struct spi_dev_s *spi,
+ unsigned int devno);
+
+/************************************************************************************************
+ * Name: ug2864ambag01_fill
+ *
+ * Description:
+ * This non-standard method can be used to clear the entire display by writing one
+ * color to the display. This is much faster than writing a series of runs.
+ *
+ * Input Parameters:
+ * priv - Reference to private driver structure
+ *
+ * Assumptions:
+ * Caller has selected the OLED section.
+ *
+ **************************************************************************************/
+
+void ug2864ambag01_fill(FAR struct lcd_dev_s *dev, uint8_t color);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* CONFIG_LCD_UG2864AMBAG01 */
+#endif /* __INCLUDE_NUTTX_UG_8264AMBAG01_H */
diff --git a/nuttx/include/nuttx/lcd/ug-9664hswag01.h b/nuttx/include/nuttx/lcd/ug-9664hswag01.h
index 696005b5d..b470e0895 100644
--- a/nuttx/include/nuttx/lcd/ug-9664hswag01.h
+++ b/nuttx/include/nuttx/lcd/ug-9664hswag01.h
@@ -3,7 +3,7 @@
* Driver for the Univision UG-9664HSWAG01 Display with the Solomon Systech
* SSD1305 LCD controller.
*
- * Copyright (C) 2011 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -58,8 +58,6 @@
* CONFIG_UG9664HSWAG01_POWER
* If the hardware supports a controllable OLED a power supply, this
* configuration shold be defined. (See ug_power() below).
- * CONFIG_LCD_UGDEBUG - Enable detailed UG-9664HSWAG01 debug output
- * (CONFIG_DEBUG and CONFIG_VERBOSE must also be enabled).
*
* Required LCD driver settings:
* CONFIG_LCD_UG9664HSWAG01 - Enable UG-9664HSWAG01 support
@@ -90,10 +88,8 @@
****************************************************************************/
#ifdef __cplusplus
-#define EXTERN extern "C"
-extern "C" {
-#else
-#define EXTERN extern
+extern "C"
+{
#endif
/****************************************************************************
@@ -123,7 +119,7 @@ extern "C" {
struct lcd_dev_s; /* see nuttx/lcd.h */
struct spi_dev_s; /* see nuttx/spi.h */
-EXTERN FAR struct lcd_dev_s *ug_initialize(FAR struct spi_dev_s *spi, unsigned int devno);
+FAR struct lcd_dev_s *ug_initialize(FAR struct spi_dev_s *spi, unsigned int devno);
/****************************************************************************
* Name: ug_power
@@ -145,12 +141,11 @@ EXTERN FAR struct lcd_dev_s *ug_initialize(FAR struct spi_dev_s *spi, unsigned i
**************************************************************************************/
#ifdef CONFIG_UG9664HSWAG01_POWER
-EXTERN void ug_power(unsigned int devno, bool on);
+void ug_power(unsigned int devno, bool on);
#else
# define ug_power(a,b)
#endif
-#undef EXTERN
#ifdef __cplusplus
}
#endif
diff --git a/nuttx/include/nuttx/math.h b/nuttx/include/nuttx/math.h
index 84dbea6e0..aaadb9c91 100644
--- a/nuttx/include/nuttx/math.h
+++ b/nuttx/include/nuttx/math.h
@@ -50,14 +50,280 @@
#ifdef CONFIG_ARCH_MATH_H
# include <arch/math.h>
-#endif
+
+/* If CONFIG_LIB is enabled, then the math library at lib/math will be
+ * built. This library was taken from the math library developed for the
+ * Rhombus OS by Nick Johnson (https://github.com/nickbjohnson4224/rhombus).
+ * The port or the Rhombus math library was contributed by Darcy Gong.
+ */
+
+#else if defined CONFIG_LIBM
/****************************************************************************
- * Type Definitions
+ * Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
****************************************************************************/
/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* General Constants ********************************************************/
+
+#define INFINITY (1.0/0.0)
+#define NAN (0.0/0.0)
+#define HUGE_VAL INFINITY
+
+#define isnan(x) ((x) != (x))
+#define isinf(x) (((x) == INFINITY) || ((x) == -INFINITY))
+
+/* Exponential and Logarithmic constants ************************************/
+
+#define M_E 2.7182818284590452353602874713526625
+#define M_SQRT2 1.4142135623730950488016887242096981
+#define M_SQRT1_2 0.7071067811865475244008443621048490
+#define M_LOG2E 1.4426950408889634073599246810018921
+#define M_LOG10E 0.4342944819032518276511289189166051
+#define M_LN2 0.6931471805599453094172321214581765
+#define M_LN10 2.3025850929940456840179914546843642
+
+/* Trigonometric Constants **************************************************/
+
+#define M_PI 3.1415926535897932384626433832795029
+#define M_PI_2 1.5707963267948966192313216916397514
+#define M_PI_4 0.7853981633974483096156608458198757
+#define M_1_PI 0.3183098861837906715377675267450287
+#define M_2_PI 0.6366197723675813430755350534900574
+#define M_2_SQRTPI 1.1283791670955125738961589031215452
+
+/****************************************************************************
* Public Function Prototypes
****************************************************************************/
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+/* General Functions ********************************************************/
+
+float ceilf (float x);
+#if CONFIG_HAVE_DOUBLE
+double ceil (double x);
+#endif
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double ceill (long double x);
+#endif
+
+float floorf(float x);
+#if CONFIG_HAVE_DOUBLE
+double floor (double x);
+#endif
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double floorl(long double x);
+#endif
+
+float roundf(float x);
+#if CONFIG_HAVE_DOUBLE
+double round (double x);
+#endif
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double roundl(long double x);
+#endif
+
+float fabsf (float x);
+#if CONFIG_HAVE_DOUBLE
+double fabs (double x);
+#endif
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double fabsl (long double x);
+#endif
+
+float modff (float x, float *iptr);
+#if CONFIG_HAVE_DOUBLE
+double modf (double x, double *iptr);
+#endif
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double modfl (long double x, long double *iptr);
+#endif
+
+float fmodf (float x, float div);
+#if CONFIG_HAVE_DOUBLE
+double fmod (double x, double div);
+#endif
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double fmodl (long double x, long double div);
+#endif
+
+/* Exponential and Logarithmic Functions ************************************/
+
+float powf (float b, float e);
+#if CONFIG_HAVE_DOUBLE
+double pow (double b, double e);
+#endif
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double powl (long double b, long double e);
+#endif
+
+float expf (float x);
+#if CONFIG_HAVE_DOUBLE
+double exp (double x);
+#endif
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double expl (long double x);
+#endif
+
+float logf (float x);
+#if CONFIG_HAVE_DOUBLE
+double log (double x);
+#endif
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double logl (long double x);
+#endif
+
+float log10f(float x);
+#if CONFIG_HAVE_DOUBLE
+double log10 (double x);
+#endif
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double log10l(long double x);
+#endif
+
+float log2f (float x);
+#if CONFIG_HAVE_DOUBLE
+double log2 (double x);
+#endif
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double log2l (long double x);
+#endif
+
+float sqrtf (float x);
+#if CONFIG_HAVE_DOUBLE
+double sqrt (double x);
+#endif
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double sqrtl (long double x);
+#endif
+
+float ldexpf(float x, int n);
+#if CONFIG_HAVE_DOUBLE
+double ldexp (double x, int n);
+#endif
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double ldexpl(long double x, int n);
+#endif
+
+float frexpf(float x, int *exp);
+#if CONFIG_HAVE_DOUBLE
+double frexp (double x, int *exp);
+#endif
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double frexpl(long double x, int *exp);
+#endif
+
+/* Trigonometric Functions **************************************************/
+
+float sinf (float x);
+#if CONFIG_HAVE_DOUBLE
+double sin (double x);
+#endif
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double sinl (long double x);
+#endif
+
+float cosf (float x);
+#if CONFIG_HAVE_DOUBLE
+double cos (double x);
+#endif
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double cosl (long double x);
+#endif
+
+float tanf (float x);
+#if CONFIG_HAVE_DOUBLE
+double tan (double x);
+#endif
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double tanl (long double x);
+#endif
+
+float asinf (float x);
+#if CONFIG_HAVE_DOUBLE
+double asin (double x);
+#endif
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double asinl (long double x);
+#endif
+
+float acosf (float x);
+#if CONFIG_HAVE_DOUBLE
+double acos (double x);
+#endif
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double acosl (long double x);
+#endif
+
+float atanf (float x);
+#if CONFIG_HAVE_DOUBLE
+double atan (double x);
+#endif
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double atanl (long double x);
+#endif
+
+float atan2f(float y, float x);
+#if CONFIG_HAVE_DOUBLE
+double atan2 (double y, double x);
+#endif
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double atan2l(long double y, long double x);
+#endif
+
+float sinhf (float x);
+#if CONFIG_HAVE_DOUBLE
+double sinh (double x);
+#endif
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double sinhl (long double x);
+#endif
+
+float coshf (float x);
+#if CONFIG_HAVE_DOUBLE
+double cosh (double x);
+#endif
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double coshl (long double x);
+#endif
+
+float tanhf (float x);
+#if CONFIG_HAVE_DOUBLE
+double tanh (double x);
+#endif
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double tanhl (long double x);
+#endif
+
+#if defined(__cplusplus)
+}
+#endif
+
+#endif /* CONFIG_LIBM */
#endif /* __INCLUDE_NUTTX_MATH_H */
diff --git a/nuttx/include/nuttx/mtd.h b/nuttx/include/nuttx/mtd.h
index 44582c412..ff48d313f 100644
--- a/nuttx/include/nuttx/mtd.h
+++ b/nuttx/include/nuttx/mtd.h
@@ -220,7 +220,6 @@ EXTERN FAR struct mtd_dev_s *at24c_initialize(FAR struct i2c_dev_s *dev);
EXTERN FAR struct mtd_dev_s *sst25_initialize(FAR struct spi_dev_s *dev);
-
/****************************************************************************
* Name: w25_initialize
*
@@ -233,6 +232,8 @@ EXTERN FAR struct mtd_dev_s *sst25_initialize(FAR struct spi_dev_s *dev);
EXTERN FAR struct mtd_dev_s *w25_initialize(FAR struct spi_dev_s *dev);
+EXTERN FAR struct mtd_dev_s *at25_initialize(FAR struct spi_dev_s *dev);
+
#undef EXTERN
#ifdef __cplusplus
}
diff --git a/nuttx/include/nuttx/net/ioctl.h b/nuttx/include/nuttx/net/ioctl.h
index be3f597f4..d5d1a001c 100644
--- a/nuttx/include/nuttx/net/ioctl.h
+++ b/nuttx/include/nuttx/net/ioctl.h
@@ -146,9 +146,15 @@
#define SIOCSIWPMKSA _SIOC(0x0036) /* PMKSA cache operation */
+/* Interface flags */
+
+#define SIOCSIFFLAGS _SIOC(0x0037) /* Sets the interface flags */
+#define SIOCGIFFLAGS _SIOC(0x0038) /* Gets the interface flags */
+
/****************************************************************************
* Type Definitions
****************************************************************************/
+
/* See include/net/if.h */
/****************************************************************************
diff --git a/nuttx/include/nuttx/net/uip/uip-arch.h b/nuttx/include/nuttx/net/uip/uip-arch.h
index 9546de04e..73805c6fb 100644
--- a/nuttx/include/nuttx/net/uip/uip-arch.h
+++ b/nuttx/include/nuttx/net/uip/uip-arch.h
@@ -90,6 +90,10 @@ struct uip_driver_s
char d_ifname[IFNAMSIZ];
#endif
+ /* Drivers interface flags. See IFF_* definitions in include/net/if.h */
+
+ uint8_t d_flags;
+
/* Ethernet device identity */
#ifdef CONFIG_NET_ETHERNET
diff --git a/nuttx/include/nuttx/power/pm.h b/nuttx/include/nuttx/power/pm.h
index 86e23f090..9c0568b2d 100644
--- a/nuttx/include/nuttx/power/pm.h
+++ b/nuttx/include/nuttx/power/pm.h
@@ -163,7 +163,7 @@
#endif
#if CONFIG_PM_IDLEENTER_THRESH >= CONFIG_PM_IDLEEXIT_THRESH
-# error "Must have CONFIG_PM_IDLEENTER_THRESH < CONFIG_PM_IDLEEXIT_THRESH
+# error "Must have CONFIG_PM_IDLEENTER_THRESH < CONFIG_PM_IDLEEXIT_THRESH"
#endif
#ifndef CONFIG_PM_IDLEENTER_COUNT
@@ -181,7 +181,7 @@
#endif
#if CONFIG_PM_STANDBYENTER_THRESH >= CONFIG_PM_STANDBYEXIT_THRESH
-# error "Must have CONFIG_PM_STANDBYENTER_THRESH < CONFIG_PM_STANDBYEXIT_THRESH
+# error "Must have CONFIG_PM_STANDBYENTER_THRESH < CONFIG_PM_STANDBYEXIT_THRESH"
#endif
#ifndef CONFIG_PM_STANDBYENTER_COUNT
@@ -199,7 +199,7 @@
#endif
#if CONFIG_PM_SLEEPENTER_THRESH >= CONFIG_PM_SLEEPEXIT_THRESH
-# error "Must have CONFIG_PM_SLEEPENTER_THRESH < CONFIG_PM_SLEEPEXIT_THRESH
+# error "Must have CONFIG_PM_SLEEPENTER_THRESH < CONFIG_PM_SLEEPEXIT_THRESH"
#endif
#ifndef CONFIG_PM_SLEEPENTER_COUNT
diff --git a/nuttx/include/nuttx/sched.h b/nuttx/include/nuttx/sched.h
index 241af6210..6eaba6e9c 100644
--- a/nuttx/include/nuttx/sched.h
+++ b/nuttx/include/nuttx/sched.h
@@ -138,11 +138,11 @@ typedef union entry_u entry_t;
*/
#ifdef CONFIG_SCHED_ATEXIT
-typedef void (*atexitfunc_t)(void);
+typedef CODE void (*atexitfunc_t)(void);
#endif
#ifdef CONFIG_SCHED_ONEXIT
-typedef void (*onexitfunc_t)(int exitcode, FAR void *arg);
+typedef CODE void (*onexitfunc_t)(int exitcode, FAR void *arg);
#endif
/* POSIX Message queue */
@@ -163,24 +163,40 @@ typedef struct environ_s environ_t;
# define SIZEOF_ENVIRON_T(alloc) (sizeof(environ_t) + alloc - 1)
#endif
-/* This structure describes a reference counted D-Space region */
+/* This structure describes a reference counted D-Space region. This must be a
+ * separately allocated "break-away" structure that can be owned by a task and
+ * any pthreads created by the task.
+ */
+#ifdef CONFIG_PIC
struct dspace_s
{
- uint32_t crefs; /* This is the number of pthreads that shared the
- * the same D-Space */
- uint8_t region[1]; /* Beginning of the allocated region */
-};
+ /* The life of the structure allocation is determined by this reference
+ * count. This count is number of threads that shared the the same D-Space.
+ * This includes the parent task as well as any pthreads created by the
+ * parent task or any of its child threads.
+ */
-#define SIZEOF_DSPACE_S(n) (sizeof(struct dspace_s) - 1 + (n))
+ uint16_t crefs;
-/* This is the task control block (TCB) */
+ /* This is the allocated D-Space memory region. This may be a physical
+ * address allocated with kmalloc(), or it may be virtual address associated
+ * with an address environment (if CONFIG_ADDRENV=y).
+ */
+
+ FAR uint8_t *region;
+};
+#endif
+
+/* This is the task control block (TCB). Each task or thread is represented by
+ * a TCB. The TCB is the heart of the NuttX task-control logic.
+ */
struct _TCB
{
/* Fields used to support list management *************************************/
- FAR struct _TCB *flink; /* link in DQ of TCBs */
+ FAR struct _TCB *flink; /* Doubly linked list */
FAR struct _TCB *blink;
/* Task Management Fields *****************************************************/
@@ -189,7 +205,7 @@ struct _TCB
start_t start; /* Thread start function */
entry_t entry; /* Entry Point into the thread */
-#ifdef CONFIG_SCHED_ATEXIT
+#if defined(CONFIG_SCHED_ATEXIT) && !defined(CONFIG_SCHED_ONEXIT)
# if defined(CONFIG_SCHED_ATEXIT_MAX) && CONFIG_SCHED_ATEXIT_MAX > 1
atexitfunc_t atexitfunc[CONFIG_SCHED_ATEXIT_MAX];
# else
diff --git a/nuttx/include/nuttx/usb/cdcacm.h b/nuttx/include/nuttx/usb/cdcacm.h
index 307f2a597..1dca050c4 100644
--- a/nuttx/include/nuttx/usb/cdcacm.h
+++ b/nuttx/include/nuttx/usb/cdcacm.h
@@ -205,7 +205,7 @@
/* USB Controller */
#ifndef CONFIG_USBDEV_SELFPOWERED
-# define SELFPOWERED USB_CONFIG_ATT_SELFPOWER
+# define SELFPOWERED USB_CONFIG_ATTR_SELFPOWER
#else
# define SELFPOWERED (0)
#endif
diff --git a/nuttx/include/nuttx/usb/usbdev_trace.h b/nuttx/include/nuttx/usb/usbdev_trace.h
index ae8e13c3a..ab3a5f4be 100644
--- a/nuttx/include/nuttx/usb/usbdev_trace.h
+++ b/nuttx/include/nuttx/usb/usbdev_trace.h
@@ -238,10 +238,6 @@
#define USBCOMPOSITE_TRACEERR_ALLOCDEVSTRUCT 0x000a
#define USBCOMPOSITE_TRACEERR_CLASSOBJECT 0x000b
#define USBCOMPOSITE_TRACEERR_DEVREGISTER 0x000c
-#define USBCOMPOSITE_TRACEERR_INVALIDARG 0x000d
-#define USBCOMPOSITE_TRACEERR_INVALIDARG 0x000f
-#define USBCOMPOSITE_TRACEERR_INVALIDARG 0x0010
-#define USBCOMPOSITE_TRACEERR_INVALIDARG 0x0011
/* USB Storage driver class events ******************************************/
diff --git a/nuttx/include/nuttx/vt100.h b/nuttx/include/nuttx/vt100.h
index d834f48f0..32344a1de 100644
--- a/nuttx/include/nuttx/vt100.h
+++ b/nuttx/include/nuttx/vt100.h
@@ -179,8 +179,8 @@
#define VT52_CLEAREOL {ASCII_ESC, 'K'} /* Erase to end of current line */
#define VT52_CLEAREOS {ASCII_ESC, 'J'} /* Erase to end of screen */
-#define VT52_IDENT {ASCII_ESC, 'Z'} /* dentify what the terminal is */
-#define VT52_IDENTRESP {ASCII_ESC, '/', 'Z'} /* Correct response to ident */
+#define VT52_IDENT {ASCII_ESC, 'Z'} /* Identify what the terminal is */
+#define VT52_IDENTRESP {ASCII_ESC, '/', 'Z'} /* Correct response to ident */
/* VT100 Special Key Codes
*
diff --git a/nuttx/include/nuttx/wqueue.h b/nuttx/include/nuttx/wqueue.h
index 644585c56..c509bf197 100644
--- a/nuttx/include/nuttx/wqueue.h
+++ b/nuttx/include/nuttx/wqueue.h
@@ -109,17 +109,35 @@
# endif
#endif
-/* Work queue IDs (indices). These are both zero if there is only one work
- * queue.
+/* Work queue IDs (indices):
+ *
+ * Kernel Work Queues:
+ * HPWORK: This ID of the high priority work queue that should only be used for
+ * hi-priority, time-critical, driver bottom-half functions.
+ *
+ * LPWORK: This is the ID of the low priority work queue that can be used for any
+ * purpose. if CONFIG_SCHED_LPWORK is not defined, then there is only one kernel
+ * work queue and LPWORK == HPWORK.
+ *
+ * User Work Queue:
+ * USRWORK: CONFIG_NUTTX_KERNEL and CONFIG_SCHED_USRWORK are defined, then NuttX
+ * will also support a user-accessible work queue. Otherwise, USRWORK == LPWORK.
*/
#define HPWORK 0
#ifdef CONFIG_SCHED_LPWORK
-# define LPWORK 1
+# define LPWORK (HPWORK+1)
#else
# define LPWORK HPWORK
#endif
+#if defined(CONFIG_NUTTX_KERNEL) && defined(CONFIG_SCHED_USRWORK)
+# warning "Feature not implemented"
+# define USRWORK (LPWORK+1)
+#else
+# define USRWORK LPWORK
+#endif
+
/****************************************************************************
* Public Types
****************************************************************************/
diff --git a/nuttx/include/stdbool.h b/nuttx/include/stdbool.h
index f11219912..9c16aee29 100644
--- a/nuttx/include/stdbool.h
+++ b/nuttx/include/stdbool.h
@@ -42,10 +42,33 @@
#include <nuttx/config.h>
+/* If CONFIG_ARCH_STDBOOL_H is set, then the archecture will provide its own
+ * stdbool.h file. In this case, this header file will simply re-direct to
+ * the architecture-specfiic stdbool.h header file.
+ */
+
#ifdef CONFIG_ARCH_STDBOOL_H
# include <arch/stdbool.h>
+
+/* NuttX will insist that the sizeof(bool) is 8-bits. The sizeof of _Bool
+ * used by any specific compiler is implementation specific: It can vary from
+ * compiler-to-compiler and even vary between different versions of the same
+ * compiler. Compilers seems to be converging to sizeof(_Bool) == 1. If that
+ * is true for your compiler, you should define CONFIG_C99_BOOL8 in your NuttX
+ * configuration for better standards compatibility.
+ *
+ * CONFIG_C99_BOOL8 - Means (1) your C++ compiler has sizeof(_Bool) == 8,
+ * (2) your C compiler supports the C99 _Bool intrinsic type, and (2) that
+ * the C99 _Bool type also has size 1.
+ */
+
#else
+
+ /* nuttx/compiler.h may also define or undefine CONFIG_C99_BOOL8 */
+
# include <nuttx/compiler.h>
+
+#if !defined(__cplusplus) || !defined(CONFIG_C99_BOOL8)
# include <stdint.h>
/****************************************************************************
@@ -58,10 +81,15 @@
* NOTE: Under C99 'bool' is required to be defined to be the intrinsic type
* _Bool. However, in this NuttX context, we need backward compatibility
* to pre-C99 standards where _Bool is not an intrinsic type. Hence, we
- * use _Bool8 as the underlying type.
+ * use _Bool8 as the underlying type (unless CONFIG_C99_BOOL8 is defined)
*/
-#define bool _Bool8
+#ifdef CONFIG_C99_BOOL8
+# define bool _Bool
+#else
+# define bool _Bool8
+#endif
+
#define true 1
#define false 0
@@ -83,7 +111,10 @@
* as the underlying type.
*/
+#ifndef CONFIG_C99_BOOL8
typedef uint8_t _Bool8;
+#endif
+#endif /* __cplusplus && CONFIG_C99_BOOL8 */
#endif /* CONFIG_ARCH_STDBOOL_H */
#endif /* __INCLUDE_STDBOOL_H */
diff --git a/nuttx/include/stdio.h b/nuttx/include/stdio.h
index 754cedbb4..0441ea4b8 100644
--- a/nuttx/include/stdio.h
+++ b/nuttx/include/stdio.h
@@ -102,6 +102,9 @@ extern "C" {
/* ANSI-like File System Interfaces */
+/* Operations on streams (FILE) */
+
+EXTERN void clearerr(register FILE *stream);
EXTERN int fclose(FAR FILE *stream);
EXTERN int fflush(FAR FILE *stream);
EXTERN int feof(FAR FILE *stream);
@@ -120,6 +123,9 @@ EXTERN int fsetpos(FAR FILE *stream, FAR fpos_t *pos);
EXTERN long ftell(FAR FILE *stream);
EXTERN size_t fwrite(FAR const void *ptr, size_t size, size_t n_items, FAR FILE *stream);
EXTERN FAR char *gets(FAR char *s);
+EXTERN int ungetc(int c, FAR FILE *stream);
+
+/* Operations on the stdout stream, buffers, paths, and the whole printf-family */
EXTERN int printf(const char *format, ...);
EXTERN int puts(FAR const char *s);
@@ -130,7 +136,6 @@ EXTERN int snprintf(FAR char *buf, size_t size, const char *format, ...);
EXTERN int sscanf(const char *buf, const char *fmt, ...);
EXTERN void perror(FAR const char *s);
-EXTERN int ungetc(int c, FAR FILE *stream);
EXTERN int vprintf(FAR const char *format, va_list ap);
EXTERN int vfprintf(FAR FILE *stream, const char *format, va_list ap);
EXTERN int vdprintf(FAR int fd, const char *format, va_list ap);
diff --git a/nuttx/include/termios.h b/nuttx/include/termios.h
index c8f590a5b..3032e4746 100644
--- a/nuttx/include/termios.h
+++ b/nuttx/include/termios.h
@@ -98,20 +98,20 @@
/* Control Modes (c_cflag in the termios structure) */
-#define CSIZE (3 << 0) /* Bits 0-1: Character size: */
-# define CS5 (0 << 0) /* 5 bits */
-# define CS6 (1 << 0) /* 6 bits */
-# define CS7 (2 << 0) /* 7 bits */
-# define CS8 (3 << 0) /* 8 bits */
-#define CSTOPB (1 << 2) /* Bit 2: Send two stop bits, else one */
-#define CREAD (1 << 3) /* Bit 3: Enable receiver */
-#define PARENB (1 << 4) /* Bit 4: Parity enable */
-#define PARODD (1 << 5) /* Bit 5: Odd parity, else even */
-#define HUPCL (1 << 6) /* Bit 6: Hang up on last close */
-#define CLOCAL (1 << 7) /* Bit 7: Ignore modem status lines */
-#define CCTS_OFLOW (1 << 8) /* Bit 8: CTS flow control of output */
-#define CRTSCTS CCTS_OFLOW
-#define CRTS_IFLOW (1 << 9) /* Bit 9: RTS flow control of input */
+#define CSIZE (3 << 0) /* Bits 0-1: Character size: */
+# define CS5 (0 << 0) /* 5 bits */
+# define CS6 (1 << 0) /* 6 bits */
+# define CS7 (2 << 0) /* 7 bits */
+# define CS8 (3 << 0) /* 8 bits */
+#define CSTOPB (1 << 2) /* Bit 2: Send two stop bits, else one */
+#define CREAD (1 << 3) /* Bit 3: Enable receiver */
+#define PARENB (1 << 4) /* Bit 4: Parity enable */
+#define PARODD (1 << 5) /* Bit 5: Odd parity, else even */
+#define HUPCL (1 << 6) /* Bit 6: Hang up on last close */
+#define CLOCAL (1 << 7) /* Bit 7: Ignore modem status lines */
+#define CCTS_OFLOW (1 << 8) /* Bit 8: CTS flow control of output */
+#define CRTSCTS CCTS_OFLOW
+#define CRTS_IFLOW (1 << 9) /* Bit 9: RTS flow control of input */
/* Local Modes (c_lflag in the termios structure) */
@@ -232,7 +232,7 @@ struct termios
* cf[set|get][o|i]speed() POSIX interfaces.
*/
- speed_t c_speed; /* Input/output speed (non-POSIX)*/
+ speed_t c_speed; /* Input/output speed (non-POSIX)*/
};
/****************************************************************************
diff --git a/nuttx/include/unistd.h b/nuttx/include/unistd.h
index e2ad6ff82..681ce9e63 100644
--- a/nuttx/include/unistd.h
+++ b/nuttx/include/unistd.h
@@ -133,6 +133,7 @@ EXTERN pid_t getpid(void);
EXTERN void _exit(int status) noreturn_function;
EXTERN unsigned int sleep(unsigned int seconds);
EXTERN int usleep(useconds_t usec);
+EXTERN int pause(void);
/* File descriptor operations */
diff --git a/nuttx/lib/Makefile b/nuttx/lib/Makefile
index fc8f0c4dd..58857dbd4 100644
--- a/nuttx/lib/Makefile
+++ b/nuttx/lib/Makefile
@@ -1,7 +1,7 @@
############################################################################
# lib/Makefile
#
-# Copyright (C) 2007-2012 Gregory Nutt. All rights reserved.
+# Copyright (C) 2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
@@ -35,101 +35,11 @@
-include $(TOPDIR)/Make.defs
-ASRCS =
-CSRCS =
+all:
-DEPPATH := --dep-path .
-VPATH := .
+depend:
-include stdio/Make.defs
-include stdlib/Make.defs
-include unistd/Make.defs
-include sched/Make.defs
-include string/Make.defs
-include pthread/Make.defs
-include semaphore/Make.defs
-include signal/Make.defs
-include mqueue/Make.defs
-include math/Make.defs
-include net/Make.defs
-include time/Make.defs
-include libgen/Make.defs
-include dirent/Make.defs
-include termios/Make.defs
-include queue/Make.defs
-include misc/Make.defs
-
-AOBJS = $(ASRCS:.S=$(OBJEXT))
-COBJS = $(CSRCS:.c=$(OBJEXT))
-
-SRCS = $(ASRCS) $(CSRCS)
-OBJS = $(AOBJS) $(COBJS)
-
-UBIN = libulib$(LIBEXT)
-KBIN = libklib$(LIBEXT)
-BIN = liblib$(LIBEXT)
-
-all: $(BIN)
-
-$(AOBJS): %$(OBJEXT): %.S
- $(call ASSEMBLE, $<, $@)
-
-$(COBJS): %$(OBJEXT): %.c
- $(call COMPILE, $<, $@)
-
-$(BIN): $(OBJS)
- @( for obj in $(OBJS) ; do \
- $(call ARCHIVE, $@, $${obj}); \
- done ; )
-
-ifneq ($(BIN),$(UBIN))
-.userlib:
- @$(MAKE) $(UBIN) BIN=$(UBIN) TOPDIR=$(TOPDIR) EXTRADEFINES=$(EXTRADEFINES)
- @touch .userlib
-
-$(UBIN): kclean .userlib
-endif
-
-ifneq ($(BIN),$(KBIN))
-.kernlib:
- @$(MAKE) $(KBIN) BIN=$(KBIN) TOPDIR=$(TOPDIR) EXTRADEFINES=$(EXTRADEFINES)
- @touch .kernlib
-
-$(KBIN): uclean .kernlib
-endif
-
-.depend: Makefile $(SRCS)
- @$(MKDEP) $(DEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
- @touch $@
-
-depend: .depend
-
-# Clean Targets:
-# Clean user-mode temporary files (retaining the UBIN binary)
-
-uclean:
-ifneq ($(OBJEXT),)
- @( if [ -f .userlib ]; then rm -f *$(OBJEXT); fi )
-endif
- @rm -f .userlib *~ .*.swp
-
-# Clean kernel-mode temporary files (retaining the KBIN binary)
-
-kclean:
-ifneq ($(OBJEXT),)
- @( if [ -f .kernlib ]; then rm -f *$(OBJEXT); fi )
-endif
- @rm -f .kernlib *~ .*.swp
-
-# Really clean everything
-
-clean: uclean kclean
- @rm -f $(BIN) $(UBIN) $(KBIN) *~ .*.swp
+clean:
$(call CLEAN)
-# Deep clean -- removes all traces of the configuration
-
distclean: clean
- @rm -f Make.dep .depend
-
--include Make.dep
diff --git a/nuttx/lib/README.txt b/nuttx/lib/README.txt
index 63d1c343c..f742b9a24 100644
--- a/nuttx/lib/README.txt
+++ b/nuttx/lib/README.txt
@@ -1,84 +1,6 @@
-lib
-===
-
-This directory contains numerous, small functions typically associated with
-what you would expect to find in a standard C library. The sub-directories
-in this directory contain standard interface that can be executed by user-
-mode programs.
-
-Normally, NuttX is built with no protection and all threads running in kerne-
-mode. In that model, there is no real architectural distinction between
-what is a kernel-mode program and what is a user-mode program; the system is
-more like on multi-threaded program that all runs in kernel-mode.
-
-But if the CONFIG_NUTTX_KERNEL option is selected, NuttX will be built into
-distinct user-mode and kernel-mode sections. In that case, most of the
-code in the nuttx/ directory will run in kernel-mode with with exceptions
-of (1) the user-mode "proxies" found in syscall/proxies, and (2) the
-standard C library functions found in this directory. In this build model,
-it is critical to separate the user-mode OS interfaces in this way.
-
-Sub-Directories
-===============
-
-The files in the lib/ directory are organized (mostly) according which file
-in the include/ directory provides the prototype for library functions. So
-we have:
-
- libgen - libgen.h
- math - math.h and fixedmath.h
- mqueue - pthread.h
- net - Various network-related header files: netinet/ether.h, arpa/inet.h
- pthread - pthread.h
- queue - queue.h
- sched - sched.h
- semaphore - semaphore.h
- stdio - stdio.h
- stdlib - stdlib.h
- string - string.h
- time - time.h
- unistd - unistd.h
-
-There is also a misc/ subdirectory that contains various internal functions
-and interfaces from header files that are too few to warrant their own sub-
-directory:
-
- misc - Nonstandard "glue" logic, debug.h, crc32.h, dirent.h
-
-Library Database
+lib/ README File
================
-Information about functions available in the NuttX C library information is
-maintained in a database. That "database" is implemented as a simple comma-
-separated-value file, lib.csv. Most spreadsheets programs will accept this
-format and can be used to maintain the library database.
-
-This library database will (eventually) be used to generate symbol library
-symbol table information that can be exported to external applications.
-
-The format of the CSV file for each line is:
-
- Field 1: Function name
- Field 2: The header file that contains the function prototype
- Field 3: Condition for compilation
- Field 4: The type of function return value.
- Field 5 - N+5: The type of each of the N formal parameters of the function
-
-Each type field has a format as follows:
+This directory is reserved for libraries generated during the NuttX build process
- type name:
- For all simpler types
- formal type | actual type:
- For array types where the form of the formal (eg. int parm[2])
- differs from the type of actual passed parameter (eg. int*). This
- is necessary because you cannot do simple casts to array types.
- formal type | union member actual type | union member fieldname:
- A similar situation exists for unions. For example, the formal
- parameter type union sigval -- You cannot cast a uintptr_t to
- a union sigval, but you can cast to the type of one of the union
- member types when passing the actual paramter. Similarly, we
- cannot cast a union sigval to a uinptr_t either. Rather, we need
- to cast a specific union member fieldname to uintptr_t.
-NOTE: The tool mksymtab can be used to generate a symbol table from this CSV
-file. See nuttx/tools/README.txt for further details about the use of mksymtab.
diff --git a/nuttx/lib/stdlib/lib_rand.c b/nuttx/lib/stdlib/lib_rand.c
deleted file mode 100644
index 7227c52d0..000000000
--- a/nuttx/lib/stdlib/lib_rand.c
+++ /dev/null
@@ -1,220 +0,0 @@
-/************************************************************
- * lib/stdlib/lib_rand.c
- *
- * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <gnutt@nuttx.org>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name NuttX nor the names of its contributors may be
- * used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- ************************************************************/
-
-/************************************************************
- * Compilation Switches
- ************************************************************/
-
-/************************************************************
- * Included Files
- ************************************************************/
-
-#include <sys/types.h>
-#include <stdlib.h>
-
-/************************************************************
- * Definitions
- ************************************************************/
-
-#ifndef CONFIG_LIB_RAND_ORDER
-#define CONFIG_LIB_RAND_ORDER 1
-#endif
-
-/* Values needed by the random number generator */
-
-#define RND1_CONSTK 470001
-#define RND1_CONSTP 999563
-#define RND2_CONSTK1 366528
-#define RND2_CONSTK2 508531
-#define RND2_CONSTP 998917
-#define RND3_CONSTK1 360137
-#define RND3_CONSTK2 519815
-#define RND3_CONSTK3 616087
-#define RND3_CONSTP 997783
-
-#if CONFIG_LIB_RAND_ORDER == 1
-# define RND_CONSTP RND1_CONSTP
-#elif CONFIG_LIB_RAND_ORDER == 2
-# define RND_CONSTP RND2_CONSTP
-#else
-# define RND_CONSTP RND3_CONSTP
-#endif
-
-/************************************************************
- * Private Type Declarations
- ************************************************************/
-
-/************************************************************
- * Private Function Prototypes
- ************************************************************/
-
-static unsigned int nrand(unsigned int nLimit);
-static double_t frand1(void);
-#if (CONFIG_LIB_RAND_ORDER > 1)
-static double_t frand2(void);
-#if (CONFIG_LIB_RAND_ORDER > 2)
-static double_t frand3(void);
-#endif
-#endif
-
-/**********************************************************
- * Global Constant Data
- **********************************************************/
-
-/************************************************************
- * Global Variables
- ************************************************************/
-
-/**********************************************************
- * Private Constant Data
- **********************************************************/
-
-/************************************************************
- * Private Variables
- ************************************************************/
-
-static unsigned long g_nRandInt1;
-#if (CONFIG_LIB_RAND_ORDER > 1)
-static unsigned long g_nRandInt2;
-#if (CONFIG_LIB_RAND_ORDER > 2)
-static unsigned long g_nRandInt3;
-#endif
-#endif
-
-/************************************************************
- * Private Functions
- ************************************************************/
-
-static unsigned int nrand(unsigned int nLimit)
-{
- unsigned long nResult;
- double_t fRatio;
-
- /* Loop to be sure a legal random number is generated */
- do {
-
- /* Get a random integer in the requested range */
-#if (CONFIG_LIB_RAND_ORDER == 1)
- fRatio = frand1();
-#elif (CONFIG_LIB_RAND_ORDER == 2)
- fRatio = frand2();
-#else
- fRatio = frand3();
-#endif
-
- /* Then, produce the return-able value */
- nResult = (unsigned long)(((double_t)nLimit) * fRatio);
-
- } while (nResult >= (unsigned long)nLimit);
-
- return (unsigned int)nResult;
-
-} /* end nrand */
-
-static double_t frand1(void)
-{
- unsigned long nRandInt;
-
- /* First order congruential generator */
- nRandInt = (RND1_CONSTK * g_nRandInt1) % RND1_CONSTP;
- g_nRandInt1 = nRandInt;
-
- /* Construct an floating point value in the range from 0.0 up to 1.0 */
- return ((double_t)nRandInt) / ((double_t)RND_CONSTP);
-
-} /* end frand */
-
-#if (CONFIG_LIB_RAND_ORDER > 1)
-static double_t frand2(void)
-{
- unsigned long nRandInt;
-
- /* Second order congruential generator */
- nRandInt = (RND2_CONSTK1 * g_nRandInt1 + RND2_CONSTK2 * g_nRandInt2) %
- RND2_CONSTP;
- g_nRandInt2 = g_nRandInt1;
- g_nRandInt1 = nRandInt;
-
- /* Construct an floating point value in the range from 0.0 up to 1.0 */
- return ((double_t)nRandInt) / ((double_t)RND_CONSTP);
-
-} /* end frand */
-
-#if (CONFIG_LIB_RAND_ORDER > 2)
-static double_t frand3(void)
-{
- unsigned long nRandInt;
-
- /* Third order congruential generator */
- nRandInt = (RND3_CONSTK1 * g_nRandInt1 + RND3_CONSTK2 * g_nRandInt2 +
- RND3_CONSTK2 * g_nRandInt3) % RND3_CONSTP;
- g_nRandInt3 = g_nRandInt2;
- g_nRandInt2 = g_nRandInt1;
- g_nRandInt1 = nRandInt;
-
- /* Construct an floating point value in the range from 0.0 up to 1.0 */
- return ((double_t)nRandInt) / ((double_t)RND_CONSTP);
-
-} /* end frand */
-#endif
-#endif
-
-/************************************************************
- * Public Functions
- ************************************************************/
-/************************************************************
- * Function: srand, rand
- ************************************************************/
-
-void srand(unsigned int seed)
-{
- g_nRandInt1 = seed;
-#if (CONFIG_LIB_RAND_ORDER > 1)
- g_nRandInt2 = seed;
- (void)frand1();
-#if (CONFIG_LIB_RAND_ORDER > 2)
- g_nRandInt3 = seed;
- (void)frand2();
-#endif
-#endif
-
-} /* end srand */
-
-int rand(void)
-{
- return (int)nrand(32768);
-
-} /* end rand */
-
diff --git a/nuttx/lib/Kconfig b/nuttx/libc/Kconfig
index 69a55d09c..bd470be7f 100644
--- a/nuttx/lib/Kconfig
+++ b/nuttx/libc/Kconfig
@@ -30,12 +30,7 @@ config LIB_HOMEDIR
---help---
The home directory to use with operations like such as 'cd ~'
-config HAVE_LIBM
- bool "Architecture-specific libm.a"
- default n
- ---help---
- Architecture specific logic provides an implementation of libm.a
- and a math.h header file that can be found at include/arch/math.h.
+source libc/math/Kconfig
config NOPRINTF_FIELDWIDTH
bool "Disable sprintf support fieldwidth"
@@ -153,42 +148,128 @@ config ARCH_OPTIMIZED_FUNCTIONS
if ARCH_OPTIMIZED_FUNCTIONS
config ARCH_MEMCPY
- bool "memcpy"
+ bool "memcpy()"
+ default n
+ ---help---
+ Select this option if the architecture provides an optimized version
+ of memcpy().
+
+config MEMCPY_VIK
+ bool "Vik memcpy()"
default n
+ depends on !ARCH_MEMCPY
+ ---help---
+ Select this option to use the optimized memcpy() function by Daniel Vik.
+ Select this option for improved performance at the expense of increased
+ size. See licensing information in the top-level COPYING file.
+
+if MEMCPY_VIK
+config MEMCPY_PRE_INC_PTRS
+ bool "Pre-increment pointers"
+ default n
+ ---help---
+ Use pre-increment of pointers. Default is post increment of pointers.
+
+config MEMCPY_INDEXED_COPY
+ bool "Array indexing"
+ default y
+ ---help---
+ Copying data using array indexing. Using this option, disables the
+ MEMCPY_PRE_INC_PTRS option.
+
+config MEMCPY_64BIT
+ bool "64-bit memcpy()"
+ default n
+ ---help---
+ Compiles memcpy() for architectures that suppport 64-bit operations
+ efficiently.
+
+endif
config ARCH_MEMCMP
- bool "memcmp"
+ bool "memcmp()"
default n
+ ---help---
+ Select this option if the architecture provides an optimized version
+ of memcmp().
config ARCH_MEMMOVE
- bool "memmove"
+ bool "memmove()"
default n
+ ---help---
+ Select this option if the architecture provides an optimized version
+ of memmove().
config ARCH_MEMSET
- bool "memset"
+ bool "memset()"
default n
+ ---help---
+ Select this option if the architecture provides an optimized version
+ of memset().
+
+config MEMSET_OPTSPEED
+ bool "Optimize memset() for speed"
+ default n
+ depends on !ARCH_MEMSET
+ ---help---
+ Select this option to use a version of memcpy() optimized for speed.
+ Default: memcpy() is optimized for size.
+
+config MEMSET_64BIT
+ bool "64-bit memset()"
+ default n
+ depends on MEMSET_OPTSPEED
+ ---help---
+ Compiles memset() for architectures that suppport 64-bit operations
+ efficiently.
+
+config ARCH_STRCHR
+ bool "strchr()"
+ default n
+ ---help---
+ Select this option if the architecture provides an optimized version
+ of strchr().
config ARCH_STRCMP
- bool "strcmp"
+ bool "strcmp()"
default n
+ ---help---
+ Select this option if the architecture provides an optimized version
+ of strcmp().
config ARCH_STRCPY
- bool "strcpy"
+ bool "strcpy()"
default n
+ ---help---
+ Select this option if the architecture provides an optimized version
+ of strcpy().
config ARCH_STRNCPY
- bool "strncpy"
+ bool "strncpy()"
default n
+ ---help---
+ Select this option if the architecture provides an optimized version
+ of strncpy().
config ARCH_STRLEN
bool "strlen"
default n
+ ---help---
+ Select this option if the architecture provides an optimized version
+ of strlen().
config ARCH_STRNLEN
- bool "strlen"
+ bool "strlen()"
default n
+ ---help---
+ Select this option if the architecture provides an optimized version
+ of strnlen().
config ARCH_BZERO
- bool "bzero"
+ bool "bzero()"
default n
+ ---help---
+ Select this option if the architecture provides an optimized version
+ of bzero().
+
endif
diff --git a/nuttx/libc/Makefile b/nuttx/libc/Makefile
new file mode 100644
index 000000000..22dbba1d9
--- /dev/null
+++ b/nuttx/libc/Makefile
@@ -0,0 +1,145 @@
+############################################################################
+# libc/Makefile
+#
+# Copyright (C) 2007-2012 Gregory Nutt. All rights reserved.
+# Author: Gregory Nutt <gnutt@nuttx.org>
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in
+# the documentation and/or other materials provided with the
+# distribution.
+# 3. Neither the name NuttX nor the names of its contributors may be
+# used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+###########################################################################
+
+-include $(TOPDIR)/Make.defs
+
+ASRCS =
+CSRCS =
+
+DEPPATH := --dep-path .
+VPATH := .
+
+include stdio/Make.defs
+include stdlib/Make.defs
+include unistd/Make.defs
+include sched/Make.defs
+include string/Make.defs
+include pthread/Make.defs
+include semaphore/Make.defs
+include signal/Make.defs
+include mqueue/Make.defs
+include math/Make.defs
+include fixedmath/Make.defs
+include net/Make.defs
+include time/Make.defs
+include libgen/Make.defs
+include dirent/Make.defs
+include termios/Make.defs
+include queue/Make.defs
+include misc/Make.defs
+
+AOBJS = $(ASRCS:.S=$(OBJEXT))
+COBJS = $(CSRCS:.c=$(OBJEXT))
+
+SRCS = $(ASRCS) $(CSRCS)
+OBJS = $(AOBJS) $(COBJS)
+
+UBIN = libuc$(LIBEXT)
+KBIN = libkc$(LIBEXT)
+BIN = libc$(LIBEXT)
+
+all: $(BIN)
+
+$(AOBJS): %$(OBJEXT): %.S
+ $(call ASSEMBLE, $<, $@)
+
+$(COBJS): %$(OBJEXT): %.c
+ $(call COMPILE, $<, $@)
+
+$(BIN): $(OBJS)
+ $(call ARCHIVE, $@, $(OBJS))
+
+ifneq ($(BIN),$(UBIN))
+.userlib:
+ $(Q) $(MAKE) $(UBIN) BIN=$(UBIN) TOPDIR=$(TOPDIR) EXTRADEFINES=$(EXTRADEFINES)
+ $(Q) touch .userlib
+
+$(UBIN): kclean .userlib
+endif
+
+ifneq ($(BIN),$(KBIN))
+.kernlib:
+ $(Q) $(MAKE) $(KBIN) BIN=$(KBIN) TOPDIR=$(TOPDIR) EXTRADEFINES=$(EXTRADEFINES)
+ $(Q) touch .kernlib
+
+$(KBIN): uclean .kernlib
+endif
+
+.depend: Makefile $(SRCS)
+ $(Q) $(MKDEP) $(DEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
+ $(Q) touch $@
+
+depend: .depend
+
+# Clean Targets:
+# Clean user-mode temporary files (retaining the UBIN binary)
+
+uclean:
+ifneq ($(OBJEXT),)
+ifeq ($(CONFIG_WINDOWS_NATIVE),y)
+ $(Q) if exist .userlib ]; then del *$(OBJEXT)
+else
+ $(Q) ( if [ -f .userlib ]; then rm -f *$(OBJEXT); fi )
+endif
+endif
+ $(call DELFILE, .userlib)
+
+# Clean kernel-mode temporary files (retaining the KBIN binary)
+
+kclean:
+ifneq ($(OBJEXT),)
+ifeq ($(CONFIG_WINDOWS_NATIVE),y)
+ $(Q) if exist .kernlib ]; then del *$(OBJEXT)
+else
+ $(Q) ( if [ -f .kernlib ]; then rm -f *$(OBJEXT); fi )
+endif
+endif
+ $(call DELFILE, .kernlib)
+
+# Really clean everything
+
+clean: uclean kclean
+ $(call DELFILE, $(BIN))
+ $(call DELFILE, $(UBIN))
+ $(call DELFILE, $(KBIN))
+ $(call CLEAN)
+
+# Deep clean -- removes all traces of the configuration
+
+distclean: clean
+ $(call DELFILE, Make.dep)
+ $(call DELFILE, .depend)
+
+-include Make.dep
diff --git a/nuttx/libc/README.txt b/nuttx/libc/README.txt
new file mode 100644
index 000000000..ed672d038
--- /dev/null
+++ b/nuttx/libc/README.txt
@@ -0,0 +1,85 @@
+lib
+===
+
+This directory contains numerous, small functions typically associated with
+what you would expect to find in a standard C library. The sub-directories
+in this directory contain standard interface that can be executed by user-
+mode programs.
+
+Normally, NuttX is built with no protection and all threads running in kerne-
+mode. In that model, there is no real architectural distinction between
+what is a kernel-mode program and what is a user-mode program; the system is
+more like on multi-threaded program that all runs in kernel-mode.
+
+But if the CONFIG_NUTTX_KERNEL option is selected, NuttX will be built into
+distinct user-mode and kernel-mode sections. In that case, most of the
+code in the nuttx/ directory will run in kernel-mode with with exceptions
+of (1) the user-mode "proxies" found in syscall/proxies, and (2) the
+standard C library functions found in this directory. In this build model,
+it is critical to separate the user-mode OS interfaces in this way.
+
+Sub-Directories
+===============
+
+The files in the libc/ directory are organized (mostly) according which file
+in the include/ directory provides the prototype for library functions. So
+we have:
+
+ libgen - libgen.h
+ fixedmath - fixedmath.h
+ math - math.h
+ mqueue - pthread.h
+ net - Various network-related header files: netinet/ether.h, arpa/inet.h
+ pthread - pthread.h
+ queue - queue.h
+ sched - sched.h
+ semaphore - semaphore.h
+ stdio - stdio.h
+ stdlib - stdlib.h
+ string - string.h
+ time - time.h
+ unistd - unistd.h
+
+There is also a misc/ subdirectory that contains various internal functions
+and interfaces from header files that are too few to warrant their own sub-
+directory:
+
+ misc - Nonstandard "glue" logic, debug.h, crc32.h, dirent.h
+
+Library Database
+================
+
+Information about functions available in the NuttX C library information is
+maintained in a database. That "database" is implemented as a simple comma-
+separated-value file, lib.csv. Most spreadsheets programs will accept this
+format and can be used to maintain the library database.
+
+This library database will (eventually) be used to generate symbol library
+symbol table information that can be exported to external applications.
+
+The format of the CSV file for each line is:
+
+ Field 1: Function name
+ Field 2: The header file that contains the function prototype
+ Field 3: Condition for compilation
+ Field 4: The type of function return value.
+ Field 5 - N+5: The type of each of the N formal parameters of the function
+
+Each type field has a format as follows:
+
+ type name:
+ For all simpler types
+ formal type | actual type:
+ For array types where the form of the formal (eg. int parm[2])
+ differs from the type of actual passed parameter (eg. int*). This
+ is necessary because you cannot do simple casts to array types.
+ formal type | union member actual type | union member fieldname:
+ A similar situation exists for unions. For example, the formal
+ parameter type union sigval -- You cannot cast a uintptr_t to
+ a union sigval, but you can cast to the type of one of the union
+ member types when passing the actual paramter. Similarly, we
+ cannot cast a union sigval to a uinptr_t either. Rather, we need
+ to cast a specific union member fieldname to uintptr_t.
+
+NOTE: The tool mksymtab can be used to generate a symbol table from this CSV
+file. See nuttx/tools/README.txt for further details about the use of mksymtab.
diff --git a/nuttx/lib/dirent/Make.defs b/nuttx/libc/dirent/Make.defs
index cc1d6b783..f2927bed8 100644
--- a/nuttx/lib/dirent/Make.defs
+++ b/nuttx/libc/dirent/Make.defs
@@ -1,5 +1,5 @@
############################################################################
-# lib/dirent/Make.defs
+# libc/dirent/Make.defs
#
# Copyright (C) 2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/dirent/lib_readdirr.c b/nuttx/libc/dirent/lib_readdirr.c
index 47c5b9a7b..93c99ac28 100644
--- a/nuttx/lib/dirent/lib_readdirr.c
+++ b/nuttx/libc/dirent/lib_readdirr.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/dirent/lib_readdirr.c
+ * libc/dirent/lib_readdirr.c
*
* Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/dirent/lib_telldir.c b/nuttx/libc/dirent/lib_telldir.c
index 3753b326e..f77a4a1c2 100644
--- a/nuttx/lib/dirent/lib_telldir.c
+++ b/nuttx/libc/dirent/lib_telldir.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/dirent/fs_telldir.c
+ * libc/dirent/fs_telldir.c
*
* Copyright (C) 2007-2008, 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/math/Make.defs b/nuttx/libc/fixedmath/Make.defs
index 126cd2f47..b53df2b2c 100644
--- a/nuttx/lib/math/Make.defs
+++ b/nuttx/libc/fixedmath/Make.defs
@@ -1,5 +1,5 @@
############################################################################
-# lib/math/Make.defs
+# libc/fixedmath/Make.defs
#
# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
@@ -33,11 +33,11 @@
#
############################################################################
-# Add the math C files to the build
+# Add the fixed precision math C files to the build
CSRCS += lib_rint.c lib_fixedmath.c lib_b16sin.c lib_b16cos.c lib_b16atan2.c
-# Add the math directory to the build
+# Add the fixed precision math directory to the build
-DEPPATH += --dep-path math
-VPATH += :math
+DEPPATH += --dep-path fixedmath
+VPATH += :fixedmath
diff --git a/nuttx/lib/math/lib_b16atan2.c b/nuttx/libc/fixedmath/lib_b16atan2.c
index 8792fa087..443ab7be3 100644
--- a/nuttx/lib/math/lib_b16atan2.c
+++ b/nuttx/libc/fixedmath/lib_b16atan2.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/math/lib_b16atan2.c
+ * libc/fixedmath/lib_b16atan2.c
*
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/math/lib_b16cos.c b/nuttx/libc/fixedmath/lib_b16cos.c
index 7547871f6..0ebe48262 100644
--- a/nuttx/lib/math/lib_b16cos.c
+++ b/nuttx/libc/fixedmath/lib_b16cos.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/math/lib_b16cos.c
+ * libc/fixedmath/lib_b16cos.c
*
* Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/math/lib_b16sin.c b/nuttx/libc/fixedmath/lib_b16sin.c
index 1eee17993..9cd2f0da3 100644
--- a/nuttx/lib/math/lib_b16sin.c
+++ b/nuttx/libc/fixedmath/lib_b16sin.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/math/lib_b16sin.c
+ * libc/fixedmath/lib_b16sin.c
*
* Copyright (C) 2008, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/math/lib_fixedmath.c b/nuttx/libc/fixedmath/lib_fixedmath.c
index c1a710e73..9e9213b4f 100644
--- a/nuttx/lib/math/lib_fixedmath.c
+++ b/nuttx/libc/fixedmath/lib_fixedmath.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/math/lib_fixedmath.c
+ * libc/math/lib_fixedmath.c
*
* Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/math/lib_rint.c b/nuttx/libc/fixedmath/lib_rint.c
index bd861eced..a1212c970 100644
--- a/nuttx/lib/math/lib_rint.c
+++ b/nuttx/libc/fixedmath/lib_rint.c
@@ -1,5 +1,5 @@
/************************************************************
- * lib/math/lib_rint.c
+ * libc/fixedmath/lib_rint.c
*
* Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/lib.csv b/nuttx/libc/lib.csv
index 171f64e9b..171f64e9b 100644
--- a/nuttx/lib/lib.csv
+++ b/nuttx/libc/lib.csv
diff --git a/nuttx/lib/lib_internal.h b/nuttx/libc/lib_internal.h
index 49cba9996..c09c751d4 100644
--- a/nuttx/lib/lib_internal.h
+++ b/nuttx/libc/lib_internal.h
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/lib_internal.h
+ * libc/lib_internal.h
*
* Copyright (C) 2007-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
@@ -117,57 +117,56 @@ extern bool g_dbgenable;
/* Defined in lib_streamsem.c */
#if CONFIG_NFILE_STREAMS > 0
-extern void stream_semtake(FAR struct streamlist *list);
-extern void stream_semgive(FAR struct streamlist *list);
+void stream_semtake(FAR struct streamlist *list);
+void stream_semgive(FAR struct streamlist *list);
#endif
/* Defined in lib_libnoflush.c */
#ifdef CONFIG_STDIO_LINEBUFFER
-extern int lib_noflush(FAR struct lib_outstream_s *this);
+int lib_noflush(FAR struct lib_outstream_s *this);
#endif
/* Defined in lib_libsprintf.c */
-extern int lib_sprintf(FAR struct lib_outstream_s *obj,
+int lib_sprintf(FAR struct lib_outstream_s *obj,
const char *fmt, ...);
/* Defined lib_libvsprintf.c */
-extern int lib_vsprintf(FAR struct lib_outstream_s *obj,
- FAR const char *src, va_list ap);
+int lib_vsprintf(FAR struct lib_outstream_s *obj,
+ FAR const char *src, va_list ap);
/* Defined lib_rawprintf.c */
-extern int lib_rawvprintf(const char *src, va_list ap);
-extern int lib_rawvdprintf(int fd, const char *fmt, va_list ap);
+int lib_rawvprintf(const char *src, va_list ap);
/* Defined lib_lowprintf.c */
-extern int lib_lowvprintf(const char *src, va_list ap);
+int lib_lowvprintf(const char *src, va_list ap);
/* Defined in lib_dtoa.c */
#ifdef CONFIG_LIBC_FLOATINGPOINT
-extern char *__dtoa(double d, int mode, int ndigits,
- int *decpt, int *sign, char **rve);
+char *__dtoa(double d, int mode, int ndigits, int *decpt, int *sign,
+ char **rve);
#endif
/* Defined in lib_libwrite.c */
-extern ssize_t lib_fwrite(FAR const void *ptr, size_t count, FAR FILE *stream);
+ssize_t lib_fwrite(FAR const void *ptr, size_t count, FAR FILE *stream);
/* Defined in lib_libfread.c */
-extern ssize_t lib_fread(FAR void *ptr, size_t count, FAR FILE *stream);
+ssize_t lib_fread(FAR void *ptr, size_t count, FAR FILE *stream);
/* Defined in lib_libfflush.c */
-extern ssize_t lib_fflush(FAR FILE *stream, bool bforce);
+ssize_t lib_fflush(FAR FILE *stream, bool bforce);
/* Defined in lib_rdflush.c */
-extern int lib_rdflush(FAR FILE *stream);
+int lib_rdflush(FAR FILE *stream);
/* Defined in lib_wrflush.c */
@@ -176,25 +175,37 @@ int lib_wrflush(FAR FILE *stream);
/* Defined in lib_sem.c */
#if CONFIG_STDIO_BUFFER_SIZE > 0
-extern void lib_sem_initialize(FAR struct file_struct *stream);
-extern void lib_take_semaphore(FAR struct file_struct *stream);
-extern void lib_give_semaphore(FAR struct file_struct *stream);
+void lib_sem_initialize(FAR struct file_struct *stream);
+void lib_take_semaphore(FAR struct file_struct *stream);
+void lib_give_semaphore(FAR struct file_struct *stream);
#endif
/* Defined in lib_libgetbase.c */
-extern int lib_getbase(const char *nptr, const char **endptr);
+int lib_getbase(const char *nptr, const char **endptr);
/* Defined in lib_skipspace.c */
-extern void lib_skipspace(const char **pptr);
+void lib_skipspace(const char **pptr);
/* Defined in lib_isbasedigit.c */
-extern bool lib_isbasedigit(int ch, int base, int *value);
+bool lib_isbasedigit(int ch, int base, int *value);
/* Defined in lib_checkbase.c */
-extern int lib_checkbase(int base, const char **pptr);
+int lib_checkbase(int base, const char **pptr);
+
+/* Defined in lib_expi.c */
+
+#ifdef CONFIG_LIBM
+double lib_expi(size_t n);
+#endif
+
+/* Defined in lib_libsqrtapprox.c */
+
+#ifdef CONFIG_LIBM
+float lib_sqrtapprox(float x);
+#endif
#endif /* __LIB_LIB_INTERNAL_H */
diff --git a/nuttx/lib/libgen/Make.defs b/nuttx/libc/libgen/Make.defs
index f12645512..6e786655d 100644
--- a/nuttx/lib/libgen/Make.defs
+++ b/nuttx/libc/libgen/Make.defs
@@ -1,5 +1,5 @@
############################################################################
-# lib/libgen/Make.defs
+# libc/libgen/Make.defs
#
# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/libgen/lib_basename.c b/nuttx/libc/libgen/lib_basename.c
index 986c6b852..68188edbf 100644
--- a/nuttx/lib/libgen/lib_basename.c
+++ b/nuttx/libc/libgen/lib_basename.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/libgen/lib_basename.c
+ * libc/libgen/lib_basename.c
*
* Copyright (C) 2007, 2009, 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/libgen/lib_dirname.c b/nuttx/libc/libgen/lib_dirname.c
index 248293a60..6d076fd61 100644
--- a/nuttx/lib/libgen/lib_dirname.c
+++ b/nuttx/libc/libgen/lib_dirname.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/libgen/lib_dirname.c
+ * libc/libgen/lib_dirname.c
*
* Copyright (C) 2007, 2009, 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/libc/math/Kconfig b/nuttx/libc/math/Kconfig
new file mode 100644
index 000000000..c24bfd53f
--- /dev/null
+++ b/nuttx/libc/math/Kconfig
@@ -0,0 +1,26 @@
+#
+# For a description of the syntax of this configuration file,
+# see misc/tools/kconfig-language.txt.
+#
+
+config LIBM
+ bool "Math library"
+ default n
+ depends on !ARCH_MATH_H
+ ---help---
+ By default, no math library will be provided by NuttX. In this this case, it
+ is assumed that (1) no math library is required, or (2) you will be using the
+ math.h header file and the libm library provided by your toolchain.
+
+ This is may be a very good choice is possible because your toolchain may have
+ have a highly optimized version of libm.
+
+ Another possibility is that you have a custom, architecture-specific math
+ libary and that the corresponding math.h file resides at arch/<architecture>/include/math.h.
+ The option is selected via ARCH_MATH_H. If ARCH_MATH_H is selected,then the include/nuttx/math.h
+ header file will be copied to include/math.h where it can be used by your applications.
+
+ If ARCH_MATH_H is not defined, then this option can be selected to build a generic,
+ math library built into NuttX. This math library comes from the Rhombus OS and
+ was written by Nick Johnson. The Rhombus OS math library port was contributed by
+ Darcy Gong.
diff --git a/nuttx/libc/math/Make.defs b/nuttx/libc/math/Make.defs
new file mode 100644
index 000000000..ece25f4e5
--- /dev/null
+++ b/nuttx/libc/math/Make.defs
@@ -0,0 +1,62 @@
+############################################################################
+# libc/math/Make.defs
+#
+# Copyright (C) 2012 Gregory Nutt. All rights reserved.
+# Author: Gregory Nutt <gnutt@nuttx.org>
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in
+# the documentation and/or other materials provided with the
+# distribution.
+# 3. Neither the name NuttX nor the names of its contributors may be
+# used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+############################################################################
+
+ifeq ($(CONFIG_LIBM),y)
+
+# Add the floating point math C files to the build
+
+CSRCS += lib_acosf.c lib_asinf.c lib_atan2f.c lib_atanf.c lib_ceilf.c lib_cosf.c
+CSRCS += lib_coshf.c lib_expf.c lib_fabsf.c lib_floorf.c lib_fmodf.c lib_frexpf.c
+CSRCS += lib_ldexpf.c lib_logf.c lib_log10f.c lib_log2f.c lib_modff.c lib_powf.c
+CSRCS += lib_roundf.c lib_sinf.c lib_sinhf.c lib_sqrtf.c lib_tanf.c lib_tanhf.c
+
+CSRCS += lib_acos.c lib_asin.c lib_atan.c lib_atan2.c lib_ceil.c lib_cos.c
+CSRCS += lib_cosh.c lib_exp.c lib_fabs.c lib_floor.c lib_fmod.c lib_frexp.c
+CSRCS += lib_ldexp.c lib_log.c lib_log10.c lib_log2.c lib_modf.c lib_pow.c
+CSRCS += lib_round.c lib_sin.c lib_sinh.c lib_sqrt.c lib_tan.c lib_tanh.c
+
+CSRCS += lib_acosl.c lib_asinl.c lib_atan2l.c lib_atanl.c lib_ceill.c lib_cosl.c
+CSRCS += lib_coshl.c lib_expl.c lib_fabsl.c lib_floorl.c lib_fmodl.c lib_frexpl.c
+CSRCS += lib_ldexpl.c lib_logl.c lib_log10l.c lib_log2l.c lib_modfl.c lib_powl.c
+CSRCS += lib_roundl.c lib_sinl.c lib_sinhl.c lib_sqrtl.c lib_tanl.c lib_tanhl.c
+
+CSRCS += lib_libexpi.c lib_libsqrtapprox.c
+
+# Add the floating point math directory to the build
+
+DEPPATH += --dep-path math
+VPATH += :math
+
+endif
diff --git a/nuttx/libc/math/lib_acos.c b/nuttx/libc/math/lib_acos.c
new file mode 100644
index 000000000..147003237
--- /dev/null
+++ b/nuttx/libc/math/lib_acos.c
@@ -0,0 +1,46 @@
+/************************************************************************
+ * libc/math/lib_acos.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009, 2010 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <math.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+#ifdef CONFIG_HAVE_DOUBLE
+double acos(double x)
+{
+ return (M_PI_2 - asin(x));
+}
+#endif
diff --git a/nuttx/libc/math/lib_acosf.c b/nuttx/libc/math/lib_acosf.c
new file mode 100644
index 000000000..447b2767f
--- /dev/null
+++ b/nuttx/libc/math/lib_acosf.c
@@ -0,0 +1,41 @@
+/************************************************************************
+ * libc/math/lib_acosf.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009, 2010 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <math.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+float acosf(float x)
+{
+ return (M_PI_2 - asinf(x));
+}
diff --git a/nuttx/libc/math/lib_acosl.c b/nuttx/libc/math/lib_acosl.c
new file mode 100644
index 000000000..a0f226238
--- /dev/null
+++ b/nuttx/libc/math/lib_acosl.c
@@ -0,0 +1,46 @@
+/************************************************************************
+ * libc/math/lib_acos.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009, 2010 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <math.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double acosl(long double x)
+{
+ return (M_PI_2 - asinl(x));
+}
+#endif
diff --git a/nuttx/libc/math/lib_asin.c b/nuttx/libc/math/lib_asin.c
new file mode 100644
index 000000000..d9941a7e5
--- /dev/null
+++ b/nuttx/libc/math/lib_asin.c
@@ -0,0 +1,69 @@
+/************************************************************************
+ * libc/math/lib_sin.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <math.h>
+#include <float.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+#ifdef CONFIG_HAVE_DOUBLE
+double asin(double x)
+{
+ long double y, y_sin, y_cos;
+
+ y = 0;
+
+ while (1)
+ {
+ y_sin = sin(y);
+ y_cos = cos(y);
+
+ if (y > M_PI_2 || y < -M_PI_2)
+ {
+ y = fmod(y, M_PI);
+ }
+
+ if (y_sin + DBL_EPSILON >= x && y_sin - DBL_EPSILON <= x)
+ {
+ break;
+ }
+
+ y = y - (y_sin - x) / y_cos;
+ }
+
+ return y;
+}
+#endif
diff --git a/nuttx/libc/math/lib_asinf.c b/nuttx/libc/math/lib_asinf.c
new file mode 100644
index 000000000..57e518acb
--- /dev/null
+++ b/nuttx/libc/math/lib_asinf.c
@@ -0,0 +1,65 @@
+/************************************************************************
+ * libc/math/lib_sinf.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <math.h>
+#include <float.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+float asinf(float x)
+{
+ long double y, y_sin, y_cos;
+
+ y = 0;
+
+ while (1)
+ {
+ y_sin = sinf(y);
+ y_cos = cosf(y);
+
+ if (y > M_PI_2 || y < -M_PI_2)
+ {
+ y = fmodf(y, M_PI);
+ }
+
+ if (y_sin + FLT_EPSILON >= x && y_sin - FLT_EPSILON <= x)
+ {
+ break;
+ }
+
+ y = y - (y_sin - x) / y_cos;
+ }
+
+ return y;
+}
+
diff --git a/nuttx/libc/math/lib_asinl.c b/nuttx/libc/math/lib_asinl.c
new file mode 100644
index 000000000..19f284e53
--- /dev/null
+++ b/nuttx/libc/math/lib_asinl.c
@@ -0,0 +1,69 @@
+/************************************************************************
+ * libc/math/lib_sinl.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <math.h>
+#include <float.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double asinl(long double x)
+{
+ long double y, y_sin, y_cos;
+
+ y = 0;
+
+ while (1)
+ {
+ y_sin = sinl(y);
+ y_cos = cosl(y);
+
+ if (y > M_PI_2 || y < -M_PI_2)
+ {
+ y = fmodl(y, M_PI);
+ }
+
+ if (y_sin + LDBL_EPSILON >= x && y_sin - LDBL_EPSILON <= x)
+ {
+ break;
+ }
+
+ y = y - (y_sin - x) / y_cos;
+ }
+
+ return y;
+}
+#endif
diff --git a/nuttx/libc/math/lib_atan.c b/nuttx/libc/math/lib_atan.c
new file mode 100644
index 000000000..44d68ece2
--- /dev/null
+++ b/nuttx/libc/math/lib_atan.c
@@ -0,0 +1,48 @@
+/************************************************************************
+ * libc/math/lib_atan.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009, 2010 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <math.h>
+#include <stddef.h>
+#include <stdint.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+#ifdef CONFIG_HAVE_DOUBLE
+double atan(double x)
+{
+ return asin(x / sqrt(x * x + 1));
+}
+#endif
diff --git a/nuttx/libc/math/lib_atan2.c b/nuttx/libc/math/lib_atan2.c
new file mode 100644
index 000000000..6d7d2ad48
--- /dev/null
+++ b/nuttx/libc/math/lib_atan2.c
@@ -0,0 +1,86 @@
+/************************************************************************
+ * libc/math/lib_atan2.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <math.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+#ifdef CONFIG_HAVE_DOUBLE
+double atan2(double y, double x)
+{
+ if (y == 0.0)
+ {
+ if (x >= 0.0)
+ {
+ return 0.0;
+ }
+ else
+ {
+ return M_PI;
+ }
+ }
+ else if (y > 0.0)
+ {
+ if (x == 0.0)
+ {
+ return M_PI_2;
+ }
+ else if (x > 0.0)
+ {
+ return atan(y / x);
+ }
+ else
+ {
+ return M_PI - atan(y / x);
+ }
+ }
+ else
+ {
+ if (x == 0.0)
+ {
+ return M_PI + M_PI_2;
+ }
+ else if (x > 0.0)
+ {
+ return 2 * M_PI - atan(y / x);
+ }
+ else
+ {
+ return M_PI + atan(y / x);
+ }
+ }
+}
+#endif
diff --git a/nuttx/libc/math/lib_atan2f.c b/nuttx/libc/math/lib_atan2f.c
new file mode 100644
index 000000000..7ff9af130
--- /dev/null
+++ b/nuttx/libc/math/lib_atan2f.c
@@ -0,0 +1,81 @@
+/************************************************************************
+ * libc/math/lib_atan2f.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <math.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+float atan2f(float y, float x)
+{
+ if (y == 0.0)
+ {
+ if (x >= 0.0)
+ {
+ return 0.0;
+ }
+ else
+ {
+ return M_PI;
+ }
+ }
+ else if (y > 0.0)
+ {
+ if (x == 0.0)
+ {
+ return M_PI_2;
+ }
+ else if (x > 0.0)
+ {
+ return atanf(y / x);
+ }
+ else
+ {
+ return M_PI - atanf(y / x);
+ }
+ }
+ else
+ {
+ if (x == 0.0)
+ {
+ return M_PI + M_PI_2;
+ }
+ else if (x > 0.0)
+ {
+ return 2 * M_PI - atanf(y / x);
+ }
+ else
+ {
+ return M_PI + atanf(y / x);
+ }
+ }
+}
diff --git a/nuttx/libc/math/lib_atan2l.c b/nuttx/libc/math/lib_atan2l.c
new file mode 100644
index 000000000..48bfd06f3
--- /dev/null
+++ b/nuttx/libc/math/lib_atan2l.c
@@ -0,0 +1,87 @@
+/************************************************************************
+ * libc/math/lib_atan2l.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <math.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double atan2l(long double y, long double x)
+{
+
+ if (y == 0.0)
+ {
+ if (x >= 0.0)
+ {
+ return 0.0;
+ }
+ else
+ {
+ return M_PI;
+ }
+ }
+ else if (y > 0.0)
+ {
+ if (x == 0.0)
+ {
+ return M_PI_2;
+ }
+ else if (x > 0.0)
+ {
+ return atanl(y / x);
+ }
+ else
+ {
+ return M_PI - atanl(y / x);
+ }
+ }
+ else
+ {
+ if (x == 0.0)
+ {
+ return M_PI + M_PI_2;
+ }
+ else if (x > 0.0)
+ {
+ return 2 * M_PI - atanl(y / x);
+ }
+ else
+ {
+ return M_PI + atanl(y / x);
+ }
+ }
+}
+#endif
diff --git a/nuttx/libc/math/lib_atanf.c b/nuttx/libc/math/lib_atanf.c
new file mode 100644
index 000000000..a84605787
--- /dev/null
+++ b/nuttx/libc/math/lib_atanf.c
@@ -0,0 +1,43 @@
+/************************************************************************
+ * libc/math/lib_atanf.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009, 2010 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <math.h>
+#include <stddef.h>
+#include <stdint.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+float atanf(float x)
+{
+ return asinf(x / sqrtf(x * x + 1));
+}
diff --git a/nuttx/libc/math/lib_atanl.c b/nuttx/libc/math/lib_atanl.c
new file mode 100644
index 000000000..752d49307
--- /dev/null
+++ b/nuttx/libc/math/lib_atanl.c
@@ -0,0 +1,48 @@
+/************************************************************************
+ * libc/math/lib_atanl.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009, 2010 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <math.h>
+#include <stddef.h>
+#include <stdint.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double atanl(long double x)
+{
+ return asinl(x / sqrtl(x * x + 1));
+}
+#endif
diff --git a/nuttx/libc/math/lib_ceil.c b/nuttx/libc/math/lib_ceil.c
new file mode 100644
index 000000000..3c6678dc1
--- /dev/null
+++ b/nuttx/libc/math/lib_ceil.c
@@ -0,0 +1,52 @@
+/************************************************************************
+ * libc/math/lib_ceil.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <math.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+#ifdef CONFIG_HAVE_DOUBLE
+double ceil(double x)
+{
+ modf(x, &x);
+ if (x > 0.0)
+ {
+ x += 1.0;
+ }
+
+ return x;
+}
+#endif
diff --git a/nuttx/libc/math/lib_ceilf.c b/nuttx/libc/math/lib_ceilf.c
new file mode 100644
index 000000000..afbe2cf13
--- /dev/null
+++ b/nuttx/libc/math/lib_ceilf.c
@@ -0,0 +1,47 @@
+/************************************************************************
+ * libc/math/lib_ceilf.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <math.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+float ceilf(float x)
+{
+ modff(x, &x);
+ if (x > 0.0)
+ {
+ x += 1.0;
+ }
+
+ return x;
+}
diff --git a/nuttx/libc/math/lib_ceill.c b/nuttx/libc/math/lib_ceill.c
new file mode 100644
index 000000000..757016b53
--- /dev/null
+++ b/nuttx/libc/math/lib_ceill.c
@@ -0,0 +1,52 @@
+/************************************************************************
+ * libc/math/lib_ceil;.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <math.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double ceill(long double x)
+{
+ modfl(x, &x);
+ if (x > 0.0)
+ {
+ x += 1.0;
+ }
+
+ return x;
+}
+#endif
diff --git a/nuttx/libc/math/lib_cos.c b/nuttx/libc/math/lib_cos.c
new file mode 100644
index 000000000..4b4e1a20b
--- /dev/null
+++ b/nuttx/libc/math/lib_cos.c
@@ -0,0 +1,46 @@
+/************************************************************************
+ * libc/math/lib_cos.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <math.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+#ifdef CONFIG_HAVE_DOUBLE
+double cos(double x)
+{
+ return sin(x + M_PI_2);
+}
+#endif
diff --git a/nuttx/libc/math/lib_cosf.c b/nuttx/libc/math/lib_cosf.c
new file mode 100644
index 000000000..d9ac951f6
--- /dev/null
+++ b/nuttx/libc/math/lib_cosf.c
@@ -0,0 +1,41 @@
+/************************************************************************
+ * libc/math/lib_cosf.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <math.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+float cosf(float x)
+{
+ return sinf(x + M_PI_2);
+}
diff --git a/nuttx/libc/math/lib_cosh.c b/nuttx/libc/math/lib_cosh.c
new file mode 100644
index 000000000..3246ea5f9
--- /dev/null
+++ b/nuttx/libc/math/lib_cosh.c
@@ -0,0 +1,47 @@
+/************************************************************************
+ * libc/math/lib_cosh.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <math.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+#ifdef CONFIG_HAVE_DOUBLE
+double cosh(double x)
+{
+ x = exp(x);
+ return ((x + (1.0 / x)) / 2.0);
+}
+#endif
diff --git a/nuttx/libc/math/lib_coshf.c b/nuttx/libc/math/lib_coshf.c
new file mode 100644
index 000000000..f0c28ab2e
--- /dev/null
+++ b/nuttx/libc/math/lib_coshf.c
@@ -0,0 +1,42 @@
+/************************************************************************
+ * libc/math/lib_coshf.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <math.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+float coshf(float x)
+{
+ x = expf(x);
+ return ((x + (1.0 / x)) / 2.0);
+}
diff --git a/nuttx/libc/math/lib_coshl.c b/nuttx/libc/math/lib_coshl.c
new file mode 100644
index 000000000..957ec61a7
--- /dev/null
+++ b/nuttx/libc/math/lib_coshl.c
@@ -0,0 +1,47 @@
+/************************************************************************
+ * libc/math/lib_coshl.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <math.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double coshl(long double x)
+{
+ x = expl(x);
+ return ((x + (1.0 / x)) / 2.0);
+}
+#endif
diff --git a/nuttx/libc/math/lib_cosl.c b/nuttx/libc/math/lib_cosl.c
new file mode 100644
index 000000000..972d4aa9d
--- /dev/null
+++ b/nuttx/libc/math/lib_cosl.c
@@ -0,0 +1,46 @@
+/************************************************************************
+ * libc/math/lib_cosl.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <math.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double cosl(long double x)
+{
+ return sinl(x + M_PI_2);
+}
+#endif
diff --git a/nuttx/libc/math/lib_exp.c b/nuttx/libc/math/lib_exp.c
new file mode 100644
index 000000000..62494251d
--- /dev/null
+++ b/nuttx/libc/math/lib_exp.c
@@ -0,0 +1,126 @@
+/************************************************************************
+ * libc/math/lib_exp.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <sys/types.h>
+#include <math.h>
+
+#include "lib_internal.h"
+
+#ifdef CONFIG_HAVE_DOUBLE
+
+/************************************************************************
+ * Private Data
+ ************************************************************************/
+
+static double _dbl_inv_fact[] =
+{
+ 1.0 / 1.0, // 1 / 0!
+ 1.0 / 1.0, // 1 / 1!
+ 1.0 / 2.0, // 1 / 2!
+ 1.0 / 6.0, // 1 / 3!
+ 1.0 / 24.0, // 1 / 4!
+ 1.0 / 120.0, // 1 / 5!
+ 1.0 / 720.0, // 1 / 6!
+ 1.0 / 5040.0, // 1 / 7!
+ 1.0 / 40320.0, // 1 / 8!
+ 1.0 / 362880.0, // 1 / 9!
+ 1.0 / 3628800.0, // 1 / 10!
+ 1.0 / 39916800.0, // 1 / 11!
+ 1.0 / 479001600.0, // 1 / 12!
+ 1.0 / 6227020800.0, // 1 / 13!
+ 1.0 / 87178291200.0, // 1 / 14!
+ 1.0 / 1307674368000.0, // 1 / 15!
+ 1.0 / 20922789888000.0, // 1 / 16!
+ 1.0 / 355687428096000.0, // 1 / 17!
+ 1.0 / 6402373705728000.0, // 1 / 18!
+};
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+double exp(double x)
+{
+ size_t int_part;
+ bool invert;
+ double value;
+ double x0;
+ size_t i;
+
+ if (x == 0)
+ {
+ return 1;
+ }
+ else if (x < 0)
+ {
+ invert = true;
+ x = -x;
+ }
+ else
+ {
+ invert = false;
+ }
+
+ /* Extract integer component */
+
+ int_part = (size_t) x;
+
+ /* Set x to fractional component */
+
+ x -= (double)int_part;
+
+ /* Perform Taylor series approximation with nineteen terms */
+
+ value = 0.0;
+ x0 = 1.0;
+ for (i = 0; i < 19; i++)
+ {
+ value += x0 * _dbl_inv_fact[i];
+ x0 *= x;
+ }
+
+ /* Multiply by exp of the integer component */
+
+ value *= lib_expi(int_part);
+
+ if (invert)
+ {
+ return (1.0 / value);
+ }
+ else
+ {
+ return value;
+ }
+}
+#endif
diff --git a/nuttx/libc/math/lib_expf.c b/nuttx/libc/math/lib_expf.c
new file mode 100644
index 000000000..3e43c54a6
--- /dev/null
+++ b/nuttx/libc/math/lib_expf.c
@@ -0,0 +1,112 @@
+/************************************************************************
+ * libc/math/lib_expf.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <sys/types.h>
+#include <math.h>
+
+#include "lib_internal.h"
+
+/************************************************************************
+ * Private Data
+ ************************************************************************/
+
+static float _flt_inv_fact[] =
+{
+ 1.0 / 1.0, // 1/0!
+ 1.0 / 1.0, // 1/1!
+ 1.0 / 2.0, // 1/2!
+ 1.0 / 6.0, // 1/3!
+ 1.0 / 24.0, // 1/4!
+ 1.0 / 120.0, // 1/5!
+ 1.0 / 720.0, // 1/6!
+ 1.0 / 5040.0, // 1/7!
+ 1.0 / 40320.0, // 1/8!
+ 1.0 / 362880.0, // 1/9!
+ 1.0 / 3628800.0, // 1/10!
+};
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+float expf(float x)
+{
+ size_t int_part;
+ bool invert;
+ float value;
+ float x0;
+ size_t i;
+
+ if (x == 0)
+ {
+ return 1;
+ }
+ else if (x < 0)
+ {
+ invert = true;
+ x = -x;
+ }
+ else
+ {
+ invert = false;
+ }
+
+ /* Extract integer component */
+
+ int_part = (size_t) x;
+
+ /* set x to fractional component */
+
+ x -= (float)int_part;
+
+ /* Perform Taylor series approximation with eleven terms */
+
+ value = 0.0;
+ x0 = 1.0;
+ for (i = 0; i < 10; i++)
+ {
+ value += x0 * _flt_inv_fact[i];
+ x0 *= x;
+ }
+
+ /* Multiply by exp of the integer component */
+
+ value *= lib_expi(int_part);
+
+ if (invert)
+ {
+ return (1.0 / value);
+ }
+ else
+ {
+ return value;
+ }
+}
diff --git a/nuttx/libc/math/lib_expl.c b/nuttx/libc/math/lib_expl.c
new file mode 100644
index 000000000..231faa35f
--- /dev/null
+++ b/nuttx/libc/math/lib_expl.c
@@ -0,0 +1,126 @@
+/************************************************************************
+ * libc/math/lib_expl.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <sys/types.h>
+#include <math.h>
+
+#include "lib_internal.h"
+
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+
+/************************************************************************
+ * Private Data
+ ************************************************************************/
+
+static long double _ldbl_inv_fact[] =
+{
+ 1.0 / 1.0, // 1 / 0!
+ 1.0 / 1.0, // 1 / 1!
+ 1.0 / 2.0, // 1 / 2!
+ 1.0 / 6.0, // 1 / 3!
+ 1.0 / 24.0, // 1 / 4!
+ 1.0 / 120.0, // 1 / 5!
+ 1.0 / 720.0, // 1 / 6!
+ 1.0 / 5040.0, // 1 / 7!
+ 1.0 / 40320.0, // 1 / 8!
+ 1.0 / 362880.0, // 1 / 9!
+ 1.0 / 3628800.0, // 1 / 10!
+ 1.0 / 39916800.0, // 1 / 11!
+ 1.0 / 479001600.0, // 1 / 12!
+ 1.0 / 6227020800.0, // 1 / 13!
+ 1.0 / 87178291200.0, // 1 / 14!
+ 1.0 / 1307674368000.0, // 1 / 15!
+ 1.0 / 20922789888000.0, // 1 / 16!
+ 1.0 / 355687428096000.0, // 1 / 17!
+ 1.0 / 6402373705728000.0, // 1 / 18!
+};
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+long double expl(long double x)
+{
+ size_t int_part;
+ bool invert;
+ long double value;
+ long double x0;
+ size_t i;
+
+ if (x == 0)
+ {
+ return 1;
+ }
+ else if (x < 0)
+ {
+ invert = true;
+ x = -x;
+ }
+ else
+ {
+ invert = false;
+ }
+
+ /* Extract integer component */
+
+ int_part = (size_t) x;
+
+ /* Set x to fractional component */
+
+ x -= (long double)int_part;
+
+ /* Perform Taylor series approximation with nineteen terms */
+
+ value = 0.0;
+ x0 = 1.0;
+ for (i = 0; i < 19; i++)
+ {
+ value += x0 * _ldbl_inv_fact[i];
+ x0 *= x;
+ }
+
+ /* Multiply by exp of the integer component */
+
+ value *= lib_expi(int_part);
+
+ if (invert)
+ {
+ return (1.0 / value);
+ }
+ else
+ {
+ return value;
+ }
+}
+#endif
diff --git a/nuttx/libc/math/lib_fabs.c b/nuttx/libc/math/lib_fabs.c
new file mode 100644
index 000000000..774755087
--- /dev/null
+++ b/nuttx/libc/math/lib_fabs.c
@@ -0,0 +1,46 @@
+/************************************************************************
+ * libc/math/lib_fabs.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009, 2010 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <math.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+#ifdef CONFIG_HAVE_DOUBLE
+double fabs(double x)
+{
+ return ((x < 0) ? -x : x);
+}
+#endif
diff --git a/nuttx/libc/math/lib_fabsf.c b/nuttx/libc/math/lib_fabsf.c
new file mode 100644
index 000000000..4c8ebae62
--- /dev/null
+++ b/nuttx/libc/math/lib_fabsf.c
@@ -0,0 +1,41 @@
+/************************************************************************
+ * libc/math/lib_fabsf.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009, 2010 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <math.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+float fabsf(float x)
+{
+ return ((x < 0) ? -x : x);
+}
diff --git a/nuttx/libc/math/lib_fabsl.c b/nuttx/libc/math/lib_fabsl.c
new file mode 100644
index 000000000..96ac7d5db
--- /dev/null
+++ b/nuttx/libc/math/lib_fabsl.c
@@ -0,0 +1,46 @@
+/************************************************************************
+ * libc/math/lib_fabsl.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009, 2010 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <math.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double fabsl(long double x)
+{
+ return ((x < 0) ? -x : x);
+}
+#endif
diff --git a/nuttx/libc/math/lib_floor.c b/nuttx/libc/math/lib_floor.c
new file mode 100644
index 000000000..3330607ce
--- /dev/null
+++ b/nuttx/libc/math/lib_floor.c
@@ -0,0 +1,52 @@
+/************************************************************************
+ * libc/math/lib_floor.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <math.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+#ifdef CONFIG_HAVE_DOUBLE
+double floor(double x)
+{
+ modf(x, &x);
+ if (x < 0.0)
+ {
+ x -= 1.0;
+ }
+
+ return x;
+}
+#endif
diff --git a/nuttx/libc/math/lib_floorf.c b/nuttx/libc/math/lib_floorf.c
new file mode 100644
index 000000000..81483d4c9
--- /dev/null
+++ b/nuttx/libc/math/lib_floorf.c
@@ -0,0 +1,47 @@
+/************************************************************************
+ * libc/math/lib_floorf.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <math.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+float floorf(float x)
+{
+ modff(x, &x);
+ if (x < 0.0)
+ {
+ x -= 1.0;
+ }
+
+ return x;
+}
diff --git a/nuttx/libc/math/lib_floorl.c b/nuttx/libc/math/lib_floorl.c
new file mode 100644
index 000000000..0d9ec43b4
--- /dev/null
+++ b/nuttx/libc/math/lib_floorl.c
@@ -0,0 +1,52 @@
+/************************************************************************
+ * libc/math/lib_floorl.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <math.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double floorl(long double x)
+{
+ modfl(x, &x);
+ if (x < 0.0)
+ {
+ x -= 1.0;
+ }
+
+ return x;
+}
+#endif
diff --git a/nuttx/libc/math/lib_fmod.c b/nuttx/libc/math/lib_fmod.c
new file mode 100644
index 000000000..c66210cde
--- /dev/null
+++ b/nuttx/libc/math/lib_fmod.c
@@ -0,0 +1,52 @@
+/************************************************************************
+ * libc/math/lib_fmod.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <math.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+#ifdef CONFIG_HAVE_DOUBLE
+double fmod(double x, double div)
+{
+ double n0;
+
+ x /= div;
+ x = modf(x, &n0);
+ x *= div;
+
+ return x;
+}
+#endif
diff --git a/nuttx/libc/math/lib_fmodf.c b/nuttx/libc/math/lib_fmodf.c
new file mode 100644
index 000000000..d70bb791c
--- /dev/null
+++ b/nuttx/libc/math/lib_fmodf.c
@@ -0,0 +1,47 @@
+/************************************************************************
+ * libc/math/lib_fmodf.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <math.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+float fmodf(float x, float div)
+{
+ float n0;
+
+ x /= div;
+ x = modff(x, &n0);
+ x *= div;
+
+ return x;
+}
diff --git a/nuttx/libc/math/lib_fmodl.c b/nuttx/libc/math/lib_fmodl.c
new file mode 100644
index 000000000..1299bf6e8
--- /dev/null
+++ b/nuttx/libc/math/lib_fmodl.c
@@ -0,0 +1,52 @@
+/************************************************************************
+ * libc/math/lib_fmodl.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <math.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double fmodl(long double x, long double div)
+{
+ long double n0;
+
+ x /= div;
+ x = modfl(x, &n0);
+ x *= div;
+
+ return x;
+}
+#endif
diff --git a/nuttx/libc/math/lib_frexp.c b/nuttx/libc/math/lib_frexp.c
new file mode 100644
index 000000000..b9576dfd4
--- /dev/null
+++ b/nuttx/libc/math/lib_frexp.c
@@ -0,0 +1,47 @@
+/************************************************************************
+ * libc/math/lib_frexp.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <math.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+#ifdef CONFIG_HAVE_DOUBLE
+double frexp(double x, int *exponent)
+{
+ *exponent = (int)ceil(log2(x));
+ return x / ldexp(1.0, *exponent);
+}
+#endif
diff --git a/nuttx/libc/math/lib_frexpf.c b/nuttx/libc/math/lib_frexpf.c
new file mode 100644
index 000000000..d93ffb173
--- /dev/null
+++ b/nuttx/libc/math/lib_frexpf.c
@@ -0,0 +1,42 @@
+/************************************************************************
+ * libc/math/lib_frexpf.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <math.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+float frexpf(float x, int *exponent)
+{
+ *exponent = (int)ceilf(log2f(x));
+ return x / ldexpf(1.0, *exponent);
+}
diff --git a/nuttx/libc/math/lib_frexpl.c b/nuttx/libc/math/lib_frexpl.c
new file mode 100644
index 000000000..90993b137
--- /dev/null
+++ b/nuttx/libc/math/lib_frexpl.c
@@ -0,0 +1,47 @@
+/************************************************************************
+ * libc/math/lib_frexpl.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <math.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double frexpl(long double x, int *exponent)
+{
+ *exponent = (int)ceill(log2(x));
+ return x / ldexpl(1.0, *exponent);
+}
+#endif
diff --git a/nuttx/libc/math/lib_ldexp.c b/nuttx/libc/math/lib_ldexp.c
new file mode 100644
index 000000000..9b74d53d7
--- /dev/null
+++ b/nuttx/libc/math/lib_ldexp.c
@@ -0,0 +1,46 @@
+/************************************************************************
+ * libc/math/lib_ldexp.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <math.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+#ifdef CONFIG_HAVE_DOUBLE
+double ldexp(double x, int n)
+{
+ return (x * pow(2.0, (double)n));
+}
+#endif
diff --git a/nuttx/libc/math/lib_ldexpf.c b/nuttx/libc/math/lib_ldexpf.c
new file mode 100644
index 000000000..f3aaf555b
--- /dev/null
+++ b/nuttx/libc/math/lib_ldexpf.c
@@ -0,0 +1,41 @@
+/************************************************************************
+ * libc/math/lib_ldexpf.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <math.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+float ldexpf(float x, int n)
+{
+ return (x * powf(2.0, (float)n));
+}
diff --git a/nuttx/libc/math/lib_ldexpl.c b/nuttx/libc/math/lib_ldexpl.c
new file mode 100644
index 000000000..29764aaba
--- /dev/null
+++ b/nuttx/libc/math/lib_ldexpl.c
@@ -0,0 +1,46 @@
+/************************************************************************
+ * libc/math/lib_ldexpl.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <math.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double ldexpl(long double x, int n)
+{
+ return (x * powl(2.0, (long double)n));
+}
+#endif
diff --git a/nuttx/libc/math/lib_libexpi.c b/nuttx/libc/math/lib_libexpi.c
new file mode 100644
index 000000000..33ba537b1
--- /dev/null
+++ b/nuttx/libc/math/lib_libexpi.c
@@ -0,0 +1,103 @@
+/************************************************************************
+ * libc/math/lib_libexpi.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <sys/types.h>
+#include <math.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+/************************************************************************
+ * Pre-processor Definitions
+ ************************************************************************/
+
+#define M_E2 (M_E * M_E)
+#define M_E4 (M_E2 * M_E2)
+#define M_E8 (M_E4 * M_E4)
+#define M_E16 (M_E8 * M_E8)
+#define M_E32 (M_E16 * M_E16)
+#define M_E64 (M_E32 * M_E32)
+#define M_E128 (M_E64 * M_E64)
+#define M_E256 (M_E128 * M_E128)
+#define M_E512 (M_E256 * M_E256)
+#define M_E1024 (M_E512 * M_E512)
+
+/************************************************************************
+ * Private Data
+ ************************************************************************/
+
+static double _expi_square_tbl[11] =
+{
+ M_E, // e^1
+ M_E2, // e^2
+ M_E4, // e^4
+ M_E8, // e^8
+ M_E16, // e^16
+ M_E32, // e^32
+ M_E64, // e^64
+ M_E128, // e^128
+ M_E256, // e^256
+ M_E512, // e^512
+ M_E1024, // e^1024
+};
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+double lib_expi(size_t n)
+{
+ size_t i;
+ double val;
+
+ if (n > 1024)
+ {
+ return INFINITY;
+ }
+
+ val = 1.0;
+
+ for (i = 0; n; i++)
+ {
+ if (n & (1 << i))
+ {
+ n &= ~(1 << i);
+ val *= _expi_square_tbl[i];
+ }
+ }
+
+ return val;
+}
+
diff --git a/nuttx/libc/math/lib_libsqrtapprox.c b/nuttx/libc/math/lib_libsqrtapprox.c
new file mode 100644
index 000000000..b6a9b0d54
--- /dev/null
+++ b/nuttx/libc/math/lib_libsqrtapprox.c
@@ -0,0 +1,50 @@
+/************************************************************************
+ * libc/math/lib_libsqrtapprox.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <stdint.h>
+#include <math.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+float lib_sqrtapprox(float x)
+{
+ int32_t i;
+
+ /* Floats + bit manipulation = +inf fun! */
+
+ i = *((int32_t *) & x);
+ i = 0x1fc00000 + (i >> 1);
+ x = *((float *)&i);
+
+ return x;
+}
diff --git a/nuttx/libc/math/lib_log.c b/nuttx/libc/math/lib_log.c
new file mode 100644
index 000000000..7156f6b41
--- /dev/null
+++ b/nuttx/libc/math/lib_log.c
@@ -0,0 +1,82 @@
+/************************************************************************
+ * libc/math/lib_log.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009, 2010 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <math.h>
+#include <float.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+#ifdef CONFIG_HAVE_DOUBLE
+double log(double x)
+{
+ double y, y_old, ey, epsilon;
+
+ y = 0.0;
+ y_old = 1.0;
+ epsilon = DBL_EPSILON;
+
+ while (y > y_old + epsilon || y < y_old - epsilon)
+ {
+ y_old = y;
+ ey = exp(y);
+ y -= (ey - x) / ey;
+
+ if (y > 700.0)
+ {
+ y = 700.0;
+ }
+
+ if (y < -700.0)
+ {
+ y = -700.0;
+ }
+
+ epsilon = (fabs(y) > 1.0) ? fabs(y) * DBL_EPSILON : DBL_EPSILON;
+ }
+
+ if (y == 700.0)
+ {
+ return INFINITY;
+ }
+
+ if (y == -700.0)
+ {
+ return INFINITY;
+ }
+
+ return y;
+}
+#endif
diff --git a/nuttx/libc/math/lib_log10.c b/nuttx/libc/math/lib_log10.c
new file mode 100644
index 000000000..9daa91492
--- /dev/null
+++ b/nuttx/libc/math/lib_log10.c
@@ -0,0 +1,46 @@
+/************************************************************************
+ * libc/math/lib_log10.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009, 2010 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <math.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+#ifdef CONFIG_HAVE_DOUBLE
+double log10(double x)
+{
+ return (log(x) / M_LN10);
+}
+#endif
diff --git a/nuttx/libc/math/lib_log10f.c b/nuttx/libc/math/lib_log10f.c
new file mode 100644
index 000000000..778daedd5
--- /dev/null
+++ b/nuttx/libc/math/lib_log10f.c
@@ -0,0 +1,41 @@
+/************************************************************************
+ * libc/math/lib_log10f.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009, 2010 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <math.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+float log10f(float x)
+{
+ return (logf(x) / M_LN10);
+}
diff --git a/nuttx/libc/math/lib_log10l.c b/nuttx/libc/math/lib_log10l.c
new file mode 100644
index 000000000..efbeb721b
--- /dev/null
+++ b/nuttx/libc/math/lib_log10l.c
@@ -0,0 +1,46 @@
+/************************************************************************
+ * libc/math/lib_log10l.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009, 2010 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <math.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double log10l(long double x)
+{
+ return (logl(x) / M_LN10);
+}
+#endif
diff --git a/nuttx/libc/math/lib_log2.c b/nuttx/libc/math/lib_log2.c
new file mode 100644
index 000000000..4da39acdc
--- /dev/null
+++ b/nuttx/libc/math/lib_log2.c
@@ -0,0 +1,46 @@
+/************************************************************************
+ * libc/math/lib_log2.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009, 2010 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <math.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+#ifdef CONFIG_HAVE_DOUBLE
+double log2(double x)
+{
+ return (log(x) / M_LN2);
+}
+#endif
diff --git a/nuttx/libc/math/lib_log2f.c b/nuttx/libc/math/lib_log2f.c
new file mode 100644
index 000000000..f514e5a9e
--- /dev/null
+++ b/nuttx/libc/math/lib_log2f.c
@@ -0,0 +1,41 @@
+/************************************************************************
+ * libc/math/lib_log2f.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009, 2010 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <math.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+float log2f(float x)
+{
+ return (logf(x) / M_LN2);
+}
diff --git a/nuttx/libc/math/lib_log2l.c b/nuttx/libc/math/lib_log2l.c
new file mode 100644
index 000000000..21e80a930
--- /dev/null
+++ b/nuttx/libc/math/lib_log2l.c
@@ -0,0 +1,46 @@
+/************************************************************************
+ * libc/math/lib_log2l.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009, 2010 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <math.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double log2l(long double x)
+{
+ return (logl(x) / M_LN2);
+}
+#endif
diff --git a/nuttx/libc/math/lib_logf.c b/nuttx/libc/math/lib_logf.c
new file mode 100644
index 000000000..3815fef84
--- /dev/null
+++ b/nuttx/libc/math/lib_logf.c
@@ -0,0 +1,77 @@
+/************************************************************************
+ * libc/math/lib_logf.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009, 2010 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <math.h>
+#include <float.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+float logf(float x)
+{
+ float y, y_old, ey, epsilon;
+
+ y = 0.0;
+ y_old = 1.0;
+ epsilon = FLT_EPSILON;
+
+ while (y > y_old + epsilon || y < y_old - epsilon)
+ {
+ y_old = y;
+ ey = exp(y);
+ y -= (ey - x) / ey;
+
+ if (y > 700.0)
+ {
+ y = 700.0;
+ }
+
+ if (y < -700.0)
+ {
+ y = -700.0;
+ }
+
+ epsilon = (fabs(y) > 1.0) ? fabs(y) * FLT_EPSILON : FLT_EPSILON;
+ }
+
+ if (y == 700.0)
+ {
+ return INFINITY;
+ }
+
+ if (y == -700.0)
+ {
+ return INFINITY;
+ }
+
+ return y;
+}
diff --git a/nuttx/libc/math/lib_logl.c b/nuttx/libc/math/lib_logl.c
new file mode 100644
index 000000000..612816011
--- /dev/null
+++ b/nuttx/libc/math/lib_logl.c
@@ -0,0 +1,80 @@
+/************************************************************************
+ * libc/math/lib_lol.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009, 2010 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <math.h>
+#include <float.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double logl(long double x)
+{
+ long double y, y_old, ey, epsilon;
+
+ y = 0.0;
+ y_old = 1.0;
+ epsilon = LDBL_EPSILON;
+
+ while (y > y_old + epsilon || y < y_old - epsilon)
+ {
+ y_old = y;
+ ey = expl(y);
+ y -= (ey - x) / ey;
+
+ if (y > 700.0)
+ {
+ y = 700.0;
+ }
+
+ if (y < -700.0)
+ {
+ y = -700.0;
+ }
+ }
+
+ if (y == 700.0)
+ {
+ return INFINITY;
+ }
+
+ if (y == -700.0)
+ {
+ return INFINITY;
+ }
+
+ return y;
+}
+#endif
diff --git a/nuttx/libc/math/lib_modf.c b/nuttx/libc/math/lib_modf.c
new file mode 100644
index 000000000..f3f25f6fb
--- /dev/null
+++ b/nuttx/libc/math/lib_modf.c
@@ -0,0 +1,58 @@
+/************************************************************************
+ * libc/math/lib_modf.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <stdint.h>
+#include <math.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+#ifdef CONFIG_HAVE_DOUBLE
+double modf(double x, double *iptr)
+{
+ if (fabs(x) >= 4503599627370496.0)
+ {
+ *iptr = x;
+ return 0.0;
+ }
+ else if (fabs(x) < 1.0)
+ {
+ *iptr = 0.0;
+ return x;
+ }
+ else
+ {
+ *iptr = (double)(int64_t) x;
+ return (x - *iptr);
+ }
+}
+#endif
diff --git a/nuttx/libc/math/lib_modff.c b/nuttx/libc/math/lib_modff.c
new file mode 100644
index 000000000..28d3a3ae0
--- /dev/null
+++ b/nuttx/libc/math/lib_modff.c
@@ -0,0 +1,55 @@
+/************************************************************************
+ * libc/math/lib_modff.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <math.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+float modff(float x, float *iptr)
+{
+ if (fabsf(x) >= 8388608.0)
+ {
+ *iptr = x;
+ return 0.0;
+ }
+ else if (fabs(x) < 1.0)
+ {
+ *iptr = 0.0;
+ return x;
+ }
+ else
+ {
+ *iptr = (float)(int)x;
+ return (x - *iptr);
+ }
+}
diff --git a/nuttx/libc/math/lib_modfl.c b/nuttx/libc/math/lib_modfl.c
new file mode 100644
index 000000000..77bba0e0c
--- /dev/null
+++ b/nuttx/libc/math/lib_modfl.c
@@ -0,0 +1,61 @@
+/************************************************************************
+ * libc/math/lib_modfl.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <stdint.h>
+#include <math.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double modfl(long double x, long double *iptr)
+{
+ if (fabs(x) >= 4503599627370496.0)
+ {
+ *iptr = x;
+ return 0.0;
+ }
+ else if (fabs(x) < 1.0)
+ {
+ *iptr = 0.0;
+ return x;
+ }
+ else
+ {
+ *iptr = (long double)(int64_t) x;
+ return (x - *iptr);
+ }
+}
+#endif
diff --git a/nuttx/libc/math/lib_pow.c b/nuttx/libc/math/lib_pow.c
new file mode 100644
index 000000000..a19d491fa
--- /dev/null
+++ b/nuttx/libc/math/lib_pow.c
@@ -0,0 +1,46 @@
+/************************************************************************
+ * libc/math/lib_pow.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009, 2010 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <math.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+#ifdef CONFIG_HAVE_DOUBLE
+double pow(double b, double e)
+{
+ return exp(e * log(b));
+}
+#endif
diff --git a/nuttx/libc/math/lib_powf.c b/nuttx/libc/math/lib_powf.c
new file mode 100644
index 000000000..570904898
--- /dev/null
+++ b/nuttx/libc/math/lib_powf.c
@@ -0,0 +1,41 @@
+/************************************************************************
+ * libc/math/lib_powf.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009, 2010 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <math.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+float powf(float b, float e)
+{
+ return expf(e * logf(b));
+}
diff --git a/nuttx/libc/math/lib_powl.c b/nuttx/libc/math/lib_powl.c
new file mode 100644
index 000000000..81438217c
--- /dev/null
+++ b/nuttx/libc/math/lib_powl.c
@@ -0,0 +1,46 @@
+/************************************************************************
+ * libc/math/lib_powl.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009, 2010 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <math.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double powl(long double b, long double e)
+{
+ return expl(e * logl(b));
+}
+#endif
diff --git a/nuttx/libc/math/lib_round.c b/nuttx/libc/math/lib_round.c
new file mode 100644
index 000000000..6191cee5b
--- /dev/null
+++ b/nuttx/libc/math/lib_round.c
@@ -0,0 +1,40 @@
+/************************************************************************
+ * lib/math/lib_round.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * (C) 2012 Petteri Aimonen <jpa@nx.mail.kapsi.fi>
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <math.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+#ifdef CONFIG_HAVE_DOUBLE
+double round(double x)
+{
+ double f = modf(x, &x);
+ if (x <= 0.0 && f <= -0.5)
+ {
+ x -= 1.0;
+ }
+
+ if (x >= 0.0 && f >= 0.5)
+ {
+ x += 1.0;
+ }
+
+ return x;
+}
+#endif
diff --git a/nuttx/libc/math/lib_roundf.c b/nuttx/libc/math/lib_roundf.c
new file mode 100644
index 000000000..145cf3df6
--- /dev/null
+++ b/nuttx/libc/math/lib_roundf.c
@@ -0,0 +1,38 @@
+/************************************************************************
+ * lib/math/lib_roundf.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * (C) 2012 Petteri Aimonen <jpa@nx.mail.kapsi.fi>
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <math.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+float roundf(float x)
+{
+ float f = modff(x, &x);
+ if (x <= 0.0f && f <= -0.5f)
+ {
+ x -= 1.0f;
+ }
+
+ if (x >= 0.0f && f >= 0.5f)
+ {
+ x += 1.0f;
+ }
+
+ return x;
+}
diff --git a/nuttx/libc/math/lib_roundl.c b/nuttx/libc/math/lib_roundl.c
new file mode 100644
index 000000000..b2ddba670
--- /dev/null
+++ b/nuttx/libc/math/lib_roundl.c
@@ -0,0 +1,40 @@
+/************************************************************************
+ * lib/math/lib_round.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * (C) 2012 Petteri Aimonen <jpa@nx.mail.kapsi.fi>
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <math.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double roundl(long double x)
+{
+ long double f = modfl(x, &x);
+ if (x <= 0.0 && f <= -0.5)
+ {
+ x -= 1.0;
+ }
+
+ if (x >= 0.0 && f >= 0.5)
+ {
+ x += 1.0;
+ }
+
+ return x;
+}
+#endif
diff --git a/nuttx/libc/math/lib_sin.c b/nuttx/libc/math/lib_sin.c
new file mode 100644
index 000000000..e005d98cb
--- /dev/null
+++ b/nuttx/libc/math/lib_sin.c
@@ -0,0 +1,114 @@
+/************************************************************************
+ * libc/math/lib_sin.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <sys/types.h>
+#include <math.h>
+
+#ifdef CONFIG_HAVE_DOUBLE
+
+/************************************************************************
+ * Private Data
+ ************************************************************************/
+
+static double _dbl_inv_fact[] =
+{
+ 1.0 / 1.0, // 1 / 1!
+ 1.0 / 6.0, // 1 / 3!
+ 1.0 / 120.0, // 1 / 5!
+ 1.0 / 5040.0, // 1 / 7!
+ 1.0 / 362880.0, // 1 / 9!
+ 1.0 / 39916800.0, // 1 / 11!
+ 1.0 / 6227020800.0, // 1 / 13!
+ 1.0 / 1307674368000.0, // 1 / 15!
+ 1.0 / 355687428096000.0, // 1 / 17!
+ 1.0 / 121645100408832000.0, // 1 / 19!
+};
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+double sin(double x)
+{
+ double x_squared;
+ double sin_x;
+ size_t i;
+
+ /* Move x to [-pi, pi) */
+
+ x = fmod(x, 2 * M_PI);
+ if (x >= M_PI)
+ {
+ x -= 2 * M_PI;
+ }
+
+ if (x < -M_PI)
+ {
+ x += 2 * M_PI;
+ }
+
+ /* Move x to [-pi/2, pi/2) */
+
+ if (x >= M_PI_2)
+ {
+ x = M_PI - x;
+ }
+
+ if (x < -M_PI_2)
+ {
+ x = -M_PI - x;
+ }
+
+ x_squared = x * x;
+ sin_x = 0.0;
+
+ /* Perform Taylor series approximation for sin(x) with ten terms */
+
+ for (i = 0; i < 10; i++)
+ {
+ if (i % 2 == 0)
+ {
+ sin_x += x * _dbl_inv_fact[i];
+ }
+ else
+ {
+ sin_x -= x * _dbl_inv_fact[i];
+ }
+
+ x *= x_squared;
+ }
+
+ return sin_x;
+}
+#endif
diff --git a/nuttx/libc/math/lib_sinf.c b/nuttx/libc/math/lib_sinf.c
new file mode 100644
index 000000000..9e493d8ef
--- /dev/null
+++ b/nuttx/libc/math/lib_sinf.c
@@ -0,0 +1,104 @@
+/************************************************************************
+ * libc/math/lib_sinf.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <sys/types.h>
+#include <math.h>
+
+/************************************************************************
+ * Private Data
+ ************************************************************************/
+
+static float _flt_inv_fact[] =
+{
+ 1.0 / 1.0, // 1 / 1!
+ 1.0 / 6.0, // 1 / 3!
+ 1.0 / 120.0, // 1 / 5!
+ 1.0 / 5040.0, // 1 / 7!
+ 1.0 / 362880.0, // 1 / 9!
+ 1.0 / 39916800.0, // 1 / 11!
+};
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+float sinf(float x)
+{
+ float x_squared;
+ float sin_x;
+ size_t i;
+
+ /* Move x to [-pi, pi) */
+
+ x = fmodf(x, 2 * M_PI);
+ if (x >= M_PI)
+ {
+ x -= 2 * M_PI;
+ }
+
+ if (x < -M_PI)
+ {
+ x += 2 * M_PI;
+ }
+
+ /* Move x to [-pi/2, pi/2) */
+
+ if (x >= M_PI_2)
+ {
+ x = M_PI - x;
+ }
+
+ if (x < -M_PI_2)
+ {
+ x = -M_PI - x;
+ }
+
+ x_squared = x * x;
+ sin_x = 0.0;
+
+ /* Perform Taylor series approximation for sin(x) with six terms */
+
+ for (i = 0; i < 6; i++)
+ {
+ if (i % 2 == 0)
+ {
+ sin_x += x * _flt_inv_fact[i];
+ }
+ else
+ {
+ sin_x -= x * _flt_inv_fact[i];
+ }
+
+ x *= x_squared;
+ }
+
+ return sin_x;
+}
diff --git a/nuttx/libc/math/lib_sinh.c b/nuttx/libc/math/lib_sinh.c
new file mode 100644
index 000000000..0c3e2d11d
--- /dev/null
+++ b/nuttx/libc/math/lib_sinh.c
@@ -0,0 +1,47 @@
+/************************************************************************
+ * libc/math/lib_sinh.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009, 2010 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <math.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+#ifdef CONFIG_HAVE_DOUBLE
+double sinh(double x)
+{
+ x = exp(x);
+ return ((x - (1.0 / x)) / 2.0);
+}
+#endif
diff --git a/nuttx/libc/math/lib_sinhf.c b/nuttx/libc/math/lib_sinhf.c
new file mode 100644
index 000000000..e9d198440
--- /dev/null
+++ b/nuttx/libc/math/lib_sinhf.c
@@ -0,0 +1,42 @@
+/************************************************************************
+ * libc/math/lib_sinhf.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009, 2010 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <math.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+float sinhf(float x)
+{
+ x = expf(x);
+ return ((x - (1.0 / x)) / 2.0);
+}
diff --git a/nuttx/libc/math/lib_sinhl.c b/nuttx/libc/math/lib_sinhl.c
new file mode 100644
index 000000000..a1bcad81e
--- /dev/null
+++ b/nuttx/libc/math/lib_sinhl.c
@@ -0,0 +1,47 @@
+/************************************************************************
+ * libc/math/lib_sinhl.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009, 2010 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <math.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double sinhl(long double x)
+{
+ x = expl(x);
+ return ((x - (1.0 / x)) / 2.0);
+}
+#endif
diff --git a/nuttx/libc/math/lib_sinl.c b/nuttx/libc/math/lib_sinl.c
new file mode 100644
index 000000000..6ed539a39
--- /dev/null
+++ b/nuttx/libc/math/lib_sinl.c
@@ -0,0 +1,114 @@
+/************************************************************************
+ * libc/math/lib_sinl.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <sys/types.h>
+#include <math.h>
+
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+
+/************************************************************************
+ * Private Data
+ ************************************************************************/
+
+static long double _ldbl_inv_fact[] =
+{
+ 1.0 / 1.0, // 1 / 1!
+ 1.0 / 6.0, // 1 / 3!
+ 1.0 / 120.0, // 1 / 5!
+ 1.0 / 5040.0, // 1 / 7!
+ 1.0 / 362880.0, // 1 / 9!
+ 1.0 / 39916800.0, // 1 / 11!
+ 1.0 / 6227020800.0, // 1 / 13!
+ 1.0 / 1307674368000.0, // 1 / 15!
+ 1.0 / 355687428096000.0, // 1 / 17!
+ 1.0 / 121645100408832000.0, // 1 / 19!
+};
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+long double sinl(long double x)
+{
+ long double x_squared;
+ long double sin_x;
+ size_t i;
+
+ /* Move x to [-pi, pi) */
+
+ x = fmodl(x, 2 * M_PI);
+ if (x >= M_PI)
+ {
+ x -= 2 * M_PI;
+ }
+
+ if (x < -M_PI)
+ {
+ x += 2 * M_PI;
+ }
+
+ /* Move x to [-pi/2, pi/2) */
+
+ if (x >= M_PI_2)
+ {
+ x = M_PI - x;
+ }
+
+ if (x < -M_PI_2)
+ {
+ x = -M_PI - x;
+ }
+
+ x_squared = x * x;
+ sin_x = 0.0;
+
+ /* Perform Taylor series approximation for sin(x) with ten terms */
+
+ for (i = 0; i < 10; i++)
+ {
+ if (i % 2 == 0)
+ {
+ sin_x += x * _ldbl_inv_fact[i];
+ }
+ else
+ {
+ sin_x -= x * _ldbl_inv_fact[i];
+ }
+
+ x *= x_squared;
+ }
+
+ return sin_x;
+}
+#endif
diff --git a/nuttx/libc/math/lib_sqrt.c b/nuttx/libc/math/lib_sqrt.c
new file mode 100644
index 000000000..e8a1c42ea
--- /dev/null
+++ b/nuttx/libc/math/lib_sqrt.c
@@ -0,0 +1,99 @@
+/************************************************************************
+ * libc/math/lib_sqrt.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <math.h>
+#include <errno.h>
+
+#include "lib_internal.h"
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+#ifdef CONFIG_HAVE_DOUBLE
+double sqrt(double x)
+{
+ long double y, y1;
+
+ if (x < 0.0)
+ {
+ errno = EDOM;
+ return NAN;
+ }
+
+ if (isnan(x))
+ {
+ return NAN;
+ }
+
+ if (isinf(x))
+ {
+ return INFINITY;
+ }
+
+ if (x == 0.0)
+ {
+ return 0.0;
+ }
+
+ /* Guess square root (using bit manipulation) */
+
+ y = lib_sqrtapprox(x);
+
+ /* Perform four iterations of approximation. This number (4) is
+ * definitely optimal
+ */
+
+ y = 0.5 * (y + x / y);
+ y = 0.5 * (y + x / y);
+ y = 0.5 * (y + x / y);
+ y = 0.5 * (y + x / y);
+
+ /* If guess was terribe (out of range of float). Repeat approximation
+ * until convergence.
+ */
+
+ if (y * y < x - 1.0 || y * y > x + 1.0)
+ {
+ y1 = -1.0;
+ while (y != y1)
+ {
+ y1 = y;
+ y = 0.5 * (y + x / y);
+ }
+ }
+
+ return y;
+}
+#endif
diff --git a/nuttx/libc/math/lib_sqrtf.c b/nuttx/libc/math/lib_sqrtf.c
new file mode 100644
index 000000000..cf45ccacc
--- /dev/null
+++ b/nuttx/libc/math/lib_sqrtf.c
@@ -0,0 +1,84 @@
+/************************************************************************
+ * libc/math/lib_sqrtf.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <math.h>
+#include <errno.h>
+
+#include "lib_internal.h"
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+float sqrtf(float x)
+{
+ float y;
+
+ /* Filter out invalid/trivial inputs */
+
+ if (x < 0.0)
+ {
+ errno = EDOM;
+ return NAN;
+ }
+
+ if (isnan(x))
+ {
+ return NAN;
+ }
+
+ if (isinf(x))
+ {
+ return INFINITY;
+ }
+
+ if (x == 0.0)
+ {
+ return 0.0;
+ }
+
+ /* Guess square root (using bit manipulation) */
+
+ y = lib_sqrtapprox(x);
+
+ /* Perform three iterations of approximation. This number (3) is
+ * definitely optimal
+ */
+
+ y = 0.5 * (y + x / y);
+ y = 0.5 * (y + x / y);
+ y = 0.5 * (y + x / y);
+
+ return y;
+}
diff --git a/nuttx/libc/math/lib_sqrtl.c b/nuttx/libc/math/lib_sqrtl.c
new file mode 100644
index 000000000..4035992fe
--- /dev/null
+++ b/nuttx/libc/math/lib_sqrtl.c
@@ -0,0 +1,101 @@
+/************************************************************************
+ * libc/math/lib_sqrtl.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <math.h>
+#include <errno.h>
+
+#include "lib_internal.h"
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double sqrtl(long double x)
+{
+ long double y, y1;
+
+ /* Filter out invalid/trivial inputs */
+
+ if (x < 0.0)
+ {
+ errno = EDOM;
+ return NAN;
+ }
+
+ if (isnan(x))
+ {
+ return NAN;
+ }
+
+ if (isinf(x))
+ {
+ return INFINITY;
+ }
+
+ if (x == 0.0)
+ {
+ return 0.0;
+ }
+
+ /* Guess square root (using bit manipulation) */
+
+ y = lib_sqrtapprox(x);
+
+ /* Perform four iterations of approximation. This number (4) is
+ * definitely optimal
+ */
+
+ y = 0.5 * (y + x / y);
+ y = 0.5 * (y + x / y);
+ y = 0.5 * (y + x / y);
+ y = 0.5 * (y + x / y);
+
+ /* If guess was terribe (out of range of float). Repeat approximation
+ * until convergence
+ */
+
+ if (y * y < x - 1.0 || y * y > x + 1.0)
+ {
+ y1 = -1.0;
+ while (y != y1)
+ {
+ y1 = y;
+ y = 0.5 * (y + x / y);
+ }
+ }
+
+ return y;
+}
+#endif
diff --git a/nuttx/libc/math/lib_tan.c b/nuttx/libc/math/lib_tan.c
new file mode 100644
index 000000000..4c091c09b
--- /dev/null
+++ b/nuttx/libc/math/lib_tan.c
@@ -0,0 +1,46 @@
+/************************************************************************
+ * libc/math/lib_tan.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009, 2010 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <math.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+#ifdef CONFIG_HAVE_DOUBLE
+double tan(double x)
+{
+ return (sin(x) / cos(x));
+}
+#endif
diff --git a/nuttx/libc/math/lib_tanf.c b/nuttx/libc/math/lib_tanf.c
new file mode 100644
index 000000000..0c9110a0b
--- /dev/null
+++ b/nuttx/libc/math/lib_tanf.c
@@ -0,0 +1,41 @@
+/************************************************************************
+ * libc/math/lib_tanf.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009, 2010 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <math.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+float tanf(float x)
+{
+ return (sinf(x) / cosf(x));
+}
diff --git a/nuttx/libc/math/lib_tanh.c b/nuttx/libc/math/lib_tanh.c
new file mode 100644
index 000000000..3b9ea0f41
--- /dev/null
+++ b/nuttx/libc/math/lib_tanh.c
@@ -0,0 +1,49 @@
+/************************************************************************
+ * libc/math/lib_tanh.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009, 2010 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <math.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+#ifdef CONFIG_HAVE_DOUBLE
+double tanh(double x)
+{
+ double x0 = exp(x);
+ double x1 = 1.0 / x0;
+
+ return ((x0 + x1) / (x0 - x1));
+}
+#endif
diff --git a/nuttx/libc/math/lib_tanhf.c b/nuttx/libc/math/lib_tanhf.c
new file mode 100644
index 000000000..43d418204
--- /dev/null
+++ b/nuttx/libc/math/lib_tanhf.c
@@ -0,0 +1,44 @@
+/************************************************************************
+ * libc/math/lib_tanhf.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009, 2010 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <math.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+float tanhf(float x)
+{
+ float x0 = expf(x);
+ float x1 = 1.0 / x0;
+
+ return ((x0 + x1) / (x0 - x1));
+}
diff --git a/nuttx/libc/math/lib_tanhl.c b/nuttx/libc/math/lib_tanhl.c
new file mode 100644
index 000000000..5aafd1e7b
--- /dev/null
+++ b/nuttx/libc/math/lib_tanhl.c
@@ -0,0 +1,49 @@
+/************************************************************************
+ * libc/math/lib_tanhl.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009, 2010 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <math.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double tanhl(long double x)
+{
+ long double x0 = exp(x);
+ long double x1 = 1.0 / x0;
+
+ return ((x0 + x1) / (x0 - x1));
+}
+#endif
diff --git a/nuttx/libc/math/lib_tanl.c b/nuttx/libc/math/lib_tanl.c
new file mode 100644
index 000000000..e77abe0f1
--- /dev/null
+++ b/nuttx/libc/math/lib_tanl.c
@@ -0,0 +1,46 @@
+/************************************************************************
+ * libc/math/lib_tanl.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Ported by: Darcy Gong
+ *
+ * It derives from the Rhombs OS math library by Nick Johnson which has
+ * a compatibile, MIT-style license:
+ *
+ * Copyright (C) 2009, 2010 Nick Johnson <nickbjohnson4224 at gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <math.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+long double tanl(long double x)
+{
+ return (sinl(x) / cosl(x));
+}
+#endif
diff --git a/nuttx/lib/misc/Make.defs b/nuttx/libc/misc/Make.defs
index c12533f75..f4284ac60 100644
--- a/nuttx/lib/misc/Make.defs
+++ b/nuttx/libc/misc/Make.defs
@@ -1,5 +1,5 @@
############################################################################
-# lib/misc/Make.defs
+# libc/misc/Make.defs
#
# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/misc/lib_crc32.c b/nuttx/libc/misc/lib_crc32.c
index f851598e0..ae73ba3d7 100644
--- a/nuttx/lib/misc/lib_crc32.c
+++ b/nuttx/libc/misc/lib_crc32.c
@@ -1,5 +1,5 @@
/************************************************************************************************
- * lib/misc/lib_crc32.c
+ * libc/misc/lib_crc32.c
*
* This file is a part of NuttX:
*
diff --git a/nuttx/lib/misc/lib_dbg.c b/nuttx/libc/misc/lib_dbg.c
index aacdaa30a..5605ff828 100644
--- a/nuttx/lib/misc/lib_dbg.c
+++ b/nuttx/libc/misc/lib_dbg.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/misc/lib_dbg.c
+ * libc/misc/lib_dbg.c
*
* Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/misc/lib_dumpbuffer.c b/nuttx/libc/misc/lib_dumpbuffer.c
index 155468ca1..52158b220 100644
--- a/nuttx/lib/misc/lib_dumpbuffer.c
+++ b/nuttx/libc/misc/lib_dumpbuffer.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/misc/lib_dumpbuffer.c
+ * libc/misc/lib_dumpbuffer.c
*
* Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/misc/lib_filesem.c b/nuttx/libc/misc/lib_filesem.c
index 1d1f25c2f..5cc4624ec 100644
--- a/nuttx/lib/misc/lib_filesem.c
+++ b/nuttx/libc/misc/lib_filesem.c
@@ -1,5 +1,5 @@
/************************************************************************
- * lib/misc/lib_filesem.c
+ * libc/misc/lib_filesem.c
*
* Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/misc/lib_init.c b/nuttx/libc/misc/lib_init.c
index 3403a837b..6a120f7b1 100644
--- a/nuttx/lib/misc/lib_init.c
+++ b/nuttx/libc/misc/lib_init.c
@@ -1,5 +1,5 @@
/************************************************************
- * lib/misc/lib_init.c
+ * libc/misc/lib_init.c
*
* Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/misc/lib_match.c b/nuttx/libc/misc/lib_match.c
index 18e0632ec..a8cfad329 100644
--- a/nuttx/lib/misc/lib_match.c
+++ b/nuttx/libc/misc/lib_match.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/misc/lib_match.c - simple shell-style filename matcher
+ * libc/misc/lib_match.c - simple shell-style filename matcher
*
* Simple shell-style filename pattern matcher written by Jef Poskanzer
* This pattern matcher only handles '?', '*' and '**', and multiple
diff --git a/nuttx/lib/misc/lib_sendfile.c b/nuttx/libc/misc/lib_sendfile.c
index a82eb325e..8a38dc317 100644
--- a/nuttx/lib/misc/lib_sendfile.c
+++ b/nuttx/libc/misc/lib_sendfile.c
@@ -1,5 +1,5 @@
/************************************************************************
- * lib/misc/lib_streamsem.c
+ * libc/misc/lib_streamsem.c
*
* Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/misc/lib_streamsem.c b/nuttx/libc/misc/lib_streamsem.c
index fdf494e75..e38298bdb 100644
--- a/nuttx/lib/misc/lib_streamsem.c
+++ b/nuttx/libc/misc/lib_streamsem.c
@@ -1,5 +1,5 @@
/************************************************************************
- * lib/misc/lib_streamsem.c
+ * libc/misc/lib_streamsem.c
*
* Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/mqueue/Make.defs b/nuttx/libc/mqueue/Make.defs
index 40dc6c13e..826970fa3 100644
--- a/nuttx/lib/mqueue/Make.defs
+++ b/nuttx/libc/mqueue/Make.defs
@@ -1,5 +1,5 @@
############################################################################
-# lib/mqueue/Make.defs
+# libc/mqueue/Make.defs
#
# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/mqueue/mq_getattr.c b/nuttx/libc/mqueue/mq_getattr.c
index 9c9f47fdc..2fc0e131b 100644
--- a/nuttx/lib/mqueue/mq_getattr.c
+++ b/nuttx/libc/mqueue/mq_getattr.c
@@ -1,5 +1,5 @@
/************************************************************************
- * lib/mqueue/mq_getattr.c
+ * libc/mqueue/mq_getattr.c
*
* Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/mqueue/mq_setattr.c b/nuttx/libc/mqueue/mq_setattr.c
index 1276d64e8..45a848e6d 100644
--- a/nuttx/lib/mqueue/mq_setattr.c
+++ b/nuttx/libc/mqueue/mq_setattr.c
@@ -1,5 +1,5 @@
/************************************************************************
- * lib/mqueue/mq_setattr.c
+ * libc/mqueue/mq_setattr.c
*
* Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/net/Make.defs b/nuttx/libc/net/Make.defs
index ae041bd2c..9d4e5c06b 100644
--- a/nuttx/lib/net/Make.defs
+++ b/nuttx/libc/net/Make.defs
@@ -1,5 +1,5 @@
############################################################################
-# lib/net/Make.defs
+# libc/net/Make.defs
#
# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/net/lib_etherntoa.c b/nuttx/libc/net/lib_etherntoa.c
index f89f205a2..91fb01c57 100644
--- a/nuttx/lib/net/lib_etherntoa.c
+++ b/nuttx/libc/net/lib_etherntoa.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/net/lib_etherntoa.c
+ * libc/net/lib_etherntoa.c
*
* Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/net/lib_htonl.c b/nuttx/libc/net/lib_htonl.c
index e4c3e5383..a10f54f37 100644
--- a/nuttx/lib/net/lib_htonl.c
+++ b/nuttx/libc/net/lib_htonl.c
@@ -1,5 +1,5 @@
/************************************************************
- * lib/net/lib_ntohl.c
+ * libc/net/lib_ntohl.c
*
* Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/net/lib_htons.c b/nuttx/libc/net/lib_htons.c
index b4117e1dc..13addd913 100644
--- a/nuttx/lib/net/lib_htons.c
+++ b/nuttx/libc/net/lib_htons.c
@@ -1,5 +1,5 @@
/***************************************************************************
- * lib/net/lib_htons.c
+ * libc/net/lib_htons.c
*
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/net/lib_inetaddr.c b/nuttx/libc/net/lib_inetaddr.c
index 48b01d682..46c6c548d 100644
--- a/nuttx/lib/net/lib_inetaddr.c
+++ b/nuttx/libc/net/lib_inetaddr.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/net/lib_inetaddr.c
+ * libc/net/lib_inetaddr.c
*
* Copyright (C) 2011 Yu Qiang. All rights reserved.
* Author: Yu Qiang <yuq825@gmail.com>
diff --git a/nuttx/lib/net/lib_inetntoa.c b/nuttx/libc/net/lib_inetntoa.c
index 0f4fb61df..e2d92d864 100644
--- a/nuttx/lib/net/lib_inetntoa.c
+++ b/nuttx/libc/net/lib_inetntoa.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/net/lib_inetntoa.c
+ * libc/net/lib_inetntoa.c
*
* Copyright (C) 2007-2008, 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/net/lib_inetntop.c b/nuttx/libc/net/lib_inetntop.c
index dc6a2d0d7..25c32c48c 100644
--- a/nuttx/lib/net/lib_inetntop.c
+++ b/nuttx/libc/net/lib_inetntop.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/net/lib_inetntop.c
+ * libc/net/lib_inetntop.c
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/net/lib_inetpton.c b/nuttx/libc/net/lib_inetpton.c
index 5371cd3f2..c5f117535 100644
--- a/nuttx/lib/net/lib_inetpton.c
+++ b/nuttx/libc/net/lib_inetpton.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/net/lib_inetpton.c
+ * libc/net/lib_inetpton.c
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/pthread/Make.defs b/nuttx/libc/pthread/Make.defs
index a1eba7bb0..07e4f0570 100644
--- a/nuttx/lib/pthread/Make.defs
+++ b/nuttx/libc/pthread/Make.defs
@@ -1,5 +1,5 @@
############################################################################
-# lib/pthread/Make.defs
+# libc/pthread/Make.defs
#
# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/pthread/pthread_attrdestroy.c b/nuttx/libc/pthread/pthread_attrdestroy.c
index 103528c7e..37ad46ebc 100644
--- a/nuttx/lib/pthread/pthread_attrdestroy.c
+++ b/nuttx/libc/pthread/pthread_attrdestroy.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/pthread/pthread_attrdestroy.c
+ * libc/pthread/pthread_attrdestroy.c
*
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/pthread/pthread_attrgetinheritsched.c b/nuttx/libc/pthread/pthread_attrgetinheritsched.c
index 02d6e0b7c..6ec8ae71f 100644
--- a/nuttx/lib/pthread/pthread_attrgetinheritsched.c
+++ b/nuttx/libc/pthread/pthread_attrgetinheritsched.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/pthread/pthread_attrgetinheritsched.c
+ * libc/pthread/pthread_attrgetinheritsched.c
*
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/pthread/pthread_attrgetschedparam.c b/nuttx/libc/pthread/pthread_attrgetschedparam.c
index c6bf55dea..6bcc9618e 100644
--- a/nuttx/lib/pthread/pthread_attrgetschedparam.c
+++ b/nuttx/libc/pthread/pthread_attrgetschedparam.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/pthread/pthread_attrgetschedparam.c
+ * libc/pthread/pthread_attrgetschedparam.c
*
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/pthread/pthread_attrgetschedpolicy.c b/nuttx/libc/pthread/pthread_attrgetschedpolicy.c
index c42b828c9..8845e2bd8 100644
--- a/nuttx/lib/pthread/pthread_attrgetschedpolicy.c
+++ b/nuttx/libc/pthread/pthread_attrgetschedpolicy.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/pthread/pthread_attrgetschedpolicy.c
+ * libc/pthread/pthread_attrgetschedpolicy.c
*
* Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/pthread/pthread_attrgetstacksize.c b/nuttx/libc/pthread/pthread_attrgetstacksize.c
index 2faa586ba..9fde29e81 100644
--- a/nuttx/lib/pthread/pthread_attrgetstacksize.c
+++ b/nuttx/libc/pthread/pthread_attrgetstacksize.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/pthread/pthread_attrgetstacksize.c
+ * libc/pthread/pthread_attrgetstacksize.c
*
* Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/pthread/pthread_attrinit.c b/nuttx/libc/pthread/pthread_attrinit.c
index d06a535d7..427a582b9 100644
--- a/nuttx/lib/pthread/pthread_attrinit.c
+++ b/nuttx/libc/pthread/pthread_attrinit.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/pthread/pthread_attrinit.c
+ * libc/pthread/pthread_attrinit.c
*
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/pthread/pthread_attrsetinheritsched.c b/nuttx/libc/pthread/pthread_attrsetinheritsched.c
index df2c2fba3..1102fe176 100644
--- a/nuttx/lib/pthread/pthread_attrsetinheritsched.c
+++ b/nuttx/libc/pthread/pthread_attrsetinheritsched.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/pthread/pthread_attrsetinheritsched.c
+ * libc/pthread/pthread_attrsetinheritsched.c
*
* Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/pthread/pthread_attrsetschedparam.c b/nuttx/libc/pthread/pthread_attrsetschedparam.c
index c2ab4d1c4..587d62206 100644
--- a/nuttx/lib/pthread/pthread_attrsetschedparam.c
+++ b/nuttx/libc/pthread/pthread_attrsetschedparam.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/pthread/pthread_attrsetschedparam.c
+ * libc/pthread/pthread_attrsetschedparam.c
*
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/pthread/pthread_attrsetschedpolicy.c b/nuttx/libc/pthread/pthread_attrsetschedpolicy.c
index 4e43e635d..e1d1c8619 100644
--- a/nuttx/lib/pthread/pthread_attrsetschedpolicy.c
+++ b/nuttx/libc/pthread/pthread_attrsetschedpolicy.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/pthread/pthread_attrsetschedpolicy.c
+ * libc/pthread/pthread_attrsetschedpolicy.c
*
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/pthread/pthread_attrsetstacksize.c b/nuttx/libc/pthread/pthread_attrsetstacksize.c
index 8a826dd3a..fca993baf 100644
--- a/nuttx/lib/pthread/pthread_attrsetstacksize.c
+++ b/nuttx/libc/pthread/pthread_attrsetstacksize.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/pthread/pthread_attrsetstacksize.c
+ * libc/pthread/pthread_attrsetstacksize.c
*
* Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/pthread/pthread_barrierattrdestroy.c b/nuttx/libc/pthread/pthread_barrierattrdestroy.c
index 6d16b9cff..5519caa61 100644
--- a/nuttx/lib/pthread/pthread_barrierattrdestroy.c
+++ b/nuttx/libc/pthread/pthread_barrierattrdestroy.c
@@ -1,5 +1,5 @@
/********************************************************************************
- * lib/pthread/pthread_barrierattrdestroy.c
+ * libc/pthread/pthread_barrierattrdestroy.c
*
* Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/pthread/pthread_barrierattrgetpshared.c b/nuttx/libc/pthread/pthread_barrierattrgetpshared.c
index d29bc6dfc..83faffae0 100644
--- a/nuttx/lib/pthread/pthread_barrierattrgetpshared.c
+++ b/nuttx/libc/pthread/pthread_barrierattrgetpshared.c
@@ -1,5 +1,5 @@
/********************************************************************************
- * lib/pthread/pthread_barrierattrgetpshared.c
+ * libc/pthread/pthread_barrierattrgetpshared.c
*
* Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/pthread/pthread_barrierattrinit.c b/nuttx/libc/pthread/pthread_barrierattrinit.c
index b5f35ca91..7ab101883 100644
--- a/nuttx/lib/pthread/pthread_barrierattrinit.c
+++ b/nuttx/libc/pthread/pthread_barrierattrinit.c
@@ -1,5 +1,5 @@
/********************************************************************************
- * lib/pthread/pthread_barrierattrinit.c
+ * libc/pthread/pthread_barrierattrinit.c
*
* Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/pthread/pthread_barrierattrsetpshared.c b/nuttx/libc/pthread/pthread_barrierattrsetpshared.c
index d0eecbf5a..2585de7a0 100644
--- a/nuttx/lib/pthread/pthread_barrierattrsetpshared.c
+++ b/nuttx/libc/pthread/pthread_barrierattrsetpshared.c
@@ -1,5 +1,5 @@
/********************************************************************************
- * lib/pthread/pthread_barrierattrsetpshared.c
+ * libc/pthread/pthread_barrierattrsetpshared.c
*
* Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/pthread/pthread_condattrdestroy.c b/nuttx/libc/pthread/pthread_condattrdestroy.c
index d6c3df5d1..30a0c4db1 100644
--- a/nuttx/lib/pthread/pthread_condattrdestroy.c
+++ b/nuttx/libc/pthread/pthread_condattrdestroy.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/pthread/pthread_condattrdestroy.c
+ * libc/pthread/pthread_condattrdestroy.c
*
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/pthread/pthread_condattrinit.c b/nuttx/libc/pthread/pthread_condattrinit.c
index 5721c6159..511376f2e 100644
--- a/nuttx/lib/pthread/pthread_condattrinit.c
+++ b/nuttx/libc/pthread/pthread_condattrinit.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/pthread/pthread_condattrinit.c
+ * libc/pthread/pthread_condattrinit.c
*
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/pthread/pthread_mutexattrdestroy.c b/nuttx/libc/pthread/pthread_mutexattrdestroy.c
index e9868df68..82a13c300 100644
--- a/nuttx/lib/pthread/pthread_mutexattrdestroy.c
+++ b/nuttx/libc/pthread/pthread_mutexattrdestroy.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/pthread/pthread_mutexattrdestroy.c
+ * libc/pthread/pthread_mutexattrdestroy.c
*
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/pthread/pthread_mutexattrgetpshared.c b/nuttx/libc/pthread/pthread_mutexattrgetpshared.c
index bc6379db5..dc18484ec 100644
--- a/nuttx/lib/pthread/pthread_mutexattrgetpshared.c
+++ b/nuttx/libc/pthread/pthread_mutexattrgetpshared.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/pthread/pthread_mutexattrgetpshared.c
+ * libc/pthread/pthread_mutexattrgetpshared.c
*
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/pthread/pthread_mutexattrgettype.c b/nuttx/libc/pthread/pthread_mutexattrgettype.c
index 5fb10f301..3b8b3ec05 100644
--- a/nuttx/lib/pthread/pthread_mutexattrgettype.c
+++ b/nuttx/libc/pthread/pthread_mutexattrgettype.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/pthread/pthread_mutexattrgettype.c
+ * libc/pthread/pthread_mutexattrgettype.c
*
* Copyright (C) 2008, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/pthread/pthread_mutexattrinit.c b/nuttx/libc/pthread/pthread_mutexattrinit.c
index f815bf16c..f8c272195 100644
--- a/nuttx/lib/pthread/pthread_mutexattrinit.c
+++ b/nuttx/libc/pthread/pthread_mutexattrinit.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/pthread/pthread_mutexattrinit.c
+ * libc/pthread/pthread_mutexattrinit.c
*
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/pthread/pthread_mutexattrsetpshared.c b/nuttx/libc/pthread/pthread_mutexattrsetpshared.c
index 900476fdd..7501fd980 100644
--- a/nuttx/lib/pthread/pthread_mutexattrsetpshared.c
+++ b/nuttx/libc/pthread/pthread_mutexattrsetpshared.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/pthread/pthread_mutexattrsetpshared.c
+ * libc/pthread/pthread_mutexattrsetpshared.c
*
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/pthread/pthread_mutexattrsettype.c b/nuttx/libc/pthread/pthread_mutexattrsettype.c
index 81427c757..068a27dc2 100644
--- a/nuttx/lib/pthread/pthread_mutexattrsettype.c
+++ b/nuttx/libc/pthread/pthread_mutexattrsettype.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/pthread/pthread_mutexattrsettype.c
+ * libc/pthread/pthread_mutexattrsettype.c
*
* Copyright (C) 2008, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/queue/Make.defs b/nuttx/libc/queue/Make.defs
index 976e7a2b8..9a843dbdc 100644
--- a/nuttx/lib/queue/Make.defs
+++ b/nuttx/libc/queue/Make.defs
@@ -1,5 +1,5 @@
############################################################################
-# lib/queue/Make.defs
+# libc/queue/Make.defs
#
# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/queue/dq_addafter.c b/nuttx/libc/queue/dq_addafter.c
index bfbe0052d..e4d1abf63 100644
--- a/nuttx/lib/queue/dq_addafter.c
+++ b/nuttx/libc/queue/dq_addafter.c
@@ -1,5 +1,5 @@
/************************************************************
- * lib/queue/dq_addafter.c
+ * libc/queue/dq_addafter.c
*
* Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/queue/dq_addbefore.c b/nuttx/libc/queue/dq_addbefore.c
index d740ea830..3c403fc94 100644
--- a/nuttx/lib/queue/dq_addbefore.c
+++ b/nuttx/libc/queue/dq_addbefore.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/queue/dq_addbefore.c
+ * libc/queue/dq_addbefore.c
*
* Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/queue/dq_addfirst.c b/nuttx/libc/queue/dq_addfirst.c
index 7c7312de3..56767b928 100644
--- a/nuttx/lib/queue/dq_addfirst.c
+++ b/nuttx/libc/queue/dq_addfirst.c
@@ -1,5 +1,5 @@
/************************************************************
- * lib/queue/dq_addfirst.c
+ * libc/queue/dq_addfirst.c
*
* Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/queue/dq_addlast.c b/nuttx/libc/queue/dq_addlast.c
index 745deb27d..3ef08abd0 100644
--- a/nuttx/lib/queue/dq_addlast.c
+++ b/nuttx/libc/queue/dq_addlast.c
@@ -1,5 +1,5 @@
/************************************************************
- * lib/queue/dq_addlast.c
+ * libc/queue/dq_addlast.c
*
* Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/queue/dq_rem.c b/nuttx/libc/queue/dq_rem.c
index 218427bf8..db20762c7 100644
--- a/nuttx/lib/queue/dq_rem.c
+++ b/nuttx/libc/queue/dq_rem.c
@@ -1,5 +1,5 @@
/************************************************************
- * lib/queue/dq_rem.c
+ * libc/queue/dq_rem.c
*
* Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/queue/dq_remfirst.c b/nuttx/libc/queue/dq_remfirst.c
index 26c5fd7a6..e87acc338 100644
--- a/nuttx/lib/queue/dq_remfirst.c
+++ b/nuttx/libc/queue/dq_remfirst.c
@@ -1,5 +1,5 @@
/************************************************************
- * lib/queue/dq_remfirst.c
+ * libc/queue/dq_remfirst.c
*
* Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/queue/dq_remlast.c b/nuttx/libc/queue/dq_remlast.c
index 35adc73e2..18c182335 100644
--- a/nuttx/lib/queue/dq_remlast.c
+++ b/nuttx/libc/queue/dq_remlast.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/queue/dq_remlast.c
+ * libc/queue/dq_remlast.c
*
* Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/queue/sq_addafter.c b/nuttx/libc/queue/sq_addafter.c
index 965ac2844..5d47feba0 100644
--- a/nuttx/lib/queue/sq_addafter.c
+++ b/nuttx/libc/queue/sq_addafter.c
@@ -1,5 +1,5 @@
/************************************************************
- * lib/queue/sq_addafter.c
+ * libc/queue/sq_addafter.c
*
* Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/queue/sq_addfirst.c b/nuttx/libc/queue/sq_addfirst.c
index 8fc8e0619..962486154 100644
--- a/nuttx/lib/queue/sq_addfirst.c
+++ b/nuttx/libc/queue/sq_addfirst.c
@@ -1,5 +1,5 @@
/************************************************************
- * lib/queue/sq_addfirst.c
+ * libc/queue/sq_addfirst.c
*
* Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/queue/sq_addlast.c b/nuttx/libc/queue/sq_addlast.c
index f9f9625cc..faa07efb5 100644
--- a/nuttx/lib/queue/sq_addlast.c
+++ b/nuttx/libc/queue/sq_addlast.c
@@ -1,5 +1,5 @@
/************************************************************
- * lib/queue/sq_addlast.c
+ * libc/queue/sq_addlast.c
*
* Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/queue/sq_rem.c b/nuttx/libc/queue/sq_rem.c
index 6ba52354d..720be182c 100644
--- a/nuttx/lib/queue/sq_rem.c
+++ b/nuttx/libc/queue/sq_rem.c
@@ -1,5 +1,5 @@
/************************************************************
- * lib/queue/sq_rem.c
+ * libc/queue/sq_rem.c
*
* Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/queue/sq_remafter.c b/nuttx/libc/queue/sq_remafter.c
index 4dcfb06e4..0545a00f9 100644
--- a/nuttx/lib/queue/sq_remafter.c
+++ b/nuttx/libc/queue/sq_remafter.c
@@ -1,5 +1,5 @@
/************************************************************
- * lib/queue/sq_remafter.c
+ * libc/queue/sq_remafter.c
*
* Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/queue/sq_remfirst.c b/nuttx/libc/queue/sq_remfirst.c
index 43df6de41..f81c18dc2 100644
--- a/nuttx/lib/queue/sq_remfirst.c
+++ b/nuttx/libc/queue/sq_remfirst.c
@@ -1,5 +1,5 @@
/************************************************************
- * lib/queue/sq_remfirst.c
+ * libc/queue/sq_remfirst.c
*
* Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/queue/sq_remlast.c b/nuttx/libc/queue/sq_remlast.c
index 92cdbde98..8f045e493 100644
--- a/nuttx/lib/queue/sq_remlast.c
+++ b/nuttx/libc/queue/sq_remlast.c
@@ -1,5 +1,5 @@
/************************************************************
- * lib/queue/sq_remlast.c
+ * libc/queue/sq_remlast.c
*
* Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/sched/Make.defs b/nuttx/libc/sched/Make.defs
index f398b755e..d2356db0f 100644
--- a/nuttx/lib/sched/Make.defs
+++ b/nuttx/libc/sched/Make.defs
@@ -1,5 +1,5 @@
############################################################################
-# lib/sched/Make.defs
+# libc/sched/Make.defs
#
# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/sched/sched_getprioritymax.c b/nuttx/libc/sched/sched_getprioritymax.c
index 14b368dfc..6ea37e76a 100644
--- a/nuttx/lib/sched/sched_getprioritymax.c
+++ b/nuttx/libc/sched/sched_getprioritymax.c
@@ -1,5 +1,5 @@
/************************************************************************
- * lib/sched/sched_getprioritymax.c
+ * libc/sched/sched_getprioritymax.c
*
* Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/sched/sched_getprioritymin.c b/nuttx/libc/sched/sched_getprioritymin.c
index 86410cb0f..dbb46d81e 100644
--- a/nuttx/lib/sched/sched_getprioritymin.c
+++ b/nuttx/libc/sched/sched_getprioritymin.c
@@ -1,5 +1,5 @@
/************************************************************************
- * lib/sched/sched_getprioritymin.c
+ * libc/sched/sched_getprioritymin.c
*
* Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/semaphore/Make.defs b/nuttx/libc/semaphore/Make.defs
index fdc0fe7d5..b6551ff96 100644
--- a/nuttx/lib/semaphore/Make.defs
+++ b/nuttx/libc/semaphore/Make.defs
@@ -1,5 +1,5 @@
############################################################################
-# lib/semaphore/Make.defs
+# libc/semaphore/Make.defs
#
# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/semaphore/sem_getvalue.c b/nuttx/libc/semaphore/sem_getvalue.c
index 31c6bb7e0..ce9d12611 100644
--- a/nuttx/lib/semaphore/sem_getvalue.c
+++ b/nuttx/libc/semaphore/sem_getvalue.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/semaphore/sem_getvalue.c
+ * libc/semaphore/sem_getvalue.c
*
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/semaphore/sem_init.c b/nuttx/libc/semaphore/sem_init.c
index bc14415f9..7732eb57a 100644
--- a/nuttx/lib/semaphore/sem_init.c
+++ b/nuttx/libc/semaphore/sem_init.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/sem/sem_init.c
+ * libc/sem/sem_init.c
*
* Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/signal/Make.defs b/nuttx/libc/signal/Make.defs
index e27da9b2e..fe7eb180e 100644
--- a/nuttx/lib/signal/Make.defs
+++ b/nuttx/libc/signal/Make.defs
@@ -1,5 +1,5 @@
############################################################################
-# lib/signal/Make.defs
+# libc/signal/Make.defs
#
# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/signal/sig_addset.c b/nuttx/libc/signal/sig_addset.c
index 19ba0cb6b..06ddabd6b 100644
--- a/nuttx/lib/signal/sig_addset.c
+++ b/nuttx/libc/signal/sig_addset.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/signal/sig_addset.c
+ * libc/signal/sig_addset.c
*
* Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/signal/sig_delset.c b/nuttx/libc/signal/sig_delset.c
index 1c661d37f..04112d872 100644
--- a/nuttx/lib/signal/sig_delset.c
+++ b/nuttx/libc/signal/sig_delset.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/signal/sig_delset.c
+ * libc/signal/sig_delset.c
*
* Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/signal/sig_emptyset.c b/nuttx/libc/signal/sig_emptyset.c
index ac0c6b3e8..16ddd3f68 100644
--- a/nuttx/lib/signal/sig_emptyset.c
+++ b/nuttx/libc/signal/sig_emptyset.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/signal/sig_emptyset.c
+ * libc/signal/sig_emptyset.c
*
* Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/signal/sig_fillset.c b/nuttx/libc/signal/sig_fillset.c
index 8697d7577..99ee95c1f 100644
--- a/nuttx/lib/signal/sig_fillset.c
+++ b/nuttx/libc/signal/sig_fillset.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/signal/sig_fillset.c
+ * libc/signal/sig_fillset.c
*
* Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/signal/sig_ismember.c b/nuttx/libc/signal/sig_ismember.c
index c5bb091b7..1a8590e00 100644
--- a/nuttx/lib/signal/sig_ismember.c
+++ b/nuttx/libc/signal/sig_ismember.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/signal/sig_ismember.c
+ * libc/signal/sig_ismember.c
*
* Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/stdio/Make.defs b/nuttx/libc/stdio/Make.defs
index a4e900705..e18ab0220 100644
--- a/nuttx/lib/stdio/Make.defs
+++ b/nuttx/libc/stdio/Make.defs
@@ -1,5 +1,5 @@
############################################################################
-# lib/stdio/Make.defs
+# libc/stdio/Make.defs
#
# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
@@ -34,27 +34,39 @@
############################################################################
# Add the stdio C files to the build
+# This first group of C files do not depend on having file descriptors or
+# C streams.
CSRCS += lib_fileno.c lib_printf.c lib_rawprintf.c lib_lowprintf.c \
- lib_sprintf.c lib_asprintf.c lib_snprintf.c lib_libsprintf.c \
- lib_vsprintf.c lib_avsprintf.c lib_vsnprintf.c lib_libvsprintf.c \
- lib_meminstream.c lib_memoutstream.c lib_lowinstream.c \
- lib_lowoutstream.c lib_zeroinstream.c lib_nullinstream.c \
- lib_nulloutstream.c lib_sscanf.c
+ lib_sprintf.c lib_asprintf.c lib_snprintf.c lib_libsprintf.c \
+ lib_vsprintf.c lib_avsprintf.c lib_vsnprintf.c lib_libvsprintf.c \
+ lib_meminstream.c lib_memoutstream.c lib_lowinstream.c \
+ lib_lowoutstream.c lib_zeroinstream.c lib_nullinstream.c \
+ lib_nulloutstream.c lib_sscanf.c
+
+# The remaining sources files depend upon file descriptors
ifneq ($(CONFIG_NFILE_DESCRIPTORS),0)
+
CSRCS += lib_rawinstream.c lib_rawoutstream.c
+
+# And these depend upon both file descriptors and C streams
+
ifneq ($(CONFIG_NFILE_STREAMS),0)
+
CSRCS += lib_fopen.c lib_fclose.c lib_fread.c lib_libfread.c lib_fseek.c \
- lib_ftell.c lib_fsetpos.c lib_fgetpos.c lib_fgetc.c lib_fgets.c \
- lib_gets.c lib_fwrite.c lib_libfwrite.c lib_fflush.c \
- lib_libflushall.c lib_libfflush.c lib_rdflush.c lib_wrflush.c \
- lib_fputc.c lib_puts.c lib_fputs.c lib_ungetc.c lib_vprintf.c \
- lib_fprintf.c lib_vfprintf.c lib_vdprintf.c lib_stdinstream.c lib_stdoutstream.c \
- lib_perror.c
+ lib_ftell.c lib_fsetpos.c lib_fgetpos.c lib_fgetc.c lib_fgets.c \
+ lib_gets.c lib_fwrite.c lib_libfwrite.c lib_fflush.c \
+ lib_libflushall.c lib_libfflush.c lib_rdflush.c lib_wrflush.c \
+ lib_fputc.c lib_puts.c lib_fputs.c lib_ungetc.c lib_vprintf.c \
+ lib_fprintf.c lib_vfprintf.c lib_stdinstream.c lib_stdoutstream.c \
+ lib_perror.c lib_feof.c lib_ferror.c lib_clearerr.c
+
endif
endif
+# Other support that depends on specific, configured features.
+
ifeq ($(CONFIG_SYSLOG),y)
CSRCS += lib_syslogstream.c
endif
diff --git a/nuttx/lib/stdio/lib_asprintf.c b/nuttx/libc/stdio/lib_asprintf.c
index 84aaafa46..20ca6de32 100644
--- a/nuttx/lib/stdio/lib_asprintf.c
+++ b/nuttx/libc/stdio/lib_asprintf.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/stdio/lib_asprintf.c
+ * libc/stdio/lib_asprintf.c
*
* Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/stdio/lib_avsprintf.c b/nuttx/libc/stdio/lib_avsprintf.c
index 8561b97c2..15ff8c9fb 100644
--- a/nuttx/lib/stdio/lib_avsprintf.c
+++ b/nuttx/libc/stdio/lib_avsprintf.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/stdio/lib_avsprintf.c
+ * libc/stdio/lib_avsprintf.c
*
* Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/libc/stdio/lib_clearerr.c b/nuttx/libc/stdio/lib_clearerr.c
new file mode 100644
index 000000000..589b56feb
--- /dev/null
+++ b/nuttx/libc/stdio/lib_clearerr.c
@@ -0,0 +1,69 @@
+/****************************************************************************
+ * libc/stdio/lib_clearerr.c
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdio.h>
+#include <errno.h>
+
+#include <nuttx/fs/fs.h>
+
+#if CONFIG_NFILE_STREAMS > 0
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: Functions
+ *
+ * Description:
+ * Clear any end-of-file or error conditions.
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+void clearerr(FILE *stream)
+{
+ stream->fs_flags = 0;
+}
+#endif /* CONFIG_NFILE_STREAMS */
+
diff --git a/nuttx/lib/stdio/lib_dtoa.c b/nuttx/libc/stdio/lib_dtoa.c
index b8c7db980..44290ae32 100644
--- a/nuttx/lib/stdio/lib_dtoa.c
+++ b/nuttx/libc/stdio/lib_dtoa.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/stdio/lib_dtoa.c
+ * libc/stdio/lib_dtoa.c
*
* This file was ported to NuttX by Yolande Cates.
*
diff --git a/nuttx/lib/stdio/lib_fclose.c b/nuttx/libc/stdio/lib_fclose.c
index 8cecb8af3..c04537adf 100644
--- a/nuttx/lib/stdio/lib_fclose.c
+++ b/nuttx/libc/stdio/lib_fclose.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/stdio/lib_fclose.c
+ * libc/stdio/lib_fclose.c
*
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/libc/stdio/lib_feof.c b/nuttx/libc/stdio/lib_feof.c
new file mode 100644
index 000000000..e036398fd
--- /dev/null
+++ b/nuttx/libc/stdio/lib_feof.c
@@ -0,0 +1,77 @@
+/****************************************************************************
+ * libc/stdio/lib_feof.c
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdio.h>
+#include <errno.h>
+
+#include <nuttx/fs/fs.h>
+
+#if CONFIG_NFILE_STREAMS > 0
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: feof
+ *
+ * Description:
+ * The feof() function shall test if the currently file pointer for the
+ * stream is at the end of file.
+ *
+ * Returned Value:
+ * This function will return non-zero if the the file pointer is positioned
+ * at the end of file.
+ *
+ ****************************************************************************/
+
+int feof(FILE *stream)
+{
+ /* If the end-of-file condition is encountered by any of the C-buffered
+ * I/O functions that perform read operations, they should set the
+ * __FS_FLAG_EOF in the fs_flags field of struct file_struct.
+ */
+
+ return (stream->fs_flags & __FS_FLAG_EOF) != 0;
+}
+
+#endif /* CONFIG_NFILE_STREAMS */
+
diff --git a/nuttx/libc/stdio/lib_ferror.c b/nuttx/libc/stdio/lib_ferror.c
new file mode 100644
index 000000000..a977394cb
--- /dev/null
+++ b/nuttx/libc/stdio/lib_ferror.c
@@ -0,0 +1,90 @@
+/****************************************************************************
+ * libc/stdio/lib_ferror.c
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdio.h>
+#include <errno.h>
+
+#include <nuttx/fs/fs.h>
+
+#if CONFIG_NFILE_STREAMS > 0
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: ferror
+ *
+ * Description:
+ * This function will test if the last operation resulted in an eror. This
+ * is used to disambiguate EOF and error conditions.
+ *
+ * Return Value:
+ * A non-zero value is returned to indicate the error condition.
+ *
+ ****************************************************************************/
+
+int ferror(FILE *stream)
+{
+#if 0
+ /* If an error is encountered by any of the C-buffered I/O functions, they
+ * should set the __FS_FLAG_ERROR in the fs_flags field of struct
+ * file_struct.
+ */
+
+ return (stream->fs_flags & __FS_FLAG_ERROR) != 0;
+#else
+ /* However, nothing currenlty sets the __FS_FLAG_ERROR flag (that is a job
+ * for another day). The __FS_FLAG_EOF is set by operations that perform
+ * read operations. Since ferror() is probably only called to disambiguate
+ * the meaning of other functions that return EOF, to indicate either EOF or
+ * an error, just testing for not EOF is probably sufficient for now.
+ *
+ * This approach would not work if ferror() is called in other contexts. In
+ * those cases, ferror() will always report an error.
+ */
+
+ return (stream->fs_flags & __FS_FLAG_EOF) == 0;
+#endif
+}
+
+#endif /* CONFIG_NFILE_STREAMS */
+
diff --git a/nuttx/lib/stdio/lib_fflush.c b/nuttx/libc/stdio/lib_fflush.c
index d0b5e0185..a84a14a59 100644
--- a/nuttx/lib/stdio/lib_fflush.c
+++ b/nuttx/libc/stdio/lib_fflush.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/stdio/lib_fflush.c
+ * libc/stdio/lib_fflush.c
*
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/stdio/lib_fgetc.c b/nuttx/libc/stdio/lib_fgetc.c
index 4b3d0ec44..81e2e4ba7 100644
--- a/nuttx/lib/stdio/lib_fgetc.c
+++ b/nuttx/libc/stdio/lib_fgetc.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/stdio/lib_fgetc.c
+ * libc/stdio/lib_fgetc.c
*
* Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/stdio/lib_fgetpos.c b/nuttx/libc/stdio/lib_fgetpos.c
index e9e9f4d10..7663ca2db 100644
--- a/nuttx/lib/stdio/lib_fgetpos.c
+++ b/nuttx/libc/stdio/lib_fgetpos.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/stdio/lib_fgetpos.c
+ * libc/stdio/lib_fgetpos.c
*
* Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/stdio/lib_fgets.c b/nuttx/libc/stdio/lib_fgets.c
index a4f9089ed..35d024ebb 100644
--- a/nuttx/lib/stdio/lib_fgets.c
+++ b/nuttx/libc/stdio/lib_fgets.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/stdio/lib_fgets.c
+ * libc/stdio/lib_fgets.c
*
* Copyright (C) 2007-2008, 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
@@ -150,7 +150,7 @@ char *fgets(FAR char *buf, int buflen, FILE *stream)
if (ch == '\n')
#elif defined(CONFIG_EOL_IS_CR)
if (ch == '\r')
-#elif CONFIG_EOL_IS_EITHER_CRLF
+#else /* elif CONFIG_EOL_IS_EITHER_CRLF */
if (ch == '\n' || ch == '\r')
#endif
{
diff --git a/nuttx/lib/stdio/lib_fileno.c b/nuttx/libc/stdio/lib_fileno.c
index fca08fc0d..f227aa372 100644
--- a/nuttx/lib/stdio/lib_fileno.c
+++ b/nuttx/libc/stdio/lib_fileno.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/stdio/lib_fileno.c
+ * libc/stdio/lib_fileno.c
*
* Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/stdio/lib_fopen.c b/nuttx/libc/stdio/lib_fopen.c
index 29ff4569c..cb68b3584 100644
--- a/nuttx/lib/stdio/lib_fopen.c
+++ b/nuttx/libc/stdio/lib_fopen.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/stdio/lib_fopen.c
+ * libc/stdio/lib_fopen.c
*
* Copyright (C) 2007-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/stdio/lib_fprintf.c b/nuttx/libc/stdio/lib_fprintf.c
index a803de4bd..5b6fe58f4 100644
--- a/nuttx/lib/stdio/lib_fprintf.c
+++ b/nuttx/libc/stdio/lib_fprintf.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/stdio/lib_fprintf.c
+ * libc/stdio/lib_fprintf.c
*
* Copyright (C) 2007, 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/stdio/lib_fputc.c b/nuttx/libc/stdio/lib_fputc.c
index 121161f10..5d8065b43 100644
--- a/nuttx/lib/stdio/lib_fputc.c
+++ b/nuttx/libc/stdio/lib_fputc.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/stdio/lib_fputc.c
+ * libc/stdio/lib_fputc.c
*
* Copyright (C) 2007, 2008, 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/stdio/lib_fputs.c b/nuttx/libc/stdio/lib_fputs.c
index 2d6217d4a..7b87a89d0 100644
--- a/nuttx/lib/stdio/lib_fputs.c
+++ b/nuttx/libc/stdio/lib_fputs.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/stdio/lib_fputs.c
+ * libc/stdio/lib_fputs.c
*
* Copyright (C) 2007, 2008, 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/stdio/lib_fread.c b/nuttx/libc/stdio/lib_fread.c
index 4a4b29256..671714122 100644
--- a/nuttx/lib/stdio/lib_fread.c
+++ b/nuttx/libc/stdio/lib_fread.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/stdio/lib_fread.c
+ * libc/stdio/lib_fread.c
*
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/stdio/lib_fseek.c b/nuttx/libc/stdio/lib_fseek.c
index 7380f83b3..36216d94a 100644
--- a/nuttx/lib/stdio/lib_fseek.c
+++ b/nuttx/libc/stdio/lib_fseek.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/stdio/lib_fseek.c
+ * libc/stdio/lib_fseek.c
*
* Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/stdio/lib_fsetpos.c b/nuttx/libc/stdio/lib_fsetpos.c
index 13d556521..3d79a1877 100644
--- a/nuttx/lib/stdio/lib_fsetpos.c
+++ b/nuttx/libc/stdio/lib_fsetpos.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/stdio/lib_fsetpos.c
+ * libc/stdio/lib_fsetpos.c
*
* Copyright (C) 2008, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/stdio/lib_ftell.c b/nuttx/libc/stdio/lib_ftell.c
index 947648152..99fc20f34 100644
--- a/nuttx/lib/stdio/lib_ftell.c
+++ b/nuttx/libc/stdio/lib_ftell.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/stdio/lib_ftell.c
+ * libc/stdio/lib_ftell.c
*
* Copyright (C) 2008, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/stdio/lib_fwrite.c b/nuttx/libc/stdio/lib_fwrite.c
index 60e001746..e8de004fe 100644
--- a/nuttx/lib/stdio/lib_fwrite.c
+++ b/nuttx/libc/stdio/lib_fwrite.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/stdio/lib_fwrite.c
+ * libc/stdio/lib_fwrite.c
*
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/stdio/lib_gets.c b/nuttx/libc/stdio/lib_gets.c
index 95a6b36eb..39c31d273 100644
--- a/nuttx/lib/stdio/lib_gets.c
+++ b/nuttx/libc/stdio/lib_gets.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/stdio/lib_gets.c
+ * libc/stdio/lib_gets.c
*
* Copyright (C) 2007-2008, 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/stdio/lib_libdtoa.c b/nuttx/libc/stdio/lib_libdtoa.c
index 667c49c53..29f61fd76 100644
--- a/nuttx/lib/stdio/lib_libdtoa.c
+++ b/nuttx/libc/stdio/lib_libdtoa.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/unistd/lib_libdtoa.c
+ * libc/unistd/lib_libdtoa.c
*
* This file was ported to NuttX by Yolande Cates.
*
diff --git a/nuttx/lib/stdio/lib_libfflush.c b/nuttx/libc/stdio/lib_libfflush.c
index 2a4fe2932..f2f0cfe14 100644
--- a/nuttx/lib/stdio/lib_libfflush.c
+++ b/nuttx/libc/stdio/lib_libfflush.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/stdio/lib_libfflush.c
+ * libc/stdio/lib_libfflush.c
*
* Copyright (C) 2007-2008, 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/stdio/lib_libflushall.c b/nuttx/libc/stdio/lib_libflushall.c
index 9d0a89e9c..7ac3da7e0 100644
--- a/nuttx/lib/stdio/lib_libflushall.c
+++ b/nuttx/libc/stdio/lib_libflushall.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/stdio/lib_libflushall.c
+ * libc/stdio/lib_libflushall.c
*
* Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/stdio/lib_libfread.c b/nuttx/libc/stdio/lib_libfread.c
index 03b47eda6..bc6479037 100644
--- a/nuttx/lib/stdio/lib_libfread.c
+++ b/nuttx/libc/stdio/lib_libfread.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/stdio/lib_libfread.c
+ * libc/stdio/lib_libfread.c
*
* Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
@@ -187,7 +187,10 @@ ssize_t lib_fread(FAR void *ptr, size_t count, FAR FILE *stream)
}
else if (bytes_read == 0)
{
- /* We are at the end of the file */
+ /* We are at the end of the file. But we may already
+ * have buffered data. In that case, we will report
+ * the EOF indication later.
+ */
goto shortread;
}
@@ -232,7 +235,10 @@ ssize_t lib_fread(FAR void *ptr, size_t count, FAR FILE *stream)
}
else if (bytes_read == 0)
{
- /* We are at the end of the file */
+ /* We are at the end of the file. But we may already
+ * have buffered data. In that case, we will report
+ * the EOF indication later.
+ */
goto shortread;
}
@@ -261,6 +267,11 @@ ssize_t lib_fread(FAR void *ptr, size_t count, FAR FILE *stream)
}
else if (bytes_read == 0)
{
+ /* We are at the end of the file. But we may already
+ * have buffered data. In that case, we will report
+ * the EOF indication later.
+ */
+
break;
}
else
@@ -270,12 +281,26 @@ ssize_t lib_fread(FAR void *ptr, size_t count, FAR FILE *stream)
}
}
#endif
- /* Here after a successful (but perhaps short) read */
+ /* Here after a successful (but perhaps short) read */
#if CONFIG_STDIO_BUFFER_SIZE > 0
shortread:
#endif
bytes_read = dest - (unsigned char*)ptr;
+
+ /* Set or clear the EOF indicator. If we get here because of a
+ * short read and the total number of* bytes read is zero, then
+ * we must be at the end-of-file.
+ */
+
+ if (bytes_read > 0)
+ {
+ stream->fs_flags &= ~__FS_FLAG_EOF;
+ }
+ else
+ {
+ stream->fs_flags |= __FS_FLAG_EOF;
+ }
}
lib_give_semaphore(stream);
diff --git a/nuttx/lib/stdio/lib_libfwrite.c b/nuttx/libc/stdio/lib_libfwrite.c
index e71866b49..b917b3b56 100644
--- a/nuttx/lib/stdio/lib_libfwrite.c
+++ b/nuttx/libc/stdio/lib_libfwrite.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/stdio/lib_libfwrite.c
+ * libc/stdio/lib_libfwrite.c
*
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/stdio/lib_libnoflush.c b/nuttx/libc/stdio/lib_libnoflush.c
index e3b891153..076f8a17e 100644
--- a/nuttx/lib/stdio/lib_libnoflush.c
+++ b/nuttx/libc/stdio/lib_libnoflush.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/stdio/lib_libnoflush.c
+ * libc/stdio/lib_libnoflush.c
*
* Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/stdio/lib_libsprintf.c b/nuttx/libc/stdio/lib_libsprintf.c
index 2474a6f01..2d820ab37 100644
--- a/nuttx/lib/stdio/lib_libsprintf.c
+++ b/nuttx/libc/stdio/lib_libsprintf.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/stdio/lib_libsprintf.c
+ * libc/stdio/lib_libsprintf.c
*
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/stdio/lib_libvsprintf.c b/nuttx/libc/stdio/lib_libvsprintf.c
index 30c988599..9a391610d 100644
--- a/nuttx/lib/stdio/lib_libvsprintf.c
+++ b/nuttx/libc/stdio/lib_libvsprintf.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/stdio/lib_libvsprintf.c
+ * libc/stdio/lib_libvsprintf.c
*
* Copyright (C) 2007-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
@@ -1161,7 +1161,7 @@ static void postjustify(FAR struct lib_outstream_s *obj, uint8_t fmt,
****************************************************************************/
/****************************************************************************
- * lib/stdio/lib_vsprintf
+ * libc/stdio/lib_vsprintf
****************************************************************************/
int lib_vsprintf(FAR struct lib_outstream_s *obj, FAR const char *src, va_list ap)
diff --git a/nuttx/lib/stdio/lib_lowinstream.c b/nuttx/libc/stdio/lib_lowinstream.c
index 499a647ea..7284601e8 100644
--- a/nuttx/lib/stdio/lib_lowinstream.c
+++ b/nuttx/libc/stdio/lib_lowinstream.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/stdio/lib_lowinstream.c
+ * libc/stdio/lib_lowinstream.c
*
* Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/stdio/lib_lowoutstream.c b/nuttx/libc/stdio/lib_lowoutstream.c
index 092f39ca2..f600bc614 100644
--- a/nuttx/lib/stdio/lib_lowoutstream.c
+++ b/nuttx/libc/stdio/lib_lowoutstream.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/stdio/lib_lowoutstream.c
+ * libc/stdio/lib_lowoutstream.c
*
* Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/stdio/lib_lowprintf.c b/nuttx/libc/stdio/lib_lowprintf.c
index 392ef2c6a..f7d4ffe2f 100644
--- a/nuttx/lib/stdio/lib_lowprintf.c
+++ b/nuttx/libc/stdio/lib_lowprintf.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/stdio/lib_lowprintf.c
+ * libc/stdio/lib_lowprintf.c
*
* Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/stdio/lib_meminstream.c b/nuttx/libc/stdio/lib_meminstream.c
index a842096fb..2a30d956d 100644
--- a/nuttx/lib/stdio/lib_meminstream.c
+++ b/nuttx/libc/stdio/lib_meminstream.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/stdio/lib_meminstream.c
+ * libc/stdio/lib_meminstream.c
*
* Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/stdio/lib_memoutstream.c b/nuttx/libc/stdio/lib_memoutstream.c
index 21197358b..efd527cbc 100644
--- a/nuttx/lib/stdio/lib_memoutstream.c
+++ b/nuttx/libc/stdio/lib_memoutstream.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/stdio/lib_memoutstream.c
+ * libc/stdio/lib_memoutstream.c
*
* Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/stdio/lib_nullinstream.c b/nuttx/libc/stdio/lib_nullinstream.c
index 0eadb0a8e..aeb0af379 100644
--- a/nuttx/lib/stdio/lib_nullinstream.c
+++ b/nuttx/libc/stdio/lib_nullinstream.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/stdio/lib_nullinstream.c
+ * libc/stdio/lib_nullinstream.c
*
* Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/stdio/lib_nulloutstream.c b/nuttx/libc/stdio/lib_nulloutstream.c
index 69878fd57..574295344 100644
--- a/nuttx/lib/stdio/lib_nulloutstream.c
+++ b/nuttx/libc/stdio/lib_nulloutstream.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/stdio/lib_nulloutstream.c
+ * libc/stdio/lib_nulloutstream.c
*
* Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/stdio/lib_perror.c b/nuttx/libc/stdio/lib_perror.c
index 867e113f9..181898329 100644
--- a/nuttx/lib/stdio/lib_perror.c
+++ b/nuttx/libc/stdio/lib_perror.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/stdio/lib_perror.c
+ * libc/stdio/lib_perror.c
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/stdio/lib_printf.c b/nuttx/libc/stdio/lib_printf.c
index 50db06c47..0e90c7ca5 100644
--- a/nuttx/lib/stdio/lib_printf.c
+++ b/nuttx/libc/stdio/lib_printf.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/stdio/lib_printf.c
+ * libc/stdio/lib_printf.c
*
* Copyright (C) 2007-2008, 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/stdio/lib_puts.c b/nuttx/libc/stdio/lib_puts.c
index e63a63917..53eda7081 100644
--- a/nuttx/lib/stdio/lib_puts.c
+++ b/nuttx/libc/stdio/lib_puts.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/stdio/lib_puts.c
+ * libc/stdio/lib_puts.c
*
* Copyright (C) 2007, 2008, 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/stdio/lib_rawinstream.c b/nuttx/libc/stdio/lib_rawinstream.c
index 9671a2716..55456769e 100644
--- a/nuttx/lib/stdio/lib_rawinstream.c
+++ b/nuttx/libc/stdio/lib_rawinstream.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/stdio/lib_rawinstream.c
+ * libc/stdio/lib_rawinstream.c
*
* Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/stdio/lib_rawoutstream.c b/nuttx/libc/stdio/lib_rawoutstream.c
index ed813f87a..e1fe37134 100644
--- a/nuttx/lib/stdio/lib_rawoutstream.c
+++ b/nuttx/libc/stdio/lib_rawoutstream.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/stdio/lib_rawoutstream.c
+ * libc/stdio/lib_rawoutstream.c
*
* Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/stdio/lib_rawprintf.c b/nuttx/libc/stdio/lib_rawprintf.c
index 1a6eb16b7..98bbbea05 100644
--- a/nuttx/lib/stdio/lib_rawprintf.c
+++ b/nuttx/libc/stdio/lib_rawprintf.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/stdio/lib_rawprintf.c
+ * libc/stdio/lib_rawprintf.c
*
* Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
@@ -149,18 +149,3 @@ int lib_rawprintf(const char *fmt, ...)
return ret;
}
-
-
-/****************************************************************************
- * Name: lib_rawvdprintf
- ****************************************************************************/
-
-int lib_rawvdprintf(int fd, const char *fmt, va_list ap)
-{
- /* Wrap the stdout in a stream object and let lib_vsprintf
- * do the work.
- */
- struct lib_rawoutstream_s rawoutstream;
- lib_rawoutstream(&rawoutstream, fd);
- return lib_vsprintf(&rawoutstream.public, fmt, ap);
-}
diff --git a/nuttx/lib/stdio/lib_rdflush.c b/nuttx/libc/stdio/lib_rdflush.c
index 35c5495c1..c6136792b 100644
--- a/nuttx/lib/stdio/lib_rdflush.c
+++ b/nuttx/libc/stdio/lib_rdflush.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/stdio/lib_rdflush.c
+ * libc/stdio/lib_rdflush.c
*
* Copyright (C) 2008, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/stdio/lib_snprintf.c b/nuttx/libc/stdio/lib_snprintf.c
index e5ce7b0f0..a4ba0dbb3 100644
--- a/nuttx/lib/stdio/lib_snprintf.c
+++ b/nuttx/libc/stdio/lib_snprintf.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/stdio/lib_snprintf.c
+ * libc/stdio/lib_snprintf.c
*
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/stdio/lib_sprintf.c b/nuttx/libc/stdio/lib_sprintf.c
index 89fd61033..deb0669a3 100644
--- a/nuttx/lib/stdio/lib_sprintf.c
+++ b/nuttx/libc/stdio/lib_sprintf.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/stdio/lib_sprintf.c
+ * libc/stdio/lib_sprintf.c
*
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/stdio/lib_sscanf.c b/nuttx/libc/stdio/lib_sscanf.c
index 7e1fae276..77a6cf212 100644
--- a/nuttx/lib/stdio/lib_sscanf.c
+++ b/nuttx/libc/stdio/lib_sscanf.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/stdio/lib_sscanf.c
+ * libc/stdio/lib_sscanf.c
*
* Copyright (C) 2007, 2008, 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/stdio/lib_stdinstream.c b/nuttx/libc/stdio/lib_stdinstream.c
index 77aab9ec8..261b26634 100644
--- a/nuttx/lib/stdio/lib_stdinstream.c
+++ b/nuttx/libc/stdio/lib_stdinstream.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/stdio/lib_stdinstream.c
+ * libc/stdio/lib_stdinstream.c
*
* Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/stdio/lib_stdoutstream.c b/nuttx/libc/stdio/lib_stdoutstream.c
index 20da5b702..dfe67271f 100644
--- a/nuttx/lib/stdio/lib_stdoutstream.c
+++ b/nuttx/libc/stdio/lib_stdoutstream.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/stdio/lib_stdoutstream.c
+ * libc/stdio/lib_stdoutstream.c
*
* Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/stdio/lib_syslogstream.c b/nuttx/libc/stdio/lib_syslogstream.c
index 21151b43a..5529c5de8 100644
--- a/nuttx/lib/stdio/lib_syslogstream.c
+++ b/nuttx/libc/stdio/lib_syslogstream.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/stdio/lib_syslogstream.c
+ * libc/stdio/lib_syslogstream.c
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/stdio/lib_ungetc.c b/nuttx/libc/stdio/lib_ungetc.c
index c10d4fba1..178aeddd1 100644
--- a/nuttx/lib/stdio/lib_ungetc.c
+++ b/nuttx/libc/stdio/lib_ungetc.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/stdio/lib_ungetc.c
+ * libc/stdio/lib_ungetc.c
*
* Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/stdio/lib_vfprintf.c b/nuttx/libc/stdio/lib_vfprintf.c
index 1c3a2d7fc..cd117ddc3 100644
--- a/nuttx/lib/stdio/lib_vfprintf.c
+++ b/nuttx/libc/stdio/lib_vfprintf.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/stdio/lib_vfprintf.c
+ * libc/stdio/lib_vfprintf.c
*
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/stdio/lib_vprintf.c b/nuttx/libc/stdio/lib_vprintf.c
index d085d5886..6ddfe2b24 100644
--- a/nuttx/lib/stdio/lib_vprintf.c
+++ b/nuttx/libc/stdio/lib_vprintf.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/stdio/lib_vprintf.c
+ * libc/stdio/lib_vprintf.c
*
* Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/stdio/lib_vsnprintf.c b/nuttx/libc/stdio/lib_vsnprintf.c
index c6f52092d..f7fd02e42 100644
--- a/nuttx/lib/stdio/lib_vsnprintf.c
+++ b/nuttx/libc/stdio/lib_vsnprintf.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/stdio/lib_vsnprintf.c
+ * libc/stdio/lib_vsnprintf.c
*
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/stdio/lib_vsprintf.c b/nuttx/libc/stdio/lib_vsprintf.c
index 5db46664e..b6d80808f 100644
--- a/nuttx/lib/stdio/lib_vsprintf.c
+++ b/nuttx/libc/stdio/lib_vsprintf.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/stdio/lib_vsprintf.c
+ * libc/stdio/lib_vsprintf.c
*
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
@@ -84,7 +84,7 @@ int vsprintf(FAR char *dest, const char *src, va_list ap)
struct lib_memoutstream_s memoutstream;
/* Wrap the destination buffer in a stream object and let
- * lib/stdio/lib_vsprintf do the work.
+ * libc/stdio/lib_vsprintf do the work.
*/
lib_memoutstream((FAR struct lib_memoutstream_s *)&memoutstream, dest, LIB_BUFLEN_UNKNOWN);
diff --git a/nuttx/lib/stdio/lib_wrflush.c b/nuttx/libc/stdio/lib_wrflush.c
index 39680da6a..40b8e38c8 100644
--- a/nuttx/lib/stdio/lib_wrflush.c
+++ b/nuttx/libc/stdio/lib_wrflush.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/stdio/lib_wrflush.c
+ * libc/stdio/lib_wrflush.c
*
* Copyright (C) 2008-2009, 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/stdio/lib_zeroinstream.c b/nuttx/libc/stdio/lib_zeroinstream.c
index 39a6c22ef..a52ecc1d0 100644
--- a/nuttx/lib/stdio/lib_zeroinstream.c
+++ b/nuttx/libc/stdio/lib_zeroinstream.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/stdio/lib_zeroinstream.c
+ * libc/stdio/lib_zeroinstream.c
*
* Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/stdlib/Make.defs b/nuttx/libc/stdlib/Make.defs
index 76e285808..dcc4dab26 100644
--- a/nuttx/lib/stdlib/Make.defs
+++ b/nuttx/libc/stdlib/Make.defs
@@ -1,5 +1,5 @@
############################################################################
-# lib/stdlib/Make.defs
+# libc/stdlib/Make.defs
#
# Copyright (C) 2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/stdlib/lib_abort.c b/nuttx/libc/stdlib/lib_abort.c
index 84b600950..1c7442c7f 100644
--- a/nuttx/lib/stdlib/lib_abort.c
+++ b/nuttx/libc/stdlib/lib_abort.c
@@ -1,5 +1,5 @@
/************************************************************************
- * lib/stdlib/lib_abort.c
+ * libc/stdlib/lib_abort.c
*
* Copyright (C) 2007, 2009, 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/stdlib/lib_abs.c b/nuttx/libc/stdlib/lib_abs.c
index 1a0c1671c..a4e4ec669 100644
--- a/nuttx/lib/stdlib/lib_abs.c
+++ b/nuttx/libc/stdlib/lib_abs.c
@@ -1,5 +1,5 @@
/************************************************************************
- * lib/stdlib/lib_abs.c
+ * libc/stdlib/lib_abs.c
*
* Copyright (C) 2010-2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/stdlib/lib_imaxabs.c b/nuttx/libc/stdlib/lib_imaxabs.c
index c6e227c7d..d36504372 100644
--- a/nuttx/lib/stdlib/lib_imaxabs.c
+++ b/nuttx/libc/stdlib/lib_imaxabs.c
@@ -1,5 +1,5 @@
/************************************************************************
- * lib/stdlib//lib_abs.c
+ * libc/stdlib//lib_abs.c
*
* Copyright (C) 2010-2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/stdlib/lib_labs.c b/nuttx/libc/stdlib/lib_labs.c
index f7218ee83..7cf92a0a1 100644
--- a/nuttx/lib/stdlib/lib_labs.c
+++ b/nuttx/libc/stdlib/lib_labs.c
@@ -1,5 +1,5 @@
/************************************************************************
- * lib/stdlib/lib_labs.c
+ * libc/stdlib/lib_labs.c
*
* Copyright (C) 2010-2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/stdlib/lib_llabs.c b/nuttx/libc/stdlib/lib_llabs.c
index db7d3dbe0..3630d1716 100644
--- a/nuttx/lib/stdlib/lib_llabs.c
+++ b/nuttx/libc/stdlib/lib_llabs.c
@@ -1,5 +1,5 @@
/************************************************************************
- * lib/stdlib/lib_llabs.c
+ * libc/stdlib/lib_llabs.c
*
* Copyright (C) 2010-2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/stdlib/lib_qsort.c b/nuttx/libc/stdlib/lib_qsort.c
index 9dd5c0040..021e782d4 100644
--- a/nuttx/lib/stdlib/lib_qsort.c
+++ b/nuttx/libc/stdlib/lib_qsort.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/stdlib/lib_qsort.c
+ * libc/stdlib/lib_qsort.c
*
* Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/libc/stdlib/lib_rand.c b/nuttx/libc/stdlib/lib_rand.c
new file mode 100644
index 000000000..453a4537a
--- /dev/null
+++ b/nuttx/libc/stdlib/lib_rand.c
@@ -0,0 +1,277 @@
+/****************************************************************************
+ * libc/stdlib/lib_rand.c
+ *
+ * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+#include <stdlib.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+/* First, second, and thired order congruential generators are supported */
+
+#ifndef CONFIG_LIB_RAND_ORDER
+# define CONFIG_LIB_RAND_ORDER 1
+#endif
+
+#if CONFIG_LIB_RAND_ORDER > 3
+# undef CONFIG_LIB_RAND_ORDER
+# define CONFIG_LIB_RAND_ORDER 3
+#endif
+
+/* Values needed by the random number generator */
+
+#define RND1_CONSTK 470001
+#define RND1_CONSTP 999563
+#define RND2_CONSTK1 366528
+#define RND2_CONSTK2 508531
+#define RND2_CONSTP 998917
+#define RND3_CONSTK1 360137
+#define RND3_CONSTK2 519815
+#define RND3_CONSTK3 616087
+#define RND3_CONSTP 997783
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static unsigned int nrand(unsigned int nLimit);
+
+/* First order congruential generators */
+
+static inline unsigned long fgenerate1(void);
+#if (CONFIG_LIB_RAND_ORDER == 1)
+static double_t frand1(void);
+#endif
+
+/* Second order congruential generators */
+
+#if (CONFIG_LIB_RAND_ORDER > 1)
+static inline unsigned long fgenerate2(void);
+#if (CONFIG_LIB_RAND_ORDER == 2)
+static double_t frand2(void);
+#endif
+
+/* Third order congruential generators */
+
+#if (CONFIG_LIB_RAND_ORDER > 2)
+static inline unsigned long fgenerate3(void);
+static double_t frand3(void);
+#endif
+#endif
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static unsigned long g_randint1;
+#if (CONFIG_LIB_RAND_ORDER > 1)
+static unsigned long g_randint2;
+#if (CONFIG_LIB_RAND_ORDER > 2)
+static unsigned long g_randint3;
+#endif
+#endif
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static unsigned int nrand(unsigned int nLimit)
+{
+ unsigned long result;
+ double_t ratio;
+
+ /* Loop to be sure a legal random number is generated */
+
+ do
+ {
+ /* Get a random integer in the requested range */
+
+#if (CONFIG_LIB_RAND_ORDER == 1)
+ ratio = frand1();
+#elif (CONFIG_LIB_RAND_ORDER == 2)
+ ratio = frand2();
+#else /* if (CONFIG_LIB_RAND_ORDER > 2) */
+ ratio = frand3();
+#endif
+
+ /* Then, produce the return-able value */
+
+ result = (unsigned long)(((double_t)nLimit) * ratio);
+ }
+ while (result >= (unsigned long)nLimit);
+
+ return (unsigned int)result;
+}
+
+/* First order congruential generators */
+
+static inline unsigned long fgenerate1(void)
+{
+ unsigned long randint;
+
+ /* First order congruential generator. One may be added to the result of the
+ * generated value to avoid the value zero. This would be fatal for the
+ * first order random number generator.
+ */
+
+ randint = (RND1_CONSTK * g_randint1) % RND1_CONSTP;
+ g_randint1 = (randint == 0 ? 1 : randint);
+ return randint;
+}
+
+#if (CONFIG_LIB_RAND_ORDER == 1)
+static double_t frand1(void)
+{
+ /* First order congruential generator. */
+
+ unsigned long randint = fgenerate1();
+
+ /* Construct an floating point value in the range from 0.0 up to 1.0 */
+
+ return ((double_t)randint) / ((double_t)RND1_CONSTP);
+}
+#endif
+
+/* Second order congruential generators */
+
+#if (CONFIG_LIB_RAND_ORDER > 1)
+static inline unsigned long fgenerate2(void)
+{
+ unsigned long randint;
+
+ /* Second order congruential generator. */
+
+ randint = (RND2_CONSTK1 * g_randint1 +
+ RND2_CONSTK2 * g_randint2) % RND2_CONSTP;
+
+ g_randint2 = g_randint1;
+ g_randint1 = randint;
+
+ /* We cannot permit both values to become zero. That would be fatal for the
+ * second order random number generator.
+ */
+
+ if (g_randint2 == 0 && g_randint1 == 0)
+ {
+ g_randint2 = 1;
+ }
+
+ return randint;
+}
+
+#if (CONFIG_LIB_RAND_ORDER == 2)
+static double_t frand2(void)
+{
+ /* Second order congruential generator */
+
+ unsigned long randint = fgenerate2();
+
+ /* Construct an floating point value in the range from 0.0 up to 1.0 */
+
+ return ((double_t)randint) / ((double_t)RND2_CONSTP);
+}
+#endif
+
+/* Third order congruential generators */
+
+#if (CONFIG_LIB_RAND_ORDER > 2)
+static inline unsigned long fgenerate3(void)
+{
+ unsigned long randint;
+
+ /* Third order congruential generator. */
+
+ randint = (RND3_CONSTK1 * g_randint1 +
+ RND3_CONSTK2 * g_randint2 +
+ RND3_CONSTK2 * g_randint3) % RND3_CONSTP;
+
+ g_randint3 = g_randint2;
+ g_randint2 = g_randint1;
+ g_randint1 = randint;
+
+ /* We cannot permit all three values to become zero. That would be fatal for the
+ * third order random number generator.
+ */
+
+ if (g_randint3 == 0 && g_randint2 == 0 && g_randint1 == 0)
+ {
+ g_randint3 = 1;
+ }
+
+ return randint;
+}
+
+static double_t frand3(void)
+{
+ /* Third order congruential generator */
+
+ unsigned long randint = fgenerate3();
+
+ /* Construct an floating point value in the range from 0.0 up to 1.0 */
+
+ return ((double_t)randint) / ((double_t)RND3_CONSTP);
+}
+#endif
+#endif
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Function: srand, rand
+ ****************************************************************************/
+
+void srand(unsigned int seed)
+{
+ g_randint1 = seed;
+#if (CONFIG_LIB_RAND_ORDER > 1)
+ g_randint2 = seed;
+ (void)fgenerate1();
+#if (CONFIG_LIB_RAND_ORDER > 2)
+ g_randint3 = seed;
+ (void)fgenerate2();
+#endif
+#endif
+}
+
+int rand(void)
+{
+ return (int)nrand(32768);
+}
diff --git a/nuttx/lib/string/Make.defs b/nuttx/libc/string/Make.defs
index 6b21c7f14..311c8afd2 100644
--- a/nuttx/lib/string/Make.defs
+++ b/nuttx/libc/string/Make.defs
@@ -1,5 +1,5 @@
############################################################################
-# lib/string/Make.defs
+# libc/string/Make.defs
#
# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
@@ -36,7 +36,7 @@
# Add the string C files to the build
CSRCS += lib_checkbase.c lib_isbasedigit.c lib_memset.c lib_memchr.c \
- lib_memccpy.c lib_memcpy.c lib_memcmp.c lib_memmove.c lib_skipspace.c \
+ lib_memccpy.c lib_memcmp.c lib_memmove.c lib_skipspace.c \
lib_strcasecmp.c lib_strcat.c lib_strchr.c lib_strcpy.c lib_strcmp.c \
lib_strcspn.c lib_strdup.c lib_strerror.c lib_strlen.c lib_strnlen.c \
lib_strncasecmp.c lib_strncat.c lib_strncmp.c lib_strncpy.c \
@@ -44,6 +44,14 @@ CSRCS += lib_checkbase.c lib_isbasedigit.c lib_memset.c lib_memchr.c \
lib_strspn.c lib_strstr.c lib_strtok.c lib_strtokr.c lib_strtol.c \
lib_strtoll.c lib_strtoul.c lib_strtoull.c lib_strtod.c
+ifneq ($(CONFIG_ARCH_MEMCPY),y)
+ifeq ($(CONFIG_MEMCPY_VIK),y)
+CSRCS += lib_vikmemcpy.c
+else
+CSRCS += lib_memcpy.c
+endif
+endif
+
# Add the string directory to the build
DEPPATH += --dep-path string
diff --git a/nuttx/lib/string/lib_checkbase.c b/nuttx/libc/string/lib_checkbase.c
index bc79ab2ce..32ae58dca 100644
--- a/nuttx/lib/string/lib_checkbase.c
+++ b/nuttx/libc/string/lib_checkbase.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/string/lib_checkbase.c
+ * libc/string/lib_checkbase.c
*
* Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/string/lib_isbasedigit.c b/nuttx/libc/string/lib_isbasedigit.c
index a2421bf2a..dff813881 100644
--- a/nuttx/lib/string/lib_isbasedigit.c
+++ b/nuttx/libc/string/lib_isbasedigit.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/string/lib_isbasedigit.c
+ * libc/string/lib_isbasedigit.c
*
* Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/string/lib_memccpy.c b/nuttx/libc/string/lib_memccpy.c
index 1f3dbb52d..1d77f58fe 100644
--- a/nuttx/lib/string/lib_memccpy.c
+++ b/nuttx/libc/string/lib_memccpy.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/string/lib_memccpy.c
+ * libc/string/lib_memccpy.c
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/string/lib_memchr.c b/nuttx/libc/string/lib_memchr.c
index e0dec8270..0ac609104 100644
--- a/nuttx/lib/string/lib_memchr.c
+++ b/nuttx/libc/string/lib_memchr.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/string/lib_memchr.c
+ * libc/string/lib_memchr.c
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/string/lib_memcmp.c b/nuttx/libc/string/lib_memcmp.c
index eb2e1fd12..5434bb847 100644
--- a/nuttx/lib/string/lib_memcmp.c
+++ b/nuttx/libc/string/lib_memcmp.c
@@ -1,7 +1,7 @@
/************************************************************
- * lib/string/lib_memcmp.c
+ * libc/string/lib_memcmp.c
*
- * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2007, 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -50,7 +50,7 @@
************************************************************/
#ifndef CONFIG_ARCH_MEMCMP
-int memcmp(const void *s1, const void *s2, size_t n)
+int memcmp(FAR const void *s1, FAR const void *s2, size_t n)
{
unsigned char *p1 = (unsigned char *)s1;
unsigned char *p2 = (unsigned char *)s2;
diff --git a/nuttx/lib/string/lib_memcpy.c b/nuttx/libc/string/lib_memcpy.c
index 3b62edbab..2ebd5beee 100644
--- a/nuttx/lib/string/lib_memcpy.c
+++ b/nuttx/libc/string/lib_memcpy.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/string/lib_memcpy.c
+ * libc/string/lib_memcpy.c
*
* Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/string/lib_memmove.c b/nuttx/libc/string/lib_memmove.c
index ecaeb54cf..cc8317223 100644
--- a/nuttx/lib/string/lib_memmove.c
+++ b/nuttx/libc/string/lib_memmove.c
@@ -1,5 +1,5 @@
/************************************************************
- * lib/string/lib_memmove.c
+ * libc/string/lib_memmove.c
*
* Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
@@ -50,23 +50,28 @@
************************************************************/
#ifndef CONFIG_ARCH_MEMMOVE
-void *memmove(void *dest, const void *src, size_t count)
+FAR void *memmove(FAR void *dest, FAR const void *src, size_t count)
{
char *tmp, *s;
if (dest <= src)
{
tmp = (char*) dest;
- s = (char*) src;
+ s = (char*) src;
while (count--)
- *tmp++ = *s++;
+ {
+ *tmp++ = *s++;
+ }
}
else
{
tmp = (char*) dest + count;
- s = (char*) src + count;
+ s = (char*) src + count;
while (count--)
- *--tmp = *--s;
+ {
+ *--tmp = *--s;
+ }
}
+
return dest;
}
#endif
diff --git a/nuttx/libc/string/lib_memset.c b/nuttx/libc/string/lib_memset.c
new file mode 100644
index 000000000..0b98ebf96
--- /dev/null
+++ b/nuttx/libc/string/lib_memset.c
@@ -0,0 +1,188 @@
+
+/****************************************************************************
+ * libc/string/lib_memset.c
+ *
+ * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+
+#include <stdint.h>
+#include <string.h>
+#include <assert.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Can't support CONFIG_MEMSET_64BIT if the platform does not have 64-bit
+ * integer types.
+ */
+
+#ifndef CONFIG_HAVE_LONG_LONG
+# undef CONFIG_MEMSET_64BIT
+#endif
+
+/****************************************************************************
+ * Global Functions
+ ****************************************************************************/
+
+#ifndef CONFIG_ARCH_MEMSET
+void *memset(void *s, int c, size_t n)
+{
+#ifdef CONFIG_MEMSET_OPTSPEED
+ /* This version is optimized for speed (you could do better
+ * still by exploiting processor caching or memory burst
+ * knowledge.)
+ */
+
+ uintptr_t addr = (uintptr_t)s;
+ uint16_t val16 = ((uint16_t)c << 8) | (uint16_t)c;
+ uint32_t val32 = ((uint32_t)val16 << 16) | (uint32_t)val16;
+#ifdef CONFIG_MEMSET_64BIT
+ uint64_t val64 = ((uint64_t)val32 << 32) | (uint64_t)val32;
+#endif
+
+ /* Make sure that there is something to be cleared */
+
+ if (n > 0)
+ {
+ /* Align to a 16-bit boundary */
+
+ if ((addr & 1) != 0)
+ {
+ *(uint8_t*)addr = (uint8_t)c;
+ addr += 1;
+ n -= 1;
+ }
+
+ /* Check if there are at least 16-bits left to be written */
+
+ if (n >= 2)
+ {
+ /* Align to a 32-bit boundary (we know that the destination
+ * address is already aligned to at least a 16-bit boundary).
+ */
+
+ if ((addr & 3) != 0)
+ {
+ *(uint16_t*)addr = val16;
+ addr += 2;
+ n -= 2;
+ }
+
+#ifndef CONFIG_MEMSET_64BIT
+ /* Loop while there are at least 32-bits left to be written */
+
+ while (n >= 4)
+ {
+ *(uint32_t*)addr = val32;
+ addr += 4;
+ n -= 4;
+ }
+#else
+ /* Check if there are at least 32-bits left to be written */
+
+ if (n >= 4)
+ {
+ /* Align to a 64-bit boundary (we know that the destination
+ * address is already aligned to at least a 32-bit boundary).
+ */
+
+ if ((addr & 7) != 0)
+ {
+ *(uint32_t*)addr = val32;
+ addr += 4;
+ n -= 4;
+ }
+
+ /* Loop while there are at least 64-bits left to be written */
+
+ while (n >= 8)
+ {
+ *(uint64_t*)addr = val64;
+ addr += 8;
+ n -= 8;
+ }
+ }
+#endif
+ }
+
+#ifdef CONFIG_MEMSET_64BIT
+ /* We may get here with n in the range 0..7. If n >= 4, then we should
+ * have 64-bit alignment.
+ */
+
+ if (n >= 4)
+ {
+ *(uint32_t*)addr = val32;
+ addr += 4;
+ n -= 4;
+ }
+#endif
+
+ /* We may get here under the following conditions:
+ *
+ * n = 0, addr may or may not be aligned
+ * n = 1, addr is aligned to at least a 16-bit boundary
+ * n = 2, addr is aligned to a 32-bit boundary
+ * n = 3, addr is aligned to a 32-bit boundary
+ */
+
+ if (n >= 2)
+ {
+ *(uint16_t*)addr = val16;
+ addr += 2;
+ n -= 2;
+ }
+
+ if (n >= 1)
+ {
+ *(uint8_t*)addr = (uint8_t)c;
+ }
+ }
+#else
+ /* This version is optimized for size */
+
+ unsigned char *p = (unsigned char*)s;
+ while (n-- > 0) *p++ = c;
+#endif
+ return s;
+}
+#endif
diff --git a/nuttx/lib/string/lib_skipspace.c b/nuttx/libc/string/lib_skipspace.c
index b4e6588e5..4b72b1ec3 100644
--- a/nuttx/lib/string/lib_skipspace.c
+++ b/nuttx/libc/string/lib_skipspace.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/string/lib_skipspace.c
+ * libc/string/lib_skipspace.c
*
* Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/string/lib_strcasecmp.c b/nuttx/libc/string/lib_strcasecmp.c
index d4aa8cc03..df6f08118 100644
--- a/nuttx/lib/string/lib_strcasecmp.c
+++ b/nuttx/libc/string/lib_strcasecmp.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/string/lib_strcasecmp.c
+ * libc/string/lib_strcasecmp.c
*
* Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/string/lib_strcasestr.c b/nuttx/libc/string/lib_strcasestr.c
index 23f0ab57e..7f17a686d 100644
--- a/nuttx/lib/string/lib_strcasestr.c
+++ b/nuttx/libc/string/lib_strcasestr.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/string/lib_strstr.c
+ * libc/string/lib_strstr.c
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
@@ -127,7 +127,9 @@ FAR char *strcasestr(FAR const char *str, FAR const char *substr)
candidate++;
}
- /* Won't get here, but some compilers might complain */
+ /* Won't get here, but some compilers might complain. Others might complain
+ * about this code being unreachable too.
+ */
return NULL;
}
diff --git a/nuttx/lib/string/lib_strcat.c b/nuttx/libc/string/lib_strcat.c
index 20350fec0..b331d3f1c 100644
--- a/nuttx/lib/string/lib_strcat.c
+++ b/nuttx/libc/string/lib_strcat.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/string/lib_strcat.c
+ * libc/string/lib_strcat.c
*
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/string/lib_strchr.c b/nuttx/libc/string/lib_strchr.c
index ad7273862..e6af56eee 100644
--- a/nuttx/lib/string/lib_strchr.c
+++ b/nuttx/libc/string/lib_strchr.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/string/lib_strchr.c
+ * libc/string/lib_strchr.c
*
* Copyright (C) 2007, 2009, 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
@@ -59,6 +59,7 @@
*
****************************************************************************/
+#ifndef CONFIG_ARCH_STRCHR
FAR char *strchr(FAR const char *s, int c)
{
if (s)
@@ -74,3 +75,4 @@ FAR char *strchr(FAR const char *s, int c)
return NULL;
}
+#endif
diff --git a/nuttx/lib/string/lib_strcmp.c b/nuttx/libc/string/lib_strcmp.c
index 0e3eee890..d4036cd3e 100644
--- a/nuttx/lib/string/lib_strcmp.c
+++ b/nuttx/libc/string/lib_strcmp.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/string/lib_strcmp.c
+ * libc/string/lib_strcmp.c
*
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/string/lib_strcpy.c b/nuttx/libc/string/lib_strcpy.c
index e2f70b94e..7a0576f5a 100644
--- a/nuttx/lib/string/lib_strcpy.c
+++ b/nuttx/libc/string/lib_strcpy.c
@@ -1,5 +1,5 @@
/************************************************************************
- * lib/string/lib_strcpy.c
+ * libc/string/lib_strcpy.c
*
* Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/string/lib_strcspn.c b/nuttx/libc/string/lib_strcspn.c
index 9da89241c..23e913fad 100644
--- a/nuttx/lib/string/lib_strcspn.c
+++ b/nuttx/libc/string/lib_strcspn.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/string/lib_strcspn.c
+ * libc/string/lib_strcspn.c
*
* Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/string/lib_strdup.c b/nuttx/libc/string/lib_strdup.c
index 44a0cbc0d..a5b3a1e8c 100644
--- a/nuttx/lib/string/lib_strdup.c
+++ b/nuttx/libc/string/lib_strdup.c
@@ -1,5 +1,5 @@
/************************************************************************
- * lib/string//lib_strdup.c
+ * libc/string//lib_strdup.c
*
* Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/string/lib_strerror.c b/nuttx/libc/string/lib_strerror.c
index 249f695c1..0c7ca28fd 100644
--- a/nuttx/lib/string/lib_strerror.c
+++ b/nuttx/libc/string/lib_strerror.c
@@ -1,5 +1,5 @@
/************************************************************************
- * lib/string/lib_strerror.c
+ * libc/string/lib_strerror.c
*
* Copyright (C) 2007, 2009, 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/string/lib_strlen.c b/nuttx/libc/string/lib_strlen.c
index 833305809..6077858e2 100644
--- a/nuttx/lib/string/lib_strlen.c
+++ b/nuttx/libc/string/lib_strlen.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/string/lib_strlen.c
+ * libc/string/lib_strlen.c
*
* Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/string/lib_strncasecmp.c b/nuttx/libc/string/lib_strncasecmp.c
index be369cf0d..35f701c5e 100644
--- a/nuttx/lib/string/lib_strncasecmp.c
+++ b/nuttx/libc/string/lib_strncasecmp.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/string/lib_strncasecmp.c
+ * libc/string/lib_strncasecmp.c
*
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/string/lib_strncat.c b/nuttx/libc/string/lib_strncat.c
index af893e0f9..78c54835e 100644
--- a/nuttx/lib/string/lib_strncat.c
+++ b/nuttx/libc/string/lib_strncat.c
@@ -1,5 +1,5 @@
/************************************************************
- * lib/string/lib_strncat.c
+ * libc/string/lib_strncat.c
*
* Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/string/lib_strncmp.c b/nuttx/libc/string/lib_strncmp.c
index ce2282024..dd8b57fd0 100644
--- a/nuttx/lib/string/lib_strncmp.c
+++ b/nuttx/libc/string/lib_strncmp.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/lib_strncmp.c
+ * libc/lib_strncmp.c
*
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/string/lib_strncpy.c b/nuttx/libc/string/lib_strncpy.c
index 149369d50..8a97aa67b 100644
--- a/nuttx/lib/string/lib_strncpy.c
+++ b/nuttx/libc/string/lib_strncpy.c
@@ -1,5 +1,5 @@
/************************************************************
- * lib/string/lib_strncpy.c
+ * libc/string/lib_strncpy.c
*
* Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/string/lib_strndup.c b/nuttx/libc/string/lib_strndup.c
index ffaf892ea..524e09754 100644
--- a/nuttx/lib/string/lib_strndup.c
+++ b/nuttx/libc/string/lib_strndup.c
@@ -1,5 +1,5 @@
/************************************************************************
- * lib/string//lib_strndup.c
+ * libc/string//lib_strndup.c
*
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/string/lib_strnlen.c b/nuttx/libc/string/lib_strnlen.c
index 2b64fe984..9bc3064cb 100644
--- a/nuttx/lib/string/lib_strnlen.c
+++ b/nuttx/libc/string/lib_strnlen.c
@@ -1,12 +1,12 @@
/****************************************************************************
- * lib/string/lib_strnlen.c
+ * libc/string/lib_strnlen.c
*
* This file is part of NuttX, contributed by Michael Hrabanek
*
* Copyright (C) 2010 Gregory Nutt. All rights reserved.
* Author: Michael Hrabanek
*
- * Derives from the file lib/lib_strlen.c:
+ * Derives from the file libc/lib_strlen.c:
*
* Copyright (C) 2007, 2008, 2010 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/string/lib_strpbrk.c b/nuttx/libc/string/lib_strpbrk.c
index 02e2ea2c7..ef9b0f3e9 100644
--- a/nuttx/lib/string/lib_strpbrk.c
+++ b/nuttx/libc/string/lib_strpbrk.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/string/lib_strpbrk.c
+ * libc/string/lib_strpbrk.c
*
* Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/string/lib_strrchr.c b/nuttx/libc/string/lib_strrchr.c
index 91243ce58..08575c82b 100644
--- a/nuttx/lib/string/lib_strrchr.c
+++ b/nuttx/libc/string/lib_strrchr.c
@@ -1,5 +1,5 @@
/************************************************************************
- * lib/string/lib_strrchr.c
+ * libc/string/lib_strrchr.c
*
* Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/string/lib_strspn.c b/nuttx/libc/string/lib_strspn.c
index e7b5ea0a5..6894b2b9d 100644
--- a/nuttx/lib/string/lib_strspn.c
+++ b/nuttx/libc/string/lib_strspn.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/string/lib_strspn.c
+ * libc/string/lib_strspn.c
*
* Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/string/lib_strstr.c b/nuttx/libc/string/lib_strstr.c
index b8c896fa2..7a60a680d 100644
--- a/nuttx/lib/string/lib_strstr.c
+++ b/nuttx/libc/string/lib_strstr.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/string/lib_strstr.c
+ * libc/string/lib_strstr.c
*
* Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
@@ -97,7 +97,9 @@ char *strstr(const char *str, const char *substr)
candidate++;
}
- /* Won't get here, but some compilers might complain */
+ /* Won't get here, but some compilers might complain. Other compilers
+ * might complain about this code being unreachable too.
+ */
return NULL;
}
diff --git a/nuttx/lib/string/lib_strtod.c b/nuttx/libc/string/lib_strtod.c
index 8fecd4571..58dfd6a29 100644
--- a/nuttx/lib/string/lib_strtod.c
+++ b/nuttx/libc/string/lib_strtod.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/string/lib_strtod.c
+ * libc/string/lib_strtod.c
* Convert string to double
*
* Copyright (C) 2002 Michael Ringgaard. All rights reserved.
diff --git a/nuttx/lib/string/lib_strtok.c b/nuttx/libc/string/lib_strtok.c
index c40993135..85d6597d7 100644
--- a/nuttx/lib/string/lib_strtok.c
+++ b/nuttx/libc/string/lib_strtok.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/string/lib_strtok.c
+ * libc/string/lib_strtok.c
*
* Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/string/lib_strtokr.c b/nuttx/libc/string/lib_strtokr.c
index 1c571b6ae..c7845be64 100644
--- a/nuttx/lib/string/lib_strtokr.c
+++ b/nuttx/libc/string/lib_strtokr.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/string/lib_strtokr.c
+ * libc/string/lib_strtokr.c
*
* Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/string/lib_strtol.c b/nuttx/libc/string/lib_strtol.c
index c17d87e63..6ac0d6827 100644
--- a/nuttx/lib/string/lib_strtol.c
+++ b/nuttx/libc/string/lib_strtol.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/string/lib_strtol.c
+ * libc/string/lib_strtol.c
*
* Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/string/lib_strtoll.c b/nuttx/libc/string/lib_strtoll.c
index 242e025c0..99fba08eb 100644
--- a/nuttx/lib/string/lib_strtoll.c
+++ b/nuttx/libc/string/lib_strtoll.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/string/lib_strtoll.c
+ * libc/string/lib_strtoll.c
*
* Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/string/lib_strtoul.c b/nuttx/libc/string/lib_strtoul.c
index b0d2d090e..8f27ae3f2 100644
--- a/nuttx/lib/string/lib_strtoul.c
+++ b/nuttx/libc/string/lib_strtoul.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * /lib/string/lib_strtoul.c
+ * /libc/string/lib_strtoul.c
*
* Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/string/lib_strtoull.c b/nuttx/libc/string/lib_strtoull.c
index 6567457c0..4808114af 100644
--- a/nuttx/lib/string/lib_strtoull.c
+++ b/nuttx/libc/string/lib_strtoull.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * /lib/string/lib_strtoull.c
+ * /libc/string/lib_strtoull.c
*
* Copyright (C) 2009, 2010 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/libc/string/lib_vikmemcpy.c b/nuttx/libc/string/lib_vikmemcpy.c
new file mode 100644
index 000000000..28bf4a4ce
--- /dev/null
+++ b/nuttx/libc/string/lib_vikmemcpy.c
@@ -0,0 +1,348 @@
+/****************************************************************************
+ * File: libc/string/lib_vikmemcpy.c
+ *
+ * This is version of the optimized memcpy by Daniel Vik, adapted to the
+ * NuttX environment.
+ *
+ * Copyright (C) 1999-2010 Daniel Vik
+ *
+ * Adaptations include:
+ * - File name change
+ * - Use of types defined in stdint.h
+ * - Integration with the NuttX configuration system
+ * - Other cosmetic changes for consistency with NuttX coding standards
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any
+ * damages arising from the use of this software.
+ * Permission is granted to anyone to use this software for any
+ * purpose, including commercial applications, and to alter it and
+ * redistribute it freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you
+ * must not claim that you wrote the original software. If you
+ * use this software in a product, an acknowledgment in the
+ * use this software in a product, an acknowledgment in the
+ * product documentation would be appreciated but is not
+ * required.
+ *
+ * 2. Altered source versions must be plainly marked as such, and
+ * must not be misrepresented as being the original software.
+ *
+ * 3. This notice may not be removed or altered from any source
+ * distribution.
+ *
+ * Description: Implementation of the standard library function memcpy.
+ * This implementation of memcpy() is ANSI-C89 compatible.
+ *
+ * The following configuration options can be set:
+ *
+ * CONFIG_ENDIAN_BIG
+ * Uses processor with big endian addressing. Default is little endian.
+ *
+ * CONFIG_MEMCPY_PRE_INC_PTRS
+ * Use pre increment of pointers. Default is post increment of pointers.
+ *
+ * CONFIG_MEMCPY_INDEXED_COPY
+ * Copying data using array indexing. Using this option, disables the
+ * CONFIG_MEMCPY_PRE_INC_PTRS option.
+ *
+ * CONFIG_MEMCPY_64BIT - Compiles memcpy for 64 bit architectures
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Configuration definitions.
+ ****************************************************************************/
+
+#define CONFIG_MEMCPY_INDEXED_COPY
+
+/********************************************************************
+ * Included Files
+ *******************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <stddef.h>
+#include <stdint.h>
+#include <string.h>
+
+/********************************************************************
+ * Pre-processor Definitions
+ *******************************************************************/
+
+/* Can't support CONFIG_MEMCPY_64BIT if the platform does not have 64-bit
+ * integer types.
+ */
+
+#ifndef CONFIG_HAVE_LONG_LONG
+# undef CONFIG_MEMCPY_64BIT
+#endif
+
+/* Remove definitions when CONFIG_MEMCPY_INDEXED_COPY is defined */
+
+#if defined (CONFIG_MEMCPY_INDEXED_COPY)
+# if defined (CONFIG_MEMCPY_PRE_INC_PTRS)
+# undef CONFIG_MEMCPY_PRE_INC_PTRS
+# endif /* CONFIG_MEMCPY_PRE_INC_PTRS */
+#endif /* CONFIG_MEMCPY_INDEXED_COPY */
+
+/* Definitions for pre and post increment of pointers */
+
+#if defined (CONFIG_MEMCPY_PRE_INC_PTRS)
+
+# define START_VAL(x) (x)--
+# define INC_VAL(x) *++(x)
+# define CAST_TO_U8(p, o) ((uint8_t*)p + o + TYPE_WIDTH)
+# define WHILE_DEST_BREAK (TYPE_WIDTH - 1)
+# define PRE_LOOP_ADJUST - (TYPE_WIDTH - 1)
+# define PRE_SWITCH_ADJUST + 1
+
+#else /* CONFIG_MEMCPY_PRE_INC_PTRS */
+
+# define START_VAL(x)
+# define INC_VAL(x) *(x)++
+# define CAST_TO_U8(p, o) ((uint8_t*)p + o)
+# define WHILE_DEST_BREAK 0
+# define PRE_LOOP_ADJUST
+# define PRE_SWITCH_ADJUST
+
+#endif /* CONFIG_MEMCPY_PRE_INC_PTRS */
+
+/* Definitions for endian-ness */
+
+#ifdef CONFIG_ENDIAN_BIG
+
+# define SHL <<
+# define SHR >>
+
+#else /* CONFIG_ENDIAN_BIG */
+
+# define SHL >>
+# define SHR <<
+
+#endif /* CONFIG_ENDIAN_BIG */
+
+/********************************************************************
+ * Macros for copying words of different alignment.
+ * Uses incremening pointers.
+ *******************************************************************/
+
+#define CP_INCR() \
+{ \
+ INC_VAL(dstN) = INC_VAL(srcN); \
+}
+
+#define CP_INCR_SH(shl, shr) \
+{ \
+ dstWord = srcWord SHL shl; \
+ srcWord = INC_VAL(srcN); \
+ dstWord |= srcWord SHR shr; \
+ INC_VAL(dstN) = dstWord; \
+}
+
+/********************************************************************
+ * Macros for copying words of different alignment.
+ * Uses array indexes.
+ *******************************************************************/
+
+#define CP_INDEX(idx) \
+{ \
+ dstN[idx] = srcN[idx]; \
+}
+
+#define CP_INDEX_SH(x, shl, shr) \
+{ \
+ dstWord = srcWord SHL shl; \
+ srcWord = srcN[x]; \
+ dstWord |= srcWord SHR shr; \
+ dstN[x] = dstWord; \
+}
+
+/********************************************************************
+ * Macros for copying words of different alignment.
+ * Uses incremening pointers or array indexes depending on
+ * configuration.
+ *******************************************************************/
+
+#if defined (CONFIG_MEMCPY_INDEXED_COPY)
+
+# define CP(idx) CP_INDEX(idx)
+# define CP_SH(idx, shl, shr) CP_INDEX_SH(idx, shl, shr)
+
+# define INC_INDEX(p, o) ((p) += (o))
+
+#else /* CONFIG_MEMCPY_INDEXED_COPY */
+
+# define CP(idx) CP_INCR()
+# define CP_SH(idx, shl, shr) CP_INCR_SH(shl, shr)
+
+# define INC_INDEX(p, o)
+
+#endif /* CONFIG_MEMCPY_INDEXED_COPY */
+
+#define COPY_REMAINING(count) \
+{ \
+ START_VAL(dst8); \
+ START_VAL(src8); \
+ \
+ switch (count) \
+ { \
+ case 7: INC_VAL(dst8) = INC_VAL(src8); \
+ case 6: INC_VAL(dst8) = INC_VAL(src8); \
+ case 5: INC_VAL(dst8) = INC_VAL(src8); \
+ case 4: INC_VAL(dst8) = INC_VAL(src8); \
+ case 3: INC_VAL(dst8) = INC_VAL(src8); \
+ case 2: INC_VAL(dst8) = INC_VAL(src8); \
+ case 1: INC_VAL(dst8) = INC_VAL(src8); \
+ case 0: \
+ default: break; \
+ } \
+}
+
+#define COPY_NO_SHIFT() \
+{ \
+ UIntN* dstN = (UIntN*)(dst8 PRE_LOOP_ADJUST); \
+ UIntN* srcN = (UIntN*)(src8 PRE_LOOP_ADJUST); \
+ size_t length = count / TYPE_WIDTH; \
+ \
+ while (length & 7) \
+ { \
+ CP_INCR(); \
+ length--; \
+ } \
+ \
+ length /= 8; \
+ \
+ while (length--) \
+ { \
+ CP(0); \
+ CP(1); \
+ CP(2); \
+ CP(3); \
+ CP(4); \
+ CP(5); \
+ CP(6); \
+ CP(7); \
+ \
+ INC_INDEX(dstN, 8); \
+ INC_INDEX(srcN, 8); \
+ } \
+ \
+ src8 = CAST_TO_U8(srcN, 0); \
+ dst8 = CAST_TO_U8(dstN, 0); \
+ \
+ COPY_REMAINING(count & (TYPE_WIDTH - 1)); \
+ \
+ return dest; \
+}
+
+#define COPY_SHIFT(shift) \
+{ \
+ UIntN* dstN = (UIntN*)((((UIntN)dst8) PRE_LOOP_ADJUST) & \
+ ~(TYPE_WIDTH - 1)); \
+ UIntN* srcN = (UIntN*)((((UIntN)src8) PRE_LOOP_ADJUST) & \
+ ~(TYPE_WIDTH - 1)); \
+ size_t length = count / TYPE_WIDTH; \
+ UIntN srcWord = INC_VAL(srcN); \
+ UIntN dstWord; \
+ \
+ while (length & 7) \
+ { \
+ CP_INCR_SH(8 * shift, 8 * (TYPE_WIDTH - shift)); \
+ length--; \
+ } \
+ \
+ length /= 8; \
+ \
+ while (length--) \
+ { \
+ CP_SH(0, 8 * shift, 8 * (TYPE_WIDTH - shift)); \
+ CP_SH(1, 8 * shift, 8 * (TYPE_WIDTH - shift)); \
+ CP_SH(2, 8 * shift, 8 * (TYPE_WIDTH - shift)); \
+ CP_SH(3, 8 * shift, 8 * (TYPE_WIDTH - shift)); \
+ CP_SH(4, 8 * shift, 8 * (TYPE_WIDTH - shift)); \
+ CP_SH(5, 8 * shift, 8 * (TYPE_WIDTH - shift)); \
+ CP_SH(6, 8 * shift, 8 * (TYPE_WIDTH - shift)); \
+ CP_SH(7, 8 * shift, 8 * (TYPE_WIDTH - shift)); \
+ \
+ INC_INDEX(dstN, 8); \
+ INC_INDEX(srcN, 8); \
+ } \
+ \
+ src8 = CAST_TO_U8(srcN, (shift - TYPE_WIDTH)); \
+ dst8 = CAST_TO_U8(dstN, 0); \
+ \
+ COPY_REMAINING(count & (TYPE_WIDTH - 1)); \
+ \
+ return dest; \
+}
+
+/********************************************************************
+ * Type Definitions
+ *******************************************************************/
+
+#ifdef CONFIG_MEMCPY_64BIT
+typedef uint64_t UIntN;
+# define TYPE_WIDTH 8L
+#else
+typedef uint32_t UIntN;
+# define TYPE_WIDTH 4L
+#endif
+
+/********************************************************************
+ * Public Functions
+ *******************************************************************/
+/********************************************************************
+ * Name: memcpy
+ *
+ * Description:
+ * Copies count bytes from src to dest. No overlap check is performed.
+ *
+ * Input Parameters:
+ * dest - pointer to destination buffer
+ * src - pointer to source buffer
+ * count - number of bytes to copy
+ *
+ * Returned Value:
+ * A pointer to destination buffer
+ *
+ *******************************************************************/
+
+void *memcpy(void *dest, const void *src, size_t count)
+{
+ uint8_t *dst8 = (uint8_t*)dest;
+ uint8_t *src8 = (uint8_t*)src;
+
+ if (count < 8)
+ {
+ COPY_REMAINING(count);
+ return dest;
+ }
+
+ START_VAL(dst8);
+ START_VAL(src8);
+
+ while (((UIntN)dst8 & (TYPE_WIDTH - 1)) != WHILE_DEST_BREAK)
+ {
+ INC_VAL(dst8) = INC_VAL(src8);
+ count--;
+ }
+
+ switch ((((UIntN)src8) PRE_SWITCH_ADJUST) & (TYPE_WIDTH - 1))
+ {
+ case 0: COPY_NO_SHIFT(); break;
+ case 1: COPY_SHIFT(1); break;
+ case 2: COPY_SHIFT(2); break;
+ case 3: COPY_SHIFT(3); break;
+#if TYPE_WIDTH > 4
+ case 4: COPY_SHIFT(4); break;
+ case 5: COPY_SHIFT(5); break;
+ case 6: COPY_SHIFT(6); break;
+ case 7: COPY_SHIFT(7); break;
+#endif
+ }
+
+ return dest;
+}
diff --git a/nuttx/lib/termios/Make.defs b/nuttx/libc/termios/Make.defs
index a6bb77f83..d20a5f95c 100644
--- a/nuttx/lib/termios/Make.defs
+++ b/nuttx/libc/termios/Make.defs
@@ -1,5 +1,5 @@
############################################################################
-# lib/misc/Make.defs
+# libc/misc/Make.defs
#
# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/termios/lib_cfgetspeed.c b/nuttx/libc/termios/lib_cfgetspeed.c
index d7f0dc473..da10daac1 100644
--- a/nuttx/lib/termios/lib_cfgetspeed.c
+++ b/nuttx/libc/termios/lib_cfgetspeed.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/termios/lib_cfgetspeed.c
+ * libc/termios/lib_cfgetspeed.c
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/termios/lib_cfsetspeed.c b/nuttx/libc/termios/lib_cfsetspeed.c
index bf9e66064..a2a9475c4 100644
--- a/nuttx/lib/termios/lib_cfsetspeed.c
+++ b/nuttx/libc/termios/lib_cfsetspeed.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/termios/lib_cfsetspeed.c
+ * libc/termios/lib_cfsetspeed.c
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
@@ -110,12 +110,7 @@
int cfsetspeed(FAR struct termios *termiosp, speed_t speed)
{
- FAR speed_t *speedp;
-
DEBUGASSERT(termiosp);
-
- speedp = (FAR speed_t *)&termiosp->c_speed;
- *speedp = speed;
-
+ termiosp->c_speed = speed;
return OK;
}
diff --git a/nuttx/lib/termios/lib_tcflush.c b/nuttx/libc/termios/lib_tcflush.c
index 338524bdd..1a9710f6a 100644
--- a/nuttx/lib/termios/lib_tcflush.c
+++ b/nuttx/libc/termios/lib_tcflush.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/termios/lib_tcflush.c
+ * libc/termios/lib_tcflush.c
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/termios/lib_tcgetattr.c b/nuttx/libc/termios/lib_tcgetattr.c
index 500871d9f..e8d311260 100644
--- a/nuttx/lib/termios/lib_tcgetattr.c
+++ b/nuttx/libc/termios/lib_tcgetattr.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/termios/lib_tcgetattr.c
+ * libc/termios/lib_tcgetattr.c
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/termios/lib_tcsetattr.c b/nuttx/libc/termios/lib_tcsetattr.c
index 791b519c8..901f2a136 100644
--- a/nuttx/lib/termios/lib_tcsetattr.c
+++ b/nuttx/libc/termios/lib_tcsetattr.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/termios/lib_tcsetattr.c
+ * libc/termios/lib_tcsetattr.c
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/time/Make.defs b/nuttx/libc/time/Make.defs
index ab7414229..4848813d1 100644
--- a/nuttx/lib/time/Make.defs
+++ b/nuttx/libc/time/Make.defs
@@ -1,5 +1,5 @@
############################################################################
-# lib/time/Make.defs
+# libc/time/Make.defs
#
# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/time/lib_calendar2utc.c b/nuttx/libc/time/lib_calendar2utc.c
index e80c292fc..1b8c40a9e 100644
--- a/nuttx/lib/time/lib_calendar2utc.c
+++ b/nuttx/libc/time/lib_calendar2utc.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/time/lib_calendar2utc.c
+ * libc/time/lib_calendar2utc.c
*
* Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/time/lib_daysbeforemonth.c b/nuttx/libc/time/lib_daysbeforemonth.c
index 8000b0e7a..28f4d67a9 100644
--- a/nuttx/lib/time/lib_daysbeforemonth.c
+++ b/nuttx/libc/time/lib_daysbeforemonth.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/time/lib_daysbeforemonth.c
+ * libc/time/lib_daysbeforemonth.c
*
* Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/time/lib_gmtime.c b/nuttx/libc/time/lib_gmtime.c
index 99afeded9..7a4d0f5e1 100644
--- a/nuttx/lib/time/lib_gmtime.c
+++ b/nuttx/libc/time/lib_gmtime.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/time/lib_gmtime.c
+ * libc/time/lib_gmtime.c
*
* Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/time/lib_gmtimer.c b/nuttx/libc/time/lib_gmtimer.c
index ba1c9724f..d98620527 100644
--- a/nuttx/lib/time/lib_gmtimer.c
+++ b/nuttx/libc/time/lib_gmtimer.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/time/lib_gmtimer.c
+ * libc/time/lib_gmtimer.c
*
* Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/time/lib_isleapyear.c b/nuttx/libc/time/lib_isleapyear.c
index 966c248e0..386e205b2 100644
--- a/nuttx/lib/time/lib_isleapyear.c
+++ b/nuttx/libc/time/lib_isleapyear.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/time/lib_isleapyear.c
+ * libc/time/lib_isleapyear.c
*
* Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/time/lib_mktime.c b/nuttx/libc/time/lib_mktime.c
index 8c17e7c0a..25254d70e 100644
--- a/nuttx/lib/time/lib_mktime.c
+++ b/nuttx/libc/time/lib_mktime.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/time/lib_mktime.c
+ * libc/time/lib_mktime.c
*
* Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/time/lib_strftime.c b/nuttx/libc/time/lib_strftime.c
index cd0804f55..3b0c8dd8f 100644
--- a/nuttx/lib/time/lib_strftime.c
+++ b/nuttx/libc/time/lib_strftime.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/time/lib_strftime.c
+ * libc/time/lib_strftime.c
*
* Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/time/lib_time.c b/nuttx/libc/time/lib_time.c
index 106a04c36..673f6fdcd 100644
--- a/nuttx/lib/time/lib_time.c
+++ b/nuttx/libc/time/lib_time.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/time/lib_time.c
+ * libc/time/lib_time.c
*
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/unistd/Make.defs b/nuttx/libc/unistd/Make.defs
index e1441a48d..67fce9b1d 100644
--- a/nuttx/lib/unistd/Make.defs
+++ b/nuttx/libc/unistd/Make.defs
@@ -1,5 +1,5 @@
############################################################################
-# lib/unistd/Make.defs
+# libc/unistd/Make.defs
#
# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/unistd/lib_chdir.c b/nuttx/libc/unistd/lib_chdir.c
index 3dd1333ce..8953fb19b 100644
--- a/nuttx/lib/unistd/lib_chdir.c
+++ b/nuttx/libc/unistd/lib_chdir.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/unistd/lib_chdir.c
+ * libc/unistd/lib_chdir.c
*
* Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/unistd/lib_getcwd.c b/nuttx/libc/unistd/lib_getcwd.c
index b94823300..717ef2971 100644
--- a/nuttx/lib/unistd/lib_getcwd.c
+++ b/nuttx/libc/unistd/lib_getcwd.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/unistd/lib_getcwd.c
+ * libc/unistd/lib_getcwd.c
*
* Copyright (C) 2008, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/unistd/lib_getopt.c b/nuttx/libc/unistd/lib_getopt.c
index 832d28721..1a9190976 100644
--- a/nuttx/lib/unistd/lib_getopt.c
+++ b/nuttx/libc/unistd/lib_getopt.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/unistd/lib_getopt.c
+ * libc/unistd/lib_getopt.c
*
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/unistd/lib_getoptargp.c b/nuttx/libc/unistd/lib_getoptargp.c
index 98a485016..5610342ca 100644
--- a/nuttx/lib/unistd/lib_getoptargp.c
+++ b/nuttx/libc/unistd/lib_getoptargp.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/unistd/lib_getoptargp.c
+ * libc/unistd/lib_getoptargp.c
*
* Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/unistd/lib_getoptindp.c b/nuttx/libc/unistd/lib_getoptindp.c
index 7714f8e70..94ea4d3fc 100644
--- a/nuttx/lib/unistd/lib_getoptindp.c
+++ b/nuttx/libc/unistd/lib_getoptindp.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/unistd/lib_getoptindp.c
+ * libc/unistd/lib_getoptindp.c
*
* Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/lib/unistd/lib_getoptoptp.c b/nuttx/libc/unistd/lib_getoptoptp.c
index 4805b7ac3..cd99b172f 100644
--- a/nuttx/lib/unistd/lib_getoptoptp.c
+++ b/nuttx/libc/unistd/lib_getoptoptp.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/unistd/lib_getoptoptp.c
+ * libc/unistd/lib_getoptoptp.c
*
* Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/libxx/Kconfig b/nuttx/libxx/Kconfig
index 4133a0ceb..9c78342c2 100644
--- a/nuttx/libxx/Kconfig
+++ b/nuttx/libxx/Kconfig
@@ -3,6 +3,16 @@
# see misc/tools/kconfig-language.txt.
#
+comment "Basic CXX Support"
+
+config C99_BOOL8
+ bool "sizeof(_Bool) is 8-bits"
+ default n
+ ---help---
+ This setting means (1) your C++ compiler has sizeof(_Bool) == 8, (2)
+ your C compiler supports the C99 _Bool intrinsic type, and (2) that
+ the C99 _Bool type also has size 1.
+
config HAVE_CXX
bool "Have C++ compiler"
default n
@@ -10,6 +20,8 @@ config HAVE_CXX
Toolchain supports C++ and CXX, CXXFLAGS, and COMPILEXX have been
defined in the configurations Make.defs file.
+if HAVE_CXX
+
config HAVE_CXXINITIALIZE
bool "Have C++ initialization"
default n
@@ -25,3 +37,33 @@ config CXX_NEWLONG
size_t may be type long or type int. This matters for some
C++ library routines because the NuttX size_t might not have
the same underlying type as your toolchain's size_t.
+
+comment "uClibc++ Standard C++ Library"
+
+config UCLIBCXX
+ bool "Build uClibc++ (must be installed)"
+ default n
+ ---help---
+ If you have installed uClibc++ into the NuttX source try, then it can
+ be built by selecting this option. See misc/uClibc++/README.txt for
+ information on installing uClibc++.
+
+if UCLIBCXX
+
+config UCLIBCXX_EXCEPTION
+ bool "Enable Exception Suppport"
+ default y
+
+config UCLIBCXX_IOSTREAM_BUFSIZE
+ int "IO Stream Buffer Size"
+ default 32
+
+config UCLIBCXX_HAVE_LIBSUPCXX
+ bool "Have libsupc++ (required)"
+ default y
+ ---help---
+ Select if your toolchain provides libsupc++. This option is required
+ at present because the built-in libsupc++ support is incomplete.
+
+endif
+endif
diff --git a/nuttx/libxx/Makefile b/nuttx/libxx/Makefile
index 4122931ac..2ab146e9c 100644
--- a/nuttx/libxx/Makefile
+++ b/nuttx/libxx/Makefile
@@ -1,7 +1,7 @@
############################################################################
# libxx/Makefile
#
-# Copyright (C) 2009 Gregory Nutt. All rights reserved.
+# Copyright (C) 2009, 2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
@@ -35,20 +35,56 @@
-include $(TOPDIR)/Make.defs
-ASRCS =
-AOBJS = $(ASRCS:.S=$(OBJEXT))
-CSRCS =
-COBJS = $(CSRCS:.c=$(OBJEXT))
-CXXSRCS = libxx_cxapurevirtual.cxx libxx_delete.cxx libxx_deletea.cxx \
- libxx_eabi_atexit.cxx libxx_new.cxx libxx_newa.cxx
-CXXOBJS = $(CXXSRCS:.cxx=$(OBJEXT))
+# Sources
-SRCS = $(ASRCS) $(CSRCS) $(CXXSRCS)
-OBJS = $(AOBJS) $(COBJS) $(CXXOBJS)
+ASRCS =
+CSRCS =
-BIN = liblibxx$(LIBEXT)
+CXXSRCS = libxx_cxapurevirtual.cxx libxx_eabi_atexit.cxx libxx_cxa_atexit.cxx
-all: $(BIN)
+# Some of the libxx/ files are not need if uClibc++ is installed because
+# uClibx++ replaces them
+
+ifneq ($(CONFIG_UCLIBCXX),y)
+CXXSRCS += libxx_delete.cxx libxx_deletea.cxx libxx_new.cxx libxx_newa.cxx
+CXXSRCS += libxx_stdthrow.cxx
+else
+ifneq ($(UCLIBCXX_EXCEPTION),y)
+CXXSRCS += libxx_stdthrow.cxx
+endif
+endif
+
+# Paths
+
+DEPPATH = --dep-path .
+VPATH = .
+
+# Include the uClibc++ Make.defs file if selected. If it is included,
+# the uClibc++/Make.defs file will add its files to the source file list,
+# add its DEPPATH info, and will add the appropriate paths to the VPATH
+# variable
+#
+# Note that an error will occur if you select CONFIG_LIBXX_UCLIBCXX
+# without installing the uClibc++ package. This is intentional to let
+# you know about the configuration problem. Refer to misc/uClibc++/README.txt
+# for more information
+
+ifeq ($(CONFIG_UCLIBCXX),y)
+include uClibc++/Make.defs
+endif
+
+# Object Files
+
+AOBJS = $(ASRCS:.S=$(OBJEXT))
+COBJS = $(CSRCS:.c=$(OBJEXT))
+CXXOBJS = $(CXXSRCS:.cxx=$(OBJEXT))
+
+SRCS = $(ASRCS) $(CSRCS) $(CXXSRCS)
+OBJS = $(AOBJS) $(COBJS) $(CXXOBJS)
+
+BIN = libcxx$(LIBEXT)
+
+all: $(BIN)
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
@@ -60,21 +96,20 @@ $(CXXOBJS): %$(OBJEXT): %.cxx
$(call COMPILEXX, $<, $@)
$(BIN): $(OBJS)
- @( for obj in $(OBJS) ; do \
- $(call ARCHIVE, $@, $${obj}); \
- done ; )
+ $(call ARCHIVE, $@, $(OBJS))
.depend: Makefile $(SRCS)
- @$(MKDEP) $(CXX) -- $(CXXFLAGS) -- $(SRCS) >Make.dep
- @touch $@
+ $(Q) $(MKDEP) $(DEPPATH) "$(CXX)" -- $(CXXFLAGS) -- $(SRCS) >Make.dep
+ $(Q) touch $@
depend: .depend
clean:
- @rm -f $(BIN) *~ .*.swp
+ $(call DELFILE, $(BIN))
$(call CLEAN)
distclean: clean
- @rm -f Make.dep .depend
+ $(call DELFILE, Make.dep)
+ $(call DELFILE, .depend)
-include Make.dep
diff --git a/nuttx/libxx/README.txt b/nuttx/libxx/README.txt
index 6cf066f08..7a1c51fa7 100644
--- a/nuttx/libxx/README.txt
+++ b/nuttx/libxx/README.txt
@@ -12,6 +12,10 @@ are recommended:
- uClibc++ http://cxx.uclibc.org/
- uSTL http://ustl.sourceforge.net/
+There is a version of uClibc++ that is customized for NuttX that can
+be found here: misc/uClibc++. See misc/uClibc++ for installation
+instructions.
+
At present, only the following are supported here:
- void *operator new(std::size_t nbytes);
@@ -19,6 +23,7 @@ At present, only the following are supported here:
- void operator delete[](void *ptr);
- void __cxa_pure_virtual(void);
- int __aeabi_atexit(void* object, void (*destroyer)(void*), void *dso_handle);
+ - int __cxa_atexit(__cxa_exitfunc_t func, FAR void *arg, FAR void *dso_handle);
operator new
------------
diff --git a/nuttx/libxx/libxx_cxa_atexit.cxx b/nuttx/libxx/libxx_cxa_atexit.cxx
new file mode 100644
index 000000000..cd31f94f6
--- /dev/null
+++ b/nuttx/libxx/libxx_cxa_atexit.cxx
@@ -0,0 +1,146 @@
+//***************************************************************************
+// libxx/libxx_eabi_atexit.cxx
+//
+// Copyright (C) 2012 Gregory Nutt. All rights reserved.
+// Author: Gregory Nutt <gnutt@nuttx.org>
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions
+// are met:
+//
+// 1. Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// 2. Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in
+// the documentation and/or other materials provided with the
+// distribution.
+// 3. Neither the name NuttX nor the names of its contributors may be
+// used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+// POSSIBILITY OF SUCH DAMAGE.
+//
+//***************************************************************************
+
+//***************************************************************************
+// Included Files
+//***************************************************************************
+
+#include <nuttx/config.h>
+
+#include <cstdlib>
+#include <cassert>
+
+#include "libxx_internal.hxx"
+
+//***************************************************************************
+// Pre-processor Definitions
+//***************************************************************************
+
+//***************************************************************************
+// Private Types
+//***************************************************************************
+
+struct __cxa_atexit_s
+{
+ __cxa_exitfunc_t func;
+ FAR void *arg;
+};
+
+//***************************************************************************
+// Private Data
+//***************************************************************************
+
+extern "C"
+{
+ //*************************************************************************
+ // Public Data
+ //*************************************************************************
+
+ FAR void *__dso_handle = NULL;
+
+ //*************************************************************************
+ // Private Functions
+ //*************************************************************************
+
+ //*************************************************************************
+ // Name: __cxa_callback
+ //
+ // Description:
+ // This is really just an "adaptor" function that matches the form of
+ // the __cxa_exitfunc_t to an onexitfunc_t using an allocated structure
+ // to marshall the call parameters.
+ //
+ //*************************************************************************
+
+#if CONFIG_SCHED_ONEXIT
+ static void __cxa_callback(int exitcode, FAR void *arg)
+ {
+ FAR struct __cxa_atexit_s *alloc = (FAR struct __cxa_atexit_s *)arg;
+ DEBUGASSERT(alloc && alloc->func);
+
+ alloc->func(alloc->arg);
+ free(alloc);
+ }
+#endif
+
+ //*************************************************************************
+ // Public Functions
+ //*************************************************************************
+
+ //*************************************************************************
+ // Name: __cxa_atexit
+ //
+ // Description:
+ // __cxa_atexit() registers a destructor function to be called by exit().
+ // On a call to exit(), the registered functions should be called with
+ // the single argument 'arg'. Destructor functions shall always be
+ // called in the reverse order to their registration (i.e. the most
+ // recently registered function shall be called first),
+ //
+ // If shared libraries were supported, the callbacks should be invoked
+ // when the shared library is unloaded as well.
+ //
+ // Reference:
+ // Linux base
+ //
+ //*************************************************************************
+
+ int __cxa_atexit(__cxa_exitfunc_t func, FAR void *arg, FAR void *dso_handle)
+ {
+#if CONFIG_SCHED_ONEXIT
+ // Allocate memory to hold the marshaled __cxa_exitfunc_t call
+ // information.
+
+ FAR struct __cxa_atexit_s *alloc =
+ (FAR struct __cxa_atexit_s *)malloc(sizeof(struct __cxa_atexit_s));
+
+ if (alloc)
+ {
+ // Register the function to be called when the task/thread exists.
+
+ alloc->func = func;
+ alloc->arg = arg;
+
+ return on_exit(__cxa_callback, alloc);
+ }
+ else
+#endif
+ {
+ // What else can we do?
+
+ return 0;
+ }
+ }
+}
diff --git a/nuttx/libxx/libxx_eabi_atexit.cxx b/nuttx/libxx/libxx_eabi_atexit.cxx
index aa0ff6956..25f8306a8 100644
--- a/nuttx/libxx/libxx_eabi_atexit.cxx
+++ b/nuttx/libxx/libxx_eabi_atexit.cxx
@@ -40,27 +40,23 @@
#include <nuttx/config.h>
#include <cstdlib>
+#include "libxx_internal.hxx"
+
//***************************************************************************
-// Definitions
+// Pre-processor Definitions
//***************************************************************************
//***************************************************************************
// Private Data
//***************************************************************************
+//***************************************************************************
+// Public Functions
+//***************************************************************************
+
extern "C"
{
//*************************************************************************
- // Public Data
- //*************************************************************************
-
- void *__dso_handle = NULL;
-
- //*************************************************************************
- // Public Functions
- //*************************************************************************
-
- //*************************************************************************
// Name: __aeabi_atexit
//
// Description:
@@ -75,9 +71,8 @@ extern "C"
//
//*************************************************************************
- int __aeabi_atexit(void* object, void (*destroyer)(void*), void *dso_handle)
+ int __aeabi_atexit(FAR void *object, __cxa_exitfunc_t func, FAR void *dso_handle)
{
- //return __cxa_atexit(destroyer, object, dso_handle); // 0 ? OK; non-0 ? failed }
- return 0;
+ return __cxa_atexit(func, object, dso_handle); // 0 ? OK; non-0 ? failed
}
}
diff --git a/nuttx/libxx/libxx_internal.hxx b/nuttx/libxx/libxx_internal.hxx
new file mode 100644
index 000000000..fe84c763e
--- /dev/null
+++ b/nuttx/libxx/libxx_internal.hxx
@@ -0,0 +1,67 @@
+//***************************************************************************
+// lib/libxx_internal.h
+//
+// Copyright (C) 2012 Gregory Nutt. All rights reserved.
+// Author: Gregory Nutt <gnutt@nuttx.org>
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions
+// are met:
+//
+// 1. Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// 2. Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in
+// the documentation and/or other materials provided with the
+// distribution.
+// 3. Neither the name NuttX nor the names of its contributors may be
+// used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+// POSSIBILITY OF SUCH DAMAGE.
+//
+//***************************************************************************
+
+#ifndef __LIBXX_LIBXX_INTERNAL_HXX
+#define __LIBXX_LIBXX_INTERNAL_HXX
+
+//***************************************************************************
+// Included Files
+//***************************************************************************
+
+#include <nuttx/config.h>
+
+//***************************************************************************
+// Definitions
+//***************************************************************************
+
+//***************************************************************************
+// Public Types
+//***************************************************************************/
+
+typedef CODE void (*__cxa_exitfunc_t)(void *arg);
+
+//***************************************************************************
+// Public Variables
+//***************************************************************************
+
+extern "C" FAR void *__dso_handle;
+
+//***************************************************************************
+// Public Function Prototypes
+//***************************************************************************
+
+extern "C" int __cxa_atexit(__cxa_exitfunc_t func, void *arg, void *dso_handle);
+
+#endif // __LIBXX_LIBXX_INTERNAL_HXX
diff --git a/nuttx/libxx/libxx_stdthrow.cxx b/nuttx/libxx/libxx_stdthrow.cxx
new file mode 100644
index 000000000..588fae264
--- /dev/null
+++ b/nuttx/libxx/libxx_stdthrow.cxx
@@ -0,0 +1,74 @@
+//***************************************************************************
+// libxx/libxx_newa.cxx
+//
+// Copyright (C) 2012 Gregory Nutt. All rights reserved.
+// Author: Petteri Aimonen <petteri.aimonen@gmail.com>;
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions
+// are met:
+//
+// 1. Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// 2. Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in
+// the documentation and/or other materials provided with the
+// distribution.
+// 3. Neither the name NuttX nor the names of its contributors may be
+// used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+// POSSIBILITY OF SUCH DAMAGE.
+//
+//***************************************************************************
+
+//***************************************************************************
+// Included Files
+//***************************************************************************
+
+#include <cstdlib>
+#include <debug.h>
+
+//***************************************************************************
+// Definitions
+//***************************************************************************
+
+//***************************************************************************
+// Private Data
+//***************************************************************************
+
+//***************************************************************************
+// Public Functions
+//***************************************************************************
+
+namespace std
+{
+ void __throw_out_of_range(const char*)
+ {
+ dbg("C++: Vector .at() with argument out of range\n");
+ abort();
+ }
+
+ void __throw_length_error(const char*)
+ {
+ dbg("C++: Vector resize to excessive length\n");
+ abort();
+ }
+
+ void __throw_bad_alloc()
+ {
+ dbg("C++: Bad allocation\n");
+ abort();
+ }
+}
diff --git a/nuttx/mm/Makefile b/nuttx/mm/Makefile
index 0ccf5a09a..da41f9f57 100644
--- a/nuttx/mm/Makefile
+++ b/nuttx/mm/Makefile
@@ -37,8 +37,8 @@
ASRCS =
CSRCS = mm_initialize.c mm_sem.c mm_addfreechunk.c mm_size2ndx.c mm_shrinkchunk.c \
- mm_malloc.c mm_zalloc.c mm_calloc.c mm_realloc.c \
- mm_memalign.c mm_free.c mm_mallinfo.c
+ mm_malloc.c mm_zalloc.c mm_calloc.c mm_realloc.c \
+ mm_memalign.c mm_free.c mm_mallinfo.c
ifeq ($(CONFIG_GRAN),y)
CSRCS += mm_graninit.c mm_granalloc.c mm_granfree.c mm_grancritical.c
@@ -61,21 +61,20 @@ $(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
$(BIN): $(OBJS)
- @( for obj in $(OBJS) ; do \
- $(call ARCHIVE, $@, $${obj}); \
- done ; )
+ $(call ARCHIVE, $@, $(OBJS))
.depend: Makefile $(SRCS)
- @$(MKDEP) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
- @touch $@
+ $(Q) $(MKDEP) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
+ $(Q) touch $@
depend: .depend
clean:
- @rm -f $(BIN) *~ .*.swp
+ $(call DELFILE, $(BIN))
$(call CLEAN)
distclean: clean
- @rm -f Make.dep .depend
+ $(call DELFILE, Make.dep)
+ $(call DELFILE, .depend)
-include Make.dep
diff --git a/nuttx/mm/Makefile.test b/nuttx/mm/Makefile.test
index 63cab910e..2ae9dcb88 100644
--- a/nuttx/mm/Makefile.test
+++ b/nuttx/mm/Makefile.test
@@ -33,12 +33,14 @@
#
############################################################################
-SRCS = mm_test.c mm_initialize.c mm_sem.c mm_addfreechunk.c mm_size2ndx.c mm_shrinkchunk.c \
+-include $(TOPDIR)/Make.defs
+
+SRCS = mm_test.c mm_initialize.c mm_sem.c mm_addfreechunk.c mm_size2ndx.c mm_shrinkchunk.c \
mm_malloc.c mm_zalloc.c mm_calloc.c mm_realloc.c \
mm_memalign.c mm_free.c mm_mallinfo.c
-OBJS = $(SRCS:.c=.o1)
+OBJS = $(SRCS:.c=.o1)
-LIBS = -lpthread -lc
+LIBS = -lpthread -lc
CC = gcc
LD = gcc
@@ -48,17 +50,19 @@ WARNIGNS = -Wall -Wstrict-prototypes -Wshadow
CFLAGS = -g $(DEFINES)
LDFLAGS =
-BIN = ../mm_test
+BIN = ..$(DELIM)mm_test
all: $(BIN)
$(OBJS): %.o1: %.c
@echo "Compiling $<"
- $(CC) -c $(CFLAGS) $< -o $@
+ $(Q) $(CC) -c $(CFLAGS) $< -o $@
$(BIN): $(OBJS)
@echo "Linking {$(OBJS)} to produce $@"
- $(LD) $(LDFLAGS) $(OBJS) $(LIBS) -o $@
+ $(Q) $(LD) $(LDFLAGS) $(OBJS) $(LIBS) -o $@
clean:
- @rm -f $(BIN) *.o1 *~
+ $(call DELFILE, $(BIN))
+ $(call DELFILE, *.o1)
+ $(call CLEAN)
diff --git a/nuttx/mm/mm_graninit.c b/nuttx/mm/mm_graninit.c
index e43839ad6..8f811c65f 100644
--- a/nuttx/mm/mm_graninit.c
+++ b/nuttx/mm/mm_graninit.c
@@ -74,7 +74,6 @@ FAR struct gran_s *g_graninfo;
* Perfrom common GRAN initialization.
*
* Input Parameters:
- * info - Private granule data structure pointer
* heapstart - Start of the granule allocation heap
* heapsize - Size of heap in bytes
* log2gran - Log base 2 of the size of one granule. 0->1 byte,
@@ -207,7 +206,6 @@ gran_common_initialize(FAR void *heapstart, size_t heapsize, uint8_t log2gran,
#ifdef CONFIG_GRAN_SINGLE
int gran_initialize(FAR void *heapstart, size_t heapsize, uint8_t log2gran,
uint8_t log2align)
-int gran_initialize(FAR void *heapstart, size_t heapsize, uint8_t log2gran)
{
g_graninfo = gran_common_initialize(heapstart, heapsize, log2gran,
log2align);
diff --git a/nuttx/mm/mm_initialize.c b/nuttx/mm/mm_initialize.c
index 3a21d1759..a7f64cfaf 100644
--- a/nuttx/mm/mm_initialize.c
+++ b/nuttx/mm/mm_initialize.c
@@ -95,9 +95,9 @@ void mm_initialize(FAR void *heapstart, size_t heapsize)
mlldbg("Heap: start=%p size=%u\n", heapstart, heapsize);
- /* The following two lines have cause problems for some ZiLog compilers
- * in the past. Life is easier if we just the suppress them for those
- * tools.
+ /* The following two lines have cause problems for some older ZiLog
+ * compilers in the past (but not the more recent). Life is easier if we
+ * just the suppress them altogther for those tools.
*/
#ifndef __ZILOG__
diff --git a/nuttx/net/Makefile b/nuttx/net/Makefile
index 506ef8213..74540b67d 100644
--- a/nuttx/net/Makefile
+++ b/nuttx/net/Makefile
@@ -100,24 +100,22 @@ $(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
$(BIN): $(OBJS)
- @( for obj in $(OBJS) ; do \
- $(call ARCHIVE, $@, $${obj}); \
- done ; )
+ $(call ARCHIVE, $@, $(OBJS))
.depend: Makefile $(SRCS)
ifeq ($(CONFIG_NET),y)
- @$(MKDEP) --dep-path . --dep-path uip $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
+ $(Q) $(MKDEP) --dep-path . --dep-path uip "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
endif
- @touch $@
+ $(Q) touch $@
depend: .depend
clean:
- @rm -f $(BIN) *~ .*.swp
- @rm -f uip/*~ uip/.*.swp
+ $(call DELFILE, $(BIN))
$(call CLEAN)
distclean: clean
- @rm -f Make.dep .depend
+ $(call DELFILE, Make.dep)
+ $(call DELFILE, .depend)
-include Make.dep
diff --git a/nuttx/net/net_poll.c b/nuttx/net/net_poll.c
index ca594c10f..815c6a71d 100644
--- a/nuttx/net/net_poll.c
+++ b/nuttx/net/net_poll.c
@@ -141,6 +141,7 @@ static uint16_t poll_interrupt(struct uip_driver_s *dev, FAR void *conn,
sem_post(fds->sem);
}
}
+
return flags;
}
#endif /* HAVE_NETPOLL */
@@ -219,6 +220,7 @@ static inline int net_pollsetup(FAR struct socket *psock, struct pollfd *fds)
sem_post(fds->sem);
}
}
+
uip_unlock(flags);
return OK;
diff --git a/nuttx/net/netdev_ioctl.c b/nuttx/net/netdev_ioctl.c
index 4b5876efa..ea5c0e436 100644
--- a/nuttx/net/netdev_ioctl.c
+++ b/nuttx/net/netdev_ioctl.c
@@ -138,19 +138,47 @@ static void ioctl_setipaddr(FAR uip_ipaddr_t *outaddr, FAR const void *inaddr)
*
****************************************************************************/
-static inline void ioctl_ifup(FAR struct uip_driver_s *dev)
+static void ioctl_ifup(FAR struct uip_driver_s *dev)
{
+ /* Make sure that the device supports the d_ifup() method */
+
if (dev->d_ifup)
{
- dev->d_ifup(dev);
+ /* Is the interface already up? */
+
+ if ((dev->d_flags & IFF_RUNNING) == 0)
+ {
+ /* No, bring the interface up now */
+
+ if (dev->d_ifup(dev) == OK)
+ {
+ /* Mark the interface as up */
+
+ dev->d_flags |= IFF_RUNNING;
+ }
+ }
}
}
-static inline void ioctl_ifdown(FAR struct uip_driver_s *dev)
+static void ioctl_ifdown(FAR struct uip_driver_s *dev)
{
+ /* Make sure that the device supports the d_ifdown() method */
+
if (dev->d_ifdown)
{
- dev->d_ifdown(dev);
+ /* Is the interface already down? */
+
+ if ((dev->d_flags & IFF_RUNNING) != 0)
+ {
+ /* No, take the interface down now */
+
+ if (dev->d_ifdown(dev) == OK)
+ {
+ /* Mark the interface as down */
+
+ dev->d_flags &= ~IFF_RUNNING;
+ }
+ }
}
}
@@ -194,63 +222,130 @@ static int netdev_ifrioctl(FAR struct socket *psock, int cmd, struct ifreq *req)
switch (cmd)
{
- case SIOCGIFADDR: /* Get IP address */
- ioctl_getipaddr(&req->ifr_addr, &dev->d_ipaddr);
+ case SIOCGIFADDR: /* Get IP address */
+ {
+ ioctl_getipaddr(&req->ifr_addr, &dev->d_ipaddr);
+ }
break;
- case SIOCSIFADDR: /* Set IP address */
- ioctl_ifdown(dev);
- ioctl_setipaddr(&dev->d_ipaddr, &req->ifr_addr);
- ioctl_ifup(dev);
+ case SIOCSIFADDR: /* Set IP address */
+ {
+ ioctl_ifdown(dev);
+ ioctl_setipaddr(&dev->d_ipaddr, &req->ifr_addr);
+ ioctl_ifup(dev);
+ }
break;
case SIOCGIFDSTADDR: /* Get P-to-P address */
- ioctl_getipaddr(&req->ifr_dstaddr, &dev->d_draddr);
+ {
+ ioctl_getipaddr(&req->ifr_dstaddr, &dev->d_draddr);
+ }
break;
case SIOCSIFDSTADDR: /* Set P-to-P address */
- ioctl_setipaddr(&dev->d_draddr, &req->ifr_dstaddr);
+ {
+ ioctl_setipaddr(&dev->d_draddr, &req->ifr_dstaddr);
+ }
break;
case SIOCGIFNETMASK: /* Get network mask */
- ioctl_getipaddr(&req->ifr_addr, &dev->d_netmask);
+ {
+ ioctl_getipaddr(&req->ifr_addr, &dev->d_netmask);
+ }
break;
case SIOCSIFNETMASK: /* Set network mask */
- ioctl_setipaddr(&dev->d_netmask, &req->ifr_addr);
+ {
+ ioctl_setipaddr(&dev->d_netmask, &req->ifr_addr);
+ }
break;
case SIOCGIFMTU: /* Get MTU size */
- req->ifr_mtu = CONFIG_NET_BUFSIZE;
+ {
+ req->ifr_mtu = CONFIG_NET_BUFSIZE;
+ }
+ break;
+
+ case SIOCSIFFLAGS: /* Sets the interface flags */
+ {
+ /* Is this a request to bring the interface up? */
+
+ if (req->ifr_flags & IF_FLAG_IFUP)
+ {
+ /* Yes.. bring the interface up */
+
+ ioctl_ifup(dev);
+ }
+
+ /* Is this a request to take the interface down? */
+
+ else if (req->ifr_flags & IF_FLAG_IFDOWN)
+ {
+ /* Yes.. take the interface down */
+
+ ioctl_ifdown(dev);
+ }
+ }
+ break;
+
+ case SIOCGIFFLAGS: /* Gets the interface flags */
+ {
+ req->ifr_flags = 0;
+
+ /* Is the interface running? */
+
+ if (dev->d_flags & IFF_RUNNING)
+ {
+ /* Yes.. report interface up */
+
+ req->ifr_flags |= IF_FLAG_IFUP;
+ }
+ else
+ {
+ /* No.. report interface down */
+
+ req->ifr_flags |= IF_FLAG_IFDOWN;
+ }
+ }
break;
/* MAC address operations only make sense if Ethernet is supported */
#ifdef CONFIG_NET_ETHERNET
case SIOCGIFHWADDR: /* Get hardware address */
- req->ifr_hwaddr.sa_family = AF_INETX;
- memcpy(req->ifr_hwaddr.sa_data, dev->d_mac.ether_addr_octet, IFHWADDRLEN);
+ {
+ req->ifr_hwaddr.sa_family = AF_INETX;
+ memcpy(req->ifr_hwaddr.sa_data, dev->d_mac.ether_addr_octet, IFHWADDRLEN);
+ }
break;
case SIOCSIFHWADDR: /* Set hardware address -- will not take effect until ifup */
- req->ifr_hwaddr.sa_family = AF_INETX;
- memcpy(dev->d_mac.ether_addr_octet, req->ifr_hwaddr.sa_data, IFHWADDRLEN);
+ {
+ req->ifr_hwaddr.sa_family = AF_INETX;
+ memcpy(dev->d_mac.ether_addr_octet, req->ifr_hwaddr.sa_data, IFHWADDRLEN);
+ }
break;
#endif
case SIOCDIFADDR: /* Delete IP address */
- ioctl_ifdown(dev);
- memset(&dev->d_ipaddr, 0, sizeof(uip_ipaddr_t));
+ {
+ ioctl_ifdown(dev);
+ memset(&dev->d_ipaddr, 0, sizeof(uip_ipaddr_t));
+ }
break;
case SIOCGIFCOUNT: /* Get number of devices */
- req->ifr_count = netdev_count();
- ret = -ENOSYS;
+ {
+ req->ifr_count = netdev_count();
+ ret = -ENOSYS;
+ }
break;
- case SIOCGIFBRDADDR: /* Get broadcast IP address */
- case SIOCSIFBRDADDR: /* Set broadcast IP address */
- ret = -ENOSYS;
+ case SIOCGIFBRDADDR: /* Get broadcast IP address */
+ case SIOCSIFBRDADDR: /* Set broadcast IP address */
+ {
+ ret = -ENOSYS;
+ }
break;
#ifdef CONFIG_NET_ARPIOCTLS
@@ -261,7 +356,9 @@ static int netdev_ifrioctl(FAR struct socket *psock, int cmd, struct ifreq *req)
#endif
default:
- ret = -EINVAL;
+ {
+ ret = -EINVAL;
+ }
break;;
}
diff --git a/nuttx/net/uip/uip_icmpping.c b/nuttx/net/uip/uip_icmpping.c
index e3ebf7252..36f6e892a 100644
--- a/nuttx/net/uip/uip_icmpping.c
+++ b/nuttx/net/uip/uip_icmpping.c
@@ -123,6 +123,7 @@ static inline int ping_timeout(struct icmp_ping_s *pstate)
{
return TRUE;
}
+
return FALSE;
}
@@ -365,6 +366,7 @@ int uip_ping(uip_ipaddr_t addr, uint16_t id, uint16_t seqno,
uip_icmpcallbackfree(state.png_cb);
}
+
uip_unlock(save);
/* Return the negated error number in the event of a failure, or the
diff --git a/nuttx/sched/Kconfig b/nuttx/sched/Kconfig
index 4f7149595..bfaec3b5d 100644
--- a/nuttx/sched/Kconfig
+++ b/nuttx/sched/Kconfig
@@ -22,7 +22,13 @@ config SCHED_INSTRUMENTATION
bool "Monitor system performance"
default n
---help---
- enables instrumentation in scheduler to monitor system performance.
+ Enables instrumentation in scheduler to monitor system performance.
+ If enabled, then the board-specific logic must provide the following
+ functions (see include/sched.h):
+
+ void sched_note_start(FAR _TCB *tcb);
+ void sched_note_stop(FAR _TCB *tcb);
+ void sched_note_switch(FAR _TCB *pFromTcb, FAR _TCB *pToTcb);
config TASK_NAME_SIZE
int "Maximum task name size"
@@ -40,7 +46,7 @@ config JULIAN_TIME
config START_YEAR
int "start year"
- default 2010
+ default 2013
config START_MONTH
int "start month"
@@ -57,12 +63,6 @@ config DEV_CONSOLE
Set if architecture-specific logic provides /dev/console. Enables
stdout, stderr, stdin.
-config DEV_LOWCONSOLE
- bool "enable low-level serial console"
- default n
- ---help---
- Use the simple, low-level, write-only serial console driver (minimul support)
-
config MUTEX_TYPES:
bool "Enable mutex types"
default n
@@ -214,12 +214,17 @@ config SCHED_ATEXIT
config SCHED_ATEXIT_MAX
int "Max number of atexit() functions"
default 1
- depends on SCHED_ATEXIT
+ depends on SCHED_ATEXIT && !SCHED_ONEXIT
---help---
By default if SCHED_ATEXIT is selected, only a single atexit() function
is supported. That number can be increased by defined this setting to
the number that you require.
+ If both SCHED_ONEXIT and SCHED_ATEXIT are selected, then atexit() is built
+ on top of the on_exit() implementation. In that case, SCHED_ONEXIT_MAX
+ determines the size of the combined number of atexit(0) and on_exit calls
+ and SCHED_ATEXIT_MAX is not used.
+
config SCHED_ONEXIT
bool "Enable on_exit() API"
default n
@@ -235,6 +240,10 @@ config SCHED_ONEXIT_MAX
is supported. That number can be increased by defined this setting to the
number that you require.
+ If both SCHED_ONEXIT and SCHED_ATEXIT are selected, then atexit() is built
+ on top of the on_exit() implementation. In that case, SCHED_ONEXIT_MAX
+ determines the size of the combined number of atexit(0) and on_exit calls.
+
config USER_ENTRYPOINT
string "Application entry point"
default "user_start"
@@ -381,14 +390,6 @@ config PREALLOC_TIMERS
comment "Stack and heap information"
-config CUSTOM_STACK
- bool "Enable custom stack"
- default n
- ---help---
- The up_ implementation will handle all stack operations outside of the
- nuttx model. This is necessary for certain architectures that have
- have hardware stacks (such as the 8051 family).
-
config IDLETHREAD_STACKSIZE
int "Idle thread stack size"
default 1024
diff --git a/nuttx/sched/Makefile b/nuttx/sched/Makefile
index 1e0a55aea..82f74fc3c 100644
--- a/nuttx/sched/Makefile
+++ b/nuttx/sched/Makefile
@@ -94,7 +94,7 @@ SIGNAL_SRCS = sig_initialize.c \
sig_findaction.c sig_allocatependingsigaction.c \
sig_releasependingsigaction.c sig_unmaskpendingsignal.c \
sig_removependingsignal.c sig_releasependingsignal.c sig_lowest.c \
- sig_mqnotempty.c sig_cleanup.c sig_received.c sig_deliver.c
+ sig_mqnotempty.c sig_cleanup.c sig_received.c sig_deliver.c pause.c
MQUEUE_SRCS = mq_open.c mq_close.c mq_unlink.c mq_send.c mq_timedsend.c\
mq_sndinternal.c mq_receive.c mq_timedreceive.c mq_rcvinternal.c \
@@ -188,6 +188,7 @@ OBJS = $(AOBJS) $(COBJS)
BIN = libsched$(LIBEXT)
all: $(BIN)
+.PHONY: context depend clean distclean
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
@@ -196,21 +197,20 @@ $(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
$(BIN): $(OBJS)
- @( for obj in $(OBJS) ; do \
- $(call ARCHIVE, $@, $${obj}); \
- done ; )
+ $(call ARCHIVE, $@, $(OBJS))
.depend: Makefile $(SRCS)
- @$(MKDEP) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
- @touch $@
+ $(Q) $(MKDEP) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
+ $(Q) touch $@
depend: .depend
clean:
- @rm -f $(BIN) *~ .*.swp
+ $(call DELFILE, $(BIN))
$(call CLEAN)
distclean: clean
- @rm -f Make.dep .depend
+ $(call DELFILE, Make.dep)
+ $(call DELFILE, .depend)
-include Make.dep
diff --git a/nuttx/sched/atexit.c b/nuttx/sched/atexit.c
index f7d81bec2..b0559b01b 100644
--- a/nuttx/sched/atexit.c
+++ b/nuttx/sched/atexit.c
@@ -96,8 +96,13 @@
* CONFIG_SCHED_ATEXIT_MAX defines a larger number.
* 2. atexit functions are not inherited when a new task is
* created.
+ * 3. If both SCHED_ONEXIT and SCHED_ATEXIT are selected, then atexit()
+ * is built on top of the on_exit() implementation. In that case,
+ * CONFIG_SCHED_ONEXIT_MAX determines the size of the combined
+ * number of atexit(0) and on_exit calls and SCHED_ATEXIT_MAX is
+ * not used.
*
- * Parameters:
+ * Input Parameters:
* func - A pointer to the function to be called when the task exits.
*
* Return Value:
@@ -107,7 +112,14 @@
int atexit(void (*func)(void))
{
-#if defined(CONFIG_SCHED_ATEXIT_MAX) && CONFIG_SCHED_ATEXIT_MAX > 1
+#if defined(CONFIG_SCHED_ONEXIT)
+ /* atexit is equivalent to on_exit() with no argument (Assuming that the ABI
+ * can handle a callback function that recieves more parameters than it expects).
+ */
+
+ return on_exit(onexitfunc_t func, NULL);
+
+#elif defined(CONFIG_SCHED_ATEXIT_MAX) && CONFIG_SCHED_ATEXIT_MAX > 1
_TCB *tcb = (_TCB*)g_readytorun.head;
int index;
int ret = ERROR;
diff --git a/nuttx/sched/clock_time2ticks.c b/nuttx/sched/clock_time2ticks.c
index 383264d51..9265872bb 100644
--- a/nuttx/sched/clock_time2ticks.c
+++ b/nuttx/sched/clock_time2ticks.c
@@ -97,6 +97,6 @@ int clock_time2ticks(FAR const struct timespec *reltime, FAR int *ticks)
/* Convert microseconds to clock ticks */
- *ticks = relusec / USEC_PER_TICK;
+ *ticks = (relusec + USEC_PER_TICK - 1) / USEC_PER_TICK;
return OK;
}
diff --git a/nuttx/sched/env_clearenv.c b/nuttx/sched/env_clearenv.c
index 7fe97a911..75890f3bc 100644
--- a/nuttx/sched/env_clearenv.c
+++ b/nuttx/sched/env_clearenv.c
@@ -79,5 +79,3 @@ int clearenv(void)
#endif /* CONFIG_DISABLE_ENVIRON */
-
-
diff --git a/nuttx/sched/env_internal.h b/nuttx/sched/env_internal.h
index a6205d658..5370da059 100644
--- a/nuttx/sched/env_internal.h
+++ b/nuttx/sched/env_internal.h
@@ -80,7 +80,7 @@ EXTERN int env_dup(FAR _TCB *ptcb);
EXTERN int env_share(FAR _TCB *ptcb);
EXTERN int env_release(FAR _TCB *ptcb);
-/* functions used internally the environment handling logic */
+/* functions used internally by the environment handling logic */
EXTERN FAR char *env_findvar(environ_t *envp, const char *pname);
EXTERN int env_removevar(environ_t *envp, char *pvar);
diff --git a/nuttx/sched/env_release.c b/nuttx/sched/env_release.c
index 83e65dbb5..8bc8d2205 100644
--- a/nuttx/sched/env_release.c
+++ b/nuttx/sched/env_release.c
@@ -94,11 +94,11 @@ int env_release(FAR _TCB *ptcb)
{
/* Check the reference count on the environment structure */
- if ( envp->ev_crefs <= 1)
+ if (envp->ev_crefs <= 1)
{
/* Decrementing the reference count will destroy the environment */
- sched_free( envp ); /* plain free() should be fine here */
+ sched_free(envp);
}
else
{
diff --git a/nuttx/sched/mq_open.c b/nuttx/sched/mq_open.c
index 5e1b9b137..89d80f072 100644
--- a/nuttx/sched/mq_open.c
+++ b/nuttx/sched/mq_open.c
@@ -113,7 +113,6 @@ mqd_t mq_open(const char *mq_name, int oflags, ...)
FAR msgq_t *msgq;
mqd_t mqdes = NULL;
va_list arg; /* Points to each un-named argument */
- mode_t mode; /* MQ creation mode parameter (ignored) */
struct mq_attr *attr; /* MQ creation attributes */
int namelen; /* Length of MQ name */
@@ -170,7 +169,7 @@ mqd_t mq_open(const char *mq_name, int oflags, ...)
*/
va_start(arg, oflags);
- mode = va_arg(arg, mode_t);
+ (void)va_arg(arg, mode_t); /* MQ creation mode parameter (ignored) */
attr = va_arg(arg, struct mq_attr*);
/* Initialize the new named message queue */
diff --git a/nuttx/sched/on_exit.c b/nuttx/sched/on_exit.c
index 5b8be5cd1..19a4f9196 100644
--- a/nuttx/sched/on_exit.c
+++ b/nuttx/sched/on_exit.c
@@ -117,7 +117,7 @@ int on_exit(CODE void (*func)(int, FAR void *), FAR void *arg)
#if defined(CONFIG_SCHED_ONEXIT_MAX) && CONFIG_SCHED_ONEXIT_MAX > 1
_TCB *tcb = (_TCB*)g_readytorun.head;
int index;
- int ret = ERROR;
+ int ret = ENOSPC;
/* The following must be atomic */
@@ -131,7 +131,6 @@ int on_exit(CODE void (*func)(int, FAR void *), FAR void *arg)
* indices.
*/
- available = -1;
for (index = 0; index < CONFIG_SCHED_ONEXIT_MAX; index++)
{
if (!tcb->onexitfunc[index])
@@ -149,7 +148,7 @@ int on_exit(CODE void (*func)(int, FAR void *), FAR void *arg)
return ret;
#else
_TCB *tcb = (_TCB*)g_readytorun.head;
- int ret = ERROR;
+ int ret = ENOSPC;
/* The following must be atomic */
diff --git a/nuttx/sched/os_bringup.c b/nuttx/sched/os_bringup.c
index ec6152891..e0a236bbe 100644
--- a/nuttx/sched/os_bringup.c
+++ b/nuttx/sched/os_bringup.c
@@ -44,6 +44,7 @@
#include <nuttx/config.h>
#include <sched.h>
+#include <stdlib.h>
#include <debug.h>
#include <nuttx/init.h>
@@ -129,6 +130,17 @@ int os_bringup(void)
#endif
int init_taskid;
+ /* Setup up the initial environment for the idle task. At present, this
+ * may consist of only the initial PATH variable. The PATH variable is
+ * (probably) not used by the IDLE task. However, the environment
+ * containing the PATH variable will be inherited by all of the threads
+ * created by the IDLE task.
+ */
+
+#if !defined(CONFIG_DISABLE_ENVIRON) && defined(CONFIG_PATH_INITIAL)
+ (void)setenv("PATH", CONFIG_PATH_INITIAL, 1);
+#endif
+
/* Start the page fill worker kernel thread that will resolve page faults.
* This should always be the first thread started because it may have to
* resolve page faults in other threads
@@ -190,5 +202,12 @@ int os_bringup(void)
(main_t)CONFIG_USER_ENTRYPOINT, (const char **)NULL);
#endif
ASSERT(init_taskid != ERROR);
+
+ /* We an save a few bytes by discarding the IDLE thread's environment. */
+
+#if !defined(CONFIG_DISABLE_ENVIRON) && defined(CONFIG_PATH_INITIAL)
+ (void)clearenv();
+#endif
+
return OK;
}
diff --git a/nuttx/sched/os_start.c b/nuttx/sched/os_start.c
index c0b16236d..a53ac2aa8 100644
--- a/nuttx/sched/os_start.c
+++ b/nuttx/sched/os_start.c
@@ -426,7 +426,9 @@ void os_start(void)
lib_initialize();
}
- /* Create stdout, stderr, stdin */
+ /* Create stdout, stderr, stdin on the IDLE task. These will be
+ * inherited by all of the threads created by the IDLE task.
+ */
(void)sched_setupidlefiles(&g_idletcb);
diff --git a/nuttx/lib/stdio/lib_vdprintf.c b/nuttx/sched/pause.c
index c2b576110..607c4c775 100644
--- a/nuttx/lib/stdio/lib_vdprintf.c
+++ b/nuttx/sched/pause.c
@@ -1,8 +1,8 @@
/****************************************************************************
- * lib/stdio/lib_vdprintf.c
+ * sched/pause.c
*
- * Copyright (C) 2007-2009, 2011 Andrew Tridgell. All rights reserved.
- * Author: Andrew Tridgell <andrew@tridgell.net>
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -39,43 +39,72 @@
#include <nuttx/config.h>
-#include <stdio.h>
-
-#include "lib_internal.h"
+#include <unistd.h>
+#include <signal.h>
/****************************************************************************
- * Pre-processor Definitions
+ * Preprocessor Definitions
****************************************************************************/
/****************************************************************************
- * Private Type Declarations
- ****************************************************************************/
-
-/****************************************************************************
- * Private Function Prototypes
+ * Private Type Definitions
****************************************************************************/
/****************************************************************************
- * Global Constant Data
+ * Global Variables
****************************************************************************/
/****************************************************************************
- * Global Variables
+ * Private Variables
****************************************************************************/
/****************************************************************************
- * Private Constant Data
+ * Private Function Prototypes
****************************************************************************/
/****************************************************************************
- * Private Variables
+ * Public Functions
****************************************************************************/
/****************************************************************************
- * Public Functions
+ * Name: pause
+ *
+ * Description:
+ * The pause() function will suspend the calling thread until delivery of a
+ * non-blocked signal.
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * Since pause() suspends thread execution indefinitely unless interrupted
+ * a signal, there is no successful completion return value. A value of -1
+ * will always be returned and errno set to indicate the error (EINTR).
+ *
+ * POSIX compatibility:
+ * In the POSIX description of this function is the pause() function will
+ * suspend the calling thread until delivery of a signal whose action is
+ * either to execute a signal-catching function or to terminate the
+ * process. This implementation only waits for any non-blocked signal
+ * to be received.
+ *
****************************************************************************/
-int vdprintf(int fd, FAR const char *fmt, va_list ap)
+int pause(void)
{
- return lib_rawvdprintf(fd, fmt, ap);
+ sigset_t set;
+ struct siginfo value;
+
+ /* Set up for the sleep. Using the empty set means that we are not
+ * waiting for any particular signal. However, any unmasked signal
+ * can still awaken sigtimedwait().
+ */
+
+ (void)sigemptyset(&set);
+
+ /* sigtwaitinfo() cannot succeed. It should always return error EINTR
+ * meaning that some unblocked signal was caught.
+ */
+
+ return sigwaitinfo(&set, &value);
}
diff --git a/nuttx/sched/prctl.c b/nuttx/sched/prctl.c
index d71a0e174..3db83d3d7 100644
--- a/nuttx/sched/prctl.c
+++ b/nuttx/sched/prctl.c
@@ -157,8 +157,14 @@ int prctl(int option, ...)
goto errout;
}
+ /* Not reachable unless CONFIG_TASK_NAME_SIZE is > 0. NOTE: This might
+ * change if additional commands are supported.
+ */
+
+#if CONFIG_TASK_NAME_SIZE > 0
va_end(ap);
return OK;
+#endif
errout:
va_end(ap);
diff --git a/nuttx/sched/pthread_create.c b/nuttx/sched/pthread_create.c
index 5fdf3b88d..dc2db2916 100644
--- a/nuttx/sched/pthread_create.c
+++ b/nuttx/sched/pthread_create.c
@@ -246,7 +246,7 @@ int pthread_create(FAR pthread_t *thread, FAR pthread_attr_t *attr,
{
FAR _TCB *ptcb;
FAR join_t *pjoin;
- int status;
+ int ret;
int priority;
#if CONFIG_RR_INTERVAL > 0
int policy;
@@ -268,13 +268,27 @@ int pthread_create(FAR pthread_t *thread, FAR pthread_attr_t *attr,
return ENOMEM;
}
+ /* Share the address environment of the parent task. NOTE: Only tasks
+ * created throught the nuttx/binfmt loaders may have an address
+ * environment.
+ */
+
+#ifdef CONFIG_ADDRENV
+ ret = up_addrenv_share((FAR const _TCB *)g_readytorun.head, ptcb);
+ if (ret < 0)
+ {
+ sched_releasetcb(ptcb);
+ return -ret;
+ }
+#endif
+
/* Associate file descriptors with the new task */
- status = sched_setuppthreadfiles(ptcb);
- if (status != OK)
+ ret = sched_setuppthreadfiles(ptcb);
+ if (ret != OK)
{
sched_releasetcb(ptcb);
- return status;
+ return ret;
}
/* Share the parent's envionment */
@@ -292,8 +306,8 @@ int pthread_create(FAR pthread_t *thread, FAR pthread_attr_t *attr,
/* Allocate the stack for the TCB */
- status = up_create_stack(ptcb, attr->stacksize);
- if (status != OK)
+ ret = up_create_stack(ptcb, attr->stacksize);
+ if (ret != OK)
{
sched_releasetcb(ptcb);
sched_free(pjoin);
@@ -310,8 +324,8 @@ int pthread_create(FAR pthread_t *thread, FAR pthread_attr_t *attr,
/* Get the priority for this thread. */
struct sched_param param;
- status = sched_getparam(0, &param);
- if (status == OK)
+ ret = sched_getparam(0, &param);
+ if (ret == OK)
{
priority = param.sched_priority;
}
@@ -348,11 +362,9 @@ int pthread_create(FAR pthread_t *thread, FAR pthread_attr_t *attr,
/* Initialize the task control block */
- status = task_schedsetup(ptcb, priority, pthread_start,
- (main_t)start_routine);
- if (status != OK)
+ ret = task_schedsetup(ptcb, priority, pthread_start, (main_t)start_routine);
+ if (ret != OK)
{
-
sched_releasetcb(ptcb);
sched_free(pjoin);
return EBUSY;
@@ -390,21 +402,21 @@ int pthread_create(FAR pthread_t *thread, FAR pthread_attr_t *attr,
/* Initialize the semaphores in the join structure to zero. */
- status = sem_init(&pjoin->data_sem, 0, 0);
- if (status == OK)
+ ret = sem_init(&pjoin->data_sem, 0, 0);
+ if (ret == OK)
{
- status = sem_init(&pjoin->exit_sem, 0, 0);
+ ret = sem_init(&pjoin->exit_sem, 0, 0);
}
/* Activate the task */
sched_lock();
- if (status == OK)
+ if (ret == OK)
{
- status = task_activate(ptcb);
+ ret = task_activate(ptcb);
}
- if (status == OK)
+ if (ret == OK)
{
/* Wait for the task to actually get running and to register
* its join_t
@@ -414,8 +426,15 @@ int pthread_create(FAR pthread_t *thread, FAR pthread_attr_t *attr,
/* Return the thread information to the caller */
- if (thread) *thread = (pthread_t)pid;
- if (!pjoin->started) status = ERROR;
+ if (thread)
+ {
+ *thread = (pthread_t)pid;
+ }
+
+ if (!pjoin->started)
+ {
+ ret = EINVAL;
+ }
sched_unlock();
(void)sem_destroy(&pjoin->data_sem);
@@ -428,8 +447,8 @@ int pthread_create(FAR pthread_t *thread, FAR pthread_attr_t *attr,
(void)sem_destroy(&pjoin->exit_sem);
sched_releasetcb(ptcb);
sched_free(pjoin);
- return EIO;
+ ret = EIO;
}
- return OK;
+ return ret;
}
diff --git a/nuttx/sched/sched_getscheduler.c b/nuttx/sched/sched_getscheduler.c
index 5771e86ff..0d996ca27 100644
--- a/nuttx/sched/sched_getscheduler.c
+++ b/nuttx/sched/sched_getscheduler.c
@@ -129,3 +129,4 @@ int sched_getscheduler(pid_t pid)
return SCHED_FIFO;
}
}
+
diff --git a/nuttx/sched/sched_releasetcb.c b/nuttx/sched/sched_releasetcb.c
index 21837262d..0557c829b 100644
--- a/nuttx/sched/sched_releasetcb.c
+++ b/nuttx/sched/sched_releasetcb.c
@@ -171,6 +171,12 @@ int sched_releasetcb(FAR _TCB *tcb)
(void)env_release(tcb);
+ /* Release this thread's reference to the address environment */
+
+#ifdef CONFIG_ADDRENV
+ ret = up_addrenv_release(tcb);
+#endif
+
/* And, finally, release the TCB itself */
sched_free(tcb);
diff --git a/nuttx/sched/sem_open.c b/nuttx/sched/sem_open.c
index 817c36b49..b2b76fe38 100644
--- a/nuttx/sched/sem_open.c
+++ b/nuttx/sched/sem_open.c
@@ -120,7 +120,6 @@ FAR sem_t *sem_open (FAR const char *name, int oflag, ...)
FAR nsem_t *psem;
FAR sem_t *sem = (FAR sem_t*)ERROR;
va_list arg; /* Points to each un-named argument */
- mode_t mode; /* Creation mode parameter (ignored) */
unsigned int value; /* Semaphore value parameter */
/* Make sure that a non-NULL name is supplied */
@@ -165,7 +164,7 @@ FAR sem_t *sem_open (FAR const char *name, int oflag, ...)
*/
va_start(arg, oflag);
- mode = va_arg(arg, mode_t);
+ (void)va_arg(arg, mode_t); /* Creation mode parameter (ignored) */
value = va_arg(arg, unsigned int);
/* Verify that a legal initial value was selected. */
diff --git a/nuttx/sched/sleep.c b/nuttx/sched/sleep.c
index 03884a5b6..9b3b6d57f 100644
--- a/nuttx/sched/sleep.c
+++ b/nuttx/sched/sleep.c
@@ -141,7 +141,7 @@ unsigned int sleep(unsigned int seconds)
if (seconds)
{
/* Set up for the sleep. Using the empty set means that we are not
- * waiting for any particualar signal. However, any unmasked signal
+ * waiting for any particular signal. However, any unmasked signal
* can still awaken sigtimedwait().
*/
diff --git a/nuttx/sched/task_exithook.c b/nuttx/sched/task_exithook.c
index e94476f2a..3bde8fb7a 100644
--- a/nuttx/sched/task_exithook.c
+++ b/nuttx/sched/task_exithook.c
@@ -81,8 +81,8 @@
* Call any registerd atexit function(s)
*
****************************************************************************/
-
-#ifdef CONFIG_SCHED_ATEXIT
+
+#if defined(CONFIG_SCHED_ATEXIT) && !defined(CONFIG_SCHED_ONEXIT)
static inline void task_atexit(FAR _TCB *tcb)
{
#if defined(CONFIG_SCHED_ATEXIT_MAX) && CONFIG_SCHED_ATEXIT_MAX > 1
@@ -126,6 +126,7 @@ static inline void task_atexit(FAR _TCB *tcb)
tcb->atexitfunc = NULL;
}
#endif
+}
#else
# define task_atexit(tcb)
#endif
diff --git a/nuttx/sched/usleep.c b/nuttx/sched/usleep.c
index 21996d788..893a420f4 100644
--- a/nuttx/sched/usleep.c
+++ b/nuttx/sched/usleep.c
@@ -137,7 +137,7 @@ int usleep(useconds_t usec)
if (usec)
{
/* Set up for the sleep. Using the empty set means that we are not
- * waiting for any particualar signal. However, any unmasked signal
+ * waiting for any particular signal. However, any unmasked signal
* can still awaken sigtimedwait().
*/
diff --git a/nuttx/sched/work_thread.c b/nuttx/sched/work_thread.c
index abd86f771..5646b06a1 100644
--- a/nuttx/sched/work_thread.c
+++ b/nuttx/sched/work_thread.c
@@ -208,10 +208,10 @@ int work_hpthread(int argc, char *argv[])
* that were queued because they could not be freed in that execution
* context (for example, if the memory was freed from an interrupt handler).
* NOTE: If the work thread is disabled, this clean-up is performed by
- * the IDLE thread (at a very, very lower priority).
+ * the IDLE thread (at a very, very low priority).
*/
-#ifdef CONFIG_SCHED_LPWORK
+#ifndef CONFIG_SCHED_LPWORK
sched_garbagecollection();
#endif
@@ -236,7 +236,7 @@ int work_lpthread(int argc, char *argv[])
* that were queued because they could not be freed in that execution
* context (for example, if the memory was freed from an interrupt handler).
* NOTE: If the work thread is disabled, this clean-up is performed by
- * the IDLE thread (at a very, very lower priority).
+ * the IDLE thread (at a very, very low priority).
*/
sched_garbagecollection();
diff --git a/nuttx/syscall/Makefile b/nuttx/syscall/Makefile
index 88365759d..4556912be 100644
--- a/nuttx/syscall/Makefile
+++ b/nuttx/syscall/Makefile
@@ -1,7 +1,7 @@
############################################################################
# syscall/Makefile
#
-# Copyright (C) 2011 Gregory Nutt. All rights reserved.
+# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
@@ -34,11 +34,13 @@
###########################################################################
-include $(TOPDIR)/Make.defs
-include proxies/Make.defs
-include stubs/Make.defs
+DELIM ?= $(strip /)
-MKSYSCALL = "$(TOPDIR)/tools/mksyscall$(EXEEXT)"
-CSVFILE = "$(TOPDIR)/syscall/syscall.csv"
+include proxies$(DELIM)Make.defs
+include stubs$(DELIM)Make.defs
+
+MKSYSCALL = "$(TOPDIR)$(DELIM)tools$(DELIM)mksyscall$(EXEEXT)"
+CSVFILE = "$(TOPDIR)$(DELIM)syscall$(DELIM)syscall.csv"
STUB_SRCS += stub_lookup.c
@@ -72,42 +74,43 @@ $(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
$(BIN1): $(PROXY_OBJS)
- @( for obj in $(PROXY_OBJS) ; do \
- $(call ARCHIVE, $@, $${obj}); \
- done ; )
+ $(call ARCHIVE, $@, $(PROXY_OBJS))
$(BIN2): $(STUB_OBJS)
- @( for obj in $(STUB_OBJS) ; do \
- $(call ARCHIVE, $@, $${obj}); \
- done ; )
+ $(call ARCHIVE, $@, "$(STUB_OBJS)")
.depend: Makefile $(SRCS)
- @$(MKDEP) $(ROOTDEPPATH) $(PROXYDEPPATH) $(STUBDEPPATH) \
- $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
- @touch $@
+ $(Q) $(MKDEP) $(ROOTDEPPATH) $(PROXYDEPPATH) $(STUBDEPPATH) \
+ "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
+ $(Q) touch $@
depend: .depend
$(MKSYSCALL):
- @$(MAKE) -C $(TOPDIR)/tools -f Makefile.host mksyscall
+ $(Q) $(MAKE) -C $(TOPDIR)$(DELIM)tools -f Makefile.host mksyscall
.context: syscall.csv
- @(cd proxies; $(MKSYSCALL) -p $(CSVFILE);)
- @(cd stubs; $(MKSYSCALL) -s $(CSVFILE);)
- @touch $@
+ $(Q) (cd proxies; $(MKSYSCALL) -p $(CSVFILE);)
+ $(Q) (cd stubs; $(MKSYSCALL) -s $(CSVFILE);)
+ $(Q) touch $@
context: $(MKSYSCALL) .context
clean:
- @rm -f $(BIN1) $(BIN2) *~ .*.swp
+ $(call DELFILE, $(BIN1))
+ $(call DELFILE, $(BIN2))
ifneq ($(OBJEXT),)
- @rm -f proxies/*$(OBJEXT) stubs/*$(OBJEXT)
+ $(call DELFILE, proxies$(DELIM)*$(OBJEXT))
+ $(call DELFILE, stubs$(DELIM)*$(OBJEXT))
endif
$(call CLEAN)
distclean: clean
- @rm -f Make.dep .depend .context
- @rm -f proxies/*.c stubs/*.c
+ $(call DELFILE, .context)
+ $(call DELFILE, Make.dep)
+ $(call DELFILE, .depend)
+ $(call DELFILE, proxies$(DELIM)*.c)
+ $(call DELFILE, stubs$(DELIM)*.c)
-include Make.dep
diff --git a/nuttx/tools/Config.mk b/nuttx/tools/Config.mk
index 3a82a1937..9ac93e7d0 100644
--- a/nuttx/tools/Config.mk
+++ b/nuttx/tools/Config.mk
@@ -2,7 +2,12 @@
# Config.mk
# Global build rules and macros.
#
+# Copyright (C) 2011 Gregory Nutt. All rights reserved.
# Author: Richard Cochran
+# Gregory Nutt <gnutt@nuttx.org>
+#
+# This file (along with $(TOPDIR)/.config) must be included by every
+# configuration-specific Make.defs file.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -40,33 +45,177 @@ CONFIG_ARCH := $(patsubst "%",%,$(strip $(CONFIG_ARCH)))
CONFIG_ARCH_CHIP := $(patsubst "%",%,$(strip $(CONFIG_ARCH_CHIP)))
CONFIG_ARCH_BOARD := $(patsubst "%",%,$(strip $(CONFIG_ARCH_BOARD)))
-# Default build rules.
+# Some defaults just to prohibit some bad behavior if for some reason they
+# are not defined
+
+OBJEXT ?= .o
+LIBEXT ?= .a
+
+# DELIM - Path segment delimiter character
+#
+# Depends on this settings defined in board-specific defconfig file installed
+# at $(TOPDIR)/.config:
+#
+# CONFIG_WINDOWS_NATIVE - Defined for a Windows native build
+
+ifeq ($(CONFIG_WINDOWS_NATIVE),y)
+ DELIM = $(strip \)
+else
+ DELIM = $(strip /)
+endif
+
+# INCDIR - Convert a list of directory paths to a list of compiler include
+# directirves
+# Example: CFFLAGS += ${shell $(INCDIR) [options] "compiler" "dir1" "dir2" "dir2" ...}
+#
+# Note that the compiler string and each directory path string must quoted if
+# they contain spaces or any other characters that might get mangled by the
+# shell
+#
+# Depends on this setting passed as a make commaond line definition from the
+# toplevel Makefile:
+#
+# TOPDIR - The path to the the top level NuttX directory in the form
+# appropriate for the current build environment
+#
+# Depends on this settings defined in board-specific defconfig file installed
+# at $(TOPDIR)/.config:
+#
+# CONFIG_WINDOWS_NATIVE - Defined for a Windows native build
+
+ifeq ($(CONFIG_WINDOWS_NATIVE),y)
+ INCDIR = "$(TOPDIR)\tools\incdir.bat"
+else
+ INCDIR = "$(TOPDIR)/tools/incdir.sh"
+endif
+
+# PREPROCESS - Default macro to run the C pre-processor
+# Example: $(call PREPROCESS, in-file, out-file)
+#
+# Depends on these settings defined in board-specific Make.defs file
+# installed at $(TOPDIR)/Make.defs:
+#
+# CPP - The command to invoke the C pre-processor
+# CPPFLAGS - Options to pass to the C pre-processor
define PREPROCESS
@echo "CPP: $1->$2"
$(Q) $(CPP) $(CPPFLAGS) $1 -o $2
endef
+# COMPILE - Default macro to compile one C file
+# Example: $(call COMPILE, in-file, out-file)
+#
+# Depends on these settings defined in board-specific Make.defs file
+# installed at $(TOPDIR)/Make.defs:
+#
+# CC - The command to invoke the C compiler
+# CFLAGS - Options to pass to the C compiler
+
define COMPILE
@echo "CC: $1"
$(Q) $(CC) -c $(CFLAGS) $1 -o $2
endef
+# COMPILEXX - Default macro to compile one C++ file
+# Example: $(call COMPILEXX, in-file, out-file)
+#
+# Depends on these settings defined in board-specific Make.defs file
+# installed at $(TOPDIR)/Make.defs:
+#
+# CXX - The command to invoke the C++ compiler
+# CXXFLAGS - Options to pass to the C++ compiler
+
define COMPILEXX
@echo "CXX: $1"
$(Q) $(CXX) -c $(CXXFLAGS) $1 -o $2
endef
+# ASSEMBLE - Default macro to assemble one assembly language file
+# Example: $(call ASSEMBLE, in-file, out-file)
+#
+# NOTE that the most common toolchain, GCC, uses the compiler to assemble
+# files because this has the advantage of running the C Pre-Processor against
+# the assembly language files. This is not possible with other toolchains;
+# platforms using those other tools should define AS and over-ride this
+# definition in order to use the assembler directly.
+#
+# Depends on these settings defined in board-specific Make.defs file
+# installed at $(TOPDIR)/Make.defs:
+#
+# CC - By default, the C compiler is used to compile assembly language
+# files
+# AFLAGS - Options to pass to the C+compiler
+
define ASSEMBLE
@echo "AS: $1"
$(Q) $(CC) -c $(AFLAGS) $1 -o $2
endef
+# ARCHIVE - Add a list of files to an archive
+# Example: $(call ARCHIVE, archive-file, "file1 file2 file3 ...")
+#
+# Note: The fileN strings may not contain spaces or characters that may be
+# interpreted strangely by the shell
+#
+# Depends on these settings defined in board-specific Make.defs file
+# installed at $(TOPDIR)/Make.defs:
+#
+# AR - The command to invoke the archiver (includes any options)
+#
+# Depends on this settings defined in board-specific defconfig file installed
+# at $(TOPDIR)/.config:
+#
+# CONFIG_WINDOWS_NATIVE - Defined for a Windows native build
+
+ifeq ($(CONFIG_WINDOWS_NATIVE),y)
+define ARCHIVE
+ @echo AR: $2
+ $(Q) $(AR) $1 $(2)
+endef
+else
define ARCHIVE
- echo "AR: $2"; \
- $(AR) $1 $2 || { echo "$(AR) $1 $2 FAILED!" ; exit 1 ; }
+ @echo "AR: $2"
+ $(Q) $(AR) $1 $(2) || { echo "$(AR) $1 FAILED!" ; exit 1 ; }
endef
+endif
+# DELFILE - Delete one file
+
+ifeq ($(CONFIG_WINDOWS_NATIVE),y)
+define DELFILE
+ $(Q) if exist $1 (del /f /q $1)
+endef
+else
+define DELFILE
+ $(Q) rm -f $1
+endef
+endif
+
+# DELDIR - Delect one directory
+
+ifeq ($(CONFIG_WINDOWS_NATIVE),y)
+define DELDIR
+ $(Q) if exist $1 (rmdir /q /s $1)
+endef
+else
+define DELDIR
+ $(Q) rm -rf $1
+endef
+endif
+
+# CLEAN - Default clean target
+
+ifeq ($(CONFIG_WINDOWS_NATIVE),y)
+define CLEAN
+ $(Q) if exist *$(OBJEXT) (del /f /q *$(OBJEXT))
+ $(Q) if exist *$(LIBEXT) (del /f /q *$(LIBEXT))
+ $(Q) if exist *~ (del /f /q *~)
+ $(Q) if exist (del /f /q .*.swp)
+endef
+else
define CLEAN
- $(Q) rm -f *.o *.a
+ $(Q) rm -f *$(OBJEXT) *$(LIBEXT) *~ .*.swp
endef
+endif
+ \ No newline at end of file
diff --git a/nuttx/tools/Makefile.export b/nuttx/tools/Makefile.export
index ce4842187..002cb526b 100644
--- a/nuttx/tools/Makefile.export
+++ b/nuttx/tools/Makefile.export
@@ -37,10 +37,16 @@ include $(TOPDIR)/.config
include $(EXPORTDIR)/Make.defs
ifdef ARCHSCRIPT
-LDPATH = ${shell echo "$(ARCHSCRIPT)" | sed -e "s/^-T[ ]*//g"}
+ifeq ($(WINTOOL),y)
+LDPATH = ${shell cygpath -u $(patsubst -T,,$(ARCHSCRIPT))}
+else
+LDPATH = $(patsubst -T,,$(ARCHSCRIPT))
+endif
+
LDNAME = ${shell basename ${LDPATH}}
LDDIR = ${shell dirname ${LDPATH}}
endif
+
ARCHSUBDIR = "arch/$(CONFIG_ARCH)/src"
ARCHDIR ="$(TOPDIR)/$(ARCHSUBDIR)"
@@ -61,7 +67,7 @@ endif
@echo "ARCHCFLAGS=\"$(ARCHCFLAGS) $(ARCHCPUFLAGS)\"" >> $(EXPORTDIR)/makeinfo.sh
@echo "ARCHCXXFLAGS=\"$(ARCHCXXFLAGS) $(ARCHCPUFLAGS)\"" >> $(EXPORTDIR)/makeinfo.sh
@echo "CROSSDEV=\"$(CROSSDEV)\"" >> $(EXPORTDIR)/makeinfo.sh
- @chmod 755 $(EXPORTDIR)/makeinfo.sh
+ $(Q) chmod 755 $(EXPORTDIR)/makeinfo.sh
clean:
- @rm -f $(EXPORTDIR)/makeinfo.sh
+ $(Q) rm -f $(EXPORTDIR)/makeinfo.sh
diff --git a/nuttx/tools/Makefile.host b/nuttx/tools/Makefile.host
index 33b7aaab2..4a46901e6 100644
--- a/nuttx/tools/Makefile.host
+++ b/nuttx/tools/Makefile.host
@@ -33,45 +33,119 @@
#
############################################################################
-all: mkconfig mkversion mksyscall bdf-converter
-default: mkconfig mksyscall
+TOPDIR ?= ${shell pwd}/..
+-include $(TOPDIR)/Make.defs
+include ${TOPDIR}/tools/Config.mk
+
+# strtok_r is used in some tools, but does not seem to be available in
+# the MinGW environment.
+
+ifneq ($(CONFIG_WINDOWS_NATIVE),y)
+ HOSTCFLAGS += -D HAVE_STRTOK_C
+endif
+
+all: b16$(HOSTEXEEXT) bdf-converter$(HOSTEXEEXT) cmpconfig$(HOSTEXEEXT) \
+ mkconfig$(HOSTEXEEXT) mkdeps$(HOSTEXEEXT) mksymtab$(HOSTEXEEXT) \
+ mksyscall$(HOSTEXEEXT) mkversion$(HOSTEXEEXT)
+default: mkconfig$(HOSTEXEEXT) mksyscall$(HOSTEXEEXT) mkdeps$(HOSTEXEEXT)
+
+ifdef HOSTEXEEXT
+.PHONY: b16 bdf-converter cmpconfig clean mkconfig mkdeps mksymtab \
+ mksyscall mkversion
+else
.PHONY: clean
+endif
-# Add CFLAGS=-g on the make command line build debug versions
+# Add HOSTCFLAGS=-g on the make command line build debug versions
-CFLAGS = -O2 -Wall -I.
+HOSTCFLAGS ?= -O2 -Wall -I.
+HOSTCC ?= gcc
+
+# b16 - Fixed precision math converstion tool
+
+b16$(HOSTEXEEXT): b16.c
+ $(Q) $(HOSTCC) $(HOSTCFLAGS) -o b16$(HOSTEXEEXT) b16.c
+
+ifdef HOSTEXEEXT
+b16: b16$(HOSTEXEEXT)
+endif
# mkconfig - Convert a .config file into a C config.h file
-mkconfig: mkconfig.c cfgparser.c
- @gcc $(CFLAGS) -o mkconfig mkconfig.c cfgparser.c
+mkconfig$(HOSTEXEEXT): mkconfig.c cfgparser.c
+ $(Q) $(HOSTCC) $(HOSTCFLAGS) -o mkconfig$(HOSTEXEEXT) mkconfig.c cfgparser.c
+
+ifdef HOSTEXEEXT
+mkconfig: mkconfig$(HOSTEXEEXT)
+endif
# cmpconfig - Compare the contents of two configuration files
-cmpconfig: cmpconfig.c
- @gcc $(CFLAGS) -o cmpconfig cmpconfig.c
+cmpconfig$(HOSTEXEEXT): cmpconfig.c
+ $(Q) $(HOSTCC) $(HOSTCFLAGS) -o cmpconfig$(HOSTEXEEXT) cmpconfig.c
+
+ifdef HOSTEXEEXT
+cmpconfig: cmpconfig$(HOSTEXEEXT)
+endif
# mkversion - Convert a .version file into a C version.h file
-mkversion: mkconfig.c cfgparser.c
- @gcc $(CFLAGS) -o mkversion mkversion.c cfgparser.c
+mkversion$(HOSTEXEEXT): mkconfig.c cfgparser.c
+ $(Q) $(HOSTCC) $(HOSTCFLAGS) -o mkversion$(HOSTEXEEXT) mkversion.c cfgparser.c
+
+ifdef HOSTEXEEXT
+mkversion: mkversion$(HOSTEXEEXT)
+endif
# mksyscall - Convert a CSV file into syscall stubs and proxies
-mksyscall: mksyscall.c csvparser.c
- @gcc $(CFLAGS) -o mksyscall mksyscall.c csvparser.c
+mksyscall$(HOSTEXEEXT): mksyscall.c csvparser.c
+ $(Q) $(HOSTCC) $(HOSTCFLAGS) -o mksyscall$(HOSTEXEEXT) mksyscall.c csvparser.c
+
+ifdef HOSTEXEEXT
+mksyscall: mksyscall$(HOSTEXEEXT)
+endif
# mksymtab - Convert a CSV file into a symbol table
-mksymtab: mksymtab.c csvparser.c
- @gcc $(CFLAGS) -o mksymtab mksymtab.c csvparser.c
+mksymtab$(HOSTEXEEXT): mksymtab.c csvparser.c
+ $(Q) $(HOSTCC) $(HOSTCFLAGS) -o mksymtab$(HOSTEXEEXT) mksymtab.c csvparser.c
+
+ifdef HOSTEXEEXT
+mksymtab: mksymtab$(HOSTEXEEXT)
+endif
# bdf-converter - Converts a BDF font to the NuttX font format
-bdf-converter: bdf-converter.c
- @gcc $(CFLAGS) -o bdf-converter bdf-converter.c
+bdf-converter$(HOSTEXEEXT): bdf-converter.c
+ $(Q) $(HOSTCC) $(HOSTCFLAGS) -o bdf-converter$(HOSTEXEEXT) bdf-converter.c
+
+ifdef HOSTEXEEXT
+bdf-converter: bdf-converter$(HOSTEXEEXT)
+endif
+
+# Create dependencies for a list of files
+
+mkdeps$(HOSTEXEEXT): mkdeps.c csvparser.c
+ $(Q) $(HOSTCC) $(HOSTCFLAGS) -o mkdeps$(HOSTEXEEXT) mkdeps.c
+
+ifdef HOSTEXEEXT
+mkdeps: mkdeps$(HOSTEXEEXT)
+endif
clean:
- @rm -f *.o *.a *~ .*.swp
- @rm -f mkconfig mksyscall mkversion bdf-converter
- @rm -f mkconfig.exe mksyscall.exe mkversion.exe bdf-converter.exe
+ $(call DELFILE, mkdeps)
+ $(call DELFILE, mkdeps.exe)
+ $(call DELFILE, mkconfig)
+ $(call DELFILE, mkconfig.exe)
+ $(call DELFILE, Make.dep)
+ $(call DELFILE, mksyscall)
+ $(call DELFILE, mksyscall.exe)
+ $(call DELFILE, mkversion)
+ $(call DELFILE, mkversion.exe)
+ $(call DELFILE, bdf-converter)
+ $(call DELFILE, bdf-converter.exe)
+ifneq ($(CONFIG_WINDOWS_NATIVE),y)
+ $(Q) rm -rf *.dSYM
+endif
+ $(call CLEAN)
diff --git a/nuttx/tools/README.txt b/nuttx/tools/README.txt
index 5d52eaeff..2b9ac61f4 100644
--- a/nuttx/tools/README.txt
+++ b/nuttx/tools/README.txt
@@ -1,5 +1,5 @@
tools/README.txt
-^^^^^^^^^^^^^^^^
+================
This README file addresses the contents of the NuttX tools/ directory.
@@ -8,22 +8,38 @@ that are necessary parts of the the NuttX build system. These files
include:
README.txt
+----------
- This file
+ This file!
+
+Config.mk
+---------
+
+ This file contains common definitions used by many configureation files.
+ This file (along with <nuttx>/.config) must be included at the top of
+ each configuration-specific Make.defs file like:
+
+ -include $(TOPDIR)/.config
+ include $(TOPDIR)/tools/Config.mk
+
+ Subsequent logic within the configuration-specific Make.defs file may then
+ override these default definitions as necessary.
configure.sh
+------------
This is a bash script that is used to configure NuttX for a given
target board. See configs/README.txt or Documentation/NuttxPortingGuide.html
for a description of how to configure NuttX with this script.
discover.py
+-----------
Example script for discovering devices in the local network.
It is the counter part to apps/netutils/discover
-
mkconfig.c, cfgparser.c, and cfgparser.h
+----------------------------------------
These are Cs file that are used to build mkconfig program. The mkconfig
program is used during the initial NuttX build.
@@ -38,11 +54,13 @@ mkconfig.c, cfgparser.c, and cfgparser.h
NuttX configuration that can be included by C files.
cmdconfig.c
+-----------
This C file can be used to build a utility for comparing two NuttX
configuration files.
mkexport.sh and Makefile.export
+-------------------------------
These implement part of the top-level Makefile's 'export' target. That
target will bundle up all of the NuttX libraries, header files, and the
@@ -51,6 +69,7 @@ mkexport.sh and Makefile.export
options from the top-level Make.defs file.
mkfsdata.pl
+-----------
This perl script is used to build the "fake" file system and CGI support
as needed for the apps/netutils/webserver. It is currently used only
@@ -61,6 +80,7 @@ mkfsdata.pl
by Adam Dunkels. uIP has a license that is compatible with NuttX.
mkversion.c, cfgparser.c, and cfgparser.h
+-----------------------------------------
This is C file that is used to build mkversion program. The mkversion
program is used during the initial NuttX build.
@@ -74,6 +94,7 @@ mkversion.c, cfgparser.c, and cfgparser.h
version.h provides version information that can be included by C files.
mksyscall.c, cvsparser.c, and cvsparser.h
+-----------------------------------------
This is a C file that is used to build mksyscall program. The mksyscall
program is used during the initial NuttX build by the logic in the top-
@@ -96,6 +117,7 @@ mksyscall.c, cvsparser.c, and cvsparser.h
stub files as output. See syscall/README.txt for additonal information.
mksymtab.c, cvsparser.c, and cvsparser.h
+----------------------------------------
This is a C file that is used to build symbol tables from common-separated
value (CSV) files. This tool is not used during the NuttX build, but
@@ -116,10 +138,12 @@ mksymtab.c, cvsparser.c, and cvsparser.h
./mksymtab.exe tmp.csv tmp.c
pic32mx
+-------
This directory contains build tools used only for PIC32MX platforms
bdf-convert.c
+-------------
This C file is used to build the bdf-converter program. The bdf-converter
program be used to convert fonts in Bitmap Distribution Format (BDF)
@@ -255,6 +279,7 @@ bdf-convert.c
};
Makefile.host
+-------------
This is the makefile that is used to make the mkconfig program from
the mkconfig.c C file, the cmpconfig program from cmpconfig.c C file
@@ -265,20 +290,25 @@ Makefile.host
make -f Makefile.host <program>
mkromfsimg.sh
+-------------
This script may be used to automate the generate of a ROMFS file system
image. It accepts an rcS script "template" and generates and image that
may be mounted under /etc in the NuttX pseudo file system.
mkdeps.sh
+mkdeps.bat
+mkdeps.c
mknulldeps.sh
+-------------
NuttX uses the GCC compilers capabilities to create Makefile dependencies.
The bash script mkdeps.sh is used to run GCC in order to create the
dependencies. If a NuttX configuration uses the GCC toolchain, its Make.defs
file (see configs/README.txt) will include a line like:
- MKDEP = $(TOPDIR)/tools/mkdeps.sh
+ MKDEP = $(TOPDIR)/tools/mkdeps.sh, or
+ MKDEP = $(TOPDIR)/tools/mkdeps[.exe] (See NOTE below)
If the NuttX configuration does not use a GCC compatible toolchain, then
it cannot use the dependencies and instead it uses mknulldeps.sh:
@@ -287,23 +317,64 @@ mknulldeps.sh
The mknulldeps.sh is a stub script that does essentially nothing.
+ NOTE: The mk*deps.* files are undergoing change. mkdeps.sh is a bash
+ script that produces dependencies well for POSIX style hosts (e..g.,
+ Linux and Cygwin). It does not work well for mixed environments with
+ a Windows toolchain running in a POSIX style environemnt (hence, the
+ mknulldeps.sh script). And, of course, cannot be used in a Windows
+ nativ environment.
+
+ [mkdeps.sh does have an option, --winpath, that purports to convert
+ the dependencies generated by a Windows toolchain to POSIX format.
+ However, that is not being used and mostly likely does not cover
+ all of the conversion cases.]
+
+ mkdeps.bat is a simple port of the bash script to run in a Windows
+ command shell. However, it does not work well either because some
+ of the common CFLAGS use characters like '=' which are transformed
+ by the CMD.exe shell.
+
+ mkdeps.c generates mkdeps (on Linux) or mkdeps.exe (on Windows).
+ However, this verison is still under-development. It works well in
+ the all POSIX environment or in the all Windows environment but also
+ does not work well in mixed POSIX environment with a Windows toolchain.
+ In that case, there are still issues with the conversion of things like
+ 'c:\Program Files' to 'c:program files' by bash. Those issues may,
+ eventually be solvable but for now continue to use mknulldeps.sh in
+ that mixed environment.
+
define.sh
+define.bat
+---------
Different compilers have different conventions for specifying pre-
processor definitions on the compiler command line. This bash
script allows the build system to create create command line definitions
without concern for the particular compiler in use.
+ The define.bat script is a counterpart for use in the native Windows
+ build.
+
incdir.sh
+incdir.bat
+---------
Different compilers have different conventions for specifying lists
- of include file paths on the the compiler command line. This bash
- script allows the build system to create include file paths without
+ of include file paths on the the compiler command line. This incdir.sh
+ bash script allows the build system to create include file paths without
concern for the particular compiler in use.
+ The incdir.bat script is a counterpart for use in the native Windows
+ build. However, there is currently only one compiler supported in
+ that context: MinGW-GCC.
+
link.sh
-winlink.sh
+link.bat
+copydir.sh
+copydir.bat
unlink.sh
+unlink.bat
+----------
Different file system have different capabilities for symbolic links.
Some windows file systems have no native support for symbolic links.
@@ -322,30 +393,40 @@ unlink.sh
default. link.sh is a bash script that performs a normal, Linux-style
symbolic link; unlink.sh is a do-it-all unlinking script.
- But if you are building under cygwin using a Windows native toolchain,
- then you will need something like the following in you Make.defs file:
+ But if you are building under cygwin using a Windows native toolchain
+ within a POSIX framework (such as Cygwin), then you will need something
+ like the following in you Make.defs file:
- DIRLINK = $(TOPDIR)/tools/winlink.sh
+ DIRLINK = $(TOPDIR)/tools/copydir.sh
DIRUNLINK = (TOPDIR)/tools/unlink.sh
- winlink.sh will copy the whole directory instead of linking it.
+ copydir.sh will copy the whole directory instead of linking it.
+
+ Finally, if you are running in a pure native Windows environment with
+ a CMD.exe shell, then you will need something like this:
+
+ DIRLINK = $(TOPDIR)/tools/copydir.bat
+ DIRUNLINK = (TOPDIR)/tools/unlink.bat
- NOTE: I have been told that some NuttX users have been able to build
- successfully using the GnuWin32 tools and modifying the link.sh
- script so that it uses the NTFS mklink command. But I have never
- tried that
+ Note that this will copy directories. ;ink.bat might also be used in
+ this case. link.bat will attempt to create a symbolic link using the
+ NTFS mklink.exe command instead of copying files. That logic, however,
+ has not been verified as of this writing.
mkimage.sh
+----------
The creates a downloadable image as needed with the rrload bootloader.
indent.sh
+---------
This script can be used to indent .c and .h files in a manner similar
to my coding NuttX coding style. It doesn't do a really good job,
however (see the comments at the top of the indent.sh file).
zipme.sh
+--------
I use this script to create the nuttx-xx.yy.tar.gz tarballs for
release on SourceForge. It is handy because it also does the
diff --git a/nuttx/tools/b16.c b/nuttx/tools/b16.c
new file mode 100644
index 000000000..66d581ffa
--- /dev/null
+++ b/nuttx/tools/b16.c
@@ -0,0 +1,121 @@
+/****************************************************************************
+ * tools/b16.c
+ *
+ * Copyright (C) 2007-2012 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static void show_usage(const char *progname)
+{
+ fprintf(stderr, "\nUSAGE: %s <b16_t>|<float>\n", progname);
+ fprintf(stderr, "\nWhere:\n");
+ fprintf(stderr, " <b16_t>:\n");
+ fprintf(stderr, " A b16 fixed precision value in hexadecimal form: E.g., 0x00010000\n");
+ fprintf(stderr, " Any value begininning with '0' will assumed by be hexadecimal format\n");
+ fprintf(stderr, " <float>:\n");
+ fprintf(stderr, " A floating value in standard form: E.g., 5.1\n");
+ exit(EXIT_FAILURE);
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+int main(int argc, char **argv, char **envp)
+{
+ double fvalue;
+ unsigned long ulvalue;
+ long lvalue;
+ const char *str;
+ char *endptr;
+
+ /* There must be exactly one argument */
+
+ if (argc != 2)
+ {
+ fprintf(stderr, "\nExpected a single argument\n");
+ show_usage(argv[0]);
+ }
+ str = argv[1];
+
+ /* If the value begins with a zero, we will assume that it is a hexadecimal
+ * representation.
+ */
+
+ if (str[0] == '0')
+ {
+ endptr = NULL;
+ ulvalue = strtoul(str, &endptr, 16);
+ if (!endptr || *endptr != '\0')
+ {
+ fprintf(stderr, "\nHexadecimal argument not fully converted\n");
+ show_usage(argv[0]);
+ }
+
+ if (ulvalue >= 0x80000000)
+ {
+ lvalue = ~ulvalue + 1;
+ }
+ else
+ {
+ lvalue = ulvalue;
+ }
+
+ fvalue = ((double)lvalue) / 65536.0;
+ printf("0x%08lx -> %10.5f\n", ulvalue, fvalue);
+ }
+ else
+ {
+ endptr = NULL;
+ fvalue = strtod(str, &endptr);
+ if (!endptr || *endptr != '\0')
+ {
+ fprintf(stderr, "\nFloating point argument not fully converted\n");
+ show_usage(argv[0]);
+ }
+
+ lvalue = 65536.0 * fvalue;
+ printf("%10.5f -> 0x%08lx\n", fvalue, lvalue);
+ }
+
+ return 0;
+}
diff --git a/nuttx/tools/cfgparser.c b/nuttx/tools/cfgparser.c
index b1f189f6f..1a35f7857 100644
--- a/nuttx/tools/cfgparser.c
+++ b/nuttx/tools/cfgparser.c
@@ -2,7 +2,7 @@
* tools/cfgpaser.c
*
* Copyright (C) 2007-2012 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <>
+ * Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
diff --git a/nuttx/tools/configure.sh b/nuttx/tools/configure.sh
index 3b68fe3f6..ffa997178 100755
--- a/nuttx/tools/configure.sh
+++ b/nuttx/tools/configure.sh
@@ -100,32 +100,54 @@ if [ ! -d "${configpath}" ]; then
exit 3
fi
-if [ ! -r "${configpath}/Make.defs" ]; then
- echo "File \"${configpath}/Make.defs\" does not exist"
+src_makedefs="${configpath}/Make.defs"
+dest_makedefs="${TOPDIR}/Make.defs"
+
+if [ ! -r "${src_makedefs}" ]; then
+ echo "File \"${src_makedefs}\" does not exist"
exit 4
fi
-if [ ! -r "${configpath}/setenv.sh" ]; then
- echo "File \"${configpath}/setenv.sh\" does not exist"
- exit 5
+src_setenv="${configpath}/setenv.sh"
+unset have_setenv
+
+if [ -r "${src_setenv}" ]; then
+ dest_setenv=${TOPDIR}/setenv.sh
+ have_setenv=y
+else
+ src_setenv="${configpath}/setenv.bat"
+ if [ -r "${src_setenv}" ]; then
+ dest_setenv=${TOPDIR}/setenv.bat
+ have_setenv=y
+ else
+ unset src_setenv
+ fi
fi
-if [ ! -r "${configpath}/defconfig" ]; then
- echo "File \"${configpath}/defconfig\" does not exist"
+src_config="${configpath}/defconfig"
+tmp_config="${TOPDIR}/.configX"
+dest_config="${TOPDIR}/.config"
+
+if [ ! -r "${src_config}" ]; then
+ echo "File \"${src_config}\" does not exist"
exit 6
fi
# Extract values needed from the defconfig file. We need:
# (1) The CONFIG_NUTTX_NEWCONFIG setting to know if this is a "new" style
-# configuration, and
-# (2) The CONFIG_APPS_DIR to see if there is a configured location for the
-# application directory.
+# configuration,
+# (2) The CONFIG_WINDOWS_NATIVE setting to know it this is target for a
+# native Windows (meaning that we want setenv.bat vs setenv.sh and we need
+# to use backslashes in the CONFIG_APPS_DIR setting).
+# (3) The CONFIG_APPS_DIR setting to see if there is a configured location for the
+# application directory. This can be overridden from the command line.
-newconfig=`grep CONFIG_NUTTX_NEWCONFIG= "${configpath}/defconfig" | cut -d'=' -f2`
+newconfig=`grep CONFIG_NUTTX_NEWCONFIG= "${src_config}" | cut -d'=' -f2`
+winnative=`grep CONFIG_WINDOWS_NATIVE= "${src_config}" | cut -d'=' -f2`
defappdir=y
if [ -z "${appdir}" ]; then
- quoted=`grep "^CONFIG_APPS_DIR=" "${configpath}/defconfig" | cut -d'=' -f2`
+ quoted=`grep "^CONFIG_APPS_DIR=" "${src_config}" | cut -d'=' -f2`
if [ ! -z "${appdir}" ]; then
appdir=`echo ${quoted} | sed -e "s/\"//g"`
defappdir=n
@@ -157,34 +179,45 @@ if [ -z "${appdir}" ]; then
fi
fi
+# For checking the apps dir path, we need a POSIX version of the relative path.
+
+posappdir=`echo "${appdir}" | sed -e 's/\\\\/\\//g'`
+winappdir=`echo "${appdir}" | sed -e 's/\\//\\\\/g'`
+
# If appsdir was provided (or discovered) then make sure that the apps/
# directory exists
-if [ ! -z "${appdir}" -a ! -d "${TOPDIR}/${appdir}" ]; then
- echo "Directory \"${TOPDIR}/${appdir}\" does not exist"
+if [ ! -z "${appdir}" -a ! -d "${TOPDIR}/${posappdir}" ]; then
+ echo "Directory \"${TOPDIR}/${posappdir}\" does not exist"
exit 7
fi
# Okay... Everything looks good. Setup the configuration
-install -C "${configpath}/Make.defs" "${TOPDIR}/." || \
- { echo "Failed to copy ${configpath}/Make.defs" ; exit 7 ; }
-install -C "${configpath}/setenv.sh" "${TOPDIR}/." || \
- { echo "Failed to copy ${configpath}/setenv.sh" ; exit 8 ; }
-chmod 755 "${TOPDIR}/setenv.sh"
-install -C "${configpath}/defconfig" "${TOPDIR}/.configX" || \
- { echo "Failed to copy ${configpath}/defconfig" ; exit 9 ; }
+install "${src_makedefs}" "${dest_makedefs}" || \
+ { echo "Failed to copy \"${src_makedefs}\"" ; exit 7 ; }
+if [ "X${have_setenv}" = "Xy" ]; then
+ install "${src_setenv}" "${dest_setenv}" || \
+ { echo "Failed to copy ${src_setenv}" ; exit 8 ; }
+ chmod 755 "${dest_setenv}"
+fi
+install "${src_config}" "${tmp_config}" || \
+ { echo "Failed to copy \"${src_config}\"" ; exit 9 ; }
# If we did not use the CONFIG_APPS_DIR that was in the defconfig config file,
# then append the correct application information to the tail of the .config
# file
if [ "X${defappdir}" = "Xy" ]; then
- sed -i -e "/^CONFIG_APPS_DIR/d" "${TOPDIR}/.configX"
- echo "" >> "${TOPDIR}/.configX"
- echo "# Application configuration" >> "${TOPDIR}/.configX"
- echo "" >> "${TOPDIR}/.configX"
- echo "CONFIG_APPS_DIR=\"$appdir\"" >> "${TOPDIR}/.configX"
+ sed -i -e "/^CONFIG_APPS_DIR/d" "${tmp_config}"
+ echo "" >> "${tmp_config}"
+ echo "# Application configuration" >> "${tmp_config}"
+ echo "" >> "${tmp_config}"
+ if [ "X${winnative}" = "Xy" ]; then
+ echo "CONFIG_APPS_DIR=\"$winappdir\"" >> "${tmp_config}"
+ else
+ echo "CONFIG_APPS_DIR=\"$posappdir\"" >> "${tmp_config}"
+ fi
fi
# Copy appconfig file. The appconfig file will be copied to ${appdir}/.config
@@ -195,7 +228,7 @@ if [ ! -z "${appdir}" -a "X${newconfig}" != "Xy" ]; then
if [ ! -r "${configpath}/appconfig" ]; then
echo "NOTE: No readable appconfig file found in ${configpath}"
else
- install -C "${configpath}/appconfig" "${TOPDIR}/${appdir}/.config" || \
+ install "${configpath}/appconfig" "${TOPDIR}/${posappdir}/.config" || \
{ echo "Failed to copy ${configpath}/appconfig" ; exit 10 ; }
fi
fi
@@ -203,6 +236,5 @@ fi
# install the final .configX only if it differs from any existing
# .config file.
-install -C "${TOPDIR}/.configX" "${TOPDIR}/.config"
-rm -f "${TOPDIR}/.configX"
-
+install "${tmp_config}" "${dest_config}"
+rm -f "${tmp_config}"
diff --git a/nuttx/tools/copydir.bat b/nuttx/tools/copydir.bat
new file mode 100755
index 000000000..2857c415f
--- /dev/null
+++ b/nuttx/tools/copydir.bat
@@ -0,0 +1,102 @@
+@echo off
+
+rem tools/copydir.bat
+rem
+rem Copyright (C) 2012 Gregory Nutt. All rights reserved.
+rem Author: Gregory Nutt <gnutt@nuttx.org>
+rem
+rem Redistribution and use in source and binary forms, with or without
+rem modification, are permitted provided that the following conditions
+rem are met:
+rem
+rem 1. Redistributions of source code must retain the above copyright
+rem notice, this list of conditions and the following disclaimer.
+rem 2. Redistributions in binary form must reproduce the above copyright
+rem notice, this list of conditions and the following disclaimer in
+rem the documentation and/or other materials provided with the
+rem distribution.
+rem 3. Neither the name NuttX nor the names of its contributors may be
+rem used to endorse or promote products derived from this software
+rem without specific prior written permission.
+rem
+rem THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+rem "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+rem LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+rem FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+rem COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+rem INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+rem BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+rem OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+rem AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+rem LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+rem ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+rem POSSIBILITY OF SUCH DAMAGE.
+rem
+
+rem
+rem NuttX uses symbolic links to configure platform-specific directories into
+rem the build system. This works great except for when a Windows native
+rem toolchain is used in a Cygwin environment. In that case, symbolic
+rem links do not work correctly when accessed from the Windows native toolchain;
+rem rather, just look link files with the extension .lnk
+rem
+rem In this environment, the build system will work around this using this script
+rem as a replacement for the 'ln' command. This scrpt will simply copy the
+rem directory into the expected positiion.
+rem
+
+set src=%1
+set dest=%2
+
+rem Verify that arguments were provided
+
+if "%src%"=="" goto :MissingSrc
+if "%dest%"=="" goto :MissingDest
+goto CheckSrc
+
+:MissingSrc
+
+echo Missing ^<src^> and ^<dest^> arguments
+goto :ShowUsage
+
+:MissingDest
+
+echo Missing ^<dest^> arguments
+goto :ShowUsage
+
+rem Verify that a directory exists at the source path
+
+:CheckSrc
+
+if exist %src% goto :CheckDest
+
+echo No directory at %src%
+goto :ShowUsage
+
+:CheckDest
+
+rem If something already exists at the destination path, remove it
+
+if not exist %dest% goto :CopyDir
+
+rmdir /q /s %dest%
+if errorlevel 1 (
+ echo Failed to remove existing object at %dest%
+ goto :ShowUsage
+)
+
+rem Copy the directory
+
+:CopyDir
+
+xcopy %src% %dest% /c /q /s /e /y /i
+echo FAKELNK > %dest%\.fakelnk
+goto :End
+
+:ShowUsage
+echo USAGE: %0 ^<src^> ^<dest^>
+echo Where:
+echo ^<src^> is the source directory to be copied
+echo ^<dest^> is the destination directory to be created
+
+:End
diff --git a/nuttx/tools/winlink.sh b/nuttx/tools/copydir.sh
index f79eda2bd..5d9f79002 100755
--- a/nuttx/tools/winlink.sh
+++ b/nuttx/tools/copydir.sh
@@ -1,6 +1,6 @@
#!/bin/bash
############################################################################
-# tools/winlink.sh
+# tools/copydir.sh
#
# Copyright (C) 2008 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
diff --git a/nuttx/tools/define.bat b/nuttx/tools/define.bat
new file mode 100644
index 000000000..13d29ac31
--- /dev/null
+++ b/nuttx/tools/define.bat
@@ -0,0 +1,178 @@
+@echo off
+
+rem tools/define.bat
+rem
+rem Copyright (C) 2012 Gregory Nutt. All rights reserved.
+rem Author: Gregory Nutt <gnutt@nuttx.org>
+rem
+rem Redistribution and use in source and binary forms, with or without
+rem modification, are permitted provided that the following conditions
+rem are met:
+rem
+rem 1. Redistributions of source code must retain the above copyright
+rem notice, this list of conditions and the following disclaimer.
+rem 2. Redistributions in binary form must reproduce the above copyright
+rem notice, this list of conditions and the following disclaimer in
+rem the documentation and/or other materials provided with the
+rem distribution.
+rem 3. Neither the name NuttX nor the names of its contributors may be
+rem used to endorse or promote products derived from this software
+rem without specific prior written permission.
+rem
+rem THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+rem "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+rem LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+rem FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+rem COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+rem INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+rem BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+rem OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+rem AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+rem LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+rem ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+rem POSSIBILITY OF SUCH DAMAGE.
+
+rem Handle command line options
+rem [-h] <compiler-path> <def1> [-val <val1>] [<def2> [-val <val2>] [<def3> [-val <val3>] ...]]
+rem [-w] [-d] ignored for compatibility with define.sh
+
+set progname=%0
+
+:ArgLoop
+if "%1"=="-d" goto :NextArg
+if "%1"=="-w" goto :NextArg
+if "%1"=="-h" goto :ShowUsage
+
+goto :CheckCompilerPath
+
+:NextArg
+shift
+goto :ArgLoop
+
+:CheckCompilerPath
+
+if "%1"=="" (
+ echo Missing compiler path
+ goto :ShowUsage
+)
+
+set ccpath=%1
+shift
+
+set compiler=
+for /F %%i in ("%ccpath%") do set compiler=%%~ni
+
+if "%1"=="" (
+ echo Missing definition list
+ goto :ShowUsage
+)
+
+rem Check for some well known, non-GCC Windows native tools that require
+rem a special output format as well as special paths
+
+:GetFormat
+set fmt=std
+if "%compiler%"=="ez8cc" goto :SetZdsFormt
+if "%compiler%"=="zneocc" goto :SetZdsFormt
+if "%compiler%"=="ez80cc" goto :SetZdsFormt
+goto :ProcessDefinitions
+
+:SetZdsFormt
+set fmt=zds
+
+rem Now process each directory in the directory list
+
+:ProcessDefinitions
+set response=
+
+:DefinitionLoop
+if "%1"=="" goto :Done
+
+set varname=%1
+shift
+
+rem Handle the output depending on if there is a value for the variable or not
+
+if "%1"=="-val" goto :GetValue
+
+rem Handle the output using the selected format
+
+:NoValue
+if "%fmt%"=="zds" goto :NoValueZDS
+
+:NoValueStandard
+rem Treat the first definition differently
+
+if "%response%"=="" (
+ set response=-D%varname%
+ goto :DefinitionLoop
+)
+
+set response=%response% -D%varname%
+goto :DefinitionLoop
+
+:NoValueZDS
+rem Treat the first definition differently
+
+if "%response%"=="" (
+ set response=-define:%varname%
+ goto :DefinitionLoop
+)
+
+set response=%response% -define:%varname%
+goto :DefinitionLoop
+
+rem Get value following the variable name
+
+:GetValue
+shift
+set varvalue=%1
+shift
+
+rem Handle the output using the selected format
+
+if "%fmt%"=="zds" goto :ValueZDS
+
+:ValueStandard
+rem Treat the first definition differently
+
+if "%response%"=="" (
+ set response=-D%varname%=%varvalue%
+ goto :DefinitionLoop
+)
+
+set response=%response% -D%varname%=%varvalue%
+goto :DefinitionLoop
+
+:ValueZds
+rem Treat the first definition differently
+
+if "%response%"=="" (
+ set response=-define:%varname%=%varvalue%
+ goto :DefinitionLoop
+)
+
+set response=%response% -define:%varname%=%varvalue%
+goto :DefinitionLoop
+
+:Done
+echo %response%
+goto :End
+
+:ShowUsage
+echo %progname% is a tool for flexible generation of command line pre-processor
+echo definitions arguments for a variety of diffent ccpaths in a variety of
+echo compilation environments"
+echo USAGE:%progname% [-h] ^<compiler-path^> [-val ^<^val1^>] [^<def2^> [-val ^<val2^>] [^<def3^> [-val ^<val3^>] ...]]
+echo Where:"
+echo ^<compiler-path^>
+echo The full path to your ccpath
+echo ^<def1^> ^<def2^> ^<def3^> ...
+echo A list of pre-preprocesser variable names to be defined.
+echo [-val ^<val1^>] [-val ^<val2^>] [-val ^<val3^>] ...
+echo optional values to be assigned to each pre-processor variable.
+echo If not supplied, the variable will be defined with no explicit value.
+echo -h
+echo Show this text and exit
+
+:End
diff --git a/nuttx/tools/define.sh b/nuttx/tools/define.sh
index c53cb92a8..dc982cc64 100755
--- a/nuttx/tools/define.sh
+++ b/nuttx/tools/define.sh
@@ -1,7 +1,7 @@
#!/bin/bash
# tools/define.sh
#
-# Copyright (C) 2011 Gregory Nutt. All rights reserved.
+# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
@@ -38,7 +38,7 @@
progname=$0
wintool=n
-usage="USAGE: $progname [-w] [-d] [-l] [-h] <compiler-path> <def1>[=val1] [<def2>[=val2] [<def3>[=val3] ...]]"
+usage="USAGE: $progname [-w] [-d] [-h] <compiler-path> <def1>[=val1] [<def2>[=val2] [<def3>[=val3] ...]]"
advice="Try '$progname -h' for more information"
while [ ! -z "$1" ]; do
@@ -60,7 +60,7 @@ while [ ! -z "$1" ]; do
echo " <compiler-path>"
echo " The full path to your compiler"
echo " <def1> <def2> [<def3> ..."
- echo " A list of pre-preprocesser variable names to be defind."
+ echo " A list of pre-preprocesser variable names to be defined."
echo " [=val1] [=val2] [=val3]"
echo " optional values to be assigned to each pre-processor variable."
echo " If not supplied, the variable will be defined with no explicit value."
@@ -164,7 +164,7 @@ else
fmt=std
fi
-# Now process each directory in the directory list
+# Now process each definition in the definition list
unset response
for vardef in $varlist; do
diff --git a/nuttx/tools/incdir.bat b/nuttx/tools/incdir.bat
new file mode 100755
index 000000000..f7383fc9a
--- /dev/null
+++ b/nuttx/tools/incdir.bat
@@ -0,0 +1,165 @@
+@echo off
+
+rem tools/incdir.sh
+rem
+rem Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved.
+rem Author: Gregory Nutt <gnutt@nuttx.org>
+rem
+rem Redistribution and use in source and binary forms, with or without
+rem modification, are permitted provided that the following conditions
+rem are met:
+rem
+rem 1. Redistributions of source code must retain the above copyright
+rem notice, this list of conditions and the following disclaimer.
+rem 2. Redistributions in binary form must reproduce the above copyright
+rem notice, this list of conditions and the following disclaimer in
+rem the documentation and/or other materials provided with the
+rem distribution.
+rem 3. Neither the name NuttX nor the names of its contributors may be
+rem used to endorse or promote products derived from this software
+rem without specific prior written permission.
+rem
+rem THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+rem "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+rem LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+rem FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+rem COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+rem INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+rem BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+rem OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+rem AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+rem LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+rem ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+rem POSSIBILITY OF SUCH DAMAGE.
+rem
+
+rem Handle command line options
+
+set progname=%0
+set pathtype=user
+
+:ArgLoop
+
+rem [-d] [-w] [-s] [-h]. [-w] and [-d] Ignored for compatibility with incdir.sh
+
+if "%1"=="-d" goto :NextArg
+if "%1"=="-w" goto :NextArg
+if "%1"=="-h" goto :Usage
+
+if "%1"=="-s" (
+ set pathtype=system
+ goto :NextArg
+)
+
+goto :CheckCompiler
+
+:NextArg
+shift
+goto :ArgLoop
+
+:CheckCompiler
+if "%1"=="" (
+ echo ERROR: Missing compiler name
+ goto :Usage
+)
+
+set ccpath=%1
+shift
+
+set compiler=
+for /F %%i in ("%ccpath%") do set compiler=%%~ni
+
+if "%1"=="" (
+ echo ERROR: Missing directory paths
+ goto :Usage
+)
+
+rem Check for some well known, non-GCC Windows native tools that require
+rem a special output format as well as special paths
+
+:GetFormat
+set fmt=std
+if "%compiler%"=="ez8cc" goto :SetZdsFormt
+if "%compiler%"=="zneocc" goto :SetZdsFormt
+if "%compiler%"=="ez80cc" goto :SetZdsFormt
+goto :GeneratePaths
+
+:SetZdsFormt
+set fmt=zds
+
+rem Generate the compiler include path directives.
+
+:GeneratePaths
+set response=
+
+:DirLoop
+if "%1" == "" (
+ echo %response%
+ goto :End
+)
+
+if not exist %1 (
+ echo ERROR: Path %1 does not exist
+ goto :Usage
+)
+
+if "%fmt%"=="zds" goto :GenerateZdsPath
+if "%response%"=="" goto :FirstStdPath
+if "%pathtype%"=="system" goto :NextStdSystemPath
+
+set response=%response% -I "%1"
+goto :EndOfDirLoop
+
+:NextStdSystemPath
+
+set response=%response% -isystem "%1"
+goto :EndOfDirLoop
+
+:FirstStdPath
+
+if "%pathtype%"=="system" goto :FirstStdSystemPath
+set response=-I "%1"
+goto :EndOfDirLoop
+
+:FirstStdSystemPath
+
+set response=-isystem "%1"
+goto :EndOfDirLoop
+
+:GenerateZdsPath
+
+if "%response%"=="" goto :FirstZdsPath
+set response=%response%;%1
+goto :EndOfDirLoop
+
+:FirstZdsPath
+
+if "%pathtype%"=="system" goto :FirstZdsSystemPath
+set response=-usrinc:%1
+goto :EndOfDirLoop
+
+:FirstZdsSystemPath
+
+set response=-stdinc:%1
+
+:EndOfDirLoop
+shift
+goto :DirLoop
+
+:Usage
+echo %progname% is a tool for flexible generation of include path arguments for a
+echo variety of different compilers in a variety of compilation environments
+echo USAGE: %progname% [-w] [-d] [-s] [-h] ^<compiler-path^> ^<dir1^> [^<dir2^> [^<dir3^> ...]]
+echo Where:
+echo ^<compiler-path^>
+echo The full path to your compiler
+echo ^<dir1^> [^<dir2^> [^<dir3^> ...]]
+echo A list of include directories
+echo -w, -d
+echo For compatibility with incdir.sh (ignored)
+echo -s
+echo Generate standard, system header file paths instead of normal user
+echo header file paths.
+echo -h
+echo Shows this help text and exits.
+:End
diff --git a/nuttx/tools/incdir.sh b/nuttx/tools/incdir.sh
index be6a1d07a..145bfe9bb 100755
--- a/nuttx/tools/incdir.sh
+++ b/nuttx/tools/incdir.sh
@@ -36,6 +36,7 @@
progname=$0
wintool=n
+pathtype=user
usage="USAGE: $progname [-w] [-d] [-h] <compiler-path> <dir1> [<dir2> [<dir3> ...]]"
advice="Try '$progname -h' for more information"
@@ -47,6 +48,9 @@ while [ ! -z "$1" ]; do
-w )
wintool=y
;;
+ -s )
+ pathtype=system
+ ;;
-h )
echo "$progname is a tool for flexible generation of include path arguments for a"
echo "variety of different compilers in a variety of compilation environments"
@@ -61,8 +65,14 @@ while [ ! -z "$1" ]; do
echo " -w"
echo " The compiler is a Windows native tool and requires Windows"
echo " style pathnames like C:\\Program Files"
+ echo " -s"
+ echo " Generate standard, system header file paths instead of normal user"
+ echo " header file paths."
echo " -d"
echo " Enable script debug"
+ echo " -h"
+ echo " Shows this help text and exits."
+ exit 0
;;
* )
break;
@@ -155,11 +165,27 @@ exefile=`basename "$compiler"`
# a special output format as well as special paths
if [ "X$exefile" = "Xez8cc.exe" -o "X$exefile" = "Xzneocc.exe" -o "X$exefile" = "Xez80cc.exe" ]; then
- fmt=userinc
+ fmt=zds
else
fmt=std
fi
+# Select system or user header file path command line option
+
+if [ "X$fmt" = "Xzds" ]; then
+ if [ "X$pathtype" = "Xsystem" ]; then
+ cmdarg=-stdinc:
+ else
+ cmdarg=-usrinc:
+ fi
+else
+ if [ "X$pathtype" = "Xsystem" ]; then
+ cmdarg=-isystem
+ else
+ cmdarg=-I
+ fi
+fi
+
# Now process each directory in the directory list
unset response
@@ -183,26 +209,26 @@ for dir in $dirlist; do
# Handle the output using the selected format
- if [ "X$fmt" = "Xuserinc" ]; then
+ if [ "X$fmt" = "Xzds" ]; then
# Treat the first directory differently
if [ -z "$response" ]; then
- response="-usrinc:'"$path
+ response="${cmdarg}'"${path}
else
- response=$response":$path"
+ response=${response}";${path}"
fi
else
# Treat the first directory differently
if [ -z "$response" ]; then
- response=-I\"$path\"
+ response="${cmdarg} \"$path\""
else
- response=$response" -I\"$path\""
+ response="${response} ${cmdarg} \"$path\""
fi
fi
done
-if [ "X$fmt" = "Xuserinc" ]; then
+if [ "X$fmt" = "Xzds" ]; then
response=$response"'"
fi
diff --git a/nuttx/tools/link.bat b/nuttx/tools/link.bat
new file mode 100755
index 000000000..434574ee3
--- /dev/null
+++ b/nuttx/tools/link.bat
@@ -0,0 +1,89 @@
+@echo off
+
+rem tools/link.bat
+rem
+rem Copyright (C) 2012 Gregory Nutt. All rights reserved.
+rem Author: Gregory Nutt <gnutt@nuttx.org>
+rem
+rem Redistribution and use in source and binary forms, with or without
+rem modification, are permitted provided that the following conditions
+rem are met:
+rem
+rem 1. Redistributions of source code must retain the above copyright
+rem notice, this list of conditions and the following disclaimer.
+rem 2. Redistributions in binary form must reproduce the above copyright
+rem notice, this list of conditions and the following disclaimer in
+rem the documentation and/or other materials provided with the
+rem distribution.
+rem 3. Neither the name NuttX nor the names of its contributors may be
+rem used to endorse or promote products derived from this software
+rem without specific prior written permission.
+rem
+rem THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+rem "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+rem LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+rem FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+rem COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+rem INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+rem BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+rem OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+rem AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+rem LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+rem ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+rem POSSIBILITY OF SUCH DAMAGE.
+rem
+
+set src=%1
+set link=%2
+
+rem Verify that arguments were provided
+
+if "%src%"=="" goto :MissingSrc
+if "%link%"=="" goto :MissingLink
+goto CheckSrc
+
+:MissingSrc
+
+echo Missing ^<src^> and ^<link^> arguments
+goto :ShowUsage
+
+:MissingLink
+
+echo Missing ^<link^> arguments
+goto :ShowUsage
+
+rem Verify that a directory exists at the source path
+
+:CheckSrc
+
+if exist %src% goto :CheckLink
+
+echo No directory at %src%
+goto :ShowUsage
+
+:CheckLink
+
+rem If something already exists at the destination path, remove it
+
+if not exist %link% goto :MkLink
+
+rmdir /q /s %link%
+if errorlevel 1 (
+ echo Failed to remove existing object at %link%
+ goto :ShowUsage
+)
+
+rem Copy the directory
+
+:MkLink
+
+/user:administrator mklink /d %src% %link%
+goto :End
+
+:ShowUsage
+echo USAGE: %0 ^<src^> ^<link^>
+echo Where:
+echo ^<src^> is the source directory to be linked
+echo ^<link^> is the link to be created
+
+:End
diff --git a/nuttx/tools/mkconfig.c b/nuttx/tools/mkconfig.c
index 2d2fff5c5..3e55f5097 100644
--- a/nuttx/tools/mkconfig.c
+++ b/nuttx/tools/mkconfig.c
@@ -116,7 +116,7 @@ int main(int argc, char **argv, char **envp)
printf(" * configured (at present, NXFLAT is the only supported binary.\n");
printf(" * format).\n");
printf(" */\n\n");
- printf("#if !defined(CONFIG_NXFLAT)\n");
+ printf("#if !defined(CONFIG_NXFLAT) && !defined(CONFIG_ELF)\n");
printf("# undef CONFIG_BINFMT_DISABLE\n");
printf("# define CONFIG_BINFMT_DISABLE 1\n");
printf("#endif\n\n");
diff --git a/nuttx/tools/mkdeps.bat b/nuttx/tools/mkdeps.bat
new file mode 100644
index 000000000..23aab0b71
--- /dev/null
+++ b/nuttx/tools/mkdeps.bat
@@ -0,0 +1,173 @@
+@echo off
+
+rem tools/mkdeps.sh
+rem
+rem Copyright (C) 2012 Gregory Nutt. All rights reserved.
+rem Author: Gregory Nutt <gnutt@nuttx.org>
+rem
+rem Redistribution and use in source and binary forms, with or without
+rem modification, are permitted provided that the following conditions
+rem are met:
+rem
+rem 1. Redistributions of source code must retain the above copyright
+rem notice, this list of conditions and the following disclaimer.
+rem 2. Redistributions in binary form must reproduce the above copyright
+rem notice, this list of conditions and the following disclaimer in
+rem the documentation and/or other materials provided with the
+rem distribution.
+rem 3. Neither the name NuttX nor the names of its contributors may be
+rem used to endorse or promote products derived from this software
+rem without specific prior written permission.
+rem
+rem THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+rem "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+rem LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+rem FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+rem COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+rem INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+rem BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+rem OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+rem AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+rem LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+rem ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+rem POSSIBILITY OF SUCH DAMAGE.
+
+rem Accumulate CFLAGS up to "--"
+
+set cc=
+set cflags=
+set altpath=
+set files=
+set args=
+set debug=n
+
+:Loop
+if "%1"=="" goto Continue
+
+if "%1"=="--" (
+ set cc=%cflags%
+ set cflags=%args%
+ set args=
+ goto NextParm
+)
+
+if "%1"=="--dep-path" (
+ if "%args%"=="" (
+ set altpath=%altpath% %2
+ ) else (
+ set args=%args% %2
+ )
+ shift
+ goto NextParm
+)
+
+if "%1"=="--dep-debug" (
+rem @echo on
+ set debug=y
+ goto NextParm
+)
+
+if "%1"=="--help" goto Usage
+
+if "%args%"=="" (
+ set args=%1
+) else (
+ set args=%args% %1
+)
+
+:NextParm
+shift
+goto Loop
+:Continue
+
+set files=%args%
+
+if "%debug%"=="y" (
+ echo cc=%cc%
+ echo cflags=%cflags%
+ echo files=%files%
+ echo altpath=%altpath%
+)
+
+rem Now check if we have everything
+
+if "%cc%"=="" (
+ echo ERROR: No compiler specified
+ goto Usage
+)
+
+if "%files%"=="" (
+ rem Don't report an error -- this happens normally in some configurations
+ echo # No files specified for dependency generataion
+ goto End
+)
+
+rem Then get the dependencies for each file
+
+if "%altpath%"=="" goto NoPaths
+for %%G in (%files%) do (
+ set fullpath=
+ set file=%%G
+ call :Checkpaths
+ if "%debug%"=="y" echo %file%: fullpath=%fullpath%
+ if "%fullpath%"=="" goto :NoFile
+ if "%debug%"=="y" echo CMD: %cc% -M %cflags% %fullpath%
+ %cc% -M %cflags% %fullpath% || goto DepFail
+)
+goto :End
+
+:NoPaths
+for %%G in (%files%) do (
+ set fullpath=
+ set file=%%G
+ call :CheckFile %%G
+)
+goto :End
+
+:CheckFile
+if "%debug%"=="y" echo Checkfile: Checking %file%
+if not exist %file% goto :NoFile
+set fullpath=%file%
+ if "%debug%"=="y" echo CMD: %cc% -M %cflags% %fullpath%
+%cc% -M %cflags% %fullpath% || goto DepFail
+goto :EOF
+
+:CheckPaths
+for %%H in (%altpath%) do (
+ set tmppath=%%H\%file%
+ if "%debug%"=="y" echo Checkfile: Checking %tmppath%
+ if exist %tmppath% (
+ set fullpath=%tmppath%
+ goto :EOF
+ )
+)
+goto :EOF
+
+:NoFile
+echo ERROR: No readable file at %file%
+goto Usage
+
+:DepFail
+echo ERROR: Failed to created dependencies for %file%
+
+:Usage
+echo Usage: mkdeps [OPTIONS] CC -- CFLAGS -- file [file [file...]]
+echo Where:
+echo CC
+echo A variable number of arguments that define how to execute the compiler
+echo CFLAGS
+echo The compiler compilation flags
+echo file
+echo One or more C files whose dependencies will be checked. Each file is expected
+echo to reside in the current directory unless --dep-path is provided on the command line
+echo And [OPTIONS] include:
+echo --dep-debug
+echo Enable script debug
+echo --dep-path ^<path^>
+echo Do not look in the current directory for the file. Instead, look in <path> to see
+echo if the file resides there. --dep-path may be used multiple times to specify
+echo multiple alternative location
+echo --help
+echo Shows this message and exits
+
+:End
diff --git a/nuttx/tools/mkdeps.c b/nuttx/tools/mkdeps.c
new file mode 100644
index 000000000..64d81cbd7
--- /dev/null
+++ b/nuttx/tools/mkdeps.c
@@ -0,0 +1,721 @@
+/****************************************************************************
+ * tools/mkdeps.c
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/stat.h>
+
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <limits.h>
+#include <ctype.h>
+#include <errno.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define MAX_BUFFER (4096)
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+enum slashmode_e
+{
+ MODE_FSLASH = 0,
+ MODE_BSLASH = 1,
+ MODE_DBLBACK = 2
+};
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static char *g_cc = NULL;
+static char *g_cflags = NULL;
+static char *g_files = NULL;
+static char *g_altpath = NULL;
+static int g_debug = 0;
+static bool g_winnative = false;
+#ifdef HAVE_WINPATH
+static bool g_winpath = false;
+static char *g_topdir = NULL;
+#endif
+
+static char g_command[MAX_BUFFER];
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+ /* MinGW does not seem to provide strtok_r */
+
+#ifndef HAVE_STRTOK_R
+static char *MY_strtok_r(char *str, const char *delim, char **saveptr)
+{
+ char *pbegin;
+ char *pend = NULL;
+
+ /* Decide if we are starting a new string or continuing from
+ * the point we left off.
+ */
+
+ if (str)
+ {
+ pbegin = str;
+ }
+ else if (saveptr && *saveptr)
+ {
+ pbegin = *saveptr;
+ }
+ else
+ {
+ return NULL;
+ }
+
+ /* Find the beginning of the next token */
+
+ for (;
+ *pbegin && strchr(delim, *pbegin) != NULL;
+ pbegin++);
+
+ /* If we are at the end of the string with nothing
+ * but delimiters found, then return NULL.
+ */
+
+ if (!*pbegin)
+ {
+ return NULL;
+ }
+
+ /* Find the end of the token */
+
+ for (pend = pbegin + 1;
+ *pend && strchr(delim, *pend) == NULL;
+ pend++);
+
+ /* pend either points to the end of the string or to
+ * the first delimiter after the string.
+ */
+
+ if (*pend)
+ {
+ /* Turn the delimiter into a null terminator */
+
+ *pend++ = '\0';
+ }
+
+ /* Save the pointer where we left off and return the
+ * beginning of the token.
+ */
+
+ if (saveptr)
+ {
+ *saveptr = pend;
+ }
+ return pbegin;
+}
+
+#define strtok_r MY_strtok_r
+#endif
+
+static void append(char **base, char *str)
+{
+ char *oldbase;
+ char *newbase;
+ int alloclen;
+
+ oldbase = *base;
+ if (!oldbase)
+ {
+ newbase = strdup(str);
+ if (!newbase)
+ {
+ fprintf(stderr, "ERROR: Failed to strdup %s\n", str);
+ exit(EXIT_FAILURE);
+ }
+ }
+ else
+ {
+ alloclen = strlen(oldbase) + strlen(str) + 2;
+ newbase = (char *)malloc(alloclen);
+ if (!newbase)
+ {
+ fprintf(stderr, "ERROR: Failed to allocate %d bytes\n", alloclen);
+ exit(EXIT_FAILURE);
+ }
+
+ snprintf(newbase, alloclen, "%s %s\n", oldbase, str);
+ free(oldbase);
+ }
+
+ *base = newbase;
+}
+
+static void show_usage(const char *progname, const char *msg, int exitcode)
+{
+ if (msg)
+ {
+ fprintf(stderr, "\n");
+ fprintf(stderr, "%s:\n", msg);
+ }
+
+ fprintf(stderr, "\n");
+ fprintf(stderr, "%s [OPTIONS] CC -- CFLAGS -- file [file [file...]]\n",
+ progname);
+ fprintf(stderr, "\n");
+ fprintf(stderr, "Where:\n");
+ fprintf(stderr, " CC\n");
+ fprintf(stderr, " A variable number of arguments that define how to execute the compiler\n");
+ fprintf(stderr, " CFLAGS\n");
+ fprintf(stderr, " The compiler compilation flags\n");
+ fprintf(stderr, " file\n");
+ fprintf(stderr, " One or more C files whose dependencies will be checked. Each file is expected\n");
+ fprintf(stderr, " to reside in the current directory unless --dep-path is provided on the command line\n");
+ fprintf(stderr, "\n");
+ fprintf(stderr, "And [OPTIONS] include:\n");
+ fprintf(stderr, " --dep-debug\n");
+ fprintf(stderr, " Enable script debug\n");
+ fprintf(stderr, " --dep-path <path>\n");
+ fprintf(stderr, " Do not look in the current directory for the file. Instead, look in <path> to see\n");
+ fprintf(stderr, " if the file resides there. --dep-path may be used multiple times to specify\n");
+ fprintf(stderr, " multiple alternative location\n");
+ fprintf(stderr, " --winnative\n");
+ fprintf(stderr, " By default, a POSIX-style environment is assumed (e.g., Linux, Cygwin, etc.) This option is\n");
+ fprintf(stderr, " inform the tool that is working in a pure Windows native environment.\n");
+#ifdef HAVE_WINPATH
+ fprintf(stderr, " --winpaths <TOPDIR>\n");
+ fprintf(stderr, " This option is useful when using a Windows native toolchain in a POSIX environment (such\n");
+ fprintf(stderr, " such as Cygwin). In this case, will CC generates dependency lists using Windows paths\n");
+ fprintf(stderr, " (e.g., C:\\blablah\\blabla). This switch instructs the script to use 'cygpath' to convert\n");
+ fprintf(stderr, " the Windows paths to Cygwin POSIXE paths.\n");
+#endif
+ fprintf(stderr, " --help\n");
+ fprintf(stderr, " Shows this message and exits\n");
+ exit(exitcode);
+}
+
+static void parse_args(int argc, char **argv)
+{
+ char *args = NULL;
+ int argidx;
+
+ /* Accumulate CFLAGS up to "--" */
+
+ for (argidx = 1; argidx < argc; argidx++)
+ {
+ if (strcmp(argv[argidx], "--") == 0)
+ {
+ g_cc = g_cflags;
+ g_cflags = args;
+ args = NULL;
+ }
+ else if (strcmp(argv[argidx], "--dep-debug") == 0)
+ {
+ g_debug++;
+ }
+ else if (strcmp(argv[argidx], "--dep-path") == 0)
+ {
+ argidx++;
+ if (argidx >= argc)
+ {
+ show_usage(argv[0], "ERROR: Missing argument to --dep-path", EXIT_FAILURE);
+ }
+
+ if (args)
+ {
+ append(&args, argv[argidx]);
+ }
+ else
+ {
+ append(&g_altpath, argv[argidx]);
+ }
+ }
+ else if (strcmp(argv[argidx], "--winnative") == 0)
+ {
+ g_winnative = true;
+ }
+#ifdef HAVE_WINPATH
+ else if (strcmp(argv[argidx], "--winpath") == 0)
+ {
+ g_winpath = true;
+ if (g_topdir)
+ {
+ free(g_topdir);
+ }
+
+ argidx++;
+ if (argidx >= argc)
+ {
+ show_usage(argv[0], "ERROR: Missing argument to --winpath", EXIT_FAILURE);
+ }
+
+ g_topdir = strdup(argv[argidx]);
+ }
+#endif
+ else if (strcmp(argv[argidx], "--help") == 0)
+ {
+ show_usage(argv[0], NULL, EXIT_SUCCESS);
+ }
+ else
+ {
+ append(&args, argv[argidx]);
+ }
+ }
+
+ /* The final thing accumulated is the list of files */
+
+ g_files = args;
+
+ /* If no paths were specified, then look in the current directory only */
+
+ if (!g_altpath)
+ {
+ g_altpath = strdup(".");
+ }
+
+ if (g_debug)
+ {
+ fprintf(stderr, "SELECTIONS\n");
+ fprintf(stderr, " CC : [%s]\n", g_cc ? g_cc : "(None)");
+ fprintf(stderr, " CFLAGS : [%s]\n", g_cflags ? g_cflags : "(None)");
+ fprintf(stderr, " FILES : [%s]\n", g_files ? g_files : "(None)");
+ fprintf(stderr, " PATHS : [%s]\n", g_altpath ? g_altpath : "(None)");
+#ifdef HAVE_WINPATH
+ fprintf(stderr, " Windows Paths : [%s]\n", g_winpath ? "TRUE" : "FALSE");
+ if (g_winpath)
+ {
+ fprintf(stderr, " TOPDIR : [%s]\n", g_topdir);
+ }
+#endif
+ fprintf(stderr, " Windows Native : [%s]\n", g_winnative ? "TRUE" : "FALSE");
+ }
+
+ /* Check for required paramters */
+
+ if (!g_cc)
+ {
+ show_usage(argv[0], "ERROR: No compiler specified", EXIT_FAILURE);
+ }
+
+ if (!g_files)
+ {
+ /* Don't report an error -- this happens normally in some configurations */
+
+ printf("# No files specified for dependency generataion\n");
+ exit(EXIT_SUCCESS);
+ }
+
+#ifdef HAVE_WINPATH
+ if (g_winnative && g_winpath)
+ {
+ show_usage(argv[0], "ERROR: Both --winnative and --winpapth makes no sense", EXIT_FAILURE);
+ }
+#endif
+}
+
+static void do_dependency(const char *file, char separator)
+{
+ static const char moption[] = " -M ";
+ struct stat buf;
+ char *alloc;
+ char *altpath;
+ char *path;
+ char *lasts;
+ int cmdlen;
+ int pathlen;
+ int filelen;
+ int totallen;
+ int ret;
+
+ /* Copy the compiler into the command buffer */
+
+ cmdlen = strlen(g_cc);
+ if (cmdlen >= MAX_BUFFER)
+ {
+ fprintf(stderr, "ERROR: Compiler string is too long [%d/%d]: %s\n",
+ cmdlen, MAX_BUFFER, g_cc);
+ exit(EXIT_FAILURE);
+ }
+
+ strcpy(g_command, g_cc);
+
+ /* Copy " -M " */
+
+ cmdlen += strlen(moption);
+ if (cmdlen >= MAX_BUFFER)
+ {
+ fprintf(stderr, "ERROR: Option string is too long [%d/%d]: %s\n",
+ cmdlen, MAX_BUFFER, moption);
+ exit(EXIT_FAILURE);
+ }
+
+ strcat(g_command, moption);
+
+ /* Copy the CFLAGS into the command buffer */
+
+ cmdlen += strlen(g_cflags);
+ if (cmdlen >= MAX_BUFFER)
+ {
+ fprintf(stderr, "ERROR: CFLAG string is too long [%d/%d]: %s\n",
+ cmdlen, MAX_BUFFER, g_cflags);
+ exit(EXIT_FAILURE);
+ }
+
+ strcat(g_command, g_cflags);
+
+ /* Add a space */
+
+ g_command[cmdlen] = ' ';
+ cmdlen++;
+ g_command[cmdlen] = '\0';
+
+ /* Make a copy of g_altpath. We need to do this because at least the version
+ * of strtok_r above does modifie it.
+ */
+
+ alloc = strdup(g_altpath);
+ if (!alloc)
+ {
+ fprintf(stderr, "ERROR: Failed to strdup paths\n");
+ exit(EXIT_FAILURE);
+ }
+
+ altpath = alloc;
+
+ /* Try each path. This loop will continue until each path has been tried
+ * (failure) or until stat() finds the file
+ */
+
+ while ((path = strtok_r(altpath, " ", &lasts)) != NULL)
+ {
+ /* Create a full path to the file */
+
+ pathlen = strlen(path);
+ totallen = cmdlen + pathlen;
+ if (totallen >= MAX_BUFFER)
+ {
+ fprintf(stderr, "ERROR: Path is too long [%d/%d]: %s\n",
+ totallen, MAX_BUFFER, path);
+ exit(EXIT_FAILURE);
+ }
+
+ strcpy(&g_command[cmdlen], path);
+
+ if (g_command[totallen] != '\0')
+ {
+ fprintf(stderr, "ERROR: Missing NUL terminator\n");
+ exit(EXIT_FAILURE);
+ }
+
+ if (g_command[totallen-1] != separator)
+ {
+ g_command[totallen] = separator;
+ g_command[totallen+1] = '\0';
+ pathlen++;
+ totallen++;
+ }
+
+ filelen = strlen(file);
+ totallen += filelen;
+ if (totallen >= MAX_BUFFER)
+ {
+ fprintf(stderr, "ERROR: Path+file is too long [%d/%d]\n",
+ totallen, MAX_BUFFER);
+ exit(EXIT_FAILURE);
+ }
+
+ strcat(g_command, file);
+
+ /* Check that a file actually exists at this path */
+
+ if (g_debug)
+ {
+ fprintf(stderr, "Trying path=%s file=%s fullpath=%s\n",
+ path, file, &g_command[cmdlen]);
+ }
+
+ ret = stat(&g_command[cmdlen], &buf);
+ if (ret < 0)
+ {
+ altpath = NULL;
+ continue;
+ }
+
+ if (!S_ISREG(buf.st_mode))
+ {
+ fprintf(stderr, "ERROR: File %s exists but is not a regular file\n",
+ &g_command[cmdlen]);
+ exit(EXIT_FAILURE);
+ }
+
+ /* Okay.. we have. Create the dependency. One a failure to start the
+ * compiler, system() will return -1; Otherwise, the returned value
+ * from the compiler is in WEXITSTATUS(ret).
+ */
+
+ ret = system(g_command);
+#ifdef WEXITSTATUS
+ if (ret < 0 || WEXITSTATUS(ret) != 0)
+ {
+ if (ret < 0)
+ {
+ fprintf(stderr, "ERROR: system failed: %s\n", strerror(errno));
+ }
+ else
+ {
+ fprintf(stderr, "ERROR: %s failed: %d\n", g_cc, WEXITSTATUS(ret));
+ }
+
+ fprintf(stderr, " command: %s\n", g_command);
+ exit(EXIT_FAILURE);
+ }
+#else
+ if (ret < 0)
+ {
+ fprintf(stderr, "ERROR: system failed: %s\n", strerror(errno));
+ fprintf(stderr, " command: %s\n", g_command);
+ exit(EXIT_FAILURE);
+ }
+#endif
+
+ /* We don't really know that the command succeeded... Let's assume that it did */
+
+ free(alloc);
+ return;
+ }
+
+ printf("# ERROR: File \"%s\" not found at any location\n", file);
+ exit(EXIT_FAILURE);
+}
+
+/* Convert a Cygwin path to a Windows path */
+
+#ifdef HAVE_WINPATH
+static char *cywin2windows(const char *str, const char *append, enum slashmode_e mode)
+{
+ static const char cygdrive[] = "/cydrive";
+ const char *src = src;
+ char *dest;
+ char *newpath;
+ char *allocpath = NULL;
+ int srclen = strlen(str);
+ int alloclen = 0;
+ int drive = 0;
+ int lastchar;
+
+ /* Skip any leading whitespace */
+
+ while (isspace(*str)) str++;
+
+ /* Were we asked to append something? */
+
+ if (append)
+ {
+ char *tmp;
+
+ alloclen = sizeof(str) + sizeof(append) + 1;
+ allocpath = (char *)malloc(alloclen);
+ if (!allocpath)
+ {
+ fprintf(stderr, "ERROR: Failed to allocate %d bytes\n", alloclen);
+ exit(EXIT_FAILURE);
+ }
+
+ snprintf(allocpath, alloclen, "%s/%s", str, append);
+ }
+
+ /* Looking for path of the form /cygdrive/c/bla/bla/bla */
+
+ if (strcasecmp(src, cygdrive) == 0)
+ {
+ int cygsize = sizeof(cygdrive);
+ if (src[cygsize] == '/')
+ {
+ cygsize++;
+ srclen -= cygsize;
+ src += cygsize;
+
+ if (srclen <= 0)
+ {
+ fprintf(stderr, "ERROR: Unhandled path: \"%s\"\n", str);
+ exit(EXIT_FAILURE);
+ }
+
+ drive = toupper(*src);
+ if (drive < 'A' || drive > 'Z')
+ {
+ fprintf(stderr, "ERROR: Drive charager: \"%s\"\n", str);
+ exit(EXIT_FAILURE);
+ }
+
+ srclen--;
+ src++;
+ alloclen = 2;
+ }
+ }
+
+ /* Determine the size of the new path */
+
+ alloclen += sizeof(src) + 1;
+ if (mode == MODE_DBLBACK)
+ {
+ const char *tmpptr;
+ for (tmpptr = src; *tmpptr; tmpptr++)
+ {
+ if (*tmpptr == '/') alloclen++;
+ }
+ }
+
+ /* Allocate memory for the new path */
+
+ newpath = (char *)malloc(alloclen);
+ if (!newpath)
+ {
+ fprintf(stderr, "ERROR: Failed to allocate %d bytes\n", alloclen);
+ exit(EXIT_FAILURE);
+ }
+
+ dest = newpath;
+
+ /* Copy the drive character */
+
+ if (drive)
+ {
+ *dest++ = drive;
+ *dest++ = ':';
+ }
+
+ /* Copy each character from the source, making modifications for foward
+ * slashes as required.
+ */
+
+ lastchar = '\0';
+ for (; *src; src++)
+ {
+ if (mode != MODE_FSLASH && *src == '/')
+ {
+ if (lastchar != '/')
+ {
+ *dest++ = '\\';
+ if (mode == MODE_DBLBACK)
+ {
+ *dest++ = '\\';
+ }
+ }
+ }
+ else
+ {
+ *dest++ = *src;
+ }
+
+ lastchar = *src;
+ }
+
+ *dest++ = '\0';
+ if (allocpath)
+ {
+ free(allocpath);
+ }
+ return dest;
+}
+#endif
+
+#ifdef HAVE_WINPATH
+static void do_winpath(char *file)
+{
+ /* The file is in POSIX format. CC expects Windows format to generate the
+ * dependencies, but GNU make expect the resulting dependencies to be back
+ * in POSIX format. What a mess!
+ */
+
+ char *path = cywin2windows(g_topdir, file, MODE_FSLASH);
+
+ /* Then get the dependency and perform conversions on it to make it
+ * palatable to the Cygwin make.
+ */
+#warning "Missing logic"
+
+ free(path);
+}
+#endif
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+int main(int argc, char **argv, char **envp)
+{
+ char *lasts;
+ char *files;
+ char *file;
+
+ /* Parse command line parameters */
+
+ parse_args(argc, argv);
+
+ /* Then generate dependencies for each path on the command line. NOTE
+ * strtok_r will clobber the files list. But that is okay because we are
+ * only going to traverse it once.
+ */
+
+ files = g_files;
+ while ((file = strtok_r(files, " ", &lasts)) != NULL)
+ {
+ /* Check if we need to do path conversions for a Windows-natvie tool
+ * being using in a POSIX/Cygwin environment.
+ */
+
+#ifdef HAVE_WINPATH
+ if (g_winpath)
+ {
+ do_winpath(file);
+ }
+ else
+#endif
+ {
+ do_dependency(file, g_winnative ? '\\' : '/');
+ }
+
+ files = NULL;
+ }
+
+ return EXIT_SUCCESS;
+}
diff --git a/nuttx/tools/mkdeps.sh b/nuttx/tools/mkdeps.sh
index d8984e553..42397012b 100755
--- a/nuttx/tools/mkdeps.sh
+++ b/nuttx/tools/mkdeps.sh
@@ -2,7 +2,7 @@
############################################################################
# tools/mkdeps.sh
#
-# Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
+# Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
diff --git a/nuttx/tools/mkromfsimg.sh b/nuttx/tools/mkromfsimg.sh
index b77411980..8811f1953 100755
--- a/nuttx/tools/mkromfsimg.sh
+++ b/nuttx/tools/mkromfsimg.sh
@@ -233,7 +233,7 @@ mkdir -p $workingdir || { echo "Failed to created the new $workingdir"; exit 1;
# Create the rcS file from the rcS.template
if [ ! -r $rcstemplate ]; then
- echo "$rcstemplete does not exist"
+ echo "$rcstemplate does not exist"
rmdir $workingdir
exit 1
fi
diff --git a/nuttx/tools/mksymtab.c b/nuttx/tools/mksymtab.c
index c5a46a92b..e401812c0 100644
--- a/nuttx/tools/mksymtab.c
+++ b/nuttx/tools/mksymtab.c
@@ -222,7 +222,7 @@ int main(int argc, char **argv, char **envp)
fprintf(outstream, "/* %s: Auto-generated symbol table. Do not edit */\n\n", symtab);
fprintf(outstream, "#include <nuttx/config.h>\n");
- fprintf(outstream, "#include <nuttx/symtab.h>\n\n");
+ fprintf(outstream, "#include <nuttx/binfmt/symtab.h>\n\n");
/* Output all of the require header files */
diff --git a/nuttx/tools/unlink.bat b/nuttx/tools/unlink.bat
new file mode 100755
index 000000000..25e83bb9f
--- /dev/null
+++ b/nuttx/tools/unlink.bat
@@ -0,0 +1,71 @@
+@echo off
+
+rem tools/unlink.bat
+rem
+rem Copyright (C) 2012 Gregory Nutt. All rights reserved.
+rem Author: Gregory Nutt <gnutt@nuttx.org>
+rem
+rem Redistribution and use in source and binary forms, with or without
+rem modification, are permitted provided that the following conditions
+rem are met:
+rem
+rem 1. Redistributions of source code must retain the above copyright
+rem notice, this list of conditions and the following disclaimer.
+rem 2. Redistributions in binary form must reproduce the above copyright
+rem notice, this list of conditions and the following disclaimer in
+rem the documentation and/or other materials provided with the
+rem distribution.
+rem 3. Neither the name NuttX nor the names of its contributors may be
+rem used to endorse or promote products derived from this software
+rem without specific prior written permission.
+rem
+rem THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+rem "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+rem LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+rem FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+rem COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+rem INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+rem BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+rem OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+rem AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+rem LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+rem ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+rem POSSIBILITY OF SUCH DAMAGE.
+rem
+
+rem Verify that arguments were provided
+
+set link=%1
+if "%link%"=="" goto :MissingArgument
+
+rem Check if something already exists at the link path
+
+if exist "%link%" goto :LinkExists
+
+echo %link% does not exist
+goto :ShowUsage
+
+rem %link% make be a symbolic link or it may be a copied director (with
+rem a .fakelnk file in it). It really does not matter which: We do the
+rem same thing in either case
+
+:LinkExists
+
+rmdir /q /s %link%
+if errorlevel 1 (
+ echo Failed to remove existing object at %link%
+ goto :ShowUsage
+)
+
+goto :End
+
+:MissingArgument
+
+echo Missing Argument
+
+:ShowUsage
+echo USAGE: %0 ^<link^>
+echo Where:
+echo ^<link^> is the linked (or copied) directory to be removed
+
+:End