• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *   Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  * Description: OS Abstract Layer.
15  */
16 
17 #ifndef __OSAL_EVENT_H__
18 #define __OSAL_EVENT_H__
19 
20 /**
21  * @defgroup osal_event osal_event
22  */
23 #ifdef __cplusplus
24 #if __cplusplus
25 extern "C" {
26 #endif
27 #endif
28 
29 /* timeout forever macro */
30 #define OSAL_EVENT_FOREVER 0xFFFFFFFF
31 
32 // Event reading mode: The task waits for all its expected events to occur.
33 #define OSAL_WAITMODE_AND 4U
34 // Event reading mode: The task waits for any of its expected events to occur.
35 #define OSAL_WAITMODE_OR 2U
36 // Event reading mode: The event flag is immediately cleared after the event is read.
37 #define OSAL_WAITMODE_CLR 1U
38 
39 typedef struct {
40     void *event;
41 } osal_event;
42 
43 /**
44  * @ingroup osal_event
45  * @brief Initialize an event control block.
46  *
47  * @par Description:
48  * This API is used to initialize the event control block pointed to by eventCB.
49  *
50  * @return OSAL_SUCCESS/OSAL_FAILURE
51  *
52  * @par Support System:
53  * liteos freertos.
54  */
55 int osal_event_init(osal_event *event_obj);
56 
57 /**
58  * @ingroup osal_event
59  * @brief Write an event.
60  *
61  * @par Description:
62  * This API is used to write an event specified by the passed-in event mask into an event control block
63  * pointed to by eventCB.
64  *
65  * @return OSAL_SUCCESS/OSAL_FAILURE
66  *
67  * @par Support System:
68  * liteos freertos.
69  */
70 int osal_event_write(osal_event *event_obj, unsigned int mask);
71 
72 /**
73  * @ingroup osal_event
74  * @brief Read an event.
75  *
76  * @par Description:
77  * This API is used to block or schedule a task that reads an event of which the event control block, event mask,
78  * reading mode, and timeout information are specified.
79  *
80  * @attention
81  * Do not read event during an interrupt.
82  * Do not recommend to use this API in software timer callback.
83  * bit 25 of the event mask is forbidden to be used on liteos.
84  *
85  * @param event_obj [in/out] Pointer to the event control block to be checked.
86  * This parameter must point to valid memory.
87  * @param mask [in] Mask of the event expected to occur by the user, indicating the event obtained after
88  * it is logically processed that matches the ID pointed to by eventId.
89  * @param timeout_ms [in] Timeout interval of event reading.(unit: ms)
90  * @param mode [in] Event reading mode.
91  *
92  * @return OSAL_SUCCESS/OSAL_FAILURE
93  *
94  * @par Support System:
95  * liteos freertos.
96  */
97 int osal_event_read(osal_event *event_obj, unsigned int mask, unsigned int timeout_ms, unsigned int mode);
98 
99 /**
100  * @ingroup osal_event
101  * @brief Clear the event occurring in a specified task.
102  *
103  * @par Description:
104  * This API is used to set the ID of an event that has a specified mask and of which the information is stored in
105  * an event control block pointed to by eventCB to 0. eventCB must point to valid memory.
106  *
107  * @param event_obj [in/out] Pointer to the event control block to be cleared.
108  * @param mask [in] Mask of the event to be cleared.
109  *
110  * @return OSAL_SUCCESS/OSAL_FAILURE
111  *
112  * @par Support System:
113  * liteos freertos.
114  */
115 int osal_event_clear(osal_event *event_obj, unsigned int mask);
116 
117 /**
118  * @ingroup osal_event
119  * @brief Destroy a event.
120  *
121  * @par Description:
122  * This API is used to destroy a event.
123  *
124  * @param event_obj [in/out] Pointer to the event control block to be destroyed.
125  *
126  * @attention this api may free memory, event_obj should be from osal_event_init.
127  *
128  * @return OSAL_SUCCESS/OSAL_FAILURE
129  *
130  * @par Support System:
131  * liteos freertos.
132  */
133 int osal_event_destroy(osal_event *event_obj);
134 
135 #ifdef __cplusplus
136 #if __cplusplus
137 }
138 #endif
139 #endif
140 #endif /* __OSAL_EVENT_H__ */
141