1 /*---------------------------------------------------------------------------*
2 Project: TwlSDK - WXC - libraries -
3 File: wxc_scheduler.c
4
5 Copyright 2005-2009 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-12-16#$
14 $Rev: 9661 $
15 $Author: okubata_ryoma $
16 *---------------------------------------------------------------------------*/
17
18 #include <nitro.h>
19
20 #include <nitro/wxc/common.h>
21 #include <nitro/wxc/scheduler.h>
22
23
24 /*****************************************************************************/
25 /* Functions */
26
27 /*---------------------------------------------------------------------------*
28 Name: WXCi_InitScheduler
29
30 Description: Initializes the mode-switch scheduler.
31
32 Arguments: p: WXCScheduler structure
33
34 Returns: None.
35 *---------------------------------------------------------------------------*/
WXCi_InitScheduler(WXCScheduler * p)36 void WXCi_InitScheduler(WXCScheduler * p)
37 {
38 /*
39 * Initialize using the default schedule, which seems to be appropriate, based on experience.
40 * This setting is usually changed only for debugging.
41 */
42 static const BOOL default_table[WXC_SCHEDULER_PATTERN_MAX][WXC_SCHEDULER_SEQ_MAX] = {
43 {TRUE, FALSE, TRUE, TRUE},
44 {FALSE, TRUE, TRUE, TRUE},
45 {FALSE, TRUE, TRUE, TRUE},
46 {TRUE, FALSE, TRUE, TRUE},
47 };
48 p->seq = (int)((OS_GetTick() >> 0) % WXC_SCHEDULER_SEQ_MAX);
49 p->pattern = (int)((OS_GetTick() >> 2) % WXC_SCHEDULER_PATTERN_MAX);
50 p->start = 0;
51 p->child_mode = FALSE;
52 MI_CpuCopy32(default_table, p->table, sizeof(default_table));
53 }
54
55 /*---------------------------------------------------------------------------*
56 Name: WXCi_SetChildMode
57
58 Description: Sets scheduler to operate with child device fixed.
59
60 Arguments: p: WXCScheduler structure
61 enable: If it can only be run on the child side, TRUE
62
63 Returns: None.
64 *---------------------------------------------------------------------------*/
WXCi_SetChildMode(WXCScheduler * p,BOOL enable)65 void WXCi_SetChildMode(WXCScheduler * p, BOOL enable)
66 {
67 p->child_mode = enable;
68 }
69
70 /*---------------------------------------------------------------------------*
71 Name: WXCi_UpdateScheduler
72
73 Description: Updates mode switch scheduler.
74
75 Arguments: p: WXCScheduler structure
76
77 Returns: Return TRUE if currently in parent mode. Return FALSE if currently in child mode.
78 *---------------------------------------------------------------------------*/
WXCi_UpdateScheduler(WXCScheduler * p)79 BOOL WXCi_UpdateScheduler(WXCScheduler * p)
80 {
81 if (++p->seq >= WXC_SCHEDULER_SEQ_MAX)
82 {
83 p->seq = 0;
84 if (++p->pattern >= WXC_SCHEDULER_PATTERN_MAX)
85 {
86 p->pattern = 0;
87 }
88 if (p->pattern == p->start)
89 {
90 /* Supposed to be random number */
91 p->start = (int)(OS_GetTick() % WXC_SCHEDULER_PATTERN_MAX);
92 p->pattern = p->start;
93 }
94 }
95 return p->table[p->pattern][p->seq] && !p->child_mode;
96 }
97