1 | /* |
---|
2 | * Defines for low level queue management |
---|
3 | * |
---|
4 | * Author: Ralf Corsepius (corsepiu@faw.uni-ulm.de) |
---|
5 | * |
---|
6 | * COPYRIGHT (c) 1997-1998, Ralf Corsepius, Germany |
---|
7 | * |
---|
8 | * This program is distributed in the hope that it will be useful, |
---|
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
---|
11 | * |
---|
12 | * |
---|
13 | * COPYRIGHT (c) 1998. |
---|
14 | * On-Line Applications Research Corporation (OAR). |
---|
15 | * Copyright assigned to U.S. Government, 1994. |
---|
16 | * |
---|
17 | * The license and distribution terms for this file may be |
---|
18 | * found in the file LICENSE in this distribution or at |
---|
19 | * http://www.OARcorp.com/rtems/license.html. |
---|
20 | * |
---|
21 | * $Id$ |
---|
22 | * |
---|
23 | */ |
---|
24 | |
---|
25 | #ifndef _io_queue_h |
---|
26 | #define _io_queue_h |
---|
27 | |
---|
28 | #include <stdlib.h> /* size_t */ |
---|
29 | |
---|
30 | /* |
---|
31 | * NOTE: size needs to be a power of 2 |
---|
32 | */ |
---|
33 | #define IO_QUEUE(type,size,name) \ |
---|
34 | typedef struct { \ |
---|
35 | volatile type queue[size] ; \ |
---|
36 | volatile unsigned short tail ; \ |
---|
37 | volatile unsigned short head ; \ |
---|
38 | } name ; |
---|
39 | |
---|
40 | #define IO_QUEUE_FULL(queue, size) \ |
---|
41 | ((queue)->tail == (((queue)->head+1) & ((size)-1))) |
---|
42 | |
---|
43 | #define IO_QUEUE_EMPTY(queue) \ |
---|
44 | (((queue)->tail) == ((queue)->head)) |
---|
45 | |
---|
46 | #define IO_QUEUE_INIT(queue) \ |
---|
47 | (queue)->tail = (queue)->head = 0 |
---|
48 | |
---|
49 | #define IO_QUEUE_ADD(queue,size) \ |
---|
50 | (queue)->head = (((queue)->head + 1) & ((size)-1)) |
---|
51 | |
---|
52 | #define IO_QUEUE_SUB(queue,size) \ |
---|
53 | (queue)->tail = (((queue)->tail + 1) & ((size)-1)) |
---|
54 | |
---|
55 | #define IO_QUEUE_PUT(_queue,item) \ |
---|
56 | { \ |
---|
57 | size_t i; \ |
---|
58 | unsigned char* dest = (unsigned char*) ((_queue)->queue[(_queue)->head]); \ |
---|
59 | unsigned char* src = (unsigned char*) (item); \ |
---|
60 | for( i = 0; i < sizeof(item); i++) \ |
---|
61 | { \ |
---|
62 | dest[i] = src[i]; \ |
---|
63 | } \ |
---|
64 | } |
---|
65 | |
---|
66 | #define IO_QUEUE_GET(_queue,item) \ |
---|
67 | {\ |
---|
68 | size_t i; \ |
---|
69 | unsigned char *src = (unsigned char*) (_queue)->queue[(_queue)->tail]; \ |
---|
70 | unsigned char *dest = (unsigned char*) (item); \ |
---|
71 | for( i=0; i< sizeof(item); i++)\ |
---|
72 | {\ |
---|
73 | dest[i] = src[i]; \ |
---|
74 | }\ |
---|
75 | } |
---|
76 | |
---|
77 | #endif |
---|