Zigbee Protocol Controller 1.6.0
process.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2005, Swedish Institute of Computer Science
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the Institute nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * This file is part of the Contiki operating system.
30 *
31 * @(#)$Id: process.h,v 1.17 2010/09/14 18:55:04 dak664 Exp $
32 */
33
54#ifndef __PROCESS_H__
55#define __PROCESS_H__
56
57#ifdef __cplusplus
58extern "C" {
59#endif
60
61#include "sys/pt.h"
62#include "sys/cc.h"
63
64typedef unsigned char process_event_t;
65typedef void *process_data_t;
67
79#define PROCESS_ERR_OK 0
87#define PROCESS_ERR_FULL 1
90#define PROCESS_NONE NULL
91
92#ifndef PROCESS_CONF_NUMEVENTS
93#define PROCESS_CONF_NUMEVENTS 255
94#define PROCESS_CONF_NUMEVENTS_PRINT 64
95#define PROCESS_CONF_NUMEVENTS_ERROR 230
96#endif /* PROCESS_CONF_NUMEVENTS */
97
98#define PROCESS_EVENT_NONE 0x80
99#define PROCESS_EVENT_INIT 0x81
100#define PROCESS_EVENT_POLL 0x82
101#define PROCESS_EVENT_EXIT 0x83
102#define PROCESS_EVENT_SERVICE_REMOVED 0x84
103#define PROCESS_EVENT_CONTINUE 0x85
104#define PROCESS_EVENT_MSG 0x86
105#define PROCESS_EVENT_EXITED 0x87
106#define PROCESS_EVENT_TIMER 0x88
107#define PROCESS_EVENT_COM 0x89
108#define PROCESS_EVENT_MAX 0x8a
109
110#define PROCESS_BROADCAST NULL
111#define PROCESS_ZOMBIE ((struct process *)0x1)
112
127#define PROCESS_BEGIN() PT_BEGIN(process_pt)
128
138#define PROCESS_END() PT_END(process_pt)
139
148#define PROCESS_WAIT_EVENT() PROCESS_YIELD()
149
164#define PROCESS_WAIT_EVENT_UNTIL(c) PROCESS_YIELD_UNTIL(c)
165
171#define PROCESS_YIELD() PT_YIELD(process_pt)
172
185#define PROCESS_YIELD_UNTIL(c) PT_YIELD_UNTIL(process_pt, c)
186
199#define PROCESS_WAIT_UNTIL(c) PT_WAIT_UNTIL(process_pt, c)
200#define PROCESS_WAIT_WHILE(c) PT_WAIT_WHILE(process_pt, c)
201
207#define PROCESS_EXIT() PT_EXIT(process_pt)
208
218#define PROCESS_PT_SPAWN(pt, thread) PT_SPAWN(process_pt, pt, thread)
219
228#define PROCESS_PAUSE() \
229 do { \
230 process_post(PROCESS_CURRENT(), PROCESS_EVENT_CONTINUE, NULL); \
231 PROCESS_WAIT_EVENT(); \
232 } while (0)
233
250#define PROCESS_POLLHANDLER(handler) \
251 if (ev == PROCESS_EVENT_POLL) { \
252 handler; \
253 }
254
265#define PROCESS_EXITHANDLER(handler) \
266 if (ev == PROCESS_EVENT_EXIT) { \
267 handler; \
268 }
269
287#define PROCESS_THREAD(name, ev, data) \
288 static PT_THREAD(process_thread_##name(struct pt *process_pt, \
289 process_event_t ev, \
290 process_data_t data))
291
300#define PROCESS_NAME(name) extern struct process name
301
315#if PROCESS_CONF_NO_PROCESS_NAMES
316#define PROCESS(name, strname) \
317 PROCESS_THREAD(name, ev, data); \
318 struct process name = {NULL, process_thread_##name}
319#else
320#define PROCESS(name, strname) \
321 PROCESS_THREAD(name, ev, data); \
322 struct process name = {NULL, strname, process_thread_##name}
323#endif
324
327struct process {
328 struct process *next;
329#if PROCESS_CONF_NO_PROCESS_NAMES
330#define PROCESS_NAME_STRING(process) ""
331#else
332 const char *name;
333#define PROCESS_NAME_STRING(process) (process)->name
334#endif
336 struct pt pt;
337 unsigned char state, needspoll;
338};
339
354CCIF void process_start(struct process *p, const char *arg) CC_REENTRANT_ARG;
355
377CCIF int process_post(struct process *p,
379 void *procdata) CC_REENTRANT_ARG;
380
395CCIF int process_count_events(const struct process *p,
397 const process_data_t procdata) CC_REENTRANT_ARG;
398
409CCIF void process_post_synch(struct process *p,
411 void *procdata) CC_REENTRANT_ARG;
412
424
434#define PROCESS_CURRENT() process_current
435CCIF extern struct process *process_current;
436
458#define PROCESS_CONTEXT_BEGIN(p) \
459 { \
460 struct process *tmp_current = PROCESS_CURRENT(); \
461 process_current = p
462
473#define PROCESS_CONTEXT_END(p) \
474 process_current = tmp_current; \
475 }
476
489
506
520void process_init(void);
521
535int process_run(void);
536
547
554int process_nevents(void);
555
558CCIF extern struct process *process_list;
559
560#define PROCESS_LIST() process_list
561
562#ifdef __cplusplus
563}
564#endif
565
566#endif /* __PROCESS_H__ */
567
#define CC_REENTRANT_ARG
Definition: cc.h:57
#define CCIF
Definition: contiki-conf.h:24
CCIF struct process * process_list
Definition: process.c:60
process_event_t process_alloc_event(void)
Allocate a global event number.
Definition: process.c:113
void process_poll(struct process *p) CC_REENTRANT_ARG
Definition: process.c:475
int process_is_running(struct process *p) CC_REENTRANT_ARG
Definition: process.c:485
int process_run(void)
Definition: process.c:348
unsigned char process_event_t
Definition: process.h:64
CCIF struct process * process_current
Definition: process.c:61
void process_post_synch(struct process *p, process_event_t ev, process_data_t data) CC_REENTRANT_ARG
Definition: process.c:465
void process_start(struct process *p, const char *arg) CC_REENTRANT_ARG
Definition: process.c:118
uint32_t process_num_events_t
Definition: process.h:66
int process_post(struct process *p, process_event_t ev, process_data_t data) CC_REENTRANT_ARG
Definition: process.c:366
int process_nevents(void)
Definition: process.c:361
void process_init(void)
Initialize the process module.
Definition: process.c:259
void * process_data_t
Definition: process.h:65
void process_exit(struct process *p) CC_REENTRANT_ARG
Cause a process to exit.
Definition: process.c:254
int process_count_events(const struct process *p, process_event_t ev, const process_data_t data) CC_REENTRANT_ARG
Definition: process.c:448
Definition: process.h:327
unsigned char needspoll
Definition: process.h:337
PT_THREAD((*thread)(struct pt *, process_event_t, process_data_t))
unsigned char state
Definition: process.h:337
const char * name
Definition: process.h:332
struct process * next
Definition: process.h:328
Definition: pt.h:54