Search
lxdream.org :: lxdream/src/eventq.h
lxdream 0.9.1
released Jun 29
Download Now
filename src/eventq.h
changeset 736:a02d1475ccfd
prev619:0800a0137472
next850:28782ebbd01d
author nkeynes
date Mon Jul 14 07:44:42 2008 +0000 (12 years ago)
permissions -rw-r--r--
last change Re-indent everything consistently
Fix include guards for consistency as well
file annotate diff log raw
nkeynes@265
     1
/**
nkeynes@561
     2
 * $Id$
nkeynes@265
     3
 *
nkeynes@265
     4
 * Simple implementation of one-shot timers. Effectively this allows IO
nkeynes@265
     5
 * devices to wait until a particular time before completing. We expect 
nkeynes@265
     6
 * there to be at least half a dozen or so continually scheduled events
nkeynes@265
     7
 * (TMU and PVR2), peaking around 20+.
nkeynes@265
     8
 *
nkeynes@265
     9
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@265
    10
 *
nkeynes@265
    11
 * This program is free software; you can redistribute it and/or modify
nkeynes@265
    12
 * it under the terms of the GNU General Public License as published by
nkeynes@265
    13
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@265
    14
 * (at your option) any later version.
nkeynes@265
    15
 *
nkeynes@265
    16
 * This program is distributed in the hope that it will be useful,
nkeynes@265
    17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@265
    18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@265
    19
 * GNU General Public License for more details.
nkeynes@265
    20
 */
nkeynes@265
    21
nkeynes@736
    22
#ifndef lxdream_eventq_H
nkeynes@736
    23
#define lxdream_eventq_H 1
nkeynes@736
    24
nkeynes@736
    25
#include "lxdream.h"
nkeynes@736
    26
nkeynes@736
    27
#ifdef __cplusplus
nkeynes@736
    28
extern "C" {
nkeynes@736
    29
#endif
nkeynes@265
    30
nkeynes@265
    31
#define NOT_SCHEDULED 0xFFFFFFFF /* Sentinel value */
nkeynes@265
    32
nkeynes@265
    33
nkeynes@265
    34
typedef void (*event_func_t)(int eventid);
nkeynes@265
    35
nkeynes@265
    36
/**
nkeynes@265
    37
 * Register the callback to be associated with the given event ID.
nkeynes@265
    38
 * Note: These should be registered at init time and never changed.
nkeynes@265
    39
 */
nkeynes@265
    40
void register_event_callback( int eventid, event_func_t func );
nkeynes@265
    41
nkeynes@265
    42
/**
nkeynes@265
    43
 * Schedule a new pending event.
nkeynes@265
    44
 * @param eventid Unique ID identifying the event in question (used to remove it
nkeynes@265
    45
 * at a later time). If the eventid is scheduled more than once, only the lastest
nkeynes@265
    46
 * schedule for that ID will be valid.
nkeynes@265
    47
 * @param nanosecs Nanoseconds from the current SH4 time at which the event
nkeynes@265
    48
 * should occur.
nkeynes@265
    49
 */
nkeynes@265
    50
void event_schedule( int eventid, uint32_t nanosecs );
nkeynes@265
    51
nkeynes@265
    52
/**
nkeynes@265
    53
 * Schedule a long-duration pending event
nkeynes@265
    54
 */
nkeynes@265
    55
void event_schedule_long( int eventid, uint32_t seconds, uint32_t nanosecs );
nkeynes@265
    56
nkeynes@265
    57
/**
nkeynes@265
    58
 * Remove a previously created event without triggering it. This is usually
nkeynes@265
    59
 * only used when an operation is aborted.
nkeynes@265
    60
 */
nkeynes@265
    61
void event_cancel( int eventid );
nkeynes@265
    62
nkeynes@265
    63
/**
nkeynes@265
    64
 * Return the slice cycle time of the next event, or NOT_SCHEDULED
nkeynes@265
    65
 * if no events are scheduled for this time slice.
nkeynes@265
    66
 */
nkeynes@265
    67
uint32_t event_get_next_time();
nkeynes@265
    68
nkeynes@265
    69
/**
nkeynes@265
    70
 * Execute the event on the top of the queue, and remove it.
nkeynes@265
    71
 */
nkeynes@265
    72
void event_execute();
nkeynes@265
    73
nkeynes@265
    74
#define MAX_EVENT_ID 128
nkeynes@265
    75
nkeynes@265
    76
/* Events 1..96 are defined as the corresponding ASIC events. */
nkeynes@265
    77
nkeynes@619
    78
#define EVENT_TMU0 97
nkeynes@619
    79
#define EVENT_TMU1 98
nkeynes@619
    80
#define EVENT_TMU2 99
nkeynes@736
    81
nkeynes@736
    82
#ifdef __cplusplus
nkeynes@736
    83
}
nkeynes@736
    84
#endif
nkeynes@736
    85
nkeynes@736
    86
#endif /* !lxdream_eventq_H */
.