-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
xTimer: port stuff from el rato (#343)
- Loading branch information
Showing
2 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,82 @@ | ||
#include "xTimer.h" | ||
#include "xMath.h" | ||
|
||
#include <types.h> | ||
|
||
static U32 sPauseTimerHash[] = | ||
{ | ||
0xBC345600, 0xBC345609, | ||
0xBC345683, 0xBC34568C, | ||
0xBC345706, 0xBC34570F, | ||
0xBC345789, 0xBC345792, | ||
0xBC34580C, 0xBC345815, | ||
0xBC34588F, 0xBC345898, | ||
0xBC345912, 0xBC34591B, | ||
0xBC345995, 0xBC34599E, | ||
0xBC345A18, 0xBC345A21, | ||
0xBC345A9B, 0xBC345AA4, | ||
}; | ||
|
||
F32 GetRandomizedTime(xTimerAsset* tasset) | ||
{ | ||
U32 halfRangeMilli = 1000.0f * tasset->randomRange; | ||
if (halfRangeMilli == 0) { | ||
return tasset->seconds; | ||
} | ||
|
||
S32 offset = xrand() % (halfRangeMilli * 2) - halfRangeMilli; | ||
F32 time = tasset->seconds + offset / 1000.0f; | ||
return time; | ||
} | ||
|
||
void xTimerInit(void* b, void* tasset) | ||
{ | ||
xTimerInit((xBase*)b, (xTimerAsset*)tasset); | ||
} | ||
|
||
S32 xTimer_ObjIDIsPauseTimer(U32 id) | ||
{ | ||
if (id == 0xCB3F6340) return TRUE; | ||
if (id >= 0x016FC9F0 && id <= 0x016FC9F9) return TRUE; | ||
|
||
S32 foo = (id >= 0xBC345600); | ||
S32 bar = (id <= 0xBC345AA4); | ||
if (foo && bar) { | ||
for (S32 i = 0; i < 10; i++) { | ||
if (id >= sPauseTimerHash[i*2] && id <= sPauseTimerHash[i*2+1]) { | ||
return TRUE; | ||
} | ||
} | ||
} | ||
|
||
return FALSE; | ||
} | ||
|
||
void xTimerInit(xBase* b, xTimerAsset* tasset) | ||
{ | ||
xBaseInit(b, tasset); | ||
|
||
xTimer* t = (xTimer*)b; | ||
|
||
t->eventFunc = xTimerEventCB; | ||
t->tasset = tasset; | ||
|
||
if (t->linkCount) { | ||
t->link = (xLinkAsset*)((U8*)t->tasset + sizeof(xTimerAsset)); | ||
} else { | ||
t->link = NULL; | ||
} | ||
|
||
t->state = 0; | ||
t->secondsLeft = GetRandomizedTime(tasset); | ||
t->runsInPause = xTimer_ObjIDIsPauseTimer(b->id); | ||
t->flags = 0; | ||
} | ||
|
||
void xTimerReset(xTimer* ent) | ||
{ | ||
xBaseReset(ent, ent->tasset); | ||
ent->state = 0; | ||
ent->secondsLeft = GetRandomizedTime(ent->tasset); | ||
ent->flags = 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters