Subversion Repositories MK3Mag

Rev

Rev 28 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 28 Rev 29
Line 64... Line 64...
64
 
64
 
65
 
65
 
Line -... Line 66...
-
 
66
#define FALSE   0
66
#define FALSE   0
67
#define TRUE    1
67
#define TRUE    1
68
 
Line 68... Line 69...
68
 
69
// keep buffers as small as possible
69
#define TXD_BUFFER_LEN  100
70
#define TXD_BUFFER_LEN  100
70
#define RXD_BUFFER_LEN  100
71
#define RXD_BUFFER_LEN  30
71
 
72
 
Line 81... Line 82...
81
#define COMPASS_HEADING 0x08
82
#define COMPASS_HEADING 0x08
Line 82... Line 83...
82
 
83
 
83
uint8_t RequestFlags = 0x00;
84
uint8_t RequestFlags = 0x00;
Line -... Line 85...
-
 
85
uint8_t RequestDebugLabel = 0;
-
 
86
 
Line 84... Line 87...
84
uint8_t RequestDebugLabel = 0;
87
uint8_t PC_Connected = 0;
Line 85... Line 88...
85
 
88
uint8_t FC_Connected = 0;
Line 135... Line 138...
135
/****************************************************************/
138
/****************************************************************/
136
/*              Initialization of the USART0                    */
139
/*              Initialization of the USART0                    */
137
/****************************************************************/
140
/****************************************************************/
138
void USART0_Init (void)
141
void USART0_Init (void)
139
{
142
{
140
        uint16_t ubrr = (uint16_t) ((uint32_t) SYSCLK/(8 * BAUD_RATE) - 1);
143
        uint16_t ubrr = (uint16_t) ((uint32_t) F_CPU/(8 * BAUD_RATE) - 1);
Line 141... Line 144...
141
 
144
 
142
        // disable all interrupts before configuration
145
        // disable all interrupts before configuration
Line 143... Line 146...
143
        cli();
146
        cli();
Line 200... Line 203...
200
        VersionInfo.Minor = VERSION_MINOR;
203
        VersionInfo.Minor = VERSION_MINOR;
201
    VersionInfo.PCCompatible = VERSION_COMPATIBLE;
204
    VersionInfo.PCCompatible = VERSION_COMPATIBLE;
Line 202... Line 205...
202
 
205
 
203
 
206
 
204
    // Version beim Start ausgeben (nicht schön, aber geht... )
207
    // Version beim Start ausgeben (nicht schön, aber geht... )
205
        uart_putchar ('\n');
208
        USART0_putchar ('\n');
206
        uart_putchar ('C');
209
        USART0_putchar ('C');
207
        uart_putchar ('P');
210
        USART0_putchar ('P');
208
        uart_putchar (':');
211
        USART0_putchar (':');
-
 
212
        USART0_putchar ('V');
209
        uart_putchar ('V');
213
        USART0_putchar (0x30 + VERSION_MAJOR);
210
        uart_putchar (0x30 + VERSION_MAJOR);
214
        USART0_putchar ('.');
211
        uart_putchar ('.');uart_putchar (0x30 + VERSION_MINOR/10);
215
        USART0_putchar (0x30 + VERSION_MINOR/10);
212
        uart_putchar (0x30 + VERSION_MINOR%10);
216
        USART0_putchar (0x30 + VERSION_MINOR%10);
Line 213... Line 217...
213
    uart_putchar ('\n');
217
    USART0_putchar ('\n');
214
}
218
}
215
 
219
 
Line 391... Line 395...
391
        }
395
        }
392
}
396
}
Line 393... Line 397...
393
 
397
 
394
 
398
 
395
// --------------------------------------------------------------------------
399
// --------------------------------------------------------------------------
396
int uart_putchar (int8_t c)
400
int16_t USART0_putchar (int8_t c)
397
{
401
{
398
        // if tx is not enabled return immediatly
402
        // if tx is not enabled return immediatly
399
        if(!(UCSR0B & (1 << TXEN0))) return (0);
403
        if(!(UCSR0B & (1 << TXEN0))) return (0);
400
        if (c == '\n') uart_putchar('\r');
404
        if (c == '\n') USART0_putchar('\r');
401
        // wait until previous character was send
405
        // wait until previous character was send
402
        loop_until_bit_is_set(UCSR0A, UDRE0);
406
        loop_until_bit_is_set(UCSR0A, UDRE0);
403
        // send character
407
        // send character
Line 416... Line 420...
416
 
420
 
417
        switch(rxd_buffer[2])
421
        switch(rxd_buffer[2])
418
        {
422
        {
419
           case 'w':// Attitude
423
           case 'w':// Attitude
420
                        Decode64((uint8_t *) &ExternData, sizeof(ExternData), 3, ReceivedBytes);
-
 
421
                        I2C_WriteAttitude.Nick = ExternData.Attitude[NICK];
-
 
422
                        I2C_WriteAttitude.Nick = ExternData.Attitude[ROLL];
-
 
423
                        AttitudeSource = ATTITUDE_SOURCE_UART;
424
                        Decode64((uint8_t *) &ExternData, sizeof(ExternData), 3, ReceivedBytes);
-
 
425
                        RequestFlags |= COMPASS_HEADING;
-
 
426
                        AttitudeSource = ATTITUDE_SOURCE_UART;
-
 
427
                        Orientation = ExternData.Orientation;
424
                        RequestFlags |= COMPASS_HEADING;
428
                        FC_Connected = 255;
Line 425... Line 429...
425
                        break;
429
                        break;
426
 
430
 
427
                case 'b': // extern control
431
                case 'b': // extern control
Line 508... Line 512...
508
        {
512
        {
509
                SendOutData('K',MySlaveAddr,(uint8_t *) &I2C_Heading, sizeof(I2C_Heading));
513
                SendOutData('K',MySlaveAddr,(uint8_t *) &I2C_Heading, sizeof(I2C_Heading));
510
                RequestFlags &= ~COMPASS_HEADING;
514
                RequestFlags &= ~COMPASS_HEADING;
511
        }
515
        }
512
}
516
}
-
 
517
 
-
 
518
 
-
 
519
void USART0_Print(int8_t *msg)
-
 
520
{
-
 
521
        uint8_t i = 0;
-
 
522
        while(msg[i] != 0)
-
 
523
        {
-
 
524
                USART0_putchar(msg[i++]);
-
 
525
        }
-
 
526
}