Documentation: migrate /libs

This commit is contained in:
raiden00pl
2023-10-25 15:21:50 +02:00
committed by Xiang Xiao
parent 6448135f65
commit 61cdd105ef
9 changed files with 721 additions and 0 deletions
+1
View File
@@ -16,3 +16,4 @@ NuttX is very feature-rich RTOS and is thus composed of various different subsys
paging.rst
audio/index.rst
filesystem/index.rst
libs/index.rst
+46
View File
@@ -0,0 +1,46 @@
===============
NuttX libraries
===============
This page discusses the NuttX libraries that can be found in ``libs/``
Libraries in NuttX are very special creatures. They have these properties:
1. They can be shared by both application logic and logic within the OS when
using the FLAT build.
2. But in PROTECTED and KERNEL modes, they must be built differently: The
copies used by applications and the OS cannot be the same. Rather,
separate versions of libraries must be built for the kernel and for
applications.
3. When used by the OS, some special care must be taken to assure that the
OS logic does not disrupt the user's errno value and that the OS does
not create inappropriate cancellation points.
For example, ``sem_wait()`` is both a cancellation point and modifies the
errno value. So within the FLAT build and without kernel version for
the PROTECTED and KERNEL builds, the special internal OS interface
``nxsem_wait()`` must be used. Within libraries, the macro ``_SEM_WAIT()``
(as defined in ``include/nuttx/semaphore.h``) is used instead. The
definition of this macro accounts for the different usage environments.
NOTE: The libraries under ``libs/`` build differently from other NuttX
components: There are no build-related files in the ``libs/`` directory; it
is simply a container for other well-known, individual library directories.
The upper level Makefile logic is aware of the libraries within the ``libs/``
container.
The only real function of the ``libs/`` directory is to prevent the top-level
directory from becoming cluttered with individual libraries.
.. toctree::
:maxdepth: 1
:caption: Contents:
libc/index.rst
libdsp.rst
libm.rst
libxx.rst
libnx/index.rst
@@ -0,0 +1,152 @@
====
libc
====
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_BUILD_PROTECTED 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 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.
If ``CONFIG_BUILD_KERNEL`` is selected, then only a NuttX kernel will be built
with no applications.
Sub-Directories
===============
The files in the ``libs/libc/`` directory are organized (mostly) according which file
in the include/ directory provides the prototype for library functions. So
we have::
audio - This part of the audio system: nuttx/audio/audio.h
builtin - Support for builtin applications. Used by nuttx/binfmt and NSH.
dlfcn - dlfcn.h
endian - endian.h
errno - errno.h
hex2bin - hex2bin.h
libgen - libgen.h
locale - locale.h
lzf - lzf.h
fixedmath - fixedmath.h
grp - grp.h
inttypes - inttypes.h
machine - Various architecture-specific implementations.
math - math.h
modlib - Part of module and shared library logic: nuttx/lib/modlib.h
net - Various network-related header files: netinet/ether.h, arpa/inet.h
pthread - pthread.h
pwd - pwd.h
queue - queue.h
sched - sched.h
semaphore - semaphore.h
stdio - stdio.h
stdlib - stdlib.h
string - string.h (and legacy strings.h and non-standard nuttx/b2c.h)
time - time.h
uio - sys/uio.h
unistd - unistd.h
wchar - wchar.h
wctype - wctype.h
Most of these are "standard" header files; some are not: ``hex2bin.h`` and
``fixemath.h`` are non-standard.
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, libc.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 parameter. 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 ``Documentation/components/tools`` for further details about the use of mksymtab.
symtab
======
Symbol Tables and Build Modes
-----------------------------
This directory provide support for a symbol table which provides all/most of
system and C library services/functions to the application and NSH.
Symbol tables have differing usefulness in different NuttX build modes:
1. In the FLAT build (``CONFIG_BUILD_FLAT``), symbol tables are used to bind
addresses in loaded ELF or NxFLAT modules to base code that usually
resides in FLASH memory. Both OS interfaces and user/application
libraries are made available to the loaded module via symbol tables.
2. Symbol tables may be of value in a protected build
(``CONFIG_BUILD_PROTECTED``) where the newly started user task must
share resources with other user code (but should use system calls to
interact with the OS).
3. But in the kernel build mode (``CONFIG_BUILD_LOADABLE``), only fully linked
executables loadable via ``execl()``, ``execv()``, or ``posix_spawan()`` can used.
There is no use for a symbol table with the kernel build since all
memory resources are separate; nothing is share-able with the newly
started process.
Code/Text Size Implications
---------------------------
The option can have substantial effect on system image size, mainly
code/text. That is because the instructions to generate symtab.inc
above will cause EVERY interface in the NuttX RTOS and the C library to be
included into build. Add to that the size of a huge symbol table.
In order to reduce the code/text size, you may want to manually prune the
auto-generated symtab.inc file to remove all interfaces that you do
not wish to include into the base FLASH image.
.. toctree::
:maxdepth: 1
:caption: Contents:
zoneinfo.rst
@@ -0,0 +1,179 @@
==================
libs/libc/zoneinfo
==================
Author: Gregory Nutt <gnutt@nuttx.org>
Directory Contents
==================
This directory contains logic to create a version of the TZ/Olson database.
This database is required if localtime() support is selected via
CONFIG_LIBC_LOCALTIME. This logic in this directory does the following:
- It downloads the current TZ database from the IANA website
- It downloads the current timezone tools from the same location
- It builds the tools and constructs the binary TZ database
- It will then, optionally, build a ROMFS filesystem image containing
the data base.
Creating and Mounting a ROMFS TZ Database
=========================================
The ROMFS filesystem image can that be mounted during the boot-up sequence
so that it is available for the localtime() logic. There are two steps to
doing this:
- First, a ROM disk device must be created. This is done by calling
the function romdisk_register() as described in
nuttx/include/nuttx/drivers/ramdisk.h. This is an OS level operation
and must be done in the board-level logic before your application
starts.
romdisk_register() will create a block driver at /dev/ramN where N
is the device minor number that was provided to romdisk_register.
- The second step is to mount the file system. This step can be
performed either in your board configuration logic or by your
application using the mount() interface described in
nuttx/include/sys/mount.h.
These steps, however, must be done very early in initialization,
before there is any need for time-related services.
Both of these steps are shown together in the following code sample at the
end of this README file.
Example Configuration
=====================
I have tested this using the sim/nsh configuration. Here are the
modifications to the configuration that I used for testing::
CONFIG_BOARD_LATE_INITIALIZE=y
CONFIG_LIBC_LOCALTIME=y
CONFIG_LIBC_TZDIR="/share/zoneinfo"
CONFIG_LIBC_TZ_MAX_TIMES=370
CONFIG_LIBC_TZ_MAX_TYPES=20
CONFIG_LIBC_ZONEINFO=y
CONFIG_LIBC_ZONEINFO_ROMFS=y
NOTE: The full TZ database is quite large. To create a reasonable sized
ROMFS image, I had to trim some of the files like this::
cd nuttx
tools/configure.sh sim:nsh
make menuconfig
Select the above localtime() and nuttx/zoneinfo configuration settings.
Then::
make context
cd ../nuttx/libs/libc/zoneinfo/tzbin/usr/share/zoneinfo
Remove as many timezone files as you can. Do not remove the GMT, localtime,
or posixrules files. Those might be needed in any event. Then you can
force rebuilding of the ROMFS filesystem be removing some files::
cd ../../..
rm romfs_zoneinfo.*
rm *.o
cd ../../nuttx
make
If you have problems building the simulator on your platform, check out
nuttx/boards/sim/sim/sim/README.txt. You might find some help there.
Here is a sample run. I have not seen any errors in single stepping through
the logic but neither am I certain that everything is working properly::
NuttShell (NSH)
nsh> date
Jul 01 00:00:02 2008
nsh> set TZ US/Mountain
nsh> date -s "Apr 11 11:53:00 2015"
nsh> date
Apr 11 17:53:00 2015
NOTE: Because of daylight savings time, US/Mountain is GMT-6 on Apr 11. The
above suggests that perhaps the NSH data command may be setting local time,
but printing GMT time?
Sample Code to Mount the ROMFS Filesystem
=========================================
.. code-block:: C
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/mount.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <nuttx/drivers/ramdisk.h>
#include <nuttx/zoneinfo.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#ifndef CONFIG_LIBC_TZDIR
# error CONFIG_LIBC_TZDIR is not defined
#endif
#ifdef CONFIG_DISABLE_MOUNTPOINT
# error "Mountpoint support is disabled"
#endif
#ifndef CONFIG_FS_ROMFS
# error "ROMFS support not enabled"
#endif
#define SECTORSIZE 64
#define NSECTORS(b) (((b)+SECTORSIZE-1)/SECTORSIZE)
/****************************************************************************
* Public Functions
****************************************************************************/
int mount_zoneinfo(int minor)
{
char devname[32];
int ret;
/* Create a RAM disk for the test */
ret = romdisk_register(minor, romfs_zoneinfo_img,
NSECTORS(romfs_zoneinfo_img_len), SECTORSIZE);
if (ret < 0)
{
printf("ERROR: Failed to create RAM disk\n");
return ret;
}
/* Use the minor number to create a name for the ROM disk block device */
snprintf(devname, 32, "/dev/ram%d", minor);
/* Mount the ROMFS file system */
printf("Mounting ROMFS filesystem at target=%s with source=%s\n",
CONFIG_LIBC_TZDIR, devname);
ret = mount(devname, CONFIG_LIBC_TZDIR, "romfs", MS_RDONLY, NULL);
if (ret < 0)
{
printf("ERROR: Mount failed: %d\n", errno);
return ret;
}
printf("TZ database mounted at %s\n", CONFIG_LIBC_TZDIR);
return OK;
}
+7
View File
@@ -0,0 +1,7 @@
======
libdsp
======
This directory contains various DSP functions.
At the moment you will find here mainly functions related to BLDC/PMSM control.
+3
View File
@@ -0,0 +1,3 @@
====
libm
====
@@ -0,0 +1,19 @@
=====
libnx
=====
The graphics capability consist both of components internal to the RTOS
and of user-callable interfaces. In the NuttX kernel mode build there are
some components of the graphics subsystem are callable in user mode and
other components that are internal to the RTOS. This directory, libs/libnx/,
contains only those user-callable components.
The RTOS internal functions are contained in the ``graphics/`` directory.
Please refer to ``Documentation/components/graphics`` for more detailed information.
.. toctree::
:maxdepth: 1
:caption: Contents:
nxfonts.rst
@@ -0,0 +1,271 @@
======
nxfont
======
This directory contains font support for NuttX. The contents of this directory
are only build if CONFIG_NXFONTS is defined in the NuttX configuration file.
Installing New Fonts
====================
There is a tool called bdf-converter in the directory tools/. The bdf-converter
program be used to convert fonts in Bitmap Distribution Format (BDF)
into fonts that can be used in the NX graphics system.
Below are general instructions for creating and installing a new font
in the NX graphic system:
1. Locate a font in BDF format,
2. Use the bdf-converter program to convert the BDF font to the NuttX
font format. This will result in a C header file containing
definitions. That header file should be installed at, for example,
graphics/nxfonts/nxfonts_myfont.h.
Create a new NuttX configuration variable. For example, suppose
you define the following variable: CONFIG_NXFONT_MYFONT. Then
you would need to:
3. Define CONFIG_NXFONT_MYFONT=y in your NuttX configuration file.
A font ID number has to be assigned for each new font. The font ID
is defined in the file include/nuttx/nx/nxfonts.h. Those definitions
have to be extended to support your new font. Look at how the font ID
enabled by CONFIG_NXFONT_SANS23X27 is defined and add an ID for your
new font in a similar fashion:
4. include/nuttx/nx/nxfonts.h. Add you new font as a possible system
default font:
.. code-block:: C
#if defined(CONFIG_NXFONT_SANS23X27)
# define NXFONT_DEFAULT FONTID_SANS23X27
#elif defined(CONFIG_NXFONT_MYFONT)
# define NXFONT_DEFAULT FONTID_MYFONT
#endif
Then define the actual font ID. Make sure that the font ID value
is unique:
enum nx_fontid_e
{
FONTID_DEFAULT = 0 /* The default font */
#ifdef CONFIG_NXFONT_SANS23X27
, FONTID_SANS23X27 = 1 /* The 23x27 sans serif font */
#endif
#ifdef CONFIG_NXFONT_MYFONT
, FONTID_MYFONT = 2 /* My shiny, new font */
#endif
...
New Add the font to the NX build system. There are several files that
you have to modify to do this. Look how the build system uses the
font CONFIG_NXFONT_SANS23X27 for examaples:
5. nuttx/graphics/Makefile. This file needs logic to auto-generate
a C source file from the header file that you generated with the
the bdf-converter program. Notice NXFONTS_FONTID=2; this must be
set to the same font ID value that you defined in the
include/nuttx/nx/nxfonts.h file.
.. code-block:: make
genfontsources:
ifeq ($(CONFIG_NXFONT_SANS23X27),y)
@$(MAKE) -C nxfonts -f Makefile.sources NXFONTS_FONTID=1 EXTRAFLAGS=$(EXTRAFLAGS)
endif
ifeq ($(CONFIG_NXFONT_MYFONT),y)
@$(MAKE) -C nxfonts -f Makefile.sources NXFONTS_FONTID=2 EXTRAFLAGS=$(EXTRAFLAGS)
endif
6. nuttx/graphics/nxfonts/Make.defs. Set the make variable NXFSET_CSRCS.
NXFSET_CSRCS determines the name of the font C file to build when
NXFONTS_FONTID=2:
.. code-block:: make
ifeq ($(CONFIG_NXFONT_SANS23X27),y)
NXFSET_CSRCS += nxfonts_bitmaps_sans23x27.c
endif
ifeq ($(CONFIG_NXFONT_MYFONT),y)
NXFSET_CSRCS += nxfonts_bitmaps_myfont.c
endif
7. nuttx/graphics/nxfonts/Makefile.sources. This is the Makefile used
in step 5 that will actually generate the font C file. So, given
your NXFONTS_FONTID=2, it needs to determine a prefix to use for
auto-generated variable and function names and (again) the name of
the autogenerated file to create (this must be the same name that
was used in nuttx/graphics/nxfonts/Make.defs):
.. code-block:: C
ifeq ($(NXFONTS_FONTID),1)
NXFONTS_PREFIX := g_sans23x27_
GEN_CSRC = nxfonts_bitmaps_sans23x27.c
endif
ifeq ($(NXFONTS_FONTID),2)
NXFONTS_PREFIX := g_myfont_
GEN_CSRC = nxfonts_bitmaps_myfont.c
endif
8. graphics/nxfonts/nxfonts_bitmaps.c. This is the file that contains
the generic font structures. It is used as a "template" file by
nuttx/graphics/nxfonts/Makefile.sources to create your customized
font data set.
.. code-block:: C
#if NXFONTS_FONTID == 1
# include "nxfonts_sans23x27.h"
#elif NXFONTS_FONTID == 2
# include "nxfonts_myfont.h"
#else
# error "No font ID specified"
#endif
Where nxfonts_myfont.h is the NuttX font file that we generated in
step 2 using the bdf-converter tool.
9. graphics/nxfonts/nxfonts_getfont.c. Finally, we need to extend the
logic that does the run-time font lookups so that can find our new
font. The lookup function is NXHANDLE nxf_getfonthandle(enum nx_fontid_e fontid).
The new font information needs to be added to data structures used by
that function
.. code-block:: C
#ifdef CONFIG_NXFONT_SANS23X27
extern const struct nx_fontpackage_s g_sans23x27_package;
#endif
#ifdef CONFIG_NXFONT_MYFONT
extern const struct nx_fontpackage_s g_myfont_package;
#endif
static FAR const struct nx_fontpackage_s *g_fontpackages[] =
{
#ifdef CONFIG_NXFONT_SANS23X27
&g_sans23x27_package,
#endif
#ifdef CONFIG_NXFONT_MYFONT
&g_myfont_package,
#endif
NULL
};
Configuration Settings
======================
NxFonts
-------
* ``CONFIG_NXFONTS``
Enables font support
* ``CONFIG_NXFONTS_CHARBITS``
The number of bits in the character set. Current options are only 7 and 8.
The default is 7.
* ``CONFIG_NXFONTS_DISABLE_1BPP``, ``CONFIG_NXFONTS_DISABLE_2BPP``,
``CONFIG_NXFONTS_DISABLE_4BPP``, ``CONFIG_NXFONTS_DISABLE_8BPP``,
``CONFIG_NXFONTS_DISABLE_16BPP``, ``CONFIG_NXFONTS_DISABLE_24BPP``, and
``CONFIG_NXFONTS_DISABLE_32BPP``
NX supports a variety of pixel depths. You can save some memory by disabling
support for unused color depths.
* ``CONFIG_NXFONTS_PACKEDMSFIRST``
If a pixel depth of less than 8-bits is used, then NX needs to know if the
pixels pack from the MS to LS or from LS to MS
Font Selections
---------------
* ``CONFIG_NXFONT_SANS17X22``
This option enables support for a tiny, 17x22 san serif font
(font ID FONTID_SANS17X22 == 14).
* ``CONFIG_NXFONT_SANS20X26``
This option enables support for a tiny, 20x26 san serif font
(font ID FONTID_SANS20X26 == 15).
* ``CONFIG_NXFONT_SANS23X27``
This option enables support for a tiny, 23x27 san serif font
(font ID FONTID_SANS23X27 == 1).
* ``CONFIG_NXFONT_SANS22X29``
This option enables support for a small, 22x29 san serif font
(font ID FONTID_SANS22X29 == 2).
* ``CONFIG_NXFONT_SANS28X37``
This option enables support for a medium, 28x37 san serif font
(font ID FONTID_SANS28X37 == 3).
* ``CONFIG_NXFONT_SANS39X48``
This option enables support for a large, 39x48 san serif font
(font ID FONTID_SANS39X48 == 4).
* ``CONFIG_NXFONT_SANS17X23B``
This option enables support for a tiny, 17x23 san serif bold font
(font ID FONTID_SANS17X23B == 16).
* ``CONFIG_NXFONT_SANS20X27B``
This option enables support for a tiny, 20x27 san serif bold font
(font ID FONTID_SANS20X27B == 17).
* ``CONFIG_NXFONT_SANS22X29B``
This option enables support for a small, 22x29 san serif bold font
(font ID FONTID_SANS22X29B == 5).
* ``CONFIG_NXFONT_SANS28X37B``
This option enables support for a medium, 28x37 san serif bold font
(font ID FONTID_SANS28X37B == 6).
* ``CONFIG_NXFONT_SANS40X49B``
This option enables support for a large, 40x49 san serif bold font
(font ID FONTID_SANS40X49B == 7).
* ``CONFIG_NXFONT_SERIF22X29``
This option enables support for a small, 22x29 font (with serifs)
(font ID FONTID_SERIF22X29 == 8).
* ``CONFIG_NXFONT_SERIF29X37``
This option enables support for a medium, 29x37 font (with serifs)
(font ID FONTID_SERIF29X37 == 9).
* ``CONFIG_NXFONT_SERIF38X48``
This option enables support for a large, 38x48 font (with serifs)
(font ID FONTID_SERIF38X48 == 10).
* ``CONFIG_NXFONT_SERIF22X28B``
This option enables support for a small, 27x38 bold font (with serifs)
(font ID FONTID_SERIF22X28B == 11).
* ``CONFIG_NXFONT_SERIF27X38B``
This option enables support for a medium, 27x38 bold font (with serifs)
(font ID FONTID_SERIF27X38B == 12).
p
* ``CONFIG_NXFONT_SERIF38X49B``
This option enables support for a large, 38x49 bold font (with serifs)
(font ID FONTID_SERIF38X49B == 13).
[REVISIT... this list is not complete]
+43
View File
@@ -0,0 +1,43 @@
=====
libxx
=====
This directory contains three C++ library:
- A fragmentary C++ library that will allow to build only the simplest of
C++ applications. In the deeply embedded world, that is probably all
that is necessary.
At present, only the following are supported here:
- ``void *operator new(std::size_t nbytes)``
- ``void operator delete(void* ptr)``
- ``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)``
This implementation is selected when neither of the following
two options are enabled.
- LLVM "libc++" C++ library (http://libcxx.llvm.org/)
This implementation is selected with CONFIG_LIBCXX=y.
- uClibc++ C++ library (http://cxx.uclibc.org/)
This implementation is selected with CONFIG_UCLIBCXX=y.
operator new
------------
This operator should take a type of size_t. But size_t has an unknown underlying
type. In the nuttx sys/types.h header file, size_t is typed as uint32_t
(which is determined by architecture-specific logic). But the C++
compiler may believe that size_t is of a different type resulting in
compilation errors in the operator. Using the underlying integer type
instead of size_t seems to resolve the compilation issues. Need to
REVISIT this.
Once some C++ compilers, this will cause an error::
Problem: "'operator new' takes size_t ('...') as first parameter"
Workaround: Add -fpermissive to the compilation flags