OpenCores
URL https://opencores.org/ocsvn/pcie_ds_dma/pcie_ds_dma/trunk

Subversion Repositories pcie_ds_dma

[/] [pcie_ds_dma/] [trunk/] [soft/] [linux/] [driver/] [pexdrv/] [event.c] - Blame information for rev 6

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 dsmv
/***************************************************************************
2
 *            Event.c
3
 *
4
 *  Mon Apr 24 11:37:38 2006
5
 *  Copyright  2006  User
6
 *  Email
7
 ****************************************************************************/
8
////////////////////////////////////////////////////////////////////////////////
9
#include <linux/kernel.h>
10
#define __NO_VERSION__
11
#include <linux/module.h>
12
#include <linux/types.h>
13
//#include <linux/jiffies.h>
14
#include <linux/delay.h>
15
#include <linux/pci.h>
16
#include <linux/interrupt.h>
17
#include <linux/bitops.h>
18
#include <linux/wait.h>
19
#include <linux/sched.h>
20
////////////////////////////////////////////////////////////////////////////////
21
#ifndef _EVENT_H_
22
        #include "event.h"
23
#endif
24
////////////////////////////////////////////////////////////////////////////////
25
//
26
KEVENT *CreateKevent ( void )
27
{
28
    return NULL;
29
}
30
////////////////////////////////////////////////////////////////////////////////
31
//
32
int InitKevent ( KEVENT * event )
33
{
34
    init_waitqueue_head ( &event->m_wq );
35
    atomic_set ( &event->m_flag, 0 );
36
    event->m_async = NULL;
37
 
38
    return 0;
39
}
40
////////////////////////////////////////////////////////////////////////////////
41
//
42
int ResetEvent ( KEVENT * event )
43
{
44
    //printk("<0>%s() %p\n", __FUNCTION__, event);
45
    atomic_set ( &event->m_flag, 0 );
46
    return 0;
47
}
48
////////////////////////////////////////////////////////////////////////////////
49
//
50
int SetEvent ( KEVENT * event )
51
{
52
    atomic_set ( &event->m_flag, 1 );   //for kernel space...
53
 
54
    wake_up_interruptible( &event->m_wq );
55
 
56
    //printk("<0>%s(): %p\n", __FUNCTION__, event);
57
 
58
    //if (event->m_async)
59
    //  kill_fasync(&event->m_async, SIGIO, POLL_IN|POLL_OUT);
60
 
61
    return 0;
62
}
63
////////////////////////////////////////////////////////////////////////////////
64
//
65
int CheckEventFlag ( KEVENT * event )
66
{
67
    //printk("<0>%s(): %p\n", __FUNCTION__, event);
68
 
69
    if ( atomic_read ( &event->m_flag ) )
70
    {
71
        //ResetEvent ( event );
72
        return 1;
73
    }
74
    return 0;
75
}
76
 
77
////////////////////////////////////////////////////////////////////////////////
78
 
79
#define ms_to_jiffies( ms ) (HZ*ms/1000)
80
#define jiffies_to_ms( jf ) (jf*1000/HZ)
81
 
82
////////////////////////////////////////////////////////////////////////////////
83
//
84
int WaitEvent( KEVENT * event, u32 timeout )
85
{
86
    int status = -1;
87
 
88
    //printk("<0>%s()\n", __FUNCTION__);
89
 
90
#ifdef DZYTOOLS_2_4_X
91
    status = interruptible_sleep_on_timeout( &event->m_wq, ms_to_jiffies(timeout) );
92
#else
93
    status = wait_event_interruptible_timeout( event->m_wq, atomic_read(&event->m_flag), ms_to_jiffies(timeout) );
94
#endif
95
 
96
    if(!status) {
97
        printk("<0>%s(): TIMEOUT\n", __FUNCTION__);
98
        return -ETIMEDOUT;
99
    }
100
 
101
    atomic_set ( &event->m_flag, 0 );
102
 
103
    return 0;
104
}
105
 
106
////////////////////////////////////////////////////////////////////////////////
107
//
108
int GrabEvent( KEVENT * event, u32 timeout )
109
{
110
    //printk ( "<0>%s(): E %p, T %d\n", __FUNCTION__, event, timeout );
111
 
112
    if( CheckEventFlag( event ) ) {
113
        ResetEvent(event);
114
        return 0;
115
    }
116
 
117
    return WaitEvent(event, timeout);
118
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.