Rev 1199 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1199 | Rev 1437 | ||
---|---|---|---|
1 | /**************************************************************************** |
1 | /**************************************************************************** |
2 | * Copyright (C) 2011 by Claas Anders "CaScAdE" Rathje * |
2 | * Copyright (C) 2011-2012 by Claas Anders "CaScAdE" Rathje * |
3 | * admiralcascade@gmail.com * |
3 | * admiralcascade@gmail.com * |
4 | * Project-URL: http://www.mylifesucks.de/oss/c-epilepsy/ * |
4 | * Project-URL: http://www.mylifesucks.de/oss/c-epilepsy/ * |
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 | 21 | ||
22 | #include "usart0.h" |
22 | #include "usart0.h" |
23 | 23 | ||
24 | volatile uint8_t rxd_buffer_locked = 0; |
24 | volatile uint8_t rxd_buffer_locked = 0; |
25 | volatile uint8_t rxd_buffer[RXD_BUFFER_LEN]; |
25 | volatile uint8_t rxd_buffer[RXD_BUFFER_LEN]; |
26 | volatile uint8_t txd_buffer[TXD_BUFFER_LEN]; |
26 | volatile uint8_t txd_buffer[TXD_BUFFER_LEN]; |
27 | volatile uint8_t ReceivedBytes = 0; |
27 | volatile uint8_t ReceivedBytes = 0; |
28 | volatile uint8_t *pRxData = 0; |
28 | volatile uint8_t *pRxData = 0; |
29 | volatile uint8_t RxDataLen = 0; |
29 | volatile uint8_t RxDataLen = 0; |
30 | 30 | ||
31 | /** |
31 | /** |
32 | * init usart0 |
32 | * init usart0 |
33 | */ |
33 | */ |
34 | void usart0_init() { |
34 | void usart0_init() { |
35 | 35 | ||
36 | UBRR0H = ((F_CPU / (16UL * USART0_BAUD)) - 1) >> 8; |
36 | UBRR0H = ((F_CPU / (16UL * USART0_BAUD)) - 1) >> 8; |
37 | UBRR0L = (F_CPU / (16UL * USART0_BAUD)) - 1; |
37 | UBRR0L = (F_CPU / (16UL * USART0_BAUD)) - 1; |
38 | 38 | ||
39 | // Enable receiver and transmitter; enable RX interrupt |
39 | // Enable receiver and transmitter; enable RX interrupt |
40 | UCSR0B = (1 << RXEN0) | (1 << TXEN0) | (1 << RXCIE0); |
40 | UCSR0B = (1 << RXEN0) | (1 << TXEN0) | (1 << RXCIE0); |
41 | 41 | ||
42 | // set asynchronous mode |
42 | // set asynchronous mode |
43 | UCSR0C &= ~(1 << UMSEL01); |
43 | UCSR0C &= ~(1 << UMSEL01); |
44 | UCSR0C &= ~(1 << UMSEL00); |
44 | UCSR0C &= ~(1 << UMSEL00); |
45 | // no parity |
45 | // no parity |
46 | UCSR0C &= ~(1 << UPM01); |
46 | UCSR0C &= ~(1 << UPM01); |
47 | UCSR0C &= ~(1 << UPM00); |
47 | UCSR0C &= ~(1 << UPM00); |
48 | // 1 stop bit |
48 | // 1 stop bit |
49 | UCSR0C &= ~(1 << USBS0); |
49 | UCSR0C &= ~(1 << USBS0); |
50 | // 8-bit |
50 | // 8-bit |
51 | UCSR0B &= ~(1 << UCSZ02); |
51 | UCSR0B &= ~(1 << UCSZ02); |
52 | UCSR0C |= (1 << UCSZ01); |
52 | UCSR0C |= (1 << UCSZ01); |
53 | UCSR0C |= (1 << UCSZ00); |
53 | UCSR0C |= (1 << UCSZ00); |
54 | 54 | ||
55 | // set direction of RXD0 and TXD0 pins |
55 | // set direction of RXD0 and TXD0 pins |
56 | // set RXD0 (PD0) as an input pin |
56 | // set RXD0 (PD0) as an input pin |
57 | PORTD &= ~(1 << PORTD0); |
57 | PORTD &= ~(1 << PORTD0); |
58 | DDRD &= ~(1 << DDD0); |
58 | DDRD &= ~(1 << DDD0); |
59 | // set TXD0 (PD1) as an output pin |
59 | // set TXD0 (PD1) as an output pin |
60 | //PORTD |= (1 << PORTD1); |
60 | //PORTD |= (1 << PORTD1); |
61 | //DDRD &= ~(1 << DDD1); |
61 | //DDRD &= ~(1 << DDD1); |
62 | 62 | ||
63 | } |
63 | } |
64 | 64 | ||
65 | /** |
65 | /** |
66 | * disable the txd pin of usart0 |
66 | * disable the txd pin of usart0 |
67 | */ |
67 | */ |
68 | void usart0_DisableTXD(void) { |
68 | void usart0_DisableTXD(void) { |
69 | UCSR0B &= ~(1 << TXCIE0); // disable TX-Interrupt |
69 | UCSR0B &= ~(1 << TXCIE0); // disable TX-Interrupt |
70 | UCSR0B &= ~(1 << TXEN0); // disable TX in USART |
70 | UCSR0B &= ~(1 << TXEN0); // disable TX in USART |
71 | DDRD &= ~(1 << DDD1); // set TXD pin as input |
71 | DDRD &= ~(1 << DDD1); // set TXD pin as input |
72 | PORTD &= ~(1 << PORTD1); // disable pullup on TXD pin |
72 | PORTD &= ~(1 << PORTD1); // disable pullup on TXD pin |
73 | } |
73 | } |
74 | 74 | ||
75 | /** |
75 | /** |
76 | * enable the txd pin of usart0 |
76 | * enable the txd pin of usart0 |
77 | */ |
77 | */ |
78 | void usart0_EnableTXD(void) { |
78 | void usart0_EnableTXD(void) { |
79 | DDRD |= (1 << DDD1); // set TXD pin as output |
79 | DDRD |= (1 << DDD1); // set TXD pin as output |
80 | PORTD &= ~(1 << PORTD1); // disable pullup on TXD pin |
80 | PORTD &= ~(1 << PORTD1); // disable pullup on TXD pin |
81 | UCSR0B |= (1 << TXEN0); // enable TX in USART |
81 | UCSR0B |= (1 << TXEN0); // enable TX in USART |
82 | UCSR0B |= (1 << TXCIE0); // enable TX-Interrupt |
82 | UCSR0B |= (1 << TXCIE0); // enable TX-Interrupt |
83 | } |
83 | } |
84 | 84 | ||
85 | /** |
85 | /** |
86 | * send a single <character> through usart0 |
86 | * send a single <character> through usart0 |
87 | */ |
87 | */ |
88 | void usart0_putc(unsigned char character) { |
88 | void usart0_putc(unsigned char character) { |
89 | // wait until UDR ready |
89 | // wait until UDR ready |
90 | while (!(UCSR0A & (1 << UDRE0))); |
90 | while (!(UCSR0A & (1 << UDRE0))); |
91 | UDR0 = character; |
91 | UDR0 = character; |
92 | } |
92 | } |
93 | 93 | ||
94 | /** |
94 | /** |
95 | * send a <string> throught usart0 |
95 | * send a <string> throught usart0 |
96 | */ |
96 | */ |
97 | void usart0_puts(char *s) { |
97 | void usart0_puts(char *s) { |
98 | while (*s) { |
98 | while (*s) { |
99 | usart0_putc(*s); |
99 | usart0_putc(*s); |
100 | s++; |
100 | s++; |
101 | } |
101 | } |
102 | } |
102 | } |
103 | 103 | ||
104 | /** |
104 | /** |
105 | * send a PGM<string> throught usart0 |
105 | * send a PGM<string> throught usart0 |
106 | */ |
106 | */ |
107 | void usart0_puts_pgm(const char* string) { |
107 | void usart0_puts_pgm(const char* string) { |
108 | while (pgm_read_byte(string) != 0x00) |
108 | while (pgm_read_byte(string) != 0x00) |
109 | usart0_putc(pgm_read_byte(string++)); |
109 | usart0_putc(pgm_read_byte(string++)); |
110 | } |
110 | } |
111 | 111 | ||
112 | /** |
112 | /** |
113 | * transmit interrupt handler |
113 | * transmit interrupt handler |
114 | * unused |
114 | * unused |
115 | */ |
115 | */ |
116 | ISR(USART0_TX_vect, ISR_BLOCK) { |
116 | ISR(USART0_TX_vect, ISR_BLOCK) { |
117 | } |
117 | } |
118 | 118 | ||
119 | /* |
119 | /* |
120 | * receive data through usart0 |
120 | * receive data through usart0 |
121 | * portions taken and adapted from |
121 | * portions taken and adapted from |
122 | * http://svn.mikrokopter.de/mikrowebsvn/filedetails.php?repname=FlightCtrl&path=%2Fbranches%2FV0.72p+Code+Redesign+killagreg%2Fuart0.c |
122 | * http://svn.mikrokopter.de/mikrowebsvn/filedetails.php?repname=FlightCtrl&path=%2Fbranches%2FV0.72p+Code+Redesign+killagreg%2Fuart0.c |
123 | */ |
123 | */ |
124 | ISR(USART0_RX_vect, ISR_BLOCK) { |
124 | ISR(USART0_RX_vect, ISR_BLOCK) { |
125 | uint8_t c; |
125 | uint8_t c; |
126 | // catch the received byte |
126 | // catch the received byte |
127 | c = UDR0; |
127 | c = UDR0; |
128 | if (rxd_buffer_locked) return; // if rxd buffer is locked immediately return |
128 | if (rxd_buffer_locked) return; // if rxd buffer is locked immediately return |
129 | static uint16_t crc; |
129 | static uint16_t crc; |
130 | static uint8_t ptr_rxd_buffer = 0; |
130 | static uint8_t ptr_rxd_buffer = 0; |
131 | static uint8_t c1 = 0; |
131 | static uint8_t c1 = 0; |
132 | static uint8_t c2 = 0; |
132 | static uint8_t c2 = 0; |
133 | static uint8_t usart_rx_ok = 0; |
133 | static uint8_t usart_rx_ok = 0; |
134 | uint8_t crc1, crc2; |
134 | uint8_t crc1, crc2; |
135 | // the rxd buffer is unlocked |
135 | // the rxd buffer is unlocked |
136 | if (usart_rx_ok == 0) { |
136 | if (usart_rx_ok == 0) { |
137 | // if ((c2 == '#') && (c1 == 'b' || c1 == 'c') && (c == 'D' || c == 'V' || c == 'O')) { |
137 | // if ((c2 == '#') && (c1 == 'b' || c1 == 'c') && (c == 'D' || c == 'V' || c == 'O')) { |
138 | 138 | ||
139 | if ((c2 == '#') && (c1 == 'b' || c1 == 'c') && |
139 | if ((c2 == '#') && (c1 == 'b' || c1 == 'c') && |
140 | #if FCONLY |
140 | #if FCONLY |
141 | (c == 'V' || c == 'D' || c == 'Q' || c == 'L')) { // version, debug, settings, LCD |
141 | (c == 'V' || c == 'D' || c == 'Q' || c == 'L')) { // version, debug, settings, LCD |
142 | #else |
142 | #else |
143 | (c == 'V' || c == 'O' || c == 'Q')) { // version, OSD, settings |
143 | (c == 'V' || c == 'O' || c == 'Q')) { // version, OSD, settings |
144 | #endif |
144 | #endif |
145 | usart_rx_ok = 1; |
145 | usart_rx_ok = 1; |
146 | rxd_buffer[ptr_rxd_buffer++] = c2; |
146 | rxd_buffer[ptr_rxd_buffer++] = c2; |
147 | crc = c2; |
147 | crc = c2; |
148 | rxd_buffer[ptr_rxd_buffer++] = c1; |
148 | rxd_buffer[ptr_rxd_buffer++] = c1; |
149 | crc += c1; |
149 | crc += c1; |
150 | rxd_buffer[ptr_rxd_buffer++] = c; |
150 | rxd_buffer[ptr_rxd_buffer++] = c; |
151 | crc += c; |
151 | crc += c; |
152 | c2 = 0; |
152 | c2 = 0; |
153 | c1 = 0; |
153 | c1 = 0; |
154 | } else { |
154 | } else { |
155 | c2 = c1; |
155 | c2 = c1; |
156 | c1 = c; |
156 | c1 = c; |
157 | } |
157 | } |
158 | } else if (ptr_rxd_buffer < RXD_BUFFER_LEN) { // collect incomming bytes |
158 | } else if (ptr_rxd_buffer < RXD_BUFFER_LEN) { // collect incomming bytes |
159 | if (c != '\r') { // no termination character |
159 | if (c != '\r') { // no termination character |
160 | rxd_buffer[ptr_rxd_buffer++] = c; // copy byte to rxd buffer |
160 | rxd_buffer[ptr_rxd_buffer++] = c; // copy byte to rxd buffer |
161 | crc += c; // update crc |
161 | crc += c; // update crc |
162 | } else { // termination character was received |
162 | } else { // termination character was received |
163 | // the last 2 bytes are no subject for checksum calculation |
163 | // the last 2 bytes are no subject for checksum calculation |
164 | // they are the checksum itself |
164 | // they are the checksum itself |
165 | crc -= rxd_buffer[ptr_rxd_buffer - 2]; |
165 | crc -= rxd_buffer[ptr_rxd_buffer - 2]; |
166 | crc -= rxd_buffer[ptr_rxd_buffer - 1]; |
166 | crc -= rxd_buffer[ptr_rxd_buffer - 1]; |
167 | // calculate checksum from transmitted data |
167 | // calculate checksum from transmitted data |
168 | crc %= 4096; |
168 | crc %= 4096; |
169 | crc1 = '=' + crc / 64; |
169 | crc1 = '=' + crc / 64; |
170 | crc2 = '=' + crc % 64; |
170 | crc2 = '=' + crc % 64; |
171 | // compare checksum to transmitted checksum bytes |
171 | // compare checksum to transmitted checksum bytes |
172 | if ((crc1 == rxd_buffer[ptr_rxd_buffer - 2]) && (crc2 == rxd_buffer[ptr_rxd_buffer - 1])) { // checksum valid |
172 | if ((crc1 == rxd_buffer[ptr_rxd_buffer - 2]) && (crc2 == rxd_buffer[ptr_rxd_buffer - 1])) { // checksum valid |
173 | rxd_buffer[ptr_rxd_buffer] = '\r'; // set termination character |
173 | rxd_buffer[ptr_rxd_buffer] = '\r'; // set termination character |
174 | ReceivedBytes = ptr_rxd_buffer + 1; // store number of received bytes |
174 | ReceivedBytes = ptr_rxd_buffer + 1; // store number of received bytes |
175 | rxd_buffer_locked = 1; // lock the rxd buffer |
175 | rxd_buffer_locked = 1; // lock the rxd buffer |
176 | 176 | ||
177 | 177 | ||
178 | if (rxd_buffer[2] == 'R') { |
178 | if (rxd_buffer[2] == 'R') { |
179 | wdt_enable(WDTO_250MS); // Reset-Commando |
179 | wdt_enable(WDTO_250MS); // Reset-Commando |
180 | } |
180 | } |
181 | } else { // checksum invalid |
181 | } else { // checksum invalid |
182 | rxd_buffer_locked = 0; // unlock rxd buffer |
182 | rxd_buffer_locked = 0; // unlock rxd buffer |
183 | 183 | ||
184 | } |
184 | } |
185 | ptr_rxd_buffer = 0; // reset rxd buffer pointer |
185 | ptr_rxd_buffer = 0; // reset rxd buffer pointer |
186 | usart_rx_ok = 0; |
186 | usart_rx_ok = 0; |
187 | } |
187 | } |
188 | } else { // rxd buffer overrun |
188 | } else { // rxd buffer overrun |
189 | ptr_rxd_buffer = 0; // reset rxd buffer |
189 | ptr_rxd_buffer = 0; // reset rxd buffer |
190 | rxd_buffer_locked = 0; // unlock rxd buffer |
190 | rxd_buffer_locked = 0; // unlock rxd buffer |
191 | usart_rx_ok = 0; |
191 | usart_rx_ok = 0; |
192 | 192 | ||
193 | } |
193 | } |
194 | } |
194 | } |
195 | 195 | ||
196 | /** |
196 | /** |
197 | * Decode the recevied Buffer |
197 | * Decode the recevied Buffer |
198 | * portions taken and adapted from |
198 | * portions taken and adapted from |
199 | * http://svn.mikrokopter.de/mikrowebsvn/filedetails.php?repname=FlightCtrl&path=%2Ftags%2FV0.72p%2Fuart.c |
199 | * http://svn.mikrokopter.de/mikrowebsvn/filedetails.php?repname=FlightCtrl&path=%2Ftags%2FV0.72p%2Fuart.c |
200 | */ |
200 | */ |
201 | void Decode64(void) { |
201 | void Decode64(void) { |
202 | uint8_t a, b, c, d; |
202 | uint8_t a, b, c, d; |
203 | uint8_t x, y, z; |
203 | uint8_t x, y, z; |
204 | uint8_t ptrIn = 3; |
204 | uint8_t ptrIn = 3; |
205 | uint8_t ptrOut = 3; |
205 | uint8_t ptrOut = 3; |
206 | uint8_t len = ReceivedBytes - 6; |
206 | uint8_t len = ReceivedBytes - 6; |
207 | 207 | ||
208 | while (len) { |
208 | while (len) { |
209 | a = rxd_buffer[ptrIn++] - '='; |
209 | a = rxd_buffer[ptrIn++] - '='; |
210 | b = rxd_buffer[ptrIn++] - '='; |
210 | b = rxd_buffer[ptrIn++] - '='; |
211 | c = rxd_buffer[ptrIn++] - '='; |
211 | c = rxd_buffer[ptrIn++] - '='; |
212 | d = rxd_buffer[ptrIn++] - '='; |
212 | d = rxd_buffer[ptrIn++] - '='; |
213 | 213 | ||
214 | x = (a << 2) | (b >> 4); |
214 | x = (a << 2) | (b >> 4); |
215 | y = ((b & 0x0f) << 4) | (c >> 2); |
215 | y = ((b & 0x0f) << 4) | (c >> 2); |
216 | z = ((c & 0x03) << 6) | d; |
216 | z = ((c & 0x03) << 6) | d; |
217 | 217 | ||
218 | if (len--) rxd_buffer[ptrOut++] = x; |
218 | if (len--) rxd_buffer[ptrOut++] = x; |
219 | else break; |
219 | else break; |
220 | if (len--) rxd_buffer[ptrOut++] = y; |
220 | if (len--) rxd_buffer[ptrOut++] = y; |
221 | else break; |
221 | else break; |
222 | if (len--) rxd_buffer[ptrOut++] = z; |
222 | if (len--) rxd_buffer[ptrOut++] = z; |
223 | else break; |
223 | else break; |
224 | } |
224 | } |
225 | pRxData = &rxd_buffer[3]; |
225 | pRxData = &rxd_buffer[3]; |
226 | RxDataLen = ptrOut - 3; |
226 | RxDataLen = ptrOut - 3; |
227 | } |
227 | } |
228 | 228 | ||
229 | /** |
229 | /** |
230 | * request Data through USART in special MK format by adding checksum and |
230 | * request Data through USART in special MK format by adding checksum and |
231 | * encode data in modified Base64 |
231 | * encode data in modified Base64 |
232 | * portions taken and adapted from |
232 | * portions taken and adapted from |
233 | * http://svn.mikrokopter.de/mikrowebsvn/filedetails.php?repname=FlightCtrl&path=%2Ftags%2FV0.72p%2Fuart.c |
233 | * http://svn.mikrokopter.de/mikrowebsvn/filedetails.php?repname=FlightCtrl&path=%2Ftags%2FV0.72p%2Fuart.c |
234 | */ |
234 | */ |
235 | void sendMKData(unsigned char cmd, unsigned char addr, unsigned char *snd, unsigned char len) { |
235 | void sendMKData(unsigned char cmd, unsigned char addr, unsigned char *snd, unsigned char len) { |
236 | unsigned int pt = 0; |
236 | unsigned int pt = 0; |
237 | unsigned char a, b, c; |
237 | unsigned char a, b, c; |
238 | unsigned char ptr = 0; |
238 | unsigned char ptr = 0; |
239 | 239 | ||
240 | txd_buffer[pt++] = '#'; // Start-Byte |
240 | txd_buffer[pt++] = '#'; // Start-Byte |
241 | txd_buffer[pt++] = 'a' + addr; // Adress |
241 | txd_buffer[pt++] = 'a' + addr; // Adress |
242 | txd_buffer[pt++] = cmd; // Command |
242 | txd_buffer[pt++] = cmd; // Command |
243 | while (len) { |
243 | while (len) { |
244 | if (len) { |
244 | if (len) { |
245 | a = snd[ptr++]; |
245 | a = snd[ptr++]; |
246 | len--; |
246 | len--; |
247 | } else a = 0; |
247 | } else a = 0; |
248 | if (len) { |
248 | if (len) { |
249 | b = snd[ptr++]; |
249 | b = snd[ptr++]; |
250 | len--; |
250 | len--; |
251 | } else b = 0; |
251 | } else b = 0; |
252 | if (len) { |
252 | if (len) { |
253 | c = snd[ptr++]; |
253 | c = snd[ptr++]; |
254 | len--; |
254 | len--; |
255 | } else c = 0; |
255 | } else c = 0; |
256 | txd_buffer[pt++] = '=' + (a >> 2); |
256 | txd_buffer[pt++] = '=' + (a >> 2); |
257 | txd_buffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4)); |
257 | txd_buffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4)); |
258 | txd_buffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6)); |
258 | txd_buffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6)); |
259 | txd_buffer[pt++] = '=' + (c & 0x3f); |
259 | txd_buffer[pt++] = '=' + (c & 0x3f); |
260 | } |
260 | } |
261 | 261 | ||
262 | // add crc |
262 | // add crc |
263 | unsigned int tmpCRC = 0, i; |
263 | unsigned int tmpCRC = 0, i; |
264 | for (i = 0; i < pt; i++) { |
264 | for (i = 0; i < pt; i++) { |
265 | tmpCRC += txd_buffer[i]; |
265 | tmpCRC += txd_buffer[i]; |
266 | } |
266 | } |
267 | tmpCRC %= 4096; |
267 | tmpCRC %= 4096; |
268 | txd_buffer[i++] = '=' + tmpCRC / 64; |
268 | txd_buffer[i++] = '=' + tmpCRC / 64; |
269 | txd_buffer[i++] = '=' + tmpCRC % 64; |
269 | txd_buffer[i++] = '=' + tmpCRC % 64; |
270 | txd_buffer[i++] = '\r'; |
270 | txd_buffer[i++] = '\r'; |
271 | 271 | ||
272 | usart0_puts((char*)txd_buffer); |
272 | usart0_puts((char*)txd_buffer); |
273 | } |
273 | } |
274 | 274 | ||
275 | /** |
275 | /** |
276 | * short script to directly send a request thorugh usart including en- and disabling it |
276 | * short script to directly send a request thorugh usart including en- and disabling it |
277 | * where <address> is the address of the receipient, <label> is which data set to request |
277 | * where <address> is the address of the receipient, <label> is which data set to request |
278 | * and <ms> represents the milliseconds delay between data |
278 | * and <ms> represents the milliseconds delay between data |
279 | */ |
279 | */ |
280 | void usart0_request_mk_data(uint8_t address, char label, uint8_t ms) { |
280 | void usart0_request_mk_data(uint8_t address, char label, uint8_t ms) { |
281 | // re-enable TXD pin |
281 | // re-enable TXD pin |
282 | usart0_EnableTXD(); |
282 | usart0_EnableTXD(); |
283 | 283 | ||
284 | unsigned char mstenth = ms / 10; |
284 | unsigned char mstenth = ms / 10; |
285 | sendMKData(label, address, &mstenth, 1); |
285 | sendMKData(label, address, &mstenth, 1); |
286 | // wait until UDR ready |
286 | // wait until UDR ready |
287 | while (!(UCSR0A & (1 << UDRE0))); |
287 | while (!(UCSR0A & (1 << UDRE0))); |
288 | // disable TXD pin again |
288 | // disable TXD pin again |
289 | usart0_DisableTXD(); |
289 | usart0_DisableTXD(); |
290 | } |
290 | } |
291 | 291 | ||
292 | 292 | ||
293 | 293 | ||
294 | 294 |