1 /*
2 * Copyright (C) 2015-2021 Alibaba Group Holding Limited
3 */
4
5 #include <stdio.h>
6 #include <time.h>
7
8 #include <k_api.h>
9 #include <aos/errno.h>
10 #include <aos/kernel.h>
11
12 #include "rhino_p.h"
13
14 #if (RHINO_CONFIG_KOBJ_DYN_ALLOC == 0)
15 #warning "RHINO_CONFIG_KOBJ_DYN_ALLOC is disabled!"
16 #endif
17
18 #if (RHINO_CONFIG_EVENT_FLAG > 0)
19
aos_event_new(aos_event_t * event,uint32_t value)20 aos_status_t aos_event_new(aos_event_t *event, uint32_t value)
21 {
22 int ret;
23 if (event == NULL) {
24 return -EINVAL;
25 }
26
27 ret = krhino_event_dyn_create((kevent_t **)(event), "AOS", value);
28
29 return rhino2stderrno(ret);
30 }
31
aos_event_create(aos_event_t * event,uint32_t value,uint32_t options)32 aos_status_t aos_event_create(aos_event_t *event, uint32_t value, uint32_t options)
33 {
34 int ret;
35
36 (void)options;
37 if (event == NULL) {
38 return -EINVAL;
39 }
40 ret = krhino_event_dyn_create((kevent_t **)(event), "AOS", value);
41
42 return rhino2stderrno(ret);
43 }
44
aos_event_free(aos_event_t * event)45 void aos_event_free(aos_event_t *event)
46 {
47 if (event == NULL || *event == NULL) {
48 return;
49 }
50
51 (void)krhino_event_dyn_del((kevent_t *)*event);
52
53 *event = NULL;
54 }
55
aos_event_get(aos_event_t * event,uint32_t value,uint32_t opt,uint32_t * actl_value,uint32_t timeout)56 aos_status_t aos_event_get(aos_event_t *event, uint32_t value, uint32_t opt,
57 uint32_t *actl_value, uint32_t timeout)
58 {
59 kstat_t ret;
60
61 CHECK_HANDLE(event);
62
63 if (timeout == AOS_WAIT_FOREVER) {
64 ret = krhino_event_get((kevent_t *)*event, value, opt, actl_value, RHINO_WAIT_FOREVER);
65 } else {
66 ret = krhino_event_get((kevent_t *)*event, value, opt, actl_value, MS2TICK(timeout));
67 }
68
69 return rhino2stderrno(ret);
70 }
71
aos_event_set(aos_event_t * event,uint32_t flags,uint32_t opt)72 aos_status_t aos_event_set(aos_event_t *event, uint32_t flags, uint32_t opt)
73 {
74 kstat_t ret;
75
76 CHECK_HANDLE(event);
77
78 ret = krhino_event_set((kevent_t *)*event, flags, opt);
79
80 return rhino2stderrno(ret);
81 }
82
aos_event_is_valid(aos_event_t * event)83 bool aos_event_is_valid(aos_event_t *event)
84 {
85 kevent_t *k_event;
86
87 if (event == NULL) {
88 return false;
89 }
90
91 k_event = (kevent_t *)*event;
92
93 if (k_event == NULL) {
94 return false;
95 }
96
97 if (k_event->blk_obj.obj_type != RHINO_EVENT_OBJ_TYPE) {
98 return false;
99 }
100
101 return true;
102 }
103
104 #endif
105
106