Subversion Repositories Projects

Rev

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

Rev 459 Rev 465
Line 58... Line 58...
58
volatile uint8_t last_RC_Quality = 255;
58
volatile uint8_t last_RC_Quality = 255;
Line 59... Line 59...
59
 
59
 
60
// 16bit should be enough, normal LiPos don't last that long
60
// 16bit should be enough, normal LiPos don't last that long
61
volatile uint16_t uptime = 0;
61
volatile uint16_t uptime = 0;
-
 
62
volatile uint16_t timer = 0;
Line 62... Line 63...
62
volatile uint16_t timer = 0;
63
volatile uint8_t short_timer = 0;
63
 
64
 
Line 64... Line 65...
64
// remember last time data was received
65
// remember last time data was received
Line 88... Line 89...
88
// battery voltages
89
// battery voltages
89
uint8_t min_voltage = 0;
90
uint8_t min_voltage = 0;
90
uint8_t max_voltage = 0;
91
uint8_t max_voltage = 0;
Line 91... Line 92...
91
 
92
 
92
// Flags
93
// Flags
Line 93... Line 94...
93
uint8_t COSD_FLAGS = 0;
94
uint8_t COSD_FLAGS = 0, COSD_FLAGS2;
94
 
95
 
95
/* ##########################################################################
96
/* ##########################################################################
96
 * debounce buttons
97
 * debounce buttons
Line 126... Line 127...
126
#if !(ALLCHARSDEBUG|(WRITECHARS != -1))
127
#if !(ALLCHARSDEBUG|(WRITECHARS != -1))
127
/* ##########################################################################
128
/* ##########################################################################
128
 * timer stuff
129
 * timer stuff
129
 * ##########################################################################*/
130
 * ##########################################################################*/
Line -... Line 131...
-
 
131
 
-
 
132
 
-
 
133
/* ##########################################################################
-
 
134
 * STROM TEST
-
 
135
 * ##########################################################################*/
-
 
136
#define INT0_HIGH                       PORTD |=  (1 << PD2);
-
 
137
#define INT0_LOW                        PORTD &= ~(1 << PD2);
-
 
138
 
-
 
139
void SpiMasterInit(void)
-
 
140
{
-
 
141
        volatile char IOReg;
-
 
142
        // set PB4(/SS), PB5(MOSI), PB7(SCK) as output
-
 
143
        DDRB  = (1<<PB4)|(1<<PB5)|(1<<PB7);
-
 
144
                PORTB |= (1 << PB4); // pullup SS
-
 
145
        // enable SPI Interrupt and SPI in Master Mode with SCK = CK/128
-
 
146
        SPCR  = (1<<SPIE)|(1<<SPE)|(1<<MSTR)|(1<<SPR0)|(1<<SPR1);
-
 
147
        IOReg   = SPSR;                         // clear SPIF bit in SPSR
-
 
148
        IOReg   = SPDR;
-
 
149
        //sei(); // we do it later
-
 
150
}
-
 
151
 
-
 
152
volatile size_t icnt = 0;
-
 
153
volatile unsigned char * iptr;
-
 
154
volatile unsigned char spi_cmd[5];       
-
 
155
volatile uint8_t spi_ready = 1;
-
 
156
int16_t ampere = 0;
-
 
157
 
-
 
158
ISR(SPI_STC_vect)
-
 
159
{
-
 
160
    /* Empfangenes Byte im Puffer ablegen. */
-
 
161
    *iptr++ = SPDR;
-
 
162
    /* Zähler dekrementieren. */
-
 
163
    icnt--;
-
 
164
    /* Falls Zähler noch nicht 0 ist... */
-
 
165
    if (icnt) {
-
 
166
                ///_delay_ms(1);
-
 
167
        /* ...nächstes Byte senden. */
-
 
168
        //SPDR = *iptr;
-
 
169
                spi_ready = 1;
-
 
170
    }
-
 
171
    else {
-
 
172
        /* ...andernfalls Interrupt Modus deaktivieren. */
-
 
173
        SPCR &= ~_BV(SPIE);
-
 
174
                INT0_HIGH
-
 
175
                //_delay_ms(1);
-
 
176
    }
-
 
177
}
-
 
178
 
-
 
179
int TransferIsBusy(void)
-
 
180
{
-
 
181
    return SPCR & _BV(SPIE);
-
 
182
}
-
 
183
 
-
 
184
void StartTransfer(unsigned char *data, size_t len)
-
 
185
{
-
 
186
        INT0_LOW
-
 
187
    /* Interrupt Datenpointer und Zähler setzen. */
-
 
188
    iptr = data;
-
 
189
    icnt = len;
-
 
190
 
-
 
191
    /* SPI Interrupt aktivieren und Transfer anstossen. */
-
 
192
    SPCR |= _BV(SPIE);
-
 
193
    SPDR = *iptr;
-
 
194
}
-
 
195
 
-
 
196
 
-
 
197
/* ##########################################################################
-
 
198
 * / STROM TEST END
-
 
199
 * ##########################################################################*/
-
 
200
 
130
 
201
 
131
/**
202
/**
132
 * timer kicks in every 1000uS ^= 1ms
203
 * timer kicks in every 1000uS ^= 1ms
133
 */
204
 */
134
ISR(TIMER0_OVF_vect) {
205
ISR(TIMER0_OVF_vect) {
135
    OCR0 = 15; // preload
206
    OCR0 = 15; // preload
136
    if (!timer--) {
207
    if (!timer--) {
137
        uptime++;
208
        uptime++;
138
        timer = 999;
209
        timer = 999;
139
        seconds_since_last_data++;
210
        seconds_since_last_data++;
-
 
211
    }
-
 
212
        short_timer++;
-
 
213
        if (spi_ready && icnt) {
-
 
214
                SPDR = *iptr;
140
    }
215
        }
Line 141... Line -...
141
}
-
 
142
 
216
}
143
 
217
 
144
/* ##########################################################################
218
/* ##########################################################################
Line 145... Line 219...
145
 * A simple config menu for the flags
219
 * A simple config menu for the flags
Line 331... Line 405...
331
    clear();
405
    clear();
332
    // update flags to paint display again because of clear
406
    // update flags to paint display again because of clear
333
    COSD_FLAGS &= ~COSD_ICONS_WRITTEN;
407
    COSD_FLAGS &= ~COSD_ICONS_WRITTEN;
334
}
408
}
Line 335... Line 409...
335
 
409
 
Line 336... Line 410...
336
#endif // ends !(ALLCHARSDEBUG|(WRITECHARS != -1))
410
#endif // ends !(ALLCHARSDEBUG|(WRITECHARS != -1))#endif // ends !(ALLCHARSDEBUG|(WRITECHARS != -1))
337
 
411
 
338
/* ##########################################################################
412
/* ##########################################################################
339
 * MAIN
413
 * MAIN
-
 
414
 * ##########################################################################*/
340
 * ##########################################################################*/
415
int main(void) {
341
int main(void) {
416
       
342
    // set up FLAGS, compiler should flatten this one
417
    // set up FLAGS, compiler should flatten this one
343
    COSD_FLAGS = (NTSC << 0);
418
    COSD_FLAGS = (NTSC << 0);
344
    COSD_FLAGS |= (HUD << 1);
419
    COSD_FLAGS |= (HUD << 1);
Line 424... Line 499...
424
    // set up timer
499
    // set up timer
425
    TCCR0 |= (1 << CS00) | (1 << CS01); // timer0 prescaler 64
500
    TCCR0 |= (1 << CS00) | (1 << CS01); // timer0 prescaler 64
426
    OCR0 = 15; // preload
501
    OCR0 = 15; // preload
427
    TIMSK |= (1 << TOIE0); // enable overflow timer0
502
    TIMSK |= (1 << TOIE0); // enable overflow timer0
Line -... Line 503...
-
 
503
 
-
 
504
        DDRD |= (1 << PD2); // PD2 output (INT0)  
-
 
505
        SpiMasterInit();
428
 
506
 
429
    // enable interrupts
507
    // enable interrupts
-
 
508
    sei();
430
    sei();
509
       
Line 431... Line 510...
431
#endif
510
#endif
432
 
511
 
433
    //write_ascii_string(2,  7, "         CaScAdE          ");
512
    //write_ascii_string(2,  7, "         CaScAdE          ");
Line 468... Line 547...
468
 
547
 
469
    char* directions[8] = {"NE", "E ", "SE", "S ", "SW", "W ", "NW", "N "};
548
    char* directions[8] = {"NE", "E ", "SE", "S ", "SW", "W ", "NW", "N "};
470
    //char arrowdir[8] = {218, 217, 224, 223, 222, 221, 220, 219};
549
    //char arrowdir[8] = {218, 217, 224, 223, 222, 221, 220, 219};
Line -... Line 550...
-
 
550
#endif
-
 
551
 
471
#endif
552
 
-
 
553
 
-
 
554
    while (1) {
-
 
555
                if (!icnt && spi_ready) {
-
 
556
                        short_timer = 0;
-
 
557
                        ampere = spi_cmd[1] << 8;
-
 
558
                        ampere |= spi_cmd[2];
-
 
559
                        //write_ascii_char(7+4*30, spi_cmd[0]);
-
 
560
                       
-
 
561
                        if (spi_cmd[0] == 'd') {
-
 
562
                                COSD_FLAGS2 |= COSD_FLAG_STROMREC;
-
 
563
                                //write_ascii_char(8+4*30, 'v'); // valid
-
 
564
                        } else {
-
 
565
                                COSD_FLAGS2 &= ~COSD_FLAG_STROMREC;
-
 
566
                                //write_ascii_char(8+4*30, 'i'); // invalid
-
 
567
                        }
-
 
568
                        spi_cmd[0] = 'A';
-
 
569
                        spi_cmd[1] = 'B';
-
 
570
                        spi_cmd[2] = 'C';
472
 
571
                        StartTransfer((unsigned char*)spi_cmd, 3);
473
    while (1) {
572
                }
474
        if (rxd_buffer_locked) {
573
        if (rxd_buffer_locked) {
475
            if (COSD_FLAGS & COSD_FLAG_HUD) {
574
            if (COSD_FLAGS & COSD_FLAG_HUD) {
476
#if FCONLY
575
#if FCONLY