1 /*---------------------------------------------------------------------------* 2 Project: TwlSDK - OS - include 3 File: alarm.h 4 5 Copyright 2003-2008 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 $Date:: 2008-09-17#$ 14 $Rev: 8556 $ 15 $Author: okubata_ryoma $ 16 17 *---------------------------------------------------------------------------*/ 18 19 #ifndef NITRO_OS_ALARM_H_ 20 #define NITRO_OS_ALARM_H_ 21 22 #ifdef __cplusplus 23 extern "C" { 24 #endif 25 26 #include <nitro/misc.h> 27 #include <nitro/types.h> 28 #include <nitro/os/common/thread.h> 29 #include <nitro/os/common/tick.h> 30 31 32 //-------------------------------------------------------------------------------- 33 //---- Alarm Handler 34 typedef void (*OSAlarmHandler) (void *); 35 36 37 //---- struct of Alarm 38 //typedef struct OSiAlarm OSAlarm; // this is decleared in thread.h 39 struct OSiAlarm 40 { 41 OSAlarmHandler handler; 42 void *arg; 43 44 u32 tag; 45 OSTick fire; 46 OSAlarm *prev; 47 OSAlarm *next; 48 49 //---- for periodic alarm 50 OSTick period; 51 OSTick start; 52 }; 53 54 //---- Alarm resource 55 typedef struct OSAlarmResource 56 { 57 int num; 58 } 59 OSAlarmResource; 60 61 //-------------------------------------------------------------------------------- 62 /*---------------------------------------------------------------------------* 63 Name: OS_InitAlarm 64 65 Description: initalize alarm system 66 67 Arguments: None. 68 69 Returns: None. 70 *---------------------------------------------------------------------------*/ 71 void OS_InitAlarm(void); 72 73 74 /*---------------------------------------------------------------------------* 75 Name: OS_EndAlarm 76 77 Description: end alarm system 78 79 Arguments: None 80 81 Returns: None 82 *---------------------------------------------------------------------------*/ 83 void OS_EndAlarm(void); 84 85 86 /*---------------------------------------------------------------------------* 87 Name: OS_IsAlarmAvailable 88 89 Description: check alarm system is available 90 91 Arguments: None 92 93 Returns: if available, TRUE. 94 *---------------------------------------------------------------------------*/ 95 BOOL OS_IsAlarmAvailable(void); 96 97 98 /*---------------------------------------------------------------------------* 99 Name: OS_CreateAlarm 100 101 Description: Create alarm 102 103 Arguments: alarm pointer to alarm to be initialized 104 105 Returns: None. 106 *---------------------------------------------------------------------------*/ 107 void OS_CreateAlarm(OSAlarm *alarm); 108 109 110 /*---------------------------------------------------------------------------* 111 Name: OS_SetAlarm 112 113 Description: Set alarm as a relative time 114 115 Arguments: alarm pointer to alarm to be set 116 tick ticks to count before firing 117 handler alarm handler to be called 118 arg argument of handler 119 120 Returns: None. 121 *---------------------------------------------------------------------------*/ 122 void OS_SetAlarm(OSAlarm *alarm, OSTick tick, OSAlarmHandler handler, void *arg); 123 124 125 /*---------------------------------------------------------------------------* 126 Name: OS_SetPeriodicAlarm 127 128 Description: set periodic alarm 129 130 Arguments: alarm pointer to alarm to be set 131 start origin of the period in absolute time 132 period ticks to count for each period 133 handler alarm handler to be called 134 arg argument of handler 135 136 Returns: None. 137 *---------------------------------------------------------------------------*/ 138 void OS_SetPeriodicAlarm(OSAlarm *alarm, OSTick start, OSTick period, OSAlarmHandler handler, 139 void *arg); 140 141 142 /*---------------------------------------------------------------------------* 143 Name: OS_SetAlarmTag 144 145 Description: set tag which is used OS_CancelAlarms 146 147 Arguments: alarm alarm to be set tag 148 tag tagNo 149 150 Returns: None. 151 *---------------------------------------------------------------------------*/ 152 void OS_SetAlarmTag(OSAlarm *alarm, u32 tag); 153 154 155 /*---------------------------------------------------------------------------* 156 Name: OS_CancelAlarm 157 158 Description: Cancel alarm 159 160 Arguments: alarm pointer to alarm to be canceled 161 162 Returns: None. 163 *---------------------------------------------------------------------------*/ 164 void OS_CancelAlarm(OSAlarm *alarm); 165 166 167 /*---------------------------------------------------------------------------* 168 Name: OS_CancelAlarms 169 170 Description: cancel alarms which have specified tag 171 172 Arguments: tag tagNo. to be cancelled. not 0 173 174 Returns: None. 175 *---------------------------------------------------------------------------*/ 176 void OS_CancelAlarms(u32 tag); 177 178 179 /*---------------------------------------------------------------------------* 180 Name: OS_CancelAllAlarms 181 182 Description: cancel all alarms 183 184 Arguments: None 185 186 Returns: None. 187 *---------------------------------------------------------------------------*/ 188 void OS_CancelAllAlarms(void); 189 190 191 //================================================================================ 192 // FOR DEBUG 193 //================================================================================ 194 /*---------------------------------------------------------------------------* 195 Name: OS_GetNumberOfAlarm 196 197 Description: get number of alarm 198 199 Arguments: None 200 201 Returns: number of alarm 202 *---------------------------------------------------------------------------*/ 203 int OS_GetNumberOfAlarm(void); 204 205 /*---------------------------------------------------------------------------* 206 Name: OS_GetAlarmResource 207 208 Description: store resources of alarm to specified pointer 209 210 Arguments: resource pointer to store alarm resources 211 212 Returns: TRUE ... success (always return this now) 213 FALSE ... fail 214 *---------------------------------------------------------------------------*/ 215 BOOL OS_GetAlarmResource(OSAlarmResource *resource); 216 217 218 //================================================================================ 219 // The following definitions or declarations are for internal use. 220 // Don't call these from use program. 221 struct OSiAlarmQueue 222 { 223 OSAlarm *head; 224 OSAlarm *tail; 225 }; 226 struct OSiAlarmQueue *OSi_GetAlarmQueue(void); 227 228 229 #ifdef __cplusplus 230 } /* extern "C" */ 231 #endif 232 233 /* NITRO_OS_ALARM_H_ */ 234 #endif 235