Rev 157 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
151 | dimkam | 1 | |
2 | //#include "../my.h" |
||
3 | #include "../zxevo_io.h" |
||
4 | |||
5 | #include <stdio.h> |
||
6 | #include <Intrz80.h> |
||
7 | #include <string.h> |
||
8 | #include "hal.h" |
||
9 | #include "sl811.h" |
||
10 | |||
11 | extern unsigned char xdata DBUF[BUFFER_LENGTH]; |
||
12 | extern WORD wordswap(WORD); |
||
13 | FLAGS bdata bFlags; |
||
14 | |||
15 | void SL11HardReset(void) |
||
16 | { |
||
17 | unsigned char val=input(0x83ab)&0x10; |
||
18 | halt(); |
||
19 | output(0x83ab,val); |
||
157 | lvd | 20 | output(0x82ab,input(0x82ab)&0xbf); |
151 | dimkam | 21 | halt(); |
22 | val|=0x20; |
||
23 | output(0x83ab,val); |
||
24 | halt(); |
||
25 | halt(); |
||
26 | halt(); |
||
27 | } |
||
28 | void SL11HostInit(void) |
||
29 | { |
||
30 | SL811Write(cSOFcnt, 0xae); // Set SOF high counter, no change D+/D-SL11Write(CtrlReg, 0x48); // Setup Normal Operation |
||
31 | SL811Write(IntEna, 0x63); // USBA/B, Insert/Remove,USBRest/Resume. |
||
32 | SL811Write(cSOFcnt, 0xae); // Set SOF high counter, no change D+/D-SL11Write(CtrlReg, 0x48); // Setup Normal Operation |
||
33 | SL811Write(CtrlReg, 0); // Disable USB transfer operation and SOF |
||
34 | SL811Write(cSOFcnt, 0xae); // Set SOF high counter, no change D+/D-SL11Write(CtrlReg, 0x48); // Clear SL811H mode and setup normal operation |
||
35 | halt(); |
||
36 | halt(); // Delay for HW stablize |
||
37 | SL811Write(CtrlReg, 0); // Disable USB transfer operation and SOF |
||
38 | } |
||
39 | |||
40 | void USBReset(void) |
||
41 | { |
||
42 | BYTE tmp; |
||
43 | tmp = SL811Read(CtrlReg); |
||
44 | SL811Write(CtrlReg,0x08); |
||
45 | EZUSB_Delay(100); |
||
46 | SL811Write(CtrlReg,0x18); |
||
47 | EZUSB_Delay(100); |
||
48 | SL811Write(CtrlReg,0x08); |
||
49 | EZUSB_Delay(500); |
||
50 | SL811Write(CtrlReg,tmp); |
||
51 | } |
||
52 | |||
53 | int sl811_init_my(void) |
||
54 | { |
||
55 | unsigned char i,count=50; |
||
56 | |||
57 | do{ |
||
58 | SL11HardReset(); |
||
59 | SL11HostInit(); |
||
60 | }while((i=SL811Read(IntStatus))==0x05); |
||
61 | |||
62 | bFlags.bits.FULL_SPEED=FALSE; |
||
63 | bFlags.bits.SLAVE_FOUND=FALSE; |
||
64 | bFlags.bits.SLAVE_ENUMERATED=FALSE; |
||
65 | bFlags.bits.BULK_OUT_DONE=FALSE; |
||
66 | bFlags.bits.DATA_INPROCESS=FALSE; |
||
67 | bFlags.bits.DATA_STOP=FALSE; |
||
68 | while(count--){ |
||
69 | SL811Write(cSOFcnt,0xae); |
||
70 | USBReset(); |
||
71 | SL811Write(IntEna,0x00); |
||
72 | SL811Write(IntStatus,INT_CLEAR); |
||
73 | EZUSB_Delay(100); |
||
74 | i=SL811Read(IntStatus); |
||
75 | if(i&USB_RESET) //0x40 |
||
76 | break; |
||
77 | if(!(i&USB_DPLUS)) //0x80 |
||
78 | continue; |
||
79 | puts("'Full' Speed is detected!"); // ** Full Speed is detected ** // |
||
80 | SL811Write(cSOFcnt,0xae); // Set up Master & low speed direct and SOF cnt high=0x2e |
||
81 | SL811Write(cDATASet,0xe0); // SOF Counter Low = 0xE0; 1ms interval |
||
82 | SL811Write(CtrlReg,0x05); // Setup 48MHz and SOF enable |
||
83 | bFlags.bits.FULL_SPEED=TRUE; |
||
84 | bFlags.bits.SLAVE_FOUND=TRUE; |
||
85 | SL811Write(EP0Status,0x50); //90); |
||
86 | SL811Write(EP0Counter,0x00); |
||
87 | SL811Write(EP0Control,1); //sDATA0_RD); //0x23 |
||
88 | EZUSB_Delay(15); |
||
89 | SL811Write(IntEna,0x61); |
||
90 | SL811Write(IntStatus,INT_CLEAR); //0xff |
||
91 | return TRUE; |
||
92 | } |
||
93 | puts("NO device detected!"); |
||
94 | return FALSE; |
||
95 | } |
||
96 | |||
97 | BYTE SL811Read(BYTE adr) |
||
98 | { |
||
99 | output(SL811H_ADDR,adr); |
||
100 | return input(SL811H_DATA); |
||
101 | } |
||
102 | |||
103 | |||
104 | void SL811Write(BYTE adr, BYTE dat) |
||
105 | { output(SL811H_ADDR,adr); |
||
106 | output(SL811H_DATA,dat); |
||
107 | } |
||
108 | |||
109 | void SL811BufRead(BYTE addr, BYTE *s, BYTE c) |
||
110 | { |
||
111 | while (c--){ |
||
112 | output(SL811H_ADDR,addr++); |
||
113 | *s++ = input(SL811H_DATA); |
||
114 | } |
||
115 | } |
||
116 | unsigned char test(unsigned char c) |
||
117 | { |
||
118 | return (c == 17) ? 0:(c + 1); |
||
119 | } |
||
120 | |||
121 | void SL811BufWrite(BYTE addr, BYTE *s, BYTE c) |
||
122 | { if(c<=0) return; |
||
123 | while (c--){ |
||
124 | output(SL811H_ADDR,addr++); |
||
125 | output(SL811H_DATA,*s++); |
||
126 | } |
||
127 | } |
||
128 | |||
129 | WORD WordSwap(WORD input) |
||
130 | { return (((input&0x00FF)<<8)|((input&0xFF00)>>8)); |
||
131 | } |
||
132 | |||
133 | |||
134 | unsigned int LSwapINT16(unsigned short dData1,unsigned short dData2) |
||
135 | { |
||
136 | unsigned int dData; |
||
137 | dData = ((dData2<<8)&0xff00)|(dData1&0x00ff); |
||
138 | return dData; |
||
139 | } |
||
140 | |||
141 | unsigned long LSwapINT32(unsigned long dData1,unsigned long dData2,unsigned long dData3,unsigned long dData4) |
||
142 | { |
||
143 | unsigned long dData; |
||
144 | dData = ((dData4<<24)&0xff000000)|((dData3<<16)&0xff0000)|((dData2<<8)&0xff00)|(dData1&0xff); |
||
145 | return dData; |
||
146 | } |