Commit graph

692 commits

Author SHA1 Message Date
Anas Nashif a2fd7d70ec cleanup: include/: move misc/util.h to sys/util.h
move misc/util.h to sys/util.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif d222553931 cleanup: include/: move misc/speculation.h to sys/speculation.h
move misc/speculation.h to sys/speculation.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 536dd5a71f cleanup: include/: move misc/slist.h to sys/slist.h
move misc/slist.h to sys/slist.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 1859244b64 cleanup: include/: move misc/rb.h to sys/rb.h
move misc/rb.h to sys/rb.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 9ab2a56751 cleanup: include/: move misc/printk.h to sys/printk.h
move misc/printk.h to sys/printk.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 0c9e280547 cleanup: include/: move misc/mutex.h to sys/mutex.h
move misc/mutex.h to sys/mutex.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 08ee8b09ba cleanup: include/: move misc/mempool.h to sys/mempool.h
move misc/mempool.h to sys/mempool.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 1ed300b318 cleanup: include/: move misc/mempool_base.h to sys/mempool_base.h
move misc/mempool_base.h to sys/mempool_base.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 6ecadb03ab cleanup: include/: move misc/math_extras.h to sys/math_extras.h
move misc/math_extras.h to sys/math_extras.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 447311ec3e cleanup: include/: move misc/libc-hooks.h to sys/libc-hooks.h
move misc/libc-hooks.h to sys/libc-hooks.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 8be9f5de03 cleanup: include/: move misc/fdtable.h to sys/fdtable.h
move misc/fdtable.h to sys/fdtable.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 896b8d3c50 cleanup: include/: move misc/errno_private.h to sys/errno_private.h
move misc/errno_private.h to sys/errno_private.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 5eb90ec169 cleanup: include/: move misc/__assert.h to sys/__assert.h
move misc/__assert.h to sys/__assert.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 7435e5e089 cleanup: include/: move ring_buffer.h to sys/ring_buffer.h
move ring_buffer.h to sys/ring_buffer.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 9e35d53d1f cleanup: include/: move display.h to drivers/display.h
move display.h to drivers/display.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif f901e26de9 cleanup: include/: move hwinfo.h to drivers/hwinfo.h
move hwinfo.h to drivers/hwinfo.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif fe051a9055 cleanup: include/: move flash.h to drivers/flash.h
move flash.h to drivers/flash.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 0abdacf3a4 cleanup: include/: move json.h to data/json.h
move json.h to data/json.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 4e48e87fd2 cleanup: include/: move crc.h to sys/crc.h
move crc.h to sys/crc.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif bd977d06f8 cleanup: include/: move base64.h to sys/base64.h
move base64.h to sys/base64.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif e1e05a2eac cleanup: include/: move atomic.h to sys/atomic.h
move atomic.h to sys/atomic.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 656f4dfdac cleanup: include/: move fs.h to fs/fs.h
move fs.h to fs/fs.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Daniel Leung 1c5fa6a128 cmake: use sdk-ng built toolchain for x86_64
This adds the necessary bits to utilize the x86_64 toolchain
built by sdk-ng for x86_64 when toolchain variant is either
zephyr or xtools. This allows decoupling the builds from
the host toolchain.

Newlib is also available with this toolchain so remove
the Kconfig restriction on CONFIG_NEWLIB_LIBC.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2019-06-27 16:08:32 -04:00
Flavio Ceolin 2a63e342f4 libc: types: Remove wrong definition
types.h was wrongly defining unsigned as signed and following
undefining it. This definition was not being used anywhere though.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2019-06-27 07:17:04 -04:00
Ioannis Glaropoulos ff07fc7f0a lib: libc: fix alignment of HEAP base address for ARM
In ARM builds with support for user mode, i.e. with
CONFIG_USERSPACE=y, we need to align the beginning
of the heap space, to respect the ARM MPU region
alignment requirements.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-06-26 09:11:45 -04:00
Ioannis Glaropoulos 53ec19c3cc lib: libc: newlib: define USED_RAM_END_ADDR only where it is needed
USED_RAM_END_ADDR is not used when Kconfig option
CONFIG_NEWLIB_LIBC_ALIGNED_HEAP_SIZE is defined,
therefore, we do not need to define the macro in
that specific case.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-06-26 09:11:45 -04:00
Nicolas Pitre f32330b22c stdint.h: streamline type definitions
Compilers (at least gcc and clang) already provide definitions to
create standard types and their range. For example, __INT16_TYPE__ is
normally defined as a short to be used with the int16_t typedef, and
__INT16_MAX__ is defined as 32767. So it makes sense to rely on them
rather than hardcoding our own, especially for the fast types where
the compiler itself knows what basic type is best.

Using compiler provided definitions makes even more sense when dealing
with 64-bit targets where some types such as intptr_t and size_t must
have a different size and range. Those definitions are then adjusted
by the compiler directly.

However there are two cases for which we should override those
definitions:

* The __INT32_TYPE__ definition on 32-bit targets vary between an int
  and a long int depending on the architecture and configuration.
  Notably, all compilers shipped with the Zephyr SDK, except for the
  i586-zephyr-elfiamcu variant, define __INT32_TYPE__ to a long int.
  Whereas, all Linux configurations for gcc, both 32-bit and 64-bit,
  always define __INT32_TYPE__ as an int. Having variability here is
  not welcome as pointers to a long int and to an int are not deemed
  compatible by the compiler, and printing an int32_t defined with a
  long using %d makes the compiler to complain, even if they're the
  same size on 32-bit targets. Given that an int is always 32 bits
  on all targets we might care about, and given that Zephyr hardcoded
  int32_t to an int before, then we just redefine __INT32_TYPE__ and
  derrivatives to an int to keep the peace in the code.

* The confusion also exists with __INTPTR_TYPE__. Looking again at the
  Zephyr SDK, it is defined as an int, even even when __INT32_TYPE__ is
  initially a long int. One notable exception is i586-zephyr-elf where
  __INTPTR_TYPE__ is a long int even when using -m32. On 64-bit targets
  this is always a long int. So let's redefine __INTPTR_TYPE__ to always
  be a long int on Zephyr which simplifies the code, works for both
  32-bit and 64-bit targets, and mimics what the Linux kernel does.
  Only a few print format strings needed adjustment.

In those two cases, there is a safeguard to ensure the type we're
enforcing has the right size and fail the build otherwise.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-06-25 23:29:22 -04:00
Nicolas Pitre d4b60d691c malloc: no longer need to round mempool's max_sz
Since commit 465b2cf31b this value is rounded at compile time instead.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-06-25 23:24:53 -04:00
Nicolas Pitre 1140bd090c mempool: properly use the inline free block bitmap
The free block bitmap uses either extra memory specified by a pointer
in struct sys_mem_pool_lvl or the space occupied by that pointer
directly if the bitmap length is small enough to fit it.

But the test is wrong. the inline bitmap should be used if the number
of required bits is smaller or _equal_ to the pointer size. Not doing so
would wrongly bounce the free block bitmap to extra memory when the
number of blocks is exactly 32, which is in disagreement with
Z_MPOOL_LBIT_WORDS() that correctly returns 0 in that case.

In theory that mean that this bug would causes an overflow of the free
block bitmap whenever one level has exactly 32 blocks. But right now
there is a separate bug fixed separately that over-sizes the extra block
bitmap mitigating this bug.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-06-25 23:24:05 -04:00
Andy Ross d0490fe9f9 lib/os/mempool: Fix corruption case with block splitting
The block_fits() predicate was borked.  It would check that a block
fits within the bounds of the whole heap.  But that's not enough:
because of alignment changes between levels the sub-blocks may be
adjusted forward.  It needs to fit inside the PARENT block that it was
split from.

What could happen at runtime is that the last subblocks of a
misaligned parent block would overlap memory from subsequent blocks,
or even run off the end of the heap.  That's bad.

Change the API of block_fits() a little so it can extract the parent
region and do this properly.

Fixes #15279.  Passes test introduced in #16728 to demonstrate what
seems like the same issue.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-06-25 18:51:08 -07:00
Nicolas Pitre 465b2cf31b mempool: fix corruption of the free block bitmap and beyond
In z_sys_mem_pool_block_alloc() the size of the first level block
allocation is rounded up to the next 4-bite boundary. This means one
or more of the trailing blocks could overlap the free block bitmap.

Let's consider this code from kernel.h:

  #define K_MEM_POOL_DEFINE(name, minsz, maxsz, nmax, align) \
       char __aligned(align) _mpool_buf_##name[_ALIGN4(maxsz * nmax) \
                              + _MPOOL_BITS_SIZE(maxsz, minsz, nmax)]; \

The static pool allocation rounds up the product of maxsz and nmax not
size of individual blocks. If we have, say maxsz = 10 and nmax = 20,
the result of _ALIGN4(10 * 20) is 200. That's the offset at which the
free block bitmap will be located.

However, because z_sys_mem_pool_block_alloc() does this:

        lsizes[0] = _ALIGN4(p->max_sz);

Individual level 0 blocks will have a size of 12 not 10. That means
the 17th block will extend up to offset 204, 18th block up to 216, 19th
block to 228, and 20th block to 240. So 4 out of the 20 blocks are
overflowing the static pool area and 3 of them are even located
completely outside of it.

In this example, we have only 20 blocks that can't be split so there is
no extra free block bitmap allocation beyond the bitmap embedded in the
sys_mem_pool_lvl structure. This means that memory corruption will
happen in whatever data is located alongside the _mpool_buf_##name
array. But even with, say, 40 blocks, or larger blocks, the extra bitmap
size would be small compared to the extent of the overflow, and it would
get corrupted too of course.

And the data corruption will happen even without allocating any memory
since z_sys_mem_pool_base_init() stores free_list pointer nodes into
those blocks, which in turn may get corrupted if that other data is
later modified instead.

Fixing this issue is simple: rounding on the static pool allocation is
"misparenthesized". Let's turn

	_ALIGN4(maxsz * nmax)

into

	_ALIGN4(maxsz) * nmax

But that's not sufficient.

In z_sys_mem_pool_base_init() we have:

        size_t buflen = p->n_max * p->max_sz, sz = p->max_sz;
        u32_t *bits = (u32_t *)((u8_t *)p->buf + buflen);

Considering the same parameters as above, here we're locating the extra
free block bitmap at offset `buflen` which is 20 * 10 = 200, again below
the reach of the last 4 memory blocks. If the number of blocks gets past
the size of the embedded bitmap, it will overlap memory blocks.

Also, the block_ptr() call used here to initialize the free block linked
list uses unrounded p->max_sz, meaning that it is initially not locating
dlist nodes within the same block boundaries as what is expected from
z_sys_mem_pool_block_alloc(). This opens the possibility for allocated
adjacent blocks to overwrite dlist nodes, leading to random crashes in
the future.

So a complete fix must round up p->max_sz here too.

Given that runtime usage of max_sz should always be rounded up, it is
then preferable to round it up once at compile time instead and avoid
further mistakes of that sort. The existing _ALIGN4() usage on p->max_sz
at run time are then redundant.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-06-24 12:10:09 -07:00
Anas Nashif f2cb20c772 docs: fix misspelling across the tree
Found a few annoying typos and figured I better run script and
fix anything it can find, here are the results...

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-19 15:34:13 -05:00
David B. Kinder 2aebc980e2 doc: fix Kconfig misspellings
Fix misspellings in Kconfig files missed during regular reviews.

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2019-06-18 15:07:52 -04:00
Andrew Boie db84a76379 lib: os: remove dead code
If multithreading is disabled, thread_entry() never runs
since we cannot create threads; the non-multithreading case
was simply dead code.

Indicate to code coverage that CODE_UNREACHABLE should be
skipped.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-06-18 09:08:01 -04:00
Nicolas Pitre c47bf1fa5e prf.c: implement the ll length modifiers
This allows for printing long long values. Because the code size
increase may be significant, this is made optional on 32-bit targets.
On 64-bit targets this doesn't change the code much as longs and
long longs are the same size so it is always enabled in that case.

The test on MAXFLD has to be adjusted accordingly. Yet, its minimum
value wasn't large enough to store a full-scale octal value, so this
is fixed as well.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-06-17 10:58:09 -07:00
Nicolas Pitre 2b32059a61 printk: make it 64-bit compatible
On 64-bit systems the most notable difference is due to longs and
pointers being 64-bit wide. Therefore there must be a distinction
between ints and longs. Similar to the prf.c case, this patch properly
implements the h, hh, l, ll and z length modifiers as well as some small
cleanups.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-06-17 10:28:44 -07:00
Nicolas Pitre a6891e0313 prf.c: make it 64-bit compatible
On 64-bit systems the most notable difference is due to longs and
pointers being 64-bit wide. Therefore there must be a distinction
between ints and longs.

This patch:

- Make support functions take a long rather than an int as this can
  carry both longs and ints just fine.

- Use unsigned values in _to_x() to cover the full unsigned range
  and avoid sign-extending big values. Negative values are already
  converted to unsigned after printing the minus sign. This also makes
  division and modulus operations slightly faster.

- Remove excessive casts around va_arg() and use proper types with it.

- Implement the l and z length modifiers as they're significant on
  64-bit targets. While at it, throw in the z modifier as well.
  Since they all come down to 32-bit values on 32-bit targets, the
  added code should get optimized away as duplicate by the compiler
  in that case.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-06-13 12:55:17 -07:00
Nicolas Pitre 03170c040c string.c: make it 64-bit compatible
Casting a pointer to an int produces warnings with 64-bit targets.
Furthermore, an int is not always the optimal memory element that
can be copied in that case.

Let's use uintptr_t to cast pointers to integers for alignment
determination purposes, and mem_word_t to denote the optimal memory
"word" that can be copied on the platform.

The mem_word_t definition is equivalent to uintptr_t by default.
However, some 32-bit targets such as ARM platforms with the LDRD/STRD
instructions could benefit from word_t being an uint64_t.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-06-07 13:19:51 -07:00
Nicolas Pitre eeb2e67f2b time_t: define using a fixed-width type
Make sure type_t and suseconds_t keep the same size on 32-bit and
64-bit targets.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-06-06 14:22:09 -07:00
Anas Nashif 4c32258606 style: add braces around if/while statements
Per guidelines, all statements should have braces around them. We do not
have a CI check for this, so a few went in unnoticed.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-06 15:20:21 +02:00
Nicolas Pitre 4323d381e7 json: make it 64-bit compatible
The struct json_obj_descr definition allocates only 2 bits for type
alignment. Instead of using them literally minus 1 to encode 1, 2, or 4,
let's store the alignment's shift value instead so that 1, 2, 4 or 8 can
be encoded with the same 2 bits to accommodate 64-bit builds.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-06-05 07:47:41 -04:00
Christian Tavares 543de09357 lib: updatehub: add support ipv6
This extends the UpdateHub library code to allow the
use of IPV6 for communication.

Signed-off-by: Christian Tavares <christian.tavares@ossystems.com.br>
2019-06-05 00:20:37 +02:00
Christian Tavares c5d74eccda lib: updatehub: add suport a CoAPS/DTLS
This extends the UpdateHub library code to allow the
use of CoAPS/DTLS for communication.

Refs: #13039.

Signed-off-by: Christian Tavares <christian.tavares@ossystems.com.br>
2019-06-05 00:20:37 +02:00
Christian Tavares 297ac3765f lib: updatehub: Add UpdateHub.io support
UpdateHub is an enterprise-grade solution which makes simple to
remotely update all your embedded devices in the field. It
handles all aspects related to sending Firmware Over-the-Air(FOTA)
updates with maximum security and efficiency, while you focus in
adding value to your product.

Signed-off-by: Christian Tavares <christian.tavares@ossystems.com.br>
Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
2019-06-05 00:20:37 +02:00
Jan Van Winkel 539d16fca8 gui: Corrected RGB888 pointer in LVGL write function
Corrected buffer pointer in LVGL zephyr_vdb_write function for
converting RGBA8888 to RGB888 pixel format.

Signed-off-by: Jan Van Winkel <jan.van_winkel@dxplore.eu>
2019-05-30 09:33:07 -04:00
Paul Sokolovsky af529d1158 libc: minimal: Implement exit()/_exit() functions.
Behavior is similar to newlib version: print "exit" message and go
into infinite loop.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-05-23 09:27:59 -04:00
Ulf Magnusson 927012dd7f lvgl: kconfig: Remove menu and use a 'menuconfig' symbol
The 'Graphical user interface' menu currently contains just the
'LittlevGL Support' symbol and its indented children.

To remove one menu level, remove the 'Graphical user interface' menu,
rename the symbol to 'LittlevGL GUI library' (consistent with e.g.
'Logging' and 'Bluetooth'), and turn it into a 'menuconfig' symbol.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-05-21 14:19:20 -05:00
Alexander Mihajlovic f19787bb84 posix: Fix calculation of clock base in clock_settime
Previous version calculated rt_clock_base incorrectly by subtracting
clock_gettime from the specified time. Effectively the following
formula was used.

    rt_clock_base := new_time - clock_gettime()

This is clearly incorrect when we consider what should happen if we
call clock_settime with the result of clock_gettime. It ought to be
approximately a no-op, but instead we end up zeroing the clock.

    rt_clock_base := clock_gettime() - clock_gettime() = 0

This patch fixes clock_settime by instead using k_uptime_get to
calculate rt_clock_base, like so:

    rt_clock_base := new_time - k_uptime_get()

Trying the earlier thought experiment we get:

    rt_clock_base := clock_gettime() - k_uptime_get()

Using the definition of clock_gettime this expands to:

    rt_clock_base := (rt_clock_base + k_uptime_get()) - k_uptime_get()

The two k_uptime_get() terms cancel out, leaving:

    rt_clock_base := rt_clock_base

I.e. the no-op that we expect when calling clock_settime with
the result of clock_gettime.

Note: The bug is only observable when rt_clock_base is non-zero.
So when clock_settime is called for the first time, it will appear
to work correctly since rt_clock_base is initialized to 0.

Signed-off-by: Alexander Mihajlovic <alexander.mihajlovic@endian.se>
2019-05-21 08:24:59 -04:00
Benoit Leforestier 472ea92e79 Build: Build with newlib-nano c library
Add an option for building with newlib-nano library.
The newlib-nano library for ARM embedded processors is a part of the
GNU Tools for ARM Embedded Processors.
Add mem_alloc tests with newlib nano.

Signed-off-by: Benoit Leforestier <benoit.leforestier@gmail.com>
2019-05-15 10:46:44 -05:00
Jakob Olesen c8708d9bf3 misc: Replace uses of __builtin_*_overflow() with <misc/math_extras.h>.
Use the new math_extras functions instead of calling builtins directly.

Change a few local variables to size_t after checking that all uses of
the variable actually expects a size_t.

Signed-off-by: Jakob Olesen <jolesen@fb.com>
2019-05-14 19:53:30 -05:00
Wentong Wu 6922d93d8e lib/posix: correct the meaning of CONFIG_MAX_PTHREAD_COUNT
Current code implement CONFIG_MAX_PTHREAD_COUNT as the maximum number
of POSIX threads that can ever be created, rather than the maximum
number of active POSIX threads. Use pthread_state of struct posix_thread
to track the state of posix thread in posix_thread_pool so that we can
reuse the unused posix thread.

Fixes #15516.

Signed-off-by: Wentong Wu <wentong.wu@intel.com>
2019-05-11 08:24:36 -04:00
Paul Sokolovsky 81fa697f32 posix: Move gettimeofday declaration to <sys/time.h>
According to POSIX, that's the header which defines this function.
Similarly, nothing in POSIX indicates that <time.h> should have
access to struct timeval, so it's removed (it's made accessible
to <sys/time.h> via <sys/_timeval.h> introduced earlier).

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-05-07 22:18:09 -04:00
Paul Sokolovsky c896f87d5d libc: minimal: Introduce sys/_timeval.h
This is implementation-level header which defines struct timeval, and
intended to be included by headers which need this structure. This
implementation scheme is compatible with Newlib, and thus provides a
step to use minlibc vs Newlib interchangeably.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-05-07 22:18:09 -04:00
Paul Sokolovsky d79d3eb725 libc: minimal: Define time_t and suseconds_t
According to POSIX, these types should be defined by sys/types.h.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-05-07 22:18:09 -04:00
Andrew Boie 7153a2eec5 lib: cmsis_v1: set stack size larger if coverage
Use some large value, coverage targets have lots of RAM.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-05-02 15:42:33 -04:00
Andrew Boie 8502a2ea73 lib: cmsis_v2: increase stack sizes if coverage
Set to 4096, coverage targets have lots of RAM.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-05-02 15:42:33 -04:00
Andrew Boie 16317c1a9f lib: cmsis_v2: set default dynamic stack size
Set to same default as regular stacks. This doesn't use
any extra memory until CMSIS_V2_THREAD_DYNAMIC_MAX_COUNT
is set. 0 is not a valid default if that is set.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-05-02 15:42:33 -04:00
Andrew Boie b8c560a439 newlib: fix user mode calls to _sbrk
Depending on configuration, this value could end up as
a variable and not an array symbol, causing a crash if
newlib decides to call _sbrk on behalf of a user thread,
which needs to perform arithmetic on it.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-05-02 07:25:19 -04:00
Balaji Kulkarni a25dce964b libc: minimal: Add bsearch function
This function implements generic binary-search.

Fixes #15159

Signed-off-by: Balaji Kulkarni <balaji.kulkarni92@gmail.com>
2019-04-25 20:39:36 -07:00
Tomasz Gorochowik 1afa9d0e5d libc: minimal: fix realloc function
Excerpt from the manual:

  If ptr is NULL, then the call is equivalent to malloc(size) [...]

Without this commit, such calls end with a BUS FAULT.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2019-04-19 16:17:14 -04:00
Anas Nashif 3ae52624ff license: cleanup: add SPDX Apache-2.0 license identifier
Update the files which contain no license information with the
'Apache-2.0' SPDX license identifier.  Many source files in the tree are
missing licensing information, which makes it harder for compliance
tools to determine the correct license.

By default all files without license information are under the default
license of Zephyr, which is Apache version 2.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-04-07 08:45:22 -04:00
Patrik Flykt 4aa48833d8 subsystems: Rename reserved function names
Rename reserved function names in the subsys/ subdirectory except
for static _mod_pub_set and _mod_unbind functions in bluetooth mesh
cfg_srv.c which clash with the similarly named global functions.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-04-03 17:31:00 -04:00
Andrew Boie c8aee7b413 sys_mem_pool: use sys_mutex
Permission management no longer necessary, the former
parameter for the mutex is now simply ignored.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-04-03 13:47:45 -04:00
Andrew Boie f0835674a3 lib: os: add sys_mutex data type
For systems without userspace enabled, these work the same
as a k_mutex.

For systems with userspace, the sys_mutex may exist in user
memory. It is still tracked as a kernel object, but has an
underlying k_mutex that is looked up in the kernel object
table.

Future enhancements will optimize sys_mutex to not require
syscalls for uncontended sys_mutexes, using atomic ops
instead.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-04-03 13:47:45 -04:00
Pawel Dunaj 2189d9b56d lib: mempool: Alloc and break must happen atomically
This fixes a regression caused by 41e90630d.

Signed-off-by: Pawel Dunaj <pawel.dunaj@nordicsemi.no>
2019-04-03 12:36:36 -04:00
Patrik Flykt 21358baa72 all: Update unsigend 'U' suffix due to multiplication
As the multiplication rule is updated, new unsigned suffixes
are added in the code.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-03-28 17:15:58 -05:00
Patrik Flykt 24d71431e9 all: Add 'U' suffix when using unsigned variables
Add a 'U' suffix to values when computing and comparing against
unsigned variables.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-03-28 17:15:58 -05:00
Flavio Ceolin c2b25151cb lib: printk: Make if/iterations evaluate boolean operands
MISRA-C rule 14.4

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2019-03-26 22:06:45 -04:00
Flavio Ceolin 44fc55e209 lib: crc16_sw: Add missing U to unsigned constants
Add U to unsigned integer constants to avoid implicit cast.

MISRA-C rule 10.1

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2019-03-26 22:06:45 -04:00
Flavio Ceolin ce696e9aa2 lib: rb: Make operands have an appropriate essential type
MISRA-C 8.10.2 defines essential operand types and how to handle them
through rules 10.1 .. 10.5. This commit adds an U to unsigned constants
to avoid implicit casts and make if/while statements evaluate a boolean
to avoid other types being casted to boolean.

MISRA-C rules 10.1, 10.2 and 10.3

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2019-03-26 22:06:45 -04:00
Flavio Ceolin 9d5936c04f lib: posix: fs: Fix access invalid memory
fs_dirent.name is MAX_FILE_NAME + 1 bytes long, not PATH_MAX. Just
fixing it to avoid access invalid memory.

Coverity CID: 186037

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2019-03-23 09:52:51 -05:00
Vincent Wan 3609e261bb net: sockets: move fcntl back to socket_offload.c
We are reverting the changes in commit
55b3f05932 given build errors are seen
when fcntl.h is included, as it declares fcntl() as a non-static
function. The same function cannot be declared as both static and
non-static.

Instead, we avoid redefining fcntl() in lib/os/fdtable.c specifically
for case of the SimpleLink family, til we have support for the new
socket_op_vtable.

Signed-off-by: Vincent Wan <vincent.wan@linaro.org>
2019-03-20 11:36:18 -05:00
Pawel Dunaj 41e90630d7 lib: mempool: Synchronize level checks
Do not perform early level usage check. This can lead to situation
where block is seen as available on level when it was taken from
the other context.

Fixes: #14504

Signed-off-by: Pawel Dunaj <pawel.dunaj@nordicsemi.no>
2019-03-19 13:38:46 -05:00
Pawel Dunaj 2c7d68009a lib: mempool: Return error if no block found
Return -ENOMEM if no block is available on any level.

Fixes: #14504

Signed-off-by: Pawel Dunaj <pawel.dunaj@nordicsemi.no>
2019-03-19 13:38:46 -05:00
Krzysztof Chruscinski 9502b8b80b lib: os: ring_buffer: Fix not handled return value
Some function return values were not handled. Added assert in case
those functions return error. It is possible only if same ring buffer
instance is used without any protection from multiple contexts.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-03-14 08:40:18 +01:00
Ulf Magnusson 53376394b7 kconfig: Remove blank lines at the beginning/end of files
Maybe this is some "just in case" thing that got copied around. There's
no need to have a blank line at the beginning or end of Kconfig files.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-03-13 07:29:42 -05:00
Kumar Gala 7aa8e43add libc: newlib: Cleanup/fix setting of system include paths
When we build with newlib we don't set -nostdinc.  In that case make
sure that we leave it to the toolchain to set the system include paths.

The one exception to leaving to the toolchain to set the system include
paths is the path to the newlib headers.  Since we build
with -ffreestanding we need to make sure the newlib header path is the
before the toolchain headers. Otherwise the toolchain's 'freestanding'
headers get picked up and that causes issues (for example getting PRI*64
defined properly from inttypes.h due to __STDC_HOSTED__ being '0').

For newlib we accomplish this by having the only system header specified
by zephyr_system_include_directories() being just the newlib headers.

Note: for minlibc we leave things alone as things just happen to work as
the -I include of the libc headers takes precedence over -isystem so we
get the libc headers over the toolchain ones.  For the newlib case it
appears that setting both -I and -isystem for the same dir causes the
-I to be ignored.

Fixes #14310

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-03-13 06:50:23 -05:00
Maureen Helm f8c4808d96 boards: mimxrt10{50,60}_evk: Set lvgl defaults in board defconfigs
Configure lvgl defaults for imx rt boards in their respective board
defconfigs rather than the lvgl sample application.

Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
2019-03-13 06:02:42 -05:00
Kumar Gala 276f766317 libc: rename _zephyr_fputc to zephyr_fputc
For some reason we missed _zephyr_fputc in commit
4344e27c26.  Rename _zephyr_fputc to just
zephyr_fputc and fixup associated code to build.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-03-12 13:59:06 -05:00
Kumar Gala c82f23cada libc: Fix fwrite function name
Commit 4344e27c26 changed the reserved
function names, but got the naming wrong for fwrite.  Just use the
name zephyr_fwrite everywhere.

Fixes #14275

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-03-12 13:59:06 -05:00
Patrik Flykt 4344e27c26 all: Update reserved function names
Update reserved function names starting with one underscore, replacing
them as follows:
   '_k_' with 'z_'
   '_K_' with 'Z_'
   '_handler_' with 'z_handl_'
   '_Cstart' with 'z_cstart'
   '_Swap' with 'z_swap'

This renaming is done on both global and those static function names
in kernel/include and include/. Other static function names in kernel/
are renamed by removing the leading underscore. Other function names
not starting with any prefix listed above are renamed starting with
a 'z_' or 'Z_' prefix.

Function names starting with two or three leading underscores are not
automatcally renamed since these names will collide with the variants
with two or three leading underscores.

Various generator scripts have also been updated as well as perf,
linker and usb files. These are
   drivers/serial/uart_handlers.c
   include/linker/kobject-text.ld
   kernel/include/syscall_handler.h
   scripts/gen_kobject_list.py
   scripts/gen_syscall_header.py

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-03-11 13:48:42 -04:00
Andrew Boie 7416457b87 lib: fdtable: safely bounds check file descriptors
Prevent speculative attacks with out-of-bounds fd
values.

Won't affect code generation for systems that don't
enable CONFIG_BOUNDS_CHECK_BYPASS_MITIGATION.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-03-11 09:54:04 -07:00
Dennis Wildmark ce4b282717 lib: cmsis_rtos_v2: changed printformat that produced warnings
Changed the print format for unsigned 32-bit variables that produced
warnings when compiled with newlib instead of the standard C library.
Chose to replace %d with PRIu32 because the latter is more portable
and adapts to the types of the standard C libraries.
Tested with and without newlib, and with sanitycheck.

Signed-off-by: Dennis Wildmark <dennis.wildmark@assaabloy.com>
2019-03-11 11:02:20 -05:00
Ulf Magnusson da704c453f kconfig: lvgl: Remove redundant LVGL dep.
Appears within an 'if LVGL'.

'if FOO' is just shorthand for adding 'depends on FOO' to each item
within the 'if'. Dependencies on menus work similarly. There are no
"conditional includes" in Kconfig, so 'if FOO' has no special meaning
around a source. Conditional includes wouldn't be possible, because an
if condition could include (directly or indirectly) forward references
to symbols not defined yet.

Tip: When adding a symbol, check its dependencies in the menuconfig
('ninja menuconfig', then / to jump to the symbol). The menuconfig also
shows how the file with the symbol got included, so if you see
duplicated dependencies, it's easy to hunt down where they come from.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-03-09 09:48:25 -05:00
Filip Brozovic fb3d9744cc lvgl: lvgl_color_1: add support for horizontally tiled displays
Enable displays which do not have SCREEN_INFO_MONO_VTILED set to work
with LittlevGL

Signed-off-by: Filip Brozovic <fbrozovic@gmail.com>
2019-03-07 07:18:50 -05:00
Patrik Flykt e8f6ea2c8c lib/os: Remove case ranges from printk
Remove case ranges from printk in order to clean up GNUisms
and make the code standards compliant.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-03-06 17:44:04 -05:00
Anas Nashif 3caea8c81e libc: minimal: add prototype of rand()
Add prototype of rand() that can be defined in tests.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-03-04 17:32:08 -08:00
Andrew Boie 7707060959 userspace: get rid of app section placeholders
We used to leave byte-long placeholder symbols to ensure
that empty application memory sections did not cause
build errors that were very difficult to understand.

Now we use some relatively portable inline assembly to
generate a symbol, but don't take up any extra space.

The malloc and libc partitions are now only instantiated
if there is some data to put in them.

Fixes: #13923

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-03-04 08:05:16 -08:00
Tim Sørensen (TIMS) 630af8a65f misc: assert_post_action: Added __weak keyword.
Added __weak keyword to to support overriding assert_post_action().
This allows system designers to change/augment the assert behaviour,
i.e. add logging to persistant storage of program counter, line
number etc, and/or change reboot behaviour.

Signed-off-by: Tim Sørensen (TIMS) <tims@oticon.com>
2019-03-02 12:26:21 -05:00
Charles E. Youse 3522e05f76 posix/pthreads: fix pthread_barrier_wait() behavior to match Posix
Exactly one caller of pthread_barrier_wait() should receive a return
value of PTHREAD_BARRIER_SERIAL_WAIT; all others should receive zero
(or an error code). Added a test to match.

Fixes: #9953

Signed-off-by: Charles E. Youse <charles.youse@intel.com>
2019-03-02 03:40:06 +01:00
Flavio Ceolin 1556fce845 libc: ctype: Fix operations between signed and unsigned types
MISRA-C says that char type should not be used in arithmetically as the
data doesn't represent numbers.

MISRA-C rules 10.1 and 10.2

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2019-03-01 09:22:24 +01:00
Andy Ross 85d895c60e lib/os: Remove recursion from mempool and rbtree
MISRA rules (see #11425) forbid recursive algorithms.  In the case of
rb_walk(), it's not actually used anywhere but a test right now, so we
can simply disable the API when CONFIG_MISRA_SANE is defined.  Mempool
had a (IMHO, fairly clever) tail recursive loop in bfree_recombine()
which can be trivially transformed into an only slightly uglier
iterative version.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-02-28 10:06:35 -08:00
Andy Ross fe04adf99b lib/os: Conditionally eliminate alloca/VLA usage
MISRA rules (see #9892) forbid alloca() and family, even though those
features can be valuable performance and memory size optimizations
useful to Zephyr.

Introduce a MISRA_SANE kconfig, which when true enables a gcc error
condition whenever a variable length array is used.

When enabled, the mempool code will use a theoretical-maximum array
size on the stack instead of one tailored to the current pool
configuration.

The rbtree code will do similarly, but because the theoretical maximum
is quite a bit larger (236 bytes on 32 bit platforms) the array is
placed into struct rbtree instead so it can live in static data (and
also so I don't have to go and retune all the test stack sizes!).
Current code only uses at most two of these (one in the scheduler when
SCHED_SCALABLE is selected, and one for dynamic kernel objects when
USERSPACE and DYNAMIC_OBJECTS are set).

This tunable is false by default, but is selected in a single test (a
subcase of tests/kernel/common) for coverage.  Note that the I2C and
SPI subsystems contain uncorrected VLAs, so a few platforms need to be
blacklisted with a filter.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-02-28 10:06:35 -08:00
Paul Sokolovsky d01f75be7e lib: os: fdtable: Add underscore aliases for read/write/close/lseek
These get references by newlib builds in other toolchains, e.g.
gnuarmemb, and lack of them breaks linking. Tested that
tests/posix/fs and tests/posix/common actually work with these
changes.

Fixes: #13906

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-02-28 08:45:13 -06:00
Ulf Magnusson 9aab5cef96 kconfig: Remove redundant 'default n' properties
Some more were added since the cleanup pass in June 2018. See e.g.
commit 2d50da70a1 ("drivers: ipm: Kconfig: Remove redundant 'default n'
properties") for a motivation. It also avoids people wondering whether
or not they need to put in 'default n'.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-02-27 09:25:22 +01:00
Rajavardhan Gundi 60186eba8c lib: cmsis_rtos_v2: kernel: Fix a coverity issue
Fixes an issue corresponding to CID: 190641

Fixes #12292.

Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>
2019-02-27 09:23:56 +01:00
Paul Sokolovsky 4bcd560985 lib: fdtable: Update for zephyr_write() rename
_impl__zephyr_write() was renamed to _impl__zephyr_write_stdout().
This wasn't caught by CI because we didn't have POSIX tests build
for newlib, but now we have.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-02-26 14:56:58 -06:00
Paul Sokolovsky b5639c4ee2 libc: newlib: Rename adhoc read/write implementation for stdin/stdout
In case newlib is enabled, but POSIX subsys isn't, there're adhoc
implementations of read() and write() which work only with adhoc
stdin/stdout emulation layer. These are backed by system calls named
like "read" and "write". Rename all these functions and syscalls to
explicitly mention stdin/stdout in the names, to free namespace
for the implementation of generic read/write syscalls which will
integrate with POSIX fdtable.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-02-26 11:36:33 -06:00
Andrew Boie feab37096b libc: fix CONFIG_STDOUT_CONSOLE semantics
The intent of this Kconfig is to allow libc stdout
functions like printf() to send their output to the
active console driver instead of discarding it.

This somehow evolved into preferring to use
printf() instead of printk() for all test case output
if enabled. Libc printf() implementation for both
minimal libc and newlib use considerably more stack
space than printk(), with nothing gained by using
them.

Remove all instances where we are conditionally
sending test case output based on this config, enable
it by default, and adjust a few tests that disabled
this because they were blowing stack.

printk() and vprintk() now work as expected for
unit_testing targets, they are just wrappers for
host printf().

Fixes: #13701

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-02-26 08:00:33 -06:00
Anas Nashif 59841c9c67 libc: do not enable newlib on x86_64
Also, for now x86_64 does not support newlib, so do not enable newlib
for this arch until we have a solution.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-02-24 17:48:10 -05:00
Kumar Gala 6cc5722a61 lib: posix: Fix compile error with mqueue.h
With newer newlib we get a build error with mqueue.h realted to mode_t.
Let's just let newlib define mode_t and have minimal libc also define
it in sys/types.h.  So we remove the duplicated definition in
posix/unistd.h.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-02-23 11:42:31 -06:00
Andrew Boie 4ce652e4b2 userspace: remove APP_SHARED_MEM Kconfig
This is an integral part of userspace and cannot be used
on its own. Fold into the main userspace configuration.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-02-23 07:43:55 -05:00
Andrew Boie 17ce822ed9 app_shmem: create generic libc partition
We need a generic name for the partition containing
essential C library globals. We're going to need to
add the stack canary guard to this area so user mode
can read it.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-02-22 18:50:43 -05:00
Kumar Gala e96d02984c lib: posix: Fix compile issue with newer newlib
Both SDK 0.10.0-beta2 and the ARM gcc 2018q2 run into a build issue with
newlib and conflict definitions of mode_t type.

First we need to add some ifdef protection if mode_t is already defined
and set _MODE_T_DECLARED if we are the first to define it.

Secondarily, we rename include/posix/sys/types.h to
include/posix/posix_types.h so that we aren't getting a name collusion
with the system sys/types.h and that we can easily and clearily include
it (which we need to do to pull in the info from newlib).

Fixes: #12224

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-02-22 11:55:01 -06:00
Kumar Gala b730fa4ccb posix_lib: Disable support on native posix arch
For now we are disabling support for POSIX lib on native posix arch.  We
need to cleanup and support POSIX lib cleanly for hardware targets.
Once that is working properly we can look to support the feature on
native posix arch.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-02-22 11:55:01 -06:00
Anas Nashif 04743c9a79 posix: rename priority in sched_param struct
Priority member in the sched_param struct should be named
sched_priority.

Fixes #13470

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-02-19 11:24:45 -05:00
Carlos Stuart 75f77db432 include: misc: util.h: Rename min/max to MIN/MAX
There are issues using lowercase min and max macros when compiling a C++
application with a third-party toolchain such as GNU ARM Embedded when
using some STL headers i.e. <chrono>.

This is because there are actual C++ functions called min and max
defined in some of the STL headers and these macros interfere with them.
By changing the macros to UPPERCASE, which is consistent with almost all
other pre-processor macros this naming conflict is avoided.

All files that use these macros have been updated.

Signed-off-by: Carlos Stuart <carlosstuart1970@gmail.com>
2019-02-14 22:16:03 -05:00
Andy Ross ec554f44d9 kernel: Split reschdule & pend into irq/spin lock versions
Just like with _Swap(), we need two variants of these utilities which
can atomically release a lock and context switch.  The naming shifts
(for byte count reasons) to _reschedule/_pend_curr, and both have an
_irqlock variant which takes the traditional locking.

Just refactoring.  No logic changes.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-02-08 14:49:39 -05:00
Carlos Stuart f5f450eeee lib: cmsis_rtos_v2: Join and detach support
Implements osThreadJoin and osThreadDetach.

This implementation uses a semaphore to signal when a thread is
exiting so any join operations are signalled to continue. It supports
multiple join operations on a single thread, and ensures joins are
aborted if a thread is detached.

Signed-off-by: Carlos Stuart <carlosstuart1970@gmail.com>
2019-02-08 11:59:38 -05:00
Jan Van Winkel d5b71ca756 gui: Corrected typo in object realign Kconfig option
Corrected typo in lv_conf.h for object realign Kconfig option.

Signed-off-by: Jan Van Winkel <jan.van_winkel@dxplore.eu>
2019-02-08 09:35:18 -06:00
Andrew Boie 41f6011c36 userspace: remove APPLICATION_MEMORY feature
This was never a long-term solution, more of a gross hack
to get test cases working until we could figure out a good
end-to-end solution for memory domains that generated
appropriate linker sections. Now that we have this with
the app shared memory feature, and have converted all tests
to remove it, delete this feature.

To date all userspace APIs have been tagged as 'experimental'
which sidesteps deprecation policies.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-02-08 07:04:30 -05:00
Andrew Boie 4b4f773484 libc: set up memory partitions
* Newlib now defines a special z_newlib_partition containing
  all globals relevant to newlib. Most of these are in libc.a
  with a heap tracking variable in newlib's hooks.

* Both C libraries now expose a k_mem_partition containing the
  bounds of the malloc heap arena. Threads that want to use
  libc malloc() will need to add this to their memory domain.

* z_newlib_get_heap_bounds has been removed, in favor of the
  memory partition for the heap arena

* ztest now includes the C library partitions in its memory
  domain.

* The mem_alloc test now runs in user mode to prove that this
  all works for both C libraries.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-02-08 07:04:30 -05:00
Carlos Stuart 655d3cc2b0 lib: cmsis_rtos_v2: Default thread prioity
If an unitialized/zeroed optional attribute was passed to osThreadNew
the priority would be osThreadNone i.e. uninitialized. This causes an
ASSERT to be hit as the priority isn't valid (it is not between
osPriorityIdle and osPriorityISR).

The fix checks the passed in priority is not osPriorityNone and assigns
osPriorityNormal. This is the correct CMSIS behaviour.

The ASSERT will still be hit if the priority is invalid (<0).

Signed-off-by: Carlos Stuart <carlosstuart1970@gmail.com>
2019-02-06 10:20:17 -05:00
Carlos Stuart d47178bc95 lib: cmsis_rtos_v2: Default name if name is NULL
Fixed an issue whereby if an attribute structure was passed into a CMSIS
RTOS v2 'new' function with an invalid address i.e. NULL assigned to the
name (char*) member the memcpy at the end of each new function
would cause a segmentation fault i.e. read from an invalid
address.

This has been fixed by checking if the name is NULL and using the
default name from the init struct if it is. This is the same name
that would be used if not passing in the optional attr function
argument.

Changed the memcpy to strncpy to ensure that the copy does not read
beyond the end of the source string and changed the length from 16 to 15
(by means of a `sizeof(...)-1`) of the destination buffer to ensure that
it will always be nul-terminated.

Signed-off-by: Carlos Stuart <carlosstuart1970@gmail.com>
2019-02-06 10:20:17 -05:00
Carlos Stuart d4eb2c9014 lib: cmsis_rtos_v2: Dynamic thread stacks
Implemented dynamic thread stacks for CMSIS threads by declaring an
array of default sized thread stacks. Allocation cannot be done on the
heap as some architectures require strict alignment for stacks so the
macro must be used to define the stack to ensure most compatibility.

Added a Kconfig variable to limit the number of dynamic threads on the
system (they also count towards total CMSIS thread count). This is so a
developer can have fine grained control over how many dynamic threads
can be allocated because all their stacks must be allocated up front so
could use a lot of memory needlessly if oversubscribed. The default
value is 0 which effectively disabled dynamic threads but also reduces
the memory impact to almost none.

Fixed an assert bug where thread_num was being tested against the
maximum allowed CMSIS threads - it previous checked for less than or
equal which actually (due to when the increment happens) allowed there
to be one more thread. The check now correctly uses less than and only
allowed up to the defined maximum.

Signed-off-by: Carlos Stuart <carlosstuart1970@gmail.com>
2019-02-06 10:20:17 -05:00
Carlos Stuart 48320433e9 lib: cmsis_rtos_v2: Dynamic memory pools
Implemented dynamic allocation of memory pools in a similar to manner to
what was already implemented for message queues. Added all the same
checks on size vs. maximum allowed and current heap.

Added an additional Kconfig variable to define the maximum size of a
dynamically allocated memory pool.

Signed-off-by: Carlos Stuart <carlosstuart1970@gmail.com>
2019-02-06 10:20:17 -05:00
Carlos Stuart 17db516069 lib: cmsis_rtos_v2: Message queue checks
Added some additional checks when creating a message queue to ensure the
size of the queue does not exceed the size of the buffer passed in via
the optional attributes.

Added a new Kconfig option to limit the maximum size of a message queue
dynamically allocated on the heap.

Added a check to ensure the heap is at least large enough to hold a
maximum size dynamically allocated queue.

Signed-off-by: Carlos Stuart <carlosstuart1970@gmail.com>
2019-02-06 10:20:17 -05:00
Carlos Stuart 07a1a60df2 lib: cmsis_rtos_v2: Additional Kconfig dependency
Added Kconfig dependency that NUM_PREEMPT_PRIORITIES must be at least
osPriorityISR (56). This was enforced by a build assert message but not
decribed in the Kconfig.

Signed-off-by: Carlos Stuart <carlosstuart1970@gmail.com>
2019-02-06 10:20:17 -05:00
Carlos Stuart ccf51e2f50 lib: cmsis_rtos_v2: Uncrustify source files
Ran uncrustify on all library source files to ensure a compliant base to
work from.

Signed-off-by: Carlos Stuart <carlosstuart1970@gmail.com>
2019-02-06 10:20:17 -05:00
Jan Van Winkel edfd41f6de gui: Upstep LittlevGL to version 5.3
Upstep LittlevGL to version 5.3

Signed-off-by: Jan Van Winkel <vanwinkeljan@gmail.com>
2019-02-04 15:32:29 -05:00
Alberto Escolar Piedras c2699dd52d misc: assert_post_action: Treat POSIX arch like others
After #12732, 6904501173
asserts call k_panic.

Before this, the POSIX arch had its own hack in the
__ASSERT_POST implementation to terminate the process instead
of spining forever.

But the POSIX arch does implement k_panic properly, so there
is no need anymore for this hack.
=> Remove the special treatment for POSIX ARCH

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2019-02-03 10:28:51 -08:00
Krzysztof Chruscinski 6904501173 misc: Add k_panic on assert
Replaced forever loop in assert with call to a function.
In post_assert_action() function, k_panic is called.

Forever loop was preventing logs to be printed and had behavior
ependent on the context (low prioriy thread - system continue to
ork, irq - system is blocked).

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-02-02 15:58:33 -08:00
Dominik Rekawek 499feaf50e lib: posix: fix build break due to size comparsion
In limits.h PATH_MAX is defined to same value as in nffs

Signed-off-by: Dominik Rekawek <dominik@itetech.pl>
2019-02-01 23:41:09 -05:00
Kumar Gala f75ddb8dc7 gui: Fix typo in Kconfig option
CONFIG_ isn't used inside Kconfig files.  Remove use.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-02-01 19:01:16 -05:00
Anas Nashif b832a1e264 printk: move into lib/os
Last file under misc/. Put it alongside other support functions in
lib/os.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-01-22 07:45:22 -05:00
Anas Nashif db92e5c66e lib: flatten all loose components into one lib
lib/ was starting to get messy and inconsitent. Files being either
dumped in the root or in sub-directories without a clear plan.
Move all library components into one single folder and call it 'os'.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-01-22 07:45:22 -05:00
Niranjhana N 81ec05548d lib: posix: fix a wrong type in mqueue.c
mq_maxmsg and mq_msgsize are defined to be of
type long in POSIX standard. So use long for
variables that hold its value in mq_open().

Signed-off-by: Niranjhana N <niranjhana.n@intel.com>
2019-01-15 17:48:34 -05:00
Andy Ross b69d0da82d arch/x86_64: New architecture added
This patch adds a x86_64 architecture and qemu_x86_64 board to Zephyr.
Only the basic architecture support needed to run 64 bit code is
added; no drivers are added, though a low-level console exists and is
wired to printk().

The support is built on top of a "X86 underkernel" layer, which can be
built in isolation as a unit test on a Linux host.

Limitations:

+ Right now the SDK lacks an x86_64 toolchain.  The build will fall
  back to a host toolchain if it finds no cross compiler defined,
  which is tested to work on gcc 8.2.1 right now.

+ No x87/SSE/AVX usage is allowed.  This is a stronger limitation than
  other architectures where the instructions work from one thread even
  if the context switch code doesn't support it.  We are passing
  -no-sse to prevent gcc from automatically generating SSE
  instructions for non-floating-point purposes, which has the side
  effect of changing the ABI.  Future work to handle the FPU registers
  will need to be combined with an "application" ABI distinct from the
  kernel one (or just to require USERSPACE).

+ Paging is enabled (it has to be in long mode), but is a 1:1 mapping
  of all memory.  No MMU/USERSPACE support yet.

+ We are building with -mno-red-zone for stack size reasons, but this
  is a valuable optimization.  Enabling it requires automatic stack
  switching, which requires a TSS, which means it has to happen after
  MMU support.

+ The OS runs in 64 bit mode, but for compatibility reasons is
  compiled to the 32 bit "X32" ABI.  So while the full 64 bit
  registers and instruction set are available, C pointers are 32 bits
  long and Zephyr is constrained to run in the bottom 4G of memory.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-01-11 15:18:52 -05:00
Jan Van Winkel cbfcae7a1f gui: Added glue logic for LittlevGL GUI library
Added glue logic to interface Zephyr with LittlevGL GUI library

This includes:
 * KConfig options for all lvgl options
 * Kernel & user space memory management
 * Zephyr to lvgl FS call mapping
 * Color space conversion function

Signed-off-by: Jan Van Winkel <jan.van_winkel@dxplore.eu>
2019-01-07 16:05:35 -05:00
Flavio Ceolin 0c4bb833de lib: posix: Make statements evaluate boolean expressions
MISRA-C requires that the if statement has essentially Boolean type.

MISRA-C rule 14.4

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2019-01-07 08:52:07 -05:00
Flavio Ceolin 76b3518ce6 kernel: Make statements evaluate boolean expressions
MISRA-C requires that the if statement has essentially Boolean type.

MISRA-C rule 14.4

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2019-01-07 08:52:07 -05:00
Alistair Francis 41dfc4d478 libc: riscv: Fix the RISC-V ifdef
Following the standard GCC RISC-V convetion use __riscv for the RISC-V
specific define:
41d6b10e96/gcc/config/riscv/riscv-c.c (L37)

Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2019-01-03 18:15:53 -05:00
Yannis Damigos 33f1951c9d crc: Move crc7 into CRC single header
Move crc7 into CRC single header

Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
2018-12-30 16:24:10 -05:00
Michael Hope bbafc36b1c lib: add crc7.
Used as a checksum on command messages when talking with MMC cards.

Implemented using the unwound bytewise implementation from
https://en.wikipedia.org/wiki/Computation_of_cyclic_redundancy_checks
which is a good mix of size and speed.

The API and naming matches lib/crc7.c in Linux.

Signed-off-by: Michael Hope <mlhx@google.com>
2018-12-30 16:24:10 -05:00
Andy Ross 0d4954fafc lib/cmsis_rtos_v2: Fix overflow in osKernelGetInfo()
If any of the Zephyr version numbers went beyond 99, the "%2d" printf
specifiers would expand to fit and the string would run over the
memory on the stack used for os_str[].

Recent GCC versions (remember native_posix and x86_64 use the host
compiler) were actually detecting this and correctly issuing a warning
(but only if the 3-digit char value would overflow the actual array
size!), which was breaking sanitycheck for me on Fedora 28 and Ubuntu
18.04 build hosts.  Pretty impresive warning.

As it happens this was wasteful anyway; we were spending bytes on the
stack (and in rodata to store the constant which, and the cycles
needed to copy it into place on the stack where it would be
overwritten immediately) when we could just snprintf() directly into
the buffer the user gave us.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-12-26 09:41:41 -05:00
Rajavardhan Gundi 41aa164c85 lib/cmsis_rtos_v2: Implement support for Thread Flags APIs
Thread Flags are used to trigger execution states between threads.
These APIs provide functionalities like set, clear and wait.

Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>
2018-12-20 12:23:22 +01:00
Rajavardhan Gundi fa499b353d lib/cmsis_rtos_v2: Implement support for Event Flag APIs
Events are used to trigger execution states between threads.
These APIs provide functionalities like event set, clear and
wait.

Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>
2018-12-20 12:23:22 +01:00
Rajavardhan Gundi 27f4cd2356 lib/cmsis_rtos_v2: Implement support for Message Queue APIs
These APIs provide message queue functionality like create,
put and get.

Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>
2018-12-20 12:23:22 +01:00
Rajavardhan Gundi e5c848878a lib/cmsis_rtos_v2: Implement support for mempool APIs
These APIs allow creating, allocating and freeing of mempools.

Note: "Mempool" in CMSIS actually means memslabs in Zephyr.

Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>
2018-12-20 12:23:22 +01:00
Rajavardhan Gundi b39f6268c1 lib/cmsis_rtos_v2: Implement support for semaphore APIs
These APIs allow creating, acquiring, releasing and deleting
of semaphores.

Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>
2018-12-20 12:23:22 +01:00
Rajavardhan Gundi 19b57ce2e8 lib/cmsis_rtos_v2: Implement support for mutex APIs
These APIs allow creating, acquiring, releasing and deleting
the mutexes.

Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>
2018-12-20 12:23:22 +01:00
Rajavardhan Gundi 0285c69a3a lib/cmsis_rtos_v2: Implement support for timer APIs
These APIs provide the support of virtual timers. All timers
can be started, restarted, or stopped. Timers can be configured
as one-shot or periodic.

Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>
2018-12-20 12:23:22 +01:00
Rajavardhan Gundi 7d499e3471 lib/cmsis_rtos_v2: Implement support for generic wait APIs
APIs to introduce wait i.e osDelay and osDelayUntil are defined
here. They are analogous to k_sleep in the kernel.

Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>
2018-12-20 12:23:22 +01:00
Rajavardhan Gundi e3fe0cafab lib/cmsis_rtos_v2: Implement support for Kernel APIs
Implement support for Kernel management APIs like
osKernelInitialize, osKernelGetTickCount, osKernelGetSysTimerCount
etc.

Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>
2018-12-20 12:23:22 +01:00
Rajavardhan Gundi 4af7b6ccf4 lib/cmsis_rtos_v2: Implement support for thread APIs
These APIs allow defining, creating and controlling of thread
related functionalities.

Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>
2018-12-20 12:23:22 +01:00
Flavio Ceolin 17c7db6bbe lib: posix: Explicitly ignoring return of memcpy
According with MISRA-C the value returned by a non-void function has
to be used. As memcpy return is almost useless, we are explicitly
ignoring it.

MISRA-C rule 17.7

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-12-19 14:37:25 +01:00
Paul Sokolovsky 4a04ed20fd lib/fdtable: Add ioctl() and fcntl() implementations
ioctl() just dispatches to the corresponding vmethod of an fd.
fcntl() handles fdtable-level operations (so far doesn't handle
actually, returning "not implemented" error), and forwards
fd-specific operations to ioctl vmethod just the same (i.e.
ioctl and fcntl operations share the same namespace, but otherwise
disjoint).

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-12-14 13:21:31 +02:00
Paul Sokolovsky 13b38ed686 lib: fdtable: Change ioctl vmethod signature to take va_list
As extend fdtable usage to more cases, there regularly arises a need
to forward ioctl/fcntl arguments to another ioctl vmethod, which is
complicated because it defined as taking variadic arguments. The only
portable solution is to convert variadic arguments to va_list at the
first point of entry from client code, and then pass va_list around.

To facilitate calling ioctl with variadic arguments from system code,
z_fdtable_call_ioctl() helper function is added.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-12-14 13:21:31 +02:00
Robert Lubos 03df2bb888 lib: fdtable: Add function to retrieve fd vtable
Add function that allows to obtain both object and vtable of the file
descriptor.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2018-12-10 11:38:13 +02:00
Flavio Ceolin c1eee25a98 lib: rbtree: Do not use lowercase l for literal suffix
Use suffix L to remove potential ambiguity between digit 1 and letter
l.

MISRA-C rule 7.3

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-12-07 09:06:34 -05:00
Patrik Flykt 186fb94bcb lib: Add 'U' to unsigned variable assignments
Add 'U' to a value when assigning it to an unsigned variable.
MISRA-C rule 7.2

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2018-12-04 22:51:56 -05:00
Anas Nashif b8424b4cae crc: deprecate old headers and issue warning when used
Change code to use crc.h instead crc{8,16,32}.h and issue warning when
old headers are used.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-12-04 08:52:46 -06:00
Flavio Ceolin ad90341288 lib: rbtree: Make boolean functions return bool
MISRA-C rule 14.4

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-11-30 08:05:11 -08:00
Flavio Ceolin 1f176e485a libc: ctype: Fix isxdigit function
The last check was never true since 'a' > 'A'.
So, things like isxdigit(Z) would return true.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-11-29 15:28:21 -08:00
Flavio Ceolin c16b1d08df misra: Ignoring the return atomic_set when not used
The function atomic_set return the previous value of the
target. Sometimes this value is irrelevant, e.g when initializing a
variable.

As MISRA-C rule 17.7 requires that the value returned by a non-void
function must be used, we have to explicitly ignore some cases.

MISRA-C rule 17.7

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-11-29 10:18:59 -08:00
Andrew Boie 2b1d54e897 kernel: add user mode work_q capability
This allows for workqueues to be started in user mode.
No additional kernel objects or system calls are defined
other than starting the workqueue in user mode; for
permission purposes the embedded queue and thread objects
are sufficient.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2018-11-29 09:21:18 -08:00
Andy Ross 7d78122caa lib/mempool: One more spurious -ENOMEM condition
Similar to the last patch, there was a spot in block recombination
where the lock would be released while the combined block was being
held allocated.  That means that when recombining a single top-level
block, it was possible for the entire heap to look allocated.

Make the combination and re-addition of the larger block atomic.
Requires a little surgery to the structure of the code, so this is a
little more involved than the earlier fix.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-11-20 11:35:10 +01:00
Andy Ross 7845e1b01e lib/mempool: Fix spurious -ENOMEM due to agressive latency control
The mempool operations need to be atomic, but because of latency
concerns (the allocator is intended for use in an ISR) the locking was
designed to be as minimal as possible.  And it... mostly got it right.
All the list handling was correctly synchronized.  The merging of four
child blocks into a parent block was atomic.  The splitting of a block
into four children was atomic.

BUT: there was a moment between the allocation of a large block and
the re-addition of its three unused children where the lock was being
released.  This meant that another context (e.g. an ISR that just
fired, interrupting the existing call to k_mem_pool_alloc()) would see
some memory "missing" that wasn't actually allocated.  And if this
happens to have been the top level block, it's entirely possible that
the whole heap looks empty, even though the other allocator might have
been doing only the smallest allocation!

Fix that by making the "remove a block then add back the three
children we don't use" into an atomic step.  We can still relax the
lock between levels as we split the subblocks further.

(Finally, note that this trick allows a somewhat cleaner API as we can
do our "retry due to race" step internally by walking back up the
block size list instead of forcing our caller to do it via that weird
-EAGAIN return value.)

Fixes #11022

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-11-20 11:35:10 +01:00
Rajavardhan Gundi 50c0ff6e8c lib/cmsis_rtos_v1: Use k_is_in_isr instead of _is_in_isr
Use the kernel API k_is_in_isr() instead of the internal
_is_in_isr() function.

Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>
2018-11-15 09:20:57 -05:00
Andrzej Głąbek 20202902f2 dts_fixups: Use DT_ prefix in all defined labels not related to Kconfig
These changes were obtained by running a script  created by
Ulf Magnusson <Ulf.Magnusson@nordicsemi.no> for the following
specification:

1. Read the contents of all dts_fixup.h files in Zephyr
2. Check the left-hand side of the #define macros (i.e. the X in
   #define X Y)
3. Check if that name is also the name of a Kconfig option
   3.a If it is, then do nothing
   3.b If it is not, then replace CONFIG_ with DT_ or add DT_ if it
       has neither of these two prefixes
4. Replace the use of the changed #define in the code itself
   (.c, .h, .ld)

Additionally, some tweaks had to be added to this script to catch some
of the macros used in the code in a parameterized form, e.g.:
- CONFIG_GPIO_STM32_GPIO##__SUFFIX##_BASE_ADDRESS
- CONFIG_UART_##idx##_TX_PIN
- I2C_SBCON_##_num##_BASE_ADDR
and to prevent adding DT_ prefix to the following symbols:
- FLASH_START
- FLASH_SIZE
- SRAM_START
- SRAM_SIZE
- _ROM_ADDR
- _ROM_SIZE
- _RAM_ADDR
- _RAM_SIZE
which are surprisingly also defined in some dts_fixup.h files.

Finally, some manual corrections had to be done as well:
- name##_IRQ -> DT_##name##_IRQ in uart_stm32.c

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2018-11-13 10:44:42 -06:00
Paul Sokolovsky 53153405aa lib: fdtable: File descriptor table should reside in kernel memory
Private kernel data structure which should not be accessible to
userspace threads. Mark with __kernel.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-11-08 09:47:46 -08:00
Paul Sokolovsky 8f690e291b lib: fdtable: FD method tables should be const.
FD method tables contain function pointers, and thus should be
const and reside in ROM. This patch fixes all cases of FD vtable
definitions: for POSIX FS API and for sockets.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-11-08 09:47:46 -08:00
Flavio Ceolin 19301849e8 lib: Normalize if/else statements
Enforce braces in all if/else statements. This is part of MISRA-C rule
15.6.

MISRA-C rule 15.6

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-11-06 16:20:15 -05:00
Paul Sokolovsky 79ea613a32 lib/fdtable: Can call zephyr_write() only for CONFIG_NEWLIB_LIBC
If we don't have Newlib, the more or less POSIX library, it's unclear
how to deal with POSIX stdin/stdout/stderr at all.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-11-04 22:04:11 +01:00
Paul Sokolovsky 65a33bd0c0 lib: fdtable: Define standard I/O file descriptors if CONFIG_POSIX_API
This is simplistic implementation which just redirects to (likewise
simplistic) implementation in lib/libc/newlib/libc-hooks.c. This
should be replaced with bindings to "real console", but what should
be a "real console" is so far discussed, at the RFC stage.

This implementation goes into the fdtable.c itself to keep all those
things nicely static. (This is again likely will change when we have
"real console", but again, it's so far not clear where it would
belong, so at least avoid creating random files to be deleted later).

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-11-04 22:04:11 +01:00
Paul Sokolovsky b2fd1a27ac libc: newlib: libc-hooks: s/CONFIG_POSIX_FS/CONFIG_POSIX_API/
read/write/etc. are defined in case CONFIG_POSIX_API is defined, and
we shouldn't provide duplicates.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-11-04 22:04:11 +01:00
Paul Sokolovsky b6e58d54c9 lib: posix: fs: Convert to use generic fdtable
All the handling of POSIX file descriptors is now done by fdtable.c.
fs.c still manages its own table of file structures of the underlying
fs lib.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-11-04 22:04:11 +01:00
Paul Sokolovsky f484bbaa26 lib: posix: Implement generic file descriptor table
The table allows to wrap read/write (i.e. POSIX-compatible) semantics
of any I/O object in POSIX-compatible fd (file descriptor) handling.
Intended I/O objects include files, sockets, special devices, etc.

The table table itself consists of (underlying obj*, function table*)
pairs, where function table provides entries for read(), write, and
generalized ioctl(), where generalized ioctl handles all other
operations, up to and including closing of the underlying I/O object.

Fixes: #7405

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-11-04 22:04:11 +01:00
Flavio Ceolin aecd4ecb8d kernel: Change k_poll_signal api
k_poll_signal was being used by both, struct and function. Besides
this being extremely error prone it is also a MISRA-C violation.
Changing the function to contain a verb, since it performs an action
and the struct will be a noun. This pattern must be formalized and
followed and across the project.

MISRA-C rules 5.7 and 5.9

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-11-04 11:37:24 -05:00
Punit Vara 2cf270758e lib: posix: Return errno code
Return EINVAL errno when argument doesn't refer to
valid semaphore.

partly fixes #9993

Signed-off-by: Punit Vara <punit.vara@intel.com>
2018-10-31 12:15:22 -04:00
Adithya Baglody d4f6485efd lib: rbtree: Fixed incorrect return type for rb_contains
The API rb_contains computes a boolean value but returns an interger
type.

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2018-10-31 08:44:47 -04:00
Kumar Gala d37e328080 lib: mempool: Fix compile warning
Fix a compile warning if we build using int types defined to match the
compiler.  We get the following warnings:

lib/mempool/mempool.c: In function ‘sys_mem_pool_alloc’:
lib/mempool/mempool.c:317:48: warning: passing argument 3 of ‘_sys_mem_pool_block_alloc’ from incompatible pointer type [-Wincompatible-pointer-types]
  if (_sys_mem_pool_block_alloc(&p->base, size, &level, &block,
                                                ^
lib/mempool/mempool.c:221:5: note: expected ‘u32_t * {aka long unsigned int *}’ but argument is of type ‘int *’
 int _sys_mem_pool_block_alloc(struct sys_mem_pool_base *p, size_t size,
     ^~~~~~~~~~~~~~~~~~~~~~~~~
lib/mempool/mempool.c:317:56: warning: passing argument 4 of ‘_sys_mem_pool_block_alloc’ from incompatible pointer type [-Wincompatible-pointer-types]
  if (_sys_mem_pool_block_alloc(&p->base, size, &level, &block,
                                                        ^
lib/mempool/mempool.c:221:5: note: expected ‘u32_t * {aka long unsigned int *}’ but argument is of type ‘int *’
 int _sys_mem_pool_block_alloc(struct sys_mem_pool_base *p, size_t size,
     ^~~~~~~~~~~~~~~~~~~~~~~~~

Make local variables block & level u32_t to match what
_sys_mem_pool_block_alloc expects.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-10-29 10:52:00 -04:00
Kumar Gala 54bdd7aee0 Revert "libc: minimal: Add error codes for key management"
This reverts commit 25fb2302f1.

The bluetooth l2cap code was using these errno values but changed to
using more standard EPERM instead, so lets remove the defines since
nothing uses them.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-10-29 10:12:23 +00:00
Paul Sokolovsky 52aa8061c0 libc: newlib: libc-hooks: Consistently use const void* as arg to write
write() function is not supposed to change buffer passed to it, so
propagate const pointer param to all write-like functions used/defined
in this file.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-10-22 15:01:12 +01:00
Paul Sokolovsky 5955996e7a libc: minimal: fcntl.h: Fix include guards for the current path
The file was moved, but include guards still referred to the old
path.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-10-10 16:38:13 -04:00
Paul Sokolovsky c80f61a1a7 libc: minimal: Add dummy sys/stat.h [REVERTME]
Some third-party components include this file without really needing
any symbols from it. Presence of this file allows to build them
against minimal libc, whereas previously they forced Newlib.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-10-10 13:31:00 -04:00
Paul Sokolovsky 8e1d78c357 libc: minimal: Make fcntl.h be at top level, not sys/fcntl.h
Placing it at sys/fcntl.h was due to mimicking internal newlib's
layout, but what we need is this file at the standard location,
for reuse.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-10-09 15:44:59 -04:00
Krzysztof Chruscinski 26031f7bfd lib: ring_buffer: add raw byte access mode
Extended ring buffer to allow storing raw bytes in it. API has been
extended keeping 'data item' mode untouched.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-10-09 13:58:44 -04:00
Krzysztof Chruscinski ff5f00f2c3 lib: ring_buffer: Rename sys_ring_buf_ to ring_buf_item_
Deprecate API prefixed with sys_ring_buf_ and rename it
to ring_buf_item_ since this API is not a typical ring buffer
but ring buffer of data items (metadata + 32bit words).

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-10-09 13:58:44 -04:00
Paul Sokolovsky 7f9127578b include: posix: unistd: Fix prototypes and dependency
For read/write/lseek, use size_t and off_t types, as mandated by
POSIX:
http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/unistd.h.html

Also, prototypes of unistd.h functions should not depend on
CONFIG_POSIX_FS, as (many) of them deal with generic I/O, not with
files in filesystem per se.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-10-09 08:19:44 -04:00
Anas Nashif f8d439d36e kernel: move malloc handling to new logger
Make this part of the kernel log domain, it is used by the kernel.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-10-08 17:49:12 -04:00
Alexander Polleti aec8971bfd crc8: fix const correctness
Declares the array with constant data const.

Tested with tests/unit/lib/crc.

Signed-off-by: Alexander Polleti <metapsychologe@yahoo.de>
2018-10-04 16:37:21 -05:00
Rajavardhan Gundi 7fdfe03ad0 lib/cmsis_rtos_v1: Fix some Kconfig inconsistencies
Fixed some Kconfig inconsistencies around THREAD_CUSTOM_DATA,
POLL and NUM_PREEMPT_PRIORITIES.

Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>
2018-10-02 14:08:33 -07:00
Paul Sokolovsky 7e9263098a lib: posix: Build pthreads files depending on CONFIG_PTHREAD_IPC
If application didn't request pthreads support, don't build related
files.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-10-02 10:51:52 -07:00
Paul Sokolovsky 0fac0cd94a lib: posix: fs: Don't depend on pthreads
File system access isn't related to pthreads.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-10-02 10:51:52 -07:00
Paul Sokolovsky d77c96b473 lib: posix: pthread_common: Don't depend on pthreads
Contrary to its name, doesn't depend on pthreads.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-10-02 10:51:52 -07:00
Paul Sokolovsky 8dc69e09da lib: posix: Add top-level define for all POSIX APIs - CONFIG_POSIX_API
It so happened that previously CONFIG_PTHREAD_IPC served this role.
But pthreads and IPC is only parts of POSIX, orthogonal to other
services.

Move CONFIG_POSIX_FS, etc. out from CONFIG_PTHREAD_IPC.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-10-02 10:51:52 -07:00
Paul Sokolovsky c152ebd634 include: posix: Split dirent.h from unistd.h
From POSIX
http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/dirent.h.html

"""
The <dirent.h> header shall define the following type:
DIR

...

also define the structure dirent
"""

etc.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-10-02 10:51:52 -07:00
Spoorthi K df5c29d3d1 lib: POSIX: Add check for deadlock in pthread_join
Calling pthread_join() with current thread would lead
to deadlock. Adding check for it and to return
appropriate error code.

Signed-off-by: Spoorthi K <spoorthi.k@intel.com>
2018-09-29 06:01:39 -04:00
Mark Ruvald Pedersen d67096da05 portability: Avoid void* arithmetics which is a GNU extension
Under GNU C, sizeof(void) = 1. This commit merely makes it explicit u8.

Pointer arithmetics over void types is:
 * A GNU C extension
 * Not supported by Clang
 * Illegal across all ISO C standards

See also: https://gcc.gnu.org/onlinedocs/gcc/Pointer-Arith.html

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2018-09-28 07:57:28 +05:30
Niranjhana N d3ab9a37d8 lib: posix: remove return error code
ENOTSUP is not being used correctly in
pthread_attr_setschedparam(), hence
replaced its check for EINVAL instead.

Signed-off-by: Niranjhana N <niranjhana.n@intel.com>
2018-09-28 06:53:24 +05:30
Niranjhana N 7e6c103ff5 lib: posix: fix return error code
Added EAGAIN error code in pthread_create()
with fixing the EINVAL return as it is
limited to attribute checking.

Signed-off-by: Niranjhana N <niranjhana.n@intel.com>
2018-09-28 06:53:24 +05:30
Niranjhana N 482579e491 lib: posix: add error code return
Added return of ESRCH error code in
pthread_getschedparam() when the
specified thread could not be found.

Signed-off-by: Niranjhana N <niranjhana.n@intel.com>
2018-09-28 06:53:24 +05:30
Flavio Ceolin 02ed85bd82 kernel: sched: Change boolean APIs to return bool
Change APIs that essentially return a boolean expression  - 0 for
false and 1 for true - to return a bool.

MISRA-C rule 14.4

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-09-28 06:28:41 +05:30
Nils Montenegro 25fb2302f1 libc: minimal: Add error codes for key management
This adds EKEY* codes, as defined by Linux, using the same numeric
values as Linux.

Signed-off-by: Nils Montenegro <nils.montenegro@nordicsemi.no>
2018-09-26 00:55:21 +05:30
Niranjhana N 1e152ff20e lib: cmsis_rtos_v1: do null check before use
Moving a thread_def null check to top before
using the structure's elements.

Signed-off-by: Niranjhana N <niranjhana.n@intel.com>
2018-09-21 08:49:27 -04:00
Niranjhana N 4462dfabb6 lib: posix: fix couple of race conditions
Added locks around thread state accesses in
pthread_create() to avoid race conditions.

Signed-off-by: Niranjhana N <niranjhana.n@intel.com>
2018-09-21 00:24:22 -04:00
Flavio Ceolin 4218d5f8f0 kernel: Make If statement have essentially Boolean type
Make if statement using pointers explicitly check whether the value is
NULL or not.

The C standard does not say that the null pointer is the same as the
pointer to memory address 0 and because of this is a good practice
always compare with the macro NULL.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-09-18 13:57:15 -04:00
Flavio Ceolin 67ca176754 headers: Fix headers across the project
Any word started with underscore followed by and uppercase letter or a
second underscore is a reserved word according with C99.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-09-17 15:49:26 -04:00
Flavio Ceolin 98c64b6d92 kernel: Change _reschedule signature
_reschedule return's value is not used anywhere, except erroneously by
pthread_barrier_wait.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-09-14 16:55:37 -04:00
Flavio Ceolin da49f2e440 coccicnelle: Ignore return of memset
The return of memset is never checked. This patch explicitly ignore
the return to avoid MISRA-C violations.

The only directory excluded directory was ext/* since it contains
only imported code.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-09-14 16:55:37 -04:00
Paul Sokolovsky da4c00c021 libc: minimal: Add sys/fcntl.h enough to compile net/lib/sockets
Contains defines enough to compile BSD Sockets subsystem. Values are
compatible with Newlib.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-09-13 14:29:17 -04:00
David Brown 9d6f1c600f lib: posix: clock: Implement clock_settime
Set a base time, using the current uptime.

Signed-off-by: David Brown <david.brown@linaro.org>
2018-09-11 09:21:52 -04:00
David Brown 9921eb329d lib: posix: clock: Add read of CLOCK_REALTIME
Add a private variable `rt_clock_base` that can be used to determine a
real-time clock by using the `k_uptime_get` clock.  Once `clock_settime`
is added, this can allow us to have a meaningful real time clock.

Signed-off-by: David Brown <david.brown@linaro.org>
2018-09-11 09:21:52 -04:00
David Brown e0dda1b4b0 lib: posix: clock: Add gettimeofday() call
Provide an implementation of gettimeofday().  This uses clock_gettime()
with the CLOCK_REALTIME parameter, which is currently unimplemented, but
will allow clients to call this function once this functionality has
been implemented.

Signed-off-by: David Brown <david.brown@linaro.org>
2018-09-11 09:21:52 -04:00
Rajavardhan Gundi 9fed7d6338 lib/cmsis_rtos_v1: Use k_mbox_async_put instead of k_mbox_put
Use the asynchronous version of mbox_put instead of the
synchronous one. Also, add an error check in osMailPut.

Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>
2018-09-11 09:03:03 -04:00
Rajavardhan Gundi 8be1cb3b61 lib/cmsis_rtos_v1: Fix boundary conditions in the signals module
Fixed the boundary conditions around osFeature_Signals.
Fixes #9857.

Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>
2018-09-09 11:49:53 -04:00
Rajavardhan Gundi 0aa47a7c4f lib/cmsis_rtos_v1: Check for mutex owner in cmsis layer
Check for the mutex owner in the cmsis layer itself while releasing.
Fixes #9574.

Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>
2018-09-09 11:05:23 -04:00
Praful Swarnakar bbad5c3fad lib: cmsis_rtos_v1: Minor refactor of CMSIS implemetation
Add few missing NULL checks to avoid crash. Also, minor
refactor of signal code and disable osFeature_Wait to
signify osWait function not implemented.

Signed-off-by: Praful Swarnakar <praful.swarnakar@intel.com>
2018-09-03 12:45:42 -04:00
Niranjhana N a08794091f lib: cmsis_rtos_v1: remove unhit return case
k_msg_get returns only three possible values, and
osErrorValue is not in osMessageGet spec, hence
removing this unhit else case.

Signed-off-by: Niranjhana N <niranjhana.n@intel.com>
2018-08-30 01:11:08 -04:00
Rajavardhan Gundi ac787e0e97 lib/posix: Use static allocation for posix_thread objects
The memory occupied by posix_thread objects are not significant.
Hence, no point in using dynamic allocation.

Addresses #8717.

Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>
2018-08-29 15:14:05 -04:00
Spoorthi K 0b8792c05c lib/cmsis_rtos_v1: Check if osKernelStart() is called from ISR
Check if osKernelStart() is called from ISR and return error code
appropriately.

Signed-off-by: Spoorthi K <spoorthi.k@intel.com>
2018-08-28 19:19:06 -04:00
Rajavardhan Gundi f72c4c5236 lib/cmsis_rtos_v1: Remove redundant stack size check
stacksize is an unsigned integer and hence there's no need to
check whether it is >= 0 since it is always true. This fixes
the Github issue #9637.

Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>
2018-08-27 04:41:11 -07:00
Niranjhana N 845fdbb7c0 lib: cmsis_rtos_v1: replace an else case
Replace an else-if case in osSemaphoreWait with
else to account for both EBUSY and EAGAIN return
values from k_sem_take. The return value would be
0 for osSemaphoreWait in both cases.

Signed-off-by: Niranjhana N <niranjhana.n@intel.com>
2018-08-26 08:56:17 -07:00
Andy Ross 71ca65306c mempool: Fix bit pointer state for N_MAX > 31
When a mempool is created with a large number of maximum-size blocks,
the logic for initializing max_inline_level (i.e. when to union the
bitmask with the pointer and when to use the pointer directly) was
wrong.  The default state was "zero", which implies that level 0
should be inlined, but that's wrong with >32 base blocks.
Additionally, the type was unsigned, making the "level zero is a
pointer" situation impossible to represent.

Fixes #6727

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-08-25 06:57:37 -07:00
Niranjhana N 411662d344 lib: cmsis_rtos_v1: fix couple of nonconformities
Add osErrorTimeoutResource as return value when message
cannot be put in queue during waiting period. Also set
message value only when message is received.

Signed-off-by: Niranjhana N <niranjhana.n@intel.com>
2018-08-20 17:51:29 -07:00
Flavio Ceolin 5c79101f30 constants: Use uppercase to indicate long
Several code guidelines recommend using uppercase L instead of letter
l (ell) because it can easily be confused with the digit 1 (one).

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-08-16 19:47:41 -07:00
Praful Swarnakar 2fc836d2fe lib: cmsis_rtos_v1: Fix timeout calculation in signals
Fix the osSignalWait timeout calculation in cases when
waiting on more than one signal event.

Signed-off-by: Praful Swarnakar <praful.swarnakar@intel.com>
2018-08-16 06:25:10 -07:00
Ulf Magnusson 8cf8db3a73 Kconfig: Use a short, consistent style for prompts
Consistently use

    config FOO
            bool/int/hex/string "Prompt text"

instead of

    config FOO
            bool/int/hex/string
            prompt "Prompt text"

(...and a bunch of other variations that e.g. swapped the order of the
type and the 'prompt', or put other properties between them).

The shorthand is fully equivalent to using 'prompt'. It saves lines and
avoids tricking people into thinking there is some semantic difference.

Most of the grunt work was done by a modified version of
https://unix.stackexchange.com/questions/26284/
how-can-i-use-sed-to-replace-a-multi-line-string/26290#26290, but some
of the rarer variations had to be converted manually.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-08-15 04:10:10 -07:00
Rajavardhan Gundi b5df23e423 lib/cmsis_rtos_v1: Implement support for Signal Event APIs
Signals are used to trigger execution states between threads.
These APIs provide functionalities like signal set, clear and
wait.

Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>
2018-08-13 13:08:07 -07:00
Rajavardhan Gundi 3bb243c6bb lib/cmsis_rtos_v1: Implement support for Message Queue APIs
These APIs provide message queue functionality like create,
put and get.

Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>
2018-08-13 13:08:07 -07:00
Rajavardhan Gundi 7c67140baf lib/cmsis_rtos_v1: Implement support for Mail Queue APIs
These APIs provide mail queue functionality like create, put and get.

Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>
2018-08-13 13:08:07 -07:00
Rajavardhan Gundi 76fc443b1e lib/cmsis_rtos_v1: Implement support for kernel APIs
These APIs allow for checking whether the kernel is initialized,
started or running.

Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>
2018-08-13 13:08:07 -07:00
Rajavardhan Gundi aff8c51128 lib/cmsis_rtos_v1: Implement support for mempool APIs
These APIs allow creating, allocating and freeing
of mempools.

Note: "Mempool" in CMSIS actually means memslabs in Zephyr.

Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>
2018-08-13 13:08:07 -07:00
Rajavardhan Gundi 45e67150f6 lib/cmsis_rtos_v1: Implement support for semaphore APIs
These APIs allow creating, acquiring, releasing and deleting
of semaphores.

Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>
2018-08-13 13:08:07 -07:00
Rajavardhan Gundi 055da73184 lib/cmsis_rtos_v1: Implement support for mutex APIs
These APIs allow creating, acquiring, releasing and deleting
the mutexes.

Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>
2018-08-13 13:08:07 -07:00
Rajavardhan Gundi 7d3a53900a lib/cmsis_rtos_v1: Implement support for timer APIs
These APIs provide the support of virtual timers. All timers
can be started, restarted, or stopped. Timers can be configured
as one-shot or periodic.

Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>
2018-08-13 13:08:07 -07:00
Rajavardhan Gundi 7e5f0b7bff lib/cmsis_rtos_v1: Implement support for osKernelSysTick
This API is used to fetch the kernel system timer as 32-bit value.
This is analogous to k_cycle_get_32 in the kernel.

Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>
2018-08-13 13:08:07 -07:00
Rajavardhan Gundi 2d7619ecf8 lib/cmsis_rtos_v1: Implement support for osDelay
This API is used to specify delay in ms. This is analogous
to k_sleep in the kernel.

Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>
2018-08-13 13:08:07 -07:00
Rajavardhan Gundi ccd1c21824 lib/cmsis_rtos_v1: Implement support for thread APIs
These APIs allow defining, creating and controlling of thread
related functionalities.

Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>
2018-08-13 13:08:07 -07:00
Andrew Boie 3641c25df9 libc: minimal: fix calloc()
calloc() wasn't zeroing out the allocated memory as it
is supposed to.

Fixes: #9221

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2018-08-01 19:40:57 -07:00
Andrew Boie 12e6aadcb0 lib: newlib: add read/write syscalls
The read/write implementations call directly into the console drivers
using the hook mechanism, causing faults if invoked from user mode.

Add system calls for read() and write() such that we do a privilege
elevation first.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2018-07-25 14:57:51 -04:00
Andrew Boie bc94cc1832 libc: minimal: add console system calls
The stdout console implementations for minimal libc call directly into
the various console drivers (depending on what specifc hooks are
registered) causing faults when invoked from user mode. This happens,
for example, when using printf() which eventually ends up calling
fputc().

The proper solution is to ensure privileges have been elevated before
the _stdout_hook is called. This was already done for printk().

puts() and fputs() have now been re-defined in terms of the
fputc() and fwrite() functions, which are now system calls.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2018-07-25 14:57:51 -04:00
Andrew Boie 6a8649f806 libc: minimal: add malloc functions
We base the malloc() implementation on a common sys_mem_pool whose
size is specified by Kconfig.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2018-07-20 11:41:08 -07:00
Andrew Boie 7f4d006959 kernel: fix errno access for user mode
The errno "variable" is required to be thread-specific.
It gets defined to a macro which dereferences a pointer
returned by a kernel function.

In user mode, we cannot simply read/write the thread struct.
We do not have thread-local storage mechanism, so for now
use the lowest address of the thread stack to store this
value, since this is guaranteed to be read/writable by
a user thread.

The downside of this approach is potential stack corruption
if the stack pointer goes down this far but does not exceed
the location, since a fault won't be generated in this case.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2018-07-19 16:44:59 -07:00
Niranjhana N 414c39fc94 posix: add pthread_key and pthread_once APIs
Added 4 new pthread_key APIs for thread-specific data
key creation, deletion, setting and getting the values.

Added a key list to the posix_struct for threads.

Added pthread_once API.

Signed-off-by: Niranjhana N <niranjhana.n@intel.com>
2018-07-19 08:46:33 -04:00
Olivier Martin e7ae7334db lib/crc: Add CRC32 support
It only adds CRC32 IEEE support at the moment.

Signed-off-by: Olivier Martin <olivier.martin@proglove.de>
2018-07-18 10:00:12 -04:00
Kumar Gala 16ff8ca2c2 libc: newlib: Enable extended linux errno defines
We utilize defines like -ESHUTDOWN in the network stack.  To support
this errno value with newlib we need to enable
__LINUX_ERRNO_EXTENSIONS__.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-07-16 11:33:07 -05:00
Kumar Gala 9aebe8b466 lib: json: Fix warning when building with newlib
If we use newlib the isdigit (and other similar functions) return an
error as char can possibly be viewed as signed:

usr/include/ctype.h:57:54: error: array subscript has type ‘char’ [-Werror=char-subscripts]
 #define __ctype_lookup(__c) ((__ctype_ptr__+sizeof(""[__c]))[(int)(__c)])

Explicity cast to unsigned char so we deal with both this warning and
possible warning when -Wpointer-sign is enabled.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-07-12 16:01:30 -05:00
Kumar Gala e66da3f9e0 libc: minimal: Add support for %F conversion specifiers
For some reason %F wasn't supported initially.  Its simple enough to
handle the case difference in infinity and NaN handling to add support
for %F.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-07-12 14:57:52 -05:00
Kumar Gala 409c9e751f libc: minimal: Fix support for -nan
We were only handling the sign bit for infinity, but not NaN.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-07-12 14:57:52 -05:00
Kumar Gala 96ea7ab7d1 libc: minimal: Fix handling of %f conversion specifiers for inf & nan
The C standard says that %f should use '[-]inf' or '[-]infinity' (which
style is implementation defined) for infinity handling and '[-]nan' for
NaN.

We where adding a '+' and had the wrong case for 'inf' and 'nan'.

Before -> After

+INF -> inf
-INF -> -inf
 NaN -> nan

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-07-12 14:57:52 -05:00
Kumar Gala e6f4f623b7 libc: minimal: Fix handling of floating point exponent
For %{e,E,g,G} conversion specifiers the C standard says the exponent
contains at least two digits, and only as many digits are necessary.  So
instead of 1.234000e-001 we should have 1.234000e-01.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-07-12 14:57:52 -05:00
Subramanian Meenakshi Sundaram 5193b5576f lib: posix: Fix Out-of-bound write to char array
memcpy copies upto (rc-1)th index but the write of NULL character
to the string is at (rc+1)th index skipping (rc)th index.
The fix addresses this as well.

CID: 186491

Fixes Issue #8280

Signed-off-by: Subramanian Meenakshi Sundaram <subbu147@gmail.com>
2018-07-03 13:01:58 -05:00
Ulf Magnusson 0785b79ebe lib: kconfig: Remove redundant 'default n' properties
Bool symbols implicitly default to 'n'.

A 'default n' can make sense e.g. in a Kconfig.defconfig file, if you
want to override a 'default y' on the base definition of the symbol. It
isn't used like that on any of these symbols though.

Also simplify the default on STDOUT_CONSOLE. Defaults can be arbitrary
expressions, not just fixed values.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-06-22 15:12:48 -04:00
Leandro Pereira 2d71236a36 lib: libc: minimal: Get rid of the bit (256-byte) charmap table
The charmap table used by strncasecmp() not only used precious 256
bytes of ROM, it also had wrong mappings outside the ASCII range
(123..218).

Rewrite strncasecmp() to call tolower() instead; might be a tiny wee
little bit slower than the current version, but it's not used in any
performance-sensitive parts of the code to justify the waste.

This reduces the ROM footprint for the ws_echo_server sample by ~224
bytes.

Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2018-06-19 14:33:34 -07:00
Alex Tereschenko 3c1a78ea0d cmake: replace PROJECT_SOURCE_DIR with ZEPHYR_BASE
Both variables were used (with the same value) interchangeably
throughout CMake files and per the discussion in GH issue,
ZEPHYR_BASE is preferred.

Also add a comment with explanation of one vs. the other.

Tested by building hello_world for several boards ensuring no errors.

Fixes #7173.

Signed-off-by: Alex Tereschenko <alext.mkrs@gmail.com>
2018-06-18 15:25:55 -04:00
Paul Sokolovsky 6245d6c47b libc: minimal: Add typedefs for "least" types
Based on feedback integrating with TI SimpleLink HAL.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-06-18 10:23:05 -04:00
Yasushi SHOJI 2e0af08e55 build: remove unused CMakeLists.txt
lib/libc/minimal/source/CMakeLists.txt and
lib/libc/minimal/source/stdout/CMakeLists.txt was introduced in
12f8f7616 but it is not used by the build system.  CMakeLists.txt in
the parent dir lib/libc/minimal/CMakeLists.txt adds C files to the
target with the lines like:

    ${CMAKE_CURRENT_SOURCE_DIR}/source/stdlib/atoi.c
    ${CMAKE_CURRENT_SOURCE_DIR}/source/stdlib/strtol.c

To make other empty CMakeLists.txt explicit, this commit adds a
comment line to them.

Signed-off-by: Yasushi SHOJI <y-shoji@ispace-inc.com>
2018-06-14 15:02:02 -04:00
Ulf Magnusson 99cef4c60d lib: Fix malformed JSON_LIBARY Kconfig default
'default N' should have been 'default n', though they happen to have the
same effect here, due to undefined Kconfig symbols ('N') evaluating to
'n' in a boolean sense.

Kconfig bool symbols implicitly default to 'n', so remove the default
rather than fixing it.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-06-13 13:35:56 -04:00