Commit graph

471 commits

Author SHA1 Message Date
Benjamin Walsh a304f16773 kernel/poll: add k_poll_signal_init() runtime init
Change-Id: Id5a27f7d25e26a1a71ef87000d35a18777210c19
Signed-off-by: Benjamin Walsh <walsh.benj@gmail.com>
2017-02-03 13:54:01 +00:00
Benjamin Walsh b017986347 kernel/poll: add missing poll_event runtime init
It was in the static initializers, but was missing from the object
runtime init functions.

Change-Id: I10d519760eabdbe640a19cc5cfa9241c1356b070
Signed-off-by: Benjamin Walsh <walsh.benj@gmail.com>
2017-02-03 13:54:00 +00:00
Benjamin Walsh 969d4a7ff1 kernel/poll: add user tag to struct k_poll_event
This will allow users to install a way of finding out what the event and
the objects are used for without looking at the object itself, or to
tag a bunch of objects that belong together.

The runtime init function _does not_ take a tag so that there is no
runtime hit if not needed. The static initializer macro _does_ take the
tag, so that it does not have to be initialized at runtime if needed,
and thus avoids a runtime hit.

Change-Id: I89a36c6f969ff952f9d1673b1bb5136e407535c6
Signed-off-by: Benjamin Walsh <walsh.benj@gmail.com>
2017-02-03 13:53:59 +00:00
Benjamin Walsh acc68c1e59 kernel: add k_poll() API
k_poll() is similar to the POSIX poll() API in spirit in that it allows
a single thread to monitor multiple events without actively polling
them, but rather pending for one or more to become ready. Such events
can be a direct event, or kernel objects (currently only semaphores and
fifos).

When a kernel object being polled on is ready, it is not "given" to the
poller: the poller must then acquire it via the regular API for the
object (e.g. k_sem_take()). Only one thread can poll on a particular
object at one time. These restrictions mean that k_poll() is most
effective when a single thread monitors multiple events that are not
subject for contention. For example, being the sole reader on multiple
fifos, or the only thread being signalled by multiple semaphores, or a
combination of both.

Change-Id: I7035a9baf4aa016fb87afc5f5c0f5f8cb216480f
Signed-off-by: Benjamin Walsh <walsh.benj@gmail.com>
2017-02-02 00:30:00 +00:00
Benjamin Walsh 39b80d8f29 kernel: add k_fifo_is_empty()
Allow peeking at the fifo to see if there is an element without
dequeuing it.

Change-Id: I99cbe4495c81f1d7b77ad6a37cef4ec8c24d48eb
Signed-off-by: Benjamin Walsh <walsh.benj@gmail.com>
2017-02-02 00:29:58 +00:00
Benjamin Walsh ed240f2796 kernel/arch: streamline thread user options
The K_<thread option> flags/options avaialble to users were hidden in
the kernel private header files: move them to include/kernel.h to
publicize them.

Also, to avoid any future confusion, rename the k_thread.execution_flags
field to user_options.

Change-Id: I65a6fd5e9e78d4ccf783f3304b607a1e6956aeac
Signed-off-by: Benjamin Walsh <walsh.benj@gmail.com>
2017-01-24 13:34:50 +00:00
Benjamin Walsh dfa7ce5c94 kernel: include kernel.h in kernel_structs.h in asm files
This will be needed for some thread user options that will move to
kernel.h since they are part of the user API.

Change-Id: I46e302b6cafcdddbad3458134b98feb5b8d45d9b
Signed-off-by: Benjamin Walsh <walsh.benj@gmail.com>
2017-01-24 13:34:48 +00:00
Andrew Boie 350f88d525 kernel.h: add prototype for private idle exit function
Had only been called from ASM domain, but upcoming interrupt changes
invoke it from core arch C code as well.

Change-Id: Ifd831826068e130e2936cfa4da6c082c3433a5ae
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-01-19 20:17:07 +00:00
David B. Kinder ac74d8b652 license: Replace Apache boilerplate with SPDX tag
Replace the existing Apache 2.0 boilerplate header with an SPDX tag
throughout the zephyr code tree. This patch was generated via a
script run over the master branch.

Also updated doc/porting/application.rst that had a dependency on
line numbers in a literal include.

Manually updated subsys/logging/sys_log.c that had a malformed
header in the original file.  Also cleanup several cases that already
had a SPDX tag and we either got a duplicate or missed updating.

Jira: ZEP-1457

Change-Id: I6131a1d4ee0e58f5b938300c2d2fc77d2e69572c
Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-01-19 03:50:58 +00:00
Anas Nashif a614950607 kernel: including legacy.h depends on CONFIG_LEGACY_KERNEL
Jira: ZEP-1585
Change-Id: I283321e862a35945f2c834f8e278338d119bbc94
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-01-17 19:03:41 +00:00
Anas Nashif 173902f940 kernel: include limits.h for UINT_MAX
Change-Id: I9ae1019179f38fd9799997c189a4180d68e9bde6
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-01-17 19:03:38 +00:00
Benjamin Walsh 2f280416e6 kernel: fix total number of coop prios in coop-only mode
The idle priority was not accounted for.

With this change, the philosophers demo runs in coop-only mode.

Change-Id: I23db33687bcf3b2107d5fc07977143730f62e476
Signed-off-by: Benjamin Walsh <walsh.benj@gmail.com>
2017-01-17 12:17:27 +00:00
Benjamin Walsh 7fa3cd7e36 kernel: use PREEMPT_ENABLED instead of NUM_PREEMPT_PRIORITIES > 0
Change-Id: Ia470211b0da78158bf20400e2f1f33bdc28d1f67
Signed-off-by: Benjamin Walsh <walsh.benj@gmail.com>
2017-01-17 12:17:25 +00:00
Benjamin Walsh edb3570913 kernel: correct the highest priority in coop-only modes
In such a case, the system must take the idle coop priority into
account.

Change-Id: Ica5a4a7a659cb165073e9b8042a77ed23a6a662a
Signed-off-by: Benjamin Walsh <walsh.benj@gmail.com>
2017-01-17 12:17:25 +00:00
Anas Nashif bbb157df54 doc: add a doxygen group for the Kernel API
This was missing and all kernel objects belong to this group.

Change-Id: I3c31b168ca984b7d44cc5614a2e2bd5cc492cf50
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-01-16 18:13:03 -05:00
Benjamin Walsh e4e98f9d7b kernel: add user data API to timers
Similar to what was available with nano timers in the original kernel,
allow a user to associate opaque data with a timer.

Fix for ZEP-1558.

Change-Id: Ib8cf998b47988da27eba4ee5cd2658f90366b1e4
Signed-off-by: Benjamin Walsh <walsh.benj@gmail.com>
2017-01-14 13:06:00 +00:00
Carles Cufi cb0cf9f5f4 kernel: profiling: Expose an API call to analyze call stacks
The main, idle, interrupt and workqueue call stack definitions are not available
to applications to call stack_analyze() on, but they often require to be
measured empirically to tune their sizes in particular applications and
use cases.
This exposes a new k_call_stacks_analyze() API call that allows the
application to measure the used call stack space for the 4
kernel-defined call stacks.
Additionally for the ARC architecture the FIRQ stack is also profiled.

Change-id: I0cde149c7366cb6c4bbe8f9b0ab1cc5b56a36ed9
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2017-01-11 15:19:18 +00:00
Anas Nashif ea8c6aad24 kernel: remove last nanokernel ocrrurances from include/
Jira: ZEP-1323
Change-Id: I32e2dc33406a74c2e592bb2df215bd9170bf286d
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-12-25 14:34:43 -05:00
Benjamin Walsh 6209218f40 kernel: optimize ms-to-ticks for certain tick frequencies
Some tick frequencies lend themselves to optimized conversions from ms
to ticks and vice-versa.

- 1000Hz which does not need any conversion
- 500Hz, 250Hz, 125Hz where the division/multiplication are a straight
  shift since they are power-of-two factors of 1000.

In addition, some more generally used values are made to use optimized
conversion equations rather than the generic one that uses 64-bit math,
and often results in calling compiler intrinsics.

These values are: 100Hz, 50Hz, 25Hz, 20Hz, 10Hz, 1Hz (the last one used
in some testing).

Avoiding the 64-bit math intrisics has the additional benefit, in
addition to increased performance, of using a significant lower amount
of stack space: 52 bytes on ARM Cortex-M and 80 bytes on x86.

Change-Id: I080eb338a2637d6b1c6838c119af1a9fa37fe869
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-12-21 19:50:07 +00:00
Anas Nashif 345fdd52b1 kernel: document behavior of k_free
Document that when passing NULL to k_free, nothing happens.

Jira: ZEP-1475
Change-Id: I0efab2c8c670b0cebfd3e72aa8cd64857798abea
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-12-21 13:53:20 +00:00
Anas Nashif 2f203c2f92 tracing: rename CONFIG_DEBUG_TRACING_KERNEL_OBJECTS
Use a short name for this option CONFIG_OBJECT_TRACING.

Change-Id: Id27de7ef9ca299492b6b7d2324d9f5bcf8059a31
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-12-19 14:59:35 -05:00
Benjamin Walsh b12a8e0914 kernel: introduce single-threaded kernel
For very constrained systems, like bootloaders.

Only the main thread is available, so a main() function must be
provided. Kernel objects where pending is in play will not behave as
expected, since the main thread cannot pend, it being the only thread in
the system. Usage of objects should be limited to using K_NO_WAIT as the
timeout parameter, effectively polling on the object.

Change-Id: Iae0261daa98bff388dc482797cde69f94e2e95cc
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-12-15 16:17:39 -05:00
Benjamin Walsh c3a2bbba16 kernel: add k_cpu_idle/k_cpu_atomic_idle()
nano_cpu_idle/nano_cpu_atomic_idle were not ported to the unified
kernel, and only the old APIs were available. There was no real impact
since, in the unified kernel, only the idle thread should really be
doing power management. However, with a single-threaded kernel, these
functions can be useful again.

The kernel internals now make use of these APIs instead of the legacy
ones.

Change-Id: Ie8a6396ba378d3ddda27b8dd32fa4711bf53eb36
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-12-15 16:17:38 -05:00
Benjamin Walsh a2c58d5b85 kernel: fix mis-use of sys_dlist_t vs sys_dnode_t in _timeout
Not a functional bug per-se since they resolve to the same thing, but a
conceptual error nonetheless.

Change-Id: Ia11f6bd272cabe8da21d59e3378b8348f034e814
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-12-15 15:50:02 -05:00
Benjamin Walsh d211a52fc0 kernel: add defines for delta_ticks_from_prev special values
Use _INACTIVE instead of hardcoding -1.

_EXPIRED is defined as -2 and will be used for an improvement so that
interrupts are not locked for a non-deterministic amount of time while
handling expired timeouts.

_abort_timeout/_abort_thread_timeout return _INACTIVE instead of -1 if
the timeout has already been disabled.

Change-Id: If99226ff316a62c27b2a2e4e874388c3c44a8aeb
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-12-15 15:50:02 -05:00
Johan Hedberg c8201b2c2c kernel: Introduce new k_delayed_work_remaining_get API
Applications may want to know how much time is left until a delayed
work gets scheduled. To prevent applications from having to track this
themselves simply use the information that's already embedded as part
of the timer that's part of the delayed work struct.

Change-Id: I189df2f3be8b207e68b554a0cbb4f97f1a99de22
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-12 18:55:40 +00:00
Johan Hedberg f99ad3f0e2 kernel: Refactor remaining time evaluation for timeouts
Factor out the code for evaluating the remaining time for _timeout
structs so that it can also be used for other objects besides k_timer
structs (like k_delayed_work, coming in a subsequent patch).

Change-Id: I243a7b29fb2831f06e95086a31f0d3a6c37dad67
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-12 18:55:40 +00:00
Benjamin Walsh 91f834c908 kernel: add emphasis to nano_sem_take/k_sem_take return code difference
The reversal of the meaning of a value of 0 from k_sem_take vs
nano_sem_take has caused some issue when porting code from the legacy
API to the new API, so put some emphasis on this difference.

- Add a note in the API description.
- Put the call to k_sem_take and the reversal of the return value inside
  of nano_sem_take on one line so that grepping on it shows the
  reversal.

Change-Id: I2f4ba58dc087176d68b55371fa6e367b72559e70
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-12-01 17:57:23 +00:00
Benjamin Walsh 669360d5ec kernel: fix thread prio and stack size types in some APIs
Prio should be an int, since values are small integers, not a fixed-size
int32_t. It aligns with the prio parameters of the other APIs.

Stack size should be size_t.

Change-Id: Id29751b86c4ad7a7c2a7ffe446c2a96ae83c77bf
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-11-18 23:08:46 +00:00
Anas Nashif 61f4b2419c kernel: remove v2 usage and rename KERNEL_V2_DEBUG
Change-Id: I6b3f07714322ad79aeec2342621a4cddfe84cb2c
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-11-18 19:00:34 +00:00
Allan Stephens 82d4c3a68b doc: Minor cosmetic tweaks for kernel API descriptions
Change-Id: Ie989b45b19e5e70958301dd8d903cf2876709f5a
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-11-18 02:31:35 +00:00
Allan Stephens c2f15a4525 doc: Add descriptions for clock-related helper macros
Also fixes up Kernel Primer examples to use these macros.

Change-Id: Ib1bc9e3f85ab75f81986bc3930fb287266a886b5
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-11-18 02:31:35 +00:00
Allan Stephens 9ef50f4f0c doc: Fix up return value descriptions for kernel APIs
Return value descriptions using the "@retval" tag now reflect
the fact that they appear on a separate line from the value
they are describing.

Change-Id: I3e3e347d133ad998e7db50a99369d41cbfb9efcc
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-11-18 02:31:33 +00:00
Allan Stephens 6bba9b052f doc: Improve descriptions of workqueue APIs
The API guide now does a better job of explaining how to use
a workqueue. Also hides information about workqueue internals
and fixes several errors and omissions.

Change-Id: I6492c1c6105c258ce98365ca33059d8f32c1be41
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-11-18 02:31:32 +00:00
Allan Stephens 5eceb8514c doc: Improve descriptions for some user-supplied functions
The API guide now does a better job of explaining how to correctly
write these functions.

Change-Id: Ib1df55eb28fa408f3f786f122353e37505002f07
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-11-18 02:31:32 +00:00
Allan Stephens c98da84e69 doc: Various corrections to doxygen info for Kernel APIs
Most kernel APIs are now ready for inclusion in the API guide.
The APIs largely follow a standard template to provide users
of the API guide with a consistent look-and-feel.

Change-Id: Ib682c31f912e19f5f6d8545d74c5f675b1741058
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-11-16 21:43:16 +00:00
Johan Hedberg 1447169c4b kernel: Add helpers for converting durations into milliseconds
These should help to make it easier to understand code passing
specific durations to the kernel APIs.

Change-Id: I8682fafc291e8af56fd0289d0cab8c736b88da59
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-11-13 10:52:15 +02:00
Benjamin Walsh f6ca7de09c kernel/arch: consolidate tTCS and TNANO definitions
There was a lot of duplication between architectures for the definition
of threads and the "nanokernel" guts. These have been consolidated.

Now, a common file kernel/unified/include/kernel_structs.h holds the
common definitions. Architectures provide two files to complement it:
kernel_arch_data.h and kernel_arch_func.h. The first one contains at
least the struct _thread_arch and struct _kernel_arch data structures,
as well as the struct _callee_saved and struct _caller_saved register
layouts. The second file contains anything that needs what is provided
by the common stuff in kernel_structs.h. Those two files are only meant
to be included in kernel_structs.h in very specific locations.

The thread data structure has been separated into three major parts:
common struct _thread_base and struct k_thread, and arch-specific struct
_thread_arch. The first and third ones are included in the second.

The struct s_NANO data structure has been split into two: common struct
_kernel and arch-specific struct _kernel_arch. The latter is included in
the former.

Offsets files have also changed: nano_offsets.h has been renamed
kernel_offsets.h and is still included by the arch-specific offsets.c.
Also, since the thread and kernel data structures are now made of
sub-structures, offsets have to be added to make up the full offset.
Some of these additions have been consolidated in shorter symbols,
available from kernel/unified/include/offsets_short.h, which includes an
arch-specific offsets_arch_short.h. Most of the code include
offsets_short.h now instead of offsets.h.

Change-Id: I084645cb7e6db8db69aeaaf162963fe157045d5a
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-11-12 07:04:52 -05:00
Allan Stephens da82722534 doc: Minor corrections to kernel API documentation
Addresses a range of issues affecting the Kernel Primer or
the API Guide generated from doxygen tags.

* Ensures mailbox examples use kernel APIs correctly.
  (Fix for ZEP-1262, as well as other errors).

* Ensures memory alignment limitations for memory slabs
  are correctly described. (Fix for ZEP-1265.)

* Ensures memory alignment limitations for memory pools
  are more clearly described. Also fixes a typo in a
  memory pool example.

* Ensures memory alignment limitations for message
  queues are more clearly described.

* Fixes references to a number of kernel configuration
  options that were omitted or incorrectly formatted.

* Fixes a typo in an example of thread spawning.

Change-Id: I395186f333490b1e0c4223b87c0fe7136548770f
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-11-11 22:13:32 +00:00
Benjamin Walsh 8215ce19ce kernel: fix k_msgq_get/put() from ISR
There was no check to see if the current context was running an ISR when
taking a decision whether to do a context switch or not.

Change-Id: Ib9c426de8c0893b3d9383290bb59f6e0e41e9f52
Signed-off-by: Benjamin Walsh <walsh.benj@gmail.com>
2016-11-10 23:38:06 +00:00
Benjamin Walsh 445830dcec kernel: add k_is_preempt_thread()
Useful for finding out if the current thread is protected against
preemption when using non-preemption to protect data structures.

Change-Id: Ib545a3609af3646ba49eeeb5a2c50dc51af010d4
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-11-10 23:18:56 +00:00
Benjamin Walsh d7ad176be6 kernel: export k_sched_lock and k_sched_unlock.
Oversight. These functions are used extensively in the kernel guts, but
are also supposed to be an API.

k_sched_lock used to be implemented as a static inline. However, until
the header files are cleaned-up, and everything, including applications
get access to the kernel internal data structures, it must be
implemented as a function. To reduce the cost to the internals of the
kernel, the new internal _sched_lock() contains the same implemetation,
but is inlined.

Change-Id: If2f61d7714f87d81ddbeed69fedd111b8ce01376
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-11-10 23:18:55 +00:00
Allan Stephens a543d956ba kernel: Remove traces of semaphore groups from public APIs
Change-Id: I68fa6d4c835e1df4b613bf4059fa8d28801b4ebf
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-11-10 00:28:03 +00:00
Allan Stephens 5a7a86cb7f unified/doc: Revise doxygen for kernel APIs
Does a general cleanup including:

* adding descriptions for APIs that are missing them
* adding information that would be helpful to users
  and removing information that wouldn't be helpful
* correcting errors
* aligning the terminology with the terminology used
  in the Kernel Primer document
* standardizing the way information is presented

Change-Id: I536644a7dc60b62100e379a199a645344430beb7
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-11-10 00:28:02 +00:00
Benjamin Walsh c7ba8b17e1 kernel: rename k_am_in_isr() to k_is_in_isr()
Change-Id: Ie312da34dbbfbeb2c76bbf38905d8f334da28b63
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-11-08 20:27:31 -05:00
Benjamin Walsh fab8d92936 kernel: add K_IDLE_PRIO
Define the priority reserved for the idle thread rather than use
K_LOWEST_THREAD_PRIO.

Change-Id: I514296d774047fa1348249da8ee90a68b6aace17
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-11-08 23:38:48 +00:00
Andrew Boie e004dec958 include: remove old kernel defintions
C++ support moved from nanokernel.h to kernel.h.

Change-Id: I5e1631941e26f4ab3f311b680267b743bab15e40
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2016-11-07 11:32:57 -08:00
Allan Stephens 22ea605eab kernel: Remove traces of legacy task groups from public API
Change-Id: Id4c4508020063ac8a7186daea7b56f5ce29a62d6
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-11-07 18:52:32 +00:00
Benjamin Walsh 8cf56bcac7 unified: dissociate system workqueue from common workqueue module
Making a reference to the common work queue code should not necessarily
drag in the system workqueue, since it is possible to use a workqueue
that is not the system workqueue. This is done by moving the system
workqueue into its own code module.

Moving the system workqueue to its own code module allows removing the
NANO_WORKQUEUE and SYSTEM_WORKQUEUE kconfig options, and compiling the
common workqueue code and system workqueue all the time. They are only
linked in the final image if a reference to them exist, same as the
other kernel modules.

Change-Id: I6f48d2542bda24f4702e7c2e317818dd082b3c11
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-11-04 22:39:54 +00:00
Dmitriy Korovkin 07414678f9 unified: Exclude inline assembler blocks from Doxygen
Prevent Doxygen from picking internal blocks of code.

Jira: ZEP-1182

Change-Id: Ib42262cc7fdf9678c73458e68c3e7a6f534e2281
Signed-off-by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
2016-11-04 00:47:50 +00:00
Allan Stephens 1342adbd63 unified: Add missing arguments to K_TIMER_DEFINE()
It is now possible to specify the expiry and stop functions
of a statically-defined timer, just as can be done for a
dynamically-defined timer.

[Part of fix to ZEP-1186]

Change-Id: Ibb9096f3fdafdc6c904184587f86ecd52accdd66
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-11-04 00:47:23 +00:00
Allan Stephens e7d2cc216d unified: Add object tracing support for kernel objects
Defines an object tracing list for each kernel object type
that supports object tracing, and ensures that both statically
and dynamically defined objects are added to the appropriate list.

Ensure that each static kernel object is grouped together with
the other static objects of the same type. Revise the initialization
function for each kernel type (or create it, if needed) so that
each static object is added to the object tracing list for its
associated type.

Note 1: Threads are handled a bit differently than other kernel
object types. A statically-defined thread is added to the thread
list when the thread is started, not when the kernel initializes.
Also, a thread is removed from the thread list when the thread
terminates or aborts, unlike other types of kernel objects which
are never removed from an object tracing list. (Such support would
require the creation of APIs to "uninitialize" the kernel object.)

Note 2: The list head variables for all kernel object types
are now explicitly defined. However, the list head variable for
the ring buffer type continues to be implicitly defined for the
time being, since it isn't considered to be an core kernel object
type.

Change-Id: Ie24d41023e05b3598dc6b344e6871a9692bba02d
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-11-02 21:56:27 +00:00
Peter Mitsis 058fa4e493 unified: API changes to event handling
Allows event objects to pend signals in a cumulative way using
the semaphore in a non-binary way.

Jira: ZEP-928
Change-Id: I3ce8a075ef89309118596ec5781c15d4f3289d34
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-11-01 16:27:41 -04:00
Peter Mitsis 348eb4c4fb unified: Update kernel.h doxygen comments
Jira: ZEP-981
Change-Id: I3797f5e8824b4a01153f3c1fe0e070d3b107f596
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-10-31 23:56:04 +00:00
Benjamin Walsh 31a3f6a70e unified: rename 'events' to 'alerts'
Event is such an overloaded and generic term (event logger, *kernel*
event logger, "protocol" events in other subsystems, etc.), that it is
confusing for the name an object. Events are kinda like signals, but not
exactly, so we chose not to name them 'signals' to prevent further
confusion. "Alerts" felt like a good fit, since they are used to "alert"
an application that something of significance should be addressed and
because an "alert handler" can be proactively registered with an alert.

Change-Id: Ibfeb5eaf0e6e62702ac3fec281d17f8a63145fa1
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-10-28 18:44:18 +00:00
Benjamin Walsh 7ef0f624a7 unified: rename 'memory maps' to 'memory slabs'
This better aligns with the actual functionality of the object.

Change-Id: I70abf54f994e92abd7367251089ea4f735d273fe
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-10-28 18:44:18 +00:00
Allan Stephens 88095027f4 unified: Ensure K_THREAD_DEFINE() generates a thread id
Previously the macro provided no way for an application to
easily reference a statically-defined thread.

Change-Id: I552e5f4ab4e6e8a793bb3a6a2b0c2636b900023a
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-10-27 08:36:14 -05:00
Allan Stephens 6cfe1322f8 unified: Streamline thread initialization macros
The _THREAD_INITIALIZER() macro is now used in all cases where
a static thread is defined. It accepts the arguments used by
k_thread_spawn(), as well as the legacy abort function and task
group arguments.

The two remaining legacy macros required to support static threads
now appear in legacy.h.

Change-Id: I7ba24c285beee63d63c8da0e0fa120f35c0d9526
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-10-27 08:14:51 -05:00
Allan Stephens 7c5bffa669 unified: Add options field to static thread initialization structure
Adds the field, in preparation for making use of it in the future.

Also re-orders the existing fields of the _static_thread_data
structure so they appear in the same order as the arguments
to k_thread_spawn(). This makes it easier to ensure all of the
arguments and fields are handled in a consistent manner.

Change-Id: I401687ecfdacd52c05ab95af7f12d8dc658ed419
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-10-27 08:14:51 -05:00
Andrew Boie 431607c20a nios2: port to unified kernel
With this patch we introduce unified kernel support for NIOS II.
Not all test cases have been ported, but the following command
currently succeeds with 43/43 passing test cases:

 $ sanitycheck --arch=nios2 -xKERNEL_TYPE=unified \
         --tag=unified_capable

Issue: ZEP-934
Change-Id: Id8effa0369a6a22c4d0a789fa2a8e108af0e0786
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2016-10-26 17:10:13 +00:00
Allan Stephens e262615280 unified: Remove k_thread_abort_handler() support
The new kernel doesn't support the thread abort handler concept,
so only the legacy API for this capability is needed.

Change-Id: Ie809092e73b784504c3d298911d216bed8dd8993
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-10-26 17:03:12 +00:00
Allan Stephens 480a131ad9 unified: Support heap memory pool
Fleshes out the prototype heap memory pool support
to make it fully operational. Noteworthy changes are
listed below:

Tweaks arguments to k_malloc() and k_free() to be more like
malloc() and free(). Similarly, modifies k_free() to take
no action when passed a NULL pointer.

Now stores the complete block descriptor at the start
of any block allocated from the heap memory pool. This
increases memory overhead by 4 bytes per block, but
streamlines the allocation and freeing algorithms. It also
ensures that the routines will work if the block descriptor
internals are changed in the future.

Now allows the heap memory pool to be defined using the
HEAP_MEM_POOL_SIZE configuration option. This will be the
official configuration approach in the unified kernel.

Also allows the heap memory pool to be defined using the
(undocumented) HEAP_SIZE entry in the MDEF. This is provided
for legacy reasons only.

Co-locates memory pool initialization code to keep the line
that causes memory pool initialization to be done during booting
right next to the routine that does the initialization.

Change-Id: Ifea9d88142fb434d4bea38bb1fcc4856a3853d8d
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-10-25 00:10:34 +00:00
Allan Stephens 904cf97263 unified: Eliminate thread config structure used by work queues
Reworks k_work_q_start() so that it accepts its 3 configuration
settings directly, rather than forcing the caller to pass in a
configuration data structure.

Change-Id: Ic0bd1b94f1a1c8e0f8a84b3bd3677d59d0708734
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-10-25 00:10:34 +00:00
Allan Stephens 06aefdb654 unified: Align thread creation APIs
Aligns the APIs for defining a thread at compile time and for
spawning a thread at run time.

Change-Id: Ic5df450cbe4d0eb562fb4a608f1ac5a8a7cb4b96
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-10-25 00:10:33 +00:00
Allan Stephens 35ffaff43d unified: Don't bother initializing memory map buffer
The "__noinit" was accidentally lost during initial prototyping
of the unified kernel. This just restores it ...

Change-Id: Id13e0e9a323c1bcd49c28a5d8da73943b0177890
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-10-25 00:10:33 +00:00
Peter Mitsis 602e6a8ae7 unfied: Tweak stack API parameters
- Reorders parameters where necessary

Change-Id: I0aa659515b71c8f2d6ed7fae47489ddcb10eb69f
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-10-24 22:58:27 +00:00
Peter Mitsis ddbe77a1dd unified: Remove unused K_STACK_SIZE() macro
Change-Id: I3ded26e249fec3e9024984f4a788bf312c3c2d88
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-10-24 22:58:26 +00:00
Dmitriy Korovkin 3c90651fd8 unified/arc: add memory pools support for ARC architecture
ARC does not align data structures by 4 bytes by default.
Add necessary linker sections.

Change-Id: I3bf7aa38b9bc8cba56f824469040c027968fa564
Signed-off-by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
2016-10-22 01:27:01 +00:00
Peter Mitsis 5f39924e58 unified: memory pool APIs to use size_t
Change-Id: Id1dd37ad3bb35052fd53a6a26711c9e0c2070a25
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-10-21 15:33:58 +00:00
Peter Mitsis fb02d576c0 unified: Memory map APIs to use size_t
Change-Id: I035019c0cb7193400d02f493546fd3964baf073a
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-10-21 15:33:45 +00:00
Peter Mitsis 4a5d62fe15 unified: Update mem_map doxygen style function headers
Change-Id: Ic683a3ea6f723cf3d615ad28ebf603ed50af9155
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-10-21 15:33:44 +00:00
Allan Stephens 6c98c4d378 unified: Ensure delays do not time out prematurely
Ensures that all APIs which accept a timeout value wait for at least
the specified amount of time, and do not time out prematurely.

* The kernel now waits for the next system clock tick to occur before
  the timeout interval is considered to have started. (That is, the only
  way to ensure a delay of N tick intervals is to wait for N+1 ticks
  to occur.)

* Gets rid of ticks -> milliseconds -> ticks conversion in task_sleep()
  and fiber_sleep() legacy APIs, since this introduces rounding that
  -- coupled with the previous change -- can alter the number of ticks
  being requested during the sleep operation.

* Corrects work queue API that was incorrectly shown to use a delay
  measured in ticks, rather than milliseconds.

Change-Id: I8b04467237b24fb0364c8f344d872457418c18da
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-10-21 15:33:29 +00:00
Peter Mitsis 026b4ed4e2 unified: msgqs to use size_t
Change-Id: I9bedf22a052990395a1f83417c533b197b31987a
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-10-20 15:20:40 -04:00
Benjamin Walsh b9c1a067bf unified: doxygen comments for semaphores.
Change-Id: If1a9fa887b07736a70cb26227e147120e5a86f6f
Signed-off-by: Benjamin Walsh <walsh.benj@gmail.com>
2016-10-19 18:36:03 +00:00
Allan Stephens 45bfa37f97 unified: Revise timer code to conform to new API specification
Provides users with a more compact and intuitive API for kernel
timers.

Provides legacy support for microkernel timers and nanokernel
timers by building on the new kernel timer infrastructure.
Each timer type requires only a small amount of additional
wrapper code, as well as the addition of a single pointer
field to the underlying timer structure, all of which will be
easily removed when support for the legacy APIs is discontinued.

Change-Id: I282dfaf1ed08681703baabf21e4dbc3516ee7463
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-10-19 18:14:58 +00:00
Peter Mitsis d7a3750b3c unified: Update msgq doxygen styled function headers
Change-Id: I4648ebcda9e6c3abea05b420584e2bcb112f3ed4
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-10-19 14:54:45 +00:00
Peter Mitsis 1da807e7a8 unified: Tweak msgq API parameters
- Reorders parameters where necessary
 - Adds alignment parameter to K_MSGQ_DEFINE() for buffer alignment
 - Renames parameters where necessary so they are more intuitive

Change-Id: I0b53105c04109127897bf4790e6908082f82da4e
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-10-19 14:54:44 +00:00
Peter Mitsis 67be24909d unified: Add k_msgq_num_free_get() API
Complements existing k_msgq_num_used_get().

Change-Id: If04a540878ae998ccdc14867a022c428947604a6
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-10-19 14:54:44 +00:00
Peter Mitsis f925f0f853 unified: Remove unused K_MSGQ_SIZE() macro
Change-Id: Ifabe0615672576834d41b36dfcc121d3de1ac30b
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-10-19 14:54:43 +00:00
Peter Mitsis 578f9111ed unified: Tweak mem_map API parameters
- Reorders parameters where necessary
 - Adds buffer alignment parameter to K_MEM_MAP_DEFINE()

Change-Id: Ifa1a09c62492cd6db8bdd83f31a5ca5ba072b484
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-10-18 15:31:51 +00:00
Peter Mitsis c001aa8ef6 unified: Add k_mem_map_num_free_get()
Complements existing k_mem_map_num_used_get().

Change-Id: Ie69c0a8e30007e365820448bde48303718369904
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-10-18 15:31:50 +00:00
Peter Mitsis c19dd50093 unified: Remove unused K_MEM_MAP_SIZE() macro
Change-Id: I25673bbeeb5ba188f6e6f52e237494cfeb85a8c6
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-10-18 15:31:50 +00:00
Peter Mitsis 937042c22a unified: Update mem_pool doxygen style function headers
Change-Id: I3b751522bbabaec5c5146cc28b85d188344a693f
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-10-18 15:30:40 +00:00
Peter Mitsis 2a2b075826 unified: Tweak K_MEMORY_POOL_DEFINE() macro
- Renames to K_MEM_POOL_DEFINE() for consistency
- Adds alignment parameter to align the pool buffer.

Jira: ZEP-926
Change-Id: I6cf0a1ce45c3a0fc5f0675047d8928659df1e75e
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-10-18 15:30:40 +00:00
Peter Mitsis c61495b9bd unified: Remove unused K_MEM_POOL_SIZE() macro
Change-Id: I1fe11628baf6d8db1dcf5a57399b29f37496dd1b
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-10-18 15:30:39 +00:00
Peter Mitsis b2fd5be4dc unified: Rework K_THREAD_DEFINE()
K_THREAD_DEFINE() can no longer specify a thread group. However, it now
accepts a 'delay' parameter just as k_thread_spawn() does.

To create a statically defined thread that may belong to one or more thread
groups the new internal _MDEF_THREAD_DEFINE() macro is used. It is only used
for legacy purposes.

Threads can not both have a delayed start AND belong to a thread group.

Jira: ZEP-916
Change-Id: Ia6e59ddcb4fc68f1f60f9c6b0f4f227f161ad1bb
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-10-17 17:52:33 +00:00
Peter Mitsis d93078cb5b unified: Mailboxes to use size_t
Change-Id: I67c1b11d2b6c09e96eb72c3e16f67f5b5acbed3a
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-10-15 07:41:24 +00:00
Peter Mitsis 1209270bf8 unified: Relocate mailbox doxygen style function headers
Change-Id: I06e9ce40da650df67f05db8779a5f6199e6091d5
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-10-15 07:41:23 +00:00
Peter Mitsis 40680f6eb9 unified: Tweak mailbox API parameters
Tweak mailbox API parameters so that not only are their descriptions
correct, but their names match across header file and C file.

Change-Id: Ieeb3a40fb7c535a5eac2e06533d01d13aaf69181
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-10-15 07:41:23 +00:00
Peter Mitsis 2fef023c3d unified: Conditionally declare k_pipe_block_put()
The routine k_pipe_block_put() is only available if the system has
been configured for asynchronous pipe sends.

Change-Id: I642fecc961ca4ef4ac8839a01ffd4125c30794b8
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-10-15 07:09:59 +00:00
Peter Mitsis e5d9c58301 unified: Tweak pipe API parameters
- Reorders parameters where necessary
 - Adds alignment parameter to K_PIPE_DEFINE()
 - Renames parameters where necessary so they are sync'd
   between header and source files

Change-Id: I4f2367abc28aff646cc90beb9f08bb266e143b0c
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-10-15 07:09:58 +00:00
Peter Mitsis 59f59088ea unified: Remove unused K_PIPE_SIZE() macro
Change-Id: If7d3a0c9153365222c85072e62a537317b998bdb
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-10-15 07:09:57 +00:00
Allan Stephens 1d07bd1bff unified: Eliminate support for dynamic timers
Gets rid of official support for dynamic timer allocation
in the unified kernel, since users can easily define and
initialize timers at any time. Legacy support for dynamic
timers is maintained for backwards compatibility reasons
for the time being ...

Change-Id: I12b3e25914fe11e3886065bee4e96fb96f59b299
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-10-13 13:54:00 +00:00
Allan Stephens 018cd9a656 unified: Eliminate k_stack_init_with_buffer()
Folds this API into k_stack_init() to provide a single API
that requires the caller to pass in the stack buffer, just
as is done for other kernel objects initialization APIs
involving the use of a buffer.

Change-Id: Icad5fd6e5387d634738d1574f8dfbc5421cd642d
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-10-13 13:54:00 +00:00
Allan Stephens 399d0ad55a unified: Rationalize thread priority APIs
* Gets rid of k_current_priority_get(). Users can just call
  k_thread_priority_get(k_current_get()) instead.

* Declares k_thread_priority_get() in kernel.h, where it
  really belongs.

* Removes duplicate declaration of k_thread_priority_set().

Change-Id: I616ae6f2e06c95ecba3b92324186b3fa29162fd1
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-10-13 13:53:59 +00:00
Allan Stephens b03955033b unified: Eliminate unimplemented unified kernel APIs
Gets rid of unified kernel APIs that will never be implemented.
(i.e. They were proposed, but are no longer considered desirable.)

Change-Id: I63ff0d2cdef355d21595f2a778ef5d5b18796149
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-10-13 13:53:59 +00:00
Allan Stephens ea6cfd1d83 unified: Add legacy DEFINE_TASK support
Allows unified kernel to support legacy microkernel applications
that use private tasks.

Also renames the unified kernel macro for defining a thread
to be consistent with the naming used for defining other kernel
objects.

Change-Id: I667d87056138c45c291dd848344e4051bf9fd1ff
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-10-11 09:59:16 -05:00
Allan Stephens 86ea333b5a unified: Remove unimplemented kernel workload APIs
These can be re-introduced if a kernel workload measuring
capability is added to the unified kernel.

Change-Id: Id7ad9c1239667511ffcecf571126301c9b278929
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-10-11 09:54:44 -05:00
Benjamin Walsh 1a5450bb8e unified: merge NANO_TIMERS and NANO_TIMEOUTS with SYS_CLOCK_EXISTS
Timers are based off timeouts now, which can only be enabled when the
system clock is enabled. So the three are really just one setting now.

Keep the NANO_TIMERS and NANO_TIMEOUTS around for now until all
middleware that rely on them is updated. They are always enabled when
SYS_CLOCK_EXISTS is enabled.

Change-Id: Iaef1302ef9ad8fc5640542ab6d7304d67aafcfdc
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-10-10 21:27:41 +00:00
Benjamin Walsh b7ef0cba5f unified: remove last instances of struct tcs
Change-Id: I956bf0e96266e68ac1743f02a82ffafe77ebb0e8
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-10-10 21:27:38 +00:00
Benjamin Walsh 055262c159 unified: remaining timeout cleanup
Rename remaining functions to fit with kernel naming convention for
internal interfaces. Use struct k_thread instead of struct tcs.

Change-Id: I28cd7f6f4d7ddaeb825c8d2999242d8d2dd93f31
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-10-10 21:27:37 +00:00
Benjamin Walsh 57d55dcc7a unified: have __ticks_to_ms() return 0 when no system clock
Change-Id: I0834dfff2a631ef365be7ae3a55d5ad4ace3dbf5
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-10-10 21:27:32 +00:00
Benjamin Walsh 71d5228ca9 unified: un-comment k_thread_[suspend|resume|abort_handler_set]
They are now available.

Change-Id: Iae15636396fdf4d5da96f6735345857d83cd3d51
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-10-10 21:27:30 +00:00
Iván Briano 9c7b5eacea unified: Fix building of the unified kernel
Change-Id: I6824cdb9123a574a56af10efdebdc1c8b82427f8
Signed-off-by: Iván Briano <ivan.briano@intel.com>
2016-10-04 18:11:05 -03:00
Peter Mitsis a04c0d70e1 unified: Rename k_thread_static_init structure
Renames the k_thread_static_init structure to better follow
Zephyr naming conventions.

Change-Id: I479add2aefa3421ebc0b879e0d04c0c7ffd7f107
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-10-04 19:57:58 +00:00
Luiz Augusto von Dentz 4ab9d32bd3 unified: Don't assert if work is pending on submit
This makes k_work_submit to allow resubmits when the work is pending so
the user code don't have to check the pending flag to avoid a possible
assert.

Change-Id: Ic39f3dc5936837ce84ad028cf3d426d0558c2925
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-10-04 17:30:42 +03:00
Luiz Augusto von Dentz ee1e99b3b7 unified: Add k_work_pending
This adds k_work_pending which can be use to check if a k_work is
pending execution.

Change-Id: Ifd56e8d65d555c7e9722c547fe83e13e886d63cd
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2016-10-04 17:30:42 +03:00
Peter Mitsis 0cb65c3c0d unified: Eliminate k_mem_pool_t typedef
Replaces it with a pointer as there is no need for an opaque memory
pool type.

Jira: ZEP-916
Change-Id: I5493eed25c9c34e1b850dc3b20699864edb22d28
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-10-03 20:17:02 +00:00
Peter Mitsis 0ca7cea8f3 unified: Relocate internal thread group APIs
Moves the following internal thread group APIs from the public
kernel.h header file to the more private thread.c source file as
they do not need to be public APIs.
	_k_task_list_start[];
	_k_task_list_end[];
	_FOREACH_STATIC_THREAD()
	is_in_any_group()

Change-Id: I0b731fb0c20a5574cb1b3c1397803af82918d69d
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-10-03 20:17:02 +00:00
Benjamin Walsh 72e5a39ba7 unified: fix misc issues with APIs in kernel.h
ZEP-1022

Change-Id: I88a043cb0127631fcbb48c91504fe4fcd6ae1ecc
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-10-01 01:36:38 +00:00
Benjamin Walsh 9091e5d253 unified: use correct init macro for k_fifo objects
Was using dlist macro instead of slist macro.

ZEP-1021.

Change-Id: I374ae88289669ca03e3c0c76d33fa0229977e403
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-10-01 01:36:38 +00:00
Dmitriy Korovkin 284042d746 unified: Invoke kernel object initialization with SYS_INIT macro
Kernel object initialization needs to follow the common initialization
scheme.

Change-Id: I6693678ed7c4975b3c588061013fa0c5d24968c3
Signed-off-by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
2016-09-28 19:13:35 +00:00
Benjamin Walsh ba5ddc189e unified: implement k_uptime_{get,delta}()
Simple conversion from ticks for now.

Change-Id: Ib81fc738d45641a6a3a88d2adec1f3eb861f3f97
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-09-23 21:39:40 +00:00
Benjamin Walsh a9604bd895 unified: move basic ticks-to-ms conversion to kernel.h
The basic conversion, i.e. not handling the TICKS_UNLIMITED case, is
useful internally since the kernel is still tick-based.

Change-Id: I00a01047ec48dad6834dd8ea5dc831eb8c0c2501
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-09-23 21:39:40 +00:00
Andy Ross 8d8b2acb26 k_timer: Don't allocate dynamic timers by default
Most apps run fine with static k_timer objects.  Don't pay the cost
for the timer pool if no one asks for it.

Also turn off the allocate/free API in the header if it can't possibly
work at runtime as it's an obviously-detectable error that would
otherwise be visible only at runtime.

Change-Id: I492e6e01c4213e3544f707247eea6e4bc601fefd
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2016-09-23 18:25:37 +00:00
Benjamin Walsh 70c68b92de unified: change signature of k_sem_reset()
Does not need to return anything, since it simply resets the count.

Change-Id: I1185ea1728a9809178afa53b3dba47f7650218e2
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-09-22 21:09:44 +00:00
Benjamin Walsh 0bee91dae1 unified: fix some leftover K_<obj>_DEFINE macros
The K_<obj>_DEFINE macros in the unified kernel create objects of name
'name', and not a pointer named 'name' to an object. Some macros
contained the code from early prototyping.

Change-Id: I7262570fbe0b267012874eac0185b4e0cd7f523d
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-09-22 21:09:22 +00:00
Tomasz Bursztyka 276086da28 kernel: Fix for k_sem where counter is a unsigned int
So let the helper return the right type.

Change-Id: I850937a70fe042e42c06cb53ad736c8904221f1b
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-09-22 17:01:48 +00:00
Dmitriy Korovkin 3c426888a1 unified: Implement memory pools
Due to the memory pool structure only static declaration of
memory pool is possible.

Change-Id: I4797ed88fd2ac3b7812ff26e552e1745611c4575
Signed-off-by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
2016-09-20 22:04:46 +00:00
Peter Mitsis 45403678aa unified: Add support for semaphore groups
Semaphore groups are enabled by default. Disabling them will both
decrease the footprint as well as improve the performance of the
k_sem_give() routine.

Change-Id: If6c1b0e2e1f71afd43e620f05f17068039d12b05
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-09-20 11:45:28 -04:00
Benjamin Walsh 456c6daa9f unified: initial unified kernel implementation
Summary of what this includes:

    initialization:

    Copy from nano_init.c, with the following changes:

    - the main thread is the continuation of the init thread, but an idle
      thread is created as well

    - _main() initializes threads in groups and starts the EXE group

    - the ready queues are initialized

    - the main thread is marked as non-essential once the system init is
      done

    - a weak main() symbol is provided if the application does not provide a
      main() function

    scheduler:

    Not an exhaustive list, but basically provide primitives for:

    - adding/removing a thread to/from a wait queue
    - adding/removing a thread to/from the ready queue
    - marking thread as ready
    - locking/unlocking the scheduler
      - instead of locking interrupts
    - getting/setting thread priority
      - checking what state (coop/preempt) a thread is currenlty running in
    - rescheduling threads
    - finding what thread is the next to run
    - yielding/sleeping/aborting sleep
    - finding the current thread

    threads:

    - Add operationns on threads, such as creating and starting them.

    standardized handling of kernel object return codes:

    - Kernel objects now cause _Swap() to return the following values:
         0      => operation successful
        -EAGAIN => operation timed out
        -Exxxxx => operation failed for another reason

    - The thread's swap_data field can be used to return any additional
    information required to complete the operation, such as the actual
    result of a successful operation.

    timeouts:

    - same as nano timeouts, renamed to simply 'timeouts'
    - the kernel is still tick-based, but objects take timeout values in
      ms for forward compatibility with a tickless kernel.

    semaphores:

      - Port of the nanokernel semaphores, which have the same basic behaviour
      as the microkernel ones. Semaphore groups are not yet implemented.

      - These semaphores are enhanced in that they accept an initial count and a
      count limit. This allows configuring them as binary semaphores, and also
      provisioning them without having to "give" the semaphore multiple times
      before using them.

    mutexes:

    - Straight port of the microkernel mutexes. An init function is added to
    allow defining them at runtime.

    pipes:

    - straight port

    timers:

    - amalgamation of nano and micro timers, with all functionalities
      intact.

    events:

    - re-implementation, using semaphores and workqueues.

    mailboxes:

    - straight port

    message queues:

    - straight port of  microkernel FIFOs

    memory maps:

    - straight port

    workqueues:

    - Basically, have all APIs follow the k_ naming rule, and use the _timeout
    subsystem from the unified kernel directory, and not the _nano_timeout
    one.

    stacks:

    - Port of the nanokernel stacks. They can now have multiple threads
    pending on them and threads can wait with a timeout.

    LIFOs:

    - Straight port of the nanokernel LIFOs.

    FIFOs:

    - Straight port of the nanokernel FIFOs.

Work by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
         Peter Mitsis <peter.mitsis@windriver.com>
         Allan Stephens <allan.stephens@windriver.com>
         Benjamin Walsh <benjamin.walsh@windriver.com>

Change-Id: Id3cadb3694484ab2ca467889cfb029be3cd3a7d6
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-09-13 17:12:55 -04:00