Subversion Repositories MK3Mag

Rev

Rev 19 | Rev 22 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 19 Rev 21
Line 64... Line 64...
64
 
64
 
65
 
65
 
Line 66... Line 66...
66
#define FALSE   0
66
#define FALSE   0
67
#define TRUE    1
67
#define TRUE    1
Line 68... Line 68...
68
 
68
 
69
#define TXD_BUFFER_LEN  100
69
#define TXD_BUFFER_LEN  150
70
#define RXD_BUFFER_LEN  100
70
#define RXD_BUFFER_LEN  150
71
 
71
 
72
volatile uint8_t txd_buffer[TXD_BUFFER_LEN];
72
volatile uint8_t txd_buffer[TXD_BUFFER_LEN];
Line -... Line 73...
-
 
73
volatile uint8_t rxd_buffer_locked = FALSE;
-
 
74
volatile uint8_t rxd_buffer[RXD_BUFFER_LEN];
73
volatile uint8_t rxd_buffer_locked = FALSE;
75
volatile uint8_t txd_complete = TRUE;
74
volatile uint8_t rxd_buffer[RXD_BUFFER_LEN];
76
volatile uint8_t ReceivedBytes = 0;
75
volatile uint8_t txd_complete = TRUE;
77
 
76
volatile uint8_t ReceivedBytes = 0;
78
 
Line 107... Line 109...
107
    "YOffset         ", //10
109
    "YOffset         ", //10
108
    "YRange          ",
110
    "YRange          ",
109
    "ZOffset         ",
111
    "ZOffset         ",
110
    "ZRange          ",
112
    "ZRange          ",
111
    "Calstate        ",
113
    "Calstate        ",
112
    "Heading Request ", //15
114
    "Heading         ", //15
113
    "User0           ",
115
    "User0           ",
114
    "User1           ",
116
    "User1           ",
115
    "Analog18        ",
117
    "Analog18        ",
116
    "Analog19        ",
118
    "Analog19        ",
117
    "Analog20        ", //20
119
    "Analog20        ", //20
Line 160... Line 162...
160
        UBRR0H = (uint8_t)(ubrr >> 8);
162
        UBRR0H = (uint8_t)(ubrr >> 8);
161
        UBRR0L = (uint8_t)ubrr;
163
        UBRR0L = (uint8_t)ubrr;
Line 162... Line 164...
162
 
164
 
Line 163... Line 165...
163
        // USART0 Control and Status Register A, B, C
165
        // USART0 Control and Status Register A, B, C
164
 
166
 
165
        // enable double speed operation in
167
        // enable double speed operation
166
        UCSR0A |= (1 << U2X0);
168
        UCSR0A |= (1 << U2X0);
167
        // enable receiver and transmitter in
169
        // enable receiver and transmitter
168
        UCSR0B |= (1 << TXEN0) | (1 << RXEN0);
170
        UCSR0B |= (1 << TXEN0) | (1 << RXEN0);
169
        // set asynchronous mode
171
        // set asynchronous mode
170
        UCSR0C &= ~(1 << UMSEL01);
172
        UCSR0C &= ~(1 << UMSEL01);
Line 208... Line 210...
208
}
210
}
Line 209... Line 211...
209
 
211
 
210
// ---------------------------------------------------------------------------------
212
// ---------------------------------------------------------------------------------
211
void USART0_EnableTXD(void)
213
void USART0_EnableTXD(void)
-
 
214
{
212
{
215
        //if(!(UCSR0B & (1 << TXEN0))) return;
213
        DDRD |= (1<<DDD1);              // set TXD pin as output
216
        DDRD |= (1<<DDD1);              // set TXD pin as output
214
        UCSR0B |= (1 << TXEN0);         // enable TX in USART
217
        UCSR0B |= (1 << TXEN0);         // enable TX in USART
Line 215... Line 218...
215
}
218
}
216
 
219
 
217
// ---------------------------------------------------------------------------------
220
// ---------------------------------------------------------------------------------
-
 
221
void USART0_DisableTXD(void)
-
 
222
{
-
 
223
        //if((UCSR0B & (1 << TXEN0))) return;
218
void USART0_DisableTXD(void)
224
        while(!txd_complete){ };
219
{
225
 
220
        UCSR0B &= ~(1 << TXEN0);        // disable TXD in USART
226
        UCSR0B &= ~(1 << TXEN0);        // disable TXD in USART
Line 221... Line 227...
221
        DDRD &= ~(1<<DDD1);             // set TXD pin as input
227
        DDRD &= ~(1<<DDD1);             // set TXD pin as input
Line 234... Line 240...
234
                tmp_tx = txd_buffer[ptr_txd_buffer];
240
                tmp_tx = txd_buffer[ptr_txd_buffer];
235
                // if terminating character or end of txd buffer was reached
241
                // if terminating character or end of txd buffer was reached
236
                if((tmp_tx == '\r') || (ptr_txd_buffer == TXD_BUFFER_LEN))
242
                if((tmp_tx == '\r') || (ptr_txd_buffer == TXD_BUFFER_LEN))
237
                {
243
                {
238
                        ptr_txd_buffer = 0; // reset txd pointer
244
                        ptr_txd_buffer = 0; // reset txd pointer
239
                        txd_complete = 1; // stop transmission
245
                        txd_complete = TRUE; // stop transmission
240
                }
246
                }
241
                UDR0 = tmp_tx; // send current byte will trigger this ISR again
247
                UDR0 = tmp_tx; // send current byte will trigger this ISR again
242
        }
248
        }
243
        // transmission completed
249
        // transmission completed
244
        else ptr_txd_buffer = 0;
250
        else ptr_txd_buffer = 0;
Line 248... Line 254...
248
/*               USART0 receiver ISR                            */
254
/*               USART0 receiver ISR                            */
249
/****************************************************************/
255
/****************************************************************/
250
ISR(USART_RX_vect)
256
ISR(USART_RX_vect)
251
{
257
{
252
        static uint16_t crc;
258
        static uint16_t crc;
253
        static uint8_t ptr_rxd_buffer = 0;
-
 
254
        uint8_t crc1, crc2;
259
        uint8_t crc1, crc2;
255
        uint8_t c;
260
        uint8_t c;
-
 
261
        static uint8_t ptr_rxd_buffer = 0;
Line 256... Line 262...
256
 
262
 
Line 257... Line 263...
257
        c = UDR0;  // catch the received byte
263
        c = UDR0;  // catch the received byte
Line 379... Line 385...
379
        }
385
        }
380
}
386
}
Line 381... Line 387...
381
 
387
 
382
 
388
 
383
// --------------------------------------------------------------------------
389
// --------------------------------------------------------------------------
384
int16_t uart_putchar (int8_t c)
390
int uart_putchar (int8_t c)
385
{
391
{
386
        // if tx is not enabled return immediatly
392
        // if tx is not enabled return immediatly
387
        if(!(UCSR0B & (1 << TXEN0))) return (0);
393
        if(!(UCSR0B & (1 << TXEN0))) return (0);
Line 404... Line 410...
404
 
410
 
405
        switch(rxd_buffer[2])
411
        switch(rxd_buffer[2])
406
        {
412
        {
407
           case 'w':// Attitude
413
           case 'w':// Attitude
408
                        Decode64((uint8_t *) &ExternData, sizeof(ExternData), 3, ReceivedBytes);
-
 
409
                        DebugOut.Analog[15]++;
414
                        Decode64((uint8_t *) &ExternData, sizeof(ExternData), 3, ReceivedBytes);
410
                        RequestCompassHeading = TRUE;
415
                        RequestCompassHeading = TRUE;
Line 411... Line 416...
411
                        break;
416
                        break;
412
 
417
 
413
                case 'b': // extern control
418
                case 'b': // extern control
-
 
419
                case 'c': // extern control with debug request
-
 
420
                        Decode64((uint8_t *) &ExternControl,sizeof(ExternControl), 3,ReceivedBytes);
-
 
421
                        #define KEY1    0x01
-
 
422
                        #define KEY2    0x02
-
 
423
                        #define KEY3    0x04
-
 
424
                        #define KEY4    0x08
-
 
425
                        #define KEY5    0x10
-
 
426
                        // use right arrow at display for switching the calstate
-
 
427
                        if(ExternControl.RemoteButtons & KEY2)
-
 
428
                        {
-
 
429
                                ExternData.CalState++;
414
                case 'c': // extern control with debug request
430
                                if(ExternData.CalState == 6) ExternData.CalState = 0;
415
                        Decode64((uint8_t *) &ExternControl,sizeof(ExternControl), 3,ReceivedBytes);
431
                        }
-
 
432
                        ExternData.Attitude[0] = ExternControl.Par1;
416
                        ExternData.Attitude[0] = ExternControl.Par1;
433
            ExternData.Attitude[1] = ExternControl.Par2;
Line 417... Line 434...
417
            ExternData.Attitude[1] = ExternControl.Par2;
434
            PC_Connected = 255;
418
                        break;
435
                        break;
419
 
436