Rev 275 | Rev 313 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 275 | Rev 280 | ||
---|---|---|---|
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 / NON-COMMERCIAL USE ONLY |
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 oder Nutzung 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 the sources to other systems or using the software on other systems (except 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 <stdio.h> |
57 | #include <stdio.h> |
58 | #include <string.h> |
58 | #include <string.h> |
59 | #include "91x_lib.h" |
59 | #include "91x_lib.h" |
60 | #include "config.h" |
60 | #include "config.h" |
61 | #include "main.h" |
61 | #include "main.h" |
62 | #include "uart1.h" |
62 | #include "uart1.h" |
63 | #include "mkprotocol.h" |
63 | #include "mkprotocol.h" |
64 | #include "waypoints.h" |
64 | #include "waypoints.h" |
65 | #include "gps.h" |
65 | #include "gps.h" |
66 | #include "timer1.h" |
66 | #include "timer1.h" |
67 | #include "uart0.h" |
67 | #include "uart0.h" |
68 | #include "uart1.h" |
68 | #include "uart1.h" |
69 | #include "uart2.h" |
69 | #include "uart2.h" |
70 | #include "menu.h" |
70 | #include "menu.h" |
71 | #include "usb.h" |
71 | #include "usb.h" |
72 | 72 | ||
73 | #define ABO_TIMEOUT 4000 // disable abo after 4 seconds |
73 | #define ABO_TIMEOUT 4000 // disable abo after 4 seconds |
74 | u32 USB_AboTimeOut = 0; |
74 | u32 USB_AboTimeOut = 0; |
75 | 75 | ||
76 | u16 Echo; // 2 bytes recieved will be sent back as echo |
76 | u16 Echo; // 2 bytes recieved will be sent back as echo |
77 | 77 | ||
78 | // the primary rx fifo |
78 | // the primary rx fifo |
79 | #define USB_RX_FIFO_LEN 512 |
79 | #define USB_RX_FIFO_LEN 512 |
80 | u8 USB_rxfifobuffer[USB_RX_FIFO_LEN]; |
80 | u8 USB_rxfifobuffer[USB_RX_FIFO_LEN]; |
81 | fifo_t USB_rx_fifo; |
81 | fifo_t USB_rx_fifo; |
82 | 82 | ||
83 | // the tx buffer |
83 | // the tx buffer |
84 | #define USB_TX_BUFFER_LEN 150 |
84 | #define USB_TX_BUFFER_LEN 150 |
85 | u8 USB_tbuffer[USB_TX_BUFFER_LEN]; |
85 | u8 USB_tbuffer[USB_TX_BUFFER_LEN]; |
86 | Buffer_t USB_tx_buffer; |
86 | Buffer_t USB_tx_buffer; |
87 | 87 | ||
88 | // the rx buffer |
88 | // the rx buffer |
89 | #define USB_RX_BUFFER_LEN 150 |
89 | #define USB_RX_BUFFER_LEN 150 |
90 | u8 USB_rbuffer[USB_RX_BUFFER_LEN]; |
90 | u8 USB_rbuffer[USB_RX_BUFFER_LEN]; |
91 | Buffer_t USB_rx_buffer; |
91 | Buffer_t USB_rx_buffer; |
92 | 92 | ||
93 | u8 USB_Request_VersionInfo = FALSE; |
93 | u8 USB_Request_VersionInfo = FALSE; |
94 | u8 USB_Request_SendFollowMe = FALSE; |
94 | u8 USB_Request_SendFollowMe = FALSE; |
95 | u8 USB_Request_ExternalControl= FALSE; |
95 | u8 USB_Request_ExternalControl= FALSE; |
96 | u8 USB_Request_Display = FALSE; |
96 | u8 USB_Request_Display = FALSE; |
97 | u8 USB_Request_Display1 = FALSE; |
97 | u8 USB_Request_Display1 = FALSE; |
98 | u8 USB_Request_DebugData = FALSE; |
98 | u8 USB_Request_DebugData = FALSE; |
99 | u8 USB_Request_DebugLabel = 255; |
99 | u8 USB_Request_DebugLabel = 255; |
100 | u8 USB_Request_NaviData = FALSE; |
100 | u8 USB_Request_NaviData = FALSE; |
101 | u8 USB_Request_ErrorMessage = FALSE; |
101 | u8 USB_Request_ErrorMessage = FALSE; |
102 | u8 USB_Request_NewWaypoint = FALSE; |
- | |
103 | u8 USB_Request_ReadWaypoint = 255; |
- | |
104 | u8 USB_Request_Data3D = FALSE; |
102 | u8 USB_Request_Data3D = FALSE; |
105 | u8 USB_Request_Echo = FALSE; |
103 | u8 USB_Request_Echo = FALSE; |
106 | u8 USB_DisplayKeys = 0; |
104 | u8 USB_DisplayKeys = 0; |
107 | u8 USB_DisplayLine = 0; |
105 | u8 USB_DisplayLine = 0; |
108 | u8 USB_ConfirmFrame = 0; |
106 | u8 USB_ConfirmFrame = 0; |
109 | 107 | ||
110 | u32 USB_DebugData_Timer = 0; |
108 | u32 USB_DebugData_Timer = 0; |
111 | u32 USB_DebugData_Interval = 0; // in ms |
109 | u32 USB_DebugData_Interval = 0; // in ms |
112 | u32 USB_NaviData_Timer = 0; |
110 | u32 USB_NaviData_Timer = 0; |
113 | u32 USB_NaviData_Interval = 0; // in ms |
111 | u32 USB_NaviData_Interval = 0; // in ms |
114 | u32 USB_Data3D_Timer = 0; |
112 | u32 USB_Data3D_Timer = 0; |
115 | u32 USB_Data3D_Interval = 0; // in ms |
113 | u32 USB_Data3D_Interval = 0; // in ms |
116 | u32 USB_Display_Timer = 0; |
114 | u32 USB_Display_Timer = 0; |
117 | u32 USB_Display_Interval = 0; // in ms |
115 | u32 USB_Display_Interval = 0; // in ms |
118 | 116 | ||
119 | //----------------------------------------------------------------- |
117 | //----------------------------------------------------------------- |
120 | void USB_ConfigInit(void) |
118 | void USB_ConfigInit(void) |
121 | { |
119 | { |
122 | GPIO_InitTypeDef GPIO_InitStructure; |
120 | GPIO_InitTypeDef GPIO_InitStructure; |
123 | 121 | ||
124 | UART1_PutString("\r\n USB init..."); |
122 | UART1_PutString("\r\n USB init..."); |
125 | #ifdef MCLK96MHZ |
123 | #ifdef MCLK96MHZ |
126 | //USB clock = MCLK/2 = 48MHz |
124 | //USB clock = MCLK/2 = 48MHz |
127 | SCU_USBCLKConfig(SCU_USBCLK_MCLK2); |
125 | SCU_USBCLKConfig(SCU_USBCLK_MCLK2); |
128 | #else |
126 | #else |
129 | //USB clock = MCLK = 48MHz |
127 | //USB clock = MCLK = 48MHz |
130 | SCU_USBCLKConfig(SCU_USBCLK_MCLK); |
128 | SCU_USBCLKConfig(SCU_USBCLK_MCLK); |
131 | #endif |
129 | #endif |
132 | //Enable USB clock |
130 | //Enable USB clock |
133 | SCU_AHBPeriphClockConfig(__USB,ENABLE); |
131 | SCU_AHBPeriphClockConfig(__USB,ENABLE); |
134 | SCU_AHBPeriphReset(__USB,DISABLE); |
132 | SCU_AHBPeriphReset(__USB,DISABLE); |
135 | SCU_AHBPeriphClockConfig(__USB48M,ENABLE); |
133 | SCU_AHBPeriphClockConfig(__USB48M,ENABLE); |
136 | 134 | ||
137 | //Configure GPIO0 (D+ Pull-Up on P0.1) |
135 | //Configure GPIO0 (D+ Pull-Up on P0.1) |
138 | SCU_APBPeriphClockConfig(__GPIO0 ,ENABLE); |
136 | SCU_APBPeriphClockConfig(__GPIO0 ,ENABLE); |
139 | SCU_APBPeriphReset(__GPIO0,DISABLE); |
137 | SCU_APBPeriphReset(__GPIO0,DISABLE); |
140 | 138 | ||
141 | // GPIO_DeInit(P0.1); |
139 | // GPIO_DeInit(P0.1); |
142 | GPIO_StructInit(&GPIO_InitStructure); |
140 | GPIO_StructInit(&GPIO_InitStructure); |
143 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
141 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
144 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; |
142 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; |
145 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
143 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
146 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable; |
144 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable; |
147 | GPIO_InitStructure.GPIO_Alternate=GPIO_OutputAlt1; |
145 | GPIO_InitStructure.GPIO_Alternate=GPIO_OutputAlt1; |
148 | GPIO_Init (GPIO0, &GPIO_InitStructure); |
146 | GPIO_Init (GPIO0, &GPIO_InitStructure); |
149 | 147 | ||
150 | // initialize the rx fifo, block UART IRQ geting a byte from fifo |
148 | // initialize the rx fifo, block UART IRQ geting a byte from fifo |
151 | fifo_init(&USB_rx_fifo, USB_rxfifobuffer, USB_RX_FIFO_LEN, NO_ITLine, USBLP_ITLine); |
149 | fifo_init(&USB_rx_fifo, USB_rxfifobuffer, USB_RX_FIFO_LEN, NO_ITLine, USBLP_ITLine); |
152 | 150 | ||
153 | // initialize txd buffer |
151 | // initialize txd buffer |
154 | Buffer_Init(&USB_tx_buffer, USB_tbuffer, USB_TX_BUFFER_LEN); |
152 | Buffer_Init(&USB_tx_buffer, USB_tbuffer, USB_TX_BUFFER_LEN); |
155 | 153 | ||
156 | // initialize rxd buffer |
154 | // initialize rxd buffer |
157 | Buffer_Init(&USB_rx_buffer, USB_rbuffer, USB_RX_BUFFER_LEN); |
155 | Buffer_Init(&USB_rx_buffer, USB_rbuffer, USB_RX_BUFFER_LEN); |
158 | 156 | ||
159 | VIC_Config(USBLP_ITLine, VIC_IRQ, PRIORITY_USB); |
157 | VIC_Config(USBLP_ITLine, VIC_IRQ, PRIORITY_USB); |
160 | VIC_ITCmd(USBLP_ITLine, ENABLE); |
158 | VIC_ITCmd(USBLP_ITLine, ENABLE); |
161 | 159 | ||
162 | USB_Init(); |
160 | USB_Init(); |
163 | 161 | ||
164 | UART1_PutString("ok"); |
162 | UART1_PutString("ok"); |
165 | } |
163 | } |
166 | 164 | ||
167 | 165 | ||
168 | /**************************************************************/ |
166 | /**************************************************************/ |
169 | /* Process incomming data from debug uart */ |
167 | /* Process incomming data from debug uart */ |
170 | /**************************************************************/ |
168 | /**************************************************************/ |
171 | void USB_ProcessRxData(void) |
169 | void USB_ProcessRxData(void) |
172 | { |
170 | { |
173 | u8 c; |
171 | u8 c; |
174 | SerialMsg_t SerialMsg; |
172 | SerialMsg_t SerialMsg; |
175 | Waypoint_t * pWaypoint = NULL; |
- | |
- | 173 | ||
176 | // if data in the rxd buffer are not locked immediately return |
174 | // if data in the rxd buffer are not locked immediately return |
177 | // if rx buffer is not locked |
175 | // if rx buffer is not locked |
178 | if(USB_rx_buffer.Locked == FALSE) |
176 | if(USB_rx_buffer.Locked == FALSE) |
179 | { |
177 | { |
180 | //collect data from primary rx fifo |
178 | //collect data from primary rx fifo |
181 | while(fifo_get(&USB_rx_fifo, &c)) |
179 | while(fifo_get(&USB_rx_fifo, &c)) |
182 | { |
180 | { |
183 | // break if complete frame has been collected |
181 | // break if complete frame has been collected |
184 | if(MKProtocol_CollectSerialFrame(&USB_rx_buffer, c)) break; |
182 | if(MKProtocol_CollectSerialFrame(&USB_rx_buffer, c)) break; |
185 | } |
183 | } |
186 | } |
184 | } |
187 | if(USB_rx_buffer.Locked == FALSE) return; |
185 | if(USB_rx_buffer.Locked == FALSE) return; |
188 | 186 | ||
189 | MKProtocol_DecodeSerialFrameHeader(&USB_rx_buffer, &SerialMsg); // decode serial frame in rxd buffer |
187 | MKProtocol_DecodeSerialFrameHeader(&USB_rx_buffer, &SerialMsg); // decode serial frame in rxd buffer |
190 | MKProtocol_DecodeSerialFrameData(&USB_rx_buffer, &SerialMsg); // decode serial frame in rxd buffer |
188 | MKProtocol_DecodeSerialFrameData(&USB_rx_buffer, &SerialMsg); // decode serial frame in rxd buffer |
191 | 189 | ||
192 | if(SerialMsg.CmdID != 'z') SerialLinkOkay = 250; // reset SerialTimeout, but not in case of the "ping" |
190 | if(SerialMsg.CmdID != 'z') SerialLinkOkay = 250; // reset SerialTimeout, but not in case of the "ping" |
193 | switch(SerialMsg.Address) // check for Slave Address |
191 | switch(SerialMsg.Address) // check for Slave Address |
194 | { |
192 | { |
195 | case NC_ADDRESS: // own Slave Address |
193 | case NC_ADDRESS: // own Slave Address |
196 | switch(SerialMsg.CmdID) |
194 | switch(SerialMsg.CmdID) |
197 | { |
195 | { |
198 | case 'z': // connection checker |
196 | case 'z': // connection checker |
199 | memcpy(&Echo, SerialMsg.pData, sizeof(Echo)); // copy echo pattern |
197 | memcpy(&Echo, SerialMsg.pData, sizeof(Echo)); // copy echo pattern |
200 | USB_Request_Echo = TRUE; |
198 | USB_Request_Echo = TRUE; |
201 | break; |
199 | break; |
202 | 200 | ||
203 | case 'e': // request for the text of the error status |
201 | case 'e': // request for the text of the error status |
204 | USB_Request_ErrorMessage = TRUE; |
202 | USB_Request_ErrorMessage = TRUE; |
205 | break; |
203 | break; |
206 | - | ||
207 | case 's':// new target position |
- | |
208 | pWaypoint = (Waypoint_t*)SerialMsg.pData; |
- | |
209 | BeepTime = 300; |
- | |
210 | if(pWaypoint->Position.Status == NEWDATA) |
- | |
211 | { |
- | |
212 | WPList_Clear(); // empty WPList |
- | |
213 | WPList_Append(pWaypoint); |
- | |
214 | GPS_pWaypoint = WPList_Begin(); |
- | |
215 | } |
- | |
216 | break; |
- | |
217 | - | ||
218 | case 'w':// Append Waypoint to List |
- | |
219 | { |
- | |
220 | pWaypoint = (Waypoint_t*)SerialMsg.pData; |
- | |
221 | - | ||
222 | if((pWaypoint->Position.Status == INVALID) && (pWaypoint->Index == 0)) |
- | |
223 | { |
- | |
224 | WPList_Clear(); |
- | |
225 | GPS_pWaypoint = WPList_Begin(); |
- | |
226 | USB_Request_NewWaypoint = TRUE; // return new WP number |
- | |
227 | } |
- | |
228 | else |
- | |
229 | { // app current WP to the list |
- | |
230 | if (pWaypoint->Index == (WPList_GetCount() + 1)) |
- | |
231 | { |
- | |
232 | WPList_Append(pWaypoint); |
- | |
233 | BeepTime = 500; |
- | |
234 | USB_Request_NewWaypoint = TRUE; // return new WP number |
- | |
235 | } |
- | |
236 | } |
- | |
237 | } |
- | |
238 | break; |
- | |
239 | - | ||
240 | case 'x':// Read Waypoint from List |
- | |
241 | USB_Request_ReadWaypoint = SerialMsg.pData[0]; |
- | |
242 | break; |
- | |
243 | 204 | ||
244 | default: |
205 | default: |
245 | // unsupported command recieved |
206 | // unsupported command recieved |
246 | break; |
207 | break; |
247 | } // case NC_ADDRESS |
208 | } // case NC_ADDRESS |
248 | // "break;" is missing here to fall thru to the common commands |
209 | // "break;" is missing here to fall thru to the common commands |
249 | 210 | ||
250 | default: // and any other Slave Address |
211 | default: // and any other Slave Address |
251 | 212 | ||
252 | switch(SerialMsg.CmdID) // check CmdID |
213 | switch(SerialMsg.CmdID) // check CmdID |
253 | { |
214 | { |
254 | case 'a':// request for the labels of the analog debug outputs |
215 | case 'a':// request for the labels of the analog debug outputs |
255 | USB_Request_DebugLabel = SerialMsg.pData[0]; |
216 | USB_Request_DebugLabel = SerialMsg.pData[0]; |
256 | if(USB_Request_DebugLabel > 31) USB_Request_DebugLabel = 31; |
217 | if(USB_Request_DebugLabel > 31) USB_Request_DebugLabel = 31; |
257 | break; |
218 | break; |
258 | /* |
219 | /* |
259 | case 'b': // submit extern control |
220 | case 'b': // submit extern control |
260 | memcpy(&ExternControl, SerialMsg.pData, sizeof(ExternControl)); |
221 | memcpy(&ExternControl, SerialMsg.pData, sizeof(ExternControl)); |
261 | USB_ConfirmFrame = ExternControl.Frame; |
222 | USB_ConfirmFrame = ExternControl.Frame; |
262 | break; |
223 | break; |
263 | */ |
224 | */ |
264 | case 'd': // request for debug data; |
225 | case 'd': // request for debug data; |
265 | USB_DebugData_Interval = (u32) SerialMsg.pData[0] * 10; |
226 | USB_DebugData_Interval = (u32) SerialMsg.pData[0] * 10; |
266 | if(USB_DebugData_Interval > 0) USB_Request_DebugData = TRUE; |
227 | if(USB_DebugData_Interval > 0) USB_Request_DebugData = TRUE; |
267 | USB_AboTimeOut = SetDelay(ABO_TIMEOUT); |
228 | USB_AboTimeOut = SetDelay(ABO_TIMEOUT); |
268 | break; |
229 | break; |
269 | 230 | ||
270 | case 'c': // request for 3D data; |
231 | case 'c': // request for 3D data; |
271 | USB_Data3D_Interval = (u32) SerialMsg.pData[0] * 10; |
232 | USB_Data3D_Interval = (u32) SerialMsg.pData[0] * 10; |
272 | if(USB_Data3D_Interval > 0) USB_Request_Data3D = TRUE; |
233 | if(USB_Data3D_Interval > 0) USB_Request_Data3D = TRUE; |
273 | USB_AboTimeOut = SetDelay(ABO_TIMEOUT); |
234 | USB_AboTimeOut = SetDelay(ABO_TIMEOUT); |
274 | break; |
235 | break; |
275 | 236 | ||
276 | case 'h':// reqest for display line |
237 | case 'h':// reqest for display line |
277 | if((SerialMsg.pData[0]& 0x80) == 0x00)// old format |
238 | if((SerialMsg.pData[0]& 0x80) == 0x00)// old format |
278 | { |
239 | { |
279 | USB_DisplayLine = 2; |
240 | USB_DisplayLine = 2; |
280 | USB_Display_Interval = 0; |
241 | USB_Display_Interval = 0; |
281 | } |
242 | } |
282 | else |
243 | else |
283 | { |
244 | { |
284 | USB_DisplayKeys |= ~SerialMsg.pData[0]; |
245 | USB_DisplayKeys |= ~SerialMsg.pData[0]; |
285 | USB_Display_Interval = (u32) SerialMsg.pData[1] * 10; |
246 | USB_Display_Interval = (u32) SerialMsg.pData[1] * 10; |
286 | USB_DisplayLine = 4; |
247 | USB_DisplayLine = 4; |
287 | USB_AboTimeOut = SetDelay(ABO_TIMEOUT); |
248 | USB_AboTimeOut = SetDelay(ABO_TIMEOUT); |
288 | } |
249 | } |
289 | USB_Request_Display = TRUE; |
250 | USB_Request_Display = TRUE; |
290 | break; |
251 | break; |
291 | 252 | ||
292 | case 'l':// reqest for display columns |
253 | case 'l':// reqest for display columns |
293 | MenuItem = SerialMsg.pData[0]; |
254 | MenuItem = SerialMsg.pData[0]; |
294 | USB_Request_Display1 = TRUE; |
255 | USB_Request_Display1 = TRUE; |
295 | break; |
256 | break; |
296 | 257 | ||
297 | case 'o': // request for navigation information |
258 | case 'o': // request for navigation information |
298 | USB_NaviData_Interval = (u32) SerialMsg.pData[0] * 10; |
259 | USB_NaviData_Interval = (u32) SerialMsg.pData[0] * 10; |
299 | if(USB_NaviData_Interval > 0) USB_Request_NaviData = TRUE; |
260 | if(USB_NaviData_Interval > 0) USB_Request_NaviData = TRUE; |
300 | USB_AboTimeOut = SetDelay(ABO_TIMEOUT); |
261 | USB_AboTimeOut = SetDelay(ABO_TIMEOUT); |
301 | break; |
262 | break; |
302 | 263 | ||
303 | case 'v': // request for version info |
264 | case 'v': // request for version info |
304 | USB_Request_VersionInfo = TRUE; |
265 | USB_Request_VersionInfo = TRUE; |
305 | break; |
266 | break; |
306 | default: |
267 | default: |
307 | // unsupported command recieved |
268 | // unsupported command recieved |
308 | break; |
269 | break; |
309 | } |
270 | } |
310 | break; // default: |
271 | break; // default: |
311 | } |
272 | } |
312 | Buffer_Clear(&USB_rx_buffer); |
273 | Buffer_Clear(&USB_rx_buffer); |
313 | } |
274 | } |
314 | 275 | ||
315 | 276 | ||
316 | //----------------------------------------------------------------- |
277 | //----------------------------------------------------------------- |
317 | void USB_CableConfig(FunctionalState NewState) |
278 | void USB_CableConfig(FunctionalState NewState) |
318 | { |
279 | { |
319 | if (NewState == ENABLE) |
280 | if (NewState == ENABLE) |
320 | GPIO_WriteBit(GPIO0, GPIO_Pin_1, Bit_RESET); |
281 | GPIO_WriteBit(GPIO0, GPIO_Pin_1, Bit_RESET); |
321 | else |
282 | else |
322 | GPIO_WriteBit(GPIO0, GPIO_Pin_1, Bit_SET); |
283 | GPIO_WriteBit(GPIO0, GPIO_Pin_1, Bit_SET); |
323 | } |
284 | } |
324 | //----------------------------------------------------------------- |
285 | //----------------------------------------------------------------- |
325 | void USB_EnterLowPowerMode(void) |
286 | void USB_EnterLowPowerMode(void) |
326 | { |
287 | { |
327 | /* Set the device state to suspend */ |
288 | /* Set the device state to suspend */ |
328 | bDeviceState = SUSPENDED; |
289 | bDeviceState = SUSPENDED; |
329 | } |
290 | } |
330 | //----------------------------------------------------------------- |
291 | //----------------------------------------------------------------- |
331 | void USB_LeaveLowPowerMode(void) |
292 | void USB_LeaveLowPowerMode(void) |
332 | { |
293 | { |
333 | DEVICE_INFO *pInfo = &Device_Info; |
294 | DEVICE_INFO *pInfo = &Device_Info; |
334 | 295 | ||
335 | /* Set the device state to the correct state */ |
296 | /* Set the device state to the correct state */ |
336 | if (pInfo->Current_Configuration != 0) |
297 | if (pInfo->Current_Configuration != 0) |
337 | { |
298 | { |
338 | /* Device configured */ |
299 | /* Device configured */ |
339 | bDeviceState = CONFIGURED; |
300 | bDeviceState = CONFIGURED; |
340 | } |
301 | } |
341 | else |
302 | else |
342 | { |
303 | { |
343 | bDeviceState = ATTACHED; |
304 | bDeviceState = ATTACHED; |
344 | } |
305 | } |
345 | } |
306 | } |
346 | 307 | ||
347 | 308 | ||
348 | //----------------------------------------------------------------- |
309 | //----------------------------------------------------------------- |
349 | void USB_PutString(u8 *string) |
310 | void USB_PutString(u8 *string) |
350 | { |
311 | { |
351 | u8 i = 0; |
312 | u8 i = 0; |
352 | u16 timeout = 0; |
313 | u16 timeout = 0; |
353 | 314 | ||
354 | while (string[i++] != 0){} // get string len |
315 | while (string[i++] != 0){} // get string len |
355 | while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){ if (timeout++ > 60000) return;} |
316 | while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){ if (timeout++ > 60000) return;} |
356 | UserToPMABufferCopy(string, ENDP1_TXADDR, ++i); // copy string to usb buffer |
317 | UserToPMABufferCopy(string, ENDP1_TXADDR, ++i); // copy string to usb buffer |
357 | SetEPTxCount(ENDP1,i); |
318 | SetEPTxCount(ENDP1,i); |
358 | SetEPTxValid(ENDP1); |
319 | SetEPTxValid(ENDP1); |
359 | } |
320 | } |
360 | 321 | ||
361 | //----------------------------------------------------------------- |
322 | //----------------------------------------------------------------- |
362 | void USB_PutChar(u8 c) |
323 | void USB_PutChar(u8 c) |
363 | { |
324 | { |
364 | u16 timeout = 0; |
325 | u16 timeout = 0; |
365 | while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){ if (timeout++ > 60000) return;} |
326 | while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){ if (timeout++ > 60000) return;} |
366 | UserToPMABufferCopy(&c, ENDP1_TXADDR, 2); |
327 | UserToPMABufferCopy(&c, ENDP1_TXADDR, 2); |
367 | SetEPTxCount(ENDP1,2); |
328 | SetEPTxCount(ENDP1,2); |
368 | SetEPTxValid(ENDP1); |
329 | SetEPTxValid(ENDP1); |
369 | } |
330 | } |
370 | 331 | ||
371 | //----------------------------------------------------------------- |
332 | //----------------------------------------------------------------- |
372 | void USB_SendData(u8 *pdata, u16 count) |
333 | void USB_SendData(u8 *pdata, u16 count) |
373 | { |
334 | { |
374 | u8 i; |
335 | u8 i; |
375 | count++; |
336 | count++; |
376 | u16 timeout = 0; |
337 | u16 timeout = 0; |
377 | 338 | ||
378 | for (i=0;i< (count/64)+1;i++) |
339 | for (i=0;i< (count/64)+1;i++) |
379 | { |
340 | { |
380 | while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){if (timeout++ > 60000) return;} |
341 | while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){if (timeout++ > 60000) return;} |
381 | if (i < (count/64)) |
342 | if (i < (count/64)) |
382 | { |
343 | { |
383 | UserToPMABufferCopy(&pdata[i*64], ENDP1_TXADDR, 64); |
344 | UserToPMABufferCopy(&pdata[i*64], ENDP1_TXADDR, 64); |
384 | SetEPTxCount(ENDP1,64); |
345 | SetEPTxCount(ENDP1,64); |
385 | } |
346 | } |
386 | else |
347 | else |
387 | { |
348 | { |
388 | UserToPMABufferCopy(&pdata[i*64], ENDP1_TXADDR, count % 64); |
349 | UserToPMABufferCopy(&pdata[i*64], ENDP1_TXADDR, count % 64); |
389 | SetEPTxCount(ENDP1, count % 64); |
350 | SetEPTxCount(ENDP1, count % 64); |
390 | } |
351 | } |
391 | SetEPTxValid(ENDP1); |
352 | SetEPTxValid(ENDP1); |
392 | } |
353 | } |
393 | } |
354 | } |
394 | 355 | ||
395 | /**************************************************************/ |
356 | /**************************************************************/ |
396 | /* Transmit tx buffer via usb */ |
357 | /* Transmit tx buffer via usb */ |
397 | /**************************************************************/ |
358 | /**************************************************************/ |
398 | void USB_Transmit(void) |
359 | void USB_Transmit(void) |
399 | { // nur blockweises kopieren des sendebuffers, nicht alles mit einem mal |
360 | { // nur blockweises kopieren des sendebuffers, nicht alles mit einem mal |
400 | // if something has to be send and the txd fifo is not full |
361 | // if something has to be send and the txd fifo is not full |
401 | 362 | ||
402 | if(USB_tx_buffer.Locked == TRUE) |
363 | if(USB_tx_buffer.Locked == TRUE) |
403 | { |
364 | { |
404 | if(_GetEPTxStatus(ENDP1) == EP_TX_NAK) |
365 | if(_GetEPTxStatus(ENDP1) == EP_TX_NAK) |
405 | { |
366 | { |
406 | u16 i; |
367 | u16 i; |
407 | if(USB_tx_buffer.Position < USB_tx_buffer.DataBytes) |
368 | if(USB_tx_buffer.Position < USB_tx_buffer.DataBytes) |
408 | { |
369 | { |
409 | i = USB_tx_buffer.DataBytes - USB_tx_buffer.Position; // bytes to send |
370 | i = USB_tx_buffer.DataBytes - USB_tx_buffer.Position; // bytes to send |
410 | if(i > 64) i = 64; // limit packet size to 64 bytes |
371 | if(i > 64) i = 64; // limit packet size to 64 bytes |
411 | UserToPMABufferCopy(&(USB_tx_buffer.pData[USB_tx_buffer.Position]), ENDP1_TXADDR, i); |
372 | UserToPMABufferCopy(&(USB_tx_buffer.pData[USB_tx_buffer.Position]), ENDP1_TXADDR, i); |
412 | SetEPTxCount(ENDP1,i); |
373 | SetEPTxCount(ENDP1,i); |
413 | SetEPTxValid(ENDP1); |
374 | SetEPTxValid(ENDP1); |
414 | USB_tx_buffer.Position += i; |
375 | USB_tx_buffer.Position += i; |
415 | } |
376 | } |
416 | } |
377 | } |
417 | if(USB_tx_buffer.Position >= USB_tx_buffer.DataBytes) // all bytes transfered |
378 | if(USB_tx_buffer.Position >= USB_tx_buffer.DataBytes) // all bytes transfered |
418 | { |
379 | { |
419 | Buffer_Clear(&USB_tx_buffer); // clear buffer |
380 | Buffer_Clear(&USB_tx_buffer); // clear buffer |
420 | } |
381 | } |
421 | } |
382 | } |
422 | } |
383 | } |
423 | 384 | ||
424 | /**************************************************************/ |
385 | /**************************************************************/ |
425 | /* Send the answers to incomming commands at the debug uart */ |
386 | /* Send the answers to incomming commands at the debug uart */ |
426 | /**************************************************************/ |
387 | /**************************************************************/ |
427 | void USB_TransmitTxData(void) |
388 | void USB_TransmitTxData(void) |
428 | { |
389 | { |
429 | USB_Transmit(); // output pending bytes in tx buffer |
390 | USB_Transmit(); // output pending bytes in tx buffer |
430 | if((USB_tx_buffer.Locked == TRUE)) return; |
391 | if((USB_tx_buffer.Locked == TRUE)) return; |
431 | 392 | ||
432 | if(CheckDelay(USB_AboTimeOut)) |
393 | if(CheckDelay(USB_AboTimeOut)) |
433 | { |
394 | { |
434 | USB_DebugData_Interval = 0; |
395 | USB_DebugData_Interval = 0; |
435 | USB_NaviData_Interval = 0; |
396 | USB_NaviData_Interval = 0; |
436 | USB_Data3D_Interval = 0; |
397 | USB_Data3D_Interval = 0; |
437 | USB_Display_Interval = 0; |
398 | USB_Display_Interval = 0; |
438 | } |
399 | } |
439 | 400 | ||
440 | if((USB_Request_DebugLabel != 0xFF) && (USB_tx_buffer.Locked == FALSE)) |
401 | if((USB_Request_DebugLabel != 0xFF) && (USB_tx_buffer.Locked == FALSE)) |
441 | { |
402 | { |
442 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'A', NC_ADDRESS, 2, &USB_Request_DebugLabel, sizeof(USB_Request_DebugLabel), (u8 *) ANALOG_LABEL[USB_Request_DebugLabel], 16); |
403 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'A', NC_ADDRESS, 2, &USB_Request_DebugLabel, sizeof(USB_Request_DebugLabel), (u8 *) ANALOG_LABEL[USB_Request_DebugLabel], 16); |
443 | USB_Request_DebugLabel = 0xFF; |
404 | USB_Request_DebugLabel = 0xFF; |
444 | } |
405 | } |
445 | else if(USB_ConfirmFrame && (USB_tx_buffer.Locked == FALSE)) |
406 | else if(USB_ConfirmFrame && (USB_tx_buffer.Locked == FALSE)) |
446 | { |
407 | { |
447 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'B', NC_ADDRESS, 1, &USB_ConfirmFrame, sizeof(USB_ConfirmFrame)); |
408 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'B', NC_ADDRESS, 1, &USB_ConfirmFrame, sizeof(USB_ConfirmFrame)); |
448 | USB_ConfirmFrame = 0; |
409 | USB_ConfirmFrame = 0; |
449 | } |
410 | } |
450 | else if( (( (USB_DebugData_Interval > 0) && CheckDelay(USB_DebugData_Timer)) || USB_Request_DebugData) && (USB_tx_buffer.Locked == FALSE)) |
411 | else if( (( (USB_DebugData_Interval > 0) && CheckDelay(USB_DebugData_Timer)) || USB_Request_DebugData) && (USB_tx_buffer.Locked == FALSE)) |
451 | { |
412 | { |
452 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'D', NC_ADDRESS, 1,(u8 *)&DebugOut, sizeof(DebugOut)); |
413 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'D', NC_ADDRESS, 1,(u8 *)&DebugOut, sizeof(DebugOut)); |
453 | USB_DebugData_Timer = SetDelay(USB_DebugData_Interval); |
414 | USB_DebugData_Timer = SetDelay(USB_DebugData_Interval); |
454 | USB_Request_DebugData = FALSE; |
415 | USB_Request_DebugData = FALSE; |
455 | } |
416 | } |
456 | else if((( (USB_Data3D_Interval > 0) && CheckDelay(USB_Data3D_Timer) ) || USB_Request_Data3D) && (USB_tx_buffer.Locked == FALSE)) |
417 | else if((( (USB_Data3D_Interval > 0) && CheckDelay(USB_Data3D_Timer) ) || USB_Request_Data3D) && (USB_tx_buffer.Locked == FALSE)) |
457 | { |
418 | { |
458 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'C', NC_ADDRESS, 1,(u8 *)&Data3D, sizeof(Data3D)); |
419 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'C', NC_ADDRESS, 1,(u8 *)&Data3D, sizeof(Data3D)); |
459 | USB_Data3D_Timer = SetDelay(USB_Data3D_Interval); |
420 | USB_Data3D_Timer = SetDelay(USB_Data3D_Interval); |
460 | USB_Request_Data3D = FALSE; |
421 | USB_Request_Data3D = FALSE; |
461 | } |
422 | } |
462 | else if(USB_Request_ExternalControl && (USB_tx_buffer.Locked == FALSE)) |
423 | else if(USB_Request_ExternalControl && (USB_tx_buffer.Locked == FALSE)) |
463 | { |
424 | { |
464 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'G', NC_ADDRESS, 1, (u8 *)&ExternControl, sizeof(ExternControl)); |
425 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'G', NC_ADDRESS, 1, (u8 *)&ExternControl, sizeof(ExternControl)); |
465 | USB_Request_ExternalControl = FALSE; |
426 | USB_Request_ExternalControl = FALSE; |
466 | } |
427 | } |
467 | else if( (( (USB_Display_Interval > 0) && CheckDelay(USB_Display_Timer)) || USB_Request_Display) && (USB_tx_buffer.Locked == FALSE)) |
428 | else if( (( (USB_Display_Interval > 0) && CheckDelay(USB_Display_Timer)) || USB_Request_Display) && (USB_tx_buffer.Locked == FALSE)) |
468 | { |
429 | { |
469 | Menu_Update(USB_DisplayKeys); |
430 | Menu_Update(USB_DisplayKeys); |
470 | USB_DisplayKeys = 0; |
431 | USB_DisplayKeys = 0; |
471 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'H', NC_ADDRESS, 1, (u8*)DisplayBuff, sizeof(DisplayBuff)); |
432 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'H', NC_ADDRESS, 1, (u8*)DisplayBuff, sizeof(DisplayBuff)); |
472 | USB_Request_Display = FALSE; |
433 | USB_Request_Display = FALSE; |
473 | } |
434 | } |
474 | else if(USB_Request_Display1 && (USB_tx_buffer.Locked == FALSE)) |
435 | else if(USB_Request_Display1 && (USB_tx_buffer.Locked == FALSE)) |
475 | { |
436 | { |
476 | Menu_Update(0); |
437 | Menu_Update(0); |
477 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'L', NC_ADDRESS, 3, (u8*)&MenuItem, sizeof(MenuItem), (u8*)&MaxMenuItem, sizeof(MaxMenuItem),(u8*)DisplayBuff, sizeof(DisplayBuff)); |
438 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'L', NC_ADDRESS, 3, (u8*)&MenuItem, sizeof(MenuItem), (u8*)&MaxMenuItem, sizeof(MaxMenuItem),(u8*)DisplayBuff, sizeof(DisplayBuff)); |
478 | USB_Request_Display1 = FALSE; |
439 | USB_Request_Display1 = FALSE; |
479 | } |
440 | } |
480 | else if(USB_Request_VersionInfo && (USB_tx_buffer.Locked == FALSE)) |
441 | else if(USB_Request_VersionInfo && (USB_tx_buffer.Locked == FALSE)) |
481 | { |
442 | { |
482 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'V', NC_ADDRESS,1, (u8 *)&UART_VersionInfo, sizeof(UART_VersionInfo)); |
443 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'V', NC_ADDRESS,1, (u8 *)&UART_VersionInfo, sizeof(UART_VersionInfo)); |
483 | USB_Request_VersionInfo = FALSE; |
444 | USB_Request_VersionInfo = FALSE; |
484 | } |
445 | } |
485 | else if(( (USB_NaviData_Interval && CheckDelay(USB_NaviData_Timer) ) || USB_Request_NaviData) && (USB_tx_buffer.Locked == FALSE)) |
446 | else if(( (USB_NaviData_Interval && CheckDelay(USB_NaviData_Timer) ) || USB_Request_NaviData) && (USB_tx_buffer.Locked == FALSE)) |
486 | { |
447 | { |
487 | NaviData.Errorcode = ErrorCode; |
448 | NaviData.Errorcode = ErrorCode; |
488 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'O', NC_ADDRESS,1, (u8 *)&NaviData, sizeof(NaviData)); |
449 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'O', NC_ADDRESS,1, (u8 *)&NaviData, sizeof(NaviData)); |
489 | USB_NaviData_Timer = SetDelay(USB_NaviData_Interval); |
450 | USB_NaviData_Timer = SetDelay(USB_NaviData_Interval); |
490 | USB_Request_NaviData = FALSE; |
451 | USB_Request_NaviData = FALSE; |
491 | } |
452 | } |
492 | else if(USB_Request_ErrorMessage && (USB_tx_buffer.Locked == FALSE)) |
453 | else if(USB_Request_ErrorMessage && (USB_tx_buffer.Locked == FALSE)) |
493 | { |
454 | { |
494 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'E', NC_ADDRESS, 1, (u8 *)&ErrorMSG, sizeof(ErrorMSG)); |
455 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'E', NC_ADDRESS, 1, (u8 *)&ErrorMSG, sizeof(ErrorMSG)); |
495 | USB_Request_ErrorMessage = FALSE; |
456 | USB_Request_ErrorMessage = FALSE; |
496 | } |
457 | } |
497 | else if(USB_Request_NewWaypoint && (USB_tx_buffer.Locked == FALSE)) |
- | |
498 | { |
- | |
499 | u8 WPNumber = WPList_GetCount(); |
- | |
500 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'W', NC_ADDRESS, 1, &WPNumber, sizeof(WPNumber)); |
- | |
501 | USB_Request_NewWaypoint = FALSE; |
- | |
502 | } |
- | |
503 | else if((USB_Request_ReadWaypoint != 0xFF) && (USB_tx_buffer.Locked == FALSE)) |
- | |
504 | { |
- | |
505 | u8 WPNumber = WPList_GetCount(); |
- | |
506 | if (USB_Request_ReadWaypoint < WPNumber) |
- | |
507 | { |
- | |
508 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'X', NC_ADDRESS, 3, &WPNumber, 1, &USB_Request_ReadWaypoint, 1, WPList_GetAt(USB_Request_ReadWaypoint), sizeof(Waypoint_t)); |
- | |
509 | } |
- | |
510 | else |
- | |
511 | { |
- | |
512 | MKProtocol_CreateSerialFrame(&USB_tx_buffer,'X', NC_ADDRESS, 1, &WPNumber, sizeof(WPNumber)); |
- | |
513 | } |
- | |
514 | USB_Request_ReadWaypoint = 0xFF; |
- | |
515 | } |
- | |
516 | USB_Transmit(); // output pending bytes in tx buffer |
458 | USB_Transmit(); // output pending bytes in tx buffer |
517 | } |
459 | } |
518 | 460 |