1 /*---------------------------------------------------------------------------*
2   Project:  Idle function demo
3   File:     idlefunctiondemo.c
4 
5   Copyright 1998, 1999 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   $Log: idlefunctiondemo.c,v $
14   Revision 1.2  02/20/2006 04:13:11  mitu
15   changed include path from dolphin/ to revolution/.
16 
17   Revision 1.1  01/13/2006 11:24:13  hiratsu
18   Initial check in.
19 
20 
21     2     6/07/00 6:12p Tian
22     Updated OSCreateThread and idle function APIs
23 
24     1     2/16/00 2:23p Tian
25     Cleaned up and moved to demos
26   $NoKeywords: $
27  *---------------------------------------------------------------------------*/
28 
29 #include <revolution.h>
30 
31 u8              Stack[4096];
32 volatile u64    Sum;
33 
Func(void * param)34 static void Func(void* param)
35 {
36     #pragma unused( param )
37     u64 n;
38 
39     // Do background job
40     for (n = 1; n <= 1000000; n++)
41     {
42         Sum += n;
43     }
44 }
45 
main(void)46 void main(void)
47 {
48 
49     OSInit();
50     VIInit();
51     OSReport("Idle Function Demo\n");
52 
53     OSSetIdleFunction(
54         Func,                   // start function
55         0,                      // initial parameter
56         Stack + sizeof Stack,   // initial stack address
57         sizeof Stack);          // stack size
58 
59     // Loop until the idle function completes. OSGetIdleFunction()
60     // returns NULL after the idle function completes.
61     do
62     {
63         OSReport("Sum of 1 to 1000000 >= %llu after %u V-syncs\n",
64                  Sum,
65                  VIGetRetraceCount());
66         VIWaitForRetrace();                 // Sleep till next V-sync
67     } while (OSGetIdleFunction());
68 
69     OSReport("Sum of 1 to 1000000 == %llu after %u V-syncs\n",
70              Sum,
71              VIGetRetraceCount());
72 
73     OSHalt("Demo complete");
74 }
75