1 /*---------------------------------------------------------------------------* 2 Project: OS Alarm API 3 File: OSAlarm.h 4 5 Copyright (C) Nintendo. All rights reserved. 6 7 These coded instructions, statements, and computer programs contain 8 proprietary information of Nintendo of America Inc. and/or Nintendo 9 Company Ltd., and are protected by Federal copyright law. They may 10 not be disclosed to third parties or copied or duplicated in any form, 11 in whole or in part, without the prior written consent of Nintendo. 12 13 *---------------------------------------------------------------------------*/ 14 15 #ifndef __OSALARM_H__ 16 #define __OSALARM_H__ 17 18 #include <types.h> 19 #include <cafe/os/OSContext.h> 20 #include <cafe/os/OSEvent.h> 21 #include <cafe/os/OSThread.h> 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 typedef struct OSAlarmQueue OSAlarmQueue; 28 typedef unsigned long OSAlarmHandle; 29 typedef unsigned long OSAlarmState; 30 typedef void (*OSAlarmHandler)(OSAlarm* alarm, OSContext* context); 31 32 enum 33 { 34 OS_ALARM_BLOCK, 35 OS_ALARM_NOBLOCK 36 }; 37 38 #define OSALARMQUEUE_TXT_TAG 0x614C6d51 // 'aLmQ' 0x614C6D51 39 40 struct OSAlarmQueue 41 { 42 u32 txtTag; // 'aLmQ' 0x614C6D51 43 char * name; // debug name or NULL 44 u32 os_reserved1; 45 46 OSThreadQueue queue; 47 OSAlarm* head; 48 OSAlarm* tail; 49 }; 50 51 #define OSALARM_TXT_TAG 0x614C724D 52 53 struct OSAlarm 54 { 55 u32 txtTag; // 'aLrM' 0x614C724D 56 char * name; // debug name or NULL 57 u32 os_reserved1; 58 59 OSAlarmHandler handler; 60 u32 tag; 61 OSTime nextFire; 62 63 OSAlarm* prev; 64 OSAlarm* next; 65 66 // Periodic alarm 67 OSTime period; 68 OSTime tbrStart; 69 70 // User data 71 void* userData; 72 73 // Alarm state: idle or running or before callback 74 OSAlarmState state; 75 76 OSThreadQueue waitQueue; 77 78 OSAlarmQueue* alarmQueue; 79 // Context of interrupted thread 80 OSContext* context; 81 }; 82 83 void OSCreateAlarm ( OSAlarm* alarm ); 84 void OSCreateAlarmEx ( OSAlarm* alarm, char * name ); 85 86 BOOL OSSetAlarm ( OSAlarm* alarm, 87 OSTime tick, 88 OSAlarmHandler handler); 89 90 BOOL OSSetPeriodicAlarm ( OSAlarm* alarm, 91 OSTime start, 92 OSTime period, 93 OSAlarmHandler handler); 94 95 void OSSetAlarmTag ( OSAlarm* alarm, u32 tag ); 96 void OSSetAlarmUserData ( OSAlarm* alarm, void* data ); 97 void* OSGetAlarmUserData ( const OSAlarm* alarm ); 98 99 BOOL OSCancelAlarm ( OSAlarm* alarm ); 100 void OSCancelAlarms ( u32 tag ); 101 BOOL OSWaitAlarm ( OSAlarm* alarm ); 102 103 #ifdef __cplusplus 104 } 105 #endif 106 107 #endif // __OSALARM_H__ 108 109