-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
74 lines (60 loc) · 1.68 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <avr/interrupt.h>
#include <avr/io.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <util/atomic.h>
#include <util/delay.h>
#include "cmd.h"
#include "serial.h"
#include "stream.h"
#include "ticks.h"
#include "track.h"
#include "train.h"
#include "version.h"
#define DCC_DEBUG
void avr_init()
{
TCCR0A = ( 1 << WGM01 ); // CTC Modus
TCCR0B |= ( 1 << CS01 ); // Prescaler 8
OCR0A = 255;
TIMSK0 |= ( 1 << OCIE0A ); // Compare Interrupt für Timer 0 erlauben
// 1000Hz counter initialisieren
// TCCR2A = (1<<WGM21);
// TCCR2B |= (1<<CS22); // Prescaler 64
// OCR2A = 249;
// TIMSK2 |= (1<<OCIE2A);
}
static char cmd[16];
int main( void )
{
uint8_t last_tick = ticks;
avr_init();
tick_counter_init();
track_init();
serial_init( 9600 );
sei(); // Global Interrupts aktivieren
serial_puts( version_string );
serial_puts( "\r\n" );
//track_set_power( main_track, 1 );
while ( 1 ) {
if ( serial_get_command( cmd, sizeof( cmd ) ) ) {
if ( *cmd ) { // Teste, ob Kommando nicht leer
if ( cmd_process( cmd ) ) {
serial_puts( "?OK\r\n" );
}
else {
serial_puts( "?ERR\r\n" );
}
}
}
else {
serial_puts( "?ERR [transmission]\r\n" );
}
if ( (uint8_t)( ticks - last_tick ) > 100 ) {
// ca., wirklich ca. 500ms Intervall
last_tick = ticks;
}
}
return 0;
}