nkeynes@265: /** nkeynes@561: * $Id$ nkeynes@265: * nkeynes@265: * Simple implementation of one-shot timers. Effectively this allows IO nkeynes@265: * devices to wait until a particular time before completing. We expect nkeynes@265: * there to be at least half a dozen or so continually scheduled events nkeynes@265: * (TMU and PVR2), peaking around 20+. nkeynes@265: * nkeynes@265: * Copyright (c) 2005 Nathan Keynes. nkeynes@265: * nkeynes@265: * This program is free software; you can redistribute it and/or modify nkeynes@265: * it under the terms of the GNU General Public License as published by nkeynes@265: * the Free Software Foundation; either version 2 of the License, or nkeynes@265: * (at your option) any later version. nkeynes@265: * nkeynes@265: * This program is distributed in the hope that it will be useful, nkeynes@265: * but WITHOUT ANY WARRANTY; without even the implied warranty of nkeynes@265: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the nkeynes@265: * GNU General Public License for more details. nkeynes@265: */ nkeynes@265: nkeynes@736: #ifndef lxdream_eventq_H nkeynes@736: #define lxdream_eventq_H 1 nkeynes@736: nkeynes@736: #include "lxdream.h" nkeynes@736: nkeynes@736: #ifdef __cplusplus nkeynes@736: extern "C" { nkeynes@736: #endif nkeynes@265: nkeynes@265: #define NOT_SCHEDULED 0xFFFFFFFF /* Sentinel value */ nkeynes@265: nkeynes@265: nkeynes@265: typedef void (*event_func_t)(int eventid); nkeynes@265: nkeynes@265: /** nkeynes@265: * Register the callback to be associated with the given event ID. nkeynes@265: * Note: These should be registered at init time and never changed. nkeynes@265: */ nkeynes@265: void register_event_callback( int eventid, event_func_t func ); nkeynes@265: nkeynes@265: /** nkeynes@265: * Schedule a new pending event. nkeynes@265: * @param eventid Unique ID identifying the event in question (used to remove it nkeynes@265: * at a later time). If the eventid is scheduled more than once, only the lastest nkeynes@265: * schedule for that ID will be valid. nkeynes@265: * @param nanosecs Nanoseconds from the current SH4 time at which the event nkeynes@265: * should occur. nkeynes@265: */ nkeynes@265: void event_schedule( int eventid, uint32_t nanosecs ); nkeynes@265: nkeynes@265: /** nkeynes@265: * Schedule a long-duration pending event nkeynes@265: */ nkeynes@265: void event_schedule_long( int eventid, uint32_t seconds, uint32_t nanosecs ); nkeynes@265: nkeynes@265: /** nkeynes@265: * Remove a previously created event without triggering it. This is usually nkeynes@265: * only used when an operation is aborted. nkeynes@265: */ nkeynes@265: void event_cancel( int eventid ); nkeynes@265: nkeynes@265: /** nkeynes@265: * Return the slice cycle time of the next event, or NOT_SCHEDULED nkeynes@265: * if no events are scheduled for this time slice. nkeynes@265: */ nkeynes@265: uint32_t event_get_next_time(); nkeynes@265: nkeynes@265: /** nkeynes@265: * Execute the event on the top of the queue, and remove it. nkeynes@265: */ nkeynes@265: void event_execute(); nkeynes@265: nkeynes@265: #define MAX_EVENT_ID 128 nkeynes@265: nkeynes@265: /* Events 1..96 are defined as the corresponding ASIC events. */ nkeynes@265: nkeynes@619: #define EVENT_TMU0 97 nkeynes@619: #define EVENT_TMU1 98 nkeynes@619: #define EVENT_TMU2 99 nkeynes@736: nkeynes@736: #ifdef __cplusplus nkeynes@736: } nkeynes@736: #endif nkeynes@736: nkeynes@736: #endif /* !lxdream_eventq_H */