Subversion Repositories NaviCtrl

Rev

Rev 378 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 ingob 1
/*#######################################################################################*/
2
/* !!! THIS IS NOT FREE SOFTWARE !!!                                                     */
3
/*#######################################################################################*/
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5
// + www.MikroKopter.com
6
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
360 holgerb 7
// + Software Nutzungsbedingungen (english version: see below)
8
// + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt -
9
// + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den
10
// + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool 
11
// + - nachfolgend Software genannt - nur für private Zwecke zu nutzen.
12
// + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig.
1 ingob 13
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
360 holgerb 14
// + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im
15
// + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu.
16
// + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie
17
// + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden.
18
// + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren
19
// + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
20
// + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren
21
// + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand 
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.
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
// + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt.
28
// + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software.
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.
1 ingob 31
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
360 holgerb 32
// + Software LICENSING TERMS
1 ingob 33
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
360 holgerb 34
// + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor -
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 
36
// + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*.
37
// + The Software may only be used with the Licensor's products.
38
// + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this
39
// + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this
40
// + agreement shall be the property of the Licensor.
41
// + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other
42
// + features that can be used to identify the program may not be altered or defaced by the customer.
43
// + The customer shall be responsible for taking reasonable precautions
44
// + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the
45
// + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and
46
// + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product
47
// + liability. However, the Licensor shall be entitled to the defense of contributory negligence.
48
// + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test
49
// + the software for his purpose before any operational usage. The customer will backup his data before using the software.
50
// + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data
51
// + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations.
52
// + *) The territory aspect only refers to the place where the Software is used, not its programmed range.
53
// + #### END OF LICENSING TERMS ####
54
// + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de.
1 ingob 55
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
275 killagreg 56
#include <stdio.h>
112 killagreg 57
#include <string.h>
41 ingob 58
#include "91x_lib.h"
136 killagreg 59
#include "config.h"
112 killagreg 60
#include "main.h"
41 ingob 61
#include "uart1.h"
111 killagreg 62
#include "mkprotocol.h"
112 killagreg 63
#include "waypoints.h"
64
#include "gps.h"
119 killagreg 65
#include "timer1.h"
112 killagreg 66
#include "uart0.h"
67
#include "uart1.h"
68
#include "uart2.h"
69
#include "menu.h"
275 killagreg 70
#include "usb.h"
111 killagreg 71
 
201 killagreg 72
#define ABO_TIMEOUT 4000 // disable abo after 4 seconds
73
u32 USB_AboTimeOut = 0;
111 killagreg 74
 
275 killagreg 75
u16 Echo; // 2 bytes recieved will be sent back as echo
76
 
77
// the primary rx fifo
78
#define USB_RX_FIFO_LEN 512
79
u8 USB_rxfifobuffer[USB_RX_FIFO_LEN];
80
fifo_t USB_rx_fifo;
81
 
111 killagreg 82
// the tx buffer
83
#define USB_TX_BUFFER_LEN  150
84
u8 USB_tbuffer[USB_TX_BUFFER_LEN];
85
Buffer_t USB_tx_buffer;
86
 
87
// the rx buffer
88
#define USB_RX_BUFFER_LEN  150
89
u8 USB_rbuffer[USB_RX_BUFFER_LEN];
90
Buffer_t USB_rx_buffer;
91
 
112 killagreg 92
u8 USB_Request_VersionInfo      = FALSE;
93
u8 USB_Request_SendFollowMe     = FALSE;
94
u8 USB_Request_ExternalControl= FALSE;
95
u8 USB_Request_Display          = FALSE;
96
u8 USB_Request_Display1         = FALSE;
97
u8 USB_Request_DebugData        = FALSE;
98
u8 USB_Request_DebugLabel       = 255;
99
u8 USB_Request_NaviData         = FALSE;
100
u8 USB_Request_ErrorMessage     = FALSE;
101
u8 USB_Request_Data3D           = FALSE;
102
u8 USB_Request_Echo                 = FALSE;
201 killagreg 103
u8 USB_DisplayKeys = 0;
275 killagreg 104
u8 USB_DisplayLine                      = 0;
112 killagreg 105
u8 USB_ConfirmFrame = 0;
106
 
107
u32 USB_DebugData_Timer = 0;
108
u32 USB_DebugData_Interval = 0; // in ms
109
u32 USB_NaviData_Timer = 0;
110
u32 USB_NaviData_Interval = 0;  // in ms
275 killagreg 111
u32 USB_Data3D_Timer = 0;
201 killagreg 112
u32 USB_Data3D_Interval = 0;    // in ms
113
u32 USB_Display_Timer = 0;
114
u32 USB_Display_Interval = 0;   // in ms
112 killagreg 115
 
1 ingob 116
//-----------------------------------------------------------------
117
void USB_ConfigInit(void)
118
{
41 ingob 119
        GPIO_InitTypeDef GPIO_InitStructure;
275 killagreg 120
 
110 killagreg 121
        UART1_PutString("\r\n USB init...");
41 ingob 122
        #ifdef MCLK96MHZ
123
        //USB clock = MCLK/2 = 48MHz
124
        SCU_USBCLKConfig(SCU_USBCLK_MCLK2);
125
        #else
126
        //USB clock = MCLK = 48MHz
127
        SCU_USBCLKConfig(SCU_USBCLK_MCLK);
128
        #endif
129
        //Enable USB clock
130
        SCU_AHBPeriphClockConfig(__USB,ENABLE);
131
        SCU_AHBPeriphReset(__USB,DISABLE);
132
        SCU_AHBPeriphClockConfig(__USB48M,ENABLE);
1 ingob 133
 
41 ingob 134
        //Configure GPIO0 (D+ Pull-Up on P0.1)
135
        SCU_APBPeriphClockConfig(__GPIO0 ,ENABLE);
136
        SCU_APBPeriphReset(__GPIO0,DISABLE);
1 ingob 137
 
41 ingob 138
        // GPIO_DeInit(P0.1);
139
        GPIO_StructInit(&GPIO_InitStructure);
140
        GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;
141
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
142
        GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
196 killagreg 143
        GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable;
41 ingob 144
        GPIO_InitStructure.GPIO_Alternate=GPIO_OutputAlt1;
145
        GPIO_Init (GPIO0, &GPIO_InitStructure);
1 ingob 146
 
275 killagreg 147
        // initialize the rx fifo, block UART IRQ geting a byte from fifo
148
        fifo_init(&USB_rx_fifo, USB_rxfifobuffer, USB_RX_FIFO_LEN, NO_ITLine, USBLP_ITLine);
149
 
112 killagreg 150
        // initialize txd buffer
151
        Buffer_Init(&USB_tx_buffer, USB_tbuffer, USB_TX_BUFFER_LEN);
275 killagreg 152
 
111 killagreg 153
        // initialize rxd buffer
112 killagreg 154
        Buffer_Init(&USB_rx_buffer, USB_rbuffer, USB_RX_BUFFER_LEN);
111 killagreg 155
 
136 killagreg 156
        VIC_Config(USBLP_ITLine, VIC_IRQ, PRIORITY_USB);
378 holgerb 157
//##    VIC_ITCmd(USBLP_ITLine, ENABLE);
275 killagreg 158
 
41 ingob 159
        USB_Init();
275 killagreg 160
 
161
        UART1_PutString("ok");
1 ingob 162
}
163
 
112 killagreg 164
 
165
/**************************************************************/
166
/* Process incomming data from debug uart                     */
167
/**************************************************************/
168
void USB_ProcessRxData(void)
169
{
275 killagreg 170
        u8 c;
112 killagreg 171
        SerialMsg_t SerialMsg;
280 killagreg 172
 
112 killagreg 173
        // if data in the rxd buffer are not locked immediately return
275 killagreg 174
        // if rx buffer is not locked
175
        if(USB_rx_buffer.Locked == FALSE)
176
        {
177
                //collect data from primary rx fifo
178
                while(fifo_get(&USB_rx_fifo, &c))
179
                {
180
                        // break if complete frame has been collected
181
                        if(MKProtocol_CollectSerialFrame(&USB_rx_buffer, c)) break;
182
                }
183
        }
184
        if(USB_rx_buffer.Locked == FALSE) return;
112 killagreg 185
 
190 killagreg 186
        MKProtocol_DecodeSerialFrameHeader(&USB_rx_buffer, &SerialMsg); // decode serial frame in rxd buffer
187
        MKProtocol_DecodeSerialFrameData(&USB_rx_buffer, &SerialMsg); // decode serial frame in rxd buffer
114 killagreg 188
 
190 killagreg 189
    if(SerialMsg.CmdID != 'z') SerialLinkOkay = 250;      // reset SerialTimeout, but not in case of the "ping"
190
        switch(SerialMsg.Address) // check for Slave Address
112 killagreg 191
        {
192
                case NC_ADDRESS:  // own Slave Address
190 killagreg 193
                switch(SerialMsg.CmdID)
112 killagreg 194
                {
275 killagreg 195
                        case 'z': // connection checker
196
                                memcpy(&Echo, SerialMsg.pData, sizeof(Echo)); // copy echo pattern
197
                                USB_Request_Echo = TRUE;
198
                                break;
199
 
112 killagreg 200
                        case 'e': // request for the text of the error status
201
                                USB_Request_ErrorMessage = TRUE;
202
                                break;
203
 
204
                        default:
205
                                // unsupported command recieved
206
                                break;
207
                } // case NC_ADDRESS
208
                // "break;" is missing here to fall thru to the common commands
209
 
210
                default:  // and any other Slave Address
211
 
190 killagreg 212
                switch(SerialMsg.CmdID) // check CmdID
112 killagreg 213
                {
214
                        case 'a':// request for the labels of the analog debug outputs
215
                                USB_Request_DebugLabel = SerialMsg.pData[0];
216
                                if(USB_Request_DebugLabel > 31) USB_Request_DebugLabel = 31;
217
                                break;
201 killagreg 218
                        /*
112 killagreg 219
                        case 'b': // submit extern control
220
                                memcpy(&ExternControl, SerialMsg.pData, sizeof(ExternControl));
221
                                USB_ConfirmFrame = ExternControl.Frame;
222
                                break;
201 killagreg 223
                        */
112 killagreg 224
                        case 'd': // request for debug data;
225
                                USB_DebugData_Interval = (u32) SerialMsg.pData[0] * 10;
275 killagreg 226
                                if(USB_DebugData_Interval > 0) USB_Request_DebugData = TRUE;
201 killagreg 227
                                USB_AboTimeOut = SetDelay(ABO_TIMEOUT);
112 killagreg 228
                                break;
229
 
230
                        case 'c': // request for 3D data;
231
                                USB_Data3D_Interval = (u32) SerialMsg.pData[0] * 10;
275 killagreg 232
                                if(USB_Data3D_Interval > 0) USB_Request_Data3D = TRUE;
201 killagreg 233
                                USB_AboTimeOut = SetDelay(ABO_TIMEOUT);
112 killagreg 234
                                break;
275 killagreg 235
 
112 killagreg 236
                        case 'h':// reqest for display line
275 killagreg 237
                                if((SerialMsg.pData[0]& 0x80) == 0x00)// old format
238
                                {
239
                                        USB_DisplayLine = 2;
240
                                        USB_Display_Interval = 0;
241
                                }
242
                                else
243
                                {
244
                                        USB_DisplayKeys |= ~SerialMsg.pData[0];
245
                                        USB_Display_Interval = (u32) SerialMsg.pData[1] * 10;
246
                                        USB_DisplayLine = 4;
247
                                        USB_AboTimeOut = SetDelay(ABO_TIMEOUT);
248
                                }
112 killagreg 249
                                USB_Request_Display = TRUE;
250
                                break;
251
 
252
                        case 'l':// reqest for display columns
253
                                MenuItem = SerialMsg.pData[0];
254
                                USB_Request_Display1 = TRUE;
255
                                break;
256
 
257
                        case 'o': // request for navigation information
258
                                USB_NaviData_Interval = (u32) SerialMsg.pData[0] * 10;
275 killagreg 259
                                if(USB_NaviData_Interval > 0) USB_Request_NaviData = TRUE;
201 killagreg 260
                                USB_AboTimeOut = SetDelay(ABO_TIMEOUT);
112 killagreg 261
                                break;
262
 
263
                        case 'v': // request for version info
264
                                USB_Request_VersionInfo = TRUE;
265
                                break;
266
                        default:
267
                                // unsupported command recieved
268
                                break;
269
                }
270
                break; // default:
271
        }
272
        Buffer_Clear(&USB_rx_buffer);
273
}
274
 
275
 
1 ingob 276
//-----------------------------------------------------------------
111 killagreg 277
void USB_CableConfig(FunctionalState NewState)
1 ingob 278
{
41 ingob 279
        if (NewState == ENABLE)
280
        GPIO_WriteBit(GPIO0, GPIO_Pin_1, Bit_RESET);
281
        else
282
        GPIO_WriteBit(GPIO0, GPIO_Pin_1, Bit_SET);
1 ingob 283
}
275 killagreg 284
//-----------------------------------------------------------------
285
void USB_EnterLowPowerMode(void)
286
{
287
  /* Set the device state to suspend */
288
  bDeviceState = SUSPENDED;
289
}
290
//-----------------------------------------------------------------
291
void USB_LeaveLowPowerMode(void)
292
{
293
  DEVICE_INFO *pInfo = &Device_Info;
1 ingob 294
 
275 killagreg 295
  /* Set the device state to the correct state */
296
  if (pInfo->Current_Configuration != 0)
297
  {
298
    /* Device configured */
299
    bDeviceState = CONFIGURED;
300
  }
301
  else
302
  {
303
    bDeviceState = ATTACHED;
304
  }
305
}
306
 
307
 
1 ingob 308
//-----------------------------------------------------------------
111 killagreg 309
void USB_PutString(u8 *string)
1 ingob 310
{
41 ingob 311
        u8 i = 0;
312
        u16 timeout = 0;
275 killagreg 313
 
111 killagreg 314
        while (string[i++] != 0){} // get string len
41 ingob 315
        while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){ if (timeout++ > 60000) return;}
111 killagreg 316
        UserToPMABufferCopy(string, ENDP1_TXADDR, ++i); // copy string to usb buffer
41 ingob 317
        SetEPTxCount(ENDP1,i);
318
        SetEPTxValid(ENDP1);
275 killagreg 319
}
1 ingob 320
 
321
//-----------------------------------------------------------------
111 killagreg 322
void USB_PutChar(u8 c)
1 ingob 323
{
41 ingob 324
        u16 timeout = 0;
325
        while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){ if (timeout++ > 60000) return;}
111 killagreg 326
        UserToPMABufferCopy(&c, ENDP1_TXADDR, 2);
41 ingob 327
        SetEPTxCount(ENDP1,2);
328
        SetEPTxValid(ENDP1);
329
}
275 killagreg 330
 
1 ingob 331
//-----------------------------------------------------------------
111 killagreg 332
void USB_SendData(u8 *pdata, u16 count)
1 ingob 333
{
41 ingob 334
        u8 i;
335
        count++;
114 killagreg 336
        u16 timeout = 0;
275 killagreg 337
 
338
        for (i=0;i< (count/64)+1;i++)
41 ingob 339
        {
275 killagreg 340
                while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){if (timeout++ > 60000) return;}
341
                if (i < (count/64))
342
                {
111 killagreg 343
                        UserToPMABufferCopy(&pdata[i*64], ENDP1_TXADDR, 64);
41 ingob 344
                        SetEPTxCount(ENDP1,64);
345
                }
275 killagreg 346
                else
347
                {
111 killagreg 348
                        UserToPMABufferCopy(&pdata[i*64], ENDP1_TXADDR, count % 64);
41 ingob 349
                        SetEPTxCount(ENDP1, count % 64);
350
                }
351
                SetEPTxValid(ENDP1);
1 ingob 352
        }
275 killagreg 353
}
1 ingob 354
 
112 killagreg 355
/**************************************************************/
356
/*         Transmit tx buffer via usb                         */
357
/**************************************************************/
358
void USB_Transmit(void)
359
{   // nur blockweises kopieren des sendebuffers, nicht alles mit einem mal
360
        // if something has to be send and the txd fifo is not full
275 killagreg 361
 
112 killagreg 362
        if(USB_tx_buffer.Locked == TRUE)
363
        {
114 killagreg 364
                if(_GetEPTxStatus(ENDP1) == EP_TX_NAK)
112 killagreg 365
                {
275 killagreg 366
                        u16 i;
112 killagreg 367
                        if(USB_tx_buffer.Position < USB_tx_buffer.DataBytes)
368
                        {
114 killagreg 369
                                i = USB_tx_buffer.DataBytes - USB_tx_buffer.Position; // bytes to send
112 killagreg 370
                                if(i > 64) i = 64; // limit packet size to 64 bytes
371
                                UserToPMABufferCopy(&(USB_tx_buffer.pData[USB_tx_buffer.Position]), ENDP1_TXADDR, i);
114 killagreg 372
                                SetEPTxCount(ENDP1,i);
275 killagreg 373
                                SetEPTxValid(ENDP1);
112 killagreg 374
                        USB_tx_buffer.Position += i;
375
                        }
376
                }
377
                if(USB_tx_buffer.Position >= USB_tx_buffer.DataBytes) // all bytes transfered
378
                {
379
                        Buffer_Clear(&USB_tx_buffer); // clear buffer
380
                }
381
        }
382
}
383
 
384
/**************************************************************/
385
/* Send the answers to incomming commands at the debug uart   */
386
/**************************************************************/
387
void USB_TransmitTxData(void)
388
{
389
        USB_Transmit(); // output pending bytes in tx buffer
390
        if((USB_tx_buffer.Locked == TRUE)) return;
391
 
201 killagreg 392
        if(CheckDelay(USB_AboTimeOut))
393
        {
394
                USB_DebugData_Interval = 0;
395
                USB_NaviData_Interval = 0;
396
                USB_Data3D_Interval = 0;
397
                USB_Display_Interval = 0;
398
        }
399
 
112 killagreg 400
        if((USB_Request_DebugLabel != 0xFF) && (USB_tx_buffer.Locked == FALSE))
401
        {
402
                MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'A', NC_ADDRESS, 2, &USB_Request_DebugLabel, sizeof(USB_Request_DebugLabel), (u8 *) ANALOG_LABEL[USB_Request_DebugLabel], 16);
403
                USB_Request_DebugLabel = 0xFF;
404
        }
201 killagreg 405
        else if(USB_ConfirmFrame && (USB_tx_buffer.Locked == FALSE))
112 killagreg 406
        {
407
                MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'B', NC_ADDRESS, 1, &USB_ConfirmFrame, sizeof(USB_ConfirmFrame));
408
                USB_ConfirmFrame = 0;
409
        }
201 killagreg 410
        else if( (( (USB_DebugData_Interval > 0) && CheckDelay(USB_DebugData_Timer)) || USB_Request_DebugData) && (USB_tx_buffer.Locked == FALSE))
112 killagreg 411
        {
412
                MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'D', NC_ADDRESS, 1,(u8 *)&DebugOut, sizeof(DebugOut));
413
                USB_DebugData_Timer = SetDelay(USB_DebugData_Interval);
414
                USB_Request_DebugData = FALSE;
415
        }
201 killagreg 416
        else if((( (USB_Data3D_Interval > 0) && CheckDelay(USB_Data3D_Timer) ) || USB_Request_Data3D) && (USB_tx_buffer.Locked == FALSE))
112 killagreg 417
        {
418
                MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'C', NC_ADDRESS, 1,(u8 *)&Data3D, sizeof(Data3D));
419
                USB_Data3D_Timer = SetDelay(USB_Data3D_Interval);
420
                USB_Request_Data3D = FALSE;
421
        }
201 killagreg 422
        else if(USB_Request_ExternalControl && (USB_tx_buffer.Locked == FALSE))
112 killagreg 423
        {
424
                MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'G', NC_ADDRESS, 1, (u8 *)&ExternControl, sizeof(ExternControl));
425
                USB_Request_ExternalControl = FALSE;
426
        }
201 killagreg 427
        else if( (( (USB_Display_Interval > 0) && CheckDelay(USB_Display_Timer)) || USB_Request_Display) && (USB_tx_buffer.Locked == FALSE))
112 killagreg 428
        {
201 killagreg 429
                Menu_Update(USB_DisplayKeys);
430
                USB_DisplayKeys = 0;
431
                MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'H', NC_ADDRESS, 1, (u8*)DisplayBuff, sizeof(DisplayBuff));
112 killagreg 432
                USB_Request_Display = FALSE;
433
        }
201 killagreg 434
        else if(USB_Request_Display1 && (USB_tx_buffer.Locked == FALSE))
112 killagreg 435
        {
201 killagreg 436
                Menu_Update(0);
112 killagreg 437
                MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'L', NC_ADDRESS, 3, (u8*)&MenuItem, sizeof(MenuItem), (u8*)&MaxMenuItem, sizeof(MaxMenuItem),(u8*)DisplayBuff, sizeof(DisplayBuff));
438
                USB_Request_Display1 = FALSE;
439
        }
201 killagreg 440
        else if(USB_Request_VersionInfo && (USB_tx_buffer.Locked == FALSE))
112 killagreg 441
        {
442
                MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'V', NC_ADDRESS,1, (u8 *)&UART_VersionInfo, sizeof(UART_VersionInfo));
443
                USB_Request_VersionInfo = FALSE;
444
        }
201 killagreg 445
        else if(( (USB_NaviData_Interval && CheckDelay(USB_NaviData_Timer) ) || USB_Request_NaviData) && (USB_tx_buffer.Locked == FALSE))
112 killagreg 446
        {
447
                NaviData.Errorcode = ErrorCode;
448
                MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'O', NC_ADDRESS,1, (u8 *)&NaviData, sizeof(NaviData));
449
                USB_NaviData_Timer = SetDelay(USB_NaviData_Interval);
450
                USB_Request_NaviData = FALSE;
451
        }
201 killagreg 452
        else if(USB_Request_ErrorMessage && (USB_tx_buffer.Locked == FALSE))
112 killagreg 453
        {
454
                MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'E', NC_ADDRESS, 1, (u8 *)&ErrorMSG, sizeof(ErrorMSG));
455
                USB_Request_ErrorMessage = FALSE;
456
        }
457
        USB_Transmit(); // output pending bytes in tx buffer
458
}