Rev 360 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 360 | Rev 378 | ||
---|---|---|---|
1 | /*#######################################################################################*/ |
1 | /*#######################################################################################*/ |
2 | /* !!! THIS IS NOT FREE SOFTWARE !!! */ |
2 | /* !!! THIS IS NOT FREE SOFTWARE !!! */ |
3 | /*#######################################################################################*/ |
3 | /*#######################################################################################*/ |
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
5 | // + www.MikroKopter.com |
5 | // + www.MikroKopter.com |
6 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
6 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
7 | // + Software Nutzungsbedingungen (english version: see below) |
7 | // + Software Nutzungsbedingungen (english version: see below) |
8 | // + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt - |
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 |
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 |
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. |
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. |
12 | // + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig. |
13 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
13 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
14 | // + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im |
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. |
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 |
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. |
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 |
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. |
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 |
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 |
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. |
22 | // + des Mitverschuldens offen. |
23 | // + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet. |
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. |
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. |
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 |
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. |
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. |
28 | // + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software. |
29 | // + #### ENDE DER NUTZUNGSBEDINGUNGEN ####' |
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 | // + 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. |
31 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
31 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
32 | // + Software LICENSING TERMS |
32 | // + Software LICENSING TERMS |
33 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
33 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
34 | // + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor - |
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 |
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*. |
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. |
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 |
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 |
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. |
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 |
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. |
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 |
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 |
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 |
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 |
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. |
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 |
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. |
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 |
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. |
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. |
52 | // + *) The territory aspect only refers to the place where the Software is used, not its programmed range. |
53 | // + #### END OF LICENSING TERMS #### |
53 | // + #### END OF LICENSING TERMS #### |
54 | // + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de. |
54 | // + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de. |
55 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
55 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
56 | #include <stdio.h> |
56 | #include <stdio.h> |
57 | #include <string.h> |
57 | #include <string.h> |
58 | #include "91x_lib.h" |
58 | #include "91x_lib.h" |
59 | #include "config.h" |
59 | #include "config.h" |
60 | #include "main.h" |
60 | #include "main.h" |
61 | #include "uart1.h" |
61 | #include "uart1.h" |
62 | #include "mkprotocol.h" |
62 | #include "mkprotocol.h" |
63 | #include "waypoints.h" |
63 | #include "waypoints.h" |
64 | #include "gps.h" |
64 | #include "gps.h" |
65 | #include "timer1.h" |
65 | #include "timer1.h" |
66 | #include "uart0.h" |
66 | #include "uart0.h" |
67 | #include "uart1.h" |
67 | #include "uart1.h" |
68 | #include "uart2.h" |
68 | #include "uart2.h" |
69 | #include "menu.h" |
69 | #include "menu.h" |
70 | #include "usb.h" |
70 | #include "usb.h" |
71 | 71 | ||
72 | #define ABO_TIMEOUT 4000 // disable abo after 4 seconds |
72 | #define ABO_TIMEOUT 4000 // disable abo after 4 seconds |
73 | u32 USB_AboTimeOut = 0; |
73 | u32 USB_AboTimeOut = 0; |
74 | 74 | ||
75 | u16 Echo; // 2 bytes recieved will be sent back as echo |
75 | u16 Echo; // 2 bytes recieved will be sent back as echo |
76 | 76 | ||
77 | // the primary rx fifo |
77 | // the primary rx fifo |
78 | #define USB_RX_FIFO_LEN 512 |
78 | #define USB_RX_FIFO_LEN 512 |
79 | u8 USB_rxfifobuffer[USB_RX_FIFO_LEN]; |
79 | u8 USB_rxfifobuffer[USB_RX_FIFO_LEN]; |
80 | fifo_t USB_rx_fifo; |
80 | fifo_t USB_rx_fifo; |
81 | 81 | ||
82 | // the tx buffer |
82 | // the tx buffer |
83 | #define USB_TX_BUFFER_LEN 150 |
83 | #define USB_TX_BUFFER_LEN 150 |
84 | u8 USB_tbuffer[USB_TX_BUFFER_LEN]; |
84 | u8 USB_tbuffer[USB_TX_BUFFER_LEN]; |
85 | Buffer_t USB_tx_buffer; |
85 | Buffer_t USB_tx_buffer; |
86 | 86 | ||
87 | // the rx buffer |
87 | // the rx buffer |
88 | #define USB_RX_BUFFER_LEN 150 |
88 | #define USB_RX_BUFFER_LEN 150 |
89 | u8 USB_rbuffer[USB_RX_BUFFER_LEN]; |
89 | u8 USB_rbuffer[USB_RX_BUFFER_LEN]; |
90 | Buffer_t USB_rx_buffer; |
90 | Buffer_t USB_rx_buffer; |
91 | 91 | ||
92 | u8 USB_Request_VersionInfo = FALSE; |
92 | u8 USB_Request_VersionInfo = FALSE; |
93 | u8 USB_Request_SendFollowMe = FALSE; |
93 | u8 USB_Request_SendFollowMe = FALSE; |
94 | u8 USB_Request_ExternalControl= FALSE; |
94 | u8 USB_Request_ExternalControl= FALSE; |
95 | u8 USB_Request_Display = FALSE; |
95 | u8 USB_Request_Display = FALSE; |
96 | u8 USB_Request_Display1 = FALSE; |
96 | u8 USB_Request_Display1 = FALSE; |
97 | u8 USB_Request_DebugData = FALSE; |
97 | u8 USB_Request_DebugData = FALSE; |
98 | u8 USB_Request_DebugLabel = 255; |
98 | u8 USB_Request_DebugLabel = 255; |
99 | u8 USB_Request_NaviData = FALSE; |
99 | u8 USB_Request_NaviData = FALSE; |
100 | u8 USB_Request_ErrorMessage = FALSE; |
100 | u8 USB_Request_ErrorMessage = FALSE; |
101 | u8 USB_Request_Data3D = FALSE; |
101 | u8 USB_Request_Data3D = FALSE; |
102 | u8 USB_Request_Echo = FALSE; |
102 | u8 USB_Request_Echo = FALSE; |
103 | u8 USB_DisplayKeys = 0; |
103 | u8 USB_DisplayKeys = 0; |
104 | u8 USB_DisplayLine = 0; |
104 | u8 USB_DisplayLine = 0; |
105 | u8 USB_ConfirmFrame = 0; |
105 | u8 USB_ConfirmFrame = 0; |
106 | 106 | ||
107 | u32 USB_DebugData_Timer = 0; |
107 | u32 USB_DebugData_Timer = 0; |
108 | u32 USB_DebugData_Interval = 0; // in ms |
108 | u32 USB_DebugData_Interval = 0; // in ms |
109 | u32 USB_NaviData_Timer = 0; |
109 | u32 USB_NaviData_Timer = 0; |
110 | u32 USB_NaviData_Interval = 0; // in ms |
110 | u32 USB_NaviData_Interval = 0; // in ms |
111 | u32 USB_Data3D_Timer = 0; |
111 | u32 USB_Data3D_Timer = 0; |
112 | u32 USB_Data3D_Interval = 0; // in ms |
112 | u32 USB_Data3D_Interval = 0; // in ms |
113 | u32 USB_Display_Timer = 0; |
113 | u32 USB_Display_Timer = 0; |
114 | u32 USB_Display_Interval = 0; // in ms |
114 | u32 USB_Display_Interval = 0; // in ms |
115 | 115 | ||
116 | //----------------------------------------------------------------- |
116 | //----------------------------------------------------------------- |
117 | void USB_ConfigInit(void) |
117 | void USB_ConfigInit(void) |
118 | { |
118 | { |
119 | GPIO_InitTypeDef GPIO_InitStructure; |
119 | GPIO_InitTypeDef GPIO_InitStructure; |
120 | 120 | ||
121 | UART1_PutString("\r\n USB init..."); |
121 | UART1_PutString("\r\n USB init..."); |
122 | #ifdef MCLK96MHZ |
122 | #ifdef MCLK96MHZ |
123 | //USB clock = MCLK/2 = 48MHz |
123 | //USB clock = MCLK/2 = 48MHz |
124 | SCU_USBCLKConfig(SCU_USBCLK_MCLK2); |
124 | SCU_USBCLKConfig(SCU_USBCLK_MCLK2); |
125 | #else |
125 | #else |
126 | //USB clock = MCLK = 48MHz |
126 | //USB clock = MCLK = 48MHz |
127 | SCU_USBCLKConfig(SCU_USBCLK_MCLK); |
127 | SCU_USBCLKConfig(SCU_USBCLK_MCLK); |
128 | #endif |
128 | #endif |
129 | //Enable USB clock |
129 | //Enable USB clock |
130 | SCU_AHBPeriphClockConfig(__USB,ENABLE); |
130 | SCU_AHBPeriphClockConfig(__USB,ENABLE); |
131 | SCU_AHBPeriphReset(__USB,DISABLE); |
131 | SCU_AHBPeriphReset(__USB,DISABLE); |
132 | SCU_AHBPeriphClockConfig(__USB48M,ENABLE); |
132 | SCU_AHBPeriphClockConfig(__USB48M,ENABLE); |
133 | 133 | ||
134 | //Configure GPIO0 (D+ Pull-Up on P0.1) |
134 | //Configure GPIO0 (D+ Pull-Up on P0.1) |
135 | SCU_APBPeriphClockConfig(__GPIO0 ,ENABLE); |
135 | SCU_APBPeriphClockConfig(__GPIO0 ,ENABLE); |
136 | SCU_APBPeriphReset(__GPIO0,DISABLE); |
136 | SCU_APBPeriphReset(__GPIO0,DISABLE); |
137 | 137 | ||
138 | // GPIO_DeInit(P0.1); |
138 | // GPIO_DeInit(P0.1); |
139 | GPIO_StructInit(&GPIO_InitStructure); |
139 | GPIO_StructInit(&GPIO_InitStructure); |
140 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
140 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
141 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; |
141 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; |
142 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
142 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
143 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable; |
143 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable; |
144 | GPIO_InitStructure.GPIO_Alternate=GPIO_OutputAlt1; |
144 | GPIO_InitStructure.GPIO_Alternate=GPIO_OutputAlt1; |
145 | GPIO_Init (GPIO0, &GPIO_InitStructure); |
145 | GPIO_Init (GPIO0, &GPIO_InitStructure); |
146 | 146 | ||
147 | // 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 |
148 | 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); |
149 | 149 | ||
150 | // initialize txd buffer |
150 | // initialize txd buffer |
151 | Buffer_Init(&USB_tx_buffer, USB_tbuffer, USB_TX_BUFFER_LEN); |
151 | Buffer_Init(&USB_tx_buffer, USB_tbuffer, USB_TX_BUFFER_LEN); |
152 | 152 | ||
153 | // initialize rxd buffer |
153 | // initialize rxd buffer |
154 | Buffer_Init(&USB_rx_buffer, USB_rbuffer, USB_RX_BUFFER_LEN); |
154 | Buffer_Init(&USB_rx_buffer, USB_rbuffer, USB_RX_BUFFER_LEN); |
155 | 155 | ||
156 | VIC_Config(USBLP_ITLine, VIC_IRQ, PRIORITY_USB); |
156 | VIC_Config(USBLP_ITLine, VIC_IRQ, PRIORITY_USB); |
157 | VIC_ITCmd(USBLP_ITLine, ENABLE); |
157 | //## VIC_ITCmd(USBLP_ITLine, ENABLE); |
158 | 158 | ||
159 | USB_Init(); |
159 | USB_Init(); |
160 | 160 | ||
161 | UART1_PutString("ok"); |
161 | UART1_PutString("ok"); |
162 | } |
162 | } |
163 | 163 | ||
164 | 164 | ||
165 | /**************************************************************/ |
165 | /**************************************************************/ |
166 | /* Process incomming data from debug uart */ |
166 | /* Process incomming data from debug uart */ |
167 | /**************************************************************/ |
167 | /**************************************************************/ |
168 | void USB_ProcessRxData(void) |
168 | void USB_ProcessRxData(void) |
169 | { |
169 | { |
170 | u8 c; |
170 | u8 c; |
171 | SerialMsg_t SerialMsg; |
171 | SerialMsg_t SerialMsg; |
172 | 172 | ||
173 | // if data in the rxd buffer are not locked immediately return |
173 | // if data in the rxd buffer are not locked immediately return |
174 | // if rx buffer is not locked |
174 | // if rx buffer is not locked |
175 | if(USB_rx_buffer.Locked == FALSE) |
175 | if(USB_rx_buffer.Locked == FALSE) |
176 | { |
176 | { |
177 | //collect data from primary rx fifo |
177 | //collect data from primary rx fifo |
178 | while(fifo_get(&USB_rx_fifo, &c)) |
178 | while(fifo_get(&USB_rx_fifo, &c)) |
179 | { |
179 | { |
180 | // break if complete frame has been collected |
180 | // break if complete frame has been collected |
181 | if(MKProtocol_CollectSerialFrame(&USB_rx_buffer, c)) break; |
181 | if(MKProtocol_CollectSerialFrame(&USB_rx_buffer, c)) break; |
182 | } |
182 | } |
183 | } |
183 | } |
184 | if(USB_rx_buffer.Locked == FALSE) return; |
184 | if(USB_rx_buffer.Locked == FALSE) return; |
185 | 185 | ||
186 | 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 |
187 | 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 |
188 | 188 | ||
189 | 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" |
190 | switch(SerialMsg.Address) // check for Slave Address |
190 | switch(SerialMsg.Address) // check for Slave Address |
191 | { |
191 | { |
192 | case NC_ADDRESS: // own Slave Address |
192 | case NC_ADDRESS: // own Slave Address |
193 | switch(SerialMsg.CmdID) |
193 | switch(SerialMsg.CmdID) |
194 | { |
194 | { |
195 | case 'z': // connection checker |
195 | case 'z': // connection checker |
196 | memcpy(&Echo, SerialMsg.pData, sizeof(Echo)); // copy echo pattern |
196 | memcpy(&Echo, SerialMsg.pData, sizeof(Echo)); // copy echo pattern |
197 | USB_Request_Echo = TRUE; |
197 | USB_Request_Echo = TRUE; |
198 | break; |
198 | break; |
199 | 199 | ||
200 | case 'e': // request for the text of the error status |
200 | case 'e': // request for the text of the error status |
201 | USB_Request_ErrorMessage = TRUE; |
201 | USB_Request_ErrorMessage = TRUE; |
202 | break; |
202 | break; |
203 | 203 | ||
204 | default: |
204 | default: |
205 | // unsupported command recieved |
205 | // unsupported command recieved |
206 | break; |
206 | break; |
207 | } // case NC_ADDRESS |
207 | } // case NC_ADDRESS |
208 | // "break;" is missing here to fall thru to the common commands |
208 | // "break;" is missing here to fall thru to the common commands |
209 | 209 | ||
210 | default: // and any other Slave Address |
210 | default: // and any other Slave Address |
211 | 211 | ||
212 | switch(SerialMsg.CmdID) // check CmdID |
212 | switch(SerialMsg.CmdID) // check CmdID |
213 | { |
213 | { |
214 | case 'a':// request for the labels of the analog debug outputs |
214 | case 'a':// request for the labels of the analog debug outputs |
215 | USB_Request_DebugLabel = SerialMsg.pData[0]; |
215 | USB_Request_DebugLabel = SerialMsg.pData[0]; |
216 | if(USB_Request_DebugLabel > 31) USB_Request_DebugLabel = 31; |
216 | if(USB_Request_DebugLabel > 31) USB_Request_DebugLabel = 31; |
217 | break; |
217 | break; |
218 | /* |
218 | /* |
219 | case 'b': // submit extern control |
219 | case 'b': // submit extern control |
220 | memcpy(&ExternControl, SerialMsg.pData, sizeof(ExternControl)); |
220 | memcpy(&ExternControl, SerialMsg.pData, sizeof(ExternControl)); |
221 | USB_ConfirmFrame = ExternControl.Frame; |
221 | USB_ConfirmFrame = ExternControl.Frame; |
222 | break; |
222 | break; |
223 | */ |
223 | */ |
224 | case 'd': // request for debug data; |
224 | case 'd': // request for debug data; |
225 | USB_DebugData_Interval = (u32) SerialMsg.pData[0] * 10; |
225 | USB_DebugData_Interval = (u32) SerialMsg.pData[0] * 10; |
226 | if(USB_DebugData_Interval > 0) USB_Request_DebugData = TRUE; |
226 | if(USB_DebugData_Interval > 0) USB_Request_DebugData = TRUE; |
227 | USB_AboTimeOut = SetDelay(ABO_TIMEOUT); |
227 | USB_AboTimeOut = SetDelay(ABO_TIMEOUT); |
228 | break; |
228 | break; |
229 | 229 | ||
230 | case 'c': // request for 3D data; |
230 | case 'c': // request for 3D data; |
231 | USB_Data3D_Interval = (u32) SerialMsg.pData[0] * 10; |
231 | USB_Data3D_Interval = (u32) SerialMsg.pData[0] * 10; |
232 | if(USB_Data3D_Interval > 0) USB_Request_Data3D = TRUE; |
232 | if(USB_Data3D_Interval > 0) USB_Request_Data3D = TRUE; |
233 | USB_AboTimeOut = SetDelay(ABO_TIMEOUT); |
233 | USB_AboTimeOut = SetDelay(ABO_TIMEOUT); |
234 | break; |
234 | break; |
235 | 235 | ||
236 | case 'h':// reqest for display line |
236 | case 'h':// reqest for display line |
237 | if((SerialMsg.pData[0]& 0x80) == 0x00)// old format |
237 | if((SerialMsg.pData[0]& 0x80) == 0x00)// old format |
238 | { |
238 | { |
239 | USB_DisplayLine = 2; |
239 | USB_DisplayLine = 2; |
240 | USB_Display_Interval = 0; |
240 | USB_Display_Interval = 0; |
241 | } |
241 | } |
242 | else |
242 | else |
243 | { |
243 | { |
244 | USB_DisplayKeys |= ~SerialMsg.pData[0]; |
244 | USB_DisplayKeys |= ~SerialMsg.pData[0]; |
245 | USB_Display_Interval = (u32) SerialMsg.pData[1] * 10; |
245 | USB_Display_Interval = (u32) SerialMsg.pData[1] * 10; |
246 | USB_DisplayLine = 4; |
246 | USB_DisplayLine = 4; |
247 | USB_AboTimeOut = SetDelay(ABO_TIMEOUT); |
247 | USB_AboTimeOut = SetDelay(ABO_TIMEOUT); |
248 | } |
248 | } |
249 | USB_Request_Display = TRUE; |
249 | USB_Request_Display = TRUE; |
250 | break; |
250 | break; |
251 | 251 | ||
252 | case 'l':// reqest for display columns |
252 | case 'l':// reqest for display columns |
253 | MenuItem = SerialMsg.pData[0]; |
253 | MenuItem = SerialMsg.pData[0]; |
254 | USB_Request_Display1 = TRUE; |
254 | USB_Request_Display1 = TRUE; |
255 | break; |
255 | break; |
256 | 256 | ||
257 | case 'o': // request for navigation information |
257 | case 'o': // request for navigation information |
258 | USB_NaviData_Interval = (u32) SerialMsg.pData[0] * 10; |
258 | USB_NaviData_Interval = (u32) SerialMsg.pData[0] * 10; |
259 | if(USB_NaviData_Interval > 0) USB_Request_NaviData = TRUE; |
259 | if(USB_NaviData_Interval > 0) USB_Request_NaviData = TRUE; |
260 | USB_AboTimeOut = SetDelay(ABO_TIMEOUT); |
260 | USB_AboTimeOut = SetDelay(ABO_TIMEOUT); |
261 | break; |
261 | break; |
262 | 262 | ||
263 | case 'v': // request for version info |
263 | case 'v': // request for version info |
264 | USB_Request_VersionInfo = TRUE; |
264 | USB_Request_VersionInfo = TRUE; |
265 | break; |
265 | break; |
266 | default: |
266 | default: |
267 | // unsupported command recieved |
267 | // unsupported command recieved |
268 | break; |
268 | break; |
269 | } |
269 | } |
270 | break; // default: |
270 | break; // default: |
271 | } |
271 | } |
272 | Buffer_Clear(&USB_rx_buffer); |
272 | Buffer_Clear(&USB_rx_buffer); |
273 | } |
273 | } |
274 | 274 | ||
275 | 275 | ||
276 | //----------------------------------------------------------------- |
276 | //----------------------------------------------------------------- |
277 | void USB_CableConfig(FunctionalState NewState) |
277 | void USB_CableConfig(FunctionalState NewState) |
278 | { |
278 | { |
279 | if (NewState == ENABLE) |
279 | if (NewState == ENABLE) |
280 | GPIO_WriteBit(GPIO0, GPIO_Pin_1, Bit_RESET); |
280 | GPIO_WriteBit(GPIO0, GPIO_Pin_1, Bit_RESET); |
281 | else |
281 | else |
282 | GPIO_WriteBit(GPIO0, GPIO_Pin_1, Bit_SET); |
282 | GPIO_WriteBit(GPIO0, GPIO_Pin_1, Bit_SET); |
283 | } |
283 | } |
284 | //----------------------------------------------------------------- |
284 | //----------------------------------------------------------------- |
285 | void USB_EnterLowPowerMode(void) |
285 | void USB_EnterLowPowerMode(void) |
286 | { |
286 | { |
287 | /* Set the device state to suspend */ |
287 | /* Set the device state to suspend */ |
288 | bDeviceState = SUSPENDED; |
288 | bDeviceState = SUSPENDED; |
289 | } |
289 | } |
290 | //----------------------------------------------------------------- |
290 | //----------------------------------------------------------------- |
291 | void USB_LeaveLowPowerMode(void) |
291 | void USB_LeaveLowPowerMode(void) |
292 | { |
292 | { |
293 | DEVICE_INFO *pInfo = &Device_Info; |
293 | DEVICE_INFO *pInfo = &Device_Info; |
294 | 294 | ||
295 | /* Set the device state to the correct state */ |
295 | /* Set the device state to the correct state */ |
296 | if (pInfo->Current_Configuration != 0) |
296 | if (pInfo->Current_Configuration != 0) |
297 | { |
297 | { |
298 | /* Device configured */ |
298 | /* Device configured */ |
299 | bDeviceState = CONFIGURED; |
299 | bDeviceState = CONFIGURED; |
300 | } |
300 | } |
301 | else |
301 | else |
302 | { |
302 | { |
303 | bDeviceState = ATTACHED; |
303 | bDeviceState = ATTACHED; |
304 | } |
304 | } |
305 | } |
305 | } |
306 | 306 | ||
307 | 307 | ||
308 | //----------------------------------------------------------------- |
308 | //----------------------------------------------------------------- |
309 | void USB_PutString(u8 *string) |
309 | void USB_PutString(u8 *string) |
310 | { |
310 | { |
311 | u8 i = 0; |
311 | u8 i = 0; |
312 | u16 timeout = 0; |
312 | u16 timeout = 0; |
313 | 313 | ||
314 | while (string[i++] != 0){} // get string len |
314 | while (string[i++] != 0){} // get string len |
315 | while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){ if (timeout++ > 60000) return;} |
315 | while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){ if (timeout++ > 60000) return;} |
316 | UserToPMABufferCopy(string, ENDP1_TXADDR, ++i); // copy string to usb buffer |
316 | UserToPMABufferCopy(string, ENDP1_TXADDR, ++i); // copy string to usb buffer |
317 | SetEPTxCount(ENDP1,i); |
317 | SetEPTxCount(ENDP1,i); |
318 | SetEPTxValid(ENDP1); |
318 | SetEPTxValid(ENDP1); |
319 | } |
319 | } |
320 | 320 | ||
321 | //----------------------------------------------------------------- |
321 | //----------------------------------------------------------------- |
322 | void USB_PutChar(u8 c) |
322 | void USB_PutChar(u8 c) |
323 | { |
323 | { |
324 | u16 timeout = 0; |
324 | u16 timeout = 0; |
325 | while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){ if (timeout++ > 60000) return;} |
325 | while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){ if (timeout++ > 60000) return;} |
326 | UserToPMABufferCopy(&c, ENDP1_TXADDR, 2); |
326 | UserToPMABufferCopy(&c, ENDP1_TXADDR, 2); |
327 | SetEPTxCount(ENDP1,2); |
327 | SetEPTxCount(ENDP1,2); |
328 | SetEPTxValid(ENDP1); |
328 | SetEPTxValid(ENDP1); |
329 | } |
329 | } |
330 | 330 | ||
331 | //----------------------------------------------------------------- |
331 | //----------------------------------------------------------------- |
332 | void USB_SendData(u8 *pdata, u16 count) |
332 | void USB_SendData(u8 *pdata, u16 count) |
333 | { |
333 | { |
334 | u8 i; |
334 | u8 i; |
335 | count++; |
335 | count++; |
336 | u16 timeout = 0; |
336 | u16 timeout = 0; |
337 | 337 | ||
338 | for (i=0;i< (count/64)+1;i++) |
338 | for (i=0;i< (count/64)+1;i++) |
339 | { |
339 | { |
340 | while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){if (timeout++ > 60000) return;} |
340 | while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){if (timeout++ > 60000) return;} |
341 | if (i < (count/64)) |
341 | if (i < (count/64)) |
342 | { |
342 | { |
343 | UserToPMABufferCopy(&pdata[i*64], ENDP1_TXADDR, 64); |
343 | UserToPMABufferCopy(&pdata[i*64], ENDP1_TXADDR, 64); |
344 | SetEPTxCount(ENDP1,64); |
344 | SetEPTxCount(ENDP1,64); |
345 | } |
345 | } |
346 | else |
346 | else |
347 | { |
347 | { |
348 | UserToPMABufferCopy(&pdata[i*64], ENDP1_TXADDR, count % 64); |
348 | UserToPMABufferCopy(&pdata[i*64], ENDP1_TXADDR, count % 64); |
349 | SetEPTxCount(ENDP1, count % 64); |
349 | SetEPTxCount(ENDP1, count % 64); |
350 | } |
350 | } |
351 | SetEPTxValid(ENDP1); |
351 | SetEPTxValid(ENDP1); |
352 | } |
352 | } |
353 | } |
353 | } |
354 | 354 | ||
355 | /**************************************************************/ |
355 | /**************************************************************/ |
356 | /* Transmit tx buffer via usb */ |
356 | /* Transmit tx buffer via usb */ |
357 | /**************************************************************/ |
357 | /**************************************************************/ |
358 | void USB_Transmit(void) |
358 | void USB_Transmit(void) |
359 | { // nur blockweises kopieren des sendebuffers, nicht alles mit einem mal |
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 |
360 | // if something has to be send and the txd fifo is not full |
361 | 361 | ||
362 | if(USB_tx_buffer.Locked == TRUE) |
362 | if(USB_tx_buffer.Locked == TRUE) |
363 | { |
363 | { |
364 | if(_GetEPTxStatus(ENDP1) == EP_TX_NAK) |
364 | if(_GetEPTxStatus(ENDP1) == EP_TX_NAK) |
365 | { |
365 | { |
366 | u16 i; |
366 | u16 i; |
367 | if(USB_tx_buffer.Position < USB_tx_buffer.DataBytes) |
367 | if(USB_tx_buffer.Position < USB_tx_buffer.DataBytes) |
368 | { |
368 | { |
369 | 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 |
370 | if(i > 64) i = 64; // limit packet size to 64 bytes |
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); |
371 | UserToPMABufferCopy(&(USB_tx_buffer.pData[USB_tx_buffer.Position]), ENDP1_TXADDR, i); |
372 | SetEPTxCount(ENDP1,i); |
372 | SetEPTxCount(ENDP1,i); |
373 | SetEPTxValid(ENDP1); |
373 | SetEPTxValid(ENDP1); |
374 | USB_tx_buffer.Position += i; |
374 | USB_tx_buffer.Position += i; |
375 | } |
375 | } |
376 | } |
376 | } |
377 | 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 |
378 | { |
378 | { |
379 | Buffer_Clear(&USB_tx_buffer); // clear buffer |
379 | Buffer_Clear(&USB_tx_buffer); // clear buffer |
380 | } |
380 | } |
381 | } |
381 | } |
382 | } |
382 | } |
383 | 383 | ||
384 | /**************************************************************/ |
384 | /**************************************************************/ |
385 | /* Send the answers to incomming commands at the debug uart */ |
385 | /* Send the answers to incomming commands at the debug uart */ |
386 | /**************************************************************/ |
386 | /**************************************************************/ |
387 | void USB_TransmitTxData(void) |
387 | void USB_TransmitTxData(void) |
388 | { |
388 | { |
389 | USB_Transmit(); // output pending bytes in tx buffer |
389 | USB_Transmit(); // output pending bytes in tx buffer |
390 | if((USB_tx_buffer.Locked == TRUE)) return; |
390 | if((USB_tx_buffer.Locked == TRUE)) return; |
391 | 391 | ||
392 | if(CheckDelay(USB_AboTimeOut)) |
392 | if(CheckDelay(USB_AboTimeOut)) |
393 | { |
393 | { |
394 | USB_DebugData_Interval = 0; |
394 | USB_DebugData_Interval = 0; |
395 | USB_NaviData_Interval = 0; |
395 | USB_NaviData_Interval = 0; |
396 | USB_Data3D_Interval = 0; |
396 | USB_Data3D_Interval = 0; |
397 | USB_Display_Interval = 0; |
397 | USB_Display_Interval = 0; |
398 | } |
398 | } |
399 | 399 | ||
400 | if((USB_Request_DebugLabel != 0xFF) && (USB_tx_buffer.Locked == FALSE)) |
400 | if((USB_Request_DebugLabel != 0xFF) && (USB_tx_buffer.Locked == FALSE)) |
401 | { |
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); |
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; |
403 | USB_Request_DebugLabel = 0xFF; |
404 | } |
404 | } |
405 | else if(USB_ConfirmFrame && (USB_tx_buffer.Locked == FALSE)) |
405 | else if(USB_ConfirmFrame && (USB_tx_buffer.Locked == FALSE)) |
406 | { |
406 | { |
407 | 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)); |
408 | USB_ConfirmFrame = 0; |
408 | USB_ConfirmFrame = 0; |
409 | } |
409 | } |
410 | 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)) |
411 | { |
411 | { |
412 | 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)); |
413 | USB_DebugData_Timer = SetDelay(USB_DebugData_Interval); |
413 | USB_DebugData_Timer = SetDelay(USB_DebugData_Interval); |
414 | USB_Request_DebugData = FALSE; |
414 | USB_Request_DebugData = FALSE; |
415 | } |
415 | } |
416 | 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)) |
417 | { |
417 | { |
418 | 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)); |
419 | USB_Data3D_Timer = SetDelay(USB_Data3D_Interval); |
419 | USB_Data3D_Timer = SetDelay(USB_Data3D_Interval); |
420 | USB_Request_Data3D = FALSE; |
420 | USB_Request_Data3D = FALSE; |
421 | } |
421 | } |
422 | else if(USB_Request_ExternalControl && (USB_tx_buffer.Locked == FALSE)) |
422 | else if(USB_Request_ExternalControl && (USB_tx_buffer.Locked == FALSE)) |
423 | { |
423 | { |
424 | 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)); |
425 | USB_Request_ExternalControl = FALSE; |
425 | USB_Request_ExternalControl = FALSE; |
426 | } |
426 | } |
427 | 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)) |
428 | { |
428 | { |
429 | Menu_Update(USB_DisplayKeys); |
429 | Menu_Update(USB_DisplayKeys); |
430 | USB_DisplayKeys = 0; |
430 | USB_DisplayKeys = 0; |
431 | 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)); |
432 | USB_Request_Display = FALSE; |
432 | USB_Request_Display = FALSE; |
433 | } |
433 | } |
434 | else if(USB_Request_Display1 && (USB_tx_buffer.Locked == FALSE)) |
434 | else if(USB_Request_Display1 && (USB_tx_buffer.Locked == FALSE)) |
435 | { |
435 | { |
436 | Menu_Update(0); |
436 | Menu_Update(0); |
437 | 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)); |
438 | USB_Request_Display1 = FALSE; |
438 | USB_Request_Display1 = FALSE; |
439 | } |
439 | } |
440 | else if(USB_Request_VersionInfo && (USB_tx_buffer.Locked == FALSE)) |
440 | else if(USB_Request_VersionInfo && (USB_tx_buffer.Locked == FALSE)) |
441 | { |
441 | { |
442 | 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)); |
443 | USB_Request_VersionInfo = FALSE; |
443 | USB_Request_VersionInfo = FALSE; |
444 | } |
444 | } |
445 | 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)) |
446 | { |
446 | { |
447 | NaviData.Errorcode = ErrorCode; |
447 | NaviData.Errorcode = ErrorCode; |
448 | 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)); |
449 | USB_NaviData_Timer = SetDelay(USB_NaviData_Interval); |
449 | USB_NaviData_Timer = SetDelay(USB_NaviData_Interval); |
450 | USB_Request_NaviData = FALSE; |
450 | USB_Request_NaviData = FALSE; |
451 | } |
451 | } |
452 | else if(USB_Request_ErrorMessage && (USB_tx_buffer.Locked == FALSE)) |
452 | else if(USB_Request_ErrorMessage && (USB_tx_buffer.Locked == FALSE)) |
453 | { |
453 | { |
454 | 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)); |
455 | USB_Request_ErrorMessage = FALSE; |
455 | USB_Request_ErrorMessage = FALSE; |
456 | } |
456 | } |
457 | USB_Transmit(); // output pending bytes in tx buffer |
457 | USB_Transmit(); // output pending bytes in tx buffer |
458 | } |
458 | } |
459 | 459 |