|
| 1 | +/**************************************************************************** |
| 2 | + * include/nuttx/event.h |
| 3 | + * |
| 4 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 5 | + * contributor license agreements. See the NOTICE file distributed with |
| 6 | + * this work for additional information regarding copyright ownership. The |
| 7 | + * ASF licenses this file to you under the Apache License, Version 2.0 (the |
| 8 | + * "License"); you may not use this file except in compliance with the |
| 9 | + * License. You may obtain a copy of the License at |
| 10 | + * |
| 11 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | + * |
| 13 | + * Unless required by applicable law or agreed to in writing, software |
| 14 | + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 15 | + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 16 | + * License for the specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + * |
| 19 | + ****************************************************************************/ |
| 20 | + |
| 21 | +#ifndef __INCLUDE_NUTTX_EVENT_H |
| 22 | +#define __INCLUDE_NUTTX_EVENT_H |
| 23 | + |
| 24 | +/**************************************************************************** |
| 25 | + * Included Files |
| 26 | + ****************************************************************************/ |
| 27 | + |
| 28 | +#include <nuttx/config.h> |
| 29 | + |
| 30 | +#include <errno.h> |
| 31 | +#include <stdint.h> |
| 32 | +#include <semaphore.h> |
| 33 | + |
| 34 | +#include <nuttx/irq.h> |
| 35 | +#include <nuttx/semaphore.h> |
| 36 | +#include <nuttx/clock.h> |
| 37 | + |
| 38 | +/**************************************************************************** |
| 39 | + * Pre-processor Definitions |
| 40 | + ****************************************************************************/ |
| 41 | + |
| 42 | +/* Initializers */ |
| 43 | + |
| 44 | +#define NXEVENT_INITIALIZER(e) {SEM_INITIALIZER(0), e} |
| 45 | + |
| 46 | +/**************************************************************************** |
| 47 | + * Public Type Definitions |
| 48 | + ****************************************************************************/ |
| 49 | + |
| 50 | +typedef struct event_s event_t; |
| 51 | +typedef uint32_t event_mask_t; |
| 52 | + |
| 53 | +struct event_s |
| 54 | +{ |
| 55 | + sem_t sem; /* Event Semaphore */ |
| 56 | + volatile event_mask_t events; /* Pending Events */ |
| 57 | +}; |
| 58 | + |
| 59 | +/**************************************************************************** |
| 60 | + * Public Data |
| 61 | + ****************************************************************************/ |
| 62 | + |
| 63 | +#ifndef __ASSEMBLY__ |
| 64 | + |
| 65 | +#ifdef __cplusplus |
| 66 | +#define EXTERN extern "C" |
| 67 | +extern "C" |
| 68 | +{ |
| 69 | +#else |
| 70 | +#define EXTERN extern |
| 71 | +#endif |
| 72 | + |
| 73 | +/**************************************************************************** |
| 74 | + * Public Function Prototypes |
| 75 | + ****************************************************************************/ |
| 76 | + |
| 77 | +/**************************************************************************** |
| 78 | + * Name: nxevent_init |
| 79 | + * |
| 80 | + * Description: |
| 81 | + * This routine initializes an event object, Set of default events to post |
| 82 | + * to event. |
| 83 | + * |
| 84 | + * Input Parameters: |
| 85 | + * event - Address of the event object |
| 86 | + * events - Set of events to post to event |
| 87 | + * |
| 88 | + * Returned Value: |
| 89 | + * This is an internal OS interface and should not be used by applications. |
| 90 | + * It follows the NuttX internal error return policy: Zero (OK) is |
| 91 | + * returned on success. A negated errno value is returned on failure. |
| 92 | + * |
| 93 | + ****************************************************************************/ |
| 94 | + |
| 95 | +int nxevent_init(FAR event_t *event, event_mask_t events); |
| 96 | + |
| 97 | +/**************************************************************************** |
| 98 | + * Name: nxevent_destroy |
| 99 | + * |
| 100 | + * Description: |
| 101 | + * This function is used to destroy the event. |
| 102 | + * |
| 103 | + * Input Parameters: |
| 104 | + * event - Address of the event object |
| 105 | + * |
| 106 | + * Returned Value: |
| 107 | + * This is an internal OS interface and should not be used by applications. |
| 108 | + * It follows the NuttX internal error return policy: Zero (OK) is |
| 109 | + * returned on success. A negated errno value is returned on failure. |
| 110 | + * |
| 111 | + ****************************************************************************/ |
| 112 | + |
| 113 | +int nxevent_destroy(FAR event_t *event); |
| 114 | + |
| 115 | +/**************************************************************************** |
| 116 | + * Name: nxevent_reset |
| 117 | + * |
| 118 | + * Description: |
| 119 | + * Reset events mask to a specific value. |
| 120 | + * |
| 121 | + * Input Parameters: |
| 122 | + * event - Address of the event object |
| 123 | + * events - Set of events to post to event |
| 124 | + * |
| 125 | + * Returned Value: |
| 126 | + * This is an internal OS interface, not available to applications, and |
| 127 | + * hence follows the NuttX internal error return policy: Zero (OK) is |
| 128 | + * returned on success. A negated errno value is returned on failure. |
| 129 | + * |
| 130 | + ****************************************************************************/ |
| 131 | + |
| 132 | +int nxevent_reset(FAR event_t *event, event_mask_t events); |
| 133 | + |
| 134 | +/**************************************************************************** |
| 135 | + * Name: nxevent_post |
| 136 | + * |
| 137 | + * Description: |
| 138 | + * Post one or more events to an event object. |
| 139 | + * |
| 140 | + * This routine posts one or more events to an event object. All tasks |
| 141 | + * waiting on the event object event whose waiting conditions become |
| 142 | + * met by this posting immediately unpend. |
| 143 | + * |
| 144 | + * Posting differs from setting in that posted events are merged together |
| 145 | + * with the current set of events tracked by the event object. |
| 146 | + * |
| 147 | + * Input Parameters: |
| 148 | + * event - Address of the event object |
| 149 | + * events - Set of events to post to event |
| 150 | + * - Set events to 0 will ignored the waiting events and |
| 151 | + * wake up the waiting thread. |
| 152 | + * |
| 153 | + * Returned Value: |
| 154 | + * This is an internal OS interface and should not be used by applications. |
| 155 | + * It follows the NuttX internal error return policy: Zero (OK) is |
| 156 | + * returned on success. A negated errno value is returned on failure. |
| 157 | + * |
| 158 | + * Assumptions: |
| 159 | + * This function may be called from an interrupt handler. |
| 160 | + * |
| 161 | + ****************************************************************************/ |
| 162 | + |
| 163 | +int nxevent_post(FAR event_t *event, event_mask_t events); |
| 164 | + |
| 165 | +/**************************************************************************** |
| 166 | + * Name: nxevent_wait |
| 167 | + * |
| 168 | + * Description: |
| 169 | + * Wait for all of the specified events. |
| 170 | + * |
| 171 | + * This routine waits on event object event until any of the specified |
| 172 | + * events have been delivered to the event object, or the maximum wait time |
| 173 | + * timeout has expired. A thread may wait on up to 32 distinctly numbered |
| 174 | + * events that are expressed as bits in a single 32-bit word. |
| 175 | + * |
| 176 | + * Input Parameters: |
| 177 | + * event - Address of the event object |
| 178 | + * events - Set of events to post to event |
| 179 | + * - Set events to 0 will indicate wait from any events |
| 180 | + * |
| 181 | + * Returned Value: |
| 182 | + * This is an internal OS interface and should not be used by applications. |
| 183 | + * Return of matching events upon success. |
| 184 | + * 0 if matching events were not received. |
| 185 | + * |
| 186 | + ****************************************************************************/ |
| 187 | + |
| 188 | +event_mask_t nxevent_wait(FAR event_t *event, event_mask_t events); |
| 189 | + |
| 190 | +/**************************************************************************** |
| 191 | + * Name: nxevent_tickwait |
| 192 | + * |
| 193 | + * Description: |
| 194 | + * Wait for all of the specified events from the specified tick time. |
| 195 | + * |
| 196 | + * This routine waits on event object event until any of the specified |
| 197 | + * events have been delivered to the event object, or the maximum wait time |
| 198 | + * timeout has expired. A thread may wait on up to 32 distinctly numbered |
| 199 | + * events that are expressed as bits in a single 32-bit word. |
| 200 | + * |
| 201 | + * Input Parameters: |
| 202 | + * event - Address of the event object |
| 203 | + * events - Set of events to post to event |
| 204 | + * - Set events to 0 will indicate wait from any events |
| 205 | + * delay - Ticks to wait from the start time until the event is |
| 206 | + * posted. If ticks is zero, then this function is equivalent |
| 207 | + * to nxevent_trywait(). |
| 208 | + * |
| 209 | + * Returned Value: |
| 210 | + * This is an internal OS interface and should not be used by applications. |
| 211 | + * Return of matching events upon success. |
| 212 | + * 0 if matching events were not received within the specified time. |
| 213 | + * |
| 214 | + ****************************************************************************/ |
| 215 | + |
| 216 | +event_mask_t nxevent_tickwait(FAR event_t *event, |
| 217 | + event_mask_t events, uint32_t delay); |
| 218 | + |
| 219 | +/**************************************************************************** |
| 220 | + * Name: nxevent_trywait |
| 221 | + * |
| 222 | + * Description: |
| 223 | + * Try wait for all of the specified events. |
| 224 | + * |
| 225 | + * This routine waits on event object event until any of the specified |
| 226 | + * events have been delivered to the event object, or the maximum wait time |
| 227 | + * timeout has expired. A thread may wait on up to 32 distinctly numbered |
| 228 | + * events that are expressed as bits in a single 32-bit word. |
| 229 | + * |
| 230 | + * Input Parameters: |
| 231 | + * event - Address of the event object |
| 232 | + * events - Set of events to post to event |
| 233 | + * - Set events to 0 will indicate wait from any events |
| 234 | + * |
| 235 | + * Returned Value: |
| 236 | + * This is an internal OS interface and should not be used by applications. |
| 237 | + * Return of matching events upon success. |
| 238 | + * 0 if matching events were not received. |
| 239 | + * |
| 240 | + ****************************************************************************/ |
| 241 | + |
| 242 | +event_mask_t nxevent_trywait(FAR event_t *event, event_mask_t events); |
| 243 | + |
| 244 | +#undef EXTERN |
| 245 | +#ifdef __cplusplus |
| 246 | +} |
| 247 | +#endif |
| 248 | + |
| 249 | +#endif /* __ASSEMBLY__ */ |
| 250 | +#endif /* __INCLUDE_NUTTX_EVENT_H */ |
0 commit comments