Rev 23 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 23 | Rev 171 | ||
---|---|---|---|
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 |
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 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 this software (or part of it) to systems (other than 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 | 57 | ||
58 | #include "main.h" |
58 | #include "main.h" |
59 | 59 | ||
60 | u8 DebugGetAnforderung = 0,DebugDisplayAnforderung = 0,DebugDataAnforderung = 0,GetVersionAnforderung = 0; |
60 | u8 DebugGetAnforderung = 0,DebugDisplayAnforderung = 0,DebugDataAnforderung = 0,GetVersionAnforderung = 0; |
61 | unsigned volatile char SioTmp = 0; |
61 | unsigned volatile char SioTmp = 0; |
62 | unsigned volatile char SendeBuffer[MAX_SENDE_BUFF]; |
62 | unsigned volatile char SendeBuffer[MAX_SENDE_BUFF]; |
63 | unsigned volatile char RxdBuffer[MAX_EMPFANGS_BUFF]; |
63 | unsigned volatile char RxdBuffer[MAX_EMPFANGS_BUFF]; |
64 | unsigned volatile char NMEABuffer[MAX_EMPFANGS_BUFF]; |
64 | unsigned volatile char NMEABuffer[MAX_EMPFANGS_BUFF]; |
65 | unsigned volatile char NeuerDatensatzEmpfangen = 0; |
65 | unsigned volatile char NeuerDatensatzEmpfangen = 0; |
66 | unsigned volatile char NeueKoordinateEmpfangen = 0; |
66 | unsigned volatile char NeueKoordinateEmpfangen = 0; |
67 | unsigned volatile char UebertragungAbgeschlossen = 1; |
67 | unsigned volatile char UebertragungAbgeschlossen = 1; |
68 | unsigned volatile char SendGPSPosAnforderung = 0; |
68 | unsigned volatile char SendGPSPosAnforderung = 0; |
69 | unsigned volatile char CntCrcError = 0; |
69 | unsigned volatile char CntCrcError = 0; |
70 | unsigned volatile char AnzahlEmpfangsBytes = 0; |
70 | unsigned volatile char AnzahlEmpfangsBytes = 0; |
71 | unsigned volatile char PC_DebugTimeout = 0; |
71 | unsigned volatile char PC_DebugTimeout = 0; |
72 | volatile unsigned char DebugTextAnforderung = 255; |
72 | volatile unsigned char DebugTextAnforderung = 255; |
73 | unsigned char NurKanalAnforderung = 0; |
73 | unsigned char NurKanalAnforderung = 0; |
74 | 74 | ||
75 | UART_TypeDef *DebugUART = UART1; |
75 | UART_TypeDef *DebugUART = UART1; |
76 | 76 | ||
77 | unsigned char RemotePollDisplayLine = 0; |
77 | unsigned char RemotePollDisplayLine = 0; |
78 | u8 PcZugriff = 100; |
78 | u8 PcZugriff = 100; |
79 | u8 MotorTest[4] = {0,0,0,0}; |
79 | u8 MotorTest[4] = {0,0,0,0}; |
80 | u8 MeineSlaveAdresse; |
80 | u8 MeineSlaveAdresse; |
81 | volatile struct str_DebugOut DebugOut; |
81 | volatile struct str_DebugOut DebugOut; |
82 | struct str_ExternControl ExternControl; |
82 | struct str_ExternControl ExternControl; |
83 | struct str_GPSPosition GPS_Position; |
83 | struct str_GPSPosition GPS_Position; |
84 | struct str_VersionInfo VersionInfo; |
84 | struct str_VersionInfo VersionInfo; |
85 | struct str_PCTargetGPSPosition PCTargetGPSPosition; |
85 | struct str_PCTargetGPSPosition PCTargetGPSPosition; |
86 | s32 Debug_Timer; |
86 | s32 Debug_Timer; |
87 | static u16 ptr = 0; |
87 | static u16 ptr = 0; |
88 | unsigned char ConfirmFrame; |
88 | unsigned char ConfirmFrame; |
89 | 89 | ||
90 | #define FIFO_TX_LEVEL 2 |
90 | #define FIFO_TX_LEVEL 2 |
91 | 91 | ||
92 | UART_InitTypeDef UART_InitStructure; |
92 | UART_InitTypeDef UART_InitStructure; |
93 | 93 | ||
94 | const unsigned char ANALOG_TEXT[32][16] = |
94 | const unsigned char ANALOG_TEXT[32][16] = |
95 | { |
95 | { |
96 | //1234567890123456 |
96 | //1234567890123456 |
97 | "WinkelNick ", //0 |
97 | "WinkelNick ", //0 |
98 | "WinkelRoll ", |
98 | "WinkelRoll ", |
99 | "AccNick ", |
99 | "AccNick ", |
100 | "AccRoll ", |
100 | "AccRoll ", |
101 | "AN4 ", |
101 | "AN4 ", |
102 | "AN5 ", //5 |
102 | "AN5 ", //5 |
103 | "GPS-Data Counter", |
103 | "GPS-Data Counter", |
104 | "7 ", |
104 | "7 ", |
105 | "8 ", |
105 | "8 ", |
106 | "9 ", |
106 | "9 ", |
107 | "10 ", //10 |
107 | "10 ", //10 |
108 | "Poti1 ", |
108 | "Poti1 ", |
109 | "SPI Error ", |
109 | "SPI Error ", |
110 | "SPI Okay ", |
110 | "SPI Okay ", |
111 | "Poti2 ", |
111 | "Poti2 ", |
112 | "Poti3 ", //15 |
112 | "Poti3 ", //15 |
113 | "I2C_ReadByte ", |
113 | "I2C_ReadByte ", |
114 | "ACC_Speed_N ", |
114 | "ACC_Speed_N ", |
115 | "ACC_Speed_E ", |
115 | "ACC_Speed_E ", |
116 | " ", |
116 | " ", |
117 | " ", //20 |
117 | " ", //20 |
118 | // "Distance_N ", |
118 | // "Distance_N ", |
119 | // "Distance_E ", //20 |
119 | // "Distance_E ", //20 |
120 | "N_Speed ", |
120 | "N_Speed ", |
121 | "E_Speed ", |
121 | "E_Speed ", |
122 | "I_North ", |
122 | "I_North ", |
123 | "I_East ", |
123 | "I_East ", |
124 | "GyroKompass ", //25 |
124 | "GyroKompass ", //25 |
125 | "Heading ", |
125 | "Heading ", |
126 | // "Distance2Target ", |
126 | // "Distance2Target ", |
127 | // "Direction2Target", |
127 | // "Direction2Target", |
128 | "Distance N ", |
128 | "Distance N ", |
129 | "Distance E ", |
129 | "Distance E ", |
130 | "GPS_NICK ", |
130 | "GPS_NICK ", |
131 | "GPS_ROLL ", //30 |
131 | "GPS_ROLL ", //30 |
132 | "Used_Sat " |
132 | "Used_Sat " |
133 | }; |
133 | }; |
134 | 134 | ||
135 | 135 | ||
136 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
136 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
137 | //++ Sende- und Empfangs-Part der Datenübertragung, incl. CRC-Auswertung |
137 | //++ Sende- und Empfangs-Part der Datenübertragung, incl. CRC-Auswertung |
138 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
138 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
139 | void UART1_IRQHandler(void) |
139 | void UART1_IRQHandler(void) |
140 | { |
140 | { |
141 | // ---------------------------- Receive ------------------------------------ |
141 | // ---------------------------- Receive ------------------------------------ |
142 | 142 | ||
143 | if((UART_GetITStatus(UART1, UART_IT_Receive) != RESET)|| (UART_GetITStatus(UART1, UART_IT_ReceiveTimeOut) != RESET) ) |
143 | if((UART_GetITStatus(UART1, UART_IT_Receive) != RESET)|| (UART_GetITStatus(UART1, UART_IT_ReceiveTimeOut) != RESET) ) |
144 | { |
144 | { |
145 | static u16 crc; |
145 | static u16 crc; |
146 | static u8 crc1,crc2,buf_ptr; |
146 | static u8 crc1,crc2,buf_ptr; |
147 | static u8 UartState = 0; |
147 | static u8 UartState = 0; |
148 | u8 CrcOkay = 0; |
148 | u8 CrcOkay = 0; |
149 | 149 | ||
150 | if (DebugUART != UART1) |
150 | if (DebugUART != UART1) |
151 | { |
151 | { |
152 | while (UART_GetFlagStatus(UART1, UART_FLAG_RxFIFOEmpty) != SET) |
152 | while (UART_GetFlagStatus(UART1, UART_FLAG_RxFIFOEmpty) != SET) |
153 | UART_SendData(DebugUART, UART_ReceiveData(UART1)); |
153 | UART_SendData(DebugUART, UART_ReceiveData(UART1)); |
154 | } |
154 | } |
155 | else |
155 | else |
156 | while ((UART_GetFlagStatus(UART1, UART_FLAG_RxFIFOEmpty) != SET)&& (!NeuerDatensatzEmpfangen)) |
156 | while ((UART_GetFlagStatus(UART1, UART_FLAG_RxFIFOEmpty) != SET)&& (!NeuerDatensatzEmpfangen)) |
157 | { |
157 | { |
158 | 158 | ||
159 | SioTmp = UART_ReceiveData(UART1); |
159 | SioTmp = UART_ReceiveData(UART1); |
160 | 160 | ||
161 | 161 | ||
162 | if(buf_ptr >= MAX_EMPFANGS_BUFF) UartState = 0; |
162 | if(buf_ptr >= MAX_EMPFANGS_BUFF) UartState = 0; |
163 | if(SioTmp == '\r' && UartState == 2) |
163 | if(SioTmp == '\r' && UartState == 2) |
164 | { |
164 | { |
165 | UartState = 0; |
165 | UartState = 0; |
166 | crc -= RxdBuffer[buf_ptr-2]; |
166 | crc -= RxdBuffer[buf_ptr-2]; |
167 | crc -= RxdBuffer[buf_ptr-1]; |
167 | crc -= RxdBuffer[buf_ptr-1]; |
168 | crc %= 4096; |
168 | crc %= 4096; |
169 | crc1 = '=' + crc / 64; |
169 | crc1 = '=' + crc / 64; |
170 | crc2 = '=' + crc % 64; |
170 | crc2 = '=' + crc % 64; |
171 | CrcOkay = 0; |
171 | CrcOkay = 0; |
172 | if((crc1 == RxdBuffer[buf_ptr-2]) && (crc2 == RxdBuffer[buf_ptr-1])) CrcOkay = 1; else { CrcOkay = 0; CntCrcError++;}; |
172 | if((crc1 == RxdBuffer[buf_ptr-2]) && (crc2 == RxdBuffer[buf_ptr-1])) CrcOkay = 1; else { CrcOkay = 0; CntCrcError++;}; |
173 | if(!NeuerDatensatzEmpfangen && CrcOkay) // Datensatz schon verarbeitet |
173 | if(!NeuerDatensatzEmpfangen && CrcOkay) // Datensatz schon verarbeitet |
174 | { |
174 | { |
175 | NeuerDatensatzEmpfangen = 1; |
175 | NeuerDatensatzEmpfangen = 1; |
176 | 176 | ||
177 | // GPIO_ToggleBit(GPIO6, GPIO_Pin_2); |
177 | // GPIO_ToggleBit(GPIO6, GPIO_Pin_2); |
178 | 178 | ||
179 | AnzahlEmpfangsBytes = buf_ptr; |
179 | AnzahlEmpfangsBytes = buf_ptr; |
180 | RxdBuffer[buf_ptr] = '\r'; |
180 | RxdBuffer[buf_ptr] = '\r'; |
181 | if(RxdBuffer[2] == 'R') |
181 | if(RxdBuffer[2] == 'R') |
182 | { |
182 | { |
183 | PowerOff(); |
183 | PowerOff(); |
184 | VIC_DeInit(); |
184 | VIC_DeInit(); |
185 | Execute_Bootloader(); // Reset-Commando - Bootloader starten |
185 | Execute_Bootloader(); // Reset-Commando - Bootloader starten |
186 | } |
186 | } |
187 | // while (UART_GetFlagStatus(UART1, UART_FLAG_RxFIFOEmpty) != SET) SioTmp = UART_ReceiveData(UART1); |
187 | // while (UART_GetFlagStatus(UART1, UART_FLAG_RxFIFOEmpty) != SET) SioTmp = UART_ReceiveData(UART1); |
188 | 188 | ||
189 | //BearbeiteRxDaten(); |
189 | //BearbeiteRxDaten(); |
190 | break; |
190 | break; |
191 | } |
191 | } |
192 | } |
192 | } |
193 | else |
193 | else |
194 | switch(UartState) |
194 | switch(UartState) |
195 | { |
195 | { |
196 | case 0: |
196 | case 0: |
197 | if(SioTmp == '#' && !NeuerDatensatzEmpfangen) UartState = 1; // Startzeichen und Daten schon verarbeitet |
197 | if(SioTmp == '#' && !NeuerDatensatzEmpfangen) UartState = 1; // Startzeichen und Daten schon verarbeitet |
198 | buf_ptr = 0; |
198 | buf_ptr = 0; |
199 | RxdBuffer[buf_ptr++] = SioTmp; |
199 | RxdBuffer[buf_ptr++] = SioTmp; |
200 | crc = SioTmp; |
200 | crc = SioTmp; |
201 | break; |
201 | break; |
202 | case 1: // Adresse auswerten |
202 | case 1: // Adresse auswerten |
203 | UartState++; |
203 | UartState++; |
204 | RxdBuffer[buf_ptr++] = SioTmp; |
204 | RxdBuffer[buf_ptr++] = SioTmp; |
205 | crc += SioTmp; |
205 | crc += SioTmp; |
206 | break; |
206 | break; |
207 | case 2: // Eingangsdaten sammeln |
207 | case 2: // Eingangsdaten sammeln |
208 | RxdBuffer[buf_ptr] = SioTmp; |
208 | RxdBuffer[buf_ptr] = SioTmp; |
209 | if(buf_ptr < MAX_EMPFANGS_BUFF) buf_ptr++; |
209 | if(buf_ptr < MAX_EMPFANGS_BUFF) buf_ptr++; |
210 | else UartState = 0; |
210 | else UartState = 0; |
211 | crc += SioTmp; |
211 | crc += SioTmp; |
212 | break; |
212 | break; |
213 | default: |
213 | default: |
214 | UartState = 0; |
214 | UartState = 0; |
215 | break; |
215 | break; |
216 | } |
216 | } |
217 | 217 | ||
218 | 218 | ||
219 | } |
219 | } |
220 | 220 | ||
221 | } |
221 | } |
222 | 222 | ||
223 | UART_ClearITPendingBit(UART1, UART_IT_Receive); |
223 | UART_ClearITPendingBit(UART1, UART_IT_Receive); |
224 | UART_ClearITPendingBit(UART1, UART_IT_ReceiveTimeOut); |
224 | UART_ClearITPendingBit(UART1, UART_IT_ReceiveTimeOut); |
225 | 225 | ||
226 | } |
226 | } |
227 | 227 | ||
228 | // -------------------------------------------------------------------------- |
228 | // -------------------------------------------------------------------------- |
229 | void UART1_Transmit(void) |
229 | void UART1_Transmit(void) |
230 | { |
230 | { |
231 | u8 tmp_tx; |
231 | u8 tmp_tx; |
232 | 232 | ||
233 | if((!UebertragungAbgeschlossen) && (UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) == RESET)) |
233 | if((!UebertragungAbgeschlossen) && (UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) == RESET)) |
234 | { |
234 | { |
235 | 235 | ||
236 | tmp_tx = SendeBuffer[ptr]; |
236 | tmp_tx = SendeBuffer[ptr]; |
237 | 237 | ||
238 | if((tmp_tx == '\r') || (ptr == MAX_SENDE_BUFF)) |
238 | if((tmp_tx == '\r') || (ptr == MAX_SENDE_BUFF)) |
239 | { |
239 | { |
240 | ptr = 0; |
240 | ptr = 0; |
241 | UebertragungAbgeschlossen = 1; |
241 | UebertragungAbgeschlossen = 1; |
242 | } |
242 | } |
243 | 243 | ||
244 | UART_SendData(UART1, tmp_tx); |
244 | UART_SendData(UART1, tmp_tx); |
245 | 245 | ||
246 | ptr++; |
246 | ptr++; |
247 | } |
247 | } |
248 | } |
248 | } |
249 | 249 | ||
250 | // -------------------------------------------------------------------------- |
250 | // -------------------------------------------------------------------------- |
251 | void AddCRC(u16 wieviele) |
251 | void AddCRC(u16 wieviele) |
252 | { |
252 | { |
253 | u16 tmpCRC = 0,i; |
253 | u16 tmpCRC = 0,i; |
254 | //u8 count = FIFO_TX_LEVEL + 2 ; |
254 | //u8 count = FIFO_TX_LEVEL + 2 ; |
255 | 255 | ||
256 | for(i = 0; i < wieviele;i++) |
256 | for(i = 0; i < wieviele;i++) |
257 | { |
257 | { |
258 | tmpCRC += SendeBuffer[i]; |
258 | tmpCRC += SendeBuffer[i]; |
259 | } |
259 | } |
260 | tmpCRC %= 4096; |
260 | tmpCRC %= 4096; |
261 | SendeBuffer[i++] = '=' + tmpCRC / 64; |
261 | SendeBuffer[i++] = '=' + tmpCRC / 64; |
262 | SendeBuffer[i++] = '=' + tmpCRC % 64; |
262 | SendeBuffer[i++] = '=' + tmpCRC % 64; |
263 | SendeBuffer[i++] = '\r'; |
263 | SendeBuffer[i++] = '\r'; |
264 | 264 | ||
265 | 265 | ||
266 | ptr = 0; |
266 | ptr = 0; |
267 | 267 | ||
268 | 268 | ||
269 | // USB_Send_Data((u8 *) SendeBuffer,i); |
269 | // USB_Send_Data((u8 *) SendeBuffer,i); |
270 | 270 | ||
271 | { |
271 | { |
272 | UART_SendData(UART1,SendeBuffer[ptr++]); |
272 | UART_SendData(UART1,SendeBuffer[ptr++]); |
273 | UebertragungAbgeschlossen = 0; |
273 | UebertragungAbgeschlossen = 0; |
274 | 274 | ||
275 | } |
275 | } |
276 | } |
276 | } |
277 | 277 | ||
278 | 278 | ||
279 | 279 | ||
280 | // -------------------------------------------------------------------------- |
280 | // -------------------------------------------------------------------------- |
281 | void SendOutData(u8 cmd,u8 modul, u8 *snd, u8 len) |
281 | void SendOutData(u8 cmd,u8 modul, u8 *snd, u8 len) |
282 | { |
282 | { |
283 | u16 pt = 0; |
283 | u16 pt = 0; |
284 | u8 a,b,c; |
284 | u8 a,b,c; |
285 | u8 ptr = 0; |
285 | u8 ptr = 0; |
286 | 286 | ||
287 | SendeBuffer[pt++] = '#'; // Startzeichen |
287 | SendeBuffer[pt++] = '#'; // Startzeichen |
288 | SendeBuffer[pt++] = modul; // Adresse (a=0; b=1,...) |
288 | SendeBuffer[pt++] = modul; // Adresse (a=0; b=1,...) |
289 | SendeBuffer[pt++] = cmd; // Commando |
289 | SendeBuffer[pt++] = cmd; // Commando |
290 | 290 | ||
291 | while(len) |
291 | while(len) |
292 | { |
292 | { |
293 | if(len) { a = snd[ptr++]; len--;} else a = 0; |
293 | if(len) { a = snd[ptr++]; len--;} else a = 0; |
294 | if(len) { b = snd[ptr++]; len--;} else b = 0; |
294 | if(len) { b = snd[ptr++]; len--;} else b = 0; |
295 | if(len) { c = snd[ptr++]; len--;} else c = 0; |
295 | if(len) { c = snd[ptr++]; len--;} else c = 0; |
296 | SendeBuffer[pt++] = '=' + (a >> 2); |
296 | SendeBuffer[pt++] = '=' + (a >> 2); |
297 | SendeBuffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4)); |
297 | SendeBuffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4)); |
298 | SendeBuffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6)); |
298 | SendeBuffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6)); |
299 | SendeBuffer[pt++] = '=' + ( c & 0x3f); |
299 | SendeBuffer[pt++] = '=' + ( c & 0x3f); |
300 | } |
300 | } |
301 | AddCRC(pt); |
301 | AddCRC(pt); |
302 | } |
302 | } |
303 | 303 | ||
304 | 304 | ||
305 | // -------------------------------------------------------------------------- |
305 | // -------------------------------------------------------------------------- |
306 | void Decode64(u8 *ptrOut, u8 len, u8 ptrIn,u8 max) // Wohin mit den Daten; Wie lang; Wo im RxdBuffer |
306 | void Decode64(u8 *ptrOut, u8 len, u8 ptrIn,u8 max) // Wohin mit den Daten; Wie lang; Wo im RxdBuffer |
307 | { |
307 | { |
308 | u8 a,b,c,d; |
308 | u8 a,b,c,d; |
309 | u8 ptr = 0; |
309 | u8 ptr = 0; |
310 | u8 x,y,z; |
310 | u8 x,y,z; |
311 | while(len) |
311 | while(len) |
312 | { |
312 | { |
313 | a = RxdBuffer[ptrIn++] - '='; |
313 | a = RxdBuffer[ptrIn++] - '='; |
314 | b = RxdBuffer[ptrIn++] - '='; |
314 | b = RxdBuffer[ptrIn++] - '='; |
315 | c = RxdBuffer[ptrIn++] - '='; |
315 | c = RxdBuffer[ptrIn++] - '='; |
316 | d = RxdBuffer[ptrIn++] - '='; |
316 | d = RxdBuffer[ptrIn++] - '='; |
317 | if(ptrIn > max - 2) break; // nicht mehr Daten verarbeiten, als empfangen wurden |
317 | if(ptrIn > max - 2) break; // nicht mehr Daten verarbeiten, als empfangen wurden |
318 | 318 | ||
319 | x = (a << 2) | (b >> 4); |
319 | x = (a << 2) | (b >> 4); |
320 | y = ((b & 0x0f) << 4) | (c >> 2); |
320 | y = ((b & 0x0f) << 4) | (c >> 2); |
321 | z = ((c & 0x03) << 6) | d; |
321 | z = ((c & 0x03) << 6) | d; |
322 | 322 | ||
323 | if(len--) ptrOut[ptr++] = x; else break; |
323 | if(len--) ptrOut[ptr++] = x; else break; |
324 | if(len--) ptrOut[ptr++] = y; else break; |
324 | if(len--) ptrOut[ptr++] = y; else break; |
325 | if(len--) ptrOut[ptr++] = z; else break; |
325 | if(len--) ptrOut[ptr++] = z; else break; |
326 | } |
326 | } |
327 | 327 | ||
328 | } |
328 | } |
329 | 329 | ||
330 | // -------------------------------------------------------------------------- |
330 | // -------------------------------------------------------------------------- |
331 | void BearbeiteRxDaten(void) |
331 | void BearbeiteRxDaten(void) |
332 | { |
332 | { |
333 | if(!NeuerDatensatzEmpfangen) return; |
333 | if(!NeuerDatensatzEmpfangen) return; |
334 | 334 | ||
335 | // u16 tmp_int_arr1[1]; |
335 | // u16 tmp_int_arr1[1]; |
336 | // u16 tmp_int_arr2[2]; |
336 | // u16 tmp_int_arr2[2]; |
337 | // u16 tmp_int_arr3[3]; |
337 | // u16 tmp_int_arr3[3]; |
338 | u8 tmp_char_arr2[2]; |
338 | u8 tmp_char_arr2[2]; |
339 | s32 tmp_long_arr2[2]; |
339 | s32 tmp_long_arr2[2]; |
340 | // u8 tmp_char_arr3[3]; |
340 | // u8 tmp_char_arr3[3]; |
341 | // u8 tmp_char_arr4[4]; |
341 | // u8 tmp_char_arr4[4]; |
342 | //if(!MotorenEin) |
342 | //if(!MotorenEin) |
343 | PcZugriff = 255; |
343 | PcZugriff = 255; |
344 | switch(RxdBuffer[2]) |
344 | switch(RxdBuffer[2]) |
345 | { |
345 | { |
346 | case 'a':// Texte der Analogwerte |
346 | case 'a':// Texte der Analogwerte |
347 | Decode64((unsigned char *) &tmp_char_arr2[0],sizeof(tmp_char_arr2),3,AnzahlEmpfangsBytes); |
347 | Decode64((unsigned char *) &tmp_char_arr2[0],sizeof(tmp_char_arr2),3,AnzahlEmpfangsBytes); |
348 | DebugTextAnforderung = tmp_char_arr2[0]; |
348 | DebugTextAnforderung = tmp_char_arr2[0]; |
349 | break; |
349 | break; |
350 | case 'b': |
350 | case 'b': |
351 | Decode64((unsigned char *) &ExternControl,sizeof(ExternControl),3,AnzahlEmpfangsBytes); |
351 | Decode64((unsigned char *) &ExternControl,sizeof(ExternControl),3,AnzahlEmpfangsBytes); |
352 | RemoteTasten |= ExternControl.RemoteTasten; |
352 | RemoteTasten |= ExternControl.RemoteTasten; |
353 | ConfirmFrame = ExternControl.Frame; |
353 | ConfirmFrame = ExternControl.Frame; |
354 | break; |
354 | break; |
355 | case 'c': |
355 | case 'c': |
356 | Decode64((unsigned char *) &ExternControl,sizeof(ExternControl),3,AnzahlEmpfangsBytes); |
356 | Decode64((unsigned char *) &ExternControl,sizeof(ExternControl),3,AnzahlEmpfangsBytes); |
357 | RemoteTasten |= ExternControl.RemoteTasten; |
357 | RemoteTasten |= ExternControl.RemoteTasten; |
358 | ConfirmFrame = ExternControl.Frame; |
358 | ConfirmFrame = ExternControl.Frame; |
359 | DebugDataAnforderung = 1; |
359 | DebugDataAnforderung = 1; |
360 | break; |
360 | break; |
361 | case 'h':// x-1 Displayzeilen |
361 | case 'h':// x-1 Displayzeilen |
362 | Decode64((unsigned char *) &tmp_char_arr2[0],sizeof(tmp_char_arr2),3,AnzahlEmpfangsBytes); |
362 | Decode64((unsigned char *) &tmp_char_arr2[0],sizeof(tmp_char_arr2),3,AnzahlEmpfangsBytes); |
363 | RemoteTasten |= tmp_char_arr2[0]; |
363 | RemoteTasten |= tmp_char_arr2[0]; |
364 | if(tmp_char_arr2[1] == 255) NurKanalAnforderung = 1; else NurKanalAnforderung = 0; // keine Displaydaten |
364 | if(tmp_char_arr2[1] == 255) NurKanalAnforderung = 1; else NurKanalAnforderung = 0; // keine Displaydaten |
365 | DebugDisplayAnforderung = 1; |
365 | DebugDisplayAnforderung = 1; |
366 | break; |
366 | break; |
367 | case 't':// Motortest |
367 | case 't':// Motortest |
368 | Decode64((unsigned char *) &MotorTest[0],sizeof(MotorTest),3,AnzahlEmpfangsBytes); |
368 | Decode64((unsigned char *) &MotorTest[0],sizeof(MotorTest),3,AnzahlEmpfangsBytes); |
369 | break; |
369 | break; |
370 | case 's':// neue PCTargetGPSPosition |
370 | case 's':// neue PCTargetGPSPosition |
371 | Decode64((unsigned char *) &tmp_long_arr2[0],sizeof(tmp_long_arr2),3,AnzahlEmpfangsBytes); |
371 | Decode64((unsigned char *) &tmp_long_arr2[0],sizeof(tmp_long_arr2),3,AnzahlEmpfangsBytes); |
372 | PCTargetGPSPosition.Longitude = tmp_long_arr2[0]; |
372 | PCTargetGPSPosition.Longitude = tmp_long_arr2[0]; |
373 | PCTargetGPSPosition.Latitude = tmp_long_arr2[1]; |
373 | PCTargetGPSPosition.Latitude = tmp_long_arr2[1]; |
374 | NewPCTargetGPSPosition = 1; |
374 | NewPCTargetGPSPosition = 1; |
375 | break; |
375 | break; |
376 | case 'k':// Keys von DubWise |
376 | case 'k':// Keys von DubWise |
377 | // Decode64((unsigned char *) &DubWiseKeys[0],sizeof(DubWiseKeys),3,AnzahlEmpfangsBytes); |
377 | // Decode64((unsigned char *) &DubWiseKeys[0],sizeof(DubWiseKeys),3,AnzahlEmpfangsBytes); |
378 | ConfirmFrame = 1; |
378 | ConfirmFrame = 1; |
379 | break; |
379 | break; |
380 | case 'v': // Version-Anforderung und Ausbaustufe |
380 | case 'v': // Version-Anforderung und Ausbaustufe |
381 | GetVersionAnforderung = 1; |
381 | GetVersionAnforderung = 1; |
382 | break; |
382 | break; |
383 | case 'g':// "Get"-Anforderung für Debug-Daten |
383 | case 'g':// "Get"-Anforderung für Debug-Daten |
384 | // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
384 | // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
385 | DebugGetAnforderung = 1; |
385 | DebugGetAnforderung = 1; |
386 | break; |
386 | break; |
387 | 387 | ||
388 | case 'l': |
388 | case 'l': |
389 | case 'm': |
389 | case 'm': |
390 | case 'n': |
390 | case 'n': |
391 | case 'o': |
391 | case 'o': |
392 | case 'p': // Parametersatz speichern |
392 | case 'p': // Parametersatz speichern |
393 | /* Decode64((u8 *) &EE_Parameter.Kanalbelegung[0],STRUCT_PARAM_LAENGE,3,AnzahlEmpfangsBytes); |
393 | /* Decode64((u8 *) &EE_Parameter.Kanalbelegung[0],STRUCT_PARAM_LAENGE,3,AnzahlEmpfangsBytes); |
394 | WriteParameterSet(RxdBuffer[2] - 'l' + 1, (u8 *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
394 | WriteParameterSet(RxdBuffer[2] - 'l' + 1, (u8 *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
395 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], RxdBuffer[2] - 'l' + 1); // aktiven Datensatz merken |
395 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], RxdBuffer[2] - 'l' + 1); // aktiven Datensatz merken |
396 | Piep(GetActiveParamSetNumber());*/ |
396 | Piep(GetActiveParamSetNumber());*/ |
397 | break; |
397 | break; |
398 | 398 | ||
399 | 399 | ||
400 | } |
400 | } |
401 | // DebugOut.AnzahlZyklen = Debug_Timer_Intervall; |
401 | // DebugOut.AnzahlZyklen = Debug_Timer_Intervall; |
402 | NeuerDatensatzEmpfangen = 0; |
402 | NeuerDatensatzEmpfangen = 0; |
403 | 403 | ||
404 | } |
404 | } |
405 | 405 | ||
406 | 406 | ||
407 | //############################################################################ |
407 | //############################################################################ |
408 | //Routine für die Serielle Ausgabe |
408 | //Routine für die Serielle Ausgabe |
409 | s16 uart_putchar (char c) |
409 | s16 uart_putchar (char c) |
410 | //############################################################################ |
410 | //############################################################################ |
411 | { |
411 | { |
412 | if (c == '\n') |
412 | if (c == '\n') |
413 | uart_putchar('\r'); |
413 | uart_putchar('\r'); |
414 | 414 | ||
415 | while (UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) != RESET); |
415 | while (UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) != RESET); |
416 | UART_SendData(UART1, c); |
416 | UART_SendData(UART1, c); |
417 | 417 | ||
418 | return (0); |
418 | return (0); |
419 | } |
419 | } |
420 | // -------------------------------------------------------------------------- |
420 | // -------------------------------------------------------------------------- |
421 | void SerialPutString(u8 *s) |
421 | void SerialPutString(u8 *s) |
422 | { |
422 | { |
423 | while (*s != '\0') |
423 | while (*s != '\0') |
424 | { |
424 | { |
425 | uart_putchar(*s); |
425 | uart_putchar(*s); |
426 | s ++; |
426 | s ++; |
427 | } |
427 | } |
428 | } |
428 | } |
429 | 429 | ||
430 | //############################################################################ |
430 | //############################################################################ |
431 | //Init der Seriellen Schnittstelle |
431 | //Init der Seriellen Schnittstelle |
432 | void Debug_UART1_Init (void) |
432 | void Debug_UART1_Init (void) |
433 | //############################################################################ |
433 | //############################################################################ |
434 | { |
434 | { |
435 | GPIO_InitTypeDef GPIO_InitStructure; |
435 | GPIO_InitTypeDef GPIO_InitStructure; |
436 | 436 | ||
437 | SCU_APBPeriphClockConfig(__UART1, ENABLE); // Enable the UART1 Clock |
437 | SCU_APBPeriphClockConfig(__UART1, ENABLE); // Enable the UART1 Clock |
438 | SCU_APBPeriphClockConfig(__GPIO3, ENABLE); // Enable the GPIO3 Clock |
438 | SCU_APBPeriphClockConfig(__GPIO3, ENABLE); // Enable the GPIO3 Clock |
439 | 439 | ||
440 | /*Configure UART1_Rx pin GPIO3.2*/ |
440 | /*Configure UART1_Rx pin GPIO3.2*/ |
441 | GPIO_DeInit(GPIO3); |
441 | GPIO_DeInit(GPIO3); |
442 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
442 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
443 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; |
443 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; |
444 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
444 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
445 | GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable; |
445 | GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable; |
446 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1 ; |
446 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1 ; |
447 | GPIO_Init(GPIO3, &GPIO_InitStructure); |
447 | GPIO_Init(GPIO3, &GPIO_InitStructure); |
448 | 448 | ||
449 | /*Configure UART1_Tx pin GPIO3.3*/ |
449 | /*Configure UART1_Tx pin GPIO3.3*/ |
450 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
450 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
451 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; |
451 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; |
452 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
452 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
453 | GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt2 ; |
453 | GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt2 ; |
454 | GPIO_Init(GPIO3, &GPIO_InitStructure); |
454 | GPIO_Init(GPIO3, &GPIO_InitStructure); |
455 | 455 | ||
456 | /* UART1 configured as follow: |
456 | /* UART1 configured as follow: |
457 | - Word Length = 8 Bits |
457 | - Word Length = 8 Bits |
458 | - One Stop Bit |
458 | - One Stop Bit |
459 | - No parity |
459 | - No parity |
460 | - BaudRate = 57600 baud |
460 | - BaudRate = 57600 baud |
461 | - Hardware flow control Disabled |
461 | - Hardware flow control Disabled |
462 | - Receive and transmit enabled |
462 | - Receive and transmit enabled |
463 | - Receive and transmit FIFOs are Disabled |
463 | - Receive and transmit FIFOs are Disabled |
464 | */ |
464 | */ |
465 | UART_InitStructure.UART_WordLength = UART_WordLength_8D; |
465 | UART_InitStructure.UART_WordLength = UART_WordLength_8D; |
466 | UART_InitStructure.UART_StopBits = UART_StopBits_1; |
466 | UART_InitStructure.UART_StopBits = UART_StopBits_1; |
467 | UART_InitStructure.UART_Parity = UART_Parity_No ; |
467 | UART_InitStructure.UART_Parity = UART_Parity_No ; |
468 | UART_InitStructure.UART_BaudRate = BAUD_RATE ; |
468 | UART_InitStructure.UART_BaudRate = BAUD_RATE ; |
469 | UART_InitStructure. UART_HardwareFlowControl = UART_HardwareFlowControl_None; |
469 | UART_InitStructure. UART_HardwareFlowControl = UART_HardwareFlowControl_None; |
470 | UART_InitStructure.UART_Mode = UART_Mode_Tx_Rx; |
470 | UART_InitStructure.UART_Mode = UART_Mode_Tx_Rx; |
471 | //UART_InitStructure.UART_FIFO = UART_FIFO_Disable; |
471 | //UART_InitStructure.UART_FIFO = UART_FIFO_Disable; |
472 | UART_InitStructure.UART_FIFO = UART_FIFO_Enable; |
472 | UART_InitStructure.UART_FIFO = UART_FIFO_Enable; |
473 | UART_InitStructure.UART_TxFIFOLevel = UART_FIFOLevel_1_2; |
473 | UART_InitStructure.UART_TxFIFOLevel = UART_FIFOLevel_1_2; |
474 | UART_InitStructure.UART_RxFIFOLevel = UART_FIFOLevel_1_2; |
474 | UART_InitStructure.UART_RxFIFOLevel = UART_FIFOLevel_1_2; |
475 | 475 | ||
476 | UART_DeInit(UART1); |
476 | UART_DeInit(UART1); |
477 | UART_Init(UART1, &UART_InitStructure); |
477 | UART_Init(UART1, &UART_InitStructure); |
478 | 478 | ||
479 | UART_ITConfig(UART1, UART_IT_Receive | UART_IT_ReceiveTimeOut /*| UART_IT_Transmit */, ENABLE); |
479 | UART_ITConfig(UART1, UART_IT_Receive | UART_IT_ReceiveTimeOut /*| UART_IT_Transmit */, ENABLE); |
480 | //UART_ITConfig(UART1, UART_IT_Receive , ENABLE); |
480 | //UART_ITConfig(UART1, UART_IT_Receive , ENABLE); |
481 | 481 | ||
482 | 482 | ||
483 | 483 | ||
484 | UART_Cmd(UART1, ENABLE); |
484 | UART_Cmd(UART1, ENABLE); |
485 | 485 | ||
486 | VIC_Config(UART1_ITLine, VIC_IRQ, 4); |
486 | VIC_Config(UART1_ITLine, VIC_IRQ, 4); |
487 | VIC_ITCmd(UART1_ITLine, ENABLE); |
487 | VIC_ITCmd(UART1_ITLine, ENABLE); |
488 | 488 | ||
489 | Debug_Timer = SetDelay(3000); |
489 | Debug_Timer = SetDelay(3000); |
490 | //---------------------------------------- |
490 | //---------------------------------------- |
491 | 491 | ||
492 | 492 | ||
493 | } |
493 | } |
494 | 494 | ||
495 | 495 | ||
496 | //--------------------------------------------------------------------------------------------- |
496 | //--------------------------------------------------------------------------------------------- |
497 | void DatenUebertragung(void) |
497 | void DatenUebertragung(void) |
498 | { |
498 | { |
499 | 499 | ||
500 | if(!UebertragungAbgeschlossen) return; |
500 | if(!UebertragungAbgeschlossen) return; |
501 | 501 | ||
502 | if(DebugGetAnforderung && UebertragungAbgeschlossen) // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
502 | if(DebugGetAnforderung && UebertragungAbgeschlossen) // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
503 | { |
503 | { |
504 | SendOutData('G',MeineSlaveAdresse,(unsigned char *) &ExternControl,sizeof(ExternControl)); |
504 | SendOutData('G',MeineSlaveAdresse,(unsigned char *) &ExternControl,sizeof(ExternControl)); |
505 | DebugGetAnforderung = 0; |
505 | DebugGetAnforderung = 0; |
506 | } |
506 | } |
507 | 507 | ||
508 | if((CheckDelay(Debug_Timer) || DebugDataAnforderung) && UebertragungAbgeschlossen) |
508 | if((CheckDelay(Debug_Timer) || DebugDataAnforderung) && UebertragungAbgeschlossen) |
509 | { |
509 | { |
510 | SendOutData('D',MeineSlaveAdresse,(unsigned char *) &DebugOut,sizeof(DebugOut)); |
510 | SendOutData('D',MeineSlaveAdresse,(unsigned char *) &DebugOut,sizeof(DebugOut)); |
511 | DebugDataAnforderung = 0; |
511 | DebugDataAnforderung = 0; |
512 | Debug_Timer = SetDelay(2000); |
512 | Debug_Timer = SetDelay(2000); |
513 | } |
513 | } |
514 | if(DebugTextAnforderung != 255) // Texte für die Analogdaten |
514 | if(DebugTextAnforderung != 255) // Texte für die Analogdaten |
515 | { |
515 | { |
516 | SendOutData('A',DebugTextAnforderung + '0',(unsigned char *) ANALOG_TEXT[DebugTextAnforderung],16); |
516 | SendOutData('A',DebugTextAnforderung + '0',(unsigned char *) ANALOG_TEXT[DebugTextAnforderung],16); |
517 | DebugTextAnforderung = 255; |
517 | DebugTextAnforderung = 255; |
518 | } |
518 | } |
519 | if(DebugDisplayAnforderung && UebertragungAbgeschlossen) |
519 | if(DebugDisplayAnforderung && UebertragungAbgeschlossen) |
520 | { |
520 | { |
521 | Menu(); |
521 | Menu(); |
522 | DebugDisplayAnforderung = 0; |
522 | DebugDisplayAnforderung = 0; |
523 | if(++RemotePollDisplayLine == 4 || NurKanalAnforderung) |
523 | if(++RemotePollDisplayLine == 4 || NurKanalAnforderung) |
524 | { |
524 | { |
525 | SendOutData('4',0,(unsigned char *) &VersionInfo,sizeof(VersionInfo)); // DisplayZeile übertragen |
525 | SendOutData('4',0,(unsigned char *) &VersionInfo,sizeof(VersionInfo)); // DisplayZeile übertragen |
526 | RemotePollDisplayLine = -1; |
526 | RemotePollDisplayLine = -1; |
527 | } |
527 | } |
528 | else SendOutData('0' + RemotePollDisplayLine,0,(unsigned char *)&DisplayBuff[20 * RemotePollDisplayLine],20); // DisplayZeile übertragen |
528 | else SendOutData('0' + RemotePollDisplayLine,0,(unsigned char *)&DisplayBuff[20 * RemotePollDisplayLine],20); // DisplayZeile übertragen |
529 | } |
529 | } |
530 | if(GetVersionAnforderung && UebertragungAbgeschlossen) |
530 | if(GetVersionAnforderung && UebertragungAbgeschlossen) |
531 | { |
531 | { |
532 | SendOutData('V',MeineSlaveAdresse,(unsigned char *) &VersionInfo,sizeof(VersionInfo)); |
532 | SendOutData('V',MeineSlaveAdresse,(unsigned char *) &VersionInfo,sizeof(VersionInfo)); |
533 | GetVersionAnforderung = 0; |
533 | GetVersionAnforderung = 0; |
534 | } |
534 | } |
535 | if(SendGPSPosAnforderung && UebertragungAbgeschlossen) |
535 | if(SendGPSPosAnforderung && UebertragungAbgeschlossen) |
536 | { |
536 | { |
537 | SendOutData('Q',MeineSlaveAdresse,(unsigned char *) &GPS_Position,sizeof(GPS_Position)); |
537 | SendOutData('Q',MeineSlaveAdresse,(unsigned char *) &GPS_Position,sizeof(GPS_Position)); |
538 | SendGPSPosAnforderung = 0; |
538 | SendGPSPosAnforderung = 0; |
539 | } |
539 | } |
540 | 540 | ||
541 | } |
541 | } |
542 | 542 | ||
543 | 543 |