forked from Archive/PX4-Autopilot
Merge branch 'fmuv2_bringup' of github.com:cvg/Firmware_Private into fmuv2_bringup
This commit is contained in:
commit
61ad4ed5fd
|
@ -24,3 +24,4 @@ Firmware.sublime-workspace
|
||||||
Images/*.bin
|
Images/*.bin
|
||||||
Images/*.px4
|
Images/*.px4
|
||||||
mavlink/include/mavlink/v0.9/
|
mavlink/include/mavlink/v0.9/
|
||||||
|
NuttX
|
|
@ -27,7 +27,7 @@ define _perf_print
|
||||||
# PC_COUNT
|
# PC_COUNT
|
||||||
if $hdr->type == 0
|
if $hdr->type == 0
|
||||||
set $count = (struct perf_ctr_count *)$hdr
|
set $count = (struct perf_ctr_count *)$hdr
|
||||||
printf "%llu events,\n", $count->event_count;
|
printf "%llu events\n", $count->event_count
|
||||||
end
|
end
|
||||||
# PC_ELPASED
|
# PC_ELPASED
|
||||||
if $hdr->type == 1
|
if $hdr->type == 1
|
||||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,12 @@
|
||||||
|
{
|
||||||
|
"board_id": 10,
|
||||||
|
"magic": "PX4FWv2",
|
||||||
|
"description": "Firmware for the PX4IOv2 board",
|
||||||
|
"image": "",
|
||||||
|
"build_time": 0,
|
||||||
|
"summary": "PX4IOv2",
|
||||||
|
"version": "2.0",
|
||||||
|
"image_size": 0,
|
||||||
|
"git_identity": "",
|
||||||
|
"board_revision": 0
|
||||||
|
}
|
89
Makefile
89
Makefile
|
@ -100,7 +100,7 @@ all: $(STAGED_FIRMWARES)
|
||||||
# is taken care of.
|
# is taken care of.
|
||||||
#
|
#
|
||||||
$(STAGED_FIRMWARES): $(IMAGE_DIR)%.px4: $(BUILD_DIR)%.build/firmware.px4
|
$(STAGED_FIRMWARES): $(IMAGE_DIR)%.px4: $(BUILD_DIR)%.build/firmware.px4
|
||||||
@echo %% Copying $@
|
@$(ECHO) %% Copying $@
|
||||||
$(Q) $(COPY) $< $@
|
$(Q) $(COPY) $< $@
|
||||||
$(Q) $(COPY) $(patsubst %.px4,%.bin,$<) $(patsubst %.px4,%.bin,$@)
|
$(Q) $(COPY) $(patsubst %.px4,%.bin,$<) $(patsubst %.px4,%.bin,$@)
|
||||||
|
|
||||||
|
@ -111,9 +111,9 @@ $(STAGED_FIRMWARES): $(IMAGE_DIR)%.px4: $(BUILD_DIR)%.build/firmware.px4
|
||||||
$(BUILD_DIR)%.build/firmware.px4: config = $(patsubst $(BUILD_DIR)%.build/firmware.px4,%,$@)
|
$(BUILD_DIR)%.build/firmware.px4: config = $(patsubst $(BUILD_DIR)%.build/firmware.px4,%,$@)
|
||||||
$(BUILD_DIR)%.build/firmware.px4: work_dir = $(BUILD_DIR)$(config).build/
|
$(BUILD_DIR)%.build/firmware.px4: work_dir = $(BUILD_DIR)$(config).build/
|
||||||
$(FIRMWARES): $(BUILD_DIR)%.build/firmware.px4:
|
$(FIRMWARES): $(BUILD_DIR)%.build/firmware.px4:
|
||||||
@echo %%%%
|
@$(ECHO) %%%%
|
||||||
@echo %%%% Building $(config) in $(work_dir)
|
@$(ECHO) %%%% Building $(config) in $(work_dir)
|
||||||
@echo %%%%
|
@$(ECHO) %%%%
|
||||||
$(Q) mkdir -p $(work_dir)
|
$(Q) mkdir -p $(work_dir)
|
||||||
$(Q) make -r -C $(work_dir) \
|
$(Q) make -r -C $(work_dir) \
|
||||||
-f $(PX4_MK_DIR)firmware.mk \
|
-f $(PX4_MK_DIR)firmware.mk \
|
||||||
|
@ -132,8 +132,6 @@ $(FIRMWARES): $(BUILD_DIR)%.build/firmware.px4:
|
||||||
# XXX Should support fetching/unpacking from a separate directory to permit
|
# XXX Should support fetching/unpacking from a separate directory to permit
|
||||||
# downloads of the prebuilt archives as well...
|
# downloads of the prebuilt archives as well...
|
||||||
#
|
#
|
||||||
# XXX PX4IO configuration name is bad - NuttX configs should probably all be "px4"
|
|
||||||
#
|
|
||||||
NUTTX_ARCHIVES = $(foreach board,$(BOARDS),$(ARCHIVE_DIR)$(board).export)
|
NUTTX_ARCHIVES = $(foreach board,$(BOARDS),$(ARCHIVE_DIR)$(board).export)
|
||||||
.PHONY: archives
|
.PHONY: archives
|
||||||
archives: $(NUTTX_ARCHIVES)
|
archives: $(NUTTX_ARCHIVES)
|
||||||
|
@ -145,17 +143,23 @@ ifneq ($(filter archives,$(MAKECMDGOALS)),)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
$(ARCHIVE_DIR)%.export: board = $(notdir $(basename $@))
|
$(ARCHIVE_DIR)%.export: board = $(notdir $(basename $@))
|
||||||
$(ARCHIVE_DIR)%.export: configuration = $(if $(filter px4io px4iov2,$(board)),io,nsh)
|
$(ARCHIVE_DIR)%.export: configuration = nsh
|
||||||
$(NUTTX_ARCHIVES): $(ARCHIVE_DIR)%.export: $(NUTTX_SRC) $(NUTTX_APPS)
|
$(NUTTX_ARCHIVES): $(ARCHIVE_DIR)%.export: $(NUTTX_SRC)
|
||||||
@echo %% Configuring NuttX for $(board)/$(configuration)
|
@$(ECHO) %% Configuring NuttX for $(board)
|
||||||
$(Q) (cd $(NUTTX_SRC) && $(RMDIR) nuttx-export)
|
$(Q) (cd $(NUTTX_SRC) && $(RMDIR) nuttx-export)
|
||||||
$(Q) make -r -j1 -C $(NUTTX_SRC) -r $(MQUIET) distclean
|
$(Q) make -r -j1 -C $(NUTTX_SRC) -r $(MQUIET) distclean
|
||||||
|
$(Q) (cd $(NUTTX_SRC)/configs && ln -sf $(PX4_BASE)/nuttx-configs/* .)
|
||||||
$(Q) (cd $(NUTTX_SRC)tools && ./configure.sh $(board)/$(configuration))
|
$(Q) (cd $(NUTTX_SRC)tools && ./configure.sh $(board)/$(configuration))
|
||||||
@echo %% Exporting NuttX for $(board)
|
@$(ECHO) %% Exporting NuttX for $(board)
|
||||||
$(Q) make -r -j1 -C $(NUTTX_SRC) -r $(MQUIET) export
|
$(Q) make -r -j1 -C $(NUTTX_SRC) -r $(MQUIET) export
|
||||||
$(Q) mkdir -p $(dir $@)
|
$(Q) mkdir -p $(dir $@)
|
||||||
$(Q) $(COPY) $(NUTTX_SRC)nuttx-export.zip $@
|
$(Q) $(COPY) $(NUTTX_SRC)nuttx-export.zip $@
|
||||||
|
|
||||||
|
$(NUTTX_SRC):
|
||||||
|
@$(ECHO) ""
|
||||||
|
@$(ECHO) "NuttX sources missing - clone https://github.com/PX4/NuttX.git and try again."
|
||||||
|
@$(ECHO) ""
|
||||||
|
|
||||||
#
|
#
|
||||||
# Cleanup targets. 'clean' should remove all built products and force
|
# Cleanup targets. 'clean' should remove all built products and force
|
||||||
# a complete re-compilation, 'distclean' should remove everything
|
# a complete re-compilation, 'distclean' should remove everything
|
||||||
|
@ -170,46 +174,47 @@ clean:
|
||||||
distclean: clean
|
distclean: clean
|
||||||
$(Q) $(REMOVE) $(ARCHIVE_DIR)*.export
|
$(Q) $(REMOVE) $(ARCHIVE_DIR)*.export
|
||||||
$(Q) make -C $(NUTTX_SRC) -r $(MQUIET) distclean
|
$(Q) make -C $(NUTTX_SRC) -r $(MQUIET) distclean
|
||||||
|
$(Q) (cd $(NUTTX_SRC)/configs && find . -type l -depth 1 -delete)
|
||||||
|
|
||||||
#
|
#
|
||||||
# Print some help text
|
# Print some help text
|
||||||
#
|
#
|
||||||
.PHONY: help
|
.PHONY: help
|
||||||
help:
|
help:
|
||||||
@echo ""
|
@$(ECHO) ""
|
||||||
@echo " PX4 firmware builder"
|
@$(ECHO) " PX4 firmware builder"
|
||||||
@echo " ===================="
|
@$(ECHO) " ===================="
|
||||||
@echo ""
|
@$(ECHO) ""
|
||||||
@echo " Available targets:"
|
@$(ECHO) " Available targets:"
|
||||||
@echo " ------------------"
|
@$(ECHO) " ------------------"
|
||||||
@echo ""
|
@$(ECHO) ""
|
||||||
@echo " archives"
|
@$(ECHO) " archives"
|
||||||
@echo " Build the NuttX RTOS archives that are used by the firmware build."
|
@$(ECHO) " Build the NuttX RTOS archives that are used by the firmware build."
|
||||||
@echo ""
|
@$(ECHO) ""
|
||||||
@echo " all"
|
@$(ECHO) " all"
|
||||||
@echo " Build all firmware configs: $(CONFIGS)"
|
@$(ECHO) " Build all firmware configs: $(CONFIGS)"
|
||||||
@echo " A limited set of configs can be built with CONFIGS=<list-of-configs>"
|
@$(ECHO) " A limited set of configs can be built with CONFIGS=<list-of-configs>"
|
||||||
@echo ""
|
@$(ECHO) ""
|
||||||
@for config in $(CONFIGS); do \
|
@for config in $(CONFIGS); do \
|
||||||
echo " $$config"; \
|
echo " $$config"; \
|
||||||
echo " Build just the $$config firmware configuration."; \
|
echo " Build just the $$config firmware configuration."; \
|
||||||
echo ""; \
|
echo ""; \
|
||||||
done
|
done
|
||||||
@echo " clean"
|
@$(ECHO) " clean"
|
||||||
@echo " Remove all firmware build pieces."
|
@$(ECHO) " Remove all firmware build pieces."
|
||||||
@echo ""
|
@$(ECHO) ""
|
||||||
@echo " distclean"
|
@$(ECHO) " distclean"
|
||||||
@echo " Remove all compilation products, including NuttX RTOS archives."
|
@$(ECHO) " Remove all compilation products, including NuttX RTOS archives."
|
||||||
@echo ""
|
@$(ECHO) ""
|
||||||
@echo " upload"
|
@$(ECHO) " upload"
|
||||||
@echo " When exactly one config is being built, add this target to upload the"
|
@$(ECHO) " When exactly one config is being built, add this target to upload the"
|
||||||
@echo " firmware to the board when the build is complete. Not supported for"
|
@$(ECHO) " firmware to the board when the build is complete. Not supported for"
|
||||||
@echo " all configurations."
|
@$(ECHO) " all configurations."
|
||||||
@echo ""
|
@$(ECHO) ""
|
||||||
@echo " Common options:"
|
@$(ECHO) " Common options:"
|
||||||
@echo " ---------------"
|
@$(ECHO) " ---------------"
|
||||||
@echo ""
|
@$(ECHO) ""
|
||||||
@echo " V=1"
|
@$(ECHO) " V=1"
|
||||||
@echo " If V is set, more verbose output is printed during the build. This can"
|
@$(ECHO) " If V is set, more verbose output is printed during the build. This can"
|
||||||
@echo " help when diagnosing issues with the build or toolchain."
|
@$(ECHO) " help when diagnosing issues with the build or toolchain."
|
||||||
@echo ""
|
@$(ECHO) ""
|
||||||
|
|
|
@ -0,0 +1,94 @@
|
||||||
|
#!nsh
|
||||||
|
#
|
||||||
|
# Flight startup script for PX4FMU on PX4IOAR carrier board.
|
||||||
|
#
|
||||||
|
|
||||||
|
# Disable the USB interface
|
||||||
|
set USB no
|
||||||
|
|
||||||
|
# Disable autostarting other apps
|
||||||
|
set MODE ardrone
|
||||||
|
|
||||||
|
echo "[init] doing PX4IOAR startup..."
|
||||||
|
|
||||||
|
#
|
||||||
|
# Start the ORB
|
||||||
|
#
|
||||||
|
uorb start
|
||||||
|
|
||||||
|
#
|
||||||
|
# Load microSD params
|
||||||
|
#
|
||||||
|
echo "[init] loading microSD params"
|
||||||
|
param select /fs/microsd/params
|
||||||
|
if [ -f /fs/microsd/params ]
|
||||||
|
then
|
||||||
|
param load /fs/microsd/params
|
||||||
|
fi
|
||||||
|
|
||||||
|
#
|
||||||
|
# Force some key parameters to sane values
|
||||||
|
# MAV_TYPE 1 = fixed wing, 2 = quadrotor, 13 = hexarotor
|
||||||
|
# see https://pixhawk.ethz.ch/mavlink/
|
||||||
|
#
|
||||||
|
param set MAV_TYPE 2
|
||||||
|
|
||||||
|
#
|
||||||
|
# Configure PX4FMU for operation with PX4IOAR
|
||||||
|
#
|
||||||
|
fmu mode_gpio_serial
|
||||||
|
|
||||||
|
#
|
||||||
|
# Start the sensors.
|
||||||
|
#
|
||||||
|
sh /etc/init.d/rc.sensors
|
||||||
|
|
||||||
|
#
|
||||||
|
# Start MAVLink and MAVLink Onboard (Flow Sensor)
|
||||||
|
#
|
||||||
|
mavlink start -d /dev/ttyS0 -b 57600
|
||||||
|
mavlink_onboard start -d /dev/ttyS3 -b 115200
|
||||||
|
usleep 5000
|
||||||
|
|
||||||
|
#
|
||||||
|
# Start the commander.
|
||||||
|
#
|
||||||
|
commander start
|
||||||
|
|
||||||
|
#
|
||||||
|
# Start the attitude estimator
|
||||||
|
#
|
||||||
|
attitude_estimator_ekf start
|
||||||
|
|
||||||
|
#
|
||||||
|
# Start the position estimator
|
||||||
|
#
|
||||||
|
flow_position_estimator start
|
||||||
|
|
||||||
|
#
|
||||||
|
# Fire up the multi rotor attitude controller
|
||||||
|
#
|
||||||
|
multirotor_att_control start
|
||||||
|
|
||||||
|
#
|
||||||
|
# Fire up the flow position controller
|
||||||
|
#
|
||||||
|
flow_position_control start
|
||||||
|
|
||||||
|
#
|
||||||
|
# Fire up the flow speed controller
|
||||||
|
#
|
||||||
|
flow_speed_control start
|
||||||
|
|
||||||
|
#
|
||||||
|
# Fire up the AR.Drone interface.
|
||||||
|
#
|
||||||
|
ardrone_interface start -d /dev/ttyS1
|
||||||
|
|
||||||
|
#
|
||||||
|
# startup is done; we don't want the shell because we
|
||||||
|
# use the same UART for telemetry
|
||||||
|
#
|
||||||
|
echo "[init] startup done"
|
||||||
|
|
||||||
|
exit
|
|
@ -54,13 +54,13 @@ sh /etc/init.d/rc.sensors
|
||||||
#
|
#
|
||||||
# Start the attitude estimator (depends on orb)
|
# Start the attitude estimator (depends on orb)
|
||||||
#
|
#
|
||||||
kalman_demo start
|
att_pos_estimator_ekf start
|
||||||
|
|
||||||
#
|
#
|
||||||
# Load mixer and start controllers (depends on px4io)
|
# Load mixer and start controllers (depends on px4io)
|
||||||
#
|
#
|
||||||
mixer load /dev/pwm_output /etc/mixers/FMU_AET.mix
|
mixer load /dev/pwm_output /etc/mixers/FMU_AET.mix
|
||||||
control_demo start
|
fixedwing_backside start
|
||||||
|
|
||||||
echo "[HIL] setup done, running"
|
echo "[HIL] setup done, running"
|
||||||
|
|
||||||
|
|
|
@ -1,17 +1,6 @@
|
||||||
#!nsh
|
#!nsh
|
||||||
#
|
#
|
||||||
# PX4FMU startup script.
|
# PX4FMU startup script.
|
||||||
#
|
|
||||||
# This script is responsible for:
|
|
||||||
#
|
|
||||||
# - mounting the microSD card (if present)
|
|
||||||
# - running the user startup script from the microSD card (if present)
|
|
||||||
# - detecting the configuration of the system and picking a suitable
|
|
||||||
# startup script to continue with
|
|
||||||
#
|
|
||||||
# Note: DO NOT add configuration-specific commands to this script;
|
|
||||||
# add them to the per-configuration scripts instead.
|
|
||||||
#
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Default to auto-start mode. An init script on the microSD card
|
# Default to auto-start mode. An init script on the microSD card
|
||||||
|
@ -20,11 +9,6 @@
|
||||||
set MODE autostart
|
set MODE autostart
|
||||||
set USB autoconnect
|
set USB autoconnect
|
||||||
|
|
||||||
#
|
|
||||||
|
|
||||||
#
|
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Try to mount the microSD card.
|
# Try to mount the microSD card.
|
||||||
#
|
#
|
||||||
|
@ -69,7 +53,12 @@ else
|
||||||
then
|
then
|
||||||
echo "[init] USB interface connected"
|
echo "[init] USB interface connected"
|
||||||
else
|
else
|
||||||
echo "[init] No USB connected"
|
if [ -f /dev/ttyACM0 ]
|
||||||
|
echo "[init] NSH via USB"
|
||||||
|
then
|
||||||
|
else
|
||||||
|
echo "[init] No USB connected"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
#!nsh
|
||||||
|
#
|
||||||
|
# Flight startup script for PX4FMU standalone configuration.
|
||||||
|
#
|
||||||
|
|
||||||
|
echo "[init] doing standalone PX4FMU startup..."
|
||||||
|
|
||||||
|
#
|
||||||
|
# Start the ORB
|
||||||
|
#
|
||||||
|
uorb start
|
||||||
|
|
||||||
|
echo "[init] startup done"
|
|
@ -0,0 +1,4 @@
|
||||||
|
#!nsh
|
||||||
|
#
|
||||||
|
# PX4FMU startup script for test hackery.
|
||||||
|
#
|
|
@ -1,10 +0,0 @@
|
||||||
*.a
|
|
||||||
*.bdat
|
|
||||||
*.pdat
|
|
||||||
.built
|
|
||||||
.config
|
|
||||||
.depend
|
|
||||||
.updated
|
|
||||||
builtin/builtin_list.h
|
|
||||||
builtin/builtin_proto.h
|
|
||||||
Make.dep
|
|
|
@ -1,509 +0,0 @@
|
||||||
5.19 2011-03-12 Gregory Nutt <gnutt@nuttx.org>
|
|
||||||
|
|
||||||
* Initial version of the apps/ directory was released as contributed by
|
|
||||||
Uros Platise.
|
|
||||||
|
|
||||||
6.0 2011-03-21 Gregory Nutt <gnutt@nuttx.org>
|
|
||||||
|
|
||||||
* README.txt -- README cosmetics
|
|
||||||
* hello/ -- hello world minor changes
|
|
||||||
* Makefile -- Makefile cosmetics (I am slowly adding the Darjeeling JVM)
|
|
||||||
* Make.defs -- New file adds common make definitions for applications.
|
|
||||||
* hello/Makefile -- Now uses new Make.defs definitions. Added README.txt.
|
|
||||||
* apps/poweroff -- New application to turn off board power.
|
|
||||||
* Moved NSH library, netutils, and examples from the nuttx/ directory to
|
|
||||||
the apps/ directory
|
|
||||||
* Moved exec_nuttapp machinery into the nuttapp/ directory.
|
|
||||||
|
|
||||||
6.1 2011-04-10 Gregory Nutt <gnutt@nuttx.org>
|
|
||||||
|
|
||||||
* Creation of auto-generated header files now occurs during the context
|
|
||||||
build phase.
|
|
||||||
* Added sdcard insert and eject, nsh command '?' and some code remarks
|
|
||||||
* Renamed nuttapp to namedapp
|
|
||||||
* namedapp/binfs.c -- Create a tiny filesystem that can be used
|
|
||||||
to show the internal named apps under /bin.
|
|
||||||
* Numerous fixes to build system required to support building with native
|
|
||||||
Windows toolchain.
|
|
||||||
|
|
||||||
6.2 2011-05-06 Gregory Nutt <gnutt@nuttx.org>
|
|
||||||
|
|
||||||
* apps/examples/nxffs: Add a test a a configuration that will be used to
|
|
||||||
verify NXFFS.
|
|
||||||
|
|
||||||
6.3 2011-05-15 Gregory Nutt <gnutt@nuttx.org>
|
|
||||||
|
|
||||||
* 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/.
|
|
||||||
* apps/netutils/dhcpc, dhcpcd, and tftp. If these directories are included
|
|
||||||
in the configuration but CONFIG_NET_UDP is disable (which is not very wise),
|
|
||||||
then a make error occurs because tools/mkdep.sh is called with no files.
|
|
||||||
* system/free: Move Uros' custom free command from vsn/free
|
|
||||||
* system/install: Add a new install command submitted by Uros Platise.
|
|
||||||
* examples/rgmp. Add a placeholder for an RGMP build example.
|
|
||||||
RGMP is a project for running GPOS and RTOS simultaneously on
|
|
||||||
multi-processor platforms. See http://rgmp.sourceforge.net/wiki/index.php/Main_Page
|
|
||||||
for further information about RGMP. NOTE: This is an empty example
|
|
||||||
on initial check-in.
|
|
||||||
|
|
||||||
6.4 2011-06-06 Gregory Nutt <gnutt@nuttx.org>
|
|
||||||
|
|
||||||
* nshlib/nsh_netcmds.c: If a network device name and IP address are provided
|
|
||||||
with the ifconfig command, then this command will now set the network address.
|
|
||||||
(Contributed by Yu Qiang).
|
|
||||||
* netutils/ftpc: A library to support client-side FTP.
|
|
||||||
* examples/ftpc: A simple add-on to the NSH. From NSH, you can start
|
|
||||||
this simple FTP shell to transfer files to/from a remote FTP server.
|
|
||||||
|
|
||||||
6.5 2011-06-21 Gregory Nutt <gnutt@nuttx.org>
|
|
||||||
|
|
||||||
* netutils/ftpc: Simpflication and size reduction.
|
|
||||||
|
|
||||||
6.6 2011-07-11 Gregory Nutt <gnutt@nuttx.org>
|
|
||||||
|
|
||||||
* Make.defs, namedapp/namedapp.c: Several structural changes made to get a
|
|
||||||
clean compile under the ez80 ZDS-II toolchain (no design changes).
|
|
||||||
* apps/examples/buttons: Add a test for the new standardized button interfaces
|
|
||||||
* apps/examples/nxtext: Add another NX graphics test. This one focus on
|
|
||||||
placing text on the background while pop-up windows occur. Text should
|
|
||||||
continue to update normally with or without the popup windows present.
|
|
||||||
|
|
||||||
6.7 2011-08-02 Gregory Nutt <gnutt@nuttx.org>
|
|
||||||
|
|
||||||
* apps/examples/nx and nxtext: These examples can now be built as NSH
|
|
||||||
"built-in" commands.
|
|
||||||
* apps/examples/nxhello: The simplest graphics example: It just says
|
|
||||||
"Hello, World!" in the center of the display. This example can also be
|
|
||||||
built as an NSH "built-in" command.
|
|
||||||
* apps/examples/nx, ntext, and nxhello: All updated to use the new
|
|
||||||
NuttX font interfaces.
|
|
||||||
* apps/examples/nximage: Another super simple graphics example: It just puts
|
|
||||||
the NuttX logo in the center of the display. This example can also be
|
|
||||||
built as an NSH "built-in" command.
|
|
||||||
* apps/examples/usbstorage: Can now be built as two NSH "built-in" commands:
|
|
||||||
'msconn' will connect the USB mass storage device; 'msdis' will disconnect
|
|
||||||
the USB storage device.
|
|
||||||
* apps/examples/nx*: All NX header files moved from nuttx/include/nuttx to
|
|
||||||
nuttx/include/nuttx/nx.
|
|
||||||
* apps/examples/usbstorage: Added instrumentation to monitor memory usage
|
|
||||||
to check for memory leaks in the USB storage driver.
|
|
||||||
* apps/examples/nxhello/nxhello_bkgd.c: Fix handling of allocated glyph
|
|
||||||
memory.
|
|
||||||
|
|
||||||
6.8 2011-08-11 Gregory Nutt <gnutt@nuttx.org>
|
|
||||||
|
|
||||||
* apps/examples/nxlines: Added a test for NX line drawing capabilities.
|
|
||||||
|
|
||||||
6.9 2011-09-11 Gregory Nutt <gnutt@nuttx.org>
|
|
||||||
|
|
||||||
* apps/examples/nxlines: Extend the line drawing text to include drawing
|
|
||||||
of circles.
|
|
||||||
* apps/system/i2c: Add an I2C test tool that should help to bring up I2C
|
|
||||||
devices (when it is fully functional).
|
|
||||||
* apps/nshlib/nsh_timcmds.c: Add the date command that can be used to
|
|
||||||
show or set the time (only if CONFIG_RTC is set).
|
|
||||||
|
|
||||||
6.10 2011-10-06 Gregory Nutt <gnutt@nuttx.org>
|
|
||||||
|
|
||||||
* apps/system/i2c: Add repitition and address auto-incrementing so that
|
|
||||||
and command can be executed numerous times. Add a new verify command
|
|
||||||
that will write to a register, read from register, and verify that
|
|
||||||
returned value.
|
|
||||||
* apps/graphics/tiff: Add a library that can be used to create TIFF files.
|
|
||||||
* apps/examples/tiff: Add a unit test for the TIFF file creation logic
|
|
||||||
* apps/examples/lcdrw: Add a test to verify if you can or can or read
|
|
||||||
data from an LCD correctly.
|
|
||||||
* apps/examples/usbterm: A USB terminal example.. more of a USB chat or
|
|
||||||
serial bridge: Data received on local console echoed via USB serial;
|
|
||||||
data received on USB serial is echoed on the local console.
|
|
||||||
* apps/examples/touchscreen: Add a simple, generic test for any
|
|
||||||
touschscreen driver.
|
|
||||||
* Makefile: The apps/ Makefile now checks for an apps/external directory
|
|
||||||
or symbolic link. If such a directory/link exists (and has a Makefile),
|
|
||||||
it will be added to the apps/ build. This allows external directories
|
|
||||||
to be included into the apps/ build by simply creating a symbolic link.
|
|
||||||
|
|
||||||
6.11 2011-11-12 Gregory Nutt <gnutt@nuttx.org>
|
|
||||||
|
|
||||||
(No major changes from 6.10)
|
|
||||||
|
|
||||||
6.12 2011-12-06 Gregory Nutt <gnutt@nuttx.org>
|
|
||||||
|
|
||||||
* apps/examples/buttons: The button test can now be executed as an NSH
|
|
||||||
built in command.
|
|
||||||
|
|
||||||
6.13 2012-12-26 Gregory Nutt <gnutt@nuttx.org>
|
|
||||||
|
|
||||||
* apps/examples/dhcpd: May now be built as an NSH built-in application
|
|
||||||
by setting CONFIG_NSH_BUILTIN_APPS.
|
|
||||||
* apps/netutils/dhcpd/dhcpd.c: Fix several problems using host order address
|
|
||||||
where network addresses expected (and vice versa).
|
|
||||||
* apps/examples/nettest: May now be built as an NSH built-in application
|
|
||||||
by setting CONFIG_NSH_BUILTIN_APPS.
|
|
||||||
* apps/examples/nettest: Correct some build issues with the nettest is
|
|
||||||
built for performance evaluation.
|
|
||||||
* apps/examples/adc: Add a very simple test to drive and test an ADC
|
|
||||||
driver.
|
|
||||||
* apps/examples/pwm: Add an NSH PWM command to drive and test a PWM
|
|
||||||
driver.
|
|
||||||
* apps/examples/can: Add an NSH CAN command to drive and test a CAN
|
|
||||||
driver in loopback mode.
|
|
||||||
|
|
||||||
6.14 2012-01-15 Gregory Nutt <gnutt@nuttx.org>
|
|
||||||
|
|
||||||
* apps/examples/buttons/main.c: The test needs to call up_buttoninit() to
|
|
||||||
properly configure the button interrupt GPIOs.
|
|
||||||
* apps/examples/pwm: Add support to test the pulse count option recently
|
|
||||||
added to the PWM interface.
|
|
||||||
|
|
||||||
6.15 2012-02-12 Gregory Nutt <gnutt@nuttx.org>
|
|
||||||
|
|
||||||
* apps/nshlib/nsh_serial.c and nsh_usbdev.c: If NuttX is configured to use
|
|
||||||
a USB serial console, then NSH needs to wait until the USB console is
|
|
||||||
connected and available.
|
|
||||||
* apps/examples/composite: Add a test of the USB composite device.
|
|
||||||
* apps/examples/Telnetd: Move the tiny uIP shell example from
|
|
||||||
netutils/Telnetd to examples/Telnetd. Enhanced the Telnetd daemon so that
|
|
||||||
it supports Telnetd via a TTY device driver: A new TTY device driver is
|
|
||||||
created when each new Telnet connection is created. The shell thread
|
|
||||||
is started with stdin, stdout, and stderr mapped to the TTY device.
|
|
||||||
* netutils/Telnetd: The old uIP Telnet demo is gone. In its place is a new
|
|
||||||
Telnet infrastructure. The new Telnet daemon creates sessions that are
|
|
||||||
"wrapped" as character devices and mapped to stdin, stdout, and stderr.
|
|
||||||
Now the Telnet session can be inherited by spawned tasks.
|
|
||||||
* examples/Telnetd: Add a test for the new Telnet daemon.
|
|
||||||
* examples/Telnetd/telnetd_driver.c: Move the internal socket structure from
|
|
||||||
the daemon's socket array into the driver's state data so that it will be
|
|
||||||
independent from the the Telnetd daemon.
|
|
||||||
* apps/system/readline: Moved the old nuttx/lib/stdio/lib_fgets.c here
|
|
||||||
and renamed it as readline(). The old fgets was simplied and the overloaded
|
|
||||||
readline functionality was removed.
|
|
||||||
* apps/netutils/ftpd: Add an FTPD server (does not even compile on initial
|
|
||||||
checkin).
|
|
||||||
* apps/examples/ftpd: Add a test for the FTPD server (untest on initial
|
|
||||||
check-in).
|
|
||||||
* apps/nshlib/nsh_fscmds.c: Add support for a 'dmesg' command that will
|
|
||||||
dump the system log if CONFIG_SYSLOG is selected.
|
|
||||||
|
|
||||||
6.16 2012-03-10 Gregory Nutt <gnutt@nuttx.org>
|
|
||||||
|
|
||||||
* apps/examples/qencoder: Add a quadrature driver test.
|
|
||||||
* apps/examples/ostest/fpu.c: Add a test to verify that FPU registers
|
|
||||||
are properly saved and restored on context switches.
|
|
||||||
* apps/system/readline/readline.c: readline() will now treat either a
|
|
||||||
backspace or a DEL character as a backspace (i.e., deleting the character
|
|
||||||
to the left of the cursor). This makes NSH less dependent on particular
|
|
||||||
keyboard mappings of the Backspace key. Submitted by Mike Smith.
|
|
||||||
* apps/examples/cdcacm: An example that illustrates how the CDC/ACM driver
|
|
||||||
may to connected and disconnected through software control.
|
|
||||||
* apps/examples/nsh/nsh_main.c: If available, call up_cxxinitialize() to
|
|
||||||
initialize all statically defined C++ classes.
|
|
||||||
* apps/nshlib: Now supports a USB serial device for NSH console I/O. This
|
|
||||||
allows NSH to be used on boards that have USB but no serial connectors.
|
|
||||||
|
|
||||||
6.17 2012-04-14 Gregory Nutt <gnutt@nuttx.org>
|
|
||||||
|
|
||||||
* apps/examples/can: Add conditional compilation so that the test can be
|
|
||||||
configured to only send messages or to only receive messages. This will
|
|
||||||
let the test work in other modes than simple loopback testing.
|
|
||||||
* apps/examples/hello and apps/examples/ostest: Can now be built as NSH
|
|
||||||
built-int functions.
|
|
||||||
* vsn/hello: Removed. The modified apps/examples/hello is enough "Hello,
|
|
||||||
World!"
|
|
||||||
* apps/examples/nxconsole: Add a test of the NX console device.
|
|
||||||
* apps/examples/nxconsole: The NX console example now supports running
|
|
||||||
the NuttShell (NSH) within an NX window.
|
|
||||||
* apps/system/readline: Now uses standard definitions from
|
|
||||||
include/nuttx/ascii.h and vt100.h
|
|
||||||
* Kconfig, */Kconfig: Added skeleton Kconfig files to all directories that
|
|
||||||
may need them.
|
|
||||||
|
|
||||||
6.18 2012-05-19 Gregory Nutt <gnutt@nuttx.org>
|
|
||||||
|
|
||||||
* Kconfig: Continued Kconfig file updates (no longer tracking on a per-file
|
|
||||||
basis in the ChangeLog)
|
|
||||||
* apps/examples/watchdog: Add a watchdog timer example.
|
|
||||||
* apps/examples/tiff: Fix wrong path used for temporary file.
|
|
||||||
* apps/examples/touchscreen: Standardize the board-specific, touchscreen
|
|
||||||
initialization interfaces.
|
|
||||||
|
|
||||||
6.19 2012-06-15 Gregory Nutt <gnutt@nuttx.org>
|
|
||||||
|
|
||||||
* apps/nshlib/nsh_usbdev.c: Add the capability to use an arbitrary USB
|
|
||||||
device as the console (not necessarily /dev/console). This is a useful
|
|
||||||
option because then you can still use the serial console to debug with.
|
|
||||||
* apps/nshlib/nsh_usbdev.c: User now has to press ENTER 3 times before
|
|
||||||
USB console will start. Otherwise, the USB console starts before there
|
|
||||||
is anyone at the other end to listen.
|
|
||||||
* apps/nshlib/nsh_usbdev.c and nsh_consolemain.c: Add support for the USB
|
|
||||||
capability when a USB console is used.
|
|
||||||
* apps/nshlib/nsh_fscmds.c: Add the 'mv' command
|
|
||||||
|
|
||||||
6.20 2012-07-12 Gregory Nutt <gnutt@nuttx.org>
|
|
||||||
|
|
||||||
* namedapp/exec_namedapp.c - Correct an error when round robin scheduling
|
|
||||||
is enabled. The priority of the new, named application was erroneously
|
|
||||||
being set to the priority of the parent thread; losing its configured
|
|
||||||
priority. Reported by Mike Smith.
|
|
||||||
|
|
||||||
6.21 2012-08-25 Gregory Nutt <gnutt@nuttx.org>
|
|
||||||
|
|
||||||
* apps/include/: Stylistic clean-up of all header files.
|
|
||||||
* apps/modbus and apps/include/modbus: A port of freemodbus-v1.5.0
|
|
||||||
has been added to the NuttX apps/ source tree.
|
|
||||||
* apps/examples/modbus: A port of the freemodbus-v1.5.0 "demo"
|
|
||||||
program that will be used to verify the FreeModBus port
|
|
||||||
* apps/modbus: Don't use strerror(). It is just too big.
|
|
||||||
* apps/modbus: Add CONFIG_MB_TERMIOS. If the driver doesn't support
|
|
||||||
termios ioctls, then don't bother trying to configure the baud, parity
|
|
||||||
etc.
|
|
||||||
* apps/nshlib: If waitpid() is supported, then NSH now catches the
|
|
||||||
return value from spawned applications (provided by Mike Smith)
|
|
||||||
* apps/nshlib: Lock the scheduler while starting built-in applications
|
|
||||||
in order to eliminate race conditions (also from Mike Smith).
|
|
||||||
* apps/examples/adc, pwm, and qencoder: Add support for testing
|
|
||||||
devices with multiple ADC, PWM, and QE devices.
|
|
||||||
* apps/nshlib/nsh_mntcmds.c: Separated mount-related commands out of
|
|
||||||
nsh_fscmds.c. Extended to the mount command so that if no arguments
|
|
||||||
are provided, then the current mountpoints are enumerated.
|
|
||||||
* apps/nshlib/nsh_mntcmds.c: Add an NSH df command to list the
|
|
||||||
properties of mounted file systems.
|
|
||||||
* apps/nshlib/nsh_parse.c: Extend help command options. 'help' with
|
|
||||||
no arguments outputs a short list of commands. With -v lists all
|
|
||||||
command line details. A command name can be added to just get
|
|
||||||
help on one command.
|
|
||||||
* system/readline.c: If character input/output is interrupted by a
|
|
||||||
signal, then readline() will try the read/write again.
|
|
||||||
* apps/*/Make.defs: Numerous fixes needed to use the automated
|
|
||||||
configuration (from Richard Cochran).
|
|
||||||
|
|
||||||
6.22 2012-09-29 Gregory Nutt <gnutt@nuttx.org>
|
|
||||||
|
|
||||||
* apps/netutils/thttpd/thttpd_cgi.c: Missing NULL in argv[]
|
|
||||||
list (contributed by Kate).
|
|
||||||
* apps/nshlib/nsh_parse.c: CONFIG_NSH_DISABLE_WGET not CONFIG_NSH_DISABLE_GET
|
|
||||||
in one location (found by Kate).
|
|
||||||
* apps/examples/ostest/prioinherit.c: Limit the number of test
|
|
||||||
threads to no more than 3 of each priority. Bad things happen
|
|
||||||
when the existing logic tried to created several hundred test
|
|
||||||
treads!
|
|
||||||
* apps/nshlib/nsh.h: Both CONFIG_LIBC_STRERROR and CONFIG_NSH_STRERROR
|
|
||||||
must be defined to use strerror() with NSH.
|
|
||||||
* apps/examples/*/*_main.c, system/i2c/i2c_main.c, and others: Added
|
|
||||||
configuration variable CONFIG_USER_ENTRYPOINT that may be used to change
|
|
||||||
the default entry from user_start to some other symbol. Contributed by
|
|
||||||
Kate.
|
|
||||||
* apps/netutils/webserver/httpd/c: Fix a typo that as introduced in
|
|
||||||
version r4402: 'lese' instead of 'else' (Noted by Max Holtzberg).
|
|
||||||
* tools/mkfsdata.pl: The uIP web server CGI image making perl script was
|
|
||||||
moved from apps/netutils/webserver/makefsdata to nuttx/tools/mkfsdata.pl
|
|
||||||
(Part of a larger change submitted by Max Holtzberg).
|
|
||||||
* apps/netutils/webserver, apps/examples/uip, and apps/include/netutils/httpd.h:
|
|
||||||
The "canned" version of the uIP web servers content that was at
|
|
||||||
netutils/webserver/httpd_fsdata.c has been replaced with a dynamically
|
|
||||||
built configuration located at apps/examples/uip (Contributed by
|
|
||||||
Max Holtzberg).
|
|
||||||
* apps/netutils/webserver: Several inenhancements from Kate including the
|
|
||||||
ability to elide scripting and SERVER headers and the ability to map
|
|
||||||
files into memory before transferring them.
|
|
||||||
* apps/netutils/webserver: Add ability to map a URL to CGI function.
|
|
||||||
Contributed by Kate.
|
|
||||||
* apps/nshlib/nsh_mntcmds.c: The changes of 6.21 introduced holes in the
|
|
||||||
error handling: Now the number of arguments to mount can be 0 or 4.
|
|
||||||
Additional parameter checking is required to prevent mysterious errors
|
|
||||||
(submiteed by Kate).
|
|
||||||
* apps/netutils/webserver/httpd_mmap.c: Fix errors when the mmap()
|
|
||||||
length is zero (submitted by Kate).
|
|
||||||
* apps/netutils/webserver/httpd_sendfile.c: Add and option,
|
|
||||||
CONFIG_NETUTILS_HTTPD_SENDFILE to transfer files using the NuttX
|
|
||||||
sendfile() interface.
|
|
||||||
* apps/netutils/discover: A UDP network discovery utility contributed
|
|
||||||
by Max Holtzberg.
|
|
||||||
* apps/examples/discover: A test example for the UDP network discovery
|
|
||||||
utility (also contribed by Max Holtzberg).
|
|
||||||
* apps/examples/*/main.c: Too many files called main.c. Each renamed
|
|
||||||
to something unique so that they will not collide in the archive.
|
|
||||||
* apps/netutils/xmlrpc: The Embeddable Lightweight XML-RPC Server
|
|
||||||
discussed at http://www.drdobbs.com/web-development/\
|
|
||||||
an-embeddable-lightweight-xml-rpc-server/184405364. Contributed by
|
|
||||||
Max Holtzberg.
|
|
||||||
* apps/netutils/uip_listenon.c: Logic in uip_server.c that creates
|
|
||||||
the listening socket was moved to this new file to support re-use.
|
|
||||||
Contributed by Kate.
|
|
||||||
* apps/netutils/webserver/httpd.c: The option CONFIG_NETUTILS_HTTPD_SINGLECONNECT
|
|
||||||
can now be used to limit the server to a single thread. Option
|
|
||||||
CONFIG_NETUTILS_HTTPD_TIMEOUT can be used to generate HTTP 408 errors.
|
|
||||||
Both from Kate.
|
|
||||||
* apps/netutils/webserver/httpd.c: Improvements to HTTP parser from
|
|
||||||
Kate.
|
|
||||||
* apps/netutils/webserver/httpd.c: Add support for Keep-alive connections
|
|
||||||
(from Kate).
|
|
||||||
* apps/NxWidget/Kconfig: This is a kludge. I created this NxWidgets
|
|
||||||
directory that ONLY contains Kconfig. NxWidgets does not live in
|
|
||||||
either the nuttx/ or the apps/ source trees. This kludge makes it
|
|
||||||
possible to configure NxWidgets/NxWM without too much trouble (with
|
|
||||||
the tradeoff being a kind ugly structure and some maintenance issues).
|
|
||||||
* apps/examples/Make.defs: Missing support for apps/examples/watchdog.
|
|
||||||
* apps/NxWidgets/Kconfig: Add option to turn on the memory monitor
|
|
||||||
feature of the NxWidgets/NxWM unit tests.
|
|
||||||
|
|
||||||
6.23 2012-11-05 Gregory Nutt <gnutt@nuttx.org>
|
|
||||||
|
|
||||||
* vsn: Moved all NSH commands from vsn/ to system/. Deleted the vsn/
|
|
||||||
directory.
|
|
||||||
* Makefile: Change order of includes when CONFIG_NEWCONFIG=y. In
|
|
||||||
that case, namedapp must be included first so that the namedapp
|
|
||||||
context is established first. If the namedapp context is established
|
|
||||||
later, it will overwrite any existing namedapp_list.h and nameapp_proto.h
|
|
||||||
files.
|
|
||||||
* CONFIG_EXAMPLES_*: To make things consistent, changed all occurrences
|
|
||||||
of CONFIG_EXAMPLE_* to CONFIG_EXAMPLES_*.
|
|
||||||
* Kconfig: Fleshed out apps/examples/adc/Kconfig and apps/examples/wget/Kconfig.
|
|
||||||
There are still a LOT of empty, stub Kconfig files.
|
|
||||||
* Kconfig: Fleshed out apps/examples/buttons/Kconfig. There are still a LOT
|
|
||||||
of empty, stub Kconfig files.
|
|
||||||
* apps/netutils/webserver/httpd.c: Fix a bug that I introduced in
|
|
||||||
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-02-01 Gregory Nutt <gnutt@nuttx.org>
|
|
||||||
|
|
||||||
* Makefiles: Removed dependency of distclean on clean in most top-level
|
|
||||||
files. It makes sense for 'leaf' Makefiles to have this dependency,
|
|
||||||
but it does not make sense for upper-level Makefiles.
|
|
||||||
* apps/namedapp/: Renamed to builtins in preparation for another change.
|
|
||||||
* .context: Removed the .context kludge. This caused lots of problems
|
|
||||||
when changing configurations because there is no easy way to get the
|
|
||||||
system to rebuild the context. Now, the context will be rebuilt
|
|
||||||
whenever there is a change in either .config or the Makefile.
|
|
||||||
* apps/builtin/registry: Updated new built-in registration logic to handle
|
|
||||||
cases where (1) old apps/.config is used, and (2) applications ared
|
|
||||||
removed, not just added.
|
|
||||||
* apps/examples/nettest/Makefile: Fix an error that crept in during
|
|
||||||
some of the recent, massive build system changes.
|
|
||||||
* apps/builtin/Makefile: Need to have auto-generated header files
|
|
||||||
in place early in the dependency generation phase to avoid warnings.
|
|
||||||
It is not important if they are only stubbed out header files at
|
|
||||||
this build phase.
|
|
||||||
* apps/examples/hidbkd: Now supports decoding of encoded special keys
|
|
||||||
if CONFIG_EXAMPLES_HIDKBD_ENCODED is defined.
|
|
||||||
* apps/examples/hidbkd: Add support for decoding key release events
|
|
||||||
as well. However, the USB HID keyboard drier has not yet been
|
|
||||||
updated to detect key release events. That is kind of tricky in
|
|
||||||
the USB HID keyboard report data.
|
|
||||||
* apps/examples/wlan: Remove non-functional example.
|
|
||||||
* apps/examples/ostest/vfork.c: Added a test of vfork().
|
|
||||||
* apps/exampes/posix_spawn: Added a test of posix_spawn().
|
|
||||||
* apps/examples/ostest: Extend signal handler test to catch
|
|
||||||
death-of-child signals (SIGCHLD).
|
|
||||||
* apps/examples/ostest/waitpid.c: Add a test for waitpid(), waitid(),
|
|
||||||
and wait().
|
|
||||||
* builtin/binfs.c: Add hooks for dup() method (not implemented).
|
|
||||||
* builtin/exec_builtin.c, nshlib/nsh_parse.c, and nshlib/nsh_builtin.c:
|
|
||||||
NSH now supports re-direction of I/O to files (but still not from).
|
|
||||||
* builtin/binfs.c: Greatly simplified (it is going to need to be
|
|
||||||
very lightweight). Now supports open, close, and a new ioctl to recover
|
|
||||||
the builtin filename. The latter will be needed to support a binfs
|
|
||||||
binfmt.
|
|
||||||
* builtin/binfs.c: Move apps/builtin/binfs.c to fs/binfs/fs_binfs.c
|
|
||||||
CONFIG_APPS_BINDIR rename CONFIG_FS_BINFS
|
|
||||||
* apps/include/builtin.h: Some of the content of
|
|
||||||
apps/include/apps.h moved to include/nuttx/binfmt/builtin.h.
|
|
||||||
apps/include/apps.h renamed builtin.h
|
|
||||||
* apps/builtin/exec_builtins.c: Move builtin
|
|
||||||
utility functions from apps/builtin/exec_builtins.c to
|
|
||||||
binfmt/libbuiltin/libbuiltin_utils.c
|
|
||||||
* apps/nshlib/nsh_mountcmds.c: The block driver/source
|
|
||||||
argument is now optional. Many files systems do not need
|
|
||||||
a source and it is really stupid to have to enter a bogus
|
|
||||||
source parameter.
|
|
||||||
* apps/nshlib/nsh_fileapp.c: Add the ability to execute a file
|
|
||||||
from a file system using posix_spawn().
|
|
||||||
* apps/builtin/: Extensions from Mike Smith.
|
|
||||||
* apps/examples/ftpd/Makefile: Name ftpd_start is not the name of
|
|
||||||
the entrypoint. Should be ftpd_main (from Yan T.)
|
|
||||||
* apps/netutils/telnetd/telnetd_driver: Was stuck in a loop if
|
|
||||||
recv[from]() ever returned a value <= 0.
|
|
||||||
* apps/examples/nettest and poll: Complete Kconfig files.
|
|
||||||
* apps/examples/ostest/waitpid.c: Need to use WEXITSTATUS()
|
|
||||||
to decode the correct exit status.
|
|
||||||
* apps/system/usbmonitor: A daemon that can be used to monitor USB
|
|
||||||
trace outpout.
|
|
||||||
* apps/nshlib/nsh_usbdev.c, nsh_consolemain.c, nsh_session.c, nsh_script.c:
|
|
||||||
Add support for a login script. The init.d/rcS script will be executed
|
|
||||||
once when NSH starts; the .nshrc script will be executed for each session:
|
|
||||||
Once for serial, once for each USB connection, once for each Telnet
|
|
||||||
session.
|
|
||||||
* apps/system/readline: Correct readline() return value. Was not
|
|
||||||
any returning special values when end-of-file or read errors
|
|
||||||
occur (it would return an empty string which is not very useful).
|
|
||||||
|
|
||||||
6.26 2013-xx-xx Gregory Nutt <gnutt@nuttx.org>
|
|
36
apps/Kconfig
36
apps/Kconfig
|
@ -1,36 +0,0 @@
|
||||||
#
|
|
||||||
# For a description of the syntax of this configuration file,
|
|
||||||
# see misc/tools/kconfig-language.txt.
|
|
||||||
#
|
|
||||||
|
|
||||||
menu "Built-In Applications"
|
|
||||||
source "$APPSDIR/builtin/Kconfig"
|
|
||||||
endmenu
|
|
||||||
|
|
||||||
menu "Examples"
|
|
||||||
source "$APPSDIR/examples/Kconfig"
|
|
||||||
endmenu
|
|
||||||
|
|
||||||
menu "Interpreters"
|
|
||||||
source "$APPSDIR/interpreters/Kconfig"
|
|
||||||
endmenu
|
|
||||||
|
|
||||||
menu "Network Utilities"
|
|
||||||
source "$APPSDIR/netutils/Kconfig"
|
|
||||||
endmenu
|
|
||||||
|
|
||||||
menu "ModBus"
|
|
||||||
source "$APPSDIR/modbus/Kconfig"
|
|
||||||
endmenu
|
|
||||||
|
|
||||||
menu "NSH Library"
|
|
||||||
source "$APPSDIR/nshlib/Kconfig"
|
|
||||||
endmenu
|
|
||||||
|
|
||||||
menu "NxWidgets/NxWM"
|
|
||||||
source "$APPSDIR/NxWidgets/Kconfig"
|
|
||||||
endmenu
|
|
||||||
|
|
||||||
menu "System NSH Add-Ons"
|
|
||||||
source "$APPSDIR/system/Kconfig"
|
|
||||||
endmenu
|
|
|
@ -1,50 +0,0 @@
|
||||||
############################################################################
|
|
||||||
# apps/Make.defs
|
|
||||||
# Common make definitions provided to all applications
|
|
||||||
#
|
|
||||||
# Copyright (C) 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.
|
|
||||||
#
|
|
||||||
############################################################################
|
|
||||||
|
|
||||||
BUILTIN_REGISTRY = $(APPDIR)$(DELIM)builtin$(DELIM)registry
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_NUTTX_NEWCONFIG),y)
|
|
||||||
DEPCONFIG = $(TOPDIR)$(DELIM).config
|
|
||||||
else
|
|
||||||
DEPCONFIG = $(TOPDIR)$(DELIM).config $(APPDIR)$(DELIM).config
|
|
||||||
endif
|
|
||||||
|
|
||||||
define REGISTER
|
|
||||||
$(Q) echo "Register: $1"
|
|
||||||
$(Q) echo "{ \"$1\", $2, $3, $4 }," > "$(BUILTIN_REGISTRY)$(DELIM)$4.bdat"
|
|
||||||
$(Q) echo "int $4(int argc, char *argv[]);" > "$(BUILTIN_REGISTRY)$(DELIM)$4.pdat"
|
|
||||||
$(Q) touch "$(BUILTIN_REGISTRY)$(DELIM).updated"
|
|
||||||
endef
|
|
208
apps/Makefile
208
apps/Makefile
|
@ -1,208 +0,0 @@
|
||||||
############################################################################
|
|
||||||
# apps/Makefile
|
|
||||||
#
|
|
||||||
# Copyright (C) 2011-2012 Uros Platise. All rights reserved.
|
|
||||||
# Authors: Uros Platise <uros.platise@isotel.eu>
|
|
||||||
# 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
|
|
||||||
-include $(TOPDIR)/.config
|
|
||||||
|
|
||||||
APPDIR = ${shell pwd}
|
|
||||||
|
|
||||||
# Application Directories
|
|
||||||
|
|
||||||
# CONFIGURED_APPS is the list of all configured built-in directories/built
|
|
||||||
# action. It is created by the configured appconfig file (a copy of which
|
|
||||||
# appears in this directory as .config)
|
|
||||||
# SUBDIRS is the list of all directories containing Makefiles. It is used
|
|
||||||
# only for cleaning. builtin must always be the first in the list. This
|
|
||||||
# list can be extended by the .config file as well.
|
|
||||||
|
|
||||||
CONFIGURED_APPS =
|
|
||||||
|
|
||||||
SUBDIRS = examples interpreters builtin nshlib system
|
|
||||||
|
|
||||||
#SUBDIRS = examples graphics interpreters modbus builtin nshlib netutils system
|
|
||||||
|
|
||||||
# There are two different mechanisms for obtaining the list of configured
|
|
||||||
# directories:
|
|
||||||
#
|
|
||||||
# (1) In the legacy method, these paths are all provided in the appconfig
|
|
||||||
# file that is copied to the top-level apps/ directory as .config
|
|
||||||
# (2) With the development of the NuttX configuration tool, however, the
|
|
||||||
# selected applications are now enabled by the configuration tool.
|
|
||||||
# The apps/.config file is no longer used. Instead, the set of
|
|
||||||
# configured build directories can be found by including a Make.defs
|
|
||||||
# file contained in each of the apps/subdirectories.
|
|
||||||
#
|
|
||||||
# When the NuttX configuration tools executes, it will always define the
|
|
||||||
# configure CONFIG_NUTTX_NEWCONFIG to select between these two cases. Then
|
|
||||||
# legacy appconfig files will still work but newly configuration files will
|
|
||||||
# also work. Eventually the CONFIG_NUTTX_NEWCONFIG option will be phased
|
|
||||||
# out.
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_NUTTX_NEWCONFIG),y)
|
|
||||||
|
|
||||||
# builtin/Make.defs must be included first
|
|
||||||
|
|
||||||
include builtin/Make.defs
|
|
||||||
include examples/Make.defs
|
|
||||||
include graphics/Make.defs
|
|
||||||
include interpreters/Make.defs
|
|
||||||
include modbus/Make.defs
|
|
||||||
include netutils/Make.defs
|
|
||||||
include nshlib/Make.defs
|
|
||||||
include system/Make.defs
|
|
||||||
|
|
||||||
# INSTALLED_APPS is the list of currently available application directories. It
|
|
||||||
# is the same as CONFIGURED_APPS, but filtered to exclude any non-existent
|
|
||||||
# application directory. builtin is always in the list of applications to be
|
|
||||||
# built.
|
|
||||||
|
|
||||||
INSTALLED_APPS =
|
|
||||||
|
|
||||||
# The legacy case:
|
|
||||||
|
|
||||||
else
|
|
||||||
-include .config
|
|
||||||
|
|
||||||
# INSTALLED_APPS is the list of currently available application directories. It
|
|
||||||
# is the same as CONFIGURED_APPS, but filtered to exclude any non-existent
|
|
||||||
# application directory. builtin is always in the list of applications to be
|
|
||||||
# built.
|
|
||||||
|
|
||||||
INSTALLED_APPS = builtin
|
|
||||||
endif
|
|
||||||
|
|
||||||
# Create the list of available applications (INSTALLED_APPS)
|
|
||||||
|
|
||||||
define ADD_BUILTIN
|
|
||||||
INSTALLED_APPS += $(if $(wildcard $1$(DELIM)Makefile),$1,)
|
|
||||||
endef
|
|
||||||
|
|
||||||
$(foreach BUILTIN, $(CONFIGURED_APPS), $(eval $(call ADD_BUILTIN,$(BUILTIN))))
|
|
||||||
|
|
||||||
# EXTERNAL_APPS is used to add out of tree apps to the build
|
|
||||||
INSTALLED_APPS += $(EXTERNAL_APPS)
|
|
||||||
|
|
||||||
# The external/ directory may also be added to the INSTALLED_APPS. But there
|
|
||||||
# is no external/ directory in the repository. Rather, this directory may be
|
|
||||||
# provided by the user (possibly as a symbolic link) to add libraries and
|
|
||||||
# applications to the standard build from the repository.
|
|
||||||
|
|
||||||
EXTERNAL_DIR := $(dir $(wildcard external$(DELIM)Makefile))
|
|
||||||
|
|
||||||
INSTALLED_APPS += $(EXTERNAL_DIR)
|
|
||||||
SUBDIRS += $(EXTERNAL_DIR)
|
|
||||||
|
|
||||||
# The final build target
|
|
||||||
|
|
||||||
BIN = libapps$(LIBEXT)
|
|
||||||
|
|
||||||
# Build targets
|
|
||||||
|
|
||||||
all: $(BIN)
|
|
||||||
.PHONY: $(INSTALLED_APPS) context depend clean distclean
|
|
||||||
|
|
||||||
$(INSTALLED_APPS):
|
|
||||||
$(Q) $(MAKE) -C $@ TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)"
|
|
||||||
|
|
||||||
$(BIN): $(INSTALLED_APPS)
|
|
||||||
|
|
||||||
context:
|
|
||||||
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
|
|
||||||
$(Q) for %%G in ($(INSTALLED_APPS)) do ( \
|
|
||||||
$(MAKE) -C %%G TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" context \
|
|
||||||
)
|
|
||||||
else
|
|
||||||
$(Q) for dir in $(INSTALLED_APPS) ; do \
|
|
||||||
$(MAKE) -C $$dir TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" context ; \
|
|
||||||
done
|
|
||||||
endif
|
|
||||||
|
|
||||||
.depend: context Makefile $(SRCS)
|
|
||||||
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 ; \
|
|
||||||
done
|
|
||||||
endif
|
|
||||||
$(Q) touch $@
|
|
||||||
|
|
||||||
depend: .depend
|
|
||||||
|
|
||||||
clean:
|
|
||||||
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
|
|
||||||
endif
|
|
||||||
$(call DELFILE, $(BIN))
|
|
||||||
$(call CLEAN)
|
|
||||||
|
|
||||||
distclean:
|
|
||||||
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
|
|
||||||
$(Q) for %%G in ($(SUBDIRS)) do ( \
|
|
||||||
$(MAKE) -C %%G distclean TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" \
|
|
||||||
)
|
|
||||||
$(call DELFILE, .config)
|
|
||||||
$(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
|
|
||||||
$(call DELFILE, .config)
|
|
||||||
$(call DELFILE, .depend)
|
|
||||||
$(Q) ( if [ -e external ]; then \
|
|
||||||
echo "********************************************************"; \
|
|
||||||
echo "* The external directory/link must be removed manually *"; \
|
|
||||||
echo "********************************************************"; \
|
|
||||||
fi; \
|
|
||||||
)
|
|
||||||
endif
|
|
||||||
|
|
||||||
|
|
273
apps/README.txt
273
apps/README.txt
|
@ -1,273 +0,0 @@
|
||||||
Application Folder
|
|
||||||
==================
|
|
||||||
|
|
||||||
Contents
|
|
||||||
--------
|
|
||||||
|
|
||||||
General
|
|
||||||
Directory Location
|
|
||||||
Built-In Applications
|
|
||||||
NuttShell (NSH) Built-In Commands
|
|
||||||
Synchronous Built-In Commands
|
|
||||||
Application Configuration File
|
|
||||||
Example Built-In Application
|
|
||||||
Building NuttX with Board-Specific Pieces Outside the Source Tree
|
|
||||||
|
|
||||||
General
|
|
||||||
-------
|
|
||||||
This folder provides various applications found in sub-directories. These
|
|
||||||
applications are not inherently a part of NuttX but are provided to help
|
|
||||||
you develop your own applications. The apps/ directory is a "break away"
|
|
||||||
part of the configuration that you may choose to use or not.
|
|
||||||
|
|
||||||
Directory Location
|
|
||||||
------------------
|
|
||||||
The default application directory used by the NuttX build should be named
|
|
||||||
apps/ (or apps-x.y/ where x.y is the NuttX version number). This apps/
|
|
||||||
directory should appear in the directory tree at the same level as the
|
|
||||||
NuttX directory. Like:
|
|
||||||
|
|
||||||
.
|
|
||||||
|- nuttx
|
|
||||||
|
|
|
||||||
`- apps
|
|
||||||
|
|
||||||
If all of the above conditions are TRUE, then NuttX will be able to
|
|
||||||
find the application directory. If your application directory has a
|
|
||||||
different name or is location at a different position, then you will
|
|
||||||
have to inform the NuttX build system of that location. There are several
|
|
||||||
ways to do that:
|
|
||||||
|
|
||||||
1) You can define CONFIG_APPS_DIR to be the full path to your application
|
|
||||||
directory in the NuttX configuration file.
|
|
||||||
2) You can provide the path to the application directory on the command line
|
|
||||||
like: make APPDIR=<path> or make CONFIG_APPS_DIR=<path>
|
|
||||||
3) When you configure NuttX using tools/configure.sh, you can provide that
|
|
||||||
path to the application directory on the configuration command line
|
|
||||||
like: ./configure.sh -a <app-dir> <board-name>/<config-name>
|
|
||||||
|
|
||||||
Built-In Applications
|
|
||||||
---------------------
|
|
||||||
NuttX also supports applications that can be started using a name string.
|
|
||||||
In this case, application entry points with their requirements are gathered
|
|
||||||
together in two files:
|
|
||||||
|
|
||||||
- builtin/builtin_proto.h Entry points, prototype function
|
|
||||||
- builtin/builtin_list.h Application specific information and requirements
|
|
||||||
|
|
||||||
The build occurs in several phases as different build targets are executed:
|
|
||||||
(1) context, (2) depend, and (3) default (all). Application information is
|
|
||||||
collected during the make context build phase.
|
|
||||||
|
|
||||||
To execute an application function:
|
|
||||||
|
|
||||||
exec_builtin() is defined in the nuttx/include/apps/builtin.h
|
|
||||||
|
|
||||||
NuttShell (NSH) Built-In Commands
|
|
||||||
---------------------------------
|
|
||||||
One use of builtin applications is to provide a way of invoking your custom
|
|
||||||
application through the NuttShell (NSH) command line. NSH will support
|
|
||||||
a seamless method invoking the applications, when the following option is
|
|
||||||
enabled in the NuttX configuration file:
|
|
||||||
|
|
||||||
CONFIG_NSH_BUILTIN_APPS=y
|
|
||||||
|
|
||||||
Applications registered in the apps/builtin/builtin_list.h file will then
|
|
||||||
be accessible from the NSH command line. If you type 'help' at the NSH
|
|
||||||
prompt, you will see a list of the registered commands.
|
|
||||||
|
|
||||||
Synchronous Built-In Commands
|
|
||||||
-----------------------------
|
|
||||||
By default, built-in commands started from the NSH command line will run
|
|
||||||
asynchronously with NSH. If you want to force NSH to execute commands
|
|
||||||
then wait for the command to execute, you can enable that feature by
|
|
||||||
adding the following to the NuttX configuration file:
|
|
||||||
|
|
||||||
CONFIG_SCHED_WAITPID=y
|
|
||||||
|
|
||||||
The configuration option enables support for the waitpid() RTOS interface.
|
|
||||||
When that interface is enabled, NSH will use it to wait, sleeping until
|
|
||||||
the built-in command executes to completion.
|
|
||||||
|
|
||||||
Of course, even with CONFIG_SCHED_WAITPID=y defined, specific commands
|
|
||||||
can still be forced to run asynchronously by adding the ampersand (&)
|
|
||||||
after the NSH command.
|
|
||||||
|
|
||||||
Application Configuration File
|
|
||||||
------------------------------
|
|
||||||
The old-style NuttX configuration uses a special configuration file is
|
|
||||||
used to configure which applications are to be included in the build.
|
|
||||||
The source for this file is configs/<board>/<configuration>/appconfig.
|
|
||||||
The existence of the appconfig file in the board configuration directory\
|
|
||||||
is sufficient to enable building of applications.
|
|
||||||
|
|
||||||
The appconfig file is copied into the apps/ directory as .config when
|
|
||||||
NuttX is configured. .config is included in the toplevel apps/Makefile.
|
|
||||||
As a minimum, this configuration file must define files to add to the
|
|
||||||
CONFIGURED_APPS list like:
|
|
||||||
|
|
||||||
CONFIGURED_APPS += examples/hello system/poweroff
|
|
||||||
|
|
||||||
The new NuttX configuration uses kconfig-frontends tools and only the
|
|
||||||
NuttX .config file. The new configuration is indicated by the existence
|
|
||||||
of the definition CONFIG_NUTTX_NEWCONFIG=y in the NuttX .config file.
|
|
||||||
If CONFIG_NUTTX_NEWCONFIG is defined, then the Makefile will:
|
|
||||||
|
|
||||||
- Assume that there is no apps/.config file and will instead
|
|
||||||
- Include Make.defs files from each of the subdirectories.
|
|
||||||
|
|
||||||
When an application is enabled using the kconfig-frontends tool, then
|
|
||||||
a new definition is added to the NuttX .config file. For example, if
|
|
||||||
you want to enable apps/examples/hello then the old apps/.config would
|
|
||||||
have had:
|
|
||||||
|
|
||||||
CONFIGURED_APPS += examples/hello
|
|
||||||
|
|
||||||
But in the new configuration there will be no apps/.config file and,
|
|
||||||
instead, the NuttX .config will have:
|
|
||||||
|
|
||||||
CONFIG_EXAMPLES_HELLO=y
|
|
||||||
|
|
||||||
This will select the apps/examples/hello in the following way:
|
|
||||||
|
|
||||||
- The top-level make will include examples/Make.defs
|
|
||||||
- examples/Make.defs will set CONFIGURED_APPS += examples/hello
|
|
||||||
like this:
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_EXAMPLES_HELLO),y)
|
|
||||||
CONFIGURED_APPS += examples/hello
|
|
||||||
endif
|
|
||||||
|
|
||||||
Thus accomplishing the same thing with no apps/.config file.
|
|
||||||
|
|
||||||
Example Built-In Application
|
|
||||||
----------------------------
|
|
||||||
An example application skeleton can be found under the examples/hello
|
|
||||||
sub-directory. This example shows how a builtin application can be added
|
|
||||||
to the project. One must define:
|
|
||||||
|
|
||||||
Old configuration method:
|
|
||||||
|
|
||||||
1. Create sub-directory as: appname
|
|
||||||
|
|
||||||
2. In this directory there should be:
|
|
||||||
|
|
||||||
- A Makefile, and
|
|
||||||
- The application source code.
|
|
||||||
|
|
||||||
3. The application source code should provide the entry point:
|
|
||||||
appname_main()
|
|
||||||
|
|
||||||
4. Set the requirements in the file: Makefile, specially the lines:
|
|
||||||
|
|
||||||
APPNAME = appname
|
|
||||||
PRIORITY = SCHED_PRIORITY_DEFAULT
|
|
||||||
STACKSIZE = 768
|
|
||||||
ASRCS = asm source file list as a.asm b.asm ...
|
|
||||||
CSRCS = C source file list as foo1.c foo2.c ..
|
|
||||||
|
|
||||||
Look at some of the other Makefiles for examples. Note the
|
|
||||||
special registration logic needed for the context: target
|
|
||||||
|
|
||||||
5. Add the to the application to the CONFIGIURED_APPS in the
|
|
||||||
apps/.config file:
|
|
||||||
|
|
||||||
CONFIGURED_APPS += appname
|
|
||||||
|
|
||||||
New Configuration Method:
|
|
||||||
|
|
||||||
1. Create sub-directory as: appname
|
|
||||||
|
|
||||||
2. In this directory there should be:
|
|
||||||
|
|
||||||
- A Make.defs file that would be included by the apps/Makefile
|
|
||||||
- A Kconfig file that would be used by the configuration tool (see
|
|
||||||
misc/tools/kconfig-language.txt). This Kconfig file should be
|
|
||||||
included by the apps/Kconfig file
|
|
||||||
- A Makefile, and
|
|
||||||
- The application source code.
|
|
||||||
|
|
||||||
3. The application source code should provide the entry point:
|
|
||||||
appname_main()
|
|
||||||
|
|
||||||
4. Set the requirements in the file: Makefile, specially the lines:
|
|
||||||
|
|
||||||
APPNAME = appname
|
|
||||||
PRIORITY = SCHED_PRIORITY_DEFAULT
|
|
||||||
STACKSIZE = 768
|
|
||||||
ASRCS = asm source file list as a.asm b.asm ...
|
|
||||||
CSRCS = C source file list as foo1.c foo2.c ..
|
|
||||||
|
|
||||||
4b. The Make.defs file should include a line like:
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_APPNAME),y)
|
|
||||||
CONFIGURED_APPS += appname
|
|
||||||
endif
|
|
||||||
|
|
||||||
Building NuttX with Board-Specific Pieces Outside the Source Tree
|
|
||||||
-----------------------------------------------------------------
|
|
||||||
|
|
||||||
Q: Has anyone come up with a tidy way to build NuttX with board-
|
|
||||||
specific pieces outside the source tree?
|
|
||||||
A: Here are four:
|
|
||||||
|
|
||||||
1) There is a make target called 'make export'. It will build
|
|
||||||
NuttX, then bundle all of the header files, libaries, startup
|
|
||||||
objects, and other build components into a .zip file. You
|
|
||||||
can can move that .zip file into any build environment you
|
|
||||||
want. You even build NuttX under a DOS CMD window.
|
|
||||||
|
|
||||||
This make target is documented in the top level nuttx/README.txt.
|
|
||||||
|
|
||||||
2) You can replace the entire apps/ directory. If there is
|
|
||||||
nothing in the apps/ directory that you need, you can define
|
|
||||||
CONFIG_APPS_DIR in your .config file so that it points to a
|
|
||||||
different, custom application directory.
|
|
||||||
|
|
||||||
You can copy any pieces that you like from the old apps/directory
|
|
||||||
to your custom apps directory as necessary.
|
|
||||||
|
|
||||||
This is documented in NuttX/configs/README.txt and
|
|
||||||
nuttx/Documentation/NuttxPortingGuide.html (Online at
|
|
||||||
http://nuttx.sourceforge.net/NuttxPortingGuide.html#apndxconfigs
|
|
||||||
under Build options). And in the apps/README.txt file.
|
|
||||||
|
|
||||||
3) If you like the random collection of stuff in the apps/ directory
|
|
||||||
but just want to expand the existing components with your own,
|
|
||||||
external sub-directory then there is an easy way to that too:
|
|
||||||
You just create the sympolic link at apps/external that
|
|
||||||
redirects to your application sub-directory. The apps/Makefile
|
|
||||||
will always automatically check for the existence of an
|
|
||||||
apps/external directory and if it exists, it will automatically
|
|
||||||
incorporate it into the build.
|
|
||||||
|
|
||||||
This feature of the apps/Makefile is documented only here.
|
|
||||||
|
|
||||||
You can, for example, create a script called install.sh that
|
|
||||||
installs a custom application, configuration, and board specific
|
|
||||||
directory:
|
|
||||||
|
|
||||||
a) Copy 'MyBoard' directory to configs/MyBoard.
|
|
||||||
b) Add a symbolic link to MyApplication at apps/external
|
|
||||||
c) Configure NuttX (usually by:
|
|
||||||
|
|
||||||
tools/configure.sh MyBoard/MyConfiguration
|
|
||||||
|
|
||||||
or simply by copying defconfig->nutt/.config,
|
|
||||||
setenv.sh->nuttx/setenv.sh, Make.defs->nuttx/Make.defs,
|
|
||||||
appconfig->apps/.config
|
|
||||||
|
|
||||||
Using the 'external' link makes it especially easy to add a
|
|
||||||
'built-in' application an existing configuration.
|
|
||||||
|
|
||||||
4) Add any link to apps/
|
|
||||||
|
|
||||||
a) Add symbolic links apps/ to as many other directories as you
|
|
||||||
want.
|
|
||||||
b) Then just add the (relative) paths to the links in your
|
|
||||||
appconfig file (that becomes the apps/.config file).
|
|
||||||
|
|
||||||
That is basically the same as my option #3 but doesn't use the
|
|
||||||
magic 'external' link. The toplevel apps/Makefile will always
|
|
||||||
to build whatever in finds in the apps/.config file (plus the
|
|
||||||
external link if present).
|
|
|
@ -1,17 +0,0 @@
|
||||||
#
|
|
||||||
# For a description of the syntax of this configuration file,
|
|
||||||
# see misc/tools/kconfig-language.txt.
|
|
||||||
#
|
|
||||||
|
|
||||||
if BUILTIN
|
|
||||||
|
|
||||||
config BUILTIN_PROXY_STACKSIZE
|
|
||||||
int "Builtin Proxy Stack Size"
|
|
||||||
default 1024
|
|
||||||
---help---
|
|
||||||
If exec_builtin uses I/O redirection options, then it will require
|
|
||||||
an intermediary/proxy task to muck with the file descriptors. This
|
|
||||||
configuration item specifies the stack size used for the proxy. Default:
|
|
||||||
1024 bytes.
|
|
||||||
|
|
||||||
endif
|
|
|
@ -1,40 +0,0 @@
|
||||||
############################################################################
|
|
||||||
# apps/builtin/Make.defs
|
|
||||||
# Adds selected applications to apps/ build
|
|
||||||
#
|
|
||||||
# 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_BUILTIN),y)
|
|
||||||
CONFIGURED_APPS += builtin
|
|
||||||
endif
|
|
||||||
|
|
|
@ -1,130 +0,0 @@
|
||||||
############################################################################
|
|
||||||
# apps/builtin/Makefile
|
|
||||||
#
|
|
||||||
# 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
|
|
||||||
# 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
|
|
||||||
include $(APPDIR)/Make.defs
|
|
||||||
|
|
||||||
# Source and object files
|
|
||||||
|
|
||||||
ASRCS =
|
|
||||||
CSRCS = builtin.c builtin_list.c exec_builtin.c
|
|
||||||
|
|
||||||
AOBJS = $(ASRCS:.S=$(OBJEXT))
|
|
||||||
COBJS = $(CSRCS:.c=$(OBJEXT))
|
|
||||||
|
|
||||||
SRCS = $(ASRCS) $(CSRCS)
|
|
||||||
OBJS = $(AOBJS) $(COBJS)
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
|
|
||||||
BIN = ..\libapps$(LIBEXT)
|
|
||||||
else
|
|
||||||
ifeq ($(WINTOOL),y)
|
|
||||||
BIN = ..\\libapps$(LIBEXT)
|
|
||||||
else
|
|
||||||
BIN = ../libapps$(LIBEXT)
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
ROOTDEPPATH = --dep-path .
|
|
||||||
VPATH =
|
|
||||||
|
|
||||||
# Build Targets
|
|
||||||
|
|
||||||
all: .built
|
|
||||||
.PHONY: context depend clean distclean
|
|
||||||
|
|
||||||
$(AOBJS): %$(OBJEXT): %.S
|
|
||||||
$(call ASSEMBLE, $<, $@)
|
|
||||||
|
|
||||||
$(COBJS): %$(OBJEXT): %.c
|
|
||||||
$(call COMPILE, $<, $@)
|
|
||||||
|
|
||||||
registry$(DELIM).updated:
|
|
||||||
$(V) $(MAKE) -C registry .updated TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)"
|
|
||||||
|
|
||||||
builtin_list.h: registry$(DELIM).updated
|
|
||||||
$(call DELFILE, builtin_list.h)
|
|
||||||
$(Q) touch builtin_list.h
|
|
||||||
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
|
|
||||||
$(Q) for /f %%G in ('dir /b registry\*.bdat`) do ( type registry\%%G >> builtin_list.h )
|
|
||||||
else
|
|
||||||
$(Q) ( \
|
|
||||||
filelist=`ls registry/*.bdat 2>/dev/null || echo ""`; \
|
|
||||||
for file in $$filelist; \
|
|
||||||
do cat $$file >> builtin_list.h; \
|
|
||||||
done; \
|
|
||||||
)
|
|
||||||
endif
|
|
||||||
|
|
||||||
builtin_proto.h: registry$(DELIM).updated
|
|
||||||
$(call DELFILE, builtin_proto.h)
|
|
||||||
$(Q) touch builtin_proto.h
|
|
||||||
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
|
|
||||||
$(Q) for /f %%G in ('dir /b registry\*.pdat`) do ( type registry\%%G >> builtin_proto.h )
|
|
||||||
else
|
|
||||||
$(Q) ( \
|
|
||||||
filelist=`ls registry/*.pdat 2>/dev/null || echo ""`; \
|
|
||||||
for file in $$filelist; \
|
|
||||||
do cat $$file >> builtin_proto.h; \
|
|
||||||
done; \
|
|
||||||
)
|
|
||||||
endif
|
|
||||||
|
|
||||||
.built: builtin_list.h builtin_proto.h $(OBJS)
|
|
||||||
$(call ARCHIVE, $(BIN), $(OBJS))
|
|
||||||
$(Q) touch .built
|
|
||||||
|
|
||||||
context:
|
|
||||||
$(Q) $(MAKE) -C registry context TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)"
|
|
||||||
|
|
||||||
.depend: Makefile $(SRCS) builtin_list.h builtin_proto.h
|
|
||||||
$(Q) $(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
|
|
||||||
$(Q) touch $@
|
|
||||||
|
|
||||||
depend: .depend
|
|
||||||
|
|
||||||
clean:
|
|
||||||
$(Q) $(MAKE) -C registry clean TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)"
|
|
||||||
$(call DELFILE, .built)
|
|
||||||
$(call CLEAN)
|
|
||||||
|
|
||||||
distclean: clean
|
|
||||||
$(Q) $(MAKE) -C registry distclean TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)"
|
|
||||||
$(call DELFILE, Make.dep)
|
|
||||||
$(call DELFILE, .depend)
|
|
||||||
$(call DELFILE, builtin_list.h)
|
|
||||||
$(call DELFILE, builtin_proto.h)
|
|
||||||
|
|
||||||
-include Make.dep
|
|
|
@ -1,80 +0,0 @@
|
||||||
/****************************************************************************
|
|
||||||
* apps/builtin/builtin.c
|
|
||||||
*
|
|
||||||
* Copyright (C) 2011 Uros Platise. All rights reserved.
|
|
||||||
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
|
||||||
* Authors: Uros Platise <uros.platise@isotel.eu>
|
|
||||||
* 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 <nuttx/binfmt/builtin.h>
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Types
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Function Prototypes
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Data
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
extern const struct builtin_s g_builtins[];
|
|
||||||
extern const int g_builtin_count;
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Data
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Functions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Functions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
FAR const struct builtin_s *builtin_for_index(int index)
|
|
||||||
{
|
|
||||||
if (index < g_builtin_count)
|
|
||||||
{
|
|
||||||
return &g_builtins[index];
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
|
@ -1,79 +0,0 @@
|
||||||
/****************************************************************************
|
|
||||||
* apps/builtin/builtin_list.c
|
|
||||||
*
|
|
||||||
* Copyright (C) 2011 Uros Platise. All rights reserved.
|
|
||||||
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
|
||||||
* Authors: Uros Platise <uros.platise@isotel.eu>
|
|
||||||
* 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 <nuttx/binfmt/builtin.h>
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Types
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Function Prototypes
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Data
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#include "builtin_proto.h"
|
|
||||||
|
|
||||||
const struct builtin_s g_builtins[] =
|
|
||||||
{
|
|
||||||
# include "builtin_list.h"
|
|
||||||
{ NULL, 0, 0, 0 }
|
|
||||||
};
|
|
||||||
|
|
||||||
const int g_builtin_count = sizeof(g_builtins) / sizeof(g_builtins[0]);
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Data
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Functions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Functions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
|
@ -1,467 +0,0 @@
|
||||||
/****************************************************************************
|
|
||||||
* apps/builtin/exec_builtin.c
|
|
||||||
*
|
|
||||||
* Originally by:
|
|
||||||
*
|
|
||||||
* Copyright (C) 2011 Uros Platise. All rights reserved.
|
|
||||||
* Author: Uros Platise <uros.platise@isotel.eu>
|
|
||||||
*
|
|
||||||
* With subsequent updates, modifications, and general maintenance by:
|
|
||||||
*
|
|
||||||
* Copyright (C) 2012-2013 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/wait.h>
|
|
||||||
#include <sched.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <semaphore.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <debug.h>
|
|
||||||
|
|
||||||
#include <nuttx/binfmt/builtin.h>
|
|
||||||
#include <apps/builtin.h>
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Pre-processor Definitions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#ifndef CONFIG_BUILTIN_PROXY_STACKSIZE
|
|
||||||
# define CONFIG_BUILTIN_PROXY_STACKSIZE 1024
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Types
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
struct builtin_parms_s
|
|
||||||
{
|
|
||||||
/* Input values */
|
|
||||||
|
|
||||||
FAR const char *redirfile;
|
|
||||||
FAR const char **argv;
|
|
||||||
int oflags;
|
|
||||||
int index;
|
|
||||||
|
|
||||||
/* Returned values */
|
|
||||||
|
|
||||||
pid_t result;
|
|
||||||
int errcode;
|
|
||||||
};
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Function Prototypes
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Data
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static sem_t g_builtin_parmsem = SEM_INITIALIZER(1);
|
|
||||||
#ifndef CONFIG_SCHED_WAITPID
|
|
||||||
static sem_t g_builtin_execsem = SEM_INITIALIZER(0);
|
|
||||||
#endif
|
|
||||||
static struct builtin_parms_s g_builtin_parms;
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Functions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: bultin_semtake and builtin_semgive
|
|
||||||
*
|
|
||||||
* Description:
|
|
||||||
* Give and take semaphores
|
|
||||||
*
|
|
||||||
* Input Parameters:
|
|
||||||
*
|
|
||||||
* sem - The semaphore to act on.
|
|
||||||
*
|
|
||||||
* Returned Value:
|
|
||||||
* None
|
|
||||||
*
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static void bultin_semtake(FAR sem_t *sem)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
ret = sem_wait(sem);
|
|
||||||
ASSERT(ret == 0 || get_errno() == EINTR);
|
|
||||||
}
|
|
||||||
while (ret != 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
#define builtin_semgive(sem) sem_post(sem)
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: builtin_taskcreate
|
|
||||||
*
|
|
||||||
* Description:
|
|
||||||
* Execute the builtin task
|
|
||||||
*
|
|
||||||
* Returned Value:
|
|
||||||
* On success, the task ID of the builtin task is returned; On failure, -1
|
|
||||||
* (ERROR) is returned and the errno is set appropriately.
|
|
||||||
*
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static int builtin_taskcreate(int index, FAR const char **argv)
|
|
||||||
{
|
|
||||||
FAR const struct builtin_s *b;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
b = builtin_for_index(index);
|
|
||||||
|
|
||||||
if (b == NULL)
|
|
||||||
{
|
|
||||||
set_errno(ENOENT);
|
|
||||||
return ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Disable pre-emption. This means that although we start the builtin
|
|
||||||
* application here, it will not actually run until pre-emption is
|
|
||||||
* re-enabled below.
|
|
||||||
*/
|
|
||||||
|
|
||||||
sched_lock();
|
|
||||||
|
|
||||||
/* Start the builtin application task */
|
|
||||||
|
|
||||||
ret = TASK_CREATE(b->name, b->priority, b->stacksize, b->main,
|
|
||||||
(argv) ? &argv[1] : (FAR const char **)NULL);
|
|
||||||
|
|
||||||
/* If robin robin scheduling is enabled, then set the scheduling policy
|
|
||||||
* of the new task to SCHED_RR before it has a chance to run.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if CONFIG_RR_INTERVAL > 0
|
|
||||||
if (ret > 0)
|
|
||||||
{
|
|
||||||
struct sched_param param;
|
|
||||||
|
|
||||||
/* Pre-emption is disabled so the task creation and the
|
|
||||||
* following operation will be atomic. The priority of the
|
|
||||||
* new task cannot yet have changed from its initial value.
|
|
||||||
*/
|
|
||||||
|
|
||||||
param.sched_priority = b->priority;
|
|
||||||
(void)sched_setscheduler(ret, SCHED_RR, ¶m);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Now let the builtin application run */
|
|
||||||
|
|
||||||
sched_unlock();
|
|
||||||
|
|
||||||
/* Return the task ID of the new task if the task was sucessfully
|
|
||||||
* started. Otherwise, ret will be ERROR (and the errno value will
|
|
||||||
* be set appropriately).
|
|
||||||
*/
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: builtin_proxy
|
|
||||||
*
|
|
||||||
* Description:
|
|
||||||
* Perform output redirection, then execute the builtin task.
|
|
||||||
*
|
|
||||||
* Input Parameters:
|
|
||||||
* Standard task start-up parameters
|
|
||||||
*
|
|
||||||
* Returned Value:
|
|
||||||
* Standard task return value.
|
|
||||||
*
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static int builtin_proxy(int argc, char *argv[])
|
|
||||||
{
|
|
||||||
int fd;
|
|
||||||
int ret = ERROR;
|
|
||||||
|
|
||||||
/* Open the output file for redirection */
|
|
||||||
|
|
||||||
svdbg("Open'ing redirfile=%s oflags=%04x mode=0644\n",
|
|
||||||
g_builtin_parms.redirfile, g_builtin_parms.oflags);
|
|
||||||
|
|
||||||
fd = open(g_builtin_parms.redirfile, g_builtin_parms.oflags, 0644);
|
|
||||||
if (fd < 0)
|
|
||||||
{
|
|
||||||
/* Remember the errno value. ret is already set to ERROR */
|
|
||||||
|
|
||||||
g_builtin_parms.errcode = get_errno();
|
|
||||||
sdbg("ERROR: open of %s failed: %d\n",
|
|
||||||
g_builtin_parms.redirfile, g_builtin_parms.errcode);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Does the return file descriptor happen to match the required file
|
|
||||||
* desciptor number?
|
|
||||||
*/
|
|
||||||
|
|
||||||
else if (fd != 1)
|
|
||||||
{
|
|
||||||
/* No.. dup2 to get the correct file number */
|
|
||||||
|
|
||||||
svdbg("Dup'ing %d->1\n", fd);
|
|
||||||
|
|
||||||
ret = dup2(fd, 1);
|
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
g_builtin_parms.errcode = get_errno();
|
|
||||||
sdbg("ERROR: dup2 failed: %d\n", g_builtin_parms.errcode);
|
|
||||||
}
|
|
||||||
|
|
||||||
svdbg("Closing fd=%d\n", fd);
|
|
||||||
close(fd);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Was the setup successful? */
|
|
||||||
|
|
||||||
if (ret == OK)
|
|
||||||
{
|
|
||||||
/* Yes.. Start the task. On success, the task ID of the builtin task
|
|
||||||
* is returned; On failure, -1 (ERROR) is returned and the errno
|
|
||||||
* is set appropriately.
|
|
||||||
*/
|
|
||||||
|
|
||||||
ret = builtin_taskcreate(g_builtin_parms.index, g_builtin_parms.argv);
|
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
g_builtin_parms.errcode = get_errno();
|
|
||||||
sdbg("ERROR: builtin_taskcreate failed: %d\n",
|
|
||||||
g_builtin_parms.errcode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* NOTE: There is a logical error here if CONFIG_SCHED_HAVE_PARENT is
|
|
||||||
* defined: The new task is the child of this proxy task, not the
|
|
||||||
* original caller. As a consequence, operations like waitpid() will
|
|
||||||
* fail on the caller's thread.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Post the semaphore to inform the parent task that we have completed
|
|
||||||
* what we need to do.
|
|
||||||
*/
|
|
||||||
|
|
||||||
g_builtin_parms.result = ret;
|
|
||||||
#ifndef CONFIG_SCHED_WAITPID
|
|
||||||
builtin_semgive(&g_builtin_execsem);
|
|
||||||
#endif
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: builtin_startproxy
|
|
||||||
*
|
|
||||||
* Description:
|
|
||||||
* Perform output redirection, then execute the builtin task.
|
|
||||||
*
|
|
||||||
* Input Parameters:
|
|
||||||
* Standard task start-up parameters
|
|
||||||
*
|
|
||||||
* Returned Value:
|
|
||||||
* On success, the task ID of the builtin task is returned; On failure, -1
|
|
||||||
* (ERROR) is returned and the errno is set appropriately.
|
|
||||||
*
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static inline int builtin_startproxy(int index, FAR const char **argv,
|
|
||||||
FAR const char *redirfile, int oflags)
|
|
||||||
{
|
|
||||||
struct sched_param param;
|
|
||||||
pid_t proxy;
|
|
||||||
int errcode = OK;
|
|
||||||
#ifdef CONFIG_SCHED_WAITPID
|
|
||||||
int status;
|
|
||||||
#endif
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
svdbg("index=%d argv=%p redirfile=%s oflags=%04x\n",
|
|
||||||
index, argv, redirfile, oflags);
|
|
||||||
|
|
||||||
/* We will have to go through an intermediary/proxy task in order to
|
|
||||||
* perform the I/O redirection. This would be a natural place to fork().
|
|
||||||
* However, true fork() behavior requires an MMU and most implementations
|
|
||||||
* of vfork() are not capable of these operations.
|
|
||||||
*
|
|
||||||
* Even without fork(), we can still do the job, but parameter passing is
|
|
||||||
* messier. Unfortunately, there is no (clean) way to pass binary values
|
|
||||||
* as a task parameter, so we will use a semaphore-protected global
|
|
||||||
* structure.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Get exclusive access to the global parameter structure */
|
|
||||||
|
|
||||||
bultin_semtake(&g_builtin_parmsem);
|
|
||||||
|
|
||||||
/* Populate the parameter structure */
|
|
||||||
|
|
||||||
g_builtin_parms.redirfile = redirfile;
|
|
||||||
g_builtin_parms.argv = argv;
|
|
||||||
g_builtin_parms.result = ERROR;
|
|
||||||
g_builtin_parms.oflags = oflags;
|
|
||||||
g_builtin_parms.index = index;
|
|
||||||
|
|
||||||
/* Get the priority of this (parent) task */
|
|
||||||
|
|
||||||
ret = sched_getparam(0, ¶m);
|
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
errcode = get_errno();
|
|
||||||
sdbg("ERROR: sched_getparam failed: %d\n", errcode);
|
|
||||||
goto errout_with_sem;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Disable pre-emption so that the proxy does not run until we waitpid
|
|
||||||
* is called. This is probably unnecessary since the builtin_proxy has
|
|
||||||
* the same priority as this thread; it should be schedule behind this
|
|
||||||
* task in the ready-to-run list.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef CONFIG_SCHED_WAITPID
|
|
||||||
sched_lock();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Start the intermediary/proxy task at the same priority as the parent task. */
|
|
||||||
|
|
||||||
proxy = TASK_CREATE("builtin_proxy", param.sched_priority,
|
|
||||||
CONFIG_BUILTIN_PROXY_STACKSIZE, (main_t)builtin_proxy,
|
|
||||||
(FAR const char **)NULL);
|
|
||||||
if (proxy < 0)
|
|
||||||
{
|
|
||||||
errcode = get_errno();
|
|
||||||
sdbg("ERROR: Failed to start builtin_proxy: %d\n", errcode);
|
|
||||||
goto errout_with_lock;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Wait for the proxy to complete its job. We could use waitpid()
|
|
||||||
* for this.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef CONFIG_SCHED_WAITPID
|
|
||||||
ret = waitpid(proxy, &status, 0);
|
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
sdbg("ERROR: waitpid() failed: %d\n", get_errno());
|
|
||||||
goto errout_with_lock;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
bultin_semtake(&g_builtin_execsem);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Get the result and relinquish our access to the parameter structure */
|
|
||||||
|
|
||||||
set_errno(g_builtin_parms.errcode);
|
|
||||||
builtin_semgive(&g_builtin_parmsem);
|
|
||||||
return g_builtin_parms.result;
|
|
||||||
|
|
||||||
errout_with_lock:
|
|
||||||
#ifdef CONFIG_SCHED_WAITPID
|
|
||||||
sched_unlock();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
errout_with_sem:
|
|
||||||
set_errno(errcode);
|
|
||||||
builtin_semgive(&g_builtin_parmsem);
|
|
||||||
return ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Functions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: exec_builtin
|
|
||||||
*
|
|
||||||
* Description:
|
|
||||||
* Executes builtin applications registered during 'make context' time.
|
|
||||||
* New application is run in a separate task context (and thread).
|
|
||||||
*
|
|
||||||
* Input Parameter:
|
|
||||||
* filename - Name of the linked-in binary to be started.
|
|
||||||
* argv - Argument list
|
|
||||||
* redirfile - If output if redirected, this parameter will be non-NULL
|
|
||||||
* and will provide the full path to the file.
|
|
||||||
* oflags - If output is redirected, this parameter will provide the
|
|
||||||
* open flags to use. This will support file replacement
|
|
||||||
* of appending to an existing file.
|
|
||||||
*
|
|
||||||
* Returned Value:
|
|
||||||
* This is an end-user function, so it follows the normal convention:
|
|
||||||
* Returns the PID of the exec'ed module. On failure, it.returns
|
|
||||||
* -1 (ERROR) and sets errno appropriately.
|
|
||||||
*
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
int exec_builtin(FAR const char *appname, FAR const char **argv,
|
|
||||||
FAR const char *redirfile, int oflags)
|
|
||||||
{
|
|
||||||
int index;
|
|
||||||
int ret = ERROR;
|
|
||||||
|
|
||||||
/* Verify that an application with this name exists */
|
|
||||||
|
|
||||||
index = builtin_isavail(appname);
|
|
||||||
if (index >= 0)
|
|
||||||
{
|
|
||||||
/* Is output being redirected? */
|
|
||||||
|
|
||||||
if (redirfile)
|
|
||||||
{
|
|
||||||
ret = builtin_startproxy(index, argv, redirfile, oflags);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Start the builtin application task */
|
|
||||||
|
|
||||||
ret = builtin_taskcreate(index, argv);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Return the task ID of the new task if the task was sucessfully
|
|
||||||
* started. Otherwise, ret will be ERROR (and the errno value will
|
|
||||||
* be set appropriately).
|
|
||||||
*/
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
|
@ -1,61 +0,0 @@
|
||||||
############################################################################
|
|
||||||
# apps/builtin/registry/Makefile
|
|
||||||
#
|
|
||||||
# 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.
|
|
||||||
#
|
|
||||||
############################################################################
|
|
||||||
|
|
||||||
-include $(TOPDIR)/Make.defs
|
|
||||||
include $(APPDIR)/Make.defs
|
|
||||||
|
|
||||||
# NSH Library
|
|
||||||
|
|
||||||
all:
|
|
||||||
.PHONY: context depend clean distclean
|
|
||||||
|
|
||||||
.updated: $(DEPCONFIG)
|
|
||||||
$(call DELFILE, *.bdat)
|
|
||||||
$(call DELFILE, *.pdat)
|
|
||||||
$(Q) touch .updated
|
|
||||||
|
|
||||||
# This must run before any other context target
|
|
||||||
|
|
||||||
context: .updated
|
|
||||||
|
|
||||||
depend:
|
|
||||||
|
|
||||||
clean:
|
|
||||||
$(call CLEAN)
|
|
||||||
|
|
||||||
distclean: clean
|
|
||||||
$(call DELFILE, *.bdat)
|
|
||||||
$(call DELFILE, *.pdat)
|
|
||||||
$(call DELFILE, .updated)
|
|
|
@ -1,49 +0,0 @@
|
||||||
/** @mainpage PX4 Codebase Overview
|
|
||||||
|
|
||||||
PX4 is an open-source, open-hardware project aiming at providing a high-end autopilot to the academic, hobby and industrial communities (BSD licensed). For full documentation, refer to the official project website:
|
|
||||||
|
|
||||||
https://pixhawk.ethz.ch/px4/
|
|
||||||
|
|
||||||
Please follow the toolchain installation instructions at https://pixhawk.ethz.ch/px4/dev/px4_quickstart.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
@defgroup topics uORB Topics
|
|
||||||
|
|
||||||
Small and efficient object request broker.
|
|
||||||
|
|
||||||
The micro object request broker (uORB) is a very efficient implementation of an object
|
|
||||||
request broker following the publisher/subscriber design pattern.
|
|
||||||
|
|
||||||
It is in detail described here:
|
|
||||||
https://pixhawk.ethz.ch/px4/dev/shared_object_communication
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
@defgroup apps Onboard Applications
|
|
||||||
|
|
||||||
This is the list of the main functions of all onboard applications. The use of these
|
|
||||||
applications is documented here:
|
|
||||||
https://pixhawk.ethz.ch/px4/users/apps/start
|
|
||||||
|
|
||||||
Developer documentation of individual applications and the uORB data sharing mechanisms
|
|
||||||
are described here:
|
|
||||||
https://pixhawk.ethz.ch/px4/dev/apps/start
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
@defgroup attitude_estimation Attitude Estimation
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
@defgroup position_estimation Position Estimation
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @addtogroup topics
|
|
||||||
* @{
|
|
||||||
*/
|
|
|
@ -1,62 +0,0 @@
|
||||||
#
|
|
||||||
# For a description of the syntax of this configuration file,
|
|
||||||
# see misc/tools/kconfig-language.txt.
|
|
||||||
#
|
|
||||||
|
|
||||||
source "$APPSDIR/examples/adc/Kconfig"
|
|
||||||
source "$APPSDIR/examples/buttons/Kconfig"
|
|
||||||
source "$APPSDIR/examples/can/Kconfig"
|
|
||||||
source "$APPSDIR/examples/cdcacm/Kconfig"
|
|
||||||
source "$APPSDIR/examples/composite/Kconfig"
|
|
||||||
source "$APPSDIR/examples/cxxtest/Kconfig"
|
|
||||||
source "$APPSDIR/examples/dhcpd/Kconfig"
|
|
||||||
source "$APPSDIR/examples/elf/Kconfig"
|
|
||||||
source "$APPSDIR/examples/ftpc/Kconfig"
|
|
||||||
source "$APPSDIR/examples/ftpd/Kconfig"
|
|
||||||
source "$APPSDIR/examples/hello/Kconfig"
|
|
||||||
source "$APPSDIR/examples/helloxx/Kconfig"
|
|
||||||
source "$APPSDIR/examples/json/Kconfig"
|
|
||||||
source "$APPSDIR/examples/hidkbd/Kconfig"
|
|
||||||
source "$APPSDIR/examples/keypadtest/Kconfig"
|
|
||||||
source "$APPSDIR/examples/igmp/Kconfig"
|
|
||||||
source "$APPSDIR/examples/lcdrw/Kconfig"
|
|
||||||
source "$APPSDIR/examples/mm/Kconfig"
|
|
||||||
source "$APPSDIR/examples/mount/Kconfig"
|
|
||||||
source "$APPSDIR/examples/modbus/Kconfig"
|
|
||||||
source "$APPSDIR/examples/nettest/Kconfig"
|
|
||||||
source "$APPSDIR/examples/nsh/Kconfig"
|
|
||||||
source "$APPSDIR/examples/null/Kconfig"
|
|
||||||
source "$APPSDIR/examples/nx/Kconfig"
|
|
||||||
source "$APPSDIR/examples/nxconsole/Kconfig"
|
|
||||||
source "$APPSDIR/examples/nxffs/Kconfig"
|
|
||||||
source "$APPSDIR/examples/nxflat/Kconfig"
|
|
||||||
source "$APPSDIR/examples/nxhello/Kconfig"
|
|
||||||
source "$APPSDIR/examples/nximage/Kconfig"
|
|
||||||
source "$APPSDIR/examples/nxlines/Kconfig"
|
|
||||||
source "$APPSDIR/examples/nxtext/Kconfig"
|
|
||||||
source "$APPSDIR/examples/ostest/Kconfig"
|
|
||||||
source "$APPSDIR/examples/pashello/Kconfig"
|
|
||||||
source "$APPSDIR/examples/pipe/Kconfig"
|
|
||||||
source "$APPSDIR/examples/poll/Kconfig"
|
|
||||||
source "$APPSDIR/examples/pwm/Kconfig"
|
|
||||||
source "$APPSDIR/examples/posix_spawn/Kconfig"
|
|
||||||
source "$APPSDIR/examples/qencoder/Kconfig"
|
|
||||||
source "$APPSDIR/examples/relays/Kconfig"
|
|
||||||
source "$APPSDIR/examples/rgmp/Kconfig"
|
|
||||||
source "$APPSDIR/examples/romfs/Kconfig"
|
|
||||||
source "$APPSDIR/examples/sendmail/Kconfig"
|
|
||||||
source "$APPSDIR/examples/serloop/Kconfig"
|
|
||||||
source "$APPSDIR/examples/telnetd/Kconfig"
|
|
||||||
source "$APPSDIR/examples/thttpd/Kconfig"
|
|
||||||
source "$APPSDIR/examples/tiff/Kconfig"
|
|
||||||
source "$APPSDIR/examples/touchscreen/Kconfig"
|
|
||||||
source "$APPSDIR/examples/udp/Kconfig"
|
|
||||||
source "$APPSDIR/examples/discover/Kconfig"
|
|
||||||
source "$APPSDIR/examples/uip/Kconfig"
|
|
||||||
source "$APPSDIR/examples/usbserial/Kconfig"
|
|
||||||
source "$APPSDIR/examples/usbstorage/Kconfig"
|
|
||||||
source "$APPSDIR/examples/usbterm/Kconfig"
|
|
||||||
source "$APPSDIR/examples/watchdog/Kconfig"
|
|
||||||
source "$APPSDIR/examples/wget/Kconfig"
|
|
||||||
source "$APPSDIR/examples/wgetjson/Kconfig"
|
|
||||||
source "$APPSDIR/examples/xmlrpc/Kconfig"
|
|
|
@ -1,263 +0,0 @@
|
||||||
############################################################################
|
|
||||||
# apps/examples/Make.defs
|
|
||||||
# Adds selected applications to apps/ build
|
|
||||||
#
|
|
||||||
# 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_EXAMPLES_ADC),y)
|
|
||||||
CONFIGURED_APPS += examples/adc
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_EXAMPLES_BUTTONS),y)
|
|
||||||
CONFIGURED_APPS += examples/buttons
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_EXAMPLES_CAN),y)
|
|
||||||
CONFIGURED_APPS += examples/can
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_EXAMPLES_CDCACM),y)
|
|
||||||
CONFIGURED_APPS += examples/cdcacm
|
|
||||||
endif
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_EXAMPLES_FTPD),y)
|
|
||||||
CONFIGURED_APPS += examples/ftpd
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_EXAMPLES_HELLO),y)
|
|
||||||
CONFIGURED_APPS += examples/hello
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_EXAMPLES_HELLOXX),y)
|
|
||||||
CONFIGURED_APPS += examples/helloxx
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_EXAMPLES_HIDKBD),y)
|
|
||||||
CONFIGURED_APPS += examples/hidkbd
|
|
||||||
endif
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_EXAMPLES_NETTEST),y)
|
|
||||||
CONFIGURED_APPS += examples/nettest
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_EXAMPLES_NSH),y)
|
|
||||||
CONFIGURED_APPS += examples/nsh
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_EXAMPLES_NULL),y)
|
|
||||||
CONFIGURED_APPS += examples/null
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_EXAMPLES_NX),y)
|
|
||||||
CONFIGURED_APPS += examples/nx
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_EXAMPLES_NXCONSOLE),y)
|
|
||||||
CONFIGURED_APPS += examples/nxconsole
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_EXAMPLES_NXFFS),y)
|
|
||||||
CONFIGURED_APPS += examples/nxffs
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_EXAMPLES_NXFLAT),y)
|
|
||||||
CONFIGURED_APPS += examples/nxflat
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_EXAMPLES_NXHELLO),y)
|
|
||||||
CONFIGURED_APPS += examples/nxhello
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_EXAMPLES_NXIMAGE),y)
|
|
||||||
CONFIGURED_APPS += examples/nximage
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_EXAMPLES_NXLINES),y)
|
|
||||||
CONFIGURED_APPS += examples/nxlines
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_EXAMPLES_NXTEXT),y)
|
|
||||||
CONFIGURED_APPS += examples/nxtext
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_EXAMPLES_OSTEST),y)
|
|
||||||
CONFIGURED_APPS += examples/ostest
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_EXAMPLES_PASHELLO),y)
|
|
||||||
CONFIGURED_APPS += examples/pashello
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_EXAMPLES_PIPE),y)
|
|
||||||
CONFIGURED_APPS += examples/pipe
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_EXAMPLES_POLL),y)
|
|
||||||
CONFIGURED_APPS += examples/poll
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_EXAMPLES_PWM),y)
|
|
||||||
CONFIGURED_APPS += examples/pwm
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_EXAMPLES_POSIXSPAWN),y)
|
|
||||||
CONFIGURED_APPS += examples/posix_spawn
|
|
||||||
endif
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_EXAMPLES_ROMFS),y)
|
|
||||||
CONFIGURED_APPS += examples/romfs
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_EXAMPLES_SENDMAIL),y)
|
|
||||||
CONFIGURED_APPS += examples/sendmail
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_EXAMPLES_SERLOOP),y)
|
|
||||||
CONFIGURED_APPS += examples/serloop
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_EXAMPLES_TELNETD),y)
|
|
||||||
CONFIGURED_APPS += examples/telnetd
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_EXAMPLES_THTTPD),y)
|
|
||||||
CONFIGURED_APPS += examples/thttpd
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_EXAMPLES_TIFF),y)
|
|
||||||
CONFIGURED_APPS += examples/tiff
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_EXAMPLES_TOUCHSCREEN),y)
|
|
||||||
CONFIGURED_APPS += examples/touchscreen
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_EXAMPLES_UDP),y)
|
|
||||||
CONFIGURED_APPS += examples/udp
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_EXAMPLES_UIP),y)
|
|
||||||
CONFIGURED_APPS += examples/uip
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_EXAMPLES_USBSERIAL),y)
|
|
||||||
CONFIGURED_APPS += examples/usbserial
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_EXAMPLES_USBMSC),y)
|
|
||||||
CONFIGURED_APPS += examples/usbmsc
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_EXAMPLES_USBTERM),y)
|
|
||||||
CONFIGURED_APPS += examples/usbterm
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_EXAMPLES_WATCHDOG),y)
|
|
||||||
CONFIGURED_APPS += examples/watchdog
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_EXAMPLES_WGET),y)
|
|
||||||
CONFIGURED_APPS += examples/wget
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_EXAMPLES_WGETJSON),y)
|
|
||||||
CONFIGURED_APPS += examples/wgetjson
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_EXAMPLES_XMLRPC),y)
|
|
||||||
CONFIGURED_APPS += examples/xmlrpc
|
|
||||||
endif
|
|
|
@ -1,129 +0,0 @@
|
||||||
############################################################################
|
|
||||||
# apps/examples/Makefile
|
|
||||||
#
|
|
||||||
# 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
|
|
||||||
# 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)/.config # Current configuration
|
|
||||||
|
|
||||||
# Sub-directories
|
|
||||||
|
|
||||||
SUBDIRS = adc can cdcacm nsh
|
|
||||||
|
|
||||||
#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 posix_spawn qencoder
|
|
||||||
#SUBDIRS += relays rgmp romfs serloop telnetd thttpd tiff touchscreen udp uip
|
|
||||||
#SUBDIRS += usbserial sendmail usbstorage usbterm watchdog wget wgetjson
|
|
||||||
|
|
||||||
# Sub-directories that might need context setup. Directories may need
|
|
||||||
# context setup for a variety of reasons, but the most common is because
|
|
||||||
# the example may be built as an NSH built-in function.
|
|
||||||
#
|
|
||||||
# Directories that may be built as NSH built-in functions may have their
|
|
||||||
# own configuration setting (like CONFIG_EXAMPLES_HELLOXX_BUILTIN), but
|
|
||||||
# many only depend on the generic CONFIG_NSH_BUILTIN_APPS setting. And
|
|
||||||
# there a few which an ONLY be built as NSH built-in applications; these
|
|
||||||
# are included in the list unconditionally.
|
|
||||||
|
|
||||||
CNTXTDIRS = pwm
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
|
|
||||||
|
|
||||||
CNTXTDIRS += adc can cdcacm
|
|
||||||
|
|
||||||
#CNTXTDIRS += adc can cdcacm composite cxxtest dhcpd discover ftpd hello json
|
|
||||||
#CNTXTDIRS += keypadtestmodbus nettest nxlines relays qencoder telnetd watchdog
|
|
||||||
#CNTXTDIRS += wgetjson
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_EXAMPLES_HELLOXX_BUILTIN),y)
|
|
||||||
CNTXTDIRS += helloxx
|
|
||||||
endif
|
|
||||||
ifeq ($(CONFIG_EXAMPLES_LCDRW_BUILTIN),y)
|
|
||||||
CNTXTDIRS += lcdrw
|
|
||||||
endif
|
|
||||||
ifeq ($(CONFIG_EXAMPLES_NX_BUILTIN),y)
|
|
||||||
CNTXTDIRS += nx
|
|
||||||
endif
|
|
||||||
ifeq ($(CONFIG_EXAMPLES_NXHELLO_BUILTIN),y)
|
|
||||||
CNTXTDIRS += nxhello
|
|
||||||
endif
|
|
||||||
ifeq ($(CONFIG_EXAMPLES_NXIMAGE_BUILTIN),y)
|
|
||||||
CNTXTDIRS += nximage
|
|
||||||
endif
|
|
||||||
ifeq ($(CONFIG_EXAMPLES_NXTEXT_BUILTIN),y)
|
|
||||||
CNTXTDIRS += nxtext
|
|
||||||
endif
|
|
||||||
ifeq ($(CONFIG_EXAMPLES_OSTEST_BUILTIN),y)
|
|
||||||
CNTXTDIRS += ostest
|
|
||||||
endif
|
|
||||||
ifeq ($(CONFIG_EXAMPLES_TIFF_BUILTIN),y)
|
|
||||||
CNTXTDIRS += tiff
|
|
||||||
endif
|
|
||||||
ifeq ($(CONFIG_EXAMPLES_TOUCHSCREEN_BUILTIN),y)
|
|
||||||
CNTXTDIRS += touchscreen
|
|
||||||
endif
|
|
||||||
ifeq ($(CONFIG_EXAMPLES_USBMSC_BUILTIN),y)
|
|
||||||
CNTXTDIRS += usbstorage
|
|
||||||
endif
|
|
||||||
ifeq ($(CONFIG_EXAMPLES_USBTERM_BUILTIN),y)
|
|
||||||
CNTXTDIRS += usbterm
|
|
||||||
endif
|
|
||||||
|
|
||||||
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: $(foreach SDIR, $(CNTXTDIRS), $(SDIR)_context)
|
|
||||||
|
|
||||||
depend: $(foreach SDIR, $(SUBDIRS), $(SDIR)_depend)
|
|
||||||
|
|
||||||
clean: $(foreach SDIR, $(SUBDIRS), $(SDIR)_clean)
|
|
||||||
|
|
||||||
distclean: $(foreach SDIR, $(SUBDIRS), $(SDIR)_distclean)
|
|
||||||
|
|
||||||
-include Make.dep
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,37 +0,0 @@
|
||||||
#
|
|
||||||
# For a description of the syntax of this configuration file,
|
|
||||||
# see misc/tools/kconfig-language.txt.
|
|
||||||
#
|
|
||||||
|
|
||||||
config EXAMPLES_ADC
|
|
||||||
bool "ADC example"
|
|
||||||
default n
|
|
||||||
depends on ADC
|
|
||||||
---help---
|
|
||||||
Enable the ADC example
|
|
||||||
|
|
||||||
if EXAMPLES_ADC
|
|
||||||
|
|
||||||
config EXAMPLES_ADC_DEVPATH
|
|
||||||
string "ADC device path"
|
|
||||||
default "/dev/adc0"
|
|
||||||
---help---
|
|
||||||
The default path to the ADC device. Default: /dev/adc0
|
|
||||||
|
|
||||||
config EXAMPLES_ADC_NSAMPLES
|
|
||||||
int "Number of Sample Groups"
|
|
||||||
default 0
|
|
||||||
depends on !NSH_BUILTIN_APPS
|
|
||||||
---help---
|
|
||||||
If 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: 0 (samples
|
|
||||||
are collected indefinitely).
|
|
||||||
|
|
||||||
config EXAMPLES_ADC_GROUPSIZE
|
|
||||||
int "Number of Samples per Group"
|
|
||||||
default 4
|
|
||||||
---help---
|
|
||||||
The number of samples to read at once. Default: 4
|
|
||||||
|
|
||||||
endif
|
|
|
@ -1,109 +0,0 @@
|
||||||
############################################################################
|
|
||||||
# apps/examples/adc/Makefile
|
|
||||||
#
|
|
||||||
# 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
|
|
||||||
# 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)/.config
|
|
||||||
-include $(TOPDIR)/Make.defs
|
|
||||||
include $(APPDIR)/Make.defs
|
|
||||||
|
|
||||||
# NuttX NX Graphics Example.
|
|
||||||
|
|
||||||
ASRCS =
|
|
||||||
CSRCS = adc_main.c
|
|
||||||
|
|
||||||
AOBJS = $(ASRCS:.S=$(OBJEXT))
|
|
||||||
COBJS = $(CSRCS:.c=$(OBJEXT))
|
|
||||||
|
|
||||||
SRCS = $(ASRCS) $(CSRCS)
|
|
||||||
OBJS = $(AOBJS) $(COBJS)
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
|
|
||||||
BIN = ..\..\libapps$(LIBEXT)
|
|
||||||
else
|
|
||||||
ifeq ($(WINTOOL),y)
|
|
||||||
BIN = ..\\..\\libapps$(LIBEXT)
|
|
||||||
else
|
|
||||||
BIN = ../../libapps$(LIBEXT)
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
ROOTDEPPATH = --dep-path .
|
|
||||||
|
|
||||||
# Touchscreen built-in application info
|
|
||||||
|
|
||||||
APPNAME = adc
|
|
||||||
PRIORITY = SCHED_PRIORITY_DEFAULT
|
|
||||||
STACKSIZE = 2048
|
|
||||||
|
|
||||||
# Common build
|
|
||||||
|
|
||||||
VPATH =
|
|
||||||
|
|
||||||
all: .built
|
|
||||||
.PHONY: context clean depend distclean
|
|
||||||
|
|
||||||
$(AOBJS): %$(OBJEXT): %.S
|
|
||||||
$(call ASSEMBLE, $<, $@)
|
|
||||||
|
|
||||||
$(COBJS): %$(OBJEXT): %.c
|
|
||||||
$(call COMPILE, $<, $@)
|
|
||||||
|
|
||||||
.built: $(OBJS)
|
|
||||||
$(call ARCHIVE, $(BIN), $(OBJS))
|
|
||||||
@touch .built
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
|
|
||||||
$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile
|
|
||||||
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
|
|
||||||
|
|
||||||
context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat
|
|
||||||
else
|
|
||||||
context:
|
|
||||||
endif
|
|
||||||
|
|
||||||
.depend: Makefile $(SRCS)
|
|
||||||
@$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
|
|
||||||
@touch $@
|
|
||||||
|
|
||||||
depend: .depend
|
|
||||||
|
|
||||||
clean:
|
|
||||||
$(call DELFILE, .built)
|
|
||||||
$(call CLEAN)
|
|
||||||
|
|
||||||
distclean: clean
|
|
||||||
$(call DELFILE, Make.dep)
|
|
||||||
$(call DELFILE, .depend)
|
|
||||||
|
|
||||||
-include Make.dep
|
|
|
@ -1,125 +0,0 @@
|
||||||
/****************************************************************************
|
|
||||||
* examples/examples/adc/adc.h
|
|
||||||
*
|
|
||||||
* Copyright (C) 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.
|
|
||||||
*
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#ifndef __APPS_EXAMPLES_ADC_ADC_H
|
|
||||||
#define __APPS_EXAMPLES_ADC_ADC_H
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Included Files
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#include <nuttx/config.h>
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Definitions
|
|
||||||
****************************************************************************/
|
|
||||||
/* Configuration ************************************************************/
|
|
||||||
/* CONFIG_NSH_BUILTIN_APPS - Build the ADC test as an NSH built-in function.
|
|
||||||
* Default: Built as a standalone problem
|
|
||||||
* CONFIG_EXAMPLES_ADC_DEVPATH - The default path to the ADC device. Default: /dev/adc0
|
|
||||||
* CONFIG_EXAMPLES_ADC_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_ADC_GROUPSIZE - The number of samples to read at once.
|
|
||||||
* Default: 4
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef CONFIG_ADC
|
|
||||||
# error "ADC device support is not enabled (CONFIG_ADC)"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef CONFIG_EXAMPLES_ADC_DEVPATH
|
|
||||||
# define CONFIG_EXAMPLES_ADC_DEVPATH "/dev/adc0"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef CONFIG_EXAMPLES_ADC_GROUPSIZE
|
|
||||||
# define CONFIG_EXAMPLES_ADC_GROUPSIZE 4
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Debug ********************************************************************/
|
|
||||||
|
|
||||||
#ifdef CONFIG_CPP_HAVE_VARARGS
|
|
||||||
# ifdef CONFIG_DEBUG
|
|
||||||
# define message(...) syslog(__VA_ARGS__)
|
|
||||||
# define msgflush()
|
|
||||||
# else
|
|
||||||
# define message(...) printf(__VA_ARGS__)
|
|
||||||
# define msgflush() fflush(stdout)
|
|
||||||
# endif
|
|
||||||
#else
|
|
||||||
# ifdef CONFIG_DEBUG
|
|
||||||
# define message syslog
|
|
||||||
# define msgflush()
|
|
||||||
# else
|
|
||||||
# define message printf
|
|
||||||
# define msgflush() fflush(stdout)
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Types
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
struct adc_state_s
|
|
||||||
{
|
|
||||||
bool initialized;
|
|
||||||
FAR char *devpath;
|
|
||||||
#if defined(CONFIG_NSH_BUILTIN_APPS) || defined(CONFIG_EXAMPLES_ADC_NSAMPLES)
|
|
||||||
int count;
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Variables
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Function Prototypes
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: adc_devinit()
|
|
||||||
*
|
|
||||||
* Description:
|
|
||||||
* Perform architecuture-specific initialization of the ADC hardware. This
|
|
||||||
* interface must be provided by all configurations using apps/examples/adc
|
|
||||||
*
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
int adc_devinit(void);
|
|
||||||
|
|
||||||
#endif /* __APPS_EXAMPLES_ADC_ADC_H */
|
|
|
@ -1,372 +0,0 @@
|
||||||
/****************************************************************************
|
|
||||||
* examples/adc/adc_main.c
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
* 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 <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <debug.h>
|
|
||||||
|
|
||||||
#include <nuttx/analog/adc.h>
|
|
||||||
|
|
||||||
#include "adc.h"
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Pre-processor Definitions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/* Use CONFIG_EXAMPLES_ADC_NSAMPLES == 0 to mean to collect samples
|
|
||||||
* indefinitely.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef CONFIG_EXAMPLES_ADC_NSAMPLES
|
|
||||||
# define CONFIG_EXAMPLES_ADC_NSAMPLES 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Types
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Function Prototypes
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Data
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static struct adc_state_s g_adcstate;
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Data
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Functions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: adc_devpath
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static void adc_devpath(FAR struct adc_state_s *adc, FAR const char *devpath)
|
|
||||||
{
|
|
||||||
/* Get rid of any old device path */
|
|
||||||
|
|
||||||
if (adc->devpath)
|
|
||||||
{
|
|
||||||
free(adc->devpath);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Then set-up the new device path by copying the string */
|
|
||||||
|
|
||||||
adc->devpath = strdup(devpath);
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: adc_help
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#ifdef CONFIG_NSH_BUILTIN_APPS
|
|
||||||
static void adc_help(FAR struct adc_state_s *adc)
|
|
||||||
{
|
|
||||||
message("Usage: adc [OPTIONS]\n");
|
|
||||||
message("\nArguments are \"sticky\". For example, once the ADC device is\n");
|
|
||||||
message("specified, that device will be re-used until it is changed.\n");
|
|
||||||
message("\n\"sticky\" OPTIONS include:\n");
|
|
||||||
message(" [-p devpath] selects the ADC device. "
|
|
||||||
"Default: %s Current: %s\n",
|
|
||||||
CONFIG_EXAMPLES_ADC_DEVPATH, g_adcstate.devpath ? g_adcstate.devpath : "NONE");
|
|
||||||
message(" [-n count] selects the samples to collect. "
|
|
||||||
"Default: 1 Current: %d\n", adc->count);
|
|
||||||
message(" [-h] shows this message and exits\n");
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: arg_string
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#ifdef CONFIG_NSH_BUILTIN_APPS
|
|
||||||
static int arg_string(FAR char **arg, FAR char **value)
|
|
||||||
{
|
|
||||||
FAR char *ptr = *arg;
|
|
||||||
|
|
||||||
if (ptr[2] == '\0')
|
|
||||||
{
|
|
||||||
*value = arg[1];
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
*value = &ptr[2];
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: arg_decimal
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#ifdef CONFIG_NSH_BUILTIN_APPS
|
|
||||||
static int arg_decimal(FAR char **arg, FAR long *value)
|
|
||||||
{
|
|
||||||
FAR char *string;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
ret = arg_string(arg, &string);
|
|
||||||
*value = strtol(string, NULL, 10);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: parse_args
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#ifdef CONFIG_NSH_BUILTIN_APPS
|
|
||||||
static void parse_args(FAR struct adc_state_s *adc, int argc, FAR char **argv)
|
|
||||||
{
|
|
||||||
FAR char *ptr;
|
|
||||||
FAR char *str;
|
|
||||||
long value;
|
|
||||||
int index;
|
|
||||||
int nargs;
|
|
||||||
|
|
||||||
for (index = 1; index < argc; )
|
|
||||||
{
|
|
||||||
ptr = argv[index];
|
|
||||||
if (ptr[0] != '-')
|
|
||||||
{
|
|
||||||
message("Invalid options format: %s\n", ptr);
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (ptr[1])
|
|
||||||
{
|
|
||||||
case 'n':
|
|
||||||
nargs = arg_decimal(&argv[index], &value);
|
|
||||||
if (value < 0)
|
|
||||||
{
|
|
||||||
message("Count must be non-negative: %ld\n", value);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
adc->count = (uint32_t)value;
|
|
||||||
index += nargs;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'p':
|
|
||||||
nargs = arg_string(&argv[index], &str);
|
|
||||||
adc_devpath(adc, str);
|
|
||||||
index += nargs;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'h':
|
|
||||||
adc_help(adc);
|
|
||||||
exit(0);
|
|
||||||
|
|
||||||
default:
|
|
||||||
message("Unsupported option: %s\n", ptr);
|
|
||||||
adc_help(adc);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Functions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: adc_main
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
int adc_main(int argc, char *argv[])
|
|
||||||
{
|
|
||||||
struct adc_msg_s sample[CONFIG_EXAMPLES_ADC_GROUPSIZE];
|
|
||||||
size_t readsize;
|
|
||||||
ssize_t nbytes;
|
|
||||||
int fd;
|
|
||||||
int errval = 0;
|
|
||||||
int ret;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
/* Check if we have initialized */
|
|
||||||
|
|
||||||
if (!g_adcstate.initialized)
|
|
||||||
{
|
|
||||||
/* Initialization of the ADC hardware is performed by logic external to
|
|
||||||
* this test.
|
|
||||||
*/
|
|
||||||
|
|
||||||
message("adc_main: Initializing external ADC device\n");
|
|
||||||
ret = adc_devinit();
|
|
||||||
if (ret != OK)
|
|
||||||
{
|
|
||||||
message("adc_main: adc_devinit failed: %d\n", ret);
|
|
||||||
errval = 1;
|
|
||||||
goto errout;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Set the default values */
|
|
||||||
|
|
||||||
adc_devpath(&g_adcstate, CONFIG_EXAMPLES_ADC_DEVPATH);
|
|
||||||
|
|
||||||
#if CONFIG_EXAMPLES_ADC_NSAMPLES > 0
|
|
||||||
g_adcstate.count = CONFIG_EXAMPLES_ADC_NSAMPLES;
|
|
||||||
#else
|
|
||||||
g_adcstate.count = 1;
|
|
||||||
#endif
|
|
||||||
g_adcstate.initialized = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Parse the command line */
|
|
||||||
|
|
||||||
#ifdef CONFIG_NSH_BUILTIN_APPS
|
|
||||||
parse_args(&g_adcstate, argc, argv);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* If this example is configured as an NX add-on, then limit the number of
|
|
||||||
* samples that we collect before returning. Otherwise, we never return
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if defined(CONFIG_NSH_BUILTIN_APPS) || CONFIG_EXAMPLES_ADC_NSAMPLES > 0
|
|
||||||
message("adc_main: g_adcstate.count: %d\n", g_adcstate.count);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Open the ADC device for reading */
|
|
||||||
|
|
||||||
message("adc_main: Hardware initialized. Opening the ADC device: %s\n",
|
|
||||||
g_adcstate.devpath);
|
|
||||||
|
|
||||||
fd = open(g_adcstate.devpath, O_RDONLY);
|
|
||||||
if (fd < 0)
|
|
||||||
{
|
|
||||||
message("adc_main: open %s failed: %d\n", g_adcstate.devpath, errno);
|
|
||||||
errval = 2;
|
|
||||||
goto errout;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Now loop the appropriate number of times, displaying the collected
|
|
||||||
* ADC samples.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if defined(CONFIG_NSH_BUILTIN_APPS)
|
|
||||||
for (; g_adcstate.count > 0; g_adcstate.count--)
|
|
||||||
#elif CONFIG_EXAMPLES_ADC_NSAMPLES > 0
|
|
||||||
for (g_adcstate.count = 0; g_adcstate.count < CONFIG_EXAMPLES_ADC_NSAMPLES; g_adcstate.count++)
|
|
||||||
#else
|
|
||||||
for (;;)
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
/* Flush any output before the loop entered or from the previous pass
|
|
||||||
* through the loop.
|
|
||||||
*/
|
|
||||||
|
|
||||||
msgflush();
|
|
||||||
|
|
||||||
/* Read CONFIG_EXAMPLES_ADC_GROUPSIZE samples */
|
|
||||||
|
|
||||||
readsize = CONFIG_EXAMPLES_ADC_GROUPSIZE * sizeof(struct adc_msg_s);
|
|
||||||
nbytes = read(fd, sample, readsize);
|
|
||||||
|
|
||||||
/* Handle unexpected return values */
|
|
||||||
|
|
||||||
if (nbytes < 0)
|
|
||||||
{
|
|
||||||
errval = errno;
|
|
||||||
if (errval != EINTR)
|
|
||||||
{
|
|
||||||
message("adc_main: read %s failed: %d\n",
|
|
||||||
g_adcstate.devpath, errval);
|
|
||||||
errval = 3;
|
|
||||||
goto errout_with_dev;
|
|
||||||
}
|
|
||||||
|
|
||||||
message("adc_main: Interrupted read...\n");
|
|
||||||
}
|
|
||||||
else if (nbytes == 0)
|
|
||||||
{
|
|
||||||
message("adc_main: No data read, Ignoring\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Print the sample data on successful return */
|
|
||||||
|
|
||||||
else
|
|
||||||
{
|
|
||||||
int nsamples = nbytes / sizeof(struct adc_msg_s);
|
|
||||||
if (nsamples * sizeof(struct adc_msg_s) != nbytes)
|
|
||||||
{
|
|
||||||
message("adc_main: read size=%d is not a multiple of sample size=%d, Ignoring\n",
|
|
||||||
nbytes, sizeof(struct adc_msg_s));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
message("Sample:\n");
|
|
||||||
for (i = 0; i < nsamples ; i++)
|
|
||||||
{
|
|
||||||
message("%d: channel: %d value: %d\n",
|
|
||||||
i, sample[i].am_channel, sample[i].am_data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
close(fd);
|
|
||||||
return OK;
|
|
||||||
|
|
||||||
/* Error exits */
|
|
||||||
|
|
||||||
errout_with_dev:
|
|
||||||
close(fd);
|
|
||||||
|
|
||||||
errout:
|
|
||||||
message("Terminating!\n");
|
|
||||||
msgflush();
|
|
||||||
return errval;
|
|
||||||
}
|
|
|
@ -1,63 +0,0 @@
|
||||||
#
|
|
||||||
# For a description of the syntax of this configuration file,
|
|
||||||
# see misc/tools/kconfig-language.txt.
|
|
||||||
#
|
|
||||||
|
|
||||||
config EXAMPLES_BUTTONS
|
|
||||||
bool "Buttons example"
|
|
||||||
default n
|
|
||||||
---help---
|
|
||||||
Enable the buttons example. May require ARCH_BUTTONS on some boards.
|
|
||||||
|
|
||||||
if EXAMPLES_BUTTONS
|
|
||||||
config EXAMPLES_BUTTONS_MIN
|
|
||||||
int "Lowest Button Number"
|
|
||||||
default 0
|
|
||||||
|
|
||||||
config EXAMPLES_BUTTONS_MAX
|
|
||||||
int "Highest Button Number"
|
|
||||||
default 7
|
|
||||||
|
|
||||||
if ARCH_IRQBUTTONS
|
|
||||||
config EXAMPLES_IRQBUTTONS_MIN
|
|
||||||
int "Lowest Interrupting Button Number"
|
|
||||||
default 0
|
|
||||||
|
|
||||||
config EXAMPLES_IRQBUTTONS_MAX
|
|
||||||
int "Highest Interrupting Button Number"
|
|
||||||
default 7
|
|
||||||
|
|
||||||
config EXAMPLES_BUTTONS_NAME0
|
|
||||||
string "Button 0 Name"
|
|
||||||
default "Button 0"
|
|
||||||
|
|
||||||
config EXAMPLES_BUTTONS_NAME1
|
|
||||||
string "Button 1 Name"
|
|
||||||
default "Button 1"
|
|
||||||
|
|
||||||
config EXAMPLES_BUTTONS_NAME2
|
|
||||||
string "Button 2 Name"
|
|
||||||
default "Button 2"
|
|
||||||
|
|
||||||
config EXAMPLES_BUTTONS_NAME3
|
|
||||||
string "Button 3 Name"
|
|
||||||
default "Button 3"
|
|
||||||
|
|
||||||
config EXAMPLES_BUTTONS_NAME4
|
|
||||||
string "Button 4 Name"
|
|
||||||
default "Button 4"
|
|
||||||
|
|
||||||
config EXAMPLES_BUTTONS_NAME5
|
|
||||||
string "Button 5 Name"
|
|
||||||
default "Button 5"
|
|
||||||
|
|
||||||
config EXAMPLES_BUTTONS_NAME6
|
|
||||||
string "Button 6 Name"
|
|
||||||
default "Button 6"
|
|
||||||
|
|
||||||
config EXAMPLES_BUTTONS_NAME7
|
|
||||||
string "Button 7 Name"
|
|
||||||
default "Button 7"
|
|
||||||
|
|
||||||
endif
|
|
||||||
endif
|
|
|
@ -1,109 +0,0 @@
|
||||||
############################################################################
|
|
||||||
# apps/examples/buttons/Makefile
|
|
||||||
#
|
|
||||||
# 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
|
|
||||||
# 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)/.config
|
|
||||||
-include $(TOPDIR)/Make.defs
|
|
||||||
include $(APPDIR)/Make.defs
|
|
||||||
|
|
||||||
# Hello, World! Example
|
|
||||||
|
|
||||||
ASRCS =
|
|
||||||
CSRCS = buttons_main.c
|
|
||||||
|
|
||||||
AOBJS = $(ASRCS:.S=$(OBJEXT))
|
|
||||||
COBJS = $(CSRCS:.c=$(OBJEXT))
|
|
||||||
|
|
||||||
SRCS = $(ASRCS) $(CSRCS)
|
|
||||||
OBJS = $(AOBJS) $(COBJS)
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
|
|
||||||
BIN = ..\..\libapps$(LIBEXT)
|
|
||||||
else
|
|
||||||
ifeq ($(WINTOOL),y)
|
|
||||||
BIN = ..\\..\\libapps$(LIBEXT)
|
|
||||||
else
|
|
||||||
BIN = ../../libapps$(LIBEXT)
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
ROOTDEPPATH = --dep-path .
|
|
||||||
|
|
||||||
# Buttons built-in application info
|
|
||||||
|
|
||||||
APPNAME = buttons
|
|
||||||
PRIORITY = SCHED_PRIORITY_DEFAULT
|
|
||||||
STACKSIZE = 2048
|
|
||||||
|
|
||||||
# Common build
|
|
||||||
|
|
||||||
VPATH =
|
|
||||||
|
|
||||||
all: .built
|
|
||||||
.PHONY: context clean depend distclean
|
|
||||||
|
|
||||||
$(AOBJS): %$(OBJEXT): %.S
|
|
||||||
$(call ASSEMBLE, $<, $@)
|
|
||||||
|
|
||||||
$(COBJS): %$(OBJEXT): %.c
|
|
||||||
$(call COMPILE, $<, $@)
|
|
||||||
|
|
||||||
.built: $(OBJS)
|
|
||||||
$(call ARCHIVE, $(BIN), $(OBJS))
|
|
||||||
@touch .built
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
|
|
||||||
$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile
|
|
||||||
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
|
|
||||||
|
|
||||||
context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat
|
|
||||||
else
|
|
||||||
context:
|
|
||||||
endif
|
|
||||||
|
|
||||||
.depend: Makefile $(SRCS)
|
|
||||||
@$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
|
|
||||||
@touch $@
|
|
||||||
|
|
||||||
depend: .depend
|
|
||||||
|
|
||||||
clean:
|
|
||||||
$(call DELFILE, .built)
|
|
||||||
$(call CLEAN)
|
|
||||||
|
|
||||||
distclean: clean
|
|
||||||
$(call DELFILE, Make.dep)
|
|
||||||
$(call DELFILE, .depend)
|
|
||||||
|
|
||||||
-include Make.dep
|
|
|
@ -1,499 +0,0 @@
|
||||||
/****************************************************************************
|
|
||||||
* examples/buttons/buttons_main.c
|
|
||||||
*
|
|
||||||
* Copyright (C) 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.
|
|
||||||
*
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* NOTE: This test exercises internal button driver interfaces. As such, it
|
|
||||||
* 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).
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Included Files
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#include <nuttx/config.h>
|
|
||||||
#include <nuttx/arch.h>
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <debug.h>
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Definitions
|
|
||||||
****************************************************************************/
|
|
||||||
/* Configuration ************************************************************/
|
|
||||||
|
|
||||||
#ifndef CONFIG_ARCH_BUTTONS
|
|
||||||
# error "CONFIG_ARCH_BUTTONS is not defined in the configuration"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef CONFIG_EXAMPLES_BUTTONS_NAME0
|
|
||||||
# define CONFIG_EXAMPLES_BUTTONS_NAME0 "BUTTON0"
|
|
||||||
#endif
|
|
||||||
#ifndef CONFIG_EXAMPLES_BUTTONS_NAME1
|
|
||||||
# define CONFIG_EXAMPLES_BUTTONS_NAME1 "BUTTON1"
|
|
||||||
#endif
|
|
||||||
#ifndef CONFIG_EXAMPLES_BUTTONS_NAME2
|
|
||||||
# define CONFIG_EXAMPLES_BUTTONS_NAME2 "BUTTON2"
|
|
||||||
#endif
|
|
||||||
#ifndef CONFIG_EXAMPLES_BUTTONS_NAME3
|
|
||||||
# define CONFIG_EXAMPLES_BUTTONS_NAME3 "BUTTON3"
|
|
||||||
#endif
|
|
||||||
#ifndef CONFIG_EXAMPLES_BUTTONS_NAME4
|
|
||||||
# define CONFIG_EXAMPLES_BUTTONS_NAME4 "BUTTON4"
|
|
||||||
#endif
|
|
||||||
#ifndef CONFIG_EXAMPLES_BUTTONS_NAME5
|
|
||||||
# define CONFIG_EXAMPLES_BUTTONS_NAME5 "BUTTON5"
|
|
||||||
#endif
|
|
||||||
#ifndef CONFIG_EXAMPLES_BUTTONS_NAME6
|
|
||||||
# define CONFIG_EXAMPLES_BUTTONS_NAME6 "BUTTON6"
|
|
||||||
#endif
|
|
||||||
#ifndef CONFIG_EXAMPLES_BUTTONS_NAME7
|
|
||||||
# define CONFIG_EXAMPLES_BUTTONS_NAME7 "BUTTON7"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define BUTTON_MIN 0
|
|
||||||
#define BUTTON_MAX 7
|
|
||||||
|
|
||||||
#ifndef CONFIG_EXAMPLES_BUTTONS_MIN
|
|
||||||
# define CONFIG_EXAMPLES_BUTTONS_MIN BUTTON_MIN
|
|
||||||
#endif
|
|
||||||
#ifndef CONFIG_EXAMPLES_BUTTONS_MAX
|
|
||||||
# define CONFIG_EXAMPLES_BUTTONS_MAX BUTTON_MAX
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if CONFIG_EXAMPLES_BUTTONS_MIN > CONFIG_EXAMPLES_BUTTONS_MAX
|
|
||||||
# error "CONFIG_EXAMPLES_BUTTONS_MIN > CONFIG_EXAMPLES_BUTTONS_MAX"
|
|
||||||
#endif
|
|
||||||
#if CONFIG_EXAMPLES_BUTTONS_MAX > 7
|
|
||||||
# error "CONFIG_EXAMPLES_BUTTONS_MAX > 7"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef CONFIG_EXAMPLES_IRQBUTTONS_MIN
|
|
||||||
# define CONFIG_EXAMPLES_IRQBUTTONS_MIN CONFIG_EXAMPLES_BUTTONS_MIN
|
|
||||||
#endif
|
|
||||||
#ifndef CONFIG_EXAMPLES_IRQBUTTONS_MAX
|
|
||||||
# define CONFIG_EXAMPLES_IRQBUTTONS_MAX CONFIG_EXAMPLES_BUTTONS_MAX
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if CONFIG_EXAMPLES_IRQBUTTONS_MIN > CONFIG_EXAMPLES_IRQBUTTONS_MAX
|
|
||||||
# error "CONFIG_EXAMPLES_IRQBUTTONS_MIN > CONFIG_EXAMPLES_IRQBUTTONS_MAX"
|
|
||||||
#endif
|
|
||||||
#if CONFIG_EXAMPLES_IRQBUTTONS_MAX > 7
|
|
||||||
# error "CONFIG_EXAMPLES_IRQBUTTONS_MAX > 7"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef MIN
|
|
||||||
# define MIN(a,b) (a < b ? a : b)
|
|
||||||
#endif
|
|
||||||
#ifndef MAX
|
|
||||||
# define MAX(a,b) (a > b ? a : b)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define MIN_BUTTON MIN(CONFIG_EXAMPLES_BUTTONS_MIN, CONFIG_EXAMPLES_IRQBUTTONS_MIN)
|
|
||||||
#define MAX_BUTTON MAX(CONFIG_EXAMPLES_BUTTONS_MAX, CONFIG_EXAMPLES_IRQBUTTONS_MAX)
|
|
||||||
|
|
||||||
#define NUM_BUTTONS (MAX_BUTTON - MIN_BUTTON + 1)
|
|
||||||
#define BUTTON_INDEX(b) ((b)-MIN_BUTTON)
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Types
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
struct button_info_s
|
|
||||||
{
|
|
||||||
FAR const char *name; /* Name for the button */
|
|
||||||
#ifdef CONFIG_ARCH_IRQBUTTONS
|
|
||||||
xcpt_t handler; /* Button interrupt handler */
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Function Prototypes
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static void show_buttons(uint8_t oldset, uint8_t newset);
|
|
||||||
|
|
||||||
#ifdef CONFIG_ARCH_IRQBUTTONS
|
|
||||||
static void button_handler(int id, int irq);
|
|
||||||
|
|
||||||
#if MIN_BUTTON < 1
|
|
||||||
static int button0_handler(int irq, FAR void *context);
|
|
||||||
#endif
|
|
||||||
#if MIN_BUTTON < 2 && MAX_BUTTON > 0
|
|
||||||
static int button1_handler(int irq, FAR void *context);
|
|
||||||
#endif
|
|
||||||
#if MIN_BUTTON < 3 && MAX_BUTTON > 1
|
|
||||||
static int button2_handler(int irq, FAR void *context);
|
|
||||||
#endif
|
|
||||||
#if MIN_BUTTON < 4 && MAX_BUTTON > 2
|
|
||||||
static int button3_handler(int irq, FAR void *context);
|
|
||||||
#endif
|
|
||||||
#if MIN_BUTTON < 5 && MAX_BUTTON > 3
|
|
||||||
static int button4_handler(int irq, FAR void *context);
|
|
||||||
#endif
|
|
||||||
#if MIN_BUTTON < 6 && MAX_BUTTON > 4
|
|
||||||
static int button5_handler(int irq, FAR void *context);
|
|
||||||
#endif
|
|
||||||
#if MIN_BUTTON < 7 && MAX_BUTTON > 5
|
|
||||||
static int button6_handler(int irq, FAR void *context);
|
|
||||||
#endif
|
|
||||||
#if MAX_BUTTON > 6
|
|
||||||
static int button7_handler(int irq, FAR void *context);
|
|
||||||
#endif
|
|
||||||
#endif /* CONFIG_ARCH_IRQBUTTONS */
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Data
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/* Button Names */
|
|
||||||
|
|
||||||
static const struct button_info_s g_buttoninfo[NUM_BUTTONS] =
|
|
||||||
{
|
|
||||||
#if MIN_BUTTON < 1
|
|
||||||
{
|
|
||||||
CONFIG_EXAMPLES_BUTTONS_NAME0,
|
|
||||||
#ifdef CONFIG_ARCH_IRQBUTTONS
|
|
||||||
button0_handler
|
|
||||||
#endif
|
|
||||||
},
|
|
||||||
#endif
|
|
||||||
#if MIN_BUTTON < 2 && MAX_BUTTON > 0
|
|
||||||
{
|
|
||||||
CONFIG_EXAMPLES_BUTTONS_NAME1,
|
|
||||||
#ifdef CONFIG_ARCH_IRQBUTTONS
|
|
||||||
button1_handler
|
|
||||||
#endif
|
|
||||||
},
|
|
||||||
#endif
|
|
||||||
#if MIN_BUTTON < 3 && MAX_BUTTON > 1
|
|
||||||
{
|
|
||||||
CONFIG_EXAMPLES_BUTTONS_NAME2,
|
|
||||||
#ifdef CONFIG_ARCH_IRQBUTTONS
|
|
||||||
button2_handler
|
|
||||||
#endif
|
|
||||||
},
|
|
||||||
#endif
|
|
||||||
#if MIN_BUTTON < 4 && MAX_BUTTON > 2
|
|
||||||
{
|
|
||||||
CONFIG_EXAMPLES_BUTTONS_NAME3,
|
|
||||||
#ifdef CONFIG_ARCH_IRQBUTTONS
|
|
||||||
button3_handler
|
|
||||||
#endif
|
|
||||||
},
|
|
||||||
#endif
|
|
||||||
#if MIN_BUTTON < 5 && MAX_BUTTON > 3
|
|
||||||
{
|
|
||||||
CONFIG_EXAMPLES_BUTTONS_NAME4,
|
|
||||||
#ifdef CONFIG_ARCH_IRQBUTTONS
|
|
||||||
button4_handler
|
|
||||||
#endif
|
|
||||||
},
|
|
||||||
#endif
|
|
||||||
#if MIN_BUTTON < 6 && MAX_BUTTON > 4
|
|
||||||
{
|
|
||||||
CONFIG_EXAMPLES_BUTTONS_NAME5,
|
|
||||||
#ifdef CONFIG_ARCH_IRQBUTTONS
|
|
||||||
button5_handler
|
|
||||||
#endif
|
|
||||||
},
|
|
||||||
#endif
|
|
||||||
#if MIN_BUTTON < 7 && MAX_BUTTON > 5
|
|
||||||
{
|
|
||||||
CONFIG_EXAMPLES_BUTTONS_NAME6,
|
|
||||||
#ifdef CONFIG_ARCH_IRQBUTTONS
|
|
||||||
button6_handler
|
|
||||||
#endif
|
|
||||||
},
|
|
||||||
#endif
|
|
||||||
#if MAX_BUTTON > 6
|
|
||||||
{
|
|
||||||
CONFIG_EXAMPLES_BUTTONS_NAME7,
|
|
||||||
#ifdef CONFIG_ARCH_IRQBUTTONS
|
|
||||||
button7_handler
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Last sampled button set */
|
|
||||||
|
|
||||||
static uint8_t g_oldset;
|
|
||||||
|
|
||||||
/* Used to limit the number of button presses */
|
|
||||||
|
|
||||||
#ifdef CONFIG_NSH_BUILTIN_APPS
|
|
||||||
static volatile long g_nbuttons;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Functions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static void show_buttons(uint8_t oldset, uint8_t newset)
|
|
||||||
{
|
|
||||||
uint8_t chgset = oldset ^ newset;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
/* Update the count of button presses shown */
|
|
||||||
|
|
||||||
#ifdef CONFIG_NSH_BUILTIN_APPS
|
|
||||||
if ((chgset & newset) != 0)
|
|
||||||
{
|
|
||||||
g_nbuttons++;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Show each button state change */
|
|
||||||
|
|
||||||
for (i = MIN_BUTTON; i <= MAX_BUTTON; i++)
|
|
||||||
{
|
|
||||||
uint8_t mask = (1 << i);
|
|
||||||
if ((chgset & mask) != 0)
|
|
||||||
{
|
|
||||||
FAR const char *state;
|
|
||||||
|
|
||||||
/* Get the button state */
|
|
||||||
|
|
||||||
if ((newset & mask) != 0)
|
|
||||||
{
|
|
||||||
state = "depressed";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
state = "released";
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Use lowsyslog() because we make be executing from an
|
|
||||||
* interrupt handler.
|
|
||||||
*/
|
|
||||||
|
|
||||||
lowsyslog(" %s %s\n", g_buttoninfo[BUTTON_INDEX(i)].name, state);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef CONFIG_ARCH_IRQBUTTONS
|
|
||||||
static void button_handler(int id, int irq)
|
|
||||||
{
|
|
||||||
uint8_t newset = up_buttons();
|
|
||||||
|
|
||||||
lowsyslog("IRQ:%d Button %d:%s SET:%02x:\n",
|
|
||||||
irq, id, g_buttoninfo[BUTTON_INDEX(id)].name, newset);
|
|
||||||
show_buttons(g_oldset, newset);
|
|
||||||
g_oldset = newset;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if MIN_BUTTON < 1
|
|
||||||
static int button0_handler(int irq, FAR void *context)
|
|
||||||
{
|
|
||||||
button_handler(0, irq);
|
|
||||||
return OK;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if MIN_BUTTON < 2 && MAX_BUTTON > 0
|
|
||||||
static int button1_handler(int irq, FAR void *context)
|
|
||||||
{
|
|
||||||
button_handler(1, irq);
|
|
||||||
return OK;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if MIN_BUTTON < 3 && MAX_BUTTON > 1
|
|
||||||
static int button2_handler(int irq, FAR void *context)
|
|
||||||
{
|
|
||||||
button_handler(2, irq);
|
|
||||||
return OK;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if MIN_BUTTON < 4 && MAX_BUTTON > 2
|
|
||||||
static int button3_handler(int irq, FAR void *context)
|
|
||||||
{
|
|
||||||
button_handler(3, irq);
|
|
||||||
return OK;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if MIN_BUTTON < 5 && MAX_BUTTON > 3
|
|
||||||
static int button4_handler(int irq, FAR void *context)
|
|
||||||
{
|
|
||||||
button_handler(4, irq);
|
|
||||||
return OK;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if MIN_BUTTON < 6 && MAX_BUTTON > 4
|
|
||||||
static int button5_handler(int irq, FAR void *context)
|
|
||||||
{
|
|
||||||
button_handler(5, irq);
|
|
||||||
return OK;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if MIN_BUTTON < 7 && MAX_BUTTON > 5
|
|
||||||
static int button6_handler(int irq, FAR void *context)
|
|
||||||
{
|
|
||||||
button_handler(6, irq);
|
|
||||||
return OK;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if MAX_BUTTON > 6
|
|
||||||
static int button7_handler(int irq, FAR void *context)
|
|
||||||
{
|
|
||||||
button_handler(7, irq);
|
|
||||||
return OK;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#endif /* CONFIG_ARCH_IRQBUTTONS */
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Functions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* buttons_main
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
int buttons_main(int argc, char *argv[])
|
|
||||||
{
|
|
||||||
uint8_t newset;
|
|
||||||
irqstate_t flags;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
/* If this example is configured as an NX add-on, then limit the number of
|
|
||||||
* samples that we collect before returning. Otherwise, we never return
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef CONFIG_NSH_BUILTIN_APPS
|
|
||||||
long maxbuttons = 1;
|
|
||||||
g_nbuttons = 0;
|
|
||||||
if (argc > 1)
|
|
||||||
{
|
|
||||||
maxbuttons = strtol(argv[1], NULL, 10);
|
|
||||||
}
|
|
||||||
lowsyslog("maxbuttons: %d\n", maxbuttons);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Initialize the button GPIOs */
|
|
||||||
|
|
||||||
up_buttoninit();
|
|
||||||
|
|
||||||
/* Register to recieve button interrupts */
|
|
||||||
|
|
||||||
#ifdef CONFIG_ARCH_IRQBUTTONS
|
|
||||||
for (i = CONFIG_EXAMPLES_IRQBUTTONS_MIN; i <= CONFIG_EXAMPLES_IRQBUTTONS_MAX; i++)
|
|
||||||
{
|
|
||||||
xcpt_t oldhandler = up_irqbutton(i, g_buttoninfo[BUTTON_INDEX(i)].handler);
|
|
||||||
|
|
||||||
/* Use lowsyslog() for compatibility with interrrupt handler output. */
|
|
||||||
|
|
||||||
lowsyslog("Attached handler at %p to button %d [%s], oldhandler:%p\n",
|
|
||||||
g_buttoninfo[BUTTON_INDEX(i)].handler, i,
|
|
||||||
g_buttoninfo[BUTTON_INDEX(i)].name, oldhandler);
|
|
||||||
|
|
||||||
/* Some hardware multiplexes different GPIO button sources to the same
|
|
||||||
* physical interrupt. If we register multiple such multiplexed button
|
|
||||||
* interrupts, then the second registration will overwrite the first. In
|
|
||||||
* this case, the first button interrupts may be aliased to the second
|
|
||||||
* interrupt handler (or worse, could be lost).
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (oldhandler != NULL)
|
|
||||||
{
|
|
||||||
lowsyslog("WARNING: oldhandler:%p is not NULL! "
|
|
||||||
"Button events may be lost or aliased!\n",
|
|
||||||
oldhandler);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Poll button state */
|
|
||||||
|
|
||||||
g_oldset = up_buttons();
|
|
||||||
#ifdef CONFIG_NSH_BUILTIN_APPS
|
|
||||||
while (g_nbuttons < maxbuttons)
|
|
||||||
#else
|
|
||||||
for (;;)
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
/* Get the set of pressed and release buttons. */
|
|
||||||
|
|
||||||
newset = up_buttons();
|
|
||||||
|
|
||||||
/* Any changes from the last sample? */
|
|
||||||
|
|
||||||
if (newset != g_oldset)
|
|
||||||
{
|
|
||||||
/* Disable interrupts so that output here will not collide with
|
|
||||||
* output from an interrupt handler.
|
|
||||||
*/
|
|
||||||
|
|
||||||
flags = irqsave();
|
|
||||||
|
|
||||||
/* Use lowsyslog() for compatibility with interrrupt handler
|
|
||||||
* output.
|
|
||||||
*/
|
|
||||||
|
|
||||||
lowsyslog("POLL SET:%02x:\n", newset);
|
|
||||||
show_buttons(g_oldset, newset);
|
|
||||||
g_oldset = newset;
|
|
||||||
irqrestore(flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Sleep a little... but not long. This will determine how fast we
|
|
||||||
* poll for button changes.
|
|
||||||
*/
|
|
||||||
|
|
||||||
usleep(150000); /* 150 Milliseconds */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Un-register button handlers */
|
|
||||||
|
|
||||||
#if defined(CONFIG_ARCH_IRQBUTTONS) && defined(CONFIG_NSH_BUILTIN_APPS)
|
|
||||||
for (i = CONFIG_EXAMPLES_IRQBUTTONS_MIN; i <= CONFIG_EXAMPLES_IRQBUTTONS_MAX; i++)
|
|
||||||
{
|
|
||||||
(void)up_irqbutton(i, NULL);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,14 +0,0 @@
|
||||||
#
|
|
||||||
# For a description of the syntax of this configuration file,
|
|
||||||
# see misc/tools/kconfig-language.txt.
|
|
||||||
#
|
|
||||||
|
|
||||||
config EXAMPLES_CAN
|
|
||||||
bool "CAN example"
|
|
||||||
default n
|
|
||||||
---help---
|
|
||||||
Enable the CAN example
|
|
||||||
|
|
||||||
if EXAMPLES_CAN
|
|
||||||
endif
|
|
||||||
|
|
|
@ -1,109 +0,0 @@
|
||||||
############################################################################
|
|
||||||
# apps/examples/can/Makefile
|
|
||||||
#
|
|
||||||
# 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
|
|
||||||
# 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)/.config
|
|
||||||
-include $(TOPDIR)/Make.defs
|
|
||||||
include $(APPDIR)/Make.defs
|
|
||||||
|
|
||||||
# NuttX NX Graphics Example.
|
|
||||||
|
|
||||||
ASRCS =
|
|
||||||
CSRCS = can_main.c
|
|
||||||
|
|
||||||
AOBJS = $(ASRCS:.S=$(OBJEXT))
|
|
||||||
COBJS = $(CSRCS:.c=$(OBJEXT))
|
|
||||||
|
|
||||||
SRCS = $(ASRCS) $(CSRCS)
|
|
||||||
OBJS = $(AOBJS) $(COBJS)
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
|
|
||||||
BIN = ..\..\libapps$(LIBEXT)
|
|
||||||
else
|
|
||||||
ifeq ($(WINTOOL),y)
|
|
||||||
BIN = ..\\..\\libapps$(LIBEXT)
|
|
||||||
else
|
|
||||||
BIN = ../../libapps$(LIBEXT)
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
ROOTDEPPATH = --dep-path .
|
|
||||||
|
|
||||||
# Touchscreen built-in application info
|
|
||||||
|
|
||||||
APPNAME = can
|
|
||||||
PRIORITY = SCHED_PRIORITY_DEFAULT
|
|
||||||
STACKSIZE = 2048
|
|
||||||
|
|
||||||
# Common build
|
|
||||||
|
|
||||||
VPATH =
|
|
||||||
|
|
||||||
all: .built
|
|
||||||
.PHONY: context clean depend distclean
|
|
||||||
|
|
||||||
$(AOBJS): %$(OBJEXT): %.S
|
|
||||||
$(call ASSEMBLE, $<, $@)
|
|
||||||
|
|
||||||
$(COBJS): %$(OBJEXT): %.c
|
|
||||||
$(call COMPILE, $<, $@)
|
|
||||||
|
|
||||||
.built: $(OBJS)
|
|
||||||
$(call ARCHIVE, $(BIN), $(OBJS))
|
|
||||||
@touch .built
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
|
|
||||||
$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile
|
|
||||||
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
|
|
||||||
|
|
||||||
context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat
|
|
||||||
else
|
|
||||||
context:
|
|
||||||
endif
|
|
||||||
|
|
||||||
.depend: Makefile $(SRCS)
|
|
||||||
@$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
|
|
||||||
@touch $@
|
|
||||||
|
|
||||||
depend: .depend
|
|
||||||
|
|
||||||
clean:
|
|
||||||
$(call DELFILE, .built)
|
|
||||||
$(call CLEAN)
|
|
||||||
|
|
||||||
distclean: clean
|
|
||||||
$(call DELFILE, Make.dep)
|
|
||||||
$(call DELFILE, .depend)
|
|
||||||
|
|
||||||
-include Make.dep
|
|
|
@ -1,131 +0,0 @@
|
||||||
/****************************************************************************
|
|
||||||
* examples/examples/can/can.h
|
|
||||||
*
|
|
||||||
* Copyright (C) 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.
|
|
||||||
*
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#ifndef __APPS_EXAMPLES_CAN_CAN_H
|
|
||||||
#define __APPS_EXAMPLES_CAN_CAN_H
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Included Files
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#include <nuttx/config.h>
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Definitions
|
|
||||||
****************************************************************************/
|
|
||||||
/* Configuration ************************************************************/
|
|
||||||
/* This test depends on these specific CAN configurations settings (your
|
|
||||||
* specific CAN settings might require additional settings).
|
|
||||||
*
|
|
||||||
* CONFIG_CAN - Enables CAN support.
|
|
||||||
* CONFIG_CAN_LOOPBACK - A CAN driver may or may not support a loopback
|
|
||||||
* mode for testing. The STM32 CAN driver does support loopback mode.
|
|
||||||
*
|
|
||||||
* Specific configuration options for this example include:
|
|
||||||
*
|
|
||||||
* CONFIG_NSH_BUILTIN_APPS - Build the CAN test as an NSH built-in function.
|
|
||||||
* Default: Built as a standalone problem
|
|
||||||
* CONFIG_CAN_LOOPBACK
|
|
||||||
* CONFIG_EXAMPLES_CAN_DEVPATH - The path to the CAN device. Default: /dev/can0
|
|
||||||
* CONFIG_EXAMPLES_CAN_NMSGS - If CONFIG_NSH_BUILTIN_APPS
|
|
||||||
* is defined, then the number of loops is provided on the command line
|
|
||||||
* and this value is ignored. Otherwise, this number of CAN message is
|
|
||||||
* collected and the program terminates. Default: If built as an NSH
|
|
||||||
* built-in, the default is 32. Otherwise messages are sent and received
|
|
||||||
* indefinitely.
|
|
||||||
* CONFIG_EXAMPLES_CAN_READONLY - Only receive messages
|
|
||||||
* CONFIG_EXAMPLES_CAN_WRITEONLY - Only send messages
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef CONFIG_CAN
|
|
||||||
# error "CAN device support is not enabled (CONFIG_CAN)"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef CONFIG_CAN_LOOPBACK
|
|
||||||
# warning "CAN loopback is not enabled (CONFIG_CAN_LOOPBACK)"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef CONFIG_EXAMPLES_CAN_DEVPATH
|
|
||||||
# define CONFIG_EXAMPLES_CAN_DEVPATH "/dev/can0"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(CONFIG_NSH_BUILTIN_APPS) && !defined(CONFIG_EXAMPLES_CAN_NMSGS)
|
|
||||||
# define CONFIG_EXAMPLES_CAN_NMSGS 32
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Debug ********************************************************************/
|
|
||||||
|
|
||||||
#ifdef CONFIG_CPP_HAVE_VARARGS
|
|
||||||
# ifdef CONFIG_DEBUG
|
|
||||||
# define message(...) syslog(__VA_ARGS__)
|
|
||||||
# define msgflush()
|
|
||||||
# else
|
|
||||||
# define message(...) printf(__VA_ARGS__)
|
|
||||||
# define msgflush() fflush(stdout)
|
|
||||||
# endif
|
|
||||||
#else
|
|
||||||
# ifdef CONFIG_DEBUG
|
|
||||||
# define message syslog
|
|
||||||
# define msgflush()
|
|
||||||
# else
|
|
||||||
# define message printf
|
|
||||||
# define msgflush() fflush(stdout)
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Types
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Variables
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Function Prototypes
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: can_devinit()
|
|
||||||
*
|
|
||||||
* Description:
|
|
||||||
* Perform architecuture-specific initialization of the CAN hardware. This
|
|
||||||
* interface must be provided by all configurations using apps/examples/can
|
|
||||||
*
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
int can_devinit(void);
|
|
||||||
|
|
||||||
#endif /* __APPS_EXAMPLES_CAN_CAN_H */
|
|
|
@ -1,301 +0,0 @@
|
||||||
/****************************************************************************
|
|
||||||
* examples/can/can_main.c
|
|
||||||
*
|
|
||||||
* Copyright (C) 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 <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <debug.h>
|
|
||||||
|
|
||||||
#include <nuttx/can.h>
|
|
||||||
|
|
||||||
#include "can.h"
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Pre-processor Definitions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#if defined(CONFIG_EXAMPLES_CAN_READONLY)
|
|
||||||
# undef CONFIG_EXAMPLES_CAN_WRITEONLY
|
|
||||||
# undef CONFIG_EXAMPLES_CAN_READWRITE
|
|
||||||
# define CAN_OFLAGS O_RDONLY
|
|
||||||
#elif defined(CONFIG_EXAMPLES_CAN_WRITEONLY)
|
|
||||||
# undef CONFIG_EXAMPLES_CAN_READWRITE
|
|
||||||
# define CAN_OFLAGS O_WRONLY
|
|
||||||
#else
|
|
||||||
# undef CONFIG_EXAMPLES_CAN_READWRITE
|
|
||||||
# define CONFIG_EXAMPLES_CAN_READWRITE 1
|
|
||||||
# define CAN_OFLAGS O_RDWR
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CONFIG_CAN_EXTID
|
|
||||||
# define MAX_ID (1 << 29)
|
|
||||||
#else
|
|
||||||
# define MAX_ID (1 << 11)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Types
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Function Prototypes
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Data
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Data
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Functions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Functions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: can_main
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
int can_main(int argc, char *argv[])
|
|
||||||
{
|
|
||||||
#ifndef CONFIG_EXAMPLES_CAN_READONLY
|
|
||||||
struct can_msg_s txmsg;
|
|
||||||
#ifdef CONFIG_CAN_EXTID
|
|
||||||
uint32_t msgid;
|
|
||||||
#else
|
|
||||||
uint16_t msgid;
|
|
||||||
#endif
|
|
||||||
int msgdlc;
|
|
||||||
uint8_t msgdata;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef CONFIG_EXAMPLES_CAN_WRITEONLY
|
|
||||||
struct can_msg_s rxmsg;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
size_t msgsize;
|
|
||||||
ssize_t nbytes;
|
|
||||||
#if defined(CONFIG_NSH_BUILTIN_APPS) || defined(CONFIG_EXAMPLES_CAN_NMSGS)
|
|
||||||
long nmsgs;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int fd;
|
|
||||||
int errval = 0;
|
|
||||||
int ret;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
/* If this example is configured as an NX add-on, then limit the number of
|
|
||||||
* samples that we collect before returning. Otherwise, we never return
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if defined(CONFIG_NSH_BUILTIN_APPS)
|
|
||||||
nmsgs = CONFIG_EXAMPLES_CAN_NMSGS;
|
|
||||||
if (argc > 1)
|
|
||||||
{
|
|
||||||
nmsgs = strtol(argv[1], NULL, 10);
|
|
||||||
}
|
|
||||||
message("can_main: nmsgs: %d\n", nmsgs);
|
|
||||||
#elif defined(CONFIG_EXAMPLES_CAN_NMSGS)
|
|
||||||
message("can_main: nmsgs: %d\n", CONFIG_EXAMPLES_CAN_NMSGS);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Initialization of the CAN hardware is performed by logic external to
|
|
||||||
* this test.
|
|
||||||
*/
|
|
||||||
|
|
||||||
message("can_main: Initializing external CAN device\n");
|
|
||||||
ret = can_devinit();
|
|
||||||
if (ret != OK)
|
|
||||||
{
|
|
||||||
message("can_main: can_devinit failed: %d\n", ret);
|
|
||||||
errval = 1;
|
|
||||||
goto errout;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Open the CAN device for reading */
|
|
||||||
|
|
||||||
message("can_main: Hardware initialized. Opening the CAN device\n");
|
|
||||||
fd = open(CONFIG_EXAMPLES_CAN_DEVPATH, CAN_OFLAGS);
|
|
||||||
if (fd < 0)
|
|
||||||
{
|
|
||||||
message("can_main: open %s failed: %d\n",
|
|
||||||
CONFIG_EXAMPLES_CAN_DEVPATH, errno);
|
|
||||||
errval = 2;
|
|
||||||
goto errout_with_dev;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Now loop the appropriate number of times, performing one loopback test
|
|
||||||
* on each pass.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef CONFIG_EXAMPLES_CAN_READONLY
|
|
||||||
msgdlc = 1;
|
|
||||||
msgid = 1;
|
|
||||||
msgdata = 0;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(CONFIG_NSH_BUILTIN_APPS)
|
|
||||||
for (; nmsgs > 0; nmsgs--)
|
|
||||||
#elif defined(CONFIG_EXAMPLES_CAN_NMSGS)
|
|
||||||
for (nmsgs = 0; nmsgs < CONFIG_EXAMPLES_CAN_NMSGS; nmsgs++)
|
|
||||||
#else
|
|
||||||
for (;;)
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
/* Flush any output before the loop entered or from the previous pass
|
|
||||||
* through the loop.
|
|
||||||
*/
|
|
||||||
|
|
||||||
msgflush();
|
|
||||||
|
|
||||||
/* Construct the next TX message */
|
|
||||||
|
|
||||||
#ifndef CONFIG_EXAMPLES_CAN_READONLY
|
|
||||||
txmsg.cm_hdr.ch_id = msgid;
|
|
||||||
txmsg.cm_hdr.ch_rtr = false;
|
|
||||||
txmsg.cm_hdr.ch_dlc = msgdlc;
|
|
||||||
#ifdef CONFIG_CAN_EXTID
|
|
||||||
txmsg.cm_hdr.ch_extid = true;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
for (i = 0; i < msgdlc; i++)
|
|
||||||
{
|
|
||||||
txmsg.cm_data[i] = msgdata + i;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Send the TX message */
|
|
||||||
|
|
||||||
msgsize = CAN_MSGLEN(msgdlc);
|
|
||||||
nbytes = write(fd, &txmsg, msgsize);
|
|
||||||
if (nbytes != msgsize)
|
|
||||||
{
|
|
||||||
message("ERROR: write(%d) returned %d\n", msgsize, nbytes);
|
|
||||||
errval = 3;
|
|
||||||
goto errout_with_dev;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CONFIG_EXAMPLES_CAN_WRITEONLY
|
|
||||||
message(" ID: %4d DLC: %d\n", msgid, msgdlc);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Read the RX message */
|
|
||||||
|
|
||||||
#ifndef CONFIG_EXAMPLES_CAN_WRITEONLY
|
|
||||||
msgsize = sizeof(struct can_msg_s);
|
|
||||||
nbytes = read(fd, &rxmsg, msgsize);
|
|
||||||
if (nbytes < CAN_MSGLEN(0) || nbytes > msgsize)
|
|
||||||
{
|
|
||||||
message("ERROR: read(%d) returned %d\n", msgsize, nbytes);
|
|
||||||
errval = 4;
|
|
||||||
goto errout_with_dev;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef CONFIG_EXAMPLES_CAN_READONLY
|
|
||||||
message(" ID: %4d DLC: %d\n", rxmsg.cm_hdr.id, rxmsg.cm_hdr.dlc);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Verify that the received messages are the same */
|
|
||||||
|
|
||||||
#ifdef CONFIG_EXAMPLES_CAN_READWRITE
|
|
||||||
if (memcmp(&txmsg.cm_hdr, &rxmsg.cm_hdr, sizeof(struct can_hdr_s)) != 0)
|
|
||||||
{
|
|
||||||
message("ERROR: Sent header does not match received header:\n");
|
|
||||||
lib_dumpbuffer("Sent header", (FAR const uint8_t*)&txmsg.cm_hdr,
|
|
||||||
sizeof(struct can_hdr_s));
|
|
||||||
lib_dumpbuffer("Received header", (FAR const uint8_t*)&rxmsg.cm_hdr,
|
|
||||||
sizeof(struct can_hdr_s));
|
|
||||||
errval = 4;
|
|
||||||
goto errout_with_dev;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (memcmp(txmsg.cm_data, rxmsg.cm_data, msgdlc) != 0)
|
|
||||||
{
|
|
||||||
message("ERROR: Data does not match. DLC=%d\n", msgdlc);
|
|
||||||
for (i = 0; i < msgdlc; i++)
|
|
||||||
{
|
|
||||||
message(" %d: TX %02x RX %02x\n", i, txmsg.cm_data[i], rxmsg.cm_data[i]);
|
|
||||||
errval = 5;
|
|
||||||
goto errout_with_dev;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Report success */
|
|
||||||
|
|
||||||
message(" ID: %4d DLC: %d -- OK\n", msgid, msgdlc);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Set up for the next pass */
|
|
||||||
|
|
||||||
#ifndef CONFIG_EXAMPLES_CAN_READONLY
|
|
||||||
msgdata += msgdlc;
|
|
||||||
|
|
||||||
if (++msgid >= MAX_ID)
|
|
||||||
{
|
|
||||||
msgid = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (++msgdlc > CAN_MAXDATALEN)
|
|
||||||
{
|
|
||||||
msgdlc = 1;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
errout_with_dev:
|
|
||||||
close(fd);
|
|
||||||
|
|
||||||
errout:
|
|
||||||
message("Terminating!\n");
|
|
||||||
msgflush();
|
|
||||||
return errval;
|
|
||||||
}
|
|
|
@ -1,14 +0,0 @@
|
||||||
#
|
|
||||||
# For a description of the syntax of this configuration file,
|
|
||||||
# see misc/tools/kconfig-language.txt.
|
|
||||||
#
|
|
||||||
|
|
||||||
config EXAMPLES_CDCACM
|
|
||||||
bool "CAN example"
|
|
||||||
default n
|
|
||||||
---help---
|
|
||||||
Enable the USB CDC/ACM class driver example
|
|
||||||
|
|
||||||
if EXAMPLES_CDCACM
|
|
||||||
endif
|
|
||||||
|
|
|
@ -1,117 +0,0 @@
|
||||||
############################################################################
|
|
||||||
# apps/examples/cdcacm/Makefile
|
|
||||||
#
|
|
||||||
# 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.
|
|
||||||
#
|
|
||||||
############################################################################
|
|
||||||
|
|
||||||
-include $(TOPDIR)/.config
|
|
||||||
-include $(TOPDIR)/Make.defs
|
|
||||||
include $(APPDIR)/Make.defs
|
|
||||||
|
|
||||||
# USB CDC/ACM serial mass storage example
|
|
||||||
|
|
||||||
ASRCS =
|
|
||||||
CSRCS = cdcacm_main.c
|
|
||||||
|
|
||||||
AOBJS = $(ASRCS:.S=$(OBJEXT))
|
|
||||||
COBJS = $(CSRCS:.c=$(OBJEXT))
|
|
||||||
|
|
||||||
SRCS = $(ASRCS) $(CSRCS)
|
|
||||||
OBJS = $(AOBJS) $(COBJS)
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
|
|
||||||
BIN = ..\..\libapps$(LIBEXT)
|
|
||||||
else
|
|
||||||
ifeq ($(WINTOOL),y)
|
|
||||||
BIN = ..\\..\\libapps$(LIBEXT)
|
|
||||||
else
|
|
||||||
BIN = ../../libapps$(LIBEXT)
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
ROOTDEPPATH = --dep-path .
|
|
||||||
|
|
||||||
# USB CDC/ACM built-in application info
|
|
||||||
|
|
||||||
APPNAME1 = sercon
|
|
||||||
PRIORITY1 = SCHED_PRIORITY_DEFAULT
|
|
||||||
STACKSIZE1 = 2048
|
|
||||||
|
|
||||||
APPNAME2 = serdis
|
|
||||||
PRIORITY2 = SCHED_PRIORITY_DEFAULT
|
|
||||||
STACKSIZE2 = 2048
|
|
||||||
|
|
||||||
# Common build
|
|
||||||
|
|
||||||
VPATH =
|
|
||||||
|
|
||||||
all: .built
|
|
||||||
.PHONY: context clean depend distclean
|
|
||||||
|
|
||||||
$(AOBJS): %$(OBJEXT): %.S
|
|
||||||
$(call ASSEMBLE, $<, $@)
|
|
||||||
|
|
||||||
$(COBJS): %$(OBJEXT): %.c
|
|
||||||
$(call COMPILE, $<, $@)
|
|
||||||
|
|
||||||
.built: $(OBJS)
|
|
||||||
$(call ARCHIVE, $(BIN), $(OBJS))
|
|
||||||
@touch .built
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
|
|
||||||
$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME1)_main.bdat: $(DEPCONFIG) Makefile
|
|
||||||
$(call REGISTER,$(APPNAME1),$(PRIORITY1),$(STACKSIZE1),$(APPNAME1)_main)
|
|
||||||
|
|
||||||
$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME2)_main.bdat: $(DEPCONFIG) Makefile
|
|
||||||
$(call REGISTER,$(APPNAME2),$(PRIORITY2),$(STACKSIZE2),$(APPNAME2)_main)
|
|
||||||
|
|
||||||
context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME1)_main.bdat $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME2)_main.bdat
|
|
||||||
else
|
|
||||||
context:
|
|
||||||
endif
|
|
||||||
|
|
||||||
.depend: Makefile $(SRCS)
|
|
||||||
@$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
|
|
||||||
@touch $@
|
|
||||||
|
|
||||||
depend: .depend
|
|
||||||
|
|
||||||
clean:
|
|
||||||
$(call DELFILE, .built)
|
|
||||||
$(call CLEAN)
|
|
||||||
|
|
||||||
distclean: clean
|
|
||||||
$(call DELFILE, Make.dep)
|
|
||||||
$(call DELFILE, .depend)
|
|
||||||
|
|
||||||
-include Make.dep
|
|
||||||
|
|
|
@ -1,165 +0,0 @@
|
||||||
/****************************************************************************
|
|
||||||
* examples/cdcacm/cdcacm.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 __EXAMPLES_CDCACM_CDCACM_H
|
|
||||||
#define __EXAMPLES_CDCACM_CDCACM_H
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Included Files
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#include <nuttx/config.h>
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#include <nuttx/usb/usbdev_trace.h>
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Pre-Processor Definitions
|
|
||||||
****************************************************************************/
|
|
||||||
/* Configuration ************************************************************/
|
|
||||||
/* Prerequisites */
|
|
||||||
|
|
||||||
#ifndef CONFIG_USBDEV
|
|
||||||
# error "CONFIG_USBDEV is not defined"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef CONFIG_CDCACM
|
|
||||||
# error "CONFIG_CDCACM is not defined"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef CONFIG_NSH_BUILTIN_APPS
|
|
||||||
# error "This example can only be built as an NSH built-in application"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Default configuration values */
|
|
||||||
|
|
||||||
#ifndef CONFIG_EXAMPLES_CDCACM_DEVMINOR
|
|
||||||
# define CONFIG_EXAMPLES_CDCACM_DEVMINOR 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Trace Configuration ******************************************************/
|
|
||||||
|
|
||||||
#ifdef CONFIG_EXAMPLES_CDCACM_TRACEINIT
|
|
||||||
# define TRACE_INIT_BITS (TRACE_INIT_BIT)
|
|
||||||
#else
|
|
||||||
# define TRACE_INIT_BITS (0)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define TRACE_ERROR_BITS (TRACE_DEVERROR_BIT|TRACE_CLSERROR_BIT)
|
|
||||||
|
|
||||||
#ifdef CONFIG_EXAMPLES_CDCACM_TRACECLASS
|
|
||||||
# define TRACE_CLASS_BITS (TRACE_CLASS_BIT|TRACE_CLASSAPI_BIT|TRACE_CLASSSTATE_BIT)
|
|
||||||
#else
|
|
||||||
# define TRACE_CLASS_BITS (0)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CONFIG_EXAMPLES_CDCACM_TRACETRANSFERS
|
|
||||||
# define TRACE_TRANSFER_BITS (TRACE_OUTREQQUEUED_BIT|TRACE_INREQQUEUED_BIT|TRACE_READ_BIT|\
|
|
||||||
TRACE_WRITE_BIT|TRACE_COMPLETE_BIT)
|
|
||||||
#else
|
|
||||||
# define TRACE_TRANSFER_BITS (0)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CONFIG_EXAMPLES_CDCACM_TRACECONTROLLER
|
|
||||||
# define TRACE_CONTROLLER_BITS (TRACE_EP_BIT|TRACE_DEV_BIT)
|
|
||||||
#else
|
|
||||||
# define TRACE_CONTROLLER_BITS (0)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CONFIG_EXAMPLES_CDCACM_TRACEINTERRUPTS
|
|
||||||
# define TRACE_INTERRUPT_BITS (TRACE_INTENTRY_BIT|TRACE_INTDECODE_BIT|TRACE_INTEXIT_BIT)
|
|
||||||
#else
|
|
||||||
# define TRACE_INTERRUPT_BITS (0)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define TRACE_BITSET (TRACE_INIT_BITS|TRACE_ERROR_BITS|TRACE_CLASS_BITS|\
|
|
||||||
TRACE_TRANSFER_BITS|TRACE_CONTROLLER_BITS|TRACE_INTERRUPT_BITS)
|
|
||||||
|
|
||||||
/* Debug ********************************************************************/
|
|
||||||
|
|
||||||
#ifdef CONFIG_CPP_HAVE_VARARGS
|
|
||||||
# ifdef CONFIG_DEBUG
|
|
||||||
# define message(...) lowsyslog(__VA_ARGS__)
|
|
||||||
# define msgflush()
|
|
||||||
# else
|
|
||||||
# define message(...) printf(__VA_ARGS__)
|
|
||||||
# define msgflush() fflush(stdout)
|
|
||||||
# endif
|
|
||||||
#else
|
|
||||||
# ifdef CONFIG_DEBUG
|
|
||||||
# define message lowsyslog
|
|
||||||
# define msgflush()
|
|
||||||
# else
|
|
||||||
# define message printf
|
|
||||||
# define msgflush() fflush(stdout)
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Types
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/* All global variables used by this example are packed into a structure in
|
|
||||||
* order to avoid name collisions.
|
|
||||||
*/
|
|
||||||
|
|
||||||
struct cdcacm_state_s
|
|
||||||
{
|
|
||||||
/* This is the handle that references to this particular USB storage driver
|
|
||||||
* instance. It is only needed if the USB mass storage device example is
|
|
||||||
* built using CONFIG_NSH_BUILTIN_APPS. In this case, the value
|
|
||||||
* of the driver handle must be remembered between the 'sercon' and 'msdis'
|
|
||||||
* commands.
|
|
||||||
*/
|
|
||||||
|
|
||||||
FAR void *handle;
|
|
||||||
};
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Data
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/* All global variables used by this example are packed into a structure in
|
|
||||||
* order to avoid name collisions.
|
|
||||||
*/
|
|
||||||
|
|
||||||
extern struct cdcacm_state_s g_cdcacm;
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Functions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#endif /* __EXAMPLES_CDCACM_CDCACM_H */
|
|
|
@ -1,147 +0,0 @@
|
||||||
/****************************************************************************
|
|
||||||
* examples/cdcacm/cdcacm_main.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 <stdio.h>
|
|
||||||
#include <debug.h>
|
|
||||||
|
|
||||||
#include <nuttx/usb/usbdev.h>
|
|
||||||
#include <nuttx/usb/cdcacm.h>
|
|
||||||
|
|
||||||
#include "cdcacm.h"
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Definitions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Data
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/* All global variables used by this example are packed into a structure in
|
|
||||||
* order to avoid name collisions.
|
|
||||||
*/
|
|
||||||
|
|
||||||
struct cdcacm_state_s g_cdcacm;
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Functions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Functions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* sercon_main
|
|
||||||
*
|
|
||||||
* Description:
|
|
||||||
* This is the main program that configures the CDC/ACM serial device.
|
|
||||||
*
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
int sercon_main(int argc, char *argv[])
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
/* Check if there is a non-NULL USB mass storage device handle (meaning that the
|
|
||||||
* USB mass storage device is already configured).
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (g_cdcacm.handle)
|
|
||||||
{
|
|
||||||
message("sercon:: ERROR: Already connected\n");
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Then, in any event, enable trace data collection as configured BEFORE
|
|
||||||
* enabling the CDC/ACM device.
|
|
||||||
*/
|
|
||||||
|
|
||||||
usbtrace_enable(TRACE_BITSET);
|
|
||||||
|
|
||||||
/* Initialize the USB CDC/ACM serial driver */
|
|
||||||
|
|
||||||
message("sercon: Registering CDC/ACM serial driver\n");
|
|
||||||
ret = cdcacm_initialize(CONFIG_EXAMPLES_CDCACM_DEVMINOR, &g_cdcacm.handle);
|
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
message("sercon: ERROR: Failed to create the CDC/ACM serial device: %d\n", -ret);
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
message("sercon: Successfully registered the CDC/ACM serial driver\n");
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* serdis_main
|
|
||||||
*
|
|
||||||
* Description:
|
|
||||||
* This is a program entry point that will disconnect the CDC/ACM serial
|
|
||||||
* device.
|
|
||||||
*
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
int serdis_main(int argc, char *argv[])
|
|
||||||
{
|
|
||||||
/* First check if the USB mass storage device is already connected */
|
|
||||||
|
|
||||||
if (!g_cdcacm.handle)
|
|
||||||
{
|
|
||||||
message("serdis: ERROR: Not connected\n");
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Then, in any event, disable trace data collection as configured BEFORE
|
|
||||||
* enabling the CDC/ACM device.
|
|
||||||
*/
|
|
||||||
|
|
||||||
usbtrace_enable(0);
|
|
||||||
|
|
||||||
/* Then disconnect the device and uninitialize the USB mass storage driver */
|
|
||||||
|
|
||||||
cdcacm_uninitialize(g_cdcacm.handle);
|
|
||||||
g_cdcacm.handle = NULL;
|
|
||||||
message("serdis: Disconnected\n");
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
|
|
@ -1,13 +0,0 @@
|
||||||
#
|
|
||||||
# For a description of the syntax of this configuration file,
|
|
||||||
# see misc/tools/kconfig-language.txt.
|
|
||||||
#
|
|
||||||
|
|
||||||
config EXAMPLES_HELLO
|
|
||||||
bool "\"Hello, World!\" example"
|
|
||||||
default n
|
|
||||||
---help---
|
|
||||||
Enable the \"Hello, World!\" example
|
|
||||||
|
|
||||||
if EXAMPLES_HELLO
|
|
||||||
endif
|
|
|
@ -1,109 +0,0 @@
|
||||||
############################################################################
|
|
||||||
# apps/examples/hello/Makefile
|
|
||||||
#
|
|
||||||
# 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
|
|
||||||
# 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)/.config
|
|
||||||
-include $(TOPDIR)/Make.defs
|
|
||||||
include $(APPDIR)/Make.defs
|
|
||||||
|
|
||||||
# Hello, World! built-in application info
|
|
||||||
|
|
||||||
APPNAME = hello
|
|
||||||
PRIORITY = SCHED_PRIORITY_DEFAULT
|
|
||||||
STACKSIZE = 2048
|
|
||||||
|
|
||||||
# Hello, World! Example
|
|
||||||
|
|
||||||
ASRCS =
|
|
||||||
CSRCS = hello_main.c
|
|
||||||
|
|
||||||
AOBJS = $(ASRCS:.S=$(OBJEXT))
|
|
||||||
COBJS = $(CSRCS:.c=$(OBJEXT))
|
|
||||||
|
|
||||||
SRCS = $(ASRCS) $(CSRCS)
|
|
||||||
OBJS = $(AOBJS) $(COBJS)
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
|
|
||||||
BIN = ..\..\libapps$(LIBEXT)
|
|
||||||
else
|
|
||||||
ifeq ($(WINTOOL),y)
|
|
||||||
BIN = ..\\..\\libapps$(LIBEXT)
|
|
||||||
else
|
|
||||||
BIN = ../../libapps$(LIBEXT)
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
ROOTDEPPATH = --dep-path .
|
|
||||||
|
|
||||||
# Common build
|
|
||||||
|
|
||||||
VPATH =
|
|
||||||
|
|
||||||
all: .built
|
|
||||||
.PHONY: clean depend distclean
|
|
||||||
|
|
||||||
$(AOBJS): %$(OBJEXT): %.S
|
|
||||||
$(call ASSEMBLE, $<, $@)
|
|
||||||
|
|
||||||
$(COBJS): %$(OBJEXT): %.c
|
|
||||||
$(call COMPILE, $<, $@)
|
|
||||||
|
|
||||||
.built: $(OBJS)
|
|
||||||
$(call ARCHIVE, $(BIN), $(OBJS))
|
|
||||||
@touch .built
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
|
|
||||||
$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile
|
|
||||||
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
|
|
||||||
|
|
||||||
context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat
|
|
||||||
else
|
|
||||||
context:
|
|
||||||
endif
|
|
||||||
|
|
||||||
.depend: Makefile $(SRCS)
|
|
||||||
@$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
|
|
||||||
@touch $@
|
|
||||||
|
|
||||||
depend: .depend
|
|
||||||
|
|
||||||
clean:
|
|
||||||
$(call DELFILE, .built)
|
|
||||||
$(call CLEAN)
|
|
||||||
|
|
||||||
distclean: clean
|
|
||||||
$(call DELFILE, Make.dep)
|
|
||||||
$(call DELFILE, .depend)
|
|
||||||
|
|
||||||
-include Make.dep
|
|
|
@ -1,64 +0,0 @@
|
||||||
/****************************************************************************
|
|
||||||
* examples/hello/hello_main.c
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
* 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>
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Definitions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Data
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Functions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* hello_main
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
int hello_main(int argc, char *argv[])
|
|
||||||
{
|
|
||||||
printf("Hello, World!!\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,13 +0,0 @@
|
||||||
#
|
|
||||||
# For a description of the syntax of this configuration file,
|
|
||||||
# see misc/tools/kconfig-language.txt.
|
|
||||||
#
|
|
||||||
|
|
||||||
config EXAMPLES_HELLOXX
|
|
||||||
bool "\"Hello, World!\" C++ example"
|
|
||||||
default n
|
|
||||||
---help---
|
|
||||||
Enable the \"Hello, World!\" C++ example
|
|
||||||
|
|
||||||
if EXAMPLES_HELLOXX
|
|
||||||
endif
|
|
|
@ -1,126 +0,0 @@
|
||||||
############################################################################
|
|
||||||
# apps/examples/helloxx/Makefile
|
|
||||||
#
|
|
||||||
# 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
|
|
||||||
# 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)/.config
|
|
||||||
-include $(TOPDIR)/Make.defs
|
|
||||||
include $(APPDIR)/Make.defs
|
|
||||||
|
|
||||||
# Hello, World! C++ Example
|
|
||||||
|
|
||||||
ASRCS =
|
|
||||||
CSRCS =
|
|
||||||
CXXSRCS = helloxx_main.cxx
|
|
||||||
|
|
||||||
AOBJS = $(ASRCS:.S=$(OBJEXT))
|
|
||||||
COBJS = $(CSRCS:.c=$(OBJEXT))
|
|
||||||
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 = ..\\..\\libapps$(LIBEXT)
|
|
||||||
else
|
|
||||||
BIN = ../../libapps$(LIBEXT)
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
ROOTDEPPATH = --dep-path .
|
|
||||||
|
|
||||||
# helloxx built-in application info
|
|
||||||
|
|
||||||
APPNAME = helloxx
|
|
||||||
PRIORITY = SCHED_PRIORITY_DEFAULT
|
|
||||||
STACKSIZE = 2048
|
|
||||||
|
|
||||||
# Common build
|
|
||||||
|
|
||||||
VPATH =
|
|
||||||
|
|
||||||
all: .built
|
|
||||||
.PHONY: clean depend distclean chkcxx
|
|
||||||
|
|
||||||
chkcxx:
|
|
||||||
ifneq ($(CONFIG_HAVE_CXX),y)
|
|
||||||
@echo ""
|
|
||||||
@echo "In order to use this example, you toolchain must support must"
|
|
||||||
@echo ""
|
|
||||||
@echo " (1) Explicitly select CONFIG_HAVE_CXX to build in C++ support"
|
|
||||||
@echo " (2) Define CXX, CXXFLAGS, and COMPILEXX in the Make.defs file"
|
|
||||||
@echo " of the configuration that you are using."
|
|
||||||
@echo ""
|
|
||||||
@exit 1
|
|
||||||
endif
|
|
||||||
|
|
||||||
$(AOBJS): %$(OBJEXT): %.S
|
|
||||||
$(call ASSEMBLE, $<, $@)
|
|
||||||
|
|
||||||
$(COBJS): %$(OBJEXT): %.c
|
|
||||||
$(call COMPILE, $<, $@)
|
|
||||||
|
|
||||||
$(CXXOBJS): %$(OBJEXT): %.cxx
|
|
||||||
$(call COMPILEXX, $<, $@)
|
|
||||||
|
|
||||||
.built: chkcxx $(OBJS)
|
|
||||||
$(call ARCHIVE, $(BIN), $(OBJS))
|
|
||||||
@touch .built
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_EXAMPLES_HELLOXX_BUILTIN),y)
|
|
||||||
$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile
|
|
||||||
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
|
|
||||||
|
|
||||||
context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat
|
|
||||||
else
|
|
||||||
context:
|
|
||||||
endif
|
|
||||||
|
|
||||||
.depend: Makefile $(SRCS)
|
|
||||||
@$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
|
|
||||||
@touch $@
|
|
||||||
|
|
||||||
depend: .depend
|
|
||||||
|
|
||||||
clean:
|
|
||||||
$(call DELFILE, .built)
|
|
||||||
$(call CLEAN)
|
|
||||||
|
|
||||||
distclean: clean
|
|
||||||
$(call DELFILE, Make.dep)
|
|
||||||
$(call DELFILE, .depend)
|
|
||||||
|
|
||||||
-include Make.dep
|
|
|
@ -1,165 +0,0 @@
|
||||||
//***************************************************************************
|
|
||||||
// examples/helloxx/helloxx_main.cxx
|
|
||||||
//
|
|
||||||
// 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
|
|
||||||
// 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 <cstdio>
|
|
||||||
#include <debug.h>
|
|
||||||
|
|
||||||
#include <nuttx/init.h>
|
|
||||||
#include <nuttx/arch.h>
|
|
||||||
|
|
||||||
//***************************************************************************
|
|
||||||
// Definitions
|
|
||||||
//***************************************************************************
|
|
||||||
// Debug ********************************************************************
|
|
||||||
// Non-standard debug that may be enabled just for testing the constructors
|
|
||||||
|
|
||||||
#ifndef CONFIG_DEBUG
|
|
||||||
# undef CONFIG_DEBUG_CXX
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CONFIG_DEBUG_CXX
|
|
||||||
# define cxxdbg dbg
|
|
||||||
# define cxxlldbg lldbg
|
|
||||||
# ifdef CONFIG_DEBUG_VERBOSE
|
|
||||||
# define cxxvdbg vdbg
|
|
||||||
# define cxxllvdbg llvdbg
|
|
||||||
# else
|
|
||||||
# define cxxvdbg(x...)
|
|
||||||
# define cxxllvdbg(x...)
|
|
||||||
# endif
|
|
||||||
#else
|
|
||||||
# define cxxdbg(x...)
|
|
||||||
# define cxxlldbg(x...)
|
|
||||||
# define cxxvdbg(x...)
|
|
||||||
# define cxxllvdbg(x...)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//***************************************************************************
|
|
||||||
// Private Classes
|
|
||||||
//***************************************************************************
|
|
||||||
|
|
||||||
class CHelloWorld
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
CHelloWorld(void) : mSecret(42)
|
|
||||||
{
|
|
||||||
cxxdbg("Constructor: mSecret=%d\n", mSecret);
|
|
||||||
}
|
|
||||||
|
|
||||||
~CHelloWorld(void)
|
|
||||||
{
|
|
||||||
cxxdbg("Destructor\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
bool HelloWorld(void)
|
|
||||||
{
|
|
||||||
cxxdbg("HelloWorld: mSecret=%d\n", mSecret);
|
|
||||||
|
|
||||||
if (mSecret != 42)
|
|
||||||
{
|
|
||||||
printf("CHelloWorld::HelloWorld: CONSTRUCTION FAILED!\n");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("CHelloWorld::HelloWorld: Hello, World!!\n");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
int mSecret;
|
|
||||||
};
|
|
||||||
|
|
||||||
//***************************************************************************
|
|
||||||
// Private Data
|
|
||||||
//***************************************************************************
|
|
||||||
|
|
||||||
// Define a statically constructed CHellowWorld instance if C++ static
|
|
||||||
// initializers are supported by the platform
|
|
||||||
|
|
||||||
#ifdef CONFIG_HAVE_CXXINITIALIZE
|
|
||||||
static CHelloWorld g_HelloWorld;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//***************************************************************************
|
|
||||||
// Public Functions
|
|
||||||
//***************************************************************************
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: helloxx_main
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
int helloxx_main(int argc, char *argv[])
|
|
||||||
{
|
|
||||||
// If C++ initialization for static constructors is supported, then do
|
|
||||||
// that first
|
|
||||||
|
|
||||||
#ifdef CONFIG_HAVE_CXXINITIALIZE
|
|
||||||
up_cxxinitialize();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Exercise an explictly instantiated C++ object
|
|
||||||
|
|
||||||
CHelloWorld *pHelloWorld = new CHelloWorld;
|
|
||||||
printf("helloxx_main: Saying hello from the dynamically constructed instance\n");
|
|
||||||
pHelloWorld->HelloWorld();
|
|
||||||
|
|
||||||
// Exercise an C++ object instantiated on the stack
|
|
||||||
|
|
||||||
#ifndef CONFIG_EXAMPLES_HELLOXX_NOSTACKCONST
|
|
||||||
CHelloWorld HelloWorld;
|
|
||||||
|
|
||||||
printf("helloxx_main: Saying hello from the instance constructed on the stack\n");
|
|
||||||
HelloWorld.HelloWorld();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Exercise an statically constructed C++ object
|
|
||||||
|
|
||||||
#ifdef CONFIG_HAVE_CXXINITIALIZE
|
|
||||||
printf("helloxx_main: Saying hello from the statically constructed instance\n");
|
|
||||||
g_HelloWorld.HelloWorld();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
delete pHelloWorld;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,13 +0,0 @@
|
||||||
#
|
|
||||||
# For a description of the syntax of this configuration file,
|
|
||||||
# see misc/tools/kconfig-language.txt.
|
|
||||||
#
|
|
||||||
|
|
||||||
config EXAMPLES_LCDRW
|
|
||||||
bool "LCD read/write example"
|
|
||||||
default n
|
|
||||||
---help---
|
|
||||||
Enable the LCD read/write example
|
|
||||||
|
|
||||||
if EXAMPLES_LCDRW
|
|
||||||
endif
|
|
|
@ -1,13 +0,0 @@
|
||||||
#
|
|
||||||
# For a description of the syntax of this configuration file,
|
|
||||||
# see misc/tools/kconfig-language.txt.
|
|
||||||
#
|
|
||||||
|
|
||||||
config EXAMPLES_MM
|
|
||||||
bool "Memory management example"
|
|
||||||
default n
|
|
||||||
---help---
|
|
||||||
Enable the memory management example
|
|
||||||
|
|
||||||
if EXAMPLES_MM
|
|
||||||
endif
|
|
|
@ -1,96 +0,0 @@
|
||||||
############################################################################
|
|
||||||
# apps/examples/mm/Makefile
|
|
||||||
#
|
|
||||||
# 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
|
|
||||||
# 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)/.config
|
|
||||||
-include $(TOPDIR)/Make.defs
|
|
||||||
include $(APPDIR)/Make.defs
|
|
||||||
|
|
||||||
# Memory Management Test
|
|
||||||
|
|
||||||
ASRCS =
|
|
||||||
CSRCS = mm_main.c
|
|
||||||
|
|
||||||
AOBJS = $(ASRCS:.S=$(OBJEXT))
|
|
||||||
COBJS = $(CSRCS:.c=$(OBJEXT))
|
|
||||||
|
|
||||||
SRCS = $(ASRCS) $(CSRCS)
|
|
||||||
OBJS = $(AOBJS) $(COBJS)
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
|
|
||||||
BIN = ..\..\libapps$(LIBEXT)
|
|
||||||
else
|
|
||||||
ifeq ($(WINTOOL),y)
|
|
||||||
BIN = ..\\..\\libapps$(LIBEXT)
|
|
||||||
else
|
|
||||||
BIN = ../../libapps$(LIBEXT)
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
ROOTDEPPATH = --dep-path .
|
|
||||||
|
|
||||||
# Common build
|
|
||||||
|
|
||||||
VPATH =
|
|
||||||
|
|
||||||
all: .built
|
|
||||||
.PHONY: clean depend distclean
|
|
||||||
|
|
||||||
$(AOBJS): %$(OBJEXT): %.S
|
|
||||||
$(call ASSEMBLE, $<, $@)
|
|
||||||
|
|
||||||
$(COBJS): %$(OBJEXT): %.c
|
|
||||||
$(call COMPILE, $<, $@)
|
|
||||||
|
|
||||||
.built: $(OBJS)
|
|
||||||
$(call ARCHIVE, $(BIN), $(OBJS))
|
|
||||||
@touch .built
|
|
||||||
|
|
||||||
context:
|
|
||||||
|
|
||||||
.depend: Makefile $(SRCS)
|
|
||||||
@$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
|
|
||||||
@touch $@
|
|
||||||
|
|
||||||
depend: .depend
|
|
||||||
|
|
||||||
clean:
|
|
||||||
$(call DELFILE, .built)
|
|
||||||
$(call CLEAN)
|
|
||||||
|
|
||||||
distclean: clean
|
|
||||||
$(call DELFILE, Make.dep)
|
|
||||||
$(call DELFILE, .depend)
|
|
||||||
|
|
||||||
-include Make.dep
|
|
|
@ -1,300 +0,0 @@
|
||||||
/****************************************************************************
|
|
||||||
* examples/mm/mm_main.c
|
|
||||||
*
|
|
||||||
* Copyright (C) 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 <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Pre-processor Definitions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#define NTEST_ALLOCS 32
|
|
||||||
|
|
||||||
/* #define STOP_ON_ERRORS do{}while(0) */
|
|
||||||
#define STOP_ON_ERRORS exit(1)
|
|
||||||
|
|
||||||
/* All other definitions derive from these two */
|
|
||||||
|
|
||||||
#define MM_MIN_SHIFT 4 /* 16 bytes */
|
|
||||||
#define MM_MIN_CHUNK (1 << MM_MIN_SHIFT)
|
|
||||||
#define MM_GRAN_MASK (MM_MIN_CHUNK-1)
|
|
||||||
#define MM_ALIGN_UP(a) (((a) + MM_GRAN_MASK) & ~MM_GRAN_MASK)
|
|
||||||
#define MM_ALIGN_DOWN(a) ((a) & ~MM_GRAN_MASK)
|
|
||||||
|
|
||||||
#ifdef CONFIG_SMALL_MEMORY
|
|
||||||
# define SIZEOF_MM_ALLOCNODE 4
|
|
||||||
#else
|
|
||||||
# define SIZEOF_MM_ALLOCNODE 8
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Data
|
|
||||||
****************************************************************************/
|
|
||||||
/* Test allocations */
|
|
||||||
|
|
||||||
static const int alloc_sizes[NTEST_ALLOCS] =
|
|
||||||
{
|
|
||||||
1024, 12, 962, 5692, 10254, 111, 9932, 601,
|
|
||||||
222, 2746, 3, 124321, 68, 776, 6750, 852,
|
|
||||||
4732, 28, 901, 480, 5011, 1536, 2011, 81647,
|
|
||||||
646, 1646, 69179, 194, 2590, 7, 969, 70
|
|
||||||
};
|
|
||||||
|
|
||||||
static const int realloc_sizes[NTEST_ALLOCS] =
|
|
||||||
{
|
|
||||||
18, 3088, 963, 123, 511, 11666, 3723, 42,
|
|
||||||
9374, 1990, 1412, 6, 592, 4088, 11, 5040,
|
|
||||||
8663, 91255, 28, 4346, 9172, 168, 229, 4734,
|
|
||||||
59139, 221, 7830, 30421, 1666, 4, 812, 416
|
|
||||||
};
|
|
||||||
|
|
||||||
static const int random1[NTEST_ALLOCS] =
|
|
||||||
{
|
|
||||||
20, 11, 3, 31, 9, 29, 7, 17,
|
|
||||||
21, 2, 26, 18, 14, 25, 0, 10,
|
|
||||||
27, 19, 22, 28, 8, 30, 12, 15,
|
|
||||||
4, 1, 24, 6, 16, 13, 5, 23
|
|
||||||
};
|
|
||||||
|
|
||||||
static const int random2[NTEST_ALLOCS] =
|
|
||||||
{
|
|
||||||
2, 19, 12, 23, 30, 11, 27, 4,
|
|
||||||
20, 7, 0, 16, 28, 15, 5, 24,
|
|
||||||
10, 17, 25, 31, 8, 29, 3, 26,
|
|
||||||
9, 18, 22, 13, 1, 21, 14, 6
|
|
||||||
};
|
|
||||||
|
|
||||||
static const int random3[NTEST_ALLOCS] =
|
|
||||||
{
|
|
||||||
8, 17, 3, 18, 26, 23, 30, 11,
|
|
||||||
12, 22, 4, 20, 25, 10, 27, 1,
|
|
||||||
29, 14, 19, 21, 0, 31, 7, 24,
|
|
||||||
9, 15, 2, 28, 16, 6, 13, 5
|
|
||||||
};
|
|
||||||
|
|
||||||
static const int alignment[NTEST_ALLOCS/2] =
|
|
||||||
{
|
|
||||||
128, 2048, 131072, 8192, 32, 32768, 16384 , 262144,
|
|
||||||
512, 4096, 65536, 8, 64, 1024, 16, 4
|
|
||||||
};
|
|
||||||
|
|
||||||
static void *allocs[NTEST_ALLOCS];
|
|
||||||
static struct mallinfo alloc_info;
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Functions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static void mm_showmallinfo(void)
|
|
||||||
{
|
|
||||||
alloc_info = mallinfo();
|
|
||||||
printf(" mallinfo:\n");
|
|
||||||
printf(" Total space allocated from system = %ld\n",
|
|
||||||
alloc_info.arena);
|
|
||||||
printf(" Number of non-inuse chunks = %ld\n",
|
|
||||||
alloc_info.ordblks);
|
|
||||||
printf(" Largest non-inuse chunk = %ld\n",
|
|
||||||
alloc_info.mxordblk);
|
|
||||||
printf(" Total allocated space = %ld\n",
|
|
||||||
alloc_info.uordblks);
|
|
||||||
printf(" Total non-inuse space = %ld\n",
|
|
||||||
alloc_info.fordblks);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void do_mallocs(void **mem, const int *size, const int *seq, int n)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int j;
|
|
||||||
|
|
||||||
for (i = 0; i < n; i++)
|
|
||||||
{
|
|
||||||
j = seq[i];
|
|
||||||
if (!mem[j])
|
|
||||||
{
|
|
||||||
printf("(%d)Allocating %d bytes\n", i, size[j]);
|
|
||||||
mem[j] = malloc(size[j]);
|
|
||||||
printf("(%d)Memory allocated at %p\n", i, mem[j]);
|
|
||||||
if (mem[j] == NULL)
|
|
||||||
{
|
|
||||||
int allocsize = MM_ALIGN_UP(size[j] + SIZEOF_MM_ALLOCNODE);
|
|
||||||
fprintf(stderr, "(%d)malloc failed for allocsize=%d\n", i, allocsize);
|
|
||||||
if (allocsize > alloc_info.mxordblk)
|
|
||||||
{
|
|
||||||
fprintf(stderr, " Normal, largest free block is only %ld\n", alloc_info.mxordblk);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
fprintf(stderr, " ERROR largest free block is %ld\n", alloc_info.mxordblk);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
memset(mem[j], 0xAA, size[j]);
|
|
||||||
}
|
|
||||||
|
|
||||||
mm_showmallinfo();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void do_reallocs(void **mem, const int *oldsize, const int *newsize, const int *seq, int n)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int j;
|
|
||||||
|
|
||||||
for (i = 0; i < n; i++)
|
|
||||||
{
|
|
||||||
j = seq[i];
|
|
||||||
printf("(%d)Re-allocating at %p from %d to %d bytes\n",
|
|
||||||
i, mem[j], oldsize[j], newsize[j]);
|
|
||||||
mem[j] = realloc(mem[j], newsize[j]);
|
|
||||||
printf("(%d)Memory re-allocated at %p\n", i, mem[j]);
|
|
||||||
if (mem[j] == NULL)
|
|
||||||
{
|
|
||||||
int allocsize = MM_ALIGN_UP(newsize[j] + SIZEOF_MM_ALLOCNODE);
|
|
||||||
fprintf(stderr, "(%d)realloc failed for allocsize=%d\n", i, allocsize);
|
|
||||||
if (allocsize > alloc_info.mxordblk)
|
|
||||||
{
|
|
||||||
fprintf(stderr, " Normal, largest free block is only %ld\n", alloc_info.mxordblk);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
fprintf(stderr, " ERROR largest free block is %ld\n", alloc_info.mxordblk);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
memset(mem[j], 0x55, newsize[j]);
|
|
||||||
}
|
|
||||||
|
|
||||||
mm_showmallinfo();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void do_memaligns(void **mem, const int *size, const int *align, const int *seq, int n)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int j;
|
|
||||||
|
|
||||||
for (i = 0; i < n; i++)
|
|
||||||
{
|
|
||||||
j = seq[i];
|
|
||||||
printf("(%d)Allocating %d bytes aligned to 0x%08x\n",
|
|
||||||
i, size[j], align[i]);
|
|
||||||
mem[j] = memalign(align[i], size[j]);
|
|
||||||
printf("(%d)Memory allocated at %p\n", i, mem[j]);
|
|
||||||
if (mem[j] == NULL)
|
|
||||||
{
|
|
||||||
int allocsize = MM_ALIGN_UP(size[j] + SIZEOF_MM_ALLOCNODE) + 2*align[i];
|
|
||||||
fprintf(stderr, "(%d)memalign failed for allocsize=%d\n", i, allocsize);
|
|
||||||
if (allocsize > alloc_info.mxordblk)
|
|
||||||
{
|
|
||||||
fprintf(stderr, " Normal, largest free block is only %ld\n", alloc_info.mxordblk);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
fprintf(stderr, " ERROR largest free block is %ld\n", alloc_info.mxordblk);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
memset(mem[j], 0x33, size[j]);
|
|
||||||
}
|
|
||||||
|
|
||||||
mm_showmallinfo();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void do_frees(void **mem, const int *size, const int *seq, int n)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int j;
|
|
||||||
|
|
||||||
for (i = 0; i < n; i++)
|
|
||||||
{
|
|
||||||
j = seq[i];
|
|
||||||
printf("(%d)Releasing memory at %p (size=%d bytes)\n",
|
|
||||||
i, mem[j], size[j]);
|
|
||||||
free(mem[j]);
|
|
||||||
mem[j] = NULL;
|
|
||||||
|
|
||||||
mm_showmallinfo();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Functions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: mm_main
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
int mm_main(int argc, char *argv[])
|
|
||||||
{
|
|
||||||
mm_showmallinfo();
|
|
||||||
|
|
||||||
/* Allocate some memory */
|
|
||||||
|
|
||||||
do_mallocs(allocs, alloc_sizes, random1, NTEST_ALLOCS);
|
|
||||||
|
|
||||||
/* Re-allocate the memory */
|
|
||||||
|
|
||||||
do_reallocs(allocs, alloc_sizes, realloc_sizes, random2, NTEST_ALLOCS);
|
|
||||||
|
|
||||||
/* Release the memory */
|
|
||||||
|
|
||||||
do_frees(allocs, realloc_sizes, random3, NTEST_ALLOCS);
|
|
||||||
|
|
||||||
/* Allocate aligned memory */
|
|
||||||
|
|
||||||
do_memaligns(allocs, alloc_sizes, alignment, random2, NTEST_ALLOCS/2);
|
|
||||||
do_memaligns(allocs, alloc_sizes, alignment, &random2[NTEST_ALLOCS/2], NTEST_ALLOCS/2);
|
|
||||||
|
|
||||||
/* Release aligned memory */
|
|
||||||
|
|
||||||
do_frees(allocs, alloc_sizes, random1, NTEST_ALLOCS);
|
|
||||||
|
|
||||||
printf("TEST COMPLETE\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
|
@ -1,13 +0,0 @@
|
||||||
#
|
|
||||||
# For a description of the syntax of this configuration file,
|
|
||||||
# see misc/tools/kconfig-language.txt.
|
|
||||||
#
|
|
||||||
|
|
||||||
config EXAMPLES_MOUNT
|
|
||||||
bool "File system mount example"
|
|
||||||
default n
|
|
||||||
---help---
|
|
||||||
Enable the file system mount example
|
|
||||||
|
|
||||||
if EXAMPLES_MOUNT
|
|
||||||
endif
|
|
|
@ -1,96 +0,0 @@
|
||||||
############################################################################
|
|
||||||
# apps/Makefile
|
|
||||||
#
|
|
||||||
# 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
|
|
||||||
# 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)/.config
|
|
||||||
-include $(TOPDIR)/Make.defs
|
|
||||||
include $(APPDIR)/Make.defs
|
|
||||||
|
|
||||||
# mount() test
|
|
||||||
|
|
||||||
ASRCS =
|
|
||||||
CSRCS = mount_main.c ramdisk.c
|
|
||||||
|
|
||||||
AOBJS = $(ASRCS:.S=$(OBJEXT))
|
|
||||||
COBJS = $(CSRCS:.c=$(OBJEXT))
|
|
||||||
|
|
||||||
SRCS = $(ASRCS) $(CSRCS)
|
|
||||||
OBJS = $(AOBJS) $(COBJS)
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
|
|
||||||
BIN = ..\..\libapps$(LIBEXT)
|
|
||||||
else
|
|
||||||
ifeq ($(WINTOOL),y)
|
|
||||||
BIN = ..\\..\\libapps$(LIBEXT)
|
|
||||||
else
|
|
||||||
BIN = ../../libapps$(LIBEXT)
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
ROOTDEPPATH = --dep-path .
|
|
||||||
|
|
||||||
# Common build
|
|
||||||
|
|
||||||
VPATH =
|
|
||||||
|
|
||||||
all: .built
|
|
||||||
.PHONY: clean depend distclean
|
|
||||||
|
|
||||||
$(AOBJS): %$(OBJEXT): %.S
|
|
||||||
$(call ASSEMBLE, $<, $@)
|
|
||||||
|
|
||||||
$(COBJS): %$(OBJEXT): %.c
|
|
||||||
$(call COMPILE, $<, $@)
|
|
||||||
|
|
||||||
.built: $(OBJS)
|
|
||||||
$(call ARCHIVE, $(BIN), $(OBJS))
|
|
||||||
@touch .built
|
|
||||||
|
|
||||||
context:
|
|
||||||
|
|
||||||
.depend: Makefile $(SRCS)
|
|
||||||
@$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
|
|
||||||
@touch $@
|
|
||||||
|
|
||||||
depend: .depend
|
|
||||||
|
|
||||||
clean:
|
|
||||||
$(call DELFILE, .built)
|
|
||||||
$(call CLEAN)
|
|
||||||
|
|
||||||
distclean: clean
|
|
||||||
$(call DELFILE, Make.dep)
|
|
||||||
$(call DELFILE, .depend)
|
|
||||||
|
|
||||||
-include Make.dep
|
|
|
@ -1,96 +0,0 @@
|
||||||
/****************************************************************************
|
|
||||||
* examples/mount/mount.h
|
|
||||||
*
|
|
||||||
* Copyright (C) 2008 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 __EXAMPLES_MOUNT_MOUNT_H
|
|
||||||
#define __EXAMPLES_MOUNT_MOUNT_H
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Included Files
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#include <nuttx/config.h>
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Definitions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/* Configure the test */
|
|
||||||
|
|
||||||
#if defined(CONFIG_EXAMPLES_MOUNT_DEVNAME)
|
|
||||||
# if !defined(CONFIG_FS_WRITABLE)
|
|
||||||
# error "Writable filesystem required in this configuration"
|
|
||||||
# endif
|
|
||||||
# undef CONFIG_EXAMPLES_MOUNT_NSECTORS
|
|
||||||
# undef CONFIG_EXAMPLES_MOUNT_SECTORSIZE
|
|
||||||
# undef CONFIG_EXAMPLES_MOUNT_RAMDEVNO
|
|
||||||
# define MOUNT_DEVNAME CONFIG_EXAMPLES_MOUNT_DEVNAME
|
|
||||||
#else
|
|
||||||
# if !defined(CONFIG_FS_FAT)
|
|
||||||
# error "CONFIG_FS_FAT required in this configuration"
|
|
||||||
# endif
|
|
||||||
# if !defined(CONFIG_EXAMPLES_MOUNT_SECTORSIZE)
|
|
||||||
# define CONFIG_EXAMPLES_MOUNT_SECTORSIZE 512
|
|
||||||
# endif
|
|
||||||
# if !defined(CONFIG_EXAMPLES_MOUNT_NSECTORS)
|
|
||||||
# define CONFIG_EXAMPLES_MOUNT_NSECTORS 2048
|
|
||||||
# endif
|
|
||||||
# if !defined(CONFIG_EXAMPLES_MOUNT_RAMDEVNO)
|
|
||||||
# define CONFIG_EXAMPLES_MOUNT_RAMDEVNO 0
|
|
||||||
# endif
|
|
||||||
# define STR_RAMDEVNO(m) #m
|
|
||||||
# define MKMOUNT_DEVNAME(m) "/dev/ram" STR_RAMDEVNO(m)
|
|
||||||
# define MOUNT_DEVNAME MKMOUNT_DEVNAME(CONFIG_EXAMPLES_MOUNT_RAMDEVNO)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Types
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Variables
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
extern const char g_source[]; /* Mount 'source' path */
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Function Prototypes
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#ifndef CONFIG_EXAMPLES_MOUNT_DEVNAME
|
|
||||||
extern int create_ramdisk(void);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* __EXAMPLES_MOUNT_MOUNT_H */
|
|
|
@ -1,754 +0,0 @@
|
||||||
/****************************************************************************
|
|
||||||
* examples/mount/mount_main.c
|
|
||||||
*
|
|
||||||
* Copyright (C) 2007-2009, 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/mount.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <sys/statfs.h>
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <dirent.h>
|
|
||||||
#include <errno.h>
|
|
||||||
|
|
||||||
#include "mount.h"
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Definitions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#define TEST_USE_STAT 1
|
|
||||||
#define TEST_SHOW_DIRECTORIES 1
|
|
||||||
#define TEST_USE_STATFS 1
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Types
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Data
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static const char g_mntdir[] = "/mnt";
|
|
||||||
static const char g_target[] = "/mnt/fs";
|
|
||||||
static const char g_filesystemtype[] = "vfat";
|
|
||||||
|
|
||||||
static const char g_testdir1[] = "/mnt/fs/TestDir";
|
|
||||||
static const char g_testdir2[] = "/mnt/fs/NewDir1";
|
|
||||||
static const char g_testdir3[] = "/mnt/fs/NewDir2";
|
|
||||||
static const char g_testdir4[] = "/mnt/fs/NewDir3";
|
|
||||||
#ifdef CONFIG_EXAMPLES_MOUNT_DEVNAME
|
|
||||||
static const char g_testfile1[] = "/mnt/fs/TestDir/TestFile.txt";
|
|
||||||
#endif
|
|
||||||
static const char g_testfile2[] = "/mnt/fs/TestDir/WrTest1.txt";
|
|
||||||
static const char g_testfile3[] = "/mnt/fs/NewDir1/WrTest2.txt";
|
|
||||||
static const char g_testfile4[] = "/mnt/fs/NewDir3/Renamed.txt";
|
|
||||||
static const char g_testmsg[] = "This is a write test";
|
|
||||||
|
|
||||||
static int g_nerrors = 0;
|
|
||||||
|
|
||||||
static char g_namebuffer[256];
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Data
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
const char g_source[] = MOUNT_DEVNAME;
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Functions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#ifdef TEST_USE_STAT
|
|
||||||
static void show_stat(const char *path, struct stat *ps)
|
|
||||||
{
|
|
||||||
printf("%s stat:\n", path);
|
|
||||||
printf("\tmode : %08x\n", ps->st_mode);
|
|
||||||
if (S_ISREG(ps->st_mode))
|
|
||||||
{
|
|
||||||
printf("\ttype : File\n");
|
|
||||||
}
|
|
||||||
else if (S_ISDIR(ps->st_mode))
|
|
||||||
{
|
|
||||||
printf("\ttype : Directory\n");
|
|
||||||
}
|
|
||||||
else if (S_ISCHR(ps->st_mode))
|
|
||||||
{
|
|
||||||
printf("\ttype : Character driver\n");
|
|
||||||
}
|
|
||||||
else if (S_ISBLK(ps->st_mode))
|
|
||||||
{
|
|
||||||
printf("\ttype : Block driver\n");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("\ttype : Unknown\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("\tsize : %d (bytes)\n", ps->st_size);
|
|
||||||
printf("\tblock size : %d (bytes)\n", ps->st_blksize);
|
|
||||||
printf("\tsize : %d (blocks)\n", ps->st_blocks);
|
|
||||||
printf("\taccess time : %d\n", ps->st_atime);
|
|
||||||
printf("\tmodify time : %d\n", ps->st_mtime);
|
|
||||||
printf("\tchange time : %d\n", ps->st_ctime);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: show_statfs
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#ifdef TEST_USE_STATFS
|
|
||||||
static void show_statfs(const char *path)
|
|
||||||
{
|
|
||||||
struct statfs buf;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
/* Try stat() against a file or directory. It should fail with expectederror */
|
|
||||||
|
|
||||||
printf("show_statfs: Try statfs(%s)\n", path);
|
|
||||||
ret = statfs(path, &buf);
|
|
||||||
if (ret == 0)
|
|
||||||
{
|
|
||||||
printf("show_statfs: statfs(%s) succeeded\n", path);
|
|
||||||
printf("\tFS Type : %0x\n", buf.f_type);
|
|
||||||
printf("\tBlock size : %d\n", buf.f_bsize);
|
|
||||||
printf("\tNumber of blocks : %d\n", buf.f_blocks);
|
|
||||||
printf("\tFree blocks : %d\n", buf.f_bfree);
|
|
||||||
printf("\tFree user blocks : %d\n", buf.f_bavail);
|
|
||||||
printf("\tNumber file nodes : %d\n", buf.f_files);
|
|
||||||
printf("\tFree file nodes : %d\n", buf.f_ffree);
|
|
||||||
printf("\tFile name length : %d\n", buf.f_namelen);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("show_statfs: ERROR statfs(%s) failed with errno=%d\n",
|
|
||||||
path, errno);
|
|
||||||
g_nerrors++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
# define show_statfs(p)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: show_directories
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#ifdef TEST_SHOW_DIRECTORIES
|
|
||||||
static void show_directories(const char *path, int indent)
|
|
||||||
{
|
|
||||||
DIR *dirp;
|
|
||||||
struct dirent *direntry;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
dirp = opendir(path);
|
|
||||||
if ( !dirp )
|
|
||||||
{
|
|
||||||
printf("show_directories: ERROR opendir(\"%s\") failed with errno=%d\n",
|
|
||||||
path, errno);
|
|
||||||
g_nerrors++;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (direntry = readdir(dirp); direntry; direntry = readdir(dirp))
|
|
||||||
{
|
|
||||||
for (i = 0; i < 2*indent; i++)
|
|
||||||
{
|
|
||||||
putchar(' ');
|
|
||||||
}
|
|
||||||
if (DIRENT_ISDIRECTORY(direntry->d_type))
|
|
||||||
{
|
|
||||||
char *subdir;
|
|
||||||
printf("%s/\n", direntry->d_name);
|
|
||||||
sprintf(g_namebuffer, "%s/%s", path, direntry->d_name);
|
|
||||||
subdir = strdup(g_namebuffer);
|
|
||||||
show_directories( subdir, indent + 1);
|
|
||||||
free(subdir);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("%s\n", direntry->d_name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
closedir(dirp);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
# define show_directories(p,i)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: fail_read_open
|
|
||||||
****************************************************************************/
|
|
||||||
#ifdef CONFIG_EXAMPLES_MOUNT_DEVNAME
|
|
||||||
static void fail_read_open(const char *path, int expectederror)
|
|
||||||
{
|
|
||||||
int fd;
|
|
||||||
|
|
||||||
printf("fail_read_open: Try open(%s) for reading\n", path);
|
|
||||||
|
|
||||||
fd = open(path, O_RDONLY);
|
|
||||||
if (fd >= 0)
|
|
||||||
{
|
|
||||||
printf("fail_read_open: ERROR open(%s) succeeded\n", path);
|
|
||||||
g_nerrors++;
|
|
||||||
close(fd);
|
|
||||||
}
|
|
||||||
else if (errno != expectederror)
|
|
||||||
{
|
|
||||||
printf("fail_read_open: ERROR open(%s) failed with errno=%d (expected %d)\n",
|
|
||||||
path, errno, expectederror);
|
|
||||||
g_nerrors++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: read_test_file
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static void read_test_file(const char *path)
|
|
||||||
{
|
|
||||||
char buffer[128];
|
|
||||||
int nbytes;
|
|
||||||
int fd;
|
|
||||||
|
|
||||||
/* Read a test file that is already on the test file system image */
|
|
||||||
|
|
||||||
printf("read_test_file: opening %s for reading\n", path);
|
|
||||||
|
|
||||||
fd = open(path, O_RDONLY);
|
|
||||||
if (fd < 0)
|
|
||||||
{
|
|
||||||
printf("read_test_file: ERROR failed to open %s, errno=%d\n",
|
|
||||||
path, errno);
|
|
||||||
g_nerrors++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
memset(buffer, 0, 128);
|
|
||||||
nbytes = read(fd, buffer, 128);
|
|
||||||
if (nbytes < 0)
|
|
||||||
{
|
|
||||||
printf("read_test_file: ERROR failed to read from %s, errno=%d\n",
|
|
||||||
path, errno);
|
|
||||||
g_nerrors++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
buffer[127]='\0';
|
|
||||||
printf("read_test_file: Read \"%s\" from %s\n", buffer, path);
|
|
||||||
}
|
|
||||||
close(fd);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: write_test_file
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static void write_test_file(const char *path)
|
|
||||||
{
|
|
||||||
int fd;
|
|
||||||
|
|
||||||
/* Write a test file into a pre-existing file on the test file system */
|
|
||||||
|
|
||||||
printf("write_test_file: opening %s for writing\n", path);
|
|
||||||
|
|
||||||
fd = open(path, O_WRONLY|O_CREAT|O_TRUNC, 0644);
|
|
||||||
if (fd < 0)
|
|
||||||
{
|
|
||||||
printf("write_test_file: ERROR failed to open %s for writing, errno=%d\n",
|
|
||||||
path, errno);
|
|
||||||
g_nerrors++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
int nbytes = write(fd, g_testmsg, strlen(g_testmsg));
|
|
||||||
if (nbytes < 0)
|
|
||||||
{
|
|
||||||
printf("write_test_file: ERROR failed to write to %s, errno=%d\n",
|
|
||||||
path, errno);
|
|
||||||
g_nerrors++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("write_test_file: wrote %d bytes to %s\n", nbytes, path);
|
|
||||||
}
|
|
||||||
close(fd);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: fail_mkdir
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static void fail_mkdir(const char *path, int expectederror)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
/* Try mkdir() against a file or directory. It should fail with expectederror */
|
|
||||||
|
|
||||||
printf("fail_mkdir: Try mkdir(%s)\n", path);
|
|
||||||
|
|
||||||
ret = mkdir(path, 0666);
|
|
||||||
if (ret == 0)
|
|
||||||
{
|
|
||||||
printf("fail_mkdir: ERROR mkdir(%s) succeeded\n", path);
|
|
||||||
g_nerrors++;
|
|
||||||
}
|
|
||||||
else if (errno != expectederror)
|
|
||||||
{
|
|
||||||
printf("fail_mkdir: ERROR mkdir(%s) failed with errno=%d (expected %d)\n",
|
|
||||||
path, errno, expectederror);
|
|
||||||
g_nerrors++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: succeed_mkdir
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static void succeed_mkdir(const char *path)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
printf("succeed_mkdir: Try mkdir(%s)\n", path);
|
|
||||||
|
|
||||||
ret = mkdir(path, 0666);
|
|
||||||
if (ret != 0)
|
|
||||||
{
|
|
||||||
printf("succeed_mkdir: ERROR mkdir(%s) failed with errno=%d\n",
|
|
||||||
path, errno);
|
|
||||||
g_nerrors++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: fail_rmdir
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static void fail_rmdir(const char *path, int expectederror)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
/* Try rmdir() against a file or directory. It should fail with expectederror */
|
|
||||||
|
|
||||||
printf("fail_rmdir: Try rmdir(%s)\n", path);
|
|
||||||
|
|
||||||
ret = rmdir(path);
|
|
||||||
if (ret == 0)
|
|
||||||
{
|
|
||||||
printf("fail_rmdir: ERROR rmdir(%s) succeeded\n", path);
|
|
||||||
g_nerrors++;
|
|
||||||
}
|
|
||||||
else if (errno != expectederror)
|
|
||||||
{
|
|
||||||
printf("fail_rmdir: ERROR rmdir(%s) failed with errno=%d (expected %d)\n",
|
|
||||||
path, errno, expectederror);
|
|
||||||
g_nerrors++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: succeed_rmdir
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static void succeed_rmdir(const char *path)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
printf("succeed_rmdir: Try rmdir(%s)\n", path);
|
|
||||||
|
|
||||||
ret = rmdir(path);
|
|
||||||
if (ret != 0)
|
|
||||||
{
|
|
||||||
printf("succeed_rmdir: ERROR rmdir(%s) failed with errno=%d\n",
|
|
||||||
path, errno);
|
|
||||||
g_nerrors++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: fail_unlink
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static void fail_unlink(const char *path, int expectederror)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
/* Try unlink() against a file or directory. It should fail with expectederror */
|
|
||||||
|
|
||||||
printf("fail_unlink: Try unlink(%s)\n", path);
|
|
||||||
|
|
||||||
ret = unlink(path);
|
|
||||||
if (ret == 0)
|
|
||||||
{
|
|
||||||
printf("fail_unlink: ERROR unlink(%s) succeeded\n", path);
|
|
||||||
g_nerrors++;
|
|
||||||
}
|
|
||||||
else if (errno != expectederror)
|
|
||||||
{
|
|
||||||
printf("fail_unlink: ERROR unlink(%s) failed with errno=%d (expected %d)\n",
|
|
||||||
path, errno, expectederror);
|
|
||||||
g_nerrors++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: succeed_unlink
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static void succeed_unlink(const char *path)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
/* Try unlink() against the test file. It should succeed. */
|
|
||||||
|
|
||||||
printf("succeed_unlink: Try unlink(%s)\n", path);
|
|
||||||
|
|
||||||
ret = unlink(path);
|
|
||||||
if (ret != 0)
|
|
||||||
{
|
|
||||||
printf("succeed_unlink: ERROR unlink(%s) failed with errno=%d\n",
|
|
||||||
path, errno);
|
|
||||||
g_nerrors++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: fail_rename
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static void fail_rename(const char *oldpath, const char *newpath, int expectederror)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
/* Try rename() against a file or directory. It should fail with expectederror */
|
|
||||||
|
|
||||||
printf("fail_rename: Try rename(%s->%s)\n", oldpath, newpath);
|
|
||||||
|
|
||||||
ret = rename(oldpath, newpath);
|
|
||||||
if (ret == 0)
|
|
||||||
{
|
|
||||||
printf("fail_rename: ERROR rename(%s->%s) succeeded\n",
|
|
||||||
oldpath, newpath);
|
|
||||||
g_nerrors++;
|
|
||||||
}
|
|
||||||
else if (errno != expectederror)
|
|
||||||
{
|
|
||||||
printf("fail_rename: ERROR rename(%s->%s) failed with errno=%d (expected %d)\n",
|
|
||||||
oldpath, newpath, errno, expectederror);
|
|
||||||
g_nerrors++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: succeed_rename
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static void succeed_rename(const char *oldpath, const char *newpath)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
printf("succeed_rename: Try rename(%s->%s)\n", oldpath, newpath);
|
|
||||||
|
|
||||||
ret = rename(oldpath, newpath);
|
|
||||||
if (ret != 0)
|
|
||||||
{
|
|
||||||
printf("succeed_rename: ERROR rename(%s->%s) failed with errno=%d\n",
|
|
||||||
oldpath, newpath, errno);
|
|
||||||
g_nerrors++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: fail_stat
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#ifdef TEST_USE_STAT
|
|
||||||
static void fail_stat(const char *path, int expectederror)
|
|
||||||
{
|
|
||||||
struct stat buf;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
/* Try stat() against a file or directory. It should fail with expectederror */
|
|
||||||
|
|
||||||
printf("fail_stat: Try stat(%s)\n", path);
|
|
||||||
|
|
||||||
ret = stat(path, &buf);
|
|
||||||
if (ret == 0)
|
|
||||||
{
|
|
||||||
printf("fail_stat: ERROR stat(%s) succeeded\n", path);
|
|
||||||
show_stat(path, &buf);
|
|
||||||
g_nerrors++;
|
|
||||||
}
|
|
||||||
else if (errno != expectederror)
|
|
||||||
{
|
|
||||||
printf("fail_stat: ERROR stat(%s) failed with errno=%d (expected %d)\n",
|
|
||||||
path, errno, expectederror);
|
|
||||||
g_nerrors++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
# define fail_stat(p,e);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: succeed_stat
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#ifdef TEST_USE_STAT
|
|
||||||
static void succeed_stat(const char *path)
|
|
||||||
{
|
|
||||||
struct stat buf;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
printf("succeed_stat: Try stat(%s)\n", path);
|
|
||||||
|
|
||||||
ret = stat(path, &buf);
|
|
||||||
if (ret != 0)
|
|
||||||
{
|
|
||||||
printf("succeed_stat: ERROR stat(%s) failed with errno=%d\n",
|
|
||||||
path, errno);
|
|
||||||
g_nerrors++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("succeed_stat: stat(%s) succeeded\n", path);
|
|
||||||
show_stat(path, &buf);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
#define succeed_stat(p)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Functions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: mount_main
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
int mount_main(int argc, char *argv[])
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
#ifndef CONFIG_EXAMPLES_MOUNT_DEVNAME
|
|
||||||
/* Create a RAM disk for the test */
|
|
||||||
|
|
||||||
ret = create_ramdisk();
|
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
printf("mount_main: ERROR failed to create RAM disk\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Mount the test file system (see arch/sim/src/up_deviceimage.c */
|
|
||||||
|
|
||||||
printf("mount_main: mounting %s filesystem at target=%s with source=%s\n",
|
|
||||||
g_filesystemtype, g_target, g_source);
|
|
||||||
|
|
||||||
ret = mount(g_source, g_target, g_filesystemtype, 0, NULL);
|
|
||||||
printf("mount_main: mount() returned %d\n", ret);
|
|
||||||
|
|
||||||
if (ret == 0)
|
|
||||||
{
|
|
||||||
show_statfs(g_mntdir);
|
|
||||||
show_statfs(g_target);
|
|
||||||
|
|
||||||
#ifdef CONFIG_EXAMPLES_MOUNT_DEVNAME
|
|
||||||
/* Read a test file that is already on the test file system image */
|
|
||||||
|
|
||||||
show_directories("", 0);
|
|
||||||
succeed_stat(g_testfile1);
|
|
||||||
show_statfs(g_testfile1);
|
|
||||||
read_test_file(g_testfile1);
|
|
||||||
#else
|
|
||||||
/* Create the test directory that would have been on the canned filesystem */
|
|
||||||
|
|
||||||
succeed_mkdir(g_testdir1);
|
|
||||||
show_directories("", 0);
|
|
||||||
succeed_stat(g_testdir1);
|
|
||||||
show_statfs(g_testdir1);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Write a test file into a pre-existing directory on the test file system */
|
|
||||||
|
|
||||||
fail_stat(g_testfile2, ENOENT);
|
|
||||||
write_test_file(g_testfile2);
|
|
||||||
show_directories("", 0);
|
|
||||||
succeed_stat(g_testfile2);
|
|
||||||
show_statfs(g_testfile2);
|
|
||||||
|
|
||||||
/* Read the file that we just wrote */
|
|
||||||
|
|
||||||
read_test_file(g_testfile2);
|
|
||||||
|
|
||||||
/* Try rmdir() against a file on the directory. It should fail with ENOTDIR */
|
|
||||||
#ifdef CONFIG_EXAMPLES_MOUNT_DEVNAME
|
|
||||||
fail_rmdir(g_testfile1, ENOTDIR);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Try rmdir() against the test directory. It should fail with ENOTEMPTY */
|
|
||||||
|
|
||||||
fail_rmdir(g_testdir1, ENOTEMPTY);
|
|
||||||
|
|
||||||
/* Try unlink() against the test directory. It should fail with EISDIR */
|
|
||||||
|
|
||||||
fail_unlink(g_testdir1, EISDIR);
|
|
||||||
|
|
||||||
/* Try unlink() against the test file1. It should succeed. */
|
|
||||||
#ifdef CONFIG_EXAMPLES_MOUNT_DEVNAME
|
|
||||||
succeed_unlink(g_testfile1);
|
|
||||||
fail_stat(g_testfile1, ENOENT);
|
|
||||||
show_directories("", 0);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Attempt to open testfile1 should fail with ENOENT */
|
|
||||||
#ifdef CONFIG_EXAMPLES_MOUNT_DEVNAME
|
|
||||||
fail_read_open(g_testfile1, ENOENT);
|
|
||||||
#endif
|
|
||||||
/* Try rmdir() against the test directory. It should still fail with ENOTEMPTY */
|
|
||||||
|
|
||||||
fail_rmdir(g_testdir1, ENOTEMPTY);
|
|
||||||
|
|
||||||
/* Try mkdir() against the test file2. It should fail with EEXIST. */
|
|
||||||
|
|
||||||
fail_mkdir(g_testfile2, EEXIST);
|
|
||||||
|
|
||||||
/* Try unlink() against the test file2. It should succeed. */
|
|
||||||
|
|
||||||
succeed_unlink(g_testfile2);
|
|
||||||
show_directories("", 0);
|
|
||||||
fail_stat(g_testfile2, ENOENT);
|
|
||||||
|
|
||||||
/* Try mkdir() against the test dir1. It should fail with EEXIST. */
|
|
||||||
|
|
||||||
fail_mkdir(g_testdir1, EEXIST);
|
|
||||||
|
|
||||||
/* Try rmdir() against the test directory. mkdir should now succeed. */
|
|
||||||
|
|
||||||
succeed_rmdir(g_testdir1);
|
|
||||||
show_directories("", 0);
|
|
||||||
fail_stat(g_testdir1, ENOENT);
|
|
||||||
|
|
||||||
/* Try mkdir() against the test dir2. It should succeed */
|
|
||||||
|
|
||||||
succeed_mkdir(g_testdir2);
|
|
||||||
show_directories("", 0);
|
|
||||||
succeed_stat(g_testdir2);
|
|
||||||
show_statfs(g_testdir2);
|
|
||||||
|
|
||||||
/* Try mkdir() against the test dir2. It should fail with EXIST */
|
|
||||||
|
|
||||||
fail_mkdir(g_testdir2, EEXIST);
|
|
||||||
|
|
||||||
/* Write a test file into a new directory on the test file system */
|
|
||||||
|
|
||||||
fail_stat(g_testfile3, ENOENT);
|
|
||||||
write_test_file(g_testfile3);
|
|
||||||
show_directories("", 0);
|
|
||||||
succeed_stat(g_testfile3);
|
|
||||||
show_statfs(g_testfile3);
|
|
||||||
|
|
||||||
/* Read the file that we just wrote */
|
|
||||||
|
|
||||||
read_test_file(g_testfile3);
|
|
||||||
|
|
||||||
/* Use mkdir() to create test dir3. It should succeed */
|
|
||||||
|
|
||||||
fail_stat(g_testdir3, ENOENT);
|
|
||||||
succeed_mkdir(g_testdir3);
|
|
||||||
show_directories("", 0);
|
|
||||||
succeed_stat(g_testdir3);
|
|
||||||
show_statfs(g_testdir3);
|
|
||||||
|
|
||||||
/* Try rename() on the root directory. Should fail with EXDEV*/
|
|
||||||
|
|
||||||
fail_rename(g_target, g_testdir4, EXDEV);
|
|
||||||
|
|
||||||
/* Try rename() to an existing directory. Should fail with EEXIST */
|
|
||||||
|
|
||||||
fail_rename(g_testdir2, g_testdir3, EEXIST);
|
|
||||||
|
|
||||||
/* Try rename() to a non-existing directory. Should succeed */
|
|
||||||
|
|
||||||
fail_stat(g_testdir4, ENOENT);
|
|
||||||
succeed_rename(g_testdir3, g_testdir4);
|
|
||||||
show_directories("", 0);
|
|
||||||
fail_stat(g_testdir3, ENOENT);
|
|
||||||
succeed_stat(g_testdir4);
|
|
||||||
show_statfs(g_testdir4);
|
|
||||||
|
|
||||||
/* Try rename() of file. Should work. */
|
|
||||||
|
|
||||||
fail_stat(g_testfile4, ENOENT);
|
|
||||||
succeed_rename(g_testfile3, g_testfile4);
|
|
||||||
show_directories("", 0);
|
|
||||||
fail_stat(g_testfile3, ENOENT);
|
|
||||||
succeed_stat(g_testfile4);
|
|
||||||
show_statfs(g_testfile4);
|
|
||||||
|
|
||||||
/* Make sure that we can still read the renamed file */
|
|
||||||
|
|
||||||
read_test_file(g_testfile4);
|
|
||||||
|
|
||||||
/* Unmount the file system */
|
|
||||||
|
|
||||||
printf("mount_main: Try unmount(%s)\n", g_target);
|
|
||||||
|
|
||||||
ret = umount(g_target);
|
|
||||||
if (ret != 0)
|
|
||||||
{
|
|
||||||
printf("mount_main: ERROR umount() failed, errno %d\n", errno);
|
|
||||||
g_nerrors++;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("mount_main: %d errors reported\n", g_nerrors);
|
|
||||||
}
|
|
||||||
|
|
||||||
fflush(stdout);
|
|
||||||
return 0;
|
|
||||||
}
|
|
|
@ -1,141 +0,0 @@
|
||||||
/****************************************************************************
|
|
||||||
* examples/mount/ramdisk.c
|
|
||||||
*
|
|
||||||
* Copyright (C) 2008-2009 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 <stdbool.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <errno.h>
|
|
||||||
|
|
||||||
#include <nuttx/ramdisk.h>
|
|
||||||
#include <nuttx/fs/mkfatfs.h>
|
|
||||||
|
|
||||||
#include "mount.h"
|
|
||||||
|
|
||||||
#ifndef CONFIG_EXAMPLES_MOUNT_DEVNAME
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Definitions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#define BUFFER_SIZE (CONFIG_EXAMPLES_MOUNT_NSECTORS*CONFIG_EXAMPLES_MOUNT_SECTORSIZE)
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Types
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Function Prototypes
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Data
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static struct fat_format_s g_fmt = FAT_FORMAT_INITIALIZER;
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Functions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Functions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: create_ramdisk
|
|
||||||
*
|
|
||||||
* Description:
|
|
||||||
* Create a RAM disk of the specified size formatting with a FAT file
|
|
||||||
* system
|
|
||||||
*
|
|
||||||
* Input Parameters:
|
|
||||||
* None
|
|
||||||
*
|
|
||||||
* Return:
|
|
||||||
* Zero on success, a negated errno on failure.
|
|
||||||
*
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
int create_ramdisk(void)
|
|
||||||
{
|
|
||||||
char *pbuffer;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
/* Allocate a buffer to hold the file system image. */
|
|
||||||
|
|
||||||
pbuffer = (char*)malloc(BUFFER_SIZE);
|
|
||||||
if (!pbuffer)
|
|
||||||
{
|
|
||||||
printf("create_ramdisk: Failed to allocate ramdisk of size %d\n",
|
|
||||||
BUFFER_SIZE);
|
|
||||||
return -ENOMEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Register a RAMDISK device to manage this RAM image */
|
|
||||||
|
|
||||||
ret = ramdisk_register(CONFIG_EXAMPLES_MOUNT_RAMDEVNO,
|
|
||||||
pbuffer,
|
|
||||||
CONFIG_EXAMPLES_MOUNT_NSECTORS,
|
|
||||||
CONFIG_EXAMPLES_MOUNT_SECTORSIZE,
|
|
||||||
true);
|
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
printf("create_ramdisk: Failed to register ramdisk at %s: %d\n",
|
|
||||||
g_source, -ret);
|
|
||||||
free(pbuffer);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Create a FAT filesystem on the ramdisk */
|
|
||||||
|
|
||||||
ret = mkfatfs(g_source, &g_fmt);
|
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
printf("create_ramdisk: Failed to create FAT filesystem on ramdisk at %s\n",
|
|
||||||
g_source);
|
|
||||||
/* free(pbuffer); -- RAM disk is registered */
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#endif /* !CONFIG_EXAMPLES_MOUNT_DEVNAME */
|
|
|
@ -1,15 +0,0 @@
|
||||||
#
|
|
||||||
# For a description of the syntax of this configuration file,
|
|
||||||
# see misc/tools/kconfig-language.txt.
|
|
||||||
#
|
|
||||||
|
|
||||||
config EXAMPLES_NSH
|
|
||||||
bool "NuttShell (NSH) example"
|
|
||||||
default n
|
|
||||||
select NSH_LIBRARY
|
|
||||||
select SYSTEM_READLINE
|
|
||||||
---help---
|
|
||||||
Enable the NuttShell (NSH) example
|
|
||||||
|
|
||||||
if EXAMPLES_NSH
|
|
||||||
endif
|
|
|
@ -1,98 +0,0 @@
|
||||||
############################################################################
|
|
||||||
# apps/examples/nsh/Makefile
|
|
||||||
#
|
|
||||||
# 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
|
|
||||||
# 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)/.config
|
|
||||||
-include $(TOPDIR)/Make.defs
|
|
||||||
include $(APPDIR)/Make.defs
|
|
||||||
|
|
||||||
# NuttShell (NSH) Example
|
|
||||||
|
|
||||||
ASRCS =
|
|
||||||
CSRCS = nsh_main.c
|
|
||||||
|
|
||||||
AOBJS = $(ASRCS:.S=$(OBJEXT))
|
|
||||||
COBJS = $(CSRCS:.c=$(OBJEXT))
|
|
||||||
|
|
||||||
SRCS = $(ASRCS) $(CSRCS)
|
|
||||||
OBJS = $(AOBJS) $(COBJS)
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
|
|
||||||
BIN = ..\..\libapps$(LIBEXT)
|
|
||||||
else
|
|
||||||
ifeq ($(WINTOOL),y)
|
|
||||||
BIN = ..\\..\\libapps$(LIBEXT)
|
|
||||||
else
|
|
||||||
BIN = ../../libapps$(LIBEXT)
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
ROOTDEPPATH = --dep-path .
|
|
||||||
|
|
||||||
# Common build
|
|
||||||
|
|
||||||
VPATH =
|
|
||||||
|
|
||||||
MAXOPTIMIZATION = -Os
|
|
||||||
|
|
||||||
all: .built
|
|
||||||
.PHONY: clean depend distclean
|
|
||||||
|
|
||||||
$(AOBJS): %$(OBJEXT): %.S
|
|
||||||
$(call ASSEMBLE, $<, $@)
|
|
||||||
|
|
||||||
$(COBJS): %$(OBJEXT): %.c
|
|
||||||
$(call COMPILE, $<, $@)
|
|
||||||
|
|
||||||
.built: $(OBJS)
|
|
||||||
$(call ARCHIVE, $(BIN), $(OBJS))
|
|
||||||
@touch .built
|
|
||||||
|
|
||||||
context:
|
|
||||||
|
|
||||||
.depend: Makefile $(SRCS)
|
|
||||||
@$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
|
|
||||||
@touch $@
|
|
||||||
|
|
||||||
depend: .depend
|
|
||||||
|
|
||||||
clean:
|
|
||||||
$(call DELFILE, .built)
|
|
||||||
$(call CLEAN)
|
|
||||||
|
|
||||||
distclean: clean
|
|
||||||
$(call DELFILE, Make.dep)
|
|
||||||
$(call DELFILE, .depend)
|
|
||||||
|
|
||||||
-include Make.dep
|
|
|
@ -1,174 +0,0 @@
|
||||||
/****************************************************************************
|
|
||||||
* examples/nsh/nsh_main.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 <nuttx/config.h>
|
|
||||||
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <sched.h>
|
|
||||||
#include <errno.h>
|
|
||||||
|
|
||||||
#include <nuttx/arch.h>
|
|
||||||
#if defined(CONFIG_FS_BINFS) && (CONFIG_BUILTIN)
|
|
||||||
#include <nuttx/binfmt/builtin.h>
|
|
||||||
#endif
|
|
||||||
#if defined(CONFIG_LIBC_EXECFUNCS) && defined(CONFIG_EXECFUNCS_SYMTAB)
|
|
||||||
#include <nuttx/binfmt/symtab.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <apps/nsh.h>
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Pre-processor Definitions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/* The NSH telnet console requires networking support (and TCP/IP) */
|
|
||||||
|
|
||||||
#ifndef CONFIG_NET
|
|
||||||
# undef CONFIG_NSH_TELNET
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Types
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Function Prototypes
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Data
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Data
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/* If posix_spawn() is enabled as required for CONFIG_NSH_FILE_APPS, then
|
|
||||||
* a symbol table is needed by the internals of posix_spawn(). The symbol
|
|
||||||
* table is needed to support ELF and NXFLAT binaries to dynamically link to
|
|
||||||
* the base code. However, if only the BINFS file system is supported, then
|
|
||||||
* no Makefile is needed.
|
|
||||||
*
|
|
||||||
* This is a kludge to plug the missing file system in the case where BINFS
|
|
||||||
* is used. REVISIT: This will, of course, be in the way if you want to
|
|
||||||
* support ELF or NXFLAT binaries!
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if defined(CONFIG_LIBC_EXECFUNCS) && defined(CONFIG_EXECFUNCS_SYMTAB)
|
|
||||||
const struct symtab_s CONFIG_EXECFUNCS_SYMTAB[1];
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Functions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Functions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: nsh_main
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
int nsh_main(int argc, char *argv[])
|
|
||||||
{
|
|
||||||
int exitval = 0;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
/* Call all C++ static constructors */
|
|
||||||
|
|
||||||
#if defined(CONFIG_HAVE_CXX) && defined(CONFIG_HAVE_CXXINITIALIZE)
|
|
||||||
up_cxxinitialize();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Make sure that we are using our symbol take */
|
|
||||||
|
|
||||||
#if defined(CONFIG_LIBC_EXECFUNCS) && defined(CONFIG_EXECFUNCS_SYMTAB)
|
|
||||||
exec_setsymtab(CONFIG_EXECFUNCS_SYMTAB, 0);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Register the BINFS file system */
|
|
||||||
|
|
||||||
#if defined(CONFIG_FS_BINFS) && (CONFIG_BUILTIN)
|
|
||||||
ret = builtin_initialize();
|
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "ERROR: builtin_initialize failed: %d\n", ret);
|
|
||||||
exitval = 1;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Initialize the NSH library */
|
|
||||||
|
|
||||||
nsh_initialize();
|
|
||||||
|
|
||||||
/* If the Telnet console is selected as a front-end, then start the
|
|
||||||
* Telnet daemon.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef CONFIG_NSH_TELNET
|
|
||||||
ret = nsh_telnetstart();
|
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
/* The daemon is NOT running. Report the the error then fail...
|
|
||||||
* either with the serial console up or just exiting.
|
|
||||||
*/
|
|
||||||
|
|
||||||
fprintf(stderr, "ERROR: Failed to start TELNET daemon: %d\n", ret);
|
|
||||||
exitval = 1;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* If the serial console front end is selected, then run it on this thread */
|
|
||||||
|
|
||||||
#ifdef CONFIG_NSH_CONSOLE
|
|
||||||
ret = nsh_consolemain(0, NULL);
|
|
||||||
|
|
||||||
/* nsh_consolemain() should not return. So if we get here, something
|
|
||||||
* is wrong.
|
|
||||||
*/
|
|
||||||
|
|
||||||
fprintf(stderr, "ERROR: nsh_consolemain() returned: %d\n", ret);
|
|
||||||
exitval = 1;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return exitval;
|
|
||||||
}
|
|
|
@ -1,13 +0,0 @@
|
||||||
#
|
|
||||||
# For a description of the syntax of this configuration file,
|
|
||||||
# see misc/tools/kconfig-language.txt.
|
|
||||||
#
|
|
||||||
|
|
||||||
config EXAMPLES_NULL
|
|
||||||
bool "NULL example"
|
|
||||||
default n
|
|
||||||
---help---
|
|
||||||
Enable the NULL example
|
|
||||||
|
|
||||||
if EXAMPLES_NULL
|
|
||||||
endif
|
|
|
@ -1,96 +0,0 @@
|
||||||
############################################################################
|
|
||||||
# examples/null/Makefile
|
|
||||||
#
|
|
||||||
# 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
|
|
||||||
# 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)/.config
|
|
||||||
-include $(TOPDIR)/Make.defs
|
|
||||||
include $(APPDIR)/Make.defs
|
|
||||||
|
|
||||||
# The smallest thing you can build -- the NULL example.
|
|
||||||
|
|
||||||
ASRCS =
|
|
||||||
CSRCS = null_main.c
|
|
||||||
|
|
||||||
AOBJS = $(ASRCS:.S=$(OBJEXT))
|
|
||||||
COBJS = $(CSRCS:.c=$(OBJEXT))
|
|
||||||
|
|
||||||
SRCS = $(ASRCS) $(CSRCS)
|
|
||||||
OBJS = $(AOBJS) $(COBJS)
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
|
|
||||||
BIN = ..\..\libapps$(LIBEXT)
|
|
||||||
else
|
|
||||||
ifeq ($(WINTOOL),y)
|
|
||||||
BIN = ..\\..\\libapps$(LIBEXT)
|
|
||||||
else
|
|
||||||
BIN = ../../libapps$(LIBEXT)
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
ROOTDEPPATH = --dep-path .
|
|
||||||
|
|
||||||
# Common build
|
|
||||||
|
|
||||||
VPATH =
|
|
||||||
|
|
||||||
all: .built
|
|
||||||
.PHONY: clean depend distclean
|
|
||||||
|
|
||||||
$(AOBJS): %$(OBJEXT): %.S
|
|
||||||
$(call ASSEMBLE, $<, $@)
|
|
||||||
|
|
||||||
$(COBJS): %$(OBJEXT): %.c
|
|
||||||
$(call COMPILE, $<, $@)
|
|
||||||
|
|
||||||
.built: $(OBJS)
|
|
||||||
$(call ARCHIVE, $(BIN), $(OBJS))
|
|
||||||
@touch .built
|
|
||||||
|
|
||||||
context:
|
|
||||||
|
|
||||||
.depend: Makefile $(SRCS)
|
|
||||||
@$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
|
|
||||||
@touch $@
|
|
||||||
|
|
||||||
depend: .depend
|
|
||||||
|
|
||||||
clean:
|
|
||||||
$(call DELFILE, .built)
|
|
||||||
$(call CLEAN)
|
|
||||||
|
|
||||||
distclean: clean
|
|
||||||
$(call DELFILE, Make.dep)
|
|
||||||
$(call DELFILE, .depend)
|
|
||||||
|
|
||||||
-include Make.dep
|
|
|
@ -1,67 +0,0 @@
|
||||||
/****************************************************************************
|
|
||||||
* examples/null/null_main.c
|
|
||||||
*
|
|
||||||
* Copyright (C) 2007, 2009, 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 Gregory Nutt 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
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Definitions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Types
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Data
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Functions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Functions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: null_main
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
int null_main(int argc, char *argv[])
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
|
@ -1,69 +0,0 @@
|
||||||
#
|
|
||||||
# For a description of the syntax of this configuration file,
|
|
||||||
# see misc/tools/kconfig-language.txt.
|
|
||||||
#
|
|
||||||
|
|
||||||
config EXAMPLES_OSTEST
|
|
||||||
bool "OS test example"
|
|
||||||
default n
|
|
||||||
---help---
|
|
||||||
Enable the OS test example
|
|
||||||
|
|
||||||
if EXAMPLES_OSTEST
|
|
||||||
|
|
||||||
config EXAMPLES_OSTEST_BUILTIN
|
|
||||||
bool "NSH built-in application"
|
|
||||||
default y if NSH_LIBRARY
|
|
||||||
default n if !NSH_LIBRARY
|
|
||||||
---help---
|
|
||||||
Build the OS test example as an NSH built-in application.
|
|
||||||
|
|
||||||
config EXAMPLES_OSTEST_LOOPS
|
|
||||||
int "OS test loop"
|
|
||||||
default 1
|
|
||||||
---help---
|
|
||||||
Used to control the number of executions of the test. If undefined, the test
|
|
||||||
executes one time. If defined to be zero, the test runs forever.
|
|
||||||
|
|
||||||
config EXAMPLES_OSTEST_STACKSIZE
|
|
||||||
int "OS test stack size"
|
|
||||||
default 8192
|
|
||||||
---help---
|
|
||||||
Size of the stack used to create the ostest task. Default is 8192.
|
|
||||||
|
|
||||||
config EXAMPLES_OSTEST_NBARRIER_THREADS
|
|
||||||
int "Number of barrier threads"
|
|
||||||
default 8
|
|
||||||
---help---
|
|
||||||
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
|
|
||||||
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
|
|
|
@ -1,161 +0,0 @@
|
||||||
############################################################################
|
|
||||||
# apps/examples/ostest/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)/.config
|
|
||||||
-include $(TOPDIR)/Make.defs
|
|
||||||
include $(APPDIR)/Make.defs
|
|
||||||
|
|
||||||
# ostest built-in application info
|
|
||||||
|
|
||||||
APPNAME = ostest
|
|
||||||
PRIORITY = SCHED_PRIORITY_DEFAULT
|
|
||||||
STACKSIZE = 2048
|
|
||||||
|
|
||||||
# NuttX OS Test
|
|
||||||
|
|
||||||
ASRCS =
|
|
||||||
CSRCS = ostest_main.c dev_null.c
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_ARCH_FPU),y)
|
|
||||||
CSRCS += fpu.c
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_SCHED_WAITPID),y)
|
|
||||||
CSRCS += waitpid.c
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifneq ($(CONFIG_DISABLE_PTHREAD),y)
|
|
||||||
CSRCS += cancel.c cond.c mutex.c sem.c barrier.c
|
|
||||||
ifneq ($(CONFIG_RR_INTERVAL),0)
|
|
||||||
CSRCS += roundrobin.c
|
|
||||||
endif # CONFIG_RR_INTERVAL
|
|
||||||
ifeq ($(CONFIG_MUTEX_TYPES),y)
|
|
||||||
CSRCS += rmutex.c
|
|
||||||
endif # CONFIG_MUTEX_TYPES
|
|
||||||
endif # CONFIG_DISABLE_PTHREAD
|
|
||||||
|
|
||||||
ifneq ($(CONFIG_DISABLE_SIGNALS),y)
|
|
||||||
CSRCS += sighand.c
|
|
||||||
ifneq ($(CONFIG_DISABLE_PTHREAD),y)
|
|
||||||
ifneq ($(CONFIG_DISABLE_CLOCK),y)
|
|
||||||
CSRCS += timedwait.c
|
|
||||||
endif # CONFIG_DISABLE_CLOCK
|
|
||||||
endif # CONFIG_DISABLE_PTHREAD
|
|
||||||
endif # CONFIG_DISABLE_SIGNALS
|
|
||||||
|
|
||||||
ifneq ($(CONFIG_DISABLE_MQUEUE),y)
|
|
||||||
ifneq ($(CONFIG_DISABLE_PTHREAD),y)
|
|
||||||
CSRCS += mqueue.c
|
|
||||||
ifneq ($(CONFIG_DISABLE_CLOCK),y)
|
|
||||||
CSRCS += timedmqueue.c
|
|
||||||
endif # CONFIG_DISABLE_CLOCK
|
|
||||||
endif # CONFIG_DISABLE_PTHREAD
|
|
||||||
endif # CONFIG_DISABLE_MQUEUE
|
|
||||||
|
|
||||||
ifneq ($(CONFIG_DISABLE_POSIX_TIMERS),y)
|
|
||||||
CSRCS += posixtimer.c
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_ARCH_HAVE_VFORK),y)
|
|
||||||
CSRCS += vfork.c
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifneq ($(CONFIG_DISABLE_SIGNALS),y)
|
|
||||||
ifneq ($(CONFIG_DISABLE_PTHREAD),y)
|
|
||||||
ifeq ($(CONFIG_PRIORITY_INHERITANCE),y)
|
|
||||||
CSRCS += prioinherit.c
|
|
||||||
endif # CONFIG_PRIORITY_INHERITANCE
|
|
||||||
endif # CONFIG_DISABLE_PTHREAD
|
|
||||||
endif # CONFIG_DISABLE_SIGNALS
|
|
||||||
|
|
||||||
AOBJS = $(ASRCS:.S=$(OBJEXT))
|
|
||||||
COBJS = $(CSRCS:.c=$(OBJEXT))
|
|
||||||
|
|
||||||
SRCS = $(ASRCS) $(CSRCS)
|
|
||||||
OBJS = $(AOBJS) $(COBJS)
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
|
|
||||||
BIN = ..\..\libapps$(LIBEXT)
|
|
||||||
else
|
|
||||||
ifeq ($(WINTOOL),y)
|
|
||||||
BIN = ..\\..\\libapps$(LIBEXT)
|
|
||||||
else
|
|
||||||
BIN = ../../libapps$(LIBEXT)
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
ROOTDEPPATH = --dep-path .
|
|
||||||
|
|
||||||
# Common build
|
|
||||||
|
|
||||||
VPATH =
|
|
||||||
|
|
||||||
all: .built
|
|
||||||
.PHONY: clean depend distclean
|
|
||||||
|
|
||||||
$(AOBJS): %$(OBJEXT): %.S
|
|
||||||
$(call ASSEMBLE, $<, $@)
|
|
||||||
|
|
||||||
$(COBJS): %$(OBJEXT): %.c
|
|
||||||
$(call COMPILE, $<, $@)
|
|
||||||
|
|
||||||
.built: $(OBJS)
|
|
||||||
$(call ARCHIVE, $(BIN), $(OBJS))
|
|
||||||
@touch .built
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_EXAMPLES_OSTEST_BUILTIN),y)
|
|
||||||
$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile
|
|
||||||
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
|
|
||||||
|
|
||||||
context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat
|
|
||||||
else
|
|
||||||
context:
|
|
||||||
endif
|
|
||||||
|
|
||||||
.depend: Makefile $(SRCS)
|
|
||||||
@$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
|
|
||||||
@touch $@
|
|
||||||
|
|
||||||
depend: .depend
|
|
||||||
|
|
||||||
clean:
|
|
||||||
$(call DELFILE, .built)
|
|
||||||
$(call CLEAN)
|
|
||||||
|
|
||||||
distclean: clean
|
|
||||||
$(call DELFILE, Make.dep)
|
|
||||||
$(call DELFILE, .depend)
|
|
||||||
|
|
||||||
-include Make.dep
|
|
|
@ -1,208 +0,0 @@
|
||||||
/****************************************************************************
|
|
||||||
* examples/ostest/barrier.c
|
|
||||||
*
|
|
||||||
* Copyright (C) 2007-2009, 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 <stdio.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <pthread.h>
|
|
||||||
|
|
||||||
#include "ostest.h"
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Definitions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#define HALF_SECOND 500000L
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Data
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static pthread_barrier_t barrier;
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Functions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: barrier_func
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static void *barrier_func(void *parameter)
|
|
||||||
{
|
|
||||||
int id = (int)parameter;
|
|
||||||
int status;
|
|
||||||
|
|
||||||
printf("barrier_func: Thread %d started\n", id);
|
|
||||||
#ifndef CONFIG_DISABLE_SIGNALS
|
|
||||||
usleep(HALF_SECOND);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Wait at the barrier until all threads are synchronized. */
|
|
||||||
|
|
||||||
printf("barrier_func: Thread %d calling pthread_barrier_wait()\n",
|
|
||||||
id);
|
|
||||||
FFLUSH();
|
|
||||||
status = pthread_barrier_wait(&barrier);
|
|
||||||
if (status == 0)
|
|
||||||
{
|
|
||||||
printf("barrier_func: Thread %d, back with "
|
|
||||||
"status=0 (I am not special)\n",
|
|
||||||
id, status);
|
|
||||||
}
|
|
||||||
else if (status == PTHREAD_BARRIER_SERIAL_THREAD)
|
|
||||||
{
|
|
||||||
printf("barrier_func: Thread %d, back with "
|
|
||||||
"status=PTHREAD_BARRIER_SERIAL_THREAD (I AM SPECIAL)\n",
|
|
||||||
id, status);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("barrier_func: ERROR thread %d could not get semaphore value\n",
|
|
||||||
id);
|
|
||||||
}
|
|
||||||
FFLUSH();
|
|
||||||
|
|
||||||
#ifndef CONFIG_DISABLE_SIGNALS
|
|
||||||
usleep(HALF_SECOND);
|
|
||||||
#endif
|
|
||||||
printf("barrier_func: Thread %d done\n", id);
|
|
||||||
FFLUSH();
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Functions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: barrier_test
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
void barrier_test(void)
|
|
||||||
{
|
|
||||||
pthread_t barrier_thread[CONFIG_EXAMPLES_OSTEST_NBARRIER_THREADS];
|
|
||||||
pthread_addr_t result;
|
|
||||||
pthread_attr_t attr;
|
|
||||||
pthread_barrierattr_t barrierattr;
|
|
||||||
int status;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
printf("barrier_test: Initializing barrier\n");
|
|
||||||
|
|
||||||
status = pthread_barrierattr_init(&barrierattr);
|
|
||||||
if (status != OK)
|
|
||||||
{
|
|
||||||
printf("barrier_test: pthread_barrierattr_init failed, status=%d\n",
|
|
||||||
status);
|
|
||||||
}
|
|
||||||
|
|
||||||
status = pthread_barrier_init(&barrier, &barrierattr,
|
|
||||||
CONFIG_EXAMPLES_OSTEST_NBARRIER_THREADS);
|
|
||||||
if (status != OK)
|
|
||||||
{
|
|
||||||
printf("barrier_test: pthread_barrierattr_init failed, status=%d\n",
|
|
||||||
status);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Create the barrier */
|
|
||||||
|
|
||||||
status = pthread_barrierattr_init(&barrierattr);
|
|
||||||
|
|
||||||
/* Start CONFIG_EXAMPLES_OSTEST_NBARRIER_THREADS thread instances */
|
|
||||||
|
|
||||||
status = pthread_attr_init(&attr);
|
|
||||||
if (status != OK)
|
|
||||||
{
|
|
||||||
printf("barrier_test: pthread_attr_init failed, status=%d\n",
|
|
||||||
status);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < CONFIG_EXAMPLES_OSTEST_NBARRIER_THREADS; i++)
|
|
||||||
{
|
|
||||||
status = pthread_create(&barrier_thread[i], &attr, barrier_func,
|
|
||||||
(pthread_addr_t)i);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("barrier_test: Error in thread %d create, status=%d\n",
|
|
||||||
i, status);
|
|
||||||
printf("barrier_test: Test aborted with waiting threads\n");
|
|
||||||
goto abort_test;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("barrier_test: Thread %d created\n", i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
FFLUSH();
|
|
||||||
|
|
||||||
/* Wait for all thread instances to complete */
|
|
||||||
|
|
||||||
for (i = 0; i < CONFIG_EXAMPLES_OSTEST_NBARRIER_THREADS; i++)
|
|
||||||
{
|
|
||||||
status = pthread_join(barrier_thread[i], &result);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("barrier_test: Error in thread %d join, status=%d\n",
|
|
||||||
i, status);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("barrier_test: Thread %d completed with result=%p\n",
|
|
||||||
i, result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Destroy the barrier */
|
|
||||||
|
|
||||||
abort_test:
|
|
||||||
status = pthread_barrier_destroy(&barrier);
|
|
||||||
if (status != OK)
|
|
||||||
{
|
|
||||||
printf("barrier_test: pthread_barrier_destroy failed, status=%d\n",
|
|
||||||
status);
|
|
||||||
}
|
|
||||||
|
|
||||||
status = pthread_barrierattr_destroy(&barrierattr);
|
|
||||||
if (status != OK)
|
|
||||||
{
|
|
||||||
printf("barrier_test: pthread_barrierattr_destroy failed, status=%d\n",
|
|
||||||
status);
|
|
||||||
}
|
|
||||||
FFLUSH();
|
|
||||||
}
|
|
|
@ -1,333 +0,0 @@
|
||||||
/***********************************************************************
|
|
||||||
* examples/ostest/cancel.c
|
|
||||||
*
|
|
||||||
* Copyright (C) 2007-2009 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 <stdio.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include <pthread.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include "ostest.h"
|
|
||||||
|
|
||||||
static pthread_mutex_t mutex;
|
|
||||||
static pthread_cond_t cond;
|
|
||||||
|
|
||||||
static void *thread_waiter(void *parameter)
|
|
||||||
{
|
|
||||||
int status;
|
|
||||||
|
|
||||||
/* Take the mutex */
|
|
||||||
|
|
||||||
printf("thread_waiter: Taking mutex\n");
|
|
||||||
status = pthread_mutex_lock(&mutex);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("thread_waiter: ERROR pthread_mutex_lock failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("thread_waiter: Starting wait for condition\n");
|
|
||||||
|
|
||||||
/* Are we a non-cancelable thread? Yes, set the non-cancelable state */
|
|
||||||
|
|
||||||
if (!parameter)
|
|
||||||
{
|
|
||||||
printf("thread_waiter: Setting non-cancelable\n");
|
|
||||||
status = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("thread_waiter: ERROR pthread_setcancelstate failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* The wait -- we will never awaken from this. */
|
|
||||||
|
|
||||||
status = pthread_cond_wait(&cond, &mutex);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("thread_waiter: ERROR pthread_cond_wait failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Release the mutex */
|
|
||||||
|
|
||||||
printf("thread_waiter: Releasing mutex\n");
|
|
||||||
status = pthread_mutex_unlock(&mutex);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("thread_waiter: ERROR pthread_mutex_unlock failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Set the cancelable state */
|
|
||||||
|
|
||||||
printf("thread_waiter: Setting cancelable\n");
|
|
||||||
status = pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("thread_waiter: ERROR pthread_setcancelstate failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("thread_waiter: Exit with status 0x12345678\n");
|
|
||||||
pthread_exit((pthread_addr_t)0x12345678);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void start_thread(pthread_t *waiter, int cancelable)
|
|
||||||
{
|
|
||||||
pthread_attr_t attr;
|
|
||||||
int status;
|
|
||||||
|
|
||||||
/* Initialize the mutex */
|
|
||||||
|
|
||||||
printf("start_thread: Initializing mutex\n");
|
|
||||||
status = pthread_mutex_init(&mutex, NULL);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("start_thread: ERROR pthread_mutex_init failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Initialize the condition variable */
|
|
||||||
|
|
||||||
printf("start_thread: Initializing cond\n");
|
|
||||||
status = pthread_cond_init(&cond, NULL);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("start_thread: ERROR pthread_cond_init failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Set up attributes */
|
|
||||||
|
|
||||||
status = pthread_attr_init(&attr);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("start_thread: pthread_attr_init failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
status = pthread_attr_setstacksize(&attr, STACKSIZE);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("start_thread: pthread_attr_setstacksize failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Start the waiter thread */
|
|
||||||
|
|
||||||
printf("start_thread: Starting thread\n");
|
|
||||||
status = pthread_create(waiter, &attr, thread_waiter, (pthread_addr_t)cancelable);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("start_thread: ERROR pthread_create failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Make sure that the waiter thread gets a chance to run */
|
|
||||||
|
|
||||||
printf("start_thread: Yielding\n");
|
|
||||||
pthread_yield();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void restart_thread(pthread_t *waiter, int cancelable)
|
|
||||||
{
|
|
||||||
int status;
|
|
||||||
|
|
||||||
/* Destroy the condition variable */
|
|
||||||
|
|
||||||
printf("restart_thread: Destroying cond\n");
|
|
||||||
status = pthread_cond_destroy(&cond);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("restart_thread: ERROR pthread_cond_destroy failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Destroy the mutex */
|
|
||||||
|
|
||||||
printf("restart_thread: Destroying mutex\n");
|
|
||||||
status = pthread_cond_destroy(&cond);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("restart_thread: ERROR pthread_mutex_destroy failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Then restart the thread */
|
|
||||||
|
|
||||||
printf("restart_thread: Re-starting thread\n");
|
|
||||||
start_thread(waiter, cancelable);
|
|
||||||
}
|
|
||||||
|
|
||||||
void cancel_test(void)
|
|
||||||
{
|
|
||||||
pthread_t waiter;
|
|
||||||
void *result;
|
|
||||||
int status;
|
|
||||||
|
|
||||||
/* Test 1: Normal Cancel *********************************************/
|
|
||||||
/* Start the waiter thread */
|
|
||||||
|
|
||||||
printf("cancel_test: Test 1: Normal Cancelation\n");
|
|
||||||
printf("cancel_test: Starting thread\n");
|
|
||||||
start_thread(&waiter, 1);
|
|
||||||
|
|
||||||
/* Then cancel it. It should be in the pthread_cond_wait now */
|
|
||||||
|
|
||||||
printf("cancel_test: Canceling thread\n");
|
|
||||||
status = pthread_cancel(waiter);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("cancel_test: ERROR pthread_cancel failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Then join to the thread to pick up the result (if we don't do
|
|
||||||
* we will have a memory leak!)
|
|
||||||
*/
|
|
||||||
|
|
||||||
printf("cancel_test: Joining\n");
|
|
||||||
status = pthread_join(waiter, &result);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("cancel_test: ERROR pthread_join failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("cancel_test: waiter exited with result=%p\n", result);
|
|
||||||
if (result != PTHREAD_CANCELED)
|
|
||||||
{
|
|
||||||
printf("cancel_test: ERROR expected result=%p\n", PTHREAD_CANCELED);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("cancel_test: PASS thread terminated with PTHREAD_CANCELED\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Test 2: Cancel Detached Thread ************************************/
|
|
||||||
|
|
||||||
printf("cancel_test: Test 2: Cancelation of detached thread\n");
|
|
||||||
printf("cancel_test: Re-starting thread\n");
|
|
||||||
restart_thread(&waiter, 1);
|
|
||||||
|
|
||||||
/* Detach the thread */
|
|
||||||
|
|
||||||
status = pthread_detach(waiter);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("cancel_test: ERROR pthread_detach, status=%d\n", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Then cancel it. It should be in the pthread_cond_wait now */
|
|
||||||
|
|
||||||
printf("cancel_test: Canceling thread\n");
|
|
||||||
status = pthread_cancel(waiter);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("cancel_test: ERROR pthread_cancel failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Join should now fail */
|
|
||||||
|
|
||||||
printf("cancel_test: Joining\n");
|
|
||||||
status = pthread_join(waiter, &result);
|
|
||||||
if (status == 0)
|
|
||||||
{
|
|
||||||
printf("cancel_test: ERROR pthread_join succeeded\n");
|
|
||||||
}
|
|
||||||
else if (status != ESRCH)
|
|
||||||
{
|
|
||||||
printf("cancel_test: ERROR pthread_join failed but with wrong status=%d\n", status);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("cancel_test: PASS pthread_join failed with status=ESRCH\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Test 3: Non-cancelable threads ************************************/
|
|
||||||
|
|
||||||
printf("cancel_test: Test 3: Non-cancelable threads\n");
|
|
||||||
printf("cancel_test: Re-starting thread (non-cancelable)\n");
|
|
||||||
restart_thread(&waiter, 0);
|
|
||||||
|
|
||||||
/* Then cancel it. It should be in the pthread_cond_wait now. The
|
|
||||||
* behavior here is non-standard: when the thread is at a cancelation
|
|
||||||
* point, it should be cancelable, even when cancelation is disable.
|
|
||||||
*
|
|
||||||
* The cancelation should succeed, because the cancelation is pending.
|
|
||||||
*/
|
|
||||||
|
|
||||||
printf("cancel_test: Canceling thread\n");
|
|
||||||
status = pthread_cancel(waiter);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("cancel_test: ERROR pthread_cancel failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Signal the thread. It should wake up and restore the cancelable state.
|
|
||||||
* When the cancelable state is re-enabled, the thread should be canceled.
|
|
||||||
*/
|
|
||||||
|
|
||||||
status = pthread_mutex_lock(&mutex);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("cancel_test: ERROR pthread_mutex_lock failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
status = pthread_cond_signal(&cond);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("cancel_test: ERROR pthread_cond_signal failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
status = pthread_mutex_unlock(&mutex);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("cancel_test: ERROR pthread_mutex_unlock failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Then join to the thread to pick up the result (if we don't do
|
|
||||||
* we will have a memory leak!)
|
|
||||||
*/
|
|
||||||
|
|
||||||
printf("cancel_test: Joining\n");
|
|
||||||
status = pthread_join(waiter, &result);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("cancel_test: ERROR pthread_join failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("cancel_test: waiter exited with result=%p\n", result);
|
|
||||||
if (result != PTHREAD_CANCELED)
|
|
||||||
{
|
|
||||||
printf("cancel_test: ERROR expected result=%p\n", PTHREAD_CANCELED);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("cancel_test: PASS thread terminated with PTHREAD_CANCELED\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,294 +0,0 @@
|
||||||
/***********************************************************************
|
|
||||||
* cond.c
|
|
||||||
*
|
|
||||||
* Copyright (C) 2007, 2008 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 <stdio.h>
|
|
||||||
#include <pthread.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include "ostest.h"
|
|
||||||
|
|
||||||
#ifndef NULL
|
|
||||||
# define NULL (void*)0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static volatile enum { RUNNING, MUTEX_WAIT, COND_WAIT} waiter_state;
|
|
||||||
|
|
||||||
static pthread_mutex_t mutex;
|
|
||||||
static pthread_cond_t cond;
|
|
||||||
static volatile int data_available = 0;
|
|
||||||
static int waiter_nloops = 0;
|
|
||||||
static int waiter_waits = 0;
|
|
||||||
static int waiter_nerrors = 0;
|
|
||||||
static int signaler_nloops = 0;
|
|
||||||
static int signaler_already = 0;
|
|
||||||
static int signaler_state = 0;
|
|
||||||
static int signaler_nerrors = 0;
|
|
||||||
|
|
||||||
static void *thread_waiter(void *parameter)
|
|
||||||
{
|
|
||||||
int status;
|
|
||||||
|
|
||||||
printf("waiter_thread: Started\n");
|
|
||||||
|
|
||||||
for(;;)
|
|
||||||
{
|
|
||||||
/* Take the mutex */
|
|
||||||
|
|
||||||
waiter_state = MUTEX_WAIT;
|
|
||||||
status = pthread_mutex_lock(&mutex);
|
|
||||||
waiter_state = RUNNING;
|
|
||||||
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("waiter_thread: ERROR pthread_mutex_lock failed, status=%d\n", status);
|
|
||||||
waiter_nerrors++;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check if data is available -- if data is not available then
|
|
||||||
* wait for it
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (!data_available)
|
|
||||||
{
|
|
||||||
/* We are higher priority than the signaler thread so the
|
|
||||||
* only time that the signaler thread will have a chance to run is when
|
|
||||||
* we are waiting for the condition variable. In this case, pthread_cond_wait
|
|
||||||
* will automatically release the mutex for the signaler (then re-acquire
|
|
||||||
* the mutex before returning.
|
|
||||||
*/
|
|
||||||
|
|
||||||
waiter_state = COND_WAIT;
|
|
||||||
status = pthread_cond_wait(&cond, &mutex);
|
|
||||||
waiter_state = RUNNING;
|
|
||||||
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("waiter_thread: ERROR pthread_cond_wait failed, status=%d\n", status);
|
|
||||||
waiter_nerrors++;
|
|
||||||
}
|
|
||||||
waiter_waits++;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Now data should be available */
|
|
||||||
|
|
||||||
if (!data_available)
|
|
||||||
{
|
|
||||||
printf("waiter_thread: ERROR data not available after wait\n");
|
|
||||||
waiter_nerrors++;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Clear data available */
|
|
||||||
|
|
||||||
data_available = 0;
|
|
||||||
|
|
||||||
/* Release the mutex */
|
|
||||||
|
|
||||||
status = pthread_mutex_unlock(&mutex);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("waiter_thread: ERROR waiter: pthread_mutex_unlock failed, status=%d\n", status);
|
|
||||||
waiter_nerrors++;
|
|
||||||
}
|
|
||||||
|
|
||||||
waiter_nloops++;
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void *thread_signaler(void *parameter)
|
|
||||||
{
|
|
||||||
int status;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
printf("thread_signaler: Started\n");
|
|
||||||
for (i = 0; i < 32; i++)
|
|
||||||
{
|
|
||||||
/* Take the mutex. The waiter is higher priority and should
|
|
||||||
* run until it waits for the condition. So, at this point
|
|
||||||
* signaler should be waiting for the condition.
|
|
||||||
*/
|
|
||||||
|
|
||||||
status = pthread_mutex_lock(&mutex);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("thread_signaler: ERROR pthread_mutex_lock failed, status=%d\n", status);
|
|
||||||
signaler_nerrors++;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Verify the state */
|
|
||||||
|
|
||||||
if (waiter_state != COND_WAIT)
|
|
||||||
{
|
|
||||||
printf("thread_signaler: ERROR waiter state = %d != COND_WAITING\n", waiter_state);
|
|
||||||
signaler_state++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data_available)
|
|
||||||
{
|
|
||||||
printf("thread_signaler: ERROR data already available, waiter_state=%d\n", waiter_state);
|
|
||||||
signaler_already++;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Set data available and signal the waiter */
|
|
||||||
|
|
||||||
data_available = 1;
|
|
||||||
status = pthread_cond_signal(&cond);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("thread_signaler: ERROR pthread_cond_signal failed, status=%d\n", status);
|
|
||||||
signaler_nerrors++;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Release the mutex */
|
|
||||||
|
|
||||||
status = pthread_mutex_unlock(&mutex);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("thread_signaler: ERROR pthread_mutex_unlock failed, status=%d\n", status);
|
|
||||||
signaler_nerrors++;
|
|
||||||
}
|
|
||||||
|
|
||||||
signaler_nloops++;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("thread_signaler: Terminating\n");
|
|
||||||
pthread_exit(NULL);
|
|
||||||
return NULL; /* Non-reachable -- needed for some compilers */
|
|
||||||
}
|
|
||||||
|
|
||||||
void cond_test(void)
|
|
||||||
{
|
|
||||||
pthread_t waiter;
|
|
||||||
pthread_t signaler;
|
|
||||||
pthread_attr_t attr;
|
|
||||||
#ifdef SDCC
|
|
||||||
pthread_addr_t result;
|
|
||||||
#endif
|
|
||||||
struct sched_param sparam;
|
|
||||||
int prio_min;
|
|
||||||
int prio_max;
|
|
||||||
int prio_mid;
|
|
||||||
int status;
|
|
||||||
|
|
||||||
/* Initialize the mutex */
|
|
||||||
|
|
||||||
printf("cond_test: Initializing mutex\n");
|
|
||||||
status = pthread_mutex_init(&mutex, NULL);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("cond_test: ERROR pthread_mutex_init failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Initialize the condition variable */
|
|
||||||
|
|
||||||
printf("cond_test: Initializing cond\n");
|
|
||||||
status = pthread_cond_init(&cond, NULL);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("cond_test: ERROR pthread_condinit failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Start the waiter thread at higher priority */
|
|
||||||
|
|
||||||
printf("cond_test: Starting waiter\n");
|
|
||||||
status = pthread_attr_init(&attr);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("cond_test: pthread_attr_init failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
prio_min = sched_get_priority_min(SCHED_FIFO);
|
|
||||||
prio_max = sched_get_priority_max(SCHED_FIFO);
|
|
||||||
prio_mid = (prio_min + prio_max) / 2;
|
|
||||||
|
|
||||||
sparam.sched_priority = prio_mid;
|
|
||||||
status = pthread_attr_setschedparam(&attr,&sparam);
|
|
||||||
if (status != OK)
|
|
||||||
{
|
|
||||||
printf("cond_test: pthread_attr_setschedparam failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("cond_test: Set thread 1 priority to %d\n", sparam.sched_priority);
|
|
||||||
}
|
|
||||||
|
|
||||||
status = pthread_create(&waiter, &attr, thread_waiter, NULL);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("cond_test: pthread_create failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("cond_test: Starting signaler\n");
|
|
||||||
status = pthread_attr_init(&attr);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("cond_test: pthread_attr_init failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
sparam.sched_priority = (prio_min + prio_mid) / 2;
|
|
||||||
status = pthread_attr_setschedparam(&attr,&sparam);
|
|
||||||
if (status != OK)
|
|
||||||
{
|
|
||||||
printf("cond_test: pthread_attr_setschedparam failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("cond_test: Set thread 2 priority to %d\n", sparam.sched_priority);
|
|
||||||
}
|
|
||||||
|
|
||||||
status = pthread_create(&signaler, &attr, thread_signaler, NULL);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("cond_test: pthread_create failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Wait for the threads to stop */
|
|
||||||
|
|
||||||
#ifdef SDCC
|
|
||||||
pthread_join(signaler, &result);
|
|
||||||
#else
|
|
||||||
pthread_join(signaler, NULL);
|
|
||||||
#endif
|
|
||||||
printf("cond_test: signaler terminated, now cancel the waiter\n");
|
|
||||||
pthread_detach(waiter);
|
|
||||||
pthread_cancel(waiter);
|
|
||||||
|
|
||||||
printf("cond_test: \tWaiter\tSignaler\n");
|
|
||||||
printf("cond_test: Loops\t%d\t%d\n", waiter_nloops, signaler_nloops);
|
|
||||||
printf("cond_test: Errors\t%d\t%d\n", waiter_nerrors, signaler_nerrors);
|
|
||||||
printf("cond_test:\n");
|
|
||||||
printf("cond_test: %d times, waiter did not have to wait for data\n", waiter_nloops - waiter_waits);
|
|
||||||
printf("cond_test: %d times, data was already available when the signaler run\n", signaler_already);
|
|
||||||
printf("cond_test: %d times, the waiter was in an unexpected state when the signaler ran\n", signaler_state);
|
|
||||||
}
|
|
|
@ -1,344 +0,0 @@
|
||||||
/***********************************************************************
|
|
||||||
* apps/examples/ostest/fpu.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/wait.h>
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <sched.h>
|
|
||||||
|
|
||||||
#include "ostest.h"
|
|
||||||
|
|
||||||
/***********************************************************************
|
|
||||||
* Pre-processor definitions
|
|
||||||
***********************************************************************/
|
|
||||||
/* Configuration *******************************************************/
|
|
||||||
|
|
||||||
#undef HAVE_FPU
|
|
||||||
#ifdef CONFIG_ARCH_FPU
|
|
||||||
# if defined(CONFIG_EXAMPLES_OSTEST_FPUSIZE) && defined(CONFIG_SCHED_WAITPID) && !defined(CONFIG_DISABLE_SIGNALS)
|
|
||||||
# define HAVE_FPU 1
|
|
||||||
# else
|
|
||||||
# ifndef CONFIG_EXAMPLES_OSTEST_FPUSIZE
|
|
||||||
# warning "FPU test not built; CONFIG_EXAMPLES_OSTEST_FPUSIZE not defined"
|
|
||||||
# endif
|
|
||||||
# ifndef CONFIG_SCHED_WAITPID
|
|
||||||
# warning "FPU test not built; CONFIG_SCHED_WAITPID not defined"
|
|
||||||
# endif
|
|
||||||
# ifdef CONFIG_DISABLE_SIGNALS
|
|
||||||
# warning "FPU test not built; CONFIG_DISABLE_SIGNALS defined"
|
|
||||||
# endif
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef HAVE_FPU
|
|
||||||
|
|
||||||
#ifndef CONFIG_EXAMPLES_OSTEST_FPULOOPS
|
|
||||||
# define CONFIG_EXAMPLES_OSTEST_FPULOOPS 16
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef CONFIG_EXAMPLES_OSTEST_FPUMSDELAY
|
|
||||||
# define CONFIG_EXAMPLES_OSTEST_FPUMSDELAY 750
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef CONFIG_EXAMPLES_OSTEST_FPUPRIORITY
|
|
||||||
# define CONFIG_EXAMPLES_OSTEST_FPUPRIORITY SCHED_PRIORITY_DEFAULT
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef CONFIG_EXAMPLES_OSTEST_FPUSTACKSIZE
|
|
||||||
# define CONFIG_EXAMPLES_OSTEST_FPUSTACKSIZE 2048
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Other defintions ****************************************************/
|
|
||||||
/* We'll keep all data using 32-bit values only to force 32-bit alignment.
|
|
||||||
* This logic has no real notion of the underlying representation.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define FPU_WORDSIZE ((CONFIG_EXAMPLES_OSTEST_FPUSIZE+3)>>2)
|
|
||||||
#define FPU_NTHREADS 2
|
|
||||||
|
|
||||||
#ifndef NULL
|
|
||||||
# define NULL (void*)0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/***********************************************************************
|
|
||||||
* External Dependencies
|
|
||||||
***********************************************************************/
|
|
||||||
/* This test is very dependent on support provided by the chip/board-
|
|
||||||
* layer logic. In particular, it expects the following functions
|
|
||||||
* to be provided:
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Given an array of size CONFIG_EXAMPLES_OSTEST_FPUSIZE, this function
|
|
||||||
* will return the current FPU registers.
|
|
||||||
*/
|
|
||||||
|
|
||||||
extern void arch_getfpu(FAR uint32_t *fpusave);
|
|
||||||
|
|
||||||
/* Given two arrays of size CONFIG_EXAMPLES_OSTEST_FPUSIZE this
|
|
||||||
* function will compare them and return true if they are identical.
|
|
||||||
*/
|
|
||||||
|
|
||||||
extern bool arch_cmpfpu(FAR const uint32_t *fpusave1,
|
|
||||||
FAR const uint32_t *fpusave2);
|
|
||||||
|
|
||||||
/***********************************************************************
|
|
||||||
* Private Types
|
|
||||||
***********************************************************************/
|
|
||||||
|
|
||||||
struct fpu_threaddata_s
|
|
||||||
{
|
|
||||||
uint32_t save1[FPU_WORDSIZE];
|
|
||||||
uint32_t save2[FPU_WORDSIZE];
|
|
||||||
|
|
||||||
/* These are just dummy values to force the compiler to do the
|
|
||||||
* requested floating point computations without the nonsense
|
|
||||||
* computations being optimized away.
|
|
||||||
*/
|
|
||||||
|
|
||||||
volatile float sp1;
|
|
||||||
volatile float sp2;
|
|
||||||
volatile float sp3;
|
|
||||||
volatile float sp4;
|
|
||||||
|
|
||||||
volatile float dp1;
|
|
||||||
volatile float dp2;
|
|
||||||
volatile float dp3;
|
|
||||||
volatile float dp4;
|
|
||||||
};
|
|
||||||
|
|
||||||
/***********************************************************************
|
|
||||||
* Private Data
|
|
||||||
***********************************************************************/
|
|
||||||
|
|
||||||
static uint8_t g_fpuno;
|
|
||||||
/* static */ struct fpu_threaddata_s g_fputhread[FPU_NTHREADS];
|
|
||||||
|
|
||||||
/***********************************************************************
|
|
||||||
* Private Functions
|
|
||||||
***********************************************************************/
|
|
||||||
|
|
||||||
static void fpu_dump(FAR uint32_t *buffer, FAR const char *msg)
|
|
||||||
{
|
|
||||||
int i, j, k;
|
|
||||||
|
|
||||||
printf("%s (%p):\n", msg, buffer);
|
|
||||||
for (i = 0; i < FPU_WORDSIZE; i += 8)
|
|
||||||
{
|
|
||||||
printf(" %04x: ", i);
|
|
||||||
for (j = 0; j < 8; j++)
|
|
||||||
{
|
|
||||||
k = i + j;
|
|
||||||
|
|
||||||
if (k < FPU_WORDSIZE)
|
|
||||||
{
|
|
||||||
printf("%08x ", buffer[k]);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("\n");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
printf("\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int fpu_task(int argc, char *argv[])
|
|
||||||
{
|
|
||||||
FAR struct fpu_threaddata_s *fpu;
|
|
||||||
register float sp1;
|
|
||||||
register float sp2;
|
|
||||||
register float sp3;
|
|
||||||
register float sp4;
|
|
||||||
register double dp1;
|
|
||||||
register double dp2;
|
|
||||||
register double dp3;
|
|
||||||
register double dp4;
|
|
||||||
|
|
||||||
int id;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
/* Which are we? */
|
|
||||||
|
|
||||||
sched_lock();
|
|
||||||
fpu = &g_fputhread[g_fpuno];
|
|
||||||
id = (int)(++g_fpuno);
|
|
||||||
sched_unlock();
|
|
||||||
|
|
||||||
/* Seed the flowing point values */
|
|
||||||
|
|
||||||
sp1 = (float)id;
|
|
||||||
dp1 = (double)id;
|
|
||||||
|
|
||||||
for (i = 0; i < CONFIG_EXAMPLES_OSTEST_FPULOOPS; i++)
|
|
||||||
{
|
|
||||||
printf("FPU#%d: pass %d\n", id, i+1);
|
|
||||||
fflush(stdout);
|
|
||||||
|
|
||||||
/* Set the FPU register save arrays to a known-but-illogical values so
|
|
||||||
* that we can verify that reading of the registers actually occurs.
|
|
||||||
*/
|
|
||||||
|
|
||||||
memset(fpu->save1, 0xff, FPU_WORDSIZE * sizeof(uint32_t));
|
|
||||||
memset(fpu->save2, 0xff, FPU_WORDSIZE * sizeof(uint32_t));
|
|
||||||
|
|
||||||
/* Prevent context switches while we set up some stuff */
|
|
||||||
|
|
||||||
sched_lock();
|
|
||||||
|
|
||||||
/* Do some trivial floating point operations that should cause some
|
|
||||||
* changes to floating point registers. First, some single preceision
|
|
||||||
* nonsense.
|
|
||||||
*/
|
|
||||||
|
|
||||||
sp4 = (float)3.14159 * sp1; /* Multiple by Pi */
|
|
||||||
sp3 = sp4 + (float)1.61803; /* Add the golden ratio */
|
|
||||||
sp2 = sp3 / (float)2.71828; /* Divide by Euler's constant */
|
|
||||||
sp1 = sp2 + (float)1.0; /* Plus one */
|
|
||||||
|
|
||||||
fpu->sp1 = sp1; /* Make the compiler believe that somebody cares about the result */
|
|
||||||
fpu->sp2 = sp2;
|
|
||||||
fpu->sp3 = sp3;
|
|
||||||
fpu->sp4 = sp4;
|
|
||||||
|
|
||||||
/* Again using double precision */
|
|
||||||
|
|
||||||
dp4 = (double)3.14159 * dp1; /* Multiple by Pi */
|
|
||||||
dp3 = dp4 + (double)1.61803; /* Add the golden ratio */
|
|
||||||
dp2 = dp3 / (double)2.71828; /* Divide by Euler's constant */
|
|
||||||
dp1 = dp2 + (double)1.0; /* Plus one */
|
|
||||||
|
|
||||||
fpu->dp1 = dp1; /* Make the compiler believe that somebody cares about the result */
|
|
||||||
fpu->dp2 = dp2;
|
|
||||||
fpu->dp3 = dp3;
|
|
||||||
fpu->dp4 = dp4;
|
|
||||||
|
|
||||||
/* Sample the floating point registers */
|
|
||||||
|
|
||||||
arch_getfpu(fpu->save1);
|
|
||||||
|
|
||||||
/* Re-read and verify the FPU registers consistently without corruption */
|
|
||||||
|
|
||||||
arch_getfpu(fpu->save2);
|
|
||||||
if (!arch_cmpfpu(fpu->save1, fpu->save2))
|
|
||||||
{
|
|
||||||
printf("ERROR FPU#%d: save1 and save2 do not match\n", id);
|
|
||||||
fpu_dump(fpu->save1, "Values after math operations (save1)");
|
|
||||||
fpu_dump(fpu->save2, "Values after verify re-read (save2)");
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Now unlock and sleep for a while -- this should result in some context switches */
|
|
||||||
|
|
||||||
sched_unlock();
|
|
||||||
usleep(CONFIG_EXAMPLES_OSTEST_FPUMSDELAY * 1000);
|
|
||||||
|
|
||||||
/* Several context switches should have occurred. Now verify that the floating
|
|
||||||
* point registers are still correctly set.
|
|
||||||
*/
|
|
||||||
|
|
||||||
arch_getfpu(fpu->save2);
|
|
||||||
if (!arch_cmpfpu(fpu->save1, fpu->save2))
|
|
||||||
{
|
|
||||||
printf("ERROR FPU#%d: save1 and save2 do not match\n", id);
|
|
||||||
fpu_dump(fpu->save1, "Values before waiting (save1)");
|
|
||||||
fpu_dump(fpu->save2, "Values after waiting (save2)");
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("FPU#%d: Succeeded\n", id);
|
|
||||||
fflush(stdout);
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
|
||||||
#endif /* HAVE_FPU */
|
|
||||||
|
|
||||||
/***********************************************************************
|
|
||||||
* Private Functions
|
|
||||||
***********************************************************************/
|
|
||||||
|
|
||||||
void fpu_test(void)
|
|
||||||
{
|
|
||||||
#ifdef HAVE_FPU
|
|
||||||
pid_t task1;
|
|
||||||
pid_t task2;
|
|
||||||
int statloc;
|
|
||||||
|
|
||||||
/* Start two two tasks */
|
|
||||||
|
|
||||||
g_fpuno = 0;
|
|
||||||
printf("Starting task FPU#1\n");
|
|
||||||
task1 = TASK_CREATE("FPU#1", CONFIG_EXAMPLES_OSTEST_FPUPRIORITY, CONFIG_EXAMPLES_OSTEST_FPUSTACKSIZE, fpu_task, NULL);
|
|
||||||
if (task1 < 0)
|
|
||||||
{
|
|
||||||
printf("fpu_test: ERROR Failed to start task FPU#1\n");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("fpu_test: Started task FPU#1 at PID=%d\n", task1);
|
|
||||||
}
|
|
||||||
fflush(stdout);
|
|
||||||
usleep(250);
|
|
||||||
|
|
||||||
printf("Starting task FPU#2\n");
|
|
||||||
task2 = TASK_CREATE("FPU#2", CONFIG_EXAMPLES_OSTEST_FPUPRIORITY, CONFIG_EXAMPLES_OSTEST_FPUSTACKSIZE, fpu_task, NULL);
|
|
||||||
if (task2 < 0)
|
|
||||||
{
|
|
||||||
printf("fpu_test: ERROR Failed to start task FPU#1\n");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("fpu_test: Started task FPU#2 at PID=%d\n", task2);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Wait for each task to complete */
|
|
||||||
|
|
||||||
fflush(stdout);
|
|
||||||
(void)waitpid(task1, &statloc, 0);
|
|
||||||
(void)waitpid(task2, &statloc, 0);
|
|
||||||
|
|
||||||
#else
|
|
||||||
printf("fpu_test: ERROR: The FPU test is not properly configured\n");
|
|
||||||
#endif
|
|
||||||
printf("fpu_test: Returning\n");
|
|
||||||
}
|
|
|
@ -1,394 +0,0 @@
|
||||||
/**************************************************************************
|
|
||||||
* apps/examples/ostest/mqueue.c
|
|
||||||
*
|
|
||||||
* Copyright (C) 2007-2009, 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 <stdio.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <ctype.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <pthread.h>
|
|
||||||
#include <mqueue.h>
|
|
||||||
#include <sched.h>
|
|
||||||
#include <errno.h>
|
|
||||||
|
|
||||||
#include "ostest.h"
|
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
* Private Definitions
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
#define TEST_MESSAGE "This is a test and only a test"
|
|
||||||
#if defined(SDCC) || defined(__ZILOG__)
|
|
||||||
/* Cannot use strlen in array size */
|
|
||||||
|
|
||||||
# define TEST_MSGLEN (31)
|
|
||||||
#else
|
|
||||||
/* Message lenght is the size of the message plus the null terminator */
|
|
||||||
|
|
||||||
# define TEST_MSGLEN (strlen(TEST_MESSAGE)+1)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define TEST_SEND_NMSGS (10)
|
|
||||||
#ifndef CONFIG_DISABLE_SIGNALS
|
|
||||||
# define TEST_RECEIVE_NMSGS (11)
|
|
||||||
#else
|
|
||||||
# define TEST_RECEIVE_NMSGS (10)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define HALF_SECOND_USEC_USEC 500000L
|
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
* Private Types
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
* Private Function Prototypes
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
* Global Variables
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
* Private Variables
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
* Private Functions
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
* Public Functions
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
static void *sender_thread(void *arg)
|
|
||||||
{
|
|
||||||
mqd_t mqfd;
|
|
||||||
char msg_buffer[TEST_MSGLEN];
|
|
||||||
struct mq_attr attr;
|
|
||||||
int status = 0;
|
|
||||||
int nerrors = 0;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
printf("sender_thread: Starting\n");
|
|
||||||
|
|
||||||
/* Fill in attributes for message queue */
|
|
||||||
|
|
||||||
attr.mq_maxmsg = 20;
|
|
||||||
attr.mq_msgsize = TEST_MSGLEN;
|
|
||||||
attr.mq_flags = 0;
|
|
||||||
|
|
||||||
/* Set the flags for the open of the queue.
|
|
||||||
* Make it a blocking open on the queue, meaning it will block if
|
|
||||||
* this process tries to send to the queue and the queue is full.
|
|
||||||
*
|
|
||||||
* O_CREAT - the queue will get created if it does not already exist.
|
|
||||||
* O_WRONLY - we are only planning to write to the queue.
|
|
||||||
*
|
|
||||||
* Open the queue, and create it if the receiving process hasn't
|
|
||||||
* already created it.
|
|
||||||
*/
|
|
||||||
|
|
||||||
mqfd = mq_open("testmq", O_WRONLY|O_CREAT, 0666, &attr);
|
|
||||||
if (mqfd < 0)
|
|
||||||
{
|
|
||||||
printf("sender_thread: ERROR mq_open failed\n");
|
|
||||||
pthread_exit((pthread_addr_t)1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Fill in a test message buffer to send */
|
|
||||||
|
|
||||||
memcpy(msg_buffer, TEST_MESSAGE, TEST_MSGLEN);
|
|
||||||
|
|
||||||
/* Perform the send TEST_SEND_NMSGS times */
|
|
||||||
|
|
||||||
for (i = 0; i < TEST_SEND_NMSGS; i++)
|
|
||||||
{
|
|
||||||
status = mq_send(mqfd, msg_buffer, TEST_MSGLEN, 42);
|
|
||||||
if (status < 0)
|
|
||||||
{
|
|
||||||
printf("sender_thread: ERROR mq_send failure=%d on msg %d\n", status, i);
|
|
||||||
nerrors++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("sender_thread: mq_send succeeded on msg %d\n", i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Close the queue and return success */
|
|
||||||
|
|
||||||
if (mq_close(mqfd) < 0)
|
|
||||||
{
|
|
||||||
printf("sender_thread: ERROR mq_close failed\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("sender_thread: returning nerrors=%d\n", nerrors);
|
|
||||||
return (pthread_addr_t)nerrors;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void *receiver_thread(void *arg)
|
|
||||||
{
|
|
||||||
mqd_t mqfd;
|
|
||||||
char msg_buffer[TEST_MSGLEN];
|
|
||||||
struct mq_attr attr;
|
|
||||||
int nbytes;
|
|
||||||
int nerrors = 0;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
printf("receiver_thread: Starting\n");
|
|
||||||
|
|
||||||
/* Fill in attributes for message queue */
|
|
||||||
|
|
||||||
attr.mq_maxmsg = 20;
|
|
||||||
attr.mq_msgsize = TEST_MSGLEN;
|
|
||||||
attr.mq_flags = 0;
|
|
||||||
|
|
||||||
/* Set the flags for the open of the queue.
|
|
||||||
* Make it a blocking open on the queue, meaning it will block if
|
|
||||||
* this task tries to read from the queue when the queue is empty
|
|
||||||
*
|
|
||||||
* O_CREAT - the queue will get created if it does not already exist.
|
|
||||||
* O_RDONLY - we are only planning to read from the queue.
|
|
||||||
*
|
|
||||||
* Open the queue, and create it if the sending process hasn't
|
|
||||||
* already created it.
|
|
||||||
*/
|
|
||||||
|
|
||||||
mqfd = mq_open("testmq", O_RDONLY|O_CREAT, 0666, &attr);
|
|
||||||
if (mqfd < 0)
|
|
||||||
{
|
|
||||||
printf("receiver_thread: ERROR mq_open failed\n");
|
|
||||||
pthread_exit((pthread_addr_t)1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Perform the receive TEST_RECEIVE_NMSGS times */
|
|
||||||
|
|
||||||
for (i = 0; i < TEST_RECEIVE_NMSGS; i++)
|
|
||||||
{
|
|
||||||
memset(msg_buffer, 0xaa, TEST_MSGLEN);
|
|
||||||
nbytes = mq_receive(mqfd, msg_buffer, TEST_MSGLEN, 0);
|
|
||||||
if (nbytes < 0)
|
|
||||||
{
|
|
||||||
/* mq_receive failed. If the error is because of EINTR then
|
|
||||||
* it is not a failure.
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (errno != EINTR)
|
|
||||||
{
|
|
||||||
printf("receiver_thread: ERROR mq_receive failure on msg %d, errno=%d\n", i, errno);
|
|
||||||
nerrors++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("receiver_thread: mq_receive interrupted!\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (nbytes != TEST_MSGLEN)
|
|
||||||
{
|
|
||||||
printf("receiver_thread: mq_receive return bad size %d on msg %d\n", nbytes, i);
|
|
||||||
nerrors++;
|
|
||||||
}
|
|
||||||
else if (memcmp(TEST_MESSAGE, msg_buffer, nbytes) != 0)
|
|
||||||
{
|
|
||||||
int j;
|
|
||||||
|
|
||||||
printf("receiver_thread: mq_receive returned corrupt message on msg %d\n", i);
|
|
||||||
printf("receiver_thread: i Expected Received\n");
|
|
||||||
|
|
||||||
for (j = 0; j < TEST_MSGLEN-1; j++)
|
|
||||||
{
|
|
||||||
if (isprint(msg_buffer[j]))
|
|
||||||
{
|
|
||||||
printf("receiver_thread: %2d %02x (%c) %02x (%c)\n",
|
|
||||||
j, TEST_MESSAGE[j], TEST_MESSAGE[j], msg_buffer[j], msg_buffer[j]);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("receiver_thread: %2d %02x (%c) %02x\n",
|
|
||||||
j, TEST_MESSAGE[j], TEST_MESSAGE[j], msg_buffer[j]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
printf("receiver_thread: %2d 00 %02x\n",
|
|
||||||
j, msg_buffer[j]);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("receiver_thread: mq_receive succeeded on msg %d\n", i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Close the queue and return success */
|
|
||||||
|
|
||||||
if (mq_close(mqfd) < 0)
|
|
||||||
{
|
|
||||||
printf("receiver_thread: ERROR mq_close failed\n");
|
|
||||||
nerrors++;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Destroy the queue */
|
|
||||||
|
|
||||||
if (mq_unlink("testmq") < 0)
|
|
||||||
{
|
|
||||||
printf("receiver_thread: ERROR mq_close failed\n");
|
|
||||||
nerrors++;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("receiver_thread: returning nerrors=%d\n", nerrors);
|
|
||||||
pthread_exit((pthread_addr_t)nerrors);
|
|
||||||
return (pthread_addr_t)nerrors;
|
|
||||||
}
|
|
||||||
|
|
||||||
void mqueue_test(void)
|
|
||||||
{
|
|
||||||
pthread_t sender;
|
|
||||||
pthread_t receiver;
|
|
||||||
void *result;
|
|
||||||
pthread_attr_t attr;
|
|
||||||
struct sched_param sparam;
|
|
||||||
int prio_min;
|
|
||||||
int prio_max;
|
|
||||||
int prio_mid;
|
|
||||||
int status;
|
|
||||||
|
|
||||||
/* Start the sending thread at higher priority */
|
|
||||||
|
|
||||||
printf("mqueue_test: Starting receiver\n");
|
|
||||||
status = pthread_attr_init(&attr);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("mqueue_test: pthread_attr_init failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
status = pthread_attr_setstacksize(&attr, STACKSIZE);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("mqueue_test: pthread_attr_setstacksize failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
prio_min = sched_get_priority_min(SCHED_FIFO);
|
|
||||||
prio_max = sched_get_priority_max(SCHED_FIFO);
|
|
||||||
prio_mid = (prio_min + prio_max) / 2;
|
|
||||||
|
|
||||||
sparam.sched_priority = prio_mid;
|
|
||||||
status = pthread_attr_setschedparam(&attr,&sparam);
|
|
||||||
if (status != OK)
|
|
||||||
{
|
|
||||||
printf("mqueue_test: pthread_attr_setschedparam failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("mqueue_test: Set receiver priority to %d\n", sparam.sched_priority);
|
|
||||||
}
|
|
||||||
|
|
||||||
status = pthread_create(&receiver, &attr, receiver_thread, NULL);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("mqueue_test: pthread_create failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Start the sending thread at lower priority */
|
|
||||||
|
|
||||||
printf("mqueue_test: Starting sender\n");
|
|
||||||
status = pthread_attr_init(&attr);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("mqueue_test: pthread_attr_init failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
status = pthread_attr_setstacksize(&attr, STACKSIZE);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("mqueue_test: pthread_attr_setstacksize failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
sparam.sched_priority = (prio_min + prio_mid) / 2;
|
|
||||||
status = pthread_attr_setschedparam(&attr,&sparam);
|
|
||||||
if (status != OK)
|
|
||||||
{
|
|
||||||
printf("mqueue_test: pthread_attr_setschedparam failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("mqueue_test: Set sender thread priority to %d\n", sparam.sched_priority);
|
|
||||||
}
|
|
||||||
|
|
||||||
status = pthread_create(&sender, &attr, sender_thread, NULL);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("mqueue_test: pthread_create failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("mqueue_test: Waiting for sender to complete\n");
|
|
||||||
pthread_join(sender, &result);
|
|
||||||
if (result != (void*)0)
|
|
||||||
{
|
|
||||||
printf("mqueue_test: ERROR sender thread exited with %d errors\n", (int)result);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef CONFIG_DISABLE_SIGNALS
|
|
||||||
/* Wake up the receiver thread with a signal */
|
|
||||||
|
|
||||||
printf("mqueue_test: Killing receiver\n");
|
|
||||||
pthread_kill(receiver, 9);
|
|
||||||
|
|
||||||
/* Wait a bit to see if the thread exits on its own */
|
|
||||||
|
|
||||||
usleep(HALF_SECOND_USEC_USEC);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Then cancel the thread and see if it did */
|
|
||||||
|
|
||||||
printf("mqueue_test: Canceling receiver\n");
|
|
||||||
status = pthread_cancel(receiver);
|
|
||||||
if (status == ESRCH)
|
|
||||||
{
|
|
||||||
printf("mqueue_test: receiver has already terminated\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
pthread_join(receiver, &result);
|
|
||||||
if (result != (void*)0)
|
|
||||||
{
|
|
||||||
printf("mqueue_test: ERROR receiver thread exited with %d errors\n", (int)result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -1,142 +0,0 @@
|
||||||
/***********************************************************************
|
|
||||||
* mutex.c
|
|
||||||
*
|
|
||||||
* Copyright (C) 2007, 2008 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 <stdio.h>
|
|
||||||
#include <pthread.h>
|
|
||||||
#include "ostest.h"
|
|
||||||
|
|
||||||
#ifndef NULL
|
|
||||||
# define NULL (void*)0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define NLOOPS 32
|
|
||||||
|
|
||||||
static pthread_mutex_t mut;
|
|
||||||
static volatile int my_mutex = 0;
|
|
||||||
static unsigned long nloops[2] = {0, 0};
|
|
||||||
static unsigned long nerrors[2] = {0, 0};
|
|
||||||
|
|
||||||
static void *thread_func(void *parameter)
|
|
||||||
{
|
|
||||||
int id = (int)parameter;
|
|
||||||
int ndx = id - 1;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (nloops[ndx] = 0; nloops[ndx] < NLOOPS; nloops[ndx]++)
|
|
||||||
{
|
|
||||||
int status = pthread_mutex_lock(&mut);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("ERROR thread %d: pthread_mutex_lock failed, status=%d\n",
|
|
||||||
id, status);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (my_mutex == 1)
|
|
||||||
{
|
|
||||||
printf("ERROR thread=%d: "
|
|
||||||
"my_mutex should be zero, instead my_mutex=%d\n",
|
|
||||||
id, my_mutex);
|
|
||||||
nerrors[ndx]++;
|
|
||||||
}
|
|
||||||
|
|
||||||
my_mutex = 1;
|
|
||||||
for (i = 0; i < 10; i++)
|
|
||||||
{
|
|
||||||
pthread_yield();
|
|
||||||
}
|
|
||||||
my_mutex = 0;
|
|
||||||
|
|
||||||
status = pthread_mutex_unlock(&mut);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("ERROR thread %d: pthread_mutex_unlock failed, status=%d\n",
|
|
||||||
id, status);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pthread_exit(NULL);
|
|
||||||
return NULL; /* Non-reachable -- needed for some compilers */
|
|
||||||
}
|
|
||||||
|
|
||||||
void mutex_test(void)
|
|
||||||
{
|
|
||||||
pthread_t thread1, thread2;
|
|
||||||
#ifdef SDCC
|
|
||||||
pthread_addr_t result1, result2;
|
|
||||||
pthread_attr_t attr;
|
|
||||||
#endif
|
|
||||||
int status;
|
|
||||||
|
|
||||||
/* Initialize the mutex */
|
|
||||||
|
|
||||||
printf("Initializing mutex\n");
|
|
||||||
pthread_mutex_init(&mut, NULL);
|
|
||||||
|
|
||||||
/* Start two thread instances */
|
|
||||||
|
|
||||||
printf("Starting thread 1\n");
|
|
||||||
#ifdef SDCC
|
|
||||||
(void)pthread_attr_init(&attr);
|
|
||||||
status = pthread_create(&thread1, &attr, thread_func, (pthread_addr_t)1);
|
|
||||||
#else
|
|
||||||
status = pthread_create(&thread1, NULL, thread_func, (pthread_addr_t)1);
|
|
||||||
#endif
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("Error in thread#1 creation\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("Starting thread 2\n");
|
|
||||||
#ifdef SDCC
|
|
||||||
status = pthread_create(&thread2, &attr, thread_func, (pthread_addr_t)2);
|
|
||||||
#else
|
|
||||||
status = pthread_create(&thread2, NULL, thread_func, (pthread_addr_t)2);
|
|
||||||
#endif
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("Error in thread#2 creation\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef SDCC
|
|
||||||
pthread_join(thread1, &result1);
|
|
||||||
pthread_join(thread2, &result2);
|
|
||||||
#else
|
|
||||||
pthread_join(thread1, NULL);
|
|
||||||
pthread_join(thread2, NULL);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
printf("\t\tThread1\tThread2\n");
|
|
||||||
printf("\tLoops\t%ld\t%ld\n", nloops[0], nloops[1]);
|
|
||||||
printf("\tErrors\t%ld\t%ld\n", nerrors[0], nerrors[1]);
|
|
||||||
}
|
|
|
@ -1,190 +0,0 @@
|
||||||
/****************************************************************************
|
|
||||||
* apps/examples/ostest/ostest.h
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
* 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 __APPS_EXAMPLES_OSTEST_OSTEST_H
|
|
||||||
#define __APPS_EXAMPLES_OSTEST_OSTEST_H
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Included Files
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#include <nuttx/config.h>
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Definitions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/* The task_create task size can be specified in the defconfig file */
|
|
||||||
|
|
||||||
#ifdef CONFIG_EXAMPLES_OSTEST_STACKSIZE
|
|
||||||
# define STACKSIZE CONFIG_EXAMPLES_OSTEST_STACKSIZE
|
|
||||||
#else
|
|
||||||
# define STACKSIZE 8192
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* The number of times to execute the test can be specified in the defconfig
|
|
||||||
* file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef CONFIG_EXAMPLES_OSTEST_LOOPS
|
|
||||||
# define CONFIG_EXAMPLES_OSTEST_LOOPS 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* This is the number of threads that are created in the barrier test.
|
|
||||||
* A smaller number should be selected on systems without sufficient memory
|
|
||||||
* to start so many threads.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef CONFIG_EXAMPLES_OSTEST_NBARRIER_THREADS
|
|
||||||
# define CONFIG_EXAMPLES_OSTEST_NBARRIER_THREADS 8
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Priority inheritance */
|
|
||||||
|
|
||||||
#if defined(CONFIG_DEBUG) && defined(CONFIG_PRIORITY_INHERITANCE) && defined(CONFIG_SEM_PHDEBUG)
|
|
||||||
# define dump_nfreeholders(s) printf(s " nfreeholders: %d\n", sem_nfreeholders())
|
|
||||||
#else
|
|
||||||
# define dump_nfreeholders(s)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* If CONFIG_STDIO_LINEBUFFER is defined, the STDIO buffer will be flushed
|
|
||||||
* on each new line. Otherwise, STDIO needs to be explicitly flushed to
|
|
||||||
* see the output in context.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0 && \
|
|
||||||
CONFIG_STDIO_BUFFER_SIZE > 0 && !defined(CONFIG_STDIO_LINEBUFFER)
|
|
||||||
# define FFLUSH() fflush(stdout)
|
|
||||||
#else
|
|
||||||
# define FFLUSH()
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Types
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Variables
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Function Prototypes
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/* dev_null.c ***************************************************************/
|
|
||||||
|
|
||||||
int dev_null(void);
|
|
||||||
|
|
||||||
/* fpu.c ********************************************************************/
|
|
||||||
|
|
||||||
void fpu_test(void);
|
|
||||||
|
|
||||||
/* waitpid.c ****************************************************************/
|
|
||||||
|
|
||||||
#ifdef CONFIG_SCHED_WAITPID
|
|
||||||
int waitpid_test(void);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* mutex.c ******************************************************************/
|
|
||||||
|
|
||||||
void mutex_test(void);
|
|
||||||
|
|
||||||
/* rmutex.c ******************************************************************/
|
|
||||||
|
|
||||||
void recursive_mutex_test(void);
|
|
||||||
|
|
||||||
/* sem.c ********************************************************************/
|
|
||||||
|
|
||||||
void sem_test(void);
|
|
||||||
|
|
||||||
/* cond.c *******************************************************************/
|
|
||||||
|
|
||||||
void cond_test(void);
|
|
||||||
|
|
||||||
/* mqueue.c *****************************************************************/
|
|
||||||
|
|
||||||
void mqueue_test(void);
|
|
||||||
|
|
||||||
/* timedmqueue.c ************************************************************/
|
|
||||||
|
|
||||||
void timedmqueue_test(void);
|
|
||||||
|
|
||||||
/* cancel.c *****************************************************************/
|
|
||||||
|
|
||||||
void cancel_test(void);
|
|
||||||
|
|
||||||
/* timedwait.c **************************************************************/
|
|
||||||
|
|
||||||
void timedwait_test(void);
|
|
||||||
|
|
||||||
/* sighand.c ****************************************************************/
|
|
||||||
|
|
||||||
void sighand_test(void);
|
|
||||||
|
|
||||||
/* posixtimers.c ************************************************************/
|
|
||||||
|
|
||||||
void timer_test(void);
|
|
||||||
|
|
||||||
/* roundrobin.c *************************************************************/
|
|
||||||
|
|
||||||
void rr_test(void);
|
|
||||||
|
|
||||||
/* barrier.c ****************************************************************/
|
|
||||||
|
|
||||||
void barrier_test(void);
|
|
||||||
|
|
||||||
/* prioinherit.c ************************************************************/
|
|
||||||
|
|
||||||
void priority_inheritance(void);
|
|
||||||
|
|
||||||
/* vfork.c ******************************************************************/
|
|
||||||
|
|
||||||
#ifdef CONFIG_ARCH_HAVE_VFORK
|
|
||||||
int vfork_test(void);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* APIs exported (conditionally) by the OS specifically for testing of
|
|
||||||
* priority inheritance
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if defined(CONFIG_DEBUG) && defined(CONFIG_PRIORITY_INHERITANCE) && defined(CONFIG_SEM_PHDEBUG)
|
|
||||||
void sem_enumholders(FAR sem_t *sem);
|
|
||||||
int sem_nfreeholders(void);
|
|
||||||
#else
|
|
||||||
# define sem_enumholders(sem)
|
|
||||||
# define sem_nfreeholders()
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* __APPS_EXAMPLES_OSTEST_OSTEST_H */
|
|
|
@ -1,564 +0,0 @@
|
||||||
/****************************************************************************
|
|
||||||
* apps/examples/ostest/ostest_main.c
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
* 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 <stdbool.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <signal.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <sched.h>
|
|
||||||
#include <errno.h>
|
|
||||||
|
|
||||||
#include <nuttx/init.h>
|
|
||||||
|
|
||||||
#include "ostest.h"
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Definitions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#define PRIORITY 100
|
|
||||||
#define NARGS 4
|
|
||||||
#define HALF_SECOND_USEC 500000L
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Data
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static const char arg1[] = "Arg1";
|
|
||||||
static const char arg2[] = "Arg2";
|
|
||||||
static const char arg3[] = "Arg3";
|
|
||||||
static const char arg4[] = "Arg4";
|
|
||||||
|
|
||||||
#if CONFIG_NFILE_DESCRIPTORS > 0
|
|
||||||
static const char write_data1[] = "stdio_test: write fd=1\n";
|
|
||||||
static const char write_data2[] = "stdio_test: write fd=2\n";
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef SDCC
|
|
||||||
/* I am not yet certain why SDCC does not like the following
|
|
||||||
* initializer. It involves some issues with 2- vs 3-byte
|
|
||||||
* pointer types.
|
|
||||||
*/
|
|
||||||
|
|
||||||
static const char *g_argv[NARGS+1];
|
|
||||||
#else
|
|
||||||
static const char *g_argv[NARGS+1] = { arg1, arg2, arg3, arg4, NULL };
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef CONFIG_DISABLE_SIGNALS
|
|
||||||
static struct mallinfo g_mmbefore;
|
|
||||||
static struct mallinfo g_mmprevious;
|
|
||||||
static struct mallinfo g_mmafter;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef CONFIG_DISABLE_ENVIRON
|
|
||||||
const char g_var1_name[] = "Variable1";
|
|
||||||
const char g_var1_value[] = "GoodValue1";
|
|
||||||
const char g_var2_name[] = "Variable2";
|
|
||||||
const char g_var2_value[] = "GoodValue2";
|
|
||||||
const char g_var3_name[] = "Variable3";
|
|
||||||
const char g_var3_value[] = "GoodValue3";
|
|
||||||
|
|
||||||
const char g_bad_value1[] = "BadValue1";
|
|
||||||
const char g_bad_value2[] = "BadValue2";
|
|
||||||
|
|
||||||
const char g_putenv_value[] = "Variable1=BadValue3";
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Functions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: show_memory_usage
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#ifndef CONFIG_DISABLE_SIGNALS
|
|
||||||
static void show_memory_usage(struct mallinfo *mmbefore,
|
|
||||||
struct mallinfo *mmafter)
|
|
||||||
{
|
|
||||||
printf("VARIABLE BEFORE AFTER\n");
|
|
||||||
printf("======== ======== ========\n");
|
|
||||||
printf("arena %8x %8x\n", mmbefore->arena, mmafter->arena);
|
|
||||||
printf("ordblks %8d %8d\n", mmbefore->ordblks, mmafter->ordblks);
|
|
||||||
printf("mxordblk %8x %8x\n", mmbefore->mxordblk, mmafter->mxordblk);
|
|
||||||
printf("uordblks %8x %8x\n", mmbefore->uordblks, mmafter->uordblks);
|
|
||||||
printf("fordblks %8x %8x\n", mmbefore->fordblks, mmafter->fordblks);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
# define show_memory_usage(mm1, mm2)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: check_test_memory_usage
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#ifndef CONFIG_DISABLE_SIGNALS
|
|
||||||
static void check_test_memory_usage(void)
|
|
||||||
{
|
|
||||||
/* Wait a little bit to let any threads terminate */
|
|
||||||
|
|
||||||
usleep(HALF_SECOND_USEC);
|
|
||||||
|
|
||||||
/* Get the current memory usage */
|
|
||||||
|
|
||||||
#ifdef CONFIG_CAN_PASS_STRUCTS
|
|
||||||
g_mmafter = mallinfo();
|
|
||||||
#else
|
|
||||||
(void)mallinfo(&g_mmafter);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Show the change from the previous time */
|
|
||||||
|
|
||||||
printf("\nEnd of test memory usage:\n");
|
|
||||||
show_memory_usage(&g_mmprevious, &g_mmafter);
|
|
||||||
|
|
||||||
/* Set up for the next test */
|
|
||||||
|
|
||||||
#ifdef CONFIG_CAN_PASS_STRUCTS
|
|
||||||
g_mmprevious = g_mmafter;
|
|
||||||
#else
|
|
||||||
memcpy(&g_mmprevious, &g_mmafter, sizeof(struct mallinfo));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* If so enabled, show the use of priority inheritance resources */
|
|
||||||
|
|
||||||
dump_nfreeholders("user_main:");
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
# define check_test_memory_usage()
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: show_variable
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#ifndef CONFIG_DISABLE_ENVIRON
|
|
||||||
static void show_variable(const char *var_name, const char *exptd_value, bool var_valid)
|
|
||||||
{
|
|
||||||
char *actual_value = getenv(var_name);
|
|
||||||
if (actual_value)
|
|
||||||
{
|
|
||||||
if (var_valid)
|
|
||||||
{
|
|
||||||
if (strcmp(actual_value, exptd_value) == 0)
|
|
||||||
{
|
|
||||||
printf("show_variable: Variable=%s has value=%s\n", var_name, exptd_value);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("show_variable: ERROR Variable=%s has the wrong value\n", var_name);
|
|
||||||
printf("show_variable: found=%s expected=%s\n", actual_value, exptd_value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("show_variable: ERROR Variable=%s has a value when it should not\n", var_name);
|
|
||||||
printf("show_variable: value=%s\n", actual_value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (var_valid)
|
|
||||||
{
|
|
||||||
printf("show_variable: ERROR Variable=%s has no value\n", var_name);
|
|
||||||
printf("show_variable: Should have had value=%s\n", exptd_value);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("show_variable: Variable=%s has no value\n", var_name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void show_environment(bool var1_valid, bool var2_valid, bool var3_valid)
|
|
||||||
{
|
|
||||||
show_variable(g_var1_name, g_var1_value, var1_valid);
|
|
||||||
show_variable(g_var2_name, g_var2_value, var2_valid);
|
|
||||||
show_variable(g_var3_name, g_var3_value, var3_valid);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
# define show_environment()
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: user_main
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static int user_main(int argc, char *argv[])
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
/* Sample the memory usage now */
|
|
||||||
|
|
||||||
#ifndef CONFIG_DISABLE_SIGNALS
|
|
||||||
usleep(HALF_SECOND_USEC);
|
|
||||||
|
|
||||||
#ifdef CONFIG_CAN_PASS_STRUCTS
|
|
||||||
g_mmbefore = mallinfo();
|
|
||||||
g_mmprevious = g_mmbefore;
|
|
||||||
#else
|
|
||||||
(void)mallinfo(&g_mmbefore);
|
|
||||||
memcpy(&g_mmprevious, &g_mmbefore, sizeof(struct mallinfo));
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
printf("\nuser_main: Begin argument test\n");
|
|
||||||
printf("user_main: Started with argc=%d\n", argc);
|
|
||||||
|
|
||||||
/* Verify passed arguments */
|
|
||||||
|
|
||||||
if (argc != NARGS + 1)
|
|
||||||
{
|
|
||||||
printf("user_main: Error expected argc=%d got argc=%d\n",
|
|
||||||
NARGS+1, argc);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i <= NARGS; i++)
|
|
||||||
{
|
|
||||||
printf("user_main: argv[%d]=\"%s\"\n", i, argv[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 1; i <= NARGS; i++)
|
|
||||||
{
|
|
||||||
if (strcmp(argv[i], g_argv[i-1]) != 0)
|
|
||||||
{
|
|
||||||
printf("user_main: ERROR argv[%d]: Expected \"%s\" found \"%s\"\n",
|
|
||||||
i, g_argv[i-1], argv[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
check_test_memory_usage();
|
|
||||||
|
|
||||||
/* If retention of child status is enable, then suppress it for this task.
|
|
||||||
* This task may produce many, many children (especially if
|
|
||||||
* CONFIG_EXAMPLES_OSTEST_LOOPS) and it does not harvest their exit status.
|
|
||||||
* As a result, the test may fail inappropriately unless retention of
|
|
||||||
* child exit status is disabled.
|
|
||||||
*
|
|
||||||
* So basically, this tests that child status can be disabled, but cannot
|
|
||||||
* verify that status is retained correctly.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if defined(CONFIG_SCHED_HAVE_PARENT) && defined(CONFIG_SCHED_CHILD_STATUS)
|
|
||||||
{
|
|
||||||
struct sigaction sa;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
sa.sa_handler = SIG_IGN;
|
|
||||||
sa.sa_flags = SA_NOCLDWAIT;
|
|
||||||
ret = sigaction(SIGCHLD, &sa, NULL);
|
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
printf("user_main: ERROR: sigaction failed: %d\n", errno);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Check environment variables */
|
|
||||||
#ifndef CONFIG_DISABLE_ENVIRON
|
|
||||||
show_environment(true, true, true);
|
|
||||||
|
|
||||||
unsetenv(g_var1_name);
|
|
||||||
show_environment(false, true, true);
|
|
||||||
check_test_memory_usage();
|
|
||||||
|
|
||||||
clearenv();
|
|
||||||
show_environment(false, false, false);
|
|
||||||
check_test_memory_usage();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Top of test loop */
|
|
||||||
|
|
||||||
#if CONFIG_EXAMPLES_OSTEST_LOOPS > 1
|
|
||||||
for (i = 0; i < CONFIG_EXAMPLES_OSTEST_LOOPS; i++)
|
|
||||||
#elif CONFIG_EXAMPLES_OSTEST_LOOPS == 0
|
|
||||||
for (;;)
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
#if CONFIG_NFILE_DESCRIPTORS > 0
|
|
||||||
/* Checkout /dev/null */
|
|
||||||
|
|
||||||
printf("\nuser_main: /dev/null test\n");
|
|
||||||
dev_null();
|
|
||||||
check_test_memory_usage();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CONFIG_ARCH_FPU
|
|
||||||
/* Check that the FPU is properly supported during context switching */
|
|
||||||
|
|
||||||
printf("\nuser_main: FPU test\n");
|
|
||||||
fpu_test();
|
|
||||||
check_test_memory_usage();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CONFIG_SCHED_WAITPID
|
|
||||||
/* Check waitpid() and friends */
|
|
||||||
|
|
||||||
printf("\nuser_main: waitpid test\n");
|
|
||||||
waitpid_test();
|
|
||||||
check_test_memory_usage();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef CONFIG_DISABLE_PTHREAD
|
|
||||||
/* Verify pthreads and pthread mutex */
|
|
||||||
|
|
||||||
printf("\nuser_main: mutex test\n");
|
|
||||||
mutex_test();
|
|
||||||
check_test_memory_usage();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if !defined(CONFIG_DISABLE_PTHREAD) && defined(CONFIG_MUTEX_TYPES)
|
|
||||||
/* Verify recursive mutexes */
|
|
||||||
|
|
||||||
printf("\nuser_main: recursive mutex test\n");
|
|
||||||
recursive_mutex_test();
|
|
||||||
check_test_memory_usage();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef CONFIG_DISABLE_PTHREAD
|
|
||||||
/* Verify pthread cancellation */
|
|
||||||
|
|
||||||
printf("\nuser_main: cancel test\n");
|
|
||||||
cancel_test();
|
|
||||||
check_test_memory_usage();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef CONFIG_DISABLE_PTHREAD
|
|
||||||
/* Verify pthreads and semaphores */
|
|
||||||
|
|
||||||
printf("\nuser_main: semaphore test\n");
|
|
||||||
sem_test();
|
|
||||||
check_test_memory_usage();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef CONFIG_DISABLE_PTHREAD
|
|
||||||
/* Verify pthreads and condition variables */
|
|
||||||
|
|
||||||
printf("\nuser_main: condition variable test\n");
|
|
||||||
#ifdef CONFIG_PRIORITY_INHERITANCE
|
|
||||||
printf("\n Skipping, Test logic incompatible with priority inheritance\n");
|
|
||||||
#else
|
|
||||||
cond_test();
|
|
||||||
check_test_memory_usage();
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if !defined(CONFIG_DISABLE_SIGNALS) && !defined(CONFIG_DISABLE_PTHREAD) && !defined(CONFIG_DISABLE_CLOCK)
|
|
||||||
/* Verify pthreads and condition variable timed waits */
|
|
||||||
|
|
||||||
printf("\nuser_main: timed wait test\n");
|
|
||||||
timedwait_test();
|
|
||||||
check_test_memory_usage();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if !defined(CONFIG_DISABLE_MQUEUE) && !defined(CONFIG_DISABLE_PTHREAD)
|
|
||||||
/* Verify pthreads and message queues */
|
|
||||||
|
|
||||||
printf("\nuser_main: message queue test\n");
|
|
||||||
mqueue_test();
|
|
||||||
check_test_memory_usage();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if !defined(CONFIG_DISABLE_MQUEUE) && !defined(CONFIG_DISABLE_PTHREAD) && !defined(CONFIG_DISABLE_CLOCK)
|
|
||||||
/* Verify pthreads and message queues */
|
|
||||||
|
|
||||||
printf("\nuser_main: timed message queue test\n");
|
|
||||||
timedmqueue_test();
|
|
||||||
check_test_memory_usage();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef CONFIG_DISABLE_SIGNALS
|
|
||||||
/* Verify signal handlers */
|
|
||||||
|
|
||||||
printf("\nuser_main: signal handler test\n");
|
|
||||||
sighand_test();
|
|
||||||
check_test_memory_usage();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if !defined(CONFIG_DISABLE_POSIX_TIMERS) && !defined(CONFIG_DISABLE_SIGNALS)
|
|
||||||
/* Verify posix timers */
|
|
||||||
|
|
||||||
printf("\nuser_main: POSIX timer test\n");
|
|
||||||
timer_test();
|
|
||||||
check_test_memory_usage();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if !defined(CONFIG_DISABLE_PTHREAD) && CONFIG_RR_INTERVAL > 0
|
|
||||||
/* Verify round robin scheduling */
|
|
||||||
|
|
||||||
printf("\nuser_main: round-robin scheduler test\n");
|
|
||||||
rr_test();
|
|
||||||
check_test_memory_usage();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef CONFIG_DISABLE_PTHREAD
|
|
||||||
/* Verify pthread barriers */
|
|
||||||
|
|
||||||
printf("\nuser_main: barrier test\n");
|
|
||||||
barrier_test();
|
|
||||||
check_test_memory_usage();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(CONFIG_PRIORITY_INHERITANCE) && !defined(CONFIG_DISABLE_SIGNALS) && !defined(CONFIG_DISABLE_PTHREAD)
|
|
||||||
/* Verify priority inheritance */
|
|
||||||
|
|
||||||
printf("\nuser_main: priority inheritance test\n");
|
|
||||||
priority_inheritance();
|
|
||||||
check_test_memory_usage();
|
|
||||||
#endif /* CONFIG_PRIORITY_INHERITANCE && !CONFIG_DISABLE_SIGNALS && !CONFIG_DISABLE_PTHREAD */
|
|
||||||
|
|
||||||
#ifdef CONFIG_ARCH_HAVE_VFORK
|
|
||||||
printf("\nuser_main: vfork() test\n");
|
|
||||||
vfork_test();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Compare memory usage at time ostest_main started until
|
|
||||||
* user_main exits. These should not be identical, but should
|
|
||||||
* be similar enough that we can detect any serious OS memory
|
|
||||||
* leaks.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef CONFIG_DISABLE_SIGNALS
|
|
||||||
usleep(HALF_SECOND_USEC);
|
|
||||||
|
|
||||||
#ifdef CONFIG_CAN_PASS_STRUCTS
|
|
||||||
g_mmafter = mallinfo();
|
|
||||||
#else
|
|
||||||
(void)mallinfo(&g_mmafter);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
printf("\nFinal memory usage:\n");
|
|
||||||
show_memory_usage(&g_mmbefore, &g_mmafter);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("user_main: Exitting\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: stdio_test
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static void stdio_test(void)
|
|
||||||
{
|
|
||||||
/* Verify that we can communicate */
|
|
||||||
|
|
||||||
#if CONFIG_NFILE_DESCRIPTORS > 0
|
|
||||||
write(1, write_data1, sizeof(write_data1)-1);
|
|
||||||
#endif
|
|
||||||
printf("stdio_test: Standard I/O Check: printf\n");
|
|
||||||
|
|
||||||
#if CONFIG_NFILE_DESCRIPTORS > 1
|
|
||||||
write(2, write_data2, sizeof(write_data2)-1);
|
|
||||||
#endif
|
|
||||||
#if CONFIG_NFILE_STREAMS > 0
|
|
||||||
fprintf(stderr, "stdio_test: Standard I/O Check: fprintf to stderr\n");
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Functions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* ostest_main
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
int ostest_main(int argc, char *argv[])
|
|
||||||
{
|
|
||||||
int result;
|
|
||||||
|
|
||||||
/* Verify that stdio works first */
|
|
||||||
|
|
||||||
stdio_test();
|
|
||||||
|
|
||||||
#ifdef SDCC
|
|
||||||
/* I am not yet certain why SDCC does not like the following initilizers.
|
|
||||||
* It involves some issues with 2- vs 3-byte pointer types.
|
|
||||||
*/
|
|
||||||
|
|
||||||
g_argv[0] = arg1;
|
|
||||||
g_argv[1] = arg2;
|
|
||||||
g_argv[2] = arg3;
|
|
||||||
g_argv[3] = arg4;
|
|
||||||
g_argv[4] = NULL;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Set up some environment variables */
|
|
||||||
|
|
||||||
#ifndef CONFIG_DISABLE_ENVIRON
|
|
||||||
printf("ostest_main: putenv(%s)\n", g_putenv_value);
|
|
||||||
putenv(g_putenv_value); /* Varaible1=BadValue3 */
|
|
||||||
printf("ostest_main: setenv(%s, %s, TRUE)\n", g_var1_name, g_var1_value);
|
|
||||||
setenv(g_var1_name, g_var1_value, TRUE); /* Variable1=GoodValue1 */
|
|
||||||
|
|
||||||
printf("ostest_main: setenv(%s, %s, FALSE)\n", g_var2_name, g_bad_value1);
|
|
||||||
setenv(g_var2_name, g_bad_value1, FALSE); /* Variable2=BadValue1 */
|
|
||||||
printf("ostest_main: setenv(%s, %s, TRUE)\n", g_var2_name, g_var2_value);
|
|
||||||
setenv(g_var2_name, g_var2_value, TRUE); /* Variable2=GoodValue2 */
|
|
||||||
|
|
||||||
printf("ostest_main: setenv(%s, %s, FALSE)\n", g_var3_name, g_var3_name);
|
|
||||||
setenv(g_var3_name, g_var3_value, FALSE); /* Variable3=GoodValue3 */
|
|
||||||
printf("ostest_main: setenv(%s, %s, FALSE)\n", g_var3_name, g_var3_name);
|
|
||||||
setenv(g_var3_name, g_bad_value2, FALSE); /* Variable3=GoodValue3 */
|
|
||||||
show_environment(true, true, true);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Verify that we can spawn a new task */
|
|
||||||
|
|
||||||
#ifndef CONFIG_CUSTOM_STACK
|
|
||||||
result = task_create("ostest", PRIORITY, STACKSIZE, user_main, g_argv);
|
|
||||||
#else
|
|
||||||
result = task_create("ostest", PRIORITY, user_main, g_argv);
|
|
||||||
#endif
|
|
||||||
if (result == ERROR)
|
|
||||||
{
|
|
||||||
printf("ostest_main: ERROR Failed to start user_main\n");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("ostest_main: Started user_main at PID=%d\n", result);
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("ostest_main: Exitting\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
|
@ -1,262 +0,0 @@
|
||||||
/***********************************************************************
|
|
||||||
* examples/ostest/posixtimer.c
|
|
||||||
*
|
|
||||||
* Copyright (C) 2007-2009, 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 <stdio.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <semaphore.h>
|
|
||||||
#include <signal.h>
|
|
||||||
#include <sched.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include "ostest.h"
|
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
* Private Definitions
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
#ifndef NULL
|
|
||||||
# define NULL (void*)0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define MY_TIMER_SIGNAL 17
|
|
||||||
#define SIGVALUE_INT 42
|
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
* Private Data
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
static sem_t sem;
|
|
||||||
static int g_nsigreceived = 0;
|
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
* Private Functions
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
static void timer_expiration(int signo, siginfo_t *info, void *ucontext)
|
|
||||||
{
|
|
||||||
sigset_t oldset;
|
|
||||||
sigset_t allsigs;
|
|
||||||
int status;
|
|
||||||
|
|
||||||
printf("timer_expiration: Received signal %d\n" , signo);
|
|
||||||
|
|
||||||
g_nsigreceived++;
|
|
||||||
|
|
||||||
/* Check signo */
|
|
||||||
|
|
||||||
if (signo != MY_TIMER_SIGNAL)
|
|
||||||
{
|
|
||||||
printf("timer_expiration: ERROR expected signo=%d\n" , MY_TIMER_SIGNAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check siginfo */
|
|
||||||
|
|
||||||
if (info->si_value.sival_int != SIGVALUE_INT)
|
|
||||||
{
|
|
||||||
printf("timer_expiration: ERROR sival_int=%d expected %d\n",
|
|
||||||
info->si_value.sival_int, SIGVALUE_INT);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("timer_expiration: sival_int=%d\n" , info->si_value.sival_int);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (info->si_signo != MY_TIMER_SIGNAL)
|
|
||||||
{
|
|
||||||
printf("timer_expiration: ERROR expected si_signo=%d, got=%d\n",
|
|
||||||
MY_TIMER_SIGNAL, info->si_signo);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (info->si_code == SI_TIMER)
|
|
||||||
{
|
|
||||||
printf("timer_expiration: si_code=%d (SI_TIMER)\n" , info->si_code);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("timer_expiration: ERROR si_code=%d, expected SI_TIMER=%d\n",
|
|
||||||
info->si_code, SI_TIMER);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check ucontext_t */
|
|
||||||
|
|
||||||
printf("timer_expiration: ucontext=%p\n" , ucontext);
|
|
||||||
|
|
||||||
/* Check sigprocmask */
|
|
||||||
|
|
||||||
(void)sigfillset(&allsigs);
|
|
||||||
status = sigprocmask(SIG_SETMASK, NULL, &oldset);
|
|
||||||
if (status != OK)
|
|
||||||
{
|
|
||||||
printf("timer_expiration: ERROR sigprocmask failed, status=%d\n",
|
|
||||||
status);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (oldset != allsigs)
|
|
||||||
{
|
|
||||||
printf("timer_expiration: ERROR sigprocmask=%x expected=%x\n",
|
|
||||||
oldset, allsigs);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
* Public Functions
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
void timer_test(void)
|
|
||||||
{
|
|
||||||
sigset_t sigset;
|
|
||||||
struct sigaction act;
|
|
||||||
struct sigaction oact;
|
|
||||||
struct sigevent notify;
|
|
||||||
struct itimerspec timer;
|
|
||||||
timer_t timerid;
|
|
||||||
int status;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
printf("timer_test: Initializing semaphore to 0\n" );
|
|
||||||
sem_init(&sem, 0, 0);
|
|
||||||
|
|
||||||
/* Start waiter thread */
|
|
||||||
|
|
||||||
printf("timer_test: Unmasking signal %d\n" , MY_TIMER_SIGNAL);
|
|
||||||
|
|
||||||
(void)sigemptyset(&sigset);
|
|
||||||
(void)sigaddset(&sigset, MY_TIMER_SIGNAL);
|
|
||||||
status = sigprocmask(SIG_UNBLOCK, &sigset, NULL);
|
|
||||||
if (status != OK)
|
|
||||||
{
|
|
||||||
printf("timer_test: ERROR sigprocmask failed, status=%d\n",
|
|
||||||
status);
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("timer_test: Registering signal handler\n" );
|
|
||||||
act.sa_sigaction = timer_expiration;
|
|
||||||
act.sa_flags = SA_SIGINFO;
|
|
||||||
|
|
||||||
(void)sigfillset(&act.sa_mask);
|
|
||||||
(void)sigdelset(&act.sa_mask, MY_TIMER_SIGNAL);
|
|
||||||
|
|
||||||
status = sigaction(MY_TIMER_SIGNAL, &act, &oact);
|
|
||||||
if (status != OK)
|
|
||||||
{
|
|
||||||
printf("timer_test: ERROR sigaction failed, status=%d\n" , status);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef SDCC
|
|
||||||
printf("timer_test: oact.sigaction=%p oact.sa_flags=%x oact.sa_mask=%x\n",
|
|
||||||
oact.sa_sigaction, oact.sa_flags, oact.sa_mask);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Create the POSIX timer */
|
|
||||||
|
|
||||||
printf("timer_test: Creating timer\n" );
|
|
||||||
|
|
||||||
notify.sigev_notify = SIGEV_SIGNAL;
|
|
||||||
notify.sigev_signo = MY_TIMER_SIGNAL;
|
|
||||||
notify.sigev_value.sival_int = SIGVALUE_INT;
|
|
||||||
|
|
||||||
status = timer_create(CLOCK_REALTIME, ¬ify, &timerid);
|
|
||||||
if (status != OK)
|
|
||||||
{
|
|
||||||
printf("timer_test: timer_create failed, errno=%d\n", errno);
|
|
||||||
goto errorout;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Start the POSIX timer */
|
|
||||||
|
|
||||||
printf("timer_test: Starting timer\n" );
|
|
||||||
|
|
||||||
timer.it_value.tv_sec = 2;
|
|
||||||
timer.it_value.tv_nsec = 0;
|
|
||||||
timer.it_interval.tv_sec = 2;
|
|
||||||
timer.it_interval.tv_nsec = 0;
|
|
||||||
|
|
||||||
status = timer_settime(timerid, 0, &timer, NULL);
|
|
||||||
if (status != OK)
|
|
||||||
{
|
|
||||||
printf("timer_test: timer_settime failed, errno=%d\n", errno);
|
|
||||||
goto errorout;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Take the semaphore */
|
|
||||||
|
|
||||||
for (i = 0; i < 5; i++)
|
|
||||||
{
|
|
||||||
printf("timer_test: Waiting on semaphore\n" );
|
|
||||||
FFLUSH();
|
|
||||||
status = sem_wait(&sem);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
int error = errno;
|
|
||||||
if (error == EINTR)
|
|
||||||
{
|
|
||||||
printf("timer_test: sem_wait() successfully interrupted by signal\n" );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("timer_test: ERROR sem_wait failed, errno=%d\n" , error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("timer_test: ERROR awakened with no error!\n" );
|
|
||||||
}
|
|
||||||
printf("timer_test: g_nsigreceived=%d\n", g_nsigreceived);
|
|
||||||
}
|
|
||||||
|
|
||||||
errorout:
|
|
||||||
sem_destroy(&sem);
|
|
||||||
|
|
||||||
/* Then delete the timer */
|
|
||||||
|
|
||||||
printf("timer_test: Deleting timer\n" );
|
|
||||||
status = timer_delete(timerid);
|
|
||||||
if (status != OK)
|
|
||||||
{
|
|
||||||
printf("timer_test: timer_create failed, errno=%d\n", errno);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Detach the signal handler */
|
|
||||||
|
|
||||||
act.sa_sigaction = SIG_DFL;
|
|
||||||
status = sigaction(MY_TIMER_SIGNAL, &act, &oact);
|
|
||||||
|
|
||||||
printf("timer_test: done\n" );
|
|
||||||
FFLUSH();
|
|
||||||
}
|
|
|
@ -1,559 +0,0 @@
|
||||||
/****************************************************************************
|
|
||||||
* examples/ostest/prioinherit.c
|
|
||||||
*
|
|
||||||
* Copyright (C) 2009, 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 <stdio.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <semaphore.h>
|
|
||||||
#include <pthread.h>
|
|
||||||
#include <errno.h>
|
|
||||||
|
|
||||||
#ifdef CONFIG_ARCH_SIM
|
|
||||||
# include <nuttx/arch.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "ostest.h"
|
|
||||||
|
|
||||||
#if defined(CONFIG_PRIORITY_INHERITANCE) && !defined(CONFIG_DISABLE_SIGNALS) && !defined(CONFIG_DISABLE_PTHREAD)
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Definitions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#ifndef CONFIG_SEM_PREALLOCHOLDERS
|
|
||||||
# define CONFIG_SEM_PREALLOCHOLDERS 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* If resources were configured for lots of holders, then run 3 low priority
|
|
||||||
* threads. Otherwise, just one.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if CONFIG_SEM_PREALLOCHOLDERS > 3
|
|
||||||
# define NLOWPRI_THREADS 3
|
|
||||||
#else
|
|
||||||
# define NLOWPRI_THREADS 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef CONFIG_SEM_NNESTPRIO
|
|
||||||
# define CONFIG_SEM_NNESTPRIO 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Where resources configured for lots of waiters? If so then run 3 high
|
|
||||||
* priority threads. Otherwise, just one.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if CONFIG_SEM_NNESTPRIO > 3
|
|
||||||
# define NHIGHPRI_THREADS 3
|
|
||||||
#else
|
|
||||||
# define NHIGHPRI_THREADS 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Data
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Functions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
enum thstate_e
|
|
||||||
{
|
|
||||||
NOTSTARTED = 0,
|
|
||||||
RUNNING,
|
|
||||||
WAITING,
|
|
||||||
DONE
|
|
||||||
};
|
|
||||||
|
|
||||||
static sem_t g_sem;
|
|
||||||
static volatile enum thstate_e g_middlestate;
|
|
||||||
static volatile enum thstate_e g_highstate[NHIGHPRI_THREADS];
|
|
||||||
static volatile enum thstate_e g_lowstate[NLOWPRI_THREADS];
|
|
||||||
static int g_highpri;
|
|
||||||
static int g_medpri;
|
|
||||||
static int g_lowpri;
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: nhighpri_waiting
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static int nhighpri_waiting(void)
|
|
||||||
{
|
|
||||||
int n = 0;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i < NHIGHPRI_THREADS; i++)
|
|
||||||
{
|
|
||||||
if (g_highstate[i] == WAITING)
|
|
||||||
{
|
|
||||||
n++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: nhighpri_running
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static int nhighpri_running(void)
|
|
||||||
{
|
|
||||||
int n = 0;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i < NHIGHPRI_THREADS; i++)
|
|
||||||
{
|
|
||||||
if (g_highstate[i] != DONE)
|
|
||||||
{
|
|
||||||
n++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: highpri_thread
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static void *highpri_thread(void *parameter)
|
|
||||||
{
|
|
||||||
int threadno = (int)parameter;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
g_highstate[threadno-1] = RUNNING;
|
|
||||||
|
|
||||||
printf("highpri_thread-%d: Started\n", threadno);
|
|
||||||
FFLUSH();
|
|
||||||
sleep(1);
|
|
||||||
|
|
||||||
printf("highpri_thread-%d: Calling sem_wait()\n", threadno);
|
|
||||||
g_highstate[threadno-1] = WAITING;
|
|
||||||
ret = sem_wait(&g_sem);
|
|
||||||
g_highstate[threadno-1] = DONE;
|
|
||||||
|
|
||||||
if (ret != 0)
|
|
||||||
{
|
|
||||||
printf("highpri_thread-%d: sem_take failed: %d\n", threadno, ret);
|
|
||||||
}
|
|
||||||
else if (g_middlestate == RUNNING)
|
|
||||||
{
|
|
||||||
printf("highpri_thread-%d: SUCCESS midpri_thread is still running!\n", threadno);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("highpri_thread-%d: ERROR -- midpri_thread has already exited!\n", threadno);
|
|
||||||
}
|
|
||||||
|
|
||||||
sem_post(&g_sem);
|
|
||||||
printf("highpri_thread-%d: Okay... I'm done!\n", threadno);
|
|
||||||
FFLUSH();
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: hog_cpu
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static inline void hog_cpu(void)
|
|
||||||
{
|
|
||||||
#ifdef CONFIG_ARCH_SIM
|
|
||||||
/* The simulator doesn't have any mechanism to do asynchronous pre-emption
|
|
||||||
* (basically because it doesn't have any interupts/asynchronous events).
|
|
||||||
* The simulator does "fake" a timer interrupt in up_idle() -- the idle
|
|
||||||
* thread that only executes when nothing else is running. In the simulator,
|
|
||||||
* we cannot suspend the middle priority task, or we wouldn't have the
|
|
||||||
* test that we want. So, we have no option but to pump the fake clock
|
|
||||||
* here by calling up_idle(). Sigh!
|
|
||||||
*/
|
|
||||||
|
|
||||||
up_idle();
|
|
||||||
#else
|
|
||||||
/* On real platforms with a real timer interrupt, we really can hog the
|
|
||||||
* CPU. When the sleep() goes off in priority_inheritance(), it will
|
|
||||||
* wake up and start the high priority thread.
|
|
||||||
*/
|
|
||||||
|
|
||||||
volatile int i;
|
|
||||||
for (i = 0; i < INT_MAX; i++);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: medpri_thread
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static void *medpri_thread(void *parameter)
|
|
||||||
{
|
|
||||||
printf("medpri_thread: Started ... I won't let go of the CPU!\n");
|
|
||||||
g_middlestate = RUNNING;
|
|
||||||
FFLUSH();
|
|
||||||
|
|
||||||
/* The following loop will completely block lowpri_thread from running.
|
|
||||||
* UNLESS priority inheritance is working. In that case, its priority
|
|
||||||
* will be boosted.
|
|
||||||
*/
|
|
||||||
|
|
||||||
while (nhighpri_running() > 0)
|
|
||||||
{
|
|
||||||
hog_cpu();
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("medpri_thread: Okay... I'm done!\n");
|
|
||||||
FFLUSH();
|
|
||||||
g_middlestate = DONE;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: lowpri_thread
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static void *lowpri_thread(void *parameter)
|
|
||||||
{
|
|
||||||
void *retval = (void*)-1;
|
|
||||||
struct sched_param sparam;
|
|
||||||
int threadno = (int)parameter;
|
|
||||||
int expected;
|
|
||||||
int count;
|
|
||||||
int policy;
|
|
||||||
int ret;
|
|
||||||
int nwaiting;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
g_lowstate[threadno-1] = RUNNING;
|
|
||||||
printf("lowpri_thread-%d: Started\n", threadno);
|
|
||||||
|
|
||||||
ret = pthread_getschedparam(pthread_self(), &policy, &sparam);
|
|
||||||
if (ret != 0)
|
|
||||||
{
|
|
||||||
printf("lowpri_thread-%d: ERROR pthread_getschedparam failed: %d\n", threadno, ret);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("lowpri_thread-%d: initial priority: %d\n", threadno, sparam.sched_priority);
|
|
||||||
if (sparam.sched_priority != g_lowpri)
|
|
||||||
{
|
|
||||||
printf(" ERROR should have been %d\n", g_lowpri);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
g_lowstate[threadno-1] = WAITING;
|
|
||||||
ret = sem_wait(&g_sem);
|
|
||||||
if (ret != 0)
|
|
||||||
{
|
|
||||||
printf("lowpri_thread-%d: sem_take failed: %d\n", threadno, ret);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Hang on to the thread until the middle priority thread runs */
|
|
||||||
|
|
||||||
while (g_middlestate == NOTSTARTED && nhighpri_waiting() < NHIGHPRI_THREADS)
|
|
||||||
{
|
|
||||||
printf("lowpri_thread-%d: Waiting for the midle pri task to run\n", threadno);
|
|
||||||
printf(" g_middlestate: %d\n", (int)g_middlestate);
|
|
||||||
for (i = 0; i < NHIGHPRI_THREADS; i++)
|
|
||||||
{
|
|
||||||
printf(" g_highstate[%d]: %d\n", i, (int)g_highstate[i]);
|
|
||||||
}
|
|
||||||
printf(" I still have a count on the semaphore\n");
|
|
||||||
sem_enumholders(&g_sem);
|
|
||||||
FFLUSH();
|
|
||||||
sleep(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Account for all of the semaphore counts. At any given time if there are 'n'
|
|
||||||
* running hight prioity tasks, then the semaphore count should be '-n'
|
|
||||||
*/
|
|
||||||
|
|
||||||
sched_lock(); /* Needs to be atomic */
|
|
||||||
ret = sem_getvalue(&g_sem, &count);
|
|
||||||
nwaiting = nhighpri_waiting();
|
|
||||||
sched_unlock();
|
|
||||||
|
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
printf("lowpri_thread-%d: ERROR sem_getvalue failed: %d\n", threadno, errno);
|
|
||||||
}
|
|
||||||
printf("lowpri_thread-%d: Sem count: %d, No. highpri thread: %d\n", threadno, count, nwaiting);
|
|
||||||
|
|
||||||
/* The middle priority task is running, let go of the semaphore */
|
|
||||||
|
|
||||||
if (g_middlestate == RUNNING && nwaiting == -count)
|
|
||||||
{
|
|
||||||
/* Good.. the middle priority task is still running and the counts are okay. */
|
|
||||||
|
|
||||||
retval = NULL;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* If the sem count is positive, then there all of the higher priority threads
|
|
||||||
* should have already completed.
|
|
||||||
*/
|
|
||||||
|
|
||||||
printf("lowpri_thread-%d: %s the middle priority task has already exitted!\n",
|
|
||||||
threadno, count >= 0 ? "SUCCESS" : "ERROR" );
|
|
||||||
printf(" g_middlestate: %d sem count=%d\n", (int)g_middlestate, count);
|
|
||||||
for (i = 0; i < NHIGHPRI_THREADS; i++)
|
|
||||||
{
|
|
||||||
printf(" g_highstate[%d]: %d\n", i, (int)g_highstate[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = pthread_getschedparam(pthread_self(), &policy, &sparam);
|
|
||||||
sem_enumholders(&g_sem);
|
|
||||||
sem_post(&g_sem);
|
|
||||||
if (ret != 0)
|
|
||||||
{
|
|
||||||
printf("lowpri_thread-%d: ERROR pthread_getschedparam failed: %d\n", threadno, ret);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (nwaiting > 0)
|
|
||||||
{
|
|
||||||
expected = g_highpri;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
expected = g_lowpri;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("lowpri_thread-%d: %s priority before sem_post: %d\n",
|
|
||||||
threadno,
|
|
||||||
sparam.sched_priority != expected ? "ERROR" : "SUCCESS",
|
|
||||||
sparam.sched_priority);
|
|
||||||
|
|
||||||
if (sparam.sched_priority != expected)
|
|
||||||
{
|
|
||||||
printf(" ERROR should have been %d\n", expected);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = pthread_getschedparam(pthread_self(), &policy, &sparam);
|
|
||||||
if (ret != 0)
|
|
||||||
{
|
|
||||||
printf("lowpri_thread-%d: ERROR pthread_getschedparam failed: %d\n", threadno, ret);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("lowpri_thread-%d: %s final priority: %d\n",
|
|
||||||
threadno,
|
|
||||||
sparam.sched_priority != g_lowpri ? "ERROR" : "SUCCESS",
|
|
||||||
sparam.sched_priority);
|
|
||||||
|
|
||||||
if (sparam.sched_priority != g_lowpri)
|
|
||||||
{
|
|
||||||
printf(" ERROR should have been %d\n", g_lowpri);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sem_enumholders(&g_sem);
|
|
||||||
|
|
||||||
printf("lowpri_thread-%d: Okay... I'm done!\n", threadno);
|
|
||||||
FFLUSH();
|
|
||||||
g_lowstate[threadno-1] = DONE;
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
#endif /* CONFIG_PRIORITY_INHERITANCE && !CONFIG_DISABLE_SIGNALS && !CONFIG_DISABLE_PTHREAD */
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Functions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: priority_inheritance
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
void priority_inheritance(void)
|
|
||||||
{
|
|
||||||
#if defined(CONFIG_PRIORITY_INHERITANCE) && !defined(CONFIG_DISABLE_SIGNALS) && !defined(CONFIG_DISABLE_PTHREAD)
|
|
||||||
pthread_t lowpri[NLOWPRI_THREADS];
|
|
||||||
pthread_t medpri;
|
|
||||||
pthread_t highpri[NHIGHPRI_THREADS];
|
|
||||||
pthread_addr_t result;
|
|
||||||
pthread_attr_t attr;
|
|
||||||
struct sched_param sparam;
|
|
||||||
int my_pri;
|
|
||||||
int status;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
printf("priority_inheritance: Started\n");
|
|
||||||
|
|
||||||
g_middlestate = NOTSTARTED;
|
|
||||||
for (i = 0; i < NHIGHPRI_THREADS; i++) g_highstate[i] = NOTSTARTED;
|
|
||||||
for (i = 0; i < NLOWPRI_THREADS; i++) g_lowstate[i] = NOTSTARTED;
|
|
||||||
|
|
||||||
status = sched_getparam (getpid(), &sparam);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("priority_inheritance: sched_getparam failed\n");
|
|
||||||
sparam.sched_priority = PTHREAD_DEFAULT_PRIORITY;
|
|
||||||
}
|
|
||||||
my_pri = sparam.sched_priority;
|
|
||||||
|
|
||||||
g_highpri = sched_get_priority_max(SCHED_FIFO);
|
|
||||||
g_lowpri = sched_get_priority_min(SCHED_FIFO);
|
|
||||||
g_medpri = my_pri - 1;
|
|
||||||
|
|
||||||
sem_init(&g_sem, 0, NLOWPRI_THREADS);
|
|
||||||
dump_nfreeholders("priority_inheritance:");
|
|
||||||
|
|
||||||
/* Start the low priority threads */
|
|
||||||
|
|
||||||
for (i = 0; i < NLOWPRI_THREADS; i++)
|
|
||||||
{
|
|
||||||
int threadno = i+1;
|
|
||||||
printf("priority_inheritance: Starting lowpri_thread-%d (of %d) at %d\n",
|
|
||||||
threadno, NLOWPRI_THREADS, g_lowpri);
|
|
||||||
status = pthread_attr_init(&attr);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("priority_inheritance: pthread_attr_init failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
sparam.sched_priority = g_lowpri;
|
|
||||||
status = pthread_attr_setschedparam(&attr,& sparam);
|
|
||||||
if (status != OK)
|
|
||||||
{
|
|
||||||
printf("priority_inheritance: pthread_attr_setschedparam failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("priority_inheritance: Set lowpri_thread-%d priority to %d\n",
|
|
||||||
threadno, sparam.sched_priority);
|
|
||||||
}
|
|
||||||
|
|
||||||
status = pthread_create(&lowpri[i], &attr, lowpri_thread, (void*)threadno);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("priority_inheritance: pthread_create failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
printf("priority_inheritance: Waiting...\n");
|
|
||||||
sleep(2);
|
|
||||||
dump_nfreeholders("priority_inheritance:");
|
|
||||||
|
|
||||||
/* Start the medium priority thread */
|
|
||||||
|
|
||||||
printf("priority_inheritance: Starting medpri_thread at %d\n", g_medpri);
|
|
||||||
status = pthread_attr_init(&attr);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("priority_inheritance: pthread_attr_init failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
sparam.sched_priority = g_medpri;
|
|
||||||
status = pthread_attr_setschedparam(&attr,& sparam);
|
|
||||||
if (status != OK)
|
|
||||||
{
|
|
||||||
printf("priority_inheritance: pthread_attr_setschedparam failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("priority_inheritance: Set medpri_thread priority to %d\n", sparam.sched_priority);
|
|
||||||
}
|
|
||||||
FFLUSH();
|
|
||||||
|
|
||||||
status = pthread_create(&medpri, &attr, medpri_thread, NULL);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("priority_inheritance: pthread_create failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
printf("priority_inheritance: Waiting...\n");
|
|
||||||
sleep(1);
|
|
||||||
dump_nfreeholders("priority_inheritance:");
|
|
||||||
|
|
||||||
/* Start the high priority threads */
|
|
||||||
|
|
||||||
for (i = 0; i < NHIGHPRI_THREADS; i++)
|
|
||||||
{
|
|
||||||
int threadno = i+1;
|
|
||||||
printf("priority_inheritance: Starting highpri_thread-%d (of %d) at %d\n",
|
|
||||||
threadno, NHIGHPRI_THREADS, g_highpri);
|
|
||||||
status = pthread_attr_init(&attr);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("priority_inheritance: pthread_attr_init failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
sparam.sched_priority = g_highpri - i;
|
|
||||||
status = pthread_attr_setschedparam(&attr,& sparam);
|
|
||||||
if (status != OK)
|
|
||||||
{
|
|
||||||
printf("priority_inheritance: pthread_attr_setschedparam failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("priority_inheritance: Set highpri_thread-%d priority to %d\n",
|
|
||||||
threadno, sparam.sched_priority);
|
|
||||||
}
|
|
||||||
FFLUSH();
|
|
||||||
|
|
||||||
status = pthread_create(&highpri[i], &attr, highpri_thread, (void*)threadno);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("priority_inheritance: pthread_create failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
dump_nfreeholders("priority_inheritance:");
|
|
||||||
FFLUSH();
|
|
||||||
|
|
||||||
/* Wait for all thread instances to complete */
|
|
||||||
|
|
||||||
for (i = 0; i < NHIGHPRI_THREADS; i++)
|
|
||||||
{
|
|
||||||
printf("priority_inheritance: Waiting for highpri_thread-%d to complete\n", i+1);
|
|
||||||
FFLUSH();
|
|
||||||
(void)pthread_join(highpri[i], &result);
|
|
||||||
dump_nfreeholders("priority_inheritance:");
|
|
||||||
}
|
|
||||||
printf("priority_inheritance: Waiting for medpri_thread to complete\n");
|
|
||||||
FFLUSH();
|
|
||||||
(void)pthread_join(medpri, &result);
|
|
||||||
dump_nfreeholders("priority_inheritance:");
|
|
||||||
for (i = 0; i < NLOWPRI_THREADS; i++)
|
|
||||||
{
|
|
||||||
printf("priority_inheritance: Waiting for lowpri_thread-%d to complete\n", i+1);
|
|
||||||
FFLUSH();
|
|
||||||
(void)pthread_join(lowpri[i], &result);
|
|
||||||
dump_nfreeholders("priority_inheritance:");
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("priority_inheritance: Finished\n");
|
|
||||||
sem_destroy(&g_sem);
|
|
||||||
dump_nfreeholders("priority_inheritance:");
|
|
||||||
FFLUSH();
|
|
||||||
#endif /* CONFIG_PRIORITY_INHERITANCE && !CONFIG_DISABLE_SIGNALS && !CONFIG_DISABLE_PTHREAD */
|
|
||||||
}
|
|
|
@ -1,166 +0,0 @@
|
||||||
/***********************************************************************
|
|
||||||
* rmutex.c
|
|
||||||
*
|
|
||||||
* Copyright (C) 2008 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 <stdio.h>
|
|
||||||
#include <pthread.h>
|
|
||||||
#include "ostest.h"
|
|
||||||
|
|
||||||
#ifndef NULL
|
|
||||||
# define NULL (void*)0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define NTHREADS 3
|
|
||||||
#define NLOOPS 3
|
|
||||||
#define NRECURSIONS 3
|
|
||||||
|
|
||||||
static pthread_mutex_t mut;
|
|
||||||
|
|
||||||
static void thread_inner(int id, int level)
|
|
||||||
{
|
|
||||||
int status;
|
|
||||||
if (level < NRECURSIONS)
|
|
||||||
{
|
|
||||||
/* Take the mutex */
|
|
||||||
|
|
||||||
printf("thread_inner[%d, %d]: Locking\n", id, level);
|
|
||||||
status = pthread_mutex_lock(&mut);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("thread_inner[%d, %d]: ERROR pthread_mutex_lock failed: %d\n",
|
|
||||||
id, level, status);
|
|
||||||
}
|
|
||||||
printf("thread_inner[%d, %d]: Locked\n", id, level);
|
|
||||||
|
|
||||||
/* Give the other threads a chance */
|
|
||||||
|
|
||||||
pthread_yield();
|
|
||||||
thread_inner(id, level+1);
|
|
||||||
pthread_yield();
|
|
||||||
|
|
||||||
/* Unlock the mutex */
|
|
||||||
|
|
||||||
printf("thread_inner[%d, %d]: Unlocking\n", id, level);
|
|
||||||
status = pthread_mutex_unlock(&mut);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("thread_inner[%d, %d]: ERROR pthread_mutex_unlock failed: %d\n",
|
|
||||||
id, level, status);
|
|
||||||
}
|
|
||||||
printf("thread_inner[%d, %d]: Unlocked\n", id, level);
|
|
||||||
pthread_yield();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void *thread_outer(void *parameter)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
printf("thread_outer[%d]: Started\n", (int)parameter);
|
|
||||||
for (i = 0; i < NLOOPS; i++)
|
|
||||||
{
|
|
||||||
printf("thread_outer[%d]: Loop %d\n", (int)parameter, i);
|
|
||||||
thread_inner((int)parameter, 0);
|
|
||||||
}
|
|
||||||
printf("thread_outer[%d]: Exitting\n", (int)parameter);
|
|
||||||
pthread_exit(NULL);
|
|
||||||
return NULL; /* Non-reachable -- needed for some compilers */
|
|
||||||
}
|
|
||||||
|
|
||||||
void recursive_mutex_test(void)
|
|
||||||
{
|
|
||||||
pthread_t thread[NTHREADS];
|
|
||||||
#ifdef SDCC
|
|
||||||
pthread_addr_t result[NTHREADS];
|
|
||||||
pthread_attr_t attr;
|
|
||||||
#endif
|
|
||||||
pthread_mutexattr_t mattr;
|
|
||||||
int type;
|
|
||||||
int status;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
/* Initialize the mutex attributes */
|
|
||||||
|
|
||||||
pthread_mutexattr_init(&mattr);
|
|
||||||
status = pthread_mutexattr_settype(&mattr, PTHREAD_MUTEX_RECURSIVE);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("recursive_mutex_test: ERROR pthread_mutexattr_settype failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
status = pthread_mutexattr_gettype(&mattr, &type);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("recursive_mutex_test: ERROR pthread_mutexattr_gettype failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
if (type != PTHREAD_MUTEX_RECURSIVE)
|
|
||||||
{
|
|
||||||
printf("recursive_mutex_test: ERROR pthread_mutexattr_gettype return type=%d\n", type);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Initialize the mutex */
|
|
||||||
|
|
||||||
printf("recursive_mutex_test: Initializing mutex\n");
|
|
||||||
pthread_mutex_init(&mut, &mattr);
|
|
||||||
|
|
||||||
/* Start the threads -- all at the same, default priority */
|
|
||||||
|
|
||||||
for (i = 0; i < NTHREADS; i++)
|
|
||||||
{
|
|
||||||
printf("recursive_mutex_test: Starting thread %d\n", i+1);
|
|
||||||
#ifdef SDCC
|
|
||||||
(void)pthread_attr_init(&attr);
|
|
||||||
status = pthread_create(&thread[i], &attr, thread_outer, (pthread_addr_t)i+1);
|
|
||||||
#else
|
|
||||||
status = pthread_create(&thread[i], NULL, thread_outer, (pthread_addr_t)i+1);
|
|
||||||
#endif
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("recursive_mutex_test: ERRROR thread#%d creation: %d\n", i+1, status);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Wait for all; of the threads to complete */
|
|
||||||
|
|
||||||
for (i = 0; i < NTHREADS; i++)
|
|
||||||
{
|
|
||||||
printf("recursive_mutex_test: Waiting for thread %d\n", i+1);
|
|
||||||
#ifdef SDCC
|
|
||||||
pthread_join(thread[i], &result1);
|
|
||||||
#else
|
|
||||||
pthread_join(thread[i], NULL);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("recursive_mutex_test: Complete\n");
|
|
||||||
}
|
|
|
@ -1,206 +0,0 @@
|
||||||
/********************************************************************************
|
|
||||||
* examples/ostest/roundrobin.c
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
* 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 <stdbool.h>
|
|
||||||
#include "ostest.h"
|
|
||||||
|
|
||||||
#if CONFIG_RR_INTERVAL > 0
|
|
||||||
|
|
||||||
/********************************************************************************
|
|
||||||
* Definitions
|
|
||||||
********************************************************************************/
|
|
||||||
|
|
||||||
/* 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. */
|
|
||||||
|
|
||||||
#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
|
|
||||||
|
|
||||||
#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: get_primes
|
|
||||||
*
|
|
||||||
* Description
|
|
||||||
* This function searches for prime numbers in the most primitive way possible.
|
|
||||||
********************************************************************************/
|
|
||||||
|
|
||||||
static void get_primes(int *count, int *last)
|
|
||||||
{
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
local_count++;
|
|
||||||
*last = number;
|
|
||||||
#if 0 /* We don't really care what the numbers are */
|
|
||||||
printf(" Prime %d: %d\n", local_count, number);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
*count = local_count;
|
|
||||||
}
|
|
||||||
|
|
||||||
/********************************************************************************
|
|
||||||
* Name: get_primes_thread
|
|
||||||
********************************************************************************/
|
|
||||||
|
|
||||||
static void *get_primes_thread(void *parameter)
|
|
||||||
{
|
|
||||||
int id = (int)parameter;
|
|
||||||
int i, count, last;
|
|
||||||
|
|
||||||
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 < CONFIG_EXAMPLES_OSTEST_RR_RUNS; i++)
|
|
||||||
{
|
|
||||||
get_primes(&count, &last);
|
|
||||||
}
|
|
||||||
|
|
||||||
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 */
|
|
||||||
}
|
|
||||||
|
|
||||||
/********************************************************************************
|
|
||||||
* Public Functions
|
|
||||||
********************************************************************************/
|
|
||||||
|
|
||||||
/********************************************************************************
|
|
||||||
* Name: rr_test
|
|
||||||
********************************************************************************/
|
|
||||||
|
|
||||||
void rr_test(void)
|
|
||||||
{
|
|
||||||
pthread_t get_primes1_thread;
|
|
||||||
pthread_t get_primes2_thread;
|
|
||||||
struct sched_param sparam;
|
|
||||||
pthread_attr_t attr;
|
|
||||||
pthread_addr_t result;
|
|
||||||
int status;
|
|
||||||
|
|
||||||
status = pthread_attr_init(&attr);
|
|
||||||
if (status != OK)
|
|
||||||
{
|
|
||||||
printf("rr_test: pthread_attr_init failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
sparam.sched_priority = sched_get_priority_min(SCHED_FIFO);
|
|
||||||
status = pthread_attr_setschedparam(&attr, &sparam);
|
|
||||||
if (status != OK)
|
|
||||||
{
|
|
||||||
printf("rr_test: pthread_attr_setschedparam failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("rr_test: Set thread priority to %d\n", sparam.sched_priority);
|
|
||||||
}
|
|
||||||
|
|
||||||
status = pthread_attr_setschedpolicy(&attr, SCHED_RR);
|
|
||||||
if (status != OK)
|
|
||||||
{
|
|
||||||
printf("rr_test: pthread_attr_setschedpolicy failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("rr_test: Set thread policy to SCHED_RR\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
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 second get_primes_thread\n");
|
|
||||||
|
|
||||||
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 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(get_primes2_thread, &result);
|
|
||||||
pthread_join(get_primes1_thread, &result);
|
|
||||||
printf("rr_test: Done\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* CONFIG_RR_INTERVAL */
|
|
|
@ -1,246 +0,0 @@
|
||||||
/***********************************************************************
|
|
||||||
* sem.c
|
|
||||||
*
|
|
||||||
* Copyright (C) 2007-2009 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 <stdio.h>
|
|
||||||
#include <pthread.h>
|
|
||||||
#include <semaphore.h>
|
|
||||||
#include <sched.h>
|
|
||||||
#include "ostest.h"
|
|
||||||
|
|
||||||
#ifndef NULL
|
|
||||||
# define NULL (void*)0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static sem_t sem;
|
|
||||||
|
|
||||||
static void *waiter_func(void *parameter)
|
|
||||||
{
|
|
||||||
int id = (int)parameter;
|
|
||||||
int status;
|
|
||||||
int value;
|
|
||||||
|
|
||||||
printf("waiter_func: Thread %d Started\n", id);
|
|
||||||
|
|
||||||
/* Take the semaphore */
|
|
||||||
|
|
||||||
status = sem_getvalue(&sem, &value);
|
|
||||||
if (status < 0)
|
|
||||||
{
|
|
||||||
printf("waiter_func: ERROR thread %d could not get semaphore value\n", id);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("waiter_func: Thread %d initial semaphore value = %d\n", id, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("waiter_func: Thread %d waiting on semaphore\n", id);
|
|
||||||
status = sem_wait(&sem);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("waiter_func: ERROR thread %d sem_wait failed\n", id);
|
|
||||||
}
|
|
||||||
printf("waiter_func: Thread %d awakened\n", id);
|
|
||||||
|
|
||||||
status = sem_getvalue(&sem, &value);
|
|
||||||
if (status < 0)
|
|
||||||
{
|
|
||||||
printf("waiter_func: ERROR thread %d could not get semaphore value\n", id);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("waiter_func: Thread %d new semaphore value = %d\n", id, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("waiter_func: Thread %d done\n", id);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void *poster_func(void *parameter)
|
|
||||||
{
|
|
||||||
int id = (int)parameter;
|
|
||||||
int status;
|
|
||||||
int value;
|
|
||||||
|
|
||||||
printf("poster_func: Thread %d started\n", id);
|
|
||||||
|
|
||||||
/* Take the semaphore */
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
status = sem_getvalue(&sem, &value);
|
|
||||||
if (status < 0)
|
|
||||||
{
|
|
||||||
printf("poster_func: ERROR thread %d could not get semaphore value\n", id);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("poster_func: Thread %d semaphore value = %d\n", id, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (value < 0)
|
|
||||||
{
|
|
||||||
printf("poster_func: Thread %d posting semaphore\n", id);
|
|
||||||
status = sem_post(&sem);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("poster_func: ERROR thread %d sem_wait failed\n", id);
|
|
||||||
}
|
|
||||||
|
|
||||||
pthread_yield();
|
|
||||||
|
|
||||||
status = sem_getvalue(&sem, &value);
|
|
||||||
if (status < 0)
|
|
||||||
{
|
|
||||||
printf("poster_func: ERROR thread %d could not get semaphore value\n", id);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("poster_func: Thread %d new semaphore value = %d\n", id, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while (value < 0);
|
|
||||||
|
|
||||||
printf("poster_func: Thread %d done\n", id);
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void sem_test(void)
|
|
||||||
{
|
|
||||||
pthread_t waiter_thread1;
|
|
||||||
pthread_t waiter_thread2;
|
|
||||||
pthread_t poster_thread;
|
|
||||||
#ifdef SDCC
|
|
||||||
pthread_addr_t result;
|
|
||||||
#endif
|
|
||||||
struct sched_param sparam;
|
|
||||||
int prio_min;
|
|
||||||
int prio_max;
|
|
||||||
int prio_mid;
|
|
||||||
pthread_attr_t attr;
|
|
||||||
int status;
|
|
||||||
|
|
||||||
printf("sem_test: Initializing semaphore to 0\n");
|
|
||||||
sem_init(&sem, 0, 0);
|
|
||||||
|
|
||||||
/* Start two waiter thread instances */
|
|
||||||
|
|
||||||
printf("sem_test: Starting waiter thread 1\n");
|
|
||||||
status = pthread_attr_init(&attr);
|
|
||||||
if (status != OK)
|
|
||||||
{
|
|
||||||
printf("sem_test: pthread_attr_init failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
prio_min = sched_get_priority_min(SCHED_FIFO);
|
|
||||||
prio_max = sched_get_priority_max(SCHED_FIFO);
|
|
||||||
prio_mid = (prio_min + prio_max) / 2;
|
|
||||||
|
|
||||||
sparam.sched_priority = (prio_mid + prio_max) / 2;
|
|
||||||
status = pthread_attr_setschedparam(&attr,&sparam);
|
|
||||||
if (status != OK)
|
|
||||||
{
|
|
||||||
printf("sem_test: pthread_attr_setschedparam failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("sem_test: Set thread 1 priority to %d\n", sparam.sched_priority);
|
|
||||||
}
|
|
||||||
|
|
||||||
status = pthread_create(&waiter_thread1, &attr, waiter_func, (pthread_addr_t)1);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("sem_test: Error in thread 1 creation, status=%d\n", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("sem_test: Starting waiter thread 2\n");
|
|
||||||
status = pthread_attr_init(&attr);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("sem_test: pthread_attr_init failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
sparam.sched_priority = prio_mid;
|
|
||||||
status = pthread_attr_setschedparam(&attr,&sparam);
|
|
||||||
if (status != OK)
|
|
||||||
{
|
|
||||||
printf("sem_test: pthread_attr_setschedparam failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("sem_test: Set thread 2 priority to %d\n", sparam.sched_priority);
|
|
||||||
}
|
|
||||||
|
|
||||||
status = pthread_create(&waiter_thread2, &attr, waiter_func, (pthread_addr_t)2);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("sem_test: Error in thread 2 creation, status=%d\n", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("sem_test: Starting poster thread 3\n");
|
|
||||||
status = pthread_attr_init(&attr);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("sem_test: pthread_attr_init failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
sparam.sched_priority = (prio_min + prio_mid) / 2;
|
|
||||||
status = pthread_attr_setschedparam(&attr,&sparam);
|
|
||||||
if (status != OK)
|
|
||||||
{
|
|
||||||
printf("sem_test: pthread_attr_setschedparam failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("sem_test: Set thread 3 priority to %d\n", sparam.sched_priority);
|
|
||||||
}
|
|
||||||
|
|
||||||
status = pthread_create(&poster_thread, &attr, poster_func, (pthread_addr_t)3);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("sem_test: Error in thread 3 creation, status=%d\n", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef SDCC
|
|
||||||
pthread_join(waiter_thread1, &result);
|
|
||||||
pthread_join(waiter_thread2, &result);
|
|
||||||
pthread_join(poster_thread, &result);
|
|
||||||
#else
|
|
||||||
pthread_join(waiter_thread1, NULL);
|
|
||||||
pthread_join(waiter_thread2, NULL);
|
|
||||||
pthread_join(poster_thread, NULL);
|
|
||||||
#endif
|
|
||||||
}
|
|
|
@ -1,330 +0,0 @@
|
||||||
/***********************************************************************
|
|
||||||
* apps/examples/ostest/sighand.c
|
|
||||||
*
|
|
||||||
* Copyright (C) 2007, 2008, 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.
|
|
||||||
*
|
|
||||||
***********************************************************************/
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <semaphore.h>
|
|
||||||
#include <signal.h>
|
|
||||||
#include <sched.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include "ostest.h"
|
|
||||||
|
|
||||||
#ifndef NULL
|
|
||||||
# define NULL (void*)0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define WAKEUP_SIGNAL 17
|
|
||||||
#define SIGVALUE_INT 42
|
|
||||||
|
|
||||||
static sem_t sem;
|
|
||||||
static bool sigreceived = false;
|
|
||||||
static bool threadexited = false;
|
|
||||||
|
|
||||||
#ifdef CONFIG_SCHED_HAVE_PARENT
|
|
||||||
static void death_of_child(int signo, siginfo_t *info, void *ucontext)
|
|
||||||
{
|
|
||||||
/* Use of printf in a signal handler is NOT safe! It can cause deadlocks!
|
|
||||||
* Also, signals are not queued by NuttX. As a consequence, some
|
|
||||||
* notifications will get lost (or the info data can be overwrittedn)!
|
|
||||||
* Because POSIX does not require signals to be queued, I do not think
|
|
||||||
* that this is a bug (the overwriting is a bug, however).
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (info)
|
|
||||||
{
|
|
||||||
printf("death_of_child: PID %d received signal=%d code=%d pid=%d status=%d\n",
|
|
||||||
getpid(), signo, info->si_code, info->si_pid, info->si_status);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("death_of_child: PID %d received signal=%d (no info?)\n",
|
|
||||||
getpid(), signo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static void wakeup_action(int signo, siginfo_t *info, void *ucontext)
|
|
||||||
{
|
|
||||||
sigset_t oldset;
|
|
||||||
sigset_t allsigs;
|
|
||||||
int status;
|
|
||||||
|
|
||||||
/* Use of printf in a signal handler is NOT safe! It can cause deadlocks! */
|
|
||||||
|
|
||||||
printf("wakeup_action: Received signal %d\n" , signo);
|
|
||||||
|
|
||||||
sigreceived = true;
|
|
||||||
|
|
||||||
/* Check signo */
|
|
||||||
|
|
||||||
if (signo != WAKEUP_SIGNAL)
|
|
||||||
{
|
|
||||||
printf("wakeup_action: ERROR expected signo=%d\n" , WAKEUP_SIGNAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check siginfo */
|
|
||||||
|
|
||||||
if (info->si_value.sival_int != SIGVALUE_INT)
|
|
||||||
{
|
|
||||||
printf("wakeup_action: ERROR sival_int=%d expected %d\n",
|
|
||||||
info->si_value.sival_int, SIGVALUE_INT);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("wakeup_action: sival_int=%d\n" , info->si_value.sival_int);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (info->si_signo != WAKEUP_SIGNAL)
|
|
||||||
{
|
|
||||||
printf("wakeup_action: ERROR expected si_signo=%d, got=%d\n",
|
|
||||||
WAKEUP_SIGNAL, info->si_signo);
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("wakeup_action: si_code=%d\n" , info->si_code);
|
|
||||||
|
|
||||||
/* Check ucontext_t */
|
|
||||||
|
|
||||||
printf("wakeup_action: ucontext=%p\n" , ucontext);
|
|
||||||
|
|
||||||
/* Check sigprocmask */
|
|
||||||
|
|
||||||
(void)sigfillset(&allsigs);
|
|
||||||
status = sigprocmask(SIG_SETMASK, NULL, &oldset);
|
|
||||||
if (status != OK)
|
|
||||||
{
|
|
||||||
printf("wakeup_action: ERROR sigprocmask failed, status=%d\n",
|
|
||||||
status);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (oldset != allsigs)
|
|
||||||
{
|
|
||||||
printf("wakeup_action: ERROR sigprocmask=%x expected=%x\n",
|
|
||||||
oldset, allsigs);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int waiter_main(int argc, char *argv[])
|
|
||||||
{
|
|
||||||
sigset_t sigset;
|
|
||||||
struct sigaction act;
|
|
||||||
struct sigaction oact;
|
|
||||||
int status;
|
|
||||||
|
|
||||||
printf("waiter_main: Waiter started\n" );
|
|
||||||
|
|
||||||
printf("waiter_main: Unmasking signal %d\n" , WAKEUP_SIGNAL);
|
|
||||||
(void)sigemptyset(&sigset);
|
|
||||||
(void)sigaddset(&sigset, WAKEUP_SIGNAL);
|
|
||||||
status = sigprocmask(SIG_UNBLOCK, &sigset, NULL);
|
|
||||||
if (status != OK)
|
|
||||||
{
|
|
||||||
printf("waiter_main: ERROR sigprocmask failed, status=%d\n",
|
|
||||||
status);
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("waiter_main: Registering signal handler\n" );
|
|
||||||
act.sa_sigaction = wakeup_action;
|
|
||||||
act.sa_flags = SA_SIGINFO;
|
|
||||||
|
|
||||||
(void)sigfillset(&act.sa_mask);
|
|
||||||
(void)sigdelset(&act.sa_mask, WAKEUP_SIGNAL);
|
|
||||||
|
|
||||||
status = sigaction(WAKEUP_SIGNAL, &act, &oact);
|
|
||||||
if (status != OK)
|
|
||||||
{
|
|
||||||
printf("waiter_main: ERROR sigaction failed, status=%d\n" , status);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef SDCC
|
|
||||||
printf("waiter_main: oact.sigaction=%p oact.sa_flags=%x oact.sa_mask=%x\n",
|
|
||||||
oact.sa_sigaction, oact.sa_flags, oact.sa_mask);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Take the semaphore */
|
|
||||||
|
|
||||||
printf("waiter_main: Waiting on semaphore\n" );
|
|
||||||
FFLUSH();
|
|
||||||
|
|
||||||
status = sem_wait(&sem);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
int error = errno;
|
|
||||||
if (error == EINTR)
|
|
||||||
{
|
|
||||||
printf("waiter_main: sem_wait() successfully interrupted by signal\n" );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("waiter_main: ERROR sem_wait failed, errno=%d\n" , error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("waiter_main: ERROR awakened with no error!\n" );
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Detach the signal handler */
|
|
||||||
|
|
||||||
act.sa_sigaction = SIG_DFL;
|
|
||||||
status = sigaction(WAKEUP_SIGNAL, &act, &oact);
|
|
||||||
|
|
||||||
printf("waiter_main: done\n" );
|
|
||||||
FFLUSH();
|
|
||||||
|
|
||||||
threadexited = true;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void sighand_test(void)
|
|
||||||
{
|
|
||||||
#ifdef CONFIG_SCHED_HAVE_PARENT
|
|
||||||
struct sigaction act;
|
|
||||||
struct sigaction oact;
|
|
||||||
sigset_t sigset;
|
|
||||||
#endif
|
|
||||||
struct sched_param param;
|
|
||||||
union sigval sigvalue;
|
|
||||||
pid_t waiterpid;
|
|
||||||
int policy;
|
|
||||||
int status;
|
|
||||||
|
|
||||||
printf("sighand_test: Initializing semaphore to 0\n" );
|
|
||||||
sem_init(&sem, 0, 0);
|
|
||||||
|
|
||||||
#ifdef CONFIG_SCHED_HAVE_PARENT
|
|
||||||
printf("sighand_test: Unmasking SIGCHLD\n");
|
|
||||||
|
|
||||||
(void)sigemptyset(&sigset);
|
|
||||||
(void)sigaddset(&sigset, SIGCHLD);
|
|
||||||
status = sigprocmask(SIG_UNBLOCK, &sigset, NULL);
|
|
||||||
if (status != OK)
|
|
||||||
{
|
|
||||||
printf("sighand_test: ERROR sigprocmask failed, status=%d\n",
|
|
||||||
status);
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("sighand_test: Registering SIGCHLD handler\n" );
|
|
||||||
act.sa_sigaction = death_of_child;
|
|
||||||
act.sa_flags = SA_SIGINFO;
|
|
||||||
|
|
||||||
(void)sigfillset(&act.sa_mask);
|
|
||||||
(void)sigdelset(&act.sa_mask, SIGCHLD);
|
|
||||||
|
|
||||||
status = sigaction(SIGCHLD, &act, &oact);
|
|
||||||
if (status != OK)
|
|
||||||
{
|
|
||||||
printf("waiter_main: ERROR sigaction failed, status=%d\n" , status);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Start waiter thread */
|
|
||||||
|
|
||||||
printf("sighand_test: Starting waiter task\n" );
|
|
||||||
status = sched_getparam (0, ¶m);
|
|
||||||
if (status != OK)
|
|
||||||
{
|
|
||||||
printf("sighand_test: ERROR sched_getparam() failed\n" );
|
|
||||||
param.sched_priority = PTHREAD_DEFAULT_PRIORITY;
|
|
||||||
}
|
|
||||||
|
|
||||||
policy = sched_getscheduler(0);
|
|
||||||
if (policy == ERROR)
|
|
||||||
{
|
|
||||||
printf("sighand_test: ERROR sched_getscheduler() failed\n" );
|
|
||||||
policy = SCHED_FIFO;
|
|
||||||
}
|
|
||||||
|
|
||||||
waiterpid = task_create("waiter", param.sched_priority,
|
|
||||||
PTHREAD_STACK_DEFAULT, waiter_main, NULL);
|
|
||||||
if (waiterpid == ERROR)
|
|
||||||
{
|
|
||||||
printf("sighand_test: ERROR failed to start waiter_main\n" );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("sighand_test: Started waiter_main pid=%d\n", waiterpid);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Wait a bit */
|
|
||||||
|
|
||||||
FFLUSH();
|
|
||||||
sleep(2);
|
|
||||||
|
|
||||||
/* Then signal the waiter thread. */
|
|
||||||
|
|
||||||
printf("sighand_test: Signaling pid=%d with signo=%d sigvalue=%d\n",
|
|
||||||
waiterpid, WAKEUP_SIGNAL, SIGVALUE_INT);
|
|
||||||
|
|
||||||
sigvalue.sival_int = SIGVALUE_INT;
|
|
||||||
#ifdef CONFIG_CAN_PASS_STRUCTS
|
|
||||||
status = sigqueue(waiterpid, WAKEUP_SIGNAL, sigvalue);
|
|
||||||
#else
|
|
||||||
status = sigqueue(waiterpid, WAKEUP_SIGNAL, sigvalue.sival_ptr);
|
|
||||||
#endif
|
|
||||||
if (status != OK)
|
|
||||||
{
|
|
||||||
printf("sighand_test: ERROR sigqueue failed\n" );
|
|
||||||
task_delete(waiterpid);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Wait a bit */
|
|
||||||
|
|
||||||
FFLUSH();
|
|
||||||
sleep(2);
|
|
||||||
|
|
||||||
/* Then check the result */
|
|
||||||
|
|
||||||
if (!threadexited)
|
|
||||||
{
|
|
||||||
printf("sighand_test: ERROR waiter task did not exit\n" );
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!sigreceived)
|
|
||||||
{
|
|
||||||
printf("sighand_test: ERROR signal handler did not run\n" );
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Detach the signal handler */
|
|
||||||
|
|
||||||
#ifdef CONFIG_SCHED_HAVE_PARENT
|
|
||||||
act.sa_sigaction = SIG_DFL;
|
|
||||||
status = sigaction(SIGCHLD, &act, &oact);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
printf("sighand_test: done\n" );
|
|
||||||
FFLUSH();
|
|
||||||
}
|
|
|
@ -1,387 +0,0 @@
|
||||||
/**************************************************************************
|
|
||||||
* apps/examples/ostest/mqueue.c
|
|
||||||
*
|
|
||||||
* Copyright (C) 2007-2009, 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 <stdio.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <ctype.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <pthread.h>
|
|
||||||
#include <mqueue.h>
|
|
||||||
#include <sched.h>
|
|
||||||
#include <errno.h>
|
|
||||||
|
|
||||||
#include "ostest.h"
|
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
* Private Definitions
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
#define TEST_MESSAGE "This is a test and only a test"
|
|
||||||
#if defined(SDCC) || defined(__ZILOG__)
|
|
||||||
/* Cannot use strlen in array size */
|
|
||||||
|
|
||||||
# define TEST_MSGLEN (31)
|
|
||||||
#else
|
|
||||||
/* Message lenght is the size of the message plus the null terminator */
|
|
||||||
|
|
||||||
# define TEST_MSGLEN (strlen(TEST_MESSAGE)+1)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define TEST_SEND_NMSGS (10)
|
|
||||||
#define TEST_RECEIVE_NMSGS (10)
|
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
* Private Types
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
* Private Function Prototypes
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
* Global Variables
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
* Private Variables
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
* Private Functions
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
* Public Functions
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
static void *sender_thread(void *arg)
|
|
||||||
{
|
|
||||||
mqd_t mqfd;
|
|
||||||
char msg_buffer[TEST_MSGLEN];
|
|
||||||
struct mq_attr attr;
|
|
||||||
int status = 0;
|
|
||||||
int nerrors = 0;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
printf("sender_thread: Starting\n");
|
|
||||||
|
|
||||||
/* Fill in attributes for message queue */
|
|
||||||
|
|
||||||
attr.mq_maxmsg = TEST_SEND_NMSGS-1;
|
|
||||||
attr.mq_msgsize = TEST_MSGLEN;
|
|
||||||
attr.mq_flags = 0;
|
|
||||||
|
|
||||||
/* Set the flags for the open of the queue.
|
|
||||||
* Make it a blocking open on the queue, meaning it will block if
|
|
||||||
* this process tries to send to the queue and the queue is full.
|
|
||||||
*
|
|
||||||
* O_CREAT - the queue will get created if it does not already exist.
|
|
||||||
* O_WRONLY - we are only planning to write to the queue.
|
|
||||||
*
|
|
||||||
* Open the queue, and create it if the receiving process hasn't
|
|
||||||
* already created it.
|
|
||||||
*/
|
|
||||||
|
|
||||||
mqfd = mq_open("testmq", O_WRONLY|O_CREAT, 0666, &attr);
|
|
||||||
if (mqfd < 0)
|
|
||||||
{
|
|
||||||
printf("sender_thread: ERROR mq_open failed\n");
|
|
||||||
pthread_exit((pthread_addr_t)1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Fill in a test message buffer to send */
|
|
||||||
|
|
||||||
memcpy(msg_buffer, TEST_MESSAGE, TEST_MSGLEN);
|
|
||||||
|
|
||||||
/* Perform the send TEST_SEND_NMSGS times */
|
|
||||||
|
|
||||||
for (i = 0; i < TEST_SEND_NMSGS; i++)
|
|
||||||
{
|
|
||||||
struct timespec ts;
|
|
||||||
status = clock_gettime(CLOCK_REALTIME, &ts);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("sender_thread: ERROR clock_gettime failed\n");
|
|
||||||
}
|
|
||||||
ts.tv_sec += 5;
|
|
||||||
|
|
||||||
/* The first TEST_SEND_NMSGS-1 send should succeed. The last
|
|
||||||
* one should fail with errno == ETIMEDOUT
|
|
||||||
*/
|
|
||||||
|
|
||||||
status = mq_timedsend(mqfd, msg_buffer, TEST_MSGLEN, 42, &ts);
|
|
||||||
if (status < 0)
|
|
||||||
{
|
|
||||||
if (i == TEST_SEND_NMSGS-1 && errno == ETIMEDOUT)
|
|
||||||
{
|
|
||||||
printf("sender_thread: mq_timedsend %d timed out as expected\n", i);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("sender_thread: ERROR mq_timedsend failure=%d on msg %d\n", errno, i);
|
|
||||||
nerrors++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (i == TEST_SEND_NMSGS-1)
|
|
||||||
{
|
|
||||||
printf("sender_thread: ERROR mq_timedsend of msg %d succeeded\n", i);
|
|
||||||
nerrors++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("sender_thread: mq_timedsend succeeded on msg %d\n", i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Close the queue and return success */
|
|
||||||
|
|
||||||
if (mq_close(mqfd) < 0)
|
|
||||||
{
|
|
||||||
printf("sender_thread: ERROR mq_close failed\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("sender_thread: returning nerrors=%d\n", nerrors);
|
|
||||||
FFLUSH();
|
|
||||||
return (pthread_addr_t)nerrors;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void *receiver_thread(void *arg)
|
|
||||||
{
|
|
||||||
mqd_t mqfd;
|
|
||||||
char msg_buffer[TEST_MSGLEN];
|
|
||||||
struct mq_attr attr;
|
|
||||||
int nbytes;
|
|
||||||
int nerrors = 0;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
printf("receiver_thread: Starting\n");
|
|
||||||
|
|
||||||
/* Fill in attributes for message queue */
|
|
||||||
|
|
||||||
attr.mq_maxmsg = TEST_SEND_NMSGS-1;
|
|
||||||
attr.mq_msgsize = TEST_MSGLEN;
|
|
||||||
attr.mq_flags = 0;
|
|
||||||
|
|
||||||
/* Set the flags for the open of the queue.
|
|
||||||
* Make it a blocking open on the queue, meaning it will block if
|
|
||||||
* this process tries to* send to the queue and the queue is full.
|
|
||||||
*
|
|
||||||
* O_CREAT - the queue will get created if it does not already exist.
|
|
||||||
* O_RDONLY - we are only planning to write to the queue.
|
|
||||||
*
|
|
||||||
* Open the queue, and create it if the sending process hasn't
|
|
||||||
* already created it.
|
|
||||||
*/
|
|
||||||
|
|
||||||
mqfd = mq_open("testmq", O_RDONLY|O_CREAT, 0666, &attr);
|
|
||||||
if (mqfd < 0)
|
|
||||||
{
|
|
||||||
printf("receiver_thread: ERROR mq_open failed\n");
|
|
||||||
pthread_exit((pthread_addr_t)1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Perform the receive TEST_RECEIVE_NMSGS times */
|
|
||||||
|
|
||||||
for (i = 0; i < TEST_RECEIVE_NMSGS; i++)
|
|
||||||
{
|
|
||||||
struct timespec ts;
|
|
||||||
int status = clock_gettime(CLOCK_REALTIME, &ts);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("sender_thread: ERROR clock_gettime failed\n");
|
|
||||||
}
|
|
||||||
ts.tv_sec += 5;
|
|
||||||
|
|
||||||
/* The first TEST_SEND_NMSGS-1 send should succeed. The last
|
|
||||||
* one should fail with errno == ETIMEDOUT
|
|
||||||
*/
|
|
||||||
|
|
||||||
memset(msg_buffer, 0xaa, TEST_MSGLEN);
|
|
||||||
nbytes = mq_timedreceive(mqfd, msg_buffer, TEST_MSGLEN, 0, &ts);
|
|
||||||
if (nbytes < 0)
|
|
||||||
{
|
|
||||||
if (i == TEST_SEND_NMSGS-1 && errno == ETIMEDOUT)
|
|
||||||
{
|
|
||||||
printf("receiver_thread: Receive %d timed out as expected\n", i);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("receiver_thread: ERROR mq_timedreceive failure=%d on msg %d\n", errno, i);
|
|
||||||
nerrors++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (nbytes != TEST_MSGLEN)
|
|
||||||
{
|
|
||||||
printf("receiver_thread: mq_timedreceive return bad size %d on msg %d\n", nbytes, i);
|
|
||||||
nerrors++;
|
|
||||||
}
|
|
||||||
else if (memcmp(TEST_MESSAGE, msg_buffer, nbytes) != 0)
|
|
||||||
{
|
|
||||||
int j;
|
|
||||||
|
|
||||||
printf("receiver_thread: mq_timedreceive returned corrupt message on msg %d\n", i);
|
|
||||||
printf("receiver_thread: i Expected Received\n");
|
|
||||||
|
|
||||||
for (j = 0; j < TEST_MSGLEN-1; j++)
|
|
||||||
{
|
|
||||||
if (isprint(msg_buffer[j]))
|
|
||||||
{
|
|
||||||
printf("receiver_thread: %2d %02x (%c) %02x (%c)\n",
|
|
||||||
j, TEST_MESSAGE[j], TEST_MESSAGE[j], msg_buffer[j], msg_buffer[j]);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("receiver_thread: %2d %02x (%c) %02x\n",
|
|
||||||
j, TEST_MESSAGE[j], TEST_MESSAGE[j], msg_buffer[j]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
printf("receiver_thread: %2d 00 %02x\n",
|
|
||||||
j, msg_buffer[j]);
|
|
||||||
}
|
|
||||||
else if (i == TEST_SEND_NMSGS-1)
|
|
||||||
{
|
|
||||||
printf("receiver_thread: ERROR mq_timedreceive of msg %d succeeded\n", i);
|
|
||||||
nerrors++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("receiver_thread: mq_timedreceive succeeded on msg %d\n", i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Close the queue and return success */
|
|
||||||
|
|
||||||
if (mq_close(mqfd) < 0)
|
|
||||||
{
|
|
||||||
printf("receiver_thread: ERROR mq_close failed\n");
|
|
||||||
nerrors++;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Destroy the queue */
|
|
||||||
|
|
||||||
if (mq_unlink("testmq") < 0)
|
|
||||||
{
|
|
||||||
printf("receiver_thread: ERROR mq_close failed\n");
|
|
||||||
nerrors++;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("receiver_thread: returning nerrors=%d\n", nerrors);
|
|
||||||
FFLUSH();
|
|
||||||
pthread_exit((pthread_addr_t)nerrors);
|
|
||||||
return (pthread_addr_t)nerrors;
|
|
||||||
}
|
|
||||||
|
|
||||||
void timedmqueue_test(void)
|
|
||||||
{
|
|
||||||
pthread_t sender;
|
|
||||||
pthread_t receiver;
|
|
||||||
void *result;
|
|
||||||
pthread_attr_t attr;
|
|
||||||
int status;
|
|
||||||
|
|
||||||
/* Start the sending thread at the default priority */
|
|
||||||
|
|
||||||
printf("timedmqueue_test: Starting sender\n");
|
|
||||||
status = pthread_attr_init(&attr);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("timedmqueue_test: pthread_attr_init failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
status = pthread_attr_setstacksize(&attr, STACKSIZE);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("timedmqueue_test: pthread_attr_setstacksize failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
status = pthread_create(&sender, &attr, sender_thread, NULL);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("timedmqueue_test: pthread_create failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Wait for the sending thread to complete */
|
|
||||||
|
|
||||||
printf("timedmqueue_test: Waiting for sender to complete\n");
|
|
||||||
pthread_join(sender, &result);
|
|
||||||
if (result != (void*)0)
|
|
||||||
{
|
|
||||||
printf("timedmqueue_test: ERROR sender thread exited with %d errors\n", (int)result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Start the receiving thread at the default priority */
|
|
||||||
|
|
||||||
printf("timedmqueue_test: Starting receiver\n");
|
|
||||||
status = pthread_attr_init(&attr);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("timedmqueue_test: pthread_attr_init failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
status = pthread_attr_setstacksize(&attr, STACKSIZE);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("timedmqueue_test: pthread_attr_setstacksize failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
status = pthread_create(&receiver, &attr, receiver_thread, NULL);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("timedmqueue_test: pthread_create failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Wait for the receiving thread to complete */
|
|
||||||
|
|
||||||
printf("timedmqueue_test: Waiting for receiver to complete\n");
|
|
||||||
pthread_join(receiver, &result);
|
|
||||||
if (result != (void*)0)
|
|
||||||
{
|
|
||||||
printf("timedmqueue_test: ERROR receiver thread exited with %d errors\n", (int)result);
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("timedmqueue_test: Test complete\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -1,195 +0,0 @@
|
||||||
/***********************************************************************
|
|
||||||
* examples/ostest/timedwait.c
|
|
||||||
*
|
|
||||||
* Copyright (C) 2007, 2008, 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 <stdio.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include <pthread.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <errno.h>
|
|
||||||
|
|
||||||
#include "ostest.h"
|
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
* Private Definitions
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
* Private Data
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
static pthread_mutex_t mutex;
|
|
||||||
static pthread_cond_t cond;
|
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
* Private Functions
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
static void *thread_waiter(void *parameter)
|
|
||||||
{
|
|
||||||
struct timespec ts;
|
|
||||||
int status;
|
|
||||||
|
|
||||||
/* Take the mutex */
|
|
||||||
|
|
||||||
printf("thread_waiter: Taking mutex\n");
|
|
||||||
status = pthread_mutex_lock(&mutex);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("thread_waiter: ERROR pthread_mutex_lock failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("thread_waiter: Starting 5 second wait for condition\n");
|
|
||||||
|
|
||||||
status = clock_gettime(CLOCK_REALTIME, &ts);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("thread_waiter: ERROR clock_gettime failed\n");
|
|
||||||
}
|
|
||||||
ts.tv_sec += 5;
|
|
||||||
|
|
||||||
/* The wait -- no-one is ever going to awaken us */
|
|
||||||
|
|
||||||
status = pthread_cond_timedwait(&cond, &mutex, &ts);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
if (status == ETIMEDOUT)
|
|
||||||
{
|
|
||||||
printf("thread_waiter: pthread_cond_timedwait timed out\n");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("thread_waiter: ERROR pthread_cond_timedwait failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("thread_waiter: ERROR pthread_cond_timedwait returned without timeout, status=%d\n", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Release the mutex */
|
|
||||||
|
|
||||||
printf("thread_waiter: Releasing mutex\n");
|
|
||||||
status = pthread_mutex_unlock(&mutex);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("thread_waiter: ERROR pthread_mutex_unlock failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("thread_waiter: Exit with status 0x12345678\n");
|
|
||||||
pthread_exit((pthread_addr_t)0x12345678);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
* Public Definitions
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
void timedwait_test(void)
|
|
||||||
{
|
|
||||||
pthread_t waiter;
|
|
||||||
pthread_attr_t attr;
|
|
||||||
struct sched_param sparam;
|
|
||||||
void *result;
|
|
||||||
int prio_max;
|
|
||||||
int status;
|
|
||||||
|
|
||||||
/* Initialize the mutex */
|
|
||||||
|
|
||||||
printf("thread_waiter: Initializing mutex\n");
|
|
||||||
status = pthread_mutex_init(&mutex, NULL);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("timedwait_test: ERROR pthread_mutex_init failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Initialize the condition variable */
|
|
||||||
|
|
||||||
printf("timedwait_test: Initializing cond\n");
|
|
||||||
status = pthread_cond_init(&cond, NULL);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("timedwait_test: ERROR pthread_condinit failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Start the waiter thread at higher priority */
|
|
||||||
|
|
||||||
printf("timedwait_test: Starting waiter\n");
|
|
||||||
status = pthread_attr_init(&attr);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("timedwait_test: pthread_attr_init failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
prio_max = sched_get_priority_max(SCHED_FIFO);
|
|
||||||
status = sched_getparam (getpid(), &sparam);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("timedwait_test: sched_getparam failed\n");
|
|
||||||
sparam.sched_priority = PTHREAD_DEFAULT_PRIORITY;
|
|
||||||
}
|
|
||||||
|
|
||||||
sparam.sched_priority = (prio_max + sparam.sched_priority) / 2;
|
|
||||||
status = pthread_attr_setschedparam(&attr,&sparam);
|
|
||||||
if (status != OK)
|
|
||||||
{
|
|
||||||
printf("timedwait_test: pthread_attr_setschedparam failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("timedwait_test: Set thread 2 priority to %d\n", sparam.sched_priority);
|
|
||||||
}
|
|
||||||
|
|
||||||
status = pthread_create(&waiter, &attr, thread_waiter, NULL);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("timedwait_test: pthread_create failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("timedwait_test: Joining\n");
|
|
||||||
FFLUSH();
|
|
||||||
status = pthread_join(waiter, &result);
|
|
||||||
if (status != 0)
|
|
||||||
{
|
|
||||||
printf("timedwait_test: ERROR pthread_join failed, status=%d\n", status);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("timedwait_test: waiter exited with result=%p\n", result);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,103 +0,0 @@
|
||||||
/****************************************************************************
|
|
||||||
* examples/ostest/vfork.c
|
|
||||||
*
|
|
||||||
* Copyright (C) 2013 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 <stdbool.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <errno.h>
|
|
||||||
|
|
||||||
#include "ostest.h"
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Pre-processor Definitions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Data
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#if defined(CONFIG_ARCH_HAVE_VFORK) && !defined(CONFIG_DISABLE_SIGNALS)
|
|
||||||
static volatile bool g_vforkchild;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Functions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
int vfork_test(void)
|
|
||||||
{
|
|
||||||
#if defined(CONFIG_ARCH_HAVE_VFORK) && !defined(CONFIG_DISABLE_SIGNALS)
|
|
||||||
pid_t pid;
|
|
||||||
|
|
||||||
g_vforkchild = false;
|
|
||||||
pid = vfork();
|
|
||||||
if (pid == 0)
|
|
||||||
{
|
|
||||||
/* There is not very much that the child is permitted to do. Perhaps
|
|
||||||
* it can just set g_vforkchild.
|
|
||||||
*/
|
|
||||||
|
|
||||||
g_vforkchild = true;
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
else if (pid < 0)
|
|
||||||
{
|
|
||||||
printf("vfork_test: vfork() failed: %d\n", errno);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sleep(1);
|
|
||||||
if (g_vforkchild)
|
|
||||||
{
|
|
||||||
printf("vfork_test: Child %d ran successfully\n", pid);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("vfork_test: ERROR Child %d did not run\n", pid);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
|
@ -1,269 +0,0 @@
|
||||||
/****************************************************************************
|
|
||||||
* examples/ostest/waitpid.c
|
|
||||||
*
|
|
||||||
* Copyright (C) 2013 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/wait.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <signal.h>
|
|
||||||
#include <errno.h>
|
|
||||||
|
|
||||||
#include "ostest.h"
|
|
||||||
|
|
||||||
#ifdef CONFIG_SCHED_WAITPID
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Pre-processor Definitions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#define RETURN_STATUS 14
|
|
||||||
#define NCHILDREN 3
|
|
||||||
#define PRIORITY 100
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Data
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static int g_waitpids[NCHILDREN];
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Priviate Functions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static int waitpid_main(int argc, char *argv[])
|
|
||||||
{
|
|
||||||
pid_t me = getpid();
|
|
||||||
|
|
||||||
printf("waitpid_main: PID %d Started\n", me);
|
|
||||||
sleep(3);
|
|
||||||
printf("waitpid_main: PID %d exitting with result=%d\n", me, RETURN_STATUS);
|
|
||||||
return RETURN_STATUS;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void waitpid_start_children(void)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i < NCHILDREN; i++)
|
|
||||||
{
|
|
||||||
ret = TASK_CREATE("waitpid", PRIORITY, STACKSIZE, waitpid_main, NULL);
|
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
printf("waitpid_start_child: ERROR Failed to start user_main\n");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("waitpid_start_child: Started waitpid_main at PID=%d\n", ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
g_waitpids[i] = ret;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void waitpid_last(void)
|
|
||||||
{
|
|
||||||
int stat_loc;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
printf("waitpid_last: Waiting for PID=%d with waitpid()\n",
|
|
||||||
g_waitpids[NCHILDREN-1]);
|
|
||||||
|
|
||||||
ret = (int)waitpid(g_waitpids[NCHILDREN-1], &stat_loc, 0);
|
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
int errcode = errno;
|
|
||||||
printf("waitpid_last: ERROR: PID %d waitpid failed: %d\n",
|
|
||||||
g_waitpids[NCHILDREN-1], errcode);
|
|
||||||
}
|
|
||||||
else if (WEXITSTATUS(stat_loc) != RETURN_STATUS)
|
|
||||||
{
|
|
||||||
printf("waitpid_last: ERROR: PID %d return status is %d, expected %d\n",
|
|
||||||
g_waitpids[NCHILDREN-1], WEXITSTATUS(stat_loc), RETURN_STATUS);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("waitpid_last: PID %d waitpid succeeded with stat_loc=%04x\n",
|
|
||||||
g_waitpids[NCHILDREN-1], stat_loc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Functions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
int waitpid_test(void)
|
|
||||||
{
|
|
||||||
#ifdef CONFIG_SCHED_HAVE_PARENT
|
|
||||||
siginfo_t info;
|
|
||||||
#endif
|
|
||||||
int stat_loc;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
/* Start the children and wait for first one to complete */
|
|
||||||
|
|
||||||
printf("\nTest waitpid()\n");
|
|
||||||
waitpid_start_children();
|
|
||||||
|
|
||||||
printf("waitpid_test: Waiting for PID=%d with waitpid()\n", g_waitpids[0]);
|
|
||||||
ret = (int)waitpid(g_waitpids[0], &stat_loc, 0);
|
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
int errcode = errno;
|
|
||||||
printf("waitpid_test: ERROR: PID %d waitpid failed: %d\n",
|
|
||||||
g_waitpids[0], errcode);
|
|
||||||
}
|
|
||||||
else if (ret != g_waitpids[0])
|
|
||||||
{
|
|
||||||
printf("waitpid_test: ERROR: PID %d wait returned PID %d\n",
|
|
||||||
g_waitpids[0], ret);
|
|
||||||
}
|
|
||||||
else if (WEXITSTATUS(stat_loc) != RETURN_STATUS)
|
|
||||||
{
|
|
||||||
printf("waitpid_test: ERROR: PID %d return status is %d, expected %d\n",
|
|
||||||
g_waitpids[0], WEXITSTATUS(stat_loc), RETURN_STATUS);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("waitpid_test: PID %d waitpid succeeded with stat_loc=%04x\n",
|
|
||||||
g_waitpids[0], stat_loc);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Wait a big to make sure that the other threads complete */
|
|
||||||
|
|
||||||
waitpid_last();
|
|
||||||
sleep(1);
|
|
||||||
|
|
||||||
#ifdef CONFIG_SCHED_HAVE_PARENT
|
|
||||||
/* Start the children and wait for first one to complete */
|
|
||||||
|
|
||||||
printf("\nTest waitid(P_PID)\n");
|
|
||||||
waitpid_start_children();
|
|
||||||
|
|
||||||
printf("waitpid_test: Waiting for PID=%d with waitid()\n", g_waitpids[0]);
|
|
||||||
ret = waitid(P_PID, (id_t)g_waitpids[0], &info, WEXITED);
|
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
int errcode = errno;
|
|
||||||
printf("waitpid_test: ERROR: PID %d waitid failed: %d\n",
|
|
||||||
g_waitpids[0], errcode);
|
|
||||||
}
|
|
||||||
else if (info.si_pid != g_waitpids[0])
|
|
||||||
{
|
|
||||||
printf("waitpid_test: ERROR: PID %d waitid returned PID %d\n",
|
|
||||||
g_waitpids[0], info.si_pid);
|
|
||||||
}
|
|
||||||
else if (info.si_status != RETURN_STATUS)
|
|
||||||
{
|
|
||||||
printf("waitpid_test: ERROR: PID %d return status is %d, expected %d\n",
|
|
||||||
info.si_pid, info.si_status, RETURN_STATUS);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("waitpid_test: waitid PID %d succeeded with si_status=%d\n",
|
|
||||||
info.si_pid, info.si_status);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Wait a big to make sure that the other threads complete */
|
|
||||||
|
|
||||||
waitpid_last();
|
|
||||||
sleep(1);
|
|
||||||
|
|
||||||
/* Start the children and wait for any one to complete */
|
|
||||||
|
|
||||||
printf("\nTest waitid(P_ALL)\n");
|
|
||||||
waitpid_start_children();
|
|
||||||
|
|
||||||
printf("waitpid_test: Waiting for any child with waitid()\n");
|
|
||||||
ret = waitid(P_ALL, 0, &info, WEXITED);
|
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
int errcode = errno;
|
|
||||||
printf("waitpid_test: ERROR: waitid failed: %d\n", errcode);
|
|
||||||
}
|
|
||||||
else if (info.si_status != RETURN_STATUS)
|
|
||||||
{
|
|
||||||
printf("waitpid_test: ERROR: PID %d return status is %d, expected %d\n",
|
|
||||||
info.si_pid, info.si_status, RETURN_STATUS);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("waitpid_test: PID %d waitid succeeded with si_status=%d\n",
|
|
||||||
info.si_pid, info.si_status);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Wait a big to make sure that the other threads complete */
|
|
||||||
|
|
||||||
waitpid_last();
|
|
||||||
sleep(1);
|
|
||||||
|
|
||||||
/* Start the children and wait for first one to complete */
|
|
||||||
|
|
||||||
printf("\nTest wait()\n");
|
|
||||||
waitpid_start_children();
|
|
||||||
|
|
||||||
printf("waitpid_test: Waiting for any child with wait()\n");
|
|
||||||
ret = (int)wait(&stat_loc);
|
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
int errcode = errno;
|
|
||||||
printf("waitpid_test: ERROR: wait failed: %d\n", errcode);
|
|
||||||
}
|
|
||||||
else if (WEXITSTATUS(stat_loc) != RETURN_STATUS)
|
|
||||||
{
|
|
||||||
printf("waitpid_test: ERROR: PID %d return status is %d, expected %d\n",
|
|
||||||
ret, WEXITSTATUS(stat_loc), RETURN_STATUS);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("waitpid_test: PID %d wait succeeded with stat_loc=%04x\n",
|
|
||||||
ret, stat_loc);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Wait a big to make sure that the other threads complete */
|
|
||||||
|
|
||||||
waitpid_last();
|
|
||||||
sleep(1);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* CONFIG_SCHED_WAITPID */
|
|
|
@ -1,13 +0,0 @@
|
||||||
#
|
|
||||||
# For a description of the syntax of this configuration file,
|
|
||||||
# see misc/tools/kconfig-language.txt.
|
|
||||||
#
|
|
||||||
|
|
||||||
config EXAMPLES_PIPE
|
|
||||||
bool "Pipe example"
|
|
||||||
default n
|
|
||||||
---help---
|
|
||||||
Enable the pipe example
|
|
||||||
|
|
||||||
if EXAMPLES_PIPE
|
|
||||||
endif
|
|
|
@ -1,96 +0,0 @@
|
||||||
############################################################################
|
|
||||||
# apps/examples/pipe/Makefile
|
|
||||||
#
|
|
||||||
# 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
|
|
||||||
# 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)/.config
|
|
||||||
-include $(TOPDIR)/Make.defs
|
|
||||||
include $(APPDIR)/Make.defs
|
|
||||||
|
|
||||||
# Pipe Example
|
|
||||||
|
|
||||||
ASRCS =
|
|
||||||
CSRCS = pipe_main.c transfer_test.c interlock_test.c redirect_test.c
|
|
||||||
|
|
||||||
AOBJS = $(ASRCS:.S=$(OBJEXT))
|
|
||||||
COBJS = $(CSRCS:.c=$(OBJEXT))
|
|
||||||
|
|
||||||
SRCS = $(ASRCS) $(CSRCS)
|
|
||||||
OBJS = $(AOBJS) $(COBJS)
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
|
|
||||||
BIN = ..\..\libapps$(LIBEXT)
|
|
||||||
else
|
|
||||||
ifeq ($(WINTOOL),y)
|
|
||||||
BIN = ..\\..\\libapps$(LIBEXT)
|
|
||||||
else
|
|
||||||
BIN = ../../libapps$(LIBEXT)
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
ROOTDEPPATH = --dep-path .
|
|
||||||
|
|
||||||
# Common build
|
|
||||||
|
|
||||||
VPATH =
|
|
||||||
|
|
||||||
all: .built
|
|
||||||
.PHONY: clean depend distclean
|
|
||||||
|
|
||||||
$(AOBJS): %$(OBJEXT): %.S
|
|
||||||
$(call ASSEMBLE, $<, $@)
|
|
||||||
|
|
||||||
$(COBJS): %$(OBJEXT): %.c
|
|
||||||
$(call COMPILE, $<, $@)
|
|
||||||
|
|
||||||
.built: $(OBJS)
|
|
||||||
$(call ARCHIVE, $(BIN), $(OBJS))
|
|
||||||
@touch .built
|
|
||||||
|
|
||||||
context:
|
|
||||||
|
|
||||||
.depend: Makefile $(SRCS)
|
|
||||||
@$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
|
|
||||||
@touch $@
|
|
||||||
|
|
||||||
depend: .depend
|
|
||||||
|
|
||||||
clean:
|
|
||||||
$(call DELFILE, .built)
|
|
||||||
$(call CLEAN)
|
|
||||||
|
|
||||||
distclean: clean
|
|
||||||
$(call DELFILE, Make.dep)
|
|
||||||
$(call DELFILE, .depend)
|
|
||||||
|
|
||||||
-include Make.dep
|
|
|
@ -1,224 +0,0 @@
|
||||||
/****************************************************************************
|
|
||||||
* examples/pipe/interlock_test.c
|
|
||||||
*
|
|
||||||
* Copyright (C) 2008 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/stat.h>
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <errno.h>
|
|
||||||
|
|
||||||
#include "pipe.h"
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Definitions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Types
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Data
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Functions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: null_writer
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static void *null_writer(pthread_addr_t pvarg)
|
|
||||||
{
|
|
||||||
int fd;
|
|
||||||
|
|
||||||
/* Wait a bit */
|
|
||||||
|
|
||||||
printf("null_writer: started -- sleeping\n");
|
|
||||||
sleep(5);
|
|
||||||
|
|
||||||
/* Then open the FIFO for write access */
|
|
||||||
|
|
||||||
printf("null_writer: Opening FIFO for write access\n");
|
|
||||||
fd = open(FIFO_PATH2, O_WRONLY);
|
|
||||||
if (fd < 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "null_writer: Failed to open FIFO %s for writing, errno=%d\n",
|
|
||||||
FIFO_PATH2, errno);
|
|
||||||
return (void*)1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Wait a bit more */
|
|
||||||
|
|
||||||
printf("null_writer: Opened %s for writing -- sleeping\n", FIFO_PATH2);
|
|
||||||
sleep(5);
|
|
||||||
|
|
||||||
/* Then close the FIFO */
|
|
||||||
|
|
||||||
printf("null_writer: Closing %s\n", FIFO_PATH2);
|
|
||||||
if (close(fd) != 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "null_writer: close failed: %d\n", errno);
|
|
||||||
}
|
|
||||||
sleep(5);
|
|
||||||
|
|
||||||
printf("null_writer: Returning success\n");
|
|
||||||
return (void*)0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Functions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: interlock_test
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
int interlock_test(void)
|
|
||||||
{
|
|
||||||
pthread_t writerid;
|
|
||||||
void *value;
|
|
||||||
char data[16];
|
|
||||||
ssize_t nbytes;
|
|
||||||
int fd;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
/* Create a FIFO */
|
|
||||||
|
|
||||||
ret = mkfifo(FIFO_PATH2, 0666);
|
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "interlock_test: mkfifo failed with errno=%d\n", errno);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Start the null_writer_thread */
|
|
||||||
|
|
||||||
printf("interlock_test: Starting null_writer thread\n");
|
|
||||||
ret = pthread_create(&writerid, NULL, null_writer, (pthread_addr_t)NULL);
|
|
||||||
if (ret != 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "interlock_test: Failed to create null_writer thread, error=%d\n", ret);
|
|
||||||
ret = 2;
|
|
||||||
goto errout_with_fifo;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Open one end of the FIFO for reading. This open call should block until the
|
|
||||||
* null_writer thread opens the other end of the FIFO for writing.
|
|
||||||
*/
|
|
||||||
|
|
||||||
printf("interlock_test: Opening FIFO for read access\n");
|
|
||||||
fd = open(FIFO_PATH2, O_RDONLY);
|
|
||||||
if (fd < 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "interlock_test: Failed to open FIFO %s for reading, errno=%d\n",
|
|
||||||
FIFO_PATH2, errno);
|
|
||||||
ret = 3;
|
|
||||||
goto errout_with_thread;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Attempt to read one byte from the FIFO. This should return end-of-file because
|
|
||||||
* the null_writer closes the FIFO without writing anything.
|
|
||||||
*/
|
|
||||||
|
|
||||||
printf("interlock_test: Reading from %s\n", FIFO_PATH2);
|
|
||||||
nbytes = read(fd, data, 16);
|
|
||||||
if (nbytes < 0 )
|
|
||||||
{
|
|
||||||
fprintf(stderr, "interlock_test: read failed, errno=%d\n", errno);
|
|
||||||
ret = 4;
|
|
||||||
goto errout_with_file;
|
|
||||||
}
|
|
||||||
else if (ret != 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "interlock_test: Read %d bytes of data -- aborting: %d\n", nbytes);
|
|
||||||
ret = 5;
|
|
||||||
goto errout_with_file;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Close the file */
|
|
||||||
|
|
||||||
printf("interlock_test: Closing %s\n", FIFO_PATH2);
|
|
||||||
if (close(fd) != 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "interlock_test: close failed: %d\n", errno);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Wait for null_writer thread to complete */
|
|
||||||
|
|
||||||
printf("interlock_test: Waiting for null_writer thread\n");
|
|
||||||
ret = pthread_join(writerid, &value);
|
|
||||||
if (ret != 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "interlock_test: pthread_join failed, error=%d\n", ret);
|
|
||||||
ret = 6;
|
|
||||||
goto errout_with_fifo;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("interlock_test: writer returned %d\n", (int)value);
|
|
||||||
if (value != (void*)0)
|
|
||||||
{
|
|
||||||
ret = 7;
|
|
||||||
goto errout_with_fifo;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* unlink(FIFO_PATH2); */
|
|
||||||
printf("interlock_test: Returning success\n");
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
errout_with_file:
|
|
||||||
if (close(fd) != 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "interlock_test: close failed: %d\n", errno);
|
|
||||||
}
|
|
||||||
errout_with_thread:
|
|
||||||
pthread_detach(writerid);
|
|
||||||
pthread_cancel(writerid);
|
|
||||||
errout_with_fifo:
|
|
||||||
/* unlink(FIFO_PATH2); */
|
|
||||||
printf("interlock_test: Returning %d\n", ret);
|
|
||||||
return ret;
|
|
||||||
}
|
|
|
@ -1,74 +0,0 @@
|
||||||
/****************************************************************************
|
|
||||||
* examples/pipe/pipe.h
|
|
||||||
*
|
|
||||||
* Copyright (C) 2008 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 __EXAMPLES_PIPE_PIPE_H
|
|
||||||
#define __EXAMPLES_PIPE_PIPE_H
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Compilation Switches
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Included Files
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Definitions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#define FIFO_PATH1 "/tmp/testfifo-1"
|
|
||||||
#define FIFO_PATH2 "/tmp/testfifo-2"
|
|
||||||
|
|
||||||
#ifndef CONFIG_EXAMPLES_PIPE_STACKSIZE
|
|
||||||
# define CONFIG_EXAMPLES_PIPE_STACKSIZE 1024
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Types
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Variables
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Function Prototypes
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
extern int transfer_test(int fdin, int fdout);
|
|
||||||
extern int interlock_test(void);
|
|
||||||
extern int redirection_test(void);
|
|
||||||
|
|
||||||
#endif /* __EXAMPLES_PIPE_PIPE_H */
|
|
|
@ -1,189 +0,0 @@
|
||||||
/****************************************************************************
|
|
||||||
* examples/pipe/pipe_main.c
|
|
||||||
*
|
|
||||||
* Copyright (C) 2008-2009, 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/stat.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <sched.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <errno.h>
|
|
||||||
|
|
||||||
#include "pipe.h"
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Definitions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Types
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Data
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Functions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Functions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: pipe_main
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
int pipe_main(int argc, char *argv[])
|
|
||||||
{
|
|
||||||
int filedes[2];
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
/* Test FIFO logic */
|
|
||||||
|
|
||||||
printf("\npipe_main: Performing FIFO test\n");
|
|
||||||
ret = mkfifo(FIFO_PATH1, 0666);
|
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "pipe_main: mkfifo failed with errno=%d\n", errno);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Open one end of the FIFO for reading and the other end for writing. NOTE:
|
|
||||||
* the following might not work on most FIFO implementations because the attempt
|
|
||||||
* to open just one end of the FIFO for writing might block. The NuttX FIFOs block
|
|
||||||
* only on open for read-only (see interlock_test()).
|
|
||||||
*/
|
|
||||||
|
|
||||||
filedes[1] = open(FIFO_PATH1, O_WRONLY);
|
|
||||||
if (filedes[1] < 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "pipe_main: Failed to open FIFO %s for writing, errno=%d\n",
|
|
||||||
FIFO_PATH1, errno);
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
filedes[0] = open(FIFO_PATH1, O_RDONLY);
|
|
||||||
if (filedes[0] < 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "pipe_main: Failed to open FIFO %s for reading, errno=%d\n",
|
|
||||||
FIFO_PATH1, errno);
|
|
||||||
if (close(filedes[1]) != 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "pipe_main: close failed: %d\n", errno);
|
|
||||||
}
|
|
||||||
return 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Then perform the test using those file descriptors */
|
|
||||||
|
|
||||||
ret = transfer_test(filedes[0], filedes[1]);
|
|
||||||
if (close(filedes[0]) != 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "pipe_main: close failed: %d\n", errno);
|
|
||||||
}
|
|
||||||
if (close(filedes[1]) != 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "pipe_main: close failed: %d\n", errno);
|
|
||||||
}
|
|
||||||
/* unlink(FIFO_PATH1); fails */
|
|
||||||
|
|
||||||
if (ret != 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "pipe_main: FIFO test FAILED (%d)\n", ret);
|
|
||||||
return 4;
|
|
||||||
}
|
|
||||||
printf("pipe_main: FIFO test PASSED\n");
|
|
||||||
|
|
||||||
/* Test PIPE logic */
|
|
||||||
|
|
||||||
printf("\npipe_main: Performing pipe test\n");
|
|
||||||
ret = pipe(filedes);
|
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "pipe_main: pipe failed with errno=%d\n", errno);
|
|
||||||
return 5;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Then perform the test using those file descriptors */
|
|
||||||
|
|
||||||
ret = transfer_test(filedes[0], filedes[1]);
|
|
||||||
if (close(filedes[0]) != 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "pipe_main: close failed: %d\n", errno);
|
|
||||||
}
|
|
||||||
if (close(filedes[1]) != 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "pipe_main: close failed: %d\n", errno);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ret != 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "pipe_main: PIPE test FAILED (%d)\n", ret);
|
|
||||||
return 6;
|
|
||||||
}
|
|
||||||
printf("pipe_main: PIPE test PASSED\n");
|
|
||||||
|
|
||||||
/* Perform the FIFO interlock test */
|
|
||||||
|
|
||||||
printf("\npipe_main: Performing pipe interlock test\n");
|
|
||||||
ret = interlock_test();
|
|
||||||
if (ret != 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "pipe_main: FIFO interlock test FAILED (%d)\n", ret);
|
|
||||||
return 7;
|
|
||||||
}
|
|
||||||
printf("pipe_main: PIPE interlock test PASSED\n");
|
|
||||||
|
|
||||||
/* Perform the pipe redirection test */
|
|
||||||
|
|
||||||
printf("\npipe_main: Performing redirection test\n");
|
|
||||||
ret = redirection_test();
|
|
||||||
if (ret != 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "pipe_main: FIFO redirection test FAILED (%d)\n", ret);
|
|
||||||
return 7;
|
|
||||||
}
|
|
||||||
printf("pipe_main: PIPE redirection test PASSED\n");
|
|
||||||
|
|
||||||
fflush(stdout);
|
|
||||||
return 0;
|
|
||||||
}
|
|
|
@ -1,326 +0,0 @@
|
||||||
/****************************************************************************
|
|
||||||
* examples/pipe/redirect_test.c
|
|
||||||
*
|
|
||||||
* Copyright (C) 2008-2009 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 <stdlib.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <sched.h>
|
|
||||||
#include <semaphore.h>
|
|
||||||
#include <errno.h>
|
|
||||||
|
|
||||||
#include "pipe.h"
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Definitions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#define READ_SIZE 37
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Types
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Data
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static sem_t g_rddone;
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Functions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: redirect_reader
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static int redirect_reader(int argc, char *argv[])
|
|
||||||
{
|
|
||||||
char buffer[READ_SIZE];
|
|
||||||
int fdin;
|
|
||||||
int fdout;
|
|
||||||
int ret;
|
|
||||||
int nbytes = 0;
|
|
||||||
|
|
||||||
printf("redirect_reader: started with fdin=%s\n", argv[1]);
|
|
||||||
|
|
||||||
/* Convert the fdin to binary */
|
|
||||||
|
|
||||||
fdin = atoi(argv[1]);
|
|
||||||
fdout = atoi(argv[2]);
|
|
||||||
|
|
||||||
/* Close fdout -- we don't need it */
|
|
||||||
|
|
||||||
ret = close(fdout);
|
|
||||||
if (ret != 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "redirect_reader: failed to close fdout=%d\n", fdout);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Re-direct the fdin to stdin */
|
|
||||||
|
|
||||||
ret = dup2(fdin, 0);
|
|
||||||
if (ret != 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "redirect_reader: dup2 failed: %d\n", errno);
|
|
||||||
close(fdin);
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Close the original file descriptor */
|
|
||||||
|
|
||||||
ret = close(fdin);
|
|
||||||
if (ret != 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "redirect_reader: failed to close fdin=%d\n", fdin);
|
|
||||||
return 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Then read from stdin until we hit the end of file */
|
|
||||||
|
|
||||||
fflush(stdout);
|
|
||||||
for (;;)
|
|
||||||
{
|
|
||||||
/* Read from stdin */
|
|
||||||
|
|
||||||
ret = read(0, buffer, READ_SIZE);
|
|
||||||
if (ret < 0 )
|
|
||||||
{
|
|
||||||
fprintf(stderr, "redirect_reader: read failed, errno=%d\n", errno);
|
|
||||||
return 4;
|
|
||||||
}
|
|
||||||
else if (ret == 0)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
nbytes += ret;
|
|
||||||
|
|
||||||
/* Echo to stdout */
|
|
||||||
|
|
||||||
ret = write(1, buffer, ret);
|
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "redirect_reader: read failed, errno=%d\n", errno);
|
|
||||||
return 5;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("redirect_reader: %d bytes read\n", nbytes);
|
|
||||||
ret = close(0);
|
|
||||||
if (ret != 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "redirect_reader: failed to close fd=0\n");
|
|
||||||
return 6;
|
|
||||||
}
|
|
||||||
|
|
||||||
sem_post(&g_rddone);
|
|
||||||
printf("redirect_reader: Returning success\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: redirect_writer
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static int redirect_writer(int argc, char *argv[])
|
|
||||||
{
|
|
||||||
int fdin;
|
|
||||||
int fdout;
|
|
||||||
int nbytes = 0;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
fprintf(stderr, "redirect_writer: started with fdout=%s\n", argv[2]);
|
|
||||||
|
|
||||||
/* Convert the fdout to binary */
|
|
||||||
|
|
||||||
fdin = atoi(argv[1]);
|
|
||||||
fdout = atoi(argv[2]);
|
|
||||||
|
|
||||||
/* Close fdin -- we don't need it */
|
|
||||||
|
|
||||||
ret = close(fdin);
|
|
||||||
if (ret != 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "redirect_reader: failed to close fdin=%d\n", fdin);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Re-direct the fdout to stdout */
|
|
||||||
|
|
||||||
ret = dup2(fdout, 1);
|
|
||||||
if (ret != 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "redirect_writer: dup2 failed: %d\n", errno);
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Close the original file descriptor */
|
|
||||||
|
|
||||||
ret = close(fdout);
|
|
||||||
if (ret != 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "redirect_reader: failed to close fdout=%d\n", fdout);
|
|
||||||
return 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Then write a bunch of stuff to stdout */
|
|
||||||
|
|
||||||
fflush(stderr);
|
|
||||||
nbytes += printf("\nFour score and seven years ago our fathers brought forth on this continent a new nation,\n");
|
|
||||||
nbytes += printf("conceived in Liberty, and dedicated to the proposition that all men are created equal.\n");
|
|
||||||
nbytes += printf("\nNow we are engaged in a great civil war, testing whether that nation, or any nation, so\n");
|
|
||||||
nbytes += printf("conceived and so dedicated, can long endure. We are met on a great battle-field of that war.\n");
|
|
||||||
nbytes += printf("We have come to dedicate a portion of that field, as a final resting place for those who here\n");
|
|
||||||
nbytes += printf("gave their lives that that nation might live. It is altogether fitting and proper that we\n");
|
|
||||||
nbytes += printf("should do this.\n");
|
|
||||||
nbytes += printf("\nBut, in a larger sense, we can not dedicate - we can not consecrate - we can not hallow - this ground.\n");
|
|
||||||
nbytes += printf("The brave men, living and dead, who struggled here, have consecrated it, far above our poor power\n");
|
|
||||||
nbytes += printf("to add or detract. The world will little note, nor long remember what we say here, but it can\n");
|
|
||||||
nbytes += printf("never forget what they did here. It is for us the living, rather, to be dedicated here to the\n");
|
|
||||||
nbytes += printf("unfinished work which they who fought here have thus far so nobly advanced. It is rather for us to\n");
|
|
||||||
nbytes += printf("be here dedicated to the great task remaining before us - that from these honored dead we take\n");
|
|
||||||
nbytes += printf("increased devotion to that cause for which they gave the last full measure of devotion - that we\n");
|
|
||||||
nbytes += printf("here highly resolve that these dead shall not have died in vain - that this nation, under God,\n");
|
|
||||||
nbytes += printf("shall have a new birth of freedom - and that government of the people, by the people, for the\n");
|
|
||||||
nbytes += printf("people, shall not perish from the earth.\n\n");
|
|
||||||
fflush(stdout);
|
|
||||||
|
|
||||||
fprintf(stderr, "redirect_writer: %d bytes written\n", nbytes);
|
|
||||||
|
|
||||||
ret = close(1);
|
|
||||||
if (ret != 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "redirect_writer: failed to close fd=1\n");
|
|
||||||
return 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
fprintf(stderr, "redirect_writer: Returning success\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Functions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: redirection_test
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
int redirection_test(void)
|
|
||||||
{
|
|
||||||
const char *argv[3];
|
|
||||||
char buffer1[8];
|
|
||||||
char buffer2[8];
|
|
||||||
int readerid;
|
|
||||||
int writerid;
|
|
||||||
int filedes[2];
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
sem_init(&g_rddone, 0, 0);
|
|
||||||
|
|
||||||
/* Create the pipe */
|
|
||||||
|
|
||||||
ret = pipe(filedes);
|
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "redirection_test: pipe failed with errno=%d\n", errno);
|
|
||||||
return 5;
|
|
||||||
}
|
|
||||||
|
|
||||||
sprintf(buffer1, "%d", filedes[0]);
|
|
||||||
argv[0] = buffer1;
|
|
||||||
sprintf(buffer2, "%d", filedes[1]);
|
|
||||||
argv[1] = buffer2;
|
|
||||||
argv[2] = NULL;
|
|
||||||
|
|
||||||
/* Start redirect_reader thread */
|
|
||||||
|
|
||||||
printf("redirection_test: Starting redirect_reader task with fd=%d\n", filedes[0]);
|
|
||||||
readerid = task_create("redirect_reader", 50, CONFIG_EXAMPLES_PIPE_STACKSIZE, redirect_reader, argv);
|
|
||||||
if (readerid < 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "redirection_test: Failed to create redirect_writer task: %d\n", errno);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Start redirect_writer task */
|
|
||||||
|
|
||||||
printf("redirection_test: Starting redirect_writer task with fd=%d\n", filedes[1]);
|
|
||||||
writerid = task_create("redirect_writer", 50, CONFIG_EXAMPLES_PIPE_STACKSIZE, redirect_writer, argv);
|
|
||||||
if (writerid < 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "redirection_test: Failed to create redirect_writer task: %d\n", errno);
|
|
||||||
ret = task_delete(readerid);
|
|
||||||
if (ret != 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "redirection_test: Failed to delete redirect_reader task %d\n", errno);
|
|
||||||
}
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* We should be able to close the pipe file descriptors now. */
|
|
||||||
|
|
||||||
if (close(filedes[0]) != 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "pipe_main: close failed: %d\n", errno);
|
|
||||||
}
|
|
||||||
if (close(filedes[1]) != 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "pipe_main: close failed: %d\n", errno);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ret != 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "pipe_main: PIPE test FAILED (%d)\n", ret);
|
|
||||||
return 6;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Wait for redirect_writer thread to complete */
|
|
||||||
|
|
||||||
printf("redirection_test: Waiting...\n");
|
|
||||||
fflush(stdout);
|
|
||||||
sem_wait(&g_rddone);
|
|
||||||
|
|
||||||
printf("redirection_test: returning %d\n", ret);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,242 +0,0 @@
|
||||||
/****************************************************************************
|
|
||||||
* examples/pipe/transfer_test.c
|
|
||||||
*
|
|
||||||
* Copyright (C) 2008-2009 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 <unistd.h>
|
|
||||||
#include <errno.h>
|
|
||||||
|
|
||||||
#include "pipe.h"
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Pre-proecessor Definitions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#define MAX_BYTE 13
|
|
||||||
|
|
||||||
#define WRITE_SIZE MAX_BYTE
|
|
||||||
#define NWRITES 1400
|
|
||||||
#define NWRITE_BYTES (NWRITES * WRITE_SIZE)
|
|
||||||
|
|
||||||
#define READ_SIZE (2*MAX_BYTE)
|
|
||||||
#define NREADS (NWRITES / 2)
|
|
||||||
#define NREAD_BYTES NWRITE_BYTES
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Types
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Data
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Functions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: transfer_reader
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static void *transfer_reader(pthread_addr_t pvarg)
|
|
||||||
{
|
|
||||||
char buffer[READ_SIZE];
|
|
||||||
int fd = (int)pvarg;
|
|
||||||
int ret;
|
|
||||||
int nbytes;
|
|
||||||
int value;
|
|
||||||
int ndx;
|
|
||||||
|
|
||||||
printf("transfer_reader: started\n");
|
|
||||||
for (nbytes = 0, value = 0; nbytes < NREAD_BYTES;)
|
|
||||||
{
|
|
||||||
ret = read(fd, buffer, READ_SIZE);
|
|
||||||
if (ret < 0 )
|
|
||||||
{
|
|
||||||
fprintf(stderr, "transfer_reader: read failed, errno=%d\n", errno);
|
|
||||||
return (void*)1;
|
|
||||||
}
|
|
||||||
else if (ret == 0)
|
|
||||||
{
|
|
||||||
if (nbytes < NREAD_BYTES)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "transfer_reader: Too few bytes read -- aborting: %d\n", nbytes);
|
|
||||||
return (void*)2;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
for (ndx = 0; ndx < ret; ndx++)
|
|
||||||
{
|
|
||||||
if (value >= WRITE_SIZE)
|
|
||||||
{
|
|
||||||
value = 0;
|
|
||||||
}
|
|
||||||
if (buffer[ndx] != value)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "transfer_reader: Byte %d, expected %d, found %d\n",
|
|
||||||
nbytes + ndx, value, buffer[ndx]);
|
|
||||||
return (void*)3;
|
|
||||||
}
|
|
||||||
value++;
|
|
||||||
}
|
|
||||||
nbytes += ret;
|
|
||||||
if (nbytes > NREAD_BYTES)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "transfer_reader: Too many bytes read -- aborting: %d\n", nbytes);
|
|
||||||
return (void*)4;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
printf("transfer_reader: %d bytes read\n", nbytes);
|
|
||||||
return (void*)0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: transfer_writer
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static void *transfer_writer(pthread_addr_t pvarg)
|
|
||||||
{
|
|
||||||
char buffer[WRITE_SIZE];
|
|
||||||
int fd = (int)pvarg;
|
|
||||||
int ret;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
printf("transfer_writer: started\n");
|
|
||||||
for (i = 0; i < WRITE_SIZE; i++)
|
|
||||||
{
|
|
||||||
buffer[i] = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < NWRITES; i++)
|
|
||||||
{
|
|
||||||
ret = write(fd, buffer, WRITE_SIZE);
|
|
||||||
if (ret < 0 )
|
|
||||||
{
|
|
||||||
fprintf(stderr, "transfer_writer: write failed, errno=%d\n", errno);
|
|
||||||
return (void*)1;
|
|
||||||
}
|
|
||||||
else if (ret != WRITE_SIZE)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "transfer_writer: Unexpected write size=%d\n", ret);
|
|
||||||
return (void*)2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
printf("transfer_writer: %d bytes written\n", NWRITE_BYTES);
|
|
||||||
return (void*)0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Functions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: transfer_test
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
int transfer_test(int fdin, int fdout)
|
|
||||||
{
|
|
||||||
pthread_t readerid;
|
|
||||||
pthread_t writerid;
|
|
||||||
void *value;
|
|
||||||
int tmp;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
/* Start transfer_reader thread */
|
|
||||||
|
|
||||||
printf("transfer_test: Starting transfer_reader thread\n");
|
|
||||||
ret = pthread_create(&readerid, NULL, transfer_reader, (pthread_addr_t)fdin);
|
|
||||||
if (ret != 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "transfer_test: Failed to create transfer_reader thread, error=%d\n", ret);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Start transfer_writer thread */
|
|
||||||
|
|
||||||
printf("transfer_test: Starting transfer_writer thread\n");
|
|
||||||
ret = pthread_create(&writerid, NULL, transfer_writer, (pthread_addr_t)fdout);
|
|
||||||
if (ret != 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "transfer_test: Failed to create transfer_writer thread, error=%d\n", ret);
|
|
||||||
pthread_detach(readerid);
|
|
||||||
ret = pthread_cancel(readerid);
|
|
||||||
if (ret != 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "transfer_test: Failed to cancel transfer_reader thread, error=%d\n", ret);
|
|
||||||
}
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Wait for transfer_writer thread to complete */
|
|
||||||
|
|
||||||
printf("transfer_test: Waiting for transfer_writer thread\n");
|
|
||||||
ret = pthread_join(writerid, &value);
|
|
||||||
if (ret != 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "transfer_test: pthread_join failed, error=%d\n", ret);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ret = (int)value;
|
|
||||||
printf("transfer_test: transfer_writer returned %d\n", ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Wait for transfer_reader thread to complete */
|
|
||||||
|
|
||||||
printf("transfer_test: Waiting for transfer_reader thread\n");
|
|
||||||
tmp = pthread_join(readerid, &value);
|
|
||||||
if (tmp != 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "transfer_test: pthread_join failed, error=%d\n", ret);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
tmp = (int)value;
|
|
||||||
printf("transfer_test: transfer_reader returned %d\n", tmp);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ret == 0)
|
|
||||||
{
|
|
||||||
ret = tmp;
|
|
||||||
}
|
|
||||||
printf("transfer_test: returning %d\n", ret);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,31 +0,0 @@
|
||||||
#
|
|
||||||
# For a description of the syntax of this configuration file,
|
|
||||||
# see misc/tools/kconfig-language.txt.
|
|
||||||
#
|
|
||||||
|
|
||||||
config EXAMPLES_POLL
|
|
||||||
bool "Poll example"
|
|
||||||
default n
|
|
||||||
depends on !NSH_BUILTIN_APPS
|
|
||||||
---help---
|
|
||||||
Enable the poll example
|
|
||||||
|
|
||||||
if EXAMPLES_POLL
|
|
||||||
|
|
||||||
config EXAMPLES_POLL_NOMAC
|
|
||||||
bool "Use Canned MAC Address"
|
|
||||||
default n
|
|
||||||
|
|
||||||
config EXAMPLES_POLL_IPADDR
|
|
||||||
hex "Target IP address"
|
|
||||||
default 0x0a000002
|
|
||||||
|
|
||||||
config EXAMPLES_POLL_DRIPADDR
|
|
||||||
hex "Default Router IP address (Gateway)"
|
|
||||||
default 0x0a000001
|
|
||||||
|
|
||||||
config EXAMPLES_POLL_NETMASK
|
|
||||||
hex "Network Mask"
|
|
||||||
default 0xffffff00
|
|
||||||
|
|
||||||
endif
|
|
|
@ -1,98 +0,0 @@
|
||||||
############################################################################
|
|
||||||
# apps/examples/poll/Makefile
|
|
||||||
#
|
|
||||||
# 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
|
|
||||||
# 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)/.config
|
|
||||||
-include $(TOPDIR)/Make.defs
|
|
||||||
include $(APPDIR)/Make.defs
|
|
||||||
|
|
||||||
# Device Driver poll()/select() Example
|
|
||||||
|
|
||||||
ASRCS =
|
|
||||||
CSRCS = poll_main.c poll_listener.c select_listener.c net_listener.c net_reader.c
|
|
||||||
|
|
||||||
AOBJS = $(ASRCS:.S=$(OBJEXT))
|
|
||||||
COBJS = $(CSRCS:.c=$(OBJEXT))
|
|
||||||
|
|
||||||
SRCS = $(ASRCS) $(CSRCS)
|
|
||||||
OBJS = $(AOBJS) $(COBJS)
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
|
|
||||||
BIN = ..\..\libapps$(LIBEXT)
|
|
||||||
else
|
|
||||||
ifeq ($(WINTOOL),y)
|
|
||||||
BIN = ..\\..\\libapps$(LIBEXT)
|
|
||||||
else
|
|
||||||
BIN = ../../libapps$(LIBEXT)
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
ROOTDEPPATH = --dep-path .
|
|
||||||
|
|
||||||
# Common build
|
|
||||||
|
|
||||||
VPATH =
|
|
||||||
|
|
||||||
all: .built
|
|
||||||
.PHONY: clean depend distclean
|
|
||||||
|
|
||||||
$(AOBJS): %$(OBJEXT): %.S
|
|
||||||
$(call ASSEMBLE, $<, $@)
|
|
||||||
|
|
||||||
$(COBJS): %$(OBJEXT): %.c
|
|
||||||
$(call COMPILE, $<, $@)
|
|
||||||
|
|
||||||
.built: $(OBJS)
|
|
||||||
$(call ARCHIVE, $(BIN), $(OBJS))
|
|
||||||
@touch .built
|
|
||||||
|
|
||||||
context:
|
|
||||||
|
|
||||||
.depend: Makefile $(SRCS)
|
|
||||||
@$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
|
|
||||||
@touch $@
|
|
||||||
|
|
||||||
# Register application
|
|
||||||
depend: .depend
|
|
||||||
|
|
||||||
clean:
|
|
||||||
$(call DELFILE, .built)
|
|
||||||
$(call CLEAN)
|
|
||||||
|
|
||||||
distclean: clean
|
|
||||||
$(call DELFILE, Make.dep)
|
|
||||||
$(call DELFILE, .depend)
|
|
||||||
$(call DELFILE, host$(HOSTEXEEXT))
|
|
||||||
|
|
||||||
-include Make.dep
|
|
|
@ -1,54 +0,0 @@
|
||||||
############################################################################
|
|
||||||
# apps/examples/poll/Makefile.host
|
|
||||||
#
|
|
||||||
# Copyright (C) 2008, 2009, 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.
|
|
||||||
#
|
|
||||||
############################################################################
|
|
||||||
|
|
||||||
# TOPDIR must be defined on the make command line
|
|
||||||
|
|
||||||
include $(TOPDIR)/.config
|
|
||||||
include $(TOPDIR)/Make.defs
|
|
||||||
|
|
||||||
SRC = host.c
|
|
||||||
BIN = host
|
|
||||||
|
|
||||||
DEFINES = -DTARGETIP=\"$(TARGETIP)\"
|
|
||||||
|
|
||||||
all: $(BIN)
|
|
||||||
|
|
||||||
$(BIN): $(SRC)
|
|
||||||
$(HOSTCC) $(HOSTCFLAGS) $(DEFINES) $^ -o $@
|
|
||||||
|
|
||||||
clean:
|
|
||||||
@rm -f $(BIN) *~ .*.swp *.o
|
|
||||||
$(call CLEAN)
|
|
||||||
|
|
|
@ -1,171 +0,0 @@
|
||||||
/****************************************************************************
|
|
||||||
* examples/poll/host.c
|
|
||||||
*
|
|
||||||
* Copyright (C) 2008-2009, 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/socket.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <pthread.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <errno.h>
|
|
||||||
|
|
||||||
#include <netinet/in.h>
|
|
||||||
#include <arpa/inet.h>
|
|
||||||
|
|
||||||
#define pthread_addr_t void *
|
|
||||||
#include "poll_internal.h"
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Pre-processor Definitions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#ifndef TARGETIP
|
|
||||||
# error TARGETIP not defined
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define IOBUFFER_SIZE 80
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Data
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Functions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* main
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
int main(int argc, char **argv, char **envp)
|
|
||||||
{
|
|
||||||
struct sockaddr_in myaddr;
|
|
||||||
char outbuf[IOBUFFER_SIZE];
|
|
||||||
char inbuf[IOBUFFER_SIZE];
|
|
||||||
int sockfd;
|
|
||||||
int len;
|
|
||||||
int nbytessent;
|
|
||||||
int nbytesrecvd;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
/* Create a new TCP socket */
|
|
||||||
|
|
||||||
sockfd = socket(PF_INET, SOCK_STREAM, 0);
|
|
||||||
if (sockfd < 0)
|
|
||||||
{
|
|
||||||
message("client socket failure %d\n", errno);
|
|
||||||
goto errout_with_outbufs;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Connect the socket to the server */
|
|
||||||
|
|
||||||
myaddr.sin_family = AF_INET;
|
|
||||||
myaddr.sin_port = htons(LISTENER_PORT);
|
|
||||||
myaddr.sin_addr.s_addr = inet_addr(TARGETIP);
|
|
||||||
|
|
||||||
message("client: Connecting to %s...\n", TARGETIP);
|
|
||||||
if (connect( sockfd, (struct sockaddr*)&myaddr, sizeof(struct sockaddr_in)) < 0)
|
|
||||||
{
|
|
||||||
message("client: connect failure: %d\n", errno);
|
|
||||||
goto errout_with_socket;
|
|
||||||
}
|
|
||||||
message("client: Connected\n");
|
|
||||||
|
|
||||||
/* Then send and receive messages */
|
|
||||||
|
|
||||||
for (i = 0; ; i++)
|
|
||||||
{
|
|
||||||
sprintf(outbuf, "Remote message %d", i);
|
|
||||||
len = strlen(outbuf);
|
|
||||||
|
|
||||||
message("client: Sending '%s' (%d bytes)\n", outbuf, len);
|
|
||||||
nbytessent = send(sockfd, outbuf, len, 0);
|
|
||||||
message("client: Sent %d bytes\n", nbytessent);
|
|
||||||
|
|
||||||
if (nbytessent < 0)
|
|
||||||
{
|
|
||||||
message("client: send failed: %d\n", errno);
|
|
||||||
goto errout_with_socket;
|
|
||||||
}
|
|
||||||
else if (nbytessent != len)
|
|
||||||
{
|
|
||||||
message("client: Bad send length: %d Expected: %d\n", nbytessent, len);
|
|
||||||
goto errout_with_socket;
|
|
||||||
}
|
|
||||||
|
|
||||||
message("client: Receiving...\n");
|
|
||||||
nbytesrecvd = recv(sockfd, inbuf, IOBUFFER_SIZE, 0);
|
|
||||||
|
|
||||||
if (nbytesrecvd < 0)
|
|
||||||
{
|
|
||||||
message("client: recv failed: %d\n", errno);
|
|
||||||
goto errout_with_socket;
|
|
||||||
}
|
|
||||||
else if (nbytesrecvd == 0)
|
|
||||||
{
|
|
||||||
message("client: The server broke the connections\n");
|
|
||||||
goto errout_with_socket;
|
|
||||||
}
|
|
||||||
|
|
||||||
inbuf[nbytesrecvd] = '\0';
|
|
||||||
message("client: Received '%s' (%d bytes)\n", inbuf, nbytesrecvd);
|
|
||||||
|
|
||||||
if (nbytesrecvd != len)
|
|
||||||
{
|
|
||||||
message("client: Bad recv length: %d Expected: %d\n", nbytesrecvd, len);
|
|
||||||
goto errout_with_socket;
|
|
||||||
}
|
|
||||||
else if (memcmp(inbuf, outbuf, len) != 0)
|
|
||||||
{
|
|
||||||
message("client: Received outbuf does not match sent outbuf\n");
|
|
||||||
goto errout_with_socket;
|
|
||||||
}
|
|
||||||
|
|
||||||
message("client: Sleeping\n");
|
|
||||||
sleep(8);
|
|
||||||
}
|
|
||||||
|
|
||||||
close(sockfd);
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
errout_with_socket:
|
|
||||||
close(sockfd);
|
|
||||||
errout_with_outbufs:
|
|
||||||
exit(1);
|
|
||||||
}
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue