structures.rst 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. OS Data Structures
  2. ==================
  3. Scalar Types
  4. ************
  5. Many of the types used to communicate with NuttX are simple scalar
  6. types. These types are used to provide architecture independence of the
  7. OS from the application. The scalar types used at the NuttX interface
  8. include:
  9. .. c:type:: pid_t
  10. .. c:type:: size_t
  11. .. c:type:: sigset_t
  12. .. c:type:: time_t
  13. Hidden Interface Structures
  14. ***************************
  15. Several of the types used to interface with NuttX are structures that
  16. are intended to be hidden from the application. From the standpoint of
  17. the application, these structures (and structure pointers) should be
  18. treated as simple handles to reference OS resources. These hidden
  19. structures include:
  20. .. c:struct:: tcb_s
  21. .. c:type:: mqd_t
  22. .. c:type:: sem_t
  23. .. c:type:: pthread_key_t
  24. In order to maintain portability, applications should not reference
  25. specific elements within these hidden structures. These hidden
  26. structures will not be described further in this user's manual.
  27. Access to the ``errno`` Variable
  28. ********************************
  29. A pointer to the thread-specific ``errno`` value is available through a
  30. function call:
  31. .. c:function:: int *__errno(void)
  32. ``__errno()`` returns a pointer to the thread-specific
  33. ``errno`` value. Note that the symbol ``errno`` is defined to be
  34. ``__errno()`` so that the usual access by referencing the symbol
  35. ``errno`` will work as expected.
  36. .. code-block:: c
  37. #include <errno.h>
  38. #define errno *__errno()
  39. int *__errno(void);
  40. There is a unique, private ``errno`` value for each NuttX task. However,
  41. the implementation of ``errno`` differs somewhat from the use of
  42. ``errno`` in most multi-threaded process environments: In NuttX, each
  43. pthread will also have its own private copy of ``errno`` and the
  44. ``errno`` will not be shared between pthreads. This is, perhaps,
  45. non-standard but promotes better thread independence.
  46. :return: A pointer to the thread-specific ``errno`` value.
  47. User Interface Structures
  48. *************************
  49. .. c:type:: int (*main_t)(int argc, char *argv[])
  50. :c:type:`main_t` defines the type of a task entry point. :c:type:`main_t` is declared in
  51. ``sys/types.h``.
  52. .. c:struct:: sched_param
  53. This structure is used to pass scheduling priorities to and from NuttX:
  54. .. code-block:: c
  55. struct sched_param
  56. {
  57. int sched_priority;
  58. };
  59. .. c:struct:: timespec
  60. This structure is used to pass timing information between the NuttX and
  61. a user application:
  62. .. code-block:: c
  63. struct timespec
  64. {
  65. time_t tv_sec; /* Seconds */
  66. long tv_nsec; /* Nanoseconds */
  67. };
  68. .. c:struct:: mq_attr
  69. This structure is used to communicate message queue attributes between
  70. NuttX and a MoBY application:
  71. .. code-block:: c
  72. struct mq_attr {
  73. size_t mq_maxmsg; /* Max number of messages in queue */
  74. size_t mq_msgsize; /* Max message size */
  75. unsigned mq_flags; /* Queue flags */
  76. size_t mq_curmsgs; /* Number of messages currently in queue */
  77. };
  78. .. note that this gives a warning due to https://github.com/sphinx-doc/sphinx/issues/7819 https://github.com/sphinx-doc/sphinx/pull/8313
  79. .. c:struct:: sigaction
  80. The following structure defines the action to take for given signal:
  81. .. code-block:: c
  82. struct sigaction
  83. {
  84. union
  85. {
  86. void (*_sa_handler)(int);
  87. void (*_sa_sigaction)(int, siginfo_t *, void *);
  88. } sa_u;
  89. sigset_t sa_mask;
  90. int sa_flags;
  91. };
  92. #define sa_handler sa_u._sa_handler
  93. #define sa_sigaction sa_u._sa_sigaction
  94. .. c:struct:: siginfo
  95. .. c:type:: siginfo_t
  96. The following types is used to pass parameters to/from signal handlers:
  97. .. code-block:: c
  98. typedef struct siginfo
  99. {
  100. int si_signo;
  101. int si_code;
  102. union sigval si_value;
  103. } siginfo_t;
  104. .. c:union:: sigval
  105. This defines the type of the struct siginfo si_value field and is used
  106. to pass parameters with signals.
  107. .. code-block:: c
  108. union sigval
  109. {
  110. int sival_int;
  111. void *sival_ptr;
  112. };
  113. .. c:struct:: sigevent
  114. The following is used to attach a signal to a message queue to notify a
  115. task when a message is available on a queue.
  116. .. code-block:: c
  117. struct sigevent
  118. {
  119. int sigev_signo;
  120. union sigval sigev_value;
  121. int sigev_notify;
  122. };