Subversion Repositories NaviCtrl

Rev

Rev 171 | Rev 195 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 171 Rev 190
1
/*#######################################################################################*/
1
/*#######################################################################################*/
2
/* !!! THIS IS NOT FREE SOFTWARE !!!                                                     */
2
/* !!! THIS IS NOT FREE SOFTWARE !!!                                                     */
3
/*#######################################################################################*/
3
/*#######################################################################################*/
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5
// + Copyright (c) 2008 Ingo Busker, Holger Buss
5
// + Copyright (c) 2008 Ingo Busker, Holger Buss
6
// + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY
6
// + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY
7
// + FOR NON COMMERCIAL USE ONLY
7
// + FOR NON COMMERCIAL USE ONLY
8
// + www.MikroKopter.com
8
// + www.MikroKopter.com
9
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
9
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
10
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation),
10
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation),
11
// + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist.
11
// + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist.
12
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt
12
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt
13
// + bzgl. der Nutzungsbedingungen aufzunehmen.
13
// + bzgl. der Nutzungsbedingungen aufzunehmen.
14
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
14
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
15
// + Verkauf von Luftbildaufnahmen, usw.
15
// + Verkauf von Luftbildaufnahmen, usw.
16
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
16
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
17
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht,
17
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht,
18
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
18
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
19
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
19
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
20
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
20
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
21
// + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
21
// + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
22
// + eindeutig als Ursprung verlinkt werden
22
// + eindeutig als Ursprung verlinkt werden
23
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
24
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
24
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
25
// + Benutzung auf eigene Gefahr
25
// + Benutzung auf eigene Gefahr
26
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
26
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
27
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
27
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
28
// + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
28
// + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
29
// + mit unserer Zustimmung zulässig
29
// + mit unserer Zustimmung zulässig
30
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
30
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
31
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
31
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
32
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
32
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
33
// + Redistributions of source code (with or without modifications) must retain the above copyright notice,
33
// + Redistributions of source code (with or without modifications) must retain the above copyright notice,
34
// + this list of conditions and the following disclaimer.
34
// + this list of conditions and the following disclaimer.
35
// +   * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
35
// +   * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
36
// +     from this software without specific prior written permission.
36
// +     from this software without specific prior written permission.
37
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permitted
37
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permitted
38
// +     for non-commercial use (directly or indirectly)
38
// +     for non-commercial use (directly or indirectly)
39
// +     Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted
39
// +     Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted
40
// +     with our written permission
40
// +     with our written permission
41
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be
41
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be
42
// +     clearly linked as origin
42
// +     clearly linked as origin
43
// +   * porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed
43
// +   * porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed
44
//
44
//
45
// +  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
45
// +  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
46
// +  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46
// +  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
47
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
47
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
48
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
48
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
49
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
49
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
50
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
50
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
51
// +  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
51
// +  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
52
// +  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
52
// +  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
53
// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
53
// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
54
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
54
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
55
// +  POSSIBILITY OF SUCH DAMAGE.
55
// +  POSSIBILITY OF SUCH DAMAGE.
56
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
56
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
57
//#include <stdio.h>
57
//#include <stdio.h>
58
#include "91x_lib.h"
58
#include "91x_lib.h"
59
#include "config.h"
59
#include "config.h"
60
#include "uart1.h"
60
#include "uart1.h"
-
 
61
#include "mkprotocol.h"
-
 
62
 
-
 
63
// the tx buffer
-
 
64
#define UART2_TX_BUFFER_LEN  150
-
 
65
u8 UART2_tbuffer[UART2_TX_BUFFER_LEN];
-
 
66
Buffer_t UART2_tx_buffer;
61
 
67
 
62
/********************************************************/
68
/********************************************************/
63
/*                  Initialize UART2                    */
69
/*                  Initialize UART2                    */
64
/********************************************************/
70
/********************************************************/
65
void UART2_Init(void)
71
void UART2_Init(void)
66
{
72
{
67
    UART_InitTypeDef UART_InitStructure;
73
    UART_InitTypeDef UART_InitStructure;
68
        GPIO_InitTypeDef GPIO_InitStructure;
74
        GPIO_InitTypeDef GPIO_InitStructure;
69
 
75
 
70
        UART1_PutString("\r\n UART2 init...");
76
        UART1_PutString("\r\n UART2 init...");
-
 
77
 
-
 
78
        // initialize txd buffer
-
 
79
        Buffer_Init(&UART2_tx_buffer, UART2_tbuffer, UART2_TX_BUFFER_LEN);
71
 
80
 
72
        SCU_APBPeriphClockConfig(__UART2, ENABLE);  // Enable the UART2 Clock
81
        SCU_APBPeriphClockConfig(__UART2, ENABLE);  // Enable the UART2 Clock
73
 
82
 
74
        SCU_APBPeriphClockConfig(__GPIO5, ENABLE);  // Enable the GPIO5 Clock
83
        SCU_APBPeriphClockConfig(__GPIO5, ENABLE);  // Enable the GPIO5 Clock
75
    /*Configure UART2_Rx pin GPIO5.2*/
84
    /*Configure UART2_Rx pin GPIO5.2*/
76
        GPIO_StructInit(&GPIO_InitStructure);
85
        GPIO_StructInit(&GPIO_InitStructure);
77
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinInput;
86
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinInput;
78
    GPIO_InitStructure.GPIO_Pin =                       GPIO_Pin_2;
87
    GPIO_InitStructure.GPIO_Pin =                       GPIO_Pin_2;
79
    GPIO_InitStructure.GPIO_Type =                      GPIO_Type_PushPull;
88
    GPIO_InitStructure.GPIO_Type =                      GPIO_Type_PushPull;
80
    GPIO_InitStructure.GPIO_IPConnected =       GPIO_IPConnected_Enable;
89
    GPIO_InitStructure.GPIO_IPConnected =       GPIO_IPConnected_Enable;
81
    GPIO_InitStructure.GPIO_Alternate =         GPIO_InputAlt1; // UART2_RxD
90
    GPIO_InitStructure.GPIO_Alternate =         GPIO_InputAlt1; // UART2_RxD
82
    GPIO_Init(GPIO5, &GPIO_InitStructure);
91
    GPIO_Init(GPIO5, &GPIO_InitStructure);
83
 
92
 
84
        SCU_APBPeriphClockConfig(__GPIO3, ENABLE);  // Enable the GPIO3 Clock
93
        SCU_APBPeriphClockConfig(__GPIO3, ENABLE);  // Enable the GPIO3 Clock
85
    /*Configure UART2_Tx pin GPIO3.0*/
94
    /*Configure UART2_Tx pin GPIO3.0*/
86
        GPIO_StructInit(&GPIO_InitStructure);
95
        GPIO_StructInit(&GPIO_InitStructure);
87
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinOutput;
96
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinOutput;
88
    GPIO_InitStructure.GPIO_Pin =                       GPIO_Pin_0;
97
    GPIO_InitStructure.GPIO_Pin =                       GPIO_Pin_0;
89
    GPIO_InitStructure.GPIO_Type =                      GPIO_Type_PushPull;
98
    GPIO_InitStructure.GPIO_Type =                      GPIO_Type_PushPull;
90
    GPIO_InitStructure.GPIO_Alternate =         GPIO_OutputAlt2; // UART2_TX
99
    GPIO_InitStructure.GPIO_Alternate =         GPIO_OutputAlt2; // UART2_TX
91
    GPIO_Init(GPIO3, &GPIO_InitStructure);
100
    GPIO_Init(GPIO3, &GPIO_InitStructure);
92
 
101
 
93
 
102
 
94
        /* UART2 configured as follow:
103
        /* UART2 configured as follow:
95
          - Word Length = 8 Bits
104
          - Word Length = 8 Bits
96
          - One Stop Bit
105
          - One Stop Bit
97
          - No parity
106
          - No parity
98
          - BaudRate = 57600 baud
107
          - BaudRate = 57600 baud
99
          - Hardware flow control Disabled
108
          - Hardware flow control Disabled
100
          - Receive and transmit enabled
109
          - Receive and transmit enabled
101
          - Receive and transmit FIFOs are Disabled
110
          - Receive and transmit FIFOs are Disabled
102
    */
111
    */
103
        UART_StructInit(&UART_InitStructure);
112
        UART_StructInit(&UART_InitStructure);
104
    UART_InitStructure.UART_WordLength =                        UART_WordLength_8D;
113
    UART_InitStructure.UART_WordLength =                        UART_WordLength_8D;
105
    UART_InitStructure.UART_StopBits =                          UART_StopBits_1;
114
    UART_InitStructure.UART_StopBits =                          UART_StopBits_1;
106
    UART_InitStructure.UART_Parity =                            UART_Parity_No ;
115
    UART_InitStructure.UART_Parity =                            UART_Parity_No ;
107
    UART_InitStructure.UART_BaudRate =                          UART2_BAUD_RATE;
116
    UART_InitStructure.UART_BaudRate =                          UART2_BAUD_RATE;
108
    UART_InitStructure.UART_HardwareFlowControl =       UART_HardwareFlowControl_None;
117
    UART_InitStructure.UART_HardwareFlowControl =       UART_HardwareFlowControl_None;
109
    UART_InitStructure.UART_Mode =                                      UART_Mode_Tx_Rx;
118
    UART_InitStructure.UART_Mode =                                      UART_Mode_Tx_Rx;
110
    UART_InitStructure.UART_FIFO =                                      UART_FIFO_Enable;
119
    UART_InitStructure.UART_FIFO =                                      UART_FIFO_Enable;
111
    UART_InitStructure.UART_TxFIFOLevel =                       UART_FIFOLevel_1_2;
120
    UART_InitStructure.UART_TxFIFOLevel =                       UART_FIFOLevel_1_2;
112
    UART_InitStructure.UART_RxFIFOLevel =                       UART_FIFOLevel_1_2;
121
    UART_InitStructure.UART_RxFIFOLevel =                       UART_FIFOLevel_1_2;
113
 
122
 
114
        UART_DeInit(UART2);     // reset uart 2 to default
123
        UART_DeInit(UART2);     // reset uart 2 to default
115
    UART_Init(UART2, &UART_InitStructure);  // initialize uart 2
124
    UART_Init(UART2, &UART_InitStructure);  // initialize uart 2
116
 
125
 
117
        // enable uart 2 interrupts selective
126
        // enable uart 2 interrupts selective
118
    UART_ITConfig(UART2, UART_IT_Receive | UART_IT_ReceiveTimeOut, ENABLE);
127
    UART_ITConfig(UART2, UART_IT_Receive | UART_IT_ReceiveTimeOut, ENABLE);
119
        UART_Cmd(UART2, ENABLE); // enable uart 2
128
        UART_Cmd(UART2, ENABLE); // enable uart 2
120
        // configure the uart 2 interupt line
129
        // configure the uart 2 interupt line
121
        VIC_Config(UART2_ITLine, VIC_IRQ, PRIORITY_UART2);
130
        VIC_Config(UART2_ITLine, VIC_IRQ, PRIORITY_UART2);
122
        // enable the uart 2 IRQ
131
        // enable the uart 2 IRQ
123
        VIC_ITCmd(UART2_ITLine, ENABLE);
132
        VIC_ITCmd(UART2_ITLine, ENABLE);
124
 
133
 
125
        UART1_PutString("ok");
134
        UART1_PutString("ok");
126
}
135
}
127
 
136
 
128
 
137
 
129
void UART2_Deinit(void)
138
void UART2_Deinit(void)
130
{
139
{
131
        GPIO_InitTypeDef GPIO_InitStructure;
140
        GPIO_InitTypeDef GPIO_InitStructure;
132
 
141
 
133
        UART1_PutString("\r\n UART2 deinit...");
142
        UART1_PutString("\r\n UART2 deinit...");
134
        VIC_ITCmd(UART2_ITLine, DISABLE); // disable the uart 2 IRQ
143
        VIC_ITCmd(UART2_ITLine, DISABLE); // disable the uart 2 IRQ
135
        UART_Cmd(UART2, DISABLE); // disable uart 2
144
        UART_Cmd(UART2, DISABLE); // disable uart 2
136
        UART_DeInit(UART2);     // reset uart 0 to default
145
        UART_DeInit(UART2);     // reset uart 0 to default
137
 
146
 
138
        SCU_APBPeriphClockConfig(__UART2, DISABLE);  // disable the UART2 Clock
147
        SCU_APBPeriphClockConfig(__UART2, DISABLE);  // disable the UART2 Clock
139
 
148
 
140
        SCU_APBPeriphClockConfig(__GPIO5, ENABLE);
149
        SCU_APBPeriphClockConfig(__GPIO5, ENABLE);
141
        // unmap UART2 from FC
150
        // unmap UART2 from FC
142
        // set port pin 5.2 (serial data from FC) to input and disconnect from IP
151
        // set port pin 5.2 (serial data from FC) to input and disconnect from IP
143
        GPIO_StructInit(&GPIO_InitStructure);
152
        GPIO_StructInit(&GPIO_InitStructure);
144
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinInput;
153
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinInput;
145
    GPIO_InitStructure.GPIO_Pin =                       GPIO_Pin_2;
154
    GPIO_InitStructure.GPIO_Pin =                       GPIO_Pin_2;
146
    GPIO_InitStructure.GPIO_Type =                      GPIO_Type_PushPull;
155
    GPIO_InitStructure.GPIO_Type =                      GPIO_Type_PushPull;
147
    GPIO_InitStructure.GPIO_IPConnected =       GPIO_IPConnected_Disable;
156
    GPIO_InitStructure.GPIO_IPConnected =       GPIO_IPConnected_Disable;
148
    GPIO_InitStructure.GPIO_Alternate =         GPIO_InputAlt1;
157
    GPIO_InitStructure.GPIO_Alternate =         GPIO_InputAlt1;
149
    GPIO_Init(GPIO5, &GPIO_InitStructure);
158
    GPIO_Init(GPIO5, &GPIO_InitStructure);
150
 
159
 
151
        SCU_APBPeriphClockConfig(__GPIO3, ENABLE);
160
        SCU_APBPeriphClockConfig(__GPIO3, ENABLE);
152
        // set port pin 3.0 (serial data to FC) to input and disconnect from IP
161
        // set port pin 3.0 (serial data to FC) to input and disconnect from IP
153
        GPIO_StructInit(&GPIO_InitStructure);
162
        GPIO_StructInit(&GPIO_InitStructure);
154
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinInput;
163
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinInput;
155
    GPIO_InitStructure.GPIO_Pin =                       GPIO_Pin_0;
164
    GPIO_InitStructure.GPIO_Pin =                       GPIO_Pin_0;
156
    GPIO_InitStructure.GPIO_Type =                      GPIO_Type_PushPull;
165
    GPIO_InitStructure.GPIO_Type =                      GPIO_Type_PushPull;
157
        GPIO_InitStructure.GPIO_IPConnected =   GPIO_IPConnected_Disable;
166
        GPIO_InitStructure.GPIO_IPConnected =   GPIO_IPConnected_Disable;
158
    GPIO_InitStructure.GPIO_Alternate =         GPIO_InputAlt1;
167
    GPIO_InitStructure.GPIO_Alternate =         GPIO_InputAlt1;
159
    GPIO_Init(GPIO3, &GPIO_InitStructure);
168
    GPIO_Init(GPIO3, &GPIO_InitStructure);
160
 
169
 
161
        UART1_PutString("ok");
170
        UART1_PutString("ok");
162
}
171
}
163
 
172
 
164
/********************************************************/
173
/********************************************************/
165
/*            UART2 Interrupt Handler                   */
174
/*            UART2 Interrupt Handler                   */
166
/********************************************************/
175
/********************************************************/
167
void UART2_IRQHandler(void)
176
void UART2_IRQHandler(void)
168
{
177
{
169
        // if receive irq or receive timeout irq has occured
178
        // if receive irq or receive timeout irq has occured
170
        if((UART_GetITStatus(UART2, UART_IT_Receive) != RESET) || (UART_GetITStatus(UART2, UART_IT_ReceiveTimeOut) != RESET) )
179
        if((UART_GetITStatus(UART2, UART_IT_Receive) != RESET) || (UART_GetITStatus(UART2, UART_IT_ReceiveTimeOut) != RESET) )
171
        {
180
        {
172
                UART_ClearITPendingBit(UART2, UART_IT_Receive);                 // clear receive interrupt flag
181
                UART_ClearITPendingBit(UART2, UART_IT_Receive);                 // clear receive interrupt flag
173
                UART_ClearITPendingBit(UART2, UART_IT_ReceiveTimeOut);  // clear receive timeout interrupt flag
182
                UART_ClearITPendingBit(UART2, UART_IT_ReceiveTimeOut);  // clear receive timeout interrupt flag
174
 
183
 
175
                // if debug UART is UART2
184
                // if debug UART is UART2
176
                if (DebugUART == UART2)
185
                if (DebugUART == UART2)
177
                {       // forward received data to the UART1 tx buffer
186
                {       // forward received data to the UART1 tx buffer
178
                        while(UART_GetFlagStatus(UART2, UART_FLAG_RxFIFOEmpty) != SET)
187
                        while(UART_GetFlagStatus(UART2, UART_FLAG_RxFIFOEmpty) != SET)
179
                        {
188
                        {
180
                                // wait for space in the tx buffer of the UART1
189
                                // wait for space in the tx buffer of the UART1
181
                                while(UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) == SET) {};
190
                                while(UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) == SET) {};
182
                                // move the byte from the rx buffer of UART2 to the tx buffer of UART1
191
                                // move the byte from the rx buffer of UART2 to the tx buffer of UART1
183
                                UART_SendData(UART1, UART_ReceiveData(UART2));
192
                                UART_SendData(UART1, UART_ReceiveData(UART2));
184
                        }
193
                        }
185
                }
194
                }
186
                else
195
                else
187
                {
196
                {
188
                        // ignore serial data from the FC
197
                        // ignore serial data from the FC
189
                        while(UART_GetFlagStatus(UART2, UART_FLAG_RxFIFOEmpty) != SET)
198
                        while(UART_GetFlagStatus(UART2, UART_FLAG_RxFIFOEmpty) != SET)
-
 
199
                        {
190
                        UART_ReceiveData(UART2);
200
                                UART_ReceiveData(UART2);
-
 
201
                        }
191
                }
202
                }
192
        } // eof receive irq or receive timeout irq
203
        } // eof receive irq or receive timeout irq
193
}
204
}
-
 
205
 
-
 
206
/**************************************************************/
-
 
207
/*         Transmit tx buffer via uart2                       */
-
 
208
/**************************************************************/
-
 
209
void UART2_Transmit(void)
-
 
210
{
-
 
211
        u8 tmp_tx;
-
 
212
        if(DebugUART == UART2) return; // no data output if debug uart is rederected to UART2
-
 
213
        // if something has to be send and the txd fifo is not full
-
 
214
        if((UART2_tx_buffer.Locked == TRUE) && (UART_GetFlagStatus(UART2, UART_FLAG_TxFIFOFull) == RESET))
-
 
215
        {
-
 
216
                tmp_tx = UART2_tx_buffer.pData[UART2_tx_buffer.Position++]; // read next byte from txd buffer
-
 
217
                UART_SendData(UART2, tmp_tx); // put character to txd fifo
-
 
218
                // if terminating character or end of txd buffer reached
-
 
219
                if((tmp_tx == '\r') || (UART2_tx_buffer.Position == UART2_tx_buffer.Size))
-
 
220
                {
-
 
221
                        Buffer_Clear(&UART2_tx_buffer);
-
 
222
                }
-
 
223
        }
-
 
224
}
-
 
225
 
-
 
226
/**************************************************************/
-
 
227
/* Send the answers to incomming commands at the uart2        */
-
 
228
/**************************************************************/
-
 
229
void UART2_TransmitTxData(void)
-
 
230
{
-
 
231
        if(DebugUART == UART2) return;
-
 
232
        UART2_Transmit(); // output pending bytes in tx buffer
-
 
233
}
-
 
234
 
-
 
235
 
-
 
236
void UART2_ProcessRxData(void)
-
 
237
{
-
 
238
 
-
 
239
}
194
 
240