Rev 280 | Rev 378 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 280 | Rev 360 | ||
---|---|---|---|
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 |
- | |
6 | // + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY |
- | |
7 | // + FOR NON COMMERCIAL USE ONLY |
- | |
8 | // + www.MikroKopter.com |
5 | // + www.MikroKopter.com |
9 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
6 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | 7 | // + Software Nutzungsbedingungen (english version: see below) |
|
10 | // + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
8 | // + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt - |
11 | // + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. |
9 | // + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den |
12 | // + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
10 | // + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool |
13 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
11 | // + - nachfolgend Software genannt - nur für private Zwecke zu nutzen. |
14 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
12 | // + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig. |
15 | // + Verkauf von Luftbildaufnahmen, usw. |
- | |
16 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
13 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
17 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
14 | // + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im |
18 | // + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
15 | // + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu. |
19 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
16 | // + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie |
20 | // + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
17 | // + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden. |
21 | // + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
18 | // + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren |
22 | // + eindeutig als Ursprung verlinkt werden |
19 | // + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
23 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
20 | // + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren |
24 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
21 | // + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand |
25 | // + Benutzung auf eigene Gefahr |
22 | // + des Mitverschuldens offen. |
- | 23 | // + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet. |
|
- | 24 | // + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
|
26 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
25 | // + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern. |
- | 26 | // + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang |
|
27 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
27 | // + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt. |
28 | // + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
28 | // + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software. |
29 | // + mit unserer Zustimmung zulässig |
29 | // + #### ENDE DER NUTZUNGSBEDINGUNGEN ####' |
- | 30 | // + Hinweis: Informationen über erweiterte Nutzungsrechte (wie z.B. Nutzung für nicht-private Zwecke) sind auf Anfrage per Email an info(@)hisystems.de verfügbar. |
|
30 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
31 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
31 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
32 | // + Software LICENSING TERMS |
32 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
33 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
33 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
34 | // + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor - |
34 | // + this list of conditions and the following disclaimer. |
35 | // + The Licensor grants the customer a non-exclusive license to use the microcontroller firmware of the Flight-Ctrl, Navi-Ctrl, BL-Ctrl, and MK3Mag hardware |
35 | // + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
36 | // + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*. |
36 | // + from this software without specific prior written permission. |
37 | // + The Software may only be used with the Licensor's products. |
37 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permitted |
38 | // + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this |
38 | // + for non-commercial use (directly or indirectly) |
- | |
39 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
39 | // + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this |
40 | // + with our written permission |
40 | // + agreement shall be the property of the Licensor. |
41 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
41 | // + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other |
42 | // + clearly linked as origin |
- | |
43 | // + * porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed |
42 | // + features that can be used to identify the program may not be altered or defaced by the customer. |
44 | // |
- | |
45 | // + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
43 | // + The customer shall be responsible for taking reasonable precautions |
46 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
44 | // + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the |
47 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
45 | // + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and |
48 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
46 | // + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product |
49 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
47 | // + liability. However, the Licensor shall be entitled to the defense of contributory negligence. |
50 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
48 | // + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test |
51 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
49 | // + the software for his purpose before any operational usage. The customer will backup his data before using the software. |
52 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
50 | // + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data |
53 | // + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
51 | // + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations. |
54 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
52 | // + *) The territory aspect only refers to the place where the Software is used, not its programmed range. |
55 | // + POSSIBILITY OF SUCH DAMAGE. |
53 | // + #### END OF LICENSING TERMS #### |
- | 54 | // + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de. |
|
56 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
55 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
57 | #include <stdio.h> |
56 | #include <stdio.h> |
58 | #include <string.h> |
57 | #include <string.h> |
59 | #include "91x_lib.h" |
58 | #include "91x_lib.h" |
60 | #include "config.h" |
59 | #include "config.h" |
61 | #include "main.h" |
60 | #include "main.h" |
62 | #include "uart1.h" |
61 | #include "uart1.h" |
63 | #include "mkprotocol.h" |
62 | #include "mkprotocol.h" |
64 | #include "waypoints.h" |
63 | #include "waypoints.h" |
65 | #include "gps.h" |
64 | #include "gps.h" |
66 | #include "timer1.h" |
65 | #include "timer1.h" |
67 | #include "uart0.h" |
66 | #include "uart0.h" |
68 | #include "uart1.h" |
67 | #include "uart1.h" |
69 | #include "uart2.h" |
68 | #include "uart2.h" |
70 | #include "menu.h" |
69 | #include "menu.h" |
71 | #include "usb.h" |
70 | #include "usb.h" |
72 | 71 | ||
73 | #define ABO_TIMEOUT 4000 // disable abo after 4 seconds |
72 | #define ABO_TIMEOUT 4000 // disable abo after 4 seconds |
74 | u32 USB_AboTimeOut = 0; |
73 | u32 USB_AboTimeOut = 0; |
75 | 74 | ||
76 | u16 Echo; // 2 bytes recieved will be sent back as echo |
75 | u16 Echo; // 2 bytes recieved will be sent back as echo |
77 | 76 | ||
78 | // the primary rx fifo |
77 | // the primary rx fifo |
79 | #define USB_RX_FIFO_LEN 512 |
78 | #define USB_RX_FIFO_LEN 512 |
80 | u8 USB_rxfifobuffer[USB_RX_FIFO_LEN]; |
79 | u8 USB_rxfifobuffer[USB_RX_FIFO_LEN]; |
81 | fifo_t USB_rx_fifo; |
80 | fifo_t USB_rx_fifo; |
82 | 81 | ||
83 | // the tx buffer |
82 | // the tx buffer |
84 | #define USB_TX_BUFFER_LEN 150 |
83 | #define USB_TX_BUFFER_LEN 150 |
85 | u8 USB_tbuffer[USB_TX_BUFFER_LEN]; |
84 | u8 USB_tbuffer[USB_TX_BUFFER_LEN]; |
86 | Buffer_t USB_tx_buffer; |
85 | Buffer_t USB_tx_buffer; |
87 | 86 | ||
88 | // the rx buffer |
87 | // the rx buffer |
89 | #define USB_RX_BUFFER_LEN 150 |
88 | #define USB_RX_BUFFER_LEN 150 |
90 | u8 USB_rbuffer[USB_RX_BUFFER_LEN]; |
89 | u8 USB_rbuffer[USB_RX_BUFFER_LEN]; |
91 | Buffer_t USB_rx_buffer; |
90 | Buffer_t USB_rx_buffer; |
92 | 91 | ||
93 | u8 USB_Request_VersionInfo = FALSE; |
92 | u8 USB_Request_VersionInfo = FALSE; |
94 | u8 USB_Request_SendFollowMe = FALSE; |
93 | u8 USB_Request_SendFollowMe = FALSE; |
95 | u8 USB_Request_ExternalControl= FALSE; |
94 | u8 USB_Request_ExternalControl= FALSE; |
96 | u8 USB_Request_Display = FALSE; |
95 | u8 USB_Request_Display = FALSE; |
97 | u8 USB_Request_Display1 = FALSE; |
96 | u8 USB_Request_Display1 = FALSE; |
98 | u8 USB_Request_DebugData = FALSE; |
97 | u8 USB_Request_DebugData = FALSE; |
99 | u8 USB_Request_DebugLabel = 255; |
98 | u8 USB_Request_DebugLabel = 255; |
100 | u8 USB_Request_NaviData = FALSE; |
99 | u8 USB_Request_NaviData = FALSE; |
101 | u8 USB_Request_ErrorMessage = FALSE; |
100 | u8 USB_Request_ErrorMessage = FALSE; |
102 | u8 USB_Request_Data3D = FALSE; |
101 | u8 USB_Request_Data3D = FALSE; |
103 | u8 USB_Request_Echo = FALSE; |
102 | u8 USB_Request_Echo = FALSE; |
104 | u8 USB_DisplayKeys = 0; |
103 | u8 USB_DisplayKeys = 0; |
105 | u8 USB_DisplayLine = 0; |
104 | u8 USB_DisplayLine = 0; |
106 | u8 USB_ConfirmFrame = 0; |
105 | u8 USB_ConfirmFrame = 0; |
107 | 106 | ||
108 | u32 USB_DebugData_Timer = 0; |
107 | u32 USB_DebugData_Timer = 0; |
109 | u32 USB_DebugData_Interval = 0; // in ms |
108 | u32 USB_DebugData_Interval = 0; // in ms |
110 | u32 USB_NaviData_Timer = 0; |
109 | u32 USB_NaviData_Timer = 0; |
111 | u32 USB_NaviData_Interval = 0; // in ms |
110 | u32 USB_NaviData_Interval = 0; // in ms |
112 | u32 USB_Data3D_Timer = 0; |
111 | u32 USB_Data3D_Timer = 0; |
113 | u32 USB_Data3D_Interval = 0; // in ms |
112 | u32 USB_Data3D_Interval = 0; // in ms |
114 | u32 USB_Display_Timer = 0; |
113 | u32 USB_Display_Timer = 0; |
115 | u32 USB_Display_Interval = 0; // in ms |
114 | u32 USB_Display_Interval = 0; // in ms |
116 | 115 | ||
117 | //----------------------------------------------------------------- |
116 | //----------------------------------------------------------------- |
118 | void USB_ConfigInit(void) |
117 | void USB_ConfigInit(void) |
119 | { |
118 | { |
120 | GPIO_InitTypeDef GPIO_InitStructure; |
119 | GPIO_InitTypeDef GPIO_InitStructure; |
121 | 120 | ||
122 | UART1_PutString("\r\n USB init..."); |
121 | UART1_PutString("\r\n USB init..."); |
123 | #ifdef MCLK96MHZ |
122 | #ifdef MCLK96MHZ |
124 | //USB clock = MCLK/2 = 48MHz |
123 | //USB clock = MCLK/2 = 48MHz |
125 | SCU_USBCLKConfig(SCU_USBCLK_MCLK2); |
124 | SCU_USBCLKConfig(SCU_USBCLK_MCLK2); |
126 | #else |
125 | #else |
127 | //USB clock = MCLK = 48MHz |
126 | //USB clock = MCLK = 48MHz |
128 | SCU_USBCLKConfig(SCU_USBCLK_MCLK); |
127 | SCU_USBCLKConfig(SCU_USBCLK_MCLK); |
129 | #endif |
128 | #endif |
130 | //Enable USB clock |
129 | //Enable USB clock |
131 | SCU_AHBPeriphClockConfig(__USB,ENABLE); |
130 | SCU_AHBPeriphClockConfig(__USB,ENABLE); |
132 | SCU_AHBPeriphReset(__USB,DISABLE); |
131 | SCU_AHBPeriphReset(__USB,DISABLE); |
133 | SCU_AHBPeriphClockConfig(__USB48M,ENABLE); |
132 | SCU_AHBPeriphClockConfig(__USB48M,ENABLE); |
134 | 133 | ||
135 | //Configure GPIO0 (D+ Pull-Up on P0.1) |
134 | //Configure GPIO0 (D+ Pull-Up on P0.1) |
136 | SCU_APBPeriphClockConfig(__GPIO0 ,ENABLE); |
135 | SCU_APBPeriphClockConfig(__GPIO0 ,ENABLE); |
137 | SCU_APBPeriphReset(__GPIO0,DISABLE); |
136 | SCU_APBPeriphReset(__GPIO0,DISABLE); |
138 | 137 | ||
139 | // GPIO_DeInit(P0.1); |
138 | // GPIO_DeInit(P0.1); |
140 | GPIO_StructInit(&GPIO_InitStructure); |
139 | GPIO_StructInit(&GPIO_InitStructure); |
141 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
140 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
142 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; |
141 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; |
143 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
142 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
144 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable; |
143 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable; |
145 | GPIO_InitStructure.GPIO_Alternate=GPIO_OutputAlt1; |
144 | GPIO_InitStructure.GPIO_Alternate=GPIO_OutputAlt1; |
146 | GPIO_Init (GPIO0, &GPIO_InitStructure); |
145 | GPIO_Init (GPIO0, &GPIO_InitStructure); |
147 | 146 | ||
148 | // initialize the rx fifo, block UART IRQ geting a byte from fifo |
147 | // initialize the rx fifo, block UART IRQ geting a byte from fifo |
149 | fifo_init(&USB_rx_fifo, USB_rxfifobuffer, USB_RX_FIFO_LEN, NO_ITLine, USBLP_ITLine); |
148 | fifo_init(&USB_rx_fifo, USB_rxfifobuffer, USB_RX_FIFO_LEN, NO_ITLine, USBLP_ITLine); |
150 | 149 | ||
151 | // initialize txd buffer |
150 | // initialize txd buffer |
152 | Buffer_Init(&USB_tx_buffer, USB_tbuffer, USB_TX_BUFFER_LEN); |
151 | Buffer_Init(&USB_tx_buffer, USB_tbuffer, USB_TX_BUFFER_LEN); |
153 | 152 | ||
154 | // initialize rxd buffer |
153 | // initialize rxd buffer |
155 | Buffer_Init(&USB_rx_buffer, USB_rbuffer, USB_RX_BUFFER_LEN); |
154 | Buffer_Init(&USB_rx_buffer, USB_rbuffer, USB_RX_BUFFER_LEN); |
156 | 155 | ||
157 | VIC_Config(USBLP_ITLine, VIC_IRQ, PRIORITY_USB); |
156 | VIC_Config(USBLP_ITLine, VIC_IRQ, PRIORITY_USB); |
158 | VIC_ITCmd(USBLP_ITLine, ENABLE); |
157 | VIC_ITCmd(USBLP_ITLine, ENABLE); |
159 | 158 | ||
160 | USB_Init(); |
159 | USB_Init(); |
161 | 160 | ||
162 | UART1_PutString("ok"); |
161 | UART1_PutString("ok"); |
163 | } |
162 | } |
164 | 163 | ||
165 | 164 | ||
166 | /**************************************************************/ |
165 | /**************************************************************/ |
167 | /* Process incomming data from debug uart */ |
166 | /* Process incomming data from debug uart */ |
168 | /**************************************************************/ |
167 | /**************************************************************/ |
169 | void USB_ProcessRxData(void) |
168 | void USB_ProcessRxData(void) |
170 | { |
169 | { |
171 | u8 c; |
170 | u8 c; |
172 | SerialMsg_t SerialMsg; |
171 | SerialMsg_t SerialMsg; |
173 | 172 | ||
174 | // if data in the rxd buffer are not locked immediately return |
173 | // if data in the rxd buffer are not locked immediately return |
175 | // if rx buffer is not locked |
174 | // if rx buffer is not locked |
176 | if(USB_rx_buffer.Locked == FALSE) |
175 | if(USB_rx_buffer.Locked == FALSE) |
177 | { |
176 | { |
178 | //collect data from primary rx fifo |
177 | //collect data from primary rx fifo |
179 | while(fifo_get(&USB_rx_fifo, &c)) |
178 | while(fifo_get(&USB_rx_fifo, &c)) |
180 | { |
179 | { |
181 | // break if complete frame has been collected |
180 | // break if complete frame has been collected |
182 | if(MKProtocol_CollectSerialFrame(&USB_rx_buffer, c)) break; |
181 | if(MKProtocol_CollectSerialFrame(&USB_rx_buffer, c)) break; |
183 | } |
182 | } |
184 | } |
183 | } |
185 | if(USB_rx_buffer.Locked == FALSE) return; |
184 | if(USB_rx_buffer.Locked == FALSE) return; |
186 | 185 | ||
187 | MKProtocol_DecodeSerialFrameHeader(&USB_rx_buffer, &SerialMsg); // decode serial frame in rxd buffer |
186 | MKProtocol_DecodeSerialFrameHeader(&USB_rx_buffer, &SerialMsg); // decode serial frame in rxd buffer |
188 | MKProtocol_DecodeSerialFrameData(&USB_rx_buffer, &SerialMsg); // decode serial frame in rxd buffer |
187 | MKProtocol_DecodeSerialFrameData(&USB_rx_buffer, &SerialMsg); // decode serial frame in rxd buffer |
189 | 188 | ||
190 | if(SerialMsg.CmdID != 'z') SerialLinkOkay = 250; // reset SerialTimeout, but not in case of the "ping" |
189 | if(SerialMsg.CmdID != 'z') SerialLinkOkay = 250; // reset SerialTimeout, but not in case of the "ping" |
191 | switch(SerialMsg.Address) // check for Slave Address |
190 | switch(SerialMsg.Address) // check for Slave Address |
192 | { |
191 | { |
193 | case NC_ADDRESS: // own Slave Address |
192 | case NC_ADDRESS: // own Slave Address |
194 | switch(SerialMsg.CmdID) |
193 | switch(SerialMsg.CmdID) |
195 | { |
194 | { |
196 | case 'z': // connection checker |
195 | case 'z': // connection checker |
197 | memcpy(&Echo, SerialMsg.pData, sizeof(Echo)); // copy echo pattern |
196 | memcpy(&Echo, SerialMsg.pData, sizeof(Echo)); // copy echo pattern |
198 | USB_Request_Echo = TRUE; |
197 | USB_Request_Echo = TRUE; |
199 | break; |
198 | break; |
200 | 199 | ||
201 | case 'e': // request for the text of the error status |
200 | case 'e': // request for the text of the error status |
202 | USB_Request_ErrorMessage = TRUE; |
201 | USB_Request_ErrorMessage = TRUE; |
203 | break; |
202 | break; |
204 | 203 | ||
205 | default: |
204 | default: |
206 | // unsupported command recieved |
205 | // unsupported command recieved |
207 | break; |
206 | break; |
208 | } // case NC_ADDRESS |
207 | } // case NC_ADDRESS |
209 | // "break;" is missing here to fall thru to the common commands |
208 | // "break;" is missing here to fall thru to the common commands |
210 | 209 | ||
211 | default: // and any other Slave Address |
210 | default: // and any other Slave Address |
212 | 211 | ||
213 | switch(SerialMsg.CmdID) // check CmdID |
212 | switch(SerialMsg.CmdID) // check CmdID |
214 | { |
213 | { |
215 | case 'a':// request for the labels of the analog debug outputs |
214 | case 'a':// request for the labels of the analog debug outputs |
216 | USB_Request_DebugLabel = SerialMsg.pData[0]; |
215 | USB_Request_DebugLabel = SerialMsg.pData[0]; |
217 | if(USB_Request_DebugLabel > 31) USB_Request_DebugLabel = 31; |
216 | if(USB_Request_DebugLabel > 31) USB_Request_DebugLabel = 31; |
218 | break; |
217 | break; |
219 | /* |
218 | /* |
220 | case 'b': // submit extern control |
219 | case 'b': // submit extern control |
221 | memcpy(&ExternControl, SerialMsg.pData, sizeof(ExternControl)); |
220 | memcpy(&ExternControl, SerialMsg.pData, sizeof(ExternControl)); |
222 | USB_ConfirmFrame = ExternControl.Frame; |
221 | USB_ConfirmFrame = ExternControl.Frame; |
223 | break; |
222 | break; |
224 | */ |
223 | */ |
225 | case 'd': // request for debug data; |
224 | case 'd': // request for debug data; |
226 | USB_DebugData_Interval = (u32) SerialMsg.pData[0] * 10; |
225 | USB_DebugData_Interval = (u32) SerialMsg.pData[0] * 10; |
227 | if(USB_DebugData_Interval > 0) USB_Request_DebugData = TRUE; |
226 | if(USB_DebugData_Interval > 0) USB_Request_DebugData = TRUE; |
228 | USB_AboTimeOut = SetDelay(ABO_TIMEOUT); |
227 | USB_AboTimeOut = SetDelay(ABO_TIMEOUT); |
229 | break; |
228 | break; |
230 | 229 | ||
231 | case 'c': // request for 3D data; |
230 | case 'c': // request for 3D data; |
232 | USB_Data3D_Interval = (u32) SerialMsg.pData[0] * 10; |
231 | USB_Data3D_Interval = (u32) SerialMsg.pData[0] * 10; |
233 | if(USB_Data3D_Interval > 0) USB_Request_Data3D = TRUE; |
232 | if(USB_Data3D_Interval > 0) USB_Request_Data3D = TRUE; |
234 | USB_AboTimeOut = SetDelay(ABO_TIMEOUT); |
233 | USB_AboTimeOut = SetDelay(ABO_TIMEOUT); |
235 | break; |
234 | break; |
236 | 235 | ||
237 | case 'h':// reqest for display line |
236 | case 'h':// reqest for display line |
238 | if((SerialMsg.pData[0]& 0x80) == 0x00)// old format |
237 | if((SerialMsg.pData[0]& 0x80) == 0x00)// old format |
239 | { |
238 | { |
240 | USB_DisplayLine = 2; |
239 | USB_DisplayLine = 2; |
241 | USB_Display_Interval = 0; |
240 | USB_Display_Interval = 0; |
242 | } |
241 | } |
243 | else |
242 | else |
244 | { |
243 | { |
245 | USB_DisplayKeys |= ~SerialMsg.pData[0]; |
244 | USB_DisplayKeys |= ~SerialMsg.pData[0]; |
246 | USB_Display_Interval = (u32) SerialMsg.pData[1] * 10; |
245 | USB_Display_Interval = (u32) SerialMsg.pData[1] * 10; |
247 | USB_DisplayLine = 4; |
246 | USB_DisplayLine = 4; |
248 | USB_AboTimeOut = SetDelay(ABO_TIMEOUT); |
247 | USB_AboTimeOut = SetDelay(ABO_TIMEOUT); |
249 | } |
248 | } |
250 | USB_Request_Display = TRUE; |
249 | USB_Request_Display = TRUE; |
251 | break; |
250 | break; |
252 | 251 | ||
253 | case 'l':// reqest for display columns |
252 | case 'l':// reqest for display columns |
254 | MenuItem = SerialMsg.pData[0]; |
253 | MenuItem = SerialMsg.pData[0]; |
255 | USB_Request_Display1 = TRUE; |
254 | USB_Request_Display1 = TRUE; |
256 | break; |
255 | break; |
257 | 256 | ||
258 | case 'o': // request for navigation information |
257 | case 'o': // request for navigation information |
259 | USB_NaviData_Interval = (u32) SerialMsg.pData[0] * 10; |
258 | USB_NaviData_Interval = (u32) SerialMsg.pData[0] * 10; |
260 | if(USB_NaviData_Interval > 0) USB_Request_NaviData = TRUE; |
259 | if(USB_NaviData_Interval > 0) USB_Request_NaviData = TRUE; |
261 | USB_AboTimeOut = SetDelay(ABO_TIMEOUT); |
260 | USB_AboTimeOut = SetDelay(ABO_TIMEOUT); |
262 | break; |
261 | break; |
263 | 262 | ||
264 | case 'v': // request for version info |
263 | case 'v': // request for version info |
265 | USB_Request_VersionInfo = TRUE; |
264 | USB_Request_VersionInfo = TRUE; |
266 | break; |
265 | break; |
267 | default: |
266 | default: |
268 | // unsupported command recieved |
267 | // unsupported command recieved |
269 | break; |
268 | break; |
270 | } |
269 | } |
271 | break; // default: |
270 | break; // default: |
272 | } |
271 | } |
273 | Buffer_Clear(&USB_rx_buffer); |
272 | Buffer_Clear(&USB_rx_buffer); |
274 | } |
273 | } |
275 | 274 | ||
276 | 275 | ||
277 | //----------------------------------------------------------------- |
276 | //----------------------------------------------------------------- |
278 | void USB_CableConfig(FunctionalState NewState) |
277 | void USB_CableConfig(FunctionalState NewState) |
279 | { |
278 | { |
280 | if (NewState == ENABLE) |
279 | if (NewState == ENABLE) |
281 | GPIO_WriteBit(GPIO0, GPIO_Pin_1, Bit_RESET); |
280 | GPIO_WriteBit(GPIO0, GPIO_Pin_1, Bit_RESET); |
282 | else |
281 | else |
283 | GPIO_WriteBit(GPIO0, GPIO_Pin_1, Bit_SET); |
282 | GPIO_WriteBit(GPIO0, GPIO_Pin_1, Bit_SET); |
284 | } |
283 | } |
285 | //----------------------------------------------------------------- |
284 | //----------------------------------------------------------------- |
286 | void USB_EnterLowPowerMode(void) |
285 | void USB_EnterLowPowerMode(void) |
287 | { |
286 | { |
288 | /* Set the device state to suspend */ |
287 | /* Set the device state to suspend */ |
289 | bDeviceState = SUSPENDED; |
288 | bDeviceState = SUSPENDED; |
290 | } |
289 | } |
291 | //----------------------------------------------------------------- |
290 | //----------------------------------------------------------------- |
292 | void USB_LeaveLowPowerMode(void) |
291 | void USB_LeaveLowPowerMode(void) |
293 | { |
292 | { |
294 | DEVICE_INFO *pInfo = &Device_Info; |
293 | DEVICE_INFO *pInfo = &Device_Info; |
295 | 294 | ||
296 | /* Set the device state to the correct state */ |
295 | /* Set the device state to the correct state */ |
297 | if (pInfo->Current_Configuration != 0) |
296 | if (pInfo->Current_Configuration != 0) |
298 | { |
297 | { |
299 | /* Device configured */ |
298 | /* Device configured */ |
300 | bDeviceState = CONFIGURED; |
299 | bDeviceState = CONFIGURED; |
301 | } |
300 | } |
302 | else |
301 | else |
303 | { |
302 | { |
304 | bDeviceState = ATTACHED; |
303 | bDeviceState = ATTACHED; |
305 | } |
304 | } |
306 | } |
305 | } |
307 | 306 | ||
308 | 307 | ||
309 | //----------------------------------------------------------------- |
308 | //----------------------------------------------------------------- |
310 | void USB_PutString(u8 *string) |
309 | void USB_PutString(u8 *string) |
311 | { |
310 | { |
312 | u8 i = 0; |
311 | u8 i = 0; |
313 | u16 timeout = 0; |
312 | u16 timeout = 0; |
314 | 313 | ||
315 | while (string[i++] != 0){} // get string len |
314 | while (string[i++] != 0){} // get string len |
316 | while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){ if (timeout++ > 60000) return;} |
315 | while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){ if (timeout++ > 60000) return;} |
317 | UserToPMABufferCopy(string, ENDP1_TXADDR, ++i); // copy string to usb buffer |
316 | UserToPMABufferCopy(string, ENDP1_TXADDR, ++i); // copy string to usb buffer |
318 | SetEPTxCount(ENDP1,i); |
317 | SetEPTxCount(ENDP1,i); |
319 | SetEPTxValid(ENDP1); |
318 | SetEPTxValid(ENDP1); |
320 | } |
319 | } |
321 | 320 | ||
322 | //----------------------------------------------------------------- |
321 | //----------------------------------------------------------------- |
323 | void USB_PutChar(u8 c) |
322 | void USB_PutChar(u8 c) |
324 | { |
323 | { |
325 | u16 timeout = 0; |
324 | u16 timeout = 0; |
326 | while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){ if (timeout++ > 60000) return;} |
325 | while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){ if (timeout++ > 60000) return;} |
327 | UserToPMABufferCopy(&c, ENDP1_TXADDR, 2); |
326 | UserToPMABufferCopy(&c, ENDP1_TXADDR, 2); |
328 | SetEPTxCount(ENDP1,2); |
327 | SetEPTxCount(ENDP1,2); |
329 | SetEPTxValid(ENDP1); |
328 | SetEPTxValid(ENDP1); |
330 | } |
329 | } |
331 | 330 | ||
332 | //----------------------------------------------------------------- |
331 | //----------------------------------------------------------------- |
333 | void USB_SendData(u8 *pdata, u16 count) |
332 | void USB_SendData(u8 *pdata, u16 count) |
334 | { |
333 | { |
335 | u8 i; |
334 | u8 i; |
336 | count++; |
335 | count++; |
337 | u16 timeout = 0; |
336 | u16 timeout = 0; |
338 | 337 | ||
339 | for (i=0;i< (count/64)+1;i++) |
338 | for (i=0;i< (count/64)+1;i++) |
340 | { |
339 | { |
341 | while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){if (timeout++ > 60000) return;} |
340 | while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){if (timeout++ > 60000) return;} |
342 | if (i < (count/64)) |
341 | if (i < (count/64)) |
343 | { |
342 | { |
344 | UserToPMABufferCopy(&pdata[i*64], ENDP1_TXADDR, 64); |
343 | UserToPMABufferCopy(&pdata[i*64], ENDP1_TXADDR, 64); |
345 | SetEPTxCount(ENDP1,64); |
344 | SetEPTxCount(ENDP1,64); |
346 | } |
345 | } |
347 | else |
346 | else |
348 | { |
347 | { |
349 | UserToPMABufferCopy(&pdata[i*64], ENDP1_TXADDR, count % 64); |
348 | UserToPMABufferCopy(&pdata[i*64], ENDP1_TXADDR, count % 64); |
350 | SetEPTxCount(ENDP1, count % 64); |
349 | SetEPTxCount(ENDP1, count % 64); |
351 | } |
350 | } |
352 | SetEPTxValid(ENDP1); |
351 | SetEPTxValid(ENDP1); |
353 | } |
352 | } |
354 | } |
353 | } |
355 | 354 | ||
356 | /**************************************************************/ |
355 | /**************************************************************/ |
357 | /* Transmit tx buffer via usb */ |
356 | /* Transmit tx buffer via usb */ |
358 | /**************************************************************/ |
357 | /**************************************************************/ |
359 | void USB_Transmit(void) |
358 | void USB_Transmit(void) |
360 | { // nur blockweises kopieren des sendebuffers, nicht alles mit einem mal |
359 | { // nur blockweises kopieren des sendebuffers, nicht alles mit einem mal |
361 | // if something has to be send and the txd fifo is not full |
360 | // if something has to be send and the txd fifo is not full |
362 | 361 | ||
363 | if(USB_tx_buffer.Locked == TRUE) |
362 | if(USB_tx_buffer.Locked == TRUE) |
364 | { |
363 | { |
365 | if(_GetEPTxStatus(ENDP1) == EP_TX_NAK) |
364 | if(_GetEPTxStatus(ENDP1) == EP_TX_NAK) |
366 | { |
365 | { |
367 | u16 i; |
366 | u16 i; |
368 | if(USB_tx_buffer.Position < USB_tx_buffer.DataBytes) |
367 | if(USB_tx_buffer.Position < USB_tx_buffer.DataBytes) |
369 | { |
368 | { |
370 | i = USB_tx_buffer.DataBytes - USB_tx_buffer.Position; // bytes to send |
369 | i = USB_tx_buffer.DataBytes - USB_tx_buffer.Position; // bytes to send |
371 | if(i > 64) i = 64; // limit packet size to 64 bytes |
370 | if(i > 64) i = 64; // limit packet size to 64 bytes |
372 | UserToPMABufferCopy(&(USB_tx_buffer.pData[USB_tx_buffer.Position]), ENDP1_TXADDR, i); |
371 | UserToPMABufferCopy(&(USB_tx_buffer.pData[USB_tx_buffer.Position]), ENDP1_TXADDR, i); |
373 | SetEPTxCount(ENDP1,i); |
372 | SetEPTxCount(ENDP1,i); |
374 | SetEPTxValid(ENDP1); |
373 | SetEPTxValid(ENDP1); |
375 | USB_tx_buffer.Position += i; |
374 | USB_tx_buffer.Position += i; |
376 | } |
375 | } |
377 | } |
376 | } |
378 | if(USB_tx_buffer.Position >= USB_tx_buffer.DataBytes) // all bytes transfered |
377 | if(USB_tx_buffer.Position >= USB_tx_buffer.DataBytes) // all bytes transfered |
379 | { |
378 | { |
380 | Buffer_Clear(&USB_tx_buffer); // clear buffer |
379 | Buffer_Clear(&USB_tx_buffer); // clear buffer |
381 | } |
380 | } |
382 | } |
381 | } |
383 | } |
382 | } |
384 | 383 | ||
385 | /**************************************************************/ |
384 | /**************************************************************/ |
386 | /* Send the answers to incomming commands at the debug uart */ |
385 | /* Send the answers to incomming commands at the debug uart */ |
387 | /**************************************************************/ |
386 | /**************************************************************/ |
388 | void USB_TransmitTxData(void) |
387 | void USB_TransmitTxData(void) |
389 | { |
388 | { |
390 | USB_Transmit(); // output pending bytes in tx buffer |
389 | USB_Transmit(); // output pending bytes in tx buffer |
391 | if((USB_tx_buffer.Locked == TRUE)) return; |
390 | if((USB_tx_buffer.Locked == TRUE)) return; |
392 | 391 | ||
393 | if(CheckDelay(USB_AboTimeOut)) |
392 | if(CheckDelay(USB_AboTimeOut)) |
394 | { |
393 | { |
395 | USB_DebugData_Interval = 0; |
394 | USB_DebugData_Interval = 0; |
396 | USB_NaviData_Interval = 0; |
395 | USB_NaviData_Interval = 0; |
397 | USB_Data3D_Interval = 0; |
396 | USB_Data3D_Interval = 0; |
398 | USB_Display_Interval = 0; |
397 | USB_Display_Interval = 0; |
399 | } |
398 | } |
400 | 399 | ||
401 | if((USB_Request_DebugLabel != 0xFF) && (USB_tx_buffer.Locked == FALSE)) |
400 | if((USB_Request_DebugLabel != 0xFF) && (USB_tx_buffer.Locked == FALSE)) |
402 | { |
401 | { |
403 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'A', NC_ADDRESS, 2, &USB_Request_DebugLabel, sizeof(USB_Request_DebugLabel), (u8 *) ANALOG_LABEL[USB_Request_DebugLabel], 16); |
402 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'A', NC_ADDRESS, 2, &USB_Request_DebugLabel, sizeof(USB_Request_DebugLabel), (u8 *) ANALOG_LABEL[USB_Request_DebugLabel], 16); |
404 | USB_Request_DebugLabel = 0xFF; |
403 | USB_Request_DebugLabel = 0xFF; |
405 | } |
404 | } |
406 | else if(USB_ConfirmFrame && (USB_tx_buffer.Locked == FALSE)) |
405 | else if(USB_ConfirmFrame && (USB_tx_buffer.Locked == FALSE)) |
407 | { |
406 | { |
408 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'B', NC_ADDRESS, 1, &USB_ConfirmFrame, sizeof(USB_ConfirmFrame)); |
407 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'B', NC_ADDRESS, 1, &USB_ConfirmFrame, sizeof(USB_ConfirmFrame)); |
409 | USB_ConfirmFrame = 0; |
408 | USB_ConfirmFrame = 0; |
410 | } |
409 | } |
411 | else if( (( (USB_DebugData_Interval > 0) && CheckDelay(USB_DebugData_Timer)) || USB_Request_DebugData) && (USB_tx_buffer.Locked == FALSE)) |
410 | else if( (( (USB_DebugData_Interval > 0) && CheckDelay(USB_DebugData_Timer)) || USB_Request_DebugData) && (USB_tx_buffer.Locked == FALSE)) |
412 | { |
411 | { |
413 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'D', NC_ADDRESS, 1,(u8 *)&DebugOut, sizeof(DebugOut)); |
412 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'D', NC_ADDRESS, 1,(u8 *)&DebugOut, sizeof(DebugOut)); |
414 | USB_DebugData_Timer = SetDelay(USB_DebugData_Interval); |
413 | USB_DebugData_Timer = SetDelay(USB_DebugData_Interval); |
415 | USB_Request_DebugData = FALSE; |
414 | USB_Request_DebugData = FALSE; |
416 | } |
415 | } |
417 | else if((( (USB_Data3D_Interval > 0) && CheckDelay(USB_Data3D_Timer) ) || USB_Request_Data3D) && (USB_tx_buffer.Locked == FALSE)) |
416 | else if((( (USB_Data3D_Interval > 0) && CheckDelay(USB_Data3D_Timer) ) || USB_Request_Data3D) && (USB_tx_buffer.Locked == FALSE)) |
418 | { |
417 | { |
419 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'C', NC_ADDRESS, 1,(u8 *)&Data3D, sizeof(Data3D)); |
418 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'C', NC_ADDRESS, 1,(u8 *)&Data3D, sizeof(Data3D)); |
420 | USB_Data3D_Timer = SetDelay(USB_Data3D_Interval); |
419 | USB_Data3D_Timer = SetDelay(USB_Data3D_Interval); |
421 | USB_Request_Data3D = FALSE; |
420 | USB_Request_Data3D = FALSE; |
422 | } |
421 | } |
423 | else if(USB_Request_ExternalControl && (USB_tx_buffer.Locked == FALSE)) |
422 | else if(USB_Request_ExternalControl && (USB_tx_buffer.Locked == FALSE)) |
424 | { |
423 | { |
425 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'G', NC_ADDRESS, 1, (u8 *)&ExternControl, sizeof(ExternControl)); |
424 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'G', NC_ADDRESS, 1, (u8 *)&ExternControl, sizeof(ExternControl)); |
426 | USB_Request_ExternalControl = FALSE; |
425 | USB_Request_ExternalControl = FALSE; |
427 | } |
426 | } |
428 | else if( (( (USB_Display_Interval > 0) && CheckDelay(USB_Display_Timer)) || USB_Request_Display) && (USB_tx_buffer.Locked == FALSE)) |
427 | else if( (( (USB_Display_Interval > 0) && CheckDelay(USB_Display_Timer)) || USB_Request_Display) && (USB_tx_buffer.Locked == FALSE)) |
429 | { |
428 | { |
430 | Menu_Update(USB_DisplayKeys); |
429 | Menu_Update(USB_DisplayKeys); |
431 | USB_DisplayKeys = 0; |
430 | USB_DisplayKeys = 0; |
432 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'H', NC_ADDRESS, 1, (u8*)DisplayBuff, sizeof(DisplayBuff)); |
431 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'H', NC_ADDRESS, 1, (u8*)DisplayBuff, sizeof(DisplayBuff)); |
433 | USB_Request_Display = FALSE; |
432 | USB_Request_Display = FALSE; |
434 | } |
433 | } |
435 | else if(USB_Request_Display1 && (USB_tx_buffer.Locked == FALSE)) |
434 | else if(USB_Request_Display1 && (USB_tx_buffer.Locked == FALSE)) |
436 | { |
435 | { |
437 | Menu_Update(0); |
436 | Menu_Update(0); |
438 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'L', NC_ADDRESS, 3, (u8*)&MenuItem, sizeof(MenuItem), (u8*)&MaxMenuItem, sizeof(MaxMenuItem),(u8*)DisplayBuff, sizeof(DisplayBuff)); |
437 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'L', NC_ADDRESS, 3, (u8*)&MenuItem, sizeof(MenuItem), (u8*)&MaxMenuItem, sizeof(MaxMenuItem),(u8*)DisplayBuff, sizeof(DisplayBuff)); |
439 | USB_Request_Display1 = FALSE; |
438 | USB_Request_Display1 = FALSE; |
440 | } |
439 | } |
441 | else if(USB_Request_VersionInfo && (USB_tx_buffer.Locked == FALSE)) |
440 | else if(USB_Request_VersionInfo && (USB_tx_buffer.Locked == FALSE)) |
442 | { |
441 | { |
443 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'V', NC_ADDRESS,1, (u8 *)&UART_VersionInfo, sizeof(UART_VersionInfo)); |
442 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'V', NC_ADDRESS,1, (u8 *)&UART_VersionInfo, sizeof(UART_VersionInfo)); |
444 | USB_Request_VersionInfo = FALSE; |
443 | USB_Request_VersionInfo = FALSE; |
445 | } |
444 | } |
446 | else if(( (USB_NaviData_Interval && CheckDelay(USB_NaviData_Timer) ) || USB_Request_NaviData) && (USB_tx_buffer.Locked == FALSE)) |
445 | else if(( (USB_NaviData_Interval && CheckDelay(USB_NaviData_Timer) ) || USB_Request_NaviData) && (USB_tx_buffer.Locked == FALSE)) |
447 | { |
446 | { |
448 | NaviData.Errorcode = ErrorCode; |
447 | NaviData.Errorcode = ErrorCode; |
449 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'O', NC_ADDRESS,1, (u8 *)&NaviData, sizeof(NaviData)); |
448 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'O', NC_ADDRESS,1, (u8 *)&NaviData, sizeof(NaviData)); |
450 | USB_NaviData_Timer = SetDelay(USB_NaviData_Interval); |
449 | USB_NaviData_Timer = SetDelay(USB_NaviData_Interval); |
451 | USB_Request_NaviData = FALSE; |
450 | USB_Request_NaviData = FALSE; |
452 | } |
451 | } |
453 | else if(USB_Request_ErrorMessage && (USB_tx_buffer.Locked == FALSE)) |
452 | else if(USB_Request_ErrorMessage && (USB_tx_buffer.Locked == FALSE)) |
454 | { |
453 | { |
455 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'E', NC_ADDRESS, 1, (u8 *)&ErrorMSG, sizeof(ErrorMSG)); |
454 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'E', NC_ADDRESS, 1, (u8 *)&ErrorMSG, sizeof(ErrorMSG)); |
456 | USB_Request_ErrorMessage = FALSE; |
455 | USB_Request_ErrorMessage = FALSE; |
457 | } |
456 | } |
458 | USB_Transmit(); // output pending bytes in tx buffer |
457 | USB_Transmit(); // output pending bytes in tx buffer |
459 | } |
458 | } |
460 | 459 |