/***************************************************************************
|
/***************************************************************************
|
* Event.c
|
* Event.c
|
*
|
*
|
* Mon Apr 24 11:37:38 2006
|
* Mon Apr 24 11:37:38 2006
|
* Copyright 2006 User
|
* Copyright 2006 User
|
* Email
|
* Email
|
****************************************************************************/
|
****************************************************************************/
|
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
#include <linux/kernel.h>
|
#include <linux/kernel.h>
|
#define __NO_VERSION__
|
#define __NO_VERSION__
|
#include <linux/module.h>
|
#include <linux/module.h>
|
#include <linux/types.h>
|
#include <linux/types.h>
|
//#include <linux/jiffies.h>
|
//#include <linux/jiffies.h>
|
#include <linux/delay.h>
|
#include <linux/delay.h>
|
#include <linux/pci.h>
|
#include <linux/pci.h>
|
#include <linux/interrupt.h>
|
#include <linux/interrupt.h>
|
#include <linux/bitops.h>
|
#include <linux/bitops.h>
|
#include <linux/wait.h>
|
#include <linux/wait.h>
|
#include <linux/sched.h>
|
#include <linux/sched.h>
|
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
#ifndef _EVENT_H_
|
#ifndef _EVENT_H_
|
#include "event.h"
|
#include "event.h"
|
#endif
|
#endif
|
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
//
|
//
|
KEVENT *CreateKevent ( void )
|
KEVENT *CreateKevent ( void )
|
{
|
{
|
return NULL;
|
return NULL;
|
}
|
}
|
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
//
|
//
|
int InitKevent ( KEVENT * event )
|
int InitKevent ( KEVENT * event )
|
{
|
{
|
init_waitqueue_head ( &event->m_wq );
|
init_waitqueue_head ( &event->m_wq );
|
atomic_set ( &event->m_flag, 0 );
|
atomic_set ( &event->m_flag, 0 );
|
event->m_async = NULL;
|
event->m_async = NULL;
|
|
|
return 0;
|
return 0;
|
}
|
}
|
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
//
|
//
|
int ResetEvent ( KEVENT * event )
|
int ResetEvent ( KEVENT * event )
|
{
|
{
|
//printk("<0>%s() %p\n", __FUNCTION__, event);
|
//printk("%s() %p\n", __FUNCTION__, event);
|
atomic_set ( &event->m_flag, 0 );
|
atomic_set ( &event->m_flag, 0 );
|
return 0;
|
return 0;
|
}
|
}
|
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
//
|
//
|
int SetEvent ( KEVENT * event )
|
int SetEvent ( KEVENT * event )
|
{
|
{
|
atomic_set ( &event->m_flag, 1 ); //for kernel space...
|
atomic_set ( &event->m_flag, 1 ); //for kernel space...
|
|
|
wake_up_interruptible( &event->m_wq );
|
wake_up_interruptible( &event->m_wq );
|
|
|
//printk("<0>%s(): %p\n", __FUNCTION__, event);
|
//printk("%s(): %p\n", __FUNCTION__, event);
|
|
|
//if (event->m_async)
|
//if (event->m_async)
|
// kill_fasync(&event->m_async, SIGIO, POLL_IN|POLL_OUT);
|
// kill_fasync(&event->m_async, SIGIO, POLL_IN|POLL_OUT);
|
|
|
return 0;
|
return 0;
|
}
|
}
|
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
//
|
//
|
int CheckEventFlag ( KEVENT * event )
|
int CheckEventFlag ( KEVENT * event )
|
{
|
{
|
//printk("<0>%s(): %p\n", __FUNCTION__, event);
|
//printk("%s(): %p\n", __FUNCTION__, event);
|
|
|
if ( atomic_read ( &event->m_flag ) )
|
if ( atomic_read ( &event->m_flag ) )
|
{
|
{
|
//ResetEvent ( event );
|
//ResetEvent ( event );
|
return 1;
|
return 1;
|
}
|
}
|
return 0;
|
return 0;
|
}
|
}
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
#define ms_to_jiffies( ms ) (HZ*ms/1000)
|
#define ms_to_jiffies( ms ) (HZ*ms/1000)
|
#define jiffies_to_ms( jf ) (jf*1000/HZ)
|
#define jiffies_to_ms( jf ) (jf*1000/HZ)
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
//
|
//
|
int WaitEvent( KEVENT * event, u32 timeout )
|
int WaitEvent( KEVENT * event, u32 timeout )
|
{
|
{
|
int status = -1;
|
int status = -1;
|
|
|
//printk("<0>%s()\n", __FUNCTION__);
|
//printk("%s()\n", __FUNCTION__);
|
|
|
#ifdef DZYTOOLS_2_4_X
|
#ifdef DZYTOOLS_2_4_X
|
status = interruptible_sleep_on_timeout( &event->m_wq, ms_to_jiffies(timeout) );
|
status = interruptible_sleep_on_timeout( &event->m_wq, ms_to_jiffies(timeout) );
|
#else
|
#else
|
status = wait_event_interruptible_timeout( event->m_wq, atomic_read(&event->m_flag), ms_to_jiffies(timeout) );
|
status = wait_event_interruptible_timeout( event->m_wq, atomic_read(&event->m_flag), ms_to_jiffies(timeout) );
|
#endif
|
#endif
|
|
|
if(!status) {
|
if(!status) {
|
printk("<0>%s(): TIMEOUT\n", __FUNCTION__);
|
printk("%s(): TIMEOUT\n", __FUNCTION__);
|
return -ETIMEDOUT;
|
return -ETIMEDOUT;
|
}
|
}
|
|
|
atomic_set ( &event->m_flag, 0 );
|
atomic_set ( &event->m_flag, 0 );
|
|
|
return 0;
|
return 0;
|
}
|
}
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
//
|
//
|
int GrabEvent( KEVENT * event, u32 timeout )
|
int GrabEvent( KEVENT * event, u32 timeout )
|
{
|
{
|
//printk ( "<0>%s(): E %p, T %d\n", __FUNCTION__, event, timeout );
|
//printk ( "%s(): E %p, T %d\n", __FUNCTION__, event, timeout );
|
|
|
if( CheckEventFlag( event ) ) {
|
if( CheckEventFlag( event ) ) {
|
ResetEvent(event);
|
ResetEvent(event);
|
return 0;
|
return 0;
|
}
|
}
|
|
|
return WaitEvent(event, timeout);
|
return WaitEvent(event, timeout);
|
}
|
}
|
|
|