Skip to content

Commit 975b1b8

Browse files
author
Arto Kinnunen
committed
Squashed 'connectivity/nanostack/sal-stack-nanostack-eventloop/' content from commit fdb818f341
git-subtree-dir: connectivity/nanostack/sal-stack-nanostack-eventloop git-subtree-split: fdb818f34127bc09819978cf1345b04ae8893d33
0 parents  commit 975b1b8

18 files changed

+2297
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*.a
2+
output/*
3+
build
4+
*.lib

LICENSE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Unless specifically indicated otherwise in a file, files are licensed
2+
under the Apache 2.0 license, as can be found in: apache-2.0.txt

Makefile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Define compiler toolchain with CC or PLATFORM variables
2+
# Example (GCC toolchains)
3+
# make PLATFORM=arm-linux-gnueabi-
4+
# OR
5+
# make CC=armcc AR=ArmAR
6+
# OR
7+
# make CC=iccarm
8+
9+
LIB = libeventOS.a
10+
SRCS += \
11+
source/event.c \
12+
source/ns_timer.c \
13+
source/system_timer.c\
14+
source/ns_timeout.c
15+
16+
include ../libService/toolchain_rules.mk
17+
18+
override CFLAGS += -I nanostack-event-loop
19+
20+
#
21+
# External sources from libService
22+
#
23+
SERVLIB_DIR := ../libService
24+
override CFLAGS += -I$(SERVLIB_DIR)/libService
25+
26+
$(eval $(call generate_rules,$(LIB),$(SRCS)))
27+
28+
.PHONY: release
29+
release:
30+
7z a edtls-lib_$(VERSION).zip *.a *.lib include
31+
32+
.PHONY: deploy_to
33+
deploy_to: all
34+
tar --transform 's,^,event-loop/,' --append -f $(TO) *.a

apache-2.0.txt

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
2+
3+
Apache License
4+
5+
Version 2.0, January 2004
6+
7+
http://www.apache.org/licenses/
8+
9+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
10+
11+
1. Definitions.
12+
13+
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
14+
15+
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
16+
17+
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
18+
19+
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
20+
21+
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
22+
23+
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
24+
25+
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
26+
27+
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
28+
29+
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
30+
31+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
32+
33+
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
34+
35+
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
36+
37+
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
38+
39+
You must give any other recipients of the Work or Derivative Works a copy of this License; and
40+
You must cause any modified files to carry prominent notices stating that You changed the files; and
41+
You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
42+
If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
43+
44+
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
45+
46+
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
47+
48+
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
49+
50+
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
51+
52+
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
53+
54+
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
55+
56+
END OF TERMS AND CONDITIONS

mbed_lib.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "nanostack-eventloop",
3+
"requires": ["nanostack-hal"],
4+
"config": {
5+
"use_platform_tick_timer": {
6+
"help": "Use platform provided low resolution tick timer for eventloop",
7+
"value": null
8+
},
9+
"exclude_highres_timer": {
10+
"help": "Exclude high resolution timer from build",
11+
"value": null
12+
}
13+
}
14+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright (c) 2014-2015 ARM Limited. All rights reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
* Licensed under the Apache License, Version 2.0 (the License); you may
5+
* not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
#ifndef EVENTOS_CALLBACK_TIMER_H_
17+
#define EVENTOS_CALLBACK_TIMER_H_
18+
#ifdef __cplusplus
19+
extern "C" {
20+
#endif
21+
#include "ns_types.h"
22+
23+
extern int8_t eventOS_callback_timer_register(void (*timer_interrupt_handler)(int8_t, uint16_t));
24+
extern int8_t eventOS_callback_timer_unregister(int8_t ns_timer_id);
25+
26+
extern int8_t eventOS_callback_timer_stop(int8_t ns_timer_id);
27+
extern int8_t eventOS_callback_timer_start(int8_t ns_timer_id, uint16_t slots);
28+
#ifdef __cplusplus
29+
}
30+
#endif
31+
32+
#endif /* EVENTOS_CALLBACK_TIMER_H_ */

nanostack-event-loop/eventOS_event.h

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
/*
2+
* Copyright (c) 2014-2015 ARM Limited. All rights reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
* Licensed under the Apache License, Version 2.0 (the License); you may
5+
* not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
#ifndef EVENTOS_EVENT_H_
17+
#define EVENTOS_EVENT_H_
18+
#ifdef __cplusplus
19+
extern "C" {
20+
#endif
21+
22+
#include "ns_types.h"
23+
#include "ns_list.h"
24+
25+
/**
26+
* \enum arm_library_event_priority_e
27+
* \brief Event Priority level.
28+
*/
29+
typedef enum arm_library_event_priority_e {
30+
ARM_LIB_HIGH_PRIORITY_EVENT = 0, /**< High Priority Event (Function CB) */
31+
ARM_LIB_MED_PRIORITY_EVENT = 1, /**< Medium Priority (Timer) */
32+
ARM_LIB_LOW_PRIORITY_EVENT = 2, /*!*< Normal Event and ECC / Security */
33+
} arm_library_event_priority_e;
34+
35+
/**
36+
* \struct arm_event_s
37+
* \brief Event structure.
38+
*/
39+
typedef struct arm_event_s {
40+
int8_t receiver; /**< Event handler Tasklet ID */
41+
int8_t sender; /**< Event sender Tasklet ID */
42+
uint8_t event_type; /**< This will be typecast arm_library_event_type_e, arm_internal_event_type_e or application specific define */
43+
uint8_t event_id; /**< Timer ID, NWK interface ID or application specific ID */
44+
void *data_ptr; /**< Application could share data pointer tasklet to tasklet */
45+
arm_library_event_priority_e priority;
46+
uintptr_t event_data;
47+
} arm_event_t;
48+
49+
/* Backwards compatibility */
50+
typedef arm_event_t arm_event_s;
51+
52+
/**
53+
* \struct arm_event_storage
54+
* \brief Event structure storage, including list link.
55+
56+
@startuml
57+
58+
partition "Event loop" {
59+
(*) -->[event created] "UNQUEUED"
60+
"UNQUEUED" -->[event_core_write()] "QUEUED"
61+
"QUEUED" -->[event_core_read()] "RUNNING"
62+
"RUNNING" ->[event_core_free_push()] "UNQUEUED"
63+
}
64+
65+
partition "system_timer.c" {
66+
"UNQUEUED:timer" -->[eventOS_event_send_timer_allocated()] "QUEUED"
67+
}
68+
@enduml
69+
70+
*/
71+
typedef struct arm_event_storage {
72+
arm_event_s data;
73+
enum {
74+
ARM_LIB_EVENT_STARTUP_POOL,
75+
ARM_LIB_EVENT_DYNAMIC,
76+
ARM_LIB_EVENT_USER,
77+
ARM_LIB_EVENT_TIMER,
78+
} allocator;
79+
enum {
80+
ARM_LIB_EVENT_UNQUEUED,
81+
ARM_LIB_EVENT_QUEUED,
82+
ARM_LIB_EVENT_RUNNING,
83+
} state;
84+
ns_list_link_t link;
85+
} arm_event_storage_t;
86+
87+
/**
88+
* \brief Send event to event scheduler.
89+
*
90+
* \param event pointer to pushed event.
91+
*
92+
* Event data is copied by the call, and this copy persists until the
93+
* recipient's callback function returns. The callback function is passed
94+
* a pointer to a copy of the data, not the original pointer.
95+
*
96+
* \return 0 Event push OK
97+
* \return -1 Memory allocation Fail
98+
*/
99+
extern int8_t eventOS_event_send(const arm_event_t *event);
100+
101+
/* Alternate names for timer function from eventOS_event_timer.h;
102+
* implementations may one day merge */
103+
#define eventOS_event_send_at(event, at) eventOS_event_timer_request_at(event, at)
104+
#define eventOS_event_send_in(event, in) eventOS_event_timer_request_in(event, in)
105+
#define eventOS_event_send_after(event, after) eventOS_event_timer_request_after(event, after)
106+
#define eventOS_event_send_every(event, every) eventOS_event_timer_request_every(event, every)
107+
108+
/**
109+
* \brief Send user-allocated event to event scheduler.
110+
*
111+
* \param event pointer to pushed event storage.
112+
*
113+
* The event structure is not copied by the call, the event system takes
114+
* ownership and it is threaded directly into the event queue. This avoids the
115+
* possibility of event sending failing due to memory exhaustion.
116+
*
117+
* event->data must be filled in on entry - the rest of the structure (link and
118+
* allocator) need not be.
119+
*
120+
* The structure must remain valid until the recipient is called - the
121+
* event system passes ownership to the receiving event handler, who may then
122+
* invalidate it, or send it again.
123+
*
124+
* The recipient receives a pointer to the arm_event_t data member of the
125+
* event - it can use NS_CONTAINER_OF() to get a pointer to the original
126+
* event passed to this call, or to its outer container.
127+
*
128+
* It is a program error to send a user-allocated event to a non-existent task.
129+
*/
130+
extern void eventOS_event_send_user_allocated(arm_event_storage_t *event);
131+
132+
/**
133+
* \brief Event handler callback register
134+
*
135+
* Function will register and allocate unique event id handler
136+
*
137+
* \param handler_func_ptr function pointer for event handler
138+
* \param init_event_type generated event type for init purpose
139+
*
140+
* \return >= 0 Unique event ID for this handler
141+
* \return < 0 Register fail
142+
*
143+
* */
144+
extern int8_t eventOS_event_handler_create(void (*handler_func_ptr)(arm_event_t *), uint8_t init_event_type);
145+
146+
/**
147+
* Cancel an event.
148+
*
149+
* Queued events are removed from the event-loop queue and/or the timer queue.
150+
*
151+
* Passing a NULL pointer is allowed, and does nothing.
152+
*
153+
* Event pointers are valid from the time they are queued until the event
154+
* has finished running or is cancelled.
155+
*
156+
* Cancelling a currently-running event is only useful to stop scheduling
157+
* it if it is on a periodic timer; it has no other effect.
158+
*
159+
* Cancelling an already-cancelled or already-run single-shot event
160+
* is undefined behaviour.
161+
*
162+
* \param event Pointer to event handle or NULL.
163+
*/
164+
extern void eventOS_cancel(arm_event_storage_t *event);
165+
166+
#ifdef __cplusplus
167+
}
168+
#endif
169+
#endif /* EVENTOS_EVENT_H_ */

0 commit comments

Comments
 (0)