]> git.zerfleddert.de Git - linexec-j720/blob - gpio.cpp
fix asm-location
[linexec-j720] / gpio.cpp
1 #include "stdafx.h"
2 #include "tester1.h"
3 #include <commctrl.h>
4 //#include <aygshell.h>
5 #include <sipapi.h>
6 #include "setup.h"
7
8 #define GPIO 0x40E00000
9 #define GPIO_MEDIAQ 0x14040000
10 #define MQ_OFF 0x008
11
12 int GPIOalt[81],GPIOio[81],GPIOst[81],mediaq;
13
14 void SetGPIOio(int i,int io) // set GPIO as io == 1 output io == 0 input
15 {
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);
18 if(io)
19 gpio[0xC/4 + (i/32)] = gpio[0xC/4 + (i/32)] | (1<<(i%32));
20 else
21 gpio[0xC/4 + (i/32)] = gpio[0xC/4 + (i/32)] & (~(1<<(i%32)));
22 VirtualFree(gpio,0,MEM_RELEASE);
23 }
24
25 void SetGPIOalt(int i,int io) // set GPIO as io == 1 output io == 0 input
26 {
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);
32 }
33
34 void writeGPIOConfig(FILE*fd, UINT32 *gpio)
35 {
36 for(int i=0;i<81;i++)
37 {
38 UINT32 adr=i/16;
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;
42
43 }
44 }
45
46 inline int readGPIOstate(UINT32 *gpio,int i)
47 {
48 return (gpio[(i/32)]>>(i%32))&0x1;
49 }
50
51 inline int readGPIOalt(UINT32 *gpio,int i)
52 {
53 return (gpio[0x54/4+i/16]>>((i%16)*2))&0x3;
54 }
55
56 void Gpio()
57 {
58 SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_BELOW_NORMAL);
59 // SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_TIME_CRITICAL);
60 FILE *fd=fopen("\\loggerG.txt","w");
61 SYSTEMTIME time;
62
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));
69
70 for(int q=0;q<16;q++)
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));
72 GetSystemTime(&time);
73 int sec=time.wSecond,quit=0;
74 sec+=4;
75 if(sec>60) sec-=60;
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);
81
82 for(int i=0;i<81;i++)
83 {
84 GPIOst[i]=-1;
85 }
86 int state,alt;
87 while(sec>time.wSecond)
88 {
89 GetSystemTime(&time);
90 if(gpio1[MQ_OFF/4]!=(UINT32)mediaq)
91 {
92 mediaq=gpio1[MQ_OFF/4];
93 fprintf(fd,"MQ_GPIO=0x%x\n",mediaq);
94 }
95 for(i=0;i<81;i++)
96 {
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;
107 GPIOst[i]=state;
108 if(GPIOalt[i]==alt)
109 fprintf(fd,"#%d: %d\n",i,state);
110 else
111 {
112 GPIOalt[i]=alt;
113 fprintf(fd,"#%d: %d\tf=%d\n",i,state,alt);
114 }
115
116 }
117 }
118 fclose(fd);
119 }
Impressum, Datenschutz