source: pacpussensors/trunk/CanGateway/driver/kvaser/linux/queue.h@ 109

Last change on this file since 109 was 97, checked in by DHERBOMEZ Gérald, 9 years ago

add include files for kvaser

File size: 4.7 KB
Line 
1/*
2** Copyright 2012 by Kvaser AB, Mölndal, Sweden
3** http://www.kvaser.com
4**
5** This software is dual licensed under the following two licenses:
6** BSD-new and GPLv2. You may use either one. See the included
7** COPYING file for details.
8**
9** License: BSD-new
10** ===============================================================================
11** Redistribution and use in source and binary forms, with or without
12** modification, are permitted provided that the following conditions are met:
13** * Redistributions of source code must retain the above copyright
14** notice, this list of conditions and the following disclaimer.
15** * Redistributions in binary form must reproduce the above copyright
16** notice, this list of conditions and the following disclaimer in the
17** documentation and/or other materials provided with the distribution.
18** * Neither the name of the <organization> nor the
19** names of its contributors may be used to endorse or promote products
20** derived from this software without specific prior written permission.
21**
22** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
23** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25** DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
26** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32**
33**
34** License: GPLv2
35** ===============================================================================
36** This program is free software; you can redistribute it and/or
37** modify it under the terms of the GNU General Public License
38** as published by the Free Software Foundation; either version 2
39** of the License, or (at your option) any later version.
40**
41** This program is distributed in the hope that it will be useful,
42** but WITHOUT ANY WARRANTY; without even the implied warranty of
43** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
44** GNU General Public License for more details.
45**
46** You should have received a copy of the GNU General Public License
47** along with this program; if not, write to the Free Software
48** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
49**
50** ---------------------------------------------------------------------------
51**/
52
53// FIFO
54// This abstraction currently only keeps track of indices into a queue,
55// the actual data needs to be kept elsewhere.
56//
57// head points to next place to put new data (back/push)
58// tail points to the oldest data (front/pop)
59// If they are equal, the queue is empty, so
60// only size-1 elements fit.
61//
62// Without USE_LOCKS defined, the behaviour is
63// exactly the same as the old code.
64
65#ifndef QUEUE_H
66#define QUEUE_H
67
68#include "osif_functions_kernel.h"
69#include "osif_kernel.h"
70
71
72typedef enum {Normal_lock, Softirq_lock, Irq_lock} Lock_type;
73typedef struct {
74 int size;
75 int head;
76 int tail;
77 atomic_t length; // For length queries without locking
78 unsigned int flags; // Only used when holding the lock (Sparc incompatible)!
79 OS_IF_WAITQUEUE_HEAD space_event;
80 Lock_type lock_type;
81 OS_IF_LOCK lock;
82 int locked; // For debugging
83 int line; // For debugging
84} Queue;
85
86
87extern void queue_reinit(Queue *queue);
88extern void queue_init(Queue *queue, int size);
89extern void queue_irq_lock(Queue *queue);
90extern int queue_length(Queue *queue);
91extern int queue_full(Queue *queue);
92extern int queue_empty(Queue *queue);
93
94// queue_back/front _must_ always be paired with queue_push/pop or _release.
95// The first two grab the Queue lock and the last three release it again.
96// Make _sure_ not to sleep inbetween and do as little work as possible
97// (the interrupts are disabled while holding the lock).
98extern int queue_back(Queue *queue);
99extern void queue_push(Queue *queue);
100extern int queue_front(Queue *queue);
101extern void queue_pop(Queue *queue);
102extern void queue_release(Queue *queue);
103
104extern void queue_add_wait_for_space(Queue *queue, OS_IF_WAITQUEUE *waiter);
105extern void queue_remove_wait_for_space(Queue *queue, OS_IF_WAITQUEUE *waiter);
106extern void queue_add_wait_for_data(Queue *queue, OS_IF_WAITQUEUE *waiter);
107extern void queue_wakeup_on_space(Queue *queue);
108extern void queue_wakeup_on_data(Queue *queue);
109extern OS_IF_WAITQUEUE_HEAD *queue_space_event(Queue *queue);
110
111#endif
Note: See TracBrowser for help on using the repository browser.