2015-04-11 07:44:37 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1997-2014 Wind River Systems, Inc.
|
|
|
|
*
|
2015-10-07 00:00:37 +08:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2015-04-11 07:44:37 +08:00
|
|
|
*
|
2015-10-07 00:00:37 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2015-04-11 07:44:37 +08:00
|
|
|
*
|
2015-10-07 00:00:37 +08:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2015-04-11 07:44:37 +08:00
|
|
|
*/
|
|
|
|
|
2015-07-20 23:56:22 +08:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* @brief Event header file.
|
|
|
|
*/
|
|
|
|
|
2015-04-11 07:44:37 +08:00
|
|
|
#ifndef EVENT_H
|
|
|
|
#define EVENT_H
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2015-08-29 21:40:34 +08:00
|
|
|
/**
|
|
|
|
* @brief Microkernel Events
|
|
|
|
* @defgroup microkernel_event Microkernel Events
|
|
|
|
* @ingroup microkernel_services
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2015-11-06 04:37:11 +08:00
|
|
|
#include <microkernel/base_api.h>
|
2015-04-11 07:44:37 +08:00
|
|
|
|
2016-02-08 23:28:39 +08:00
|
|
|
/** Well-known events. */
|
2015-10-22 02:04:58 +08:00
|
|
|
extern const kevent_t TICK_EVENT;
|
2015-05-14 03:08:08 +08:00
|
|
|
|
2015-07-20 23:56:22 +08:00
|
|
|
/**
|
|
|
|
*
|
2016-02-08 23:28:39 +08:00
|
|
|
* @brief Signal an event from an ISR.
|
2015-07-20 23:56:22 +08:00
|
|
|
*
|
2016-02-08 23:28:39 +08:00
|
|
|
* This routine does @em not validate the specified event number.
|
2015-07-20 23:56:22 +08:00
|
|
|
*
|
|
|
|
* @param event Event to signal.
|
|
|
|
*
|
|
|
|
* @return N/A
|
|
|
|
*/
|
2015-04-11 07:44:37 +08:00
|
|
|
extern void isr_event_send(kevent_t event);
|
2015-07-20 23:56:22 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
2016-02-08 23:28:39 +08:00
|
|
|
* @brief Signal an event from a fiber.
|
2015-07-20 23:56:22 +08:00
|
|
|
*
|
2016-02-08 23:28:39 +08:00
|
|
|
* This routine does @em not validate the specified event number.
|
2015-07-20 23:56:22 +08:00
|
|
|
*
|
|
|
|
* @param event Event to signal.
|
|
|
|
*
|
|
|
|
* @return N/A
|
|
|
|
*/
|
2015-04-11 07:44:37 +08:00
|
|
|
extern void fiber_event_send(kevent_t event);
|
2015-07-20 23:56:22 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
2016-02-08 23:28:39 +08:00
|
|
|
* @brief Set event handler request.
|
2015-07-20 23:56:22 +08:00
|
|
|
*
|
2016-02-08 23:28:39 +08:00
|
|
|
* This routine specifies the event handler that runs in the context of the
|
|
|
|
* microkernel server fiber when the associated event is signaled. Specifying
|
2015-08-13 03:37:58 +08:00
|
|
|
* a non-NULL handler installs a new handler, while specifying a NULL event
|
|
|
|
* handler removes the existing event handler.
|
2015-07-20 23:56:22 +08:00
|
|
|
*
|
2016-02-08 23:28:39 +08:00
|
|
|
* A new event handler cannot be installed if one already exists for that event.
|
|
|
|
* The old handler must be removed first. However, the NULL event handler can be
|
|
|
|
* replaced with itself.
|
2015-07-20 23:56:22 +08:00
|
|
|
*
|
2016-02-08 23:28:39 +08:00
|
|
|
* @param event Event upon which to register.
|
2015-07-20 23:56:22 +08:00
|
|
|
* @param handler Function pointer to handler.
|
|
|
|
*
|
2016-02-08 23:28:39 +08:00
|
|
|
* @retval RC_FAIL If an event handler exists or the event number is invalid.
|
|
|
|
* @retval RC_OK Otherwise.
|
2015-07-20 23:56:22 +08:00
|
|
|
*/
|
2015-08-11 05:52:20 +08:00
|
|
|
extern int task_event_handler_set(kevent_t event, kevent_handler_t handler);
|
2015-04-11 07:44:37 +08:00
|
|
|
|
2015-07-20 23:56:22 +08:00
|
|
|
/**
|
|
|
|
*
|
2016-02-08 23:28:39 +08:00
|
|
|
* @brief Signal an event request.
|
2015-07-20 23:56:22 +08:00
|
|
|
*
|
|
|
|
* This routine signals the specified event from a task. If an event handler
|
2016-02-08 23:28:39 +08:00
|
|
|
* is installed for that event, it will run. If no event handler is installed,
|
2015-07-20 23:56:22 +08:00
|
|
|
* any task waiting on the event is released.
|
|
|
|
*
|
|
|
|
* @param event Event to signal.
|
|
|
|
*
|
2016-02-08 23:28:39 +08:00
|
|
|
* @retval RC_FAIL If the event number is invalid.
|
|
|
|
* @retval RC_OK Otherwise.
|
2015-07-20 23:56:22 +08:00
|
|
|
*/
|
2015-04-11 07:44:37 +08:00
|
|
|
extern int task_event_send(kevent_t event);
|
2015-07-20 23:56:22 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
2016-02-08 23:28:39 +08:00
|
|
|
* @brief Test for an event request with timeout.
|
2015-07-20 23:56:22 +08:00
|
|
|
*
|
|
|
|
* This routine tests an event to see if it has been signaled.
|
|
|
|
*
|
2016-02-08 23:28:39 +08:00
|
|
|
* @param event Event to test.
|
|
|
|
* @param timeout Determines the action to take when the event has not yet
|
|
|
|
* been signaled.
|
|
|
|
* For TICKS_NONE, return immediately.
|
|
|
|
* For TICKS_UNLIMITED, wait as long as necessary.
|
|
|
|
* Otherwise, wait up to the specified number of ticks before
|
|
|
|
* timing out.
|
2015-12-08 04:36:25 +08:00
|
|
|
*
|
|
|
|
* @retval RC_OK Successfully received signaled event
|
|
|
|
* @retval RC_TIME Timed out while waiting for signaled event
|
|
|
|
* @retval RC_FAIL Failed to immediately receive signaled event when
|
2016-02-08 23:28:39 +08:00
|
|
|
* timeout = TICKS_NONE
|
2015-07-20 23:56:22 +08:00
|
|
|
*/
|
2015-12-08 04:36:25 +08:00
|
|
|
extern int task_event_recv(kevent_t event, int32_t timeout);
|
2015-07-20 23:56:22 +08:00
|
|
|
|
2015-08-29 21:40:34 +08:00
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|
2015-05-11 22:46:39 +08:00
|
|
|
|
2015-10-22 02:04:58 +08:00
|
|
|
#define _K_EVENT_INITIALIZER(handler) \
|
|
|
|
{ \
|
|
|
|
.status = 0, \
|
|
|
|
.func = (kevent_handler_t)handler, \
|
|
|
|
.waiter = NULL, \
|
|
|
|
.count = 0, \
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Define a private microkernel event
|
|
|
|
*
|
|
|
|
* This declares and initializes a private event. The new event
|
|
|
|
* can be passed to the microkernel event functions.
|
|
|
|
*
|
|
|
|
* @param name Name of the event
|
|
|
|
* @param handler Function to handle the event (can be NULL)
|
|
|
|
*/
|
|
|
|
#define DEFINE_EVENT(name, handler) \
|
|
|
|
struct _k_event_struct _k_event_obj_##name \
|
|
|
|
__in_section(_k_event_list, event, name) = \
|
|
|
|
_K_EVENT_INITIALIZER(handler); \
|
|
|
|
const kevent_t name = (kevent_t)&_k_event_obj_##name;
|
|
|
|
|
2015-04-11 07:44:37 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* EVENT_H */
|