Subversion Repositories Projects

Rev

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

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