kernel: make K_.*_INITIALIZER private to kernel

Upcoming memory protection features will be placing some additional
constraints on kernel objects:

- They need to reside in memory owned by the kernel and not the
application
- Certain kernel object validation schemes will require some run-time
initialization of all kernel objects before they can be used.

Per Ben these initializer macros were never intended to be public. It is
not forbidden to use them, but doing so requires care: the memory being
initialized must reside in kernel space, and extra runtime
initialization steps may need to be peformed before they are fully
usable as kernel objects. In particular, kernel subsystems or drivers
whose objects are already in kernel memory may still need to use these
macros if they define kernel objects as members of a larger data
structure.

It is intended that application developers instead use the
K_<object>_DEFINE macros, which will automatically put the object in the
right memory and add them to a section which can be iterated over at
boot to complete initiailization.

There was no K_WORK_DEFINE() macro for creating struct k_work objects,
this is now added.

k_poll_event and k_poll_signal are intended to be instatiated from
application memory and have not been changed.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
This commit is contained in:
Andrew Boie 2017-06-27 10:51:23 -07:00 committed by Andrew Boie
commit 65a9d2a94a
18 changed files with 119 additions and 79 deletions

View file

@ -138,7 +138,7 @@ the timer's expiry function submits a work item to the
... ...
} }
struct k_work my_work = K_WORK_INITIALIZER(my_work_handler); K_WORK_DEFINE(my_work, my_work_handler);
void my_timer_handler(struct k_timer *dummy) void my_timer_handler(struct k_timer *dummy)
{ {

View file

@ -59,7 +59,7 @@ static struct {
u8_t hdr[4]; u8_t hdr[4];
}; };
} rx = { } rx = {
.fifo = K_FIFO_INITIALIZER(rx.fifo), .fifo = _K_FIFO_INITIALIZER(rx.fifo),
}; };
static struct { static struct {
@ -67,7 +67,7 @@ static struct {
struct net_buf *buf; struct net_buf *buf;
struct k_fifo fifo; struct k_fifo fifo;
} tx = { } tx = {
.fifo = K_FIFO_INITIALIZER(tx.fifo), .fifo = _K_FIFO_INITIALIZER(tx.fifo),
}; };
static struct device *h4_dev; static struct device *h4_dev;

View file

@ -282,7 +282,7 @@ static void clear_display(struct k_timer *timer)
} }
static struct mb_display display = { static struct mb_display display = {
.timer = K_TIMER_INITIALIZER(display.timer, show_row, clear_display), .timer = _K_TIMER_INITIALIZER(display.timer, show_row, clear_display),
}; };
static void start_scroll(struct mb_display *disp, s32_t duration) static void start_scroll(struct mb_display *disp, s32_t duration)

View file

@ -41,10 +41,10 @@ struct spi_context {
}; };
#define SPI_CONTEXT_INIT_LOCK(_data, _ctx_name) \ #define SPI_CONTEXT_INIT_LOCK(_data, _ctx_name) \
._ctx_name.lock = K_SEM_INITIALIZER(_data._ctx_name.lock, 0, 1) ._ctx_name.lock = _K_SEM_INITIALIZER(_data._ctx_name.lock, 0, 1)
#define SPI_CONTEXT_INIT_SYNC(_data, _ctx_name) \ #define SPI_CONTEXT_INIT_SYNC(_data, _ctx_name) \
._ctx_name.sync = K_SEM_INITIALIZER(_data._ctx_name.sync, 0, UINT_MAX) ._ctx_name.sync = _K_SEM_INITIALIZER(_data._ctx_name.sync, 0, UINT_MAX)
static inline bool spi_context_configured(struct spi_context *ctx, static inline bool spi_context_configured(struct spi_context *ctx,
struct spi_config *config) struct spi_config *config)

View file

@ -967,7 +967,7 @@ struct k_timer {
_OBJECT_TRACING_NEXT_PTR(k_timer); _OBJECT_TRACING_NEXT_PTR(k_timer);
}; };
#define K_TIMER_INITIALIZER(obj, expiry, stop) \ #define _K_TIMER_INITIALIZER(obj, expiry, stop) \
{ \ { \
.timeout.delta_ticks_from_prev = _INACTIVE, \ .timeout.delta_ticks_from_prev = _INACTIVE, \
.timeout.wait_q = NULL, \ .timeout.wait_q = NULL, \
@ -981,6 +981,8 @@ struct k_timer {
_OBJECT_TRACING_INIT \ _OBJECT_TRACING_INIT \
} }
#define K_TIMER_INITIALIZER DEPRECATED_MACRO _K_TIMER_INITIALIZER
/** /**
* INTERNAL_HIDDEN @endcond * INTERNAL_HIDDEN @endcond
*/ */
@ -1034,7 +1036,7 @@ typedef void (*k_timer_stop_t)(struct k_timer *timer);
#define K_TIMER_DEFINE(name, expiry_fn, stop_fn) \ #define K_TIMER_DEFINE(name, expiry_fn, stop_fn) \
struct k_timer name \ struct k_timer name \
__in_section(_k_timer, static, name) = \ __in_section(_k_timer, static, name) = \
K_TIMER_INITIALIZER(name, expiry_fn, stop_fn) _K_TIMER_INITIALIZER(name, expiry_fn, stop_fn)
/** /**
* @brief Initialize a timer. * @brief Initialize a timer.
@ -1297,7 +1299,7 @@ struct k_queue {
_OBJECT_TRACING_NEXT_PTR(k_queue); _OBJECT_TRACING_NEXT_PTR(k_queue);
}; };
#define K_QUEUE_INITIALIZER(obj) \ #define _K_QUEUE_INITIALIZER(obj) \
{ \ { \
.wait_q = SYS_DLIST_STATIC_INIT(&obj.wait_q), \ .wait_q = SYS_DLIST_STATIC_INIT(&obj.wait_q), \
.data_q = SYS_SLIST_STATIC_INIT(&obj.data_q), \ .data_q = SYS_SLIST_STATIC_INIT(&obj.data_q), \
@ -1305,6 +1307,8 @@ struct k_queue {
_OBJECT_TRACING_INIT \ _OBJECT_TRACING_INIT \
} }
#define K_QUEUE_INITIALIZER DEPRECATED_MACRO _K_QUEUE_INITIALIZER
/** /**
* INTERNAL_HIDDEN @endcond * INTERNAL_HIDDEN @endcond
*/ */
@ -1498,7 +1502,7 @@ static inline void *k_queue_peek_tail(struct k_queue *queue)
#define K_QUEUE_DEFINE(name) \ #define K_QUEUE_DEFINE(name) \
struct k_queue name \ struct k_queue name \
__in_section(_k_queue, static, name) = \ __in_section(_k_queue, static, name) = \
K_QUEUE_INITIALIZER(name) _K_QUEUE_INITIALIZER(name)
/** /**
* @} end defgroup queue_apis * @} end defgroup queue_apis
@ -1512,11 +1516,13 @@ struct k_fifo {
struct k_queue _queue; struct k_queue _queue;
}; };
#define K_FIFO_INITIALIZER(obj) \ #define _K_FIFO_INITIALIZER(obj) \
{ \ { \
._queue = K_QUEUE_INITIALIZER(obj._queue) \ ._queue = _K_QUEUE_INITIALIZER(obj._queue) \
} }
#define K_FIFO_INITIALIZER DEPRECATED_MACRO _K_FIFO_INITIALIZER
/** /**
* INTERNAL_HIDDEN @endcond * INTERNAL_HIDDEN @endcond
*/ */
@ -1685,7 +1691,7 @@ struct k_fifo {
#define K_FIFO_DEFINE(name) \ #define K_FIFO_DEFINE(name) \
struct k_fifo name \ struct k_fifo name \
__in_section(_k_queue, static, name) = \ __in_section(_k_queue, static, name) = \
K_FIFO_INITIALIZER(name) _K_FIFO_INITIALIZER(name)
/** /**
* @} end defgroup fifo_apis * @} end defgroup fifo_apis
@ -1699,11 +1705,13 @@ struct k_lifo {
struct k_queue _queue; struct k_queue _queue;
}; };
#define K_LIFO_INITIALIZER(obj) \ #define _K_LIFO_INITIALIZER(obj) \
{ \ { \
._queue = K_QUEUE_INITIALIZER(obj._queue) \ ._queue = _K_QUEUE_INITIALIZER(obj._queue) \
} }
#define K_LIFO_INITIALIZER DEPRECATED_MACRO _K_LIFO_INITIALIZER
/** /**
* INTERNAL_HIDDEN @endcond * INTERNAL_HIDDEN @endcond
*/ */
@ -1773,7 +1781,7 @@ struct k_lifo {
#define K_LIFO_DEFINE(name) \ #define K_LIFO_DEFINE(name) \
struct k_lifo name \ struct k_lifo name \
__in_section(_k_queue, static, name) = \ __in_section(_k_queue, static, name) = \
K_LIFO_INITIALIZER(name) _K_LIFO_INITIALIZER(name)
/** /**
* @} end defgroup lifo_apis * @} end defgroup lifo_apis
@ -1790,7 +1798,7 @@ struct k_stack {
_OBJECT_TRACING_NEXT_PTR(k_stack); _OBJECT_TRACING_NEXT_PTR(k_stack);
}; };
#define K_STACK_INITIALIZER(obj, stack_buffer, stack_num_entries) \ #define _K_STACK_INITIALIZER(obj, stack_buffer, stack_num_entries) \
{ \ { \
.wait_q = SYS_DLIST_STATIC_INIT(&obj.wait_q), \ .wait_q = SYS_DLIST_STATIC_INIT(&obj.wait_q), \
.base = stack_buffer, \ .base = stack_buffer, \
@ -1799,6 +1807,8 @@ struct k_stack {
_OBJECT_TRACING_INIT \ _OBJECT_TRACING_INIT \
} }
#define K_STACK_INITIALIZER DEPRECATED_MACRO _K_STACK_INITIALIZER
/** /**
* INTERNAL_HIDDEN @endcond * INTERNAL_HIDDEN @endcond
*/ */
@ -1871,7 +1881,7 @@ extern int k_stack_pop(struct k_stack *stack, u32_t *data, s32_t timeout);
_k_stack_buf_##name[stack_num_entries]; \ _k_stack_buf_##name[stack_num_entries]; \
struct k_stack name \ struct k_stack name \
__in_section(_k_stack, static, name) = \ __in_section(_k_stack, static, name) = \
K_STACK_INITIALIZER(name, _k_stack_buf_##name, \ _K_STACK_INITIALIZER(name, _k_stack_buf_##name, \
stack_num_entries) stack_num_entries)
/** /**
@ -1930,22 +1940,30 @@ extern struct k_work_q k_sys_work_q;
* INTERNAL_HIDDEN @endcond * INTERNAL_HIDDEN @endcond
*/ */
#define _K_WORK_INITIALIZER(work_handler) \
{ \
._reserved = NULL, \
.handler = work_handler, \
.flags = { 0 } \
}
#define K_WORK_INITIALIZER DEPRECATED_MACRO _K_WORK_INITIALIZER
/** /**
* @brief Initialize a statically-defined work item. * @brief Initialize a statically-defined work item.
* *
* This macro can be used to initialize a statically-defined workqueue work * This macro can be used to initialize a statically-defined workqueue work
* item, prior to its first use. For example, * item, prior to its first use. For example,
* *
* @code struct k_work <work> = K_WORK_INITIALIZER(<work_handler>); @endcode * @code static K_WORK_DEFINE(<work>, <work_handler>); @endcode
* *
* @param work Symbol name for work item object
* @param work_handler Function to invoke each time work item is processed. * @param work_handler Function to invoke each time work item is processed.
*/ */
#define K_WORK_INITIALIZER(work_handler) \ #define K_WORK_DEFINE(work, work_handler) \
{ \ struct k_work work \
._reserved = NULL, \ __in_section(_k_work, static, work) = \
.handler = work_handler, \ _K_WORK_INITIALIZER(work_handler)
.flags = { 0 } \
}
/** /**
* @brief Initialize a work item. * @brief Initialize a work item.
@ -2192,7 +2210,7 @@ struct k_mutex {
_OBJECT_TRACING_NEXT_PTR(k_mutex); _OBJECT_TRACING_NEXT_PTR(k_mutex);
}; };
#define K_MUTEX_INITIALIZER(obj) \ #define _K_MUTEX_INITIALIZER(obj) \
{ \ { \
.wait_q = SYS_DLIST_STATIC_INIT(&obj.wait_q), \ .wait_q = SYS_DLIST_STATIC_INIT(&obj.wait_q), \
.owner = NULL, \ .owner = NULL, \
@ -2201,6 +2219,8 @@ struct k_mutex {
_OBJECT_TRACING_INIT \ _OBJECT_TRACING_INIT \
} }
#define K_MUTEX_INITIALIZER DEPRECATED_MACRO _K_MUTEX_INITIALIZER
/** /**
* INTERNAL_HIDDEN @endcond * INTERNAL_HIDDEN @endcond
*/ */
@ -2223,7 +2243,7 @@ struct k_mutex {
#define K_MUTEX_DEFINE(name) \ #define K_MUTEX_DEFINE(name) \
struct k_mutex name \ struct k_mutex name \
__in_section(_k_mutex, static, name) = \ __in_section(_k_mutex, static, name) = \
K_MUTEX_INITIALIZER(name) _K_MUTEX_INITIALIZER(name)
/** /**
* @brief Initialize a mutex. * @brief Initialize a mutex.
@ -2291,7 +2311,7 @@ struct k_sem {
_OBJECT_TRACING_NEXT_PTR(k_sem); _OBJECT_TRACING_NEXT_PTR(k_sem);
}; };
#define K_SEM_INITIALIZER(obj, initial_count, count_limit) \ #define _K_SEM_INITIALIZER(obj, initial_count, count_limit) \
{ \ { \
.wait_q = SYS_DLIST_STATIC_INIT(&obj.wait_q), \ .wait_q = SYS_DLIST_STATIC_INIT(&obj.wait_q), \
.count = initial_count, \ .count = initial_count, \
@ -2300,6 +2320,8 @@ struct k_sem {
_OBJECT_TRACING_INIT \ _OBJECT_TRACING_INIT \
} }
#define K_SEM_INITIALIZER DEPRECATED_MACRO _K_SEM_INITIALIZER
/** /**
* INTERNAL_HIDDEN @endcond * INTERNAL_HIDDEN @endcond
*/ */
@ -2403,7 +2425,7 @@ static inline unsigned int k_sem_count_get(struct k_sem *sem)
#define K_SEM_DEFINE(name, initial_count, count_limit) \ #define K_SEM_DEFINE(name, initial_count, count_limit) \
struct k_sem name \ struct k_sem name \
__in_section(_k_sem, static, name) = \ __in_section(_k_sem, static, name) = \
K_SEM_INITIALIZER(name, initial_count, count_limit) _K_SEM_INITIALIZER(name, initial_count, count_limit)
/** /**
* @} end defgroup semaphore_apis * @} end defgroup semaphore_apis
@ -2451,15 +2473,17 @@ struct k_alert {
extern void _alert_deliver(struct k_work *work); extern void _alert_deliver(struct k_work *work);
#define K_ALERT_INITIALIZER(obj, alert_handler, max_num_pending_alerts) \ #define _K_ALERT_INITIALIZER(obj, alert_handler, max_num_pending_alerts) \
{ \ { \
.handler = (k_alert_handler_t)alert_handler, \ .handler = (k_alert_handler_t)alert_handler, \
.send_count = ATOMIC_INIT(0), \ .send_count = ATOMIC_INIT(0), \
.work_item = K_WORK_INITIALIZER(_alert_deliver), \ .work_item = _K_WORK_INITIALIZER(_alert_deliver), \
.sem = K_SEM_INITIALIZER(obj.sem, 0, max_num_pending_alerts), \ .sem = _K_SEM_INITIALIZER(obj.sem, 0, max_num_pending_alerts), \
_OBJECT_TRACING_INIT \ _OBJECT_TRACING_INIT \
} }
#define K_ALERT_INITIALIZER DEPRECATED_MACRO _K_ALERT_INITIALIZER
/** /**
* INTERNAL_HIDDEN @endcond * INTERNAL_HIDDEN @endcond
*/ */
@ -2486,7 +2510,7 @@ extern void _alert_deliver(struct k_work *work);
#define K_ALERT_DEFINE(name, alert_handler, max_num_pending_alerts) \ #define K_ALERT_DEFINE(name, alert_handler, max_num_pending_alerts) \
struct k_alert name \ struct k_alert name \
__in_section(_k_alert, static, name) = \ __in_section(_k_alert, static, name) = \
K_ALERT_INITIALIZER(name, alert_handler, \ _K_ALERT_INITIALIZER(name, alert_handler, \
max_num_pending_alerts) max_num_pending_alerts)
/** /**
@ -2560,7 +2584,7 @@ struct k_msgq {
_OBJECT_TRACING_NEXT_PTR(k_msgq); _OBJECT_TRACING_NEXT_PTR(k_msgq);
}; };
#define K_MSGQ_INITIALIZER(obj, q_buffer, q_msg_size, q_max_msgs) \ #define _K_MSGQ_INITIALIZER(obj, q_buffer, q_msg_size, q_max_msgs) \
{ \ { \
.wait_q = SYS_DLIST_STATIC_INIT(&obj.wait_q), \ .wait_q = SYS_DLIST_STATIC_INIT(&obj.wait_q), \
.max_msgs = q_max_msgs, \ .max_msgs = q_max_msgs, \
@ -2573,6 +2597,8 @@ struct k_msgq {
_OBJECT_TRACING_INIT \ _OBJECT_TRACING_INIT \
} }
#define K_MSGQ_INITIALIZER DEPRECATED_MACRO _K_MSGQ_INITIALIZER
/** /**
* INTERNAL_HIDDEN @endcond * INTERNAL_HIDDEN @endcond
*/ */
@ -2607,7 +2633,7 @@ struct k_msgq {
_k_fifo_buf_##q_name[(q_max_msgs) * (q_msg_size)]; \ _k_fifo_buf_##q_name[(q_max_msgs) * (q_msg_size)]; \
struct k_msgq q_name \ struct k_msgq q_name \
__in_section(_k_msgq, static, q_name) = \ __in_section(_k_msgq, static, q_name) = \
K_MSGQ_INITIALIZER(q_name, _k_fifo_buf_##q_name, \ _K_MSGQ_INITIALIZER(q_name, _k_fifo_buf_##q_name, \
q_msg_size, q_max_msgs) q_msg_size, q_max_msgs)
/** /**
@ -2782,13 +2808,15 @@ struct k_mbox {
_OBJECT_TRACING_NEXT_PTR(k_mbox); _OBJECT_TRACING_NEXT_PTR(k_mbox);
}; };
#define K_MBOX_INITIALIZER(obj) \ #define _K_MBOX_INITIALIZER(obj) \
{ \ { \
.tx_msg_queue = SYS_DLIST_STATIC_INIT(&obj.tx_msg_queue), \ .tx_msg_queue = SYS_DLIST_STATIC_INIT(&obj.tx_msg_queue), \
.rx_msg_queue = SYS_DLIST_STATIC_INIT(&obj.rx_msg_queue), \ .rx_msg_queue = SYS_DLIST_STATIC_INIT(&obj.rx_msg_queue), \
_OBJECT_TRACING_INIT \ _OBJECT_TRACING_INIT \
} }
#define K_MBOX_INITIALIZER DEPRECATED_MACRO _K_MBOX_INITIALIZER
/** /**
* INTERNAL_HIDDEN @endcond * INTERNAL_HIDDEN @endcond
*/ */
@ -2805,7 +2833,7 @@ struct k_mbox {
#define K_MBOX_DEFINE(name) \ #define K_MBOX_DEFINE(name) \
struct k_mbox name \ struct k_mbox name \
__in_section(_k_mbox, static, name) = \ __in_section(_k_mbox, static, name) = \
K_MBOX_INITIALIZER(name) \ _K_MBOX_INITIALIZER(name) \
/** /**
* @brief Initialize a mailbox. * @brief Initialize a mailbox.
@ -2953,7 +2981,7 @@ struct k_pipe {
_OBJECT_TRACING_NEXT_PTR(k_pipe); _OBJECT_TRACING_NEXT_PTR(k_pipe);
}; };
#define K_PIPE_INITIALIZER(obj, pipe_buffer, pipe_buffer_size) \ #define _K_PIPE_INITIALIZER(obj, pipe_buffer, pipe_buffer_size) \
{ \ { \
.buffer = pipe_buffer, \ .buffer = pipe_buffer, \
.size = pipe_buffer_size, \ .size = pipe_buffer_size, \
@ -2965,6 +2993,8 @@ struct k_pipe {
_OBJECT_TRACING_INIT \ _OBJECT_TRACING_INIT \
} }
#define K_PIPE_INITIALIZER DEPRECATED_MACRO _K_PIPE_INITIALIZER
/** /**
* INTERNAL_HIDDEN @endcond * INTERNAL_HIDDEN @endcond
*/ */
@ -2992,7 +3022,7 @@ struct k_pipe {
_k_pipe_buf_##name[pipe_buffer_size]; \ _k_pipe_buf_##name[pipe_buffer_size]; \
struct k_pipe name \ struct k_pipe name \
__in_section(_k_pipe, static, name) = \ __in_section(_k_pipe, static, name) = \
K_PIPE_INITIALIZER(name, _k_pipe_buf_##name, pipe_buffer_size) _K_PIPE_INITIALIZER(name, _k_pipe_buf_##name, pipe_buffer_size)
/** /**
* @brief Initialize a pipe. * @brief Initialize a pipe.
@ -3092,7 +3122,7 @@ struct k_mem_slab {
_OBJECT_TRACING_NEXT_PTR(k_mem_slab); _OBJECT_TRACING_NEXT_PTR(k_mem_slab);
}; };
#define K_MEM_SLAB_INITIALIZER(obj, slab_buffer, slab_block_size, \ #define _K_MEM_SLAB_INITIALIZER(obj, slab_buffer, slab_block_size, \
slab_num_blocks) \ slab_num_blocks) \
{ \ { \
.wait_q = SYS_DLIST_STATIC_INIT(&obj.wait_q), \ .wait_q = SYS_DLIST_STATIC_INIT(&obj.wait_q), \
@ -3104,6 +3134,9 @@ struct k_mem_slab {
_OBJECT_TRACING_INIT \ _OBJECT_TRACING_INIT \
} }
#define K_MEM_SLAB_INITIALIZER DEPRECATED_MACRO _K_MEM_SLAB_INITIALIZER
/** /**
* INTERNAL_HIDDEN @endcond * INTERNAL_HIDDEN @endcond
*/ */
@ -3138,7 +3171,7 @@ struct k_mem_slab {
_k_mem_slab_buf_##name[(slab_num_blocks) * (slab_block_size)]; \ _k_mem_slab_buf_##name[(slab_num_blocks) * (slab_block_size)]; \
struct k_mem_slab name \ struct k_mem_slab name \
__in_section(_k_mem_slab, static, name) = \ __in_section(_k_mem_slab, static, name) = \
K_MEM_SLAB_INITIALIZER(name, _k_mem_slab_buf_##name, \ _K_MEM_SLAB_INITIALIZER(name, _k_mem_slab_buf_##name, \
slab_block_size, slab_num_blocks) slab_block_size, slab_num_blocks)
/** /**

View file

@ -100,6 +100,13 @@
_k_pipe_list_end = .; _k_pipe_list_end = .;
} GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION) } GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION)
SECTION_DATA_PROLOGUE(_k_work_area, (OPTIONAL),)
{
_k_work_list_start = .;
KEEP(*(SORT_BY_NAME("._k_work.static.*")))
_k_work_list_end = .;
} GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION)
SECTION_DATA_PROLOGUE(_k_task_list, (OPTIONAL),) SECTION_DATA_PROLOGUE(_k_task_list, (OPTIONAL),)
{ {
_k_task_list_start = .; _k_task_list_start = .;

View file

@ -480,7 +480,7 @@ struct net_buf_pool {
#define NET_BUF_POOL_INITIALIZER(_pool, _bufs, _count, _size, _ud_size, \ #define NET_BUF_POOL_INITIALIZER(_pool, _bufs, _count, _size, _ud_size, \
_destroy) \ _destroy) \
{ \ { \
.free = K_LIFO_INITIALIZER(_pool.free), \ .free = _K_LIFO_INITIALIZER(_pool.free), \
.__bufs = (struct net_buf *)_bufs, \ .__bufs = (struct net_buf *)_bufs, \
.buf_count = _count, \ .buf_count = _count, \
.uninit_count = _count, \ .uninit_count = _count, \
@ -495,7 +495,7 @@ struct net_buf_pool {
#define NET_BUF_POOL_INITIALIZER(_pool, _bufs, _count, _size, _ud_size, \ #define NET_BUF_POOL_INITIALIZER(_pool, _bufs, _count, _size, _ud_size, \
_destroy) \ _destroy) \
{ \ { \
.free = K_LIFO_INITIALIZER(_pool.free), \ .free = _K_LIFO_INITIALIZER(_pool.free), \
.__bufs = (struct net_buf *)_bufs, \ .__bufs = (struct net_buf *)_bufs, \
.buf_count = _count, \ .buf_count = _count, \
.uninit_count = _count, \ .uninit_count = _count, \

View file

@ -66,7 +66,7 @@ void k_alert_init(struct k_alert *alert, k_alert_handler_t handler,
{ {
alert->handler = handler; alert->handler = handler;
alert->send_count = ATOMIC_INIT(0); alert->send_count = ATOMIC_INIT(0);
alert->work_item = (struct k_work)K_WORK_INITIALIZER(_alert_deliver); alert->work_item = (struct k_work)_K_WORK_INITIALIZER(_alert_deliver);
k_sem_init(&alert->sem, 0, max_num_pending_alerts); k_sem_init(&alert->sem, 0, max_num_pending_alerts);
SYS_TRACING_OBJ_INIT(k_alert, alert); SYS_TRACING_OBJ_INIT(k_alert, alert);
} }

View file

@ -90,7 +90,7 @@ static s64_t ended;
static struct k_delayed_work refresh; static struct k_delayed_work refresh;
/* Semaphore to indicate that there was an update to the display */ /* Semaphore to indicate that there was an update to the display */
static struct k_sem disp_update = K_SEM_INITIALIZER(disp_update, 0, 1); static K_SEM_DEFINE(disp_update, 0, 1);
/* X coordinate of the left corner of the paddle */ /* X coordinate of the left corner of the paddle */
static volatile int paddle_x = PADDLE_MIN; static volatile int paddle_x = PADDLE_MIN;

View file

@ -849,7 +849,7 @@ on_msg_rcvd(void *data, struct zirc_chan *chan, char *umask, char *msg)
#define DHCPV4_TIMEOUT K_SECONDS(30) #define DHCPV4_TIMEOUT K_SECONDS(30)
static struct net_mgmt_event_callback mgmt4_cb; static struct net_mgmt_event_callback mgmt4_cb;
static struct k_sem dhcpv4_ok = K_SEM_INITIALIZER(dhcpv4_ok, 0, UINT_MAX); static K_SEM_DEFINE(dhcpv4_ok, 0, UINT_MAX);
static void ipv4_addr_add_handler(struct net_mgmt_event_callback *cb, static void ipv4_addr_add_handler(struct net_mgmt_event_callback *cb,
u32_t mgmt_event, u32_t mgmt_event,
@ -945,7 +945,7 @@ static void setup_ipv4(struct zirc *irc, struct net_if *iface)
#define DAD_TIMEOUT K_SECONDS(3) #define DAD_TIMEOUT K_SECONDS(3)
static struct net_mgmt_event_callback mgmt6_cb; static struct net_mgmt_event_callback mgmt6_cb;
static struct k_sem dad_ok = K_SEM_INITIALIZER(dad_ok, 0, UINT_MAX); static K_SEM_DEFINE(dad_ok, 0, UINT_MAX);
static struct in6_addr laddr; static struct in6_addr laddr;
static void ipv6_dad_ok_handler(struct net_mgmt_event_callback *cb, static void ipv6_dad_ok_handler(struct net_mgmt_event_callback *cb,

View file

@ -470,7 +470,7 @@ class SizeCalculator:
alloc_sections = ["bss", "noinit", "app_bss", "app_noinit"] alloc_sections = ["bss", "noinit", "app_bss", "app_noinit"]
rw_sections = ["datas", "initlevel", "_k_task_list", "_k_event_list", rw_sections = ["datas", "initlevel", "_k_task_list", "_k_event_list",
"_k_memory_pool", "exceptions", "initshell", "_k_memory_pool", "exceptions", "initshell",
"_static_thread_area", "_k_timer_area", "_static_thread_area", "_k_timer_area", "_k_work_area",
"_k_mem_slab_area", "_k_mem_pool_area", "_k_mem_slab_area", "_k_mem_pool_area",
"_k_sem_area", "_k_mutex_area", "_k_alert_area", "_k_sem_area", "_k_mutex_area", "_k_alert_area",
"_k_fifo_area", "_k_lifo_area", "_k_stack_area", "_k_fifo_area", "_k_lifo_area", "_k_stack_area",

View file

@ -135,7 +135,7 @@ void bt_gatt_init(void)
gatt_register(&gatt_svc); gatt_register(&gatt_svc);
} }
static struct k_sem sc_sem = K_SEM_INITIALIZER(sc_sem, 1, 1); static struct k_sem sc_sem = _K_SEM_INITIALIZER(sc_sem, 1, 1);
static void sc_indicate_rsp(struct bt_conn *conn, static void sc_indicate_rsp(struct bt_conn *conn,
const struct bt_gatt_attr *attr, u8_t err) const struct bt_gatt_attr *attr, u8_t err)

View file

@ -58,19 +58,19 @@ static BT_STACK_NOINIT(tx_thread_stack, CONFIG_BLUETOOTH_HCI_TX_STACK_SIZE);
static void init_work(struct k_work *work); static void init_work(struct k_work *work);
struct bt_dev bt_dev = { struct bt_dev bt_dev = {
.init = K_WORK_INITIALIZER(init_work), .init = _K_WORK_INITIALIZER(init_work),
/* Give cmd_sem allowing to send first HCI_Reset cmd, the only /* Give cmd_sem allowing to send first HCI_Reset cmd, the only
* exception is if the controller requests to wait for an * exception is if the controller requests to wait for an
* initial Command Complete for NOP. * initial Command Complete for NOP.
*/ */
#if !defined(CONFIG_BLUETOOTH_WAIT_NOP) #if !defined(CONFIG_BLUETOOTH_WAIT_NOP)
.ncmd_sem = K_SEM_INITIALIZER(bt_dev.ncmd_sem, 1, 1), .ncmd_sem = _K_SEM_INITIALIZER(bt_dev.ncmd_sem, 1, 1),
#else #else
.ncmd_sem = K_SEM_INITIALIZER(bt_dev.ncmd_sem, 0, 1), .ncmd_sem = _K_SEM_INITIALIZER(bt_dev.ncmd_sem, 0, 1),
#endif #endif
.cmd_tx_queue = K_FIFO_INITIALIZER(bt_dev.cmd_tx_queue), .cmd_tx_queue = _K_FIFO_INITIALIZER(bt_dev.cmd_tx_queue),
#if !defined(CONFIG_BLUETOOTH_RECV_IS_RX_THREAD) #if !defined(CONFIG_BLUETOOTH_RECV_IS_RX_THREAD)
.rx_queue = K_FIFO_INITIALIZER(bt_dev.rx_queue), .rx_queue = _K_FIFO_INITIALIZER(bt_dev.rx_queue),
#endif #endif
}; };

View file

@ -200,7 +200,7 @@ static int mgmt_event_wait_call(struct net_if *iface,
int timeout) int timeout)
{ {
struct mgmt_event_wait sync_data = { struct mgmt_event_wait sync_data = {
.sync_call = K_SEM_INITIALIZER(sync_data.sync_call, 0, 1), .sync_call = _K_SEM_INITIALIZER(sync_data.sync_call, 0, 1),
}; };
struct net_mgmt_event_callback sync = { struct net_mgmt_event_callback sync = {
.sync_call = &sync_data.sync_call, .sync_call = &sync_data.sync_call,

View file

@ -27,7 +27,7 @@
#include <net/net_app.h> #include <net/net_app.h>
static struct k_sem waiter = K_SEM_INITIALIZER(waiter, 0, 1); static K_SEM_DEFINE(waiter, 0, 1);
static struct k_sem counter; static struct k_sem counter;
#if defined(CONFIG_NET_DHCPV4) #if defined(CONFIG_NET_DHCPV4)

View file

@ -265,7 +265,7 @@ static struct k_poll_event async_evt =
K_POLL_EVENT_INITIALIZER(K_POLL_TYPE_SIGNAL, K_POLL_EVENT_INITIALIZER(K_POLL_TYPE_SIGNAL,
K_POLL_MODE_NOTIFY_ONLY, K_POLL_MODE_NOTIFY_ONLY,
&async_sig); &async_sig);
static struct k_sem caller = K_SEM_INITIALIZER(caller, 0, 1); static K_SEM_DEFINE(caller, 0, 1);
static char __noinit spi_async_stack[256]; static char __noinit spi_async_stack[256];
static int result = 1; static int result = 1;

View file

@ -89,8 +89,8 @@ void test_poll_no_wait(void)
/* verify k_poll() that has to wait */ /* verify k_poll() that has to wait */
static struct k_sem wait_sem = K_SEM_INITIALIZER(wait_sem, 0, 1); static K_SEM_DEFINE(wait_sem, 0, 1);
static struct k_fifo wait_fifo = K_FIFO_INITIALIZER(wait_fifo); static K_FIFO_DEFINE(wait_fifo);
static struct k_poll_signal wait_signal = K_POLL_SIGNAL_INITIALIZER(); static struct k_poll_signal wait_signal = K_POLL_SIGNAL_INITIALIZER();
struct fifo_msg wait_msg = { NULL, FIFO_MSG_VALUE }; struct fifo_msg wait_msg = { NULL, FIFO_MSG_VALUE };
@ -299,9 +299,8 @@ void test_poll_wait(void)
} }
/* verify -EADDRINUSE return value when object has already a poller */ /* verify -EADDRINUSE return value when object has already a poller */
static struct k_sem eaddrinuse_sem = K_SEM_INITIALIZER(eaddrinuse_sem, 0, 1); static K_SEM_DEFINE(eaddrinuse_sem, 0, 1);
static struct k_sem eaddrinuse_reply = static K_SEM_DEFINE(eaddrinuse_reply, 0, 1);
K_SEM_INITIALIZER(eaddrinuse_reply, 0, 1);
static struct k_thread eaddrinuse_hogger_thread; static struct k_thread eaddrinuse_hogger_thread;
static K_THREAD_STACK_DEFINE(eaddrinuse_hogger_stack, KB(1)); static K_THREAD_STACK_DEFINE(eaddrinuse_hogger_stack, KB(1));
@ -320,8 +319,7 @@ static void eaddrinuse_hogger(void *p1, void *p2, void *p3)
k_sem_give(&eaddrinuse_reply); k_sem_give(&eaddrinuse_reply);
} }
static struct k_sem eaddrinuse_ready_sem = static K_SEM_DEFINE(eaddrinuse_ready_sem, 1, 1);
K_SEM_INITIALIZER(eaddrinuse_ready_sem, 1, 1);
void test_poll_eaddrinuse(void) void test_poll_eaddrinuse(void)
{ {

View file

@ -214,12 +214,14 @@ void test_timer_k_define(void)
static void user_data_timer_handler(struct k_timer *timer); static void user_data_timer_handler(struct k_timer *timer);
static struct k_timer user_data_timer[5] = { K_TIMER_DEFINE(timer0, user_data_timer_handler, NULL);
K_TIMER_INITIALIZER(user_data_timer[0], user_data_timer_handler, NULL), K_TIMER_DEFINE(timer1, user_data_timer_handler, NULL);
K_TIMER_INITIALIZER(user_data_timer[1], user_data_timer_handler, NULL), K_TIMER_DEFINE(timer2, user_data_timer_handler, NULL);
K_TIMER_INITIALIZER(user_data_timer[2], user_data_timer_handler, NULL), K_TIMER_DEFINE(timer3, user_data_timer_handler, NULL);
K_TIMER_INITIALIZER(user_data_timer[3], user_data_timer_handler, NULL), K_TIMER_DEFINE(timer4, user_data_timer_handler, NULL);
K_TIMER_INITIALIZER(user_data_timer[4], user_data_timer_handler, NULL),
static struct k_timer *user_data_timer[5] = {
&timer0, &timer1, &timer2, &timer3, &timer4
}; };
static const intptr_t user_data[5] = { 0x1337, 0xbabe, 0xd00d, 0xdeaf, 0xfade }; static const intptr_t user_data[5] = { 0x1337, 0xbabe, 0xd00d, 0xdeaf, 0xfade };
@ -228,11 +230,11 @@ static int user_data_correct[5] = { 0, 0, 0, 0, 0 };
static void user_data_timer_handler(struct k_timer *timer) static void user_data_timer_handler(struct k_timer *timer)
{ {
int timer_num = timer == &user_data_timer[0] ? 0 : int timer_num = timer == user_data_timer[0] ? 0 :
timer == &user_data_timer[1] ? 1 : timer == user_data_timer[1] ? 1 :
timer == &user_data_timer[2] ? 2 : timer == user_data_timer[2] ? 2 :
timer == &user_data_timer[3] ? 3 : timer == user_data_timer[3] ? 3 :
timer == &user_data_timer[4] ? 4 : -1; timer == user_data_timer[4] ? 4 : -1;
if (timer_num == -1) { if (timer_num == -1) {
return; return;
@ -249,21 +251,21 @@ void test_timer_user_data(void)
for (ii = 0; ii < 5; ii++) { for (ii = 0; ii < 5; ii++) {
intptr_t check; intptr_t check;
k_timer_user_data_set(&user_data_timer[ii], k_timer_user_data_set(user_data_timer[ii],
(void *)user_data[ii]); (void *)user_data[ii]);
check = (intptr_t)k_timer_user_data_get(&user_data_timer[ii]); check = (intptr_t)k_timer_user_data_get(user_data_timer[ii]);
zassert_true(check == user_data[ii], NULL); zassert_true(check == user_data[ii], NULL);
} }
for (ii = 0; ii < 5; ii++) { for (ii = 0; ii < 5; ii++) {
k_timer_start(&user_data_timer[ii], 50 + ii * 50, 0); k_timer_start(user_data_timer[ii], 50 + ii * 50, 0);
} }
k_sleep(50 * ii + 50); k_sleep(50 * ii + 50);
for (ii = 0; ii < 5; ii++) { for (ii = 0; ii < 5; ii++) {
k_timer_stop(&user_data_timer[ii]); k_timer_stop(user_data_timer[ii]);
} }
for (ii = 0; ii < 5; ii++) { for (ii = 0; ii < 5; ii++) {