Rev 767 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 767 | Rev 803 | ||
---|---|---|---|
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 <stdarg.h> |
57 | #include <stdarg.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 "uart0.h" |
62 | #include "uart0.h" |
63 | #include "uart1.h" |
63 | #include "uart1.h" |
64 | #include "timer1.h" |
64 | #include "timer1.h" |
65 | #include "ubx.h" |
65 | #include "ubx.h" |
66 | #include "mkprotocol.h" |
66 | #include "mkprotocol.h" |
67 | 67 | ||
68 | 68 | ||
69 | //------------------------------------------------------------------------------------ |
69 | //------------------------------------------------------------------------------------ |
70 | // global variables |
70 | // global variables |
71 | 71 | ||
72 | MKOSD_VersionInfo_t MKOSD_VersionInfo; |
72 | MKOSD_VersionInfo_t MKOSD_VersionInfo; |
73 | 73 | ||
74 | // UART0 MUXER |
74 | // UART0 MUXER |
75 | UART0_MuxerState_t UART0_Muxer = UART0_UNDEF; |
75 | UART0_MuxerState_t UART0_Muxer = UART0_UNDEF; |
76 | u16 Uart0Baudrate = UART0_BAUD_RATE; |
76 | u16 Uart0Baudrate = UART0_BAUD_RATE; |
77 | u16 Uart0MK3MagBaudrate = UART0_BAUD_RATE; |
77 | u16 Uart0MK3MagBaudrate = UART0_BAUD_RATE; |
78 | 78 | ||
79 | // the tx buffer |
79 | // the tx buffer |
80 | #define UART0_TX_BUFFER_LEN 150 |
80 | #define UART0_TX_BUFFER_LEN 150 |
81 | u8 UART0_tbuffer[UART0_TX_BUFFER_LEN]; |
81 | u8 UART0_tbuffer[UART0_TX_BUFFER_LEN]; |
82 | Buffer_t UART0_tx_buffer; |
82 | Buffer_t UART0_tx_buffer; |
83 | 83 | ||
84 | // the rx buffer |
84 | // the rx buffer |
85 | #define UART0_RX_BUFFER_LEN 150 |
85 | #define UART0_RX_BUFFER_LEN 150 |
86 | u8 UART0_rbuffer[UART0_RX_BUFFER_LEN]; |
86 | u8 UART0_rbuffer[UART0_RX_BUFFER_LEN]; |
87 | Buffer_t UART0_rx_buffer; |
87 | Buffer_t UART0_rx_buffer; |
88 | 88 | ||
89 | u8 UART0_Request_VersionInfo = FALSE; |
89 | u8 UART0_Request_VersionInfo = FALSE; |
90 | u8 UART0_Request_NaviData = FALSE; |
90 | u8 UART0_Request_NaviData = FALSE; |
91 | u8 UART0_Request_ErrorMessage = FALSE; |
91 | u8 UART0_Request_ErrorMessage = FALSE; |
92 | u32 UART0_NaviData_Timer; |
92 | u32 UART0_NaviData_Timer; |
93 | u32 UART0_NaviData_Interval = 0; // in ms |
93 | u32 UART0_NaviData_Interval = 0; // in ms |
94 | 94 | ||
95 | u16 GPS_Version = 0; |
95 | u16 GPS_Version = 0; |
96 | //------------------------------------------------------------------------------------ |
96 | //------------------------------------------------------------------------------------ |
97 | // functions |
97 | // functions |
98 | 98 | ||
99 | /********************************************************/ |
99 | /********************************************************/ |
100 | /* Configure uart 0 */ |
100 | /* Configure uart 0 */ |
101 | /********************************************************/ |
101 | /********************************************************/ |
102 | void UART0_Configure(u16 Baudrate) |
102 | void UART0_Configure(u16 Baudrate) |
103 | { |
103 | { |
104 | UART_InitTypeDef UART_InitStructure; |
104 | UART_InitTypeDef UART_InitStructure; |
105 | 105 | ||
106 | SCU_APBPeriphClockConfig(__UART0, ENABLE); // Enable the UART0 Clock |
106 | SCU_APBPeriphClockConfig(__UART0, ENABLE); // Enable the UART0 Clock |
107 | 107 | ||
108 | /* UART0 configured as follow: |
108 | /* UART0 configured as follow: |
109 | - Word Length = 8 Bits |
109 | - Word Length = 8 Bits |
110 | - One Stop Bit |
110 | - One Stop Bit |
111 | - No parity |
111 | - No parity |
112 | - BaudRate taken from function argument |
112 | - BaudRate taken from function argument |
113 | - Hardware flow control Disabled |
113 | - Hardware flow control Disabled |
114 | - Receive and transmit enabled |
114 | - Receive and transmit enabled |
115 | - Receive and transmit FIFOs are Disabled |
115 | - Receive and transmit FIFOs are Disabled |
116 | */ |
116 | */ |
117 | UART_StructInit(&UART_InitStructure); |
117 | UART_StructInit(&UART_InitStructure); |
118 | UART_InitStructure.UART_WordLength = UART_WordLength_8D; |
118 | UART_InitStructure.UART_WordLength = UART_WordLength_8D; |
119 | UART_InitStructure.UART_StopBits = UART_StopBits_1; |
119 | UART_InitStructure.UART_StopBits = UART_StopBits_1; |
120 | UART_InitStructure.UART_Parity = UART_Parity_No ; |
120 | UART_InitStructure.UART_Parity = UART_Parity_No ; |
121 | UART_InitStructure.UART_BaudRate = Baudrate; |
121 | UART_InitStructure.UART_BaudRate = Baudrate; |
122 | UART_InitStructure.UART_HardwareFlowControl = UART_HardwareFlowControl_None; |
122 | UART_InitStructure.UART_HardwareFlowControl = UART_HardwareFlowControl_None; |
123 | UART_InitStructure.UART_Mode = UART_Mode_Tx_Rx; |
123 | UART_InitStructure.UART_Mode = UART_Mode_Tx_Rx; |
124 | UART_InitStructure.UART_FIFO = UART_FIFO_Enable; |
124 | UART_InitStructure.UART_FIFO = UART_FIFO_Enable; |
125 | UART_InitStructure.UART_TxFIFOLevel = UART_FIFOLevel_1_2; |
125 | UART_InitStructure.UART_TxFIFOLevel = UART_FIFOLevel_1_2; |
126 | UART_InitStructure.UART_RxFIFOLevel = UART_FIFOLevel_1_2; |
126 | UART_InitStructure.UART_RxFIFOLevel = UART_FIFOLevel_1_2; |
127 | 127 | ||
128 | UART_DeInit(UART0); // reset uart 0 to default |
128 | UART_DeInit(UART0); // reset uart 0 to default |
129 | UART_Init(UART0, &UART_InitStructure); // initialize uart 0 |
129 | UART_Init(UART0, &UART_InitStructure); // initialize uart 0 |
130 | 130 | ||
131 | // enable uart 0 interrupts selective |
131 | // enable uart 0 interrupts selective |
132 | UART_ITConfig(UART0, UART_IT_Receive | UART_IT_ReceiveTimeOut /*| UART_IT_FrameError*/, ENABLE); |
132 | UART_ITConfig(UART0, UART_IT_Receive | UART_IT_ReceiveTimeOut /*| UART_IT_FrameError*/, ENABLE); |
133 | UART_Cmd(UART0, ENABLE); // enable uart 0 |
133 | UART_Cmd(UART0, ENABLE); // enable uart 0 |
134 | // configure the uart 0 interupt line |
134 | // configure the uart 0 interupt line |
135 | VIC_Config(UART0_ITLine, VIC_IRQ, PRIORITY_UART0); |
135 | VIC_Config(UART0_ITLine, VIC_IRQ, PRIORITY_UART0); |
136 | // enable the uart 0 IRQ |
136 | // enable the uart 0 IRQ |
137 | VIC_ITCmd(UART0_ITLine, ENABLE); |
137 | VIC_ITCmd(UART0_ITLine, ENABLE); |
138 | } |
138 | } |
139 | 139 | ||
140 | /********************************************************/ |
140 | /********************************************************/ |
141 | /* Connect RXD & TXD to GPS */ |
141 | /* Connect RXD & TXD to GPS */ |
142 | /********************************************************/ |
142 | /********************************************************/ |
143 | void UART0_Connect_to_MKGPS(u16 Baudrate) |
143 | void UART0_Connect_to_MKGPS(u16 Baudrate) |
144 | { |
144 | { |
145 | GPIO_InitTypeDef GPIO_InitStructure; |
145 | GPIO_InitTypeDef GPIO_InitStructure; |
146 | 146 | ||
147 | UART0_Muxer = UART0_UNDEF; |
147 | UART0_Muxer = UART0_UNDEF; |
148 | 148 | ||
149 | SCU_APBPeriphClockConfig(__GPIO6, ENABLE); // Enable the GPIO6 Clock |
149 | SCU_APBPeriphClockConfig(__GPIO6, ENABLE); // Enable the GPIO6 Clock |
150 | // unmap UART0 from Compass |
150 | // unmap UART0 from Compass |
151 | // set port pin 5.1 (serial data from compass) to input and disconnect from IP |
151 | // set port pin 5.1 (serial data from compass) to input and disconnect from IP |
152 | GPIO_StructInit(&GPIO_InitStructure); |
152 | GPIO_StructInit(&GPIO_InitStructure); |
153 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
153 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
154 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; |
154 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; |
155 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
155 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
156 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Disable; |
156 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Disable; |
157 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; |
157 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; |
158 | GPIO_Init(GPIO5, &GPIO_InitStructure); |
158 | GPIO_Init(GPIO5, &GPIO_InitStructure); |
159 | // set port pin 5.0 (serial data to compass) to input |
159 | // set port pin 5.0 (serial data to compass) to input |
160 | GPIO_StructInit(&GPIO_InitStructure); |
160 | GPIO_StructInit(&GPIO_InitStructure); |
161 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
161 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
162 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; |
162 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; |
163 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
163 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
164 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Disable; |
164 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Disable; |
165 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; |
165 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; |
166 | GPIO_Init(GPIO5, &GPIO_InitStructure); |
166 | GPIO_Init(GPIO5, &GPIO_InitStructure); |
167 | // map UART0 to GPS |
167 | // map UART0 to GPS |
168 | // set port pin 6.6 (serial data from gps) to input and connect to IP |
168 | // set port pin 6.6 (serial data from gps) to input and connect to IP |
169 | GPIO_StructInit(&GPIO_InitStructure); |
169 | GPIO_StructInit(&GPIO_InitStructure); |
170 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
170 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
171 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; |
171 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; |
172 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
172 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
173 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable; |
173 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable; |
174 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; //UART0_RxD |
174 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; //UART0_RxD |
175 | GPIO_Init(GPIO6, &GPIO_InitStructure); |
175 | GPIO_Init(GPIO6, &GPIO_InitStructure); |
176 | // set port pin 6.7 (serial data to gps) to output |
176 | // set port pin 6.7 (serial data to gps) to output |
177 | GPIO_StructInit(&GPIO_InitStructure); |
177 | GPIO_StructInit(&GPIO_InitStructure); |
178 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
178 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
179 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; |
179 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; |
180 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
180 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
181 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable; |
181 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable; |
182 | GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt3; //UART0_TX |
182 | GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt3; //UART0_TX |
183 | GPIO_Init(GPIO6, &GPIO_InitStructure); |
183 | GPIO_Init(GPIO6, &GPIO_InitStructure); |
184 | // configure the UART0 |
184 | // configure the UART0 |
185 | UART0_Configure(Baudrate); |
185 | UART0_Configure(Baudrate); |
186 | 186 | ||
187 | UART0_Muxer = UART0_MKGPS; |
187 | UART0_Muxer = UART0_MKGPS; |
188 | } |
188 | } |
189 | 189 | ||
190 | /********************************************************/ |
190 | /********************************************************/ |
191 | /* Connect RXD & TXD to MK3MAG */ |
191 | /* Connect RXD & TXD to MK3MAG */ |
192 | /********************************************************/ |
192 | /********************************************************/ |
193 | void UART0_Connect_to_MK3MAG(void) |
193 | void UART0_Connect_to_MK3MAG(void) |
194 | { |
194 | { |
195 | u16 Baudrate; |
195 | u16 Baudrate; |
196 | 196 | ||
197 | GPIO_InitTypeDef GPIO_InitStructure; |
197 | GPIO_InitTypeDef GPIO_InitStructure; |
198 | 198 | ||
199 | UART0_Muxer = UART0_UNDEF; |
199 | UART0_Muxer = UART0_UNDEF; |
200 | 200 | ||
201 | SCU_APBPeriphClockConfig(__GPIO5, ENABLE); |
201 | SCU_APBPeriphClockConfig(__GPIO5, ENABLE); |
202 | // unmap UART0 from GPS |
202 | // unmap UART0 from GPS |
203 | // set port pin 6.6 (serial data from gps) to input and disconnect from IP |
203 | // set port pin 6.6 (serial data from gps) to input and disconnect from IP |
204 | GPIO_StructInit(&GPIO_InitStructure); |
204 | GPIO_StructInit(&GPIO_InitStructure); |
205 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
205 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
206 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; |
206 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; |
207 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
207 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
208 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Disable; |
208 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Disable; |
209 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; |
209 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; |
210 | GPIO_Init(GPIO6, &GPIO_InitStructure); |
210 | GPIO_Init(GPIO6, &GPIO_InitStructure); |
211 | // set port pin 6.7 (serial data to gps) to input |
211 | // set port pin 6.7 (serial data to gps) to input |
212 | GPIO_StructInit(&GPIO_InitStructure); |
212 | GPIO_StructInit(&GPIO_InitStructure); |
213 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
213 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
214 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; |
214 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; |
215 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
215 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
216 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Disable; |
216 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Disable; |
217 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; |
217 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; |
218 | GPIO_Init(GPIO6, &GPIO_InitStructure); |
218 | GPIO_Init(GPIO6, &GPIO_InitStructure); |
219 | 219 | ||
220 | // map UART0 to Compass |
220 | // map UART0 to Compass |
221 | // set port pin 5.1 (serial data from compass) to input and connect to IP |
221 | // set port pin 5.1 (serial data from compass) to input and connect to IP |
222 | GPIO_StructInit(&GPIO_InitStructure); |
222 | GPIO_StructInit(&GPIO_InitStructure); |
223 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
223 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
224 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; |
224 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; |
225 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
225 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
226 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable; |
226 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable; |
227 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; //UART0_RxD |
227 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; //UART0_RxD |
228 | GPIO_Init(GPIO5, &GPIO_InitStructure); |
228 | GPIO_Init(GPIO5, &GPIO_InitStructure); |
229 | // set port pin 5.0 (serial data to compass) to output |
229 | // set port pin 5.0 (serial data to compass) to output |
230 | GPIO_StructInit(&GPIO_InitStructure); |
230 | GPIO_StructInit(&GPIO_InitStructure); |
231 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
231 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
232 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; |
232 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; |
233 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
233 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
234 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable; |
234 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable; |
235 | GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt3; //UART0_TX |
235 | GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt3; //UART0_TX |
236 | GPIO_Init(GPIO5, &GPIO_InitStructure); |
236 | GPIO_Init(GPIO5, &GPIO_InitStructure); |
237 | Baudrate = UART0_BAUD_RATE + ((UART0_BAUD_RATE * 2)/100); // MK3Mag baudrate is a little bit higher... |
237 | Baudrate = UART0_BAUD_RATE + ((UART0_BAUD_RATE * 2)/100); // MK3Mag baudrate is a little bit higher... |
238 | UART0_Configure(Baudrate); |
238 | UART0_Configure(Baudrate); |
239 | UART0_Muxer = UART0_MK3MAG; |
239 | UART0_Muxer = UART0_MK3MAG; |
240 | } |
240 | } |
241 | 241 | ||
242 | /********************************************************/ |
242 | /********************************************************/ |
243 | /* Initialize UART0 */ |
243 | /* Initialize UART0 */ |
244 | /********************************************************/ |
244 | /********************************************************/ |
245 | void UART0_Init(void) |
245 | void UART0_Init(void) |
246 | { |
246 | { |
247 | UART1_PutString("\r\n UART0 init..."); |
247 | UART1_PutString("\r\n UART0 init..."); |
248 | 248 | ||
249 | UART0_Connect_to_MKGPS(UART0_BAUD_RATE); |
249 | UART0_Connect_to_MKGPS(UART0_BAUD_RATE); |
250 | 250 | ||
251 | // initialize txd buffer |
251 | // initialize txd buffer |
252 | Buffer_Init(&UART0_tx_buffer, UART0_tbuffer, UART0_TX_BUFFER_LEN); |
252 | Buffer_Init(&UART0_tx_buffer, UART0_tbuffer, UART0_TX_BUFFER_LEN); |
253 | 253 | ||
254 | // initialize rxd buffer |
254 | // initialize rxd buffer |
255 | Buffer_Init(&UART0_rx_buffer, UART0_rbuffer, UART0_RX_BUFFER_LEN); |
255 | Buffer_Init(&UART0_rx_buffer, UART0_rbuffer, UART0_RX_BUFFER_LEN); |
256 | 256 | ||
257 | UART1_PutString("ok"); |
257 | UART1_PutString("ok"); |
258 | } |
258 | } |
259 | 259 | ||
260 | /********************************************************/ |
260 | /********************************************************/ |
261 | /* UART0 Interrupt Handler */ |
261 | /* UART0 Interrupt Handler */ |
262 | /********************************************************/ |
262 | /********************************************************/ |
263 | void UART0_IRQHandler(void) |
263 | void UART0_IRQHandler(void) |
264 | { |
264 | { |
265 | u8 c; |
265 | u8 c; |
266 | // if receive irq (FIFO is over trigger level) or receive timeout irq (FIFO is not empty for longer times) has occured |
266 | // if receive irq (FIFO is over trigger level) or receive timeout irq (FIFO is not empty for longer times) has occured |
267 | if((UART_GetITStatus(UART0, UART_IT_Receive) != RESET) || (UART_GetITStatus(UART0, UART_IT_ReceiveTimeOut) != RESET) ) |
267 | if((UART_GetITStatus(UART0, UART_IT_Receive) != RESET) || (UART_GetITStatus(UART0, UART_IT_ReceiveTimeOut) != RESET) ) |
268 | { |
268 | { |
269 | UART_ClearITPendingBit(UART0, UART_IT_Receive); // clear receive interrupt flag |
269 | UART_ClearITPendingBit(UART0, UART_IT_Receive); // clear receive interrupt flag |
270 | UART_ClearITPendingBit(UART0, UART_IT_ReceiveTimeOut); // clear receive timeout interrupt flag |
270 | UART_ClearITPendingBit(UART0, UART_IT_ReceiveTimeOut); // clear receive timeout interrupt flag |
271 | 271 | ||
272 | // if debug UART is UART0 |
272 | // if debug UART is UART0 |
273 | if (DebugUART == UART0) |
273 | if (DebugUART == UART0) |
274 | { // forward received data to the UART1 tx buffer |
274 | { // forward received data to the UART1 tx buffer |
275 | while(UART_GetFlagStatus(UART0, UART_FLAG_RxFIFOEmpty) != SET) |
275 | while(UART_GetFlagStatus(UART0, UART_FLAG_RxFIFOEmpty) != SET) |
276 | { |
276 | { |
277 | // wait for space in the tx buffer of the UART1 |
277 | // wait for space in the tx buffer of the UART1 |
278 | while(UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) == SET) {}; |
278 | while(UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) == SET) {}; |
279 | // move the byte from the rx buffer of UART0 to the tx buffer of UART1 |
279 | // move the byte from the rx buffer of UART0 to the tx buffer of UART1 |
280 | UART_SendData(UART1, UART_ReceiveData(UART0)); |
280 | UART_SendData(UART1, UART_ReceiveData(UART0)); |
281 | } |
281 | } |
282 | } |
282 | } |
283 | else // UART0 is not the DebugUART (normal operation) |
283 | else // UART0 is not the DebugUART (normal operation) |
284 | { |
284 | { |
285 | // repeat until no byte is in the RxFIFO |
285 | // repeat until no byte is in the RxFIFO |
286 | while (UART_GetFlagStatus(UART0, UART_FLAG_RxFIFOEmpty) != SET) |
286 | while (UART_GetFlagStatus(UART0, UART_FLAG_RxFIFOEmpty) != SET) |
287 | { |
287 | { |
288 | c = UART_ReceiveData(UART0); // get byte from rx fifo |
288 | c = UART_ReceiveData(UART0); // get byte from rx fifo |
289 | switch(UART0_Muxer) |
289 | switch(UART0_Muxer) |
290 | { |
290 | { |
291 | case UART0_MKGPS: |
291 | case UART0_MKGPS: |
292 | UBX_RxParser(c); // if connected to GPS forward byte to ubx parser |
292 | UBX_RxParser(c); // if connected to GPS forward byte to ubx parser |
293 | // MKProtocol_CollectSerialFrame(&UART0_rx_buffer, c); // ckeck for MK-Frames also |
293 | // MKProtocol_CollectSerialFrame(&UART0_rx_buffer, c); // ckeck for MK-Frames also |
294 | break; |
294 | break; |
295 | case UART0_MK3MAG: |
295 | case UART0_MK3MAG: |
296 | // ignore any byte send from MK3MAG |
296 | // ignore any byte send from MK3MAG |
297 | break; |
297 | break; |
298 | case UART0_UNDEF: |
298 | case UART0_UNDEF: |
299 | default: |
299 | default: |
300 | // ignore the byte from unknown source |
300 | // ignore the byte from unknown source |
301 | break; |
301 | break; |
302 | } // eof switch(UART0_Muxer) |
302 | } // eof switch(UART0_Muxer) |
303 | } // eof while |
303 | } // eof while |
304 | } // eof UART0 is not the DebugUART |
304 | } // eof UART0 is not the DebugUART |
305 | } // eof receive irq or receive timeout irq |
305 | } // eof receive irq or receive timeout irq |
306 | 306 | ||
307 | VIC1->VAR = 0xFF; // write any value to VIC0 Vector address register |
307 | VIC1->VAR = 0xFF; // write any value to VIC0 Vector address register |
308 | } |
308 | } |
309 | 309 | ||
310 | /**************************************************************/ |
310 | /**************************************************************/ |
311 | /* Process incomming data from debug uart */ |
311 | /* Process incomming data from debug uart */ |
312 | /**************************************************************/ |
312 | /**************************************************************/ |
313 | void UART0_ProcessRxData(void) |
313 | void UART0_ProcessRxData(void) |
314 | { |
314 | { |
315 | SerialMsg_t SerialMsg; |
315 | SerialMsg_t SerialMsg; |
316 | // if data in the rxd buffer are not locked immediately return |
316 | // if data in the rxd buffer are not locked immediately return |
317 | if((UART0_rx_buffer.Locked == FALSE) || (DebugUART == UART0) ) return; |
317 | if((UART0_rx_buffer.Locked == FALSE) || (DebugUART == UART0) ) return; |
318 | 318 | ||
319 | MKProtocol_DecodeSerialFrameHeader(&UART0_rx_buffer, &SerialMsg); // decode serial frame in rxd buffer |
319 | MKProtocol_DecodeSerialFrameHeader(&UART0_rx_buffer, &SerialMsg); // decode serial frame in rxd buffer |
320 | MKProtocol_DecodeSerialFrameData(&UART0_rx_buffer, &SerialMsg); // decode serial frame in rxd buffer |
320 | MKProtocol_DecodeSerialFrameData(&UART0_rx_buffer, &SerialMsg); // decode serial frame in rxd buffer |
321 | 321 | ||
322 | switch(SerialMsg.Address) // check for Slave Address |
322 | switch(SerialMsg.Address) // check for Slave Address |
323 | { |
323 | { |
324 | case MKOSD_ADDRESS: // answers from the MKOSD |
324 | case MKOSD_ADDRESS: // answers from the MKOSD |
325 | switch(SerialMsg.CmdID) |
325 | switch(SerialMsg.CmdID) |
326 | { |
326 | { |
327 | case 'V': |
327 | case 'V': |
328 | memcpy(&MKOSD_VersionInfo, SerialMsg.pData, sizeof(MKOSD_VersionInfo)); // copy echo pattern |
328 | memcpy(&MKOSD_VersionInfo, SerialMsg.pData, sizeof(MKOSD_VersionInfo)); // copy echo pattern |
329 | break; |
329 | break; |
330 | default: |
330 | default: |
331 | break; |
331 | break; |
332 | } // case MKOSD_ADDRESS |
332 | } // case MKOSD_ADDRESS |
333 | break; |
333 | break; |
334 | 334 | ||
335 | case NC_ADDRESS: // own Slave Address |
335 | case NC_ADDRESS: // own Slave Address |
336 | switch(SerialMsg.CmdID) |
336 | switch(SerialMsg.CmdID) |
337 | { |
337 | { |
338 | case 'e': // request for the text of the error status |
338 | case 'e': // request for the text of the error status |
339 | UART0_Request_ErrorMessage = TRUE; |
339 | UART0_Request_ErrorMessage = TRUE; |
340 | break; |
340 | break; |
341 | case 'o': // request for navigation information |
341 | case 'o': // request for navigation information |
342 | UART0_NaviData_Interval = (u32) SerialMsg.pData[0] * 10; |
342 | UART0_NaviData_Interval = (u32) SerialMsg.pData[0] * 10; |
343 | if(UART0_NaviData_Interval > 0) UART0_Request_NaviData = TRUE; |
343 | if(UART0_NaviData_Interval > 0) UART0_Request_NaviData = TRUE; |
344 | break; |
344 | break; |
345 | default: |
345 | default: |
346 | break; |
346 | break; |
347 | } // case NC_ADDRESS |
347 | } // case NC_ADDRESS |
348 | // "break;" is missing here to fall thru to the common commands |
348 | // "break;" is missing here to fall thru to the common commands |
349 | 349 | ||
350 | default: // and any other Slave Address |
350 | default: // and any other Slave Address |
351 | switch(SerialMsg.CmdID) // check CmdID |
351 | switch(SerialMsg.CmdID) // check CmdID |
352 | { |
352 | { |
353 | case 'v': // request for version info |
353 | case 'v': // request for version info |
354 | UART0_Request_VersionInfo = TRUE; |
354 | UART0_Request_VersionInfo = TRUE; |
355 | break; |
355 | break; |
356 | default: |
356 | default: |
357 | // unsupported command recieved |
357 | // unsupported command recieved |
358 | break; |
358 | break; |
359 | } |
359 | } |
360 | break; // default: |
360 | break; // default: |
361 | } |
361 | } |
362 | Buffer_Clear(&UART0_rx_buffer); |
362 | Buffer_Clear(&UART0_rx_buffer); |
363 | } |
363 | } |
364 | 364 | ||
365 | /**************************************************************/ |
365 | /**************************************************************/ |
366 | /* Transmit tx buffer via uart0 */ |
366 | /* Transmit tx buffer via uart0 */ |
367 | /**************************************************************/ |
367 | /**************************************************************/ |
368 | void UART0_Transmit(void) |
368 | void UART0_Transmit(void) |
369 | { |
369 | { |
370 | u8 tmp_tx; |
370 | u8 tmp_tx; |
371 | 371 | ||
372 | if(DebugUART == UART0) return; // no data output if debug uart is rederected to UART0 |
372 | if(DebugUART == UART0) return; // no data output if debug uart is rederected to UART0 |
373 | // if something has to be send and the txd fifo is not full |
373 | // if something has to be send and the txd fifo is not full |
374 | if((UART0_tx_buffer.Locked == TRUE) && (UART_GetFlagStatus(UART0, UART_FLAG_TxFIFOFull) == RESET)) |
374 | if((UART0_tx_buffer.Locked == TRUE) && (UART_GetFlagStatus(UART0, UART_FLAG_TxFIFOFull) == RESET)) |
375 | { |
375 | { |
376 | tmp_tx = UART0_tx_buffer.pData[UART0_tx_buffer.Position++]; // read next byte from txd buffer |
376 | tmp_tx = UART0_tx_buffer.pData[UART0_tx_buffer.Position++]; // read next byte from txd buffer |
377 | UART_SendData(UART0, tmp_tx); // put character to txd fifo |
377 | UART_SendData(UART0, tmp_tx); // put character to txd fifo |
378 | // if terminating character or end of txd buffer reached |
378 | // if terminating character or end of txd buffer reached |
379 | // if((tmp_tx == '\r') || (UART0_tx_buffer.Position == UART0_tx_buffer.Size)) |
379 | // if((tmp_tx == '\r') || (UART0_tx_buffer.Position == UART0_tx_buffer.Size)) |
380 | if((UART0_tx_buffer.Position == UART0_tx_buffer.DataBytes) || (UART0_tx_buffer.Position == UART0_tx_buffer.Size)) |
380 | if((UART0_tx_buffer.Position == UART0_tx_buffer.DataBytes) || (UART0_tx_buffer.Position == UART0_tx_buffer.Size)) |
381 | { |
381 | { |
382 | Buffer_Clear(&UART0_tx_buffer); |
382 | Buffer_Clear(&UART0_tx_buffer); |
383 | } |
383 | } |
384 | } |
384 | } |
385 | } |
385 | } |
386 | 386 | ||
387 | 387 | ||
388 | /**************************************************************/ |
388 | /**************************************************************/ |
389 | /* Send the answers to incomming commands at the uart0 */ |
389 | /* Send the answers to incomming commands at the uart0 */ |
390 | /**************************************************************/ |
390 | /**************************************************************/ |
391 | void UART0_TransmitTxData(void) |
391 | void UART0_TransmitTxData(void) |
392 | { |
392 | { |
393 | if(DebugUART == UART0) return; |
393 | if(DebugUART == UART0) return; |
394 | UART0_Transmit(); // output pending bytes in tx buffer |
394 | UART0_Transmit(); // output pending bytes in tx buffer |
395 | if(UART0_tx_buffer.Locked == TRUE) return; |
395 | if(UART0_tx_buffer.Locked == TRUE) return; |
396 | 396 | ||
397 | else if(UART0_Request_ErrorMessage && (UART0_tx_buffer.Locked == FALSE)) |
397 | else if(UART0_Request_ErrorMessage && (UART0_tx_buffer.Locked == FALSE)) |
398 | { |
398 | { |
399 | MKProtocol_CreateSerialFrame(&UART0_tx_buffer, 'E', NC_ADDRESS, 1, (u8 *)&ErrorMSG, sizeof(ErrorMSG)); |
399 | MKProtocol_CreateSerialFrame(&UART0_tx_buffer, 'E', NC_ADDRESS, 1, (u8 *)&ErrorMSG, sizeof(ErrorMSG)); |
400 | UART0_Request_ErrorMessage = FALSE; |
400 | UART0_Request_ErrorMessage = FALSE; |
401 | } |
401 | } |
402 | else if(UART0_Request_VersionInfo && (UART0_tx_buffer.Locked == FALSE)) |
402 | else if(UART0_Request_VersionInfo && (UART0_tx_buffer.Locked == FALSE)) |
403 | { |
403 | { |
404 | MKProtocol_CreateSerialFrame(&UART0_tx_buffer, 'V', NC_ADDRESS,1, (u8 *)&UART_VersionInfo, sizeof(UART_VersionInfo)); |
404 | MKProtocol_CreateSerialFrame(&UART0_tx_buffer, 'V', NC_ADDRESS,1, (u8 *)&UART_VersionInfo, sizeof(UART_VersionInfo)); |
405 | UART0_Request_VersionInfo = FALSE; |
405 | UART0_Request_VersionInfo = FALSE; |
406 | } |
406 | } |
407 | else if(( ((UART0_NaviData_Interval >0) && CheckDelay(UART0_NaviData_Timer) ) || UART0_Request_NaviData) && (UART0_tx_buffer.Locked == FALSE)) |
407 | else if(( ((UART0_NaviData_Interval >0) && CheckDelay(UART0_NaviData_Timer) ) || UART0_Request_NaviData) && (UART0_tx_buffer.Locked == FALSE)) |
408 | { |
408 | { |
409 | NaviData.Errorcode = ErrorCode; |
409 | NaviData.Errorcode = ErrorCode; |
410 | MKProtocol_CreateSerialFrame(&UART0_tx_buffer, 'O', NC_ADDRESS,1, (u8 *)&NaviData, sizeof(NaviData)); |
410 | MKProtocol_CreateSerialFrame(&UART0_tx_buffer, 'O', NC_ADDRESS,1, (u8 *)&NaviData, sizeof(NaviData)); |
411 | UART0_NaviData_Timer = SetDelay(UART0_NaviData_Interval); |
411 | UART0_NaviData_Timer = SetDelay(UART0_NaviData_Interval); |
412 | UART0_Request_NaviData = FALSE; |
412 | UART0_Request_NaviData = FALSE; |
413 | } |
413 | } |
414 | UART0_Transmit(); // output pending bytes in tx buffer |
414 | UART0_Transmit(); // output pending bytes in tx buffer |
415 | } |
415 | } |
416 | 416 | ||
417 | 417 | ||
418 | /**************************************************************/ |
418 | /**************************************************************/ |
419 | /* Get the version of the MKOSD */ |
419 | /* Get the version of the MKOSD */ |
420 | /**************************************************************/ |
420 | /**************************************************************/ |
421 | u8 UART0_GetMKOSDVersion(void) |
421 | u8 UART0_GetMKOSDVersion(void) |
422 | { |
422 | { |
423 | u32 timeout; |
423 | u32 timeout; |
424 | u8 msg[64]; |
424 | u8 msg[64]; |
425 | u8 retval = 0; |
425 | u8 retval = 0; |
426 | 426 | ||
427 | MKOSD_VersionInfo.SWMajor = 0xFF; |
427 | MKOSD_VersionInfo.SWMajor = 0xFF; |
428 | MKOSD_VersionInfo.SWMinor = 0xFF; |
428 | MKOSD_VersionInfo.SWMinor = 0xFF; |
429 | MKOSD_VersionInfo.SWPatch = 0xFF; |
429 | MKOSD_VersionInfo.SWPatch = 0xFF; |
430 | 430 | ||
431 | if(UART0_Muxer != UART0_MKGPS) UART0_Connect_to_MKGPS(UART0_BAUD_RATE); |
431 | if(UART0_Muxer != UART0_MKGPS) UART0_Connect_to_MKGPS(UART0_BAUD_RATE); |
432 | while(UART0_tx_buffer.Locked == TRUE) UART0_Transmit(); // output pending bytes in tx buffer; |
432 | while(UART0_tx_buffer.Locked == TRUE) UART0_Transmit(); // output pending bytes in tx buffer; |
433 | 433 | ||
434 | MKProtocol_CreateSerialFrame(&UART0_tx_buffer, 'v', MKOSD_ADDRESS, 0); // request for version info |
434 | MKProtocol_CreateSerialFrame(&UART0_tx_buffer, 'v', MKOSD_ADDRESS, 0); // request for version info |
435 | while(UART0_tx_buffer.Locked == TRUE) UART0_Transmit(); // output pending bytes in tx buffer; |
435 | while(UART0_tx_buffer.Locked == TRUE) UART0_Transmit(); // output pending bytes in tx buffer; |
436 | 436 | ||
437 | timeout = SetDelay(500); |
437 | timeout = SetDelay(500); |
438 | do |
438 | do |
439 | { |
439 | { |
440 | UART0_ProcessRxData(); |
440 | UART0_ProcessRxData(); |
441 | if(MKOSD_VersionInfo.SWMajor != 0xFF) break; |
441 | if(MKOSD_VersionInfo.SWMajor != 0xFF) break; |
442 | }while(!CheckDelay(timeout)); |
442 | }while(!CheckDelay(timeout)); |
443 | 443 | ||
444 | if(MKOSD_VersionInfo.SWMajor != 0xFF) |
444 | if(MKOSD_VersionInfo.SWMajor != 0xFF) |
445 | { |
445 | { |
446 | sprintf(msg, "\r\n MK-OSD V%d.%d%c", MKOSD_VersionInfo.SWMajor, MKOSD_VersionInfo.SWMinor, 'a'+MKOSD_VersionInfo.SWPatch); |
446 | sprintf(msg, "\r\n MK-OSD V%d.%d%c", MKOSD_VersionInfo.SWMajor, MKOSD_VersionInfo.SWMinor, 'a'+MKOSD_VersionInfo.SWPatch); |
447 | UART1_PutString(msg); |
447 | UART1_PutString(msg); |
448 | retval = 1; |
448 | retval = 1; |
449 | } |
449 | } |
450 | //else UART1_PutString("\n\r No version information from MK-OSD."); |
450 | //else UART1_PutString("\n\r No version information from MK-OSD."); |
451 | return(retval); |
451 | return(retval); |
452 | } |
452 | } |
453 | 453 | ||
454 | /**************************************************************/ |
454 | /**************************************************************/ |
455 | /* Send a message to the UBLOX device */ |
455 | /* Send a message to the UBLOX device */ |
456 | /**************************************************************/ |
456 | /**************************************************************/ |
457 | u8 UART0_UBXSendMsg(u8* pData, u16 Len) |
457 | u8 UART0_UBXSendMsg(u8* pData, u16 Len) |
458 | { |
458 | { |
459 | u8 retval = 0; |
459 | u8 retval = 0; |
460 | // check for connection to GPS |
460 | // check for connection to GPS |
461 | if(UART0_Muxer != UART0_MKGPS) return(retval); |
461 | if(UART0_Muxer != UART0_MKGPS) return(retval); |
462 | while(UART0_tx_buffer.Locked == TRUE) UART0_Transmit(); // output pending bytes in tx buffer; |
462 | while(UART0_tx_buffer.Locked == TRUE) UART0_Transmit(); // output pending bytes in tx buffer; |
463 | UBX_CreateMsg(&UART0_tx_buffer, pData, Len); // build ubx message frame |
463 | UBX_CreateMsg(&UART0_tx_buffer, pData, Len); // build ubx message frame |
464 | while(UART0_tx_buffer.Locked == TRUE) UART0_Transmit(); // output pending bytes in tx buffer; |
464 | while(UART0_tx_buffer.Locked == TRUE) UART0_Transmit(); // output pending bytes in tx buffer; |
465 | return(1); |
465 | return(1); |
466 | } |
466 | } |
467 | 467 | ||
468 | /**************************************************************/ |
468 | /**************************************************************/ |
469 | /* Send a configuration message to the UBLOX device */ |
469 | /* Send a configuration message to the UBLOX device */ |
470 | /**************************************************************/ |
470 | /**************************************************************/ |
471 | u8 UART0_UBXSendCFGMsg(u8* pData, u16 Len) |
471 | u8 UART0_UBXSendCFGMsg(u8* pData, u16 Len) |
472 | { |
472 | { |
473 | u32 timeout; |
473 | u32 timeout; |
474 | u8 retval = 0; |
474 | u8 retval = 0; |
475 | // if data are not a CFG MSG |
475 | // if data are not a CFG MSG |
476 | if(pData[0]!= UBX_CLASS_CFG) return(retval); |
476 | if(pData[0]!= UBX_CLASS_CFG) return(retval); |
477 | // prepare rx msg filter |
477 | // prepare rx msg filter |
478 | UbxMsg.Hdr.Class = UBX_CLASS_ACK; |
478 | UbxMsg.Hdr.Class = UBX_CLASS_ACK; |
479 | UbxMsg.Hdr.Id = 0xFF; |
479 | UbxMsg.Hdr.Id = 0xFF; |
480 | UbxMsg.Hdr.Length = 0; |
480 | UbxMsg.Hdr.Length = 0; |
481 | UbxMsg.ClassMask = 0xFF; |
481 | UbxMsg.ClassMask = 0xFF; |
482 | UbxMsg.IdMask = 0x00; |
482 | UbxMsg.IdMask = 0x00; |
483 | UbxMsg.Status = INVALID; |
483 | UbxMsg.Status = INVALID; |
484 | UART0_UBXSendMsg(pData, Len); |
484 | UART0_UBXSendMsg(pData, Len); |
485 | // check for acknowledge msg |
485 | // check for acknowledge msg |
486 | timeout = SetDelay(100); |
486 | timeout = SetDelay(100); |
487 | do |
487 | do |
488 | { |
488 | { |
489 | if(UbxMsg.Status == NEWDATA) break; |
489 | if(UbxMsg.Status == NEWDATA) break; |
490 | }while(!CheckDelay(timeout)); |
490 | }while(!CheckDelay(timeout)); |
491 | if(UbxMsg.Status == NEWDATA) |
491 | if(UbxMsg.Status == NEWDATA) |
492 | { // 2 bytes payload |
492 | { // 2 bytes payload |
493 | if((UbxMsg.Data[0] == pData[0]) && (UbxMsg.Data[1] == pData[1]) && (UbxMsg.Hdr.Length == 2)) retval = UbxMsg.Hdr.Id; |
493 | if((UbxMsg.Data[0] == pData[0]) && (UbxMsg.Data[1] == pData[1]) && (UbxMsg.Hdr.Length == 2)) retval = UbxMsg.Hdr.Id; |
494 | } |
494 | } |
495 | UbxMsg.Status = INVALID; |
495 | UbxMsg.Status = INVALID; |
496 | return(retval); |
496 | return(retval); |
497 | } |
497 | } |
498 | 498 | ||
499 | /**************************************************************/ |
499 | /**************************************************************/ |
500 | /* Get Version Info from UBX Module */ |
500 | /* Get Version Info from UBX Module */ |
501 | /**************************************************************/ |
501 | /**************************************************************/ |
502 | u8 UART0_GetUBXVersion(void) |
502 | u8 UART0_GetUBXVersion(void) |
503 | { |
503 | { |
504 | u32 timeout; |
504 | u32 timeout; |
505 | u8 msg[64]; |
505 | u8 msg[220]; |
506 | u8 retval = 0xFF; |
506 | u8 retval = 0xFF; |
507 | u8 ubxmsg[]={0x0A, 0x04, 0x00, 0x00}; //MON-VER |
507 | u8 ubxmsg[]={0x0A, 0x04, 0x00, 0x00}; //MON-VER |
508 | // prepare rx msg filter |
508 | // prepare rx msg filter |
509 | UbxMsg.Hdr.Class = 0x0A; |
509 | UbxMsg.Hdr.Class = 0x0A; |
510 | UbxMsg.Hdr.Id = 0x04; |
510 | UbxMsg.Hdr.Id = 0x04; |
511 | UbxMsg.Hdr.Length = 0; |
511 | UbxMsg.Hdr.Length = 0; |
512 | UbxMsg.ClassMask = 0xFF; |
512 | UbxMsg.ClassMask = 0xFF; |
513 | UbxMsg.IdMask = 0xFF; |
513 | UbxMsg.IdMask = 0xFF; |
514 | UbxMsg.Status = INVALID; |
514 | UbxMsg.Status = INVALID; |
515 | UART0_UBXSendMsg(ubxmsg, sizeof(ubxmsg)); |
515 | UART0_UBXSendMsg(ubxmsg, sizeof(ubxmsg)); |
516 | // check for answer |
516 | // check for answer |
517 | timeout = SetDelay(100); |
517 | timeout = SetDelay(100); |
518 | do |
518 | do |
519 | { |
519 | { |
520 | if(UbxMsg.Status == NEWDATA) break; |
520 | if(UbxMsg.Status == NEWDATA) break; |
521 | }while(!CheckDelay(timeout)); |
521 | }while(!CheckDelay(timeout)); |
522 | if((UbxMsg.Hdr.Length >= 40) && (UbxMsg.Status == NEWDATA)) |
522 | if((UbxMsg.Hdr.Length >= 40) && (UbxMsg.Status == NEWDATA)) |
523 | { |
523 | { |
524 | retval = UbxVersionParser(); |
524 | retval = UbxVersionParser(); |
525 | if(retval != 0xff) |
525 | if(retval != 0xff) |
526 | { |
526 | { |
- | 527 | /* |
|
- | 528 | unsigned int i; |
|
- | 529 | for(i=0;i< sizeof(UbxMsg.Data);i++) |
|
- | 530 | { |
|
- | 531 | if(UbxMsg.Data[i] == 0) UbxMsg.Data[i] = '°'; |
|
- | 532 | } |
|
- | 533 | //UbxMsg.Data[30] = 0; |
|
- | 534 | UbxMsg.Data[sizeof(UbxMsg.Data)-1] = 0; |
|
527 | UbxMsg.Data[4] = 0; //Only the first 4 characters |
535 | // UbxMsg.Data[4] = 0; //Only the first 4 characters |
- | 536 | */ |
|
- | 537 | ||
528 | sprintf(msg, " V%d.%d SW:%s", retval/10,retval%10, (u8*)&UbxMsg.Data[0]); |
538 | sprintf(msg, " V%d.%d (%d) SW:%s", retval/10,retval%10, GPS_Version, (u8*)&UbxMsg.Data[0]); |
529 | UART1_PutString(msg); |
539 | UART1_PutString(msg); |
- | 540 | sprintf(msg, "|%s|%s",(u8*)&UbxMsg.Data[40],(u8*)&UbxMsg.Data[40+30]); |
|
- | 541 | UART1_PutString(msg); |
|
- | 542 | ||
- | 543 | if(UbxMsg.Data[40+60]) |
|
- | 544 | { |
|
- | 545 | sprintf(msg, "\n\r %s|%s|%s",(u8*)&UbxMsg.Data[40+60],(u8*)&UbxMsg.Data[40+90],(u8*)&UbxMsg.Data[40+120]); |
|
- | 546 | UART1_PutString(msg); |
|
- | 547 | } |
|
530 | } |
548 | } |
531 | else UART1_PutString(" ! -> UNKNOWN <- ! "); |
549 | else UART1_PutString(" ! -> UNKNOWN <- ! "); |
532 | } |
550 | } |
533 | UbxMsg.Status = INVALID; |
551 | UbxMsg.Status = INVALID; |
534 | return(retval); |
552 | return(retval); |
535 | } |
553 | } |
536 | 554 | ||
537 | 555 | ||
538 | 556 | ||
539 | 557 | ||
540 | 558 | ||
541 | 559 | ||
542 | 560 | ||
543 | 561 | ||
544 | 562 | ||
545 | 563 | ||
546 | 564 | ||
547 | 565 | ||
548 | 566 | ||
549 | 567 | ||
550 | 568 | ||
551 | 569 | ||
552 | 570 | ||
553 | 571 | ||
554 | 572 |