-
Notifications
You must be signed in to change notification settings - Fork 57
/
raw_idle_event.c
303 lines (196 loc) · 6.38 KB
/
raw_idle_event.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
/*
raw os - Copyright (C) Lingjun Chen(jorya_txj).
This file is part of raw os.
raw os is free software; you can redistribute it it under the terms of the
GNU General Public License as published by the Free Software Foundation;
either version 3 of the License, or (at your option) any later version.
raw os is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. if not, write email to [email protected]
---
A special exception to the LGPL can be applied should you wish to distribute
a combined work that includes raw os, without being obliged to provide
the source code for any proprietary components. See the file exception.txt
for full details of how and when the exception can be applied.
*/
/* 2012-12 Created by jorya_txj
* xxxxxx please added here
*/
#include <raw_api.h>
#if (CONFIG_RAW_IDLE_EVENT > 0)
#include <port_idle_config.h>
void idle_event_init(void)
{
ACTIVE_EVENT_STRUCT *temp;
RAW_U8 i;
/*Init idle task queue information, MAX_IDLE_EVENT_TASK max 64 is allowed*/
for (i = 0; i <= MAX_IDLE_EVENT_TASK - 1; i++) {
temp = active_idle_task[i].act;
RAW_ASSERT(temp != 0);
temp->prio = i;
temp->head = 0;
temp->tail = 0;
temp->nUsed = 0;
temp->priority_x = i & 0x7;
temp->priority_y = i >> 3;
temp->priority_bit_y = (RAW_U8 )(1 << temp->priority_y);
temp->priority_bit_x = (RAW_U8 )(1 << temp->priority_x);
}
/*Init the list*/
list_init(&raw_idle_tick_head);
}
RAW_OS_ERROR event_post(ACTIVE_EVENT_STRUCT *me, RAW_U16 sig, void *para, RAW_U8 opt_send_method)
{
ACTIVE_EVENT_STRUCT_CB *acb;
RAW_SR_ALLOC();
acb = &active_idle_task[me->prio];
RAW_CRITICAL_ENTER();
if (me->nUsed == acb->end) {
RAW_CRITICAL_EXIT();
return RAW_IDLE_EVENT_EXHAUSTED;
}
if (opt_send_method == SEND_TO_END) {
acb->queue[me->head].sig = sig;
acb->queue[me->head].para = para;
me->head++;
if (me->head == acb->end) {
me->head = 0;
}
}
else {
if (me->tail == 0) {
me->tail = acb->end;
}
me->tail--;
acb->queue[me->tail].sig = sig;
acb->queue[me->tail].para = para;
}
++me->nUsed;
if (me->nUsed == 1) {
raw_idle_rdy_grp |= acb->act->priority_bit_y;
raw_rdy_tbl[acb->act->priority_y] |= acb->act->priority_bit_x;
}
RAW_CRITICAL_EXIT();
return RAW_SUCCESS;
}
/*
************************************************************************************************************************
* Post an event (FIFO) to idle task
*
* Description: This function is called to post an event to idle task, it might be called in interrupt.
*
* Arguments :me is the address of ACTIVE_EVENT_STRUCT
* -----
* sig is the signal which want to be posted to idle task
* -----
* para is the parameter which want to be posted to idle task.
*
* Returns RAW_SUCCESS: raw os return success
* RAW_IDLE_EVENT_EXHAUSTED: No more msg to me.
*
* Note(s)
*
*
************************************************************************************************************************
*/
RAW_OS_ERROR idle_event_end_post(ACTIVE_EVENT_STRUCT *me, RAW_U16 sig, void *para)
{
return event_post(me, sig, para, SEND_TO_END);
}
/*
************************************************************************************************************************
* Post an event (LIFO) to idle task
*
* Description: This function is called to post an event to idle task, it might be called in interrupt.
*
* Arguments :me is the address of ACTIVE_EVENT_STRUCT
* -----
* sig is the signal which want to be posted to idle task
* -----
* para is the parameter which want to be posted to idle task.
*
* Returns RAW_SUCCESS: raw os return success
* RAW_IDLE_EVENT_EXHAUSTED: No more msg to me.
*
* Note(s)
*
*
************************************************************************************************************************
*/
RAW_OS_ERROR idle_event_front_post(ACTIVE_EVENT_STRUCT *me, RAW_U16 sig, void *para)
{
return event_post(me, sig, para, SEND_TO_FRONT);
}
void idle_tick_isr(void)
{
ACTIVE_EVENT_STRUCT *a;
LIST *head;
LIST *iter;
LIST *iter_temp;
head = &raw_idle_tick_head;
iter = head->next;
/*if list is not empty*/
while (iter != head) {
a = raw_list_entry(iter, ACTIVE_EVENT_STRUCT, idle_tick_list);
iter_temp = iter->next;
if (a->tick_ctr) {
--a->tick_ctr;
if (a->tick_ctr == 0) {
list_delete(iter);
idle_event_end_post(a, STM_TIMEOUT_SIG, 0);
}
}
iter = iter_temp;
}
}
void idle_run(void)
{
ACTIVE_EVENT_STRUCT *a;
STATE_EVENT temp;
ACTIVE_EVENT_STRUCT_CB *acb;
RAW_U8 x;
RAW_U8 y;
RAW_U8 idle_high_priority;
RAW_SR_ALLOC();
while (1) {
RAW_CRITICAL_ENTER();
/*if get events then process it*/
if (raw_idle_rdy_grp) {
y = raw_idle_map_table[raw_idle_rdy_grp];
x = y >> 3;
idle_high_priority = (y + raw_idle_map_table[raw_rdy_tbl[x]]);
acb = &active_idle_task[idle_high_priority];
a = active_idle_task[idle_high_priority].act;
--a->nUsed;
if (a->nUsed == 0) {
raw_rdy_tbl[a->priority_y] &= (RAW_U8)~a->priority_bit_x;
if (raw_rdy_tbl[a->priority_y] == 0) { /* Clear event grp bit if this was only task pending */
raw_idle_rdy_grp &= (RAW_U8)~a->priority_bit_y;
}
}
temp.sig = acb->queue[a->tail].sig;
temp.which_pool = acb->queue[a->tail].para;
a->tail++;
if (a->tail == acb->end) {
a->tail = 0;
}
RAW_CRITICAL_EXIT();
#if (RAW_FSM_ACTIVE > 0)
fsm_exceute(&a->super, &temp);
#else
hsm_exceute(&a->super, &temp);
#endif
}
else {
RAW_CRITICAL_EXIT();
RAW_CPU_DISABLE();
if (raw_idle_rdy_grp == 0) {
idle_event_user();
}
RAW_CPU_ENABLE();
}
}
}
#endif