Rev 772 | Rev 800 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 772 | Rev 783 | ||
---|---|---|---|
1 | /**************************************************************************** |
1 | /**************************************************************************** |
2 | * Copyright (C) 2009-2010 by Claas Anders "CaScAdE" Rathje * |
2 | * Copyright (C) 2009-2010 by Claas Anders "CaScAdE" Rathje * |
3 | * admiralcascade@gmail.com * |
3 | * admiralcascade@gmail.com * |
4 | * Project-URL: http://www.mylifesucks.de/oss/c-osd/ * |
4 | * Project-URL: http://www.mylifesucks.de/oss/c-osd/ * |
5 | * * |
5 | * * |
6 | * This program is free software; you can redistribute it and/or modify * |
6 | * This program is free software; you can redistribute it and/or modify * |
7 | * it under the terms of the GNU General Public License as published by * |
7 | * it under the terms of the GNU General Public License as published by * |
8 | * the Free Software Foundation; either version 2 of the License. * |
8 | * the Free Software Foundation; either version 2 of the License. * |
9 | * * |
9 | * * |
10 | * This program is distributed in the hope that it will be useful, * |
10 | * This program is distributed in the hope that it will be useful, * |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
13 | * GNU General Public License for more details. * |
13 | * GNU General Public License for more details. * |
14 | * * |
14 | * * |
15 | * You should have received a copy of the GNU General Public License * |
15 | * You should have received a copy of the GNU General Public License * |
16 | * along with this program; if not, write to the * |
16 | * along with this program; if not, write to the * |
17 | * Free Software Foundation, Inc., * |
17 | * Free Software Foundation, Inc., * |
18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
19 | ****************************************************************************/ |
19 | ****************************************************************************/ |
20 | 20 | ||
21 | #include <avr/io.h> |
21 | #include <avr/io.h> |
22 | #include <avr/interrupt.h> |
22 | #include <avr/interrupt.h> |
23 | #include <util/delay.h> |
23 | #include <util/delay.h> |
24 | #include "main.h" |
24 | #include "main.h" |
25 | #include "usart1.h" |
25 | #include "usart1.h" |
26 | 26 | ||
27 | #if !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
27 | #if !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
28 | 28 | ||
29 | volatile uint8_t rxd_buffer_locked = 0; |
29 | volatile uint8_t rxd_buffer_locked = 0; |
30 | volatile uint8_t rxd_buffer[RXD_BUFFER_LEN]; |
30 | volatile uint8_t rxd_buffer[RXD_BUFFER_LEN]; |
31 | volatile uint8_t txd_buffer[TXD_BUFFER_LEN]; |
31 | //volatile uint8_t txd_buffer[TXD_BUFFER_LEN]; |
32 | volatile uint8_t ReceivedBytes = 0; |
32 | volatile uint8_t ReceivedBytes = 0; |
33 | volatile uint8_t *pRxData = 0; |
33 | volatile uint8_t *pRxData = 0; |
34 | volatile uint8_t RxDataLen = 0; |
34 | volatile uint8_t RxDataLen = 0; |
35 | 35 | ||
36 | /* ########################################################################## |
36 | /* ########################################################################## |
37 | * USART1 stuff |
37 | * USART1 stuff |
38 | * ##########################################################################*/ |
38 | * ##########################################################################*/ |
39 | 39 | ||
40 | /** |
40 | /** |
41 | * init usart1 |
41 | * init usart1 |
42 | */ |
42 | */ |
43 | void usart1_init() { |
43 | void usart1_init() { |
44 | UBRR1H = ((F_CPU / (16UL * baud)) - 1) >> 8; |
44 | UBRR1H = ((F_CPU / (16UL * baud)) - 1) >> 8; |
45 | UBRR1L = (F_CPU / (16UL * baud)) - 1; |
45 | UBRR1L = (F_CPU / (16UL * baud)) - 1; |
46 | 46 | ||
47 | // Enable receiver and transmitter; enable RX interrupt |
47 | // Enable receiver and transmitter; enable RX interrupt |
48 | UCSR1B = (1 << RXEN1) | (1 << TXEN1) | (1 << RXCIE1); |
48 | UCSR1B = (1 << RXEN1) | (1 << TXEN1) | (1 << RXCIE1); |
49 | 49 | ||
50 | //asynchronous 8N1 |
50 | //asynchronous 8N1 |
51 | UCSR1C = (1 << URSEL1) | (3 << UCSZ10); |
51 | UCSR1C = (1 << URSEL1) | (3 << UCSZ10); |
52 | } |
52 | } |
53 | 53 | ||
54 | /** |
54 | /** |
55 | * disable the txd pin of usart1 |
55 | * disable the txd pin of usart1 |
56 | */ |
56 | */ |
57 | void usart1_DisableTXD(void) { |
57 | void usart1_DisableTXD(void) { |
58 | UCSR1B &= ~(1 << TXCIE1); // disable TX-Interrupt |
58 | UCSR1B &= ~(1 << TXCIE1); // disable TX-Interrupt |
59 | UCSR1B &= ~(1 << TXEN1); // disable TX in USART |
59 | UCSR1B &= ~(1 << TXEN1); // disable TX in USART |
60 | DDRB &= ~(1 << DDB3); // set TXD pin as input |
60 | DDRB &= ~(1 << DDB3); // set TXD pin as input |
61 | PORTB &= ~(1 << PORTB3); // disable pullup on TXD pin |
61 | PORTB &= ~(1 << PORTB3); // disable pullup on TXD pin |
62 | } |
62 | } |
63 | 63 | ||
64 | /** |
64 | /** |
65 | * enable the txd pin of usart1 |
65 | * enable the txd pin of usart1 |
66 | */ |
66 | */ |
67 | void usart1_EnableTXD(void) { |
67 | void usart1_EnableTXD(void) { |
68 | DDRB |= (1 << DDB3); // set TXD pin as output |
68 | DDRB |= (1 << DDB3); // set TXD pin as output |
69 | PORTB &= ~(1 << PORTB3); // disable pullup on TXD pin |
69 | PORTB &= ~(1 << PORTB3); // disable pullup on TXD pin |
70 | UCSR1B |= (1 << TXEN1); // enable TX in USART |
70 | UCSR1B |= (1 << TXEN1); // enable TX in USART |
71 | UCSR1B |= (1 << TXCIE1); // enable TX-Interrupt |
71 | UCSR1B |= (1 << TXCIE1); // enable TX-Interrupt |
72 | } |
72 | } |
73 | 73 | ||
74 | /** |
74 | /** |
75 | * send a single <character> through usart1 |
75 | * send a single <character> through usart1 |
76 | */ |
76 | */ |
77 | void usart1_putc(unsigned char character) { |
77 | void usart1_putc(unsigned char character) { |
78 | // wait until UDR ready |
78 | // wait until UDR ready |
79 | while (!(UCSR1A & (1 << UDRE1))); |
79 | while (!(UCSR1A & (1 << UDRE1))); |
80 | UDR1 = character; |
80 | UDR1 = character; |
81 | } |
81 | } |
82 | 82 | ||
83 | /** |
83 | /** |
84 | * send a <string> throught usart1 |
84 | * send a <string> throught usart1 |
85 | */ |
85 | */ |
86 | /*void usart1_puts(char *s) { |
86 | /*void usart1_puts(char *s) { |
87 | while (*s) { |
87 | while (*s) { |
88 | usart1_putc(*s); |
88 | usart1_putc(*s); |
89 | s++; |
89 | s++; |
90 | } |
90 | } |
91 | }*/ |
91 | }*/ |
92 | 92 | ||
93 | /** |
93 | /** |
94 | * send a PGM<string> throught usart1 |
94 | * send a PGM<string> throught usart1 |
95 | */ |
95 | */ |
96 | void usart1_puts_pgm(const char* string) { |
96 | void usart1_puts_pgm(const char* string) { |
97 | while (pgm_read_byte(string) != 0x00) |
97 | while (pgm_read_byte(string) != 0x00) |
98 | usart1_putc(pgm_read_byte(string++)); |
98 | usart1_putc(pgm_read_byte(string++)); |
99 | } |
99 | } |
100 | 100 | ||
101 | /** |
101 | /** |
102 | * transmit interrupt handler |
102 | * transmit interrupt handler |
103 | * unused |
103 | * unused |
104 | */ |
104 | */ |
105 | ISR(SIG_USART1_DATA) { |
105 | ISR(SIG_USART1_DATA) { |
106 | } |
106 | } |
107 | 107 | ||
108 | /* |
108 | /* |
109 | * receive data through usart1 |
109 | * receive data through usart1 |
110 | * portions taken and adapted from |
110 | * portions taken and adapted from |
111 | * http://svn.mikrokopter.de/mikrowebsvn/filedetails.php?repname=FlightCtrl&path=%2Fbranches%2FV0.72p+Code+Redesign+killagreg%2Fuart0.c |
111 | * http://svn.mikrokopter.de/mikrowebsvn/filedetails.php?repname=FlightCtrl&path=%2Fbranches%2FV0.72p+Code+Redesign+killagreg%2Fuart0.c |
112 | */ |
112 | */ |
113 | ISR(SIG_USART1_RECV) { |
113 | ISR(SIG_USART1_RECV) { |
114 | uint8_t c; |
114 | uint8_t c; |
115 | // catch the received byte |
115 | // catch the received byte |
116 | c = UDR1; |
116 | c = UDR1; |
117 | if (rxd_buffer_locked) return; // if rxd buffer is locked immediately return |
117 | if (rxd_buffer_locked) return; // if rxd buffer is locked immediately return |
118 | static uint16_t crc; |
118 | static uint16_t crc; |
119 | static uint8_t ptr_rxd_buffer = 0; |
119 | static uint8_t ptr_rxd_buffer = 0; |
120 | static uint8_t c1 = 0; |
120 | static uint8_t c1 = 0; |
121 | static uint8_t c2 = 0; |
121 | static uint8_t c2 = 0; |
122 | static uint8_t usart_rx_ok = 0; |
122 | static uint8_t usart_rx_ok = 0; |
123 | uint8_t crc1, crc2; |
123 | uint8_t crc1, crc2; |
124 | // the rxd buffer is unlocked |
124 | // the rxd buffer is unlocked |
125 | if (usart_rx_ok == 0) { |
125 | if (usart_rx_ok == 0) { |
126 | // if ((c2 == '#') && (c1 == 'b' || c1 == 'c') && (c == 'D' || c == 'V' || c == 'O')) { |
126 | // if ((c2 == '#') && (c1 == 'b' || c1 == 'c') && (c == 'D' || c == 'V' || c == 'O')) { |
127 | 127 | ||
128 | if ((c2 == '#') && (c1 == 'b' || c1 == 'c') && |
128 | if ((c2 == '#') && (c1 == 'b' || c1 == 'c') && |
129 | #if FCONLY |
129 | #if FCONLY |
130 | (c == 'V' || c == 'D')) { // version and debug |
130 | (c == 'V' || c == 'D' || c == 'Q')) { // version, debug, settings |
131 | #else |
131 | #else |
132 | (c == 'V' || c == 'O')) { // version and OSD |
132 | (c == 'V' || c == 'O' || c == 'Q')) { // version, OSD, settings |
133 | #endif |
133 | #endif |
134 | usart_rx_ok = 1; |
134 | usart_rx_ok = 1; |
135 | rxd_buffer[ptr_rxd_buffer++] = c2; |
135 | rxd_buffer[ptr_rxd_buffer++] = c2; |
136 | crc = c2; |
136 | crc = c2; |
137 | rxd_buffer[ptr_rxd_buffer++] = c1; |
137 | rxd_buffer[ptr_rxd_buffer++] = c1; |
138 | crc += c1; |
138 | crc += c1; |
139 | rxd_buffer[ptr_rxd_buffer++] = c; |
139 | rxd_buffer[ptr_rxd_buffer++] = c; |
140 | crc += c; |
140 | crc += c; |
141 | c2 = 0; |
141 | c2 = 0; |
142 | c1 = 0; |
142 | c1 = 0; |
143 | LED1_ON |
143 | LED1_ON |
144 | LED2_OFF |
144 | LED2_OFF |
145 | } else { |
145 | } else { |
146 | c2 = c1; |
146 | c2 = c1; |
147 | c1 = c; |
147 | c1 = c; |
148 | } |
148 | } |
149 | } else if (ptr_rxd_buffer < RXD_BUFFER_LEN) { // collect incomming bytes |
149 | } else if (ptr_rxd_buffer < RXD_BUFFER_LEN) { // collect incomming bytes |
150 | if (c != '\r') { // no termination character |
150 | if (c != '\r') { // no termination character |
151 | rxd_buffer[ptr_rxd_buffer++] = c; // copy byte to rxd buffer |
151 | rxd_buffer[ptr_rxd_buffer++] = c; // copy byte to rxd buffer |
152 | crc += c; // update crc |
152 | crc += c; // update crc |
153 | } else { // termination character was received |
153 | } else { // termination character was received |
154 | // the last 2 bytes are no subject for checksum calculation |
154 | // the last 2 bytes are no subject for checksum calculation |
155 | // they are the checksum itself |
155 | // they are the checksum itself |
156 | crc -= rxd_buffer[ptr_rxd_buffer - 2]; |
156 | crc -= rxd_buffer[ptr_rxd_buffer - 2]; |
157 | crc -= rxd_buffer[ptr_rxd_buffer - 1]; |
157 | crc -= rxd_buffer[ptr_rxd_buffer - 1]; |
158 | // calculate checksum from transmitted data |
158 | // calculate checksum from transmitted data |
159 | crc %= 4096; |
159 | crc %= 4096; |
160 | crc1 = '=' + crc / 64; |
160 | crc1 = '=' + crc / 64; |
161 | crc2 = '=' + crc % 64; |
161 | crc2 = '=' + crc % 64; |
162 | // compare checksum to transmitted checksum bytes |
162 | // compare checksum to transmitted checksum bytes |
163 | if ((crc1 == rxd_buffer[ptr_rxd_buffer - 2]) && (crc2 == rxd_buffer[ptr_rxd_buffer - 1])) { // checksum valid |
163 | if ((crc1 == rxd_buffer[ptr_rxd_buffer - 2]) && (crc2 == rxd_buffer[ptr_rxd_buffer - 1])) { // checksum valid |
164 | rxd_buffer[ptr_rxd_buffer] = '\r'; // set termination character |
164 | rxd_buffer[ptr_rxd_buffer] = '\r'; // set termination character |
165 | ReceivedBytes = ptr_rxd_buffer + 1; // store number of received bytes |
165 | ReceivedBytes = ptr_rxd_buffer + 1; // store number of received bytes |
166 | rxd_buffer_locked = 1; // lock the rxd buffer |
166 | rxd_buffer_locked = 1; // lock the rxd buffer |
167 | LED1_OFF |
167 | LED1_OFF |
168 | } else { // checksum invalid |
168 | } else { // checksum invalid |
169 | rxd_buffer_locked = 0; // unlock rxd buffer |
169 | rxd_buffer_locked = 0; // unlock rxd buffer |
170 | LED2_ON |
170 | LED2_ON |
171 | } |
171 | } |
172 | ptr_rxd_buffer = 0; // reset rxd buffer pointer |
172 | ptr_rxd_buffer = 0; // reset rxd buffer pointer |
173 | usart_rx_ok = 0; |
173 | usart_rx_ok = 0; |
174 | } |
174 | } |
175 | } else { // rxd buffer overrun |
175 | } else { // rxd buffer overrun |
176 | ptr_rxd_buffer = 0; // reset rxd buffer |
176 | ptr_rxd_buffer = 0; // reset rxd buffer |
177 | rxd_buffer_locked = 0; // unlock rxd buffer |
177 | rxd_buffer_locked = 0; // unlock rxd buffer |
178 | usart_rx_ok = 0; |
178 | usart_rx_ok = 0; |
179 | LED2_ON |
179 | LED2_ON |
180 | } |
180 | } |
181 | } |
181 | } |
182 | 182 | ||
183 | /** |
183 | /** |
184 | * Decode the recevied Buffer |
184 | * Decode the recevied Buffer |
185 | * portions taken and adapted from |
185 | * portions taken and adapted from |
186 | * http://svn.mikrokopter.de/mikrowebsvn/filedetails.php?repname=FlightCtrl&path=%2Ftags%2FV0.72p%2Fuart.c |
186 | * http://svn.mikrokopter.de/mikrowebsvn/filedetails.php?repname=FlightCtrl&path=%2Ftags%2FV0.72p%2Fuart.c |
187 | */ |
187 | */ |
188 | void Decode64(void) { |
188 | void Decode64(void) { |
189 | uint8_t a, b, c, d; |
189 | uint8_t a, b, c, d; |
190 | uint8_t x, y, z; |
190 | uint8_t x, y, z; |
191 | uint8_t ptrIn = 3; |
191 | uint8_t ptrIn = 3; |
192 | uint8_t ptrOut = 3; |
192 | uint8_t ptrOut = 3; |
193 | uint8_t len = ReceivedBytes - 6; |
193 | uint8_t len = ReceivedBytes - 6; |
194 | 194 | ||
195 | while (len) { |
195 | while (len) { |
196 | a = rxd_buffer[ptrIn++] - '='; |
196 | a = rxd_buffer[ptrIn++] - '='; |
197 | b = rxd_buffer[ptrIn++] - '='; |
197 | b = rxd_buffer[ptrIn++] - '='; |
198 | c = rxd_buffer[ptrIn++] - '='; |
198 | c = rxd_buffer[ptrIn++] - '='; |
199 | d = rxd_buffer[ptrIn++] - '='; |
199 | d = rxd_buffer[ptrIn++] - '='; |
200 | 200 | ||
201 | x = (a << 2) | (b >> 4); |
201 | x = (a << 2) | (b >> 4); |
202 | y = ((b & 0x0f) << 4) | (c >> 2); |
202 | y = ((b & 0x0f) << 4) | (c >> 2); |
203 | z = ((c & 0x03) << 6) | d; |
203 | z = ((c & 0x03) << 6) | d; |
204 | 204 | ||
205 | if (len--) rxd_buffer[ptrOut++] = x; |
205 | if (len--) rxd_buffer[ptrOut++] = x; |
206 | else break; |
206 | else break; |
207 | if (len--) rxd_buffer[ptrOut++] = y; |
207 | if (len--) rxd_buffer[ptrOut++] = y; |
208 | else break; |
208 | else break; |
209 | if (len--) rxd_buffer[ptrOut++] = z; |
209 | if (len--) rxd_buffer[ptrOut++] = z; |
210 | else break; |
210 | else break; |
211 | } |
211 | } |
212 | pRxData = &rxd_buffer[3]; |
212 | pRxData = &rxd_buffer[3]; |
213 | RxDataLen = ptrOut - 3; |
213 | RxDataLen = ptrOut - 3; |
214 | } |
214 | } |
- | 215 | ||
- | 216 | ||
- | 217 | /** |
|
- | 218 | * Request Data through usart1 until a answer is received |
|
- | 219 | */ |
|
- | 220 | void usart1_request_blocking(unsigned char answer, const char* message) { |
|
- | 221 | rxd_buffer[2] = answer + 1; |
|
- | 222 | while (rxd_buffer[2] != answer) { |
|
- | 223 | rxd_buffer_locked = 0; |
|
- | 224 | usart1_EnableTXD(); |
|
- | 225 | usart1_puts_pgm(message); |
|
- | 226 | usart1_DisableTXD(); |
|
- | 227 | static uint8_t wait = 0; |
|
- | 228 | wait = 0; |
|
- | 229 | while (rxd_buffer_locked == 0 && wait < 150) { |
|
- | 230 | wait++; |
|
- | 231 | _delay_ms(10); |
|
- | 232 | } |
|
- | 233 | } |
|
- | 234 | Decode64(); |
|
- | 235 | } |
|
- | 236 | ||
- | 237 | /** |
|
- | 238 | * Request UART Redirect from NC to itself |
|
- | 239 | */ |
|
- | 240 | void usart1_request_nc_uart(void) { |
|
- | 241 | usart1_EnableTXD(); |
|
- | 242 | usart1_putc(0x1B); |
|
- | 243 | usart1_putc(0x1B); |
|
- | 244 | usart1_putc(0x55); |
|
- | 245 | usart1_putc(0xAA); |
|
- | 246 | usart1_putc(0x00); |
|
- | 247 | usart1_DisableTXD(); |
|
- | 248 | } |
|
- | 249 | ||
215 | 250 | ||
216 | /** |
251 | /** |
217 | * request Data through USART in special MK format by adding checksum and |
252 | * request Data through USART in special MK format by adding checksum and |
218 | * encode data in modified Base64 |
253 | * encode data in modified Base64 |
219 | * portions taken and adapted from |
254 | * portions taken and adapted from |
220 | * http://svn.mikrokopter.de/mikrowebsvn/filedetails.php?repname=FlightCtrl&path=%2Ftags%2FV0.72p%2Fuart.c |
255 | * http://svn.mikrokopter.de/mikrowebsvn/filedetails.php?repname=FlightCtrl&path=%2Ftags%2FV0.72p%2Fuart.c |
221 | */ |
256 | */ |
222 | /*void sendMKData(unsigned char cmd, unsigned char addr, unsigned char *snd, unsigned char len) { |
257 | /*void sendMKData(unsigned char cmd, unsigned char addr, unsigned char *snd, unsigned char len) { |
223 | unsigned int pt = 0; |
258 | unsigned int pt = 0; |
224 | unsigned char a, b, c; |
259 | unsigned char a, b, c; |
225 | unsigned char ptr = 0; |
260 | unsigned char ptr = 0; |
226 | 261 | ||
227 | txd_buffer[pt++] = '#'; // Start-Byte |
262 | txd_buffer[pt++] = '#'; // Start-Byte |
228 | txd_buffer[pt++] = 'a' + addr; // Adress |
263 | txd_buffer[pt++] = 'a' + addr; // Adress |
229 | txd_buffer[pt++] = cmd; // Command |
264 | txd_buffer[pt++] = cmd; // Command |
230 | while (len) { |
265 | while (len) { |
231 | if (len) { |
266 | if (len) { |
232 | a = snd[ptr++]; |
267 | a = snd[ptr++]; |
233 | len--; |
268 | len--; |
234 | } else a = 0; |
269 | } else a = 0; |
235 | if (len) { |
270 | if (len) { |
236 | b = snd[ptr++]; |
271 | b = snd[ptr++]; |
237 | len--; |
272 | len--; |
238 | } else b = 0; |
273 | } else b = 0; |
239 | if (len) { |
274 | if (len) { |
240 | c = snd[ptr++]; |
275 | c = snd[ptr++]; |
241 | len--; |
276 | len--; |
242 | } else c = 0; |
277 | } else c = 0; |
243 | txd_buffer[pt++] = '=' + (a >> 2); |
278 | txd_buffer[pt++] = '=' + (a >> 2); |
244 | txd_buffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4)); |
279 | txd_buffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4)); |
245 | txd_buffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6)); |
280 | txd_buffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6)); |
246 | txd_buffer[pt++] = '=' + (c & 0x3f); |
281 | txd_buffer[pt++] = '=' + (c & 0x3f); |
247 | } |
282 | } |
248 | 283 | ||
249 | // add crc |
284 | // add crc |
250 | unsigned int tmpCRC = 0, i; |
285 | unsigned int tmpCRC = 0, i; |
251 | for (i = 0; i < pt; i++) { |
286 | for (i = 0; i < pt; i++) { |
252 | tmpCRC += txd_buffer[i]; |
287 | tmpCRC += txd_buffer[i]; |
253 | } |
288 | } |
254 | tmpCRC %= 4096; |
289 | tmpCRC %= 4096; |
255 | txd_buffer[i++] = '=' + tmpCRC / 64; |
290 | txd_buffer[i++] = '=' + tmpCRC / 64; |
256 | txd_buffer[i++] = '=' + tmpCRC % 64; |
291 | txd_buffer[i++] = '=' + tmpCRC % 64; |
257 | txd_buffer[i++] = '\r'; |
292 | txd_buffer[i++] = '\r'; |
258 | 293 | ||
259 | usart1_puts((char*) txd_buffer); |
294 | usart1_puts((char*) txd_buffer); |
260 | }*/ |
295 | }*/ |
261 | 296 | ||
262 | /** |
297 | /** |
263 | * short script to directly send a request thorugh usart including en- and disabling it |
298 | * short script to directly send a request thorugh usart including en- and disabling it |
264 | * where <address> is the address of the receipient, <label> is which data set to request |
299 | * where <address> is the address of the receipient, <label> is which data set to request |
265 | * and <ms> represents the milliseconds delay between data |
300 | * and <ms> represents the milliseconds delay between data |
266 | */ |
301 | */ |
267 | /*void usart1_request_mk_data(uint8_t address, char label, uint8_t ms) { |
302 | /*void usart1_request_mk_data(uint8_t address, char label, uint8_t ms) { |
268 | // re-enable TXD pin |
303 | // re-enable TXD pin |
269 | usart1_EnableTXD(); |
304 | usart1_EnableTXD(); |
270 | 305 | ||
271 | unsigned char mstenth = ms / 10; |
306 | unsigned char mstenth = ms / 10; |
272 | sendMKData(label, address, &mstenth, 1); |
307 | sendMKData(label, address, &mstenth, 1); |
273 | // wait until UDR ready |
308 | // wait until UDR ready |
274 | while (!(UCSR1A & (1 << UDRE1))); |
309 | while (!(UCSR1A & (1 << UDRE1))); |
275 | // disable TXD pin again |
310 | // disable TXD pin again |
276 | usart1_DisableTXD(); |
311 | usart1_DisableTXD(); |
277 | }*/ |
312 | }*/ |
278 | 313 | ||
279 | #endif |
314 | #endif |
280 | 315 |