Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
90 | gunterl | 1 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 | // + Copyright (c) 04.2007 Holger Buss |
||
3 | // + Copyright (c) 12.2007 Gunter Logemann (Roboboard extensions, serial control) |
||
4 | // + only for non-profit use |
||
5 | // + www.MikroKopter.com |
||
6 | // + see the File "License.txt" for further Informations |
||
7 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
8 | |||
9 | #include "main.h" |
||
10 | #include "uart.h" |
||
11 | |||
12 | unsigned char DebugGetAnforderung = 0,DebugDisplayAnforderung = 0,DebugDataAnforderung = 0,GetVersionAnforderung = 0; |
||
13 | unsigned volatile char SioTmp = 0; |
||
14 | unsigned volatile char SendeBuffer[MAX_SENDE_BUFF]; |
||
15 | unsigned volatile char RxdBuffer[MAX_EMPFANGS_BUFF]; |
||
16 | unsigned volatile char NMEABuffer[MAX_EMPFANGS_BUFF]; |
||
17 | unsigned volatile char NeuerDatensatzEmpfangen = 0; |
||
18 | unsigned volatile char NeueKoordinateEmpfangen = 0; |
||
19 | unsigned volatile char UebertragungAbgeschlossen = 1; |
||
20 | unsigned volatile char CntCrcError = 0; |
||
21 | unsigned volatile char AnzahlEmpfangsBytes = 0; |
||
22 | unsigned volatile char PC_DebugTimeout = 0; |
||
23 | unsigned char RemotePollDisplayLine = 0; |
||
24 | unsigned char NurKanalAnforderung = 0; |
||
25 | unsigned char DebugTextAnforderung = 255; |
||
26 | unsigned char PcZugriff = 100; |
||
27 | unsigned char MotorTest[4] = {0,0,0,0}; |
||
28 | unsigned char DubWiseKeys[3] = {0,0,0}; |
||
29 | unsigned char MeineSlaveAdresse; |
||
30 | struct str_DebugOut DebugOut; |
||
31 | struct str_Debug DebugIn; |
||
32 | struct str_VersionInfo VersionInfo; |
||
33 | int Debug_Timer; |
||
34 | |||
35 | unsigned volatile char SioTmp1 = 0; |
||
36 | unsigned volatile char SendeBuffer1[MAX_SENDE_BUFF]; |
||
37 | unsigned volatile char RxdBuffer1[MAX_EMPFANGS_BUFF]; |
||
38 | unsigned volatile char NeuerDatensatzEmpfangen1 = 0; |
||
39 | unsigned volatile char AnzahlEmpfangsBytes1 = 0; |
||
40 | unsigned volatile char UebertragungAbgeschlossen1 = 1; |
||
41 | |||
42 | struct str_ControlIn ControlIn; |
||
43 | struct str_ControlOut ControlOut; |
||
44 | unsigned volatile char ControlReceived = 0; |
||
45 | |||
46 | |||
47 | const unsigned char ANALOG_TEXT[32][16] = |
||
48 | { |
||
49 | //1234567890123456 |
||
50 | "IntegralNick ", //0 |
||
51 | "IntegralRoll ", |
||
52 | "AccNick ", |
||
53 | "AccRoll ", |
||
54 | "GyroGier ", |
||
55 | "HoehenWert ", //5 |
||
56 | "AccZ ", |
||
57 | "Gas ", |
||
58 | "KompassValue ", |
||
59 | "Spannung ", |
||
60 | "Empfang ", //10 |
||
61 | "11 --- ", |
||
62 | "Motor_Vorne ", |
||
63 | "Motor_Hinten ", |
||
64 | "Motor_Links ", |
||
65 | "Motor_Rechts ", //15 |
||
66 | "16_Acc_Z ", |
||
67 | "17MittelAccNick ", |
||
68 | "18_MittelAccRoll", |
||
69 | "Analog19 ", |
||
70 | "IntegralErrRoll ", //20 |
||
71 | "Analog21 ", |
||
72 | "22_MittelGIngR ", |
||
73 | "Analog23 ", |
||
74 | "24RollOffset ", |
||
75 | "25IntRoll*Fakt ", //25 |
||
76 | "Analog26 ", |
||
77 | "DirektAusglRoll ", |
||
78 | "28MesswertRoll ", |
||
79 | "29AusgleichRoll ", |
||
80 | "30_I-LageRoll ", //30 |
||
81 | "31_StickRoll " |
||
82 | }; |
||
83 | |||
84 | |||
85 | |||
86 | // 2. Seriell Schnittstelle |
||
87 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
88 | //++ Sende-Part der Datenübertragung an zweiten UART |
||
89 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
90 | SIGNAL(INT_VEC_TX1) |
||
91 | { |
||
92 | static unsigned int ptr1 = 0; |
||
93 | unsigned char tmp_tx1; |
||
94 | if(!UebertragungAbgeschlossen1) |
||
95 | { |
||
96 | ptr1++; // die [0] wurde schon gesendet |
||
97 | tmp_tx1 = SendeBuffer1[ptr1]; |
||
98 | if((tmp_tx1 == '\r') || (ptr1 == MAX_SENDE_BUFF)) |
||
99 | { |
||
100 | ptr1 = 0; |
||
101 | UebertragungAbgeschlossen1 = 1; |
||
102 | } |
||
103 | UDR1 = tmp_tx1; |
||
104 | } |
||
105 | else ptr1 = 0; |
||
106 | } |
||
107 | |||
108 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
109 | //++ Empfangs-Part der Datenübertragung von zweitem UART |
||
110 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
111 | SIGNAL(INT_VEC_RX1) |
||
112 | { |
||
113 | static unsigned char buf_ptr1; |
||
114 | static unsigned char UartState1 = 0; |
||
115 | SioTmp1 = UDR1; |
||
116 | if(buf_ptr1 >= MAX_EMPFANGS_BUFF) UartState1 = 0; |
||
117 | if(SioTmp1 == '\r' && UartState1 == 2) |
||
118 | { |
||
119 | UartState1 = 0; |
||
120 | NeuerDatensatzEmpfangen1 = 1; |
||
121 | AnzahlEmpfangsBytes1 = buf_ptr1; |
||
122 | RxdBuffer1[buf_ptr1] = '\r'; |
||
123 | } |
||
124 | else |
||
125 | switch(UartState1) |
||
126 | { |
||
127 | case 0: |
||
128 | if(SioTmp1 == '#' && !NeuerDatensatzEmpfangen1) |
||
129 | { |
||
130 | UartState1 = 1; // Startzeichen und Daten schon verarbeitet |
||
131 | buf_ptr1 = 0; |
||
132 | RxdBuffer1[buf_ptr1++] = SioTmp1; |
||
133 | } |
||
134 | break; |
||
135 | case 1: // Adresse auswerten |
||
136 | UartState1++; |
||
137 | RxdBuffer1[buf_ptr1++] = SioTmp1; |
||
138 | break; |
||
139 | case 2: // Eingangsdaten sammeln |
||
140 | RxdBuffer1[buf_ptr1] = SioTmp1; |
||
141 | if(buf_ptr1 < MAX_EMPFANGS_BUFF) buf_ptr1++; |
||
142 | else UartState1 = 0; |
||
143 | break; |
||
144 | default: |
||
145 | UartState1 = 0; |
||
146 | break; |
||
147 | } |
||
148 | } |
||
149 | |||
150 | |||
151 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
152 | //++ Sende-Part der Datenübertragung |
||
153 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
154 | SIGNAL(INT_VEC_TX0) |
||
155 | { |
||
156 | static unsigned int ptr = 0; |
||
157 | unsigned char tmp_tx; |
||
158 | if(!UebertragungAbgeschlossen) |
||
159 | { |
||
160 | ptr++; // die [0] wurde schon gesendet |
||
161 | tmp_tx = SendeBuffer[ptr]; |
||
162 | if((tmp_tx == '\r') || (ptr == MAX_SENDE_BUFF)) |
||
163 | { |
||
164 | ptr = 0; |
||
165 | UebertragungAbgeschlossen = 1; |
||
166 | } |
||
167 | UDR = tmp_tx; |
||
168 | } |
||
169 | else ptr = 0; |
||
170 | } |
||
171 | |||
172 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
173 | //++ Empfangs-Part der Datenübertragung, incl. CRC-Auswertung |
||
174 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
175 | SIGNAL(INT_VEC_RX0) |
||
176 | { |
||
177 | static unsigned int crc; |
||
178 | static unsigned char crc1,crc2,buf_ptr; |
||
179 | static unsigned char UartState = 0; |
||
180 | unsigned char CrcOkay = 0; |
||
181 | |||
182 | SioTmp = UDR; |
||
183 | |||
184 | if(buf_ptr >= MAX_EMPFANGS_BUFF) UartState = 0; |
||
185 | if(SioTmp == '\r' && UartState == 2) |
||
186 | { |
||
187 | UartState = 0; |
||
188 | crc -= RxdBuffer[buf_ptr-2]; |
||
189 | crc -= RxdBuffer[buf_ptr-1]; |
||
190 | crc %= 4096; |
||
191 | crc1 = '=' + crc / 64; |
||
192 | crc2 = '=' + crc % 64; |
||
193 | CrcOkay = 0; |
||
194 | if((crc1 == RxdBuffer[buf_ptr-2]) && (crc2 == RxdBuffer[buf_ptr-1])) CrcOkay = 1; else { CrcOkay = 0; CntCrcError++;}; |
||
195 | |||
196 | if(!NeuerDatensatzEmpfangen && CrcOkay) // Datensatz schon verarbeitet |
||
197 | { |
||
198 | NeuerDatensatzEmpfangen = 1; |
||
199 | AnzahlEmpfangsBytes = buf_ptr; |
||
200 | RxdBuffer[buf_ptr] = '\r'; |
||
201 | if(RxdBuffer[2] == 'R') wdt_enable(WDTO_250MS); // Reset-Commando |
||
202 | } |
||
203 | } |
||
204 | else |
||
205 | switch(UartState) |
||
206 | { |
||
207 | case 0: |
||
208 | if(SioTmp == '#' && !NeuerDatensatzEmpfangen) { |
||
209 | UartState = 1; // Startzeichen und Daten schon verarbeitet |
||
210 | buf_ptr = 0; |
||
211 | RxdBuffer[buf_ptr++] = SioTmp; |
||
212 | crc = SioTmp; |
||
213 | } |
||
214 | break; |
||
215 | case 1: // Adresse auswerten |
||
216 | UartState++; |
||
217 | RxdBuffer[buf_ptr++] = SioTmp; |
||
218 | crc += SioTmp; |
||
219 | break; |
||
220 | case 2: // Eingangsdaten sammeln |
||
221 | RxdBuffer[buf_ptr] = SioTmp; |
||
222 | if(buf_ptr < MAX_EMPFANGS_BUFF) buf_ptr++; |
||
223 | else UartState = 0; |
||
224 | crc += SioTmp; |
||
225 | break; |
||
226 | default: |
||
227 | UartState = 0; |
||
228 | break; |
||
229 | } |
||
230 | } |
||
231 | |||
232 | |||
233 | // -------------------------------------------------------------------------- |
||
234 | void AddCRC(unsigned int wieviele) |
||
235 | { |
||
236 | unsigned int tmpCRC = 0,i; |
||
237 | for(i = 0; i < wieviele;i++) |
||
238 | { |
||
239 | tmpCRC += SendeBuffer[i]; |
||
240 | } |
||
241 | tmpCRC %= 4096; |
||
242 | SendeBuffer[i++] = '=' + tmpCRC / 64; |
||
243 | SendeBuffer[i++] = '=' + tmpCRC % 64; |
||
244 | SendeBuffer[i++] = '\r'; |
||
245 | UebertragungAbgeschlossen = 0; |
||
246 | UDR = SendeBuffer[0]; |
||
247 | } |
||
248 | |||
249 | |||
250 | |||
251 | |||
252 | // -------------------------------------------------------------------------- |
||
253 | void SendOutRXTunnelData(unsigned char *snd, unsigned char len) |
||
254 | { |
||
255 | unsigned int pt = 0; |
||
256 | unsigned char ptr = 0; |
||
257 | |||
258 | while(len) |
||
259 | { |
||
260 | SendeBuffer1[pt++] = snd[ptr++]; |
||
261 | len--; |
||
262 | } |
||
263 | SendeBuffer1[pt++] = '\r'; |
||
264 | UebertragungAbgeschlossen1 = 0; |
||
265 | UDR1 = SendeBuffer1[0]; |
||
266 | } |
||
267 | |||
268 | // -------------------------------------------------------------------------- |
||
269 | void SendOutTXTunnelData(unsigned char *snd, unsigned char len) |
||
270 | { |
||
271 | unsigned int pt = 0; |
||
272 | unsigned char ptr = 0; |
||
273 | |||
274 | while(len) |
||
275 | { |
||
276 | SendeBuffer[pt++] = snd[ptr++]; |
||
277 | len--; |
||
278 | } |
||
279 | SendeBuffer[pt++] = '\r'; |
||
280 | UebertragungAbgeschlossen = 0; |
||
281 | NeuerDatensatzEmpfangen1 = 0; |
||
282 | UDR = SendeBuffer[0]; |
||
283 | } |
||
284 | |||
285 | |||
286 | // -------------------------------------------------------------------------- |
||
287 | void SendOutData(unsigned char cmd,unsigned char modul, unsigned char *snd, unsigned char len) |
||
288 | { |
||
289 | unsigned int pt = 0; |
||
290 | unsigned char a,b,c; |
||
291 | unsigned char ptr = 0; |
||
292 | |||
293 | SendeBuffer[pt++] = '#'; // Startzeichen |
||
294 | SendeBuffer[pt++] = modul; // Adresse (a=0; b=1,...) |
||
295 | SendeBuffer[pt++] = cmd; // Commando |
||
296 | |||
297 | while(len) |
||
298 | { |
||
299 | if(len) { a = snd[ptr++]; len--;} else a = 0; |
||
300 | if(len) { b = snd[ptr++]; len--;} else b = 0; |
||
301 | if(len) { c = snd[ptr++]; len--;} else c = 0; |
||
302 | SendeBuffer[pt++] = '=' + (a >> 2); |
||
303 | SendeBuffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4)); |
||
304 | SendeBuffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6)); |
||
305 | SendeBuffer[pt++] = '=' + ( c & 0x3f); |
||
306 | } |
||
307 | AddCRC(pt); |
||
308 | } |
||
309 | |||
310 | |||
311 | // -------------------------------------------------------------------------- |
||
312 | void Decode64(unsigned char *ptrOut, unsigned char len, unsigned char ptrIn,unsigned char max) // Wohin mit den Daten; Wie lang; Wo im RxdBuffer |
||
313 | { |
||
314 | unsigned char a,b,c,d; |
||
315 | unsigned char ptr = 0; |
||
316 | unsigned char x,y,z; |
||
317 | while(len) |
||
318 | { |
||
319 | a = RxdBuffer[ptrIn++] - '='; |
||
320 | b = RxdBuffer[ptrIn++] - '='; |
||
321 | c = RxdBuffer[ptrIn++] - '='; |
||
322 | d = RxdBuffer[ptrIn++] - '='; |
||
323 | if(ptrIn > max - 2) break; // nicht mehr Daten verarbeiten, als empfangen wurden |
||
324 | |||
325 | x = (a << 2) | (b >> 4); |
||
326 | y = ((b & 0x0f) << 4) | (c >> 2); |
||
327 | z = ((c & 0x03) << 6) | d; |
||
328 | |||
329 | if(len--) ptrOut[ptr++] = x; else break; |
||
330 | if(len--) ptrOut[ptr++] = y; else break; |
||
331 | if(len--) ptrOut[ptr++] = z; else break; |
||
332 | } |
||
333 | |||
334 | } |
||
335 | |||
336 | // -------------------------------------------------------------------------- |
||
337 | void BearbeiteRxDaten(void) |
||
338 | { |
||
339 | |||
340 | if(!NeuerDatensatzEmpfangen) return; |
||
341 | |||
342 | // unsigned int tmp_int_arr1[1]; |
||
343 | // unsigned int tmp_int_arr2[2]; |
||
344 | // unsigned int tmp_int_arr3[3]; |
||
345 | unsigned char tmp_char_arr2[2]; |
||
346 | // unsigned char tmp_char_arr3[3]; |
||
347 | // unsigned char tmp_char_arr4[4]; |
||
348 | //if(!MotorenEin) |
||
349 | PcZugriff = 255; |
||
350 | switch(RxdBuffer[2]) |
||
351 | { |
||
352 | case 'a':// Texte der Analogwerte |
||
353 | Decode64((unsigned char *) &tmp_char_arr2[0],sizeof(tmp_char_arr2),3,AnzahlEmpfangsBytes); |
||
354 | DebugTextAnforderung = tmp_char_arr2[0]; |
||
355 | break; |
||
356 | case 'c':// Debugdaten incl. Externe IOs usw |
||
357 | Decode64((unsigned char *) &DebugIn,sizeof(DebugIn),3,AnzahlEmpfangsBytes); |
||
358 | /* for(unsigned char i=0; i<4;i++) |
||
359 | { |
||
360 | EE_CheckAndWrite(&EE_Buffer[EE_DEBUGWERTE + i*2], DebugIn.Analog[i]); |
||
361 | EE_CheckAndWrite(&EE_Buffer[EE_DEBUGWERTE + i*2 + 1], DebugIn.Analog[i] >> 8); |
||
362 | }*/ |
||
363 | RemoteTasten |= DebugIn.RemoteTasten; |
||
364 | DebugDataAnforderung = 1; |
||
365 | break; |
||
366 | case 'h':// x-1 Displayzeilen |
||
367 | Decode64((unsigned char *) &tmp_char_arr2[0],sizeof(tmp_char_arr2),3,AnzahlEmpfangsBytes); |
||
368 | RemoteTasten |= tmp_char_arr2[0]; |
||
369 | if(tmp_char_arr2[1] == 255) NurKanalAnforderung = 1; else NurKanalAnforderung = 0; // keine Displaydaten |
||
370 | DebugDisplayAnforderung = 1; |
||
371 | break; |
||
372 | case 't':// Motortest |
||
373 | Decode64((unsigned char *) &MotorTest[0],sizeof(MotorTest),3,AnzahlEmpfangsBytes); |
||
374 | break; |
||
375 | case 'k':// Keys von DubWise |
||
376 | Decode64((unsigned char *) &DubWiseKeys[0],sizeof(DubWiseKeys),3,AnzahlEmpfangsBytes); |
||
377 | break; |
||
378 | case 'v': // Version-Anforderung und Ausbaustufe |
||
379 | GetVersionAnforderung = 1; |
||
380 | break; |
||
381 | case 'g':// "Get"-Anforderung für Debug-Daten |
||
382 | // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
||
383 | DebugGetAnforderung = 1; |
||
384 | break; |
||
385 | case 'q':// "Get"-Anforderung für Settings |
||
386 | // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
||
387 | Decode64((unsigned char *) &tmp_char_arr2[0],sizeof(tmp_char_arr2),3,AnzahlEmpfangsBytes); |
||
388 | if(tmp_char_arr2[0] != 0xff) |
||
389 | { |
||
390 | if(tmp_char_arr2[0] > 5) tmp_char_arr2[0] = 5; |
||
391 | ReadParameterSet(tmp_char_arr2[0], (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
||
392 | SendOutData('L' + tmp_char_arr2[0] -1,MeineSlaveAdresse,(unsigned char *) &EE_Parameter.Kanalbelegung[0],STRUCT_PARAM_LAENGE); |
||
393 | } |
||
394 | else |
||
395 | SendOutData('L' + GetActiveParamSetNumber()-1,MeineSlaveAdresse,(unsigned char *) &EE_Parameter.Kanalbelegung[0],STRUCT_PARAM_LAENGE); |
||
396 | |||
397 | break; |
||
398 | |||
399 | case 'l': |
||
400 | case 'm': |
||
401 | case 'n': |
||
402 | case 'o': |
||
403 | case 'p': // Parametersatz speichern |
||
404 | Decode64((unsigned char *) &EE_Parameter.Kanalbelegung[0],STRUCT_PARAM_LAENGE,3,AnzahlEmpfangsBytes); |
||
405 | WriteParameterSet(RxdBuffer[2] - 'l' + 1, (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
||
406 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], RxdBuffer[2] - 'l' + 1); // aktiven Datensatz merken |
||
407 | Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L; |
||
408 | Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L; |
||
409 | Piep(GetActiveParamSetNumber()); |
||
410 | break; |
||
411 | |||
412 | case 'X': // Serial Tunnel Message received |
||
413 | SendOutRXTunnelData((unsigned char *)&RxdBuffer[0], AnzahlEmpfangsBytes); |
||
414 | break; |
||
415 | |||
416 | case 'C': // Flight Control Message received |
||
417 | if(Parameter_UserParam2 > 10) { |
||
418 | Decode64((unsigned char *) &ControlIn,sizeof(ControlIn),3,AnzahlEmpfangsBytes); |
||
419 | ControlOut.errorcode = ControlError_ok; |
||
420 | ControlReceived = 1; |
||
421 | } |
||
422 | else |
||
423 | { |
||
424 | ControlIn.roll = 0; |
||
425 | ControlIn.nick = 0; |
||
426 | ControlIn.gier = 0; |
||
427 | ControlIn.gas = 0; |
||
428 | ControlOut.errorcode = ControlError_ignore; |
||
429 | ControlReceived = 1; |
||
430 | } |
||
431 | break; |
||
432 | |||
433 | } |
||
434 | // DebugOut.AnzahlZyklen = Debug_Timer_Intervall; |
||
435 | NeuerDatensatzEmpfangen = 0; |
||
436 | } |
||
437 | |||
438 | //############################################################################ |
||
439 | //Routine für die Serielle Ausgabe |
||
440 | int uart_putchar (char c) |
||
441 | //############################################################################ |
||
442 | { |
||
443 | if (c == '\n') |
||
444 | uart_putchar('\r'); |
||
445 | //Warten solange bis Zeichen gesendet wurde |
||
446 | loop_until_bit_is_set(USR, UDRE); |
||
447 | //Ausgabe des Zeichens |
||
448 | UDR = c; |
||
449 | |||
450 | return (0); |
||
451 | } |
||
452 | |||
453 | // -------------------------------------------------------------------------- |
||
454 | void WriteProgramData(unsigned int pos, unsigned char wert) |
||
455 | { |
||
456 | //if (ProgramLocation == IN_RAM) Buffer[pos] = wert; |
||
457 | // else eeprom_write_byte(&EE_Buffer[pos], wert); |
||
458 | // Buffer[pos] = wert; |
||
459 | } |
||
460 | |||
461 | //############################################################################ |
||
462 | //INstallation der Seriellen Schnittstelle |
||
463 | void UART_Init (void) |
||
464 | //############################################################################ |
||
465 | { |
||
466 | //Enable TXEN im Register UCR TX-Data Enable & RX Enable |
||
467 | |||
468 | UCR=(1 << TXEN) | (1 << RXEN); |
||
469 | // UART Double Speed (U2X) |
||
470 | USR |= (1<<U2X); |
||
471 | // RX-Interrupt Freigabe |
||
472 | UCSRB |= (1<<RXCIE); |
||
473 | // TX-Interrupt Freigabe |
||
474 | UCSRB |= (1<<TXCIE); |
||
475 | |||
476 | //Teiler wird gesetzt |
||
477 | UBRR=(SYSCLK / (BAUD_RATE * 8L) - 1); |
||
478 | //UBRR = 33; |
||
479 | //öffnet einen Kanal für printf (STDOUT) |
||
480 | //fdevopen (uart_putchar, 0); |
||
481 | //sbi(PORTD,4); |
||
482 | |||
483 | // INIT 2ND uart |
||
484 | UCR1=(1 << TXEN1) | (1 << RXEN1); |
||
485 | // UART Double Speed (U2X) |
||
486 | USR1 |= (1<<U2X1); |
||
487 | // RX-Interrupt Freigabe |
||
488 | UCSR1B |= (1<<RXCIE1); |
||
489 | // TX-Interrupt Freigabe |
||
490 | UCSR1B |= (1<<TXCIE1); |
||
491 | |||
492 | //Teiler wird gesetzt |
||
493 | UBRR1=(SYSCLK / (BAUD_RATE * 8L) - 1); |
||
494 | //UBRR = 33; |
||
495 | //öffnet einen Kanal für printf (STDOUT) |
||
496 | //fdevopen (uart_putchar, 0); |
||
497 | //sbi(PORTD,4); |
||
498 | |||
499 | Debug_Timer = SetDelay(200); |
||
500 | } |
||
501 | |||
502 | //--------------------------------------------------------------------------------------------- |
||
503 | void DatenUebertragung(void) |
||
504 | { |
||
505 | if(!UebertragungAbgeschlossen) return; |
||
506 | |||
507 | if(NeuerDatensatzEmpfangen1 && UebertragungAbgeschlossen) { |
||
508 | SendOutTXTunnelData((unsigned char *) &RxdBuffer1[0],(unsigned char)AnzahlEmpfangsBytes1); |
||
509 | } |
||
510 | |||
511 | if(ControlReceived && UebertragungAbgeschlossen) |
||
512 | { |
||
513 | SendOutData('C',MeineSlaveAdresse,(unsigned char *) &ControlOut,sizeof(ControlOut)); |
||
514 | ControlReceived = 0; |
||
515 | } |
||
516 | |||
517 | if(DebugGetAnforderung && UebertragungAbgeschlossen) // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen |
||
518 | { |
||
519 | SendOutData('G',MeineSlaveAdresse,(unsigned char *) &DebugIn,sizeof(DebugIn)); |
||
520 | DebugGetAnforderung = 0; |
||
521 | } |
||
522 | |||
523 | if((CheckDelay(Debug_Timer) || DebugDataAnforderung) && UebertragungAbgeschlossen) |
||
524 | { |
||
525 | SendOutData('D',MeineSlaveAdresse,(unsigned char *) &DebugOut,sizeof(DebugOut)); |
||
526 | DebugDataAnforderung = 0; |
||
527 | Debug_Timer = SetDelay(MIN_DEBUG_INTERVALL); |
||
528 | } |
||
529 | if(DebugTextAnforderung != 255) // Texte für die Analogdaten |
||
530 | { |
||
531 | SendOutData('A',DebugTextAnforderung + '0',(unsigned char *) ANALOG_TEXT[DebugTextAnforderung],16); |
||
532 | DebugTextAnforderung = 255; |
||
533 | } |
||
534 | |||
535 | if(DebugDisplayAnforderung && UebertragungAbgeschlossen) |
||
536 | { |
||
537 | Menu(); |
||
538 | DebugDisplayAnforderung = 0; |
||
539 | if(++RemotePollDisplayLine == 4 || NurKanalAnforderung) |
||
540 | { |
||
541 | SendOutData('4',0,(unsigned char *)&PPM_in,sizeof(PPM_in)); // DisplayZeile übertragen |
||
542 | RemotePollDisplayLine = -1; |
||
543 | } |
||
544 | else SendOutData('0' + RemotePollDisplayLine,0,(unsigned char *)&DisplayBuff[20 * RemotePollDisplayLine],20); // DisplayZeile übertragen |
||
545 | } |
||
546 | if(GetVersionAnforderung && UebertragungAbgeschlossen) |
||
547 | { |
||
548 | SendOutData('V',MeineSlaveAdresse,(unsigned char *) &VersionInfo,sizeof(VersionInfo)); |
||
549 | GetVersionAnforderung = 0; |
||
550 | } |
||
551 | |||
552 | } |
||
553 |