Rev 380 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 380 | Rev 580 | ||
---|---|---|---|
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 "91x_lib.h" |
57 | #include "91x_lib.h" |
58 | #include "config.h" |
58 | #include "config.h" |
59 | #include "uart1.h" |
59 | #include "uart1.h" |
60 | #include "mkprotocol.h" |
60 | #include "mkprotocol.h" |
61 | 61 | ||
62 | // the tx buffer |
62 | // the tx buffer |
63 | #define UART2_TX_BUFFER_LEN 150 |
63 | #define UART2_TX_BUFFER_LEN 150 |
64 | u8 UART2_tbuffer[UART2_TX_BUFFER_LEN]; |
64 | u8 UART2_tbuffer[UART2_TX_BUFFER_LEN]; |
65 | Buffer_t UART2_tx_buffer; |
65 | Buffer_t UART2_tx_buffer; |
66 | 66 | ||
67 | /********************************************************/ |
67 | /********************************************************/ |
68 | /* Initialize UART2 */ |
68 | /* Initialize UART2 */ |
69 | /********************************************************/ |
69 | /********************************************************/ |
70 | void UART2_Init(void) |
70 | void UART2_Init(void) |
71 | { |
71 | { |
72 | UART_InitTypeDef UART_InitStructure; |
72 | UART_InitTypeDef UART_InitStructure; |
73 | GPIO_InitTypeDef GPIO_InitStructure; |
73 | GPIO_InitTypeDef GPIO_InitStructure; |
74 | 74 | ||
75 | UART1_PutString("\r\n UART2 init..."); |
75 | // UART1_PutString("\r\n UART2 init..."); |
76 | 76 | ||
77 | // initialize txd buffer |
77 | // initialize txd buffer |
78 | Buffer_Init(&UART2_tx_buffer, UART2_tbuffer, UART2_TX_BUFFER_LEN); |
78 | Buffer_Init(&UART2_tx_buffer, UART2_tbuffer, UART2_TX_BUFFER_LEN); |
79 | 79 | ||
80 | SCU_APBPeriphClockConfig(__UART2, ENABLE); // Enable the UART2 Clock |
80 | SCU_APBPeriphClockConfig(__UART2, ENABLE); // Enable the UART2 Clock |
81 | 81 | ||
82 | SCU_APBPeriphClockConfig(__GPIO5, ENABLE); // Enable the GPIO5 Clock |
82 | SCU_APBPeriphClockConfig(__GPIO5, ENABLE); // Enable the GPIO5 Clock |
83 | /*Configure UART2_Rx pin GPIO5.2*/ |
83 | /*Configure UART2_Rx pin GPIO5.2*/ |
84 | GPIO_StructInit(&GPIO_InitStructure); |
84 | GPIO_StructInit(&GPIO_InitStructure); |
85 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
85 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
86 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; |
86 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; |
87 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
87 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
88 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable; |
88 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable; |
89 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; // UART2_RxD |
89 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; // UART2_RxD |
90 | GPIO_Init(GPIO5, &GPIO_InitStructure); |
90 | GPIO_Init(GPIO5, &GPIO_InitStructure); |
91 | 91 | ||
92 | SCU_APBPeriphClockConfig(__GPIO3, ENABLE); // Enable the GPIO3 Clock |
92 | SCU_APBPeriphClockConfig(__GPIO3, ENABLE); // Enable the GPIO3 Clock |
93 | /*Configure UART2_Tx pin GPIO3.0*/ |
93 | /*Configure UART2_Tx pin GPIO3.0*/ |
94 | GPIO_StructInit(&GPIO_InitStructure); |
94 | GPIO_StructInit(&GPIO_InitStructure); |
95 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
95 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
96 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; |
96 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; |
97 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
97 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
98 | GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt2; // UART2_TX |
98 | GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt2; // UART2_TX |
99 | GPIO_Init(GPIO3, &GPIO_InitStructure); |
99 | GPIO_Init(GPIO3, &GPIO_InitStructure); |
100 | 100 | ||
101 | 101 | ||
102 | /* UART2 configured as follow: |
102 | /* UART2 configured as follow: |
103 | - Word Length = 8 Bits |
103 | - Word Length = 8 Bits |
104 | - One Stop Bit |
104 | - One Stop Bit |
105 | - No parity |
105 | - No parity |
106 | - BaudRate = 57600 baud |
106 | - BaudRate = 57600 baud |
107 | - Hardware flow control Disabled |
107 | - Hardware flow control Disabled |
108 | - Receive and transmit enabled |
108 | - Receive and transmit enabled |
109 | - Receive and transmit FIFOs are Disabled |
109 | - Receive and transmit FIFOs are Disabled |
110 | */ |
110 | */ |
111 | UART_StructInit(&UART_InitStructure); |
111 | UART_StructInit(&UART_InitStructure); |
112 | UART_InitStructure.UART_WordLength = UART_WordLength_8D; |
112 | UART_InitStructure.UART_WordLength = UART_WordLength_8D; |
113 | UART_InitStructure.UART_StopBits = UART_StopBits_1; |
113 | UART_InitStructure.UART_StopBits = UART_StopBits_1; |
114 | UART_InitStructure.UART_Parity = UART_Parity_No ; |
114 | UART_InitStructure.UART_Parity = UART_Parity_No ; |
115 | UART_InitStructure.UART_BaudRate = UART2_BAUD_RATE; |
115 | UART_InitStructure.UART_BaudRate = UART2_BAUD_RATE; |
116 | UART_InitStructure.UART_HardwareFlowControl = UART_HardwareFlowControl_None; |
116 | UART_InitStructure.UART_HardwareFlowControl = UART_HardwareFlowControl_None; |
117 | UART_InitStructure.UART_Mode = UART_Mode_Tx_Rx; |
117 | UART_InitStructure.UART_Mode = UART_Mode_Tx_Rx; |
118 | UART_InitStructure.UART_FIFO = UART_FIFO_Enable; |
118 | UART_InitStructure.UART_FIFO = UART_FIFO_Enable; |
119 | UART_InitStructure.UART_TxFIFOLevel = UART_FIFOLevel_1_2; |
119 | UART_InitStructure.UART_TxFIFOLevel = UART_FIFOLevel_1_2; |
120 | UART_InitStructure.UART_RxFIFOLevel = UART_FIFOLevel_1_2; |
120 | UART_InitStructure.UART_RxFIFOLevel = UART_FIFOLevel_1_2; |
121 | 121 | ||
122 | UART_DeInit(UART2); // reset uart 2 to default |
122 | UART_DeInit(UART2); // reset uart 2 to default |
123 | UART_Init(UART2, &UART_InitStructure); // initialize uart 2 |
123 | UART_Init(UART2, &UART_InitStructure); // initialize uart 2 |
124 | 124 | ||
125 | // enable uart 2 interrupts selective |
125 | // enable uart 2 interrupts selective |
126 | UART_ITConfig(UART2, UART_IT_Receive | UART_IT_ReceiveTimeOut, ENABLE); |
126 | UART_ITConfig(UART2, UART_IT_Receive | UART_IT_ReceiveTimeOut, ENABLE); |
127 | UART_Cmd(UART2, ENABLE); // enable uart 2 |
127 | UART_Cmd(UART2, ENABLE); // enable uart 2 |
128 | // configure the uart 2 interupt line |
128 | // configure the uart 2 interupt line |
129 | VIC_Config(UART2_ITLine, VIC_IRQ, PRIORITY_UART2); |
129 | VIC_Config(UART2_ITLine, VIC_IRQ, PRIORITY_UART2); |
130 | // enable the uart 2 IRQ |
130 | // enable the uart 2 IRQ |
131 | VIC_ITCmd(UART2_ITLine, ENABLE); |
131 | VIC_ITCmd(UART2_ITLine, ENABLE); |
132 | 132 | ||
133 | UART1_PutString("ok"); |
133 | // UART1_PutString("ok"); |
134 | } |
134 | } |
135 | 135 | ||
136 | 136 | ||
137 | void UART2_Deinit(void) |
137 | void UART2_Deinit(void) |
138 | { |
138 | { |
139 | GPIO_InitTypeDef GPIO_InitStructure; |
139 | GPIO_InitTypeDef GPIO_InitStructure; |
140 | 140 | ||
141 | UART1_PutString("\r\n UART2 deinit..."); |
141 | UART1_PutString("\r\n UART2 deinit..."); |
142 | VIC_ITCmd(UART2_ITLine, DISABLE); // disable the uart 2 IRQ |
142 | VIC_ITCmd(UART2_ITLine, DISABLE); // disable the uart 2 IRQ |
143 | UART_Cmd(UART2, DISABLE); // disable uart 2 |
143 | UART_Cmd(UART2, DISABLE); // disable uart 2 |
144 | UART_DeInit(UART2); // reset uart 0 to default |
144 | UART_DeInit(UART2); // reset uart 0 to default |
145 | 145 | ||
146 | SCU_APBPeriphClockConfig(__UART2, DISABLE); // disable the UART2 Clock |
146 | SCU_APBPeriphClockConfig(__UART2, DISABLE); // disable the UART2 Clock |
147 | 147 | ||
148 | SCU_APBPeriphClockConfig(__GPIO5, ENABLE); |
148 | SCU_APBPeriphClockConfig(__GPIO5, ENABLE); |
149 | // unmap UART2 from FC |
149 | // unmap UART2 from FC |
150 | // set port pin 5.2 (serial data from FC) to input and disconnect from IP |
150 | // set port pin 5.2 (serial data from FC) to input and disconnect from IP |
151 | GPIO_StructInit(&GPIO_InitStructure); |
151 | GPIO_StructInit(&GPIO_InitStructure); |
152 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
152 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
153 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; |
153 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; |
154 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
154 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
155 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Disable; |
155 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Disable; |
156 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; |
156 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; |
157 | GPIO_Init(GPIO5, &GPIO_InitStructure); |
157 | GPIO_Init(GPIO5, &GPIO_InitStructure); |
158 | 158 | ||
159 | SCU_APBPeriphClockConfig(__GPIO3, ENABLE); |
159 | SCU_APBPeriphClockConfig(__GPIO3, ENABLE); |
160 | // set port pin 3.0 (serial data to FC) to input and disconnect from IP |
160 | // set port pin 3.0 (serial data to FC) to input and disconnect from IP |
161 | GPIO_StructInit(&GPIO_InitStructure); |
161 | GPIO_StructInit(&GPIO_InitStructure); |
162 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
162 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
163 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; |
163 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; |
164 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
164 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
165 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Disable; |
165 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Disable; |
166 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; |
166 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; |
167 | GPIO_Init(GPIO3, &GPIO_InitStructure); |
167 | GPIO_Init(GPIO3, &GPIO_InitStructure); |
168 | 168 | ||
169 | UART1_PutString("ok"); |
169 | UART1_PutString("ok"); |
170 | } |
170 | } |
171 | 171 | ||
172 | /********************************************************/ |
172 | /********************************************************/ |
173 | /* UART2 Interrupt Handler */ |
173 | /* UART2 Interrupt Handler */ |
174 | /********************************************************/ |
174 | /********************************************************/ |
175 | void UART2_IRQHandler(void) |
175 | void UART2_IRQHandler(void) |
176 | { |
176 | { |
177 | 177 | ||
178 | 178 | ||
179 | // if receive irq or receive timeout irq has occured |
179 | // if receive irq or receive timeout irq has occured |
180 | if((UART_GetITStatus(UART2, UART_IT_Receive) != RESET) || (UART_GetITStatus(UART2, UART_IT_ReceiveTimeOut) != RESET) ) |
180 | if((UART_GetITStatus(UART2, UART_IT_Receive) != RESET) || (UART_GetITStatus(UART2, UART_IT_ReceiveTimeOut) != RESET) ) |
181 | { |
181 | { |
182 | UART_ClearITPendingBit(UART2, UART_IT_Receive); // clear receive interrupt flag |
182 | UART_ClearITPendingBit(UART2, UART_IT_Receive); // clear receive interrupt flag |
183 | UART_ClearITPendingBit(UART2, UART_IT_ReceiveTimeOut); // clear receive timeout interrupt flag |
183 | UART_ClearITPendingBit(UART2, UART_IT_ReceiveTimeOut); // clear receive timeout interrupt flag |
184 | 184 | ||
185 | // if debug UART is UART2 |
185 | // if debug UART is UART2 |
186 | if (DebugUART == UART2) |
186 | if (DebugUART == UART2) |
187 | { // forward received data to the UART1 tx buffer |
187 | { // forward received data to the UART1 tx buffer |
188 | while(UART_GetFlagStatus(UART2, UART_FLAG_RxFIFOEmpty) != SET) |
188 | while(UART_GetFlagStatus(UART2, UART_FLAG_RxFIFOEmpty) != SET) |
189 | { |
189 | { |
190 | // wait for space in the tx buffer of the UART1 |
190 | // wait for space in the tx buffer of the UART1 |
191 | while(UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) == SET) {}; |
191 | while(UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) == SET) {}; |
192 | // move the byte from the rx buffer of UART2 to the tx buffer of UART1 |
192 | // move the byte from the rx buffer of UART2 to the tx buffer of UART1 |
193 | UART_SendData(UART1, UART_ReceiveData(UART2)); |
193 | UART_SendData(UART1, UART_ReceiveData(UART2)); |
194 | } |
194 | } |
195 | } |
195 | } |
196 | else |
196 | else |
197 | { |
197 | { |
198 | // ignore serial data from the FC |
198 | // ignore serial data from the FC |
199 | while(UART_GetFlagStatus(UART2, UART_FLAG_RxFIFOEmpty) != SET) |
199 | while(UART_GetFlagStatus(UART2, UART_FLAG_RxFIFOEmpty) != SET) |
200 | { |
200 | { |
201 | UART_ReceiveData(UART2); |
201 | UART_ReceiveData(UART2); |
202 | } |
202 | } |
203 | } |
203 | } |
204 | } // eof receive irq or receive timeout irq |
204 | } // eof receive irq or receive timeout irq |
205 | 205 | ||
206 | 206 | ||
207 | VIC1->VAR = 0xFF; // write any value to VIC1 Vector address register |
207 | VIC1->VAR = 0xFF; // write any value to VIC1 Vector address register |
208 | } |
208 | } |
209 | 209 | ||
210 | /**************************************************************/ |
210 | /**************************************************************/ |
211 | /* Transmit tx buffer via uart2 */ |
211 | /* Transmit tx buffer via uart2 */ |
212 | /**************************************************************/ |
212 | /**************************************************************/ |
213 | void UART2_Transmit(void) |
213 | void UART2_Transmit(void) |
214 | { |
214 | { |
215 | u8 tmp_tx; |
215 | u8 tmp_tx; |
216 | if(DebugUART == UART2) return; // no data output if debug uart is rederected to UART2 |
216 | if(DebugUART == UART2) return; // no data output if debug uart is rederected to UART2 |
217 | // if something has to be send and the txd fifo is not full |
217 | // if something has to be send and the txd fifo is not full |
218 | if((UART2_tx_buffer.Locked == TRUE) && (UART_GetFlagStatus(UART2, UART_FLAG_TxFIFOFull) == RESET)) |
218 | if((UART2_tx_buffer.Locked == TRUE) && (UART_GetFlagStatus(UART2, UART_FLAG_TxFIFOFull) == RESET)) |
219 | { |
219 | { |
220 | tmp_tx = UART2_tx_buffer.pData[UART2_tx_buffer.Position++]; // read next byte from txd buffer |
220 | tmp_tx = UART2_tx_buffer.pData[UART2_tx_buffer.Position++]; // read next byte from txd buffer |
221 | UART_SendData(UART2, tmp_tx); // put character to txd fifo |
221 | UART_SendData(UART2, tmp_tx); // put character to txd fifo |
222 | // if terminating character or end of txd buffer reached |
222 | // if terminating character or end of txd buffer reached |
223 | if((tmp_tx == '\r') || (UART2_tx_buffer.Position == UART2_tx_buffer.Size)) |
223 | if((tmp_tx == '\r') || (UART2_tx_buffer.Position == UART2_tx_buffer.Size)) |
224 | { |
224 | { |
225 | Buffer_Clear(&UART2_tx_buffer); |
225 | Buffer_Clear(&UART2_tx_buffer); |
226 | } |
226 | } |
227 | } |
227 | } |
228 | } |
228 | } |
229 | 229 | ||
230 | /**************************************************************/ |
230 | /**************************************************************/ |
231 | /* Send the answers to incomming commands at the uart2 */ |
231 | /* Send the answers to incomming commands at the uart2 */ |
232 | /**************************************************************/ |
232 | /**************************************************************/ |
233 | void UART2_TransmitTxData(void) |
233 | void UART2_TransmitTxData(void) |
234 | { |
234 | { |
235 | if(DebugUART == UART2) return; |
235 | if(DebugUART == UART2) return; |
236 | UART2_Transmit(); // output pending bytes in tx buffer |
236 | UART2_Transmit(); // output pending bytes in tx buffer |
237 | } |
237 | } |
238 | 238 | ||
239 | 239 | ||
240 | void UART2_ProcessRxData(void) |
240 | void UART2_ProcessRxData(void) |
241 | { |
241 | { |
242 | 242 | ||
243 | } |
243 | } |
244 | 244 |