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
 
66
#define FALSE   0
66
#define FALSE   0
67
#define TRUE    1
67
#define TRUE    1
68
 
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
 
72
volatile uint8_t txd_buffer[TXD_BUFFER_LEN];
73
volatile uint8_t txd_buffer[TXD_BUFFER_LEN];
73
volatile uint8_t rxd_buffer_locked = FALSE;
74
volatile uint8_t rxd_buffer_locked = FALSE;
74
volatile uint8_t rxd_buffer[RXD_BUFFER_LEN];
75
volatile uint8_t rxd_buffer[RXD_BUFFER_LEN];
75
volatile uint8_t txd_complete = TRUE;
76
volatile uint8_t txd_complete = TRUE;
Line 81... Line 82...
81
#define COMPASS_HEADING 0x08
82
#define COMPASS_HEADING 0x08
82
 
83
 
83
uint8_t RequestFlags = 0x00;
84
uint8_t RequestFlags = 0x00;
84
uint8_t RequestDebugLabel = 0;
85
uint8_t RequestDebugLabel = 0;
85
 
86
 
-
 
87
uint8_t PC_Connected = 0;
-
 
88
uint8_t FC_Connected = 0;
86
 
89
 
87
uint8_t MySlaveAddr = 0;
90
uint8_t MySlaveAddr = 0;
88
 
91
 
89
 
92
 
90
struct DebugOut_t               DebugOut;
93
struct DebugOut_t               DebugOut;
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);
141
 
144
 
142
        // disable all interrupts before configuration
145
        // disable all interrupts before configuration
143
        cli();
146
        cli();
144
 
147
 
145
        // disable RX-Interrupt
148
        // disable RX-Interrupt
Line 200... Line 203...
200
        VersionInfo.Minor = VERSION_MINOR;
203
        VersionInfo.Minor = VERSION_MINOR;
201
    VersionInfo.PCCompatible = VERSION_COMPATIBLE;
204
    VersionInfo.PCCompatible = VERSION_COMPATIBLE;
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 (':');
209
        uart_putchar ('V');
212
        USART0_putchar ('V');
210
        uart_putchar (0x30 + VERSION_MAJOR);
213
        USART0_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);
213
    uart_putchar ('\n');
217
    USART0_putchar ('\n');
214
}
218
}
215
 
219
 
216
// ---------------------------------------------------------------------------------
220
// ---------------------------------------------------------------------------------
217
void USART0_EnableTXD(void)
221
void USART0_EnableTXD(void)
218
{
222
{
Line 391... Line 395...
391
        }
395
        }
392
}
396
}
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
404
        UDR0 = c;
408
        UDR0 = c;
405
        return (0);
409
        return (0);
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);
424
                        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
                        RequestFlags |= COMPASS_HEADING;
425
                        RequestFlags |= COMPASS_HEADING;
-
 
426
                        AttitudeSource = ATTITUDE_SOURCE_UART;
-
 
427
                        Orientation = ExternData.Orientation;
-
 
428
                        FC_Connected = 255;
425
                        break;
429
                        break;
426
 
430
 
427
                case 'b': // extern control
431
                case 'b': // extern control
428
                case 'c': // extern control with debug request
432
                case 'c': // extern control with debug request
429
                        Decode64((uint8_t *) &ExternControl,sizeof(ExternControl), 3,ReceivedBytes);
433
                        Decode64((uint8_t *) &ExternControl,sizeof(ExternControl), 3,ReceivedBytes);
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
}