main.c
2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*---------------------------------------------------------------------
File : main.c
Copyright by Nintendo, Co., Ltd. 1997.
---------------------------------------------------------------------*/
#include <ultra64.h>
#include "nu64sys.h"
#include "sram.h"
#define NUM_PI_MSGS 8
public u64 bootStack[STACKSIZE/8];
private void idle(void *);
private OSThread idleThread;
private u64 idleThreadStack[STACKSIZE/8];
extern void mainproc(void *);
private OSThread mainThread;
private u64 mainThreadStack[STACKSIZE/8];
private OSMesg PiMessages[NUM_PI_MSGS];
private OSMesgQueue PiMessageQ;
public OSMesgQueue n_dmaMessageQ;
private OSMesg dmaMessageBuf;
extern OSPiHandle *SramInit(void);
extern u32 writebuf[];
extern u32 readbuf[];
OSPiHandle *handler;
OSIoMesg MyIoMesg;
void SRAM_DMA(u32 rw_flag, u32 *data_addr)
{
osWritebackDCache(data_addr, SRAM_SIZE);
MyIoMesg.hdr.pri = OS_MESG_PRI_NORMAL;
MyIoMesg.hdr.retQueue = &n_dmaMessageQ;
MyIoMesg.dramAddr = data_addr;
MyIoMesg.devAddr = SRAM_START_ADDR;
MyIoMesg.size = SRAM_SIZE;
osEPiStartDma(handler, &MyIoMesg, rw_flag);
(void)osRecvMesg(&n_dmaMessageQ, NULL, OS_MESG_BLOCK);
}
u32 rand (void)
{
static unsigned long seed = 1;
seed = seed * 1103515245 + 12345;
return seed;
}
void boot(void)
{
osInitialize();
osCreateThread(&idleThread, TID_IDLE, idle, (void*)0,
idleThreadStack+STACKSIZE/8, 10);
osStartThread(&idleThread);
}
void idle(void *arg)
{
osCreatePiManager((OSPri)OS_PRIORITY_PIMGR,
&PiMessageQ, PiMessages, NUM_PI_MSGS);
osCreateMesgQueue(&n_dmaMessageQ, &dmaMessageBuf, 1);
osCreateThread(&mainThread, TID_MAINPROC, mainproc, (void *)0,
(void *)(mainThreadStack+STACKSIZE/8), 10);
osStartThread(&mainThread);
osSetThreadPri(0, 0);
while(1){
}
}
void mainproc(void *arg)
{
u32 i, result;
handler = SramInit();
for (i = 0; i < SRAM_SIZE/4; ++i)
writebuf[i] = rand();
/* test SRAM patern: RANDOM */
SRAM_DMA(OS_WRITE, writebuf);
SRAM_DMA(OS_READ, readbuf);
if(bcmp(readbuf,writebuf,SRAM_SIZE/4)!=0)
osSyncPrintf("fill random data test error\n");
else
osSyncPrintf("SRAM TEST OK!\n");
}