Rev 109 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 109 | Rev 171 | ||
---|---|---|---|
1 | /*#######################################################################################*/ |
1 | /*#######################################################################################*/ |
2 | /* !!! THIS IS NOT FREE SOFTWARE !!! */ |
2 | /* !!! THIS IS NOT FREE SOFTWARE !!! */ |
3 | /*#######################################################################################*/ |
3 | /*#######################################################################################*/ |
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
5 | // + Copyright (c) 2008 Ingo Busker, Holger Buss |
5 | // + Copyright (c) 2008 Ingo Busker, Holger Buss |
6 | // + Nur für den privaten Gebrauch |
6 | // + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY |
7 | // + FOR NON COMMERCIAL USE ONLY |
7 | // + FOR NON COMMERCIAL USE ONLY |
8 | // + www.MikroKopter.com |
8 | // + www.MikroKopter.com |
9 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
9 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
10 | // + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
10 | // + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
11 | // + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. |
11 | // + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. |
12 | // + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
12 | // + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
13 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
13 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
14 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
14 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
15 | // + Verkauf von Luftbildaufnahmen, usw. |
15 | // + Verkauf von Luftbildaufnahmen, usw. |
16 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
16 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
17 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
17 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
18 | // + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
18 | // + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
19 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
19 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
20 | // + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
20 | // + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
21 | // + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
21 | // + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
22 | // + eindeutig als Ursprung verlinkt werden |
22 | // + eindeutig als Ursprung verlinkt werden |
23 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
23 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
24 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
24 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
25 | // + Benutzung auf eigene Gefahr |
25 | // + Benutzung auf eigene Gefahr |
26 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
26 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
27 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
27 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
28 | // + Die PORTIERUNG der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
28 | // + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
29 | // + mit unserer Zustimmung zulässig |
29 | // + mit unserer Zustimmung zulässig |
30 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
30 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
31 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
31 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
32 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
32 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
33 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
33 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
34 | // + this list of conditions and the following disclaimer. |
34 | // + this list of conditions and the following disclaimer. |
35 | // + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
35 | // + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
36 | // + from this software without specific prior written permission. |
36 | // + from this software without specific prior written permission. |
37 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permitted |
37 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permitted |
38 | // + for non-commercial use (directly or indirectly) |
38 | // + for non-commercial use (directly or indirectly) |
39 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
39 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
40 | // + with our written permission |
40 | // + with our written permission |
41 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
41 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
42 | // + clearly linked as origin |
42 | // + clearly linked as origin |
43 | // + * PORTING this software (or part of it) to systems (other than hardware from www.mikrokopter.de) is NOT allowed |
43 | // + * porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed |
44 | // |
44 | // |
45 | // + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
45 | // + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
46 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
46 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
47 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
47 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
48 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
48 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
49 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
49 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
50 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
50 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
51 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
51 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
52 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
52 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
53 | // + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
53 | // + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
54 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
54 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
55 | // + POSSIBILITY OF SUCH DAMAGE. |
55 | // + POSSIBILITY OF SUCH DAMAGE. |
56 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
56 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
57 | #include "91x_lib.h" |
57 | #include "91x_lib.h" |
58 | #include "uart1.h" |
58 | #include "uart1.h" |
59 | #include "usb.h" |
59 | #include "usb.h" |
60 | //----------------------------------------------------------------- |
60 | //----------------------------------------------------------------- |
61 | void USB_ConfigInit(void) |
61 | void USB_ConfigInit(void) |
62 | { |
62 | { |
63 | GPIO_InitTypeDef GPIO_InitStructure; |
63 | GPIO_InitTypeDef GPIO_InitStructure; |
64 | 64 | ||
65 | SerialPutString("\r\n USB init..."); |
65 | SerialPutString("\r\n USB init..."); |
66 | #ifdef MCLK96MHZ |
66 | #ifdef MCLK96MHZ |
67 | //USB clock = MCLK/2 = 48MHz |
67 | //USB clock = MCLK/2 = 48MHz |
68 | SCU_USBCLKConfig(SCU_USBCLK_MCLK2); |
68 | SCU_USBCLKConfig(SCU_USBCLK_MCLK2); |
69 | #else |
69 | #else |
70 | //USB clock = MCLK = 48MHz |
70 | //USB clock = MCLK = 48MHz |
71 | SCU_USBCLKConfig(SCU_USBCLK_MCLK); |
71 | SCU_USBCLKConfig(SCU_USBCLK_MCLK); |
72 | #endif |
72 | #endif |
73 | //Enable USB clock |
73 | //Enable USB clock |
74 | SCU_AHBPeriphClockConfig(__USB,ENABLE); |
74 | SCU_AHBPeriphClockConfig(__USB,ENABLE); |
75 | SCU_AHBPeriphReset(__USB,DISABLE); |
75 | SCU_AHBPeriphReset(__USB,DISABLE); |
76 | SCU_AHBPeriphClockConfig(__USB48M,ENABLE); |
76 | SCU_AHBPeriphClockConfig(__USB48M,ENABLE); |
77 | 77 | ||
78 | //Configure GPIO0 (D+ Pull-Up on P0.1) |
78 | //Configure GPIO0 (D+ Pull-Up on P0.1) |
79 | SCU_APBPeriphClockConfig(__GPIO0 ,ENABLE); |
79 | SCU_APBPeriphClockConfig(__GPIO0 ,ENABLE); |
80 | SCU_APBPeriphReset(__GPIO0,DISABLE); |
80 | SCU_APBPeriphReset(__GPIO0,DISABLE); |
81 | 81 | ||
82 | // GPIO_DeInit(P0.1); |
82 | // GPIO_DeInit(P0.1); |
83 | GPIO_StructInit(&GPIO_InitStructure); |
83 | GPIO_StructInit(&GPIO_InitStructure); |
84 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
84 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
85 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; |
85 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; |
86 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
86 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
87 | GPIO_InitStructure.GPIO_IPConnected=GPIO_IPConnected_Enable; |
87 | GPIO_InitStructure.GPIO_IPConnected=GPIO_IPConnected_Enable; |
88 | GPIO_InitStructure.GPIO_Alternate=GPIO_OutputAlt1; |
88 | GPIO_InitStructure.GPIO_Alternate=GPIO_OutputAlt1; |
89 | GPIO_Init (GPIO0, &GPIO_InitStructure); |
89 | GPIO_Init (GPIO0, &GPIO_InitStructure); |
90 | 90 | ||
91 | PowerOff(); |
91 | PowerOff(); |
92 | Virtual_Com_Port_Reset(); |
92 | Virtual_Com_Port_Reset(); |
93 | 93 | ||
94 | VIC_Config(USBLP_ITLine, VIC_IRQ, 2); |
94 | VIC_Config(USBLP_ITLine, VIC_IRQ, 2); |
95 | VIC_ITCmd(USBLP_ITLine, ENABLE); |
95 | VIC_ITCmd(USBLP_ITLine, ENABLE); |
96 | 96 | ||
97 | USB_Init(); |
97 | USB_Init(); |
98 | 98 | ||
99 | SerialPutString("ok"); |
99 | SerialPutString("ok"); |
100 | } |
100 | } |
101 | 101 | ||
102 | //----------------------------------------------------------------- |
102 | //----------------------------------------------------------------- |
103 | void USB_Cable_Config (FunctionalState NewState) |
103 | void USB_Cable_Config (FunctionalState NewState) |
104 | { |
104 | { |
105 | if (NewState == ENABLE) |
105 | if (NewState == ENABLE) |
106 | GPIO_WriteBit(GPIO0, GPIO_Pin_1, Bit_RESET); |
106 | GPIO_WriteBit(GPIO0, GPIO_Pin_1, Bit_RESET); |
107 | else |
107 | else |
108 | GPIO_WriteBit(GPIO0, GPIO_Pin_1, Bit_SET); |
108 | GPIO_WriteBit(GPIO0, GPIO_Pin_1, Bit_SET); |
109 | } |
109 | } |
110 | 110 | ||
111 | //----------------------------------------------------------------- |
111 | //----------------------------------------------------------------- |
112 | void USB_Send_String(u8 *StrPtr) |
112 | void USB_Send_String(u8 *StrPtr) |
113 | { |
113 | { |
114 | u8 i = 0; |
114 | u8 i = 0; |
115 | u16 timeout = 0; |
115 | u16 timeout = 0; |
116 | 116 | ||
117 | while (StrPtr[i++] !=0){} // get string len |
117 | while (StrPtr[i++] !=0){} // get string len |
118 | while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){ if (timeout++ > 60000) return;} |
118 | while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){ if (timeout++ > 60000) return;} |
119 | UserToPMABufferCopy(StrPtr, ENDP1_TXADDR, ++i); // copy string to usb buffer |
119 | UserToPMABufferCopy(StrPtr, ENDP1_TXADDR, ++i); // copy string to usb buffer |
120 | SetEPTxCount(ENDP1,i); |
120 | SetEPTxCount(ENDP1,i); |
121 | SetEPTxValid(ENDP1); |
121 | SetEPTxValid(ENDP1); |
122 | } |
122 | } |
123 | 123 | ||
124 | //----------------------------------------------------------------- |
124 | //----------------------------------------------------------------- |
125 | void USB_Send_Char(u8 ch) |
125 | void USB_Send_Char(u8 ch) |
126 | { |
126 | { |
127 | u16 timeout = 0; |
127 | u16 timeout = 0; |
128 | while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){ if (timeout++ > 60000) return;} |
128 | while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){ if (timeout++ > 60000) return;} |
129 | UserToPMABufferCopy(&ch, ENDP1_TXADDR, 2); |
129 | UserToPMABufferCopy(&ch, ENDP1_TXADDR, 2); |
130 | SetEPTxCount(ENDP1,2); |
130 | SetEPTxCount(ENDP1,2); |
131 | SetEPTxValid(ENDP1); |
131 | SetEPTxValid(ENDP1); |
132 | } |
132 | } |
133 | 133 | ||
134 | //----------------------------------------------------------------- |
134 | //----------------------------------------------------------------- |
135 | void USB_Send_Data(u8 *data, u16 count) |
135 | void USB_Send_Data(u8 *data, u16 count) |
136 | { |
136 | { |
137 | u8 i; |
137 | u8 i; |
138 | count++; |
138 | count++; |
139 | 139 | ||
140 | for (i=0;i< (count/64)+1;i++) |
140 | for (i=0;i< (count/64)+1;i++) |
141 | { |
141 | { |
142 | while (_GetEPTxStatus(ENDP1) != EP_TX_NAK); |
142 | while (_GetEPTxStatus(ENDP1) != EP_TX_NAK); |
143 | if (i < (count/64)) |
143 | if (i < (count/64)) |
144 | { |
144 | { |
145 | UserToPMABufferCopy(&data[i*64], ENDP1_TXADDR, 64); |
145 | UserToPMABufferCopy(&data[i*64], ENDP1_TXADDR, 64); |
146 | SetEPTxCount(ENDP1,64); |
146 | SetEPTxCount(ENDP1,64); |
147 | } |
147 | } |
148 | else |
148 | else |
149 | { |
149 | { |
150 | UserToPMABufferCopy(&data[i*64], ENDP1_TXADDR, count % 64); |
150 | UserToPMABufferCopy(&data[i*64], ENDP1_TXADDR, count % 64); |
151 | SetEPTxCount(ENDP1, count % 64); |
151 | SetEPTxCount(ENDP1, count % 64); |
152 | } |
152 | } |
153 | 153 | ||
154 | SetEPTxValid(ENDP1); |
154 | SetEPTxValid(ENDP1); |
155 | } |
155 | } |
156 | } |
156 | } |
157 | 157 | ||
158 | 158 |