From 7d61592105d0a53960d2129f3feee7615ec17833 Mon Sep 17 00:00:00 2001 From: patacongo Date: Mon, 26 Nov 2012 13:22:51 +0000 Subject: STM32 FLASH pre-fetch is no long enabled unless it is so configured git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5388 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/arch/arm/src/stm32/Kconfig | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'nuttx/arch/arm/src/stm32/Kconfig') diff --git a/nuttx/arch/arm/src/stm32/Kconfig b/nuttx/arch/arm/src/stm32/Kconfig index 2807e1a47..99dde3209 100644 --- a/nuttx/arch/arm/src/stm32/Kconfig +++ b/nuttx/arch/arm/src/stm32/Kconfig @@ -689,6 +689,15 @@ endchoice endmenu +config STM32_FLASH_PREFETCH + bool "Enable FLASH Pre-fetch" + depends on STM32_STM32F20XX || STM32_STM32F40XX + default n + ---help--- + Enable FLASH prefetch and F2 and F4 parts (FLASH pre-fetch is always enabled + on F1 parts). Some early revisions of F4 parts do not support FLASH pre-fetch + properly and enabling this option may interfere with ADC accuracy. + choice prompt "JTAG Configuration" default STM32_JTAG_DISABLE -- cgit v1.2.3 From f127495caa2d45a1b1fff3be7a9d3756259d23e2 Mon Sep 17 00:00:00 2001 From: px4dev Date: Fri, 11 Jan 2013 02:14:43 -0800 Subject: Manually fixup merge botches via direct comparison with NuttX r5447. --- Makefile | 6 +- nuttx/COPYING | 51 + nuttx/Kconfig | 112 +- nuttx/Makefile | 622 +------- nuttx/TODO | 55 +- nuttx/arch/arm/include/elf.h | 243 +++ nuttx/arch/arm/include/stm32/chip.h | 200 ++- nuttx/arch/arm/include/stm32/stm32f10xxx_irq.h | 58 +- nuttx/arch/arm/src/Makefile | 148 +- nuttx/arch/arm/src/armv7-m/Kconfig | 51 + nuttx/arch/arm/src/armv7-m/memcpy.S | 351 ----- nuttx/arch/arm/src/armv7-m/up_elf.c | 450 ++++++ nuttx/arch/arm/src/armv7-m/up_hardfault.c | 4 +- nuttx/arch/arm/src/armv7-m/up_memcpy.S | 416 +++++ nuttx/arch/arm/src/common/arm-elf.h | 53 + nuttx/arch/arm/src/stm32/Kconfig | 622 ++++++-- nuttx/arch/arm/src/stm32/chip/stm32_eth.h | 8 - nuttx/arch/arm/src/stm32/chip/stm32f100_pinmap.h | 190 ++- nuttx/arch/arm/src/stm32/chip/stm32f103vc_pinmap.h | 2 +- nuttx/arch/arm/src/stm32/chip/stm32f103ze_pinmap.h | 98 +- nuttx/arch/arm/src/stm32/chip/stm32f105vb_pinmap.h | 2 +- nuttx/arch/arm/src/stm32/chip/stm32f107vc_pinmap.h | 2 +- nuttx/arch/arm/src/stm32/chip/stm32f10xxx_gpio.h | 23 + .../arm/src/stm32/chip/stm32f10xxx_memorymap.h | 61 +- nuttx/arch/arm/src/stm32/chip/stm32f10xxx_rcc.h | 78 +- .../arch/arm/src/stm32/chip/stm32f10xxx_vectors.h | 72 +- nuttx/arch/arm/src/stm32/chip/stm32f20xxx_pinmap.h | 2 +- nuttx/arch/arm/src/stm32/chip/stm32f40xxx_pinmap.h | 2 +- nuttx/arch/arm/src/stm32/stm32_adc.h | 2 +- nuttx/arch/arm/src/stm32/stm32_eth.c | 11 + nuttx/arch/arm/src/stm32/stm32_eth.h | 35 +- nuttx/arch/arm/src/stm32/stm32_i2c.c | 385 ++--- nuttx/arch/arm/src/stm32/stm32_lowputc.c | 75 +- nuttx/arch/arm/src/stm32/stm32_otgfsdev.c | 26 +- nuttx/arch/arm/src/stm32/stm32_qencoder.c | 1 + nuttx/arch/arm/src/stm32/stm32_serial.c | 186 ++- nuttx/arch/arm/src/stm32/stm32_uart.h | 14 + nuttx/arch/arm/src/stm32/stm32f10xxx_rcc.c | 56 +- nuttx/binfmt/binfmt_exec.c | 2 +- nuttx/binfmt/binfmt_globals.c | 2 +- nuttx/binfmt/binfmt_internal.h | 2 +- nuttx/binfmt/binfmt_register.c | 2 +- nuttx/binfmt/binfmt_unregister.c | 2 +- nuttx/binfmt/libnxflat/Kconfig | 5 + nuttx/binfmt/libnxflat/libnxflat_init.c | 7 +- nuttx/binfmt/libnxflat/libnxflat_read.c | 14 +- nuttx/binfmt/libnxflat/libnxflat_uninit.c | 7 +- nuttx/binfmt/libnxflat/libnxflat_verify.c | 9 +- nuttx/binfmt/symtab_findbyname.c | 2 +- nuttx/binfmt/symtab_findbyvalue.c | 2 +- nuttx/binfmt/symtab_findorderedbyname.c | 2 +- nuttx/binfmt/symtab_findorderedbyvalue.c | 2 +- nuttx/configs/README.txt | 179 ++- nuttx/configs/px4fmu/nsh/defconfig | 5 + nuttx/drivers/Kconfig | 76 +- nuttx/drivers/Makefile | 27 +- nuttx/drivers/analog/adc.c | 15 +- nuttx/drivers/input/max11802.c | 1313 ++++++++++++++++ nuttx/drivers/input/max11802.h | 167 ++ nuttx/drivers/lcd/Kconfig | 81 +- nuttx/drivers/lcd/ug-9664hswag01.c | 15 +- nuttx/drivers/mmcsd/mmcsd_sdio.c | 5 + nuttx/drivers/mmcsd/mmcsd_spi.c | 11 +- nuttx/drivers/net/e1000.c | 307 ++-- nuttx/drivers/net/e1000.h | 4 +- nuttx/drivers/net/vnet.c | 333 ++-- nuttx/drivers/usbdev/pl2303.c | 2 +- nuttx/drivers/usbdev/usbmsc.h | 2 +- nuttx/fs/Makefile | 18 +- nuttx/fs/fs_stat.c | 7 +- nuttx/graphics/Makefile | 98 +- nuttx/graphics/nxfonts/Makefile.sources | 14 +- nuttx/graphics/nxglib/Makefile.sources | 52 +- nuttx/graphics/nxmu/nx_bitmap.c | 29 +- nuttx/graphics/nxmu/nx_block.c | 2 +- nuttx/graphics/nxmu/nx_getrectangle.c | 30 +- nuttx/graphics/nxmu/nxfe.h | 21 + nuttx/graphics/nxmu/nxmu_kbdin.c | 2 +- nuttx/graphics/nxmu/nxmu_mouse.c | 46 +- nuttx/graphics/nxmu/nxmu_redrawreq.c | 2 +- nuttx/graphics/nxmu/nxmu_reportposition.c | 2 +- nuttx/graphics/nxmu/nxmu_sendwindow.c | 44 + nuttx/graphics/nxmu/nxmu_server.c | 10 + nuttx/graphics/nxsu/nx_mousein.c | 30 +- nuttx/graphics/nxtk/nxtk_events.c | 39 +- nuttx/graphics/nxtk/nxtk_internal.h | 5 + nuttx/include/cxx/cstdbool | 9 + nuttx/include/cxx/cstdio | 12 +- nuttx/include/elf32.h | 352 +++++ nuttx/include/net/if.h | 9 + nuttx/include/nuttx/binfmt.h | 209 --- nuttx/include/nuttx/binfmt/symtab.h | 163 ++ nuttx/include/nuttx/compiler.h | 23 +- nuttx/include/nuttx/float.h | 225 +++ nuttx/include/nuttx/fs/fs.h | 15 +- nuttx/include/nuttx/i2c.h | 31 +- nuttx/include/nuttx/input/max11802.h | 175 +++ nuttx/include/nuttx/lcd/ug-2864ambag01.h | 245 +++ nuttx/include/nuttx/lcd/ug-9664hswag01.h | 15 +- nuttx/include/nuttx/net/ioctl.h | 6 + nuttx/include/nuttx/net/uip/uip-arch.h | 4 + nuttx/include/nuttx/nxflat.h | 264 ---- nuttx/include/nuttx/power/pm.h | 6 +- nuttx/include/nuttx/sched.h | 6 +- nuttx/include/nuttx/symtab.h | 163 -- nuttx/include/nuttx/usb/cdcacm.h | 2 +- nuttx/include/nuttx/usb/usbdev_trace.h | 4 - nuttx/include/nuttx/wqueue.h | 24 +- nuttx/include/stdio.h | 7 +- nuttx/include/termios.h | 2 +- nuttx/include/unistd.h | 1 + nuttx/lib/Kconfig | 194 --- nuttx/lib/Makefile | 98 +- nuttx/lib/README.txt | 82 +- nuttx/lib/dirent/Make.defs | 48 - nuttx/lib/dirent/lib_readdirr.c | 122 -- nuttx/lib/dirent/lib_telldir.c | 91 -- nuttx/lib/lib.csv | 171 -- nuttx/lib/lib_internal.h | 200 --- nuttx/lib/libgen/Make.defs | 43 - nuttx/lib/libgen/lib_basename.c | 131 -- nuttx/lib/libgen/lib_dirname.c | 144 -- nuttx/lib/math/Make.defs | 43 - nuttx/lib/math/lib_b16atan2.c | 108 -- nuttx/lib/math/lib_b16cos.c | 64 - nuttx/lib/math/lib_b16sin.c | 110 -- nuttx/lib/math/lib_fixedmath.c | 272 ---- nuttx/lib/math/lib_rint.c | 135 -- nuttx/lib/misc/Make.defs | 69 - nuttx/lib/misc/lib_crc32.c | 123 -- nuttx/lib/misc/lib_dbg.c | 165 -- nuttx/lib/misc/lib_dumpbuffer.c | 129 -- nuttx/lib/misc/lib_filesem.c | 145 -- nuttx/lib/misc/lib_init.c | 207 --- nuttx/lib/misc/lib_match.c | 148 -- nuttx/lib/misc/lib_sendfile.c | 297 ---- nuttx/lib/misc/lib_streamsem.c | 90 -- nuttx/lib/mqueue/Make.defs | 48 - nuttx/lib/mqueue/mq_getattr.c | 104 -- nuttx/lib/mqueue/mq_setattr.c | 118 -- nuttx/lib/net/Make.defs | 44 - nuttx/lib/net/lib_etherntoa.c | 69 - nuttx/lib/net/lib_htonl.c | 68 - nuttx/lib/net/lib_htons.c | 65 - nuttx/lib/net/lib_inetaddr.c | 74 - nuttx/lib/net/lib_inetntoa.c | 79 - nuttx/lib/net/lib_inetntop.c | 202 --- nuttx/lib/net/lib_inetpton.c | 338 ---- nuttx/lib/pthread/Make.defs | 56 - nuttx/lib/pthread/pthread_attrdestroy.c | 108 -- nuttx/lib/pthread/pthread_attrgetinheritsched.c | 111 -- nuttx/lib/pthread/pthread_attrgetschedparam.c | 110 -- nuttx/lib/pthread/pthread_attrgetschedpolicy.c | 105 -- nuttx/lib/pthread/pthread_attrgetstacksize.c | 106 -- nuttx/lib/pthread/pthread_attrinit.c | 123 -- nuttx/lib/pthread/pthread_attrsetinheritsched.c | 113 -- nuttx/lib/pthread/pthread_attrsetschedparam.c | 108 -- nuttx/lib/pthread/pthread_attrsetschedpolicy.c | 111 -- nuttx/lib/pthread/pthread_attrsetstacksize.c | 106 -- nuttx/lib/pthread/pthread_barrierattrdestroy.c | 102 -- nuttx/lib/pthread/pthread_barrierattrgetpshared.c | 101 -- nuttx/lib/pthread/pthread_barrierattrinit.c | 101 -- nuttx/lib/pthread/pthread_barrierattrsetpshared.c | 111 -- nuttx/lib/pthread/pthread_condattrdestroy.c | 82 - nuttx/lib/pthread/pthread_condattrinit.c | 85 - nuttx/lib/pthread/pthread_mutexattrdestroy.c | 104 -- nuttx/lib/pthread/pthread_mutexattrgetpshared.c | 104 -- nuttx/lib/pthread/pthread_mutexattrgettype.c | 98 -- nuttx/lib/pthread/pthread_mutexattrinit.c | 106 -- nuttx/lib/pthread/pthread_mutexattrsetpshared.c | 104 -- nuttx/lib/pthread/pthread_mutexattrsettype.c | 98 -- nuttx/lib/queue/Make.defs | 47 - nuttx/lib/queue/dq_addafter.c | 74 - nuttx/lib/queue/dq_addbefore.c | 69 - nuttx/lib/queue/dq_addfirst.c | 74 - nuttx/lib/queue/dq_addlast.c | 74 - nuttx/lib/queue/dq_rem.c | 84 - nuttx/lib/queue/dq_remfirst.c | 82 - nuttx/lib/queue/dq_remlast.c | 78 - nuttx/lib/queue/sq_addafter.c | 71 - nuttx/lib/queue/sq_addfirst.c | 67 - nuttx/lib/queue/sq_addlast.c | 72 - nuttx/lib/queue/sq_rem.c | 83 - nuttx/lib/queue/sq_remafter.c | 79 - nuttx/lib/queue/sq_remfirst.c | 76 - nuttx/lib/queue/sq_remlast.c | 87 -- nuttx/lib/sched/Make.defs | 43 - nuttx/lib/sched/sched_getprioritymax.c | 100 -- nuttx/lib/sched/sched_getprioritymin.c | 100 -- nuttx/lib/semaphore/Make.defs | 43 - nuttx/lib/semaphore/sem_getvalue.c | 108 -- nuttx/lib/semaphore/sem_init.c | 125 -- nuttx/lib/signal/Make.defs | 47 - nuttx/lib/signal/sig_addset.c | 100 -- nuttx/lib/signal/sig_delset.c | 100 -- nuttx/lib/signal/sig_emptyset.c | 88 -- nuttx/lib/signal/sig_fillset.c | 88 -- nuttx/lib/signal/sig_ismember.c | 101 -- nuttx/lib/stdio/Make.defs | 73 - nuttx/lib/stdio/lib_asprintf.c | 105 -- nuttx/lib/stdio/lib_avsprintf.c | 146 -- nuttx/lib/stdio/lib_dtoa.c | 1641 -------------------- nuttx/lib/stdio/lib_fclose.c | 154 -- nuttx/lib/stdio/lib_fflush.c | 132 -- nuttx/lib/stdio/lib_fgetc.c | 101 -- nuttx/lib/stdio/lib_fgetpos.c | 123 -- nuttx/lib/stdio/lib_fgets.c | 207 --- nuttx/lib/stdio/lib_fileno.c | 70 - nuttx/lib/stdio/lib_fopen.c | 299 ---- nuttx/lib/stdio/lib_fprintf.c | 93 -- nuttx/lib/stdio/lib_fputc.c | 113 -- nuttx/lib/stdio/lib_fputs.c | 220 --- nuttx/lib/stdio/lib_fread.c | 101 -- nuttx/lib/stdio/lib_fseek.c | 138 -- nuttx/lib/stdio/lib_fsetpos.c | 116 -- nuttx/lib/stdio/lib_ftell.c | 129 -- nuttx/lib/stdio/lib_fwrite.c | 99 -- nuttx/lib/stdio/lib_gets.c | 120 -- nuttx/lib/stdio/lib_libdtoa.c | 304 ---- nuttx/lib/stdio/lib_libfflush.c | 202 --- nuttx/lib/stdio/lib_libflushall.c | 137 -- nuttx/lib/stdio/lib_libfread.c | 290 ---- nuttx/lib/stdio/lib_libfwrite.c | 179 --- nuttx/lib/stdio/lib_libnoflush.c | 103 -- nuttx/lib/stdio/lib_libsprintf.c | 90 -- nuttx/lib/stdio/lib_libvsprintf.c | 1620 ------------------- nuttx/lib/stdio/lib_lowinstream.c | 102 -- nuttx/lib/stdio/lib_lowoutstream.c | 97 -- nuttx/lib/stdio/lib_lowprintf.c | 128 -- nuttx/lib/stdio/lib_meminstream.c | 104 -- nuttx/lib/stdio/lib_memoutstream.c | 105 -- nuttx/lib/stdio/lib_nullinstream.c | 79 - nuttx/lib/stdio/lib_nulloutstream.c | 84 - nuttx/lib/stdio/lib_perror.c | 99 -- nuttx/lib/stdio/lib_printf.c | 109 -- nuttx/lib/stdio/lib_puts.c | 130 -- nuttx/lib/stdio/lib_rawinstream.c | 107 -- nuttx/lib/stdio/lib_rawoutstream.c | 115 -- nuttx/lib/stdio/lib_rawprintf.c | 166 -- nuttx/lib/stdio/lib_rdflush.c | 144 -- nuttx/lib/stdio/lib_snprintf.c | 99 -- nuttx/lib/stdio/lib_sprintf.c | 95 -- nuttx/lib/stdio/lib_sscanf.c | 507 ------ nuttx/lib/stdio/lib_stdinstream.c | 99 -- nuttx/lib/stdio/lib_stdoutstream.c | 147 -- nuttx/lib/stdio/lib_syslogstream.c | 122 -- nuttx/lib/stdio/lib_ungetc.c | 121 -- nuttx/lib/stdio/lib_vdprintf.c | 81 - nuttx/lib/stdio/lib_vfprintf.c | 102 -- nuttx/lib/stdio/lib_vprintf.c | 92 -- nuttx/lib/stdio/lib_vsnprintf.c | 96 -- nuttx/lib/stdio/lib_vsprintf.c | 92 -- nuttx/lib/stdio/lib_wrflush.c | 134 -- nuttx/lib/stdio/lib_zeroinstream.c | 79 - nuttx/lib/stdlib/Make.defs | 44 - nuttx/lib/stdlib/lib_abort.c | 121 -- nuttx/lib/stdlib/lib_abs.c | 54 - nuttx/lib/stdlib/lib_imaxabs.c | 54 - nuttx/lib/stdlib/lib_labs.c | 54 - nuttx/lib/stdlib/lib_llabs.c | 57 - nuttx/lib/stdlib/lib_qsort.c | 238 --- nuttx/lib/stdlib/lib_rand.c | 220 --- nuttx/lib/string/Make.defs | 50 - nuttx/lib/string/lib_checkbase.c | 115 -- nuttx/lib/string/lib_isbasedigit.c | 105 -- nuttx/lib/string/lib_memccpy.c | 99 -- nuttx/lib/string/lib_memchr.c | 80 - nuttx/lib/string/lib_memcmp.c | 74 - nuttx/lib/string/lib_memcpy.c | 64 - nuttx/lib/string/lib_memmove.c | 72 - nuttx/lib/string/lib_memset.c | 59 - nuttx/lib/string/lib_skipspace.c | 69 - nuttx/lib/string/lib_strcasecmp.c | 65 - nuttx/lib/string/lib_strcasestr.c | 134 -- nuttx/lib/string/lib_strcat.c | 62 - nuttx/lib/string/lib_strchr.c | 76 - nuttx/lib/string/lib_strcmp.c | 59 - nuttx/lib/string/lib_strcpy.c | 55 - nuttx/lib/string/lib_strcspn.c | 67 - nuttx/lib/string/lib_strdup.c | 62 - nuttx/lib/string/lib_strerror.c | 375 ----- nuttx/lib/string/lib_strlen.c | 55 - nuttx/lib/string/lib_strncasecmp.c | 70 - nuttx/lib/string/lib_strncat.c | 62 - nuttx/lib/string/lib_strncmp.c | 65 - nuttx/lib/string/lib_strncpy.c | 57 - nuttx/lib/string/lib_strndup.c | 93 -- nuttx/lib/string/lib_strnlen.c | 62 - nuttx/lib/string/lib_strpbrk.c | 85 - nuttx/lib/string/lib_strrchr.c | 68 - nuttx/lib/string/lib_strspn.c | 66 - nuttx/lib/string/lib_strstr.c | 104 -- nuttx/lib/string/lib_strtod.c | 241 --- nuttx/lib/string/lib_strtok.c | 87 -- nuttx/lib/string/lib_strtokr.c | 157 -- nuttx/lib/string/lib_strtol.c | 103 -- nuttx/lib/string/lib_strtoll.c | 107 -- nuttx/lib/string/lib_strtoul.c | 98 -- nuttx/lib/string/lib_strtoull.c | 100 -- nuttx/lib/termios/Make.defs | 54 - nuttx/lib/termios/lib_cfgetspeed.c | 93 -- nuttx/lib/termios/lib_cfsetspeed.c | 121 -- nuttx/lib/termios/lib_tcflush.c | 88 -- nuttx/lib/termios/lib_tcgetattr.c | 93 -- nuttx/lib/termios/lib_tcsetattr.c | 122 -- nuttx/lib/time/Make.defs | 44 - nuttx/lib/time/lib_calendar2utc.c | 209 --- nuttx/lib/time/lib_daysbeforemonth.c | 102 -- nuttx/lib/time/lib_gmtime.c | 93 -- nuttx/lib/time/lib_gmtimer.c | 355 ----- nuttx/lib/time/lib_isleapyear.c | 88 -- nuttx/lib/time/lib_mktime.c | 141 -- nuttx/lib/time/lib_strftime.c | 398 ----- nuttx/lib/time/lib_time.c | 110 -- nuttx/lib/unistd/Make.defs | 49 - nuttx/lib/unistd/lib_chdir.c | 179 --- nuttx/lib/unistd/lib_getcwd.c | 132 -- nuttx/lib/unistd/lib_getopt.c | 269 ---- nuttx/lib/unistd/lib_getoptargp.c | 73 - nuttx/lib/unistd/lib_getoptindp.c | 73 - nuttx/lib/unistd/lib_getoptoptp.c | 73 - nuttx/libc/Kconfig | 275 ++++ nuttx/libc/Makefile | 145 ++ nuttx/libc/README.txt | 85 + nuttx/libc/dirent/Make.defs | 48 + nuttx/libc/dirent/lib_readdirr.c | 122 ++ nuttx/libc/dirent/lib_telldir.c | 91 ++ nuttx/libc/fixedmath/Make.defs | 43 + nuttx/libc/fixedmath/lib_b16atan2.c | 108 ++ nuttx/libc/fixedmath/lib_b16cos.c | 64 + nuttx/libc/fixedmath/lib_b16sin.c | 110 ++ nuttx/libc/fixedmath/lib_fixedmath.c | 272 ++++ nuttx/libc/fixedmath/lib_rint.c | 135 ++ nuttx/libc/lib.csv | 171 ++ nuttx/libc/lib_internal.h | 211 +++ nuttx/libc/libgen/Make.defs | 43 + nuttx/libc/libgen/lib_basename.c | 131 ++ nuttx/libc/libgen/lib_dirname.c | 144 ++ nuttx/libc/math/Kconfig | 26 + nuttx/libc/math/lib_acos.c | 46 + nuttx/libc/math/lib_acosf.c | 41 + nuttx/libc/math/lib_acosl.c | 46 + nuttx/libc/math/lib_asin.c | 69 + nuttx/libc/math/lib_asinf.c | 65 + nuttx/libc/math/lib_asinl.c | 69 + nuttx/libc/math/lib_atan.c | 48 + nuttx/libc/math/lib_atan2.c | 86 + nuttx/libc/math/lib_atan2f.c | 81 + nuttx/libc/math/lib_atan2l.c | 87 ++ nuttx/libc/math/lib_atanf.c | 43 + nuttx/libc/math/lib_atanl.c | 48 + nuttx/libc/math/lib_ceil.c | 52 + nuttx/libc/math/lib_ceilf.c | 47 + nuttx/libc/math/lib_ceill.c | 52 + nuttx/libc/math/lib_cos.c | 46 + nuttx/libc/math/lib_cosf.c | 41 + nuttx/libc/math/lib_cosh.c | 47 + nuttx/libc/math/lib_coshf.c | 42 + nuttx/libc/math/lib_coshl.c | 47 + nuttx/libc/math/lib_cosl.c | 46 + nuttx/libc/math/lib_exp.c | 126 ++ nuttx/libc/math/lib_expf.c | 112 ++ nuttx/libc/math/lib_expl.c | 126 ++ nuttx/libc/math/lib_fabs.c | 46 + nuttx/libc/math/lib_fabsf.c | 41 + nuttx/libc/math/lib_fabsl.c | 46 + nuttx/libc/math/lib_floor.c | 52 + nuttx/libc/math/lib_floorf.c | 47 + nuttx/libc/math/lib_floorl.c | 52 + nuttx/libc/math/lib_fmod.c | 52 + nuttx/libc/math/lib_fmodf.c | 47 + nuttx/libc/math/lib_fmodl.c | 52 + nuttx/libc/math/lib_frexp.c | 47 + nuttx/libc/math/lib_frexpf.c | 42 + nuttx/libc/math/lib_frexpl.c | 47 + nuttx/libc/math/lib_ldexp.c | 46 + nuttx/libc/math/lib_ldexpf.c | 41 + nuttx/libc/math/lib_ldexpl.c | 46 + nuttx/libc/math/lib_libexpi.c | 103 ++ nuttx/libc/math/lib_libsqrtapprox.c | 50 + nuttx/libc/math/lib_log.c | 82 + nuttx/libc/math/lib_log10.c | 46 + nuttx/libc/math/lib_log10f.c | 41 + nuttx/libc/math/lib_log10l.c | 46 + nuttx/libc/math/lib_log2.c | 46 + nuttx/libc/math/lib_log2f.c | 41 + nuttx/libc/math/lib_log2l.c | 46 + nuttx/libc/math/lib_logf.c | 77 + nuttx/libc/math/lib_logl.c | 80 + nuttx/libc/math/lib_modf.c | 58 + nuttx/libc/math/lib_modff.c | 55 + nuttx/libc/math/lib_modfl.c | 61 + nuttx/libc/math/lib_pow.c | 46 + nuttx/libc/math/lib_powf.c | 41 + nuttx/libc/math/lib_powl.c | 46 + nuttx/libc/math/lib_sin.c | 114 ++ nuttx/libc/math/lib_sinf.c | 104 ++ nuttx/libc/math/lib_sinh.c | 47 + nuttx/libc/math/lib_sinhf.c | 42 + nuttx/libc/math/lib_sinhl.c | 47 + nuttx/libc/math/lib_sinl.c | 114 ++ nuttx/libc/math/lib_sqrt.c | 99 ++ nuttx/libc/math/lib_sqrtf.c | 84 + nuttx/libc/math/lib_sqrtl.c | 101 ++ nuttx/libc/math/lib_tan.c | 46 + nuttx/libc/math/lib_tanf.c | 41 + nuttx/libc/math/lib_tanh.c | 49 + nuttx/libc/math/lib_tanhf.c | 44 + nuttx/libc/math/lib_tanhl.c | 49 + nuttx/libc/math/lib_tanl.c | 46 + nuttx/libc/misc/Make.defs | 69 + nuttx/libc/misc/lib_crc32.c | 123 ++ nuttx/libc/misc/lib_dbg.c | 165 ++ nuttx/libc/misc/lib_dumpbuffer.c | 129 ++ nuttx/libc/misc/lib_filesem.c | 145 ++ nuttx/libc/misc/lib_init.c | 207 +++ nuttx/libc/misc/lib_match.c | 148 ++ nuttx/libc/misc/lib_sendfile.c | 297 ++++ nuttx/libc/misc/lib_streamsem.c | 90 ++ nuttx/libc/mqueue/Make.defs | 48 + nuttx/libc/mqueue/mq_getattr.c | 104 ++ nuttx/libc/mqueue/mq_setattr.c | 118 ++ nuttx/libc/net/Make.defs | 44 + nuttx/libc/net/lib_etherntoa.c | 69 + nuttx/libc/net/lib_htonl.c | 68 + nuttx/libc/net/lib_htons.c | 65 + nuttx/libc/net/lib_inetaddr.c | 74 + nuttx/libc/net/lib_inetntoa.c | 79 + nuttx/libc/net/lib_inetntop.c | 202 +++ nuttx/libc/net/lib_inetpton.c | 338 ++++ nuttx/libc/pthread/Make.defs | 56 + nuttx/libc/pthread/pthread_attrdestroy.c | 108 ++ nuttx/libc/pthread/pthread_attrgetinheritsched.c | 111 ++ nuttx/libc/pthread/pthread_attrgetschedparam.c | 110 ++ nuttx/libc/pthread/pthread_attrgetschedpolicy.c | 105 ++ nuttx/libc/pthread/pthread_attrgetstacksize.c | 106 ++ nuttx/libc/pthread/pthread_attrinit.c | 123 ++ nuttx/libc/pthread/pthread_attrsetinheritsched.c | 113 ++ nuttx/libc/pthread/pthread_attrsetschedparam.c | 108 ++ nuttx/libc/pthread/pthread_attrsetschedpolicy.c | 111 ++ nuttx/libc/pthread/pthread_attrsetstacksize.c | 106 ++ nuttx/libc/pthread/pthread_barrierattrdestroy.c | 102 ++ nuttx/libc/pthread/pthread_barrierattrgetpshared.c | 101 ++ nuttx/libc/pthread/pthread_barrierattrinit.c | 101 ++ nuttx/libc/pthread/pthread_barrierattrsetpshared.c | 111 ++ nuttx/libc/pthread/pthread_condattrdestroy.c | 82 + nuttx/libc/pthread/pthread_condattrinit.c | 85 + nuttx/libc/pthread/pthread_mutexattrdestroy.c | 104 ++ nuttx/libc/pthread/pthread_mutexattrgetpshared.c | 104 ++ nuttx/libc/pthread/pthread_mutexattrgettype.c | 98 ++ nuttx/libc/pthread/pthread_mutexattrinit.c | 106 ++ nuttx/libc/pthread/pthread_mutexattrsetpshared.c | 104 ++ nuttx/libc/pthread/pthread_mutexattrsettype.c | 98 ++ nuttx/libc/queue/Make.defs | 47 + nuttx/libc/queue/dq_addafter.c | 74 + nuttx/libc/queue/dq_addbefore.c | 69 + nuttx/libc/queue/dq_addfirst.c | 74 + nuttx/libc/queue/dq_addlast.c | 74 + nuttx/libc/queue/dq_rem.c | 84 + nuttx/libc/queue/dq_remfirst.c | 82 + nuttx/libc/queue/dq_remlast.c | 78 + nuttx/libc/queue/sq_addafter.c | 71 + nuttx/libc/queue/sq_addfirst.c | 67 + nuttx/libc/queue/sq_addlast.c | 72 + nuttx/libc/queue/sq_rem.c | 83 + nuttx/libc/queue/sq_remafter.c | 79 + nuttx/libc/queue/sq_remfirst.c | 76 + nuttx/libc/queue/sq_remlast.c | 87 ++ nuttx/libc/sched/Make.defs | 43 + nuttx/libc/sched/sched_getprioritymax.c | 100 ++ nuttx/libc/sched/sched_getprioritymin.c | 100 ++ nuttx/libc/semaphore/Make.defs | 43 + nuttx/libc/semaphore/sem_getvalue.c | 108 ++ nuttx/libc/semaphore/sem_init.c | 125 ++ nuttx/libc/signal/Make.defs | 47 + nuttx/libc/signal/sig_addset.c | 100 ++ nuttx/libc/signal/sig_delset.c | 100 ++ nuttx/libc/signal/sig_emptyset.c | 88 ++ nuttx/libc/signal/sig_fillset.c | 88 ++ nuttx/libc/signal/sig_ismember.c | 101 ++ nuttx/libc/stdio/Make.defs | 85 + nuttx/libc/stdio/lib_asprintf.c | 105 ++ nuttx/libc/stdio/lib_avsprintf.c | 146 ++ nuttx/libc/stdio/lib_clearerr.c | 69 + nuttx/libc/stdio/lib_dtoa.c | 1641 ++++++++++++++++++++ nuttx/libc/stdio/lib_fclose.c | 154 ++ nuttx/libc/stdio/lib_feof.c | 77 + nuttx/libc/stdio/lib_ferror.c | 90 ++ nuttx/libc/stdio/lib_fflush.c | 132 ++ nuttx/libc/stdio/lib_fgetc.c | 101 ++ nuttx/libc/stdio/lib_fgetpos.c | 123 ++ nuttx/libc/stdio/lib_fgets.c | 207 +++ nuttx/libc/stdio/lib_fileno.c | 70 + nuttx/libc/stdio/lib_fopen.c | 299 ++++ nuttx/libc/stdio/lib_fprintf.c | 93 ++ nuttx/libc/stdio/lib_fputc.c | 113 ++ nuttx/libc/stdio/lib_fputs.c | 220 +++ nuttx/libc/stdio/lib_fread.c | 101 ++ nuttx/libc/stdio/lib_fseek.c | 138 ++ nuttx/libc/stdio/lib_fsetpos.c | 116 ++ nuttx/libc/stdio/lib_ftell.c | 129 ++ nuttx/libc/stdio/lib_fwrite.c | 99 ++ nuttx/libc/stdio/lib_gets.c | 120 ++ nuttx/libc/stdio/lib_libdtoa.c | 304 ++++ nuttx/libc/stdio/lib_libfflush.c | 202 +++ nuttx/libc/stdio/lib_libflushall.c | 137 ++ nuttx/libc/stdio/lib_libfread.c | 315 ++++ nuttx/libc/stdio/lib_libfwrite.c | 179 +++ nuttx/libc/stdio/lib_libnoflush.c | 103 ++ nuttx/libc/stdio/lib_libsprintf.c | 90 ++ nuttx/libc/stdio/lib_libvsprintf.c | 1620 +++++++++++++++++++ nuttx/libc/stdio/lib_lowinstream.c | 102 ++ nuttx/libc/stdio/lib_lowoutstream.c | 97 ++ nuttx/libc/stdio/lib_lowprintf.c | 128 ++ nuttx/libc/stdio/lib_meminstream.c | 104 ++ nuttx/libc/stdio/lib_memoutstream.c | 105 ++ nuttx/libc/stdio/lib_nullinstream.c | 79 + nuttx/libc/stdio/lib_nulloutstream.c | 84 + nuttx/libc/stdio/lib_perror.c | 99 ++ nuttx/libc/stdio/lib_printf.c | 109 ++ nuttx/libc/stdio/lib_puts.c | 130 ++ nuttx/libc/stdio/lib_rawinstream.c | 107 ++ nuttx/libc/stdio/lib_rawoutstream.c | 115 ++ nuttx/libc/stdio/lib_rawprintf.c | 151 ++ nuttx/libc/stdio/lib_rdflush.c | 144 ++ nuttx/libc/stdio/lib_snprintf.c | 99 ++ nuttx/libc/stdio/lib_sprintf.c | 95 ++ nuttx/libc/stdio/lib_sscanf.c | 507 ++++++ nuttx/libc/stdio/lib_stdinstream.c | 99 ++ nuttx/libc/stdio/lib_stdoutstream.c | 147 ++ nuttx/libc/stdio/lib_syslogstream.c | 122 ++ nuttx/libc/stdio/lib_ungetc.c | 121 ++ nuttx/libc/stdio/lib_vfprintf.c | 102 ++ nuttx/libc/stdio/lib_vprintf.c | 92 ++ nuttx/libc/stdio/lib_vsnprintf.c | 96 ++ nuttx/libc/stdio/lib_vsprintf.c | 92 ++ nuttx/libc/stdio/lib_wrflush.c | 134 ++ nuttx/libc/stdio/lib_zeroinstream.c | 79 + nuttx/libc/stdlib/Make.defs | 44 + nuttx/libc/stdlib/lib_abort.c | 121 ++ nuttx/libc/stdlib/lib_abs.c | 54 + nuttx/libc/stdlib/lib_imaxabs.c | 54 + nuttx/libc/stdlib/lib_labs.c | 54 + nuttx/libc/stdlib/lib_llabs.c | 57 + nuttx/libc/stdlib/lib_qsort.c | 238 +++ nuttx/libc/string/Make.defs | 58 + nuttx/libc/string/lib_checkbase.c | 115 ++ nuttx/libc/string/lib_isbasedigit.c | 105 ++ nuttx/libc/string/lib_memccpy.c | 99 ++ nuttx/libc/string/lib_memchr.c | 80 + nuttx/libc/string/lib_memcpy.c | 64 + nuttx/libc/string/lib_memset.c | 188 +++ nuttx/libc/string/lib_skipspace.c | 69 + nuttx/libc/string/lib_strcasecmp.c | 65 + nuttx/libc/string/lib_strcat.c | 62 + nuttx/libc/string/lib_strchr.c | 78 + nuttx/libc/string/lib_strcmp.c | 59 + nuttx/libc/string/lib_strcpy.c | 55 + nuttx/libc/string/lib_strcspn.c | 67 + nuttx/libc/string/lib_strdup.c | 62 + nuttx/libc/string/lib_strerror.c | 375 +++++ nuttx/libc/string/lib_strlen.c | 55 + nuttx/libc/string/lib_strncasecmp.c | 70 + nuttx/libc/string/lib_strncat.c | 62 + nuttx/libc/string/lib_strncmp.c | 65 + nuttx/libc/string/lib_strncpy.c | 57 + nuttx/libc/string/lib_strndup.c | 93 ++ nuttx/libc/string/lib_strnlen.c | 62 + nuttx/libc/string/lib_strpbrk.c | 85 + nuttx/libc/string/lib_strrchr.c | 68 + nuttx/libc/string/lib_strspn.c | 66 + nuttx/libc/string/lib_strtod.c | 241 +++ nuttx/libc/string/lib_strtok.c | 87 ++ nuttx/libc/string/lib_strtokr.c | 157 ++ nuttx/libc/string/lib_strtol.c | 103 ++ nuttx/libc/string/lib_strtoll.c | 107 ++ nuttx/libc/string/lib_strtoul.c | 98 ++ nuttx/libc/string/lib_strtoull.c | 100 ++ nuttx/libc/string/lib_vikmemcpy.c | 348 +++++ nuttx/libc/termios/Make.defs | 54 + nuttx/libc/termios/lib_cfgetspeed.c | 93 ++ nuttx/libc/termios/lib_cfsetspeed.c | 116 ++ nuttx/libc/termios/lib_tcflush.c | 88 ++ nuttx/libc/termios/lib_tcgetattr.c | 93 ++ nuttx/libc/termios/lib_tcsetattr.c | 122 ++ nuttx/libc/time/Make.defs | 44 + nuttx/libc/time/lib_calendar2utc.c | 209 +++ nuttx/libc/time/lib_daysbeforemonth.c | 102 ++ nuttx/libc/time/lib_gmtime.c | 93 ++ nuttx/libc/time/lib_gmtimer.c | 355 +++++ nuttx/libc/time/lib_isleapyear.c | 88 ++ nuttx/libc/time/lib_mktime.c | 141 ++ nuttx/libc/time/lib_strftime.c | 398 +++++ nuttx/libc/time/lib_time.c | 110 ++ nuttx/libc/unistd/Make.defs | 49 + nuttx/libc/unistd/lib_chdir.c | 179 +++ nuttx/libc/unistd/lib_getcwd.c | 132 ++ nuttx/libc/unistd/lib_getopt.c | 269 ++++ nuttx/libc/unistd/lib_getoptargp.c | 73 + nuttx/libc/unistd/lib_getoptindp.c | 73 + nuttx/libc/unistd/lib_getoptoptp.c | 73 + nuttx/libxx/Makefile | 73 +- nuttx/libxx/README.txt | 5 + nuttx/libxx/libxx_cxa_atexit.cxx | 146 ++ nuttx/libxx/libxx_eabi_atexit.cxx | 23 +- nuttx/libxx/libxx_internal.hxx | 67 + nuttx/libxx/libxx_stdthrow.cxx | 74 + nuttx/mm/Makefile | 17 +- nuttx/mm/Makefile.test | 18 +- nuttx/mm/mm_initialize.c | 6 +- nuttx/net/Makefile | 14 +- nuttx/net/netdev_ioctl.c | 151 +- nuttx/net/uip/uip_icmpping.c | 2 + nuttx/sched/Kconfig | 11 +- nuttx/sched/Makefile | 16 +- nuttx/sched/atexit.c | 16 +- nuttx/sched/mq_open.c | 3 +- nuttx/sched/on_exit.c | 5 +- nuttx/sched/pause.c | 110 ++ nuttx/sched/sched_getscheduler.c | 1 + nuttx/sched/sem_open.c | 3 +- nuttx/sched/sleep.c | 2 +- nuttx/sched/task_exithook.c | 4 +- nuttx/sched/usleep.c | 2 +- nuttx/tools/Makefile.export | 4 +- nuttx/tools/configure.sh | 92 +- nuttx/tools/define.bat | 178 +++ nuttx/tools/define.sh | 8 +- nuttx/tools/incdir.sh | 3 + nuttx/tools/mkconfig.c | 2 +- nuttx/tools/mkdeps.bat | 173 +++ nuttx/tools/mkdeps.c | 721 +++++++++ nuttx/tools/mkdeps.sh | 2 +- nuttx/tools/mkromfsimg.sh | 2 +- nuttx/tools/mksymtab.c | 2 +- 635 files changed, 40029 insertions(+), 29985 deletions(-) create mode 100644 nuttx/arch/arm/include/elf.h create mode 100644 nuttx/arch/arm/src/armv7-m/Kconfig delete mode 100644 nuttx/arch/arm/src/armv7-m/memcpy.S create mode 100644 nuttx/arch/arm/src/armv7-m/up_elf.c create mode 100644 nuttx/arch/arm/src/armv7-m/up_memcpy.S create mode 100644 nuttx/arch/arm/src/common/arm-elf.h create mode 100644 nuttx/drivers/input/max11802.c create mode 100644 nuttx/drivers/input/max11802.h create mode 100644 nuttx/include/elf32.h delete mode 100644 nuttx/include/nuttx/binfmt.h create mode 100644 nuttx/include/nuttx/binfmt/symtab.h create mode 100644 nuttx/include/nuttx/float.h create mode 100644 nuttx/include/nuttx/input/max11802.h create mode 100644 nuttx/include/nuttx/lcd/ug-2864ambag01.h delete mode 100644 nuttx/include/nuttx/nxflat.h delete mode 100644 nuttx/include/nuttx/symtab.h delete mode 100644 nuttx/lib/Kconfig delete mode 100644 nuttx/lib/dirent/Make.defs delete mode 100644 nuttx/lib/dirent/lib_readdirr.c delete mode 100644 nuttx/lib/dirent/lib_telldir.c delete mode 100644 nuttx/lib/lib.csv delete mode 100644 nuttx/lib/lib_internal.h delete mode 100644 nuttx/lib/libgen/Make.defs delete mode 100644 nuttx/lib/libgen/lib_basename.c delete mode 100644 nuttx/lib/libgen/lib_dirname.c delete mode 100644 nuttx/lib/math/Make.defs delete mode 100644 nuttx/lib/math/lib_b16atan2.c delete mode 100644 nuttx/lib/math/lib_b16cos.c delete mode 100644 nuttx/lib/math/lib_b16sin.c delete mode 100644 nuttx/lib/math/lib_fixedmath.c delete mode 100644 nuttx/lib/math/lib_rint.c delete mode 100644 nuttx/lib/misc/Make.defs delete mode 100644 nuttx/lib/misc/lib_crc32.c delete mode 100644 nuttx/lib/misc/lib_dbg.c delete mode 100644 nuttx/lib/misc/lib_dumpbuffer.c delete mode 100644 nuttx/lib/misc/lib_filesem.c delete mode 100644 nuttx/lib/misc/lib_init.c delete mode 100644 nuttx/lib/misc/lib_match.c delete mode 100644 nuttx/lib/misc/lib_sendfile.c delete mode 100644 nuttx/lib/misc/lib_streamsem.c delete mode 100644 nuttx/lib/mqueue/Make.defs delete mode 100644 nuttx/lib/mqueue/mq_getattr.c delete mode 100644 nuttx/lib/mqueue/mq_setattr.c delete mode 100644 nuttx/lib/net/Make.defs delete mode 100644 nuttx/lib/net/lib_etherntoa.c delete mode 100644 nuttx/lib/net/lib_htonl.c delete mode 100644 nuttx/lib/net/lib_htons.c delete mode 100644 nuttx/lib/net/lib_inetaddr.c delete mode 100644 nuttx/lib/net/lib_inetntoa.c delete mode 100644 nuttx/lib/net/lib_inetntop.c delete mode 100644 nuttx/lib/net/lib_inetpton.c delete mode 100644 nuttx/lib/pthread/Make.defs delete mode 100644 nuttx/lib/pthread/pthread_attrdestroy.c delete mode 100644 nuttx/lib/pthread/pthread_attrgetinheritsched.c delete mode 100644 nuttx/lib/pthread/pthread_attrgetschedparam.c delete mode 100644 nuttx/lib/pthread/pthread_attrgetschedpolicy.c delete mode 100644 nuttx/lib/pthread/pthread_attrgetstacksize.c delete mode 100644 nuttx/lib/pthread/pthread_attrinit.c delete mode 100644 nuttx/lib/pthread/pthread_attrsetinheritsched.c delete mode 100644 nuttx/lib/pthread/pthread_attrsetschedparam.c delete mode 100644 nuttx/lib/pthread/pthread_attrsetschedpolicy.c delete mode 100644 nuttx/lib/pthread/pthread_attrsetstacksize.c delete mode 100644 nuttx/lib/pthread/pthread_barrierattrdestroy.c delete mode 100644 nuttx/lib/pthread/pthread_barrierattrgetpshared.c delete mode 100644 nuttx/lib/pthread/pthread_barrierattrinit.c delete mode 100644 nuttx/lib/pthread/pthread_barrierattrsetpshared.c delete mode 100644 nuttx/lib/pthread/pthread_condattrdestroy.c delete mode 100644 nuttx/lib/pthread/pthread_condattrinit.c delete mode 100644 nuttx/lib/pthread/pthread_mutexattrdestroy.c delete mode 100644 nuttx/lib/pthread/pthread_mutexattrgetpshared.c delete mode 100644 nuttx/lib/pthread/pthread_mutexattrgettype.c delete mode 100644 nuttx/lib/pthread/pthread_mutexattrinit.c delete mode 100644 nuttx/lib/pthread/pthread_mutexattrsetpshared.c delete mode 100644 nuttx/lib/pthread/pthread_mutexattrsettype.c delete mode 100644 nuttx/lib/queue/Make.defs delete mode 100644 nuttx/lib/queue/dq_addafter.c delete mode 100644 nuttx/lib/queue/dq_addbefore.c delete mode 100644 nuttx/lib/queue/dq_addfirst.c delete mode 100644 nuttx/lib/queue/dq_addlast.c delete mode 100644 nuttx/lib/queue/dq_rem.c delete mode 100644 nuttx/lib/queue/dq_remfirst.c delete mode 100644 nuttx/lib/queue/dq_remlast.c delete mode 100644 nuttx/lib/queue/sq_addafter.c delete mode 100644 nuttx/lib/queue/sq_addfirst.c delete mode 100644 nuttx/lib/queue/sq_addlast.c delete mode 100644 nuttx/lib/queue/sq_rem.c delete mode 100644 nuttx/lib/queue/sq_remafter.c delete mode 100644 nuttx/lib/queue/sq_remfirst.c delete mode 100644 nuttx/lib/queue/sq_remlast.c delete mode 100644 nuttx/lib/sched/Make.defs delete mode 100644 nuttx/lib/sched/sched_getprioritymax.c delete mode 100644 nuttx/lib/sched/sched_getprioritymin.c delete mode 100644 nuttx/lib/semaphore/Make.defs delete mode 100644 nuttx/lib/semaphore/sem_getvalue.c delete mode 100644 nuttx/lib/semaphore/sem_init.c delete mode 100644 nuttx/lib/signal/Make.defs delete mode 100644 nuttx/lib/signal/sig_addset.c delete mode 100644 nuttx/lib/signal/sig_delset.c delete mode 100644 nuttx/lib/signal/sig_emptyset.c delete mode 100644 nuttx/lib/signal/sig_fillset.c delete mode 100644 nuttx/lib/signal/sig_ismember.c delete mode 100644 nuttx/lib/stdio/Make.defs delete mode 100644 nuttx/lib/stdio/lib_asprintf.c delete mode 100644 nuttx/lib/stdio/lib_avsprintf.c delete mode 100644 nuttx/lib/stdio/lib_dtoa.c delete mode 100644 nuttx/lib/stdio/lib_fclose.c delete mode 100644 nuttx/lib/stdio/lib_fflush.c delete mode 100644 nuttx/lib/stdio/lib_fgetc.c delete mode 100644 nuttx/lib/stdio/lib_fgetpos.c delete mode 100644 nuttx/lib/stdio/lib_fgets.c delete mode 100644 nuttx/lib/stdio/lib_fileno.c delete mode 100644 nuttx/lib/stdio/lib_fopen.c delete mode 100644 nuttx/lib/stdio/lib_fprintf.c delete mode 100644 nuttx/lib/stdio/lib_fputc.c delete mode 100644 nuttx/lib/stdio/lib_fputs.c delete mode 100644 nuttx/lib/stdio/lib_fread.c delete mode 100644 nuttx/lib/stdio/lib_fseek.c delete mode 100644 nuttx/lib/stdio/lib_fsetpos.c delete mode 100644 nuttx/lib/stdio/lib_ftell.c delete mode 100644 nuttx/lib/stdio/lib_fwrite.c delete mode 100644 nuttx/lib/stdio/lib_gets.c delete mode 100644 nuttx/lib/stdio/lib_libdtoa.c delete mode 100644 nuttx/lib/stdio/lib_libfflush.c delete mode 100644 nuttx/lib/stdio/lib_libflushall.c delete mode 100644 nuttx/lib/stdio/lib_libfread.c delete mode 100644 nuttx/lib/stdio/lib_libfwrite.c delete mode 100644 nuttx/lib/stdio/lib_libnoflush.c delete mode 100644 nuttx/lib/stdio/lib_libsprintf.c delete mode 100644 nuttx/lib/stdio/lib_libvsprintf.c delete mode 100644 nuttx/lib/stdio/lib_lowinstream.c delete mode 100644 nuttx/lib/stdio/lib_lowoutstream.c delete mode 100644 nuttx/lib/stdio/lib_lowprintf.c delete mode 100644 nuttx/lib/stdio/lib_meminstream.c delete mode 100644 nuttx/lib/stdio/lib_memoutstream.c delete mode 100644 nuttx/lib/stdio/lib_nullinstream.c delete mode 100644 nuttx/lib/stdio/lib_nulloutstream.c delete mode 100644 nuttx/lib/stdio/lib_perror.c delete mode 100644 nuttx/lib/stdio/lib_printf.c delete mode 100644 nuttx/lib/stdio/lib_puts.c delete mode 100644 nuttx/lib/stdio/lib_rawinstream.c delete mode 100644 nuttx/lib/stdio/lib_rawoutstream.c delete mode 100644 nuttx/lib/stdio/lib_rawprintf.c delete mode 100644 nuttx/lib/stdio/lib_rdflush.c delete mode 100644 nuttx/lib/stdio/lib_snprintf.c delete mode 100644 nuttx/lib/stdio/lib_sprintf.c delete mode 100644 nuttx/lib/stdio/lib_sscanf.c delete mode 100644 nuttx/lib/stdio/lib_stdinstream.c delete mode 100644 nuttx/lib/stdio/lib_stdoutstream.c delete mode 100644 nuttx/lib/stdio/lib_syslogstream.c delete mode 100644 nuttx/lib/stdio/lib_ungetc.c delete mode 100644 nuttx/lib/stdio/lib_vdprintf.c delete mode 100644 nuttx/lib/stdio/lib_vfprintf.c delete mode 100644 nuttx/lib/stdio/lib_vprintf.c delete mode 100644 nuttx/lib/stdio/lib_vsnprintf.c delete mode 100644 nuttx/lib/stdio/lib_vsprintf.c delete mode 100644 nuttx/lib/stdio/lib_wrflush.c delete mode 100644 nuttx/lib/stdio/lib_zeroinstream.c delete mode 100644 nuttx/lib/stdlib/Make.defs delete mode 100644 nuttx/lib/stdlib/lib_abort.c delete mode 100644 nuttx/lib/stdlib/lib_abs.c delete mode 100644 nuttx/lib/stdlib/lib_imaxabs.c delete mode 100644 nuttx/lib/stdlib/lib_labs.c delete mode 100644 nuttx/lib/stdlib/lib_llabs.c delete mode 100644 nuttx/lib/stdlib/lib_qsort.c delete mode 100644 nuttx/lib/stdlib/lib_rand.c delete mode 100644 nuttx/lib/string/Make.defs delete mode 100644 nuttx/lib/string/lib_checkbase.c delete mode 100644 nuttx/lib/string/lib_isbasedigit.c delete mode 100644 nuttx/lib/string/lib_memccpy.c delete mode 100644 nuttx/lib/string/lib_memchr.c delete mode 100644 nuttx/lib/string/lib_memcmp.c delete mode 100644 nuttx/lib/string/lib_memcpy.c delete mode 100644 nuttx/lib/string/lib_memmove.c delete mode 100644 nuttx/lib/string/lib_memset.c delete mode 100644 nuttx/lib/string/lib_skipspace.c delete mode 100644 nuttx/lib/string/lib_strcasecmp.c delete mode 100644 nuttx/lib/string/lib_strcasestr.c delete mode 100644 nuttx/lib/string/lib_strcat.c delete mode 100644 nuttx/lib/string/lib_strchr.c delete mode 100644 nuttx/lib/string/lib_strcmp.c delete mode 100644 nuttx/lib/string/lib_strcpy.c delete mode 100644 nuttx/lib/string/lib_strcspn.c delete mode 100644 nuttx/lib/string/lib_strdup.c delete mode 100644 nuttx/lib/string/lib_strerror.c delete mode 100644 nuttx/lib/string/lib_strlen.c delete mode 100644 nuttx/lib/string/lib_strncasecmp.c delete mode 100644 nuttx/lib/string/lib_strncat.c delete mode 100644 nuttx/lib/string/lib_strncmp.c delete mode 100644 nuttx/lib/string/lib_strncpy.c delete mode 100644 nuttx/lib/string/lib_strndup.c delete mode 100644 nuttx/lib/string/lib_strnlen.c delete mode 100644 nuttx/lib/string/lib_strpbrk.c delete mode 100644 nuttx/lib/string/lib_strrchr.c delete mode 100644 nuttx/lib/string/lib_strspn.c delete mode 100644 nuttx/lib/string/lib_strstr.c delete mode 100644 nuttx/lib/string/lib_strtod.c delete mode 100644 nuttx/lib/string/lib_strtok.c delete mode 100644 nuttx/lib/string/lib_strtokr.c delete mode 100644 nuttx/lib/string/lib_strtol.c delete mode 100644 nuttx/lib/string/lib_strtoll.c delete mode 100644 nuttx/lib/string/lib_strtoul.c delete mode 100644 nuttx/lib/string/lib_strtoull.c delete mode 100644 nuttx/lib/termios/Make.defs delete mode 100644 nuttx/lib/termios/lib_cfgetspeed.c delete mode 100644 nuttx/lib/termios/lib_cfsetspeed.c delete mode 100644 nuttx/lib/termios/lib_tcflush.c delete mode 100644 nuttx/lib/termios/lib_tcgetattr.c delete mode 100644 nuttx/lib/termios/lib_tcsetattr.c delete mode 100644 nuttx/lib/time/Make.defs delete mode 100644 nuttx/lib/time/lib_calendar2utc.c delete mode 100644 nuttx/lib/time/lib_daysbeforemonth.c delete mode 100644 nuttx/lib/time/lib_gmtime.c delete mode 100644 nuttx/lib/time/lib_gmtimer.c delete mode 100644 nuttx/lib/time/lib_isleapyear.c delete mode 100644 nuttx/lib/time/lib_mktime.c delete mode 100644 nuttx/lib/time/lib_strftime.c delete mode 100644 nuttx/lib/time/lib_time.c delete mode 100644 nuttx/lib/unistd/Make.defs delete mode 100644 nuttx/lib/unistd/lib_chdir.c delete mode 100644 nuttx/lib/unistd/lib_getcwd.c delete mode 100644 nuttx/lib/unistd/lib_getopt.c delete mode 100644 nuttx/lib/unistd/lib_getoptargp.c delete mode 100644 nuttx/lib/unistd/lib_getoptindp.c delete mode 100644 nuttx/lib/unistd/lib_getoptoptp.c create mode 100644 nuttx/libc/Kconfig create mode 100644 nuttx/libc/Makefile create mode 100644 nuttx/libc/README.txt create mode 100644 nuttx/libc/dirent/Make.defs create mode 100644 nuttx/libc/dirent/lib_readdirr.c create mode 100644 nuttx/libc/dirent/lib_telldir.c create mode 100644 nuttx/libc/fixedmath/Make.defs create mode 100644 nuttx/libc/fixedmath/lib_b16atan2.c create mode 100644 nuttx/libc/fixedmath/lib_b16cos.c create mode 100644 nuttx/libc/fixedmath/lib_b16sin.c create mode 100644 nuttx/libc/fixedmath/lib_fixedmath.c create mode 100644 nuttx/libc/fixedmath/lib_rint.c create mode 100644 nuttx/libc/lib.csv create mode 100644 nuttx/libc/lib_internal.h create mode 100644 nuttx/libc/libgen/Make.defs create mode 100644 nuttx/libc/libgen/lib_basename.c create mode 100644 nuttx/libc/libgen/lib_dirname.c create mode 100644 nuttx/libc/math/Kconfig create mode 100644 nuttx/libc/math/lib_acos.c create mode 100644 nuttx/libc/math/lib_acosf.c create mode 100644 nuttx/libc/math/lib_acosl.c create mode 100644 nuttx/libc/math/lib_asin.c create mode 100644 nuttx/libc/math/lib_asinf.c create mode 100644 nuttx/libc/math/lib_asinl.c create mode 100644 nuttx/libc/math/lib_atan.c create mode 100644 nuttx/libc/math/lib_atan2.c create mode 100644 nuttx/libc/math/lib_atan2f.c create mode 100644 nuttx/libc/math/lib_atan2l.c create mode 100644 nuttx/libc/math/lib_atanf.c create mode 100644 nuttx/libc/math/lib_atanl.c create mode 100644 nuttx/libc/math/lib_ceil.c create mode 100644 nuttx/libc/math/lib_ceilf.c create mode 100644 nuttx/libc/math/lib_ceill.c create mode 100644 nuttx/libc/math/lib_cos.c create mode 100644 nuttx/libc/math/lib_cosf.c create mode 100644 nuttx/libc/math/lib_cosh.c create mode 100644 nuttx/libc/math/lib_coshf.c create mode 100644 nuttx/libc/math/lib_coshl.c create mode 100644 nuttx/libc/math/lib_cosl.c create mode 100644 nuttx/libc/math/lib_exp.c create mode 100644 nuttx/libc/math/lib_expf.c create mode 100644 nuttx/libc/math/lib_expl.c create mode 100644 nuttx/libc/math/lib_fabs.c create mode 100644 nuttx/libc/math/lib_fabsf.c create mode 100644 nuttx/libc/math/lib_fabsl.c create mode 100644 nuttx/libc/math/lib_floor.c create mode 100644 nuttx/libc/math/lib_floorf.c create mode 100644 nuttx/libc/math/lib_floorl.c create mode 100644 nuttx/libc/math/lib_fmod.c create mode 100644 nuttx/libc/math/lib_fmodf.c create mode 100644 nuttx/libc/math/lib_fmodl.c create mode 100644 nuttx/libc/math/lib_frexp.c create mode 100644 nuttx/libc/math/lib_frexpf.c create mode 100644 nuttx/libc/math/lib_frexpl.c create mode 100644 nuttx/libc/math/lib_ldexp.c create mode 100644 nuttx/libc/math/lib_ldexpf.c create mode 100644 nuttx/libc/math/lib_ldexpl.c create mode 100644 nuttx/libc/math/lib_libexpi.c create mode 100644 nuttx/libc/math/lib_libsqrtapprox.c create mode 100644 nuttx/libc/math/lib_log.c create mode 100644 nuttx/libc/math/lib_log10.c create mode 100644 nuttx/libc/math/lib_log10f.c create mode 100644 nuttx/libc/math/lib_log10l.c create mode 100644 nuttx/libc/math/lib_log2.c create mode 100644 nuttx/libc/math/lib_log2f.c create mode 100644 nuttx/libc/math/lib_log2l.c create mode 100644 nuttx/libc/math/lib_logf.c create mode 100644 nuttx/libc/math/lib_logl.c create mode 100644 nuttx/libc/math/lib_modf.c create mode 100644 nuttx/libc/math/lib_modff.c create mode 100644 nuttx/libc/math/lib_modfl.c create mode 100644 nuttx/libc/math/lib_pow.c create mode 100644 nuttx/libc/math/lib_powf.c create mode 100644 nuttx/libc/math/lib_powl.c create mode 100644 nuttx/libc/math/lib_sin.c create mode 100644 nuttx/libc/math/lib_sinf.c create mode 100644 nuttx/libc/math/lib_sinh.c create mode 100644 nuttx/libc/math/lib_sinhf.c create mode 100644 nuttx/libc/math/lib_sinhl.c create mode 100644 nuttx/libc/math/lib_sinl.c create mode 100644 nuttx/libc/math/lib_sqrt.c create mode 100644 nuttx/libc/math/lib_sqrtf.c create mode 100644 nuttx/libc/math/lib_sqrtl.c create mode 100644 nuttx/libc/math/lib_tan.c create mode 100644 nuttx/libc/math/lib_tanf.c create mode 100644 nuttx/libc/math/lib_tanh.c create mode 100644 nuttx/libc/math/lib_tanhf.c create mode 100644 nuttx/libc/math/lib_tanhl.c create mode 100644 nuttx/libc/math/lib_tanl.c create mode 100644 nuttx/libc/misc/Make.defs create mode 100644 nuttx/libc/misc/lib_crc32.c create mode 100644 nuttx/libc/misc/lib_dbg.c create mode 100644 nuttx/libc/misc/lib_dumpbuffer.c create mode 100644 nuttx/libc/misc/lib_filesem.c create mode 100644 nuttx/libc/misc/lib_init.c create mode 100644 nuttx/libc/misc/lib_match.c create mode 100644 nuttx/libc/misc/lib_sendfile.c create mode 100644 nuttx/libc/misc/lib_streamsem.c create mode 100644 nuttx/libc/mqueue/Make.defs create mode 100644 nuttx/libc/mqueue/mq_getattr.c create mode 100644 nuttx/libc/mqueue/mq_setattr.c create mode 100644 nuttx/libc/net/Make.defs create mode 100644 nuttx/libc/net/lib_etherntoa.c create mode 100644 nuttx/libc/net/lib_htonl.c create mode 100644 nuttx/libc/net/lib_htons.c create mode 100644 nuttx/libc/net/lib_inetaddr.c create mode 100644 nuttx/libc/net/lib_inetntoa.c create mode 100644 nuttx/libc/net/lib_inetntop.c create mode 100644 nuttx/libc/net/lib_inetpton.c create mode 100644 nuttx/libc/pthread/Make.defs create mode 100644 nuttx/libc/pthread/pthread_attrdestroy.c create mode 100644 nuttx/libc/pthread/pthread_attrgetinheritsched.c create mode 100644 nuttx/libc/pthread/pthread_attrgetschedparam.c create mode 100644 nuttx/libc/pthread/pthread_attrgetschedpolicy.c create mode 100644 nuttx/libc/pthread/pthread_attrgetstacksize.c create mode 100644 nuttx/libc/pthread/pthread_attrinit.c create mode 100644 nuttx/libc/pthread/pthread_attrsetinheritsched.c create mode 100644 nuttx/libc/pthread/pthread_attrsetschedparam.c create mode 100644 nuttx/libc/pthread/pthread_attrsetschedpolicy.c create mode 100644 nuttx/libc/pthread/pthread_attrsetstacksize.c create mode 100644 nuttx/libc/pthread/pthread_barrierattrdestroy.c create mode 100644 nuttx/libc/pthread/pthread_barrierattrgetpshared.c create mode 100644 nuttx/libc/pthread/pthread_barrierattrinit.c create mode 100644 nuttx/libc/pthread/pthread_barrierattrsetpshared.c create mode 100644 nuttx/libc/pthread/pthread_condattrdestroy.c create mode 100644 nuttx/libc/pthread/pthread_condattrinit.c create mode 100644 nuttx/libc/pthread/pthread_mutexattrdestroy.c create mode 100644 nuttx/libc/pthread/pthread_mutexattrgetpshared.c create mode 100644 nuttx/libc/pthread/pthread_mutexattrgettype.c create mode 100644 nuttx/libc/pthread/pthread_mutexattrinit.c create mode 100644 nuttx/libc/pthread/pthread_mutexattrsetpshared.c create mode 100644 nuttx/libc/pthread/pthread_mutexattrsettype.c create mode 100644 nuttx/libc/queue/Make.defs create mode 100644 nuttx/libc/queue/dq_addafter.c create mode 100644 nuttx/libc/queue/dq_addbefore.c create mode 100644 nuttx/libc/queue/dq_addfirst.c create mode 100644 nuttx/libc/queue/dq_addlast.c create mode 100644 nuttx/libc/queue/dq_rem.c create mode 100644 nuttx/libc/queue/dq_remfirst.c create mode 100644 nuttx/libc/queue/dq_remlast.c create mode 100644 nuttx/libc/queue/sq_addafter.c create mode 100644 nuttx/libc/queue/sq_addfirst.c create mode 100644 nuttx/libc/queue/sq_addlast.c create mode 100644 nuttx/libc/queue/sq_rem.c create mode 100644 nuttx/libc/queue/sq_remafter.c create mode 100644 nuttx/libc/queue/sq_remfirst.c create mode 100644 nuttx/libc/queue/sq_remlast.c create mode 100644 nuttx/libc/sched/Make.defs create mode 100644 nuttx/libc/sched/sched_getprioritymax.c create mode 100644 nuttx/libc/sched/sched_getprioritymin.c create mode 100644 nuttx/libc/semaphore/Make.defs create mode 100644 nuttx/libc/semaphore/sem_getvalue.c create mode 100644 nuttx/libc/semaphore/sem_init.c create mode 100644 nuttx/libc/signal/Make.defs create mode 100644 nuttx/libc/signal/sig_addset.c create mode 100644 nuttx/libc/signal/sig_delset.c create mode 100644 nuttx/libc/signal/sig_emptyset.c create mode 100644 nuttx/libc/signal/sig_fillset.c create mode 100644 nuttx/libc/signal/sig_ismember.c create mode 100644 nuttx/libc/stdio/Make.defs create mode 100644 nuttx/libc/stdio/lib_asprintf.c create mode 100644 nuttx/libc/stdio/lib_avsprintf.c create mode 100644 nuttx/libc/stdio/lib_clearerr.c create mode 100644 nuttx/libc/stdio/lib_dtoa.c create mode 100644 nuttx/libc/stdio/lib_fclose.c create mode 100644 nuttx/libc/stdio/lib_feof.c create mode 100644 nuttx/libc/stdio/lib_ferror.c create mode 100644 nuttx/libc/stdio/lib_fflush.c create mode 100644 nuttx/libc/stdio/lib_fgetc.c create mode 100644 nuttx/libc/stdio/lib_fgetpos.c create mode 100644 nuttx/libc/stdio/lib_fgets.c create mode 100644 nuttx/libc/stdio/lib_fileno.c create mode 100644 nuttx/libc/stdio/lib_fopen.c create mode 100644 nuttx/libc/stdio/lib_fprintf.c create mode 100644 nuttx/libc/stdio/lib_fputc.c create mode 100644 nuttx/libc/stdio/lib_fputs.c create mode 100644 nuttx/libc/stdio/lib_fread.c create mode 100644 nuttx/libc/stdio/lib_fseek.c create mode 100644 nuttx/libc/stdio/lib_fsetpos.c create mode 100644 nuttx/libc/stdio/lib_ftell.c create mode 100644 nuttx/libc/stdio/lib_fwrite.c create mode 100644 nuttx/libc/stdio/lib_gets.c create mode 100644 nuttx/libc/stdio/lib_libdtoa.c create mode 100644 nuttx/libc/stdio/lib_libfflush.c create mode 100644 nuttx/libc/stdio/lib_libflushall.c create mode 100644 nuttx/libc/stdio/lib_libfread.c create mode 100644 nuttx/libc/stdio/lib_libfwrite.c create mode 100644 nuttx/libc/stdio/lib_libnoflush.c create mode 100644 nuttx/libc/stdio/lib_libsprintf.c create mode 100644 nuttx/libc/stdio/lib_libvsprintf.c create mode 100644 nuttx/libc/stdio/lib_lowinstream.c create mode 100644 nuttx/libc/stdio/lib_lowoutstream.c create mode 100644 nuttx/libc/stdio/lib_lowprintf.c create mode 100644 nuttx/libc/stdio/lib_meminstream.c create mode 100644 nuttx/libc/stdio/lib_memoutstream.c create mode 100644 nuttx/libc/stdio/lib_nullinstream.c create mode 100644 nuttx/libc/stdio/lib_nulloutstream.c create mode 100644 nuttx/libc/stdio/lib_perror.c create mode 100644 nuttx/libc/stdio/lib_printf.c create mode 100644 nuttx/libc/stdio/lib_puts.c create mode 100644 nuttx/libc/stdio/lib_rawinstream.c create mode 100644 nuttx/libc/stdio/lib_rawoutstream.c create mode 100644 nuttx/libc/stdio/lib_rawprintf.c create mode 100644 nuttx/libc/stdio/lib_rdflush.c create mode 100644 nuttx/libc/stdio/lib_snprintf.c create mode 100644 nuttx/libc/stdio/lib_sprintf.c create mode 100644 nuttx/libc/stdio/lib_sscanf.c create mode 100644 nuttx/libc/stdio/lib_stdinstream.c create mode 100644 nuttx/libc/stdio/lib_stdoutstream.c create mode 100644 nuttx/libc/stdio/lib_syslogstream.c create mode 100644 nuttx/libc/stdio/lib_ungetc.c create mode 100644 nuttx/libc/stdio/lib_vfprintf.c create mode 100644 nuttx/libc/stdio/lib_vprintf.c create mode 100644 nuttx/libc/stdio/lib_vsnprintf.c create mode 100644 nuttx/libc/stdio/lib_vsprintf.c create mode 100644 nuttx/libc/stdio/lib_wrflush.c create mode 100644 nuttx/libc/stdio/lib_zeroinstream.c create mode 100644 nuttx/libc/stdlib/Make.defs create mode 100644 nuttx/libc/stdlib/lib_abort.c create mode 100644 nuttx/libc/stdlib/lib_abs.c create mode 100644 nuttx/libc/stdlib/lib_imaxabs.c create mode 100644 nuttx/libc/stdlib/lib_labs.c create mode 100644 nuttx/libc/stdlib/lib_llabs.c create mode 100644 nuttx/libc/stdlib/lib_qsort.c create mode 100644 nuttx/libc/string/Make.defs create mode 100644 nuttx/libc/string/lib_checkbase.c create mode 100644 nuttx/libc/string/lib_isbasedigit.c create mode 100644 nuttx/libc/string/lib_memccpy.c create mode 100644 nuttx/libc/string/lib_memchr.c create mode 100644 nuttx/libc/string/lib_memcpy.c create mode 100644 nuttx/libc/string/lib_memset.c create mode 100644 nuttx/libc/string/lib_skipspace.c create mode 100644 nuttx/libc/string/lib_strcasecmp.c create mode 100644 nuttx/libc/string/lib_strcat.c create mode 100644 nuttx/libc/string/lib_strchr.c create mode 100644 nuttx/libc/string/lib_strcmp.c create mode 100644 nuttx/libc/string/lib_strcpy.c create mode 100644 nuttx/libc/string/lib_strcspn.c create mode 100644 nuttx/libc/string/lib_strdup.c create mode 100644 nuttx/libc/string/lib_strerror.c create mode 100644 nuttx/libc/string/lib_strlen.c create mode 100644 nuttx/libc/string/lib_strncasecmp.c create mode 100644 nuttx/libc/string/lib_strncat.c create mode 100644 nuttx/libc/string/lib_strncmp.c create mode 100644 nuttx/libc/string/lib_strncpy.c create mode 100644 nuttx/libc/string/lib_strndup.c create mode 100644 nuttx/libc/string/lib_strnlen.c create mode 100644 nuttx/libc/string/lib_strpbrk.c create mode 100644 nuttx/libc/string/lib_strrchr.c create mode 100644 nuttx/libc/string/lib_strspn.c create mode 100644 nuttx/libc/string/lib_strtod.c create mode 100644 nuttx/libc/string/lib_strtok.c create mode 100644 nuttx/libc/string/lib_strtokr.c create mode 100644 nuttx/libc/string/lib_strtol.c create mode 100644 nuttx/libc/string/lib_strtoll.c create mode 100644 nuttx/libc/string/lib_strtoul.c create mode 100644 nuttx/libc/string/lib_strtoull.c create mode 100644 nuttx/libc/string/lib_vikmemcpy.c create mode 100644 nuttx/libc/termios/Make.defs create mode 100644 nuttx/libc/termios/lib_cfgetspeed.c create mode 100644 nuttx/libc/termios/lib_cfsetspeed.c create mode 100644 nuttx/libc/termios/lib_tcflush.c create mode 100644 nuttx/libc/termios/lib_tcgetattr.c create mode 100644 nuttx/libc/termios/lib_tcsetattr.c create mode 100644 nuttx/libc/time/Make.defs create mode 100644 nuttx/libc/time/lib_calendar2utc.c create mode 100644 nuttx/libc/time/lib_daysbeforemonth.c create mode 100644 nuttx/libc/time/lib_gmtime.c create mode 100644 nuttx/libc/time/lib_gmtimer.c create mode 100644 nuttx/libc/time/lib_isleapyear.c create mode 100644 nuttx/libc/time/lib_mktime.c create mode 100644 nuttx/libc/time/lib_strftime.c create mode 100644 nuttx/libc/time/lib_time.c create mode 100644 nuttx/libc/unistd/Make.defs create mode 100644 nuttx/libc/unistd/lib_chdir.c create mode 100644 nuttx/libc/unistd/lib_getcwd.c create mode 100644 nuttx/libc/unistd/lib_getopt.c create mode 100644 nuttx/libc/unistd/lib_getoptargp.c create mode 100644 nuttx/libc/unistd/lib_getoptindp.c create mode 100644 nuttx/libc/unistd/lib_getoptoptp.c create mode 100644 nuttx/libxx/libxx_cxa_atexit.cxx create mode 100644 nuttx/libxx/libxx_internal.hxx create mode 100644 nuttx/libxx/libxx_stdthrow.cxx create mode 100644 nuttx/sched/pause.c create mode 100644 nuttx/tools/define.bat create mode 100644 nuttx/tools/mkdeps.bat create mode 100644 nuttx/tools/mkdeps.c (limited to 'nuttx/arch/arm/src/stm32/Kconfig') diff --git a/Makefile b/Makefile index ef51025a4..b762521e2 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,9 @@ UPLOADER = $(PX4BASE)/Tools/px_uploader.py # What are we currently configured for? # CONFIGURED = $(PX4BASE)/.configured +ifneq ($(wildcard $(CONFIGURED)),) export TARGET := $(shell cat $(CONFIGURED)) +endif # # What we will build @@ -40,8 +42,8 @@ FIRMWARE_PROTOTYPE = $(IMAGE_DIR)/$(TARGET).prototype # # Debugging # -MQUIET = --no-print-directory -#MQUIET = --print-directory +#MQUIET = --no-print-directory +MQUIET = --print-directory all: $(FIRMWARE_BUNDLE) diff --git a/nuttx/COPYING b/nuttx/COPYING index 863b81a2f..b3655265d 100644 --- a/nuttx/COPYING +++ b/nuttx/COPYING @@ -163,6 +163,57 @@ dtoa(): "This product includes software developed by the University of California, Berkeley and its contributors." +libc/string/lib_vikmemcpy.c +^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + If you enable CONFIG_MEMCPY_VIK, then you will build with the optimized + version of memcpy from Daniel Vik. Licensing information for that version + of memcpy() follows: + + Copyright (C) 1999-2010 Daniel Vik + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any + damages arising from the use of this software. + Permission is granted to anyone to use this software for any + purpose, including commercial applications, and to alter it and + redistribute it freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you + must not claim that you wrote the original software. If you + use this software in a product, an acknowledgment in the + use this software in a product, an acknowledgment in the + product documentation would be appreciated but is not + required. + + 2. Altered source versions must be plainly marked as such, and + must not be misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source + distribution. + +libc/math +^^^^^^^^^ + + If you enable CONFIG_LIB, you will build the math library at libc/math. + This library was taken from the math library developed for the Rhombus + OS by Nick Johnson (https://github.com/nickbjohnson4224/rhombus). This + port was contributed by Darcy Gong. The Rhombus math library has this + compatible MIT license: + + Copyright (C) 2009-2011 Nick Johnson + + Permission to use, copy, modify, and distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + Documents/rss.gif ^^^^^^^^^^^^^^^^^ diff --git a/nuttx/Kconfig b/nuttx/Kconfig index 0fe6eb0f7..10d624efb 100644 --- a/nuttx/Kconfig +++ b/nuttx/Kconfig @@ -20,10 +20,75 @@ menu "Build Setup" config EXPERIMENTAL bool "Prompt for development and/or incomplete code/drivers" +choice + prompt "Build Host Platform" + default HOST_LINUX + +config HOST_LINUX + bool "Linux" + +config HOST_OSX + bool "OSX" + +config HOST_WINDOWS + bool "Windows" + +config HOST_OTHER + bool "Other" + +endchoice + +choice + prompt "Windows Build Environment" + default WINDOWS_CYGWIN + depends on HOST_WINDOWS + +config WINDOWS_NATIVE + bool "Windows Native" + ---help--- + Build natively in a CMD.exe environment with Windows style paths (like C:\cgywin\home) + +config WINDOWS_CYGWIN + bool "Cygwin" +- --help--- + Build natively in a Cygwin environment with POSIX style paths (like /cygdrive/c/cgywin/home) + +config WINDOWS_MSYS + bool "MSYS" + ---help--- + Build natively in a Cygwin environment with POSIX style paths (like /cygdrive/c/cgywin/home) + +config WINDOWS_OTHER + bool "Windows POSIX-like environment" + ---help--- + Build natively in another POSIX-like environment. Additional support may be necessary + +endchoice + +config WINDOWS_MKLINK + bool "Use mklink" + default n + depends on WINDOWS_NATIVE + ---help--- + Use the mklink command to set up symbolic links when NuttX is + configured. Otherwise, configuration directories will be copied to + establish the configuration. + + If directories are copied, then some confusion can result ("Which + version of the file did I modify?"). In that case, it is recommended + that you re-build using 'make clean_context all'. That will cause the + configured directories to be recopied on each build. + + NOTE: This option also (1) that you have administrator privileges, (2) + that you are using Windows 2000 or better, and (3) that you are using + the NTFS file system. Select 'n' is that is not the case. + menu "Build Configuration" + config APPS_DIR string "Application directory" - default "../apps" + default "../apps" if !WINDOWS_NATIVE + default "..\apps" if WINDOWS_NATIVE ---help--- Identifies the directory that builds the application to link with NuttX. Default: ../apps This symbol must be assigned @@ -192,6 +257,17 @@ config ARCH_MATH_H that don't select ARCH_MATH_H, the redirecting math.h header file will stay out-of-the-way in include/nuttx/. +config ARCH_FLOAT_H + bool "float.h" + default n + ---help--- + The float.h header file defines the properties of your floating + point implementation. It would always be best to use your + toolchain's float.h header file but if none is avaiable, a default + float.h header file will provided if this option is selected. However + there is no assurance that the settings in this float.h are actually + correct for your platform! + config ARCH_STDARG_H bool "stdarg.h" default n @@ -244,17 +320,24 @@ config DEBUG_ENABLE comment "Subsystem Debug Options" +config DEBUG_MM + bool "Enable Memory Manager Debug Output" + default n + ---help--- + Enable memory management debug output (disabled by default) + config DEBUG_SCHED bool "Enable Scheduler Debug Output" default n ---help--- Enable OS debug output (disabled by default) -config DEBUG_MM - bool "Enable Memory Manager Debug Output" +config DEBUG_PAGING + bool "Enable Demand Paging Debug Output" default n + depends on PAGING ---help--- - Enable memory management debug output (disabled by default) + Enable demand paging debug output (disabled by default) config DEBUG_NET bool "Enable Network Debug Output" @@ -311,6 +394,13 @@ config DEBUG_INPUT Enable low level debug output from the input device drivers such as mice and touchscreens (disabled by default) +config DEBUG_ANALOG + bool "Enable Analog Device Debug Output" + default n + ---help--- + Enable low level debug output from the analog device drivers such as + A/D and D/A converters (disabled by default) + config DEBUG_I2C bool "Enable I2C Debug Output" default n @@ -325,12 +415,18 @@ config DEBUG_SPI ---help--- Enable I2C driver debug output (disabled by default) +config DEBUG_DMA + bool "Enable DMA Debug Output" + default n + ---help--- + Enable DMA-releated debug output (disabled by default) + config DEBUG_WATCHDOG bool "Enable Watchdog Timer Debug Output" default n depends on WATCHDOG ---help--- - Enable watchdog timer debug output (disabled by default) + Enable watchdog timer debug output (disabled by default) endif @@ -375,8 +471,12 @@ menu "Memory Management" source mm/Kconfig endmenu +menu "Binary Formats" +source binfmt/Kconfig +endmenu + menu "Library Routines" -source lib/Kconfig +source libc/Kconfig source libxx/Kconfig endmenu diff --git a/nuttx/Makefile b/nuttx/Makefile index 7a058d88e..cf7a57c83 100644 --- a/nuttx/Makefile +++ b/nuttx/Makefile @@ -1,7 +1,7 @@ ############################################################################ # Makefile # -# Copyright (C) 2007-2012 Gregory Nutt. All rights reserved. +# Copyright (C) 2012 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -33,619 +33,17 @@ # ############################################################################ -TOPDIR := ${shell pwd | sed -e 's/ /\\ /g'} --include ${TOPDIR}/.config --include ${TOPDIR}/tools/Config.mk --include ${TOPDIR}/Make.defs - -# Control build verbosity - -ifeq ($(V),1) -export Q := -else -export Q := @ -endif - -# Default tools - -ifeq ($(DIRLINK),) -DIRLINK = $(TOPDIR)/tools/link.sh -DIRUNLINK = $(TOPDIR)/tools/unlink.sh -endif - -# This define is passed as EXTRADEFINES for kernel-mode builds. It is also passed -# during PASS1 (but not PASS2) context and depend targets. - -KDEFINE = ${shell $(TOPDIR)/tools/define.sh $(CC) __KERNEL__} - -# Process architecture and board-specific directories - -ARCH_DIR = arch/$(CONFIG_ARCH) -ARCH_SRC = $(ARCH_DIR)/src -ARCH_INC = $(ARCH_DIR)/include -BOARD_DIR = configs/$(CONFIG_ARCH_BOARD) - -# Add-on directories. These may or may not be in place in the -# NuttX source tree (they must be specifically installed) +# This is a top-level "kludge" Makefile that just includes the correct +# Makefile. If you already know the Makefile that you want, you can skip +# this nonsense using: # -# CONFIG_APPS_DIR can be over-ridden from the command line or in the .config file. -# The default value of CONFIG_APPS_DIR is ../apps. Ultimately, the application -# will be built if APPDIR is defined. APPDIR will be defined if a directory containing -# a Makefile is found at the path provided by CONFIG_APPS_DIR - -ifeq ($(CONFIG_APPS_DIR),) -CONFIG_APPS_DIR = ../apps -endif -APPDIR := ${shell if [ -r $(CONFIG_APPS_DIR)/Makefile ]; then echo "$(CONFIG_APPS_DIR)"; fi} - -# All add-on directories. +# make -f Makefile.unix, OR +# make -f Makefile.win # -# NUTTX_ADDONS is the list of directories built into the NuttX kernel. -# USER_ADDONS is the list of directories that will be built into the user application -NUTTX_ADDONS := $(NX_DIR) -USER_ADDONS := - -ifeq ($(CONFIG_NUTTX_KERNEL),y) -USER_ADDONS += $(APPDIR) +-include .config +ifeq ($(CONFIG_WINDOWS_NATIVE),y) +include Makefile.win else -NUTTX_ADDONS += $(APPDIR) -endif - -# Lists of build directories. -# -# FSDIRS depend on file descriptor support; NONFSDIRS do not (except for parts -# of FSDIRS). We will exclude FSDIRS from the build if file descriptor -# support is disabled -# CONTEXTDIRS include directories that have special, one-time pre-build -# requirements. Normally this includes things like auto-generation of -# configuration specific files or creation of configurable symbolic links -# USERDIRS - When NuttX is build is a monolithic kernel, this provides the -# list of directories that must be built -# OTHERDIRS - These are directories that are not built but probably should -# be cleaned to prevent garbarge from collecting in them when changing -# configurations. - -NONFSDIRS = sched $(ARCH_SRC) $(NUTTX_ADDONS) -FSDIRS = fs drivers binfmt -CONTEXTDIRS = $(APPDIR) -USERDIRS = - -ifeq ($(CONFIG_NUTTX_KERNEL),y) - -NONFSDIRS += syscall -CONTEXTDIRS += syscall -USERDIRS += syscall lib mm $(USER_ADDONS) -ifeq ($(CONFIG_HAVE_CXX),y) -USERDIRS += libxx -endif - -else - -NONFSDIRS += lib mm -OTHERDIRS += syscall $(USER_ADDONS) -ifeq ($(CONFIG_HAVE_CXX),y) -NONFSDIRS += libxx -else -OTHERDIRS += libxx -endif - -endif - -ifeq ($(CONFIG_NX),y) -NONFSDIRS += graphics -CONTEXTDIRS += graphics -else -OTHERDIRS += graphics -endif - -# CLEANDIRS are the directories that will clean in. These are -# all directories that we know about. -# KERNDEPDIRS are the directories in which we will build target dependencies. -# If NuttX and applications are built separately (CONFIG_NUTTX_KERNEL), -# then this holds only the directories containing kernel files. -# USERDEPDIRS. If NuttX and applications are built separately (CONFIG_NUTTX_KERNEL), -# then this holds only the directories containing user files. - -CLEANDIRS = $(NONFSDIRS) $(FSDIRS) $(USERDIRS) $(OTHERDIRS) -KERNDEPDIRS = $(NONFSDIRS) -USERDEPDIRS = $(USERDIRS) - -# Add file system directories to KERNDEPDIRS (they are already in CLEANDIRS) - -ifeq ($(CONFIG_NFILE_DESCRIPTORS),0) -ifeq ($(CONFIG_NET),y) -ifneq ($(CONFIG_NSOCKET_DESCRIPTORS),0) -KERNDEPDIRS += fs -endif -KERNDEPDIRS += drivers -endif -else -KERNDEPDIRS += $(FSDIRS) -endif - -# Add networking directories to KERNDEPDIRS and CLEANDIRS - -ifeq ($(CONFIG_NET),y) -KERNDEPDIRS += net -endif -CLEANDIRS += net - -# -# Extra objects used in the final link. -# -# Pass 1 1ncremental (relative) link objects should be put into the -# processor-specific source directory (where other link objects will -# be created). If the pass1 obect is an archive, it could go anywhere. - -ifeq ($(CONFIG_BUILD_2PASS),y) -EXTRA_OBJS += $(CONFIG_PASS1_OBJECT) -endif - -# NUTTXLIBS is the list of NuttX libraries that is passed to the -# processor-specific Makefile to build the final NuttX target. -# Libraries in FSDIRS are excluded if file descriptor support -# is disabled. -# USERLIBS is the list of libraries used to build the final user-space -# application - -NUTTXLIBS = sched/libsched$(LIBEXT) $(ARCH_SRC)/libarch$(LIBEXT) -USERLIBS = - -# Add libraries for syscall support. The C library will be needed by -# both the kernel- and user-space builds. For now, the memory manager (mm) -# is placed in user space (only). - -ifeq ($(CONFIG_NUTTX_KERNEL),y) -NUTTXLIBS += syscall/libstubs$(LIBEXT) lib/libklib$(LIBEXT) -USERLIBS += syscall/libproxies$(LIBEXT) lib/libulib$(LIBEXT) mm/libmm$(LIBEXT) -else -NUTTXLIBS += mm/libmm$(LIBEXT) lib/liblib$(LIBEXT) -endif - -# Add libraries for C++ support. CXX, CXXFLAGS, and COMPILEXX must -# be defined in Make.defs for this to work! - -ifeq ($(CONFIG_HAVE_CXX),y) -ifeq ($(CONFIG_NUTTX_KERNEL),y) -USERLIBS += libxx/liblibxx$(LIBEXT) -else -NUTTXLIBS += libxx/liblibxx$(LIBEXT) -endif -endif - -# Add library for application support. - -ifneq ($(APPDIR),) -ifeq ($(CONFIG_NUTTX_KERNEL),y) -USERLIBS += $(APPDIR)/libapps$(LIBEXT) -else -NUTTXLIBS += $(APPDIR)/libapps$(LIBEXT) -endif -endif - -# Add libraries for network support - -ifeq ($(CONFIG_NET),y) -NUTTXLIBS += net/libnet$(LIBEXT) -endif - -# Add libraries for file system support - -ifeq ($(CONFIG_NFILE_DESCRIPTORS),0) -ifneq ($(CONFIG_NSOCKET_DESCRIPTORS),0) -NUTTXLIBS += fs/libfs$(LIBEXT) -endif -ifeq ($(CONFIG_NET),y) -NUTTXLIBS += drivers/libdrivers$(LIBEXT) -endif -else -NUTTXLIBS += fs/libfs$(LIBEXT) drivers/libdrivers$(LIBEXT) binfmt/libbinfmt$(LIBEXT) -endif - -# Add libraries for the NX graphics sub-system - -ifneq ($(NX_DIR),) -NUTTXLIBS += $(NX_DIR)/libnx$(LIBEXT) -endif - -ifeq ($(CONFIG_NX),y) -NUTTXLIBS += graphics/libgraphics$(LIBEXT) -endif - -# This is the name of the final target (relative to the top level directorty) - -BIN = nuttx$(EXEEXT) - -all: $(BIN) -.PHONY: context clean_context check_context export subdir_clean clean subdir_distclean distclean apps_clean apps_distclean - -# Target used to copy include/nuttx/math.h. If CONFIG_ARCH_MATH_H is -# defined, then there is an architecture specific math.h header file -# that will be included indirectly from include/math.h. But first, we -# have to copy math.h from include/nuttx/. to include/. - -ifeq ($(CONFIG_ARCH_MATH_H),y) -include/math.h: include/nuttx/math.h - @cp -f include/nuttx/math.h include/math.h -else -include/math.h: -endif - -# Target used to copy include/nuttx/stdarg.h. If CONFIG_ARCH_STDARG_H is -# defined, then there is an architecture specific stdarg.h header file -# that will be included indirectly from include/stdarg.h. But first, we -# have to copy stdarg.h from include/nuttx/. to include/. - -ifeq ($(CONFIG_ARCH_STDARG_H),y) -include/stdarg.h: include/nuttx/stdarg.h - @cp -f include/nuttx/stdarg.h include/stdarg.h -else -include/stdarg.h: -endif - -# Targets used to build include/nuttx/version.h. Creation of version.h is -# part of the overall NuttX configuration sequence. Notice that the -# tools/mkversion tool is built and used to create include/nuttx/version.h - -tools/mkversion: - @$(MAKE) -C tools -f Makefile.host TOPDIR="$(TOPDIR)" mkversion - -$(TOPDIR)/.version: - @if [ ! -f .version ]; then \ - echo "No .version file found, creating one"; \ - tools/version.sh -v 0.0 -b 0 .version; \ - chmod 755 .version; \ - fi - -include/nuttx/version.h: $(TOPDIR)/.version tools/mkversion - @tools/mkversion $(TOPDIR) > include/nuttx/version.h - -# Targets used to build include/nuttx/config.h. Creation of config.h is -# part of the overall NuttX configuration sequence. Notice that the -# tools/mkconfig tool is built and used to create include/nuttx/config.h - -tools/mkconfig: - @$(MAKE) -C tools -f Makefile.host TOPDIR="$(TOPDIR)" mkconfig - -include/nuttx/config.h: $(TOPDIR)/.config tools/mkconfig - @tools/mkconfig $(TOPDIR) > include/nuttx/config.h - -# dirlinks, and helpers -# -# Directories links. Most of establishing the NuttX configuration involves -# setting up symbolic links with 'generic' directory names to specific, -# configured directories. -# -# Link the apps/include directory to include/apps - -include/apps: Make.defs -ifneq ($(APPDIR),) - @if [ -d $(TOPDIR)/$(APPDIR)/include ]; then \ - $(DIRLINK) $(TOPDIR)/$(APPDIR)/include include/apps; \ - fi -endif - -# Link the arch//include directory to include/arch - -include/arch: Make.defs - @$(DIRLINK) $(TOPDIR)/$(ARCH_DIR)/include include/arch - -# Link the configs//include directory to include/arch/board - -include/arch/board: include/arch Make.defs include/arch - @$(DIRLINK) $(TOPDIR)/$(BOARD_DIR)/include include/arch/board - -# Link the configs//src dir to arch//src/board - -$(ARCH_SRC)/board: Make.defs - @$(DIRLINK) $(TOPDIR)/$(BOARD_DIR)/src $(ARCH_SRC)/board - -# Link arch//include/ to arch//include/chip - -$(ARCH_SRC)/chip: Make.defs -ifneq ($(CONFIG_ARCH_CHIP),) - @$(DIRLINK) $(TOPDIR)/$(ARCH_SRC)/$(CONFIG_ARCH_CHIP) $(ARCH_SRC)/chip -endif - -# Link arch//src/ to arch//src/chip - -include/arch/chip: include/arch Make.defs -ifneq ($(CONFIG_ARCH_CHIP),) - @$(DIRLINK) $(TOPDIR)/$(ARCH_INC)/$(CONFIG_ARCH_CHIP) include/arch/chip +include Makefile.unix endif - -dirlinks: include/arch include/arch/board include/arch/chip $(ARCH_SRC)/board $(ARCH_SRC)/chip include/apps - -# context -# -# The context target is invoked on each target build to assure that NuttX is -# properly configured. The basic configuration steps include creation of the -# the config.h and version.h header files in the include/nuttx directory and -# the establishment of symbolic links to configured directories. - -context: check_context include/nuttx/config.h include/nuttx/version.h include/math.h include/stdarg.h dirlinks - @for dir in $(CONTEXTDIRS) ; do \ - $(MAKE) -C $$dir TOPDIR="$(TOPDIR)" context; \ - done - -# clean_context -# -# This is part of the distclean target. It removes all of the header files -# and symbolic links created by the context target. - -clean_context: - @rm -f include/nuttx/config.h - @rm -f include/nuttx/version.h - @rm -f include/math.h - @rm -f include/stdarg.h - @$(DIRUNLINK) include/arch/board - @$(DIRUNLINK) include/arch/chip - @$(DIRUNLINK) include/arch - @$(DIRUNLINK) $(ARCH_SRC)/board - @$(DIRUNLINK) $(ARCH_SRC)/chip - @$(DIRUNLINK) include/apps - -# check_context -# -# This target checks if NuttX has been configured. NuttX is configured using -# the script tools/configure.sh. That script will install certain files in -# the top-level NuttX build directory. This target verifies that those -# configuration files have been installed and that NuttX is ready to be built. - -check_context: - @if [ ! -e ${TOPDIR}/.config -o ! -e ${TOPDIR}/Make.defs ]; then \ - echo "" ; echo "Nuttx has not been configured:" ; \ - echo " cd tools; ./configure.sh " ; echo "" ; \ - exit 1 ; \ - fi - -# Archive targets. The target build sequency will first create a series of -# libraries, one per configured source file directory. The final NuttX -# execution will then be built from those libraries. The following targets -# built those libraries. -# -# Possible kernel-mode builds - -lib/libklib$(LIBEXT): context - @$(MAKE) -C lib TOPDIR="$(TOPDIR)" libklib$(LIBEXT) EXTRADEFINES=$(KDEFINE) - -sched/libsched$(LIBEXT): context - @$(MAKE) -C sched TOPDIR="$(TOPDIR)" libsched$(LIBEXT) EXTRADEFINES=$(KDEFINE) - -$(ARCH_SRC)/libarch$(LIBEXT): context - @$(MAKE) -C $(ARCH_SRC) TOPDIR="$(TOPDIR)" libarch$(LIBEXT) EXTRADEFINES=$(KDEFINE) - -net/libnet$(LIBEXT): context - @$(MAKE) -C net TOPDIR="$(TOPDIR)" libnet$(LIBEXT) EXTRADEFINES=$(KDEFINE) - -fs/libfs$(LIBEXT): context - @$(MAKE) -C fs TOPDIR="$(TOPDIR)" libfs$(LIBEXT) EXTRADEFINES=$(KDEFINE) - -drivers/libdrivers$(LIBEXT): context - @$(MAKE) -C drivers TOPDIR="$(TOPDIR)" libdrivers$(LIBEXT) EXTRADEFINES=$(KDEFINE) - -binfmt/libbinfmt$(LIBEXT): context - @$(MAKE) -C binfmt TOPDIR="$(TOPDIR)" libbinfmt$(LIBEXT) EXTRADEFINES=$(KDEFINE) - -graphics/libgraphics$(LIBEXT): context - @$(MAKE) -C graphics TOPDIR="$(TOPDIR)" libgraphics$(LIBEXT) EXTRADEFINES=$(KDEFINE) - -syscall/libstubs$(LIBEXT): context - @$(MAKE) -C syscall TOPDIR="$(TOPDIR)" libstubs$(LIBEXT) EXTRADEFINES=$(KDEFINE) - -# Possible user-mode builds - -lib/libulib$(LIBEXT): context - @$(MAKE) -C lib TOPDIR="$(TOPDIR)" libulib$(LIBEXT) - -libxx/liblibxx$(LIBEXT): context - @$(MAKE) -C libxx TOPDIR="$(TOPDIR)" liblibxx$(LIBEXT) - -mm/libmm$(LIBEXT): context - @$(MAKE) -C mm TOPDIR="$(TOPDIR)" libmm$(LIBEXT) EXTRADEFINES=$(KDEFINE) - -$(APPDIR)/libapps$(LIBEXT): context - @$(MAKE) -C $(APPDIR) TOPDIR="$(TOPDIR)" libapps$(LIBEXT) - -syscall/libproxies$(LIBEXT): context - @$(MAKE) -C syscall TOPDIR="$(TOPDIR)" libproxies$(LIBEXT) - -# Possible non-kernel builds - -lib/liblib$(LIBEXT): context - @$(MAKE) -C lib TOPDIR="$(TOPDIR)" liblib$(LIBEXT) - -# pass1 and pass2 -# -# If the 2 pass build option is selected, then this pass1 target is -# configured to built before the pass2 target. This pass1 target may, as an -# example, build an extra link object (CONFIG_PASS1_OBJECT) which may be an -# incremental (relative) link object, but could be a static library (archive); -# some modification to this Makefile would be required if CONFIG_PASS1_OBJECT -# is an archive. Exactly what is performed during pass1 or what it generates -# is unknown to this makefule unless CONFIG_PASS1_OBJECT is defined. - -pass1deps: context pass1dep $(USERLIBS) - -pass1: pass1deps -ifeq ($(CONFIG_BUILD_2PASS),y) - @if [ -z "$(CONFIG_PASS1_BUILDIR)" ]; then \ - echo "ERROR: CONFIG_PASS1_BUILDIR not defined"; \ - exit 1; \ - fi - @if [ ! -d "$(CONFIG_PASS1_BUILDIR)" ]; then \ - echo "ERROR: CONFIG_PASS1_BUILDIR does not exist"; \ - exit 1; \ - fi - @if [ ! -f "$(CONFIG_PASS1_BUILDIR)/Makefile" ]; then \ - echo "ERROR: No Makefile in CONFIG_PASS1_BUILDIR"; \ - exit 1; \ - fi - @$(MAKE) -C $(CONFIG_PASS1_BUILDIR) TOPDIR="$(TOPDIR)" LINKLIBS="$(NUTTXLIBS)" USERLIBS="$(USERLIBS)" "$(CONFIG_PASS1_TARGET)" -endif - -pass2deps: context pass2dep $(NUTTXLIBS) - -pass2: pass2deps - @$(MAKE) -C $(ARCH_SRC) TOPDIR="$(TOPDIR)" EXTRA_OBJS="$(EXTRA_OBJS)" LINKLIBS="$(NUTTXLIBS)" EXTRADEFINES=$(KDEFINE) $(BIN) - @if [ -w /tftpboot ] ; then \ - cp -f $(BIN) /tftpboot/$(BIN).${CONFIG_ARCH}; \ - fi -ifeq ($(CONFIG_RRLOAD_BINARY),y) - @echo "MK: $(BIN).rr" - @$(TOPDIR)/tools/mkimage.sh --Prefix $(CROSSDEV) $(BIN) $(BIN).rr - @if [ -w /tftpboot ] ; then \ - cp -f $(BIN).rr /tftpboot/$\(BIN).rr.$(CONFIG_ARCH); \ - fi -endif -ifeq ($(CONFIG_INTELHEX_BINARY),y) - @echo "CP: $(BIN).hex" - @$(OBJCOPY) $(OBJCOPYARGS) -O ihex $(BIN) $(BIN).hex -endif -ifeq ($(CONFIG_MOTOROLA_SREC),y) - @echo "CP: $(BIN).srec" - @$(OBJCOPY) $(OBJCOPYARGS) -O srec $(BIN) $(BIN).srec -endif -ifeq ($(CONFIG_RAW_BINARY),y) - @echo "CP: $(BIN).bin" - @$(OBJCOPY) $(OBJCOPYARGS) -O binary $(BIN) $(BIN).bin -endif - -# $(BIN) -# -# Create the final NuttX executable in a two pass build process. In the -# normal case, all pass1 and pass2 dependencies are created then pass1 -# and pass2 targets are built. However, in some cases, you may need to build -# pass1 depenencies and pass1 first, then build pass2 dependencies and pass2. -# in that case, execute 'make pass1 pass2' from the command line. - -$(BIN): pass1deps pass2deps pass1 pass2 - -# download -# -# This is a helper target that will rebuild NuttX and download it to the target -# system in one step. The operation of this target depends completely upon -# implementation of the DOWNLOAD command in the user Make.defs file. It will -# generate an error an error if the DOWNLOAD command is not defined. - -download: $(BIN) - $(call DOWNLOAD, $<) - -# pass1dep: Create pass1 build dependencies -# pass2dep: Create pass2 build dependencies - -pass1dep: context - @for dir in $(USERDEPDIRS) ; do \ - $(MAKE) -C $$dir TOPDIR="$(TOPDIR)" depend ; \ - done - -pass2dep: context - @for dir in $(KERNDEPDIRS) ; do \ - $(MAKE) -C $$dir TOPDIR="$(TOPDIR)" EXTRADEFINES=$(KDEFINE) depend; \ - done - -# Configuration targets -# -# These targets depend on the kconfig-frontends packages. To use these, you -# must first download and install the kconfig-frontends package from this -# location: http://ymorin.is-a-geek.org/projects/kconfig-frontends. See -# misc/tools/README.txt for additional information. - -config: - @APPSDIR=${CONFIG_APPS_DIR} conf Kconfig - -oldconfig: - @APPSDIR=${CONFIG_APPS_DIR} conf --oldconfig Kconfig - -menuconfig: - @APPSDIR=${CONFIG_APPS_DIR} mconf Kconfig - -# export -# -# The export target will package the NuttX libraries and header files into -# an exportable package. Caveats: (1) These needs some extension for the KERNEL -# build; it needs to receive USERLIBS and create a libuser.a). (2) The logic -# in tools/mkexport.sh only supports GCC and, for example, explicitly assumes -# that the archiver is 'ar' - -export: pass2deps - @tools/mkexport.sh -w$(WINTOOL) -t "$(TOPDIR)" -l "$(NUTTXLIBS)" - -# General housekeeping targets: dependencies, cleaning, etc. -# -# depend: Create both PASS1 and PASS2 dependencies -# clean: Removes derived object files, archives, executables, and -# temporary files, but retains the configuration and context -# files and directories. -# distclean: Does 'clean' then also removes all configuration and context -# files. This essentially restores the directory structure -# to its original, unconfigured stated. - -depend: pass1dep pass2dep - -subdir_clean: - @for dir in $(CLEANDIRS) ; do \ - if [ -e $$dir/Makefile ]; then \ - $(MAKE) -C $$dir TOPDIR="$(TOPDIR)" clean ; \ - fi \ - done - @$(MAKE) -C tools -f Makefile.host TOPDIR="$(TOPDIR)" clean - @$(MAKE) -C mm -f Makefile.test TOPDIR="$(TOPDIR)" clean -ifeq ($(CONFIG_BUILD_2PASS),y) - @$(MAKE) -C $(CONFIG_PASS1_BUILDIR) TOPDIR="$(TOPDIR)" clean -endif - -clean: subdir_clean - @rm -f $(BIN) nuttx.* mm_test *.map _SAVED_APPS_config *~ - @rm -f nuttx-export* - -subdir_distclean: - @for dir in $(CLEANDIRS) ; do \ - if [ -e $$dir/Makefile ]; then \ - $(MAKE) -C $$dir TOPDIR="$(TOPDIR)" distclean ; \ - fi \ - done - -distclean: clean subdir_distclean clean_context -ifeq ($(CONFIG_BUILD_2PASS),y) - @$(MAKE) -C $(CONFIG_PASS1_BUILDIR) TOPDIR="$(TOPDIR)" distclean -endif - @rm -f Make.defs setenv.sh .config .config.old - -# Application housekeeping targets. The APPDIR variable refers to the user -# application directory. A sample apps/ directory is included with NuttX, -# however, this is not treated as part of NuttX and may be replaced with a -# different application directory. For the most part, the application -# directory is treated like any other build directory in this script. However, -# as a convenience, the following targets are included to support housekeeping -# functions in the user application directory from the NuttX build directory. -# -# apps_clean: Perform the clean operation only in the user application -# directory -# apps_distclean: Perform the distclean operation only in the user application -# directory. Note that the apps/.config file (inf any) is -# preserved so that this is not a "full" distclean but more of a -# configuration "reset." (There willnot be an apps/.config -# file if the configuration was generated via make menuconfig). - -apps_clean: -ifneq ($(APPDIR),) - @$(MAKE) -C "$(TOPDIR)/$(APPDIR)" TOPDIR="$(TOPDIR)" clean -endif - -apps_distclean: -ifneq ($(APPDIR),) - @if [ -r "$(TOPDIR)/$(APPDIR)/.config" ]; then \ - cp "$(TOPDIR)/$(APPDIR)/.config" _SAVED_APPS_config || \ - { echo "Copy of $(APPDIR)/.config failed" ; exit 1 ; } \ - else \ - rm -f _SAVED_APPS_config; \ - fi - @$(MAKE) -C "$(TOPDIR)/$(APPDIR)" TOPDIR="$(TOPDIR)" distclean - @if [ -r _SAVED_APPS_config ]; then \ - @mv _SAVED_APPS_config "$(TOPDIR)/$(APPDIR)/.config" || \ - { echo "Copy of _SAVED_APPS_config failed" ; exit 1 ; } \ - fi -endif - diff --git a/nuttx/TODO b/nuttx/TODO index 8e353a956..6c28bfd43 100644 --- a/nuttx/TODO +++ b/nuttx/TODO @@ -14,8 +14,8 @@ nuttx/ (2) C++ Support (6) Binary loaders (binfmt/) (17) Network (net/, drivers/net) - (3) USB (drivers/usbdev, drivers/usbhost) - (11) Libraries (lib/) + (4) USB (drivers/usbdev, drivers/usbhost) + (11) Libraries (libc/, ) (9) File system/Generic drivers (fs/, drivers/) (5) Graphics subystem (graphics/) (1) Pascal add-on (pcode/) @@ -32,7 +32,7 @@ nuttx/ (0) ARM/LPC43x (arch/arm/src/lpc43xx/) (3) ARM/STR71x (arch/arm/src/str71x/) (3) ARM/LM3S6918 (arch/arm/src/lm3s/) - (7) ARM/STM32 (arch/arm/src/stm32/) + (4) ARM/STM32 (arch/arm/src/stm32/) (3) AVR (arch/avr) (0) Intel x86 (arch/x86) (5) 8051 / MCS51 (arch/8051/) @@ -421,7 +421,7 @@ o Binary loaders (binfmt/) .word .LC3-(.LPIC4+4) .word .LC4-(.LPIC5+4) - This is good and bad. This is good because it means that .rodata.str1.1 can not + This is good and bad. This is good because it means that .rodata.str1.1 can now reside in FLASH with .text and can be accessed using PC-relative addressing. That can be accomplished by simply moving the .rodata from the .data section to the .text section in the linker script. (The NXFLAT linker script is located at @@ -629,8 +629,13 @@ o USB (drivers/usbdev, drivers/usbhost) CDC/ACM serial driver might need the line coding data (that data is not used currenly, but it might be). -o Libraries (lib/) - ^^^^^^^^^^^^^^^^ + Title: USB HUB SUPPORT + Description: Add support for USB hubs + Status: Open + Priority: Low/Unknown. This is a feature enhancement. + +o Libraries (libc/) + ^^^^^^^^^^^^^^^^^ Title: ENVIRON Description: The definition of environ in stdlib.h is bogus and will not @@ -643,7 +648,7 @@ o Libraries (lib/) Description: Need some minimal termios support... at a minimum, enough to switch between raw and "normal" modes to support behavior like that needed for readline(). - UPDATE: There is growing functionality in lib/termios/ and in the + UPDATE: There is growing functionality in libc/termios/ and in the ioctl methods of several MCU serial drivers (stm32, lpc43, lpc17, pic32). However, as phrased, this bug cannot yet be closed since this "growing functionality" does not address all termios.h @@ -708,7 +713,7 @@ o Libraries (lib/) Priority: Title: OLD dtoa NEEDS TO BE UPDATED - Description: This implementation of dtoa in lib/stdio is old and will not + Description: This implementation of dtoa in libc/stdio is old and will not work with some newer compilers. See http://patrakov.blogspot.com/2009/03/dont-use-old-dtoac.html Status: Open @@ -716,7 +721,7 @@ o Libraries (lib/) Title: SYSLOG INTEGRATION Description: There are the beginnings of some system logging capabilities (see - drivers/syslog, fs/fs_syslog.c, and lib/stdio/lib_librawprintf.c and + drivers/syslog, fs/fs_syslog.c, and libc/stdio/lib_librawprintf.c and lib_liblowprintf.c. For NuttX, SYSLOG is a concept and includes, extends, and replaces the legacy NuttX debug ouput. Some additional integration is required to formalized this. For example: @@ -960,7 +965,7 @@ o Build system built configuration, only the multiple user mode can be supported with the NX server residing inside of the kernel space. In this case, most of the user end functions in graphics/nxmu - must be moved to lib/nx and those functions must be built into + must be moved to libc/nx and those functions must be built into libuser.a to be linked with the user-space code. A similar issue exists in NSH that uses some internal OS interfaces that would not be available in a kernel build @@ -1393,11 +1398,6 @@ o ARM/LM3S6918 (arch/arm/src/lm3s/) o ARM/STM32 (arch/arm/src/stm32/) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - Title: NOR FLASH DRIVER - Description: NOR Flash driver with FTL layer to support a file system. - Status: Open - Priority: Low - Title: USBSERIAL ISSUES Description A USB device-side driver is in place but not well tested. At present, the apps/examples/usbserial test sometimes fails. The situation @@ -1420,11 +1420,6 @@ o ARM/STM32 (arch/arm/src/stm32/) Status: Open Priority: Medium-High - Title: FSMC EXTERNAL MEMORY UNTESTED - Description: FSMC external memory support is untested - Status: Open - Priority: Low - Title: DMA EXTENSIONS Description: DMA logic needs to be extended. DMA2, Channel 5, will not work because the DMA2 channels 4 & 5 share the same interrupt. @@ -1432,12 +1427,6 @@ o ARM/STM32 (arch/arm/src/stm32/) Priority: Low until someone needs DMA1, Channel 5 (ADC3, UART4_TX, TIM5_CH1, or TIM8_CH2). - Title: UNFINISHED DRIVERS - Description: The following drivers are incomplete: DAC. The following drivers - are untested: DMA on the F4, CAN. - Status: Open - Priority: Medium - Title: F4 SDIO MULTI-BLOCK TRANSFER FAILURES Description: If you use a large I/O buffer to access the file system, then the MMCSD driver will perform multiple block SD transfers. With DMA @@ -1461,13 +1450,15 @@ o ARM/STM32 (arch/arm/src/stm32/) Status: Open Priority: Low (I am not even sure if this is a problem yet). - Status: UNFINISHED STM32 F4 OTG FS HOST DRIVER - Description: A quick-n-dirty leverage of the the LPC17xx host driver was put into - the STM32 source to support development of the STM32 F4 OTG FS host - driver. It is non-functional and still waiting for STM32 F4 logic - to be added. Don't use it! + Title: DMA FROM EXTERNAL, FSMC MEMORY + Description: I have seen a problem on F1 where all SDIO DMAs work exist for + write DMAs from FSMC memory (i.e., from FSMC memory to SDIO). + Read transfers work fine (SDIO to FSMC memory). The failure is + a data underrun error with zero bytes of data transferred. The + workaround for now is to use DMA buffers allocted from internal + SRAM. Status: Open - Priority: Low (unless you need a host driver). + Priority: Low o AVR (arch/avr) ^^^^^^^^^^^^^^ diff --git a/nuttx/arch/arm/include/elf.h b/nuttx/arch/arm/include/elf.h new file mode 100644 index 000000000..21b2c1c2c --- /dev/null +++ b/nuttx/arch/arm/include/elf.h @@ -0,0 +1,243 @@ +/**************************************************************************** + * arch/arm/include/syscall.h + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Reference: "ELF for the ARM® Architecture," ARM IHI 0044D, current through + * ABI release 2.08, October 28, 2009, ARM Limited. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __ARCH_ARM_INCLUDE_ELF_H +#define __ARCH_ARM_INCLUDE_ELF_H + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* 4.3.1 ELF Identification. Should have: + * + * e_machine = EM_ARM + * e_ident[EI_CLASS] = ELFCLASS32 + * e_ident[EI_DATA] = ELFDATA2LSB (little endian) or ELFDATA2MSB (big endian) + */ + +#if 0 /* Defined in include/elf32.h */ +#define EM_ARM 40 +#endif + +/* Table 4-2, ARM-specific e_flags */ + +#define EF_ARM_EABI_MASK 0xff000000 +#define EF_ARM_EABI_UNKNOWN 0x00000000 +#define EF_ARM_EABI_VER1 0x01000000 +#define EF_ARM_EABI_VER2 0x02000000 +#define EF_ARM_EABI_VER3 0x03000000 +#define EF_ARM_EABI_VER4 0x04000000 +#define EF_ARM_EABI_VER5 0x05000000 + +#define EF_ARM_BE8 0x00800000 + +/* Table 4-4, Processor specific section types */ + +#define SHT_ARM_EXIDX 0x70000001 /* Exception Index table */ +#define SHT_ARM_PREEMPTMAP 0x70000002 /* BPABI DLL dynamic linking pre-emption map */ +#define SHT_ARM_ATTRIBUTES 0x70000003 /* Object file compatibility attributes */ +#define SHT_ARM_DEBUGOVERLAY 0x70000004 +#define SHT_ARM_OVERLAYSECTION 0x70000005 + +/* 4.7.1 Relocation codes + * + * S (when used on its own) is the address of the symbol. + * A is the addend for the relocation. + * P is the address of the place being relocated (derived from r_offset). + * Pa is the adjusted address of the place being relocated, defined as (P & 0xFFFFFFFC). + * T is 1 if the target symbol S has type STT_FUNC and the symbol addresses a Thumb instruction; + * it is 0 otherwise. + * B(S) is the addressing origin of the output segment defining the symbol S. + * GOT_ORG is the addressing origin of the Global Offset Table + * GOT(S) is the address of the GOT entry for the symbol S. + */ + +#define R_ARM_NONE 0 /* No relocation */ +#define R_ARM_PC24 1 /* ARM ((S + A) | T) - P */ +#define R_ARM_ABS32 2 /* Data (S + A) | T */ +#define R_ARM_REL32 3 /* Data ((S + A) | T) - P */ +#define R_ARM_LDR_PC_G0 4 /* ARM S + A - P */ +#define R_ARM_ABS16 5 /* Data S + A */ +#define R_ARM_ABS12 6 /* ARM S + A */ +#define R_ARM_THM_ABS5 7 /* Thumb16 S + A */ +#define R_ARM_ABS8 8 /* Data S + A */ +#define R_ARM_SBREL32 9 /* Data ((S + A) | T) - B(S) */ +#define R_ARM_THM_CALL 10 /* Thumb32 ((S + A) | T) - P */ +#define R_ARM_THM_PC8 11 /* Thumb16 S + A - Pa */ +#define R_ARM_BREL_ADJ 12 /* Data ?B(S) + A */ +#define R_ARM_TLS_DESC 13 /* Data */ +#define R_ARM_THM_SWI8 14 /* Obsolete */ +#define R_ARM_XPC25 15 /* Obsolete */ +#define R_ARM_THM_XPC22 16 /* Obsolete */ +#define R_ARM_TLS_DTPMOD32 17 /* Data Module[S] */ +#define R_ARM_TLS_DTPOFF32 18 /* Data S + A - TLS */ +#define R_ARM_TLS_TPOFF32 19 /* Data S + A - tp */ +#define R_ARM_COPY 20 /* Miscellaneous */ +#define R_ARM_GLOB_DAT 21 /* Data (S + A) | T */ +#define R_ARM_JUMP_SLOT 22 /* Data (S + A) | T */ +#define R_ARM_RELATIVE 23 /* Data B(S) + A */ +#define R_ARM_GOTOFF32 24 /* Data ((S + A) | T) - GOT_ORG */ +#define R_ARM_BASE_PREL 25 /* Data B(S) + A - P */ +#define R_ARM_GOT_BREL 26 /* Data GOT(S) + A - GOT_ORG */ +#define R_ARM_PLT32 27 /* ARM ((S + A) | T) - P */ +#define R_ARM_CALL 28 /* ARM ((S + A) | T) - P */ +#define R_ARM_JUMP24 29 /* ARM ((S + A) | T) - P */ +#define R_ARM_THM_JUMP24 30 /* Thumb32 ((S + A) | T) - P */ +#define R_ARM_BASE_ABS 31 /* Data B(S) + A */ +#define R_ARM_ALU_PCREL_7_0 32 /* Obsolete */ +#define R_ARM_ALU_PCREL_15_8 33 /* Obsolete */ +#define R_ARM_ALU_PCREL_23_15 34 /* Obsolete */ +#define R_ARM_LDR_SBREL_11_0_NC 35 /* ARM S + A - B(S) */ +#define R_ARM_ALU_SBREL_19_12_NC 36 /* ARM S + A - B(S) */ +#define R_ARM_ALU_SBREL_27_20_CK 37 /* ARM S + A - B(S) */ +#define R_ARM_TARGET1 38 /* Miscellaneous (S + A) | T or ((S + A) | T) - P */ +#define R_ARM_SBREL31 39 /* Data ((S + A) | T) - B(S) */ +#define R_ARM_V4BX 40 /* Miscellaneous */ +#define R_ARM_TARGET2 41 /* Miscellaneous */ +#define R_ARM_PREL31 42 /* Data ((S + A) | T) - P */ +#define R_ARM_MOVW_ABS_NC 43 /* ARM (S + A) | T */ +#define R_ARM_MOVT_ABS 44 /* ARM S + A */ +#define R_ARM_MOVW_PREL_NC 45 /* ARM ((S + A) | T) - P */ +#define R_ARM_MOVT_PREL 46 /* ARM S + A - P */ +#define R_ARM_THM_MOVW_ABS_NC 47 /* Thumb32 (S + A) | T */ +#define R_ARM_THM_MOVT_ABS 48 /* Thumb32 S + A */ +#define R_ARM_THM_MOVW_PREL_NC 49 /* Thumb32 ((S + A) | T) - P */ +#define R_ARM_THM_MOVT_PREL 50 /* Thumb32 S + A - P */ +#define R_ARM_THM_JUMP19 51 /* Thumb32 ((S + A) | T) - P */ +#define R_ARM_THM_JUMP6 52 /* Thumb16 S + A - P */ +#define R_ARM_THM_ALU_PREL_11_0 53 /* Thumb32 ((S + A) | T) - Pa */ +#define R_ARM_THM_PC12 54 /* Thumb32 S + A - Pa */ +#define R_ARM_ABS32_NOI 55 /* Data S + A */ +#define R_ARM_REL32_NOI 56 /* Data S + A - P */ +#define R_ARM_ALU_PC_G0_NC 57 /* ARM ((S + A) | T) - P */ +#define R_ARM_ALU_PC_G0 58 /* ARM ((S + A) | T) - P */ +#define R_ARM_ALU_PC_G1_NC 59 /* ARM ((S + A) | T) - P */ +#define R_ARM_ALU_PC_G1 60 /* ARM ((S + A) | T) - P */ +#define R_ARM_ALU_PC_G2 61 /* ARM ((S + A) | T) - P */ +#define R_ARM_LDR_PC_G1 62 /* ARM S + A - P */ +#define R_ARM_LDR_PC_G2 63 /* ARM S + A - P */ +#define R_ARM_LDRS_PC_G0 64 /* ARM S + A - P */ +#define R_ARM_LDRS_PC_G1 65 /* ARM S + A - P */ +#define R_ARM_LDRS_PC_G2 66 /* ARM S + A - P */ +#define R_ARM_LDC_PC_G0 67 /* ARM S + A - P */ +#define R_ARM_LDC_PC_G1 68 /* ARM S + A - P */ +#define R_ARM_LDC_PC_G2 69 /* ARM S + A - P */ +#define R_ARM_ALU_SB_G0_NC 70 /* ARM ((S + A) | T) - B(S) */ +#define R_ARM_ALU_SB_G0 71 /* ARM ((S + A) | T) - B(S) */ +#define R_ARM_ALU_SB_G1_NC 72 /* ARM ((S + A) | T) - B(S) */ +#define R_ARM_ALU_SB_G1 73 /* ARM ((S + A) | T) - B(S) */ +#define R_ARM_ALU_SB_G2 74 /* ARM ((S + A) | T) - B(S) */ +#define R_ARM_LDR_SB_G0 75 /* ARM S + A - B(S) */ +#define R_ARM_LDR_SB_G1 76 /* ARM S + A - B(S) */ +#define R_ARM_LDR_SB_G2 77 /* ARM S + A - B(S) */ +#define R_ARM_LDRS_SB_G0 78 /* ARM S + A - B(S) */ +#define R_ARM_LDRS_SB_G1 79 /* ARM S + A - B(S) */ +#define R_ARM_LDRS_SB_G2 80 /* ARM S + A - B(S) */ +#define R_ARM_LDC_SB_G0 81 /* ARM S + A - B(S) */ +#define R_ARM_LDC_SB_G1 82 /* ARM S + A - B(S) */ +#define R_ARM_LDC_SB_G2 83 /* ARM S + A - B(S) */ +#define R_ARM_MOVW_BREL_NC 84 /* ARM ((S + A) | T) - B(S) */ +#define R_ARM_MOVT_BREL 85 /* ARM S + A - B(S) */ +#define R_ARM_MOVW_BREL 86 /* ARM ((S + A) | T) - B(S) */ +#define R_ARM_THM_MOVW_BREL_NC 87 /* Thumb32 ((S + A) | T) - B(S) */ +#define R_ARM_THM_MOVT_BREL 88 /* Thumb32 S + A - B(S) */ +#define R_ARM_THM_MOVW_BREL 89 /* Thumb32 ((S + A) | T) - B(S) */ +#define R_ARM_TLS_GOTDESC 90 /* Data */ +#define R_ARM_TLS_CALL 91 /* ARM */ +#define R_ARM_TLS_DESCSEQ 92 /* ARM TLS relaxation */ +#define R_ARM_THM_TLS_CALL 93 /* Thumb32 */ +#define R_ARM_PLT32_ABS 94 /* Data PLT(S) + A */ +#define R_ARM_GOT_ABS 95 /* Data GOT(S) + A */ +#define R_ARM_GOT_PREL 96 /* Data GOT(S) + A - P */ +#define R_ARM_GOT_BREL12 97 /* ARM GOT(S) + A - GOT_ORG */ +#define R_ARM_GOTOFF12 98 /* ARM S + A - GOT_ORG */ +#define R_ARM_GOTRELAX 99 /* Miscellaneous */ +#define R_ARM_GNU_VTENTRY 100 /* Data */ +#define R_ARM_GNU_VTINHERIT 101 /* Data */ +#define R_ARM_THM_JUMP11 102 /* Thumb16 S + A - P */ +#define R_ARM_THM_JUMP8 103 /* Thumb16 S + A - P */ +#define R_ARM_TLS_GD32 104 /* Data GOT(S) + A - P */ +#define R_ARM_TLS_LDM32 105 /* Data GOT(S) + A - P */ +#define R_ARM_TLS_LDO32 106 /* Data S + A - TLS */ +#define R_ARM_TLS_IE32 107 /* Data GOT(S) + A - P */ +#define R_ARM_TLS_LE32 108 /* Data S + A - tp */ +#define R_ARM_TLS_LDO12 109 /* ARM S + A - TLS */ +#define R_ARM_TLS_LE12 110 /* ARM S + A - tp */ +#define R_ARM_TLS_IE12GP 111 /* ARM GOT(S) + A - GOT_ORG */ +#define R_ARM_ME_TOO 128 /* Obsolete */ +#define R_ARM_THM_TLS_DESCSEQ16 129 /* Thumb16 */ +#define R_ARM_THM_TLS_DESCSEQ32 130 /* Thumb32 */ + +/* 5.2.1 Platform architecture compatibility data */ + +#define PT_ARM_ARCHEXT_FMTMSK 0xff000000 +#define PT_ARM_ARCHEXT_PROFMSK 0x00ff0000 +#define PT_ARM_ARCHEXT_ARCHMSK 0x000000ff + +#define PT_ARM_ARCHEXT_FMT_OS 0x00000000 +#define PT_ARM_ARCHEXT_FMT_ABI 0x01000000 + +#define PT_ARM_ARCHEXT_PROF_NONE 0x00000000 +#define PT_ARM_ARCHEXT_PROF_ARM 0x00410000 +#define PT_ARM_ARCHEXT_PROF_RT 0x00520000 +#define PT_ARM_ARCHEXT_PROF_MC 0x004d0000 +#define PT_ARM_ARCHEXT_PROF_CLASSIC 0x00530000 + +#define PT_ARM_ARCHEXT_ARCH_UNKNOWN 0x00 +#define PT_ARM_ARCHEXT_ARCHv4 0x01 +#define PT_ARM_ARCHEXT_ARCHv4T 0x02 +#define PT_ARM_ARCHEXT_ARCHv5T 0x03 +#define PT_ARM_ARCHEXT_ARCHv5TE 0x04 +#define PT_ARM_ARCHEXT_ARCHv5TEJ 0x05 +#define PT_ARM_ARCHEXT_ARCHv6 0x06 +#define PT_ARM_ARCHEXT_ARCHv6KZ 0x07 +#define PT_ARM_ARCHEXT_ARCHv6T2 0x08 +#define PT_ARM_ARCHEXT_ARCHv6K 0x09 +#define PT_ARM_ARCHEXT_ARCHv7 0x0a +#define PT_ARM_ARCHEXT_ARCHv6M 0x0b +#define PT_ARM_ARCHEXT_ARCHv6SM 0x0c +#define PT_ARM_ARCHEXT_ARCHv7EM 0x0d + +/* Table 5-6, ARM-specific dynamic array tags */ + +#define DT_ARM_RESERVED1 0x70000000 +#define DT_ARM_SYMTABSZ 0x70000001 +#define DT_ARM_PREEMPTMAP 0x70000002 +#define DT_ARM_RESERVED2 0x70000003 + +#endif /* __ARCH_ARM_INCLUDE_ELF_H */ diff --git a/nuttx/arch/arm/include/stm32/chip.h b/nuttx/arch/arm/include/stm32/chip.h index d01929e1c..d34c2eb4f 100644 --- a/nuttx/arch/arm/include/stm32/chip.h +++ b/nuttx/arch/arm/include/stm32/chip.h @@ -59,12 +59,11 @@ /* STM32 F100 Value Line ************************************************************/ #if defined(CONFIG_ARCH_CHIP_STM32F100C8) || defined(CONFIG_ARCH_CHIP_STM32F100CB) \ - || defined(CONFIG_ARCH_CHIP_STM32F100R8) || defined(CONFIG_ARCH_CHIP_STM32F100RB) \ - || defined(CONFIG_ARCH_CHIP_STM32F100V8) || defined(CONFIG_ARCH_CHIP_STM32F100VB) + || defined(CONFIG_ARCH_CHIP_STM32F100R8) || defined(CONFIG_ARCH_CHIP_STM32F100RB) # define CONFIG_STM32_STM32F10XX 1 /* STM32F10xxx family */ -# undef CONFIG_STM32_LOWDENSITY /* STM32F100x, STM32F102x and STM32F103x w/ 16/32 Kbytes */ -# define CONFIG_STM32_MEDIUMDENSITY 1 /* STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */ -# undef CONFIG_STM32_HIGHDENSITY /* STM32F101x and STM32F103x w/ 256/512 Kbytes */ +# undef CONFIG_STM32_LOWDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */ +# define CONFIG_STM32_MEDIUMDENSITY 1 /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */ +# undef CONFIG_STM32_HIGHDENSITY /* STM32F100x, STM32F101x, and STM32F103x w/ 256/512 Kbytes */ # define CONFIG_STM32_VALUELINE 1 /* STM32F100x */ # undef CONFIG_STM32_CONNECTIVITYLINE /* STM32F105x and STM32F107x */ # undef CONFIG_STM32_STM32F20XX /* STM32F205x and STM32F207x */ @@ -72,10 +71,41 @@ # define STM32_NFSMC 0 /* FSMC */ # define STM32_NATIM 1 /* One advanced timer TIM1 */ # define STM32_NGTIM 3 /* 16-bit general timers TIM2,3,4 with DMA */ -# define STM32_NBTIM 0 /* No basic timers */ -# define STM32_NDMA 2 /* DMA1-2 */ +# define STM32_NBTIM 2 /* 2 basic timers: TIM6, TIM7 */ +// TODO: there are also 3 additional timers (15-17) that don't fit any existing category +# define STM32_NDMA 1 /* DMA1 */ # define STM32_NSPI 2 /* SPI1-2 */ -# define STM32_NI2S 0 /* No I2S (?) */ +# define STM32_NI2S 0 /* No I2S */ +# define STM32_NUSART 3 /* USART1-3 */ +# define STM32_NI2C 2 /* I2C1-2 */ +# define STM32_NCAN 0 /* No CAN */ +# define STM32_NSDIO 0 /* No SDIO */ +# define STM32_NUSBOTG 0 /* No USB OTG FS/HS */ +# define STM32_NGPIO 64 /* GPIOA-D */ +# define STM32_NADC 1 /* ADC1 */ +# define STM32_NDAC 2 /* DAC 1-2 */ +# define STM32_NCRC 1 /* CRC1 */ +# define STM32_NETHERNET 0 /* No ethernet */ +# define STM32_NRNG 0 /* No random number generator (RNG) */ +# define STM32_NDCMI 0 /* No digital camera interface (DCMI) */ + +#elif defined(CONFIG_ARCH_CHIP_STM32F100V8) || defined(CONFIG_ARCH_CHIP_STM32F100VB) +# define CONFIG_STM32_STM32F10XX 1 /* STM32F10xxx family */ +# undef CONFIG_STM32_LOWDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */ +# define CONFIG_STM32_MEDIUMDENSITY 1 /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */ +# undef CONFIG_STM32_HIGHDENSITY /* STM32F100x, STM32F101x, and STM32F103x w/ 256/512 Kbytes */ +# define CONFIG_STM32_VALUELINE 1 /* STM32F100x */ +# undef CONFIG_STM32_CONNECTIVITYLINE /* STM32F105x and STM32F107x */ +# undef CONFIG_STM32_STM32F20XX /* STM32F205x and STM32F207x */ +# undef CONFIG_STM32_STM32F40XX /* STM32F405xx and STM32407xx families */ +# define STM32_NFSMC 0 /* FSMC */ +# define STM32_NATIM 1 /* One advanced timer TIM1 */ +# define STM32_NGTIM 3 /* 16-bit general timers TIM2,3,4 with DMA */ +# define STM32_NBTIM 2 /* 2 basic timers: TIM6, TIM7 */ +// TODO: there are also 3 additional timers (15-17) that don't fit any existing category +# define STM32_NDMA 1 /* DMA1 */ +# define STM32_NSPI 2 /* SPI1-2 */ +# define STM32_NI2S 0 /* No I2S */ # define STM32_NUSART 3 /* USART1-3 */ # define STM32_NI2C 2 /* I2C1-2 */ # define STM32_NCAN 0 /* No CAN */ @@ -89,6 +119,70 @@ # define STM32_NRNG 0 /* No random number generator (RNG) */ # define STM32_NDCMI 0 /* No digital camera interface (DCMI) */ +/* STM32 F100 High-density value Line ************************************************************/ + +#elif defined(CONFIG_ARCH_CHIP_STM32F100RC) || defined(CONFIG_ARCH_CHIP_STM32F100RD) \ + || defined(CONFIG_ARCH_CHIP_STM32F100RE) +# define CONFIG_STM32_STM32F10XX 1 /* STM32F10xxx family */ +# undef CONFIG_STM32_LOWDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */ +# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */ +# define CONFIG_STM32_HIGHDENSITY 1 /* STM32F100x, STM32F101x, and STM32F103x w/ 256/512 Kbytes */ +# define CONFIG_STM32_VALUELINE 1 /* STM32F100x */ +# undef CONFIG_STM32_CONNECTIVITYLINE /* STM32F105x and STM32F107x */ +# undef CONFIG_STM32_STM32F20XX /* STM32F205x and STM32F207x */ +# undef CONFIG_STM32_STM32F40XX /* STM32F405xx and STM32407xx families */ +# define STM32_NFSMC 0 /* FSMC */ +# define STM32_NATIM 1 /* One advanced timer TIM1 */ +# define STM32_NGTIM 4 /* 16-bit general timers TIM2,3,4,5 with DMA */ +# define STM32_NBTIM 2 /* 2 basic timers: TIM6, TIM7 */ +// TODO: there are also 6 additional timers (12-17) that don't fit any existing category +# define STM32_NDMA 2 /* DMA1-2 */ +# define STM32_NSPI 3 /* SPI1-3 */ +# define STM32_NI2S 0 /* No I2S */ +# define STM32_NUSART 5 /* USART1-5 */ +# define STM32_NI2C 2 /* I2C1-2 */ +# define STM32_NCAN 0 /* No CAN */ +# define STM32_NSDIO 0 /* No SDIO */ +# define STM32_NUSBOTG 0 /* No USB OTG FS/HS */ +# define STM32_NGPIO 64 /* GPIOA-D */ +# define STM32_NADC 1 /* ADC1 */ +# define STM32_NDAC 2 /* DAC 1-2 */ +# define STM32_NCRC 1 /* CRC1 */ +# define STM32_NETHERNET 0 /* No ethernet */ +# define STM32_NRNG 0 /* No random number generator (RNG) */ +# define STM32_NDCMI 0 /* No digital camera interface (DCMI) */ + +#elif defined(CONFIG_ARCH_CHIP_STM32F100VC) || defined(CONFIG_ARCH_CHIP_STM32F100VD) \ + || defined(CONFIG_ARCH_CHIP_STM32F100VE) +# define CONFIG_STM32_STM32F10XX 1 /* STM32F10xxx family */ +# undef CONFIG_STM32_LOWDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */ +# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */ +# define CONFIG_STM32_HIGHDENSITY 1 /* STM32F100x, STM32F101x, and STM32F103x w/ 256/512 Kbytes */ +# define CONFIG_STM32_VALUELINE 1 /* STM32F100x */ +# undef CONFIG_STM32_CONNECTIVITYLINE /* STM32F105x and STM32F107x */ +# undef CONFIG_STM32_STM32F20XX /* STM32F205x and STM32F207x */ +# undef CONFIG_STM32_STM32F40XX /* STM32F405xx and STM32407xx families */ +# define STM32_NFSMC 1 /* FSMC */ +# define STM32_NATIM 1 /* One advanced timer TIM1 */ +# define STM32_NGTIM 4 /* 16-bit general timers TIM2,3,4,5 with DMA */ +# define STM32_NBTIM 2 /* 2 basic timers: TIM6, TIM7 */ +// TODO: there are also 6 additional timers (12-17) that don't fit any existing category +# define STM32_NDMA 2 /* DMA1-2 */ +# define STM32_NSPI 3 /* SPI1-3 */ +# define STM32_NI2S 0 /* No I2S */ +# define STM32_NUSART 5 /* USART1-5 */ +# define STM32_NI2C 2 /* I2C1-2 */ +# define STM32_NCAN 0 /* No CAN */ +# define STM32_NSDIO 0 /* No SDIO */ +# define STM32_NUSBOTG 0 /* No USB OTG FS/HS */ +# define STM32_NGPIO 80 /* GPIOA-E */ +# define STM32_NADC 1 /* ADC1 */ +# define STM32_NDAC 2 /* DAC 1-2 */ +# define STM32_NCRC 1 /* CRC1 */ +# define STM32_NETHERNET 0 /* No ethernet */ +# define STM32_NRNG 0 /* No random number generator (RNG) */ +# define STM32_NDCMI 0 /* No digital camera interface (DCMI) */ + /* STM32 F103 High Density Family ***************************************************/ /* STM32F103RC, STM32F103RD, and STM32F103RE are all provided in 64 pin packages and differ * only in the available FLASH and SRAM. @@ -96,9 +190,9 @@ #elif defined(CONFIG_ARCH_CHIP_STM32F103RET6) # define CONFIG_STM32_STM32F10XX 1 /* STM32F10xxx family */ -# undef CONFIG_STM32_LOWDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */ -# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */ -# define CONFIG_STM32_HIGHDENSITY 1 /* STM32F101x and STM32F103x w/ 256/512 Kbytes */ +# undef CONFIG_STM32_LOWDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */ +# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */ +# define CONFIG_STM32_HIGHDENSITY 1 /* STM32F100x, STM32F101x, and STM32F103x w/ 256/512 Kbytes */ # undef CONFIG_STM32_VALUELINE /* STM32F100x */ # undef CONFIG_STM32_CONNECTIVITYLINE /* STM32F105x and STM32F107x */ # undef CONFIG_STM32_STM32F20XX /* STM32F205x and STM32F207x */ @@ -129,9 +223,9 @@ #elif defined(CONFIG_ARCH_CHIP_STM32F103VCT6) || defined(CONFIG_ARCH_CHIP_STM32F103VET6) # define CONFIG_STM32_STM32F10XX 1 /* STM32F10xxx family */ -# undef CONFIG_STM32_LOWDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */ -# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */ -# define CONFIG_STM32_HIGHDENSITY 1 /* STM32F101x and STM32F103x w/ 256/512 Kbytes */ +# undef CONFIG_STM32_LOWDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */ +# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */ +# define CONFIG_STM32_HIGHDENSITY 1 /* STM32F100x, STM32F101x, and STM32F103x w/ 256/512 Kbytes */ # undef CONFIG_STM32_VALUELINE /* STM32F100x */ # undef CONFIG_STM32_CONNECTIVITYLINE /* STM32F105x and STM32F107x */ # undef CONFIG_STM32_STM32F20XX /* STM32F205x and STM32F207x */ @@ -162,9 +256,9 @@ #elif defined(CONFIG_ARCH_CHIP_STM32F103ZET6) # define CONFIG_STM32_STM32F10XX 1 /* STM32F10xxx family */ -# undef CONFIG_STM32_LOWDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */ -# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */ -# define CONFIG_STM32_HIGHDENSITY 1 /* STM32F101x and STM32F103x w/ 256/512 Kbytes */ +# undef CONFIG_STM32_LOWDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */ +# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */ +# define CONFIG_STM32_HIGHDENSITY 1 /* STM32F100x, STM32F101x, and STM32F103x w/ 256/512 Kbytes */ # undef CONFIG_STM32_VALUELINE /* STM32F100x */ # undef CONFIG_STM32_CONNECTIVITYLINE /* STM32F105x and STM32F107x */ # undef CONFIG_STM32_STM32F20XX /* STM32F205x and STM32F207x */ @@ -192,9 +286,9 @@ /* STM32 F105/F107 Connectivity Line *******************************************************/ #elif defined(CONFIG_ARCH_CHIP_STM32F105VBT7) # define CONFIG_STM32_STM32F10XX 1 /* STM32F10xxx family */ -# undef CONFIG_STM32_LOWDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */ -# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */ -# undef CONFIG_STM32_HIGHDENSITY /* STM32F101x and STM32F103x w/ 256/512 Kbytes */ +# undef CONFIG_STM32_LOWDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */ +# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */ +# undef CONFIG_STM32_HIGHDENSITY /* STM32F100x, STM32F101x, and STM32F103x w/ 256/512 Kbytes */ # undef CONFIG_STM32_VALUELINE /* STM32F100x */ # define CONFIG_STM32_CONNECTIVITYLINE 1 /* STM32F105x and STM32F107x */ # undef CONFIG_STM32_STM32F20XX /* STM32F205x and STM32F207x */ @@ -221,9 +315,9 @@ #elif defined(CONFIG_ARCH_CHIP_STM32F107VC) # define CONFIG_STM32_STM32F10XX 1 /* STM32F10xxx family */ -# undef CONFIG_STM32_LOWDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */ -# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */ -# undef CONFIG_STM32_HIGHDENSITY /* STM32F101x and STM32F103x w/ 256/512 Kbytes */ +# undef CONFIG_STM32_LOWDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */ +# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */ +# undef CONFIG_STM32_HIGHDENSITY /* STM32F100x, STM32F101x, and STM32F103x w/ 256/512 Kbytes */ # undef CONFIG_STM32_VALUELINE /* STM32F100x */ # define CONFIG_STM32_CONNECTIVITYLINE 1 /* STM32F105x and STM32F107x */ # undef CONFIG_STM32_STM32F20XX /* STM32F205x and STM32F207x */ @@ -251,9 +345,9 @@ /* STM32 F2 Family ******************************************************************/ #elif defined(CONFIG_ARCH_CHIP_STM32F207IG) /* UFBGA-176 1024Kb FLASH 128Kb SRAM */ # undef CONFIG_STM32_STM32F10XX /* STM32F10xxx family */ -# undef CONFIG_STM32_LOWDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */ -# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */ -# undef CONFIG_STM32_HIGHDENSITY /* STM32F101x and STM32F103x w/ 256/512 Kbytes */ +# undef CONFIG_STM32_LOWDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */ +# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */ +# undef CONFIG_STM32_HIGHDENSITY /* STM32F100x, STM32F101x, and STM32F103x w/ 256/512 Kbytes */ # undef CONFIG_STM32_VALUELINE /* STM32F100x */ # undef CONFIG_STM32_CONNECTIVITYLINE /* STM32F105x and STM32F107x */ # define CONFIG_STM32_STM32F20XX 1 /* STM32F205x and STM32F207x */ @@ -283,9 +377,9 @@ /* STM23 F4 Family ******************************************************************/ #elif defined(CONFIG_ARCH_CHIP_STM32F405RG) /* LQFP 64 10x10x1.4 1024Kb FLASH 192Kb SRAM */ # undef CONFIG_STM32_STM32F10XX /* STM32F10xxx family */ -# undef CONFIG_STM32_LOWDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */ -# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */ -# undef CONFIG_STM32_HIGHDENSITY /* STM32F101x and STM32F103x w/ 256/512 Kbytes */ +# undef CONFIG_STM32_LOWDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */ +# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */ +# undef CONFIG_STM32_HIGHDENSITY /* STM32F100x, STM32F101x, and STM32F103x w/ 256/512 Kbytes */ # undef CONFIG_STM32_VALUELINE /* STM32F100x */ # undef CONFIG_STM32_CONNECTIVITYLINE /* STM32F105x and STM32F107x */ # undef CONFIG_STM32_STM32F20XX /* STM32F205x and STM32F207x */ @@ -314,9 +408,9 @@ #elif defined(CONFIG_ARCH_CHIP_STM32F405VG) /* LQFP 100 14x14x1.4 1024Kb FLASH 192Kb SRAM */ # undef CONFIG_STM32_STM32F10XX /* STM32F10xxx family */ -# undef CONFIG_STM32_LOWDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */ -# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */ -# undef CONFIG_STM32_HIGHDENSITY /* STM32F101x and STM32F103x w/ 256/512 Kbytes */ +# undef CONFIG_STM32_LOWDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */ +# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */ +# undef CONFIG_STM32_HIGHDENSITY /* STM32F100x, STM32F101x, and STM32F103x w/ 256/512 Kbytes */ # undef CONFIG_STM32_VALUELINE /* STM32F100x */ # undef CONFIG_STM32_CONNECTIVITYLINE /* STM32F105x and STM32F107x */ # undef CONFIG_STM32_STM32F20XX /* STM32F205x and STM32F207x */ @@ -345,9 +439,9 @@ #elif defined(CONFIG_ARCH_CHIP_STM32F405ZG) /* LQFP 144 20x20x1.4 1024Kb FLASH 192Kb SRAM */ # undef CONFIG_STM32_STM32F10XX /* STM32F10xxx family */ -# undef CONFIG_STM32_LOWDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */ -# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */ -# undef CONFIG_STM32_HIGHDENSITY /* STM32F101x and STM32F103x w/ 256/512 Kbytes */ +# undef CONFIG_STM32_LOWDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */ +# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */ +# undef CONFIG_STM32_HIGHDENSITY /* STM32F100x, STM32F101x, and STM32F103x w/ 256/512 Kbytes */ # undef CONFIG_STM32_VALUELINE /* STM32F100x */ # undef CONFIG_STM32_CONNECTIVITYLINE /* STM32F105x and STM32F107x */ # undef CONFIG_STM32_STM32F20XX /* STM32F205x and STM32F207x */ @@ -376,9 +470,9 @@ #elif defined(CONFIG_ARCH_CHIP_STM32F407VE) /* LQFP-100 512Kb FLASH 192Kb SRAM */ # undef CONFIG_STM32_STM32F10XX /* STM32F10xxx family */ -# undef CONFIG_STM32_LOWDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */ -# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */ -# undef CONFIG_STM32_HIGHDENSITY /* STM32F101x and STM32F103x w/ 256/512 Kbytes */ +# undef CONFIG_STM32_LOWDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */ +# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */ +# undef CONFIG_STM32_HIGHDENSITY /* STM32F100x, STM32F101x, and STM32F103x w/ 256/512 Kbytes */ # undef CONFIG_STM32_VALUELINE /* STM32F100x */ # undef CONFIG_STM32_CONNECTIVITYLINE /* STM32F105x and STM32F107x */ # undef CONFIG_STM32_STM32F20XX /* STM32F205x and STM32F207x */ @@ -407,9 +501,9 @@ #elif defined(CONFIG_ARCH_CHIP_STM32F407VG) /* LQFP-100 14x14x1.4 1024Kb FLASH 192Kb SRAM */ # undef CONFIG_STM32_STM32F10XX /* STM32F10xxx family */ -# undef CONFIG_STM32_LOWDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */ -# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */ -# undef CONFIG_STM32_HIGHDENSITY /* STM32F101x and STM32F103x w/ 256/512 Kbytes */ +# undef CONFIG_STM32_LOWDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */ +# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */ +# undef CONFIG_STM32_HIGHDENSITY /* STM32F100x, STM32F101x, and STM32F103x w/ 256/512 Kbytes */ # undef CONFIG_STM32_VALUELINE /* STM32F100x */ # undef CONFIG_STM32_CONNECTIVITYLINE /* STM32F105x and STM32F107x */ # undef CONFIG_STM32_STM32F20XX /* STM32F205x and STM32F207x */ @@ -438,9 +532,9 @@ #elif defined(CONFIG_ARCH_CHIP_STM32F407ZE) /* LQFP-144 512Kb FLASH 192Kb SRAM */ # undef CONFIG_STM32_STM32F10XX /* STM32F10xxx family */ -# undef CONFIG_STM32_LOWDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */ -# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */ -# undef CONFIG_STM32_HIGHDENSITY /* STM32F101x and STM32F103x w/ 256/512 Kbytes */ +# undef CONFIG_STM32_LOWDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */ +# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */ +# undef CONFIG_STM32_HIGHDENSITY /* STM32F100x, STM32F101x, and STM32F103x w/ 256/512 Kbytes */ # undef CONFIG_STM32_VALUELINE /* STM32F100x */ # undef CONFIG_STM32_CONNECTIVITYLINE /* STM32F105x and STM32F107x */ # undef CONFIG_STM32_STM32F20XX /* STM32F205x and STM32F207x */ @@ -469,9 +563,9 @@ #elif defined(CONFIG_ARCH_CHIP_STM32F407ZG) /* LQFP 144 20x20x1.4 1024Kb FLASH 192Kb SRAM */ # undef CONFIG_STM32_STM32F10XX /* STM32F10xxx family */ -# undef CONFIG_STM32_LOWDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */ -# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */ -# undef CONFIG_STM32_HIGHDENSITY /* STM32F101x and STM32F103x w/ 256/512 Kbytes */ +# undef CONFIG_STM32_LOWDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */ +# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */ +# undef CONFIG_STM32_HIGHDENSITY /* STM32F100x, STM32F101x, and STM32F103x w/ 256/512 Kbytes */ # undef CONFIG_STM32_VALUELINE /* STM32F100x */ # undef CONFIG_STM32_CONNECTIVITYLINE /* STM32F105x and STM32F107x */ # undef CONFIG_STM32_STM32F20XX /* STM32F205x and STM32F207x */ @@ -500,9 +594,9 @@ #elif defined(CONFIG_ARCH_CHIP_STM32F407IE) /* LQFP 176 24x24x1.4 512Kb FLASH 192Kb SRAM */ # undef CONFIG_STM32_STM32F10XX /* STM32F10xxx family */ -# undef CONFIG_STM32_LOWDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */ -# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */ -# undef CONFIG_STM32_HIGHDENSITY /* STM32F101x and STM32F103x w/ 256/512 Kbytes */ +# undef CONFIG_STM32_LOWDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */ +# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */ +# undef CONFIG_STM32_HIGHDENSITY /* STM32F100x, STM32F101x, and STM32F103x w/ 256/512 Kbytes */ # undef CONFIG_STM32_VALUELINE /* STM32F100x */ # undef CONFIG_STM32_CONNECTIVITYLINE /* STM32F105x and STM32F107x */ # undef CONFIG_STM32_STM32F20XX /* STM32F205x and STM32F207x */ @@ -531,9 +625,9 @@ #elif defined(CONFIG_ARCH_CHIP_STM32F407IG) /* BGA 176; LQFP 176 24x24x1.4 1024Kb FLASH 192Kb SRAM */ # undef CONFIG_STM32_STM32F10XX /* STM32F10xxx family */ -# undef CONFIG_STM32_LOWDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */ -# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */ -# undef CONFIG_STM32_HIGHDENSITY /* STM32F101x and STM32F103x w/ 256/512 Kbytes */ +# undef CONFIG_STM32_LOWDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 16/32 Kbytes */ +# undef CONFIG_STM32_MEDIUMDENSITY /* STM32F100x, STM32F101x, STM32F102x and STM32F103x w/ 64/128 Kbytes */ +# undef CONFIG_STM32_HIGHDENSITY /* STM32F100x, STM32F101x, and STM32F103x w/ 256/512 Kbytes */ # undef CONFIG_STM32_VALUELINE /* STM32F100x */ # undef CONFIG_STM32_CONNECTIVITYLINE /* STM32F105x and STM32F107x */ # undef CONFIG_STM32_STM32F20XX /* STM32F205x and STM32F207x */ diff --git a/nuttx/arch/arm/include/stm32/stm32f10xxx_irq.h b/nuttx/arch/arm/include/stm32/stm32f10xxx_irq.h index 67f4ba436..7c3f7cf95 100644 --- a/nuttx/arch/arm/include/stm32/stm32f10xxx_irq.h +++ b/nuttx/arch/arm/include/stm32/stm32f10xxx_irq.h @@ -61,11 +61,13 @@ * External interrupts (vectors >= 16) */ -#if defined(CONFIG_STM32_VALUELINE) && defined(CONFIG_STM32_MEDIUMDENSITY) + /* Value line devices */ + +#if defined(CONFIG_STM32_VALUELINE) # define STM32_IRQ_WWDG (16) /* 0: Window Watchdog interrupt */ # define STM32_IRQ_PVD (17) /* 1: PVD through EXTI Line detection interrupt */ # define STM32_IRQ_TAMPER (18) /* 2: Tamper interrupt */ -# define STM32_IRQ_RTC (19) /* 3: RTC global interrupt */ +# define STM32_IRQ_RTC (19) /* 3: RTC Wakeup through EXTI line interrupt */ # define STM32_IRQ_FLASH (20) /* 4: Flash global interrupt */ # define STM32_IRQ_RCC (21) /* 5: RCC global interrupt */ # define STM32_IRQ_EXTI0 (22) /* 6: EXTI Line 0 interrupt */ @@ -80,12 +82,18 @@ # define STM32_IRQ_DMA1CH5 (31) /* 15: DMA1 Channel 5 global interrupt */ # define STM32_IRQ_DMA1CH6 (32) /* 16: DMA1 Channel 6 global interrupt */ # define STM32_IRQ_DMA1CH7 (33) /* 17: DMA1 Channel 7 global interrupt */ -# define STM32_IRQ_ADC12 (34) /* 18: ADC1 and ADC2 global interrupt */ - /* 19-22: reserved */ +# define STM32_IRQ_ADC1 (34) /* 18: ADC1 global interrupt */ +# define STM32_IRQ_RESERVED0 (35) /* 19: Reserved 0 */ +# define STM32_IRQ_RESERVED1 (36) /* 20: Reserved 1 */ +# define STM32_IRQ_RESERVED2 (37) /* 21: Reserved 2 */ +# define STM32_IRQ_RESERVED3 (38) /* 22: Reserved 3 */ # define STM32_IRQ_EXTI95 (39) /* 23: EXTI Line[9:5] interrupts */ # define STM32_IRQ_TIM1BRK (40) /* 24: TIM1 Break interrupt */ -# define STM32_IRQ_TIM1UP (41) /* 25: TIM1 Update interrupt (TIM16 global interrupt) */ -# define STM32_IRQ_TIM1TRGCOM (42) /* 26: TIM1 Trigger and Commutation interrupts (TIM17 global interrupt) */ +# define STM32_IRQ_TIM15 (40) /* TIM15 global interrupt */ +# define STM32_IRQ_TIM1UP (41) /* 25: TIM1 Update interrupt */ +# define STM32_IRQ_TIM16 (41) /* TIM16 global interrupt */ +# define STM32_IRQ_TIM1TRGCOM (42) /* 26: TIM1 Trigger and Commutation interrupts */ +# define STM32_IRQ_TIM17 (42) /* TIM17 global interrupt */ # define STM32_IRQ_TIM1CC (43) /* 27: TIM1 Capture Compare interrupt */ # define STM32_IRQ_TIM2 (44) /* 28: TIM2 global interrupt */ # define STM32_IRQ_TIM3 (45) /* 29: TIM3 global interrupt */ @@ -100,29 +108,30 @@ # define STM32_IRQ_USART2 (54) /* 38: USART2 global interrupt */ # define STM32_IRQ_USART3 (55) /* 39: USART3 global interrupt */ # define STM32_IRQ_EXTI1510 (56) /* 40: EXTI Line[15:10] interrupts */ -# define STM32_IRQ_RTCALR (57) /* 41: RTC alarm through EXTI line interrupt */ +# define STM32_IRQ_RTCALR (57) /* 41: RTC alarms (A and B) through EXTI line interrupt */ # define STM32_IRQ_CEC (58) /* 42: CEC global interrupt */ -# if defined(CONFIG_STM32_HIGHDENSITY) -# define STM32_IRQ_TIM12 (59) /* 43: TIM12 global interrupt */ -# define STM32_IRQ_TIM13 (60) /* 44: TIM13 global interrupt */ -# define STM32_IRQ_TIM14 (61) /* 45: TIM14 global interrupt */ - /* 46-47: reserved */ -# define STM32_IRQ_FSMC (64) /* 48: FSMC global interrupt */ - /* 49: reserved */ -# define STM32_IRQ_TIM5 (66) /* 50: TIM5 global interrupt */ -# define STM32_IRQ_SPI3 (67) /* 51: SPI1 global interrupt */ -# define STM32_IRQ_UART4 (68) /* 52: USART2 global interrupt */ -# define STM32_IRQ_UART5 (69) /* 53: USART3 global interrupt */ -# else - /* 43-53: reserved */ -# endif +# define STM32_IRQ_TIM12 (59) /* 43: TIM12 global interrupt */ +# define STM32_IRQ_TIM13 (60) /* 44: TIM13 global interrupt */ +# define STM32_IRQ_TIM14 (61) /* 45: TIM14 global interrupt */ +# define STM32_IRQ_RESERVED4 (62) /* 46: Reserved 4 */ +# define STM32_IRQ_RESERVED5 (63) /* 47: Reserved 5 */ +# define STM32_IRQ_FSMC (64) /* 48: FSMC global interrupt */ +# define STM32_IRQ_RESERVED6 (65) /* 49: Reserved 6 */ +# define STM32_IRQ_TIM5 (66) /* 50: TIM5 global interrupt */ +# define STM32_IRQ_SPI3 (67) /* 51: SPI3 global interrupt */ +# define STM32_IRQ_UART4 (68) /* 52: USART2 global interrupt */ +# define STM32_IRQ_UART5 (69) /* 53: USART5 global interrupt */ # define STM32_IRQ_TIM6 (70) /* 54: TIM6 global interrupt */ # define STM32_IRQ_TIM7 (71) /* 55: TIM7 global interrupt */ # define STM32_IRQ_DMA2CH1 (72) /* 56: DMA2 Channel 1 global interrupt */ # define STM32_IRQ_DMA2CH2 (73) /* 57: DMA2 Channel 2 global interrupt */ # define STM32_IRQ_DMA2CH3 (74) /* 58: DMA2 Channel 3 global interrupt */ -# define STM32_IRQ_DMA2CH45 (75) /* 59: DMA2 Channel 4 global interrupt */ -# define NR_IRQS (76) +# define STM32_IRQ_DMA2CH45 (75) /* 59: DMA2 Channel 4 and 5 global interrupt */ +# define STM32_IRQ_DMA2CH5 (76) /* 60: DMA2 Channel 5 global interrupt */ +# define NR_IRQS (77) + +/* Connectivity Line Devices */ + #elif defined(CONFIG_STM32_CONNECTIVITYLINE) # define STM32_IRQ_WWDG (16) /* 0: Window Watchdog interrupt */ # define STM32_IRQ_PVD (17) /* 1: PVD through EXTI Line detection interrupt */ @@ -193,6 +202,9 @@ # define STM32_IRQ_CAN2SCE (82) /* 66: CAN2 SCE interrupt */ # define STM32_IRQ_OTGFS (83) /* 67: USB On The Go FS global interrupt */ # define NR_IRQS (84) + +/* Medium and High Density Devices */ + #else # define STM32_IRQ_WWDG (16) /* 0: Window Watchdog interrupt */ # define STM32_IRQ_PVD (17) /* 1: PVD through EXTI Line detection interrupt */ diff --git a/nuttx/arch/arm/src/Makefile b/nuttx/arch/arm/src/Makefile index 74be6c18d..e44def30c 100644 --- a/nuttx/arch/arm/src/Makefile +++ b/nuttx/arch/arm/src/Makefile @@ -36,58 +36,90 @@ -include $(TOPDIR)/Make.defs -include chip/Make.defs -ARCH_SRCDIR = $(TOPDIR)/arch/$(CONFIG_ARCH)/src ifeq ($(CONFIG_ARCH_CORTEXM3),y) # Cortex-M3 is ARMv7-M -ARCH_SUBDIR = armv7-m +ARCH_SUBDIR = armv7-m else ifeq ($(CONFIG_ARCH_CORTEXM4),y) # Cortex-M4 is ARMv7E-M -ARCH_SUBDIR = armv7-m +ARCH_SUBDIR = armv7-m else -ARCH_SUBDIR = arm +ARCH_SUBDIR = arm endif endif +ifeq ($(CONFIG_WINDOWS_NATIVE),y) + ARCH_SRCDIR = $(TOPDIR)\arch\$(CONFIG_ARCH)\src + NUTTX = "$(TOPDIR)\nuttx$(EXEEXT)" + CFLAGS += -I$(ARCH_SRCDIR)\chip + CFLAGS += -I$(ARCH_SRCDIR)\common + CFLAGS += -I$(ARCH_SRCDIR)\$(ARCH_SUBDIR) + CFLAGS += -I$(TOPDIR)\sched +else + ARCH_SRCDIR = $(TOPDIR)/arch/$(CONFIG_ARCH)/src ifeq ($(WINTOOL),y) - NUTTX = "${shell cygpath -w $(TOPDIR)/nuttx}" - CFLAGS += -I "${shell cygpath -w $(ARCH_SRCDIR)/chip}" \ - -I "${shell cygpath -w $(ARCH_SRCDIR)/common}" \ - -I "${shell cygpath -w $(ARCH_SRCDIR)/$(ARCH_SUBDIR)}" \ - -I "${shell cygpath -w $(TOPDIR)/sched}" + NUTTX = "${shell cygpath -w $(TOPDIR)/nuttx$(EXEEXT)}" + CFLAGS += -I "${shell cygpath -w $(ARCH_SRCDIR)/chip}" + CFLAGS += -I "${shell cygpath -w $(ARCH_SRCDIR)/common}" + CFLAGS += -I "${shell cygpath -w $(ARCH_SRCDIR)/$(ARCH_SUBDIR)}" + CFLAGS += -I "${shell cygpath -w $(TOPDIR)/sched}" else - NUTTX = $(TOPDIR)/nuttx - CFLAGS += -I$(ARCH_SRCDIR)/chip -I$(ARCH_SRCDIR)/common \ - -I$(ARCH_SRCDIR)/$(ARCH_SUBDIR) -I$(TOPDIR)/sched + NUTTX = "$(TOPDIR)/nuttx$(EXEEXT)" + CFLAGS += -I$(ARCH_SRCDIR)/chip + CFLAGS += -I$(ARCH_SRCDIR)/common + CFLAGS += -I$(ARCH_SRCDIR)/$(ARCH_SUBDIR) + CFLAGS += -I$(TOPDIR)/sched +endif endif -HEAD_OBJ = $(HEAD_ASRC:.S=$(OBJEXT)) +HEAD_OBJ = $(HEAD_ASRC:.S=$(OBJEXT)) + +ASRCS = $(CHIP_ASRCS) $(CMN_ASRCS) +AOBJS = $(ASRCS:.S=$(OBJEXT)) -ASRCS = $(CHIP_ASRCS) $(CMN_ASRCS) -AOBJS = $(ASRCS:.S=$(OBJEXT)) +CSRCS = $(CHIP_CSRCS) $(CMN_CSRCS) +COBJS = $(CSRCS:.c=$(OBJEXT)) -CSRCS = $(CHIP_CSRCS) $(CMN_CSRCS) -COBJS = $(CSRCS:.c=$(OBJEXT)) +SRCS = $(ASRCS) $(CSRCS) +OBJS = $(AOBJS) $(COBJS) -SRCS = $(ASRCS) $(CSRCS) -OBJS = $(AOBJS) $(COBJS) +LDFLAGS += $(ARCHSCRIPT) -LDFLAGS = $(ARCHSCRIPT) -EXTRA_LIBS ?= +EXTRA_LIBS ?= +EXTRA_LIBPATHS ?= +LINKLIBS ?= + +ifeq ($(CONFIG_WINDOWS_NATIVE),y) + BOARDMAKE = $(if $(wildcard .\board\Makefile),y,) + LIBPATHS += -L"$(TOPDIR)\lib" +ifeq ($(BOARDMAKE),y) + LIBPATHS += -L"$(TOPDIR)\arch\$(CONFIG_ARCH)\src\board" +endif + +else + BOARDMAKE = $(if $(wildcard ./board/Makefile),y,) -LINKLIBS = ifeq ($(WINTOOL),y) - LIBPATHS = ${shell for path in $(LINKLIBS); do dir=`dirname $(TOPDIR)/$$path`;echo "-L\"`cygpath -w $$dir`\"";done} - LIBPATHS += -L"${shell cygpath -w $(BOARDDIR)}" + LIBPATHS += -L"${shell cygpath -w "$(TOPDIR)/lib"}" +ifeq ($(BOARDMAKE),y) + LIBPATHS += -L"${shell cygpath -w "$(TOPDIR)/arch/$(CONFIG_ARCH)/src/board"}" +endif + else - LIBPATHS = $(addprefix -L$(TOPDIR)/,$(dir $(LINKLIBS))) - LIBPATHS += -L"$(BOARDDIR)" + LIBPATHS += -L"$(TOPDIR)/lib" +ifeq ($(BOARDMAKE),y) + LIBPATHS += -L"$(TOPDIR)/arch/$(CONFIG_ARCH)/src/board" +endif +endif endif -LDLIBS = $(patsubst lib%,-l%,$(basename $(notdir $(LINKLIBS)))) -BOARDDIR = $(TOPDIR)/arch/$(CONFIG_ARCH)/src/board +LDLIBS = $(patsubst %.a,%,$(patsubst lib%,-l%,$(LINKLIBS))) +ifeq ($(BOARDMAKE),y) + LDLIBS += -lboard +endif -LIBGCC = "${shell $(CC) $(ARCHCPUFLAGS) -print-libgcc-file-name}" +LIBGCC = "${shell "$(CC)" $(ARCHCPUFLAGS) -print-libgcc-file-name}" +GCC_LIBDIR := ${shell dirname $(LIBGCC)} -VPATH = chip:common:$(ARCH_SUBDIR) +VPATH = chip:common:$(ARCH_SUBDIR) all: $(HEAD_OBJ) libarch$(LIBEXT) @@ -100,20 +132,21 @@ $(COBJS): %$(OBJEXT): %.c $(call COMPILE, $<, $@) libarch$(LIBEXT): $(OBJS) - @( for obj in $(OBJS) ; do \ - $(call ARCHIVE, $@, $${obj}); \ - done ; ) + $(call ARCHIVE, $@, $(OBJS)) board/libboard$(LIBEXT): - @$(MAKE) -C board TOPDIR="$(TOPDIR)" libboard$(LIBEXT) EXTRADEFINES=$(EXTRADEFINES) - -nuttx: $(HEAD_OBJ) board/libboard$(LIBEXT) - @echo "LD: nuttx" - @$(LD) --entry=__start $(LDFLAGS) $(LIBPATHS) -o $(NUTTX)$(EXEEXT) $(HEAD_OBJ) $(EXTRA_OBJS) \ - --start-group $(LDLIBS) -lboard $(EXTRA_LIBS) $(LIBGCC) --end-group - @$(NM) $(NUTTX)$(EXEEXT) | \ + $(Q) $(MAKE) -C board TOPDIR="$(TOPDIR)" libboard$(LIBEXT) EXTRADEFINES=$(EXTRADEFINES) + +nuttx$(EXEEXT): $(HEAD_OBJ) board/libboard$(LIBEXT) + $(Q) echo "LD: nuttx" + $(Q) $(LD) --entry=__start $(LDFLAGS) $(LIBPATHS) $(EXTRA_LIBPATHS) \ + -o $(NUTTX)$(EXEEXT) $(HEAD_OBJ) $(EXTRA_OBJS) \ + --start-group $(LDLIBS) $(EXTRA_LIBS) $(LIBGCC) --end-group +ifneq ($(CONFIG_WINDOWS_NATIVE),y) + $(Q) $(NM) $(NUTTX)$(EXEEXT) | \ grep -v '\(compiled\)\|\(\$(OBJEXT)$$\)\|\( [aUw] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' | \ sort > $(TOPDIR)/System.map +endif # This is part of the top-level export target # Note that there may not be a head object if layout is handled @@ -121,37 +154,38 @@ nuttx: $(HEAD_OBJ) board/libboard$(LIBEXT) export_head: board/libboard$(LIBEXT) $(HEAD_OBJ) ifneq ($(HEAD_OBJ),) - @if [ -d "$(EXPORT_DIR)/startup" ]; then \ + $(Q) if [ -d "$(EXPORT_DIR)/startup" ]; then \ cp -f $(HEAD_OBJ) "$(EXPORT_DIR)/startup"; \ else \ echo "$(EXPORT_DIR)/startup does not exist"; \ - exit 1; \ - fi + exit 1; \ + fi endif # Dependencies .depend: Makefile chip/Make.defs $(SRCS) - @if [ -e board/Makefile ]; then \ - $(MAKE) -C board TOPDIR="$(TOPDIR)" depend ; \ - fi - @$(MKDEP) --dep-path chip --dep-path common --dep-path $(ARCH_SUBDIR) \ - $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep - @touch $@ +ifeq ($(BOARDMAKE),y) + $(Q) $(MAKE) -C board TOPDIR="$(TOPDIR)" depend +endif + $(Q) $(MKDEP) --dep-path chip --dep-path common --dep-path $(ARCH_SUBDIR) \ + "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep + $(Q) touch $@ depend: .depend clean: - @if [ -e board/Makefile ]; then \ - $(MAKE) -C board TOPDIR="$(TOPDIR)" clean ; \ - fi - @rm -f libarch$(LIBEXT) *~ .*.swp +ifeq ($(BOARDMAKE),y) + $(Q) $(MAKE) -C board TOPDIR="$(TOPDIR)" clean +endif + $(call DELFILE, libarch$(LIBEXT)) $(call CLEAN) distclean: clean - @if [ -e board/Makefile ]; then \ - $(MAKE) -C board TOPDIR="$(TOPDIR)" distclean ; \ - fi - @rm -f Make.dep .depend +ifeq ($(BOARDMAKE),y) + $(Q) $(MAKE) -C board TOPDIR="$(TOPDIR)" distclean +endif + $(call DELFILE, Make.dep) + $(call DELFILE, .depend) -include Make.dep diff --git a/nuttx/arch/arm/src/armv7-m/Kconfig b/nuttx/arch/arm/src/armv7-m/Kconfig new file mode 100644 index 000000000..dc5aa3915 --- /dev/null +++ b/nuttx/arch/arm/src/armv7-m/Kconfig @@ -0,0 +1,51 @@ +# +# For a description of the syntax of this configuration file, +# see misc/tools/kconfig-language.txt. +# + +comment "ARMV7M Configuration Options" + +choice + prompt "Toolchain Selection" + default ARMV7M_TOOLCHAIN_CODESOURCERYW if HOST_WINDOWS + default ARMV7M_TOOLCHAIN_GNU_EABI if !HOST_WINDOWS + +config ARMV7M_TOOLCHAIN_ATOLLIC + bool "Atollic Lite/Pro for Windows" + depends on HOST_WINDOWS + +config ARMV7M_TOOLCHAIN_BUILDROOT + bool "Buildroot (Cygwin or Linux)" + depends on !WINDOWS_NATIVE + +config ARMV7M_TOOLCHAIN_CODEREDL + bool "CodeRed for Linux" + depends on HOST_LINUX + +config ARMV7M_TOOLCHAIN_CODEREDW + bool "CodeRed for Windows" + depends on HOST_WINDOWS + +config ARMV7M_TOOLCHAIN_CODESOURCERYL + bool "CodeSourcery GNU toolchain under Linux" + depends on HOST_LINUX + +config ARMV7M_TOOLCHAIN_CODESOURCERYW + bool "CodeSourcery GNU toolchain under Windows" + depends on HOST_WINDOWS + +config ARMV7M_TOOLCHAIN_DEVKITARM + bool "devkitARM GNU toolchain" + depends on HOST_WINDOWS + +config ARMV7M_TOOLCHAIN_GNU_EABI + bool "Generic GNU EABI toolchain" + ---help--- + This option should work for any modern GNU toolchain (GCC 4.5 or newer) + configured for arm-none-eabi. + +config ARMV7M_TOOLCHAIN_RAISONANCE + bool "STMicro Raisonance for Windows" + depends on HOST_WINDOWS + +endchoice diff --git a/nuttx/arch/arm/src/armv7-m/memcpy.S b/nuttx/arch/arm/src/armv7-m/memcpy.S deleted file mode 100644 index c6d3ff649..000000000 --- a/nuttx/arch/arm/src/armv7-m/memcpy.S +++ /dev/null @@ -1,351 +0,0 @@ -@ -@ armv7m-optimised memcpy, apparently in the public domain -@ -@ Obtained via a posting on the Stellaris forum: -@ http://e2e.ti.com/support/microcontrollers/stellaris_arm_cortex-m3_microcontroller/f/473/t/44360.aspx -@ -@ Posted by rocksoft on Jul 24, 2008 10:19 AM -@ -@ Hi, -@ -@ I recently finished a "memcpy" replacement and thought it might be useful for others... -@ -@ I've put some instructions and the code here: -@ -@ http://www.rock-software.net/downloads/memcpy/ -@ -@ Hope it works for you as well as it did for me. -@ -@ Liam. -@ @ -@ ---------------------------------------------------------------------------- - -.syntax unified - -.thumb - -.cpu cortex-m3 - -@ ---------------------------------------------------------------------------- - - .global memcpy - - -@ ---------------------------------------------------------------------------- -@ Optimised "general" copy routine - -.text - -@ We have 16 possible alignment combinations of src and dst, this jump table directs the copy operation -@ Bits: Src=00, Dst=00 - Long to Long copy -@ Bits: Src=00, Dst=01 - Long to Byte before half word -@ Bits: Src=00, Dst=10 - Long to Half word -@ Bits: Src=00, Dst=11 - Long to Byte before long word -@ Bits: Src=01, Dst=00 - Byte before half word to long -@ Bits: Src=01, Dst=01 - Byte before half word to byte before half word - Same alignment -@ Bits: Src=01, Dst=10 - Byte before half word to half word -@ Bits: Src=01, Dst=11 - Byte before half word to byte before long word -@ Bits: Src=10, Dst=00 - Half word to long word -@ Bits: Src=10, Dst=01 - Half word to byte before half word -@ Bits: Src=10, Dst=10 - Half word to half word - Same Alignment -@ Bits: Src=10, Dst=11 - Half word to byte before long word -@ Bits: Src=11, Dst=00 - Byte before long word to long word -@ Bits: Src=11, Dst=01 - Byte before long word to byte before half word -@ Bits: Src=11, Dst=11 - Byte before long word to half word -@ Bits: Src=11, Dst=11 - Byte before long word to Byte before long word - Same alignment - -MEM_DataCopyTable: - .byte (MEM_DataCopy0 - MEM_DataCopyJump) >> 1 - .byte (MEM_DataCopy1 - MEM_DataCopyJump) >> 1 - .byte (MEM_DataCopy2 - MEM_DataCopyJump) >> 1 - .byte (MEM_DataCopy3 - MEM_DataCopyJump) >> 1 - .byte (MEM_DataCopy4 - MEM_DataCopyJump) >> 1 - .byte (MEM_DataCopy5 - MEM_DataCopyJump) >> 1 - .byte (MEM_DataCopy6 - MEM_DataCopyJump) >> 1 - .byte (MEM_DataCopy7 - MEM_DataCopyJump) >> 1 - .byte (MEM_DataCopy8 - MEM_DataCopyJump) >> 1 - .byte (MEM_DataCopy9 - MEM_DataCopyJump) >> 1 - .byte (MEM_DataCopy10 - MEM_DataCopyJump) >> 1 - .byte (MEM_DataCopy11 - MEM_DataCopyJump) >> 1 - .byte (MEM_DataCopy12 - MEM_DataCopyJump) >> 1 - .byte (MEM_DataCopy13 - MEM_DataCopyJump) >> 1 - .byte (MEM_DataCopy14 - MEM_DataCopyJump) >> 1 - .byte (MEM_DataCopy15 - MEM_DataCopyJump) >> 1 - - .align 2 - -@ ---------------------------------------------------------------------------- - -//#define 10 10 - -MEM_LongCopyTable: - .byte (MEM_LongCopyEnd - MEM_LongCopyJump) >> 1 @ 0 bytes left - .byte 0 @ 4 bytes left - .byte (1 * 10) >> 1 @ 8 bytes left - .byte (2 * 10) >> 1 @ 12 bytes left - .byte (3 * 10) >> 1 @ 16 bytes left - .byte (4 * 10) >> 1 @ 20 bytes left - .byte (5 * 10) >> 1 @ 24 bytes left - .byte (6 * 10) >> 1 @ 28 bytes left - .byte (7 * 10) >> 1 @ 32 bytes left - .byte (8 * 10) >> 1 @ 36 bytes left - - .align 2 - -@ ---------------------------------------------------------------------------- -@ r0 = destination, r1 = source, r2 = length - -.thumb_func - -memcpy: - push {r14} - - @ This allows the inner workings to "assume" a minimum amount of bytes - cmp r2, #4 - blt MEM_DataCopyBytes - - and r14, r0, #3 @ Get destination alignment bits - bfi r14, r1, #2, #2 @ Get source alignment bits - ldr r3, =MEM_DataCopyTable @ Jump table base - tbb [r3, r14] @ Perform jump on src/dst alignment bits -MEM_DataCopyJump: - - .align 4 - -@ ---------------------------------------------------------------------------- -@ Bits: Src=01, Dst=01 - Byte before half word to byte before half word - Same alignment -@ 3 bytes to read for long word aligning - -MEM_DataCopy5: - ldrb r3, [r1], #0x01 - strb r3, [r0], #0x01 - sub r2, r2, #0x01 - -@ ---------------------------------------------------------------------------- -@ Bits: Src=10, Dst=10 - Half word to half word - Same Alignment -@ 2 bytes to read for long word aligning - -MEM_DataCopy10: - ldrb r3, [r1], #0x01 - strb r3, [r0], #0x01 - sub r2, r2, #0x01 - -@ ---------------------------------------------------------------------------- -@ Bits: Src=11, Dst=11 - Byte before long word to Byte before long word - Same alignment -@ 1 bytes to read for long word aligning - -MEM_DataCopy15: - ldrb r3, [r1], #0x01 - strb r3, [r0], #0x01 - sub r2, r2, #0x01 - -@ ---------------------------------------------------------------------------- -@ Bits: Src=00, Dst=00 - Long to Long copy - -MEM_DataCopy0: - @ Save regs - push {r4-r12} - - cmp r2, #0x28 - blt MEM_DataCopy0_2 - -MEM_DataCopy0_1: - ldmia r1!, {r3-r12} - stmia r0!, {r3-r12} - sub r2, r2, #0x28 - cmp r2, #0x28 - bge MEM_DataCopy0_1 - -MEM_DataCopy0_2: - @ Copy remaining long words - ldr r14, =MEM_LongCopyTable - lsr r11, r2, #0x02 - tbb [r14, r11] - -MEM_LongCopyJump: - ldr.w r3, [r1], #0x04 @ 4 bytes remain - str.w r3, [r0], #0x04 - b MEM_LongCopyEnd - ldmia.w r1!, {r3-r4} @ 8 bytes remain - stmia.w r0!, {r3-r4} - b MEM_LongCopyEnd - ldmia.w r1!, {r3-r5} @ 12 bytes remain - stmia.w r0!, {r3-r5} - b MEM_LongCopyEnd - ldmia.w r1!, {r3-r6} @ 16 bytes remain - stmia.w r0!, {r3-r6} - b MEM_LongCopyEnd - ldmia.w r1!, {r3-r7} @ 20 bytes remain - stmia.w r0!, {r3-r7} - b MEM_LongCopyEnd - ldmia.w r1!, {r3-r8} @ 24 bytes remain - stmia.w r0!, {r3-r8} - b MEM_LongCopyEnd - ldmia.w r1!, {r3-r9} @ 28 bytes remain - stmia.w r0!, {r3-r9} - b MEM_LongCopyEnd - ldmia.w r1!, {r3-r10} @ 32 bytes remain - stmia.w r0!, {r3-r10} - b MEM_LongCopyEnd - ldmia.w r1!, {r3-r11} @ 36 bytes remain - stmia.w r0!, {r3-r11} - -MEM_LongCopyEnd: - pop {r4-r12} - and r2, r2, #0x03 @ All the longs have been copied - -@ ---------------------------------------------------------------------------- - -MEM_DataCopyBytes: - @ Deal with up to 3 remaining bytes - cmp r2, #0x00 - it eq - popeq {pc} - ldrb r3, [r1], #0x01 - strb r3, [r0], #0x01 - subs r2, r2, #0x01 - it eq - popeq {pc} - ldrb r3, [r1], #0x01 - strb r3, [r0], #0x01 - subs r2, r2, #0x01 - it eq - popeq {pc} - ldrb r3, [r1], #0x01 - strb r3, [r0], #0x01 - pop {pc} - - .align 4 - -@ ---------------------------------------------------------------------------- -@ Bits: Src=01, Dst=11 - Byte before half word to byte before long word -@ 3 bytes to read for long word aligning the source - -MEM_DataCopy7: - ldrb r3, [r1], #0x01 - strb r3, [r0], #0x01 - sub r2, r2, #0x01 - -@ ---------------------------------------------------------------------------- -@ Bits: Src=10, Dst=00 - Half word to long word -@ 2 bytes to read for long word aligning the source - -MEM_DataCopy8: - ldrb r3, [r1], #0x01 - strb r3, [r0], #0x01 - sub r2, r2, #0x01 - -@ ---------------------------------------------------------------------------- -@ Bits: Src=11, Dst=01 - Byte before long word to byte before half word -@ 1 byte to read for long word aligning the source - -MEM_DataCopy13: - ldrb r3, [r1], #0x01 - strb r3, [r0], #0x01 - sub r2, r2, #0x01 - -@ ---------------------------------------------------------------------------- -@ Bits: Src=00, Dst=10 - Long to Half word - -MEM_DataCopy2: - cmp r2, #0x28 - blt MEM_DataCopy2_1 - - @ Save regs - push {r4-r12} -MEM_DataCopy2_2: - ldmia r1!, {r3-r12} - - strh r3, [r0], #0x02 - - lsr r3, r3, #0x10 - bfi r3, r4, #0x10, #0x10 - lsr r4, r4, #0x10 - bfi r4, r5, #0x10, #0x10 - lsr r5, r5, #0x10 - bfi r5, r6, #0x10, #0x10 - lsr r6, r6, #0x10 - bfi r6, r7, #0x10, #0x10 - lsr r7, r7, #0x10 - bfi r7, r8, #0x10, #0x10 - lsr r8, r8, #0x10 - bfi r8, r9, #0x10, #0x10 - lsr r9, r9, #0x10 - bfi r9, r10, #0x10, #0x10 - lsr r10, r10, #0x10 - bfi r10, r11, #0x10, #0x10 - lsr r11, r11, #0x10 - bfi r11, r12, #0x10, #0x10 - stmia r0!, {r3-r11} - lsr r12, r12, #0x10 - strh r12, [r0], #0x02 - - sub r2, r2, #0x28 - cmp r2, #0x28 - bge MEM_DataCopy2_2 - pop {r4-r12} - -MEM_DataCopy2_1: @ Read longs and write 2 x half words - cmp r2, #4 - blt MEM_DataCopyBytes - ldr r3, [r1], #0x04 - strh r3, [r0], #0x02 - lsr r3, r3, #0x10 - strh r3, [r0], #0x02 - sub r2, r2, #0x04 - b MEM_DataCopy2 - -@ ---------------------------------------------------------------------------- -@ Bits: Src=01, Dst=00 - Byte before half word to long -@ Bits: Src=01, Dst=10 - Byte before half word to half word -@ 3 bytes to read for long word aligning the source - -MEM_DataCopy4: -MEM_DataCopy6: - @ Read B and write B - ldrb r3, [r1], #0x01 - strb r3, [r0], #0x01 - sub r2, r2, #0x01 - -@ ---------------------------------------------------------------------------- -@ Bits: Src=10, Dst=01 - Half word to byte before half word -@ Bits: Src=10, Dst=11 - Half word to byte before long word -@ 2 bytes to read for long word aligning the source - -MEM_DataCopy9: -MEM_DataCopy11: - ldrb r3, [r1], #0x01 - strb r3, [r0], #0x01 - sub r2, r2, #0x01 - -@ ---------------------------------------------------------------------------- -@ Bits: Src=11, Dst=00 - Byte before long word to long word -@ Bits: Src=11, Dst=11 - Byte before long word to half word -@ 1 byte to read for long word aligning the source - -MEM_DataCopy12: -MEM_DataCopy14: - @ Read B and write B - ldrb r3, [r1], #0x01 - strb r3, [r0], #0x01 - sub r2, r2, #0x01 - -@ ---------------------------------------------------------------------------- -@ Bits: Src=00, Dst=01 - Long to Byte before half word -@ Bits: Src=00, Dst=11 - Long to Byte before long word - -MEM_DataCopy1: @ Read longs, write B->H->B -MEM_DataCopy3: - cmp r2, #4 - blt MEM_DataCopyBytes - ldr r3, [r1], #0x04 - strb r3, [r0], #0x01 - lsr r3, r3, #0x08 - strh r3, [r0], #0x02 - lsr r3, r3, #0x10 - strb r3, [r0], #0x01 - sub r2, r2, #0x04 - b MEM_DataCopy3 - -@ ---------------------------------------------------------------------------- - diff --git a/nuttx/arch/arm/src/armv7-m/up_elf.c b/nuttx/arch/arm/src/armv7-m/up_elf.c new file mode 100644 index 000000000..b838a6905 --- /dev/null +++ b/nuttx/arch/arm/src/armv7-m/up_elf.c @@ -0,0 +1,450 @@ +/**************************************************************************** + * arch/arm/src/armv7-m/up_elf.c + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include +#include +#include + +#include +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: arch_checkarch + * + * Description: + * Given the ELF header in 'hdr', verify that the ELF file is appropriate + * for the current, configured architecture. Every architecture that uses + * the ELF loader must provide this function. + * + * Input Parameters: + * hdr - The ELF header read from the ELF file. + * + * Returned Value: + * True if the architecture supports this ELF file. + * + ****************************************************************************/ + +bool arch_checkarch(FAR const Elf32_Ehdr *ehdr) +{ + /* Make sure it's an ARM executable */ + + if (ehdr->e_machine != EM_ARM) + { + bdbg("Not for ARM: e_machine=%04x\n", ehdr->e_machine); + return -ENOEXEC; + } + + /* Make sure that 32-bit objects are supported */ + + if (ehdr->e_ident[EI_CLASS] != ELFCLASS32) + { + bdbg("Need 32-bit objects: e_ident[EI_CLASS]=%02x\n", ehdr->e_ident[EI_CLASS]); + return -ENOEXEC; + } + + /* Verify endian-ness */ + +#ifdef CONFIG_ENDIAN_BIG + if (ehdr->e_ident[EI_DATA] != ELFDATA2MSB) +#else + if (ehdr->e_ident[EI_DATA] != ELFDATA2LSB) +#endif + { + bdbg("Wrong endian-ness: e_ident[EI_DATA]=%02x\n", ehdr->e_ident[EI_DATA]); + return -ENOEXEC; + } + + /* TODO: Check ABI here. */ + return OK; +} + +/**************************************************************************** + * Name: arch_relocate and arch_relocateadd + * + * Description: + * Perform on architecture-specific ELF relocation. Every architecture + * that uses the ELF loader must provide this function. + * + * Input Parameters: + * rel - The relocation type + * sym - The ELF symbol structure containing the fully resolved value. + * addr - The address that requires the relocation. + * + * Returned Value: + * Zero (OK) if the relocation was successful. Otherwise, a negated errno + * value indicating the cause of the relocation failure. + * + ****************************************************************************/ + +int arch_relocate(FAR const Elf32_Rel *rel, FAR const Elf32_Sym *sym, + uintptr_t addr) +{ + int32_t offset; + uint32_t upper_insn; + uint32_t lower_insn; + + switch (ELF32_R_TYPE(rel->r_info)) + { + case R_ARM_NONE: + { + /* No relocation */ + } + break; + + case R_ARM_PC24: + case R_ARM_CALL: + case R_ARM_JUMP24: + { + bvdbg("Performing PC24 [%d] link at addr %08lx [%08lx] to sym '%s' st_value=%08lx\n", + ELF32_R_TYPE(rel->r_info), (long)addr, (long)(*(uint32_t*)addr), + sym, (long)sym->st_value); + + offset = (*(uint32_t*)addr & 0x00ffffff) << 2; + if (offset & 0x02000000) + { + offset -= 0x04000000; + } + + offset += sym->st_value - addr; + if (offset & 3 || offset <= (int32_t) 0xfe000000 || offset >= (int32_t) 0x02000000) + { + bdbg(" ERROR: PC24 [%d] relocation out of range, offset=%08lx\n", + ELF32_R_TYPE(rel->r_info), offset); + + return -EINVAL; + } + + offset >>= 2; + + *(uint32_t*)addr &= 0xff000000; + *(uint32_t*)addr |= offset & 0x00ffffff; + } + break; + + case R_ARM_ABS32: + case R_ARM_TARGET1: /* New ABI: TARGET1 always treated as ABS32 */ + { + bvdbg("Performing ABS32 link at addr=%08lx [%08lx] to sym=%p st_value=%08lx\n", + (long)addr, (long)(*(uint32_t*)addr), sym, (long)sym->st_value); + + *(uint32_t*)addr += sym->st_value; + } + break; + + case R_ARM_THM_CALL: + case R_ARM_THM_JUMP24: + { + uint32_t S; + uint32_t J1; + uint32_t J2; + + /* Thumb BL and B.W instructions. Encoding: + * + * upper_insn: + * + * 1 1 1 1 1 1 + * 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 + * +----------+---+-------------------------------+--------------+ + * |1 1 1 |OP1| OP2 | | 32-Bit Instructions + * +----------+---+--+-----+----------------------+--------------+ + * |1 1 1 | 1 0| S | imm10 | BL Instruction + * +----------+------+-----+-------------------------------------+ + * + * lower_insn: + * + * 1 1 1 1 1 1 + * 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 + * +---+---------------------------------------------------------+ + * |OP | | 32-Bit Instructions + * +---+--+---+---+---+------------------------------------------+ + * |1 1 |J1 | 1 |J2 | imm11 | BL Instruction + * +------+---+---+---+------------------------------------------+ + * + * The branch target is encoded in these bits: + * + * S = upper_insn[10] + * imm10 = upper_insn[0:9] + * imm11 = lower_insn[0:10] + * J1 = lower_insn[13] + * J2 = lower_insn[11] + */ + + upper_insn = (uint32_t)(*(uint16_t*)addr); + lower_insn = (uint32_t)(*(uint16_t*)(addr + 2)); + + bvdbg("Performing THM_JUMP24 [%d] link at addr=%08lx [%04x %04x] to sym=%p st_value=%08lx\n", + ELF32_R_TYPE(rel->r_info), (long)addr, (int)upper_insn, (int)lower_insn, + sym, (long)sym->st_value); + + /* Extract the 25-bit offset from the 32-bit instruction: + * + * offset[24] = S + * offset[23] = ~(J1 ^ S) + * offset[22] = ~(J2 ^ S)] + * offset[12:21] = imm10 + * offset[1:11] = imm11 + * offset[0] = 0 + */ + + S = (upper_insn >> 10) & 1; + J1 = (lower_insn >> 13) & 1; + J2 = (lower_insn >> 11) & 1; + + offset = (S << 24) | /* S - > offset[24] */ + ((~(J1 ^ S) & 1) << 23) | /* J1 -> offset[23] */ + ((~(J2 ^ S) & 1) << 22) | /* J2 -> offset[22] */ + ((upper_insn & 0x03ff) << 12) | /* imm10 -> offset[12:21] */ + ((lower_insn & 0x07ff) << 1); /* imm11 -> offset[1:11] */ + /* 0 -> offset[0] */ + + /* Sign extend */ + + if (offset & 0x01000000) + { + offset -= 0x02000000; + } + + /* And perform the relocation */ + + bvdbg(" S=%d J1=%d J2=%d offset=%08lx branch target=%08lx\n", + S, J1, J2, (long)offset, offset + sym->st_value - addr); + + offset += sym->st_value - addr; + + /* Is this a function symbol? If so, then the branch target must be + * an odd Thumb address + */ + + if (ELF32_ST_TYPE(sym->st_info) == STT_FUNC && (offset & 1) == 0) + { + bdbg(" ERROR: JUMP24 [%d] requires odd offset, offset=%08lx\n", + ELF32_R_TYPE(rel->r_info), offset); + + return -EINVAL; + } + + /* Check the range of the offset */ + + if (offset <= (int32_t)0xff000000 || offset >= (int32_t)0x01000000) + { + bdbg(" ERROR: JUMP24 [%d] relocation out of range, branch taget=%08lx\n", + ELF32_R_TYPE(rel->r_info), offset); + + return -EINVAL; + } + + /* Now, reconstruct the 32-bit instruction using the new, relocated + * branch target. + */ + + S = (offset >> 24) & 1; + J1 = S ^ (~(offset >> 23) & 1); + J2 = S ^ (~(offset >> 22) & 1); + + upper_insn = ((upper_insn & 0xf800) | (S << 10) | ((offset >> 12) & 0x03ff)); + *(uint16_t*)addr = (uint16_t)upper_insn; + + lower_insn = ((lower_insn & 0xd000) | (J1 << 13) | (J2 << 11) | ((offset >> 1) & 0x07ff)); + *(uint16_t*)(addr + 2) = (uint16_t)lower_insn; + + bvdbg(" S=%d J1=%d J2=%d insn [%04x %04x]\n", + S, J1, J2, (int)upper_insn, (int)lower_insn); + } + break; + + case R_ARM_V4BX: + { + bvdbg("Performing V4BX link at addr=%08lx [%08lx]\n", + (long)addr, (long)(*(uint32_t*)addr)); + + /* Preserve only Rm and the condition code */ + + *(uint32_t*)addr &= 0xf000000f; + + /* Change instruction to 'mov pc, Rm' */ + + *(uint32_t*)addr |= 0x01a0f000; + } + break; + + case R_ARM_PREL31: + { + bvdbg("Performing PREL31 link at addr=%08lx [%08lx] to sym=%p st_value=%08lx\n", + (long)addr, (long)(*(uint32_t*)addr), sym, (long)sym->st_value); + + offset = *(uint32_t*)addr + sym->st_value - addr; + *(uint32_t*)addr = offset & 0x7fffffff; + } + break; + + case R_ARM_MOVW_ABS_NC: + case R_ARM_MOVT_ABS: + { + bvdbg("Performing MOVx_ABS [%d] link at addr=%08lx [%08lx] to sym=%p st_value=%08lx\n", + ELF32_R_TYPE(rel->r_info), (long)addr, (long)(*(uint32_t*)addr), + sym, (long)sym->st_value); + + offset = *(uint32_t*)addr; + offset = ((offset & 0xf0000) >> 4) | (offset & 0xfff); + offset = (offset ^ 0x8000) - 0x8000; + + offset += sym->st_value; + if (ELF32_R_TYPE(rel->r_info) == R_ARM_MOVT_ABS) + { + offset >>= 16; + } + + *(uint32_t*)addr &= 0xfff0f000; + *(uint32_t*)addr |= ((offset & 0xf000) << 4) | (offset & 0x0fff); + } + break; + + case R_ARM_THM_MOVW_ABS_NC: + case R_ARM_THM_MOVT_ABS: + { + /* Thumb BL and B.W instructions. Encoding: + * + * upper_insn: + * + * 1 1 1 1 1 1 + * 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 + * +----------+---+-------------------------------+--------------+ + * |1 1 1 |OP1| OP2 | | 32-Bit Instructions + * +----------+---+--+-----+----------------------+--------------+ + * |1 1 1 | 1 0| i | 1 0 1 1 0 0 | imm4 | MOVT Instruction + * +----------+------+-----+----------------------+--------------+ + * + * lower_insn: + * + * 1 1 1 1 1 1 + * 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 + * +---+---------------------------------------------------------+ + * |OP | | 32-Bit Instructions + * +---+----------+--------------+-------------------------------+ + * |0 | imm3 | Rd | imm8 | MOVT Instruction + * +---+----------+--------------+-------------------------------+ + * + * The 16-bit immediate value is encoded in these bits: + * + * i = imm16[11] = upper_insn[10] + * imm4 = imm16[12:15] = upper_insn[3:0] + * imm3 = imm16[8:10] = lower_insn[14:12] + * imm8 = imm16[0:7] = lower_insn[7:0] + */ + + upper_insn = (uint32_t)(*(uint16_t*)addr); + lower_insn = (uint32_t)(*(uint16_t*)(addr + 2)); + + bvdbg("Performing THM_MOVx [%d] link at addr=%08lx [%04x %04x] to sym=%p st_value=%08lx\n", + ELF32_R_TYPE(rel->r_info), (long)addr, (int)upper_insn, (int)lower_insn, + sym, (long)sym->st_value); + + /* Extract the 16-bit offset from the 32-bit instruction */ + + offset = ((upper_insn & 0x000f) << 12) | /* imm4 -> imm16[8:10] */ + ((upper_insn & 0x0400) << 1) | /* i -> imm16[11] */ + ((lower_insn & 0x7000) >> 4) | /* imm3 -> imm16[8:10] */ + (lower_insn & 0x00ff); /* imm8 -> imm16[0:7] */ + + /* Sign extend */ + + offset = (offset ^ 0x8000) - 0x8000; + + /* And perform the relocation */ + + bvdbg(" offset=%08lx branch target=%08lx\n", + (long)offset, offset + sym->st_value); + + offset += sym->st_value; + + /* Update the immediate value in the instruction. For MOVW we want the bottom + * 16-bits; for MOVT we want the top 16-bits. + */ + + if (ELF32_R_TYPE(rel->r_info) == R_ARM_THM_MOVT_ABS) + { + offset >>= 16; + } + + upper_insn = ((upper_insn & 0xfbf0) | ((offset & 0xf000) >> 12) | ((offset & 0x0800) >> 1)); + *(uint16_t*)addr = (uint16_t)upper_insn; + + lower_insn = ((lower_insn & 0x8f00) | ((offset & 0x0700) << 4) | (offset & 0x00ff)); + *(uint16_t*)(addr + 2) = (uint16_t)lower_insn; + + bvdbg(" insn [%04x %04x]\n", + (int)upper_insn, (int)lower_insn); + } + break; + + default: + bdbg("Unsupported relocation: %d\n", ELF32_R_TYPE(rel->r_info)); + return -EINVAL; + } + + return OK; +} + +int arch_relocateadd(FAR const Elf32_Rela *rel, FAR const Elf32_Sym *sym, + uintptr_t addr) +{ + bdbg("RELA relocation not supported\n"); + return -ENOSYS; +} + diff --git a/nuttx/arch/arm/src/armv7-m/up_hardfault.c b/nuttx/arch/arm/src/armv7-m/up_hardfault.c index cb3ce9e8a..c30015ad2 100644 --- a/nuttx/arch/arm/src/armv7-m/up_hardfault.c +++ b/nuttx/arch/arm/src/armv7-m/up_hardfault.c @@ -57,9 +57,7 @@ /* Debug output from this file may interfere with context switching! */ -#undef DEBUG_HARDFAULTS /* Define to debug hard faults */ - -#ifdef DEBUG_HARDFAULTS +#ifdef CONFIG_DEBUG_HARDFAULT # define hfdbg(format, arg...) lldbg(format, ##arg) #else # define hfdbg(x...) diff --git a/nuttx/arch/arm/src/armv7-m/up_memcpy.S b/nuttx/arch/arm/src/armv7-m/up_memcpy.S new file mode 100644 index 000000000..a154cab61 --- /dev/null +++ b/nuttx/arch/arm/src/armv7-m/up_memcpy.S @@ -0,0 +1,416 @@ +/************************************************************************************ + * nuttx/arch/arm/src/armv7-m/up_memcpy.S + * + * armv7m-optimised memcpy, contributed by Mike Smith. Apparently in the public + * domain and is re-released here under the modified BSD license: + * + * Obtained via a posting on the Stellaris forum: + * http://e2e.ti.com/support/microcontrollers/\ + * stellaris_arm_cortex-m3_microcontroller/f/473/t/44360.aspx + * + * Posted by rocksoft on Jul 24, 2008 10:19 AM + * + * Hi, + * + * I recently finished a "memcpy" replacement and thought it might be useful for + * others... + * + * I've put some instructions and the code here: + * + * http://www.rock-software.net/downloads/memcpy/ + * + * Hope it works for you as well as it did for me. + * + * Liam. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ************************************************************************************/ + +/************************************************************************************ + * Global Symbols + ************************************************************************************/ + + .global memcpy + + .syntax unified + .thumb + .cpu cortex-m3 + .file "up_memcpy.S" + +/************************************************************************************ + * .text + ************************************************************************************/ + + .text + +/************************************************************************************ + * Private Constant Data + ************************************************************************************/ + +/* We have 16 possible alignment combinations of src and dst, this jump table + * directs the copy operation + * + * Bits: Src=00, Dst=00 - Long to Long copy + * Bits: Src=00, Dst=01 - Long to Byte before half word + * Bits: Src=00, Dst=10 - Long to Half word + * Bits: Src=00, Dst=11 - Long to Byte before long word + * Bits: Src=01, Dst=00 - Byte before half word to long + * Bits: Src=01, Dst=01 - Byte before half word to byte before half word - + * Same alignment + * Bits: Src=01, Dst=10 - Byte before half word to half word + * Bits: Src=01, Dst=11 - Byte before half word to byte before long word + * Bits: Src=10, Dst=00 - Half word to long word + * Bits: Src=10, Dst=01 - Half word to byte before half word + * Bits: Src=10, Dst=10 - Half word to half word - Same Alignment + * Bits: Src=10, Dst=11 - Half word to byte before long word + * Bits: Src=11, Dst=00 - Byte before long word to long word + * Bits: Src=11, Dst=01 - Byte before long word to byte before half word + * Bits: Src=11, Dst=11 - Byte before long word to half word + * Bits: Src=11, Dst=11 - Byte before long word to Byte before long word - + * Same alignment + */ + +MEM_DataCopyTable: + .byte (MEM_DataCopy0 - MEM_DataCopyJump) >> 1 + .byte (MEM_DataCopy1 - MEM_DataCopyJump) >> 1 + .byte (MEM_DataCopy2 - MEM_DataCopyJump) >> 1 + .byte (MEM_DataCopy3 - MEM_DataCopyJump) >> 1 + .byte (MEM_DataCopy4 - MEM_DataCopyJump) >> 1 + .byte (MEM_DataCopy5 - MEM_DataCopyJump) >> 1 + .byte (MEM_DataCopy6 - MEM_DataCopyJump) >> 1 + .byte (MEM_DataCopy7 - MEM_DataCopyJump) >> 1 + .byte (MEM_DataCopy8 - MEM_DataCopyJump) >> 1 + .byte (MEM_DataCopy9 - MEM_DataCopyJump) >> 1 + .byte (MEM_DataCopy10 - MEM_DataCopyJump) >> 1 + .byte (MEM_DataCopy11 - MEM_DataCopyJump) >> 1 + .byte (MEM_DataCopy12 - MEM_DataCopyJump) >> 1 + .byte (MEM_DataCopy13 - MEM_DataCopyJump) >> 1 + .byte (MEM_DataCopy14 - MEM_DataCopyJump) >> 1 + .byte (MEM_DataCopy15 - MEM_DataCopyJump) >> 1 + + .align 2 + +MEM_LongCopyTable: + .byte (MEM_LongCopyEnd - MEM_LongCopyJump) >> 1 /* 0 bytes left */ + .byte 0 /* 4 bytes left */ + .byte (1 * 10) >> 1 /* 8 bytes left */ + .byte (2 * 10) >> 1 /* 12 bytes left */ + .byte (3 * 10) >> 1 /* 16 bytes left */ + .byte (4 * 10) >> 1 /* 20 bytes left */ + .byte (5 * 10) >> 1 /* 24 bytes left */ + .byte (6 * 10) >> 1 /* 28 bytes left */ + .byte (7 * 10) >> 1 /* 32 bytes left */ + .byte (8 * 10) >> 1 /* 36 bytes left */ + + .align 2 + +/************************************************************************************ + * Public Functions + ************************************************************************************/ +/************************************************************************************ + * Name: memcpy + * + * Description: + * Optimised "general" copy routine + * + * Input Parameters: + * r0 = destination, r1 = source, r2 = length + * + ************************************************************************************/ + + .thumb_func +memcpy: + push {r14} + + /* This allows the inner workings to "assume" a minimum amount of bytes */ + /* Quickly check for very short copies */ + + cmp r2, #4 + blt MEM_DataCopyBytes + + and r14, r0, #3 /* Get destination alignment bits */ + bfi r14, r1, #2, #2 /* Get source alignment bits */ + ldr r3, =MEM_DataCopyTable /* Jump table base */ + tbb [r3, r14] /* Perform jump on src/dst alignment bits */ +MEM_DataCopyJump: + + .align 4 + +/* Bits: Src=01, Dst=01 - Byte before half word to byte before half word - Same alignment + * 3 bytes to read for long word aligning + */ + +MEM_DataCopy5: + ldrb r3, [r1], #0x01 + strb r3, [r0], #0x01 + sub r2, r2, #0x01 + +/* Bits: Src=10, Dst=10 - Half word to half word - Same Alignment + * 2 bytes to read for long word aligning + */ + +MEM_DataCopy10: + ldrb r3, [r1], #0x01 + strb r3, [r0], #0x01 + sub r2, r2, #0x01 + +/* Bits: Src=11, Dst=11 - Byte before long word to Byte before long word - Same alignment + * 1 bytes to read for long word aligning + */ + +MEM_DataCopy15: + ldrb r3, [r1], #0x01 + strb r3, [r0], #0x01 + sub r2, r2, #0x01 + +/* Bits: Src=00, Dst=00 - Long to Long copy */ + +MEM_DataCopy0: + /* Save regs that may be used by memcpy */ + + push {r4-r12} + + /* Check for short word-aligned copy */ + + cmp r2, #0x28 + blt MEM_DataCopy0_2 + + /* Bulk copy loop */ + +MEM_DataCopy0_1: + ldmia r1!, {r3-r12} + stmia r0!, {r3-r12} + sub r2, r2, #0x28 + cmp r2, #0x28 + bge MEM_DataCopy0_1 + + /* Copy remaining long words */ + +MEM_DataCopy0_2: + /* Copy remaining long words */ + + ldr r14, =MEM_LongCopyTable + lsr r11, r2, #0x02 + tbb [r14, r11] + + /* longword copy branch table anchor */ + +MEM_LongCopyJump: + ldr.w r3, [r1], #0x04 /* 4 bytes remain */ + str.w r3, [r0], #0x04 + b MEM_LongCopyEnd + ldmia.w r1!, {r3-r4} /* 8 bytes remain */ + stmia.w r0!, {r3-r4} + b MEM_LongCopyEnd + ldmia.w r1!, {r3-r5} /* 12 bytes remain */ + stmia.w r0!, {r3-r5} + b MEM_LongCopyEnd + ldmia.w r1!, {r3-r6} /* 16 bytes remain */ + stmia.w r0!, {r3-r6} + b MEM_LongCopyEnd + ldmia.w r1!, {r3-r7} /* 20 bytes remain */ + stmia.w r0!, {r3-r7} + b MEM_LongCopyEnd + ldmia.w r1!, {r3-r8} /* 24 bytes remain */ + stmia.w r0!, {r3-r8} + b MEM_LongCopyEnd + ldmia.w r1!, {r3-r9} /* 28 bytes remain */ + stmia.w r0!, {r3-r9} + b MEM_LongCopyEnd + ldmia.w r1!, {r3-r10} /* 32 bytes remain */ + stmia.w r0!, {r3-r10} + b MEM_LongCopyEnd + ldmia.w r1!, {r3-r11} /* 36 bytes remain */ + stmia.w r0!, {r3-r11} + +MEM_LongCopyEnd: + pop {r4-r12} + and r2, r2, #0x03 /* All the longs have been copied */ + + /* Deal with up to 3 remaining bytes */ + +MEM_DataCopyBytes: + /* Deal with up to 3 remaining bytes */ + + cmp r2, #0x00 + it eq + popeq {pc} + ldrb r3, [r1], #0x01 + strb r3, [r0], #0x01 + subs r2, r2, #0x01 + it eq + popeq {pc} + ldrb r3, [r1], #0x01 + strb r3, [r0], #0x01 + subs r2, r2, #0x01 + it eq + popeq {pc} + ldrb r3, [r1], #0x01 + strb r3, [r0], #0x01 + pop {pc} + + .align 4 + +/* Bits: Src=01, Dst=11 - Byte before half word to byte before long word + * 3 bytes to read for long word aligning the source + */ + +MEM_DataCopy7: + ldrb r3, [r1], #0x01 + strb r3, [r0], #0x01 + sub r2, r2, #0x01 + +/* Bits: Src=10, Dst=00 - Half word to long word + * 2 bytes to read for long word aligning the source + */ + +MEM_DataCopy8: + ldrb r3, [r1], #0x01 + strb r3, [r0], #0x01 + sub r2, r2, #0x01 + +/* Bits: Src=11, Dst=01 - Byte before long word to byte before half word + * 1 byte to read for long word aligning the source + */ + +MEM_DataCopy13: + ldrb r3, [r1], #0x01 + strb r3, [r0], #0x01 + sub r2, r2, #0x01 + +/* Bits: Src=00, Dst=10 - Long to Half word */ + +MEM_DataCopy2: + cmp r2, #0x28 + blt MEM_DataCopy2_1 + + /* Save regs */ + + push {r4-r12} + + /* Bulk copy loop */ + +MEM_DataCopy2_2: + ldmia r1!, {r3-r12} + + strh r3, [r0], #0x02 + + lsr r3, r3, #0x10 + bfi r3, r4, #0x10, #0x10 + lsr r4, r4, #0x10 + bfi r4, r5, #0x10, #0x10 + lsr r5, r5, #0x10 + bfi r5, r6, #0x10, #0x10 + lsr r6, r6, #0x10 + bfi r6, r7, #0x10, #0x10 + lsr r7, r7, #0x10 + bfi r7, r8, #0x10, #0x10 + lsr r8, r8, #0x10 + bfi r8, r9, #0x10, #0x10 + lsr r9, r9, #0x10 + bfi r9, r10, #0x10, #0x10 + lsr r10, r10, #0x10 + bfi r10, r11, #0x10, #0x10 + lsr r11, r11, #0x10 + bfi r11, r12, #0x10, #0x10 + stmia r0!, {r3-r11} + lsr r12, r12, #0x10 + strh r12, [r0], #0x02 + + sub r2, r2, #0x28 + cmp r2, #0x28 + bge MEM_DataCopy2_2 + pop {r4-r12} + +MEM_DataCopy2_1: /* Read longs and write 2 x half words */ + cmp r2, #4 + blt MEM_DataCopyBytes + ldr r3, [r1], #0x04 + strh r3, [r0], #0x02 + lsr r3, r3, #0x10 + strh r3, [r0], #0x02 + sub r2, r2, #0x04 + b MEM_DataCopy2 + +/* Bits: Src=01, Dst=00 - Byte before half word to long + * Bits: Src=01, Dst=10 - Byte before half word to half word + * 3 bytes to read for long word aligning the source + */ + +MEM_DataCopy4: +MEM_DataCopy6: + /* Read B and write B */ + + ldrb r3, [r1], #0x01 + strb r3, [r0], #0x01 + sub r2, r2, #0x01 + +/* Bits: Src=10, Dst=01 - Half word to byte before half word + * Bits: Src=10, Dst=11 - Half word to byte before long word + * 2 bytes to read for long word aligning the source + */ + +MEM_DataCopy9: +MEM_DataCopy11: + ldrb r3, [r1], #0x01 + strb r3, [r0], #0x01 + sub r2, r2, #0x01 + +/* Bits: Src=11, Dst=00 -chm Byte before long word to long word + * Bits: Src=11, Dst=11 - Byte before long word to half word + * 1 byte to read for long word aligning the source + */ + +MEM_DataCopy12: +MEM_DataCopy14: + /* Read B and write B */ + + ldrb r3, [r1], #0x01 + strb r3, [r0], #0x01 + sub r2, r2, #0x01 + +/* Bits: Src=00, Dst=01 - Long to Byte before half word + * Bits: Src=00, Dst=11 - Long to Byte before long word + */ + +MEM_DataCopy1: /* Read longs, write B->H->B */ +MEM_DataCopy3: + cmp r2, #4 + blt MEM_DataCopyBytes + ldr r3, [r1], #0x04 + strb r3, [r0], #0x01 + lsr r3, r3, #0x08 + strh r3, [r0], #0x02 + lsr r3, r3, #0x10 + strb r3, [r0], #0x01 + sub r2, r2, #0x04 + b MEM_DataCopy3 + + .size memcpy, .-memcpy + .end diff --git a/nuttx/arch/arm/src/common/arm-elf.h b/nuttx/arch/arm/src/common/arm-elf.h new file mode 100644 index 000000000..fac387b11 --- /dev/null +++ b/nuttx/arch/arm/src/common/arm-elf.h @@ -0,0 +1,53 @@ +/**************************************************************************** + * arch/arm/src/common/arm-elf.h + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __ARCH_ARM_SRC_ARM_ELF_H +#define __ARCH_ARM_SRC_ARM_ELF_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +#endif /* __ARCH_ARM_SRC_ARM_ELF_H */ diff --git a/nuttx/arch/arm/src/stm32/Kconfig b/nuttx/arch/arm/src/stm32/Kconfig index a1635f0a4..99dde3209 100644 --- a/nuttx/arch/arm/src/stm32/Kconfig +++ b/nuttx/arch/arm/src/stm32/Kconfig @@ -34,6 +34,27 @@ config ARCH_CHIP_STM32F100RB select STM32_STM32F10XX select STM32_VALUELINE +config ARCH_CHIP_STM32F100RC + bool "STM32F100RC" + select ARCH_CORTEXM3 + select STM32_STM32F10XX + select STM32_VALUELINE + select STM32_HIGHDENSITY + +config ARCH_CHIP_STM32F100RD + bool "STM32F100RD" + select ARCH_CORTEXM3 + select STM32_STM32F10XX + select STM32_VALUELINE + select STM32_HIGHDENSITY + +config ARCH_CHIP_STM32F100RE + bool "STM32F100RE" + select ARCH_CORTEXM3 + select STM32_STM32F10XX + select STM32_VALUELINE + select STM32_HIGHDENSITY + config ARCH_CHIP_STM32F100V8 bool "STM32F100V8" select ARCH_CORTEXM3 @@ -46,6 +67,27 @@ config ARCH_CHIP_STM32F100VB select STM32_STM32F10XX select STM32_VALUELINE +config ARCH_CHIP_STM32F100VC + bool "STM32F100VC" + select ARCH_CORTEXM3 + select STM32_STM32F10XX + select STM32_VALUELINE + select STM32_HIGHDENSITY + +config ARCH_CHIP_STM32F100VD + bool "STM32F100VD" + select ARCH_CORTEXM3 + select STM32_STM32F10XX + select STM32_VALUELINE + select STM32_HIGHDENSITY + +config ARCH_CHIP_STM32F100VE + bool "STM32F100VE" + select ARCH_CORTEXM3 + select STM32_STM32F10XX + select STM32_VALUELINE + select STM32_HIGHDENSITY + config ARCH_CHIP_STM32F103RET6 bool "STM32F103RET6" select ARCH_CORTEXM3 @@ -108,7 +150,7 @@ config ARCH_CHIP_STM32F407VE config ARCH_CHIP_STM32F407VG bool "STM32F407VG" - select ARCH_CORTEXM3 + select ARCH_CORTEXM4 select STM32_STM32F40XX config ARCH_CHIP_STM32F407ZE @@ -151,37 +193,10 @@ config STM32_STM32F20XX config STM32_STM32F40XX bool -choice - prompt "Toolchain Selection" - default STM32_CODESOURCERYW - depends on ARCH_CHIP_STM32 - -config STM32_CODESOURCERYW - bool "CodeSourcery for Windows" - -config STM32_CODESOURCERYL - bool "CodeSourcery for Linux" - -config STM32_ATOLLIC_LITE - bool "Atollic Lite for Windows" - -config STM32_ATOLLIC_PRO - bool "Atollic Pro for Windows" - -config STM32_DEVKITARM - bool "DevkitARM (Windows)" - -config STM32_RAISONANCE - bool "STMicro Raisonance for Windows" - -config STM32_BUILDROOT - bool "NuttX buildroot (Cygwin or Linux)" - -endchoice - config STM32_DFU bool "DFU bootloader" default n + depends on !STM32_VALUELINE ---help--- Configure and position code for use with the STMicro DFU bootloader. Do not select this option if you will load code using JTAG/SWM. @@ -197,25 +212,13 @@ config STM32_ADC2 bool "ADC2" default n select STM32_ADC + depends on !STM32_VALUELINE config STM32_ADC3 bool "ADC3" default n select STM32_ADC - -config STM32_CRC - bool "CRC" - default n - -config STM32_DMA1 - bool "DMA1" - default n - select ARCH_DMA - -config STM32_DMA2 - bool "DMA2" - default n - select ARCH_DMA + depends on !STM32_VALUELINE config STM32_BKP bool "BKP" @@ -232,6 +235,7 @@ config STM32_CAN1 default n select CAN select STM32_CAN + depends on !STM32_VALUELINE config STM32_CAN2 bool "CAN2" @@ -245,11 +249,31 @@ config STM32_CCMDATARAM default n depends on STM32_STM32F40XX +config STM32_CEC + bool "CEC" + default n + depends on STM32_VALUELINE + +config STM32_CRC + bool "CRC" + default n + config STM32_CRYP bool "CRYP" default n depends on STM32_STM32F20XX || STM32_STM32F40XX +config STM32_DMA1 + bool "DMA1" + default n + select ARCH_DMA + +config STM32_DMA2 + bool "DMA2" + default n + select ARCH_DMA + depends on !STM32_VALUELINE || (STM32_VALUELINE && STM32_HIGHDENSITY) + config STM32_DAC1 bool "DAC1" default n @@ -274,7 +298,7 @@ config STM32_ETHMAC config STM32_FSMC bool "FSMC" default n - depends on !STM32_CONNECTIVITYLINE + depends on !STM32_CONNECTIVITYLINE && (STM32_HIGHDENSITY || STM32_STM32F20XX || STM32_STM32F40XX) config STM32_HASH bool "HASH" @@ -325,7 +349,7 @@ config STM32_RNG config STM32_SDIO bool "SDIO" default n - depends on !STM32_CONNECTIVITYLINE + depends on !STM32_CONNECTIVITYLINE && !STM32_VALUELINE config STM32_SPI1 bool "SPI1" @@ -342,7 +366,7 @@ config STM32_SPI2 config STM32_SPI3 bool "SPI3" default n - depends on STM32_CONNECTIVITYLINE || STM32_STM32F20XX || STM32_STM32F40XX + depends on STM32_CONNECTIVITYLINE || STM32_STM32F20XX || STM32_STM32F40XX || (STM32_VALUELINE && STM32_HIGHDENSITY) select SPI select STM32_SPI @@ -382,6 +406,7 @@ config STM32_TIM7 config STM32_TIM8 bool "TIM8" default n + depends on !STM32_VALUELINE config STM32_TIM9 bool "TIM9" @@ -401,17 +426,32 @@ config STM32_TIM11 config STM32_TIM12 bool "TIM12" default n - depends on STM32_STM32F20XX || STM32_STM32F40XX + depends on STM32_STM32F20XX || STM32_STM32F40XX || STM32_VALUELINE config STM32_TIM13 bool "TIM13" default n - depends on STM32_STM32F20XX || STM32_STM32F40XX + depends on STM32_STM32F20XX || STM32_STM32F40XX || STM32_VALUELINE config STM32_TIM14 bool "TIM14" default n - depends on STM32_STM32F20XX || STM32_STM32F40XX + depends on STM32_STM32F20XX || STM32_STM32F40XX || STM32_VALUELINE + +config STM32_TIM15 + bool "TIM15" + default n + depends on STM32_VALUELINE + +config STM32_TIM16 + bool "TIM16" + default n + depends on STM32_VALUELINE + +config STM32_TIM17 + bool "TIM17" + default n + depends on STM32_VALUELINE config STM32_USART1 bool "USART1" @@ -447,7 +487,7 @@ config STM32_USART6 config STM32_USB bool "USB Device" default n - depends on STM32_STM32F10XX + depends on STM32_STM32F10XX && !STM32_VALUELINE select USBDEV config STM32_WWDG @@ -474,6 +514,52 @@ config STM32_CAN menu "Alternate Pin Mapping" +choice + prompt "CAN1 Alternate Pin Mappings" + depends on STM32_STM32F10XX && STM32_CAN1 + default STM32_CAN1_NO_REMAP + +config STM32_CAN1_NO_REMAP + bool "No pin remapping" + +config STM32_CAN1_REMAP1 + bool "CAN1 alternate pin remapping #1" + +config STM32_CAN1_REMAP2 + bool "CAN1 alternate pin remapping #2" + +endchoice + +config STM32_CAN2_REMAP + bool "CAN2 Alternate Pin Mapping" + default n + depends on STM32_CONNECTIVITYLINE && STM32_CAN2 + +config STM32_CEC_REMAP + bool "CEC Alternate Pin Mapping" + default n + depends on STM32_STM32F10XX && STM32_CEC + +config STM32_ETH_REMAP + bool "Ethernet Alternate Pin Mapping" + default n + depends on STM32_CONNECTIVITYLINE && STM32_ETHMAC + +config STM32_I2C1_REMAP + bool "I2C1 Alternate Pin Mapping" + default n + depends on STM32_STM32F10XX && STM32_I2C1 + +config STM32_SPI1_REMAP + bool "SPI1 Alternate Pin Mapping" + default n + depends on STM32_STM32F10XX && STM32_SPI1 + +config STM32_SPI3_REMAP + bool "SPI3 Alternate Pin Mapping" + default n + depends on STM32_STM32F10XX && STM32_SPI3 && !STM32_VALUELINE + choice prompt "TIM1 Alternate Pin Mappings" depends on STM32_STM32F10XX && STM32_TIM1 @@ -530,6 +616,51 @@ config STM32_TIM4_REMAP default n depends on STM32_STM32F10XX && STM32_TIM4 +config STM32_TIM9_REMAP + bool "TIM9 Alternate Pin Mapping" + default n + depends on STM32_STM32F10XX && STM32_TIM9 + +config STM32_TIM10_REMAP + bool "TIM10 Alternate Pin Mapping" + default n + depends on STM32_STM32F10XX && STM32_TIM10 + +config STM32_TIM11_REMAP + bool "TIM11 Alternate Pin Mapping" + default n + depends on STM32_STM32F10XX && STM32_TIM11 + +config STM32_TIM12_REMAP + bool "TIM12 Alternate Pin Mapping" + default n + depends on STM32_STM32F10XX && STM32_TIM12 + +config STM32_TIM13_REMAP + bool "TIM13 Alternate Pin Mapping" + default n + depends on STM32_STM32F10XX && STM32_TIM13 + +config STM32_TIM14_REMAP + bool "TIM14 Alternate Pin Mapping" + default n + depends on STM32_STM32F10XX && STM32_TIM14 + +config STM32_TIM15_REMAP + bool "TIM15 Alternate Pin Mapping" + default n + depends on STM32_STM32F10XX && STM32_TIM15 + +config STM32_TIM16_REMAP + bool "TIM16 Alternate Pin Mapping" + default n + depends on STM32_STM32F10XX && STM32_TIM16 + +config STM32_TIM17_REMAP + bool "TIM17 Alternate Pin Mapping" + default n + depends on STM32_STM32F10XX && STM32_TIM17 + config STM32_USART1_REMAP bool "USART1 Alternate Pin Mapping" default n @@ -556,47 +687,6 @@ config STM32_USART3_PARTIAL_REMAP endchoice -config STM32_SPI1_REMAP - bool "SPI1 Alternate Pin Mapping" - default n - depends on STM32_STM32F10XX && STM32_SPI1 - -config STM32_SPI3_REMAP - bool "SPI3 Alternate Pin Mapping" - default n - depends on STM32_STM32F10XX && STM32_SPI3 - -config STM32_I2C1_REMAP - bool "I2C1 Alternate Pin Mapping" - default n - depends on STM32_STM32F10XX && STM32_I2C1 - -choice - prompt "CAN1 Alternate Pin Mappings" - depends on STM32_STM32F10XX && STM32_CAN1 - default STM32_CAN1_NO_REMAP - -config STM32_CAN1_NO_REMAP - bool "No pin remapping" - -config STM32_CAN1_REMAP1 - bool "CAN1 alternate pin remapping #1" - -config STM32_CAN1_REMAP2 - bool "CAN1 alternate pin remapping #2" - -endchoice - -config STM32_CAN2_REMAP - bool "CAN2 Alternate Pin Mapping" - default n - depends on STM32_CONNECTIVITYLINE && STM32_CAN2 - -config STM32_ETH_REMAP - bool "Ethernet Alternate Pin Mapping" - default n - depends on STM32_CONNECTIVITYLINE && STM32_ETHMAC - endmenu config STM32_FLASH_PREFETCH @@ -645,9 +735,11 @@ config ARCH_BOARD_STM32_CUSTOM_CLOCKCONFIG config STM32_CCMEXCLUDE bool "Exclude CCM SRAM from the heap" depends on STM32_STM32F20XX || STM32_STM32F40XX - default y if ARCH_DMA + default y if ARCH_DMA || ELF ---help--- - Exclude CCM SRAM from the HEAP because it cannot be used for DMA. + Exclude CCM SRAM from the HEAP because (1) it cannot be used for DMA + and (2) it appears to be impossible to execute ELF modules from CCM + RAM. config STM32_FSMC_SRAM bool "External SRAM on FSMC" @@ -672,6 +764,7 @@ config STM32_TIM1_PWM config STM32_TIM1_CHANNEL int "TIM1 PWM Output Channel" default 1 + range 1 4 depends on STM32_TIM1_PWM ---help--- If TIM1 is enabled for PWM usage, you also need specifies the timer output @@ -682,7 +775,7 @@ config STM32_TIM2_PWM default n depends on STM32_TIM2 ---help--- - Reserve timer 1 for use by PWM + Reserve timer 2 for use by PWM Timer devices may be used for different purposes. One special purpose is to generate modulated outputs for such things as motor control. If STM32_TIM2 @@ -692,6 +785,7 @@ config STM32_TIM2_PWM config STM32_TIM2_CHANNEL int "TIM2 PWM Output Channel" default 1 + range 1 4 depends on STM32_TIM2_PWM ---help--- If TIM2 is enabled for PWM usage, you also need specifies the timer output @@ -702,7 +796,7 @@ config STM32_TIM3_PWM default n depends on STM32_TIM3 ---help--- - Reserve timer 1 for use by PWM + Reserve timer 3 for use by PWM Timer devices may be used for different purposes. One special purpose is to generate modulated outputs for such things as motor control. If STM32_TIM3 @@ -712,6 +806,7 @@ config STM32_TIM3_PWM config STM32_TIM3_CHANNEL int "TIM3 PWM Output Channel" default 1 + range 1 4 depends on STM32_TIM3_PWM ---help--- If TIM3 is enabled for PWM usage, you also need specifies the timer output @@ -722,7 +817,7 @@ config STM32_TIM4_PWM default n depends on STM32_TIM4 ---help--- - Reserve timer 1 for use by PWM + Reserve timer 4 for use by PWM Timer devices may be used for different purposes. One special purpose is to generate modulated outputs for such things as motor control. If STM32_TIM4 @@ -732,6 +827,7 @@ config STM32_TIM4_PWM config STM32_TIM4_CHANNEL int "TIM4 PWM Output Channel" default 1 + range 1 4 depends on STM32_TIM4_PWM ---help--- If TIM4 is enabled for PWM usage, you also need specifies the timer output @@ -742,7 +838,7 @@ config STM32_TIM5_PWM default n depends on STM32_TIM5 ---help--- - Reserve timer 1 for use by PWM + Reserve timer 5 for use by PWM Timer devices may be used for different purposes. One special purpose is to generate modulated outputs for such things as motor control. If STM32_TIM5 @@ -752,6 +848,7 @@ config STM32_TIM5_PWM config STM32_TIM5_CHANNEL int "TIM5 PWM Output Channel" default 1 + range 1 4 depends on STM32_TIM5_PWM ---help--- If TIM5 is enabled for PWM usage, you also need specifies the timer output @@ -762,7 +859,7 @@ config STM32_TIM8_PWM default n depends on STM32_TIM8 ---help--- - Reserve timer 1 for use by PWM + Reserve timer 8 for use by PWM Timer devices may be used for different purposes. One special purpose is to generate modulated outputs for such things as motor control. If STM32_TIM8 @@ -772,6 +869,7 @@ config STM32_TIM8_PWM config STM32_TIM8_CHANNEL int "TIM8 PWM Output Channel" default 1 + range 1 4 depends on STM32_TIM8_PWM ---help--- If TIM8 is enabled for PWM usage, you also need specifies the timer output @@ -782,7 +880,7 @@ config STM32_TIM9_PWM default n depends on STM32_TIM9 ---help--- - Reserve timer 1 for use by PWM + Reserve timer 9 for use by PWM Timer devices may be used for different purposes. One special purpose is to generate modulated outputs for such things as motor control. If STM32_TIM9 @@ -792,6 +890,7 @@ config STM32_TIM9_PWM config STM32_TIM9_CHANNEL int "TIM9 PWM Output Channel" default 1 + range 1 4 depends on STM32_TIM9_PWM ---help--- If TIM9 is enabled for PWM usage, you also need specifies the timer output @@ -802,7 +901,7 @@ config STM32_TIM10_PWM default n depends on STM32_TIM10 ---help--- - Reserve timer 1 for use by PWM + Reserve timer 10 for use by PWM Timer devices may be used for different purposes. One special purpose is to generate modulated outputs for such things as motor control. If STM32_TIM10 @@ -812,6 +911,7 @@ config STM32_TIM10_PWM config STM32_TIM10_CHANNEL int "TIM10 PWM Output Channel" default 1 + range 1 4 depends on STM32_TIM10_PWM ---help--- If TIM10 is enabled for PWM usage, you also need specifies the timer output @@ -822,7 +922,7 @@ config STM32_TIM11_PWM default n depends on STM32_TIM11 ---help--- - Reserve timer 1 for use by PWM + Reserve timer 11 for use by PWM Timer devices may be used for different purposes. One special purpose is to generate modulated outputs for such things as motor control. If STM32_TIM11 @@ -832,6 +932,7 @@ config STM32_TIM11_PWM config STM32_TIM11_CHANNEL int "TIM11 PWM Output Channel" default 1 + range 1 4 depends on STM32_TIM11_PWM ---help--- If TIM11 is enabled for PWM usage, you also need specifies the timer output @@ -842,7 +943,7 @@ config STM32_TIM12_PWM default n depends on STM32_TIM12 ---help--- - Reserve timer 1 for use by PWM + Reserve timer 12 for use by PWM Timer devices may be used for different purposes. One special purpose is to generate modulated outputs for such things as motor control. If STM32_TIM12 @@ -852,6 +953,7 @@ config STM32_TIM12_PWM config STM32_TIM12_CHANNEL int "TIM12 PWM Output Channel" default 1 + range 1 4 depends on STM32_TIM12_PWM ---help--- If TIM12 is enabled for PWM usage, you also need specifies the timer output @@ -862,7 +964,7 @@ config STM32_TIM13_PWM default n depends on STM32_TIM13 ---help--- - Reserve timer 1 for use by PWM + Reserve timer 13 for use by PWM Timer devices may be used for different purposes. One special purpose is to generate modulated outputs for such things as motor control. If STM32_TIM13 @@ -872,6 +974,7 @@ config STM32_TIM13_PWM config STM32_TIM13_CHANNEL int "TIM13 PWM Output Channel" default 1 + range 1 4 depends on STM32_TIM13_PWM ---help--- If TIM13 is enabled for PWM usage, you also need specifies the timer output @@ -882,7 +985,7 @@ config STM32_TIM14_PWM default n depends on STM32_TIM14 ---help--- - Reserve timer 1 for use by PWM + Reserve timer 14 for use by PWM Timer devices may be used for different purposes. One special purpose is to generate modulated outputs for such things as motor control. If STM32_TIM14 @@ -892,11 +995,75 @@ config STM32_TIM14_PWM config STM32_TIM14_CHANNEL int "TIM14 PWM Output Channel" default 1 + range 1 4 depends on STM32_TIM14_PWM ---help--- If TIM14 is enabled for PWM usage, you also need specifies the timer output channel {1,..,4} +config STM32_TIM15_PWM + bool "TIM15 PWM" + default n + depends on STM32_TIM15 + ---help--- + Reserve timer 15 for use by PWM + + Timer devices may be used for different purposes. One special purpose is + to generate modulated outputs for such things as motor control. If STM32_TIM15 + is defined then THIS following may also be defined to indicate that + the timer is intended to be used for pulsed output modulation. + +config STM32_TIM15_CHANNEL + int "TIM15 PWM Output Channel" + default 1 + range 1 2 + depends on STM32_TIM15_PWM + ---help--- + If TIM15 is enabled for PWM usage, you also need specifies the timer output + channel {1,2} + +config STM32_TIM16_PWM + bool "TIM16 PWM" + default n + depends on STM32_TIM16 + ---help--- + Reserve timer 16 for use by PWM + + Timer devices may be used for different purposes. One special purpose is + to generate modulated outputs for such things as motor control. If STM32_TIM16 + is defined then THIS following may also be defined to indicate that + the timer is intended to be used for pulsed output modulation. + +config STM32_TIM16_CHANNEL + int "TIM16 PWM Output Channel" + default 1 + range 1 1 + depends on STM32_TIM16_PWM + ---help--- + If TIM16 is enabled for PWM usage, you also need specifies the timer output + channel {1} + +config STM32_TIM17_PWM + bool "TIM17 PWM" + default n + depends on STM32_TIM17 + ---help--- + Reserve timer 17 for use by PWM + + Timer devices may be used for different purposes. One special purpose is + to generate modulated outputs for such things as motor control. If STM32_TIM17 + is defined then THIS following may also be defined to indicate that + the timer is intended to be used for pulsed output modulation. + +config STM32_TIM17_CHANNEL + int "TIM17 PWM Output Channel" + default 1 + range 1 1 + depends on STM32_TIM17_PWM + ---help--- + If TIM17 is enabled for PWM usage, you also need specifies the timer output + channel {1} + config STM32_TIM1_ADC bool "TIM1 ADC" default n @@ -918,16 +1085,22 @@ choice config STM32_TIM1_ADC1 bool "TIM1 ADC channel 1" + depends on STM32_ADC1 + select HAVE_ADC1_TIMER ---help--- Reserve TIM1 to trigger ADC1 config STM32_TIM1_ADC2 bool "TIM1 ADC channel 2" + depends on STM32_ADC2 + select HAVE_ADC2_TIMER ---help--- Reserve TIM1 to trigger ADC2 config STM32_TIM1_ADC3 bool "TIM1 ADC channel 3" + depends on STM32_ADC3 + select HAVE_ADC3_TIMER ---help--- Reserve TIM1 to trigger ADC3 @@ -954,16 +1127,22 @@ choice config STM32_TIM2_ADC1 bool "TIM2 ADC channel 1" + depends on STM32_ADC1 + select HAVE_ADC1_TIMER ---help--- Reserve TIM2 to trigger ADC1 config STM32_TIM2_ADC2 bool "TIM2 ADC channel 2" + depends on STM32_ADC2 + select HAVE_ADC2_TIMER ---help--- Reserve TIM2 to trigger ADC2 config STM32_TIM2_ADC3 bool "TIM2 ADC channel 3" + depends on STM32_ADC3 + select HAVE_ADC3_TIMER ---help--- Reserve TIM2 to trigger ADC3 @@ -990,16 +1169,22 @@ choice config STM32_TIM3_ADC1 bool "TIM3 ADC channel 1" + depends on STM32_ADC1 + select HAVE_ADC1_TIMER ---help--- Reserve TIM3 to trigger ADC1 config STM32_TIM3_ADC2 bool "TIM3 ADC channel 2" + depends on STM32_ADC2 + select HAVE_ADC2_TIMER ---help--- Reserve TIM3 to trigger ADC2 config STM32_TIM3_ADC3 bool "TIM3 ADC channel 3" + depends on STM32_ADC3 + select HAVE_ADC3_TIMER ---help--- Reserve TIM3 to trigger ADC3 @@ -1026,16 +1211,22 @@ choice config STM32_TIM4_ADC1 bool "TIM4 ADC channel 1" + depends on STM32_ADC1 + select HAVE_ADC1_TIMER ---help--- Reserve TIM4 to trigger ADC1 config STM32_TIM4_ADC2 bool "TIM4 ADC channel 2" + depends on STM32_ADC2 + select HAVE_ADC2_TIMER ---help--- Reserve TIM4 to trigger ADC2 config STM32_TIM4_ADC3 bool "TIM4 ADC channel 3" + depends on STM32_ADC3 + select HAVE_ADC3_TIMER ---help--- Reserve TIM4 to trigger ADC3 @@ -1062,16 +1253,22 @@ choice config STM32_TIM5_ADC1 bool "TIM5 ADC channel 1" + depends on STM32_ADC1 + select HAVE_ADC1_TIMER ---help--- Reserve TIM5 to trigger ADC1 config STM32_TIM5_ADC2 bool "TIM5 ADC channel 2" + depends on STM32_ADC2 + select HAVE_ADC2_TIMER ---help--- Reserve TIM5 to trigger ADC2 config STM32_TIM5_ADC3 bool "TIM5 ADC channel 3" + depends on STM32_ADC3 + select HAVE_ADC3_TIMER ---help--- Reserve TIM5 to trigger ADC3 @@ -1098,21 +1295,81 @@ choice config STM32_TIM8_ADC1 bool "TIM8 ADC channel 1" + depends on STM32_ADC1 + select HAVE_ADC1_TIMER ---help--- Reserve TIM8 to trigger ADC1 config STM32_TIM8_ADC2 bool "TIM8 ADC channel 2" + depends on STM32_ADC2 + select HAVE_ADC2_TIMER ---help--- Reserve TIM8 to trigger ADC2 config STM32_TIM8_ADC3 bool "TIM8 ADC channel 3" + depends on STM32_ADC3 + select HAVE_ADC3_TIMER ---help--- Reserve TIM8 to trigger ADC3 endchoice +config HAVE_ADC1_TIMER + bool + +config HAVE_ADC2_TIMER + bool + +config HAVE_ADC3_TIMER + bool + +config STM32_ADC1_SAMPLE_FREQUENCY + int "ADC1 Sampling Frequency" + default 100 + depends on HAVE_ADC1_TIMER + ---help--- + ADC1 sampling frequency. Default: 100Hz + +config STM32_ADC1_TIMTRIG + int "ADC1 Timer Trigger" + default 0 + range 0 4 + depends on HAVE_ADC1_TIMER + ---help--- + Values 0:CC1 1:CC2 2:CC3 3:CC4 4:TRGO + +config STM32_ADC2_SAMPLE_FREQUENCY + int "ADC2 Sampling Frequency" + default 100 + depends on HAVE_ADC2_TIMER + ---help--- + ADC2 sampling frequency. Default: 100Hz + +config STM32_ADC2_TIMTRIG + int "ADC2 Timer Trigger" + default 0 + range 0 4 + depends on HAVE_ADC2_TIMER + ---help--- + Values 0:CC1 1:CC2 2:CC3 3:CC4 4:TRGO + +config STM32_ADC3_SAMPLE_FREQUENCY + int "ADC3 Sampling Frequency" + default 100 + depends on HAVE_ADC3_TIMER + ---help--- + ADC3 sampling frequency. Default: 100Hz + +config STM32_ADC3_TIMTRIG + int "ADC3 Timer Trigger" + default 0 + range 0 4 + depends on HAVE_ADC3_TIMER + ---help--- + Values 0:CC1 1:CC2 2:CC3 3:CC4 4:TRGO + config STM32_TIM1_DAC bool "TIM1 DAC" default n @@ -1149,7 +1406,7 @@ config STM32_TIM2_DAC default n depends on STM32_TIM2 && STM32_DAC ---help--- - Reserve timer 1 for use by DAC + Reserve timer 2 for use by DAC Timer devices may be used for different purposes. If STM32_TIM2 is defined then the following may also be defined to indicate that the @@ -1180,7 +1437,7 @@ config STM32_TIM3_DAC default n depends on STM32_TIM3 && STM32_DAC ---help--- - Reserve timer 1 for use by DAC + Reserve timer 3 for use by DAC Timer devices may be used for different purposes. If STM32_TIM3 is defined then the following may also be defined to indicate that the @@ -1211,7 +1468,7 @@ config STM32_TIM4_DAC default n depends on STM32_TIM4 && STM32_DAC ---help--- - Reserve timer 1 for use by DAC + Reserve timer 4 for use by DAC Timer devices may be used for different purposes. If STM32_TIM4 is defined then the following may also be defined to indicate that the @@ -1242,7 +1499,7 @@ config STM32_TIM5_DAC default n depends on STM32_TIM5 && STM32_DAC ---help--- - Reserve timer 1 for use by DAC + Reserve timer 5 for use by DAC Timer devices may be used for different purposes. If STM32_TIM5 is defined then the following may also be defined to indicate that the @@ -1273,7 +1530,7 @@ config STM32_TIM6_DAC default n depends on STM32_TIM6 && STM32_DAC ---help--- - Reserve timer 1 for use by DAC + Reserve timer 6 for use by DAC Timer devices may be used for different purposes. If STM32_TIM6 is defined then the following may also be defined to indicate that the @@ -1304,7 +1561,7 @@ config STM32_TIM7_DAC default n depends on STM32_TIM7 && STM32_DAC ---help--- - Reserve timer 1 for use by DAC + Reserve timer 7 for use by DAC Timer devices may be used for different purposes. If STM32_TIM7 is defined then the following may also be defined to indicate that the @@ -1335,7 +1592,7 @@ config STM32_TIM8_DAC default n depends on STM32_TIM8 && STM32_DAC ---help--- - Reserve timer 1 for use by DAC + Reserve timer 8 for use by DAC Timer devices may be used for different purposes. If STM32_TIM8 is defined then the following may also be defined to indicate that the @@ -1366,7 +1623,7 @@ config STM32_TIM9_DAC default n depends on STM32_TIM9 && STM32_DAC ---help--- - Reserve timer 1 for use by DAC + Reserve timer 9 for use by DAC Timer devices may be used for different purposes. If STM32_TIM9 is defined then the following may also be defined to indicate that the @@ -1397,7 +1654,7 @@ config STM32_TIM10_DAC default n depends on STM32_TIM10 && STM32_DAC ---help--- - Reserve timer 1 for use by DAC + Reserve timer 10 for use by DAC Timer devices may be used for different purposes. If STM32_TIM10 is defined then the following may also be defined to indicate that the @@ -1428,7 +1685,7 @@ config STM32_TIM11_DAC default n depends on STM32_TIM11 && STM32_DAC ---help--- - Reserve timer 1 for use by DAC + Reserve timer 11 for use by DAC Timer devices may be used for different purposes. If STM32_TIM11 is defined then the following may also be defined to indicate that the @@ -1459,7 +1716,7 @@ config STM32_TIM12_DAC default n depends on STM32_TIM12 && STM32_DAC ---help--- - Reserve timer 1 for use by DAC + Reserve timer 12 for use by DAC Timer devices may be used for different purposes. If STM32_TIM12 is defined then the following may also be defined to indicate that the @@ -1490,7 +1747,7 @@ config STM32_TIM13_DAC default n depends on STM32_TIM13 && STM32_DAC ---help--- - Reserve timer 1 for use by DAC + Reserve timer 13 for use by DAC Timer devices may be used for different purposes. If STM32_TIM13 is defined then the following may also be defined to indicate that the @@ -1521,7 +1778,7 @@ config STM32_TIM14_DAC default n depends on STM32_TIM14 && STM32_DAC ---help--- - Reserve timer 1 for use by DAC + Reserve timer 14 for use by DAC Timer devices may be used for different purposes. If STM32_TIM14 is defined then the following may also be defined to indicate that the @@ -1547,6 +1804,27 @@ config STM32_TIM14_DAC2 endchoice +menu "U[S]ART Configuration" + depends on STM32_USART1 || STM32_USART2 || STM32_USART3 || STM32_USART4 || STM32_USART5 || STM32_USART6 + +config USART1_RS485 + bool "RS-485 on USART1" + default n + depends on STM32_USART1 + ---help--- + Enable RS-485 interface on USART1. Your board config will have to + provide GPIO_USART1_RS485_DIR pin definition. Currently it cannot be + used with USART1_RXDMA. + +config USART1_RS485_DIR_POLARITY + int "USART1 RS-485 DIR pin polarity" + default 1 + range 0 1 + depends on USART1_RS485 + ---help--- + Polarity of DIR pin for RS-485 on USART1. Set to state on DIR pin which + enables TX (0 - low / nTXEN, 1 - high / TXEN). + config USART1_RXDMA bool "USART1 Rx DMA" default n @@ -1554,6 +1832,24 @@ config USART1_RXDMA ---help--- In high data rate usage, Rx DMA may eliminate Rx overrun errors +config USART2_RS485 + bool "RS-485 on USART2" + default n + depends on STM32_USART2 + ---help--- + Enable RS-485 interface on USART2. Your board config will have to + provide GPIO_USART2_RS485_DIR pin definition. Currently it cannot be + used with USART2_RXDMA. + +config USART2_RS485_DIR_POLARITY + int "USART2 RS-485 DIR pin polarity" + default 1 + range 0 1 + depends on USART2_RS485 + ---help--- + Polarity of DIR pin for RS-485 on USART2. Set to state on DIR pin which + enables TX (0 - low / nTXEN, 1 - high / TXEN). + config USART2_RXDMA bool "USART2 Rx DMA" default n @@ -1561,6 +1857,24 @@ config USART2_RXDMA ---help--- In high data rate usage, Rx DMA may eliminate Rx overrun errors +config USART3_RS485 + bool "RS-485 on USART3" + default n + depends on STM32_USART3 + ---help--- + Enable RS-485 interface on USART3. Your board config will have to + provide GPIO_USART3_RS485_DIR pin definition. Currently it cannot be + used with USART3_RXDMA. + +config USART3_RS485_DIR_POLARITY + int "USART3 RS-485 DIR pin polarity" + default 1 + range 0 1 + depends on USART3_RS485 + ---help--- + Polarity of DIR pin for RS-485 on USART3. Set to state on DIR pin which + enables TX (0 - low / nTXEN, 1 - high / TXEN). + config USART3_RXDMA bool "USART3 Rx DMA" default n @@ -1568,6 +1882,24 @@ config USART3_RXDMA ---help--- In high data rate usage, Rx DMA may eliminate Rx overrun errors +config UART4_RS485 + bool "RS-485 on UART4" + default n + depends on STM32_UART4 + ---help--- + Enable RS-485 interface on UART4. Your board config will have to + provide GPIO_UART4_RS485_DIR pin definition. Currently it cannot be + used with UART4_RXDMA. + +config UART4_RS485_DIR_POLARITY + int "UART4 RS-485 DIR pin polarity" + default 1 + range 0 1 + depends on UART4_RS485 + ---help--- + Polarity of DIR pin for RS-485 on UART4. Set to state on DIR pin which + enables TX (0 - low / nTXEN, 1 - high / TXEN). + config UART4_RXDMA bool "UART4 Rx DMA" default n @@ -1575,6 +1907,24 @@ config UART4_RXDMA ---help--- In high data rate usage, Rx DMA may eliminate Rx overrun errors +config UART5_RS485 + bool "RS-485 on UART5" + default n + depends on STM32_UART5 + ---help--- + Enable RS-485 interface on UART5. Your board config will have to + provide GPIO_UART5_RS485_DIR pin definition. Currently it cannot be + used with UART5_RXDMA. + +config UART5_RS485_DIR_POLARITY + int "UART5 RS-485 DIR pin polarity" + default 1 + range 0 1 + depends on UART5_RS485 + ---help--- + Polarity of DIR pin for RS-485 on UART5. Set to state on DIR pin which + enables TX (0 - low / nTXEN, 1 - high / TXEN). + config UART5_RXDMA bool "UART5 Rx DMA" default n @@ -1582,6 +1932,24 @@ config UART5_RXDMA ---help--- In high data rate usage, Rx DMA may eliminate Rx overrun errors +config USART6_RS485 + bool "RS-485 on USART6" + default n + depends on STM32_USART6 + ---help--- + Enable RS-485 interface on USART6. Your board config will have to + provide GPIO_USART6_RS485_DIR pin definition. Currently it cannot be + used with USART6_RXDMA. + +config USART6_RS485_DIR_POLARITY + int "USART6 RS-485 DIR pin polarity" + default 1 + range 0 1 + depends on USART6_RS485 + ---help--- + Polarity of DIR pin for RS-485 on USART6. Set to state on DIR pin which + enables TX (0 - low / nTXEN, 1 - high / TXEN). + config USART6_RXDMA bool "USART6 Rx DMA" default n @@ -1598,6 +1966,8 @@ config SERIAL_TERMIOS If this is not defined, then the terminal settings (baud, parity, etc). are not configurable at runtime; serial streams cannot be flushed, etc.. +endmenu + menu "SPI Configuration" depends on STM32_SPI @@ -1697,6 +2067,16 @@ config STM32_PHYADDR ---help--- The 5-bit address of the PHY on the board. Default: 1 +config STM32_PHYINIT + bool "Board-specific PHY Initialization" + default n + ---help--- + Some boards require specialized initialization of the PHY before it can be used. + This may include such things as configuring GPIOs, resetting the PHY, etc. If + STM32_PHYINIT is defined in the configuration then the board specific logic must + provide stm32_phyinitialize(); The STM32 Ethernet driver will call this function + one time before it first uses the PHY. + config STM32_MII bool "Use MII interface" default n @@ -1908,14 +2288,14 @@ config STM32_OTGFS_NPTXFIFO_SIZE depends on USBHOST && STM32_OTGFS ---help--- Size of the non-periodic Tx FIFO in 32-bit words. Default 96 (384 bytes) - + config STM32_OTGFS_PTXFIFO_SIZE int "Periodic Tx FIFO size" default 128 depends on USBHOST && STM32_OTGFS ---help--- Size of the periodic Tx FIFO in 32-bit words. Default 96 (384 bytes) - + config STM32_OTGFS_DESCSIZE int "Descriptor Size" default 128 @@ -1929,14 +2309,14 @@ config STM32_OTGFS_SOFINTR depends on USBHOST && STM32_OTGFS ---help--- Enable SOF interrupts. Why would you ever want to do that? - + config STM32_USBHOST_REGDEBUG bool "Register-Level Debug" default n depends on USBHOST && STM32_OTGFS ---help--- Enable very low-level register access debug. Depends on DEBUG. - + config STM32_USBHOST_PKTDUMP bool "Packet Dump Debug" default n diff --git a/nuttx/arch/arm/src/stm32/chip/stm32_eth.h b/nuttx/arch/arm/src/stm32/chip/stm32_eth.h index a4a109d01..92a229ccc 100644 --- a/nuttx/arch/arm/src/stm32/chip/stm32_eth.h +++ b/nuttx/arch/arm/src/stm32/chip/stm32_eth.h @@ -835,14 +835,6 @@ struct eth_rxdesc_s * Public Functions ****************************************************************************************************/ -#undef EXTERN -#if defined(__cplusplus) -#define EXTERN extern "C" -extern "C" { -#else -#define EXTERN extern -#endif - #endif /* __ASSEMBLY__ */ #endif /* STM32_NETHERNET > 0 */ #endif /* __ARCH_ARM_SRC_STM32_CHIP_STM32_ETH_H */ diff --git a/nuttx/arch/arm/src/stm32/chip/stm32f100_pinmap.h b/nuttx/arch/arm/src/stm32/chip/stm32f100_pinmap.h index 01d6e1ce0..addef0265 100644 --- a/nuttx/arch/arm/src/stm32/chip/stm32f100_pinmap.h +++ b/nuttx/arch/arm/src/stm32/chip/stm32f100_pinmap.h @@ -6,6 +6,8 @@ * Copyright (C) 2012 Michael Smith. All Rights reserved. * Author: Gregory Nutt * Uros Platise + * Michael Smith + * Freddie Chopin * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -49,6 +51,87 @@ * Pre-processor Definitions ************************************************************************************/ +/* Alternate Pin Functions: */ + +/* ADC */ + +#define GPIO_ADC1_IN0 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN0) +#define GPIO_ADC1_IN1 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN1) +#define GPIO_ADC1_IN2 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN2) +#define GPIO_ADC1_IN3 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN3) +#define GPIO_ADC1_IN4 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN4) +#define GPIO_ADC1_IN5 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN5) +#define GPIO_ADC1_IN6 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN6) +#define GPIO_ADC1_IN7 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN7) +#define GPIO_ADC1_IN8 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTB|GPIO_PIN0) +#define GPIO_ADC1_IN9 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTB|GPIO_PIN1) +#define GPIO_ADC1_IN10 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN0) +#define GPIO_ADC1_IN11 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN1) +#define GPIO_ADC1_IN12 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN2) +#define GPIO_ADC1_IN13 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN3) +#define GPIO_ADC1_IN14 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN4) +#define GPIO_ADC1_IN15 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN5) + +/* CEC */ +#if defined(CONFIG_STM32_CEC_REMAP) +# define GPIO_CEC (GPIO_ALT|GPIO_CNF_AFOD|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN10) +#else +# define GPIO_CEC (GPIO_ALT|GPIO_CNF_AFOD|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN8) +#endif + +/* DAC + * Note from RM0041, 11.2: "Once the DAC channelx is enabled, the corresponding + * GPIO pin (PA4 or PA5) is automatically connected to the analog converter + * output (DAC_OUTx). In order to avoid parasitic consumption, the PA4 or PA5 + * pin should first be configured to analog (AIN)." + */ + +#define GPIO_DAC_OUT1 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN4) +#define GPIO_DAC_OUT2 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN5) + +/* FSMC */ + +/* TODO - VL devices in 100- and 144-pin packages have FSMC */ + +/* I2C */ + +#if defined(CONFIG_STM32_I2C1_REMAP) +# define GPIO_I2C1_SCL (GPIO_ALT|GPIO_CNF_AFOD|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN8) +# define GPIO_I2C1_SDA (GPIO_ALT|GPIO_CNF_AFOD|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN9) +#else +# define GPIO_I2C1_SCL (GPIO_ALT|GPIO_CNF_AFOD|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN6) +# define GPIO_I2C1_SDA (GPIO_ALT|GPIO_CNF_AFOD|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN7) +#endif +#define GPIO_I2C1_SMBA (GPIO_ALT|GPIO_CNF_INFLOAT|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN5) + +#define GPIO_I2C2_SCL (GPIO_ALT|GPIO_CNF_AFOD|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN10) +#define GPIO_I2C2_SDA (GPIO_ALT|GPIO_CNF_AFOD|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN11) +#define GPIO_I2C2_SMBA (GPIO_ALT|GPIO_CNF_INFLOAT|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN12) + +/* SPI */ + +#if defined(CONFIG_STM32_SPI1_REMAP) +# define GPIO_SPI1_NSS (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN15) +# define GPIO_SPI1_SCK (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN3) +# define GPIO_SPI1_MISO (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|GPIO_PORTB|GPIO_PIN4) +# define GPIO_SPI1_MOSI (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN5) +#else +# define GPIO_SPI1_NSS (GPIO_INPUT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTA|GPIO_PIN4) +# define GPIO_SPI1_SCK (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTA|GPIO_PIN5) +# define GPIO_SPI1_MISO (GPIO_INPUT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTA|GPIO_PIN6) +# define GPIO_SPI1_MOSI (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTA|GPIO_PIN7) +#endif + +#define GPIO_SPI2_NSS (GPIO_INPUT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN12) +#define GPIO_SPI2_SCK (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN13) +#define GPIO_SPI2_MISO (GPIO_INPUT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN14) +#define GPIO_SPI2_MOSI (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN15) + +#define GPIO_SPI3_NSS (GPIO_INPUT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTA|GPIO_PIN15) +#define GPIO_SPI3_SCK (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN3) +#define GPIO_SPI3_MISO (GPIO_INPUT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN4) +#define GPIO_SPI3_MOSI (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN5) + /* TIMERS */ #if defined(CONFIG_STM32_TIM1_FULL_REMAP) @@ -186,6 +269,77 @@ # define GPIO_TIM4_CH4OUT (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN9) #endif +#define GPIO_TIM5_CH1IN (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN0) +#define GPIO_TIM5_CH1OUT (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTA|GPIO_PIN0) +#define GPIO_TIM5_CH2IN (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN1) +#define GPIO_TIM5_CH2OUT (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTA|GPIO_PIN1) +#define GPIO_TIM5_CH3IN (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN2) +#define GPIO_TIM5_CH3OUT (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTA|GPIO_PIN2) +#define GPIO_TIM5_CH4IN (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN3) +#define GPIO_TIM5_CH4OUT (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTA|GPIO_PIN3) + +#if defined(CONFIG_STM32_TIM12_REMAP) +# define GPIO_TIM12_CH1IN (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|GPIO_PORTB|GPIO_PIN12) +# define GPIO_TIM12_CH1OUT (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN12) +# define GPIO_TIM12_CH2IN (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|GPIO_PORTB|GPIO_PIN13) +# define GPIO_TIM12_CH2OUT (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN13) +#else +# define GPIO_TIM12_CH1IN (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN4) +# define GPIO_TIM12_CH1OUT (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTC|GPIO_PIN4) +# define GPIO_TIM12_CH2IN (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN5) +# define GPIO_TIM12_CH2OUT (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTC|GPIO_PIN5) +#endif + +#if defined(CONFIG_STM32_TIM13_REMAP) +# define GPIO_TIM13_CH1IN (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|GPIO_PORTB|GPIO_PIN0) +# define GPIO_TIM13_CH1OUT (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN0) +#else +# define GPIO_TIM13_CH1IN (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN8) +# define GPIO_TIM13_CH1OUT (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTC|GPIO_PIN8) +#endif + +#if defined(CONFIG_STM32_TIM14_REMAP) +# define GPIO_TIM14_CH1IN (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|GPIO_PORTB|GPIO_PIN1) +# define GPIO_TIM14_CH1OUT (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN1) +#else +# define GPIO_TIM14_CH1IN (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN9) +# define GPIO_TIM14_CH1OUT (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTC|GPIO_PIN9) +#endif + +#if defined(CONFIG_STM32_TIM15_REMAP) +# define GPIO_TIM15_CH1IN (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|GPIO_PORTB|GPIO_PIN14) +# define GPIO_TIM15_CH1OUT (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN14) +# define GPIO_TIM15_CH2IN (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|GPIO_PORTB|GPIO_PIN15) +# define GPIO_TIM15_CH2OUT (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN15) +#else +# define GPIO_TIM15_CH1IN (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN2) +# define GPIO_TIM15_CH1OUT (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTA|GPIO_PIN2) +# define GPIO_TIM15_CH2IN (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN3) +# define GPIO_TIM15_CH2OUT (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTA|GPIO_PIN3) +#endif +#define GPIO_TIM15_BKIN (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN9) +#define GPIO_TIM15_CH1N (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN15) + +#if defined(CONFIG_STM32_TIM16_REMAP) +# define GPIO_TIM16_CH1IN (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN6) +# define GPIO_TIM16_CH1OUT (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTA|GPIO_PIN6) +#else +# define GPIO_TIM16_CH1IN (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|GPIO_PORTB|GPIO_PIN8) +# define GPIO_TIM16_CH1OUT (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN8) +#endif +#define GPIO_TIM16_BKIN (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|GPIO_PORTB|GPIO_PIN5) +#define GPIO_TIM16_CH1N (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN6) + +#if defined(CONFIG_STM32_TIM17_REMAP) +# define GPIO_TIM17_CH1IN (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN7) +# define GPIO_TIM17_CH1OUT (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTA|GPIO_PIN7) +#else +# define GPIO_TIM17_CH1IN (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|GPIO_PORTB|GPIO_PIN9) +# define GPIO_TIM17_CH1OUT (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN9) +#endif +#define GPIO_TIM17_BKIN (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN10) +#define GPIO_TIM17_CH1N (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN7) + /* USART */ #if defined(CONFIG_STM32_USART1_REMAP) @@ -230,38 +384,10 @@ # define GPIO_USART3_RTS (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN14) #endif -/* SPI */ - -#if defined(CONFIG_STM32_SPI1_REMAP) -# define GPIO_SPI1_NSS (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN15) -# define GPIO_SPI1_SCK (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN3) -# define GPIO_SPI1_MISO (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|GPIO_PORTB|GPIO_PIN4) -# define GPIO_SPI1_MOSI (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN5) -#else -# define GPIO_SPI1_NSS (GPIO_INPUT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTA|GPIO_PIN4) -# define GPIO_SPI1_SCK (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTA|GPIO_PIN5) -# define GPIO_SPI1_MISO (GPIO_INPUT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTA|GPIO_PIN6) -# define GPIO_SPI1_MOSI (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTA|GPIO_PIN7) -#endif - -#define GPIO_SPI2_NSS (GPIO_INPUT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN12) -#define GPIO_SPI2_SCK (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN13) -#define GPIO_SPI2_MISO (GPIO_INPUT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN14) -#define GPIO_SPI2_MOSI (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN15) - -/* I2C */ - -#if defined(CONFIG_STM32_I2C1_REMAP) -# define GPIO_I2C1_SCL (GPIO_ALT|GPIO_CNF_AFOD|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN8) -# define GPIO_I2C1_SDA (GPIO_ALT|GPIO_CNF_AFOD|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN9) -#else -# define GPIO_I2C1_SCL (GPIO_ALT|GPIO_CNF_AFOD|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN6) -# define GPIO_I2C1_SDA (GPIO_ALT|GPIO_CNF_AFOD|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN7) -#endif -#define GPIO_I2C1_SMBA (GPIO_ALT|GPIO_CNF_INFLOAT|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN5) +#define GPIO_UART4_TX (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTC|GPIO_PIN10) +#define GPIO_UART4_RX (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN11) -#define GPIO_I2C2_SCL (GPIO_ALT|GPIO_CNF_AFOD|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN10) -#define GPIO_I2C2_SDA (GPIO_ALT|GPIO_CNF_AFOD|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN11) -#define GPIO_I2C2_SMBA (GPIO_ALT|GPIO_CNF_INFLOAT|GPIO_MODE_50MHz|GPIO_PORTB|GPIO_PIN12) +#define GPIO_UART5_TX (GPIO_ALT|GPIO_CNF_AFPP|GPIO_MODE_50MHz|GPIO_PORTC|GPIO_PIN12) +#define GPIO_UART5_RX (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|GPIO_PORTD|GPIO_PIN2) #endif /* __ARCH_ARM_SRC_STM32_CHIP_STM32F100_PINMAP_H */ diff --git a/nuttx/arch/arm/src/stm32/chip/stm32f103vc_pinmap.h b/nuttx/arch/arm/src/stm32/chip/stm32f103vc_pinmap.h index 160676802..52a513215 100644 --- a/nuttx/arch/arm/src/stm32/chip/stm32f103vc_pinmap.h +++ b/nuttx/arch/arm/src/stm32/chip/stm32f103vc_pinmap.h @@ -129,7 +129,7 @@ #if 0 /* Needs further investigation */ -#define GPIO_DAC_OUT1 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUTz|GPIO_PORTA|GPIO_PIN4) +#define GPIO_DAC_OUT1 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN4) #define GPIO_DAC_OUT2 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN5) #endif diff --git a/nuttx/arch/arm/src/stm32/chip/stm32f103ze_pinmap.h b/nuttx/arch/arm/src/stm32/chip/stm32f103ze_pinmap.h index 9bcee49f5..581b026a0 100644 --- a/nuttx/arch/arm/src/stm32/chip/stm32f103ze_pinmap.h +++ b/nuttx/arch/arm/src/stm32/chip/stm32f103ze_pinmap.h @@ -50,53 +50,53 @@ /* ADC */ -#define GPIO_ADC1_IN0 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN0) -#define GPIO_ADC1_IN1 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN1) -#define GPIO_ADC1_IN2 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN2) -#define GPIO_ADC1_IN3 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN3) -#define GPIO_ADC1_IN4 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN4) -#define GPIO_ADC1_IN5 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN5) -#define GPIO_ADC1_IN6 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN6) -#define GPIO_ADC1_IN7 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN7) -#define GPIO_ADC1_IN8 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTB|GPIO_PIN0) -#define GPIO_ADC1_IN9 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTB|GPIO_PIN1) -#define GPIO_ADC1_IN10 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN0) -#define GPIO_ADC1_IN11 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN1) -#define GPIO_ADC1_IN12 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN2) -#define GPIO_ADC1_IN13 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN3) -#define GPIO_ADC1_IN14 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN4) -#define GPIO_ADC1_IN15 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN5) - -#define GPIO_ADC2_IN0 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN0) -#define GPIO_ADC2_IN1 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN1) -#define GPIO_ADC2_IN2 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN2) -#define GPIO_ADC2_IN3 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN3) -#define GPIO_ADC2_IN4 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN4) -#define GPIO_ADC2_IN5 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN5) -#define GPIO_ADC2_IN6 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN6) -#define GPIO_ADC2_IN7 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN7) -#define GPIO_ADC2_IN8 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTB|GPIO_PIN0) -#define GPIO_ADC2_IN9 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTB|GPIO_PIN1) -#define GPIO_ADC2_IN10 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN0) -#define GPIO_ADC2_IN11 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN1) -#define GPIO_ADC2_IN12 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN2) -#define GPIO_ADC2_IN13 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN3) -#define GPIO_ADC2_IN14 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN4) -#define GPIO_ADC2_IN15 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN5) - -#define GPIO_ADC3_IN0 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN0) -#define GPIO_ADC3_IN1 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN1) -#define GPIO_ADC3_IN2 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN2) -#define GPIO_ADC3_IN3 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN3) -#define GPIO_ADC3_IN4 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTF|GPIO_PIN6) -#define GPIO_ADC3_IN5 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTF|GPIO_PIN7) -#define GPIO_ADC3_IN6 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTF|GPIO_PIN8) -#define GPIO_ADC3_IN7 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTF|GPIO_PIN9) -#define GPIO_ADC3_IN8 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTF|GPIO_PIN10) -#define GPIO_ADC3_IN10 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN0) -#define GPIO_ADC3_IN11 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN1) -#define GPIO_ADC3_IN12 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN2) -#define GPIO_ADC3_IN13 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN3) +#define GPIO_ADC1_IN0 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN0) +#define GPIO_ADC1_IN1 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN1) +#define GPIO_ADC1_IN2 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN2) +#define GPIO_ADC1_IN3 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN3) +#define GPIO_ADC1_IN4 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN4) +#define GPIO_ADC1_IN5 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN5) +#define GPIO_ADC1_IN6 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN6) +#define GPIO_ADC1_IN7 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN7) +#define GPIO_ADC1_IN8 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTB|GPIO_PIN0) +#define GPIO_ADC1_IN9 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTB|GPIO_PIN1) +#define GPIO_ADC1_IN10 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN0) +#define GPIO_ADC1_IN11 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN1) +#define GPIO_ADC1_IN12 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN2) +#define GPIO_ADC1_IN13 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN3) +#define GPIO_ADC1_IN14 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN4) +#define GPIO_ADC1_IN15 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN5) + +#define GPIO_ADC2_IN0 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN0) +#define GPIO_ADC2_IN1 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN1) +#define GPIO_ADC2_IN2 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN2) +#define GPIO_ADC2_IN3 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN3) +#define GPIO_ADC2_IN4 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN4) +#define GPIO_ADC2_IN5 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN5) +#define GPIO_ADC2_IN6 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN6) +#define GPIO_ADC2_IN7 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN7) +#define GPIO_ADC2_IN8 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTB|GPIO_PIN0) +#define GPIO_ADC2_IN9 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTB|GPIO_PIN1) +#define GPIO_ADC2_IN10 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN0) +#define GPIO_ADC2_IN11 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN1) +#define GPIO_ADC2_IN12 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN2) +#define GPIO_ADC2_IN13 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN3) +#define GPIO_ADC2_IN14 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN4) +#define GPIO_ADC2_IN15 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN5) + +#define GPIO_ADC3_IN0 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN0) +#define GPIO_ADC3_IN1 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN1) +#define GPIO_ADC3_IN2 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN2) +#define GPIO_ADC3_IN3 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN3) +#define GPIO_ADC3_IN4 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTF|GPIO_PIN6) +#define GPIO_ADC3_IN5 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTF|GPIO_PIN7) +#define GPIO_ADC3_IN6 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTF|GPIO_PIN8) +#define GPIO_ADC3_IN7 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTF|GPIO_PIN9) +#define GPIO_ADC3_IN8 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTF|GPIO_PIN10) +#define GPIO_ADC3_IN10 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN0) +#define GPIO_ADC3_IN11 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN1) +#define GPIO_ADC3_IN12 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN2) +#define GPIO_ADC3_IN13 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTC|GPIO_PIN3) /* DAC - "Once the DAC channelx is enabled, the corresponding GPIO pin * (PA4 or PA5) is automatically connected to the analog converter output @@ -104,8 +104,8 @@ * should first be configured to analog (AIN)." */ -#define GPIO_DAC_OUT1 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTF|GPIO_PIN10) -#define GPIO_DAC_OUT2 (GPIO_ALT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PIN10) +#define GPIO_DAC_OUT1 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN4) +#define GPIO_DAC_OUT2 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN5) /* TIMERS */ diff --git a/nuttx/arch/arm/src/stm32/chip/stm32f105vb_pinmap.h b/nuttx/arch/arm/src/stm32/chip/stm32f105vb_pinmap.h index 7a5ec3381..054a7337d 100644 --- a/nuttx/arch/arm/src/stm32/chip/stm32f105vb_pinmap.h +++ b/nuttx/arch/arm/src/stm32/chip/stm32f105vb_pinmap.h @@ -85,7 +85,7 @@ #endif #if 0 /* Needs further investigation */ -#define GPIO_DAC_OUT1 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUTz|GPIO_PORTA|GPIO_PIN4) +#define GPIO_DAC_OUT1 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN4) #define GPIO_DAC_OUT2 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN5) #endif diff --git a/nuttx/arch/arm/src/stm32/chip/stm32f107vc_pinmap.h b/nuttx/arch/arm/src/stm32/chip/stm32f107vc_pinmap.h index 9bbc21479..2419620fc 100644 --- a/nuttx/arch/arm/src/stm32/chip/stm32f107vc_pinmap.h +++ b/nuttx/arch/arm/src/stm32/chip/stm32f107vc_pinmap.h @@ -85,7 +85,7 @@ #endif #if 0 /* Needs further investigation */ -#define GPIO_DAC_OUT1 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUTz|GPIO_PORTA|GPIO_PIN4) +#define GPIO_DAC_OUT1 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN4) #define GPIO_DAC_OUT2 (GPIO_INPUT|GPIO_CNF_ANALOGIN|GPIO_MODE_INPUT|GPIO_PORTA|GPIO_PIN5) #endif diff --git a/nuttx/arch/arm/src/stm32/chip/stm32f10xxx_gpio.h b/nuttx/arch/arm/src/stm32/chip/stm32f10xxx_gpio.h index a95d13100..d339fc15e 100644 --- a/nuttx/arch/arm/src/stm32/chip/stm32f10xxx_gpio.h +++ b/nuttx/arch/arm/src/stm32/chip/stm32f10xxx_gpio.h @@ -59,6 +59,7 @@ #define STM32_AFIO_EXTICR2_OFFSET 0x000c /* External interrupt configuration register 2 */ #define STM32_AFIO_EXTICR3_OFFSET 0x0010 /* External interrupt configuration register 3 */ #define STM32_AFIO_EXTICR4_OFFSET 0x0014 /* External interrupt configuration register 4 */ +#define STM32_AFIO_MAPR2_OFFSET 0x001c /* AF remap and debug I/O configuration register 2 */ /* Register Addresses ***************************************************************/ @@ -373,5 +374,27 @@ #define AFIO_EXTICR4_EXTI15_SHIFT (12) /* Bits 15-12: EXTI 15 configuration */ #define AFIO_EXTICR4_EXTI15_MASK (AFIO_EXTICR_PORT_MASK << AFIO_EXTICR4_EXTI15_SHIFT) +/* AF remap and debug I/O configuration register 2 */ + +#ifdef CONFIG_STM32_VALUELINE +# define AFIO_MAPR2_TIM15_REMAP (1 << 0) /* Bit 0: TIM15 remapping */ +# define AFIO_MAPR2_TIM16_REMAP (1 << 1) /* Bit 1: TIM16 remapping */ +# define AFIO_MAPR2_TIM17_REMAP (1 << 2) /* Bit 2: TIM17 remapping */ +# define AFIO_MAPR2_CEC_REMAP (1 << 3) /* Bit 3: CEC remapping */ +# define AFIO_MAPR2_TIM1_DMA_REMAP (1 << 4) /* Bit 4: TIM1 DMA remapping */ +#else +# define AFIO_MAPR2_TIM9_REMAP (1 << 5) /* Bit 5: TIM9 remapping */ +# define AFIO_MAPR2_TIM10_REMAP (1 << 6) /* Bit 6: TIM10 remapping */ +# define AFIO_MAPR2_TIM11_REMAP (1 << 7) /* Bit 7: TIM11 remapping */ +#endif +#define AFIO_MAPR2_TIM13_REMAP (1 << 8) /* Bit 8: TIM13 remapping */ +#define AFIO_MAPR2_TIM14_REMAP (1 << 9) /* Bit 9: TIM14 remapping */ +#define AFIO_MAPR2_FSMC_NADV (1 << 10) /* Bit 10: NADV connect/disconnect */ +#ifdef CONFIG_STM32_VALUELINE +# define AFIO_MAPR2_TIM67_DAC_DMA_REMAP (1 << 11) /* Bit 11: TIM67_DAC DMA remapping */ +# define AFIO_MAPR2_TIM12_REMAP (1 << 12) /* Bit 12: TIM12 remapping */ +# define AFIO_MAPR2_MISC_REMAP (1 << 13) /* Bit 13: Miscellaneous features remapping */ +#endif + #endif /* __ARCH_ARM_SRC_STM32_CHIP_STM32F10XXX_GPIO_H */ diff --git a/nuttx/arch/arm/src/stm32/chip/stm32f10xxx_memorymap.h b/nuttx/arch/arm/src/stm32/chip/stm32f10xxx_memorymap.h index ed1bc2625..a1d2e26d3 100644 --- a/nuttx/arch/arm/src/stm32/chip/stm32f10xxx_memorymap.h +++ b/nuttx/arch/arm/src/stm32/chip/stm32f10xxx_memorymap.h @@ -60,7 +60,9 @@ #define STM32_TIM5_BASE 0x40000c00 /* 0x40000c00 - 0x40000fff: TIM5 timer */ #define STM32_TIM6_BASE 0x40001000 /* 0x40001000 - 0x400013ff: TIM6 timer */ #define STM32_TIM7_BASE 0x40001400 /* 0x40001400 - 0x400007ff: TIM7 timer */ - /* 0x40001800 - 0x40000fff: Reserved */ +#define STM32_TIM12_BASE 0x40001800 /* 0x40001800 - 0x40001bff: TIM12 timer */ +#define STM32_TIM13_BASE 0x40001c00 /* 0x40001c00 - 0x40001fff: TIM13 timer */ +#define STM32_TIM14_BASE 0x40002000 /* 0x40002000 - 0x400023ff: TIM14 timer */ #define STM32_RTC_BASE 0x40002800 /* 0x40002800 - 0x40002bff: RTC */ #define STM32_WWDG_BASE 0x40002c00 /* 0x40002C00 - 0x40002fff: Window watchdog (WWDG) */ #define STM32_IWDG_BASE 0x40003000 /* 0x40003000 - 0x400033ff: Independent watchdog (IWDG) */ @@ -83,8 +85,8 @@ #define STM32_BKP_BASE 0x40006c00 /* 0x40006c00 - 0x40006fff: Backup registers (BKP) */ #define STM32_PWR_BASE 0x40007000 /* 0x40007000 - 0x400073ff: Power control PWR */ #define STM32_DAC_BASE 0x40007400 /* 0x40007400 - 0x400077ff: DAC */ - /* 0x40007800 - 0x4000ffff: Reserved */ - +#define STM32_CEC_BASE 0x40007800 /* 0x40007800 - 0x40007bff: CEC */ + /* 0x40007c00 - 0x4000ffff: Reserved */ /* APB2 bus */ #define STM32_AFIO_BASE 0x40010000 /* 0x40010000 - 0x400103ff: AFIO */ @@ -102,44 +104,49 @@ #define STM32_SPI1_BASE 0x40013000 /* 0x40013000 - 0x400133ff: SPI1 */ #define STM32_TIM8_BASE 0x40013400 /* 0x40013400 - 0x400137ff: TIM8 timer */ #define STM32_USART1_BASE 0x40013800 /* 0x40013800 - 0x40013bff: USART1 */ -#define STM32_ADC3_BASE 0x40012800 /* 0x40012800 - 0x40013fff: ADC3 */ - /* 0x40014000 - 0x40017fff: Reserved */ +#define STM32_ADC3_BASE 0x40012800 /* 0x40012800 - 0x40013c00: ADC3 */ + /* 0x40013c00 - 0x40013fff: Reserved */ +#define STM32_TIM15_BASE 0x40014400 /* 0x40014400 - 0x400147ff: TIM15 */ +#define STM32_TIM16_BASE 0x40014400 /* 0x40014400 - 0x400147ff: TIM16 */ +#define STM32_TIM17_BASE 0x40014800 /* 0x40014800 - 0x40014bff: TIM17 */ + /* 0x40014c00 - 0x4001ffff: Reserved */ + /* AHB bus */ -#define STM32_SDIO_BASE 0x40018000 /* 0x40018000 - 0x400183ff: SDIO */ - /* 0x40018400 - 0x40017fff: Reserved */ -#define STM32_DMA1_BASE 0x40020000 /* 0x40020000 - 0x400203ff: DMA1 */ -#define STM32_DMA2_BASE 0x40020400 /* 0x40020000 - 0x400207ff: DMA2 */ - /* 0x40020800 - 0x40020fff: Reserved */ -#define STM32_RCC_BASE 0x40021000 /* 0x40021000 - 0x400213ff: Reset and Clock control RCC */ - /* 0x40021400 - 0x40021fff: Reserved */ -#define STM32_OTGFS_BASE 0x50000000 /* 0x50000000 - 0x500003ff: USB OTG FS */ -#define STM32_FLASHIF_BASE 0x40022000 /* 0x40022000 - 0x400223ff: Flash memory interface */ -#define STM32_CRC_BASE 0x40028000 /* 0x40023000 - 0x400233ff: CRC */ - /* 0x40023400 - 0x40027fff: Reserved */ -#define STM32_ETHERNET_BASE 0x40028000 /* 0x40028000 - 0x40029fff: Ethernet */ - /* 0x40030000 - 0x4fffffff: Reserved */ +#define STM32_SDIO_BASE 0x40018000 /* 0x40018000 - 0x400183ff: SDIO */ + /* 0x40018400 - 0x40017fff: Reserved */ +#define STM32_DMA1_BASE 0x40020000 /* 0x40020000 - 0x400203ff: DMA1 */ +#define STM32_DMA2_BASE 0x40020400 /* 0x40020000 - 0x400207ff: DMA2 */ + /* 0x40020800 - 0x40020fff: Reserved */ +#define STM32_RCC_BASE 0x40021000 /* 0x40021000 - 0x400213ff: Reset and Clock control RCC */ + /* 0x40021400 - 0x40021fff: Reserved */ +#define STM32_OTGFS_BASE 0x50000000 /* 0x50000000 - 0x500003ff: USB OTG FS */ +#define STM32_FLASHIF_BASE 0x40022000 /* 0x40022000 - 0x400223ff: Flash memory interface */ +#define STM32_CRC_BASE 0x40028000 /* 0x40023000 - 0x400233ff: CRC */ + /* 0x40023400 - 0x40027fff: Reserved */ +#define STM32_ETHERNET_BASE 0x40028000 /* 0x40028000 - 0x40029fff: Ethernet */ + /* 0x40030000 - 0x4fffffff: Reserved */ /* Peripheral BB base */ -#define STM32_PERIPHBB_BASE 0x42000000 +#define STM32_PERIPHBB_BASE 0x42000000 /* Flexible SRAM controller (FSMC) */ -#define STM32_FSMC_BANK1 0x60000000 /* 0x60000000-0x6fffffff: 256Mb NOR/SRAM */ -#define STM32_FSMC_BANK2 0x70000000 /* 0x70000000-0x7fffffff: 256Mb NAND FLASH */ -#define STM32_FSMC_BANK3 0x80000000 /* 0x80000000-0x8fffffff: 256Mb NAND FLASH */ -#define STM32_FSMC_BANK4 0x90000000 /* 0x90000000-0x9fffffff: 256Mb PC CARD*/ -#define STM32_IS_EXTSRAM(a) ((((uint32_t)(a)) & STM32_REGION_MASK) == STM32_FSMC_BANK1) +#define STM32_FSMC_BANK1 0x60000000 /* 0x60000000-0x6fffffff: 256Mb NOR/SRAM */ +#define STM32_FSMC_BANK2 0x70000000 /* 0x70000000-0x7fffffff: 256Mb NAND FLASH */ +#define STM32_FSMC_BANK3 0x80000000 /* 0x80000000-0x8fffffff: 256Mb NAND FLASH */ +#define STM32_FSMC_BANK4 0x90000000 /* 0x90000000-0x9fffffff: 256Mb PC CARD*/ +#define STM32_IS_EXTSRAM(a) ((((uint32_t)(a)) & STM32_REGION_MASK) == STM32_FSMC_BANK1) -#define STM32_FSMC_BASE 0xa0000000 /* 0xa0000000-0xbfffffff: 512Mb FSMC register block */ +#define STM32_FSMC_BASE 0xa0000000 /* 0xa0000000-0xbfffffff: 512Mb FSMC register block */ /* Other registers -- see armv7-m/nvic.h for standard Cortex-M3 registers in this * address range */ -#define STM32_SCS_BASE 0xe000e000 -#define STM32_DEBUGMCU_BASE 0xe0042000 +#define STM32_SCS_BASE 0xe000e000 +#define STM32_DEBUGMCU_BASE 0xe0042000 #endif /* __ARCH_ARM_SRC_STM32_CHIP_STM32F10XXX_MEMORYMAP_H */ diff --git a/nuttx/arch/arm/src/stm32/chip/stm32f10xxx_rcc.h b/nuttx/arch/arm/src/stm32/chip/stm32f10xxx_rcc.h index 60365b921..1a792b7eb 100644 --- a/nuttx/arch/arm/src/stm32/chip/stm32f10xxx_rcc.h +++ b/nuttx/arch/arm/src/stm32/chip/stm32f10xxx_rcc.h @@ -163,7 +163,9 @@ # define RCC_CFGR_PLLMUL_CLKx14 (12 << RCC_CFGR_PLLMUL_SHIFT) /* 1100: PLL input clock x 14 */ # define RCC_CFGR_PLLMUL_CLKx15 (13 << RCC_CFGR_PLLMUL_SHIFT) /* 1101: PLL input clock x 15 */ # define RCC_CFGR_PLLMUL_CLKx16 (14 << RCC_CFGR_PLLMUL_SHIFT) /* 111x: PLL input clock x 16 */ -#define RCC_CFGR_USBPRE (1 << 22) /* Bit 22: USB prescaler */ +#ifndef CONFIG_STM32_VALUELINE +# define RCC_CFGR_USBPRE (1 << 22) /* Bit 22: USB prescaler */ +#endif #define RCC_CFGR_MCO_SHIFT (24) /* Bits 26-24: Microcontroller Clock Output */ #define RCC_CFGR_MCO_MASK (0x0f << RCC_CFGR_MCO_SHIFT) # define RCC_CFGR_NOCLK (0 << RCC_CFGR_MCO_SHIFT) /* 0xx: No clock */ @@ -207,12 +209,22 @@ #define TCC_APB2RSTR_IOPFRST (1 << 7) /* Bit 7: IO port F reset */ #define TCC_APB2RSTR_IOPGRST (1 << 8) /* Bit 8: IO port G reset */ #define RCC_APB2RSTR_ADC1RST (1 << 9) /* Bit 9: ADC 1 interface reset */ -#define RCC_APB2RSTR_ADC2RST (1 << 10) /* Bit 10: ADC 2 interface reset */ +#ifndef CONFIG_STM32_VALUELINE +# define RCC_APB2RSTR_ADC2RST (1 << 10) /* Bit 10: ADC 2 interface reset */ +#endif #define RCC_APB2RSTR_TIM1RST (1 << 11) /* Bit 11: TIM1 Timer reset */ #define RCC_APB2RSTR_SPI1RST (1 << 12) /* Bit 12: SPI 1 reset */ -#define RCC_APB2RSTR_TIM8RST (1 << 13) /* Bit 13: TIM8 Timer reset */ +#ifndef CONFIG_STM32_VALUELINE +# define RCC_APB2RSTR_TIM8RST (1 << 13) /* Bit 13: TIM8 Timer reset */ +#endif #define RCC_APB2RSTR_USART1RST (1 << 14) /* Bit 14: USART1 reset */ -#define RCC_APB2RSTR_ADC3RST (1 << 15) /* Bit 15: ADC3 interface reset */ +#ifndef CONFIG_STM32_VALUELINE +# define RCC_APB2RSTR_ADC3RST (1 << 15) /* Bit 15: ADC3 interface reset */ +#else +# define RCC_APB2RSTR_TIM15RST (1 << 16) /* Bit 16: TIM15 reset */ +# define RCC_APB2RSTR_TIM16RST (1 << 17) /* Bit 17: TIM16 reset */ +# define RCC_APB2RSTR_TIM17RST (1 << 18) /* Bit 18: TIM17 reset */ +#endif /* APB1 Peripheral reset register */ @@ -222,6 +234,11 @@ #define RCC_APB1RSTR_TIM5RST (1 << 3) /* Bit 3: Timer 5 reset */ #define RCC_APB1RSTR_TIM6RST (1 << 4) /* Bit 4: Timer 6 reset */ #define RCC_APB1RSTR_TIM7RST (1 << 5) /* Bit 5: Timer 7 reset */ +#ifdef CONFIG_STM32_VALUELINE +# define RCC_APB1RSTR_TIM12RST (1 << 6) /* Bit 6: TIM12 reset */ +# define RCC_APB1RSTR_TIM13RST (1 << 7) /* Bit 7: TIM13 reset */ +# define RCC_APB1RSTR_TIM14RST (1 << 8) /* Bit 8: TIM14 reset */ +#endif #define RCC_APB1RSTR_WWDGRST (1 << 11) /* Bit 11: Window Watchdog reset */ #define RCC_APB1RSTR_SPI2RST (1 << 14) /* Bit 14: SPI 2 reset */ #define RCC_APB1RSTR_SPI3RST (1 << 15) /* Bit 15: SPI 3 reset */ @@ -231,12 +248,17 @@ #define RCC_APB1RSTR_UART5RST (1 << 20) /* Bit 18: UART 5 reset */ #define RCC_APB1RSTR_I2C1RST (1 << 21) /* Bit 21: I2C 1 reset */ #define RCC_APB1RSTR_I2C2RST (1 << 22) /* Bit 22: I2C 2 reset */ -#define RCC_APB1RSTR_USBRST (1 << 23) /* Bit 23: USB reset */ -#define RCC_APB1RSTR_CAN1RST (1 << 25) /* Bit 25: CAN1 reset */ -#define RCC_APB1RSTR_CAN2RST (1 << 26) /* Bit 26: CAN2 reset */ +#ifndef CONFIG_STM32_VALUELINE +# define RCC_APB1RSTR_USBRST (1 << 23) /* Bit 23: USB reset */ +# define RCC_APB1RSTR_CAN1RST (1 << 25) /* Bit 25: CAN1 reset */ +# define RCC_APB1RSTR_CAN2RST (1 << 26) /* Bit 26: CAN2 reset */ +#endif #define RCC_APB1RSTR_BKPRST (1 << 27) /* Bit 27: Backup interface reset */ #define RCC_APB1RSTR_PWRRST (1 << 28) /* Bit 28: Power interface reset */ #define RCC_APB1RSTR_DACRST (1 << 29) /* Bit 29: DAC interface reset */ +#ifdef CONFIG_STM32_VALUELINE +# define RCC_APB1RSTR_CECRST (1 << 30) /* Bit 30: CEC reset */ +#endif /* AHB Peripheral Clock enable register */ @@ -246,7 +268,9 @@ #define RCC_AHBENR_FLITFEN (1 << 4) /* Bit 4: FLITF clock enable */ #define RCC_AHBENR_CRCEN (1 << 6) /* Bit 6: CRC clock enable */ #define RCC_AHBENR_FSMCEN (1 << 8) /* Bit 8: FSMC clock enable */ -#define RCC_AHBENR_SDIOEN (1 << 10) /* Bit 10: SDIO clock enable */ +#ifndef CONFIG_STM32_VALUELINE +# define RCC_AHBENR_SDIOEN (1 << 10) /* Bit 10: SDIO clock enable */ +#endif #ifdef CONFIG_STM32_CONNECTIVITYLINE # define RCC_AHBENR_ETHMACEN (1 << 14) /* Bit 14: Ethernet MAC clock enable */ # define RCC_AHBENR_ETHMACTXEN (1 << 15) /* Bit 15: Ethernet MAC TX clock enable */ @@ -272,12 +296,22 @@ #define RCC_APB2ENR_IOPFEN (1 << 7) /* Bit 7: I/O port F clock enable */ #define RCC_APB2ENR_IOPGEN (1 << 8) /* Bit 8: I/O port G clock enable */ #define RCC_APB2ENR_ADC1EN (1 << 9) /* Bit 9: ADC 1 interface clock enable */ -#define RCC_APB2ENR_ADC2EN (1 << 10) /* Bit 10: ADC 2 interface clock enable */ +#ifndef CONFIG_STM32_VALUELINE +# define RCC_APB2ENR_ADC2EN (1 << 10) /* Bit 10: ADC 2 interface clock enable */ +#endif #define RCC_APB2ENR_TIM1EN (1 << 11) /* Bit 11: TIM1 Timer clock enable */ #define RCC_APB2ENR_SPI1EN (1 << 12) /* Bit 12: SPI 1 clock enable */ -#define RCC_APB2ENR_TIM8EN (1 << 13) /* Bit 13: TIM8 Timer clock enable */ +#ifndef CONFIG_STM32_VALUELINE +# define RCC_APB2ENR_TIM8EN (1 << 13) /* Bit 13: TIM8 Timer clock enable */ +#endif #define RCC_APB2ENR_USART1EN (1 << 14) /* Bit 14: USART1 clock enable */ -#define RCC_APB2ENR_ADC3EN (1 << 15) /* Bit 14: ADC3 interface clock enable */ +#ifndef CONFIG_STM32_VALUELINE +# define RCC_APB2ENR_ADC3EN (1 << 15) /* Bit 14: ADC3 interface clock enable */ +#else +# define RCC_APB2ENR_TIM15EN (1 << 16) /* Bit 16: TIM15 clock enable */ +# define RCC_APB2ENR_TIM16EN (1 << 17) /* Bit 17: TIM16 clock enable */ +# define RCC_APB2ENR_TIM17EN (1 << 18) /* Bit 18: TIM17 clock enable */ +#endif /* APB1 Peripheral Clock enable register */ @@ -287,6 +321,11 @@ #define RCC_APB1ENR_TIM5EN (1 << 3) /* Bit 3: Timer 5 clock enable */ #define RCC_APB1ENR_TIM6EN (1 << 4) /* Bit 4: Timer 6 clock enable */ #define RCC_APB1ENR_TIM7EN (1 << 5) /* Bit 5: Timer 7 clock enable */ +#ifdef CONFIG_STM32_VALUELINE +# define RCC_APB1ENR_TIM12EN (1 << 6) /* Bit 6: Timer 12 clock enable */ +# define RCC_APB1ENR_TIM13EN (1 << 7) /* Bit 7: Timer 13 clock enable */ +# define RCC_APB1ENR_TIM14EN (1 << 8) /* Bit 8: Timer 14 clock enable */ +#endif #define RCC_APB1ENR_WWDGEN (1 << 11) /* Bit 11: Window Watchdog clock enable */ #define RCC_APB1ENR_SPI2EN (1 << 14) /* Bit 14: SPI 2 clock enable */ #define RCC_APB1ENR_SPI3EN (1 << 15) /* Bit 15: SPI 3 clock enable */ @@ -296,12 +335,17 @@ #define RCC_APB1ENR_UART5EN (1 << 20) /* Bit 20: UART 5 clock enable */ #define RCC_APB1ENR_I2C1EN (1 << 21) /* Bit 21: I2C 1 clock enable */ #define RCC_APB1ENR_I2C2EN (1 << 22) /* Bit 22: I2C 2 clock enable */ -#define RCC_APB1ENR_USBEN (1 << 23) /* Bit 23: USB clock enable */ -#define RCC_APB1ENR_CAN1EN (1 << 25) /* Bit 25: CAN1 clock enable */ -#define RCC_APB1ENR_CAN2EN (1 << 26) /* Bit 25: CAN2 clock enable */ +#ifndef CONFIG_STM32_VALUELINE +# define RCC_APB1ENR_USBEN (1 << 23) /* Bit 23: USB clock enable */ +# define RCC_APB1ENR_CAN1EN (1 << 25) /* Bit 25: CAN1 clock enable */ +# define RCC_APB1ENR_CAN2EN (1 << 26) /* Bit 25: CAN2 clock enable */ +#endif #define RCC_APB1ENR_BKPEN (1 << 27) /* Bit 27: Backup interface clock enable */ #define RCC_APB1ENR_PWREN (1 << 28) /* Bit 28: Power interface clock enable */ #define RCC_APB1ENR_DACEN (1 << 29) /* Bit 29: DAC interface clock enable */ +#ifdef CONFIG_STM32_VALUELINE +# define RCC_APB1ENR_CECEN (1 << 30) /* Bit 30: CEC clock enable */ +#endif /* Backup domain control register */ @@ -331,7 +375,7 @@ #if defined(CONFIG_STM32_VALUELINE) || defined(CONFIG_STM32_CONNECTIVITYLINE) -/* Clock configuration register 2 (For connectivity line only) */ +/* Clock configuration register 2 (For value line and connectivity line only) */ #define RCC_CFGR2_PREDIV1_SHIFT (0) #define RCC_CFGR2_PREDIV1_MASK (0x0f << RCC_CFGR2_PREDIV1_SHIFT) @@ -352,6 +396,10 @@ # define RCC_CFGR2_PREDIV1d15 (14 << RCC_CFGR2_PREDIV1_SHIFT) # define RCC_CFGR2_PREDIV1d16 (15 << RCC_CFGR2_PREDIV1_SHIFT) +#endif + +#ifdef CONFIG_STM32_CONNECTIVITYLINE + #define RCC_CFGR2_PREDIV2_SHIFT (4) #define RCC_CFGR2_PREDIV2_MASK (0x0f << RCC_CFGR2_PREDIV2_SHIFT) # define RCC_CFGR2_PREDIV2d1 (0 << RCC_CFGR2_PREDIV2_SHIFT) diff --git a/nuttx/arch/arm/src/stm32/chip/stm32f10xxx_vectors.h b/nuttx/arch/arm/src/stm32/chip/stm32f10xxx_vectors.h index b8d71799f..24822c37d 100644 --- a/nuttx/arch/arm/src/stm32/chip/stm32f10xxx_vectors.h +++ b/nuttx/arch/arm/src/stm32/chip/stm32f10xxx_vectors.h @@ -49,15 +49,77 @@ * definition that provides the number of supported vectors. */ -#ifdef CONFIG_ARMV7M_CMNVECTOR +# ifdef CONFIG_ARMV7M_CMNVECTOR -/* Reserve 60 interrupt table entries for I/O interrupts. */ +/* Reserve 61 interrupt table entries for I/O interrupts. */ -# define ARMV7M_PERIPHERAL_INTERRUPTS 60 +# define ARMV7M_PERIPHERAL_INTERRUPTS 61 #else -# error This target requires CONFIG_ARMV7M_CMNVECTOR -#endif /* CONFIG_ARMV7M_CMNVECTOR */ + +VECTOR(stm32_wwdg, STM32_IRQ_WWDG) /* Vector 16+0: Window Watchdog interrupt */ +VECTOR(stm32_pvd, STM32_IRQ_PVD) /* Vector 16+1: PVD through EXTI Line detection interrupt */ +VECTOR(stm32_tamper, STM32_IRQ_TAMPER) /* Vector 16+2: Tamper interrupt */ +VECTOR(stm32_rtc, STM32_IRQ_RTC) /* Vector 16+3: RTC Wakeup through EXTI line interrupt */ +VECTOR(stm32_flash, STM32_IRQ_FLASH) /* Vector 16+4: Flash global interrupt */ +VECTOR(stm32_rcc, STM32_IRQ_RCC) /* Vector 16+5: RCC global interrupt */ +VECTOR(stm32_exti0, STM32_IRQ_EXTI0) /* Vector 16+6: EXTI Line 0 interrupt */ +VECTOR(stm32_exti1, STM32_IRQ_EXTI1) /* Vector 16+7: EXTI Line 1 interrupt */ +VECTOR(stm32_exti2, STM32_IRQ_EXTI2) /* Vector 16+8: EXTI Line 2 interrupt */ +VECTOR(stm32_exti3, STM32_IRQ_EXTI3) /* Vector 16+9: EXTI Line 3 interrupt */ +VECTOR(stm32_exti4, STM32_IRQ_EXTI4) /* Vector 16+10: EXTI Line 4 interrupt */ +VECTOR(stm32_dma1ch1, STM32_IRQ_DMA1CH1) /* Vector 16+11: DMA1 Channel 1 global interrupt */ +VECTOR(stm32_dma1ch2, STM32_IRQ_DMA1CH2) /* Vector 16+12: DMA1 Channel 2 global interrupt */ +VECTOR(stm32_dma1ch3, STM32_IRQ_DMA1CH3) /* Vector 16+13: DMA1 Channel 3 global interrupt */ +VECTOR(stm32_dma1ch4, STM32_IRQ_DMA1CH4) /* Vector 16+14: DMA1 Channel 4 global interrupt */ +VECTOR(stm32_dma1ch5, STM32_IRQ_DMA1CH5) /* Vector 16+15: DMA1 Channel 5 global interrupt */ +VECTOR(stm32_dma1ch6, STM32_IRQ_DMA1CH6) /* Vector 16+16: DMA1 Channel 6 global interrupt */ +VECTOR(stm32_dma1ch7, STM32_IRQ_DMA1CH7) /* Vector 16+17: DMA1 Channel 7 global interrupt */ +VECTOR(stm32_adc1, STM32_IRQ_ADC1) /* Vector 16+18: ADC1 global interrupt */ +UNUSED(STM32_IRQ_RESERVED0) /* Vector 16+19: Reserved 0 */ +UNUSED(STM32_IRQ_RESERVED1) /* Vector 16+20: Reserved 1 */ +UNUSED(STM32_IRQ_RESERVED2) /* Vector 16+21: Reserved 2 */ +UNUSED(STM32_IRQ_RESERVED3) /* Vector 16+22: Reserved 3 */ +VECTOR(stm32_exti95, STM32_IRQ_EXTI95) /* Vector 16+23: EXTI Line[9:5] interrupts */ +VECTOR(stm32_tim1brk, STM32_IRQ_TIM1BRK) /* Vector 16+24: TIM1 Break interrupt; TIM15 global interrupt */ +VECTOR(stm32_tim1up, STM32_IRQ_TIM1UP) /* Vector 16+25: TIM1 Update interrupt; TIM16 global interrupt */ +VECTOR(stm32_tim1trgcom, STM32_IRQ_TIM1TRGCOM) /* Vector 16+26: TIM1 Trigger and Commutation interrupts; TIM17 global interrupt */ +VECTOR(stm32_tim1cc, STM32_IRQ_TIM1CC) /* Vector 16+27: TIM1 Capture Compare interrupt */ +VECTOR(stm32_tim2, STM32_IRQ_TIM2) /* Vector 16+28: TIM2 global interrupt */ +VECTOR(stm32_tim3, STM32_IRQ_TIM3) /* Vector 16+29: TIM3 global interrupt */ +VECTOR(stm32_tim4, STM32_IRQ_TIM4) /* Vector 16+30: TIM4 global interrupt */ +VECTOR(stm32_i2c1ev, STM32_IRQ_I2C1EV) /* Vector 16+31: I2C1 event interrupt */ +VECTOR(stm32_i2c1er, STM32_IRQ_I2C1ER) /* Vector 16+32: I2C1 error interrupt */ +VECTOR(stm32_i2c2ev, STM32_IRQ_I2C2EV) /* Vector 16+33: I2C2 event interrupt */ +VECTOR(stm32_i2c2er, STM32_IRQ_I2C2ER) /* Vector 16+34: I2C2 error interrupt */ +VECTOR(stm32_spi1, STM32_IRQ_SPI1) /* Vector 16+35: SPI1 global interrupt */ +VECTOR(stm32_spi2, STM32_IRQ_SPI2) /* Vector 16+36: SPI2 global interrupt */ +VECTOR(stm32_usart1, STM32_IRQ_USART1) /* Vector 16+37: USART1 global interrupt */ +VECTOR(stm32_usart2, STM32_IRQ_USART2) /* Vector 16+38: USART2 global interrupt */ +VECTOR(stm32_usart3, STM32_IRQ_USART3) /* Vector 16+39: USART3 global interrupt */ +VECTOR(stm32_exti1510, STM32_IRQ_EXTI1510) /* Vector 16+40: EXTI Line[15:10] interrupts */ +VECTOR(stm32_rtcalr, STM32_IRQ_RTCALR) /* Vector 16+41: RTC alarms (A and B) through EXTI line interrupt */ +VECTOR(stm32_cec, STM32_IRQ_CEC) /* Vector 16+42: CEC global interrupt */ +VECTOR(stm32_tim12, STM32_IRQ_TIM12) /* Vector 16+43: TIM12 global interrupt */ +VECTOR(stm32_tim13, STM32_IRQ_TIM13) /* Vector 16+44: TIM13 global interrupt */ +VECTOR(stm32_tim14, STM32_IRQ_TIM14) /* Vector 16+45: TIM14 global interrupt */ +UNUSED(STM32_IRQ_RESERVED4) /* Vector 16+46: Reserved 4 */ +UNUSED(STM32_IRQ_RESERVED5) /* Vector 16+47: Reserved 5 */ +VECTOR(stm32_fsmc, STM32_IRQ_FSMC) /* Vector 16+48: FSMC global interrupt */ +UNUSED(STM32_IRQ_RESERVED6) /* Vector 16+49: Reserved 6 */ +VECTOR(stm32_tim5, STM32_IRQ_TIM5) /* Vector 16+50: TIM5 global interrupt */ +VECTOR(stm32_spi3, STM32_IRQ_SPI3) /* Vector 16+51: SPI3 global interrupt */ +VECTOR(stm32_uart4, STM32_IRQ_UART4) /* Vector 16+52: USART2 global interrupt */ +VECTOR(stm32_uart5, STM32_IRQ_UART5) /* Vector 16+53: USART5 global interrupt */ +VECTOR(stm32_tim6, STM32_IRQ_TIM6) /* Vector 16+54: TIM6 global interrupt */ +VECTOR(stm32_tim7, STM32_IRQ_TIM7) /* Vector 16+55: TIM7 global interrupt */ +VECTOR(stm32_dma2ch1, STM32_IRQ_DMA2CH1) /* Vector 16+56: DMA2 Channel 1 global interrupt */ +VECTOR(stm32_dma2ch2, STM32_IRQ_DMA2CH2) /* Vector 16+57: DMA2 Channel 2 global interrupt */ +VECTOR(stm32_dma2ch3, STM32_IRQ_DMA2CH3) /* Vector 16+58: DMA2 Channel 3 global interrupt */ +VECTOR(stm32_dma2ch45, STM32_IRQ_DMA2CH45) /* Vector 16+59: DMA2 Channel 4 and 5 global interrupt */ +VECTOR(stm32_dma2ch5, STM32_IRQ_DMA2CH5) /* Vector 16+60: DMA2 Channel 5 global interrupt */ + +# endif /* CONFIG_ARMV7M_CMNVECTOR */ #elif defined(CONFIG_STM32_CONNECTIVITYLINE) diff --git a/nuttx/arch/arm/src/stm32/chip/stm32f20xxx_pinmap.h b/nuttx/arch/arm/src/stm32/chip/stm32f20xxx_pinmap.h index 817e747f7..699ca4fdc 100644 --- a/nuttx/arch/arm/src/stm32/chip/stm32f20xxx_pinmap.h +++ b/nuttx/arch/arm/src/stm32/chip/stm32f20xxx_pinmap.h @@ -222,7 +222,7 @@ #define GPIO_ETH_MII_TX_EN_2 (GPIO_ALT|GPIO_AF11|GPIO_SPEED_100MHz|GPIO_PUSHPULL|GPIO_PORTG|GPIO_PIN11) #define GPIO_ETH_PPS_OUT_1 (GPIO_ALT|GPIO_AF11|GPIO_SPEED_100MHz|GPIO_PUSHPULL|GPIO_PORTB|GPIO_PIN5) #define GPIO_ETH_PPS_OUT_2 (GPIO_ALT|GPIO_AF11|GPIO_SPEED_100MHz|GPIO_PUSHPULL|GPIO_PORTG|GPIO_PIN8) -#define GPIO_ETH_RMII_CRS_DV (GPIO_ALT|GPIO_AF11|GPIO_SPEED_100MHz|GPIO_PUSHPULLGPIO_PORTA|GPIO_PIN7) +#define GPIO_ETH_RMII_CRS_DV (GPIO_ALT|GPIO_AF11|GPIO_SPEED_100MHz|GPIO_PUSHPULL|GPIO_PORTA|GPIO_PIN7) #define GPIO_ETH_RMII_REF_CLK (GPIO_ALT|GPIO_AF11|GPIO_SPEED_100MHz|GPIO_PUSHPULL|GPIO_PORTA|GPIO_PIN1) #define GPIO_ETH_RMII_RXD0 (GPIO_ALT|GPIO_AF11|GPIO_SPEED_100MHz|GPIO_PUSHPULL|GPIO_PORTC|GPIO_PIN4) #define GPIO_ETH_RMII_RXD1 (GPIO_ALT|GPIO_AF11|GPIO_SPEED_100MHz|GPIO_PUSHPULL|GPIO_PORTC|GPIO_PIN5) diff --git a/nuttx/arch/arm/src/stm32/chip/stm32f40xxx_pinmap.h b/nuttx/arch/arm/src/stm32/chip/stm32f40xxx_pinmap.h index ae2436a70..31e51caf0 100644 --- a/nuttx/arch/arm/src/stm32/chip/stm32f40xxx_pinmap.h +++ b/nuttx/arch/arm/src/stm32/chip/stm32f40xxx_pinmap.h @@ -222,7 +222,7 @@ #define GPIO_ETH_MII_TX_EN_2 (GPIO_ALT|GPIO_AF11|GPIO_SPEED_100MHz|GPIO_PUSHPULL|GPIO_PORTG|GPIO_PIN11) #define GPIO_ETH_PPS_OUT_1 (GPIO_ALT|GPIO_AF11|GPIO_SPEED_100MHz|GPIO_PUSHPULL|GPIO_PORTB|GPIO_PIN5) #define GPIO_ETH_PPS_OUT_2 (GPIO_ALT|GPIO_AF11|GPIO_SPEED_100MHz|GPIO_PUSHPULL|GPIO_PORTG|GPIO_PIN8) -#define GPIO_ETH_RMII_CRS_DV (GPIO_ALT|GPIO_AF11|GPIO_SPEED_100MHz|GPIO_PUSHPULLGPIO_PORTA|GPIO_PIN7) +#define GPIO_ETH_RMII_CRS_DV (GPIO_ALT|GPIO_AF11|GPIO_SPEED_100MHz|GPIO_PUSHPULL|GPIO_PORTA|GPIO_PIN7) #define GPIO_ETH_RMII_REF_CLK (GPIO_ALT|GPIO_AF11|GPIO_SPEED_100MHz|GPIO_PUSHPULL|GPIO_PORTA|GPIO_PIN1) #define GPIO_ETH_RMII_RXD0 (GPIO_ALT|GPIO_AF11|GPIO_SPEED_100MHz|GPIO_PUSHPULL|GPIO_PORTC|GPIO_PIN4) #define GPIO_ETH_RMII_RXD1 (GPIO_ALT|GPIO_AF11|GPIO_SPEED_100MHz|GPIO_PUSHPULL|GPIO_PORTC|GPIO_PIN5) diff --git a/nuttx/arch/arm/src/stm32/stm32_adc.h b/nuttx/arch/arm/src/stm32/stm32_adc.h index c25da3830..7b6c13b33 100644 --- a/nuttx/arch/arm/src/stm32/stm32_adc.h +++ b/nuttx/arch/arm/src/stm32/stm32_adc.h @@ -281,7 +281,7 @@ #if defined(ADC1_HAVE_TIMER) || defined(ADC2_HAVE_TIMER) || defined(ADC3_HAVE_TIMER) # define ADC_HAVE_TIMER 1 -# if defined(CONFIG_STM32_STM32F10XX) && defined(CONFIG_STM32_FORCEPOWER) +# if defined(CONFIG_STM32_STM32F10XX) && !defined(CONFIG_STM32_FORCEPOWER) # warning "CONFIG_STM32_FORCEPOWER must be defined to enable the timer(s)" # endif #else diff --git a/nuttx/arch/arm/src/stm32/stm32_eth.c b/nuttx/arch/arm/src/stm32/stm32_eth.c index 3054142ce..006f67142 100644 --- a/nuttx/arch/arm/src/stm32/stm32_eth.c +++ b/nuttx/arch/arm/src/stm32/stm32_eth.c @@ -2594,6 +2594,17 @@ static int stm32_phyinit(FAR struct stm32_ethmac_s *priv) } up_mdelay(PHY_RESET_DELAY); + /* Perform any necessary, board-specific PHY initialization */ + +#ifdef CONFIG_STM32_PHYINIT + ret = stm32_phy_boardinitialize(0); + if (ret < 0) + { + ndbg("Failed to initialize the PHY: %d\n", ret); + return ret; + } +#endif + /* Special workaround for the Davicom DM9161 PHY is required. */ #ifdef CONFIG_PHY_DM9161 diff --git a/nuttx/arch/arm/src/stm32/stm32_eth.h b/nuttx/arch/arm/src/stm32/stm32_eth.h index f0c14b5b1..4501712b1 100644 --- a/nuttx/arch/arm/src/stm32/stm32_eth.h +++ b/nuttx/arch/arm/src/stm32/stm32_eth.h @@ -66,14 +66,13 @@ extern "C" { * Function: stm32_ethinitialize * * Description: - * Initialize the Ethernet driver for one interface. If the STM32 chip - * supports multiple Ethernet controllers, then board specific logic - * must implement up_netinitialize() and call this function to initialize - * the desired interfaces. + * Initialize the Ethernet driver for one interface. If the STM32 chip supports + * multiple Ethernet controllers, then board specific logic must implement + * up_netinitialize() and call this function to initialize the desired interfaces. * * Parameters: - * intf - In the case where there are multiple EMACs, this value - * identifies which EMAC is to be initialized. + * intf - In the case where there are multiple EMACs, this value identifies which + * EMAC is to be initialized. * * Returned Value: * OK on success; Negated errno on failure. @@ -86,6 +85,30 @@ extern "C" { EXTERN int stm32_ethinitialize(int intf); #endif +/************************************************************************************ + * Function: stm32_phy_boardinitialize + * + * Description: + * Some boards require specialized initialization of the PHY before it can be used. + * This may include such things as configuring GPIOs, resetting the PHY, etc. If + * CONFIG_STM32_PHYINIT is defined in the configuration then the board specific + * logic must provide stm32_phyinitialize(); The STM32 Ethernet driver will call + * this function one time before it first uses the PHY. + * + * Parameters: + * intf - Always zero for now. + * + * Returned Value: + * OK on success; Negated errno on failure. + * + * Assumptions: + * + ************************************************************************************/ + +#ifdef CONFIG_STM32_PHYINIT +EXTERN int stm32_phy_boardinitialize(int intf); +#endif + #undef EXTERN #if defined(__cplusplus) } diff --git a/nuttx/arch/arm/src/stm32/stm32_i2c.c b/nuttx/arch/arm/src/stm32/stm32_i2c.c index a4b10b55c..c44a823db 100644 --- a/nuttx/arch/arm/src/stm32/stm32_i2c.c +++ b/nuttx/arch/arm/src/stm32/stm32_i2c.c @@ -107,17 +107,23 @@ #if !defined(CONFIG_STM32_I2CTIMEOSEC) && !defined(CONFIG_STM32_I2CTIMEOMS) # define CONFIG_STM32_I2CTIMEOSEC 0 -# define CONFIG_STM32_I2CTIMEOMS 500 /* Default is 500 milliseconds */ +# define CONFIG_STM32_I2CTIMEOMS 500 /* Default is 500 milliseconds */ #elif !defined(CONFIG_STM32_I2CTIMEOSEC) # define CONFIG_STM32_I2CTIMEOSEC 0 /* User provided milliseconds */ #elif !defined(CONFIG_STM32_I2CTIMEOMS) -# define CONFIG_STM32_I2CTIMEOMS 0 /* User provided seconds */ +# define CONFIG_STM32_I2CTIMEOMS 0 /* User provided seconds */ #endif /* Interrupt wait time timeout in system timer ticks */ -#define CONFIG_STM32_I2CTIMEOTICKS \ - (SEC2TICK(CONFIG_STM32_I2CTIMEOSEC) + MSEC2TICK(CONFIG_STM32_I2CTIMEOMS)) +#ifndef CONFIG_STM32_I2CTIMEOTICKS +# define CONFIG_STM32_I2CTIMEOTICKS \ + (SEC2TICK(CONFIG_STM32_I2CTIMEOSEC) + MSEC2TICK(CONFIG_STM32_I2CTIMEOMS)) +#endif + +#ifndef CONFIG_STM32_I2C_DYNTIMEO_STARTSTOP +# define CONFIG_STM32_I2C_DYNTIMEO_STARTSTOP TICK2USEC(CONFIG_STM32_I2CTIMEOTICKS) +#endif /* On the STM32F103ZE, there is an internal conflict between I2C1 and FSMC. In that * case, it is necessary to disable FSMC before each I2C1 access and re-enable FSMC @@ -129,6 +135,18 @@ # define I2C1_FSMC_CONFLICT #endif +/* Macros to convert a I2C pin to a GPIO output */ + +#if defined(CONFIG_STM32_STM32F10XX) +# define I2C_OUTPUT (GPIO_OUTPUT | GPIO_OUTPUT_SET | GPIO_CNF_OUTOD | \ + GPIO_MODE_50MHz) +#elif defined(CONFIG_STM32_STM32F20XX) || defined(CONFIG_STM32_STM32F40XX) +# define I2C_OUTPUT (GPIO_OUTPUT | GPIO_FLOAT | GPIO_OPENDRAIN |\ + GPIO_SPEED_50MHz | GPIO_OUTPUT_SET) +#endif + +#define MKI2C_OUTPUT(p) (((p) & (GPIO_PORT_MASK | GPIO_PIN_MASK)) | I2C_OUTPUT) + /* Debug ****************************************************************************/ /* CONFIG_DEBUG_I2C + CONFIG_DEBUG enables general I2C debug output. */ @@ -200,18 +218,16 @@ struct stm32_trace_s struct stm32_i2c_config_s { - uint32_t base; /* I2C base address */ + uint32_t base; /* I2C base address */ + uint32_t clk_bit; /* Clock enable bit */ + uint32_t reset_bit; /* Reset bit */ + uint32_t scl_pin; /* GPIO configuration for SCL as SCL */ + uint32_t sda_pin; /* GPIO configuration for SDA as SDA */ #ifndef CONFIG_I2C_POLLED - int ( *isr)(int, void *); /* Interrupt handler */ + int (*isr)(int, void *); /* Interrupt handler */ + uint32_t ev_irq; /* Event IRQ */ + uint32_t er_irq; /* Error IRQ */ #endif - uint32_t clk_bit; /* Clock enable bit */ - uint32_t reset_bit; /* Reset bit */ - uint32_t scl_pin; /* GPIO configuration for SCL as SCL */ - uint32_t scl_gpio; /* GPIO configuration for SCL as a GPIO */ - uint32_t sda_pin; /* GPIO configuration for SDA as SDA */ - uint32_t sda_gpio; /* GPIO configuration for SDA as a GPIO */ - uint32_t ev_irq; /* Event IRQ */ - uint32_t er_irq; /* Error IRQ */ }; /* I2C Device Private Data */ @@ -219,31 +235,31 @@ struct stm32_i2c_config_s struct stm32_i2c_priv_s { const struct stm32_i2c_config_s *config; /* Port configuration */ - int refs; /* Referernce count */ - sem_t sem_excl; /* Mutual exclusion semaphore */ + int refs; /* Referernce count */ + sem_t sem_excl; /* Mutual exclusion semaphore */ #ifndef CONFIG_I2C_POLLED - sem_t sem_isr; /* Interrupt wait semaphore */ + sem_t sem_isr; /* Interrupt wait semaphore */ #endif - volatile uint8_t intstate; /* Interrupt handshake (see enum stm32_intstate_e) */ + volatile uint8_t intstate; /* Interrupt handshake (see enum stm32_intstate_e) */ - uint8_t msgc; /* Message count */ - struct i2c_msg_s *msgv; /* Message list */ - uint8_t *ptr; /* Current message buffer */ - int dcnt; /* Current message length */ - uint16_t flags; /* Current message flags */ + uint8_t msgc; /* Message count */ + struct i2c_msg_s *msgv; /* Message list */ + uint8_t *ptr; /* Current message buffer */ + int dcnt; /* Current message length */ + uint16_t flags; /* Current message flags */ /* I2C trace support */ #ifdef CONFIG_I2C_TRACE - int tndx; /* Trace array index */ - uint32_t start_time; /* Time when the trace was started */ + int tndx; /* Trace array index */ + uint32_t start_time; /* Time when the trace was started */ /* The actual trace data */ struct stm32_trace_s trace[CONFIG_I2C_NTRACE]; #endif - uint32_t status; /* End of transfer SR2|SR1 status */ + uint32_t status; /* End of transfer SR2|SR1 status */ }; /* I2C Device, Instance */ @@ -270,8 +286,11 @@ static inline void stm32_i2c_modifyreg(FAR struct stm32_i2c_priv_s *priv, uint8_t offset, uint16_t clearbits, uint16_t setbits); static inline void stm32_i2c_sem_wait(FAR struct i2c_dev_s *dev); -static inline int stm32_i2c_sem_waitdone(FAR struct stm32_i2c_priv_s *priv, int timeout_us); -static inline void stm32_i2c_sem_waitstop(FAR struct stm32_i2c_priv_s *priv, int timeout_us); +#ifdef CONFIG_STM32_I2C_DYNTIMEO +static useconds_t stm32_i2c_tousecs(int msgc, FAR struct i2c_msg_s *msgs); +#endif /* CONFIG_STM32_I2C_DYNTIMEO */ +static inline int stm32_i2c_sem_waitdone(FAR struct stm32_i2c_priv_s *priv); +static inline void stm32_i2c_sem_waitstop(FAR struct stm32_i2c_priv_s *priv); static inline void stm32_i2c_sem_post(FAR struct i2c_dev_s *dev); static inline void stm32_i2c_sem_init(FAR struct i2c_dev_s *dev); static inline void stm32_i2c_sem_destroy(FAR struct i2c_dev_s *dev); @@ -281,7 +300,7 @@ static void stm32_i2c_tracenew(FAR struct stm32_i2c_priv_s *priv, uint32_t statu static void stm32_i2c_traceevent(FAR struct stm32_i2c_priv_s *priv, enum stm32_trace_e event, uint32_t parm); static void stm32_i2c_tracedump(FAR struct stm32_i2c_priv_s *priv); -#endif +#endif /* CONFIG_I2C_TRACE */ static void stm32_i2c_setclock(FAR struct stm32_i2c_priv_s *priv, uint32_t frequency); static inline void stm32_i2c_sendstart(FAR struct stm32_i2c_priv_s *priv); @@ -291,7 +310,7 @@ static inline uint32_t stm32_i2c_getstatus(FAR struct stm32_i2c_priv_s *priv); #ifdef I2C1_FSMC_CONFLICT static inline uint32_t stm32_i2c_disablefsmc(FAR struct stm32_i2c_priv_s *priv); static inline void stm32_i2c_enablefsmc(uint32_t ahbenr); -#endif +#endif /* I2C1_FSMC_CONFLICT */ static int stm32_i2c_isr(struct stm32_i2c_priv_s * priv); #ifndef CONFIG_I2C_POLLED #ifdef CONFIG_STM32_I2C1 @@ -329,27 +348,18 @@ static int stm32_i2c_transfer(FAR struct i2c_dev_s *dev, FAR struct i2c_msg_s *m ************************************************************************************/ #ifdef CONFIG_STM32_I2C1 -# ifndef GPIO_I2C1_SCL_GPIO -# define GPIO_I2C1_SCL_GPIO 0 -# endif -# ifndef GPIO_I2C1_SDA_GPIO -# define GPIO_I2C1_SDA_GPIO 0 -# endif - static const struct stm32_i2c_config_s stm32_i2c1_config = { .base = STM32_I2C1_BASE, -#ifndef CONFIG_I2C_POLLED - .isr = stm32_i2c1_isr, -#endif .clk_bit = RCC_APB1ENR_I2C1EN, .reset_bit = RCC_APB1RSTR_I2C1RST, .scl_pin = GPIO_I2C1_SCL, - .scl_gpio = GPIO_I2C1_SCL_GPIO, .sda_pin = GPIO_I2C1_SDA, - .sda_gpio = GPIO_I2C1_SDA_GPIO, +#ifndef CONFIG_I2C_POLLED + .isr = stm32_i2c1_isr, .ev_irq = STM32_IRQ_I2C1EV, .er_irq = STM32_IRQ_I2C1ER +#endif }; struct stm32_i2c_priv_s stm32_i2c1_priv = @@ -367,27 +377,18 @@ struct stm32_i2c_priv_s stm32_i2c1_priv = #endif #ifdef CONFIG_STM32_I2C2 -# ifndef GPIO_I2C2_SCL_GPIO -# define GPIO_I2C2_SCL_GPIO 0 -# endif -# ifndef GPIO_I2C2_SDA_GPIO -# define GPIO_I2C2_SDA_GPIO 0 -# endif - static const struct stm32_i2c_config_s stm32_i2c2_config = { .base = STM32_I2C2_BASE, -#ifndef CONFIG_I2C_POLLED - .isr = stm32_i2c2_isr, -#endif .clk_bit = RCC_APB1ENR_I2C2EN, .reset_bit = RCC_APB1RSTR_I2C2RST, .scl_pin = GPIO_I2C2_SCL, - .scl_gpio = GPIO_I2C2_SCL_GPIO, .sda_pin = GPIO_I2C2_SDA, - .sda_gpio = GPIO_I2C2_SDA_GPIO, +#ifndef CONFIG_I2C_POLLED + .isr = stm32_i2c2_isr, .ev_irq = STM32_IRQ_I2C2EV, .er_irq = STM32_IRQ_I2C2ER +#endif }; struct stm32_i2c_priv_s stm32_i2c2_priv = @@ -405,27 +406,18 @@ struct stm32_i2c_priv_s stm32_i2c2_priv = #endif #ifdef CONFIG_STM32_I2C3 -# ifndef GPIO_I2C3_SCL_GPIO -# define GPIO_I2C3_SCL_GPIO 0 -# endif -# ifndef GPIO_I2C3_SDA_GPIO -# define GPIO_I2C3_SDA_GPIO 0 -# endif - static const struct stm32_i2c_config_s stm32_i2c3_config = { .base = STM32_I2C3_BASE, -#ifndef CONFIG_I2C_POLLED - .isr = stm32_i2c3_isr, -#endif .clk_bit = RCC_APB1ENR_I2C3EN, .reset_bit = RCC_APB1RSTR_I2C3RST, .scl_pin = GPIO_I2C3_SCL, - .scl_gpio = GPIO_I2C3_SCL_GPIO, .sda_pin = GPIO_I2C3_SDA, - .sda_gpio = GPIO_I2C3_SDA_GPIO, +#ifndef CONFIG_I2C_POLLED + .isr = stm32_i2c3_isr, .ev_irq = STM32_IRQ_I2C3EV, .er_irq = STM32_IRQ_I2C3ER +#endif }; struct stm32_i2c_priv_s stm32_i2c3_priv = @@ -525,6 +517,35 @@ static inline void stm32_i2c_sem_wait(FAR struct i2c_dev_s *dev) } } +/************************************************************************************ + * Name: stm32_i2c_tousecs + * + * Description: + * Return a micro-second delay based on the number of bytes left to be processed. + * + ************************************************************************************/ + +#ifdef CONFIG_STM32_I2C_DYNTIMEO +static useconds_t stm32_i2c_tousecs(int msgc, FAR struct i2c_msg_s *msgs) +{ + size_t bytecount = 0; + int i; + + /* Count the number of bytes left to process */ + + for (i = 0; i < msgc; i++) + { + bytecount += msgs[i].length; + } + + /* Then return a number of microseconds based on a user provided scaling + * factor. + */ + + return (useconds_t)(CONFIG_STM32_I2C_DYNTIMEO_USECPERBYTE * bytecount); +} +#endif + /************************************************************************************ * Name: stm32_i2c_sem_waitdone * @@ -534,7 +555,7 @@ static inline void stm32_i2c_sem_wait(FAR struct i2c_dev_s *dev) ************************************************************************************/ #ifndef CONFIG_I2C_POLLED -static inline int stm32_i2c_sem_waitdone(FAR struct stm32_i2c_priv_s *priv, int timeout_us) +static inline int stm32_i2c_sem_waitdone(FAR struct stm32_i2c_priv_s *priv) { struct timespec abstime; irqstate_t flags; @@ -566,31 +587,24 @@ static inline int stm32_i2c_sem_waitdone(FAR struct stm32_i2c_priv_s *priv, int #if CONFIG_STM32_I2CTIMEOSEC > 0 abstime.tv_sec += CONFIG_STM32_I2CTIMEOSEC; #endif -#if CONFIG_STM32_I2CTIMEOUS_PER_BYTE > 0 - /* Count the number of bytes left to process */ - int i; - int bytecount = 0; - for (i = 0; i < priv->msgc; i++) + /* Add a value proportional to the number of bytes in the transfer */ + +#ifdef CONFIG_STM32_I2C_DYNTIMEO + abstime.tv_nsec += 1000 * stm32_i2c_tousecs(priv->msgc, priv->msgv); + if (abstime.tv_nsec > 1000 * 1000 * 1000) { - bytecount += priv->msgv[i].length; + abstime.tv_sec++; + abstime.tv_nsec -= 1000 * 1000 * 1000; } - abstime.tv_nsec += (CONFIG_STM32_I2CTIMEOUS_PER_BYTE * bytecount) * 1000; +#elif CONFIG_STM32_I2CTIMEOMS > 0 + abstime.tv_nsec += CONFIG_STM32_I2CTIMEOMS * 1000 * 1000; if (abstime.tv_nsec > 1000 * 1000 * 1000) { abstime.tv_sec++; abstime.tv_nsec -= 1000 * 1000 * 1000; } -#else - #if CONFIG_STM32_I2CTIMEOMS > 0 - abstime.tv_nsec += CONFIG_STM32_I2CTIMEOMS * 1000 * 1000; - if (abstime.tv_nsec > 1000 * 1000 * 1000) - { - abstime.tv_sec++; - abstime.tv_nsec -= 1000 * 1000 * 1000; - } - #endif #endif /* Wait until either the transfer is complete or the timeout expires */ @@ -624,12 +638,21 @@ static inline int stm32_i2c_sem_waitdone(FAR struct stm32_i2c_priv_s *priv, int return ret; } #else -static inline int stm32_i2c_sem_waitdone(FAR struct stm32_i2c_priv_s *priv, int timeout_us) +static inline int stm32_i2c_sem_waitdone(FAR struct stm32_i2c_priv_s *priv) { + uint32_t timeout; uint32_t start; uint32_t elapsed; int ret; + /* Get the timeout value */ + +#ifdef CONFIG_STM32_I2C_DYNTIMEO + timeout = USEC2TICK(stm32_i2c_tousecs(priv->msgc, priv->msgv)); +#else + timeout = CONFIG_STM32_I2CTIMEOTICKS; +#endif + /* Signal the interrupt handler that we are waiting. NOTE: Interrupts * are currently disabled but will be temporarily re-enabled below when * sem_timedwait() sleeps. @@ -652,10 +675,11 @@ static inline int stm32_i2c_sem_waitdone(FAR struct stm32_i2c_priv_s *priv, int } /* Loop until the transfer is complete. */ - while (priv->intstate != INTSTATE_DONE && elapsed < USEC2TICK(timeout_us)); + + while (priv->intstate != INTSTATE_DONE && elapsed < timeout); i2cvdbg("intstate: %d elapsed: %d threshold: %d status: %08x\n", - priv->intstate, elapsed, USEC2TICK(timeout_us), priv->status); + priv->intstate, elapsed, timeout, priv->status); /* Set the interrupt state back to IDLE */ @@ -673,13 +697,22 @@ static inline int stm32_i2c_sem_waitdone(FAR struct stm32_i2c_priv_s *priv, int * ************************************************************************************/ -static inline void stm32_i2c_sem_waitstop(FAR struct stm32_i2c_priv_s *priv, int timeout_us) +static inline void stm32_i2c_sem_waitstop(FAR struct stm32_i2c_priv_s *priv) { uint32_t start; uint32_t elapsed; + uint32_t timeout; uint32_t cr1; uint32_t sr1; + /* Select a timeout */ + +#ifdef CONFIG_STM32_I2C_DYNTIMEO + timeout = USEC2TICK(CONFIG_STM32_I2C_DYNTIMEO_STARTSTOP); +#else + timeout = CONFIG_STM32_I2CTIMEOTICKS; +#endif + /* Wait as stop might still be in progress; but stop might also * be set because of a timeout error: "The [STOP] bit is set and * cleared by software, cleared by hardware when a Stop condition is @@ -712,7 +745,7 @@ static inline void stm32_i2c_sem_waitstop(FAR struct stm32_i2c_priv_s *priv, int /* Loop until the stop is complete or a timeout occurs. */ - while (elapsed < USEC2TICK(timeout_us)); + while (elapsed < timeout); /* If we get here then a timeout occurred with the STOP condition * still pending. @@ -932,7 +965,7 @@ static void stm32_i2c_setclock(FAR struct stm32_i2c_priv_s *priv, uint32_t frequ { /* Fast mode speed calculation with Tlow/Thigh = 16/9 */ -#ifdef CONFIG_I2C_DUTY16_9 +#ifdef CONFIG_STM32_I2C_DUTY16_9 speed = (uint16_t)(STM32_PCLK1_FREQUENCY / (frequency * 25)); /* Set DUTY and fast speed bits */ @@ -1071,7 +1104,7 @@ static inline uint32_t stm32_i2c_disablefsmc(FAR struct stm32_i2c_priv_s *priv) /* Is this I2C1 */ -#ifdef CONFIG_STM32_I2C2 +#if defined(CONFIG_STM32_I2C2) || defined(CONFIG_STM32_I2C3) if (priv->config->base == STM32_I2C1_BASE) #endif { @@ -1198,10 +1231,14 @@ static int stm32_i2c_isr(struct stm32_i2c_priv_s *priv) { stm32_i2c_traceevent(priv, I2CEVENT_RCVBYTE, priv->dcnt); + /* No interrupts or context switches may occur in the following + * sequence. Otherwise, additional bytes may be sent by the + * device. + */ + #ifdef CONFIG_I2C_POLLED irqstate_t state = irqsave(); #endif - /* Receive a byte */ *priv->ptr++ = stm32_i2c_getreg(priv, STM32_I2C_DR_OFFSET); @@ -1217,7 +1254,6 @@ static int stm32_i2c_isr(struct stm32_i2c_priv_s *priv) #ifdef CONFIG_I2C_POLLED irqrestore(state); #endif - } } @@ -1408,7 +1444,6 @@ static int stm32_i2c_init(FAR struct stm32_i2c_priv_s *priv) /* Enable power and reset the peripheral */ modifyreg32(STM32_RCC_APB1ENR, 0, priv->config->clk_bit); - modifyreg32(STM32_RCC_APB1RSTR, 0, priv->config->reset_bit); modifyreg32(STM32_RCC_APB1RSTR, priv->config->reset_bit, 0); @@ -1428,10 +1463,10 @@ static int stm32_i2c_init(FAR struct stm32_i2c_priv_s *priv) /* Attach ISRs */ #ifndef CONFIG_I2C_POLLED - irq_attach(priv->config->ev_irq, priv->config->isr); - irq_attach(priv->config->er_irq, priv->config->isr); - up_enable_irq(priv->config->ev_irq); - up_enable_irq(priv->config->er_irq); + irq_attach(priv->config->ev_irq, priv->config->isr); + irq_attach(priv->config->er_irq, priv->config->isr); + up_enable_irq(priv->config->ev_irq); + up_enable_irq(priv->config->er_irq); #endif /* Set peripheral frequency, where it must be at least 2 MHz for 100 kHz @@ -1461,17 +1496,23 @@ static int stm32_i2c_deinit(FAR struct stm32_i2c_priv_s *priv) stm32_i2c_putreg(priv, STM32_I2C_CR1_OFFSET, 0); + /* Unconfigure GPIO pins */ + stm32_unconfiggpio(priv->config->scl_pin); stm32_unconfiggpio(priv->config->sda_pin); + /* Disable and detach interrupts */ + #ifndef CONFIG_I2C_POLLED up_disable_irq(priv->config->ev_irq); up_disable_irq(priv->config->er_irq); irq_detach(priv->config->ev_irq); irq_detach(priv->config->er_irq); #endif - modifyreg32(STM32_RCC_APB1ENR, priv->config->clk_bit, 0); + /* Disable clocking */ + + modifyreg32(STM32_RCC_APB1ENR, priv->config->clk_bit, 0); return OK; } @@ -1533,14 +1574,14 @@ static int stm32_i2c_process(FAR struct i2c_dev_s *dev, FAR struct i2c_msg_s *ms struct stm32_i2c_inst_s *inst = (struct stm32_i2c_inst_s *)dev; FAR struct stm32_i2c_priv_s *priv = inst->priv; uint32_t status = 0; - //uint32_t ahbenr; + uint32_t ahbenr; int errval = 0; ASSERT(count); /* Disable FSMC that shares a pin with I2C1 (LBAR) */ - (void)stm32_i2c_disablefsmc(priv); + ahbenr = stm32_i2c_disablefsmc(priv); /* Wait for any STOP in progress. NOTE: If we have to disable the FSMC * then we cannot do this at the top of the loop, unfortunately. The STOP @@ -1548,11 +1589,7 @@ static int stm32_i2c_process(FAR struct i2c_dev_s *dev, FAR struct i2c_msg_s *ms */ #ifndef I2C1_FSMC_CONFLICT - #if CONFIG_STM32_I2CTIMEOUS_START_STOP > 0 - stm32_i2c_sem_waitstop(priv, CONFIG_STM32_I2CTIMEOUS_START_STOP); - #else - stm32_i2c_sem_waitstop(priv, CONFIG_STM32_I2CTIMEOMS + CONFIG_STM32_I2CTIMEOSEC * 1000000); - #endif + stm32_i2c_sem_waitstop(priv); #endif /* Clear any pending error interrupts */ @@ -1573,22 +1610,6 @@ static int stm32_i2c_process(FAR struct i2c_dev_s *dev, FAR struct i2c_msg_s *ms priv->msgv = msgs; priv->msgc = count; - /* Calculate timeout values */ - int timeout_us = 0; - #if CONFIG_STM32_I2CTIMEOUS_PER_BYTE > 0 - /* Count the number of bytes left to process */ - int i; - int bytecount = 10; - for (i = 0; i < count; i++) - { - bytecount += msgs[i].length; - } - timeout_us = CONFIG_STM32_I2CTIMEOUS_PER_BYTE * bytecount; - //i2cvdbg("i2c wait: %d\n", timeout_us); - #else - timeout_us = CONFIG_STM32_I2CTIMEOMS + CONFIG_STM32_I2CTIMEOSEC * 1000000; - #endif - /* Reset I2C trace logic */ stm32_i2c_tracereset(priv); @@ -1608,7 +1629,7 @@ static int stm32_i2c_process(FAR struct i2c_dev_s *dev, FAR struct i2c_msg_s *ms * the BUSY flag. */ - if (stm32_i2c_sem_waitdone(priv, timeout_us) < 0) + if (stm32_i2c_sem_waitdone(priv) < 0) { status = stm32_i2c_getstatus(priv); errval = ETIMEDOUT; @@ -1623,7 +1644,9 @@ static int stm32_i2c_process(FAR struct i2c_dev_s *dev, FAR struct i2c_msg_s *ms */ stm32_i2c_clrstart(priv); - // XXX also clear busy flag in case of timeout + + /* Clear busy flag in case of timeout */ + status = priv->status & 0xffff; } else @@ -1953,11 +1976,14 @@ int up_i2cuninitialize(FAR struct i2c_dev_s * dev) * ************************************************************************************/ +#ifdef CONFIG_I2C_RESET int up_i2creset(FAR struct i2c_dev_s * dev) { struct stm32_i2c_priv_s * priv; - unsigned clock_count; - unsigned stretch_count; + unsigned int clock_count; + unsigned int stretch_count; + unit32_ scl_gpio; + unit32_ sda_gpio; int ret = ERROR; irqstate_t state; @@ -1979,83 +2005,70 @@ int up_i2creset(FAR struct i2c_dev_s * dev) stm32_i2c_deinit(priv); - /* If possible, use GPIO configuration to un-wedge the bus */ + /* Use GPIO configuration to un-wedge the bus */ - if ((priv->config->scl_gpio != 0) && (priv->config->sda_gpio != 0)) + scl_gpio = MKI2C_OUTPUT(priv->config->scl_pin); + sda_gpio = MKI2C_OUTPUT(priv->config->sda_pin); + + /* Clock the bus until any slaves currently driving it let it go. */ + + clock_count = 0; + while (!stm32_gpioread(sda_gpio)) { - stm32_configgpio(priv->config->scl_gpio); - stm32_configgpio(priv->config->sda_gpio); + /* Give up if we have tried too hard */ - /* - * Clock the bus until any slaves currently driving it let it go. - */ + if (clock_count++ > 1000) + { + goto out; + } - clock_count = 0; - while (!stm32_gpioread(priv->config->sda_gpio)) - { + /* Sniff to make sure that clock stretching has finished. + * + * If the bus never relaxes, the reset has failed. + */ + stretch_count = 0; + while (!stm32_gpioread(scl_gpio)) + { /* Give up if we have tried too hard */ - if (clock_count++ > 1000) + if (stretch_count++ > 1000) { goto out; } - /* - * Sniff to make sure that clock stretching has finished. - * - * If the bus never relaxes, the reset has failed. - */ - - stretch_count = 0; - while (!stm32_gpioread(priv->config->scl_gpio)) - { - - /* Give up if we have tried too hard */ - - if (stretch_count++ > 1000) - { - goto out; - } - - up_udelay(10); - - } - - /* Drive SCL low */ - - stm32_gpiowrite(priv->config->scl_gpio, 0); - up_udelay(10); - - /* Drive SCL high again */ - - stm32_gpiowrite(priv->config->scl_gpio, 1); - up_udelay(10); - + up_udelay(10); } - /* - * Generate a start followed by a stop to reset slave - * state machines. - */ + /* Drive SCL low */ - stm32_gpiowrite(priv->config->sda_gpio, 0); - up_udelay(10); - stm32_gpiowrite(priv->config->scl_gpio, 0); - up_udelay(10); - stm32_gpiowrite(priv->config->scl_gpio, 1); - up_udelay(10); - stm32_gpiowrite(priv->config->sda_gpio, 1); + stm32_gpiowrite(scl_gpio, 0); up_udelay(10); - /* - * Revert the GPIO configuration. - */ - stm32_unconfiggpio(priv->config->sda_gpio); - stm32_unconfiggpio(priv->config->scl_gpio); + /* Drive SCL high again */ + stm32_gpiowrite(scl_gpio, 1); + up_udelay(10); } + /* Generate a start followed by a stop to reset slave + * state machines. + */ + + stm32_gpiowrite(sda_gpio, 0); + up_udelay(10); + stm32_gpiowrite(scl_gpio, 0); + up_udelay(10); + stm32_gpiowrite(scl_gpio, 1); + up_udelay(10); + stm32_gpiowrite(sda_gpio, 1); + up_udelay(10); + + /* Revert the GPIO configuration. */ + + stm32_unconfiggpio(sda_gpio); + stm32_unconfiggpio(scl_gpio); + /* Re-init the port */ stm32_i2c_init(priv); @@ -2063,11 +2076,11 @@ int up_i2creset(FAR struct i2c_dev_s * dev) out: - /* release the port for re-use by other clients */ + /* Release the port for re-use by other clients */ stm32_i2c_sem_post(dev); - return ret; } +#endif /* CONFIG_I2C_RESET */ -#endif /* defined(CONFIG_STM32_I2C1) || defined(CONFIG_STM32_I2C2) || defined(CONFIG_STM32_I2C3) */ +#endif /* CONFIG_STM32_I2C1 || CONFIG_STM32_I2C2 || CONFIG_STM32_I2C3 */ diff --git a/nuttx/arch/arm/src/stm32/stm32_lowputc.c b/nuttx/arch/arm/src/stm32/stm32_lowputc.c index 7f7205672..6cb07dad9 100644 --- a/nuttx/arch/arm/src/stm32/stm32_lowputc.c +++ b/nuttx/arch/arm/src/stm32/stm32_lowputc.c @@ -67,6 +67,14 @@ # define STM32_CONSOLE_2STOP CONFIG_USART1_2STOP # define STM32_CONSOLE_TX GPIO_USART1_TX # define STM32_CONSOLE_RX GPIO_USART1_RX +# ifdef CONFIG_USART1_RS485 +# define STM32_CONSOLE_RS485_DIR GPIO_USART1_RS485_DIR +# if (CONFIG_USART1_RS485_DIR_POLARITY == 0) +# define STM32_CONSOLE_RS485_DIR_POLARITY false +# else +# define STM32_CONSOLE_RS485_DIR_POLARITY true +# endif +# endif #elif defined(CONFIG_USART2_SERIAL_CONSOLE) # define STM32_CONSOLE_BASE STM32_USART2_BASE # define STM32_APBCLOCK STM32_PCLK1_FREQUENCY @@ -76,6 +84,14 @@ # define STM32_CONSOLE_2STOP CONFIG_USART2_2STOP # define STM32_CONSOLE_TX GPIO_USART2_TX # define STM32_CONSOLE_RX GPIO_USART2_RX +# ifdef CONFIG_USART2_RS485 +# define STM32_CONSOLE_RS485_DIR GPIO_USART2_RS485_DIR +# if (CONFIG_USART2_RS485_DIR_POLARITY == 0) +# define STM32_CONSOLE_RS485_DIR_POLARITY false +# else +# define STM32_CONSOLE_RS485_DIR_POLARITY true +# endif +# endif #elif defined(CONFIG_USART3_SERIAL_CONSOLE) # define STM32_CONSOLE_BASE STM32_USART3_BASE # define STM32_APBCLOCK STM32_PCLK1_FREQUENCY @@ -85,6 +101,14 @@ # define STM32_CONSOLE_2STOP CONFIG_USART3_2STOP # define STM32_CONSOLE_TX GPIO_USART3_TX # define STM32_CONSOLE_RX GPIO_USART3_RX +# ifdef CONFIG_USART3_RS485 +# define STM32_CONSOLE_RS485_DIR GPIO_USART3_RS485_DIR +# if (CONFIG_USART3_RS485_DIR_POLARITY == 0) +# define STM32_CONSOLE_RS485_DIR_POLARITY false +# else +# define STM32_CONSOLE_RS485_DIR_POLARITY true +# endif +# endif #elif defined(CONFIG_UART4_SERIAL_CONSOLE) # define STM32_CONSOLE_BASE STM32_UART4_BASE # define STM32_APBCLOCK STM32_PCLK1_FREQUENCY @@ -94,6 +118,14 @@ # define STM32_CONSOLE_2STOP CONFIG_UART4_2STOP # define STM32_CONSOLE_TX GPIO_UART4_TX # define STM32_CONSOLE_RX GPIO_UART4_RX +# ifdef CONFIG_UART4_RS485 +# define STM32_CONSOLE_RS485_DIR GPIO_UART4_RS485_DIR +# if (CONFIG_UART4_RS485_DIR_POLARITY == 0) +# define STM32_CONSOLE_RS485_DIR_POLARITY false +# else +# define STM32_CONSOLE_RS485_DIR_POLARITY true +# endif +# endif #elif defined(CONFIG_UART5_SERIAL_CONSOLE) # define STM32_CONSOLE_BASE STM32_UART5_BASE # define STM32_APBCLOCK STM32_PCLK1_FREQUENCY @@ -103,6 +135,14 @@ # define STM32_CONSOLE_2STOP CONFIG_UART5_2STOP # define STM32_CONSOLE_TX GPIO_UART5_TX # define STM32_CONSOLE_RX GPIO_UART5_RX +# ifdef CONFIG_UART5_RS485 +# define STM32_CONSOLE_RS485_DIR GPIO_UART5_RS485_DIR +# if (CONFIG_UART5_RS485_DIR_POLARITY == 0) +# define STM32_CONSOLE_RS485_DIR_POLARITY false +# else +# define STM32_CONSOLE_RS485_DIR_POLARITY true +# endif +# endif #elif defined(CONFIG_USART6_SERIAL_CONSOLE) # define STM32_CONSOLE_BASE STM32_USART6_BASE # define STM32_APBCLOCK STM32_PCLK2_FREQUENCY @@ -112,6 +152,14 @@ # define STM32_CONSOLE_2STOP CONFIG_USART6_2STOP # define STM32_CONSOLE_TX GPIO_USART6_TX # define STM32_CONSOLE_RX GPIO_USART6_RX +# ifdef CONFIG_USART6_RS485 +# define STM32_CONSOLE_RS485_DIR GPIO_USART6_RS485_DIR +# if (CONFIG_USART6_RS485_DIR_POLARITY == 0) +# define STM32_CONSOLE_RS485_DIR_POLARITY false +# else +# define STM32_CONSOLE_RS485_DIR_POLARITY true +# endif +# endif #endif /* CR1 settings */ @@ -230,10 +278,19 @@ void up_lowputc(char ch) /* Wait until the TX data register is empty */ while ((getreg32(STM32_CONSOLE_BASE + STM32_USART_SR_OFFSET) & USART_SR_TXE) == 0); +#if STM32_CONSOLE_RS485_DIR + stm32_gpiowrite(STM32_CONSOLE_RS485_DIR, STM32_CONSOLE_RS485_DIR_POLARITY); +#endif /* Then send the character */ putreg32((uint32_t)ch, STM32_CONSOLE_BASE + STM32_USART_DR_OFFSET); + +#if STM32_CONSOLE_RS485_DIR + while ((getreg32(STM32_CONSOLE_BASE + STM32_USART_SR_OFFSET) & USART_SR_TC) == 0); + stm32_gpiowrite(STM32_CONSOLE_RS485_DIR, !STM32_CONSOLE_RS485_DIR_POLARITY); +#endif + #endif } @@ -328,7 +385,14 @@ void stm32_lowsetup(void) #ifdef STM32_CONSOLE_TX stm32_configgpio(STM32_CONSOLE_TX); - stm32_configgpio(STM32_CONSOLE_TX); +#endif +#ifdef STM32_CONSOLE_RX + stm32_configgpio(STM32_CONSOLE_RX); +#endif + +#if STM32_CONSOLE_RS485_DIR + stm32_configgpio(STM32_CONSOLE_RS485_DIR); + stm32_gpiowrite(STM32_CONSOLE_RS485_DIR, !STM32_CONSOLE_RS485_DIR_POLARITY); #endif /* Enable and configure the selected console device */ @@ -382,7 +446,14 @@ void stm32_lowsetup(void) #ifdef STM32_CONSOLE_TX stm32_configgpio(STM32_CONSOLE_TX); - stm32_configgpio(STM32_CONSOLE_TX); +#endif +#ifdef STM32_CONSOLE_RX + stm32_configgpio(STM32_CONSOLE_RX); +#endif + +#if STM32_CONSOLE_RS485_DIR + stm32_configgpio(STM32_CONSOLE_RS485_DIR); + stm32_gpiowrite(STM32_CONSOLE_RS485_DIR, !STM32_CONSOLE_RS485_DIR_POLARITY); #endif /* Enable and configure the selected console device */ diff --git a/nuttx/arch/arm/src/stm32/stm32_otgfsdev.c b/nuttx/arch/arm/src/stm32/stm32_otgfsdev.c index 461d500ad..94772b693 100644 --- a/nuttx/arch/arm/src/stm32/stm32_otgfsdev.c +++ b/nuttx/arch/arm/src/stm32/stm32_otgfsdev.c @@ -3651,10 +3651,14 @@ static int stm32_epout_configure(FAR struct stm32_ep_s *privep, uint8_t eptype, regval = stm32_getreg(regaddr); if ((regval & OTGFS_DOEPCTL_USBAEP) == 0) { - regval &= ~(OTGFS_DOEPCTL_MPSIZ_MASK | OTGFS_DIEPCTL_EPTYP_MASK | OTGFS_DIEPCTL_TXFNUM_MASK); + if (regval & OTGFS_DOEPCTL_NAKSTS) + { + regval |= OTGFS_DOEPCTL_CNAK; + } + + regval &= ~(OTGFS_DOEPCTL_MPSIZ_MASK | OTGFS_DOEPCTL_EPTYP_MASK); regval |= mpsiz; regval |= (eptype << OTGFS_DOEPCTL_EPTYP_SHIFT); - regval |= (eptype << OTGFS_DIEPCTL_TXFNUM_SHIFT); regval |= (OTGFS_DOEPCTL_SD0PID | OTGFS_DOEPCTL_USBAEP); stm32_putreg(regval, regaddr); @@ -3743,6 +3747,11 @@ static int stm32_epin_configure(FAR struct stm32_ep_s *privep, uint8_t eptype, regval = stm32_getreg(regaddr); if ((regval & OTGFS_DIEPCTL_USBAEP) == 0) { + if (regval & OTGFS_DIEPCTL_NAKSTS) + { + regval |= OTGFS_DIEPCTL_CNAK; + } + regval &= ~(OTGFS_DIEPCTL_MPSIZ_MASK | OTGFS_DIEPCTL_EPTYP_MASK | OTGFS_DIEPCTL_TXFNUM_MASK); regval |= mpsiz; regval |= (eptype << OTGFS_DIEPCTL_EPTYP_SHIFT); @@ -3900,7 +3909,7 @@ static void stm32_epout_disable(FAR struct stm32_ep_s *privep) * Name: stm32_epin_disable * * Description: - * Diable an IN endpoint will no longer be used + * Disable an IN endpoint when it will no longer be used * *******************************************************************************/ @@ -3912,6 +3921,17 @@ static void stm32_epin_disable(FAR struct stm32_ep_s *privep) usbtrace(TRACE_EPDISABLE, privep->epphy); + /* After USB reset, the endpoint will already be deactivated by the + * hardware. Trying to disable again will just hang in the wait. + */ + + regaddr = STM32_OTGFS_DIEPCTL(privep->epphy); + regval = stm32_getreg(regaddr); + if ((regval & OTGFS_DIEPCTL_USBAEP) == 0) + { + return; + } + /* Make sure that there is no pending IPEPNE interrupt (because we are * to poll this bit below). */ diff --git a/nuttx/arch/arm/src/stm32/stm32_qencoder.c b/nuttx/arch/arm/src/stm32/stm32_qencoder.c index 8553296f9..d37614c03 100644 --- a/nuttx/arch/arm/src/stm32/stm32_qencoder.c +++ b/nuttx/arch/arm/src/stm32/stm32_qencoder.c @@ -607,6 +607,7 @@ static FAR struct stm32_lowerhalf_s *stm32_tim2lower(int tim) #endif #ifdef CONFIG_STM32_TIM3_QE case 3: + return &g_tim3lower; #endif #ifdef CONFIG_STM32_TIM4_QE case 4: diff --git a/nuttx/arch/arm/src/stm32/stm32_serial.c b/nuttx/arch/arm/src/stm32/stm32_serial.c index c7f97b25a..aa46a8987 100644 --- a/nuttx/arch/arm/src/stm32/stm32_serial.c +++ b/nuttx/arch/arm/src/stm32/stm32_serial.c @@ -198,11 +198,15 @@ struct up_dev_s uint8_t parity; /* 0=none, 1=odd, 2=even */ uint8_t bits; /* Number of bits (7 or 8) */ bool stopbits2; /* True: Configure with 2 stop bits instead of 1 */ + bool iflow; /* input flow control (RTS) enabled */ + bool oflow; /* output flow control (CTS) enabled */ uint32_t baud; /* Configured baud */ #else const uint8_t parity; /* 0=none, 1=odd, 2=even */ const uint8_t bits; /* Number of bits (7 or 8) */ const bool stopbits2; /* True: Configure with 2 stop bits instead of 1 */ + const bool iflow; /* input flow control (RTS) enabled */ + const bool oflow; /* output flow control (CTS) enabled */ const uint32_t baud; /* Configured baud */ #endif @@ -239,7 +243,7 @@ struct up_dev_s * Private Function Prototypes ****************************************************************************/ -static void up_setspeed(struct uart_dev_s *dev); +static void up_set_format(struct uart_dev_s *dev); static int up_setup(struct uart_dev_s *dev); static void up_shutdown(struct uart_dev_s *dev); static int up_attach(struct uart_dev_s *dev); @@ -411,6 +415,8 @@ static struct up_dev_s g_usart1priv = .parity = CONFIG_USART1_PARITY, .bits = CONFIG_USART1_BITS, .stopbits2 = CONFIG_USART1_2STOP, + .iflow = false, + .oflow = false, .baud = CONFIG_USART1_BAUD, .apbclock = STM32_PCLK2_FREQUENCY, .usartbase = STM32_USART1_BASE, @@ -471,6 +477,8 @@ static struct up_dev_s g_usart2priv = .parity = CONFIG_USART2_PARITY, .bits = CONFIG_USART2_BITS, .stopbits2 = CONFIG_USART2_2STOP, + .iflow = false, + .oflow = false, .baud = CONFIG_USART2_BAUD, .apbclock = STM32_PCLK1_FREQUENCY, .usartbase = STM32_USART2_BASE, @@ -531,6 +539,8 @@ static struct up_dev_s g_usart3priv = .parity = CONFIG_USART3_PARITY, .bits = CONFIG_USART3_BITS, .stopbits2 = CONFIG_USART3_2STOP, + .iflow = false, + .oflow = false, .baud = CONFIG_USART3_BAUD, .apbclock = STM32_PCLK1_FREQUENCY, .usartbase = STM32_USART3_BASE, @@ -591,17 +601,15 @@ static struct up_dev_s g_uart4priv = .parity = CONFIG_UART4_PARITY, .bits = CONFIG_UART4_BITS, .stopbits2 = CONFIG_UART4_2STOP, + .iflow = false, + .oflow = false, .baud = CONFIG_UART4_BAUD, .apbclock = STM32_PCLK1_FREQUENCY, .usartbase = STM32_UART4_BASE, .tx_gpio = GPIO_UART4_TX, .rx_gpio = GPIO_UART4_RX, -#ifdef GPIO_UART4_CTS - .cts_gpio = GPIO_UART4_CTS, -#endif -#ifdef GPIO_UART4_RTS - .rts_gpio = GPIO_UART4_RTS, -#endif + .cts_gpio = 0, /* flow control not supported on this port */ + .rts_gpio = 0, /* flow control not supported on this port */ #ifdef CONFIG_UART4_RXDMA .rxdma_channel = DMAMAP_UART4_RX, .rxfifo = g_uart4rxfifo, @@ -651,17 +659,15 @@ static struct up_dev_s g_uart5priv = .parity = CONFIG_UART5_PARITY, .bits = CONFIG_UART5_BITS, .stopbits2 = CONFIG_UART5_2STOP, + .iflow = false, + .oflow = false, .baud = CONFIG_UART5_BAUD, .apbclock = STM32_PCLK1_FREQUENCY, .usartbase = STM32_UART5_BASE, .tx_gpio = GPIO_UART5_TX, .rx_gpio = GPIO_UART5_RX, -#ifdef GPIO_UART5_CTS - .cts_gpio = GPIO_UART5_CTS, -#endif -#ifdef GPIO_UART5_RTS - .rts_gpio = GPIO_UART5_RTS, -#endif + .cts_gpio = 0, /* flow control not supported on this port */ + .rts_gpio = 0, /* flow control not supported on this port */ #ifdef CONFIG_UART5_RXDMA .rxdma_channel = DMAMAP_UART5_RX, .rxfifo = g_uart5rxfifo, @@ -711,6 +717,8 @@ static struct up_dev_s g_usart6priv = .parity = CONFIG_USART6_PARITY, .bits = CONFIG_USART6_BITS, .stopbits2 = CONFIG_USART6_2STOP, + .iflow = false, + .oflow = false, .baud = CONFIG_USART6_BAUD, .apbclock = STM32_PCLK2_FREQUENCY, .usartbase = STM32_USART6_BASE, @@ -884,21 +892,22 @@ static int up_dma_nextrx(struct up_dev_s *priv) #endif /**************************************************************************** - * Name: up_setspeed + * Name: up_set_format * * Description: - * Set the serial line speed. + * Set the serial line format and speed. * ****************************************************************************/ #ifndef CONFIG_SUPPRESS_UART_CONFIG -static void up_setspeed(struct uart_dev_s *dev) +static void up_set_format(struct uart_dev_s *dev) { struct up_dev_s *priv = (struct up_dev_s*)dev->priv; uint32_t usartdiv32; uint32_t mantissa; uint32_t fraction; uint32_t brr; + uint32_t regval; /* Configure the USART Baud Rate. The baud rate for the receiver and * transmitter (Rx and Tx) are both set to the same value as programmed @@ -928,8 +937,52 @@ static void up_setspeed(struct uart_dev_s *dev) fraction = (usartdiv32 - (mantissa << 5) + 1) >> 1; brr |= fraction << USART_BRR_FRAC_SHIFT; up_serialout(priv, STM32_USART_BRR_OFFSET, brr); + + /* Configure parity mode */ + + regval = up_serialin(priv, STM32_USART_CR1_OFFSET); + regval &= ~(USART_CR1_PCE|USART_CR1_PS); + + if (priv->parity == 1) /* Odd parity */ + { + regval |= (USART_CR1_PCE|USART_CR1_PS); + } + else if (priv->parity == 2) /* Even parity */ + { + regval |= USART_CR1_PCE; + } + + up_serialout(priv, STM32_USART_CR1_OFFSET, regval); + + /* Configure STOP bits */ + + regval = up_serialin(priv, STM32_USART_CR2_OFFSET); + regval &= ~(USART_CR2_STOP_MASK); + + if (priv->stopbits2) + { + regval |= USART_CR2_STOP2; + } + up_serialout(priv, STM32_USART_CR2_OFFSET, regval); + + /* Configure hardware flow control */ + + regval = up_serialin(priv, STM32_USART_CR3_OFFSET); + regval &= ~(USART_CR3_CTSE|USART_CR3_RTSE); + + if (priv->iflow && (priv->rts_gpio != 0)) + { + regval |= USART_CR3_RTSE; + } + if (priv->oflow && (priv->cts_gpio != 0)) + { + regval |= USART_CR3_CTSE; + } + + up_serialout(priv, STM32_USART_CR3_OFFSET, regval); + } -#endif +#endif /* CONFIG_SUPPRESS_UART_CONFIG */ /**************************************************************************** * Name: up_setup @@ -974,43 +1027,28 @@ static int up_setup(struct uart_dev_s *dev) #endif /* Configure CR2 */ - /* Clear STOP, CLKEN, CPOL, CPHA, LBCL, and interrupt enable bits */ + /* Clear CLKEN, CPOL, CPHA, LBCL, and interrupt enable bits */ regval = up_serialin(priv, STM32_USART_CR2_OFFSET); - regval &= ~(USART_CR2_STOP_MASK|USART_CR2_CLKEN|USART_CR2_CPOL| + regval &= ~(USART_CR2_CLKEN|USART_CR2_CPOL| USART_CR2_CPHA|USART_CR2_LBCL|USART_CR2_LBDIE); - /* Configure STOP bits */ - - if (priv->stopbits2) - { - regval |= USART_CR2_STOP2; - } up_serialout(priv, STM32_USART_CR2_OFFSET, regval); /* Configure CR1 */ - /* Clear M, PCE, PS, TE, REm and all interrupt enable bits */ + /* Clear M, TE, REm and all interrupt enable bits */ regval = up_serialin(priv, STM32_USART_CR1_OFFSET); - regval &= ~(USART_CR1_M|USART_CR1_PCE|USART_CR1_PS|USART_CR1_TE| + regval &= ~(USART_CR1_M|USART_CR1_TE| USART_CR1_RE|USART_CR1_ALLINTS); - /* Configure word length and parity mode */ + /* Configure word length */ if (priv->bits == 9) /* Default: 1 start, 8 data, n stop */ { regval |= USART_CR1_M; /* 1 start, 9 data, n stop */ } - if (priv->parity == 1) /* Odd parity */ - { - regval |= (USART_CR1_PCE|USART_CR1_PS); - } - else if (priv->parity == 2) /* Even parity */ - { - regval |= USART_CR1_PCE; - } - up_serialout(priv, STM32_USART_CR1_OFFSET, regval); /* Configure CR3 */ @@ -1023,9 +1061,9 @@ static int up_setup(struct uart_dev_s *dev) up_serialout(priv, STM32_USART_CR3_OFFSET, regval); - /* Configure the USART Baud Rate. */ + /* Configure the USART line format and speed. */ - up_setspeed(dev); + up_set_format(dev); /* Enable Rx, Tx, and the USART */ @@ -1056,12 +1094,15 @@ static int up_dma_setup(struct uart_dev_s *dev) int result; uint32_t regval; - /* Do the basic UART setup first */ + /* Do the basic UART setup first, unless we are the console */ - result = up_setup(dev); - if (result != OK) - { - return result; + if (!dev->isconsole) + { + result = up_setup(dev); + if (result != OK) + { + return result; + } } /* Acquire the DMA channel. This should always succeed. */ @@ -1371,12 +1412,21 @@ static int up_ioctl(struct file *filep, int cmd, unsigned long arg) break; } - /* TODO: Other termios fields are not yet returned. - * Note that only cfsetospeed is not necessary because we have - * knowledge that only one speed is supported. + cfsetispeed(termiosp, priv->baud); + + /* Note that since we only support 8/9 bit modes and + * there is no way to report 9-bit mode, we always claim 8. */ - cfsetispeed(termiosp, priv->baud); + termiosp->c_cflag = + ((priv->parity != 0) ? PARENB : 0) | + ((priv->parity == 1) ? PARODD : 0) | + ((priv->stopbits2) ? CSTOPB : 0) | + ((priv->oflow) ? CCTS_OFLOW : 0) | + ((priv->iflow) ? CRTS_IFLOW : 0) | + CS8; + + /* TODO: CCTS_IFLOW, CCTS_OFLOW */ } break; @@ -1390,16 +1440,48 @@ static int up_ioctl(struct file *filep, int cmd, unsigned long arg) break; } - /* TODO: Handle other termios settings. - * Note that only cfgetispeed is used besued we have knowledge + /* Perform some sanity checks before accepting any changes */ + + if (((termiosp->c_cflag & CSIZE) != CS8) || + ((termiosp->c_cflag & CCTS_OFLOW) && (priv->cts_gpio == 0)) || + ((termiosp->c_cflag & CRTS_IFLOW) && (priv->rts_gpio == 0))) + { + ret = -EINVAL; + break; + } + + if (termiosp->c_cflag & PARENB) + { + priv->parity = (termiosp->c_cflag & PARODD) ? 1 : 2; + } + else + { + priv->parity = 0; + } + + priv->stopbits2 = (termiosp->c_cflag & CSTOPB) != 0; + priv->oflow = (termiosp->c_cflag & CCTS_OFLOW) != 0; + priv->iflow = (termiosp->c_cflag & CRTS_IFLOW) != 0; + + /* Note that since there is no way to request 9-bit mode + * and no way to support 5/6/7-bit modes, we ignore them + * all here. + */ + + /* Note that only cfgetispeed is used because we have knowledge * that only one speed is supported. */ priv->baud = cfgetispeed(termiosp); - up_setspeed(dev); + + /* effect the changes immediately - note that we do not implement + * TCSADRAIN / TCSAFLUSH + */ + + up_set_format(dev); } break; -#endif +#endif /* CONFIG_SERIAL_TERMIOS */ #ifdef CONFIG_USART_BREAKS case TIOCSBRK: /* BSD compatibility: Turn break on, unconditionally */ diff --git a/nuttx/arch/arm/src/stm32/stm32_uart.h b/nuttx/arch/arm/src/stm32/stm32_uart.h index a70923cbf..8ff6a9975 100644 --- a/nuttx/arch/arm/src/stm32/stm32_uart.h +++ b/nuttx/arch/arm/src/stm32/stm32_uart.h @@ -223,6 +223,20 @@ # undef SERIAL_HAVE_ONLY_DMA #endif +/* Is RS-485 used? */ + +#if defined(CONFIG_USART1_RS485) || defined(CONFIG_USART2_RS485) || \ + defined(CONFIG_USART3_RS485) || defined(CONFIG_UART4_RS485) || \ + defined(CONFIG_UART5_RS485) || defined(CONFIG_USART6_RS485) +# define HAVE_RS485 1 +#endif + +#ifdef HAVE_RS485 +# define USART_CR1_USED_INTS (USART_CR1_RXNEIE | USART_CR1_TXEIE | USART_CR1_PEIE | USART_CR1_TCIE) +#else +# define USART_CR1_USED_INTS (USART_CR1_RXNEIE | USART_CR1_TXEIE | USART_CR1_PEIE) +#endif + /************************************************************************************ * Public Types ************************************************************************************/ diff --git a/nuttx/arch/arm/src/stm32/stm32f10xxx_rcc.c b/nuttx/arch/arm/src/stm32/stm32f10xxx_rcc.c index 47ed5e016..ae3fa516e 100644 --- a/nuttx/arch/arm/src/stm32/stm32f10xxx_rcc.c +++ b/nuttx/arch/arm/src/stm32/stm32f10xxx_rcc.c @@ -92,7 +92,11 @@ static inline void rcc_reset(void) putreg32(regval, STM32_RCC_CR); regval = getreg32(STM32_RCC_CFGR); /* Reset PLLSRC, PLLXTPRE, PLLMUL and USBPRE bits */ - regval &= ~(RCC_CFGR_PLLSRC|RCC_CFGR_PLLXTPRE|RCC_CFGR_PLLMUL_MASK|RCC_CFGR_USBPRE); + regval &= ~(RCC_CFGR_PLLSRC|RCC_CFGR_PLLXTPRE|RCC_CFGR_PLLMUL_MASK +#ifndef CONFIG_STM32_VALUELINE + |RCC_CFGR_USBPRE +#endif + ); putreg32(regval, STM32_RCC_CFGR); putreg32(0, STM32_RCC_CIR); /* Disable all interrupts */ @@ -224,6 +228,27 @@ static inline void rcc_enableapb1(void) #endif #endif +#ifdef CONFIG_STM32_TIM12 + /* Timer 12 clock enable */ +#ifdef CONFIG_STM32_FORCEPOWER + regval |= RCC_APB1ENR_TIM12EN; +#endif +#endif + +#ifdef CONFIG_STM32_TIM13 + /* Timer 13 clock enable */ +#ifdef CONFIG_STM32_FORCEPOWER + regval |= RCC_APB1ENR_TIM13EN; +#endif +#endif + +#ifdef CONFIG_STM32_TIM14 + /* Timer 14 clock enable */ +#ifdef CONFIG_STM32_FORCEPOWER + regval |= RCC_APB1ENR_TIM14EN; +#endif +#endif + #ifdef CONFIG_STM32_WWDG /* Window Watchdog clock enable */ @@ -315,6 +340,13 @@ static inline void rcc_enableapb1(void) regval |= RCC_APB1ENR_DACEN; #endif + +#ifdef CONFIG_STM32_CEC + /* CEC clock enable */ + + regval |= RCC_APB1ENR_CECEN; +#endif + putreg32(regval, STM32_RCC_APB1ENR); } @@ -404,6 +436,28 @@ static inline void rcc_enableapb2(void) regval |= RCC_APB2ENR_ADC3EN; #endif + +#ifdef CONFIG_STM32_TIM15 + /* TIM15 Timer clock enable */ +#ifdef CONFIG_STM32_FORCEPOWER + regval |= RCC_APB2ENR_TIM15EN; +#endif +#endif + +#ifdef CONFIG_STM32_TIM16 + /* TIM16 Timer clock enable */ +#ifdef CONFIG_STM32_FORCEPOWER + regval |= RCC_APB2ENR_TIM16EN; +#endif +#endif + +#ifdef CONFIG_STM32_TIM17 + /* TIM17 Timer clock enable */ +#ifdef CONFIG_STM32_FORCEPOWER + regval |= RCC_APB2ENR_TIM17EN; +#endif +#endif + putreg32(regval, STM32_RCC_APB2ENR); } diff --git a/nuttx/binfmt/binfmt_exec.c b/nuttx/binfmt/binfmt_exec.c index c070324c3..60e8d8efd 100644 --- a/nuttx/binfmt/binfmt_exec.c +++ b/nuttx/binfmt/binfmt_exec.c @@ -44,7 +44,7 @@ #include #include -#include +#include #include "binfmt_internal.h" diff --git a/nuttx/binfmt/binfmt_globals.c b/nuttx/binfmt/binfmt_globals.c index 069d3a2aa..d3246bd50 100644 --- a/nuttx/binfmt/binfmt_globals.c +++ b/nuttx/binfmt/binfmt_globals.c @@ -39,7 +39,7 @@ #include -#include +#include #ifndef CONFIG_BINFMT_DISABLE diff --git a/nuttx/binfmt/binfmt_internal.h b/nuttx/binfmt/binfmt_internal.h index da67f5350..4fab9724d 100644 --- a/nuttx/binfmt/binfmt_internal.h +++ b/nuttx/binfmt/binfmt_internal.h @@ -42,7 +42,7 @@ #include -#include +#include /**************************************************************************** * Pre-processor Definitions diff --git a/nuttx/binfmt/binfmt_register.c b/nuttx/binfmt/binfmt_register.c index 7f6eef671..925f29353 100644 --- a/nuttx/binfmt/binfmt_register.c +++ b/nuttx/binfmt/binfmt_register.c @@ -44,7 +44,7 @@ #include #include -#include +#include #include "binfmt_internal.h" diff --git a/nuttx/binfmt/binfmt_unregister.c b/nuttx/binfmt/binfmt_unregister.c index b97b9b67d..f895e354d 100644 --- a/nuttx/binfmt/binfmt_unregister.c +++ b/nuttx/binfmt/binfmt_unregister.c @@ -44,7 +44,7 @@ #include #include -#include +#include #include "binfmt_internal.h" diff --git a/nuttx/binfmt/libnxflat/Kconfig b/nuttx/binfmt/libnxflat/Kconfig index ae2bf3130..fdb270cfb 100644 --- a/nuttx/binfmt/libnxflat/Kconfig +++ b/nuttx/binfmt/libnxflat/Kconfig @@ -2,3 +2,8 @@ # For a description of the syntax of this configuration file, # see misc/tools/kconfig-language.txt. # + +config NXFLAT_DUMPBUFFER + bool "Dump NXFLAT buffers" + default n + depends on DEBUG && DEBUG_VERBOSE diff --git a/nuttx/binfmt/libnxflat/libnxflat_init.c b/nuttx/binfmt/libnxflat/libnxflat_init.c index 5b6375ff1..b7cac8d86 100644 --- a/nuttx/binfmt/libnxflat/libnxflat_init.c +++ b/nuttx/binfmt/libnxflat/libnxflat_init.c @@ -48,7 +48,7 @@ #include #include -#include +#include /**************************************************************************** * Pre-Processor Definitions @@ -112,8 +112,9 @@ int nxflat_init(const char *filename, struct nxflat_loadinfo_s *loadinfo) loadinfo->filfd = open(filename, O_RDONLY); if (loadinfo->filfd < 0) { - bdbg("Failed to open NXFLAT binary %s: %d\n", filename, ret); - return -errno; + int errval = errno; + bdbg("Failed to open NXFLAT binary %s: %d\n", filename, errval); + return -errval; } /* Read the NXFLAT header from offset 0 */ diff --git a/nuttx/binfmt/libnxflat/libnxflat_read.c b/nuttx/binfmt/libnxflat/libnxflat_read.c index dbcd54279..8deeb0805 100644 --- a/nuttx/binfmt/libnxflat/libnxflat_read.c +++ b/nuttx/binfmt/libnxflat/libnxflat_read.c @@ -48,7 +48,7 @@ #include #include -#include +#include /**************************************************************************** * Pre-Processor Definitions @@ -129,8 +129,9 @@ int nxflat_read(struct nxflat_loadinfo_s *loadinfo, char *buffer, int readsize, rpos = lseek(loadinfo->filfd, offset, SEEK_SET); if (rpos != offset) { - bdbg("Failed to seek to position %d: %d\n", offset, errno); - return -errno; + int errval = errno; + bdbg("Failed to seek to position %d: %d\n", offset, errval); + return -errval; } /* Read the file data at offset into the user buffer */ @@ -138,10 +139,11 @@ int nxflat_read(struct nxflat_loadinfo_s *loadinfo, char *buffer, int readsize, nbytes = read(loadinfo->filfd, bufptr, bytesleft); if (nbytes < 0) { - if (errno != EINTR) + int errval = errno; + if (errval != EINTR) { - bdbg("Read of .data failed: %d\n", errno); - return -errno; + bdbg("Read of .data failed: %d\n", errval); + return -errval; } } else if (nbytes == 0) diff --git a/nuttx/binfmt/libnxflat/libnxflat_uninit.c b/nuttx/binfmt/libnxflat/libnxflat_uninit.c index 5d06296c7..b9715196b 100644 --- a/nuttx/binfmt/libnxflat/libnxflat_uninit.c +++ b/nuttx/binfmt/libnxflat/libnxflat_uninit.c @@ -42,7 +42,8 @@ #include #include #include -#include + +#include /**************************************************************************** * Pre-Processor Definitions @@ -56,10 +57,6 @@ * Private Functions ****************************************************************************/ -/**************************************************************************** - * Name: nxflat_swap32 - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/nuttx/binfmt/libnxflat/libnxflat_verify.c b/nuttx/binfmt/libnxflat/libnxflat_verify.c index f799aca4f..20af5d2f7 100644 --- a/nuttx/binfmt/libnxflat/libnxflat_verify.c +++ b/nuttx/binfmt/libnxflat/libnxflat_verify.c @@ -42,8 +42,9 @@ #include #include #include + #include -#include +#include /**************************************************************************** * Pre-processor Definitions @@ -91,10 +92,10 @@ int nxflat_verifyheader(const struct nxflat_hdr_s *header) if (strncmp(header->h_magic, NXFLAT_MAGIC, 4) != 0) { bdbg("Unrecognized magic=\"%c%c%c%c\"\n", - header->h_magic[0], header->h_magic[1], - header->h_magic[2], header->h_magic[3]); + header->h_magic[0], header->h_magic[1], + header->h_magic[2], header->h_magic[3]); return -ENOEXEC; } + return OK; } - diff --git a/nuttx/binfmt/symtab_findbyname.c b/nuttx/binfmt/symtab_findbyname.c index 201d7ba07..c0343e270 100644 --- a/nuttx/binfmt/symtab_findbyname.c +++ b/nuttx/binfmt/symtab_findbyname.c @@ -44,7 +44,7 @@ #include #include -#include +#include /**************************************************************************** * Pre-processor Definitions diff --git a/nuttx/binfmt/symtab_findbyvalue.c b/nuttx/binfmt/symtab_findbyvalue.c index 4382ed5d8..c47d5c751 100644 --- a/nuttx/binfmt/symtab_findbyvalue.c +++ b/nuttx/binfmt/symtab_findbyvalue.c @@ -44,7 +44,7 @@ #include #include -#include +#include /**************************************************************************** * Pre-processor Definitions diff --git a/nuttx/binfmt/symtab_findorderedbyname.c b/nuttx/binfmt/symtab_findorderedbyname.c index 61decf49a..a678788e7 100644 --- a/nuttx/binfmt/symtab_findorderedbyname.c +++ b/nuttx/binfmt/symtab_findorderedbyname.c @@ -44,7 +44,7 @@ #include #include -#include +#include /**************************************************************************** * Pre-processor Definitions diff --git a/nuttx/binfmt/symtab_findorderedbyvalue.c b/nuttx/binfmt/symtab_findorderedbyvalue.c index 92b107856..bad4bf8cd 100644 --- a/nuttx/binfmt/symtab_findorderedbyvalue.c +++ b/nuttx/binfmt/symtab_findorderedbyvalue.c @@ -44,7 +44,7 @@ #include #include -#include +#include /**************************************************************************** * Pre-processor Definitions diff --git a/nuttx/configs/README.txt b/nuttx/configs/README.txt index c4f5de5e3..21aace2af 100644 --- a/nuttx/configs/README.txt +++ b/nuttx/configs/README.txt @@ -103,14 +103,23 @@ Make.defs -- This makefile fragment provides architecture and Tools: CC, LD, AR, NM, OBJCOPY, OBJDUMP Tool options: CFLAGS, LDFLAGS - COMPILE, ASSEMBLE, ARCHIVE, CLEAN, and MKDEP macros When this makefile fragment runs, it will be passed TOPDIR which is the path to the root directory of the build. This makefile - fragment may include ${TOPDIR}/.config to perform configuration - specific settings. For example, the CFLAGS will most likely be + fragment should include: + + $(TOPDIR)/.config : Nuttx configuration + $(TOPDIR)/tools/Config.mk : Common definitions + + Definitions in the Make.defs file probably depend on some of the + settings in the .config file. For example, the CFLAGS will most likely be different if CONFIG_DEBUG=y. + The included tools/Config.mk file contains additional definitions that may + be overriden in the architecture-specific Make.defs file as necessary: + + COMPILE, ASSEMBLE, ARCHIVE, CLEAN, and MKDEP macros + defconfig -- This is a configuration file similar to the Linux configuration file. In contains variable/value pairs like: @@ -174,7 +183,6 @@ defconfig -- This is a configuration file similar to the Linux CONFIG_RAW_BINARY - make a raw binary format file used with many different loaders using the GNU objcopy program. This option should not be selected if you are not using the GNU toolchain. - CONFIG_HAVE_LIBM - toolchain supports libm.a CONFIG_HAVE_CXX - toolchain supports C++ and CXX, CXXFLAGS, and COMPILEXX have been defined in the configurations Make.defs file. @@ -321,7 +329,7 @@ defconfig -- This is a configuration file similar to the Linux CONFIG_RR_INTERVAL - The round robin timeslice will be set this number of milliseconds; Round robin scheduling can be disabled by setting this value to zero. - CONFIG_SCHED_INSTRUMENTATION - enables instrumentation in + CONFIG_SCHED_INSTRUMENTATION - enables instrumentation in scheduler to monitor system performance CONFIG_TASK_NAME_SIZE - Specifies that maximum size of a task name to save in the TCB. Useful if scheduler @@ -349,7 +357,7 @@ defconfig -- This is a configuration file similar to the Linux CONFIG_SEM_PREALLOCHOLDERS: This setting is only used if priority inheritance is enabled. It defines the maximum number of different threads (minus one) that can take counts on a - semaphore with priority inheritance support. This may be + semaphore with priority inheritance support. This may be set to zero if priority inheritance is disabled OR if you are only using semaphores as mutexes (only one holder) OR if no more than two threads participate using a counting @@ -375,9 +383,6 @@ defconfig -- This is a configuration file similar to the Linux CONFIG_SDCLONE_DISABLE. Disable cloning of all socket desciptors by task_create() when a new task is started. If set, all sockets will appear to be closed in the new task. - CONFIG_NXFLAT. Enable support for the NXFLAT binary format. - This format will support execution of NuttX binaries located - in a ROMFS filesystem (see examples/nxflat). CONFIG_SCHED_WORKQUEUE. Create a dedicated "worker" thread to handle delayed processing from interrupt handlers. This feature is required for some drivers but, if there are not complaints, @@ -421,6 +426,39 @@ defconfig -- This is a configuration file similar to the Linux where 'app' is the application name. If not defined, CONFIG_USER_ENTRYPOINT defaults to user_start. + Binary Loaders: + CONFIG_BINFMT_DISABLE - By default, support for loadable binary formats + is built. + This logic may be suppressed be defining this setting. + CONFIG_BINFMT_CONSTRUCTORS - Build in support for C++ constructors in + loaded modules. + CONFIG_SYMTAB_ORDEREDBYNAME - Symbol tables are order by name (rather + than value). + CONFIG_NXFLAT. Enable support for the NXFLAT binary format. This format + will support execution of NuttX binaries located in a ROMFS filesystem + (see apps/examples/nxflat). + CONFIG_ELF - Enable support for the ELF binary format. This format will + support execution of ELF binaries copied from a file system and + relocated into RAM (see apps/examples/elf). + + If CONFIG_ELF is selected, then these additional options are available: + + CONFIG_ELF_ALIGN_LOG2 - Align all sections to this Log2 value: 0->1, + 1->2, 2->4, etc. + CONFIG_ELF_STACKSIZE - This is the default stack size that will will + be used when starting ELF binaries. + CONFIG_ELF_BUFFERSIZE - This is an I/O buffer that is used to access + the ELF file. Variable length items will need to be read (such as + symbol names). This is really just this initial size of the buffer; + it will be reallocated as necessary to hold large symbol names). + Default: 128 + CONFIG_ELF_BUFFERINCR - This is an I/O buffer that is used to access + the ELF file. Variable length items will need to be read (such as + symbol names). This value specifies the size increment to use each + time the buffer is reallocated. Default: 32 + CONFIG_ELF_DUMPBUFFER - Dump various ELF buffers for debug purposes. + This option requires CONFIG_DEBUG and CONFIG_DEBUG_VERBOSE. + System Logging: CONFIG_SYSLOG enables general system logging support. CONFIG_SYSLOG_DEVPATH - The full path to the system logging device. Default @@ -506,7 +544,7 @@ defconfig -- This is a configuration file similar to the Linux from the end of RAM for page tables or other system usage. The configuration settings and linker directives must be cognizant of that: CONFIG_PAGING_NDATA should be defined to prevent the data region from - extending all the way to the end of memory. + extending all the way to the end of memory. CONFIG_PAGING_DEFPRIO - The default, minimum priority of the page fill worker thread. The priority of the page fill work thread will be boosted boosted dynmically so that it matches the priority of the task on behalf @@ -520,7 +558,7 @@ defconfig -- This is a configuration file similar to the Linux transfer is completed. Default: Undefined (non-blocking). CONFIG_PAGING_WORKPERIOD - The page fill worker thread will wake periodically even if there is no mapping to do. This selection controls that wake-up - period (in microseconds). This wake-up a failsafe that will handle any + period (in microseconds). This wake-up a failsafe that will handle any cases where a single is lost (that would really be a bug and shouldn't happen!) and also supports timeouts for case of non-blocking, asynchronous fills (see CONFIG_PAGING_TIMEOUT_TICKS). @@ -532,7 +570,7 @@ defconfig -- This is a configuration file similar to the Linux Some architecture-specific settings. Defaults are architecture specific. If you don't know what you are doing, it is best to leave these undefined and try the system defaults: - + CONFIG_PAGING_VECPPAGE - This the physical address of the page in memory to be mapped to the vector address. CONFIG_PAGING_VECL2PADDR - This is the physical address of the L2 @@ -555,7 +593,7 @@ defconfig -- This is a configuration file similar to the Linux devices. CONFIG_PAGING_SDSLOT identifies the slot number of the SD device to initialize. This must be undefined if SD is not being used. This should be defined to be zero for the typical device that has - only a single slot (See CONFIG_MMCSD_NSLOTS). If defined, + only a single slot (See CONFIG_MMCSD_NSLOTS). If defined, CONFIG_PAGING_SDSLOT will instruct certain board-specific logic to initialize the media in this SD slot. CONFIG_PAGING_M25PX - Use the m25px.c FLASH driver. If this is selected, @@ -624,6 +662,37 @@ defconfig -- This is a configuration file similar to the Linux CONFIG_ARCH_STRNCPY, CONFIG_ARCH_STRLEN, CONFIG_ARCH_STRNLEN CONFIG_ARCH_BZERO + If CONFIG_ARCH_MEMCPY is not selected, then you make also select Daniel + Vik's optimized implementation of memcpy(): + + CONFIG_MEMCPY_VIK - Select this option to use the optimized memcpy() + function by Daniel Vik. Select this option for improved performance + at the expense of increased size. See licensing information in the + top-level COPYING file. Default: n + + And if CONFIG_MEMCPY_VIK is selected, the following tuning options are available: + + CONFIG_MEMCPY_PRE_INC_PTRS - Use pre-increment of pointers. Default is + post increment of pointers. + + CONFIG_MEMCPY_INDEXED_COPY - Copying data using array indexing. Using + this option, disables the CONFIG_MEMCPY_PRE_INC_PTRS option. + + CONFIG_MEMCPY_64BIT - Compiles memcpy for architectures that suppport + 64-bit operations efficiently. + + If CONFIG_ARCH_MEMSET is not selected, then the following option is + also available: + + CONFIG_MEMSET_OPTSPEED - Select this option to use a version of memcpy() + optimized for speed. Default: memcpy() is optimized for size. + + And if CONFIG_MEMSET_OPTSPEED is selected, the following tuning option is + available: + + CONFIG_MEMSET_64BIT - Compiles memset() for architectures that suppport + 64-bit operations efficiently. + The architecture may provide custom versions of certain standard header files: @@ -666,6 +735,15 @@ defconfig -- This is a configuration file similar to the Linux don't select CONFIG_ARCH_MATH_H, the redirecting math.h header file will stay out-of-the-way in include/nuttx/. + CONFIG_ARCH_FLOAT_H + If you enable the generic, built-in math library, then that math library + will expect your toolchain to provide the standard float.h header file. + The float.h header file defines the properties of your floating point + implementation. It would always be best to use your toolchain's float.h + header file but if none is avaiable, a default float.h header file will + provided if this option is selected. However, there is no assurance that + the settings in this float.h are actually correct for your platform! + CONFIG_ARCH_STDARG_H - There is also a redirecting version of stdarg.h in the source tree as well. It also resides out-of-the-way at include/nuttx/stdarg.h. This is because you should normally use your toolchain's stdarg.h file. But @@ -696,7 +774,7 @@ defconfig -- This is a configuration file similar to the Linux If CONFIG_ARCH_ROMGETC is defined, then the architecture logic must export the function up_romgetc(). up_romgetc() will simply read one byte of data from the instruction space. - + If CONFIG_ARCH_ROMGETC, certain C stdio functions are effected: (1) All format strings in printf, fprintf, sprintf, etc. are assumed to lie in FLASH (string arguments for %s are still assumed @@ -766,7 +844,7 @@ defconfig -- This is a configuration file similar to the Linux much sense in supporting FAT date and time unless you have a hardware RTC or other way to get the time and date. CONFIG_FS_NXFFS: Enable NuttX FLASH file system (NXFF) support. - CONFIG_NXFFS_ERASEDSTATE: The erased state of FLASH. + CONFIG_NXFFS_ERASEDSTATE: The erased state of FLASH. This must have one of the values of 0xff or 0x00. Default: 0xff. CONFIG_NXFFS_PACKTHRESHOLD: When packing flash file data, @@ -920,7 +998,7 @@ defconfig -- This is a configuration file similar to the Linux CONFIG_INPUT Enables general support for input devices - + CONFIG_INPUT_TSC2007 If CONFIG_INPUT is selected, then this setting will enable building of the TI TSC2007 touchscreen driver. @@ -935,14 +1013,14 @@ defconfig -- This is a configuration file similar to the Linux Enables support for the SPI interface (not currenly supported) CONFIG_STMPE811_I2C Enables support for the I2C interface - CONFIG_STMPE811_MULTIPLE + CONFIG_STMPE811_MULTIPLE Can be defined to support multiple STMPE811 devices on board. CONFIG_STMPE811_ACTIVELOW Interrupt is generated by an active low signal (or falling edge). CONFIG_STMPE811_EDGE Interrupt is generated on an edge (vs. on the active level) CONFIG_STMPE811_NPOLLWAITERS - Maximum number of threads that can be waiting on poll() (ignored if + Maximum number of threads that can be waiting on poll() (ignored if CONFIG_DISABLE_POLL is set). CONFIG_STMPE811_TSC_DISABLE Disable driver touchscreen functionality. @@ -1051,21 +1129,21 @@ defconfig -- This is a configuration file similar to the Linux port. The default data link layer for uIP is Ethernet. If CONFIG_NET_SLIP is defined in the NuttX configuration file, then SLIP will be supported. The basic differences between the SLIP and Ethernet configurations is that - when SLIP is selected: + when SLIP is selected: - * The link level header (that comes before the IP header) is omitted. - * All MAC address processing is suppressed. + * The link level header (that comes before the IP header) is omitted. + * All MAC address processing is suppressed. * ARP is disabled. If CONFIG_NET_SLIP is not selected, then Ethernet will be used (there is no need to define anything special in the configuration file to use - Ethernet -- it is the default). + Ethernet -- it is the default). CONFIG_NET_SLIP -- Enables building of the SLIP driver. SLIP requires at least one IP protocols selected and the following additional network settings: CONFIG_NET_NOINTS and CONFIG_NET_MULTIBUFFER. CONFIG_NET_BUFSIZE *must* be set to 296. Other optional configuration - settings that affect the SLIP driver: CONFIG_NET_STATISTICS. + settings that affect the SLIP driver: CONFIG_NET_STATISTICS. Default: Ethernet If SLIP is selected, then the following SLIP options are available: @@ -1081,6 +1159,10 @@ defconfig -- This is a configuration file similar to the Linux CONFIG_NET_DHCP_LIGHT - Reduces size of DHCP CONFIG_NET_RESOLV_ENTRIES - Number of resolver entries + CONFIG_NET_RESOLV_MAXRESPONSE - This setting determines the maximum + size of response message that can be received by the DNS resolver. + The default is 96 but may need to be larger on enterprise networks + (perhaps 176). THTTPD @@ -1102,7 +1184,7 @@ defconfig -- This is a configuration file similar to the Linux to run before killing them. CONFIG_THTTPD_CHARSET- The default character set name to use with text MIME types. - CONFIG_THTTPD_IOBUFFERSIZE - + CONFIG_THTTPD_IOBUFFERSIZE - CONFIG_THTTPD_INDEX_NAMES - A list of index filenames to check. The files are searched for in this order. CONFIG_AUTH_FILE - The file to use for authentication. If this is @@ -1134,7 +1216,7 @@ defconfig -- This is a configuration file similar to the Linux You can also leave both options undefined, and thttpd will not do anything special about tildes. Enabling both options is an error. Typical values, if they're defined, are "users" for - CONFIG_THTTPD_TILDE_MAP1 and "public_html"forCONFIG_THTTPD_TILDE_MAP2. + CONFIG_THTTPD_TILDE_MAP1 and "public_html"forCONFIG_THTTPD_TILDE_MAP2. CONFIG_THTTPD_GENERATE_INDICES CONFIG_THTTPD_URLPATTERN - If defined, then it will be used to match and verify referrers. @@ -1192,7 +1274,7 @@ defconfig -- This is a configuration file similar to the Linux USB host HID class driver. Requires CONFIG_USBHOST=y, CONFIG_USBHOST_INT_DISABLE=n, CONFIG_NFILE_DESCRIPTORS > 0, CONFIG_SCHED_WORKQUEUE=y, and CONFIG_DISABLE_SIGNALS=n. - + CONFIG_HIDKBD_POLLUSEC Device poll rate in microseconds. Default: 100 milliseconds. CONFIG_HIDKBD_DEFPRIO @@ -1211,7 +1293,7 @@ defconfig -- This is a configuration file similar to the Linux If set to y all 231 possible scancodes will be converted to something. Default: 104 key US keyboard. CONFIG_HIDKBD_NODEBOUNCE - If set to y normal debouncing is disabled. Default: + If set to y normal debouncing is disabled. Default: Debounce enabled (No repeat keys). USB host mass storage class driver. Requires CONFIG_USBHOST=y, @@ -1248,12 +1330,12 @@ defconfig -- This is a configuration file similar to the Linux Configure the CDC serial driver as part of a composite driver (only if CONFIG_USBDEV_COMPOSITE is also defined) CONFIG_CDCACM_IFNOBASE - If the CDC driver is part of a composite device, then this may need to + If the CDC driver is part of a composite device, then this may need to be defined to offset the CDC/ACM interface numbers so that they are unique and contiguous. When used with the Mass Storage driver, the correct value for this offset is zero. CONFIG_CDCACM_STRBASE - If the CDC driver is part of a composite device, then this may need to + If the CDC driver is part of a composite device, then this may need to be defined to offset the CDC/ACM string numbers so that they are unique and contiguous. When used with the Mass Storage driver, the correct value for this offset is four (this value actuallly only needs @@ -1312,13 +1394,13 @@ defconfig -- This is a configuration file similar to the Linux Configure the mass storage driver as part of a composite driver (only if CONFIG_USBDEV_COMPOSITE is also defined) CONFIG_USBMSC_IFNOBASE - If the CDC driver is part of a composite device, then this may need to + If the CDC driver is part of a composite device, then this may need to be defined to offset the mass storage interface number so that it is unique and contiguous. When used with the CDC/ACM driver, the correct value for this offset is two (because of the two CDC/ACM interfaces that will precede it). CONFIG_USBMSC_STRBASE - If the CDC driver is part of a composite device, then this may need to + If the CDC driver is part of a composite device, then this may need to be defined to offset the mass storage string numbers so that they are unique and contiguous. When used with the CDC/ACM driver, the correct value for this offset is four (or perhaps 5 or 6, depending @@ -1526,10 +1608,15 @@ configs/avr32dev1 configs/c5471evm This is a port to the Spectrum Digital C5471 evaluation board. The TMS320C5471 is a dual core processor from TI with an ARM7TDMI general - purpose processor and a c54 DSP. It is also known as TMS320DA180 or just DA180. + purpose processor and a c54 DSP. It is also known as TMS320DA180 or just DA180. NuttX runs on the ARM core and is built with a GNU arm-nuttx-elf toolchain*. This port is complete and verified. +configs/cloudctrl + Darcy's CloudController board. This is a small network relay development + board. Based on the Shenzhou IV development board design. It is based on + the STM32F107VC MCU. + configs/compal_e88 and compal_e99 These directories contain the board support for compal e88 and e99 phones. These ports are based on patches contributed by Denis Carikli for both the @@ -1542,23 +1629,23 @@ configs/demo9s12ne64 is code complete but has not yet been verified. configs/ea3131 - Embedded Artists EA3131 Development board. This board is based on the + Embedded Artists EA3131 Development board. This board is based on the an NXP LPC3131 MCU. This OS is built with the arm-nuttx-elf toolchain*. STATUS: This port is complete and mature. configs/ea3152 - Embedded Artists EA3152 Development board. This board is based on the + Embedded Artists EA3152 Development board. This board is based on the an NXP LPC3152 MCU. This OS is built with the arm-nuttx-elf toolchain*. STATUS: This port is has not be exercised well, but since it is a simple derivative of the ea3131, it should be fully functional. configs/eagle100 - Micromint Eagle-100 Development board. This board is based on the + Micromint Eagle-100 Development board. This board is based on the an ARM Cortex-M3 MCU, the Luminary LM3S6918. This OS is built with the arm-nuttx-elf toolchain*. STATUS: This port is complete and mature. configs/ekk-lm3s9b96 - TI/Stellaris EKK-LM3S9B96 board. This board is based on the + TI/Stellaris EKK-LM3S9B96 board. This board is based on the an EKK-LM3S9B96 which is a Cortex-M3. configs/ez80f0910200kitg @@ -1586,13 +1673,13 @@ configs/kwikstik-k40. configs/lincoln60 NuttX port to the Micromint Lincoln 60 board. - + configs/lm3s6432-s2e Stellaris RDK-S2E Reference Design Kit and the MDL-S2E Ethernet to Serial module. configs/lm3s6965-ek - Stellaris LM3S6965 Evaluation Kit. This board is based on the + Stellaris LM3S6965 Evaluation Kit. This board is based on the an ARM Cortex-M3 MCU, the Luminary/TI LM3S6965. This OS is built with the arm-nuttx-elf toolchain*. STATUS: This port is complete and mature. @@ -1649,7 +1736,7 @@ configs/ntosd-dm320 toolchain*: see http://wiki.neurostechnology.com/index.php/OSD_1.0_Developer_Home - + There are some differences between the Dev Board and the currently available commercial v1.0 Boards. See @@ -1739,7 +1826,7 @@ configs/qemu-i486 hardwared (Google the Bifferboard). configs/rgmp - RGMP stands for RTOS and GPOS on Multi-Processor. RGMP is a project for + RGMP stands for RTOS and GPOS on Multi-Processor. RGMP is a project for running GPOS and RTOS simultaneously on multi-processor platforms. You can port your favorite RTOS to RGMP together with an unmodified Linux to form a hybrid operating system. This makes your application able to use both RTOS @@ -1780,8 +1867,14 @@ configs/stm3240g-eval microcontroller (ARM Cortex-M4 with FPU). This port uses a GNU Cortex-M4 toolchain (such as CodeSourcery). +configs/stm32f100rc_generic + STMicro STM32F100RC generic board based on STM32F100RC high-density value line + chip. This "generic" configuration is not very usable out-of-box, but can be + used as a starting point to creating new configs with similar STM32 + high-density value line chips. + configs/stm32f4discovery - STMicro STM32F4-Discovery board boased on the STMIcro STM32F407VGT6 MCU. + STMicro STM32F4-Discovery board based on the STMIcro STM32F407VGT6 MCU. configs/sure-pic32mx The "Advanced USB Storage Demo Board," Model DB-DP11215, from Sure @@ -1818,7 +1911,7 @@ configs/vsn configs/xtrs TRS80 Model 3. This port uses a vintage computer based on the Z80. - An emulator for this computer is available to run TRS80 programs on a + An emulator for this computer is available to run TRS80 programs on a linux platform (http://www.tim-mann.org/xtrs.html). configs/z16f2800100zcog @@ -1869,7 +1962,7 @@ And if configs///appconfig exists and your application directory is not in the standard loction (../apps), then you should also specify the location of the application directory on the command line like: - + cd tools ./configure.sh -a / diff --git a/nuttx/configs/px4fmu/nsh/defconfig b/nuttx/configs/px4fmu/nsh/defconfig index cd86d5544..9555e43ec 100755 --- a/nuttx/configs/px4fmu/nsh/defconfig +++ b/nuttx/configs/px4fmu/nsh/defconfig @@ -200,6 +200,10 @@ CONFIG_STM32_TIM9=y CONFIG_STM32_TIM10=y CONFIG_STM32_TIM11=y +# +# We want the flash prefetch on for max performance. +# +STM32_FLASH_PREFETCH=y # # Enable the MTD driver for the onboard I2C EEPROM @@ -351,6 +355,7 @@ CONFIG_I2C=y CONFIG_I2C_POLLED=y CONFIG_I2C_TRANSFER=y CONFIG_I2C_TRACE=n +CONFIG_I2C_RESET=y # Allow 180 us per byte, a wide margin for the 400 KHz clock we're using # e.g. 9.6 ms for an EEPROM page write, 0.9 ms for a MAG update CONFIG_STM32_I2CTIMEOUS_PER_BYTE=200 diff --git a/nuttx/drivers/Kconfig b/nuttx/drivers/Kconfig index 1d263ec14..8302d21b7 100644 --- a/nuttx/drivers/Kconfig +++ b/nuttx/drivers/Kconfig @@ -47,7 +47,8 @@ config CAN_EXTID bool "CAN extended IDs" default n ---help--- - Enables support for the 29-bit extended ID. Default Standard 11-bit IDs. + Enables support for the 29-bit extended ID. Default Standard 11-bit + IDs. config CAN_FIFOSIZE int "CAN driver I/O buffer size" @@ -83,10 +84,10 @@ config PWM_PULSECOUNT bool "PWM Pulse Count Support" default n ---help--- - Some hardware will support generation of a fixed number of pulses. This - might be used, for example to support a stepper motor. If the hardware - will support a fixed pulse count, then this configuration should be set to - enable the capability. + Some hardware will support generation of a fixed number of pulses. + This might be used, for example to support a stepper motor. If the + hardware will support a fixed pulse count, then this configuration + should be set to enable the capability. endif @@ -147,23 +148,25 @@ config SPI_OWNBUS bool "SPI single device" default n ---help--- - Set if there is only one active device on the SPI bus. No locking or SPI - configuration will be performed. It is not necessary for clients to lock, - re-configure, etc.. + Set if there is only one active device on the SPI bus. No locking or + SPI configuration will be performed. It is not necessary for clients to + lock, re-configure, etc.. config SPI_EXCHANGE bool "SPI exchange" default y ---help--- - Driver supports a single exchange method (vs a recvblock() and sndblock ()methods). + Driver supports a single exchange method (vs a recvblock() and + sndblock() methods). config SPI_CMDDATA bool "SPI CMD/DATA" default n ---help--- - Devices on the SPI bus require out-of-band support to distinguish command - transfers from data transfers. Such devices will often support either 9-bit - SPI (yech) or 8-bit SPI and a GPIO output that selects between command and data. + Devices on the SPI bus require out-of-band support to distinguish + command transfers from data transfers. Such devices will often support + either 9-bit SPI (yech) or 8-bit SPI and a GPIO output that selects + between command and data. endif @@ -173,35 +176,36 @@ menuconfig RTC ---help--- This selection enables configuration of a real time clock (RTCdriver. See include/nuttx/rtc.h for further watchdog timer driver information. - Most RTC drivers are MCU specific and may require other specific settings. + Most RTC drivers are MCU specific and may require other specific + settings. config RTC_DATETIME bool "Date/Time RTC Support" default n depends on RTC ---help--- - There are two general types of RTC: (1) A simple battery backed counter - that keeps the time when power is down, and (2) a full date / time RTC the - provides the date and time information, often in BCD format. If - RTC_DATETIME is selected, it specifies this second kind of RTC. In this - case, the RTC is used to "seed" the normal NuttX timer and the NuttX system - timer provides for higher resolution time. + There are two general types of RTC: (1) A simple battery backed + counter that keeps the time when power is down, and (2) a full + date / time RTC the provides the date and time information, often in + BCD format. If RTC_DATETIME is selected, it specifies this second kind + of RTC. In this case, the RTC is used to "seed" the normal NuttX timer + and the NuttX system timer provides for higher resolution time. config RTC_HIRES bool "Hi-Res RTC Support" default n depends on RTC && !RTC_DATETIME ---help--- - If RTC_DATETIME not selected, then the simple, battery backed counter is - used. There are two different implementations of such simple counters - based on the time resolution of the counter: The typical RTC keeps time - to resolution of 1 second, usually supporting a 32-bit time_t value. In - this case, the RTC is used to "seed" the normal NuttX timer and the NuttX - timer provides for higherresoution time. + If RTC_DATETIME not selected, then the simple, battery backed counter + is used. There are two different implementations of such simple + counters based on the time resolution of the counter: The typical RTC + keeps time to resolution of 1 second, usually supporting a 32-bit + time_t value. In this case, the RTC is used to "seed" the normal NuttX + timer and the NuttX timer provides for higherresoution time. - If RTC_HIRES is enabled in the NuttX configuration, then the RTC provides - higher resolution time and completely replaces the system timer for purpose - of date and time. + If RTC_HIRES is enabled in the NuttX configuration, then the RTC + provides higher resolution time and completely replaces the system + timer for purpose of date and time. config RTC_FREQUENCY int "Hi-Res RTC frequency" @@ -209,8 +213,8 @@ config RTC_FREQUENCY depends on RTC && !RTC_DATETIME && RTC_HIRES ---help--- If RTC_HIRES is defined, then the frequency of the high resolution RTC - must be provided. If RTC_HIRES is not defined, RTC_FREQUENCY is assumed - to be one Hz. + must be provided. If RTC_HIRES is not defined, RTC_FREQUENCY is + assumed to be one Hz. config RTC_ALARM bool "RTC Alarm Support" @@ -224,8 +228,9 @@ menuconfig WATCHDOG bool "Watchdog Timer Support" default n ---help--- - This selection enables building of the "upper-half" watchdog timer driver. - See include/nuttx/watchdog.h for further watchdog timer driver information. + This selection enables building of the "upper-half" watchdog timer + driver. See include/nuttx/watchdog.h for further watchdog timer driver + information. if WATCHDOG endif @@ -348,7 +353,8 @@ menuconfig POWER bool "Power Management Support" default n ---help--- - Enable building of power-related devices (battery monitors, chargers, etc). + Enable building of power-related devices (battery monitors, chargers, + etc). if POWER source drivers/power/Kconfig @@ -386,8 +392,8 @@ menuconfig SERIAL default y ---help--- Front-end character drivers for chip-specific UARTs. This provide - some TTY-like functionality and are commonly used (but not required for) - the NuttX system console. See also include/nuttx/serial/serial.h + some TTY-like functionality and are commonly used (but not required + for) the NuttX system console. See also include/nuttx/serial/serial.h if SERIAL source drivers/serial/Kconfig diff --git a/nuttx/drivers/Makefile b/nuttx/drivers/Makefile index 6d3b40b1f..aaaa67bd7 100644 --- a/nuttx/drivers/Makefile +++ b/nuttx/drivers/Makefile @@ -86,15 +86,15 @@ ifeq ($(CONFIG_WATCHDOG),y) endif endif -AOBJS = $(ASRCS:.S=$(OBJEXT)) -COBJS = $(CSRCS:.c=$(OBJEXT)) +AOBJS = $(ASRCS:.S=$(OBJEXT)) +COBJS = $(CSRCS:.c=$(OBJEXT)) -SRCS = $(ASRCS) $(CSRCS) -OBJS = $(AOBJS) $(COBJS) +SRCS = $(ASRCS) $(CSRCS) +OBJS = $(AOBJS) $(COBJS) -BIN = libdrivers$(LIBEXT) +BIN = libdrivers$(LIBEXT) -all: $(BIN) +all: $(BIN) $(AOBJS): %$(OBJEXT): %.S $(call ASSEMBLE, $<, $@) @@ -102,22 +102,21 @@ $(AOBJS): %$(OBJEXT): %.S $(COBJS): %$(OBJEXT): %.c $(call COMPILE, $<, $@) -$(BIN): $(OBJS) - @( for obj in $(OBJS) ; do \ - $(call ARCHIVE, $@, $${obj}); \ - done ; ) +$(BIN): $(OBJS) + $(call ARCHIVE, $@, $(OBJS)) .depend: Makefile $(SRCS) - @$(MKDEP) $(DEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep - @touch $@ + $(Q) $(MKDEP) $(DEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep + $(Q) touch $@ depend: .depend clean: - @rm -f $(BIN) *~ .*.swp + $(call DELFILE, $(BIN)) $(call CLEAN) distclean: clean - @rm -f Make.dep .depend + $(call DELFILE, Make.dep) + $(call DELFILE, .depend) -include Make.dep diff --git a/nuttx/drivers/analog/adc.c b/nuttx/drivers/analog/adc.c index 84070f162..72f19452a 100644 --- a/nuttx/drivers/analog/adc.c +++ b/nuttx/drivers/analog/adc.c @@ -143,7 +143,7 @@ static int adc_open(FAR struct file *filep) dev->ad_recv.af_head = 0; dev->ad_recv.af_tail = 0; - /* Finally, Enable the CAN RX interrupt */ + /* Finally, Enable the ADC RX interrupt */ dev->ad_ops->ao_rxint(dev, true); @@ -151,9 +151,11 @@ static int adc_open(FAR struct file *filep) dev->ad_ocount = tmp; } + irqrestore(flags); } } + sem_post(&dev->ad_closesem); } return ret; @@ -370,6 +372,10 @@ static int adc_ioctl(FAR struct file *filep, int cmd, unsigned long arg) * Public Functions ****************************************************************************/ +/**************************************************************************** + * Name: adc_receive + ****************************************************************************/ + int adc_receive(FAR struct adc_dev_s *dev, uint8_t ch, int32_t data) { FAR struct adc_fifo_s *fifo = &dev->ad_recv; @@ -390,7 +396,7 @@ int adc_receive(FAR struct adc_dev_s *dev, uint8_t ch, int32_t data) if (nexttail != fifo->af_head) { - /* Add the new, decoded CAN message at the tail of the FIFO */ + /* Add the new, decoded ADC sample at the tail of the FIFO */ fifo->af_buffer[fifo->af_tail].am_channel = ch; fifo->af_buffer[fifo->af_tail].am_data = data; @@ -403,11 +409,16 @@ int adc_receive(FAR struct adc_dev_s *dev, uint8_t ch, int32_t data) { sem_post(&fifo->af_sem); } + err = OK; } return err; } +/**************************************************************************** + * Name: adc_register + ****************************************************************************/ + int adc_register(FAR const char *path, FAR struct adc_dev_s *dev) { /* Initialize the ADC device structure */ diff --git a/nuttx/drivers/input/max11802.c b/nuttx/drivers/input/max11802.c new file mode 100644 index 000000000..ea3883cd0 --- /dev/null +++ b/nuttx/drivers/input/max11802.c @@ -0,0 +1,1313 @@ +/**************************************************************************** + * drivers/input/max11802.c + * + * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. + * Authors: Gregory Nutt + * Petteri Aimonen + * + * References: + * "Low-Power, Ultra-Small Resistive Touch-Screen Controllers + * with I2C/SPI Interface" Maxim IC, Rev 3, 10/2010 + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include + +#include "max11802.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* This is a value for the threshold that guantees a big difference on the + * first pendown (but can't overflow). + */ + +#define INVALID_THRESHOLD 0x1000 + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ +/* Low-level SPI helpers */ + +#ifdef CONFIG_SPI_OWNBUS +static inline void max11802_configspi(FAR struct spi_dev_s *spi); +# define max11802_lock(spi) +# define max11802_unlock(spi) +#else +# define max11802_configspi(spi); +static void max11802_lock(FAR struct spi_dev_s *spi); +static void max11802_unlock(FAR struct spi_dev_s *spi); +#endif + +static uint16_t max11802_sendcmd(FAR struct max11802_dev_s *priv, uint8_t cmd, int *tags); + +/* Interrupts and data sampling */ + +static void max11802_notify(FAR struct max11802_dev_s *priv); +static int max11802_sample(FAR struct max11802_dev_s *priv, + FAR struct max11802_sample_s *sample); +static int max11802_waitsample(FAR struct max11802_dev_s *priv, + FAR struct max11802_sample_s *sample); +static void max11802_worker(FAR void *arg); +static int max11802_interrupt(int irq, FAR void *context); + +/* Character driver methods */ + +static int max11802_open(FAR struct file *filep); +static int max11802_close(FAR struct file *filep); +static ssize_t max11802_read(FAR struct file *filep, FAR char *buffer, size_t len); +static int max11802_ioctl(FAR struct file *filep, int cmd, unsigned long arg); +#ifndef CONFIG_DISABLE_POLL +static int max11802_poll(FAR struct file *filep, struct pollfd *fds, bool setup); +#endif + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/* This the the vtable that supports the character driver interface */ + +static const struct file_operations max11802_fops = +{ + max11802_open, /* open */ + max11802_close, /* close */ + max11802_read, /* read */ + 0, /* write */ + 0, /* seek */ + max11802_ioctl /* ioctl */ +#ifndef CONFIG_DISABLE_POLL + , max11802_poll /* poll */ +#endif +}; + +/* If only a single MAX11802 device is supported, then the driver state + * structure may as well be pre-allocated. + */ + +#ifndef CONFIG_MAX11802_MULTIPLE +static struct max11802_dev_s g_max11802; + +/* Otherwise, we will need to maintain allocated driver instances in a list */ + +#else +static struct max11802_dev_s *g_max11802list; +#endif + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: max11802_lock + * + * Description: + * Lock the SPI bus and re-configure as necessary. This function must be + * to assure: (1) exclusive access to the SPI bus, and (2) to assure that + * the shared bus is properly configured for the touchscreen controller. + * + * Parameters: + * spi - Reference to the SPI driver structure + * + * Returned Value: + * None + * + * Assumptions: + * + ****************************************************************************/ + +#ifndef CONFIG_SPI_OWNBUS +static void max11802_lock(FAR struct spi_dev_s *spi) +{ + /* Lock the SPI bus because there are multiple devices competing for the + * SPI bus + */ + + (void)SPI_LOCK(spi, true); + + /* We have the lock. Now make sure that the SPI bus is configured for the + * MAX11802 (it might have gotten configured for a different device while + * unlocked) + */ + + SPI_SELECT(spi, SPIDEV_TOUCHSCREEN, true); + SPI_SETMODE(spi, CONFIG_MAX11802_SPIMODE); + SPI_SETBITS(spi, 8); + SPI_SETFREQUENCY(spi, CONFIG_MAX11802_FREQUENCY); + SPI_SELECT(spi, SPIDEV_TOUCHSCREEN, false); +} +#endif + +/**************************************************************************** + * Function: max11802_unlock + * + * Description: + * If we are sharing the SPI bus with other devices (CONFIG_SPI_OWNBUS + * undefined) then we need to un-lock the SPI bus for each transfer, + * possibly losing the current configuration. + * + * Parameters: + * spi - Reference to the SPI driver structure + * + * Returned Value: + * None + * + * Assumptions: + * + ****************************************************************************/ + +#ifndef CONFIG_SPI_OWNBUS +static void max11802_unlock(FAR struct spi_dev_s *spi) +{ + /* Relinquish the SPI bus. */ + + (void)SPI_LOCK(spi, false); +} +#endif + +/**************************************************************************** + * Function: max11802_configspi + * + * Description: + * Configure the SPI for use with the MAX11802. This function should be + * called once during touchscreen initialization to configure the SPI + * bus. Note that if CONFIG_SPI_OWNBUS is not defined, then this function + * does nothing. + * + * Parameters: + * spi - Reference to the SPI driver structure + * + * Returned Value: + * None + * + * Assumptions: + * + ****************************************************************************/ + +#ifdef CONFIG_SPI_OWNBUS +static inline void max11802_configspi(FAR struct spi_dev_s *spi) +{ + /* Configure SPI for the MAX11802. But only if we own the SPI bus. Otherwise, don't + * bother because it might change. + */ + + SPI_SELECT(spi, SPIDEV_TOUCHSCREEN, true); + SPI_SETMODE(spi, CONFIG_MAX11802_SPIMODE); + SPI_SETBITS(spi, 8); + SPI_SETFREQUENCY(spi, CONFIG_MAX11802_FREQUENCY); + SPI_SELECT(spi, SPIDEV_TOUCHSCREEN, false); +} +#endif + +/**************************************************************************** + * Name: max11802_sendcmd + ****************************************************************************/ + +static uint16_t max11802_sendcmd(FAR struct max11802_dev_s *priv, uint8_t cmd, int *tags) +{ + uint8_t buffer[2]; + uint16_t result; + + /* Select the MAX11802 */ + + SPI_SELECT(priv->spi, SPIDEV_TOUCHSCREEN, true); + + /* Send the command */ + + (void)SPI_SEND(priv->spi, cmd); + + /* Read the data */ + + SPI_RECVBLOCK(priv->spi, buffer, 2); + SPI_SELECT(priv->spi, SPIDEV_TOUCHSCREEN, false); + + result = ((uint16_t)buffer[0] << 8) | (uint16_t)buffer[1]; + *tags = result & 0xF; + result >>= 4; // Get rid of tags + + ivdbg("cmd:%02x response:%04x\n", cmd, result); + return result; +} + +/**************************************************************************** + * Name: max11802_notify + ****************************************************************************/ + +static void max11802_notify(FAR struct max11802_dev_s *priv) +{ +#ifndef CONFIG_DISABLE_POLL + int i; +#endif + + /* If there are threads waiting for read data, then signal one of them + * that the read data is available. + */ + + if (priv->nwaiters > 0) + { + /* After posting this semaphore, we need to exit because the sample + * is no longer available. + */ + + sem_post(&priv->waitsem); + } + + /* If there are threads waiting on poll() for MAX11802 data to become available, + * then wake them up now. NOTE: we wake up all waiting threads because we + * do not know that they are going to do. If they all try to read the data, + * then some make end up blocking after all. + */ + +#ifndef CONFIG_DISABLE_POLL + for (i = 0; i < CONFIG_MAX11802_NPOLLWAITERS; i++) + { + struct pollfd *fds = priv->fds[i]; + if (fds) + { + fds->revents |= POLLIN; + ivdbg("Report events: %02x\n", fds->revents); + sem_post(fds->sem); + } + } +#endif +} + +/**************************************************************************** + * Name: max11802_sample + ****************************************************************************/ + +static int max11802_sample(FAR struct max11802_dev_s *priv, + FAR struct max11802_sample_s *sample) +{ + irqstate_t flags; + int ret = -EAGAIN; + + /* Interrupts must be disabled when this is called to (1) prevent posting + * of semaphores from interrupt handlers, and (2) to prevent sampled data + * from changing until it has been reported. + */ + + flags = irqsave(); + + /* Is there new MAX11802 sample data available? */ + + if (priv->penchange) + { + /* Yes.. the state has changed in some way. Return a copy of the + * sampled data. + */ + + memcpy(sample, &priv->sample, sizeof(struct max11802_sample_s )); + + /* Now manage state transitions */ + + if (sample->contact == CONTACT_UP) + { + /* Next.. no contact. Increment the ID so that next contact ID + * will be unique. X/Y positions are no longer valid. + */ + + priv->sample.contact = CONTACT_NONE; + priv->sample.valid = false; + priv->id++; + } + else if (sample->contact == CONTACT_DOWN) + { + /* First report -- next report will be a movement */ + + priv->sample.contact = CONTACT_MOVE; + } + + priv->penchange = false; + ret = OK; + } + + irqrestore(flags); + return ret; +} + +/**************************************************************************** + * Name: max11802_waitsample + ****************************************************************************/ + +static int max11802_waitsample(FAR struct max11802_dev_s *priv, + FAR struct max11802_sample_s *sample) +{ + irqstate_t flags; + int ret; + + /* Interrupts must be disabled when this is called to (1) prevent posting + * of semaphores from interrupt handlers, and (2) to prevent sampled data + * from changing until it has been reported. + * + * In addition, we will also disable pre-emption to prevent other threads + * from getting control while we muck with the semaphores. + */ + + sched_lock(); + flags = irqsave(); + + /* Now release the semaphore that manages mutually exclusive access to + * the device structure. This may cause other tasks to become ready to + * run, but they cannot run yet because pre-emption is disabled. + */ + + sem_post(&priv->devsem); + + /* Try to get the a sample... if we cannot, then wait on the semaphore + * that is posted when new sample data is available. + */ + + while (max11802_sample(priv, sample) < 0) + { + /* Wait for a change in the MAX11802 state */ + + ivdbg("Waiting..\n"); + priv->nwaiters++; + ret = sem_wait(&priv->waitsem); + priv->nwaiters--; + + if (ret < 0) + { + /* If we are awakened by a signal, then we need to return + * the failure now. + */ + + idbg("sem_wait: %d\n", errno); + DEBUGASSERT(errno == EINTR); + ret = -EINTR; + goto errout; + } + } + + ivdbg("Sampled\n"); + + /* Re-acquire the the semaphore that manages mutually exclusive access to + * the device structure. We may have to wait here. But we have our sample. + * Interrupts and pre-emption will be re-enabled while we wait. + */ + + ret = sem_wait(&priv->devsem); + +errout: + /* Then re-enable interrupts. We might get interrupt here and there + * could be a new sample. But no new threads will run because we still + * have pre-emption disabled. + */ + + irqrestore(flags); + + /* Restore pre-emption. We might get suspended here but that is okay + * because we already have our sample. Note: this means that if there + * were two threads reading from the MAX11802 for some reason, the data + * might be read out of order. + */ + + sched_unlock(); + return ret; +} + +/**************************************************************************** + * Name: max11802_schedule + ****************************************************************************/ + +static int max11802_schedule(FAR struct max11802_dev_s *priv) +{ + FAR struct max11802_config_s *config; + int ret; + + /* Get a pointer the callbacks for convenience (and so the code is not so + * ugly). + */ + + config = priv->config; + DEBUGASSERT(config != NULL); + + /* Disable further interrupts. MAX11802 interrupts will be re-enabled + * after the worker thread executes. + */ + + config->enable(config, false); + + /* Disable the watchdog timer. It will be re-enabled in the worker thread + * while the pen remains down. + */ + + wd_cancel(priv->wdog); + + /* Transfer processing to the worker thread. Since MAX11802 interrupts are + * disabled while the work is pending, no special action should be required + * to protected the work queue. + */ + + DEBUGASSERT(priv->work.worker == NULL); + ret = work_queue(HPWORK, &priv->work, max11802_worker, priv, 0); + if (ret != 0) + { + illdbg("Failed to queue work: %d\n", ret); + } + + return OK; +} + +/**************************************************************************** + * Name: max11802_wdog + ****************************************************************************/ + +static void max11802_wdog(int argc, uint32_t arg1, ...) +{ + FAR struct max11802_dev_s *priv = (FAR struct max11802_dev_s *)((uintptr_t)arg1); + (void)max11802_schedule(priv); +} + +/**************************************************************************** + * Name: max11802_worker + ****************************************************************************/ + +static void max11802_worker(FAR void *arg) +{ + FAR struct max11802_dev_s *priv = (FAR struct max11802_dev_s *)arg; + FAR struct max11802_config_s *config; + uint16_t x; + uint16_t y; + uint16_t xdiff; + uint16_t ydiff; + bool pendown; + int ret; + int tags, tags2; + + ASSERT(priv != NULL); + + /* Get a pointer the callbacks for convenience (and so the code is not so + * ugly). + */ + + config = priv->config; + DEBUGASSERT(config != NULL); + + /* Disable the watchdog timer. This is safe because it is started only + * by this function and this function is serialized on the worker thread. + */ + + wd_cancel(priv->wdog); + + /* Lock the SPI bus so that we have exclusive access */ + + max11802_lock(priv->spi); + + /* Start coordinate measurement */ + (void)max11802_sendcmd(priv, MAX11802_CMD_MEASUREXY, &tags); + + /* Get exclusive access to the driver data structure */ + + do + { + ret = sem_wait(&priv->devsem); + + /* This should only fail if the wait was canceled by an signal + * (and the worker thread will receive a lot of signals). + */ + + DEBUGASSERT(ret == OK || errno == EINTR); + } + while (ret < 0); + + /* Check for pen up or down by reading the PENIRQ GPIO. */ + + pendown = config->pendown(config); + + /* Handle the change from pen down to pen up */ + + if (pendown) + ivdbg("\nPD\n"); + else + ivdbg("\nPU\n"); + + if (!pendown) + { + /* The pen is up.. reset thresholding variables. */ + + priv->threshx = INVALID_THRESHOLD; + priv->threshy = INVALID_THRESHOLD; + + /* Ignore the interrupt if the pen was already up (CONTACT_NONE == pen up + * and already reported; CONTACT_UP == pen up, but not reported) + */ + + ivdbg("\nPC%d\n", priv->sample.contact); + + if (priv->sample.contact == CONTACT_NONE || + priv->sample.contact == CONTACT_UP) + + { + goto ignored; + } + + /* The pen is up. NOTE: We know from a previous test, that this is a + * loss of contact condition. This will be changed to CONTACT_NONE + * after the loss of contact is sampled. + */ + + priv->sample.contact = CONTACT_UP; + } + + /* It is a pen down event. If the last loss-of-contact event has not been + * processed yet, then we have to ignore the pen down event (or else it will + * look like a drag event) + */ + + else if (priv->sample.contact == CONTACT_UP) + { + /* If we have not yet processed the last pen up event, then we + * cannot handle this pen down event. We will have to discard it. That + * should be okay because we will set the timer to to sample again + * later. + */ + + ivdbg("Previous pen up event still in buffer\n"); + max11802_notify(priv); + wd_start(priv->wdog, MAX11802_WDOG_DELAY, max11802_wdog, 1, (uint32_t)priv); + goto ignored; + } + else + { + /* Wait for data ready */ + do { + /* Handle pen down events. First, sample positional values. */ + +#ifdef CONFIG_MAX11802_SWAPXY + x = max11802_sendcmd(priv, MAX11802_CMD_YPOSITION, &tags); + y = max11802_sendcmd(priv, MAX11802_CMD_XPOSITION, &tags2); +#else + x = max11802_sendcmd(priv, MAX11802_CMD_XPOSITION, &tags); + y = max11802_sendcmd(priv, MAX11802_CMD_YPOSITION, &tags2); +#endif + } while (tags == 0xF || tags2 == 0xF); + + /* Continue to sample the position while the pen is down */ + wd_start(priv->wdog, MAX11802_WDOG_DELAY, max11802_wdog, 1, (uint32_t)priv); + + /* Check if data is valid */ + if ((tags & 0x03) != 0) + { + ivdbg("Touch ended before measurement\n"); + goto ignored; + } + + /* Perform a thresholding operation so that the results will be more stable. + * If the difference from the last sample is small, then ignore the event. + * REVISIT: Should a large change in pressure also generate a event? + */ + + xdiff = x > priv->threshx ? (x - priv->threshx) : (priv->threshx - x); + ydiff = y > priv->threshy ? (y - priv->threshy) : (priv->threshy - y); + + /* Check the thresholds. Bail if there is no significant difference */ + + if (xdiff < CONFIG_MAX11802_THRESHX && ydiff < CONFIG_MAX11802_THRESHY) + { + /* Little or no change in either direction ... don't report anything. */ + + goto ignored; + } + + /* When we see a big difference, snap to the new x/y thresholds */ + + priv->threshx = x; + priv->threshy = y; + + /* Update the x/y position in the sample data */ + + priv->sample.x = priv->threshx; + priv->sample.y = priv->threshy; + + /* The X/Y positional data is now valid */ + + priv->sample.valid = true; + + /* If this is the first (acknowledged) pen down report, then report + * this as the first contact. If contact == CONTACT_DOWN, it will be + * set to set to CONTACT_MOVE after the contact is first sampled. + */ + + if (priv->sample.contact != CONTACT_MOVE) + { + /* First contact */ + + priv->sample.contact = CONTACT_DOWN; + } + } + + /* Indicate the availability of new sample data for this ID */ + + priv->sample.id = priv->id; + priv->penchange = true; + + /* Notify any waiters that new MAX11802 data is available */ + + max11802_notify(priv); + +ignored: + config->enable(config, true); + + /* Release our lock on the state structure and unlock the SPI bus */ + + sem_post(&priv->devsem); + max11802_unlock(priv->spi); +} + +/**************************************************************************** + * Name: max11802_interrupt + ****************************************************************************/ + +static int max11802_interrupt(int irq, FAR void *context) +{ + FAR struct max11802_dev_s *priv; + FAR struct max11802_config_s *config; + int ret; + + /* Which MAX11802 device caused the interrupt? */ + +#ifndef CONFIG_MAX11802_MULTIPLE + priv = &g_max11802; +#else + for (priv = g_max11802list; + priv && priv->configs->irq != irq; + priv = priv->flink); + + ASSERT(priv != NULL); +#endif + + /* Get a pointer the callbacks for convenience (and so the code is not so + * ugly). + */ + + config = priv->config; + DEBUGASSERT(config != NULL); + + /* Schedule sampling to occur on the worker thread */ + + ret = max11802_schedule(priv); + + /* Clear any pending interrupts and return success */ + + config->clear(config); + return ret; +} + +/**************************************************************************** + * Name: max11802_open + ****************************************************************************/ + +static int max11802_open(FAR struct file *filep) +{ +#ifdef CONFIG_MAX11802_REFCNT + FAR struct inode *inode; + FAR struct max11802_dev_s *priv; + uint8_t tmp; + int ret; + + ivdbg("Opening\n"); + + DEBUGASSERT(filep); + inode = filep->f_inode; + + DEBUGASSERT(inode && inode->i_private); + priv = (FAR struct max11802_dev_s *)inode->i_private; + + /* Get exclusive access to the driver data structure */ + + ret = sem_wait(&priv->devsem); + if (ret < 0) + { + /* This should only happen if the wait was canceled by an signal */ + + DEBUGASSERT(errno == EINTR); + return -EINTR; + } + + /* Increment the reference count */ + + tmp = priv->crefs + 1; + if (tmp == 0) + { + /* More than 255 opens; uint8_t overflows to zero */ + + ret = -EMFILE; + goto errout_with_sem; + } + + /* When the reference increments to 1, this is the first open event + * on the driver.. and an opportunity to do any one-time initialization. + */ + + /* Save the new open count on success */ + + priv->crefs = tmp; + +errout_with_sem: + sem_post(&priv->devsem); + return ret; +#else + ivdbg("Opening\n"); + return OK; +#endif +} + +/**************************************************************************** + * Name: max11802_close + ****************************************************************************/ + +static int max11802_close(FAR struct file *filep) +{ +#ifdef CONFIG_MAX11802_REFCNT + FAR struct inode *inode; + FAR struct max11802_dev_s *priv; + int ret; + + ivdbg("Closing\n"); + DEBUGASSERT(filep); + inode = filep->f_inode; + + DEBUGASSERT(inode && inode->i_private); + priv = (FAR struct max11802_dev_s *)inode->i_private; + + /* Get exclusive access to the driver data structure */ + + ret = sem_wait(&priv->devsem); + if (ret < 0) + { + /* This should only happen if the wait was canceled by an signal */ + + DEBUGASSERT(errno == EINTR); + return -EINTR; + } + + /* Decrement the reference count unless it would decrement a negative + * value. When the count decrements to zero, there are no further + * open references to the driver. + */ + + if (priv->crefs >= 1) + { + priv->crefs--; + } + + sem_post(&priv->devsem); +#endif + ivdbg("Closing\n"); + return OK; +} + +/**************************************************************************** + * Name: max11802_read + ****************************************************************************/ + +static ssize_t max11802_read(FAR struct file *filep, FAR char *buffer, size_t len) +{ + FAR struct inode *inode; + FAR struct max11802_dev_s *priv; + FAR struct touch_sample_s *report; + struct max11802_sample_s sample; + int ret; + + ivdbg("buffer:%p len:%d\n", buffer, len); + DEBUGASSERT(filep); + inode = filep->f_inode; + + DEBUGASSERT(inode && inode->i_private); + priv = (FAR struct max11802_dev_s *)inode->i_private; + + /* Verify that the caller has provided a buffer large enough to receive + * the touch data. + */ + + if (len < SIZEOF_TOUCH_SAMPLE_S(1)) + { + /* We could provide logic to break up a touch report into segments and + * handle smaller reads... but why? + */ + + idbg("Unsupported read size: %d\n", len); + return -ENOSYS; + } + + /* Get exclusive access to the driver data structure */ + + ret = sem_wait(&priv->devsem); + if (ret < 0) + { + /* This should only happen if the wait was canceled by an signal */ + + idbg("sem_wait: %d\n", errno); + DEBUGASSERT(errno == EINTR); + return -EINTR; + } + + /* Try to read sample data. */ + + ret = max11802_sample(priv, &sample); + if (ret < 0) + { + /* Sample data is not available now. We would ave to wait to get + * receive sample data. If the user has specified the O_NONBLOCK + * option, then just return an error. + */ + + ivdbg("Sample data is not available\n"); + if (filep->f_oflags & O_NONBLOCK) + { + ret = -EAGAIN; + goto errout; + } + + /* Wait for sample data */ + + ret = max11802_waitsample(priv, &sample); + if (ret < 0) + { + /* We might have been awakened by a signal */ + + idbg("max11802_waitsample: %d\n", ret); + goto errout; + } + } + + /* In any event, we now have sampled MAX11802 data that we can report + * to the caller. + */ + + report = (FAR struct touch_sample_s *)buffer; + memset(report, 0, SIZEOF_TOUCH_SAMPLE_S(1)); + report->npoints = 1; + report->point[0].id = sample.id; + report->point[0].x = sample.x; + report->point[0].y = sample.y; + + /* Report the appropriate flags */ + + if (sample.contact == CONTACT_UP) + { + /* Pen is now up. Is the positional data valid? This is important to + * know because the release will be sent to the window based on its + * last positional data. + */ + + if (sample.valid) + { + report->point[0].flags = TOUCH_UP | TOUCH_ID_VALID | TOUCH_POS_VALID; + } + else + { + report->point[0].flags = TOUCH_UP | TOUCH_ID_VALID; + } + } + else if (sample.contact == CONTACT_DOWN) + { + /* First contact */ + + report->point[0].flags = TOUCH_DOWN | TOUCH_ID_VALID | TOUCH_POS_VALID; + } + else /* if (sample->contact == CONTACT_MOVE) */ + { + /* Movement of the same contact */ + + report->point[0].flags = TOUCH_MOVE | TOUCH_ID_VALID | TOUCH_POS_VALID; + } + + ivdbg(" id: %d\n", report->point[0].id); + ivdbg(" flags: %02x\n", report->point[0].flags); + ivdbg(" x: %d\n", report->point[0].x); + ivdbg(" y: %d\n", report->point[0].y); + + ret = SIZEOF_TOUCH_SAMPLE_S(1); + +errout: + sem_post(&priv->devsem); + ivdbg("Returning: %d\n", ret); + return ret; +} + +/**************************************************************************** + * Name:max11802_ioctl + ****************************************************************************/ + +static int max11802_ioctl(FAR struct file *filep, int cmd, unsigned long arg) +{ + FAR struct inode *inode; + FAR struct max11802_dev_s *priv; + int ret; + + ivdbg("cmd: %d arg: %ld\n", cmd, arg); + DEBUGASSERT(filep); + inode = filep->f_inode; + + DEBUGASSERT(inode && inode->i_private); + priv = (FAR struct max11802_dev_s *)inode->i_private; + + /* Get exclusive access to the driver data structure */ + + ret = sem_wait(&priv->devsem); + if (ret < 0) + { + /* This should only happen if the wait was canceled by an signal */ + + DEBUGASSERT(errno == EINTR); + return -EINTR; + } + + /* Process the IOCTL by command */ + + switch (cmd) + { + case TSIOC_SETFREQUENCY: /* arg: Pointer to uint32_t frequency value */ + { + FAR uint32_t *ptr = (FAR uint32_t *)((uintptr_t)arg); + DEBUGASSERT(priv->config != NULL && ptr != NULL); + priv->config->frequency = SPI_SETFREQUENCY(priv->spi, *ptr); + } + break; + + case TSIOC_GETFREQUENCY: /* arg: Pointer to uint32_t frequency value */ + { + FAR uint32_t *ptr = (FAR uint32_t *)((uintptr_t)arg); + DEBUGASSERT(priv->config != NULL && ptr != NULL); + *ptr = priv->config->frequency; + } + break; + + default: + ret = -ENOTTY; + break; + } + + sem_post(&priv->devsem); + return ret; +} + +/**************************************************************************** + * Name: max11802_poll + ****************************************************************************/ + +#ifndef CONFIG_DISABLE_POLL +static int max11802_poll(FAR struct file *filep, FAR struct pollfd *fds, + bool setup) +{ + FAR struct inode *inode; + FAR struct max11802_dev_s *priv; + pollevent_t eventset; + int ndx; + int ret = OK; + int i; + + ivdbg("setup: %d\n", (int)setup); + DEBUGASSERT(filep && fds); + inode = filep->f_inode; + + DEBUGASSERT(inode && inode->i_private); + priv = (FAR struct max11802_dev_s *)inode->i_private; + + /* Are we setting up the poll? Or tearing it down? */ + + ret = sem_wait(&priv->devsem); + if (ret < 0) + { + /* This should only happen if the wait was canceled by an signal */ + + DEBUGASSERT(errno == EINTR); + return -EINTR; + } + + if (setup) + { + /* Ignore waits that do not include POLLIN */ + + if ((fds->events & POLLIN) == 0) + { + ret = -EDEADLK; + goto errout; + } + + /* This is a request to set up the poll. Find an available + * slot for the poll structure reference + */ + + for (i = 0; i < CONFIG_MAX11802_NPOLLWAITERS; i++) + { + /* Find an available slot */ + + if (!priv->fds[i]) + { + /* Bind the poll structure and this slot */ + + priv->fds[i] = fds; + fds->priv = &priv->fds[i]; + break; + } + } + + if (i >= CONFIG_MAX11802_NPOLLWAITERS) + { + fds->priv = NULL; + ret = -EBUSY; + goto errout; + } + + /* Should we immediately notify on any of the requested events? */ + + if (priv->penchange) + { + max11802_notify(priv); + } + } + else if (fds->priv) + { + /* This is a request to tear down the poll. */ + + struct pollfd **slot = (struct pollfd **)fds->priv; + DEBUGASSERT(slot != NULL); + + /* Remove all memory of the poll setup */ + + *slot = NULL; + fds->priv = NULL; + } + +errout: + sem_post(&priv->devsem); + return ret; +} +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: max11802_register + * + * Description: + * Configure the MAX11802 to use the provided SPI device instance. This + * will register the driver as /dev/inputN where N is the minor device + * number + * + * Input Parameters: + * dev - An SPI driver instance + * config - Persistent board configuration data + * minor - The input device minor number + * + * Returned Value: + * Zero is returned on success. Otherwise, a negated errno value is + * returned to indicate the nature of the failure. + * + ****************************************************************************/ + +int max11802_register(FAR struct spi_dev_s *spi, + FAR struct max11802_config_s *config, int minor) +{ + FAR struct max11802_dev_s *priv; + char devname[DEV_NAMELEN]; +#ifdef CONFIG_MAX11802_MULTIPLE + irqstate_t flags; +#endif + int ret; + + ivdbg("spi: %p minor: %d\n", spi, minor); + + /* Debug-only sanity checks */ + + DEBUGASSERT(spi != NULL && config != NULL && minor >= 0 && minor < 100); + + /* Create and initialize a MAX11802 device driver instance */ + +#ifndef CONFIG_MAX11802_MULTIPLE + priv = &g_max11802; +#else + priv = (FAR struct max11802_dev_s *)kmalloc(sizeof(struct max11802_dev_s)); + if (!priv) + { + idbg("kmalloc(%d) failed\n", sizeof(struct max11802_dev_s)); + return -ENOMEM; + } +#endif + + /* Initialize the MAX11802 device driver instance */ + + memset(priv, 0, sizeof(struct max11802_dev_s)); + priv->spi = spi; /* Save the SPI device handle */ + priv->config = config; /* Save the board configuration */ + priv->wdog = wd_create(); /* Create a watchdog timer */ + priv->threshx = INVALID_THRESHOLD; /* Initialize thresholding logic */ + priv->threshy = INVALID_THRESHOLD; /* Initialize thresholding logic */ + + sem_init(&priv->devsem, 0, 1); /* Initialize device structure semaphore */ + sem_init(&priv->waitsem, 0, 0); /* Initialize pen event wait semaphore */ + + /* Make sure that interrupts are disabled */ + + config->clear(config); + config->enable(config, false); + + /* Attach the interrupt handler */ + + ret = config->attach(config, max11802_interrupt); + if (ret < 0) + { + idbg("Failed to attach interrupt\n"); + goto errout_with_priv; + } + + idbg("Mode: %d Bits: 8 Frequency: %d\n", + CONFIG_MAX11802_SPIMODE, CONFIG_MAX11802_FREQUENCY); + + /* Lock the SPI bus so that we have exclusive access */ + + max11802_lock(spi); + + /* Configure the SPI interface */ + + max11802_configspi(spi); + + /* Configure MAX11802 registers */ + SPI_SELECT(priv->spi, SPIDEV_TOUCHSCREEN, true); + (void)SPI_SEND(priv->spi, MAX11802_CMD_MODE_WR); + (void)SPI_SEND(priv->spi, MAX11802_MODE); + SPI_SELECT(priv->spi, SPIDEV_TOUCHSCREEN, false); + + SPI_SELECT(priv->spi, SPIDEV_TOUCHSCREEN, true); + (void)SPI_SEND(priv->spi, MAX11802_CMD_AVG_WR); + (void)SPI_SEND(priv->spi, MAX11802_AVG); + SPI_SELECT(priv->spi, SPIDEV_TOUCHSCREEN, false); + + SPI_SELECT(priv->spi, SPIDEV_TOUCHSCREEN, true); + (void)SPI_SEND(priv->spi, MAX11802_CMD_TIMING_WR); + (void)SPI_SEND(priv->spi, MAX11802_TIMING); + SPI_SELECT(priv->spi, SPIDEV_TOUCHSCREEN, false); + + SPI_SELECT(priv->spi, SPIDEV_TOUCHSCREEN, true); + (void)SPI_SEND(priv->spi, MAX11802_CMD_DELAY_WR); + (void)SPI_SEND(priv->spi, MAX11802_DELAY); + SPI_SELECT(priv->spi, SPIDEV_TOUCHSCREEN, false); + + /* Test that the device access was successful. */ + SPI_SELECT(priv->spi, SPIDEV_TOUCHSCREEN, true); + (void)SPI_SEND(priv->spi, MAX11802_CMD_MODE_RD); + ret = SPI_SEND(priv->spi, 0); + SPI_SELECT(priv->spi, SPIDEV_TOUCHSCREEN, false); + + /* Unlock the bus */ + max11802_unlock(spi); + + if (ret != MAX11802_MODE) + { + idbg("max11802 mode readback failed: %02x\n", ret); + goto errout_with_priv; + } + + /* Register the device as an input device */ + + (void)snprintf(devname, DEV_NAMELEN, DEV_FORMAT, minor); + ivdbg("Registering %s\n", devname); + + ret = register_driver(devname, &max11802_fops, 0666, priv); + if (ret < 0) + { + idbg("register_driver() failed: %d\n", ret); + goto errout_with_priv; + } + + /* If multiple MAX11802 devices are supported, then we will need to add + * this new instance to a list of device instances so that it can be + * found by the interrupt handler based on the recieved IRQ number. + */ + +#ifdef CONFIG_MAX11802_MULTIPLE + priv->flink = g_max11802list; + g_max11802list = priv; + irqrestore(flags); +#endif + + /* Schedule work to perform the initial sampling and to set the data + * availability conditions. + */ + + ret = work_queue(HPWORK, &priv->work, max11802_worker, priv, 0); + if (ret != 0) + { + idbg("Failed to queue work: %d\n", ret); + goto errout_with_priv; + } + + /* And return success (?) */ + + return OK; + +errout_with_priv: + sem_destroy(&priv->devsem); +#ifdef CONFIG_MAX11802_MULTIPLE + kfree(priv); +#endif + return ret; +} diff --git a/nuttx/drivers/input/max11802.h b/nuttx/drivers/input/max11802.h new file mode 100644 index 000000000..b6beec045 --- /dev/null +++ b/nuttx/drivers/input/max11802.h @@ -0,0 +1,167 @@ +/******************************************************************************************** + * drivers/input/max11802.h + * + * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. + * Authors: Gregory Nutt + * Petteri Aimonen + * + * References: + * "Low-Power, Ultra-Small Resistive Touch-Screen Controllers + * with I2C/SPI Interface" Maxim IC, Rev 3, 10/2010 + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ********************************************************************************************/ + +#ifndef __DRIVERS_INPUT_MAX11802_H +#define __DRIVERS_INPUT_MAX11802_H + +/******************************************************************************************** + * Included Files + ********************************************************************************************/ + +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +/******************************************************************************************** + * Pre-Processor Definitions + ********************************************************************************************/ +/* Configuration ****************************************************************************/ + +/* MAX11802 Interfaces *********************************************************************/ + +/* LSB of register addresses specifies read (1) or write (0). */ +#define MAX11802_CMD_XPOSITION ((0x52 << 1) | 1) +#define MAX11802_CMD_YPOSITION ((0x54 << 1) | 1) +#define MAX11802_CMD_MEASUREXY (0x70 << 1) +#define MAX11802_CMD_MODE_WR (0x0B << 1) +#define MAX11802_CMD_MODE_RD ((0x0B << 1) | 1) +#define MAX11802_CMD_AVG_WR (0x03 << 1) +#define MAX11802_CMD_TIMING_WR (0x05 << 1) +#define MAX11802_CMD_DELAY_WR (0x06 << 1) + +/* Register values to set */ +#define MAX11802_MODE 0x0E +#define MAX11802_AVG 0x55 +#define MAX11802_TIMING 0x77 +#define MAX11802_DELAY 0x55 + +/* Driver support **************************************************************************/ +/* This format is used to construct the /dev/input[n] device driver path. It + * defined here so that it will be used consistently in all places. + */ + +#define DEV_FORMAT "/dev/input%d" +#define DEV_NAMELEN 16 + +/* Poll the pen position while the pen is down at this rate (50MS): */ + +#define MAX11802_WDOG_DELAY ((50 + (MSEC_PER_TICK-1))/ MSEC_PER_TICK) + +/******************************************************************************************** + * Public Types + ********************************************************************************************/ + +/* This describes the state of one contact */ + +enum max11802_contact_3 +{ + CONTACT_NONE = 0, /* No contact */ + CONTACT_DOWN, /* First contact */ + CONTACT_MOVE, /* Same contact, possibly different position */ + CONTACT_UP, /* Contact lost */ +}; + +/* This structure describes the results of one MAX11802 sample */ + +struct max11802_sample_s +{ + uint8_t id; /* Sampled touch point ID */ + uint8_t contact; /* Contact state (see enum ads7843e_contact_e) */ + bool valid; /* True: x,y contain valid, sampled data */ + uint16_t x; /* Measured X position */ + uint16_t y; /* Measured Y position */ +}; + +/* This structure describes the state of one MAX11802 driver instance */ + +struct max11802_dev_s +{ +#ifdef CONFIG_ADS7843E_MULTIPLE + FAR struct ads7843e_dev_s *flink; /* Supports a singly linked list of drivers */ +#endif + uint8_t nwaiters; /* Number of threads waiting for MAX11802 data */ + uint8_t id; /* Current touch point ID */ + volatile bool penchange; /* An unreported event is buffered */ + uint16_t threshx; /* Thresholding X value */ + uint16_t threshy; /* Thresholding Y value */ + sem_t devsem; /* Manages exclusive access to this structure */ + sem_t waitsem; /* Used to wait for the availability of data */ + + FAR struct max11802_config_s *config; /* Board configuration data */ + FAR struct spi_dev_s *spi; /* Saved SPI driver instance */ + struct work_s work; /* Supports the interrupt handling "bottom half" */ + struct max11802_sample_s sample; /* Last sampled touch point data */ + WDOG_ID wdog; /* Poll the position while the pen is down */ + + /* The following is a list if poll structures of threads waiting for + * driver events. The 'struct pollfd' reference for each open is also + * retained in the f_priv field of the 'struct file'. + */ + +#ifndef CONFIG_DISABLE_POLL + struct pollfd *fds[CONFIG_ADS7843E_NPOLLWAITERS]; +#endif +}; + +/******************************************************************************************** + * Public Function Prototypes + ********************************************************************************************/ + +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" { +#else +#define EXTERN extern +#endif + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif /* __DRIVERS_INPUT_ADS7843E_H */ diff --git a/nuttx/drivers/lcd/Kconfig b/nuttx/drivers/lcd/Kconfig index 640239e63..2d20003ac 100644 --- a/nuttx/drivers/lcd/Kconfig +++ b/nuttx/drivers/lcd/Kconfig @@ -183,12 +183,85 @@ config NOKIA6100_RGBORD endif config LCD_UG9664HSWAG01 - bool "9664HSWAG01 OLED Display Module" + bool "UG-9664HSWAG01 OLED Display Module" default n ---help--- - ug-9664hswag01.c. OLED Display Module, UG-9664HSWAG01", Univision - Technology Inc. Used with the LPC Xpresso and Embedded Artists - base board. + OLED Display Module, UG-9664HSWAG01, Univision Technology Inc. Used + with the LPCXpresso and Embedded Artists base board. + + Required LCD driver settings: + LCD_MAXCONTRAST should be 255, but any value >0 and <=255 will be accepted. + LCD_MAXPOWER should be 1: 0=off, 1=on + + Required SPI driver settings: + SPI_CMDDATA - Include support for cmd/data selection. + +if LCD_UG9664HSWAG01 + +config UG9664HSWAG01_SPIMODE + int "UG-9664HSWAG01 SPI Mode" + default 0 + ---help--- + Controls the SPI mode + +config UG9664HSWAG01_FREQUENCY + int "UG-9664HSWAG01 SPI Frequency" + default 3500000 + ---help--- + Define to use a different bus frequency + +config UG9664HSWAG01_NINTERFACES + int "Number of UG-9664HSWAG01 Devices" + default 1 + ---help--- + Specifies the number of physical UG-9664HSWAG01 devices that will be + supported. NOTE: At present, this must be undefined or defined to be 1. + +config UG9664HSWAG01_POWER + bool "Power control" + default n + ---help--- + If the hardware supports a controllable OLED a power supply, this + configuration should be defined. In this case the system must + provide an interface ug_power(). + +endif + +config LCD_UG2864AMBAG01 + bool "UG-2864AMBAG01 OLED Display Module" + default n + ---help--- + OLED Display Module, UG-2864AMBAG01, Univision Technology Inc. + + Required LCD driver settings: + LCD_MAXCONTRAST should be 255, but any value >0 and <=255 will be accepted. + LCD_MAXPOWER should be 1: 0=off, 1=on + + Required SPI driver settings: + SPI_CMDDATA - Include support for cmd/data selection. + +if LCD_UG2864AMBAG01 + + config UG2864AMBAG01_SPIMODE + int "UG-2864AMBAG01 SPI Mode" + default 3 + ---help--- + Controls the SPI mode + +config UG2864AMBAG01_FREQUENCY + int "UG-2864AMBAG01 SPI Frequency" + default 3500000 + ---help--- + Define to use a different bus frequency + +config UG2864AMBAG01_NINTERFACES + int "Number of UG-2864AMBAG01 Devices" + default 1 + ---help--- + Specifies the number of physical UG-9664HSWAG01 devices that will be + supported. NOTE: At present, this must be undefined or defined to be 1. + +endif config LCD_SSD1289 bool "LCD Based on SSD1289 Controller" diff --git a/nuttx/drivers/lcd/ug-9664hswag01.c b/nuttx/drivers/lcd/ug-9664hswag01.c index e0e8e8e3a..6ef78fca6 100644 --- a/nuttx/drivers/lcd/ug-9664hswag01.c +++ b/nuttx/drivers/lcd/ug-9664hswag01.c @@ -73,8 +73,6 @@ * CONFIG_UG9664HSWAG01_POWER * If the hardware supports a controllable OLED a power supply, this * configuration shold be defined. (See ug_power() below). - * CONFIG_LCD_UGDEBUG - Enable detailed UG-9664HSWAG01 debug output - * (CONFIG_DEBUG and CONFIG_VERBOSE must also be enabled). * * Required LCD driver settings: * CONFIG_LCD_UG9664HSWAG01 - Enable UG-9664HSWAG01 support @@ -119,11 +117,10 @@ #ifndef CONFIG_DEBUG # undef CONFIG_DEBUG_VERBOSE -# undef CONFIG_DEBUG_GRAPHICS #endif #ifndef CONFIG_DEBUG_VERBOSE -# undef CONFIG_LCD_UGDEBUG +# undef CONFIG_DEBUG_LCD #endif /* Check contrast selection */ @@ -182,7 +179,7 @@ #define UG_BPP 1 #define UG_COLORFMT FB_FMT_Y1 -/* Bytes per logical row andactual device row */ +/* Bytes per logical row and actual device row */ #define UG_XSTRIDE (UG_XRES >> 3) /* Pixels arrange "horizontally for user" */ #define UG_YSTRIDE (UG_YRES >> 3) /* But actual device arrangement is "vertical" */ @@ -198,10 +195,10 @@ /* Debug ******************************************************************************/ -#ifdef CONFIG_LCD_UGDEBUG -# define ugdbg(format, arg...) vdbg(format, ##arg) +#ifdef CONFIG_DEBUG_LCD +# define lcddbg(format, arg...) vdbg(format, ##arg) #else -# define ugdbg(x...) +# define lcddbg(x...) #endif /************************************************************************************** @@ -997,7 +994,7 @@ FAR struct lcd_dev_s *ug_initialize(FAR struct spi_dev_s *spi, unsigned int devn SPI_CMDDATA(spi, SPIDEV_DISPLAY, true); - /* Set the starting position for the run */ + /* Configure the device */ (void)SPI_SEND(spi, SSD1305_SETCOLL + 2); /* Set low column address */ (void)SPI_SEND(spi, SSD1305_SETCOLH + 2); /* Set high column address */ diff --git a/nuttx/drivers/mmcsd/mmcsd_sdio.c b/nuttx/drivers/mmcsd/mmcsd_sdio.c index b17ae077d..3caa61583 100644 --- a/nuttx/drivers/mmcsd/mmcsd_sdio.c +++ b/nuttx/drivers/mmcsd/mmcsd_sdio.c @@ -38,6 +38,9 @@ ****************************************************************************/ #include + +#if defined (CONFIG_MMCSD) && defined (CONFIG_MMCSD_SDIO) + #include #include @@ -3179,3 +3182,5 @@ errout_with_alloc: kfree(priv); return ret; } + +#endif /* defined (CONFIG_MMCSD) && defined (CONFIG_MMCSD_SDIO) */ diff --git a/nuttx/drivers/mmcsd/mmcsd_spi.c b/nuttx/drivers/mmcsd/mmcsd_spi.c index 7dbadc55f..d437b7fea 100644 --- a/nuttx/drivers/mmcsd/mmcsd_spi.c +++ b/nuttx/drivers/mmcsd/mmcsd_spi.c @@ -38,6 +38,9 @@ ****************************************************************************/ #include + +#if defined (CONFIG_MMCSD) && defined (CONFIG_MMCSD_SPI) + #include #include @@ -508,7 +511,7 @@ static uint32_t mmcsd_sendcmd(FAR struct mmcsd_slot_s *slot, } break; - /* The R3 response is 5 bytes long */ + /* The R3 response is 5 bytes long. The first byte is identical to R1. */ case MMCSD_CMDRESP_R3: { @@ -520,8 +523,10 @@ static uint32_t mmcsd_sendcmd(FAR struct mmcsd_slot_s *slot, fvdbg("CMD%d[%08x] R1=%02x OCR=%08x\n", cmd->cmd & 0x3f, arg, response, slot->ocr); } + break; + + /* The R7 response is 5 bytes long. The first byte is identical to R1. */ - /* The R7 response is 5 bytes long */ case MMCSD_CMDRESP_R7: default: { @@ -1876,3 +1881,5 @@ int mmcsd_spislotinitialize(int minor, int slotno, FAR struct spi_dev_s *spi) (void)SPI_REGISTERCALLBACK(spi, mmcsd_mediachanged, (void*)slot); return OK; } + +#endif /* defined (CONFIG_MMCSD) && defined (CONFIG_MMCSD_SPI) */ diff --git a/nuttx/drivers/net/e1000.c b/nuttx/drivers/net/e1000.c index ec2b29b6a..cae6f39b4 100644 --- a/nuttx/drivers/net/e1000.c +++ b/nuttx/drivers/net/e1000.c @@ -60,6 +60,7 @@ #include #include #include +#include #include #include #include "e1000.h" @@ -104,9 +105,9 @@ struct e1000_dev { uint32_t io_mem_base; uint32_t mem_size; int pci_dev_id; + uint16_t pci_addr; unsigned char src_mac[6]; unsigned char dst_mac[6]; - int irq; struct irq_action int_desc; struct tx_ring tx_ring; struct rx_ring rx_ring; @@ -308,16 +309,16 @@ void e1000_init(struct e1000_dev *dev) e1000_outl(dev, E1000_FCRTH, pba*9/10); // setup tx rings - txd_phys = PADDR(dev->tx_ring.desc); - kmem_phys = PADDR(dev->tx_ring.buf); + txd_phys = PADDR((uintptr_t)dev->tx_ring.desc); + kmem_phys = PADDR((uintptr_t)dev->tx_ring.buf); for (i=0; itx_ring.desc[i].base_address = kmem_phys; - dev->tx_ring.desc[i].packet_length = 0; - dev->tx_ring.desc[i].cksum_offset = 0; - dev->tx_ring.desc[i].cksum_origin = 0; - dev->tx_ring.desc[i].desc_status = 1; - dev->tx_ring.desc[i].desc_command = (1<<0)|(1<<1)|(1<<3); - dev->tx_ring.desc[i].special_info = 0; + dev->tx_ring.desc[i].base_address = kmem_phys; + dev->tx_ring.desc[i].packet_length = 0; + dev->tx_ring.desc[i].cksum_offset = 0; + dev->tx_ring.desc[i].cksum_origin = 0; + dev->tx_ring.desc[i].desc_status = 1; + dev->tx_ring.desc[i].desc_command = (1<<0)|(1<<1)|(1<<3); + dev->tx_ring.desc[i].special_info = 0; } dev->tx_ring.tail = 0; e1000_outl(dev, E1000_TDT, 0); @@ -329,15 +330,15 @@ void e1000_init(struct e1000_dev *dev) e1000_outl(dev, E1000_TXDCTL, 0x01010000); // setup rx rings - rxd_phys = PADDR(dev->rx_ring.desc); - kmem_phys = PADDR(dev->rx_ring.buf); + rxd_phys = PADDR((uintptr_t)dev->rx_ring.desc); + kmem_phys = PADDR((uintptr_t)dev->rx_ring.buf); for (i=0; irx_ring.desc[i].base_address = kmem_phys; - dev->rx_ring.desc[i].packet_length = 0; - dev->rx_ring.desc[i].packet_cksum = 0; - dev->rx_ring.desc[i].desc_status = 0; - dev->rx_ring.desc[i].desc_errors = 0; - dev->rx_ring.desc[i].vlan_tag = 0; + dev->rx_ring.desc[i].base_address = kmem_phys; + dev->rx_ring.desc[i].packet_length = 0; + dev->rx_ring.desc[i].packet_cksum = 0; + dev->rx_ring.desc[i].desc_status = 0; + dev->rx_ring.desc[i].desc_errors = 0; + dev->rx_ring.desc[i].vlan_tag = 0; } dev->rx_ring.head = 0; dev->rx_ring.tail = CONFIG_E1000_N_RX_DESC-1; @@ -378,7 +379,7 @@ static int e1000_transmit(struct e1000_dev *e1000) { int tail = e1000->tx_ring.tail; unsigned char *cp = (unsigned char *) - (e1000->tx_ring.buf + tail * CONFIG_E1000_BUFF_SIZE); + (e1000->tx_ring.buf + tail * CONFIG_E1000_BUFF_SIZE); int count = e1000->uip_dev.d_len; /* Verify that the hardware is ready to send another packet. If we get @@ -387,7 +388,7 @@ static int e1000_transmit(struct e1000_dev *e1000) */ if (!e1000->tx_ring.desc[tail].desc_status) - return -1; + return -1; /* Increment statistics */ @@ -445,14 +446,14 @@ static int e1000_uiptxpoll(struct uip_driver_s *dev) */ if (e1000->uip_dev.d_len > 0) { - uip_arp_out(&e1000->uip_dev); - e1000_transmit(e1000); - - /* Check if there is room in the device to hold another packet. If not, - * return a non-zero value to terminate the poll. - */ - if (!e1000->tx_ring.desc[tail].desc_status) - return -1; + uip_arp_out(&e1000->uip_dev); + e1000_transmit(e1000); + + /* Check if there is room in the device to hold another packet. If not, + * return a non-zero value to terminate the poll. + */ + if (!e1000->tx_ring.desc[tail].desc_status) + return -1; } /* If zero is returned, the polling will continue until all connections have @@ -483,75 +484,75 @@ static void e1000_receive(struct e1000_dev *e1000) { int head = e1000->rx_ring.head; unsigned char *cp = (unsigned char *) - (e1000->rx_ring.buf + head * CONFIG_E1000_BUFF_SIZE); + (e1000->rx_ring.buf + head * CONFIG_E1000_BUFF_SIZE); int cnt; while (e1000->rx_ring.desc[head].desc_status) { - /* Check for errors and update statistics */ + /* Check for errors and update statistics */ - // Here we do not handle packets that exceed packet-buffer size - if ((e1000->rx_ring.desc[head].desc_status & 3) == 1) { - cprintf("NIC READ: Oversized packet\n"); - goto next; - } + // Here we do not handle packets that exceed packet-buffer size + if ((e1000->rx_ring.desc[head].desc_status & 3) == 1) { + cprintf("NIC READ: Oversized packet\n"); + goto next; + } - /* Check if the packet is a valid size for the uIP buffer configuration */ + /* Check if the packet is a valid size for the uIP buffer configuration */ - // get the number of actual data-bytes in this packet - cnt = e1000->rx_ring.desc[head].packet_length; + // get the number of actual data-bytes in this packet + cnt = e1000->rx_ring.desc[head].packet_length; - if (cnt > CONFIG_NET_BUFSIZE || cnt < 14) { - cprintf("NIC READ: invalid package size\n"); - goto next; - } + if (cnt > CONFIG_NET_BUFSIZE || cnt < 14) { + cprintf("NIC READ: invalid package size\n"); + goto next; + } - /* Copy the data data from the hardware to e1000->uip_dev.d_buf. Set - * amount of data in e1000->uip_dev.d_len - */ + /* Copy the data data from the hardware to e1000->uip_dev.d_buf. Set + * amount of data in e1000->uip_dev.d_len + */ - // now we try to copy these data-bytes to the UIP buffer - memcpy(e1000->uip_dev.d_buf, cp, cnt); - e1000->uip_dev.d_len = cnt; + // now we try to copy these data-bytes to the UIP buffer + memcpy(e1000->uip_dev.d_buf, cp, cnt); + e1000->uip_dev.d_len = cnt; - /* We only accept IP packets of the configured type and ARP packets */ + /* We only accept IP packets of the configured type and ARP packets */ #ifdef CONFIG_NET_IPv6 - if (BUF->type == HTONS(UIP_ETHTYPE_IP6)) + if (BUF->type == HTONS(UIP_ETHTYPE_IP6)) #else - if (BUF->type == HTONS(UIP_ETHTYPE_IP)) + if (BUF->type == HTONS(UIP_ETHTYPE_IP)) #endif - { - uip_arp_ipin(&e1000->uip_dev); - uip_input(&e1000->uip_dev); - - /* If the above function invocation resulted in data that should be - * sent out on the network, the field d_len will set to a value > 0. - */ - - if (e1000->uip_dev.d_len > 0) { - uip_arp_out(&e1000->uip_dev); - e1000_transmit(e1000); - } - } - else if (BUF->type == htons(UIP_ETHTYPE_ARP)) { - uip_arp_arpin(&e1000->uip_dev); - - /* If the above function invocation resulted in data that should be - * sent out on the network, the field d_len will set to a value > 0. - */ - - if (e1000->uip_dev.d_len > 0) { - e1000_transmit(e1000); - } - } + { + uip_arp_ipin(&e1000->uip_dev); + uip_input(&e1000->uip_dev); + + /* If the above function invocation resulted in data that should be + * sent out on the network, the field d_len will set to a value > 0. + */ + + if (e1000->uip_dev.d_len > 0) { + uip_arp_out(&e1000->uip_dev); + e1000_transmit(e1000); + } + } + else if (BUF->type == htons(UIP_ETHTYPE_ARP)) { + uip_arp_arpin(&e1000->uip_dev); + + /* If the above function invocation resulted in data that should be + * sent out on the network, the field d_len will set to a value > 0. + */ + + if (e1000->uip_dev.d_len > 0) { + e1000_transmit(e1000); + } + } next: - e1000->rx_ring.desc[head].desc_status = 0; - e1000->rx_ring.head = (head + 1) % CONFIG_E1000_N_RX_DESC; - e1000->rx_ring.free++; - head = e1000->rx_ring.head; - cp = (unsigned char *)(e1000->rx_ring.buf + head * CONFIG_E1000_BUFF_SIZE); + e1000->rx_ring.desc[head].desc_status = 0; + e1000->rx_ring.head = (head + 1) % CONFIG_E1000_N_RX_DESC; + e1000->rx_ring.free++; + head = e1000->rx_ring.head; + cp = (unsigned char *)(e1000->rx_ring.buf + head * CONFIG_E1000_BUFF_SIZE); } } @@ -615,7 +616,7 @@ static void e1000_polltimer(int argc, uint32_t arg, ...) * the TX poll if he are unable to accept another packet for transmission. */ if (!e1000->tx_ring.desc[tail].desc_status) - return; + return; /* If so, update TCP timing states and poll uIP for new XMIT data. Hmmm.. * might be bug here. Does this mean if there is a transmit in progress, @@ -651,8 +652,8 @@ static int e1000_ifup(struct uip_driver_s *dev) struct e1000_dev *e1000 = (struct e1000_dev *)dev->d_private; ndbg("Bringing up: %d.%d.%d.%d\n", - dev->d_ipaddr & 0xff, (dev->d_ipaddr >> 8) & 0xff, - (dev->d_ipaddr >> 16) & 0xff, dev->d_ipaddr >> 24 ); + dev->d_ipaddr & 0xff, (dev->d_ipaddr >> 8) & 0xff, + (dev->d_ipaddr >> 16) & 0xff, dev->d_ipaddr >> 24 ); /* Initialize PHYs, the Ethernet interface, and setup up Ethernet interrupts */ e1000_init(e1000); @@ -662,9 +663,9 @@ static int e1000_ifup(struct uip_driver_s *dev) (void)wd_start(e1000->txpoll, E1000_WDDELAY, e1000_polltimer, 1, (uint32_t)e1000); if (e1000_inl(e1000, E1000_STATUS) & 2) - e1000->bifup = true; + e1000->bifup = true; else - e1000->bifup = false; + e1000->bifup = false; return OK; } @@ -749,9 +750,9 @@ static int e1000_txavail(struct uip_driver_s *dev) /* Ignore the notification if the interface is not yet up */ if (e1000->bifup) { - /* Check if there is room in the hardware to hold another outgoing packet. */ - if (e1000->tx_ring.desc[tail].desc_status) - (void)uip_poll(&e1000->uip_dev, e1000_uiptxpoll); + /* Check if there is room in the hardware to hold another outgoing packet. */ + if (e1000->tx_ring.desc[tail].desc_status) + (void)uip_poll(&e1000->uip_dev, e1000_uiptxpoll); } irqrestore(flags); @@ -779,11 +780,11 @@ static int e1000_txavail(struct uip_driver_s *dev) #ifdef CONFIG_NET_IGMP static int e1000_addmac(struct uip_driver_s *dev, const uint8_t *mac) { - struct e1000_dev *e1000 = (struct e1000_dev *)dev->d_private; + struct e1000_dev *e1000 = (struct e1000_dev *)dev->d_private; - /* Add the MAC address to the hardware multicast routing table */ + /* Add the MAC address to the hardware multicast routing table */ - return OK; + return OK; } #endif @@ -808,15 +809,15 @@ static int e1000_addmac(struct uip_driver_s *dev, const uint8_t *mac) #ifdef CONFIG_NET_IGMP static int e1000_rmmac(struct uip_driver_s *dev, const uint8_t *mac) { - struct e1000_dev *e1000 = (struct e1000_dev *)dev->d_private; + struct e1000_dev *e1000 = (struct e1000_dev *)dev->d_private; - /* Add the MAC address to the hardware multicast routing table */ + /* Add the MAC address to the hardware multicast routing table */ - return OK; + return OK; } #endif -irqreturn_t e1000_interrupt_handler(struct Trapframe *tf, void *dev_id) +static irqreturn_t e1000_interrupt_handler(int irq, void *dev_id) { struct e1000_dev *e1000 = (struct e1000_dev *)dev_id; @@ -826,27 +827,27 @@ irqreturn_t e1000_interrupt_handler(struct Trapframe *tf, void *dev_id) // not for me if (intr_cause == 0) - return IRQ_NONE; + return IRQ_NONE; /* Handle interrupts according to status bit settings */ // Link status change if (intr_cause & (1<<2)) { - if (e1000_inl(e1000, E1000_STATUS) & 2) - e1000->bifup = true; - else - e1000->bifup = false; + if (e1000_inl(e1000, E1000_STATUS) & 2) + e1000->bifup = true; + else + e1000->bifup = false; } /* Check if we received an incoming packet, if so, call skel_receive() */ // Rx-descriptor Timer expired if (intr_cause & (1<<7)) - e1000_receive(e1000); + e1000_receive(e1000); // Tx queue empty if (intr_cause & (1<<1)) - wd_cancel(e1000->txtimeout); + wd_cancel(e1000->txtimeout); /* Check is a packet transmission just completed. If so, call skel_txdone. * This may disable further Tx interrupts if there are no pending @@ -855,17 +856,17 @@ irqreturn_t e1000_interrupt_handler(struct Trapframe *tf, void *dev_id) // Tx-descriptor Written back if (intr_cause & (1<<0)) - uip_poll(&e1000->uip_dev, e1000_uiptxpoll); + uip_poll(&e1000->uip_dev, e1000_uiptxpoll); // Rx-Descriptors Low if (intr_cause & (1<<4)) { - int tail; - tail = e1000->rx_ring.tail + e1000->rx_ring.free; - tail %= CONFIG_E1000_N_RX_DESC; - e1000->rx_ring.tail = tail; - e1000->rx_ring.free = 0; - e1000_outl(e1000, E1000_RDT, tail); + int tail; + tail = e1000->rx_ring.tail + e1000->rx_ring.free; + tail %= CONFIG_E1000_N_RX_DESC; + e1000->rx_ring.tail = tail; + e1000->rx_ring.free = 0; + e1000_outl(e1000, E1000_RDT, tail); } return IRQ_HANDLED; @@ -885,20 +886,21 @@ static pci_id_t e1000_id_table[] = { static int e1000_probe(uint16_t addr, pci_id_t id) { uint32_t mmio_base, mmio_size; - uint32_t pci_cmd, size; - int err, irq, flags; + uint32_t size; + int err; void *kmem, *omem; struct e1000_dev *dev; // alloc e1000_dev memory - dev = kzalloc(sizeof(struct e1000_dev)); - if (dev == NULL) - return -1; + if ((dev = kzalloc(sizeof(struct e1000_dev))) == NULL) + return -1; + + // save pci addr + dev->pci_addr = addr; // enable device - err = pci_enable_device(addr, PCI_RESOURCE_MEM); - if (err) - goto error; + if ((err = pci_enable_device(addr, PCI_BUS_MASTER)) < 0) + goto error; // get e1000 device type dev->pci_dev_id = id.join; @@ -908,33 +910,20 @@ static int e1000_probe(uint16_t addr, pci_id_t id) mmio_size = pci_resource_len(addr, 0); err = rgmp_memmap_nocache(mmio_base, mmio_size, mmio_base); if (err) - goto error; + goto error; dev->phy_mem_base = mmio_base; dev->io_mem_base = mmio_base; dev->mem_size = mmio_size; - // make sure the controller's Bus Master capability is enabled - pci_cmd = pci_config_readl(addr, PCI_COMMAND); - pci_cmd |= (1<<2); - pci_config_writel(addr, PCI_COMMAND, pci_cmd); - // MAC address memset(dev->dst_mac, 0xFF, 6); memcpy(dev->src_mac, (void *)(dev->io_mem_base+E1000_RA), 6); - // get e1000 IRQ - flags = 0; - irq = pci_enable_msi(addr); - if (irq == 0) { - irq = pci_read_irq(addr); - flags |= IDC_SHARE; - } - dev->irq = irq; + // IRQ setup dev->int_desc.handler = e1000_interrupt_handler; dev->int_desc.dev_id = dev; - err = rgmp_request_irq(irq, &dev->int_desc, flags); - if (err) - goto err0; + if ((err = pci_request_irq(addr, &dev->int_desc, 0)) < 0) + goto err0; // Here we alloc a big block of memory once and make it // aligned to page boundary and multiple of page size. This @@ -942,15 +931,19 @@ static int e1000_probe(uint16_t addr, pci_id_t id) // should be mapped no-cache which will hugely reduce memory // access performance. The page size alloc will restrict // this bad effect only within the memory we alloc here. + // + // NEED FIX: the memalign may alloc memory continous in + // virtual address but dis-continous in physical address + // due to RGMP memory setup. size = CONFIG_E1000_N_TX_DESC * sizeof(struct tx_desc) + - CONFIG_E1000_N_TX_DESC * CONFIG_E1000_BUFF_SIZE + - CONFIG_E1000_N_RX_DESC * sizeof(struct rx_desc) + - CONFIG_E1000_N_RX_DESC * CONFIG_E1000_BUFF_SIZE; + CONFIG_E1000_N_TX_DESC * CONFIG_E1000_BUFF_SIZE + + CONFIG_E1000_N_RX_DESC * sizeof(struct rx_desc) + + CONFIG_E1000_N_RX_DESC * CONFIG_E1000_BUFF_SIZE; size = ROUNDUP(size, PGSIZE); omem = kmem = memalign(PGSIZE, size); if (kmem == NULL) { - err = -ENOMEM; - goto err1; + err = -ENOMEM; + goto err1; } rgmp_memremap_nocache((uintptr_t)kmem, size); @@ -991,7 +984,7 @@ static int e1000_probe(uint16_t addr, pci_id_t id) /* Register the device with the OS so that socket IOCTLs can be performed */ err = netdev_register(&dev->uip_dev); if (err) - goto err2; + goto err2; // insert into e1000_list dev->next = e1000_list.next; @@ -1000,14 +993,14 @@ static int e1000_probe(uint16_t addr, pci_id_t id) return 0; - err2: +err2: rgmp_memremap((uintptr_t)omem, size); free(omem); - err1: - rgmp_free_irq(irq, &dev->int_desc); - err0: +err1: + pci_free_irq(addr); +err0: rgmp_memunmap(mmio_base, mmio_size); - error: +error: kfree(dev); cprintf("e1000 device probe fail: %d\n", err); return err; @@ -1028,21 +1021,21 @@ void e1000_mod_exit(void) struct e1000_dev *dev; size = CONFIG_E1000_N_TX_DESC * sizeof(struct tx_desc) + - CONFIG_E1000_N_TX_DESC * CONFIG_E1000_BUFF_SIZE + - CONFIG_E1000_N_RX_DESC * sizeof(struct rx_desc) + - CONFIG_E1000_N_RX_DESC * CONFIG_E1000_BUFF_SIZE; + CONFIG_E1000_N_TX_DESC * CONFIG_E1000_BUFF_SIZE + + CONFIG_E1000_N_RX_DESC * sizeof(struct rx_desc) + + CONFIG_E1000_N_RX_DESC * CONFIG_E1000_BUFF_SIZE; size = ROUNDUP(size, PGSIZE); for (dev=e1000_list.next; dev!=NULL; dev=dev->next) { - netdev_unregister(&dev->uip_dev); - e1000_reset(dev); - wd_delete(dev->txpoll); - wd_delete(dev->txtimeout); - rgmp_memremap((uintptr_t)dev->tx_ring.desc, size); - free(dev->tx_ring.desc); - rgmp_free_irq(dev->irq, &dev->int_desc); - rgmp_memunmap((uintptr_t)dev->io_mem_base, dev->mem_size); - kfree(dev); + netdev_unregister(&dev->uip_dev); + e1000_reset(dev); + wd_delete(dev->txpoll); + wd_delete(dev->txtimeout); + rgmp_memremap((uintptr_t)dev->tx_ring.desc, size); + free(dev->tx_ring.desc); + pci_free_irq(dev->pci_addr); + rgmp_memunmap((uintptr_t)dev->io_mem_base, dev->mem_size); + kfree(dev); } e1000_list.next = NULL; diff --git a/nuttx/drivers/net/e1000.h b/nuttx/drivers/net/e1000.h index 6614ad77e..63ff53e3c 100644 --- a/nuttx/drivers/net/e1000.h +++ b/nuttx/drivers/net/e1000.h @@ -44,9 +44,7 @@ * Included Files ****************************************************************************/ -#include -#include -#include +#include /**************************************************************************** * Pre-processor Definitions diff --git a/nuttx/drivers/net/vnet.c b/nuttx/drivers/net/vnet.c index f1e2465b9..e05a39675 100644 --- a/nuttx/drivers/net/vnet.c +++ b/nuttx/drivers/net/vnet.c @@ -168,30 +168,30 @@ static int vnet_transmit(FAR struct vnet_driver_s *vnet) { int err; - /* Verify that the hardware is ready to send another packet. If we get - * here, then we are committed to sending a packet; Higher level logic - * must have assured that there is not transmission in progress. - */ + /* Verify that the hardware is ready to send another packet. If we get + * here, then we are committed to sending a packet; Higher level logic + * must have assured that there is not transmission in progress. + */ - /* Increment statistics */ + /* Increment statistics */ - /* Send the packet: address=vnet->sk_dev.d_buf, length=vnet->sk_dev.d_len */ + /* Send the packet: address=vnet->sk_dev.d_buf, length=vnet->sk_dev.d_len */ err = vnet_xmit(vnet->vnet, (char *)vnet->sk_dev.d_buf, vnet->sk_dev.d_len); if (err) { - /* Setup the TX timeout watchdog (perhaps restarting the timer) */ - //(void)wd_start(vnet->sk_txtimeout, VNET_TXTIMEOUT, vnet_txtimeout, 1, (uint32_t)vnet); + /* Setup the TX timeout watchdog (perhaps restarting the timer) */ + //(void)wd_start(vnet->sk_txtimeout, VNET_TXTIMEOUT, vnet_txtimeout, 1, (uint32_t)vnet); - // When vnet_xmit fail, it means TX buffer is full. Watchdog - // is of no use here because no TX done INT will happen. So - // we reset the TX buffer directly. + // When vnet_xmit fail, it means TX buffer is full. Watchdog + // is of no use here because no TX done INT will happen. So + // we reset the TX buffer directly. #ifdef CONFIG_DEBUG - cprintf("VNET: TX buffer is full\n"); + cprintf("VNET: TX buffer is full\n"); #endif - return ERROR; + return ERROR; } else { - // this step may be unnecessary here - vnet_txdone(vnet); + // this step may be unnecessary here + vnet_txdone(vnet); } return OK; @@ -223,29 +223,29 @@ static int vnet_transmit(FAR struct vnet_driver_s *vnet) static int vnet_uiptxpoll(struct uip_driver_s *dev) { - FAR struct vnet_driver_s *vnet = (FAR struct vnet_driver_s *)dev->d_private; + FAR struct vnet_driver_s *vnet = (FAR struct vnet_driver_s *)dev->d_private; - /* If the polling resulted in data that should be sent out on the network, - * the field d_len is set to a value > 0. - */ + /* If the polling resulted in data that should be sent out on the network, + * the field d_len is set to a value > 0. + */ - if (vnet->sk_dev.d_len > 0) + if (vnet->sk_dev.d_len > 0) { - uip_arp_out(&vnet->sk_dev); - vnet_transmit(vnet); - - /* Check if there is room in the device to hold another packet. If not, - * return a non-zero value to terminate the poll. - */ - if (vnet_is_txbuff_full(vnet->vnet)) - return 1; + uip_arp_out(&vnet->sk_dev); + vnet_transmit(vnet); + + /* Check if there is room in the device to hold another packet. If not, + * return a non-zero value to terminate the poll. + */ + if (vnet_is_txbuff_full(vnet->vnet)) + return 1; } - /* If zero is returned, the polling will continue until all connections have - * been examined. - */ + /* If zero is returned, the polling will continue until all connections have + * been examined. + */ - return 0; + return 0; } /**************************************************************************** @@ -265,54 +265,53 @@ static int vnet_uiptxpoll(struct uip_driver_s *dev) * ****************************************************************************/ -void rtos_vnet_recv(struct rgmp_vnet *vnet_dummy, char *data, int len) +void rtos_vnet_recv(struct rgmp_vnet *rgmp_vnet, char *data, int len) { - // now only support 1 vnet - struct vnet_driver_s *vnet = &g_vnet[0]; + struct vnet_driver_s *vnet = rgmp_vnet->priv; do { - /* Check for errors and update statistics */ + /* Check for errors and update statistics */ - /* Check if the packet is a valid size for the uIP buffer configuration */ - if (len > CONFIG_NET_BUFSIZE || len < 14) { + /* Check if the packet is a valid size for the uIP buffer configuration */ + if (len > CONFIG_NET_BUFSIZE || len < 14) { #ifdef CONFIG_DEBUG - cprintf("VNET: receive invalid packet of size %d\n", len); + cprintf("VNET: receive invalid packet of size %d\n", len); #endif - return; - } + return; + } - // Copy the data data from the hardware to vnet->sk_dev.d_buf. Set - // amount of data in vnet->sk_dev.d_len - memcpy(vnet->sk_dev.d_buf, data, len); - vnet->sk_dev.d_len = len; + // Copy the data data from the hardware to vnet->sk_dev.d_buf. Set + // amount of data in vnet->sk_dev.d_len + memcpy(vnet->sk_dev.d_buf, data, len); + vnet->sk_dev.d_len = len; - /* We only accept IP packets of the configured type and ARP packets */ + /* We only accept IP packets of the configured type and ARP packets */ #ifdef CONFIG_NET_IPv6 - if (BUF->type == HTONS(UIP_ETHTYPE_IP6)) + if (BUF->type == HTONS(UIP_ETHTYPE_IP6)) #else - if (BUF->type == HTONS(UIP_ETHTYPE_IP)) + if (BUF->type == HTONS(UIP_ETHTYPE_IP)) #endif - { - uip_arp_ipin(&vnet->sk_dev); - uip_input(&vnet->sk_dev); - - // If the above function invocation resulted in data that should be - // sent out on the network, the field d_len will set to a value > 0. - if (vnet->sk_dev.d_len > 0) { - uip_arp_out(&vnet->sk_dev); - vnet_transmit(vnet); - } - } - else if (BUF->type == htons(UIP_ETHTYPE_ARP)) { - uip_arp_arpin(&vnet->sk_dev); - - // If the above function invocation resulted in data that should be - // sent out on the network, the field d_len will set to a value > 0. - if (vnet->sk_dev.d_len > 0) { - vnet_transmit(vnet); - } - } + { + uip_arp_ipin(&vnet->sk_dev); + uip_input(&vnet->sk_dev); + + // If the above function invocation resulted in data that should be + // sent out on the network, the field d_len will set to a value > 0. + if (vnet->sk_dev.d_len > 0) { + uip_arp_out(&vnet->sk_dev); + vnet_transmit(vnet); + } + } + else if (BUF->type == htons(UIP_ETHTYPE_ARP)) { + uip_arp_arpin(&vnet->sk_dev); + + // If the above function invocation resulted in data that should be + // sent out on the network, the field d_len will set to a value > 0. + if (vnet->sk_dev.d_len > 0) { + vnet_transmit(vnet); + } + } } while (0); /* While there are more packets to be processed */ } @@ -336,17 +335,17 @@ void rtos_vnet_recv(struct rgmp_vnet *vnet_dummy, char *data, int len) static void vnet_txdone(FAR struct vnet_driver_s *vnet) { - /* Check for errors and update statistics */ + /* Check for errors and update statistics */ - /* If no further xmits are pending, then cancel the TX timeout and - * disable further Tx interrupts. - */ + /* If no further xmits are pending, then cancel the TX timeout and + * disable further Tx interrupts. + */ - //wd_cancel(vnet->sk_txtimeout); + //wd_cancel(vnet->sk_txtimeout); - /* Then poll uIP for new XMIT data */ + /* Then poll uIP for new XMIT data */ - (void)uip_poll(&vnet->sk_dev, vnet_uiptxpoll); + (void)uip_poll(&vnet->sk_dev, vnet_uiptxpoll); } /**************************************************************************** @@ -370,15 +369,15 @@ static void vnet_txdone(FAR struct vnet_driver_s *vnet) static void vnet_txtimeout(int argc, uint32_t arg, ...) { - FAR struct vnet_driver_s *vnet = (FAR struct vnet_driver_s *)arg; + FAR struct vnet_driver_s *vnet = (FAR struct vnet_driver_s *)arg; - /* Increment statistics and dump debug info */ + /* Increment statistics and dump debug info */ - /* Then reset the hardware */ + /* Then reset the hardware */ - /* Then poll uIP for new XMIT data */ + /* Then poll uIP for new XMIT data */ - (void)uip_poll(&vnet->sk_dev, vnet_uiptxpoll); + (void)uip_poll(&vnet->sk_dev, vnet_uiptxpoll); } /**************************************************************************** @@ -401,28 +400,28 @@ static void vnet_txtimeout(int argc, uint32_t arg, ...) static void vnet_polltimer(int argc, uint32_t arg, ...) { - FAR struct vnet_driver_s *vnet = (FAR struct vnet_driver_s *)arg; + FAR struct vnet_driver_s *vnet = (FAR struct vnet_driver_s *)arg; - /* Check if there is room in the send another TX packet. We cannot perform - * the TX poll if he are unable to accept another packet for transmission. - */ - if (vnet_is_txbuff_full(vnet->vnet)) { + /* Check if there is room in the send another TX packet. We cannot perform + * the TX poll if he are unable to accept another packet for transmission. + */ + if (vnet_is_txbuff_full(vnet->vnet)) { #ifdef CONFIG_DEBUG - cprintf("VNET: TX buffer is full\n"); + cprintf("VNET: TX buffer is full\n"); #endif - return; - } + return; + } - /* If so, update TCP timing states and poll uIP for new XMIT data. Hmmm.. - * might be bug here. Does this mean if there is a transmit in progress, - * we will missing TCP time state updates? - */ + /* If so, update TCP timing states and poll uIP for new XMIT data. Hmmm.. + * might be bug here. Does this mean if there is a transmit in progress, + * we will missing TCP time state updates? + */ - (void)uip_timer(&vnet->sk_dev, vnet_uiptxpoll, VNET_POLLHSEC); + (void)uip_timer(&vnet->sk_dev, vnet_uiptxpoll, VNET_POLLHSEC); - /* Setup the watchdog poll timer again */ + /* Setup the watchdog poll timer again */ - (void)wd_start(vnet->sk_txpoll, VNET_WDDELAY, vnet_polltimer, 1, arg); + (void)wd_start(vnet->sk_txpoll, VNET_WDDELAY, vnet_polltimer, 1, arg); } /**************************************************************************** @@ -444,20 +443,20 @@ static void vnet_polltimer(int argc, uint32_t arg, ...) static int vnet_ifup(struct uip_driver_s *dev) { - FAR struct vnet_driver_s *vnet = (FAR struct vnet_driver_s *)dev->d_private; + FAR struct vnet_driver_s *vnet = (FAR struct vnet_driver_s *)dev->d_private; - ndbg("Bringing up: %d.%d.%d.%d\n", - dev->d_ipaddr & 0xff, (dev->d_ipaddr >> 8) & 0xff, - (dev->d_ipaddr >> 16) & 0xff, dev->d_ipaddr >> 24 ); + ndbg("Bringing up: %d.%d.%d.%d\n", + dev->d_ipaddr & 0xff, (dev->d_ipaddr >> 8) & 0xff, + (dev->d_ipaddr >> 16) & 0xff, dev->d_ipaddr >> 24 ); - /* Initialize PHYs, the Ethernet interface, and setup up Ethernet interrupts */ + /* Initialize PHYs, the Ethernet interface, and setup up Ethernet interrupts */ - /* Set and activate a timer process */ + /* Set and activate a timer process */ - (void)wd_start(vnet->sk_txpoll, VNET_WDDELAY, vnet_polltimer, 1, (uint32_t)vnet); + (void)wd_start(vnet->sk_txpoll, VNET_WDDELAY, vnet_polltimer, 1, (uint32_t)vnet); - vnet->sk_bifup = true; - return OK; + vnet->sk_bifup = true; + return OK; } /**************************************************************************** @@ -478,28 +477,28 @@ static int vnet_ifup(struct uip_driver_s *dev) static int vnet_ifdown(struct uip_driver_s *dev) { - FAR struct vnet_driver_s *vnet = (FAR struct vnet_driver_s *)dev->d_private; - irqstate_t flags; + FAR struct vnet_driver_s *vnet = (FAR struct vnet_driver_s *)dev->d_private; + irqstate_t flags; - /* Disable the Ethernet interrupt */ + /* Disable the Ethernet interrupt */ - flags = irqsave(); + flags = irqsave(); - /* Cancel the TX poll timer and TX timeout timers */ + /* Cancel the TX poll timer and TX timeout timers */ - wd_cancel(vnet->sk_txpoll); - //wd_cancel(vnet->sk_txtimeout); + wd_cancel(vnet->sk_txpoll); + //wd_cancel(vnet->sk_txtimeout); - /* Put the the EMAC is its reset, non-operational state. This should be - * a known configuration that will guarantee the vnet_ifup() always - * successfully brings the interface back up. - */ + /* Put the the EMAC is its reset, non-operational state. This should be + * a known configuration that will guarantee the vnet_ifup() always + * successfully brings the interface back up. + */ - /* Mark the device "down" */ + /* Mark the device "down" */ - vnet->sk_bifup = false; - irqrestore(flags); - return OK; + vnet->sk_bifup = false; + irqrestore(flags); + return OK; } /**************************************************************************** @@ -523,35 +522,35 @@ static int vnet_ifdown(struct uip_driver_s *dev) static int vnet_txavail(struct uip_driver_s *dev) { - FAR struct vnet_driver_s *vnet = (FAR struct vnet_driver_s *)dev->d_private; - irqstate_t flags; + FAR struct vnet_driver_s *vnet = (FAR struct vnet_driver_s *)dev->d_private; + irqstate_t flags; - /* Disable interrupts because this function may be called from interrupt - * level processing. - */ + /* Disable interrupts because this function may be called from interrupt + * level processing. + */ - flags = irqsave(); + flags = irqsave(); - /* Ignore the notification if the interface is not yet up */ + /* Ignore the notification if the interface is not yet up */ - if (vnet->sk_bifup) + if (vnet->sk_bifup) { - /* Check if there is room in the hardware to hold another outgoing packet. */ - if (vnet_is_txbuff_full(vnet->vnet)) { + /* Check if there is room in the hardware to hold another outgoing packet. */ + if (vnet_is_txbuff_full(vnet->vnet)) { #ifdef CONFIG_DEBUG - cprintf("VNET: TX buffer is full\n"); + cprintf("VNET: TX buffer is full\n"); #endif - goto out; - } + goto out; + } - /* If so, then poll uIP for new XMIT data */ + /* If so, then poll uIP for new XMIT data */ - (void)uip_poll(&vnet->sk_dev, vnet_uiptxpoll); + (void)uip_poll(&vnet->sk_dev, vnet_uiptxpoll); } - out: - irqrestore(flags); - return OK; +out: + irqrestore(flags); + return OK; } /**************************************************************************** @@ -575,11 +574,11 @@ static int vnet_txavail(struct uip_driver_s *dev) #ifdef CONFIG_NET_IGMP static int vnet_addmac(struct uip_driver_s *dev, FAR const uint8_t *mac) { - FAR struct vnet_driver_s *vnet = (FAR struct vnet_driver_s *)dev->d_private; + FAR struct vnet_driver_s *vnet = (FAR struct vnet_driver_s *)dev->d_private; - /* Add the MAC address to the hardware multicast routing table */ + /* Add the MAC address to the hardware multicast routing table */ - return OK; + return OK; } #endif @@ -604,11 +603,11 @@ static int vnet_addmac(struct uip_driver_s *dev, FAR const uint8_t *mac) #ifdef CONFIG_NET_IGMP static int vnet_rmmac(struct uip_driver_s *dev, FAR const uint8_t *mac) { - FAR struct vnet_driver_s *vnet = (FAR struct vnet_driver_s *)dev->d_private; + FAR struct vnet_driver_s *vnet = (FAR struct vnet_driver_s *)dev->d_private; - /* Add the MAC address to the hardware multicast routing table */ + /* Add the MAC address to the hardware multicast routing table */ - return OK; + return OK; } #endif @@ -633,41 +632,41 @@ static int vnet_rmmac(struct uip_driver_s *dev, FAR const uint8_t *mac) * ****************************************************************************/ -void vnet_initialize(void) +int vnet_init(struct rgmp_vnet *vnet) { - struct vnet_driver_s *priv; - struct rgmp_vnet *vnet = vnet_list.next; - int i; + struct vnet_driver_s *priv; + static int i = 0; - for (i=0; i= CONFIG_VNET_NINTERFACES) + return -1; - /* Initialize the driver structure */ + priv = &g_vnet[i++]; - memset(priv, 0, sizeof(struct vnet_driver_s)); - priv->sk_dev.d_ifup = vnet_ifup; /* I/F down callback */ - priv->sk_dev.d_ifdown = vnet_ifdown; /* I/F up (new IP address) callback */ - priv->sk_dev.d_txavail = vnet_txavail; /* New TX data callback */ + /* Initialize the driver structure */ + + memset(priv, 0, sizeof(struct vnet_driver_s)); + priv->sk_dev.d_ifup = vnet_ifup; /* I/F down callback */ + priv->sk_dev.d_ifdown = vnet_ifdown; /* I/F up (new IP address) callback */ + priv->sk_dev.d_txavail = vnet_txavail; /* New TX data callback */ #ifdef CONFIG_NET_IGMP - priv->sk_dev.d_addmac = vnet_addmac; /* Add multicast MAC address */ - priv->sk_dev.d_rmmac = vnet_rmmac; /* Remove multicast MAC address */ + priv->sk_dev.d_addmac = vnet_addmac; /* Add multicast MAC address */ + priv->sk_dev.d_rmmac = vnet_rmmac; /* Remove multicast MAC address */ #endif - priv->sk_dev.d_private = (void*)g_vnet; /* Used to recover private state from dev */ + priv->sk_dev.d_private = (void*)priv; /* Used to recover private state from dev */ + + /* Create a watchdog for timing polling for and timing of transmisstions */ - /* Create a watchdog for timing polling for and timing of transmisstions */ + priv->sk_txpoll = wd_create(); /* Create periodic poll timer */ + //priv->sk_txtimeout = wd_create(); /* Create TX timeout timer */ - priv->sk_txpoll = wd_create(); /* Create periodic poll timer */ - //priv->sk_txtimeout = wd_create(); /* Create TX timeout timer */ + priv->vnet = vnet; + vnet->priv = priv; - priv->vnet = vnet; + /* Register the device with the OS */ - /* Register the device with the OS */ + (void)netdev_register(&priv->sk_dev); - (void)netdev_register(&priv->sk_dev); - vnet = vnet->next; - } + return 0; } #endif /* CONFIG_NET && CONFIG_NET_VNET */ diff --git a/nuttx/drivers/usbdev/pl2303.c b/nuttx/drivers/usbdev/pl2303.c index 69bf87965..95f26c185 100644 --- a/nuttx/drivers/usbdev/pl2303.c +++ b/nuttx/drivers/usbdev/pl2303.c @@ -132,7 +132,7 @@ /* USB Controller */ #ifndef CONFIG_USBDEV_SELFPOWERED -# define SELFPOWERED USB_CONFIG_ATT_SELFPOWER +# define SELFPOWERED USB_CONFIG_ATTR_SELFPOWER #else # define SELFPOWERED (0) #endif diff --git a/nuttx/drivers/usbdev/usbmsc.h b/nuttx/drivers/usbdev/usbmsc.h index 6a5530d9d..883a49951 100644 --- a/nuttx/drivers/usbdev/usbmsc.h +++ b/nuttx/drivers/usbdev/usbmsc.h @@ -227,7 +227,7 @@ /* USB Controller */ #ifndef CONFIG_USBDEV_SELFPOWERED -# define SELFPOWERED USB_CONFIG_ATT_SELFPOWER +# define SELFPOWERED USB_CONFIG_ATTR_SELFPOWER #else # define SELFPOWERED (0) #endif diff --git a/nuttx/fs/Makefile b/nuttx/fs/Makefile index ce952e06f..6955c164b 100644 --- a/nuttx/fs/Makefile +++ b/nuttx/fs/Makefile @@ -120,25 +120,21 @@ $(COBJS): %$(OBJEXT): %.c $(call COMPILE, $<, $@) $(BIN): $(OBJS) - @( for obj in $(OBJS) ; do \ - $(call ARCHIVE, $@, $${obj}); \ - done ; ) + $(call ARCHIVE, $@, $(OBJS)) .depend: Makefile $(SRCS) - @$(MKDEP) --dep-path . $(MMAPDEPPATH) $(FATDEPPATH) $(ROMFSDEPPATH) $(NXFFSDEPPATH) $(NFSDEPPATH) \ - $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep - @touch $@ + $(Q) $(MKDEP) --dep-path . $(MMAPDEPPATH) $(FATDEPPATH) $(ROMFSDEPPATH) $(NXFFSDEPPATH) $(NFSDEPPATH) \ + "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep + $(Q) touch $@ depend: .depend clean: - @rm -f $(BIN) *~ .*.swp + $(call DELFILE, $(BIN)) $(call CLEAN) - @( for dir in $(SUBDIRS); do \ - rm -f $${dir}/*~ $${dir}/.*.swp; \ - done ; ) distclean: clean - @rm -f Make.dep .depend + $(call DELFILE, Make.dep) + $(call DELFILE, .depend) -include Make.dep diff --git a/nuttx/fs/fs_stat.c b/nuttx/fs/fs_stat.c index cf27e87a6..4df25028f 100644 --- a/nuttx/fs/fs_stat.c +++ b/nuttx/fs/fs_stat.c @@ -1,7 +1,7 @@ /**************************************************************************** * fs/fs_stat.c * - * Copyright (C) 2007-2009 , 2012Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2012 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -122,7 +122,8 @@ static inline int statroot(FAR struct stat *buf) /**************************************************************************** * Name: stat * - * Return: Zero on success; -1 on failure with errno set: + * Returned Value: + * Zero on success; -1 on failure with errno set: * * EACCES Search permission is denied for one of the directories in the * path prefix of path. @@ -134,7 +135,7 @@ static inline int statroot(FAR struct stat *buf) * ****************************************************************************/ -int stat(const char *path, FAR struct stat *buf) +int stat(FAR const char *path, FAR struct stat *buf) { FAR struct inode *inode; const char *relpath = NULL; diff --git a/nuttx/graphics/Makefile b/nuttx/graphics/Makefile index 6e549c1dd..238e14df4 100644 --- a/nuttx/graphics/Makefile +++ b/nuttx/graphics/Makefile @@ -33,7 +33,6 @@ # ############################################################################ --include $(TOPDIR)/.config -include $(TOPDIR)/Make.defs DEPPATH = --dep-path . @@ -44,34 +43,34 @@ endif include nxglib/Make.defs DEPPATH += --dep-path nxglib -CFLAGS += ${shell $(TOPDIR)/tools/incdir.sh $(INCDIROPT) "$(CC)" $(TOPDIR)/graphics/nxglib} +CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)/graphics/nxglib} include nxbe/Make.defs DEPPATH += --dep-path nxbe -CFLAGS += ${shell $(TOPDIR)/tools/incdir.sh $(INCDIROPT) "$(CC)" $(TOPDIR)/graphics/nxbe} +CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)/graphics/nxbe} ifeq ($(CONFIG_NX_MULTIUSER),y) include nxmu/Make.defs DEPPATH += --dep-path nxmu -CFLAGS += ${shell $(TOPDIR)/tools/incdir.sh $(INCDIROPT) "$(CC)" $(TOPDIR)/graphics/nxmu} +CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)/graphics/nxmu} else include nxsu/Make.defs DEPPATH += --dep-path nxsu -CFLAGS += ${shell $(TOPDIR)/tools/incdir.sh $(INCDIROPT) "$(CC)" $(TOPDIR)/graphics/nxsu} +CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)/graphics/nxsu} endif include nxtk/Make.defs DEPPATH += --dep-path nxtk -CFLAGS += ${shell $(TOPDIR)/tools/incdir.sh $(INCDIROPT) "$(CC)" $(TOPDIR)/graphics/nxtk} +CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)/graphics/nxtk} include nxfonts/Make.defs DEPPATH += --dep-path nxfonts -CFLAGS += ${shell $(TOPDIR)/tools/incdir.sh $(INCDIROPT) "$(CC)" $(TOPDIR)/graphics/nxfonts} +CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)/graphics/nxfonts} ifeq ($(CONFIG_NXCONSOLE),y) include nxconsole/Make.defs DEPPATH += --dep-path nxconsole -CFLAGS += ${shell $(TOPDIR)/tools/incdir.sh $(INCDIROPT) "$(CC)" $(TOPDIR)/graphics/nxconsole} +CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)/graphics/nxconsole} endif ASRCS = $(NXGLIB_ASRCS) $(NXBE_ASRCS) $(NX_ASRCS) $(NXTK_ASRCS) $(NXFONTS_ASRCS) $(NXCON_ASRCS) @@ -97,84 +96,84 @@ all: mklibgraphics gen32bppsources genfontsources gen1bppsources: - @$(MAKE) -C nxglib -f Makefile.sources TOPDIR=$(TOPDIR) NXGLIB_BITSPERPIXEL=1 EXTRADEFINES=$(EXTRADEFINES) - @$(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_BITSPERPIXEL=1 EXTRADEFINES=$(EXTRADEFINES) + $(Q) $(MAKE) -C nxglib -f Makefile.sources TOPDIR=$(TOPDIR) NXGLIB_BITSPERPIXEL=1 EXTRADEFINES=$(EXTRADEFINES) + $(Q) $(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_BITSPERPIXEL=1 EXTRADEFINES=$(EXTRADEFINES) gen2bppsource: - @$(MAKE) -C nxglib -f Makefile.sources TOPDIR=$(TOPDIR) NXGLIB_BITSPERPIXEL=2 EXTRADEFINES=$(EXTRADEFINES) - @$(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_BITSPERPIXEL=2 EXTRADEFINES=$(EXTRADEFINES) + $(Q) $(MAKE) -C nxglib -f Makefile.sources TOPDIR=$(TOPDIR) NXGLIB_BITSPERPIXEL=2 EXTRADEFINES=$(EXTRADEFINES) + $(Q) $(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_BITSPERPIXEL=2 EXTRADEFINES=$(EXTRADEFINES) gen4bppsource: - @$(MAKE) -C nxglib -f Makefile.sources TOPDIR=$(TOPDIR) NXGLIB_BITSPERPIXEL=4 EXTRADEFINES=$(EXTRADEFINES) - @$(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_BITSPERPIXEL=4 EXTRADEFINES=$(EXTRADEFINES) + $(Q) $(MAKE) -C nxglib -f Makefile.sources TOPDIR=$(TOPDIR) NXGLIB_BITSPERPIXEL=4 EXTRADEFINES=$(EXTRADEFINES) + $(Q) $(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_BITSPERPIXEL=4 EXTRADEFINES=$(EXTRADEFINES) gen8bppsource: - @$(MAKE) -C nxglib -f Makefile.sources TOPDIR=$(TOPDIR) NXGLIB_BITSPERPIXEL=8 EXTRADEFINES=$(EXTRADEFINES) - @$(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_BITSPERPIXEL=8 EXTRADEFINES=$(EXTRADEFINES) + $(Q) $(MAKE) -C nxglib -f Makefile.sources TOPDIR=$(TOPDIR) NXGLIB_BITSPERPIXEL=8 EXTRADEFINES=$(EXTRADEFINES) + $(Q) $(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_BITSPERPIXEL=8 EXTRADEFINES=$(EXTRADEFINES) gen16bppsource: - @$(MAKE) -C nxglib -f Makefile.sources TOPDIR=$(TOPDIR) NXGLIB_BITSPERPIXEL=16 EXTRADEFINES=$(EXTRADEFINES) - @$(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_BITSPERPIXEL=16 EXTRADEFINES=$(EXTRADEFINES) + $(Q) $(MAKE) -C nxglib -f Makefile.sources TOPDIR=$(TOPDIR) NXGLIB_BITSPERPIXEL=16 EXTRADEFINES=$(EXTRADEFINES) + $(Q) $(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_BITSPERPIXEL=16 EXTRADEFINES=$(EXTRADEFINES) gen24bppsource: - @$(MAKE) -C nxglib -f Makefile.sources TOPDIR=$(TOPDIR) NXGLIB_BITSPERPIXEL=24 EXTRADEFINES=$(EXTRADEFINES) - @$(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_BITSPERPIXEL=24 EXTRADEFINES=$(EXTRADEFINES) + $(Q) $(MAKE) -C nxglib -f Makefile.sources TOPDIR=$(TOPDIR) NXGLIB_BITSPERPIXEL=24 EXTRADEFINES=$(EXTRADEFINES) + $(Q) $(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_BITSPERPIXEL=24 EXTRADEFINES=$(EXTRADEFINES) gen32bppsources: - @$(MAKE) -C nxglib -f Makefile.sources TOPDIR=$(TOPDIR) NXGLIB_BITSPERPIXEL=32 EXTRADEFINES=$(EXTRADEFINES) - @$(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_BITSPERPIXEL=32 EXTRADEFINES=$(EXTRADEFINES) + $(Q) $(MAKE) -C nxglib -f Makefile.sources TOPDIR=$(TOPDIR) NXGLIB_BITSPERPIXEL=32 EXTRADEFINES=$(EXTRADEFINES) + $(Q) $(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_BITSPERPIXEL=32 EXTRADEFINES=$(EXTRADEFINES) genfontsources: ifeq ($(CONFIG_NXFONT_SANS23X27),y) - @$(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=1 EXTRADEFINES=$(EXTRADEFINES) + $(Q) $(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=1 EXTRADEFINES=$(EXTRADEFINES) endif ifeq ($(CONFIG_NXFONT_SANS22X29),y) - @$(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=2 EXTRADEFINES=$(EXTRADEFINES) + $(Q) $(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=2 EXTRADEFINES=$(EXTRADEFINES) endif ifeq ($(CONFIG_NXFONT_SANS28X37),y) - @$(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=3 EXTRADEFINES=$(EXTRADEFINES) + $(Q) $(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=3 EXTRADEFINES=$(EXTRADEFINES) endif ifeq ($(CONFIG_NXFONT_SANS39X48),y) - @$(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=4 EXTRADEFINES=$(EXTRADEFINES) + $(Q) $(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=4 EXTRADEFINES=$(EXTRADEFINES) endif ifeq ($(CONFIG_NXFONT_SANS17X23B),y) - @$(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=16 EXTRADEFINES=$(EXTRADEFINES) + $(Q) $(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=16 EXTRADEFINES=$(EXTRADEFINES) endif ifeq ($(CONFIG_NXFONT_SANS20X27B),y) - @$(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=17 EXTRADEFINES=$(EXTRADEFINES) + $(Q) $(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=17 EXTRADEFINES=$(EXTRADEFINES) endif ifeq ($(CONFIG_NXFONT_SANS22X29B),y) - @$(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=5 EXTRADEFINES=$(EXTRADEFINES) + $(Q) $(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=5 EXTRADEFINES=$(EXTRADEFINES) endif ifeq ($(CONFIG_NXFONT_SANS28X37B),y) - @$(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=6 EXTRADEFINES=$(EXTRADEFINES) + $(Q) $(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=6 EXTRADEFINES=$(EXTRADEFINES) endif ifeq ($(CONFIG_NXFONT_SANS40X49B),y) - @$(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=7 EXTRADEFINES=$(EXTRADEFINES) + $(Q) $(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=7 EXTRADEFINES=$(EXTRADEFINES) endif ifeq ($(CONFIG_NXFONT_SERIF22X29),y) - @$(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=8 EXTRADEFINES=$(EXTRADEFINES) + $(Q) $(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=8 EXTRADEFINES=$(EXTRADEFINES) endif ifeq ($(CONFIG_NXFONT_SERIF29X37),y) - @$(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=9 EXTRADEFINES=$(EXTRADEFINES) + $(Q) $(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=9 EXTRADEFINES=$(EXTRADEFINES) endif ifeq ($(CONFIG_NXFONT_SERIF38X48),y) - @$(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=10 EXTRADEFINES=$(EXTRADEFINES) + $(Q) $(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=10 EXTRADEFINES=$(EXTRADEFINES) endif ifeq ($(CONFIG_NXFONT_SERIF22X28B),y) - @$(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=11 EXTRADEFINES=$(EXTRADEFINES) + $(Q) $(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=11 EXTRADEFINES=$(EXTRADEFINES) endif ifeq ($(CONFIG_NXFONT_SERIF27X38B),y) - @$(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=12 EXTRADEFINES=$(EXTRADEFINES) + $(Q) $(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=12 EXTRADEFINES=$(EXTRADEFINES) endif ifeq ($(CONFIG_NXFONT_SERIF38X49B),y) - @$(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=13 EXTRADEFINES=$(EXTRADEFINES) + $(Q) $(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=13 EXTRADEFINES=$(EXTRADEFINES) endif ifeq ($(CONFIG_NXFONT_SANS17X22),y) - @$(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=14 EXTRADEFINES=$(EXTRADEFINES) + $(Q) $(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=14 EXTRADEFINES=$(EXTRADEFINES) endif ifeq ($(CONFIG_NXFONT_SANS20X26),y) - @$(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=15 EXTRADEFINES=$(EXTRADEFINES) + $(Q) $(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=15 EXTRADEFINES=$(EXTRADEFINES) endif gensources: gen1bppsources gen2bppsource gen4bppsource gen8bppsource gen16bppsource gen24bppsource gen32bppsources genfontsources @@ -186,30 +185,29 @@ $(COBJS): %$(OBJEXT): %.c $(call COMPILE, $<, $@) $(BIN): $(OBJS) - @( for obj in $(OBJS) ; do \ - $(call ARCHIVE, $@, $${obj}); \ - done ; ) + $(call ARCHIVE, $@, $(OBJS)) mklibgraphics: gensources $(BIN) .depend: gensources Makefile $(SRCS) - @$(MKDEP) $(DEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep - @touch $@ + $(Q) $(MKDEP) $(DEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep + $(Q) touch $@ depend: .depend context: gensources clean: - @$(MAKE) -C nxglib -f Makefile.sources clean TOPDIR=$(TOPDIR) EXTRADEFINES=$(EXTRADEFINES) - @$(MAKE) -C nxfonts -f Makefile.sources clean TOPDIR=$(TOPDIR) EXTRADEFINES=$(EXTRADEFINES) - @rm -f $(BIN) *~ .*.swp + $(Q) $(MAKE) -C nxglib -f Makefile.sources clean TOPDIR=$(TOPDIR) EXTRADEFINES=$(EXTRADEFINES) + $(Q) $(MAKE) -C nxfonts -f Makefile.sources clean TOPDIR=$(TOPDIR) EXTRADEFINES=$(EXTRADEFINES) + $(call DELFILE, $(BIN)) $(call CLEAN) distclean: clean - @$(MAKE) -C nxglib -f Makefile.sources distclean TOPDIR=$(TOPDIR) EXTRADEFINES=$(EXTRADEFINES) - @$(MAKE) -C nxfonts -f Makefile.sources distclean TOPDIR=$(TOPDIR) EXTRADEFINES=$(EXTRADEFINES) - @rm -f Make.dep .depend + $(Q) $(MAKE) -C nxglib -f Makefile.sources distclean TOPDIR=$(TOPDIR) EXTRADEFINES=$(EXTRADEFINES) + $(Q) $(MAKE) -C nxfonts -f Makefile.sources distclean TOPDIR=$(TOPDIR) EXTRADEFINES=$(EXTRADEFINES) + $(call DELFILE, Make.dep) + $(call DELFILE, .depend) -include Make.dep diff --git a/nuttx/graphics/nxfonts/Makefile.sources b/nuttx/graphics/nxfonts/Makefile.sources index f2aa87caf..76a099dcb 100644 --- a/nuttx/graphics/nxfonts/Makefile.sources +++ b/nuttx/graphics/nxfonts/Makefile.sources @@ -33,7 +33,6 @@ # ############################################################################ --include $(TOPDIR)/.config -include $(TOPDIR)/Make.defs ifdef NXFONTS_BITSPERPIXEL @@ -177,13 +176,14 @@ all: $(GEN_CSRC) .PHONY : clean distclean $(GEN_CSRC) : $(DEPENDENCY) - @$(call PREPROCESS, $<, $(GEN_TMP)) - @cat $(GEN_TMP) | sed -e "/^#/d" >$@ - @rm -f $(GEN_TMP) + $(call PREPROCESS, $<, $(GEN_TMP)) + $(Q) cat $(GEN_TMP) | sed -e "/^#/d" >$@ + $(Q) rm -f $(GEN_TMP) clean: - @rm -f *~ .*.swp *.i + $(call DELFILE, *.i) + $(call CLEAN) distclean: clean - @rm -f nxfonts_convert_*bpp.c - @rm -f nxfonts_bitmaps_*.c + $(call DELFILE, nxfonts_convert_*bpp.c) + $(call DELFILE, nxfonts_bitmaps_*.c) diff --git a/nuttx/graphics/nxglib/Makefile.sources b/nuttx/graphics/nxglib/Makefile.sources index 67f8defc3..71d6e0661 100644 --- a/nuttx/graphics/nxglib/Makefile.sources +++ b/nuttx/graphics/nxglib/Makefile.sources @@ -33,7 +33,6 @@ # ############################################################################ --include $(TOPDIR)/.config -include $(TOPDIR)/Make.defs ifeq ($(NXGLIB_BITSPERPIXEL),1) @@ -123,53 +122,54 @@ all: $(GEN_CSRCS) $(SETP_CSRC) : $(BLITDIR)/nxglib_setpixel.c nxglib_bitblit.h ifneq ($(NXGLIB_BITSPERPIXEL),) - @$(call PREPROCESS, $(BLITDIR)/nxglib_setpixel.c, $(SETP_TMP)) - @cat $(SETP_TMP) | sed -e "/^#/d" >$@ - @rm -f $(SETP_TMP) + $(call PREPROCESS, $(BLITDIR)/nxglib_setpixel.c, $(SETP_TMP)) + $(Q) cat $(SETP_TMP) | sed -e "/^#/d" >$@ + $(Q) rm -f $(SETP_TMP) endif $(RFILL_CSRC) : $(BLITDIR)/nxglib_fillrectangle.c nxglib_bitblit.h ifneq ($(NXGLIB_BITSPERPIXEL),) - @$(call PREPROCESS, $(BLITDIR)/nxglib_fillrectangle.c, $(RFILL_TMP)) - @cat $(RFILL_TMP) | sed -e "/^#/d" >$@ - @rm -f $(RFILL_TMP) + $(call PREPROCESS, $(BLITDIR)/nxglib_fillrectangle.c, $(RFILL_TMP)) + $(Q) cat $(RFILL_TMP) | sed -e "/^#/d" >$@ + $(Q) rm -f $(RFILL_TMP) endif $(RGET_CSRC) : $(BLITDIR)/nxglib_getrectangle.c nxglib_bitblit.h ifneq ($(NXGLIB_BITSPERPIXEL),) - @$(call PREPROCESS, $(BLITDIR)/nxglib_getrectangle.c, $(RGET_TMP)) - @cat $(RGET_TMP) | sed -e "/^#/d" >$@ - @rm -f $(RGET_TMP) + $(call PREPROCESS, $(BLITDIR)/nxglib_getrectangle.c, $(RGET_TMP)) + $(Q) cat $(RGET_TMP) | sed -e "/^#/d" >$@ + $(Q) rm -f $(RGET_TMP) endif $(TFILL_CSRC) : $(BLITDIR)/nxglib_filltrapezoid.c nxglib_bitblit.h ifneq ($(NXGLIB_BITSPERPIXEL),) - @$(call PREPROCESS, $(BLITDIR)/nxglib_filltrapezoid.c, $(TFILL_TMP)) - @cat $(TFILL_TMP) | sed -e "/^#/d" >$@ - @rm -f $(TFILL_TMP) + $(call PREPROCESS, $(BLITDIR)/nxglib_filltrapezoid.c, $(TFILL_TMP)) + $(Q) cat $(TFILL_TMP) | sed -e "/^#/d" >$@ + $(Q) rm -f $(TFILL_TMP) endif $(RMOVE_CSRC) : $(BLITDIR)/nxglib_moverectangle.c nxglib_bitblit.h ifneq ($(NXGLIB_BITSPERPIXEL),) - @$(call PREPROCESS, $(BLITDIR)/nxglib_moverectangle.c, $(RMOVE_TMP)) - @cat $(RMOVE_TMP) | sed -e "/^#/d" >$@ - @rm -f $(RMOVE_TMP) + $(call PREPROCESS, $(BLITDIR)/nxglib_moverectangle.c, $(RMOVE_TMP)) + $(Q) cat $(RMOVE_TMP) | sed -e "/^#/d" >$@ + $(Q) rm -f $(RMOVE_TMP) endif $(RCOPY_CSRC) : $(BLITDIR)/nxglib_copyrectangle.c nxglib_bitblit.h ifneq ($(NXGLIB_BITSPERPIXEL),) - @$(call PREPROCESS, $(BLITDIR)/nxglib_copyrectangle.c, $(RCOPY_TMP)) - @cat $(RCOPY_TMP) | sed -e "/^#/d" >$@ - @rm -f $(RCOPY_TMP) + $(call PREPROCESS, $(BLITDIR)/nxglib_copyrectangle.c, $(RCOPY_TMP)) + $(Q) cat $(RCOPY_TMP) | sed -e "/^#/d" >$@ + $(Q) rm -f $(RCOPY_TMP) endif clean: - @rm -f *~ .*.swp *.i + $(call DELFILE, *.i) + $(call CLEAN) distclean: clean - @rm -f nxglib_setpixel_*bpp.c - @rm -f nxglib_fillrectangle_*bpp.c - @rm -f nxglib_getrectangle_*bpp.c - @rm -f nxglib_filltrapezoid_*bpp.c - @rm -f nxglib_moverectangle_*bpp.c - @rm -f nxglib_copyrectangle_*bpp.c + $(call DELFILE, nxglib_setpixel_*bpp.c) + $(call DELFILE, nxglib_fillrectangle_*bpp.c) + $(call DELFILE, nxglib_getrectangle_*bpp.c) + $(call DELFILE, nxglib_filltrapezoid_*bpp.c) + $(call DELFILE, nxglib_moverectangle_*bpp.c) + $(call DELFILE, nxglib_copyrectangle_*bpp.c) diff --git a/nuttx/graphics/nxmu/nx_bitmap.c b/nuttx/graphics/nxmu/nx_bitmap.c index a86eda96a..a0bd748b0 100644 --- a/nuttx/graphics/nxmu/nx_bitmap.c +++ b/nuttx/graphics/nxmu/nx_bitmap.c @@ -100,6 +100,8 @@ int nx_bitmap(NXWINDOW hwnd, FAR const struct nxgl_rect_s *dest, FAR struct nxbe_window_s *wnd = (FAR struct nxbe_window_s *)hwnd; struct nxsvrmsg_bitmap_s outmsg; int i; + int ret; + sem_t sem_done; #ifdef CONFIG_DEBUG if (!wnd || !dest || !src || !origin) @@ -124,7 +126,32 @@ int nx_bitmap(NXWINDOW hwnd, FAR const struct nxgl_rect_s *dest, outmsg.origin.y = origin->y; nxgl_rectcopy(&outmsg.dest, dest); + + /* Create a semaphore for tracking command completion */ + + outmsg.sem_done = &sem_done; + ret = sem_init(&sem_done, 0, 0); + + if (ret != OK) + { + gdbg("sem_init failed: %d\n", errno); + return ret; + } + /* Forward the fill command to the server */ - return nxmu_sendwindow(wnd, &outmsg, sizeof(struct nxsvrmsg_bitmap_s)); + ret = nxmu_sendwindow(wnd, &outmsg, sizeof(struct nxsvrmsg_bitmap_s)); + + /* Wait that the command is completed, so that caller can release the buffer. */ + + if (ret == OK) + { + ret = sem_wait(&sem_done); + } + + /* Destroy the semaphore and return. */ + + sem_destroy(&sem_done); + + return ret; } diff --git a/nuttx/graphics/nxmu/nx_block.c b/nuttx/graphics/nxmu/nx_block.c index 3a051f9d7..7b198613c 100644 --- a/nuttx/graphics/nxmu/nx_block.c +++ b/nuttx/graphics/nxmu/nx_block.c @@ -140,7 +140,7 @@ int nx_block(NXWINDOW hwnd, FAR void *arg) * that it will not be blocked. */ - ret = nxmu_sendserver(wnd->conn, &outmsg, sizeof(struct nxbe_window_s)); + ret = nxmu_sendserver(wnd->conn, &outmsg, sizeof(struct nxsvrmsg_blocked_s)); } return ret; diff --git a/nuttx/graphics/nxmu/nx_getrectangle.c b/nuttx/graphics/nxmu/nx_getrectangle.c index f32065129..9b7d3679c 100644 --- a/nuttx/graphics/nxmu/nx_getrectangle.c +++ b/nuttx/graphics/nxmu/nx_getrectangle.c @@ -98,7 +98,9 @@ int nx_getrectangle(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect, { FAR struct nxbe_window_s *wnd = (FAR struct nxbe_window_s *)hwnd; struct nxsvrmsg_getrectangle_s outmsg; - + int ret; + sem_t sem_done; + #ifdef CONFIG_DEBUG if (!hwnd || !rect || !dest) { @@ -118,7 +120,31 @@ int nx_getrectangle(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect, nxgl_rectcopy(&outmsg.rect, rect); + /* Create a semaphore for tracking command completion */ + + outmsg.sem_done = &sem_done; + ret = sem_init(&sem_done, 0, 0); + + if (ret != OK) + { + gdbg("sem_init failed: %d\n", errno); + return ret; + } + /* Forward the fill command to the server */ - return nxmu_sendwindow(wnd, &outmsg, sizeof(struct nxsvrmsg_getrectangle_s)); + ret = nxmu_sendwindow(wnd, &outmsg, sizeof(struct nxsvrmsg_getrectangle_s)); + + /* Wait that the command is completed, so that caller can release the buffer. */ + + if (ret == OK) + { + ret = sem_wait(&sem_done); + } + + /* Destroy the semaphore and return. */ + + sem_destroy(&sem_done); + + return ret; } diff --git a/nuttx/graphics/nxmu/nxfe.h b/nuttx/graphics/nxmu/nxfe.h index 8b6a21ef4..b9e02616c 100644 --- a/nuttx/graphics/nxmu/nxfe.h +++ b/nuttx/graphics/nxmu/nxfe.h @@ -392,6 +392,7 @@ struct nxsvrmsg_getrectangle_s unsigned int plane; /* The plane number to read */ FAR uint8_t *dest; /* Memory location in which to store the graphics data */ unsigned int deststride; /* Width of the destination memory in bytes */ + sem_t *sem_done; /* Semaphore to report when command is done. */ }; /* Fill a trapezoidal region in the window with a color */ @@ -425,6 +426,7 @@ struct nxsvrmsg_bitmap_s FAR const void *src[CONFIG_NX_NPLANES]; /* The start of the source image. */ struct nxgl_point_s origin; /* Offset into the source image data */ unsigned int stride; /* The width of the full source image in pixels. */ + sem_t *sem_done; /* Semaphore to report when command is done. */ }; /* Set the color of the background */ @@ -586,6 +588,25 @@ EXTERN int nxmu_sendwindow(FAR struct nxbe_window_s *wnd, FAR const void *msg, EXTERN int nxmu_sendclient(FAR struct nxfe_conn_s *conn, FAR const void *msg, size_t msglen); +/**************************************************************************** + * Name: nxmu_sendclientwindow + * + * Description: + * Send a message to the client at NX_CLIMSG_PRIO priority + * + * Input Parameters: + * wnd - A pointer to the back-end window structure + * msg - A pointer to the message to send + * msglen - The length of the message in bytes. + * + * Return: + * OK on success; ERROR on failure with errno set appropriately + * + ****************************************************************************/ + +int nxmu_sendclientwindow(FAR struct nxbe_window_s *wnd, FAR const void *msg, + size_t msglen); + /**************************************************************************** * Name: nxmu_openwindow * diff --git a/nuttx/graphics/nxmu/nxmu_kbdin.c b/nuttx/graphics/nxmu/nxmu_kbdin.c index 2c658009b..0308c2bfa 100644 --- a/nuttx/graphics/nxmu/nxmu_kbdin.c +++ b/nuttx/graphics/nxmu/nxmu_kbdin.c @@ -108,7 +108,7 @@ void nxmu_kbdin(FAR struct nxfe_state_s *fe, uint8_t nch, FAR uint8_t *ch) outmsg->ch[i] = ch[i]; } - (void)nxmu_sendclient(fe->be.topwnd->conn, outmsg, size); + (void)nxmu_sendclientwindow(fe->be.topwnd, outmsg, size); free(outmsg); } } diff --git a/nuttx/graphics/nxmu/nxmu_mouse.c b/nuttx/graphics/nxmu/nxmu_mouse.c index 3ebe062d2..1b8f4a592 100644 --- a/nuttx/graphics/nxmu/nxmu_mouse.c +++ b/nuttx/graphics/nxmu/nxmu_mouse.c @@ -61,9 +61,10 @@ * Private Data ****************************************************************************/ -static struct nxgl_point_s g_mpos; -static struct nxgl_point_s g_mrange; -static uint8_t g_mbutton; +static struct nxgl_point_s g_mpos; +static struct nxgl_point_s g_mrange; +static uint8_t g_mbutton; +static struct nxbe_window_s *g_mwnd; /**************************************************************************** * Public Data @@ -129,7 +130,7 @@ int nxmu_mousereport(struct nxbe_window_s *wnd) outmsg.buttons = g_mbutton; nxgl_vectsubtract(&outmsg.pos, &g_mpos, &wnd->bounds.pt1); - return nxmu_sendclient(wnd->conn, &outmsg, sizeof(struct nxclimsg_mousein_s)); + return nxmu_sendclientwindow(wnd, &outmsg, sizeof(struct nxclimsg_mousein_s)); } } @@ -154,6 +155,7 @@ int nxmu_mousein(FAR struct nxfe_state_s *fe, struct nxbe_window_s *wnd; nxgl_coord_t x = pos->x; nxgl_coord_t y = pos->y; + uint8_t oldbuttons; int ret; /* Clip x and y to within the bounding rectangle */ @@ -182,20 +184,36 @@ int nxmu_mousein(FAR struct nxfe_state_s *fe, { /* Update the mouse value */ - g_mpos.x = x; - g_mpos.y = y; - g_mbutton = buttons; + oldbuttons = g_mbutton; + g_mpos.x = x; + g_mpos.y = y; + g_mbutton = buttons; - /* Pick the window to receive the mouse event. Start with - * the top window and go down. Stop with the first window - * that gets the mouse report + /* If a button is already down, regard this as part of a mouse drag + * event. Pass all the following events to the window where the drag + * started in. + */ + + if (oldbuttons && g_mwnd && g_mwnd->cb->mousein) + { + struct nxclimsg_mousein_s outmsg; + outmsg.msgid = NX_CLIMSG_MOUSEIN; + outmsg.wnd = g_mwnd; + outmsg.buttons = g_mbutton; + nxgl_vectsubtract(&outmsg.pos, &g_mpos, &g_mwnd->bounds.pt1); + + return nxmu_sendclientwindow(g_mwnd, &outmsg, sizeof(struct nxclimsg_mousein_s)); + } + + /* Pick the window to receive the mouse event. Start with the top + * window and go down. Stop with the first window that gets the mouse + * report */ for (wnd = fe->be.topwnd; wnd; wnd = wnd->below) { - /* The background window normally has no callback structure - * (unless a client has taken control of the background via - * nx_requestbkgd()). + /* The background window normally has no callback structure (unless + * a client has taken control of the background via nx_requestbkgd()). */ if (wnd->cb) @@ -207,6 +225,8 @@ int nxmu_mousein(FAR struct nxfe_state_s *fe, } } } + + g_mwnd = wnd; } return OK; diff --git a/nuttx/graphics/nxmu/nxmu_redrawreq.c b/nuttx/graphics/nxmu/nxmu_redrawreq.c index 32ca477a2..f54aa85a7 100644 --- a/nuttx/graphics/nxmu/nxmu_redrawreq.c +++ b/nuttx/graphics/nxmu/nxmu_redrawreq.c @@ -87,7 +87,7 @@ void nxfe_redrawreq(FAR struct nxbe_window_s *wnd, FAR const struct nxgl_rect_s outmsg.more = false; nxgl_rectoffset(&outmsg.rect, rect, -wnd->bounds.pt1.x, -wnd->bounds.pt1.y); - (void)nxmu_sendclient(wnd->conn, &outmsg, sizeof(struct nxclimsg_redraw_s)); + (void)nxmu_sendclientwindow(wnd, &outmsg, sizeof(struct nxclimsg_redraw_s)); } diff --git a/nuttx/graphics/nxmu/nxmu_reportposition.c b/nuttx/graphics/nxmu/nxmu_reportposition.c index f9b5f9daf..6ffb3f4ee 100644 --- a/nuttx/graphics/nxmu/nxmu_reportposition.c +++ b/nuttx/graphics/nxmu/nxmu_reportposition.c @@ -100,7 +100,7 @@ void nxfe_reportposition(FAR struct nxbe_window_s *wnd) /* And provide this to the client */ - ret = nxmu_sendclient(wnd->conn, &outmsg, sizeof(struct nxclimsg_newposition_s)); + ret = nxmu_sendclientwindow(wnd, &outmsg, sizeof(struct nxclimsg_newposition_s)); if (ret < 0) { gdbg("nxmu_sendclient failed: %d\n", errno); diff --git a/nuttx/graphics/nxmu/nxmu_sendwindow.c b/nuttx/graphics/nxmu/nxmu_sendwindow.c index 6f64ffff2..0826a45bc 100644 --- a/nuttx/graphics/nxmu/nxmu_sendwindow.c +++ b/nuttx/graphics/nxmu/nxmu_sendwindow.c @@ -112,3 +112,47 @@ int nxmu_sendwindow(FAR struct nxbe_window_s *wnd, FAR const void *msg, return ret; } + +/**************************************************************************** + * Name: nxmu_sendclientwindow + * + * Description: + * Send a message to the client at NX_CLIMSG_PRIO priority + * + * Input Parameters: + * wnd - A pointer to the back-end window structure + * msg - A pointer to the message to send + * msglen - The length of the message in bytes. + * + * Return: + * OK on success; ERROR on failure with errno set appropriately + * + ****************************************************************************/ + +int nxmu_sendclientwindow(FAR struct nxbe_window_s *wnd, FAR const void *msg, + size_t msglen) +{ + int ret = OK; + + /* Sanity checking */ + +#ifdef CONFIG_DEBUG + if (!wnd || !wnd->conn) + { + errno = EINVAL; + return ERROR; + } +#endif + + /* Ignore messages destined to a blocked window (no errors reported) */ + + if (!NXBE_ISBLOCKED(wnd)) + { + /* Send the message to the server */ + + ret = nxmu_sendclient(wnd->conn, msg, msglen); + } + + return ret; +} + diff --git a/nuttx/graphics/nxmu/nxmu_server.c b/nuttx/graphics/nxmu/nxmu_server.c index 2730e0ea2..cfaa5bbf5 100644 --- a/nuttx/graphics/nxmu/nxmu_server.c +++ b/nuttx/graphics/nxmu/nxmu_server.c @@ -451,6 +451,11 @@ int nx_runinstance(FAR const char *mqname, FAR NX_DRIVERTYPE *dev) { FAR struct nxsvrmsg_getrectangle_s *getmsg = (FAR struct nxsvrmsg_getrectangle_s *)buffer; nxbe_getrectangle(getmsg->wnd, &getmsg->rect, getmsg->plane, getmsg->dest, getmsg->deststride); + + if (getmsg->sem_done) + { + sem_post(getmsg->sem_done); + } } break; @@ -471,6 +476,11 @@ int nx_runinstance(FAR const char *mqname, FAR NX_DRIVERTYPE *dev) { FAR struct nxsvrmsg_bitmap_s *bmpmsg = (FAR struct nxsvrmsg_bitmap_s *)buffer; nxbe_bitmap(bmpmsg->wnd, &bmpmsg->dest, bmpmsg->src, &bmpmsg->origin, bmpmsg->stride); + + if (bmpmsg->sem_done) + { + sem_post(bmpmsg->sem_done); + } } break; diff --git a/nuttx/graphics/nxsu/nx_mousein.c b/nuttx/graphics/nxsu/nx_mousein.c index bee4a2265..5b268358b 100644 --- a/nuttx/graphics/nxsu/nx_mousein.c +++ b/nuttx/graphics/nxsu/nx_mousein.c @@ -62,9 +62,10 @@ * Private Data ****************************************************************************/ -static struct nxgl_point_s g_mpos; -static struct nxgl_point_s g_mrange; -static uint8_t g_mbutton; +static struct nxgl_point_s g_mpos; +static struct nxgl_point_s g_mrange; +static uint8_t g_mbutton; +static struct nxbe_window_s *g_mwnd; /**************************************************************************** * Public Data @@ -148,6 +149,7 @@ int nx_mousein(NXHANDLE handle, nxgl_coord_t x, nxgl_coord_t y, uint8_t buttons) { FAR struct nxfe_state_s *fe = (FAR struct nxfe_state_s *)handle; struct nxbe_window_s *wnd; + uint8_t oldbuttons; int ret; /* Clip x and y to within the bounding rectangle */ @@ -176,13 +178,27 @@ int nx_mousein(NXHANDLE handle, nxgl_coord_t x, nxgl_coord_t y, uint8_t buttons) { /* Update the mouse value */ + oldbuttons = g_mbutton; g_mpos.x = x; g_mpos.y = y; g_mbutton = buttons; - /* Pick the window to receive the mouse event. Start with - * the top window and go down. Step with the first window - * that gets the mouse report + /* If a button is already down, regard this as part of a mouse drag + * event. Pass all the following events to the window where the drag + * started in. + */ + + if (oldbuttons && g_mwnd && g_mwnd->cb->mousein) + { + struct nxgl_point_s relpos; + nxgl_vectsubtract(&relpos, &g_mpos, &g_mwnd->bounds.pt1); + g_mwnd->cb->mousein((NXWINDOW)g_mwnd, &relpos, g_mbutton, g_mwnd->arg); + return OK; + } + + /* Pick the window to receive the mouse event. Start with the top + * window and go down. Step with the first window that gets the mouse + * report */ for (wnd = fe->be.topwnd; wnd; wnd = wnd->below) @@ -193,6 +209,8 @@ int nx_mousein(NXHANDLE handle, nxgl_coord_t x, nxgl_coord_t y, uint8_t buttons) break; } } + + g_mwnd = wnd; } return OK; } diff --git a/nuttx/graphics/nxtk/nxtk_events.c b/nuttx/graphics/nxtk/nxtk_events.c index 33c50b7f9..facf92176 100644 --- a/nuttx/graphics/nxtk/nxtk_events.c +++ b/nuttx/graphics/nxtk/nxtk_events.c @@ -76,6 +76,9 @@ static void nxtk_mousein(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos, static void nxtk_kbdin(NXWINDOW hwnd, uint8_t nch, const uint8_t *ch, FAR void *arg); #endif +#ifdef CONFIG_NX_MULTIUSER +static void nxtk_blocked(NXWINDOW hwnd, FAR void *arg1, FAR void *arg2); +#endif /**************************************************************************** * Private Data @@ -95,6 +98,9 @@ const struct nx_callback_s g_nxtkcb = #ifdef CONFIG_NX_KBD , nxtk_kbdin /* kbdin */ #endif +#ifdef CONFIG_NX_MULTIUSER + , nxtk_blocked +#endif }; /**************************************************************************** @@ -255,9 +261,20 @@ static void nxtk_mousein(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos, nxgl_vectoradd(&abspos, pos, &fwnd->wnd.bounds.pt1); + /* In order to deliver mouse release events to the same window where the + * mouse down event happened, we store the initial mouse down location. + */ + + if (fwnd->mbutton == 0 && buttons != 0) + { + fwnd->mpos = abspos; + } + + fwnd->mbutton = buttons; + /* Is the mouse position inside of the client window region? */ - if (fwnd->fwcb->mousein && nxgl_rectinside(&fwnd->fwrect, &abspos)) + if (fwnd->fwcb->mousein && nxgl_rectinside(&fwnd->fwrect, &fwnd->mpos)) { nxgl_vectsubtract(&relpos, &abspos, &fwnd->fwrect.pt1); fwnd->fwcb->mousein((NXTKWINDOW)fwnd, &relpos, buttons, fwnd->fwarg); @@ -265,7 +282,7 @@ static void nxtk_mousein(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos, /* If the mouse position inside the toobar region? */ - else if (fwnd->tbcb->mousein && nxgl_rectinside(&fwnd->tbrect, &abspos)) + else if (fwnd->tbcb->mousein && nxgl_rectinside(&fwnd->tbrect, &fwnd->mpos)) { nxgl_vectsubtract(&relpos, &abspos, &fwnd->tbrect.pt1); fwnd->tbcb->mousein((NXTKWINDOW)fwnd, &relpos, buttons, fwnd->tbarg); @@ -292,6 +309,24 @@ static void nxtk_kbdin(NXWINDOW hwnd, uint8_t nch, const uint8_t *ch, } #endif +/**************************************************************************** + * Name: nxtk_blocked + ****************************************************************************/ + +#ifdef CONFIG_NX_MULTIUSER +static void nxtk_blocked(NXWINDOW hwnd, FAR void *arg1, FAR void *arg2) +{ + FAR struct nxtk_framedwindow_s *fwnd = (FAR struct nxtk_framedwindow_s *)hwnd; + + /* Only the client window gets keyboard input */ + + if (fwnd->fwcb->blocked) + { + fwnd->fwcb->blocked((NXTKWINDOW)fwnd, fwnd->fwarg, arg2); + } +} +#endif + /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/nuttx/graphics/nxtk/nxtk_internal.h b/nuttx/graphics/nxtk/nxtk_internal.h index 87a098845..3a31215d8 100644 --- a/nuttx/graphics/nxtk/nxtk_internal.h +++ b/nuttx/graphics/nxtk/nxtk_internal.h @@ -72,6 +72,11 @@ struct nxtk_framedwindow_s struct nxgl_rect_s fwrect; FAR const struct nx_callback_s *fwcb; FAR void *fwarg; + + /* Initial mouse down location */ + + uint8_t mbutton; + struct nxgl_point_s mpos; }; /**************************************************************************** diff --git a/nuttx/include/cxx/cstdbool b/nuttx/include/cxx/cstdbool index d2f0639d2..192fde490 100644 --- a/nuttx/include/cxx/cstdbool +++ b/nuttx/include/cxx/cstdbool @@ -46,4 +46,13 @@ // Namespace //*************************************************************************** +//*************************************************************************** +// Namespace +//*************************************************************************** + +namespace std +{ + using ::_Bool8; +} + #endif // __INCLUDE_CXX_CSTDBOOL diff --git a/nuttx/include/cxx/cstdio b/nuttx/include/cxx/cstdio index 900d429cb..6a9620e1a 100644 --- a/nuttx/include/cxx/cstdio +++ b/nuttx/include/cxx/cstdio @@ -52,6 +52,8 @@ namespace std using ::FILE; using ::fpos_t; using ::size_t; + + using ::clearerr; using ::fclose; using ::fflush; using ::feof; @@ -69,16 +71,24 @@ namespace std using ::ftell; using ::fwrite; using ::gets; + using ::ungetc; + using ::printf; using ::puts; using ::rename; using ::sprintf; + using ::asprintf; using ::snprintf; - using ::ungetc; + using ::sscanf; + using ::perror; + using ::vprintf; using ::vfprintf; using ::vsprintf; + using ::avsprintf; using ::vsnprintf; + using ::vsscanf; + using ::fdopen; using ::statfs; } diff --git a/nuttx/include/elf32.h b/nuttx/include/elf32.h new file mode 100644 index 000000000..e16ae0091 --- /dev/null +++ b/nuttx/include/elf32.h @@ -0,0 +1,352 @@ +/**************************************************************************** + * include/elf32.h + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Reference: System V Application Binary Interface, Edition 4.1, March 18, + * 1997, The Santa Cruz Operation, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_ELF32_H +#define __INCLUDE_ELF32_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Values for Elf32_Ehdr::e_type */ + +#define ET_NONE 0 /* No file type */ +#define ET_REL 1 /* Relocatable file */ +#define ET_EXEC 2 /* Executable file */ +#define ET_DYN 3 /* Shared object file */ +#define ET_CORE 4 /* Core file */ +#define ET_LOPROC 0xff00 /* Processor-specific */ +#define ET_HIPROC 0xffff /* Processor-specific */ + +/* Values for Elf32_Ehdr::e_machine (most of this were not included in the + * original SCO document but have been gleaned from elsewhere). + */ + +#define EM_NONE 0 /* No machine */ +#define EM_M32 1 /* AT&T WE 32100 */ +#define EM_SPARC 2 /* SPARC */ +#define EM_386 3 /* Intel 80386 */ +#define EM_68K 4 /* Motorola 68000 */ +#define EM_88K 5 /* Motorola 88000 */ +#define EM_486 6 /* Intel 486+ */ +#define EM_860 7 /* Intel 80860 */ +#define EM_MIPS 8 /* MIPS R3000 Big-Endian */ +#define EM_MIPS_RS4_BE 10 /* MIPS R4000 Big-Endian */ +#define EM_PARISC 15 /* HPPA */ +#define EM_SPARC32PLUS 18 /* Sun's "v8plus" */ +#define EM_PPC 20 /* PowerPC */ +#define EM_PPC64 21 /* PowerPC64 */ +#define EM_ARM 40 /* ARM */ +#define EM_SH 42 /* SuperH */ +#define EM_SPARCV9 43 /* SPARC v9 64-bit */ +#define EM_IA_64 50 /* HP/Intel IA-64 */ +#define EM_X86_64 62 /* AMD x86-64 */ +#define EM_S390 22 /* IBM S/390 */ +#define EM_CRIS 76 /* Axis Communications 32-bit embedded processor */ +#define EM_V850 87 /* NEC v850 */ +#define EM_M32R 88 /* Renesas M32R */ +#define EM_H8_300 46 +#define EM_ALPHA 0x9026 +#define EM_CYGNUS_V850 0x9080 +#define EM_CYGNUS_M32R 0x9041 +#define EM_S390_OLD 0xa390 +#define EM_FRV 0x5441 + +/* Values for Elf32_Ehdr::e_version */ + +#define EV_NONE 0 /* Invalid version */ +#define EV_CURRENT 1 /* The current version */ + +/* Ehe ELF identifier */ + +#define EI_MAG0 0 /* File identification */ +#define EI_MAG1 1 /* " " " " */ +#define EI_MAG2 2 /* " " " " */ +#define EI_MAG3 3 /* " " " " */ +#define EI_CLASS 4 /* File class */ +#define EI_DATA 5 /* Data encoding */ +#define EI_VERSION 6 /* File version */ +#define EI_PAD 7 /* Start of padding bytes */ +#define EI_NIDENT 16 /* Size of eident[] */ + +#define EI_MAGIC_SIZE 4 +#define EI_MAGIC {0x7f, 'E', 'L', 'F'} + +/* Values for EI_CLASS */ + +#define ELFCLASSNONE 0 /* Invalid class */ +#define ELFCLASS32 1 /* 32-bit objects */ +#define ELFCLASS64 2 /* 64-bit objects */ + +/* Values for EI_DATA */ + +#define ELFDATANONE 0 /* Invalid data encoding */ +#define ELFDATA2LSB 1 /* Least significant byte occupying the lowest address */ +#define ELFDATA2MSB 2 /* Most significant byte occupying the lowest address */ + +/* Figure 4-7: Special Section Indexes */ + +#define SHN_UNDEF 0 +#define SHN_LORESERVE 0xff00 +#define SHN_LOPROC 0xff00 +#define SHN_HIPROC 0xff1f +#define SHN_ABS 0xfff1 +#define SHN_COMMON 0xfff2 +#define SHN_HIRESERVE 0xffff + +/* Figure 4-9: Section Types, sh_type */ + +#define SHT_NULL 0 +#define SHT_PROGBITS 1 +#define SHT_SYMTAB 2 +#define SHT_STRTAB 3 +#define SHT_RELA 4 +#define SHT_HASH 5 +#define SHT_DYNAMIC 6 +#define SHT_NOTE 7 +#define SHT_NOBITS 8 +#define SHT_REL 9 +#define SHT_SHLIB 10 +#define SHT_DYNSYM 11 +#define SHT_LOPROC 0x70000000 +#define SHT_HIPROC 0x7fffffff +#define SHT_LOUSER 0x80000000 +#define SHT_HIUSER 0xffffffff + +/* Figure 4-11: Section Attribute Flags, sh_flags */ + +#define SHF_WRITE 1 +#define SHF_ALLOC 2 +#define SHF_EXECINSTR 4 +#define SHF_MASKPROC 0xf0000000 + +/* Definitions for Elf32_Sym::st_info */ + +#define ELF32_ST_BIND(i) ((i) >> 4) +#define ELF32_ST_TYPE(i) ((i) & 0xf) +#define ELF32_ST_INFO(b,t) (((b) << 4) | ((t) & 0xf)) + +/* Figure 4-16: Symbol Binding, ELF32_ST_BIND */ + +#define STB_LOCAL 0 +#define STB_GLOBAL 1 +#define STB_WEAK 2 +#define STB_LOPROC 13 +#define STB_HIPROC 15 + +/* Figure 4-17: Symbol Types, ELF32_ST_TYPE */ + +#define STT_NOTYPE 0 +#define STT_OBJECT 1 +#define STT_FUNC 2 +#define STT_SECTION 3 +#define STT_FILE 4 +#define STT_LOPROC 13 +#define STT_HIPROC 15 + +/* Definitions for Elf32_Rel*::r_info */ + +#define ELF32_R_SYM(i) ((i) >> 8) +#define ELF32_R_TYPE(i) ((i) & 0xff) +#define ELF32_R_INFO(s,t) (((s)<< 8) | ((t) & 0xff)) + +/* Figure 5-2: Segment Types, p_type */ + +#define PT_NULL 0 +#define PT_LOAD 1 +#define PT_DYNAMIC 2 +#define PT_INTERP 3 +#define PT_NOTE 4 +#define PT_SHLIB 5 +#define PT_PHDR 6 +#define PT_LOPROC 0x70000000 +#define PT_HIPROC 0x7fffffff + +/* Figure 5-3: Segment Flag Bits, p_flags */ + +#define PF_X 1 /* Execute */ +#define PF_W 2 /* Write */ +#define PF_R 4 /* Read */ +#define PF_MASKPROC 0xf0000000 /* Unspecified */ + +/* Figure 5-10: Dynamic Array Tags, d_tag */ + +#define DT_NULL 0 /* d_un=ignored */ +#define DT_NEEDED 1 /* d_un=d_val */ +#define DT_PLTRELSZ 2 /* d_un=d_val */ +#define DT_PLTGOT 3 /* d_un=d_ptr */ +#define DT_HASH 4 /* d_un=d_ptr */ +#define DT_STRTAB 5 /* d_un=d_ptr */ +#define DT_SYMTAB 6 /* d_un=d_ptr */ +#define DT_RELA 7 /* d_un=d_ptr */ +#define DT_RELASZ 8 /* d_un=d_val */ +#define DT_RELAENT 9 /* d_un=d_val */ +#define DT_STRSZ 10 /* d_un=d_val */ +#define DT_SYMENT 11 /* d_un=d_val */ +#define DT_INIT 12 /* d_un=d_ptr */ +#define DT_FINI 13 /* d_un=d_ptr */ +#define DT_SONAME 14 /* d_un=d_val */ +#define DT_RPATH 15 /* d_un=d_val */ +#define DT_SYMBOLIC 16 /* d_un=ignored */ +#define DT_REL 17 /* d_un=d_ptr */ +#define DT_RELSZ 18 /* d_un=d_val */ +#define DT_RELENT 19 /* d_un=d_val */ +#define DT_PLTREL 20 /* d_un=d_val */ +#define DT_DEBUG 21 /* d_un=d_ptr */ +#define DT_TEXTREL 22 /* d_un=ignored */ +#define DT_JMPREL 23 /* d_un=d_ptr */ +#define DT_BINDNOW 24 /* d_un=ignored */ +#define DT_LOPROC 0x70000000 /* d_un=unspecified */ +#define DT_HIPROC 0x7fffffff /* d_un= unspecified */ + +/**************************************************************************** + * Public Type Definitions + ****************************************************************************/ + +/* Figure 4.2: 32-Bit Data Types */ + +typedef uint32_t Elf32_Addr; /* Unsigned program address */ +typedef uint16_t Elf32_Half; /* Unsigned medium integer */ +typedef uint32_t Elf32_Off; /* Unsigned file offset */ +typedef int32_t Elf32_Sword; /* Signed large integer */ +typedef uint32_t Elf32_Word; /* Unsigned large integer */ + +/* Figure 4-3: ELF Header */ + +typedef struct +{ + unsigned char e_ident[EI_NIDENT]; + Elf32_Half e_type; + Elf32_Half e_machine; + Elf32_Word e_version; + Elf32_Addr e_entry; + Elf32_Off e_phoff; + Elf32_Off e_shoff; + Elf32_Word e_flags; + Elf32_Half e_ehsize; + Elf32_Half e_phentsize; + Elf32_Half e_phnum; + Elf32_Half e_shentsize; + Elf32_Half e_shnum; + Elf32_Half e_shstrndx; +} Elf32_Ehdr; + +/* Figure 4-8: Section Header */ + +typedef struct +{ + Elf32_Word sh_name; + Elf32_Word sh_type; + Elf32_Word sh_flags; + Elf32_Addr sh_addr; + Elf32_Off sh_offset; + Elf32_Word sh_size; + Elf32_Word sh_link; + Elf32_Word sh_info; + Elf32_Word sh_addralign; + Elf32_Word sh_entsize; +} Elf32_Shdr; + +/* Figure 4-15: Symbol Table Entry */ + +typedef struct +{ + Elf32_Word st_name; + Elf32_Addr st_value; + Elf32_Word st_size; + unsigned char st_info; + unsigned char st_other; + Elf32_Half st_shndx; +} Elf32_Sym; + +/* Figure 4-19: Relocation Entries */ + +typedef struct +{ + Elf32_Addr r_offset; + Elf32_Word r_info; +} Elf32_Rel; + +typedef struct +{ + Elf32_Addr r_offset; + Elf32_Word r_info; + Elf32_Sword r_addend; +} Elf32_Rela; + +/* Figure 5-1: Program Header */ + +typedef struct +{ + Elf32_Word p_type; + Elf32_Off p_offset; + Elf32_Addr p_vaddr; + Elf32_Addr p_paddr; + Elf32_Word p_filesz; + Elf32_Word p_memsz; + Elf32_Word p_flags; + Elf32_Word p_align; +} Elf32_Phdr; + +/* Figure 5-9: Dynamic Structure */ + +typedef struct +{ + Elf32_Sword d_tag; + union + { + Elf32_Word d_val; + Elf32_Addr d_ptr; + } d_un; +} Elf32_Dyn; + +//extern Elf32_Dyn _DYNAMIC[] ; + +#endif /* __INCLUDE_ELF32_H */ diff --git a/nuttx/include/net/if.h b/nuttx/include/net/if.h index e64b58563..1ff8ebc38 100644 --- a/nuttx/include/net/if.h +++ b/nuttx/include/net/if.h @@ -52,6 +52,10 @@ #define IF_NAMESIZE 6 /* Newer naming standard */ #define IFHWADDRLEN 6 +#define IFF_RUNNING (1 << 0) +#define IF_FLAG_IFUP (1 << 0) +#define IF_FLAG_IFDOWN (2 << 0) + /******************************************************************************************* * Public Type Definitions *******************************************************************************************/ @@ -72,6 +76,7 @@ struct lifreq struct sockaddr lifru_hwaddr; /* MAC address */ int lifru_count; /* Number of devices */ int lifru_mtu; /* MTU size */ + uint8_t lifru_flags; /* Interface flags */ } lifr_ifru; }; @@ -82,6 +87,7 @@ struct lifreq #define lifr_hwaddr lifr_ifru.lifru_hwaddr /* MAC address */ #define lifr_mtu lifr_ifru.lifru_mtu /* MTU */ #define lifr_count lifr_ifru.lifru_count /* Number of devices */ +#define lifr_flags lifr_ifru.lifru_flags /* interface flags */ /* This is the older I/F request that should only be used with IPv4. However, since * NuttX only supports IPv4 or 6 (not both), we can force the older structure to @@ -101,6 +107,7 @@ struct ifreq struct sockaddr ifru_hwaddr; /* MAC address */ int ifru_count; /* Number of devices */ int ifru_mtu; /* MTU size */ + uint8_t ifru_flags; /* Interface flags */ } ifr_ifru; }; @@ -111,6 +118,7 @@ struct ifreq #define ifr_hwaddr ifr_ifru.ifru_hwaddr /* MAC address */ #define ifr_mtu ifr_ifru.ifru_mtu /* MTU */ #define ifr_count ifr_ifru.ifru_count /* Number of devices */ +#define ifr_flags ifr_ifru.ifru_flags /* interface flags */ #else /* CONFIG_NET_IPv6 */ @@ -123,6 +131,7 @@ struct ifreq #define ifr_hwaddr lifr_ifru.lifru_hwaddr /* MAC address */ #define ifr_mtu lifr_ifru.lifru_mtu /* MTU */ #define ifr_count lifr_ifru.lifru_count /* Number of devices */ +#define ifr_flags lifr_ifru.lifru_flags /* interface flags */ #endif /* CONFIG_NET_IPv6 */ diff --git a/nuttx/include/nuttx/binfmt.h b/nuttx/include/nuttx/binfmt.h deleted file mode 100644 index 70beda393..000000000 --- a/nuttx/include/nuttx/binfmt.h +++ /dev/null @@ -1,209 +0,0 @@ -/**************************************************************************** - * include/nuttx/binfmt.h - * - * Copyright (C) 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -#ifndef __INCLUDE_NUTTX_BINFMT_H -#define __INCLUDE_NUTTX_BINFMT_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/* This describes the file to be loaded */ - -struct symtab_s; -struct binary_s -{ - /* Information provided to the loader to load and bind a module */ - - FAR const char *filename; /* Full path to the binary to be loaded */ - FAR const char **argv; /* Argument list */ - FAR const struct symtab_s *exports; /* Table of exported symbols */ - int nexports; /* The number of symbols in exports[] */ - - /* Information provided from the loader (if successful) describing the - * resources used by the loaded module. - */ - - main_t entrypt; /* Entry point into a program module */ - FAR void *ispace; /* Memory-mapped, I-space (.text) address */ - FAR struct dspace_s *dspace; /* Address of the allocated .data/.bss space */ - size_t isize; /* Size of the I-space region (needed for munmap) */ - size_t stacksize; /* Size of the stack in bytes (unallocated) */ -}; - -/* This describes one binary format handler */ - -struct binfmt_s -{ - FAR struct binfmt_s *next; /* Supports a singly-linked list */ - int (*load)(FAR struct binary_s *bin); /* Verify and load binary into memory */ -}; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -#undef EXTERN -#if defined(__cplusplus) -#define EXTERN extern "C" -extern "C" { -#else -#define EXTERN extern -#endif - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Name: register_binfmt - * - * Description: - * Register a loader for a binary format - * - * Returned Value: - * This is a NuttX internal function so it follows the convention that - * 0 (OK) is returned on success and a negated errno is returned on - * failure. - * - ****************************************************************************/ - -EXTERN int register_binfmt(FAR struct binfmt_s *binfmt); - -/**************************************************************************** - * Name: unregister_binfmt - * - * Description: - * Register a loader for a binary format - * - * Returned Value: - * This is a NuttX internal function so it follows the convention that - * 0 (OK) is returned on success and a negated errno is returned on - * failure. - * - ****************************************************************************/ - -EXTERN int unregister_binfmt(FAR struct binfmt_s *binfmt); - -/**************************************************************************** - * Name: load_module - * - * Description: - * Load a module into memory, bind it to an exported symbol take, and - * prep the module for execution. - * - * Returned Value: - * This is an end-user function, so it follows the normal convention: - * Returns 0 (OK) on success. On failure, it returns -1 (ERROR) with - * errno set appropriately. - * - ****************************************************************************/ - -EXTERN int load_module(FAR struct binary_s *bin); - -/**************************************************************************** - * Name: unload_module - * - * Description: - * Unload a (non-executing) module from memory. If the module has - * been started (via exec_module), calling this will be fatal. - * - * Returned Value: - * This is a NuttX internal function so it follows the convention that - * 0 (OK) is returned on success and a negated errno is returned on - * failure. - * - ****************************************************************************/ - -EXTERN int unload_module(FAR const struct binary_s *bin); - -/**************************************************************************** - * Name: exec_module - * - * Description: - * Execute a module that has been loaded into memory by load_module(). - * - * 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. - * - ****************************************************************************/ - -EXTERN int exec_module(FAR const struct binary_s *bin, int priority); - -/**************************************************************************** - * Name: exec - * - * Description: - * This is a convenience function that wraps load_ and exec_module into - * one call. - * - * Input Parameter: - * filename - Fulll path to the binary to be loaded - * argv - Argument list - * exports - Table of exported symbols - * nexports - The number of symbols in exports - * - * 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. - * - ****************************************************************************/ - -EXTERN int exec(FAR const char *filename, FAR const char **argv, - FAR const struct symtab_s *exports, int nexports); - -#undef EXTERN -#if defined(__cplusplus) -} -#endif - -#endif /* __INCLUDE_NUTTX_BINFMT_H */ - diff --git a/nuttx/include/nuttx/binfmt/symtab.h b/nuttx/include/nuttx/binfmt/symtab.h new file mode 100644 index 000000000..346c6099f --- /dev/null +++ b/nuttx/include/nuttx/binfmt/symtab.h @@ -0,0 +1,163 @@ +/**************************************************************************** + * include/nuttx/binfmt/symtab.h + * + * Copyright (C) 2009 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_BINFMT_SYMTAB_H +#define __INCLUDE_NUTTX_BINFMT_SYMTAB_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/* struct symbtab_s describes one entry in the symbol table. A symbol table + * is a fixed size array of struct symtab_s. The information is intentionally + * minimal and supports only: + * + * 1. Function pointers as sym_values. Of other kinds of values need to be + * supported, then typing information would also need to be included in + * the structure. + * + * 2. Fixed size arrays. There is no explicit provisional for dyanamically + * adding or removing entries from the symbol table (realloc might be + * used for that purpose if needed). The intention is to support only + * fixed size arrays completely defined at compilation or link time. + */ + +struct symtab_s +{ + FAR const char *sym_name; /* A pointer to the symbol name string */ + FAR const void *sym_value; /* The value associated witht the string */ +}; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +#undef EXTERN +#if defined(__cplusplus) +#define EXTERN extern "C" +extern "C" { +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Name: symtab_findbyname + * + * Description: + * Find the symbol in the symbol table with the matching name. + * This version assumes that table is not ordered with respect to symbol + * name and, hence, access time will be linear with respect to nsyms. + * + * Returned Value: + * A reference to the symbol table entry if an entry with the matching + * name is found; NULL is returned if the entry is not found. + * + ****************************************************************************/ + +EXTERN FAR const struct symtab_s * +symtab_findbyname(FAR const struct symtab_s *symtab, + FAR const char *name, int nsyms); + +/**************************************************************************** + * Name: symtab_findorderedbyname + * + * Description: + * Find the symbol in the symbol table with the matching name. + * This version assumes that table ordered with respect to symbol name. + * + * Returned Value: + * A reference to the symbol table entry if an entry with the matching + * name is found; NULL is returned if the entry is not found. + * + ****************************************************************************/ + +EXTERN FAR const struct symtab_s * +symtab_findorderedbyname(FAR const struct symtab_s *symtab, + FAR const char *name, int nsyms); + +/**************************************************************************** + * Name: symtab_findbyvalue + * + * Description: + * Find the symbol in the symbol table whose value closest (but not greater + * than), the provided value. This version assumes that table is not ordered + * with respect to symbol name and, hence, access time will be linear with + * respect to nsyms. + * + * Returned Value: + * A reference to the symbol table entry if an entry with the matching + * name is found; NULL is returned if the entry is not found. + * + ****************************************************************************/ + +EXTERN FAR const struct symtab_s * +symtab_findbyvalue(FAR const struct symtab_s *symtab, + FAR void *value, int nsyms); + +/**************************************************************************** + * Name: symtab_findorderedbyvalue + * + * Description: + * Find the symbol in the symbol table whose value closest (but not greater + * than), the provided value. This version assumes that table is ordered + * with respect to symbol name. + * + * Returned Value: + * A reference to the symbol table entry if an entry with the matching + * name is found; NULL is returned if the entry is not found. + * + ****************************************************************************/ + +EXTERN FAR const struct symtab_s * +symtab_findorderedbyvalue(FAR const struct symtab_s *symtab, + FAR void *value, int nsyms); + +#undef EXTERN +#if defined(__cplusplus) +} +#endif + +#endif /* __INCLUDE_NUTTX_BINFMT_SYMTAB_H */ + diff --git a/nuttx/include/nuttx/compiler.h b/nuttx/include/nuttx/compiler.h index d8f79fe9e..6ad51ad0f 100644 --- a/nuttx/include/nuttx/compiler.h +++ b/nuttx/include/nuttx/compiler.h @@ -87,11 +87,16 @@ # define packed_struct __attribute__ ((packed)) -/* GCC does not support the reentrant or naked attributes */ +/* GCC does not support the reentrant attribute */ # define reentrant_function -# define naked_function +/* The naked attribute informs GCC that the programmer will take care of + * the function prolog and epilog. + */ + +# define naked_function __attribute__ ((naked,no_instrument_function)) + /* The inline_function attribute informs GCC that the function should always * be inlined, regardless of the level of optimization. The noinline_function * indicates that the function should never be inlined. @@ -191,8 +196,10 @@ /* GCC supports both types double and long long */ -# define CONFIG_HAVE_DOUBLE 1 # define CONFIG_HAVE_LONG_LONG 1 +# define CONFIG_HAVE_FLOAT 1 +# define CONFIG_HAVE_DOUBLE 1 +# define CONFIG_HAVE_LONG_DOUBLE 1 /* Structures and unions can be assigned and passed as values */ @@ -295,7 +302,9 @@ /* SDCC does not support type long long or type double */ # undef CONFIG_HAVE_LONG_LONG +# define CONFIG_HAVE_FLOAT 1 # undef CONFIG_HAVE_DOUBLE +# undef CONFIG_HAVE_LONG_DOUBLE /* Structures and unions cannot be passed as values or used * in assignments. @@ -398,8 +407,10 @@ * simply do not support long long or double. */ -# undef CONFIG_HAVE_DOUBLE # undef CONFIG_HAVE_LONG_LONG +# define CONFIG_HAVE_FLOAT 1 +# undef CONFIG_HAVE_DOUBLE +# undef CONFIG_HAVE_LONG_DOUBLE /* Structures and unions can be assigned and passed as values */ @@ -433,9 +444,11 @@ # undef CONFIG_LONG_IS_NOT_INT # undef CONFIG_PTR_IS_NOT_INT # undef CONFIG_HAVE_INLINE -# define inline +# define inline 1 # undef CONFIG_HAVE_LONG_LONG +# define CONFIG_HAVE_FLOAT 1 # undef CONFIG_HAVE_DOUBLE +# undef CONFIG_HAVE_LONG_DOUBLE # undef CONFIG_CAN_PASS_STRUCTS #endif diff --git a/nuttx/include/nuttx/float.h b/nuttx/include/nuttx/float.h new file mode 100644 index 000000000..a8e4aa28b --- /dev/null +++ b/nuttx/include/nuttx/float.h @@ -0,0 +1,225 @@ +/**************************************************************************** + * include/nuttx/float.h + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Reference: http://pubs.opengroup.org/onlinepubs/009695399/basedefs/float.h.html + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_FLOAT_H +#define __INCLUDE_NUTTX_FLOAT_H + +/* TODO: These values could vary with architectures toolchains. This + * logic should be move at least to the include/arch directory. + */ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Radix of exponent representation, b. */ + +#define FLT_RADIX 2 + +/* Number of base-FLT_RADIX digits in the floating-point significand, p. */ + +#define FLT_MANT_DIG 24 + +#if CONFIG_HAVE_DOUBLE +# define DBL_MANT_DIG 53 +#else +# define DBL_MANT_DIG FLT_MANT_DIG +#endif + +#ifdef CONFIG_HAVE_LONG_DOUBLE +# define LDBL_MANT_DIG DBL_MANT_DIG /* FIX ME */ +#else +# define LDBL_MANT_DIG DBL_MANT_DIG +#endif + +/* Number of decimal digits, n, such that any floating-point number in the + * widest supported floating type with pmax radix b digits can be rounded + * to a floating-point number with n decimal digits and back again without + * change to the value. + */ + +#define DECIMAL_DIG 10 + +/* Number of decimal digits, q, such that any floating-point number with q + * decimal digits can be rounded into a floating-point number with p radix + * b digits and back again without change to the q decimal digits. + */ + +#define FLT_DIG 6 + +#if CONFIG_HAVE_DOUBLE +# define DBL_DIG 15 /* 10 */ +#else +# define DBL_DIG FLT_DIG +#endif + +#ifdef CONFIG_HAVE_LONG_DOUBLE +# define LDBL_DIG DBL_DIG /* FIX ME */ +#else +# define LDBL_DIG DBL_DIG +#endif + +/* Minimum negative integer such that FLT_RADIX raised to that power minus + * 1 is a normalized floating-point number, emin. + */ + +#define FLT_MIN_EXP (-125) + +#if CONFIG_HAVE_DOUBLE +# define DBL_MIN_EXP (-1021) +#else +# define DBL_MIN_EXP FLT_MIN_EXP +#endif + +#ifdef CONFIG_HAVE_LONG_DOUBLE +# define LDBL_MIN_EXP DBL_MIN_EXP /* FIX ME */ +#else +# define LDBL_MIN_EXP DBL_MIN_EXP +#endif + +/* inimum negative integer such that 10 raised to that power is in the range + * of normalized floating-point numbers. + */ + +#define FLT_MIN_10_EXP (-37) + +#if CONFIG_HAVE_DOUBLE +# define DBL_MIN_10_EXP (-307) /* -37 */ +#else +# define DBL_MIN_10_EXP FLT_MIN_10_EXP +#endif + +#ifdef CONFIG_HAVE_LONG_DOUBLE +# define LDBL_MIN_10_EXP DBL_MIN_10_EXP /* FIX ME */ +#else +# define LDBL_MIN_10_EXP DBL_MIN_10_EXP +#endif + +/* Maximum integer such that FLT_RADIX raised to that power minus 1 is a + * representable finite floating-point number, emax. + */ + +#define FLT_MAX_EXP 128 + +#if CONFIG_HAVE_DOUBLE +# define DBL_MAX_EXP 1024 +#else +# define DBL_MAX_EXP FLT_MAX_EXP +#endif + +#ifdef CONFIG_HAVE_LONG_DOUBLE +# define LDBL_MAX_EXP DBL_MAX_EXP /* FIX ME */ +#else +# define LDBL_MAX_EXP DBL_MAX_EXP +#endif + +/* Maximum integer such that 10 raised to that power is in the range of + * representable finite floating-point numbers. + */ + +#define FLT_MAX_10_EXP 38 /* 37 */ + +#if CONFIG_HAVE_DOUBLE +# define DBL_MAX_10_EXP 308 /* 37 */ +#else +# define DBL_MAX_10_EXP FLT_MAX_10_EXP +#endif + +#ifdef CONFIG_HAVE_LONG_DOUBLE +# define LDBL_MAX_10_EXP DBL_MAX_10_EXP /* FIX ME */ +#else +# define LDBL_MAX_10_EXP DBL_MAX_10_EXP +#endif + +/* Maximum representable finite floating-point number. */ + +#define FLT_MAX 3.40282347e+38F /* 1E+37 */ + +#if CONFIG_HAVE_DOUBLE +# define DBL_MAX 1.7976931348623157e+308 /* 1E+37 */ +#else +# define DBL_MAX FLT_MAX +#endif + +#ifdef CONFIG_HAVE_LONG_DOUBLE +# define LDBL_MAX DBL_MAX /* FIX ME */ +#else +# define LDBL_MAX DBL_MAX +#endif + +/* The difference between 1 and the least value greater than 1 that is + * representable in the given floating-point type, b1-p. + */ + +#define FLT_EPSILON 1.1920929e-07F /* 1E-5 */ + +#if CONFIG_HAVE_DOUBLE +# define DBL_EPSILON 2.2204460492503131e-16 /* 1E-9 */ +#else +# define DBL_EPSILON FLT_EPSILON +#endif + +#ifdef CONFIG_HAVE_LONG_DOUBLE +# define LDBL_EPSILON DBL_EPSILON /* FIX ME */ +#else +# define LDBL_EPSILON DBL_EPSILON +#endif + +/* Minimum normalized positive floating-point number, bemin -1. */ + +#define FLT_MIN 1.17549435e-38F /* 1E-37 */ + +#if CONFIG_HAVE_DOUBLE +#define DBL_MIN 2.2250738585072014e-308 /* 1E-37 */ +#else +# define DBL_MIN FLT_MIN +#endif + +#ifdef CONFIG_HAVE_LONG_DOUBLE +# define LDBL_MIN DBL_MIN /* FIX ME */ +#else +# define LDBL_MIN DBL_MIN +#endif + +#endif /* __INCLUDE_NUTTX_FLOAT_H */ diff --git a/nuttx/include/nuttx/fs/fs.h b/nuttx/include/nuttx/fs/fs.h index 79090a8da..1759310bc 100644 --- a/nuttx/include/nuttx/fs/fs.h +++ b/nuttx/include/nuttx/fs/fs.h @@ -51,6 +51,10 @@ /**************************************************************************** * Definitions ****************************************************************************/ +/* Stream flags for the fs_flags field of in struct file_struct */ + +#define __FS_FLAG_EOF (1 << 0) /* EOF detected by a read operation */ +#define __FS_FLAG_ERROR (1 << 1) /* Error detected by any operation */ /**************************************************************************** * Type Definitions @@ -270,11 +274,6 @@ struct filelist struct file_struct { int fs_filedes; /* File descriptor associated with stream */ - uint16_t fs_oflags; /* Open mode flags */ -#if CONFIG_NUNGET_CHARS > 0 - uint8_t fs_nungotten; /* The number of characters buffered for ungetc */ - unsigned char fs_ungotten[CONFIG_NUNGET_CHARS]; -#endif #if CONFIG_STDIO_BUFFER_SIZE > 0 sem_t fs_sem; /* For thread safety */ pid_t fs_holder; /* Holder of sem */ @@ -283,6 +282,12 @@ struct file_struct FAR unsigned char *fs_bufend; /* Pointer to 1 past end of buffer */ FAR unsigned char *fs_bufpos; /* Current position in buffer */ FAR unsigned char *fs_bufread; /* Pointer to 1 past last buffered read char. */ +#endif + uint16_t fs_oflags; /* Open mode flags */ + uint8_t fs_flags; /* Stream flags */ +#if CONFIG_NUNGET_CHARS > 0 + uint8_t fs_nungotten; /* The number of characters buffered for ungetc */ + unsigned char fs_ungotten[CONFIG_NUNGET_CHARS]; #endif }; diff --git a/nuttx/include/nuttx/i2c.h b/nuttx/include/nuttx/i2c.h index ef3d9a388..23356ecd3 100644 --- a/nuttx/include/nuttx/i2c.h +++ b/nuttx/include/nuttx/i2c.h @@ -1,7 +1,7 @@ /**************************************************************************** * include/nuttx/i2c.h * - * Copyright(C) 2009-2011 Gregory Nutt. All rights reserved. + * Copyright(C) 2009-2012 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -47,6 +47,16 @@ /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ +/* If a dynamic timeout is selected, then a non-negative, non-zero micro- + * seconds per byte vale must be provided as well. + */ + +#ifdef CONFIG_STM32_I2C_DYNTIMEO +# if CONFIG_STM32_I2C_DYNTIMEO_USECPERBYTE < 1 +# warning "Ignoring CONFIG_STM32_I2C_DYNTIMEO because of CONFIG_STM32_I2C_DYNTIMEO_USECPERBYTE" +# undef CONFIG_STM32_I2C_DYNTIMEO +# endif +#endif /* I2C address calculation. Convert 7- and 10-bit address to 8-bit and * 16-bit read/write address @@ -323,24 +333,19 @@ EXTERN FAR struct i2c_dev_s *up_i2cinitialize(int port); * ****************************************************************************/ -EXTERN int up_i2cuninitialize(FAR struct i2c_dev_s * dev); +EXTERN int up_i2cuninitialize(FAR struct i2c_dev_s *dev); -/**************************************************************************** +/************************************************************************************ * Name: up_i2creset * * Description: - * Reset the port and the associated I2C bus. Useful when the bus or an - * attached slave has become wedged or unresponsive. + * Reset an I2C bus * - * Input Parameter: - * Device structure as returned by the up_i2cinitalize() - * - * Returned Value: - * OK on success, ERROR if the bus cannot be unwedged. - * - ****************************************************************************/ + ************************************************************************************/ -EXTERN int up_i2creset(FAR struct i2c_dev_s * dev); +#ifdef CONFIG_I2C_RESET +EXTERN int up_i2creset(FAR struct i2c_dev_s *dev); +#endif #undef EXTERN #if defined(__cplusplus) diff --git a/nuttx/include/nuttx/input/max11802.h b/nuttx/include/nuttx/input/max11802.h new file mode 100644 index 000000000..3d03bdd11 --- /dev/null +++ b/nuttx/include/nuttx/input/max11802.h @@ -0,0 +1,175 @@ +/**************************************************************************** + * include/nuttx/input/max11802.h + * + * Copyright (C) 2011 Gregory Nutt. All rights reserved. + * Authors: Gregory Nutt + * Petteri Aimonen + * + * References: + * "Low-Power, Ultra-Small Resistive Touch-Screen Controllers + * with I2C/SPI Interface" Maxim IC, Rev 3, 10/2010 + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_INPUT_MAX11802_H +#define __INCLUDE_NUTTX_INPUT_MAX11802_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include +#include + +#if defined(CONFIG_INPUT) && defined(CONFIG_INPUT_MAX11802) + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ +/* Configuration ************************************************************/ +/* SPI Frequency. Default: 100KHz */ + +#ifndef CONFIG_MAX11802_FREQUENCY +# define CONFIG_MAX11802_FREQUENCY 100000 +#endif + +/* Maximum number of threads than can be waiting for POLL events */ + +#ifndef CONFIG_MAX11802_NPOLLWAITERS +# define CONFIG_MAX11802_NPOLLWAITERS 2 +#endif + +#ifndef CONFIG_MAX11802_SPIMODE +# define CONFIG_MAX11802_SPIMODE SPIDEV_MODE0 +#endif + +/* Thresholds */ + +#ifndef CONFIG_MAX11802_THRESHX +# define CONFIG_MAX11802_THRESHX 12 +#endif + +#ifndef CONFIG_MAX11802_THRESHY +# define CONFIG_MAX11802_THRESHY 12 +#endif + +/* Check for some required settings. This can save the user a lot of time + * in getting the right configuration. + */ + +#ifdef CONFIG_DISABLE_SIGNALS +# error "Signals are required. CONFIG_DISABLE_SIGNALS must not be selected." +#endif + +#ifndef CONFIG_SCHED_WORKQUEUE +# error "Work queue support required. CONFIG_SCHED_WORKQUEUE must be selected." +#endif + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/* A reference to a structure of this type must be passed to the MAX11802 + * driver. This structure provides information about the configuration + * of the MAX11802 and provides some board-specific hooks. + * + * Memory for this structure is provided by the caller. It is not copied + * by the driver and is presumed to persist while the driver is active. The + * memory must be writable because, under certain circumstances, the driver + * may modify frequency or X plate resistance values. + */ + +struct max11802_config_s +{ + /* Device characterization */ + + uint32_t frequency; /* SPI frequency */ + + /* IRQ/GPIO access callbacks. These operations all hidden behind + * callbacks to isolate the MAX11802 driver from differences in GPIO + * interrupt handling by varying boards and MCUs. If possible, + * interrupts should be configured on both rising and falling edges + * so that contact and loss-of-contact events can be detected. + * + * attach - Attach the MAX11802 interrupt handler to the GPIO interrupt + * enable - Enable or disable the GPIO interrupt + * clear - Acknowledge/clear any pending GPIO interrupt + * pendown - Return the state of the pen down GPIO input + */ + + int (*attach)(FAR struct max11802_config_s *state, xcpt_t isr); + void (*enable)(FAR struct max11802_config_s *state, bool enable); + void (*clear)(FAR struct max11802_config_s *state); + bool (*pendown)(FAR struct max11802_config_s *state); +}; + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" { +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Name: max11802_register + * + * Description: + * Configure the MAX11802 to use the provided SPI device instance. This + * will register the driver as /dev/inputN where N is the minor device + * number + * + * Input Parameters: + * spi - An SPI driver instance + * config - Persistent board configuration data + * minor - The input device minor number + * + * Returned Value: + * Zero is returned on success. Otherwise, a negated errno value is + * returned to indicate the nature of the failure. + * + ****************************************************************************/ + +EXTERN int max11802_register(FAR struct spi_dev_s *spi, + FAR struct max11802_config_s *config, + int minor); + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif /* CONFIG_INPUT && CONFIG_INPUT_MAX11802 */ +#endif /* __INCLUDE_NUTTX_INPUT_MAX11802_H */ diff --git a/nuttx/include/nuttx/lcd/ug-2864ambag01.h b/nuttx/include/nuttx/lcd/ug-2864ambag01.h new file mode 100644 index 000000000..deb568981 --- /dev/null +++ b/nuttx/include/nuttx/lcd/ug-2864ambag01.h @@ -0,0 +1,245 @@ +/************************************************************************************** + * include/nuttx/lcd/ug-2864ambag01.h + * Driver for Univision UG-2864AMBAG01 OLED display (wih SH1101A controller) in SPI + * mode + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * References: + * 1. Product Specification (Preliminary), Part Name: OEL Display Module, Part ID: + * UG-2864AMBAG01, Doc No: SASI-9015-A, Univision Technology Inc. + * 2. SH1101A, 132 X 64 Dot Matrix OLED/PLED, Preliminary Segment/Common Driver with + * Controller, Sino Wealth + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************************/ + +#ifndef __INCLUDE_NUTTX_UG_8264AMBAG01_H +#define __INCLUDE_NUTTX_UG_8264AMBAG01_H + +/************************************************************************************** + * Included Files + **************************************************************************************/ + +#include + +#include + +#include + +#ifdef CONFIG_LCD_UG2864AMBAG01 + +/************************************************************************************** + * Pre-processor Definitions + **************************************************************************************/ +/* Configuration **********************************************************************/ +/* UG-2864AMBAG01 Configuration Settings: + * + * CONFIG_UG2864AMBAG01_SPIMODE - Controls the SPI mode + * CONFIG_UG2864AMBAG01_FREQUENCY - Define to use a different bus frequency + * CONFIG_UG2864AMBAG01_NINTERFACES - Specifies the number of physical UG-2864AMBAG01 + * devices that will be supported. + * + * Required LCD driver settings: + * + * CONFIG_LCD_UG28AMBAG01 - Enable UG-2864AMBAG01 support + * CONFIG_LCD_MAXCONTRAST should be 255, but any value >0 and <=255 will be accepted. + * CONFIG_LCD_MAXPOWER must be 1 + * + * Option LCD driver settings: + * CONFIG_LCD_LANDSCAPE, CONFIG_LCD_PORTRAIT, CONFIG_LCD_RLANDSCAPE, and + * CONFIG_LCD_RPORTRAIT - Display orientation. + * + * Required SPI driver settings: + * CONFIG_SPI_CMDDATA - Include support for cmd/data selection. + */ + +/* SPI Interface + * + * "The serial interface consists of serial clock SCL, serial data SI, A0 and + * CS . SI is shifted into an 8-bit shift register on every rising edge of + * SCL in the order of D7, D6, … and D0. A0 is sampled on every eighth clock + * and the data byte in the shift register is written to the display data RAM + * or command register in the same clock." + * + * MODE 3: + * Clock polarity: High (CPOL=1) + * Clock phase: Sample on trailing (rising edge) (CPHA 1) + */ + +#ifndef CONFIG_UG2864AMBAG01_SPIMODE +# define CONFIG_UG2864AMBAG01_SPIMODE SPIDEV_MODE3 +#endif + +/* "This module determines whether the input data is interpreted as data or + * command. When A0 = “H”, the inputs at D7 - D0 are interpreted as data and be + * written to display RAM. When A0 = “L”, the inputs at D7 - D0 are interpreted + * as command, they will be decoded and be written to the corresponding command + * registers. + */ + +#ifndef CONFIG_SPI_CMDDATA +# error "CONFIG_SPI_CMDDATA must be defined in your NuttX configuration" +#endif + +/* CONFIG_UG2864AMBAG01_NINTERFACES determines the number of physical interfaces + * that will be supported. + */ + +#ifndef CONFIG_UG2864AMBAG01_NINTERFACES +# define CONFIG_UG2864AMBAG01_NINTERFACES 1 +#endif + +/* Check contrast selection */ + +#if !defined(CONFIG_LCD_MAXCONTRAST) +# define CONFIG_LCD_MAXCONTRAST 255 +#endif + +#if CONFIG_LCD_MAXCONTRAST <= 0|| CONFIG_LCD_MAXCONTRAST > 255 +# error "CONFIG_LCD_MAXCONTRAST exceeds supported maximum" +#endif + +#if CONFIG_LCD_MAXCONTRAST < 255 +# warning "Optimal setting of CONFIG_LCD_MAXCONTRAST is 255" +#endif + +/* Check power setting */ + +#if !defined(CONFIG_LCD_MAXPOWER) +# define CONFIG_LCD_MAXPOWER 1 +#endif + +#if CONFIG_LCD_MAXPOWER != 1 +# warning "CONFIG_LCD_MAXPOWER exceeds supported maximum" +# undef CONFIG_LCD_MAXPOWER +# define CONFIG_LCD_MAXPOWER 1 +#endif + +/* Color is 1bpp monochrome with leftmost column contained in bits 0 */ + +#ifdef CONFIG_NX_DISABLE_1BPP +# warning "1 bit-per-pixel support needed" +#endif + +/* Orientation */ + +#if defined(CONFIG_LCD_LANDSCAPE) +# undef CONFIG_LCD_PORTRAIT +# undef CONFIG_LCD_RLANDSCAPE +# undef CONFIG_LCD_RPORTRAIT +#elif defined(CONFIG_LCD_PORTRAIT) +# undef CONFIG_LCD_LANDSCAPE +# undef CONFIG_LCD_RLANDSCAPE +# undef CONFIG_LCD_RPORTRAIT +#elif defined(CONFIG_LCD_RLANDSCAPE) +# undef CONFIG_LCD_LANDSCAPE +# undef CONFIG_LCD_PORTRAIT +# undef CONFIG_LCD_RPORTRAIT +#elif defined(CONFIG_LCD_RPORTRAIT) +# undef CONFIG_LCD_LANDSCAPE +# undef CONFIG_LCD_PORTRAIT +# undef CONFIG_LCD_RLANDSCAPE +#else +# define CONFIG_LCD_LANDSCAPE 1 +# warning "Assuming landscape orientation" +#endif + +/* Some important "colors" */ + +#define UG_Y1_BLACK 0 +#define UG_Y1_WHITE 1 + +/************************************************************************************** + * Public Types + **************************************************************************************/ + +/************************************************************************************** + * Public Data + **************************************************************************************/ + +#ifdef __cplusplus +extern "C" +{ +#endif + +/************************************************************************************** + * Public Function Prototypes + **************************************************************************************/ + +/************************************************************************************** + * Name: ug2864ambag01_initialize + * + * Description: + * Initialize the UG-2864AMBAG01 video hardware. The initial state of the + * OLED is fully initialized, display memory cleared, and the OLED ready + * to use, but with the power setting at 0 (full off == sleep mode). + * + * Input Parameters: + * + * spi - A reference to the SPI driver instance. + * devno - A value in the range of 0 through CONFIG_UG2864AMBAG01_NINTERFACES-1. + * This allows support for multiple OLED devices. + * + * Returned Value: + * + * On success, this function returns a reference to the LCD object for + * the specified OLED. NULL is returned on any failure. + * + **************************************************************************************/ + +struct lcd_dev_s; /* See include/nuttx/lcd/lcd.h */ +struct spi_dev_s; /* See include/nuttx/spi.h */ +FAR struct lcd_dev_s *ug2864ambag01_initialize(FAR struct spi_dev_s *spi, + unsigned int devno); + +/************************************************************************************************ + * Name: ug2864ambag01_fill + * + * Description: + * This non-standard method can be used to clear the entire display by writing one + * color to the display. This is much faster than writing a series of runs. + * + * Input Parameters: + * priv - Reference to private driver structure + * + * Assumptions: + * Caller has selected the OLED section. + * + **************************************************************************************/ + +void ug2864ambag01_fill(FAR struct lcd_dev_s *dev, uint8_t color); + +#ifdef __cplusplus +} +#endif + +#endif /* CONFIG_LCD_UG2864AMBAG01 */ +#endif /* __INCLUDE_NUTTX_UG_8264AMBAG01_H */ diff --git a/nuttx/include/nuttx/lcd/ug-9664hswag01.h b/nuttx/include/nuttx/lcd/ug-9664hswag01.h index 696005b5d..b470e0895 100644 --- a/nuttx/include/nuttx/lcd/ug-9664hswag01.h +++ b/nuttx/include/nuttx/lcd/ug-9664hswag01.h @@ -3,7 +3,7 @@ * Driver for the Univision UG-9664HSWAG01 Display with the Solomon Systech * SSD1305 LCD controller. * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. + * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -58,8 +58,6 @@ * CONFIG_UG9664HSWAG01_POWER * If the hardware supports a controllable OLED a power supply, this * configuration shold be defined. (See ug_power() below). - * CONFIG_LCD_UGDEBUG - Enable detailed UG-9664HSWAG01 debug output - * (CONFIG_DEBUG and CONFIG_VERBOSE must also be enabled). * * Required LCD driver settings: * CONFIG_LCD_UG9664HSWAG01 - Enable UG-9664HSWAG01 support @@ -90,10 +88,8 @@ ****************************************************************************/ #ifdef __cplusplus -#define EXTERN extern "C" -extern "C" { -#else -#define EXTERN extern +extern "C" +{ #endif /**************************************************************************** @@ -123,7 +119,7 @@ extern "C" { struct lcd_dev_s; /* see nuttx/lcd.h */ struct spi_dev_s; /* see nuttx/spi.h */ -EXTERN FAR struct lcd_dev_s *ug_initialize(FAR struct spi_dev_s *spi, unsigned int devno); +FAR struct lcd_dev_s *ug_initialize(FAR struct spi_dev_s *spi, unsigned int devno); /**************************************************************************** * Name: ug_power @@ -145,12 +141,11 @@ EXTERN FAR struct lcd_dev_s *ug_initialize(FAR struct spi_dev_s *spi, unsigned i **************************************************************************************/ #ifdef CONFIG_UG9664HSWAG01_POWER -EXTERN void ug_power(unsigned int devno, bool on); +void ug_power(unsigned int devno, bool on); #else # define ug_power(a,b) #endif -#undef EXTERN #ifdef __cplusplus } #endif diff --git a/nuttx/include/nuttx/net/ioctl.h b/nuttx/include/nuttx/net/ioctl.h index be3f597f4..d5d1a001c 100644 --- a/nuttx/include/nuttx/net/ioctl.h +++ b/nuttx/include/nuttx/net/ioctl.h @@ -146,9 +146,15 @@ #define SIOCSIWPMKSA _SIOC(0x0036) /* PMKSA cache operation */ +/* Interface flags */ + +#define SIOCSIFFLAGS _SIOC(0x0037) /* Sets the interface flags */ +#define SIOCGIFFLAGS _SIOC(0x0038) /* Gets the interface flags */ + /**************************************************************************** * Type Definitions ****************************************************************************/ + /* See include/net/if.h */ /**************************************************************************** diff --git a/nuttx/include/nuttx/net/uip/uip-arch.h b/nuttx/include/nuttx/net/uip/uip-arch.h index 9546de04e..73805c6fb 100644 --- a/nuttx/include/nuttx/net/uip/uip-arch.h +++ b/nuttx/include/nuttx/net/uip/uip-arch.h @@ -90,6 +90,10 @@ struct uip_driver_s char d_ifname[IFNAMSIZ]; #endif + /* Drivers interface flags. See IFF_* definitions in include/net/if.h */ + + uint8_t d_flags; + /* Ethernet device identity */ #ifdef CONFIG_NET_ETHERNET diff --git a/nuttx/include/nuttx/nxflat.h b/nuttx/include/nuttx/nxflat.h deleted file mode 100644 index b6501522e..000000000 --- a/nuttx/include/nuttx/nxflat.h +++ /dev/null @@ -1,264 +0,0 @@ -/**************************************************************************** - * include/nuttx/nxflat.h - * - * Copyright (C) 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -#ifndef __INCLUDE_NUTTX_NXFLAT_H -#define __INCLUDE_NUTTX_NXFLAT_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/* This struct provides a desciption of the currently loaded instantiation - * of an nxflat binary. - */ - -struct nxflat_loadinfo_s -{ - /* Instruction Space (ISpace): This region contains the nxflat file header - * plus everything from the text section. Ideally, will have only one mmap'ed - * text section instance in the system for each module. - */ - - uint32_t ispace; /* Address where hdr/text is loaded */ - uint32_t entryoffs; /* Offset from ispace to entry point */ - uint32_t isize; /* Size of ispace. */ - - /* Data Space (DSpace): This region contains all information that in referenced - * as data (other than the stack which is separately allocated). There will be - * a unique instance of DSpace (and stack) for each instance of a process. - */ - - struct dspace_s *dspace; /* Allocated D-Space (data/bss/etc) */ - uint32_t datasize; /* Size of data segment in dspace */ - uint32_t bsssize; /* Size of bss segment in dspace */ - uint32_t stacksize; /* Size of stack (not allocated) */ - uint32_t dsize; /* Size of dspace (may be large than parts) */ - - /* This is temporary memory where relocation records will be loaded. */ - - uint32_t relocstart; /* Start of array of struct flat_reloc */ - uint16_t reloccount; /* Number of elements in reloc array */ - - /* File descriptors */ - - int filfd; /* Descriptor for the file being loaded */ - - /* This is a copy of the NXFLAT header (still in network order) */ - - struct nxflat_hdr_s header; -}; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -#undef EXTERN -#if defined(__cplusplus) -#define EXTERN extern "C" -extern "C" { -#else -#define EXTERN extern -#endif - -/**************************************************************************** - * These are APIs exported by libnxflat (and may be used outside of NuttX): - ****************************************************************************/ - -/*********************************************************************** - * Name: nxflat_verifyheader - * - * Description: - * Given the header from a possible NXFLAT executable, verify that it - * is an NXFLAT executable. - * - * Returned Value: - * 0 (OK) is returned on success and a negated errno is returned on - * failure. - * - ***********************************************************************/ - -EXTERN int nxflat_verifyheader(const struct nxflat_hdr_s *header); - -/*********************************************************************** - * Name: nxflat_init - * - * Description: - * This function is called to configure the library to process an NXFLAT - * program binary. - * - * Returned Value: - * 0 (OK) is returned on success and a negated errno is returned on - * failure. - * - ***********************************************************************/ - -EXTERN int nxflat_init(const char *filename, - struct nxflat_loadinfo_s *loadinfo); - -/*********************************************************************** - * Name: nxflat_uninit - * - * Description: - * Releases any resources committed by nxflat_init(). This essentially - * undoes the actions of nxflat_init. - * - * Returned Value: - * 0 (OK) is returned on success and a negated errno is returned on - * failure. - * - ***********************************************************************/ - -EXTERN int nxflat_uninit(struct nxflat_loadinfo_s *loadinfo); - -/*********************************************************************** - * Name: nxflat_load - * - * Description: - * Loads the binary specified by nxflat_init into memory, mapping - * the I-space executable regions, allocating the D-Space region, - * and inializing the data segment (relocation information is - * temporarily loaded into the BSS region. BSS will be cleared - * by nxflat_bind() after the relocation data has been processed). - * - * Returned Value: - * 0 (OK) is returned on success and a negated errno is returned on - * failure. - * - ***********************************************************************/ - -EXTERN int nxflat_load(struct nxflat_loadinfo_s *loadinfo); - -/*********************************************************************** - * Name: nxflat_read - * - * Description: - * Read 'readsize' bytes from the object file at 'offset' - * - * Returned Value: - * 0 (OK) is returned on success and a negated errno is returned on - * failure. - * - ***********************************************************************/ - -EXTERN int nxflat_read(struct nxflat_loadinfo_s *loadinfo, char *buffer, - int readsize, int offset); - -/*********************************************************************** - * Name: nxflat_bind - * - * Description: - * Bind the imported symbol names in the loaded module described by - * 'loadinfo' using the exported symbol values provided by 'symtab' - * After binding the module, clear the BSS region (which held the relocation - * data) in preparation for execution. - * - * Returned Value: - * 0 (OK) is returned on success and a negated errno is returned on - * failure. - * - ***********************************************************************/ - -struct symtab_s; -EXTERN int nxflat_bind(FAR struct nxflat_loadinfo_s *loadinfo, - FAR const struct symtab_s *exports, int nexports); - -/*********************************************************************** - * Name: nxflat_unload - * - * Description: - * This function unloads the object from memory. This essentially - * undoes the actions of nxflat_load. - * - * Returned Value: - * 0 (OK) is returned on success and a negated errno is returned on - * failure. - * - ***********************************************************************/ - -EXTERN int nxflat_unload(struct nxflat_loadinfo_s *loadinfo); - -/**************************************************************************** - * These are APIs used internally only by NuttX: - ****************************************************************************/ -/*********************************************************************** - * Name: nxflat_initialize - * - * Description: - * NXFLAT support is built unconditionally. However, it order to - * use this binary format, this function must be called during system - * format in order to register the NXFLAT binary format. - * - * Returned Value: - * This is a NuttX internal function so it follows the convention that - * 0 (OK) is returned on success and a negated errno is returned on - * failure. - * - ***********************************************************************/ - -EXTERN int nxflat_initialize(void); - -/**************************************************************************** - * Name: nxflat_uninitialize - * - * Description: - * Unregister the NXFLAT binary loader - * - * Returned Value: - * None - * - ****************************************************************************/ - -EXTERN void nxflat_uninitialize(void); - -#undef EXTERN -#if defined(__cplusplus) -} -#endif - -#endif /* __INCLUDE_NUTTX_NXFLAT_H */ diff --git a/nuttx/include/nuttx/power/pm.h b/nuttx/include/nuttx/power/pm.h index 86e23f090..9c0568b2d 100644 --- a/nuttx/include/nuttx/power/pm.h +++ b/nuttx/include/nuttx/power/pm.h @@ -163,7 +163,7 @@ #endif #if CONFIG_PM_IDLEENTER_THRESH >= CONFIG_PM_IDLEEXIT_THRESH -# error "Must have CONFIG_PM_IDLEENTER_THRESH < CONFIG_PM_IDLEEXIT_THRESH +# error "Must have CONFIG_PM_IDLEENTER_THRESH < CONFIG_PM_IDLEEXIT_THRESH" #endif #ifndef CONFIG_PM_IDLEENTER_COUNT @@ -181,7 +181,7 @@ #endif #if CONFIG_PM_STANDBYENTER_THRESH >= CONFIG_PM_STANDBYEXIT_THRESH -# error "Must have CONFIG_PM_STANDBYENTER_THRESH < CONFIG_PM_STANDBYEXIT_THRESH +# error "Must have CONFIG_PM_STANDBYENTER_THRESH < CONFIG_PM_STANDBYEXIT_THRESH" #endif #ifndef CONFIG_PM_STANDBYENTER_COUNT @@ -199,7 +199,7 @@ #endif #if CONFIG_PM_SLEEPENTER_THRESH >= CONFIG_PM_SLEEPEXIT_THRESH -# error "Must have CONFIG_PM_SLEEPENTER_THRESH < CONFIG_PM_SLEEPEXIT_THRESH +# error "Must have CONFIG_PM_SLEEPENTER_THRESH < CONFIG_PM_SLEEPEXIT_THRESH" #endif #ifndef CONFIG_PM_SLEEPENTER_COUNT diff --git a/nuttx/include/nuttx/sched.h b/nuttx/include/nuttx/sched.h index 54094c8f1..6eaba6e9c 100644 --- a/nuttx/include/nuttx/sched.h +++ b/nuttx/include/nuttx/sched.h @@ -138,11 +138,11 @@ typedef union entry_u entry_t; */ #ifdef CONFIG_SCHED_ATEXIT -typedef void (*atexitfunc_t)(void); +typedef CODE void (*atexitfunc_t)(void); #endif #ifdef CONFIG_SCHED_ONEXIT -typedef void (*onexitfunc_t)(int exitcode, FAR void *arg); +typedef CODE void (*onexitfunc_t)(int exitcode, FAR void *arg); #endif /* POSIX Message queue */ @@ -205,7 +205,7 @@ struct _TCB start_t start; /* Thread start function */ entry_t entry; /* Entry Point into the thread */ -#ifdef CONFIG_SCHED_ATEXIT +#if defined(CONFIG_SCHED_ATEXIT) && !defined(CONFIG_SCHED_ONEXIT) # if defined(CONFIG_SCHED_ATEXIT_MAX) && CONFIG_SCHED_ATEXIT_MAX > 1 atexitfunc_t atexitfunc[CONFIG_SCHED_ATEXIT_MAX]; # else diff --git a/nuttx/include/nuttx/symtab.h b/nuttx/include/nuttx/symtab.h deleted file mode 100644 index b302ab20a..000000000 --- a/nuttx/include/nuttx/symtab.h +++ /dev/null @@ -1,163 +0,0 @@ -/**************************************************************************** - * include/nuttx/symtab.h - * - * Copyright (C) 2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -#ifndef __INCLUDE_NUTTX_SYMTAB_H -#define __INCLUDE_NUTTX_SYMTAB_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/* struct symbtab_s describes one entry in the symbol table. A symbol table - * is a fixed size array of struct symtab_s. The information is intentionally - * minimal and supports only: - * - * 1. Function points as sym_values. Of other kinds of values need to be - * supported, then typing information would also need to be included in - * the structure. - * - * 2. Fixed size arrays. There is no explicit provisional for dyanamically - * adding or removing entries from the symbol table (realloc might be - * used for that purpose if needed). The intention is to support only - * fixed size arrays completely defined at compilation or link time. - */ - -struct symtab_s -{ - FAR const char *sym_name; /* A pointer to the symbol name string */ - FAR const void *sym_value; /* The value associated witht the string */ -}; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -#undef EXTERN -#if defined(__cplusplus) -#define EXTERN extern "C" -extern "C" { -#else -#define EXTERN extern -#endif - -/**************************************************************************** - * Name: symtab_findbyname - * - * Description: - * Find the symbol in the symbol table with the matching name. - * This version assumes that table is not ordered with respect to symbol - * name and, hence, access time will be linear with respect to nsyms. - * - * Returned Value: - * A reference to the symbol table entry if an entry with the matching - * name is found; NULL is returned if the entry is not found. - * - ****************************************************************************/ - -EXTERN FAR const struct symtab_s * -symtab_findbyname(FAR const struct symtab_s *symtab, - FAR const char *name, int nsyms); - -/**************************************************************************** - * Name: symtab_findorderedbyname - * - * Description: - * Find the symbol in the symbol table with the matching name. - * This version assumes that table ordered with respect to symbol name. - * - * Returned Value: - * A reference to the symbol table entry if an entry with the matching - * name is found; NULL is returned if the entry is not found. - * - ****************************************************************************/ - -EXTERN FAR const struct symtab_s * -symtab_findorderedbyname(FAR const struct symtab_s *symtab, - FAR const char *name, int nsyms); - -/**************************************************************************** - * Name: symtab_findbyvalue - * - * Description: - * Find the symbol in the symbol table whose value closest (but not greater - * than), the provided value. This version assumes that table is not ordered - * with respect to symbol name and, hence, access time will be linear with - * respect to nsyms. - * - * Returned Value: - * A reference to the symbol table entry if an entry with the matching - * name is found; NULL is returned if the entry is not found. - * - ****************************************************************************/ - -EXTERN FAR const struct symtab_s * -symtab_findbyvalue(FAR const struct symtab_s *symtab, - FAR void *value, int nsyms); - -/**************************************************************************** - * Name: symtab_findorderedbyvalue - * - * Description: - * Find the symbol in the symbol table whose value closest (but not greater - * than), the provided value. This version assumes that table is ordered - * with respect to symbol name. - * - * Returned Value: - * A reference to the symbol table entry if an entry with the matching - * name is found; NULL is returned if the entry is not found. - * - ****************************************************************************/ - -EXTERN FAR const struct symtab_s * -symtab_findorderedbyvalue(FAR const struct symtab_s *symtab, - FAR void *value, int nsyms); - -#undef EXTERN -#if defined(__cplusplus) -} -#endif - -#endif /* __INCLUDE_NUTTX_SYMTAB_H */ - diff --git a/nuttx/include/nuttx/usb/cdcacm.h b/nuttx/include/nuttx/usb/cdcacm.h index 307f2a597..1dca050c4 100644 --- a/nuttx/include/nuttx/usb/cdcacm.h +++ b/nuttx/include/nuttx/usb/cdcacm.h @@ -205,7 +205,7 @@ /* USB Controller */ #ifndef CONFIG_USBDEV_SELFPOWERED -# define SELFPOWERED USB_CONFIG_ATT_SELFPOWER +# define SELFPOWERED USB_CONFIG_ATTR_SELFPOWER #else # define SELFPOWERED (0) #endif diff --git a/nuttx/include/nuttx/usb/usbdev_trace.h b/nuttx/include/nuttx/usb/usbdev_trace.h index ae8e13c3a..ab3a5f4be 100644 --- a/nuttx/include/nuttx/usb/usbdev_trace.h +++ b/nuttx/include/nuttx/usb/usbdev_trace.h @@ -238,10 +238,6 @@ #define USBCOMPOSITE_TRACEERR_ALLOCDEVSTRUCT 0x000a #define USBCOMPOSITE_TRACEERR_CLASSOBJECT 0x000b #define USBCOMPOSITE_TRACEERR_DEVREGISTER 0x000c -#define USBCOMPOSITE_TRACEERR_INVALIDARG 0x000d -#define USBCOMPOSITE_TRACEERR_INVALIDARG 0x000f -#define USBCOMPOSITE_TRACEERR_INVALIDARG 0x0010 -#define USBCOMPOSITE_TRACEERR_INVALIDARG 0x0011 /* USB Storage driver class events ******************************************/ diff --git a/nuttx/include/nuttx/wqueue.h b/nuttx/include/nuttx/wqueue.h index 644585c56..c509bf197 100644 --- a/nuttx/include/nuttx/wqueue.h +++ b/nuttx/include/nuttx/wqueue.h @@ -109,17 +109,35 @@ # endif #endif -/* Work queue IDs (indices). These are both zero if there is only one work - * queue. +/* Work queue IDs (indices): + * + * Kernel Work Queues: + * HPWORK: This ID of the high priority work queue that should only be used for + * hi-priority, time-critical, driver bottom-half functions. + * + * LPWORK: This is the ID of the low priority work queue that can be used for any + * purpose. if CONFIG_SCHED_LPWORK is not defined, then there is only one kernel + * work queue and LPWORK == HPWORK. + * + * User Work Queue: + * USRWORK: CONFIG_NUTTX_KERNEL and CONFIG_SCHED_USRWORK are defined, then NuttX + * will also support a user-accessible work queue. Otherwise, USRWORK == LPWORK. */ #define HPWORK 0 #ifdef CONFIG_SCHED_LPWORK -# define LPWORK 1 +# define LPWORK (HPWORK+1) #else # define LPWORK HPWORK #endif +#if defined(CONFIG_NUTTX_KERNEL) && defined(CONFIG_SCHED_USRWORK) +# warning "Feature not implemented" +# define USRWORK (LPWORK+1) +#else +# define USRWORK LPWORK +#endif + /**************************************************************************** * Public Types ****************************************************************************/ diff --git a/nuttx/include/stdio.h b/nuttx/include/stdio.h index 754cedbb4..0441ea4b8 100644 --- a/nuttx/include/stdio.h +++ b/nuttx/include/stdio.h @@ -102,6 +102,9 @@ extern "C" { /* ANSI-like File System Interfaces */ +/* Operations on streams (FILE) */ + +EXTERN void clearerr(register FILE *stream); EXTERN int fclose(FAR FILE *stream); EXTERN int fflush(FAR FILE *stream); EXTERN int feof(FAR FILE *stream); @@ -120,6 +123,9 @@ EXTERN int fsetpos(FAR FILE *stream, FAR fpos_t *pos); EXTERN long ftell(FAR FILE *stream); EXTERN size_t fwrite(FAR const void *ptr, size_t size, size_t n_items, FAR FILE *stream); EXTERN FAR char *gets(FAR char *s); +EXTERN int ungetc(int c, FAR FILE *stream); + +/* Operations on the stdout stream, buffers, paths, and the whole printf-family */ EXTERN int printf(const char *format, ...); EXTERN int puts(FAR const char *s); @@ -130,7 +136,6 @@ EXTERN int snprintf(FAR char *buf, size_t size, const char *format, ...); EXTERN int sscanf(const char *buf, const char *fmt, ...); EXTERN void perror(FAR const char *s); -EXTERN int ungetc(int c, FAR FILE *stream); EXTERN int vprintf(FAR const char *format, va_list ap); EXTERN int vfprintf(FAR FILE *stream, const char *format, va_list ap); EXTERN int vdprintf(FAR int fd, const char *format, va_list ap); diff --git a/nuttx/include/termios.h b/nuttx/include/termios.h index 537edbd8f..3032e4746 100644 --- a/nuttx/include/termios.h +++ b/nuttx/include/termios.h @@ -232,7 +232,7 @@ struct termios * cf[set|get][o|i]speed() POSIX interfaces. */ - speed_t c_speed; /* Input/output speed (non-POSIX)*/ + speed_t c_speed; /* Input/output speed (non-POSIX)*/ }; /**************************************************************************** diff --git a/nuttx/include/unistd.h b/nuttx/include/unistd.h index e2ad6ff82..681ce9e63 100644 --- a/nuttx/include/unistd.h +++ b/nuttx/include/unistd.h @@ -133,6 +133,7 @@ EXTERN pid_t getpid(void); EXTERN void _exit(int status) noreturn_function; EXTERN unsigned int sleep(unsigned int seconds); EXTERN int usleep(useconds_t usec); +EXTERN int pause(void); /* File descriptor operations */ diff --git a/nuttx/lib/Kconfig b/nuttx/lib/Kconfig deleted file mode 100644 index 69a55d09c..000000000 --- a/nuttx/lib/Kconfig +++ /dev/null @@ -1,194 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see misc/tools/kconfig-language.txt. -# - -config STDIO_BUFFER_SIZE - int "C STDIO buffer size" - default 64 - ---help--- - Size of buffers using within the C buffered I/O interfaces. - (printf, putchar, fwrite, etc.). - -config STDIO_LINEBUFFER - bool "STDIO line buffering" - default y - ---help--- - Flush buffer I/O whenever a newline character is found in - the output data stream. - -config NUNGET_CHARS - int "Number unget() characters" - default 2 - ---help--- - Number of characters that can be buffered by ungetc() (Only if NFILE_STREAMS > 0) - -config LIB_HOMEDIR - string "Home directory" - default "/" - depends on !DISABLE_ENVIRON - ---help--- - The home directory to use with operations like such as 'cd ~' - -config HAVE_LIBM - bool "Architecture-specific libm.a" - default n - ---help--- - Architecture specific logic provides an implementation of libm.a - and a math.h header file that can be found at include/arch/math.h. - -config NOPRINTF_FIELDWIDTH - bool "Disable sprintf support fieldwidth" - default n - ---help--- - sprintf-related logic is a - little smaller if we do not support fieldwidthes - -config LIBC_FLOATINGPOINT - bool "Enable floating point in printf" - default n - ---help--- - By default, floating point - support in printf, sscanf, etc. is disabled. - -choice - prompt "Newline Options" - default EOL_IS_EITHER_CRLF - ---help--- - This selection determines the line terminating character that is used. - Some environments may return CR as end-of-line, others LF, and others - both. If not specified, the default is either CR or LF (but not both) - as the line terminating charactor. - -config EOL_IS_CR - bool "EOL is CR" - -config EOL_IS_LF - bool "EOL is LF" - -config EOL_IS_BOTH_CRLF - bool "EOL is CR and LF" - -config EOL_IS_EITHER_CRLF - bool "EOL is CR or LF" - -endchoice - -config LIBC_STRERROR - bool "Enable strerror" - default n - ---help--- - strerror() is useful because it decodes 'errno' values into a human readable - strings. But it can also require a lot of memory. If this option is selected, - strerror() will still exist in the build but it will not decode error values. - This option should be used by other logic to decide if it should use strerror() - or not. For example, the NSH application will not use strerror() if this - option is not selected; perror() will not use strerror() is this option is not - selected (see also NSH_STRERROR). - -config LIBC_STRERROR_SHORT - bool "Use short error descriptions in strerror()" - default n - depends on LIBC_STRERROR - ---help--- - If this option is selected, then strerror() will use a shortened string when - it decodes the error. Specifically, strerror() is simply use the string that - is the common name for the error. For example, the 'errno' value of 2 will - produce the string "No such file or directory" is LIBC_STRERROR_SHORT - is not defined but the string "ENOENT" is LIBC_STRERROR_SHORT is defined. - -config LIBC_PERROR_STDOUT - bool "perror() to stdout" - default n - ---help--- - POSIX requires that perror() provide its output on stderr. This option may - be defined, however, to provide perror() output that is serialized with - other stdout messages. - -config ARCH_LOWPUTC - bool "Low-level console output" - default "y" - ---help--- - architecture supports low-level, boot time console output - -config LIB_SENDFILE_BUFSIZE - int "sendfile() buffer size" - default 512 - ---help--- - Size of the I/O buffer to allocate in sendfile(). Default: 512b - -config ARCH_ROMGETC - bool "Support for ROM string access" - default n - ---help--- - In Harvard architectures, data accesses and instruction accesses - occur on different busses, perhaps concurrently. All data accesses - are performed on the data bus unless special machine instructions - are used to read data from the instruction address space. Also, in - the typical MCU, the available SRAM data memory is much smaller that - the non-volatile FLASH instruction memory. So if the application - requires many constant strings, the only practical solution may be - to store those constant strings in FLASH memory where they can only - be accessed using architecture-specific machine instructions. - - If ARCH_ROMGETC is defined, then the architecture logic must export - the function up_romgetc(). up_romgetc() will simply read one byte - of data from the instruction space. - - If ARCH_ROMGETC, certain C stdio functions are effected: (1) All - format strings in printf, fprintf, sprintf, etc. are assumed to lie - in FLASH (string arguments for %s are still assumed to reside in SRAM). - And (2), the string argument to puts and fputs is assumed to reside - in FLASH. Clearly, these assumptions may have to modified for the - particular needs of your environment. There is no "one-size-fits-all" - solution for this problem. - -config ARCH_OPTIMIZED_FUNCTIONS - bool "Enable arch optimized functions" - default n - ---help--- - Allow for architecture optimized implementations of certain library - functions. Architecture-specific implementations can improve overall - system performance. - -if ARCH_OPTIMIZED_FUNCTIONS -config ARCH_MEMCPY - bool "memcpy" - default n - -config ARCH_MEMCMP - bool "memcmp" - default n - -config ARCH_MEMMOVE - bool "memmove" - default n - -config ARCH_MEMSET - bool "memset" - default n - -config ARCH_STRCMP - bool "strcmp" - default n - -config ARCH_STRCPY - bool "strcpy" - default n - -config ARCH_STRNCPY - bool "strncpy" - default n - -config ARCH_STRLEN - bool "strlen" - default n - -config ARCH_STRNLEN - bool "strlen" - default n - -config ARCH_BZERO - bool "bzero" - default n -endif diff --git a/nuttx/lib/Makefile b/nuttx/lib/Makefile index fc8f0c4dd..58857dbd4 100644 --- a/nuttx/lib/Makefile +++ b/nuttx/lib/Makefile @@ -1,7 +1,7 @@ ############################################################################ # lib/Makefile # -# Copyright (C) 2007-2012 Gregory Nutt. All rights reserved. +# Copyright (C) 2012 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -35,101 +35,11 @@ -include $(TOPDIR)/Make.defs -ASRCS = -CSRCS = +all: -DEPPATH := --dep-path . -VPATH := . +depend: -include stdio/Make.defs -include stdlib/Make.defs -include unistd/Make.defs -include sched/Make.defs -include string/Make.defs -include pthread/Make.defs -include semaphore/Make.defs -include signal/Make.defs -include mqueue/Make.defs -include math/Make.defs -include net/Make.defs -include time/Make.defs -include libgen/Make.defs -include dirent/Make.defs -include termios/Make.defs -include queue/Make.defs -include misc/Make.defs - -AOBJS = $(ASRCS:.S=$(OBJEXT)) -COBJS = $(CSRCS:.c=$(OBJEXT)) - -SRCS = $(ASRCS) $(CSRCS) -OBJS = $(AOBJS) $(COBJS) - -UBIN = libulib$(LIBEXT) -KBIN = libklib$(LIBEXT) -BIN = liblib$(LIBEXT) - -all: $(BIN) - -$(AOBJS): %$(OBJEXT): %.S - $(call ASSEMBLE, $<, $@) - -$(COBJS): %$(OBJEXT): %.c - $(call COMPILE, $<, $@) - -$(BIN): $(OBJS) - @( for obj in $(OBJS) ; do \ - $(call ARCHIVE, $@, $${obj}); \ - done ; ) - -ifneq ($(BIN),$(UBIN)) -.userlib: - @$(MAKE) $(UBIN) BIN=$(UBIN) TOPDIR=$(TOPDIR) EXTRADEFINES=$(EXTRADEFINES) - @touch .userlib - -$(UBIN): kclean .userlib -endif - -ifneq ($(BIN),$(KBIN)) -.kernlib: - @$(MAKE) $(KBIN) BIN=$(KBIN) TOPDIR=$(TOPDIR) EXTRADEFINES=$(EXTRADEFINES) - @touch .kernlib - -$(KBIN): uclean .kernlib -endif - -.depend: Makefile $(SRCS) - @$(MKDEP) $(DEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep - @touch $@ - -depend: .depend - -# Clean Targets: -# Clean user-mode temporary files (retaining the UBIN binary) - -uclean: -ifneq ($(OBJEXT),) - @( if [ -f .userlib ]; then rm -f *$(OBJEXT); fi ) -endif - @rm -f .userlib *~ .*.swp - -# Clean kernel-mode temporary files (retaining the KBIN binary) - -kclean: -ifneq ($(OBJEXT),) - @( if [ -f .kernlib ]; then rm -f *$(OBJEXT); fi ) -endif - @rm -f .kernlib *~ .*.swp - -# Really clean everything - -clean: uclean kclean - @rm -f $(BIN) $(UBIN) $(KBIN) *~ .*.swp +clean: $(call CLEAN) -# Deep clean -- removes all traces of the configuration - distclean: clean - @rm -f Make.dep .depend - --include Make.dep diff --git a/nuttx/lib/README.txt b/nuttx/lib/README.txt index 63d1c343c..f742b9a24 100644 --- a/nuttx/lib/README.txt +++ b/nuttx/lib/README.txt @@ -1,84 +1,6 @@ -lib -=== - -This directory contains numerous, small functions typically associated with -what you would expect to find in a standard C library. The sub-directories -in this directory contain standard interface that can be executed by user- -mode programs. - -Normally, NuttX is built with no protection and all threads running in kerne- -mode. In that model, there is no real architectural distinction between -what is a kernel-mode program and what is a user-mode program; the system is -more like on multi-threaded program that all runs in kernel-mode. - -But if the CONFIG_NUTTX_KERNEL option is selected, NuttX will be built into -distinct user-mode and kernel-mode sections. In that case, most of the -code in the nuttx/ directory will run in kernel-mode with with exceptions -of (1) the user-mode "proxies" found in syscall/proxies, and (2) the -standard C library functions found in this directory. In this build model, -it is critical to separate the user-mode OS interfaces in this way. - -Sub-Directories -=============== - -The files in the lib/ directory are organized (mostly) according which file -in the include/ directory provides the prototype for library functions. So -we have: - - libgen - libgen.h - math - math.h and fixedmath.h - mqueue - pthread.h - net - Various network-related header files: netinet/ether.h, arpa/inet.h - pthread - pthread.h - queue - queue.h - sched - sched.h - semaphore - semaphore.h - stdio - stdio.h - stdlib - stdlib.h - string - string.h - time - time.h - unistd - unistd.h - -There is also a misc/ subdirectory that contains various internal functions -and interfaces from header files that are too few to warrant their own sub- -directory: - - misc - Nonstandard "glue" logic, debug.h, crc32.h, dirent.h - -Library Database +lib/ README File ================ -Information about functions available in the NuttX C library information is -maintained in a database. That "database" is implemented as a simple comma- -separated-value file, lib.csv. Most spreadsheets programs will accept this -format and can be used to maintain the library database. - -This library database will (eventually) be used to generate symbol library -symbol table information that can be exported to external applications. - -The format of the CSV file for each line is: - - Field 1: Function name - Field 2: The header file that contains the function prototype - Field 3: Condition for compilation - Field 4: The type of function return value. - Field 5 - N+5: The type of each of the N formal parameters of the function - -Each type field has a format as follows: +This directory is reserved for libraries generated during the NuttX build process - type name: - For all simpler types - formal type | actual type: - For array types where the form of the formal (eg. int parm[2]) - differs from the type of actual passed parameter (eg. int*). This - is necessary because you cannot do simple casts to array types. - formal type | union member actual type | union member fieldname: - A similar situation exists for unions. For example, the formal - parameter type union sigval -- You cannot cast a uintptr_t to - a union sigval, but you can cast to the type of one of the union - member types when passing the actual paramter. Similarly, we - cannot cast a union sigval to a uinptr_t either. Rather, we need - to cast a specific union member fieldname to uintptr_t. -NOTE: The tool mksymtab can be used to generate a symbol table from this CSV -file. See nuttx/tools/README.txt for further details about the use of mksymtab. diff --git a/nuttx/lib/dirent/Make.defs b/nuttx/lib/dirent/Make.defs deleted file mode 100644 index cc1d6b783..000000000 --- a/nuttx/lib/dirent/Make.defs +++ /dev/null @@ -1,48 +0,0 @@ -############################################################################ -# lib/dirent/Make.defs -# -# Copyright (C) 2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt -# -# 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. -# -############################################################################ - -ifneq ($(CONFIG_NFILE_DESCRIPTORS),0) - -# Add the dirent C files to the build - -CSRCS += lib_readdirr.c lib_telldir.c - -# Add the dirent directory to the build - -DEPPATH += --dep-path dirent -VPATH += :dirent - -endif - diff --git a/nuttx/lib/dirent/lib_readdirr.c b/nuttx/lib/dirent/lib_readdirr.c deleted file mode 100644 index 47c5b9a7b..000000000 --- a/nuttx/lib/dirent/lib_readdirr.c +++ /dev/null @@ -1,122 +0,0 @@ -/**************************************************************************** - * lib/dirent/lib_readdirr.c - * - * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include -#include - -#include - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: readdir_r - * - * Description: - * The readdir() function returns a pointer to a dirent - * structure representing the next directory entry in the - * directory stream pointed to by dir. It returns NULL on - * reaching the end-of-file or if an error occurred. - * - * Inputs: - * dirp -- An instance of type DIR created by a previous - * call to opendir(); - * entry -- The storage pointed to by entry must be large - * enough for a dirent with an array of char d_name - * members containing at least {NAME_MAX}+1 elements. - * result -- Upon successful return, the pointer returned - * at *result shall have the same value as the - * argument entry. Upon reaching the end of the directory - * stream, this pointer shall have the value NULL. - * - * Return: - * If successful, the readdir_r() function return s zero; - * otherwise, an error number is returned to indicate the - * error. - * - * EBADF - Invalid directory stream descriptor dir - * - ****************************************************************************/ - -int readdir_r(FAR DIR *dirp, FAR struct dirent *entry, - FAR struct dirent **result) -{ - struct dirent *tmp; - - /* NOTE: The following use or errno is *not* thread-safe */ - - set_errno(0); - tmp = readdir(dirp); - if (!tmp) - { - int error = get_errno(); - if (!error) - { - if (result) - { - *result = NULL; - } - return 0; - } - else - { - return error; - } - } - - if (entry) - { - memcpy(entry, tmp, sizeof(struct dirent)); - } - - if (result) - { - *result = entry; - } - return 0; -} - diff --git a/nuttx/lib/dirent/lib_telldir.c b/nuttx/lib/dirent/lib_telldir.c deleted file mode 100644 index 3753b326e..000000000 --- a/nuttx/lib/dirent/lib_telldir.c +++ /dev/null @@ -1,91 +0,0 @@ -/**************************************************************************** - * lib/dirent/fs_telldir.c - * - * Copyright (C) 2007-2008, 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include -#include - -#include -#include - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: telldir - * - * Description: - * The telldir() function returns the current location - * associated with the directory stream dirp. - * - * Inputs: - * dirp -- An instance of type DIR created by a previous - * call to opendir(); - * - * Return: - * On success, the telldir() function returns the current - * location in the directory stream. On error, -1 is - * returned, and errno is set appropriately. - * - * EBADF - Invalid directory stream descriptor dir - * - ****************************************************************************/ - -off_t telldir(FAR DIR *dirp) -{ - struct fs_dirent_s *idir = (struct fs_dirent_s *)dirp; - - if (!idir || !idir->fd_root) - { - set_errno(EBADF); - return (off_t)-1; - } - - /* Just return the current position */ - - return idir->fd_position; -} - diff --git a/nuttx/lib/lib.csv b/nuttx/lib/lib.csv deleted file mode 100644 index 171f64e9b..000000000 --- a/nuttx/lib/lib.csv +++ /dev/null @@ -1,171 +0,0 @@ -"_inet_ntoa","arpa/inet.h","!defined(CONFIG_NET_IPv6) && !defined(CONFIG_CAN_PASS_STRUCTS)","FAR char","in_addr_t" -"abort","stdlib.h","","void" -"abs","stdlib.h","","int","int" -"asprintf","stdio.h","","int","FAR char **","const char *","..." -"avsprintf","stdio.h","","int","FAR char **","const char *","va_list" -"b16atan2","fixedmath.h","","b16_t","b16_t","b16_t" -"b16cos","fixedmath.h","","b16_t","b16_t" -"b16divb16","fixedmath.h","","b16_t","b16_t","b16_t" -"b16mulb16","fixedmath.h","","b16_t","b16_t","b16_t" -"b16sin","fixedmath.h","","b16_t","b16_t" -"b16sqr","fixedmath.h","","b16_t","b16_t" -"basename","libgen.h","","FAR char","FAR char *" -"cfgetspeed","termios.h","CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_SERIAL_TERMIOS)","speed_t","FAR const struct termios *" -"cfsetspeed","termios.h","CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_SERIAL_TERMIOS)","int","FAR struct termios *","speed_t" -"chdir","unistd.h","CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_ENVIRON)","int","FAR const char *" -"crc32","crc32.h","","uint32_t","FAR const uint8_t *","size_t" -"crc32part","crc32.h","","uint32_t","FAR const uint8_t *","size_t","uint32_t" -"dbg","debug.h","!defined(CONFIG_CPP_HAVE_VARARGS) && defined(CONFIG_DEBUG)","int","const char *","..." -"dbg_enable","debug.h","defined(CONFIG_DEBUG_ENABLE)","void","bool" -"dirname","libgen.h","","FAR char","FAR char *" -"dq_addafter","queue.h","","void","FAR dq_entry_t *","FAR dq_entry_t *","FAR dq_queue_t *" -"dq_addbefore","queue.h","","void","FAR dq_entry_t *","FAR dq_entry_t *","FAR dq_queue_t *" -"dq_addfirst","queue.h","","void","FAR dq_entry_t *","dq_queue_t *" -"dq_addlast","queue.h","","void","FAR dq_entry_t *","dq_queue_t *" -"dq_rem","queue.h","","void","FAR dq_entry_t *","dq_queue_t *" -"dq_remfirst","queue.h","","FAR dq_entry_t","dq_queue_t *" -"dq_remlast","queue.h","","FAR dq_entry_t","dq_queue_t *" -"ether_ntoa","netinet/ether.h","","FAR char","FAR const struct ether_addr *" -"fclose","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","FAR FILE *" -"fdopen","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","FAR FILE","int","FAR const char *" -"fflush","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","FAR FILE *" -"fgetc","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","FAR FILE *" -"fgetpos","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","FAR FILE *","FAR fpos_t *" -"fgets","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","FAR char","FAR char *","int","FAR FILE *" -"fileno","stdio.h","","int","FAR FILE *" -"fopen","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","FAR FILE","FAR const char *","FAR const char *" -"fprintf","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","FAR FILE *","FAR const char *","..." -"fputc","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","int c","FAR FILE *" -"fputs","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","FAR const char *","FAR FILE *" -"fread","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","size_t","FAR void *","size_t","size_t","FAR FILE *" -"fseek","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","FAR FILE *","long int","int" -"fsetpos","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","FAR FILE *","FAR fpos_t *" -"ftell","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","long","FAR FILE *" -"fwrite","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","size_t","FAR const void *","size_t","size_t","FAR FILE *" -"getcwd","unistd.h","CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_ENVIRON)","FAR char","FAR char *","size_t" -"getopt","unistd.h","","int","int","FAR char *const[]","FAR const char *" -"getoptargp","unistd.h","","FAR char *" -"getoptindp","unistd.h","","int" -"getoptoptp","unistd.h","","int" -"gets","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","FAR char","FAR char *" -"gmtime","time.h","","struct tm","const time_t *" -"gmtime_r","time.h","","FAR struct tm","FAR const time_t *","FAR struct tm *" -"htonl","arpa/inet.h","","uint32_t","uint32_t" -"htons","arpa/inet.h","","uint16_t","uint16_t" -"imaxabs","stdlib.h","","intmax_t","intmax_t" -"inet_addr","arpa/inet.h","","in_addr_t","FAR const char " -"inet_ntoa","arpa/inet.h","!defined(CONFIG_NET_IPv6) && defined(CONFIG_CAN_PASS_STRUCTS)","FAR char","struct in_addr" -"inet_ntop","arpa/inet.h","","FAR const char","int","FAR const void *","FAR char *","socklen_t" -"inet_pton","arpa/inet.h","","int","int","FAR const char *","FAR void *" -"labs","stdlib.h","","long int","long int" -"lib_dumpbuffer","debug.h","","void","FAR const char *","FAR const uint8_t *","unsigned int" -"lib_lowprintf","debug.h","","int","FAR const char *","..." -"lib_rawprintf","debug.h","","int","FAR const char *","..." -"llabs","stdlib.h","defined(CONFIG_HAVE_LONG_LONG)","long long int","long long int" -"lldbg","debug.h","!defined(CONFIG_CPP_HAVE_VARARGS) && defined(CONFIG_DEBUG) && defined(CONFIG_ARCH_LOWPUTC)","int","const char *","..." -"llvdbg","debug.h","!defined(CONFIG_CPP_HAVE_VARARGS) && defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_VERBOSE) && defined(CONFIG_ARCH_LOWPUTC)","int","const char *","..." -"match","","","int","const char *","const char *" -"memccpy","string.h","","FAR void","FAR void *","FAR const void *","int c","size_t" -"memchr","string.h","","FAR void","FAR const void *","int c","size_t" -"memcmp","string.h","","int","FAR const void *","FAR const void *","size_t" -"memcpy","string.h","","FAR void","FAR void *","FAR const void *","size_t" -"memmove","string.h","","FAR void","FAR void *","FAR const void *","size_t" -"memset","string.h","","FAR void","FAR void *","int c","size_t" -"mktime","time.h","","time_t","const struct tm *" -"mq_getattr","mqueue.h","!defined(CONFIG_DISABLE_MQUEUE)","int","mqd_t","struct mq_attr *" -"mq_setattr","mqueue.h","!defined(CONFIG_DISABLE_MQUEUE)","int","mqd_t","const struct mq_attr *","struct mq_attr *" -"ntohl","arpa/inet.h","","uint32_t","uint32_t" -"ntohs","arpa/inet.h","","uint16_t","uint16_t" -"perror","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","void","FAR const char *" -"printf","stdio.h","","int","const char *","..." -"pthread_attr_destroy","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_attr_t *" -"pthread_attr_getinheritsched","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR const pthread_attr_t *","FAR int *" -"pthread_attr_getschedparam","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_attr_t *","FAR struct sched_param *" -"pthread_attr_getschedpolicy","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_attr_t *","int *" -"pthread_attr_getstacksize","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_attr_t *","FAR long *" -"pthread_attr_init","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_attr_t *" -"pthread_attr_setinheritsched","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_attr_t *","int" -"pthread_attr_setschedparam","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_attr_t *","FAR const struct sched_param *" -"pthread_attr_setschedpolicy","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_attr_t *","int" -"pthread_attr_setstacksize","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_attr_t *","long" -"pthread_barrierattr_destroy","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_barrierattr_t *" -"pthread_barrierattr_getpshared","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR const pthread_barrierattr_t *","FAR int *" -"pthread_barrierattr_init","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_barrierattr_t *" -"pthread_barrierattr_setpshared","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_barrierattr_t *","int" -"pthread_condattr_destroy","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_condattr_t *" -"pthread_condattr_init","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_condattr_t *" -"pthread_mutexattr_destroy","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_mutexattr_t *" -"pthread_mutexattr_getpshared","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_mutexattr_t *","FAR int *" -"pthread_mutexattr_gettype","pthread.h","!defined(CONFIG_DISABLE_PTHREAD) && defined(CONFIG_MUTEX_TYPES)","int","const pthread_mutexattr_t *","int *" -"pthread_mutexattr_init","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_mutexattr_t *" -"pthread_mutexattr_setpshared","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_mutexattr_t *","int " -"pthread_mutexattr_settype","pthread.h","!defined(CONFIG_DISABLE_PTHREAD) && defined(CONFIG_MUTEX_TYPES)","int","pthread_mutexattr_t *","int" -"puts","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","FAR const char *" -"qsort","stdlib.h","","void","void *","size_t","size_t","int(*)(const void *","const void *)" -"rand","stdlib.h","","int" -"readdir_r","dirent.h","CONFIG_NFILE_DESCRIPTORS > 0","int","FAR DIR *","FAR struct dirent *","FAR struct dirent **" -"rint","","","double_t","double_t" -"sched_get_priority_max","sched.h","","int","int" -"sched_get_priority_min","sched.h","","int","int" -"sem_getvalue","semaphore.h","","int","FAR sem_t *","FAR int *" -"sem_init","semaphore.h","","int","FAR sem_t *","int","unsigned int" -"sendfile","sys/sendfile.h","CONFIG_NSOCKET_DESCRIPTORS > 0 || CONFIG_NFILE_DESCRIPTORS > 0","ssize_t","int","int","off_t","size_t" -"sigaddset","signal.h","!defined(CONFIG_DISABLE_SIGNALS)","int","FAR sigset_t *","int" -"sigdelset","signal.h","!defined(CONFIG_DISABLE_SIGNALS)","int","FAR sigset_t *","int" -"sigemptyset","signal.h","!defined(CONFIG_DISABLE_SIGNALS)","int","FAR sigset_t *" -"sigfillset","signal.h","!defined(CONFIG_DISABLE_SIGNALS)","int","FAR sigset_t *" -"sigismember","signal.h","!defined(CONFIG_DISABLE_SIGNALS)","int","FAR const sigset_t *","int" -"snprintf","stdio.h","","int","FAR char *","size_t","const char *","..." -"sprintf","stdio.h","","int","FAR char *","const char *","..." -"sq_addafter","queue.h","","void","FAR sq_entry_t *","FAR sq_entry_t *","FAR sq_queue_t *" -"sq_addfirst","queue.h","","void","FAR sq_entry_t *","sq_queue_t *" -"sq_addlast","queue.h","","void","FAR sq_entry_t *","sq_queue_t *" -"sq_rem","queue.h","","void","FAR sq_entry_t *","sq_queue_t *" -"sq_remafter","queue.h","","FAR sq_entry_t","FAR sq_entry_t *","sq_queue_t *" -"sq_remfirst","queue.h","","FAR sq_entry_t","sq_queue_t *" -"sq_remlast","queue.h","","FAR sq_entry_t","sq_queue_t *" -"srand","stdlib.h","","void","unsigned int" -"sscanf","stdio.h","","int","const char *","const char *","..." -"strcasecmp","string.h","","int","FAR const char *","FAR const char *" -"strcasestr","string.h","","FAR char","FAR const char *","FAR const char *" -"strcat","string.h","","FAR char","FAR char *","FAR const char *" -"strchr","string.h","","FAR char","FAR const char *","int" -"strcmp","string.h","","int","FAR const char *","FAR const char *" -"strcpy","string.h","","FAR char","char *","FAR const char *" -"strcspn","string.h","","size_t","FAR const char *","FAR const char *" -"strdup","string.h","","FAR char","FAR const char *" -"strerror","string.h","","FAR const char","int" -"strftime","time.h","","size_t","char *","size_t","const char *","const struct tm *" -"strlen","string.h","","size_t","FAR const char *" -"strncasecmp","string.h","","int","FAR const char *","FAR const char *","size_t" -"strncat","string.h","","FAR char","FAR char *","FAR const char *","size_t" -"strncmp","string.h","","int","FAR const char *","FAR const char *","size_t" -"strncpy","string.h","","FAR char","char *","FAR const char *","size_t" -"strndup","string.h","","FAR char","FAR const char *","size_t" -"strnlen","string.h","","size_t","FAR const char *","size_t" -"strpbrk","string.h","","FAR char","FAR const char *","FAR const char *" -"strrchr","string.h","","FAR char","FAR const char *","int" -"strspn","string.h","","size_t","FAR const char *","FAR const char *" -"strstr","string.h","","FAR char","FAR const char *","FAR const char *" -"strtod","stdlib.h","","double_t","const char *str","char **endptr" -"strtok","string.h","","FAR char","FAR char *","FAR const char *" -"strtok_r","string.h","","FAR char","FAR char *","FAR const char *","FAR char **" -"strtol","string.h","","long","const char *","char **","int" -"strtoll","stdlib.h","defined(CONFIG_HAVE_LONG_LONG)","long long","const char *nptr","char **endptr","int base" -"strtoul","stdlib.h","","unsigned long","const char *","char **","int" -"strtoull","stdlib.h","defined(CONFIG_HAVE_LONG_LONG)","unsigned long long","const char *","char **","int" -"tcflush","termios.h","CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_SERIAL_TERMIOS)","int","int","int" -"tcgetattr","termios.h","CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_SERIAL_TERMIOS)","int","int","FAR struct termios *" -"tcsetattr","termios.h","CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_SERIAL_TERMIOS)","int","int","int","FAR const struct termios *" -"telldir","dirent.h","CONFIG_NFILE_DESCRIPTORS > 0","off_t","FAR DIR *" -"time","time.h","","time_t","time_t *" -"ub16divub16","fixedmath.h","","ub16_t","ub16_t","ub16_t" -"ub16mulub16","fixedmath.h","","ub16_t","ub16_t","ub16_t" -"ub16sqr","fixedmath.h","","ub16_t","ub16_t" -"ungetc","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","int","FAR FILE *" -"vdbg","debug.h","!defined(CONFIG_CPP_HAVE_VARARGS) && defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_VERBOSE)","int","const char *","..." -"vfprintf","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","FAR FILE *","const char *","va_list" -"vprintf","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","FAR const char *","va_list" -"vsnprintf","stdio.h","","int","FAR char *","size_t","const char *","va_list" -"vsprintf","stdio.h","","int","FAR char *","const char *","va_list" -"vsscanf","stdio.h","","int","char *","const char *","va_list" diff --git a/nuttx/lib/lib_internal.h b/nuttx/lib/lib_internal.h deleted file mode 100644 index 49cba9996..000000000 --- a/nuttx/lib/lib_internal.h +++ /dev/null @@ -1,200 +0,0 @@ -/**************************************************************************** - * lib/lib_internal.h - * - * Copyright (C) 2007-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 __LIB_LIB_INTERNAL_H -#define __LIB_LIB_INTERNAL_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include -#include - -#include - -/**************************************************************************** - * Definitions - ****************************************************************************/ -/* This configuration directory is used in environment variable processing - * when we need to reference the user's home directory. There are no user - * directories in NuttX so, by default, this always refers to the root - * directory. - */ - -#ifndef CONFIG_LIB_HOMEDIR -# define CONFIG_LIB_HOMEDIR "/" -#endif - -/* If C std I/O buffering is not supported, then we don't need its semaphore - * protection. - */ - -#if CONFIG_STDIO_BUFFER_SIZE <= 0 -# define lib_sem_initialize(s) -# define lib_take_semaphore(s) -# define lib_give_semaphore(s) -#endif - -/* The NuttX C library an be build in two modes: (1) as a standard, C-libary - * that can be used by normal, user-space applications, or (2) as a special, - * kernel-mode C-library only used within the OS. If NuttX is not being - * built as separated kernel- and user-space modules, then only the first - * mode is supported. - */ - -#if defined(CONFIG_NUTTX_KERNEL) && defined(__KERNEL__) -# include -# define lib_malloc(s) kmalloc(s) -# define lib_zalloc(s) kzalloc(s) -# define lib_realloc(p,s) krealloc(p,s) -# define lib_free(p) kfree(p) -#else -# include -# define lib_malloc(s) malloc(s) -# define lib_zalloc(s) zalloc(s) -# define lib_realloc(p,s) realloc(p,s) -# define lib_free(p) free(p) -#endif - -#define LIB_BUFLEN_UNKNOWN INT_MAX - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/**************************************************************************** - * Public Variables - ****************************************************************************/ - -/* Debug output is initially disabled */ - -#ifdef CONFIG_DEBUG_ENABLE -extern bool g_dbgenable; -#endif - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/* Defined in lib_streamsem.c */ - -#if CONFIG_NFILE_STREAMS > 0 -extern void stream_semtake(FAR struct streamlist *list); -extern void stream_semgive(FAR struct streamlist *list); -#endif - -/* Defined in lib_libnoflush.c */ - -#ifdef CONFIG_STDIO_LINEBUFFER -extern int lib_noflush(FAR struct lib_outstream_s *this); -#endif - -/* Defined in lib_libsprintf.c */ - -extern int lib_sprintf(FAR struct lib_outstream_s *obj, - const char *fmt, ...); - -/* Defined lib_libvsprintf.c */ - -extern int lib_vsprintf(FAR struct lib_outstream_s *obj, - FAR const char *src, va_list ap); - -/* Defined lib_rawprintf.c */ - -extern int lib_rawvprintf(const char *src, va_list ap); -extern int lib_rawvdprintf(int fd, const char *fmt, va_list ap); - -/* Defined lib_lowprintf.c */ - -extern int lib_lowvprintf(const char *src, va_list ap); - -/* Defined in lib_dtoa.c */ - -#ifdef CONFIG_LIBC_FLOATINGPOINT -extern char *__dtoa(double d, int mode, int ndigits, - int *decpt, int *sign, char **rve); -#endif - -/* Defined in lib_libwrite.c */ - -extern ssize_t lib_fwrite(FAR const void *ptr, size_t count, FAR FILE *stream); - -/* Defined in lib_libfread.c */ - -extern ssize_t lib_fread(FAR void *ptr, size_t count, FAR FILE *stream); - -/* Defined in lib_libfflush.c */ - -extern ssize_t lib_fflush(FAR FILE *stream, bool bforce); - -/* Defined in lib_rdflush.c */ - -extern int lib_rdflush(FAR FILE *stream); - -/* Defined in lib_wrflush.c */ - -int lib_wrflush(FAR FILE *stream); - -/* Defined in lib_sem.c */ - -#if CONFIG_STDIO_BUFFER_SIZE > 0 -extern void lib_sem_initialize(FAR struct file_struct *stream); -extern void lib_take_semaphore(FAR struct file_struct *stream); -extern void lib_give_semaphore(FAR struct file_struct *stream); -#endif - -/* Defined in lib_libgetbase.c */ - -extern int lib_getbase(const char *nptr, const char **endptr); - -/* Defined in lib_skipspace.c */ - -extern void lib_skipspace(const char **pptr); - -/* Defined in lib_isbasedigit.c */ - -extern bool lib_isbasedigit(int ch, int base, int *value); - -/* Defined in lib_checkbase.c */ - -extern int lib_checkbase(int base, const char **pptr); - -#endif /* __LIB_LIB_INTERNAL_H */ diff --git a/nuttx/lib/libgen/Make.defs b/nuttx/lib/libgen/Make.defs deleted file mode 100644 index f12645512..000000000 --- a/nuttx/lib/libgen/Make.defs +++ /dev/null @@ -1,43 +0,0 @@ -############################################################################ -# lib/libgen/Make.defs -# -# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt -# -# 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. -# -############################################################################ - -# Add the libgen C files to the build - -CSRCS += lib_basename.c lib_dirname.c - -# Add the libgen directory to the build - -DEPPATH += --dep-path libgen -VPATH += :libgen diff --git a/nuttx/lib/libgen/lib_basename.c b/nuttx/lib/libgen/lib_basename.c deleted file mode 100644 index 986c6b852..000000000 --- a/nuttx/lib/libgen/lib_basename.c +++ /dev/null @@ -1,131 +0,0 @@ -/**************************************************************************** - * lib/libgen/lib_basename.c - * - * Copyright (C) 2007, 2009, 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static char g_retchar[2]; - -/**************************************************************************** - * Global Functions - ****************************************************************************/ - -/**************************************************************************** - * Function: basename - * - * Description: - * basename() extracts the filename component from a null-terminated - * pathname string. In the usual case, basename() returns the component - * following the final '/'. Trailing '/' characters are not counted as - * part of the pathname. - * - * If path does not contain a slash, basename() returns a copy of path. - * If path is the string "/", then basename() returns the string "/". If - * path is a NULL pointer or points to an empty string, then basename() - * return the string ".". - * - * basename() may modify the contents of path, so copies should be passed. - * basename() may return pointers to statically allocated memory which may - * be overwritten by subsequent calls. - * - * Parameter: - * path The null-terminated string referring to the path to be decomposed - * - * Return: - * On success the filename component of the path is returned. - * - ****************************************************************************/ - -FAR char *basename(FAR char *path) -{ - char *p; - int len; - int ch; - - /* Handle some corner cases */ - - if (!path || *path == '\0') - { - ch = '.'; - goto out_retchar; - } - - /* Check for trailing slash characters */ - - len = strlen(path); - while (path[len-1] == '/') - { - /* Remove trailing '/' UNLESS this would make a zero length string */ - if (len > 1) - { - path[len-1] = '\0'; - len--; - } - else - { - ch = '/'; - goto out_retchar; - } - } - - /* Get the address of the last '/' which is not at the end of the path and, - * therefor, must be just before the beginning of the filename component. - */ - - p = strrchr(path, '/'); - if (p) - { - return p + 1; - } - - /* There is no '/' in the path */ - - return path; - -out_retchar: - g_retchar[0] = ch; - g_retchar[1] = '\0'; - return g_retchar; -} diff --git a/nuttx/lib/libgen/lib_dirname.c b/nuttx/lib/libgen/lib_dirname.c deleted file mode 100644 index 248293a60..000000000 --- a/nuttx/lib/libgen/lib_dirname.c +++ /dev/null @@ -1,144 +0,0 @@ -/**************************************************************************** - * lib/libgen/lib_dirname.c - * - * Copyright (C) 2007, 2009, 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static char g_retchar[2]; - -/**************************************************************************** - * Global Functions - ****************************************************************************/ - -/**************************************************************************** - * Function: dirname - * - * Description: - * dirname() extracts the directory component from a null-terminated - * pathname string. In the usual case, dirname() returns the string up - * to, but not including, the final '/'. Trailing '/' characters are not - * counted as part of the pathname. - * - * If path does not contain a slash, dirname() returns the string ".". If - * path is the string "/", then dirname() returns the string "/". If path - * is a NULL pointer or points to an empty string, then dirname() returns - * the string ".". - * - * dirname() may modify the contents of path, so copies should be passed. - * dirname() may return pointers to statically allocated memory which may - * be overwritten by subsequent calls. - * - * Parameter: - * path The null-terminated string referring to the path to be decomposed - * - * Return: - * On success the directory component of the path is returned. - * - ****************************************************************************/ - -FAR char *dirname(FAR char *path) -{ - char *p; - int len; - int ch; - - /* Handle some corner cases */ - - if (!path || *path == '\0') - { - ch = '.'; - goto out_retchar; - } - - /* Check for trailing slash characters */ - - len = strlen(path); - while (path[len-1] == '/') - { - /* Remove trailing '/' UNLESS this would make a zero length string */ - if (len > 1) - { - path[len-1] = '\0'; - len--; - } - else - { - ch = '/'; - goto out_retchar; - } - } - - /* Get the address of the last '/' which is not at the end of the path and, - * therefor, must be the end of the directory component. - */ - - p = strrchr(path, '/'); - if (p) - { - /* Handle the case where the only '/' in the string is the at the beginning - * of the path. - */ - - if (p == path) - { - ch = '/'; - goto out_retchar; - } - - /* No, the directory component is the substring before the '/'. */ - - *p = '\0'; - return path; - } - - /* There is no '/' in the path */ - - ch = '.'; - -out_retchar: - g_retchar[0] = ch; - g_retchar[1] = '\0'; - return g_retchar; -} diff --git a/nuttx/lib/math/Make.defs b/nuttx/lib/math/Make.defs deleted file mode 100644 index 126cd2f47..000000000 --- a/nuttx/lib/math/Make.defs +++ /dev/null @@ -1,43 +0,0 @@ -############################################################################ -# lib/math/Make.defs -# -# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt -# -# 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. -# -############################################################################ - -# Add the math C files to the build - -CSRCS += lib_rint.c lib_fixedmath.c lib_b16sin.c lib_b16cos.c lib_b16atan2.c - -# Add the math directory to the build - -DEPPATH += --dep-path math -VPATH += :math diff --git a/nuttx/lib/math/lib_b16atan2.c b/nuttx/lib/math/lib_b16atan2.c deleted file mode 100644 index 8792fa087..000000000 --- a/nuttx/lib/math/lib_b16atan2.c +++ /dev/null @@ -1,108 +0,0 @@ -/**************************************************************************** - * lib/math/lib_b16atan2.c - * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define B16_C1 0x00000373 /* 0.013480470 */ -#define B16_C2 0x00000eb7 /* 0.057477314 */ -#define B16_C3 0x00001f0a /* 0.121239071 */ -#define B16_C4 0x00003215 /* 0.195635925 */ -#define B16_C5 0x0000553f /* 0.332994597 */ -#define B16_C6 0x00010000 /* 0.999995630 */ -#define B16_HALFPI 0x00019220 /* 1.570796327 */ -#define B16_PI 0x00032440 /* 3.141592654 */ - -#ifndef MAX -# define MAX(a,b) (a > b ? a : b) -#endif - -#ifndef MIN -# define MIN(a,b) (a < b ? a : b) -#endif - -#ifndef ABS -# define ABS(a) (a < 0 ? -a : a) -#endif - -/**************************************************************************** - * Global Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: b16atan2 - * - * Description: - * atan2 calculates the arctangent of y/x. (Based on a algorithm I saw - * posted on the internet... now I have lost the link -- sorry). - * - ****************************************************************************/ - -b16_t b16atan2(b16_t y, b16_t x) -{ - b16_t t0; - b16_t t1; - b16_t t2; - b16_t t3; - - t2 = ABS(x); - t1 = ABS(y); - t0 = MAX(t2, t1); - t1 = MIN(t2, t1); - t2 = ub16inv(t0); - t2 = b16mulb16(t1, t2); - - t3 = b16mulb16(t2, t2); - t0 = - B16_C1; - t0 = b16mulb16(t0, t3) + B16_C2; - t0 = b16mulb16(t0, t3) - B16_C3; - t0 = b16mulb16(t0, t3) + B16_C4; - t0 = b16mulb16(t0, t3) - B16_C5; - t0 = b16mulb16(t0, t3) + B16_C6; - t2 = b16mulb16(t0, t2); - - t2 = (ABS(y) > ABS(x)) ? B16_HALFPI - t2 : t2; - t2 = (x < 0) ? B16_PI - t2 : t2; - t2 = (y < 0) ? -t2 : t2; - - return t2; -} diff --git a/nuttx/lib/math/lib_b16cos.c b/nuttx/lib/math/lib_b16cos.c deleted file mode 100644 index 7547871f6..000000000 --- a/nuttx/lib/math/lib_b16cos.c +++ /dev/null @@ -1,64 +0,0 @@ -/**************************************************************************** - * lib/math/lib_b16cos.c - * - * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Global Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: b16cos - ****************************************************************************/ - -b16_t b16cos(b16_t rad) -{ - /* Compute cosine: sin(rad + PI/2) = cos(rad) */ - - rad += b16HALFPI; - if (rad > b16PI) - { - rad -= b16TWOPI; - } - return b16sin(rad); -} diff --git a/nuttx/lib/math/lib_b16sin.c b/nuttx/lib/math/lib_b16sin.c deleted file mode 100644 index 1eee17993..000000000 --- a/nuttx/lib/math/lib_b16sin.c +++ /dev/null @@ -1,110 +0,0 @@ -/**************************************************************************** - * lib/math/lib_b16sin.c - * - * Copyright (C) 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define b16_P225 0x0000399a -#define b16_P405284735 0x000067c1 -#define b16_1P27323954 0x000145f3 - -/**************************************************************************** - * Global Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: b16sin - * Ref: http://lab.polygonal.de/2007/07/18/fast-and-accurate-sinecosine-approximation/ - ****************************************************************************/ - -b16_t b16sin(b16_t rad) -{ - b16_t tmp1; - b16_t tmp2; - b16_t tmp3; - - /* Force angle into the good range */ - - if (rad < -b16PI) - { - rad += b16TWOPI; - } - else if (rad > b16PI) - { - rad -= b16TWOPI; - } - - /* tmp1 = 1.27323954 * rad - * tmp2 = .405284735 * rad * rad - */ - - - tmp1 = b16mulb16(b16_1P27323954, rad); - tmp2 = b16mulb16(b16_P405284735, b16sqr(rad)); - - if (rad < 0) - { - /* tmp3 = 1.27323954 * rad + .405284735 * rad * rad */ - - tmp3 = tmp1 + tmp2; - } - else - { - /* tmp3 = 1.27323954 * rad - 0.405284735 * rad * rad */ - - tmp3 = tmp1 - tmp2; - } - - /* tmp1 = tmp3*tmp3 */ - - tmp1 = b16sqr(tmp3); - if (tmp3 < 0) - { - /* tmp1 = tmp3 * -tmp3 */ - - tmp1 = -tmp1; - } - - /* Return sin = .225 * (tmp3 * (+/-tmp3) - tmp3) + tmp3 */ - - return b16mulb16(b16_P225, (tmp1 - tmp3)) + tmp3; -} diff --git a/nuttx/lib/math/lib_fixedmath.c b/nuttx/lib/math/lib_fixedmath.c deleted file mode 100644 index c1a710e73..000000000 --- a/nuttx/lib/math/lib_fixedmath.c +++ /dev/null @@ -1,272 +0,0 @@ -/**************************************************************************** - * lib/math/lib_fixedmath.c - * - * Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include -#include - -#ifndef CONFIG_HAVE_LONG_LONG - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Name: fixsign - ****************************************************************************/ - -static void fixsign(b16_t *parg1, b16_t *parg2, bool *pnegate) -{ - bool negate = false; - b16_t arg; - - arg = *parg1; - if (arg < 0) - { - *parg1 = -arg; - negate = true; - } - - arg = *parg2; - if (arg < 0) - { - *parg2 = -arg; - negate ^= true; - } - - *pnegate = negate; -} - -/**************************************************************************** - * Name: adjustsign - ****************************************************************************/ - -static b16_t adjustsign(b16_t result, bool negate) -{ - /* If the product is negative, then we overflowed */ - - if (result < 0) - { - if (result) - { - return b16MIN; - } - else - { - return b16MAX; - } - } - - /* correct the sign of the result */ - - if (negate) - { - return -result; - } - return result; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: b16mulb16 - ****************************************************************************/ - -b16_t b16mulb16(b16_t m1, b16_t m2) -{ - bool negate; - b16_t product; - - fixsign(&m1, &m2, &negate); - product = (b16_t)ub16mulub16((ub16_t)m1, (ub16_t)m2); - return adjustsign(product, negate); -} - -/**************************************************************************** - * Name: ub16mulub16 - **************************************************************************/ - -ub16_t ub16mulub16(ub16_t m1, ub16_t m2) -{ - /* Let: - * - * m1 = m1i*2**16 + m1f (b16) - * m2 = m2i*2**16 + m2f (b16) - * - * Then: - * - * m1*m2 = (m1i*m2i)*2**32 + (m1i*m2f + m2i*m1f)*2**16 + m1f*m2f (b32) - * = (m1i*m2i)*2**16 + (m1i*m2f + m2i*m1f) + m1f*m2f*2**-16 (b16) - * = a*2**16 + b + c*2**-16 - */ - - uint32_t m1i = ((uint32_t)m1 >> 16); - uint32_t m2i = ((uint32_t)m1 >> 16); - uint32_t m1f = ((uint32_t)m1 & 0x0000ffff); - uint32_t m2f = ((uint32_t)m2 & 0x0000ffff); - - return (m1i*m2i << 16) + m1i*m2f + m2i*m1f + (((m1f*m2f) + b16HALF) >> 16); -} - -/**************************************************************************** - * Name: b16sqr - **************************************************************************/ - -b16_t b16sqr(b16_t a) -{ - b16_t sq; - - /* The result is always positive. Just take the absolute value */ - - if (a < 0) - { - a = -a; - } - - /* Overflow occurred if the result is negative */ - - sq = (b16_t)ub16sqr(a); - if (sq < 0) - { - sq = b16MAX; - } - return sq; -} - -/**************************************************************************** - * Name: b16divb16 - **************************************************************************/ - -ub16_t ub16sqr(ub16_t a) -{ - /* Let: - * - * m = mi*2**16 + mf (b16) - * - * Then: - * - * m*m = (mi*mi)*2**32 + 2*(m1*m2)*2**16 + mf*mf (b32) - * = (mi*mi)*2**16 + 2*(mi*mf) + mf*mf*2**-16 (b16) - */ - - uint32_t mi = ((uint32_t)a >> 16); - uint32_t mf = ((uint32_t)a & 0x0000ffff); - - return (mi*mi << 16) + (mi*mf << 1) + ((mf*mf + b16HALF) >> 16); -} - -/**************************************************************************** - * Name: b16divb16 - **************************************************************************/ - -b16_t b16divb16(b16_t num, b16_t denom) -{ - bool negate; - b16_t quotient; - - fixsign(&num, &denom, &negate); - quotient = (b16_t)ub16divub16((ub16_t)num, (ub16_t)denom); - return adjustsign(quotient, negate); -} - -/**************************************************************************** - * Name: ub16divub16 - **************************************************************************/ - -ub16_t ub16divub16(ub16_t num, ub16_t denom) -{ - uint32_t term1; - uint32_t numf; - uint32_t product; - - /* Let: - * - * num = numi*2**16 + numf (b16) - * den = deni*2**16 + denf (b16) - * - * Then: - * - * num/den = numi*2**16 / den + numf / den (b0) - * = numi*2**32 / den + numf*2**16 /den (b16) - */ - - /* Check for overflow in the first part of the quotient */ - - term1 = ((uint32_t)num & 0xffff0000) / denom; - if (term1 >= 0x00010000) - { - return ub16MAX; /* Will overflow */ - } - - /* Finish the division */ - - numf = num - term1 * denom; - term1 <<= 16; - product = term1 + (numf + (denom >> 1)) / denom; - - /* Check for overflow */ - - if (product < term1) - { - return ub16MAX; /* Overflowed */ - } - return product; -} - -#endif diff --git a/nuttx/lib/math/lib_rint.c b/nuttx/lib/math/lib_rint.c deleted file mode 100644 index bd861eced..000000000 --- a/nuttx/lib/math/lib_rint.c +++ /dev/null @@ -1,135 +0,0 @@ -/************************************************************ - * lib/math/lib_rint.c - * - * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ************************************************************/ - -/************************************************************ - * Compilation Switches - ************************************************************/ - -/************************************************************ - * Included Files - ************************************************************/ - -#include -#include -#include - -/************************************************************ - * Definitions - ************************************************************/ - -/************************************************************ - * Private Type Declarations - ************************************************************/ - -/************************************************************ - * Private Function Prototypes - ************************************************************/ - -/********************************************************** - * Global Constant Data - **********************************************************/ - -/************************************************************ - * Global Variables - ************************************************************/ - -/********************************************************** - * Private Constant Data - **********************************************************/ - -/************************************************************ - * Private Variables - ************************************************************/ - -double_t rint(double_t x) -{ - double_t ret; - - /* If the current rounding mode rounds toward negative - * infinity, rint() is identical to floor(). If the current - * rounding mode rounds toward positive infinity, rint() is - * identical to ceil(). - */ - -#if defined(CONFIG_FP_ROUND_POSITIVE) && CONFIG_FP_ROUNDING_POSITIVE != 0 - - ret = ceil(x); - -#elif defined(CONFIG_FP_ROUND_NEGATIVE) && CONFIG_FP_ROUNDING_NEGATIVE != 0 - - ret = floor(x); - -#else - - /* In the default rounding mode (round to nearest), rint(x) is the - * integer nearest x with the additional stipulation that if - * |rint(x)-x|=1/2, then rint(x) is even. - */ - - long dwinteger = (long)x; - double_t fremainder = x - (double_t)dwinteger; - - if (x < 0.0) - { - /* fremainder should be in range 0 .. -1 */ - - if (fremainder == -0.5) - { - dwinteger = ((dwinteger+1)&~1); - } - else if (fremainder < -0.5) - { - dwinteger--; - } - } - else - { - /* fremainder should be in range 0 .. 1 */ - - if (fremainder == 0.5) - { - dwinteger = ((dwinteger+1)&~1); - } - else if (fremainder > 0.5) - { - dwinteger++; - } - } - - ret = (double_t)dwinteger; -#endif - - return ret; -} diff --git a/nuttx/lib/misc/Make.defs b/nuttx/lib/misc/Make.defs deleted file mode 100644 index c12533f75..000000000 --- a/nuttx/lib/misc/Make.defs +++ /dev/null @@ -1,69 +0,0 @@ -############################################################################ -# lib/misc/Make.defs -# -# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt -# -# 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. -# -############################################################################ - -# Add the internal C files to the build - -CSRCS += lib_init.c lib_filesem.c - -# Add C files that depend on file OR socket descriptors - -ifneq ($(CONFIG_NFILE_DESCRIPTORS),0) - -CSRCS += lib_sendfile.c -ifneq ($(CONFIG_NFILE_STREAMS),0) -CSRCS += lib_streamsem.c -endif - -else -ifneq ($(CONFIG_NSOCKET_DESCRIPTORS),0) - -CSRCS += lib_sendfile.c -ifneq ($(CONFIG_NFILE_STREAMS),0) -CSRCS += lib_streamsem.c -endif - -endif -endif - -# Add the miscellaneous C files to the build - -CSRCS += lib_match.c -CSRCS += lib_crc32.c -CSRCS += lib_dbg.c lib_dumpbuffer.c - -# Add the misc directory to the build - -DEPPATH += --dep-path misc -VPATH += :misc diff --git a/nuttx/lib/misc/lib_crc32.c b/nuttx/lib/misc/lib_crc32.c deleted file mode 100644 index f851598e0..000000000 --- a/nuttx/lib/misc/lib_crc32.c +++ /dev/null @@ -1,123 +0,0 @@ -/************************************************************************************************ - * lib/misc/lib_crc32.c - * - * This file is a part of NuttX: - * - * Copyright (C) 2010-2011 Gregory Nutt. All rights reserved. - * - * The logic in this file was developed by Gary S. Brown: - * - * COPYRIGHT (C) 1986 Gary S. Brown. You may use this program, or code or tables - * extracted from it, as desired without restriction. - * - * First, the polynomial itself and its table of feedback terms. The polynomial is: - * - * X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0 - * - * Note that we take it "backwards" and put the highest-order term in the lowest-order bit. - * The X^32 term is "implied"; the LSB is the X^31 term, etc. The X^0 term (usually shown - * as "+1") results in the MSB being 1 - * - * Note that the usual hardware shift register implementation, which is what we're using - * (we're merely optimizing it by doing eight-bit chunks at a time) shifts bits into the - * lowest-order term. In our implementation, that means shifting towards the right. Why - * do we do it this way? Because the calculated CRC must be transmitted in order from - * highest-order term to lowest-order term. UARTs transmit characters in order from LSB - * to MSB. By storing the CRC this way we hand it to the UART in the order low-byte to - * high-byte; the UART sends each low-bit to hight-bit; and the result is transmission bit - * by bit from highest- to lowest-order term without requiring any bit shuffling on our - * part. Reception works similarly - * - * The feedback terms table consists of 256, 32-bit entries. Notes - * - * - The table can be generated at runtime if desired; code to do so is shown later. It - * might not be obvious, but the feedback terms simply represent the results of eight - * shift/xor operations for all combinations of data and CRC register values - * - * - The values must be right-shifted by eight bits by the updcrc logic; the shift must - * be u_(bring in zeroes). On some hardware you could probably optimize the shift in - * assembler by using byte-swap instructions polynomial $edb88320 - ************************************************************************************************/ - -/************************************************************************************************ - * Included Files - ************************************************************************************************/ - -#include -#include -#include - -/************************************************************************************************ - * Private Data - ************************************************************************************************/ - -static const uint32_t crc32_tab[] = -{ - 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, - 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, - 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, - 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, - 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, - 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, - 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, - 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, - 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, - 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, - 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, - 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, - 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, - 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, - 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, - 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, - 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, - 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, - 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, - 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, - 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, - 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, - 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, - 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, - 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, - 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, - 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, - 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, - 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, - 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, - 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, - 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d -}; - -/************************************************************************************************ - * Public Functions - ************************************************************************************************/ -/************************************************************************************************ - * Name: crc32part - * - * Description: - * Continue CRC calculation on a part of the buffer. - * - ************************************************************************************************/ - -uint32_t crc32part(FAR const uint8_t *src, size_t len, uint32_t crc32val) -{ - size_t i; - - for (i = 0; i < len; i++) - { - crc32val = crc32_tab[(crc32val ^ src[i]) & 0xff] ^ (crc32val >> 8); - } - return crc32val; -} - -/************************************************************************************************ - * Name: crc32 - * - * Description: - * Return a 32-bit CRC of the contents of the 'src' buffer, length 'len' - * - ************************************************************************************************/ - -uint32_t crc32(FAR const uint8_t *src, size_t len) -{ - return crc32part(src, len, 0); -} diff --git a/nuttx/lib/misc/lib_dbg.c b/nuttx/lib/misc/lib_dbg.c deleted file mode 100644 index aacdaa30a..000000000 --- a/nuttx/lib/misc/lib_dbg.c +++ /dev/null @@ -1,165 +0,0 @@ -/**************************************************************************** - * lib/misc/lib_dbg.c - * - * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include - -#include "lib_internal.h" - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/* Debug output is initially disabled */ - -#ifdef CONFIG_DEBUG_ENABLE -bool g_dbgenable; -#endif - -/**************************************************************************** - * Global Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: dbg_enable - * - * Description: - * Enable or disable debug output. - * - ****************************************************************************/ - -#ifdef CONFIG_DEBUG_ENABLE -void dbg_enable(bool enable) -{ - g_dbgenable = enable; -} -#endif - -/**************************************************************************** - * Name: dbg, lldbg, vdbg - * - * Description: - * If the cross-compiler's pre-processor does not support variable - * length arguments, then these additional APIs will be built. - * - ****************************************************************************/ - -#ifndef CONFIG_CPP_HAVE_VARARGS -#ifdef CONFIG_DEBUG -int dbg(const char *format, ...) -{ - va_list ap; - int ret; - -#ifdef CONFIG_DEBUG_ENABLE - ret = 0; - if (g_dbgenable) -#endif - { - va_start(ap, format); - ret = lib_rawvprintf(format, ap); - va_end(ap); - } - - return ret; -} - -#ifdef CONFIG_ARCH_LOWPUTC -int lldbg(const char *format, ...) -{ - va_list ap; - int ret; - -#ifdef CONFIG_DEBUG_ENABLE - ret = 0; - if (g_dbgenable) -#endif - { - va_start(ap, format); - ret = lib_lowvprintf(format, ap); - va_end(ap); - } - - return ret; -} -#endif - -#ifdef CONFIG_DEBUG_VERBOSE -int vdbg(const char *format, ...) -{ - va_list ap; - int ret; - -#ifdef CONFIG_DEBUG_ENABLE - ret = 0; - if (g_dbgenable) -#endif - { - va_start(ap, format); - ret = lib_rawvprintf(format, ap); - va_end(ap); - } - - return ret; -} - -#ifdef CONFIG_ARCH_LOWPUTC -int llvdbg(const char *format, ...) -{ - va_list ap; - int ret; - -#ifdef CONFIG_DEBUG_ENABLE - ret = 0; - if (g_dbgenable) -#endif - { - va_start(ap, format); - ret = lib_lowvprintf(format, ap); - va_end(ap); - } - - return ret; -} -#endif /* CONFIG_ARCH_LOWPUTC */ -#endif /* CONFIG_DEBUG_VERBOSE */ -#endif /* CONFIG_DEBUG */ -#endif /* CONFIG_CPP_HAVE_VARARGS */ diff --git a/nuttx/lib/misc/lib_dumpbuffer.c b/nuttx/lib/misc/lib_dumpbuffer.c deleted file mode 100644 index 155468ca1..000000000 --- a/nuttx/lib/misc/lib_dumpbuffer.c +++ /dev/null @@ -1,129 +0,0 @@ -/**************************************************************************** - * lib/misc/lib_dumpbuffer.c - * - * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 -#include - -#include -#include - -/**************************************************************************** - * Pre-processor definitions - ****************************************************************************/ - -/* Select the lowest level debug interface available */ - -#ifdef CONFIG_CPP_HAVE_VARARGS -# ifdef CONFIG_ARCH_LOWPUTC -# define message(format, arg...) lib_lowprintf(format, ##arg) -# else -# define message(format, arg...) lib_rawprintf(format, ##arg) -# endif -#else -# ifdef CONFIG_ARCH_LOWPUTC -# define message lib_lowprintf -# else -# define message lib_rawprintf -# endif -#endif - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: lib_dumpbuffer - * - * Description: - * Do a pretty buffer dump - * - ****************************************************************************/ - -void lib_dumpbuffer(FAR const char *msg, FAR const uint8_t *buffer, unsigned int buflen) -{ - int i, j, k; - - message("%s (%p):\n", msg, buffer); - for (i = 0; i < buflen; i += 32) - { - message("%04x: ", i); - for (j = 0; j < 32; j++) - { - k = i + j; - - if (j == 16) - { - message(" "); - } - - if (k < buflen) - { - message("%02x", buffer[k]); - } - else - { - message(" "); - } - } - - message(" "); - for (j = 0; j < 32; j++) - { - k = i + j; - - if (j == 16) - { - message(" "); - } - - if (k < buflen) - { - if (buffer[k] >= 0x20 && buffer[k] < 0x7f) - { - message("%c", buffer[k]); - } - else - { - message("."); - } - } - } - message("\n"); - } -} diff --git a/nuttx/lib/misc/lib_filesem.c b/nuttx/lib/misc/lib_filesem.c deleted file mode 100644 index 1d1f25c2f..000000000 --- a/nuttx/lib/misc/lib_filesem.c +++ /dev/null @@ -1,145 +0,0 @@ -/************************************************************************ - * lib/misc/lib_filesem.c - * - * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include -#include -#include -#include - -#include "lib_internal.h" - -#if CONFIG_STDIO_BUFFER_SIZE > 0 - -/************************************************************************ - * Pre-processor Definitions - ************************************************************************/ - -/************************************************************************ - * Private Data - ************************************************************************/ - -/************************************************************************ - * Global Functions - ************************************************************************/ - -/************************************************************************ - * lib_sem_initialize - ************************************************************************/ - -void lib_sem_initialize(FAR struct file_struct *stream) -{ - /* Initialize the LIB semaphore to one (to support one-at- - * a-time access to private data sets. - */ - - (void)sem_init(&stream->fs_sem, 0, 1); - - stream->fs_holder = -1; - stream->fs_counts = 0; -} - -/************************************************************************ - * lib_take_semaphore - ************************************************************************/ - -void lib_take_semaphore(FAR struct file_struct *stream) -{ - pid_t my_pid = getpid(); - - /* Do I already have the semaphore? */ - - if (stream->fs_holder == my_pid) - { - /* Yes, just increment the number of references that I have */ - - stream->fs_counts++; - } - else - { - /* Take the semaphore (perhaps waiting) */ - - while (sem_wait(&stream->fs_sem) != 0) - { - /* The only case that an error should occr here is if - * the wait was awakened by a signal. - */ - - ASSERT(get_errno() == EINTR); - } - - /* We have it. Claim the stak and return */ - - stream->fs_holder = my_pid; - stream->fs_counts = 1; - } -} - -/************************************************************************ - * lib_give_semaphore - ************************************************************************/ - -void lib_give_semaphore(FAR struct file_struct *stream) -{ - pid_t my_pid = getpid(); - - /* I better be holding at least one reference to the semaphore */ - - ASSERT(stream->fs_holder == my_pid); - - /* Do I hold multiple references to the semphore */ - - if (stream->fs_counts > 1) - { - /* Yes, just release one count and return */ - - stream->fs_counts--; - } - else - { - /* Nope, this is the last reference I have */ - - stream->fs_holder = -1; - stream->fs_counts = 0; - ASSERT(sem_post(&stream->fs_sem) == 0); - } -} -#endif /* CONFIG_STDIO_BUFFER_SIZE */ diff --git a/nuttx/lib/misc/lib_init.c b/nuttx/lib/misc/lib_init.c deleted file mode 100644 index 3403a837b..000000000 --- a/nuttx/lib/misc/lib_init.c +++ /dev/null @@ -1,207 +0,0 @@ -/************************************************************ - * lib/misc/lib_init.c - * - * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include -#include - -#include -#include -#include - -#include "lib_internal.h" - -/************************************************************ - * Definitions - ************************************************************/ - -/************************************************************ - * Private Variables - ************************************************************/ - -/************************************************************ - * Private Functions - ************************************************************/ - -/************************************************************ - * Public Functions - ************************************************************/ - -/************************************************************ - * lib_initialize - ************************************************************/ - -/* General library initialization hook */ - -void weak_const_function lib_initialize(void) -{ -} - -#if CONFIG_NFILE_STREAMS > 0 -/* The following function is called when a new TCB is allocated. It - * creates the streamlist instance that is stored in the TCB. - */ - -FAR struct streamlist *lib_alloclist(void) -{ - FAR struct streamlist *list; - list = (FAR struct streamlist*)lib_zalloc(sizeof(struct streamlist)); - if (list) - { - int i; - - /* Start with a reference count of one */ - - list->sl_crefs = 1; - - /* Initialize the list access mutex */ - - (void)sem_init(&list->sl_sem, 0, 1); - - /* Initialize each FILE structure */ - - for (i = 0; i < CONFIG_NFILE_STREAMS; i++) - { - /* Clear the IOB */ - - memset(&list->sl_streams[i], 0, sizeof(FILE)); - - /* Indicate not opened */ - - list->sl_streams[i].fs_filedes = -1; - - /* Initialize the stream semaphore to one to support one-at- - * a-time access to private data sets. - */ - - lib_sem_initialize(&list->sl_streams[i]); - } - } - return list; - -} - -/* This function is called when a TCB is closed (such as with - * pthread_create(). It increases the reference count on the stream - * list. - */ - -void lib_addreflist(FAR struct streamlist *list) -{ - if (list) - { - /* Increment the reference count on the list. - * NOTE: that we disable interrupts to do this - * (vs. taking the list semaphore). We do this - * because file cleanup operations often must be - * done from the IDLE task which cannot wait - * on semaphores. - */ - - register irqstate_t flags = irqsave(); - list->sl_crefs++; - irqrestore(flags); - } -} - -/* this function is called when a TCB is destroyed. Note that is - * does not close the file by release this inode. This happens - * separately when the file descriptor list is freed. - */ - -void lib_releaselist(FAR struct streamlist *list) -{ - int crefs; - if (list) - { - /* Decrement the reference count on the list. - * NOTE: that we disable interrupts to do this - * (vs. taking the list semaphore). We do this - * because file cleanup operations often must be - * done from the IDLE task which cannot wait - * on semaphores. - */ - - register irqstate_t flags = irqsave(); - crefs = --(list->sl_crefs); - irqrestore(flags); - - /* If the count decrements to zero, then there is no reference - * to the structure and it should be deallocated. Since there - * are references, it would be an error if any task still held - * a reference to the list's semaphore. - */ - - if (crefs <= 0) - { -#if CONFIG_STDIO_BUFFER_SIZE > 0 - int i; -#endif - /* Destroy the semaphore and release the filelist */ - - (void)sem_destroy(&list->sl_sem); - - /* Release each stream in the list */ - -#if CONFIG_STDIO_BUFFER_SIZE > 0 - for (i = 0; i < CONFIG_NFILE_STREAMS; i++) - { - /* Destroy the semaphore that protects the IO buffer */ - - (void)sem_destroy(&list->sl_streams[i].fs_sem); - - /* Release the IO buffer */ - if (list->sl_streams[i].fs_bufstart) - { - sched_free(list->sl_streams[i].fs_bufstart); - } - } -#endif - /* Finally, release the list itself */ - - sched_free(list); - } - } -} - -#endif /* CONFIG_NFILE_STREAMS */ - - diff --git a/nuttx/lib/misc/lib_match.c b/nuttx/lib/misc/lib_match.c deleted file mode 100644 index 18e0632ec..000000000 --- a/nuttx/lib/misc/lib_match.c +++ /dev/null @@ -1,148 +0,0 @@ -/**************************************************************************** - * lib/misc/lib_match.c - simple shell-style filename matcher - * - * Simple shell-style filename pattern matcher written by Jef Poskanzer - * This pattern matcher only handles '?', '*' and '**', and multiple - * patterns separated by '|'. - * - * Copyright © 1995,2000 by Jef Poskanzer . - * All rights reserved. - * - * 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. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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 -#include - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: match_one - * - * Description: - * Does all of the work for one '|' delimited pattern - * - * Returned Value: - * Returns 1 (match) or 0 (no-match). - * - ****************************************************************************/ - -static int match_one(const char *pattern, int patlen, const char *string) -{ - const char *p; - int pl; - int i; - - for (p = pattern; p - pattern < patlen; p++, string++) - { - if (*p == '?' && *string != '\0') - { - continue; - } - - if (*p == '*') - { - p++; - if (*p == '*') - { - /* Double-wildcard matches anything. */ - - p++; - i = strlen(string); - } - else - { - /* Single-wildcard matches anything but slash. */ - - i = strcspn(string, "/"); - } - - pl = patlen - (p - pattern); - for (; i >= 0; i--) - { - if (match_one(p, pl, &(string[i]))) - { - return 1; - } - } - return 0; - } - - if (*p != *string) - { - return 0; - } - } - - if (*string == '\0') - { - return 1; - } - return 0; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: match - * - * Description: - * Simple shell-style filename pattern matcher written by Jef Poskanzer - * This pattern matcher only handles '?', '*' and '**', and multiple - * patterns separated by '|'. - * - * Returned Value: - * Returns 1 (match) or 0 (no-match). - * - ****************************************************************************/ - -int match(const char *pattern, const char *string) -{ - const char *or; - - for (;;) - { - or = strchr(pattern, '|'); - if (or == (char *)0) - { - return match_one(pattern, strlen(pattern), string); - } - - if (match_one(pattern, or - pattern, string)) - { - return 1; - } - - pattern = or + 1; - } -} - diff --git a/nuttx/lib/misc/lib_sendfile.c b/nuttx/lib/misc/lib_sendfile.c deleted file mode 100644 index a82eb325e..000000000 --- a/nuttx/lib/misc/lib_sendfile.c +++ /dev/null @@ -1,297 +0,0 @@ -/************************************************************************ - * lib/misc/lib_streamsem.c - * - * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include -#include -#include -#include - -#if CONFIG_NSOCKET_DESCRIPTORS > 0 || CONFIG_NFILE_DESCRIPTORS > 0 - -/************************************************************************ - * Private types - ************************************************************************/ - -/************************************************************************ - * Private Variables - ************************************************************************/ - -/************************************************************************ - * Public Variables - ************************************************************************/ - -/************************************************************************ - * Private Functions - ************************************************************************/ - -/************************************************************************ - * Public Functions - ************************************************************************/ - -/************************************************************************ - * Name: sendfile - * - * Description: - * sendfile() copies data between one file descriptor and another. - * sendfile() basically just wraps a sequence of reads() and writes() - * to perform a copy. It serves a purpose in systems where there is - * a penalty for copies to between user and kernal space, but really - * nothing in NuttX but provide some Linux compatible (and adding - * another 'almost standard' interface). - * - * NOTE: This interface is *not* specified in POSIX.1-2001, or other - * standards. The implementation here is very similar to the Linux - * sendfile interface. Other UNIX systems implement sendfile() with - * different semantics and prototypes. sendfile() should not be used - * in portable programs. - * - * Input Parmeters: - * infd - A file (or socket) descriptor opened for reading - * outfd - A descriptor opened for writing. - * offset - If 'offset' is not NULL, then it points to a variable - * holding the file offset from which sendfile() will start - * reading data from 'infd'. When sendfile() returns, this - * variable will be set to the offset of the byte following - * the last byte that was read. If 'offset' is not NULL, - * then sendfile() does not modify the current file offset of - * 'infd'; otherwise the current file offset is adjusted to - * reflect the number of bytes read from 'infd.' - * - * If 'offset' is NULL, then data will be read from 'infd' - * starting at the current file offset, and the file offset - * will be updated by the call. - * count - The number of bytes to copy between the file descriptors. - * - * Returned Value: - * If the transfer was successful, the number of bytes written to outfd is - * returned. On error, -1 is returned, and errno is set appropriately. - * There error values are those returned by read() or write() plus: - * - * EINVAL - Bad input parameters. - * ENOMEM - Could not allocated an I/O buffer - * - ************************************************************************/ - -ssize_t sendfile(int outfd, int infd, off_t *offset, size_t count) -{ - FAR uint8_t *iobuffer; - FAR uint8_t *wrbuffer; - off_t startpos = 0; - ssize_t nbytesread; - ssize_t nbyteswritten; - size_t ntransferred; - bool endxfr; - - /* Get the current file position. */ - - if (offset) - { - /* Use lseek to get the current file position */ - - startpos = lseek(infd, 0, SEEK_CUR); - if (startpos == (off_t)-1) - { - return ERROR; - } - - /* Use lseek again to set the new file position */ - - if (lseek(infd, *offset, SEEK_SET) == (off_t)-1) - { - return ERROR; - } - } - - /* Allocate an I/O buffer */ - - iobuffer = (FAR void *)malloc(CONFIG_LIB_SENDFILE_BUFSIZE); - if (!iobuffer) - { - set_errno(ENOMEM); - return ERROR; - } - - /* Now transfer 'count' bytes from the infd to the outfd */ - - for (ntransferred = 0, endxfr = false; ntransferred < count && !endxfr; ) - { - /* Loop until the read side of the transfer comes to some conclusion */ - - do - { - /* Read a buffer of data from the infd */ - - nbytesread = read(infd, iobuffer, CONFIG_LIB_SENDFILE_BUFSIZE); - - /* Check for end of file */ - - if (nbytesread == 0) - { - /* End of file. Break out and return current number of bytes - * transferred. - */ - - endxfr = true; - break; - } - - /* Check for a read ERROR. EINTR is a special case. This function - * should break out and return an error if EINTR is returned and - * no data has been transferred. But what should it do if some - * data has been transferred? I suppose just continue? - */ - - else if (nbytesread < 0) - { - /* EINTR is not an error (but will still stop the copy) */ - -#ifndef CONFIG_DISABLE_SIGNALS - if (errno != EINTR || ntransferred == 0) -#endif - { - /* Read error. Break out and return the error condition. */ - - ntransferred = ERROR; - endxfr = true; - break; - } - } - } - while (nbytesread < 0); - - /* Was anything read? */ - - if (!endxfr) - { - /* Yes.. Loop until the read side of the transfer comes to some - * conclusion. - */ - - wrbuffer = iobuffer; - do - { - /* Write the buffer of data to the outfd */ - - nbyteswritten = write(outfd, wrbuffer, nbytesread); - - /* Check for a complete (or parial) write. write() should not - * return zero. - */ - - if (nbyteswritten >= 0) - { - /* Advance the buffer pointer and decrement the number of bytes - * remaining in the iobuffer. Typically, nbytesread will now - * be zero. - */ - - wrbuffer += nbyteswritten; - nbytesread -= nbyteswritten; - - /* Increment the total number of bytes successfully transferred. */ - - ntransferred += nbyteswritten; - } - - /* Otherwise an error occurred */ - - else - { - /* Check for a read ERROR. EINTR is a special case. This - * function should break out and return an error if EINTR - * is returned and no data has been transferred. But what - * should it do if some data has been transferred? I - * suppose just continue? - */ - -#ifndef CONFIG_DISABLE_SIGNALS - if (errno != EINTR || ntransferred == 0) -#endif - { - /* Write error. Break out and return the error condition */ - - ntransferred = ERROR; - endxfr = true; - break; - } - } - } - while (nbytesread > 0); - } - } - - /* Release the I/O buffer */ - - free(iobuffer); - - /* Return the current file position */ - - if (offset) - { - /* Use lseek to get the current file position */ - - off_t curpos = lseek(infd, 0, SEEK_CUR); - if (curpos == (off_t)-1) - { - return ERROR; - } - - /* Return the current file position */ - - *offset = curpos; - - /* Use lseek again to restore the original file position */ - - if (lseek(infd, startpos, SEEK_SET) == (off_t)-1) - { - return ERROR; - } - } - - /* Finally return the number of bytes actually transferred (or ERROR - * if any failure occurred). - */ - - return ntransferred; -} - -#endif /* CONFIG_NSOCKET_DESCRIPTORS > 0 || CONFIG_NFILE_DESCRIPTORS > 0 */ diff --git a/nuttx/lib/misc/lib_streamsem.c b/nuttx/lib/misc/lib_streamsem.c deleted file mode 100644 index fdf494e75..000000000 --- a/nuttx/lib/misc/lib_streamsem.c +++ /dev/null @@ -1,90 +0,0 @@ -/************************************************************************ - * lib/misc/lib_streamsem.c - * - * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include -#include -#include -#include -#include - -#include "lib_internal.h" - -/************************************************************************ - * Private types - ************************************************************************/ - -/************************************************************************ - * Private Variables - ************************************************************************/ - -/************************************************************************ - * Public Variables - ************************************************************************/ - -/************************************************************************ - * Private Functions - ************************************************************************/ - -/************************************************************************ - * Public Functions - ************************************************************************/ - -void stream_semtake(FAR struct streamlist *list) -{ - /* Take the semaphore (perhaps waiting) */ - - while (sem_wait(&list->sl_sem) != 0) - { - /* The only case that an error should occr here is if - * the wait was awakened by a signal. - */ - - ASSERT(get_errno() == EINTR); - } -} - -void stream_semgive(FAR struct streamlist *list) -{ - sem_post(&list->sl_sem); -} - - diff --git a/nuttx/lib/mqueue/Make.defs b/nuttx/lib/mqueue/Make.defs deleted file mode 100644 index 40dc6c13e..000000000 --- a/nuttx/lib/mqueue/Make.defs +++ /dev/null @@ -1,48 +0,0 @@ -############################################################################ -# lib/mqueue/Make.defs -# -# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt -# -# 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. -# -############################################################################ - -ifneq ($(CONFIG_DISABLE_MQUEUE),y) - -# Add the mqueue C files to the build - -CSRCS += mq_setattr.c mq_getattr.c - -# Add the mqueue directory to the build - -DEPPATH += --dep-path mqueue -VPATH += :mqueue - -endif - diff --git a/nuttx/lib/mqueue/mq_getattr.c b/nuttx/lib/mqueue/mq_getattr.c deleted file mode 100644 index 9c9f47fdc..000000000 --- a/nuttx/lib/mqueue/mq_getattr.c +++ /dev/null @@ -1,104 +0,0 @@ -/************************************************************************ - * lib/mqueue/mq_getattr.c - * - * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include - -/************************************************************************ - * Definitions - ************************************************************************/ - -/************************************************************************ - * Private Type Declarations - ************************************************************************/ - -/************************************************************************ - * Global Variables - ************************************************************************/ - -/************************************************************************ - * Private Variables - ************************************************************************/ - -/************************************************************************ - * Private Functions - ************************************************************************/ - -/************************************************************************ - * Public Functions - ************************************************************************/ - -/************************************************************************ - * Function: mq_getattr - * - * Description: - * This functions gets status information and attributes - * associated with the specified message queue. - * - * Parameters: - * mqdes - Message queue descriptor - * mq_stat - Buffer in which to return attributes - * - * Return Value: - * 0 (OK) if attributes provided, -1 (ERROR) otherwise. - * - * Assumptions: - * - ************************************************************************/ - -int mq_getattr(mqd_t mqdes, struct mq_attr *mq_stat) -{ - int ret = ERROR; - - if (mqdes && mq_stat) - { - /* Return the attributes */ - - mq_stat->mq_maxmsg = mqdes->msgq->maxmsgs; - mq_stat->mq_msgsize = mqdes->msgq->maxmsgsize; - mq_stat->mq_flags = mqdes->oflags; - mq_stat->mq_curmsgs = mqdes->msgq->nmsgs; - - ret = OK; - } - - return ret; -} diff --git a/nuttx/lib/mqueue/mq_setattr.c b/nuttx/lib/mqueue/mq_setattr.c deleted file mode 100644 index 1276d64e8..000000000 --- a/nuttx/lib/mqueue/mq_setattr.c +++ /dev/null @@ -1,118 +0,0 @@ -/************************************************************************ - * lib/mqueue/mq_setattr.c - * - * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include /* O_NONBLOCK */ -#include - -#include - -/************************************************************************ - * Definitions - ************************************************************************/ - -/************************************************************************ - * Private Type Declarations - ************************************************************************/ - -/************************************************************************ - * Global Variables - ************************************************************************/ - -/************************************************************************ - * Private Variables - ************************************************************************/ - -/************************************************************************ - * Private Functions - ************************************************************************/ - -/************************************************************************ - * Public Functions - ************************************************************************/ - -/************************************************************************ - * Function: mq_setattr - * - * Description: - * This function sets the attributes associated with the - * specified message queue "mqdes." Only the "O_NONBLOCK" - * bit of the "mq_flags" can be changed. - * - * If "oldstat" is non-null, mq_setattr() will store the - * previous message queue attributes at that location (just - * as would have been returned by mq_getattr()). - * - * Parameters: - * mqdes - Message queue descriptor - * mq_stat - New attributes - * oldstate - Old attributes - * - * Return Value: - * 0 (OK) if attributes are set successfully, otherwise - * -1 (ERROR). - * - * Assumptions: - * - ************************************************************************/ - -int mq_setattr(mqd_t mqdes, const struct mq_attr *mq_stat, - struct mq_attr *oldstat) -{ - int ret = ERROR; - - if (mqdes && mq_stat) - { - /* Return the attributes if so requested */ - - if (oldstat) - { - (void)mq_getattr(mqdes, oldstat); - } - - /* Set the new value of the O_NONBLOCK flag. */ - - mqdes->oflags = ((mq_stat->mq_flags & O_NONBLOCK) | - (mqdes->oflags & (~O_NONBLOCK))); - ret = OK; - } - - return ret; -} diff --git a/nuttx/lib/net/Make.defs b/nuttx/lib/net/Make.defs deleted file mode 100644 index ae041bd2c..000000000 --- a/nuttx/lib/net/Make.defs +++ /dev/null @@ -1,44 +0,0 @@ -############################################################################ -# lib/net/Make.defs -# -# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt -# -# 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. -# -############################################################################ - -# Add the networking C files to the build - -CSRCS += lib_etherntoa.c lib_htons.c lib_htonl.c lib_inetaddr.c -CSRCS += lib_inetntoa.c lib_inetntop.c lib_inetpton.c - -# Add the net directory to the build - -DEPPATH += --dep-path net -VPATH += :net diff --git a/nuttx/lib/net/lib_etherntoa.c b/nuttx/lib/net/lib_etherntoa.c deleted file mode 100644 index f89f205a2..000000000 --- a/nuttx/lib/net/lib_etherntoa.c +++ /dev/null @@ -1,69 +0,0 @@ -/**************************************************************************** - * lib/net/lib_etherntoa.c - * - * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 -#include - -#include -#include - -/**************************************************************************** - * Global Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: ether_ntoa - * - * Description: - * The ether_ntoa() function converts the Ethernet host address addr given - * in network byte order to a string in standard hex-digits-and-colons - * notation. The string is returned in a statically allocated buffer, which - * subsequent calls will overwrite. - * - ****************************************************************************/ - -FAR char *ether_ntoa(FAR const struct ether_addr *addr) -{ - static char buffer[20]; - sprintf(buffer, "%02x:%02x:%02x:%02x:%02x:%02x", - addr->ether_addr_octet[0], addr->ether_addr_octet[1], - addr->ether_addr_octet[2], addr->ether_addr_octet[3], - addr->ether_addr_octet[4], addr->ether_addr_octet[5]); - return buffer; -} diff --git a/nuttx/lib/net/lib_htonl.c b/nuttx/lib/net/lib_htonl.c deleted file mode 100644 index e4c3e5383..000000000 --- a/nuttx/lib/net/lib_htonl.c +++ /dev/null @@ -1,68 +0,0 @@ -/************************************************************ - * lib/net/lib_ntohl.c - * - * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include - -/************************************************************ - * Global Functions - ************************************************************/ - -uint32_t htonl(uint32_t hl) -{ -#ifdef CONFIG_ENDIAN_BIG - return hl; -#else - return (( (hl) >> 24) | - (((hl) >> 8) & 0x0000ff00) | - (((hl) << 8) & 0x00ff0000) | - ( (hl) << 24)); -#endif -} - -uint32_t ntohl(uint32_t nl) -{ -#ifdef CONFIG_ENDIAN_BIG - return nl; -#else - return htonl(nl); -#endif -} diff --git a/nuttx/lib/net/lib_htons.c b/nuttx/lib/net/lib_htons.c deleted file mode 100644 index b4117e1dc..000000000 --- a/nuttx/lib/net/lib_htons.c +++ /dev/null @@ -1,65 +0,0 @@ -/*************************************************************************** - * lib/net/lib_htons.c - * - * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ***************************************************************************/ - -/*************************************************************************** - * Compilation Switches - ***************************************************************************/ - -/*************************************************************************** - * Included Files - ***************************************************************************/ - -#include - -#include -#include - -/*************************************************************************** - * Global Functions - ***************************************************************************/ - -uint16_t htons(uint16_t hs) -{ - return HTONS(hs); -} - -uint16_t ntohs(uint16_t ns) -{ -#ifdef CONFIG_ENDIAN_BIG - return ns; -#else - return htons(ns); -#endif -} diff --git a/nuttx/lib/net/lib_inetaddr.c b/nuttx/lib/net/lib_inetaddr.c deleted file mode 100644 index 48b01d682..000000000 --- a/nuttx/lib/net/lib_inetaddr.c +++ /dev/null @@ -1,74 +0,0 @@ -/**************************************************************************** - * lib/net/lib_inetaddr.c - * - * Copyright (C) 2011 Yu Qiang. All rights reserved. - * Author: Yu Qiang - * - * This file is a part of NuttX: - * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * - * 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 -#include - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * name inet_addr - * - * Description: - * The inet_addr() function converts the string pointed to by cp, in the - * standard IPv4 dotted decimal notation, to an integer value suitable for - * use as an Internet address. - - ****************************************************************************/ - -in_addr_t inet_addr(FAR const char *cp) -{ - unsigned int a, b, c, d; - uint32_t result; - - sscanf(cp, "%u.%u.%u.%u", &a, &b, &c, &d); - result = a << 8; - result |= b; - result <<= 8; - result |= c; - result <<= 8; - result |= d; - return HTONL(result); -} diff --git a/nuttx/lib/net/lib_inetntoa.c b/nuttx/lib/net/lib_inetntoa.c deleted file mode 100644 index 0f4fb61df..000000000 --- a/nuttx/lib/net/lib_inetntoa.c +++ /dev/null @@ -1,79 +0,0 @@ -/**************************************************************************** - * lib/net/lib_inetntoa.c - * - * Copyright (C) 2007-2008, 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 -#include -#include - -#ifndef CONFIG_NET_IPv6 - -/**************************************************************************** - * Global Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: inet_ntoa - * - * Description: - * The inet_ntoa() function converts the Internet host address in given in - * network byte order to a string in standard numbers-and-dots notation. - * The string is returned in a statically allocated buffer, which subsequent - * calls will overwrite. - * - ****************************************************************************/ - -#ifdef CONFIG_CAN_PASS_STRUCTS -FAR char *inet_ntoa(struct in_addr in) -{ - static char buffer[INET_ADDRSTRLEN+2]; - FAR char *ptr = (FAR char*)&in.s_addr; - sprintf(buffer, "%d.%d.%d.%d", ptr[0], ptr[1], ptr[2], ptr[3]); - return buffer; -} -#else -FAR char *_inet_ntoa(in_addr_t in) -{ - static char buffer[INET_ADDRSTRLEN+2]; - FAR char *ptr = (FAR char*)∈ - sprintf(buffer, "%d.%d.%d.%d", ptr[0], ptr[1], ptr[2], ptr[3]); - return buffer; -} -#endif -#endif /* !CONFIG_NET_IPv6 */ - diff --git a/nuttx/lib/net/lib_inetntop.c b/nuttx/lib/net/lib_inetntop.c deleted file mode 100644 index dc6a2d0d7..000000000 --- a/nuttx/lib/net/lib_inetntop.c +++ /dev/null @@ -1,202 +0,0 @@ -/**************************************************************************** - * lib/net/lib_inetntop.c - * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Includes some logic extracted from hwport_ftpd, written by Jaehyuk Cho - * which was released under the BSD license. - * - * Copyright (C) HWPORT.COM. All rights reserved. - * Author: JAEHYUK CHO - * - * 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 - -#include - -#include -#include -#include - -#include - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: inet_ntop - * - * Description: - * The inet_ntop() function converts a numeric address into a text string - * suitable for presentation. - * - * Input Parameters: - * af - The af argument specifies the family of the address. This can be - * AF_INET or AF_INET6. - * src - The src argument points to a buffer holding an address of the - * specified type. The address must be in network byte order. - * dst - The dst argument points to a buffer where the function stores - * the resulting text string; it shall not be NULL. - * size - The size argument specifies the size of this buffer, which must - * be large enough to hold the text string (INET_ADDRSTRLEN - * characters for IPv4, INET6_ADDRSTRLEN characters for IPv6). - * - * Returned Value: - * inet_ntop() returns a pointer to the buffer containing the text string - * if the conversion succeeds. Otherwise, NULL is returned and the errno - * is set to indicate the error. There follow errno values may be set: - * - * EAFNOSUPPORT - The af argument is invalid. - * ENOSPC - The size of the inet_ntop() result buffer is inadequate - * - ****************************************************************************/ - -FAR const char *inet_ntop(int af, FAR const void *src, FAR char *dst, socklen_t size) -{ - int errval; -#ifndef CONFIG_NET_IPv6 - FAR char *ptr; - - DEBUGASSERT(src && dst); - - if (af != AF_INET) - { - errval = EAFNOSUPPORT; - goto errout; - } - - if (size < INET_ADDRSTRLEN) - { - errval = ENOSPC; - goto errout; - } - - ptr = (FAR char*)src; - sprintf(dst, "%d.%d.%d.%d", ptr[0], ptr[1], ptr[2], ptr[3]); - return dst; -#else - FAR const struct in6_addr *in6_addr; - uint16_t warray[8]; - int offset; - int entry; - int count; - int maxentry; - int maxcount; - - DEBUGASSERT(src && dst); - - if (af != AF_INET6) - { - errval = EAFNOSUPPORT; - goto errout; - } - - if (size < INET6_ADDRSTRLEN) - { - errval = ENOSPC; - goto errout; - } - - in6_addr = (FAR const struct in6_addr *)src; - entry = -1; - maxentry = -1; - maxcount = 0; - offset = 0; - - while (offset < 8) - { - warray[offset] = ntohs(in6_addr->s6_addr16[offset]); - if (warray[offset] == 0) - { - entry = offset; - count = 1; - offset++; - - while (offset < 8) - { - warray[offset] = ntohs(in6_addr->s6_addr16[offset]); - if (warray[offset] != 0) - { - break; - } - offset++; - count++; - } - - if (count > maxcount) - { - maxentry = entry; - maxcount = count; - } - } - offset++; - } - - offset = 0; - dst[0] = '\0'; - - while (offset < 8) - { - if (offset == maxentry) - { - size -= snprintf(&dst[strlen(dst)], size, ":"); - offset += maxcount; - if (offset >= 8) - { - size -= snprintf(&dst[strlen(dst)], size, ":"); - } - } - else - { - if (offset > 0) - { - size -= snprintf(&dst[strlen(dst)], size, ":"); - } - - size -= snprintf(&dst[strlen(dst)], size, "%x", warray[offset]); - offset++; - } - } - - return dst; -#endif - -errout: - set_errno(errval); - memset(dst, 0, size); - return NULL; -} diff --git a/nuttx/lib/net/lib_inetpton.c b/nuttx/lib/net/lib_inetpton.c deleted file mode 100644 index 5371cd3f2..000000000 --- a/nuttx/lib/net/lib_inetpton.c +++ /dev/null @@ -1,338 +0,0 @@ -/**************************************************************************** - * lib/net/lib_inetpton.c - * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Includes some logic extracted from hwport_ftpd, written by Jaehyuk Cho - * which was released under the BSD license. - * - * Copyright (C) HWPORT.COM. All rights reserved. - * Author: JAEHYUK CHO - * - * 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 - -#include - -#include -#include -#include -#include - -#include - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: inet_pton - * - * Description: - * The inet_pton() function converts an address in its standard text - * presentation form into its numeric binary form. - * - * If the af argument of inet_pton() is AF_INET, the src string will be - * in the standard IPv4 dotted-decimal form: - * - * ddd.ddd.ddd.ddd - * - * where "ddd" is a one to three digit decimal number between 0 and 255. - * - * If the af argument of inet_pton() is AF_INET6, the src string will be in - * one of the following standard IPv6 text forms: - * - * 1. The preferred form is "x:x:x:x:x:x:x:x", where the 'x' s are the - * hexadecimal values of the eight 16-bit pieces of the address. Leading - * zeros in individual fields can be omitted, but there must be at least - * one numeral in every field. - * - * 2. A string of contiguous zero fields in the preferred form can be shown - * as "::". The "::" can only appear once in an address. Unspecified - * addresses ( "0:0:0:0:0:0:0:0" ) may be represented simply as "::". - * - * 3. A third form that is sometimes more convenient when dealing with a - * mixed environment of IPv4 and IPv6 nodes is "x:x:x:x:x:x:d.d.d.d", - * where the 'x' s are the hexadecimal values of the six high-order - * 16-bit pieces of the address, and the 'd' s are the decimal values - * of the four low-order 8-bit pieces of the address (standard IPv4 - * representation). - * - * Input Parameters: - * af - The af argument specifies the family of the address. This can be - * AF_INET or AF_INET6. - * src - The src argument points to the string being passed in. - * dst - The dst argument points to a numstr into which the function stores - * the numeric address; this must be large enough to hold the numeric - * address (32 bits for AF_INET, 128 bits for AF_INET6). - * - * Returned Value: - * The inet_pton() function returns 1 if the conversion succeeds, with the - * address pointed to by dst in network byte order. It will return 0 if the - * input is not a valid IPv4 dotted-decimal string or a valid IPv6 address - * string, or -1 with errno set to EAFNOSUPPOR] if the af argument is unknown. - * - ****************************************************************************/ - -int inet_pton(int af, FAR const char *src, FAR void *dst) -{ -#ifndef CONFIG_NET_IPv6 - size_t srcoffset; - size_t numoffset; - int value; - int ndots; - uint8_t ch; - char numstr[4]; - uint8_t *ip; - - DEBUGASSERT(src && dst); - - if (af != AF_INET) - { - set_errno(EAFNOSUPPORT); - return -1; - } - - (void)memset(dst, 0, sizeof(struct in_addr)); - - ip = (uint8_t *)dst; - srcoffset = 0; - numoffset = 0; - ndots = 0; - - for(;;) - { - ch = (uint8_t)src[srcoffset++]; - - if (ch == '.' || ch == '\0') - { - if (ch == '.' && ndots >= 4) - { - /* Too many dots */ - - break; - } - - if (numoffset <= 0) - { - /* Empty numeric string */ - - break; - } - - numstr[numoffset] = '\0'; - numoffset = 0; - - value = atoi(numstr); - if (value < 0 || value > 255) - { - /* Out of range value */ - - break; - } - - ip[ndots] = (uint8_t)value; - - if (ch == '\0') - { - if (ndots != 3) - { - /* Not enough dots */ - - break; - } - - /* Return 1 if the conversion succeeds */ - - return 1; - } - - ndots++; - } - else if (ch >= '0' && ch <= '9') - { - numstr[numoffset++] = ch; - if (numoffset >= 4) - { - /* Number is too long */ - - break; - } - } - else - { - /* Illegal character */ - - break; - } - } - - /* Return zero if there is any problem parsing the input */ - - return 0; -#else - size_t srcoffset; - size_t numoffset; - long value; - int nsep; - int nrsep; - uint8_t ch; - char numstr[5]; - uint8_t ip[sizeof(struct in6_addr)]; - uint8_t rip[sizeof(struct in6_addr)]; - bool rtime; - - DEBUGASSERT(src && dst); - - if (af != AF_INET6) - { - set_errno(EAFNOSUPPORT); - return -1; - } - - (void)memset(dst, 0, sizeof(struct in6_addr)); - - srcoffset = 0; - numoffset = 0; - nsep = 0; - nrsep = 0; - rtime = false; - - for(;;) - { - ch = (uint8_t)src[srcoffset++]; - - if (ch == ':' || ch == '\0') - { - if (ch == ':' && (nsep + nrsep) >= 8) - { - /* Too many separators */ - - break; - } - - if (ch != '\0' && numoffset <= 0) - { - /* Empty numeric string */ - - if (rtime && nrsep > 1) - { - /* dup simple */ - - break; - } - - numoffset = 0; - rtime = true; - continue; - } - - numstr[numoffset] = '\0'; - numoffset = 0; - - value = strtol(numstr, NULL, 16); - if (value < 0 || value > 0xffff) - { - /* Out of range value */ - - break; - } - - if (!rtime) - { - ip[(nsep << 1) + 0] = (uint8_t)((value >> 8) & 0xff); - ip[(nsep << 1) + 1] = (uint8_t)((value >> 0) & 0xff); - nsep++; - } - else - { - rip[(nrsep << 1) + 0] = (uint8_t)((value >> 8) & 0xff); - rip[(nrsep << 1) + 1] = (uint8_t)((value >> 0) & 0xff); - nrsep++; - } - - if (ch == '\0' /* || ch == '/' */) - { - if ((nsep <= 1 && nrsep <= 0) || - (nsep + nrsep) < 1 || - (nsep + nrsep) > 8) - { - /* Separator count problem */ - - break; - } - - if (nsep > 0) - { - memcpy(dst, &ip[0], nsep << 1); - } - - if (nrsep > 0) - { - memcpy(dst + (16 - (nrsep << 1)), &rip[0], nrsep << 1); - } - - /* Return 1 if the conversion succeeds */ - - return 1; - } - } - else if ((ch >= '0' && ch <= '9') || - (ch >= 'a' && ch <= 'f') || - (ch >= 'A' && ch <= 'F')) - { - numstr[numoffset++] = ch; - if (numoffset >= 5) - { - /* Numeric string is too long */ - - break; - } - } - else - { - /* Illegal character */ - - break; - } - } - - - /* Return zero if there is any problem parsing the input */ - - return 0; -#endif -} diff --git a/nuttx/lib/pthread/Make.defs b/nuttx/lib/pthread/Make.defs deleted file mode 100644 index a1eba7bb0..000000000 --- a/nuttx/lib/pthread/Make.defs +++ /dev/null @@ -1,56 +0,0 @@ -############################################################################ -# lib/pthread/Make.defs -# -# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt -# -# 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. -# -############################################################################ - -# Add the pthread C files to the build - -CSRCS += pthread_attrinit.c pthread_attrdestroy.c \ - pthread_attrsetschedpolicy.c pthread_attrgetschedpolicy.c \ - pthread_attrsetinheritsched.c pthread_attrgetinheritsched.c \ - pthread_attrsetstacksize.c pthread_attrgetstacksize.c \ - pthread_attrsetschedparam.c pthread_attrgetschedparam.c \ - pthread_barrierattrinit.c pthread_barrierattrdestroy.c \ - pthread_barrierattrgetpshared.c pthread_barrierattrsetpshared.c \ - pthread_condattrinit.c pthread_condattrdestroy.c \ - pthread_mutexattrinit.c pthread_mutexattrdestroy.c \ - pthread_mutexattrgetpshared.c pthread_mutexattrsetpshared.c - -ifeq ($(CONFIG_MUTEX_TYPES),y) -CSRCS += pthread_mutexattrsettype.c pthread_mutexattrgettype.c -endif - -# Add the pthread directory to the build - -DEPPATH += --dep-path pthread -VPATH += :pthread diff --git a/nuttx/lib/pthread/pthread_attrdestroy.c b/nuttx/lib/pthread/pthread_attrdestroy.c deleted file mode 100644 index 103528c7e..000000000 --- a/nuttx/lib/pthread/pthread_attrdestroy.c +++ /dev/null @@ -1,108 +0,0 @@ -/**************************************************************************** - * lib/pthread/pthread_attrdestroy.c - * - * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include -#include -#include - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Function: pthread_attr_destroy - * - * Description: - * An attributes object can be deleted when it is no longer - * needed. - * - * Parameters: - * attr - * - * Return Value: - * 0 meaning success - * - * Assumptions: - * - ****************************************************************************/ - -int pthread_attr_destroy(FAR pthread_attr_t *attr) -{ - int ret; - - sdbg("attr=0x%p\n", attr); - - if (!attr) - { - ret = EINVAL; - } - else - { - memset(attr, 0, sizeof(pthread_attr_t)); - ret = OK; - } - - sdbg("Returning %d\n", ret); - return ret; -} - - diff --git a/nuttx/lib/pthread/pthread_attrgetinheritsched.c b/nuttx/lib/pthread/pthread_attrgetinheritsched.c deleted file mode 100644 index 02d6e0b7c..000000000 --- a/nuttx/lib/pthread/pthread_attrgetinheritsched.c +++ /dev/null @@ -1,111 +0,0 @@ -/**************************************************************************** - * lib/pthread/pthread_attrgetinheritsched.c - * - * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include -#include -#include - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Function: pthread_attr_getinheritsched - * - * Description: - * Report whether the scheduling info in the pthread - * attributes will be used or if the thread will - * inherit the properties of the parent. - * - * Parameters: - * attr - * inheritsched - * - * Return Value: - * 0 if successful. Otherwise, an error code. - * - * Assumptions: - * - ****************************************************************************/ - -int pthread_attr_getinheritsched(FAR const pthread_attr_t *attr, - FAR int *inheritsched) -{ - int ret; - - sdbg("attr=0x%p inheritsched=0x%p\n", attr, inheritsched); - - if (!attr || !inheritsched) - { - ret = EINVAL; - } - else - { - *inheritsched = (int)attr->inheritsched; - ret = OK; - } - - sdbg("Returning %d\n", ret); - return ret; -} - - diff --git a/nuttx/lib/pthread/pthread_attrgetschedparam.c b/nuttx/lib/pthread/pthread_attrgetschedparam.c deleted file mode 100644 index c6bf55dea..000000000 --- a/nuttx/lib/pthread/pthread_attrgetschedparam.c +++ /dev/null @@ -1,110 +0,0 @@ -/**************************************************************************** - * lib/pthread/pthread_attrgetschedparam.c - * - * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include -#include -#include -#include - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Function: pthread_attr_getschedparam - * - * Description: - * - * Parameters: - * attr - * param - * - * Return Value: - * 0 if successful. Otherwise, an error code. - * - * Assumptions: - * - ****************************************************************************/ - -int pthread_attr_getschedparam(FAR pthread_attr_t *attr, - FAR struct sched_param *param) -{ - int ret; - - sdbg("attr=0x%p param=0x%p\n", attr, param); - - if (!attr || !param) - { - ret = EINVAL; - } - else - { - param->sched_priority = attr->priority; - ret = OK; - } - - sdbg("Returning %d\n", ret); - return ret; -} - - - diff --git a/nuttx/lib/pthread/pthread_attrgetschedpolicy.c b/nuttx/lib/pthread/pthread_attrgetschedpolicy.c deleted file mode 100644 index c42b828c9..000000000 --- a/nuttx/lib/pthread/pthread_attrgetschedpolicy.c +++ /dev/null @@ -1,105 +0,0 @@ -/**************************************************************************** - * lib/pthread/pthread_attrgetschedpolicy.c - * - * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 -#include -#include -#include -#include - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Function: pthread_attr_getschedpolicy - * - * Description: - * Obtain the scheduling algorithm attribute. - * - * Parameters: - * attr - * policy - * - * Return Value: - * 0 if successful. Otherwise, an error code. - * - * Assumptions: - * - ****************************************************************************/ - -int pthread_attr_getschedpolicy(FAR pthread_attr_t *attr, int *policy) -{ - int ret; - - sdbg("attr=0x%p policy=0x%p\n", attr, policy); - - if (!attr || !policy) - { - ret = EINVAL; - } - else - { - *policy = attr->policy; - ret = OK; - } - - sdbg("Returning %d\n", ret); - return ret; -} diff --git a/nuttx/lib/pthread/pthread_attrgetstacksize.c b/nuttx/lib/pthread/pthread_attrgetstacksize.c deleted file mode 100644 index 2faa586ba..000000000 --- a/nuttx/lib/pthread/pthread_attrgetstacksize.c +++ /dev/null @@ -1,106 +0,0 @@ -/**************************************************************************** - * lib/pthread/pthread_attrgetstacksize.c - * - * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 -#include -#include -#include -#include - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Function: pthread_attr_getstacksize - * - * Description: - * - * Parameters: - * attr - * stacksize - * - * Return Value: - * 0 if successful. Otherwise, an error code. - * - * Assumptions: - * - ****************************************************************************/ - -int pthread_attr_getstacksize(FAR pthread_attr_t *attr, FAR long *stacksize) -{ - int ret; - - sdbg("attr=0x%p stacksize=0x%p\n", attr, stacksize); - - if (!stacksize) - { - ret = EINVAL; - } - else - { - *stacksize = attr->stacksize; - ret = OK; - } - - sdbg("Returning %d\n", ret); - return ret; -} - - diff --git a/nuttx/lib/pthread/pthread_attrinit.c b/nuttx/lib/pthread/pthread_attrinit.c deleted file mode 100644 index d06a535d7..000000000 --- a/nuttx/lib/pthread/pthread_attrinit.c +++ /dev/null @@ -1,123 +0,0 @@ -/**************************************************************************** - * lib/pthread/pthread_attrinit.c - * - * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include -#include -#include - -#include - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/* Default pthread attributes (see included/nuttx/pthread.h). When configured - * to build separate kernel- and user-address spaces, this global is - * duplicated in each address spaced. This copy can only be shared within - * the user address space. - */ - -#if defined(CONFIG_NUTTX_KERNEL) && !defined(__KERNEL__) -pthread_attr_t g_default_pthread_attr = PTHREAD_ATTR_INITIALIZER; -#endif - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Function: pthread_attr_init - * - * Description: - * Initializes a thread attributes object (attr) with - * default values for all of the individual attributes - * used by a given implementation. - * - * Parameters: - * attr - * - * Return Value: - * 0 on success, otherwise an error number - * - * Assumptions: - * - ****************************************************************************/ - -int pthread_attr_init(FAR pthread_attr_t *attr) -{ - int ret = OK; - - sdbg("attr=0x%p\n", attr); - if (!attr) - { - ret = ENOMEM; - } - else - { - /* Set the child thread priority to be the default - * priority. Set the child stack size to some arbitrary - * default value. - */ - - memcpy(attr, &g_default_pthread_attr, sizeof(pthread_attr_t)); - } - - sdbg("Returning %d\n", ret); - return ret; -} - diff --git a/nuttx/lib/pthread/pthread_attrsetinheritsched.c b/nuttx/lib/pthread/pthread_attrsetinheritsched.c deleted file mode 100644 index df2c2fba3..000000000 --- a/nuttx/lib/pthread/pthread_attrsetinheritsched.c +++ /dev/null @@ -1,113 +0,0 @@ -/**************************************************************************** - * lib/pthread/pthread_attrsetinheritsched.c - * - * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include -#include -#include -#include - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Function: pthread_attr_setinheritsched - * - * Description: - * Indicate whether the scheduling info in the pthread - * attributes will be used or if the thread will - * inherit the properties of the parent. - * - * Parameters: - * attr - * policy - * - * Return Value: - * 0 if successful. Otherwise, an error code. - * - * Assumptions: - * - ****************************************************************************/ - -int pthread_attr_setinheritsched(FAR pthread_attr_t *attr, - int inheritsched) -{ - int ret; - - sdbg("inheritsched=%d\n", inheritsched); - - if (!attr || - (inheritsched != PTHREAD_INHERIT_SCHED && - inheritsched != PTHREAD_EXPLICIT_SCHED)) - { - ret = EINVAL; - } - else - { - attr->inheritsched = (uint8_t)inheritsched; - ret = OK; - } - - sdbg("Returning %d\n", ret); - return ret; -} - diff --git a/nuttx/lib/pthread/pthread_attrsetschedparam.c b/nuttx/lib/pthread/pthread_attrsetschedparam.c deleted file mode 100644 index c2ab4d1c4..000000000 --- a/nuttx/lib/pthread/pthread_attrsetschedparam.c +++ /dev/null @@ -1,108 +0,0 @@ -/**************************************************************************** - * lib/pthread/pthread_attrsetschedparam.c - * - * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include -#include -#include -#include - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Function: pthread_attr_setschedparam - * - * Description: - * - * Parameters: - * attr - * param - * - * Return Value: - * 0 if successful. Otherwise, an error code. - * - * Assumptions: - * - ****************************************************************************/ - -int pthread_attr_setschedparam(FAR pthread_attr_t *attr, - FAR const struct sched_param *param) -{ - int ret; - - sdbg("attr=0x%p param=0x%p\n", attr, param); - - if (!attr || !param) - { - ret = EINVAL; - } - else - { - attr->priority = (short)param->sched_priority; - ret = OK; - } - sdbg("Returning %d\n", ret); - return ret; -} - - diff --git a/nuttx/lib/pthread/pthread_attrsetschedpolicy.c b/nuttx/lib/pthread/pthread_attrsetschedpolicy.c deleted file mode 100644 index 4e43e635d..000000000 --- a/nuttx/lib/pthread/pthread_attrsetschedpolicy.c +++ /dev/null @@ -1,111 +0,0 @@ -/**************************************************************************** - * lib/pthread/pthread_attrsetschedpolicy.c - * - * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include -#include -#include -#include - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Function: pthread_attr_setschedpolicy - * - * Description: - * Set the scheduling algorithm attribute. - * - * Parameters: - * attr - * policy - * - * Return Value: - * 0 if successful. Otherwise, an error code. - * - * Assumptions: - * - ****************************************************************************/ - -int pthread_attr_setschedpolicy(FAR pthread_attr_t *attr, int policy) -{ - int ret; - - sdbg("attr=0x%p policy=%d\n", attr, policy); - -#if CONFIG_RR_INTERVAL > 0 - if (!attr || (policy != SCHED_FIFO && policy != SCHED_RR)) -#else - if (!attr || policy != SCHED_FIFO ) -#endif - { - ret = EINVAL; - } - else - { - attr->policy = policy; - ret = OK; - } - - sdbg("Returning %d\n", ret); - return ret; -} diff --git a/nuttx/lib/pthread/pthread_attrsetstacksize.c b/nuttx/lib/pthread/pthread_attrsetstacksize.c deleted file mode 100644 index 8a826dd3a..000000000 --- a/nuttx/lib/pthread/pthread_attrsetstacksize.c +++ /dev/null @@ -1,106 +0,0 @@ -/**************************************************************************** - * lib/pthread/pthread_attrsetstacksize.c - * - * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include -#include -#include - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Function: pthread_attr_setstacksize - * - * Description: - * - * Parameters: - * attr - * stacksize - * - * Return Value: - * 0 if successful. Otherwise, an error code. - * - * Assumptions: - * - ****************************************************************************/ - -int pthread_attr_setstacksize(FAR pthread_attr_t *attr, long stacksize) -{ - int ret; - - sdbg("attr=0x%p stacksize=%ld\n", attr, stacksize); - - if (!attr || stacksize < PTHREAD_STACK_MIN) - { - ret = EINVAL; - } - else - { - attr->stacksize = stacksize; - ret = OK; - } - - sdbg("Returning %d\n", ret); - return ret; -} - diff --git a/nuttx/lib/pthread/pthread_barrierattrdestroy.c b/nuttx/lib/pthread/pthread_barrierattrdestroy.c deleted file mode 100644 index 6d16b9cff..000000000 --- a/nuttx/lib/pthread/pthread_barrierattrdestroy.c +++ /dev/null @@ -1,102 +0,0 @@ -/******************************************************************************** - * lib/pthread/pthread_barrierattrdestroy.c - * - * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include -#include - -/******************************************************************************** - * Definitions - ********************************************************************************/ - -/******************************************************************************** - * Private Type Declarations - ********************************************************************************/ - -/******************************************************************************** - * Global Variables - ********************************************************************************/ - -/******************************************************************************** - * Private Variables - ********************************************************************************/ - -/******************************************************************************** - * Private Function Prototypes - ********************************************************************************/ - -/******************************************************************************** - * Public Functions - ********************************************************************************/ - -/******************************************************************************** - * Function: pthread_barrierattr_destroy - * - * Description: - * The pthread_barrierattr_destroy() function will destroy a barrier attributes - * object. A destroyed attr attributes object can be reinitialized using - * pthread_barrierattr_init(); the results of otherwise referencing the object - * after it has been destroyed are undefined. - * - * Parameters: - * attr - barrier attributes to be destroyed. - * - * Return Value: - * 0 (OK) on success or EINVAL if attr is invalid. - * - * Assumptions: - * - ********************************************************************************/ - -int pthread_barrierattr_destroy(FAR pthread_barrierattr_t *attr) -{ - int ret = OK; - - if (!attr) - { - ret = EINVAL; - } - else - { - attr->pshared = PTHREAD_PROCESS_PRIVATE; - } - return ret; -} diff --git a/nuttx/lib/pthread/pthread_barrierattrgetpshared.c b/nuttx/lib/pthread/pthread_barrierattrgetpshared.c deleted file mode 100644 index d29bc6dfc..000000000 --- a/nuttx/lib/pthread/pthread_barrierattrgetpshared.c +++ /dev/null @@ -1,101 +0,0 @@ -/******************************************************************************** - * lib/pthread/pthread_barrierattrgetpshared.c - * - * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include -#include - -/******************************************************************************** - * Definitions - ********************************************************************************/ - -/******************************************************************************** - * Private Type Declarations - ********************************************************************************/ - -/******************************************************************************** - * Global Variables - ********************************************************************************/ - -/******************************************************************************** - * Private Variables - ********************************************************************************/ - -/******************************************************************************** - * Private Function Prototypes - ********************************************************************************/ - -/******************************************************************************** - * Public Functions - ********************************************************************************/ - -/******************************************************************************** - * Function: pthread_barrierattr_getpshared - * - * Description: - * The pthread_barrierattr_getpshared() function will obtain the value of the - * process-shared attribute from the attributes object referenced by attr. - * - * Parameters: - * attr - barrier attributes to be queried. - * pshared - the location to stored the current value of the pshared attribute. - * - * Return Value: - * 0 (OK) on success or EINVAL if either attr or pshared is invalid. - * - * Assumptions: - * - ********************************************************************************/ - -int pthread_barrierattr_getpshared(FAR const pthread_barrierattr_t *attr, FAR int *pshared) -{ - int ret = OK; - - if (!attr || !pshared) - { - ret = EINVAL; - } - else - { - *pshared = attr->pshared; - } - return ret; -} diff --git a/nuttx/lib/pthread/pthread_barrierattrinit.c b/nuttx/lib/pthread/pthread_barrierattrinit.c deleted file mode 100644 index b5f35ca91..000000000 --- a/nuttx/lib/pthread/pthread_barrierattrinit.c +++ /dev/null @@ -1,101 +0,0 @@ -/******************************************************************************** - * lib/pthread/pthread_barrierattrinit.c - * - * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include -#include - -/******************************************************************************** - * Definitions - ********************************************************************************/ - -/******************************************************************************** - * Private Type Declarations - ********************************************************************************/ - -/******************************************************************************** - * Global Variables - ********************************************************************************/ - -/******************************************************************************** - * Private Variables - ********************************************************************************/ - -/******************************************************************************** - * Private Function Prototypes - ********************************************************************************/ - -/******************************************************************************** - * Public Functions - ********************************************************************************/ - -/******************************************************************************** - * Function: pthread_barrierattr_init - * - * Description: - * The pthread_barrierattr_init() function will initialize a barrier attribute - * object attr with the default value for all of the attributes defined by the - * implementation. - * - * Parameters: - * attr - barrier attributes to be initialized. - * - * Return Value: - * 0 (OK) on success or EINVAL if attr is invalid. - * - * Assumptions: - * - ********************************************************************************/ - -int pthread_barrierattr_init(FAR pthread_barrierattr_t *attr) -{ - int ret = OK; - - if (!attr) - { - ret = EINVAL; - } - else - { - attr->pshared = PTHREAD_PROCESS_PRIVATE; - } - return ret; -} diff --git a/nuttx/lib/pthread/pthread_barrierattrsetpshared.c b/nuttx/lib/pthread/pthread_barrierattrsetpshared.c deleted file mode 100644 index d0eecbf5a..000000000 --- a/nuttx/lib/pthread/pthread_barrierattrsetpshared.c +++ /dev/null @@ -1,111 +0,0 @@ -/******************************************************************************** - * lib/pthread/pthread_barrierattrsetpshared.c - * - * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include -#include - -/******************************************************************************** - * Definitions - ********************************************************************************/ - -/******************************************************************************** - * Private Type Declarations - ********************************************************************************/ - -/******************************************************************************** - * Global Variables - ********************************************************************************/ - -/******************************************************************************** - * Private Variables - ********************************************************************************/ - -/******************************************************************************** - * Private Function Prototypes - ********************************************************************************/ - -/******************************************************************************** - * Public Functions - ********************************************************************************/ - -/******************************************************************************** - * Function: pthread_barrierattr_setpshared - * - * Description: - * The process-shared attribute is set to PTHREAD_PROCESS_SHARED to permit a - * barrier to be operated upon by any thread that has access to the memory where - * the barrier is allocated. If the process-shared attribute is - * PTHREAD_PROCESS_PRIVATE, the barrier can only be operated upon by threads - * created within the same process as the thread that initialized the barrier. - * If threads of different processes attempt to operate on such a barrier, the - * behavior is undefined. The default value of the attribute is - * PTHREAD_PROCESS_PRIVATE. - * - * Both constants PTHREAD_PROCESS_SHARED and PTHREAD_PROCESS_PRIVATE are defined - * in pthread.h. - * - * Parameters: - * attr - barrier attributes to be modified. - * pshared - the new value of the pshared attribute. - * - * Return Value: - * 0 (OK) on success or EINVAL if either attr is invalid or pshared is not one - * of PTHREAD_PROCESS_SHARED or PTHREAD_PROCESS_PRIVATE. - * - * Assumptions: - * - ********************************************************************************/ - -int pthread_barrierattr_setpshared(FAR pthread_barrierattr_t *attr, int pshared) -{ - int ret = OK; - - if (!attr || (pshared != PTHREAD_PROCESS_SHARED && pshared != PTHREAD_PROCESS_PRIVATE)) - { - ret = EINVAL; - } - else - { - attr->pshared = pshared; - } - return ret; -} diff --git a/nuttx/lib/pthread/pthread_condattrdestroy.c b/nuttx/lib/pthread/pthread_condattrdestroy.c deleted file mode 100644 index d6c3df5d1..000000000 --- a/nuttx/lib/pthread/pthread_condattrdestroy.c +++ /dev/null @@ -1,82 +0,0 @@ -/**************************************************************************** - * lib/pthread/pthread_condattrdestroy.c - * - * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include -#include - -/**************************************************************************** - * Global Functions - ****************************************************************************/ - -/**************************************************************************** - * Function: pthread_condattr_destroy - * - * Description: - * Operations on condition variable attributes - * - * Parameters: - * None - * - * Return Value: - * None - * - * Assumptions: - * - ****************************************************************************/ - -int pthread_condattr_destroy(FAR pthread_condattr_t *attr) -{ - int ret = OK; - - sdbg("attr=0x%p\n", attr); - - if (!attr) - { - ret = EINVAL; - } - - sdbg("Returning %d\n", ret); - return ret; -} - - - diff --git a/nuttx/lib/pthread/pthread_condattrinit.c b/nuttx/lib/pthread/pthread_condattrinit.c deleted file mode 100644 index 5721c6159..000000000 --- a/nuttx/lib/pthread/pthread_condattrinit.c +++ /dev/null @@ -1,85 +0,0 @@ -/**************************************************************************** - * lib/pthread/pthread_condattrinit.c - * - * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include -#include - -/**************************************************************************** - * Global Functions - ****************************************************************************/ - -/**************************************************************************** - * Function: pthread_condattr_init - * - * Description: - * Operations on condition variable attributes - * - * Parameters: - * None - * - * Return Value: - * None - * - * Assumptions: - * - ****************************************************************************/ - -int pthread_condattr_init(FAR pthread_condattr_t *attr) -{ - int ret = OK; - - sdbg("attr=0x%p\n", attr); - - if (!attr) - { - ret = EINVAL; - } - else - { - *attr = 0; - } - - sdbg("Returning %d\n", ret); - return ret; -} - - diff --git a/nuttx/lib/pthread/pthread_mutexattrdestroy.c b/nuttx/lib/pthread/pthread_mutexattrdestroy.c deleted file mode 100644 index e9868df68..000000000 --- a/nuttx/lib/pthread/pthread_mutexattrdestroy.c +++ /dev/null @@ -1,104 +0,0 @@ -/**************************************************************************** - * lib/pthread/pthread_mutexattrdestroy.c - * - * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include -#include - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Function: pthread_mutexattr_destroy - * - * Description: - * Destroy mutex attributes. - * - * Parameters: - * attr - * pshared - * - * Return Value: - * 0 if successful. Otherwise, an error code. - * - * Assumptions: - * - ****************************************************************************/ - -int pthread_mutexattr_destroy(FAR pthread_mutexattr_t *attr) -{ - int ret = OK; - - sdbg("attr=0x%p\n", attr); - - if (!attr) - { - ret = EINVAL; - } - else - { - attr->pshared = 0; - } - - sdbg("Returning %d\n", ret); - return ret; -} diff --git a/nuttx/lib/pthread/pthread_mutexattrgetpshared.c b/nuttx/lib/pthread/pthread_mutexattrgetpshared.c deleted file mode 100644 index bc6379db5..000000000 --- a/nuttx/lib/pthread/pthread_mutexattrgetpshared.c +++ /dev/null @@ -1,104 +0,0 @@ -/**************************************************************************** - * lib/pthread/pthread_mutexattrgetpshared.c - * - * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include -#include - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Function: pthread_mutexattr_getpshared - * - * Description: - * Get pshared mutex attribute. - * - * Parameters: - * attr - * pshared - * - * Return Value: - * 0 if successful. Otherwise, an error code. - * - * Assumptions: - * - ****************************************************************************/ - -int pthread_mutexattr_getpshared(FAR pthread_mutexattr_t *attr, FAR int *pshared) -{ - int ret = OK; - - sdbg("attr=0x%p pshared=0x%p\n", attr, pshared); - - if (!attr || !pshared) - { - ret = EINVAL; - } - else - { - *pshared = attr->pshared; - } - - sdbg("Returning %d\n", ret); - return ret; -} diff --git a/nuttx/lib/pthread/pthread_mutexattrgettype.c b/nuttx/lib/pthread/pthread_mutexattrgettype.c deleted file mode 100644 index 5fb10f301..000000000 --- a/nuttx/lib/pthread/pthread_mutexattrgettype.c +++ /dev/null @@ -1,98 +0,0 @@ -/**************************************************************************** - * lib/pthread/pthread_mutexattrgettype.c - * - * Copyright (C) 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 -#include -#include - -#ifdef CONFIG_MUTEX_TYPES - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Function: pthread_mutexattr_gettype - * - * Description: - * Return the mutex type from the mutex attributes. - * - * Parameters: - * attr - The mutex attributes to query - * type - Location to return the mutex type - * - * Return Value: - * 0, if the mutex type was successfully return in 'type', or - * EINVAL, if any NULL pointers provided. - * - * Assumptions: - * - ****************************************************************************/ - -int pthread_mutexattr_gettype(const pthread_mutexattr_t *attr, int *type) -{ - if (attr && type) - { - *type = attr->type; - return 0; - } - return EINVAL; -} - -#endif /* CONFIG_MUTEX_TYPES */ diff --git a/nuttx/lib/pthread/pthread_mutexattrinit.c b/nuttx/lib/pthread/pthread_mutexattrinit.c deleted file mode 100644 index f815bf16c..000000000 --- a/nuttx/lib/pthread/pthread_mutexattrinit.c +++ /dev/null @@ -1,106 +0,0 @@ -/**************************************************************************** - * lib/pthread/pthread_mutexattrinit.c - * - * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include -#include - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Function: pthread_mutexattr_init - * - * Description: - * Create mutex attributes. - * - * Parameters: - * attr - * - * Return Value: - * 0 if successful. Otherwise, an error code. - * - * Assumptions: - * - ****************************************************************************/ - -int pthread_mutexattr_init(FAR pthread_mutexattr_t *attr) -{ - int ret = OK; - - sdbg("attr=0x%p\n", attr); - - if (!attr) - { - ret = EINVAL; - } - else - { - attr->pshared = 0; -#ifdef CONFIG_MUTEX_TYPES - attr->type = PTHREAD_MUTEX_DEFAULT; -#endif - } - - sdbg("Returning %d\n", ret); - return ret; -} diff --git a/nuttx/lib/pthread/pthread_mutexattrsetpshared.c b/nuttx/lib/pthread/pthread_mutexattrsetpshared.c deleted file mode 100644 index 900476fdd..000000000 --- a/nuttx/lib/pthread/pthread_mutexattrsetpshared.c +++ /dev/null @@ -1,104 +0,0 @@ -/**************************************************************************** - * lib/pthread/pthread_mutexattrsetpshared.c - * - * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include -#include - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Function: pthread_mutexattr_setpshared - * - * Description: - * Set pshared mutex attribute. - * - * Parameters: - * attr - * pshared - * - * Return Value: - * 0 if successful. Otherwise, an error code. - * - * Assumptions: - * - ****************************************************************************/ - -int pthread_mutexattr_setpshared(FAR pthread_mutexattr_t *attr, int pshared) -{ - int ret = OK; - - sdbg("attr=0x%p pshared=%d\n", attr, pshared); - - if (!attr || (pshared != 0 && pshared != 1)) - { - ret = EINVAL; - } - else - { - attr->pshared = pshared; - } - - sdbg("Returning %d\n", ret); - return ret; -} diff --git a/nuttx/lib/pthread/pthread_mutexattrsettype.c b/nuttx/lib/pthread/pthread_mutexattrsettype.c deleted file mode 100644 index 81427c757..000000000 --- a/nuttx/lib/pthread/pthread_mutexattrsettype.c +++ /dev/null @@ -1,98 +0,0 @@ -/**************************************************************************** - * lib/pthread/pthread_mutexattrsettype.c - * - * Copyright (C) 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 -#include -#include - -#ifdef CONFIG_MUTEX_TYPES - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Function: pthread_mutexattr_settype - * - * Description: - * Set the mutex type in the mutex attributes. - * - * Parameters: - * attr - The mutex attributes in which to set the mutex type. - * type - The mutex type value to set. - * - * Return Value: - * 0, if the mutex type was successfully set in 'attr', or - * EINVAL, if 'attr' is NULL or 'type' unrecognized. - * - * Assumptions: - * - ****************************************************************************/ - -int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type) -{ - if (attr && type >= PTHREAD_MUTEX_NORMAL && type <= PTHREAD_MUTEX_RECURSIVE) - { - attr->type = type; - return OK; - } - return EINVAL; -} - -#endif /* CONFIG_MUTEX_TYPES */ diff --git a/nuttx/lib/queue/Make.defs b/nuttx/lib/queue/Make.defs deleted file mode 100644 index 976e7a2b8..000000000 --- a/nuttx/lib/queue/Make.defs +++ /dev/null @@ -1,47 +0,0 @@ -############################################################################ -# lib/queue/Make.defs -# -# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt -# -# 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. -# -############################################################################ - -# Add the queue C files to the build - -CSRCS += sq_addlast.c sq_addfirst.c sq_addafter.c \ - sq_rem.c sq_remlast.c sq_remfirst.c sq_remafter.c - -CSRCS += dq_addlast.c dq_addfirst.c dq_addafter.c dq_addbefore.c \ - dq_rem.c dq_remlast.c dq_remfirst.c - -# Add the queue directory to the build - -DEPPATH += --dep-path queue -VPATH += :queue diff --git a/nuttx/lib/queue/dq_addafter.c b/nuttx/lib/queue/dq_addafter.c deleted file mode 100644 index bfbe0052d..000000000 --- a/nuttx/lib/queue/dq_addafter.c +++ /dev/null @@ -1,74 +0,0 @@ -/************************************************************ - * lib/queue/dq_addafter.c - * - * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ************************************************************/ - -/************************************************************ - * Compilation Switches - ************************************************************/ - -/************************************************************ - * Included Files - ************************************************************/ - -#include - -/************************************************************ - * Public Functions - ************************************************************/ - -/************************************************************ - * Name: dq_addafter - * - * Description: - * dq_addafter function adds 'node' after 'qqqq' in the - * 'queue.' - * - ************************************************************/ - -void dq_addafter(FAR dq_entry_t *prev, FAR dq_entry_t *node, - dq_queue_t *queue) -{ - if (!queue->head || prev == queue->tail) - { - dq_addlast(node, queue); - } - else - { - FAR dq_entry_t *next = prev->flink; - node->blink = prev; - node->flink = next; - next->blink = node; - prev->flink = node; - } -} diff --git a/nuttx/lib/queue/dq_addbefore.c b/nuttx/lib/queue/dq_addbefore.c deleted file mode 100644 index d740ea830..000000000 --- a/nuttx/lib/queue/dq_addbefore.c +++ /dev/null @@ -1,69 +0,0 @@ -/**************************************************************************** - * lib/queue/dq_addbefore.c - * - * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: dq_addbefore - * - * Description: - * dq_addbefore adds 'node' before 'next' in 'queue' - * - ****************************************************************************/ - -void dq_addbefore(FAR dq_entry_t *next, FAR dq_entry_t *node, - dq_queue_t *queue) -{ - if (!queue->head || next == queue->head) - { - dq_addfirst(node, queue); - } - else - { - FAR dq_entry_t *prev = next->blink; - node->flink = next; - node->blink = prev; - prev->flink = node; - next->blink = node; - } -} diff --git a/nuttx/lib/queue/dq_addfirst.c b/nuttx/lib/queue/dq_addfirst.c deleted file mode 100644 index 7c7312de3..000000000 --- a/nuttx/lib/queue/dq_addfirst.c +++ /dev/null @@ -1,74 +0,0 @@ -/************************************************************ - * lib/queue/dq_addfirst.c - * - * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ************************************************************/ - -/************************************************************ - * Compilation Switches - ************************************************************/ - -/************************************************************ - * Included Files - ************************************************************/ - -#include - -/************************************************************ - * Public Functions - ************************************************************/ - -/************************************************************ - * Name: dq_addfirst - * - * Description: - * dq_addfirst affs 'node' at the beginning of 'queue' - * - ************************************************************/ - -void dq_addfirst(FAR dq_entry_t *node, dq_queue_t *queue) -{ - node->blink = NULL; - node->flink = queue->head; - - if (!queue->head) - { - queue->head = node; - queue->tail = node; - } - else - { - queue->head->blink = node; - queue->head = node; - } -} - diff --git a/nuttx/lib/queue/dq_addlast.c b/nuttx/lib/queue/dq_addlast.c deleted file mode 100644 index 745deb27d..000000000 --- a/nuttx/lib/queue/dq_addlast.c +++ /dev/null @@ -1,74 +0,0 @@ -/************************************************************ - * lib/queue/dq_addlast.c - * - * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ************************************************************/ - -/************************************************************ - * Compilation Switches - ************************************************************/ - -/************************************************************ - * Included Files - ************************************************************/ - -#include - -/************************************************************ - * Public Functions - ************************************************************/ - -/************************************************************ - * Name: dq_addlast - * - * Description - * dq_addlast adds 'node' to the end of 'queue' - * - ************************************************************/ - -void dq_addlast(FAR dq_entry_t *node, dq_queue_t *queue) -{ - node->flink = NULL; - node->blink = queue->tail; - - if (!queue->head) - { - queue->head = node; - queue->tail = node; - } - else - { - queue->tail->flink = node; - queue->tail = node; - } -} - diff --git a/nuttx/lib/queue/dq_rem.c b/nuttx/lib/queue/dq_rem.c deleted file mode 100644 index 218427bf8..000000000 --- a/nuttx/lib/queue/dq_rem.c +++ /dev/null @@ -1,84 +0,0 @@ -/************************************************************ - * lib/queue/dq_rem.c - * - * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ************************************************************/ - -/************************************************************ - * Compilation Switches - ************************************************************/ - -/************************************************************ - * Included Files - ************************************************************/ - -#include - -/************************************************************ - * Public Functions - ************************************************************/ - -/************************************************************ - * Name: dq_rem - * - * Descripton: - * dq_rem removes 'node' from 'queue' - * - ************************************************************/ - -void dq_rem(FAR dq_entry_t *node, dq_queue_t *queue) -{ - FAR dq_entry_t *prev = node->blink; - FAR dq_entry_t *next = node->flink; - - if (!prev) - { - queue->head = next; - } - else - { - prev->flink = next; - } - - if (!next) - { - queue->tail = prev; - } - else - { - next->blink = prev; - } - - node->flink = NULL; - node->blink = NULL; -} - diff --git a/nuttx/lib/queue/dq_remfirst.c b/nuttx/lib/queue/dq_remfirst.c deleted file mode 100644 index 26c5fd7a6..000000000 --- a/nuttx/lib/queue/dq_remfirst.c +++ /dev/null @@ -1,82 +0,0 @@ -/************************************************************ - * lib/queue/dq_remfirst.c - * - * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ************************************************************/ - -/************************************************************ - * Compilation Switches - ************************************************************/ - -/************************************************************ - * Included Files - ************************************************************/ - -#include - -/************************************************************ - * Public Functions - ************************************************************/ - -/************************************************************ - * Name: dq_remfirst - * - * Description: - * dq_remfirst removes 'node' from the head of 'queue' - * - ************************************************************/ - -FAR dq_entry_t *dq_remfirst(dq_queue_t *queue) -{ - FAR dq_entry_t *ret = queue->head; - - if (ret) - { - FAR dq_entry_t *next = ret->flink; - if (!next) - { - queue->head = NULL; - queue->tail = NULL; - } - else - { - queue->head = next; - next->blink = NULL; - } - - ret->flink = NULL; - ret->blink = NULL; - } - - return ret; -} - diff --git a/nuttx/lib/queue/dq_remlast.c b/nuttx/lib/queue/dq_remlast.c deleted file mode 100644 index 35adc73e2..000000000 --- a/nuttx/lib/queue/dq_remlast.c +++ /dev/null @@ -1,78 +0,0 @@ -/**************************************************************************** - * lib/queue/dq_remlast.c - * - * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/***************************************************(************************ - * Name: dq_remlast - * - * Description: - * dq_remlast removes the last entry from 'queue' - * - ****************************************************************************/ - -FAR dq_entry_t *dq_remlast(dq_queue_t *queue) -{ - FAR dq_entry_t *ret = queue->tail; - - if (ret) - { - FAR dq_entry_t *prev = ret->blink; - if (!prev) - { - queue->head = NULL; - queue->tail = NULL; - } - else - { - queue->tail = prev; - prev->flink = NULL; - } - - ret->flink = NULL; - ret->blink = NULL; - } - - return ret; -} - diff --git a/nuttx/lib/queue/sq_addafter.c b/nuttx/lib/queue/sq_addafter.c deleted file mode 100644 index 965ac2844..000000000 --- a/nuttx/lib/queue/sq_addafter.c +++ /dev/null @@ -1,71 +0,0 @@ -/************************************************************ - * lib/queue/sq_addafter.c - * - * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ************************************************************/ - -/************************************************************ - * Compilation Switches - ************************************************************/ - -/************************************************************ - * Included Files - ************************************************************/ - -#include - -/************************************************************ - * Public Functions - ************************************************************/ - -/************************************************************ - * Name: sq_addafter.c - * - * Description: - * The sq_addafter function adds 'node' after 'prev' in the - * 'queue.' - * - ************************************************************/ - -void sq_addafter(FAR sq_entry_t *prev, FAR sq_entry_t *node, - sq_queue_t *queue) -{ - if (!queue->head || prev == queue->tail) - { - sq_addlast(node, queue); - } - else - { - node->flink = prev->flink; - prev->flink = node; - } -} diff --git a/nuttx/lib/queue/sq_addfirst.c b/nuttx/lib/queue/sq_addfirst.c deleted file mode 100644 index 8fc8e0619..000000000 --- a/nuttx/lib/queue/sq_addfirst.c +++ /dev/null @@ -1,67 +0,0 @@ -/************************************************************ - * lib/queue/sq_addfirst.c - * - * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ************************************************************/ - -/************************************************************ - * Compilation Switches - ************************************************************/ - -/************************************************************ - * Included Files - ************************************************************/ - -#include - -/************************************************************ - * Public Functions - ************************************************************/ - -/************************************************************ - * Name: sq_addfirst - * - * Description: - * The sq_addfirst function places the 'node' at the head - * of the 'queue' - * - ************************************************************/ - -void sq_addfirst(FAR sq_entry_t *node, sq_queue_t *queue) -{ - node->flink = queue->head; - if (!queue->head) - { - queue->tail = node; - } - queue->head = node; -} diff --git a/nuttx/lib/queue/sq_addlast.c b/nuttx/lib/queue/sq_addlast.c deleted file mode 100644 index f9f9625cc..000000000 --- a/nuttx/lib/queue/sq_addlast.c +++ /dev/null @@ -1,72 +0,0 @@ -/************************************************************ - * lib/queue/sq_addlast.c - * - * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ************************************************************/ - -/************************************************************ - * Compilation Switches - ************************************************************/ - -/************************************************************ - * Included Files - ************************************************************/ - -#include - -/************************************************************ - * Public Functions - ************************************************************/ - -/************************************************************ - * Name: sq_addlast - * - * Description: - * The sq_addlast function places the 'node' at the tail of - * the 'queue' - ************************************************************/ - -void sq_addlast(FAR sq_entry_t *node, sq_queue_t *queue) -{ - node->flink = NULL; - if (!queue->head) - { - queue->head = node; - queue->tail = node; - } - else - { - queue->tail->flink = node; - queue->tail = node; - } -} - diff --git a/nuttx/lib/queue/sq_rem.c b/nuttx/lib/queue/sq_rem.c deleted file mode 100644 index 6ba52354d..000000000 --- a/nuttx/lib/queue/sq_rem.c +++ /dev/null @@ -1,83 +0,0 @@ -/************************************************************ - * lib/queue/sq_rem.c - * - * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ************************************************************/ - -/************************************************************ - * Compilation Switches - ************************************************************/ - -/************************************************************ - * Included Files - ************************************************************/ - -#include - -/************************************************************ - * public Functions - ************************************************************/ - -/************************************************************ - * Name: sq_rem - * - * Description: - * sq_rem removes a 'node' for 'queue.' - * - ************************************************************/ - -void sq_rem(FAR sq_entry_t *node, sq_queue_t *queue) -{ - if (queue->head && node) - { - if (node == queue->head) - { - queue->head = node->flink; - if (node == queue->tail) - { - queue->tail = NULL; - } - } - else - { - FAR sq_entry_t *prev; - for(prev = (FAR sq_entry_t*)queue->head; - prev && prev->flink != node; - prev = prev->flink); - - if (prev) - { - sq_remafter(prev, queue); - } - } - } -} diff --git a/nuttx/lib/queue/sq_remafter.c b/nuttx/lib/queue/sq_remafter.c deleted file mode 100644 index 4dcfb06e4..000000000 --- a/nuttx/lib/queue/sq_remafter.c +++ /dev/null @@ -1,79 +0,0 @@ -/************************************************************ - * lib/queue/sq_remafter.c - * - * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ************************************************************/ - -/************************************************************ - * Compilation Switches - ************************************************************/ - -/************************************************************ - * Included Files - ************************************************************/ - -#include - -/************************************************************ - * Public Functions - ************************************************************/ - -/************************************************************ - * Name: - * - * Description: - * sq_remafter removes the entry following 'node; from the - * 'queue' Returns a reference to the removed entry. - * - ************************************************************/ - -FAR sq_entry_t *sq_remafter(FAR sq_entry_t *node, sq_queue_t *queue) -{ - FAR sq_entry_t *ret = node->flink; - if (queue->head && ret) - { - if (queue->tail == ret) - { - queue->tail = node; - node->flink = NULL; - } - else - { - node->flink = ret->flink; - } - - ret->flink = NULL; - } - - return ret; -} - diff --git a/nuttx/lib/queue/sq_remfirst.c b/nuttx/lib/queue/sq_remfirst.c deleted file mode 100644 index 43df6de41..000000000 --- a/nuttx/lib/queue/sq_remfirst.c +++ /dev/null @@ -1,76 +0,0 @@ -/************************************************************ - * lib/queue/sq_remfirst.c - * - * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ************************************************************/ - -/************************************************************ - * Compilation Switches - ************************************************************/ - -/************************************************************ - * Included Files - ************************************************************/ - -#include - -/************************************************************ - * Public Functions - ************************************************************/ - -/************************************************************ - * Name: sq_remfirst - * - * Description: - * sq_remfirst function removes the first entry from - * 'queue' - * - ************************************************************/ - -FAR sq_entry_t *sq_remfirst(sq_queue_t *queue) -{ - FAR sq_entry_t *ret = queue->head; - - if (ret) - { - queue->head = ret->flink; - if (!queue->head) - { - queue->tail = NULL; - } - - ret->flink = NULL; - } - - return ret; -} - diff --git a/nuttx/lib/queue/sq_remlast.c b/nuttx/lib/queue/sq_remlast.c deleted file mode 100644 index 92cdbde98..000000000 --- a/nuttx/lib/queue/sq_remlast.c +++ /dev/null @@ -1,87 +0,0 @@ -/************************************************************ - * lib/queue/sq_remlast.c - * - * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ************************************************************/ - -/************************************************************ - * Compilation Switches - ************************************************************/ - -/************************************************************ - * Included Files - ************************************************************/ - -#include - -/************************************************************ - * Public Functions - ************************************************************/ - -/************************************************************ - * Name: sq_remlast - * - * Description: - * Removes the last entry in a singly-linked queue. - * - ************************************************************/ - -FAR sq_entry_t *sq_remlast(sq_queue_t *queue) -{ - FAR sq_entry_t *ret = queue->tail; - - if (ret) - { - if (queue->head == queue->tail) - { - queue->head = NULL; - queue->tail = NULL; - } - else - { - FAR sq_entry_t *prev; - for(prev = queue->head; - prev && prev->flink != ret; - prev = prev->flink); - - if (prev) - { - prev->flink = NULL; - queue->tail = prev; - } - } - - ret->flink = NULL; - } - - return ret; -} diff --git a/nuttx/lib/sched/Make.defs b/nuttx/lib/sched/Make.defs deleted file mode 100644 index f398b755e..000000000 --- a/nuttx/lib/sched/Make.defs +++ /dev/null @@ -1,43 +0,0 @@ -############################################################################ -# lib/sched/Make.defs -# -# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt -# -# 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. -# -############################################################################ - -# Add the sched C files to the build - -CSRCS += sched_getprioritymax.c sched_getprioritymin.c - -# Add the sched directory to the build - -DEPPATH += --dep-path sched -VPATH += :sched diff --git a/nuttx/lib/sched/sched_getprioritymax.c b/nuttx/lib/sched/sched_getprioritymax.c deleted file mode 100644 index 14b368dfc..000000000 --- a/nuttx/lib/sched/sched_getprioritymax.c +++ /dev/null @@ -1,100 +0,0 @@ -/************************************************************************ - * lib/sched/sched_getprioritymax.c - * - * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include - -/************************************************************************ - * Definitions - ************************************************************************/ - -/************************************************************************ - * Private Type Declarations - ************************************************************************/ - -/************************************************************************ - * Global Variables - ************************************************************************/ - -/************************************************************************ - * Private Variables - ************************************************************************/ - -/************************************************************************ - * Private Function Prototypes - ************************************************************************/ - -/************************************************************************ - * Private Functions - ************************************************************************/ - -/************************************************************************ - * Public Functions - ************************************************************************/ - -/************************************************************************ - * Name: ched_get_priority_max - * - * Description: - * This function returns the value of the highest possible - * task priority for a specified scheduling policy. - * - * Inputs: - * policy - Scheduling policy requested. - * - * Return Value: - * The maximum priority value or -1 (ERROR) - * (errno is not set) - * - * Assumptions: - * - ************************************************************************/ - -int sched_get_priority_max(int policy) -{ - if (policy != SCHED_FIFO && policy != SCHED_RR) - { - return ERROR; - } - else - { - return SCHED_PRIORITY_MAX; - } -} diff --git a/nuttx/lib/sched/sched_getprioritymin.c b/nuttx/lib/sched/sched_getprioritymin.c deleted file mode 100644 index 86410cb0f..000000000 --- a/nuttx/lib/sched/sched_getprioritymin.c +++ /dev/null @@ -1,100 +0,0 @@ -/************************************************************************ - * lib/sched/sched_getprioritymin.c - * - * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include - -/************************************************************************ - * Definitions - ************************************************************************/ - -/************************************************************************ - * Private Type Declarations - ************************************************************************/ - -/************************************************************************ - * Global Variables - ************************************************************************/ - -/************************************************************************ - * Private Variables - ************************************************************************/ - -/************************************************************************ - * Private Function Prototypes - ************************************************************************/ - -/************************************************************************ - * Private Functions - ************************************************************************/ - -/************************************************************************ - * Public Functions - ************************************************************************/ - -/************************************************************************ - * Name: sched_get_priority_min - * - * Description: - * This function returns the value of the lowest possible - * task priority for a specified scheduling policy. - * - * Inputs: - * policy - Scheduling policy requested. - * - * Return Value: - * The minimum priority value or -1 (ERROR) - * (errno is not set) - * - * Assumptions: - * - ************************************************************************/ - -int sched_get_priority_min(int policy) -{ - if (policy != SCHED_FIFO && policy != SCHED_RR) - { - return ERROR; - } - else - { - return SCHED_PRIORITY_MIN; - } -} diff --git a/nuttx/lib/semaphore/Make.defs b/nuttx/lib/semaphore/Make.defs deleted file mode 100644 index fdc0fe7d5..000000000 --- a/nuttx/lib/semaphore/Make.defs +++ /dev/null @@ -1,43 +0,0 @@ -############################################################################ -# lib/semaphore/Make.defs -# -# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt -# -# 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. -# -############################################################################ - -# Add the semaphore C files to the build - -CSRCS += sem_init.c sem_getvalue.c - -# Add the semaphore directory to the build - -DEPPATH += --dep-path semaphore -VPATH += :semaphore diff --git a/nuttx/lib/semaphore/sem_getvalue.c b/nuttx/lib/semaphore/sem_getvalue.c deleted file mode 100644 index 31c6bb7e0..000000000 --- a/nuttx/lib/semaphore/sem_getvalue.c +++ /dev/null @@ -1,108 +0,0 @@ -/**************************************************************************** - * lib/semaphore/sem_getvalue.c - * - * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include -#include - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Function: sem_getvalue - * - * Description: - * This function updates the location referenced by 'sval' argument to - * have the value of the semaphore referenced by 'sem' without effecting - * the state of the semaphore. The updated value represents the actual - * semaphore value that occurred at some unspecified time during the call, - * but may not reflect the actual value of the semaphore when it is - * returned to the calling task. - * - * If 'sem' is locked, the value return by sem_getvalue() will either be - * zero or a negative number whose absolute value represents the number - * of tasks waiting for the semaphore. - * - * Parameters: - * sem - Semaphore descriptor - * sval - Buffer by which the value is returned - * - * Return Value: - * 0 (OK), or -1 (ERROR) if unsuccessful - * - * Assumptions: - * - ****************************************************************************/ - -int sem_getvalue(FAR sem_t *sem, FAR int *sval) -{ - if (sem && sval) - { - *sval = sem->semcount; - return OK; - } - else - { - set_errno(EINVAL); - return ERROR; - } -} diff --git a/nuttx/lib/semaphore/sem_init.c b/nuttx/lib/semaphore/sem_init.c deleted file mode 100644 index bc14415f9..000000000 --- a/nuttx/lib/semaphore/sem_init.c +++ /dev/null @@ -1,125 +0,0 @@ -/**************************************************************************** - * lib/sem/sem_init.c - * - * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include -#include -#include - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Function: sem_init - * - * Description: - * This function initializes the UNAMED semaphore sem. Following a - * successful call to sem_init(), the semaophore may be used in subsequent - * calls to sem_wait(), sem_post(), and sem_trywait(). The semaphore - * remains usable until it is destroyed. - * - * Only sem itself may be used for performing synchronization. The result - * of referring to copies of sem in calls to sem_wait(), sem_trywait(), - * sem_post(), and sem_destroy() is undefined. - * - * Parameters: - * sem - Semaphore to be initialized - * pshared - Process sharing (not used) - * value - Semaphore initialization value - * - * Return Value: - * 0 (OK), or -1 (ERROR) if unsuccessful. - * - * Assumptions: - * - ****************************************************************************/ - -int sem_init(FAR sem_t *sem, int pshared, unsigned int value) -{ - /* Verify that a semaphore was provided and the count is within the valid - * range. - */ - - if (sem && value <= SEM_VALUE_MAX) - { - /* Initialize the seamphore count */ - - sem->semcount = (int16_t)value; - - /* Initialize to support priority inheritance */ - -#ifdef CONFIG_PRIORITY_INHERITANCE -# if CONFIG_SEM_PREALLOCHOLDERS > 0 - sem->hhead = NULL; -# else - sem->holder.htcb = NULL; - sem->holder.counts = 0; -# endif -#endif - return OK; - } - else - { - set_errno(EINVAL); - return ERROR; - } -} diff --git a/nuttx/lib/signal/Make.defs b/nuttx/lib/signal/Make.defs deleted file mode 100644 index e27da9b2e..000000000 --- a/nuttx/lib/signal/Make.defs +++ /dev/null @@ -1,47 +0,0 @@ -############################################################################ -# lib/signal/Make.defs -# -# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt -# -# 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. -# -############################################################################ - -ifneq ($(CONFIG_DISABLE_SIGNALS),y) - -# Add the signal C files to the build - -CSRCS += sig_emptyset.c sig_fillset.c sig_addset.c sig_delset.c sig_ismember.c - -# Add the signal directory to the build - -DEPPATH += --dep-path signal -VPATH += :signal - -endif diff --git a/nuttx/lib/signal/sig_addset.c b/nuttx/lib/signal/sig_addset.c deleted file mode 100644 index 19ba0cb6b..000000000 --- a/nuttx/lib/signal/sig_addset.c +++ /dev/null @@ -1,100 +0,0 @@ -/**************************************************************************** - * lib/signal/sig_addset.c - * - * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Function: sigaddset - * - * Description: - * This function adds the signal specified by signo to the signal set - * specified by set. - * - * Parameters: - * set - Signal set to add signal to - * signo - Signal to add - * - * Return Value: - * 0 (OK), or -1 (ERROR) if the signal number is invalid. - * - * Assumptions: - * - ****************************************************************************/ - -int sigaddset(FAR sigset_t *set, int signo) -{ - int ret = ERROR; - - /* Verify the signal */ - - if (GOOD_SIGNO(signo)) - { - /* Add the signal to the set */ - - *set |= SIGNO2SET(signo); - ret = OK; - } - - return ret; -} - diff --git a/nuttx/lib/signal/sig_delset.c b/nuttx/lib/signal/sig_delset.c deleted file mode 100644 index 1c661d37f..000000000 --- a/nuttx/lib/signal/sig_delset.c +++ /dev/null @@ -1,100 +0,0 @@ -/**************************************************************************** - * lib/signal/sig_delset.c - * - * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Function: sigdelset - * - * Description: - * This function deletes the signal specified by signo from the signal - * set specified by the 'set' argument. - * - * Parameters: - * set - Signal set to delete the signal from - * signo - Signal to delete - * - * Return Value: - * 0 (OK), or -1 (ERROR) if the signal number is invalid. - * - * Assumptions: - * - ****************************************************************************/ - -int sigdelset(FAR sigset_t *set, int signo) -{ - int ret = ERROR; - - /* Verify the signal */ - - if (GOOD_SIGNO(signo)) - { - /* Delete the signal to the set */ - - *set &= ~SIGNO2SET(signo); - ret = OK; - } - - return ret; -} - diff --git a/nuttx/lib/signal/sig_emptyset.c b/nuttx/lib/signal/sig_emptyset.c deleted file mode 100644 index ac0c6b3e8..000000000 --- a/nuttx/lib/signal/sig_emptyset.c +++ /dev/null @@ -1,88 +0,0 @@ -/**************************************************************************** - * lib/signal/sig_emptyset.c - * - * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Function: sigemptyset - * - * Description: - * This function initializes the signal set specified by set such that all - * signals are excluded. - * - * Parameters: - * set - Signal set to initalize - * - * Return Value: - * 0 (OK), or -1 (ERROR) if the signal set cannot be initialized. - * - * Assumptions: - * - ****************************************************************************/ - -int sigemptyset(FAR sigset_t *set) -{ - *set = NULL_SIGNAL_SET; - return OK; -} - diff --git a/nuttx/lib/signal/sig_fillset.c b/nuttx/lib/signal/sig_fillset.c deleted file mode 100644 index 8697d7577..000000000 --- a/nuttx/lib/signal/sig_fillset.c +++ /dev/null @@ -1,88 +0,0 @@ -/**************************************************************************** - * lib/signal/sig_fillset.c - * - * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Publics Functions - ****************************************************************************/ - -/**************************************************************************** - * Function: sigfillset - * - * Description: - * This function initializes the signal set specified by set such that all - * signals are included. - * - * Parameters: - * set - Signal set to initalize - * - * Return Value: - * 0 (OK), or -1 (ERROR) if the signal set cannot be initialized. - * - * Assumptions: - * - ****************************************************************************/ - -int sigfillset(FAR sigset_t *set) -{ - *set = ALL_SIGNAL_SET; - return OK; -} - diff --git a/nuttx/lib/signal/sig_ismember.c b/nuttx/lib/signal/sig_ismember.c deleted file mode 100644 index c5bb091b7..000000000 --- a/nuttx/lib/signal/sig_ismember.c +++ /dev/null @@ -1,101 +0,0 @@ -/**************************************************************************** - * lib/signal/sig_ismember.c - * - * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Function: sigismember - * - * Description: - * This function tests whether the signal specified by signo is a member - * of the set specified by set. - * - * Parameters: - * set - Signal set to test - * signo - Signal to test for - * - * Return Value: - * 1 (true), if the specified signal is a member of the set, - * 0 (OK or FALSE), if it is not, or - * -1 (ERROR) if the signal number is invalid. - * - * Assumptions: - * - ****************************************************************************/ - -int sigismember(FAR const sigset_t *set, int signo) -{ - int ret = ERROR; - - /* Verify the signal */ - - if (GOOD_SIGNO(signo)) - { - /* Check if the signal is in the set */ - - ret = ((*set & SIGNO2SET(signo)) != 0); - } - - return ret; -} - diff --git a/nuttx/lib/stdio/Make.defs b/nuttx/lib/stdio/Make.defs deleted file mode 100644 index a4e900705..000000000 --- a/nuttx/lib/stdio/Make.defs +++ /dev/null @@ -1,73 +0,0 @@ -############################################################################ -# lib/stdio/Make.defs -# -# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt -# -# 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. -# -############################################################################ - -# Add the stdio C files to the build - -CSRCS += lib_fileno.c lib_printf.c lib_rawprintf.c lib_lowprintf.c \ - lib_sprintf.c lib_asprintf.c lib_snprintf.c lib_libsprintf.c \ - lib_vsprintf.c lib_avsprintf.c lib_vsnprintf.c lib_libvsprintf.c \ - lib_meminstream.c lib_memoutstream.c lib_lowinstream.c \ - lib_lowoutstream.c lib_zeroinstream.c lib_nullinstream.c \ - lib_nulloutstream.c lib_sscanf.c - -ifneq ($(CONFIG_NFILE_DESCRIPTORS),0) -CSRCS += lib_rawinstream.c lib_rawoutstream.c -ifneq ($(CONFIG_NFILE_STREAMS),0) -CSRCS += lib_fopen.c lib_fclose.c lib_fread.c lib_libfread.c lib_fseek.c \ - lib_ftell.c lib_fsetpos.c lib_fgetpos.c lib_fgetc.c lib_fgets.c \ - lib_gets.c lib_fwrite.c lib_libfwrite.c lib_fflush.c \ - lib_libflushall.c lib_libfflush.c lib_rdflush.c lib_wrflush.c \ - lib_fputc.c lib_puts.c lib_fputs.c lib_ungetc.c lib_vprintf.c \ - lib_fprintf.c lib_vfprintf.c lib_vdprintf.c lib_stdinstream.c lib_stdoutstream.c \ - lib_perror.c -endif -endif - -ifeq ($(CONFIG_SYSLOG),y) -CSRCS += lib_syslogstream.c -endif - -ifeq ($(CONFIG_LIBC_FLOATINGPOINT),y) -CSRCS += lib_dtoa.c -endif - -ifeq ($(CONFIG_STDIO_LINEBUFFER),y) -CSRCS += lib_libnoflush.c -endif - -# Add the stdio directory to the build - -DEPPATH += --dep-path stdio -VPATH += :stdio diff --git a/nuttx/lib/stdio/lib_asprintf.c b/nuttx/lib/stdio/lib_asprintf.c deleted file mode 100644 index 84aaafa46..000000000 --- a/nuttx/lib/stdio/lib_asprintf.c +++ /dev/null @@ -1,105 +0,0 @@ -/**************************************************************************** - * lib/stdio/lib_asprintf.c - * - * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Global Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Global Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: asprintf - * - * Description: - * This function is similar to sprintf, except that it dynamically - * allocates a string (as with malloc) to hold the output, instead of - * putting the output in a buffer you allocate in advance. The ptr - * argument should be the address of a char * object, and a successful - * call to asprintf stores a pointer to the newly allocated string at that - * location. - * - * Returned Value: - * The returned value is the number of characters allocated for the buffer, - * or less than zero if an error occurred. Usually this means that the buffer - * could not be allocated. - * - ****************************************************************************/ - -int asprintf (FAR char **ptr, const char *fmt, ...) -{ - va_list ap; - int ret; - - /* Let avsprintf do all of the work */ - - va_start(ap, fmt); - ret = avsprintf(ptr, fmt, ap); - va_end(ap); - - return ret; -} diff --git a/nuttx/lib/stdio/lib_avsprintf.c b/nuttx/lib/stdio/lib_avsprintf.c deleted file mode 100644 index 8561b97c2..000000000 --- a/nuttx/lib/stdio/lib_avsprintf.c +++ /dev/null @@ -1,146 +0,0 @@ -/**************************************************************************** - * lib/stdio/lib_avsprintf.c - * - * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 -#include -#include -#include - -#include "lib_internal.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Global Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Global Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: avsprintf - * - * Description: - * This function is similar to vsprintf, except that it dynamically - * allocates a string (as with malloc) to hold the output, instead of - * putting the output in a buffer you allocate in advance. The ptr - * argument should be the address of a char * object, and a successful - * call to avsprintf stores a pointer to the newly allocated string at that - * location. - * - * Returned Value: - * The returned value is the number of characters allocated for the buffer, - * or less than zero if an error occurred. Usually this means that the buffer - * could not be allocated. - * - ****************************************************************************/ - -int avsprintf(FAR char **ptr, const char *fmt, va_list ap) -{ - struct lib_outstream_s nulloutstream; - struct lib_memoutstream_s memoutstream; - FAR char *buf; - int nbytes; - - DEBUGASSERT(ptr && fmt); - - /* First, use a nullstream to get the size of the buffer. The number - * of bytes returned may or may not include the null terminator. - */ - - lib_nulloutstream(&nulloutstream); - nbytes = lib_vsprintf((FAR struct lib_outstream_s *)&nulloutstream, fmt, ap); - - /* Then allocate a buffer to hold that number of characters, adding one - * for the null terminator. - */ - - buf = (FAR char *)malloc(nulloutstream.nput + 1); - if (!buf) - { - return ERROR; - } - - /* Initialize a memory stream to write into the allocated buffer. The - * memory stream will reserve one byte at the end of the buffer for the - * null terminator and will not report this in the number of output bytes. - */ - - lib_memoutstream((FAR struct lib_memoutstream_s *)&memoutstream, - buf, nulloutstream.nput + 1); - - /* Then let lib_vsprintf do it's real thing */ - - nbytes = lib_vsprintf((FAR struct lib_outstream_s *)&memoutstream.public, fmt, ap); - - /* Return a pointer to the string to the caller. NOTE: the memstream put() - * method has already added the NUL terminator to the end of the string (not - * included in the nput count). - * - * Hmmm.. looks like the memory would be stranded if lib_vsprintf() returned - * an error. Does that ever happen? - */ - - DEBUGASSERT(nbytes < 0 || nbytes == nulloutstream.nput); - *ptr = buf; - return nbytes; -} diff --git a/nuttx/lib/stdio/lib_dtoa.c b/nuttx/lib/stdio/lib_dtoa.c deleted file mode 100644 index b8c7db980..000000000 --- a/nuttx/lib/stdio/lib_dtoa.c +++ /dev/null @@ -1,1641 +0,0 @@ -/**************************************************************************** - * lib/stdio/lib_dtoa.c - * - * This file was ported to NuttX by Yolande Cates. - * - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University 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 REGENTS 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 REGENTS 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 - -#include -#include - -#include "lib_internal.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#ifdef Unsigned_Shifts -# define Sign_Extend(a,b) if (b < 0) a |= 0xffff0000; -#else -# define Sign_Extend(a,b) /* no-op */ -#endif - -#ifdef CONFIG_ENDIAN_BIG -# define word0(x) ((uint32_t *)&x)[0] -# define word1(x) ((uint32_t *)&x)[1] -#else -# define word0(x) ((uint32_t *)&x)[1] -# define word1(x) ((uint32_t *)&x)[0] -#endif - -#ifdef CONFIG_ENDIAN_BIG -# define Storeinc(a,b,c) (((unsigned short *)a)[0] = (unsigned short)b, \ - ((unsigned short *)a)[1] = (unsigned short)c, a++) -#else -# define Storeinc(a,b,c) (((unsigned short *)a)[1] = (unsigned short)b, \ - ((unsigned short *)a)[0] = (unsigned short)c, a++) -#endif - -#define Exp_shift 20 -#define Exp_shift1 20 -#define Exp_msk1 0x100000 -#define Exp_msk11 0x100000 -#define Exp_mask 0x7ff00000 -#define P 53 -#define Bias 1023 -#define IEEE_Arith -#define Emin (-1022) -#define Exp_1 0x3ff00000 -#define Exp_11 0x3ff00000 -#define Ebits 11 -#define Frac_mask 0xfffff -#define Frac_mask1 0xfffff -#define Ten_pmax 22 -#define Bletch 0x10 -#define Bndry_mask 0xfffff -#define Bndry_mask1 0xfffff -#define LSB 1 -#define Sign_bit 0x80000000 -#define Log2P 1 -#define Tiny0 0 -#define Tiny1 1 -#define Quick_max 14 -#define Int_max 14 -#define Infinite(x) (word0(x) == 0x7ff00000) /* sufficient test for here */ - -#define Kmax 15 - -#define Bcopy(x,y) memcpy((char *)&x->sign, (char *)&y->sign, \ - y->wds*sizeof(long) + 2*sizeof(int)) - -/**************************************************************************** - * Private Type Definitions - ****************************************************************************/ - -struct Bigint -{ - struct Bigint *next; - int k, maxwds, sign, wds; - unsigned long x[1]; -}; - -typedef struct Bigint Bigint; - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static Bigint *freelist[Kmax + 1]; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static Bigint *Balloc(int k) -{ - int x; - Bigint *rv; - - if ((rv = freelist[k])) - { - freelist[k] = rv->next; - } - else - { - x = 1 << k; - rv = (Bigint *)lib_malloc(sizeof(Bigint) + (x - 1) * sizeof(long)); - rv->k = k; - rv->maxwds = x; - } - rv->sign = rv->wds = 0; - return rv; -} - -static void Bfree(Bigint * v) -{ - if (v) - { - v->next = freelist[v->k]; - freelist[v->k] = v; - } -} - -/* multiply by m and add a */ - -static Bigint *multadd(Bigint * b, int m, int a) -{ - int i, wds; - unsigned long *x, y; -#ifdef Pack_32 - unsigned long xi, z; -#endif - Bigint *b1; - - wds = b->wds; - x = b->x; - i = 0; - do - { -#ifdef Pack_32 - xi = *x; - y = (xi & 0xffff) * m + a; - z = (xi >> 16) * m + (y >> 16); - a = (int)(z >> 16); - *x++ = (z << 16) + (y & 0xffff); -#else - y = *x * m + a; - a = (int)(y >> 16); - *x++ = y & 0xffff; -#endif - } - while (++i < wds); - if (a) - { - if (wds >= b->maxwds) - { - b1 = Balloc(b->k + 1); - Bcopy(b1, b); - Bfree(b); - b = b1; - } - b->x[wds++] = a; - b->wds = wds; - } - return b; -} - -static int hi0bits(unsigned long x) -{ - int k = 0; - - if (!(x & 0xffff0000)) - { - k = 16; - x <<= 16; - } - - if (!(x & 0xff000000)) - { - k += 8; - x <<= 8; - } - - if (!(x & 0xf0000000)) - { - k += 4; - x <<= 4; - } - - if (!(x & 0xc0000000)) - { - k += 2; - x <<= 2; - } - - if (!(x & 0x80000000)) - { - k++; - if (!(x & 0x40000000)) - { - return 32; - } - } - return k; -} - -static int lo0bits(unsigned long *y) -{ - int k; - unsigned long x = *y; - - if (x & 7) - { - if (x & 1) - { - return 0; - } - if (x & 2) - { - *y = x >> 1; - return 1; - } - *y = x >> 2; - return 2; - } - - k = 0; - if (!(x & 0xffff)) - { - k = 16; - x >>= 16; - } - - if (!(x & 0xff)) - { - k += 8; - x >>= 8; - } - - if (!(x & 0xf)) - { - k += 4; - x >>= 4; - } - - if (!(x & 0x3)) - { - k += 2; - x >>= 2; - } - - if (!(x & 1)) - { - k++; - x >>= 1; - if (!x & 1) - { - return 32; - } - } - *y = x; - return k; -} - -static Bigint *i2b(int i) -{ - Bigint *b; - - b = Balloc(1); - b->x[0] = i; - b->wds = 1; - return b; -} - -static Bigint *mult(Bigint * a, Bigint * b) -{ - Bigint *c; - int k, wa, wb, wc; - unsigned long carry, y, z; - unsigned long *x, *xa, *xae, *xb, *xbe, *xc, *xc0; -#ifdef Pack_32 - uint32_t z2; -#endif - - if (a->wds < b->wds) - { - c = a; - a = b; - b = c; - } - - k = a->k; - wa = a->wds; - wb = b->wds; - wc = wa + wb; - if (wc > a->maxwds) - { - k++; - } - c = Balloc(k); - for (x = c->x, xa = x + wc; x < xa; x++) - { - *x = 0; - } - xa = a->x; - xae = xa + wa; - xb = b->x; - xbe = xb + wb; - xc0 = c->x; -#ifdef Pack_32 - for (; xb < xbe; xb++, xc0++) - { - if ((y = *xb & 0xffff)) - { - x = xa; - xc = xc0; - carry = 0; - do - { - z = (*x & 0xffff) * y + (*xc & 0xffff) + carry; - carry = z >> 16; - z2 = (*x++ >> 16) * y + (*xc >> 16) + carry; - carry = z2 >> 16; - Storeinc(xc, z2, z); - } - while (x < xae); - *xc = carry; - } - if ((y = *xb >> 16)) - { - x = xa; - xc = xc0; - carry = 0; - z2 = *xc; - do - { - z = (*x & 0xffff) * y + (*xc >> 16) + carry; - carry = z >> 16; - Storeinc(xc, z, z2); - z2 = (*x++ >> 16) * y + (*xc & 0xffff) + carry; - carry = z2 >> 16; - } - while (x < xae); - *xc = z2; - } - } -#else - for (; xb < xbe; xc0++) - { - if ((y = *xb++)) - { - x = xa; - xc = xc0; - carry = 0; - do - { - z = *x++ * y + *xc + carry; - carry = z >> 16; - *xc++ = z & 0xffff; - } - while (x < xae); - *xc = carry; - } - } -#endif - for (xc0 = c->x, xc = xc0 + wc; wc > 0 && !*--xc; --wc); - c->wds = wc; - return c; -} - -static Bigint *p5s; - -static Bigint *pow5mult(Bigint * b, int k) -{ - Bigint *b1, *p5, *p51; - int i; - static int p05[3] = { 5, 25, 125 }; - - if ((i = k & 3)) - b = multadd(b, p05[i - 1], 0); - - if (!(k >>= 2)) - { - return b; - } - - if (!(p5 = p5s)) - { - /* first time */ - p5 = p5s = i2b(625); - p5->next = 0; - } - - for (;;) - { - if (k & 1) - { - b1 = mult(b, p5); - Bfree(b); - b = b1; - } - if (!(k >>= 1)) - { - break; - } - - if (!(p51 = p5->next)) - { - p51 = p5->next = mult(p5, p5); - p51->next = 0; - } - p5 = p51; - } - return b; -} - -static Bigint *lshift(Bigint * b, int k) -{ - int i, k1, n, n1; - Bigint *b1; - unsigned long *x, *x1, *xe, z; - -#ifdef Pack_32 - n = k >> 5; -#else - n = k >> 4; -#endif - k1 = b->k; - n1 = n + b->wds + 1; - for (i = b->maxwds; n1 > i; i <<= 1) - { - k1++; - } - b1 = Balloc(k1); - x1 = b1->x; - for (i = 0; i < n; i++) - { - *x1++ = 0; - } - x = b->x; - xe = x + b->wds; -#ifdef Pack_32 - if (k &= 0x1f) - { - k1 = 32 - k; - z = 0; - do - { - *x1++ = *x << k | z; - z = *x++ >> k1; - } - while (x < xe); - if ((*x1 = z)) - { - ++n1; - } - } -#else - if (k &= 0xf) - { - k1 = 16 - k; - z = 0; - do - { - *x1++ = ((*x << k) & 0xffff) | z; - z = *x++ >> k1; - } - while (x < xe); - if ((*x1 = z)) - { - ++n1; - } - } -#endif - else - do - { - *x1++ = *x++; - } - while (x < xe); - b1->wds = n1 - 1; - Bfree(b); - return b1; -} - -static int cmp(Bigint * a, Bigint * b) -{ - unsigned long *xa, *xa0, *xb, *xb0; - int i, j; - - i = a->wds; - j = b->wds; -#ifdef CONFIG_DEBUG_LIB - if (i > 1 && !a->x[i - 1]) - { - ldbg("cmp called with a->x[a->wds-1] == 0\n"); - } - if (j > 1 && !b->x[j - 1]) - { - ldbg("cmp called with b->x[b->wds-1] == 0\n"); - } -#endif - if (i -= j) - return i; - xa0 = a->x; - xa = xa0 + j; - xb0 = b->x; - xb = xb0 + j; - for (;;) - { - if (*--xa != *--xb) - return *xa < *xb ? -1 : 1; - if (xa <= xa0) - break; - } - return 0; -} - -static Bigint *diff(Bigint * a, Bigint * b) -{ - Bigint *c; - int i, wa, wb; - long borrow, y; /* We need signed shifts here. */ - unsigned long *xa, *xae, *xb, *xbe, *xc; -#ifdef Pack_32 - int32_t z; -#endif - - i = cmp(a, b); - if (!i) - { - c = Balloc(0); - c->wds = 1; - c->x[0] = 0; - return c; - } - if (i < 0) - { - c = a; - a = b; - b = c; - i = 1; - } - else - i = 0; - c = Balloc(a->k); - c->sign = i; - wa = a->wds; - xa = a->x; - xae = xa + wa; - wb = b->wds; - xb = b->x; - xbe = xb + wb; - xc = c->x; - borrow = 0; -#ifdef Pack_32 - do - { - y = (*xa & 0xffff) - (*xb & 0xffff) + borrow; - borrow = y >> 16; - Sign_Extend(borrow, y); - z = (*xa++ >> 16) - (*xb++ >> 16) + borrow; - borrow = z >> 16; - Sign_Extend(borrow, z); - Storeinc(xc, z, y); - } - while (xb < xbe); - while (xa < xae) - { - y = (*xa & 0xffff) + borrow; - borrow = y >> 16; - Sign_Extend(borrow, y); - z = (*xa++ >> 16) + borrow; - borrow = z >> 16; - Sign_Extend(borrow, z); - Storeinc(xc, z, y); - } -#else - do - { - y = *xa++ - *xb++ + borrow; - borrow = y >> 16; - Sign_Extend(borrow, y); - *xc++ = y & 0xffff; - } - while (xb < xbe); - while (xa < xae) - { - y = *xa++ + borrow; - borrow = y >> 16; - Sign_Extend(borrow, y); - *xc++ = y & 0xffff; - } -#endif - while (!*--xc) - wa--; - c->wds = wa; - return c; -} - -static Bigint *d2b(double d, int *e, int *bits) -{ - Bigint *b; - int de, i, k; - unsigned long *x, y, z; - -#ifdef Pack_32 - b = Balloc(1); -#else - b = Balloc(2); -#endif - x = b->x; - - z = word0(d) & Frac_mask; - word0(d) &= 0x7fffffff; /* clear sign bit, which we ignore */ - if ((de = (int)(word0(d) >> Exp_shift))) - z |= Exp_msk1; -#ifdef Pack_32 - if ((y = word1(d))) - { - if ((k = lo0bits(&y))) - { - x[0] = y | z << (32 - k); - z >>= k; - } - else - x[0] = y; - i = b->wds = (x[1] = z) ? 2 : 1; - } - else - { -#ifdef CONFIG_DEBUG_LIB - if (!z) - { - ldbg("Zero passed to d2b\n"); - } -#endif - k = lo0bits(&z); - x[0] = z; - i = b->wds = 1; - k += 32; - } -#else - if ((y = word1(d))) - { - if ((k = lo0bits(&y))) - if (k >= 16) - { - x[0] = y | ((z << (32 - k)) & 0xffff); - x[1] = z >> (k - 16) & 0xffff; - x[2] = z >> k; - i = 2; - } - else - { - x[0] = y & 0xffff; - x[1] = (y >> 16) | ((z << (16 - k)) & 0xffff); - x[2] = z >> k & 0xffff; - x[3] = z >> (k + 16); - i = 3; - } - else - { - x[0] = y & 0xffff; - x[1] = y >> 16; - x[2] = z & 0xffff; - x[3] = z >> 16; - i = 3; - } - } - else - { -#ifdef CONFIG_DEBUG_LIB - if (!z) - { - ldbg("Zero passed to d2b\n"); - } -#endif - k = lo0bits(&z); - if (k >= 16) - { - x[0] = z; - i = 0; - } - else - { - x[0] = z & 0xffff; - x[1] = z >> 16; - i = 1; - } - k += 32; - } - while (!x[i]) - --i; - b->wds = i + 1; -#endif - if (de) - { - *e = de - Bias - (P - 1) + k; - *bits = P - k; - } - else - { - *e = de - Bias - (P - 1) + 1 + k; -#ifdef Pack_32 - *bits = 32 * i - hi0bits(x[i - 1]); -#else - *bits = (i + 2) * 16 - hi0bits(x[i]); -#endif - } - return b; -} - -static const double tens[] = { - 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, - 1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19, - 1e20, 1e21, 1e22 -}; - -#ifdef IEEE_Arith -static const double bigtens[] = { 1e16, 1e32, 1e64, 1e128, 1e256 }; -static const double tinytens[] = { 1e-16, 1e-32, 1e-64, 1e-128, 1e-256 }; - -# define n_bigtens 5 -#else -static const double bigtens[] = { 1e16, 1e32 }; -static const double tinytens[] = { 1e-16, 1e-32 }; - -# define n_bigtens 2 -#endif - -static int quorem(Bigint * b, Bigint * S) -{ - int n; - long borrow, y; - unsigned long carry, q, ys; - unsigned long *bx, *bxe, *sx, *sxe; -#ifdef Pack_32 - int32_t z; - uint32_t si, zs; -#endif - - n = S->wds; -#ifdef CONFIG_DEBUG_LIB - if (b->wds > n) - { - ldbg("oversize b in quorem\n"); - } -#endif - if (b->wds < n) - { - return 0; - } - sx = S->x; - sxe = sx + --n; - bx = b->x; - bxe = bx + n; - q = *bxe / (*sxe + 1); /* ensure q <= true quotient */ -#ifdef CONFIG_DEBUG_LIB - if (q > 9) - { - ldbg("oversized quotient in quorem\n"); - } -#endif - if (q) - { - borrow = 0; - carry = 0; - do - { -#ifdef Pack_32 - si = *sx++; - ys = (si & 0xffff) * q + carry; - zs = (si >> 16) * q + (ys >> 16); - carry = zs >> 16; - y = (*bx & 0xffff) - (ys & 0xffff) + borrow; - borrow = y >> 16; - Sign_Extend(borrow, y); - z = (*bx >> 16) - (zs & 0xffff) + borrow; - borrow = z >> 16; - Sign_Extend(borrow, z); - Storeinc(bx, z, y); -#else - ys = *sx++ * q + carry; - carry = ys >> 16; - y = *bx - (ys & 0xffff) + borrow; - borrow = y >> 16; - Sign_Extend(borrow, y); - *bx++ = y & 0xffff; -#endif - } - while (sx <= sxe); - if (!*bxe) - { - bx = b->x; - while (--bxe > bx && !*bxe) - --n; - b->wds = n; - } - } - if (cmp(b, S) >= 0) - { - q++; - borrow = 0; - carry = 0; - bx = b->x; - sx = S->x; - do - { -#ifdef Pack_32 - si = *sx++; - ys = (si & 0xffff) + carry; - zs = (si >> 16) + (ys >> 16); - carry = zs >> 16; - y = (*bx & 0xffff) - (ys & 0xffff) + borrow; - borrow = y >> 16; - Sign_Extend(borrow, y); - z = (*bx >> 16) - (zs & 0xffff) + borrow; - borrow = z >> 16; - Sign_Extend(borrow, z); - Storeinc(bx, z, y); -#else - ys = *sx++ + carry; - carry = ys >> 16; - y = *bx - (ys & 0xffff) + borrow; - borrow = y >> 16; - Sign_Extend(borrow, y); - *bx++ = y & 0xffff; -#endif - } - while (sx <= sxe); - bx = b->x; - bxe = bx + n; - if (!*bxe) - { - while (--bxe > bx && !*bxe) - --n; - b->wds = n; - } - } - return q; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/* dtoa for IEEE arithmetic (dmg): convert double to ASCII string. - * - * Inspired by "How to Print Floating-Point Numbers Accurately" by - * Guy L. Steele, Jr. and Jon L. White [Proc. ACM SIGPLAN '90, pp. 92-101]. - * - * Modifications: - * 1. Rather than iterating, we use a simple numeric overestimate - * to determine k = floor(log10(d)). We scale relevant - * quantities using O(log2(k)) rather than O(k) multiplications. - * 2. For some modes > 2 (corresponding to ecvt and fcvt), we don't - * try to generate digits strictly left to right. Instead, we - * compute with fewer bits and propagate the carry if necessary - * when rounding the final digit up. This is often faster. - * 3. Under the assumption that input will be rounded nearest, - * mode 0 renders 1e23 as 1e23 rather than 9.999999999999999e22. - * That is, we allow equality in stopping tests when the - * round-nearest rule will give the same floating-point value - * as would satisfaction of the stopping test with strict - * inequality. - * 4. We remove common factors of powers of 2 from relevant - * quantities. - * 5. When converting floating-point integers less than 1e16, - * we use floating-point arithmetic rather than resorting - * to multiple-precision integers. - * 6. When asked to produce fewer than 15 digits, we first try - * to get by with floating-point arithmetic; we resort to - * multiple-precision integer arithmetic only if we cannot - * guarantee that the floating-point calculation has given - * the correctly rounded result. For k requested digits and - * "uniformly" distributed input, the probability is - * something like 10^(k-15) that we must resort to the int32_t - * calculation. - */ - -char *__dtoa(double d, int mode, int ndigits, int *decpt, int *sign, char **rve) -{ - /* Arguments ndigits, decpt, sign are similar to those of ecvt and fcvt; - * trailing zeros are suppressed from the returned string. If not null, *rve - * is set to point to the end of the return value. If d is +-Infinity or - * NaN, then *decpt is set to 9999. - * - * mode: 0 ==> shortest string that yields d when read in and rounded to - * nearest. 1 ==> like 0, but with Steele & White stopping rule; e.g. with - * IEEE P754 arithmetic , mode 0 gives 1e23 whereas mode 1 gives - * 9.999999999999999e22. 2 ==> max(1,ndigits) significant digits. This gives - * a return value similar to that of ecvt, except that trailing zeros are - * suppressed. 3 ==> through ndigits past the decimal point. This gives a - * return value similar to that from fcvt, except that trailing zeros are - * suppressed, and ndigits can be negative. 4-9 should give the same return - * values as 2-3, i.e., 4 <= mode <= 9 ==> same return as mode 2 + (mode & - * 1). These modes are mainly for debugging; often they run slower but - * sometimes faster than modes 2-3. 4,5,8,9 ==> left-to-right digit - * generation. 6-9 ==> don't try fast floating-point estimate (if - * applicable). - * - * Values of mode other than 0-9 are treated as mode 0. - * - * Sufficient space is allocated to the return value to hold the suppressed - * trailing zeros. */ - - int bbits, b2, b5, be, dig, i, ieps, ilim = 0, ilim0, ilim1 = 0, - j, j_1, k, k0, k_check, leftright, m2, m5, s2, s5, spec_case = 0, try_quick; - long L; - int denorm; - unsigned long x; - Bigint *b, *b1, *delta, *mlo = NULL, *mhi, *S; - double d2, ds, eps; - char *s, *s0; - static Bigint *result; - static int result_k; - - if (result) - { - result->k = result_k; - result->maxwds = 1 << result_k; - Bfree(result); - result = 0; - } - - if (word0(d) & Sign_bit) - { - /* set sign for everything, including 0's and NaNs */ - *sign = 1; - word0(d) &= ~Sign_bit; /* clear sign bit */ - } - else - { - *sign = 0; - } - -#if defined(IEEE_Arith) -# ifdef IEEE_Arith - if ((word0(d) & Exp_mask) == Exp_mask) -#else - if (word0(d) == 0x8000) -#endif - { - /* Infinity or NaN */ - *decpt = 9999; - s = -#ifdef IEEE_Arith - !word1(d) && !(word0(d) & 0xfffff) ? "Infinity" : -#endif - "NaN"; - if (rve) - *rve = -#ifdef IEEE_Arith - s[3] ? s + 8 : -#endif - s + 3; - return s; - } -#endif - if (!d) - { - *decpt = 1; - s = "0"; - if (rve) - *rve = s + 1; - return s; - } - - b = d2b(d, &be, &bbits); - if ((i = (int)(word0(d) >> Exp_shift1 & (Exp_mask >> Exp_shift1)))) - { - d2 = d; - word0(d2) &= Frac_mask1; - word0(d2) |= Exp_11; - - /* log(x) ~=~ log(1.5) + (x-1.5)/1.5 log10(x) = log(x) / log(10) ~=~ - * log(1.5)/log(10) + (x-1.5)/(1.5*log(10)) log10(d) = - * (i-Bias)*log(2)/log(10) + log10(d2) This suggests computing an - * approximation k to log10(d) by k = (i - Bias)*0.301029995663981 + ( - * (d2-1.5)*0.289529654602168 + 0.176091259055681 ); We want k to be too - * large rather than too small. The error in the first-order Taylor - * series approximation is in our favor, so we just round up the constant - * enough to compensate for any error in the multiplication of (i - Bias) - * by 0.301029995663981; since |i - Bias| <= 1077, and 1077 * 0.30103 * - * 2^-52 ~=~ 7.2e-14, adding 1e-13 to the constant term more than - * suffices. Hence we adjust the constant term to 0.1760912590558. (We - * could get a more accurate k by invoking log10, but this is probably - * not worthwhile.) */ - - i -= Bias; - denorm = 0; - } - else - { - /* d is denormalized */ - - i = bbits + be + (Bias + (P - 1) - 1); - x = i > 32 ? word0(d) << (64 - i) | word1(d) >> (i - 32) - : word1(d) << (32 - i); - d2 = x; - word0(d2) -= 31 * Exp_msk1; /* adjust exponent */ - i -= (Bias + (P - 1) - 1) + 1; - denorm = 1; - } - - ds = (d2 - 1.5) * 0.289529654602168 + 0.1760912590558 + i * 0.301029995663981; - k = (int)ds; - if (ds < 0. && ds != k) - { - k--; /* want k = floor(ds) */ - } - k_check = 1; - - if (k >= 0 && k <= Ten_pmax) - { - if (d < tens[k]) - k--; - k_check = 0; - } - - j = bbits - i - 1; - if (j >= 0) - { - b2 = 0; - s2 = j; - } - else - { - b2 = -j; - s2 = 0; - } - - if (k >= 0) - { - b5 = 0; - s5 = k; - s2 += k; - } - else - { - b2 -= k; - b5 = -k; - s5 = 0; - } - - if (mode < 0 || mode > 9) - { - mode = 0; - } - - try_quick = 1; - if (mode > 5) - { - mode -= 4; - try_quick = 0; - } - - leftright = 1; - switch (mode) - { - case 0: - case 1: - ilim = ilim1 = -1; - i = 18; - ndigits = 0; - break; - - case 2: - leftright = 0; - /* no break */ - case 4: - if (ndigits <= 0) - { - ndigits = 1; - } - - ilim = ilim1 = i = ndigits; - break; - - case 3: - leftright = 0; - /* no break */ - case 5: - i = ndigits + k + 1; - ilim = i; - ilim1 = i - 1; - if (i <= 0) - { - i = 1; - } - } - - j = sizeof(unsigned long); - for (result_k = 0; - (signed)(sizeof(Bigint) - sizeof(unsigned long) + j) <= i; - j <<= 1) - { - result_k++; - } - - result = Balloc(result_k); - s = s0 = (char *)result; - - if (ilim >= 0 && ilim <= Quick_max && try_quick) - { - /* Try to get by with floating-point arithmetic. */ - - i = 0; - d2 = d; - k0 = k; - ilim0 = ilim; - ieps = 2; /* conservative */ - - if (k > 0) - { - ds = tens[k & 0xf]; - j = k >> 4; - - if (j & Bletch) - { - /* prevent overflows */ - j &= Bletch - 1; - d /= bigtens[n_bigtens - 1]; - ieps++; - } - - for (; j; j >>= 1, i++) - { - if (j & 1) - { - ieps++; - ds *= bigtens[i]; - } - } - - d /= ds; - } - else if ((j_1 = -k)) - { - d *= tens[j_1 & 0xf]; - for (j = j_1 >> 4; j; j >>= 1, i++) - { - if (j & 1) - { - ieps++; - d *= bigtens[i]; - } - } - } - - if (k_check && d < 1. && ilim > 0) - { - if (ilim1 <= 0) - { - goto fast_failed; - } - - ilim = ilim1; - k--; - d *= 10.; - ieps++; - } - - eps = ieps * d + 7.; - word0(eps) -= (P - 1) * Exp_msk1; - if (ilim == 0) - { - S = mhi = 0; - d -= 5.; - if (d > eps) - goto one_digit; - if (d < -eps) - goto no_digits; - goto fast_failed; - } - -#ifndef No_leftright - if (leftright) - { - /* Use Steele & White method of only generating digits needed. */ - - eps = 0.5 / tens[ilim - 1] - eps; - for (i = 0;;) - { - L = (int)d; - d -= L; - *s++ = '0' + (int)L; - if (d < eps) - goto ret1; - if (1. - d < eps) - goto bump_up; - if (++i >= ilim) - break; - eps *= 10.; - d *= 10.; - } - } - else - { -#endif - /* Generate ilim digits, then fix them up. */ - - eps *= tens[ilim - 1]; - for (i = 1;; i++, d *= 10.) - { - L = (int)d; - d -= L; - *s++ = '0' + (int)L; - if (i == ilim) - { - if (d > 0.5 + eps) - goto bump_up; - else if (d < 0.5 - eps) - { - while (*--s == '0'); - s++; - goto ret1; - } - break; - } - } -#ifndef No_leftright - } -#endif - fast_failed: - s = s0; - d = d2; - k = k0; - ilim = ilim0; - } - - /* Do we have a "small" integer? */ - - if (be >= 0 && k <= Int_max) - { - /* Yes. */ - - ds = tens[k]; - if (ndigits < 0 && ilim <= 0) - { - S = mhi = 0; - if (ilim < 0 || d <= 5 * ds) - goto no_digits; - goto one_digit; - } - - for (i = 1;; i++) - { - L = (int)(d / ds); - d -= L * ds; -#ifdef Check_FLT_ROUNDS - /* If FLT_ROUNDS == 2, L will usually be high by 1 */ - if (d < 0) - { - L--; - d += ds; - } -#endif - *s++ = '0' + (int)L; - if (i == ilim) - { - d += d; - if (d > ds || (d == ds && (L & 1))) - { - bump_up: - while (*--s == '9') - if (s == s0) - { - k++; - *s = '0'; - break; - } - ++*s++; - } - break; - } - if (!(d *= 10.)) - { - break; - } - } - - goto ret1; - } - - m2 = b2; - m5 = b5; - mhi = mlo = 0; - if (leftright) - { - if (mode < 2) - { - i = denorm ? be + (Bias + (P - 1) - 1 + 1) : 1 + P - bbits; - } - else - { - j = ilim - 1; - if (m5 >= j) - m5 -= j; - else - { - s5 += j -= m5; - b5 += j; - m5 = 0; - } - if ((i = ilim) < 0) - { - m2 -= i; - i = 0; - } - } - - b2 += i; - s2 += i; - mhi = i2b(1); - } - - if (m2 > 0 && s2 > 0) - { - i = m2 < s2 ? m2 : s2; - b2 -= i; - m2 -= i; - s2 -= i; - } - - if (b5 > 0) - { - if (leftright) - { - if (m5 > 0) - { - mhi = pow5mult(mhi, m5); - b1 = mult(mhi, b); - Bfree(b); - b = b1; - } - if ((j = b5 - m5)) - b = pow5mult(b, j); - } - else - { - b = pow5mult(b, b5); - } - } - - S = i2b(1); - if (s5 > 0) - { - S = pow5mult(S, s5); - } - - /* Check for special case that d is a normalized power of 2. */ - - if (mode < 2) - { - if (!word1(d) && !(word0(d) & Bndry_mask) && word0(d) & Exp_mask) - { - /* The special case */ - b2 += Log2P; - s2 += Log2P; - spec_case = 1; - } - else - { - spec_case = 0; - } - } - - /* Arrange for convenient computation of quotients: shift left if - * necessary so divisor has 4 leading 0 bits. - * - * Perhaps we should just compute leading 28 bits of S once and for all - * and pass them and a shift to quorem, so it can do shifts and ors - * to compute the numerator for q. - */ - -#ifdef Pack_32 - if ((i = ((s5 ? 32 - hi0bits(S->x[S->wds - 1]) : 1) + s2) & 0x1f)) - { - i = 32 - i; - } -#else - if ((i = ((s5 ? 32 - hi0bits(S->x[S->wds - 1]) : 1) + s2) & 0xf)) - { - i = 16 - i; - } -#endif - - if (i > 4) - { - i -= 4; - b2 += i; - m2 += i; - s2 += i; - } - else if (i < 4) - { - i += 28; - b2 += i; - m2 += i; - s2 += i; - } - - if (b2 > 0) - { - b = lshift(b, b2); - } - - if (s2 > 0) - { - S = lshift(S, s2); - } - - if (k_check) - { - if (cmp(b, S) < 0) - { - k--; - b = multadd(b, 10, 0); /* we botched the k estimate */ - if (leftright) - { - mhi = multadd(mhi, 10, 0); - } - - ilim = ilim1; - } - } - - if (ilim <= 0 && mode > 2) - { - if (ilim < 0 || cmp(b, S = multadd(S, 5, 0)) <= 0) - { - /* no digits, fcvt style */ - no_digits: - k = -1 - ndigits; - goto ret; - } - one_digit: - *s++ = '1'; - k++; - goto ret; - } - - if (leftright) - { - if (m2 > 0) - { - mhi = lshift(mhi, m2); - } - - /* Compute mlo -- check for special case that d is a normalized power of - * 2. */ - - mlo = mhi; - if (spec_case) - { - mhi = Balloc(mhi->k); - Bcopy(mhi, mlo); - mhi = lshift(mhi, Log2P); - } - - for (i = 1;; i++) - { - dig = quorem(b, S) + '0'; - /* Do we yet have the shortest decimal string that will round to d? */ - j = cmp(b, mlo); - delta = diff(S, mhi); - j_1 = delta->sign ? 1 : cmp(b, delta); - Bfree(delta); -#ifndef ROUND_BIASED - if (j_1 == 0 && !mode && !(word1(d) & 1)) - { - if (dig == '9') - { - goto round_9_up; - } - - if (j > 0) - { - dig++; - } - - *s++ = dig; - goto ret; - } -#endif - if (j < 0 || (j == 0 && !mode -#ifndef ROUND_BIASED - && (!(word1(d) & 1)) -#endif - )) - { - if ((j_1 > 0)) - { - b = lshift(b, 1); - j_1 = cmp(b, S); - if ((j_1 > 0 || (j_1 == 0 && (dig & 1))) && dig++ == '9') - { - goto round_9_up; - } - } - - *s++ = dig; - goto ret; - } - - if (j_1 > 0) - { - if (dig == '9') - { /* possible if i == 1 */ - round_9_up: - *s++ = '9'; - goto roundoff; - } - - *s++ = dig + 1; - goto ret; - } - - *s++ = dig; - if (i == ilim) - { - break; - } - - b = multadd(b, 10, 0); - if (mlo == mhi) - { - mlo = mhi = multadd(mhi, 10, 0); - } - else - { - mlo = multadd(mlo, 10, 0); - mhi = multadd(mhi, 10, 0); - } - } - } - else - { - for (i = 1;; i++) - { - *s++ = dig = quorem(b, S) + '0'; - if (i >= ilim) - { - break; - } - - b = multadd(b, 10, 0); - } - } - - /* Round off last digit */ - - b = lshift(b, 1); - j = cmp(b, S); - if (j > 0 || (j == 0 && (dig & 1))) - { - roundoff: - while (*--s == '9') - if (s == s0) - { - k++; - *s++ = '1'; - goto ret; - } - ++*s++; - } - else - { - while (*--s == '0'); - s++; - } - -ret: - Bfree(S); - if (mhi) - { - if (mlo && mlo != mhi) - { - Bfree(mlo); - } - - Bfree(mhi); - } -ret1: - Bfree(b); - if (s == s0) - { /* don't return empty string */ - *s++ = '0'; - k = 0; - } - - *s = 0; - *decpt = k + 1; - if (rve) - { - *rve = s; - } - - return s0; -} diff --git a/nuttx/lib/stdio/lib_fclose.c b/nuttx/lib/stdio/lib_fclose.c deleted file mode 100644 index 8cecb8af3..000000000 --- a/nuttx/lib/stdio/lib_fclose.c +++ /dev/null @@ -1,154 +0,0 @@ -/**************************************************************************** - * lib/stdio/lib_fclose.c - * - * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include -#include -#include -#include - -#include "lib_internal.h" - -/**************************************************************************** - * Global Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: fclose - * - * Description - * The fclose() function will flush the stream pointed to by stream - * (writing any buffered output data using lib_fflush()) and close the - * underlying file descriptor. - * - * Returned Value: - * Upon successful completion 0 is returned. Otherwise, EOF is returned - * and the global variable errno is set to indicate the error. In either - * case any further access (including another call to fclose()) to the - * stream results in undefined behaviour. - * - ****************************************************************************/ - -int fclose(FAR FILE *stream) -{ - int err = EINVAL; - int ret = ERROR; - int status; - - /* Verify that a stream was provided. */ - - if (stream) - { - /* Check that the underlying file descriptor corresponds to an an open - * file. - */ - - ret = OK; - if (stream->fs_filedes >= 0) - { - /* If the stream was opened for writing, then flush the stream */ - - if ((stream->fs_oflags & O_WROK) != 0) - { - ret = lib_fflush(stream, true); - err = errno; - } - - /* Close the underlying file descriptor and save the return status */ - - status = close(stream->fs_filedes); - - /* If close() returns an error but flush() did not then make sure - * that we return the close() error condition. - */ - - if (ret == OK) - { - ret = status; - err = errno; - } - } - -#if CONFIG_STDIO_BUFFER_SIZE > 0 - /* Destroy the semaphore */ - - sem_destroy(&stream->fs_sem); - - /* Release the buffer */ - - if (stream->fs_bufstart) - { - lib_free(stream->fs_bufstart); - } - - /* Clear the whole structure */ - - memset(stream, 0, sizeof(FILE)); -#else -#if CONFIG_NUNGET_CHARS > 0 - /* Reset the number of ungetc characters */ - - stream->fs_nungotten = 0; -#endif - /* Reset the flags */ - - stream->fs_oflags = 0; -#endif - /* Setting the fs_filedescriptor to -1 makes the stream available for reuse */ - - stream->fs_filedes = -1; - } - - /* On an error, reset the errno to the first error encountered and return - * EOF. - */ - - if (ret != OK) - { - set_errno(err); - return EOF; - } - - /* Return success */ - - return OK; -} - diff --git a/nuttx/lib/stdio/lib_fflush.c b/nuttx/lib/stdio/lib_fflush.c deleted file mode 100644 index d0b5e0185..000000000 --- a/nuttx/lib/stdio/lib_fflush.c +++ /dev/null @@ -1,132 +0,0 @@ -/**************************************************************************** - * lib/stdio/lib_fflush.c - * - * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include -#include -#include - -#include - -#include "lib_internal.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Global Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Global Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: fflush - * - * Description: - * The function fflush() forces a write of all user-space buffered data for - * the given output or update stream via the stream's underlying write - * function. The open status of the stream is unaffected. - * - * If the stream argument is NULL, fflush() flushes all open output streams. - * - * Return: - * OK on success EOF on failure (with errno set appropriately) - * - ****************************************************************************/ - -int fflush(FAR FILE *stream) -{ - int ret; - - /* Is the stream argument NULL? */ - - if (!stream) - { - /* Yes... then this is a request to flush all streams */ - - ret = lib_flushall(sched_getstreams()); - } - else - { - ret = lib_fflush(stream, true); - } - - /* Check the return value */ - - if (ret < 0) - { - /* An error occurred during the flush AND/OR we were unable to flush - * all of the buffered write data. Set the errno value. - */ - - set_errno(-ret); - - /* And return EOF on failure. */ - - return EOF; - } - - return OK; -} - diff --git a/nuttx/lib/stdio/lib_fgetc.c b/nuttx/lib/stdio/lib_fgetc.c deleted file mode 100644 index 4b3d0ec44..000000000 --- a/nuttx/lib/stdio/lib_fgetc.c +++ /dev/null @@ -1,101 +0,0 @@ -/**************************************************************************** - * lib/stdio/lib_fgetc.c - * - * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Compilation Switches - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include "lib_internal.h" - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Global Function Prototypes - ****************************************************************************/ - -/************************************************************************** - * Global Constant Data - **************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/************************************************************************** - * Private Constant Data - **************************************************************************/ - -/**************************************************************************** - * Private Variables - **************************************************************************/ - -/**************************************************************************** - * Global Functions - **************************************************************************/ - -/**************************************************************************** - * fgetc - **************************************************************************/ - -int fgetc(FAR FILE *stream) -{ - unsigned char ch; - ssize_t ret; - - ret = lib_fread(&ch, 1, stream); - if (ret > 0) - { - return ch; - } - else - { - return EOF; - } -} diff --git a/nuttx/lib/stdio/lib_fgetpos.c b/nuttx/lib/stdio/lib_fgetpos.c deleted file mode 100644 index e9e9f4d10..000000000 --- a/nuttx/lib/stdio/lib_fgetpos.c +++ /dev/null @@ -1,123 +0,0 @@ -/**************************************************************************** - * lib/stdio/lib_fgetpos.c - * - * Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Compilation Switches - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include - -#include "lib_internal.h" - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Global Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: fgetpos - * - * Description: - * fgetpos() function is an alternate interfaces equivalent to ftell(). - * It gets the current value of the file offset and store it in the location - * referenced by pos. On some non-UNIX systems an fpos_t object may be a - * complex object and fsetpos may be the only way to portably reposition a - * stream. - * - * Returned Value: - * Zero on succes; -1 on failure with errno set appropriately. - * - ****************************************************************************/ - -int fgetpos(FAR FILE *stream, FAR fpos_t *pos) -{ - long position; - -#if CONFIG_DEBUG - if (!stream || !pos) - { - set_errno(EINVAL); - return ERROR; - } -#endif - - position = ftell(stream); - if (position == -1) - { - return ERROR; - } - - *pos = (fpos_t)position; - return OK; -} diff --git a/nuttx/lib/stdio/lib_fgets.c b/nuttx/lib/stdio/lib_fgets.c deleted file mode 100644 index a4f9089ed..000000000 --- a/nuttx/lib/stdio/lib_fgets.c +++ /dev/null @@ -1,207 +0,0 @@ -/**************************************************************************** - * lib/stdio/lib_fgets.c - * - * Copyright (C) 2007-2008, 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include -#include -#include -#include -#include - -/**************************************************************************** - * Definitions - ****************************************************************************/ -/* Some environments may return CR as end-of-line, others LF, and others - * both. If not specified, the logic here assumes either (but not both) as - * the default. - */ - -#if defined(CONFIG_EOL_IS_CR) -# undef CONFIG_EOL_IS_LF -# undef CONFIG_EOL_IS_BOTH_CRLF -# undef CONFIG_EOL_IS_EITHER_CRLF -#elif defined(CONFIG_EOL_IS_LF) -# undef CONFIG_EOL_IS_CR -# undef CONFIG_EOL_IS_BOTH_CRLF -# undef CONFIG_EOL_IS_EITHER_CRLF -#elif defined(CONFIG_EOL_IS_BOTH_CRLF) -# undef CONFIG_EOL_IS_CR -# undef CONFIG_EOL_IS_LF -# undef CONFIG_EOL_IS_EITHER_CRLF -#elif defined(CONFIG_EOL_IS_EITHER_CRLF) -# undef CONFIG_EOL_IS_CR -# undef CONFIG_EOL_IS_LF -# undef CONFIG_EOL_IS_BOTH_CRLF -#else -# undef CONFIG_EOL_IS_CR -# undef CONFIG_EOL_IS_LF -# undef CONFIG_EOL_IS_BOTH_CRLF -# define CONFIG_EOL_IS_EITHER_CRLF 1 -#endif - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Global Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: fgets - * - * Description: - * fgets() reads in at most one less than 'buflen' characters from stream - * and stores them into the buffer pointed to by 'buf'. Reading stops after - * an EOF or a newline. If a newline is read, it is stored into the - * buffer. A null terminator is stored after the last character in the - * buffer. - * - **************************************************************************/ - -char *fgets(FAR char *buf, int buflen, FILE *stream) -{ - int nch = 0; - - /* Sanity checks */ - - if (!stream || !buf || buflen < 1 || stream->fs_filedes < 0) - { - return NULL; - } - - if (buflen < 2) - { - *buf = '\0'; - return buf; - } - - /* Read characters until we have a full line. On each the loop we must - * be assured that there are two free bytes in the line buffer: One for - * the next character and one for the null terminator. - */ - - for(;;) - { - /* Get the next character */ - - int ch = fgetc(stream); - - /* Check for end-of-line. This is tricky only in that some - * environments may return CR as end-of-line, others LF, and - * others both. - */ - -#if defined(CONFIG_EOL_IS_LF) || defined(CONFIG_EOL_IS_BOTH_CRLF) - if (ch == '\n') -#elif defined(CONFIG_EOL_IS_CR) - if (ch == '\r') -#elif CONFIG_EOL_IS_EITHER_CRLF - if (ch == '\n' || ch == '\r') -#endif - { - /* The newline is stored in the buffer along with the null - * terminator. - */ - - buf[nch++] = '\n'; - buf[nch] = '\0'; - return buf; - } - - /* Check for end-of-file */ - - else if (ch == EOF) - { - /* End of file with no data? */ - - if (!nch) - { - /* Yes.. return NULL as the end of file mark */ - - return NULL; - } - else - { - /* Terminate the line */ - - buf[nch] = '\0'; - return buf; - } - } - - /* Otherwise, check if the character is printable and, if so, put the - * character in the line buffer - */ - - else if (isprint(ch)) - { - buf[nch++] = ch; - - /* Check if there is room for another character and the line's - * null terminator. If not then we have to end the line now. - */ - - if (nch + 1 >= buflen) - { - buf[nch] = '\0'; - return buf; - } - } - } -} - diff --git a/nuttx/lib/stdio/lib_fileno.c b/nuttx/lib/stdio/lib_fileno.c deleted file mode 100644 index fca08fc0d..000000000 --- a/nuttx/lib/stdio/lib_fileno.c +++ /dev/null @@ -1,70 +0,0 @@ -/**************************************************************************** - * lib/stdio/lib_fileno.c - * - * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include - -#include - -#if CONFIG_NFILE_STREAMS > 0 - -/**************************************************************************** - * Global Functions - ****************************************************************************/ - -int fileno(FAR FILE *stream) -{ - int ret = -1; - if (stream) - { - ret = stream->fs_filedes; - } - - if (ret < 0) - { - set_errno(EBADF); - return ERROR; - } - - return ret; -} -#endif /* CONFIG_NFILE_STREAMS */ - diff --git a/nuttx/lib/stdio/lib_fopen.c b/nuttx/lib/stdio/lib_fopen.c deleted file mode 100644 index 29ff4569c..000000000 --- a/nuttx/lib/stdio/lib_fopen.c +++ /dev/null @@ -1,299 +0,0 @@ -/**************************************************************************** - * lib/stdio/lib_fopen.c - * - * Copyright (C) 2007-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include -#include -#include -#include -#include - -#include "lib_internal.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -enum open_mode_e -{ - MODE_NONE = 0, /* No access mode determined */ - MODE_R, /* "r" or "rb" open for reading */ - MODE_W, /* "w" or "wb" open for writing, truncating or creating file */ - MODE_A, /* "a" or "ab" open for writing, appending to file */ - MODE_RPLUS, /* "r+", "rb+", or "r+b" open for update (reading and writing) */ - MODE_WPLUS, /* "w+", "wb+", or "w+b" open for update, truncating or creating file */ - MODE_APLUS /* "a+", "ab+", or "a+b" open for update, appending to file */ -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: lib_mode2oflags - ****************************************************************************/ - -static int lib_mode2oflags(FAR const char *mode) -{ - enum open_mode_e state; - int oflags; - - /* Verify that a mode string was provided. No error is */ - - if (!mode) - { - goto errout; - } - - /* Parse the mode string to determine the corresponding open flags */ - - state = MODE_NONE; - oflags = 0; - - for (; *mode; mode++) - { - switch (*mode) - { - /* Open for read access ("r", "r[+]", "r[b]", "r[b+]", or "r[+b]") */ - - case 'r' : - if (state == MODE_NONE) - { - /* Open for read access */ - - oflags = O_RDOK; - state = MODE_R; - } - else - { - goto errout; - } - break; - - /* Open for write access ("w", "w[+]", "w[b]", "w[b+]", or "w[+b]") */ - - case 'w' : - if (state == MODE_NONE) - { - /* Open for write access, truncating any existing file */ - - oflags = O_WROK|O_CREAT|O_TRUNC; - state = MODE_W; - } - else - { - goto errout; - } - break; - - /* Open for write/append access ("a", "a[+]", "a[b]", "a[b+]", or "a[+b]") */ - - case 'a' : - if (state == MODE_NONE) - { - /* Write to the end of the file */ - - oflags = O_WROK|O_CREAT|O_APPEND; - state = MODE_A; - } - else - { - goto errout; - } - break; - - /* Open for update access ("[r]+", "[rb]+]", "[r]+[b]", "[w]+", - * "[wb]+]", "[w]+[b]", "[a]+", "[ab]+]", "[a]+[b]") - */ - - case '+' : - switch (state) - { - case MODE_R: - { - /* Retain any binary mode selection */ - - oflags &= O_BINARY; - - /* Open for read/write access */ - - oflags |= O_RDWR; - state = MODE_RPLUS; - } - break; - - case MODE_W: - { - /* Retain any binary mode selection */ - - oflags &= O_BINARY; - - /* Open for write read/access, truncating any existing file */ - - oflags |= O_RDWR|O_CREAT|O_TRUNC; - state = MODE_WPLUS; - } - break; - - case MODE_A: - { - /* Retain any binary mode selection */ - - oflags &= O_BINARY; - - /* Read from the beginning of the file; write to the end */ - - oflags |= O_RDWR|O_CREAT|O_APPEND; - state = MODE_APLUS; - } - break; - - default: - goto errout; - break; - } - break; - - /* Open for binary access ("[r]b", "[r]b[+]", "[r+]b", "[w]b", - * "[w]b[+]", "[w+]b", "[a]b", "[a]b[+]", "[a+]b") - */ - - case 'b' : - if (state != MODE_NONE) - { - /* The file is opened in binary mode */ - - oflags |= O_BINARY; - } - else - { - goto errout; - } - break; - - /* Unrecognized or unsupported mode */ - - default: - goto errout; - break; - } - } - - return oflags; - -/* Both fopen and fdopen should fail with errno == EINVAL if the mode - * string is invalid. - */ - -errout: - set_errno(EINVAL); - return ERROR; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: fdopen - ****************************************************************************/ - -FAR FILE *fdopen(int fd, FAR const char *mode) -{ - FAR FILE *ret = NULL; - int oflags; - - /* Map the open mode string to open flags */ - - oflags = lib_mode2oflags(mode); - if (oflags >= 0) - { - ret = fs_fdopen(fd, oflags, NULL); - } - - return ret; -} - -/**************************************************************************** - * Name: fopen - ****************************************************************************/ - -FAR FILE *fopen(FAR const char *path, FAR const char *mode) -{ - FAR FILE *ret = NULL; - int oflags; - int fd; - - /* Map the open mode string to open flags */ - - oflags = lib_mode2oflags(mode); - if (oflags < 0) - { - return NULL; - } - - /* Open the file */ - - fd = open(path, oflags, 0666); - - /* If the open was successful, then fdopen() the fil using the file - * desciptor returned by open. If open failed, then just return the - * NULL stream -- open() has already set the errno. - */ - - if (fd >= 0) - { - ret = fs_fdopen(fd, oflags, NULL); - if (!ret) - { - /* Don't forget to close the file descriptor if any other - * failures are reported by fdopen(). - */ - - (void)close(fd); - } - } - return ret; -} diff --git a/nuttx/lib/stdio/lib_fprintf.c b/nuttx/lib/stdio/lib_fprintf.c deleted file mode 100644 index a803de4bd..000000000 --- a/nuttx/lib/stdio/lib_fprintf.c +++ /dev/null @@ -1,93 +0,0 @@ -/**************************************************************************** - * lib/stdio/lib_fprintf.c - * - * Copyright (C) 2007, 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Compilation Switches - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Global Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: fprintf - ****************************************************************************/ - -int fprintf(FAR FILE *stream, FAR const char *fmt, ...) -{ - va_list ap; - int n; - - /* vfprintf into the stream */ - - va_start(ap, fmt); - n = vfprintf(stream, fmt, ap); - va_end(ap); - return n; -} diff --git a/nuttx/lib/stdio/lib_fputc.c b/nuttx/lib/stdio/lib_fputc.c deleted file mode 100644 index 121161f10..000000000 --- a/nuttx/lib/stdio/lib_fputc.c +++ /dev/null @@ -1,113 +0,0 @@ -/**************************************************************************** - * lib/stdio/lib_fputc.c - * - * Copyright (C) 2007, 2008, 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Compilation Switches - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include "lib_internal.h" - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Global Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Global Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Global Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: fputc - ****************************************************************************/ - -int fputc(int c, FAR FILE *stream) -{ - unsigned char buf = (unsigned char)c; - int ret; - - ret = lib_fwrite(&buf, 1, stream); - if (ret > 0) - { - /* Flush the buffer if a newline is output */ - -#ifdef CONFIG_STDIO_LINEBUFFER - if (c == '\n') - { - ret = lib_fflush(stream, true); - if (ret < 0) - { - return EOF; - } - } -#endif - return c; - } - else - { - return EOF; - } -} diff --git a/nuttx/lib/stdio/lib_fputs.c b/nuttx/lib/stdio/lib_fputs.c deleted file mode 100644 index 2d6217d4a..000000000 --- a/nuttx/lib/stdio/lib_fputs.c +++ /dev/null @@ -1,220 +0,0 @@ -/**************************************************************************** - * lib/stdio/lib_fputs.c - * - * Copyright (C) 2007, 2008, 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Compilation Switches - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include - -#include - -#include "lib_internal.h" - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Global Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Global Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: fputs - * - * Description: - * fputs() writes the string s to stream, without its trailing '\0'. - * - ****************************************************************************/ - -#if defined(CONFIG_ARCH_ROMGETC) -int fputs(FAR const char *s, FAR FILE *stream) -{ - int nput; - int ret; - char ch; - - /* Make sure that a string was provided. */ - -#ifdef CONFIG_DEBUG /* Most parameter checking is disabled if DEBUG is off */ - if (!s) - { - set_errno(EINVAL); - return EOF; - } -#endif - - /* Write the string. Loop until the null terminator is encountered */ - - for (nput = 0, ch = up_romgetc(s); ch; nput++, s++, ch = up_romgetc(s)) - { - /* Write the next character to the stream buffer */ - - ret = lib_fwrite(&ch, 1, stream); - if (ret <= 0) - { - return EOF; - } - - /* Flush the buffer if a newline was written to the buffer */ - -#ifdef CONFIG_STDIO_LINEBUFFER - if (ch == '\n') - { - ret = lib_fflush(stream, true); - if (ret < 0) - { - return EOF; - } - } -#endif - } - - return nput; -} - -#elif defined(CONFIG_STDIO_LINEBUFFER) -int fputs(FAR const char *s, FAR FILE *stream) -{ - int nput; - int ret; - - /* Make sure that a string was provided. */ - -#ifdef CONFIG_DEBUG /* Most parameter checking is disabled if DEBUG is off */ - if (!s) - { - set_errno(EINVAL); - return EOF; - } -#endif - - /* Write the string. Loop until the null terminator is encountered */ - - for (nput = 0; *s; nput++, s++) - { - /* Write the next character to the stream buffer */ - - ret = lib_fwrite(s, 1, stream); - if (ret <= 0) - { - return EOF; - } - - /* Flush the buffer if a newline was written to the buffer */ - - if (*s == '\n') - { - ret = lib_fflush(stream, true); - if (ret < 0) - { - return EOF; - } - } - } - - return nput; -} - -#else -int fputs(FAR const char *s, FAR FILE *stream) -{ - int ntowrite; - int nput; - - /* Make sure that a string was provided. */ - -#ifdef CONFIG_DEBUG /* Most parameter checking is disabled if DEBUG is off */ - if (!s) - { - set_errno(EINVAL); - return EOF; - } -#endif - - /* Get the length of the string. */ - - ntowrite = strlen(s); - if (ntowrite == 0) - { - return 0; - } - - /* Write the string */ - - nput = lib_fwrite(s, ntowrite, stream); - if (nput < 0) - { - return EOF; - } - return nput; -} -#endif diff --git a/nuttx/lib/stdio/lib_fread.c b/nuttx/lib/stdio/lib_fread.c deleted file mode 100644 index 4a4b29256..000000000 --- a/nuttx/lib/stdio/lib_fread.c +++ /dev/null @@ -1,101 +0,0 @@ -/**************************************************************************** - * lib/stdio/lib_fread.c - * - * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include - -#include "lib_internal.h" - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Global Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: fread - ****************************************************************************/ - -size_t fread(FAR void *ptr, size_t size, size_t n_items, FAR FILE *stream) -{ - size_t full_size = n_items * (size_t)size; - ssize_t bytes_read; - size_t items_read = 0; - - /* Write the data into the stream buffer */ - - bytes_read = lib_fread(ptr, full_size, stream); - if (bytes_read > 0) - { - /* Return the number of full items read */ - - items_read = bytes_read / size; - } - return items_read; -} - - diff --git a/nuttx/lib/stdio/lib_fseek.c b/nuttx/lib/stdio/lib_fseek.c deleted file mode 100644 index 7380f83b3..000000000 --- a/nuttx/lib/stdio/lib_fseek.c +++ /dev/null @@ -1,138 +0,0 @@ -/**************************************************************************** - * lib/stdio/lib_fseek.c - * - * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Compilation Switches - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include -#include - -#include "lib_internal.h" - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Global Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: fseek - * - * Description: - * The fseek() function sets the file position indicator for the stream - * pointed to by stream. The new position, measured in bytes, is obtained - * by adding offset bytes to the position specified by whence. If whence is - * set to SEEK_SET, SEEK_CUR, or SEEK_END, the offset is relative to the - * start of the file, the current position indicator, or end-of-file, - * respectively. A successful call to the fseek() function clears the - * end-of-file indicator for the stream and undoes any effects of the ungetc(3) - * function on the same stream. - * - * Returned Value: - * Zero on succes; -1 on failure with errno set appropriately. - * - ****************************************************************************/ - -int fseek(FAR FILE *stream, long int offset, int whence) -{ - #if CONFIG_STDIO_BUFFER_SIZE > 0 - /* Flush any valid read/write data in the buffer (also verifies stream) */ - - if (lib_rdflush(stream) < 0 || lib_wrflush(stream) < 0) - { - return ERROR; - } -#else - /* Verify that we were provided with a stream */ - - if (!stream) - { - set_errno(EBADF); - return ERROR; - } -#endif - - /* On success or failure, discard any characters saved by ungetc() */ - -#if CONFIG_NUNGET_CHARS > 0 - stream->fs_nungotten = 0; -#endif - - /* Perform the fseek on the underlying file descriptor */ - - return lseek(stream->fs_filedes, offset, whence) == (off_t)-1 ? ERROR : OK; -} - - diff --git a/nuttx/lib/stdio/lib_fsetpos.c b/nuttx/lib/stdio/lib_fsetpos.c deleted file mode 100644 index 13d556521..000000000 --- a/nuttx/lib/stdio/lib_fsetpos.c +++ /dev/null @@ -1,116 +0,0 @@ -/**************************************************************************** - * lib/stdio/lib_fsetpos.c - * - * Copyright (C) 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Compilation Switches - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include -#include - -#include "lib_internal.h" - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Global Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: fsetpos - * - * Description: - * fsetpos() function is an alternate interfaces equivalent to fseek() - * (with whence set to SEEK_SET). It sets the current value of the file - * offset to value in the location referenced by pos. On some non-UNIX - * systems an fpos_t object may be a complex object and fsetpos may be the - * only way to portably reposition a stream. - * - * Returned Value: - * Zero on succes; -1 on failure with errno set appropriately. - * - ****************************************************************************/ - -int fsetpos(FAR FILE *stream, FAR fpos_t *pos) -{ -#if CONFIG_DEBUG - if (!stream || !pos) - { - set_errno(EINVAL); - return ERROR; - } -#endif - - return fseek(stream, (FAR off_t)*pos, SEEK_SET); -} diff --git a/nuttx/lib/stdio/lib_ftell.c b/nuttx/lib/stdio/lib_ftell.c deleted file mode 100644 index 947648152..000000000 --- a/nuttx/lib/stdio/lib_ftell.c +++ /dev/null @@ -1,129 +0,0 @@ -/**************************************************************************** - * lib/stdio/lib_ftell.c - * - * Copyright (C) 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Compilation Switches - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include -#include - -#include "lib_internal.h" - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Global Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: ftell - * - * Description: - * ftell() returns the current value of the file position indicator for the - * stream pointed to by stream. - * - * Returned Value: - * Zero on succes; -1 on failure with errno set appropriately. - * - ****************************************************************************/ - -long ftell(FAR FILE *stream) -{ - off_t position; - - /* Verify that we were provided with a stream */ - - if (!stream) - { - set_errno(EBADF); - return ERROR; - } - - /* Perform the lseek to the current position. This will not move the - * file pointer, but will return its current setting - */ - - position = lseek(stream->fs_filedes, 0, SEEK_CUR); - if (position != (off_t)-1) - { - return (long)position; - } - else - { - return ERROR; - } -} - - diff --git a/nuttx/lib/stdio/lib_fwrite.c b/nuttx/lib/stdio/lib_fwrite.c deleted file mode 100644 index 60e001746..000000000 --- a/nuttx/lib/stdio/lib_fwrite.c +++ /dev/null @@ -1,99 +0,0 @@ -/**************************************************************************** - * lib/stdio/lib_fwrite.c - * - * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include - -#include "lib_internal.h" - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Global Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: fwrite - ****************************************************************************/ - -size_t fwrite(FAR const void *ptr, size_t size, size_t n_items, FAR FILE *stream) -{ - size_t full_size = n_items * (size_t)size; - ssize_t bytes_written; - size_t items_written = 0; - - /* Write the data into the stream buffer */ - - bytes_written = lib_fwrite(ptr, full_size, stream); - if (bytes_written > 0) - { - /* Return the number of full items written */ - - items_written = bytes_written / size; - } - return items_written; -} diff --git a/nuttx/lib/stdio/lib_gets.c b/nuttx/lib/stdio/lib_gets.c deleted file mode 100644 index 95a6b36eb..000000000 --- a/nuttx/lib/stdio/lib_gets.c +++ /dev/null @@ -1,120 +0,0 @@ -/**************************************************************************** - * lib/stdio/lib_gets.c - * - * Copyright (C) 2007-2008, 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 -#include -#include - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Global Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Global Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: gets - * - * Description: - * gets() reads a line from stdin into the buffer pointed to by s until - * either a terminating newline or EOF, which it replaces with '\0'. No - * check for buffer overrun is performed - * - * This API should not be used because it is inherently unsafe. Consider - * using fgets which is safer and slightly more efficient. - * - **************************************************************************/ - -FAR char *gets(FAR char *s) -{ - /* gets is ALMOST the same as fgets using stdin and no length limit - * (hence, the unsafeness of gets). So let fgets do most of the work. - */ - - FAR char *ret = fgets(s, INT_MAX, stdin); - if (ret) - { - /* Another subtle difference from fgets is that gets replaces - * end-of-line markers with null terminators. We will do that as - * a second step (with some loss in performance). - */ - - int len = strlen(ret); - if (len > 0 && ret[len-1] == '\n') - { - ret[len-1] = '\0'; - } - } - - return ret; -} - diff --git a/nuttx/lib/stdio/lib_libdtoa.c b/nuttx/lib/stdio/lib_libdtoa.c deleted file mode 100644 index 667c49c53..000000000 --- a/nuttx/lib/stdio/lib_libdtoa.c +++ /dev/null @@ -1,304 +0,0 @@ -/**************************************************************************** - * lib/unistd/lib_libdtoa.c - * - * This file was ported to NuttX by Yolande Cates. - * - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University 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 REGENTS 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 REGENTS 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 - ****************************************************************************/ - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define MAX_PREC 16 - -#ifndef MIN -# define MIN(a,b) (a < b ? a : b) -#endif - -#ifndef MAX -# define MAX(a,b) (a > b ? a : b) -#endif - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Global Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Name: zeroes - * - * Description: - * Print the specified number of zeres - * - ****************************************************************************/ - -static void zeroes(FAR struct lib_outstream_s *obj, int nzeroes) -{ - int i; - - for (i = nzeroes; i > 0; i--) - { - obj->put(obj, '0'); - } -} - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: lib_dtoa - * - * Description: - * This is part of lib_vsprintf(). It handles the floating point formats. - * This version supports only the %f (with precision). If no precision - * was provided in the format, this will use precision == 0 which is - * probably not what you want. - * - * Input Parameters: - * obj - The output stream object - * fmt - The format character. Not used 'f' is always assumed - * prec - The number of digits to the right of the decimal point. If no - * precision is provided in the format, this will be zero. And, - * unfortunately in this case, it will be treated literally as - * a precision of zero. - * flags - Only ALTFORM and SHOWPLUS flags are supported. ALTFORM only - * applies if prec == 0 which is not supported anyway. - * value - The floating point value to convert. - * - ****************************************************************************/ - -static void lib_dtoa(FAR struct lib_outstream_s *obj, int fmt, int prec, - uint8_t flags, double value) -{ - FAR char *digits; /* String returned by __dtoa */ - FAR char *digalloc; /* Copy of digits to be freed after usage */ - FAR char *rve; /* Points to the end of the return value */ - int expt; /* Integer value of exponent */ - int numlen; /* Actual number of digits returned by cvt */ - int nchars; /* Number of characters to print */ - int dsgn; /* Unused sign indicator */ - int i; - - /* Non-zero... positive or negative */ - - if (value < 0) - { - value = -value; - SET_NEGATE(flags); - } - - /* Perform the conversion */ - - digits = __dtoa(value, 3, prec, &expt, &dsgn, &rve); - digalloc = digits; - numlen = rve - digits; - - if (IS_NEGATE(flags)) - { - obj->put(obj, '-'); - } - else if (IS_SHOWPLUS(flags)) - { - obj->put(obj, '+'); - } - - /* Special case exact zero or the case where the number is smaller than - * the print precision. - */ - - if (value == 0 || expt < -prec) - { - /* kludge for __dtoa irregularity */ - - obj->put(obj, '0'); - - /* A decimal point is printed only in the alternate form or if a - * particular precision is requested. - */ - - if (prec > 0 || IS_ALTFORM(flags)) - { - obj->put(obj, '.'); - - /* Always print at least one digit to the right of the decimal point. */ - - prec = MAX(1, prec); - } - } - - /* A non-zero value will be printed */ - - else - { - - /* Handle the case where the value is less than 1.0 (in magnitude) and - * will need a leading zero. - */ - - if (expt <= 0) - { - /* Print a single zero to the left of the decimal point */ - - obj->put(obj, '0'); - - /* Print the decimal point */ - - obj->put(obj, '.'); - - /* Print any leading zeros to the right of the decimal point */ - - if (expt < 0) - { - nchars = MIN(-expt, prec); - zeroes(obj, nchars); - prec -= nchars; - } - } - - /* Handle the general case where the value is greater than 1.0 (in - * magnitude). - */ - - else - { - /* Print the integer part to the left of the decimal point */ - - for (i = expt; i > 0; i--) - { - if (*digits != '\0') - { - obj->put(obj, *digits); - digits++; - } - else - { - obj->put(obj, '0'); - } - } - - /* Get the length of the fractional part */ - - numlen -= expt; - - /* If there is no fractional part, then a decimal point is printed - * only in the alternate form or if a particular precision is - * requested. - */ - - if (numlen > 0 || prec > 0 || IS_ALTFORM(flags)) - { - /* Print the decimal point */ - - obj->put(obj, '.'); - - /* Always print at least one digit to the right of the decimal - * point. - */ - - prec = MAX(1, prec); - } - } - - /* If a precision was specified, then limit the number digits to the - * right of the decimal point. - */ - - if (prec > 0) - { - nchars = MIN(numlen, prec); - } - else - { - nchars = numlen; - } - - /* Print the fractional part to the right of the decimal point */ - - for (i = nchars; i > 0; i--) - { - obj->put(obj, *digits); - digits++; - } - - /* Decremnt to get the number of trailing zeroes to print */ - - prec -= nchars; - } - - /* Finally, print any trailing zeroes */ - - zeroes(obj, prec); - - /* Is this memory supposed to be freed or not? */ - -#if 0 - if (digalloc) - { - free(digalloc); - } -#endif -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - diff --git a/nuttx/lib/stdio/lib_libfflush.c b/nuttx/lib/stdio/lib_libfflush.c deleted file mode 100644 index 2a4fe2932..000000000 --- a/nuttx/lib/stdio/lib_libfflush.c +++ /dev/null @@ -1,202 +0,0 @@ -/**************************************************************************** - * lib/stdio/lib_libfflush.c - * - * Copyright (C) 2007-2008, 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Compilation Switches - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include -#include - -#include - -#include "lib_internal.h" - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Global Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: lib_fflush - * - * Description: - * The function lib_fflush() forces a write of all user-space buffered data for - * the given output or update stream via the stream's underlying write - * function. The open status of the stream is unaffected. - * - * Parmeters: - * stream - the stream to flush - * bforce - flush must be complete. - * - * Return: - * A negated errno value on failure, otherwise the number of bytes remaining - * in the buffer. - * - ****************************************************************************/ - -ssize_t lib_fflush(FAR FILE *stream, bool bforce) -{ -#if CONFIG_STDIO_BUFFER_SIZE > 0 - FAR const unsigned char *src; - ssize_t bytes_written; - ssize_t nbuffer; - - /* Return EBADF if the file is not opened for writing */ - - if (stream->fs_filedes < 0 || (stream->fs_oflags & O_WROK) == 0) - { - return -EBADF; - } - - /* Make sure that we have exclusive access to the stream */ - - lib_take_semaphore(stream); - - /* Make sure that the buffer holds valid data */ - - if (stream->fs_bufpos != stream->fs_bufstart) - { - /* Make sure that the buffer holds buffered write data. We do not - * support concurrent read/write buffer usage. - */ - - if (stream->fs_bufread != stream->fs_bufstart) - { - /* The buffer holds read data... just return zero meaning "no bytes - * remaining in the buffer." - */ - - lib_give_semaphore(stream); - return 0; - } - - /* How many bytes of write data are used in the buffer now */ - - nbuffer = stream->fs_bufpos - stream->fs_bufstart; - - /* Try to write that amount */ - - src = stream->fs_bufstart; - do - { - /* Perform the write */ - - bytes_written = write(stream->fs_filedes, src, nbuffer); - if (bytes_written < 0) - { - /* Write failed. The cause of the failure is in 'errno'. - * returned the negated errno value. - */ - - lib_give_semaphore(stream); - return -get_errno(); - } - - /* Handle partial writes. fflush() must either return with - * an error condition or with the data successfully flushed - * from the buffer. - */ - - src += bytes_written; - nbuffer -= bytes_written; - } - while (bforce && nbuffer > 0); - - /* Reset the buffer position to the beginning of the buffer */ - - stream->fs_bufpos = stream->fs_bufstart; - - /* For the case of an incomplete write, nbuffer will be non-zero - * It will hold the number of bytes that were not written. - * Move the data down in the buffer to handle this (rare) case - */ - - while (nbuffer) - { - *stream->fs_bufpos++ = *src++; - --nbuffer; - } - } - - /* Restore normal access to the stream and return the number of bytes - * remaining in the buffer. - */ - - lib_give_semaphore(stream); - return stream->fs_bufpos - stream->fs_bufstart; -#else - /* Return no bytes remaining in the buffer */ - - return 0; -#endif -} - diff --git a/nuttx/lib/stdio/lib_libflushall.c b/nuttx/lib/stdio/lib_libflushall.c deleted file mode 100644 index 9d0a89e9c..000000000 --- a/nuttx/lib/stdio/lib_libflushall.c +++ /dev/null @@ -1,137 +0,0 @@ -/**************************************************************************** - * lib/stdio/lib_libflushall.c - * - * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include -#include - -#include - -#include "lib_internal.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Global Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Global Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: lib_flushall - * - * Description: - * Called either (1) by the OS when a task exits, or (2) from fflush() - * when a NULL stream argument is provided. - * - ****************************************************************************/ - -int lib_flushall(FAR struct streamlist *list) -{ - int lasterrno = OK; - int ret; - - /* Make sure that there are streams associated with this thread */ - - if (list) - { - int i; - - /* Process each stream in the thread's stream list */ - - stream_semtake(list); - for (i = 0; i < CONFIG_NFILE_STREAMS; i++) - { - FILE *stream = &list->sl_streams[i]; - - /* If the stream is open (i.e., assigned a non-negative file - * descriptor) and opened for writing, then flush all of the pending - * write data in the stream. - */ - - if (stream->fs_filedes >= 0 && (stream->fs_oflags & O_WROK) != 0) - { - /* Flush the writable FILE */ - - ret = lib_fflush(stream, true); - if (ret < 0) - { - /* An error occurred during the flush AND/OR we were unable - * to flush all of the buffered write data. Remember the - * last errcode. - */ - - lasterrno = ret; - } - } - } - - stream_semgive(list); - } - - /* If any flush failed, return the errorcode of the last failed flush */ - - return lasterrno; -} diff --git a/nuttx/lib/stdio/lib_libfread.c b/nuttx/lib/stdio/lib_libfread.c deleted file mode 100644 index 03b47eda6..000000000 --- a/nuttx/lib/stdio/lib_libfread.c +++ /dev/null @@ -1,290 +0,0 @@ -/**************************************************************************** - * lib/stdio/lib_libfread.c - * - * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 /* for CONFIG_STDIO_BUFFER_SIZE */ - -#include -#include -#include -#include -#include -#include - -#include "lib_internal.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Global Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: lib_fread - ****************************************************************************/ - -ssize_t lib_fread(FAR void *ptr, size_t count, FAR FILE *stream) -{ - unsigned char *dest = (unsigned char*)ptr; - ssize_t bytes_read; - int ret; - - /* Make sure that reading from this stream is allowed */ - - if (!stream || (stream->fs_oflags & O_RDOK) == 0) - { - set_errno(EBADF); - bytes_read = -1; - } - else - { - /* The stream must be stable until we complete the read */ - - lib_take_semaphore(stream); - -#if CONFIG_NUNGET_CHARS > 0 - /* First, re-read any previously ungotten characters */ - - while ((stream->fs_nungotten > 0) && (count > 0)) - { - /* Decrement the count of ungotten bytes to get an index */ - - stream->fs_nungotten--; - - /* Return the last ungotten byte */ - - *dest++ = stream->fs_ungotten[stream->fs_nungotten]; - - /* That's one less byte that we have to read */ - - count--; - } -#endif - -#if CONFIG_STDIO_BUFFER_SIZE > 0 - /* If the buffer is currently being used for write access, then - * flush all of the buffered write data. We do not support concurrent - * buffered read/write access. - */ - - ret = lib_wrflush(stream); - if (ret < 0) - { - lib_give_semaphore(stream); - return ret; - } - - /* Now get any other needed chars from the buffer or the file. */ - - while (count > 0) - { - /* Is there readable data in the buffer? */ - - while ((count > 0) && (stream->fs_bufpos < stream->fs_bufread)) - { - /* Yes, copy a byte into the user buffer */ - - *dest++ = *stream->fs_bufpos++; - count--; - } - - /* The buffer is empty OR we have already supplied the number of - * bytes requested in the read. Check if we need to read - * more from the file. - */ - - if (count > 0) - { - size_t buffer_available; - - /* We need to read more data into the buffer from the file */ - - /* Mark the buffer empty */ - - stream->fs_bufpos = stream->fs_bufread = stream->fs_bufstart; - - /* How much space is available in the buffer? */ - - buffer_available = stream->fs_bufend - stream->fs_bufread; - - /* Will the number of bytes that we need to read fit into - * the buffer space that is available? If the read size is - * larger than the buffer, then read some of the data - * directly into the user's buffer. - */ - - if (count > buffer_available) - { - bytes_read = read(stream->fs_filedes, dest, count); - if (bytes_read < 0) - { - /* An error occurred on the read. The error code is - * in the 'errno' variable. - */ - - goto errout_with_errno; - } - else if (bytes_read == 0) - { - /* We are at the end of the file */ - - goto shortread; - } - else - { - /* Some bytes were read. Adjust the dest pointer */ - - dest += bytes_read; - - /* Were all of the requested bytes read? */ - - if (bytes_read < count) - { - /* No. We must be at the end of file. */ - - goto shortread; - } - else - { - /* Yes. We are done. */ - - count = 0; - } - } - } - else - { - /* The number of bytes required to satisfy the read - * is less than or equal to the size of the buffer - * space that we have left. Read as much as we can - * into the buffer. - */ - - bytes_read = read(stream->fs_filedes, stream->fs_bufread, buffer_available); - if (bytes_read < 0) - { - /* An error occurred on the read. The error code is - * in the 'errno' variable. - */ - - goto errout_with_errno; - } - else if (bytes_read == 0) - { - /* We are at the end of the file */ - - goto shortread; - } - else - { - /* Some bytes were read */ - - stream->fs_bufread += bytes_read; - } - } - } - } -#else - /* Now get any other needed chars from the file. */ - - while (count > 0) - { - bytes_read = read(stream->fs_filedes, dest, count); - if (bytes_read < 0) - { - /* An error occurred on the read. The error code is - * in the 'errno' variable. - */ - - goto errout_with_errno; - } - else if (bytes_read == 0) - { - break; - } - else - { - dest += bytes_read; - count -= bytes_read; - } - } -#endif - /* Here after a successful (but perhaps short) read */ - -#if CONFIG_STDIO_BUFFER_SIZE > 0 - shortread: -#endif - bytes_read = dest - (unsigned char*)ptr; - } - - lib_give_semaphore(stream); - return bytes_read; - -/* Error exits */ - -errout_with_errno: - lib_give_semaphore(stream); - return -get_errno(); -} - diff --git a/nuttx/lib/stdio/lib_libfwrite.c b/nuttx/lib/stdio/lib_libfwrite.c deleted file mode 100644 index e71866b49..000000000 --- a/nuttx/lib/stdio/lib_libfwrite.c +++ /dev/null @@ -1,179 +0,0 @@ -/**************************************************************************** - * lib/stdio/lib_libfwrite.c - * - * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 /* for CONFIG_STDIO_BUFFER_SIZE */ - -#include -#include -#include -#include -#include -#include - -#include "lib_internal.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Global Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: lib_fwrite - ****************************************************************************/ - -ssize_t lib_fwrite(FAR const void *ptr, size_t count, FAR FILE *stream) -#if CONFIG_STDIO_BUFFER_SIZE > 0 -{ - FAR const unsigned char *start = ptr; - FAR const unsigned char *src = ptr; - ssize_t ret = ERROR; - unsigned char *dest; - - /* Make sure that writing to this stream is allowed */ - - if (!stream || (stream->fs_oflags & O_WROK) == 0) - { - set_errno(EBADF); - goto errout; - } - - /* Get exclusive access to the stream */ - - lib_take_semaphore(stream); - - /* If the buffer is currently being used for read access, then - * discard all of the read-ahead data. We do not support concurrent - * buffered read/write access. - */ - - if (lib_rdflush(stream) < 0) - { - goto errout_with_semaphore; - } - - /* Loop until all of the bytes have been buffered */ - - while (count > 0) - { - /* Determine the number of bytes left in the buffer */ - - size_t gulp_size = stream->fs_bufend - stream->fs_bufpos; - - /* Will the user data fit into the amount of buffer space - * that we have left? - */ - - if (gulp_size > count) - { - /* Yes, clip the gulp to the size of the user data */ - - gulp_size = count; - } - - /* Adjust the number of bytes remaining to be transferred - * on the next pass through the loop (might be zero). - */ - - count -= gulp_size; - - /* Transfer the data into the buffer */ - - for (dest = stream->fs_bufpos; gulp_size > 0; gulp_size--) - { - *dest++ = *src++; - } - stream->fs_bufpos = dest; - - /* Is the buffer full? */ - - if (dest >= stream->fs_bufend) - { - /* Flush the buffered data to the IO stream */ - - int bytes_buffered = lib_fflush(stream, false); - if (bytes_buffered < 0) - { - goto errout_with_semaphore; - } - } - } - - /* Return the number of bytes written */ - - ret = src - start; - -errout_with_semaphore: - lib_give_semaphore(stream); - -errout: - return ret; -} -#else -{ - return write(stream->fs_filedes, ptr, count); -} -#endif /* CONFIG_STDIO_BUFFER_SIZE */ - diff --git a/nuttx/lib/stdio/lib_libnoflush.c b/nuttx/lib/stdio/lib_libnoflush.c deleted file mode 100644 index e3b891153..000000000 --- a/nuttx/lib/stdio/lib_libnoflush.c +++ /dev/null @@ -1,103 +0,0 @@ -/**************************************************************************** - * lib/stdio/lib_libnoflush.c - * - * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include -#include -#include - -#include - -#include "lib_internal.h" - -#ifdef CONFIG_STDIO_LINEBUFFER - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Global Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Global Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: lib_noflush - * - * Description: - * lib_noflush() provides a common, dummy flush method for output streams - * that are not flushable. Only used if CONFIG_STDIO_LINEBUFFER is selected. - * - * Return: - * Always returns OK - * - ****************************************************************************/ - -int lib_noflush(FAR struct lib_outstream_s *this) -{ - return OK; -} - -#endif /* CONFIG_STDIO_LINEBUFFER */ - diff --git a/nuttx/lib/stdio/lib_libsprintf.c b/nuttx/lib/stdio/lib_libsprintf.c deleted file mode 100644 index 2474a6f01..000000000 --- a/nuttx/lib/stdio/lib_libsprintf.c +++ /dev/null @@ -1,90 +0,0 @@ -/**************************************************************************** - * lib/stdio/lib_libsprintf.c - * - * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 -#include "lib_internal.h" - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Global Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: lib_sprintf - ****************************************************************************/ - -int lib_sprintf(FAR struct lib_outstream_s *obj, const char *fmt, ...) -{ - va_list ap; - int n; - - /* Let lib_vsprintf do the real work */ - - va_start(ap, fmt); - n = lib_vsprintf(obj, fmt, ap); - va_end(ap); - return n; -} diff --git a/nuttx/lib/stdio/lib_libvsprintf.c b/nuttx/lib/stdio/lib_libvsprintf.c deleted file mode 100644 index 30c988599..000000000 --- a/nuttx/lib/stdio/lib_libvsprintf.c +++ /dev/null @@ -1,1620 +0,0 @@ -/**************************************************************************** - * lib/stdio/lib_libvsprintf.c - * - * Copyright (C) 2007-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include -#include -#include - -#include - -#include "lib_internal.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ -/* If you have floating point but no fieldwidth, then use a fixed (but - * configurable) floating point precision. - */ - -#if defined(CONFIG_LIBC_FLOATINGPOINT) && \ - defined(CONFIG_NOPRINTF_FIELDWIDTH) && \ - !defined(CONFIG_LIBC_FIXEDPRECISION) -# define CONFIG_LIBC_FIXEDPRECISION 3 -#endif - -#define FLAG_SHOWPLUS 0x01 -#define FLAG_ALTFORM 0x02 -#define FLAG_HASDOT 0x04 -#define FLAG_HASASTERISKWIDTH 0x08 -#define FLAG_HASASTERISKTRUNC 0x10 -#define FLAG_LONGPRECISION 0x20 -#define FLAG_LONGLONGPRECISION 0x40 -#define FLAG_NEGATE 0x80 - -#define SET_SHOWPLUS(f) do (f) |= FLAG_SHOWPLUS; while (0) -#define SET_ALTFORM(f) do (f) |= FLAG_ALTFORM; while (0) -#define SET_HASDOT(f) do (f) |= FLAG_HASDOT; while (0) -#define SET_HASASTERISKWIDTH(f) do (f) |= FLAG_HASASTERISKWIDTH; while (0) -#define SET_HASASTERISKTRUNC(f) do (f) |= FLAG_HASASTERISKTRUNC; while (0) -#define SET_LONGPRECISION(f) do (f) |= FLAG_LONGPRECISION; while (0) -#define SET_LONGLONGPRECISION(f) do (f) |= FLAG_LONGLONGPRECISION; while (0) -#define SET_NEGATE(f) do (f) |= FLAG_NEGATE; while (0) - -#define CLR_SHOWPLUS(f) do (f) &= ~FLAG_SHOWPLUS; while (0) -#define CLR_ALTFORM(f) do (f) &= ~FLAG_ALTFORM; while (0) -#define CLR_HASDOT(f) do (f) &= ~FLAG_HASDOT; while (0) -#define CLR_HASASTERISKWIDTH(f) do (f) &= ~FLAG_HASASTERISKWIDTH; while (0) -#define CLR_HASASTERISKTRUNC(f) do (f) &= ~FLAG_HASASTERISKTRUNC; while (0) -#define CLR_LONGPRECISION(f) do (f) &= ~FLAG_LONGPRECISION; while (0) -#define CLR_LONGLONGPRECISION(f) do (f) &= ~FLAG_LONGLONGPRECISION; while (0) -#define CLR_NEGATE(f) do (f) &= ~FLAG_NEGATE; while (0) -#define CLR_SIGNED(f) do (f) &= ~(FLAG_SHOWPLUS|FLAG_NEGATE); while (0) - -#define IS_SHOWPLUS(f) (((f) & FLAG_SHOWPLUS) != 0) -#define IS_ALTFORM(f) (((f) & FLAG_ALTFORM) != 0) -#define IS_HASDOT(f) (((f) & FLAG_HASDOT) != 0) -#define IS_HASASTERISKWIDTH(f) (((f) & FLAG_HASASTERISKWIDTH) != 0) -#define IS_HASASTERISKTRUNC(f) (((f) & FLAG_HASASTERISKTRUNC) != 0) -#define IS_LONGPRECISION(f) (((f) & FLAG_LONGPRECISION) != 0) -#define IS_LONGLONGPRECISION(f) (((f) & FLAG_LONGLONGPRECISION) != 0) -#define IS_NEGATE(f) (((f) & FLAG_NEGATE) != 0) -#define IS_SIGNED(f) (((f) & (FLAG_SHOWPLUS|FLAG_NEGATE)) != 0) - -/* If CONFIG_ARCH_ROMGETC is defined, then it is assumed that the format - * string data cannot be accessed by simply de-referencing the format string - * pointer. This might be in the case in Harvard architectures where string - * data might be stored in instruction space or if string data were stored - * on some media like EEPROM or external serial FLASH. In all of these cases, - * string data has to be accessed indirectly using the architecture-supplied - * up_romgetc(). The following mechanisms attempt to make these different - * access methods indistinguishable in the following code. - * - * NOTE: It is assumed that string arguments for %s still reside in memory - * that can be directly accessed by de-referencing the string pointer. - */ - -#ifdef CONFIG_ARCH_ROMGETC -# define FMT_TOP ch = up_romgetc(src) /* Loop initialization */ -# define FMT_BOTTOM src++, ch = up_romgetc(src) /* Bottom of a loop */ -# define FMT_CHAR ch /* Access a character */ -# define FMT_NEXT src++; ch = up_romgetc(src) /* Advance to the next character */ -# define FMT_PREV src--; ch = up_romgetc(src) /* Backup to the previous character */ -#else -# define FMT_TOP /* Loop initialization */ -# define FMT_BOTTOM src++ /* Bottom of a loop */ -# define FMT_CHAR *src /* Access a character */ -# define FMT_NEXT src++ /* Advance to the next character */ -# define FMT_PREV src-- /* Backup to the previous character */ -#endif - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -enum -{ - FMT_RJUST = 0, /* Default */ - FMT_LJUST, - FMT_RJUST0, - FMT_CENTER -}; - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/* Pointer to ASCII conversion */ - -#ifdef CONFIG_PTR_IS_NOT_INT -static void ptohex(FAR struct lib_outstream_s *obj, uint8_t flags, FAR void *p); -#ifndef CONFIG_NOPRINTF_FIELDWIDTH -static int getsizesize(uint8_t fmt, uint8_t flags, FAR void *p) -#endif /* CONFIG_NOPRINTF_FIELDWIDTH */ -#endif /* CONFIG_PTR_IS_NOT_INT */ - -/* Unsigned int to ASCII conversion */ - -static void utodec(FAR struct lib_outstream_s *obj, unsigned int n); -static void utohex(FAR struct lib_outstream_s *obj, unsigned int n, uint8_t a); -static void utooct(FAR struct lib_outstream_s *obj, unsigned int n); -static void utobin(FAR struct lib_outstream_s *obj, unsigned int n); -static void utoascii(FAR struct lib_outstream_s *obj, uint8_t fmt, - uint8_t flags, unsigned int lln); - -#ifndef CONFIG_NOPRINTF_FIELDWIDTH -static void fixup(uint8_t fmt, FAR uint8_t *flags, int *n); -static int getusize(uint8_t fmt, uint8_t flags, unsigned int lln); -#endif - -/* Unsigned long int to ASCII conversion */ - -#ifdef CONFIG_LONG_IS_NOT_INT -static void lutodec(FAR struct lib_outstream_s *obj, unsigned long ln); -static void lutohex(FAR struct lib_outstream_s *obj, unsigned long ln, uint8_t a); -static void lutooct(FAR struct lib_outstream_s *obj, unsigned long ln); -static void lutobin(FAR struct lib_outstream_s *obj, unsigned long ln); -static void lutoascii(FAR struct lib_outstream_s *obj, uint8_t fmt, - uint8_t flags, unsigned long ln); -#ifndef CONFIG_NOPRINTF_FIELDWIDTH -static void lfixup(uint8_t fmt, FAR uint8_t *flags, long *ln); -static int getlusize(uint8_t fmt, FAR uint8_t flags, unsigned long ln); -#endif -#endif - -/* Unsigned long long int to ASCII conversions */ - -#ifdef CONFIG_HAVE_LONG_LONG -static void llutodec(FAR struct lib_outstream_s *obj, unsigned long long lln); -static void llutohex(FAR struct lib_outstream_s *obj, unsigned long long lln, uint8_t a); -static void llutooct(FAR struct lib_outstream_s *obj, unsigned long long lln); -static void llutobin(FAR struct lib_outstream_s *obj, unsigned long long lln); -static void llutoascii(FAR struct lib_outstream_s *obj, uint8_t fmt, - uint8_t flags, unsigned long long lln); -#ifndef CONFIG_NOPRINTF_FIELDWIDTH -static void llfixup(uint8_t fmt, FAR uint8_t *flags, FAR long long *lln); -static int getllusize(uint8_t fmt, FAR uint8_t flags, FAR unsigned long long lln); -#endif -#endif - -#ifndef CONFIG_NOPRINTF_FIELDWIDTH -static void prejustify(FAR struct lib_outstream_s *obj, uint8_t fmt, - uint8_t flags, int fieldwidth, int valwidth); -static void postjustify(FAR struct lib_outstream_s *obj, uint8_t fmt, - uint8_t flags, int fieldwidth, int valwidth); -#endif - -/**************************************************************************** - * Global Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Constant Data - ****************************************************************************/ - -static const char g_nullstring[] = "(null)"; - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/* Include floating point functions */ - -#ifdef CONFIG_LIBC_FLOATINGPOINT -# include "stdio/lib_libdtoa.c" -#endif - -/**************************************************************************** - * Name: ptohex - ****************************************************************************/ - -#ifdef CONFIG_PTR_IS_NOT_INT -static void ptohex(FAR struct lib_outstream_s *obj, uint8_t flags, FAR void *p) -{ - union - { - uint32_t dw; - FAR void *p; - } u; - uint8_t bits; - - /* Check for alternate form */ - - if (IS_ALTFORM(flags)) - { - /* Prefix the number with "0x" */ - - obj->put(obj, '0'); - obj->put(obj, 'x'); - } - - u.dw = 0; - u.p = p; - - for (bits = 8*sizeof(void *); bits > 0; bits -= 4) - { - uint8_t nibble = (uint8_t)((u.dw >> (bits - 4)) & 0xf); - if (nibble < 10) - { - obj->put(obj, nibble + '0'); - } - else - { - obj->put(obj, nibble + 'a' - 10); - } - } -} - -/**************************************************************************** - * Name: getpsize - ****************************************************************************/ - -#ifndef CONFIG_NOPRINTF_FIELDWIDTH -static int getpsize(uint8_t flags, FAR void *p) -{ - struct lib_outstream_s nulloutstream; - lib_nulloutstream(&nulloutstream); - - ptohex(&nulloutstream, flags, p); - return nulloutstream.nput; -} - -#endif /* CONFIG_NOPRINTF_FIELDWIDTH */ -#endif /* CONFIG_PTR_IS_NOT_INT */ - -/**************************************************************************** - * Name: utodec - ****************************************************************************/ - -static void utodec(FAR struct lib_outstream_s *obj, unsigned int n) -{ - unsigned int remainder = n % 10; - unsigned int dividend = n / 10; - - if (dividend) - { - utodec(obj, dividend); - } - - obj->put(obj, (remainder + (unsigned int)'0')); -} - -/**************************************************************************** - * Name: utohex - ****************************************************************************/ - -static void utohex(FAR struct lib_outstream_s *obj, unsigned int n, uint8_t a) -{ - bool nonzero = false; - uint8_t bits; - - for (bits = 8*sizeof(unsigned int); bits > 0; bits -= 4) - { - uint8_t nibble = (uint8_t)((n >> (bits - 4)) & 0xf); - if (nibble || nonzero) - { - nonzero = true; - - if (nibble < 10) - { - obj->put(obj, nibble + '0'); - } - else - { - obj->put(obj, nibble + a - 10); - } - } - } - - if (!nonzero) - { - obj->put(obj, '0'); - } -} - -/**************************************************************************** - * Name: utooct - ****************************************************************************/ - -static void utooct(FAR struct lib_outstream_s *obj, unsigned int n) -{ - unsigned int remainder = n & 0x7; - unsigned int dividend = n >> 3; - - if (dividend) - { - utooct(obj, dividend); - } - - obj->put(obj, (remainder + (unsigned int)'0')); -} - -/**************************************************************************** - * Name: utobin - ****************************************************************************/ - -static void utobin(FAR struct lib_outstream_s *obj, unsigned int n) -{ - unsigned int remainder = n & 1; - unsigned int dividend = n >> 1; - - if (dividend) - { - utobin(obj, dividend); - } - - obj->put(obj, (remainder + (unsigned int)'0')); -} - -/**************************************************************************** - * Name: utoascii - ****************************************************************************/ - -static void utoascii(FAR struct lib_outstream_s *obj, uint8_t fmt, uint8_t flags, unsigned int n) -{ - /* Perform the integer conversion according to the format specifier */ - - switch (fmt) - { - case 'd': - case 'i': - /* Signed base 10 */ - { -#ifdef CONFIG_NOPRINTF_FIELDWIDTH - if ((int)n < 0) - { - obj->put(obj, '-'); - n = (unsigned int)(-(int)n); - } - else if (IS_SHOWPLUS(flags)) - { - obj->put(obj, '+'); - } -#endif - /* Convert the unsigned value to a string. */ - - utodec(obj, n); - } - break; - - case 'u': - /* Unigned base 10 */ - { -#ifdef CONFIG_NOPRINTF_FIELDWIDTH - if (IS_SHOWPLUS(flags)) - { - obj->put(obj, '+'); - } -#endif - /* Convert the unsigned value to a string. */ - - utodec(obj, n); - } - break; - -#ifndef CONFIG_PTR_IS_NOT_INT - case 'p': -#endif - case 'x': - case 'X': - /* Hexadecimal */ - { - /* Check for alternate form */ - - if (IS_ALTFORM(flags)) - { - /* Prefix the number with "0x" */ - - obj->put(obj, '0'); - obj->put(obj, 'x'); - } - - /* Convert the unsigned value to a string. */ - - if (fmt == 'X') - { - utohex(obj, n, 'A'); - } - else - { - utohex(obj, n, 'a'); - } - } - break; - - case 'o': - /* Octal */ - { - /* Check for alternate form */ - - if (IS_ALTFORM(flags)) - { - /* Prefix the number with '0' */ - - obj->put(obj, '0'); - } - - /* Convert the unsigned value to a string. */ - - utooct(obj, n); - } - break; - - case 'b': - /* Binary */ - { - /* Convert the unsigned value to a string. */ - - utobin(obj, n); - } - break; - -#ifdef CONFIG_PTR_IS_NOT_INT - case 'p': -#endif - default: - break; - } -} - -/**************************************************************************** - * Name: fixup - ****************************************************************************/ - -#ifndef CONFIG_NOPRINTF_FIELDWIDTH -static void fixup(uint8_t fmt, FAR uint8_t *flags, FAR int *n) -{ - /* Perform the integer conversion according to the format specifier */ - - switch (fmt) - { - case 'd': - case 'i': - /* Signed base 10 */ - - if (*n < 0) - { - SET_NEGATE(*flags); - CLR_SHOWPLUS(*flags); - *n = -*n; - } - break; - - case 'u': - /* Unsigned base 10 */ - break; - - case 'p': - case 'x': - case 'X': - /* Hexadecimal */ - case 'o': - /* Octal */ - case 'b': - /* Binary */ - CLR_SIGNED(*flags); - break; - - default: - break; - } -} - -/**************************************************************************** - * Name: getusize - ****************************************************************************/ - -static int getusize(uint8_t fmt, uint8_t flags, unsigned int n) -{ - struct lib_outstream_s nulloutstream; - lib_nulloutstream(&nulloutstream); - - utoascii(&nulloutstream, fmt, flags, n); - return nulloutstream.nput; -} - -/**************************************************************************** - * Name: getdblsize - ****************************************************************************/ - -#ifdef CONFIG_LIBC_FLOATINGPOINT -static int getdblsize(uint8_t fmt, int trunc, uint8_t flags, double n) -{ - struct lib_outstream_s nulloutstream; - lib_nulloutstream(&nulloutstream); - - lib_dtoa(&nulloutstream, fmt, trunc, flags, n); - return nulloutstream.nput; -} -#endif -#endif /* CONFIG_NOPRINTF_FIELDWIDTH */ - -#ifdef CONFIG_LONG_IS_NOT_INT -/**************************************************************************** - * Name: lutodec - ****************************************************************************/ - -static void lutodec(FAR struct lib_outstream_s *obj, unsigned long n) -{ - unsigned int remainder = n % 10; - unsigned long dividend = n / 10; - - if (dividend) - { - lutodec(obj, dividend); - } - - obj->put(obj, (remainder + (unsigned int)'0')); -} - -/**************************************************************************** - * Name: lutohex - ****************************************************************************/ - -static void lutohex(FAR struct lib_outstream_s *obj, unsigned long n, uint8_t a) -{ - bool nonzero = false; - uint8_t bits; - - for (bits = 8*sizeof(unsigned long); bits > 0; bits -= 4) - { - uint8_t nibble = (uint8_t)((n >> (bits - 4)) & 0xf); - if (nibble || nonzero) - { - nonzero = true; - - if (nibble < 10) - { - obj->put(obj, nibble + '0'); - } - else - { - obj->put(obj, nibble + a - 10); - } - } - } - - if (!nonzero) - { - obj->put(obj, '0'); - } -} - -/**************************************************************************** - * Name: lutooct - ****************************************************************************/ - -static void lutooct(FAR struct lib_outstream_s *obj, unsigned long n) -{ - unsigned int remainder = n & 0x7; - unsigned long dividend = n >> 3; - - if (dividend) - { - lutooct(obj, dividend); - } - - obj->put(obj, (remainder + (unsigned int)'0')); -} - -/**************************************************************************** - * Name: lutobin - ****************************************************************************/ - -static void lutobin(FAR struct lib_outstream_s *obj, unsigned long n) -{ - unsigned int remainder = n & 1; - unsigned long dividend = n >> 1; - - if (dividend) - { - lutobin(obj, dividend); - } - - obj->put(obj, (remainder + (unsigned int)'0')); -} - -/**************************************************************************** - * Name: lutoascii - ****************************************************************************/ - -static void lutoascii(FAR struct lib_outstream_s *obj, uint8_t fmt, uint8_t flags, unsigned long ln) -{ - /* Perform the integer conversion according to the format specifier */ - - switch (fmt) - { - case 'd': - case 'i': - /* Signed base 10 */ - { -#ifdef CONFIG_NOPRINTF_FIELDWIDTH - if ((long)ln < 0) - { - obj->put(obj, '-'); - ln = (unsigned long)(-(long)ln); - } - else if (IS_SHOWPLUS(flags)) - { - obj->put(obj, '+'); - } -#endif - /* Convert the unsigned value to a string. */ - - lutodec(obj, ln); - } - break; - - case 'u': - /* Unigned base 10 */ - { -#ifdef CONFIG_NOPRINTF_FIELDWIDTH - if (IS_SHOWPLUS(flags)) - { - obj->put(obj, '+'); - } -#endif - /* Convert the unsigned value to a string. */ - - lutodec(obj, ln); - } - break; - - case 'x': - case 'X': - /* Hexadecimal */ - { - /* Check for alternate form */ - - if (IS_ALTFORM(flags)) - { - /* Prefix the number with "0x" */ - - obj->put(obj, '0'); - obj->put(obj, 'x'); - } - - /* Convert the unsigned value to a string. */ - - if (fmt == 'X') - { - lutohex(obj, ln, 'A'); - } - else - { - lutohex(obj, ln, 'a'); - } - } - break; - - case 'o': - /* Octal */ - { - /* Check for alternate form */ - - if (IS_ALTFORM(flags)) - { - /* Prefix the number with '0' */ - - obj->put(obj, '0'); - } - - /* Convert the unsigned value to a string. */ - - lutooct(obj, ln); - } - break; - - case 'b': - /* Binary */ - { - /* Convert the unsigned value to a string. */ - - lutobin(obj, ln); - } - break; - - case 'p': - default: - break; - } -} - -/**************************************************************************** - * Name: lfixup - ****************************************************************************/ - -#ifndef CONFIG_NOPRINTF_FIELDWIDTH -static void lfixup(uint8_t fmt, FAR uint8_t *flags, FAR long *ln) -{ - /* Perform the integer conversion according to the format specifier */ - - switch (fmt) - { - case 'd': - case 'i': - /* Signed base 10 */ - - if (*ln < 0) - { - SET_NEGATE(*flags); - CLR_SHOWPLUS(*flags); - *ln = -*ln; - } - break; - - case 'u': - /* Unsigned base 10 */ - break; - - case 'p': - case 'x': - case 'X': - /* Hexadecimal */ - case 'o': - /* Octal */ - case 'b': - /* Binary */ - CLR_SIGNED(*flags); - break; - - default: - break; - } -} - -/**************************************************************************** - * Name: getlusize - ****************************************************************************/ - -static int getlusize(uint8_t fmt, uint8_t flags, unsigned long ln) -{ - struct lib_outstream_s nulloutstream; - lib_nulloutstream(&nulloutstream); - - lutoascii(&nulloutstream, fmt, flags, ln); - return nulloutstream.nput; -} - -#endif /* CONFIG_NOPRINTF_FIELDWIDTH */ -#endif /* CONFIG_LONG_IS_NOT_INT */ - -#ifdef CONFIG_HAVE_LONG_LONG -/**************************************************************************** - * Name: llutodec - ****************************************************************************/ - -static void llutodec(FAR struct lib_outstream_s *obj, unsigned long long n) -{ - unsigned int remainder = n % 10; - unsigned long long dividend = n / 10; - - if (dividend) - { - llutodec(obj, dividend); - } - - obj->put(obj, (remainder + (unsigned int)'0')); -} - -/**************************************************************************** - * Name: llutohex - ****************************************************************************/ - -static void llutohex(FAR struct lib_outstream_s *obj, unsigned long long n, uint8_t a) -{ - bool nonzero = false; - uint8_t bits; - - for (bits = 8*sizeof(unsigned long long); bits > 0; bits -= 4) - { - uint8_t nibble = (uint8_t)((n >> (bits - 4)) & 0xf); - if (nibble || nonzero) - { - nonzero = true; - - if (nibble < 10) - { - obj->put(obj, (nibble + '0')); - } - else - { - obj->put(obj, (nibble + a - 10)); - } - } - } - - if (!nonzero) - { - obj->put(obj, '0'); - } -} - -/**************************************************************************** - * Name: llutooct - ****************************************************************************/ - -static void llutooct(FAR struct lib_outstream_s *obj, unsigned long long n) -{ - unsigned int remainder = n & 0x7; - unsigned long long dividend = n >> 3; - - if (dividend) - { - llutooct(obj, dividend); - } - - obj->put(obj, (remainder + (unsigned int)'0')); -} - -/**************************************************************************** - * Name: llutobin - ****************************************************************************/ - -static void llutobin(FAR struct lib_outstream_s *obj, unsigned long long n) -{ - unsigned int remainder = n & 1; - unsigned long long dividend = n >> 1; - - if (dividend) - { - llutobin(obj, dividend); - } - - obj->put(obj, (remainder + (unsigned int)'0')); -} - -/**************************************************************************** - * Name: llutoascii - ****************************************************************************/ - -static void llutoascii(FAR struct lib_outstream_s *obj, uint8_t fmt, uint8_t flags, unsigned long long lln) -{ - /* Perform the integer conversion according to the format specifier */ - - switch (fmt) - { - case 'd': - case 'i': - /* Signed base 10 */ - { -#ifdef CONFIG_NOPRINTF_FIELDWIDTH - if ((long long)lln < 0) - { - obj->put(obj, '-'); - lln = (unsigned long long)(-(long long)lln); - } - else if (IS_SHOWPLUS(flags)) - { - obj->put(obj, '+'); - } -#endif - /* Convert the unsigned value to a string. */ - - llutodec(obj, (unsigned long long)lln); - } - break; - - case 'u': - /* Unigned base 10 */ - { -#ifdef CONFIG_NOPRINTF_FIELDWIDTH - if (IS_SHOWPLUS(flags)) - { - obj->put(obj, '+'); - } -#endif - /* Convert the unsigned value to a string. */ - - llutodec(obj, (unsigned long long)lln); - } - break; - - case 'x': - case 'X': - /* Hexadecimal */ - { - /* Check for alternate form */ - - if (IS_ALTFORM(flags)) - { - /* Prefix the number with "0x" */ - - obj->put(obj, '0'); - obj->put(obj, 'x'); - } - - /* Convert the unsigned value to a string. */ - - if (fmt == 'X') - { - llutohex(obj, (unsigned long long)lln, 'A'); - } - else - { - llutohex(obj, (unsigned long long)lln, 'a'); - } - } - break; - - case 'o': - /* Octal */ - { - /* Check for alternate form */ - - if (IS_ALTFORM(flags)) - { - /* Prefix the number with '0' */ - - obj->put(obj, '0'); - } - - /* Convert the unsigned value to a string. */ - - llutooct(obj, (unsigned long long)lln); - } - break; - - case 'b': - /* Binary */ - { - /* Convert the unsigned value to a string. */ - - llutobin(obj, (unsigned long long)lln); - } - break; - - case 'p': - default: - break; - } -} - -/**************************************************************************** - * Name: llfixup - ****************************************************************************/ - -#ifndef CONFIG_NOPRINTF_FIELDWIDTH -static void llfixup(uint8_t fmt, FAR uint8_t *flags, FAR long long *lln) -{ - /* Perform the integer conversion according to the format specifier */ - - switch (fmt) - { - case 'd': - case 'i': - /* Signed base 10 */ - - if (*lln < 0) - { - SET_NEGATE(*flags); - CLR_SHOWPLUS(*flags); - *lln = -*lln; - } - break; - - case 'u': - /* Unsigned base 10 */ - break; - - case 'p': - case 'x': - case 'X': - /* Hexadecimal */ - case 'o': - /* Octal */ - case 'b': - /* Binary */ - CLR_SIGNED(*flags); - break; - - default: - break; - } -} - -/**************************************************************************** - * Name: getllusize - ****************************************************************************/ - -static int getllusize(uint8_t fmt, uint8_t flags, unsigned long long lln) -{ - struct lib_outstream_s nulloutstream; - lib_nulloutstream(&nulloutstream); - - - llutoascii(&nulloutstream, fmt, flags, lln); - return nulloutstream.nput; -} - -#endif /* CONFIG_NOPRINTF_FIELDWIDTH */ -#endif /* CONFIG_HAVE_LONG_LONG */ - -/**************************************************************************** - * Name: prejustify - ****************************************************************************/ - -#ifndef CONFIG_NOPRINTF_FIELDWIDTH -static void prejustify(FAR struct lib_outstream_s *obj, uint8_t fmt, - uint8_t flags, int fieldwidth, int valwidth) -{ - int i; - - switch (fmt) - { - default: - case FMT_RJUST: - if (IS_SIGNED(flags)) - { - valwidth++; - } - - for (i = fieldwidth - valwidth; i > 0; i--) - { - obj->put(obj, ' '); - } - - if (IS_NEGATE(flags)) - { - obj->put(obj, '-'); - } - else if (IS_SHOWPLUS(flags)) - { - obj->put(obj, '+'); - } - break; - - case FMT_RJUST0: - if (IS_NEGATE(flags)) - { - obj->put(obj, '-'); - valwidth++; - } - else if (IS_SHOWPLUS(flags)) - { - obj->put(obj, '+'); - valwidth++; - } - - for (i = fieldwidth - valwidth; i > 0; i--) - { - obj->put(obj, '0'); - } - break; - - case FMT_LJUST: - if (IS_NEGATE(flags)) - { - obj->put(obj, '-'); - } - else if (IS_SHOWPLUS(flags)) - { - obj->put(obj, '+'); - } - break; - } -} -#endif - -/**************************************************************************** - * Name: postjustify - ****************************************************************************/ - -#ifndef CONFIG_NOPRINTF_FIELDWIDTH -static void postjustify(FAR struct lib_outstream_s *obj, uint8_t fmt, - uint8_t flags, int fieldwidth, int valwidth) -{ - int i; - - /* Apply field justification to the integer value. */ - - switch (fmt) - { - default: - case FMT_RJUST: - case FMT_RJUST0: - break; - - case FMT_LJUST: - if (IS_SIGNED(flags)) - { - valwidth++; - } - - for (i = fieldwidth - valwidth; i > 0; i--) - { - obj->put(obj, ' '); - } - break; - } -} -#endif - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * lib/stdio/lib_vsprintf - ****************************************************************************/ - -int lib_vsprintf(FAR struct lib_outstream_s *obj, FAR const char *src, va_list ap) -{ - FAR char *ptmp; -#ifndef CONFIG_NOPRINTF_FIELDWIDTH - int width; -#ifdef CONFIG_LIBC_FLOATINGPOINT - int trunc; -#endif - uint8_t fmt; -#endif - uint8_t flags; -#ifdef CONFIG_ARCH_ROMGETC - char ch; -#endif - - for (FMT_TOP; FMT_CHAR; FMT_BOTTOM) - { - /* Just copy regular characters */ - - if (FMT_CHAR != '%') - { - /* Output the character */ - - obj->put(obj, FMT_CHAR); - - /* Flush the buffer if a newline is encountered */ - -#ifdef CONFIG_STDIO_LINEBUFFER - if (FMT_CHAR == '\n') - { - /* Should return an error on a failure to flush */ - - (void)obj->flush(obj); - } -#endif - /* Process the next character in the format */ - - continue; - } - - /* We have found a format specifier. Move past it. */ - - FMT_NEXT; - - /* Assume defaults */ - - flags = 0; -#ifndef CONFIG_NOPRINTF_FIELDWIDTH - fmt = FMT_RJUST; - width = 0; -#ifdef CONFIG_LIBC_FLOATINGPOINT - trunc = 0; -#endif -#endif - - /* Process each format qualifier. */ - - for (; FMT_CHAR; FMT_BOTTOM) - { - /* Break out of the loop when the format is known. */ - - if (strchr("diuxXpobeEfgGlLsc%", FMT_CHAR)) - { - break; - } - - /* Check for left justification. */ - - else if (FMT_CHAR == '-') - { -#ifndef CONFIG_NOPRINTF_FIELDWIDTH - fmt = FMT_LJUST; -#endif - } - - /* Check for leading zero fill right justification. */ - - else if (FMT_CHAR == '0') - { -#ifndef CONFIG_NOPRINTF_FIELDWIDTH - fmt = FMT_RJUST0; -#endif - } -#if 0 - /* Center justification. */ - - else if (FMT_CHAR == '~') - { -#ifndef CONFIG_NOPRINTF_FIELDWIDTH - fmt = FMT_CENTER; -#endif - } -#endif - - else if (FMT_CHAR == '*') - { -#ifndef CONFIG_NOPRINTF_FIELDWIDTH - int value = va_arg(ap, int); - if (IS_HASDOT(flags)) - { -#ifdef CONFIG_LIBC_FLOATINGPOINT - trunc = value; - SET_HASASTERISKTRUNC(flags); -#endif - } - else - { - width = value; - SET_HASASTERISKWIDTH(flags); - } -#endif - } - - /* Check for field width */ - - else if (FMT_CHAR >= '1' && FMT_CHAR <= '9') - { -#ifdef CONFIG_NOPRINTF_FIELDWIDTH - do - { - FMT_NEXT; - } - while (FMT_CHAR >= '0' && FMT_CHAR <= '9'); -#else - /* Accumulate the field width integer. */ - - int n = ((int)(FMT_CHAR)) - (int)'0'; - for (;;) - { - FMT_NEXT; - if (FMT_CHAR >= '0' && FMT_CHAR <= '9') - { - n = 10*n + (((int)(FMT_CHAR)) - (int)'0'); - } - else - { - break; - } - } - - if (IS_HASDOT(flags)) - { -#ifdef CONFIG_LIBC_FLOATINGPOINT - trunc = n; -#endif - } - else - { - width = n; - } -#endif - /* Back up to the last digit. */ - - FMT_PREV; - } - - /* Check for a decimal point. */ - - else if (FMT_CHAR == '.') - { -#ifndef CONFIG_NOPRINTF_FIELDWIDTH - SET_HASDOT(flags); -#endif - } - - /* Check for leading plus sign. */ - - else if (FMT_CHAR == '+') - { - SET_SHOWPLUS(flags); - } - - /* Check for alternate form. */ - - else if (FMT_CHAR == '#') - { - SET_ALTFORM(flags); - } - } - - /* "%%" means that a literal '%' was intended (instead of a format - * specification). - */ - - if (FMT_CHAR == '%') - { - obj->put(obj, '%'); - continue; - } - - /* Check for the string format. */ - - if (FMT_CHAR == 's') - { -#ifndef CONFIG_NOPRINTF_FIELDWIDTH - int swidth; -#endif - /* Get the string to output */ - - ptmp = va_arg(ap, char *); - if (!ptmp) - { - ptmp = (char*)g_nullstring; - } - - /* Get the widith of the string and perform right-justification - * operations. - */ - -#ifndef CONFIG_NOPRINTF_FIELDWIDTH - swidth = strlen(ptmp); - prejustify(obj, fmt, 0, width, swidth); -#endif - /* Concatenate the string into the output */ - - while (*ptmp) - { - obj->put(obj, *ptmp); - ptmp++; - } - - /* Perform left-justification operations. */ - -#ifndef CONFIG_NOPRINTF_FIELDWIDTH - postjustify(obj, fmt, 0, width, swidth); -#endif - continue; - } - - /* Check for the character output */ - - else if (FMT_CHAR == 'c') - { - /* Just copy the character into the output. */ - - int n = va_arg(ap, int); - obj->put(obj, n); - continue; - } - - /* Check for the long long prefix. */ - - if (FMT_CHAR == 'L') - { - SET_LONGLONGPRECISION(flags); - FMT_NEXT; - } - else if (FMT_CHAR == 'l') - { - SET_LONGPRECISION(flags); - FMT_NEXT; - if (FMT_CHAR == 'l') - { - SET_LONGLONGPRECISION(flags); - FMT_NEXT; - } - } - - /* Handle integer conversions */ - - if (strchr("diuxXpob", FMT_CHAR)) - { -#ifdef CONFIG_HAVE_LONG_LONG - if (IS_LONGLONGPRECISION(flags) && FMT_CHAR != 'p') - { - long long lln; -#ifndef CONFIG_NOPRINTF_FIELDWIDTH - int lluwidth; -#endif - /* Extract the long long value. */ - - lln = va_arg(ap, long long); - -#ifdef CONFIG_NOPRINTF_FIELDWIDTH - /* Output the number */ - - llutoascii(obj, FMT_CHAR, flags, (unsigned long long)lln); -#else - /* Resolve sign-ness and format issues */ - - llfixup(FMT_CHAR, &flags, &lln); - - /* Get the width of the output */ - - lluwidth = getllusize(FMT_CHAR, flags, lln); - - /* Perform left field justification actions */ - - prejustify(obj, fmt, flags, width, lluwidth); - - /* Output the number */ - - llutoascii(obj, FMT_CHAR, flags, (unsigned long long)lln); - - /* Perform right field justification actions */ - - postjustify(obj, fmt, flags, width, lluwidth); -#endif - } - else -#endif /* CONFIG_HAVE_LONG_LONG */ -#ifdef CONFIG_LONG_IS_NOT_INT - if (IS_LONGPRECISION(flags) && FMT_CHAR != 'p') - { - long ln; -#ifndef CONFIG_NOPRINTF_FIELDWIDTH - int luwidth; -#endif - /* Extract the long value. */ - - ln = va_arg(ap, long); - -#ifdef CONFIG_NOPRINTF_FIELDWIDTH - /* Output the number */ - - lutoascii(obj, FMT_CHAR, flags, (unsigned long)ln); -#else - /* Resolve sign-ness and format issues */ - - lfixup(FMT_CHAR, &flags, &ln); - - /* Get the width of the output */ - - luwidth = getlusize(FMT_CHAR, flags, ln); - - /* Perform left field justification actions */ - - prejustify(obj, fmt, flags, width, luwidth); - - /* Output the number */ - - lutoascii(obj, FMT_CHAR, flags, (unsigned long)ln); - - /* Perform right field justification actions */ - - postjustify(obj, fmt, flags, width, luwidth); -#endif - } - else -#endif /* CONFIG_LONG_IS_NOT_INT */ -#ifdef CONFIG_PTR_IS_NOT_INT - if (FMT_CHAR == 'p') - { - void *p; -#ifndef CONFIG_NOPRINTF_FIELDWIDTH - int pwidth; -#endif - /* Extract the integer value. */ - - p = va_arg(ap, void *); - -#ifdef CONFIG_NOPRINTF_FIELDWIDTH - /* Output the pointer value */ - - ptohex(obj, flags, p); -#else - /* Resolve sign-ness and format issues */ - - lfixup(FMT_CHAR, &flags, &ln); - - /* Get the width of the output */ - - luwidth = getpsize(FMT_CHAR, flags, p); - - /* Perform left field justification actions */ - - prejustify(obj, fmt, flags, width, pwidth); - - /* Output the pointer value */ - - ptohex(obj, flags, p); - - /* Perform right field justification actions */ - - postjustify(obj, fmt, flags, width, pwidth); -#endif - } - else -#endif - { - int n; -#ifndef CONFIG_NOPRINTF_FIELDWIDTH - int uwidth; -#endif - /* Extract the long long value. */ - - n = va_arg(ap, int); - -#ifdef CONFIG_NOPRINTF_FIELDWIDTH - /* Output the number */ - - utoascii(obj, FMT_CHAR, flags, (unsigned int)n); -#else - /* Resolve sign-ness and format issues */ - - fixup(FMT_CHAR, &flags, &n); - - /* Get the width of the output */ - - uwidth = getusize(FMT_CHAR, flags, n); - - /* Perform left field justification actions */ - - prejustify(obj, fmt, flags, width, uwidth); - - /* Output the number */ - - utoascii(obj, FMT_CHAR, flags, (unsigned int)n); - - /* Perform right field justification actions */ - - postjustify(obj, fmt, flags, width, uwidth); -#endif - } - } - - /* Handle floating point conversions */ - -#ifdef CONFIG_LIBC_FLOATINGPOINT - else if (strchr("eEfgG", FMT_CHAR)) - { -#ifndef CONFIG_NOPRINTF_FIELDWIDTH - double dblval = va_arg(ap, double); - int dblsize; - - /* Get the width of the output */ - - dblsize = getdblsize(FMT_CHAR, trunc, flags, dblval); - - /* Perform left field justification actions */ - - prejustify(obj, fmt, 0, width, dblsize); - - /* Output the number */ - - lib_dtoa(obj, FMT_CHAR, trunc, flags, dblval); - - /* Perform right field justification actions */ - - postjustify(obj, fmt, 0, width, dblsize); -#else - /* Output the number with a fixed precision */ - - double dblval = va_arg(ap, double); - lib_dtoa(obj, FMT_CHAR, CONFIG_LIBC_FIXEDPRECISION, flags, dblval); -#endif - } -#endif /* CONFIG_LIBC_FLOATINGPOINT */ - } - - return obj->nput; -} - - diff --git a/nuttx/lib/stdio/lib_lowinstream.c b/nuttx/lib/stdio/lib_lowinstream.c deleted file mode 100644 index 499a647ea..000000000 --- a/nuttx/lib/stdio/lib_lowinstream.c +++ /dev/null @@ -1,102 +0,0 @@ -/**************************************************************************** - * lib/stdio/lib_lowinstream.c - * - * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include -#include - -#include - -#include "lib_internal.h" - -#ifdef CONFIG_ARCH_LOWGETC - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: lowinstream_getc - ****************************************************************************/ - -static int lowinstream_getc(FAR struct lib_instream_s *this) -{ - int ret; - - DEBUGASSERT(this); - - /* Get the next character from the incoming stream */ - - ret = up_getc(ch) - if (ret != EOF) - { - this->nget++; - } - - return ret; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: lib_lowinstream - * - * Description: - * Initializes a stream for use with low-level, architecture-specific I/O. - * - * Input parameters: - * lowoutstream - User allocated, uninitialized instance of struct - * lib_lowoutstream_s to be initialized. - * - * Returned Value: - * None (User allocated instance initialized). - * - ****************************************************************************/ - -void lib_lowinstream(FAR struct lib_instream_s *stream) -{ - stream->get = lowinstream_getc; - stream->nget = 0; -} - -#endif /* CONFIG_ARCH_LOWGETC */ diff --git a/nuttx/lib/stdio/lib_lowoutstream.c b/nuttx/lib/stdio/lib_lowoutstream.c deleted file mode 100644 index 092f39ca2..000000000 --- a/nuttx/lib/stdio/lib_lowoutstream.c +++ /dev/null @@ -1,97 +0,0 @@ -/**************************************************************************** - * lib/stdio/lib_lowoutstream.c - * - * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#ifdef CONFIG_ARCH_LOWPUTC - -#include -#include -#include -#include - -#include "lib_internal.h" - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: lowoutstream_putc - ****************************************************************************/ - -static void lowoutstream_putc(FAR struct lib_outstream_s *this, int ch) -{ - DEBUGASSERT(this); - - if (up_putc(ch) != EOF) - { - this->nput++; - } -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: lib_lowoutstream - * - * Description: - * Initializes a stream for use with low-level, architecture-specific I/O. - * - * Input parameters: - * lowoutstream - User allocated, uninitialized instance of struct - * lib_lowoutstream_s to be initialized. - * - * Returned Value: - * None (User allocated instance initialized). - * - ****************************************************************************/ - -void lib_lowoutstream(FAR struct lib_outstream_s *stream) -{ - stream->put = lowoutstream_putc; -#ifdef CONFIG_STDIO_LINEBUFFER - stream->flush = lib_noflush; -#endif - stream->nput = 0; -} - -#endif /* CONFIG_ARCH_LOWPUTC */ diff --git a/nuttx/lib/stdio/lib_lowprintf.c b/nuttx/lib/stdio/lib_lowprintf.c deleted file mode 100644 index 392ef2c6a..000000000 --- a/nuttx/lib/stdio/lib_lowprintf.c +++ /dev/null @@ -1,128 +0,0 @@ -/**************************************************************************** - * lib/stdio/lib_lowprintf.c - * - * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 -#include -#include -#include "lib_internal.h" - -/* This interface can only be used from within the kernel */ - -#if !defined(CONFIG_NUTTX_KERNEL) || defined(__KERNEL__) - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Global Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Global Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: lib_lowvprintf - ****************************************************************************/ - -#if defined(CONFIG_ARCH_LOWPUTC) || defined(CONFIG_SYSLOG) - -int lib_lowvprintf(const char *fmt, va_list ap) -{ - struct lib_outstream_s stream; - - /* Wrap the stdout in a stream object and let lib_vsprintf do the work. */ - -#ifdef CONFIG_SYSLOG - lib_syslogstream((FAR struct lib_outstream_s *)&stream); -#else - lib_lowoutstream((FAR struct lib_outstream_s *)&stream); -#endif - return lib_vsprintf((FAR struct lib_outstream_s *)&stream, fmt, ap); -} - -/**************************************************************************** - * Name: lib_lowprintf - ****************************************************************************/ - -int lib_lowprintf(const char *fmt, ...) -{ - va_list ap; - int ret; - -#ifdef CONFIG_DEBUG_ENABLE - ret = 0; - if (g_dbgenable) -#endif - { - va_start(ap, fmt); - ret = lib_lowvprintf(fmt, ap); - va_end(ap); - } - - return ret; -} - -#endif /* CONFIG_ARCH_LOWPUTC || CONFIG_SYSLOG */ -#endif /* __KERNEL__ */ diff --git a/nuttx/lib/stdio/lib_meminstream.c b/nuttx/lib/stdio/lib_meminstream.c deleted file mode 100644 index a842096fb..000000000 --- a/nuttx/lib/stdio/lib_meminstream.c +++ /dev/null @@ -1,104 +0,0 @@ -/**************************************************************************** - * lib/stdio/lib_meminstream.c - * - * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include "lib_internal.h" - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: meminstream_getc - ****************************************************************************/ - -static int meminstream_getc(FAR struct lib_instream_s *this) -{ - FAR struct lib_meminstream_s *mthis = (FAR struct lib_meminstream_s *)this; - int ret; - - DEBUGASSERT(this); - - /* Get the next character (if any) from the buffer */ - - if (this->nget < mthis->buflen) - { - ret = mthis->buffer[this->nget]; - this->nget++; - } - else - { - ret = EOF; - } - - return ret; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: lib_meminstream - * - * Description: - * Initializes a stream for use with a fixed-size memory buffer. - * - * Input parameters: - * meminstream - User allocated, uninitialized instance of struct - * lib_meminstream_s to be initialized. - * bufstart - Address of the beginning of the fixed-size memory buffer - * buflen - Size of the fixed-sized memory buffer in bytes - * - * Returned Value: - * None (meminstream initialized). - * - ****************************************************************************/ - -void lib_meminstream(FAR struct lib_meminstream_s *meminstream, - FAR const char *bufstart, int buflen) -{ - meminstream->public.get = meminstream_getc; - meminstream->public.nget = 0; /* Will be buffer index */ - meminstream->buffer = bufstart; /* Start of buffer */ - meminstream->buflen = buflen; /* Length of the buffer */ -} - - diff --git a/nuttx/lib/stdio/lib_memoutstream.c b/nuttx/lib/stdio/lib_memoutstream.c deleted file mode 100644 index 21197358b..000000000 --- a/nuttx/lib/stdio/lib_memoutstream.c +++ /dev/null @@ -1,105 +0,0 @@ -/**************************************************************************** - * lib/stdio/lib_memoutstream.c - * - * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include "lib_internal.h" - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: memoutstream_putc - ****************************************************************************/ - -static void memoutstream_putc(FAR struct lib_outstream_s *this, int ch) -{ - FAR struct lib_memoutstream_s *mthis = (FAR struct lib_memoutstream_s *)this; - - DEBUGASSERT(this); - - /* If this will not overrun the buffer, then write the character to the - * buffer. Not that buflen was pre-decremented when the stream was - * created so it is okay to write past the end of the buflen by one. - */ - - if (this->nput < mthis->buflen) - { - mthis->buffer[this->nput] = ch; - this->nput++; - mthis->buffer[this->nput] = '\0'; - } -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: lib_memoutstream - * - * Description: - * Initializes a stream for use with a fixed-size memory buffer. - * - * Input parameters: - * memoutstream - User allocated, uninitialized instance of struct - * lib_memoutstream_s to be initialized. - * bufstart - Address of the beginning of the fixed-size memory buffer - * buflen - Size of the fixed-sized memory buffer in bytes - * - * Returned Value: - * None (memoutstream initialized). - * - ****************************************************************************/ - -void lib_memoutstream(FAR struct lib_memoutstream_s *memoutstream, - FAR char *bufstart, int buflen) -{ - memoutstream->public.put = memoutstream_putc; -#ifdef CONFIG_STDIO_LINEBUFFER - memoutstream->public.flush = lib_noflush; -#endif - memoutstream->public.nput = 0; /* Will be buffer index */ - memoutstream->buffer = bufstart; /* Start of buffer */ - memoutstream->buflen = buflen - 1; /* Save space for null terminator */ - memoutstream->buffer[0] = '\0'; /* Start with an empty string */ -} - - diff --git a/nuttx/lib/stdio/lib_nullinstream.c b/nuttx/lib/stdio/lib_nullinstream.c deleted file mode 100644 index 0eadb0a8e..000000000 --- a/nuttx/lib/stdio/lib_nullinstream.c +++ /dev/null @@ -1,79 +0,0 @@ -/**************************************************************************** - * lib/stdio/lib_nullinstream.c - * - * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 -#include - -#include "lib_internal.h" - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static int nullinstream_getc(FAR struct lib_instream_s *this) -{ - return EOF; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: lib_nullinstream - * - * Description: - * Initializes a NULL stream. The initialized stream will will return only - * EOF. - * - * Input parameters: - * nullinstream - User allocated, uninitialized instance of struct - * lib_instream_s to be initialized. - * - * Returned Value: - * None (User allocated instance initialized). - * - ****************************************************************************/ - -void lib_nullinstream(FAR struct lib_instream_s *nullinstream) -{ - nullinstream->get = nullinstream_getc; - nullinstream->nget = 0; -} - diff --git a/nuttx/lib/stdio/lib_nulloutstream.c b/nuttx/lib/stdio/lib_nulloutstream.c deleted file mode 100644 index 69878fd57..000000000 --- a/nuttx/lib/stdio/lib_nulloutstream.c +++ /dev/null @@ -1,84 +0,0 @@ -/**************************************************************************** - * lib/stdio/lib_nulloutstream.c - * - * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 -#include -#include - -#include "lib_internal.h" - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static void nulloutstream_putc(FAR struct lib_outstream_s *this, int ch) -{ - DEBUGASSERT(this); - this->nput++; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: lib_nulloutstream - * - * Description: - * Initializes a NULL streams. The initialized stream will write all data - * to the bit-bucket. - * - * Input parameters: - * nulloutstream - User allocated, uninitialized instance of struct - * lib_outstream_s to be initialized. - * - * Returned Value: - * None (User allocated instance initialized). - * - ****************************************************************************/ - -void lib_nulloutstream(FAR struct lib_outstream_s *nulloutstream) -{ - nulloutstream->put = nulloutstream_putc; -#ifdef CONFIG_STDIO_LINEBUFFER - nulloutstream->flush = lib_noflush; -#endif - nulloutstream->nput = 0; -} - diff --git a/nuttx/lib/stdio/lib_perror.c b/nuttx/lib/stdio/lib_perror.c deleted file mode 100644 index 867e113f9..000000000 --- a/nuttx/lib/stdio/lib_perror.c +++ /dev/null @@ -1,99 +0,0 @@ -/**************************************************************************** - * lib/stdio/lib_perror.c - * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* POSIX requires that perror provide its output on stderr. This option may - * be defined, however, to provide perror output that is serialized with - * other stdout messages. - */ - -#ifdef CONFIG_LIBC_PERROR_STDOUT -# define PERROR_STREAM stdout -#else -# define PERROR_STREAM stderr -#endif - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: perror - ****************************************************************************/ - -void perror(FAR const char *s) -{ - - /* If strerror() is not enabled, then just print the error number */ - -#ifdef CONFIG_LIBC_STRERROR - (void)fprintf(PERROR_STREAM, "%s: %s\n", s, strerror(errno)); -#else - (void)fprintf(PERROR_STREAM, "%s: Error %d\n", s, errno); -#endif -} - diff --git a/nuttx/lib/stdio/lib_printf.c b/nuttx/lib/stdio/lib_printf.c deleted file mode 100644 index 50db06c47..000000000 --- a/nuttx/lib/stdio/lib_printf.c +++ /dev/null @@ -1,109 +0,0 @@ -/**************************************************************************** - * lib/stdio/lib_printf.c - * - * Copyright (C) 2007-2008, 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Compilation Switches - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include "lib_internal.h" - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Global Function Prototypes - ****************************************************************************/ - -/************************************************************************** - * Global Constant Data - **************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/************************************************************************** - * Private Constant Data - **************************************************************************/ - -/**************************************************************************** - * Private Variables - **************************************************************************/ - -/**************************************************************************** - * Global Functions - **************************************************************************/ - -/**************************************************************************** - * Name: printf - **************************************************************************/ - -int printf(const char *fmt, ...) -{ - va_list ap; - int ret; - - va_start(ap, fmt); -#if CONFIG_NFILE_STREAMS > 0 - ret = vfprintf(stdout, fmt, ap); -#elif CONFIG_NFILE_DESCRIPTORS > 0 - ret = lib_rawvprintf(fmt, ap); -#elif defined(CONFIG_ARCH_LOWPUTC) - ret = lib_lowvprintf(fmt, ap); -#else -# ifdef CONFIG_CPP_HAVE_WARNING -# warning "printf has no data sink" -# endif - ret = 0; -#endif - va_end(ap); - - return ret; -} - diff --git a/nuttx/lib/stdio/lib_puts.c b/nuttx/lib/stdio/lib_puts.c deleted file mode 100644 index e63a63917..000000000 --- a/nuttx/lib/stdio/lib_puts.c +++ /dev/null @@ -1,130 +0,0 @@ -/**************************************************************************** - * lib/stdio/lib_puts.c - * - * Copyright (C) 2007, 2008, 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Compilation Switches - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include "lib_internal.h" - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Global Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Public Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Public Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: puts - * - * Description: - * puts() writes the string s and a trailing newline to stdout. - * - ****************************************************************************/ - -int puts(FAR const char *s) -{ - FILE *stream = stdout; - int nwritten; - int nput = EOF; - int ret; - - /* Write the string (the next two steps must be atomic) */ - - lib_take_semaphore(stream); - - /* Write the string without its trailing '\0' */ - - nwritten = fputs(s, stream); - if (nwritten > 0) - { - /* Followed by a newline */ - - char newline = '\n'; - ret = lib_fwrite(&newline, 1, stream); - if (ret > 0) - { - nput = nwritten + 1; - - /* Flush the buffer after the newline is output. */ - -#ifdef CONFIG_STDIO_LINEBUFFER - ret = lib_fflush(stream, true); - if (ret < 0) - { - nput = EOF; - } -#endif - } - } - - lib_give_semaphore(stdout); - return nput; -} - diff --git a/nuttx/lib/stdio/lib_rawinstream.c b/nuttx/lib/stdio/lib_rawinstream.c deleted file mode 100644 index 9671a2716..000000000 --- a/nuttx/lib/stdio/lib_rawinstream.c +++ /dev/null @@ -1,107 +0,0 @@ -/**************************************************************************** - * lib/stdio/lib_rawinstream.c - * - * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 -#include -#include - -#include "lib_internal.h" - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: rawinstream_getc - ****************************************************************************/ - -static int rawinstream_getc(FAR struct lib_instream_s *this) -{ - FAR struct lib_rawinstream_s *rthis = (FAR struct lib_rawinstream_s *)this; - int nwritten; - char ch; - - DEBUGASSERT(this && rthis->fd >= 0); - - /* Attempt to read one character */ - - nwritten = read(rthis->fd, &ch, 1); - if (nwritten == 1) - { - this->nget++; - return ch; - } - - /* Return EOF on any failure to read from the incoming byte stream. The - * only expected error is EINTR meaning that the read was interrupted - * by a signal. A Zero return value would indicated an end-of-file - * confition. - */ - - return EOF; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: lib_rawinstream - * - * Description: - * Initializes a stream for use with a file descriptor. - * - * Input parameters: - * rawinstream - User allocated, uninitialized instance of struct - * lib_rawinstream_s to be initialized. - * fd - User provided file/socket descriptor (must have been opened - * for the correct access). - * - * Returned Value: - * None (User allocated instance initialized). - * - ****************************************************************************/ - -void lib_rawinstream(FAR struct lib_rawinstream_s *rawinstream, int fd) -{ - rawinstream->public.get = rawinstream_getc; - rawinstream->public.nget = 0; - rawinstream->fd = fd; -} - diff --git a/nuttx/lib/stdio/lib_rawoutstream.c b/nuttx/lib/stdio/lib_rawoutstream.c deleted file mode 100644 index ed813f87a..000000000 --- a/nuttx/lib/stdio/lib_rawoutstream.c +++ /dev/null @@ -1,115 +0,0 @@ -/**************************************************************************** - * lib/stdio/lib_rawoutstream.c - * - * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 -#include -#include - -#include "lib_internal.h" - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: rawoutstream_putc - ****************************************************************************/ - -static void rawoutstream_putc(FAR struct lib_outstream_s *this, int ch) -{ - FAR struct lib_rawoutstream_s *rthis = (FAR struct lib_rawoutstream_s *)this; - int nwritten; - char buffer = ch; - - DEBUGASSERT(this && rthis->fd >= 0); - - /* Loop until the character is successfully transferred or until an - * irrecoverable error occurs. - */ - - do - { - nwritten = write(rthis->fd, &buffer, 1); - if (nwritten == 1) - { - this->nput++; - return; - } - - /* The only expected error is EINTR, meaning that the write operation - * was awakened by a signal. Zero would not be a valid return value - * from write(). - */ - - DEBUGASSERT(nwritten < 0); - } - while (get_errno() == EINTR); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: lib_rawoutstream - * - * Description: - * Initializes a stream for use with a file descriptor. - * - * Input parameters: - * rawoutstream - User allocated, uninitialized instance of struct - * lib_rawoutstream_s to be initialized. - * fd - User provided file/socket descriptor (must have been opened - * for write access). - * - * Returned Value: - * None (User allocated instance initialized). - * - ****************************************************************************/ - -void lib_rawoutstream(FAR struct lib_rawoutstream_s *rawoutstream, int fd) -{ - rawoutstream->public.put = rawoutstream_putc; -#ifdef CONFIG_STDIO_LINEBUFFER - rawoutstream->public.flush = lib_noflush; -#endif - rawoutstream->public.nput = 0; - rawoutstream->fd = fd; -} - diff --git a/nuttx/lib/stdio/lib_rawprintf.c b/nuttx/lib/stdio/lib_rawprintf.c deleted file mode 100644 index 1a6eb16b7..000000000 --- a/nuttx/lib/stdio/lib_rawprintf.c +++ /dev/null @@ -1,166 +0,0 @@ -/**************************************************************************** - * lib/stdio/lib_rawprintf.c - * - * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 -#include -#include "lib_internal.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* Some output destinations are only available from within the kernel */ - -#if defined(CONFIG_NUTTX_KERNEL) && !defined(__KERNEL__) -# undef CONFIG_SYSLOG -# undef CONFIG_ARCH_LOWPUTC -#endif - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Global Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Global Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: lib_rawvprintf - ****************************************************************************/ - -int lib_rawvprintf(const char *fmt, va_list ap) -{ -#if defined(CONFIG_SYSLOG) - - struct lib_outstream_s stream; - - /* Wrap the low-level output in a stream object and let lib_vsprintf - * do the work. - */ - - lib_syslogstream((FAR struct lib_outstream_s *)&stream); - return lib_vsprintf((FAR struct lib_outstream_s *)&stream, fmt, ap); - -#elif CONFIG_NFILE_DESCRIPTORS > 0 - - struct lib_rawoutstream_s rawoutstream; - - /* Wrap the stdout in a stream object and let lib_vsprintf - * do the work. - */ - - lib_rawoutstream(&rawoutstream, 1); - return lib_vsprintf(&rawoutstream.public, fmt, ap); - -#elif defined(CONFIG_ARCH_LOWPUTC) - - struct lib_outstream_s stream; - - /* Wrap the low-level output in a stream object and let lib_vsprintf - * do the work. - */ - - lib_lowoutstream((FAR struct lib_outstream_s *)&stream); - return lib_vsprintf((FAR struct lib_outstream_s *)&stream, fmt, ap); - -#else - return 0; -#endif -} - -/**************************************************************************** - * Name: lib_rawprintf - ****************************************************************************/ - -int lib_rawprintf(const char *fmt, ...) -{ - va_list ap; - int ret; - -#ifdef CONFIG_DEBUG_ENABLE - ret = 0; - if (g_dbgenable) -#endif - { - va_start(ap, fmt); - ret = lib_rawvprintf(fmt, ap); - va_end(ap); - } - - return ret; -} - - -/**************************************************************************** - * Name: lib_rawvdprintf - ****************************************************************************/ - -int lib_rawvdprintf(int fd, const char *fmt, va_list ap) -{ - /* Wrap the stdout in a stream object and let lib_vsprintf - * do the work. - */ - struct lib_rawoutstream_s rawoutstream; - lib_rawoutstream(&rawoutstream, fd); - return lib_vsprintf(&rawoutstream.public, fmt, ap); -} diff --git a/nuttx/lib/stdio/lib_rdflush.c b/nuttx/lib/stdio/lib_rdflush.c deleted file mode 100644 index 35c5495c1..000000000 --- a/nuttx/lib/stdio/lib_rdflush.c +++ /dev/null @@ -1,144 +0,0 @@ -/**************************************************************************** - * lib/stdio/lib_rdflush.c - * - * Copyright (C) 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Compilation Switches - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include - -#include "lib_internal.h" - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Global Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Global Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: lib_rdflush - * - * Description: - * Flush read data from the I/O buffer and adjust the file pointer to - * account for the unread data - * - ****************************************************************************/ - -#if CONFIG_STDIO_BUFFER_SIZE > 0 -int lib_rdflush(FAR FILE *stream) -{ - if (!stream) - { - set_errno(EBADF); - return ERROR; - } - - /* Get exclusive access to the stream */ - - lib_take_semaphore(stream); - - /* If the buffer is currently being used for read access, then discard all - * of the read-ahead data. We do not support concurrent buffered read/write - * access. - */ - - if (stream->fs_bufread != stream->fs_bufstart) - { - /* Now adjust the stream pointer to account for the read-ahead data that - * was not actually read by the user. - */ - -#if CONFIG_NUNGET_CHARS > 0 - off_t rdoffset = stream->fs_bufread - stream->fs_bufpos + stream->fs_nungotten; -#else - off_t rdoffset = stream->fs_bufread - stream->fs_bufpos; -#endif - /* Mark the buffer as empty (do this before calling fseek() because fseek() - * also calls this function). - */ - - stream->fs_bufpos = stream->fs_bufread = stream->fs_bufstart; -#if CONFIG_NUNGET_CHARS > 0 - stream->fs_nungotten = 0; -#endif - /* Then seek to the position corresponding to the last data read by the user */ - - if (fseek(stream, -rdoffset, SEEK_CUR) < 0) - { - lib_give_semaphore(stream); - return ERROR; - } - } - - lib_give_semaphore(stream); - return OK; -} -#endif /* CONFIG_STDIO_BUFFER_SIZE */ - diff --git a/nuttx/lib/stdio/lib_snprintf.c b/nuttx/lib/stdio/lib_snprintf.c deleted file mode 100644 index e5ce7b0f0..000000000 --- a/nuttx/lib/stdio/lib_snprintf.c +++ /dev/null @@ -1,99 +0,0 @@ -/**************************************************************************** - * lib/stdio/lib_snprintf.c - * - * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include - -#include "lib_internal.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Global Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Global Functions - ****************************************************************************/ - -/**************************************************************************** - * sprintf - ****************************************************************************/ - -int snprintf(FAR char *buf, size_t size, const char *format, ...) -{ - struct lib_memoutstream_s memoutstream; - va_list ap; - int n; - - /* Initialize a memory stream to write to the buffer */ - - lib_memoutstream((FAR struct lib_memoutstream_s *)&memoutstream, buf, size); - - /* Then let lib_vsprintf do the real work */ - - va_start(ap, format); - n = lib_vsprintf((FAR struct lib_outstream_s *)&memoutstream.public, format, ap); - va_end(ap); - return n; -} diff --git a/nuttx/lib/stdio/lib_sprintf.c b/nuttx/lib/stdio/lib_sprintf.c deleted file mode 100644 index 89fd61033..000000000 --- a/nuttx/lib/stdio/lib_sprintf.c +++ /dev/null @@ -1,95 +0,0 @@ -/**************************************************************************** - * lib/stdio/lib_sprintf.c - * - * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 -#include "lib_internal.h" - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Global Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Global Functions - ****************************************************************************/ - -/**************************************************************************** - * sprintf - ****************************************************************************/ - -int sprintf (FAR char *buf, const char *fmt, ...) -{ - struct lib_memoutstream_s memoutstream; - va_list ap; - int n; - - /* Initialize a memory stream to write to the buffer */ - - lib_memoutstream((FAR struct lib_memoutstream_s *)&memoutstream, buf, LIB_BUFLEN_UNKNOWN); - - /* Then let lib_vsprintf do the real work */ - - va_start(ap, fmt); - n = lib_vsprintf((FAR struct lib_outstream_s *)&memoutstream.public, fmt, ap); - va_end(ap); - return n; -} diff --git a/nuttx/lib/stdio/lib_sscanf.c b/nuttx/lib/stdio/lib_sscanf.c deleted file mode 100644 index 7e1fae276..000000000 --- a/nuttx/lib/stdio/lib_sscanf.c +++ /dev/null @@ -1,507 +0,0 @@ -/**************************************************************************** - * lib/stdio/lib_sscanf.c - * - * Copyright (C) 2007, 2008, 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include -#include -#include -#include -#include -#include - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -#define MAXLN 128 - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Global Function Prototypes - ****************************************************************************/ - -int vsscanf(char *buf, const char *fmt, va_list ap); - -/************************************************************************** - * Global Constant Data - **************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/************************************************************************** - * Private Constant Data - **************************************************************************/ - -static const char spaces[] = " \t\n\r\f\v"; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Function: findwidth - * - * Description: - * Try to figure out the width of the input data. - * - ****************************************************************************/ - -static int findwidth(FAR const char *buf, FAR const char *fmt) -{ - FAR const char *next = fmt + 1; - - /* No... is there a space after the format? Or does the format string end - * here? - */ - - if (isspace(*next) || *next == 0) - { - /* Use the input up until the first white space is encountered. */ - - return strcspn(buf, spaces); - } - - /* No.. Another possibility is the the format character is followed by - * some recognizable delimiting value. - */ - - if (*next != '%') - { - /* If so we will say that the string ends there if we can find that - * delimiter in the input string. - */ - - FAR const char *ptr = strchr(buf, *next); - if (ptr) - { - return (int)(ptr - buf); - } - } - - /* No... the format has not delimiter and is back-to-back with the next - * formats (or no is following by a delimiter that does not exist in the - * input string). At this point we just bail and Use the input up until - * the first white space is encountered. - * - * NOTE: This means that values from the following format may be - * concatenated with the first. This is a bug. We have no generic way of - * determining the width of the data if there is no fieldwith, no space - * separating the input, and no usable delimiter character. - */ - - return strcspn(buf, spaces); -} - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Function: sscanf - * - * Description: - * ANSI standard sscanf implementation. - * - ****************************************************************************/ - -int sscanf(FAR const char *buf, FAR const char *fmt, ...) -{ - va_list ap; - int count; - - va_start(ap, fmt); - count = vsscanf((FAR char*)buf, fmt, ap); - va_end(ap); - return count; -} - -/**************************************************************************** - * Function: vsscanf - * - * Description: - * ANSI standard vsscanf implementation. - * - ****************************************************************************/ - -int vsscanf(FAR char *buf, FAR const char *fmt, va_list ap) -{ - FAR char *bufstart; - FAR char *tv; - FAR const char *tc; - bool lflag; - bool noassign; - int count; - int width; - int base = 10; - char tmp[MAXLN]; - - lvdbg("vsscanf: buf=\"%s\" fmt=\"%s\"\n", buf, fmt); - - /* Remember the start of the input buffer. We will need this for %n - * calculations. - */ - - bufstart = buf; - - /* Parse the format, extracting values from the input buffer as needed */ - - count = 0; - width = 0; - noassign = false; - lflag = false; - - while (*fmt && *buf) - { - /* Skip over white space */ - - while (isspace(*fmt)) - { - fmt++; - } - - /* Check for a conversion specifier */ - - if (*fmt == '%') - { - lvdbg("vsscanf: Specifier found\n"); - - /* Check for qualifiers on the conversion specifier */ - fmt++; - for (; *fmt; fmt++) - { - lvdbg("vsscanf: Processing %c\n", *fmt); - - if (strchr("dibouxcsefgn%", *fmt)) - { - break; - } - - if (*fmt == '*') - { - noassign = true; - } - else if (*fmt == 'l' || *fmt == 'L') - { - /* NOTE: Missing check for long long ('ll') */ - - lflag = true; - } - else if (*fmt >= '1' && *fmt <= '9') - { - for (tc = fmt; isdigit(*fmt); fmt++); - strncpy(tmp, tc, fmt - tc); - tmp[fmt - tc] = '\0'; - width = atoi(tmp); - fmt--; - } - } - - /* Process %s: String conversion */ - - if (*fmt == 's') - { - lvdbg("vsscanf: Performing string conversion\n"); - - while (isspace(*buf)) - { - buf++; - } - - /* Was a fieldwidth specified? */ - - if (!width) - { - /* No... Guess a field width using some heuristics */ - - width = findwidth(buf, fmt); - } - - if (!noassign) - { - tv = va_arg(ap, char*); - strncpy(tv, buf, width); - tv[width] = '\0'; - } - - buf += width; - } - - /* Process %c: Character conversion */ - - else if (*fmt == 'c') - { - lvdbg("vsscanf: Performing character conversion\n"); - - /* Was a fieldwidth specified? */ - - if (!width) - { - /* No, then width is this one single character */ - - width = 1; - } - - if (!noassign) - { - tv = va_arg(ap, char*); - strncpy(tv, buf, width); - tv[width] = '\0'; - } - - buf += width; - } - - /* Process %d, %o, %b, %x, %u: Various integer conversions */ - - else if (strchr("dobxu", *fmt)) - { - lvdbg("vsscanf: Performing integer conversion\n"); - - /* Skip over any white space before the integer string */ - - while (isspace(*buf)) - { - buf++; - } - - /* The base of the integer conversion depends on the specific - * conversion specification. - */ - - if (*fmt == 'd' || *fmt == 'u') - { - base = 10; - } - else if (*fmt == 'x') - { - base = 16; - } - else if (*fmt == 'o') - { - base = 8; - } - else if (*fmt == 'b') - { - base = 2; - } - - /* Was a fieldwidth specified? */ - - if (!width) - { - /* No... Guess a field width using some heuristics */ - - width = findwidth(buf, fmt); - } - - /* Copy the numeric string into a temporary working buffer. */ - - strncpy(tmp, buf, width); - tmp[width] = '\0'; - - lvdbg("vsscanf: tmp[]=\"%s\"\n", tmp); - - /* Perform the integer conversion */ - - buf += width; - if (!noassign) - { -#ifdef SDCC - char *endptr; - long tmplong = strtol(tmp, &endptr, base); -#else - long tmplong = strtol(tmp, NULL, base); -#endif - if (lflag) - { - long *plong = va_arg(ap, long*); - lvdbg("vsscanf: Return %ld to 0x%p\n", tmplong, plong); - *plong = tmplong; - } - else - { - int *pint = va_arg(ap, int*); - lvdbg("vsscanf: Return %ld to 0x%p\n", tmplong, pint); - *pint = (int)tmplong; - } - } - } - - /* Process %f: Floating point conversion */ - - else if (*fmt == 'f') - { -#ifndef CONFIG_LIBC_FLOATINGPOINT - /* No floating point conversions */ - - void *pv = va_arg(ap, void*); - - lvdbg("vsscanf: Return 0.0 to %p\n", pv); - *((double_t*)pv) = 0.0; -#else - lvdbg("vsscanf: Performing floating point conversion\n"); - - /* Skip over any white space before the real string */ - - while (isspace(*buf)) - { - buf++; - } - - /* Was a fieldwidth specified? */ - - if (!width) - { - /* No... Guess a field width using some heuristics */ - - width = findwidth(buf, fmt); - } - - /* Copy the real string into a temporary working buffer. */ - - strncpy(tmp, buf, width); - tmp[width] = '\0'; - buf += width; - - lvdbg("vsscanf: tmp[]=\"%s\"\n", tmp); - - /* Perform the floating point conversion */ - - if (!noassign) - { - /* strtod always returns a double */ -#ifdef SDCC - char *endptr; - double_t dvalue = strtod(tmp,&endptr); -#else - double_t dvalue = strtod(tmp, NULL); -#endif - void *pv = va_arg(ap, void*); - - lvdbg("vsscanf: Return %f to %p\n", dvalue, pv); - - /* But we have to check whether we need to return a - * float or a double. - */ - -#ifdef CONFIG_HAVE_DOUBLE - if (lflag) - { - *((double_t*)pv) = dvalue; - } - else -#endif - { - *((float*)pv) = (float)dvalue; - } - } -#endif - } - - /* Process %n: Character count */ - - else if (*fmt == 'n') - { - lvdbg("vsscanf: Performing character count\n"); - - if (!noassign) - { - size_t nchars = (size_t)(buf - bufstart); - - if (lflag) - { - long *plong = va_arg(ap, long*); - *plong = (long)nchars; - } - else - { - int *pint = va_arg(ap, int*); - *pint = (int)nchars; - } - } - } - - /* Note %n does not count as a conversion */ - - if (!noassign && *fmt != 'n') - { - count++; - } - - width = 0; - noassign = false; - lflag = false; - - fmt++; - } - - /* Its is not a conversion specifier */ - - else - { - while (isspace(*buf)) - { - buf++; - } - - if (*fmt != *buf) - { - break; - } - else - { - fmt++; - buf++; - } - } - } - - return count; -} diff --git a/nuttx/lib/stdio/lib_stdinstream.c b/nuttx/lib/stdio/lib_stdinstream.c deleted file mode 100644 index 77aab9ec8..000000000 --- a/nuttx/lib/stdio/lib_stdinstream.c +++ /dev/null @@ -1,99 +0,0 @@ -/**************************************************************************** - * lib/stdio/lib_stdinstream.c - * - * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include "lib_internal.h" - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: stdinstream_getc - ****************************************************************************/ - -static int stdinstream_getc(FAR struct lib_instream_s *this) -{ - FAR struct lib_stdinstream_s *sthis = (FAR struct lib_stdinstream_s *)this; - int ret; - - DEBUGASSERT(this); - - /* Get the next character from the incoming stream */ - - ret = getc(sthis->stream); - if (ret != EOF) - { - this->nget++; - } - - return ret; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: lib_stdinstream - * - * Description: - * Initializes a stream for use with a FILE instance. - * - * Input parameters: - * stdinstream - User allocated, uninitialized instance of struct - * lib_stdinstream_s to be initialized. - * stream - User provided stream instance (must have been opened for - * read access). - * - * Returned Value: - * None (User allocated instance initialized). - * - ****************************************************************************/ - -void lib_stdinstream(FAR struct lib_stdinstream_s *stdinstream, - FAR FILE *stream) -{ - stdinstream->public.get = stdinstream_getc; - stdinstream->public.nget = 0; - stdinstream->stream = stream; -} - - diff --git a/nuttx/lib/stdio/lib_stdoutstream.c b/nuttx/lib/stdio/lib_stdoutstream.c deleted file mode 100644 index 20da5b702..000000000 --- a/nuttx/lib/stdio/lib_stdoutstream.c +++ /dev/null @@ -1,147 +0,0 @@ -/**************************************************************************** - * lib/stdio/lib_stdoutstream.c - * - * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 -#include -#include - -#include "lib_internal.h" - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: stdoutstream_putc - ****************************************************************************/ - -static void stdoutstream_putc(FAR struct lib_outstream_s *this, int ch) -{ - FAR struct lib_stdoutstream_s *sthis = (FAR struct lib_stdoutstream_s *)this; - int result; - - DEBUGASSERT(this && sthis->stream); - - /* Loop until the character is successfully transferred or an irrecoverable - * error occurs. - */ - - do - { - result = fputc(ch, sthis->stream); - if (result != EOF) - { - this->nput++; - return; - } - - /* EINTR (meaning that fputc was interrupted by a signal) is the only - * recoverable error. - */ - } - while (get_errno() == EINTR); -} - -/**************************************************************************** - * Name: stdoutstream_flush - ****************************************************************************/ - -#if defined(CONFIG_STDIO_LINEBUFFER) && CONFIG_STDIO_BUFFER_SIZE > 0 -int stdoutstream_flush(FAR struct lib_outstream_s *this) -{ - FAR struct lib_stdoutstream_s *sthis = (FAR struct lib_stdoutstream_s *)this; - return lib_fflush(sthis->stream, true); -} -#endif - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: lib_stdoutstream - * - * Description: - * Initializes a stream for use with a FILE instance. - * - * Input parameters: - * stdoutstream - User allocated, uninitialized instance of struct - * lib_stdoutstream_s to be initialized. - * stream - User provided stream instance (must have been opened for - * write access). - * - * Returned Value: - * None (User allocated instance initialized). - * - ****************************************************************************/ - -void lib_stdoutstream(FAR struct lib_stdoutstream_s *stdoutstream, - FAR FILE *stream) -{ - /* Select the put operation */ - - stdoutstream->public.put = stdoutstream_putc; - - /* Select the correct flush operation. This flush is only called when - * a newline is encountered in the output stream. However, we do not - * want to support this line buffering behavior if the stream was - * opened in binary mode. In binary mode, the newline has no special - * meaning. - */ - -#ifdef CONFIG_STDIO_LINEBUFFER -#if CONFIG_STDIO_BUFFER_SIZE > 0 - if ((stream->fs_oflags & O_BINARY) == 0) - { - stdoutstream->public.flush = stdoutstream_flush; - } - else -#endif - { - stdoutstream->public.flush = lib_noflush; - } -#endif - - /* Set the number of bytes put to zero and remember the stream */ - - stdoutstream->public.nput = 0; - stdoutstream->stream = stream; -} - - diff --git a/nuttx/lib/stdio/lib_syslogstream.c b/nuttx/lib/stdio/lib_syslogstream.c deleted file mode 100644 index 21151b43a..000000000 --- a/nuttx/lib/stdio/lib_syslogstream.c +++ /dev/null @@ -1,122 +0,0 @@ -/**************************************************************************** - * lib/stdio/lib_syslogstream.c - * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include -#include - -#include - -#include "lib_internal.h" - -#ifdef CONFIG_SYSLOG - -/**************************************************************************** - * Pre-processor definition - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: syslogstream_putc - ****************************************************************************/ - -static void syslogstream_putc(FAR struct lib_outstream_s *this, int ch) -{ - int ret; - - /* Try writing until the write was successful or until an irrecoverable - * error occurs. - */ - - do - { - /* Write the character to the supported logging device */ - - ret = syslog_putc(ch); - if (ret == OK) - { - this->nput++; - return; - } - - /* On failure syslog_putc will return a negated errno value. The - * errno variable will not be set. The special value -EINTR means that - * syslog_putc() was awakened by a signal. This is not a real error and - * must be ignored in this context. - */ - } - while (ret == -EINTR); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: lib_syslogstream - * - * Description: - * Initializes a stream for use with the configured syslog interface. - * - * Input parameters: - * lowoutstream - User allocated, uninitialized instance of struct - * lib_lowoutstream_s to be initialized. - * - * Returned Value: - * None (User allocated instance initialized). - * - ****************************************************************************/ - -void lib_syslogstream(FAR struct lib_outstream_s *stream) -{ - stream->put = syslogstream_putc; -#ifdef CONFIG_STDIO_LINEBUFFER - stream->flush = lib_noflush; -#endif - stream->nput = 0; -} - -#endif /* CONFIG_SYSLOG */ - - diff --git a/nuttx/lib/stdio/lib_ungetc.c b/nuttx/lib/stdio/lib_ungetc.c deleted file mode 100644 index c10d4fba1..000000000 --- a/nuttx/lib/stdio/lib_ungetc.c +++ /dev/null @@ -1,121 +0,0 @@ -/**************************************************************************** - * lib/stdio/lib_ungetc.c - * - * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Compilation Switches - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include -#include -#include -#include "lib_internal.h" - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Global Function Prototypes - ****************************************************************************/ - -/************************************************************************** - * Global Constant Data - **************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/************************************************************************** - * Private Constant Data - **************************************************************************/ - -/**************************************************************************** - * Private Variables - **************************************************************************/ - -/**************************************************************************** - * Public Functions - **************************************************************************/ - -/**************************************************************************** - * Name: ungetc - **************************************************************************/ - -int ungetc(int c, FAR FILE *stream) -{ -#if CONFIG_NUNGET_CHARS > 0 - int nungotten; -#endif - - /* Stream must be open for read access */ - - if ((stream && stream->fs_filedes < 0) || - ((stream->fs_oflags & O_RDOK) == 0)) - { - set_errno(EBADF); - return EOF; - } - -#if CONFIG_NUNGET_CHARS > 0 - nungotten = stream->fs_nungotten; - if (stream->fs_nungotten < CONFIG_NUNGET_CHARS) - { - stream->fs_ungotten[nungotten] = c; - stream->fs_nungotten = nungotten + 1; - return c; - } - else -#endif - { - set_errno(ENOMEM); - return EOF; - } -} - diff --git a/nuttx/lib/stdio/lib_vdprintf.c b/nuttx/lib/stdio/lib_vdprintf.c deleted file mode 100644 index c2b576110..000000000 --- a/nuttx/lib/stdio/lib_vdprintf.c +++ /dev/null @@ -1,81 +0,0 @@ -/**************************************************************************** - * lib/stdio/lib_vdprintf.c - * - * Copyright (C) 2007-2009, 2011 Andrew Tridgell. All rights reserved. - * Author: Andrew Tridgell - * - * 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 - -#include - -#include "lib_internal.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Global Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int vdprintf(int fd, FAR const char *fmt, va_list ap) -{ - return lib_rawvdprintf(fd, fmt, ap); -} diff --git a/nuttx/lib/stdio/lib_vfprintf.c b/nuttx/lib/stdio/lib_vfprintf.c deleted file mode 100644 index 1c3a2d7fc..000000000 --- a/nuttx/lib/stdio/lib_vfprintf.c +++ /dev/null @@ -1,102 +0,0 @@ -/**************************************************************************** - * lib/stdio/lib_vfprintf.c - * - * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include - -#include "lib_internal.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Global Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -int vfprintf(FAR FILE *stream, FAR const char *fmt, va_list ap) -{ - struct lib_stdoutstream_s stdoutstream; - int n = ERROR; - - if (stream) - { - /* Wrap the stream in a stream object and let lib_vsprintf - * do the work. - */ - - lib_stdoutstream(&stdoutstream, stream); - - /* Hold the stream semaphore throughout the lib_vsprintf - * call so that this thread can get its entire message out - * before being pre-empted by the next thread. - */ - - lib_take_semaphore(stream); - n = lib_vsprintf(&stdoutstream.public, fmt, ap); - lib_give_semaphore(stream); - } - return n; -} diff --git a/nuttx/lib/stdio/lib_vprintf.c b/nuttx/lib/stdio/lib_vprintf.c deleted file mode 100644 index d085d5886..000000000 --- a/nuttx/lib/stdio/lib_vprintf.c +++ /dev/null @@ -1,92 +0,0 @@ -/**************************************************************************** - * lib/stdio/lib_vprintf.c - * - * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Compilation Switches - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Global Function Prototypes - ****************************************************************************/ - -/************************************************************************** - * Global Constant Data - **************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/************************************************************************** - * Private Constant Data - **************************************************************************/ - -/**************************************************************************** - * Private Variables - **************************************************************************/ - -/**************************************************************************** - * Public Functions - **************************************************************************/ - -/**************************************************************************** - * Name: vprintf - **************************************************************************/ - -int vprintf(FAR const char *fmt, va_list ap) -{ - /* vfprintf into stdout */ - - return vfprintf(stdout, fmt, ap); -} - diff --git a/nuttx/lib/stdio/lib_vsnprintf.c b/nuttx/lib/stdio/lib_vsnprintf.c deleted file mode 100644 index c6f52092d..000000000 --- a/nuttx/lib/stdio/lib_vsnprintf.c +++ /dev/null @@ -1,96 +0,0 @@ -/**************************************************************************** - * lib/stdio/lib_vsnprintf.c - * - * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include - -#include "lib_internal.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Global Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: vsnprintf - ****************************************************************************/ - -int vsnprintf(FAR char *buf, size_t size, const char *format, va_list ap) -{ - struct lib_memoutstream_s memoutstream; - int n; - - /* Initialize a memory stream to write to the buffer */ - - lib_memoutstream((FAR struct lib_memoutstream_s *)&memoutstream, buf, size); - - /* Then let lib_vsprintf do the real work */ - - n = lib_vsprintf((FAR struct lib_outstream_s *)&memoutstream.public, format, ap); - return n; -} diff --git a/nuttx/lib/stdio/lib_vsprintf.c b/nuttx/lib/stdio/lib_vsprintf.c deleted file mode 100644 index 5db46664e..000000000 --- a/nuttx/lib/stdio/lib_vsprintf.c +++ /dev/null @@ -1,92 +0,0 @@ -/**************************************************************************** - * lib/stdio/lib_vsprintf.c - * - * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include - -#include "lib_internal.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Global Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: vsprintf - ****************************************************************************/ - -int vsprintf(FAR char *dest, const char *src, va_list ap) -{ - struct lib_memoutstream_s memoutstream; - - /* Wrap the destination buffer in a stream object and let - * lib/stdio/lib_vsprintf do the work. - */ - - lib_memoutstream((FAR struct lib_memoutstream_s *)&memoutstream, dest, LIB_BUFLEN_UNKNOWN); - return lib_vsprintf((FAR struct lib_outstream_s *)&memoutstream.public, src, ap); -} diff --git a/nuttx/lib/stdio/lib_wrflush.c b/nuttx/lib/stdio/lib_wrflush.c deleted file mode 100644 index 39680da6a..000000000 --- a/nuttx/lib/stdio/lib_wrflush.c +++ /dev/null @@ -1,134 +0,0 @@ -/**************************************************************************** - * lib/stdio/lib_wrflush.c - * - * Copyright (C) 2008-2009, 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include -#include - -#include "lib_internal.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Global Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: lib_wrflush - * - * Description: - * This is simply a version of fflush that does not report an error if - * the file is not open for writing. - * - ****************************************************************************/ - -int lib_wrflush(FAR FILE *stream) -{ -#if CONFIG_STDIO_BUFFER_SIZE > 0 - /* Verify that we were passed a valid (i.e., non-NULL) stream */ - -#ifdef CONFIG_DEBUG - if (!stream) - { - return -EINVAL; - } -#endif - - /* Verify that the stream is opened for writing... lib_fflush will - * return an error if it is called for a stream that is not opened for - * writing. Check that first so that this function will not fail in - * that case. - */ - - if ((stream->fs_oflags & O_WROK) == 0) - { - /* Report that the success was successful if we attempt to flush a - * read-only stream. - */ - - return OK; - } - - /* Flush the stream. Return success if there is no buffered write data - * -- i.e., that the stream is opened for writing and that all of the - * buffered write data was successfully flushed by lib_fflush(). - */ - - return lib_fflush(stream, true); -#else - /* Verify that we were passed a valid (i.e., non-NULL) stream */ - -#ifdef CONFIG_DEBUG - if (!stream) - { - return -EINVAL; - } -#endif - - return OK; -#endif -} diff --git a/nuttx/lib/stdio/lib_zeroinstream.c b/nuttx/lib/stdio/lib_zeroinstream.c deleted file mode 100644 index 39a6c22ef..000000000 --- a/nuttx/lib/stdio/lib_zeroinstream.c +++ /dev/null @@ -1,79 +0,0 @@ -/**************************************************************************** - * lib/stdio/lib_zeroinstream.c - * - * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 -#include -#include "lib_internal.h" - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static int zeroinstream_getc(FAR struct lib_instream_s *this) -{ - this->nget++; - return 0; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: lib_zeroinstream - * - * Description: - * Initializes a NULL stream. The initialized stream will return an - * infinitely long stream of zeroes. - * - * Input parameters: - * zeroinstream - User allocated, uninitialized instance of struct - * lib_instream_s to be initialized. - * - * Returned Value: - * None (User allocated instance initialized). - * - ****************************************************************************/ - -void lib_zeroinstream(FAR struct lib_instream_s *zeroinstream) -{ - zeroinstream->get = zeroinstream_getc; - zeroinstream->nget = 0; -} - diff --git a/nuttx/lib/stdlib/Make.defs b/nuttx/lib/stdlib/Make.defs deleted file mode 100644 index 76e285808..000000000 --- a/nuttx/lib/stdlib/Make.defs +++ /dev/null @@ -1,44 +0,0 @@ -############################################################################ -# lib/stdlib/Make.defs -# -# Copyright (C) 2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt -# -# 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. -# -############################################################################ - -# Add the stdlib C files to the build - -CSRCS += lib_abs.c lib_abort.c lib_imaxabs.c lib_labs.c lib_llabs.c \ - lib_rand.c lib_qsort.c - -# Add the stdlib directory to the build - -DEPPATH += --dep-path stdlib -VPATH += :stdlib diff --git a/nuttx/lib/stdlib/lib_abort.c b/nuttx/lib/stdlib/lib_abort.c deleted file mode 100644 index 84b600950..000000000 --- a/nuttx/lib/stdlib/lib_abort.c +++ /dev/null @@ -1,121 +0,0 @@ -/************************************************************************ - * lib/stdlib/lib_abort.c - * - * Copyright (C) 2007, 2009, 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include - -/************************************************************************ - * Pre-processor Definitions - ************************************************************************/ - -/************************************************************************ - * Private Type Declarations - ************************************************************************/ - -/************************************************************************ - * Global Variables - ************************************************************************/ - -/************************************************************************ - * Private Variables - ************************************************************************/ - -/************************************************************************ - * Private Function Prototypes - ************************************************************************/ - -/************************************************************************ - * Private Functions - ************************************************************************/ - -/************************************************************************ - * Public Functions - ************************************************************************/ - -/************************************************************************ - * Name: Abort - * - * Description: - * The abort() first unblocks the SIGABRT signal, and then raises that - * signal for the calling process. This results in the abnormal - * termination of the process unless the SIGABRT signal is caught and - * the signal handler does not return. - * - * If the abort() function causes process termination, all open - * streams are closed and flushed. - * - * If the SIGABRT signal is ignored, or caught by a handler that - * returns, the abort() function will still terminate the process. - * It does this by restoring the default disposition for SIGABRT and - * then raising the signal for a second time. - * - * Input parameters: - * None - * - * Returned Value: - * This function does not return, - * - ************************************************************************/ - -void abort(void) -{ - /* NuttX does not support standard signal functionality (like the - * behavior of the SIGABRT signal). So no attempt is made to provide - * a conformant version of abort() at this time. This version does not - * signal the calling thread all. - * - * Note that pthread_exit() is called instead of exit(). That is because - * we do no know if abort was called from a pthread or a normal thread - * (we could find out, of course). If abort() is called from a non-pthread, - * then pthread_exit() should fail and fall back to call exit() anyway. - * - * If exit() is called (either below or via pthread_exit()), then exit() - * will flush and close all open files and terminate the thread. If this - * function was called from a pthread, then pthread_exit() will complete - * any joins, but will not flush or close any streams. - */ - -#ifdef CONFIG_DISABLE_PTHREAD - exit(EXIT_FAILURE); -#else - pthread_exit(NULL); -#endif -} diff --git a/nuttx/lib/stdlib/lib_abs.c b/nuttx/lib/stdlib/lib_abs.c deleted file mode 100644 index 1a0c1671c..000000000 --- a/nuttx/lib/stdlib/lib_abs.c +++ /dev/null @@ -1,54 +0,0 @@ -/************************************************************************ - * lib/stdlib/lib_abs.c - * - * Copyright (C) 2010-2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 -#include - -/************************************************************************ - * Global Functions - ************************************************************************/ - -int abs(int j) -{ - if (j < 0) - { - j = -j; - } - return j; -} diff --git a/nuttx/lib/stdlib/lib_imaxabs.c b/nuttx/lib/stdlib/lib_imaxabs.c deleted file mode 100644 index c6e227c7d..000000000 --- a/nuttx/lib/stdlib/lib_imaxabs.c +++ /dev/null @@ -1,54 +0,0 @@ -/************************************************************************ - * lib/stdlib//lib_abs.c - * - * Copyright (C) 2010-2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 -#include - -/************************************************************************ - * Global Functions - ************************************************************************/ - -intmax_t imaxabs(intmax_t j) -{ - if (j < 0) - { - j = -j; - } - return j; -} diff --git a/nuttx/lib/stdlib/lib_labs.c b/nuttx/lib/stdlib/lib_labs.c deleted file mode 100644 index f7218ee83..000000000 --- a/nuttx/lib/stdlib/lib_labs.c +++ /dev/null @@ -1,54 +0,0 @@ -/************************************************************************ - * lib/stdlib/lib_labs.c - * - * Copyright (C) 2010-2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 -#include - -/************************************************************************ - * Global Functions - ************************************************************************/ - -long int labs(long int j) -{ - if (j < 0) - { - j = -j; - } - return j; -} diff --git a/nuttx/lib/stdlib/lib_llabs.c b/nuttx/lib/stdlib/lib_llabs.c deleted file mode 100644 index db7d3dbe0..000000000 --- a/nuttx/lib/stdlib/lib_llabs.c +++ /dev/null @@ -1,57 +0,0 @@ -/************************************************************************ - * lib/stdlib/lib_llabs.c - * - * Copyright (C) 2010-2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 -#include -#include - -/************************************************************************ - * Global Functions - ************************************************************************/ - -#ifdef CONFIG_HAVE_LONG_LONG -long long int llabs(long long int j) -{ - if (j < 0) - { - j = -j; - } - return j; -} -#endif diff --git a/nuttx/lib/stdlib/lib_qsort.c b/nuttx/lib/stdlib/lib_qsort.c deleted file mode 100644 index 9dd5c0040..000000000 --- a/nuttx/lib/stdlib/lib_qsort.c +++ /dev/null @@ -1,238 +0,0 @@ -/**************************************************************************** - * lib/stdlib/lib_qsort.c - * - * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Leveraged from: - * - * Copyright (c) 1992, 1993 - * The Regents of the University of California. All rights reserved. - * - * 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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University 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 REGENTS 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 REGENTS 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 - -#include -#include - -/**************************************************************************** - * Preprocessor Definitions - ****************************************************************************/ - -#define min(a, b) (a) < (b) ? a : b - -#define swapcode(TYPE, parmi, parmj, n) \ - { \ - long i = (n) / sizeof (TYPE); \ - register TYPE *pi = (TYPE *) (parmi); \ - register TYPE *pj = (TYPE *) (parmj); \ - do { \ - register TYPE t = *pi; \ - *pi++ = *pj; \ - *pj++ = t; \ - } while (--i > 0); \ - } - -#define SWAPINIT(a, size) \ - swaptype = ((char *)a - (char *)0) % sizeof(long) || \ - size % sizeof(long) ? 2 : size == sizeof(long)? 0 : 1; - -#define swap(a, b) \ - if (swaptype == 0) \ - { \ - long t = *(long *)(a); \ - *(long *)(a) = *(long *)(b); \ - *(long *)(b) = t; \ - } \ - else \ - { \ - swapfunc(a, b, size, swaptype); \ - } - -#define vecswap(a, b, n) if ((n) > 0) swapfunc(a, b, n, swaptype) - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static inline void swapfunc(char *a, char *b, int n, int swaptype); -static inline char *med3(char *a, char *b, char *c, - int (*compar)(const void *, const void *)); - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static inline void swapfunc(char *a, char *b, int n, int swaptype) -{ - if(swaptype <= 1) - { - swapcode(long, a, b, n) - } - else - { - swapcode(char, a, b, n) - } -} - -static inline char *med3(char *a, char *b, char *c, - int (*compar)(const void *, const void *)) -{ - return compar(a, b) < 0 ? - (compar(b, c) < 0 ? b : (compar(a, c) < 0 ? c : a )) - :(compar(b, c) > 0 ? b : (compar(a, c) < 0 ? a : c )); -} - -/**************************************************************************** - * Public Function - ****************************************************************************/ - -/**************************************************************************** - * Name: qsort - * - * Description: - * Qsort routine from Bentley & McIlroy's "Engineering a Sort Function". - * - ****************************************************************************/ - -void qsort(void *base, size_t nmemb, size_t size, - int(*compar)(const void *, const void *)) -{ - char *pa, *pb, *pc, *pd, *pl, *pm, *pn; - int d, r, swaptype, swap_cnt; - -loop: - SWAPINIT(base, size); - swap_cnt = 0; - if (nmemb < 7) - { - for (pm = (char *) base + size; pm < (char *) base + nmemb * size; pm += size) - { - for (pl = pm; pl > (char *) base && compar(pl - size, pl) > 0; pl -= size) - { - swap(pl, pl - size); - } - } - return; - } - - pm = (char *) base + (nmemb / 2) * size; - if (nmemb > 7) - { - pl = base; - pn = (char *) base + (nmemb - 1) * size; - if (nmemb > 40) - { - d = (nmemb / 8) * size; - pl = med3(pl, pl + d, pl + 2 * d, compar); - pm = med3(pm - d, pm, pm + d, compar); - pn = med3(pn - 2 * d, pn - d, pn, compar); - } - pm = med3(pl, pm, pn, compar); - } - swap(base, pm); - pa = pb = (char *) base + size; - - pc = pd = (char *) base + (nmemb - 1) * size; - for (;;) - { - while (pb <= pc && (r = compar(pb, base)) <= 0) - { - if (r == 0) - { - swap_cnt = 1; - swap(pa, pb); - pa += size; - } - pb += size; - } - while (pb <= pc && (r = compar(pc, base)) >= 0) - { - if (r == 0) - { - swap_cnt = 1; - swap(pc, pd); - pd -= size; - } - pc -= size; - } - - if (pb > pc) - { - break; - } - - swap(pb, pc); - swap_cnt = 1; - pb += size; - pc -= size; - } - - if (swap_cnt == 0) - { - /* Switch to insertion sort */ - - for (pm = (char *) base + size; pm < (char *) base + nmemb * size; pm += size) - { - for (pl = pm; pl > (char *) base && compar(pl - size, pl) > 0; pl -= size) - { - swap(pl, pl - size); - } - } - return; - } - - pn = (char *) base + nmemb * size; - r = min(pa - (char *)base, pb - pa); - vecswap(base, pb - r, r); - r = min(pd - pc, pn - pd - size); - vecswap(pb, pn - r, r); - - if ((r = pb - pa) > size) - { - qsort(base, r / size, size, compar); - } - - if ((r = pd - pc) > size) - { - /* Iterate rather than recurse to save stack space */ - base = pn - r; - nmemb = r / size; - goto loop; - } -} - diff --git a/nuttx/lib/stdlib/lib_rand.c b/nuttx/lib/stdlib/lib_rand.c deleted file mode 100644 index 7227c52d0..000000000 --- a/nuttx/lib/stdlib/lib_rand.c +++ /dev/null @@ -1,220 +0,0 @@ -/************************************************************ - * lib/stdlib/lib_rand.c - * - * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ************************************************************/ - -/************************************************************ - * Compilation Switches - ************************************************************/ - -/************************************************************ - * Included Files - ************************************************************/ - -#include -#include - -/************************************************************ - * Definitions - ************************************************************/ - -#ifndef CONFIG_LIB_RAND_ORDER -#define CONFIG_LIB_RAND_ORDER 1 -#endif - -/* Values needed by the random number generator */ - -#define RND1_CONSTK 470001 -#define RND1_CONSTP 999563 -#define RND2_CONSTK1 366528 -#define RND2_CONSTK2 508531 -#define RND2_CONSTP 998917 -#define RND3_CONSTK1 360137 -#define RND3_CONSTK2 519815 -#define RND3_CONSTK3 616087 -#define RND3_CONSTP 997783 - -#if CONFIG_LIB_RAND_ORDER == 1 -# define RND_CONSTP RND1_CONSTP -#elif CONFIG_LIB_RAND_ORDER == 2 -# define RND_CONSTP RND2_CONSTP -#else -# define RND_CONSTP RND3_CONSTP -#endif - -/************************************************************ - * Private Type Declarations - ************************************************************/ - -/************************************************************ - * Private Function Prototypes - ************************************************************/ - -static unsigned int nrand(unsigned int nLimit); -static double_t frand1(void); -#if (CONFIG_LIB_RAND_ORDER > 1) -static double_t frand2(void); -#if (CONFIG_LIB_RAND_ORDER > 2) -static double_t frand3(void); -#endif -#endif - -/********************************************************** - * Global Constant Data - **********************************************************/ - -/************************************************************ - * Global Variables - ************************************************************/ - -/********************************************************** - * Private Constant Data - **********************************************************/ - -/************************************************************ - * Private Variables - ************************************************************/ - -static unsigned long g_nRandInt1; -#if (CONFIG_LIB_RAND_ORDER > 1) -static unsigned long g_nRandInt2; -#if (CONFIG_LIB_RAND_ORDER > 2) -static unsigned long g_nRandInt3; -#endif -#endif - -/************************************************************ - * Private Functions - ************************************************************/ - -static unsigned int nrand(unsigned int nLimit) -{ - unsigned long nResult; - double_t fRatio; - - /* Loop to be sure a legal random number is generated */ - do { - - /* Get a random integer in the requested range */ -#if (CONFIG_LIB_RAND_ORDER == 1) - fRatio = frand1(); -#elif (CONFIG_LIB_RAND_ORDER == 2) - fRatio = frand2(); -#else - fRatio = frand3(); -#endif - - /* Then, produce the return-able value */ - nResult = (unsigned long)(((double_t)nLimit) * fRatio); - - } while (nResult >= (unsigned long)nLimit); - - return (unsigned int)nResult; - -} /* end nrand */ - -static double_t frand1(void) -{ - unsigned long nRandInt; - - /* First order congruential generator */ - nRandInt = (RND1_CONSTK * g_nRandInt1) % RND1_CONSTP; - g_nRandInt1 = nRandInt; - - /* Construct an floating point value in the range from 0.0 up to 1.0 */ - return ((double_t)nRandInt) / ((double_t)RND_CONSTP); - -} /* end frand */ - -#if (CONFIG_LIB_RAND_ORDER > 1) -static double_t frand2(void) -{ - unsigned long nRandInt; - - /* Second order congruential generator */ - nRandInt = (RND2_CONSTK1 * g_nRandInt1 + RND2_CONSTK2 * g_nRandInt2) % - RND2_CONSTP; - g_nRandInt2 = g_nRandInt1; - g_nRandInt1 = nRandInt; - - /* Construct an floating point value in the range from 0.0 up to 1.0 */ - return ((double_t)nRandInt) / ((double_t)RND_CONSTP); - -} /* end frand */ - -#if (CONFIG_LIB_RAND_ORDER > 2) -static double_t frand3(void) -{ - unsigned long nRandInt; - - /* Third order congruential generator */ - nRandInt = (RND3_CONSTK1 * g_nRandInt1 + RND3_CONSTK2 * g_nRandInt2 + - RND3_CONSTK2 * g_nRandInt3) % RND3_CONSTP; - g_nRandInt3 = g_nRandInt2; - g_nRandInt2 = g_nRandInt1; - g_nRandInt1 = nRandInt; - - /* Construct an floating point value in the range from 0.0 up to 1.0 */ - return ((double_t)nRandInt) / ((double_t)RND_CONSTP); - -} /* end frand */ -#endif -#endif - -/************************************************************ - * Public Functions - ************************************************************/ -/************************************************************ - * Function: srand, rand - ************************************************************/ - -void srand(unsigned int seed) -{ - g_nRandInt1 = seed; -#if (CONFIG_LIB_RAND_ORDER > 1) - g_nRandInt2 = seed; - (void)frand1(); -#if (CONFIG_LIB_RAND_ORDER > 2) - g_nRandInt3 = seed; - (void)frand2(); -#endif -#endif - -} /* end srand */ - -int rand(void) -{ - return (int)nrand(32768); - -} /* end rand */ - diff --git a/nuttx/lib/string/Make.defs b/nuttx/lib/string/Make.defs deleted file mode 100644 index 6b21c7f14..000000000 --- a/nuttx/lib/string/Make.defs +++ /dev/null @@ -1,50 +0,0 @@ -############################################################################ -# lib/string/Make.defs -# -# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt -# -# 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. -# -############################################################################ - -# Add the string C files to the build - -CSRCS += lib_checkbase.c lib_isbasedigit.c lib_memset.c lib_memchr.c \ - lib_memccpy.c lib_memcpy.c lib_memcmp.c lib_memmove.c lib_skipspace.c \ - lib_strcasecmp.c lib_strcat.c lib_strchr.c lib_strcpy.c lib_strcmp.c \ - lib_strcspn.c lib_strdup.c lib_strerror.c lib_strlen.c lib_strnlen.c \ - lib_strncasecmp.c lib_strncat.c lib_strncmp.c lib_strncpy.c \ - lib_strndup.c lib_strcasestr.c lib_strpbrk.c lib_strrchr.c\ - lib_strspn.c lib_strstr.c lib_strtok.c lib_strtokr.c lib_strtol.c \ - lib_strtoll.c lib_strtoul.c lib_strtoull.c lib_strtod.c - -# Add the string directory to the build - -DEPPATH += --dep-path string -VPATH += :string diff --git a/nuttx/lib/string/lib_checkbase.c b/nuttx/lib/string/lib_checkbase.c deleted file mode 100644 index bc79ab2ce..000000000 --- a/nuttx/lib/string/lib_checkbase.c +++ /dev/null @@ -1,115 +0,0 @@ -/**************************************************************************** - * lib/string/lib_checkbase.c - * - * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include - -#include "lib_internal.h" - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: lib_checkbase - * - * Description: - * This is part of the strol() family implementation. This function checks - * the initial part of a string to see if it can determine the numeric - * base that is represented. - * - * Assumptions: - * *ptr points to the first, non-whitespace character in the string. - * - ****************************************************************************/ - -int lib_checkbase(int base, const char **pptr) -{ - const char *ptr = *pptr; - - /* Check for unspecified base */ - - if (!base) - { - /* Assume base 10 */ - - base = 10; - - /* Check for leading '0' - that would signify octal or hex (or binary) */ - - if (*ptr == '0') - { - /* Assume octal */ - - base = 8; - ptr++; - - /* Check for hexidecimal */ - - if ((*ptr == 'X' || *ptr == 'x') && - lib_isbasedigit(ptr[1], 16, NULL)) - { - base = 16; - ptr++; - } - } - } - - /* If it a hexidecimal representation, than discard any leading "0X" or "0x" */ - - else if (base == 16) - { - if (ptr[0] == '0' && (ptr[1] == 'X' || ptr[1] == 'x')) - { - ptr += 2; - } - } - - /* Return the updated pointer and base */ - - *pptr = ptr; - return base; -} - diff --git a/nuttx/lib/string/lib_isbasedigit.c b/nuttx/lib/string/lib_isbasedigit.c deleted file mode 100644 index a2421bf2a..000000000 --- a/nuttx/lib/string/lib_isbasedigit.c +++ /dev/null @@ -1,105 +0,0 @@ -/**************************************************************************** - * lib/string/lib_isbasedigit.c - * - * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include -#include - -#include "lib_internal.h" - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: lib_isbasedigit - * - * Description: - * Given an ASCII character, ch, and a base (1-36) do two - * things: 1) Determine if ch is a valid charcter, and 2) - * convert ch to its binary value. - * - ****************************************************************************/ - -bool lib_isbasedigit(int ch, int base, int *value) -{ - bool ret = false; - int tmp = 0; - - if (base <= 10) - { - if (ch >= '0' && ch <= base + '0' - 1) - { - tmp = ch - '0'; - ret = true; - } - } - else if (base <= 36) - { - if (ch >= '0' && ch <= '9') - { - tmp = ch - '0'; - ret = true; - } - else if (ch >= 'a' && ch <= 'a' + base - 11) - { - tmp = ch - 'a' + 10; - ret = true; - } - else if (ch >= 'A' && ch <= 'A' + base - 11) - { - tmp = ch - 'A' + 10; - ret = true; - } - } - - if (value) - { - *value = tmp; - } - return ret; -} - - diff --git a/nuttx/lib/string/lib_memccpy.c b/nuttx/lib/string/lib_memccpy.c deleted file mode 100644 index 1f3dbb52d..000000000 --- a/nuttx/lib/string/lib_memccpy.c +++ /dev/null @@ -1,99 +0,0 @@ -/**************************************************************************** - * lib/string/lib_memccpy.c - * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Compilation Switches - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include - -/**************************************************************************** - * Global Functions - ****************************************************************************/ - - -/**************************************************************************** - * Name: memccpy - * - * Description: - * The memccpy() function copies bytes from memory area s2 into s1, - * stopping after the first occurrence of byte c (converted to an unsigned - * char) is copied, or after n bytes are copied, whichever comes first. If - * copying takes place between objects that overlap, the behavior is - * undefined. - * - * Returned Value: - * The memccpy() function returns a pointer to the byte after the copy of c - * in s1, or a null pointer if c was not found in the first n bytes of s2. - * - ****************************************************************************/ - -FAR void *memccpy(FAR void *s1, FAR const void *s2, int c, size_t n) -{ - FAR unsigned char *pout = (FAR unsigned char*)s1; - FAR unsigned char *pin = (FAR unsigned char*)s2; - - /* Copy at most n bytes */ - - while (n-- > 0) - { - /* Copy one byte */ - - *pout = *pin++; - - /* Did we just copy the terminating byte c? */ - - if (*pout == (unsigned char)c) - { - /* Yes return a pointer to the byte after the copy of c into s1 */ - - return (FAR void *)pout; - } - - /* No increment to the next destination location */ - - pout++; - } - - /* C was not found in the first n bytes of s2 */ - - return NULL; -} diff --git a/nuttx/lib/string/lib_memchr.c b/nuttx/lib/string/lib_memchr.c deleted file mode 100644 index e0dec8270..000000000 --- a/nuttx/lib/string/lib_memchr.c +++ /dev/null @@ -1,80 +0,0 @@ -/**************************************************************************** - * lib/string/lib_memchr.c - * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include - -/**************************************************************************** - * Global Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: memchr - * - * Description: - * The memchr() function locates the first occurrence of 'c' (converted to - * an unsigned char) in the initial 'n' bytes (each interpreted as - * unsigned char) of the object pointed to by s. - * - * Returned Value: - * The memchr() function returns a pointer to the located byte, or a null - * pointer if the byte does not occur in the object. - * - ****************************************************************************/ - -FAR void *memchr(FAR const void *s, int c, size_t n) -{ - FAR const unsigned char *p = (FAR const unsigned char *)s; - - if (s) - { - while (n--) - { - if (*p == (unsigned char)c) - { - return (FAR void *)p; - } - - p++; - } - } - - return NULL; -} diff --git a/nuttx/lib/string/lib_memcmp.c b/nuttx/lib/string/lib_memcmp.c deleted file mode 100644 index eb2e1fd12..000000000 --- a/nuttx/lib/string/lib_memcmp.c +++ /dev/null @@ -1,74 +0,0 @@ -/************************************************************ - * lib/string/lib_memcmp.c - * - * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ************************************************************/ - -/************************************************************ - * Compilation Switches - ************************************************************/ - -/************************************************************ - * Included Files - ************************************************************/ - -#include -#include -#include - -/************************************************************ - * Global Functions - ************************************************************/ - -#ifndef CONFIG_ARCH_MEMCMP -int memcmp(const void *s1, const void *s2, size_t n) -{ - unsigned char *p1 = (unsigned char *)s1; - unsigned char *p2 = (unsigned char *)s2; - - while (n-- > 0) - { - if (*p1 < *p2) - { - return -1; - } - else if (*p1 > *p2) - { - return 1; - } - - p1++; - p2++; - } - return 0; -} -#endif diff --git a/nuttx/lib/string/lib_memcpy.c b/nuttx/lib/string/lib_memcpy.c deleted file mode 100644 index 3b62edbab..000000000 --- a/nuttx/lib/string/lib_memcpy.c +++ /dev/null @@ -1,64 +0,0 @@ -/**************************************************************************** - * lib/string/lib_memcpy.c - * - * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Compilation Switches - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include - -/**************************************************************************** - * Global Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: memcpy - ****************************************************************************/ - -#ifndef CONFIG_ARCH_MEMCPY -FAR void *memcpy(FAR void *dest, FAR const void *src, size_t n) -{ - FAR unsigned char *pout = (FAR unsigned char*)dest; - FAR unsigned char *pin = (FAR unsigned char*)src; - while (n-- > 0) *pout++ = *pin++; - return dest; -} -#endif diff --git a/nuttx/lib/string/lib_memmove.c b/nuttx/lib/string/lib_memmove.c deleted file mode 100644 index ecaeb54cf..000000000 --- a/nuttx/lib/string/lib_memmove.c +++ /dev/null @@ -1,72 +0,0 @@ -/************************************************************ - * lib/string/lib_memmove.c - * - * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ************************************************************/ - -/************************************************************ - * Compilation Switches - ************************************************************/ - -/************************************************************ - * Included Files - ************************************************************/ - -#include -#include -#include - -/************************************************************ - * Global Functions - ************************************************************/ - -#ifndef CONFIG_ARCH_MEMMOVE -void *memmove(void *dest, const void *src, size_t count) -{ - char *tmp, *s; - if (dest <= src) - { - tmp = (char*) dest; - s = (char*) src; - while (count--) - *tmp++ = *s++; - } - else - { - tmp = (char*) dest + count; - s = (char*) src + count; - while (count--) - *--tmp = *--s; - } - return dest; -} -#endif diff --git a/nuttx/lib/string/lib_memset.c b/nuttx/lib/string/lib_memset.c deleted file mode 100644 index 916351b97..000000000 --- a/nuttx/lib/string/lib_memset.c +++ /dev/null @@ -1,59 +0,0 @@ -/************************************************************ - * lib/string/lib_memset.c - * - * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ************************************************************/ - -/************************************************************ - * Compilation Switches - ************************************************************/ - -/************************************************************ - * Included Files - ************************************************************/ - -#include -#include -#include - -/************************************************************ - * Global Functions - ************************************************************/ - -#ifndef CONFIG_ARCH_MEMSET -void *memset(void *s, int c, size_t n) -{ - unsigned char *p = (unsigned char*)s; - while (n-- > 0) *p++ = c; - return s; -} -#endif diff --git a/nuttx/lib/string/lib_skipspace.c b/nuttx/lib/string/lib_skipspace.c deleted file mode 100644 index b4e6588e5..000000000 --- a/nuttx/lib/string/lib_skipspace.c +++ /dev/null @@ -1,69 +0,0 @@ -/**************************************************************************** - * lib/string/lib_skipspace.c - * - * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include -#include "lib_internal.h" - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: lib_skipspace - * - * Description: - * Skip over leading whitespace - * - ****************************************************************************/ - -void lib_skipspace(const char **pptr) -{ - const char *ptr = *pptr; - while (isspace(*ptr)) ptr++; - *pptr = ptr; -} - - diff --git a/nuttx/lib/string/lib_strcasecmp.c b/nuttx/lib/string/lib_strcasecmp.c deleted file mode 100644 index d4aa8cc03..000000000 --- a/nuttx/lib/string/lib_strcasecmp.c +++ /dev/null @@ -1,65 +0,0 @@ -/**************************************************************************** - * lib/string/lib_strcasecmp.c - * - * Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include - -/**************************************************************************** - * Public Functions - *****************************************************************************/ - -#ifndef CONFIG_ARCH_STRCMP -int strcasecmp(const char *cs, const char *ct) -{ - int result; - for (;;) - { - if ((result = (int)toupper(*cs) - (int)toupper(*ct)) != 0 || !*cs) - { - break; - } - - cs++; - ct++; - } - return result; -} -#endif diff --git a/nuttx/lib/string/lib_strcasestr.c b/nuttx/lib/string/lib_strcasestr.c deleted file mode 100644 index 23f0ab57e..000000000 --- a/nuttx/lib/string/lib_strcasestr.c +++ /dev/null @@ -1,134 +0,0 @@ -/**************************************************************************** - * lib/string/lib_strstr.c - * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use str 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 str binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer str - * 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 - -#include -#include - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static FAR char *strcasechr(FAR const char *s, int uc) -{ - register char ch; - - if (s) - { - for (; *s; s++) - { - ch = *s; - if (toupper(ch) == uc) - { - return (FAR char*)s; - } - } - } - - return NULL; -} - -/**************************************************************************** - * Global Functions - ****************************************************************************/ - -FAR char *strcasestr(FAR const char *str, FAR const char *substr) -{ - const char *candidate; /* Candidate in str with matching start character */ - char ch; /* First character of the substring */ - int len; /* The length of the substring */ - - /* Special case the empty substring */ - - len = strlen(substr); - ch = *substr; - - if (!ch) - { - /* We'll say that an empty substring matches at the beginning of - * the string - */ - - return (char*)str; - } - - /* Search for the substring */ - - candidate = str; - ch = toupper(ch); - - for (;;) - { - /* strcasechr() will return a pointer to the next occurrence of the - * character ch in the string (ignoring case) - */ - - candidate = strcasechr(candidate, ch); - if (!candidate || strlen(candidate) < len) - { - /* First character of the substring does not appear in the string - * or the remainder of the string is not long enough to contain the - * substring. - */ - - return NULL; - } - - /* Check if this is the beginning of a matching substring (ignoring case) */ - - if (strncasecmp(candidate, substr, len) == 0) - { - /* Yes.. return the pointer to the first occurrence of the matching - * substring. - */ - - return (char*)candidate; - } - - /* No, find the next candidate after this one */ - - candidate++; - } - - /* Won't get here, but some compilers might complain */ - - return NULL; -} - diff --git a/nuttx/lib/string/lib_strcat.c b/nuttx/lib/string/lib_strcat.c deleted file mode 100644 index 20350fec0..000000000 --- a/nuttx/lib/string/lib_strcat.c +++ /dev/null @@ -1,62 +0,0 @@ -/**************************************************************************** - * lib/string/lib_strcat.c - * - * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include - -/**************************************************************************** - * Global Functions - ****************************************************************************/ - -#ifndef CONFIG_ARCH_STRCAT -char *strcat(char *dest, const char *src) -{ - char *ret = dest; - - dest += strlen(dest); - while (*src != '\0') - { - *dest++ = *src++; - } - *dest = '\0'; - - return ret; -} -#endif diff --git a/nuttx/lib/string/lib_strchr.c b/nuttx/lib/string/lib_strchr.c deleted file mode 100644 index ad7273862..000000000 --- a/nuttx/lib/string/lib_strchr.c +++ /dev/null @@ -1,76 +0,0 @@ -/**************************************************************************** - * lib/string/lib_strchr.c - * - * Copyright (C) 2007, 2009, 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include - -/**************************************************************************** - * Global Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: strchr - * - * Description: - * The strchr() function locates the first occurrence of 'c' (converted to - * a char) in the string pointed to by 's'. The terminating null byte is - * considered to be part of the string. - * - * Returned Value: - * Upon completion, strchr() returns a pointer to the byte, or a null - * pointer if the byte was not found. - * - ****************************************************************************/ - -FAR char *strchr(FAR const char *s, int c) -{ - if (s) - { - for (; *s; s++) - { - if (*s == c) - { - return (FAR char *)s; - } - } - } - - return NULL; -} diff --git a/nuttx/lib/string/lib_strcmp.c b/nuttx/lib/string/lib_strcmp.c deleted file mode 100644 index 0e3eee890..000000000 --- a/nuttx/lib/string/lib_strcmp.c +++ /dev/null @@ -1,59 +0,0 @@ -/**************************************************************************** - * lib/string/lib_strcmp.c - * - * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include - -/**************************************************************************** - * Public Functions - *****************************************************************************/ - -#ifndef CONFIG_ARCH_STRCMP -int strcmp(const char *cs, const char *ct) -{ - register signed char result; - for (;;) - { - if ((result = *cs - *ct++) != 0 || !*cs++) - break; - } - return result; -} -#endif diff --git a/nuttx/lib/string/lib_strcpy.c b/nuttx/lib/string/lib_strcpy.c deleted file mode 100644 index e2f70b94e..000000000 --- a/nuttx/lib/string/lib_strcpy.c +++ /dev/null @@ -1,55 +0,0 @@ -/************************************************************************ - * lib/string/lib_strcpy.c - * - * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include - -/************************************************************************ - * Global Functions - ************************************************************************/ - -#ifndef CONFIG_ARCH_STRCPY -char *strcpy(char *dest, const char *src) -{ - char *tmp = dest; - while ((*dest++ = *src++) != '\0'); - return tmp; -} -#endif diff --git a/nuttx/lib/string/lib_strcspn.c b/nuttx/lib/string/lib_strcspn.c deleted file mode 100644 index 9da89241c..000000000 --- a/nuttx/lib/string/lib_strcspn.c +++ /dev/null @@ -1,67 +0,0 @@ -/**************************************************************************** - * lib/string/lib_strcspn.c - * - * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Compilation Switches - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include - -/**************************************************************************** - * Global Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: strcspn - * - * Description: - * strspn() calculates the length of the initial segment of s which - * consists entirely of characters not in reject - * - ****************************************************************************/ - -size_t strcspn(const char *s, const char *reject) -{ - size_t i; - for (i = 0; s[i] && strchr(reject, s[i]) == NULL; i++); - return i; -} - diff --git a/nuttx/lib/string/lib_strdup.c b/nuttx/lib/string/lib_strdup.c deleted file mode 100644 index 44a0cbc0d..000000000 --- a/nuttx/lib/string/lib_strdup.c +++ /dev/null @@ -1,62 +0,0 @@ -/************************************************************************ - * lib/string//lib_strdup.c - * - * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include - -#include "lib_internal.h" - -/************************************************************************ - * Global Functions - ************************************************************************/ - -FAR char *strdup(const char *s) -{ - FAR char *news = NULL; - if (s) - { - news = (FAR char*)lib_malloc(strlen(s) + 1); - if (news) - { - strcpy(news, s); - } - } - return news; -} diff --git a/nuttx/lib/string/lib_strerror.c b/nuttx/lib/string/lib_strerror.c deleted file mode 100644 index 249f695c1..000000000 --- a/nuttx/lib/string/lib_strerror.c +++ /dev/null @@ -1,375 +0,0 @@ -/************************************************************************ - * lib/string/lib_strerror.c - * - * Copyright (C) 2007, 2009, 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include -#include - -/************************************************************************ - * Definitions - ************************************************************************/ - -/************************************************************************ - * Private Types - ************************************************************************/ - -struct errno_strmap_s -{ - uint8_t errnum; - const char *str; -}; - -/************************************************************************ - * Private Data - ************************************************************************/ - -#ifdef CONFIG_LIBC_STRERROR - -/* This table maps all error numbers to descriptive strings. - * The only assumption that the code makes with regard to this - * this table is that it is ordered by error number. - * - * The size of this table is quite large. Its size can be - * reduced by eliminating some of the more obscure error - * strings. - */ - -#ifndef CONFIG_LIBC_STRERROR_SHORT - -static const struct errno_strmap_s g_errnomap[] = -{ - { EPERM, EPERM_STR }, - { ENOENT, ENOENT_STR }, - { ESRCH, ESRCH_STR }, - { EINTR, EINTR_STR }, - { EIO, EIO_STR }, - { ENXIO, ENXIO_STR }, - { E2BIG, E2BIG_STR }, - { ENOEXEC, ENOEXEC_STR }, - { EBADF, EBADF_STR }, - { ECHILD, ECHILD_STR }, - { EAGAIN, EAGAIN_STR }, - { ENOMEM, ENOMEM_STR }, - { EACCES, EACCES_STR }, - { EFAULT, EFAULT_STR }, - { ENOTBLK, ENOTBLK_STR }, - { EBUSY, EBUSY_STR }, - { EEXIST, EEXIST_STR }, - { EXDEV, EXDEV_STR }, - { ENODEV, ENODEV_STR }, - { ENOTDIR, ENOTDIR_STR }, - { EISDIR, EISDIR_STR }, - { EINVAL, EINVAL_STR }, - { ENFILE, ENFILE_STR }, - { EMFILE, EMFILE_STR }, - { ENOTTY, ENOTTY_STR }, - { ETXTBSY, ETXTBSY_STR }, - { EFBIG, EFBIG_STR }, - { ENOSPC, ENOSPC_STR }, - { ESPIPE, ESPIPE_STR }, - { EROFS, EROFS_STR }, - { EMLINK, EMLINK_STR }, - { EPIPE, EPIPE_STR }, - { EDOM, EDOM_STR }, - { ERANGE, ERANGE_STR }, - { EDEADLK, EDEADLK_STR }, - { ENAMETOOLONG, ENAMETOOLONG_STR }, - { ENOLCK, ENOLCK_STR }, - { ENOSYS, ENOSYS_STR }, - { ENOTEMPTY, ENOTEMPTY_STR }, - { ELOOP, ELOOP_STR }, - { ENOMSG, ENOMSG_STR }, - { EIDRM, EIDRM_STR }, - { ECHRNG, ECHRNG_STR }, - { EL2NSYNC, EL2NSYNC_STR }, - { EL3HLT, EL3HLT_STR }, - { EL3RST, EL3RST_STR }, - { ELNRNG, ELNRNG_STR }, - { EUNATCH, EUNATCH_STR }, - { ENOCSI, ENOCSI_STR }, - { EL2HLT, EL2HLT_STR }, - { EBADE, EBADE_STR }, - { EBADR, EBADR_STR }, - { EXFULL, EXFULL_STR }, - { ENOANO, ENOANO_STR }, - { EBADRQC, EBADRQC_STR }, - { EBADSLT, EBADSLT_STR }, - { EBFONT, EBFONT_STR }, - { ENOSTR, ENOSTR_STR }, - { ENODATA, ENODATA_STR }, - { ETIME, ETIME_STR }, - { ENOSR, ENOSR_STR }, - { ENONET, ENONET_STR }, - { ENOPKG, ENOPKG_STR }, - { EREMOTE, EREMOTE_STR }, - { ENOLINK, ENOLINK_STR }, - { EADV, EADV_STR }, - { ESRMNT, ESRMNT_STR }, - { ECOMM, ECOMM_STR }, - { EPROTO, EPROTO_STR }, - { EMULTIHOP, EMULTIHOP_STR }, - { EDOTDOT, EDOTDOT_STR }, - { EBADMSG, EBADMSG_STR }, - { EOVERFLOW, EOVERFLOW_STR }, - { ENOTUNIQ, ENOTUNIQ_STR }, - { EBADFD, EBADFD_STR }, - { EREMCHG, EREMCHG_STR }, - { ELIBACC, ELIBACC_STR }, - { ELIBBAD, ELIBBAD_STR }, - { ELIBSCN, ELIBSCN_STR }, - { ELIBMAX, ELIBMAX_STR }, - { ELIBEXEC, ELIBEXEC_STR }, - { EILSEQ, EILSEQ_STR }, - { ERESTART, ERESTART_STR }, - { ESTRPIPE, ESTRPIPE_STR }, - { EUSERS, EUSERS_STR }, - { ENOTSOCK, ENOTSOCK_STR }, - { EDESTADDRREQ, EDESTADDRREQ_STR }, - { EMSGSIZE, EMSGSIZE_STR }, - { EPROTOTYPE, EPROTOTYPE_STR }, - { ENOPROTOOPT, ENOPROTOOPT_STR }, - { EPROTONOSUPPORT, EPROTONOSUPPORT_STR }, - { ESOCKTNOSUPPORT, ESOCKTNOSUPPORT_STR }, - { EOPNOTSUPP, EOPNOTSUPP_STR }, - { EPFNOSUPPORT, EPFNOSUPPORT_STR }, - { EAFNOSUPPORT, EAFNOSUPPORT_STR }, - { EADDRINUSE, EADDRINUSE_STR }, - { EADDRNOTAVAIL, EADDRNOTAVAIL_STR }, - { ENETDOWN, ENETDOWN_STR }, - { ENETUNREACH, ENETUNREACH_STR }, - { ENETRESET, ENETRESET_STR }, - { ECONNABORTED, ECONNABORTED_STR }, - { ECONNRESET, ECONNRESET_STR }, - { ENOBUFS, ENOBUFS_STR }, - { EISCONN, EISCONN_STR }, - { ENOTCONN, ENOTCONN_STR }, - { ESHUTDOWN, ESHUTDOWN_STR }, - { ETOOMANYREFS, ETOOMANYREFS_STR }, - { ETIMEDOUT, ETIMEDOUT_STR }, - { ECONNREFUSED, ECONNREFUSED_STR }, - { EHOSTDOWN, EHOSTDOWN_STR }, - { EHOSTUNREACH, EHOSTUNREACH_STR }, - { EALREADY, EALREADY_STR }, - { EINPROGRESS, EINPROGRESS_STR }, - { ESTALE, ESTALE_STR }, - { EUCLEAN, EUCLEAN_STR }, - { ENOTNAM, ENOTNAM_STR }, - { ENAVAIL, ENAVAIL_STR }, - { EISNAM, EISNAM_STR }, - { EREMOTEIO, EREMOTEIO_STR }, - { EDQUOT, EDQUOT_STR }, - { ENOMEDIUM, ENOMEDIUM_STR }, - { EMEDIUMTYPE, EMEDIUMTYPE_STR } -}; - -#else /* CONFIG_LIBC_STRERROR_SHORT */ - -static const struct errno_strmap_s g_errnomap[] = -{ - { EPERM, "EPERM" }, - { ENOENT, "ENOENT" }, - { ESRCH, "ESRCH" }, - { EINTR, "EINTR" }, - { EIO, "EIO" }, - { ENXIO, "ENXIO" }, - { E2BIG, "E2BIG" }, - { ENOEXEC, "ENOEXEC" }, - { EBADF, "EBADF" }, - { ECHILD, "ECHILD" }, - { EAGAIN, "EAGAIN" }, - { ENOMEM, "ENOMEM" }, - { EACCES, "EACCES" }, - { EFAULT, "EFAULT" }, - { ENOTBLK, "ENOTBLK" }, - { EBUSY, "EBUSY" }, - { EEXIST, "EEXIST" }, - { EXDEV, "EXDEV" }, - { ENODEV, "ENODEV" }, - { ENOTDIR, "ENOTDIR" }, - { EISDIR, "EISDIR" }, - { EINVAL, "EINVAL" }, - { ENFILE, "ENFILE" }, - { EMFILE, "EMFILE" }, - { ENOTTY, "ENOTTY" }, - { ETXTBSY, "ETXTBSY" }, - { EFBIG, "EFBIG" }, - { ENOSPC, "ENOSPC" }, - { ESPIPE, "ESPIPE" }, - { EROFS, "EROFS" }, - { EMLINK, "EMLINK" }, - { EPIPE, "EPIPE" }, - { EDOM, "EDOM" }, - { ERANGE, "ERANGE" }, - { EDEADLK, "EDEADLK" }, - { ENAMETOOLONG, "ENAMETOOLONG" }, - { ENOLCK, "ENOLCK" }, - { ENOSYS, "ENOSYS" }, - { ENOTEMPTY, "ENOTEMPTY" }, - { ELOOP, "ELOOP" }, - { ENOMSG, "ENOMSG" }, - { EIDRM, "EIDRM" }, - { ECHRNG, "ECHRNG" }, - { EL2NSYNC, "EL2NSYNC" }, - { EL3HLT, "EL3HLT" }, - { EL3RST, "EL3RST" }, - { EL3RST, "EL3RST" }, - { EUNATCH, "EUNATCH" }, - { ENOCSI, "ENOCSI" }, - { EL2HLT, "EL2HLT" }, - { EBADE, "EBADE" }, - { EBADR, "EBADR" }, - { EXFULL, "EXFULL" }, - { ENOANO, "ENOANO" }, - { EBADRQC, "EBADRQC" }, - { EBADSLT, "EBADSLT" }, - { EBFONT, "EBFONT" }, - { ENOSTR, "ENOSTR" }, - { ENODATA, "ENODATA" }, - { ETIME, "ETIME" }, - { ENOSR, "ENOSR" }, - { ENONET, "ENONET" }, - { ENOPKG, "ENOPKG" }, - { EREMOTE, "EREMOTE" }, - { ENOLINK, "ENOLINK" }, - { EADV, "EADV" }, - { ESRMNT, "ESRMNT" }, - { ECOMM, "ECOMM" }, - { EPROTO, "EPROTO" }, - { EMULTIHOP, "EMULTIHOP" }, - { EDOTDOT, "EDOTDOT" }, - { EBADMSG, "EBADMSG" }, - { EOVERFLOW, "EOVERFLOW" }, - { ENOTUNIQ, "ENOTUNIQ" }, - { EBADFD, "EBADFD" }, - { EREMCHG, "EREMCHG" }, - { ELIBACC, "ELIBACC" }, - { ELIBBAD, "ELIBBAD" }, - { ELIBSCN, "ELIBSCN" }, - { ELIBMAX, "ELIBMAX" }, - { ELIBEXEC, "ELIBEXEC" }, - { EILSEQ, "EILSEQ" }, - { ERESTART, "ERESTART" }, - { ESTRPIPE, "ESTRPIPE" }, - { EUSERS, "EUSERS" }, - { ENOTSOCK, "ENOTSOCK" }, - { EDESTADDRREQ, "EDESTADDRREQ" }, - { EMSGSIZE, "EMSGSIZE" }, - { EPROTOTYPE, "EPROTOTYPE" }, - { ENOPROTOOPT, "ENOPROTOOPT" }, - { EPROTONOSUPPORT, "EPROTONOSUPPORT" }, - { ESOCKTNOSUPPORT, "ESOCKTNOSUPPORT" }, - { EOPNOTSUPP, "EOPNOTSUPP" }, - { EPFNOSUPPORT, "EPFNOSUPPORT" }, - { EAFNOSUPPORT, "EAFNOSUPPORT" }, - { EADDRINUSE, "EADDRINUSE" }, - { EADDRNOTAVAIL, "EADDRNOTAVAIL" }, - { ENETDOWN, "ENETDOWN" }, - { ENETUNREACH, "ENETUNREACH" }, - { ENETRESET, "ENETRESET" }, - { ECONNABORTED, "ECONNABORTED" }, - { ECONNRESET, "ECONNRESET" }, - { ENOBUFS, "ENOBUFS" }, - { EISCONN, "EISCONN" }, - { ENOTCONN, "ENOTCONN" }, - { ESHUTDOWN, "ESHUTDOWN" }, - { ETOOMANYREFS, "ETOOMANYREFS" }, - { ETIMEDOUT, "ETIMEDOUT" }, - { ECONNREFUSED, "ECONNREFUSED" }, - { EHOSTDOWN, "EHOSTDOWN" }, - { EHOSTUNREACH, "EHOSTUNREACH" }, - { EALREADY, "EALREADY" }, - { EINPROGRESS, "EINPROGRESS" }, - { ESTALE, "ESTALE" }, - { EUCLEAN, "EUCLEAN" }, - { ENOTNAM, "ENOTNAM" }, - { ENAVAIL, "ENAVAIL" }, - { EISNAM, "EISNAM" }, - { EREMOTEIO, "EREMOTEIO" }, - { EDQUOT, "EDQUOT" }, - { ENOMEDIUM, "ENOMEDIUM" }, - { EMEDIUMTYPE, "EMEDIUMTYPE" } -}; - -#endif /* CONFIG_LIBC_STRERROR_SHORT */ - -#define NERRNO_STRS (sizeof(g_errnomap) / sizeof(struct errno_strmap_s)) - -#endif /* CONFIG_LIBC_STRERROR */ - -/************************************************************************ - * Private Functions - ************************************************************************/ - -/************************************************************************ - * Public Functions - ************************************************************************/ - -/************************************************************************ - * Name: strerror - ************************************************************************/ - -FAR const char *strerror(int errnum) -{ -#ifdef CONFIG_LIBC_STRERROR - int ndxlow = 0; - int ndxhi = NERRNO_STRS - 1; - int ndxmid; - - do - { - ndxmid = (ndxlow + ndxhi) >> 1; - if (errnum > g_errnomap[ndxmid].errnum) - { - ndxlow = ndxmid + 1; - } - else if (errnum < g_errnomap[ndxmid].errnum) - { - ndxhi = ndxmid - 1; - } - else - { - return g_errnomap[ndxmid].str; - } - } - while (ndxlow <= ndxhi); -#endif - return "Unknown error"; -} diff --git a/nuttx/lib/string/lib_strlen.c b/nuttx/lib/string/lib_strlen.c deleted file mode 100644 index 833305809..000000000 --- a/nuttx/lib/string/lib_strlen.c +++ /dev/null @@ -1,55 +0,0 @@ -/**************************************************************************** - * lib/string/lib_strlen.c - * - * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 -#include -#include - -/**************************************************************************** - * Global Functions - ****************************************************************************/ - -#ifndef CONFIG_ARCH_STRLEN -size_t strlen(const char *s) -{ - const char *sc; - for (sc = s; *sc != '\0'; ++sc); - return sc - s; -} -#endif diff --git a/nuttx/lib/string/lib_strncasecmp.c b/nuttx/lib/string/lib_strncasecmp.c deleted file mode 100644 index be369cf0d..000000000 --- a/nuttx/lib/string/lib_strncasecmp.c +++ /dev/null @@ -1,70 +0,0 @@ -/**************************************************************************** - * lib/string/lib_strncasecmp.c - * - * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - *****************************************************************************/ - -/**************************************************************************** - * Compilation Switches - *****************************************************************************/ - -/**************************************************************************** - * Included Files - *****************************************************************************/ - -#include - -#include -#include -#include - -/**************************************************************************** - * Global Functions - *****************************************************************************/ - -#ifndef CONFIG_ARCH_STRNCASECMP -int strncasecmp(const char *cs, const char *ct, size_t nb) -{ - int result = 0; - for (; nb > 0; nb--) - { - if ((result = (int)toupper(*cs) - (int)toupper(*ct)) != 0 || !*cs) - { - break; - } - - cs++; - ct++; - } - return result; -} -#endif diff --git a/nuttx/lib/string/lib_strncat.c b/nuttx/lib/string/lib_strncat.c deleted file mode 100644 index af893e0f9..000000000 --- a/nuttx/lib/string/lib_strncat.c +++ /dev/null @@ -1,62 +0,0 @@ -/************************************************************ - * lib/string/lib_strncat.c - * - * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 -#include -#include - -/************************************************************ - * Global Functions - ************************************************************/ - -#ifndef CONFIG_ARCH_STRNCAT -char *strncat(char *dest, const char *src, size_t n) -{ - char *ret = dest; - - dest += strlen(dest); - for (; n > 0 && *src != '\0' ; n--) - { - *dest++ = *src++; - } - *dest = '\0'; - - return ret; -} -#endif diff --git a/nuttx/lib/string/lib_strncmp.c b/nuttx/lib/string/lib_strncmp.c deleted file mode 100644 index ce2282024..000000000 --- a/nuttx/lib/string/lib_strncmp.c +++ /dev/null @@ -1,65 +0,0 @@ -/**************************************************************************** - * lib/lib_strncmp.c - * - * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - *****************************************************************************/ - -/**************************************************************************** - * Compilation Switches - *****************************************************************************/ - -/**************************************************************************** - * Included Files - *****************************************************************************/ - -#include -#include -#include - -/**************************************************************************** - * Global Functions - *****************************************************************************/ - -#ifndef CONFIG_ARCH_STRNCMP -int strncmp(const char *cs, const char *ct, size_t nb) -{ - int result = 0; - for (; nb > 0; nb--) - { - if ((result = (int)*cs - (int)*ct++) != 0 || !*cs++) - { - break; - } - } - return result; -} -#endif diff --git a/nuttx/lib/string/lib_strncpy.c b/nuttx/lib/string/lib_strncpy.c deleted file mode 100644 index 149369d50..000000000 --- a/nuttx/lib/string/lib_strncpy.c +++ /dev/null @@ -1,57 +0,0 @@ -/************************************************************ - * lib/string/lib_strncpy.c - * - * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 -#include -#include - -/************************************************************ - * Global Functions - ************************************************************/ - -#ifndef CONFIG_ARCH_STRNCPY -char *strncpy(char *dest, const char *src, size_t n) -{ - char *ret = dest; /* Value to be returned */ - char *end = dest + n; /* End of dest buffer + 1 byte */ - - while ((*dest++ = *src++) != '\0' && dest != end); - return ret; -} -#endif diff --git a/nuttx/lib/string/lib_strndup.c b/nuttx/lib/string/lib_strndup.c deleted file mode 100644 index ffaf892ea..000000000 --- a/nuttx/lib/string/lib_strndup.c +++ /dev/null @@ -1,93 +0,0 @@ -/************************************************************************ - * lib/string//lib_strndup.c - * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include - -#include "lib_internal.h" - -/************************************************************************ - * Global Functions - ************************************************************************/ -/************************************************************************ - * Name: strndup - * - * Description: - * The strndup() function is equivalent to the strdup() function, - * duplicating the provided 's' in a new block of memory allocated as - * if by using malloc(), with the exception being that strndup() copies - * at most 'size' plus one bytes into the newly allocated memory, - * terminating the new string with a NUL character. If the length of 's' - * is larger than 'size', only 'size' bytes will be duplicated. If - * 'size' is larger than the length of 's', all bytes in s will be - * copied into the new memory buffer, including the terminating NUL - * character. The newly created string will always be properly - * terminated. - * - ************************************************************************/ - -FAR char *strndup(FAR const char *s, size_t size) -{ - FAR char *news = NULL; - if (s) - { - /* Get the size of the new string = MIN(strlen(s), size) */ - - size_t allocsize = strlen(s); - if (allocsize > size) - { - allocsize = size; - } - - /* Allocate the new string, adding 1 for the NUL terminator */ - - news = (FAR char*)lib_malloc(allocsize + 1); - if (news) - { - /* Copy the string into the allocated memory and add a NUL - * terminator in any case. - */ - - memcpy(news, s, allocsize); - news[allocsize] = '\0'; - } - } - return news; -} diff --git a/nuttx/lib/string/lib_strnlen.c b/nuttx/lib/string/lib_strnlen.c deleted file mode 100644 index 2b64fe984..000000000 --- a/nuttx/lib/string/lib_strnlen.c +++ /dev/null @@ -1,62 +0,0 @@ -/**************************************************************************** - * lib/string/lib_strnlen.c - * - * This file is part of NuttX, contributed by Michael Hrabanek - * - * Copyright (C) 2010 Gregory Nutt. All rights reserved. - * Author: Michael Hrabanek - * - * Derives from the file lib/lib_strlen.c: - * - * Copyright (C) 2007, 2008, 2010 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 -#include -#include - -/**************************************************************************** - * Global Functions - ****************************************************************************/ - -#ifndef CONFIG_ARCH_STRNLEN -size_t strnlen(const char *s, size_t maxlen) -{ - const char *sc; - for (sc = s; maxlen != 0 && *sc != '\0'; maxlen--, ++sc); - return sc - s; -} -#endif diff --git a/nuttx/lib/string/lib_strpbrk.c b/nuttx/lib/string/lib_strpbrk.c deleted file mode 100644 index 02e2ea2c7..000000000 --- a/nuttx/lib/string/lib_strpbrk.c +++ /dev/null @@ -1,85 +0,0 @@ -/**************************************************************************** - * lib/string/lib_strpbrk.c - * - * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use str 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 str binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer str - * 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 - -#include - -/**************************************************************************** - * Global Functions - ****************************************************************************/ - -char *strpbrk(const char *str, const char *charset) -{ - /* Sanity checking */ - -#ifdef CONFIG_DEBUG - if (!str || !charset) - { - return NULL; - } -#endif - - /* Check each character in the string */ - - while (*str) - { - /* Check if the character from the string matches any character in the charset */ - - if (strchr(charset, *str) != NULL) - { - /* Yes, then this position must be the first occurrence in string */ - - return (char*)str; - } - - /* This character from the strings matches none of those in the charset. - * Try the next character from the string. - */ - - str++; - } - - /* We have looked at every character in the string, and none of them match any of - * the characters in charset. - */ - - return NULL; -} - diff --git a/nuttx/lib/string/lib_strrchr.c b/nuttx/lib/string/lib_strrchr.c deleted file mode 100644 index 91243ce58..000000000 --- a/nuttx/lib/string/lib_strrchr.c +++ /dev/null @@ -1,68 +0,0 @@ -/************************************************************************ - * lib/string/lib_strrchr.c - * - * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include - -/************************************************************************ - * Global Functions - ************************************************************************/ - -/* The strrchr() function returns a pointer to the last - * occurrence of the character c in the string s. - */ - -char *strrchr(const char *s, int c) -{ - if (s) - { - const char *p = &s[strlen(s) - 1]; - for (; p >= s; p--) - { - if (*p == c) - { - return (char*)p; - } - } - } - - return NULL; -} - diff --git a/nuttx/lib/string/lib_strspn.c b/nuttx/lib/string/lib_strspn.c deleted file mode 100644 index e7b5ea0a5..000000000 --- a/nuttx/lib/string/lib_strspn.c +++ /dev/null @@ -1,66 +0,0 @@ -/**************************************************************************** - * lib/string/lib_strspn.c - * - * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Compilation Switches - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include - -/**************************************************************************** - * Global Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: strspn - * - * Description: - * strspn() calculates the length of the initial segment of s which - * consists entirely of characters in accept. - * - ****************************************************************************/ - -size_t strspn(const char *s, const char *accept) -{ - size_t i; - for (i = 0; s[i] && strchr(accept, s[i]) != NULL; i++); - return i; -} diff --git a/nuttx/lib/string/lib_strstr.c b/nuttx/lib/string/lib_strstr.c deleted file mode 100644 index b8c896fa2..000000000 --- a/nuttx/lib/string/lib_strstr.c +++ /dev/null @@ -1,104 +0,0 @@ -/**************************************************************************** - * lib/string/lib_strstr.c - * - * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use str 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 str binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer str - * 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 - -#include - -/**************************************************************************** - * Global Functions - ****************************************************************************/ - -char *strstr(const char *str, const char *substr) -{ - const char *candidate; /* Candidate in str with matching start character */ - char ch; /* First character of the substring */ - int len; /* The length of the substring */ - - /* Special case the empty substring */ - - len = strlen(substr); - ch = *substr; - - if (!ch) - { - /* We'll say that an empty substring matches at the beginning of - * the string - */ - - return (char*)str; - } - - /* Search for the substring */ - - candidate = str; - for (;;) - { - /* strchr() will return a pointer to the next occurrence of the - * character ch in the string - */ - - candidate = strchr(candidate, ch); - if (!candidate || strlen(candidate) < len) - { - /* First character of the substring does not appear in the string - * or the remainder of the string is not long enough to contain the - * substring. - */ - - return NULL; - } - - /* Check if this is the beginning of a matching substring */ - - if (strncmp(candidate, substr, len) == 0) - { - return (char*)candidate; - } - - /* No, find the next candidate after this one */ - - candidate++; - } - - /* Won't get here, but some compilers might complain */ - - return NULL; -} - diff --git a/nuttx/lib/string/lib_strtod.c b/nuttx/lib/string/lib_strtod.c deleted file mode 100644 index 8fecd4571..000000000 --- a/nuttx/lib/string/lib_strtod.c +++ /dev/null @@ -1,241 +0,0 @@ -/**************************************************************************** - * lib/string/lib_strtod.c - * Convert string to double - * - * Copyright (C) 2002 Michael Ringgaard. All rights reserved. - * Copyright (C) 2006-2007 H. Peter Anvin. - * - * 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 of the project 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 -#include - -#include -#include -#include - -#ifdef CONFIG_HAVE_DOUBLE - -/**************************************************************************** - * Pre-processor definitions - ****************************************************************************/ - -/* These are predefined with GCC, but could be issues for other compilers. If - * not defined, an arbitrary big number is put in for now. These should be - * added to nuttx/compiler for your compiler. - */ - -#if !defined(__DBL_MIN_EXP__) || !defined(__DBL_MAX_EXP__) -# ifdef CONFIG_CPP_HAVE_WARNING -# warning "Size of exponent is unknown" -# endif -# undef __DBL_MIN_EXP__ -# define __DBL_MIN_EXP__ (-1021) -# undef __DBL_MAX_EXP__ -# define __DBL_MAX_EXP__ (1024) -#endif - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static inline int is_real(double x) -{ - const double_t infinite = 1.0/0.0; - return (x < infinite) && (x >= -infinite); -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/***************************************************(************************ - * Name: strtod - * - * Description: - * Convert a string to a double value - * - ****************************************************************************/ - -double_t strtod(const char *str, char **endptr) -{ - double_t number; - int exponent; - int negative; - char *p = (char *) str; - double p10; - int n; - int num_digits; - int num_decimals; - const double_t infinite = 1.0/0.0; - - /* Skip leading whitespace */ - - while (isspace(*p)) - { - p++; - } - - /* Handle optional sign */ - - negative = 0; - switch (*p) - { - case '-': - negative = 1; /* Fall through to increment position */ - case '+': - p++; - } - - number = 0.; - exponent = 0; - num_digits = 0; - num_decimals = 0; - - /* Process string of digits */ - - while (isdigit(*p)) - { - number = number * 10. + (*p - '0'); - p++; - num_digits++; - } - - /* Process decimal part */ - - if (*p == '.') - { - p++; - - while (isdigit(*p)) - { - number = number * 10. + (*p - '0'); - p++; - num_digits++; - num_decimals++; - } - - exponent -= num_decimals; - } - - if (num_digits == 0) - { - set_errno(ERANGE); - return 0.0; - } - - /* Correct for sign */ - - if (negative) - { - number = -number; - } - - /* Process an exponent string */ - - if (*p == 'e' || *p == 'E') - { - /* Handle optional sign */ - - negative = 0; - switch(*++p) - { - case '-': - negative = 1; /* Fall through to increment pos */ - case '+': - p++; - } - - /* Process string of digits */ - - n = 0; - while (isdigit(*p)) - { - n = n * 10 + (*p - '0'); - p++; - } - - if (negative) - { - exponent -= n; - } - else - { - exponent += n; - } - } - - if (exponent < __DBL_MIN_EXP__ || - exponent > __DBL_MAX_EXP__) - { - set_errno(ERANGE); - return infinite; - } - - /* Scale the result */ - - p10 = 10.; - n = exponent; - if (n < 0) n = -n; - while (n) - { - if (n & 1) - { - if (exponent < 0) - { - number /= p10; - } - else - { - number *= p10; - } - } - n >>= 1; - p10 *= p10; - } - - if (!is_real(number)) - { - set_errno(ERANGE); - } - - if (endptr) - { - *endptr = p; - } - - return number; -} - -#endif /* CONFIG_HAVE_DOUBLE */ - diff --git a/nuttx/lib/string/lib_strtok.c b/nuttx/lib/string/lib_strtok.c deleted file mode 100644 index c40993135..000000000 --- a/nuttx/lib/string/lib_strtok.c +++ /dev/null @@ -1,87 +0,0 @@ -/**************************************************************************** - * lib/string/lib_strtok.c - * - * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static char *g_saveptr = NULL; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: strtok - * - * Description: - * The strtok() function parses a string into a - * sequence of tokens. On the first call to strtok() the - * string to be parsed should be specified in 'str'. In - * each subsequent call that should parse the same string, - * 'str' should be NULL. - * - * The 'delim' argument specifies a set of characters that - * delimit the tokens in the parsed string. The caller - * may specify different strings in delim in successive - * calls that parse the same string. - * - * Each call to strtok() returns a pointer to a null- - * terminated string containing the next token. This - * string does not include the delimiting character. If - * no more tokens are found, strtok() returns NULL. - * - * A sequence of two or more contiguous delimiter - * characters in the parsed string is considered to be a - * single delimiter. Delimiter characters at the start or - * end of the string are ignored. The tokens returned by - * strtok() are always non-empty strings. - * - * Return - * strtok() returns a pointer to the next token, or NULL - * if there are no more tokens. - * - ****************************************************************************/ - -char *strtok(char *str, const char *delim) -{ - return strtok_r(str, delim, &g_saveptr); -} diff --git a/nuttx/lib/string/lib_strtokr.c b/nuttx/lib/string/lib_strtokr.c deleted file mode 100644 index 1c571b6ae..000000000 --- a/nuttx/lib/string/lib_strtokr.c +++ /dev/null @@ -1,157 +0,0 @@ -/**************************************************************************** - * lib/string/lib_strtokr.c - * - * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: strtok_r - * - * Description: - * The strtok_r() function is a reentrant version strtok(). - * Like strtok(), it parses a string into a sequence of - * tokens. On the first call to strtok() the string to be - * parsed should be specified in 'str'. In each subsequent - * call that should parse the same string, 'str' should be - * NULL. - * - * The 'saveptr' argument is a pointer to a char * - * variable that is used internally by strtok_r() in - * order to maintain context between successive calls - * that parse the same string. - * - * On the first call to strtok_r(), 'str' should point to the - * string to be parsed, and the value of 'saveptr' is - * ignored. In subsequent calls, 'str' should be NULL, and - * saveptr should be unchanged since the previous call. - * - * The 'delim' argument specifies a set of characters that - * delimit the tokens in the parsed string. The caller - * may specify different strings in delim in successive - * calls that parse the same string. - * - * Each call to strtok_r() returns a pointer to a null- - * terminated string containing the next token. This - * string does not include the delimiting character. If - * no more tokens are found, strtok_r() returns NULL. - * - * A sequence of two or more contiguous delimiter - * characters in the parsed string is considered to be a - * single delimiter. Delimiter characters at the start or - * end of the string are ignored. The tokens returned by - * strtok() are always non-empty strings. - * - * Return - * strtok_r() returns a pointer to the next token, or NULL - * if there are no more tokens. - * - ****************************************************************************/ - -FAR char *strtok_r(FAR char *str, FAR const char *delim, FAR char **saveptr) -{ - char *pbegin; - char *pend = NULL; - - /* Decide if we are starting a new string or continuing from - * the point we left off. - */ - - if (str) - { - pbegin = str; - } - else if (saveptr && *saveptr) - { - pbegin = *saveptr; - } - else - { - return NULL; - } - - /* Find the beginning of the next token */ - - for (; - *pbegin && strchr(delim, *pbegin) != NULL; - pbegin++); - - /* If we are at the end of the string with nothing - * but delimiters found, then return NULL. - */ - - if (!*pbegin) - { - return NULL; - } - - /* Find the end of the token */ - - for (pend = pbegin + 1; - *pend && strchr(delim, *pend) == NULL; - pend++); - - - /* pend either points to the end of the string or to - * the first delimiter after the string. - */ - - if (*pend) - { - /* Turn the delimiter into a null terminator */ - - *pend++ = '\0'; - } - - /* Save the pointer where we left off and return the - * beginning of the token. - */ - - if (saveptr) - { - *saveptr = pend; - } - return pbegin; -} diff --git a/nuttx/lib/string/lib_strtol.c b/nuttx/lib/string/lib_strtol.c deleted file mode 100644 index c17d87e63..000000000 --- a/nuttx/lib/string/lib_strtol.c +++ /dev/null @@ -1,103 +0,0 @@ -/**************************************************************************** - * lib/string/lib_strtol.c - * - * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include - -#include "lib_internal.h" - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: strtol - * - * Description: - * The strtol() function converts the initial part of the string in - * nptr to a long integer value according to the given base, which must be - * between 2 and 36 inclusive, or be the special value 0. - * - * Warning: does not check for integer overflow! - * - ****************************************************************************/ - -long strtol(const char *nptr, char **endptr, int base) -{ - unsigned long accum = 0; - bool negate = false; - - if (nptr) - { - /* Skip leading spaces */ - - lib_skipspace(&nptr); - - /* Check for leading + or - */ - - if (*nptr == '-') - { - negate = true; - nptr++; - } - else if (*nptr == '+') - { - nptr++; - } - - /* Get the unsigned value */ - - accum = strtoul(nptr, endptr, base); - - /* Correct the sign of the result */ - - if (negate) - { - return -(long)accum; - } - } - return (long)accum; -} - diff --git a/nuttx/lib/string/lib_strtoll.c b/nuttx/lib/string/lib_strtoll.c deleted file mode 100644 index 242e025c0..000000000 --- a/nuttx/lib/string/lib_strtoll.c +++ /dev/null @@ -1,107 +0,0 @@ -/**************************************************************************** - * lib/string/lib_strtoll.c - * - * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include - -#include "lib_internal.h" - -#ifdef CONFIG_HAVE_LONG_LONG - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: strtoll - * - * Description: - * The strtol() function converts the initial part of the string in - * nptr to a long long integer value according to the given base, which - * must be between 2 and 36 inclusive, or be the special value 0. - * - * Warning: does not check for integer overflow! - * - ****************************************************************************/ - -long long strtoll(const char *nptr, char **endptr, int base) -{ - unsigned long long accum = 0; - bool negate = false; - - if (nptr) - { - /* Skip leading spaces */ - - lib_skipspace(&nptr); - - /* Check for leading + or - */ - - if (*nptr == '-') - { - negate = true; - nptr++; - } - else if (*nptr == '+') - { - nptr++; - } - - /* Get the unsigned value */ - - accum = strtoull(nptr, endptr, base); - - /* Correct the sign of the result */ - - if (negate) - { - return -(long long)accum; - } - } - return (long long)accum; -} - -#endif - diff --git a/nuttx/lib/string/lib_strtoul.c b/nuttx/lib/string/lib_strtoul.c deleted file mode 100644 index b0d2d090e..000000000 --- a/nuttx/lib/string/lib_strtoul.c +++ /dev/null @@ -1,98 +0,0 @@ -/**************************************************************************** - * /lib/string/lib_strtoul.c - * - * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include - -#include "lib_internal.h" - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: strtoul - * - * Description: - * The strtol() function converts the initial part of the string in - * nptr to a long unsigned integer value according to the given base, which - * must be between 2 and 36 inclusive, or be the special value 0. - * - * Warning: does not check for integer overflow! - * - ****************************************************************************/ - -unsigned long strtoul(const char *nptr, char **endptr, int base) -{ - unsigned long accum = 0; - int value; - - if (nptr) - { - /* Skip leading spaces */ - - lib_skipspace(&nptr); - - /* Check for unspecified base */ - - base = lib_checkbase(base, &nptr); - - /* Accumulate each "digit" */ - - while (lib_isbasedigit(*nptr, base, &value)) - { - accum = accum*base + value; - nptr++; - } - - /* Return the final pointer to the unused value */ - - if (endptr) - { - *endptr = (char *)nptr; - } - } - return accum; -} - diff --git a/nuttx/lib/string/lib_strtoull.c b/nuttx/lib/string/lib_strtoull.c deleted file mode 100644 index 6567457c0..000000000 --- a/nuttx/lib/string/lib_strtoull.c +++ /dev/null @@ -1,100 +0,0 @@ -/**************************************************************************** - * /lib/string/lib_strtoull.c - * - * Copyright (C) 2009, 2010 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 -#include - -#include - -#include "lib_internal.h" - -#ifdef CONFIG_HAVE_LONG_LONG - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: strtoull - * - * Description: - * The strtol() function converts the initial part of the string in - * nptr to a long unsigned integer value according to the given base, which - * must be between 2 and 36 inclusive, or be the special value 0. - * - ****************************************************************************/ - -unsigned long long strtoull(const char *nptr, char **endptr, int base) -{ - unsigned long long accum = 0; - int value; - - if (nptr) - { - /* Skip leading spaces */ - - lib_skipspace(&nptr); - - /* Check for unspecified base */ - - base = lib_checkbase(base, &nptr); - - /* Accumulate each "digit" */ - - while (lib_isbasedigit(*nptr, base, &value)) - { - accum = accum*base + value; - nptr++; - } - - /* Return the final pointer to the unused value */ - - if (endptr) - { - *endptr = (char *)nptr; - } - } - return accum; -} -#endif - diff --git a/nuttx/lib/termios/Make.defs b/nuttx/lib/termios/Make.defs deleted file mode 100644 index a6bb77f83..000000000 --- a/nuttx/lib/termios/Make.defs +++ /dev/null @@ -1,54 +0,0 @@ -############################################################################ -# lib/misc/Make.defs -# -# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt -# -# 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. -# -############################################################################ - -# termios.h support requires file descriptors and that CONFIG_SERIAL_TERMIOS -# is defined - -ifneq ($(CONFIG_NFILE_DESCRIPTORS),0) -ifeq ($(CONFIG_SERIAL_TERMIOS),y) - -# Add the termios C files to the build - -CSRCS += lib_cfgetspeed.c lib_cfsetspeed.c lib_tcflush.c -CSRCS += lib_tcgetattr.c lib_tcsetattr.c - -# Add the termios directory to the build - -DEPPATH += --dep-path termios -VPATH += termios - -endif -endif - diff --git a/nuttx/lib/termios/lib_cfgetspeed.c b/nuttx/lib/termios/lib_cfgetspeed.c deleted file mode 100644 index d7f0dc473..000000000 --- a/nuttx/lib/termios/lib_cfgetspeed.c +++ /dev/null @@ -1,93 +0,0 @@ -/**************************************************************************** - * lib/termios/lib_cfgetspeed.c - * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Public Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: cfgetspeed - * - * Descripton: - * The cfgetspeed() function is a non-POSIX function will extract the baud - * from the termios structure to which the termiosp argument points. - * - * This function will return exactly the value in the termios data - * structure, without interpretation. - * - * NOTE 1: NuttX does not control input/output baud independently. Both - * must be the same. The POSIX standard interfaces, cfisetispeed() and - * cfisetospeed() are defined to be cfgetspeed() in termios.h. - * NOTE 2. In Nuttx, the speed_t is defined to be uint32_t and the baud - * encodings of termios.h are the actual baud values themselves. Therefore, - * any baud value may be returned here... not just those enumerated in - * termios.h - * - * Input Parameters: - * termiosp - The termiosp argument is a pointer to a termios structure. - * - * Returned Value: - * Encoded baud value from the termios structure. - * - ****************************************************************************/ - -speed_t cfgetspeed(FAR const struct termios *termiosp) -{ - DEBUGASSERT(termiosp); - return termiosp->c_speed; -} diff --git a/nuttx/lib/termios/lib_cfsetspeed.c b/nuttx/lib/termios/lib_cfsetspeed.c deleted file mode 100644 index bf9e66064..000000000 --- a/nuttx/lib/termios/lib_cfsetspeed.c +++ /dev/null @@ -1,121 +0,0 @@ -/**************************************************************************** - * lib/termios/lib_cfsetspeed.c - * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 -#include -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Public Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: cfsetspeed - * - * Descripton: - * The cfsetspeed() function is a non-POSIX function that sets the baud - * stored in the structure pointed to by termiosp to speed. - * - * There is no effect on the baud set in the hardware until a subsequent - * successful call to tcsetattr() on the same termios structure. - * - * NOTE 1: NuttX does not control input/output baud independently. Both - * must be the same. The POSIX standard interfaces, cfisetispeed() and - * cfisetospeed() are defined to be cfsetspeed() in termios.h. - * - * NOTE 3: A consequence of NOTE 1 is that you should never attempt to - * set the input and output baud to different values. - * - * Also, the following POSIX requirement cannot be supported: "If the input - * baud rate stored in the termios structure pointed to by termios_p is 0, - * the input baud rate given to the hardware will be the same as the output - * baud rate stored in the termios structure." - * - * NOTE 2. In Nuttx, the speed_t is defined to be uint32_t and the baud - * encodings of termios.h are the actual baud values themselves. Therefore, - * any baud value can be provided as the speed argument here. However, if - * you do so, your code will *NOT* be portable to other environments where - * speed_t is smaller and where the termios.h baud values are encoded! To - * avoid portability issues, use the baud definitions in termios.h! - * - * Linux, for example, would require this (also non-portable) sequence: - * - * cfsetispeed(termiosp, BOTHER); - * termiosp->c_ispeed = baud; - * - * cfsetospeed(termiosp, BOTHER); - * termiosp->c_ospeed = baud; - * - * Input Parameters: - * termiosp - The termiosp argument is a pointer to a termios structure. - * speed - The new input speed - * - * Returned Value: - * Baud is not checked... OK is always returned (this is non-standard - * behavior). - * - ****************************************************************************/ - -int cfsetspeed(FAR struct termios *termiosp, speed_t speed) -{ - FAR speed_t *speedp; - - DEBUGASSERT(termiosp); - - speedp = (FAR speed_t *)&termiosp->c_speed; - *speedp = speed; - - return OK; -} diff --git a/nuttx/lib/termios/lib_tcflush.c b/nuttx/lib/termios/lib_tcflush.c deleted file mode 100644 index 338524bdd..000000000 --- a/nuttx/lib/termios/lib_tcflush.c +++ /dev/null @@ -1,88 +0,0 @@ -/**************************************************************************** - * lib/termios/lib_tcflush.c - * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include - -#include -#include - -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Public Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: tcflush - * - * Descripton: - * Function for flushing a terminal/serial device - * - * Input Parameters: - * fd - The 'fd' argument is an open file descriptor associated with a terminal. - * cmd - The TCFLSH ioctl argument. - * - * Returned Value: - * Upon successful completion, 0 is returned. Otherwise, -1 is returned and - * errno is set to indicate the error. - * - ****************************************************************************/ - -int tcflush(int fd, int cmd) -{ - return ioctl(fd, TCFLSH, (unsigned long)cmd); -} diff --git a/nuttx/lib/termios/lib_tcgetattr.c b/nuttx/lib/termios/lib_tcgetattr.c deleted file mode 100644 index 500871d9f..000000000 --- a/nuttx/lib/termios/lib_tcgetattr.c +++ /dev/null @@ -1,93 +0,0 @@ -/**************************************************************************** - * lib/termios/lib_tcgetattr.c - * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include - -#include -#include - -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Public Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: tcgetattr - * - * Descripton: - * The tcgetattr() function gets the parameters associated with the - * terminal referred to by 'fd' and stores them in the termios structure - * referenced by 'termiosp'. - * - * Input Parameters: - * fd - The 'fd' argument is an open file descriptor associated with a terminal. - * termiosp - The termiosp argument is a pointer to a termios structure. - * - * Returned Value: - * Upon successful completion, 0 is returned. Otherwise, -1 is returned and - * errno is set to indicate the error. The following errors may be reported: - * - * - EBADF: The 'fd' argument is not a valid file descriptor. - * - ENOTTY: The file associated with 'fd' is not a terminal. - * - ****************************************************************************/ - -int tcgetattr(int fd, FAR struct termios *termiosp) -{ - return ioctl(fd, TCGETS, (unsigned long)termiosp); -} diff --git a/nuttx/lib/termios/lib_tcsetattr.c b/nuttx/lib/termios/lib_tcsetattr.c deleted file mode 100644 index 791b519c8..000000000 --- a/nuttx/lib/termios/lib_tcsetattr.c +++ /dev/null @@ -1,122 +0,0 @@ -/**************************************************************************** - * lib/termios/lib_tcsetattr.c - * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include - -#include -#include - -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Public Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: tcsetattr - * - * Descripton: - * The tcsetattr() function sets the parameters associated with the - * terminal referred to by the open file descriptor 'fd' from the termios - * structure referenced by 'termiop' as follows: - * - * If 'options' is TCSANOW, the change will occur immediately. - * - * If 'options' is TCSADRAIN, the change will occur after all output - * written to 'fd' is transmitted. This function should be used when changing - * parameters that affect output. - * - * If 'options' is TCSAFLUSH, the change will occur after all - * output written to 'fd' is transmitted, and all input so far received but - * not read will be discarded before the change is made. - * - * The tcsetattr() function will return successfully if it was able to - * perform any of the requested actions, even if some of the requested - * actions could not be performed. It will set all the attributes that - * implementation supports as requested and leave all the attributes not - * supported by the implementation unchanged. If no part of the request - * can be honoured, it will return -1 and set errno to EINVAL. - * - * The effect of tcsetattr() is undefined if the value of the termios - * structure pointed to by 'termiop' was not derived from the result of - * a call to tcgetattr() on 'fd'; an application should modify only fields - * and flags defined by this specification between the call to tcgetattr() - * and tcsetattr(), leaving all other fields and flags unmodified. - * - * Returned Value: - * - * Upon successful completion, 0 is returned. Otherwise, -1 is returned - * and errno is set to indicate the error. The following errors may be - * reported: - * - * - EBADF: The 'fd' argument is not a valid file descriptor. - * - EINTR: A signal interrupted tcsetattr(). - * - EINVAL: The 'options' argument is not a supported value, or - * an attempt was made to change an attribute represented in the - * termios structure to an unsupported value. - * - ENOTTY: The file associated with 'fd' is not a terminal. - * - ****************************************************************************/ - -int tcsetattr(int fd, int options, FAR const struct termios *termiosp) -{ - if (options == TCSANOW) - { - return ioctl(fd, TCSETS, (unsigned long)termiosp); - } - return -ENOSYS; -} diff --git a/nuttx/lib/time/Make.defs b/nuttx/lib/time/Make.defs deleted file mode 100644 index ab7414229..000000000 --- a/nuttx/lib/time/Make.defs +++ /dev/null @@ -1,44 +0,0 @@ -############################################################################ -# lib/time/Make.defs -# -# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt -# -# 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. -# -############################################################################ - -# Add the time C files to the build - -CSRCS += lib_mktime.c lib_gmtime.c lib_gmtimer.c lib_strftime.c \ - lib_calendar2utc.c lib_daysbeforemonth.c lib_isleapyear.c lib_time.c - -# Add the time directory to the build - -DEPPATH += --dep-path time -VPATH += :time diff --git a/nuttx/lib/time/lib_calendar2utc.c b/nuttx/lib/time/lib_calendar2utc.c deleted file mode 100644 index e80c292fc..000000000 --- a/nuttx/lib/time/lib_calendar2utc.c +++ /dev/null @@ -1,209 +0,0 @@ -/**************************************************************************** - * lib/time/lib_calendar2utc.c - * - * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include -#include - -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Public Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Public Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Function: clock_gregorian2utc, clock_julian2utc - * - * Description: - * UTC conversion routines. These conversions are based - * on algorithms from p. 604 of Seidelman, P. K. 1992. - * Explanatory Supplement to the Astronomical Almanac. - * University Science Books, Mill Valley. - * - ****************************************************************************/ - -#ifdef CONFIG_GREGORIAN_TIME -static time_t clock_gregorian2utc(int year, int month, int day) -{ - int temp; - - /* temp = (month - 14)/12; */ - - temp = (month <= 2 ? -1:0); - - return (1461*(year + 4800 + temp))/4 - + (367*(month - 2 - 12*temp))/12 - - (3*((year + 4900 + temp)/100))/4 + day - 32075; -} - -#ifdef CONFIG_JULIAN_TIME -static time_t clock_julian2utc(int year, int month, int day) -{ - return 367*year - - (7*(year + 5001 + (month-9)/7))/4 - + (275*month)/9 - + day + 1729777; -} -#endif /* CONFIG_JULIAN_TIME */ -#endif /* CONFIG_GREGORIAN_TIME */ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Function: clock_calendar2utc - * - * Description: - * Calendar/UTC conversion based on algorithms from p. 604 - * of Seidelman, P. K. 1992. Explanatory Supplement to - * the Astronomical Almanac. University Science Books, - * Mill Valley. - * - ****************************************************************************/ - -#ifdef CONFIG_GREGORIAN_TIME -time_t clock_calendar2utc(int year, int month, int day) -{ - int dyear; -#ifdef CONFIG_JULIAN_TIME - bool isgreg; -#endif /* CONFIG_JULIAN_TIME */ - - /* Correct year & month ranges. Shift month into range 1-12 */ - - dyear = (month-1) / 12; - month -= 12 * dyear; - year += dyear; - - if (month < 1) - { - month += 12; - year -= 1; - } - -#ifdef CONFIG_JULIAN_TIME - /* Determine which calendar to use */ - - if (year > GREG_YEAR) - { - isgreg = true; - } - else if (year < GREG_YEAR) - { - isgreg = false; - } - else if (month > GREG_MONTH) - { - isgreg = true; - } - else if (month < GREG_MONTH) - { - isgreg = false; - } - else - { - isgreg = (day >= GREG_DAY); - } - - /* Calculate and return date */ - - if (isgreg) - { - return clock_gregorian2utc(year, month, day) - JD_OF_EPOCH; - } - else - { - return clock_julian2utc (year, month, day) - JD_OF_EPOCH; - } - -#else /* CONFIG_JULIAN_TIME */ - - return clock_gregorian2utc(year, month, day) - JD_OF_EPOCH; - -#endif /* CONFIG_JULIAN_TIME */ -} -#else - -/* A highly simplified version that only handles days in the time - * since Jan 1, 1970. - */ - -time_t clock_calendar2utc(int year, int month, int day) -{ - struct tm t; - - /* mktime can (kind of) do this */ - - t.tm_year = year; - t.tm_mon = month; - t.tm_mday = day; - t.tm_hour = 0; - t.tm_min = 0; - t.tm_sec = 0; - return mktime(&t); -} -#endif /* CONFIG_GREGORIAN_TIME */ - diff --git a/nuttx/lib/time/lib_daysbeforemonth.c b/nuttx/lib/time/lib_daysbeforemonth.c deleted file mode 100644 index 8000b0e7a..000000000 --- a/nuttx/lib/time/lib_daysbeforemonth.c +++ /dev/null @@ -1,102 +0,0 @@ -/**************************************************************************** - * lib/time/lib_daysbeforemonth.c - * - * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include - -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Public Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Public Variables - ****************************************************************************/ - -uint16_t g_daysbeforemonth[13] = -{ - 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 -}; - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Function: clock_daysbeforemonth - * - * Description: - * Get the number of days that occurred before the beginning of the month. - * - ****************************************************************************/ - -int clock_daysbeforemonth(int month, bool leapyear) -{ - int retval = g_daysbeforemonth[month]; - if (month >= 2 && leapyear) - { - retval++; - } - return retval; -} - - diff --git a/nuttx/lib/time/lib_gmtime.c b/nuttx/lib/time/lib_gmtime.c deleted file mode 100644 index 99afeded9..000000000 --- a/nuttx/lib/time/lib_gmtime.c +++ /dev/null @@ -1,93 +0,0 @@ -/**************************************************************************** - * lib/time/lib_gmtime.c - * - * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include -#include - -#include - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/************************************************************************** - * Public Constant Data - **************************************************************************/ - -/**************************************************************************** - * Public Variables - ****************************************************************************/ - -/************************************************************************** - * Private Variables - **************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Function: gmtime - * - * Description: - * Similar to gmtime_r, but not thread-safe - * - ****************************************************************************/ - -struct tm *gmtime(const time_t *timer) -{ - static struct tm tm; - return gmtime_r(timer, &tm); -} - diff --git a/nuttx/lib/time/lib_gmtimer.c b/nuttx/lib/time/lib_gmtimer.c deleted file mode 100644 index ba1c9724f..000000000 --- a/nuttx/lib/time/lib_gmtimer.c +++ /dev/null @@ -1,355 +0,0 @@ -/**************************************************************************** - * lib/time/lib_gmtimer.c - * - * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include -#include -#include - -#include - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -#define SEC_PER_MIN ((time_t)60) -#define SEC_PER_HOUR ((time_t)60 * SEC_PER_MIN) -#define SEC_PER_DAY ((time_t)24 * SEC_PER_HOUR) - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/* Calendar/UTC conversion routines */ - -static void clock_utc2calendar(time_t utc, int *year, int *month, int *day); -#ifdef CONFIG_GREGORIAN_TIME -static void clock_utc2gregorian (time_t jdn, int *year, int *month, int *day); - -#ifdef CONFIG_JULIAN_TIME -static void clock_utc2julian(time_t jdn, int *year, int *month, int *day); -#endif /* CONFIG_JULIAN_TIME */ -#endif /* CONFIG_GREGORIAN_TIME */ - -/************************************************************************** - * Public Constant Data - **************************************************************************/ - -/**************************************************************************** - * Public Variables - ****************************************************************************/ - -/************************************************************************** - * Private Variables - **************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Function: clock_calendar2utc, clock_gregorian2utc, - * and clock_julian2utc - * - * Description: - * Calendar to UTC conversion routines. These conversions - * are based on algorithms from p. 604 of Seidelman, P. K. - * 1992. Explanatory Supplement to the Astronomical - * Almanac. University Science Books, Mill Valley. - * - ****************************************************************************/ - -#ifdef CONFIG_GREGORIAN_TIME -static void clock_utc2calendar(time_t utc, int *year, int *month, int *day) -{ -#ifdef CONFIG_JULIAN_TIME - - if (utc >= GREG_DUTC) - { - clock_utc2gregorian(utc + JD_OF_EPOCH, year, month, day); - } - else - { - clock_utc2julian (utc + JD_OF_EPOCH, year, month, day); - } - -#else /* CONFIG_JULIAN_TIME */ - - clock_utc2gregorian(utc + JD_OF_EPOCH, year, month, day); - -#endif /* CONFIG_JULIAN_TIME */ -} - -static void clock_utc2gregorian(time_t jd, int *year, int *month, int *day) -{ - long l, n, i, j, d, m, y; - - l = jd + 68569; - n = (4*l) / 146097; - l = l - (146097*n + 3)/4; - i = (4000*(l+1))/1461001; - l = l - (1461*i)/4 + 31; - j = (80*l)/2447; - d = l - (2447*j)/80; - l = j/11; - m = j + 2 - 12*l; - y = 100*(n-49) + i + l; - - *year = y; - *month = m; - *day = d; -} - -#ifdef CONFIG_JULIAN_TIME - -static void clock_utc2julian(time_t jd, int *year, int *month, int *day) -{ - long j, k, l, n, d, i, m, y; - - j = jd + 1402; - k = (j-1)/1461; - l = j - 1461*k; - n = (l-1)/365 - l/1461; - i = l - 365*n + 30; - j = (80*i)/2447; - d = i - (2447*j)/80; - i = j/11; - m = j + 2 - 12*i; - y = 4*k + n + i - 4716; - - *year = y; - *month = m; - *day = d; -} - -#endif /* CONFIG_JULIAN_TIME */ -#else/* CONFIG_GREGORIAN_TIME */ - -/* Only handles dates since Jan 1, 1970 */ - -static void clock_utc2calendar(time_t days, int *year, int *month, int *day) -{ - int value; - int min; - int max; - int tmp; - bool leapyear; - - /* There is one leap year every four years, so we can get close with the - * following: - */ - - value = days / (4*365 + 1); /* Number of 4-years periods since the epoch*/ - days -= value * (4*365 + 1); /* Remaining days */ - value <<= 2; /* Years since the epoch */ - - /* Then we will brute force the next 0-3 years */ - - for (;;) - { - /* Is this year a leap year (we'll need this later too) */ - - leapyear = clock_isleapyear(value + 1970); - - /* Get the number of days in the year */ - - tmp = (leapyear ? 366 : 365); - - /* Do we have that many days? */ - - if (days >= tmp) - { - /* Yes.. bump up the year */ - - value++; - days -= tmp; - } - else - { - /* Nope... then go handle months */ - - break; - } - } - - /* At this point, value has the year and days has number days into this year */ - - *year = 1970 + value; - - /* Handle the month (zero based) */ - - min = 0; - max = 11; - - do - { - /* Get the midpoint */ - - value = (min + max) >> 1; - - /* Get the number of days that occurred before the beginning of the month - * following the midpoint. - */ - - tmp = clock_daysbeforemonth(value + 1, leapyear); - - /* Does the number of days before this month that equal or exceed the - * number of days we have remaining? - */ - - if (tmp > days) - { - /* Yes.. then the month we want is somewhere from 'min' and to the - * midpoint, 'value'. Could it be the midpoint? - */ - - tmp = clock_daysbeforemonth(value, leapyear); - if (tmp > days) - { - /* No... The one we want is somewhere between min and value-1 */ - - max = value - 1; - } - else - { - /* Yes.. 'value' contains the month that we want */ - - break; - } - } - else - { - /* No... The one we want is somwhere between value+1 and max */ - - min = value + 1; - } - - /* If we break out of the loop because min == max, then we want value - * to be equal to min == max. - */ - - value = min; - } - while (min < max); - - /* The selected month number is in value. Subtract the number of days in the - * selected month - */ - - days -= clock_daysbeforemonth(value, leapyear); - - /* At this point, value has the month into this year (zero based) and days has - * number of days into this month (zero based) - */ - - *month = value + 1; /* 1-based */ - *day = days + 1; /* 1-based */ -} - -#endif /* CONFIG_GREGORIAN_TIME */ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Function: gmtime_r - * - * Description: - * Time conversion (based on the POSIX API) - * - ****************************************************************************/ - -FAR struct tm *gmtime_r(FAR const time_t *timer, FAR struct tm *result) -{ - time_t epoch; - time_t jdn; - int year; - int month; - int day; - int hour; - int min; - int sec; - - /* Get the seconds since the EPOCH */ - - epoch = *timer; - sdbg("timer=%d\n", (int)epoch); - - /* Convert to days, hours, minutes, and seconds since the EPOCH */ - - jdn = epoch / SEC_PER_DAY; - epoch -= SEC_PER_DAY * jdn; - - hour = epoch / SEC_PER_HOUR; - epoch -= SEC_PER_HOUR * hour; - - min = epoch / SEC_PER_MIN; - epoch -= SEC_PER_MIN * min; - - sec = epoch; - - sdbg("hour=%d min=%d sec=%d\n", - (int)hour, (int)min, (int)sec); - - /* Convert the days since the EPOCH to calendar day */ - - clock_utc2calendar(jdn, &year, &month, &day); - - sdbg("jdn=%d year=%d month=%d day=%d\n", - (int)jdn, (int)year, (int)month, (int)day); - - /* Then return the struct tm contents */ - - result->tm_year = (int)year - 1900; /* Relative to 1900 */ - result->tm_mon = (int)month - 1; /* zero-based */ - result->tm_mday = (int)day; /* one-based */ - result->tm_hour = (int)hour; - result->tm_min = (int)min; - result->tm_sec = (int)sec; - - return result; -} - diff --git a/nuttx/lib/time/lib_isleapyear.c b/nuttx/lib/time/lib_isleapyear.c deleted file mode 100644 index 966c248e0..000000000 --- a/nuttx/lib/time/lib_isleapyear.c +++ /dev/null @@ -1,88 +0,0 @@ -/**************************************************************************** - * lib/time/lib_isleapyear.c - * - * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Public Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Public Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Function: clock_isleapyear - * - * Description: - * Return true if the specified year is a leap year - * - ****************************************************************************/ - -int clock_isleapyear(int year) -{ - return year % 400 ? (year % 100 ? (year % 4 ? 0 : 1) : 0) : 1; -} - diff --git a/nuttx/lib/time/lib_mktime.c b/nuttx/lib/time/lib_mktime.c deleted file mode 100644 index 8c17e7c0a..000000000 --- a/nuttx/lib/time/lib_mktime.c +++ /dev/null @@ -1,141 +0,0 @@ -/**************************************************************************** - * lib/time/lib_mktime.c - * - * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include - -#include - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Public Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Public Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Function: mktime - * - * Description: - * Time conversion (based on the POSIX API) - * - ****************************************************************************/ - -#ifdef CONFIG_GREGORIAN_TIME -time_t mktime(const struct tm *tp) -{ - time_t ret; - time_t jdn; - - /* Get the EPOCH-relative julian date from the calendar year, - * month, and date - */ - - jdn = clock_calendar2utc(tp->tm_year+1900, tp->tm_mon+1, tp->tm_mday); - sdbg("jdn=%d tm_year=%d tm_mon=%d tm_mday=%d\n", - (int)jdn, tp->tm_year, tp->tm_mon, tp->tm_mday); - - /* Return the seconds into the julian day. */ - - ret = ((jdn*24 + tp->tm_hour)*60 + tp->tm_min)*60 + tp->tm_sec; - sdbg("ret=%d tm_hour=%d tm_min=%d tm_sec=%d\n", - (int)ret, tp->tm_hour, tp->tm_min, tp->tm_sec); - - return ret; -} -#else - -/* Simple version that only works for dates within a (relatively) small range - * from the epoch. It does not handle earlier days or longer days where leap - * seconds, etc. apply. - */ - -time_t mktime(const struct tm *tp) -{ - unsigned int days; - - /* Years since epoch in units of days (ignoring leap years). */ - - days = (tp->tm_year - 70) * 365; - - /* Add in the extra days for the leap years prior to the current year. */ - - days += (tp->tm_year - 69) >> 2; - - /* Add in the days up to the beginning of this month. */ - - days += (time_t)clock_daysbeforemonth(tp->tm_mon, clock_isleapyear(tp->tm_year + 1900)); - - /* Add in the days since the beginning of this month (days are 1-based). */ - - days += tp->tm_mday - 1; - - /* Then convert the seconds and add in hours, minutes, and seconds */ - - return ((days * 24 + tp->tm_hour) * 60 + tp->tm_min) * 60 + tp->tm_sec; -} -#endif /* CONFIG_GREGORIAN_TIME */ - diff --git a/nuttx/lib/time/lib_strftime.c b/nuttx/lib/time/lib_strftime.c deleted file mode 100644 index cd0804f55..000000000 --- a/nuttx/lib/time/lib_strftime.c +++ /dev/null @@ -1,398 +0,0 @@ -/**************************************************************************** - * lib/time/lib_strftime.c - * - * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 -#include - -#include -#include -#include - -#include - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Public Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static const char * const g_abbrevmonthname[12] = -{ - "Jan", "Feb", "Mar", "Apr", "May", "Jun", - "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" -}; - -static const char * const g_monthname[12] = -{ - "January", "February", "March", "April", "May", "June", - "July", "August", "September", "October", "November", "December" -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Function: strftime - * - * Description: - * The strftime() function formats the broken-down time tm according to - * the format specification format and places the result in the character - * array s of size max. - * - * Ordinary characters placed in the format string are copied to s without - * conversion. Conversion specifications are introduced by a '%' charac- - * ter, and terminated by a conversion specifier character, and are - * replaced in s as follows: - * - * %b The abbreviated month name according to the current locale. - * %B The full month name according to the current locale. - * %C The century number (year/100) as a 2-digit integer. (SU) - * %d The day of the month as a decimal number (range 01 to 31). - * %e Like %d, the day of the month as a decimal number, but a leading - * zero is replaced by a space. - * %h Equivalent to %b. (SU) - * %H The hour as a decimal number using a 24-hour clock (range 00 to 23). - * %I The hour as a decimal number using a 12-hour clock (range 01 to 12). - * %j The day of the year as a decimal number (range 001 to 366). - * %k The hour (24-hour clock) as a decimal number (range 0 to 23); - * single digits are preceded by a blank. (See also %H.) (TZ) - * %l The hour (12-hour clock) as a decimal number (range 1 to 12); - * single digits are preceded by a blank. (See also %I.) (TZ) - * %m The month as a decimal number (range 01 to 12). - * %M The minute as a decimal number (range 00 to 59). - * %n A newline character. (SU) - * %p Either "AM" or "PM" according to the given time value, or the - * corresponding strings for the current locale. Noon is treated - * as "PM" and midnight as "AM". - * %P Like %p but in lowercase: "am" or "pm" or a corresponding string - * for the current locale. (GNU) - * %s The number of seconds since the Epoch, that is, since 1970-01-01 - * 00:00:00 UTC. (TZ) - * %S The second as a decimal number (range 00 to 60). (The range is - * up to 60 to allow for occasional leap seconds.) - * %t A tab character. (SU) - * %y The year as a decimal number without a century (range 00 to 99). - * %Y The year as a decimal number including the century. - * %% A literal '%' character. - * - * Returned Value: - * The strftime() function returns the number of characters placed in the - * array s, not including the terminating null byte, provided the string, - * including the terminating null byte, fits. Otherwise, it returns 0, - * and the contents of the array is undefined. - * - ****************************************************************************/ - -size_t strftime(char *s, size_t max, const char *format, const struct tm *tm) -{ - const char *str; - char *dest = s; - int chleft = max; - int value; - int len; - - while (*format && chleft > 0) - { - /* Just copy regular characters */ - - if (*format != '%') - { - *dest++ = *format++; - chleft--; - continue; - } - - /* Handle the format character */ - - format++; - len = 0; - - switch (*format++) - { - /* %a: A three-letter abbreviation for the day of the week. */ - /* %A: The full name for the day of the week. */ - - case 'a': - case 'A': - { - len = snprintf(dest, chleft, "Day"); /* Not supported */ - } - break; - - /* %h: Equivalent to %b */ - - case 'h': - - /* %b: The abbreviated month name according to the current locale. */ - - case 'b': - { - if (tm->tm_mon < 12) - { - str = g_abbrevmonthname[tm->tm_mon]; - len = snprintf(dest, chleft, "%s", str); - } - } - break; - - /* %B: The full month name according to the current locale. */ - - case 'B': - { - if (tm->tm_mon < 12) - { - str = g_monthname[tm->tm_mon]; - len = snprintf(dest, chleft, "%s", str); - } - } - break; - - /* %y: The year as a decimal number without a century (range 00 to 99). */ - - case 'y': - - /* %C: The century number (year/100) as a 2-digit integer. */ - - case 'C': - { - len = snprintf(dest, chleft, "%02d", tm->tm_year % 100); - } - break; - - /* %d: The day of the month as a decimal number (range 01 to 31). */ - - case 'd': - { - len = snprintf(dest, chleft, "%02d", tm->tm_mday); - } - break; - - /* %e: Like %d, the day of the month as a decimal number, but a leading - * zero is replaced by a space. - */ - - case 'e': - { - len = snprintf(dest, chleft, "%2d", tm->tm_mday); - } - break; - - /* %H: The hour as a decimal number using a 24-hour clock (range 00 to 23). */ - - case 'H': - { - len = snprintf(dest, chleft, "%02d", tm->tm_hour); - } - break; - - /* %I: The hour as a decimal number using a 12-hour clock (range 01 to 12). */ - - case 'I': - { - len = snprintf(dest, chleft, "%02d", tm->tm_hour % 12); - } - break; - - /* %j: The day of the year as a decimal number (range 001 to 366). */ - - case 'j': - { - if (tm->tm_mon < 12) - { - value = clock_daysbeforemonth(tm->tm_mon, clock_isleapyear(tm->tm_year)) + tm->tm_mday; - len = snprintf(dest, chleft, "%03d", value); - } - } - break; - - /* %k: The hour (24-hour clock) as a decimal number (range 0 to 23); - * single digits are preceded by a blank. - */ - - case 'k': - { - len = snprintf(dest, chleft, "%2d", tm->tm_hour); - } - break; - - /* %l: The hour (12-hour clock) as a decimal number (range 1 to 12); - * single digits are preceded by a blank. - */ - - case 'l': - { - len = snprintf(dest, chleft, "%2d", tm->tm_hour % 12); - } - break; - - /* %m: The month as a decimal number (range 01 to 12). */ - - case 'm': - { - len = snprintf(dest, chleft, "%02d", tm->tm_mon + 1); - } - break; - - /* %M: The minute as a decimal number (range 00 to 59). */ - - case 'M': - { - len = snprintf(dest, chleft, "%02d", tm->tm_min); - } - break; - - /* %n: A newline character. */ - - case 'n': - { - *dest = '\n'; - len = 1; - } - break; - - /* %p: Either "AM" or "PM" according to the given time value. */ - - case 'p': - { - if (tm->tm_hour >= 12) - { - str = "PM"; - } - else - { - str = "AM"; - } - len = snprintf(dest, chleft, "%s", str); - } - break; - - /* %P: Like %p but in lowercase: "am" or "pm" */ - - case 'P': - { - if (tm->tm_hour >= 12) - { - str = "pm"; - } - else - { - str = "am"; - } - len = snprintf(dest, chleft, "%s", str); - } - break; - - /* %s: The number of seconds since the Epoch, that is, since 1970-01-01 - * 00:00:00 UTC. - */ - - case 's': - { - len = snprintf(dest, chleft, "%d", mktime(tm)); - } - break; - - /* %S: The second as a decimal number (range 00 to 60). (The range is - * up to 60 to allow for occasional leap seconds.) - */ - - case 'S': - { - len = snprintf(dest, chleft, "%02d", tm->tm_sec); - } - break; - - /* %t: A tab character. */ - - case 't': - { - *dest = '\t'; - len = 1; - } - break; - - /* %Y: The year as a decimal number including the century. */ - - case 'Y': - { - len = snprintf(dest, chleft, "%04d", tm->tm_year + 1900); - } - break; - - /* %%: A literal '%' character. */ - - case '%': - { - *dest = '%'; - len = 1; - } - break; - } - - /* Update counts and pointers */ - - dest += len; - chleft -= len; - } - - return max - chleft; -} diff --git a/nuttx/lib/time/lib_time.c b/nuttx/lib/time/lib_time.c deleted file mode 100644 index 106a04c36..000000000 --- a/nuttx/lib/time/lib_time.c +++ /dev/null @@ -1,110 +0,0 @@ -/**************************************************************************** - * lib/time/lib_time.c - * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include - -#ifndef CONFIG_DISABLE_CLOCK - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Function: time - * - * Description: - * Get the current calendar time as a time_t object. The function returns - * this value, and if the argument is not a null pointer, the value is also - * set to the object pointed by tloc. - * - * Note that this function is just a thin wrapper around gettimeofday() - * and is provided for compatibility. gettimeofday() is the preffered way - * to obtain system time. - * - * Parameters: - * Pointer to an object of type time_t, where the time value is stored. - * Alternativelly, this parameter can be a null pointer, in which case the - * parameter is not used, but a time_t object is still returned by the - * function. - * - * Return Value: - * The current calendar time as a time_t object. If the argument is not - * a null pointer, the return value is the same as the one stored in the - * location pointed by the argument. - * - * If the function could not retrieve the calendar time, it returns a -1 - * value. - * - ****************************************************************************/ - -time_t time(time_t *tloc) -{ - struct timeval tp; - int ret; - - /* Get the current time from the system */ - - ret = gettimeofday(&tp, NULL); - if (ret == OK) - { - /* Return the seconds since the epoch */ - - if (tloc) - { - *tloc = tp.tv_sec; - } - - return tp.tv_sec; - } - - return (time_t)ERROR; -} - -#endif /* !CONFIG_DISABLE_CLOCK */ diff --git a/nuttx/lib/unistd/Make.defs b/nuttx/lib/unistd/Make.defs deleted file mode 100644 index e1441a48d..000000000 --- a/nuttx/lib/unistd/Make.defs +++ /dev/null @@ -1,49 +0,0 @@ -############################################################################ -# lib/unistd/Make.defs -# -# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt -# -# 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. -# -############################################################################ - -# Add the unistd C files to the build - -CSRCS += lib_getopt.c lib_getoptargp.c lib_getoptindp.c lib_getoptoptp.c - -ifneq ($(CONFIG_NFILE_DESCRIPTORS),0) -ifneq ($(CONFIG_DISABLE_ENVIRON),y) -CSRCS += lib_chdir.c lib_getcwd.c -endif -endif - -# Add the unistd directory to the build - -DEPPATH += --dep-path unistd -VPATH += :unistd diff --git a/nuttx/lib/unistd/lib_chdir.c b/nuttx/lib/unistd/lib_chdir.c deleted file mode 100644 index 3dd1333ce..000000000 --- a/nuttx/lib/unistd/lib_chdir.c +++ /dev/null @@ -1,179 +0,0 @@ -/**************************************************************************** - * lib/unistd/lib_chdir.c - * - * Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include -#include -#include -#include - -#include "lib_internal.h" - -#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_ENVIRON) - -/**************************************************************************** - * Public Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: _trimdir - ****************************************************************************/ - -#if 0 -static inline void _trimdir(char *path) -{ - /* Skip any trailing '/' characters (unless it is also the leading '/') */ - - int len = strlen(path) - 1; - while (len > 0 && path[len] == '/') - { - path[len] = '\0'; - len--; - } -} -#else -# define _trimdir(p) -#endif - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: chdir - * - * Description: - * The chdir() function causes the directory named by the pathname pointed - * to by the 'path' argument to become the current working directory; that - * is, the starting point for path searches for pathnames not beginning - * with '/'. - * - * Input Parmeters: - * path - A pointer to a directory to use as the new current working - * directory - * - * Returned Value: - * 0(OK) on success; -1(ERROR) on failure with errno set appropriately: - * - * EACCES - * Search permission is denied for any component of the pathname. - * ELOOP - * A loop exists in symbolic links encountered during resolution of the - * 'path' argument OR more that SYMLOOP_MAX symbolic links in the - * resolution of the 'path' argument. - * ENAMETOOLONG - * The length of the path argument exceeds PATH_MAX or a pathname component - * is longer than NAME_MAX. - * ENOENT - * A component of 'path' does not name an existing directory or path is - * an empty string. - * ENOTDIR - * A component of the pathname is not a directory. - * - ****************************************************************************/ - -int chdir(FAR const char *path) -{ - struct stat buf; - char *oldpwd; - char *alloc; - int err; - int ret; - - /* Verify the input parameters */ - - if (!path) - { - err = ENOENT; - goto errout; - } - - /* Verify that 'path' refers to a directory */ - - ret = stat(path, &buf); - if (ret != 0) - { - err = ENOENT; - goto errout; - } - - /* Something exists here... is it a directory? */ - - if (!S_ISDIR(buf.st_mode)) - { - err = ENOTDIR; - goto errout; - } - - /* Yes, it is a directory. Remove any trailing '/' characters from the path */ - - _trimdir(path); - - /* Replace any preceding OLDPWD with the current PWD (this is to - * support 'cd -' in NSH) - */ - - sched_lock(); - oldpwd = getenv("PWD"); - if (!oldpwd) - { - oldpwd = CONFIG_LIB_HOMEDIR; - } - - alloc = strdup(oldpwd); /* kludge needed because environment is realloc'ed */ - setenv("OLDPWD", alloc, TRUE); - lib_free(alloc); - - /* Set the cwd to the input 'path' */ - - setenv("PWD", path, TRUE); - sched_unlock(); - return OK; - -errout: - set_errno(err); - return ERROR; -} -#endif /* CONFIG_NFILE_DESCRIPTORS && !CONFIG_DISABLE_ENVIRON */ diff --git a/nuttx/lib/unistd/lib_getcwd.c b/nuttx/lib/unistd/lib_getcwd.c deleted file mode 100644 index b94823300..000000000 --- a/nuttx/lib/unistd/lib_getcwd.c +++ /dev/null @@ -1,132 +0,0 @@ -/**************************************************************************** - * lib/unistd/lib_getcwd.c - * - * Copyright (C) 2008, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include -#include -#include -#include - -#include "lib_internal.h" - -#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_ENVIRON) - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Public Variables - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: getwcd - * - * Description: - * getcwd() function places the absolute pathname of the current working - * directory in the array pointed to by 'buf', and returns 'buf.' The - * pathname copied to the array shall contain no components that are - * symbolic links. The 'size' argument is the size in bytes of the - * character array pointed to by the 'buf' argument. - * - * Input Parmeters: - * buf - a pointer to the location in which the current working directory - * pathaname is returned. - * size - The size in bytes avaiable at 'buf' - * - * Returned Value: - * Upon successful completion, getcwd() returns the 'buf' argument. - * Otherwise, getcwd() returns a null pointer and sets errno to indicate - * the error: - * - * EINVAL - * The 'size' argument is 0 or the 'buf' argument is NULL. - * ERANGE - * The size argument is greater than 0, but is smaller than the length - * of the currrent working directory pathname +1. - * EACCES - * Read or search permission was denied for a component of the pathname. - * ENOMEM - * Insufficient storage space is available. - * - ****************************************************************************/ - -FAR char *getcwd(FAR char *buf, size_t size) -{ - char *pwd; - - /* Verify input parameters */ - -#ifdef CONFIG_DEBUG - if (!buf || !size) - { - set_errno(EINVAL); - return NULL; - } -#endif - - /* If no working directory is defined, then default to the home directory */ - - pwd = getenv("PWD"); - if (!pwd) - { - pwd = CONFIG_LIB_HOMEDIR; - } - - /* Verify that the cwd will fit into the user-provided buffer */ - - if (strlen(pwd) + 1 > size) - { - set_errno(ERANGE); - return NULL; - } - - /* Copy the cwd to the user buffer */ - - strcpy(buf, pwd); - sched_unlock(); - return buf; -} -#endif /* CONFIG_NFILE_DESCRIPTORS && !CONFIG_DISABLE_ENVIRON */ diff --git a/nuttx/lib/unistd/lib_getopt.c b/nuttx/lib/unistd/lib_getopt.c deleted file mode 100644 index 832d28721..000000000 --- a/nuttx/lib/unistd/lib_getopt.c +++ /dev/null @@ -1,269 +0,0 @@ -/**************************************************************************** - * lib/unistd/lib_getopt.c - * - * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -FAR char *optarg; /* Optional argument following option */ -int optind = 1; /* Index into argv */ -int optopt = '?'; /* unrecognized option character */ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -static FAR char *g_optptr = NULL; -static bool g_binitialized = false; - -/**************************************************************************** - * Global Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: getopt - * - * Description: getopt() parses command-line arguments. Its arguments argc - * and argv are the argument count and array as passed to the main() - * function on program invocation. An element of argv that starts with - * '-' is an option element. The characters of this element (aside from - * the initial '-') are option characters. If getopt() is called repeatedly, - * it returns successively each of the option characters from each of the - * option elements. - * - * If getopt() finds another option character, it returns that character, - * updating the external variable optind and a static variable nextchar so - * that the next call to getopt() can resume the scan with the following - * option character or argv-element. - * - * If there are no more option characters, getopt() returns -1. Then optind - * is the index in argv of the first argv-element that is not an option. - * - * The 'optstring' argument is a string containing the legitimate option - * characters. If such a character is followed by a colon, this indicates - * that the option requires an argument. If an argument is required for an - * option so getopt() places a pointer to the following text in the same - * argv-element, or the text of the following argv-element, in optarg. - * - * NOTES: - * 1. opterr is not supported and this implementation of getopt() never - * printfs error messages. - * 2. getopt is NOT threadsafe! - * 3. This version of getopt() does not reset global variables until - * -1 is returned. As a result, your command line parsing loops - * must call getopt() repeatedly and continue to parse if other - * errors are returned ('?' or ':') until getopt() finally returns -1. - * (You can also set optind to -1 to force a reset). - * - * Return: If an option was successfully found, then getopt() returns the - * option character. If all command-line options have been parsed, then - * getopt() returns -1. If getopt() encounters an option character that - * was not in optstring, then '?' is returned. If getopt() encounters an - * option with a missing argument, then the return value depends on the - * first character in optstring: if it is ':', then ':' is returned; - * otherwise '?' is returned. - * - ****************************************************************************/ - -int getopt(int argc, FAR char *const argv[], FAR const char *optstring) -{ - if (argv && optstring && argc > 1) - { - int noarg_ret = '?'; - char *optchar; - - /* The inital value of optind is 1. If getopt() is called again in the - * program, optind must be reset to some value <= 1. - */ - - if (optind < 1 || !g_binitialized) - { - optind = 1; /* Skip over the program name */ - g_optptr = NULL; /* Start at the beginning of the first argument */ - g_binitialized = true; /* Now we are initialized */ - } - - /* If the first character of opstring s ':', then ':' is in the event of - * a missing argument. Otherwise '?' is returned. - */ - - if (*optstring == ':') - { - noarg_ret = ':'; - optstring++; - } - - /* Are we resuming in the middle, or at the end of a string of arguments? - * g_optptr == NULL means that we are started at the beginning of argv[optind]; - * *g_optptr == \0 means that we are starting at the beginning of optind+1 - */ - - while (!g_optptr || !*g_optptr) - { - /* We need to start at the beginning of the next argv. Check if we need - * to increment optind - */ - - if (g_optptr) - { - /* Yes.. Increment it and check for the case where where we have - * processed everything in the argv[] array. - */ - - optind++; - } - - /* Check for the end of the argument list */ - - g_optptr = argv[optind]; - if (!g_optptr) - { - /* There are no more arguments, we are finished */ - - g_binitialized = false; - return ERROR; - } - - /* We are starting at the beginning of argv[optind]. In this case, the - * first character must be '-' - */ - - if (*g_optptr != '-') - { - /* The argument does not start with '-', we are finished */ - - g_binitialized = false; - return ERROR; - } - - /* Skip over the '-' */ - - g_optptr++; - } - - /* Special case handling of "-" and "-:" */ - - if (!*g_optptr) - { - optopt = '\0'; /* We'll fix up g_optptr the next time we are called */ - return '?'; - } - - /* Handle the case of "-:" */ - - if (*g_optptr == ':') - { - optopt = ':'; - g_optptr++; - return '?'; - } - - /* g_optptr now points at the next option and it is not something crazy. - * check if the option is in the list of valid options. - */ - - optchar = strchr(optstring, *g_optptr); - if (!optchar) - { - /* No this character is not in the list of valid options */ - - optopt = *g_optptr; - g_optptr++; - return '?'; - } - - /* Yes, the character is in the list of valid options. Does it have an - * required argument? - */ - - if (optchar[1] != ':') - { - /* No, no arguments. Just return the character that we found */ - - g_optptr++; - return *optchar; - } - - /* Yes, it has a required argument. Is the required argument - * immediately after the command in this same argument? - */ - - if (g_optptr[1] != '\0') - { - /* Yes, return a pointer into the current argument */ - - optarg = &g_optptr[1]; - optind++; - g_optptr = NULL; - return *optchar; - } - - /* No.. is the optional argument the next argument in argv[] ? */ - - if (argv[optind+1] && *argv[optind+1] != '-') - { - /* Yes.. return that */ - - optarg = argv[optind+1]; - optind += 2; - g_optptr = NULL; - return *optchar; - } - - /* No argument was supplied */ - - optarg = NULL; - optopt = *optchar; - optind++; - return noarg_ret; - } - - g_binitialized = false; - return ERROR; -} diff --git a/nuttx/lib/unistd/lib_getoptargp.c b/nuttx/lib/unistd/lib_getoptargp.c deleted file mode 100644 index 98a485016..000000000 --- a/nuttx/lib/unistd/lib_getoptargp.c +++ /dev/null @@ -1,73 +0,0 @@ -/**************************************************************************** - * lib/unistd/lib_getoptargp.c - * - * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Global Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: getoptargp - * - * Description: - * Returns a pointer to optarg. This function is only used for external - * modules that need to access the base, global variable, optarg. - * - ****************************************************************************/ - -FAR char **getoptargp(void) -{ - return &optarg; -} - diff --git a/nuttx/lib/unistd/lib_getoptindp.c b/nuttx/lib/unistd/lib_getoptindp.c deleted file mode 100644 index 7714f8e70..000000000 --- a/nuttx/lib/unistd/lib_getoptindp.c +++ /dev/null @@ -1,73 +0,0 @@ -/**************************************************************************** - * lib/unistd/lib_getoptindp.c - * - * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Global Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: getoptindp - * - * Description: - * Returns a pointer to optind. This function is only used for external - * modules that need to access the base, global variable, optind. - * - ****************************************************************************/ - -int *getoptindp(void) -{ - return &optind; -} - diff --git a/nuttx/lib/unistd/lib_getoptoptp.c b/nuttx/lib/unistd/lib_getoptoptp.c deleted file mode 100644 index 4805b7ac3..000000000 --- a/nuttx/lib/unistd/lib_getoptoptp.c +++ /dev/null @@ -1,73 +0,0 @@ -/**************************************************************************** - * lib/unistd/lib_getoptoptp.c - * - * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Global Variables - ****************************************************************************/ - -/**************************************************************************** - * Private Variables - ****************************************************************************/ - -/**************************************************************************** - * Global Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: getoptoptp - * - * Description: - * Returns a pointer to optopt. This function is only used for external - * modules that need to access the base, global variable, optopt. - * - ****************************************************************************/ - -int *getoptoptp(void) -{ - return &optopt; -} - diff --git a/nuttx/libc/Kconfig b/nuttx/libc/Kconfig new file mode 100644 index 000000000..bd470be7f --- /dev/null +++ b/nuttx/libc/Kconfig @@ -0,0 +1,275 @@ +# +# For a description of the syntax of this configuration file, +# see misc/tools/kconfig-language.txt. +# + +config STDIO_BUFFER_SIZE + int "C STDIO buffer size" + default 64 + ---help--- + Size of buffers using within the C buffered I/O interfaces. + (printf, putchar, fwrite, etc.). + +config STDIO_LINEBUFFER + bool "STDIO line buffering" + default y + ---help--- + Flush buffer I/O whenever a newline character is found in + the output data stream. + +config NUNGET_CHARS + int "Number unget() characters" + default 2 + ---help--- + Number of characters that can be buffered by ungetc() (Only if NFILE_STREAMS > 0) + +config LIB_HOMEDIR + string "Home directory" + default "/" + depends on !DISABLE_ENVIRON + ---help--- + The home directory to use with operations like such as 'cd ~' + +source libc/math/Kconfig + +config NOPRINTF_FIELDWIDTH + bool "Disable sprintf support fieldwidth" + default n + ---help--- + sprintf-related logic is a + little smaller if we do not support fieldwidthes + +config LIBC_FLOATINGPOINT + bool "Enable floating point in printf" + default n + ---help--- + By default, floating point + support in printf, sscanf, etc. is disabled. + +choice + prompt "Newline Options" + default EOL_IS_EITHER_CRLF + ---help--- + This selection determines the line terminating character that is used. + Some environments may return CR as end-of-line, others LF, and others + both. If not specified, the default is either CR or LF (but not both) + as the line terminating charactor. + +config EOL_IS_CR + bool "EOL is CR" + +config EOL_IS_LF + bool "EOL is LF" + +config EOL_IS_BOTH_CRLF + bool "EOL is CR and LF" + +config EOL_IS_EITHER_CRLF + bool "EOL is CR or LF" + +endchoice + +config LIBC_STRERROR + bool "Enable strerror" + default n + ---help--- + strerror() is useful because it decodes 'errno' values into a human readable + strings. But it can also require a lot of memory. If this option is selected, + strerror() will still exist in the build but it will not decode error values. + This option should be used by other logic to decide if it should use strerror() + or not. For example, the NSH application will not use strerror() if this + option is not selected; perror() will not use strerror() is this option is not + selected (see also NSH_STRERROR). + +config LIBC_STRERROR_SHORT + bool "Use short error descriptions in strerror()" + default n + depends on LIBC_STRERROR + ---help--- + If this option is selected, then strerror() will use a shortened string when + it decodes the error. Specifically, strerror() is simply use the string that + is the common name for the error. For example, the 'errno' value of 2 will + produce the string "No such file or directory" is LIBC_STRERROR_SHORT + is not defined but the string "ENOENT" is LIBC_STRERROR_SHORT is defined. + +config LIBC_PERROR_STDOUT + bool "perror() to stdout" + default n + ---help--- + POSIX requires that perror() provide its output on stderr. This option may + be defined, however, to provide perror() output that is serialized with + other stdout messages. + +config ARCH_LOWPUTC + bool "Low-level console output" + default "y" + ---help--- + architecture supports low-level, boot time console output + +config LIB_SENDFILE_BUFSIZE + int "sendfile() buffer size" + default 512 + ---help--- + Size of the I/O buffer to allocate in sendfile(). Default: 512b + +config ARCH_ROMGETC + bool "Support for ROM string access" + default n + ---help--- + In Harvard architectures, data accesses and instruction accesses + occur on different busses, perhaps concurrently. All data accesses + are performed on the data bus unless special machine instructions + are used to read data from the instruction address space. Also, in + the typical MCU, the available SRAM data memory is much smaller that + the non-volatile FLASH instruction memory. So if the application + requires many constant strings, the only practical solution may be + to store those constant strings in FLASH memory where they can only + be accessed using architecture-specific machine instructions. + + If ARCH_ROMGETC is defined, then the architecture logic must export + the function up_romgetc(). up_romgetc() will simply read one byte + of data from the instruction space. + + If ARCH_ROMGETC, certain C stdio functions are effected: (1) All + format strings in printf, fprintf, sprintf, etc. are assumed to lie + in FLASH (string arguments for %s are still assumed to reside in SRAM). + And (2), the string argument to puts and fputs is assumed to reside + in FLASH. Clearly, these assumptions may have to modified for the + particular needs of your environment. There is no "one-size-fits-all" + solution for this problem. + +config ARCH_OPTIMIZED_FUNCTIONS + bool "Enable arch optimized functions" + default n + ---help--- + Allow for architecture optimized implementations of certain library + functions. Architecture-specific implementations can improve overall + system performance. + +if ARCH_OPTIMIZED_FUNCTIONS +config ARCH_MEMCPY + bool "memcpy()" + default n + ---help--- + Select this option if the architecture provides an optimized version + of memcpy(). + +config MEMCPY_VIK + bool "Vik memcpy()" + default n + depends on !ARCH_MEMCPY + ---help--- + Select this option to use the optimized memcpy() function by Daniel Vik. + Select this option for improved performance at the expense of increased + size. See licensing information in the top-level COPYING file. + +if MEMCPY_VIK +config MEMCPY_PRE_INC_PTRS + bool "Pre-increment pointers" + default n + ---help--- + Use pre-increment of pointers. Default is post increment of pointers. + +config MEMCPY_INDEXED_COPY + bool "Array indexing" + default y + ---help--- + Copying data using array indexing. Using this option, disables the + MEMCPY_PRE_INC_PTRS option. + +config MEMCPY_64BIT + bool "64-bit memcpy()" + default n + ---help--- + Compiles memcpy() for architectures that suppport 64-bit operations + efficiently. + +endif + +config ARCH_MEMCMP + bool "memcmp()" + default n + ---help--- + Select this option if the architecture provides an optimized version + of memcmp(). + +config ARCH_MEMMOVE + bool "memmove()" + default n + ---help--- + Select this option if the architecture provides an optimized version + of memmove(). + +config ARCH_MEMSET + bool "memset()" + default n + ---help--- + Select this option if the architecture provides an optimized version + of memset(). + +config MEMSET_OPTSPEED + bool "Optimize memset() for speed" + default n + depends on !ARCH_MEMSET + ---help--- + Select this option to use a version of memcpy() optimized for speed. + Default: memcpy() is optimized for size. + +config MEMSET_64BIT + bool "64-bit memset()" + default n + depends on MEMSET_OPTSPEED + ---help--- + Compiles memset() for architectures that suppport 64-bit operations + efficiently. + +config ARCH_STRCHR + bool "strchr()" + default n + ---help--- + Select this option if the architecture provides an optimized version + of strchr(). + +config ARCH_STRCMP + bool "strcmp()" + default n + ---help--- + Select this option if the architecture provides an optimized version + of strcmp(). + +config ARCH_STRCPY + bool "strcpy()" + default n + ---help--- + Select this option if the architecture provides an optimized version + of strcpy(). + +config ARCH_STRNCPY + bool "strncpy()" + default n + ---help--- + Select this option if the architecture provides an optimized version + of strncpy(). + +config ARCH_STRLEN + bool "strlen" + default n + ---help--- + Select this option if the architecture provides an optimized version + of strlen(). + +config ARCH_STRNLEN + bool "strlen()" + default n + ---help--- + Select this option if the architecture provides an optimized version + of strnlen(). + +config ARCH_BZERO + bool "bzero()" + default n + ---help--- + Select this option if the architecture provides an optimized version + of bzero(). + +endif diff --git a/nuttx/libc/Makefile b/nuttx/libc/Makefile new file mode 100644 index 000000000..22dbba1d9 --- /dev/null +++ b/nuttx/libc/Makefile @@ -0,0 +1,145 @@ +############################################################################ +# libc/Makefile +# +# Copyright (C) 2007-2012 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name NuttX nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +########################################################################### + +-include $(TOPDIR)/Make.defs + +ASRCS = +CSRCS = + +DEPPATH := --dep-path . +VPATH := . + +include stdio/Make.defs +include stdlib/Make.defs +include unistd/Make.defs +include sched/Make.defs +include string/Make.defs +include pthread/Make.defs +include semaphore/Make.defs +include signal/Make.defs +include mqueue/Make.defs +include math/Make.defs +include fixedmath/Make.defs +include net/Make.defs +include time/Make.defs +include libgen/Make.defs +include dirent/Make.defs +include termios/Make.defs +include queue/Make.defs +include misc/Make.defs + +AOBJS = $(ASRCS:.S=$(OBJEXT)) +COBJS = $(CSRCS:.c=$(OBJEXT)) + +SRCS = $(ASRCS) $(CSRCS) +OBJS = $(AOBJS) $(COBJS) + +UBIN = libuc$(LIBEXT) +KBIN = libkc$(LIBEXT) +BIN = libc$(LIBEXT) + +all: $(BIN) + +$(AOBJS): %$(OBJEXT): %.S + $(call ASSEMBLE, $<, $@) + +$(COBJS): %$(OBJEXT): %.c + $(call COMPILE, $<, $@) + +$(BIN): $(OBJS) + $(call ARCHIVE, $@, $(OBJS)) + +ifneq ($(BIN),$(UBIN)) +.userlib: + $(Q) $(MAKE) $(UBIN) BIN=$(UBIN) TOPDIR=$(TOPDIR) EXTRADEFINES=$(EXTRADEFINES) + $(Q) touch .userlib + +$(UBIN): kclean .userlib +endif + +ifneq ($(BIN),$(KBIN)) +.kernlib: + $(Q) $(MAKE) $(KBIN) BIN=$(KBIN) TOPDIR=$(TOPDIR) EXTRADEFINES=$(EXTRADEFINES) + $(Q) touch .kernlib + +$(KBIN): uclean .kernlib +endif + +.depend: Makefile $(SRCS) + $(Q) $(MKDEP) $(DEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep + $(Q) touch $@ + +depend: .depend + +# Clean Targets: +# Clean user-mode temporary files (retaining the UBIN binary) + +uclean: +ifneq ($(OBJEXT),) +ifeq ($(CONFIG_WINDOWS_NATIVE),y) + $(Q) if exist .userlib ]; then del *$(OBJEXT) +else + $(Q) ( if [ -f .userlib ]; then rm -f *$(OBJEXT); fi ) +endif +endif + $(call DELFILE, .userlib) + +# Clean kernel-mode temporary files (retaining the KBIN binary) + +kclean: +ifneq ($(OBJEXT),) +ifeq ($(CONFIG_WINDOWS_NATIVE),y) + $(Q) if exist .kernlib ]; then del *$(OBJEXT) +else + $(Q) ( if [ -f .kernlib ]; then rm -f *$(OBJEXT); fi ) +endif +endif + $(call DELFILE, .kernlib) + +# Really clean everything + +clean: uclean kclean + $(call DELFILE, $(BIN)) + $(call DELFILE, $(UBIN)) + $(call DELFILE, $(KBIN)) + $(call CLEAN) + +# Deep clean -- removes all traces of the configuration + +distclean: clean + $(call DELFILE, Make.dep) + $(call DELFILE, .depend) + +-include Make.dep diff --git a/nuttx/libc/README.txt b/nuttx/libc/README.txt new file mode 100644 index 000000000..ed672d038 --- /dev/null +++ b/nuttx/libc/README.txt @@ -0,0 +1,85 @@ +lib +=== + +This directory contains numerous, small functions typically associated with +what you would expect to find in a standard C library. The sub-directories +in this directory contain standard interface that can be executed by user- +mode programs. + +Normally, NuttX is built with no protection and all threads running in kerne- +mode. In that model, there is no real architectural distinction between +what is a kernel-mode program and what is a user-mode program; the system is +more like on multi-threaded program that all runs in kernel-mode. + +But if the CONFIG_NUTTX_KERNEL option is selected, NuttX will be built into +distinct user-mode and kernel-mode sections. In that case, most of the +code in the nuttx/ directory will run in kernel-mode with with exceptions +of (1) the user-mode "proxies" found in syscall/proxies, and (2) the +standard C library functions found in this directory. In this build model, +it is critical to separate the user-mode OS interfaces in this way. + +Sub-Directories +=============== + +The files in the libc/ directory are organized (mostly) according which file +in the include/ directory provides the prototype for library functions. So +we have: + + libgen - libgen.h + fixedmath - fixedmath.h + math - math.h + mqueue - pthread.h + net - Various network-related header files: netinet/ether.h, arpa/inet.h + pthread - pthread.h + queue - queue.h + sched - sched.h + semaphore - semaphore.h + stdio - stdio.h + stdlib - stdlib.h + string - string.h + time - time.h + unistd - unistd.h + +There is also a misc/ subdirectory that contains various internal functions +and interfaces from header files that are too few to warrant their own sub- +directory: + + misc - Nonstandard "glue" logic, debug.h, crc32.h, dirent.h + +Library Database +================ + +Information about functions available in the NuttX C library information is +maintained in a database. That "database" is implemented as a simple comma- +separated-value file, lib.csv. Most spreadsheets programs will accept this +format and can be used to maintain the library database. + +This library database will (eventually) be used to generate symbol library +symbol table information that can be exported to external applications. + +The format of the CSV file for each line is: + + Field 1: Function name + Field 2: The header file that contains the function prototype + Field 3: Condition for compilation + Field 4: The type of function return value. + Field 5 - N+5: The type of each of the N formal parameters of the function + +Each type field has a format as follows: + + type name: + For all simpler types + formal type | actual type: + For array types where the form of the formal (eg. int parm[2]) + differs from the type of actual passed parameter (eg. int*). This + is necessary because you cannot do simple casts to array types. + formal type | union member actual type | union member fieldname: + A similar situation exists for unions. For example, the formal + parameter type union sigval -- You cannot cast a uintptr_t to + a union sigval, but you can cast to the type of one of the union + member types when passing the actual paramter. Similarly, we + cannot cast a union sigval to a uinptr_t either. Rather, we need + to cast a specific union member fieldname to uintptr_t. + +NOTE: The tool mksymtab can be used to generate a symbol table from this CSV +file. See nuttx/tools/README.txt for further details about the use of mksymtab. diff --git a/nuttx/libc/dirent/Make.defs b/nuttx/libc/dirent/Make.defs new file mode 100644 index 000000000..f2927bed8 --- /dev/null +++ b/nuttx/libc/dirent/Make.defs @@ -0,0 +1,48 @@ +############################################################################ +# libc/dirent/Make.defs +# +# Copyright (C) 2012 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# 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. +# +############################################################################ + +ifneq ($(CONFIG_NFILE_DESCRIPTORS),0) + +# Add the dirent C files to the build + +CSRCS += lib_readdirr.c lib_telldir.c + +# Add the dirent directory to the build + +DEPPATH += --dep-path dirent +VPATH += :dirent + +endif + diff --git a/nuttx/libc/dirent/lib_readdirr.c b/nuttx/libc/dirent/lib_readdirr.c new file mode 100644 index 000000000..93c99ac28 --- /dev/null +++ b/nuttx/libc/dirent/lib_readdirr.c @@ -0,0 +1,122 @@ +/**************************************************************************** + * libc/dirent/lib_readdirr.c + * + * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include +#include + +#include + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: readdir_r + * + * Description: + * The readdir() function returns a pointer to a dirent + * structure representing the next directory entry in the + * directory stream pointed to by dir. It returns NULL on + * reaching the end-of-file or if an error occurred. + * + * Inputs: + * dirp -- An instance of type DIR created by a previous + * call to opendir(); + * entry -- The storage pointed to by entry must be large + * enough for a dirent with an array of char d_name + * members containing at least {NAME_MAX}+1 elements. + * result -- Upon successful return, the pointer returned + * at *result shall have the same value as the + * argument entry. Upon reaching the end of the directory + * stream, this pointer shall have the value NULL. + * + * Return: + * If successful, the readdir_r() function return s zero; + * otherwise, an error number is returned to indicate the + * error. + * + * EBADF - Invalid directory stream descriptor dir + * + ****************************************************************************/ + +int readdir_r(FAR DIR *dirp, FAR struct dirent *entry, + FAR struct dirent **result) +{ + struct dirent *tmp; + + /* NOTE: The following use or errno is *not* thread-safe */ + + set_errno(0); + tmp = readdir(dirp); + if (!tmp) + { + int error = get_errno(); + if (!error) + { + if (result) + { + *result = NULL; + } + return 0; + } + else + { + return error; + } + } + + if (entry) + { + memcpy(entry, tmp, sizeof(struct dirent)); + } + + if (result) + { + *result = entry; + } + return 0; +} + diff --git a/nuttx/libc/dirent/lib_telldir.c b/nuttx/libc/dirent/lib_telldir.c new file mode 100644 index 000000000..f77a4a1c2 --- /dev/null +++ b/nuttx/libc/dirent/lib_telldir.c @@ -0,0 +1,91 @@ +/**************************************************************************** + * libc/dirent/fs_telldir.c + * + * Copyright (C) 2007-2008, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include +#include + +#include +#include + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: telldir + * + * Description: + * The telldir() function returns the current location + * associated with the directory stream dirp. + * + * Inputs: + * dirp -- An instance of type DIR created by a previous + * call to opendir(); + * + * Return: + * On success, the telldir() function returns the current + * location in the directory stream. On error, -1 is + * returned, and errno is set appropriately. + * + * EBADF - Invalid directory stream descriptor dir + * + ****************************************************************************/ + +off_t telldir(FAR DIR *dirp) +{ + struct fs_dirent_s *idir = (struct fs_dirent_s *)dirp; + + if (!idir || !idir->fd_root) + { + set_errno(EBADF); + return (off_t)-1; + } + + /* Just return the current position */ + + return idir->fd_position; +} + diff --git a/nuttx/libc/fixedmath/Make.defs b/nuttx/libc/fixedmath/Make.defs new file mode 100644 index 000000000..b53df2b2c --- /dev/null +++ b/nuttx/libc/fixedmath/Make.defs @@ -0,0 +1,43 @@ +############################################################################ +# libc/fixedmath/Make.defs +# +# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# 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. +# +############################################################################ + +# Add the fixed precision math C files to the build + +CSRCS += lib_rint.c lib_fixedmath.c lib_b16sin.c lib_b16cos.c lib_b16atan2.c + +# Add the fixed precision math directory to the build + +DEPPATH += --dep-path fixedmath +VPATH += :fixedmath diff --git a/nuttx/libc/fixedmath/lib_b16atan2.c b/nuttx/libc/fixedmath/lib_b16atan2.c new file mode 100644 index 000000000..443ab7be3 --- /dev/null +++ b/nuttx/libc/fixedmath/lib_b16atan2.c @@ -0,0 +1,108 @@ +/**************************************************************************** + * libc/fixedmath/lib_b16atan2.c + * + * Copyright (C) 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define B16_C1 0x00000373 /* 0.013480470 */ +#define B16_C2 0x00000eb7 /* 0.057477314 */ +#define B16_C3 0x00001f0a /* 0.121239071 */ +#define B16_C4 0x00003215 /* 0.195635925 */ +#define B16_C5 0x0000553f /* 0.332994597 */ +#define B16_C6 0x00010000 /* 0.999995630 */ +#define B16_HALFPI 0x00019220 /* 1.570796327 */ +#define B16_PI 0x00032440 /* 3.141592654 */ + +#ifndef MAX +# define MAX(a,b) (a > b ? a : b) +#endif + +#ifndef MIN +# define MIN(a,b) (a < b ? a : b) +#endif + +#ifndef ABS +# define ABS(a) (a < 0 ? -a : a) +#endif + +/**************************************************************************** + * Global Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: b16atan2 + * + * Description: + * atan2 calculates the arctangent of y/x. (Based on a algorithm I saw + * posted on the internet... now I have lost the link -- sorry). + * + ****************************************************************************/ + +b16_t b16atan2(b16_t y, b16_t x) +{ + b16_t t0; + b16_t t1; + b16_t t2; + b16_t t3; + + t2 = ABS(x); + t1 = ABS(y); + t0 = MAX(t2, t1); + t1 = MIN(t2, t1); + t2 = ub16inv(t0); + t2 = b16mulb16(t1, t2); + + t3 = b16mulb16(t2, t2); + t0 = - B16_C1; + t0 = b16mulb16(t0, t3) + B16_C2; + t0 = b16mulb16(t0, t3) - B16_C3; + t0 = b16mulb16(t0, t3) + B16_C4; + t0 = b16mulb16(t0, t3) - B16_C5; + t0 = b16mulb16(t0, t3) + B16_C6; + t2 = b16mulb16(t0, t2); + + t2 = (ABS(y) > ABS(x)) ? B16_HALFPI - t2 : t2; + t2 = (x < 0) ? B16_PI - t2 : t2; + t2 = (y < 0) ? -t2 : t2; + + return t2; +} diff --git a/nuttx/libc/fixedmath/lib_b16cos.c b/nuttx/libc/fixedmath/lib_b16cos.c new file mode 100644 index 000000000..0ebe48262 --- /dev/null +++ b/nuttx/libc/fixedmath/lib_b16cos.c @@ -0,0 +1,64 @@ +/**************************************************************************** + * libc/fixedmath/lib_b16cos.c + * + * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Global Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: b16cos + ****************************************************************************/ + +b16_t b16cos(b16_t rad) +{ + /* Compute cosine: sin(rad + PI/2) = cos(rad) */ + + rad += b16HALFPI; + if (rad > b16PI) + { + rad -= b16TWOPI; + } + return b16sin(rad); +} diff --git a/nuttx/libc/fixedmath/lib_b16sin.c b/nuttx/libc/fixedmath/lib_b16sin.c new file mode 100644 index 000000000..9cd2f0da3 --- /dev/null +++ b/nuttx/libc/fixedmath/lib_b16sin.c @@ -0,0 +1,110 @@ +/**************************************************************************** + * libc/fixedmath/lib_b16sin.c + * + * Copyright (C) 2008, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define b16_P225 0x0000399a +#define b16_P405284735 0x000067c1 +#define b16_1P27323954 0x000145f3 + +/**************************************************************************** + * Global Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: b16sin + * Ref: http://lab.polygonal.de/2007/07/18/fast-and-accurate-sinecosine-approximation/ + ****************************************************************************/ + +b16_t b16sin(b16_t rad) +{ + b16_t tmp1; + b16_t tmp2; + b16_t tmp3; + + /* Force angle into the good range */ + + if (rad < -b16PI) + { + rad += b16TWOPI; + } + else if (rad > b16PI) + { + rad -= b16TWOPI; + } + + /* tmp1 = 1.27323954 * rad + * tmp2 = .405284735 * rad * rad + */ + + + tmp1 = b16mulb16(b16_1P27323954, rad); + tmp2 = b16mulb16(b16_P405284735, b16sqr(rad)); + + if (rad < 0) + { + /* tmp3 = 1.27323954 * rad + .405284735 * rad * rad */ + + tmp3 = tmp1 + tmp2; + } + else + { + /* tmp3 = 1.27323954 * rad - 0.405284735 * rad * rad */ + + tmp3 = tmp1 - tmp2; + } + + /* tmp1 = tmp3*tmp3 */ + + tmp1 = b16sqr(tmp3); + if (tmp3 < 0) + { + /* tmp1 = tmp3 * -tmp3 */ + + tmp1 = -tmp1; + } + + /* Return sin = .225 * (tmp3 * (+/-tmp3) - tmp3) + tmp3 */ + + return b16mulb16(b16_P225, (tmp1 - tmp3)) + tmp3; +} diff --git a/nuttx/libc/fixedmath/lib_fixedmath.c b/nuttx/libc/fixedmath/lib_fixedmath.c new file mode 100644 index 000000000..9e9213b4f --- /dev/null +++ b/nuttx/libc/fixedmath/lib_fixedmath.c @@ -0,0 +1,272 @@ +/**************************************************************************** + * libc/math/lib_fixedmath.c + * + * Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include +#include + +#ifndef CONFIG_HAVE_LONG_LONG + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Name: fixsign + ****************************************************************************/ + +static void fixsign(b16_t *parg1, b16_t *parg2, bool *pnegate) +{ + bool negate = false; + b16_t arg; + + arg = *parg1; + if (arg < 0) + { + *parg1 = -arg; + negate = true; + } + + arg = *parg2; + if (arg < 0) + { + *parg2 = -arg; + negate ^= true; + } + + *pnegate = negate; +} + +/**************************************************************************** + * Name: adjustsign + ****************************************************************************/ + +static b16_t adjustsign(b16_t result, bool negate) +{ + /* If the product is negative, then we overflowed */ + + if (result < 0) + { + if (result) + { + return b16MIN; + } + else + { + return b16MAX; + } + } + + /* correct the sign of the result */ + + if (negate) + { + return -result; + } + return result; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: b16mulb16 + ****************************************************************************/ + +b16_t b16mulb16(b16_t m1, b16_t m2) +{ + bool negate; + b16_t product; + + fixsign(&m1, &m2, &negate); + product = (b16_t)ub16mulub16((ub16_t)m1, (ub16_t)m2); + return adjustsign(product, negate); +} + +/**************************************************************************** + * Name: ub16mulub16 + **************************************************************************/ + +ub16_t ub16mulub16(ub16_t m1, ub16_t m2) +{ + /* Let: + * + * m1 = m1i*2**16 + m1f (b16) + * m2 = m2i*2**16 + m2f (b16) + * + * Then: + * + * m1*m2 = (m1i*m2i)*2**32 + (m1i*m2f + m2i*m1f)*2**16 + m1f*m2f (b32) + * = (m1i*m2i)*2**16 + (m1i*m2f + m2i*m1f) + m1f*m2f*2**-16 (b16) + * = a*2**16 + b + c*2**-16 + */ + + uint32_t m1i = ((uint32_t)m1 >> 16); + uint32_t m2i = ((uint32_t)m1 >> 16); + uint32_t m1f = ((uint32_t)m1 & 0x0000ffff); + uint32_t m2f = ((uint32_t)m2 & 0x0000ffff); + + return (m1i*m2i << 16) + m1i*m2f + m2i*m1f + (((m1f*m2f) + b16HALF) >> 16); +} + +/**************************************************************************** + * Name: b16sqr + **************************************************************************/ + +b16_t b16sqr(b16_t a) +{ + b16_t sq; + + /* The result is always positive. Just take the absolute value */ + + if (a < 0) + { + a = -a; + } + + /* Overflow occurred if the result is negative */ + + sq = (b16_t)ub16sqr(a); + if (sq < 0) + { + sq = b16MAX; + } + return sq; +} + +/**************************************************************************** + * Name: b16divb16 + **************************************************************************/ + +ub16_t ub16sqr(ub16_t a) +{ + /* Let: + * + * m = mi*2**16 + mf (b16) + * + * Then: + * + * m*m = (mi*mi)*2**32 + 2*(m1*m2)*2**16 + mf*mf (b32) + * = (mi*mi)*2**16 + 2*(mi*mf) + mf*mf*2**-16 (b16) + */ + + uint32_t mi = ((uint32_t)a >> 16); + uint32_t mf = ((uint32_t)a & 0x0000ffff); + + return (mi*mi << 16) + (mi*mf << 1) + ((mf*mf + b16HALF) >> 16); +} + +/**************************************************************************** + * Name: b16divb16 + **************************************************************************/ + +b16_t b16divb16(b16_t num, b16_t denom) +{ + bool negate; + b16_t quotient; + + fixsign(&num, &denom, &negate); + quotient = (b16_t)ub16divub16((ub16_t)num, (ub16_t)denom); + return adjustsign(quotient, negate); +} + +/**************************************************************************** + * Name: ub16divub16 + **************************************************************************/ + +ub16_t ub16divub16(ub16_t num, ub16_t denom) +{ + uint32_t term1; + uint32_t numf; + uint32_t product; + + /* Let: + * + * num = numi*2**16 + numf (b16) + * den = deni*2**16 + denf (b16) + * + * Then: + * + * num/den = numi*2**16 / den + numf / den (b0) + * = numi*2**32 / den + numf*2**16 /den (b16) + */ + + /* Check for overflow in the first part of the quotient */ + + term1 = ((uint32_t)num & 0xffff0000) / denom; + if (term1 >= 0x00010000) + { + return ub16MAX; /* Will overflow */ + } + + /* Finish the division */ + + numf = num - term1 * denom; + term1 <<= 16; + product = term1 + (numf + (denom >> 1)) / denom; + + /* Check for overflow */ + + if (product < term1) + { + return ub16MAX; /* Overflowed */ + } + return product; +} + +#endif diff --git a/nuttx/libc/fixedmath/lib_rint.c b/nuttx/libc/fixedmath/lib_rint.c new file mode 100644 index 000000000..a1212c970 --- /dev/null +++ b/nuttx/libc/fixedmath/lib_rint.c @@ -0,0 +1,135 @@ +/************************************************************ + * libc/fixedmath/lib_rint.c + * + * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ************************************************************/ + +/************************************************************ + * Compilation Switches + ************************************************************/ + +/************************************************************ + * Included Files + ************************************************************/ + +#include +#include +#include + +/************************************************************ + * Definitions + ************************************************************/ + +/************************************************************ + * Private Type Declarations + ************************************************************/ + +/************************************************************ + * Private Function Prototypes + ************************************************************/ + +/********************************************************** + * Global Constant Data + **********************************************************/ + +/************************************************************ + * Global Variables + ************************************************************/ + +/********************************************************** + * Private Constant Data + **********************************************************/ + +/************************************************************ + * Private Variables + ************************************************************/ + +double_t rint(double_t x) +{ + double_t ret; + + /* If the current rounding mode rounds toward negative + * infinity, rint() is identical to floor(). If the current + * rounding mode rounds toward positive infinity, rint() is + * identical to ceil(). + */ + +#if defined(CONFIG_FP_ROUND_POSITIVE) && CONFIG_FP_ROUNDING_POSITIVE != 0 + + ret = ceil(x); + +#elif defined(CONFIG_FP_ROUND_NEGATIVE) && CONFIG_FP_ROUNDING_NEGATIVE != 0 + + ret = floor(x); + +#else + + /* In the default rounding mode (round to nearest), rint(x) is the + * integer nearest x with the additional stipulation that if + * |rint(x)-x|=1/2, then rint(x) is even. + */ + + long dwinteger = (long)x; + double_t fremainder = x - (double_t)dwinteger; + + if (x < 0.0) + { + /* fremainder should be in range 0 .. -1 */ + + if (fremainder == -0.5) + { + dwinteger = ((dwinteger+1)&~1); + } + else if (fremainder < -0.5) + { + dwinteger--; + } + } + else + { + /* fremainder should be in range 0 .. 1 */ + + if (fremainder == 0.5) + { + dwinteger = ((dwinteger+1)&~1); + } + else if (fremainder > 0.5) + { + dwinteger++; + } + } + + ret = (double_t)dwinteger; +#endif + + return ret; +} diff --git a/nuttx/libc/lib.csv b/nuttx/libc/lib.csv new file mode 100644 index 000000000..171f64e9b --- /dev/null +++ b/nuttx/libc/lib.csv @@ -0,0 +1,171 @@ +"_inet_ntoa","arpa/inet.h","!defined(CONFIG_NET_IPv6) && !defined(CONFIG_CAN_PASS_STRUCTS)","FAR char","in_addr_t" +"abort","stdlib.h","","void" +"abs","stdlib.h","","int","int" +"asprintf","stdio.h","","int","FAR char **","const char *","..." +"avsprintf","stdio.h","","int","FAR char **","const char *","va_list" +"b16atan2","fixedmath.h","","b16_t","b16_t","b16_t" +"b16cos","fixedmath.h","","b16_t","b16_t" +"b16divb16","fixedmath.h","","b16_t","b16_t","b16_t" +"b16mulb16","fixedmath.h","","b16_t","b16_t","b16_t" +"b16sin","fixedmath.h","","b16_t","b16_t" +"b16sqr","fixedmath.h","","b16_t","b16_t" +"basename","libgen.h","","FAR char","FAR char *" +"cfgetspeed","termios.h","CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_SERIAL_TERMIOS)","speed_t","FAR const struct termios *" +"cfsetspeed","termios.h","CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_SERIAL_TERMIOS)","int","FAR struct termios *","speed_t" +"chdir","unistd.h","CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_ENVIRON)","int","FAR const char *" +"crc32","crc32.h","","uint32_t","FAR const uint8_t *","size_t" +"crc32part","crc32.h","","uint32_t","FAR const uint8_t *","size_t","uint32_t" +"dbg","debug.h","!defined(CONFIG_CPP_HAVE_VARARGS) && defined(CONFIG_DEBUG)","int","const char *","..." +"dbg_enable","debug.h","defined(CONFIG_DEBUG_ENABLE)","void","bool" +"dirname","libgen.h","","FAR char","FAR char *" +"dq_addafter","queue.h","","void","FAR dq_entry_t *","FAR dq_entry_t *","FAR dq_queue_t *" +"dq_addbefore","queue.h","","void","FAR dq_entry_t *","FAR dq_entry_t *","FAR dq_queue_t *" +"dq_addfirst","queue.h","","void","FAR dq_entry_t *","dq_queue_t *" +"dq_addlast","queue.h","","void","FAR dq_entry_t *","dq_queue_t *" +"dq_rem","queue.h","","void","FAR dq_entry_t *","dq_queue_t *" +"dq_remfirst","queue.h","","FAR dq_entry_t","dq_queue_t *" +"dq_remlast","queue.h","","FAR dq_entry_t","dq_queue_t *" +"ether_ntoa","netinet/ether.h","","FAR char","FAR const struct ether_addr *" +"fclose","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","FAR FILE *" +"fdopen","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","FAR FILE","int","FAR const char *" +"fflush","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","FAR FILE *" +"fgetc","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","FAR FILE *" +"fgetpos","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","FAR FILE *","FAR fpos_t *" +"fgets","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","FAR char","FAR char *","int","FAR FILE *" +"fileno","stdio.h","","int","FAR FILE *" +"fopen","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","FAR FILE","FAR const char *","FAR const char *" +"fprintf","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","FAR FILE *","FAR const char *","..." +"fputc","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","int c","FAR FILE *" +"fputs","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","FAR const char *","FAR FILE *" +"fread","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","size_t","FAR void *","size_t","size_t","FAR FILE *" +"fseek","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","FAR FILE *","long int","int" +"fsetpos","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","FAR FILE *","FAR fpos_t *" +"ftell","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","long","FAR FILE *" +"fwrite","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","size_t","FAR const void *","size_t","size_t","FAR FILE *" +"getcwd","unistd.h","CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_ENVIRON)","FAR char","FAR char *","size_t" +"getopt","unistd.h","","int","int","FAR char *const[]","FAR const char *" +"getoptargp","unistd.h","","FAR char *" +"getoptindp","unistd.h","","int" +"getoptoptp","unistd.h","","int" +"gets","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","FAR char","FAR char *" +"gmtime","time.h","","struct tm","const time_t *" +"gmtime_r","time.h","","FAR struct tm","FAR const time_t *","FAR struct tm *" +"htonl","arpa/inet.h","","uint32_t","uint32_t" +"htons","arpa/inet.h","","uint16_t","uint16_t" +"imaxabs","stdlib.h","","intmax_t","intmax_t" +"inet_addr","arpa/inet.h","","in_addr_t","FAR const char " +"inet_ntoa","arpa/inet.h","!defined(CONFIG_NET_IPv6) && defined(CONFIG_CAN_PASS_STRUCTS)","FAR char","struct in_addr" +"inet_ntop","arpa/inet.h","","FAR const char","int","FAR const void *","FAR char *","socklen_t" +"inet_pton","arpa/inet.h","","int","int","FAR const char *","FAR void *" +"labs","stdlib.h","","long int","long int" +"lib_dumpbuffer","debug.h","","void","FAR const char *","FAR const uint8_t *","unsigned int" +"lib_lowprintf","debug.h","","int","FAR const char *","..." +"lib_rawprintf","debug.h","","int","FAR const char *","..." +"llabs","stdlib.h","defined(CONFIG_HAVE_LONG_LONG)","long long int","long long int" +"lldbg","debug.h","!defined(CONFIG_CPP_HAVE_VARARGS) && defined(CONFIG_DEBUG) && defined(CONFIG_ARCH_LOWPUTC)","int","const char *","..." +"llvdbg","debug.h","!defined(CONFIG_CPP_HAVE_VARARGS) && defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_VERBOSE) && defined(CONFIG_ARCH_LOWPUTC)","int","const char *","..." +"match","","","int","const char *","const char *" +"memccpy","string.h","","FAR void","FAR void *","FAR const void *","int c","size_t" +"memchr","string.h","","FAR void","FAR const void *","int c","size_t" +"memcmp","string.h","","int","FAR const void *","FAR const void *","size_t" +"memcpy","string.h","","FAR void","FAR void *","FAR const void *","size_t" +"memmove","string.h","","FAR void","FAR void *","FAR const void *","size_t" +"memset","string.h","","FAR void","FAR void *","int c","size_t" +"mktime","time.h","","time_t","const struct tm *" +"mq_getattr","mqueue.h","!defined(CONFIG_DISABLE_MQUEUE)","int","mqd_t","struct mq_attr *" +"mq_setattr","mqueue.h","!defined(CONFIG_DISABLE_MQUEUE)","int","mqd_t","const struct mq_attr *","struct mq_attr *" +"ntohl","arpa/inet.h","","uint32_t","uint32_t" +"ntohs","arpa/inet.h","","uint16_t","uint16_t" +"perror","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","void","FAR const char *" +"printf","stdio.h","","int","const char *","..." +"pthread_attr_destroy","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_attr_t *" +"pthread_attr_getinheritsched","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR const pthread_attr_t *","FAR int *" +"pthread_attr_getschedparam","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_attr_t *","FAR struct sched_param *" +"pthread_attr_getschedpolicy","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_attr_t *","int *" +"pthread_attr_getstacksize","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_attr_t *","FAR long *" +"pthread_attr_init","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_attr_t *" +"pthread_attr_setinheritsched","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_attr_t *","int" +"pthread_attr_setschedparam","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_attr_t *","FAR const struct sched_param *" +"pthread_attr_setschedpolicy","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_attr_t *","int" +"pthread_attr_setstacksize","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_attr_t *","long" +"pthread_barrierattr_destroy","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_barrierattr_t *" +"pthread_barrierattr_getpshared","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR const pthread_barrierattr_t *","FAR int *" +"pthread_barrierattr_init","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_barrierattr_t *" +"pthread_barrierattr_setpshared","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_barrierattr_t *","int" +"pthread_condattr_destroy","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_condattr_t *" +"pthread_condattr_init","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_condattr_t *" +"pthread_mutexattr_destroy","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_mutexattr_t *" +"pthread_mutexattr_getpshared","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_mutexattr_t *","FAR int *" +"pthread_mutexattr_gettype","pthread.h","!defined(CONFIG_DISABLE_PTHREAD) && defined(CONFIG_MUTEX_TYPES)","int","const pthread_mutexattr_t *","int *" +"pthread_mutexattr_init","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_mutexattr_t *" +"pthread_mutexattr_setpshared","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_mutexattr_t *","int " +"pthread_mutexattr_settype","pthread.h","!defined(CONFIG_DISABLE_PTHREAD) && defined(CONFIG_MUTEX_TYPES)","int","pthread_mutexattr_t *","int" +"puts","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","FAR const char *" +"qsort","stdlib.h","","void","void *","size_t","size_t","int(*)(const void *","const void *)" +"rand","stdlib.h","","int" +"readdir_r","dirent.h","CONFIG_NFILE_DESCRIPTORS > 0","int","FAR DIR *","FAR struct dirent *","FAR struct dirent **" +"rint","","","double_t","double_t" +"sched_get_priority_max","sched.h","","int","int" +"sched_get_priority_min","sched.h","","int","int" +"sem_getvalue","semaphore.h","","int","FAR sem_t *","FAR int *" +"sem_init","semaphore.h","","int","FAR sem_t *","int","unsigned int" +"sendfile","sys/sendfile.h","CONFIG_NSOCKET_DESCRIPTORS > 0 || CONFIG_NFILE_DESCRIPTORS > 0","ssize_t","int","int","off_t","size_t" +"sigaddset","signal.h","!defined(CONFIG_DISABLE_SIGNALS)","int","FAR sigset_t *","int" +"sigdelset","signal.h","!defined(CONFIG_DISABLE_SIGNALS)","int","FAR sigset_t *","int" +"sigemptyset","signal.h","!defined(CONFIG_DISABLE_SIGNALS)","int","FAR sigset_t *" +"sigfillset","signal.h","!defined(CONFIG_DISABLE_SIGNALS)","int","FAR sigset_t *" +"sigismember","signal.h","!defined(CONFIG_DISABLE_SIGNALS)","int","FAR const sigset_t *","int" +"snprintf","stdio.h","","int","FAR char *","size_t","const char *","..." +"sprintf","stdio.h","","int","FAR char *","const char *","..." +"sq_addafter","queue.h","","void","FAR sq_entry_t *","FAR sq_entry_t *","FAR sq_queue_t *" +"sq_addfirst","queue.h","","void","FAR sq_entry_t *","sq_queue_t *" +"sq_addlast","queue.h","","void","FAR sq_entry_t *","sq_queue_t *" +"sq_rem","queue.h","","void","FAR sq_entry_t *","sq_queue_t *" +"sq_remafter","queue.h","","FAR sq_entry_t","FAR sq_entry_t *","sq_queue_t *" +"sq_remfirst","queue.h","","FAR sq_entry_t","sq_queue_t *" +"sq_remlast","queue.h","","FAR sq_entry_t","sq_queue_t *" +"srand","stdlib.h","","void","unsigned int" +"sscanf","stdio.h","","int","const char *","const char *","..." +"strcasecmp","string.h","","int","FAR const char *","FAR const char *" +"strcasestr","string.h","","FAR char","FAR const char *","FAR const char *" +"strcat","string.h","","FAR char","FAR char *","FAR const char *" +"strchr","string.h","","FAR char","FAR const char *","int" +"strcmp","string.h","","int","FAR const char *","FAR const char *" +"strcpy","string.h","","FAR char","char *","FAR const char *" +"strcspn","string.h","","size_t","FAR const char *","FAR const char *" +"strdup","string.h","","FAR char","FAR const char *" +"strerror","string.h","","FAR const char","int" +"strftime","time.h","","size_t","char *","size_t","const char *","const struct tm *" +"strlen","string.h","","size_t","FAR const char *" +"strncasecmp","string.h","","int","FAR const char *","FAR const char *","size_t" +"strncat","string.h","","FAR char","FAR char *","FAR const char *","size_t" +"strncmp","string.h","","int","FAR const char *","FAR const char *","size_t" +"strncpy","string.h","","FAR char","char *","FAR const char *","size_t" +"strndup","string.h","","FAR char","FAR const char *","size_t" +"strnlen","string.h","","size_t","FAR const char *","size_t" +"strpbrk","string.h","","FAR char","FAR const char *","FAR const char *" +"strrchr","string.h","","FAR char","FAR const char *","int" +"strspn","string.h","","size_t","FAR const char *","FAR const char *" +"strstr","string.h","","FAR char","FAR const char *","FAR const char *" +"strtod","stdlib.h","","double_t","const char *str","char **endptr" +"strtok","string.h","","FAR char","FAR char *","FAR const char *" +"strtok_r","string.h","","FAR char","FAR char *","FAR const char *","FAR char **" +"strtol","string.h","","long","const char *","char **","int" +"strtoll","stdlib.h","defined(CONFIG_HAVE_LONG_LONG)","long long","const char *nptr","char **endptr","int base" +"strtoul","stdlib.h","","unsigned long","const char *","char **","int" +"strtoull","stdlib.h","defined(CONFIG_HAVE_LONG_LONG)","unsigned long long","const char *","char **","int" +"tcflush","termios.h","CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_SERIAL_TERMIOS)","int","int","int" +"tcgetattr","termios.h","CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_SERIAL_TERMIOS)","int","int","FAR struct termios *" +"tcsetattr","termios.h","CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_SERIAL_TERMIOS)","int","int","int","FAR const struct termios *" +"telldir","dirent.h","CONFIG_NFILE_DESCRIPTORS > 0","off_t","FAR DIR *" +"time","time.h","","time_t","time_t *" +"ub16divub16","fixedmath.h","","ub16_t","ub16_t","ub16_t" +"ub16mulub16","fixedmath.h","","ub16_t","ub16_t","ub16_t" +"ub16sqr","fixedmath.h","","ub16_t","ub16_t" +"ungetc","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","int","FAR FILE *" +"vdbg","debug.h","!defined(CONFIG_CPP_HAVE_VARARGS) && defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_VERBOSE)","int","const char *","..." +"vfprintf","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","FAR FILE *","const char *","va_list" +"vprintf","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","FAR const char *","va_list" +"vsnprintf","stdio.h","","int","FAR char *","size_t","const char *","va_list" +"vsprintf","stdio.h","","int","FAR char *","const char *","va_list" +"vsscanf","stdio.h","","int","char *","const char *","va_list" diff --git a/nuttx/libc/lib_internal.h b/nuttx/libc/lib_internal.h new file mode 100644 index 000000000..c09c751d4 --- /dev/null +++ b/nuttx/libc/lib_internal.h @@ -0,0 +1,211 @@ +/**************************************************************************** + * libc/lib_internal.h + * + * Copyright (C) 2007-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 __LIB_LIB_INTERNAL_H +#define __LIB_LIB_INTERNAL_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include + +#include + +/**************************************************************************** + * Definitions + ****************************************************************************/ +/* This configuration directory is used in environment variable processing + * when we need to reference the user's home directory. There are no user + * directories in NuttX so, by default, this always refers to the root + * directory. + */ + +#ifndef CONFIG_LIB_HOMEDIR +# define CONFIG_LIB_HOMEDIR "/" +#endif + +/* If C std I/O buffering is not supported, then we don't need its semaphore + * protection. + */ + +#if CONFIG_STDIO_BUFFER_SIZE <= 0 +# define lib_sem_initialize(s) +# define lib_take_semaphore(s) +# define lib_give_semaphore(s) +#endif + +/* The NuttX C library an be build in two modes: (1) as a standard, C-libary + * that can be used by normal, user-space applications, or (2) as a special, + * kernel-mode C-library only used within the OS. If NuttX is not being + * built as separated kernel- and user-space modules, then only the first + * mode is supported. + */ + +#if defined(CONFIG_NUTTX_KERNEL) && defined(__KERNEL__) +# include +# define lib_malloc(s) kmalloc(s) +# define lib_zalloc(s) kzalloc(s) +# define lib_realloc(p,s) krealloc(p,s) +# define lib_free(p) kfree(p) +#else +# include +# define lib_malloc(s) malloc(s) +# define lib_zalloc(s) zalloc(s) +# define lib_realloc(p,s) realloc(p,s) +# define lib_free(p) free(p) +#endif + +#define LIB_BUFLEN_UNKNOWN INT_MAX + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/**************************************************************************** + * Public Variables + ****************************************************************************/ + +/* Debug output is initially disabled */ + +#ifdef CONFIG_DEBUG_ENABLE +extern bool g_dbgenable; +#endif + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/* Defined in lib_streamsem.c */ + +#if CONFIG_NFILE_STREAMS > 0 +void stream_semtake(FAR struct streamlist *list); +void stream_semgive(FAR struct streamlist *list); +#endif + +/* Defined in lib_libnoflush.c */ + +#ifdef CONFIG_STDIO_LINEBUFFER +int lib_noflush(FAR struct lib_outstream_s *this); +#endif + +/* Defined in lib_libsprintf.c */ + +int lib_sprintf(FAR struct lib_outstream_s *obj, + const char *fmt, ...); + +/* Defined lib_libvsprintf.c */ + +int lib_vsprintf(FAR struct lib_outstream_s *obj, + FAR const char *src, va_list ap); + +/* Defined lib_rawprintf.c */ + +int lib_rawvprintf(const char *src, va_list ap); + +/* Defined lib_lowprintf.c */ + +int lib_lowvprintf(const char *src, va_list ap); + +/* Defined in lib_dtoa.c */ + +#ifdef CONFIG_LIBC_FLOATINGPOINT +char *__dtoa(double d, int mode, int ndigits, int *decpt, int *sign, + char **rve); +#endif + +/* Defined in lib_libwrite.c */ + +ssize_t lib_fwrite(FAR const void *ptr, size_t count, FAR FILE *stream); + +/* Defined in lib_libfread.c */ + +ssize_t lib_fread(FAR void *ptr, size_t count, FAR FILE *stream); + +/* Defined in lib_libfflush.c */ + +ssize_t lib_fflush(FAR FILE *stream, bool bforce); + +/* Defined in lib_rdflush.c */ + +int lib_rdflush(FAR FILE *stream); + +/* Defined in lib_wrflush.c */ + +int lib_wrflush(FAR FILE *stream); + +/* Defined in lib_sem.c */ + +#if CONFIG_STDIO_BUFFER_SIZE > 0 +void lib_sem_initialize(FAR struct file_struct *stream); +void lib_take_semaphore(FAR struct file_struct *stream); +void lib_give_semaphore(FAR struct file_struct *stream); +#endif + +/* Defined in lib_libgetbase.c */ + +int lib_getbase(const char *nptr, const char **endptr); + +/* Defined in lib_skipspace.c */ + +void lib_skipspace(const char **pptr); + +/* Defined in lib_isbasedigit.c */ + +bool lib_isbasedigit(int ch, int base, int *value); + +/* Defined in lib_checkbase.c */ + +int lib_checkbase(int base, const char **pptr); + +/* Defined in lib_expi.c */ + +#ifdef CONFIG_LIBM +double lib_expi(size_t n); +#endif + +/* Defined in lib_libsqrtapprox.c */ + +#ifdef CONFIG_LIBM +float lib_sqrtapprox(float x); +#endif + +#endif /* __LIB_LIB_INTERNAL_H */ diff --git a/nuttx/libc/libgen/Make.defs b/nuttx/libc/libgen/Make.defs new file mode 100644 index 000000000..6e786655d --- /dev/null +++ b/nuttx/libc/libgen/Make.defs @@ -0,0 +1,43 @@ +############################################################################ +# libc/libgen/Make.defs +# +# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# 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. +# +############################################################################ + +# Add the libgen C files to the build + +CSRCS += lib_basename.c lib_dirname.c + +# Add the libgen directory to the build + +DEPPATH += --dep-path libgen +VPATH += :libgen diff --git a/nuttx/libc/libgen/lib_basename.c b/nuttx/libc/libgen/lib_basename.c new file mode 100644 index 000000000..68188edbf --- /dev/null +++ b/nuttx/libc/libgen/lib_basename.c @@ -0,0 +1,131 @@ +/**************************************************************************** + * libc/libgen/lib_basename.c + * + * Copyright (C) 2007, 2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static char g_retchar[2]; + +/**************************************************************************** + * Global Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: basename + * + * Description: + * basename() extracts the filename component from a null-terminated + * pathname string. In the usual case, basename() returns the component + * following the final '/'. Trailing '/' characters are not counted as + * part of the pathname. + * + * If path does not contain a slash, basename() returns a copy of path. + * If path is the string "/", then basename() returns the string "/". If + * path is a NULL pointer or points to an empty string, then basename() + * return the string ".". + * + * basename() may modify the contents of path, so copies should be passed. + * basename() may return pointers to statically allocated memory which may + * be overwritten by subsequent calls. + * + * Parameter: + * path The null-terminated string referring to the path to be decomposed + * + * Return: + * On success the filename component of the path is returned. + * + ****************************************************************************/ + +FAR char *basename(FAR char *path) +{ + char *p; + int len; + int ch; + + /* Handle some corner cases */ + + if (!path || *path == '\0') + { + ch = '.'; + goto out_retchar; + } + + /* Check for trailing slash characters */ + + len = strlen(path); + while (path[len-1] == '/') + { + /* Remove trailing '/' UNLESS this would make a zero length string */ + if (len > 1) + { + path[len-1] = '\0'; + len--; + } + else + { + ch = '/'; + goto out_retchar; + } + } + + /* Get the address of the last '/' which is not at the end of the path and, + * therefor, must be just before the beginning of the filename component. + */ + + p = strrchr(path, '/'); + if (p) + { + return p + 1; + } + + /* There is no '/' in the path */ + + return path; + +out_retchar: + g_retchar[0] = ch; + g_retchar[1] = '\0'; + return g_retchar; +} diff --git a/nuttx/libc/libgen/lib_dirname.c b/nuttx/libc/libgen/lib_dirname.c new file mode 100644 index 000000000..6d076fd61 --- /dev/null +++ b/nuttx/libc/libgen/lib_dirname.c @@ -0,0 +1,144 @@ +/**************************************************************************** + * libc/libgen/lib_dirname.c + * + * Copyright (C) 2007, 2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static char g_retchar[2]; + +/**************************************************************************** + * Global Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: dirname + * + * Description: + * dirname() extracts the directory component from a null-terminated + * pathname string. In the usual case, dirname() returns the string up + * to, but not including, the final '/'. Trailing '/' characters are not + * counted as part of the pathname. + * + * If path does not contain a slash, dirname() returns the string ".". If + * path is the string "/", then dirname() returns the string "/". If path + * is a NULL pointer or points to an empty string, then dirname() returns + * the string ".". + * + * dirname() may modify the contents of path, so copies should be passed. + * dirname() may return pointers to statically allocated memory which may + * be overwritten by subsequent calls. + * + * Parameter: + * path The null-terminated string referring to the path to be decomposed + * + * Return: + * On success the directory component of the path is returned. + * + ****************************************************************************/ + +FAR char *dirname(FAR char *path) +{ + char *p; + int len; + int ch; + + /* Handle some corner cases */ + + if (!path || *path == '\0') + { + ch = '.'; + goto out_retchar; + } + + /* Check for trailing slash characters */ + + len = strlen(path); + while (path[len-1] == '/') + { + /* Remove trailing '/' UNLESS this would make a zero length string */ + if (len > 1) + { + path[len-1] = '\0'; + len--; + } + else + { + ch = '/'; + goto out_retchar; + } + } + + /* Get the address of the last '/' which is not at the end of the path and, + * therefor, must be the end of the directory component. + */ + + p = strrchr(path, '/'); + if (p) + { + /* Handle the case where the only '/' in the string is the at the beginning + * of the path. + */ + + if (p == path) + { + ch = '/'; + goto out_retchar; + } + + /* No, the directory component is the substring before the '/'. */ + + *p = '\0'; + return path; + } + + /* There is no '/' in the path */ + + ch = '.'; + +out_retchar: + g_retchar[0] = ch; + g_retchar[1] = '\0'; + return g_retchar; +} diff --git a/nuttx/libc/math/Kconfig b/nuttx/libc/math/Kconfig new file mode 100644 index 000000000..c24bfd53f --- /dev/null +++ b/nuttx/libc/math/Kconfig @@ -0,0 +1,26 @@ +# +# For a description of the syntax of this configuration file, +# see misc/tools/kconfig-language.txt. +# + +config LIBM + bool "Math library" + default n + depends on !ARCH_MATH_H + ---help--- + By default, no math library will be provided by NuttX. In this this case, it + is assumed that (1) no math library is required, or (2) you will be using the + math.h header file and the libm library provided by your toolchain. + + This is may be a very good choice is possible because your toolchain may have + have a highly optimized version of libm. + + Another possibility is that you have a custom, architecture-specific math + libary and that the corresponding math.h file resides at arch//include/math.h. + The option is selected via ARCH_MATH_H. If ARCH_MATH_H is selected,then the include/nuttx/math.h + header file will be copied to include/math.h where it can be used by your applications. + + If ARCH_MATH_H is not defined, then this option can be selected to build a generic, + math library built into NuttX. This math library comes from the Rhombus OS and + was written by Nick Johnson. The Rhombus OS math library port was contributed by + Darcy Gong. diff --git a/nuttx/libc/math/lib_acos.c b/nuttx/libc/math/lib_acos.c new file mode 100644 index 000000000..147003237 --- /dev/null +++ b/nuttx/libc/math/lib_acos.c @@ -0,0 +1,46 @@ +/************************************************************************ + * libc/math/lib_acos.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009, 2010 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include +#include + +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +#ifdef CONFIG_HAVE_DOUBLE +double acos(double x) +{ + return (M_PI_2 - asin(x)); +} +#endif diff --git a/nuttx/libc/math/lib_acosf.c b/nuttx/libc/math/lib_acosf.c new file mode 100644 index 000000000..447b2767f --- /dev/null +++ b/nuttx/libc/math/lib_acosf.c @@ -0,0 +1,41 @@ +/************************************************************************ + * libc/math/lib_acosf.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009, 2010 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +float acosf(float x) +{ + return (M_PI_2 - asinf(x)); +} diff --git a/nuttx/libc/math/lib_acosl.c b/nuttx/libc/math/lib_acosl.c new file mode 100644 index 000000000..a0f226238 --- /dev/null +++ b/nuttx/libc/math/lib_acosl.c @@ -0,0 +1,46 @@ +/************************************************************************ + * libc/math/lib_acos.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009, 2010 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include +#include + +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +#ifdef CONFIG_HAVE_LONG_DOUBLE +long double acosl(long double x) +{ + return (M_PI_2 - asinl(x)); +} +#endif diff --git a/nuttx/libc/math/lib_asin.c b/nuttx/libc/math/lib_asin.c new file mode 100644 index 000000000..d9941a7e5 --- /dev/null +++ b/nuttx/libc/math/lib_asin.c @@ -0,0 +1,69 @@ +/************************************************************************ + * libc/math/lib_sin.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009-2011 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include +#include + +#include +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +#ifdef CONFIG_HAVE_DOUBLE +double asin(double x) +{ + long double y, y_sin, y_cos; + + y = 0; + + while (1) + { + y_sin = sin(y); + y_cos = cos(y); + + if (y > M_PI_2 || y < -M_PI_2) + { + y = fmod(y, M_PI); + } + + if (y_sin + DBL_EPSILON >= x && y_sin - DBL_EPSILON <= x) + { + break; + } + + y = y - (y_sin - x) / y_cos; + } + + return y; +} +#endif diff --git a/nuttx/libc/math/lib_asinf.c b/nuttx/libc/math/lib_asinf.c new file mode 100644 index 000000000..57e518acb --- /dev/null +++ b/nuttx/libc/math/lib_asinf.c @@ -0,0 +1,65 @@ +/************************************************************************ + * libc/math/lib_sinf.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009-2011 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +float asinf(float x) +{ + long double y, y_sin, y_cos; + + y = 0; + + while (1) + { + y_sin = sinf(y); + y_cos = cosf(y); + + if (y > M_PI_2 || y < -M_PI_2) + { + y = fmodf(y, M_PI); + } + + if (y_sin + FLT_EPSILON >= x && y_sin - FLT_EPSILON <= x) + { + break; + } + + y = y - (y_sin - x) / y_cos; + } + + return y; +} + diff --git a/nuttx/libc/math/lib_asinl.c b/nuttx/libc/math/lib_asinl.c new file mode 100644 index 000000000..19f284e53 --- /dev/null +++ b/nuttx/libc/math/lib_asinl.c @@ -0,0 +1,69 @@ +/************************************************************************ + * libc/math/lib_sinl.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009-2011 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include +#include + +#include +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +#ifdef CONFIG_HAVE_LONG_DOUBLE +long double asinl(long double x) +{ + long double y, y_sin, y_cos; + + y = 0; + + while (1) + { + y_sin = sinl(y); + y_cos = cosl(y); + + if (y > M_PI_2 || y < -M_PI_2) + { + y = fmodl(y, M_PI); + } + + if (y_sin + LDBL_EPSILON >= x && y_sin - LDBL_EPSILON <= x) + { + break; + } + + y = y - (y_sin - x) / y_cos; + } + + return y; +} +#endif diff --git a/nuttx/libc/math/lib_atan.c b/nuttx/libc/math/lib_atan.c new file mode 100644 index 000000000..44d68ece2 --- /dev/null +++ b/nuttx/libc/math/lib_atan.c @@ -0,0 +1,48 @@ +/************************************************************************ + * libc/math/lib_atan.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009, 2010 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include +#include + +#include +#include +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +#ifdef CONFIG_HAVE_DOUBLE +double atan(double x) +{ + return asin(x / sqrt(x * x + 1)); +} +#endif diff --git a/nuttx/libc/math/lib_atan2.c b/nuttx/libc/math/lib_atan2.c new file mode 100644 index 000000000..6d7d2ad48 --- /dev/null +++ b/nuttx/libc/math/lib_atan2.c @@ -0,0 +1,86 @@ +/************************************************************************ + * libc/math/lib_atan2.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009-2011 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include +#include + +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +#ifdef CONFIG_HAVE_DOUBLE +double atan2(double y, double x) +{ + if (y == 0.0) + { + if (x >= 0.0) + { + return 0.0; + } + else + { + return M_PI; + } + } + else if (y > 0.0) + { + if (x == 0.0) + { + return M_PI_2; + } + else if (x > 0.0) + { + return atan(y / x); + } + else + { + return M_PI - atan(y / x); + } + } + else + { + if (x == 0.0) + { + return M_PI + M_PI_2; + } + else if (x > 0.0) + { + return 2 * M_PI - atan(y / x); + } + else + { + return M_PI + atan(y / x); + } + } +} +#endif diff --git a/nuttx/libc/math/lib_atan2f.c b/nuttx/libc/math/lib_atan2f.c new file mode 100644 index 000000000..7ff9af130 --- /dev/null +++ b/nuttx/libc/math/lib_atan2f.c @@ -0,0 +1,81 @@ +/************************************************************************ + * libc/math/lib_atan2f.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009-2011 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +float atan2f(float y, float x) +{ + if (y == 0.0) + { + if (x >= 0.0) + { + return 0.0; + } + else + { + return M_PI; + } + } + else if (y > 0.0) + { + if (x == 0.0) + { + return M_PI_2; + } + else if (x > 0.0) + { + return atanf(y / x); + } + else + { + return M_PI - atanf(y / x); + } + } + else + { + if (x == 0.0) + { + return M_PI + M_PI_2; + } + else if (x > 0.0) + { + return 2 * M_PI - atanf(y / x); + } + else + { + return M_PI + atanf(y / x); + } + } +} diff --git a/nuttx/libc/math/lib_atan2l.c b/nuttx/libc/math/lib_atan2l.c new file mode 100644 index 000000000..48bfd06f3 --- /dev/null +++ b/nuttx/libc/math/lib_atan2l.c @@ -0,0 +1,87 @@ +/************************************************************************ + * libc/math/lib_atan2l.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009-2011 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include +#include + +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +#ifdef CONFIG_HAVE_LONG_DOUBLE +long double atan2l(long double y, long double x) +{ + + if (y == 0.0) + { + if (x >= 0.0) + { + return 0.0; + } + else + { + return M_PI; + } + } + else if (y > 0.0) + { + if (x == 0.0) + { + return M_PI_2; + } + else if (x > 0.0) + { + return atanl(y / x); + } + else + { + return M_PI - atanl(y / x); + } + } + else + { + if (x == 0.0) + { + return M_PI + M_PI_2; + } + else if (x > 0.0) + { + return 2 * M_PI - atanl(y / x); + } + else + { + return M_PI + atanl(y / x); + } + } +} +#endif diff --git a/nuttx/libc/math/lib_atanf.c b/nuttx/libc/math/lib_atanf.c new file mode 100644 index 000000000..a84605787 --- /dev/null +++ b/nuttx/libc/math/lib_atanf.c @@ -0,0 +1,43 @@ +/************************************************************************ + * libc/math/lib_atanf.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009, 2010 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include +#include +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +float atanf(float x) +{ + return asinf(x / sqrtf(x * x + 1)); +} diff --git a/nuttx/libc/math/lib_atanl.c b/nuttx/libc/math/lib_atanl.c new file mode 100644 index 000000000..752d49307 --- /dev/null +++ b/nuttx/libc/math/lib_atanl.c @@ -0,0 +1,48 @@ +/************************************************************************ + * libc/math/lib_atanl.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009, 2010 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include +#include + +#include +#include +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +#ifdef CONFIG_HAVE_LONG_DOUBLE +long double atanl(long double x) +{ + return asinl(x / sqrtl(x * x + 1)); +} +#endif diff --git a/nuttx/libc/math/lib_ceil.c b/nuttx/libc/math/lib_ceil.c new file mode 100644 index 000000000..3c6678dc1 --- /dev/null +++ b/nuttx/libc/math/lib_ceil.c @@ -0,0 +1,52 @@ +/************************************************************************ + * libc/math/lib_ceil.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009-2011 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include +#include + +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +#ifdef CONFIG_HAVE_DOUBLE +double ceil(double x) +{ + modf(x, &x); + if (x > 0.0) + { + x += 1.0; + } + + return x; +} +#endif diff --git a/nuttx/libc/math/lib_ceilf.c b/nuttx/libc/math/lib_ceilf.c new file mode 100644 index 000000000..afbe2cf13 --- /dev/null +++ b/nuttx/libc/math/lib_ceilf.c @@ -0,0 +1,47 @@ +/************************************************************************ + * libc/math/lib_ceilf.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009-2011 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +float ceilf(float x) +{ + modff(x, &x); + if (x > 0.0) + { + x += 1.0; + } + + return x; +} diff --git a/nuttx/libc/math/lib_ceill.c b/nuttx/libc/math/lib_ceill.c new file mode 100644 index 000000000..757016b53 --- /dev/null +++ b/nuttx/libc/math/lib_ceill.c @@ -0,0 +1,52 @@ +/************************************************************************ + * libc/math/lib_ceil;.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009-2011 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include +#include + +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +#ifdef CONFIG_HAVE_LONG_DOUBLE +long double ceill(long double x) +{ + modfl(x, &x); + if (x > 0.0) + { + x += 1.0; + } + + return x; +} +#endif diff --git a/nuttx/libc/math/lib_cos.c b/nuttx/libc/math/lib_cos.c new file mode 100644 index 000000000..4b4e1a20b --- /dev/null +++ b/nuttx/libc/math/lib_cos.c @@ -0,0 +1,46 @@ +/************************************************************************ + * libc/math/lib_cos.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009-2011 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include +#include + +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +#ifdef CONFIG_HAVE_DOUBLE +double cos(double x) +{ + return sin(x + M_PI_2); +} +#endif diff --git a/nuttx/libc/math/lib_cosf.c b/nuttx/libc/math/lib_cosf.c new file mode 100644 index 000000000..d9ac951f6 --- /dev/null +++ b/nuttx/libc/math/lib_cosf.c @@ -0,0 +1,41 @@ +/************************************************************************ + * libc/math/lib_cosf.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009-2011 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +float cosf(float x) +{ + return sinf(x + M_PI_2); +} diff --git a/nuttx/libc/math/lib_cosh.c b/nuttx/libc/math/lib_cosh.c new file mode 100644 index 000000000..3246ea5f9 --- /dev/null +++ b/nuttx/libc/math/lib_cosh.c @@ -0,0 +1,47 @@ +/************************************************************************ + * libc/math/lib_cosh.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009-2011 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include +#include + +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +#ifdef CONFIG_HAVE_DOUBLE +double cosh(double x) +{ + x = exp(x); + return ((x + (1.0 / x)) / 2.0); +} +#endif diff --git a/nuttx/libc/math/lib_coshf.c b/nuttx/libc/math/lib_coshf.c new file mode 100644 index 000000000..f0c28ab2e --- /dev/null +++ b/nuttx/libc/math/lib_coshf.c @@ -0,0 +1,42 @@ +/************************************************************************ + * libc/math/lib_coshf.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009-2011 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +float coshf(float x) +{ + x = expf(x); + return ((x + (1.0 / x)) / 2.0); +} diff --git a/nuttx/libc/math/lib_coshl.c b/nuttx/libc/math/lib_coshl.c new file mode 100644 index 000000000..957ec61a7 --- /dev/null +++ b/nuttx/libc/math/lib_coshl.c @@ -0,0 +1,47 @@ +/************************************************************************ + * libc/math/lib_coshl.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009-2011 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include +#include + +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +#ifdef CONFIG_HAVE_LONG_DOUBLE +long double coshl(long double x) +{ + x = expl(x); + return ((x + (1.0 / x)) / 2.0); +} +#endif diff --git a/nuttx/libc/math/lib_cosl.c b/nuttx/libc/math/lib_cosl.c new file mode 100644 index 000000000..972d4aa9d --- /dev/null +++ b/nuttx/libc/math/lib_cosl.c @@ -0,0 +1,46 @@ +/************************************************************************ + * libc/math/lib_cosl.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009-2011 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include +#include + +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +#ifdef CONFIG_HAVE_LONG_DOUBLE +long double cosl(long double x) +{ + return sinl(x + M_PI_2); +} +#endif diff --git a/nuttx/libc/math/lib_exp.c b/nuttx/libc/math/lib_exp.c new file mode 100644 index 000000000..62494251d --- /dev/null +++ b/nuttx/libc/math/lib_exp.c @@ -0,0 +1,126 @@ +/************************************************************************ + * libc/math/lib_exp.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009-2011 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include +#include + +#include +#include + +#include "lib_internal.h" + +#ifdef CONFIG_HAVE_DOUBLE + +/************************************************************************ + * Private Data + ************************************************************************/ + +static double _dbl_inv_fact[] = +{ + 1.0 / 1.0, // 1 / 0! + 1.0 / 1.0, // 1 / 1! + 1.0 / 2.0, // 1 / 2! + 1.0 / 6.0, // 1 / 3! + 1.0 / 24.0, // 1 / 4! + 1.0 / 120.0, // 1 / 5! + 1.0 / 720.0, // 1 / 6! + 1.0 / 5040.0, // 1 / 7! + 1.0 / 40320.0, // 1 / 8! + 1.0 / 362880.0, // 1 / 9! + 1.0 / 3628800.0, // 1 / 10! + 1.0 / 39916800.0, // 1 / 11! + 1.0 / 479001600.0, // 1 / 12! + 1.0 / 6227020800.0, // 1 / 13! + 1.0 / 87178291200.0, // 1 / 14! + 1.0 / 1307674368000.0, // 1 / 15! + 1.0 / 20922789888000.0, // 1 / 16! + 1.0 / 355687428096000.0, // 1 / 17! + 1.0 / 6402373705728000.0, // 1 / 18! +}; + +/************************************************************************ + * Public Functions + ************************************************************************/ + +double exp(double x) +{ + size_t int_part; + bool invert; + double value; + double x0; + size_t i; + + if (x == 0) + { + return 1; + } + else if (x < 0) + { + invert = true; + x = -x; + } + else + { + invert = false; + } + + /* Extract integer component */ + + int_part = (size_t) x; + + /* Set x to fractional component */ + + x -= (double)int_part; + + /* Perform Taylor series approximation with nineteen terms */ + + value = 0.0; + x0 = 1.0; + for (i = 0; i < 19; i++) + { + value += x0 * _dbl_inv_fact[i]; + x0 *= x; + } + + /* Multiply by exp of the integer component */ + + value *= lib_expi(int_part); + + if (invert) + { + return (1.0 / value); + } + else + { + return value; + } +} +#endif diff --git a/nuttx/libc/math/lib_expf.c b/nuttx/libc/math/lib_expf.c new file mode 100644 index 000000000..3e43c54a6 --- /dev/null +++ b/nuttx/libc/math/lib_expf.c @@ -0,0 +1,112 @@ +/************************************************************************ + * libc/math/lib_expf.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009-2011 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include +#include + +#include "lib_internal.h" + +/************************************************************************ + * Private Data + ************************************************************************/ + +static float _flt_inv_fact[] = +{ + 1.0 / 1.0, // 1/0! + 1.0 / 1.0, // 1/1! + 1.0 / 2.0, // 1/2! + 1.0 / 6.0, // 1/3! + 1.0 / 24.0, // 1/4! + 1.0 / 120.0, // 1/5! + 1.0 / 720.0, // 1/6! + 1.0 / 5040.0, // 1/7! + 1.0 / 40320.0, // 1/8! + 1.0 / 362880.0, // 1/9! + 1.0 / 3628800.0, // 1/10! +}; + +/************************************************************************ + * Public Functions + ************************************************************************/ + +float expf(float x) +{ + size_t int_part; + bool invert; + float value; + float x0; + size_t i; + + if (x == 0) + { + return 1; + } + else if (x < 0) + { + invert = true; + x = -x; + } + else + { + invert = false; + } + + /* Extract integer component */ + + int_part = (size_t) x; + + /* set x to fractional component */ + + x -= (float)int_part; + + /* Perform Taylor series approximation with eleven terms */ + + value = 0.0; + x0 = 1.0; + for (i = 0; i < 10; i++) + { + value += x0 * _flt_inv_fact[i]; + x0 *= x; + } + + /* Multiply by exp of the integer component */ + + value *= lib_expi(int_part); + + if (invert) + { + return (1.0 / value); + } + else + { + return value; + } +} diff --git a/nuttx/libc/math/lib_expl.c b/nuttx/libc/math/lib_expl.c new file mode 100644 index 000000000..231faa35f --- /dev/null +++ b/nuttx/libc/math/lib_expl.c @@ -0,0 +1,126 @@ +/************************************************************************ + * libc/math/lib_expl.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009-2011 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include +#include + +#include +#include + +#include "lib_internal.h" + +#ifdef CONFIG_HAVE_LONG_DOUBLE + +/************************************************************************ + * Private Data + ************************************************************************/ + +static long double _ldbl_inv_fact[] = +{ + 1.0 / 1.0, // 1 / 0! + 1.0 / 1.0, // 1 / 1! + 1.0 / 2.0, // 1 / 2! + 1.0 / 6.0, // 1 / 3! + 1.0 / 24.0, // 1 / 4! + 1.0 / 120.0, // 1 / 5! + 1.0 / 720.0, // 1 / 6! + 1.0 / 5040.0, // 1 / 7! + 1.0 / 40320.0, // 1 / 8! + 1.0 / 362880.0, // 1 / 9! + 1.0 / 3628800.0, // 1 / 10! + 1.0 / 39916800.0, // 1 / 11! + 1.0 / 479001600.0, // 1 / 12! + 1.0 / 6227020800.0, // 1 / 13! + 1.0 / 87178291200.0, // 1 / 14! + 1.0 / 1307674368000.0, // 1 / 15! + 1.0 / 20922789888000.0, // 1 / 16! + 1.0 / 355687428096000.0, // 1 / 17! + 1.0 / 6402373705728000.0, // 1 / 18! +}; + +/************************************************************************ + * Public Functions + ************************************************************************/ + +long double expl(long double x) +{ + size_t int_part; + bool invert; + long double value; + long double x0; + size_t i; + + if (x == 0) + { + return 1; + } + else if (x < 0) + { + invert = true; + x = -x; + } + else + { + invert = false; + } + + /* Extract integer component */ + + int_part = (size_t) x; + + /* Set x to fractional component */ + + x -= (long double)int_part; + + /* Perform Taylor series approximation with nineteen terms */ + + value = 0.0; + x0 = 1.0; + for (i = 0; i < 19; i++) + { + value += x0 * _ldbl_inv_fact[i]; + x0 *= x; + } + + /* Multiply by exp of the integer component */ + + value *= lib_expi(int_part); + + if (invert) + { + return (1.0 / value); + } + else + { + return value; + } +} +#endif diff --git a/nuttx/libc/math/lib_fabs.c b/nuttx/libc/math/lib_fabs.c new file mode 100644 index 000000000..774755087 --- /dev/null +++ b/nuttx/libc/math/lib_fabs.c @@ -0,0 +1,46 @@ +/************************************************************************ + * libc/math/lib_fabs.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009, 2010 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include +#include + +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +#ifdef CONFIG_HAVE_DOUBLE +double fabs(double x) +{ + return ((x < 0) ? -x : x); +} +#endif diff --git a/nuttx/libc/math/lib_fabsf.c b/nuttx/libc/math/lib_fabsf.c new file mode 100644 index 000000000..4c8ebae62 --- /dev/null +++ b/nuttx/libc/math/lib_fabsf.c @@ -0,0 +1,41 @@ +/************************************************************************ + * libc/math/lib_fabsf.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009, 2010 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +float fabsf(float x) +{ + return ((x < 0) ? -x : x); +} diff --git a/nuttx/libc/math/lib_fabsl.c b/nuttx/libc/math/lib_fabsl.c new file mode 100644 index 000000000..96ac7d5db --- /dev/null +++ b/nuttx/libc/math/lib_fabsl.c @@ -0,0 +1,46 @@ +/************************************************************************ + * libc/math/lib_fabsl.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009, 2010 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include +#include + +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +#ifdef CONFIG_HAVE_LONG_DOUBLE +long double fabsl(long double x) +{ + return ((x < 0) ? -x : x); +} +#endif diff --git a/nuttx/libc/math/lib_floor.c b/nuttx/libc/math/lib_floor.c new file mode 100644 index 000000000..3330607ce --- /dev/null +++ b/nuttx/libc/math/lib_floor.c @@ -0,0 +1,52 @@ +/************************************************************************ + * libc/math/lib_floor.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009-2011 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include +#include + +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +#ifdef CONFIG_HAVE_DOUBLE +double floor(double x) +{ + modf(x, &x); + if (x < 0.0) + { + x -= 1.0; + } + + return x; +} +#endif diff --git a/nuttx/libc/math/lib_floorf.c b/nuttx/libc/math/lib_floorf.c new file mode 100644 index 000000000..81483d4c9 --- /dev/null +++ b/nuttx/libc/math/lib_floorf.c @@ -0,0 +1,47 @@ +/************************************************************************ + * libc/math/lib_floorf.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009-2011 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +float floorf(float x) +{ + modff(x, &x); + if (x < 0.0) + { + x -= 1.0; + } + + return x; +} diff --git a/nuttx/libc/math/lib_floorl.c b/nuttx/libc/math/lib_floorl.c new file mode 100644 index 000000000..0d9ec43b4 --- /dev/null +++ b/nuttx/libc/math/lib_floorl.c @@ -0,0 +1,52 @@ +/************************************************************************ + * libc/math/lib_floorl.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009-2011 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include +#include + +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +#ifdef CONFIG_HAVE_LONG_DOUBLE +long double floorl(long double x) +{ + modfl(x, &x); + if (x < 0.0) + { + x -= 1.0; + } + + return x; +} +#endif diff --git a/nuttx/libc/math/lib_fmod.c b/nuttx/libc/math/lib_fmod.c new file mode 100644 index 000000000..c66210cde --- /dev/null +++ b/nuttx/libc/math/lib_fmod.c @@ -0,0 +1,52 @@ +/************************************************************************ + * libc/math/lib_fmod.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009-2011 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include +#include + +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +#ifdef CONFIG_HAVE_DOUBLE +double fmod(double x, double div) +{ + double n0; + + x /= div; + x = modf(x, &n0); + x *= div; + + return x; +} +#endif diff --git a/nuttx/libc/math/lib_fmodf.c b/nuttx/libc/math/lib_fmodf.c new file mode 100644 index 000000000..d70bb791c --- /dev/null +++ b/nuttx/libc/math/lib_fmodf.c @@ -0,0 +1,47 @@ +/************************************************************************ + * libc/math/lib_fmodf.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009-2011 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +float fmodf(float x, float div) +{ + float n0; + + x /= div; + x = modff(x, &n0); + x *= div; + + return x; +} diff --git a/nuttx/libc/math/lib_fmodl.c b/nuttx/libc/math/lib_fmodl.c new file mode 100644 index 000000000..1299bf6e8 --- /dev/null +++ b/nuttx/libc/math/lib_fmodl.c @@ -0,0 +1,52 @@ +/************************************************************************ + * libc/math/lib_fmodl.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009-2011 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include +#include + +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +#ifdef CONFIG_HAVE_LONG_DOUBLE +long double fmodl(long double x, long double div) +{ + long double n0; + + x /= div; + x = modfl(x, &n0); + x *= div; + + return x; +} +#endif diff --git a/nuttx/libc/math/lib_frexp.c b/nuttx/libc/math/lib_frexp.c new file mode 100644 index 000000000..b9576dfd4 --- /dev/null +++ b/nuttx/libc/math/lib_frexp.c @@ -0,0 +1,47 @@ +/************************************************************************ + * libc/math/lib_frexp.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009-2011 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include +#include + +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +#ifdef CONFIG_HAVE_DOUBLE +double frexp(double x, int *exponent) +{ + *exponent = (int)ceil(log2(x)); + return x / ldexp(1.0, *exponent); +} +#endif diff --git a/nuttx/libc/math/lib_frexpf.c b/nuttx/libc/math/lib_frexpf.c new file mode 100644 index 000000000..d93ffb173 --- /dev/null +++ b/nuttx/libc/math/lib_frexpf.c @@ -0,0 +1,42 @@ +/************************************************************************ + * libc/math/lib_frexpf.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009-2011 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +float frexpf(float x, int *exponent) +{ + *exponent = (int)ceilf(log2f(x)); + return x / ldexpf(1.0, *exponent); +} diff --git a/nuttx/libc/math/lib_frexpl.c b/nuttx/libc/math/lib_frexpl.c new file mode 100644 index 000000000..90993b137 --- /dev/null +++ b/nuttx/libc/math/lib_frexpl.c @@ -0,0 +1,47 @@ +/************************************************************************ + * libc/math/lib_frexpl.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009-2011 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include +#include + +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +#ifdef CONFIG_HAVE_LONG_DOUBLE +long double frexpl(long double x, int *exponent) +{ + *exponent = (int)ceill(log2(x)); + return x / ldexpl(1.0, *exponent); +} +#endif diff --git a/nuttx/libc/math/lib_ldexp.c b/nuttx/libc/math/lib_ldexp.c new file mode 100644 index 000000000..9b74d53d7 --- /dev/null +++ b/nuttx/libc/math/lib_ldexp.c @@ -0,0 +1,46 @@ +/************************************************************************ + * libc/math/lib_ldexp.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009-2011 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include +#include + +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +#ifdef CONFIG_HAVE_DOUBLE +double ldexp(double x, int n) +{ + return (x * pow(2.0, (double)n)); +} +#endif diff --git a/nuttx/libc/math/lib_ldexpf.c b/nuttx/libc/math/lib_ldexpf.c new file mode 100644 index 000000000..f3aaf555b --- /dev/null +++ b/nuttx/libc/math/lib_ldexpf.c @@ -0,0 +1,41 @@ +/************************************************************************ + * libc/math/lib_ldexpf.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009-2011 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +float ldexpf(float x, int n) +{ + return (x * powf(2.0, (float)n)); +} diff --git a/nuttx/libc/math/lib_ldexpl.c b/nuttx/libc/math/lib_ldexpl.c new file mode 100644 index 000000000..29764aaba --- /dev/null +++ b/nuttx/libc/math/lib_ldexpl.c @@ -0,0 +1,46 @@ +/************************************************************************ + * libc/math/lib_ldexpl.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009-2011 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include +#include + +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +#ifdef CONFIG_HAVE_LONG_DOUBLE +long double ldexpl(long double x, int n) +{ + return (x * powl(2.0, (long double)n)); +} +#endif diff --git a/nuttx/libc/math/lib_libexpi.c b/nuttx/libc/math/lib_libexpi.c new file mode 100644 index 000000000..33ba537b1 --- /dev/null +++ b/nuttx/libc/math/lib_libexpi.c @@ -0,0 +1,103 @@ +/************************************************************************ + * libc/math/lib_libexpi.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009-2011 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include +#include + +#include +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +/************************************************************************ + * Pre-processor Definitions + ************************************************************************/ + +#define M_E2 (M_E * M_E) +#define M_E4 (M_E2 * M_E2) +#define M_E8 (M_E4 * M_E4) +#define M_E16 (M_E8 * M_E8) +#define M_E32 (M_E16 * M_E16) +#define M_E64 (M_E32 * M_E32) +#define M_E128 (M_E64 * M_E64) +#define M_E256 (M_E128 * M_E128) +#define M_E512 (M_E256 * M_E256) +#define M_E1024 (M_E512 * M_E512) + +/************************************************************************ + * Private Data + ************************************************************************/ + +static double _expi_square_tbl[11] = +{ + M_E, // e^1 + M_E2, // e^2 + M_E4, // e^4 + M_E8, // e^8 + M_E16, // e^16 + M_E32, // e^32 + M_E64, // e^64 + M_E128, // e^128 + M_E256, // e^256 + M_E512, // e^512 + M_E1024, // e^1024 +}; + +/************************************************************************ + * Public Functions + ************************************************************************/ + +double lib_expi(size_t n) +{ + size_t i; + double val; + + if (n > 1024) + { + return INFINITY; + } + + val = 1.0; + + for (i = 0; n; i++) + { + if (n & (1 << i)) + { + n &= ~(1 << i); + val *= _expi_square_tbl[i]; + } + } + + return val; +} + diff --git a/nuttx/libc/math/lib_libsqrtapprox.c b/nuttx/libc/math/lib_libsqrtapprox.c new file mode 100644 index 000000000..b6a9b0d54 --- /dev/null +++ b/nuttx/libc/math/lib_libsqrtapprox.c @@ -0,0 +1,50 @@ +/************************************************************************ + * libc/math/lib_libsqrtapprox.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009-2011 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +float lib_sqrtapprox(float x) +{ + int32_t i; + + /* Floats + bit manipulation = +inf fun! */ + + i = *((int32_t *) & x); + i = 0x1fc00000 + (i >> 1); + x = *((float *)&i); + + return x; +} diff --git a/nuttx/libc/math/lib_log.c b/nuttx/libc/math/lib_log.c new file mode 100644 index 000000000..7156f6b41 --- /dev/null +++ b/nuttx/libc/math/lib_log.c @@ -0,0 +1,82 @@ +/************************************************************************ + * libc/math/lib_log.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009, 2010 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include +#include + +#include +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +#ifdef CONFIG_HAVE_DOUBLE +double log(double x) +{ + double y, y_old, ey, epsilon; + + y = 0.0; + y_old = 1.0; + epsilon = DBL_EPSILON; + + while (y > y_old + epsilon || y < y_old - epsilon) + { + y_old = y; + ey = exp(y); + y -= (ey - x) / ey; + + if (y > 700.0) + { + y = 700.0; + } + + if (y < -700.0) + { + y = -700.0; + } + + epsilon = (fabs(y) > 1.0) ? fabs(y) * DBL_EPSILON : DBL_EPSILON; + } + + if (y == 700.0) + { + return INFINITY; + } + + if (y == -700.0) + { + return INFINITY; + } + + return y; +} +#endif diff --git a/nuttx/libc/math/lib_log10.c b/nuttx/libc/math/lib_log10.c new file mode 100644 index 000000000..9daa91492 --- /dev/null +++ b/nuttx/libc/math/lib_log10.c @@ -0,0 +1,46 @@ +/************************************************************************ + * libc/math/lib_log10.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009, 2010 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include +#include + +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +#ifdef CONFIG_HAVE_DOUBLE +double log10(double x) +{ + return (log(x) / M_LN10); +} +#endif diff --git a/nuttx/libc/math/lib_log10f.c b/nuttx/libc/math/lib_log10f.c new file mode 100644 index 000000000..778daedd5 --- /dev/null +++ b/nuttx/libc/math/lib_log10f.c @@ -0,0 +1,41 @@ +/************************************************************************ + * libc/math/lib_log10f.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009, 2010 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +float log10f(float x) +{ + return (logf(x) / M_LN10); +} diff --git a/nuttx/libc/math/lib_log10l.c b/nuttx/libc/math/lib_log10l.c new file mode 100644 index 000000000..efbeb721b --- /dev/null +++ b/nuttx/libc/math/lib_log10l.c @@ -0,0 +1,46 @@ +/************************************************************************ + * libc/math/lib_log10l.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009, 2010 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include +#include + +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +#ifdef CONFIG_HAVE_LONG_DOUBLE +long double log10l(long double x) +{ + return (logl(x) / M_LN10); +} +#endif diff --git a/nuttx/libc/math/lib_log2.c b/nuttx/libc/math/lib_log2.c new file mode 100644 index 000000000..4da39acdc --- /dev/null +++ b/nuttx/libc/math/lib_log2.c @@ -0,0 +1,46 @@ +/************************************************************************ + * libc/math/lib_log2.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009, 2010 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include +#include + +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +#ifdef CONFIG_HAVE_DOUBLE +double log2(double x) +{ + return (log(x) / M_LN2); +} +#endif diff --git a/nuttx/libc/math/lib_log2f.c b/nuttx/libc/math/lib_log2f.c new file mode 100644 index 000000000..f514e5a9e --- /dev/null +++ b/nuttx/libc/math/lib_log2f.c @@ -0,0 +1,41 @@ +/************************************************************************ + * libc/math/lib_log2f.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009, 2010 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +float log2f(float x) +{ + return (logf(x) / M_LN2); +} diff --git a/nuttx/libc/math/lib_log2l.c b/nuttx/libc/math/lib_log2l.c new file mode 100644 index 000000000..21e80a930 --- /dev/null +++ b/nuttx/libc/math/lib_log2l.c @@ -0,0 +1,46 @@ +/************************************************************************ + * libc/math/lib_log2l.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009, 2010 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include +#include + +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +#ifdef CONFIG_HAVE_LONG_DOUBLE +long double log2l(long double x) +{ + return (logl(x) / M_LN2); +} +#endif diff --git a/nuttx/libc/math/lib_logf.c b/nuttx/libc/math/lib_logf.c new file mode 100644 index 000000000..3815fef84 --- /dev/null +++ b/nuttx/libc/math/lib_logf.c @@ -0,0 +1,77 @@ +/************************************************************************ + * libc/math/lib_logf.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009, 2010 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +float logf(float x) +{ + float y, y_old, ey, epsilon; + + y = 0.0; + y_old = 1.0; + epsilon = FLT_EPSILON; + + while (y > y_old + epsilon || y < y_old - epsilon) + { + y_old = y; + ey = exp(y); + y -= (ey - x) / ey; + + if (y > 700.0) + { + y = 700.0; + } + + if (y < -700.0) + { + y = -700.0; + } + + epsilon = (fabs(y) > 1.0) ? fabs(y) * FLT_EPSILON : FLT_EPSILON; + } + + if (y == 700.0) + { + return INFINITY; + } + + if (y == -700.0) + { + return INFINITY; + } + + return y; +} diff --git a/nuttx/libc/math/lib_logl.c b/nuttx/libc/math/lib_logl.c new file mode 100644 index 000000000..612816011 --- /dev/null +++ b/nuttx/libc/math/lib_logl.c @@ -0,0 +1,80 @@ +/************************************************************************ + * libc/math/lib_lol.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009, 2010 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include +#include + +#include +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +#ifdef CONFIG_HAVE_LONG_DOUBLE +long double logl(long double x) +{ + long double y, y_old, ey, epsilon; + + y = 0.0; + y_old = 1.0; + epsilon = LDBL_EPSILON; + + while (y > y_old + epsilon || y < y_old - epsilon) + { + y_old = y; + ey = expl(y); + y -= (ey - x) / ey; + + if (y > 700.0) + { + y = 700.0; + } + + if (y < -700.0) + { + y = -700.0; + } + } + + if (y == 700.0) + { + return INFINITY; + } + + if (y == -700.0) + { + return INFINITY; + } + + return y; +} +#endif diff --git a/nuttx/libc/math/lib_modf.c b/nuttx/libc/math/lib_modf.c new file mode 100644 index 000000000..f3f25f6fb --- /dev/null +++ b/nuttx/libc/math/lib_modf.c @@ -0,0 +1,58 @@ +/************************************************************************ + * libc/math/lib_modf.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009-2011 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +#ifdef CONFIG_HAVE_DOUBLE +double modf(double x, double *iptr) +{ + if (fabs(x) >= 4503599627370496.0) + { + *iptr = x; + return 0.0; + } + else if (fabs(x) < 1.0) + { + *iptr = 0.0; + return x; + } + else + { + *iptr = (double)(int64_t) x; + return (x - *iptr); + } +} +#endif diff --git a/nuttx/libc/math/lib_modff.c b/nuttx/libc/math/lib_modff.c new file mode 100644 index 000000000..28d3a3ae0 --- /dev/null +++ b/nuttx/libc/math/lib_modff.c @@ -0,0 +1,55 @@ +/************************************************************************ + * libc/math/lib_modff.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009-2011 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +float modff(float x, float *iptr) +{ + if (fabsf(x) >= 8388608.0) + { + *iptr = x; + return 0.0; + } + else if (fabs(x) < 1.0) + { + *iptr = 0.0; + return x; + } + else + { + *iptr = (float)(int)x; + return (x - *iptr); + } +} diff --git a/nuttx/libc/math/lib_modfl.c b/nuttx/libc/math/lib_modfl.c new file mode 100644 index 000000000..77bba0e0c --- /dev/null +++ b/nuttx/libc/math/lib_modfl.c @@ -0,0 +1,61 @@ +/************************************************************************ + * libc/math/lib_modfl.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009-2011 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include +#include + +#include +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +#ifdef CONFIG_HAVE_LONG_DOUBLE +long double modfl(long double x, long double *iptr) +{ + if (fabs(x) >= 4503599627370496.0) + { + *iptr = x; + return 0.0; + } + else if (fabs(x) < 1.0) + { + *iptr = 0.0; + return x; + } + else + { + *iptr = (long double)(int64_t) x; + return (x - *iptr); + } +} +#endif diff --git a/nuttx/libc/math/lib_pow.c b/nuttx/libc/math/lib_pow.c new file mode 100644 index 000000000..a19d491fa --- /dev/null +++ b/nuttx/libc/math/lib_pow.c @@ -0,0 +1,46 @@ +/************************************************************************ + * libc/math/lib_pow.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009, 2010 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include +#include + +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +#ifdef CONFIG_HAVE_DOUBLE +double pow(double b, double e) +{ + return exp(e * log(b)); +} +#endif diff --git a/nuttx/libc/math/lib_powf.c b/nuttx/libc/math/lib_powf.c new file mode 100644 index 000000000..570904898 --- /dev/null +++ b/nuttx/libc/math/lib_powf.c @@ -0,0 +1,41 @@ +/************************************************************************ + * libc/math/lib_powf.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009, 2010 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +float powf(float b, float e) +{ + return expf(e * logf(b)); +} diff --git a/nuttx/libc/math/lib_powl.c b/nuttx/libc/math/lib_powl.c new file mode 100644 index 000000000..81438217c --- /dev/null +++ b/nuttx/libc/math/lib_powl.c @@ -0,0 +1,46 @@ +/************************************************************************ + * libc/math/lib_powl.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009, 2010 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include +#include + +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +#ifdef CONFIG_HAVE_LONG_DOUBLE +long double powl(long double b, long double e) +{ + return expl(e * logl(b)); +} +#endif diff --git a/nuttx/libc/math/lib_sin.c b/nuttx/libc/math/lib_sin.c new file mode 100644 index 000000000..e005d98cb --- /dev/null +++ b/nuttx/libc/math/lib_sin.c @@ -0,0 +1,114 @@ +/************************************************************************ + * libc/math/lib_sin.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009-2011 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include +#include + +#include +#include + +#ifdef CONFIG_HAVE_DOUBLE + +/************************************************************************ + * Private Data + ************************************************************************/ + +static double _dbl_inv_fact[] = +{ + 1.0 / 1.0, // 1 / 1! + 1.0 / 6.0, // 1 / 3! + 1.0 / 120.0, // 1 / 5! + 1.0 / 5040.0, // 1 / 7! + 1.0 / 362880.0, // 1 / 9! + 1.0 / 39916800.0, // 1 / 11! + 1.0 / 6227020800.0, // 1 / 13! + 1.0 / 1307674368000.0, // 1 / 15! + 1.0 / 355687428096000.0, // 1 / 17! + 1.0 / 121645100408832000.0, // 1 / 19! +}; + +/************************************************************************ + * Public Functions + ************************************************************************/ + +double sin(double x) +{ + double x_squared; + double sin_x; + size_t i; + + /* Move x to [-pi, pi) */ + + x = fmod(x, 2 * M_PI); + if (x >= M_PI) + { + x -= 2 * M_PI; + } + + if (x < -M_PI) + { + x += 2 * M_PI; + } + + /* Move x to [-pi/2, pi/2) */ + + if (x >= M_PI_2) + { + x = M_PI - x; + } + + if (x < -M_PI_2) + { + x = -M_PI - x; + } + + x_squared = x * x; + sin_x = 0.0; + + /* Perform Taylor series approximation for sin(x) with ten terms */ + + for (i = 0; i < 10; i++) + { + if (i % 2 == 0) + { + sin_x += x * _dbl_inv_fact[i]; + } + else + { + sin_x -= x * _dbl_inv_fact[i]; + } + + x *= x_squared; + } + + return sin_x; +} +#endif diff --git a/nuttx/libc/math/lib_sinf.c b/nuttx/libc/math/lib_sinf.c new file mode 100644 index 000000000..9e493d8ef --- /dev/null +++ b/nuttx/libc/math/lib_sinf.c @@ -0,0 +1,104 @@ +/************************************************************************ + * libc/math/lib_sinf.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009-2011 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include +#include + +/************************************************************************ + * Private Data + ************************************************************************/ + +static float _flt_inv_fact[] = +{ + 1.0 / 1.0, // 1 / 1! + 1.0 / 6.0, // 1 / 3! + 1.0 / 120.0, // 1 / 5! + 1.0 / 5040.0, // 1 / 7! + 1.0 / 362880.0, // 1 / 9! + 1.0 / 39916800.0, // 1 / 11! +}; + +/************************************************************************ + * Public Functions + ************************************************************************/ + +float sinf(float x) +{ + float x_squared; + float sin_x; + size_t i; + + /* Move x to [-pi, pi) */ + + x = fmodf(x, 2 * M_PI); + if (x >= M_PI) + { + x -= 2 * M_PI; + } + + if (x < -M_PI) + { + x += 2 * M_PI; + } + + /* Move x to [-pi/2, pi/2) */ + + if (x >= M_PI_2) + { + x = M_PI - x; + } + + if (x < -M_PI_2) + { + x = -M_PI - x; + } + + x_squared = x * x; + sin_x = 0.0; + + /* Perform Taylor series approximation for sin(x) with six terms */ + + for (i = 0; i < 6; i++) + { + if (i % 2 == 0) + { + sin_x += x * _flt_inv_fact[i]; + } + else + { + sin_x -= x * _flt_inv_fact[i]; + } + + x *= x_squared; + } + + return sin_x; +} diff --git a/nuttx/libc/math/lib_sinh.c b/nuttx/libc/math/lib_sinh.c new file mode 100644 index 000000000..0c3e2d11d --- /dev/null +++ b/nuttx/libc/math/lib_sinh.c @@ -0,0 +1,47 @@ +/************************************************************************ + * libc/math/lib_sinh.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009, 2010 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include +#include + +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +#ifdef CONFIG_HAVE_DOUBLE +double sinh(double x) +{ + x = exp(x); + return ((x - (1.0 / x)) / 2.0); +} +#endif diff --git a/nuttx/libc/math/lib_sinhf.c b/nuttx/libc/math/lib_sinhf.c new file mode 100644 index 000000000..e9d198440 --- /dev/null +++ b/nuttx/libc/math/lib_sinhf.c @@ -0,0 +1,42 @@ +/************************************************************************ + * libc/math/lib_sinhf.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009, 2010 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +float sinhf(float x) +{ + x = expf(x); + return ((x - (1.0 / x)) / 2.0); +} diff --git a/nuttx/libc/math/lib_sinhl.c b/nuttx/libc/math/lib_sinhl.c new file mode 100644 index 000000000..a1bcad81e --- /dev/null +++ b/nuttx/libc/math/lib_sinhl.c @@ -0,0 +1,47 @@ +/************************************************************************ + * libc/math/lib_sinhl.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009, 2010 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include +#include + +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +#ifdef CONFIG_HAVE_LONG_DOUBLE +long double sinhl(long double x) +{ + x = expl(x); + return ((x - (1.0 / x)) / 2.0); +} +#endif diff --git a/nuttx/libc/math/lib_sinl.c b/nuttx/libc/math/lib_sinl.c new file mode 100644 index 000000000..6ed539a39 --- /dev/null +++ b/nuttx/libc/math/lib_sinl.c @@ -0,0 +1,114 @@ +/************************************************************************ + * libc/math/lib_sinl.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009-2011 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include +#include + +#include +#include + +#ifdef CONFIG_HAVE_LONG_DOUBLE + +/************************************************************************ + * Private Data + ************************************************************************/ + +static long double _ldbl_inv_fact[] = +{ + 1.0 / 1.0, // 1 / 1! + 1.0 / 6.0, // 1 / 3! + 1.0 / 120.0, // 1 / 5! + 1.0 / 5040.0, // 1 / 7! + 1.0 / 362880.0, // 1 / 9! + 1.0 / 39916800.0, // 1 / 11! + 1.0 / 6227020800.0, // 1 / 13! + 1.0 / 1307674368000.0, // 1 / 15! + 1.0 / 355687428096000.0, // 1 / 17! + 1.0 / 121645100408832000.0, // 1 / 19! +}; + +/************************************************************************ + * Public Functions + ************************************************************************/ + +long double sinl(long double x) +{ + long double x_squared; + long double sin_x; + size_t i; + + /* Move x to [-pi, pi) */ + + x = fmodl(x, 2 * M_PI); + if (x >= M_PI) + { + x -= 2 * M_PI; + } + + if (x < -M_PI) + { + x += 2 * M_PI; + } + + /* Move x to [-pi/2, pi/2) */ + + if (x >= M_PI_2) + { + x = M_PI - x; + } + + if (x < -M_PI_2) + { + x = -M_PI - x; + } + + x_squared = x * x; + sin_x = 0.0; + + /* Perform Taylor series approximation for sin(x) with ten terms */ + + for (i = 0; i < 10; i++) + { + if (i % 2 == 0) + { + sin_x += x * _ldbl_inv_fact[i]; + } + else + { + sin_x -= x * _ldbl_inv_fact[i]; + } + + x *= x_squared; + } + + return sin_x; +} +#endif diff --git a/nuttx/libc/math/lib_sqrt.c b/nuttx/libc/math/lib_sqrt.c new file mode 100644 index 000000000..e8a1c42ea --- /dev/null +++ b/nuttx/libc/math/lib_sqrt.c @@ -0,0 +1,99 @@ +/************************************************************************ + * libc/math/lib_sqrt.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009-2011 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include +#include + +#include +#include + +#include "lib_internal.h" + +/************************************************************************ + * Public Functions + ************************************************************************/ + +#ifdef CONFIG_HAVE_DOUBLE +double sqrt(double x) +{ + long double y, y1; + + if (x < 0.0) + { + errno = EDOM; + return NAN; + } + + if (isnan(x)) + { + return NAN; + } + + if (isinf(x)) + { + return INFINITY; + } + + if (x == 0.0) + { + return 0.0; + } + + /* Guess square root (using bit manipulation) */ + + y = lib_sqrtapprox(x); + + /* Perform four iterations of approximation. This number (4) is + * definitely optimal + */ + + y = 0.5 * (y + x / y); + y = 0.5 * (y + x / y); + y = 0.5 * (y + x / y); + y = 0.5 * (y + x / y); + + /* If guess was terribe (out of range of float). Repeat approximation + * until convergence. + */ + + if (y * y < x - 1.0 || y * y > x + 1.0) + { + y1 = -1.0; + while (y != y1) + { + y1 = y; + y = 0.5 * (y + x / y); + } + } + + return y; +} +#endif diff --git a/nuttx/libc/math/lib_sqrtf.c b/nuttx/libc/math/lib_sqrtf.c new file mode 100644 index 000000000..cf45ccacc --- /dev/null +++ b/nuttx/libc/math/lib_sqrtf.c @@ -0,0 +1,84 @@ +/************************************************************************ + * libc/math/lib_sqrtf.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009-2011 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include +#include + +#include +#include + +#include "lib_internal.h" + +/************************************************************************ + * Public Functions + ************************************************************************/ + +float sqrtf(float x) +{ + float y; + + /* Filter out invalid/trivial inputs */ + + if (x < 0.0) + { + errno = EDOM; + return NAN; + } + + if (isnan(x)) + { + return NAN; + } + + if (isinf(x)) + { + return INFINITY; + } + + if (x == 0.0) + { + return 0.0; + } + + /* Guess square root (using bit manipulation) */ + + y = lib_sqrtapprox(x); + + /* Perform three iterations of approximation. This number (3) is + * definitely optimal + */ + + y = 0.5 * (y + x / y); + y = 0.5 * (y + x / y); + y = 0.5 * (y + x / y); + + return y; +} diff --git a/nuttx/libc/math/lib_sqrtl.c b/nuttx/libc/math/lib_sqrtl.c new file mode 100644 index 000000000..4035992fe --- /dev/null +++ b/nuttx/libc/math/lib_sqrtl.c @@ -0,0 +1,101 @@ +/************************************************************************ + * libc/math/lib_sqrtl.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009-2011 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include +#include + +#include +#include + +#include "lib_internal.h" + +/************************************************************************ + * Public Functions + ************************************************************************/ + +#ifdef CONFIG_HAVE_LONG_DOUBLE +long double sqrtl(long double x) +{ + long double y, y1; + + /* Filter out invalid/trivial inputs */ + + if (x < 0.0) + { + errno = EDOM; + return NAN; + } + + if (isnan(x)) + { + return NAN; + } + + if (isinf(x)) + { + return INFINITY; + } + + if (x == 0.0) + { + return 0.0; + } + + /* Guess square root (using bit manipulation) */ + + y = lib_sqrtapprox(x); + + /* Perform four iterations of approximation. This number (4) is + * definitely optimal + */ + + y = 0.5 * (y + x / y); + y = 0.5 * (y + x / y); + y = 0.5 * (y + x / y); + y = 0.5 * (y + x / y); + + /* If guess was terribe (out of range of float). Repeat approximation + * until convergence + */ + + if (y * y < x - 1.0 || y * y > x + 1.0) + { + y1 = -1.0; + while (y != y1) + { + y1 = y; + y = 0.5 * (y + x / y); + } + } + + return y; +} +#endif diff --git a/nuttx/libc/math/lib_tan.c b/nuttx/libc/math/lib_tan.c new file mode 100644 index 000000000..4c091c09b --- /dev/null +++ b/nuttx/libc/math/lib_tan.c @@ -0,0 +1,46 @@ +/************************************************************************ + * libc/math/lib_tan.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009, 2010 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include +#include + +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +#ifdef CONFIG_HAVE_DOUBLE +double tan(double x) +{ + return (sin(x) / cos(x)); +} +#endif diff --git a/nuttx/libc/math/lib_tanf.c b/nuttx/libc/math/lib_tanf.c new file mode 100644 index 000000000..0c9110a0b --- /dev/null +++ b/nuttx/libc/math/lib_tanf.c @@ -0,0 +1,41 @@ +/************************************************************************ + * libc/math/lib_tanf.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009, 2010 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +float tanf(float x) +{ + return (sinf(x) / cosf(x)); +} diff --git a/nuttx/libc/math/lib_tanh.c b/nuttx/libc/math/lib_tanh.c new file mode 100644 index 000000000..3b9ea0f41 --- /dev/null +++ b/nuttx/libc/math/lib_tanh.c @@ -0,0 +1,49 @@ +/************************************************************************ + * libc/math/lib_tanh.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009, 2010 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include +#include + +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +#ifdef CONFIG_HAVE_DOUBLE +double tanh(double x) +{ + double x0 = exp(x); + double x1 = 1.0 / x0; + + return ((x0 + x1) / (x0 - x1)); +} +#endif diff --git a/nuttx/libc/math/lib_tanhf.c b/nuttx/libc/math/lib_tanhf.c new file mode 100644 index 000000000..43d418204 --- /dev/null +++ b/nuttx/libc/math/lib_tanhf.c @@ -0,0 +1,44 @@ +/************************************************************************ + * libc/math/lib_tanhf.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009, 2010 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +float tanhf(float x) +{ + float x0 = expf(x); + float x1 = 1.0 / x0; + + return ((x0 + x1) / (x0 - x1)); +} diff --git a/nuttx/libc/math/lib_tanhl.c b/nuttx/libc/math/lib_tanhl.c new file mode 100644 index 000000000..5aafd1e7b --- /dev/null +++ b/nuttx/libc/math/lib_tanhl.c @@ -0,0 +1,49 @@ +/************************************************************************ + * libc/math/lib_tanhl.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009, 2010 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include +#include + +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +#ifdef CONFIG_HAVE_LONG_DOUBLE +long double tanhl(long double x) +{ + long double x0 = exp(x); + long double x1 = 1.0 / x0; + + return ((x0 + x1) / (x0 - x1)); +} +#endif diff --git a/nuttx/libc/math/lib_tanl.c b/nuttx/libc/math/lib_tanl.c new file mode 100644 index 000000000..e77abe0f1 --- /dev/null +++ b/nuttx/libc/math/lib_tanl.c @@ -0,0 +1,46 @@ +/************************************************************************ + * libc/math/lib_tanl.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Ported by: Darcy Gong + * + * It derives from the Rhombs OS math library by Nick Johnson which has + * a compatibile, MIT-style license: + * + * Copyright (C) 2009, 2010 Nick Johnson + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include +#include + +#include + +/************************************************************************ + * Public Functions + ************************************************************************/ + +#ifdef CONFIG_HAVE_LONG_DOUBLE +long double tanl(long double x) +{ + return (sinl(x) / cosl(x)); +} +#endif diff --git a/nuttx/libc/misc/Make.defs b/nuttx/libc/misc/Make.defs new file mode 100644 index 000000000..f4284ac60 --- /dev/null +++ b/nuttx/libc/misc/Make.defs @@ -0,0 +1,69 @@ +############################################################################ +# libc/misc/Make.defs +# +# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# 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. +# +############################################################################ + +# Add the internal C files to the build + +CSRCS += lib_init.c lib_filesem.c + +# Add C files that depend on file OR socket descriptors + +ifneq ($(CONFIG_NFILE_DESCRIPTORS),0) + +CSRCS += lib_sendfile.c +ifneq ($(CONFIG_NFILE_STREAMS),0) +CSRCS += lib_streamsem.c +endif + +else +ifneq ($(CONFIG_NSOCKET_DESCRIPTORS),0) + +CSRCS += lib_sendfile.c +ifneq ($(CONFIG_NFILE_STREAMS),0) +CSRCS += lib_streamsem.c +endif + +endif +endif + +# Add the miscellaneous C files to the build + +CSRCS += lib_match.c +CSRCS += lib_crc32.c +CSRCS += lib_dbg.c lib_dumpbuffer.c + +# Add the misc directory to the build + +DEPPATH += --dep-path misc +VPATH += :misc diff --git a/nuttx/libc/misc/lib_crc32.c b/nuttx/libc/misc/lib_crc32.c new file mode 100644 index 000000000..ae73ba3d7 --- /dev/null +++ b/nuttx/libc/misc/lib_crc32.c @@ -0,0 +1,123 @@ +/************************************************************************************************ + * libc/misc/lib_crc32.c + * + * This file is a part of NuttX: + * + * Copyright (C) 2010-2011 Gregory Nutt. All rights reserved. + * + * The logic in this file was developed by Gary S. Brown: + * + * COPYRIGHT (C) 1986 Gary S. Brown. You may use this program, or code or tables + * extracted from it, as desired without restriction. + * + * First, the polynomial itself and its table of feedback terms. The polynomial is: + * + * X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0 + * + * Note that we take it "backwards" and put the highest-order term in the lowest-order bit. + * The X^32 term is "implied"; the LSB is the X^31 term, etc. The X^0 term (usually shown + * as "+1") results in the MSB being 1 + * + * Note that the usual hardware shift register implementation, which is what we're using + * (we're merely optimizing it by doing eight-bit chunks at a time) shifts bits into the + * lowest-order term. In our implementation, that means shifting towards the right. Why + * do we do it this way? Because the calculated CRC must be transmitted in order from + * highest-order term to lowest-order term. UARTs transmit characters in order from LSB + * to MSB. By storing the CRC this way we hand it to the UART in the order low-byte to + * high-byte; the UART sends each low-bit to hight-bit; and the result is transmission bit + * by bit from highest- to lowest-order term without requiring any bit shuffling on our + * part. Reception works similarly + * + * The feedback terms table consists of 256, 32-bit entries. Notes + * + * - The table can be generated at runtime if desired; code to do so is shown later. It + * might not be obvious, but the feedback terms simply represent the results of eight + * shift/xor operations for all combinations of data and CRC register values + * + * - The values must be right-shifted by eight bits by the updcrc logic; the shift must + * be u_(bring in zeroes). On some hardware you could probably optimize the shift in + * assembler by using byte-swap instructions polynomial $edb88320 + ************************************************************************************************/ + +/************************************************************************************************ + * Included Files + ************************************************************************************************/ + +#include +#include +#include + +/************************************************************************************************ + * Private Data + ************************************************************************************************/ + +static const uint32_t crc32_tab[] = +{ + 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, + 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, + 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, + 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, + 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, + 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, + 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, + 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, + 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, + 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, + 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, + 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, + 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, + 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, + 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, + 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, + 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, + 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, + 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, + 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, + 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, + 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, + 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, + 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, + 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, + 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, + 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, + 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, + 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, + 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, + 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, + 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d +}; + +/************************************************************************************************ + * Public Functions + ************************************************************************************************/ +/************************************************************************************************ + * Name: crc32part + * + * Description: + * Continue CRC calculation on a part of the buffer. + * + ************************************************************************************************/ + +uint32_t crc32part(FAR const uint8_t *src, size_t len, uint32_t crc32val) +{ + size_t i; + + for (i = 0; i < len; i++) + { + crc32val = crc32_tab[(crc32val ^ src[i]) & 0xff] ^ (crc32val >> 8); + } + return crc32val; +} + +/************************************************************************************************ + * Name: crc32 + * + * Description: + * Return a 32-bit CRC of the contents of the 'src' buffer, length 'len' + * + ************************************************************************************************/ + +uint32_t crc32(FAR const uint8_t *src, size_t len) +{ + return crc32part(src, len, 0); +} diff --git a/nuttx/libc/misc/lib_dbg.c b/nuttx/libc/misc/lib_dbg.c new file mode 100644 index 000000000..5605ff828 --- /dev/null +++ b/nuttx/libc/misc/lib_dbg.c @@ -0,0 +1,165 @@ +/**************************************************************************** + * libc/misc/lib_dbg.c + * + * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include + +#include "lib_internal.h" + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/* Debug output is initially disabled */ + +#ifdef CONFIG_DEBUG_ENABLE +bool g_dbgenable; +#endif + +/**************************************************************************** + * Global Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: dbg_enable + * + * Description: + * Enable or disable debug output. + * + ****************************************************************************/ + +#ifdef CONFIG_DEBUG_ENABLE +void dbg_enable(bool enable) +{ + g_dbgenable = enable; +} +#endif + +/**************************************************************************** + * Name: dbg, lldbg, vdbg + * + * Description: + * If the cross-compiler's pre-processor does not support variable + * length arguments, then these additional APIs will be built. + * + ****************************************************************************/ + +#ifndef CONFIG_CPP_HAVE_VARARGS +#ifdef CONFIG_DEBUG +int dbg(const char *format, ...) +{ + va_list ap; + int ret; + +#ifdef CONFIG_DEBUG_ENABLE + ret = 0; + if (g_dbgenable) +#endif + { + va_start(ap, format); + ret = lib_rawvprintf(format, ap); + va_end(ap); + } + + return ret; +} + +#ifdef CONFIG_ARCH_LOWPUTC +int lldbg(const char *format, ...) +{ + va_list ap; + int ret; + +#ifdef CONFIG_DEBUG_ENABLE + ret = 0; + if (g_dbgenable) +#endif + { + va_start(ap, format); + ret = lib_lowvprintf(format, ap); + va_end(ap); + } + + return ret; +} +#endif + +#ifdef CONFIG_DEBUG_VERBOSE +int vdbg(const char *format, ...) +{ + va_list ap; + int ret; + +#ifdef CONFIG_DEBUG_ENABLE + ret = 0; + if (g_dbgenable) +#endif + { + va_start(ap, format); + ret = lib_rawvprintf(format, ap); + va_end(ap); + } + + return ret; +} + +#ifdef CONFIG_ARCH_LOWPUTC +int llvdbg(const char *format, ...) +{ + va_list ap; + int ret; + +#ifdef CONFIG_DEBUG_ENABLE + ret = 0; + if (g_dbgenable) +#endif + { + va_start(ap, format); + ret = lib_lowvprintf(format, ap); + va_end(ap); + } + + return ret; +} +#endif /* CONFIG_ARCH_LOWPUTC */ +#endif /* CONFIG_DEBUG_VERBOSE */ +#endif /* CONFIG_DEBUG */ +#endif /* CONFIG_CPP_HAVE_VARARGS */ diff --git a/nuttx/libc/misc/lib_dumpbuffer.c b/nuttx/libc/misc/lib_dumpbuffer.c new file mode 100644 index 000000000..52158b220 --- /dev/null +++ b/nuttx/libc/misc/lib_dumpbuffer.c @@ -0,0 +1,129 @@ +/**************************************************************************** + * libc/misc/lib_dumpbuffer.c + * + * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 +#include + +#include +#include + +/**************************************************************************** + * Pre-processor definitions + ****************************************************************************/ + +/* Select the lowest level debug interface available */ + +#ifdef CONFIG_CPP_HAVE_VARARGS +# ifdef CONFIG_ARCH_LOWPUTC +# define message(format, arg...) lib_lowprintf(format, ##arg) +# else +# define message(format, arg...) lib_rawprintf(format, ##arg) +# endif +#else +# ifdef CONFIG_ARCH_LOWPUTC +# define message lib_lowprintf +# else +# define message lib_rawprintf +# endif +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: lib_dumpbuffer + * + * Description: + * Do a pretty buffer dump + * + ****************************************************************************/ + +void lib_dumpbuffer(FAR const char *msg, FAR const uint8_t *buffer, unsigned int buflen) +{ + int i, j, k; + + message("%s (%p):\n", msg, buffer); + for (i = 0; i < buflen; i += 32) + { + message("%04x: ", i); + for (j = 0; j < 32; j++) + { + k = i + j; + + if (j == 16) + { + message(" "); + } + + if (k < buflen) + { + message("%02x", buffer[k]); + } + else + { + message(" "); + } + } + + message(" "); + for (j = 0; j < 32; j++) + { + k = i + j; + + if (j == 16) + { + message(" "); + } + + if (k < buflen) + { + if (buffer[k] >= 0x20 && buffer[k] < 0x7f) + { + message("%c", buffer[k]); + } + else + { + message("."); + } + } + } + message("\n"); + } +} diff --git a/nuttx/libc/misc/lib_filesem.c b/nuttx/libc/misc/lib_filesem.c new file mode 100644 index 000000000..5cc4624ec --- /dev/null +++ b/nuttx/libc/misc/lib_filesem.c @@ -0,0 +1,145 @@ +/************************************************************************ + * libc/misc/lib_filesem.c + * + * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include +#include +#include +#include + +#include "lib_internal.h" + +#if CONFIG_STDIO_BUFFER_SIZE > 0 + +/************************************************************************ + * Pre-processor Definitions + ************************************************************************/ + +/************************************************************************ + * Private Data + ************************************************************************/ + +/************************************************************************ + * Global Functions + ************************************************************************/ + +/************************************************************************ + * lib_sem_initialize + ************************************************************************/ + +void lib_sem_initialize(FAR struct file_struct *stream) +{ + /* Initialize the LIB semaphore to one (to support one-at- + * a-time access to private data sets. + */ + + (void)sem_init(&stream->fs_sem, 0, 1); + + stream->fs_holder = -1; + stream->fs_counts = 0; +} + +/************************************************************************ + * lib_take_semaphore + ************************************************************************/ + +void lib_take_semaphore(FAR struct file_struct *stream) +{ + pid_t my_pid = getpid(); + + /* Do I already have the semaphore? */ + + if (stream->fs_holder == my_pid) + { + /* Yes, just increment the number of references that I have */ + + stream->fs_counts++; + } + else + { + /* Take the semaphore (perhaps waiting) */ + + while (sem_wait(&stream->fs_sem) != 0) + { + /* The only case that an error should occr here is if + * the wait was awakened by a signal. + */ + + ASSERT(get_errno() == EINTR); + } + + /* We have it. Claim the stak and return */ + + stream->fs_holder = my_pid; + stream->fs_counts = 1; + } +} + +/************************************************************************ + * lib_give_semaphore + ************************************************************************/ + +void lib_give_semaphore(FAR struct file_struct *stream) +{ + pid_t my_pid = getpid(); + + /* I better be holding at least one reference to the semaphore */ + + ASSERT(stream->fs_holder == my_pid); + + /* Do I hold multiple references to the semphore */ + + if (stream->fs_counts > 1) + { + /* Yes, just release one count and return */ + + stream->fs_counts--; + } + else + { + /* Nope, this is the last reference I have */ + + stream->fs_holder = -1; + stream->fs_counts = 0; + ASSERT(sem_post(&stream->fs_sem) == 0); + } +} +#endif /* CONFIG_STDIO_BUFFER_SIZE */ diff --git a/nuttx/libc/misc/lib_init.c b/nuttx/libc/misc/lib_init.c new file mode 100644 index 000000000..6a120f7b1 --- /dev/null +++ b/nuttx/libc/misc/lib_init.c @@ -0,0 +1,207 @@ +/************************************************************ + * libc/misc/lib_init.c + * + * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include +#include + +#include +#include +#include + +#include "lib_internal.h" + +/************************************************************ + * Definitions + ************************************************************/ + +/************************************************************ + * Private Variables + ************************************************************/ + +/************************************************************ + * Private Functions + ************************************************************/ + +/************************************************************ + * Public Functions + ************************************************************/ + +/************************************************************ + * lib_initialize + ************************************************************/ + +/* General library initialization hook */ + +void weak_const_function lib_initialize(void) +{ +} + +#if CONFIG_NFILE_STREAMS > 0 +/* The following function is called when a new TCB is allocated. It + * creates the streamlist instance that is stored in the TCB. + */ + +FAR struct streamlist *lib_alloclist(void) +{ + FAR struct streamlist *list; + list = (FAR struct streamlist*)lib_zalloc(sizeof(struct streamlist)); + if (list) + { + int i; + + /* Start with a reference count of one */ + + list->sl_crefs = 1; + + /* Initialize the list access mutex */ + + (void)sem_init(&list->sl_sem, 0, 1); + + /* Initialize each FILE structure */ + + for (i = 0; i < CONFIG_NFILE_STREAMS; i++) + { + /* Clear the IOB */ + + memset(&list->sl_streams[i], 0, sizeof(FILE)); + + /* Indicate not opened */ + + list->sl_streams[i].fs_filedes = -1; + + /* Initialize the stream semaphore to one to support one-at- + * a-time access to private data sets. + */ + + lib_sem_initialize(&list->sl_streams[i]); + } + } + return list; + +} + +/* This function is called when a TCB is closed (such as with + * pthread_create(). It increases the reference count on the stream + * list. + */ + +void lib_addreflist(FAR struct streamlist *list) +{ + if (list) + { + /* Increment the reference count on the list. + * NOTE: that we disable interrupts to do this + * (vs. taking the list semaphore). We do this + * because file cleanup operations often must be + * done from the IDLE task which cannot wait + * on semaphores. + */ + + register irqstate_t flags = irqsave(); + list->sl_crefs++; + irqrestore(flags); + } +} + +/* this function is called when a TCB is destroyed. Note that is + * does not close the file by release this inode. This happens + * separately when the file descriptor list is freed. + */ + +void lib_releaselist(FAR struct streamlist *list) +{ + int crefs; + if (list) + { + /* Decrement the reference count on the list. + * NOTE: that we disable interrupts to do this + * (vs. taking the list semaphore). We do this + * because file cleanup operations often must be + * done from the IDLE task which cannot wait + * on semaphores. + */ + + register irqstate_t flags = irqsave(); + crefs = --(list->sl_crefs); + irqrestore(flags); + + /* If the count decrements to zero, then there is no reference + * to the structure and it should be deallocated. Since there + * are references, it would be an error if any task still held + * a reference to the list's semaphore. + */ + + if (crefs <= 0) + { +#if CONFIG_STDIO_BUFFER_SIZE > 0 + int i; +#endif + /* Destroy the semaphore and release the filelist */ + + (void)sem_destroy(&list->sl_sem); + + /* Release each stream in the list */ + +#if CONFIG_STDIO_BUFFER_SIZE > 0 + for (i = 0; i < CONFIG_NFILE_STREAMS; i++) + { + /* Destroy the semaphore that protects the IO buffer */ + + (void)sem_destroy(&list->sl_streams[i].fs_sem); + + /* Release the IO buffer */ + if (list->sl_streams[i].fs_bufstart) + { + sched_free(list->sl_streams[i].fs_bufstart); + } + } +#endif + /* Finally, release the list itself */ + + sched_free(list); + } + } +} + +#endif /* CONFIG_NFILE_STREAMS */ + + diff --git a/nuttx/libc/misc/lib_match.c b/nuttx/libc/misc/lib_match.c new file mode 100644 index 000000000..a8cfad329 --- /dev/null +++ b/nuttx/libc/misc/lib_match.c @@ -0,0 +1,148 @@ +/**************************************************************************** + * libc/misc/lib_match.c - simple shell-style filename matcher + * + * Simple shell-style filename pattern matcher written by Jef Poskanzer + * This pattern matcher only handles '?', '*' and '**', and multiple + * patterns separated by '|'. + * + * Copyright © 1995,2000 by Jef Poskanzer . + * All rights reserved. + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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 +#include + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: match_one + * + * Description: + * Does all of the work for one '|' delimited pattern + * + * Returned Value: + * Returns 1 (match) or 0 (no-match). + * + ****************************************************************************/ + +static int match_one(const char *pattern, int patlen, const char *string) +{ + const char *p; + int pl; + int i; + + for (p = pattern; p - pattern < patlen; p++, string++) + { + if (*p == '?' && *string != '\0') + { + continue; + } + + if (*p == '*') + { + p++; + if (*p == '*') + { + /* Double-wildcard matches anything. */ + + p++; + i = strlen(string); + } + else + { + /* Single-wildcard matches anything but slash. */ + + i = strcspn(string, "/"); + } + + pl = patlen - (p - pattern); + for (; i >= 0; i--) + { + if (match_one(p, pl, &(string[i]))) + { + return 1; + } + } + return 0; + } + + if (*p != *string) + { + return 0; + } + } + + if (*string == '\0') + { + return 1; + } + return 0; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: match + * + * Description: + * Simple shell-style filename pattern matcher written by Jef Poskanzer + * This pattern matcher only handles '?', '*' and '**', and multiple + * patterns separated by '|'. + * + * Returned Value: + * Returns 1 (match) or 0 (no-match). + * + ****************************************************************************/ + +int match(const char *pattern, const char *string) +{ + const char *or; + + for (;;) + { + or = strchr(pattern, '|'); + if (or == (char *)0) + { + return match_one(pattern, strlen(pattern), string); + } + + if (match_one(pattern, or - pattern, string)) + { + return 1; + } + + pattern = or + 1; + } +} + diff --git a/nuttx/libc/misc/lib_sendfile.c b/nuttx/libc/misc/lib_sendfile.c new file mode 100644 index 000000000..8a38dc317 --- /dev/null +++ b/nuttx/libc/misc/lib_sendfile.c @@ -0,0 +1,297 @@ +/************************************************************************ + * libc/misc/lib_streamsem.c + * + * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include +#include +#include +#include + +#if CONFIG_NSOCKET_DESCRIPTORS > 0 || CONFIG_NFILE_DESCRIPTORS > 0 + +/************************************************************************ + * Private types + ************************************************************************/ + +/************************************************************************ + * Private Variables + ************************************************************************/ + +/************************************************************************ + * Public Variables + ************************************************************************/ + +/************************************************************************ + * Private Functions + ************************************************************************/ + +/************************************************************************ + * Public Functions + ************************************************************************/ + +/************************************************************************ + * Name: sendfile + * + * Description: + * sendfile() copies data between one file descriptor and another. + * sendfile() basically just wraps a sequence of reads() and writes() + * to perform a copy. It serves a purpose in systems where there is + * a penalty for copies to between user and kernal space, but really + * nothing in NuttX but provide some Linux compatible (and adding + * another 'almost standard' interface). + * + * NOTE: This interface is *not* specified in POSIX.1-2001, or other + * standards. The implementation here is very similar to the Linux + * sendfile interface. Other UNIX systems implement sendfile() with + * different semantics and prototypes. sendfile() should not be used + * in portable programs. + * + * Input Parmeters: + * infd - A file (or socket) descriptor opened for reading + * outfd - A descriptor opened for writing. + * offset - If 'offset' is not NULL, then it points to a variable + * holding the file offset from which sendfile() will start + * reading data from 'infd'. When sendfile() returns, this + * variable will be set to the offset of the byte following + * the last byte that was read. If 'offset' is not NULL, + * then sendfile() does not modify the current file offset of + * 'infd'; otherwise the current file offset is adjusted to + * reflect the number of bytes read from 'infd.' + * + * If 'offset' is NULL, then data will be read from 'infd' + * starting at the current file offset, and the file offset + * will be updated by the call. + * count - The number of bytes to copy between the file descriptors. + * + * Returned Value: + * If the transfer was successful, the number of bytes written to outfd is + * returned. On error, -1 is returned, and errno is set appropriately. + * There error values are those returned by read() or write() plus: + * + * EINVAL - Bad input parameters. + * ENOMEM - Could not allocated an I/O buffer + * + ************************************************************************/ + +ssize_t sendfile(int outfd, int infd, off_t *offset, size_t count) +{ + FAR uint8_t *iobuffer; + FAR uint8_t *wrbuffer; + off_t startpos = 0; + ssize_t nbytesread; + ssize_t nbyteswritten; + size_t ntransferred; + bool endxfr; + + /* Get the current file position. */ + + if (offset) + { + /* Use lseek to get the current file position */ + + startpos = lseek(infd, 0, SEEK_CUR); + if (startpos == (off_t)-1) + { + return ERROR; + } + + /* Use lseek again to set the new file position */ + + if (lseek(infd, *offset, SEEK_SET) == (off_t)-1) + { + return ERROR; + } + } + + /* Allocate an I/O buffer */ + + iobuffer = (FAR void *)malloc(CONFIG_LIB_SENDFILE_BUFSIZE); + if (!iobuffer) + { + set_errno(ENOMEM); + return ERROR; + } + + /* Now transfer 'count' bytes from the infd to the outfd */ + + for (ntransferred = 0, endxfr = false; ntransferred < count && !endxfr; ) + { + /* Loop until the read side of the transfer comes to some conclusion */ + + do + { + /* Read a buffer of data from the infd */ + + nbytesread = read(infd, iobuffer, CONFIG_LIB_SENDFILE_BUFSIZE); + + /* Check for end of file */ + + if (nbytesread == 0) + { + /* End of file. Break out and return current number of bytes + * transferred. + */ + + endxfr = true; + break; + } + + /* Check for a read ERROR. EINTR is a special case. This function + * should break out and return an error if EINTR is returned and + * no data has been transferred. But what should it do if some + * data has been transferred? I suppose just continue? + */ + + else if (nbytesread < 0) + { + /* EINTR is not an error (but will still stop the copy) */ + +#ifndef CONFIG_DISABLE_SIGNALS + if (errno != EINTR || ntransferred == 0) +#endif + { + /* Read error. Break out and return the error condition. */ + + ntransferred = ERROR; + endxfr = true; + break; + } + } + } + while (nbytesread < 0); + + /* Was anything read? */ + + if (!endxfr) + { + /* Yes.. Loop until the read side of the transfer comes to some + * conclusion. + */ + + wrbuffer = iobuffer; + do + { + /* Write the buffer of data to the outfd */ + + nbyteswritten = write(outfd, wrbuffer, nbytesread); + + /* Check for a complete (or parial) write. write() should not + * return zero. + */ + + if (nbyteswritten >= 0) + { + /* Advance the buffer pointer and decrement the number of bytes + * remaining in the iobuffer. Typically, nbytesread will now + * be zero. + */ + + wrbuffer += nbyteswritten; + nbytesread -= nbyteswritten; + + /* Increment the total number of bytes successfully transferred. */ + + ntransferred += nbyteswritten; + } + + /* Otherwise an error occurred */ + + else + { + /* Check for a read ERROR. EINTR is a special case. This + * function should break out and return an error if EINTR + * is returned and no data has been transferred. But what + * should it do if some data has been transferred? I + * suppose just continue? + */ + +#ifndef CONFIG_DISABLE_SIGNALS + if (errno != EINTR || ntransferred == 0) +#endif + { + /* Write error. Break out and return the error condition */ + + ntransferred = ERROR; + endxfr = true; + break; + } + } + } + while (nbytesread > 0); + } + } + + /* Release the I/O buffer */ + + free(iobuffer); + + /* Return the current file position */ + + if (offset) + { + /* Use lseek to get the current file position */ + + off_t curpos = lseek(infd, 0, SEEK_CUR); + if (curpos == (off_t)-1) + { + return ERROR; + } + + /* Return the current file position */ + + *offset = curpos; + + /* Use lseek again to restore the original file position */ + + if (lseek(infd, startpos, SEEK_SET) == (off_t)-1) + { + return ERROR; + } + } + + /* Finally return the number of bytes actually transferred (or ERROR + * if any failure occurred). + */ + + return ntransferred; +} + +#endif /* CONFIG_NSOCKET_DESCRIPTORS > 0 || CONFIG_NFILE_DESCRIPTORS > 0 */ diff --git a/nuttx/libc/misc/lib_streamsem.c b/nuttx/libc/misc/lib_streamsem.c new file mode 100644 index 000000000..e38298bdb --- /dev/null +++ b/nuttx/libc/misc/lib_streamsem.c @@ -0,0 +1,90 @@ +/************************************************************************ + * libc/misc/lib_streamsem.c + * + * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include +#include +#include +#include +#include + +#include "lib_internal.h" + +/************************************************************************ + * Private types + ************************************************************************/ + +/************************************************************************ + * Private Variables + ************************************************************************/ + +/************************************************************************ + * Public Variables + ************************************************************************/ + +/************************************************************************ + * Private Functions + ************************************************************************/ + +/************************************************************************ + * Public Functions + ************************************************************************/ + +void stream_semtake(FAR struct streamlist *list) +{ + /* Take the semaphore (perhaps waiting) */ + + while (sem_wait(&list->sl_sem) != 0) + { + /* The only case that an error should occr here is if + * the wait was awakened by a signal. + */ + + ASSERT(get_errno() == EINTR); + } +} + +void stream_semgive(FAR struct streamlist *list) +{ + sem_post(&list->sl_sem); +} + + diff --git a/nuttx/libc/mqueue/Make.defs b/nuttx/libc/mqueue/Make.defs new file mode 100644 index 000000000..826970fa3 --- /dev/null +++ b/nuttx/libc/mqueue/Make.defs @@ -0,0 +1,48 @@ +############################################################################ +# libc/mqueue/Make.defs +# +# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# 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. +# +############################################################################ + +ifneq ($(CONFIG_DISABLE_MQUEUE),y) + +# Add the mqueue C files to the build + +CSRCS += mq_setattr.c mq_getattr.c + +# Add the mqueue directory to the build + +DEPPATH += --dep-path mqueue +VPATH += :mqueue + +endif + diff --git a/nuttx/libc/mqueue/mq_getattr.c b/nuttx/libc/mqueue/mq_getattr.c new file mode 100644 index 000000000..2fc0e131b --- /dev/null +++ b/nuttx/libc/mqueue/mq_getattr.c @@ -0,0 +1,104 @@ +/************************************************************************ + * libc/mqueue/mq_getattr.c + * + * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include + +/************************************************************************ + * Definitions + ************************************************************************/ + +/************************************************************************ + * Private Type Declarations + ************************************************************************/ + +/************************************************************************ + * Global Variables + ************************************************************************/ + +/************************************************************************ + * Private Variables + ************************************************************************/ + +/************************************************************************ + * Private Functions + ************************************************************************/ + +/************************************************************************ + * Public Functions + ************************************************************************/ + +/************************************************************************ + * Function: mq_getattr + * + * Description: + * This functions gets status information and attributes + * associated with the specified message queue. + * + * Parameters: + * mqdes - Message queue descriptor + * mq_stat - Buffer in which to return attributes + * + * Return Value: + * 0 (OK) if attributes provided, -1 (ERROR) otherwise. + * + * Assumptions: + * + ************************************************************************/ + +int mq_getattr(mqd_t mqdes, struct mq_attr *mq_stat) +{ + int ret = ERROR; + + if (mqdes && mq_stat) + { + /* Return the attributes */ + + mq_stat->mq_maxmsg = mqdes->msgq->maxmsgs; + mq_stat->mq_msgsize = mqdes->msgq->maxmsgsize; + mq_stat->mq_flags = mqdes->oflags; + mq_stat->mq_curmsgs = mqdes->msgq->nmsgs; + + ret = OK; + } + + return ret; +} diff --git a/nuttx/libc/mqueue/mq_setattr.c b/nuttx/libc/mqueue/mq_setattr.c new file mode 100644 index 000000000..45a848e6d --- /dev/null +++ b/nuttx/libc/mqueue/mq_setattr.c @@ -0,0 +1,118 @@ +/************************************************************************ + * libc/mqueue/mq_setattr.c + * + * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include /* O_NONBLOCK */ +#include + +#include + +/************************************************************************ + * Definitions + ************************************************************************/ + +/************************************************************************ + * Private Type Declarations + ************************************************************************/ + +/************************************************************************ + * Global Variables + ************************************************************************/ + +/************************************************************************ + * Private Variables + ************************************************************************/ + +/************************************************************************ + * Private Functions + ************************************************************************/ + +/************************************************************************ + * Public Functions + ************************************************************************/ + +/************************************************************************ + * Function: mq_setattr + * + * Description: + * This function sets the attributes associated with the + * specified message queue "mqdes." Only the "O_NONBLOCK" + * bit of the "mq_flags" can be changed. + * + * If "oldstat" is non-null, mq_setattr() will store the + * previous message queue attributes at that location (just + * as would have been returned by mq_getattr()). + * + * Parameters: + * mqdes - Message queue descriptor + * mq_stat - New attributes + * oldstate - Old attributes + * + * Return Value: + * 0 (OK) if attributes are set successfully, otherwise + * -1 (ERROR). + * + * Assumptions: + * + ************************************************************************/ + +int mq_setattr(mqd_t mqdes, const struct mq_attr *mq_stat, + struct mq_attr *oldstat) +{ + int ret = ERROR; + + if (mqdes && mq_stat) + { + /* Return the attributes if so requested */ + + if (oldstat) + { + (void)mq_getattr(mqdes, oldstat); + } + + /* Set the new value of the O_NONBLOCK flag. */ + + mqdes->oflags = ((mq_stat->mq_flags & O_NONBLOCK) | + (mqdes->oflags & (~O_NONBLOCK))); + ret = OK; + } + + return ret; +} diff --git a/nuttx/libc/net/Make.defs b/nuttx/libc/net/Make.defs new file mode 100644 index 000000000..9d4e5c06b --- /dev/null +++ b/nuttx/libc/net/Make.defs @@ -0,0 +1,44 @@ +############################################################################ +# libc/net/Make.defs +# +# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# 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. +# +############################################################################ + +# Add the networking C files to the build + +CSRCS += lib_etherntoa.c lib_htons.c lib_htonl.c lib_inetaddr.c +CSRCS += lib_inetntoa.c lib_inetntop.c lib_inetpton.c + +# Add the net directory to the build + +DEPPATH += --dep-path net +VPATH += :net diff --git a/nuttx/libc/net/lib_etherntoa.c b/nuttx/libc/net/lib_etherntoa.c new file mode 100644 index 000000000..91fb01c57 --- /dev/null +++ b/nuttx/libc/net/lib_etherntoa.c @@ -0,0 +1,69 @@ +/**************************************************************************** + * libc/net/lib_etherntoa.c + * + * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 +#include + +#include +#include + +/**************************************************************************** + * Global Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: ether_ntoa + * + * Description: + * The ether_ntoa() function converts the Ethernet host address addr given + * in network byte order to a string in standard hex-digits-and-colons + * notation. The string is returned in a statically allocated buffer, which + * subsequent calls will overwrite. + * + ****************************************************************************/ + +FAR char *ether_ntoa(FAR const struct ether_addr *addr) +{ + static char buffer[20]; + sprintf(buffer, "%02x:%02x:%02x:%02x:%02x:%02x", + addr->ether_addr_octet[0], addr->ether_addr_octet[1], + addr->ether_addr_octet[2], addr->ether_addr_octet[3], + addr->ether_addr_octet[4], addr->ether_addr_octet[5]); + return buffer; +} diff --git a/nuttx/libc/net/lib_htonl.c b/nuttx/libc/net/lib_htonl.c new file mode 100644 index 000000000..a10f54f37 --- /dev/null +++ b/nuttx/libc/net/lib_htonl.c @@ -0,0 +1,68 @@ +/************************************************************ + * libc/net/lib_ntohl.c + * + * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include + +/************************************************************ + * Global Functions + ************************************************************/ + +uint32_t htonl(uint32_t hl) +{ +#ifdef CONFIG_ENDIAN_BIG + return hl; +#else + return (( (hl) >> 24) | + (((hl) >> 8) & 0x0000ff00) | + (((hl) << 8) & 0x00ff0000) | + ( (hl) << 24)); +#endif +} + +uint32_t ntohl(uint32_t nl) +{ +#ifdef CONFIG_ENDIAN_BIG + return nl; +#else + return htonl(nl); +#endif +} diff --git a/nuttx/libc/net/lib_htons.c b/nuttx/libc/net/lib_htons.c new file mode 100644 index 000000000..13addd913 --- /dev/null +++ b/nuttx/libc/net/lib_htons.c @@ -0,0 +1,65 @@ +/*************************************************************************** + * libc/net/lib_htons.c + * + * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ***************************************************************************/ + +/*************************************************************************** + * Compilation Switches + ***************************************************************************/ + +/*************************************************************************** + * Included Files + ***************************************************************************/ + +#include + +#include +#include + +/*************************************************************************** + * Global Functions + ***************************************************************************/ + +uint16_t htons(uint16_t hs) +{ + return HTONS(hs); +} + +uint16_t ntohs(uint16_t ns) +{ +#ifdef CONFIG_ENDIAN_BIG + return ns; +#else + return htons(ns); +#endif +} diff --git a/nuttx/libc/net/lib_inetaddr.c b/nuttx/libc/net/lib_inetaddr.c new file mode 100644 index 000000000..46c6c548d --- /dev/null +++ b/nuttx/libc/net/lib_inetaddr.c @@ -0,0 +1,74 @@ +/**************************************************************************** + * libc/net/lib_inetaddr.c + * + * Copyright (C) 2011 Yu Qiang. All rights reserved. + * Author: Yu Qiang + * + * This file is a part of NuttX: + * + * Copyright (C) 2011 Gregory Nutt. All rights reserved. + * + * 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 +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * name inet_addr + * + * Description: + * The inet_addr() function converts the string pointed to by cp, in the + * standard IPv4 dotted decimal notation, to an integer value suitable for + * use as an Internet address. + + ****************************************************************************/ + +in_addr_t inet_addr(FAR const char *cp) +{ + unsigned int a, b, c, d; + uint32_t result; + + sscanf(cp, "%u.%u.%u.%u", &a, &b, &c, &d); + result = a << 8; + result |= b; + result <<= 8; + result |= c; + result <<= 8; + result |= d; + return HTONL(result); +} diff --git a/nuttx/libc/net/lib_inetntoa.c b/nuttx/libc/net/lib_inetntoa.c new file mode 100644 index 000000000..e2d92d864 --- /dev/null +++ b/nuttx/libc/net/lib_inetntoa.c @@ -0,0 +1,79 @@ +/**************************************************************************** + * libc/net/lib_inetntoa.c + * + * Copyright (C) 2007-2008, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 +#include +#include + +#ifndef CONFIG_NET_IPv6 + +/**************************************************************************** + * Global Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: inet_ntoa + * + * Description: + * The inet_ntoa() function converts the Internet host address in given in + * network byte order to a string in standard numbers-and-dots notation. + * The string is returned in a statically allocated buffer, which subsequent + * calls will overwrite. + * + ****************************************************************************/ + +#ifdef CONFIG_CAN_PASS_STRUCTS +FAR char *inet_ntoa(struct in_addr in) +{ + static char buffer[INET_ADDRSTRLEN+2]; + FAR char *ptr = (FAR char*)&in.s_addr; + sprintf(buffer, "%d.%d.%d.%d", ptr[0], ptr[1], ptr[2], ptr[3]); + return buffer; +} +#else +FAR char *_inet_ntoa(in_addr_t in) +{ + static char buffer[INET_ADDRSTRLEN+2]; + FAR char *ptr = (FAR char*)∈ + sprintf(buffer, "%d.%d.%d.%d", ptr[0], ptr[1], ptr[2], ptr[3]); + return buffer; +} +#endif +#endif /* !CONFIG_NET_IPv6 */ + diff --git a/nuttx/libc/net/lib_inetntop.c b/nuttx/libc/net/lib_inetntop.c new file mode 100644 index 000000000..25c32c48c --- /dev/null +++ b/nuttx/libc/net/lib_inetntop.c @@ -0,0 +1,202 @@ +/**************************************************************************** + * libc/net/lib_inetntop.c + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Includes some logic extracted from hwport_ftpd, written by Jaehyuk Cho + * which was released under the BSD license. + * + * Copyright (C) HWPORT.COM. All rights reserved. + * Author: JAEHYUK CHO + * + * 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 + +#include + +#include +#include +#include + +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: inet_ntop + * + * Description: + * The inet_ntop() function converts a numeric address into a text string + * suitable for presentation. + * + * Input Parameters: + * af - The af argument specifies the family of the address. This can be + * AF_INET or AF_INET6. + * src - The src argument points to a buffer holding an address of the + * specified type. The address must be in network byte order. + * dst - The dst argument points to a buffer where the function stores + * the resulting text string; it shall not be NULL. + * size - The size argument specifies the size of this buffer, which must + * be large enough to hold the text string (INET_ADDRSTRLEN + * characters for IPv4, INET6_ADDRSTRLEN characters for IPv6). + * + * Returned Value: + * inet_ntop() returns a pointer to the buffer containing the text string + * if the conversion succeeds. Otherwise, NULL is returned and the errno + * is set to indicate the error. There follow errno values may be set: + * + * EAFNOSUPPORT - The af argument is invalid. + * ENOSPC - The size of the inet_ntop() result buffer is inadequate + * + ****************************************************************************/ + +FAR const char *inet_ntop(int af, FAR const void *src, FAR char *dst, socklen_t size) +{ + int errval; +#ifndef CONFIG_NET_IPv6 + FAR char *ptr; + + DEBUGASSERT(src && dst); + + if (af != AF_INET) + { + errval = EAFNOSUPPORT; + goto errout; + } + + if (size < INET_ADDRSTRLEN) + { + errval = ENOSPC; + goto errout; + } + + ptr = (FAR char*)src; + sprintf(dst, "%d.%d.%d.%d", ptr[0], ptr[1], ptr[2], ptr[3]); + return dst; +#else + FAR const struct in6_addr *in6_addr; + uint16_t warray[8]; + int offset; + int entry; + int count; + int maxentry; + int maxcount; + + DEBUGASSERT(src && dst); + + if (af != AF_INET6) + { + errval = EAFNOSUPPORT; + goto errout; + } + + if (size < INET6_ADDRSTRLEN) + { + errval = ENOSPC; + goto errout; + } + + in6_addr = (FAR const struct in6_addr *)src; + entry = -1; + maxentry = -1; + maxcount = 0; + offset = 0; + + while (offset < 8) + { + warray[offset] = ntohs(in6_addr->s6_addr16[offset]); + if (warray[offset] == 0) + { + entry = offset; + count = 1; + offset++; + + while (offset < 8) + { + warray[offset] = ntohs(in6_addr->s6_addr16[offset]); + if (warray[offset] != 0) + { + break; + } + offset++; + count++; + } + + if (count > maxcount) + { + maxentry = entry; + maxcount = count; + } + } + offset++; + } + + offset = 0; + dst[0] = '\0'; + + while (offset < 8) + { + if (offset == maxentry) + { + size -= snprintf(&dst[strlen(dst)], size, ":"); + offset += maxcount; + if (offset >= 8) + { + size -= snprintf(&dst[strlen(dst)], size, ":"); + } + } + else + { + if (offset > 0) + { + size -= snprintf(&dst[strlen(dst)], size, ":"); + } + + size -= snprintf(&dst[strlen(dst)], size, "%x", warray[offset]); + offset++; + } + } + + return dst; +#endif + +errout: + set_errno(errval); + memset(dst, 0, size); + return NULL; +} diff --git a/nuttx/libc/net/lib_inetpton.c b/nuttx/libc/net/lib_inetpton.c new file mode 100644 index 000000000..c5f117535 --- /dev/null +++ b/nuttx/libc/net/lib_inetpton.c @@ -0,0 +1,338 @@ +/**************************************************************************** + * libc/net/lib_inetpton.c + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Includes some logic extracted from hwport_ftpd, written by Jaehyuk Cho + * which was released under the BSD license. + * + * Copyright (C) HWPORT.COM. All rights reserved. + * Author: JAEHYUK CHO + * + * 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 + +#include + +#include +#include +#include +#include + +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: inet_pton + * + * Description: + * The inet_pton() function converts an address in its standard text + * presentation form into its numeric binary form. + * + * If the af argument of inet_pton() is AF_INET, the src string will be + * in the standard IPv4 dotted-decimal form: + * + * ddd.ddd.ddd.ddd + * + * where "ddd" is a one to three digit decimal number between 0 and 255. + * + * If the af argument of inet_pton() is AF_INET6, the src string will be in + * one of the following standard IPv6 text forms: + * + * 1. The preferred form is "x:x:x:x:x:x:x:x", where the 'x' s are the + * hexadecimal values of the eight 16-bit pieces of the address. Leading + * zeros in individual fields can be omitted, but there must be at least + * one numeral in every field. + * + * 2. A string of contiguous zero fields in the preferred form can be shown + * as "::". The "::" can only appear once in an address. Unspecified + * addresses ( "0:0:0:0:0:0:0:0" ) may be represented simply as "::". + * + * 3. A third form that is sometimes more convenient when dealing with a + * mixed environment of IPv4 and IPv6 nodes is "x:x:x:x:x:x:d.d.d.d", + * where the 'x' s are the hexadecimal values of the six high-order + * 16-bit pieces of the address, and the 'd' s are the decimal values + * of the four low-order 8-bit pieces of the address (standard IPv4 + * representation). + * + * Input Parameters: + * af - The af argument specifies the family of the address. This can be + * AF_INET or AF_INET6. + * src - The src argument points to the string being passed in. + * dst - The dst argument points to a numstr into which the function stores + * the numeric address; this must be large enough to hold the numeric + * address (32 bits for AF_INET, 128 bits for AF_INET6). + * + * Returned Value: + * The inet_pton() function returns 1 if the conversion succeeds, with the + * address pointed to by dst in network byte order. It will return 0 if the + * input is not a valid IPv4 dotted-decimal string or a valid IPv6 address + * string, or -1 with errno set to EAFNOSUPPOR] if the af argument is unknown. + * + ****************************************************************************/ + +int inet_pton(int af, FAR const char *src, FAR void *dst) +{ +#ifndef CONFIG_NET_IPv6 + size_t srcoffset; + size_t numoffset; + int value; + int ndots; + uint8_t ch; + char numstr[4]; + uint8_t *ip; + + DEBUGASSERT(src && dst); + + if (af != AF_INET) + { + set_errno(EAFNOSUPPORT); + return -1; + } + + (void)memset(dst, 0, sizeof(struct in_addr)); + + ip = (uint8_t *)dst; + srcoffset = 0; + numoffset = 0; + ndots = 0; + + for(;;) + { + ch = (uint8_t)src[srcoffset++]; + + if (ch == '.' || ch == '\0') + { + if (ch == '.' && ndots >= 4) + { + /* Too many dots */ + + break; + } + + if (numoffset <= 0) + { + /* Empty numeric string */ + + break; + } + + numstr[numoffset] = '\0'; + numoffset = 0; + + value = atoi(numstr); + if (value < 0 || value > 255) + { + /* Out of range value */ + + break; + } + + ip[ndots] = (uint8_t)value; + + if (ch == '\0') + { + if (ndots != 3) + { + /* Not enough dots */ + + break; + } + + /* Return 1 if the conversion succeeds */ + + return 1; + } + + ndots++; + } + else if (ch >= '0' && ch <= '9') + { + numstr[numoffset++] = ch; + if (numoffset >= 4) + { + /* Number is too long */ + + break; + } + } + else + { + /* Illegal character */ + + break; + } + } + + /* Return zero if there is any problem parsing the input */ + + return 0; +#else + size_t srcoffset; + size_t numoffset; + long value; + int nsep; + int nrsep; + uint8_t ch; + char numstr[5]; + uint8_t ip[sizeof(struct in6_addr)]; + uint8_t rip[sizeof(struct in6_addr)]; + bool rtime; + + DEBUGASSERT(src && dst); + + if (af != AF_INET6) + { + set_errno(EAFNOSUPPORT); + return -1; + } + + (void)memset(dst, 0, sizeof(struct in6_addr)); + + srcoffset = 0; + numoffset = 0; + nsep = 0; + nrsep = 0; + rtime = false; + + for(;;) + { + ch = (uint8_t)src[srcoffset++]; + + if (ch == ':' || ch == '\0') + { + if (ch == ':' && (nsep + nrsep) >= 8) + { + /* Too many separators */ + + break; + } + + if (ch != '\0' && numoffset <= 0) + { + /* Empty numeric string */ + + if (rtime && nrsep > 1) + { + /* dup simple */ + + break; + } + + numoffset = 0; + rtime = true; + continue; + } + + numstr[numoffset] = '\0'; + numoffset = 0; + + value = strtol(numstr, NULL, 16); + if (value < 0 || value > 0xffff) + { + /* Out of range value */ + + break; + } + + if (!rtime) + { + ip[(nsep << 1) + 0] = (uint8_t)((value >> 8) & 0xff); + ip[(nsep << 1) + 1] = (uint8_t)((value >> 0) & 0xff); + nsep++; + } + else + { + rip[(nrsep << 1) + 0] = (uint8_t)((value >> 8) & 0xff); + rip[(nrsep << 1) + 1] = (uint8_t)((value >> 0) & 0xff); + nrsep++; + } + + if (ch == '\0' /* || ch == '/' */) + { + if ((nsep <= 1 && nrsep <= 0) || + (nsep + nrsep) < 1 || + (nsep + nrsep) > 8) + { + /* Separator count problem */ + + break; + } + + if (nsep > 0) + { + memcpy(dst, &ip[0], nsep << 1); + } + + if (nrsep > 0) + { + memcpy(dst + (16 - (nrsep << 1)), &rip[0], nrsep << 1); + } + + /* Return 1 if the conversion succeeds */ + + return 1; + } + } + else if ((ch >= '0' && ch <= '9') || + (ch >= 'a' && ch <= 'f') || + (ch >= 'A' && ch <= 'F')) + { + numstr[numoffset++] = ch; + if (numoffset >= 5) + { + /* Numeric string is too long */ + + break; + } + } + else + { + /* Illegal character */ + + break; + } + } + + + /* Return zero if there is any problem parsing the input */ + + return 0; +#endif +} diff --git a/nuttx/libc/pthread/Make.defs b/nuttx/libc/pthread/Make.defs new file mode 100644 index 000000000..07e4f0570 --- /dev/null +++ b/nuttx/libc/pthread/Make.defs @@ -0,0 +1,56 @@ +############################################################################ +# libc/pthread/Make.defs +# +# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# 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. +# +############################################################################ + +# Add the pthread C files to the build + +CSRCS += pthread_attrinit.c pthread_attrdestroy.c \ + pthread_attrsetschedpolicy.c pthread_attrgetschedpolicy.c \ + pthread_attrsetinheritsched.c pthread_attrgetinheritsched.c \ + pthread_attrsetstacksize.c pthread_attrgetstacksize.c \ + pthread_attrsetschedparam.c pthread_attrgetschedparam.c \ + pthread_barrierattrinit.c pthread_barrierattrdestroy.c \ + pthread_barrierattrgetpshared.c pthread_barrierattrsetpshared.c \ + pthread_condattrinit.c pthread_condattrdestroy.c \ + pthread_mutexattrinit.c pthread_mutexattrdestroy.c \ + pthread_mutexattrgetpshared.c pthread_mutexattrsetpshared.c + +ifeq ($(CONFIG_MUTEX_TYPES),y) +CSRCS += pthread_mutexattrsettype.c pthread_mutexattrgettype.c +endif + +# Add the pthread directory to the build + +DEPPATH += --dep-path pthread +VPATH += :pthread diff --git a/nuttx/libc/pthread/pthread_attrdestroy.c b/nuttx/libc/pthread/pthread_attrdestroy.c new file mode 100644 index 000000000..37ad46ebc --- /dev/null +++ b/nuttx/libc/pthread/pthread_attrdestroy.c @@ -0,0 +1,108 @@ +/**************************************************************************** + * libc/pthread/pthread_attrdestroy.c + * + * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include +#include +#include + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: pthread_attr_destroy + * + * Description: + * An attributes object can be deleted when it is no longer + * needed. + * + * Parameters: + * attr + * + * Return Value: + * 0 meaning success + * + * Assumptions: + * + ****************************************************************************/ + +int pthread_attr_destroy(FAR pthread_attr_t *attr) +{ + int ret; + + sdbg("attr=0x%p\n", attr); + + if (!attr) + { + ret = EINVAL; + } + else + { + memset(attr, 0, sizeof(pthread_attr_t)); + ret = OK; + } + + sdbg("Returning %d\n", ret); + return ret; +} + + diff --git a/nuttx/libc/pthread/pthread_attrgetinheritsched.c b/nuttx/libc/pthread/pthread_attrgetinheritsched.c new file mode 100644 index 000000000..6ec8ae71f --- /dev/null +++ b/nuttx/libc/pthread/pthread_attrgetinheritsched.c @@ -0,0 +1,111 @@ +/**************************************************************************** + * libc/pthread/pthread_attrgetinheritsched.c + * + * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include +#include +#include + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: pthread_attr_getinheritsched + * + * Description: + * Report whether the scheduling info in the pthread + * attributes will be used or if the thread will + * inherit the properties of the parent. + * + * Parameters: + * attr + * inheritsched + * + * Return Value: + * 0 if successful. Otherwise, an error code. + * + * Assumptions: + * + ****************************************************************************/ + +int pthread_attr_getinheritsched(FAR const pthread_attr_t *attr, + FAR int *inheritsched) +{ + int ret; + + sdbg("attr=0x%p inheritsched=0x%p\n", attr, inheritsched); + + if (!attr || !inheritsched) + { + ret = EINVAL; + } + else + { + *inheritsched = (int)attr->inheritsched; + ret = OK; + } + + sdbg("Returning %d\n", ret); + return ret; +} + + diff --git a/nuttx/libc/pthread/pthread_attrgetschedparam.c b/nuttx/libc/pthread/pthread_attrgetschedparam.c new file mode 100644 index 000000000..6bcc9618e --- /dev/null +++ b/nuttx/libc/pthread/pthread_attrgetschedparam.c @@ -0,0 +1,110 @@ +/**************************************************************************** + * libc/pthread/pthread_attrgetschedparam.c + * + * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include +#include +#include +#include + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: pthread_attr_getschedparam + * + * Description: + * + * Parameters: + * attr + * param + * + * Return Value: + * 0 if successful. Otherwise, an error code. + * + * Assumptions: + * + ****************************************************************************/ + +int pthread_attr_getschedparam(FAR pthread_attr_t *attr, + FAR struct sched_param *param) +{ + int ret; + + sdbg("attr=0x%p param=0x%p\n", attr, param); + + if (!attr || !param) + { + ret = EINVAL; + } + else + { + param->sched_priority = attr->priority; + ret = OK; + } + + sdbg("Returning %d\n", ret); + return ret; +} + + + diff --git a/nuttx/libc/pthread/pthread_attrgetschedpolicy.c b/nuttx/libc/pthread/pthread_attrgetschedpolicy.c new file mode 100644 index 000000000..8845e2bd8 --- /dev/null +++ b/nuttx/libc/pthread/pthread_attrgetschedpolicy.c @@ -0,0 +1,105 @@ +/**************************************************************************** + * libc/pthread/pthread_attrgetschedpolicy.c + * + * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 +#include +#include +#include +#include + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: pthread_attr_getschedpolicy + * + * Description: + * Obtain the scheduling algorithm attribute. + * + * Parameters: + * attr + * policy + * + * Return Value: + * 0 if successful. Otherwise, an error code. + * + * Assumptions: + * + ****************************************************************************/ + +int pthread_attr_getschedpolicy(FAR pthread_attr_t *attr, int *policy) +{ + int ret; + + sdbg("attr=0x%p policy=0x%p\n", attr, policy); + + if (!attr || !policy) + { + ret = EINVAL; + } + else + { + *policy = attr->policy; + ret = OK; + } + + sdbg("Returning %d\n", ret); + return ret; +} diff --git a/nuttx/libc/pthread/pthread_attrgetstacksize.c b/nuttx/libc/pthread/pthread_attrgetstacksize.c new file mode 100644 index 000000000..9fde29e81 --- /dev/null +++ b/nuttx/libc/pthread/pthread_attrgetstacksize.c @@ -0,0 +1,106 @@ +/**************************************************************************** + * libc/pthread/pthread_attrgetstacksize.c + * + * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 +#include +#include +#include +#include + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: pthread_attr_getstacksize + * + * Description: + * + * Parameters: + * attr + * stacksize + * + * Return Value: + * 0 if successful. Otherwise, an error code. + * + * Assumptions: + * + ****************************************************************************/ + +int pthread_attr_getstacksize(FAR pthread_attr_t *attr, FAR long *stacksize) +{ + int ret; + + sdbg("attr=0x%p stacksize=0x%p\n", attr, stacksize); + + if (!stacksize) + { + ret = EINVAL; + } + else + { + *stacksize = attr->stacksize; + ret = OK; + } + + sdbg("Returning %d\n", ret); + return ret; +} + + diff --git a/nuttx/libc/pthread/pthread_attrinit.c b/nuttx/libc/pthread/pthread_attrinit.c new file mode 100644 index 000000000..427a582b9 --- /dev/null +++ b/nuttx/libc/pthread/pthread_attrinit.c @@ -0,0 +1,123 @@ +/**************************************************************************** + * libc/pthread/pthread_attrinit.c + * + * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include +#include +#include + +#include + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/* Default pthread attributes (see included/nuttx/pthread.h). When configured + * to build separate kernel- and user-address spaces, this global is + * duplicated in each address spaced. This copy can only be shared within + * the user address space. + */ + +#if defined(CONFIG_NUTTX_KERNEL) && !defined(__KERNEL__) +pthread_attr_t g_default_pthread_attr = PTHREAD_ATTR_INITIALIZER; +#endif + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: pthread_attr_init + * + * Description: + * Initializes a thread attributes object (attr) with + * default values for all of the individual attributes + * used by a given implementation. + * + * Parameters: + * attr + * + * Return Value: + * 0 on success, otherwise an error number + * + * Assumptions: + * + ****************************************************************************/ + +int pthread_attr_init(FAR pthread_attr_t *attr) +{ + int ret = OK; + + sdbg("attr=0x%p\n", attr); + if (!attr) + { + ret = ENOMEM; + } + else + { + /* Set the child thread priority to be the default + * priority. Set the child stack size to some arbitrary + * default value. + */ + + memcpy(attr, &g_default_pthread_attr, sizeof(pthread_attr_t)); + } + + sdbg("Returning %d\n", ret); + return ret; +} + diff --git a/nuttx/libc/pthread/pthread_attrsetinheritsched.c b/nuttx/libc/pthread/pthread_attrsetinheritsched.c new file mode 100644 index 000000000..1102fe176 --- /dev/null +++ b/nuttx/libc/pthread/pthread_attrsetinheritsched.c @@ -0,0 +1,113 @@ +/**************************************************************************** + * libc/pthread/pthread_attrsetinheritsched.c + * + * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include +#include +#include +#include + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: pthread_attr_setinheritsched + * + * Description: + * Indicate whether the scheduling info in the pthread + * attributes will be used or if the thread will + * inherit the properties of the parent. + * + * Parameters: + * attr + * policy + * + * Return Value: + * 0 if successful. Otherwise, an error code. + * + * Assumptions: + * + ****************************************************************************/ + +int pthread_attr_setinheritsched(FAR pthread_attr_t *attr, + int inheritsched) +{ + int ret; + + sdbg("inheritsched=%d\n", inheritsched); + + if (!attr || + (inheritsched != PTHREAD_INHERIT_SCHED && + inheritsched != PTHREAD_EXPLICIT_SCHED)) + { + ret = EINVAL; + } + else + { + attr->inheritsched = (uint8_t)inheritsched; + ret = OK; + } + + sdbg("Returning %d\n", ret); + return ret; +} + diff --git a/nuttx/libc/pthread/pthread_attrsetschedparam.c b/nuttx/libc/pthread/pthread_attrsetschedparam.c new file mode 100644 index 000000000..587d62206 --- /dev/null +++ b/nuttx/libc/pthread/pthread_attrsetschedparam.c @@ -0,0 +1,108 @@ +/**************************************************************************** + * libc/pthread/pthread_attrsetschedparam.c + * + * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include +#include +#include +#include + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: pthread_attr_setschedparam + * + * Description: + * + * Parameters: + * attr + * param + * + * Return Value: + * 0 if successful. Otherwise, an error code. + * + * Assumptions: + * + ****************************************************************************/ + +int pthread_attr_setschedparam(FAR pthread_attr_t *attr, + FAR const struct sched_param *param) +{ + int ret; + + sdbg("attr=0x%p param=0x%p\n", attr, param); + + if (!attr || !param) + { + ret = EINVAL; + } + else + { + attr->priority = (short)param->sched_priority; + ret = OK; + } + sdbg("Returning %d\n", ret); + return ret; +} + + diff --git a/nuttx/libc/pthread/pthread_attrsetschedpolicy.c b/nuttx/libc/pthread/pthread_attrsetschedpolicy.c new file mode 100644 index 000000000..e1d1c8619 --- /dev/null +++ b/nuttx/libc/pthread/pthread_attrsetschedpolicy.c @@ -0,0 +1,111 @@ +/**************************************************************************** + * libc/pthread/pthread_attrsetschedpolicy.c + * + * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include +#include +#include +#include + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: pthread_attr_setschedpolicy + * + * Description: + * Set the scheduling algorithm attribute. + * + * Parameters: + * attr + * policy + * + * Return Value: + * 0 if successful. Otherwise, an error code. + * + * Assumptions: + * + ****************************************************************************/ + +int pthread_attr_setschedpolicy(FAR pthread_attr_t *attr, int policy) +{ + int ret; + + sdbg("attr=0x%p policy=%d\n", attr, policy); + +#if CONFIG_RR_INTERVAL > 0 + if (!attr || (policy != SCHED_FIFO && policy != SCHED_RR)) +#else + if (!attr || policy != SCHED_FIFO ) +#endif + { + ret = EINVAL; + } + else + { + attr->policy = policy; + ret = OK; + } + + sdbg("Returning %d\n", ret); + return ret; +} diff --git a/nuttx/libc/pthread/pthread_attrsetstacksize.c b/nuttx/libc/pthread/pthread_attrsetstacksize.c new file mode 100644 index 000000000..fca993baf --- /dev/null +++ b/nuttx/libc/pthread/pthread_attrsetstacksize.c @@ -0,0 +1,106 @@ +/**************************************************************************** + * libc/pthread/pthread_attrsetstacksize.c + * + * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include +#include +#include + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: pthread_attr_setstacksize + * + * Description: + * + * Parameters: + * attr + * stacksize + * + * Return Value: + * 0 if successful. Otherwise, an error code. + * + * Assumptions: + * + ****************************************************************************/ + +int pthread_attr_setstacksize(FAR pthread_attr_t *attr, long stacksize) +{ + int ret; + + sdbg("attr=0x%p stacksize=%ld\n", attr, stacksize); + + if (!attr || stacksize < PTHREAD_STACK_MIN) + { + ret = EINVAL; + } + else + { + attr->stacksize = stacksize; + ret = OK; + } + + sdbg("Returning %d\n", ret); + return ret; +} + diff --git a/nuttx/libc/pthread/pthread_barrierattrdestroy.c b/nuttx/libc/pthread/pthread_barrierattrdestroy.c new file mode 100644 index 000000000..5519caa61 --- /dev/null +++ b/nuttx/libc/pthread/pthread_barrierattrdestroy.c @@ -0,0 +1,102 @@ +/******************************************************************************** + * libc/pthread/pthread_barrierattrdestroy.c + * + * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include +#include + +/******************************************************************************** + * Definitions + ********************************************************************************/ + +/******************************************************************************** + * Private Type Declarations + ********************************************************************************/ + +/******************************************************************************** + * Global Variables + ********************************************************************************/ + +/******************************************************************************** + * Private Variables + ********************************************************************************/ + +/******************************************************************************** + * Private Function Prototypes + ********************************************************************************/ + +/******************************************************************************** + * Public Functions + ********************************************************************************/ + +/******************************************************************************** + * Function: pthread_barrierattr_destroy + * + * Description: + * The pthread_barrierattr_destroy() function will destroy a barrier attributes + * object. A destroyed attr attributes object can be reinitialized using + * pthread_barrierattr_init(); the results of otherwise referencing the object + * after it has been destroyed are undefined. + * + * Parameters: + * attr - barrier attributes to be destroyed. + * + * Return Value: + * 0 (OK) on success or EINVAL if attr is invalid. + * + * Assumptions: + * + ********************************************************************************/ + +int pthread_barrierattr_destroy(FAR pthread_barrierattr_t *attr) +{ + int ret = OK; + + if (!attr) + { + ret = EINVAL; + } + else + { + attr->pshared = PTHREAD_PROCESS_PRIVATE; + } + return ret; +} diff --git a/nuttx/libc/pthread/pthread_barrierattrgetpshared.c b/nuttx/libc/pthread/pthread_barrierattrgetpshared.c new file mode 100644 index 000000000..83faffae0 --- /dev/null +++ b/nuttx/libc/pthread/pthread_barrierattrgetpshared.c @@ -0,0 +1,101 @@ +/******************************************************************************** + * libc/pthread/pthread_barrierattrgetpshared.c + * + * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include +#include + +/******************************************************************************** + * Definitions + ********************************************************************************/ + +/******************************************************************************** + * Private Type Declarations + ********************************************************************************/ + +/******************************************************************************** + * Global Variables + ********************************************************************************/ + +/******************************************************************************** + * Private Variables + ********************************************************************************/ + +/******************************************************************************** + * Private Function Prototypes + ********************************************************************************/ + +/******************************************************************************** + * Public Functions + ********************************************************************************/ + +/******************************************************************************** + * Function: pthread_barrierattr_getpshared + * + * Description: + * The pthread_barrierattr_getpshared() function will obtain the value of the + * process-shared attribute from the attributes object referenced by attr. + * + * Parameters: + * attr - barrier attributes to be queried. + * pshared - the location to stored the current value of the pshared attribute. + * + * Return Value: + * 0 (OK) on success or EINVAL if either attr or pshared is invalid. + * + * Assumptions: + * + ********************************************************************************/ + +int pthread_barrierattr_getpshared(FAR const pthread_barrierattr_t *attr, FAR int *pshared) +{ + int ret = OK; + + if (!attr || !pshared) + { + ret = EINVAL; + } + else + { + *pshared = attr->pshared; + } + return ret; +} diff --git a/nuttx/libc/pthread/pthread_barrierattrinit.c b/nuttx/libc/pthread/pthread_barrierattrinit.c new file mode 100644 index 000000000..7ab101883 --- /dev/null +++ b/nuttx/libc/pthread/pthread_barrierattrinit.c @@ -0,0 +1,101 @@ +/******************************************************************************** + * libc/pthread/pthread_barrierattrinit.c + * + * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include +#include + +/******************************************************************************** + * Definitions + ********************************************************************************/ + +/******************************************************************************** + * Private Type Declarations + ********************************************************************************/ + +/******************************************************************************** + * Global Variables + ********************************************************************************/ + +/******************************************************************************** + * Private Variables + ********************************************************************************/ + +/******************************************************************************** + * Private Function Prototypes + ********************************************************************************/ + +/******************************************************************************** + * Public Functions + ********************************************************************************/ + +/******************************************************************************** + * Function: pthread_barrierattr_init + * + * Description: + * The pthread_barrierattr_init() function will initialize a barrier attribute + * object attr with the default value for all of the attributes defined by the + * implementation. + * + * Parameters: + * attr - barrier attributes to be initialized. + * + * Return Value: + * 0 (OK) on success or EINVAL if attr is invalid. + * + * Assumptions: + * + ********************************************************************************/ + +int pthread_barrierattr_init(FAR pthread_barrierattr_t *attr) +{ + int ret = OK; + + if (!attr) + { + ret = EINVAL; + } + else + { + attr->pshared = PTHREAD_PROCESS_PRIVATE; + } + return ret; +} diff --git a/nuttx/libc/pthread/pthread_barrierattrsetpshared.c b/nuttx/libc/pthread/pthread_barrierattrsetpshared.c new file mode 100644 index 000000000..2585de7a0 --- /dev/null +++ b/nuttx/libc/pthread/pthread_barrierattrsetpshared.c @@ -0,0 +1,111 @@ +/******************************************************************************** + * libc/pthread/pthread_barrierattrsetpshared.c + * + * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include +#include + +/******************************************************************************** + * Definitions + ********************************************************************************/ + +/******************************************************************************** + * Private Type Declarations + ********************************************************************************/ + +/******************************************************************************** + * Global Variables + ********************************************************************************/ + +/******************************************************************************** + * Private Variables + ********************************************************************************/ + +/******************************************************************************** + * Private Function Prototypes + ********************************************************************************/ + +/******************************************************************************** + * Public Functions + ********************************************************************************/ + +/******************************************************************************** + * Function: pthread_barrierattr_setpshared + * + * Description: + * The process-shared attribute is set to PTHREAD_PROCESS_SHARED to permit a + * barrier to be operated upon by any thread that has access to the memory where + * the barrier is allocated. If the process-shared attribute is + * PTHREAD_PROCESS_PRIVATE, the barrier can only be operated upon by threads + * created within the same process as the thread that initialized the barrier. + * If threads of different processes attempt to operate on such a barrier, the + * behavior is undefined. The default value of the attribute is + * PTHREAD_PROCESS_PRIVATE. + * + * Both constants PTHREAD_PROCESS_SHARED and PTHREAD_PROCESS_PRIVATE are defined + * in pthread.h. + * + * Parameters: + * attr - barrier attributes to be modified. + * pshared - the new value of the pshared attribute. + * + * Return Value: + * 0 (OK) on success or EINVAL if either attr is invalid or pshared is not one + * of PTHREAD_PROCESS_SHARED or PTHREAD_PROCESS_PRIVATE. + * + * Assumptions: + * + ********************************************************************************/ + +int pthread_barrierattr_setpshared(FAR pthread_barrierattr_t *attr, int pshared) +{ + int ret = OK; + + if (!attr || (pshared != PTHREAD_PROCESS_SHARED && pshared != PTHREAD_PROCESS_PRIVATE)) + { + ret = EINVAL; + } + else + { + attr->pshared = pshared; + } + return ret; +} diff --git a/nuttx/libc/pthread/pthread_condattrdestroy.c b/nuttx/libc/pthread/pthread_condattrdestroy.c new file mode 100644 index 000000000..30a0c4db1 --- /dev/null +++ b/nuttx/libc/pthread/pthread_condattrdestroy.c @@ -0,0 +1,82 @@ +/**************************************************************************** + * libc/pthread/pthread_condattrdestroy.c + * + * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include +#include + +/**************************************************************************** + * Global Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: pthread_condattr_destroy + * + * Description: + * Operations on condition variable attributes + * + * Parameters: + * None + * + * Return Value: + * None + * + * Assumptions: + * + ****************************************************************************/ + +int pthread_condattr_destroy(FAR pthread_condattr_t *attr) +{ + int ret = OK; + + sdbg("attr=0x%p\n", attr); + + if (!attr) + { + ret = EINVAL; + } + + sdbg("Returning %d\n", ret); + return ret; +} + + + diff --git a/nuttx/libc/pthread/pthread_condattrinit.c b/nuttx/libc/pthread/pthread_condattrinit.c new file mode 100644 index 000000000..511376f2e --- /dev/null +++ b/nuttx/libc/pthread/pthread_condattrinit.c @@ -0,0 +1,85 @@ +/**************************************************************************** + * libc/pthread/pthread_condattrinit.c + * + * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include +#include + +/**************************************************************************** + * Global Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: pthread_condattr_init + * + * Description: + * Operations on condition variable attributes + * + * Parameters: + * None + * + * Return Value: + * None + * + * Assumptions: + * + ****************************************************************************/ + +int pthread_condattr_init(FAR pthread_condattr_t *attr) +{ + int ret = OK; + + sdbg("attr=0x%p\n", attr); + + if (!attr) + { + ret = EINVAL; + } + else + { + *attr = 0; + } + + sdbg("Returning %d\n", ret); + return ret; +} + + diff --git a/nuttx/libc/pthread/pthread_mutexattrdestroy.c b/nuttx/libc/pthread/pthread_mutexattrdestroy.c new file mode 100644 index 000000000..82a13c300 --- /dev/null +++ b/nuttx/libc/pthread/pthread_mutexattrdestroy.c @@ -0,0 +1,104 @@ +/**************************************************************************** + * libc/pthread/pthread_mutexattrdestroy.c + * + * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include +#include + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: pthread_mutexattr_destroy + * + * Description: + * Destroy mutex attributes. + * + * Parameters: + * attr + * pshared + * + * Return Value: + * 0 if successful. Otherwise, an error code. + * + * Assumptions: + * + ****************************************************************************/ + +int pthread_mutexattr_destroy(FAR pthread_mutexattr_t *attr) +{ + int ret = OK; + + sdbg("attr=0x%p\n", attr); + + if (!attr) + { + ret = EINVAL; + } + else + { + attr->pshared = 0; + } + + sdbg("Returning %d\n", ret); + return ret; +} diff --git a/nuttx/libc/pthread/pthread_mutexattrgetpshared.c b/nuttx/libc/pthread/pthread_mutexattrgetpshared.c new file mode 100644 index 000000000..dc18484ec --- /dev/null +++ b/nuttx/libc/pthread/pthread_mutexattrgetpshared.c @@ -0,0 +1,104 @@ +/**************************************************************************** + * libc/pthread/pthread_mutexattrgetpshared.c + * + * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include +#include + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: pthread_mutexattr_getpshared + * + * Description: + * Get pshared mutex attribute. + * + * Parameters: + * attr + * pshared + * + * Return Value: + * 0 if successful. Otherwise, an error code. + * + * Assumptions: + * + ****************************************************************************/ + +int pthread_mutexattr_getpshared(FAR pthread_mutexattr_t *attr, FAR int *pshared) +{ + int ret = OK; + + sdbg("attr=0x%p pshared=0x%p\n", attr, pshared); + + if (!attr || !pshared) + { + ret = EINVAL; + } + else + { + *pshared = attr->pshared; + } + + sdbg("Returning %d\n", ret); + return ret; +} diff --git a/nuttx/libc/pthread/pthread_mutexattrgettype.c b/nuttx/libc/pthread/pthread_mutexattrgettype.c new file mode 100644 index 000000000..3b8b3ec05 --- /dev/null +++ b/nuttx/libc/pthread/pthread_mutexattrgettype.c @@ -0,0 +1,98 @@ +/**************************************************************************** + * libc/pthread/pthread_mutexattrgettype.c + * + * Copyright (C) 2008, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 +#include +#include + +#ifdef CONFIG_MUTEX_TYPES + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: pthread_mutexattr_gettype + * + * Description: + * Return the mutex type from the mutex attributes. + * + * Parameters: + * attr - The mutex attributes to query + * type - Location to return the mutex type + * + * Return Value: + * 0, if the mutex type was successfully return in 'type', or + * EINVAL, if any NULL pointers provided. + * + * Assumptions: + * + ****************************************************************************/ + +int pthread_mutexattr_gettype(const pthread_mutexattr_t *attr, int *type) +{ + if (attr && type) + { + *type = attr->type; + return 0; + } + return EINVAL; +} + +#endif /* CONFIG_MUTEX_TYPES */ diff --git a/nuttx/libc/pthread/pthread_mutexattrinit.c b/nuttx/libc/pthread/pthread_mutexattrinit.c new file mode 100644 index 000000000..f8c272195 --- /dev/null +++ b/nuttx/libc/pthread/pthread_mutexattrinit.c @@ -0,0 +1,106 @@ +/**************************************************************************** + * libc/pthread/pthread_mutexattrinit.c + * + * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include +#include + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: pthread_mutexattr_init + * + * Description: + * Create mutex attributes. + * + * Parameters: + * attr + * + * Return Value: + * 0 if successful. Otherwise, an error code. + * + * Assumptions: + * + ****************************************************************************/ + +int pthread_mutexattr_init(FAR pthread_mutexattr_t *attr) +{ + int ret = OK; + + sdbg("attr=0x%p\n", attr); + + if (!attr) + { + ret = EINVAL; + } + else + { + attr->pshared = 0; +#ifdef CONFIG_MUTEX_TYPES + attr->type = PTHREAD_MUTEX_DEFAULT; +#endif + } + + sdbg("Returning %d\n", ret); + return ret; +} diff --git a/nuttx/libc/pthread/pthread_mutexattrsetpshared.c b/nuttx/libc/pthread/pthread_mutexattrsetpshared.c new file mode 100644 index 000000000..7501fd980 --- /dev/null +++ b/nuttx/libc/pthread/pthread_mutexattrsetpshared.c @@ -0,0 +1,104 @@ +/**************************************************************************** + * libc/pthread/pthread_mutexattrsetpshared.c + * + * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include +#include + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: pthread_mutexattr_setpshared + * + * Description: + * Set pshared mutex attribute. + * + * Parameters: + * attr + * pshared + * + * Return Value: + * 0 if successful. Otherwise, an error code. + * + * Assumptions: + * + ****************************************************************************/ + +int pthread_mutexattr_setpshared(FAR pthread_mutexattr_t *attr, int pshared) +{ + int ret = OK; + + sdbg("attr=0x%p pshared=%d\n", attr, pshared); + + if (!attr || (pshared != 0 && pshared != 1)) + { + ret = EINVAL; + } + else + { + attr->pshared = pshared; + } + + sdbg("Returning %d\n", ret); + return ret; +} diff --git a/nuttx/libc/pthread/pthread_mutexattrsettype.c b/nuttx/libc/pthread/pthread_mutexattrsettype.c new file mode 100644 index 000000000..068a27dc2 --- /dev/null +++ b/nuttx/libc/pthread/pthread_mutexattrsettype.c @@ -0,0 +1,98 @@ +/**************************************************************************** + * libc/pthread/pthread_mutexattrsettype.c + * + * Copyright (C) 2008, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 +#include +#include + +#ifdef CONFIG_MUTEX_TYPES + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: pthread_mutexattr_settype + * + * Description: + * Set the mutex type in the mutex attributes. + * + * Parameters: + * attr - The mutex attributes in which to set the mutex type. + * type - The mutex type value to set. + * + * Return Value: + * 0, if the mutex type was successfully set in 'attr', or + * EINVAL, if 'attr' is NULL or 'type' unrecognized. + * + * Assumptions: + * + ****************************************************************************/ + +int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type) +{ + if (attr && type >= PTHREAD_MUTEX_NORMAL && type <= PTHREAD_MUTEX_RECURSIVE) + { + attr->type = type; + return OK; + } + return EINVAL; +} + +#endif /* CONFIG_MUTEX_TYPES */ diff --git a/nuttx/libc/queue/Make.defs b/nuttx/libc/queue/Make.defs new file mode 100644 index 000000000..9a843dbdc --- /dev/null +++ b/nuttx/libc/queue/Make.defs @@ -0,0 +1,47 @@ +############################################################################ +# libc/queue/Make.defs +# +# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# 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. +# +############################################################################ + +# Add the queue C files to the build + +CSRCS += sq_addlast.c sq_addfirst.c sq_addafter.c \ + sq_rem.c sq_remlast.c sq_remfirst.c sq_remafter.c + +CSRCS += dq_addlast.c dq_addfirst.c dq_addafter.c dq_addbefore.c \ + dq_rem.c dq_remlast.c dq_remfirst.c + +# Add the queue directory to the build + +DEPPATH += --dep-path queue +VPATH += :queue diff --git a/nuttx/libc/queue/dq_addafter.c b/nuttx/libc/queue/dq_addafter.c new file mode 100644 index 000000000..e4d1abf63 --- /dev/null +++ b/nuttx/libc/queue/dq_addafter.c @@ -0,0 +1,74 @@ +/************************************************************ + * libc/queue/dq_addafter.c + * + * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ************************************************************/ + +/************************************************************ + * Compilation Switches + ************************************************************/ + +/************************************************************ + * Included Files + ************************************************************/ + +#include + +/************************************************************ + * Public Functions + ************************************************************/ + +/************************************************************ + * Name: dq_addafter + * + * Description: + * dq_addafter function adds 'node' after 'qqqq' in the + * 'queue.' + * + ************************************************************/ + +void dq_addafter(FAR dq_entry_t *prev, FAR dq_entry_t *node, + dq_queue_t *queue) +{ + if (!queue->head || prev == queue->tail) + { + dq_addlast(node, queue); + } + else + { + FAR dq_entry_t *next = prev->flink; + node->blink = prev; + node->flink = next; + next->blink = node; + prev->flink = node; + } +} diff --git a/nuttx/libc/queue/dq_addbefore.c b/nuttx/libc/queue/dq_addbefore.c new file mode 100644 index 000000000..3c403fc94 --- /dev/null +++ b/nuttx/libc/queue/dq_addbefore.c @@ -0,0 +1,69 @@ +/**************************************************************************** + * libc/queue/dq_addbefore.c + * + * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: dq_addbefore + * + * Description: + * dq_addbefore adds 'node' before 'next' in 'queue' + * + ****************************************************************************/ + +void dq_addbefore(FAR dq_entry_t *next, FAR dq_entry_t *node, + dq_queue_t *queue) +{ + if (!queue->head || next == queue->head) + { + dq_addfirst(node, queue); + } + else + { + FAR dq_entry_t *prev = next->blink; + node->flink = next; + node->blink = prev; + prev->flink = node; + next->blink = node; + } +} diff --git a/nuttx/libc/queue/dq_addfirst.c b/nuttx/libc/queue/dq_addfirst.c new file mode 100644 index 000000000..56767b928 --- /dev/null +++ b/nuttx/libc/queue/dq_addfirst.c @@ -0,0 +1,74 @@ +/************************************************************ + * libc/queue/dq_addfirst.c + * + * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ************************************************************/ + +/************************************************************ + * Compilation Switches + ************************************************************/ + +/************************************************************ + * Included Files + ************************************************************/ + +#include + +/************************************************************ + * Public Functions + ************************************************************/ + +/************************************************************ + * Name: dq_addfirst + * + * Description: + * dq_addfirst affs 'node' at the beginning of 'queue' + * + ************************************************************/ + +void dq_addfirst(FAR dq_entry_t *node, dq_queue_t *queue) +{ + node->blink = NULL; + node->flink = queue->head; + + if (!queue->head) + { + queue->head = node; + queue->tail = node; + } + else + { + queue->head->blink = node; + queue->head = node; + } +} + diff --git a/nuttx/libc/queue/dq_addlast.c b/nuttx/libc/queue/dq_addlast.c new file mode 100644 index 000000000..3ef08abd0 --- /dev/null +++ b/nuttx/libc/queue/dq_addlast.c @@ -0,0 +1,74 @@ +/************************************************************ + * libc/queue/dq_addlast.c + * + * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ************************************************************/ + +/************************************************************ + * Compilation Switches + ************************************************************/ + +/************************************************************ + * Included Files + ************************************************************/ + +#include + +/************************************************************ + * Public Functions + ************************************************************/ + +/************************************************************ + * Name: dq_addlast + * + * Description + * dq_addlast adds 'node' to the end of 'queue' + * + ************************************************************/ + +void dq_addlast(FAR dq_entry_t *node, dq_queue_t *queue) +{ + node->flink = NULL; + node->blink = queue->tail; + + if (!queue->head) + { + queue->head = node; + queue->tail = node; + } + else + { + queue->tail->flink = node; + queue->tail = node; + } +} + diff --git a/nuttx/libc/queue/dq_rem.c b/nuttx/libc/queue/dq_rem.c new file mode 100644 index 000000000..db20762c7 --- /dev/null +++ b/nuttx/libc/queue/dq_rem.c @@ -0,0 +1,84 @@ +/************************************************************ + * libc/queue/dq_rem.c + * + * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ************************************************************/ + +/************************************************************ + * Compilation Switches + ************************************************************/ + +/************************************************************ + * Included Files + ************************************************************/ + +#include + +/************************************************************ + * Public Functions + ************************************************************/ + +/************************************************************ + * Name: dq_rem + * + * Descripton: + * dq_rem removes 'node' from 'queue' + * + ************************************************************/ + +void dq_rem(FAR dq_entry_t *node, dq_queue_t *queue) +{ + FAR dq_entry_t *prev = node->blink; + FAR dq_entry_t *next = node->flink; + + if (!prev) + { + queue->head = next; + } + else + { + prev->flink = next; + } + + if (!next) + { + queue->tail = prev; + } + else + { + next->blink = prev; + } + + node->flink = NULL; + node->blink = NULL; +} + diff --git a/nuttx/libc/queue/dq_remfirst.c b/nuttx/libc/queue/dq_remfirst.c new file mode 100644 index 000000000..e87acc338 --- /dev/null +++ b/nuttx/libc/queue/dq_remfirst.c @@ -0,0 +1,82 @@ +/************************************************************ + * libc/queue/dq_remfirst.c + * + * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ************************************************************/ + +/************************************************************ + * Compilation Switches + ************************************************************/ + +/************************************************************ + * Included Files + ************************************************************/ + +#include + +/************************************************************ + * Public Functions + ************************************************************/ + +/************************************************************ + * Name: dq_remfirst + * + * Description: + * dq_remfirst removes 'node' from the head of 'queue' + * + ************************************************************/ + +FAR dq_entry_t *dq_remfirst(dq_queue_t *queue) +{ + FAR dq_entry_t *ret = queue->head; + + if (ret) + { + FAR dq_entry_t *next = ret->flink; + if (!next) + { + queue->head = NULL; + queue->tail = NULL; + } + else + { + queue->head = next; + next->blink = NULL; + } + + ret->flink = NULL; + ret->blink = NULL; + } + + return ret; +} + diff --git a/nuttx/libc/queue/dq_remlast.c b/nuttx/libc/queue/dq_remlast.c new file mode 100644 index 000000000..18c182335 --- /dev/null +++ b/nuttx/libc/queue/dq_remlast.c @@ -0,0 +1,78 @@ +/**************************************************************************** + * libc/queue/dq_remlast.c + * + * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/***************************************************(************************ + * Name: dq_remlast + * + * Description: + * dq_remlast removes the last entry from 'queue' + * + ****************************************************************************/ + +FAR dq_entry_t *dq_remlast(dq_queue_t *queue) +{ + FAR dq_entry_t *ret = queue->tail; + + if (ret) + { + FAR dq_entry_t *prev = ret->blink; + if (!prev) + { + queue->head = NULL; + queue->tail = NULL; + } + else + { + queue->tail = prev; + prev->flink = NULL; + } + + ret->flink = NULL; + ret->blink = NULL; + } + + return ret; +} + diff --git a/nuttx/libc/queue/sq_addafter.c b/nuttx/libc/queue/sq_addafter.c new file mode 100644 index 000000000..5d47feba0 --- /dev/null +++ b/nuttx/libc/queue/sq_addafter.c @@ -0,0 +1,71 @@ +/************************************************************ + * libc/queue/sq_addafter.c + * + * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ************************************************************/ + +/************************************************************ + * Compilation Switches + ************************************************************/ + +/************************************************************ + * Included Files + ************************************************************/ + +#include + +/************************************************************ + * Public Functions + ************************************************************/ + +/************************************************************ + * Name: sq_addafter.c + * + * Description: + * The sq_addafter function adds 'node' after 'prev' in the + * 'queue.' + * + ************************************************************/ + +void sq_addafter(FAR sq_entry_t *prev, FAR sq_entry_t *node, + sq_queue_t *queue) +{ + if (!queue->head || prev == queue->tail) + { + sq_addlast(node, queue); + } + else + { + node->flink = prev->flink; + prev->flink = node; + } +} diff --git a/nuttx/libc/queue/sq_addfirst.c b/nuttx/libc/queue/sq_addfirst.c new file mode 100644 index 000000000..962486154 --- /dev/null +++ b/nuttx/libc/queue/sq_addfirst.c @@ -0,0 +1,67 @@ +/************************************************************ + * libc/queue/sq_addfirst.c + * + * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ************************************************************/ + +/************************************************************ + * Compilation Switches + ************************************************************/ + +/************************************************************ + * Included Files + ************************************************************/ + +#include + +/************************************************************ + * Public Functions + ************************************************************/ + +/************************************************************ + * Name: sq_addfirst + * + * Description: + * The sq_addfirst function places the 'node' at the head + * of the 'queue' + * + ************************************************************/ + +void sq_addfirst(FAR sq_entry_t *node, sq_queue_t *queue) +{ + node->flink = queue->head; + if (!queue->head) + { + queue->tail = node; + } + queue->head = node; +} diff --git a/nuttx/libc/queue/sq_addlast.c b/nuttx/libc/queue/sq_addlast.c new file mode 100644 index 000000000..faa07efb5 --- /dev/null +++ b/nuttx/libc/queue/sq_addlast.c @@ -0,0 +1,72 @@ +/************************************************************ + * libc/queue/sq_addlast.c + * + * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ************************************************************/ + +/************************************************************ + * Compilation Switches + ************************************************************/ + +/************************************************************ + * Included Files + ************************************************************/ + +#include + +/************************************************************ + * Public Functions + ************************************************************/ + +/************************************************************ + * Name: sq_addlast + * + * Description: + * The sq_addlast function places the 'node' at the tail of + * the 'queue' + ************************************************************/ + +void sq_addlast(FAR sq_entry_t *node, sq_queue_t *queue) +{ + node->flink = NULL; + if (!queue->head) + { + queue->head = node; + queue->tail = node; + } + else + { + queue->tail->flink = node; + queue->tail = node; + } +} + diff --git a/nuttx/libc/queue/sq_rem.c b/nuttx/libc/queue/sq_rem.c new file mode 100644 index 000000000..720be182c --- /dev/null +++ b/nuttx/libc/queue/sq_rem.c @@ -0,0 +1,83 @@ +/************************************************************ + * libc/queue/sq_rem.c + * + * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ************************************************************/ + +/************************************************************ + * Compilation Switches + ************************************************************/ + +/************************************************************ + * Included Files + ************************************************************/ + +#include + +/************************************************************ + * public Functions + ************************************************************/ + +/************************************************************ + * Name: sq_rem + * + * Description: + * sq_rem removes a 'node' for 'queue.' + * + ************************************************************/ + +void sq_rem(FAR sq_entry_t *node, sq_queue_t *queue) +{ + if (queue->head && node) + { + if (node == queue->head) + { + queue->head = node->flink; + if (node == queue->tail) + { + queue->tail = NULL; + } + } + else + { + FAR sq_entry_t *prev; + for(prev = (FAR sq_entry_t*)queue->head; + prev && prev->flink != node; + prev = prev->flink); + + if (prev) + { + sq_remafter(prev, queue); + } + } + } +} diff --git a/nuttx/libc/queue/sq_remafter.c b/nuttx/libc/queue/sq_remafter.c new file mode 100644 index 000000000..0545a00f9 --- /dev/null +++ b/nuttx/libc/queue/sq_remafter.c @@ -0,0 +1,79 @@ +/************************************************************ + * libc/queue/sq_remafter.c + * + * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ************************************************************/ + +/************************************************************ + * Compilation Switches + ************************************************************/ + +/************************************************************ + * Included Files + ************************************************************/ + +#include + +/************************************************************ + * Public Functions + ************************************************************/ + +/************************************************************ + * Name: + * + * Description: + * sq_remafter removes the entry following 'node; from the + * 'queue' Returns a reference to the removed entry. + * + ************************************************************/ + +FAR sq_entry_t *sq_remafter(FAR sq_entry_t *node, sq_queue_t *queue) +{ + FAR sq_entry_t *ret = node->flink; + if (queue->head && ret) + { + if (queue->tail == ret) + { + queue->tail = node; + node->flink = NULL; + } + else + { + node->flink = ret->flink; + } + + ret->flink = NULL; + } + + return ret; +} + diff --git a/nuttx/libc/queue/sq_remfirst.c b/nuttx/libc/queue/sq_remfirst.c new file mode 100644 index 000000000..f81c18dc2 --- /dev/null +++ b/nuttx/libc/queue/sq_remfirst.c @@ -0,0 +1,76 @@ +/************************************************************ + * libc/queue/sq_remfirst.c + * + * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ************************************************************/ + +/************************************************************ + * Compilation Switches + ************************************************************/ + +/************************************************************ + * Included Files + ************************************************************/ + +#include + +/************************************************************ + * Public Functions + ************************************************************/ + +/************************************************************ + * Name: sq_remfirst + * + * Description: + * sq_remfirst function removes the first entry from + * 'queue' + * + ************************************************************/ + +FAR sq_entry_t *sq_remfirst(sq_queue_t *queue) +{ + FAR sq_entry_t *ret = queue->head; + + if (ret) + { + queue->head = ret->flink; + if (!queue->head) + { + queue->tail = NULL; + } + + ret->flink = NULL; + } + + return ret; +} + diff --git a/nuttx/libc/queue/sq_remlast.c b/nuttx/libc/queue/sq_remlast.c new file mode 100644 index 000000000..8f045e493 --- /dev/null +++ b/nuttx/libc/queue/sq_remlast.c @@ -0,0 +1,87 @@ +/************************************************************ + * libc/queue/sq_remlast.c + * + * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ************************************************************/ + +/************************************************************ + * Compilation Switches + ************************************************************/ + +/************************************************************ + * Included Files + ************************************************************/ + +#include + +/************************************************************ + * Public Functions + ************************************************************/ + +/************************************************************ + * Name: sq_remlast + * + * Description: + * Removes the last entry in a singly-linked queue. + * + ************************************************************/ + +FAR sq_entry_t *sq_remlast(sq_queue_t *queue) +{ + FAR sq_entry_t *ret = queue->tail; + + if (ret) + { + if (queue->head == queue->tail) + { + queue->head = NULL; + queue->tail = NULL; + } + else + { + FAR sq_entry_t *prev; + for(prev = queue->head; + prev && prev->flink != ret; + prev = prev->flink); + + if (prev) + { + prev->flink = NULL; + queue->tail = prev; + } + } + + ret->flink = NULL; + } + + return ret; +} diff --git a/nuttx/libc/sched/Make.defs b/nuttx/libc/sched/Make.defs new file mode 100644 index 000000000..d2356db0f --- /dev/null +++ b/nuttx/libc/sched/Make.defs @@ -0,0 +1,43 @@ +############################################################################ +# libc/sched/Make.defs +# +# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# 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. +# +############################################################################ + +# Add the sched C files to the build + +CSRCS += sched_getprioritymax.c sched_getprioritymin.c + +# Add the sched directory to the build + +DEPPATH += --dep-path sched +VPATH += :sched diff --git a/nuttx/libc/sched/sched_getprioritymax.c b/nuttx/libc/sched/sched_getprioritymax.c new file mode 100644 index 000000000..6ea37e76a --- /dev/null +++ b/nuttx/libc/sched/sched_getprioritymax.c @@ -0,0 +1,100 @@ +/************************************************************************ + * libc/sched/sched_getprioritymax.c + * + * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include + +/************************************************************************ + * Definitions + ************************************************************************/ + +/************************************************************************ + * Private Type Declarations + ************************************************************************/ + +/************************************************************************ + * Global Variables + ************************************************************************/ + +/************************************************************************ + * Private Variables + ************************************************************************/ + +/************************************************************************ + * Private Function Prototypes + ************************************************************************/ + +/************************************************************************ + * Private Functions + ************************************************************************/ + +/************************************************************************ + * Public Functions + ************************************************************************/ + +/************************************************************************ + * Name: ched_get_priority_max + * + * Description: + * This function returns the value of the highest possible + * task priority for a specified scheduling policy. + * + * Inputs: + * policy - Scheduling policy requested. + * + * Return Value: + * The maximum priority value or -1 (ERROR) + * (errno is not set) + * + * Assumptions: + * + ************************************************************************/ + +int sched_get_priority_max(int policy) +{ + if (policy != SCHED_FIFO && policy != SCHED_RR) + { + return ERROR; + } + else + { + return SCHED_PRIORITY_MAX; + } +} diff --git a/nuttx/libc/sched/sched_getprioritymin.c b/nuttx/libc/sched/sched_getprioritymin.c new file mode 100644 index 000000000..dbb46d81e --- /dev/null +++ b/nuttx/libc/sched/sched_getprioritymin.c @@ -0,0 +1,100 @@ +/************************************************************************ + * libc/sched/sched_getprioritymin.c + * + * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include + +/************************************************************************ + * Definitions + ************************************************************************/ + +/************************************************************************ + * Private Type Declarations + ************************************************************************/ + +/************************************************************************ + * Global Variables + ************************************************************************/ + +/************************************************************************ + * Private Variables + ************************************************************************/ + +/************************************************************************ + * Private Function Prototypes + ************************************************************************/ + +/************************************************************************ + * Private Functions + ************************************************************************/ + +/************************************************************************ + * Public Functions + ************************************************************************/ + +/************************************************************************ + * Name: sched_get_priority_min + * + * Description: + * This function returns the value of the lowest possible + * task priority for a specified scheduling policy. + * + * Inputs: + * policy - Scheduling policy requested. + * + * Return Value: + * The minimum priority value or -1 (ERROR) + * (errno is not set) + * + * Assumptions: + * + ************************************************************************/ + +int sched_get_priority_min(int policy) +{ + if (policy != SCHED_FIFO && policy != SCHED_RR) + { + return ERROR; + } + else + { + return SCHED_PRIORITY_MIN; + } +} diff --git a/nuttx/libc/semaphore/Make.defs b/nuttx/libc/semaphore/Make.defs new file mode 100644 index 000000000..b6551ff96 --- /dev/null +++ b/nuttx/libc/semaphore/Make.defs @@ -0,0 +1,43 @@ +############################################################################ +# libc/semaphore/Make.defs +# +# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# 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. +# +############################################################################ + +# Add the semaphore C files to the build + +CSRCS += sem_init.c sem_getvalue.c + +# Add the semaphore directory to the build + +DEPPATH += --dep-path semaphore +VPATH += :semaphore diff --git a/nuttx/libc/semaphore/sem_getvalue.c b/nuttx/libc/semaphore/sem_getvalue.c new file mode 100644 index 000000000..ce9d12611 --- /dev/null +++ b/nuttx/libc/semaphore/sem_getvalue.c @@ -0,0 +1,108 @@ +/**************************************************************************** + * libc/semaphore/sem_getvalue.c + * + * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include +#include + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: sem_getvalue + * + * Description: + * This function updates the location referenced by 'sval' argument to + * have the value of the semaphore referenced by 'sem' without effecting + * the state of the semaphore. The updated value represents the actual + * semaphore value that occurred at some unspecified time during the call, + * but may not reflect the actual value of the semaphore when it is + * returned to the calling task. + * + * If 'sem' is locked, the value return by sem_getvalue() will either be + * zero or a negative number whose absolute value represents the number + * of tasks waiting for the semaphore. + * + * Parameters: + * sem - Semaphore descriptor + * sval - Buffer by which the value is returned + * + * Return Value: + * 0 (OK), or -1 (ERROR) if unsuccessful + * + * Assumptions: + * + ****************************************************************************/ + +int sem_getvalue(FAR sem_t *sem, FAR int *sval) +{ + if (sem && sval) + { + *sval = sem->semcount; + return OK; + } + else + { + set_errno(EINVAL); + return ERROR; + } +} diff --git a/nuttx/libc/semaphore/sem_init.c b/nuttx/libc/semaphore/sem_init.c new file mode 100644 index 000000000..7732eb57a --- /dev/null +++ b/nuttx/libc/semaphore/sem_init.c @@ -0,0 +1,125 @@ +/**************************************************************************** + * libc/sem/sem_init.c + * + * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include +#include +#include + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: sem_init + * + * Description: + * This function initializes the UNAMED semaphore sem. Following a + * successful call to sem_init(), the semaophore may be used in subsequent + * calls to sem_wait(), sem_post(), and sem_trywait(). The semaphore + * remains usable until it is destroyed. + * + * Only sem itself may be used for performing synchronization. The result + * of referring to copies of sem in calls to sem_wait(), sem_trywait(), + * sem_post(), and sem_destroy() is undefined. + * + * Parameters: + * sem - Semaphore to be initialized + * pshared - Process sharing (not used) + * value - Semaphore initialization value + * + * Return Value: + * 0 (OK), or -1 (ERROR) if unsuccessful. + * + * Assumptions: + * + ****************************************************************************/ + +int sem_init(FAR sem_t *sem, int pshared, unsigned int value) +{ + /* Verify that a semaphore was provided and the count is within the valid + * range. + */ + + if (sem && value <= SEM_VALUE_MAX) + { + /* Initialize the seamphore count */ + + sem->semcount = (int16_t)value; + + /* Initialize to support priority inheritance */ + +#ifdef CONFIG_PRIORITY_INHERITANCE +# if CONFIG_SEM_PREALLOCHOLDERS > 0 + sem->hhead = NULL; +# else + sem->holder.htcb = NULL; + sem->holder.counts = 0; +# endif +#endif + return OK; + } + else + { + set_errno(EINVAL); + return ERROR; + } +} diff --git a/nuttx/libc/signal/Make.defs b/nuttx/libc/signal/Make.defs new file mode 100644 index 000000000..fe7eb180e --- /dev/null +++ b/nuttx/libc/signal/Make.defs @@ -0,0 +1,47 @@ +############################################################################ +# libc/signal/Make.defs +# +# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# 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. +# +############################################################################ + +ifneq ($(CONFIG_DISABLE_SIGNALS),y) + +# Add the signal C files to the build + +CSRCS += sig_emptyset.c sig_fillset.c sig_addset.c sig_delset.c sig_ismember.c + +# Add the signal directory to the build + +DEPPATH += --dep-path signal +VPATH += :signal + +endif diff --git a/nuttx/libc/signal/sig_addset.c b/nuttx/libc/signal/sig_addset.c new file mode 100644 index 000000000..06ddabd6b --- /dev/null +++ b/nuttx/libc/signal/sig_addset.c @@ -0,0 +1,100 @@ +/**************************************************************************** + * libc/signal/sig_addset.c + * + * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: sigaddset + * + * Description: + * This function adds the signal specified by signo to the signal set + * specified by set. + * + * Parameters: + * set - Signal set to add signal to + * signo - Signal to add + * + * Return Value: + * 0 (OK), or -1 (ERROR) if the signal number is invalid. + * + * Assumptions: + * + ****************************************************************************/ + +int sigaddset(FAR sigset_t *set, int signo) +{ + int ret = ERROR; + + /* Verify the signal */ + + if (GOOD_SIGNO(signo)) + { + /* Add the signal to the set */ + + *set |= SIGNO2SET(signo); + ret = OK; + } + + return ret; +} + diff --git a/nuttx/libc/signal/sig_delset.c b/nuttx/libc/signal/sig_delset.c new file mode 100644 index 000000000..04112d872 --- /dev/null +++ b/nuttx/libc/signal/sig_delset.c @@ -0,0 +1,100 @@ +/**************************************************************************** + * libc/signal/sig_delset.c + * + * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: sigdelset + * + * Description: + * This function deletes the signal specified by signo from the signal + * set specified by the 'set' argument. + * + * Parameters: + * set - Signal set to delete the signal from + * signo - Signal to delete + * + * Return Value: + * 0 (OK), or -1 (ERROR) if the signal number is invalid. + * + * Assumptions: + * + ****************************************************************************/ + +int sigdelset(FAR sigset_t *set, int signo) +{ + int ret = ERROR; + + /* Verify the signal */ + + if (GOOD_SIGNO(signo)) + { + /* Delete the signal to the set */ + + *set &= ~SIGNO2SET(signo); + ret = OK; + } + + return ret; +} + diff --git a/nuttx/libc/signal/sig_emptyset.c b/nuttx/libc/signal/sig_emptyset.c new file mode 100644 index 000000000..16ddd3f68 --- /dev/null +++ b/nuttx/libc/signal/sig_emptyset.c @@ -0,0 +1,88 @@ +/**************************************************************************** + * libc/signal/sig_emptyset.c + * + * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: sigemptyset + * + * Description: + * This function initializes the signal set specified by set such that all + * signals are excluded. + * + * Parameters: + * set - Signal set to initalize + * + * Return Value: + * 0 (OK), or -1 (ERROR) if the signal set cannot be initialized. + * + * Assumptions: + * + ****************************************************************************/ + +int sigemptyset(FAR sigset_t *set) +{ + *set = NULL_SIGNAL_SET; + return OK; +} + diff --git a/nuttx/libc/signal/sig_fillset.c b/nuttx/libc/signal/sig_fillset.c new file mode 100644 index 000000000..99ee95c1f --- /dev/null +++ b/nuttx/libc/signal/sig_fillset.c @@ -0,0 +1,88 @@ +/**************************************************************************** + * libc/signal/sig_fillset.c + * + * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Publics Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: sigfillset + * + * Description: + * This function initializes the signal set specified by set such that all + * signals are included. + * + * Parameters: + * set - Signal set to initalize + * + * Return Value: + * 0 (OK), or -1 (ERROR) if the signal set cannot be initialized. + * + * Assumptions: + * + ****************************************************************************/ + +int sigfillset(FAR sigset_t *set) +{ + *set = ALL_SIGNAL_SET; + return OK; +} + diff --git a/nuttx/libc/signal/sig_ismember.c b/nuttx/libc/signal/sig_ismember.c new file mode 100644 index 000000000..1a8590e00 --- /dev/null +++ b/nuttx/libc/signal/sig_ismember.c @@ -0,0 +1,101 @@ +/**************************************************************************** + * libc/signal/sig_ismember.c + * + * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: sigismember + * + * Description: + * This function tests whether the signal specified by signo is a member + * of the set specified by set. + * + * Parameters: + * set - Signal set to test + * signo - Signal to test for + * + * Return Value: + * 1 (true), if the specified signal is a member of the set, + * 0 (OK or FALSE), if it is not, or + * -1 (ERROR) if the signal number is invalid. + * + * Assumptions: + * + ****************************************************************************/ + +int sigismember(FAR const sigset_t *set, int signo) +{ + int ret = ERROR; + + /* Verify the signal */ + + if (GOOD_SIGNO(signo)) + { + /* Check if the signal is in the set */ + + ret = ((*set & SIGNO2SET(signo)) != 0); + } + + return ret; +} + diff --git a/nuttx/libc/stdio/Make.defs b/nuttx/libc/stdio/Make.defs new file mode 100644 index 000000000..e18ab0220 --- /dev/null +++ b/nuttx/libc/stdio/Make.defs @@ -0,0 +1,85 @@ +############################################################################ +# libc/stdio/Make.defs +# +# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# 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. +# +############################################################################ + +# Add the stdio C files to the build +# This first group of C files do not depend on having file descriptors or +# C streams. + +CSRCS += lib_fileno.c lib_printf.c lib_rawprintf.c lib_lowprintf.c \ + lib_sprintf.c lib_asprintf.c lib_snprintf.c lib_libsprintf.c \ + lib_vsprintf.c lib_avsprintf.c lib_vsnprintf.c lib_libvsprintf.c \ + lib_meminstream.c lib_memoutstream.c lib_lowinstream.c \ + lib_lowoutstream.c lib_zeroinstream.c lib_nullinstream.c \ + lib_nulloutstream.c lib_sscanf.c + +# The remaining sources files depend upon file descriptors + +ifneq ($(CONFIG_NFILE_DESCRIPTORS),0) + +CSRCS += lib_rawinstream.c lib_rawoutstream.c + +# And these depend upon both file descriptors and C streams + +ifneq ($(CONFIG_NFILE_STREAMS),0) + +CSRCS += lib_fopen.c lib_fclose.c lib_fread.c lib_libfread.c lib_fseek.c \ + lib_ftell.c lib_fsetpos.c lib_fgetpos.c lib_fgetc.c lib_fgets.c \ + lib_gets.c lib_fwrite.c lib_libfwrite.c lib_fflush.c \ + lib_libflushall.c lib_libfflush.c lib_rdflush.c lib_wrflush.c \ + lib_fputc.c lib_puts.c lib_fputs.c lib_ungetc.c lib_vprintf.c \ + lib_fprintf.c lib_vfprintf.c lib_stdinstream.c lib_stdoutstream.c \ + lib_perror.c lib_feof.c lib_ferror.c lib_clearerr.c + +endif +endif + +# Other support that depends on specific, configured features. + +ifeq ($(CONFIG_SYSLOG),y) +CSRCS += lib_syslogstream.c +endif + +ifeq ($(CONFIG_LIBC_FLOATINGPOINT),y) +CSRCS += lib_dtoa.c +endif + +ifeq ($(CONFIG_STDIO_LINEBUFFER),y) +CSRCS += lib_libnoflush.c +endif + +# Add the stdio directory to the build + +DEPPATH += --dep-path stdio +VPATH += :stdio diff --git a/nuttx/libc/stdio/lib_asprintf.c b/nuttx/libc/stdio/lib_asprintf.c new file mode 100644 index 000000000..20ca6de32 --- /dev/null +++ b/nuttx/libc/stdio/lib_asprintf.c @@ -0,0 +1,105 @@ +/**************************************************************************** + * libc/stdio/lib_asprintf.c + * + * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Global Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Global Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: asprintf + * + * Description: + * This function is similar to sprintf, except that it dynamically + * allocates a string (as with malloc) to hold the output, instead of + * putting the output in a buffer you allocate in advance. The ptr + * argument should be the address of a char * object, and a successful + * call to asprintf stores a pointer to the newly allocated string at that + * location. + * + * Returned Value: + * The returned value is the number of characters allocated for the buffer, + * or less than zero if an error occurred. Usually this means that the buffer + * could not be allocated. + * + ****************************************************************************/ + +int asprintf (FAR char **ptr, const char *fmt, ...) +{ + va_list ap; + int ret; + + /* Let avsprintf do all of the work */ + + va_start(ap, fmt); + ret = avsprintf(ptr, fmt, ap); + va_end(ap); + + return ret; +} diff --git a/nuttx/libc/stdio/lib_avsprintf.c b/nuttx/libc/stdio/lib_avsprintf.c new file mode 100644 index 000000000..15ff8c9fb --- /dev/null +++ b/nuttx/libc/stdio/lib_avsprintf.c @@ -0,0 +1,146 @@ +/**************************************************************************** + * libc/stdio/lib_avsprintf.c + * + * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 +#include +#include +#include + +#include "lib_internal.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Global Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Global Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: avsprintf + * + * Description: + * This function is similar to vsprintf, except that it dynamically + * allocates a string (as with malloc) to hold the output, instead of + * putting the output in a buffer you allocate in advance. The ptr + * argument should be the address of a char * object, and a successful + * call to avsprintf stores a pointer to the newly allocated string at that + * location. + * + * Returned Value: + * The returned value is the number of characters allocated for the buffer, + * or less than zero if an error occurred. Usually this means that the buffer + * could not be allocated. + * + ****************************************************************************/ + +int avsprintf(FAR char **ptr, const char *fmt, va_list ap) +{ + struct lib_outstream_s nulloutstream; + struct lib_memoutstream_s memoutstream; + FAR char *buf; + int nbytes; + + DEBUGASSERT(ptr && fmt); + + /* First, use a nullstream to get the size of the buffer. The number + * of bytes returned may or may not include the null terminator. + */ + + lib_nulloutstream(&nulloutstream); + nbytes = lib_vsprintf((FAR struct lib_outstream_s *)&nulloutstream, fmt, ap); + + /* Then allocate a buffer to hold that number of characters, adding one + * for the null terminator. + */ + + buf = (FAR char *)malloc(nulloutstream.nput + 1); + if (!buf) + { + return ERROR; + } + + /* Initialize a memory stream to write into the allocated buffer. The + * memory stream will reserve one byte at the end of the buffer for the + * null terminator and will not report this in the number of output bytes. + */ + + lib_memoutstream((FAR struct lib_memoutstream_s *)&memoutstream, + buf, nulloutstream.nput + 1); + + /* Then let lib_vsprintf do it's real thing */ + + nbytes = lib_vsprintf((FAR struct lib_outstream_s *)&memoutstream.public, fmt, ap); + + /* Return a pointer to the string to the caller. NOTE: the memstream put() + * method has already added the NUL terminator to the end of the string (not + * included in the nput count). + * + * Hmmm.. looks like the memory would be stranded if lib_vsprintf() returned + * an error. Does that ever happen? + */ + + DEBUGASSERT(nbytes < 0 || nbytes == nulloutstream.nput); + *ptr = buf; + return nbytes; +} diff --git a/nuttx/libc/stdio/lib_clearerr.c b/nuttx/libc/stdio/lib_clearerr.c new file mode 100644 index 000000000..589b56feb --- /dev/null +++ b/nuttx/libc/stdio/lib_clearerr.c @@ -0,0 +1,69 @@ +/**************************************************************************** + * libc/stdio/lib_clearerr.c + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include + +#include + +#if CONFIG_NFILE_STREAMS > 0 + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: Functions + * + * Description: + * Clear any end-of-file or error conditions. + * + * Returned Value: + * None + * + ****************************************************************************/ + +void clearerr(FILE *stream) +{ + stream->fs_flags = 0; +} +#endif /* CONFIG_NFILE_STREAMS */ + diff --git a/nuttx/libc/stdio/lib_dtoa.c b/nuttx/libc/stdio/lib_dtoa.c new file mode 100644 index 000000000..44290ae32 --- /dev/null +++ b/nuttx/libc/stdio/lib_dtoa.c @@ -0,0 +1,1641 @@ +/**************************************************************************** + * libc/stdio/lib_dtoa.c + * + * This file was ported to NuttX by Yolande Cates. + * + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University 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 REGENTS 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 REGENTS 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 + +#include +#include + +#include "lib_internal.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#ifdef Unsigned_Shifts +# define Sign_Extend(a,b) if (b < 0) a |= 0xffff0000; +#else +# define Sign_Extend(a,b) /* no-op */ +#endif + +#ifdef CONFIG_ENDIAN_BIG +# define word0(x) ((uint32_t *)&x)[0] +# define word1(x) ((uint32_t *)&x)[1] +#else +# define word0(x) ((uint32_t *)&x)[1] +# define word1(x) ((uint32_t *)&x)[0] +#endif + +#ifdef CONFIG_ENDIAN_BIG +# define Storeinc(a,b,c) (((unsigned short *)a)[0] = (unsigned short)b, \ + ((unsigned short *)a)[1] = (unsigned short)c, a++) +#else +# define Storeinc(a,b,c) (((unsigned short *)a)[1] = (unsigned short)b, \ + ((unsigned short *)a)[0] = (unsigned short)c, a++) +#endif + +#define Exp_shift 20 +#define Exp_shift1 20 +#define Exp_msk1 0x100000 +#define Exp_msk11 0x100000 +#define Exp_mask 0x7ff00000 +#define P 53 +#define Bias 1023 +#define IEEE_Arith +#define Emin (-1022) +#define Exp_1 0x3ff00000 +#define Exp_11 0x3ff00000 +#define Ebits 11 +#define Frac_mask 0xfffff +#define Frac_mask1 0xfffff +#define Ten_pmax 22 +#define Bletch 0x10 +#define Bndry_mask 0xfffff +#define Bndry_mask1 0xfffff +#define LSB 1 +#define Sign_bit 0x80000000 +#define Log2P 1 +#define Tiny0 0 +#define Tiny1 1 +#define Quick_max 14 +#define Int_max 14 +#define Infinite(x) (word0(x) == 0x7ff00000) /* sufficient test for here */ + +#define Kmax 15 + +#define Bcopy(x,y) memcpy((char *)&x->sign, (char *)&y->sign, \ + y->wds*sizeof(long) + 2*sizeof(int)) + +/**************************************************************************** + * Private Type Definitions + ****************************************************************************/ + +struct Bigint +{ + struct Bigint *next; + int k, maxwds, sign, wds; + unsigned long x[1]; +}; + +typedef struct Bigint Bigint; + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static Bigint *freelist[Kmax + 1]; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +static Bigint *Balloc(int k) +{ + int x; + Bigint *rv; + + if ((rv = freelist[k])) + { + freelist[k] = rv->next; + } + else + { + x = 1 << k; + rv = (Bigint *)lib_malloc(sizeof(Bigint) + (x - 1) * sizeof(long)); + rv->k = k; + rv->maxwds = x; + } + rv->sign = rv->wds = 0; + return rv; +} + +static void Bfree(Bigint * v) +{ + if (v) + { + v->next = freelist[v->k]; + freelist[v->k] = v; + } +} + +/* multiply by m and add a */ + +static Bigint *multadd(Bigint * b, int m, int a) +{ + int i, wds; + unsigned long *x, y; +#ifdef Pack_32 + unsigned long xi, z; +#endif + Bigint *b1; + + wds = b->wds; + x = b->x; + i = 0; + do + { +#ifdef Pack_32 + xi = *x; + y = (xi & 0xffff) * m + a; + z = (xi >> 16) * m + (y >> 16); + a = (int)(z >> 16); + *x++ = (z << 16) + (y & 0xffff); +#else + y = *x * m + a; + a = (int)(y >> 16); + *x++ = y & 0xffff; +#endif + } + while (++i < wds); + if (a) + { + if (wds >= b->maxwds) + { + b1 = Balloc(b->k + 1); + Bcopy(b1, b); + Bfree(b); + b = b1; + } + b->x[wds++] = a; + b->wds = wds; + } + return b; +} + +static int hi0bits(unsigned long x) +{ + int k = 0; + + if (!(x & 0xffff0000)) + { + k = 16; + x <<= 16; + } + + if (!(x & 0xff000000)) + { + k += 8; + x <<= 8; + } + + if (!(x & 0xf0000000)) + { + k += 4; + x <<= 4; + } + + if (!(x & 0xc0000000)) + { + k += 2; + x <<= 2; + } + + if (!(x & 0x80000000)) + { + k++; + if (!(x & 0x40000000)) + { + return 32; + } + } + return k; +} + +static int lo0bits(unsigned long *y) +{ + int k; + unsigned long x = *y; + + if (x & 7) + { + if (x & 1) + { + return 0; + } + if (x & 2) + { + *y = x >> 1; + return 1; + } + *y = x >> 2; + return 2; + } + + k = 0; + if (!(x & 0xffff)) + { + k = 16; + x >>= 16; + } + + if (!(x & 0xff)) + { + k += 8; + x >>= 8; + } + + if (!(x & 0xf)) + { + k += 4; + x >>= 4; + } + + if (!(x & 0x3)) + { + k += 2; + x >>= 2; + } + + if (!(x & 1)) + { + k++; + x >>= 1; + if (!x & 1) + { + return 32; + } + } + *y = x; + return k; +} + +static Bigint *i2b(int i) +{ + Bigint *b; + + b = Balloc(1); + b->x[0] = i; + b->wds = 1; + return b; +} + +static Bigint *mult(Bigint * a, Bigint * b) +{ + Bigint *c; + int k, wa, wb, wc; + unsigned long carry, y, z; + unsigned long *x, *xa, *xae, *xb, *xbe, *xc, *xc0; +#ifdef Pack_32 + uint32_t z2; +#endif + + if (a->wds < b->wds) + { + c = a; + a = b; + b = c; + } + + k = a->k; + wa = a->wds; + wb = b->wds; + wc = wa + wb; + if (wc > a->maxwds) + { + k++; + } + c = Balloc(k); + for (x = c->x, xa = x + wc; x < xa; x++) + { + *x = 0; + } + xa = a->x; + xae = xa + wa; + xb = b->x; + xbe = xb + wb; + xc0 = c->x; +#ifdef Pack_32 + for (; xb < xbe; xb++, xc0++) + { + if ((y = *xb & 0xffff)) + { + x = xa; + xc = xc0; + carry = 0; + do + { + z = (*x & 0xffff) * y + (*xc & 0xffff) + carry; + carry = z >> 16; + z2 = (*x++ >> 16) * y + (*xc >> 16) + carry; + carry = z2 >> 16; + Storeinc(xc, z2, z); + } + while (x < xae); + *xc = carry; + } + if ((y = *xb >> 16)) + { + x = xa; + xc = xc0; + carry = 0; + z2 = *xc; + do + { + z = (*x & 0xffff) * y + (*xc >> 16) + carry; + carry = z >> 16; + Storeinc(xc, z, z2); + z2 = (*x++ >> 16) * y + (*xc & 0xffff) + carry; + carry = z2 >> 16; + } + while (x < xae); + *xc = z2; + } + } +#else + for (; xb < xbe; xc0++) + { + if ((y = *xb++)) + { + x = xa; + xc = xc0; + carry = 0; + do + { + z = *x++ * y + *xc + carry; + carry = z >> 16; + *xc++ = z & 0xffff; + } + while (x < xae); + *xc = carry; + } + } +#endif + for (xc0 = c->x, xc = xc0 + wc; wc > 0 && !*--xc; --wc); + c->wds = wc; + return c; +} + +static Bigint *p5s; + +static Bigint *pow5mult(Bigint * b, int k) +{ + Bigint *b1, *p5, *p51; + int i; + static int p05[3] = { 5, 25, 125 }; + + if ((i = k & 3)) + b = multadd(b, p05[i - 1], 0); + + if (!(k >>= 2)) + { + return b; + } + + if (!(p5 = p5s)) + { + /* first time */ + p5 = p5s = i2b(625); + p5->next = 0; + } + + for (;;) + { + if (k & 1) + { + b1 = mult(b, p5); + Bfree(b); + b = b1; + } + if (!(k >>= 1)) + { + break; + } + + if (!(p51 = p5->next)) + { + p51 = p5->next = mult(p5, p5); + p51->next = 0; + } + p5 = p51; + } + return b; +} + +static Bigint *lshift(Bigint * b, int k) +{ + int i, k1, n, n1; + Bigint *b1; + unsigned long *x, *x1, *xe, z; + +#ifdef Pack_32 + n = k >> 5; +#else + n = k >> 4; +#endif + k1 = b->k; + n1 = n + b->wds + 1; + for (i = b->maxwds; n1 > i; i <<= 1) + { + k1++; + } + b1 = Balloc(k1); + x1 = b1->x; + for (i = 0; i < n; i++) + { + *x1++ = 0; + } + x = b->x; + xe = x + b->wds; +#ifdef Pack_32 + if (k &= 0x1f) + { + k1 = 32 - k; + z = 0; + do + { + *x1++ = *x << k | z; + z = *x++ >> k1; + } + while (x < xe); + if ((*x1 = z)) + { + ++n1; + } + } +#else + if (k &= 0xf) + { + k1 = 16 - k; + z = 0; + do + { + *x1++ = ((*x << k) & 0xffff) | z; + z = *x++ >> k1; + } + while (x < xe); + if ((*x1 = z)) + { + ++n1; + } + } +#endif + else + do + { + *x1++ = *x++; + } + while (x < xe); + b1->wds = n1 - 1; + Bfree(b); + return b1; +} + +static int cmp(Bigint * a, Bigint * b) +{ + unsigned long *xa, *xa0, *xb, *xb0; + int i, j; + + i = a->wds; + j = b->wds; +#ifdef CONFIG_DEBUG_LIB + if (i > 1 && !a->x[i - 1]) + { + ldbg("cmp called with a->x[a->wds-1] == 0\n"); + } + if (j > 1 && !b->x[j - 1]) + { + ldbg("cmp called with b->x[b->wds-1] == 0\n"); + } +#endif + if (i -= j) + return i; + xa0 = a->x; + xa = xa0 + j; + xb0 = b->x; + xb = xb0 + j; + for (;;) + { + if (*--xa != *--xb) + return *xa < *xb ? -1 : 1; + if (xa <= xa0) + break; + } + return 0; +} + +static Bigint *diff(Bigint * a, Bigint * b) +{ + Bigint *c; + int i, wa, wb; + long borrow, y; /* We need signed shifts here. */ + unsigned long *xa, *xae, *xb, *xbe, *xc; +#ifdef Pack_32 + int32_t z; +#endif + + i = cmp(a, b); + if (!i) + { + c = Balloc(0); + c->wds = 1; + c->x[0] = 0; + return c; + } + if (i < 0) + { + c = a; + a = b; + b = c; + i = 1; + } + else + i = 0; + c = Balloc(a->k); + c->sign = i; + wa = a->wds; + xa = a->x; + xae = xa + wa; + wb = b->wds; + xb = b->x; + xbe = xb + wb; + xc = c->x; + borrow = 0; +#ifdef Pack_32 + do + { + y = (*xa & 0xffff) - (*xb & 0xffff) + borrow; + borrow = y >> 16; + Sign_Extend(borrow, y); + z = (*xa++ >> 16) - (*xb++ >> 16) + borrow; + borrow = z >> 16; + Sign_Extend(borrow, z); + Storeinc(xc, z, y); + } + while (xb < xbe); + while (xa < xae) + { + y = (*xa & 0xffff) + borrow; + borrow = y >> 16; + Sign_Extend(borrow, y); + z = (*xa++ >> 16) + borrow; + borrow = z >> 16; + Sign_Extend(borrow, z); + Storeinc(xc, z, y); + } +#else + do + { + y = *xa++ - *xb++ + borrow; + borrow = y >> 16; + Sign_Extend(borrow, y); + *xc++ = y & 0xffff; + } + while (xb < xbe); + while (xa < xae) + { + y = *xa++ + borrow; + borrow = y >> 16; + Sign_Extend(borrow, y); + *xc++ = y & 0xffff; + } +#endif + while (!*--xc) + wa--; + c->wds = wa; + return c; +} + +static Bigint *d2b(double d, int *e, int *bits) +{ + Bigint *b; + int de, i, k; + unsigned long *x, y, z; + +#ifdef Pack_32 + b = Balloc(1); +#else + b = Balloc(2); +#endif + x = b->x; + + z = word0(d) & Frac_mask; + word0(d) &= 0x7fffffff; /* clear sign bit, which we ignore */ + if ((de = (int)(word0(d) >> Exp_shift))) + z |= Exp_msk1; +#ifdef Pack_32 + if ((y = word1(d))) + { + if ((k = lo0bits(&y))) + { + x[0] = y | z << (32 - k); + z >>= k; + } + else + x[0] = y; + i = b->wds = (x[1] = z) ? 2 : 1; + } + else + { +#ifdef CONFIG_DEBUG_LIB + if (!z) + { + ldbg("Zero passed to d2b\n"); + } +#endif + k = lo0bits(&z); + x[0] = z; + i = b->wds = 1; + k += 32; + } +#else + if ((y = word1(d))) + { + if ((k = lo0bits(&y))) + if (k >= 16) + { + x[0] = y | ((z << (32 - k)) & 0xffff); + x[1] = z >> (k - 16) & 0xffff; + x[2] = z >> k; + i = 2; + } + else + { + x[0] = y & 0xffff; + x[1] = (y >> 16) | ((z << (16 - k)) & 0xffff); + x[2] = z >> k & 0xffff; + x[3] = z >> (k + 16); + i = 3; + } + else + { + x[0] = y & 0xffff; + x[1] = y >> 16; + x[2] = z & 0xffff; + x[3] = z >> 16; + i = 3; + } + } + else + { +#ifdef CONFIG_DEBUG_LIB + if (!z) + { + ldbg("Zero passed to d2b\n"); + } +#endif + k = lo0bits(&z); + if (k >= 16) + { + x[0] = z; + i = 0; + } + else + { + x[0] = z & 0xffff; + x[1] = z >> 16; + i = 1; + } + k += 32; + } + while (!x[i]) + --i; + b->wds = i + 1; +#endif + if (de) + { + *e = de - Bias - (P - 1) + k; + *bits = P - k; + } + else + { + *e = de - Bias - (P - 1) + 1 + k; +#ifdef Pack_32 + *bits = 32 * i - hi0bits(x[i - 1]); +#else + *bits = (i + 2) * 16 - hi0bits(x[i]); +#endif + } + return b; +} + +static const double tens[] = { + 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, + 1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19, + 1e20, 1e21, 1e22 +}; + +#ifdef IEEE_Arith +static const double bigtens[] = { 1e16, 1e32, 1e64, 1e128, 1e256 }; +static const double tinytens[] = { 1e-16, 1e-32, 1e-64, 1e-128, 1e-256 }; + +# define n_bigtens 5 +#else +static const double bigtens[] = { 1e16, 1e32 }; +static const double tinytens[] = { 1e-16, 1e-32 }; + +# define n_bigtens 2 +#endif + +static int quorem(Bigint * b, Bigint * S) +{ + int n; + long borrow, y; + unsigned long carry, q, ys; + unsigned long *bx, *bxe, *sx, *sxe; +#ifdef Pack_32 + int32_t z; + uint32_t si, zs; +#endif + + n = S->wds; +#ifdef CONFIG_DEBUG_LIB + if (b->wds > n) + { + ldbg("oversize b in quorem\n"); + } +#endif + if (b->wds < n) + { + return 0; + } + sx = S->x; + sxe = sx + --n; + bx = b->x; + bxe = bx + n; + q = *bxe / (*sxe + 1); /* ensure q <= true quotient */ +#ifdef CONFIG_DEBUG_LIB + if (q > 9) + { + ldbg("oversized quotient in quorem\n"); + } +#endif + if (q) + { + borrow = 0; + carry = 0; + do + { +#ifdef Pack_32 + si = *sx++; + ys = (si & 0xffff) * q + carry; + zs = (si >> 16) * q + (ys >> 16); + carry = zs >> 16; + y = (*bx & 0xffff) - (ys & 0xffff) + borrow; + borrow = y >> 16; + Sign_Extend(borrow, y); + z = (*bx >> 16) - (zs & 0xffff) + borrow; + borrow = z >> 16; + Sign_Extend(borrow, z); + Storeinc(bx, z, y); +#else + ys = *sx++ * q + carry; + carry = ys >> 16; + y = *bx - (ys & 0xffff) + borrow; + borrow = y >> 16; + Sign_Extend(borrow, y); + *bx++ = y & 0xffff; +#endif + } + while (sx <= sxe); + if (!*bxe) + { + bx = b->x; + while (--bxe > bx && !*bxe) + --n; + b->wds = n; + } + } + if (cmp(b, S) >= 0) + { + q++; + borrow = 0; + carry = 0; + bx = b->x; + sx = S->x; + do + { +#ifdef Pack_32 + si = *sx++; + ys = (si & 0xffff) + carry; + zs = (si >> 16) + (ys >> 16); + carry = zs >> 16; + y = (*bx & 0xffff) - (ys & 0xffff) + borrow; + borrow = y >> 16; + Sign_Extend(borrow, y); + z = (*bx >> 16) - (zs & 0xffff) + borrow; + borrow = z >> 16; + Sign_Extend(borrow, z); + Storeinc(bx, z, y); +#else + ys = *sx++ + carry; + carry = ys >> 16; + y = *bx - (ys & 0xffff) + borrow; + borrow = y >> 16; + Sign_Extend(borrow, y); + *bx++ = y & 0xffff; +#endif + } + while (sx <= sxe); + bx = b->x; + bxe = bx + n; + if (!*bxe) + { + while (--bxe > bx && !*bxe) + --n; + b->wds = n; + } + } + return q; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/* dtoa for IEEE arithmetic (dmg): convert double to ASCII string. + * + * Inspired by "How to Print Floating-Point Numbers Accurately" by + * Guy L. Steele, Jr. and Jon L. White [Proc. ACM SIGPLAN '90, pp. 92-101]. + * + * Modifications: + * 1. Rather than iterating, we use a simple numeric overestimate + * to determine k = floor(log10(d)). We scale relevant + * quantities using O(log2(k)) rather than O(k) multiplications. + * 2. For some modes > 2 (corresponding to ecvt and fcvt), we don't + * try to generate digits strictly left to right. Instead, we + * compute with fewer bits and propagate the carry if necessary + * when rounding the final digit up. This is often faster. + * 3. Under the assumption that input will be rounded nearest, + * mode 0 renders 1e23 as 1e23 rather than 9.999999999999999e22. + * That is, we allow equality in stopping tests when the + * round-nearest rule will give the same floating-point value + * as would satisfaction of the stopping test with strict + * inequality. + * 4. We remove common factors of powers of 2 from relevant + * quantities. + * 5. When converting floating-point integers less than 1e16, + * we use floating-point arithmetic rather than resorting + * to multiple-precision integers. + * 6. When asked to produce fewer than 15 digits, we first try + * to get by with floating-point arithmetic; we resort to + * multiple-precision integer arithmetic only if we cannot + * guarantee that the floating-point calculation has given + * the correctly rounded result. For k requested digits and + * "uniformly" distributed input, the probability is + * something like 10^(k-15) that we must resort to the int32_t + * calculation. + */ + +char *__dtoa(double d, int mode, int ndigits, int *decpt, int *sign, char **rve) +{ + /* Arguments ndigits, decpt, sign are similar to those of ecvt and fcvt; + * trailing zeros are suppressed from the returned string. If not null, *rve + * is set to point to the end of the return value. If d is +-Infinity or + * NaN, then *decpt is set to 9999. + * + * mode: 0 ==> shortest string that yields d when read in and rounded to + * nearest. 1 ==> like 0, but with Steele & White stopping rule; e.g. with + * IEEE P754 arithmetic , mode 0 gives 1e23 whereas mode 1 gives + * 9.999999999999999e22. 2 ==> max(1,ndigits) significant digits. This gives + * a return value similar to that of ecvt, except that trailing zeros are + * suppressed. 3 ==> through ndigits past the decimal point. This gives a + * return value similar to that from fcvt, except that trailing zeros are + * suppressed, and ndigits can be negative. 4-9 should give the same return + * values as 2-3, i.e., 4 <= mode <= 9 ==> same return as mode 2 + (mode & + * 1). These modes are mainly for debugging; often they run slower but + * sometimes faster than modes 2-3. 4,5,8,9 ==> left-to-right digit + * generation. 6-9 ==> don't try fast floating-point estimate (if + * applicable). + * + * Values of mode other than 0-9 are treated as mode 0. + * + * Sufficient space is allocated to the return value to hold the suppressed + * trailing zeros. */ + + int bbits, b2, b5, be, dig, i, ieps, ilim = 0, ilim0, ilim1 = 0, + j, j_1, k, k0, k_check, leftright, m2, m5, s2, s5, spec_case = 0, try_quick; + long L; + int denorm; + unsigned long x; + Bigint *b, *b1, *delta, *mlo = NULL, *mhi, *S; + double d2, ds, eps; + char *s, *s0; + static Bigint *result; + static int result_k; + + if (result) + { + result->k = result_k; + result->maxwds = 1 << result_k; + Bfree(result); + result = 0; + } + + if (word0(d) & Sign_bit) + { + /* set sign for everything, including 0's and NaNs */ + *sign = 1; + word0(d) &= ~Sign_bit; /* clear sign bit */ + } + else + { + *sign = 0; + } + +#if defined(IEEE_Arith) +# ifdef IEEE_Arith + if ((word0(d) & Exp_mask) == Exp_mask) +#else + if (word0(d) == 0x8000) +#endif + { + /* Infinity or NaN */ + *decpt = 9999; + s = +#ifdef IEEE_Arith + !word1(d) && !(word0(d) & 0xfffff) ? "Infinity" : +#endif + "NaN"; + if (rve) + *rve = +#ifdef IEEE_Arith + s[3] ? s + 8 : +#endif + s + 3; + return s; + } +#endif + if (!d) + { + *decpt = 1; + s = "0"; + if (rve) + *rve = s + 1; + return s; + } + + b = d2b(d, &be, &bbits); + if ((i = (int)(word0(d) >> Exp_shift1 & (Exp_mask >> Exp_shift1)))) + { + d2 = d; + word0(d2) &= Frac_mask1; + word0(d2) |= Exp_11; + + /* log(x) ~=~ log(1.5) + (x-1.5)/1.5 log10(x) = log(x) / log(10) ~=~ + * log(1.5)/log(10) + (x-1.5)/(1.5*log(10)) log10(d) = + * (i-Bias)*log(2)/log(10) + log10(d2) This suggests computing an + * approximation k to log10(d) by k = (i - Bias)*0.301029995663981 + ( + * (d2-1.5)*0.289529654602168 + 0.176091259055681 ); We want k to be too + * large rather than too small. The error in the first-order Taylor + * series approximation is in our favor, so we just round up the constant + * enough to compensate for any error in the multiplication of (i - Bias) + * by 0.301029995663981; since |i - Bias| <= 1077, and 1077 * 0.30103 * + * 2^-52 ~=~ 7.2e-14, adding 1e-13 to the constant term more than + * suffices. Hence we adjust the constant term to 0.1760912590558. (We + * could get a more accurate k by invoking log10, but this is probably + * not worthwhile.) */ + + i -= Bias; + denorm = 0; + } + else + { + /* d is denormalized */ + + i = bbits + be + (Bias + (P - 1) - 1); + x = i > 32 ? word0(d) << (64 - i) | word1(d) >> (i - 32) + : word1(d) << (32 - i); + d2 = x; + word0(d2) -= 31 * Exp_msk1; /* adjust exponent */ + i -= (Bias + (P - 1) - 1) + 1; + denorm = 1; + } + + ds = (d2 - 1.5) * 0.289529654602168 + 0.1760912590558 + i * 0.301029995663981; + k = (int)ds; + if (ds < 0. && ds != k) + { + k--; /* want k = floor(ds) */ + } + k_check = 1; + + if (k >= 0 && k <= Ten_pmax) + { + if (d < tens[k]) + k--; + k_check = 0; + } + + j = bbits - i - 1; + if (j >= 0) + { + b2 = 0; + s2 = j; + } + else + { + b2 = -j; + s2 = 0; + } + + if (k >= 0) + { + b5 = 0; + s5 = k; + s2 += k; + } + else + { + b2 -= k; + b5 = -k; + s5 = 0; + } + + if (mode < 0 || mode > 9) + { + mode = 0; + } + + try_quick = 1; + if (mode > 5) + { + mode -= 4; + try_quick = 0; + } + + leftright = 1; + switch (mode) + { + case 0: + case 1: + ilim = ilim1 = -1; + i = 18; + ndigits = 0; + break; + + case 2: + leftright = 0; + /* no break */ + case 4: + if (ndigits <= 0) + { + ndigits = 1; + } + + ilim = ilim1 = i = ndigits; + break; + + case 3: + leftright = 0; + /* no break */ + case 5: + i = ndigits + k + 1; + ilim = i; + ilim1 = i - 1; + if (i <= 0) + { + i = 1; + } + } + + j = sizeof(unsigned long); + for (result_k = 0; + (signed)(sizeof(Bigint) - sizeof(unsigned long) + j) <= i; + j <<= 1) + { + result_k++; + } + + result = Balloc(result_k); + s = s0 = (char *)result; + + if (ilim >= 0 && ilim <= Quick_max && try_quick) + { + /* Try to get by with floating-point arithmetic. */ + + i = 0; + d2 = d; + k0 = k; + ilim0 = ilim; + ieps = 2; /* conservative */ + + if (k > 0) + { + ds = tens[k & 0xf]; + j = k >> 4; + + if (j & Bletch) + { + /* prevent overflows */ + j &= Bletch - 1; + d /= bigtens[n_bigtens - 1]; + ieps++; + } + + for (; j; j >>= 1, i++) + { + if (j & 1) + { + ieps++; + ds *= bigtens[i]; + } + } + + d /= ds; + } + else if ((j_1 = -k)) + { + d *= tens[j_1 & 0xf]; + for (j = j_1 >> 4; j; j >>= 1, i++) + { + if (j & 1) + { + ieps++; + d *= bigtens[i]; + } + } + } + + if (k_check && d < 1. && ilim > 0) + { + if (ilim1 <= 0) + { + goto fast_failed; + } + + ilim = ilim1; + k--; + d *= 10.; + ieps++; + } + + eps = ieps * d + 7.; + word0(eps) -= (P - 1) * Exp_msk1; + if (ilim == 0) + { + S = mhi = 0; + d -= 5.; + if (d > eps) + goto one_digit; + if (d < -eps) + goto no_digits; + goto fast_failed; + } + +#ifndef No_leftright + if (leftright) + { + /* Use Steele & White method of only generating digits needed. */ + + eps = 0.5 / tens[ilim - 1] - eps; + for (i = 0;;) + { + L = (int)d; + d -= L; + *s++ = '0' + (int)L; + if (d < eps) + goto ret1; + if (1. - d < eps) + goto bump_up; + if (++i >= ilim) + break; + eps *= 10.; + d *= 10.; + } + } + else + { +#endif + /* Generate ilim digits, then fix them up. */ + + eps *= tens[ilim - 1]; + for (i = 1;; i++, d *= 10.) + { + L = (int)d; + d -= L; + *s++ = '0' + (int)L; + if (i == ilim) + { + if (d > 0.5 + eps) + goto bump_up; + else if (d < 0.5 - eps) + { + while (*--s == '0'); + s++; + goto ret1; + } + break; + } + } +#ifndef No_leftright + } +#endif + fast_failed: + s = s0; + d = d2; + k = k0; + ilim = ilim0; + } + + /* Do we have a "small" integer? */ + + if (be >= 0 && k <= Int_max) + { + /* Yes. */ + + ds = tens[k]; + if (ndigits < 0 && ilim <= 0) + { + S = mhi = 0; + if (ilim < 0 || d <= 5 * ds) + goto no_digits; + goto one_digit; + } + + for (i = 1;; i++) + { + L = (int)(d / ds); + d -= L * ds; +#ifdef Check_FLT_ROUNDS + /* If FLT_ROUNDS == 2, L will usually be high by 1 */ + if (d < 0) + { + L--; + d += ds; + } +#endif + *s++ = '0' + (int)L; + if (i == ilim) + { + d += d; + if (d > ds || (d == ds && (L & 1))) + { + bump_up: + while (*--s == '9') + if (s == s0) + { + k++; + *s = '0'; + break; + } + ++*s++; + } + break; + } + if (!(d *= 10.)) + { + break; + } + } + + goto ret1; + } + + m2 = b2; + m5 = b5; + mhi = mlo = 0; + if (leftright) + { + if (mode < 2) + { + i = denorm ? be + (Bias + (P - 1) - 1 + 1) : 1 + P - bbits; + } + else + { + j = ilim - 1; + if (m5 >= j) + m5 -= j; + else + { + s5 += j -= m5; + b5 += j; + m5 = 0; + } + if ((i = ilim) < 0) + { + m2 -= i; + i = 0; + } + } + + b2 += i; + s2 += i; + mhi = i2b(1); + } + + if (m2 > 0 && s2 > 0) + { + i = m2 < s2 ? m2 : s2; + b2 -= i; + m2 -= i; + s2 -= i; + } + + if (b5 > 0) + { + if (leftright) + { + if (m5 > 0) + { + mhi = pow5mult(mhi, m5); + b1 = mult(mhi, b); + Bfree(b); + b = b1; + } + if ((j = b5 - m5)) + b = pow5mult(b, j); + } + else + { + b = pow5mult(b, b5); + } + } + + S = i2b(1); + if (s5 > 0) + { + S = pow5mult(S, s5); + } + + /* Check for special case that d is a normalized power of 2. */ + + if (mode < 2) + { + if (!word1(d) && !(word0(d) & Bndry_mask) && word0(d) & Exp_mask) + { + /* The special case */ + b2 += Log2P; + s2 += Log2P; + spec_case = 1; + } + else + { + spec_case = 0; + } + } + + /* Arrange for convenient computation of quotients: shift left if + * necessary so divisor has 4 leading 0 bits. + * + * Perhaps we should just compute leading 28 bits of S once and for all + * and pass them and a shift to quorem, so it can do shifts and ors + * to compute the numerator for q. + */ + +#ifdef Pack_32 + if ((i = ((s5 ? 32 - hi0bits(S->x[S->wds - 1]) : 1) + s2) & 0x1f)) + { + i = 32 - i; + } +#else + if ((i = ((s5 ? 32 - hi0bits(S->x[S->wds - 1]) : 1) + s2) & 0xf)) + { + i = 16 - i; + } +#endif + + if (i > 4) + { + i -= 4; + b2 += i; + m2 += i; + s2 += i; + } + else if (i < 4) + { + i += 28; + b2 += i; + m2 += i; + s2 += i; + } + + if (b2 > 0) + { + b = lshift(b, b2); + } + + if (s2 > 0) + { + S = lshift(S, s2); + } + + if (k_check) + { + if (cmp(b, S) < 0) + { + k--; + b = multadd(b, 10, 0); /* we botched the k estimate */ + if (leftright) + { + mhi = multadd(mhi, 10, 0); + } + + ilim = ilim1; + } + } + + if (ilim <= 0 && mode > 2) + { + if (ilim < 0 || cmp(b, S = multadd(S, 5, 0)) <= 0) + { + /* no digits, fcvt style */ + no_digits: + k = -1 - ndigits; + goto ret; + } + one_digit: + *s++ = '1'; + k++; + goto ret; + } + + if (leftright) + { + if (m2 > 0) + { + mhi = lshift(mhi, m2); + } + + /* Compute mlo -- check for special case that d is a normalized power of + * 2. */ + + mlo = mhi; + if (spec_case) + { + mhi = Balloc(mhi->k); + Bcopy(mhi, mlo); + mhi = lshift(mhi, Log2P); + } + + for (i = 1;; i++) + { + dig = quorem(b, S) + '0'; + /* Do we yet have the shortest decimal string that will round to d? */ + j = cmp(b, mlo); + delta = diff(S, mhi); + j_1 = delta->sign ? 1 : cmp(b, delta); + Bfree(delta); +#ifndef ROUND_BIASED + if (j_1 == 0 && !mode && !(word1(d) & 1)) + { + if (dig == '9') + { + goto round_9_up; + } + + if (j > 0) + { + dig++; + } + + *s++ = dig; + goto ret; + } +#endif + if (j < 0 || (j == 0 && !mode +#ifndef ROUND_BIASED + && (!(word1(d) & 1)) +#endif + )) + { + if ((j_1 > 0)) + { + b = lshift(b, 1); + j_1 = cmp(b, S); + if ((j_1 > 0 || (j_1 == 0 && (dig & 1))) && dig++ == '9') + { + goto round_9_up; + } + } + + *s++ = dig; + goto ret; + } + + if (j_1 > 0) + { + if (dig == '9') + { /* possible if i == 1 */ + round_9_up: + *s++ = '9'; + goto roundoff; + } + + *s++ = dig + 1; + goto ret; + } + + *s++ = dig; + if (i == ilim) + { + break; + } + + b = multadd(b, 10, 0); + if (mlo == mhi) + { + mlo = mhi = multadd(mhi, 10, 0); + } + else + { + mlo = multadd(mlo, 10, 0); + mhi = multadd(mhi, 10, 0); + } + } + } + else + { + for (i = 1;; i++) + { + *s++ = dig = quorem(b, S) + '0'; + if (i >= ilim) + { + break; + } + + b = multadd(b, 10, 0); + } + } + + /* Round off last digit */ + + b = lshift(b, 1); + j = cmp(b, S); + if (j > 0 || (j == 0 && (dig & 1))) + { + roundoff: + while (*--s == '9') + if (s == s0) + { + k++; + *s++ = '1'; + goto ret; + } + ++*s++; + } + else + { + while (*--s == '0'); + s++; + } + +ret: + Bfree(S); + if (mhi) + { + if (mlo && mlo != mhi) + { + Bfree(mlo); + } + + Bfree(mhi); + } +ret1: + Bfree(b); + if (s == s0) + { /* don't return empty string */ + *s++ = '0'; + k = 0; + } + + *s = 0; + *decpt = k + 1; + if (rve) + { + *rve = s; + } + + return s0; +} diff --git a/nuttx/libc/stdio/lib_fclose.c b/nuttx/libc/stdio/lib_fclose.c new file mode 100644 index 000000000..c04537adf --- /dev/null +++ b/nuttx/libc/stdio/lib_fclose.c @@ -0,0 +1,154 @@ +/**************************************************************************** + * libc/stdio/lib_fclose.c + * + * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include +#include +#include +#include + +#include "lib_internal.h" + +/**************************************************************************** + * Global Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: fclose + * + * Description + * The fclose() function will flush the stream pointed to by stream + * (writing any buffered output data using lib_fflush()) and close the + * underlying file descriptor. + * + * Returned Value: + * Upon successful completion 0 is returned. Otherwise, EOF is returned + * and the global variable errno is set to indicate the error. In either + * case any further access (including another call to fclose()) to the + * stream results in undefined behaviour. + * + ****************************************************************************/ + +int fclose(FAR FILE *stream) +{ + int err = EINVAL; + int ret = ERROR; + int status; + + /* Verify that a stream was provided. */ + + if (stream) + { + /* Check that the underlying file descriptor corresponds to an an open + * file. + */ + + ret = OK; + if (stream->fs_filedes >= 0) + { + /* If the stream was opened for writing, then flush the stream */ + + if ((stream->fs_oflags & O_WROK) != 0) + { + ret = lib_fflush(stream, true); + err = errno; + } + + /* Close the underlying file descriptor and save the return status */ + + status = close(stream->fs_filedes); + + /* If close() returns an error but flush() did not then make sure + * that we return the close() error condition. + */ + + if (ret == OK) + { + ret = status; + err = errno; + } + } + +#if CONFIG_STDIO_BUFFER_SIZE > 0 + /* Destroy the semaphore */ + + sem_destroy(&stream->fs_sem); + + /* Release the buffer */ + + if (stream->fs_bufstart) + { + lib_free(stream->fs_bufstart); + } + + /* Clear the whole structure */ + + memset(stream, 0, sizeof(FILE)); +#else +#if CONFIG_NUNGET_CHARS > 0 + /* Reset the number of ungetc characters */ + + stream->fs_nungotten = 0; +#endif + /* Reset the flags */ + + stream->fs_oflags = 0; +#endif + /* Setting the fs_filedescriptor to -1 makes the stream available for reuse */ + + stream->fs_filedes = -1; + } + + /* On an error, reset the errno to the first error encountered and return + * EOF. + */ + + if (ret != OK) + { + set_errno(err); + return EOF; + } + + /* Return success */ + + return OK; +} + diff --git a/nuttx/libc/stdio/lib_feof.c b/nuttx/libc/stdio/lib_feof.c new file mode 100644 index 000000000..e036398fd --- /dev/null +++ b/nuttx/libc/stdio/lib_feof.c @@ -0,0 +1,77 @@ +/**************************************************************************** + * libc/stdio/lib_feof.c + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include + +#include + +#if CONFIG_NFILE_STREAMS > 0 + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: feof + * + * Description: + * The feof() function shall test if the currently file pointer for the + * stream is at the end of file. + * + * Returned Value: + * This function will return non-zero if the the file pointer is positioned + * at the end of file. + * + ****************************************************************************/ + +int feof(FILE *stream) +{ + /* If the end-of-file condition is encountered by any of the C-buffered + * I/O functions that perform read operations, they should set the + * __FS_FLAG_EOF in the fs_flags field of struct file_struct. + */ + + return (stream->fs_flags & __FS_FLAG_EOF) != 0; +} + +#endif /* CONFIG_NFILE_STREAMS */ + diff --git a/nuttx/libc/stdio/lib_ferror.c b/nuttx/libc/stdio/lib_ferror.c new file mode 100644 index 000000000..a977394cb --- /dev/null +++ b/nuttx/libc/stdio/lib_ferror.c @@ -0,0 +1,90 @@ +/**************************************************************************** + * libc/stdio/lib_ferror.c + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include + +#include + +#if CONFIG_NFILE_STREAMS > 0 + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: ferror + * + * Description: + * This function will test if the last operation resulted in an eror. This + * is used to disambiguate EOF and error conditions. + * + * Return Value: + * A non-zero value is returned to indicate the error condition. + * + ****************************************************************************/ + +int ferror(FILE *stream) +{ +#if 0 + /* If an error is encountered by any of the C-buffered I/O functions, they + * should set the __FS_FLAG_ERROR in the fs_flags field of struct + * file_struct. + */ + + return (stream->fs_flags & __FS_FLAG_ERROR) != 0; +#else + /* However, nothing currenlty sets the __FS_FLAG_ERROR flag (that is a job + * for another day). The __FS_FLAG_EOF is set by operations that perform + * read operations. Since ferror() is probably only called to disambiguate + * the meaning of other functions that return EOF, to indicate either EOF or + * an error, just testing for not EOF is probably sufficient for now. + * + * This approach would not work if ferror() is called in other contexts. In + * those cases, ferror() will always report an error. + */ + + return (stream->fs_flags & __FS_FLAG_EOF) == 0; +#endif +} + +#endif /* CONFIG_NFILE_STREAMS */ + diff --git a/nuttx/libc/stdio/lib_fflush.c b/nuttx/libc/stdio/lib_fflush.c new file mode 100644 index 000000000..a84a14a59 --- /dev/null +++ b/nuttx/libc/stdio/lib_fflush.c @@ -0,0 +1,132 @@ +/**************************************************************************** + * libc/stdio/lib_fflush.c + * + * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include +#include +#include + +#include + +#include "lib_internal.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Global Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Global Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: fflush + * + * Description: + * The function fflush() forces a write of all user-space buffered data for + * the given output or update stream via the stream's underlying write + * function. The open status of the stream is unaffected. + * + * If the stream argument is NULL, fflush() flushes all open output streams. + * + * Return: + * OK on success EOF on failure (with errno set appropriately) + * + ****************************************************************************/ + +int fflush(FAR FILE *stream) +{ + int ret; + + /* Is the stream argument NULL? */ + + if (!stream) + { + /* Yes... then this is a request to flush all streams */ + + ret = lib_flushall(sched_getstreams()); + } + else + { + ret = lib_fflush(stream, true); + } + + /* Check the return value */ + + if (ret < 0) + { + /* An error occurred during the flush AND/OR we were unable to flush + * all of the buffered write data. Set the errno value. + */ + + set_errno(-ret); + + /* And return EOF on failure. */ + + return EOF; + } + + return OK; +} + diff --git a/nuttx/libc/stdio/lib_fgetc.c b/nuttx/libc/stdio/lib_fgetc.c new file mode 100644 index 000000000..81e2e4ba7 --- /dev/null +++ b/nuttx/libc/stdio/lib_fgetc.c @@ -0,0 +1,101 @@ +/**************************************************************************** + * libc/stdio/lib_fgetc.c + * + * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Compilation Switches + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include "lib_internal.h" + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Global Function Prototypes + ****************************************************************************/ + +/************************************************************************** + * Global Constant Data + **************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/************************************************************************** + * Private Constant Data + **************************************************************************/ + +/**************************************************************************** + * Private Variables + **************************************************************************/ + +/**************************************************************************** + * Global Functions + **************************************************************************/ + +/**************************************************************************** + * fgetc + **************************************************************************/ + +int fgetc(FAR FILE *stream) +{ + unsigned char ch; + ssize_t ret; + + ret = lib_fread(&ch, 1, stream); + if (ret > 0) + { + return ch; + } + else + { + return EOF; + } +} diff --git a/nuttx/libc/stdio/lib_fgetpos.c b/nuttx/libc/stdio/lib_fgetpos.c new file mode 100644 index 000000000..7663ca2db --- /dev/null +++ b/nuttx/libc/stdio/lib_fgetpos.c @@ -0,0 +1,123 @@ +/**************************************************************************** + * libc/stdio/lib_fgetpos.c + * + * Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Compilation Switches + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include "lib_internal.h" + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Global Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: fgetpos + * + * Description: + * fgetpos() function is an alternate interfaces equivalent to ftell(). + * It gets the current value of the file offset and store it in the location + * referenced by pos. On some non-UNIX systems an fpos_t object may be a + * complex object and fsetpos may be the only way to portably reposition a + * stream. + * + * Returned Value: + * Zero on succes; -1 on failure with errno set appropriately. + * + ****************************************************************************/ + +int fgetpos(FAR FILE *stream, FAR fpos_t *pos) +{ + long position; + +#if CONFIG_DEBUG + if (!stream || !pos) + { + set_errno(EINVAL); + return ERROR; + } +#endif + + position = ftell(stream); + if (position == -1) + { + return ERROR; + } + + *pos = (fpos_t)position; + return OK; +} diff --git a/nuttx/libc/stdio/lib_fgets.c b/nuttx/libc/stdio/lib_fgets.c new file mode 100644 index 000000000..35d024ebb --- /dev/null +++ b/nuttx/libc/stdio/lib_fgets.c @@ -0,0 +1,207 @@ +/**************************************************************************** + * libc/stdio/lib_fgets.c + * + * Copyright (C) 2007-2008, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include +#include +#include +#include +#include + +/**************************************************************************** + * Definitions + ****************************************************************************/ +/* Some environments may return CR as end-of-line, others LF, and others + * both. If not specified, the logic here assumes either (but not both) as + * the default. + */ + +#if defined(CONFIG_EOL_IS_CR) +# undef CONFIG_EOL_IS_LF +# undef CONFIG_EOL_IS_BOTH_CRLF +# undef CONFIG_EOL_IS_EITHER_CRLF +#elif defined(CONFIG_EOL_IS_LF) +# undef CONFIG_EOL_IS_CR +# undef CONFIG_EOL_IS_BOTH_CRLF +# undef CONFIG_EOL_IS_EITHER_CRLF +#elif defined(CONFIG_EOL_IS_BOTH_CRLF) +# undef CONFIG_EOL_IS_CR +# undef CONFIG_EOL_IS_LF +# undef CONFIG_EOL_IS_EITHER_CRLF +#elif defined(CONFIG_EOL_IS_EITHER_CRLF) +# undef CONFIG_EOL_IS_CR +# undef CONFIG_EOL_IS_LF +# undef CONFIG_EOL_IS_BOTH_CRLF +#else +# undef CONFIG_EOL_IS_CR +# undef CONFIG_EOL_IS_LF +# undef CONFIG_EOL_IS_BOTH_CRLF +# define CONFIG_EOL_IS_EITHER_CRLF 1 +#endif + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Global Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: fgets + * + * Description: + * fgets() reads in at most one less than 'buflen' characters from stream + * and stores them into the buffer pointed to by 'buf'. Reading stops after + * an EOF or a newline. If a newline is read, it is stored into the + * buffer. A null terminator is stored after the last character in the + * buffer. + * + **************************************************************************/ + +char *fgets(FAR char *buf, int buflen, FILE *stream) +{ + int nch = 0; + + /* Sanity checks */ + + if (!stream || !buf || buflen < 1 || stream->fs_filedes < 0) + { + return NULL; + } + + if (buflen < 2) + { + *buf = '\0'; + return buf; + } + + /* Read characters until we have a full line. On each the loop we must + * be assured that there are two free bytes in the line buffer: One for + * the next character and one for the null terminator. + */ + + for(;;) + { + /* Get the next character */ + + int ch = fgetc(stream); + + /* Check for end-of-line. This is tricky only in that some + * environments may return CR as end-of-line, others LF, and + * others both. + */ + +#if defined(CONFIG_EOL_IS_LF) || defined(CONFIG_EOL_IS_BOTH_CRLF) + if (ch == '\n') +#elif defined(CONFIG_EOL_IS_CR) + if (ch == '\r') +#else /* elif CONFIG_EOL_IS_EITHER_CRLF */ + if (ch == '\n' || ch == '\r') +#endif + { + /* The newline is stored in the buffer along with the null + * terminator. + */ + + buf[nch++] = '\n'; + buf[nch] = '\0'; + return buf; + } + + /* Check for end-of-file */ + + else if (ch == EOF) + { + /* End of file with no data? */ + + if (!nch) + { + /* Yes.. return NULL as the end of file mark */ + + return NULL; + } + else + { + /* Terminate the line */ + + buf[nch] = '\0'; + return buf; + } + } + + /* Otherwise, check if the character is printable and, if so, put the + * character in the line buffer + */ + + else if (isprint(ch)) + { + buf[nch++] = ch; + + /* Check if there is room for another character and the line's + * null terminator. If not then we have to end the line now. + */ + + if (nch + 1 >= buflen) + { + buf[nch] = '\0'; + return buf; + } + } + } +} + diff --git a/nuttx/libc/stdio/lib_fileno.c b/nuttx/libc/stdio/lib_fileno.c new file mode 100644 index 000000000..f227aa372 --- /dev/null +++ b/nuttx/libc/stdio/lib_fileno.c @@ -0,0 +1,70 @@ +/**************************************************************************** + * libc/stdio/lib_fileno.c + * + * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include + +#include + +#if CONFIG_NFILE_STREAMS > 0 + +/**************************************************************************** + * Global Functions + ****************************************************************************/ + +int fileno(FAR FILE *stream) +{ + int ret = -1; + if (stream) + { + ret = stream->fs_filedes; + } + + if (ret < 0) + { + set_errno(EBADF); + return ERROR; + } + + return ret; +} +#endif /* CONFIG_NFILE_STREAMS */ + diff --git a/nuttx/libc/stdio/lib_fopen.c b/nuttx/libc/stdio/lib_fopen.c new file mode 100644 index 000000000..cb68b3584 --- /dev/null +++ b/nuttx/libc/stdio/lib_fopen.c @@ -0,0 +1,299 @@ +/**************************************************************************** + * libc/stdio/lib_fopen.c + * + * Copyright (C) 2007-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include +#include +#include +#include +#include + +#include "lib_internal.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +enum open_mode_e +{ + MODE_NONE = 0, /* No access mode determined */ + MODE_R, /* "r" or "rb" open for reading */ + MODE_W, /* "w" or "wb" open for writing, truncating or creating file */ + MODE_A, /* "a" or "ab" open for writing, appending to file */ + MODE_RPLUS, /* "r+", "rb+", or "r+b" open for update (reading and writing) */ + MODE_WPLUS, /* "w+", "wb+", or "w+b" open for update, truncating or creating file */ + MODE_APLUS /* "a+", "ab+", or "a+b" open for update, appending to file */ +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: lib_mode2oflags + ****************************************************************************/ + +static int lib_mode2oflags(FAR const char *mode) +{ + enum open_mode_e state; + int oflags; + + /* Verify that a mode string was provided. No error is */ + + if (!mode) + { + goto errout; + } + + /* Parse the mode string to determine the corresponding open flags */ + + state = MODE_NONE; + oflags = 0; + + for (; *mode; mode++) + { + switch (*mode) + { + /* Open for read access ("r", "r[+]", "r[b]", "r[b+]", or "r[+b]") */ + + case 'r' : + if (state == MODE_NONE) + { + /* Open for read access */ + + oflags = O_RDOK; + state = MODE_R; + } + else + { + goto errout; + } + break; + + /* Open for write access ("w", "w[+]", "w[b]", "w[b+]", or "w[+b]") */ + + case 'w' : + if (state == MODE_NONE) + { + /* Open for write access, truncating any existing file */ + + oflags = O_WROK|O_CREAT|O_TRUNC; + state = MODE_W; + } + else + { + goto errout; + } + break; + + /* Open for write/append access ("a", "a[+]", "a[b]", "a[b+]", or "a[+b]") */ + + case 'a' : + if (state == MODE_NONE) + { + /* Write to the end of the file */ + + oflags = O_WROK|O_CREAT|O_APPEND; + state = MODE_A; + } + else + { + goto errout; + } + break; + + /* Open for update access ("[r]+", "[rb]+]", "[r]+[b]", "[w]+", + * "[wb]+]", "[w]+[b]", "[a]+", "[ab]+]", "[a]+[b]") + */ + + case '+' : + switch (state) + { + case MODE_R: + { + /* Retain any binary mode selection */ + + oflags &= O_BINARY; + + /* Open for read/write access */ + + oflags |= O_RDWR; + state = MODE_RPLUS; + } + break; + + case MODE_W: + { + /* Retain any binary mode selection */ + + oflags &= O_BINARY; + + /* Open for write read/access, truncating any existing file */ + + oflags |= O_RDWR|O_CREAT|O_TRUNC; + state = MODE_WPLUS; + } + break; + + case MODE_A: + { + /* Retain any binary mode selection */ + + oflags &= O_BINARY; + + /* Read from the beginning of the file; write to the end */ + + oflags |= O_RDWR|O_CREAT|O_APPEND; + state = MODE_APLUS; + } + break; + + default: + goto errout; + break; + } + break; + + /* Open for binary access ("[r]b", "[r]b[+]", "[r+]b", "[w]b", + * "[w]b[+]", "[w+]b", "[a]b", "[a]b[+]", "[a+]b") + */ + + case 'b' : + if (state != MODE_NONE) + { + /* The file is opened in binary mode */ + + oflags |= O_BINARY; + } + else + { + goto errout; + } + break; + + /* Unrecognized or unsupported mode */ + + default: + goto errout; + break; + } + } + + return oflags; + +/* Both fopen and fdopen should fail with errno == EINVAL if the mode + * string is invalid. + */ + +errout: + set_errno(EINVAL); + return ERROR; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: fdopen + ****************************************************************************/ + +FAR FILE *fdopen(int fd, FAR const char *mode) +{ + FAR FILE *ret = NULL; + int oflags; + + /* Map the open mode string to open flags */ + + oflags = lib_mode2oflags(mode); + if (oflags >= 0) + { + ret = fs_fdopen(fd, oflags, NULL); + } + + return ret; +} + +/**************************************************************************** + * Name: fopen + ****************************************************************************/ + +FAR FILE *fopen(FAR const char *path, FAR const char *mode) +{ + FAR FILE *ret = NULL; + int oflags; + int fd; + + /* Map the open mode string to open flags */ + + oflags = lib_mode2oflags(mode); + if (oflags < 0) + { + return NULL; + } + + /* Open the file */ + + fd = open(path, oflags, 0666); + + /* If the open was successful, then fdopen() the fil using the file + * desciptor returned by open. If open failed, then just return the + * NULL stream -- open() has already set the errno. + */ + + if (fd >= 0) + { + ret = fs_fdopen(fd, oflags, NULL); + if (!ret) + { + /* Don't forget to close the file descriptor if any other + * failures are reported by fdopen(). + */ + + (void)close(fd); + } + } + return ret; +} diff --git a/nuttx/libc/stdio/lib_fprintf.c b/nuttx/libc/stdio/lib_fprintf.c new file mode 100644 index 000000000..5b6fe58f4 --- /dev/null +++ b/nuttx/libc/stdio/lib_fprintf.c @@ -0,0 +1,93 @@ +/**************************************************************************** + * libc/stdio/lib_fprintf.c + * + * Copyright (C) 2007, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Compilation Switches + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Global Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: fprintf + ****************************************************************************/ + +int fprintf(FAR FILE *stream, FAR const char *fmt, ...) +{ + va_list ap; + int n; + + /* vfprintf into the stream */ + + va_start(ap, fmt); + n = vfprintf(stream, fmt, ap); + va_end(ap); + return n; +} diff --git a/nuttx/libc/stdio/lib_fputc.c b/nuttx/libc/stdio/lib_fputc.c new file mode 100644 index 000000000..5d8065b43 --- /dev/null +++ b/nuttx/libc/stdio/lib_fputc.c @@ -0,0 +1,113 @@ +/**************************************************************************** + * libc/stdio/lib_fputc.c + * + * Copyright (C) 2007, 2008, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Compilation Switches + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include "lib_internal.h" + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Global Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Global Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Global Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: fputc + ****************************************************************************/ + +int fputc(int c, FAR FILE *stream) +{ + unsigned char buf = (unsigned char)c; + int ret; + + ret = lib_fwrite(&buf, 1, stream); + if (ret > 0) + { + /* Flush the buffer if a newline is output */ + +#ifdef CONFIG_STDIO_LINEBUFFER + if (c == '\n') + { + ret = lib_fflush(stream, true); + if (ret < 0) + { + return EOF; + } + } +#endif + return c; + } + else + { + return EOF; + } +} diff --git a/nuttx/libc/stdio/lib_fputs.c b/nuttx/libc/stdio/lib_fputs.c new file mode 100644 index 000000000..7b87a89d0 --- /dev/null +++ b/nuttx/libc/stdio/lib_fputs.c @@ -0,0 +1,220 @@ +/**************************************************************************** + * libc/stdio/lib_fputs.c + * + * Copyright (C) 2007, 2008, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Compilation Switches + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include + +#include "lib_internal.h" + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Global Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Global Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: fputs + * + * Description: + * fputs() writes the string s to stream, without its trailing '\0'. + * + ****************************************************************************/ + +#if defined(CONFIG_ARCH_ROMGETC) +int fputs(FAR const char *s, FAR FILE *stream) +{ + int nput; + int ret; + char ch; + + /* Make sure that a string was provided. */ + +#ifdef CONFIG_DEBUG /* Most parameter checking is disabled if DEBUG is off */ + if (!s) + { + set_errno(EINVAL); + return EOF; + } +#endif + + /* Write the string. Loop until the null terminator is encountered */ + + for (nput = 0, ch = up_romgetc(s); ch; nput++, s++, ch = up_romgetc(s)) + { + /* Write the next character to the stream buffer */ + + ret = lib_fwrite(&ch, 1, stream); + if (ret <= 0) + { + return EOF; + } + + /* Flush the buffer if a newline was written to the buffer */ + +#ifdef CONFIG_STDIO_LINEBUFFER + if (ch == '\n') + { + ret = lib_fflush(stream, true); + if (ret < 0) + { + return EOF; + } + } +#endif + } + + return nput; +} + +#elif defined(CONFIG_STDIO_LINEBUFFER) +int fputs(FAR const char *s, FAR FILE *stream) +{ + int nput; + int ret; + + /* Make sure that a string was provided. */ + +#ifdef CONFIG_DEBUG /* Most parameter checking is disabled if DEBUG is off */ + if (!s) + { + set_errno(EINVAL); + return EOF; + } +#endif + + /* Write the string. Loop until the null terminator is encountered */ + + for (nput = 0; *s; nput++, s++) + { + /* Write the next character to the stream buffer */ + + ret = lib_fwrite(s, 1, stream); + if (ret <= 0) + { + return EOF; + } + + /* Flush the buffer if a newline was written to the buffer */ + + if (*s == '\n') + { + ret = lib_fflush(stream, true); + if (ret < 0) + { + return EOF; + } + } + } + + return nput; +} + +#else +int fputs(FAR const char *s, FAR FILE *stream) +{ + int ntowrite; + int nput; + + /* Make sure that a string was provided. */ + +#ifdef CONFIG_DEBUG /* Most parameter checking is disabled if DEBUG is off */ + if (!s) + { + set_errno(EINVAL); + return EOF; + } +#endif + + /* Get the length of the string. */ + + ntowrite = strlen(s); + if (ntowrite == 0) + { + return 0; + } + + /* Write the string */ + + nput = lib_fwrite(s, ntowrite, stream); + if (nput < 0) + { + return EOF; + } + return nput; +} +#endif diff --git a/nuttx/libc/stdio/lib_fread.c b/nuttx/libc/stdio/lib_fread.c new file mode 100644 index 000000000..671714122 --- /dev/null +++ b/nuttx/libc/stdio/lib_fread.c @@ -0,0 +1,101 @@ +/**************************************************************************** + * libc/stdio/lib_fread.c + * + * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include + +#include "lib_internal.h" + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Global Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: fread + ****************************************************************************/ + +size_t fread(FAR void *ptr, size_t size, size_t n_items, FAR FILE *stream) +{ + size_t full_size = n_items * (size_t)size; + ssize_t bytes_read; + size_t items_read = 0; + + /* Write the data into the stream buffer */ + + bytes_read = lib_fread(ptr, full_size, stream); + if (bytes_read > 0) + { + /* Return the number of full items read */ + + items_read = bytes_read / size; + } + return items_read; +} + + diff --git a/nuttx/libc/stdio/lib_fseek.c b/nuttx/libc/stdio/lib_fseek.c new file mode 100644 index 000000000..36216d94a --- /dev/null +++ b/nuttx/libc/stdio/lib_fseek.c @@ -0,0 +1,138 @@ +/**************************************************************************** + * libc/stdio/lib_fseek.c + * + * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Compilation Switches + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include + +#include "lib_internal.h" + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Global Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: fseek + * + * Description: + * The fseek() function sets the file position indicator for the stream + * pointed to by stream. The new position, measured in bytes, is obtained + * by adding offset bytes to the position specified by whence. If whence is + * set to SEEK_SET, SEEK_CUR, or SEEK_END, the offset is relative to the + * start of the file, the current position indicator, or end-of-file, + * respectively. A successful call to the fseek() function clears the + * end-of-file indicator for the stream and undoes any effects of the ungetc(3) + * function on the same stream. + * + * Returned Value: + * Zero on succes; -1 on failure with errno set appropriately. + * + ****************************************************************************/ + +int fseek(FAR FILE *stream, long int offset, int whence) +{ + #if CONFIG_STDIO_BUFFER_SIZE > 0 + /* Flush any valid read/write data in the buffer (also verifies stream) */ + + if (lib_rdflush(stream) < 0 || lib_wrflush(stream) < 0) + { + return ERROR; + } +#else + /* Verify that we were provided with a stream */ + + if (!stream) + { + set_errno(EBADF); + return ERROR; + } +#endif + + /* On success or failure, discard any characters saved by ungetc() */ + +#if CONFIG_NUNGET_CHARS > 0 + stream->fs_nungotten = 0; +#endif + + /* Perform the fseek on the underlying file descriptor */ + + return lseek(stream->fs_filedes, offset, whence) == (off_t)-1 ? ERROR : OK; +} + + diff --git a/nuttx/libc/stdio/lib_fsetpos.c b/nuttx/libc/stdio/lib_fsetpos.c new file mode 100644 index 000000000..3d79a1877 --- /dev/null +++ b/nuttx/libc/stdio/lib_fsetpos.c @@ -0,0 +1,116 @@ +/**************************************************************************** + * libc/stdio/lib_fsetpos.c + * + * Copyright (C) 2008, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Compilation Switches + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include + +#include "lib_internal.h" + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Global Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: fsetpos + * + * Description: + * fsetpos() function is an alternate interfaces equivalent to fseek() + * (with whence set to SEEK_SET). It sets the current value of the file + * offset to value in the location referenced by pos. On some non-UNIX + * systems an fpos_t object may be a complex object and fsetpos may be the + * only way to portably reposition a stream. + * + * Returned Value: + * Zero on succes; -1 on failure with errno set appropriately. + * + ****************************************************************************/ + +int fsetpos(FAR FILE *stream, FAR fpos_t *pos) +{ +#if CONFIG_DEBUG + if (!stream || !pos) + { + set_errno(EINVAL); + return ERROR; + } +#endif + + return fseek(stream, (FAR off_t)*pos, SEEK_SET); +} diff --git a/nuttx/libc/stdio/lib_ftell.c b/nuttx/libc/stdio/lib_ftell.c new file mode 100644 index 000000000..99fc20f34 --- /dev/null +++ b/nuttx/libc/stdio/lib_ftell.c @@ -0,0 +1,129 @@ +/**************************************************************************** + * libc/stdio/lib_ftell.c + * + * Copyright (C) 2008, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Compilation Switches + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include + +#include "lib_internal.h" + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Global Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: ftell + * + * Description: + * ftell() returns the current value of the file position indicator for the + * stream pointed to by stream. + * + * Returned Value: + * Zero on succes; -1 on failure with errno set appropriately. + * + ****************************************************************************/ + +long ftell(FAR FILE *stream) +{ + off_t position; + + /* Verify that we were provided with a stream */ + + if (!stream) + { + set_errno(EBADF); + return ERROR; + } + + /* Perform the lseek to the current position. This will not move the + * file pointer, but will return its current setting + */ + + position = lseek(stream->fs_filedes, 0, SEEK_CUR); + if (position != (off_t)-1) + { + return (long)position; + } + else + { + return ERROR; + } +} + + diff --git a/nuttx/libc/stdio/lib_fwrite.c b/nuttx/libc/stdio/lib_fwrite.c new file mode 100644 index 000000000..e8de004fe --- /dev/null +++ b/nuttx/libc/stdio/lib_fwrite.c @@ -0,0 +1,99 @@ +/**************************************************************************** + * libc/stdio/lib_fwrite.c + * + * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include + +#include "lib_internal.h" + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Global Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: fwrite + ****************************************************************************/ + +size_t fwrite(FAR const void *ptr, size_t size, size_t n_items, FAR FILE *stream) +{ + size_t full_size = n_items * (size_t)size; + ssize_t bytes_written; + size_t items_written = 0; + + /* Write the data into the stream buffer */ + + bytes_written = lib_fwrite(ptr, full_size, stream); + if (bytes_written > 0) + { + /* Return the number of full items written */ + + items_written = bytes_written / size; + } + return items_written; +} diff --git a/nuttx/libc/stdio/lib_gets.c b/nuttx/libc/stdio/lib_gets.c new file mode 100644 index 000000000..39c31d273 --- /dev/null +++ b/nuttx/libc/stdio/lib_gets.c @@ -0,0 +1,120 @@ +/**************************************************************************** + * libc/stdio/lib_gets.c + * + * Copyright (C) 2007-2008, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 +#include +#include + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Global Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Global Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: gets + * + * Description: + * gets() reads a line from stdin into the buffer pointed to by s until + * either a terminating newline or EOF, which it replaces with '\0'. No + * check for buffer overrun is performed + * + * This API should not be used because it is inherently unsafe. Consider + * using fgets which is safer and slightly more efficient. + * + **************************************************************************/ + +FAR char *gets(FAR char *s) +{ + /* gets is ALMOST the same as fgets using stdin and no length limit + * (hence, the unsafeness of gets). So let fgets do most of the work. + */ + + FAR char *ret = fgets(s, INT_MAX, stdin); + if (ret) + { + /* Another subtle difference from fgets is that gets replaces + * end-of-line markers with null terminators. We will do that as + * a second step (with some loss in performance). + */ + + int len = strlen(ret); + if (len > 0 && ret[len-1] == '\n') + { + ret[len-1] = '\0'; + } + } + + return ret; +} + diff --git a/nuttx/libc/stdio/lib_libdtoa.c b/nuttx/libc/stdio/lib_libdtoa.c new file mode 100644 index 000000000..29f61fd76 --- /dev/null +++ b/nuttx/libc/stdio/lib_libdtoa.c @@ -0,0 +1,304 @@ +/**************************************************************************** + * libc/unistd/lib_libdtoa.c + * + * This file was ported to NuttX by Yolande Cates. + * + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University 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 REGENTS 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 REGENTS 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 + ****************************************************************************/ + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define MAX_PREC 16 + +#ifndef MIN +# define MIN(a,b) (a < b ? a : b) +#endif + +#ifndef MAX +# define MAX(a,b) (a > b ? a : b) +#endif + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Global Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Name: zeroes + * + * Description: + * Print the specified number of zeres + * + ****************************************************************************/ + +static void zeroes(FAR struct lib_outstream_s *obj, int nzeroes) +{ + int i; + + for (i = nzeroes; i > 0; i--) + { + obj->put(obj, '0'); + } +} + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: lib_dtoa + * + * Description: + * This is part of lib_vsprintf(). It handles the floating point formats. + * This version supports only the %f (with precision). If no precision + * was provided in the format, this will use precision == 0 which is + * probably not what you want. + * + * Input Parameters: + * obj - The output stream object + * fmt - The format character. Not used 'f' is always assumed + * prec - The number of digits to the right of the decimal point. If no + * precision is provided in the format, this will be zero. And, + * unfortunately in this case, it will be treated literally as + * a precision of zero. + * flags - Only ALTFORM and SHOWPLUS flags are supported. ALTFORM only + * applies if prec == 0 which is not supported anyway. + * value - The floating point value to convert. + * + ****************************************************************************/ + +static void lib_dtoa(FAR struct lib_outstream_s *obj, int fmt, int prec, + uint8_t flags, double value) +{ + FAR char *digits; /* String returned by __dtoa */ + FAR char *digalloc; /* Copy of digits to be freed after usage */ + FAR char *rve; /* Points to the end of the return value */ + int expt; /* Integer value of exponent */ + int numlen; /* Actual number of digits returned by cvt */ + int nchars; /* Number of characters to print */ + int dsgn; /* Unused sign indicator */ + int i; + + /* Non-zero... positive or negative */ + + if (value < 0) + { + value = -value; + SET_NEGATE(flags); + } + + /* Perform the conversion */ + + digits = __dtoa(value, 3, prec, &expt, &dsgn, &rve); + digalloc = digits; + numlen = rve - digits; + + if (IS_NEGATE(flags)) + { + obj->put(obj, '-'); + } + else if (IS_SHOWPLUS(flags)) + { + obj->put(obj, '+'); + } + + /* Special case exact zero or the case where the number is smaller than + * the print precision. + */ + + if (value == 0 || expt < -prec) + { + /* kludge for __dtoa irregularity */ + + obj->put(obj, '0'); + + /* A decimal point is printed only in the alternate form or if a + * particular precision is requested. + */ + + if (prec > 0 || IS_ALTFORM(flags)) + { + obj->put(obj, '.'); + + /* Always print at least one digit to the right of the decimal point. */ + + prec = MAX(1, prec); + } + } + + /* A non-zero value will be printed */ + + else + { + + /* Handle the case where the value is less than 1.0 (in magnitude) and + * will need a leading zero. + */ + + if (expt <= 0) + { + /* Print a single zero to the left of the decimal point */ + + obj->put(obj, '0'); + + /* Print the decimal point */ + + obj->put(obj, '.'); + + /* Print any leading zeros to the right of the decimal point */ + + if (expt < 0) + { + nchars = MIN(-expt, prec); + zeroes(obj, nchars); + prec -= nchars; + } + } + + /* Handle the general case where the value is greater than 1.0 (in + * magnitude). + */ + + else + { + /* Print the integer part to the left of the decimal point */ + + for (i = expt; i > 0; i--) + { + if (*digits != '\0') + { + obj->put(obj, *digits); + digits++; + } + else + { + obj->put(obj, '0'); + } + } + + /* Get the length of the fractional part */ + + numlen -= expt; + + /* If there is no fractional part, then a decimal point is printed + * only in the alternate form or if a particular precision is + * requested. + */ + + if (numlen > 0 || prec > 0 || IS_ALTFORM(flags)) + { + /* Print the decimal point */ + + obj->put(obj, '.'); + + /* Always print at least one digit to the right of the decimal + * point. + */ + + prec = MAX(1, prec); + } + } + + /* If a precision was specified, then limit the number digits to the + * right of the decimal point. + */ + + if (prec > 0) + { + nchars = MIN(numlen, prec); + } + else + { + nchars = numlen; + } + + /* Print the fractional part to the right of the decimal point */ + + for (i = nchars; i > 0; i--) + { + obj->put(obj, *digits); + digits++; + } + + /* Decremnt to get the number of trailing zeroes to print */ + + prec -= nchars; + } + + /* Finally, print any trailing zeroes */ + + zeroes(obj, prec); + + /* Is this memory supposed to be freed or not? */ + +#if 0 + if (digalloc) + { + free(digalloc); + } +#endif +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + diff --git a/nuttx/libc/stdio/lib_libfflush.c b/nuttx/libc/stdio/lib_libfflush.c new file mode 100644 index 000000000..f2f0cfe14 --- /dev/null +++ b/nuttx/libc/stdio/lib_libfflush.c @@ -0,0 +1,202 @@ +/**************************************************************************** + * libc/stdio/lib_libfflush.c + * + * Copyright (C) 2007-2008, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Compilation Switches + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include + +#include + +#include "lib_internal.h" + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Global Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: lib_fflush + * + * Description: + * The function lib_fflush() forces a write of all user-space buffered data for + * the given output or update stream via the stream's underlying write + * function. The open status of the stream is unaffected. + * + * Parmeters: + * stream - the stream to flush + * bforce - flush must be complete. + * + * Return: + * A negated errno value on failure, otherwise the number of bytes remaining + * in the buffer. + * + ****************************************************************************/ + +ssize_t lib_fflush(FAR FILE *stream, bool bforce) +{ +#if CONFIG_STDIO_BUFFER_SIZE > 0 + FAR const unsigned char *src; + ssize_t bytes_written; + ssize_t nbuffer; + + /* Return EBADF if the file is not opened for writing */ + + if (stream->fs_filedes < 0 || (stream->fs_oflags & O_WROK) == 0) + { + return -EBADF; + } + + /* Make sure that we have exclusive access to the stream */ + + lib_take_semaphore(stream); + + /* Make sure that the buffer holds valid data */ + + if (stream->fs_bufpos != stream->fs_bufstart) + { + /* Make sure that the buffer holds buffered write data. We do not + * support concurrent read/write buffer usage. + */ + + if (stream->fs_bufread != stream->fs_bufstart) + { + /* The buffer holds read data... just return zero meaning "no bytes + * remaining in the buffer." + */ + + lib_give_semaphore(stream); + return 0; + } + + /* How many bytes of write data are used in the buffer now */ + + nbuffer = stream->fs_bufpos - stream->fs_bufstart; + + /* Try to write that amount */ + + src = stream->fs_bufstart; + do + { + /* Perform the write */ + + bytes_written = write(stream->fs_filedes, src, nbuffer); + if (bytes_written < 0) + { + /* Write failed. The cause of the failure is in 'errno'. + * returned the negated errno value. + */ + + lib_give_semaphore(stream); + return -get_errno(); + } + + /* Handle partial writes. fflush() must either return with + * an error condition or with the data successfully flushed + * from the buffer. + */ + + src += bytes_written; + nbuffer -= bytes_written; + } + while (bforce && nbuffer > 0); + + /* Reset the buffer position to the beginning of the buffer */ + + stream->fs_bufpos = stream->fs_bufstart; + + /* For the case of an incomplete write, nbuffer will be non-zero + * It will hold the number of bytes that were not written. + * Move the data down in the buffer to handle this (rare) case + */ + + while (nbuffer) + { + *stream->fs_bufpos++ = *src++; + --nbuffer; + } + } + + /* Restore normal access to the stream and return the number of bytes + * remaining in the buffer. + */ + + lib_give_semaphore(stream); + return stream->fs_bufpos - stream->fs_bufstart; +#else + /* Return no bytes remaining in the buffer */ + + return 0; +#endif +} + diff --git a/nuttx/libc/stdio/lib_libflushall.c b/nuttx/libc/stdio/lib_libflushall.c new file mode 100644 index 000000000..7ac3da7e0 --- /dev/null +++ b/nuttx/libc/stdio/lib_libflushall.c @@ -0,0 +1,137 @@ +/**************************************************************************** + * libc/stdio/lib_libflushall.c + * + * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include +#include + +#include + +#include "lib_internal.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Global Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Global Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: lib_flushall + * + * Description: + * Called either (1) by the OS when a task exits, or (2) from fflush() + * when a NULL stream argument is provided. + * + ****************************************************************************/ + +int lib_flushall(FAR struct streamlist *list) +{ + int lasterrno = OK; + int ret; + + /* Make sure that there are streams associated with this thread */ + + if (list) + { + int i; + + /* Process each stream in the thread's stream list */ + + stream_semtake(list); + for (i = 0; i < CONFIG_NFILE_STREAMS; i++) + { + FILE *stream = &list->sl_streams[i]; + + /* If the stream is open (i.e., assigned a non-negative file + * descriptor) and opened for writing, then flush all of the pending + * write data in the stream. + */ + + if (stream->fs_filedes >= 0 && (stream->fs_oflags & O_WROK) != 0) + { + /* Flush the writable FILE */ + + ret = lib_fflush(stream, true); + if (ret < 0) + { + /* An error occurred during the flush AND/OR we were unable + * to flush all of the buffered write data. Remember the + * last errcode. + */ + + lasterrno = ret; + } + } + } + + stream_semgive(list); + } + + /* If any flush failed, return the errorcode of the last failed flush */ + + return lasterrno; +} diff --git a/nuttx/libc/stdio/lib_libfread.c b/nuttx/libc/stdio/lib_libfread.c new file mode 100644 index 000000000..bc6479037 --- /dev/null +++ b/nuttx/libc/stdio/lib_libfread.c @@ -0,0 +1,315 @@ +/**************************************************************************** + * libc/stdio/lib_libfread.c + * + * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 /* for CONFIG_STDIO_BUFFER_SIZE */ + +#include +#include +#include +#include +#include +#include + +#include "lib_internal.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Global Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: lib_fread + ****************************************************************************/ + +ssize_t lib_fread(FAR void *ptr, size_t count, FAR FILE *stream) +{ + unsigned char *dest = (unsigned char*)ptr; + ssize_t bytes_read; + int ret; + + /* Make sure that reading from this stream is allowed */ + + if (!stream || (stream->fs_oflags & O_RDOK) == 0) + { + set_errno(EBADF); + bytes_read = -1; + } + else + { + /* The stream must be stable until we complete the read */ + + lib_take_semaphore(stream); + +#if CONFIG_NUNGET_CHARS > 0 + /* First, re-read any previously ungotten characters */ + + while ((stream->fs_nungotten > 0) && (count > 0)) + { + /* Decrement the count of ungotten bytes to get an index */ + + stream->fs_nungotten--; + + /* Return the last ungotten byte */ + + *dest++ = stream->fs_ungotten[stream->fs_nungotten]; + + /* That's one less byte that we have to read */ + + count--; + } +#endif + +#if CONFIG_STDIO_BUFFER_SIZE > 0 + /* If the buffer is currently being used for write access, then + * flush all of the buffered write data. We do not support concurrent + * buffered read/write access. + */ + + ret = lib_wrflush(stream); + if (ret < 0) + { + lib_give_semaphore(stream); + return ret; + } + + /* Now get any other needed chars from the buffer or the file. */ + + while (count > 0) + { + /* Is there readable data in the buffer? */ + + while ((count > 0) && (stream->fs_bufpos < stream->fs_bufread)) + { + /* Yes, copy a byte into the user buffer */ + + *dest++ = *stream->fs_bufpos++; + count--; + } + + /* The buffer is empty OR we have already supplied the number of + * bytes requested in the read. Check if we need to read + * more from the file. + */ + + if (count > 0) + { + size_t buffer_available; + + /* We need to read more data into the buffer from the file */ + + /* Mark the buffer empty */ + + stream->fs_bufpos = stream->fs_bufread = stream->fs_bufstart; + + /* How much space is available in the buffer? */ + + buffer_available = stream->fs_bufend - stream->fs_bufread; + + /* Will the number of bytes that we need to read fit into + * the buffer space that is available? If the read size is + * larger than the buffer, then read some of the data + * directly into the user's buffer. + */ + + if (count > buffer_available) + { + bytes_read = read(stream->fs_filedes, dest, count); + if (bytes_read < 0) + { + /* An error occurred on the read. The error code is + * in the 'errno' variable. + */ + + goto errout_with_errno; + } + else if (bytes_read == 0) + { + /* We are at the end of the file. But we may already + * have buffered data. In that case, we will report + * the EOF indication later. + */ + + goto shortread; + } + else + { + /* Some bytes were read. Adjust the dest pointer */ + + dest += bytes_read; + + /* Were all of the requested bytes read? */ + + if (bytes_read < count) + { + /* No. We must be at the end of file. */ + + goto shortread; + } + else + { + /* Yes. We are done. */ + + count = 0; + } + } + } + else + { + /* The number of bytes required to satisfy the read + * is less than or equal to the size of the buffer + * space that we have left. Read as much as we can + * into the buffer. + */ + + bytes_read = read(stream->fs_filedes, stream->fs_bufread, buffer_available); + if (bytes_read < 0) + { + /* An error occurred on the read. The error code is + * in the 'errno' variable. + */ + + goto errout_with_errno; + } + else if (bytes_read == 0) + { + /* We are at the end of the file. But we may already + * have buffered data. In that case, we will report + * the EOF indication later. + */ + + goto shortread; + } + else + { + /* Some bytes were read */ + + stream->fs_bufread += bytes_read; + } + } + } + } +#else + /* Now get any other needed chars from the file. */ + + while (count > 0) + { + bytes_read = read(stream->fs_filedes, dest, count); + if (bytes_read < 0) + { + /* An error occurred on the read. The error code is + * in the 'errno' variable. + */ + + goto errout_with_errno; + } + else if (bytes_read == 0) + { + /* We are at the end of the file. But we may already + * have buffered data. In that case, we will report + * the EOF indication later. + */ + + break; + } + else + { + dest += bytes_read; + count -= bytes_read; + } + } +#endif + /* Here after a successful (but perhaps short) read */ + +#if CONFIG_STDIO_BUFFER_SIZE > 0 + shortread: +#endif + bytes_read = dest - (unsigned char*)ptr; + + /* Set or clear the EOF indicator. If we get here because of a + * short read and the total number of* bytes read is zero, then + * we must be at the end-of-file. + */ + + if (bytes_read > 0) + { + stream->fs_flags &= ~__FS_FLAG_EOF; + } + else + { + stream->fs_flags |= __FS_FLAG_EOF; + } + } + + lib_give_semaphore(stream); + return bytes_read; + +/* Error exits */ + +errout_with_errno: + lib_give_semaphore(stream); + return -get_errno(); +} + diff --git a/nuttx/libc/stdio/lib_libfwrite.c b/nuttx/libc/stdio/lib_libfwrite.c new file mode 100644 index 000000000..b917b3b56 --- /dev/null +++ b/nuttx/libc/stdio/lib_libfwrite.c @@ -0,0 +1,179 @@ +/**************************************************************************** + * libc/stdio/lib_libfwrite.c + * + * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 /* for CONFIG_STDIO_BUFFER_SIZE */ + +#include +#include +#include +#include +#include +#include + +#include "lib_internal.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Global Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: lib_fwrite + ****************************************************************************/ + +ssize_t lib_fwrite(FAR const void *ptr, size_t count, FAR FILE *stream) +#if CONFIG_STDIO_BUFFER_SIZE > 0 +{ + FAR const unsigned char *start = ptr; + FAR const unsigned char *src = ptr; + ssize_t ret = ERROR; + unsigned char *dest; + + /* Make sure that writing to this stream is allowed */ + + if (!stream || (stream->fs_oflags & O_WROK) == 0) + { + set_errno(EBADF); + goto errout; + } + + /* Get exclusive access to the stream */ + + lib_take_semaphore(stream); + + /* If the buffer is currently being used for read access, then + * discard all of the read-ahead data. We do not support concurrent + * buffered read/write access. + */ + + if (lib_rdflush(stream) < 0) + { + goto errout_with_semaphore; + } + + /* Loop until all of the bytes have been buffered */ + + while (count > 0) + { + /* Determine the number of bytes left in the buffer */ + + size_t gulp_size = stream->fs_bufend - stream->fs_bufpos; + + /* Will the user data fit into the amount of buffer space + * that we have left? + */ + + if (gulp_size > count) + { + /* Yes, clip the gulp to the size of the user data */ + + gulp_size = count; + } + + /* Adjust the number of bytes remaining to be transferred + * on the next pass through the loop (might be zero). + */ + + count -= gulp_size; + + /* Transfer the data into the buffer */ + + for (dest = stream->fs_bufpos; gulp_size > 0; gulp_size--) + { + *dest++ = *src++; + } + stream->fs_bufpos = dest; + + /* Is the buffer full? */ + + if (dest >= stream->fs_bufend) + { + /* Flush the buffered data to the IO stream */ + + int bytes_buffered = lib_fflush(stream, false); + if (bytes_buffered < 0) + { + goto errout_with_semaphore; + } + } + } + + /* Return the number of bytes written */ + + ret = src - start; + +errout_with_semaphore: + lib_give_semaphore(stream); + +errout: + return ret; +} +#else +{ + return write(stream->fs_filedes, ptr, count); +} +#endif /* CONFIG_STDIO_BUFFER_SIZE */ + diff --git a/nuttx/libc/stdio/lib_libnoflush.c b/nuttx/libc/stdio/lib_libnoflush.c new file mode 100644 index 000000000..076f8a17e --- /dev/null +++ b/nuttx/libc/stdio/lib_libnoflush.c @@ -0,0 +1,103 @@ +/**************************************************************************** + * libc/stdio/lib_libnoflush.c + * + * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include +#include +#include + +#include + +#include "lib_internal.h" + +#ifdef CONFIG_STDIO_LINEBUFFER + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Global Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Global Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: lib_noflush + * + * Description: + * lib_noflush() provides a common, dummy flush method for output streams + * that are not flushable. Only used if CONFIG_STDIO_LINEBUFFER is selected. + * + * Return: + * Always returns OK + * + ****************************************************************************/ + +int lib_noflush(FAR struct lib_outstream_s *this) +{ + return OK; +} + +#endif /* CONFIG_STDIO_LINEBUFFER */ + diff --git a/nuttx/libc/stdio/lib_libsprintf.c b/nuttx/libc/stdio/lib_libsprintf.c new file mode 100644 index 000000000..2d820ab37 --- /dev/null +++ b/nuttx/libc/stdio/lib_libsprintf.c @@ -0,0 +1,90 @@ +/**************************************************************************** + * libc/stdio/lib_libsprintf.c + * + * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 +#include "lib_internal.h" + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Global Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: lib_sprintf + ****************************************************************************/ + +int lib_sprintf(FAR struct lib_outstream_s *obj, const char *fmt, ...) +{ + va_list ap; + int n; + + /* Let lib_vsprintf do the real work */ + + va_start(ap, fmt); + n = lib_vsprintf(obj, fmt, ap); + va_end(ap); + return n; +} diff --git a/nuttx/libc/stdio/lib_libvsprintf.c b/nuttx/libc/stdio/lib_libvsprintf.c new file mode 100644 index 000000000..9a391610d --- /dev/null +++ b/nuttx/libc/stdio/lib_libvsprintf.c @@ -0,0 +1,1620 @@ +/**************************************************************************** + * libc/stdio/lib_libvsprintf.c + * + * Copyright (C) 2007-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include +#include +#include + +#include + +#include "lib_internal.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ +/* If you have floating point but no fieldwidth, then use a fixed (but + * configurable) floating point precision. + */ + +#if defined(CONFIG_LIBC_FLOATINGPOINT) && \ + defined(CONFIG_NOPRINTF_FIELDWIDTH) && \ + !defined(CONFIG_LIBC_FIXEDPRECISION) +# define CONFIG_LIBC_FIXEDPRECISION 3 +#endif + +#define FLAG_SHOWPLUS 0x01 +#define FLAG_ALTFORM 0x02 +#define FLAG_HASDOT 0x04 +#define FLAG_HASASTERISKWIDTH 0x08 +#define FLAG_HASASTERISKTRUNC 0x10 +#define FLAG_LONGPRECISION 0x20 +#define FLAG_LONGLONGPRECISION 0x40 +#define FLAG_NEGATE 0x80 + +#define SET_SHOWPLUS(f) do (f) |= FLAG_SHOWPLUS; while (0) +#define SET_ALTFORM(f) do (f) |= FLAG_ALTFORM; while (0) +#define SET_HASDOT(f) do (f) |= FLAG_HASDOT; while (0) +#define SET_HASASTERISKWIDTH(f) do (f) |= FLAG_HASASTERISKWIDTH; while (0) +#define SET_HASASTERISKTRUNC(f) do (f) |= FLAG_HASASTERISKTRUNC; while (0) +#define SET_LONGPRECISION(f) do (f) |= FLAG_LONGPRECISION; while (0) +#define SET_LONGLONGPRECISION(f) do (f) |= FLAG_LONGLONGPRECISION; while (0) +#define SET_NEGATE(f) do (f) |= FLAG_NEGATE; while (0) + +#define CLR_SHOWPLUS(f) do (f) &= ~FLAG_SHOWPLUS; while (0) +#define CLR_ALTFORM(f) do (f) &= ~FLAG_ALTFORM; while (0) +#define CLR_HASDOT(f) do (f) &= ~FLAG_HASDOT; while (0) +#define CLR_HASASTERISKWIDTH(f) do (f) &= ~FLAG_HASASTERISKWIDTH; while (0) +#define CLR_HASASTERISKTRUNC(f) do (f) &= ~FLAG_HASASTERISKTRUNC; while (0) +#define CLR_LONGPRECISION(f) do (f) &= ~FLAG_LONGPRECISION; while (0) +#define CLR_LONGLONGPRECISION(f) do (f) &= ~FLAG_LONGLONGPRECISION; while (0) +#define CLR_NEGATE(f) do (f) &= ~FLAG_NEGATE; while (0) +#define CLR_SIGNED(f) do (f) &= ~(FLAG_SHOWPLUS|FLAG_NEGATE); while (0) + +#define IS_SHOWPLUS(f) (((f) & FLAG_SHOWPLUS) != 0) +#define IS_ALTFORM(f) (((f) & FLAG_ALTFORM) != 0) +#define IS_HASDOT(f) (((f) & FLAG_HASDOT) != 0) +#define IS_HASASTERISKWIDTH(f) (((f) & FLAG_HASASTERISKWIDTH) != 0) +#define IS_HASASTERISKTRUNC(f) (((f) & FLAG_HASASTERISKTRUNC) != 0) +#define IS_LONGPRECISION(f) (((f) & FLAG_LONGPRECISION) != 0) +#define IS_LONGLONGPRECISION(f) (((f) & FLAG_LONGLONGPRECISION) != 0) +#define IS_NEGATE(f) (((f) & FLAG_NEGATE) != 0) +#define IS_SIGNED(f) (((f) & (FLAG_SHOWPLUS|FLAG_NEGATE)) != 0) + +/* If CONFIG_ARCH_ROMGETC is defined, then it is assumed that the format + * string data cannot be accessed by simply de-referencing the format string + * pointer. This might be in the case in Harvard architectures where string + * data might be stored in instruction space or if string data were stored + * on some media like EEPROM or external serial FLASH. In all of these cases, + * string data has to be accessed indirectly using the architecture-supplied + * up_romgetc(). The following mechanisms attempt to make these different + * access methods indistinguishable in the following code. + * + * NOTE: It is assumed that string arguments for %s still reside in memory + * that can be directly accessed by de-referencing the string pointer. + */ + +#ifdef CONFIG_ARCH_ROMGETC +# define FMT_TOP ch = up_romgetc(src) /* Loop initialization */ +# define FMT_BOTTOM src++, ch = up_romgetc(src) /* Bottom of a loop */ +# define FMT_CHAR ch /* Access a character */ +# define FMT_NEXT src++; ch = up_romgetc(src) /* Advance to the next character */ +# define FMT_PREV src--; ch = up_romgetc(src) /* Backup to the previous character */ +#else +# define FMT_TOP /* Loop initialization */ +# define FMT_BOTTOM src++ /* Bottom of a loop */ +# define FMT_CHAR *src /* Access a character */ +# define FMT_NEXT src++ /* Advance to the next character */ +# define FMT_PREV src-- /* Backup to the previous character */ +#endif + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +enum +{ + FMT_RJUST = 0, /* Default */ + FMT_LJUST, + FMT_RJUST0, + FMT_CENTER +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/* Pointer to ASCII conversion */ + +#ifdef CONFIG_PTR_IS_NOT_INT +static void ptohex(FAR struct lib_outstream_s *obj, uint8_t flags, FAR void *p); +#ifndef CONFIG_NOPRINTF_FIELDWIDTH +static int getsizesize(uint8_t fmt, uint8_t flags, FAR void *p) +#endif /* CONFIG_NOPRINTF_FIELDWIDTH */ +#endif /* CONFIG_PTR_IS_NOT_INT */ + +/* Unsigned int to ASCII conversion */ + +static void utodec(FAR struct lib_outstream_s *obj, unsigned int n); +static void utohex(FAR struct lib_outstream_s *obj, unsigned int n, uint8_t a); +static void utooct(FAR struct lib_outstream_s *obj, unsigned int n); +static void utobin(FAR struct lib_outstream_s *obj, unsigned int n); +static void utoascii(FAR struct lib_outstream_s *obj, uint8_t fmt, + uint8_t flags, unsigned int lln); + +#ifndef CONFIG_NOPRINTF_FIELDWIDTH +static void fixup(uint8_t fmt, FAR uint8_t *flags, int *n); +static int getusize(uint8_t fmt, uint8_t flags, unsigned int lln); +#endif + +/* Unsigned long int to ASCII conversion */ + +#ifdef CONFIG_LONG_IS_NOT_INT +static void lutodec(FAR struct lib_outstream_s *obj, unsigned long ln); +static void lutohex(FAR struct lib_outstream_s *obj, unsigned long ln, uint8_t a); +static void lutooct(FAR struct lib_outstream_s *obj, unsigned long ln); +static void lutobin(FAR struct lib_outstream_s *obj, unsigned long ln); +static void lutoascii(FAR struct lib_outstream_s *obj, uint8_t fmt, + uint8_t flags, unsigned long ln); +#ifndef CONFIG_NOPRINTF_FIELDWIDTH +static void lfixup(uint8_t fmt, FAR uint8_t *flags, long *ln); +static int getlusize(uint8_t fmt, FAR uint8_t flags, unsigned long ln); +#endif +#endif + +/* Unsigned long long int to ASCII conversions */ + +#ifdef CONFIG_HAVE_LONG_LONG +static void llutodec(FAR struct lib_outstream_s *obj, unsigned long long lln); +static void llutohex(FAR struct lib_outstream_s *obj, unsigned long long lln, uint8_t a); +static void llutooct(FAR struct lib_outstream_s *obj, unsigned long long lln); +static void llutobin(FAR struct lib_outstream_s *obj, unsigned long long lln); +static void llutoascii(FAR struct lib_outstream_s *obj, uint8_t fmt, + uint8_t flags, unsigned long long lln); +#ifndef CONFIG_NOPRINTF_FIELDWIDTH +static void llfixup(uint8_t fmt, FAR uint8_t *flags, FAR long long *lln); +static int getllusize(uint8_t fmt, FAR uint8_t flags, FAR unsigned long long lln); +#endif +#endif + +#ifndef CONFIG_NOPRINTF_FIELDWIDTH +static void prejustify(FAR struct lib_outstream_s *obj, uint8_t fmt, + uint8_t flags, int fieldwidth, int valwidth); +static void postjustify(FAR struct lib_outstream_s *obj, uint8_t fmt, + uint8_t flags, int fieldwidth, int valwidth); +#endif + +/**************************************************************************** + * Global Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Constant Data + ****************************************************************************/ + +static const char g_nullstring[] = "(null)"; + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/* Include floating point functions */ + +#ifdef CONFIG_LIBC_FLOATINGPOINT +# include "stdio/lib_libdtoa.c" +#endif + +/**************************************************************************** + * Name: ptohex + ****************************************************************************/ + +#ifdef CONFIG_PTR_IS_NOT_INT +static void ptohex(FAR struct lib_outstream_s *obj, uint8_t flags, FAR void *p) +{ + union + { + uint32_t dw; + FAR void *p; + } u; + uint8_t bits; + + /* Check for alternate form */ + + if (IS_ALTFORM(flags)) + { + /* Prefix the number with "0x" */ + + obj->put(obj, '0'); + obj->put(obj, 'x'); + } + + u.dw = 0; + u.p = p; + + for (bits = 8*sizeof(void *); bits > 0; bits -= 4) + { + uint8_t nibble = (uint8_t)((u.dw >> (bits - 4)) & 0xf); + if (nibble < 10) + { + obj->put(obj, nibble + '0'); + } + else + { + obj->put(obj, nibble + 'a' - 10); + } + } +} + +/**************************************************************************** + * Name: getpsize + ****************************************************************************/ + +#ifndef CONFIG_NOPRINTF_FIELDWIDTH +static int getpsize(uint8_t flags, FAR void *p) +{ + struct lib_outstream_s nulloutstream; + lib_nulloutstream(&nulloutstream); + + ptohex(&nulloutstream, flags, p); + return nulloutstream.nput; +} + +#endif /* CONFIG_NOPRINTF_FIELDWIDTH */ +#endif /* CONFIG_PTR_IS_NOT_INT */ + +/**************************************************************************** + * Name: utodec + ****************************************************************************/ + +static void utodec(FAR struct lib_outstream_s *obj, unsigned int n) +{ + unsigned int remainder = n % 10; + unsigned int dividend = n / 10; + + if (dividend) + { + utodec(obj, dividend); + } + + obj->put(obj, (remainder + (unsigned int)'0')); +} + +/**************************************************************************** + * Name: utohex + ****************************************************************************/ + +static void utohex(FAR struct lib_outstream_s *obj, unsigned int n, uint8_t a) +{ + bool nonzero = false; + uint8_t bits; + + for (bits = 8*sizeof(unsigned int); bits > 0; bits -= 4) + { + uint8_t nibble = (uint8_t)((n >> (bits - 4)) & 0xf); + if (nibble || nonzero) + { + nonzero = true; + + if (nibble < 10) + { + obj->put(obj, nibble + '0'); + } + else + { + obj->put(obj, nibble + a - 10); + } + } + } + + if (!nonzero) + { + obj->put(obj, '0'); + } +} + +/**************************************************************************** + * Name: utooct + ****************************************************************************/ + +static void utooct(FAR struct lib_outstream_s *obj, unsigned int n) +{ + unsigned int remainder = n & 0x7; + unsigned int dividend = n >> 3; + + if (dividend) + { + utooct(obj, dividend); + } + + obj->put(obj, (remainder + (unsigned int)'0')); +} + +/**************************************************************************** + * Name: utobin + ****************************************************************************/ + +static void utobin(FAR struct lib_outstream_s *obj, unsigned int n) +{ + unsigned int remainder = n & 1; + unsigned int dividend = n >> 1; + + if (dividend) + { + utobin(obj, dividend); + } + + obj->put(obj, (remainder + (unsigned int)'0')); +} + +/**************************************************************************** + * Name: utoascii + ****************************************************************************/ + +static void utoascii(FAR struct lib_outstream_s *obj, uint8_t fmt, uint8_t flags, unsigned int n) +{ + /* Perform the integer conversion according to the format specifier */ + + switch (fmt) + { + case 'd': + case 'i': + /* Signed base 10 */ + { +#ifdef CONFIG_NOPRINTF_FIELDWIDTH + if ((int)n < 0) + { + obj->put(obj, '-'); + n = (unsigned int)(-(int)n); + } + else if (IS_SHOWPLUS(flags)) + { + obj->put(obj, '+'); + } +#endif + /* Convert the unsigned value to a string. */ + + utodec(obj, n); + } + break; + + case 'u': + /* Unigned base 10 */ + { +#ifdef CONFIG_NOPRINTF_FIELDWIDTH + if (IS_SHOWPLUS(flags)) + { + obj->put(obj, '+'); + } +#endif + /* Convert the unsigned value to a string. */ + + utodec(obj, n); + } + break; + +#ifndef CONFIG_PTR_IS_NOT_INT + case 'p': +#endif + case 'x': + case 'X': + /* Hexadecimal */ + { + /* Check for alternate form */ + + if (IS_ALTFORM(flags)) + { + /* Prefix the number with "0x" */ + + obj->put(obj, '0'); + obj->put(obj, 'x'); + } + + /* Convert the unsigned value to a string. */ + + if (fmt == 'X') + { + utohex(obj, n, 'A'); + } + else + { + utohex(obj, n, 'a'); + } + } + break; + + case 'o': + /* Octal */ + { + /* Check for alternate form */ + + if (IS_ALTFORM(flags)) + { + /* Prefix the number with '0' */ + + obj->put(obj, '0'); + } + + /* Convert the unsigned value to a string. */ + + utooct(obj, n); + } + break; + + case 'b': + /* Binary */ + { + /* Convert the unsigned value to a string. */ + + utobin(obj, n); + } + break; + +#ifdef CONFIG_PTR_IS_NOT_INT + case 'p': +#endif + default: + break; + } +} + +/**************************************************************************** + * Name: fixup + ****************************************************************************/ + +#ifndef CONFIG_NOPRINTF_FIELDWIDTH +static void fixup(uint8_t fmt, FAR uint8_t *flags, FAR int *n) +{ + /* Perform the integer conversion according to the format specifier */ + + switch (fmt) + { + case 'd': + case 'i': + /* Signed base 10 */ + + if (*n < 0) + { + SET_NEGATE(*flags); + CLR_SHOWPLUS(*flags); + *n = -*n; + } + break; + + case 'u': + /* Unsigned base 10 */ + break; + + case 'p': + case 'x': + case 'X': + /* Hexadecimal */ + case 'o': + /* Octal */ + case 'b': + /* Binary */ + CLR_SIGNED(*flags); + break; + + default: + break; + } +} + +/**************************************************************************** + * Name: getusize + ****************************************************************************/ + +static int getusize(uint8_t fmt, uint8_t flags, unsigned int n) +{ + struct lib_outstream_s nulloutstream; + lib_nulloutstream(&nulloutstream); + + utoascii(&nulloutstream, fmt, flags, n); + return nulloutstream.nput; +} + +/**************************************************************************** + * Name: getdblsize + ****************************************************************************/ + +#ifdef CONFIG_LIBC_FLOATINGPOINT +static int getdblsize(uint8_t fmt, int trunc, uint8_t flags, double n) +{ + struct lib_outstream_s nulloutstream; + lib_nulloutstream(&nulloutstream); + + lib_dtoa(&nulloutstream, fmt, trunc, flags, n); + return nulloutstream.nput; +} +#endif +#endif /* CONFIG_NOPRINTF_FIELDWIDTH */ + +#ifdef CONFIG_LONG_IS_NOT_INT +/**************************************************************************** + * Name: lutodec + ****************************************************************************/ + +static void lutodec(FAR struct lib_outstream_s *obj, unsigned long n) +{ + unsigned int remainder = n % 10; + unsigned long dividend = n / 10; + + if (dividend) + { + lutodec(obj, dividend); + } + + obj->put(obj, (remainder + (unsigned int)'0')); +} + +/**************************************************************************** + * Name: lutohex + ****************************************************************************/ + +static void lutohex(FAR struct lib_outstream_s *obj, unsigned long n, uint8_t a) +{ + bool nonzero = false; + uint8_t bits; + + for (bits = 8*sizeof(unsigned long); bits > 0; bits -= 4) + { + uint8_t nibble = (uint8_t)((n >> (bits - 4)) & 0xf); + if (nibble || nonzero) + { + nonzero = true; + + if (nibble < 10) + { + obj->put(obj, nibble + '0'); + } + else + { + obj->put(obj, nibble + a - 10); + } + } + } + + if (!nonzero) + { + obj->put(obj, '0'); + } +} + +/**************************************************************************** + * Name: lutooct + ****************************************************************************/ + +static void lutooct(FAR struct lib_outstream_s *obj, unsigned long n) +{ + unsigned int remainder = n & 0x7; + unsigned long dividend = n >> 3; + + if (dividend) + { + lutooct(obj, dividend); + } + + obj->put(obj, (remainder + (unsigned int)'0')); +} + +/**************************************************************************** + * Name: lutobin + ****************************************************************************/ + +static void lutobin(FAR struct lib_outstream_s *obj, unsigned long n) +{ + unsigned int remainder = n & 1; + unsigned long dividend = n >> 1; + + if (dividend) + { + lutobin(obj, dividend); + } + + obj->put(obj, (remainder + (unsigned int)'0')); +} + +/**************************************************************************** + * Name: lutoascii + ****************************************************************************/ + +static void lutoascii(FAR struct lib_outstream_s *obj, uint8_t fmt, uint8_t flags, unsigned long ln) +{ + /* Perform the integer conversion according to the format specifier */ + + switch (fmt) + { + case 'd': + case 'i': + /* Signed base 10 */ + { +#ifdef CONFIG_NOPRINTF_FIELDWIDTH + if ((long)ln < 0) + { + obj->put(obj, '-'); + ln = (unsigned long)(-(long)ln); + } + else if (IS_SHOWPLUS(flags)) + { + obj->put(obj, '+'); + } +#endif + /* Convert the unsigned value to a string. */ + + lutodec(obj, ln); + } + break; + + case 'u': + /* Unigned base 10 */ + { +#ifdef CONFIG_NOPRINTF_FIELDWIDTH + if (IS_SHOWPLUS(flags)) + { + obj->put(obj, '+'); + } +#endif + /* Convert the unsigned value to a string. */ + + lutodec(obj, ln); + } + break; + + case 'x': + case 'X': + /* Hexadecimal */ + { + /* Check for alternate form */ + + if (IS_ALTFORM(flags)) + { + /* Prefix the number with "0x" */ + + obj->put(obj, '0'); + obj->put(obj, 'x'); + } + + /* Convert the unsigned value to a string. */ + + if (fmt == 'X') + { + lutohex(obj, ln, 'A'); + } + else + { + lutohex(obj, ln, 'a'); + } + } + break; + + case 'o': + /* Octal */ + { + /* Check for alternate form */ + + if (IS_ALTFORM(flags)) + { + /* Prefix the number with '0' */ + + obj->put(obj, '0'); + } + + /* Convert the unsigned value to a string. */ + + lutooct(obj, ln); + } + break; + + case 'b': + /* Binary */ + { + /* Convert the unsigned value to a string. */ + + lutobin(obj, ln); + } + break; + + case 'p': + default: + break; + } +} + +/**************************************************************************** + * Name: lfixup + ****************************************************************************/ + +#ifndef CONFIG_NOPRINTF_FIELDWIDTH +static void lfixup(uint8_t fmt, FAR uint8_t *flags, FAR long *ln) +{ + /* Perform the integer conversion according to the format specifier */ + + switch (fmt) + { + case 'd': + case 'i': + /* Signed base 10 */ + + if (*ln < 0) + { + SET_NEGATE(*flags); + CLR_SHOWPLUS(*flags); + *ln = -*ln; + } + break; + + case 'u': + /* Unsigned base 10 */ + break; + + case 'p': + case 'x': + case 'X': + /* Hexadecimal */ + case 'o': + /* Octal */ + case 'b': + /* Binary */ + CLR_SIGNED(*flags); + break; + + default: + break; + } +} + +/**************************************************************************** + * Name: getlusize + ****************************************************************************/ + +static int getlusize(uint8_t fmt, uint8_t flags, unsigned long ln) +{ + struct lib_outstream_s nulloutstream; + lib_nulloutstream(&nulloutstream); + + lutoascii(&nulloutstream, fmt, flags, ln); + return nulloutstream.nput; +} + +#endif /* CONFIG_NOPRINTF_FIELDWIDTH */ +#endif /* CONFIG_LONG_IS_NOT_INT */ + +#ifdef CONFIG_HAVE_LONG_LONG +/**************************************************************************** + * Name: llutodec + ****************************************************************************/ + +static void llutodec(FAR struct lib_outstream_s *obj, unsigned long long n) +{ + unsigned int remainder = n % 10; + unsigned long long dividend = n / 10; + + if (dividend) + { + llutodec(obj, dividend); + } + + obj->put(obj, (remainder + (unsigned int)'0')); +} + +/**************************************************************************** + * Name: llutohex + ****************************************************************************/ + +static void llutohex(FAR struct lib_outstream_s *obj, unsigned long long n, uint8_t a) +{ + bool nonzero = false; + uint8_t bits; + + for (bits = 8*sizeof(unsigned long long); bits > 0; bits -= 4) + { + uint8_t nibble = (uint8_t)((n >> (bits - 4)) & 0xf); + if (nibble || nonzero) + { + nonzero = true; + + if (nibble < 10) + { + obj->put(obj, (nibble + '0')); + } + else + { + obj->put(obj, (nibble + a - 10)); + } + } + } + + if (!nonzero) + { + obj->put(obj, '0'); + } +} + +/**************************************************************************** + * Name: llutooct + ****************************************************************************/ + +static void llutooct(FAR struct lib_outstream_s *obj, unsigned long long n) +{ + unsigned int remainder = n & 0x7; + unsigned long long dividend = n >> 3; + + if (dividend) + { + llutooct(obj, dividend); + } + + obj->put(obj, (remainder + (unsigned int)'0')); +} + +/**************************************************************************** + * Name: llutobin + ****************************************************************************/ + +static void llutobin(FAR struct lib_outstream_s *obj, unsigned long long n) +{ + unsigned int remainder = n & 1; + unsigned long long dividend = n >> 1; + + if (dividend) + { + llutobin(obj, dividend); + } + + obj->put(obj, (remainder + (unsigned int)'0')); +} + +/**************************************************************************** + * Name: llutoascii + ****************************************************************************/ + +static void llutoascii(FAR struct lib_outstream_s *obj, uint8_t fmt, uint8_t flags, unsigned long long lln) +{ + /* Perform the integer conversion according to the format specifier */ + + switch (fmt) + { + case 'd': + case 'i': + /* Signed base 10 */ + { +#ifdef CONFIG_NOPRINTF_FIELDWIDTH + if ((long long)lln < 0) + { + obj->put(obj, '-'); + lln = (unsigned long long)(-(long long)lln); + } + else if (IS_SHOWPLUS(flags)) + { + obj->put(obj, '+'); + } +#endif + /* Convert the unsigned value to a string. */ + + llutodec(obj, (unsigned long long)lln); + } + break; + + case 'u': + /* Unigned base 10 */ + { +#ifdef CONFIG_NOPRINTF_FIELDWIDTH + if (IS_SHOWPLUS(flags)) + { + obj->put(obj, '+'); + } +#endif + /* Convert the unsigned value to a string. */ + + llutodec(obj, (unsigned long long)lln); + } + break; + + case 'x': + case 'X': + /* Hexadecimal */ + { + /* Check for alternate form */ + + if (IS_ALTFORM(flags)) + { + /* Prefix the number with "0x" */ + + obj->put(obj, '0'); + obj->put(obj, 'x'); + } + + /* Convert the unsigned value to a string. */ + + if (fmt == 'X') + { + llutohex(obj, (unsigned long long)lln, 'A'); + } + else + { + llutohex(obj, (unsigned long long)lln, 'a'); + } + } + break; + + case 'o': + /* Octal */ + { + /* Check for alternate form */ + + if (IS_ALTFORM(flags)) + { + /* Prefix the number with '0' */ + + obj->put(obj, '0'); + } + + /* Convert the unsigned value to a string. */ + + llutooct(obj, (unsigned long long)lln); + } + break; + + case 'b': + /* Binary */ + { + /* Convert the unsigned value to a string. */ + + llutobin(obj, (unsigned long long)lln); + } + break; + + case 'p': + default: + break; + } +} + +/**************************************************************************** + * Name: llfixup + ****************************************************************************/ + +#ifndef CONFIG_NOPRINTF_FIELDWIDTH +static void llfixup(uint8_t fmt, FAR uint8_t *flags, FAR long long *lln) +{ + /* Perform the integer conversion according to the format specifier */ + + switch (fmt) + { + case 'd': + case 'i': + /* Signed base 10 */ + + if (*lln < 0) + { + SET_NEGATE(*flags); + CLR_SHOWPLUS(*flags); + *lln = -*lln; + } + break; + + case 'u': + /* Unsigned base 10 */ + break; + + case 'p': + case 'x': + case 'X': + /* Hexadecimal */ + case 'o': + /* Octal */ + case 'b': + /* Binary */ + CLR_SIGNED(*flags); + break; + + default: + break; + } +} + +/**************************************************************************** + * Name: getllusize + ****************************************************************************/ + +static int getllusize(uint8_t fmt, uint8_t flags, unsigned long long lln) +{ + struct lib_outstream_s nulloutstream; + lib_nulloutstream(&nulloutstream); + + + llutoascii(&nulloutstream, fmt, flags, lln); + return nulloutstream.nput; +} + +#endif /* CONFIG_NOPRINTF_FIELDWIDTH */ +#endif /* CONFIG_HAVE_LONG_LONG */ + +/**************************************************************************** + * Name: prejustify + ****************************************************************************/ + +#ifndef CONFIG_NOPRINTF_FIELDWIDTH +static void prejustify(FAR struct lib_outstream_s *obj, uint8_t fmt, + uint8_t flags, int fieldwidth, int valwidth) +{ + int i; + + switch (fmt) + { + default: + case FMT_RJUST: + if (IS_SIGNED(flags)) + { + valwidth++; + } + + for (i = fieldwidth - valwidth; i > 0; i--) + { + obj->put(obj, ' '); + } + + if (IS_NEGATE(flags)) + { + obj->put(obj, '-'); + } + else if (IS_SHOWPLUS(flags)) + { + obj->put(obj, '+'); + } + break; + + case FMT_RJUST0: + if (IS_NEGATE(flags)) + { + obj->put(obj, '-'); + valwidth++; + } + else if (IS_SHOWPLUS(flags)) + { + obj->put(obj, '+'); + valwidth++; + } + + for (i = fieldwidth - valwidth; i > 0; i--) + { + obj->put(obj, '0'); + } + break; + + case FMT_LJUST: + if (IS_NEGATE(flags)) + { + obj->put(obj, '-'); + } + else if (IS_SHOWPLUS(flags)) + { + obj->put(obj, '+'); + } + break; + } +} +#endif + +/**************************************************************************** + * Name: postjustify + ****************************************************************************/ + +#ifndef CONFIG_NOPRINTF_FIELDWIDTH +static void postjustify(FAR struct lib_outstream_s *obj, uint8_t fmt, + uint8_t flags, int fieldwidth, int valwidth) +{ + int i; + + /* Apply field justification to the integer value. */ + + switch (fmt) + { + default: + case FMT_RJUST: + case FMT_RJUST0: + break; + + case FMT_LJUST: + if (IS_SIGNED(flags)) + { + valwidth++; + } + + for (i = fieldwidth - valwidth; i > 0; i--) + { + obj->put(obj, ' '); + } + break; + } +} +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * libc/stdio/lib_vsprintf + ****************************************************************************/ + +int lib_vsprintf(FAR struct lib_outstream_s *obj, FAR const char *src, va_list ap) +{ + FAR char *ptmp; +#ifndef CONFIG_NOPRINTF_FIELDWIDTH + int width; +#ifdef CONFIG_LIBC_FLOATINGPOINT + int trunc; +#endif + uint8_t fmt; +#endif + uint8_t flags; +#ifdef CONFIG_ARCH_ROMGETC + char ch; +#endif + + for (FMT_TOP; FMT_CHAR; FMT_BOTTOM) + { + /* Just copy regular characters */ + + if (FMT_CHAR != '%') + { + /* Output the character */ + + obj->put(obj, FMT_CHAR); + + /* Flush the buffer if a newline is encountered */ + +#ifdef CONFIG_STDIO_LINEBUFFER + if (FMT_CHAR == '\n') + { + /* Should return an error on a failure to flush */ + + (void)obj->flush(obj); + } +#endif + /* Process the next character in the format */ + + continue; + } + + /* We have found a format specifier. Move past it. */ + + FMT_NEXT; + + /* Assume defaults */ + + flags = 0; +#ifndef CONFIG_NOPRINTF_FIELDWIDTH + fmt = FMT_RJUST; + width = 0; +#ifdef CONFIG_LIBC_FLOATINGPOINT + trunc = 0; +#endif +#endif + + /* Process each format qualifier. */ + + for (; FMT_CHAR; FMT_BOTTOM) + { + /* Break out of the loop when the format is known. */ + + if (strchr("diuxXpobeEfgGlLsc%", FMT_CHAR)) + { + break; + } + + /* Check for left justification. */ + + else if (FMT_CHAR == '-') + { +#ifndef CONFIG_NOPRINTF_FIELDWIDTH + fmt = FMT_LJUST; +#endif + } + + /* Check for leading zero fill right justification. */ + + else if (FMT_CHAR == '0') + { +#ifndef CONFIG_NOPRINTF_FIELDWIDTH + fmt = FMT_RJUST0; +#endif + } +#if 0 + /* Center justification. */ + + else if (FMT_CHAR == '~') + { +#ifndef CONFIG_NOPRINTF_FIELDWIDTH + fmt = FMT_CENTER; +#endif + } +#endif + + else if (FMT_CHAR == '*') + { +#ifndef CONFIG_NOPRINTF_FIELDWIDTH + int value = va_arg(ap, int); + if (IS_HASDOT(flags)) + { +#ifdef CONFIG_LIBC_FLOATINGPOINT + trunc = value; + SET_HASASTERISKTRUNC(flags); +#endif + } + else + { + width = value; + SET_HASASTERISKWIDTH(flags); + } +#endif + } + + /* Check for field width */ + + else if (FMT_CHAR >= '1' && FMT_CHAR <= '9') + { +#ifdef CONFIG_NOPRINTF_FIELDWIDTH + do + { + FMT_NEXT; + } + while (FMT_CHAR >= '0' && FMT_CHAR <= '9'); +#else + /* Accumulate the field width integer. */ + + int n = ((int)(FMT_CHAR)) - (int)'0'; + for (;;) + { + FMT_NEXT; + if (FMT_CHAR >= '0' && FMT_CHAR <= '9') + { + n = 10*n + (((int)(FMT_CHAR)) - (int)'0'); + } + else + { + break; + } + } + + if (IS_HASDOT(flags)) + { +#ifdef CONFIG_LIBC_FLOATINGPOINT + trunc = n; +#endif + } + else + { + width = n; + } +#endif + /* Back up to the last digit. */ + + FMT_PREV; + } + + /* Check for a decimal point. */ + + else if (FMT_CHAR == '.') + { +#ifndef CONFIG_NOPRINTF_FIELDWIDTH + SET_HASDOT(flags); +#endif + } + + /* Check for leading plus sign. */ + + else if (FMT_CHAR == '+') + { + SET_SHOWPLUS(flags); + } + + /* Check for alternate form. */ + + else if (FMT_CHAR == '#') + { + SET_ALTFORM(flags); + } + } + + /* "%%" means that a literal '%' was intended (instead of a format + * specification). + */ + + if (FMT_CHAR == '%') + { + obj->put(obj, '%'); + continue; + } + + /* Check for the string format. */ + + if (FMT_CHAR == 's') + { +#ifndef CONFIG_NOPRINTF_FIELDWIDTH + int swidth; +#endif + /* Get the string to output */ + + ptmp = va_arg(ap, char *); + if (!ptmp) + { + ptmp = (char*)g_nullstring; + } + + /* Get the widith of the string and perform right-justification + * operations. + */ + +#ifndef CONFIG_NOPRINTF_FIELDWIDTH + swidth = strlen(ptmp); + prejustify(obj, fmt, 0, width, swidth); +#endif + /* Concatenate the string into the output */ + + while (*ptmp) + { + obj->put(obj, *ptmp); + ptmp++; + } + + /* Perform left-justification operations. */ + +#ifndef CONFIG_NOPRINTF_FIELDWIDTH + postjustify(obj, fmt, 0, width, swidth); +#endif + continue; + } + + /* Check for the character output */ + + else if (FMT_CHAR == 'c') + { + /* Just copy the character into the output. */ + + int n = va_arg(ap, int); + obj->put(obj, n); + continue; + } + + /* Check for the long long prefix. */ + + if (FMT_CHAR == 'L') + { + SET_LONGLONGPRECISION(flags); + FMT_NEXT; + } + else if (FMT_CHAR == 'l') + { + SET_LONGPRECISION(flags); + FMT_NEXT; + if (FMT_CHAR == 'l') + { + SET_LONGLONGPRECISION(flags); + FMT_NEXT; + } + } + + /* Handle integer conversions */ + + if (strchr("diuxXpob", FMT_CHAR)) + { +#ifdef CONFIG_HAVE_LONG_LONG + if (IS_LONGLONGPRECISION(flags) && FMT_CHAR != 'p') + { + long long lln; +#ifndef CONFIG_NOPRINTF_FIELDWIDTH + int lluwidth; +#endif + /* Extract the long long value. */ + + lln = va_arg(ap, long long); + +#ifdef CONFIG_NOPRINTF_FIELDWIDTH + /* Output the number */ + + llutoascii(obj, FMT_CHAR, flags, (unsigned long long)lln); +#else + /* Resolve sign-ness and format issues */ + + llfixup(FMT_CHAR, &flags, &lln); + + /* Get the width of the output */ + + lluwidth = getllusize(FMT_CHAR, flags, lln); + + /* Perform left field justification actions */ + + prejustify(obj, fmt, flags, width, lluwidth); + + /* Output the number */ + + llutoascii(obj, FMT_CHAR, flags, (unsigned long long)lln); + + /* Perform right field justification actions */ + + postjustify(obj, fmt, flags, width, lluwidth); +#endif + } + else +#endif /* CONFIG_HAVE_LONG_LONG */ +#ifdef CONFIG_LONG_IS_NOT_INT + if (IS_LONGPRECISION(flags) && FMT_CHAR != 'p') + { + long ln; +#ifndef CONFIG_NOPRINTF_FIELDWIDTH + int luwidth; +#endif + /* Extract the long value. */ + + ln = va_arg(ap, long); + +#ifdef CONFIG_NOPRINTF_FIELDWIDTH + /* Output the number */ + + lutoascii(obj, FMT_CHAR, flags, (unsigned long)ln); +#else + /* Resolve sign-ness and format issues */ + + lfixup(FMT_CHAR, &flags, &ln); + + /* Get the width of the output */ + + luwidth = getlusize(FMT_CHAR, flags, ln); + + /* Perform left field justification actions */ + + prejustify(obj, fmt, flags, width, luwidth); + + /* Output the number */ + + lutoascii(obj, FMT_CHAR, flags, (unsigned long)ln); + + /* Perform right field justification actions */ + + postjustify(obj, fmt, flags, width, luwidth); +#endif + } + else +#endif /* CONFIG_LONG_IS_NOT_INT */ +#ifdef CONFIG_PTR_IS_NOT_INT + if (FMT_CHAR == 'p') + { + void *p; +#ifndef CONFIG_NOPRINTF_FIELDWIDTH + int pwidth; +#endif + /* Extract the integer value. */ + + p = va_arg(ap, void *); + +#ifdef CONFIG_NOPRINTF_FIELDWIDTH + /* Output the pointer value */ + + ptohex(obj, flags, p); +#else + /* Resolve sign-ness and format issues */ + + lfixup(FMT_CHAR, &flags, &ln); + + /* Get the width of the output */ + + luwidth = getpsize(FMT_CHAR, flags, p); + + /* Perform left field justification actions */ + + prejustify(obj, fmt, flags, width, pwidth); + + /* Output the pointer value */ + + ptohex(obj, flags, p); + + /* Perform right field justification actions */ + + postjustify(obj, fmt, flags, width, pwidth); +#endif + } + else +#endif + { + int n; +#ifndef CONFIG_NOPRINTF_FIELDWIDTH + int uwidth; +#endif + /* Extract the long long value. */ + + n = va_arg(ap, int); + +#ifdef CONFIG_NOPRINTF_FIELDWIDTH + /* Output the number */ + + utoascii(obj, FMT_CHAR, flags, (unsigned int)n); +#else + /* Resolve sign-ness and format issues */ + + fixup(FMT_CHAR, &flags, &n); + + /* Get the width of the output */ + + uwidth = getusize(FMT_CHAR, flags, n); + + /* Perform left field justification actions */ + + prejustify(obj, fmt, flags, width, uwidth); + + /* Output the number */ + + utoascii(obj, FMT_CHAR, flags, (unsigned int)n); + + /* Perform right field justification actions */ + + postjustify(obj, fmt, flags, width, uwidth); +#endif + } + } + + /* Handle floating point conversions */ + +#ifdef CONFIG_LIBC_FLOATINGPOINT + else if (strchr("eEfgG", FMT_CHAR)) + { +#ifndef CONFIG_NOPRINTF_FIELDWIDTH + double dblval = va_arg(ap, double); + int dblsize; + + /* Get the width of the output */ + + dblsize = getdblsize(FMT_CHAR, trunc, flags, dblval); + + /* Perform left field justification actions */ + + prejustify(obj, fmt, 0, width, dblsize); + + /* Output the number */ + + lib_dtoa(obj, FMT_CHAR, trunc, flags, dblval); + + /* Perform right field justification actions */ + + postjustify(obj, fmt, 0, width, dblsize); +#else + /* Output the number with a fixed precision */ + + double dblval = va_arg(ap, double); + lib_dtoa(obj, FMT_CHAR, CONFIG_LIBC_FIXEDPRECISION, flags, dblval); +#endif + } +#endif /* CONFIG_LIBC_FLOATINGPOINT */ + } + + return obj->nput; +} + + diff --git a/nuttx/libc/stdio/lib_lowinstream.c b/nuttx/libc/stdio/lib_lowinstream.c new file mode 100644 index 000000000..7284601e8 --- /dev/null +++ b/nuttx/libc/stdio/lib_lowinstream.c @@ -0,0 +1,102 @@ +/**************************************************************************** + * libc/stdio/lib_lowinstream.c + * + * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include +#include + +#include + +#include "lib_internal.h" + +#ifdef CONFIG_ARCH_LOWGETC + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: lowinstream_getc + ****************************************************************************/ + +static int lowinstream_getc(FAR struct lib_instream_s *this) +{ + int ret; + + DEBUGASSERT(this); + + /* Get the next character from the incoming stream */ + + ret = up_getc(ch) + if (ret != EOF) + { + this->nget++; + } + + return ret; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: lib_lowinstream + * + * Description: + * Initializes a stream for use with low-level, architecture-specific I/O. + * + * Input parameters: + * lowoutstream - User allocated, uninitialized instance of struct + * lib_lowoutstream_s to be initialized. + * + * Returned Value: + * None (User allocated instance initialized). + * + ****************************************************************************/ + +void lib_lowinstream(FAR struct lib_instream_s *stream) +{ + stream->get = lowinstream_getc; + stream->nget = 0; +} + +#endif /* CONFIG_ARCH_LOWGETC */ diff --git a/nuttx/libc/stdio/lib_lowoutstream.c b/nuttx/libc/stdio/lib_lowoutstream.c new file mode 100644 index 000000000..f600bc614 --- /dev/null +++ b/nuttx/libc/stdio/lib_lowoutstream.c @@ -0,0 +1,97 @@ +/**************************************************************************** + * libc/stdio/lib_lowoutstream.c + * + * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#ifdef CONFIG_ARCH_LOWPUTC + +#include +#include +#include +#include + +#include "lib_internal.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: lowoutstream_putc + ****************************************************************************/ + +static void lowoutstream_putc(FAR struct lib_outstream_s *this, int ch) +{ + DEBUGASSERT(this); + + if (up_putc(ch) != EOF) + { + this->nput++; + } +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: lib_lowoutstream + * + * Description: + * Initializes a stream for use with low-level, architecture-specific I/O. + * + * Input parameters: + * lowoutstream - User allocated, uninitialized instance of struct + * lib_lowoutstream_s to be initialized. + * + * Returned Value: + * None (User allocated instance initialized). + * + ****************************************************************************/ + +void lib_lowoutstream(FAR struct lib_outstream_s *stream) +{ + stream->put = lowoutstream_putc; +#ifdef CONFIG_STDIO_LINEBUFFER + stream->flush = lib_noflush; +#endif + stream->nput = 0; +} + +#endif /* CONFIG_ARCH_LOWPUTC */ diff --git a/nuttx/libc/stdio/lib_lowprintf.c b/nuttx/libc/stdio/lib_lowprintf.c new file mode 100644 index 000000000..f7d4ffe2f --- /dev/null +++ b/nuttx/libc/stdio/lib_lowprintf.c @@ -0,0 +1,128 @@ +/**************************************************************************** + * libc/stdio/lib_lowprintf.c + * + * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 +#include +#include +#include "lib_internal.h" + +/* This interface can only be used from within the kernel */ + +#if !defined(CONFIG_NUTTX_KERNEL) || defined(__KERNEL__) + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Global Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Global Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: lib_lowvprintf + ****************************************************************************/ + +#if defined(CONFIG_ARCH_LOWPUTC) || defined(CONFIG_SYSLOG) + +int lib_lowvprintf(const char *fmt, va_list ap) +{ + struct lib_outstream_s stream; + + /* Wrap the stdout in a stream object and let lib_vsprintf do the work. */ + +#ifdef CONFIG_SYSLOG + lib_syslogstream((FAR struct lib_outstream_s *)&stream); +#else + lib_lowoutstream((FAR struct lib_outstream_s *)&stream); +#endif + return lib_vsprintf((FAR struct lib_outstream_s *)&stream, fmt, ap); +} + +/**************************************************************************** + * Name: lib_lowprintf + ****************************************************************************/ + +int lib_lowprintf(const char *fmt, ...) +{ + va_list ap; + int ret; + +#ifdef CONFIG_DEBUG_ENABLE + ret = 0; + if (g_dbgenable) +#endif + { + va_start(ap, fmt); + ret = lib_lowvprintf(fmt, ap); + va_end(ap); + } + + return ret; +} + +#endif /* CONFIG_ARCH_LOWPUTC || CONFIG_SYSLOG */ +#endif /* __KERNEL__ */ diff --git a/nuttx/libc/stdio/lib_meminstream.c b/nuttx/libc/stdio/lib_meminstream.c new file mode 100644 index 000000000..2a30d956d --- /dev/null +++ b/nuttx/libc/stdio/lib_meminstream.c @@ -0,0 +1,104 @@ +/**************************************************************************** + * libc/stdio/lib_meminstream.c + * + * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include "lib_internal.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: meminstream_getc + ****************************************************************************/ + +static int meminstream_getc(FAR struct lib_instream_s *this) +{ + FAR struct lib_meminstream_s *mthis = (FAR struct lib_meminstream_s *)this; + int ret; + + DEBUGASSERT(this); + + /* Get the next character (if any) from the buffer */ + + if (this->nget < mthis->buflen) + { + ret = mthis->buffer[this->nget]; + this->nget++; + } + else + { + ret = EOF; + } + + return ret; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: lib_meminstream + * + * Description: + * Initializes a stream for use with a fixed-size memory buffer. + * + * Input parameters: + * meminstream - User allocated, uninitialized instance of struct + * lib_meminstream_s to be initialized. + * bufstart - Address of the beginning of the fixed-size memory buffer + * buflen - Size of the fixed-sized memory buffer in bytes + * + * Returned Value: + * None (meminstream initialized). + * + ****************************************************************************/ + +void lib_meminstream(FAR struct lib_meminstream_s *meminstream, + FAR const char *bufstart, int buflen) +{ + meminstream->public.get = meminstream_getc; + meminstream->public.nget = 0; /* Will be buffer index */ + meminstream->buffer = bufstart; /* Start of buffer */ + meminstream->buflen = buflen; /* Length of the buffer */ +} + + diff --git a/nuttx/libc/stdio/lib_memoutstream.c b/nuttx/libc/stdio/lib_memoutstream.c new file mode 100644 index 000000000..efd527cbc --- /dev/null +++ b/nuttx/libc/stdio/lib_memoutstream.c @@ -0,0 +1,105 @@ +/**************************************************************************** + * libc/stdio/lib_memoutstream.c + * + * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include "lib_internal.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: memoutstream_putc + ****************************************************************************/ + +static void memoutstream_putc(FAR struct lib_outstream_s *this, int ch) +{ + FAR struct lib_memoutstream_s *mthis = (FAR struct lib_memoutstream_s *)this; + + DEBUGASSERT(this); + + /* If this will not overrun the buffer, then write the character to the + * buffer. Not that buflen was pre-decremented when the stream was + * created so it is okay to write past the end of the buflen by one. + */ + + if (this->nput < mthis->buflen) + { + mthis->buffer[this->nput] = ch; + this->nput++; + mthis->buffer[this->nput] = '\0'; + } +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: lib_memoutstream + * + * Description: + * Initializes a stream for use with a fixed-size memory buffer. + * + * Input parameters: + * memoutstream - User allocated, uninitialized instance of struct + * lib_memoutstream_s to be initialized. + * bufstart - Address of the beginning of the fixed-size memory buffer + * buflen - Size of the fixed-sized memory buffer in bytes + * + * Returned Value: + * None (memoutstream initialized). + * + ****************************************************************************/ + +void lib_memoutstream(FAR struct lib_memoutstream_s *memoutstream, + FAR char *bufstart, int buflen) +{ + memoutstream->public.put = memoutstream_putc; +#ifdef CONFIG_STDIO_LINEBUFFER + memoutstream->public.flush = lib_noflush; +#endif + memoutstream->public.nput = 0; /* Will be buffer index */ + memoutstream->buffer = bufstart; /* Start of buffer */ + memoutstream->buflen = buflen - 1; /* Save space for null terminator */ + memoutstream->buffer[0] = '\0'; /* Start with an empty string */ +} + + diff --git a/nuttx/libc/stdio/lib_nullinstream.c b/nuttx/libc/stdio/lib_nullinstream.c new file mode 100644 index 000000000..aeb0af379 --- /dev/null +++ b/nuttx/libc/stdio/lib_nullinstream.c @@ -0,0 +1,79 @@ +/**************************************************************************** + * libc/stdio/lib_nullinstream.c + * + * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 +#include + +#include "lib_internal.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +static int nullinstream_getc(FAR struct lib_instream_s *this) +{ + return EOF; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: lib_nullinstream + * + * Description: + * Initializes a NULL stream. The initialized stream will will return only + * EOF. + * + * Input parameters: + * nullinstream - User allocated, uninitialized instance of struct + * lib_instream_s to be initialized. + * + * Returned Value: + * None (User allocated instance initialized). + * + ****************************************************************************/ + +void lib_nullinstream(FAR struct lib_instream_s *nullinstream) +{ + nullinstream->get = nullinstream_getc; + nullinstream->nget = 0; +} + diff --git a/nuttx/libc/stdio/lib_nulloutstream.c b/nuttx/libc/stdio/lib_nulloutstream.c new file mode 100644 index 000000000..574295344 --- /dev/null +++ b/nuttx/libc/stdio/lib_nulloutstream.c @@ -0,0 +1,84 @@ +/**************************************************************************** + * libc/stdio/lib_nulloutstream.c + * + * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 +#include +#include + +#include "lib_internal.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +static void nulloutstream_putc(FAR struct lib_outstream_s *this, int ch) +{ + DEBUGASSERT(this); + this->nput++; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: lib_nulloutstream + * + * Description: + * Initializes a NULL streams. The initialized stream will write all data + * to the bit-bucket. + * + * Input parameters: + * nulloutstream - User allocated, uninitialized instance of struct + * lib_outstream_s to be initialized. + * + * Returned Value: + * None (User allocated instance initialized). + * + ****************************************************************************/ + +void lib_nulloutstream(FAR struct lib_outstream_s *nulloutstream) +{ + nulloutstream->put = nulloutstream_putc; +#ifdef CONFIG_STDIO_LINEBUFFER + nulloutstream->flush = lib_noflush; +#endif + nulloutstream->nput = 0; +} + diff --git a/nuttx/libc/stdio/lib_perror.c b/nuttx/libc/stdio/lib_perror.c new file mode 100644 index 000000000..181898329 --- /dev/null +++ b/nuttx/libc/stdio/lib_perror.c @@ -0,0 +1,99 @@ +/**************************************************************************** + * libc/stdio/lib_perror.c + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* POSIX requires that perror provide its output on stderr. This option may + * be defined, however, to provide perror output that is serialized with + * other stdout messages. + */ + +#ifdef CONFIG_LIBC_PERROR_STDOUT +# define PERROR_STREAM stdout +#else +# define PERROR_STREAM stderr +#endif + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: perror + ****************************************************************************/ + +void perror(FAR const char *s) +{ + + /* If strerror() is not enabled, then just print the error number */ + +#ifdef CONFIG_LIBC_STRERROR + (void)fprintf(PERROR_STREAM, "%s: %s\n", s, strerror(errno)); +#else + (void)fprintf(PERROR_STREAM, "%s: Error %d\n", s, errno); +#endif +} + diff --git a/nuttx/libc/stdio/lib_printf.c b/nuttx/libc/stdio/lib_printf.c new file mode 100644 index 000000000..0e90c7ca5 --- /dev/null +++ b/nuttx/libc/stdio/lib_printf.c @@ -0,0 +1,109 @@ +/**************************************************************************** + * libc/stdio/lib_printf.c + * + * Copyright (C) 2007-2008, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Compilation Switches + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include "lib_internal.h" + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Global Function Prototypes + ****************************************************************************/ + +/************************************************************************** + * Global Constant Data + **************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/************************************************************************** + * Private Constant Data + **************************************************************************/ + +/**************************************************************************** + * Private Variables + **************************************************************************/ + +/**************************************************************************** + * Global Functions + **************************************************************************/ + +/**************************************************************************** + * Name: printf + **************************************************************************/ + +int printf(const char *fmt, ...) +{ + va_list ap; + int ret; + + va_start(ap, fmt); +#if CONFIG_NFILE_STREAMS > 0 + ret = vfprintf(stdout, fmt, ap); +#elif CONFIG_NFILE_DESCRIPTORS > 0 + ret = lib_rawvprintf(fmt, ap); +#elif defined(CONFIG_ARCH_LOWPUTC) + ret = lib_lowvprintf(fmt, ap); +#else +# ifdef CONFIG_CPP_HAVE_WARNING +# warning "printf has no data sink" +# endif + ret = 0; +#endif + va_end(ap); + + return ret; +} + diff --git a/nuttx/libc/stdio/lib_puts.c b/nuttx/libc/stdio/lib_puts.c new file mode 100644 index 000000000..53eda7081 --- /dev/null +++ b/nuttx/libc/stdio/lib_puts.c @@ -0,0 +1,130 @@ +/**************************************************************************** + * libc/stdio/lib_puts.c + * + * Copyright (C) 2007, 2008, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Compilation Switches + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include "lib_internal.h" + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Global Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Public Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Public Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: puts + * + * Description: + * puts() writes the string s and a trailing newline to stdout. + * + ****************************************************************************/ + +int puts(FAR const char *s) +{ + FILE *stream = stdout; + int nwritten; + int nput = EOF; + int ret; + + /* Write the string (the next two steps must be atomic) */ + + lib_take_semaphore(stream); + + /* Write the string without its trailing '\0' */ + + nwritten = fputs(s, stream); + if (nwritten > 0) + { + /* Followed by a newline */ + + char newline = '\n'; + ret = lib_fwrite(&newline, 1, stream); + if (ret > 0) + { + nput = nwritten + 1; + + /* Flush the buffer after the newline is output. */ + +#ifdef CONFIG_STDIO_LINEBUFFER + ret = lib_fflush(stream, true); + if (ret < 0) + { + nput = EOF; + } +#endif + } + } + + lib_give_semaphore(stdout); + return nput; +} + diff --git a/nuttx/libc/stdio/lib_rawinstream.c b/nuttx/libc/stdio/lib_rawinstream.c new file mode 100644 index 000000000..55456769e --- /dev/null +++ b/nuttx/libc/stdio/lib_rawinstream.c @@ -0,0 +1,107 @@ +/**************************************************************************** + * libc/stdio/lib_rawinstream.c + * + * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 +#include +#include + +#include "lib_internal.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: rawinstream_getc + ****************************************************************************/ + +static int rawinstream_getc(FAR struct lib_instream_s *this) +{ + FAR struct lib_rawinstream_s *rthis = (FAR struct lib_rawinstream_s *)this; + int nwritten; + char ch; + + DEBUGASSERT(this && rthis->fd >= 0); + + /* Attempt to read one character */ + + nwritten = read(rthis->fd, &ch, 1); + if (nwritten == 1) + { + this->nget++; + return ch; + } + + /* Return EOF on any failure to read from the incoming byte stream. The + * only expected error is EINTR meaning that the read was interrupted + * by a signal. A Zero return value would indicated an end-of-file + * confition. + */ + + return EOF; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: lib_rawinstream + * + * Description: + * Initializes a stream for use with a file descriptor. + * + * Input parameters: + * rawinstream - User allocated, uninitialized instance of struct + * lib_rawinstream_s to be initialized. + * fd - User provided file/socket descriptor (must have been opened + * for the correct access). + * + * Returned Value: + * None (User allocated instance initialized). + * + ****************************************************************************/ + +void lib_rawinstream(FAR struct lib_rawinstream_s *rawinstream, int fd) +{ + rawinstream->public.get = rawinstream_getc; + rawinstream->public.nget = 0; + rawinstream->fd = fd; +} + diff --git a/nuttx/libc/stdio/lib_rawoutstream.c b/nuttx/libc/stdio/lib_rawoutstream.c new file mode 100644 index 000000000..e1fe37134 --- /dev/null +++ b/nuttx/libc/stdio/lib_rawoutstream.c @@ -0,0 +1,115 @@ +/**************************************************************************** + * libc/stdio/lib_rawoutstream.c + * + * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 +#include +#include + +#include "lib_internal.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: rawoutstream_putc + ****************************************************************************/ + +static void rawoutstream_putc(FAR struct lib_outstream_s *this, int ch) +{ + FAR struct lib_rawoutstream_s *rthis = (FAR struct lib_rawoutstream_s *)this; + int nwritten; + char buffer = ch; + + DEBUGASSERT(this && rthis->fd >= 0); + + /* Loop until the character is successfully transferred or until an + * irrecoverable error occurs. + */ + + do + { + nwritten = write(rthis->fd, &buffer, 1); + if (nwritten == 1) + { + this->nput++; + return; + } + + /* The only expected error is EINTR, meaning that the write operation + * was awakened by a signal. Zero would not be a valid return value + * from write(). + */ + + DEBUGASSERT(nwritten < 0); + } + while (get_errno() == EINTR); +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: lib_rawoutstream + * + * Description: + * Initializes a stream for use with a file descriptor. + * + * Input parameters: + * rawoutstream - User allocated, uninitialized instance of struct + * lib_rawoutstream_s to be initialized. + * fd - User provided file/socket descriptor (must have been opened + * for write access). + * + * Returned Value: + * None (User allocated instance initialized). + * + ****************************************************************************/ + +void lib_rawoutstream(FAR struct lib_rawoutstream_s *rawoutstream, int fd) +{ + rawoutstream->public.put = rawoutstream_putc; +#ifdef CONFIG_STDIO_LINEBUFFER + rawoutstream->public.flush = lib_noflush; +#endif + rawoutstream->public.nput = 0; + rawoutstream->fd = fd; +} + diff --git a/nuttx/libc/stdio/lib_rawprintf.c b/nuttx/libc/stdio/lib_rawprintf.c new file mode 100644 index 000000000..98bbbea05 --- /dev/null +++ b/nuttx/libc/stdio/lib_rawprintf.c @@ -0,0 +1,151 @@ +/**************************************************************************** + * libc/stdio/lib_rawprintf.c + * + * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 +#include +#include "lib_internal.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Some output destinations are only available from within the kernel */ + +#if defined(CONFIG_NUTTX_KERNEL) && !defined(__KERNEL__) +# undef CONFIG_SYSLOG +# undef CONFIG_ARCH_LOWPUTC +#endif + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Global Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Global Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: lib_rawvprintf + ****************************************************************************/ + +int lib_rawvprintf(const char *fmt, va_list ap) +{ +#if defined(CONFIG_SYSLOG) + + struct lib_outstream_s stream; + + /* Wrap the low-level output in a stream object and let lib_vsprintf + * do the work. + */ + + lib_syslogstream((FAR struct lib_outstream_s *)&stream); + return lib_vsprintf((FAR struct lib_outstream_s *)&stream, fmt, ap); + +#elif CONFIG_NFILE_DESCRIPTORS > 0 + + struct lib_rawoutstream_s rawoutstream; + + /* Wrap the stdout in a stream object and let lib_vsprintf + * do the work. + */ + + lib_rawoutstream(&rawoutstream, 1); + return lib_vsprintf(&rawoutstream.public, fmt, ap); + +#elif defined(CONFIG_ARCH_LOWPUTC) + + struct lib_outstream_s stream; + + /* Wrap the low-level output in a stream object and let lib_vsprintf + * do the work. + */ + + lib_lowoutstream((FAR struct lib_outstream_s *)&stream); + return lib_vsprintf((FAR struct lib_outstream_s *)&stream, fmt, ap); + +#else + return 0; +#endif +} + +/**************************************************************************** + * Name: lib_rawprintf + ****************************************************************************/ + +int lib_rawprintf(const char *fmt, ...) +{ + va_list ap; + int ret; + +#ifdef CONFIG_DEBUG_ENABLE + ret = 0; + if (g_dbgenable) +#endif + { + va_start(ap, fmt); + ret = lib_rawvprintf(fmt, ap); + va_end(ap); + } + + return ret; +} diff --git a/nuttx/libc/stdio/lib_rdflush.c b/nuttx/libc/stdio/lib_rdflush.c new file mode 100644 index 000000000..c6136792b --- /dev/null +++ b/nuttx/libc/stdio/lib_rdflush.c @@ -0,0 +1,144 @@ +/**************************************************************************** + * libc/stdio/lib_rdflush.c + * + * Copyright (C) 2008, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Compilation Switches + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include + +#include "lib_internal.h" + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Global Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Global Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: lib_rdflush + * + * Description: + * Flush read data from the I/O buffer and adjust the file pointer to + * account for the unread data + * + ****************************************************************************/ + +#if CONFIG_STDIO_BUFFER_SIZE > 0 +int lib_rdflush(FAR FILE *stream) +{ + if (!stream) + { + set_errno(EBADF); + return ERROR; + } + + /* Get exclusive access to the stream */ + + lib_take_semaphore(stream); + + /* If the buffer is currently being used for read access, then discard all + * of the read-ahead data. We do not support concurrent buffered read/write + * access. + */ + + if (stream->fs_bufread != stream->fs_bufstart) + { + /* Now adjust the stream pointer to account for the read-ahead data that + * was not actually read by the user. + */ + +#if CONFIG_NUNGET_CHARS > 0 + off_t rdoffset = stream->fs_bufread - stream->fs_bufpos + stream->fs_nungotten; +#else + off_t rdoffset = stream->fs_bufread - stream->fs_bufpos; +#endif + /* Mark the buffer as empty (do this before calling fseek() because fseek() + * also calls this function). + */ + + stream->fs_bufpos = stream->fs_bufread = stream->fs_bufstart; +#if CONFIG_NUNGET_CHARS > 0 + stream->fs_nungotten = 0; +#endif + /* Then seek to the position corresponding to the last data read by the user */ + + if (fseek(stream, -rdoffset, SEEK_CUR) < 0) + { + lib_give_semaphore(stream); + return ERROR; + } + } + + lib_give_semaphore(stream); + return OK; +} +#endif /* CONFIG_STDIO_BUFFER_SIZE */ + diff --git a/nuttx/libc/stdio/lib_snprintf.c b/nuttx/libc/stdio/lib_snprintf.c new file mode 100644 index 000000000..a4ba0dbb3 --- /dev/null +++ b/nuttx/libc/stdio/lib_snprintf.c @@ -0,0 +1,99 @@ +/**************************************************************************** + * libc/stdio/lib_snprintf.c + * + * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include + +#include "lib_internal.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Global Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Global Functions + ****************************************************************************/ + +/**************************************************************************** + * sprintf + ****************************************************************************/ + +int snprintf(FAR char *buf, size_t size, const char *format, ...) +{ + struct lib_memoutstream_s memoutstream; + va_list ap; + int n; + + /* Initialize a memory stream to write to the buffer */ + + lib_memoutstream((FAR struct lib_memoutstream_s *)&memoutstream, buf, size); + + /* Then let lib_vsprintf do the real work */ + + va_start(ap, format); + n = lib_vsprintf((FAR struct lib_outstream_s *)&memoutstream.public, format, ap); + va_end(ap); + return n; +} diff --git a/nuttx/libc/stdio/lib_sprintf.c b/nuttx/libc/stdio/lib_sprintf.c new file mode 100644 index 000000000..deb0669a3 --- /dev/null +++ b/nuttx/libc/stdio/lib_sprintf.c @@ -0,0 +1,95 @@ +/**************************************************************************** + * libc/stdio/lib_sprintf.c + * + * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 +#include "lib_internal.h" + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Global Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Global Functions + ****************************************************************************/ + +/**************************************************************************** + * sprintf + ****************************************************************************/ + +int sprintf (FAR char *buf, const char *fmt, ...) +{ + struct lib_memoutstream_s memoutstream; + va_list ap; + int n; + + /* Initialize a memory stream to write to the buffer */ + + lib_memoutstream((FAR struct lib_memoutstream_s *)&memoutstream, buf, LIB_BUFLEN_UNKNOWN); + + /* Then let lib_vsprintf do the real work */ + + va_start(ap, fmt); + n = lib_vsprintf((FAR struct lib_outstream_s *)&memoutstream.public, fmt, ap); + va_end(ap); + return n; +} diff --git a/nuttx/libc/stdio/lib_sscanf.c b/nuttx/libc/stdio/lib_sscanf.c new file mode 100644 index 000000000..77a6cf212 --- /dev/null +++ b/nuttx/libc/stdio/lib_sscanf.c @@ -0,0 +1,507 @@ +/**************************************************************************** + * libc/stdio/lib_sscanf.c + * + * Copyright (C) 2007, 2008, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include +#include +#include +#include +#include +#include + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +#define MAXLN 128 + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Global Function Prototypes + ****************************************************************************/ + +int vsscanf(char *buf, const char *fmt, va_list ap); + +/************************************************************************** + * Global Constant Data + **************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/************************************************************************** + * Private Constant Data + **************************************************************************/ + +static const char spaces[] = " \t\n\r\f\v"; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: findwidth + * + * Description: + * Try to figure out the width of the input data. + * + ****************************************************************************/ + +static int findwidth(FAR const char *buf, FAR const char *fmt) +{ + FAR const char *next = fmt + 1; + + /* No... is there a space after the format? Or does the format string end + * here? + */ + + if (isspace(*next) || *next == 0) + { + /* Use the input up until the first white space is encountered. */ + + return strcspn(buf, spaces); + } + + /* No.. Another possibility is the the format character is followed by + * some recognizable delimiting value. + */ + + if (*next != '%') + { + /* If so we will say that the string ends there if we can find that + * delimiter in the input string. + */ + + FAR const char *ptr = strchr(buf, *next); + if (ptr) + { + return (int)(ptr - buf); + } + } + + /* No... the format has not delimiter and is back-to-back with the next + * formats (or no is following by a delimiter that does not exist in the + * input string). At this point we just bail and Use the input up until + * the first white space is encountered. + * + * NOTE: This means that values from the following format may be + * concatenated with the first. This is a bug. We have no generic way of + * determining the width of the data if there is no fieldwith, no space + * separating the input, and no usable delimiter character. + */ + + return strcspn(buf, spaces); +} + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Function: sscanf + * + * Description: + * ANSI standard sscanf implementation. + * + ****************************************************************************/ + +int sscanf(FAR const char *buf, FAR const char *fmt, ...) +{ + va_list ap; + int count; + + va_start(ap, fmt); + count = vsscanf((FAR char*)buf, fmt, ap); + va_end(ap); + return count; +} + +/**************************************************************************** + * Function: vsscanf + * + * Description: + * ANSI standard vsscanf implementation. + * + ****************************************************************************/ + +int vsscanf(FAR char *buf, FAR const char *fmt, va_list ap) +{ + FAR char *bufstart; + FAR char *tv; + FAR const char *tc; + bool lflag; + bool noassign; + int count; + int width; + int base = 10; + char tmp[MAXLN]; + + lvdbg("vsscanf: buf=\"%s\" fmt=\"%s\"\n", buf, fmt); + + /* Remember the start of the input buffer. We will need this for %n + * calculations. + */ + + bufstart = buf; + + /* Parse the format, extracting values from the input buffer as needed */ + + count = 0; + width = 0; + noassign = false; + lflag = false; + + while (*fmt && *buf) + { + /* Skip over white space */ + + while (isspace(*fmt)) + { + fmt++; + } + + /* Check for a conversion specifier */ + + if (*fmt == '%') + { + lvdbg("vsscanf: Specifier found\n"); + + /* Check for qualifiers on the conversion specifier */ + fmt++; + for (; *fmt; fmt++) + { + lvdbg("vsscanf: Processing %c\n", *fmt); + + if (strchr("dibouxcsefgn%", *fmt)) + { + break; + } + + if (*fmt == '*') + { + noassign = true; + } + else if (*fmt == 'l' || *fmt == 'L') + { + /* NOTE: Missing check for long long ('ll') */ + + lflag = true; + } + else if (*fmt >= '1' && *fmt <= '9') + { + for (tc = fmt; isdigit(*fmt); fmt++); + strncpy(tmp, tc, fmt - tc); + tmp[fmt - tc] = '\0'; + width = atoi(tmp); + fmt--; + } + } + + /* Process %s: String conversion */ + + if (*fmt == 's') + { + lvdbg("vsscanf: Performing string conversion\n"); + + while (isspace(*buf)) + { + buf++; + } + + /* Was a fieldwidth specified? */ + + if (!width) + { + /* No... Guess a field width using some heuristics */ + + width = findwidth(buf, fmt); + } + + if (!noassign) + { + tv = va_arg(ap, char*); + strncpy(tv, buf, width); + tv[width] = '\0'; + } + + buf += width; + } + + /* Process %c: Character conversion */ + + else if (*fmt == 'c') + { + lvdbg("vsscanf: Performing character conversion\n"); + + /* Was a fieldwidth specified? */ + + if (!width) + { + /* No, then width is this one single character */ + + width = 1; + } + + if (!noassign) + { + tv = va_arg(ap, char*); + strncpy(tv, buf, width); + tv[width] = '\0'; + } + + buf += width; + } + + /* Process %d, %o, %b, %x, %u: Various integer conversions */ + + else if (strchr("dobxu", *fmt)) + { + lvdbg("vsscanf: Performing integer conversion\n"); + + /* Skip over any white space before the integer string */ + + while (isspace(*buf)) + { + buf++; + } + + /* The base of the integer conversion depends on the specific + * conversion specification. + */ + + if (*fmt == 'd' || *fmt == 'u') + { + base = 10; + } + else if (*fmt == 'x') + { + base = 16; + } + else if (*fmt == 'o') + { + base = 8; + } + else if (*fmt == 'b') + { + base = 2; + } + + /* Was a fieldwidth specified? */ + + if (!width) + { + /* No... Guess a field width using some heuristics */ + + width = findwidth(buf, fmt); + } + + /* Copy the numeric string into a temporary working buffer. */ + + strncpy(tmp, buf, width); + tmp[width] = '\0'; + + lvdbg("vsscanf: tmp[]=\"%s\"\n", tmp); + + /* Perform the integer conversion */ + + buf += width; + if (!noassign) + { +#ifdef SDCC + char *endptr; + long tmplong = strtol(tmp, &endptr, base); +#else + long tmplong = strtol(tmp, NULL, base); +#endif + if (lflag) + { + long *plong = va_arg(ap, long*); + lvdbg("vsscanf: Return %ld to 0x%p\n", tmplong, plong); + *plong = tmplong; + } + else + { + int *pint = va_arg(ap, int*); + lvdbg("vsscanf: Return %ld to 0x%p\n", tmplong, pint); + *pint = (int)tmplong; + } + } + } + + /* Process %f: Floating point conversion */ + + else if (*fmt == 'f') + { +#ifndef CONFIG_LIBC_FLOATINGPOINT + /* No floating point conversions */ + + void *pv = va_arg(ap, void*); + + lvdbg("vsscanf: Return 0.0 to %p\n", pv); + *((double_t*)pv) = 0.0; +#else + lvdbg("vsscanf: Performing floating point conversion\n"); + + /* Skip over any white space before the real string */ + + while (isspace(*buf)) + { + buf++; + } + + /* Was a fieldwidth specified? */ + + if (!width) + { + /* No... Guess a field width using some heuristics */ + + width = findwidth(buf, fmt); + } + + /* Copy the real string into a temporary working buffer. */ + + strncpy(tmp, buf, width); + tmp[width] = '\0'; + buf += width; + + lvdbg("vsscanf: tmp[]=\"%s\"\n", tmp); + + /* Perform the floating point conversion */ + + if (!noassign) + { + /* strtod always returns a double */ +#ifdef SDCC + char *endptr; + double_t dvalue = strtod(tmp,&endptr); +#else + double_t dvalue = strtod(tmp, NULL); +#endif + void *pv = va_arg(ap, void*); + + lvdbg("vsscanf: Return %f to %p\n", dvalue, pv); + + /* But we have to check whether we need to return a + * float or a double. + */ + +#ifdef CONFIG_HAVE_DOUBLE + if (lflag) + { + *((double_t*)pv) = dvalue; + } + else +#endif + { + *((float*)pv) = (float)dvalue; + } + } +#endif + } + + /* Process %n: Character count */ + + else if (*fmt == 'n') + { + lvdbg("vsscanf: Performing character count\n"); + + if (!noassign) + { + size_t nchars = (size_t)(buf - bufstart); + + if (lflag) + { + long *plong = va_arg(ap, long*); + *plong = (long)nchars; + } + else + { + int *pint = va_arg(ap, int*); + *pint = (int)nchars; + } + } + } + + /* Note %n does not count as a conversion */ + + if (!noassign && *fmt != 'n') + { + count++; + } + + width = 0; + noassign = false; + lflag = false; + + fmt++; + } + + /* Its is not a conversion specifier */ + + else + { + while (isspace(*buf)) + { + buf++; + } + + if (*fmt != *buf) + { + break; + } + else + { + fmt++; + buf++; + } + } + } + + return count; +} diff --git a/nuttx/libc/stdio/lib_stdinstream.c b/nuttx/libc/stdio/lib_stdinstream.c new file mode 100644 index 000000000..261b26634 --- /dev/null +++ b/nuttx/libc/stdio/lib_stdinstream.c @@ -0,0 +1,99 @@ +/**************************************************************************** + * libc/stdio/lib_stdinstream.c + * + * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include "lib_internal.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: stdinstream_getc + ****************************************************************************/ + +static int stdinstream_getc(FAR struct lib_instream_s *this) +{ + FAR struct lib_stdinstream_s *sthis = (FAR struct lib_stdinstream_s *)this; + int ret; + + DEBUGASSERT(this); + + /* Get the next character from the incoming stream */ + + ret = getc(sthis->stream); + if (ret != EOF) + { + this->nget++; + } + + return ret; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: lib_stdinstream + * + * Description: + * Initializes a stream for use with a FILE instance. + * + * Input parameters: + * stdinstream - User allocated, uninitialized instance of struct + * lib_stdinstream_s to be initialized. + * stream - User provided stream instance (must have been opened for + * read access). + * + * Returned Value: + * None (User allocated instance initialized). + * + ****************************************************************************/ + +void lib_stdinstream(FAR struct lib_stdinstream_s *stdinstream, + FAR FILE *stream) +{ + stdinstream->public.get = stdinstream_getc; + stdinstream->public.nget = 0; + stdinstream->stream = stream; +} + + diff --git a/nuttx/libc/stdio/lib_stdoutstream.c b/nuttx/libc/stdio/lib_stdoutstream.c new file mode 100644 index 000000000..dfe67271f --- /dev/null +++ b/nuttx/libc/stdio/lib_stdoutstream.c @@ -0,0 +1,147 @@ +/**************************************************************************** + * libc/stdio/lib_stdoutstream.c + * + * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 +#include +#include + +#include "lib_internal.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: stdoutstream_putc + ****************************************************************************/ + +static void stdoutstream_putc(FAR struct lib_outstream_s *this, int ch) +{ + FAR struct lib_stdoutstream_s *sthis = (FAR struct lib_stdoutstream_s *)this; + int result; + + DEBUGASSERT(this && sthis->stream); + + /* Loop until the character is successfully transferred or an irrecoverable + * error occurs. + */ + + do + { + result = fputc(ch, sthis->stream); + if (result != EOF) + { + this->nput++; + return; + } + + /* EINTR (meaning that fputc was interrupted by a signal) is the only + * recoverable error. + */ + } + while (get_errno() == EINTR); +} + +/**************************************************************************** + * Name: stdoutstream_flush + ****************************************************************************/ + +#if defined(CONFIG_STDIO_LINEBUFFER) && CONFIG_STDIO_BUFFER_SIZE > 0 +int stdoutstream_flush(FAR struct lib_outstream_s *this) +{ + FAR struct lib_stdoutstream_s *sthis = (FAR struct lib_stdoutstream_s *)this; + return lib_fflush(sthis->stream, true); +} +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: lib_stdoutstream + * + * Description: + * Initializes a stream for use with a FILE instance. + * + * Input parameters: + * stdoutstream - User allocated, uninitialized instance of struct + * lib_stdoutstream_s to be initialized. + * stream - User provided stream instance (must have been opened for + * write access). + * + * Returned Value: + * None (User allocated instance initialized). + * + ****************************************************************************/ + +void lib_stdoutstream(FAR struct lib_stdoutstream_s *stdoutstream, + FAR FILE *stream) +{ + /* Select the put operation */ + + stdoutstream->public.put = stdoutstream_putc; + + /* Select the correct flush operation. This flush is only called when + * a newline is encountered in the output stream. However, we do not + * want to support this line buffering behavior if the stream was + * opened in binary mode. In binary mode, the newline has no special + * meaning. + */ + +#ifdef CONFIG_STDIO_LINEBUFFER +#if CONFIG_STDIO_BUFFER_SIZE > 0 + if ((stream->fs_oflags & O_BINARY) == 0) + { + stdoutstream->public.flush = stdoutstream_flush; + } + else +#endif + { + stdoutstream->public.flush = lib_noflush; + } +#endif + + /* Set the number of bytes put to zero and remember the stream */ + + stdoutstream->public.nput = 0; + stdoutstream->stream = stream; +} + + diff --git a/nuttx/libc/stdio/lib_syslogstream.c b/nuttx/libc/stdio/lib_syslogstream.c new file mode 100644 index 000000000..5529c5de8 --- /dev/null +++ b/nuttx/libc/stdio/lib_syslogstream.c @@ -0,0 +1,122 @@ +/**************************************************************************** + * libc/stdio/lib_syslogstream.c + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include +#include + +#include + +#include "lib_internal.h" + +#ifdef CONFIG_SYSLOG + +/**************************************************************************** + * Pre-processor definition + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: syslogstream_putc + ****************************************************************************/ + +static void syslogstream_putc(FAR struct lib_outstream_s *this, int ch) +{ + int ret; + + /* Try writing until the write was successful or until an irrecoverable + * error occurs. + */ + + do + { + /* Write the character to the supported logging device */ + + ret = syslog_putc(ch); + if (ret == OK) + { + this->nput++; + return; + } + + /* On failure syslog_putc will return a negated errno value. The + * errno variable will not be set. The special value -EINTR means that + * syslog_putc() was awakened by a signal. This is not a real error and + * must be ignored in this context. + */ + } + while (ret == -EINTR); +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: lib_syslogstream + * + * Description: + * Initializes a stream for use with the configured syslog interface. + * + * Input parameters: + * lowoutstream - User allocated, uninitialized instance of struct + * lib_lowoutstream_s to be initialized. + * + * Returned Value: + * None (User allocated instance initialized). + * + ****************************************************************************/ + +void lib_syslogstream(FAR struct lib_outstream_s *stream) +{ + stream->put = syslogstream_putc; +#ifdef CONFIG_STDIO_LINEBUFFER + stream->flush = lib_noflush; +#endif + stream->nput = 0; +} + +#endif /* CONFIG_SYSLOG */ + + diff --git a/nuttx/libc/stdio/lib_ungetc.c b/nuttx/libc/stdio/lib_ungetc.c new file mode 100644 index 000000000..178aeddd1 --- /dev/null +++ b/nuttx/libc/stdio/lib_ungetc.c @@ -0,0 +1,121 @@ +/**************************************************************************** + * libc/stdio/lib_ungetc.c + * + * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Compilation Switches + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include +#include +#include +#include "lib_internal.h" + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Global Function Prototypes + ****************************************************************************/ + +/************************************************************************** + * Global Constant Data + **************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/************************************************************************** + * Private Constant Data + **************************************************************************/ + +/**************************************************************************** + * Private Variables + **************************************************************************/ + +/**************************************************************************** + * Public Functions + **************************************************************************/ + +/**************************************************************************** + * Name: ungetc + **************************************************************************/ + +int ungetc(int c, FAR FILE *stream) +{ +#if CONFIG_NUNGET_CHARS > 0 + int nungotten; +#endif + + /* Stream must be open for read access */ + + if ((stream && stream->fs_filedes < 0) || + ((stream->fs_oflags & O_RDOK) == 0)) + { + set_errno(EBADF); + return EOF; + } + +#if CONFIG_NUNGET_CHARS > 0 + nungotten = stream->fs_nungotten; + if (stream->fs_nungotten < CONFIG_NUNGET_CHARS) + { + stream->fs_ungotten[nungotten] = c; + stream->fs_nungotten = nungotten + 1; + return c; + } + else +#endif + { + set_errno(ENOMEM); + return EOF; + } +} + diff --git a/nuttx/libc/stdio/lib_vfprintf.c b/nuttx/libc/stdio/lib_vfprintf.c new file mode 100644 index 000000000..cd117ddc3 --- /dev/null +++ b/nuttx/libc/stdio/lib_vfprintf.c @@ -0,0 +1,102 @@ +/**************************************************************************** + * libc/stdio/lib_vfprintf.c + * + * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include + +#include "lib_internal.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Global Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +int vfprintf(FAR FILE *stream, FAR const char *fmt, va_list ap) +{ + struct lib_stdoutstream_s stdoutstream; + int n = ERROR; + + if (stream) + { + /* Wrap the stream in a stream object and let lib_vsprintf + * do the work. + */ + + lib_stdoutstream(&stdoutstream, stream); + + /* Hold the stream semaphore throughout the lib_vsprintf + * call so that this thread can get its entire message out + * before being pre-empted by the next thread. + */ + + lib_take_semaphore(stream); + n = lib_vsprintf(&stdoutstream.public, fmt, ap); + lib_give_semaphore(stream); + } + return n; +} diff --git a/nuttx/libc/stdio/lib_vprintf.c b/nuttx/libc/stdio/lib_vprintf.c new file mode 100644 index 000000000..6ddfe2b24 --- /dev/null +++ b/nuttx/libc/stdio/lib_vprintf.c @@ -0,0 +1,92 @@ +/**************************************************************************** + * libc/stdio/lib_vprintf.c + * + * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Compilation Switches + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Global Function Prototypes + ****************************************************************************/ + +/************************************************************************** + * Global Constant Data + **************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/************************************************************************** + * Private Constant Data + **************************************************************************/ + +/**************************************************************************** + * Private Variables + **************************************************************************/ + +/**************************************************************************** + * Public Functions + **************************************************************************/ + +/**************************************************************************** + * Name: vprintf + **************************************************************************/ + +int vprintf(FAR const char *fmt, va_list ap) +{ + /* vfprintf into stdout */ + + return vfprintf(stdout, fmt, ap); +} + diff --git a/nuttx/libc/stdio/lib_vsnprintf.c b/nuttx/libc/stdio/lib_vsnprintf.c new file mode 100644 index 000000000..f7fd02e42 --- /dev/null +++ b/nuttx/libc/stdio/lib_vsnprintf.c @@ -0,0 +1,96 @@ +/**************************************************************************** + * libc/stdio/lib_vsnprintf.c + * + * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include + +#include "lib_internal.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Global Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: vsnprintf + ****************************************************************************/ + +int vsnprintf(FAR char *buf, size_t size, const char *format, va_list ap) +{ + struct lib_memoutstream_s memoutstream; + int n; + + /* Initialize a memory stream to write to the buffer */ + + lib_memoutstream((FAR struct lib_memoutstream_s *)&memoutstream, buf, size); + + /* Then let lib_vsprintf do the real work */ + + n = lib_vsprintf((FAR struct lib_outstream_s *)&memoutstream.public, format, ap); + return n; +} diff --git a/nuttx/libc/stdio/lib_vsprintf.c b/nuttx/libc/stdio/lib_vsprintf.c new file mode 100644 index 000000000..b6d80808f --- /dev/null +++ b/nuttx/libc/stdio/lib_vsprintf.c @@ -0,0 +1,92 @@ +/**************************************************************************** + * libc/stdio/lib_vsprintf.c + * + * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include + +#include "lib_internal.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Global Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: vsprintf + ****************************************************************************/ + +int vsprintf(FAR char *dest, const char *src, va_list ap) +{ + struct lib_memoutstream_s memoutstream; + + /* Wrap the destination buffer in a stream object and let + * libc/stdio/lib_vsprintf do the work. + */ + + lib_memoutstream((FAR struct lib_memoutstream_s *)&memoutstream, dest, LIB_BUFLEN_UNKNOWN); + return lib_vsprintf((FAR struct lib_outstream_s *)&memoutstream.public, src, ap); +} diff --git a/nuttx/libc/stdio/lib_wrflush.c b/nuttx/libc/stdio/lib_wrflush.c new file mode 100644 index 000000000..40b8e38c8 --- /dev/null +++ b/nuttx/libc/stdio/lib_wrflush.c @@ -0,0 +1,134 @@ +/**************************************************************************** + * libc/stdio/lib_wrflush.c + * + * Copyright (C) 2008-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include +#include + +#include "lib_internal.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Global Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: lib_wrflush + * + * Description: + * This is simply a version of fflush that does not report an error if + * the file is not open for writing. + * + ****************************************************************************/ + +int lib_wrflush(FAR FILE *stream) +{ +#if CONFIG_STDIO_BUFFER_SIZE > 0 + /* Verify that we were passed a valid (i.e., non-NULL) stream */ + +#ifdef CONFIG_DEBUG + if (!stream) + { + return -EINVAL; + } +#endif + + /* Verify that the stream is opened for writing... lib_fflush will + * return an error if it is called for a stream that is not opened for + * writing. Check that first so that this function will not fail in + * that case. + */ + + if ((stream->fs_oflags & O_WROK) == 0) + { + /* Report that the success was successful if we attempt to flush a + * read-only stream. + */ + + return OK; + } + + /* Flush the stream. Return success if there is no buffered write data + * -- i.e., that the stream is opened for writing and that all of the + * buffered write data was successfully flushed by lib_fflush(). + */ + + return lib_fflush(stream, true); +#else + /* Verify that we were passed a valid (i.e., non-NULL) stream */ + +#ifdef CONFIG_DEBUG + if (!stream) + { + return -EINVAL; + } +#endif + + return OK; +#endif +} diff --git a/nuttx/libc/stdio/lib_zeroinstream.c b/nuttx/libc/stdio/lib_zeroinstream.c new file mode 100644 index 000000000..a52ecc1d0 --- /dev/null +++ b/nuttx/libc/stdio/lib_zeroinstream.c @@ -0,0 +1,79 @@ +/**************************************************************************** + * libc/stdio/lib_zeroinstream.c + * + * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 +#include +#include "lib_internal.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +static int zeroinstream_getc(FAR struct lib_instream_s *this) +{ + this->nget++; + return 0; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: lib_zeroinstream + * + * Description: + * Initializes a NULL stream. The initialized stream will return an + * infinitely long stream of zeroes. + * + * Input parameters: + * zeroinstream - User allocated, uninitialized instance of struct + * lib_instream_s to be initialized. + * + * Returned Value: + * None (User allocated instance initialized). + * + ****************************************************************************/ + +void lib_zeroinstream(FAR struct lib_instream_s *zeroinstream) +{ + zeroinstream->get = zeroinstream_getc; + zeroinstream->nget = 0; +} + diff --git a/nuttx/libc/stdlib/Make.defs b/nuttx/libc/stdlib/Make.defs new file mode 100644 index 000000000..dcc4dab26 --- /dev/null +++ b/nuttx/libc/stdlib/Make.defs @@ -0,0 +1,44 @@ +############################################################################ +# libc/stdlib/Make.defs +# +# Copyright (C) 2012 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# 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. +# +############################################################################ + +# Add the stdlib C files to the build + +CSRCS += lib_abs.c lib_abort.c lib_imaxabs.c lib_labs.c lib_llabs.c \ + lib_rand.c lib_qsort.c + +# Add the stdlib directory to the build + +DEPPATH += --dep-path stdlib +VPATH += :stdlib diff --git a/nuttx/libc/stdlib/lib_abort.c b/nuttx/libc/stdlib/lib_abort.c new file mode 100644 index 000000000..1c7442c7f --- /dev/null +++ b/nuttx/libc/stdlib/lib_abort.c @@ -0,0 +1,121 @@ +/************************************************************************ + * libc/stdlib/lib_abort.c + * + * Copyright (C) 2007, 2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include + +/************************************************************************ + * Pre-processor Definitions + ************************************************************************/ + +/************************************************************************ + * Private Type Declarations + ************************************************************************/ + +/************************************************************************ + * Global Variables + ************************************************************************/ + +/************************************************************************ + * Private Variables + ************************************************************************/ + +/************************************************************************ + * Private Function Prototypes + ************************************************************************/ + +/************************************************************************ + * Private Functions + ************************************************************************/ + +/************************************************************************ + * Public Functions + ************************************************************************/ + +/************************************************************************ + * Name: Abort + * + * Description: + * The abort() first unblocks the SIGABRT signal, and then raises that + * signal for the calling process. This results in the abnormal + * termination of the process unless the SIGABRT signal is caught and + * the signal handler does not return. + * + * If the abort() function causes process termination, all open + * streams are closed and flushed. + * + * If the SIGABRT signal is ignored, or caught by a handler that + * returns, the abort() function will still terminate the process. + * It does this by restoring the default disposition for SIGABRT and + * then raising the signal for a second time. + * + * Input parameters: + * None + * + * Returned Value: + * This function does not return, + * + ************************************************************************/ + +void abort(void) +{ + /* NuttX does not support standard signal functionality (like the + * behavior of the SIGABRT signal). So no attempt is made to provide + * a conformant version of abort() at this time. This version does not + * signal the calling thread all. + * + * Note that pthread_exit() is called instead of exit(). That is because + * we do no know if abort was called from a pthread or a normal thread + * (we could find out, of course). If abort() is called from a non-pthread, + * then pthread_exit() should fail and fall back to call exit() anyway. + * + * If exit() is called (either below or via pthread_exit()), then exit() + * will flush and close all open files and terminate the thread. If this + * function was called from a pthread, then pthread_exit() will complete + * any joins, but will not flush or close any streams. + */ + +#ifdef CONFIG_DISABLE_PTHREAD + exit(EXIT_FAILURE); +#else + pthread_exit(NULL); +#endif +} diff --git a/nuttx/libc/stdlib/lib_abs.c b/nuttx/libc/stdlib/lib_abs.c new file mode 100644 index 000000000..a4e4ec669 --- /dev/null +++ b/nuttx/libc/stdlib/lib_abs.c @@ -0,0 +1,54 @@ +/************************************************************************ + * libc/stdlib/lib_abs.c + * + * Copyright (C) 2010-2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 +#include + +/************************************************************************ + * Global Functions + ************************************************************************/ + +int abs(int j) +{ + if (j < 0) + { + j = -j; + } + return j; +} diff --git a/nuttx/libc/stdlib/lib_imaxabs.c b/nuttx/libc/stdlib/lib_imaxabs.c new file mode 100644 index 000000000..d36504372 --- /dev/null +++ b/nuttx/libc/stdlib/lib_imaxabs.c @@ -0,0 +1,54 @@ +/************************************************************************ + * libc/stdlib//lib_abs.c + * + * Copyright (C) 2010-2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 +#include + +/************************************************************************ + * Global Functions + ************************************************************************/ + +intmax_t imaxabs(intmax_t j) +{ + if (j < 0) + { + j = -j; + } + return j; +} diff --git a/nuttx/libc/stdlib/lib_labs.c b/nuttx/libc/stdlib/lib_labs.c new file mode 100644 index 000000000..7cf92a0a1 --- /dev/null +++ b/nuttx/libc/stdlib/lib_labs.c @@ -0,0 +1,54 @@ +/************************************************************************ + * libc/stdlib/lib_labs.c + * + * Copyright (C) 2010-2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 +#include + +/************************************************************************ + * Global Functions + ************************************************************************/ + +long int labs(long int j) +{ + if (j < 0) + { + j = -j; + } + return j; +} diff --git a/nuttx/libc/stdlib/lib_llabs.c b/nuttx/libc/stdlib/lib_llabs.c new file mode 100644 index 000000000..3630d1716 --- /dev/null +++ b/nuttx/libc/stdlib/lib_llabs.c @@ -0,0 +1,57 @@ +/************************************************************************ + * libc/stdlib/lib_llabs.c + * + * Copyright (C) 2010-2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 +#include +#include + +/************************************************************************ + * Global Functions + ************************************************************************/ + +#ifdef CONFIG_HAVE_LONG_LONG +long long int llabs(long long int j) +{ + if (j < 0) + { + j = -j; + } + return j; +} +#endif diff --git a/nuttx/libc/stdlib/lib_qsort.c b/nuttx/libc/stdlib/lib_qsort.c new file mode 100644 index 000000000..021e782d4 --- /dev/null +++ b/nuttx/libc/stdlib/lib_qsort.c @@ -0,0 +1,238 @@ +/**************************************************************************** + * libc/stdlib/lib_qsort.c + * + * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Leveraged from: + * + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * 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. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University 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 REGENTS 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 REGENTS 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 + +#include +#include + +/**************************************************************************** + * Preprocessor Definitions + ****************************************************************************/ + +#define min(a, b) (a) < (b) ? a : b + +#define swapcode(TYPE, parmi, parmj, n) \ + { \ + long i = (n) / sizeof (TYPE); \ + register TYPE *pi = (TYPE *) (parmi); \ + register TYPE *pj = (TYPE *) (parmj); \ + do { \ + register TYPE t = *pi; \ + *pi++ = *pj; \ + *pj++ = t; \ + } while (--i > 0); \ + } + +#define SWAPINIT(a, size) \ + swaptype = ((char *)a - (char *)0) % sizeof(long) || \ + size % sizeof(long) ? 2 : size == sizeof(long)? 0 : 1; + +#define swap(a, b) \ + if (swaptype == 0) \ + { \ + long t = *(long *)(a); \ + *(long *)(a) = *(long *)(b); \ + *(long *)(b) = t; \ + } \ + else \ + { \ + swapfunc(a, b, size, swaptype); \ + } + +#define vecswap(a, b, n) if ((n) > 0) swapfunc(a, b, n, swaptype) + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static inline void swapfunc(char *a, char *b, int n, int swaptype); +static inline char *med3(char *a, char *b, char *c, + int (*compar)(const void *, const void *)); + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +static inline void swapfunc(char *a, char *b, int n, int swaptype) +{ + if(swaptype <= 1) + { + swapcode(long, a, b, n) + } + else + { + swapcode(char, a, b, n) + } +} + +static inline char *med3(char *a, char *b, char *c, + int (*compar)(const void *, const void *)) +{ + return compar(a, b) < 0 ? + (compar(b, c) < 0 ? b : (compar(a, c) < 0 ? c : a )) + :(compar(b, c) > 0 ? b : (compar(a, c) < 0 ? a : c )); +} + +/**************************************************************************** + * Public Function + ****************************************************************************/ + +/**************************************************************************** + * Name: qsort + * + * Description: + * Qsort routine from Bentley & McIlroy's "Engineering a Sort Function". + * + ****************************************************************************/ + +void qsort(void *base, size_t nmemb, size_t size, + int(*compar)(const void *, const void *)) +{ + char *pa, *pb, *pc, *pd, *pl, *pm, *pn; + int d, r, swaptype, swap_cnt; + +loop: + SWAPINIT(base, size); + swap_cnt = 0; + if (nmemb < 7) + { + for (pm = (char *) base + size; pm < (char *) base + nmemb * size; pm += size) + { + for (pl = pm; pl > (char *) base && compar(pl - size, pl) > 0; pl -= size) + { + swap(pl, pl - size); + } + } + return; + } + + pm = (char *) base + (nmemb / 2) * size; + if (nmemb > 7) + { + pl = base; + pn = (char *) base + (nmemb - 1) * size; + if (nmemb > 40) + { + d = (nmemb / 8) * size; + pl = med3(pl, pl + d, pl + 2 * d, compar); + pm = med3(pm - d, pm, pm + d, compar); + pn = med3(pn - 2 * d, pn - d, pn, compar); + } + pm = med3(pl, pm, pn, compar); + } + swap(base, pm); + pa = pb = (char *) base + size; + + pc = pd = (char *) base + (nmemb - 1) * size; + for (;;) + { + while (pb <= pc && (r = compar(pb, base)) <= 0) + { + if (r == 0) + { + swap_cnt = 1; + swap(pa, pb); + pa += size; + } + pb += size; + } + while (pb <= pc && (r = compar(pc, base)) >= 0) + { + if (r == 0) + { + swap_cnt = 1; + swap(pc, pd); + pd -= size; + } + pc -= size; + } + + if (pb > pc) + { + break; + } + + swap(pb, pc); + swap_cnt = 1; + pb += size; + pc -= size; + } + + if (swap_cnt == 0) + { + /* Switch to insertion sort */ + + for (pm = (char *) base + size; pm < (char *) base + nmemb * size; pm += size) + { + for (pl = pm; pl > (char *) base && compar(pl - size, pl) > 0; pl -= size) + { + swap(pl, pl - size); + } + } + return; + } + + pn = (char *) base + nmemb * size; + r = min(pa - (char *)base, pb - pa); + vecswap(base, pb - r, r); + r = min(pd - pc, pn - pd - size); + vecswap(pb, pn - r, r); + + if ((r = pb - pa) > size) + { + qsort(base, r / size, size, compar); + } + + if ((r = pd - pc) > size) + { + /* Iterate rather than recurse to save stack space */ + base = pn - r; + nmemb = r / size; + goto loop; + } +} + diff --git a/nuttx/libc/string/Make.defs b/nuttx/libc/string/Make.defs new file mode 100644 index 000000000..311c8afd2 --- /dev/null +++ b/nuttx/libc/string/Make.defs @@ -0,0 +1,58 @@ +############################################################################ +# libc/string/Make.defs +# +# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# 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. +# +############################################################################ + +# Add the string C files to the build + +CSRCS += lib_checkbase.c lib_isbasedigit.c lib_memset.c lib_memchr.c \ + lib_memccpy.c lib_memcmp.c lib_memmove.c lib_skipspace.c \ + lib_strcasecmp.c lib_strcat.c lib_strchr.c lib_strcpy.c lib_strcmp.c \ + lib_strcspn.c lib_strdup.c lib_strerror.c lib_strlen.c lib_strnlen.c \ + lib_strncasecmp.c lib_strncat.c lib_strncmp.c lib_strncpy.c \ + lib_strndup.c lib_strcasestr.c lib_strpbrk.c lib_strrchr.c\ + lib_strspn.c lib_strstr.c lib_strtok.c lib_strtokr.c lib_strtol.c \ + lib_strtoll.c lib_strtoul.c lib_strtoull.c lib_strtod.c + +ifneq ($(CONFIG_ARCH_MEMCPY),y) +ifeq ($(CONFIG_MEMCPY_VIK),y) +CSRCS += lib_vikmemcpy.c +else +CSRCS += lib_memcpy.c +endif +endif + +# Add the string directory to the build + +DEPPATH += --dep-path string +VPATH += :string diff --git a/nuttx/libc/string/lib_checkbase.c b/nuttx/libc/string/lib_checkbase.c new file mode 100644 index 000000000..32ae58dca --- /dev/null +++ b/nuttx/libc/string/lib_checkbase.c @@ -0,0 +1,115 @@ +/**************************************************************************** + * libc/string/lib_checkbase.c + * + * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include + +#include "lib_internal.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: lib_checkbase + * + * Description: + * This is part of the strol() family implementation. This function checks + * the initial part of a string to see if it can determine the numeric + * base that is represented. + * + * Assumptions: + * *ptr points to the first, non-whitespace character in the string. + * + ****************************************************************************/ + +int lib_checkbase(int base, const char **pptr) +{ + const char *ptr = *pptr; + + /* Check for unspecified base */ + + if (!base) + { + /* Assume base 10 */ + + base = 10; + + /* Check for leading '0' - that would signify octal or hex (or binary) */ + + if (*ptr == '0') + { + /* Assume octal */ + + base = 8; + ptr++; + + /* Check for hexidecimal */ + + if ((*ptr == 'X' || *ptr == 'x') && + lib_isbasedigit(ptr[1], 16, NULL)) + { + base = 16; + ptr++; + } + } + } + + /* If it a hexidecimal representation, than discard any leading "0X" or "0x" */ + + else if (base == 16) + { + if (ptr[0] == '0' && (ptr[1] == 'X' || ptr[1] == 'x')) + { + ptr += 2; + } + } + + /* Return the updated pointer and base */ + + *pptr = ptr; + return base; +} + diff --git a/nuttx/libc/string/lib_isbasedigit.c b/nuttx/libc/string/lib_isbasedigit.c new file mode 100644 index 000000000..dff813881 --- /dev/null +++ b/nuttx/libc/string/lib_isbasedigit.c @@ -0,0 +1,105 @@ +/**************************************************************************** + * libc/string/lib_isbasedigit.c + * + * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include +#include + +#include "lib_internal.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: lib_isbasedigit + * + * Description: + * Given an ASCII character, ch, and a base (1-36) do two + * things: 1) Determine if ch is a valid charcter, and 2) + * convert ch to its binary value. + * + ****************************************************************************/ + +bool lib_isbasedigit(int ch, int base, int *value) +{ + bool ret = false; + int tmp = 0; + + if (base <= 10) + { + if (ch >= '0' && ch <= base + '0' - 1) + { + tmp = ch - '0'; + ret = true; + } + } + else if (base <= 36) + { + if (ch >= '0' && ch <= '9') + { + tmp = ch - '0'; + ret = true; + } + else if (ch >= 'a' && ch <= 'a' + base - 11) + { + tmp = ch - 'a' + 10; + ret = true; + } + else if (ch >= 'A' && ch <= 'A' + base - 11) + { + tmp = ch - 'A' + 10; + ret = true; + } + } + + if (value) + { + *value = tmp; + } + return ret; +} + + diff --git a/nuttx/libc/string/lib_memccpy.c b/nuttx/libc/string/lib_memccpy.c new file mode 100644 index 000000000..1d77f58fe --- /dev/null +++ b/nuttx/libc/string/lib_memccpy.c @@ -0,0 +1,99 @@ +/**************************************************************************** + * libc/string/lib_memccpy.c + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Compilation Switches + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include + +/**************************************************************************** + * Global Functions + ****************************************************************************/ + + +/**************************************************************************** + * Name: memccpy + * + * Description: + * The memccpy() function copies bytes from memory area s2 into s1, + * stopping after the first occurrence of byte c (converted to an unsigned + * char) is copied, or after n bytes are copied, whichever comes first. If + * copying takes place between objects that overlap, the behavior is + * undefined. + * + * Returned Value: + * The memccpy() function returns a pointer to the byte after the copy of c + * in s1, or a null pointer if c was not found in the first n bytes of s2. + * + ****************************************************************************/ + +FAR void *memccpy(FAR void *s1, FAR const void *s2, int c, size_t n) +{ + FAR unsigned char *pout = (FAR unsigned char*)s1; + FAR unsigned char *pin = (FAR unsigned char*)s2; + + /* Copy at most n bytes */ + + while (n-- > 0) + { + /* Copy one byte */ + + *pout = *pin++; + + /* Did we just copy the terminating byte c? */ + + if (*pout == (unsigned char)c) + { + /* Yes return a pointer to the byte after the copy of c into s1 */ + + return (FAR void *)pout; + } + + /* No increment to the next destination location */ + + pout++; + } + + /* C was not found in the first n bytes of s2 */ + + return NULL; +} diff --git a/nuttx/libc/string/lib_memchr.c b/nuttx/libc/string/lib_memchr.c new file mode 100644 index 000000000..0ac609104 --- /dev/null +++ b/nuttx/libc/string/lib_memchr.c @@ -0,0 +1,80 @@ +/**************************************************************************** + * libc/string/lib_memchr.c + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include + +/**************************************************************************** + * Global Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: memchr + * + * Description: + * The memchr() function locates the first occurrence of 'c' (converted to + * an unsigned char) in the initial 'n' bytes (each interpreted as + * unsigned char) of the object pointed to by s. + * + * Returned Value: + * The memchr() function returns a pointer to the located byte, or a null + * pointer if the byte does not occur in the object. + * + ****************************************************************************/ + +FAR void *memchr(FAR const void *s, int c, size_t n) +{ + FAR const unsigned char *p = (FAR const unsigned char *)s; + + if (s) + { + while (n--) + { + if (*p == (unsigned char)c) + { + return (FAR void *)p; + } + + p++; + } + } + + return NULL; +} diff --git a/nuttx/libc/string/lib_memcpy.c b/nuttx/libc/string/lib_memcpy.c new file mode 100644 index 000000000..2ebd5beee --- /dev/null +++ b/nuttx/libc/string/lib_memcpy.c @@ -0,0 +1,64 @@ +/**************************************************************************** + * libc/string/lib_memcpy.c + * + * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Compilation Switches + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include + +/**************************************************************************** + * Global Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: memcpy + ****************************************************************************/ + +#ifndef CONFIG_ARCH_MEMCPY +FAR void *memcpy(FAR void *dest, FAR const void *src, size_t n) +{ + FAR unsigned char *pout = (FAR unsigned char*)dest; + FAR unsigned char *pin = (FAR unsigned char*)src; + while (n-- > 0) *pout++ = *pin++; + return dest; +} +#endif diff --git a/nuttx/libc/string/lib_memset.c b/nuttx/libc/string/lib_memset.c new file mode 100644 index 000000000..0b98ebf96 --- /dev/null +++ b/nuttx/libc/string/lib_memset.c @@ -0,0 +1,188 @@ + +/**************************************************************************** + * libc/string/lib_memset.c + * + * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include + +#include +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Can't support CONFIG_MEMSET_64BIT if the platform does not have 64-bit + * integer types. + */ + +#ifndef CONFIG_HAVE_LONG_LONG +# undef CONFIG_MEMSET_64BIT +#endif + +/**************************************************************************** + * Global Functions + ****************************************************************************/ + +#ifndef CONFIG_ARCH_MEMSET +void *memset(void *s, int c, size_t n) +{ +#ifdef CONFIG_MEMSET_OPTSPEED + /* This version is optimized for speed (you could do better + * still by exploiting processor caching or memory burst + * knowledge.) + */ + + uintptr_t addr = (uintptr_t)s; + uint16_t val16 = ((uint16_t)c << 8) | (uint16_t)c; + uint32_t val32 = ((uint32_t)val16 << 16) | (uint32_t)val16; +#ifdef CONFIG_MEMSET_64BIT + uint64_t val64 = ((uint64_t)val32 << 32) | (uint64_t)val32; +#endif + + /* Make sure that there is something to be cleared */ + + if (n > 0) + { + /* Align to a 16-bit boundary */ + + if ((addr & 1) != 0) + { + *(uint8_t*)addr = (uint8_t)c; + addr += 1; + n -= 1; + } + + /* Check if there are at least 16-bits left to be written */ + + if (n >= 2) + { + /* Align to a 32-bit boundary (we know that the destination + * address is already aligned to at least a 16-bit boundary). + */ + + if ((addr & 3) != 0) + { + *(uint16_t*)addr = val16; + addr += 2; + n -= 2; + } + +#ifndef CONFIG_MEMSET_64BIT + /* Loop while there are at least 32-bits left to be written */ + + while (n >= 4) + { + *(uint32_t*)addr = val32; + addr += 4; + n -= 4; + } +#else + /* Check if there are at least 32-bits left to be written */ + + if (n >= 4) + { + /* Align to a 64-bit boundary (we know that the destination + * address is already aligned to at least a 32-bit boundary). + */ + + if ((addr & 7) != 0) + { + *(uint32_t*)addr = val32; + addr += 4; + n -= 4; + } + + /* Loop while there are at least 64-bits left to be written */ + + while (n >= 8) + { + *(uint64_t*)addr = val64; + addr += 8; + n -= 8; + } + } +#endif + } + +#ifdef CONFIG_MEMSET_64BIT + /* We may get here with n in the range 0..7. If n >= 4, then we should + * have 64-bit alignment. + */ + + if (n >= 4) + { + *(uint32_t*)addr = val32; + addr += 4; + n -= 4; + } +#endif + + /* We may get here under the following conditions: + * + * n = 0, addr may or may not be aligned + * n = 1, addr is aligned to at least a 16-bit boundary + * n = 2, addr is aligned to a 32-bit boundary + * n = 3, addr is aligned to a 32-bit boundary + */ + + if (n >= 2) + { + *(uint16_t*)addr = val16; + addr += 2; + n -= 2; + } + + if (n >= 1) + { + *(uint8_t*)addr = (uint8_t)c; + } + } +#else + /* This version is optimized for size */ + + unsigned char *p = (unsigned char*)s; + while (n-- > 0) *p++ = c; +#endif + return s; +} +#endif diff --git a/nuttx/libc/string/lib_skipspace.c b/nuttx/libc/string/lib_skipspace.c new file mode 100644 index 000000000..4b72b1ec3 --- /dev/null +++ b/nuttx/libc/string/lib_skipspace.c @@ -0,0 +1,69 @@ +/**************************************************************************** + * libc/string/lib_skipspace.c + * + * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include +#include "lib_internal.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: lib_skipspace + * + * Description: + * Skip over leading whitespace + * + ****************************************************************************/ + +void lib_skipspace(const char **pptr) +{ + const char *ptr = *pptr; + while (isspace(*ptr)) ptr++; + *pptr = ptr; +} + + diff --git a/nuttx/libc/string/lib_strcasecmp.c b/nuttx/libc/string/lib_strcasecmp.c new file mode 100644 index 000000000..df6f08118 --- /dev/null +++ b/nuttx/libc/string/lib_strcasecmp.c @@ -0,0 +1,65 @@ +/**************************************************************************** + * libc/string/lib_strcasecmp.c + * + * Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include + +/**************************************************************************** + * Public Functions + *****************************************************************************/ + +#ifndef CONFIG_ARCH_STRCMP +int strcasecmp(const char *cs, const char *ct) +{ + int result; + for (;;) + { + if ((result = (int)toupper(*cs) - (int)toupper(*ct)) != 0 || !*cs) + { + break; + } + + cs++; + ct++; + } + return result; +} +#endif diff --git a/nuttx/libc/string/lib_strcat.c b/nuttx/libc/string/lib_strcat.c new file mode 100644 index 000000000..b331d3f1c --- /dev/null +++ b/nuttx/libc/string/lib_strcat.c @@ -0,0 +1,62 @@ +/**************************************************************************** + * libc/string/lib_strcat.c + * + * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include + +/**************************************************************************** + * Global Functions + ****************************************************************************/ + +#ifndef CONFIG_ARCH_STRCAT +char *strcat(char *dest, const char *src) +{ + char *ret = dest; + + dest += strlen(dest); + while (*src != '\0') + { + *dest++ = *src++; + } + *dest = '\0'; + + return ret; +} +#endif diff --git a/nuttx/libc/string/lib_strchr.c b/nuttx/libc/string/lib_strchr.c new file mode 100644 index 000000000..e6af56eee --- /dev/null +++ b/nuttx/libc/string/lib_strchr.c @@ -0,0 +1,78 @@ +/**************************************************************************** + * libc/string/lib_strchr.c + * + * Copyright (C) 2007, 2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include + +/**************************************************************************** + * Global Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: strchr + * + * Description: + * The strchr() function locates the first occurrence of 'c' (converted to + * a char) in the string pointed to by 's'. The terminating null byte is + * considered to be part of the string. + * + * Returned Value: + * Upon completion, strchr() returns a pointer to the byte, or a null + * pointer if the byte was not found. + * + ****************************************************************************/ + +#ifndef CONFIG_ARCH_STRCHR +FAR char *strchr(FAR const char *s, int c) +{ + if (s) + { + for (; *s; s++) + { + if (*s == c) + { + return (FAR char *)s; + } + } + } + + return NULL; +} +#endif diff --git a/nuttx/libc/string/lib_strcmp.c b/nuttx/libc/string/lib_strcmp.c new file mode 100644 index 000000000..d4036cd3e --- /dev/null +++ b/nuttx/libc/string/lib_strcmp.c @@ -0,0 +1,59 @@ +/**************************************************************************** + * libc/string/lib_strcmp.c + * + * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include + +/**************************************************************************** + * Public Functions + *****************************************************************************/ + +#ifndef CONFIG_ARCH_STRCMP +int strcmp(const char *cs, const char *ct) +{ + register signed char result; + for (;;) + { + if ((result = *cs - *ct++) != 0 || !*cs++) + break; + } + return result; +} +#endif diff --git a/nuttx/libc/string/lib_strcpy.c b/nuttx/libc/string/lib_strcpy.c new file mode 100644 index 000000000..7a0576f5a --- /dev/null +++ b/nuttx/libc/string/lib_strcpy.c @@ -0,0 +1,55 @@ +/************************************************************************ + * libc/string/lib_strcpy.c + * + * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include + +/************************************************************************ + * Global Functions + ************************************************************************/ + +#ifndef CONFIG_ARCH_STRCPY +char *strcpy(char *dest, const char *src) +{ + char *tmp = dest; + while ((*dest++ = *src++) != '\0'); + return tmp; +} +#endif diff --git a/nuttx/libc/string/lib_strcspn.c b/nuttx/libc/string/lib_strcspn.c new file mode 100644 index 000000000..23e913fad --- /dev/null +++ b/nuttx/libc/string/lib_strcspn.c @@ -0,0 +1,67 @@ +/**************************************************************************** + * libc/string/lib_strcspn.c + * + * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Compilation Switches + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include + +/**************************************************************************** + * Global Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: strcspn + * + * Description: + * strspn() calculates the length of the initial segment of s which + * consists entirely of characters not in reject + * + ****************************************************************************/ + +size_t strcspn(const char *s, const char *reject) +{ + size_t i; + for (i = 0; s[i] && strchr(reject, s[i]) == NULL; i++); + return i; +} + diff --git a/nuttx/libc/string/lib_strdup.c b/nuttx/libc/string/lib_strdup.c new file mode 100644 index 000000000..a5b3a1e8c --- /dev/null +++ b/nuttx/libc/string/lib_strdup.c @@ -0,0 +1,62 @@ +/************************************************************************ + * libc/string//lib_strdup.c + * + * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include + +#include "lib_internal.h" + +/************************************************************************ + * Global Functions + ************************************************************************/ + +FAR char *strdup(const char *s) +{ + FAR char *news = NULL; + if (s) + { + news = (FAR char*)lib_malloc(strlen(s) + 1); + if (news) + { + strcpy(news, s); + } + } + return news; +} diff --git a/nuttx/libc/string/lib_strerror.c b/nuttx/libc/string/lib_strerror.c new file mode 100644 index 000000000..0c7ca28fd --- /dev/null +++ b/nuttx/libc/string/lib_strerror.c @@ -0,0 +1,375 @@ +/************************************************************************ + * libc/string/lib_strerror.c + * + * Copyright (C) 2007, 2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include +#include + +/************************************************************************ + * Definitions + ************************************************************************/ + +/************************************************************************ + * Private Types + ************************************************************************/ + +struct errno_strmap_s +{ + uint8_t errnum; + const char *str; +}; + +/************************************************************************ + * Private Data + ************************************************************************/ + +#ifdef CONFIG_LIBC_STRERROR + +/* This table maps all error numbers to descriptive strings. + * The only assumption that the code makes with regard to this + * this table is that it is ordered by error number. + * + * The size of this table is quite large. Its size can be + * reduced by eliminating some of the more obscure error + * strings. + */ + +#ifndef CONFIG_LIBC_STRERROR_SHORT + +static const struct errno_strmap_s g_errnomap[] = +{ + { EPERM, EPERM_STR }, + { ENOENT, ENOENT_STR }, + { ESRCH, ESRCH_STR }, + { EINTR, EINTR_STR }, + { EIO, EIO_STR }, + { ENXIO, ENXIO_STR }, + { E2BIG, E2BIG_STR }, + { ENOEXEC, ENOEXEC_STR }, + { EBADF, EBADF_STR }, + { ECHILD, ECHILD_STR }, + { EAGAIN, EAGAIN_STR }, + { ENOMEM, ENOMEM_STR }, + { EACCES, EACCES_STR }, + { EFAULT, EFAULT_STR }, + { ENOTBLK, ENOTBLK_STR }, + { EBUSY, EBUSY_STR }, + { EEXIST, EEXIST_STR }, + { EXDEV, EXDEV_STR }, + { ENODEV, ENODEV_STR }, + { ENOTDIR, ENOTDIR_STR }, + { EISDIR, EISDIR_STR }, + { EINVAL, EINVAL_STR }, + { ENFILE, ENFILE_STR }, + { EMFILE, EMFILE_STR }, + { ENOTTY, ENOTTY_STR }, + { ETXTBSY, ETXTBSY_STR }, + { EFBIG, EFBIG_STR }, + { ENOSPC, ENOSPC_STR }, + { ESPIPE, ESPIPE_STR }, + { EROFS, EROFS_STR }, + { EMLINK, EMLINK_STR }, + { EPIPE, EPIPE_STR }, + { EDOM, EDOM_STR }, + { ERANGE, ERANGE_STR }, + { EDEADLK, EDEADLK_STR }, + { ENAMETOOLONG, ENAMETOOLONG_STR }, + { ENOLCK, ENOLCK_STR }, + { ENOSYS, ENOSYS_STR }, + { ENOTEMPTY, ENOTEMPTY_STR }, + { ELOOP, ELOOP_STR }, + { ENOMSG, ENOMSG_STR }, + { EIDRM, EIDRM_STR }, + { ECHRNG, ECHRNG_STR }, + { EL2NSYNC, EL2NSYNC_STR }, + { EL3HLT, EL3HLT_STR }, + { EL3RST, EL3RST_STR }, + { ELNRNG, ELNRNG_STR }, + { EUNATCH, EUNATCH_STR }, + { ENOCSI, ENOCSI_STR }, + { EL2HLT, EL2HLT_STR }, + { EBADE, EBADE_STR }, + { EBADR, EBADR_STR }, + { EXFULL, EXFULL_STR }, + { ENOANO, ENOANO_STR }, + { EBADRQC, EBADRQC_STR }, + { EBADSLT, EBADSLT_STR }, + { EBFONT, EBFONT_STR }, + { ENOSTR, ENOSTR_STR }, + { ENODATA, ENODATA_STR }, + { ETIME, ETIME_STR }, + { ENOSR, ENOSR_STR }, + { ENONET, ENONET_STR }, + { ENOPKG, ENOPKG_STR }, + { EREMOTE, EREMOTE_STR }, + { ENOLINK, ENOLINK_STR }, + { EADV, EADV_STR }, + { ESRMNT, ESRMNT_STR }, + { ECOMM, ECOMM_STR }, + { EPROTO, EPROTO_STR }, + { EMULTIHOP, EMULTIHOP_STR }, + { EDOTDOT, EDOTDOT_STR }, + { EBADMSG, EBADMSG_STR }, + { EOVERFLOW, EOVERFLOW_STR }, + { ENOTUNIQ, ENOTUNIQ_STR }, + { EBADFD, EBADFD_STR }, + { EREMCHG, EREMCHG_STR }, + { ELIBACC, ELIBACC_STR }, + { ELIBBAD, ELIBBAD_STR }, + { ELIBSCN, ELIBSCN_STR }, + { ELIBMAX, ELIBMAX_STR }, + { ELIBEXEC, ELIBEXEC_STR }, + { EILSEQ, EILSEQ_STR }, + { ERESTART, ERESTART_STR }, + { ESTRPIPE, ESTRPIPE_STR }, + { EUSERS, EUSERS_STR }, + { ENOTSOCK, ENOTSOCK_STR }, + { EDESTADDRREQ, EDESTADDRREQ_STR }, + { EMSGSIZE, EMSGSIZE_STR }, + { EPROTOTYPE, EPROTOTYPE_STR }, + { ENOPROTOOPT, ENOPROTOOPT_STR }, + { EPROTONOSUPPORT, EPROTONOSUPPORT_STR }, + { ESOCKTNOSUPPORT, ESOCKTNOSUPPORT_STR }, + { EOPNOTSUPP, EOPNOTSUPP_STR }, + { EPFNOSUPPORT, EPFNOSUPPORT_STR }, + { EAFNOSUPPORT, EAFNOSUPPORT_STR }, + { EADDRINUSE, EADDRINUSE_STR }, + { EADDRNOTAVAIL, EADDRNOTAVAIL_STR }, + { ENETDOWN, ENETDOWN_STR }, + { ENETUNREACH, ENETUNREACH_STR }, + { ENETRESET, ENETRESET_STR }, + { ECONNABORTED, ECONNABORTED_STR }, + { ECONNRESET, ECONNRESET_STR }, + { ENOBUFS, ENOBUFS_STR }, + { EISCONN, EISCONN_STR }, + { ENOTCONN, ENOTCONN_STR }, + { ESHUTDOWN, ESHUTDOWN_STR }, + { ETOOMANYREFS, ETOOMANYREFS_STR }, + { ETIMEDOUT, ETIMEDOUT_STR }, + { ECONNREFUSED, ECONNREFUSED_STR }, + { EHOSTDOWN, EHOSTDOWN_STR }, + { EHOSTUNREACH, EHOSTUNREACH_STR }, + { EALREADY, EALREADY_STR }, + { EINPROGRESS, EINPROGRESS_STR }, + { ESTALE, ESTALE_STR }, + { EUCLEAN, EUCLEAN_STR }, + { ENOTNAM, ENOTNAM_STR }, + { ENAVAIL, ENAVAIL_STR }, + { EISNAM, EISNAM_STR }, + { EREMOTEIO, EREMOTEIO_STR }, + { EDQUOT, EDQUOT_STR }, + { ENOMEDIUM, ENOMEDIUM_STR }, + { EMEDIUMTYPE, EMEDIUMTYPE_STR } +}; + +#else /* CONFIG_LIBC_STRERROR_SHORT */ + +static const struct errno_strmap_s g_errnomap[] = +{ + { EPERM, "EPERM" }, + { ENOENT, "ENOENT" }, + { ESRCH, "ESRCH" }, + { EINTR, "EINTR" }, + { EIO, "EIO" }, + { ENXIO, "ENXIO" }, + { E2BIG, "E2BIG" }, + { ENOEXEC, "ENOEXEC" }, + { EBADF, "EBADF" }, + { ECHILD, "ECHILD" }, + { EAGAIN, "EAGAIN" }, + { ENOMEM, "ENOMEM" }, + { EACCES, "EACCES" }, + { EFAULT, "EFAULT" }, + { ENOTBLK, "ENOTBLK" }, + { EBUSY, "EBUSY" }, + { EEXIST, "EEXIST" }, + { EXDEV, "EXDEV" }, + { ENODEV, "ENODEV" }, + { ENOTDIR, "ENOTDIR" }, + { EISDIR, "EISDIR" }, + { EINVAL, "EINVAL" }, + { ENFILE, "ENFILE" }, + { EMFILE, "EMFILE" }, + { ENOTTY, "ENOTTY" }, + { ETXTBSY, "ETXTBSY" }, + { EFBIG, "EFBIG" }, + { ENOSPC, "ENOSPC" }, + { ESPIPE, "ESPIPE" }, + { EROFS, "EROFS" }, + { EMLINK, "EMLINK" }, + { EPIPE, "EPIPE" }, + { EDOM, "EDOM" }, + { ERANGE, "ERANGE" }, + { EDEADLK, "EDEADLK" }, + { ENAMETOOLONG, "ENAMETOOLONG" }, + { ENOLCK, "ENOLCK" }, + { ENOSYS, "ENOSYS" }, + { ENOTEMPTY, "ENOTEMPTY" }, + { ELOOP, "ELOOP" }, + { ENOMSG, "ENOMSG" }, + { EIDRM, "EIDRM" }, + { ECHRNG, "ECHRNG" }, + { EL2NSYNC, "EL2NSYNC" }, + { EL3HLT, "EL3HLT" }, + { EL3RST, "EL3RST" }, + { EL3RST, "EL3RST" }, + { EUNATCH, "EUNATCH" }, + { ENOCSI, "ENOCSI" }, + { EL2HLT, "EL2HLT" }, + { EBADE, "EBADE" }, + { EBADR, "EBADR" }, + { EXFULL, "EXFULL" }, + { ENOANO, "ENOANO" }, + { EBADRQC, "EBADRQC" }, + { EBADSLT, "EBADSLT" }, + { EBFONT, "EBFONT" }, + { ENOSTR, "ENOSTR" }, + { ENODATA, "ENODATA" }, + { ETIME, "ETIME" }, + { ENOSR, "ENOSR" }, + { ENONET, "ENONET" }, + { ENOPKG, "ENOPKG" }, + { EREMOTE, "EREMOTE" }, + { ENOLINK, "ENOLINK" }, + { EADV, "EADV" }, + { ESRMNT, "ESRMNT" }, + { ECOMM, "ECOMM" }, + { EPROTO, "EPROTO" }, + { EMULTIHOP, "EMULTIHOP" }, + { EDOTDOT, "EDOTDOT" }, + { EBADMSG, "EBADMSG" }, + { EOVERFLOW, "EOVERFLOW" }, + { ENOTUNIQ, "ENOTUNIQ" }, + { EBADFD, "EBADFD" }, + { EREMCHG, "EREMCHG" }, + { ELIBACC, "ELIBACC" }, + { ELIBBAD, "ELIBBAD" }, + { ELIBSCN, "ELIBSCN" }, + { ELIBMAX, "ELIBMAX" }, + { ELIBEXEC, "ELIBEXEC" }, + { EILSEQ, "EILSEQ" }, + { ERESTART, "ERESTART" }, + { ESTRPIPE, "ESTRPIPE" }, + { EUSERS, "EUSERS" }, + { ENOTSOCK, "ENOTSOCK" }, + { EDESTADDRREQ, "EDESTADDRREQ" }, + { EMSGSIZE, "EMSGSIZE" }, + { EPROTOTYPE, "EPROTOTYPE" }, + { ENOPROTOOPT, "ENOPROTOOPT" }, + { EPROTONOSUPPORT, "EPROTONOSUPPORT" }, + { ESOCKTNOSUPPORT, "ESOCKTNOSUPPORT" }, + { EOPNOTSUPP, "EOPNOTSUPP" }, + { EPFNOSUPPORT, "EPFNOSUPPORT" }, + { EAFNOSUPPORT, "EAFNOSUPPORT" }, + { EADDRINUSE, "EADDRINUSE" }, + { EADDRNOTAVAIL, "EADDRNOTAVAIL" }, + { ENETDOWN, "ENETDOWN" }, + { ENETUNREACH, "ENETUNREACH" }, + { ENETRESET, "ENETRESET" }, + { ECONNABORTED, "ECONNABORTED" }, + { ECONNRESET, "ECONNRESET" }, + { ENOBUFS, "ENOBUFS" }, + { EISCONN, "EISCONN" }, + { ENOTCONN, "ENOTCONN" }, + { ESHUTDOWN, "ESHUTDOWN" }, + { ETOOMANYREFS, "ETOOMANYREFS" }, + { ETIMEDOUT, "ETIMEDOUT" }, + { ECONNREFUSED, "ECONNREFUSED" }, + { EHOSTDOWN, "EHOSTDOWN" }, + { EHOSTUNREACH, "EHOSTUNREACH" }, + { EALREADY, "EALREADY" }, + { EINPROGRESS, "EINPROGRESS" }, + { ESTALE, "ESTALE" }, + { EUCLEAN, "EUCLEAN" }, + { ENOTNAM, "ENOTNAM" }, + { ENAVAIL, "ENAVAIL" }, + { EISNAM, "EISNAM" }, + { EREMOTEIO, "EREMOTEIO" }, + { EDQUOT, "EDQUOT" }, + { ENOMEDIUM, "ENOMEDIUM" }, + { EMEDIUMTYPE, "EMEDIUMTYPE" } +}; + +#endif /* CONFIG_LIBC_STRERROR_SHORT */ + +#define NERRNO_STRS (sizeof(g_errnomap) / sizeof(struct errno_strmap_s)) + +#endif /* CONFIG_LIBC_STRERROR */ + +/************************************************************************ + * Private Functions + ************************************************************************/ + +/************************************************************************ + * Public Functions + ************************************************************************/ + +/************************************************************************ + * Name: strerror + ************************************************************************/ + +FAR const char *strerror(int errnum) +{ +#ifdef CONFIG_LIBC_STRERROR + int ndxlow = 0; + int ndxhi = NERRNO_STRS - 1; + int ndxmid; + + do + { + ndxmid = (ndxlow + ndxhi) >> 1; + if (errnum > g_errnomap[ndxmid].errnum) + { + ndxlow = ndxmid + 1; + } + else if (errnum < g_errnomap[ndxmid].errnum) + { + ndxhi = ndxmid - 1; + } + else + { + return g_errnomap[ndxmid].str; + } + } + while (ndxlow <= ndxhi); +#endif + return "Unknown error"; +} diff --git a/nuttx/libc/string/lib_strlen.c b/nuttx/libc/string/lib_strlen.c new file mode 100644 index 000000000..6077858e2 --- /dev/null +++ b/nuttx/libc/string/lib_strlen.c @@ -0,0 +1,55 @@ +/**************************************************************************** + * libc/string/lib_strlen.c + * + * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 +#include +#include + +/**************************************************************************** + * Global Functions + ****************************************************************************/ + +#ifndef CONFIG_ARCH_STRLEN +size_t strlen(const char *s) +{ + const char *sc; + for (sc = s; *sc != '\0'; ++sc); + return sc - s; +} +#endif diff --git a/nuttx/libc/string/lib_strncasecmp.c b/nuttx/libc/string/lib_strncasecmp.c new file mode 100644 index 000000000..35f701c5e --- /dev/null +++ b/nuttx/libc/string/lib_strncasecmp.c @@ -0,0 +1,70 @@ +/**************************************************************************** + * libc/string/lib_strncasecmp.c + * + * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + *****************************************************************************/ + +/**************************************************************************** + * Compilation Switches + *****************************************************************************/ + +/**************************************************************************** + * Included Files + *****************************************************************************/ + +#include + +#include +#include +#include + +/**************************************************************************** + * Global Functions + *****************************************************************************/ + +#ifndef CONFIG_ARCH_STRNCASECMP +int strncasecmp(const char *cs, const char *ct, size_t nb) +{ + int result = 0; + for (; nb > 0; nb--) + { + if ((result = (int)toupper(*cs) - (int)toupper(*ct)) != 0 || !*cs) + { + break; + } + + cs++; + ct++; + } + return result; +} +#endif diff --git a/nuttx/libc/string/lib_strncat.c b/nuttx/libc/string/lib_strncat.c new file mode 100644 index 000000000..78c54835e --- /dev/null +++ b/nuttx/libc/string/lib_strncat.c @@ -0,0 +1,62 @@ +/************************************************************ + * libc/string/lib_strncat.c + * + * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 +#include +#include + +/************************************************************ + * Global Functions + ************************************************************/ + +#ifndef CONFIG_ARCH_STRNCAT +char *strncat(char *dest, const char *src, size_t n) +{ + char *ret = dest; + + dest += strlen(dest); + for (; n > 0 && *src != '\0' ; n--) + { + *dest++ = *src++; + } + *dest = '\0'; + + return ret; +} +#endif diff --git a/nuttx/libc/string/lib_strncmp.c b/nuttx/libc/string/lib_strncmp.c new file mode 100644 index 000000000..dd8b57fd0 --- /dev/null +++ b/nuttx/libc/string/lib_strncmp.c @@ -0,0 +1,65 @@ +/**************************************************************************** + * libc/lib_strncmp.c + * + * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + *****************************************************************************/ + +/**************************************************************************** + * Compilation Switches + *****************************************************************************/ + +/**************************************************************************** + * Included Files + *****************************************************************************/ + +#include +#include +#include + +/**************************************************************************** + * Global Functions + *****************************************************************************/ + +#ifndef CONFIG_ARCH_STRNCMP +int strncmp(const char *cs, const char *ct, size_t nb) +{ + int result = 0; + for (; nb > 0; nb--) + { + if ((result = (int)*cs - (int)*ct++) != 0 || !*cs++) + { + break; + } + } + return result; +} +#endif diff --git a/nuttx/libc/string/lib_strncpy.c b/nuttx/libc/string/lib_strncpy.c new file mode 100644 index 000000000..8a97aa67b --- /dev/null +++ b/nuttx/libc/string/lib_strncpy.c @@ -0,0 +1,57 @@ +/************************************************************ + * libc/string/lib_strncpy.c + * + * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 +#include +#include + +/************************************************************ + * Global Functions + ************************************************************/ + +#ifndef CONFIG_ARCH_STRNCPY +char *strncpy(char *dest, const char *src, size_t n) +{ + char *ret = dest; /* Value to be returned */ + char *end = dest + n; /* End of dest buffer + 1 byte */ + + while ((*dest++ = *src++) != '\0' && dest != end); + return ret; +} +#endif diff --git a/nuttx/libc/string/lib_strndup.c b/nuttx/libc/string/lib_strndup.c new file mode 100644 index 000000000..524e09754 --- /dev/null +++ b/nuttx/libc/string/lib_strndup.c @@ -0,0 +1,93 @@ +/************************************************************************ + * libc/string//lib_strndup.c + * + * Copyright (C) 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include + +#include "lib_internal.h" + +/************************************************************************ + * Global Functions + ************************************************************************/ +/************************************************************************ + * Name: strndup + * + * Description: + * The strndup() function is equivalent to the strdup() function, + * duplicating the provided 's' in a new block of memory allocated as + * if by using malloc(), with the exception being that strndup() copies + * at most 'size' plus one bytes into the newly allocated memory, + * terminating the new string with a NUL character. If the length of 's' + * is larger than 'size', only 'size' bytes will be duplicated. If + * 'size' is larger than the length of 's', all bytes in s will be + * copied into the new memory buffer, including the terminating NUL + * character. The newly created string will always be properly + * terminated. + * + ************************************************************************/ + +FAR char *strndup(FAR const char *s, size_t size) +{ + FAR char *news = NULL; + if (s) + { + /* Get the size of the new string = MIN(strlen(s), size) */ + + size_t allocsize = strlen(s); + if (allocsize > size) + { + allocsize = size; + } + + /* Allocate the new string, adding 1 for the NUL terminator */ + + news = (FAR char*)lib_malloc(allocsize + 1); + if (news) + { + /* Copy the string into the allocated memory and add a NUL + * terminator in any case. + */ + + memcpy(news, s, allocsize); + news[allocsize] = '\0'; + } + } + return news; +} diff --git a/nuttx/libc/string/lib_strnlen.c b/nuttx/libc/string/lib_strnlen.c new file mode 100644 index 000000000..9bc3064cb --- /dev/null +++ b/nuttx/libc/string/lib_strnlen.c @@ -0,0 +1,62 @@ +/**************************************************************************** + * libc/string/lib_strnlen.c + * + * This file is part of NuttX, contributed by Michael Hrabanek + * + * Copyright (C) 2010 Gregory Nutt. All rights reserved. + * Author: Michael Hrabanek + * + * Derives from the file libc/lib_strlen.c: + * + * Copyright (C) 2007, 2008, 2010 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 +#include +#include + +/**************************************************************************** + * Global Functions + ****************************************************************************/ + +#ifndef CONFIG_ARCH_STRNLEN +size_t strnlen(const char *s, size_t maxlen) +{ + const char *sc; + for (sc = s; maxlen != 0 && *sc != '\0'; maxlen--, ++sc); + return sc - s; +} +#endif diff --git a/nuttx/libc/string/lib_strpbrk.c b/nuttx/libc/string/lib_strpbrk.c new file mode 100644 index 000000000..ef9b0f3e9 --- /dev/null +++ b/nuttx/libc/string/lib_strpbrk.c @@ -0,0 +1,85 @@ +/**************************************************************************** + * libc/string/lib_strpbrk.c + * + * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use str 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 str binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer str + * 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 + +#include + +/**************************************************************************** + * Global Functions + ****************************************************************************/ + +char *strpbrk(const char *str, const char *charset) +{ + /* Sanity checking */ + +#ifdef CONFIG_DEBUG + if (!str || !charset) + { + return NULL; + } +#endif + + /* Check each character in the string */ + + while (*str) + { + /* Check if the character from the string matches any character in the charset */ + + if (strchr(charset, *str) != NULL) + { + /* Yes, then this position must be the first occurrence in string */ + + return (char*)str; + } + + /* This character from the strings matches none of those in the charset. + * Try the next character from the string. + */ + + str++; + } + + /* We have looked at every character in the string, and none of them match any of + * the characters in charset. + */ + + return NULL; +} + diff --git a/nuttx/libc/string/lib_strrchr.c b/nuttx/libc/string/lib_strrchr.c new file mode 100644 index 000000000..08575c82b --- /dev/null +++ b/nuttx/libc/string/lib_strrchr.c @@ -0,0 +1,68 @@ +/************************************************************************ + * libc/string/lib_strrchr.c + * + * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include + +/************************************************************************ + * Global Functions + ************************************************************************/ + +/* The strrchr() function returns a pointer to the last + * occurrence of the character c in the string s. + */ + +char *strrchr(const char *s, int c) +{ + if (s) + { + const char *p = &s[strlen(s) - 1]; + for (; p >= s; p--) + { + if (*p == c) + { + return (char*)p; + } + } + } + + return NULL; +} + diff --git a/nuttx/libc/string/lib_strspn.c b/nuttx/libc/string/lib_strspn.c new file mode 100644 index 000000000..6894b2b9d --- /dev/null +++ b/nuttx/libc/string/lib_strspn.c @@ -0,0 +1,66 @@ +/**************************************************************************** + * libc/string/lib_strspn.c + * + * Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Compilation Switches + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include + +/**************************************************************************** + * Global Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: strspn + * + * Description: + * strspn() calculates the length of the initial segment of s which + * consists entirely of characters in accept. + * + ****************************************************************************/ + +size_t strspn(const char *s, const char *accept) +{ + size_t i; + for (i = 0; s[i] && strchr(accept, s[i]) != NULL; i++); + return i; +} diff --git a/nuttx/libc/string/lib_strtod.c b/nuttx/libc/string/lib_strtod.c new file mode 100644 index 000000000..58dfd6a29 --- /dev/null +++ b/nuttx/libc/string/lib_strtod.c @@ -0,0 +1,241 @@ +/**************************************************************************** + * libc/string/lib_strtod.c + * Convert string to double + * + * Copyright (C) 2002 Michael Ringgaard. All rights reserved. + * Copyright (C) 2006-2007 H. Peter Anvin. + * + * 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 of the project 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 +#include + +#include +#include +#include + +#ifdef CONFIG_HAVE_DOUBLE + +/**************************************************************************** + * Pre-processor definitions + ****************************************************************************/ + +/* These are predefined with GCC, but could be issues for other compilers. If + * not defined, an arbitrary big number is put in for now. These should be + * added to nuttx/compiler for your compiler. + */ + +#if !defined(__DBL_MIN_EXP__) || !defined(__DBL_MAX_EXP__) +# ifdef CONFIG_CPP_HAVE_WARNING +# warning "Size of exponent is unknown" +# endif +# undef __DBL_MIN_EXP__ +# define __DBL_MIN_EXP__ (-1021) +# undef __DBL_MAX_EXP__ +# define __DBL_MAX_EXP__ (1024) +#endif + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +static inline int is_real(double x) +{ + const double_t infinite = 1.0/0.0; + return (x < infinite) && (x >= -infinite); +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/***************************************************(************************ + * Name: strtod + * + * Description: + * Convert a string to a double value + * + ****************************************************************************/ + +double_t strtod(const char *str, char **endptr) +{ + double_t number; + int exponent; + int negative; + char *p = (char *) str; + double p10; + int n; + int num_digits; + int num_decimals; + const double_t infinite = 1.0/0.0; + + /* Skip leading whitespace */ + + while (isspace(*p)) + { + p++; + } + + /* Handle optional sign */ + + negative = 0; + switch (*p) + { + case '-': + negative = 1; /* Fall through to increment position */ + case '+': + p++; + } + + number = 0.; + exponent = 0; + num_digits = 0; + num_decimals = 0; + + /* Process string of digits */ + + while (isdigit(*p)) + { + number = number * 10. + (*p - '0'); + p++; + num_digits++; + } + + /* Process decimal part */ + + if (*p == '.') + { + p++; + + while (isdigit(*p)) + { + number = number * 10. + (*p - '0'); + p++; + num_digits++; + num_decimals++; + } + + exponent -= num_decimals; + } + + if (num_digits == 0) + { + set_errno(ERANGE); + return 0.0; + } + + /* Correct for sign */ + + if (negative) + { + number = -number; + } + + /* Process an exponent string */ + + if (*p == 'e' || *p == 'E') + { + /* Handle optional sign */ + + negative = 0; + switch(*++p) + { + case '-': + negative = 1; /* Fall through to increment pos */ + case '+': + p++; + } + + /* Process string of digits */ + + n = 0; + while (isdigit(*p)) + { + n = n * 10 + (*p - '0'); + p++; + } + + if (negative) + { + exponent -= n; + } + else + { + exponent += n; + } + } + + if (exponent < __DBL_MIN_EXP__ || + exponent > __DBL_MAX_EXP__) + { + set_errno(ERANGE); + return infinite; + } + + /* Scale the result */ + + p10 = 10.; + n = exponent; + if (n < 0) n = -n; + while (n) + { + if (n & 1) + { + if (exponent < 0) + { + number /= p10; + } + else + { + number *= p10; + } + } + n >>= 1; + p10 *= p10; + } + + if (!is_real(number)) + { + set_errno(ERANGE); + } + + if (endptr) + { + *endptr = p; + } + + return number; +} + +#endif /* CONFIG_HAVE_DOUBLE */ + diff --git a/nuttx/libc/string/lib_strtok.c b/nuttx/libc/string/lib_strtok.c new file mode 100644 index 000000000..85d6597d7 --- /dev/null +++ b/nuttx/libc/string/lib_strtok.c @@ -0,0 +1,87 @@ +/**************************************************************************** + * libc/string/lib_strtok.c + * + * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static char *g_saveptr = NULL; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: strtok + * + * Description: + * The strtok() function parses a string into a + * sequence of tokens. On the first call to strtok() the + * string to be parsed should be specified in 'str'. In + * each subsequent call that should parse the same string, + * 'str' should be NULL. + * + * The 'delim' argument specifies a set of characters that + * delimit the tokens in the parsed string. The caller + * may specify different strings in delim in successive + * calls that parse the same string. + * + * Each call to strtok() returns a pointer to a null- + * terminated string containing the next token. This + * string does not include the delimiting character. If + * no more tokens are found, strtok() returns NULL. + * + * A sequence of two or more contiguous delimiter + * characters in the parsed string is considered to be a + * single delimiter. Delimiter characters at the start or + * end of the string are ignored. The tokens returned by + * strtok() are always non-empty strings. + * + * Return + * strtok() returns a pointer to the next token, or NULL + * if there are no more tokens. + * + ****************************************************************************/ + +char *strtok(char *str, const char *delim) +{ + return strtok_r(str, delim, &g_saveptr); +} diff --git a/nuttx/libc/string/lib_strtokr.c b/nuttx/libc/string/lib_strtokr.c new file mode 100644 index 000000000..c7845be64 --- /dev/null +++ b/nuttx/libc/string/lib_strtokr.c @@ -0,0 +1,157 @@ +/**************************************************************************** + * libc/string/lib_strtokr.c + * + * Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: strtok_r + * + * Description: + * The strtok_r() function is a reentrant version strtok(). + * Like strtok(), it parses a string into a sequence of + * tokens. On the first call to strtok() the string to be + * parsed should be specified in 'str'. In each subsequent + * call that should parse the same string, 'str' should be + * NULL. + * + * The 'saveptr' argument is a pointer to a char * + * variable that is used internally by strtok_r() in + * order to maintain context between successive calls + * that parse the same string. + * + * On the first call to strtok_r(), 'str' should point to the + * string to be parsed, and the value of 'saveptr' is + * ignored. In subsequent calls, 'str' should be NULL, and + * saveptr should be unchanged since the previous call. + * + * The 'delim' argument specifies a set of characters that + * delimit the tokens in the parsed string. The caller + * may specify different strings in delim in successive + * calls that parse the same string. + * + * Each call to strtok_r() returns a pointer to a null- + * terminated string containing the next token. This + * string does not include the delimiting character. If + * no more tokens are found, strtok_r() returns NULL. + * + * A sequence of two or more contiguous delimiter + * characters in the parsed string is considered to be a + * single delimiter. Delimiter characters at the start or + * end of the string are ignored. The tokens returned by + * strtok() are always non-empty strings. + * + * Return + * strtok_r() returns a pointer to the next token, or NULL + * if there are no more tokens. + * + ****************************************************************************/ + +FAR char *strtok_r(FAR char *str, FAR const char *delim, FAR char **saveptr) +{ + char *pbegin; + char *pend = NULL; + + /* Decide if we are starting a new string or continuing from + * the point we left off. + */ + + if (str) + { + pbegin = str; + } + else if (saveptr && *saveptr) + { + pbegin = *saveptr; + } + else + { + return NULL; + } + + /* Find the beginning of the next token */ + + for (; + *pbegin && strchr(delim, *pbegin) != NULL; + pbegin++); + + /* If we are at the end of the string with nothing + * but delimiters found, then return NULL. + */ + + if (!*pbegin) + { + return NULL; + } + + /* Find the end of the token */ + + for (pend = pbegin + 1; + *pend && strchr(delim, *pend) == NULL; + pend++); + + + /* pend either points to the end of the string or to + * the first delimiter after the string. + */ + + if (*pend) + { + /* Turn the delimiter into a null terminator */ + + *pend++ = '\0'; + } + + /* Save the pointer where we left off and return the + * beginning of the token. + */ + + if (saveptr) + { + *saveptr = pend; + } + return pbegin; +} diff --git a/nuttx/libc/string/lib_strtol.c b/nuttx/libc/string/lib_strtol.c new file mode 100644 index 000000000..6ac0d6827 --- /dev/null +++ b/nuttx/libc/string/lib_strtol.c @@ -0,0 +1,103 @@ +/**************************************************************************** + * libc/string/lib_strtol.c + * + * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include + +#include "lib_internal.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: strtol + * + * Description: + * The strtol() function converts the initial part of the string in + * nptr to a long integer value according to the given base, which must be + * between 2 and 36 inclusive, or be the special value 0. + * + * Warning: does not check for integer overflow! + * + ****************************************************************************/ + +long strtol(const char *nptr, char **endptr, int base) +{ + unsigned long accum = 0; + bool negate = false; + + if (nptr) + { + /* Skip leading spaces */ + + lib_skipspace(&nptr); + + /* Check for leading + or - */ + + if (*nptr == '-') + { + negate = true; + nptr++; + } + else if (*nptr == '+') + { + nptr++; + } + + /* Get the unsigned value */ + + accum = strtoul(nptr, endptr, base); + + /* Correct the sign of the result */ + + if (negate) + { + return -(long)accum; + } + } + return (long)accum; +} + diff --git a/nuttx/libc/string/lib_strtoll.c b/nuttx/libc/string/lib_strtoll.c new file mode 100644 index 000000000..99fba08eb --- /dev/null +++ b/nuttx/libc/string/lib_strtoll.c @@ -0,0 +1,107 @@ +/**************************************************************************** + * libc/string/lib_strtoll.c + * + * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include + +#include "lib_internal.h" + +#ifdef CONFIG_HAVE_LONG_LONG + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: strtoll + * + * Description: + * The strtol() function converts the initial part of the string in + * nptr to a long long integer value according to the given base, which + * must be between 2 and 36 inclusive, or be the special value 0. + * + * Warning: does not check for integer overflow! + * + ****************************************************************************/ + +long long strtoll(const char *nptr, char **endptr, int base) +{ + unsigned long long accum = 0; + bool negate = false; + + if (nptr) + { + /* Skip leading spaces */ + + lib_skipspace(&nptr); + + /* Check for leading + or - */ + + if (*nptr == '-') + { + negate = true; + nptr++; + } + else if (*nptr == '+') + { + nptr++; + } + + /* Get the unsigned value */ + + accum = strtoull(nptr, endptr, base); + + /* Correct the sign of the result */ + + if (negate) + { + return -(long long)accum; + } + } + return (long long)accum; +} + +#endif + diff --git a/nuttx/libc/string/lib_strtoul.c b/nuttx/libc/string/lib_strtoul.c new file mode 100644 index 000000000..8f27ae3f2 --- /dev/null +++ b/nuttx/libc/string/lib_strtoul.c @@ -0,0 +1,98 @@ +/**************************************************************************** + * /libc/string/lib_strtoul.c + * + * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include + +#include "lib_internal.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: strtoul + * + * Description: + * The strtol() function converts the initial part of the string in + * nptr to a long unsigned integer value according to the given base, which + * must be between 2 and 36 inclusive, or be the special value 0. + * + * Warning: does not check for integer overflow! + * + ****************************************************************************/ + +unsigned long strtoul(const char *nptr, char **endptr, int base) +{ + unsigned long accum = 0; + int value; + + if (nptr) + { + /* Skip leading spaces */ + + lib_skipspace(&nptr); + + /* Check for unspecified base */ + + base = lib_checkbase(base, &nptr); + + /* Accumulate each "digit" */ + + while (lib_isbasedigit(*nptr, base, &value)) + { + accum = accum*base + value; + nptr++; + } + + /* Return the final pointer to the unused value */ + + if (endptr) + { + *endptr = (char *)nptr; + } + } + return accum; +} + diff --git a/nuttx/libc/string/lib_strtoull.c b/nuttx/libc/string/lib_strtoull.c new file mode 100644 index 000000000..4808114af --- /dev/null +++ b/nuttx/libc/string/lib_strtoull.c @@ -0,0 +1,100 @@ +/**************************************************************************** + * /libc/string/lib_strtoull.c + * + * Copyright (C) 2009, 2010 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 +#include + +#include + +#include "lib_internal.h" + +#ifdef CONFIG_HAVE_LONG_LONG + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: strtoull + * + * Description: + * The strtol() function converts the initial part of the string in + * nptr to a long unsigned integer value according to the given base, which + * must be between 2 and 36 inclusive, or be the special value 0. + * + ****************************************************************************/ + +unsigned long long strtoull(const char *nptr, char **endptr, int base) +{ + unsigned long long accum = 0; + int value; + + if (nptr) + { + /* Skip leading spaces */ + + lib_skipspace(&nptr); + + /* Check for unspecified base */ + + base = lib_checkbase(base, &nptr); + + /* Accumulate each "digit" */ + + while (lib_isbasedigit(*nptr, base, &value)) + { + accum = accum*base + value; + nptr++; + } + + /* Return the final pointer to the unused value */ + + if (endptr) + { + *endptr = (char *)nptr; + } + } + return accum; +} +#endif + diff --git a/nuttx/libc/string/lib_vikmemcpy.c b/nuttx/libc/string/lib_vikmemcpy.c new file mode 100644 index 000000000..28bf4a4ce --- /dev/null +++ b/nuttx/libc/string/lib_vikmemcpy.c @@ -0,0 +1,348 @@ +/**************************************************************************** + * File: libc/string/lib_vikmemcpy.c + * + * This is version of the optimized memcpy by Daniel Vik, adapted to the + * NuttX environment. + * + * Copyright (C) 1999-2010 Daniel Vik + * + * Adaptations include: + * - File name change + * - Use of types defined in stdint.h + * - Integration with the NuttX configuration system + * - Other cosmetic changes for consistency with NuttX coding standards + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any + * damages arising from the use of this software. + * Permission is granted to anyone to use this software for any + * purpose, including commercial applications, and to alter it and + * redistribute it freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you + * must not claim that you wrote the original software. If you + * use this software in a product, an acknowledgment in the + * use this software in a product, an acknowledgment in the + * product documentation would be appreciated but is not + * required. + * + * 2. Altered source versions must be plainly marked as such, and + * must not be misrepresented as being the original software. + * + * 3. This notice may not be removed or altered from any source + * distribution. + * + * Description: Implementation of the standard library function memcpy. + * This implementation of memcpy() is ANSI-C89 compatible. + * + * The following configuration options can be set: + * + * CONFIG_ENDIAN_BIG + * Uses processor with big endian addressing. Default is little endian. + * + * CONFIG_MEMCPY_PRE_INC_PTRS + * Use pre increment of pointers. Default is post increment of pointers. + * + * CONFIG_MEMCPY_INDEXED_COPY + * Copying data using array indexing. Using this option, disables the + * CONFIG_MEMCPY_PRE_INC_PTRS option. + * + * CONFIG_MEMCPY_64BIT - Compiles memcpy for 64 bit architectures + * + ****************************************************************************/ + +/**************************************************************************** + * Configuration definitions. + ****************************************************************************/ + +#define CONFIG_MEMCPY_INDEXED_COPY + +/******************************************************************** + * Included Files + *******************************************************************/ + +#include +#include + +#include +#include +#include + +/******************************************************************** + * Pre-processor Definitions + *******************************************************************/ + +/* Can't support CONFIG_MEMCPY_64BIT if the platform does not have 64-bit + * integer types. + */ + +#ifndef CONFIG_HAVE_LONG_LONG +# undef CONFIG_MEMCPY_64BIT +#endif + +/* Remove definitions when CONFIG_MEMCPY_INDEXED_COPY is defined */ + +#if defined (CONFIG_MEMCPY_INDEXED_COPY) +# if defined (CONFIG_MEMCPY_PRE_INC_PTRS) +# undef CONFIG_MEMCPY_PRE_INC_PTRS +# endif /* CONFIG_MEMCPY_PRE_INC_PTRS */ +#endif /* CONFIG_MEMCPY_INDEXED_COPY */ + +/* Definitions for pre and post increment of pointers */ + +#if defined (CONFIG_MEMCPY_PRE_INC_PTRS) + +# define START_VAL(x) (x)-- +# define INC_VAL(x) *++(x) +# define CAST_TO_U8(p, o) ((uint8_t*)p + o + TYPE_WIDTH) +# define WHILE_DEST_BREAK (TYPE_WIDTH - 1) +# define PRE_LOOP_ADJUST - (TYPE_WIDTH - 1) +# define PRE_SWITCH_ADJUST + 1 + +#else /* CONFIG_MEMCPY_PRE_INC_PTRS */ + +# define START_VAL(x) +# define INC_VAL(x) *(x)++ +# define CAST_TO_U8(p, o) ((uint8_t*)p + o) +# define WHILE_DEST_BREAK 0 +# define PRE_LOOP_ADJUST +# define PRE_SWITCH_ADJUST + +#endif /* CONFIG_MEMCPY_PRE_INC_PTRS */ + +/* Definitions for endian-ness */ + +#ifdef CONFIG_ENDIAN_BIG + +# define SHL << +# define SHR >> + +#else /* CONFIG_ENDIAN_BIG */ + +# define SHL >> +# define SHR << + +#endif /* CONFIG_ENDIAN_BIG */ + +/******************************************************************** + * Macros for copying words of different alignment. + * Uses incremening pointers. + *******************************************************************/ + +#define CP_INCR() \ +{ \ + INC_VAL(dstN) = INC_VAL(srcN); \ +} + +#define CP_INCR_SH(shl, shr) \ +{ \ + dstWord = srcWord SHL shl; \ + srcWord = INC_VAL(srcN); \ + dstWord |= srcWord SHR shr; \ + INC_VAL(dstN) = dstWord; \ +} + +/******************************************************************** + * Macros for copying words of different alignment. + * Uses array indexes. + *******************************************************************/ + +#define CP_INDEX(idx) \ +{ \ + dstN[idx] = srcN[idx]; \ +} + +#define CP_INDEX_SH(x, shl, shr) \ +{ \ + dstWord = srcWord SHL shl; \ + srcWord = srcN[x]; \ + dstWord |= srcWord SHR shr; \ + dstN[x] = dstWord; \ +} + +/******************************************************************** + * Macros for copying words of different alignment. + * Uses incremening pointers or array indexes depending on + * configuration. + *******************************************************************/ + +#if defined (CONFIG_MEMCPY_INDEXED_COPY) + +# define CP(idx) CP_INDEX(idx) +# define CP_SH(idx, shl, shr) CP_INDEX_SH(idx, shl, shr) + +# define INC_INDEX(p, o) ((p) += (o)) + +#else /* CONFIG_MEMCPY_INDEXED_COPY */ + +# define CP(idx) CP_INCR() +# define CP_SH(idx, shl, shr) CP_INCR_SH(shl, shr) + +# define INC_INDEX(p, o) + +#endif /* CONFIG_MEMCPY_INDEXED_COPY */ + +#define COPY_REMAINING(count) \ +{ \ + START_VAL(dst8); \ + START_VAL(src8); \ + \ + switch (count) \ + { \ + case 7: INC_VAL(dst8) = INC_VAL(src8); \ + case 6: INC_VAL(dst8) = INC_VAL(src8); \ + case 5: INC_VAL(dst8) = INC_VAL(src8); \ + case 4: INC_VAL(dst8) = INC_VAL(src8); \ + case 3: INC_VAL(dst8) = INC_VAL(src8); \ + case 2: INC_VAL(dst8) = INC_VAL(src8); \ + case 1: INC_VAL(dst8) = INC_VAL(src8); \ + case 0: \ + default: break; \ + } \ +} + +#define COPY_NO_SHIFT() \ +{ \ + UIntN* dstN = (UIntN*)(dst8 PRE_LOOP_ADJUST); \ + UIntN* srcN = (UIntN*)(src8 PRE_LOOP_ADJUST); \ + size_t length = count / TYPE_WIDTH; \ + \ + while (length & 7) \ + { \ + CP_INCR(); \ + length--; \ + } \ + \ + length /= 8; \ + \ + while (length--) \ + { \ + CP(0); \ + CP(1); \ + CP(2); \ + CP(3); \ + CP(4); \ + CP(5); \ + CP(6); \ + CP(7); \ + \ + INC_INDEX(dstN, 8); \ + INC_INDEX(srcN, 8); \ + } \ + \ + src8 = CAST_TO_U8(srcN, 0); \ + dst8 = CAST_TO_U8(dstN, 0); \ + \ + COPY_REMAINING(count & (TYPE_WIDTH - 1)); \ + \ + return dest; \ +} + +#define COPY_SHIFT(shift) \ +{ \ + UIntN* dstN = (UIntN*)((((UIntN)dst8) PRE_LOOP_ADJUST) & \ + ~(TYPE_WIDTH - 1)); \ + UIntN* srcN = (UIntN*)((((UIntN)src8) PRE_LOOP_ADJUST) & \ + ~(TYPE_WIDTH - 1)); \ + size_t length = count / TYPE_WIDTH; \ + UIntN srcWord = INC_VAL(srcN); \ + UIntN dstWord; \ + \ + while (length & 7) \ + { \ + CP_INCR_SH(8 * shift, 8 * (TYPE_WIDTH - shift)); \ + length--; \ + } \ + \ + length /= 8; \ + \ + while (length--) \ + { \ + CP_SH(0, 8 * shift, 8 * (TYPE_WIDTH - shift)); \ + CP_SH(1, 8 * shift, 8 * (TYPE_WIDTH - shift)); \ + CP_SH(2, 8 * shift, 8 * (TYPE_WIDTH - shift)); \ + CP_SH(3, 8 * shift, 8 * (TYPE_WIDTH - shift)); \ + CP_SH(4, 8 * shift, 8 * (TYPE_WIDTH - shift)); \ + CP_SH(5, 8 * shift, 8 * (TYPE_WIDTH - shift)); \ + CP_SH(6, 8 * shift, 8 * (TYPE_WIDTH - shift)); \ + CP_SH(7, 8 * shift, 8 * (TYPE_WIDTH - shift)); \ + \ + INC_INDEX(dstN, 8); \ + INC_INDEX(srcN, 8); \ + } \ + \ + src8 = CAST_TO_U8(srcN, (shift - TYPE_WIDTH)); \ + dst8 = CAST_TO_U8(dstN, 0); \ + \ + COPY_REMAINING(count & (TYPE_WIDTH - 1)); \ + \ + return dest; \ +} + +/******************************************************************** + * Type Definitions + *******************************************************************/ + +#ifdef CONFIG_MEMCPY_64BIT +typedef uint64_t UIntN; +# define TYPE_WIDTH 8L +#else +typedef uint32_t UIntN; +# define TYPE_WIDTH 4L +#endif + +/******************************************************************** + * Public Functions + *******************************************************************/ +/******************************************************************** + * Name: memcpy + * + * Description: + * Copies count bytes from src to dest. No overlap check is performed. + * + * Input Parameters: + * dest - pointer to destination buffer + * src - pointer to source buffer + * count - number of bytes to copy + * + * Returned Value: + * A pointer to destination buffer + * + *******************************************************************/ + +void *memcpy(void *dest, const void *src, size_t count) +{ + uint8_t *dst8 = (uint8_t*)dest; + uint8_t *src8 = (uint8_t*)src; + + if (count < 8) + { + COPY_REMAINING(count); + return dest; + } + + START_VAL(dst8); + START_VAL(src8); + + while (((UIntN)dst8 & (TYPE_WIDTH - 1)) != WHILE_DEST_BREAK) + { + INC_VAL(dst8) = INC_VAL(src8); + count--; + } + + switch ((((UIntN)src8) PRE_SWITCH_ADJUST) & (TYPE_WIDTH - 1)) + { + case 0: COPY_NO_SHIFT(); break; + case 1: COPY_SHIFT(1); break; + case 2: COPY_SHIFT(2); break; + case 3: COPY_SHIFT(3); break; +#if TYPE_WIDTH > 4 + case 4: COPY_SHIFT(4); break; + case 5: COPY_SHIFT(5); break; + case 6: COPY_SHIFT(6); break; + case 7: COPY_SHIFT(7); break; +#endif + } + + return dest; +} diff --git a/nuttx/libc/termios/Make.defs b/nuttx/libc/termios/Make.defs new file mode 100644 index 000000000..d20a5f95c --- /dev/null +++ b/nuttx/libc/termios/Make.defs @@ -0,0 +1,54 @@ +############################################################################ +# libc/misc/Make.defs +# +# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# 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. +# +############################################################################ + +# termios.h support requires file descriptors and that CONFIG_SERIAL_TERMIOS +# is defined + +ifneq ($(CONFIG_NFILE_DESCRIPTORS),0) +ifeq ($(CONFIG_SERIAL_TERMIOS),y) + +# Add the termios C files to the build + +CSRCS += lib_cfgetspeed.c lib_cfsetspeed.c lib_tcflush.c +CSRCS += lib_tcgetattr.c lib_tcsetattr.c + +# Add the termios directory to the build + +DEPPATH += --dep-path termios +VPATH += termios + +endif +endif + diff --git a/nuttx/libc/termios/lib_cfgetspeed.c b/nuttx/libc/termios/lib_cfgetspeed.c new file mode 100644 index 000000000..da10daac1 --- /dev/null +++ b/nuttx/libc/termios/lib_cfgetspeed.c @@ -0,0 +1,93 @@ +/**************************************************************************** + * libc/termios/lib_cfgetspeed.c + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Public Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: cfgetspeed + * + * Descripton: + * The cfgetspeed() function is a non-POSIX function will extract the baud + * from the termios structure to which the termiosp argument points. + * + * This function will return exactly the value in the termios data + * structure, without interpretation. + * + * NOTE 1: NuttX does not control input/output baud independently. Both + * must be the same. The POSIX standard interfaces, cfisetispeed() and + * cfisetospeed() are defined to be cfgetspeed() in termios.h. + * NOTE 2. In Nuttx, the speed_t is defined to be uint32_t and the baud + * encodings of termios.h are the actual baud values themselves. Therefore, + * any baud value may be returned here... not just those enumerated in + * termios.h + * + * Input Parameters: + * termiosp - The termiosp argument is a pointer to a termios structure. + * + * Returned Value: + * Encoded baud value from the termios structure. + * + ****************************************************************************/ + +speed_t cfgetspeed(FAR const struct termios *termiosp) +{ + DEBUGASSERT(termiosp); + return termiosp->c_speed; +} diff --git a/nuttx/libc/termios/lib_cfsetspeed.c b/nuttx/libc/termios/lib_cfsetspeed.c new file mode 100644 index 000000000..a2a9475c4 --- /dev/null +++ b/nuttx/libc/termios/lib_cfsetspeed.c @@ -0,0 +1,116 @@ +/**************************************************************************** + * libc/termios/lib_cfsetspeed.c + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Public Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: cfsetspeed + * + * Descripton: + * The cfsetspeed() function is a non-POSIX function that sets the baud + * stored in the structure pointed to by termiosp to speed. + * + * There is no effect on the baud set in the hardware until a subsequent + * successful call to tcsetattr() on the same termios structure. + * + * NOTE 1: NuttX does not control input/output baud independently. Both + * must be the same. The POSIX standard interfaces, cfisetispeed() and + * cfisetospeed() are defined to be cfsetspeed() in termios.h. + * + * NOTE 3: A consequence of NOTE 1 is that you should never attempt to + * set the input and output baud to different values. + * + * Also, the following POSIX requirement cannot be supported: "If the input + * baud rate stored in the termios structure pointed to by termios_p is 0, + * the input baud rate given to the hardware will be the same as the output + * baud rate stored in the termios structure." + * + * NOTE 2. In Nuttx, the speed_t is defined to be uint32_t and the baud + * encodings of termios.h are the actual baud values themselves. Therefore, + * any baud value can be provided as the speed argument here. However, if + * you do so, your code will *NOT* be portable to other environments where + * speed_t is smaller and where the termios.h baud values are encoded! To + * avoid portability issues, use the baud definitions in termios.h! + * + * Linux, for example, would require this (also non-portable) sequence: + * + * cfsetispeed(termiosp, BOTHER); + * termiosp->c_ispeed = baud; + * + * cfsetospeed(termiosp, BOTHER); + * termiosp->c_ospeed = baud; + * + * Input Parameters: + * termiosp - The termiosp argument is a pointer to a termios structure. + * speed - The new input speed + * + * Returned Value: + * Baud is not checked... OK is always returned (this is non-standard + * behavior). + * + ****************************************************************************/ + +int cfsetspeed(FAR struct termios *termiosp, speed_t speed) +{ + DEBUGASSERT(termiosp); + termiosp->c_speed = speed; + return OK; +} diff --git a/nuttx/libc/termios/lib_tcflush.c b/nuttx/libc/termios/lib_tcflush.c new file mode 100644 index 000000000..1a9710f6a --- /dev/null +++ b/nuttx/libc/termios/lib_tcflush.c @@ -0,0 +1,88 @@ +/**************************************************************************** + * libc/termios/lib_tcflush.c + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include + +#include +#include + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Public Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: tcflush + * + * Descripton: + * Function for flushing a terminal/serial device + * + * Input Parameters: + * fd - The 'fd' argument is an open file descriptor associated with a terminal. + * cmd - The TCFLSH ioctl argument. + * + * Returned Value: + * Upon successful completion, 0 is returned. Otherwise, -1 is returned and + * errno is set to indicate the error. + * + ****************************************************************************/ + +int tcflush(int fd, int cmd) +{ + return ioctl(fd, TCFLSH, (unsigned long)cmd); +} diff --git a/nuttx/libc/termios/lib_tcgetattr.c b/nuttx/libc/termios/lib_tcgetattr.c new file mode 100644 index 000000000..e8d311260 --- /dev/null +++ b/nuttx/libc/termios/lib_tcgetattr.c @@ -0,0 +1,93 @@ +/**************************************************************************** + * libc/termios/lib_tcgetattr.c + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include + +#include +#include + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Public Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: tcgetattr + * + * Descripton: + * The tcgetattr() function gets the parameters associated with the + * terminal referred to by 'fd' and stores them in the termios structure + * referenced by 'termiosp'. + * + * Input Parameters: + * fd - The 'fd' argument is an open file descriptor associated with a terminal. + * termiosp - The termiosp argument is a pointer to a termios structure. + * + * Returned Value: + * Upon successful completion, 0 is returned. Otherwise, -1 is returned and + * errno is set to indicate the error. The following errors may be reported: + * + * - EBADF: The 'fd' argument is not a valid file descriptor. + * - ENOTTY: The file associated with 'fd' is not a terminal. + * + ****************************************************************************/ + +int tcgetattr(int fd, FAR struct termios *termiosp) +{ + return ioctl(fd, TCGETS, (unsigned long)termiosp); +} diff --git a/nuttx/libc/termios/lib_tcsetattr.c b/nuttx/libc/termios/lib_tcsetattr.c new file mode 100644 index 000000000..901f2a136 --- /dev/null +++ b/nuttx/libc/termios/lib_tcsetattr.c @@ -0,0 +1,122 @@ +/**************************************************************************** + * libc/termios/lib_tcsetattr.c + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include + +#include +#include + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Public Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: tcsetattr + * + * Descripton: + * The tcsetattr() function sets the parameters associated with the + * terminal referred to by the open file descriptor 'fd' from the termios + * structure referenced by 'termiop' as follows: + * + * If 'options' is TCSANOW, the change will occur immediately. + * + * If 'options' is TCSADRAIN, the change will occur after all output + * written to 'fd' is transmitted. This function should be used when changing + * parameters that affect output. + * + * If 'options' is TCSAFLUSH, the change will occur after all + * output written to 'fd' is transmitted, and all input so far received but + * not read will be discarded before the change is made. + * + * The tcsetattr() function will return successfully if it was able to + * perform any of the requested actions, even if some of the requested + * actions could not be performed. It will set all the attributes that + * implementation supports as requested and leave all the attributes not + * supported by the implementation unchanged. If no part of the request + * can be honoured, it will return -1 and set errno to EINVAL. + * + * The effect of tcsetattr() is undefined if the value of the termios + * structure pointed to by 'termiop' was not derived from the result of + * a call to tcgetattr() on 'fd'; an application should modify only fields + * and flags defined by this specification between the call to tcgetattr() + * and tcsetattr(), leaving all other fields and flags unmodified. + * + * Returned Value: + * + * Upon successful completion, 0 is returned. Otherwise, -1 is returned + * and errno is set to indicate the error. The following errors may be + * reported: + * + * - EBADF: The 'fd' argument is not a valid file descriptor. + * - EINTR: A signal interrupted tcsetattr(). + * - EINVAL: The 'options' argument is not a supported value, or + * an attempt was made to change an attribute represented in the + * termios structure to an unsupported value. + * - ENOTTY: The file associated with 'fd' is not a terminal. + * + ****************************************************************************/ + +int tcsetattr(int fd, int options, FAR const struct termios *termiosp) +{ + if (options == TCSANOW) + { + return ioctl(fd, TCSETS, (unsigned long)termiosp); + } + return -ENOSYS; +} diff --git a/nuttx/libc/time/Make.defs b/nuttx/libc/time/Make.defs new file mode 100644 index 000000000..4848813d1 --- /dev/null +++ b/nuttx/libc/time/Make.defs @@ -0,0 +1,44 @@ +############################################################################ +# libc/time/Make.defs +# +# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# 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. +# +############################################################################ + +# Add the time C files to the build + +CSRCS += lib_mktime.c lib_gmtime.c lib_gmtimer.c lib_strftime.c \ + lib_calendar2utc.c lib_daysbeforemonth.c lib_isleapyear.c lib_time.c + +# Add the time directory to the build + +DEPPATH += --dep-path time +VPATH += :time diff --git a/nuttx/libc/time/lib_calendar2utc.c b/nuttx/libc/time/lib_calendar2utc.c new file mode 100644 index 000000000..1b8c40a9e --- /dev/null +++ b/nuttx/libc/time/lib_calendar2utc.c @@ -0,0 +1,209 @@ +/**************************************************************************** + * libc/time/lib_calendar2utc.c + * + * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include +#include + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Public Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Public Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: clock_gregorian2utc, clock_julian2utc + * + * Description: + * UTC conversion routines. These conversions are based + * on algorithms from p. 604 of Seidelman, P. K. 1992. + * Explanatory Supplement to the Astronomical Almanac. + * University Science Books, Mill Valley. + * + ****************************************************************************/ + +#ifdef CONFIG_GREGORIAN_TIME +static time_t clock_gregorian2utc(int year, int month, int day) +{ + int temp; + + /* temp = (month - 14)/12; */ + + temp = (month <= 2 ? -1:0); + + return (1461*(year + 4800 + temp))/4 + + (367*(month - 2 - 12*temp))/12 + - (3*((year + 4900 + temp)/100))/4 + day - 32075; +} + +#ifdef CONFIG_JULIAN_TIME +static time_t clock_julian2utc(int year, int month, int day) +{ + return 367*year + - (7*(year + 5001 + (month-9)/7))/4 + + (275*month)/9 + + day + 1729777; +} +#endif /* CONFIG_JULIAN_TIME */ +#endif /* CONFIG_GREGORIAN_TIME */ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: clock_calendar2utc + * + * Description: + * Calendar/UTC conversion based on algorithms from p. 604 + * of Seidelman, P. K. 1992. Explanatory Supplement to + * the Astronomical Almanac. University Science Books, + * Mill Valley. + * + ****************************************************************************/ + +#ifdef CONFIG_GREGORIAN_TIME +time_t clock_calendar2utc(int year, int month, int day) +{ + int dyear; +#ifdef CONFIG_JULIAN_TIME + bool isgreg; +#endif /* CONFIG_JULIAN_TIME */ + + /* Correct year & month ranges. Shift month into range 1-12 */ + + dyear = (month-1) / 12; + month -= 12 * dyear; + year += dyear; + + if (month < 1) + { + month += 12; + year -= 1; + } + +#ifdef CONFIG_JULIAN_TIME + /* Determine which calendar to use */ + + if (year > GREG_YEAR) + { + isgreg = true; + } + else if (year < GREG_YEAR) + { + isgreg = false; + } + else if (month > GREG_MONTH) + { + isgreg = true; + } + else if (month < GREG_MONTH) + { + isgreg = false; + } + else + { + isgreg = (day >= GREG_DAY); + } + + /* Calculate and return date */ + + if (isgreg) + { + return clock_gregorian2utc(year, month, day) - JD_OF_EPOCH; + } + else + { + return clock_julian2utc (year, month, day) - JD_OF_EPOCH; + } + +#else /* CONFIG_JULIAN_TIME */ + + return clock_gregorian2utc(year, month, day) - JD_OF_EPOCH; + +#endif /* CONFIG_JULIAN_TIME */ +} +#else + +/* A highly simplified version that only handles days in the time + * since Jan 1, 1970. + */ + +time_t clock_calendar2utc(int year, int month, int day) +{ + struct tm t; + + /* mktime can (kind of) do this */ + + t.tm_year = year; + t.tm_mon = month; + t.tm_mday = day; + t.tm_hour = 0; + t.tm_min = 0; + t.tm_sec = 0; + return mktime(&t); +} +#endif /* CONFIG_GREGORIAN_TIME */ + diff --git a/nuttx/libc/time/lib_daysbeforemonth.c b/nuttx/libc/time/lib_daysbeforemonth.c new file mode 100644 index 000000000..28f4d67a9 --- /dev/null +++ b/nuttx/libc/time/lib_daysbeforemonth.c @@ -0,0 +1,102 @@ +/**************************************************************************** + * libc/time/lib_daysbeforemonth.c + * + * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Public Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Public Variables + ****************************************************************************/ + +uint16_t g_daysbeforemonth[13] = +{ + 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 +}; + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: clock_daysbeforemonth + * + * Description: + * Get the number of days that occurred before the beginning of the month. + * + ****************************************************************************/ + +int clock_daysbeforemonth(int month, bool leapyear) +{ + int retval = g_daysbeforemonth[month]; + if (month >= 2 && leapyear) + { + retval++; + } + return retval; +} + + diff --git a/nuttx/libc/time/lib_gmtime.c b/nuttx/libc/time/lib_gmtime.c new file mode 100644 index 000000000..7a4d0f5e1 --- /dev/null +++ b/nuttx/libc/time/lib_gmtime.c @@ -0,0 +1,93 @@ +/**************************************************************************** + * libc/time/lib_gmtime.c + * + * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include +#include + +#include + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/************************************************************************** + * Public Constant Data + **************************************************************************/ + +/**************************************************************************** + * Public Variables + ****************************************************************************/ + +/************************************************************************** + * Private Variables + **************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: gmtime + * + * Description: + * Similar to gmtime_r, but not thread-safe + * + ****************************************************************************/ + +struct tm *gmtime(const time_t *timer) +{ + static struct tm tm; + return gmtime_r(timer, &tm); +} + diff --git a/nuttx/libc/time/lib_gmtimer.c b/nuttx/libc/time/lib_gmtimer.c new file mode 100644 index 000000000..d98620527 --- /dev/null +++ b/nuttx/libc/time/lib_gmtimer.c @@ -0,0 +1,355 @@ +/**************************************************************************** + * libc/time/lib_gmtimer.c + * + * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include +#include +#include + +#include + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +#define SEC_PER_MIN ((time_t)60) +#define SEC_PER_HOUR ((time_t)60 * SEC_PER_MIN) +#define SEC_PER_DAY ((time_t)24 * SEC_PER_HOUR) + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/* Calendar/UTC conversion routines */ + +static void clock_utc2calendar(time_t utc, int *year, int *month, int *day); +#ifdef CONFIG_GREGORIAN_TIME +static void clock_utc2gregorian (time_t jdn, int *year, int *month, int *day); + +#ifdef CONFIG_JULIAN_TIME +static void clock_utc2julian(time_t jdn, int *year, int *month, int *day); +#endif /* CONFIG_JULIAN_TIME */ +#endif /* CONFIG_GREGORIAN_TIME */ + +/************************************************************************** + * Public Constant Data + **************************************************************************/ + +/**************************************************************************** + * Public Variables + ****************************************************************************/ + +/************************************************************************** + * Private Variables + **************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: clock_calendar2utc, clock_gregorian2utc, + * and clock_julian2utc + * + * Description: + * Calendar to UTC conversion routines. These conversions + * are based on algorithms from p. 604 of Seidelman, P. K. + * 1992. Explanatory Supplement to the Astronomical + * Almanac. University Science Books, Mill Valley. + * + ****************************************************************************/ + +#ifdef CONFIG_GREGORIAN_TIME +static void clock_utc2calendar(time_t utc, int *year, int *month, int *day) +{ +#ifdef CONFIG_JULIAN_TIME + + if (utc >= GREG_DUTC) + { + clock_utc2gregorian(utc + JD_OF_EPOCH, year, month, day); + } + else + { + clock_utc2julian (utc + JD_OF_EPOCH, year, month, day); + } + +#else /* CONFIG_JULIAN_TIME */ + + clock_utc2gregorian(utc + JD_OF_EPOCH, year, month, day); + +#endif /* CONFIG_JULIAN_TIME */ +} + +static void clock_utc2gregorian(time_t jd, int *year, int *month, int *day) +{ + long l, n, i, j, d, m, y; + + l = jd + 68569; + n = (4*l) / 146097; + l = l - (146097*n + 3)/4; + i = (4000*(l+1))/1461001; + l = l - (1461*i)/4 + 31; + j = (80*l)/2447; + d = l - (2447*j)/80; + l = j/11; + m = j + 2 - 12*l; + y = 100*(n-49) + i + l; + + *year = y; + *month = m; + *day = d; +} + +#ifdef CONFIG_JULIAN_TIME + +static void clock_utc2julian(time_t jd, int *year, int *month, int *day) +{ + long j, k, l, n, d, i, m, y; + + j = jd + 1402; + k = (j-1)/1461; + l = j - 1461*k; + n = (l-1)/365 - l/1461; + i = l - 365*n + 30; + j = (80*i)/2447; + d = i - (2447*j)/80; + i = j/11; + m = j + 2 - 12*i; + y = 4*k + n + i - 4716; + + *year = y; + *month = m; + *day = d; +} + +#endif /* CONFIG_JULIAN_TIME */ +#else/* CONFIG_GREGORIAN_TIME */ + +/* Only handles dates since Jan 1, 1970 */ + +static void clock_utc2calendar(time_t days, int *year, int *month, int *day) +{ + int value; + int min; + int max; + int tmp; + bool leapyear; + + /* There is one leap year every four years, so we can get close with the + * following: + */ + + value = days / (4*365 + 1); /* Number of 4-years periods since the epoch*/ + days -= value * (4*365 + 1); /* Remaining days */ + value <<= 2; /* Years since the epoch */ + + /* Then we will brute force the next 0-3 years */ + + for (;;) + { + /* Is this year a leap year (we'll need this later too) */ + + leapyear = clock_isleapyear(value + 1970); + + /* Get the number of days in the year */ + + tmp = (leapyear ? 366 : 365); + + /* Do we have that many days? */ + + if (days >= tmp) + { + /* Yes.. bump up the year */ + + value++; + days -= tmp; + } + else + { + /* Nope... then go handle months */ + + break; + } + } + + /* At this point, value has the year and days has number days into this year */ + + *year = 1970 + value; + + /* Handle the month (zero based) */ + + min = 0; + max = 11; + + do + { + /* Get the midpoint */ + + value = (min + max) >> 1; + + /* Get the number of days that occurred before the beginning of the month + * following the midpoint. + */ + + tmp = clock_daysbeforemonth(value + 1, leapyear); + + /* Does the number of days before this month that equal or exceed the + * number of days we have remaining? + */ + + if (tmp > days) + { + /* Yes.. then the month we want is somewhere from 'min' and to the + * midpoint, 'value'. Could it be the midpoint? + */ + + tmp = clock_daysbeforemonth(value, leapyear); + if (tmp > days) + { + /* No... The one we want is somewhere between min and value-1 */ + + max = value - 1; + } + else + { + /* Yes.. 'value' contains the month that we want */ + + break; + } + } + else + { + /* No... The one we want is somwhere between value+1 and max */ + + min = value + 1; + } + + /* If we break out of the loop because min == max, then we want value + * to be equal to min == max. + */ + + value = min; + } + while (min < max); + + /* The selected month number is in value. Subtract the number of days in the + * selected month + */ + + days -= clock_daysbeforemonth(value, leapyear); + + /* At this point, value has the month into this year (zero based) and days has + * number of days into this month (zero based) + */ + + *month = value + 1; /* 1-based */ + *day = days + 1; /* 1-based */ +} + +#endif /* CONFIG_GREGORIAN_TIME */ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: gmtime_r + * + * Description: + * Time conversion (based on the POSIX API) + * + ****************************************************************************/ + +FAR struct tm *gmtime_r(FAR const time_t *timer, FAR struct tm *result) +{ + time_t epoch; + time_t jdn; + int year; + int month; + int day; + int hour; + int min; + int sec; + + /* Get the seconds since the EPOCH */ + + epoch = *timer; + sdbg("timer=%d\n", (int)epoch); + + /* Convert to days, hours, minutes, and seconds since the EPOCH */ + + jdn = epoch / SEC_PER_DAY; + epoch -= SEC_PER_DAY * jdn; + + hour = epoch / SEC_PER_HOUR; + epoch -= SEC_PER_HOUR * hour; + + min = epoch / SEC_PER_MIN; + epoch -= SEC_PER_MIN * min; + + sec = epoch; + + sdbg("hour=%d min=%d sec=%d\n", + (int)hour, (int)min, (int)sec); + + /* Convert the days since the EPOCH to calendar day */ + + clock_utc2calendar(jdn, &year, &month, &day); + + sdbg("jdn=%d year=%d month=%d day=%d\n", + (int)jdn, (int)year, (int)month, (int)day); + + /* Then return the struct tm contents */ + + result->tm_year = (int)year - 1900; /* Relative to 1900 */ + result->tm_mon = (int)month - 1; /* zero-based */ + result->tm_mday = (int)day; /* one-based */ + result->tm_hour = (int)hour; + result->tm_min = (int)min; + result->tm_sec = (int)sec; + + return result; +} + diff --git a/nuttx/libc/time/lib_isleapyear.c b/nuttx/libc/time/lib_isleapyear.c new file mode 100644 index 000000000..386e205b2 --- /dev/null +++ b/nuttx/libc/time/lib_isleapyear.c @@ -0,0 +1,88 @@ +/**************************************************************************** + * libc/time/lib_isleapyear.c + * + * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Public Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Public Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: clock_isleapyear + * + * Description: + * Return true if the specified year is a leap year + * + ****************************************************************************/ + +int clock_isleapyear(int year) +{ + return year % 400 ? (year % 100 ? (year % 4 ? 0 : 1) : 0) : 1; +} + diff --git a/nuttx/libc/time/lib_mktime.c b/nuttx/libc/time/lib_mktime.c new file mode 100644 index 000000000..25254d70e --- /dev/null +++ b/nuttx/libc/time/lib_mktime.c @@ -0,0 +1,141 @@ +/**************************************************************************** + * libc/time/lib_mktime.c + * + * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include + +#include + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Public Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Public Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: mktime + * + * Description: + * Time conversion (based on the POSIX API) + * + ****************************************************************************/ + +#ifdef CONFIG_GREGORIAN_TIME +time_t mktime(const struct tm *tp) +{ + time_t ret; + time_t jdn; + + /* Get the EPOCH-relative julian date from the calendar year, + * month, and date + */ + + jdn = clock_calendar2utc(tp->tm_year+1900, tp->tm_mon+1, tp->tm_mday); + sdbg("jdn=%d tm_year=%d tm_mon=%d tm_mday=%d\n", + (int)jdn, tp->tm_year, tp->tm_mon, tp->tm_mday); + + /* Return the seconds into the julian day. */ + + ret = ((jdn*24 + tp->tm_hour)*60 + tp->tm_min)*60 + tp->tm_sec; + sdbg("ret=%d tm_hour=%d tm_min=%d tm_sec=%d\n", + (int)ret, tp->tm_hour, tp->tm_min, tp->tm_sec); + + return ret; +} +#else + +/* Simple version that only works for dates within a (relatively) small range + * from the epoch. It does not handle earlier days or longer days where leap + * seconds, etc. apply. + */ + +time_t mktime(const struct tm *tp) +{ + unsigned int days; + + /* Years since epoch in units of days (ignoring leap years). */ + + days = (tp->tm_year - 70) * 365; + + /* Add in the extra days for the leap years prior to the current year. */ + + days += (tp->tm_year - 69) >> 2; + + /* Add in the days up to the beginning of this month. */ + + days += (time_t)clock_daysbeforemonth(tp->tm_mon, clock_isleapyear(tp->tm_year + 1900)); + + /* Add in the days since the beginning of this month (days are 1-based). */ + + days += tp->tm_mday - 1; + + /* Then convert the seconds and add in hours, minutes, and seconds */ + + return ((days * 24 + tp->tm_hour) * 60 + tp->tm_min) * 60 + tp->tm_sec; +} +#endif /* CONFIG_GREGORIAN_TIME */ + diff --git a/nuttx/libc/time/lib_strftime.c b/nuttx/libc/time/lib_strftime.c new file mode 100644 index 000000000..3b0c8dd8f --- /dev/null +++ b/nuttx/libc/time/lib_strftime.c @@ -0,0 +1,398 @@ +/**************************************************************************** + * libc/time/lib_strftime.c + * + * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 +#include + +#include +#include +#include + +#include + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Public Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const char * const g_abbrevmonthname[12] = +{ + "Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" +}; + +static const char * const g_monthname[12] = +{ + "January", "February", "March", "April", "May", "June", + "July", "August", "September", "October", "November", "December" +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: strftime + * + * Description: + * The strftime() function formats the broken-down time tm according to + * the format specification format and places the result in the character + * array s of size max. + * + * Ordinary characters placed in the format string are copied to s without + * conversion. Conversion specifications are introduced by a '%' charac- + * ter, and terminated by a conversion specifier character, and are + * replaced in s as follows: + * + * %b The abbreviated month name according to the current locale. + * %B The full month name according to the current locale. + * %C The century number (year/100) as a 2-digit integer. (SU) + * %d The day of the month as a decimal number (range 01 to 31). + * %e Like %d, the day of the month as a decimal number, but a leading + * zero is replaced by a space. + * %h Equivalent to %b. (SU) + * %H The hour as a decimal number using a 24-hour clock (range 00 to 23). + * %I The hour as a decimal number using a 12-hour clock (range 01 to 12). + * %j The day of the year as a decimal number (range 001 to 366). + * %k The hour (24-hour clock) as a decimal number (range 0 to 23); + * single digits are preceded by a blank. (See also %H.) (TZ) + * %l The hour (12-hour clock) as a decimal number (range 1 to 12); + * single digits are preceded by a blank. (See also %I.) (TZ) + * %m The month as a decimal number (range 01 to 12). + * %M The minute as a decimal number (range 00 to 59). + * %n A newline character. (SU) + * %p Either "AM" or "PM" according to the given time value, or the + * corresponding strings for the current locale. Noon is treated + * as "PM" and midnight as "AM". + * %P Like %p but in lowercase: "am" or "pm" or a corresponding string + * for the current locale. (GNU) + * %s The number of seconds since the Epoch, that is, since 1970-01-01 + * 00:00:00 UTC. (TZ) + * %S The second as a decimal number (range 00 to 60). (The range is + * up to 60 to allow for occasional leap seconds.) + * %t A tab character. (SU) + * %y The year as a decimal number without a century (range 00 to 99). + * %Y The year as a decimal number including the century. + * %% A literal '%' character. + * + * Returned Value: + * The strftime() function returns the number of characters placed in the + * array s, not including the terminating null byte, provided the string, + * including the terminating null byte, fits. Otherwise, it returns 0, + * and the contents of the array is undefined. + * + ****************************************************************************/ + +size_t strftime(char *s, size_t max, const char *format, const struct tm *tm) +{ + const char *str; + char *dest = s; + int chleft = max; + int value; + int len; + + while (*format && chleft > 0) + { + /* Just copy regular characters */ + + if (*format != '%') + { + *dest++ = *format++; + chleft--; + continue; + } + + /* Handle the format character */ + + format++; + len = 0; + + switch (*format++) + { + /* %a: A three-letter abbreviation for the day of the week. */ + /* %A: The full name for the day of the week. */ + + case 'a': + case 'A': + { + len = snprintf(dest, chleft, "Day"); /* Not supported */ + } + break; + + /* %h: Equivalent to %b */ + + case 'h': + + /* %b: The abbreviated month name according to the current locale. */ + + case 'b': + { + if (tm->tm_mon < 12) + { + str = g_abbrevmonthname[tm->tm_mon]; + len = snprintf(dest, chleft, "%s", str); + } + } + break; + + /* %B: The full month name according to the current locale. */ + + case 'B': + { + if (tm->tm_mon < 12) + { + str = g_monthname[tm->tm_mon]; + len = snprintf(dest, chleft, "%s", str); + } + } + break; + + /* %y: The year as a decimal number without a century (range 00 to 99). */ + + case 'y': + + /* %C: The century number (year/100) as a 2-digit integer. */ + + case 'C': + { + len = snprintf(dest, chleft, "%02d", tm->tm_year % 100); + } + break; + + /* %d: The day of the month as a decimal number (range 01 to 31). */ + + case 'd': + { + len = snprintf(dest, chleft, "%02d", tm->tm_mday); + } + break; + + /* %e: Like %d, the day of the month as a decimal number, but a leading + * zero is replaced by a space. + */ + + case 'e': + { + len = snprintf(dest, chleft, "%2d", tm->tm_mday); + } + break; + + /* %H: The hour as a decimal number using a 24-hour clock (range 00 to 23). */ + + case 'H': + { + len = snprintf(dest, chleft, "%02d", tm->tm_hour); + } + break; + + /* %I: The hour as a decimal number using a 12-hour clock (range 01 to 12). */ + + case 'I': + { + len = snprintf(dest, chleft, "%02d", tm->tm_hour % 12); + } + break; + + /* %j: The day of the year as a decimal number (range 001 to 366). */ + + case 'j': + { + if (tm->tm_mon < 12) + { + value = clock_daysbeforemonth(tm->tm_mon, clock_isleapyear(tm->tm_year)) + tm->tm_mday; + len = snprintf(dest, chleft, "%03d", value); + } + } + break; + + /* %k: The hour (24-hour clock) as a decimal number (range 0 to 23); + * single digits are preceded by a blank. + */ + + case 'k': + { + len = snprintf(dest, chleft, "%2d", tm->tm_hour); + } + break; + + /* %l: The hour (12-hour clock) as a decimal number (range 1 to 12); + * single digits are preceded by a blank. + */ + + case 'l': + { + len = snprintf(dest, chleft, "%2d", tm->tm_hour % 12); + } + break; + + /* %m: The month as a decimal number (range 01 to 12). */ + + case 'm': + { + len = snprintf(dest, chleft, "%02d", tm->tm_mon + 1); + } + break; + + /* %M: The minute as a decimal number (range 00 to 59). */ + + case 'M': + { + len = snprintf(dest, chleft, "%02d", tm->tm_min); + } + break; + + /* %n: A newline character. */ + + case 'n': + { + *dest = '\n'; + len = 1; + } + break; + + /* %p: Either "AM" or "PM" according to the given time value. */ + + case 'p': + { + if (tm->tm_hour >= 12) + { + str = "PM"; + } + else + { + str = "AM"; + } + len = snprintf(dest, chleft, "%s", str); + } + break; + + /* %P: Like %p but in lowercase: "am" or "pm" */ + + case 'P': + { + if (tm->tm_hour >= 12) + { + str = "pm"; + } + else + { + str = "am"; + } + len = snprintf(dest, chleft, "%s", str); + } + break; + + /* %s: The number of seconds since the Epoch, that is, since 1970-01-01 + * 00:00:00 UTC. + */ + + case 's': + { + len = snprintf(dest, chleft, "%d", mktime(tm)); + } + break; + + /* %S: The second as a decimal number (range 00 to 60). (The range is + * up to 60 to allow for occasional leap seconds.) + */ + + case 'S': + { + len = snprintf(dest, chleft, "%02d", tm->tm_sec); + } + break; + + /* %t: A tab character. */ + + case 't': + { + *dest = '\t'; + len = 1; + } + break; + + /* %Y: The year as a decimal number including the century. */ + + case 'Y': + { + len = snprintf(dest, chleft, "%04d", tm->tm_year + 1900); + } + break; + + /* %%: A literal '%' character. */ + + case '%': + { + *dest = '%'; + len = 1; + } + break; + } + + /* Update counts and pointers */ + + dest += len; + chleft -= len; + } + + return max - chleft; +} diff --git a/nuttx/libc/time/lib_time.c b/nuttx/libc/time/lib_time.c new file mode 100644 index 000000000..673f6fdcd --- /dev/null +++ b/nuttx/libc/time/lib_time.c @@ -0,0 +1,110 @@ +/**************************************************************************** + * libc/time/lib_time.c + * + * Copyright (C) 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include + +#ifndef CONFIG_DISABLE_CLOCK + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: time + * + * Description: + * Get the current calendar time as a time_t object. The function returns + * this value, and if the argument is not a null pointer, the value is also + * set to the object pointed by tloc. + * + * Note that this function is just a thin wrapper around gettimeofday() + * and is provided for compatibility. gettimeofday() is the preffered way + * to obtain system time. + * + * Parameters: + * Pointer to an object of type time_t, where the time value is stored. + * Alternativelly, this parameter can be a null pointer, in which case the + * parameter is not used, but a time_t object is still returned by the + * function. + * + * Return Value: + * The current calendar time as a time_t object. If the argument is not + * a null pointer, the return value is the same as the one stored in the + * location pointed by the argument. + * + * If the function could not retrieve the calendar time, it returns a -1 + * value. + * + ****************************************************************************/ + +time_t time(time_t *tloc) +{ + struct timeval tp; + int ret; + + /* Get the current time from the system */ + + ret = gettimeofday(&tp, NULL); + if (ret == OK) + { + /* Return the seconds since the epoch */ + + if (tloc) + { + *tloc = tp.tv_sec; + } + + return tp.tv_sec; + } + + return (time_t)ERROR; +} + +#endif /* !CONFIG_DISABLE_CLOCK */ diff --git a/nuttx/libc/unistd/Make.defs b/nuttx/libc/unistd/Make.defs new file mode 100644 index 000000000..67fce9b1d --- /dev/null +++ b/nuttx/libc/unistd/Make.defs @@ -0,0 +1,49 @@ +############################################################################ +# libc/unistd/Make.defs +# +# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# 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. +# +############################################################################ + +# Add the unistd C files to the build + +CSRCS += lib_getopt.c lib_getoptargp.c lib_getoptindp.c lib_getoptoptp.c + +ifneq ($(CONFIG_NFILE_DESCRIPTORS),0) +ifneq ($(CONFIG_DISABLE_ENVIRON),y) +CSRCS += lib_chdir.c lib_getcwd.c +endif +endif + +# Add the unistd directory to the build + +DEPPATH += --dep-path unistd +VPATH += :unistd diff --git a/nuttx/libc/unistd/lib_chdir.c b/nuttx/libc/unistd/lib_chdir.c new file mode 100644 index 000000000..8953fb19b --- /dev/null +++ b/nuttx/libc/unistd/lib_chdir.c @@ -0,0 +1,179 @@ +/**************************************************************************** + * libc/unistd/lib_chdir.c + * + * Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include +#include +#include +#include + +#include "lib_internal.h" + +#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_ENVIRON) + +/**************************************************************************** + * Public Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: _trimdir + ****************************************************************************/ + +#if 0 +static inline void _trimdir(char *path) +{ + /* Skip any trailing '/' characters (unless it is also the leading '/') */ + + int len = strlen(path) - 1; + while (len > 0 && path[len] == '/') + { + path[len] = '\0'; + len--; + } +} +#else +# define _trimdir(p) +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: chdir + * + * Description: + * The chdir() function causes the directory named by the pathname pointed + * to by the 'path' argument to become the current working directory; that + * is, the starting point for path searches for pathnames not beginning + * with '/'. + * + * Input Parmeters: + * path - A pointer to a directory to use as the new current working + * directory + * + * Returned Value: + * 0(OK) on success; -1(ERROR) on failure with errno set appropriately: + * + * EACCES + * Search permission is denied for any component of the pathname. + * ELOOP + * A loop exists in symbolic links encountered during resolution of the + * 'path' argument OR more that SYMLOOP_MAX symbolic links in the + * resolution of the 'path' argument. + * ENAMETOOLONG + * The length of the path argument exceeds PATH_MAX or a pathname component + * is longer than NAME_MAX. + * ENOENT + * A component of 'path' does not name an existing directory or path is + * an empty string. + * ENOTDIR + * A component of the pathname is not a directory. + * + ****************************************************************************/ + +int chdir(FAR const char *path) +{ + struct stat buf; + char *oldpwd; + char *alloc; + int err; + int ret; + + /* Verify the input parameters */ + + if (!path) + { + err = ENOENT; + goto errout; + } + + /* Verify that 'path' refers to a directory */ + + ret = stat(path, &buf); + if (ret != 0) + { + err = ENOENT; + goto errout; + } + + /* Something exists here... is it a directory? */ + + if (!S_ISDIR(buf.st_mode)) + { + err = ENOTDIR; + goto errout; + } + + /* Yes, it is a directory. Remove any trailing '/' characters from the path */ + + _trimdir(path); + + /* Replace any preceding OLDPWD with the current PWD (this is to + * support 'cd -' in NSH) + */ + + sched_lock(); + oldpwd = getenv("PWD"); + if (!oldpwd) + { + oldpwd = CONFIG_LIB_HOMEDIR; + } + + alloc = strdup(oldpwd); /* kludge needed because environment is realloc'ed */ + setenv("OLDPWD", alloc, TRUE); + lib_free(alloc); + + /* Set the cwd to the input 'path' */ + + setenv("PWD", path, TRUE); + sched_unlock(); + return OK; + +errout: + set_errno(err); + return ERROR; +} +#endif /* CONFIG_NFILE_DESCRIPTORS && !CONFIG_DISABLE_ENVIRON */ diff --git a/nuttx/libc/unistd/lib_getcwd.c b/nuttx/libc/unistd/lib_getcwd.c new file mode 100644 index 000000000..717ef2971 --- /dev/null +++ b/nuttx/libc/unistd/lib_getcwd.c @@ -0,0 +1,132 @@ +/**************************************************************************** + * libc/unistd/lib_getcwd.c + * + * Copyright (C) 2008, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include +#include +#include +#include + +#include "lib_internal.h" + +#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_ENVIRON) + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Variables + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: getwcd + * + * Description: + * getcwd() function places the absolute pathname of the current working + * directory in the array pointed to by 'buf', and returns 'buf.' The + * pathname copied to the array shall contain no components that are + * symbolic links. The 'size' argument is the size in bytes of the + * character array pointed to by the 'buf' argument. + * + * Input Parmeters: + * buf - a pointer to the location in which the current working directory + * pathaname is returned. + * size - The size in bytes avaiable at 'buf' + * + * Returned Value: + * Upon successful completion, getcwd() returns the 'buf' argument. + * Otherwise, getcwd() returns a null pointer and sets errno to indicate + * the error: + * + * EINVAL + * The 'size' argument is 0 or the 'buf' argument is NULL. + * ERANGE + * The size argument is greater than 0, but is smaller than the length + * of the currrent working directory pathname +1. + * EACCES + * Read or search permission was denied for a component of the pathname. + * ENOMEM + * Insufficient storage space is available. + * + ****************************************************************************/ + +FAR char *getcwd(FAR char *buf, size_t size) +{ + char *pwd; + + /* Verify input parameters */ + +#ifdef CONFIG_DEBUG + if (!buf || !size) + { + set_errno(EINVAL); + return NULL; + } +#endif + + /* If no working directory is defined, then default to the home directory */ + + pwd = getenv("PWD"); + if (!pwd) + { + pwd = CONFIG_LIB_HOMEDIR; + } + + /* Verify that the cwd will fit into the user-provided buffer */ + + if (strlen(pwd) + 1 > size) + { + set_errno(ERANGE); + return NULL; + } + + /* Copy the cwd to the user buffer */ + + strcpy(buf, pwd); + sched_unlock(); + return buf; +} +#endif /* CONFIG_NFILE_DESCRIPTORS && !CONFIG_DISABLE_ENVIRON */ diff --git a/nuttx/libc/unistd/lib_getopt.c b/nuttx/libc/unistd/lib_getopt.c new file mode 100644 index 000000000..1a9190976 --- /dev/null +++ b/nuttx/libc/unistd/lib_getopt.c @@ -0,0 +1,269 @@ +/**************************************************************************** + * libc/unistd/lib_getopt.c + * + * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +FAR char *optarg; /* Optional argument following option */ +int optind = 1; /* Index into argv */ +int optopt = '?'; /* unrecognized option character */ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +static FAR char *g_optptr = NULL; +static bool g_binitialized = false; + +/**************************************************************************** + * Global Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: getopt + * + * Description: getopt() parses command-line arguments. Its arguments argc + * and argv are the argument count and array as passed to the main() + * function on program invocation. An element of argv that starts with + * '-' is an option element. The characters of this element (aside from + * the initial '-') are option characters. If getopt() is called repeatedly, + * it returns successively each of the option characters from each of the + * option elements. + * + * If getopt() finds another option character, it returns that character, + * updating the external variable optind and a static variable nextchar so + * that the next call to getopt() can resume the scan with the following + * option character or argv-element. + * + * If there are no more option characters, getopt() returns -1. Then optind + * is the index in argv of the first argv-element that is not an option. + * + * The 'optstring' argument is a string containing the legitimate option + * characters. If such a character is followed by a colon, this indicates + * that the option requires an argument. If an argument is required for an + * option so getopt() places a pointer to the following text in the same + * argv-element, or the text of the following argv-element, in optarg. + * + * NOTES: + * 1. opterr is not supported and this implementation of getopt() never + * printfs error messages. + * 2. getopt is NOT threadsafe! + * 3. This version of getopt() does not reset global variables until + * -1 is returned. As a result, your command line parsing loops + * must call getopt() repeatedly and continue to parse if other + * errors are returned ('?' or ':') until getopt() finally returns -1. + * (You can also set optind to -1 to force a reset). + * + * Return: If an option was successfully found, then getopt() returns the + * option character. If all command-line options have been parsed, then + * getopt() returns -1. If getopt() encounters an option character that + * was not in optstring, then '?' is returned. If getopt() encounters an + * option with a missing argument, then the return value depends on the + * first character in optstring: if it is ':', then ':' is returned; + * otherwise '?' is returned. + * + ****************************************************************************/ + +int getopt(int argc, FAR char *const argv[], FAR const char *optstring) +{ + if (argv && optstring && argc > 1) + { + int noarg_ret = '?'; + char *optchar; + + /* The inital value of optind is 1. If getopt() is called again in the + * program, optind must be reset to some value <= 1. + */ + + if (optind < 1 || !g_binitialized) + { + optind = 1; /* Skip over the program name */ + g_optptr = NULL; /* Start at the beginning of the first argument */ + g_binitialized = true; /* Now we are initialized */ + } + + /* If the first character of opstring s ':', then ':' is in the event of + * a missing argument. Otherwise '?' is returned. + */ + + if (*optstring == ':') + { + noarg_ret = ':'; + optstring++; + } + + /* Are we resuming in the middle, or at the end of a string of arguments? + * g_optptr == NULL means that we are started at the beginning of argv[optind]; + * *g_optptr == \0 means that we are starting at the beginning of optind+1 + */ + + while (!g_optptr || !*g_optptr) + { + /* We need to start at the beginning of the next argv. Check if we need + * to increment optind + */ + + if (g_optptr) + { + /* Yes.. Increment it and check for the case where where we have + * processed everything in the argv[] array. + */ + + optind++; + } + + /* Check for the end of the argument list */ + + g_optptr = argv[optind]; + if (!g_optptr) + { + /* There are no more arguments, we are finished */ + + g_binitialized = false; + return ERROR; + } + + /* We are starting at the beginning of argv[optind]. In this case, the + * first character must be '-' + */ + + if (*g_optptr != '-') + { + /* The argument does not start with '-', we are finished */ + + g_binitialized = false; + return ERROR; + } + + /* Skip over the '-' */ + + g_optptr++; + } + + /* Special case handling of "-" and "-:" */ + + if (!*g_optptr) + { + optopt = '\0'; /* We'll fix up g_optptr the next time we are called */ + return '?'; + } + + /* Handle the case of "-:" */ + + if (*g_optptr == ':') + { + optopt = ':'; + g_optptr++; + return '?'; + } + + /* g_optptr now points at the next option and it is not something crazy. + * check if the option is in the list of valid options. + */ + + optchar = strchr(optstring, *g_optptr); + if (!optchar) + { + /* No this character is not in the list of valid options */ + + optopt = *g_optptr; + g_optptr++; + return '?'; + } + + /* Yes, the character is in the list of valid options. Does it have an + * required argument? + */ + + if (optchar[1] != ':') + { + /* No, no arguments. Just return the character that we found */ + + g_optptr++; + return *optchar; + } + + /* Yes, it has a required argument. Is the required argument + * immediately after the command in this same argument? + */ + + if (g_optptr[1] != '\0') + { + /* Yes, return a pointer into the current argument */ + + optarg = &g_optptr[1]; + optind++; + g_optptr = NULL; + return *optchar; + } + + /* No.. is the optional argument the next argument in argv[] ? */ + + if (argv[optind+1] && *argv[optind+1] != '-') + { + /* Yes.. return that */ + + optarg = argv[optind+1]; + optind += 2; + g_optptr = NULL; + return *optchar; + } + + /* No argument was supplied */ + + optarg = NULL; + optopt = *optchar; + optind++; + return noarg_ret; + } + + g_binitialized = false; + return ERROR; +} diff --git a/nuttx/libc/unistd/lib_getoptargp.c b/nuttx/libc/unistd/lib_getoptargp.c new file mode 100644 index 000000000..5610342ca --- /dev/null +++ b/nuttx/libc/unistd/lib_getoptargp.c @@ -0,0 +1,73 @@ +/**************************************************************************** + * libc/unistd/lib_getoptargp.c + * + * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Global Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: getoptargp + * + * Description: + * Returns a pointer to optarg. This function is only used for external + * modules that need to access the base, global variable, optarg. + * + ****************************************************************************/ + +FAR char **getoptargp(void) +{ + return &optarg; +} + diff --git a/nuttx/libc/unistd/lib_getoptindp.c b/nuttx/libc/unistd/lib_getoptindp.c new file mode 100644 index 000000000..94ea4d3fc --- /dev/null +++ b/nuttx/libc/unistd/lib_getoptindp.c @@ -0,0 +1,73 @@ +/**************************************************************************** + * libc/unistd/lib_getoptindp.c + * + * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Global Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: getoptindp + * + * Description: + * Returns a pointer to optind. This function is only used for external + * modules that need to access the base, global variable, optind. + * + ****************************************************************************/ + +int *getoptindp(void) +{ + return &optind; +} + diff --git a/nuttx/libc/unistd/lib_getoptoptp.c b/nuttx/libc/unistd/lib_getoptoptp.c new file mode 100644 index 000000000..cd99b172f --- /dev/null +++ b/nuttx/libc/unistd/lib_getoptoptp.c @@ -0,0 +1,73 @@ +/**************************************************************************** + * libc/unistd/lib_getoptoptp.c + * + * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Global Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: getoptoptp + * + * Description: + * Returns a pointer to optopt. This function is only used for external + * modules that need to access the base, global variable, optopt. + * + ****************************************************************************/ + +int *getoptoptp(void) +{ + return &optopt; +} + diff --git a/nuttx/libxx/Makefile b/nuttx/libxx/Makefile index 4122931ac..2ab146e9c 100644 --- a/nuttx/libxx/Makefile +++ b/nuttx/libxx/Makefile @@ -1,7 +1,7 @@ ############################################################################ # libxx/Makefile # -# Copyright (C) 2009 Gregory Nutt. All rights reserved. +# Copyright (C) 2009, 2012 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -35,20 +35,56 @@ -include $(TOPDIR)/Make.defs -ASRCS = -AOBJS = $(ASRCS:.S=$(OBJEXT)) -CSRCS = -COBJS = $(CSRCS:.c=$(OBJEXT)) -CXXSRCS = libxx_cxapurevirtual.cxx libxx_delete.cxx libxx_deletea.cxx \ - libxx_eabi_atexit.cxx libxx_new.cxx libxx_newa.cxx -CXXOBJS = $(CXXSRCS:.cxx=$(OBJEXT)) +# Sources -SRCS = $(ASRCS) $(CSRCS) $(CXXSRCS) -OBJS = $(AOBJS) $(COBJS) $(CXXOBJS) +ASRCS = +CSRCS = -BIN = liblibxx$(LIBEXT) +CXXSRCS = libxx_cxapurevirtual.cxx libxx_eabi_atexit.cxx libxx_cxa_atexit.cxx -all: $(BIN) +# Some of the libxx/ files are not need if uClibc++ is installed because +# uClibx++ replaces them + +ifneq ($(CONFIG_UCLIBCXX),y) +CXXSRCS += libxx_delete.cxx libxx_deletea.cxx libxx_new.cxx libxx_newa.cxx +CXXSRCS += libxx_stdthrow.cxx +else +ifneq ($(UCLIBCXX_EXCEPTION),y) +CXXSRCS += libxx_stdthrow.cxx +endif +endif + +# Paths + +DEPPATH = --dep-path . +VPATH = . + +# Include the uClibc++ Make.defs file if selected. If it is included, +# the uClibc++/Make.defs file will add its files to the source file list, +# add its DEPPATH info, and will add the appropriate paths to the VPATH +# variable +# +# Note that an error will occur if you select CONFIG_LIBXX_UCLIBCXX +# without installing the uClibc++ package. This is intentional to let +# you know about the configuration problem. Refer to misc/uClibc++/README.txt +# for more information + +ifeq ($(CONFIG_UCLIBCXX),y) +include uClibc++/Make.defs +endif + +# Object Files + +AOBJS = $(ASRCS:.S=$(OBJEXT)) +COBJS = $(CSRCS:.c=$(OBJEXT)) +CXXOBJS = $(CXXSRCS:.cxx=$(OBJEXT)) + +SRCS = $(ASRCS) $(CSRCS) $(CXXSRCS) +OBJS = $(AOBJS) $(COBJS) $(CXXOBJS) + +BIN = libcxx$(LIBEXT) + +all: $(BIN) $(AOBJS): %$(OBJEXT): %.S $(call ASSEMBLE, $<, $@) @@ -60,21 +96,20 @@ $(CXXOBJS): %$(OBJEXT): %.cxx $(call COMPILEXX, $<, $@) $(BIN): $(OBJS) - @( for obj in $(OBJS) ; do \ - $(call ARCHIVE, $@, $${obj}); \ - done ; ) + $(call ARCHIVE, $@, $(OBJS)) .depend: Makefile $(SRCS) - @$(MKDEP) $(CXX) -- $(CXXFLAGS) -- $(SRCS) >Make.dep - @touch $@ + $(Q) $(MKDEP) $(DEPPATH) "$(CXX)" -- $(CXXFLAGS) -- $(SRCS) >Make.dep + $(Q) touch $@ depend: .depend clean: - @rm -f $(BIN) *~ .*.swp + $(call DELFILE, $(BIN)) $(call CLEAN) distclean: clean - @rm -f Make.dep .depend + $(call DELFILE, Make.dep) + $(call DELFILE, .depend) -include Make.dep diff --git a/nuttx/libxx/README.txt b/nuttx/libxx/README.txt index 6cf066f08..7a1c51fa7 100644 --- a/nuttx/libxx/README.txt +++ b/nuttx/libxx/README.txt @@ -12,6 +12,10 @@ are recommended: - uClibc++ http://cxx.uclibc.org/ - uSTL http://ustl.sourceforge.net/ +There is a version of uClibc++ that is customized for NuttX that can +be found here: misc/uClibc++. See misc/uClibc++ for installation +instructions. + At present, only the following are supported here: - void *operator new(std::size_t nbytes); @@ -19,6 +23,7 @@ At present, only the following are supported here: - void operator delete[](void *ptr); - void __cxa_pure_virtual(void); - int __aeabi_atexit(void* object, void (*destroyer)(void*), void *dso_handle); + - int __cxa_atexit(__cxa_exitfunc_t func, FAR void *arg, FAR void *dso_handle); operator new ------------ diff --git a/nuttx/libxx/libxx_cxa_atexit.cxx b/nuttx/libxx/libxx_cxa_atexit.cxx new file mode 100644 index 000000000..cd31f94f6 --- /dev/null +++ b/nuttx/libxx/libxx_cxa_atexit.cxx @@ -0,0 +1,146 @@ +//*************************************************************************** +// libxx/libxx_eabi_atexit.cxx +// +// Copyright (C) 2012 Gregory Nutt. All rights reserved. +// Author: Gregory Nutt +// +// 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 + +#include +#include + +#include "libxx_internal.hxx" + +//*************************************************************************** +// Pre-processor Definitions +//*************************************************************************** + +//*************************************************************************** +// Private Types +//*************************************************************************** + +struct __cxa_atexit_s +{ + __cxa_exitfunc_t func; + FAR void *arg; +}; + +//*************************************************************************** +// Private Data +//*************************************************************************** + +extern "C" +{ + //************************************************************************* + // Public Data + //************************************************************************* + + FAR void *__dso_handle = NULL; + + //************************************************************************* + // Private Functions + //************************************************************************* + + //************************************************************************* + // Name: __cxa_callback + // + // Description: + // This is really just an "adaptor" function that matches the form of + // the __cxa_exitfunc_t to an onexitfunc_t using an allocated structure + // to marshall the call parameters. + // + //************************************************************************* + +#if CONFIG_SCHED_ONEXIT + static void __cxa_callback(int exitcode, FAR void *arg) + { + FAR struct __cxa_atexit_s *alloc = (FAR struct __cxa_atexit_s *)arg; + DEBUGASSERT(alloc && alloc->func); + + alloc->func(alloc->arg); + free(alloc); + } +#endif + + //************************************************************************* + // Public Functions + //************************************************************************* + + //************************************************************************* + // Name: __cxa_atexit + // + // Description: + // __cxa_atexit() registers a destructor function to be called by exit(). + // On a call to exit(), the registered functions should be called with + // the single argument 'arg'. Destructor functions shall always be + // called in the reverse order to their registration (i.e. the most + // recently registered function shall be called first), + // + // If shared libraries were supported, the callbacks should be invoked + // when the shared library is unloaded as well. + // + // Reference: + // Linux base + // + //************************************************************************* + + int __cxa_atexit(__cxa_exitfunc_t func, FAR void *arg, FAR void *dso_handle) + { +#if CONFIG_SCHED_ONEXIT + // Allocate memory to hold the marshaled __cxa_exitfunc_t call + // information. + + FAR struct __cxa_atexit_s *alloc = + (FAR struct __cxa_atexit_s *)malloc(sizeof(struct __cxa_atexit_s)); + + if (alloc) + { + // Register the function to be called when the task/thread exists. + + alloc->func = func; + alloc->arg = arg; + + return on_exit(__cxa_callback, alloc); + } + else +#endif + { + // What else can we do? + + return 0; + } + } +} diff --git a/nuttx/libxx/libxx_eabi_atexit.cxx b/nuttx/libxx/libxx_eabi_atexit.cxx index aa0ff6956..25f8306a8 100644 --- a/nuttx/libxx/libxx_eabi_atexit.cxx +++ b/nuttx/libxx/libxx_eabi_atexit.cxx @@ -40,26 +40,22 @@ #include #include +#include "libxx_internal.hxx" + //*************************************************************************** -// Definitions +// Pre-processor Definitions //*************************************************************************** //*************************************************************************** // Private Data //*************************************************************************** +//*************************************************************************** +// Public Functions +//*************************************************************************** + extern "C" { - //************************************************************************* - // Public Data - //************************************************************************* - - void *__dso_handle = NULL; - - //************************************************************************* - // Public Functions - //************************************************************************* - //************************************************************************* // Name: __aeabi_atexit // @@ -75,9 +71,8 @@ extern "C" // //************************************************************************* - int __aeabi_atexit(void* object, void (*destroyer)(void*), void *dso_handle) + int __aeabi_atexit(FAR void *object, __cxa_exitfunc_t func, FAR void *dso_handle) { - //return __cxa_atexit(destroyer, object, dso_handle); // 0 ? OK; non-0 ? failed } - return 0; + return __cxa_atexit(func, object, dso_handle); // 0 ? OK; non-0 ? failed } } diff --git a/nuttx/libxx/libxx_internal.hxx b/nuttx/libxx/libxx_internal.hxx new file mode 100644 index 000000000..fe84c763e --- /dev/null +++ b/nuttx/libxx/libxx_internal.hxx @@ -0,0 +1,67 @@ +//*************************************************************************** +// lib/libxx_internal.h +// +// Copyright (C) 2012 Gregory Nutt. All rights reserved. +// Author: Gregory Nutt +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in +// the documentation and/or other materials provided with the +// distribution. +// 3. Neither the name NuttX nor the names of its contributors may be +// used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +//*************************************************************************** + +#ifndef __LIBXX_LIBXX_INTERNAL_HXX +#define __LIBXX_LIBXX_INTERNAL_HXX + +//*************************************************************************** +// Included Files +//*************************************************************************** + +#include + +//*************************************************************************** +// Definitions +//*************************************************************************** + +//*************************************************************************** +// Public Types +//***************************************************************************/ + +typedef CODE void (*__cxa_exitfunc_t)(void *arg); + +//*************************************************************************** +// Public Variables +//*************************************************************************** + +extern "C" FAR void *__dso_handle; + +//*************************************************************************** +// Public Function Prototypes +//*************************************************************************** + +extern "C" int __cxa_atexit(__cxa_exitfunc_t func, void *arg, void *dso_handle); + +#endif // __LIBXX_LIBXX_INTERNAL_HXX diff --git a/nuttx/libxx/libxx_stdthrow.cxx b/nuttx/libxx/libxx_stdthrow.cxx new file mode 100644 index 000000000..588fae264 --- /dev/null +++ b/nuttx/libxx/libxx_stdthrow.cxx @@ -0,0 +1,74 @@ +//*************************************************************************** +// libxx/libxx_newa.cxx +// +// Copyright (C) 2012 Gregory Nutt. All rights reserved. +// Author: Petteri Aimonen ; +// +// 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 +#include + +//*************************************************************************** +// Definitions +//*************************************************************************** + +//*************************************************************************** +// Private Data +//*************************************************************************** + +//*************************************************************************** +// Public Functions +//*************************************************************************** + +namespace std +{ + void __throw_out_of_range(const char*) + { + dbg("C++: Vector .at() with argument out of range\n"); + abort(); + } + + void __throw_length_error(const char*) + { + dbg("C++: Vector resize to excessive length\n"); + abort(); + } + + void __throw_bad_alloc() + { + dbg("C++: Bad allocation\n"); + abort(); + } +} diff --git a/nuttx/mm/Makefile b/nuttx/mm/Makefile index 0ccf5a09a..da41f9f57 100644 --- a/nuttx/mm/Makefile +++ b/nuttx/mm/Makefile @@ -37,8 +37,8 @@ ASRCS = CSRCS = mm_initialize.c mm_sem.c mm_addfreechunk.c mm_size2ndx.c mm_shrinkchunk.c \ - mm_malloc.c mm_zalloc.c mm_calloc.c mm_realloc.c \ - mm_memalign.c mm_free.c mm_mallinfo.c + mm_malloc.c mm_zalloc.c mm_calloc.c mm_realloc.c \ + mm_memalign.c mm_free.c mm_mallinfo.c ifeq ($(CONFIG_GRAN),y) CSRCS += mm_graninit.c mm_granalloc.c mm_granfree.c mm_grancritical.c @@ -61,21 +61,20 @@ $(COBJS): %$(OBJEXT): %.c $(call COMPILE, $<, $@) $(BIN): $(OBJS) - @( for obj in $(OBJS) ; do \ - $(call ARCHIVE, $@, $${obj}); \ - done ; ) + $(call ARCHIVE, $@, $(OBJS)) .depend: Makefile $(SRCS) - @$(MKDEP) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep - @touch $@ + $(Q) $(MKDEP) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep + $(Q) touch $@ depend: .depend clean: - @rm -f $(BIN) *~ .*.swp + $(call DELFILE, $(BIN)) $(call CLEAN) distclean: clean - @rm -f Make.dep .depend + $(call DELFILE, Make.dep) + $(call DELFILE, .depend) -include Make.dep diff --git a/nuttx/mm/Makefile.test b/nuttx/mm/Makefile.test index 63cab910e..2ae9dcb88 100644 --- a/nuttx/mm/Makefile.test +++ b/nuttx/mm/Makefile.test @@ -33,12 +33,14 @@ # ############################################################################ -SRCS = mm_test.c mm_initialize.c mm_sem.c mm_addfreechunk.c mm_size2ndx.c mm_shrinkchunk.c \ +-include $(TOPDIR)/Make.defs + +SRCS = mm_test.c mm_initialize.c mm_sem.c mm_addfreechunk.c mm_size2ndx.c mm_shrinkchunk.c \ mm_malloc.c mm_zalloc.c mm_calloc.c mm_realloc.c \ mm_memalign.c mm_free.c mm_mallinfo.c -OBJS = $(SRCS:.c=.o1) +OBJS = $(SRCS:.c=.o1) -LIBS = -lpthread -lc +LIBS = -lpthread -lc CC = gcc LD = gcc @@ -48,17 +50,19 @@ WARNIGNS = -Wall -Wstrict-prototypes -Wshadow CFLAGS = -g $(DEFINES) LDFLAGS = -BIN = ../mm_test +BIN = ..$(DELIM)mm_test all: $(BIN) $(OBJS): %.o1: %.c @echo "Compiling $<" - $(CC) -c $(CFLAGS) $< -o $@ + $(Q) $(CC) -c $(CFLAGS) $< -o $@ $(BIN): $(OBJS) @echo "Linking {$(OBJS)} to produce $@" - $(LD) $(LDFLAGS) $(OBJS) $(LIBS) -o $@ + $(Q) $(LD) $(LDFLAGS) $(OBJS) $(LIBS) -o $@ clean: - @rm -f $(BIN) *.o1 *~ + $(call DELFILE, $(BIN)) + $(call DELFILE, *.o1) + $(call CLEAN) diff --git a/nuttx/mm/mm_initialize.c b/nuttx/mm/mm_initialize.c index 3a21d1759..a7f64cfaf 100644 --- a/nuttx/mm/mm_initialize.c +++ b/nuttx/mm/mm_initialize.c @@ -95,9 +95,9 @@ void mm_initialize(FAR void *heapstart, size_t heapsize) mlldbg("Heap: start=%p size=%u\n", heapstart, heapsize); - /* The following two lines have cause problems for some ZiLog compilers - * in the past. Life is easier if we just the suppress them for those - * tools. + /* The following two lines have cause problems for some older ZiLog + * compilers in the past (but not the more recent). Life is easier if we + * just the suppress them altogther for those tools. */ #ifndef __ZILOG__ diff --git a/nuttx/net/Makefile b/nuttx/net/Makefile index 506ef8213..74540b67d 100644 --- a/nuttx/net/Makefile +++ b/nuttx/net/Makefile @@ -100,24 +100,22 @@ $(COBJS): %$(OBJEXT): %.c $(call COMPILE, $<, $@) $(BIN): $(OBJS) - @( for obj in $(OBJS) ; do \ - $(call ARCHIVE, $@, $${obj}); \ - done ; ) + $(call ARCHIVE, $@, $(OBJS)) .depend: Makefile $(SRCS) ifeq ($(CONFIG_NET),y) - @$(MKDEP) --dep-path . --dep-path uip $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep + $(Q) $(MKDEP) --dep-path . --dep-path uip "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep endif - @touch $@ + $(Q) touch $@ depend: .depend clean: - @rm -f $(BIN) *~ .*.swp - @rm -f uip/*~ uip/.*.swp + $(call DELFILE, $(BIN)) $(call CLEAN) distclean: clean - @rm -f Make.dep .depend + $(call DELFILE, Make.dep) + $(call DELFILE, .depend) -include Make.dep diff --git a/nuttx/net/netdev_ioctl.c b/nuttx/net/netdev_ioctl.c index 4b5876efa..ea5c0e436 100644 --- a/nuttx/net/netdev_ioctl.c +++ b/nuttx/net/netdev_ioctl.c @@ -138,19 +138,47 @@ static void ioctl_setipaddr(FAR uip_ipaddr_t *outaddr, FAR const void *inaddr) * ****************************************************************************/ -static inline void ioctl_ifup(FAR struct uip_driver_s *dev) +static void ioctl_ifup(FAR struct uip_driver_s *dev) { + /* Make sure that the device supports the d_ifup() method */ + if (dev->d_ifup) { - dev->d_ifup(dev); + /* Is the interface already up? */ + + if ((dev->d_flags & IFF_RUNNING) == 0) + { + /* No, bring the interface up now */ + + if (dev->d_ifup(dev) == OK) + { + /* Mark the interface as up */ + + dev->d_flags |= IFF_RUNNING; + } + } } } -static inline void ioctl_ifdown(FAR struct uip_driver_s *dev) +static void ioctl_ifdown(FAR struct uip_driver_s *dev) { + /* Make sure that the device supports the d_ifdown() method */ + if (dev->d_ifdown) { - dev->d_ifdown(dev); + /* Is the interface already down? */ + + if ((dev->d_flags & IFF_RUNNING) != 0) + { + /* No, take the interface down now */ + + if (dev->d_ifdown(dev) == OK) + { + /* Mark the interface as down */ + + dev->d_flags &= ~IFF_RUNNING; + } + } } } @@ -194,63 +222,130 @@ static int netdev_ifrioctl(FAR struct socket *psock, int cmd, struct ifreq *req) switch (cmd) { - case SIOCGIFADDR: /* Get IP address */ - ioctl_getipaddr(&req->ifr_addr, &dev->d_ipaddr); + case SIOCGIFADDR: /* Get IP address */ + { + ioctl_getipaddr(&req->ifr_addr, &dev->d_ipaddr); + } break; - case SIOCSIFADDR: /* Set IP address */ - ioctl_ifdown(dev); - ioctl_setipaddr(&dev->d_ipaddr, &req->ifr_addr); - ioctl_ifup(dev); + case SIOCSIFADDR: /* Set IP address */ + { + ioctl_ifdown(dev); + ioctl_setipaddr(&dev->d_ipaddr, &req->ifr_addr); + ioctl_ifup(dev); + } break; case SIOCGIFDSTADDR: /* Get P-to-P address */ - ioctl_getipaddr(&req->ifr_dstaddr, &dev->d_draddr); + { + ioctl_getipaddr(&req->ifr_dstaddr, &dev->d_draddr); + } break; case SIOCSIFDSTADDR: /* Set P-to-P address */ - ioctl_setipaddr(&dev->d_draddr, &req->ifr_dstaddr); + { + ioctl_setipaddr(&dev->d_draddr, &req->ifr_dstaddr); + } break; case SIOCGIFNETMASK: /* Get network mask */ - ioctl_getipaddr(&req->ifr_addr, &dev->d_netmask); + { + ioctl_getipaddr(&req->ifr_addr, &dev->d_netmask); + } break; case SIOCSIFNETMASK: /* Set network mask */ - ioctl_setipaddr(&dev->d_netmask, &req->ifr_addr); + { + ioctl_setipaddr(&dev->d_netmask, &req->ifr_addr); + } break; case SIOCGIFMTU: /* Get MTU size */ - req->ifr_mtu = CONFIG_NET_BUFSIZE; + { + req->ifr_mtu = CONFIG_NET_BUFSIZE; + } + break; + + case SIOCSIFFLAGS: /* Sets the interface flags */ + { + /* Is this a request to bring the interface up? */ + + if (req->ifr_flags & IF_FLAG_IFUP) + { + /* Yes.. bring the interface up */ + + ioctl_ifup(dev); + } + + /* Is this a request to take the interface down? */ + + else if (req->ifr_flags & IF_FLAG_IFDOWN) + { + /* Yes.. take the interface down */ + + ioctl_ifdown(dev); + } + } + break; + + case SIOCGIFFLAGS: /* Gets the interface flags */ + { + req->ifr_flags = 0; + + /* Is the interface running? */ + + if (dev->d_flags & IFF_RUNNING) + { + /* Yes.. report interface up */ + + req->ifr_flags |= IF_FLAG_IFUP; + } + else + { + /* No.. report interface down */ + + req->ifr_flags |= IF_FLAG_IFDOWN; + } + } break; /* MAC address operations only make sense if Ethernet is supported */ #ifdef CONFIG_NET_ETHERNET case SIOCGIFHWADDR: /* Get hardware address */ - req->ifr_hwaddr.sa_family = AF_INETX; - memcpy(req->ifr_hwaddr.sa_data, dev->d_mac.ether_addr_octet, IFHWADDRLEN); + { + req->ifr_hwaddr.sa_family = AF_INETX; + memcpy(req->ifr_hwaddr.sa_data, dev->d_mac.ether_addr_octet, IFHWADDRLEN); + } break; case SIOCSIFHWADDR: /* Set hardware address -- will not take effect until ifup */ - req->ifr_hwaddr.sa_family = AF_INETX; - memcpy(dev->d_mac.ether_addr_octet, req->ifr_hwaddr.sa_data, IFHWADDRLEN); + { + req->ifr_hwaddr.sa_family = AF_INETX; + memcpy(dev->d_mac.ether_addr_octet, req->ifr_hwaddr.sa_data, IFHWADDRLEN); + } break; #endif case SIOCDIFADDR: /* Delete IP address */ - ioctl_ifdown(dev); - memset(&dev->d_ipaddr, 0, sizeof(uip_ipaddr_t)); + { + ioctl_ifdown(dev); + memset(&dev->d_ipaddr, 0, sizeof(uip_ipaddr_t)); + } break; case SIOCGIFCOUNT: /* Get number of devices */ - req->ifr_count = netdev_count(); - ret = -ENOSYS; + { + req->ifr_count = netdev_count(); + ret = -ENOSYS; + } break; - case SIOCGIFBRDADDR: /* Get broadcast IP address */ - case SIOCSIFBRDADDR: /* Set broadcast IP address */ - ret = -ENOSYS; + case SIOCGIFBRDADDR: /* Get broadcast IP address */ + case SIOCSIFBRDADDR: /* Set broadcast IP address */ + { + ret = -ENOSYS; + } break; #ifdef CONFIG_NET_ARPIOCTLS @@ -261,7 +356,9 @@ static int netdev_ifrioctl(FAR struct socket *psock, int cmd, struct ifreq *req) #endif default: - ret = -EINVAL; + { + ret = -EINVAL; + } break;; } diff --git a/nuttx/net/uip/uip_icmpping.c b/nuttx/net/uip/uip_icmpping.c index e3ebf7252..36f6e892a 100644 --- a/nuttx/net/uip/uip_icmpping.c +++ b/nuttx/net/uip/uip_icmpping.c @@ -123,6 +123,7 @@ static inline int ping_timeout(struct icmp_ping_s *pstate) { return TRUE; } + return FALSE; } @@ -365,6 +366,7 @@ int uip_ping(uip_ipaddr_t addr, uint16_t id, uint16_t seqno, uip_icmpcallbackfree(state.png_cb); } + uip_unlock(save); /* Return the negated error number in the event of a failure, or the diff --git a/nuttx/sched/Kconfig b/nuttx/sched/Kconfig index 3438ccf2c..bfaec3b5d 100644 --- a/nuttx/sched/Kconfig +++ b/nuttx/sched/Kconfig @@ -214,12 +214,17 @@ config SCHED_ATEXIT config SCHED_ATEXIT_MAX int "Max number of atexit() functions" default 1 - depends on SCHED_ATEXIT + depends on SCHED_ATEXIT && !SCHED_ONEXIT ---help--- By default if SCHED_ATEXIT is selected, only a single atexit() function is supported. That number can be increased by defined this setting to the number that you require. + If both SCHED_ONEXIT and SCHED_ATEXIT are selected, then atexit() is built + on top of the on_exit() implementation. In that case, SCHED_ONEXIT_MAX + determines the size of the combined number of atexit(0) and on_exit calls + and SCHED_ATEXIT_MAX is not used. + config SCHED_ONEXIT bool "Enable on_exit() API" default n @@ -235,6 +240,10 @@ config SCHED_ONEXIT_MAX is supported. That number can be increased by defined this setting to the number that you require. + If both SCHED_ONEXIT and SCHED_ATEXIT are selected, then atexit() is built + on top of the on_exit() implementation. In that case, SCHED_ONEXIT_MAX + determines the size of the combined number of atexit(0) and on_exit calls. + config USER_ENTRYPOINT string "Application entry point" default "user_start" diff --git a/nuttx/sched/Makefile b/nuttx/sched/Makefile index 1e0a55aea..82f74fc3c 100644 --- a/nuttx/sched/Makefile +++ b/nuttx/sched/Makefile @@ -94,7 +94,7 @@ SIGNAL_SRCS = sig_initialize.c \ sig_findaction.c sig_allocatependingsigaction.c \ sig_releasependingsigaction.c sig_unmaskpendingsignal.c \ sig_removependingsignal.c sig_releasependingsignal.c sig_lowest.c \ - sig_mqnotempty.c sig_cleanup.c sig_received.c sig_deliver.c + sig_mqnotempty.c sig_cleanup.c sig_received.c sig_deliver.c pause.c MQUEUE_SRCS = mq_open.c mq_close.c mq_unlink.c mq_send.c mq_timedsend.c\ mq_sndinternal.c mq_receive.c mq_timedreceive.c mq_rcvinternal.c \ @@ -188,6 +188,7 @@ OBJS = $(AOBJS) $(COBJS) BIN = libsched$(LIBEXT) all: $(BIN) +.PHONY: context depend clean distclean $(AOBJS): %$(OBJEXT): %.S $(call ASSEMBLE, $<, $@) @@ -196,21 +197,20 @@ $(COBJS): %$(OBJEXT): %.c $(call COMPILE, $<, $@) $(BIN): $(OBJS) - @( for obj in $(OBJS) ; do \ - $(call ARCHIVE, $@, $${obj}); \ - done ; ) + $(call ARCHIVE, $@, $(OBJS)) .depend: Makefile $(SRCS) - @$(MKDEP) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep - @touch $@ + $(Q) $(MKDEP) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep + $(Q) touch $@ depend: .depend clean: - @rm -f $(BIN) *~ .*.swp + $(call DELFILE, $(BIN)) $(call CLEAN) distclean: clean - @rm -f Make.dep .depend + $(call DELFILE, Make.dep) + $(call DELFILE, .depend) -include Make.dep diff --git a/nuttx/sched/atexit.c b/nuttx/sched/atexit.c index f7d81bec2..b0559b01b 100644 --- a/nuttx/sched/atexit.c +++ b/nuttx/sched/atexit.c @@ -96,8 +96,13 @@ * CONFIG_SCHED_ATEXIT_MAX defines a larger number. * 2. atexit functions are not inherited when a new task is * created. + * 3. If both SCHED_ONEXIT and SCHED_ATEXIT are selected, then atexit() + * is built on top of the on_exit() implementation. In that case, + * CONFIG_SCHED_ONEXIT_MAX determines the size of the combined + * number of atexit(0) and on_exit calls and SCHED_ATEXIT_MAX is + * not used. * - * Parameters: + * Input Parameters: * func - A pointer to the function to be called when the task exits. * * Return Value: @@ -107,7 +112,14 @@ int atexit(void (*func)(void)) { -#if defined(CONFIG_SCHED_ATEXIT_MAX) && CONFIG_SCHED_ATEXIT_MAX > 1 +#if defined(CONFIG_SCHED_ONEXIT) + /* atexit is equivalent to on_exit() with no argument (Assuming that the ABI + * can handle a callback function that recieves more parameters than it expects). + */ + + return on_exit(onexitfunc_t func, NULL); + +#elif defined(CONFIG_SCHED_ATEXIT_MAX) && CONFIG_SCHED_ATEXIT_MAX > 1 _TCB *tcb = (_TCB*)g_readytorun.head; int index; int ret = ERROR; diff --git a/nuttx/sched/mq_open.c b/nuttx/sched/mq_open.c index 5e1b9b137..89d80f072 100644 --- a/nuttx/sched/mq_open.c +++ b/nuttx/sched/mq_open.c @@ -113,7 +113,6 @@ mqd_t mq_open(const char *mq_name, int oflags, ...) FAR msgq_t *msgq; mqd_t mqdes = NULL; va_list arg; /* Points to each un-named argument */ - mode_t mode; /* MQ creation mode parameter (ignored) */ struct mq_attr *attr; /* MQ creation attributes */ int namelen; /* Length of MQ name */ @@ -170,7 +169,7 @@ mqd_t mq_open(const char *mq_name, int oflags, ...) */ va_start(arg, oflags); - mode = va_arg(arg, mode_t); + (void)va_arg(arg, mode_t); /* MQ creation mode parameter (ignored) */ attr = va_arg(arg, struct mq_attr*); /* Initialize the new named message queue */ diff --git a/nuttx/sched/on_exit.c b/nuttx/sched/on_exit.c index 5b8be5cd1..19a4f9196 100644 --- a/nuttx/sched/on_exit.c +++ b/nuttx/sched/on_exit.c @@ -117,7 +117,7 @@ int on_exit(CODE void (*func)(int, FAR void *), FAR void *arg) #if defined(CONFIG_SCHED_ONEXIT_MAX) && CONFIG_SCHED_ONEXIT_MAX > 1 _TCB *tcb = (_TCB*)g_readytorun.head; int index; - int ret = ERROR; + int ret = ENOSPC; /* The following must be atomic */ @@ -131,7 +131,6 @@ int on_exit(CODE void (*func)(int, FAR void *), FAR void *arg) * indices. */ - available = -1; for (index = 0; index < CONFIG_SCHED_ONEXIT_MAX; index++) { if (!tcb->onexitfunc[index]) @@ -149,7 +148,7 @@ int on_exit(CODE void (*func)(int, FAR void *), FAR void *arg) return ret; #else _TCB *tcb = (_TCB*)g_readytorun.head; - int ret = ERROR; + int ret = ENOSPC; /* The following must be atomic */ diff --git a/nuttx/sched/pause.c b/nuttx/sched/pause.c new file mode 100644 index 000000000..607c4c775 --- /dev/null +++ b/nuttx/sched/pause.c @@ -0,0 +1,110 @@ +/**************************************************************************** + * sched/pause.c + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include + +/**************************************************************************** + * Preprocessor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Definitions + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: pause + * + * Description: + * The pause() function will suspend the calling thread until delivery of a + * non-blocked signal. + * + * Input Parameters: + * None + * + * Returned Value: + * Since pause() suspends thread execution indefinitely unless interrupted + * a signal, there is no successful completion return value. A value of -1 + * will always be returned and errno set to indicate the error (EINTR). + * + * POSIX compatibility: + * In the POSIX description of this function is the pause() function will + * suspend the calling thread until delivery of a signal whose action is + * either to execute a signal-catching function or to terminate the + * process. This implementation only waits for any non-blocked signal + * to be received. + * + ****************************************************************************/ + +int pause(void) +{ + sigset_t set; + struct siginfo value; + + /* Set up for the sleep. Using the empty set means that we are not + * waiting for any particular signal. However, any unmasked signal + * can still awaken sigtimedwait(). + */ + + (void)sigemptyset(&set); + + /* sigtwaitinfo() cannot succeed. It should always return error EINTR + * meaning that some unblocked signal was caught. + */ + + return sigwaitinfo(&set, &value); +} diff --git a/nuttx/sched/sched_getscheduler.c b/nuttx/sched/sched_getscheduler.c index 5771e86ff..0d996ca27 100644 --- a/nuttx/sched/sched_getscheduler.c +++ b/nuttx/sched/sched_getscheduler.c @@ -129,3 +129,4 @@ int sched_getscheduler(pid_t pid) return SCHED_FIFO; } } + diff --git a/nuttx/sched/sem_open.c b/nuttx/sched/sem_open.c index 817c36b49..b2b76fe38 100644 --- a/nuttx/sched/sem_open.c +++ b/nuttx/sched/sem_open.c @@ -120,7 +120,6 @@ FAR sem_t *sem_open (FAR const char *name, int oflag, ...) FAR nsem_t *psem; FAR sem_t *sem = (FAR sem_t*)ERROR; va_list arg; /* Points to each un-named argument */ - mode_t mode; /* Creation mode parameter (ignored) */ unsigned int value; /* Semaphore value parameter */ /* Make sure that a non-NULL name is supplied */ @@ -165,7 +164,7 @@ FAR sem_t *sem_open (FAR const char *name, int oflag, ...) */ va_start(arg, oflag); - mode = va_arg(arg, mode_t); + (void)va_arg(arg, mode_t); /* Creation mode parameter (ignored) */ value = va_arg(arg, unsigned int); /* Verify that a legal initial value was selected. */ diff --git a/nuttx/sched/sleep.c b/nuttx/sched/sleep.c index 03884a5b6..9b3b6d57f 100644 --- a/nuttx/sched/sleep.c +++ b/nuttx/sched/sleep.c @@ -141,7 +141,7 @@ unsigned int sleep(unsigned int seconds) if (seconds) { /* Set up for the sleep. Using the empty set means that we are not - * waiting for any particualar signal. However, any unmasked signal + * waiting for any particular signal. However, any unmasked signal * can still awaken sigtimedwait(). */ diff --git a/nuttx/sched/task_exithook.c b/nuttx/sched/task_exithook.c index 004d09e20..3bde8fb7a 100644 --- a/nuttx/sched/task_exithook.c +++ b/nuttx/sched/task_exithook.c @@ -81,8 +81,8 @@ * Call any registerd atexit function(s) * ****************************************************************************/ - -#ifdef CONFIG_SCHED_ATEXIT + +#if defined(CONFIG_SCHED_ATEXIT) && !defined(CONFIG_SCHED_ONEXIT) static inline void task_atexit(FAR _TCB *tcb) { #if defined(CONFIG_SCHED_ATEXIT_MAX) && CONFIG_SCHED_ATEXIT_MAX > 1 diff --git a/nuttx/sched/usleep.c b/nuttx/sched/usleep.c index 21996d788..893a420f4 100644 --- a/nuttx/sched/usleep.c +++ b/nuttx/sched/usleep.c @@ -137,7 +137,7 @@ int usleep(useconds_t usec) if (usec) { /* Set up for the sleep. Using the empty set means that we are not - * waiting for any particualar signal. However, any unmasked signal + * waiting for any particular signal. However, any unmasked signal * can still awaken sigtimedwait(). */ diff --git a/nuttx/tools/Makefile.export b/nuttx/tools/Makefile.export index e3629a480..002cb526b 100644 --- a/nuttx/tools/Makefile.export +++ b/nuttx/tools/Makefile.export @@ -67,7 +67,7 @@ endif @echo "ARCHCFLAGS=\"$(ARCHCFLAGS) $(ARCHCPUFLAGS)\"" >> $(EXPORTDIR)/makeinfo.sh @echo "ARCHCXXFLAGS=\"$(ARCHCXXFLAGS) $(ARCHCPUFLAGS)\"" >> $(EXPORTDIR)/makeinfo.sh @echo "CROSSDEV=\"$(CROSSDEV)\"" >> $(EXPORTDIR)/makeinfo.sh - @chmod 755 $(EXPORTDIR)/makeinfo.sh + $(Q) chmod 755 $(EXPORTDIR)/makeinfo.sh clean: - @rm -f $(EXPORTDIR)/makeinfo.sh + $(Q) rm -f $(EXPORTDIR)/makeinfo.sh diff --git a/nuttx/tools/configure.sh b/nuttx/tools/configure.sh index 3b68fe3f6..ffa997178 100755 --- a/nuttx/tools/configure.sh +++ b/nuttx/tools/configure.sh @@ -100,32 +100,54 @@ if [ ! -d "${configpath}" ]; then exit 3 fi -if [ ! -r "${configpath}/Make.defs" ]; then - echo "File \"${configpath}/Make.defs\" does not exist" +src_makedefs="${configpath}/Make.defs" +dest_makedefs="${TOPDIR}/Make.defs" + +if [ ! -r "${src_makedefs}" ]; then + echo "File \"${src_makedefs}\" does not exist" exit 4 fi -if [ ! -r "${configpath}/setenv.sh" ]; then - echo "File \"${configpath}/setenv.sh\" does not exist" - exit 5 +src_setenv="${configpath}/setenv.sh" +unset have_setenv + +if [ -r "${src_setenv}" ]; then + dest_setenv=${TOPDIR}/setenv.sh + have_setenv=y +else + src_setenv="${configpath}/setenv.bat" + if [ -r "${src_setenv}" ]; then + dest_setenv=${TOPDIR}/setenv.bat + have_setenv=y + else + unset src_setenv + fi fi -if [ ! -r "${configpath}/defconfig" ]; then - echo "File \"${configpath}/defconfig\" does not exist" +src_config="${configpath}/defconfig" +tmp_config="${TOPDIR}/.configX" +dest_config="${TOPDIR}/.config" + +if [ ! -r "${src_config}" ]; then + echo "File \"${src_config}\" does not exist" exit 6 fi # Extract values needed from the defconfig file. We need: # (1) The CONFIG_NUTTX_NEWCONFIG setting to know if this is a "new" style -# configuration, and -# (2) The CONFIG_APPS_DIR to see if there is a configured location for the -# application directory. +# configuration, +# (2) The CONFIG_WINDOWS_NATIVE setting to know it this is target for a +# native Windows (meaning that we want setenv.bat vs setenv.sh and we need +# to use backslashes in the CONFIG_APPS_DIR setting). +# (3) The CONFIG_APPS_DIR setting to see if there is a configured location for the +# application directory. This can be overridden from the command line. -newconfig=`grep CONFIG_NUTTX_NEWCONFIG= "${configpath}/defconfig" | cut -d'=' -f2` +newconfig=`grep CONFIG_NUTTX_NEWCONFIG= "${src_config}" | cut -d'=' -f2` +winnative=`grep CONFIG_WINDOWS_NATIVE= "${src_config}" | cut -d'=' -f2` defappdir=y if [ -z "${appdir}" ]; then - quoted=`grep "^CONFIG_APPS_DIR=" "${configpath}/defconfig" | cut -d'=' -f2` + quoted=`grep "^CONFIG_APPS_DIR=" "${src_config}" | cut -d'=' -f2` if [ ! -z "${appdir}" ]; then appdir=`echo ${quoted} | sed -e "s/\"//g"` defappdir=n @@ -157,34 +179,45 @@ if [ -z "${appdir}" ]; then fi fi +# For checking the apps dir path, we need a POSIX version of the relative path. + +posappdir=`echo "${appdir}" | sed -e 's/\\\\/\\//g'` +winappdir=`echo "${appdir}" | sed -e 's/\\//\\\\/g'` + # If appsdir was provided (or discovered) then make sure that the apps/ # directory exists -if [ ! -z "${appdir}" -a ! -d "${TOPDIR}/${appdir}" ]; then - echo "Directory \"${TOPDIR}/${appdir}\" does not exist" +if [ ! -z "${appdir}" -a ! -d "${TOPDIR}/${posappdir}" ]; then + echo "Directory \"${TOPDIR}/${posappdir}\" does not exist" exit 7 fi # Okay... Everything looks good. Setup the configuration -install -C "${configpath}/Make.defs" "${TOPDIR}/." || \ - { echo "Failed to copy ${configpath}/Make.defs" ; exit 7 ; } -install -C "${configpath}/setenv.sh" "${TOPDIR}/." || \ - { echo "Failed to copy ${configpath}/setenv.sh" ; exit 8 ; } -chmod 755 "${TOPDIR}/setenv.sh" -install -C "${configpath}/defconfig" "${TOPDIR}/.configX" || \ - { echo "Failed to copy ${configpath}/defconfig" ; exit 9 ; } +install "${src_makedefs}" "${dest_makedefs}" || \ + { echo "Failed to copy \"${src_makedefs}\"" ; exit 7 ; } +if [ "X${have_setenv}" = "Xy" ]; then + install "${src_setenv}" "${dest_setenv}" || \ + { echo "Failed to copy ${src_setenv}" ; exit 8 ; } + chmod 755 "${dest_setenv}" +fi +install "${src_config}" "${tmp_config}" || \ + { echo "Failed to copy \"${src_config}\"" ; exit 9 ; } # If we did not use the CONFIG_APPS_DIR that was in the defconfig config file, # then append the correct application information to the tail of the .config # file if [ "X${defappdir}" = "Xy" ]; then - sed -i -e "/^CONFIG_APPS_DIR/d" "${TOPDIR}/.configX" - echo "" >> "${TOPDIR}/.configX" - echo "# Application configuration" >> "${TOPDIR}/.configX" - echo "" >> "${TOPDIR}/.configX" - echo "CONFIG_APPS_DIR=\"$appdir\"" >> "${TOPDIR}/.configX" + sed -i -e "/^CONFIG_APPS_DIR/d" "${tmp_config}" + echo "" >> "${tmp_config}" + echo "# Application configuration" >> "${tmp_config}" + echo "" >> "${tmp_config}" + if [ "X${winnative}" = "Xy" ]; then + echo "CONFIG_APPS_DIR=\"$winappdir\"" >> "${tmp_config}" + else + echo "CONFIG_APPS_DIR=\"$posappdir\"" >> "${tmp_config}" + fi fi # Copy appconfig file. The appconfig file will be copied to ${appdir}/.config @@ -195,7 +228,7 @@ if [ ! -z "${appdir}" -a "X${newconfig}" != "Xy" ]; then if [ ! -r "${configpath}/appconfig" ]; then echo "NOTE: No readable appconfig file found in ${configpath}" else - install -C "${configpath}/appconfig" "${TOPDIR}/${appdir}/.config" || \ + install "${configpath}/appconfig" "${TOPDIR}/${posappdir}/.config" || \ { echo "Failed to copy ${configpath}/appconfig" ; exit 10 ; } fi fi @@ -203,6 +236,5 @@ fi # install the final .configX only if it differs from any existing # .config file. -install -C "${TOPDIR}/.configX" "${TOPDIR}/.config" -rm -f "${TOPDIR}/.configX" - +install "${tmp_config}" "${dest_config}" +rm -f "${tmp_config}" diff --git a/nuttx/tools/define.bat b/nuttx/tools/define.bat new file mode 100644 index 000000000..13d29ac31 --- /dev/null +++ b/nuttx/tools/define.bat @@ -0,0 +1,178 @@ +@echo off + +rem tools/define.bat +rem +rem Copyright (C) 2012 Gregory Nutt. All rights reserved. +rem Author: Gregory Nutt +rem +rem Redistribution and use in source and binary forms, with or without +rem modification, are permitted provided that the following conditions +rem are met: +rem +rem 1. Redistributions of source code must retain the above copyright +rem notice, this list of conditions and the following disclaimer. +rem 2. Redistributions in binary form must reproduce the above copyright +rem notice, this list of conditions and the following disclaimer in +rem the documentation and/or other materials provided with the +rem distribution. +rem 3. Neither the name NuttX nor the names of its contributors may be +rem used to endorse or promote products derived from this software +rem without specific prior written permission. +rem +rem THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +rem "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +rem LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +rem FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +rem COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +rem INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +rem BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +rem OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +rem AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +rem LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +rem ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +rem POSSIBILITY OF SUCH DAMAGE. + +rem Handle command line options +rem [-h] [-val ] [ [-val ] [ [-val ] ...]] +rem [-w] [-d] ignored for compatibility with define.sh + +set progname=%0 + +:ArgLoop +if "%1"=="-d" goto :NextArg +if "%1"=="-w" goto :NextArg +if "%1"=="-h" goto :ShowUsage + +goto :CheckCompilerPath + +:NextArg +shift +goto :ArgLoop + +:CheckCompilerPath + +if "%1"=="" ( + echo Missing compiler path + goto :ShowUsage +) + +set ccpath=%1 +shift + +set compiler= +for /F %%i in ("%ccpath%") do set compiler=%%~ni + +if "%1"=="" ( + echo Missing definition list + goto :ShowUsage +) + +rem Check for some well known, non-GCC Windows native tools that require +rem a special output format as well as special paths + +:GetFormat +set fmt=std +if "%compiler%"=="ez8cc" goto :SetZdsFormt +if "%compiler%"=="zneocc" goto :SetZdsFormt +if "%compiler%"=="ez80cc" goto :SetZdsFormt +goto :ProcessDefinitions + +:SetZdsFormt +set fmt=zds + +rem Now process each directory in the directory list + +:ProcessDefinitions +set response= + +:DefinitionLoop +if "%1"=="" goto :Done + +set varname=%1 +shift + +rem Handle the output depending on if there is a value for the variable or not + +if "%1"=="-val" goto :GetValue + +rem Handle the output using the selected format + +:NoValue +if "%fmt%"=="zds" goto :NoValueZDS + +:NoValueStandard +rem Treat the first definition differently + +if "%response%"=="" ( + set response=-D%varname% + goto :DefinitionLoop +) + +set response=%response% -D%varname% +goto :DefinitionLoop + +:NoValueZDS +rem Treat the first definition differently + +if "%response%"=="" ( + set response=-define:%varname% + goto :DefinitionLoop +) + +set response=%response% -define:%varname% +goto :DefinitionLoop + +rem Get value following the variable name + +:GetValue +shift +set varvalue=%1 +shift + +rem Handle the output using the selected format + +if "%fmt%"=="zds" goto :ValueZDS + +:ValueStandard +rem Treat the first definition differently + +if "%response%"=="" ( + set response=-D%varname%=%varvalue% + goto :DefinitionLoop +) + +set response=%response% -D%varname%=%varvalue% +goto :DefinitionLoop + +:ValueZds +rem Treat the first definition differently + +if "%response%"=="" ( + set response=-define:%varname%=%varvalue% + goto :DefinitionLoop +) + +set response=%response% -define:%varname%=%varvalue% +goto :DefinitionLoop + +:Done +echo %response% +goto :End + +:ShowUsage +echo %progname% is a tool for flexible generation of command line pre-processor +echo definitions arguments for a variety of diffent ccpaths in a variety of +echo compilation environments" +echo USAGE:%progname% [-h] ^ [-val ^<^val1^>] [^ [-val ^] [^ [-val ^] ...]] +echo Where:" +echo ^ +echo The full path to your ccpath +echo ^ ^ ^ ... +echo A list of pre-preprocesser variable names to be defined. +echo [-val ^] [-val ^] [-val ^] ... +echo optional values to be assigned to each pre-processor variable. +echo If not supplied, the variable will be defined with no explicit value. +echo -h +echo Show this text and exit + +:End diff --git a/nuttx/tools/define.sh b/nuttx/tools/define.sh index c53cb92a8..dc982cc64 100755 --- a/nuttx/tools/define.sh +++ b/nuttx/tools/define.sh @@ -1,7 +1,7 @@ #!/bin/bash # tools/define.sh # -# Copyright (C) 2011 Gregory Nutt. All rights reserved. +# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -38,7 +38,7 @@ progname=$0 wintool=n -usage="USAGE: $progname [-w] [-d] [-l] [-h] [=val1] [[=val2] [[=val3] ...]]" +usage="USAGE: $progname [-w] [-d] [-h] [=val1] [[=val2] [[=val3] ...]]" advice="Try '$progname -h' for more information" while [ ! -z "$1" ]; do @@ -60,7 +60,7 @@ while [ ! -z "$1" ]; do echo " " echo " The full path to your compiler" echo " [ ..." - echo " A list of pre-preprocesser variable names to be defind." + echo " A list of pre-preprocesser variable names to be defined." echo " [=val1] [=val2] [=val3]" echo " optional values to be assigned to each pre-processor variable." echo " If not supplied, the variable will be defined with no explicit value." @@ -164,7 +164,7 @@ else fmt=std fi -# Now process each directory in the directory list +# Now process each definition in the definition list unset response for vardef in $varlist; do diff --git a/nuttx/tools/incdir.sh b/nuttx/tools/incdir.sh index eaae082b9..145bfe9bb 100755 --- a/nuttx/tools/incdir.sh +++ b/nuttx/tools/incdir.sh @@ -70,6 +70,9 @@ while [ ! -z "$1" ]; do echo " header file paths." echo " -d" echo " Enable script debug" + echo " -h" + echo " Shows this help text and exits." + exit 0 ;; * ) break; diff --git a/nuttx/tools/mkconfig.c b/nuttx/tools/mkconfig.c index 2d2fff5c5..3e55f5097 100644 --- a/nuttx/tools/mkconfig.c +++ b/nuttx/tools/mkconfig.c @@ -116,7 +116,7 @@ int main(int argc, char **argv, char **envp) printf(" * configured (at present, NXFLAT is the only supported binary.\n"); printf(" * format).\n"); printf(" */\n\n"); - printf("#if !defined(CONFIG_NXFLAT)\n"); + printf("#if !defined(CONFIG_NXFLAT) && !defined(CONFIG_ELF)\n"); printf("# undef CONFIG_BINFMT_DISABLE\n"); printf("# define CONFIG_BINFMT_DISABLE 1\n"); printf("#endif\n\n"); diff --git a/nuttx/tools/mkdeps.bat b/nuttx/tools/mkdeps.bat new file mode 100644 index 000000000..23aab0b71 --- /dev/null +++ b/nuttx/tools/mkdeps.bat @@ -0,0 +1,173 @@ +@echo off + +rem tools/mkdeps.sh +rem +rem Copyright (C) 2012 Gregory Nutt. All rights reserved. +rem Author: Gregory Nutt +rem +rem Redistribution and use in source and binary forms, with or without +rem modification, are permitted provided that the following conditions +rem are met: +rem +rem 1. Redistributions of source code must retain the above copyright +rem notice, this list of conditions and the following disclaimer. +rem 2. Redistributions in binary form must reproduce the above copyright +rem notice, this list of conditions and the following disclaimer in +rem the documentation and/or other materials provided with the +rem distribution. +rem 3. Neither the name NuttX nor the names of its contributors may be +rem used to endorse or promote products derived from this software +rem without specific prior written permission. +rem +rem THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +rem "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +rem LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +rem FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +rem COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +rem INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +rem BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +rem OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +rem AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +rem LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +rem ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +rem POSSIBILITY OF SUCH DAMAGE. + +rem Accumulate CFLAGS up to "--" + +set cc= +set cflags= +set altpath= +set files= +set args= +set debug=n + +:Loop +if "%1"=="" goto Continue + +if "%1"=="--" ( + set cc=%cflags% + set cflags=%args% + set args= + goto NextParm +) + +if "%1"=="--dep-path" ( + if "%args%"=="" ( + set altpath=%altpath% %2 + ) else ( + set args=%args% %2 + ) + shift + goto NextParm +) + +if "%1"=="--dep-debug" ( +rem @echo on + set debug=y + goto NextParm +) + +if "%1"=="--help" goto Usage + +if "%args%"=="" ( + set args=%1 +) else ( + set args=%args% %1 +) + +:NextParm +shift +goto Loop +:Continue + +set files=%args% + +if "%debug%"=="y" ( + echo cc=%cc% + echo cflags=%cflags% + echo files=%files% + echo altpath=%altpath% +) + +rem Now check if we have everything + +if "%cc%"=="" ( + echo ERROR: No compiler specified + goto Usage +) + +if "%files%"=="" ( + rem Don't report an error -- this happens normally in some configurations + echo # No files specified for dependency generataion + goto End +) + +rem Then get the dependencies for each file + +if "%altpath%"=="" goto NoPaths +for %%G in (%files%) do ( + set fullpath= + set file=%%G + call :Checkpaths + if "%debug%"=="y" echo %file%: fullpath=%fullpath% + if "%fullpath%"=="" goto :NoFile + if "%debug%"=="y" echo CMD: %cc% -M %cflags% %fullpath% + %cc% -M %cflags% %fullpath% || goto DepFail +) +goto :End + +:NoPaths +for %%G in (%files%) do ( + set fullpath= + set file=%%G + call :CheckFile %%G +) +goto :End + +:CheckFile +if "%debug%"=="y" echo Checkfile: Checking %file% +if not exist %file% goto :NoFile +set fullpath=%file% + if "%debug%"=="y" echo CMD: %cc% -M %cflags% %fullpath% +%cc% -M %cflags% %fullpath% || goto DepFail +goto :EOF + +:CheckPaths +for %%H in (%altpath%) do ( + set tmppath=%%H\%file% + if "%debug%"=="y" echo Checkfile: Checking %tmppath% + if exist %tmppath% ( + set fullpath=%tmppath% + goto :EOF + ) +) +goto :EOF + +:NoFile +echo ERROR: No readable file at %file% +goto Usage + +:DepFail +echo ERROR: Failed to created dependencies for %file% + +:Usage +echo Usage: mkdeps [OPTIONS] CC -- CFLAGS -- file [file [file...]] +echo Where: +echo CC +echo A variable number of arguments that define how to execute the compiler +echo CFLAGS +echo The compiler compilation flags +echo file +echo One or more C files whose dependencies will be checked. Each file is expected +echo to reside in the current directory unless --dep-path is provided on the command line +echo And [OPTIONS] include: +echo --dep-debug +echo Enable script debug +echo --dep-path ^ +echo Do not look in the current directory for the file. Instead, look in to see +echo if the file resides there. --dep-path may be used multiple times to specify +echo multiple alternative location +echo --help +echo Shows this message and exits + +:End diff --git a/nuttx/tools/mkdeps.c b/nuttx/tools/mkdeps.c new file mode 100644 index 000000000..64d81cbd7 --- /dev/null +++ b/nuttx/tools/mkdeps.c @@ -0,0 +1,721 @@ +/**************************************************************************** + * tools/mkdeps.c + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include +#include +#include +#include +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define MAX_BUFFER (4096) + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +enum slashmode_e +{ + MODE_FSLASH = 0, + MODE_BSLASH = 1, + MODE_DBLBACK = 2 +}; + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static char *g_cc = NULL; +static char *g_cflags = NULL; +static char *g_files = NULL; +static char *g_altpath = NULL; +static int g_debug = 0; +static bool g_winnative = false; +#ifdef HAVE_WINPATH +static bool g_winpath = false; +static char *g_topdir = NULL; +#endif + +static char g_command[MAX_BUFFER]; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + + /* MinGW does not seem to provide strtok_r */ + +#ifndef HAVE_STRTOK_R +static char *MY_strtok_r(char *str, const char *delim, char **saveptr) +{ + char *pbegin; + char *pend = NULL; + + /* Decide if we are starting a new string or continuing from + * the point we left off. + */ + + if (str) + { + pbegin = str; + } + else if (saveptr && *saveptr) + { + pbegin = *saveptr; + } + else + { + return NULL; + } + + /* Find the beginning of the next token */ + + for (; + *pbegin && strchr(delim, *pbegin) != NULL; + pbegin++); + + /* If we are at the end of the string with nothing + * but delimiters found, then return NULL. + */ + + if (!*pbegin) + { + return NULL; + } + + /* Find the end of the token */ + + for (pend = pbegin + 1; + *pend && strchr(delim, *pend) == NULL; + pend++); + + /* pend either points to the end of the string or to + * the first delimiter after the string. + */ + + if (*pend) + { + /* Turn the delimiter into a null terminator */ + + *pend++ = '\0'; + } + + /* Save the pointer where we left off and return the + * beginning of the token. + */ + + if (saveptr) + { + *saveptr = pend; + } + return pbegin; +} + +#define strtok_r MY_strtok_r +#endif + +static void append(char **base, char *str) +{ + char *oldbase; + char *newbase; + int alloclen; + + oldbase = *base; + if (!oldbase) + { + newbase = strdup(str); + if (!newbase) + { + fprintf(stderr, "ERROR: Failed to strdup %s\n", str); + exit(EXIT_FAILURE); + } + } + else + { + alloclen = strlen(oldbase) + strlen(str) + 2; + newbase = (char *)malloc(alloclen); + if (!newbase) + { + fprintf(stderr, "ERROR: Failed to allocate %d bytes\n", alloclen); + exit(EXIT_FAILURE); + } + + snprintf(newbase, alloclen, "%s %s\n", oldbase, str); + free(oldbase); + } + + *base = newbase; +} + +static void show_usage(const char *progname, const char *msg, int exitcode) +{ + if (msg) + { + fprintf(stderr, "\n"); + fprintf(stderr, "%s:\n", msg); + } + + fprintf(stderr, "\n"); + fprintf(stderr, "%s [OPTIONS] CC -- CFLAGS -- file [file [file...]]\n", + progname); + fprintf(stderr, "\n"); + fprintf(stderr, "Where:\n"); + fprintf(stderr, " CC\n"); + fprintf(stderr, " A variable number of arguments that define how to execute the compiler\n"); + fprintf(stderr, " CFLAGS\n"); + fprintf(stderr, " The compiler compilation flags\n"); + fprintf(stderr, " file\n"); + fprintf(stderr, " One or more C files whose dependencies will be checked. Each file is expected\n"); + fprintf(stderr, " to reside in the current directory unless --dep-path is provided on the command line\n"); + fprintf(stderr, "\n"); + fprintf(stderr, "And [OPTIONS] include:\n"); + fprintf(stderr, " --dep-debug\n"); + fprintf(stderr, " Enable script debug\n"); + fprintf(stderr, " --dep-path \n"); + fprintf(stderr, " Do not look in the current directory for the file. Instead, look in to see\n"); + fprintf(stderr, " if the file resides there. --dep-path may be used multiple times to specify\n"); + fprintf(stderr, " multiple alternative location\n"); + fprintf(stderr, " --winnative\n"); + fprintf(stderr, " By default, a POSIX-style environment is assumed (e.g., Linux, Cygwin, etc.) This option is\n"); + fprintf(stderr, " inform the tool that is working in a pure Windows native environment.\n"); +#ifdef HAVE_WINPATH + fprintf(stderr, " --winpaths \n"); + fprintf(stderr, " This option is useful when using a Windows native toolchain in a POSIX environment (such\n"); + fprintf(stderr, " such as Cygwin). In this case, will CC generates dependency lists using Windows paths\n"); + fprintf(stderr, " (e.g., C:\\blablah\\blabla). This switch instructs the script to use 'cygpath' to convert\n"); + fprintf(stderr, " the Windows paths to Cygwin POSIXE paths.\n"); +#endif + fprintf(stderr, " --help\n"); + fprintf(stderr, " Shows this message and exits\n"); + exit(exitcode); +} + +static void parse_args(int argc, char **argv) +{ + char *args = NULL; + int argidx; + + /* Accumulate CFLAGS up to "--" */ + + for (argidx = 1; argidx < argc; argidx++) + { + if (strcmp(argv[argidx], "--") == 0) + { + g_cc = g_cflags; + g_cflags = args; + args = NULL; + } + else if (strcmp(argv[argidx], "--dep-debug") == 0) + { + g_debug++; + } + else if (strcmp(argv[argidx], "--dep-path") == 0) + { + argidx++; + if (argidx >= argc) + { + show_usage(argv[0], "ERROR: Missing argument to --dep-path", EXIT_FAILURE); + } + + if (args) + { + append(&args, argv[argidx]); + } + else + { + append(&g_altpath, argv[argidx]); + } + } + else if (strcmp(argv[argidx], "--winnative") == 0) + { + g_winnative = true; + } +#ifdef HAVE_WINPATH + else if (strcmp(argv[argidx], "--winpath") == 0) + { + g_winpath = true; + if (g_topdir) + { + free(g_topdir); + } + + argidx++; + if (argidx >= argc) + { + show_usage(argv[0], "ERROR: Missing argument to --winpath", EXIT_FAILURE); + } + + g_topdir = strdup(argv[argidx]); + } +#endif + else if (strcmp(argv[argidx], "--help") == 0) + { + show_usage(argv[0], NULL, EXIT_SUCCESS); + } + else + { + append(&args, argv[argidx]); + } + } + + /* The final thing accumulated is the list of files */ + + g_files = args; + + /* If no paths were specified, then look in the current directory only */ + + if (!g_altpath) + { + g_altpath = strdup("."); + } + + if (g_debug) + { + fprintf(stderr, "SELECTIONS\n"); + fprintf(stderr, " CC : [%s]\n", g_cc ? g_cc : "(None)"); + fprintf(stderr, " CFLAGS : [%s]\n", g_cflags ? g_cflags : "(None)"); + fprintf(stderr, " FILES : [%s]\n", g_files ? g_files : "(None)"); + fprintf(stderr, " PATHS : [%s]\n", g_altpath ? g_altpath : "(None)"); +#ifdef HAVE_WINPATH + fprintf(stderr, " Windows Paths : [%s]\n", g_winpath ? "TRUE" : "FALSE"); + if (g_winpath) + { + fprintf(stderr, " TOPDIR : [%s]\n", g_topdir); + } +#endif + fprintf(stderr, " Windows Native : [%s]\n", g_winnative ? "TRUE" : "FALSE"); + } + + /* Check for required paramters */ + + if (!g_cc) + { + show_usage(argv[0], "ERROR: No compiler specified", EXIT_FAILURE); + } + + if (!g_files) + { + /* Don't report an error -- this happens normally in some configurations */ + + printf("# No files specified for dependency generataion\n"); + exit(EXIT_SUCCESS); + } + +#ifdef HAVE_WINPATH + if (g_winnative && g_winpath) + { + show_usage(argv[0], "ERROR: Both --winnative and --winpapth makes no sense", EXIT_FAILURE); + } +#endif +} + +static void do_dependency(const char *file, char separator) +{ + static const char moption[] = " -M "; + struct stat buf; + char *alloc; + char *altpath; + char *path; + char *lasts; + int cmdlen; + int pathlen; + int filelen; + int totallen; + int ret; + + /* Copy the compiler into the command buffer */ + + cmdlen = strlen(g_cc); + if (cmdlen >= MAX_BUFFER) + { + fprintf(stderr, "ERROR: Compiler string is too long [%d/%d]: %s\n", + cmdlen, MAX_BUFFER, g_cc); + exit(EXIT_FAILURE); + } + + strcpy(g_command, g_cc); + + /* Copy " -M " */ + + cmdlen += strlen(moption); + if (cmdlen >= MAX_BUFFER) + { + fprintf(stderr, "ERROR: Option string is too long [%d/%d]: %s\n", + cmdlen, MAX_BUFFER, moption); + exit(EXIT_FAILURE); + } + + strcat(g_command, moption); + + /* Copy the CFLAGS into the command buffer */ + + cmdlen += strlen(g_cflags); + if (cmdlen >= MAX_BUFFER) + { + fprintf(stderr, "ERROR: CFLAG string is too long [%d/%d]: %s\n", + cmdlen, MAX_BUFFER, g_cflags); + exit(EXIT_FAILURE); + } + + strcat(g_command, g_cflags); + + /* Add a space */ + + g_command[cmdlen] = ' '; + cmdlen++; + g_command[cmdlen] = '\0'; + + /* Make a copy of g_altpath. We need to do this because at least the version + * of strtok_r above does modifie it. + */ + + alloc = strdup(g_altpath); + if (!alloc) + { + fprintf(stderr, "ERROR: Failed to strdup paths\n"); + exit(EXIT_FAILURE); + } + + altpath = alloc; + + /* Try each path. This loop will continue until each path has been tried + * (failure) or until stat() finds the file + */ + + while ((path = strtok_r(altpath, " ", &lasts)) != NULL) + { + /* Create a full path to the file */ + + pathlen = strlen(path); + totallen = cmdlen + pathlen; + if (totallen >= MAX_BUFFER) + { + fprintf(stderr, "ERROR: Path is too long [%d/%d]: %s\n", + totallen, MAX_BUFFER, path); + exit(EXIT_FAILURE); + } + + strcpy(&g_command[cmdlen], path); + + if (g_command[totallen] != '\0') + { + fprintf(stderr, "ERROR: Missing NUL terminator\n"); + exit(EXIT_FAILURE); + } + + if (g_command[totallen-1] != separator) + { + g_command[totallen] = separator; + g_command[totallen+1] = '\0'; + pathlen++; + totallen++; + } + + filelen = strlen(file); + totallen += filelen; + if (totallen >= MAX_BUFFER) + { + fprintf(stderr, "ERROR: Path+file is too long [%d/%d]\n", + totallen, MAX_BUFFER); + exit(EXIT_FAILURE); + } + + strcat(g_command, file); + + /* Check that a file actually exists at this path */ + + if (g_debug) + { + fprintf(stderr, "Trying path=%s file=%s fullpath=%s\n", + path, file, &g_command[cmdlen]); + } + + ret = stat(&g_command[cmdlen], &buf); + if (ret < 0) + { + altpath = NULL; + continue; + } + + if (!S_ISREG(buf.st_mode)) + { + fprintf(stderr, "ERROR: File %s exists but is not a regular file\n", + &g_command[cmdlen]); + exit(EXIT_FAILURE); + } + + /* Okay.. we have. Create the dependency. One a failure to start the + * compiler, system() will return -1; Otherwise, the returned value + * from the compiler is in WEXITSTATUS(ret). + */ + + ret = system(g_command); +#ifdef WEXITSTATUS + if (ret < 0 || WEXITSTATUS(ret) != 0) + { + if (ret < 0) + { + fprintf(stderr, "ERROR: system failed: %s\n", strerror(errno)); + } + else + { + fprintf(stderr, "ERROR: %s failed: %d\n", g_cc, WEXITSTATUS(ret)); + } + + fprintf(stderr, " command: %s\n", g_command); + exit(EXIT_FAILURE); + } +#else + if (ret < 0) + { + fprintf(stderr, "ERROR: system failed: %s\n", strerror(errno)); + fprintf(stderr, " command: %s\n", g_command); + exit(EXIT_FAILURE); + } +#endif + + /* We don't really know that the command succeeded... Let's assume that it did */ + + free(alloc); + return; + } + + printf("# ERROR: File \"%s\" not found at any location\n", file); + exit(EXIT_FAILURE); +} + +/* Convert a Cygwin path to a Windows path */ + +#ifdef HAVE_WINPATH +static char *cywin2windows(const char *str, const char *append, enum slashmode_e mode) +{ + static const char cygdrive[] = "/cydrive"; + const char *src = src; + char *dest; + char *newpath; + char *allocpath = NULL; + int srclen = strlen(str); + int alloclen = 0; + int drive = 0; + int lastchar; + + /* Skip any leading whitespace */ + + while (isspace(*str)) str++; + + /* Were we asked to append something? */ + + if (append) + { + char *tmp; + + alloclen = sizeof(str) + sizeof(append) + 1; + allocpath = (char *)malloc(alloclen); + if (!allocpath) + { + fprintf(stderr, "ERROR: Failed to allocate %d bytes\n", alloclen); + exit(EXIT_FAILURE); + } + + snprintf(allocpath, alloclen, "%s/%s", str, append); + } + + /* Looking for path of the form /cygdrive/c/bla/bla/bla */ + + if (strcasecmp(src, cygdrive) == 0) + { + int cygsize = sizeof(cygdrive); + if (src[cygsize] == '/') + { + cygsize++; + srclen -= cygsize; + src += cygsize; + + if (srclen <= 0) + { + fprintf(stderr, "ERROR: Unhandled path: \"%s\"\n", str); + exit(EXIT_FAILURE); + } + + drive = toupper(*src); + if (drive < 'A' || drive > 'Z') + { + fprintf(stderr, "ERROR: Drive charager: \"%s\"\n", str); + exit(EXIT_FAILURE); + } + + srclen--; + src++; + alloclen = 2; + } + } + + /* Determine the size of the new path */ + + alloclen += sizeof(src) + 1; + if (mode == MODE_DBLBACK) + { + const char *tmpptr; + for (tmpptr = src; *tmpptr; tmpptr++) + { + if (*tmpptr == '/') alloclen++; + } + } + + /* Allocate memory for the new path */ + + newpath = (char *)malloc(alloclen); + if (!newpath) + { + fprintf(stderr, "ERROR: Failed to allocate %d bytes\n", alloclen); + exit(EXIT_FAILURE); + } + + dest = newpath; + + /* Copy the drive character */ + + if (drive) + { + *dest++ = drive; + *dest++ = ':'; + } + + /* Copy each character from the source, making modifications for foward + * slashes as required. + */ + + lastchar = '\0'; + for (; *src; src++) + { + if (mode != MODE_FSLASH && *src == '/') + { + if (lastchar != '/') + { + *dest++ = '\\'; + if (mode == MODE_DBLBACK) + { + *dest++ = '\\'; + } + } + } + else + { + *dest++ = *src; + } + + lastchar = *src; + } + + *dest++ = '\0'; + if (allocpath) + { + free(allocpath); + } + return dest; +} +#endif + +#ifdef HAVE_WINPATH +static void do_winpath(char *file) +{ + /* The file is in POSIX format. CC expects Windows format to generate the + * dependencies, but GNU make expect the resulting dependencies to be back + * in POSIX format. What a mess! + */ + + char *path = cywin2windows(g_topdir, file, MODE_FSLASH); + + /* Then get the dependency and perform conversions on it to make it + * palatable to the Cygwin make. + */ +#warning "Missing logic" + + free(path); +} +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +int main(int argc, char **argv, char **envp) +{ + char *lasts; + char *files; + char *file; + + /* Parse command line parameters */ + + parse_args(argc, argv); + + /* Then generate dependencies for each path on the command line. NOTE + * strtok_r will clobber the files list. But that is okay because we are + * only going to traverse it once. + */ + + files = g_files; + while ((file = strtok_r(files, " ", &lasts)) != NULL) + { + /* Check if we need to do path conversions for a Windows-natvie tool + * being using in a POSIX/Cygwin environment. + */ + +#ifdef HAVE_WINPATH + if (g_winpath) + { + do_winpath(file); + } + else +#endif + { + do_dependency(file, g_winnative ? '\\' : '/'); + } + + files = NULL; + } + + return EXIT_SUCCESS; +} diff --git a/nuttx/tools/mkdeps.sh b/nuttx/tools/mkdeps.sh index d8984e553..42397012b 100755 --- a/nuttx/tools/mkdeps.sh +++ b/nuttx/tools/mkdeps.sh @@ -2,7 +2,7 @@ ############################################################################ # tools/mkdeps.sh # -# Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. +# Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without diff --git a/nuttx/tools/mkromfsimg.sh b/nuttx/tools/mkromfsimg.sh index b77411980..8811f1953 100755 --- a/nuttx/tools/mkromfsimg.sh +++ b/nuttx/tools/mkromfsimg.sh @@ -233,7 +233,7 @@ mkdir -p $workingdir || { echo "Failed to created the new $workingdir"; exit 1; # Create the rcS file from the rcS.template if [ ! -r $rcstemplate ]; then - echo "$rcstemplete does not exist" + echo "$rcstemplate does not exist" rmdir $workingdir exit 1 fi diff --git a/nuttx/tools/mksymtab.c b/nuttx/tools/mksymtab.c index c5a46a92b..e401812c0 100644 --- a/nuttx/tools/mksymtab.c +++ b/nuttx/tools/mksymtab.c @@ -222,7 +222,7 @@ int main(int argc, char **argv, char **envp) fprintf(outstream, "/* %s: Auto-generated symbol table. Do not edit */\n\n", symtab); fprintf(outstream, "#include \n"); - fprintf(outstream, "#include \n\n"); + fprintf(outstream, "#include \n\n"); /* Output all of the require header files */ -- cgit v1.2.3