Search
lxdream.org :: lxdream/src/eventq.h :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/eventq.h
changeset 265:5daf59b7f31b
next561:533f6b478071
author nkeynes
date Sat Jan 06 04:06:36 2007 +0000 (13 years ago)
permissions -rw-r--r--
last change Implement event queue.
Fix pvr2 timing (yes, again).
file annotate diff log raw
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/eventq.h Sat Jan 06 04:06:36 2007 +0000
1.3 @@ -0,0 +1,71 @@
1.4 +/**
1.5 + * $Id: eventq.h,v 1.1 2007-01-06 04:06:36 nkeynes Exp $
1.6 + *
1.7 + * Simple implementation of one-shot timers. Effectively this allows IO
1.8 + * devices to wait until a particular time before completing. We expect
1.9 + * there to be at least half a dozen or so continually scheduled events
1.10 + * (TMU and PVR2), peaking around 20+.
1.11 + *
1.12 + * Copyright (c) 2005 Nathan Keynes.
1.13 + *
1.14 + * This program is free software; you can redistribute it and/or modify
1.15 + * it under the terms of the GNU General Public License as published by
1.16 + * the Free Software Foundation; either version 2 of the License, or
1.17 + * (at your option) any later version.
1.18 + *
1.19 + * This program is distributed in the hope that it will be useful,
1.20 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.21 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.22 + * GNU General Public License for more details.
1.23 + */
1.24 +
1.25 +#include "dream.h"
1.26 +
1.27 +#define NOT_SCHEDULED 0xFFFFFFFF /* Sentinel value */
1.28 +
1.29 +
1.30 +typedef void (*event_func_t)(int eventid);
1.31 +
1.32 +/**
1.33 + * Register the callback to be associated with the given event ID.
1.34 + * Note: These should be registered at init time and never changed.
1.35 + */
1.36 +void register_event_callback( int eventid, event_func_t func );
1.37 +
1.38 +/**
1.39 + * Schedule a new pending event.
1.40 + * @param eventid Unique ID identifying the event in question (used to remove it
1.41 + * at a later time). If the eventid is scheduled more than once, only the lastest
1.42 + * schedule for that ID will be valid.
1.43 + * @param nanosecs Nanoseconds from the current SH4 time at which the event
1.44 + * should occur.
1.45 + */
1.46 +void event_schedule( int eventid, uint32_t nanosecs );
1.47 +
1.48 +/**
1.49 + * Schedule a long-duration pending event
1.50 + */
1.51 +void event_schedule_long( int eventid, uint32_t seconds, uint32_t nanosecs );
1.52 +
1.53 +/**
1.54 + * Remove a previously created event without triggering it. This is usually
1.55 + * only used when an operation is aborted.
1.56 + */
1.57 +void event_cancel( int eventid );
1.58 +
1.59 +/**
1.60 + * Return the slice cycle time of the next event, or NOT_SCHEDULED
1.61 + * if no events are scheduled for this time slice.
1.62 + */
1.63 +uint32_t event_get_next_time();
1.64 +
1.65 +/**
1.66 + * Execute the event on the top of the queue, and remove it.
1.67 + */
1.68 +void event_execute();
1.69 +
1.70 +#define MAX_EVENT_ID 128
1.71 +
1.72 +/* Events 1..96 are defined as the corresponding ASIC events. */
1.73 +
1.74 +
.