cocoOS  4.0.0
os_event.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012 Peter Eckstrand
3  *
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted (subject to the limitations in the
8  * disclaimer below) provided that the following conditions are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in the
15  * documentation and/or other materials provided with the
16  * distribution.
17  *
18  * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
19  * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
20  * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
21  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
27  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
29  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
30  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  * This file is part of the cocoOS operating system.
33  * Author: Peter Eckstrand <info@cocoos.net>
34  */
35 
36 /***************************************************************************************
37 
38 
39  Change log:
40  2009-07-06: 1.0.0 First release
41  2010-10-12: New event type definition
42  2011-12-17: Implemented support for timeout when waiting for single event
43  2012-01-04: Released under BSD license.
44  2013-12-25: OS_INT_SIGNAL_EVENT sets signalling tid to ISR_TID
45 
46 
47 ***************************************************************************************
48 */
49 #ifndef OS_EVENT_H
50 #define OS_EVENT_H
51 
54 #include "cocoos.h"
55 #include "stdarg.h"
56 
57 #ifdef __cplusplus
58 extern "C" {
59 #endif
60 
61 #define EVENT_OFS1 10000
62 #define EVENT_OFS2 11000
63 #define EVENT_OFS3 12000
64 
65 #define OS_WAIT_SINGLE_EVENT(x,timeout) do {\
66  os_wait_event(running_tid,x,1,timeout);\
67  OS_SCHEDULE(EVENT_OFS1);\
68  } while (0)
69 
70 
71 
72 
73 
74 
75 #define OS_WAIT_MULTIPLE_EVENTS( waitAll, args...) do {\
76  os_wait_multiple(waitAll, args, NO_EVENT);\
77  OS_SCHEDULE(EVENT_OFS2);\
78  } while (0)
79 
80 
81 
82 
83 
84 
85 #define OS_SIGNAL_EVENT(event) do {\
86  os_signal_event(event);\
87  os_event_set_signaling_tid( event, running_tid );\
88  OS_SCHEDULE(EVENT_OFS3);\
89  } while (0)
90 
91 
92 
93 
94 #define OS_INT_SIGNAL_EVENT(event) do {\
95  os_signal_event(event);\
96  os_event_set_signaling_tid( event, ISR_TID );\
97  } while (0)
98 
99 
100 #ifdef N_TOTAL_EVENTS
101  #define EVENT_QUEUE_SIZE ((N_TOTAL_EVENTS/9)+1)
102 #else
103  #define EVENT_QUEUE_SIZE 1
104 #endif
105 
106 
107 typedef uint8_t Evt_t;
108 
109 typedef struct {
110  uint8_t eventList[ EVENT_QUEUE_SIZE ];
111 } EventQueue_t;
112 
113 
114 
115 void os_wait_event( uint8_t tid, Evt_t ev, uint8_t waitSingleEvent, uint16_t timeout );
116 void os_wait_multiple( uint8_t waitAll, ...);
117 void os_signal_event( Evt_t ev );
118 void os_event_set_signaling_tid( Evt_t ev, uint8_t tid );
119 
120 #ifdef __cplusplus
121 }
122 #endif
123 
124 #endif
Definition: os_event.h:109