4 //#include <aygshell.h>
8 #define GPIO 0x40E00000
9 #define GPIO_MEDIAQ 0x14040000
12 int GPIOalt
[81],GPIOio
[81],GPIOst
[81],mediaq
;
14 void SetGPIOio(int i
,int io
) // set GPIO as io == 1 output io == 0 input
16 UINT32
*gpio
=(UINT32
*)VirtualAlloc((void*)0x0,0x100, MEM_RESERVE
,PAGE_READWRITE
);
17 VirtualCopy((void*)gpio
,(void *) (GPIO
/256), 0x100, PAGE_READWRITE
|PAGE_NOCACHE
|PAGE_PHYSICAL
);
19 gpio
[0xC/4 + (i
/32)] = gpio
[0xC/4 + (i
/32)] | (1<<(i
%32));
21 gpio
[0xC/4 + (i
/32)] = gpio
[0xC/4 + (i
/32)] & (~(1<<(i
%32)));
22 VirtualFree(gpio
,0,MEM_RELEASE
);
25 void SetGPIOalt(int i
,int io
) // set GPIO as io == 1 output io == 0 input
27 UINT32
*gpio
=(UINT32
*)VirtualAlloc((void*)0x0,0x100, MEM_RESERVE
,PAGE_READWRITE
);
28 VirtualCopy((void*)gpio
,(void *) (GPIO
/256), 0x100, PAGE_READWRITE
|PAGE_NOCACHE
|PAGE_PHYSICAL
);
29 UINT32 w
= gpio
[0x54/4 + (i
/16)] & (~(3<<((i
%16)*2)));
30 gpio
[0x54/4 + (i
/16)] = w
| (io
<<((i
%16)*2));
31 VirtualFree(gpio
,0,MEM_RELEASE
);
34 void writeGPIOConfig(FILE*fd
, UINT32
*gpio
)
39 fprintf(fd
,"GPIO #%d=%c, %d\n",i
,(gpio
[0xC/4+(adr
/2)]>>(i
%32))&0x1?'O':'I',(gpio
[0x54/4+adr
]>>((i
%16)*2))&0x3);
40 GPIOalt
[i
]=(gpio
[0x54/4+adr
]>>((i
%16)*2))&0x3;
41 GPIOio
[i
]=(gpio
[0xC/4+(adr
/2)]>>(i
%32))&0x1;
46 inline int readGPIOstate(UINT32
*gpio
,int i
)
48 return (gpio
[(i
/32)]>>(i
%32))&0x1;
51 inline int readGPIOalt(UINT32
*gpio
,int i
)
53 return (gpio
[0x54/4+i
/16]>>((i
%16)*2))&0x3;
58 SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_BELOW_NORMAL
);
59 // SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_TIME_CRITICAL);
60 FILE *fd
=fopen("\\loggerG.txt","w");
63 fprintf(fd
,"MCMEM0=0x%x\n",ReadPhysical(0x48000028));
64 fprintf(fd
,"MCMEM1=x%x\n",ReadPhysical(0x4800002C));
65 fprintf(fd
,"MCATT0=0x%x\n",ReadPhysical(0x48000030));
66 fprintf(fd
,"MCATT1=0x%x\n",ReadPhysical(0x48000034));
67 fprintf(fd
,"MCIO0=0x%x\n",ReadPhysical(0x48000038));
68 fprintf(fd
,"MCIO1=0x%x\n",ReadPhysical(0x4800003C));
71 fprintf(fd
,"DMA #%d=0x%x\tDCMD=0x%x\tDSADR=0x%x\tDTADR=0x%x\n",q
,ReadPhysical(0x40000000+q
*4),ReadPhysical(0x40000200+q
*0x10+0xC),ReadPhysical(0x40000200+q
*0x10+0x4),ReadPhysical(0x40000200+q
*0x10+0x8));
73 int sec
=time
.wSecond
,quit
=0;
76 UINT32
*gpio
=(UINT32
*)VirtualAlloc((void*)0x0,0x100, MEM_RESERVE
,PAGE_READWRITE
);
77 VirtualCopy((void*)gpio
,(void *) (GPIO
/256), 0x100, PAGE_READWRITE
|PAGE_NOCACHE
|PAGE_PHYSICAL
);
78 UINT32
*gpio1
=(UINT32
*)VirtualAlloc((void*)0x0,0x1000, MEM_RESERVE
,PAGE_READWRITE
);
79 VirtualCopy((void*)gpio1
,(void *) (GPIO_MEDIAQ
/256), 0x1000, PAGE_READWRITE
|PAGE_NOCACHE
|PAGE_PHYSICAL
);
80 writeGPIOConfig(fd
,gpio
);
87 while(sec
>time
.wSecond
)
90 if(gpio1
[MQ_OFF
/4]!=(UINT32
)mediaq
)
92 mediaq
=gpio1
[MQ_OFF
/4];
93 fprintf(fd
,"MQ_GPIO=0x%x\n",mediaq
);
97 /* if(GPIOio[i]) continue;*/
98 if(GPIOalt
[i
]) continue;
99 // if(i==16) continue;
100 // if(i==28) continue;
101 // if(i==29) continue;
102 // if(i==30) continue;
103 // if(i==31) continue;
104 state
=readGPIOstate(gpio
,i
);
105 alt
=readGPIOalt(gpio
,i
);
106 if(GPIOst
[i
]==state
&&GPIOalt
[i
]==alt
) continue;
109 fprintf(fd
,"#%d: %d\n",i
,state
);
113 fprintf(fd
,"#%d: %d\tf=%d\n",i
,state
,alt
);